@prisma-next/sql-contract 0.14.0-dev.9 → 0.14.0-dev.90

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 (80) hide show
  1. package/dist/canonicalization-hooks.d.mts.map +1 -1
  2. package/dist/canonicalization-hooks.mjs +80 -50
  3. package/dist/canonicalization-hooks.mjs.map +1 -1
  4. package/dist/contract-view.d.mts +61 -0
  5. package/dist/contract-view.d.mts.map +1 -0
  6. package/dist/contract-view.mjs +39 -0
  7. package/dist/contract-view.mjs.map +1 -0
  8. package/dist/entity-handle-lowering-hook.d.mts +91 -0
  9. package/dist/entity-handle-lowering-hook.d.mts.map +1 -0
  10. package/dist/entity-handle-lowering-hook.mjs +11 -0
  11. package/dist/entity-handle-lowering-hook.mjs.map +1 -0
  12. package/dist/entity-kinds-BEPZdFBN.mjs +132 -0
  13. package/dist/entity-kinds-BEPZdFBN.mjs.map +1 -0
  14. package/dist/entity-kinds.d.mts +2 -1
  15. package/dist/entity-kinds.d.mts.map +1 -1
  16. package/dist/entity-kinds.mjs +1 -1
  17. package/dist/factories.d.mts +6 -4
  18. package/dist/factories.d.mts.map +1 -1
  19. package/dist/factories.mjs +5 -4
  20. package/dist/factories.mjs.map +1 -1
  21. package/dist/{foreign-key-BATxB95l.d.mts → foreign-key-DM1UTydh.d.mts} +3 -41
  22. package/dist/foreign-key-DM1UTydh.d.mts.map +1 -0
  23. package/dist/index-type-validation.d.mts +1 -1
  24. package/dist/referential-action-sql.d.mts +1 -1
  25. package/dist/resolve-storage-table.d.mts +2 -2
  26. package/dist/sql-node-V214WXQD.d.mts +42 -0
  27. package/dist/sql-node-V214WXQD.d.mts.map +1 -0
  28. package/dist/{sql-storage-Dga0jwP2.d.mts → sql-storage-Dt5ipcRl.d.mts} +63 -20
  29. package/dist/sql-storage-Dt5ipcRl.d.mts.map +1 -0
  30. package/dist/{storage-value-set-WnYsIFM8.d.mts → storage-table-Bj1ZN1P7.d.mts} +16 -39
  31. package/dist/storage-table-Bj1ZN1P7.d.mts.map +1 -0
  32. package/dist/{entity-kinds-Cl36zL5j.mjs → storage-table-y6R6pxyI.mjs} +17 -157
  33. package/dist/storage-table-y6R6pxyI.mjs.map +1 -0
  34. package/dist/storage-value-set-D-jww77l.d.mts +41 -0
  35. package/dist/storage-value-set-D-jww77l.d.mts.map +1 -0
  36. package/dist/storage-value-set-Tx3CFoS_.mjs +38 -0
  37. package/dist/storage-value-set-Tx3CFoS_.mjs.map +1 -0
  38. package/dist/types-Hkxybhdj.mjs +13 -0
  39. package/dist/types-Hkxybhdj.mjs.map +1 -0
  40. package/dist/{types-B1N8w0I2.d.mts → types-zBvpNCmg.d.mts} +25 -55
  41. package/dist/types-zBvpNCmg.d.mts.map +1 -0
  42. package/dist/types.d.mts +13 -5
  43. package/dist/types.d.mts.map +1 -0
  44. package/dist/types.mjs +106 -3
  45. package/dist/types.mjs.map +1 -0
  46. package/dist/validators.d.mts +10 -7
  47. package/dist/validators.d.mts.map +1 -1
  48. package/dist/validators.mjs +8 -18
  49. package/dist/validators.mjs.map +1 -1
  50. package/dist/value-set-derivation-hook.d.mts +35 -0
  51. package/dist/value-set-derivation-hook.d.mts.map +1 -0
  52. package/dist/value-set-derivation-hook.mjs +22 -0
  53. package/dist/value-set-derivation-hook.mjs.map +1 -0
  54. package/package.json +13 -10
  55. package/src/canonicalization-hooks.ts +31 -2
  56. package/src/column-type-resolution.ts +26 -0
  57. package/src/contract-view.ts +98 -0
  58. package/src/entity-handle-lowering-hook.ts +104 -0
  59. package/src/exports/contract-view.ts +11 -0
  60. package/src/exports/entity-handle-lowering-hook.ts +10 -0
  61. package/src/exports/types.ts +17 -4
  62. package/src/exports/value-set-derivation-hook.ts +2 -0
  63. package/src/factories.ts +12 -2
  64. package/src/ir/sql-storage.ts +81 -17
  65. package/src/ir/storage-column.ts +3 -0
  66. package/src/ir/storage-entry-schemas.ts +1 -0
  67. package/src/ir/storage-table.ts +21 -0
  68. package/src/ir/storage-value-set.ts +5 -0
  69. package/src/types.ts +51 -8
  70. package/src/validators.ts +12 -41
  71. package/src/value-set-derivation-hook.ts +47 -0
  72. package/dist/entity-kinds-Cl36zL5j.mjs.map +0 -1
  73. package/dist/foreign-key-BATxB95l.d.mts.map +0 -1
  74. package/dist/sql-storage-Dga0jwP2.d.mts.map +0 -1
  75. package/dist/storage-value-set-WnYsIFM8.d.mts.map +0 -1
  76. package/dist/types-B-eiQXff.mjs +0 -191
  77. package/dist/types-B-eiQXff.mjs.map +0 -1
  78. package/dist/types-B1N8w0I2.d.mts.map +0 -1
  79. package/src/ir/build-sql-namespace.ts +0 -110
  80. package/src/ir/sql-unbound-namespace.ts +0 -74
