@sequenceholdings/orm 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/README.md +11 -1
  2. package/dist/authoring.cjs +1066 -59
  3. package/dist/authoring.cjs.map +1 -1
  4. package/dist/authoring.d.cts +289 -24
  5. package/dist/authoring.d.ts +289 -24
  6. package/dist/authoring.js +1056 -60
  7. package/dist/authoring.js.map +1 -1
  8. package/dist/canonical.cjs +415 -9
  9. package/dist/canonical.cjs.map +1 -1
  10. package/dist/canonical.d.cts +235 -1
  11. package/dist/canonical.d.ts +235 -1
  12. package/dist/canonical.js +411 -10
  13. package/dist/canonical.js.map +1 -1
  14. package/dist/cli.cjs +1764 -225
  15. package/dist/cli.cjs.map +1 -1
  16. package/dist/cli.js +1765 -226
  17. package/dist/cli.js.map +1 -1
  18. package/dist/client.cjs.map +1 -1
  19. package/dist/client.d.cts +1 -1
  20. package/dist/client.d.ts +1 -1
  21. package/dist/client.js.map +1 -1
  22. package/dist/compiler.cjs +506 -54
  23. package/dist/compiler.cjs.map +1 -1
  24. package/dist/compiler.d.cts +39 -231
  25. package/dist/compiler.d.ts +39 -231
  26. package/dist/compiler.js +504 -55
  27. package/dist/compiler.js.map +1 -1
  28. package/dist/drizzle.cjs +14 -0
  29. package/dist/drizzle.cjs.map +1 -0
  30. package/dist/drizzle.d.cts +1 -0
  31. package/dist/drizzle.d.ts +1 -0
  32. package/dist/drizzle.js +3 -0
  33. package/dist/drizzle.js.map +1 -0
  34. package/dist/dynamic-input.cjs +391 -0
  35. package/dist/dynamic-input.cjs.map +1 -0
  36. package/dist/dynamic-input.d.cts +111 -0
  37. package/dist/dynamic-input.d.ts +111 -0
  38. package/dist/dynamic-input.js +380 -0
  39. package/dist/dynamic-input.js.map +1 -0
  40. package/dist/index.cjs +2223 -219
  41. package/dist/index.cjs.map +1 -1
  42. package/dist/index.d.cts +125 -9
  43. package/dist/index.d.ts +125 -9
  44. package/dist/index.js +2199 -220
  45. package/dist/index.js.map +1 -1
  46. package/dist/ir.cjs +249 -14
  47. package/dist/ir.cjs.map +1 -1
  48. package/dist/ir.d.cts +20 -80
  49. package/dist/ir.d.ts +20 -80
  50. package/dist/ir.js +249 -14
  51. package/dist/ir.js.map +1 -1
  52. package/dist/predicate-v2.cjs +1093 -0
  53. package/dist/predicate-v2.cjs.map +1 -0
  54. package/dist/predicate-v2.d.cts +139 -0
  55. package/dist/predicate-v2.d.ts +139 -0
  56. package/dist/predicate-v2.js +1083 -0
  57. package/dist/predicate-v2.js.map +1 -0
  58. package/dist/sdl.cjs +344 -55
  59. package/dist/sdl.cjs.map +1 -1
  60. package/dist/sdl.d.cts +1 -3
  61. package/dist/sdl.d.ts +1 -3
  62. package/dist/sdl.js +344 -55
  63. package/dist/sdl.js.map +1 -1
  64. package/package.json +16 -1
  65. package/templates/orm-namespace/CLAUDE.md +6 -5
@@ -109,7 +109,39 @@ declare const canonicalPoliciesSchema: z.ZodObject<{
109
109
  policy: z.ZodOptional<z.ZodString>;
110
110
  }, z.core.$strip>>>;
111
111
  }, z.core.$strip>]>>;
112
+ insert: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
113
+ default: z.ZodString;
114
+ variants: z.ZodDefault<z.ZodArray<z.ZodObject<{
115
+ when: z.ZodString;
116
+ allow: z.ZodOptional<z.ZodLiteral<true>>;
117
+ policy: z.ZodOptional<z.ZodString>;
118
+ }, z.core.$strip>>>;
119
+ }, z.core.$strip>]>>;
120
+ update: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
121
+ default: z.ZodString;
122
+ variants: z.ZodDefault<z.ZodArray<z.ZodObject<{
123
+ when: z.ZodString;
124
+ allow: z.ZodOptional<z.ZodLiteral<true>>;
125
+ policy: z.ZodOptional<z.ZodString>;
126
+ }, z.core.$strip>>>;
127
+ }, z.core.$strip>]>>;
112
128
  }, z.core.$strip>;
