@prisma-next/sql-relational-core 0.13.0-dev.28 → 0.13.0-dev.29

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.
@@ -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;;;;;;;;;;;iBCQgB,wBAAA,CACd,OAAA,EAAS,UAAA,EACT,WAAA,UACA,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;;;;;;;;;;;iBCIgB,wBAAA,CACd,OAAA,EAAS,UAAA,EACT,WAAA,UACA,SAAA,UACA,UAAA,WACC,QAAQ"}
@@ -1,5 +1,5 @@
1
1
  import { resolveStorageTable } from "@prisma-next/sql-contract/resolve-storage-table";
2
- import { isPostgresEnumStorageEntry, isStorageTypeInstance } from "@prisma-next/sql-contract/types";
2
+ import { isStorageTypeInstance } from "@prisma-next/sql-contract/types";
3
3
  //#region src/codec-ref-for-column.ts
4
4
  /**
5
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`.
@@ -22,19 +22,8 @@ function codecRefForStorageColumn(storage, namespaceId, tableName, columnName) {
22
22
  const columnDef = resolved.table.columns[columnName];
23
23
  if (!columnDef) return void 0;
24
24
  if (columnDef.typeRef !== void 0) {
25
- let instance = storage.types?.[columnDef.typeRef];
26
- if (!instance) for (const ns of Object.values(storage.namespaces)) {
27
- const nsEntry = ns.entries.type?.[columnDef.typeRef];
28
- if (nsEntry !== void 0) {
29
- instance = nsEntry;
30
- break;
31
- }
32
- }
25
+ const instance = storage.types?.[columnDef.typeRef];
33
26
  if (!instance) return void 0;
34
- if (isPostgresEnumStorageEntry(instance)) return {
35
- codecId: instance.codecId,
36
- typeParams: { values: instance.values }
37
- };
38
27
  if (isStorageTypeInstance(instance)) {
39
28
  const instanceParams = instance.typeParams;
40
29
  return instanceParams !== void 0 && Object.keys(instanceParams).length > 0 ? {
@@ -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 { 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;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,GAAG;GAMnC,MAAM,iBAAiB,SAAS;GAEhC,OADqB,mBAAmB,KAAA,KAAa,OAAO,KAAK,cAAc,CAAC,CAAC,SAAS,IAEtF;IAAE,SAAS,SAAS;IAAS,YAAY;GAA4B,IACrE,EAAE,SAAS,SAAS,QAAQ;EAClC;EACA;CACF;CACA,IAAI,UAAU,eAAe,KAAA,KAAa,OAAO,KAAK,UAAU,UAAU,CAAC,CAAC,SAAS,GACnF,OAAO;EAAE,SAAS,UAAU;EAAS,YAAY,UAAU;CAAwB;CAErF,OAAO,EAAE,SAAS,UAAU,QAAQ;AACtC;;;;;;;;;;;;;AChEA,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,aAAqB,OAAe,QAAsC;GAC1F,IAAI,CAAC,SAAS,OAAO,KAAA;GACrB,OAAO,yBAAyB,SAAS,aAAa,OAAO,MAAM;EACrE;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 { isStorageTypeInstance, type SqlStorage } 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 const instance = storage.types?.[columnDef.typeRef];\n if (!instance) return undefined;\n if (isStorageTypeInstance(instance)) {\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":";;;;;;;;;;;;;;;;;;AAoBA,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,MAAM,WAAW,QAAQ,QAAQ,UAAU;EAC3C,IAAI,CAAC,UAAU,OAAO,KAAA;EACtB,IAAI,sBAAsB,QAAQ,GAAG;GACnC,MAAM,iBAAiB,SAAS;GAEhC,OADqB,mBAAmB,KAAA,KAAa,OAAO,KAAK,cAAc,CAAC,CAAC,SAAS,IAEtF;IAAE,SAAS,SAAS;IAAS,YAAY;GAA4B,IACrE,EAAE,SAAS,SAAS,QAAQ;EAClC;EACA;CACF;CACA,IAAI,UAAU,eAAe,KAAA,KAAa,OAAO,KAAK,UAAU,UAAU,CAAC,CAAC,SAAS,GACnF,OAAO;EAAE,SAAS,UAAU;EAAS,YAAY,UAAU;CAAwB;CAErF,OAAO,EAAE,SAAS,UAAU,QAAQ;AACtC;;;;;;;;;;;;;AC/BA,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,aAAqB,OAAe,QAAsC;GAC1F,IAAI,CAAC,SAAS,OAAO,KAAA;GACrB,OAAO,yBAAyB,SAAS,aAAa,OAAO,MAAM;EACrE;EACA,CAAC,SAA0C;GACzC,OAAO,KAAK,OAAO;EACrB;EACA,aAAa,YAA8C;GACzD,OAAO,aAAa,IAAI,UAAU,KAAK,OAAO,OAAO,CAAC,CAAC;EACzD;CACF;AACF"}
package/package.json CHANGED
@@ -1,26 +1,26 @@
1
1
  {
2
2
  "name": "@prisma-next/sql-relational-core",
3
- "version": "0.13.0-dev.28",
3
+ "version": "0.13.0-dev.29",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "description": "AST types, query lane context, and type utilities for Prisma Next SQL lanes",
8
8
  "dependencies": {
9
- "@prisma-next/contract": "0.13.0-dev.28",
10
- "@prisma-next/framework-components": "0.13.0-dev.28",
11
- "@prisma-next/operations": "0.13.0-dev.28",
12
- "@prisma-next/sql-contract": "0.13.0-dev.28",
13
- "@prisma-next/sql-operations": "0.13.0-dev.28",
14
- "@prisma-next/utils": "0.13.0-dev.28",
9
+ "@prisma-next/contract": "0.13.0-dev.29",
10
+ "@prisma-next/framework-components": "0.13.0-dev.29",
11
+ "@prisma-next/operations": "0.13.0-dev.29",
12
+ "@prisma-next/sql-contract": "0.13.0-dev.29",
13
+ "@prisma-next/sql-operations": "0.13.0-dev.29",
14
+ "@prisma-next/utils": "0.13.0-dev.29",
15
15
  "@standard-schema/spec": "^1.1.0",
16
16
  "arktype": "^2.2.0",
17
17
  "ts-toolbelt": "^9.6.0"
18
18
  },
19
19
  "devDependencies": {
20
- "@prisma-next/sql-contract-ts": "0.13.0-dev.28",
21
- "@prisma-next/test-utils": "0.13.0-dev.28",
22
- "@prisma-next/tsconfig": "0.13.0-dev.28",
23
- "@prisma-next/tsdown": "0.13.0-dev.28",
20
+ "@prisma-next/sql-contract-ts": "0.13.0-dev.29",
21
+ "@prisma-next/test-utils": "0.13.0-dev.29",
22
+ "@prisma-next/tsconfig": "0.13.0-dev.29",
23
+ "@prisma-next/tsdown": "0.13.0-dev.29",
24
24
  "tsdown": "0.22.1",
25
25
  "typescript": "5.9.3",
26
26
  "vitest": "4.1.8"
@@ -1,11 +1,7 @@
1
1
  import type { JsonValue } from '@prisma-next/contract/types';
2
2
  import type { CodecRef } from '@prisma-next/framework-components/codec';
3
3
  import { resolveStorageTable } from '@prisma-next/sql-contract/resolve-storage-table';
4
- import {
5
- isPostgresEnumStorageEntry,
6
- isStorageTypeInstance,
7
- type SqlStorage,
8
- } from '@prisma-next/sql-contract/types';
4
+ import { isStorageTypeInstance, type SqlStorage } from '@prisma-next/sql-contract/types';
9
5
 
10
6
  /**
11
7
  * 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`.
@@ -34,38 +30,9 @@ export function codecRefForStorageColumn(
34
30
  const columnDef = tableDef.columns[columnName];
35
31
  if (!columnDef) return undefined;
36
32
  if (columnDef.typeRef !== undefined) {
37
- let instance: unknown = storage.types?.[columnDef.typeRef];
38
- if (!instance) {
39
- for (const ns of Object.values(storage.namespaces)) {
40
- const typeSlot = (ns.entries as { type?: Record<string, unknown> }).type;
41
- const nsEntry = typeSlot?.[columnDef.typeRef];
42
- if (nsEntry !== undefined) {
43
- instance = nsEntry;
44
- break;
45
- }
46
- }
47
- }
33
+ const instance = storage.types?.[columnDef.typeRef];
48
34
  if (!instance) return undefined;
49
- if (isPostgresEnumStorageEntry(instance)) {
50
- // Canonical path: the entry is a live `PostgresEnumType` IR
51
- // instance reached through the per-target serializer's
52
- // hydration. Raw JSON envelopes carrying `kind: 'postgres-enum'`
53
- // never reach this site — `SqlStorage.normaliseTypeEntry`
54
- // rejects them upstream (F09). Read `codecId` and `values` off
55
- // the structural shape (enumerable own properties on the live
56
- // instance) so the dispatch stays layered against the family
57
- // alphabet rather than a target-specific class import.
58
- return {
59
- codecId: instance.codecId,
60
- typeParams: { values: instance.values } as unknown as JsonValue,
61
- };
62
- }
63
35
  if (isStorageTypeInstance(instance)) {
64
- // Empty-state canonicalization: a `StorageTypeInstance` with absent
65
- // (or empty) `typeParams` produces a `CodecRef` with no `typeParams`
66
- // field. Equivalent to the non-parameterized-column branch below.
67
- // Carrying `{}` here would break content-keyed memoisation and trip
68
- // the runtime validator against non-parameterized codec descriptors.
69
36
  const instanceParams = instance.typeParams;
70
37
  const hasParamKeys = instanceParams !== undefined && Object.keys(instanceParams).length > 0;
71
38
  return hasParamKeys