/** * Zod schemas for Schema Builder domain objects. Source of truth for both * React Flow edge rendering (SchemaRelationSchema -> crow's-foot markers) and * the Supabase mutation layer (via toDbRelation / fromDbRelation). * * See `docs/plans/20260501-universal-wysiwyg-schema-ux-v1.00W.md` §3.9. */ import { z } from 'zod'; import type { TenantEntityRelation } from './types.js'; /** Airtable / Supabase FK semantics. Maps 1:1 onto DB `relation_type`. */ export declare const CardinalitySchema: z.ZodEnum<{ one_to_one: "one_to_one"; one_to_many: "one_to_many"; many_to_many: "many_to_many"; inherits_from: "inherits_from"; }>; export type Cardinality = z.infer; /** Referential-action semantics for the FK columns. */ export declare const ReferentialActionSchema: z.ZodEnum<{ CASCADE: "CASCADE"; "SET NULL": "SET NULL"; RESTRICT: "RESTRICT"; "NO ACTION": "NO ACTION"; }>; export type ReferentialAction = z.infer; /** A single column row inside an entity card. */ export declare const EntityFieldSchema: z.ZodObject<{ id: z.ZodString; name: z.ZodString; type: z.ZodString; isPrimary: z.ZodDefault; isNullable: z.ZodDefault; }, z.core.$strip>; export type EntityField = z.infer; /** The React Flow node's `data` prop shape. */ export declare const EntityNodeDataSchema: z.ZodObject<{ tableId: z.ZodString; label: z.ZodString; fields: z.ZodDefault; isNullable: z.ZodDefault; }, z.core.$strip>>>; accentColor: z.ZodOptional; collapsed: z.ZodDefault; isSystem: z.ZodDefault; }, z.core.$strip>; export type EntityNodeData = z.infer; /** * One edge on the canvas = one documented relation between two ENTITIES. * * ⚠ `source.fieldId`, `target.fieldId`, `metadata.onDelete` and * `metadata.onUpdate` are UI-MODEL ONLY and ARE NOT PERSISTED. The columns * that backed them were dropped by migration 20260503000001 (see * `TenantEntityRelation` in types.ts for the full history). `toDbRelation` * deliberately does not emit them, and `relationInsertContract.test.ts` fails * if it ever starts to again. * * They are retained on the Zod model so that the drag gesture can keep * reporting which handle it started from, and so that re-applying * 20260503000000 is a small diff rather than a rewrite. Do not read them back * expecting a round trip — `fromDbRelation` leaves fieldId undefined and lets * onDelete/onUpdate fall to their defaults, because the database has nothing to * tell it. */ export declare const SchemaRelationSchema: z.ZodObject<{ id: z.ZodUUID; name: z.ZodOptional; source: z.ZodObject<{ tableId: z.ZodString; fieldId: z.ZodOptional; handle: z.ZodDefault>; }, z.core.$strip>; target: z.ZodObject<{ tableId: z.ZodString; fieldId: z.ZodOptional; handle: z.ZodDefault>; }, z.core.$strip>; metadata: z.ZodObject<{ cardinality: z.ZodDefault>; onDelete: z.ZodDefault>; onUpdate: z.ZodDefault>; isSystem: z.ZodDefault; applyAsPostgresFK: z.ZodDefault; }, z.core.$strip>; }, z.core.$strip>; export type SchemaRelation = z.infer; /** * Alias table (Zod -> DB column, §3.9). Used by toDbRelation / fromDbRelation. * Kept exported so tests can assert coverage of every column. */ export declare const ZOD_TO_DB_ALIASES: readonly [readonly ["id", "id"], readonly ["name", "source_label"], readonly ["source.tableId", "source_entity_id"], readonly ["target.tableId", "target_entity_id"], readonly ["metadata.cardinality", "relation_type"], readonly ["metadata.isSystem", "is_system"]]; /** * Translate a validated `SchemaRelation` into the `tenant_entity_relations` * row shape expected by the Supabase upsert. The `source.handle` / * `target.handle` fields are intentionally dropped — they are UI-only; the * full React Flow Handle ID (`${tableId}.${fieldId}.${handle}`) is * reconstructed at render time by `EntityNode` and never persisted. * * `metadata.applyAsPostgresFK` is also dropped — it is consumed by the * `apply_schema_relation` RPC, not stored. */ export declare function toDbRelation(relation: SchemaRelation, opts: { tenantId: string | null; appScope: string; }): Omit; /** Reverse of toDbRelation — rebuild a Zod-validated relation from a DB row. */ export declare function fromDbRelation(row: TenantEntityRelation): SchemaRelation; //# sourceMappingURL=schemas.d.ts.map