129
+ /**
130
+ * View SQL is generated by Drizzle in the authoring process, then crosses the
131
+ * CLI → Atlas JSON boundary. Keep the canonical form to one SELECT statement:
132
+ * PostgreSQL validates the complete grammar when the view is created, while
133
+ * this scanner prevents statement stacking before the text reaches DDL.
134
+ */
135
+ declare function isSingleViewQuerySql(value: string): boolean;
136
+ /**
137
+ * Managed views execute as the shared ORM relation owner. Treat function use
138
+ * as a capability boundary: a new function is unavailable until it is
139
+ * deliberately reviewed here as side-effect-free. The migration engine checks
140
+ * the functions PostgreSQL actually resolved against this list and pg_catalog,
141
+ * so qualification and same-named functions in a consumer schema cannot evade
142
+ * the boundary.
143
+ */
144
+ declare const VIEW_QUERY_FUNCTION_ALLOWLIST: readonly ["abs", "age", "array_agg", "array_append", "array_cat", "array_dims", "array_length", "array_lower", "array_ndims", "array_position", "array_positions", "array_prepend", "array_remove", "array_replace", "array_to_string", "array_trim", "array_upper", "ascii", "avg", "bit_and", "bit_or", "bit_xor", "bool_and", "bool_or", "btrim", "cardinality", "cbrt", "ceil", "ceiling", "char_length", "character_length", "chr", "concat", "concat_ws", "count", "cume_dist", "date_bin", "date_part", "date_trunc", "decode", "degrees", "dense_rank", "encode", "enum_first", "enum_last", "enum_range", "every", "exp", "first_value", "floor", "format", "grouping", "initcap", "json_agg", "json_array_length", "json_build_array", "json_build_object", "json_extract_path", "json_extract_path_text", "json_object_agg", "json_object_keys", "json_strip_nulls", "json_typeof", "jsonb_agg", "jsonb_array_length", "jsonb_build_array", "jsonb_build_object", "jsonb_extract_path", "jsonb_extract_path_text", "jsonb_insert", "jsonb_object_agg", "jsonb_object_keys", "jsonb_path_exists", "jsonb_path_match", "jsonb_path_query", "jsonb_path_query_array", "jsonb_path_query_first", "jsonb_pretty", "jsonb_set", "jsonb_set_lax", "jsonb_strip_nulls", "jsonb_typeof", "justify_days", "justify_hours", "justify_interval", "lag", "last_value", "lead", "left", "length", "ln", "log", "lower", "lpad", "ltrim", "make_date", "make_interval", "make_time", "make_timestamp", "make_timestamptz", "max", "md5", "min", "mod", "nth_value", "ntile", "octet_length", "percent_rank", "pi", "power", "quote_ident", "quote_literal", "quote_nullable", "radians", "rank", "regexp_count", "regexp_instr", "regexp_like", "regexp_match", "regexp_matches", "regexp_replace", "regexp_split_to_array", "regexp_split_to_table", "repeat", "replace", "reverse", "right", "round", "row_number", "rpad", "rtrim", "sign", "split_part", "sqrt", "starts_with", "string_agg", "string_to_array", "strpos", "substr", "substring", "sum", "timezone", "to_ascii", "to_char", "to_date", "to_hex", "to_json", "to_jsonb", "to_number", "to_timestamp", "translate", "trunc", "unnest", "upper", "width_bucket"];
113
145
  /** Actions carry over from v1 as compiled named-SQL ops (plan: resolved OQ-1). */
114
146
  declare const canonicalActionSchema: z.ZodObject<{
115
147
  name: z.ZodString;
@@ -140,6 +172,27 @@ declare const canonicalActionSchema: z.ZodObject<{
140
172
  resource: z.ZodString;
141
173
  }, z.core.$strip>>;
142
174
  }, z.core.$strip>;
175
+ /**
176
+ * Copy-on-write mutations for overlay tables backed by a synced twin
177
+ * (v2-only). Structured metadata, never authored SQL: the compiler and data
178
+ * plane generate the INSERT…SELECT / UPDATE / DELETE statements from it, so
179
+ * there is no SQL surface to validate and write policies inject like any
180
+ * other mutation. `override` copies the synced row into the overlay
181
+ * (ON CONFLICT DO NOTHING) then updates the `set` columns; `revert` deletes
182
+ * the overlay row so the coalesce view falls back to synced.
183
+ */
184
+ declare const canonicalCowMutationSchema: z.ZodObject<{
185
+ kind: z.ZodEnum<{
186
+ override: "override";
187
+ revert: "revert";
188
+ }>;
189
+ name: z.ZodString;
190
+ synced: z.ZodString;
191
+ pk: z.ZodString;
192
+ copy: z.ZodDefault<z.ZodArray<z.ZodString>>;
193
+ set: z.ZodDefault<z.ZodArray<z.ZodString>>;
194
+ }, z.core.$strip>;
195
+ type CanonicalCowMutation = z.infer<typeof canonicalCowMutationSchema>;
143
196
  declare const canonicalTableSchema: z.ZodObject<{
144
197
  table: z.ZodString;
145
198
  description: z.ZodOptional<z.ZodString>;
@@ -210,6 +263,22 @@ declare const canonicalTableSchema: z.ZodObject<{
210
263
  policy: z.ZodOptional<z.ZodString>;
211
264
  }, z.core.$strip>>>;
212
265
  }, z.core.$strip>]>>;
