import {z} from 'zod' export type SchemaConditionValue = unknown; export type SchemaCondition = {action?: string | undefined, jsonKey: string, op?: string | undefined, value: SchemaConditionValue}; export type SchemaStyle = {colSpan: number}; export type SchemaGroupOption = {keys: Array, label: string}; export type SchemaValidateDefaultValue = unknown; export type SchemaOptionValue = unknown; export type SchemaOption = {label: string, value: SchemaOptionValue}; export type SchemaValidate = {defaultValue?: SchemaValidateDefaultValue | undefined, immutable: boolean, max?: number | undefined, maxLength?: number | undefined, min?: number | undefined, minLength?: number | undefined, options?: Array | undefined, pattern?: string | undefined, required?: boolean | undefined}; export type SchemaUIParameter = {additional?: boolean | undefined, additionalParameter?: SchemaUIParameter | undefined, conditions?: Array | undefined, description: string, disable?: boolean | undefined, jsonKey: string, label: string, sort: number, style?: SchemaStyle | undefined, subParameterGroupOption?: Array | undefined, subParameters?: Array | undefined, uiType: string, validate?: SchemaValidate | undefined}; export type V1UpdateUISchemaRequest = {type: string, uiSchema: Array}; export type UpdateApiApiV1DefinitionsDefinitionNameUischemaArgs = {definitionName: string, body: V1UpdateUISchemaRequest}; export type UpdateApiApiV1DefinitionsDefinitionNameUischemaOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const schemaUIParameter = z.unknown(); export const updateApiApiV1DefinitionsDefinitionNameUischemaResponse = z.array(schemaUIParameter); 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 }; /** * Update the UI schema for a definition * * PUT /api/v1/definitions/{definitionName}/uischema */ export const updateApiApiV1DefinitionsDefinitionNameUischema = async (args: UpdateApiApiV1DefinitionsDefinitionNameUischemaArgs, options: UpdateApiApiV1DefinitionsDefinitionNameUischemaOptions) => { 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/definitions/${encodeURIComponent(String(args.definitionName))}/uischema${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(updateApiApiV1DefinitionsDefinitionNameUischemaResponse, await res.json()) };