@@ -1 +1 @@
1
- {"version":3,"file":"factories.mjs","names":[],"sources":["../src/factories.ts"],"sourcesContent":["import { asNamespaceId, type ScalarFieldType } from '@prisma-next/contract/types';\nimport { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';\nimport {\n applyFkDefaults,\n ForeignKey,\n type ForeignKeyOptions,\n Index,\n PrimaryKey,\n type SqlModelFieldStorage,\n type SqlModelStorage,\n StorageColumn,\n type StorageColumnInput,\n StorageTable,\n UniqueConstraint,\n} from './types';\n\nexport function col(nativeType: string, codecId: string, nullable = false): StorageColumn {\n return new StorageColumn({ nativeType, codecId, nullable });\n}\n\nexport function pk(...columns: readonly string[]): PrimaryKey {\n return new PrimaryKey({ columns });\n}\n\nexport function unique(...columns: readonly string[]): UniqueConstraint {\n return new UniqueConstraint({ columns });\n}\n\nexport function index(...columns: readonly string[]): Index {\n return new Index({ columns });\n}\n\nexport function fk(\n srcTableName: string,\n srcColumns: readonly string[],\n targetTableName: string,\n targetColumns: readonly string[],\n opts?: ForeignKeyOptions & { constraint?: boolean; index?: boolean; namespaceId?: string },\n): ForeignKey {\n const defaults = applyFkDefaults({ constraint: opts?.constraint, index: opts?.index });\n const namespaceId = asNamespaceId(opts?.namespaceId ?? UNBOUND_NAMESPACE_ID);\n return new ForeignKey({\n source: { namespaceId, tableName: srcTableName, columns: srcColumns },\n target: { namespaceId, tableName: targetTableName, columns: targetColumns },\n ...(opts?.name !== undefined && { name: opts.name }),\n ...(opts?.onDelete !== undefined && { onDelete: opts.onDelete }),\n ...(opts?.onUpdate !== undefined && { onUpdate: opts.onUpdate }),\n constraint: defaults.constraint,\n index: defaults.index,\n });\n}\n\nexport function table(\n columns: Record<string, StorageColumn | StorageColumnInput>,\n opts?: {\n pk?: PrimaryKey;\n uniques?: readonly UniqueConstraint[];\n indexes?: readonly Index[];\n fks?: readonly ForeignKey[];\n },\n): StorageTable {\n return new StorageTable({\n columns,\n ...(opts?.pk !== undefined && { primaryKey: opts.pk }),\n uniques: opts?.uniques ?? [],\n indexes: opts?.indexes ?? [],\n foreignKeys: opts?.fks ?? [],\n });\n}\n\nexport function model(\n tableName: string,\n fields: Record<string, SqlModelFieldStorage>,\n relations: Record<string, unknown> = {},\n namespaceId: string = UNBOUND_NAMESPACE_ID,\n): {\n storage: SqlModelStorage;\n fields: Record<string, { readonly nullable: boolean; readonly type: ScalarFieldType }>;\n relations: Record<string, unknown>;\n} {\n const storage: SqlModelStorage = { table: tableName, namespaceId, fields };\n const domainFields = Object.fromEntries(\n Object.entries(fields).map(([name, field]) => [\n name,\n {\n nullable: field.nullable ?? false,\n type: { kind: 'scalar' as const, codecId: field.codecId ?? 'core/unknown@1' },\n },\n ]),\n ) as Record<string, { nullable: boolean; type: ScalarFieldType }>;\n return {\n storage,\n fields: domainFields,\n relations,\n };\n}\n"],"mappings":";;;;;AAgBA,SAAgB,IAAI,YAAoB,SAAiB,WAAW,OAAsB;CACxF,OAAO,IAAI,cAAc;EAAE;EAAY;EAAS;CAAS,CAAC;AAC5D;AAEA,SAAgB,GAAG,GAAG,SAAwC;CAC5D,OAAO,IAAI,WAAW,EAAE,QAAQ,CAAC;AACnC;AAEA,SAAgB,OAAO,GAAG,SAA8C;CACtE,OAAO,IAAI,iBAAiB,EAAE,QAAQ,CAAC;AACzC;AAEA,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ceId, type ScalarFieldType } from '@prisma-next/contract/types';\nimport { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';\nimport {\n applyFkDefaults,\n ForeignKey,\n type ForeignKeyOptions,\n Index,\n PrimaryKey,\n type SqlModelFieldStorage,\n type SqlModelStorage,\n StorageColumn,\n type StorageColumnInput,\n StorageTable,\n UniqueConstraint,\n} from './types';\n\nexport function col(\n nativeType: string,\n codecId: string,\n nullable = false,\n opts?: { readonly many?: boolean },\n): StorageColumn {\n return new StorageColumn({\n nativeType,\n codecId,\n nullable,\n ...(opts?.many !== undefined && { many: opts.many }),\n });\n}\n\nexport function pk(...columns: readonly string[]): PrimaryKey {\n return new PrimaryKey({ columns });\n}\n\nexport function unique(...columns: readonly string[]): UniqueConstraint {\n return new UniqueConstraint({ columns });\n}\n\nexport function index(...columns: readonly string[]): Index {\n return new Index({ columns });\n}\n\nexport function fk(\n srcTableName: string,\n srcColumns: readonly string[],\n targetTableName: string,\n targetColumns: readonly string[],\n opts?: ForeignKeyOptions & { constraint?: boolean; index?: boolean; namespaceId?: string },\n): ForeignKey {\n const defaults = applyFkDefaults({ constraint: opts?.constraint, index: opts?.index });\n const namespaceId = asNamespaceId(opts?.namespaceId ?? UNBOUND_NAMESPACE_ID);\n return new ForeignKey({\n source: { namespaceId, tableName: srcTableName, columns: srcColumns },\n target: { namespaceId, tableName: targetTableName, columns: targetColumns },\n ...(opts?.name !== undefined && { name: opts.name }),\n ...(opts?.onDelete !== undefined && { onDelete: opts.onDelete }),\n ...(opts?.onUpdate !== undefined && { onUpdate: opts.onUpdate }),\n constraint: defaults.constraint,\n index: defaults.index,\n });\n}\n\nexport function table(\n columns: Record<string, StorageColumn | StorageColumnInput>,\n opts?: {\n pk?: PrimaryKey;\n uniques?: readonly UniqueConstraint[];\n indexes?: readonly Index[];\n fks?: readonly ForeignKey[];\n },\n): StorageTable {\n return new StorageTable({\n columns,\n ...(opts?.pk !== undefined && { primaryKey: opts.pk }),\n uniques: opts?.uniques ?? [],\n indexes: opts?.indexes ?? [],\n foreignKeys: opts?.fks ?? [],\n });\n}\n\nexport function model(\n tableName: string,\n fields: Record<string, SqlModelFieldStorage>,\n relations: Record<string, unknown> = {},\n namespaceId: string = UNBOUND_NAMESPACE_ID,\n): {\n storage: SqlModelStorage;\n fields: Record<string, { readonly nullable: boolean; readonly type: ScalarFieldType }>;\n relations: Record<string, unknown>;\n} {\n const storage: SqlModelStorage = { table: tableName, namespaceId, fields };\n const domainFields = Object.fromEntries(\n Object.entries(fields).map(([name, field]) => [\n name,\n {\n nullable: field.nullable ?? false,\n type: { kind: 'scalar' as const, codecId: field.codecId ?? 'core/unknown@1' },\n },\n ]),\n ) as Record<string, { nullable: boolean; type: ScalarFieldType }>;\n return {\n storage,\n fields: domainFields,\n relations,\n };\n}\n"],"mappings":";;;;;AAgBA,SAAgB,IACd,YACA,SACA,WAAW,OACX,MACe;CACf,OAAO,IAAI,cAAc;EACvB;EACA;EACA;EACA,GAAI,MAAM,SAAS,KAAA,KAAa,EAAE,MAAM,KAAK,KAAK;CACpD,CAAC;AACH;AAEA,SAAgB,GAAG,GAAG,SAAwC;CAC5D,OAAO,IAAI,WAAW,EAAE,QAAQ,CAAC;AACnC;AAEA,SAAgB,OAAO,GAAG,SAA8C;CACtE,OAAO,IAAI,iBAAiB,EAAE,QAAQ,CAAC;AACzC;AAEA,SAAgB,MAAM,GAAG,SAAmC;CAC1D,OAAO,IAAI,MAAM,EAAE,QAAQ,CAAC;AAC9B;AAEA,SAAgB,GACd,cACA,YACA,iBACA,eACA,MACY;CACZ,MAAM,WAAW,gBAAgB;EAAE,YAAY,MAAM;EAAY,OAAO,MAAM;CAAM,CAAC;CACrF,MAAM,cAAc,cAAc,MAAM,eAAe,oBAAoB;CAC3E,OAAO,IAAI,WAAW;EACpB,QAAQ;GAAE;GAAa,WAAW;GAAc,SAAS;EAAW;EACpE,QAAQ;GAAE;GAAa,WAAW;GAAiB,SAAS;EAAc;EAC1E,GAAI,MAAM,SAAS,KAAA,KAAa,EAAE,MAAM,KAAK,KAAK;EAClD,GAAI,MAAM,aAAa,KAAA,KAAa,EAAE,UAAU,KAAK,SAAS;EAC9D,GAAI,MAAM,aAAa,KAAA,KAAa,EAAE,UAAU,KAAK,SAAS;EAC9D,YAAY,SAAS;EACrB,OAAO,SAAS;CAClB,CAAC;AACH;AAEA,SAAgB,MACd,SACA,MAMc;CACd,OAAO,IAAI,aAAa;EACtB;EACA,GAAI,MAAM,OAAO,KAAA,KAAa,EAAE,YAAY,KAAK,GAAG;EACpD,SAAS,MAAM,WAAW,CAAC;EAC3B,SAAS,MAAM,WAAW,CAAC;EAC3B,aAAa,MAAM,OAAO,CAAC;CAC7B,CAAC;AACH;AAEA,SAAgB,MACd,WACA,QACA,YAAqC,CAAC,GACtC,cAAsB,sBAKtB;CAWA,OAAO;EACL,SAAA;GAXiC,OAAO;GAAW;GAAa;EAW1D;EACN,QAXmB,OAAO,YAC1B,OAAO,QAAQ,MAAM,CAAC,CAAC,KAAK,CAAC,MAAM,WAAW,CAC5C,MACA;GACE,UAAU,MAAM,YAAY;GAC5B,MAAM;IAAE,MAAM;IAAmB,SAAS,MAAM,WAAW;GAAiB;EAC9E,CACF,CAAC,CAIkB;EACnB;CACF;AACF"}
@@ -1,44 +1,6 @@
1
- import { IRNodeBase } from "@prisma-next/framework-components/ir";
1
+ import { t as SqlNode } from "./sql-node-V214WXQD.mjs";
2
2
  import { NamespaceId } from "@prisma-next/contract/types";
3
3
 