266
+ insert: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
267
+ default: z.ZodString;
268
+ variants: z.ZodDefault<z.ZodArray<z.ZodObject<{
269
+ when: z.ZodString;
270
+ allow: z.ZodOptional<z.ZodLiteral<true>>;
271
+ policy: z.ZodOptional<z.ZodString>;
272
+ }, z.core.$strip>>>;
273
+ }, z.core.$strip>]>>;
274
+ update: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
275
+ default: z.ZodString;
276
+ variants: z.ZodDefault<z.ZodArray<z.ZodObject<{
277
+ when: z.ZodString;
278
+ allow: z.ZodOptional<z.ZodLiteral<true>>;
279
+ policy: z.ZodOptional<z.ZodString>;
280
+ }, z.core.$strip>>>;
281
+ }, z.core.$strip>]>>;
213
282
  }, z.core.$strip>>;
214
283
  actions: z.ZodDefault<z.ZodArray<z.ZodObject<{
215
284
  name: z.ZodString;
@@ -240,8 +309,79 @@ declare const canonicalTableSchema: z.ZodObject<{
240
309
  resource: z.ZodString;
241
310
  }, z.core.$strip>>;
242
311
  }, z.core.$strip>>>;
312
+ cowMutations: z.ZodOptional<z.ZodArray<z.ZodObject<{
313
+ kind: z.ZodEnum<{
314
+ override: "override";
315
+ revert: "revert";
316
+ }>;
317
+ name: z.ZodString;
318
+ synced: z.ZodString;
319
+ pk: z.ZodString;
320
+ copy: z.ZodDefault<z.ZodArray<z.ZodString>>;
321
+ set: z.ZodDefault<z.ZodArray<z.ZodString>>;
322
+ }, z.core.$strip>>>;
243
323
  }, z.core.$strip>;
244
324
  type CanonicalTable = z.infer<typeof canonicalTableSchema>;
325
+ declare const canonicalViewSchema: z.ZodObject<{
326
+ view: z.ZodString;
327
+ description: z.ZodOptional<z.ZodString>;
328
+ columns: z.ZodArray<z.ZodObject<{
329
+ name: z.ZodString;
330
+ columnName: z.ZodString;
331
+ type: z.ZodUnion<readonly [z.ZodEnum<{
332
+ bigint: "bigint";
333
+ boolean: "boolean";
334
+ uuid: "uuid";
335
+ text: "text";
336
+ integer: "integer";
337
+ numeric: "numeric";
338
+ double: "double";
339
+ timestamptz: "timestamptz";
340
+ date: "date";
341
+ jsonb: "jsonb";
342
+ }>, z.ZodObject<{
343
+ enum: z.ZodString;
344
+ }, z.core.$strip>]>;
345
+ nullable: z.ZodDefault<z.ZodBoolean>;
346
+ unique: z.ZodDefault<z.ZodBoolean>;
347
+ default: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>>;
348
+ defaultFn: z.ZodOptional<z.ZodEnum<{
349
+ "gen_random_uuid()": "gen_random_uuid()";
350
+ "now()": "now()";
351
+ }>>;
352
+ description: z.ZodOptional<z.ZodString>;
353
+ renamedFrom: z.ZodOptional<z.ZodString>;
354
+ cast: z.ZodOptional<z.ZodString>;
355
+ deprecated: z.ZodDefault<z.ZodBoolean>;
356
+ }, z.core.$strip>>;
357
+ primaryKey: z.ZodOptional<z.ZodArray<z.ZodString>>;
358
+ links: z.ZodDefault<z.ZodArray<z.ZodObject<{
359
+ name: z.ZodString;
360
+ kind: z.ZodEnum<{
361
+ toOne: "toOne";
362
+ toMany: "toMany";
363
+ toPlatformUser: "toPlatformUser";
364
+ }>;
365
+ target: z.ZodOptional<z.ZodString>;
366
+ on: z.ZodString;
367
+ references: z.ZodOptional<z.ZodString>;
368
+ enforce: z.ZodDefault<z.ZodBoolean>;
369
+ description: z.ZodOptional<z.ZodString>;
370
+ }, z.core.$strip>>>;
371
+ policies: z.ZodObject<{
372
+ read: z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
373
+ default: z.ZodString;
374
+ variants: z.ZodDefault<z.ZodArray<z.ZodObject<{
375
+ when: z.ZodString;
376
+ allow: z.ZodOptional<z.ZodLiteral<true>>;
377
+ policy: z.ZodOptional<z.ZodString>;
378
+ }, z.core.$strip>>>;
379
+ }, z.core.$strip>]>;
380
+ }, z.core.$strict>;
381
+ query: z.ZodString;
382
+ dependencies: z.ZodArray<z.ZodString>;
383
+ }, z.core.$strip>;
384
+ type CanonicalView = z.infer<typeof canonicalViewSchema>;
245
385
  declare const canonicalDefinitionSchema: z.ZodObject<{
246
386
  definition_format: z.ZodLiteral<2>;
247
387
  namespace: z.ZodString;
@@ -320,6 +460,22 @@ declare const canonicalDefinitionSchema: z.ZodObject<{
320
460
  policy: z.ZodOptional<z.ZodString>;
321
461
  }, z.core.$strip>>>;
322
462
  }, z.core.$strip>]>>;
