import {z} from 'zod' export type V1alpha1WorkflowExecuteMode = {steps?: string | undefined, subSteps?: string | undefined}; export type V1alpha1ForEach = {from?: string | undefined, items?: Record | undefined, key?: Array | undefined, mode?: string | undefined}; export type V1alpha1InputItem = {from: string, parameterKey?: string | undefined}; export type V1alpha1WorkflowStepMeta = {alias?: string | undefined}; export type V1alpha1OutputItem = {name: string, valueFrom: string}; export type ModelJSONStruct = Record; export type ModelWorkflowStepBase = {alias: string, dependsOn: Array, description: string, if?: string | undefined, inputs?: Array | undefined, meta?: V1alpha1WorkflowStepMeta | undefined, name: string, orderIndex: number, outputs?: Array | undefined, properties?: ModelJSONStruct | undefined, timeout?: string | undefined, type: string}; export type ModelWorkflowStep = {alias: string, dependsOn: Array, description: string, forEach?: V1alpha1ForEach | undefined, if?: string | undefined, inputs?: Array | undefined, meta?: V1alpha1WorkflowStepMeta | undefined, mode?: string | undefined, name: string, orderIndex: number, outputs?: Array | undefined, properties?: ModelJSONStruct | undefined, subSteps?: Array | undefined, timeout?: string | undefined, type: string}; export type ModelWorkflowSpec = {mode?: V1alpha1WorkflowExecuteMode | undefined, steps?: Array | undefined}; export type V1CreatePipelineRequest = {alias?: string | undefined, description?: string | undefined, name: string, spec: ModelWorkflowSpec}; export type CreateApiApiV1ProjectsProjectNamePipelinesArgs = {projectName: string, body: V1CreatePipelineRequest}; export type CreateApiApiV1ProjectsProjectNamePipelinesOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const v1NameAlias = z.object({alias: z.string(), name: z.string()}); export const v1alpha1WorkflowExecuteMode = z.object({steps: z.string().optional(), subSteps: z.string().optional()}); export const v1alpha1ForEach = z.object({from: z.string().optional(), items: z.object({}).optional(), key: z.array(z.string()).optional(), mode: z.string().optional()}); export const v1alpha1InputItem = z.object({from: z.string(), parameterKey: z.string().optional()}); export const v1alpha1WorkflowStepMeta = z.object({alias: z.string().optional()}); export const v1alpha1OutputItem = z.object({name: z.string(), valueFrom: z.string()}); export const modelJSONStruct = z.object({}); export const modelWorkflowStepBase = z.object({alias: z.string(), dependsOn: z.array(z.string()), description: z.string(), if: z.string().optional(), inputs: z.array(v1alpha1InputItem).optional(), meta: v1alpha1WorkflowStepMeta.optional(), name: z.string(), orderIndex: z.number().int(), outputs: z.array(v1alpha1OutputItem).optional(), properties: modelJSONStruct.optional(), timeout: z.string().optional(), type: z.string()}); export const modelWorkflowStep = z.object({alias: z.string(), dependsOn: z.array(z.string()), description: z.string(), forEach: v1alpha1ForEach.optional(), if: z.string().optional(), inputs: z.array(v1alpha1InputItem).optional(), meta: v1alpha1WorkflowStepMeta.optional(), mode: z.string().optional(), name: z.string(), orderIndex: z.number().int(), outputs: z.array(v1alpha1OutputItem).optional(), properties: modelJSONStruct.optional(), subSteps: z.array(modelWorkflowStepBase).optional(), timeout: z.string().optional(), type: z.string()}); export const modelWorkflowSpec = z.object({mode: v1alpha1WorkflowExecuteMode.optional(), steps: z.array(modelWorkflowStep).optional()}); export const v1PipelineBase = z.object({alias: z.string(), createTime: z.string(), description: z.string(), name: z.string(), project: v1NameAlias, spec: modelWorkflowSpec}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * create pipeline * * POST /api/v1/projects/{projectName}/pipelines */ export const createApiApiV1ProjectsProjectNamePipelines = async (args: CreateApiApiV1ProjectsProjectNamePipelinesArgs, options: CreateApiApiV1ProjectsProjectNamePipelinesOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/projects/${encodeURIComponent(String(args.projectName))}/pipelines${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(v1PipelineBase, await res.json()) };