@prisma-next/sql-relational-core 0.12.0 → 0.13.0-dev.2

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 (74) hide show
  1. package/dist/{codec-types-Cezo7k-i.d.mts → codec-types-DFLA6Hmj.d.mts} +6 -4
  2. package/dist/codec-types-DFLA6Hmj.d.mts.map +1 -0
  3. package/dist/ddl-types-D3vlEjMA.d.mts +126 -0
  4. package/dist/ddl-types-D3vlEjMA.d.mts.map +1 -0
  5. package/dist/ddl-types-X9_XHUl0.mjs +130 -0
  6. package/dist/ddl-types-X9_XHUl0.mjs.map +1 -0
  7. package/dist/{errors-BF7W5uUd.mjs → errors-BwyJxXME.mjs} +1 -1
  8. package/dist/{errors-BF7W5uUd.mjs.map → errors-BwyJxXME.mjs.map} +1 -1
  9. package/dist/{errors-Bavu5wZA.d.mts → errors-CPLfzKkw.d.mts} +2 -2
  10. package/dist/{errors-Bavu5wZA.d.mts.map → errors-CPLfzKkw.d.mts.map} +1 -1
  11. package/dist/exports/ast.d.mts +11 -15
  12. package/dist/exports/ast.d.mts.map +1 -1
  13. package/dist/exports/ast.mjs +4 -3
  14. package/dist/exports/ast.mjs.map +1 -1
  15. package/dist/exports/codec-descriptor-registry.d.mts +8 -4
  16. package/dist/exports/codec-descriptor-registry.d.mts.map +1 -1
  17. package/dist/exports/codec-descriptor-registry.mjs +24 -26
  18. package/dist/exports/codec-descriptor-registry.mjs.map +1 -1
  19. package/dist/exports/contract-free.d.mts +161 -0
  20. package/dist/exports/contract-free.d.mts.map +1 -0
  21. package/dist/exports/contract-free.mjs +268 -0
  22. package/dist/exports/contract-free.mjs.map +1 -0
  23. package/dist/exports/errors.d.mts +1 -1
  24. package/dist/exports/errors.mjs +1 -1
  25. package/dist/exports/expression.d.mts +2 -2
  26. package/dist/exports/expression.d.mts.map +1 -1
  27. package/dist/exports/expression.mjs +1 -1
  28. package/dist/exports/middleware.d.mts +2 -2
  29. package/dist/exports/middleware.mjs +1 -1
  30. package/dist/exports/plan.d.mts +2 -2
  31. package/dist/exports/query-lane-context.d.mts +1 -1
  32. package/dist/exports/types.d.mts +3 -3
  33. package/dist/index.d.mts +12 -11
  34. package/dist/index.mjs +6 -5
  35. package/dist/{middleware-EOcO8Ogo.d.mts → middleware-BXSFukKU.d.mts} +2 -2
  36. package/dist/{middleware-EOcO8Ogo.d.mts.map → middleware-BXSFukKU.d.mts.map} +1 -1
  37. package/dist/{middleware-B0yz0pff.mjs → middleware-CMr4CHNz.mjs} +2 -2
  38. package/dist/{middleware-B0yz0pff.mjs.map → middleware-CMr4CHNz.mjs.map} +1 -1
  39. package/dist/{plan-CG3sy5kw.d.mts → plan-DObuWSWi.d.mts} +3 -3
  40. package/dist/plan-DObuWSWi.d.mts.map +1 -0
  41. package/dist/{query-lane-context-Dw1Tz0kv.d.mts → query-lane-context-CY0-e8Qo.d.mts} +8 -6
  42. package/dist/query-lane-context-CY0-e8Qo.d.mts.map +1 -0
  43. package/dist/{sql-execution-plan-D4OimCVH.d.mts → sql-execution-plan-JwVeAzXt.d.mts} +2 -2
  44. package/dist/{sql-execution-plan-D4OimCVH.d.mts.map → sql-execution-plan-JwVeAzXt.d.mts.map} +1 -1
  45. package/dist/{types-C_1ZqLwZ.d.mts → types-BbGUx5Bi.d.mts} +19 -6
  46. package/dist/types-BbGUx5Bi.d.mts.map +1 -0
  47. package/dist/{types-DoolOzqd.d.mts → types-CQVke4QO.d.mts} +8 -20
  48. package/dist/types-CQVke4QO.d.mts.map +1 -0
  49. package/dist/{types-C4EdOD-s.mjs → types-D72v8s92.mjs} +24 -5
  50. package/dist/types-D72v8s92.mjs.map +1 -0
  51. package/dist/{types-CkTDkFcK.d.mts → types-LGikJRYV.d.mts} +3 -3
  52. package/dist/{types-CkTDkFcK.d.mts.map → types-LGikJRYV.d.mts.map} +1 -1
  53. package/dist/{util-DWmhUCEO.mjs → util-DQQgv2j1.mjs} +1 -1
  54. package/dist/{util-DWmhUCEO.mjs.map → util-DQQgv2j1.mjs.map} +1 -1
  55. package/package.json +14 -13
  56. package/src/ast/adapter-types.ts +0 -5
  57. package/src/ast/codec-types.ts +5 -3
  58. package/src/ast/ddl-types.ts +198 -0
  59. package/src/ast/types.ts +31 -6
  60. package/src/codec-descriptor-registry.ts +2 -2
  61. package/src/codec-ref-for-column.ts +26 -20
  62. package/src/contract-free/column.ts +56 -0
  63. package/src/contract-free/dml.ts +17 -0
  64. package/src/contract-free/table.ts +390 -0
  65. package/src/exports/ast.ts +1 -0
  66. package/src/exports/contract-free.ts +26 -0
  67. package/src/query-lane-context.ts +5 -3
  68. package/src/types.ts +3 -23
  69. package/dist/codec-types-Cezo7k-i.d.mts.map +0 -1
  70. package/dist/plan-CG3sy5kw.d.mts.map +0 -1
  71. package/dist/query-lane-context-Dw1Tz0kv.d.mts.map +0 -1
  72. package/dist/types-C4EdOD-s.mjs.map +0 -1
  73. package/dist/types-C_1ZqLwZ.d.mts.map +0 -1
  74. package/dist/types-DoolOzqd.d.mts.map +0 -1
@@ -1,5 +1,5 @@
1
- import { t as AnyCodecDescriptor } from "../codec-types-Cezo7k-i.mjs";
2
- import { n as CodecDescriptorRegistry } from "../query-lane-context-Dw1Tz0kv.mjs";
1
+ import { t as AnyCodecDescriptor } from "../codec-types-DFLA6Hmj.mjs";
2
+ import { n as CodecDescriptorRegistry } from "../query-lane-context-CY0-e8Qo.mjs";
3
3
  import { CodecRef } from "@prisma-next/framework-components/codec";
4
4
  import { SqlStorage } from "@prisma-next/sql-contract/types";
5
5
 