463
+ insert: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
464
+ default: z.ZodString;
465
+ variants: z.ZodDefault<z.ZodArray<z.ZodObject<{
466
+ when: z.ZodString;
467
+ allow: z.ZodOptional<z.ZodLiteral<true>>;
468
+ policy: z.ZodOptional<z.ZodString>;
469
+ }, z.core.$strip>>>;
470
+ }, z.core.$strip>]>>;
471
+ update: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
472
+ default: z.ZodString;
473
+ variants: z.ZodDefault<z.ZodArray<z.ZodObject<{
474
+ when: z.ZodString;
475
+ allow: z.ZodOptional<z.ZodLiteral<true>>;
476
+ policy: z.ZodOptional<z.ZodString>;
477
+ }, z.core.$strip>>>;
478
+ }, z.core.$strip>]>>;
323
479
  }, z.core.$strip>>;
324
480
  actions: z.ZodDefault<z.ZodArray<z.ZodObject<{
325
481
  name: z.ZodString;
@@ -350,13 +506,91 @@ declare const canonicalDefinitionSchema: z.ZodObject<{
350
506
  resource: z.ZodString;
351
507
  }, z.core.$strip>>;
352
508
  }, z.core.$strip>>>;
509
+ cowMutations: z.ZodOptional<z.ZodArray<z.ZodObject<{
510
+ kind: z.ZodEnum<{
511
+ override: "override";
512
+ revert: "revert";
513
+ }>;
514
+ name: z.ZodString;
515
+ synced: z.ZodString;
516
+ pk: z.ZodString;
517
+ copy: z.ZodDefault<z.ZodArray<z.ZodString>>;
518
+ set: z.ZodDefault<z.ZodArray<z.ZodString>>;
519
+ }, z.core.$strip>>>;
353
520
  }, z.core.$strip>>;
521
+ views: z.ZodOptional<z.ZodArray<z.ZodObject<{
522
+ view: z.ZodString;
523
+ description: z.ZodOptional<z.ZodString>;
524
+ columns: z.ZodArray<z.ZodObject<{
525
+ name: z.ZodString;
526
+ columnName: z.ZodString;
527
+ type: z.ZodUnion<readonly [z.ZodEnum<{
528
+ bigint: "bigint";
529
+ boolean: "boolean";
530
+ uuid: "uuid";
531
+ text: "text";
532
+ integer: "integer";
533
+ numeric: "numeric";
534
+ double: "double";
535
+ timestamptz: "timestamptz";
536
+ date: "date";
537
+ jsonb: "jsonb";
538
+ }>, z.ZodObject<{
539
+ enum: z.ZodString;
540
+ }, z.core.$strip>]>;
541
+ nullable: z.ZodDefault<z.ZodBoolean>;
542
+ unique: z.ZodDefault<z.ZodBoolean>;
543
+ default: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>>;
544
+ defaultFn: z.ZodOptional<z.ZodEnum<{
545
+ "gen_random_uuid()": "gen_random_uuid()";
546
+ "now()": "now()";
547
+ }>>;
548
+ description: z.ZodOptional<z.ZodString>;
549
+ renamedFrom: z.ZodOptional<z.ZodString>;
550
+ cast: z.ZodOptional<z.ZodString>;
551
+ deprecated: z.ZodDefault<z.ZodBoolean>;
552
+ }, z.core.$strip>>;
553
+ primaryKey: z.ZodOptional<z.ZodArray<z.ZodString>>;
554
+ links: z.ZodDefault<z.ZodArray<z.ZodObject<{
555
+ name: z.ZodString;
556
+ kind: z.ZodEnum<{
557
+ toOne: "toOne";
558
+ toMany: "toMany";
559
+ toPlatformUser: "toPlatformUser";
560
+ }>;
561
+ target: z.ZodOptional<z.ZodString>;
562
+ on: z.ZodString;
563
+ references: z.ZodOptional<z.ZodString>;
564
+ enforce: z.ZodDefault<z.ZodBoolean>;
565
+ description: z.ZodOptional<z.ZodString>;
566
+ }, z.core.$strip>>>;
567
+ policies: z.ZodObject<{
568
+ read: z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
569
+ default: z.ZodString;
570
+ variants: z.ZodDefault<z.ZodArray<z.ZodObject<{
571
+ when: z.ZodString;
572
+ allow: z.ZodOptional<z.ZodLiteral<true>>;
573
+ policy: z.ZodOptional<z.ZodString>;
574
+ }, z.core.$strip>>>;
575
+ }, z.core.$strip>]>;
576
+ }, z.core.$strict>;
577
+ query: z.ZodString;
578
+ dependencies: z.ZodArray<z.ZodString>;
579
+ }, z.core.$strip>>>;
354
580
  capabilities: z.ZodDefault<z.ZodObject<{
355
581
  roles: z.ZodOptional<z.ZodUnknown>;
356
582
  uses: z.ZodDefault<z.ZodArray<z.ZodString>>;
357
583
  }, z.core.$strip>>;
358
584
  }, z.core.$strip>;
359
585
  type CanonicalDefinition = z.infer<typeof canonicalDefinitionSchema>;
586
+ /**
587
+ * Project namespace-local tables and views onto the shared read/query surface.
588
+ * A view deliberately becomes a CanonicalTable-shaped relation with no write
589
+ * policy, indexes, actions, defaults, or constraints. Keeping this adapter at
590
+ * the canonical boundary makes SDL and compiler behavior identical without
591
+ * pretending views are writable tables in the wire contract.
592
+ */
593
+ declare function canonicalRelations(definition: CanonicalDefinition): CanonicalTable[];
360
594
  /**
361
595
  * Deterministic serialization discipline: tables sorted by name, columns in
362
596
  * declaration order (order is meaningful for DDL), links/indexes/actions
@@ -366,4 +600,4 @@ type CanonicalDefinition = z.infer<typeof canonicalDefinitionSchema>;
366
600
  */
