@prisma-next/sql-contract 0.12.0-dev.5 → 0.12.0-dev.51

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 (42) hide show
  1. package/dist/canonicalization-hooks.mjs +10 -5
  2. package/dist/canonicalization-hooks.mjs.map +1 -1
  3. package/dist/factories.d.mts +3 -2
  4. package/dist/factories.d.mts.map +1 -1
  5. package/dist/factories.mjs +3 -2
  6. package/dist/factories.mjs.map +1 -1
  7. package/dist/index-type-validation.d.mts +2 -2
  8. package/dist/index-type-validation.mjs +1 -1
  9. package/dist/index-type-validation.mjs.map +1 -1
  10. package/dist/{index-types-B1cf5N0F.d.mts → index-types-DqVqGHwg.d.mts} +1 -1
  11. package/dist/{index-types-B1cf5N0F.d.mts.map → index-types-DqVqGHwg.d.mts.map} +1 -1
  12. package/dist/index-types.d.mts +1 -1
  13. package/dist/resolve-storage-table.d.mts +17 -0
  14. package/dist/resolve-storage-table.d.mts.map +1 -0
  15. package/dist/resolve-storage-table.mjs +26 -0
  16. package/dist/resolve-storage-table.mjs.map +1 -0
  17. package/dist/{types-Cx_5A_L0.d.mts → sql-storage-CV7Tc9Vh.d.mts} +27 -208
  18. package/dist/sql-storage-CV7Tc9Vh.d.mts.map +1 -0
  19. package/dist/types-BaoyuVGt.d.mts +207 -0
  20. package/dist/types-BaoyuVGt.d.mts.map +1 -0
  21. package/dist/{types-YQrDHy-b.mjs → types-ByD-iN24.mjs} +25 -26
  22. package/dist/types-ByD-iN24.mjs.map +1 -0
  23. package/dist/types.d.mts +3 -2
  24. package/dist/types.mjs +2 -2
  25. package/dist/validators.d.mts +3 -3
  26. package/dist/validators.d.mts.map +1 -1
  27. package/dist/validators.mjs +16 -16
  28. package/dist/validators.mjs.map +1 -1
  29. package/package.json +8 -7
  30. package/src/canonicalization-hooks.ts +5 -5
  31. package/src/exports/resolve-storage-table.ts +1 -0
  32. package/src/exports/types.ts +2 -0
  33. package/src/factories.ts +2 -1
  34. package/src/index-type-validation.ts +1 -1
  35. package/src/ir/build-sql-namespace.ts +28 -23
  36. package/src/ir/sql-storage.ts +41 -50
  37. package/src/ir/sql-unbound-namespace.ts +11 -4
  38. package/src/resolve-storage-table.ts +41 -0
  39. package/src/types.ts +11 -0
  40. package/src/validators.ts +30 -27
  41. package/dist/types-Cx_5A_L0.d.mts.map +0 -1
  42. package/dist/types-YQrDHy-b.mjs.map +0 -1
@@ -5,20 +5,23 @@ const sqlContractCanonicalizationHooks = {
5
5
  "storage",
6
6
  "namespaces",
7
7
  "*",
8
- "tables"
8
+ "entries",
9
+ "table"
9
10
  ],
10
11
  [
11
12
  "storage",
12
13
  "namespaces",
13
14
  "*",
14
- "tables",
15
+ "entries",
16
+ "table",
15
17
  "*"
16
18
  ],
