import {z} from 'zod' export type FerryDiagramPosition = {x: number, y: number}; export type FerryDiagramNodeData = {label: string, description?: string | undefined, fields?: Array | undefined, moduleName?: (string | null) | undefined, objectKey?: (string | null) | undefined, objectSlug?: (string | null) | undefined, color?: ('default' | 'brand' | 'success' | 'warning' | 'danger') | undefined, shape?: ('rectangle' | 'roundedRectangle' | 'square' | 'circle' | 'diamond' | 'triangle' | 'invertedTriangle' | 'oval' | 'cylinder' | 'pill' | null) | undefined, fontSize?: (number | null) | undefined, fillColor?: (string | null) | undefined, strokeColor?: (string | null) | undefined, textColor?: (string | null) | undefined}; export type FerryDiagramNode = {id: string, type: 'objectTable' | 'process' | 'note' | 'section', position: FerryDiagramPosition, data: FerryDiagramNodeData, width?: (number | null) | undefined, height?: (number | null) | undefined}; export type FerryDiagramEdge = {id: string, source: string, target: string, label?: string | undefined, type?: ('default' | 'smoothstep' | 'straight') | undefined, sourceHandle?: (string | null) | undefined, strokeWidth?: (number | null) | undefined, targetHandle?: (string | null) | undefined, sourceArrow?: boolean | undefined, sourceCardinality?: ('one' | 'zero_or_one' | 'one_or_many' | 'zero_or_many' | null) | undefined, targetArrow?: boolean | undefined, targetCardinality?: ('one' | 'zero_or_one' | 'one_or_many' | 'zero_or_many' | null) | undefined, strokeStyle?: ('solid' | 'dashed' | 'dotted' | null) | undefined, strokeColor?: (string | null) | undefined, fontSize?: (number | null) | undefined}; export type FerryDiagramViewport = {x?: number | undefined, y?: number | undefined, zoom?: number | undefined}; export type FerryDiagramCreateRequest = {name: string, description?: string | undefined, nodes?: Array | undefined, edges?: Array | undefined, viewport?: FerryDiagramViewport | undefined}; export type CreateApiV2PublicFerryDiagramsArgs = {workspace_id?: (string | null) | undefined, 'X-Workspace-Code'?: string | undefined, body: FerryDiagramCreateRequest}; export type CreateApiV2PublicFerryDiagramsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const ferryDiagramPosition = z.object({x: z.number().gte(-1000000).lte(1000000), y: z.number().gte(-1000000).lte(1000000)}); export const ferryDiagramNodeData = z.object({label: z.string().min(1).max(255), description: z.string().max(4000).optional(), fields: z.array(z.string()).optional(), moduleName: z.string().max(255).nullable().optional(), objectKey: z.string().max(255).nullable().optional(), objectSlug: z.string().max(255).nullable().optional(), color: z.enum(["default", "brand", "success", "warning", "danger"]).optional(), shape: z.enum(["rectangle", "roundedRectangle", "square", "circle", "diamond", "triangle", "invertedTriangle", "oval", "cylinder", "pill"]).nullable().optional(), fontSize: z.number().gte(8).lte(96).nullable().optional(), fillColor: z.string().nullable().optional(), strokeColor: z.string().nullable().optional(), textColor: z.string().nullable().optional()}); export const ferryDiagramNode = z.object({id: z.string().min(1).max(120), type: z.enum(["objectTable", "process", "note", "section"]), position: ferryDiagramPosition, data: ferryDiagramNodeData, width: z.number().gte(96).lte(8000).nullable().optional(), height: z.number().gte(64).lte(8000).nullable().optional()}); export const ferryDiagramEdge = z.object({id: z.string().min(1).max(120), source: z.string().min(1).max(120), target: z.string().min(1).max(120), label: z.string().max(255).optional(), type: z.enum(["default", "smoothstep", "straight"]).optional(), sourceHandle: z.string().max(120).nullable().optional(), strokeWidth: z.number().gte(0.5).lte(24).nullable().optional(), targetHandle: z.string().max(120).nullable().optional(), sourceArrow: z.boolean().optional(), sourceCardinality: z.enum(["one", "zero_or_one", "one_or_many", "zero_or_many"]).nullable().optional(), targetArrow: z.boolean().optional(), targetCardinality: z.enum(["one", "zero_or_one", "one_or_many", "zero_or_many"]).nullable().optional(), strokeStyle: z.enum(["solid", "dashed", "dotted"]).nullable().optional(), strokeColor: z.string().nullable().optional(), fontSize: z.number().gte(8).lte(96).nullable().optional()}); export const ferryDiagramViewport = z.object({x: z.number().gte(-1000000).lte(1000000).optional(), y: z.number().gte(-1000000).lte(1000000).optional(), zoom: z.number().gte(0.1).lte(4).optional()}); export const ferryDiagramData = z.object({name: z.string().min(1).max(120), description: z.string().max(500).optional(), nodes: z.array(ferryDiagramNode).optional(), edges: z.array(ferryDiagramEdge).optional(), viewport: ferryDiagramViewport.optional(), id: z.string(), workspaceId: z.string(), revision: z.number().int(), createdById: z.number().int().nullable().optional(), updatedById: z.number().int().nullable().optional(), createdAt: z.union([z.string(), z.string()]).nullable().optional(), updatedAt: z.union([z.string(), z.string()]).nullable().optional()}); export const paginationMeta = z.object({page: z.number().int().gte(1), page_size: z.number().int().gte(1).lte(500), total: z.number().int().gte(0), next_cursor: z.string().nullable().optional()}); export const toastMessageI18n = z.object({en: z.string(), ja: z.string()}); export const toastMessage = z.object({variant: z.enum(["success", "error", "info", "warning"]), code: z.string(), message: z.string(), i18n: toastMessageI18n}); export const envelopeMeta = z.object({ctx_id: z.string(), pagination: paginationMeta.optional(), toast: toastMessage.optional()}); export const createPublicFerryDiagramApiV2PublicFerryDiagramsPost200Envelope = z.object({success: z.literal(true), data: ferryDiagramData, meta: envelopeMeta}); 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 Public Ferry Diagram * * POST /v2/public/ferry/diagrams */ export const createApiV2PublicFerryDiagrams = async (args: CreateApiV2PublicFerryDiagramsArgs, options?: CreateApiV2PublicFerryDiagramsOptions) => { const {baseUrl = "https://api.sanka.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.workspace_id != null) query.append("workspace_id", String(args.workspace_id)) if (args['X-Workspace-Code'] != null) headers.set("X-Workspace-Code", String(args['X-Workspace-Code'])) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/public/ferry/diagrams${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(createPublicFerryDiagramApiV2PublicFerryDiagramsPost200Envelope, await res.json()) };