import {z} from 'zod' export type GetApiApiV1ApplicationsAppNameComponentsArgs = {appName: string, envName?: string | undefined}; export type GetApiApiV1ApplicationsAppNameComponentsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const v1alpha1InputItem = z.object({from: z.string(), parameterKey: z.string().optional()}); export const v1alpha1OutputItem = z.object({name: z.string(), valueFrom: z.string()}); export const modelJSONStruct = z.object({}); export const v1ApplicationTrait = z.object({alias: z.string().optional(), createTime: z.string(), description: z.string().optional(), properties: modelJSONStruct, type: z.string(), updateTime: z.string()}); export const commonWorkloadGVK = z.object({apiVersion: z.string(), kind: z.string()}); export const commonWorkloadTypeDescriptor = z.object({definition: commonWorkloadGVK.optional(), type: z.string().optional()}); export const v1ComponentBase = z.object({alias: z.string(), componentType: z.string(), createTime: z.string(), creator: z.string().optional(), dependsOn: z.array(z.string()), description: z.string(), icon: z.string().optional(), inputs: z.array(v1alpha1InputItem).optional(), labels: z.record(z.string(), z.string()).optional(), main: z.boolean(), name: z.string(), outputs: z.array(v1alpha1OutputItem).optional(), traits: z.array(v1ApplicationTrait), updateTime: z.string(), workloadType: commonWorkloadTypeDescriptor.optional()}); export const v1ComponentListResponse = z.object({components: z.array(v1ComponentBase)}); 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 }; /** * gets the list of application components * * GET /api/v1/applications/{appName}/components */ export const getApiApiV1ApplicationsAppNameComponents = async (args: GetApiApiV1ApplicationsAppNameComponentsArgs, options: GetApiApiV1ApplicationsAppNameComponentsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.envName != null) query.append("envName", String(args.envName)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/applications/${encodeURIComponent(String(args.appName))}/components${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(v1ComponentListResponse, await res.json()) };