4
- //#region src/ir/sql-node.d.ts
5
- /**
6
- * SQL family IR node base. Carries the family-level `kind` discriminator
7
- * `'sql'` and inherits the framework's `freezeNode` affordance.
8
- *
9
- * Single family-level discriminator (not per-leaf) reflects the fact that
10
- * SQL IR has no polymorphic dispatch today — verifiers and serializers
11
- * walk by structural position (`storage.tables[name].columns[name]`),
12
- * not by inspecting `kind`. The abstract bar for per-leaf discriminators
13
- * isn't earned until a future polymorphic consumer arrives.
14
- *
15
- * `kind` is installed as a non-enumerable own property on every instance,
16
- * which keeps three things clean simultaneously:
17
- *
18
- * - `JSON.stringify(node)` produces the canonical pre-lift JSON envelope
19
- * shape (no `kind` field), so emitted contract.json files and the
20
- * `validateSqlContractFully` arktype schemas stay unchanged.
21
- * - Test assertions that use `toEqual({...})` against the pre-lift flat
22
- * shape continue to pass — only enumerable own properties are
23
- * compared.
24
- * - Direct access (`node.kind`) and runtime narrowing
25
- * (`if (node.kind === 'sql')`) still work, so future polymorphic
26
- * dispatch can begin reading `kind` without a runtime change.
27
- *
28
- * Future per-leaf overrides land cleanly: a class that gains a
29
- * polymorphic-dispatch consumer (e.g. an enum type instance walked
30
- * alongside other types) overrides `kind` with its narrower literal
31
- * at that leaf level. Per-leaf overrides will use enumerable kind
32
- * (matching the Mongo per-class-discriminator precedent) because they
33
- * encode dispatch-relevant information that callers need to see in
34
- * JSON envelopes; the family-level `'sql'` is uniform across all SQL
35
- * IR and carries no dispatch-relevant information.
36
- */
37
- declare abstract class SqlNode extends IRNodeBase {
38
- readonly kind?: string;
39
- constructor();
40
- }
41
- //#endregion
42
4
  //#region src/ir/foreign-key-reference.d.ts
43
5
  /**
44
6
  * Input for a foreign-key reference (one side of a foreign-key declaration).
@@ -117,5 +79,5 @@ declare class ForeignKey extends SqlNode {
117
79
  constructor(input: ForeignKeyInput);
118
80
  }
119
81
  //#endregion
120
- export { ForeignKeyReferenceInput as a, ForeignKeyReference as i, ForeignKeyInput as n, SqlNode as o, ReferentialAction as r, ForeignKey as t };
121
- //# sourceMappingURL=foreign-key-BATxB95l.d.mts.map
82
+ export { ForeignKeyReferenceInput as a, ForeignKeyReference as i, ForeignKeyInput as n, ReferentialAction as r, ForeignKey as t };
83
+ //# sourceMappingURL=foreign-key-DM1UTydh.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"foreign-key-DM1UTydh.d.mts","names":[],"sources":["../src/ir/foreign-key-reference.ts","../src/ir/foreign-key.ts"],"mappings":";;;;;;AAeA;;;;;;;;;UAAiB,wBAAA;EAAA,SACN,WAAA;EAAA,SACA,SAAA;EAAA,SACA,OAAA;EAAA,SACA,OAAA;AAAA;;;;;;;;;;;;;;AAyBkC;;;cANhC,mBAAA,SAA4B,OAAA;EAAA,SAC9B,WAAA,EAAa,WAAA;EAAA,SACb,SAAA;EAAA,SACA,OAAA;EAAA,SACQ,OAAA;cAEL,KAAA,EAAO,wBAAA;AAAA;;;KCxCT,iBAAA;AAAA,UAEK,eAAA;EAAA,SACN,MAAA,EAAQ,mBAAA,GAAsB,wBAAA;EAAA,SAC9B,MAAA,EAAQ,mBAAA,GAAsB,wBAAA;EAAA,SAC9B,IAAA;EAAA,SACA,QAAA,GAAW,iBAAA;EAAA,SACX,QAAA,GAAW,iBAAA;EDMX;EAAA,SCJA,UAAA;EDMA;EAAA,SCJA,KAAA;AAAA;ADuBX;;;;;;;;;;;;AAAA,cCRa,UAAA,SAAmB,OAAA;EAAA,SACrB,MAAA,EAAQ,mBAAA;EAAA,SACR,MAAA,EAAQ,mBAAA;EAAA,SACR,UAAA;EAAA,SACA,KAAA;EAAA,SACQ,IAAA;EAAA,SACA,QAAA,GAAW,iBAAA;EAAA,SACX,QAAA,GAAW,iBAAA;cAEhB,KAAA,EAAO,eAAA;AAAA"}
@@ -1,4 +1,4 @@
1
- import { i as SqlStorage } from "./sql-storage-Dga0jwP2.mjs";
1
+ import { s as SqlStorage } from "./sql-storage-Dt5ipcRl.mjs";
2
2
  import { a as IndexTypeRegistry } from "./index-types-Czsyu7Iw.mjs";
3
3
  import { Contract } from "@prisma-next/contract/types";
4
4
 
@@ -1,4 +1,4 @@
1
- import { r as ReferentialAction } from "./foreign-key-BATxB95l.mjs";
1
+ import { r as ReferentialAction } from "./foreign-key-DM1UTydh.mjs";
2
2
 
3
3
  //#region src/referential-action-sql.d.ts
4
4
  /**
@@ -1,5 +1,5 @@
1
- import { r as StorageTable } from "./storage-value-set-WnYsIFM8.mjs";
2
- import { i as SqlStorage } from "./sql-storage-Dga0jwP2.mjs";
1
+ import { t as StorageTable } from "./storage-table-Bj1ZN1P7.mjs";
2
+ import { s as SqlStorage } from "./sql-storage-Dt5ipcRl.mjs";
3
3
 
4
4
  //#region src/resolve-storage-table.d.ts
5
5
  interface ResolvedStorageTable {
@@ -0,0 +1,42 @@
1
+ import { IRNodeBase } from "@prisma-next/framework-components/ir";
2
+
3
+ //#region src/ir/sql-node.d.ts
4
+ /**
5
+ * SQL family IR node base. Carries the family-level `kind` discriminator
6
+ * `'sql'` and inherits the framework's `freezeNode` affordance.
7
+ *
8
+ * Single family-level discriminator (not per-leaf) reflects the fact that
9
+ * SQL IR has no polymorphic dispatch today — verifiers and serializers
10
+ * walk by structural position (`storage.tables[name].columns[name]`),
11
+ * not by inspecting `kind`. The abstract bar for per-leaf discriminators
12
+ * isn't earned until a future polymorphic consumer arrives.
13
+ *
14
+ * `kind` is installed as a non-enumerable own property on every instance,
15
+ * which keeps three things clean simultaneously:
16
+ *
17
+ * - `JSON.stringify(node)` produces the canonical pre-lift JSON envelope
18
+ * shape (no `kind` field), so emitted contract.json files and the
19
+ * `validateSqlContractFully` arktype schemas stay unchanged.
20
+ * - Test assertions that use `toEqual({...})` against the pre-lift flat
21
+ * shape continue to pass — only enumerable own properties are
22
+ * compared.
23
+ * - Direct access (`node.kind`) and runtime narrowing
24
+ * (`if (node.kind === 'sql')`) still work, so future polymorphic
25
+ * dispatch can begin reading `kind` without a runtime change.
26
+ *
27
+ * Future per-leaf overrides land cleanly: a class that gains a
28
+ * polymorphic-dispatch consumer (e.g. an enum type instance walked
29
+ * alongside other types) overrides `kind` with its narrower literal
30
+ * at that leaf level. Per-leaf overrides will use enumerable kind
31
+ * (matching the Mongo per-class-discriminator precedent) because they
32
+ * encode dispatch-relevant information that callers need to see in
33
+ * JSON envelopes; the family-level `'sql'` is uniform across all SQL
34
+ * IR and carries no dispatch-relevant information.
35
+ */
36
+ declare abstract class SqlNode extends IRNodeBase {
37
+ readonly kind?: string;
38
+ constructor();
39
+ }
40
+ //#endregion
41
+ export { SqlNode as t };
42
+ //# sourceMappingURL=sql-node-V214WXQD.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sql-node-V214WXQD.d.mts","names":[],"sources":["../src/ir/sql-node.ts"],"mappings":";;;;;AAkCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uBAAsB,OAAA,SAAgB,UAAU;EAAA,SACrC,IAAA"}
@@ -1,7 +1,9 @@
1
- import { o as SqlNode } from "./foreign-key-BATxB95l.mjs";
2
- import { r as StorageTable, t as StorageValueSet } from "./storage-value-set-WnYsIFM8.mjs";
3
- import { Namespace, Storage, StorageType } from "@prisma-next/framework-components/ir";
1
+ import { t as SqlNode } from "./sql-node-V214WXQD.mjs";
2
+ import { t as StorageTable } from "./storage-table-Bj1ZN1P7.mjs";
3
+ import { t as StorageValueSet } from "./storage-value-set-D-jww77l.mjs";
4
+ import { Namespace, NamespaceBase, Storage, StorageType } from "@prisma-next/framework-components/ir";
4
5
  import { StorageHashBase } from "@prisma-next/contract/types";
