feat: steps system metadata
This commit is contained in:
@@ -7,7 +7,14 @@ import { translateToNewRESTCollection } from "~/newstore/collections"
|
|||||||
|
|
||||||
export default defineImporter({
|
export default defineImporter({
|
||||||
name: "Hoppscotch REST Collection",
|
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]) =>
|
importer: ([content]) =>
|
||||||
pipe(
|
pipe(
|
||||||
E.tryCatch(
|
E.tryCatch(
|
||||||
|
|||||||
@@ -2,24 +2,44 @@
|
|||||||
* Defines which type of content a Step returns.
|
* Defines which type of content a Step returns.
|
||||||
* Add an entry here when you define a step
|
* Add an entry here when you define a step
|
||||||
*/
|
*/
|
||||||
export type StepReturnTypes = {
|
export type StepDefinition = {
|
||||||
FILE_OR_URL_IMPORT: string // String content of the file/url
|
FILE_OR_URL_IMPORT: {
|
||||||
TARGET_MY_COLLECTION: number // folderPath
|
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
|
* Defines what the data structure of a step
|
||||||
*/
|
*/
|
||||||
export type Step<T extends keyof StepReturnTypes> = {
|
export type Step<T extends keyof StepDefinition> =
|
||||||
name: T
|
StepDefinition[T]["metadata"] extends never
|
||||||
caption?: string
|
? {
|
||||||
}
|
name: T
|
||||||
|
caption?: string
|
||||||
|
metadata: undefined
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
name: T
|
||||||
|
caption?: string
|
||||||
|
metadata: StepDefinition[T]["metadata"]
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The return output value of an individual step
|
* The return output value of an individual step
|
||||||
*/
|
*/
|
||||||
export type StepReturnType<T> = T extends Step<infer U>
|
export type StepReturnType<T> = T extends Step<infer U>
|
||||||
? StepReturnTypes[U]
|
? StepDefinition[U]["returnType"]
|
||||||
|
: never
|
||||||
|
|
||||||
|
export type StepMetadata<T> = T extends Step<infer U>
|
||||||
|
? StepDefinition[U]["metadata"]
|
||||||
: never
|
: never
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -29,12 +49,22 @@ export type StepsOutputList<T> = {
|
|||||||
[K in keyof T]: StepReturnType<T[K]>
|
[K in keyof T]: StepReturnType<T[K]>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type StepFuncInput<T extends keyof StepDefinition> =
|
||||||
|
StepDefinition[T]["metadata"] extends never
|
||||||
|
? {
|
||||||
|
stepName: T
|
||||||
|
caption?: string
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
stepName: T
|
||||||
|
caption?: string
|
||||||
|
metadata: StepDefinition[T]["metadata"]
|
||||||
|
}
|
||||||
|
|
||||||
/** Use this function to define a step */
|
/** Use this function to define a step */
|
||||||
export const step = <T extends keyof StepReturnTypes>(
|
export const step = <T extends keyof StepDefinition>(input: StepFuncInput<T>) =>
|
||||||
stepName: T,
|
|
||||||
caption?: string
|
|
||||||
) =>
|
|
||||||
<Step<T>>{
|
<Step<T>>{
|
||||||
name: stepName,
|
name: input.stepName,
|
||||||
caption,
|
metadata: (input as any).metadata ?? undefined,
|
||||||
|
caption: input.caption,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user