import { z } from "zod"; import type { DesktopApi } from "../../../shared/desktop-api"; import { collaborationContracts } from "./collaboration"; import { organizationContracts } from "./organization"; import { platformContracts } from "./platform"; /** Every desktop API method the renderer invokes (not the event subscription or the constants). */ export type InvokedMethod = { [K in keyof DesktopApi]: DesktopApi[K] extends (...args: never[]) => Promise ? K : never }[keyof DesktopApi]; export type InputOf = Parameters extends [infer I] ? I : undefined; const noInput = z.undefined(); /** The runtime contract of each IPC call; a method without a schema, or a schema that disagrees with its type, fails the typecheck. */ export const IPC_CONTRACTS: { [K in InvokedMethod]: z.ZodType> } = { loadSnapshot: noInput, relaunchApp: noInput, reportUnsaved: z.strictObject({ unsaved: z.boolean() }), copyText: z.strictObject({ text: z.string().max(100_000) }), saveViewState: z.strictObject({ key: z.string().min(1).max(200), value: z.json().refine((value) => JSON.stringify(value).length <= 4_000, "View state value is too large.") }), runningSessionCount: noInput, pickDirectory: noInput, listConnectorCatalog: noInput, windowMinimize: noInput, windowMaximize: noInput, windowClose: noInput, ...organizationContracts, ...collaborationContracts, ...platformContracts, };