6
+ import { AuthoringContributions } from "@prisma-next/framework-components/authoring";
5
7
 
6
8
  //#region src/ir/storage-type-instance.d.ts
7
9
  /**
@@ -60,14 +62,34 @@ declare function isStorageTypeInstance(value: unknown): value is StorageTypeInst
60
62
  * `entries.type` slot on `PostgresSchema` (target layer), not here.
61
63
  */
62
64
  type SqlStorageTypeEntry = StorageTypeInstance | StorageTypeInstanceInput;
63
- interface SqlNamespaceTablesInput {
65
+ interface SqlNamespaceInput {
64
66
  readonly id: string;
65
67
  readonly entries: Readonly<Record<string, Readonly<Record<string, unknown>>>>;
66
68
  }
69
+ /**
70
+ * Target-supplied factory that materializes a `Namespace` from a SQL
71
+ * `SqlNamespaceInput` (used to populate `SqlStorage.namespaces`).
72
+ */
73
+ type SqlNamespaceFactory = (input: SqlNamespaceInput) => Namespace;
74
+ /**
75
+ * SQL-family extension of the framework `AuthoringContributions`. SQL target
76
+ * packs add a `createNamespace` factory so the PSL/TS authoring paths can
77
+ * materialize namespaces (and merge lowered extension-block entities) without
78
+ * each consumer re-specifying it. The factory is SQL-specific, so it lives here
79
+ * rather than on the framework `AuthoringContributions` base.
80
+ */
81
+ interface SqlAuthoringContributions extends AuthoringContributions {
82
+ readonly createNamespace?: SqlNamespaceFactory;
83
+ }
84
+ /**
85
+ * Narrows framework `AuthoringContributions` to the SQL-family shape by testing
86
+ * for the SQL-specific `createNamespace` capability.
87
+ */
88
+ declare function isSqlAuthoringContributions(authoring: AuthoringContributions | undefined): authoring is SqlAuthoringContributions;
67
89
  interface SqlStorageInput<THash extends string = string> {
68
90
  readonly storageHash: StorageHashBase<THash>;
69
91
  readonly types?: Record<string, SqlStorageTypeEntry>;
70
- readonly namespaces: Readonly<Record<string, SqlNamespace>>;
92
+ readonly namespaces: Readonly<Record<string, SqlNamespaceBase>>;
71
93
  }
72
94
  /**
73
95
  * SQL Contract IR root node for the `storage` field.
@@ -101,22 +123,43 @@ type SqlNamespaceEntries = Readonly<Record<string, Readonly<Record<string, unkno
101
123
  readonly valueSet?: Readonly<Record<string, StorageValueSet>>;
102
124
  };
103
125
  /**
104
- * SQL family namespace. `entries` is the open ADR 224 dictionary —
105
- * `entries[entityKind][entityName]` addresses any entity. Emitted
106
- * contract literals satisfy this structurally (no prototype getters
107
- * needed). For typed access to specific kinds, use the class getters
108
- * on the concretion or `ns.entries.table` / `ns.entries.valueSet` directly.
126
+ * Structural interface for SQL family namespaces. Generated `.d.ts` contract
127
+ * types satisfy this structurally (no prototype methods). The runtime
128
+ * abstract class `SqlNamespaceBase` extends this.
129
+ *
130
+ * `qualifyTable` and `isUnbound` are optional so JSON-shaped contract types
131
+ * (which carry no methods) are accepted where `SqlNamespace` is required.
132
+ * Hydrated `SqlNamespaceBase` instances always have both.
109
133
  */
110
- type SqlNamespace = Namespace & {
134
+ interface SqlNamespace {
135
+ readonly kind: string;
136
+ readonly id: string;
111
137
  readonly entries: SqlNamespaceEntries;
112
- /**
113
- * Render a dialect-qualified table reference for runtime SQL emission.
114
- * Present on materialised target concretions (`PostgresSchema`,
115
- * `SqliteDatabase`, …) and family placeholders; omitted on emitted
116
- * contract structural namespace literals (methods are not serialised).
117
- */
138
+ readonly isUnbound?: boolean;
118
139
  qualifyTable?(tableName: string): string;
119
- };
140
+ }
141
+ /**
142
+ * Abstract SQL family namespace base class. Target concretions (`PostgresSchema`,
143
+ * `SqliteDatabase`, …) extend this — it is never instantiated directly.
144
+ * `entries` is the open ADR 224 dictionary: `entries[entityKind][entityName]`
145
+ * addresses any entity.
146
+ */
147
+ declare abstract class SqlNamespaceBase extends NamespaceBase implements SqlNamespace {
148
+ abstract readonly id: string;
149
+ abstract readonly entries: SqlNamespaceEntries;
150
+ abstract qualifyTable(tableName: string): string;
151
+ }
152
+ /**
153
+ * Realm-safe guard for hydrated `SqlNamespaceBase` concretions. Checks
154
+ * `qualifyTable` structurally instead of `instanceof NamespaceBase`, so it
155
+ * survives duplicate-module boundaries (e.g. dist e2e where the target and
156
+ * the family carry separate copies of `@prisma-next/framework-components`).
157
+ *
158
+ * Every concrete `SqlNamespaceBase` subclass (`PostgresSchema`, `SqliteDatabase`,
159
+ * `TestSqlNamespace`, …) implements `qualifyTable`. Raw `SqlNamespaceInput`
160
+ * objects (`{ id, entries }`) do not.
161
+ */
162
+ declare function isMaterializedSqlNamespace(x: unknown): x is SqlNamespaceBase;
120
163
  declare class SqlStorage<THash extends string = string> extends SqlNode implements Storage {
121
164
  readonly storageHash: StorageHashBase<THash>;
122
165
  readonly namespaces: Readonly<Record<string, SqlNamespace>>;
@@ -124,5 +167,5 @@ declare class SqlStorage<THash extends string = string> extends SqlNode implemen
124
167
  constructor(input: SqlStorageInput<THash>);
125
168
  }
126
169
  //#endregion
127
- export { SqlStorageInput as a, StorageTypeInstance as c, toStorageTypeInstance as d, SqlStorage as i, StorageTypeInstanceInput as l, SqlNamespaceEntries as n, SqlStorageTypeEntry as o, SqlNamespaceTablesInput as r, CODEC_INSTANCE_KIND as s, SqlNamespace as t, isStorageTypeInstance as u };
128
- //# sourceMappingURL=sql-storage-Dga0jwP2.d.mts.map
170
+ export { SqlNamespaceFactory as a, SqlStorageInput as c, isSqlAuthoringContributions as d, CODEC_INSTANCE_KIND as f, toStorageTypeInstance as g, isStorageTypeInstance as h, SqlNamespaceEntries as i, SqlStorageTypeEntry as l, StorageTypeInstanceInput as m, SqlNamespace as n, SqlNamespaceInput as o, StorageTypeInstance as p, SqlNamespaceBase as r, SqlStorage as s, SqlAuthoringContributions as t, isMaterializedSqlNamespace as u };
171
+ //# sourceMappingURL=sql-storage-Dt5ipcRl.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sql-storage-Dt5ipcRl.d.mts","names":[],"sources":["../src/ir/storage-type-instance.ts","../src/ir/sql-storage.ts"],"mappings":";;;;;;;;;;;;;;;cASa,mBAAA;;;;AAA+C;AAU5D;;;;UAAiB,mBAAA,SAA4B,WAAA;EAAA,SAClC,IAAA,SAAa,mBAAA;EAAA,SACb,OAAA;EAAA,SACA,UAAA;EAAA,SACA,UAAA,EAAY,MAAA;AAAA;;;;;;;AAAM;UAUZ,wBAAA;EAAA,SACN,OAAA;EAAA,SACA,UAAA;EAAA,SACA,UAAA,GAAa,MAAM;AAAA;;;;;AAAA;iBAQd,qBAAA,CAAsB,KAAA,EAAO,wBAAA,GAA2B,mBAAmB;;;;;;iBAc3E,qBAAA,CAAsB,KAAA,YAAiB,KAAA,IAAS,mBAAmB;;;;AAjDnF;;;;AAA4D;AAU5D;KCOY,mBAAA,GAAsB,mBAAA,GAAsB,wBAAwB;AAAA,UAE/D,iBAAA;EAAA,SACN,EAAA;EAAA,SACA,OAAA,EAAS,QAAA,CAAS,MAAA,SAAe,QAAA,CAAS,MAAA;AAAA;;;;;KAOzC,mBAAA,IAAuB,KAAA,EAAO,iBAAA,KAAsB,SAAS;;;;;;ADd5C;AAU7B;UCaiB,yBAAA,SAAkC,sBAAsB;EAAA,SAC9D,eAAA,GAAkB,mBAAA;AAAA;;;;;iBAOb,2BAAA,CACd,SAAA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"@prisma-next/contract/types";
1
+ import { t as SqlNode } from "./sql-node-V214WXQD.mjs";
2
+ import { n as ForeignKeyInput, t as ForeignKey } from "./foreign-key-DM1UTydh.mjs";
3
+ import { ColumnDefault, ControlPolicy, ValueSetRef } from "@prisma-next/contract/types";
3
4
 
4
5
  //#region src/ir/check-constraint.d.ts
5
6
  /**
@@ -85,6 +86,7 @@ interface StorageColumnInput {
85
86
  readonly nativeType: string;
86
87
  readonly codecId: string;
87
88
  readonly nullable: boolean;
89
+ readonly many?: boolean;
88
90
  readonly typeParams?: Record<string, unknown>;
89
91
  readonly typeRef?: string;
90
92
  readonly default?: ColumnDefault;
@@ -108,6 +110,7 @@ declare class StorageColumn extends SqlNode {
108
110
  readonly nativeType: string;
109
111
  readonly codecId: string;
110
112
  readonly nullable: boolean;
113
+ readonly many?: boolean;
111
114
  readonly typeParams?: Record<string, unknown>;
112
115
  readonly typeRef?: string;
113
116
  readonly default?: ColumnDefault;
@@ -161,42 +164,16 @@ declare class StorageTable extends SqlNode {
161
164
  readonly control?: ControlPolicy;
162
165
  readonly checks?: ReadonlyArray<CheckConstraint>;
163
166
  constructor(input: StorageTableInput);
167
+ /**
168
+ * Runtime guard that a namespace `table` entry is really a `StorageTable`.
169
+ * The compiler already types the entry as `StorageTable`, but a
170
+ * freshly-deserialized contract may carry plain JSON at that slot until
171
+ * hydration; this duck-types the structural shape. Accepts `undefined` so
172
+ * optional-chained entry lookups pass straight through.
173
+ */
174
+ static is(value: StorageTable | undefined): value is StorageTable;
175
+ static assert(value: StorageTable | undefined, coordinate: string): asserts value is StorageTable;
164
176
  }
