@prisma-next/sql-contract 0.13.0-dev.3 → 0.13.0-dev.30

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 (36) hide show
  1. package/dist/factories.d.mts +2 -2
  2. package/dist/factories.mjs +1 -1
  3. package/dist/index-type-validation.d.mts +1 -1
  4. package/dist/index-type-validation.mjs +8 -11
  5. package/dist/index-type-validation.mjs.map +1 -1
  6. package/dist/resolve-storage-table.d.mts +1 -1
  7. package/dist/resolve-storage-table.d.mts.map +1 -1
  8. package/dist/resolve-storage-table.mjs +11 -8
  9. package/dist/resolve-storage-table.mjs.map +1 -1
  10. package/dist/{sql-storage-CXf9xjAL.d.mts → sql-storage-BCLmt-nS.d.mts} +30 -20
  11. package/dist/{sql-storage-CXf9xjAL.d.mts.map → sql-storage-BCLmt-nS.d.mts.map} +1 -1
  12. package/dist/{types-DqhaAjCH.mjs → types-B7kJ6S7m.mjs} +42 -50
  13. package/dist/types-B7kJ6S7m.mjs.map +1 -0
  14. package/dist/{types-DEnWD3xB.d.mts → types-CFpK1iC5.d.mts} +6 -59
  15. package/dist/types-CFpK1iC5.d.mts.map +1 -0
  16. package/dist/types.d.mts +3 -3
  17. package/dist/types.mjs +2 -2
  18. package/dist/validators.d.mts +29 -28
  19. package/dist/validators.d.mts.map +1 -1
  20. package/dist/validators.mjs +71 -95
  21. package/dist/validators.mjs.map +1 -1
  22. package/package.json +7 -7
  23. package/src/exports/types.ts +2 -4
  24. package/src/index-type-validation.ts +2 -3
  25. package/src/ir/build-sql-namespace.ts +62 -32
  26. package/src/ir/sql-node.ts +2 -2
  27. package/src/ir/sql-storage.ts +22 -24
  28. package/src/ir/sql-unbound-namespace.ts +15 -3
  29. package/src/ir/storage-type-instance.ts +3 -3
  30. package/src/ir/storage-value-set.ts +6 -5
  31. package/src/resolve-storage-table.ts +12 -17
  32. package/src/types.ts +2 -6
  33. package/src/validators.ts +93 -113
  34. package/dist/types-DEnWD3xB.d.mts.map +0 -1
  35. package/dist/types-DqhaAjCH.mjs.map +0 -1
  36. package/src/ir/postgres-enum-storage-entry.ts +0 -57
@@ -1,3 +1,4 @@
1
+ import type { JsonValue } from '@prisma-next/contract/types';
1
2
  import { freezeNode } from '@prisma-next/framework-components/ir';
2
3
  import { SqlNode } from './sql-node';
3
4
 
@@ -7,9 +8,9 @@ import { SqlNode } from './sql-node';
7
8
  * walker can hand a validated literal straight to `new`.
8
9
  */
9
10
  export interface StorageValueSetInput {
10
- readonly kind: 'value-set';
11
+ readonly kind: 'valueSet';
11
12
  /** Ordered permitted values, codec-encoded. Declaration order is preserved. */
12
- readonly values: readonly string[];
13
+ readonly values: readonly JsonValue[];
13
14
  }
14
15
 
15
16
  /**
@@ -21,7 +22,7 @@ export interface StorageValueSetInput {
21
22
  * column that references it already holds the codec; the value-set holds
22
23
  * only the permitted values.
23
24
  *
24
- * The node's `kind` is enumerable (`'value-set'`) so the JSON envelope
25
+ * The node's `kind` is enumerable (`'valueSet'`) so the JSON envelope
25
26
  * carries the discriminator and the serializer hydration walker can
26
27
  * dispatch on it. This follows the per-leaf enumerable-kind convention
27
28
  * established in the SQL-node comment (future polymorphic dispatch on
@@ -31,8 +32,8 @@ export interface StorageValueSetInput {
31
32
  * the parent namespace's `valueSet: Record<string, StorageValueSet>` map.
32
33
  */