367
601
  declare function normalizeCanonical(definition: CanonicalDefinition): CanonicalDefinition;
368
602
 
369
- export { CANONICAL_FORMAT, COLUMN_TYPES, type CanonicalColumn, type CanonicalDefinition, type CanonicalEnum, type CanonicalLink, type CanonicalTable, type ColumnType, IDENTIFIER_RE, type PolicyExpression, canonicalActionSchema, canonicalColumnSchema, canonicalDefinitionSchema, canonicalEnumSchema, canonicalIndexSchema, canonicalLinkSchema, canonicalPoliciesSchema, canonicalTableSchema, normalizeCanonical, policyExpressionSchema, policyVariantSchema };
603
+ export { CANONICAL_FORMAT, COLUMN_TYPES, type CanonicalColumn, type CanonicalCowMutation, type CanonicalDefinition, type CanonicalEnum, type CanonicalLink, type CanonicalTable, type CanonicalView, type ColumnType, IDENTIFIER_RE, type PolicyExpression, VIEW_QUERY_FUNCTION_ALLOWLIST, canonicalActionSchema, canonicalColumnSchema, canonicalCowMutationSchema, canonicalDefinitionSchema, canonicalEnumSchema, canonicalIndexSchema, canonicalLinkSchema, canonicalPoliciesSchema, canonicalRelations, canonicalTableSchema, canonicalViewSchema, isSingleViewQuerySql, normalizeCanonical, policyExpressionSchema, policyVariantSchema };
@@ -109,7 +109,39 @@ declare const canonicalPoliciesSchema: z.ZodObject<{
109
109
  policy: z.ZodOptional<z.ZodString>;
110
110
  }, z.core.$strip>>>;
111
111
  }, z.core.$strip>]>>;
112
+ insert: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
113
+ default: z.ZodString;
114
+ variants: z.ZodDefault<z.ZodArray<z.ZodObject<{
115
+ when: z.ZodString;
116
+ allow: z.ZodOptional<z.ZodLiteral<true>>;
117
+ policy: z.ZodOptional<z.ZodString>;
118
+ }, z.core.$strip>>>;
119
+ }, z.core.$strip>]>>;
120
+ update: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
121
+ default: z.ZodString;
122
+ variants: z.ZodDefault<z.ZodArray<z.ZodObject<{
123
+ when: z.ZodString;
124
+ allow: z.ZodOptional<z.ZodLiteral<true>>;
125
+ policy: z.ZodOptional<z.ZodString>;
126
+ }, z.core.$strip>>>;
127
+ }, z.core.$strip>]>>;
112
128
  }, z.core.$strip>;
129
+ /**
130
+ * View SQL is generated by Drizzle in the authoring process, then crosses the
131
+ * CLI → Atlas JSON boundary. Keep the canonical form to one SELECT statement:
132
+ * PostgreSQL validates the complete grammar when the view is created, while
133
+ * this scanner prevents statement stacking before the text reaches DDL.
134
+ */
135
+ declare function isSingleViewQuerySql(value: string): boolean;
136
+ /**
137
+ * Managed views execute as the shared ORM relation owner. Treat function use
138
+ * as a capability boundary: a new function is unavailable until it is
139
+ * deliberately reviewed here as side-effect-free. The migration engine checks
140
+ * the functions PostgreSQL actually resolved against this list and pg_catalog,
141
+ * so qualification and same-named functions in a consumer schema cannot evade
142
+ * the boundary.
143
+ */
144
+ declare const VIEW_QUERY_FUNCTION_ALLOWLIST: readonly ["abs", "age", "array_agg", "array_append", "array_cat", "array_dims", "array_length", "array_lower", "array_ndims", "array_position", "array_positions", "array_prepend", "array_remove", "array_replace", "array_to_string", "array_trim", "array_upper", "ascii", "avg", "bit_and", "bit_or", "bit_xor", "bool_and", "bool_or", "btrim", "cardinality", "cbrt", "ceil", "ceiling", "char_length", "character_length", "chr", "concat", "concat_ws", "count", "cume_dist", "date_bin", "date_part", "date_trunc", "decode", "degrees", "dense_rank", "encode", "enum_first", "enum_last", "enum_range", "every", "exp", "first_value", "floor", "format", "grouping", "initcap", "json_agg", "json_array_length", "json_build_array", "json_build_object", "json_extract_path", "json_extract_path_text", "json_object_agg", "json_object_keys", "json_strip_nulls", "json_typeof", "jsonb_agg", "jsonb_array_length", "jsonb_build_array", "jsonb_build_object", "jsonb_extract_path", "jsonb_extract_path_text", "jsonb_insert", "jsonb_object_agg", "jsonb_object_keys", "jsonb_path_exists", "jsonb_path_match", "jsonb_path_query", "jsonb_path_query_array", "jsonb_path_query_first", "jsonb_pretty", "jsonb_set", "jsonb_set_lax", "jsonb_strip_nulls", "jsonb_typeof", "justify_days", "justify_hours", "justify_interval", "lag", "last_value", "lead", "left", "length", "ln", "log", "lower", "lpad", "ltrim", "make_date", "make_interval", "make_time", "make_timestamp", "make_timestamptz", "max", "md5", "min", "mod", "nth_value", "ntile", "octet_length", "percent_rank", "pi", "power", "quote_ident", "quote_literal", "quote_nullable", "radians", "rank", "regexp_count", "regexp_instr", "regexp_like", "regexp_match", "regexp_matches", "regexp_replace", "regexp_split_to_array", "regexp_split_to_table", "repeat", "replace", "reverse", "right", "round", "row_number", "rpad", "rtrim", "sign", "split_part", "sqrt", "starts_with", "string_agg", "string_to_array", "strpos", "substr", "substring", "sum", "timezone", "to_ascii", "to_char", "to_date", "to_hex", "to_json", "to_jsonb", "to_number", "to_timestamp", "translate", "trunc", "unnest", "upper", "width_bucket"];
113
145
  /** Actions carry over from v1 as compiled named-SQL ops (plan: resolved OQ-1). */