165
177
  //#endregion
166
- //#region src/ir/storage-value-set.d.ts
167
- /**
168
- * Hydration / construction input shape for {@link StorageValueSet}.
169
- * Mirrors the on-disk storage JSON envelope so the serializer hydration
170
- * walker can hand a validated literal straight to `new`.
171
- */
172
- interface StorageValueSetInput {
173
- readonly kind: 'valueSet';
174
- /** Ordered permitted values, codec-encoded. Declaration order is preserved. */
175
- readonly values: readonly JsonValue[];
176
- }
177
- /**
178
- * SQL Contract IR node for a value-set entry in a namespace's `valueSet`
179
- * map (`SqlNamespace.entries.valueSet`).
180
- *
181
- * A value-set records the ordered set of permitted codec-encoded values for
182
- * an enum-like column restriction. It does not carry a `codecId` — the
183
- * column that references it already holds the codec; the value-set holds
184
- * only the permitted values.
185
- *
186
- * The node's `kind` is enumerable (`'valueSet'`) so the JSON envelope
187
- * carries the discriminator and the serializer hydration walker can
188
- * dispatch on it. This follows the per-leaf enumerable-kind convention
189
- * established in the SQL-node comment (future polymorphic dispatch on
190
- * namespace entries needs the discriminator in JSON).
191
- *
192
- * The entry's name is not on the class — value-sets are keyed by name in
193
- * the parent namespace's `valueSet: Record<string, StorageValueSet>` map.
194
- */
195
- declare class StorageValueSet extends SqlNode {
196
- readonly kind: "valueSet";
197
- readonly values: readonly JsonValue[];
198
- constructor(input: StorageValueSetInput);
199
- }
200
- //#endregion
201
- export { UniqueConstraint as a, StorageColumnInput as c, PrimaryKey as d, PrimaryKeyInput as f, StorageTableInput as i, Index as l, CheckConstraintInput as m, StorageValueSetInput as n, UniqueConstraintInput as o, CheckConstraint as p, StorageTable as r, StorageColumn as s, StorageValueSet as t, IndexInput as u };
202
- //# sourceMappingURL=storage-value-set-WnYsIFM8.d.mts.map
178
+ export { StorageColumn as a, IndexInput as c, CheckConstraint as d, CheckConstraintInput as f, UniqueConstraintInput as i, PrimaryKey as l, StorageTableInput as n, StorageColumnInput as o, UniqueConstraint as r, Index as s, StorageTable as t, PrimaryKeyInput as u };
179
+ //# sourceMappingURL=storage-table-Bj1ZN1P7.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage-table-Bj1ZN1P7.d.mts","names":[],"sources":["../src/ir/check-constraint.ts","../src/ir/primary-key.ts","../src/ir/sql-index.ts","../src/ir/storage-column.ts","../src/ir/unique-constraint.ts","../src/ir/storage-table.ts"],"mappings":";;;;;;;;AASA;;UAAiB,oBAAA;EAAA,SACN,IAAA;EAAA,S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;EAAA,SAClC,OAAA;EAAA,SACQ,IAAA;cAEL,KAAA,EAAO,qBAAA;AAAA;;;UCLJ,iBAAA;EAAA,SACN,OAAA,EAAS,MAAA,SAAe,aAAA,GAAgB,kBAAA;EAAA,SACxC,UAAA,GAAa,UAAA,GAAa,eAAA;EAAA,SAC1B,OAAA,EAAS,aAAA,CAAc,gBAAA,GAAmB,qBAAA;EAAA,SAC1C,OAAA,EAAS,aAAA,CAAc,KAAA,GAAQ,UAAA;EAAA,SAC/B,WAAA,EAAa,aAAA,CAAc,UAAA,GAAa,eAAA;EAAA,SACxC,OAAA,GAAU,aAAA;EAAA,SACV,MAAA,GAAS,aAAA,CAAc,eAAA,GAAkB,oBAAA;AAAA;;;;;;;;;;;;;cAevC,YAAA,SAAqB,OAAA;EAAA,SACvB,OAAA,EAAS,QAAA,CAAS,MAAA,SAAe,aAAA;EAAA,SACjC,OAAA,EAAS,aAAA,CAAc,gBAAA;EAAA,SACvB,OAAA,EAAS,aAAA,CAAc,KAAA;EAAA,SACvB,WAAA,EAAa,aAAA,CAAc,UAAA;EAAA,SACnB,UAAA,GAAa,UAAA;EAAA,SACb,OAAA,GAAU,aAAA;EAAA,SACV,MAAA,GAAS,aAAA,CAAc,eAAA;cAE5B,KAAA,EAAO,iBAAA;;;AJpCN;AAMf;;;;SImES,EAAA,CAAG,KAAA,EAAO,YAAA,eAA2B,KAAA,IAAS,YAAA;EAAA,OAK9C,MAAA,CACL,KAAA,EAAO,YAAA,cACP,UAAA,mBACS,KAAA,IAAS,YAAA;AAAA"}
@@ -1,103 +1,5 @@
1
- import { type } from "arktype";
2
1
  import { IRNodeBase, freezeNode } from "@prisma-next/framework-components/ir";
3
2
  import { asNamespaceId } from "@prisma-next/contract/types";
