import {z} from 'zod' export type GetApiScopedDiagramInfoScopeIdScopeTypeArgs = {scopeId: string, scopeType: string, subScopeId?: string | undefined, modelType?: string | undefined, testModelId?: string | undefined}; export type GetApiScopedDiagramInfoScopeIdScopeTypeOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const jsonNode = z.object({string: z.boolean().optional(), valueNode: z.boolean().optional(), missingNode: z.boolean().optional(), short: z.boolean().optional(), double: z.boolean().optional(), bigDecimal: z.boolean().optional(), bigInteger: z.boolean().optional(), textual: z.boolean().optional(), boolean: z.boolean().optional(), container: z.boolean().optional(), object: z.boolean().optional(), binary: z.boolean().optional(), number: z.boolean().optional(), nodeType: z.enum(["ARRAY", "BINARY", "BOOLEAN", "MISSING", "NULL", "NUMBER", "OBJECT", "POJO", "STRING"]).optional(), long: z.boolean().optional(), pojo: z.boolean().optional(), int: z.boolean().optional(), integralNumber: z.boolean().optional(), floatingPointNumber: z.boolean().optional(), array: z.boolean().optional(), empty: z.boolean().optional(), : z.boolean().optional(), float: z.boolean().optional(), embeddedValue: z.boolean().optional()}); 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 }; /** * Get scoped diagram info information * * GET /scoped-diagram-info/{scopeId}/{scopeType} */ export const getApiScopedDiagramInfoScopeIdScopeType = async (args: GetApiScopedDiagramInfoScopeIdScopeTypeArgs, options?: GetApiScopedDiagramInfoScopeIdScopeTypeOptions) => { const {baseUrl = "http://localhost:8090/inspect-api", fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.subScopeId != null) query.append("subScopeId", String(args.subScopeId)) if (args.modelType != null) query.append("modelType", String(args.modelType)) if (args.testModelId != null) query.append("testModelId", String(args.testModelId)) if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/scoped-diagram-info/${encodeURIComponent(String(args.scopeId))}/${encodeURIComponent(String(args.scopeType))}${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(jsonNode, await res.json()) };