import type { StandardSchemaV1 } from '@standard-schema/spec'; import { EntityClass, type PrimaryKeyField } from './schema.js'; /** * A Standard Schema validator with a convenience `validate()` method. * * - Pass the object to any Standard Schema-compatible library (TanStack Form, * Conform, tRPC v11, etc.) — they read `~standard`. * - Call `.validate(value)` directly from your own form code. */ export interface RayfinStandardSchema extends StandardSchemaV1 { /** * Validates a value against the schema. * * @param value - The value to validate. * @returns An object with the parsed `value` on success, or `issues` describing validation failures. */ validate(value: unknown): { value: O; issues?: undefined; } | { value?: undefined; issues: readonly StandardSchemaV1.Issue[]; }; } /** * Build a [Standard Schema](https://standardschema.dev) validator for an * entity class declared with the Rayfin decorators (`@entity`, `@text`, * `@uuid`, `@int`, `@boolean`, `@set`, …). * * The returned object implements the `~standard` contract and can be passed * to any Standard Schema-compatible library. It also exposes a convenience * `.validate()` method so form code doesn't need `['~standard'].validate()`. * * The primary key field (`id`) is **automatically omitted** — form schemas * never validate server-generated IDs. Pass additional field names via * `omit` for other server-managed fields like timestamps. * * @example * ```ts * import { toStandardSchema } from '@microsoft/rayfin-core'; * import { Todo } from '../rayfin/data/Todo.js'; * * // id is auto-omitted — only list additional fields to exclude * const todoInput = toStandardSchema(Todo, { * omit: ['createdAt', 'updatedAt'] as const, * }); * * const result = todoInput.validate(formValues); * if (result.issues) { * // show errors keyed by issue.path[0] * } else { * await api.createTodo(result.value); * } * ``` * * @param entity - Entity class decorated with `@entity()`. * @param options - Optional configuration. * - `omit`: Field names to exclude from the schema (in addition to `id`). * The validated value type is narrowed to `Omit`. Omitted * fields are also rejected as unknown if they appear in the input. The * `K extends keyof T` constraint catches typos at compile time. */ export declare function toStandardSchema(entity: EntityClass, options?: { omit?: readonly K[]; }): RayfinStandardSchema>; //# sourceMappingURL=standard-schema.d.ts.map