114
146
  declare const canonicalActionSchema: z.ZodObject<{
115
147
  name: z.ZodString;
@@ -140,6 +172,27 @@ declare const canonicalActionSchema: z.ZodObject<{
140
172
  resource: z.ZodString;
141
173
  }, z.core.$strip>>;
142
174
  }, z.core.$strip>;
175
+ /**
176
+ * Copy-on-write mutations for overlay tables backed by a synced twin
177
+ * (v2-only). Structured metadata, never authored SQL: the compiler and data
178
+ * plane generate the INSERT…SELECT / UPDATE / DELETE statements from it, so
179
+ * there is no SQL surface to validate and write policies inject like any
180
+ * other mutation. `override` copies the synced row into the overlay
181
+ * (ON CONFLICT DO NOTHING) then updates the `set` columns; `revert` deletes
182
+ * the overlay row so the coalesce view falls back to synced.
183
+ */
184
+ declare const canonicalCowMutationSchema: z.ZodObject<{
185
+ kind: z.ZodEnum<{
186
+ override: "override";
187
+ revert: "revert";
188
+ }>;
189
+ name: z.ZodString;
190
+ synced: z.ZodString;
191
+ pk: z.ZodString;
192
+ copy: z.ZodDefault<z.ZodArray<z.ZodString>>;
193
+ set: z.ZodDefault<z.ZodArray<z.ZodString>>;
194
+ }, z.core.$strip>;
195
+ type CanonicalCowMutation = z.infer<typeof canonicalCowMutationSchema>;
143
196
  declare const canonicalTableSchema: z.ZodObject<{
144
197
  table: z.ZodString;
145
198
  description: z.ZodOptional<z.ZodString>;
@@ -210,6 +263,22 @@ declare const canonicalTableSchema: z.ZodObject<{
210
263
  policy: z.ZodOptional<z.ZodString>;
211
264
  }, z.core.$strip>>>;
212
265
  }, z.core.$strip>]>>;
266
+ insert: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
267
+ default: z.ZodString;
268
+ variants: z.ZodDefault<z.ZodArray<z.ZodObject<{
269
+ when: z.ZodString;
270
+ allow: z.ZodOptional<z.ZodLiteral<true>>;
271
+ policy: z.ZodOptional<z.ZodString>;
272
+ }, z.core.$strip>>>;
273
+ }, z.core.$strip>]>>;
274
+ update: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
275
+ default: z.ZodString;
276
+ variants: z.ZodDefault<z.ZodArray<z.ZodObject<{
277
+ when: z.ZodString;
278
+ allow: z.ZodOptional<z.ZodLiteral<true>>;
279
+ policy: z.ZodOptional<z.ZodString>;
280
+ }, z.core.$strip>>>;
281
+ }, z.core.$strip>]>>;
213
282
  }, z.core.$strip>>;
214
283
  actions: z.ZodDefault<z.ZodArray<z.ZodObject<{
215
284
  name: z.ZodString;
@@ -240,8 +309,79 @@ declare const canonicalTableSchema: z.ZodObject<{
240
309
  resource: z.ZodString;
241
310
  }, z.core.$strip>>;
242
311
  }, z.core.$strip>>>;
312
+ cowMutations: z.ZodOptional<z.ZodArray<z.ZodObject<{
313
+ kind: z.ZodEnum<{
314
+ override: "override";
315
+ revert: "revert";
316
+ }>;
317
+ name: z.ZodString;
318
+ synced: z.ZodString;
319
+ pk: z.ZodString;
320
+ copy: z.ZodDefault<z.ZodArray<z.ZodString>>;
321
+ set: z.ZodDefault<z.ZodArray<z.ZodString>>;
322
+ }, z.core.$strip>>>;
243
323
  }, z.core.$strip>;
244
324
  type CanonicalTable = z.infer<typeof canonicalTableSchema>;
