From c99797bcef060faca669d606eea43b38424e74c3 Mon Sep 17 00:00:00 2001 From: Nivedin <53208152+nivedin@users.noreply.github.com> Date: Fri, 28 Oct 2022 07:59:46 +0530 Subject: [PATCH] fix: import hopp collection (#2824) --- .../src/helpers/import-export/import/hopp.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/hoppscotch-app/src/helpers/import-export/import/hopp.ts b/packages/hoppscotch-app/src/helpers/import-export/import/hopp.ts index d8f7f84d..259ea59b 100644 --- a/packages/hoppscotch-app/src/helpers/import-export/import/hopp.ts +++ b/packages/hoppscotch-app/src/helpers/import-export/import/hopp.ts @@ -33,12 +33,7 @@ export default defineImporter({ O.chain( flow( makeCollectionsArray, - RA.map( - flow( - O.fromPredicate(isValidCollection), - O.map(translateToNewRESTCollection) - ) - ), + RA.map(validateCollection), O.sequenceArray, O.map(RA.toArray) ) @@ -61,6 +56,18 @@ const isValidCollection = ( ): collection is HoppCollection => isPlainObject(collection) && "v" in collection +/** + * checks if a collection is a valid hoppscotch collection. + * else translate it into one. + */ +const validateCollection = (collection: unknown) => { + if (isValidCollection(collection)) { + return O.some(collection) + } else { + return O.some(translateToNewRESTCollection(collection)) + } +} + /** * convert single collection object into an array so it can be handled the same as multiple collections */