4
- //#region src/ir/storage-entry-schemas.ts
5
- const literalKindSchema = type("'literal'");
6
- const functionKindSchema = type("'function'");
7
- const ControlPolicySchema = type("'managed' | 'tolerated' | 'external' | 'observed'");
8
- const ColumnDefaultLiteralSchema = type.declare().type({
9
- kind: literalKindSchema,
10
- value: "string | number | boolean | null | unknown[] | Record<string, unknown>"
11
- });
12
- const ColumnDefaultFunctionSchema = type.declare().type({
13
- kind: functionKindSchema,
14
- expression: "string"
15
- });
16
- const ColumnDefaultSchema = ColumnDefaultLiteralSchema.or(ColumnDefaultFunctionSchema);
17
- const StorageValueSetRefSchema = type({
18
- plane: "'storage'",
19
- namespaceId: "string",
20
- entityKind: "'valueSet'",
21
- entityName: "string",
22
- "spaceId?": "string"
23
- });
24
- const StorageColumnSchema = type({
25
- "+": "reject",
26
- nativeType: "string",
27
- codecId: "string",
28
- nullable: "boolean",
29
- "typeParams?": "Record<string, unknown>",
30
- "typeRef?": "string",
31
- "default?": ColumnDefaultSchema,
32
- "control?": ControlPolicySchema,
33
- "valueSet?": StorageValueSetRefSchema
34
- }).narrow((col, ctx) => {
35
- if (col.typeParams !== void 0 && col.typeRef !== void 0) return ctx.mustBe("a column with either typeParams or typeRef, not both");
36
- return true;
37
- });
38
- /**
39
- * Storage value-set entry under `storage.namespaces[id].entries.valueSet[name]`.
40
- * Carries a `kind: 'valueSet'` discriminator (enumerable, survives JSON) and an
41
- * ordered `values` array of codec-encoded permitted values.
42
- */
43
- const StorageValueSetSchema = type({
44
- kind: "'valueSet'",
45
- values: type("string | number | boolean | null | unknown[] | Record<string, unknown>").array().readonly()
46
- });
47
- const PrimaryKeySchema = type.declare().type({
48
- columns: type.string.array().readonly(),
49
- "name?": "string"
50
- });
51
- const UniqueConstraintSchema = type.declare().type({
52
- columns: type.string.array().readonly(),
53
- "name?": "string"
54
- });
55
- const IndexSchema = type({
56
- columns: type.string.array().readonly(),
57
- "name?": "string",
58
- "type?": "string",
59
- "options?": "Record<string, unknown>"
60
- });
61
- const ForeignKeyReferenceSchema = type({
62
- "+": "reject",
63
- namespaceId: "string",
64
- tableName: "string",
65
- columns: type.string.array().readonly(),
66
- "spaceId?": "string"
67
- });
68
- const ForeignKeySourceSchema = type({
69
- "+": "reject",
70
- namespaceId: "string",
71
- tableName: "string",
72
- columns: type.string.array().readonly()
73
- });
74
- const ReferentialActionSchema = type.declare().type("'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault'");
75
- const ForeignKeySchema = type.declare().type({
76
- source: ForeignKeySourceSchema,
77
- target: ForeignKeyReferenceSchema,
78
- "name?": "string",
79
- "onDelete?": ReferentialActionSchema,
80
- "onUpdate?": ReferentialActionSchema,
81
- constraint: "boolean",
82
- index: "boolean"
83
- });
84
- const CheckConstraintSchema = type({
85
- "+": "reject",
86
- name: "string",
87
- column: "string",
88
- valueSet: StorageValueSetRefSchema
89
- });
90
- const StorageTableSchema = type({
91
- "+": "reject",
92
- columns: type({ "[string]": StorageColumnSchema }),
93
- "primaryKey?": PrimaryKeySchema,
94
- uniques: UniqueConstraintSchema.array().readonly(),
95
- indexes: IndexSchema.array().readonly(),
96
- foreignKeys: ForeignKeySchema.array().readonly(),
97
- "control?": ControlPolicySchema,
98
- "checks?": CheckConstraintSchema.array().readonly()
99
- });
100
- //#endregion
101
3
  //#region src/ir/sql-node.ts
102
4
  /**
103
5
  * SQL family IR node base. Carries the family-level `kind` discriminator
@@ -292,6 +194,7 @@ var StorageColumn = class extends SqlNode {
292
194
  this.nativeType = input.nativeType;
293
195
  this.codecId = input.codecId;
294
196
  this.nullable = input.nullable;
197
+ if (input.many !== void 0) this.many = input.many;
295
198
  if (input.typeParams !== void 0) this.typeParams = input.typeParams;
296
199
  if (input.typeRef !== void 0) this.typeRef = input.typeRef;
297
200
  if (input.default !== void 0) this.default = input.default;
@@ -328,7 +231,7 @@ var UniqueConstraint = class extends SqlNode {
328
231
  * The table's `name` is not on the class — tables are keyed by name in
329
232
  * the parent namespace's `tables: Record<string, StorageTable>` map.
330
233
  */
