diff --git a/packages/hoppscotch-app/helpers/import-export/import/hopp.ts b/packages/hoppscotch-app/helpers/import-export/import/hopp.ts index 5c64275e5..9ee0d0f1c 100644 --- a/packages/hoppscotch-app/helpers/import-export/import/hopp.ts +++ b/packages/hoppscotch-app/helpers/import-export/import/hopp.ts @@ -7,7 +7,14 @@ import { translateToNewRESTCollection } from "~/newstore/collections" export default defineImporter({ name: "Hoppscotch REST Collection", - steps: [step("FILE_OR_URL_IMPORT", "Select a file or URL")] as const, + steps: [ + step({ + stepName: "FILE_OR_URL_IMPORT", + metadata: { + acceptedFileTypes: ["application/json"], + }, + }), + ] as const, importer: ([content]) => pipe( E.tryCatch( diff --git a/packages/hoppscotch-app/helpers/import-export/steps.ts b/packages/hoppscotch-app/helpers/import-export/steps.ts index cadcecb30..989bb0c2e 100644 --- a/packages/hoppscotch-app/helpers/import-export/steps.ts +++ b/packages/hoppscotch-app/helpers/import-export/steps.ts @@ -2,24 +2,44 @@ * Defines which type of content a Step returns. * Add an entry here when you define a step */ -export type StepReturnTypes = { - FILE_OR_URL_IMPORT: string // String content of the file/url - TARGET_MY_COLLECTION: number // folderPath +export type StepDefinition = { + FILE_OR_URL_IMPORT: { + returnType: string + metadata: { + acceptedFileTypes: string[] + } + } // String content of the file/url + TARGET_MY_COLLECTION: { + returnType: number + metadata: never + } // folderPath } /** * Defines what the data structure of a step */ -export type Step = { - name: T - caption?: string -} +export type Step = + StepDefinition[T]["metadata"] extends never + ? { + name: T + caption?: string + metadata: undefined + } + : { + name: T + caption?: string + metadata: StepDefinition[T]["metadata"] + } /** * The return output value of an individual step */ export type StepReturnType = T extends Step - ? StepReturnTypes[U] + ? StepDefinition[U]["returnType"] + : never + +export type StepMetadata = T extends Step + ? StepDefinition[U]["metadata"] : never /** @@ -29,12 +49,22 @@ export type StepsOutputList = { [K in keyof T]: StepReturnType } +type StepFuncInput = + StepDefinition[T]["metadata"] extends never + ? { + stepName: T + caption?: string + } + : { + stepName: T + caption?: string + metadata: StepDefinition[T]["metadata"] + } + /** Use this function to define a step */ -export const step = ( - stepName: T, - caption?: string -) => +export const step = (input: StepFuncInput) => >{ - name: stepName, - caption, + name: input.stepName, + metadata: (input as any).metadata ?? undefined, + caption: input.caption, }