17
19
  [
18
20
  "storage",
19
21
  "namespaces",
20
22
  "*",
21
- "tables",
23
+ "entries",
24
+ "table",
22
25
  "*",
23
26
  [
24
27
  "uniques",
@@ -30,7 +33,8 @@ const sqlContractCanonicalizationHooks = {
30
33
  "storage",
31
34
  "namespaces",
32
35
  "*",
33
- "tables",
36
+ "entries",
37
+ "table",
34
38
  "*",
35
39
  "foreignKeys",
36
40
  ["constraint", "index"]
@@ -46,7 +50,8 @@ const sqlContractCanonicalizationHooks = {
46
50
  path: [
47
51
  "namespaces",
48
52
  "*",
49
- "tables",
53
+ "entries",
54
+ "table",
50
55
  "*"
51
56
  ],
52
57
  arrayKeys: ["indexes", "uniques"]
@@ -1 +1 @@
1
- {"version":3,"file":"canonicalization-hooks.mjs","names":[],"sources":["../src/canonicalization-hooks.ts"],"sourcesContent":["import type { PreserveEmptyPredicate, StorageSort } from '@prisma-next/contract/hashing';\nimport {\n createPreserveEmptyPredicate,\n createStorageSort,\n type NamedArraySortTarget,\n type PathPattern,\n} from '@prisma-next/contract/hashing-utils';\n\nconst preserveEmptyPatterns = [\n ['storage', 'namespaces', '*', 'tables'],\n ['storage', 'namespaces', '*', 'tables', '*'],\n ['storage', 'namespaces', '*', 'tables', '*', ['uniques', 'indexes', 'foreignKeys']],\n ['storage', 'namespaces', '*', 'tables', '*', 'foreignKeys', ['constraint', 'index']],\n ['storage', 'types', '*', 'typeParams'],\n] as const satisfies readonly PathPattern[];\n\nconst sortTargets = [\n { path: ['namespaces', '*', 'tables', '*'], arrayKeys: ['indexes', 'uniques'] },\n] as const satisfies readonly NamedArraySortTarget[];\n\nconst shouldPreserveEmpty: PreserveEmptyPredicate =\n createPreserveEmptyPredicate(preserveEmptyPatterns);\n\nconst sortStorage: StorageSort = createStorageSort(sortTargets);\n\nexport const sqlContractCanonicalizationHooks: {\n readonly shouldPreserveEmpty: PreserveEmptyPredicate;\n readonly sortStorage: StorageSort;\n} = {\n shouldPreserveEmpty,\n sortStorage,\n};\n"],"mappings":";AAyBA,MAAa,mCAGT;CACF,qBARA,6BAA6B;EAZ7B;GAAC;GAAW;GAAc;GAAK;EAAQ;EACvC;GAAC;GAAW;GAAc;GAAK;GAAU;EAAG;EAC5C;GAAC;GAAW;GAAc;GAAK;GAAU;GAAK;IAAC;IAAW;IAAW;GAAa;EAAC;EACnF;GAAC;GAAW;GAAc;GAAK;GAAU;GAAK;GAAe,CAAC,cAAc,OAAO;EAAC;EACpF;GAAC;GAAW;GAAS;GAAK;EAAY;CAQT,CAQ7B;CACA,aAP+B,kBAAkB,CANjD;EAAE,MAAM;GAAC;GAAc;GAAK;GAAU;EAAG;EAAG,WAAW,CAAC,WAAW,SAAS;CAAE,CAM7B,CAOjD;AACF"}
1
+ {"version":3,"file":"canonicalization-hooks.mjs","names":[],"sources":["../src/canonicalization-hooks.ts"],"sourcesContent":["import type { PreserveEmptyPredicate, StorageSort } from '@prisma-next/contract/hashing';\nimport {\n createPreserveEmptyPredicate,\n createStorageSort,\n type NamedArraySortTarget,\n type PathPattern,\n} from '@prisma-next/contract/hashing-utils';\n\nconst preserveEmptyPatterns = [\n ['storage', 'namespaces', '*', 'entries', 'table'],\n ['storage', 'namespaces', '*', 'entries', 'table', '*'],\n ['storage', 'namespaces', '*', 'entries', 'table', '*', ['uniques', 'indexes', 'foreignKeys']],\n ['storage', 'namespaces', '*', 'entries', 'table', '*', 'foreignKeys', ['constraint', 'index']],\n ['storage', 'types', '*', 'typeParams'],\n] as const satisfies readonly PathPattern[];\n\nconst sortTargets = [\n { path: ['namespaces', '*', 'entries', 'table', '*'], arrayKeys: ['indexes', 'uniques'] },\n] as const satisfies readonly NamedArraySortTarget[];\n\nconst shouldPreserveEmpty: PreserveEmptyPredicate =\n createPreserveEmptyPredicate(preserveEmptyPatterns);\n\nconst sortStorage: StorageSort = createStorageSort(sortTargets);\n\nexport const sqlContractCanonicalizationHooks: {\n readonly shouldPreserveEmpty: PreserveEmptyPredicate;\n readonly sortStorage: StorageSort;\n} = {\n shouldPreserveEmpty,\n sortStorage,\n};\n"],"mappings":";AAyBA,MAAa,mCAGT;CACF,qBARA,6BAA6B;EAZ7B;GAAC;GAAW;GAAc;GAAK;GAAW;EAAO;EACjD;GAAC;GAAW;GAAc;GAAK;GAAW;GAAS;EAAG;EACtD;GAAC;GAAW;GAAc;GAAK;GAAW;GAAS;GAAK;IAAC;IAAW;IAAW;GAAa;EAAC;EAC7F;GAAC;GAAW;GAAc;GAAK;GAAW;GAAS;GAAK;GAAe,CAAC,cAAc,OAAO;EAAC;EAC9F;GAAC;GAAW;GAAS;GAAK;EAAY;CAQT,CAQ7B;CACA,aAP+B,kBAAkB,CANjD;EAAE,MAAM;GAAC;GAAc;GAAK;GAAW;GAAS;EAAG;EAAG,WAAW,CAAC,WAAW,SAAS;CAAE,CAMvC,CAOjD;AACF"}
@@ -1,4 +1,5 @@
1
- import { G as PrimaryKey, H as StorageColumnInput, L as StorageTable, U as Index, V as StorageColumn, X as ForeignKey, b as SqlModelStorage, f as ForeignKeyOptions, y as SqlModelFieldStorage, z as UniqueConstraint } from "./types-Cx_5A_L0.mjs";
1
+ import { S as ForeignKey, _ as StorageColumnInput, b as PrimaryKey, f as StorageTable, g as StorageColumn, m as UniqueConstraint, v as Index } from "./sql-storage-CV7Tc9Vh.mjs";
2
+ import { b as SqlModelFieldStorage, f as ForeignKeyOptions, x as SqlModelStorage } from "./types-BaoyuVGt.mjs";
2
3
  import { ScalarFieldType } from "@prisma-next/contract/types";
3
4
 
4
5
  //#region src/factories.d.ts
@@ -17,7 +18,7 @@ declare function table(columns: Record<string, StorageColumn | StorageColumnInpu
17
18
  indexes?: readonly Index[];
18
19
  fks?: readonly ForeignKey[];
19
20
  }): StorageTable;
20
- declare function model(tableName: string, fields: Record<string, SqlModelFieldStorage>, relations?: Record<string, unknown>): {
21
+ declare function model(tableName: string, fields: Record<string, SqlModelFieldStorage>, relations?: Record<string, unknown>, namespaceId?: string): {
21
22
  storage: SqlModelStorage;
22
23
  fields: Record<string, {
23
24
  readonly nullable: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"factories.d.mts","names":[],"sources":["../src/factories.ts"],"mappings":";;;;iBAgBgB,GAAA,CAAI,UAAA,UAAoB,OAAA,UAAiB,QAAA,aAAmB,aAAa;AAAA,iBAIzE,EAAA,CAAA,GAAM,OAAA,sBAA6B,UAAU;AAAA,iBAI7C,MAAA,CAAA,GAAU,OAAA,sBAA6B,gBAAgB;AAAA,iBAIvD,KAAA,CAAA,GAAS,OAAA,sBAA6B,KAAK;AAAA,iBAI3C,EAAA,CACd,YAAA,UACA,UAAA,qBACA,eAAA,UACA,aAAA,qBACA,IAAA,GAAO,iBAAA;EAAsB,UAAA;EAAsB,KAAA;EAAiB,WAAA;AAAA,IACnE,UAAU;AAAA,iBAcG,KAAA,CACd,OAAA,EAAS,MAAA,SAAe,aAAA,GAAgB,kBAAA,GACxC,IAAA;EACE,EAAA,GAAK,UAAA;EACL,OAAA,YAAmB,gBAAA;EACnB,OAAA,YAAmB,KAAA;EACnB,GAAA,YAAe,UAAA;AAAA,IAEhB,YAAA;AAAA,iBAUa,KAAA,CACd,SAAA,UACA,MAAA,EAAQ,MAAA,SAAe,oBAAA,GACvB,SAAA,GAAW,MAAA;EAEX,OAAA,EAAS,eAAA;EACT,MAAA,EAAQ,MAAA;IAAA,SAA0B,QAAA;IAAA,SAA4B,IAAA,EAAM,eAAA;EAAA;EACpE,SAAA,EAAW,MAAA;AAAA"}
1
+ {"version":3,"file":"factories.d.mts","names":[],"sources":["../src/factories.ts"],"mappings":";;;;;iBAgBgB,GAAA,CAAI,UAAA,UAAoB,OAAA,UAAiB,QAAA,aAAmB,aAAa;AAAA,iBAIzE,EAAA,CAAA,GAAM,OAAA,sBAA6B,UAAU;AAAA,iBAI7C,MAAA,CAAA,GAAU,OAAA,sBAA6B,gBAAgB;AAAA,iBAIvD,KAAA,CAAA,GAAS,OAAA,sBAA6B,KAAK;AAAA,iBAI3C,EAAA,CACd,YAAA,UACA,UAAA,qBACA,eAAA,UACA,aAAA,qBACA,IAAA,GAAO,iBAAA;EAAsB,UAAA;EAAsB,KAAA;EAAiB,WAAA;AAAA,IACnE,UAAU;AAAA,iBAcG,KAAA,CACd,OAAA,EAAS,MAAA,SAAe,aAAA,GAAgB,kBAAA,GACxC,IAAA;EACE,EAAA,GAAK,UAAA;EACL,OAAA,YAAmB,gBAAA;EACnB,OAAA,YAAmB,KAAA;EACnB,GAAA,YAAe,UAAA;AAAA,IAEhB,YAAA;AAAA,iBAUa,KAAA,CACd,SAAA,UACA,MAAA,EAAQ,MAAA,SAAe,oBAAA,GACvB,SAAA,GAAW,MAAA,mBACX,WAAA;EAEA,OAAA,EAAS,eAAA;EACT,MAAA,EAAQ,MAAA;IAAA,SAA0B,QAAA;IAAA,SAA4B,IAAA,EAAM,eAAA;EAAA;EACpE,SAAA,EAAW,MAAA;AAAA"}
@@ -1,4 +1,4 @@
1
- import { _ as ForeignKey, f as StorageTable, g as PrimaryKey, h as Index, m as StorageColumn, p as UniqueConstraint, r as applyFkDefaults } from "./types-YQrDHy-b.mjs";
1
+ import { _ as PrimaryKey, g as Index, h as StorageColumn, m as UniqueConstraint, p as StorageTable, r as applyFkDefaults, v as ForeignKey } from "./types-ByD-iN24.mjs";
2
2
  import { UNBOUND_NAMESPACE_ID } from "@prisma-next/framework-components/ir";
3
3
  import { asNamespaceId } from "@prisma-next/contract/types";
4
4
  //#region src/factories.ts
@@ -51,10 +51,11 @@ function table(columns, opts) {
51
51
  foreignKeys: opts?.fks ?? []
52
52
  });
53
53
  }
54
- function model(tableName, fields, relations = {}) {
54
+ function model(tableName, fields, relations = {}, namespaceId = UNBOUND_NAMESPACE_ID) {
55
55
  return {
56
56
  storage: {
57
57
  table: tableName,
58
+ namespaceId,
58
59
  fields
59
60
  },
60
61
  fields: Object.fromEntries(Object.entries(fields).map(([name, field]) => [name, {
@@ -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): {\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, 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,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,GAKtC;CAWA,OAAO;EACL,SAAA;GAXiC,OAAO;GAAW;EAW7C;EACN,QAXmB,OAAO,YAC1B,OAAO,QAAQ,MAAM,EAAE,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
+ {"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,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,EAAE,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,5 +1,5 @@
1
- import { k as SqlStorage } from "./types-Cx_5A_L0.mjs";
2
- import { a as IndexTypeRegistry } from "./index-types-B1cf5N0F.mjs";
1
+ import { r as SqlStorage } from "./sql-storage-CV7Tc9Vh.mjs";
2
+ import { a as IndexTypeRegistry } from "./index-types-DqVqGHwg.mjs";
3
3
  import { Contract } from "@prisma-next/contract/types";
4
4
 
5
5
  //#region src/index-type-validation.d.ts
@@ -2,7 +2,7 @@ import { ContractValidationError } from "@prisma-next/contract/contract-validati
2
2
  import { type } from "arktype";
3
3
  //#region src/index-type-validation.ts
4
4
  function validateIndexTypes(contract, indexTypeRegistry) {
5
- for (const [namespaceId, ns] of Object.entries(contract.storage.namespaces)) for (const [tableName, rawTable] of Object.entries(ns.tables)) {
5
+ for (const [namespaceId, ns] of Object.entries(contract.storage.namespaces)) for (const [tableName, rawTable] of Object.entries(ns.entries.table)) {
6
6
  const table = rawTable;
7
7
  for (const index of table.indexes) {
8
8
  if (index.type === void 0 && index.options !== void 0) throw new ContractValidationError(`Namespace "${namespaceId}" table "${tableName}" index on columns [${index.columns.join(", ")}] has options without a type`, "storage");
@@ -1 +1 @@
1
- {"version":3,"file":"index-type-validation.mjs","names":[],"sources":["../src/index-type-validation.ts"],"sourcesContent":["import { ContractValidationError } from '@prisma-next/contract/contract-validation-error';\nimport type { Contract } from '@prisma-next/contract/types';\nimport { type } from 'arktype';\nimport type { IndexTypeRegistry } from './index-types';\nimport type { SqlStorage, StorageTable } from './types';\n\nexport function validateIndexTypes(\n contract: Contract<SqlStorage>,\n indexTypeRegistry: IndexTypeRegistry,\n): void {\n for (const [namespaceId, ns] of Object.entries(contract.storage.namespaces)) {\n for (const [tableName, rawTable] of Object.entries(ns.tables)) {\n const table = rawTable as StorageTable;\n for (const index of table.indexes) {\n if (index.type === undefined && index.options !== undefined) {\n throw new ContractValidationError(\n `Namespace \"${namespaceId}\" table \"${tableName}\" index on columns [${index.columns.join(', ')}] has options without a type`,\n 'storage',\n );\n }\n if (index.type === undefined) continue;\n const entry = indexTypeRegistry.get(index.type);\n if (entry === undefined) {\n throw new ContractValidationError(\n `Namespace \"${namespaceId}\" table \"${tableName}\" index on columns [${index.columns.join(', ')}] uses unregistered index type \"${index.type}\"`,\n 'storage',\n );\n }\n const optionsValue = index.options ?? {};\n const result = entry.options(optionsValue);\n if (result instanceof type.errors) {\n throw new ContractValidationError(\n `Namespace \"${namespaceId}\" table \"${tableName}\" index on columns [${index.columns.join(', ')}] has invalid options for type \"${index.type}\": ${result.summary}`,\n 'storage',\n );\n }\n }\n }\n }\n}\n"],"mappings":";;;AAMA,SAAgB,mBACd,UACA,mBACM;CACN,KAAK,MAAM,CAAC,aAAa,OAAO,OAAO,QAAQ,SAAS,QAAQ,UAAU,GACxE,KAAK,MAAM,CAAC,WAAW,aAAa,OAAO,QAAQ,GAAG,MAAM,GAAG;EAC7D,MAAM,QAAQ;EACd,KAAK,MAAM,SAAS,MAAM,SAAS;GACjC,IAAI,MAAM,SAAS,KAAA,KAAa,MAAM,YAAY,KAAA,GAChD,MAAM,IAAI,wBACR,cAAc,YAAY,WAAW,UAAU,sBAAsB,MAAM,QAAQ,KAAK,IAAI,EAAE,+BAC9F,SACF;GAEF,IAAI,MAAM,SAAS,KAAA,GAAW;GAC9B,MAAM,QAAQ,kBAAkB,IAAI,MAAM,IAAI;GAC9C,IAAI,UAAU,KAAA,GACZ,MAAM,IAAI,wBACR,cAAc,YAAY,WAAW,UAAU,sBAAsB,MAAM,QAAQ,KAAK,IAAI,EAAE,kCAAkC,MAAM,KAAK,IAC3I,SACF;GAEF,MAAM,eAAe,MAAM,WAAW,CAAC;GACvC,MAAM,SAAS,MAAM,QAAQ,YAAY;GACzC,IAAI,kBAAkB,KAAK,QACzB,MAAM,IAAI,wBACR,cAAc,YAAY,WAAW,UAAU,sBAAsB,MAAM,QAAQ,KAAK,IAAI,EAAE,kCAAkC,MAAM,KAAK,KAAK,OAAO,WACvJ,SACF;EAEJ;CACF;AAEJ"}
1
+ {"version":3,"file":"index-type-validation.mjs","names":[],"sources":["../src/index-type-validation.ts"],"sourcesContent":["import { ContractValidationError } from '@prisma-next/contract/contract-validation-error';\nimport type { Contract } from '@prisma-next/contract/types';\nimport { type } from 'arktype';\nimport type { IndexTypeRegistry } from './index-types';\nimport type { SqlStorage, StorageTable } from './types';\n\nexport function validateIndexTypes(\n contract: Contract<SqlStorage>,\n indexTypeRegistry: IndexTypeRegistry,\n): void {\n for (const [namespaceId, ns] of Object.entries(contract.storage.namespaces)) {\n for (const [tableName, rawTable] of Object.entries(ns.entries.table)) {\n const table = rawTable as StorageTable;\n for (const index of table.indexes) {\n if (index.type === undefined && index.options !== undefined) {\n throw new ContractValidationError(\n `Namespace \"${namespaceId}\" table \"${tableName}\" index on columns [${index.columns.join(', ')}] has options without a type`,\n 'storage',\n );\n }\n if (index.type === undefined) continue;\n const entry = indexTypeRegistry.get(index.type);\n if (entry === undefined) {\n throw new ContractValidationError(\n `Namespace \"${namespaceId}\" table \"${tableName}\" index on columns [${index.columns.join(', ')}] uses unregistered index type \"${index.type}\"`,\n 'storage',\n );\n }\n const optionsValue = index.options ?? {};\n const result = entry.options(optionsValue);\n if (result instanceof type.errors) {\n throw new ContractValidationError(\n `Namespace \"${namespaceId}\" table \"${tableName}\" index on columns [${index.columns.join(', ')}] has invalid options for type \"${index.type}\": ${result.summary}`,\n 'storage',\n );\n }\n }\n }\n }\n}\n"],"mappings":";;;AAMA,SAAgB,mBACd,UACA,mBACM;CACN,KAAK,MAAM,CAAC,aAAa,OAAO,OAAO,QAAQ,SAAS,QAAQ,UAAU,GACxE,KAAK,MAAM,CAAC,WAAW,aAAa,OAAO,QAAQ,GAAG,QAAQ,KAAK,GAAG;EACpE,MAAM,QAAQ;EACd,KAAK,MAAM,SAAS,MAAM,SAAS;GACjC,IAAI,MAAM,SAAS,KAAA,KAAa,MAAM,YAAY,KAAA,GAChD,MAAM,IAAI,wBACR,cAAc,YAAY,WAAW,UAAU,sBAAsB,MAAM,QAAQ,KAAK,IAAI,EAAE,+BAC9F,SACF;GAEF,IAAI,MAAM,SAAS,KAAA,GAAW;GAC9B,MAAM,QAAQ,kBAAkB,IAAI,MAAM,IAAI;GAC9C,IAAI,UAAU,KAAA,GACZ,MAAM,IAAI,wBACR,cAAc,YAAY,WAAW,UAAU,sBAAsB,MAAM,QAAQ,KAAK,IAAI,EAAE,kCAAkC,MAAM,KAAK,IAC3I,SACF;GAEF,MAAM,eAAe,MAAM,WAAW,CAAC;GACvC,MAAM,SAAS,MAAM,QAAQ,YAAY;GACzC,IAAI,kBAAkB,KAAK,QACzB,MAAM,IAAI,wBACR,cAAc,YAAY,WAAW,UAAU,sBAAsB,MAAM,QAAQ,KAAK,IAAI,EAAE,kCAAkC,MAAM,KAAK,KAAK,OAAO,WACvJ,SACF;EAEJ;CACF;AAEJ"}
@@ -28,4 +28,4 @@ interface IndexTypeRegistry {
28
28
  declare function createIndexTypeRegistry(): IndexTypeRegistry;
29
29
  //#endregion
30
30
  export { IndexTypeRegistry as a, IndexTypeRegistration as i, IndexTypeEntry as n, createIndexTypeRegistry as o, IndexTypeMap as r, defineIndexTypes as s, IndexTypeBuilder as t };
31
- //# sourceMappingURL=index-types-B1cf5N0F.d.mts.map
31
+ //# sourceMappingURL=index-types-DqVqGHwg.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index-types-B1cf5N0F.d.mts","names":[],"sources":["../src/index-types.ts"],"mappings":";;;UAEiB,cAAA;EAAA,SACN,IAAA;EAAA,SACA,OAAA,EAAS,IAAI,CAAC,QAAA;AAAA;AAAA,KAGb,YAAA;EAAA,SAAoD,OAAO;AAAA;AAAA,UAEtD,qBAAA,cAAmC,YAAA,GAAe,MAAA;EAAA,SACxD,UAAA,EAAY,IAAA;EAAA,SACZ,OAAA,EAAS,aAAA,CAAc,cAAA;AAAA;AAAA,UAGjB,gBAAA,cAA8B,YAAA,GAAe,MAAA,wBACpD,qBAAA,CAAsB,IAAA;EAC9B,GAAA,6BACE,WAAA,EAAa,IAAA,EACb,KAAA;IAAA,SAAkB,OAAA,EAAS,IAAA,CAAK,KAAA;EAAA,IAC/B,gBAAA,CAAiB,IAAA,GAAO,MAAA,CAAO,IAAA;IAAA,SAAiB,OAAA,EAAS,KAAA;EAAA;AAAA;AAAA,iBA0B9C,gBAAA,CAAA,GAAoB,gBAAgB,CAAC,MAAA;AAAA,UAIpC,iBAAA;EACf,QAAA,CAAS,KAAA,EAAO,cAAA;EAChB,GAAA,CAAI,WAAA,WAAsB,cAAc;EACxC,GAAA,CAAI,WAAA;AAAA;AAAA,iBAsBU,uBAAA,CAAA,GAA2B,iBAAiB"}
1
+ {"version":3,"file":"index-types-DqVqGHwg.d.mts","names":[],"sources":["../src/index-types.ts"],"mappings":";;;UAEiB,cAAA;EAAA,SACN,IAAA;EAAA,SACA,OAAA,EAAS,IAAI,CAAC,QAAA;AAAA;AAAA,KAGb,YAAA;EAAA,SAAoD,OAAO;AAAA;AAAA,UAEtD,qBAAA,cAAmC,YAAA,GAAe,MAAA;EAAA,SACxD,UAAA,EAAY,IAAA;EAAA,SACZ,OAAA,EAAS,aAAA,CAAc,cAAA;AAAA;AAAA,UAGjB,gBAAA,cAA8B,YAAA,GAAe,MAAA,wBACpD,qBAAA,CAAsB,IAAA;EAC9B,GAAA,6BACE,WAAA,EAAa,IAAA,EACb,KAAA;IAAA,SAAkB,OAAA,EAAS,IAAA,CAAK,KAAA;EAAA,IAC/B,gBAAA,CAAiB,IAAA,GAAO,MAAA,CAAO,IAAA;IAAA,SAAiB,OAAA,EAAS,KAAA;EAAA;AAAA;AAAA,iBA0B9C,gBAAA,CAAA,GAAoB,gBAAgB,CAAC,MAAA;AAAA,UAIpC,iBAAA;EACf,QAAA,CAAS,KAAA,EAAO,cAAA;EAChB,GAAA,CAAI,WAAA,WAAsB,cAAc;EACxC,GAAA,CAAI,WAAA;AAAA;AAAA,iBAsBU,uBAAA,CAAA,GAA2B,iBAAiB"}
@@ -1,2 +1,2 @@
1
- import { a as IndexTypeRegistry, i as IndexTypeRegistration, n as IndexTypeEntry, o as createIndexTypeRegistry, r as IndexTypeMap, s as defineIndexTypes, t as IndexTypeBuilder } from "./index-types-B1cf5N0F.mjs";
1
+ import { a as IndexTypeRegistry, i as IndexTypeRegistration, n as IndexTypeEntry, o as createIndexTypeRegistry, r as IndexTypeMap, s as defineIndexTypes, t as IndexTypeBuilder } from "./index-types-DqVqGHwg.mjs";
2
2
  export { type IndexTypeBuilder, type IndexTypeEntry, type IndexTypeMap, type IndexTypeRegistration, type IndexTypeRegistry, createIndexTypeRegistry, defineIndexTypes };
@@ -0,0 +1,17 @@
1
+ import { f as StorageTable, r as SqlStorage } from "./sql-storage-CV7Tc9Vh.mjs";
2
+
3
+ //#region src/resolve-storage-table.d.ts
4
+ interface ResolvedStorageTable {
5
+ readonly namespaceId: string;
6
+ readonly table: StorageTable;
7
+ }
8
+ /**
9
+ * Resolve a bare storage table name to its namespace coordinate and table IR by
10
+ * scanning the contract's namespaces. For the single-namespace contracts in
11
+ * scope the scan is exact; cross-namespace bare-name collisions are selected
12
+ * explicitly (TML-2550).
13
+ */
14
+ declare function resolveStorageTable(storage: SqlStorage, tableName: string): ResolvedStorageTable | undefined;
15
+ //#endregion
16
+ export { type ResolvedStorageTable, resolveStorageTable };
17
+ //# sourceMappingURL=resolve-storage-table.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-storage-table.d.mts","names":[],"sources":["../src/resolve-storage-table.ts"],"mappings":";;;UAGiB,oBAAA;EAAA,SACN,WAAA;EAAA,SACA,KAAA,EAAO,YAAY;AAAA;;;;;;AAAA;iBAuBd,mBAAA,CACd,OAAA,EAAS,UAAA,EACT,SAAA,WACC,oBAAoB"}
@@ -0,0 +1,26 @@
1
+ //#region src/resolve-storage-table.ts
2
+ function tableInNamespace(namespace, tableName) {
3
+ if (namespace === void 0) return;
4
+ const tables = namespace.entries.table;
5
+ if (!Object.hasOwn(tables, tableName)) return;
6
+ return tables[tableName];
7
+ }
8
+ /**
9
+ * Resolve a bare storage table name to its namespace coordinate and table IR by
10
+ * scanning the contract's namespaces. For the single-namespace contracts in
11
+ * scope the scan is exact; cross-namespace bare-name collisions are selected
12
+ * explicitly (TML-2550).
13
+ */
14
+ function resolveStorageTable(storage, tableName) {
15
+ for (const namespaceId of Object.keys(storage.namespaces)) {
16
+ const table = tableInNamespace(storage.namespaces[namespaceId], tableName);
17
+ if (table !== void 0) return {
18
+ namespaceId,
19
+ table
20
+ };
21
+ }
22
+ }
23
+ //#endregion
24
+ export { resolveStorageTable };
25
+
26
+ //# sourceMappingURL=resolve-storage-table.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-storage-table.mjs","names":[],"sources":["../src/resolve-storage-table.ts"],"sourcesContent":["import type { SqlNamespace, SqlStorage } from './ir/sql-storage';\nimport type { StorageTable } from './ir/storage-table';\n\nexport interface ResolvedStorageTable {\n readonly namespaceId: string;\n readonly table: StorageTable;\n}\n\nfunction tableInNamespace(\n namespace: SqlNamespace | undefined,\n tableName: string,\n): StorageTable | undefined {\n if (namespace === undefined) {\n return undefined;\n }\n const tables = namespace.entries.table;\n if (!Object.hasOwn(tables, tableName)) {\n return undefined;\n }\n return tables[tableName];\n}\n\n/**\n * Resolve a bare storage table name to its namespace coordinate and table IR by\n * scanning the contract's namespaces. For the single-namespace contracts in\n * scope the scan is exact; cross-namespace bare-name collisions are selected\n * explicitly (TML-2550).\n */\nexport function resolveStorageTable(\n storage: SqlStorage,\n tableName: string,\n): ResolvedStorageTable | undefined {\n for (const namespaceId of Object.keys(storage.namespaces)) {\n const table = tableInNamespace(storage.namespaces[namespaceId], tableName);\n if (table !== undefined) {\n return { namespaceId, table };\n }\n }\n\n return undefined;\n}\n"],"mappings":";AAQA,SAAS,iBACP,WACA,WAC0B;CAC1B,IAAI,cAAc,KAAA,GAChB;CAEF,MAAM,SAAS,UAAU,QAAQ;CACjC,IAAI,CAAC,OAAO,OAAO,QAAQ,SAAS,GAClC;CAEF,OAAO,OAAO;AAChB;;;;;;;AAQA,SAAgB,oBACd,SACA,WACkC;CAClC,KAAK,MAAM,eAAe,OAAO,KAAK,QAAQ,UAAU,GAAG;EACzD,MAAM,QAAQ,iBAAiB,QAAQ,WAAW,cAAc,SAAS;EACzE,IAAI,UAAU,KAAA,GACZ,OAAO;GAAE;GAAa;EAAM;CAEhC;AAGF"}
@@ -1,6 +1,5 @@
1
- import { IRNodeBase, Namespace, NamespaceBase, Storage, StorageType } from "@prisma-next/framework-components/ir";
1
+ import { IRNodeBase, Namespace, Storage, StorageType } from "@prisma-next/framework-components/ir";
2
2
  import { ColumnDefault, ControlPolicy, NamespaceId, StorageHashBase } from "@prisma-next/contract/types";
3
- import { CodecTrait } from "@prisma-next/framework-components/codec";
4
3
 
5
4
  //#region src/ir/sql-node.d.ts
6
5
  /**
@@ -96,57 +95,6 @@ declare class ForeignKey extends SqlNode {
96
95
  constructor(input: ForeignKeyInput);
97
96
  }
98
97
  //#endregion
99
- //#region src/ir/postgres-enum-storage-entry.d.ts
100
- /**
101
- * Discriminator literal for the Postgres-enum variant on the polymorphic
102
- * `SqlStorage.types` slot.
103
- *
104
- * Enums are a target-level concept: Postgres ships native
105
- * `CREATE TYPE … AS ENUM` while other SQL targets approximate enums via
106
- * constraints. The literal lives at the SQL family layer because every
107
- * SQL-family consumer (verifier, planner, lowering, …) needs to
108
- * discriminate enum-typed slot entries from codec-typed ones. The
109
- * concrete IR class (`PostgresEnumType`) lives in the target-postgres
110
- * package and implements this structural contract; cross-domain
111
- * layering rules forbid the SQL family from importing the concrete
112
- * target class directly, so the discriminator and structural interface
113
- * carry the dispatch.
114
- */
115
- declare const POSTGRES_ENUM_KIND: "postgres-enum";
116
- /**
117
- * Structural contract every Postgres-enum slot entry honours — both
118
- * the live `PostgresEnumType` IR-class instance and the raw JSON
119
- * envelope shape that survives `JSON.stringify` round-trips. SQL
120
- * family-layer dispatch narrows polymorphic `StorageType` slot
121
- * entries to this shape via `isPostgresEnumStorageEntry`.
122
- *
123
- * The `codecBinding` field is accessor-shaped (live class instance) on
124
- * the IR class and undefined on the raw JSON envelope; consumers that
125
- * need it must guard for its presence (the JSON path synthesises an
126
- * equivalent shape from `codecId` + `values`).
127
- */
128
- interface PostgresEnumStorageEntry extends StorageType {
129
- readonly kind: typeof POSTGRES_ENUM_KIND;
130
- readonly name: string;
131
- readonly nativeType: string;
132
- readonly values: readonly string[];
133
- /**
134
- * Enumerable own property on the persisted JSON envelope; the live
135
- * IR-class instance carries it too. Family-shared dispatch sites
136
- * read `codecId` directly rather than going through the IR-class
137
- * `codecBinding` accessor (which lives on the prototype and isn't
138
- * present on raw JSON envelopes).
139
- */
140
- readonly codecId: string;
141
- readonly control?: ControlPolicy;
142
- }
143
- /**
144
- * Narrow a polymorphic `StorageType` entry to the Postgres-enum shape
145
- * via its enumerable `kind` discriminator. Type guard returns true for
146
- * both live `PostgresEnumType` instances and raw JSON envelopes.
147
- */
148
- declare function isPostgresEnumStorageEntry(value: unknown): value is PostgresEnumStorageEntry;
149
- //#endregion
150
98
  //#region src/ir/primary-key.d.ts
151
99
  interface PrimaryKeyInput {
152
100
  readonly columns: readonly string[];
@@ -322,15 +270,17 @@ declare function isStorageTypeInstance(value: unknown): value is StorageTypeInst
322
270
  //#region src/ir/sql-storage.d.ts
323
271
  /**
324
272
  * Polymorphic value type for document-scoped `SqlStorage.types` entries
325
- * (codec aliases / parameterised native type registrations). Postgres
326
- * native enum registrations live under
327
- * `storage.namespaces[namespaceId].enum` instead.
273
+ * (codec aliases / parameterised native type registrations).
274
+ *
275
+ * Postgres native enum registrations live under the postgres-specific
276
+ * `entries.type` slot on `PostgresSchema` (target layer), not here.
328
277
  */
329
- type SqlStorageTypeEntry = StorageTypeInstance | StorageTypeInstanceInput | PostgresEnumStorageEntry;
278
+ type SqlStorageTypeEntry = StorageTypeInstance | StorageTypeInstanceInput;
330
279
  interface SqlNamespaceTablesInput {
331
280
  readonly id: string;
332
- readonly tables?: Record<string, StorageTable | StorageTableInput>;
333
- readonly enum?: Record<string, PostgresEnumStorageEntry>;
281
+ readonly entries: {
282
+ readonly table: Record<string, StorageTable | StorageTableInput>;
283
+ };
334
284
  }
335
285
  interface SqlStorageInput<THash extends string = string> {
336
286
  readonly storageHash: StorageHashBase<THash>;
@@ -353,161 +303,30 @@ interface SqlStorageInput<THash extends string = string> {
353
303
  *
354
304
  * The constructor normalises optional `types` into class instances.
355
305
  * `types` is polymorphic per Decision 18 Option B: codec-triple inputs
356
- * are stamped with `kind: 'codec-instance'`; class-instance kinds
357
- * (e.g. Postgres-enum entries satisfying `PostgresEnumStorageEntry`)
358
- * pass through; hydration of raw JSON class-instance entries (carrying
359
- * their narrower `kind` literal) is the per-target serializer's
360
- * responsibility (so the family base does not import target-specific
361
- * subclasses).
306
+ * are stamped with `kind: 'codec-instance'`; hydration of raw JSON
307
+ * class-instance entries (carrying their narrower `kind` literal) is
308
+ * the per-target serializer's responsibility (so the family base does
309
+ * not import target-specific subclasses).
362
310
  */
363
311
  type SqlNamespace = Namespace & {
364
- readonly tables: Readonly<Record<string, StorageTable>>;
365
- readonly enum?: Readonly<Record<string, PostgresEnumStorageEntry>>;
312
+ readonly entries: Readonly<{
313
+ readonly table: Readonly<Record<string, StorageTable>>;
314
+ }>;
315
+ /**
316
+ * Render a dialect-qualified table reference for runtime SQL emission.
317
+ * Present on materialised target concretions (`PostgresSchema`,
318
+ * `SqliteDatabase`, …) and family placeholders; omitted on emitted
319
+ * contract structural namespace literals (methods are not serialised).
320
+ */
321
+ qualifyTable?(tableName: string): string;
366
322
  };
367
323
  declare class SqlStorage<THash extends string = string> extends SqlNode implements Storage {
368
324
  readonly storageHash: StorageHashBase<THash>;
369
325
  readonly namespaces: Readonly<Record<string, SqlNamespace>>;
370
- readonly types?: Readonly<Record<string, StorageTypeInstance | PostgresEnumStorageEntry>>;
326
+ readonly types?: Readonly<Record<string, StorageTypeInstance>>;
371
327
  constructor(input: SqlStorageInput<THash>);
372
328
  }
329
+ declare function storageTableAt(storage: SqlStorage, namespaceId: string, tableName: string): StorageTable | undefined;
373
330
  //#endregion
374
- //#region src/ir/build-sql-namespace.d.ts
375
- declare function buildSqlNamespace(input: SqlNamespaceTablesInput): SqlNamespace;
376
- declare function buildSqlNamespaceMap(namespaces: Readonly<Record<string, Namespace | SqlNamespaceTablesInput>>): Readonly<Record<string, SqlNamespace>>;
377
- //#endregion
378
- //#region src/ir/sql-unbound-namespace.d.ts
379
- /**
380
- * Family-layer placeholder for the SQL unbound-namespace singleton —
381
- * the late-bound slot whose binding the target resolves at connection
382
- * time rather than at authoring time.
383
- *
384
- * SQL contracts honour the framework `Storage.namespaces` invariant from
385
- * the moment they appear in the IR. Today `SqlStorage` is family-shared
386
- * (Postgres + SQLite consume the same class); a per-target namespace
387
- * concretion (`PostgresSchema.unbound`, `SqliteUnboundDatabase.instance`)
388
- * earns its existence when each target's namespace shape lands. Until
389
- * then the family ships a single placeholder singleton so the JSON
390
- * envelope and runtime walk are honest at every layer.
391
- *
392
- * The `kind` discriminator is installed as a non-enumerable own property
393
- * so the JSON envelope reads `{ "id": "__unbound__" }` — symmetric
394
- * with the family-level non-enumerable `kind` on `SqlNode` and bounded
395
- * to the minimum data the framework `Namespace` interface promises.
396
- *
397
- * **Freeze-trap warning.** The leaf constructor calls
398
- * `freezeNode(this)` after installing `kind`. The leaf-class shape
399
- * works today only because `NamespaceBase` does NOT freeze in its
400
- * constructor — the `Object.defineProperty(this, 'kind', …)` call after
401
- * `super()` succeeds because the instance is still mutable at that
402
- * point. Subclasses that add instance fields will still hit the freeze
403
- * trap once leaf-class `freezeNode(this)` runs; and if a future
404
- * framework change lifts the freeze to `NamespaceBase`, even the
405
- * `defineProperty` here would silently fail. To add subclass instance
406
- * fields safely, lift `freezeNode` to a leaf-class `seal()` hook each
407
- * leaf calls explicitly at the end of its own constructor.
408
- */
409
- declare class SqlUnboundNamespace extends NamespaceBase {
410
- static readonly instance: SqlUnboundNamespace;
411
- readonly id: "__unbound__";
412
- readonly tables: Readonly<Record<string, StorageTable>>;
413
- readonly kind: string;
414
- private constructor();
415
- }
416
- //#endregion
417
- //#region src/types.d.ts
418
- type ForeignKeyOptions = {
419
- readonly name?: string;
420
- readonly onDelete?: ReferentialAction;
421
- readonly onUpdate?: ReferentialAction;
422
- };
423
- type SqlModelFieldStorage = {
424
- readonly column: string;
425
- readonly codecId?: string;
426
- readonly nullable?: boolean;
427
- };
428
- type SqlModelStorage = {
429
- readonly table: string;
430
- readonly fields: Record<string, SqlModelFieldStorage>;
431
- };
432
- declare const DEFAULT_FK_CONSTRAINT = true;
433
- declare const DEFAULT_FK_INDEX = true;
434
- declare function applyFkDefaults(fk: {
435
- constraint?: boolean | undefined;
436
- index?: boolean | undefined;
437
- }, overrideDefaults?: {
438
- constraint?: boolean | undefined;
439
- index?: boolean | undefined;
440
- }): {
441
- constraint: boolean;
442
- index: boolean;
443
- };
444
- type TypeMaps<TCodecTypes extends Record<string, {
445
- output: unknown;
446
- }> = Record<string, never>, TQueryOperationTypes extends Record<string, unknown> = Record<string, never>, TFieldOutputTypes extends Record<string, Record<string, unknown>> = Record<string, never>, TFieldInputTypes extends Record<string, Record<string, unknown>> = Record<string, never>> = {
447
- readonly codecTypes: TCodecTypes;
448
- readonly queryOperationTypes: TQueryOperationTypes;
449
- readonly fieldOutputTypes: TFieldOutputTypes;
450
- readonly fieldInputTypes: TFieldInputTypes;
451
- };
452
- type CodecTypesOf<T> = [T] extends [never] ? Record<string, never> : T extends {
453
- readonly codecTypes: infer C;
454
- } ? C extends Record<string, {
455
- output: unknown;
456
- }> ? C : Record<string, never> : Record<string, never>;
457
- /**
458
- * Dispatch hint identifying the first-argument target of an operation.
459
- *
460
- * Used by ORM column helpers to decide whether an operation is reachable on a
461
- * field. Either names a concrete codec identity or a set of capability traits
462
- * that the field's codec must carry.
463
- */
464
- type QueryOperationSelfSpec = {
465
- readonly codecId: string;
466
- readonly traits?: never;
467
- } | {
468
- readonly traits: readonly CodecTrait[];
469
- readonly codecId?: never;
470
- };
471
- /**
472
- * Structural shape an operation's impl must return: any value carrying a
473
- * codec-exact `returnType` descriptor. `Expression<T>` (from
474
- * `@prisma-next/sql-relational-core/expression`, with `T extends ScopeField`)
475
- * extends this. Trait-targeted returns are deliberately excluded — predicate
476
- * detection and result decoding both depend on knowing the concrete return
477
- * codec.
478
- */
479
- type QueryOperationReturn = {
480
- readonly returnType: {
481
- readonly codecId: string;
482
- readonly nullable: boolean;
483
- };
484
- };
485
- type QueryOperationTypeEntry = {
486
- readonly self?: QueryOperationSelfSpec;
487
- readonly impl: (...args: never[]) => QueryOperationReturn;
488
- };
489
- type SqlQueryOperationTypes<_CT extends Record<string, {
490
- readonly input: unknown;
491
- readonly output: unknown;
492
- }>, T extends Record<string, QueryOperationTypeEntry>> = T;
493
- type QueryOperationTypesBase = Record<string, QueryOperationTypeEntry>;
494
- type QueryOperationTypesOf<T> = [T] extends [never] ? Record<string, never> : T extends {
495
- readonly queryOperationTypes: infer Q;
496
- } ? Q extends Record<string, unknown> ? Q : Record<string, never> : Record<string, never>;
497
- type TypeMapsPhantomKey = '__@prisma-next/sql-contract/typeMaps@__';
498
- type ContractWithTypeMaps<TContract, TTypeMaps> = TContract & { readonly [K in TypeMapsPhantomKey]?: TTypeMaps };
499
- type ExtractTypeMapsFromContract<T> = TypeMapsPhantomKey extends keyof T ? NonNullable<T[TypeMapsPhantomKey & keyof T]> : never;
500
- type FieldOutputTypesOf<T> = [T] extends [never] ? Record<string, never> : T extends {
501
- readonly fieldOutputTypes: infer F;
502
- } ? F extends Record<string, Record<string, unknown>> ? F : Record<string, never> : Record<string, never>;
503
- type FieldInputTypesOf<T> = [T] extends [never] ? Record<string, never> : T extends {
504
- readonly fieldInputTypes: infer F;
505
- } ? F extends Record<string, Record<string, unknown>> ? F : Record<string, never> : Record<string, never>;
506
- type ExtractCodecTypes<T> = CodecTypesOf<ExtractTypeMapsFromContract<T>>;
507
- type ExtractQueryOperationTypes<T> = QueryOperationTypesOf<ExtractTypeMapsFromContract<T>>;
508
- type ExtractFieldOutputTypes<T> = FieldOutputTypesOf<ExtractTypeMapsFromContract<T>>;
509
- type ExtractFieldInputTypes<T> = FieldInputTypesOf<ExtractTypeMapsFromContract<T>>;
510
- type ResolveCodecTypes<TContract, TTypeMaps> = [TTypeMaps] extends [never] ? ExtractCodecTypes<TContract> : CodecTypesOf<TTypeMaps>;
511
- //#endregion
512
- export { ForeignKeyReference as $, SqlStorageInput as A, UniqueConstraintInput as B, TypeMapsPhantomKey as C, buildSqlNamespaceMap as D, buildSqlNamespace as E, isStorageTypeInstance as F, PrimaryKey as G, StorageColumnInput as H, toStorageTypeInstance as I, PostgresEnumStorageEntry as J, PrimaryKeyInput as K, StorageTable as L, CODEC_INSTANCE_KIND as M, StorageTypeInstance as N, SqlNamespaceTablesInput as O, StorageTypeInstanceInput as P, ReferentialAction as Q, StorageTableInput as R, TypeMaps as S, SqlUnboundNamespace as T, Index as U, StorageColumn as V, IndexInput as W, ForeignKey as X, isPostgresEnumStorageEntry as Y, ForeignKeyInput as Z, QueryOperationTypesOf as _, ExtractCodecTypes as a, SqlModelStorage as b, ExtractQueryOperationTypes as c, FieldOutputTypesOf as d, ForeignKeyReferenceInput as et, ForeignKeyOptions as f, QueryOperationTypesBase as g, QueryOperationTypeEntry as h, DEFAULT_FK_INDEX as i, SqlStorageTypeEntry as j, SqlStorage as k, ExtractTypeMapsFromContract as l, QueryOperationSelfSpec as m, ContractWithTypeMaps as n, ExtractFieldInputTypes as o, QueryOperationReturn as p, POSTGRES_ENUM_KIND as q, DEFAULT_FK_CONSTRAINT as r, ExtractFieldOutputTypes as s, CodecTypesOf as t, SqlNode as tt, FieldInputTypesOf as u, ResolveCodecTypes as v, applyFkDefaults as w, SqlQueryOperationTypes as x, SqlModelFieldStorage as y, UniqueConstraint as z };
513
- //# sourceMappingURL=types-Cx_5A_L0.d.mts.map
331
+ export { ForeignKeyInput as C, SqlNode as D, ForeignKeyReferenceInput as E, ForeignKey as S, ForeignKeyReference as T, StorageColumnInput as _, SqlStorageTypeEntry as a, PrimaryKey as b, StorageTypeInstance as c, toStorageTypeInstance as d, StorageTable as f, StorageColumn as g, UniqueConstraintInput as h, SqlStorageInput as i, StorageTypeInstanceInput as l, UniqueConstraint as m, SqlNamespaceTablesInput as n, storageTableAt as o, StorageTableInput as p, SqlStorage as r, CODEC_INSTANCE_KIND as s, SqlNamespace as t, isStorageTypeInstance as u, Index as v, ReferentialAction as w, PrimaryKeyInput as x, IndexInput as y };
332
+ //# sourceMappingURL=sql-storage-CV7Tc9Vh.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sql-storage-CV7Tc9Vh.d.mts","names":[],"sources":["../src/ir/sql-node.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","../src/ir/storage-type-instance.ts","../src/ir/sql-storage.ts"],"mappings":";;;;;;;AAkCA;;;;;;;;;;;;AC9BA;;;;;;;;AAGkB;AAUlB;;;;;;;;uBDiBsB,OAAA,SAAgB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