325
+ declare const canonicalViewSchema: z.ZodObject<{
326
+ view: z.ZodString;
327
+ description: z.ZodOptional<z.ZodString>;
328
+ columns: z.ZodArray<z.ZodObject<{
329
+ name: z.ZodString;
330
+ columnName: z.ZodString;
331
+ type: z.ZodUnion<readonly [z.ZodEnum<{
332
+ bigint: "bigint";
333
+ boolean: "boolean";
334
+ uuid: "uuid";
335
+ text: "text";
336
+ integer: "integer";
337
+ numeric: "numeric";
338
+ double: "double";
339
+ timestamptz: "timestamptz";
340
+ date: "date";
341
+ jsonb: "jsonb";
342
+ }>, z.ZodObject<{
343
+ enum: z.ZodString;
344
+ }, z.core.$strip>]>;
345
+ nullable: z.ZodDefault<z.ZodBoolean>;
346
+ unique: z.ZodDefault<z.ZodBoolean>;
347
+ default: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>>;
348
+ defaultFn: z.ZodOptional<z.ZodEnum<{
349
+ "gen_random_uuid()": "gen_random_uuid()";
350
+ "now()": "now()";
351
+ }>>;
352
+ description: z.ZodOptional<z.ZodString>;
353
+ renamedFrom: z.ZodOptional<z.ZodString>;
354
+ cast: z.ZodOptional<z.ZodString>;
355
+ deprecated: z.ZodDefault<z.ZodBoolean>;
356
+ }, z.core.$strip>>;
357
+ primaryKey: z.ZodOptional<z.ZodArray<z.ZodString>>;
358
+ links: z.ZodDefault<z.ZodArray<z.ZodObject<{
359
+ name: z.ZodString;
360
+ kind: z.ZodEnum<{
361
+ toOne: "toOne";
362
+ toMany: "toMany";
363
+ toPlatformUser: "toPlatformUser";
364
+ }>;
365
+ target: z.ZodOptional<z.ZodString>;
366
+ on: z.ZodString;
367
+ references: z.ZodOptional<z.ZodString>;
368
+ enforce: z.ZodDefault<z.ZodBoolean>;
369
+ description: z.ZodOptional<z.ZodString>;
370
+ }, z.core.$strip>>>;
371
+ policies: z.ZodObject<{
372
+ read: z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
373
+ default: z.ZodString;
374
+ variants: z.ZodDefault<z.ZodArray<z.ZodObject<{
375
+ when: z.ZodString;
376
+ allow: z.ZodOptional<z.ZodLiteral<true>>;
377
+ policy: z.ZodOptional<z.ZodString>;
378
+ }, z.core.$strip>>>;
379
+ }, z.core.$strip>]>;
380
+ }, z.core.$strict>;
381
+ query: z.ZodString;
382
+ dependencies: z.ZodArray<z.ZodString>;
383
+ }, z.core.$strip>;
384
+ type CanonicalView = z.infer<typeof canonicalViewSchema>;
245
385
  declare const canonicalDefinitionSchema: z.ZodObject<{
246
386
  definition_format: z.ZodLiteral<2>;
247
387
  namespace: z.ZodString;
@@ -320,6 +460,22 @@ declare const canonicalDefinitionSchema: z.ZodObject<{
320
460
  policy: z.ZodOptional<z.ZodString>;
321
461
  }, z.core.$strip>>>;
322
462
  }, z.core.$strip>]>>;
463
+ insert: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
464
+ default: z.ZodString;
465
+ variants: z.ZodDefault<z.ZodArray<z.ZodObject<{
466
+ when: z.ZodString;
467
+ allow: z.ZodOptional<z.ZodLiteral<true>>;
468
+ policy: z.ZodOptional<z.ZodString>;
469
+ }, z.core.$strip>>>;
470
+ }, z.core.$strip>]>>;
471
+ update: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
472
+ default: z.ZodString;
473
+ variants: z.ZodDefault<z.ZodArray<z.ZodObject<{
474
+ when: z.ZodString;
475
+ allow: z.ZodOptional<z.ZodLiteral<true>>;
476
+ policy: z.ZodOptional<z.ZodString>;
477
+ }, z.core.$strip>>>;
478
+ }, z.core.$strip>]>>;
323
479
  }, z.core.$strip>>;
324
480
  actions: z.ZodDefault<z.ZodArray<z.ZodObject<{
325
481
  name: z.ZodString;
@@ -350,13 +506,91 @@ declare const canonicalDefinitionSchema: z.ZodObject<{
350
506
  resource: z.ZodString;
351
507
  }, z.core.$strip>>;
352
508
  }, z.core.$strip>>>;
509
+ cowMutations: z.ZodOptional<z.ZodArray<z.ZodObject<{
510
+ kind: z.ZodEnum<{
511
+ override: "override";
512
+ revert: "revert";
513
+ }>;
514
+ name: z.ZodString;
515
+ synced: z.ZodString;
516
+ pk: z.ZodString;
517
+ copy: z.ZodDefault<z.ZodArray<z.ZodString>>;
518
+ set: z.ZodDefault<z.ZodArray<z.ZodString>>;
519
+ }, z.core.$strip>>>;
353
520
  }, z.core.$strip>>;