@@ -20,15 +20,19 @@ declare function buildCodecDescriptorRegistry(allDescriptors: ReadonlyArray<AnyC
20
20
  /**
21
21
  * Derive the canonical {@link CodecRef} for a `(table, column)` pair against a {@link SqlStorage}. This is the build-time path every column-bound `ParamRef` / `ProjectionItem` uses to stamp its `codec` slot before the AST is handed to the runtime — the runtime resolver then materialises a memoised {@link import('@prisma-next/sql-relational-core/ast').Codec} for the same `CodecRef` via `forCodecRef`.
22
22
  *
23
- * Resolution rules over `storage.tables[table].columns[column]`:
23
+ * Resolution rules over namespace `entries.table[table].columns[column]`:
24
24
  *
25
25
  * - `typeRef` column → `{codecId, typeParams}` from `storage.types[typeRef]` (multiple columns sharing the typeRef share one ref → one memoised codec).
26
26
  * - inline `typeParams` column → `{codecId, typeParams}` from the column itself.
27
27
  * - non-parameterized column → `{codecId}` with `typeParams` undefined.
28
28
  *
29
29
  * Returns `undefined` when the table or column is unknown, or when a `typeRef` column references a `storage.types` entry that does not exist.
30
+ *
31
+ * `namespaceId` leads the coordinate args and is always supplied: every
32
+ * model/table sits in an explicit namespace, so the table is resolved strictly
33
+ * within that namespace (see {@link resolveStorageTable}).
30
34
  */
31
- declare function codecRefForStorageColumn(storage: SqlStorage, tableName: string, columnName: string): CodecRef | undefined;
35
+ declare function codecRefForStorageColumn(storage: SqlStorage, namespaceId: string, tableName: string, columnName: string): CodecRef | undefined;
32
36
  //#endregion
33
37
  export { buildCodecDescriptorRegistry, codecRefForStorageColumn };
34
38
  //# sourceMappingURL=codec-descriptor-registry.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"codec-descriptor-registry.d.mts","names":[],"sources":["../../src/codec-descriptor-registry.ts","../../src/codec-ref-for-column.ts"],"mappings":";;;;;;;;;AAgBA;;;;;;;iBAAgB,4BAAA,CACd,cAAA,EAAgB,aAAA,CAAc,kBAAA,GAC9B,OAAA,GAAU,UAAA,GACT,uBAAA;;;;;;;AAHH;;;;;;;iBCIgB,wBAAA,CACd,OAAA,EAAS,UAAA,EACT,SAAA,UACA,UAAA,WACC,QAAQ"}
1
+ {"version":3,"file":"codec-descriptor-registry.d.mts","names":[],"sources":["../../src/codec-descriptor-registry.ts","../../src/codec-ref-for-column.ts"],"mappings":";;;;;;;;;AAgBA;;;;;;;iBAAgB,4BAAA,CACd,cAAA,EAAgB,aAAA,CAAc,kBAAA,GAC9B,OAAA,GAAU,UAAA,GACT,uBAAA;;;;;;;AAHH;;;;;;;;;;;iBCQgB,wBAAA,CACd,OAAA,EAAS,UAAA,EACT,WAAA,UACA,SAAA,UACA,UAAA,WACC,QAAQ"}
@@ -1,38 +1,33 @@
1
+ import { resolveStorageTable } from "@prisma-next/sql-contract/resolve-storage-table";
1
2
  import { isPostgresEnumStorageEntry, isStorageTypeInstance } from "@prisma-next/sql-contract/types";
2
3
  //#region src/codec-ref-for-column.ts
3
4
  /**
4
5
  * Derive the canonical {@link CodecRef} for a `(table, column)` pair against a {@link SqlStorage}. This is the build-time path every column-bound `ParamRef` / `ProjectionItem` uses to stamp its `codec` slot before the AST is handed to the runtime — the runtime resolver then materialises a memoised {@link import('@prisma-next/sql-relational-core/ast').Codec} for the same `CodecRef` via `forCodecRef`.
5
6
  *
6
- * Resolution rules over `storage.tables[table].columns[column]`:
7
+ * Resolution rules over namespace `entries.table[table].columns[column]`:
7
8
  *
8
9
  * - `typeRef` column → `{codecId, typeParams}` from `storage.types[typeRef]` (multiple columns sharing the typeRef share one ref → one memoised codec).
9
10
  * - inline `typeParams` column → `{codecId, typeParams}` from the column itself.
10
11
  * - non-parameterized column → `{codecId}` with `typeParams` undefined.
11
12
  *
12
13
  * Returns `undefined` when the table or column is unknown, or when a `typeRef` column references a `storage.types` entry that does not exist.
14
+ *
15
+ * `namespaceId` leads the coordinate args and is always supplied: every
16
+ * model/table sits in an explicit namespace, so the table is resolved strictly
17
+ * within that namespace (see {@link resolveStorageTable}).
13
18
  */
14
- function codecRefForStorageColumn(storage, tableName, columnName) {
15
- let tableDef;
16
- for (const ns of Object.values(storage.namespaces)) {
17
- const candidate = ns.tables[tableName];
18
- if (candidate !== void 0) {
19
- tableDef = candidate;
20
- break;
21
- }
22
- }
23
- if (!tableDef) return void 0;
24
- const columnDef = tableDef.columns[columnName];
19
+ function codecRefForStorageColumn(storage, namespaceId, tableName, columnName) {
20
+ const resolved = resolveStorageTable(storage, tableName, namespaceId);
21
+ if (resolved === void 0) return void 0;
22
+ const columnDef = resolved.table.columns[columnName];
25
23
  if (!columnDef) return void 0;
26
24
  if (columnDef.typeRef !== void 0) {
27
25
  let instance = storage.types?.[columnDef.typeRef];
28
26
  if (!instance) for (const ns of Object.values(storage.namespaces)) {
29
- const nsEnums = ns.enum;
30
- if (nsEnums) {
31
- const nsEntry = nsEnums[columnDef.typeRef];
32
- if (nsEntry !== void 0) {
33
- instance = nsEntry;
34
- break;
35
- }
27
+ const nsEntry = ns.entries.type?.[columnDef.typeRef];
28
+ if (nsEntry !== void 0) {
29
+ instance = nsEntry;
30
+ break;
36
31
  }
37
32
  }
38
33
  if (!instance) return void 0;
@@ -40,13 +35,16 @@ function codecRefForStorageColumn(storage, tableName, columnName) {
40
35
  codecId: instance.codecId,
41
36
  typeParams: { values: instance.values }
42
37
  };
43
- if (isStorageTypeInstance(instance)) return {
44
- codecId: instance.codecId,
45
- typeParams: instance.typeParams
46
- };
38
+ if (isStorageTypeInstance(instance)) {
39
+ const instanceParams = instance.typeParams;
40
+ return instanceParams !== void 0 && Object.keys(instanceParams).length > 0 ? {
41
+ codecId: instance.codecId,
42
+ typeParams: instanceParams
43
+ } : { codecId: instance.codecId };
44
+ }
47
45
  return;
48
46
  }
49
- if (columnDef.typeParams !== void 0) return {
47
+ if (columnDef.typeParams !== void 0 && Object.keys(columnDef.typeParams).length > 0) return {
50
48
  codecId: columnDef.codecId,
51
49
  typeParams: columnDef.typeParams
52
50
  };
@@ -81,9 +79,9 @@ function buildCodecDescriptorRegistry(allDescriptors, storage) {
81
79
  descriptorFor(codecId) {
82
80
  return byId.get(codecId);
83
81
  },
84
- codecRefForColumn(table, column) {
82
+ codecRefForColumn(namespaceId, table, column) {
85
83
  if (!storage) return void 0;
86
- return codecRefForStorageColumn(storage, table, column);
84
+ return codecRefForStorageColumn(storage, namespaceId, table, column);
87
85
  },
88
86
  *values() {
89
87
  yield* byId.values();
@@ -1 +1 @@
1
- {"version":3,"file":"codec-descriptor-registry.mjs","names":[],"sources":["../../src/codec-ref-for-column.ts","../../src/codec-descriptor-registry.ts"],"sourcesContent":["import type { JsonValue } from '@prisma-next/contract/types';\nimport type { CodecRef } from '@prisma-next/framework-components/codec';\nimport {\n isPostgresEnumStorageEntry,\n isStorageTypeInstance,\n type SqlStorage,\n type StorageTable,\n} from '@prisma-next/sql-contract/types';\n\n/**\n * Derive the canonical {@link CodecRef} for a `(table, column)` pair against a {@link SqlStorage}. This is the build-time path every column-bound `ParamRef` / `ProjectionItem` uses to stamp its `codec` slot before the AST is handed to the runtime — the runtime resolver then materialises a memoised {@link import('@prisma-next/sql-relational-core/ast').Codec} for the same `CodecRef` via `forCodecRef`.\n *\n * Resolution rules over `storage.tables[table].columns[column]`:\n *\n * - `typeRef` column → `{codecId, typeParams}` from `storage.types[typeRef]` (multiple columns sharing the typeRef share one ref → one memoised codec).\n * - inline `typeParams` column → `{codecId, typeParams}` from the column itself.\n * - non-parameterized column → `{codecId}` with `typeParams` undefined.\n *\n * Returns `undefined` when the table or column is unknown, or when a `typeRef` column references a `storage.types` entry that does not exist.\n */\nexport function codecRefForStorageColumn(\n storage: SqlStorage,\n tableName: string,\n columnName: string,\n): CodecRef | undefined {\n let tableDef: StorageTable | undefined;\n for (const ns of Object.values(storage.namespaces)) {\n const candidate = ns.tables[tableName] as StorageTable | undefined;\n if (candidate !== undefined) {\n tableDef = candidate;\n break;\n }\n }\n if (!tableDef) return undefined;\n const columnDef = tableDef.columns[columnName];\n if (!columnDef) return undefined;\n if (columnDef.typeRef !== undefined) {\n let instance: unknown = storage.types?.[columnDef.typeRef];\n if (!instance) {\n for (const ns of Object.values(storage.namespaces)) {\n const nsEnums = (ns as { enum?: Record<string, unknown> }).enum;\n if (nsEnums) {\n const nsEntry = nsEnums[columnDef.typeRef];\n if (nsEntry !== undefined) {\n instance = nsEntry;\n break;\n }\n }\n }\n }\n if (!instance) return undefined;\n if (isPostgresEnumStorageEntry(instance)) {\n // Canonical path: the entry is a live `PostgresEnumType` IR\n // instance reached through the per-target serializer's\n // hydration. Raw JSON envelopes carrying `kind: 'postgres-enum'`\n // never reach this site — `SqlStorage.normaliseTypeEntry`\n // rejects them upstream (F09). Read `codecId` and `values` off\n // the structural shape (enumerable own properties on the live\n // instance) so the dispatch stays layered against the family\n // alphabet rather than a target-specific class import.\n return {\n codecId: instance.codecId,\n typeParams: { values: instance.values } as unknown as JsonValue,\n };\n }\n if (isStorageTypeInstance(instance)) {\n return { codecId: instance.codecId, typeParams: instance.typeParams as JsonValue };\n }\n return undefined;\n }\n if (columnDef.typeParams !== undefined) {\n return { codecId: columnDef.codecId, typeParams: columnDef.typeParams as JsonValue };\n }\n return { codecId: columnDef.codecId };\n}\n","import type { CodecDescriptor, CodecRef } from '@prisma-next/framework-components/codec';\nimport type { SqlStorage } from '@prisma-next/sql-contract/types';\nimport type { AnyCodecDescriptor } from './ast/codec-types';\nimport { codecRefForStorageColumn } from './codec-ref-for-column';\nimport type { CodecDescriptorRegistry } from './query-lane-context';\n\n/**\n * Build a {@link CodecDescriptorRegistry} from a flat descriptor list.\n *\n * Used by:\n * - Each codec-shipping package's `core/registry.ts` to expose a package-scoped registry as the public consumer surface (replacing raw descriptor-array exports). See ADR 208.\n * - The runtime's `buildExecutionContext` to construct the contract-bound combined registry from every contributor's `codecs:` slot.\n *\n * The descriptor map is heterogeneous in `P` — each codec id has its own params shape. The public {@link CodecDescriptorRegistry} interface widens to `CodecDescriptor<unknown>` and consumers narrow per codec id at the call site (the descriptor's `paramsSchema` validates JSON-sourced params before the factory ever sees them, so the runtime narrow is safe). The cast at registration goes through `unknown` because\n * `CodecDescriptor<P>` is invariant in `P` (the `factory` and `renderOutputType` slots use `P` contravariantly).\n */\nexport function buildCodecDescriptorRegistry(\n allDescriptors: ReadonlyArray<AnyCodecDescriptor>,\n storage?: SqlStorage,\n): CodecDescriptorRegistry {\n type AnyDescriptor = CodecDescriptor<unknown>;\n const byId = new Map<string, AnyDescriptor>();\n const byTargetType = new Map<string, Array<AnyDescriptor>>();\n\n for (const descriptor of allDescriptors) {\n if (byId.has(descriptor.codecId)) {\n throw new Error(\n `Duplicate codec descriptor id: '${descriptor.codecId}' — registered twice during registry construction. ` +\n 'Each codecId must be contributed by exactly one component (target / adapter / extension pack).',\n );\n }\n const widened = descriptor as unknown as AnyDescriptor;\n byId.set(descriptor.codecId, widened);\n for (const targetType of descriptor.targetTypes) {\n const list = byTargetType.get(targetType);\n if (list) {\n list.push(widened);\n } else {\n byTargetType.set(targetType, [widened]);\n }\n }\n }\n\n return {\n descriptorFor(codecId: string): AnyDescriptor | undefined {\n return byId.get(codecId);\n },\n codecRefForColumn(table: string, column: string): CodecRef | undefined {\n if (!storage) return undefined;\n return codecRefForStorageColumn(storage, table, column);\n },\n *values(): IterableIterator<AnyDescriptor> {\n yield* byId.values();\n },\n byTargetType(targetType: string): readonly AnyDescriptor[] {\n return byTargetType.get(targetType) ?? Object.freeze([]);\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;AAoBA,SAAgB,yBACd,SACA,WACA,YACsB;CACtB,IAAI;CACJ,KAAK,MAAM,MAAM,OAAO,OAAO,QAAQ,UAAU,GAAG;EAClD,MAAM,YAAY,GAAG,OAAO;EAC5B,IAAI,cAAc,KAAA,GAAW;GAC3B,WAAW;GACX;EACF;CACF;CACA,IAAI,CAAC,UAAU,OAAO,KAAA;CACtB,MAAM,YAAY,SAAS,QAAQ;CACnC,IAAI,CAAC,WAAW,OAAO,KAAA;CACvB,IAAI,UAAU,YAAY,KAAA,GAAW;EACnC,IAAI,WAAoB,QAAQ,QAAQ,UAAU;EAClD,IAAI,CAAC,UACH,KAAK,MAAM,MAAM,OAAO,OAAO,QAAQ,UAAU,GAAG;GAClD,MAAM,UAAW,GAA0C;GAC3D,IAAI,SAAS;IACX,MAAM,UAAU,QAAQ,UAAU;IAClC,IAAI,YAAY,KAAA,GAAW;KACzB,WAAW;KACX;IACF;GACF;EACF;EAEF,IAAI,CAAC,UAAU,OAAO,KAAA;EACtB,IAAI,2BAA2B,QAAQ,GASrC,OAAO;GACL,SAAS,SAAS;GAClB,YAAY,EAAE,QAAQ,SAAS,OAAO;EACxC;EAEF,IAAI,sBAAsB,QAAQ,GAChC,OAAO;GAAE,SAAS,SAAS;GAAS,YAAY,SAAS;EAAwB;EAEnF;CACF;CACA,IAAI,UAAU,eAAe,KAAA,GAC3B,OAAO;EAAE,SAAS,UAAU;EAAS,YAAY,UAAU;CAAwB;CAErF,OAAO,EAAE,SAAS,UAAU,QAAQ;AACtC;;;;;;;;;;;;;AC1DA,SAAgB,6BACd,gBACA,SACyB;CAEzB,MAAM,uBAAO,IAAI,IAA2B;CAC5C,MAAM,+BAAe,IAAI,IAAkC;CAE3D,KAAK,MAAM,cAAc,gBAAgB;EACvC,IAAI,KAAK,IAAI,WAAW,OAAO,GAC7B,MAAM,IAAI,MACR,mCAAmC,WAAW,QAAQ,kJAExD;EAEF,MAAM,UAAU;EAChB,KAAK,IAAI,WAAW,SAAS,OAAO;EACpC,KAAK,MAAM,cAAc,WAAW,aAAa;GAC/C,MAAM,OAAO,aAAa,IAAI,UAAU;GACxC,IAAI,MACF,KAAK,KAAK,OAAO;QAEjB,aAAa,IAAI,YAAY,CAAC,OAAO,CAAC;EAE1C;CACF;CAEA,OAAO;EACL,cAAc,SAA4C;GACxD,OAAO,KAAK,IAAI,OAAO;EACzB;EACA,kBAAkB,OAAe,QAAsC;GACrE,IAAI,CAAC,SAAS,OAAO,KAAA;GACrB,OAAO,yBAAyB,SAAS,OAAO,MAAM;EACxD;EACA,CAAC,SAA0C;GACzC,OAAO,KAAK,OAAO;EACrB;EACA,aAAa,YAA8C;GACzD,OAAO,aAAa,IAAI,UAAU,KAAK,OAAO,OAAO,CAAC,CAAC;EACzD;CACF;AACF"}
1
+ {"version":3,"file":"codec-descriptor-registry.mjs","names":[],"sources":["../../src/codec-ref-for-column.ts","../../src/codec-descriptor-registry.ts"],"sourcesContent":["import type { JsonValue } from '@prisma-next/contract/types';\nimport type { CodecRef } from '@prisma-next/framework-components/codec';\nimport { resolveStorageTable } from '@prisma-next/sql-contract/resolve-storage-table';\nimport {\n isPostgresEnumStorageEntry,\n isStorageTypeInstance,\n type SqlStorage,\n} from '@prisma-next/sql-contract/types';\n\n/**\n * Derive the canonical {@link CodecRef} for a `(table, column)` pair against a {@link SqlStorage}. This is the build-time path every column-bound `ParamRef` / `ProjectionItem` uses to stamp its `codec` slot before the AST is handed to the runtime — the runtime resolver then materialises a memoised {@link import('@prisma-next/sql-relational-core/ast').Codec} for the same `CodecRef` via `forCodecRef`.\n *\n * Resolution rules over namespace `entries.table[table].columns[column]`:\n *\n * - `typeRef` column → `{codecId, typeParams}` from `storage.types[typeRef]` (multiple columns sharing the typeRef share one ref → one memoised codec).\n * - inline `typeParams` column → `{codecId, typeParams}` from the column itself.\n * - non-parameterized column → `{codecId}` with `typeParams` undefined.\n *\n * Returns `undefined` when the table or column is unknown, or when a `typeRef` column references a `storage.types` entry that does not exist.\n *\n * `namespaceId` leads the coordinate args and is always supplied: every\n * model/table sits in an explicit namespace, so the table is resolved strictly\n * within that namespace (see {@link resolveStorageTable}).\n */\nexport function codecRefForStorageColumn(\n storage: SqlStorage,\n namespaceId: string,\n tableName: string,\n columnName: string,\n): CodecRef | undefined {\n const resolved = resolveStorageTable(storage, tableName, namespaceId);\n if (resolved === undefined) return undefined;\n const tableDef = resolved.table;\n const columnDef = tableDef.columns[columnName];\n if (!columnDef) return undefined;\n if (columnDef.typeRef !== undefined) {\n let instance: unknown = storage.types?.[columnDef.typeRef];\n if (!instance) {\n for (const ns of Object.values(storage.namespaces)) {\n const typeSlot = (ns.entries as { type?: Record<string, unknown> }).type;\n const nsEntry = typeSlot?.[columnDef.typeRef];\n if (nsEntry !== undefined) {\n instance = nsEntry;\n break;\n }\n }\n }\n if (!instance) return undefined;\n if (isPostgresEnumStorageEntry(instance)) {\n // Canonical path: the entry is a live `PostgresEnumType` IR\n // instance reached through the per-target serializer's\n // hydration. Raw JSON envelopes carrying `kind: 'postgres-enum'`\n // never reach this site — `SqlStorage.normaliseTypeEntry`\n // rejects them upstream (F09). Read `codecId` and `values` off\n // the structural shape (enumerable own properties on the live\n // instance) so the dispatch stays layered against the family\n // alphabet rather than a target-specific class import.\n return {\n codecId: instance.codecId,\n typeParams: { values: instance.values } as unknown as JsonValue,\n };\n }\n if (isStorageTypeInstance(instance)) {\n // Empty-state canonicalization: a `StorageTypeInstance` with absent\n // (or empty) `typeParams` produces a `CodecRef` with no `typeParams`\n // field. Equivalent to the non-parameterized-column branch below.\n // Carrying `{}` here would break content-keyed memoisation and trip\n // the runtime validator against non-parameterized codec descriptors.\n const instanceParams = instance.typeParams;\n const hasParamKeys = instanceParams !== undefined && Object.keys(instanceParams).length > 0;\n return hasParamKeys\n ? { codecId: instance.codecId, typeParams: instanceParams as JsonValue }\n : { codecId: instance.codecId };\n }\n return undefined;\n }\n if (columnDef.typeParams !== undefined && Object.keys(columnDef.typeParams).length > 0) {\n return { codecId: columnDef.codecId, typeParams: columnDef.typeParams as JsonValue };\n }\n return { codecId: columnDef.codecId };\n}\n","import type { CodecDescriptor, CodecRef } from '@prisma-next/framework-components/codec';\nimport type { SqlStorage } from '@prisma-next/sql-contract/types';\nimport type { AnyCodecDescriptor } from './ast/codec-types';\nimport { codecRefForStorageColumn } from './codec-ref-for-column';\nimport type { CodecDescriptorRegistry } from './query-lane-context';\n\n/**\n * Build a {@link CodecDescriptorRegistry} from a flat descriptor list.\n *\n * Used by:\n * - Each codec-shipping package's `core/registry.ts` to expose a package-scoped registry as the public consumer surface (replacing raw descriptor-array exports). See ADR 208.\n * - The runtime's `buildExecutionContext` to construct the contract-bound combined registry from every contributor's `codecs:` slot.\n *\n * The descriptor map is heterogeneous in `P` — each codec id has its own params shape. The public {@link CodecDescriptorRegistry} interface widens to `CodecDescriptor<unknown>` and consumers narrow per codec id at the call site (the descriptor's `paramsSchema` validates JSON-sourced params before the factory ever sees them, so the runtime narrow is safe). The cast at registration goes through `unknown` because\n * `CodecDescriptor<P>` is invariant in `P` (the `factory` and `renderOutputType` slots use `P` contravariantly).\n */\nexport function buildCodecDescriptorRegistry(\n allDescriptors: ReadonlyArray<AnyCodecDescriptor>,\n storage?: SqlStorage,\n): CodecDescriptorRegistry {\n type AnyDescriptor = CodecDescriptor<unknown>;\n const byId = new Map<string, AnyDescriptor>();\n const byTargetType = new Map<string, Array<AnyDescriptor>>();\n\n for (const descriptor of allDescriptors) {\n if (byId.has(descriptor.codecId)) {\n throw new Error(\n `Duplicate codec descriptor id: '${descriptor.codecId}' — registered twice during registry construction. ` +\n 'Each codecId must be contributed by exactly one component (target / adapter / extension pack).',\n );\n }\n const widened = descriptor as unknown as AnyDescriptor;\n byId.set(descriptor.codecId, widened);\n for (const targetType of descriptor.targetTypes) {\n const list = byTargetType.get(targetType);\n if (list) {\n list.push(widened);\n } else {\n byTargetType.set(targetType, [widened]);\n }\n }\n }\n\n return {\n descriptorFor(codecId: string): AnyDescriptor | undefined {\n return byId.get(codecId);\n },\n codecRefForColumn(namespaceId: string, table: string, column: string): CodecRef | undefined {\n if (!storage) return undefined;\n return codecRefForStorageColumn(storage, namespaceId, table, column);\n },\n *values(): IterableIterator<AnyDescriptor> {\n yield* byId.values();\n },\n byTargetType(targetType: string): readonly AnyDescriptor[] {\n return byTargetType.get(targetType) ?? Object.freeze([]);\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAwBA,SAAgB,yBACd,SACA,aACA,WACA,YACsB;CACtB,MAAM,WAAW,oBAAoB,SAAS,WAAW,WAAW;CACpE,IAAI,aAAa,KAAA,GAAW,OAAO,KAAA;CAEnC,MAAM,YADW,SAAS,MACC,QAAQ;CACnC,IAAI,CAAC,WAAW,OAAO,KAAA;CACvB,IAAI,UAAU,YAAY,KAAA,GAAW;EACnC,IAAI,WAAoB,QAAQ,QAAQ,UAAU;EAClD,IAAI,CAAC,UACH,KAAK,MAAM,MAAM,OAAO,OAAO,QAAQ,UAAU,GAAG;GAElD,MAAM,UADY,GAAG,QAA+C,OACzC,UAAU;GACrC,IAAI,YAAY,KAAA,GAAW;IACzB,WAAW;IACX;GACF;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,aAAa,YAA8C;GACzD,OAAO,aAAa,IAAI,UAAU,KAAK,OAAO,OAAO,CAAC,CAAC;EACzD;CACF;AACF"}
@@ -0,0 +1,161 @@
1
+ import { A as InsertAst, Z as ProjectionItem, at as TableSource, g as ColumnRef, o as AnyExpression, q as OrderByItem, st as UpdateAst, tt as SelectAst } from "../types-BbGUx5Bi.mjs";
2
+ import { c as ForeignKeyConstraint, d as PrimaryKeyConstraint, f as UniqueConstraint, l as FunctionColumnDefault, n as DdlColumn, t as AnyDdlColumnDefault, u as LiteralColumnDefault } from "../ddl-types-D3vlEjMA.mjs";
3
+ import { ColumnDefaultLiteralInputValue } from "@prisma-next/contract/types";
4
+ import { ReferentialAction } from "@prisma-next/sql-contract/types";
5
+
6
+ //#region src/contract-free/column.d.ts
7
+ interface DdlColumnOptions {
8
+ readonly notNull?: boolean;
9
+ readonly primaryKey?: boolean;
10
+ readonly default?: AnyDdlColumnDefault;
11
+ }
12
+ declare function lit(value: ColumnDefaultLiteralInputValue): LiteralColumnDefault;
13
+ declare function fn(expression: string): FunctionColumnDefault;
14
+ declare function col(name: string, type: string, options?: DdlColumnOptions): DdlColumn;
15
+ declare function primaryKey(columns: readonly string[], options?: {
16
+ readonly name?: string;
17
+ }): PrimaryKeyConstraint;
18
+ declare function foreignKey(columns: readonly string[], refTable: string, refColumns: readonly string[], options?: {
19
+ readonly name?: string;
20
+ readonly onDelete?: ReferentialAction;
21
+ readonly onUpdate?: ReferentialAction;
22
+ }): ForeignKeyConstraint;
23
+ declare function unique(columns: readonly string[], options?: {
24
+ readonly name?: string;
25
+ }): UniqueConstraint;
26
+ //#endregion
27
+ //#region src/contract-free/table.d.ts
28
+ interface ColumnDescriptor {
29
+ readonly codecId: string;
30
+ readonly nullable: boolean;
31
+ }
32
+ type ColumnSchema = Record<string, ColumnDescriptor>;
33
+ /**
34
+ * A composable WHERE / ON expression. Wraps an `AnyExpression` and exposes
35
+ * fluent boolean combinators, mirroring the spirit of `sql-builder`'s
36
+ * `Expression` interface without the contract-bound type machinery.
37
+ */
38
+ declare class CfExpr {
39
+ readonly ast: AnyExpression;
40
+ constructor(ast: AnyExpression);
41
+ and(other: CfExpr): CfExpr;
42
+ or(other: CfExpr): CfExpr;
43
+ not(): CfExpr;
44
+ }
45
+ /**
46
+ * Per-column authoring handle exposed as a keyed property on a {@link TableHandle}.
47
+ * Carries codec metadata baked at declaration time so no codec ID, table name, or
48
+ * column name needs to be repeated at the call site.
49
+ */
50
+ interface ColumnProxy {
51
+ readonly codecId: string;
52
+ readonly nullable: boolean;
53
+ readonly columnName: string;
54
+ readonly tableName: string;
55
+ eq(value: unknown): CfExpr;
56
+ neq(value: unknown): CfExpr;
57
+ isNull(): CfExpr;
58
+ isNotNull(): CfExpr;
59
+ toRef(): ColumnRef;
60
+ toProjectionItem(alias?: string): ProjectionItem;
61
+ }
62
+ /**
63
+ * Object passed to the {@link CfConflictClause.doUpdate} callback. Each key
64
+ * resolves to a `ColumnRef` for the corresponding `excluded.<column>`, so the
65
+ * upsert conflict-update branch can copy proposed values without re-binding
66
+ * parameters.
67
+ */
68
+ type ExcludedProxy<Schema extends ColumnSchema> = { readonly [K in keyof Schema]: ColumnRef };
69
+ type TableInsertRow<Schema extends ColumnSchema> = { readonly [K in keyof Schema]: unknown };
70
+ type TableSetValues<Schema extends ColumnSchema> = { readonly [K in keyof Schema]?: unknown };
71
+ /**
72
+ * Fluent authoring handle for a fixed control-plane table. Column proxies are
73
+ * exposed as keyed properties so `handle.columnName.eq(value)` composes without
74
+ * threading codec IDs, table names, or column refs at the call site.
75
+ */
76
+ type TableHandle<Schema extends ColumnSchema> = {
77
+ readonly source: TableSource;
78
+ insert(row: TableInsertRow<Schema>): CfInsertQuery<Schema>;
79
+ upsert(row: TableInsertRow<Schema>): CfUpsertBuilder<Schema>;
80
+ update(): CfUpdateQuery<Schema>;
81
+ select(...columns: ReadonlyArray<ColumnProxy>): CfSelectQuery;
82
+ } & { readonly [K in keyof Schema]: ColumnProxy };
83
+ declare class CfInsertQuery<Schema extends ColumnSchema> {
84
+ private readonly src;
85
+ private readonly schema;
86
+ private readonly rowValues;
87
+ private readonly returningItems;
88
+ constructor(src: TableSource, schema: Schema, rowValues: TableInsertRow<Schema>, returningItems?: ReadonlyArray<ProjectionItem> | undefined);
89
+ returning(...columns: ReadonlyArray<ColumnProxy>): CfInsertQuery<Schema>;
90
+ build(): InsertAst;
91
+ }
92
+ declare class CfUpsertBuilder<Schema extends ColumnSchema> {
93
+ private readonly src;
94
+ private readonly schema;
95
+ private readonly rowValues;
96
+ constructor(src: TableSource, schema: Schema, rowValues: TableInsertRow<Schema>);
97
+ onConflict(...columns: ReadonlyArray<ColumnProxy>): CfConflictClause<Schema>;
98
+ }
99
+ declare class CfConflictClause<Schema extends ColumnSchema> {
100
+ private readonly src;
101
+ private readonly schema;
102
+ private readonly rowValues;
103
+ private readonly conflictCols;
104
+ constructor(src: TableSource, schema: Schema, rowValues: TableInsertRow<Schema>, conflictCols: ReadonlyArray<ColumnProxy>);
105
+ doUpdate(setOrCallback: TableSetValues<Schema> | ((excluded: ExcludedProxy<Schema>) => TableSetValues<Schema>)): CfUpsertQuery<Schema>;
106
+ doNothing(): CfUpsertQuery<Schema>;
107
+ }
108
+ declare class CfUpsertQuery<Schema extends ColumnSchema> {
109
+ private readonly src;
110
+ private readonly schema;
111
+ private readonly rowValues;
112
+ private readonly conflictCols;
113
+ private readonly updateSet;
114
+ constructor(src: TableSource, schema: Schema, rowValues: TableInsertRow<Schema>, conflictCols: ReadonlyArray<ColumnProxy>, updateSet: TableSetValues<Schema> | undefined);
115
+ build(): InsertAst;
116
+ }
117
+ declare class CfUpdateQuery<Schema extends ColumnSchema> {
118
+ private readonly src;
119
+ private readonly schema;
120
+ private readonly setValues;
121
+ private readonly whereExpr;
122
+ private readonly returningItems;
123
+ constructor(src: TableSource, schema: Schema, setValues?: TableSetValues<Schema> | undefined, whereExpr?: CfExpr | undefined, returningItems?: ReadonlyArray<ProjectionItem> | undefined);
124
+ set(values: TableSetValues<Schema>): CfUpdateQuery<Schema>;
125
+ where(expr: CfExpr): CfUpdateQuery<Schema>;
126
+ returning(...columns: ReadonlyArray<ColumnProxy>): CfUpdateQuery<Schema>;
127
+ build(): UpdateAst;
128
+ }
129
+ declare class CfSelectQuery {
130
+ private readonly src;
131
+ private readonly projectionItems;
132
+ private readonly whereExpr;
133
+ private readonly orderByItems;
134
+ constructor(src: TableSource, projectionItems: ReadonlyArray<ProjectionItem>, whereExpr?: CfExpr | undefined, orderByItems?: ReadonlyArray<OrderByItem>);
135
+ where(expr: CfExpr): CfSelectQuery;
136
+ orderBy(column: ColumnProxy, dir?: 'asc' | 'desc'): CfSelectQuery;
137
+ build(): SelectAst;
138
+ }
139
+ /**
140
+ * Declare a control-plane table once, binding column codecs at declaration time.
141
+ * Returns a `TableHandle` whose column properties compose expressions directly
142
+ * without per-call-site codec or column-name threading.
143
+ *
144
+ * ```ts
145
+ * const marker = pgTable({ name: 'marker', schema: 'prisma_contract' }, {
146
+ * space: text(),
147
+ * core_hash: text(),
148
+ * updated_at: timestamptz(),
149
+ * });
150
+ *
151
+ * const query = marker.update()
152
+ * .set({ core_hash: newHash, updated_at: NOW })
153
+ * .where(marker.space.eq(space).and(marker.core_hash.eq(expectedFrom)))
154
+ * .returning(marker.space)
155
+ * .build();
156
+ * ```
157
+ */
158
+ declare function table<Schema extends ColumnSchema>(source: TableSource, schema: Schema): TableHandle<Schema>;
159
+ //#endregion
160
+ export { CfConflictClause, CfExpr, CfInsertQuery, CfSelectQuery, CfUpdateQuery, CfUpsertBuilder, CfUpsertQuery, type ColumnDescriptor, type ColumnProxy, type ColumnSchema, type DdlColumnOptions, type ExcludedProxy, type TableHandle, type TableInsertRow, type TableSetValues, col, fn, foreignKey, lit, primaryKey, table, unique };
161
+ //# sourceMappingURL=contract-free.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract-free.d.mts","names":[],"sources":["../../src/contract-free/column.ts","../../src/contract-free/table.ts"],"mappings":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AAW,MAAA,cACX,YAAA,GAAc,aAAA,CAAc,WAAA;EAG/C,KAAA,CAAM,IAAA,EAAM,MAAA,GAAS,aAAA;EAIrB,OAAA,CAAQ,MAAA,EAAQ,WAAA,EAAa,GAAA,oBAA8B,aAAA;EAQ3D,KAAA,IAAS,SAAA;AAAA;;;AAhMI;AAUf;;;;;;;;;;;;;;;;iBAgNgB,KAAA,gBAAqB,YAAA,EACnC,MAAA,EAAQ,WAAA,EACR,MAAA,EAAQ,MAAA,GACP,WAAA,CAAY,MAAA"}
@@ -0,0 +1,268 @@
1
+ import { a as FunctionColumnDefault, c as UniqueConstraint, i as ForeignKeyConstraint, o as LiteralColumnDefault, s as PrimaryKeyConstraint, t as DdlColumn } from "../ddl-types-X9_XHUl0.mjs";
2
+ import { A as SelectAst, C as OrExpr, D as ProjectionItem, N as UpdateAst, T as ParamRef, i as ColumnRef, m as InsertOnConflict, n as AndExpr, p as InsertAst, r as BinaryExpr, w as OrderByItem, x as NullCheckExpr } from "../types-D72v8s92.mjs";
3
+ import { blindCast } from "@prisma-next/utils/casts";
4
+ //#region src/contract-free/column.ts
5
+ function lit(value) {
6
+ return new LiteralColumnDefault(value);
7
+ }
8
+ function fn(expression) {
9
+ return new FunctionColumnDefault(expression);
10
+ }
11
+ function col(name, type, options) {
12
+ return new DdlColumn({
13
+ name,
14
+ type,
15
+ ...options
16
+ });
17
+ }
18
+ function primaryKey(columns, options) {
19
+ return new PrimaryKeyConstraint({
20
+ columns,
21
+ ...options
22
+ });
23
+ }
24
+ function foreignKey(columns, refTable, refColumns, options) {
25
+ return new ForeignKeyConstraint({
26
+ columns,
27
+ refTable,
28
+ refColumns,
29
+ ...options
30
+ });
31
+ }
32
+ function unique(columns, options) {
33
+ return new UniqueConstraint({
34
+ columns,
35
+ ...options
36
+ });
37
+ }
38
+ //#endregion
39
+ //#region src/contract-free/table.ts
40
+ /**
41
+ * A composable WHERE / ON expression. Wraps an `AnyExpression` and exposes
42
+ * fluent boolean combinators, mirroring the spirit of `sql-builder`'s
43
+ * `Expression` interface without the contract-bound type machinery.
44
+ */
45
+ var CfExpr = class CfExpr {
46
+ ast;
47
+ constructor(ast) {
48
+ this.ast = ast;
49
+ }
50
+ and(other) {
51
+ return new CfExpr(AndExpr.of([this.ast, other.ast]));
52
+ }
53
+ or(other) {
54
+ return new CfExpr(OrExpr.of([this.ast, other.ast]));
55
+ }
56
+ not() {
57
+ return new CfExpr(this.ast.not());
58
+ }
59
+ };
60
+ var CfInsertQuery = class CfInsertQuery {
61
+ src;
62
+ schema;
63
+ rowValues;
64
+ returningItems;
65
+ constructor(src, schema, rowValues, returningItems = void 0) {
66
+ this.src = src;
67
+ this.schema = schema;
68
+ this.rowValues = rowValues;
69
+ this.returningItems = returningItems;
70
+ }
71
+ returning(...columns) {
72
+ return new CfInsertQuery(this.src, this.schema, this.rowValues, columns.map((col) => col.toProjectionItem()));
73
+ }
74
+ build() {
75
+ const row = buildInsertRow(this.schema, this.rowValues);
76
+ const ast = InsertAst.into(this.src).withRows([row]);
77
+ return this.returningItems ? ast.withReturning(this.returningItems) : ast;
78
+ }
79
+ };
80
+ var CfUpsertBuilder = class {
81
+ src;
82
+ schema;
83
+ rowValues;
84
+ constructor(src, schema, rowValues) {
85
+ this.src = src;
86
+ this.schema = schema;
87
+ this.rowValues = rowValues;
88
+ }
89
+ onConflict(...columns) {
90
+ return new CfConflictClause(this.src, this.schema, this.rowValues, [...columns]);
91
+ }
92
+ };
93
+ var CfConflictClause = class {
94
+ src;
95
+ schema;
96
+ rowValues;
97
+ conflictCols;
98
+ constructor(src, schema, rowValues, conflictCols) {
99
+ this.src = src;
100
+ this.schema = schema;
101
+ this.rowValues = rowValues;
102
+ this.conflictCols = conflictCols;
103
+ }
104
+ doUpdate(setOrCallback) {
105
+ const set = typeof setOrCallback === "function" ? setOrCallback(buildExcludedProxy(this.schema)) : setOrCallback;
106
+ return new CfUpsertQuery(this.src, this.schema, this.rowValues, this.conflictCols, set);
107
+ }
108
+ doNothing() {
109
+ return new CfUpsertQuery(this.src, this.schema, this.rowValues, this.conflictCols, void 0);
110
+ }
111
+ };
112
+ var CfUpsertQuery = class {
113
+ src;
114
+ schema;
115
+ rowValues;
116
+ conflictCols;
117
+ updateSet;
118
+ constructor(src, schema, rowValues, conflictCols, updateSet) {
119
+ this.src = src;
120
+ this.schema = schema;
121
+ this.rowValues = rowValues;
122
+ this.conflictCols = conflictCols;
123
+ this.updateSet = updateSet;
124
+ }
125
+ build() {
126
+ const row = buildInsertRow(this.schema, this.rowValues);
127
+ const conflictRefs = this.conflictCols.map((col) => col.toRef());
128
+ const onConflict = this.updateSet === void 0 ? InsertOnConflict.on(conflictRefs).doNothing() : InsertOnConflict.on(conflictRefs).doUpdateSet(buildSetMap(this.schema, this.updateSet));
129
+ return InsertAst.into(this.src).withRows([row]).withOnConflict(onConflict);
130
+ }
131
+ };
132
+ var CfUpdateQuery = class CfUpdateQuery {
133
+ src;
134
+ schema;
135
+ setValues;
136
+ whereExpr;
137
+ returningItems;
138
+ constructor(src, schema, setValues = void 0, whereExpr = void 0, returningItems = void 0) {
139
+ this.src = src;
140
+ this.schema = schema;
141
+ this.setValues = setValues;
142
+ this.whereExpr = whereExpr;
143
+ this.returningItems = returningItems;
144
+ }
145
+ set(values) {
146
+ return new CfUpdateQuery(this.src, this.schema, values, this.whereExpr, this.returningItems);
147
+ }
148
+ where(expr) {
149
+ return new CfUpdateQuery(this.src, this.schema, this.setValues, expr, this.returningItems);
150
+ }
151
+ returning(...columns) {
152
+ return new CfUpdateQuery(this.src, this.schema, this.setValues, this.whereExpr, columns.map((col) => col.toProjectionItem()));
153
+ }
154
+ build() {
155
+ const set = buildSetMap(this.schema, this.setValues);
156
+ const base = UpdateAst.table(this.src).withSet(set);
157
+ const withWhere = this.whereExpr ? base.withWhere(this.whereExpr.ast) : base;
158
+ return this.returningItems ? withWhere.withReturning(this.returningItems) : withWhere;
159
+ }
160
+ };
161
+ var CfSelectQuery = class CfSelectQuery {
162
+ src;
163
+ projectionItems;
164
+ whereExpr;
165
+ orderByItems;
166
+ constructor(src, projectionItems, whereExpr = void 0, orderByItems = []) {
167
+ this.src = src;
168
+ this.projectionItems = projectionItems;
169
+ this.whereExpr = whereExpr;
170
+ this.orderByItems = orderByItems;
171
+ }
172
+ where(expr) {
173
+ return new CfSelectQuery(this.src, this.projectionItems, expr, this.orderByItems);
174
+ }
175
+ orderBy(column, dir = "asc") {
176
+ const item = dir === "asc" ? OrderByItem.asc(column.toRef()) : OrderByItem.desc(column.toRef());
177
+ return new CfSelectQuery(this.src, this.projectionItems, this.whereExpr, [...this.orderByItems, item]);
178
+ }
179
+ build() {
180
+ const base = SelectAst.from(this.src).withProjection(this.projectionItems);
181
+ const withWhere = this.whereExpr ? base.withWhere(this.whereExpr.ast) : base;
182
+ return this.orderByItems.length > 0 ? withWhere.withOrderBy(this.orderByItems) : withWhere;
183
+ }
184
+ };
185
+ /**
186
+ * Declare a control-plane table once, binding column codecs at declaration time.
187
+ * Returns a `TableHandle` whose column properties compose expressions directly
188
+ * without per-call-site codec or column-name threading.
189
+ *
190
+ * ```ts
191
+ * const marker = pgTable({ name: 'marker', schema: 'prisma_contract' }, {
192
+ * space: text(),
193
+ * core_hash: text(),
194
+ * updated_at: timestamptz(),
195
+ * });
196
+ *
197
+ * const query = marker.update()
198
+ * .set({ core_hash: newHash, updated_at: NOW })
199
+ * .where(marker.space.eq(space).and(marker.core_hash.eq(expectedFrom)))
200
+ * .returning(marker.space)
201
+ * .build();
202
+ * ```
203
+ */
204
+ function table(source, schema) {
205
+ const proxies = {};
206
+ for (const [col, desc] of Object.entries(schema)) proxies[col] = makeColumnProxy(source.alias ?? source.name, col, desc);
207
+ return blindCast({
208
+ ...proxies,
209
+ source,
210
+ insert: (row) => new CfInsertQuery(source, schema, row),
211
+ upsert: (row) => new CfUpsertBuilder(source, schema, row),
212
+ update: () => new CfUpdateQuery(source, schema),
213
+ select: (...cols) => new CfSelectQuery(source, cols.map((col) => col.toProjectionItem()))
214
+ });
215
+ }
216
+ function makeColumnProxy(tableName, columnName, desc) {
217
+ const ref = ColumnRef.of(tableName, columnName);
218
+ return {
219
+ codecId: desc.codecId,
220
+ nullable: desc.nullable,
221
+ columnName,
222
+ tableName,
223
+ eq: (value) => value === null ? new CfExpr(NullCheckExpr.isNull(ref)) : new CfExpr(BinaryExpr.eq(ref, toSetExpression(value, desc))),
224
+ neq: (value) => value === null ? new CfExpr(NullCheckExpr.isNotNull(ref)) : new CfExpr(BinaryExpr.neq(ref, toSetExpression(value, desc))),
225
+ isNull: () => new CfExpr(NullCheckExpr.isNull(ref)),
226
+ isNotNull: () => new CfExpr(NullCheckExpr.isNotNull(ref)),
227
+ toRef: () => ref,
228
+ toProjectionItem: (alias = columnName) => ProjectionItem.of(alias, ref, { codecId: desc.codecId })
229
+ };
230
+ }
231
+ function buildExcludedProxy(schema) {
232
+ return blindCast(Object.fromEntries(Object.keys(schema).map((col) => [col, ColumnRef.of("excluded", col)])));
233
+ }
234
+ function isExpressionSource(value) {
235
+ return typeof value === "object" && value !== null && "toExpr" in value && typeof value.toExpr === "function";
236
+ }
237
+ function toInsertValue(value, desc) {
238
+ if (isExpressionSource(value)) {
239
+ const expr = value.toExpr();
240
+ if (expr.kind === "column-ref" || expr.kind === "param-ref" || expr.kind === "prepared-param-ref" || expr.kind === "raw-expr") return expr;
241
+ }
242
+ return ParamRef.of(value, { codec: { codecId: desc.codecId } });
243
+ }
244
+ function toSetExpression(value, desc) {
245
+ if (isExpressionSource(value)) return value.toExpr();
246
+ return ParamRef.of(value, { codec: { codecId: desc.codecId } });
247
+ }
248
+ function buildInsertRow(schema, values) {
249
+ const row = {};
250
+ const rawValues = blindCast(values);
251
+ for (const [col, desc] of Object.entries(schema)) row[col] = toInsertValue(rawValues[col], desc);
252
+ return row;
253
+ }
254
+ function buildSetMap(schema, values) {
255
+ if (values === void 0) return {};
256
+ const set = {};
257
+ const rawSchema = blindCast(schema);
258
+ const rawValues = blindCast(values);
259
+ for (const [col, value] of Object.entries(rawValues)) {
260
+ const desc = rawSchema[col];
261
+ if (desc !== void 0) set[col] = toSetExpression(value, desc);
262
+ }
263
+ return set;
264
+ }
265
+ //#endregion
266
+ export { CfConflictClause, CfExpr, CfInsertQuery, CfSelectQuery, CfUpdateQuery, CfUpsertBuilder, CfUpsertQuery, col, fn, foreignKey, lit, primaryKey, table, unique };
267
+
268
+ //# sourceMappingURL=contract-free.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract-free.mjs","names":[],"sources":["../../src/contract-free/column.ts","../../src/contract-free/table.ts"],"sourcesContent":["import type { ColumnDefaultLiteralInputValue } from '@prisma-next/contract/types';\nimport type { ReferentialAction } from '@prisma-next/sql-contract/types';\nimport type { AnyDdlColumnDefault } from '../ast/ddl-types';\nimport {\n DdlColumn,\n ForeignKeyConstraint,\n FunctionColumnDefault,\n LiteralColumnDefault,\n PrimaryKeyConstraint,\n UniqueConstraint,\n} from '../ast/ddl-types';\n\nexport interface DdlColumnOptions {\n readonly notNull?: boolean;\n readonly primaryKey?: boolean;\n readonly default?: AnyDdlColumnDefault;\n}\n\nexport function lit(value: ColumnDefaultLiteralInputValue): LiteralColumnDefault {\n return new LiteralColumnDefault(value);\n}\n\nexport function fn(expression: string): FunctionColumnDefault {\n return new FunctionColumnDefault(expression);\n}\n\nexport function col(name: string, type: string, options?: DdlColumnOptions): DdlColumn {\n return new DdlColumn({ name, type, ...options });\n}\n\nexport function primaryKey(\n columns: readonly string[],\n options?: { readonly name?: string },\n): PrimaryKeyConstraint {\n return new PrimaryKeyConstraint({ columns, ...options });\n}\n\nexport function foreignKey(\n columns: readonly string[],\n refTable: string,\n refColumns: readonly string[],\n options?: {\n readonly name?: string;\n readonly onDelete?: ReferentialAction;\n readonly onUpdate?: ReferentialAction;\n },\n): ForeignKeyConstraint {\n return new ForeignKeyConstraint({ columns, refTable, refColumns, ...options });\n}\n\nexport function unique(\n columns: readonly string[],\n options?: { readonly name?: string },\n): UniqueConstraint {\n return new UniqueConstraint({ columns, ...options });\n}\n","import { blindCast } from '@prisma-next/utils/casts';\nimport {\n AndExpr,\n type AnyExpression,\n BinaryExpr,\n ColumnRef,\n InsertAst,\n InsertOnConflict,\n type InsertValue,\n NullCheckExpr,\n OrderByItem,\n OrExpr,\n ParamRef,\n ProjectionItem,\n SelectAst,\n type TableSource,\n UpdateAst,\n} from '../ast/types';\n\nexport interface ColumnDescriptor {\n readonly codecId: string;\n readonly nullable: boolean;\n}\n\nexport type ColumnSchema = Record<string, ColumnDescriptor>;\n\n/**\n * A composable WHERE / ON expression. Wraps an `AnyExpression` and exposes\n * fluent boolean combinators, mirroring the spirit of `sql-builder`'s\n * `Expression` interface without the contract-bound type machinery.\n */\nexport class CfExpr {\n constructor(readonly ast: AnyExpression) {}\n\n and(other: CfExpr): CfExpr {\n return new CfExpr(AndExpr.of([this.ast, other.ast]));\n }\n\n or(other: CfExpr): CfExpr {\n return new CfExpr(OrExpr.of([this.ast, other.ast]));\n }\n\n not(): CfExpr {\n return new CfExpr(this.ast.not());\n }\n}\n\n/**\n * Per-column authoring handle exposed as a keyed property on a {@link TableHandle}.\n * Carries codec metadata baked at declaration time so no codec ID, table name, or\n * column name needs to be repeated at the call site.\n */\nexport interface ColumnProxy {\n readonly codecId: string;\n readonly nullable: boolean;\n readonly columnName: string;\n readonly tableName: string;\n eq(value: unknown): CfExpr;\n neq(value: unknown): CfExpr;\n isNull(): CfExpr;\n isNotNull(): CfExpr;\n toRef(): ColumnRef;\n toProjectionItem(alias?: string): ProjectionItem;\n}\n\n/**\n * Object passed to the {@link CfConflictClause.doUpdate} callback. Each key\n * resolves to a `ColumnRef` for the corresponding `excluded.<column>`, so the\n * upsert conflict-update branch can copy proposed values without re-binding\n * parameters.\n */\nexport type ExcludedProxy<Schema extends ColumnSchema> = {\n readonly [K in keyof Schema]: ColumnRef;\n};\n\nexport type TableInsertRow<Schema extends ColumnSchema> = {\n readonly [K in keyof Schema]: unknown;\n};\n\nexport type TableSetValues<Schema extends ColumnSchema> = {\n readonly [K in keyof Schema]?: unknown;\n};\n\n/**\n * Fluent authoring handle for a fixed control-plane table. Column proxies are\n * exposed as keyed properties so `handle.columnName.eq(value)` composes without\n * threading codec IDs, table names, or column refs at the call site.\n */\nexport type TableHandle<Schema extends ColumnSchema> = {\n readonly source: TableSource;\n insert(row: TableInsertRow<Schema>): CfInsertQuery<Schema>;\n upsert(row: TableInsertRow<Schema>): CfUpsertBuilder<Schema>;\n update(): CfUpdateQuery<Schema>;\n select(...columns: ReadonlyArray<ColumnProxy>): CfSelectQuery;\n} & {\n readonly [K in keyof Schema]: ColumnProxy;\n};\n\nexport class CfInsertQuery<Schema extends ColumnSchema> {\n constructor(\n private readonly src: TableSource,\n private readonly schema: Schema,\n private readonly rowValues: TableInsertRow<Schema>,\n private readonly returningItems: ReadonlyArray<ProjectionItem> | undefined = undefined,\n ) {}\n\n returning(...columns: ReadonlyArray<ColumnProxy>): CfInsertQuery<Schema> {\n return new CfInsertQuery(\n this.src,\n this.schema,\n this.rowValues,\n columns.map((col) => col.toProjectionItem()),\n );\n }\n\n build(): InsertAst {\n const row = buildInsertRow(this.schema, this.rowValues);\n const ast = InsertAst.into(this.src).withRows([row]);\n return this.returningItems ? ast.withReturning(this.returningItems) : ast;\n }\n}\n\nexport class CfUpsertBuilder<Schema extends ColumnSchema> {\n constructor(\n private readonly src: TableSource,\n private readonly schema: Schema,\n private readonly rowValues: TableInsertRow<Schema>,\n ) {}\n\n onConflict(...columns: ReadonlyArray<ColumnProxy>): CfConflictClause<Schema> {\n return new CfConflictClause(this.src, this.schema, this.rowValues, [...columns]);\n }\n}\n\nexport class CfConflictClause<Schema extends ColumnSchema> {\n constructor(\n private readonly src: TableSource,\n private readonly schema: Schema,\n private readonly rowValues: TableInsertRow<Schema>,\n private readonly conflictCols: ReadonlyArray<ColumnProxy>,\n ) {}\n\n doUpdate(\n setOrCallback:\n | TableSetValues<Schema>\n | ((excluded: ExcludedProxy<Schema>) => TableSetValues<Schema>),\n ): CfUpsertQuery<Schema> {\n const set =\n typeof setOrCallback === 'function'\n ? setOrCallback(buildExcludedProxy(this.schema))\n : setOrCallback;\n return new CfUpsertQuery(this.src, this.schema, this.rowValues, this.conflictCols, set);\n }\n\n doNothing(): CfUpsertQuery<Schema> {\n return new CfUpsertQuery(this.src, this.schema, this.rowValues, this.conflictCols, undefined);\n }\n}\n\nexport class CfUpsertQuery<Schema extends ColumnSchema> {\n constructor(\n private readonly src: TableSource,\n private readonly schema: Schema,\n private readonly rowValues: TableInsertRow<Schema>,\n private readonly conflictCols: ReadonlyArray<ColumnProxy>,\n private readonly updateSet: TableSetValues<Schema> | undefined,\n ) {}\n\n build(): InsertAst {\n const row = buildInsertRow(this.schema, this.rowValues);\n const conflictRefs = this.conflictCols.map((col) => col.toRef());\n const onConflict =\n this.updateSet === undefined\n ? InsertOnConflict.on(conflictRefs).doNothing()\n : InsertOnConflict.on(conflictRefs).doUpdateSet(buildSetMap(this.schema, this.updateSet));\n return InsertAst.into(this.src).withRows([row]).withOnConflict(onConflict);\n }\n}\n\nexport class CfUpdateQuery<Schema extends ColumnSchema> {\n constructor(\n private readonly src: TableSource,\n private readonly schema: Schema,\n private readonly setValues: TableSetValues<Schema> | undefined = undefined,\n private readonly whereExpr: CfExpr | undefined = undefined,\n private readonly returningItems: ReadonlyArray<ProjectionItem> | undefined = undefined,\n ) {}\n\n set(values: TableSetValues<Schema>): CfUpdateQuery<Schema> {\n return new CfUpdateQuery(this.src, this.schema, values, this.whereExpr, this.returningItems);\n }\n\n where(expr: CfExpr): CfUpdateQuery<Schema> {\n return new CfUpdateQuery(this.src, this.schema, this.setValues, expr, this.returningItems);\n }\n\n returning(...columns: ReadonlyArray<ColumnProxy>): CfUpdateQuery<Schema> {\n return new CfUpdateQuery(\n this.src,\n this.schema,\n this.setValues,\n this.whereExpr,\n columns.map((col) => col.toProjectionItem()),\n );\n }\n\n build(): UpdateAst {\n const set = buildSetMap(this.schema, this.setValues);\n const base = UpdateAst.table(this.src).withSet(set);\n const withWhere = this.whereExpr ? base.withWhere(this.whereExpr.ast) : base;\n return this.returningItems ? withWhere.withReturning(this.returningItems) : withWhere;\n }\n}\n\nexport class CfSelectQuery {\n constructor(\n private readonly src: TableSource,\n private readonly projectionItems: ReadonlyArray<ProjectionItem>,\n private readonly whereExpr: CfExpr | undefined = undefined,\n private readonly orderByItems: ReadonlyArray<OrderByItem> = [],\n ) {}\n\n where(expr: CfExpr): CfSelectQuery {\n return new CfSelectQuery(this.src, this.projectionItems, expr, this.orderByItems);\n }\n\n orderBy(column: ColumnProxy, dir: 'asc' | 'desc' = 'asc'): CfSelectQuery {\n const item = dir === 'asc' ? OrderByItem.asc(column.toRef()) : OrderByItem.desc(column.toRef());\n return new CfSelectQuery(this.src, this.projectionItems, this.whereExpr, [\n ...this.orderByItems,\n item,\n ]);\n }\n\n build(): SelectAst {\n const base = SelectAst.from(this.src).withProjection(this.projectionItems);\n const withWhere = this.whereExpr ? base.withWhere(this.whereExpr.ast) : base;\n return this.orderByItems.length > 0 ? withWhere.withOrderBy(this.orderByItems) : withWhere;\n }\n}\n\n/**\n * Declare a control-plane table once, binding column codecs at declaration time.\n * Returns a `TableHandle` whose column properties compose expressions directly\n * without per-call-site codec or column-name threading.\n *\n * ```ts\n * const marker = pgTable({ name: 'marker', schema: 'prisma_contract' }, {\n * space: text(),\n * core_hash: text(),\n * updated_at: timestamptz(),\n * });\n *\n * const query = marker.update()\n * .set({ core_hash: newHash, updated_at: NOW })\n * .where(marker.space.eq(space).and(marker.core_hash.eq(expectedFrom)))\n * .returning(marker.space)\n * .build();\n * ```\n */\nexport function table<Schema extends ColumnSchema>(\n source: TableSource,\n schema: Schema,\n): TableHandle<Schema> {\n const proxies: Record<string, ColumnProxy> = {};\n for (const [col, desc] of Object.entries(schema)) {\n proxies[col] = makeColumnProxy(source.alias ?? source.name, col, desc);\n }\n\n const handle = {\n ...proxies,\n source,\n insert: (row: TableInsertRow<Schema>) => new CfInsertQuery(source, schema, row),\n upsert: (row: TableInsertRow<Schema>) => new CfUpsertBuilder(source, schema, row),\n update: () => new CfUpdateQuery(source, schema),\n select: (...cols: ReadonlyArray<ColumnProxy>) =>\n new CfSelectQuery(\n source,\n cols.map((col) => col.toProjectionItem()),\n ),\n };\n\n return blindCast<\n TableHandle<Schema>,\n 'Column proxies are dynamically built from Schema keys — TypeScript cannot verify the per-key ColumnProxy constraint at the spread call site. Construction is correct by construction: every key maps to makeColumnProxy(source.name, key, schema[key]).'\n >(handle);\n}\n\nfunction makeColumnProxy(\n tableName: string,\n columnName: string,\n desc: ColumnDescriptor,\n): ColumnProxy {\n const ref = ColumnRef.of(tableName, columnName);\n return {\n codecId: desc.codecId,\n nullable: desc.nullable,\n columnName,\n tableName,\n eq: (value) =>\n value === null\n ? new CfExpr(NullCheckExpr.isNull(ref))\n : new CfExpr(BinaryExpr.eq(ref, toSetExpression(value, desc))),\n neq: (value) =>\n value === null\n ? new CfExpr(NullCheckExpr.isNotNull(ref))\n : new CfExpr(BinaryExpr.neq(ref, toSetExpression(value, desc))),\n isNull: () => new CfExpr(NullCheckExpr.isNull(ref)),\n isNotNull: () => new CfExpr(NullCheckExpr.isNotNull(ref)),\n toRef: () => ref,\n toProjectionItem: (alias = columnName) =>\n ProjectionItem.of(alias, ref, { codecId: desc.codecId }),\n };\n}\n\nfunction buildExcludedProxy<Schema extends ColumnSchema>(schema: Schema): ExcludedProxy<Schema> {\n return blindCast<\n ExcludedProxy<Schema>,\n 'Object.fromEntries cannot preserve per-key ColumnRef types — correct by construction: every key maps to ColumnRef.of(\"excluded\", key).'\n >(Object.fromEntries(Object.keys(schema).map((col) => [col, ColumnRef.of('excluded', col)])));\n}\n\nfunction isExpressionSource(value: unknown): value is { toExpr(): AnyExpression } {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'toExpr' in value &&\n typeof value.toExpr === 'function'\n );\n}\n\nfunction toInsertValue(value: unknown, desc: ColumnDescriptor): InsertValue {\n if (isExpressionSource(value)) {\n const expr = value.toExpr();\n if (\n expr.kind === 'column-ref' ||\n expr.kind === 'param-ref' ||\n expr.kind === 'prepared-param-ref' ||\n expr.kind === 'raw-expr'\n ) {\n return expr;\n }\n }\n return ParamRef.of(value, { codec: { codecId: desc.codecId } });\n}\n\nfunction toSetExpression(value: unknown, desc: ColumnDescriptor): AnyExpression {\n if (isExpressionSource(value)) {\n return value.toExpr();\n }\n return ParamRef.of(value, { codec: { codecId: desc.codecId } });\n}\n\nfunction buildInsertRow<Schema extends ColumnSchema>(\n schema: Schema,\n values: TableInsertRow<Schema>,\n): Record<string, InsertValue> {\n const row: Record<string, InsertValue> = {};\n const rawValues = blindCast<\n Record<string, unknown>,\n 'TableInsertRow<Schema> maps Schema keys to unknown; indexing by the same string keys is correct by construction'\n >(values);\n for (const [col, desc] of Object.entries(schema)) {\n row[col] = toInsertValue(rawValues[col], desc);\n }\n return row;\n}\n\nfunction buildSetMap<Schema extends ColumnSchema>(\n schema: Schema,\n values: TableSetValues<Schema> | undefined,\n): Record<string, AnyExpression> {\n if (values === undefined) return {};\n const set: Record<string, AnyExpression> = {};\n const rawSchema = blindCast<\n Record<string, ColumnDescriptor>,\n 'Schema extends ColumnSchema = Record<string, ColumnDescriptor>; runtime key access is correct by construction'\n >(schema);\n const rawValues = blindCast<\n Record<string, unknown>,\n 'TableSetValues<Schema> maps Schema keys to unknown; iterating with Object.entries is correct by construction'\n >(values);\n for (const [col, value] of Object.entries(rawValues)) {\n const desc = rawSchema[col];\n if (desc !== undefined) {\n set[col] = toSetExpression(value, desc);\n }\n }\n return set;\n}\n"],"mappings":";;;;AAkBA,SAAgB,IAAI,OAA6D;CAC/E,OAAO,IAAI,qBAAqB,KAAK;AACvC;AAEA,SAAgB,GAAG,YAA2C;CAC5D,OAAO,IAAI,sBAAsB,UAAU;AAC7C;AAEA,SAAgB,IAAI,MAAc,MAAc,SAAuC;CACrF,OAAO,IAAI,UAAU;EAAE;EAAM;EAAM,GAAG;CAAQ,CAAC;AACjD;AAEA,SAAgB,WACd,SACA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