@prisma-next/sql-relational-core 0.11.0-dev.6 → 0.11.0-dev.7
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.
|
@@ -26,9 +26,9 @@ function codecRefForStorageColumn(storage, tableName, columnName) {
|
|
|
26
26
|
if (columnDef.typeRef !== void 0) {
|
|
27
27
|
let instance = storage.types?.[columnDef.typeRef];
|
|
28
28
|
if (!instance) for (const ns of Object.values(storage.namespaces)) {
|
|
29
|
-
const
|
|
30
|
-
if (
|
|
31
|
-
const nsEntry =
|
|
29
|
+
const nsEnums = ns.enum;
|
|
30
|
+
if (nsEnums) {
|
|
31
|
+
const nsEntry = nsEnums[columnDef.typeRef];
|
|
32
32
|
if (nsEntry !== void 0) {
|
|
33
33
|
instance = nsEntry;
|
|
34
34
|
break;
|
|
@@ -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
|
|
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,WAAW,EAAE;EAClD,MAAM,YAAY,GAAG,OAAO;EAC5B,IAAI,cAAc,KAAA,GAAW;GAC3B,WAAW;GACX;;;CAGJ,IAAI,CAAC,UAAU,O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,OAAe,QAAsC;GACrE,IAAI,CAAC,SAAS,OAAO,KAAA;GACrB,OAAO,yBAAyB,SAAS,OAAO,OAAO;;EAEzD,CAAC,SAA0C;GACzC,OAAO,KAAK,QAAQ;;EAEtB,aAAa,YAA8C;GACzD,OAAO,aAAa,IAAI,WAAW,IAAI,OAAO,OAAO,EAAE,CAAC;;EAE3D"}
|
package/package.json
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/sql-relational-core",
|
|
3
|
-
"version": "0.11.0-dev.
|
|
3
|
+
"version": "0.11.0-dev.7",
|
|
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.11.0-dev.
|
|
10
|
-
"@prisma-next/framework-components": "0.11.0-dev.
|
|
11
|
-
"@prisma-next/operations": "0.11.0-dev.
|
|
12
|
-
"@prisma-next/sql-contract": "0.11.0-dev.
|
|
13
|
-
"@prisma-next/sql-operations": "0.11.0-dev.
|
|
14
|
-
"@prisma-next/utils": "0.11.0-dev.
|
|
9
|
+
"@prisma-next/contract": "0.11.0-dev.7",
|
|
10
|
+
"@prisma-next/framework-components": "0.11.0-dev.7",
|
|
11
|
+
"@prisma-next/operations": "0.11.0-dev.7",
|
|
12
|
+
"@prisma-next/sql-contract": "0.11.0-dev.7",
|
|
13
|
+
"@prisma-next/sql-operations": "0.11.0-dev.7",
|
|
14
|
+
"@prisma-next/utils": "0.11.0-dev.7",
|
|
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.11.0-dev.
|
|
21
|
-
"@prisma-next/test-utils": "0.11.0-dev.
|
|
22
|
-
"@prisma-next/tsconfig": "0.11.0-dev.
|
|
23
|
-
"@prisma-next/tsdown": "0.11.0-dev.
|
|
20
|
+
"@prisma-next/sql-contract-ts": "0.11.0-dev.7",
|
|
21
|
+
"@prisma-next/test-utils": "0.11.0-dev.7",
|
|
22
|
+
"@prisma-next/tsconfig": "0.11.0-dev.7",
|
|
23
|
+
"@prisma-next/tsdown": "0.11.0-dev.7",
|
|
24
24
|
"tsdown": "0.22.0",
|
|
25
25
|
"typescript": "5.9.3",
|
|
26
26
|
"vitest": "4.1.6"
|
|
@@ -38,9 +38,9 @@ export function codecRefForStorageColumn(
|
|
|
38
38
|
let instance: unknown = storage.types?.[columnDef.typeRef];
|
|
39
39
|
if (!instance) {
|
|
40
40
|
for (const ns of Object.values(storage.namespaces)) {
|
|
41
|
-
const
|
|
42
|
-
if (
|
|
43
|
-
const nsEntry =
|
|
41
|
+
const nsEnums = (ns as { enum?: Record<string, unknown> }).enum;
|
|
42
|
+
if (nsEnums) {
|
|
43
|
+
const nsEntry = nsEnums[columnDef.typeRef];
|
|
44
44
|
if (nsEntry !== undefined) {
|
|
45
45
|
instance = nsEntry;
|
|
46
46
|
break;
|