521
+ views: z.ZodOptional<z.ZodArray<z.ZodObject<{
522
+ view: z.ZodString;
523
+ description: z.ZodOptional<z.ZodString>;
524
+ columns: z.ZodArray<z.ZodObject<{
525
+ name: z.ZodString;
526
+ columnName: z.ZodString;
527
+ type: z.ZodUnion<readonly [z.ZodEnum<{
528
+ bigint: "bigint";
529
+ boolean: "boolean";
530
+ uuid: "uuid";
531
+ text: "text";
532
+ integer: "integer";
533
+ numeric: "numeric";
534
+ double: "double";
535
+ timestamptz: "timestamptz";
536
+ date: "date";
537
+ jsonb: "jsonb";
538
+ }>, z.ZodObject<{
539
+ enum: z.ZodString;
540
+ }, z.core.$strip>]>;
541
+ nullable: z.ZodDefault<z.ZodBoolean>;
542
+ unique: z.ZodDefault<z.ZodBoolean>;
543
+ default: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>>;
544
+ defaultFn: z.ZodOptional<z.ZodEnum<{
545
+ "gen_random_uuid()": "gen_random_uuid()";
546
+ "now()": "now()";
547
+ }>>;
548
+ description: z.ZodOptional<z.ZodString>;
549
+ renamedFrom: z.ZodOptional<z.ZodString>;
550
+ cast: z.ZodOptional<z.ZodString>;
551
+ deprecated: z.ZodDefault<z.ZodBoolean>;
552
+ }, z.core.$strip>>;
553
+ primaryKey: z.ZodOptional<z.ZodArray<z.ZodString>>;
554
+ links: z.ZodDefault<z.ZodArray<z.ZodObject<{
555
+ name: z.ZodString;
556
+ kind: z.ZodEnum<{
557
+ toOne: "toOne";
558
+ toMany: "toMany";
559
+ toPlatformUser: "toPlatformUser";
560
+ }>;
561
+ target: z.ZodOptional<z.ZodString>;
562
+ on: z.ZodString;
563
+ references: z.ZodOptional<z.ZodString>;
564
+ enforce: z.ZodDefault<z.ZodBoolean>;
565
+ description: z.ZodOptional<z.ZodString>;
566
+ }, z.core.$strip>>>;
567
+ policies: z.ZodObject<{
568
+ read: z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
569
+ default: z.ZodString;
570
+ variants: z.ZodDefault<z.ZodArray<z.ZodObject<{
571
+ when: z.ZodString;
572
+ allow: z.ZodOptional<z.ZodLiteral<true>>;
573
+ policy: z.ZodOptional<z.ZodString>;
574
+ }, z.core.$strip>>>;
575
+ }, z.core.$strip>]>;
576
+ }, z.core.$strict>;
577
+ query: z.ZodString;
578
+ dependencies: z.ZodArray<z.ZodString>;
579
+ }, z.core.$strip>>>;
354
580
  capabilities: z.ZodDefault<z.ZodObject<{
355
581
  roles: z.ZodOptional<z.ZodUnknown>;
356
582
  uses: z.ZodDefault<z.ZodArray<z.ZodString>>;
357
583
  }, z.core.$strip>>;
358
584
  }, z.core.$strip>;
359
585
  type CanonicalDefinition = z.infer<typeof canonicalDefinitionSchema>;
586
+ /**
587
+ * Project namespace-local tables and views onto the shared read/query surface.
588
+ * A view deliberately becomes a CanonicalTable-shaped relation with no write
589
+ * policy, indexes, actions, defaults, or constraints. Keeping this adapter at
590
+ * the canonical boundary makes SDL and compiler behavior identical without
591
+ * pretending views are writable tables in the wire contract.
592
+ */
593
+ declare function canonicalRelations(definition: CanonicalDefinition): CanonicalTable[];
360
594
  /**
361
595
  * Deterministic serialization discipline: tables sorted by name, columns in
362
596
  * declaration order (order is meaningful for DDL), links/indexes/actions
@@ -366,4 +600,4 @@ type CanonicalDefinition = z.infer<typeof canonicalDefinitionSchema>;
366
600
  */
367
601
  declare function normalizeCanonical(definition: CanonicalDefinition): CanonicalDefinition;
368
602
 
369
- export { CANONICAL_FORMAT, COLUMN_TYPES, type CanonicalColumn, type CanonicalDefinition, type CanonicalEnum, type CanonicalLink, type CanonicalTable, type ColumnType, IDENTIFIER_RE, type PolicyExpression, canonicalActionSchema, canonicalColumnSchema, canonicalDefinitionSchema, canonicalEnumSchema, canonicalIndexSchema, canonicalLinkSchema, canonicalPoliciesSchema, canonicalTableSchema, normalizeCanonical, policyExpressionSchema, policyVariantSchema };
603
+ export { CANONICAL_FORMAT, COLUMN_TYPES, type CanonicalColumn, type CanonicalCowMutation, type CanonicalDefinition, type CanonicalEnum, type CanonicalLink, type CanonicalTable, type CanonicalView, type ColumnType, IDENTIFIER_RE, type PolicyExpression, VIEW_QUERY_FUNCTION_ALLOWLIST, canonicalActionSchema, canonicalColumnSchema, canonicalCowMutationSchema, canonicalDefinitionSchema, canonicalEnumSchema, canonicalIndexSchema, canonicalLinkSchema, canonicalPoliciesSchema, canonicalRelations, canonicalTableSchema, canonicalViewSchema, isSingleViewQuerySql, normalizeCanonical, policyExpressionSchema, policyVariantSchema };