33
34
  export class StorageValueSet extends SqlNode {
34
- override readonly kind = 'value-set' as const;
35
- readonly values: readonly string[];
35
+ override readonly kind = 'valueSet' as const;
36
+ readonly values: readonly JsonValue[];
36
37
 
37
38
  constructor(input: StorageValueSetInput) {
38
39
  super();
@@ -1,4 +1,5 @@
1
- import type { SqlNamespace, SqlStorage } from './ir/sql-storage';
1
+ import { entityAt } from '@prisma-next/framework-components/ir';
2
+ import type { SqlStorage } from './ir/sql-storage';
2
3
  import type { StorageTable } from './ir/storage-table';
3
4
 
4
5
  export interface ResolvedStorageTable {
@@ -6,20 +7,6 @@ export interface ResolvedStorageTable {
6
7
  readonly table: StorageTable;
7
8
  }
8
9
 
9
- function tableInNamespace(
10
- namespace: SqlNamespace | undefined,
11
- tableName: string,
12
- ): StorageTable | undefined {
13
- if (namespace === undefined) {
14
- return undefined;
15
- }
16
- const tables = namespace.entries.table;
17
- if (!Object.hasOwn(tables, tableName)) {
18
- return undefined;
19
- }
20
- return tables[tableName];
21
- }
22
-
23
10
  /**
24
11
  * Resolve a bare storage table name to its namespace coordinate and table IR.
25
12
  *
@@ -35,13 +22,21 @@ export function resolveStorageTable(
35
22
  namespaceId?: string,
36
23
  ): ResolvedStorageTable | undefined {
37
24
  if (namespaceId !== undefined) {
38
- const table = tableInNamespace(storage.namespaces[namespaceId], tableName);
25
+ const table = entityAt<StorageTable>(storage, {
26
+ namespaceId,
27
+ entityKind: 'table',
28
+ entityName: tableName,
29
+ });
39
30
  return table === undefined ? undefined : { namespaceId, table };
40
31
  }
41
32
 
42
33
  const matches: ResolvedStorageTable[] = [];
43
34
  for (const candidateNamespaceId of Object.keys(storage.namespaces)) {
44
- const table = tableInNamespace(storage.namespaces[candidateNamespaceId], tableName);
35
+ const table = entityAt<StorageTable>(storage, {
36
+ namespaceId: candidateNamespaceId,
37
+ entityKind: 'table',
38
+ entityName: tableName,
39
+ });
45
40
  if (table !== undefined) {
46
41
  matches.push({ namespaceId: candidateNamespaceId, table });
47
42
  }
package/src/types.ts CHANGED
@@ -21,20 +21,16 @@ export {
21
21
  ForeignKeyReference,
22
22
  type ForeignKeyReferenceInput,
23
23
  } from './ir/foreign-key-reference';
24
- export {
25
- isPostgresEnumStorageEntry,
26
- POSTGRES_ENUM_KIND,
27
- type PostgresEnumStorageEntry,
28
- } from './ir/postgres-enum-storage-entry';
29
24
  export { PrimaryKey, type PrimaryKeyInput } from './ir/primary-key';
30
25
  export { Index, type IndexInput } from './ir/sql-index';
31
26
  export { SqlNode } from './ir/sql-node';
32
27
  export {
28
+ type SqlNamespace,
29
+ type SqlNamespaceEntries,
33
30
  type SqlNamespaceTablesInput,
34
31
  SqlStorage,
35
32
  type SqlStorageInput,
36
33
  type SqlStorageTypeEntry,
37
- storageTableAt,
38
34
  } from './ir/sql-storage';
39
35
  export { SqlUnboundNamespace } from './ir/sql-unbound-namespace';
40
36
  export { StorageColumn, type StorageColumnInput } from './ir/storage-column';
package/src/validators.ts CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  } from '@prisma-next/contract/types';
8
8
  import { validateContractDomain } from '@prisma-next/contract/validate-domain';
9
9
  import { type Namespace, UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';
10
- import { blindCast } from '@prisma-next/utils/casts';
10
+ import { blindCast, castAs } from '@prisma-next/utils/casts';
11
11
  import { ifDefined } from '@prisma-next/utils/defined';
12
12
  import { type Type, type } from 'arktype';
13
13
  import { buildSqlNamespaceMap } from './ir/build-sql-namespace';
@@ -77,11 +77,19 @@ const ExecutionSchema = type({
77
77
  },
78
78
  });
79
79
 
80
- const ValueSetRefSchema = type({
81
- plane: "'domain' | 'storage'",
80
+ const StorageValueSetRefSchema = type({
81
+ plane: "'storage'",
82
82
  namespaceId: 'string',
83
- entityKind: "'enum' | 'value-set'",
84
- name: 'string',
83
+ entityKind: "'valueSet'",
84
+ entityName: 'string',
85
+ 'spaceId?': 'string',
86
+ });
87
+
88
+ const DomainEnumRefSchema = type({
89
+ plane: "'domain'",
90
+ namespaceId: 'string',
91
+ entityKind: "'enum'",
92
+ entityName: 'string',
85
93
  'spaceId?': 'string',
86
94
  });
87
95
 
@@ -94,7 +102,7 @@ const StorageColumnSchema = type({
94
102
  'typeRef?': 'string',
95
103
  'default?': ColumnDefaultSchema,
96
104
  'control?': ControlPolicySchema,
97
- 'valueSet?': ValueSetRefSchema,
105
+ 'valueSet?': StorageValueSetRefSchema,
98
106
  }).narrow((col, ctx) => {
99
107
  if (col.typeParams !== undefined && col.typeRef !== undefined) {
100
108
  return ctx.mustBe('a column with either typeParams or typeRef, not both');
@@ -105,8 +113,7 @@ const StorageColumnSchema = type({
105
113
  /**
106
114
  * Codec-triple entry persisted under `storage.types[name]`. Carries an
107
115
  * enumerable literal `kind: 'codec-instance'` discriminator so the
108
- * polymorphic slot dispatch can distinguish codec triples from
109
- * class-instance kinds (e.g. `'postgres-enum'`) sharing the slot.
116
+ * polymorphic slot dispatch can distinguish codec triples.
110
117
  */
111
118
  const StorageTypeInstanceSchema = type
112
119
  .declare<StorageTypeInstanceInput & { kind: 'codec-instance' }>()
@@ -117,30 +124,19 @@ const StorageTypeInstanceSchema = type
117
124
  'typeParams?': 'Record<string, unknown>',
118
125
  });
119
126
 
120
- /**
121
- * Postgres native enum entry under `storage.namespaces[namespaceId].entries.type[name]`.
122
- * Document-scoped `storage.types` carries codec aliases only
123
- * (`DocumentScopedStorageTypeSchema`).
124
- */
125
- const PostgresEnumTypeSchema = type({
126
- kind: "'postgres-enum'",
127
- 'name?': 'string',
128
- 'nativeType?': 'string',
129
- values: type.string.array().readonly(),
130
- 'control?': ControlPolicySchema,
131
- });
132
-
133
127
  /** Document-scoped `storage.types`: codec triples only. */
134
128
  const DocumentScopedStorageTypeSchema = StorageTypeInstanceSchema;
135
129
 
136
130
  /**
137
131
  * Storage value-set entry under `storage.namespaces[id].entries.valueSet[name]`.
138
- * Carries a `kind: 'value-set'` discriminator (enumerable, survives JSON) and an
132
+ * Carries a `kind: 'valueSet'` discriminator (enumerable, survives JSON) and an
139
133
  * ordered `values` array of codec-encoded permitted values.
140
134
  */
141
135
  export const StorageValueSetSchema = type({
142
- kind: "'value-set'",
143
- values: type.string.array().readonly(),
136
+ kind: "'valueSet'",
137
+ values: type('string | number | boolean | null | unknown[] | Record<string, unknown>')
138
+ .array()
139
+ .readonly(),
144
140
  });
145
141
 
146
142
  /**
@@ -152,7 +148,7 @@ export const ContractEnumSchema = type({
152
148
  codecId: 'string',
153
149
  members: type({
154
150
  name: 'string',
155
- value: 'string',
151
+ value: 'string | number | boolean | null | unknown[] | Record<string, unknown>',
156
152
  })
157
153
  .array()
158
154
  .readonly(),
@@ -208,7 +204,7 @@ export const CheckConstraintSchema = type({
208
204
  '+': 'reject',
209
205
  name: 'string',
210
206
  column: 'string',
211
- valueSet: ValueSetRefSchema,
207
+ valueSet: StorageValueSetRefSchema,
212
208
  });
213
209
 
214
210
  const StorageTableSchema = type({
@@ -223,103 +219,88 @@ const StorageTableSchema = type({
223
219
  });
224
220
 
225
221
  /**
226
- * Re-exported so target packs can register their `validatorSchema`
227
- * fragment without re-declaring the schema for the kinds the family
228
- * core already validates. Full extraction of enum-specific schemas
229
- * into the Postgres pack is a follow-up; today the symbol lives here.
230
- */
231
- export { PostgresEnumTypeSchema };
232
-
233
- /**
234
- * Composes a hardcoded family `fallback` schema with optional
235
- * pack-contributed `fragments` keyed by the entry's `kind`
236
- * discriminator. The composition is **additive**, not substitutive:
237
- *
238
- * - No fragments registered → entries are validated by `fallback`
239
- * alone (the unchanged baseline).
240
- * - An entry's `kind` matches `fallbackKind` AND a fragment for that
241
- * kind is registered → the entry must pass **both** `fallback` and
242
- * the fragment. This preserves family-owned invariants (e.g. the
243
- * built-in `PostgresEnumType` shape) even when a pack contributes
244
- * its own schema for the same kind.
245
- * - An entry's `kind` matches a registered fragment for some
246
- * non-fallback kind → the fragment alone validates the entry.
247
- * `fallback` is family-specific (validates a single hardcoded kind)
248
- * and would reject any other kind, so it does not apply here.
249
- * - An entry's `kind` matches no fragment → fall through to
250
- * `fallback`.
222
+ * Composes the single entry-validator registry consulted during
223
+ * structural validation. SQL core registers its own kinds (`'table'`,
224
+ * `'valueSet'`) into the same registry targets extend — there is no
225
+ * separate built-in fallback tier. Target packs pass their contributed
226
+ * kinds via `packSchemas`.
251
227
  */
252
- function namespaceSlotEntrySchema(
253
- fallback: Type<unknown>,
254
- fallbackKind: string,
255
- fragments?: ReadonlyMap<string, Type<unknown>>,
256
- ): Type<unknown> {
257
- if (fragments === undefined || fragments.size === 0) {
258
- return fallback;
259
- }
260
- return type('unknown').narrow((entry, ctx) => {
261
- if (typeof entry !== 'object' || entry === null || Array.isArray(entry)) {
262
- return ctx.mustBe('an object');
263
- }
264
- const kind = (entry as { kind?: unknown }).kind;
265
- if (typeof kind === 'string') {
266
- const fragment = fragments.get(kind);
267
- if (fragment !== undefined) {
268
- if (kind === fallbackKind) {
269
- const baseParsed = fallback(entry);
270
- if (baseParsed instanceof type.errors) {
271
- return ctx.reject({ expected: baseParsed.summary });
272
- }
273
- }
274
- const parsed = fragment(entry);
275
- if (parsed instanceof type.errors) {
276
- return ctx.reject({ expected: parsed.summary });
277
- }
278
- return true;
228
+ export function createSqlEntrySchemaRegistry(
229
+ packSchemas?: ReadonlyMap<string, Type<unknown>>,
230
+ ): ReadonlyMap<string, Type<unknown>> {
231
+ const registry = new Map<string, Type<unknown>>([
232
+ ['table', castAs<Type<unknown>>(StorageTableSchema)],
233
+ ['valueSet', castAs<Type<unknown>>(StorageValueSetSchema)],
234
+ ]);
235
+ if (packSchemas !== undefined) {
236
+ for (const [kind, schema] of packSchemas) {
237
+ if (registry.has(kind)) {
238
+ throw new Error(
239
+ `createSqlEntrySchemaRegistry: pack schema "${kind}" collides with a core kind — pack schemas cannot override "table" or "valueSet"`,
240
+ );
279
241
  }
242
+ registry.set(kind, schema);
280
243
  }
281
- const parsed = fallback(entry);
282
- if (parsed instanceof type.errors) {
283
- return ctx.reject({ expected: parsed.summary });
284
- }
285
- return true;
286
- });
244
+ }
245
+ return registry;
287
246
  }
288
247
 
289
248
  /**
290
249
  * Builds the per-namespace entry schema for `storage.namespaces[id]`.
291
- * Pack-contributed `validatorSchema` fragments — keyed by the
292
- * descriptor's `discriminator` validate each entry by matching the
293
- * entry's `kind` field on the `'entries.type'` slot.
250
+ *
251
+ * Validation is registry-driven: the `registry` parameter maps each
252
+ * entries key to an arktype schema that validates a single inner-map
253
+ * value for that kind. Compose the registry with
254
+ * {@link createSqlEntrySchemaRegistry} — SQL core's kinds and pack
255
+ * contributions live in the same map. An unregistered key fails
256
+ * validation naming the kind and the namespace id, so validation fails
257
+ * closed.
294
258
  */
295
259
  export function createNamespaceEntrySchema(
296
- fragments?: ReadonlyMap<string, Type<unknown>>,
260
+ registry: ReadonlyMap<string, Type<unknown>>,
297
261
  ): Type<unknown> {
298
262
  return type({
299
263
  '+': 'reject',
300
264
  id: 'string',
301
265
  'kind?': 'string',
302
- entries: type({
303
- '+': 'reject',
304
- 'table?': type({ '[string]': StorageTableSchema }),
305
- 'type?': type({
306
- '[string]': namespaceSlotEntrySchema(PostgresEnumTypeSchema, 'postgres-enum', fragments),
307
- }),
308
- 'valueSet?': type({ '[string]': StorageValueSetSchema }),
309
- }),
266
+ entries: 'object',
267
+ }).narrow((ns, ctx) => {
268
+ if (!isPlainRecord(ns.entries)) {
269
+ return ctx.mustBe('an entries object');
270
+ }
271
+ for (const [key, innerMap] of Object.entries(ns.entries)) {
272
+ const entrySchema = registry.get(key);
273
+ if (entrySchema === undefined) {
274
+ return ctx.reject({
275
+ expected: `entries key "${key}" in namespace "${ns.id}" is not a registered entity kind`,
276
+ });
277
+ }
278
+ if (!isPlainRecord(innerMap)) {
279
+ return ctx.reject({
280
+ expected: `entries["${key}"] in namespace "${ns.id}" must be an object`,
281
+ });
282
+ }
283
+ for (const [, value] of Object.entries(innerMap)) {
284
+ const parsed = entrySchema(value);
285
+ if (parsed instanceof type.errors) {
286
+ return ctx.reject({ expected: parsed.summary });
287
+ }
288
+ }
289
+ }
290
+ return true;
310
291
  }) as Type<unknown>;
311
292
  }
312
293
 
313
294
  /**
314
295
  * Builds the storage schema. Pack contributions reach the per-namespace
315
296
  * entry shape through {@link createNamespaceEntrySchema}; the
316
- * document-scoped `storage.types` slot (codec triples only) and the
297
+ * document-scoped `storage.types` field (codec triples only) and the
317
298
  * storage hash stay family-shared.
318
299
  */
319
300
  export function createSqlStorageSchema(
320
- fragments?: ReadonlyMap<string, Type<unknown>>,
301
+ registry: ReadonlyMap<string, Type<unknown>>,
321
302
  ): Type<unknown> {
322
- const namespaceEntry = createNamespaceEntrySchema(fragments);
303
+ const namespaceEntry = createNamespaceEntrySchema(registry);
323
304
  return type({
324
305
  '+': 'reject',
325
306
  storageHash: 'string',
@@ -333,24 +314,20 @@ export function createSqlStorageSchema(
333
314
  }) as Type<unknown>;
334
315
  }
335
316
 
336
- const StorageSchema = createSqlStorageSchema();
317
+ const StorageSchema = createSqlStorageSchema(createSqlEntrySchemaRegistry());
337
318
 
338
- // SQL-specific namespace walk shape (`entries.table` is the SQL family's
339
- // idiom). The wider `object` table value keeps this helper structurally
340
- // compatible with `SqlNamespace` and JSON envelope variants that lose class
341
- // identity.
342
319
  type NamespacedStorageWalk = {
343
320
  readonly namespaces: Readonly<
344
321
  Record<
345
322
  string,
346
- Namespace & { readonly entries: { readonly table: Readonly<Record<string, object>> } }
323
+ Namespace & { readonly entries: Readonly<Record<string, Readonly<Record<string, unknown>>>> }
347
324
  >
348
325
  >;
349
326
  };
350
327
 
351
328
  function eachStorageTable(storage: NamespacedStorageWalk) {
352
329
  return Object.entries(storage.namespaces).flatMap(([namespaceId, ns]) =>
353
- Object.entries(ns.entries.table).map(([tableName, table]) => ({
330
+ Object.entries(ns.entries['table'] ?? {}).map(([tableName, table]) => ({
354
331
  namespaceId,
355
332
  tableName,
356
333
  table,
@@ -359,7 +336,9 @@ function eachStorageTable(storage: NamespacedStorageWalk) {
359
336
  }
360
337
 
361
338
  function isPlainRecord(value: unknown): value is Record<string, unknown> {
362
- return typeof value === 'object' && value !== null && !Array.isArray(value);
339
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) return false;
340
+ const proto = Object.getPrototypeOf(value) as unknown;
341
+ return proto === Object.prototype || proto === null;
363
342
  }
364
343
 
365
344
  function findDuplicateValue(values: readonly string[]): string | undefined {
@@ -403,7 +382,7 @@ const ModelFieldSchema = type({
403
382
  type: ContractFieldTypeSchema,
404
383
  'many?': 'true',
405
384
  'dict?': 'true',
406
- 'valueSet?': ValueSetRefSchema,
385
+ 'valueSet?': DomainEnumRefSchema,
407
386
  });
408
387
 
409
388
  const ModelStorageFieldSchema = type({
@@ -480,9 +459,9 @@ const ContractMetaSchema = type({
480
459
  * of the contract envelope is family-shared.
481
460
  */
482
461
  export function createSqlContractSchema(
483
- fragments?: ReadonlyMap<string, Type<unknown>>,
462
+ registry: ReadonlyMap<string, Type<unknown>>,
484
463
  ): Type<unknown> {
485
- const storage = createSqlStorageSchema(fragments);
464
+ const storage = createSqlStorageSchema(registry);
486
465
  return type({
487
466
  '+': 'reject',
488
467
  target: 'string',
@@ -508,7 +487,7 @@ export function createSqlContractSchema(
508
487
  }) as Type<unknown>;
509
488
  }
510
489
 
511
- const SqlContractSchema = createSqlContractSchema();
490
+ const SqlContractSchema = createSqlContractSchema(createSqlEntrySchemaRegistry());
512
491
 
513
492
  // NOTE: StorageColumnSchema, StorageTableSchema, and StorageSchema use bare type()
514
493
  // instead of type.declare<T>().type() because the ColumnDefault union's value field
@@ -792,7 +771,8 @@ export function validateModelStorageReferences(contract: Contract<SqlStorage>):
792
771
  }
793
772
 
794
773
  const storageTable = model.storage.table;
795
- const rawTable = contract.storage.namespaces[storageNamespaceId]?.entries.table[storageTable];
774
+ const storageNs = contract.storage.namespaces[storageNamespaceId];
775
+ const rawTable = storageNs?.entries.table?.[storageTable];
796
776
  if (rawTable === undefined) {
797
777
  throw new ContractValidationError(
798
778
  `Model "${qualifiedName}" references non-existent table "${storageNamespaceId}.${storageTable}"`,
@@ -912,7 +892,7 @@ export function validateSqlStorageConsistency(contract: Contract<SqlStorage>): v
912
892
 
913
893
  if (fk.target.spaceId === undefined) {
914
894
  const targetNamespace = contract.storage.namespaces[fk.target.namespaceId];
915
- const referencedRaw = targetNamespace?.entries.table[fk.target.tableName];
895
+ const referencedRaw = targetNamespace?.entries.table?.[fk.target.tableName];
916
896
  if (referencedRaw === undefined) {
917
897
  throw new ContractValidationError(
918
898
  `Namespace "${namespaceId}" table "${tableName}" foreignKey references non-existent table "${fk.target.namespaceId}.${fk.target.tableName}"`,
@@ -1 +0,0 @@
1
- {"version":3,"file":"types-DEnWD3xB.d.mts","names":[],"sources":["../src/ir/build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KAEzC,qBAAA,OAA4B,CAAA,oBACpC,MAAA,kBACA,CAAA;EAAA,SAAqB,mBAAA;AAAA,IACnB,CAAA,SAAU,MAAA,oBACR,CAAA,GACA,MAAA,kBACF,MAAA;AAAA,KAEM,kBAAA;AAAA,KAEA,oBAAA,yBAA6C,SAAA,oBACxC,kBAAA,IAAsB,SAAA;AAAA,KAG3B,2BAAA,MAAiC,kBAAA,eAAiC,CAAA,GAC1E,WAAA,CAAY,CAAA,CAAE,kBAAA,SAA2B,CAAA;AAAA,KAGjC,kBAAA,OAAyB,CAAA,oBACjC,MAAA,kBACA,CAAA;EAAA,SAAqB,gBAAA;AAAA,IACnB,CAAA,SAAU,MAAA,SAAe,MAAA,qBACvB,CAAA,GACA,MAAA,kBACF,MAAA;AAAA,KAEM,iBAAA,OAAwB,CAAA,oBAChC,MAAA,kBACA,CAAA;EAAA,SAAqB,eAAA;AAAA,IACnB,CAAA,SAAU,MAAA,SAAe,MAAA,qBACvB,CAAA,GACA,MAAA,kBACF,MAAA;AAAA,KAEM,iBAAA,MAAuB,YAAA,CAAa,2BAAA,CAA4B,CAAA;AAAA,KAChE,0BAAA,MAAgC,qBAAA,CAAsB,2BAAA,CAA4B,CAAA;AAAA,KAClF,uBAAA,MAA6B,kBAAA,CAAmB,2BAAA,CAA4B,CAAA;AAAA,KAC5E,sBAAA,MAA4B,iBAAA,CAAkB,2BAAA,CAA4B,CAAA;AAAA,KAE1E,iBAAA,0BAA2C,SAAA,oBACnD,iBAAA,CAAkB,SAAA,IAClB,YAAA,CAAa,SAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"types-DqhaAjCH.mjs","names":[],"sources":["../src/ir/sql-unbound-namespace.ts","../src/ir/sql-node.ts","../src/ir/check-constraint.ts","../src/ir/foreign-key-reference.ts","../src/ir/foreign-key.ts","../src/ir/primary-key.ts","../src/ir/sql-index.ts","../src/ir/storage-column.ts","../src/ir/unique-constraint.ts","../src/ir/storage-table.ts","../src/ir/storage-value-set.ts","../src/ir/build-sql-namespace.ts","../src/ir/postgres-enum-storage-entry.ts","../src/ir/storage-type-instance.ts","../src/ir/sql-storage.ts","../src/types.ts"],"sourcesContent":["import {\n freezeNode,\n NamespaceBase,\n UNBOUND_NAMESPACE_ID,\n} from '@prisma-next/framework-components/ir';\nimport type { StorageTable } from './storage-table';\n\n/**\n * Family-layer placeholder for the SQL unbound-namespace singleton —\n * the late-bound slot whose binding the target resolves at connection\n * time rather than at authoring time.\n *\n * SQL contracts honour the framework `Storage.namespaces` invariant from\n * the moment they appear in the IR. Today `SqlStorage` is family-shared\n * (Postgres + SQLite consume the same class); a per-target namespace\n * concretion (`PostgresSchema.unbound`, `SqliteUnboundDatabase.instance`)\n * earns its existence when each target's namespace shape lands. Until\n * then the family ships a single placeholder singleton so the JSON\n * envelope and runtime walk are honest at every layer.\n *\n * The `kind` discriminator is installed as a non-enumerable own property\n * so the JSON envelope reads `{ \"id\": \"__unbound__\", \"entries\": { … } }`\n * — symmetric with the family-level non-enumerable `kind` on `SqlNode`\n * and bounded to the minimum data the framework `Namespace` interface\n * promises.\n *\n * **Freeze-trap warning.** The leaf constructor calls\n * `freezeNode(this)` after installing `kind`. The leaf-class shape\n * works today only because `NamespaceBase` does NOT freeze in its\n * constructor — the `Object.defineProperty(this, 'kind', …)` call after\n * `super()` succeeds because the instance is still mutable at that\n * point. Subclasses that add instance fields will still hit the freeze\n * trap once leaf-class `freezeNode(this)` runs; and if a future\n * framework change lifts the freeze to `NamespaceBase`, even the\n * `defineProperty` here would silently fail. To add subclass instance\n * fields safely, lift `freezeNode` to a leaf-class `seal()` hook each\n * leaf calls explicitly at the end of its own constructor.\n */\nexport class SqlUnboundNamespace extends NamespaceBase {\n static readonly instance: SqlUnboundNamespace = new SqlUnboundNamespace();\n\n readonly id = UNBOUND_NAMESPACE_ID;\n readonly entries: Readonly<{\n readonly table: Readonly<Record<string, StorageTable>>;\n }> = Object.freeze({ table: Object.freeze({}) });\n declare readonly kind: string;\n\n private constructor() {\n super();\n Object.defineProperty(this, 'kind', {\n value: 'sql-namespace',\n writable: false,\n enumerable: false,\n configurable: true,\n });\n freezeNode(this);\n }\n\n qualifyTable(tableName: string): string {\n return `\"${tableName}\"`;\n }\n}\n","import { IRNodeBase } from '@prisma-next/framework-components/ir';\n\n/**\n * SQL family IR node base. Carries the family-level `kind` discriminator\n * `'sql'` and inherits the framework's `freezeNode` affordance.\n *\n * Single family-level discriminator (not per-leaf) reflects the fact that\n * SQL IR has no polymorphic dispatch today — verifiers and serializers\n * walk by structural position (`storage.tables[name].columns[name]`),\n * not by inspecting `kind`. The abstract bar for per-leaf discriminators\n * isn't earned until a future polymorphic consumer arrives.\n *\n * `kind` is installed as a non-enumerable own property on every instance,\n * which keeps three things clean simultaneously:\n *\n * - `JSON.stringify(node)` produces the canonical pre-lift JSON envelope\n * shape (no `kind` field), so emitted contract.json files and the\n * `validateSqlContractFully` arktype schemas stay unchanged.\n * - Test assertions that use `toEqual({...})` against the pre-lift flat\n * shape continue to pass — only enumerable own properties are\n * compared.\n * - Direct access (`node.kind`) and runtime narrowing\n * (`if (node.kind === 'sql')`) still work, so future polymorphic\n * dispatch can begin reading `kind` without a runtime change.\n *\n * Future per-leaf overrides land cleanly: a class that gains a\n * polymorphic-dispatch consumer (e.g. an enum type instance walked\n * alongside other types) overrides `kind` with its narrower literal\n * at that leaf level. Per-leaf overrides will use enumerable kind\n * (matching the Mongo per-class-discriminator precedent) because they\n * encode dispatch-relevant information that callers need to see in\n * JSON envelopes; the family-level `'sql'` is uniform across all SQL\n * IR and carries no dispatch-relevant information.\n */\nexport abstract class SqlNode extends IRNodeBase {\n readonly kind?: string;\n\n constructor() {\n super();\n Object.defineProperty(this, 'kind', {\n value: 'sql',\n writable: false,\n enumerable: false,\n // configurable so per-leaf subclasses (e.g. PostgresEnumType in\n // target-postgres) can override `kind` with their narrower\n // enumerable literal via a class-field initializer. SqlNode\n // itself never needs to mutate the property again, so\n // configurability has no surface impact at this layer.\n configurable: true,\n });\n }\n}\n","import type { ValueSetRef } from '@prisma-next/contract/types';\nimport { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from './sql-node';\n\n/**\n * Hydration / construction input shape for {@link CheckConstraint}.\n * Mirrors the on-disk storage JSON envelope so the serializer hydration\n * walker can hand a validated literal straight to `new`.\n */\nexport interface CheckConstraintInput {\n readonly name: string;\n readonly column: string;\n readonly valueSet: ValueSetRef;\n}\n\n/**\n * SQL Contract IR node for a table-level check constraint that restricts\n * a column to the permitted values of a value-set.\n *\n * The constraint is **structured** (names a column and a value-set\n * reference), not a raw SQL expression. Each target renders its own DDL\n * from the structured form, keeping the contract target-agnostic.\n *\n * Construction is idempotent: passing an existing `CheckConstraint`\n * instance as input produces a new instance with identical fields.\n * The constructor does not use `instanceof` for input discrimination —\n * it reads plain named properties, which is sufficient since\n * `CheckConstraintInput` is a structural type.\n */\nexport class CheckConstraint extends SqlNode {\n readonly name: string;\n readonly column: string;\n readonly valueSet: ValueSetRef;\n\n constructor(input: CheckConstraintInput) {\n super();\n this.name = input.name;\n this.column = input.column;\n this.valueSet = input.valueSet;\n freezeNode(this);\n }\n}\n","import { asNamespaceId, type NamespaceId } from '@prisma-next/contract/types';\nimport { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from './sql-node';\n\n/**\n * Input for a foreign-key reference (one side of a foreign-key declaration).\n *\n * When `spaceId` is absent the reference is local — the referenced table lives\n * in the same contract-space. When `spaceId` is present the reference is\n * cross-space — the referenced table lives in a different contract-space\n * identified by `spaceId`.\n *\n * Presence-based discrimination keeps local FK JSON byte-identical to\n * contracts authored before cross-space support was added.\n */\nexport interface ForeignKeyReferenceInput {\n readonly namespaceId: string;\n readonly tableName: string;\n readonly columns: readonly string[];\n readonly spaceId?: string;\n}\n\n/**\n * SQL Contract IR node for one side (source or target) of a foreign-key\n * declaration. Carries the full coordinate: namespace, table, and columns.\n *\n * Cross-space discrimination is based on `spaceId` presence: absent means\n * local (same contract-space); present means cross-space (the referenced\n * table lives in the contract-space identified by `spaceId`).\n *\n * For local references `spaceId` is absent from JSON, keeping the serialized\n * shape byte-identical to contracts authored before cross-space support was\n * added. For cross-space references `spaceId` appears in JSON so round-trips\n * are lossless.\n *\n * Use `UNBOUND_NAMESPACE_ID` from `@prisma-next/framework-components/ir`\n * as the sentinel `namespaceId` for single-namespace (unbound) references.\n */\nexport class ForeignKeyReference extends SqlNode {\n readonly namespaceId: NamespaceId;\n readonly tableName: string;\n readonly columns: readonly string[];\n declare readonly spaceId?: string;\n\n constructor(input: ForeignKeyReferenceInput) {\n super();\n this.namespaceId = asNamespaceId(input.namespaceId);\n this.tableName = input.tableName;\n this.columns = input.columns;\n if (input.spaceId !== undefined) this.spaceId = input.spaceId;\n freezeNode(this);\n }\n}\n","import { freezeNode } from '@prisma-next/framework-components/ir';\nimport { ForeignKeyReference, type ForeignKeyReferenceInput } from './foreign-key-reference';\nimport { SqlNode } from './sql-node';\n\nexport type ReferentialAction = 'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault';\n\nexport interface ForeignKeyInput {\n readonly source: ForeignKeyReference | ForeignKeyReferenceInput;\n readonly target: ForeignKeyReference | ForeignKeyReferenceInput;\n readonly name?: string;\n readonly onDelete?: ReferentialAction;\n readonly onUpdate?: ReferentialAction;\n /** Whether to emit FK constraint DDL (ALTER TABLE … ADD CONSTRAINT … FOREIGN KEY). */\n readonly constraint: boolean;\n /** Whether to emit a backing index for the FK columns. */\n readonly index: boolean;\n}\n\n/**\n * SQL Contract IR node for a table-level foreign-key declaration.\n *\n * Each FK carries explicit `source` and `target` {@link ForeignKeyReference}\n * coordinates (namespace, table, columns). For single-namespace contracts the\n * sentinel `UNBOUND_NAMESPACE_ID` appears on both sides.\n *\n * The nested references are normalised to {@link ForeignKeyReference}\n * instances inside the constructor so downstream walks see a uniform AST\n * regardless of whether the input was a JSON literal or an already-constructed\n * class instance.\n */\nexport class ForeignKey extends SqlNode {\n readonly source: ForeignKeyReference;\n readonly target: ForeignKeyReference;\n readonly constraint: boolean;\n readonly index: boolean;\n declare readonly name?: string;\n declare readonly onDelete?: ReferentialAction;\n declare readonly onUpdate?: ReferentialAction;\n\n constructor(input: ForeignKeyInput) {\n super();\n this.source =\n input.source instanceof ForeignKeyReference\n ? input.source\n : new ForeignKeyReference(input.source);\n this.target =\n input.target instanceof ForeignKeyReference\n ? input.target\n : new ForeignKeyReference(input.target);\n this.constraint = input.constraint;\n this.index = input.index;\n if (input.name !== undefined) this.name = input.name;\n if (input.onDelete !== undefined) this.onDelete = input.onDelete;\n if (input.onUpdate !== undefined) this.onUpdate = input.onUpdate;\n freezeNode(this);\n }\n}\n","import { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from './sql-node';\n\nexport interface PrimaryKeyInput {\n readonly columns: readonly string[];\n readonly name?: string;\n}\n\n/**\n * SQL Contract IR node for a table's primary-key constraint.\n */\nexport class PrimaryKey extends SqlNode {\n readonly columns: readonly string[];\n declare readonly name?: string;\n\n constructor(input: PrimaryKeyInput) {\n super();\n this.columns = input.columns;\n if (input.name !== undefined) this.name = input.name;\n freezeNode(this);\n }\n}\n","import { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from './sql-node';\n\nexport interface IndexInput {\n readonly columns: readonly string[];\n readonly name?: string;\n readonly type?: string;\n readonly options?: Record<string, unknown>;\n}\n\n/**\n * SQL Contract IR node for a table-level secondary index.\n *\n * Note that this class shadows the global TypeScript `Index` lib type\n * at the family-shared name; consumer files that need both should\n * alias one (e.g.\n * `import { Index as SqlIndexNode } from '@prisma-next/sql-contract/types'`).\n */\nexport class Index extends SqlNode {\n readonly columns: readonly string[];\n declare readonly name?: string;\n declare readonly type?: string;\n declare readonly options?: Record<string, unknown>;\n\n constructor(input: IndexInput) {\n super();\n this.columns = input.columns;\n if (input.name !== undefined) this.name = input.name;\n if (input.type !== undefined) this.type = input.type;\n if (input.options !== undefined) this.options = input.options;\n freezeNode(this);\n }\n}\n","import type { ColumnDefault, ControlPolicy, ValueSetRef } from '@prisma-next/contract/types';\nimport { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from './sql-node';\n\n/**\n * Hydration / construction input shape for {@link StorageColumn}. Mirrors\n * the on-disk storage JSON envelope exactly so the family-base\n * serializer's hydration walker can hand an arktype-validated literal\n * straight to `new`.\n *\n * `typeParams` and `typeRef` remain mutually exclusive (one or the\n * other, not both); the constructor preserves whichever caller-side\n * choice the input encodes.\n */\nexport interface StorageColumnInput {\n readonly nativeType: string;\n readonly codecId: string;\n readonly nullable: boolean;\n readonly typeParams?: Record<string, unknown>;\n readonly typeRef?: string;\n readonly default?: ColumnDefault;\n readonly control?: ControlPolicy;\n readonly valueSet?: ValueSetRef;\n}\n\n/**\n * SQL Contract IR node for a single column entry in `StorageTable.columns`.\n *\n * Single concrete family-shared class — every SQL target reads the\n * same column shape today, so there is no per-target subclass. The\n * class type accepts any caller that constructs via\n * `new StorageColumn(input)`; literal construction sites must pass\n * through the constructor or the family-base hydration walker.\n *\n * The column's `name` is not on the class — columns are keyed by name\n * in the parent `StorageTable.columns: Record<string, StorageColumn>`\n * map, so a `name` field would be redundant with the key.\n */\nexport class StorageColumn extends SqlNode {\n readonly nativeType: string;\n readonly codecId: string;\n readonly nullable: boolean;\n declare readonly typeParams?: Record<string, unknown>;\n declare readonly typeRef?: string;\n declare readonly default?: ColumnDefault;\n declare readonly control?: ControlPolicy;\n declare readonly valueSet?: ValueSetRef;\n\n constructor(input: StorageColumnInput) {\n super();\n this.nativeType = input.nativeType;\n this.codecId = input.codecId;\n this.nullable = input.nullable;\n if (input.typeParams !== undefined) this.typeParams = input.typeParams;\n if (input.typeRef !== undefined) this.typeRef = input.typeRef;\n if (input.default !== undefined) this.default = input.default;\n if (input.control !== undefined) this.control = input.control;\n if (input.valueSet !== undefined) this.valueSet = input.valueSet;\n freezeNode(this);\n }\n}\n","import { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from './sql-node';\n\nexport interface UniqueConstraintInput {\n readonly columns: readonly string[];\n readonly name?: string;\n}\n\n/**\n * SQL Contract IR node for a table-level unique constraint.\n */\nexport class UniqueConstraint extends SqlNode {\n readonly columns: readonly string[];\n declare readonly name?: string;\n\n constructor(input: UniqueConstraintInput) {\n super();\n this.columns = input.columns;\n if (input.name !== undefined) this.name = input.name;\n freezeNode(this);\n }\n}\n","import type { ControlPolicy } from '@prisma-next/contract/types';\nimport { freezeNode } from '@prisma-next/framework-components/ir';\nimport { CheckConstraint, type CheckConstraintInput } from './check-constraint';\nimport { ForeignKey, type ForeignKeyInput } from './foreign-key';\nimport { PrimaryKey, type PrimaryKeyInput } from './primary-key';\nimport { Index, type IndexInput } from './sql-index';\nimport { SqlNode } from './sql-node';\nimport { StorageColumn, type StorageColumnInput } from './storage-column';\nimport { UniqueConstraint, type UniqueConstraintInput } from './unique-constraint';\n\nexport interface StorageTableInput {\n readonly columns: Record<string, StorageColumn | StorageColumnInput>;\n readonly primaryKey?: PrimaryKey | PrimaryKeyInput;\n readonly uniques: ReadonlyArray<UniqueConstraint | UniqueConstraintInput>;\n readonly indexes: ReadonlyArray<Index | IndexInput>;\n readonly foreignKeys: ReadonlyArray<ForeignKey | ForeignKeyInput>;\n readonly control?: ControlPolicy;\n readonly checks?: ReadonlyArray<CheckConstraint | CheckConstraintInput>;\n}\n\n/**\n * SQL Contract IR node for a single table entry in a namespace's\n * `tables` map.\n *\n * The constructor normalises nested IR-class fields (columns, primary\n * key, uniques, indexes, foreign keys) into the appropriate class\n * instances so downstream walks see a uniform AST regardless of whether\n * the input was a JSON literal or an already-constructed class.\n *\n * The table's `name` is not on the class — tables are keyed by name in\n * the parent namespace's `tables: Record<string, StorageTable>` map.\n */\nexport class StorageTable extends SqlNode {\n readonly columns: Readonly<Record<string, StorageColumn>>;\n readonly uniques: ReadonlyArray<UniqueConstraint>;\n readonly indexes: ReadonlyArray<Index>;\n readonly foreignKeys: ReadonlyArray<ForeignKey>;\n declare readonly primaryKey?: PrimaryKey;\n declare readonly control?: ControlPolicy;\n declare readonly checks?: ReadonlyArray<CheckConstraint>;\n\n constructor(input: StorageTableInput) {\n super();\n this.columns = Object.freeze(\n Object.fromEntries(\n Object.entries(input.columns).map(([name, col]) => [\n name,\n col instanceof StorageColumn ? col : new StorageColumn(col),\n ]),\n ),\n );\n if (input.primaryKey !== undefined) {\n this.primaryKey =\n input.primaryKey instanceof PrimaryKey\n ? input.primaryKey\n : new PrimaryKey(input.primaryKey);\n }\n this.uniques = Object.freeze(\n input.uniques.map((u) => (u instanceof UniqueConstraint ? u : new UniqueConstraint(u))),\n );\n this.indexes = Object.freeze(input.indexes.map((i) => (i instanceof Index ? i : new Index(i))));\n this.foreignKeys = Object.freeze(\n input.foreignKeys.map((fk) => (fk instanceof ForeignKey ? fk : new ForeignKey(fk))),\n );\n if (input.control !== undefined) this.control = input.control;\n if (input.checks !== undefined && input.checks.length > 0) {\n this.checks = Object.freeze(input.checks.map((cc) => new CheckConstraint(cc)));\n }\n freezeNode(this);\n }\n}\n","import { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from './sql-node';\n\n/**\n * Hydration / construction input shape for {@link StorageValueSet}.\n * Mirrors the on-disk storage JSON envelope so the serializer hydration\n * walker can hand a validated literal straight to `new`.\n */\nexport interface StorageValueSetInput {\n readonly kind: 'value-set';\n /** Ordered permitted values, codec-encoded. Declaration order is preserved. */\n readonly values: readonly string[];\n}\n\n/**\n * SQL Contract IR node for a value-set entry in a namespace's `valueSet`\n * map (`SqlNamespace.entries.valueSet`).\n *\n * A value-set records the ordered set of permitted codec-encoded values for\n * an enum-like column restriction. It does not carry a `codecId` — the\n * column that references it already holds the codec; the value-set holds\n * only the permitted values.\n *\n * The node's `kind` is enumerable (`'value-set'`) so the JSON envelope\n * carries the discriminator and the serializer hydration walker can\n * dispatch on it. This follows the per-leaf enumerable-kind convention\n * established in the SQL-node comment (future polymorphic dispatch on\n * namespace entries needs the discriminator in JSON).\n *\n * The entry's name is not on the class — value-sets are keyed by name in\n * the parent namespace's `valueSet: Record<string, StorageValueSet>` map.\n */\nexport class StorageValueSet extends SqlNode {\n override readonly kind = 'value-set' as const;\n readonly values: readonly string[];\n\n constructor(input: StorageValueSetInput) {\n super();\n this.values = Object.freeze([...input.values]);\n freezeNode(this);\n }\n}\n","import {\n freezeNode,\n type Namespace,\n NamespaceBase,\n UNBOUND_NAMESPACE_ID,\n} from '@prisma-next/framework-components/ir';\nimport { blindCast, castAs } from '@prisma-next/utils/casts';\nimport type { SqlNamespace, SqlNamespaceTablesInput } from './sql-storage';\nimport { SqlUnboundNamespace } from './sql-unbound-namespace';\nimport { StorageTable } from './storage-table';\nimport { StorageValueSet } from './storage-value-set';\n\nconst SQL_NAMESPACE_KIND = 'sql-namespace' as const;\n\nfunction isMaterializedSqlNamespace(ns: Namespace | SqlNamespaceTablesInput): ns is SqlNamespace {\n if (typeof ns !== 'object' || ns === null) {\n return false;\n }\n const proto = Object.getPrototypeOf(ns);\n if (proto === Object.prototype || proto === null) {\n return false;\n }\n return (ns as Namespace).kind === SQL_NAMESPACE_KIND;\n}\n\nclass SqlBoundNamespace extends NamespaceBase {\n declare readonly kind: string;\n\n readonly id: string;\n readonly entries: Readonly<{\n readonly table: Readonly<Record<string, StorageTable>>;\n readonly valueSet?: Readonly<Record<string, StorageValueSet>>;\n }>;\n\n static fromTablesInput(input: SqlNamespaceTablesInput): SqlNamespace {\n const tableCount = Object.keys(input.entries.table).length;\n const hasValueSets =\n input.entries.valueSet !== undefined && Object.keys(input.entries.valueSet).length > 0;\n if (input.id === UNBOUND_NAMESPACE_ID && tableCount === 0 && !hasValueSets) {\n return castAs<SqlNamespace>(SqlUnboundNamespace.instance);\n }\n return castAs<SqlNamespace>(new SqlBoundNamespace(input));\n }\n\n private constructor(input: SqlNamespaceTablesInput) {\n super();\n this.id = input.id;\n const table = Object.freeze(\n Object.fromEntries(\n Object.entries(input.entries.table).map(([k, v]) => [k, new StorageTable(v)]),\n ),\n );\n if (input.entries.valueSet !== undefined) {\n const valueSet = Object.freeze(\n Object.fromEntries(\n Object.entries(input.entries.valueSet).map(([k, v]) => [k, new StorageValueSet(v)]),\n ),\n );\n this.entries = Object.freeze({ table, valueSet });\n } else {\n this.entries = Object.freeze({ table });\n }\n Object.defineProperty(this, 'kind', {\n value: SQL_NAMESPACE_KIND,\n writable: false,\n enumerable: false,\n configurable: true,\n });\n freezeNode(this);\n }\n\n qualifyTable(tableName: string): string {\n if (this.id === UNBOUND_NAMESPACE_ID) {\n return `\"${tableName}\"`;\n }\n return `\"${this.id}\".\"${tableName}\"`;\n }\n}\n\nexport function buildSqlNamespace(input: SqlNamespaceTablesInput): SqlNamespace {\n return SqlBoundNamespace.fromTablesInput(input);\n}\n\nexport function buildSqlNamespaceMap(\n namespaces: Readonly<Record<string, Namespace | SqlNamespaceTablesInput>>,\n): Readonly<Record<string, SqlNamespace>> {\n return Object.fromEntries(\n Object.entries(namespaces).map(([nsKey, ns]) => [\n nsKey,\n isMaterializedSqlNamespace(ns)\n ? blindCast<\n SqlNamespace,\n 'a materialised SQL-family namespace entry in a namespace map is a SqlNamespace'\n >(ns)\n : SqlBoundNamespace.fromTablesInput(\n blindCast<\n SqlNamespaceTablesInput,\n 'non-materialized SQL namespace map entry is a SqlNamespaceTablesInput'\n >(ns),\n ),\n ]),\n );\n}\n","import type { ControlPolicy } from '@prisma-next/contract/types';\nimport type { StorageType } from '@prisma-next/framework-components/ir';\n\n/**\n * Discriminator literal for the Postgres-enum variant on the polymorphic\n * `SqlStorage.types` slot.\n *\n * Enums are a target-level concept: Postgres ships native\n * `CREATE TYPE … AS ENUM` while other SQL targets approximate enums via\n * constraints. The literal lives at the SQL family layer because every\n * SQL-family consumer (verifier, planner, lowering, …) needs to\n * discriminate enum-typed slot entries from codec-typed ones. The\n * concrete IR class (`PostgresEnumType`) lives in the target-postgres\n * package and implements this structural contract; cross-domain\n * layering rules forbid the SQL family from importing the concrete\n * target class directly, so the discriminator and structural interface\n * carry the dispatch.\n */\nexport const POSTGRES_ENUM_KIND = 'postgres-enum' as const;\n\n/**\n * Structural contract every Postgres-enum slot entry honours — both\n * the live `PostgresEnumType` IR-class instance and the raw JSON\n * envelope shape that survives `JSON.stringify` round-trips. SQL\n * family-layer dispatch narrows polymorphic `StorageType` slot\n * entries to this shape via `isPostgresEnumStorageEntry`.\n *\n * The `codecBinding` field is accessor-shaped (live class instance) on\n * the IR class and undefined on the raw JSON envelope; consumers that\n * need it must guard for its presence (the JSON path synthesises an\n * equivalent shape from `codecId` + `values`).\n */\nexport interface PostgresEnumStorageEntry extends StorageType {\n readonly kind: typeof POSTGRES_ENUM_KIND;\n readonly name: string;\n readonly nativeType: string;\n readonly values: readonly string[];\n /**\n * Enumerable own property on the persisted JSON envelope; the live\n * IR-class instance carries it too. Family-shared dispatch sites\n * read `codecId` directly rather than going through the IR-class\n * `codecBinding` accessor (which lives on the prototype and isn't\n * present on raw JSON envelopes).\n */\n readonly codecId: string;\n readonly control?: ControlPolicy;\n}\n\n/**\n * Narrow a polymorphic `StorageType` entry to the Postgres-enum shape\n * via its enumerable `kind` discriminator. Type guard returns true for\n * both live `PostgresEnumType` instances and raw JSON envelopes.\n */\nexport function isPostgresEnumStorageEntry(value: unknown): value is PostgresEnumStorageEntry {\n if (typeof value !== 'object' || value === null) return false;\n return (value as { kind?: unknown }).kind === POSTGRES_ENUM_KIND;\n}\n","import type { StorageType } from '@prisma-next/framework-components/ir';\n\n/**\n * Sentinel kind for the legacy codec-triple shape persisted under\n * `SqlStorage.types`. Plain JSON-clean object literals carry this\n * discriminator so the polymorphic slot dispatch can route them down\n * the codec path while target-specific IR class instances (e.g. the\n * Postgres enum class) keep their own narrower `kind` literal.\n */\nexport const CODEC_INSTANCE_KIND = 'codec-instance' as const;\n\n/**\n * Structural sub-interface of {@link StorageType} for codec-typed entries\n * in `SqlStorage.types`. These are plain object literals — there is no\n * runtime IR class, the JSON envelope round-trips through the slot\n * unchanged. The `kind: 'codec-instance'` discriminator is the dispatch\n * key that distinguishes codec-typed entries from class-instance entries\n * (e.g. `PostgresEnumType`) sharing the polymorphic slot.\n */\nexport interface StorageTypeInstance extends StorageType {\n readonly kind: typeof CODEC_INSTANCE_KIND;\n readonly codecId: string;\n readonly nativeType: string;\n readonly typeParams: Record<string, unknown>;\n}\n\n/**\n * Construction-time input for a codec-triple entry. Symmetric with the\n * structural runtime shape minus the `kind` discriminator — callers may\n * omit `kind`; the helper {@link toStorageTypeInstance} stamps it on.\n * `typeParams` may be omitted on input; the constructor normalises a\n * missing value to `{}` so the in-memory shape is always present.\n */\nexport interface StorageTypeInstanceInput {\n readonly codecId: string;\n readonly nativeType: string;\n readonly typeParams?: Record<string, unknown>;\n}\n\n/**\n * Stamp the codec-instance `kind` discriminator on a caller-supplied\n * codec triple. Idempotent: input that already carries the discriminator\n * passes through unchanged. Missing `typeParams` is normalised to `{}`.\n */\nexport function toStorageTypeInstance(input: StorageTypeInstanceInput): StorageTypeInstance {\n return {\n kind: CODEC_INSTANCE_KIND,\n codecId: input.codecId,\n nativeType: input.nativeType,\n typeParams: input.typeParams ?? {},\n };\n}\n\n/**\n * Type-guard for codec-typed entries on the polymorphic\n * `SqlStorage.types` slot. Distinguishes `StorageTypeInstance` from\n * class-instance kinds (e.g. `PostgresEnumType`).\n */\nexport function isStorageTypeInstance(value: unknown): value is StorageTypeInstance {\n if (typeof value !== 'object' || value === null) return false;\n return (value as { kind?: unknown }).kind === CODEC_INSTANCE_KIND;\n}\n","import type { StorageHashBase } from '@prisma-next/contract/types';\nimport { freezeNode, type Namespace, type Storage } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from './sql-node';\nimport type { StorageTable, StorageTableInput } from './storage-table';\nimport {\n isStorageTypeInstance,\n type StorageTypeInstance,\n type StorageTypeInstanceInput,\n toStorageTypeInstance,\n} from './storage-type-instance';\nimport type { StorageValueSet, StorageValueSetInput } from './storage-value-set';\n\n/**\n * Polymorphic value type for document-scoped `SqlStorage.types` entries\n * (codec aliases / parameterised native type registrations).\n *\n * Postgres native enum registrations live under the postgres-specific\n * `entries.type` slot on `PostgresSchema` (target layer), not here.\n */\nexport type SqlStorageTypeEntry = StorageTypeInstance | StorageTypeInstanceInput;\n\nexport interface SqlNamespaceTablesInput {\n readonly id: string;\n readonly entries: {\n readonly table: Record<string, StorageTable | StorageTableInput>;\n readonly valueSet?: Record<string, StorageValueSet | StorageValueSetInput>;\n };\n}\n\nexport interface SqlStorageInput<THash extends string = string> {\n readonly storageHash: StorageHashBase<THash>;\n readonly types?: Record<string, SqlStorageTypeEntry>;\n readonly namespaces: Readonly<Record<string, SqlNamespace>>;\n}\n\n/**\n * SQL Contract IR root node for the `storage` field.\n *\n * Single concrete family-shared class — both Postgres and SQLite\n * consume this class today. Per-target storage subclasses are\n * introduced when each target's namespace shape earns its\n * target-specific concretion (target-specific derived fields,\n * target-specific storage extensions).\n *\n * Honours the framework `Storage` interface: every SQL IR carries a\n * `namespaces` map keyed by namespace id. Callers must supply fully\n * constructed `Namespace` instances — construction discipline lives\n * in the authoring builders and deserializer hydration paths.\n *\n * The constructor normalises optional `types` into class instances.\n * `types` is polymorphic per Decision 18 Option B: codec-triple inputs\n * are stamped with `kind: 'codec-instance'`; hydration of raw JSON\n * class-instance entries (carrying their narrower `kind` literal) is\n * the per-target serializer's responsibility (so the family base does\n * not import target-specific subclasses).\n */\n// SQL concretions store `StorageTable` values under `entries.table`.\n// Mongo namespaces carry `entries.collection` instead. The wider\n// `Record<string, object>` on `StorageTable` is only there so emitted\n// `contract.d.ts` table literals (which lack the runtime `kind`\n// discriminator on `StorageTable`) structurally satisfy the slot without\n// a class-instance check.\nexport type SqlNamespace = Namespace & {\n readonly entries: Readonly<{\n readonly table: Readonly<Record<string, StorageTable>>;\n readonly valueSet?: Readonly<Record<string, StorageValueSet>>;\n }>;\n /**\n * Render a dialect-qualified table reference for runtime SQL emission.\n * Present on materialised target concretions (`PostgresSchema`,\n * `SqliteDatabase`, …) and family placeholders; omitted on emitted\n * contract structural namespace literals (methods are not serialised).\n */\n qualifyTable?(tableName: string): string;\n};\n\nexport class SqlStorage<THash extends string = string> extends SqlNode implements Storage {\n readonly storageHash: StorageHashBase<THash>;\n readonly namespaces: Readonly<Record<string, SqlNamespace>>;\n declare readonly types?: Readonly<Record<string, StorageTypeInstance>>;\n\n constructor(input: SqlStorageInput<THash>) {\n super();\n this.storageHash = input.storageHash;\n this.namespaces = Object.freeze(input.namespaces);\n if (input.types !== undefined) {\n this.types = Object.freeze(\n Object.fromEntries(\n Object.entries(input.types).map(([name, ti]) => [name, normaliseTypeEntry(name, ti)]),\n ),\n );\n }\n freezeNode(this);\n }\n}\n\nexport function storageTableAt(\n storage: SqlStorage,\n namespaceId: string,\n tableName: string,\n): StorageTable | undefined {\n return storage.namespaces[namespaceId]?.entries.table[tableName];\n}\n\n/**\n * Strict polymorphic-slot dispatch for `SqlStorage.types` entries.\n * Every entry must carry a `kind: 'codec-instance'` discriminator or\n * be an already-constructed `StorageTypeInstance`. Untagged or\n * unrecognised inputs throw a diagnostic naming the entry and its\n * `kind`, so format drift surfaces loudly at the deserializer\n * boundary instead of slipping past the seam and corrupting\n * downstream IR walks.\n *\n * Codec-triple authors that have an untagged shape on hand can call\n * `toStorageTypeInstance(...)` (which stamps the `'codec-instance'`\n * discriminator) before constructing `SqlStorage`. On-disk reads\n * cross `familyInstance.deserializeContract` first; the structural\n * arktype schema rejects untagged entries earlier, so this throw\n * only fires for in-memory authoring bugs.\n */\nfunction normaliseTypeEntry(name: string, entry: SqlStorageTypeEntry): StorageTypeInstance {\n if (isStorageTypeInstance(entry)) {\n // Normalise on-disk objects that omit `typeParams` (the canonical on-disk\n // form strips empty typeParams to keep JSON compact). The in-memory invariant\n // is always `typeParams: {}` when empty — never `undefined`. Only create a\n // new object when necessary to preserve identity-equality for callers that\n // hold a reference to an already-correct in-memory entry.\n if ('typeParams' in entry) {\n return entry;\n }\n return toStorageTypeInstance(entry);\n }\n const rawKind = (entry as { kind?: unknown }).kind;\n const kindDescription =\n rawKind === undefined\n ? 'missing `kind` discriminator'\n : `unrecognised \\`kind\\` discriminator ${JSON.stringify(rawKind)}`;\n throw new Error(\n `storage.types[${JSON.stringify(name)}] has ${kindDescription}; expected ${JSON.stringify('codec-instance')}. Untagged codec triples should be wrapped with toStorageTypeInstance(...) before construction.`,\n );\n}\n","import type { CodecTrait } from '@prisma-next/framework-components/codec';\nimport type { ControlDriverInstance } from '@prisma-next/framework-components/control';\nimport type { ReferentialAction } from './ir/foreign-key';\n\nexport interface SqlControlDriverInstance<T extends string = string>\n extends ControlDriverInstance<'sql', T> {\n query<Row = Record<string, unknown>>(\n sql: string,\n params?: readonly unknown[],\n ): Promise<{ readonly rows: Row[] }>;\n}\n\nexport { buildSqlNamespace, buildSqlNamespaceMap } from './ir/build-sql-namespace';\nexport { CheckConstraint, type CheckConstraintInput } from './ir/check-constraint';\nexport {\n ForeignKey,\n type ForeignKeyInput,\n type ReferentialAction,\n} from './ir/foreign-key';\nexport {\n ForeignKeyReference,\n type ForeignKeyReferenceInput,\n} from './ir/foreign-key-reference';\nexport {\n isPostgresEnumStorageEntry,\n POSTGRES_ENUM_KIND,\n type PostgresEnumStorageEntry,\n} from './ir/postgres-enum-storage-entry';\nexport { PrimaryKey, type PrimaryKeyInput } from './ir/primary-key';\nexport { Index, type IndexInput } from './ir/sql-index';\nexport { SqlNode } from './ir/sql-node';\nexport {\n type SqlNamespaceTablesInput,\n SqlStorage,\n type SqlStorageInput,\n type SqlStorageTypeEntry,\n storageTableAt,\n} from './ir/sql-storage';\nexport { SqlUnboundNamespace } from './ir/sql-unbound-namespace';\nexport { StorageColumn, type StorageColumnInput } from './ir/storage-column';\nexport { StorageTable, type StorageTableInput } from './ir/storage-table';\nexport {\n CODEC_INSTANCE_KIND,\n isStorageTypeInstance,\n type StorageTypeInstance,\n type StorageTypeInstanceInput,\n toStorageTypeInstance,\n} from './ir/storage-type-instance';\nexport { StorageValueSet, type StorageValueSetInput } from './ir/storage-value-set';\nexport {\n UniqueConstraint,\n type UniqueConstraintInput,\n} from './ir/unique-constraint';\n\nexport type ForeignKeyOptions = {\n readonly name?: string;\n readonly onDelete?: ReferentialAction;\n readonly onUpdate?: ReferentialAction;\n};\n\nexport type SqlModelFieldStorage = {\n readonly column: string;\n readonly codecId?: string;\n readonly nullable?: boolean;\n};\n\nexport type SqlModelStorage = {\n readonly table: string;\n readonly namespaceId: string;\n readonly fields: Record<string, SqlModelFieldStorage>;\n};\n\nexport const DEFAULT_FK_CONSTRAINT = true;\nexport const DEFAULT_FK_INDEX = true;\n\nexport function applyFkDefaults(\n fk: { constraint?: boolean | undefined; index?: boolean | undefined },\n overrideDefaults?: { constraint?: boolean | undefined; index?: boolean | undefined },\n): { constraint: boolean; index: boolean } {\n return {\n constraint: fk.constraint ?? overrideDefaults?.constraint ?? DEFAULT_FK_CONSTRAINT,\n index: fk.index ?? overrideDefaults?.index ?? DEFAULT_FK_INDEX,\n };\n}\n\nexport type TypeMaps<\n TCodecTypes extends Record<string, { output: unknown }> = Record<string, never>,\n TQueryOperationTypes extends Record<string, unknown> = Record<string, never>,\n TFieldOutputTypes extends Record<string, Record<string, unknown>> = Record<string, never>,\n TFieldInputTypes extends Record<string, Record<string, unknown>> = Record<string, never>,\n> = {\n readonly codecTypes: TCodecTypes;\n readonly queryOperationTypes: TQueryOperationTypes;\n readonly fieldOutputTypes: TFieldOutputTypes;\n readonly fieldInputTypes: TFieldInputTypes;\n};\n\nexport type CodecTypesOf<T> = [T] extends [never]\n ? Record<string, never>\n : T extends { readonly codecTypes: infer C }\n ? C extends Record<string, { output: unknown }>\n ? C\n : Record<string, never>\n : Record<string, never>;\n\n/**\n * Dispatch hint identifying the first-argument target of an operation.\n *\n * Used by ORM column helpers to decide whether an operation is reachable on a\n * field. Either names a concrete codec identity or a set of capability traits\n * that the field's codec must carry.\n */\nexport type QueryOperationSelfSpec =\n | { readonly codecId: string; readonly traits?: never }\n | { readonly traits: readonly CodecTrait[]; readonly codecId?: never };\n\n/**\n * Structural shape an operation's impl must return: any value carrying a\n * codec-exact `returnType` descriptor. `Expression<T>` (from\n * `@prisma-next/sql-relational-core/expression`, with `T extends ScopeField`)\n * extends this. Trait-targeted returns are deliberately excluded — predicate\n * detection and result decoding both depend on knowing the concrete return\n * codec.\n */\nexport type QueryOperationReturn = {\n readonly returnType: { readonly codecId: string; readonly nullable: boolean };\n};\n\nexport type QueryOperationTypeEntry = {\n readonly self?: QueryOperationSelfSpec;\n readonly impl: (...args: never[]) => QueryOperationReturn;\n};\n\nexport type SqlQueryOperationTypes<\n _CT extends Record<string, { readonly input: unknown; readonly output: unknown }>,\n T extends Record<string, QueryOperationTypeEntry>,\n> = T;\n\nexport type QueryOperationTypesBase = Record<string, QueryOperationTypeEntry>;\n\nexport type QueryOperationTypesOf<T> = [T] extends [never]\n ? Record<string, never>\n : T extends { readonly queryOperationTypes: infer Q }\n ? Q extends Record<string, unknown>\n ? Q\n : Record<string, never>\n : Record<string, never>;\n\nexport type TypeMapsPhantomKey = '__@prisma-next/sql-contract/typeMaps@__';\n\nexport type ContractWithTypeMaps<TContract, TTypeMaps> = TContract & {\n readonly [K in TypeMapsPhantomKey]?: TTypeMaps;\n};\n\nexport type ExtractTypeMapsFromContract<T> = TypeMapsPhantomKey extends keyof T\n ? NonNullable<T[TypeMapsPhantomKey & keyof T]>\n : never;\n\nexport type FieldOutputTypesOf<T> = [T] extends [never]\n ? Record<string, never>\n : T extends { readonly fieldOutputTypes: infer F }\n ? F extends Record<string, Record<string, unknown>>\n ? F\n : Record<string, never>\n : Record<string, never>;\n\nexport type FieldInputTypesOf<T> = [T] extends [never]\n ? Record<string, never>\n : T extends { readonly fieldInputTypes: infer F }\n ? F extends Record<string, Record<string, unknown>>\n ? F\n : Record<string, never>\n : Record<string, never>;\n\nexport type ExtractCodecTypes<T> = CodecTypesOf<ExtractTypeMapsFromContract<T>>;\nexport type ExtractQueryOperationTypes<T> = QueryOperationTypesOf<ExtractTypeMapsFromContract<T>>;\nexport type ExtractFieldOutputTypes<T> = FieldOutputTypesOf<ExtractTypeMapsFromContract<T>>;\nexport type ExtractFieldInputTypes<T> = FieldInputTypesOf<ExtractTypeMapsFromContract<T>>;\n\nexport type ResolveCodecTypes<TContract, TTypeMaps> = [TTypeMaps] extends [never]\n ? ExtractCodecTypes<TContract>\n : CodecTypesOf<TTypeMaps>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,IAAa,sBAAb,MAAa,4BAA4B,cAAc;CACrD,OAAgB,WAAgC,IAAI,oBAAoB;CAExE,KAAc;CACd,UAEK,OAAO,OAAO,EAAE,OAAO,OAAO,OAAO,CAAC,CAAC,EAAE,CAAC;CAG/C,cAAsB;EACpB,MAAM;EACN,OAAO,eAAe,MAAM,QAAQ;GAClC,OAAO;GACP,UAAU;GACV,YAAY;GACZ,cAAc;EAChB,CAAC;EACD,WAAW,IAAI;CACjB;CAEA,aAAa,WAA2B;EACtC,OAAO,IAAI,UAAU;CACvB;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC3BA,IAAsB,UAAtB,cAAsC,WAAW;CAC/C;CAEA,cAAc;EACZ,MAAM;EACN,OAAO,eAAe,MAAM,QAAQ;GAClC,OAAO;GACP,UAAU;GACV,YAAY;GAMZ,cAAc;EAChB,CAAC;CACH;AACF;;;;;;;;;;;;;;;;;ACtBA,IAAa,kBAAb,cAAqC,QAAQ;CAC3C;CACA;CACA;CAEA,YAAY,OAA6B;EACvC,MAAM;EACN,KAAK,OAAO,MAAM;EAClB,KAAK,SAAS,MAAM;EACpB,KAAK,WAAW,MAAM;EACtB,WAAW,IAAI;CACjB;AACF;;;;;;;;;;;;;;;;;;;ACHA,IAAa,sBAAb,cAAyC,QAAQ;CAC/C;CACA;CACA;CAGA,YAAY,OAAiC;EAC3C,MAAM;EACN,KAAK,cAAc,cAAc,MAAM,WAAW;EAClD,KAAK,YAAY,MAAM;EACvB,KAAK,UAAU,MAAM;EACrB,IAAI,MAAM,YAAY,KAAA,GAAW,KAAK,UAAU,MAAM;EACtD,W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ACzC,MAAM;EACN,KAAK,cAAc,MAAM;EACzB,KAAK,aAAa,OAAO,OAAO,MAAM,UAAU;EAChD,IAAI,MAAM,UAAU,KAAA,GAClB,KAAK,QAAQ,OAAO,OAClB,OAAO,YACL,OAAO,QAAQ,MAAM,KAAK,CAAC,CAAC,KAAK,CAAC,MAAM,QAAQ,CAAC,MAAM,mBAAmB,MAAM,EAAE,CAAC,CAAC,CACtF,CACF;EAEF,WAAW,IAAI;CACjB;AACF;AAEA,SAAgB,eACd,SACA,aACA,WAC0B;CAC1B,OAAO,QAAQ,WAAW,YAAY,EAAE,QAAQ,MAAM;AACxD;;;;;;;;;;;;;;;;;AAkBA,SAAS,mBAAmB,MAAc,OAAiD;CACzF,IAAI,sBAAsB,KAAK,GAAG;EAMhC,IAAI,gBAAgB,OAClB,OAAO;EAET,OAAO,sBAAsB,KAAK;CACpC;CACA,MAAM,UAAW,MAA6B;CAC9C,MAAM,kBACJ,YAAY,KAAA,IACR,iCACA,uCAAuC,KAAK,UAAU,OAAO;CACnE,MAAM,IAAI,MACR,iBAAiB,KAAK,UAAU,IAAI,EAAE,QAAQ,gBAAgB,aAAa,KAAK,UAAU,gBAAgB,EAAE,gGAC9G;AACF;;;ACpEA,MAAa,wBAAwB;AACrC,MAAa,mBAAmB;AAEhC,SAAgB,gBACd,IACA,kBACyC;CACzC,OAAO;EACL,YAAY,GAAG,cAAc,kBAAkB,cAAA;EAC/C,OAAO,GAAG,SAAS,kBAAkB,SAAA;CACvC;AACF"}
@@ -1,57 +0,0 @@
1
- import type { ControlPolicy } from '@prisma-next/contract/types';
2
- import type { StorageType } from '@prisma-next/framework-components/ir';
3
-
4
- /**
5
- * Discriminator literal for the Postgres-enum variant on the polymorphic
6
- * `SqlStorage.types` slot.
7
- *
8
- * Enums are a target-level concept: Postgres ships native
9
- * `CREATE TYPE … AS ENUM` while other SQL targets approximate enums via
10
- * constraints. The literal lives at the SQL family layer because every
11
- * SQL-family consumer (verifier, planner, lowering, …) needs to
12
- * discriminate enum-typed slot entries from codec-typed ones. The
13
- * concrete IR class (`PostgresEnumType`) lives in the target-postgres
14
- * package and implements this structural contract; cross-domain
15
- * layering rules forbid the SQL family from importing the concrete
16
- * target class directly, so the discriminator and structural interface
17
- * carry the dispatch.
18
- */
19
- export const POSTGRES_ENUM_KIND = 'postgres-enum' as const;
20
-
21
- /**
22
- * Structural contract every Postgres-enum slot entry honours — both
23
- * the live `PostgresEnumType` IR-class instance and the raw JSON
24
- * envelope shape that survives `JSON.stringify` round-trips. SQL
25
- * family-layer dispatch narrows polymorphic `StorageType` slot
26
- * entries to this shape via `isPostgresEnumStorageEntry`.
27
- *
28
- * The `codecBinding` field is accessor-shaped (live class instance) on
29
- * the IR class and undefined on the raw JSON envelope; consumers that
30
- * need it must guard for its presence (the JSON path synthesises an
31
- * equivalent shape from `codecId` + `values`).
32
- */
33
- export interface PostgresEnumStorageEntry extends StorageType {
34
- readonly kind: typeof POSTGRES_ENUM_KIND;
35
- readonly name: string;
36
- readonly nativeType: string;
37
- readonly values: readonly string[];
38
- /**
39
- * Enumerable own property on the persisted JSON envelope; the live
40
- * IR-class instance carries it too. Family-shared dispatch sites
41
- * read `codecId` directly rather than going through the IR-class
42
- * `codecBinding` accessor (which lives on the prototype and isn't
43
- * present on raw JSON envelopes).
44
- */
45
- readonly codecId: string;
46
- readonly control?: ControlPolicy;
47
- }
48
-
49
- /**
50
- * Narrow a polymorphic `StorageType` entry to the Postgres-enum shape
51
- * via its enumerable `kind` discriminator. Type guard returns true for
52
- * both live `PostgresEnumType` instances and raw JSON envelopes.
53
- */
54
- export function isPostgresEnumStorageEntry(value: unknown): value is PostgresEnumStorageEntry {
55
- if (typeof value !== 'object' || value === null) return false;
56
- return (value as { kind?: unknown }).kind === POSTGRES_ENUM_KIND;
57
- }