331
- var StorageTable = class extends SqlNode {
234
+ var StorageTable = class StorageTable extends SqlNode {
332
235
  columns;
333
236
  uniques;
334
237
  indexes;
@@ -344,65 +247,22 @@ var StorageTable = class extends SqlNode {
344
247
  if (input.checks !== void 0 && input.checks.length > 0) this.checks = Object.freeze(input.checks.map((cc) => new CheckConstraint(cc)));
345
248
  freezeNode(this);
346
249
  }
347
- };
348
- //#endregion
349
- //#region src/ir/storage-value-set.ts
350
- /**
351
- * SQL Contract IR node for a value-set entry in a namespace's `valueSet`
352
- * map (`SqlNamespace.entries.valueSet`).
353
- *
354
- * A value-set records the ordered set of permitted codec-encoded values for
355
- * an enum-like column restriction. It does not carry a `codecId` — the
356
- * column that references it already holds the codec; the value-set holds
357
- * only the permitted values.
358
- *
359
- * The node's `kind` is enumerable (`'valueSet'`) so the JSON envelope
360
- * carries the discriminator and the serializer hydration walker can
361
- * dispatch on it. This follows the per-leaf enumerable-kind convention
362
- * established in the SQL-node comment (future polymorphic dispatch on
363
- * namespace entries needs the discriminator in JSON).
364
- *
365
- * The entry's name is not on the class — value-sets are keyed by name in
366
- * the parent namespace's `valueSet: Record<string, StorageValueSet>` map.
367
- */
368
- var StorageValueSet = class extends SqlNode {
369
- kind = "valueSet";
370
- values;
371
- constructor(input) {
372
- super();
373
- this.values = Object.freeze([...input.values]);
374
- freezeNode(this);
250
+ /**
251
+ * Runtime guard that a namespace `table` entry is really a `StorageTable`.
252
+ * The compiler already types the entry as `StorageTable`, but a
253
+ * freshly-deserialized contract may carry plain JSON at that slot until
254
+ * hydration; this duck-types the structural shape. Accepts `undefined` so
255
+ * optional-chained entry lookups pass straight through.
256
+ */
257
+ static is(value) {
258
+ if (typeof value !== "object" || value === null) return false;
259
+ return "columns" in value && "uniques" in value && "indexes" in value && "foreignKeys" in value;
375
260
  }
376
- };
377
- //#endregion
378
- //#region src/entity-kinds.ts
379
- const tableEntityKind = {
380
- kind: "table",
381
- schema: StorageTableSchema,
382
- construct: (input) => new StorageTable(input)
383
- };
384
- const valueSetEntityKind = {
385
- kind: "valueSet",
386
- schema: StorageValueSetSchema,
387
- construct: (input) => new StorageValueSet(input)
388
- };
389
- /**
390
- * Assembles the `kind → descriptor` registry for SQL namespaces: the built-in
391
- * `table` and `valueSet` kinds plus any target `packKinds`. This builds the
392
- * lookup table — it does not touch contract data. `hydrateNamespaceEntities`
393
- * later consumes this registry to turn a namespace's raw entries into IR
394
- * instances, and `createSqlContractSchema` derives validation from the same
395
- * registry. Throws on a duplicate kind.
396
- */
397
- function composeSqlEntityKinds(packKinds = []) {
398
- const kinds = new Map([["table", tableEntityKind], ["valueSet", valueSetEntityKind]]);
399
- for (const descriptor of packKinds) {
400
- if (kinds.has(descriptor.kind)) throw new Error(`composeSqlEntityKinds: duplicate entity kind "${descriptor.kind}" — each kind may be registered only once`);
401
- kinds.set(descriptor.kind, descriptor);
261
+ static assert(value, coordinate) {
262
+ if (!StorageTable.is(value)) throw new Error(`Expected a StorageTable at ${coordinate}`);
402
263
  }
403
- return kinds;
404
- }
264
+ };
405
265
  //#endregion
406
- export { StorageTableSchema as C, ReferentialActionSchema as S, ColumnDefaultSchema as _, StorageTable as a, ForeignKeySourceSchema as b, Index as c, ForeignKeyReference as d, CheckConstraint as f, ColumnDefaultLiteralSchema as g, ColumnDefaultFunctionSchema as h, StorageValueSet as i, PrimaryKey as l, CheckConstraintSchema as m, tableEntityKind as n, UniqueConstraint as o, SqlNode as p, valueSetEntityKind as r, StorageColumn as s, composeSqlEntityKinds as t, ForeignKey as u, ForeignKeyReferenceSchema as v, StorageValueSetSchema as w, IndexSchema as x, ForeignKeySchema as y };
266
+ export { PrimaryKey as a, CheckConstraint as c, Index as i, SqlNode as l, UniqueConstraint as n, ForeignKey as o, StorageColumn as r, ForeignKeyReference as s, StorageTable as t };
407
267
 
408
- //# sourceMappingURL=entity-kinds-Cl36zL5j.mjs.map
268
+ //# sourceMappingURL=storage-table-y6R6pxyI.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage-table-y6R6pxyI.mjs","names":[],"sources":["../src/ir/sql-node.ts","../src/ir/check-constraint.ts","../src/ir/foreign-key-reference.ts","../src/ir/foreign-key.ts","../src/ir/primary-key.ts","../src/ir/sql-index.ts","../src/ir/storage-column.ts","../src/ir/unique-constraint.ts","../src/ir/storage-table.ts"],"sourcesContent":["import { IRNodeBase } from '@prisma-next/framework-components/ir';\n\n/**\n * SQL family IR node base. Carries the family-level `kind` discriminator\n * `'sql'` and inherits the framework's `freezeNode` affordance.\n *\n * Single family-level discriminator (not per-leaf) reflects the fact that\n * SQL IR has no polymorphic dispatch today — verifiers and serializers\n * walk by structural position (`storage.tables[name].columns[name]`),\n * not by inspecting `kind`. The abstract bar for per-leaf discriminators\n * isn't earned until a future polymorphic consumer arrives.\n *\n * `kind` is installed as a non-enumerable own property on every instance,\n * which keeps three things clean simultaneously:\n *\n * - `JSON.stringify(node)` produces the canonical pre-lift JSON envelope\n * shape (no `kind` field), so emitted contract.json files and the\n * `validateSqlContractFully` arktype schemas stay unchanged.\n * - Test assertions that use `toEqual({...})` against the pre-lift flat\n * shape continue to pass — only enumerable own properties are\n * compared.\n * - Direct access (`node.kind`) and runtime narrowing\n * (`if (node.kind === 'sql')`) still work, so future polymorphic\n * dispatch can begin reading `kind` without a runtime change.\n *\n * Future per-leaf overrides land cleanly: a class that gains a\n * polymorphic-dispatch consumer (e.g. an enum type instance walked\n * alongside other types) overrides `kind` with its narrower literal\n * at that leaf level. Per-leaf overrides will use enumerable kind\n * (matching the Mongo per-class-discriminator precedent) because they\n * encode dispatch-relevant information that callers need to see in\n * JSON envelopes; the family-level `'sql'` is uniform across all SQL\n * IR and carries no dispatch-relevant information.\n */\nexport abstract class SqlNode extends IRNodeBase {\n readonly kind?: string;\n\n constructor() {\n super();\n Object.defineProperty(this, 'kind', {\n value: 'sql',\n writable: false,\n enumerable: false,\n // configurable so per-leaf subclasses (e.g. StorageValueSet)\n // can override `kind` with their narrower\n // enumerable literal via a class-field initializer. SqlNode\n // itself never needs to mutate the property again, so\n // configurability has no surface impact at this layer.\n configurable: true,\n });\n }\n}\n","import type { ValueSetRef } from '@prisma-next/contract/types';\nimport { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from './sql-node';\n\n/**\n * Hydration / construction input shape for {@link CheckConstraint}.\n * Mirrors the on-disk storage JSON envelope so the serializer hydration\n * walker can hand a validated literal straight to `new`.\n */\nexport interface CheckConstraintInput {\n readonly name: string;\n readonly column: string;\n readonly valueSet: ValueSetRef;\n}\n\n/**\n * SQL Contract IR node for a table-level check constraint that restricts\n * a column to the permitted values of a value-set.\n *\n * The constraint is **structured** (names a column and a value-set\n * reference), not a raw SQL expression. Each target renders its own DDL\n * from the structured form, keeping the contract target-agnostic.\n *\n * Construction is idempotent: passing an existing `CheckConstraint`\n * instance as input produces a new instance with identical fields.\n * The constructor does not use `instanceof` for input discrimination —\n * it reads plain named properties, which is sufficient since\n * `CheckConstraintInput` is a structural type.\n */\nexport class CheckConstraint extends SqlNode {\n readonly name: string;\n readonly column: string;\n readonly valueSet: ValueSetRef;\n\n constructor(input: CheckConstraintInput) {\n super();\n this.name = input.name;\n this.column = input.column;\n this.valueSet = input.valueSet;\n freezeNode(this);\n }\n}\n","import { asNamespaceId, type NamespaceId } from '@prisma-next/contract/types';\nimport { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from './sql-node';\n\n/**\n * Input for a foreign-key reference (one side of a foreign-key declaration).\n *\n * When `spaceId` is absent the reference is local — the referenced table lives\n * in the same contract-space. When `spaceId` is present the reference is\n * cross-space — the referenced table lives in a different contract-space\n * identified by `spaceId`.\n *\n * Presence-based discrimination keeps local FK JSON byte-identical to\n * contracts authored before cross-space support was added.\n */\nexport interface ForeignKeyReferenceInput {\n readonly namespaceId: string;\n readonly tableName: string;\n readonly columns: readonly string[];\n readonly spaceId?: string;\n}\n\n/**\n * SQL Contract IR node for one side (source or target) of a foreign-key\n * declaration. Carries the full coordinate: namespace, table, and columns.\n *\n * Cross-space discrimination is based on `spaceId` presence: absent means\n * local (same contract-space); present means cross-space (the referenced\n * table lives in the contract-space identified by `spaceId`).\n *\n * For local references `spaceId` is absent from JSON, keeping the serialized\n * shape byte-identical to contracts authored before cross-space support was\n * added. For cross-space references `spaceId` appears in JSON so round-trips\n * are lossless.\n *\n * Use `UNBOUND_NAMESPACE_ID` from `@prisma-next/framework-components/ir`\n * as the sentinel `namespaceId` for single-namespace (unbound) references.\n */\nexport class ForeignKeyReference extends SqlNode {\n readonly namespaceId: NamespaceId;\n readonly tableName: string;\n readonly columns: readonly string[];\n declare readonly spaceId?: string;\n\n constructor(input: ForeignKeyReferenceInput) {\n super();\n this.namespaceId = asNamespaceId(input.namespaceId);\n this.tableName = input.tableName;\n this.columns = input.columns;\n if (input.spaceId !== undefined) this.spaceId = input.spaceId;\n freezeNode(this);\n }\n}\n","import { freezeNode } from '@prisma-next/framework-components/ir';\nimport { ForeignKeyReference, type ForeignKeyReferenceInput } from './foreign-key-reference';\nimport { SqlNode } from './sql-node';\n\nexport type ReferentialAction = 'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault';\n\nexport interface ForeignKeyInput {\n readonly source: ForeignKeyReference | ForeignKeyReferenceInput;\n readonly target: ForeignKeyReference | ForeignKeyReferenceInput;\n readonly name?: string;\n readonly onDelete?: ReferentialAction;\n readonly onUpdate?: ReferentialAction;\n /** Whether to emit FK constraint DDL (ALTER TABLE … ADD CONSTRAINT … FOREIGN KEY). */\n readonly constraint: boolean;\n /** Whether to emit a backing index for the FK columns. */\n readonly index: boolean;\n}\n\n/**\n * SQL Contract IR node for a table-level foreign-key declaration.\n *\n * Each FK carries explicit `source` and `target` {@link ForeignKeyReference}\n * coordinates (namespace, table, columns). For single-namespace contracts the\n * sentinel `UNBOUND_NAMESPACE_ID` appears on both sides.\n *\n * The nested references are normalised to {@link ForeignKeyReference}\n * instances inside the constructor so downstream walks see a uniform AST\n * regardless of whether the input was a JSON literal or an already-constructed\n * class instance.\n */\nexport class ForeignKey extends SqlNode {\n readonly source: ForeignKeyReference;\n readonly target: ForeignKeyReference;\n readonly constraint: boolean;\n readonly index: boolean;\n declare readonly name?: string;\n declare readonly onDelete?: ReferentialAction;\n declare readonly onUpdate?: ReferentialAction;\n\n constructor(input: ForeignKeyInput) {\n super();\n this.source =\n input.source instanceof ForeignKeyReference\n ? input.source\n : new ForeignKeyReference(input.source);\n this.target =\n input.target instanceof ForeignKeyReference\n ? input.target\n : new ForeignKeyReference(input.target);\n this.constraint = input.constraint;\n this.index = input.index;\n if (input.name !== undefined) this.name = input.name;\n if (input.onDelete !== undefined) this.onDelete = input.onDelete;\n if (input.onUpdate !== undefined) this.onUpdate = input.onUpdate;\n freezeNode(this);\n }\n}\n","import { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from './sql-node';\n\nexport interface PrimaryKeyInput {\n readonly columns: readonly string[];\n readonly name?: string;\n}\n\n/**\n * SQL Contract IR node for a table's primary-key constraint.\n */\nexport class PrimaryKey extends SqlNode {\n readonly columns: readonly string[];\n declare readonly name?: string;\n\n constructor(input: PrimaryKeyInput) {\n super();\n this.columns = input.columns;\n if (input.name !== undefined) this.name = input.name;\n freezeNode(this);\n }\n}\n","import { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from './sql-node';\n\nexport interface IndexInput {\n readonly columns: readonly string[];\n readonly name?: string;\n readonly type?: string;\n readonly options?: Record<string, unknown>;\n}\n\n/**\n * SQL Contract IR node for a table-level secondary index.\n *\n * Note that this class shadows the global TypeScript `Index` lib type\n * at the family-shared name; consumer files that need both should\n * alias one (e.g.\n * `import { Index as SqlIndexNode } from '@prisma-next/sql-contract/types'`).\n */\nexport class Index extends SqlNode {\n readonly columns: readonly string[];\n declare readonly name?: string;\n declare readonly type?: string;\n declare readonly options?: Record<string, unknown>;\n\n constructor(input: IndexInput) {\n super();\n this.columns = input.columns;\n if (input.name !== undefined) this.name = input.name;\n if (input.type !== undefined) this.type = input.type;\n if (input.options !== undefined) this.options = input.options;\n freezeNode(this);\n }\n}\n","import type { ColumnDefault, ControlPolicy, ValueSetRef } from '@prisma-next/contract/types';\nimport { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from './sql-node';\n\n/**\n * Hydration / construction input shape for {@link StorageColumn}. Mirrors\n * the on-disk storage JSON envelope exactly so the family-base\n * serializer's hydration walker can hand an arktype-validated literal\n * straight to `new`.\n *\n * `typeParams` and `typeRef` remain mutually exclusive (one or the\n * other, not both); the constructor preserves whichever caller-side\n * choice the input encodes.\n */\nexport interface StorageColumnInput {\n readonly nativeType: string;\n readonly codecId: string;\n readonly nullable: boolean;\n readonly many?: boolean;\n readonly typeParams?: Record<string, unknown>;\n readonly typeRef?: string;\n readonly default?: ColumnDefault;\n readonly control?: ControlPolicy;\n readonly valueSet?: ValueSetRef;\n}\n\n/**\n * SQL Contract IR node for a single column entry in `StorageTable.columns`.\n *\n * Single concrete family-shared class — every SQL target reads the\n * same column shape today, so there is no per-target subclass. The\n * class type accepts any caller that constructs via\n * `new StorageColumn(input)`; literal construction sites must pass\n * through the constructor or the family-base hydration walker.\n *\n * The column's `name` is not on the class — columns are keyed by name\n * in the parent `StorageTable.columns: Record<string, StorageColumn>`\n * map, so a `name` field would be redundant with the key.\n */\nexport class StorageColumn extends SqlNode {\n readonly nativeType: string;\n readonly codecId: string;\n readonly nullable: boolean;\n declare readonly many?: boolean;\n declare readonly typeParams?: Record<string, unknown>;\n declare readonly typeRef?: string;\n declare readonly default?: ColumnDefault;\n declare readonly control?: ControlPolicy;\n declare readonly valueSet?: ValueSetRef;\n\n constructor(input: StorageColumnInput) {\n super();\n this.nativeType = input.nativeType;\n this.codecId = input.codecId;\n this.nullable = input.nullable;\n if (input.many !== undefined) this.many = input.many;\n if (input.typeParams !== undefined) this.typeParams = input.typeParams;\n if (input.typeRef !== undefined) this.typeRef = input.typeRef;\n if (input.default !== undefined) this.default = input.default;\n if (input.control !== undefined) this.control = input.control;\n if (input.valueSet !== undefined) this.valueSet = input.valueSet;\n freezeNode(this);\n }\n}\n","import { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from './sql-node';\n\nexport interface UniqueConstraintInput {\n readonly columns: readonly string[];\n readonly name?: string;\n}\n\n/**\n * SQL Contract IR node for a table-level unique constraint.\n */\nexport class UniqueConstraint extends SqlNode {\n readonly columns: readonly string[];\n declare readonly name?: string;\n\n constructor(input: UniqueConstraintInput) {\n super();\n this.columns = input.columns;\n if (input.name !== undefined) this.name = input.name;\n freezeNode(this);\n }\n}\n","import type { ControlPolicy } from '@prisma-next/contract/types';\nimport { freezeNode } from '@prisma-next/framework-components/ir';\nimport { CheckConstraint, type CheckConstraintInput } from './check-constraint';\nimport { ForeignKey, type ForeignKeyInput } from './foreign-key';\nimport { PrimaryKey, type PrimaryKeyInput } from './primary-key';\nimport { Index, type IndexInput } from './sql-index';\nimport { SqlNode } from './sql-node';\nimport { StorageColumn, type StorageColumnInput } from './storage-column';\nimport { UniqueConstraint, type UniqueConstraintInput } from './unique-constraint';\n\nexport interface StorageTableInput {\n readonly columns: Record<string, StorageColumn | StorageColumnInput>;\n readonly primaryKey?: PrimaryKey | PrimaryKeyInput;\n readonly uniques: ReadonlyArray<UniqueConstraint | UniqueConstraintInput>;\n readonly indexes: ReadonlyArray<Index | IndexInput>;\n readonly foreignKeys: ReadonlyArray<ForeignKey | ForeignKeyInput>;\n readonly control?: ControlPolicy;\n readonly checks?: ReadonlyArray<CheckConstraint | CheckConstraintInput>;\n}\n\n/**\n * SQL Contract IR node for a single table entry in a namespace's\n * `tables` map.\n *\n * The constructor normalises nested IR-class fields (columns, primary\n * key, uniques, indexes, foreign keys) into the appropriate class\n * instances so downstream walks see a uniform AST regardless of whether\n * the input was a JSON literal or an already-constructed class.\n *\n * The table's `name` is not on the class — tables are keyed by name in\n * the parent namespace's `tables: Record<string, StorageTable>` map.\n */\nexport class StorageTable extends SqlNode {\n readonly columns: Readonly<Record<string, StorageColumn>>;\n readonly uniques: ReadonlyArray<UniqueConstraint>;\n readonly indexes: ReadonlyArray<Index>;\n readonly foreignKeys: ReadonlyArray<ForeignKey>;\n declare readonly primaryKey?: PrimaryKey;\n declare readonly control?: ControlPolicy;\n declare readonly checks?: ReadonlyArray<CheckConstraint>;\n\n constructor(input: StorageTableInput) {\n super();\n this.columns = Object.freeze(\n Object.fromEntries(\n Object.entries(input.columns).map(([name, col]) => [\n name,\n col instanceof StorageColumn ? col : new StorageColumn(col),\n ]),\n ),\n );\n if (input.primaryKey !== undefined) {\n this.primaryKey =\n input.primaryKey instanceof PrimaryKey\n ? input.primaryKey\n : new PrimaryKey(input.primaryKey);\n }\n this.uniques = Object.freeze(\n input.uniques.map((u) => (u instanceof UniqueConstraint ? u : new UniqueConstraint(u))),\n );\n this.indexes = Object.freeze(input.indexes.map((i) => (i instanceof Index ? i : new Index(i))));\n this.foreignKeys = Object.freeze(\n input.foreignKeys.map((fk) => (fk instanceof ForeignKey ? fk : new ForeignKey(fk))),\n );\n if (input.control !== undefined) this.control = input.control;\n if (input.checks !== undefined && input.checks.length > 0) {\n this.checks = Object.freeze(input.checks.map((cc) => new CheckConstraint(cc)));\n }\n freezeNode(this);\n }\n\n /**\n * Runtime guard that a namespace `table` entry is really a `StorageTable`.\n * The compiler already types the entry as `StorageTable`, but a\n * freshly-deserialized contract may carry plain JSON at that slot until\n * hydration; this duck-types the structural shape. Accepts `undefined` so\n * optional-chained entry lookups pass straight through.\n */\n static is(value: StorageTable | undefined): value is StorageTable {\n if (typeof value !== 'object' || value === null) return false;\n return 'columns' in value && 'uniques' in value && 'indexes' in value && 'foreignKeys' in value;\n }\n\n static assert(\n value: StorageTable | undefined,\n coordinate: string,\n ): asserts value is StorageTable {\n if (!StorageTable.is(value)) {\n throw new Error(`Expected a StorageTable at ${coordinate}`);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,IAAsB,UAAtB,cAAsC,WAAW;CAC/C;CAEA,cAAc;EACZ,MAAM;EACN,OAAO,eAAe,MAAM,QAAQ;GAClC,OAAO;GACP,UAAU;GACV,YAAY;GAMZ,cAAc;EAChB,CAAC;CACH;AACF;;;;;;;;;;;;;;;;;ACtBA,IAAa,kBAAb,cAAqC,QAAQ;CAC3C;CACA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