@prisma-next/sql-contract 0.13.0 → 0.14.0

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 (48) hide show
  1. package/dist/{types-DqhaAjCH.mjs → entity-kinds-Cl36zL5j.mjs} +121 -205
  2. package/dist/entity-kinds-Cl36zL5j.mjs.map +1 -0
  3. package/dist/entity-kinds.d.mts +18 -0
  4. package/dist/entity-kinds.d.mts.map +1 -0
  5. package/dist/entity-kinds.mjs +2 -0
  6. package/dist/factories.d.mts +2 -2
  7. package/dist/factories.mjs +2 -1
  8. package/dist/factories.mjs.map +1 -1
  9. package/dist/index-type-validation.d.mts +1 -1
  10. package/dist/index-type-validation.mjs +9 -12
  11. package/dist/index-type-validation.mjs.map +1 -1
  12. package/dist/resolve-storage-table.d.mts +2 -1
  13. package/dist/resolve-storage-table.d.mts.map +1 -1
  14. package/dist/resolve-storage-table.mjs +11 -8
  15. package/dist/resolve-storage-table.mjs.map +1 -1
  16. package/dist/sql-storage-Dga0jwP2.d.mts +128 -0
  17. package/dist/sql-storage-Dga0jwP2.d.mts.map +1 -0
  18. package/dist/{sql-storage-CXf9xjAL.d.mts → storage-value-set-WnYsIFM8.d.mts} +8 -120
  19. package/dist/storage-value-set-WnYsIFM8.d.mts.map +1 -0
  20. package/dist/types-B-eiQXff.mjs +191 -0
  21. package/dist/types-B-eiQXff.mjs.map +1 -0
  22. package/dist/{types-DEnWD3xB.d.mts → types-B1N8w0I2.d.mts} +11 -62
  23. package/dist/types-B1N8w0I2.d.mts.map +1 -0
  24. package/dist/types.d.mts +4 -3
  25. package/dist/types.mjs +3 -2
  26. package/dist/validators.d.mts +75 -40
  27. package/dist/validators.d.mts.map +1 -1
  28. package/dist/validators.mjs +54 -184
  29. package/dist/validators.mjs.map +1 -1
  30. package/package.json +8 -7
  31. package/src/entity-kinds.ts +45 -0
  32. package/src/exports/entity-kinds.ts +5 -0
  33. package/src/exports/types.ts +2 -4
  34. package/src/index-type-validation.ts +2 -3
  35. package/src/ir/build-sql-namespace.ts +39 -32
  36. package/src/ir/sql-node.ts +2 -2
  37. package/src/ir/sql-storage.ts +22 -24
  38. package/src/ir/sql-unbound-namespace.ts +15 -3
  39. package/src/ir/storage-entry-schemas.ts +128 -0
  40. package/src/ir/storage-type-instance.ts +3 -3
  41. package/src/ir/storage-value-set.ts +6 -5
  42. package/src/resolve-storage-table.ts +12 -17
  43. package/src/types.ts +10 -10
  44. package/src/validators.ts +84 -225
  45. package/dist/sql-storage-CXf9xjAL.d.mts.map +0 -1
  46. package/dist/types-DEnWD3xB.d.mts.map +0 -1
  47. package/dist/types-DqhaAjCH.mjs.map +0 -1
  48. package/src/ir/postgres-enum-storage-entry.ts +0 -57
@@ -0,0 +1,128 @@
1
+ import { o as SqlNode } from "./foreign-key-BATxB95l.mjs";
2
+ import { r as StorageTable, t as StorageValueSet } from "./storage-value-set-WnYsIFM8.mjs";
3
+ import { Namespace, Storage, StorageType } from "@prisma-next/framework-components/ir";
4
+ import { StorageHashBase } from "@prisma-next/contract/types";
5
+
6
+ //#region src/ir/storage-type-instance.d.ts
7
+ /**
8
+ * Sentinel kind for the legacy codec-triple shape persisted under
9
+ * `SqlStorage.types`. Plain JSON-clean object literals carry this
10
+ * discriminator so the polymorphic slot dispatch can route them down
11
+ * the codec path while target-specific IR class instances (e.g. the
12
+ * Postgres enum class) keep their own narrower `kind` literal.
13
+ */
14
+ declare const CODEC_INSTANCE_KIND: "codec-instance";
15
+ /**
16
+ * Structural sub-interface of {@link StorageType} for codec-typed entries
17
+ * in `SqlStorage.types`. These are plain object literals — there is no
18
+ * runtime IR class, the JSON envelope round-trips through the slot
19
+ * unchanged. The `kind: 'codec-instance'` discriminator is the dispatch
20
+ * key that distinguishes codec-typed entries from any class-instance
21
+ * kinds a target pack contributes to the polymorphic slot.
22
+ */
23
+ interface StorageTypeInstance extends StorageType {
24
+ readonly kind: typeof CODEC_INSTANCE_KIND;
25
+ readonly codecId: string;
26
+ readonly nativeType: string;
27
+ readonly typeParams: Record<string, unknown>;
28
+ }
29
+ /**
30
+ * Construction-time input for a codec-triple entry. Symmetric with the
31
+ * structural runtime shape minus the `kind` discriminator — callers may
32
+ * omit `kind`; the helper {@link toStorageTypeInstance} stamps it on.
33
+ * `typeParams` may be omitted on input; the constructor normalises a
34
+ * missing value to `{}` so the in-memory shape is always present.
35
+ */
36
+ interface StorageTypeInstanceInput {
37
+ readonly codecId: string;
38
+ readonly nativeType: string;
39
+ readonly typeParams?: Record<string, unknown>;
40
+ }
41
+ /**
42
+ * Stamp the codec-instance `kind` discriminator on a caller-supplied
43
+ * codec triple. Idempotent: input that already carries the discriminator
44
+ * passes through unchanged. Missing `typeParams` is normalised to `{}`.
45
+ */
46
+ declare function toStorageTypeInstance(input: StorageTypeInstanceInput): StorageTypeInstance;
47
+ /**
48
+ * Type-guard for codec-typed entries on the polymorphic
49
+ * `SqlStorage.types` slot. Distinguishes `StorageTypeInstance` from
50
+ * any class-instance kinds a target pack contributes.
51
+ */
52
+ declare function isStorageTypeInstance(value: unknown): value is StorageTypeInstance;
53
+ //#endregion
54
+ //#region src/ir/sql-storage.d.ts
55
+ /**
56
+ * Polymorphic value type for document-scoped `SqlStorage.types` entries
57
+ * (codec aliases / parameterised native type registrations).
58
+ *
59
+ * Postgres native enum registrations live under the postgres-specific
60
+ * `entries.type` slot on `PostgresSchema` (target layer), not here.
61
+ */
62
+ type SqlStorageTypeEntry = StorageTypeInstance | StorageTypeInstanceInput;
63
+ interface SqlNamespaceTablesInput {
64
+ readonly id: string;
65
+ readonly entries: Readonly<Record<string, Readonly<Record<string, unknown>>>>;
66
+ }
67
+ interface SqlStorageInput<THash extends string = string> {
68
+ readonly storageHash: StorageHashBase<THash>;
69
+ readonly types?: Record<string, SqlStorageTypeEntry>;
70
+ readonly namespaces: Readonly<Record<string, SqlNamespace>>;
71
+ }
72
+ /**
73
+ * SQL Contract IR root node for the `storage` field.
74
+ *
75
+ * Single concrete family-shared class — both Postgres and SQLite
76
+ * consume this class today. Per-target storage subclasses are
77
+ * introduced when each target's namespace shape earns its
78
+ * target-specific concretion (target-specific derived fields,
79
+ * target-specific storage extensions).
80
+ *
81
+ * Honours the framework `Storage` interface: every SQL IR carries a
82
+ * `namespaces` map keyed by namespace id. Callers must supply fully
83
+ * constructed `Namespace` instances — construction discipline lives
84
+ * in the authoring builders and deserializer hydration paths.
85
+ *
86
+ * The constructor normalises optional `types` into class instances.
87
+ * `types` is polymorphic per Decision 18 Option B: codec-triple inputs
88
+ * are stamped with `kind: 'codec-instance'`; hydration of raw JSON
89
+ * class-instance entries (carrying their narrower `kind` literal) is
90
+ * the per-target serializer's responsibility (so the family base does
91
+ * not import target-specific subclasses).
92
+ */
93
+ /**
94
+ * The typed `entries` shape for SQL family namespaces. The open dictionary
95
+ * is intersected with optional known-kind maps so that `ns.entries.table`
96
+ * and `ns.entries.valueSet` resolve without a cast, while unknown pack-
97
+ * contributed kinds remain valid (the `Record` part allows any string key).
98
+ */
99
+ type SqlNamespaceEntries = Readonly<Record<string, Readonly<Record<string, unknown>>>> & {
100
+ readonly table?: Readonly<Record<string, StorageTable>>;
101
+ readonly valueSet?: Readonly<Record<string, StorageValueSet>>;
102
+ };
103
+ /**
104
+ * SQL family namespace. `entries` is the open ADR 224 dictionary —
105
+ * `entries[entityKind][entityName]` addresses any entity. Emitted
106
+ * contract literals satisfy this structurally (no prototype getters
107
+ * needed). For typed access to specific kinds, use the class getters
108
+ * on the concretion or `ns.entries.table` / `ns.entries.valueSet` directly.
109
+ */
110
+ type SqlNamespace = Namespace & {
111
+ readonly entries: SqlNamespaceEntries;
112
+ /**
113
+ * Render a dialect-qualified table reference for runtime SQL emission.
114
+ * Present on materialised target concretions (`PostgresSchema`,
115
+ * `SqliteDatabase`, …) and family placeholders; omitted on emitted
116
+ * contract structural namespace literals (methods are not serialised).
117
+ */
118
+ qualifyTable?(tableName: string): string;
119
+ };
120
+ declare class SqlStorage<THash extends string = string> extends SqlNode implements Storage {
121
+ readonly storageHash: StorageHashBase<THash>;
122
+ readonly namespaces: Readonly<Record<string, SqlNamespace>>;
123
+ readonly types?: Readonly<Record<string, StorageTypeInstance>>;
124
+ constructor(input: SqlStorageInput<THash>);
125
+ }
126
+ //#endregion
127
+ export { SqlStorageInput as a, StorageTypeInstance as c, toStorageTypeInstance as d, SqlStorage as i, StorageTypeInstanceInput as l, SqlNamespaceEntries as n, SqlStorageTypeEntry as o, SqlNamespaceTablesInput as r, CODEC_INSTANCE_KIND as s, SqlNamespace as t, isStorageTypeInstance as u };
128
+ //# sourceMappingURL=sql-storage-Dga0jwP2.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sql-storage-Dga0jwP2.d.mts","names":[],"sources":["../src/ir/storage-type-instance.ts","../src/ir/sql-storage.ts"],"mappings":";;;;;;;;;;;AASA;;cAAa,mBAAA;;AAA+C;AAU5D;;;;;;UAAiB,mBAAA,SAA4B,WAAA;EAAA,SAClC,IAAA,SAAa,mBAAA;EAAA,SACb,OAAA;EAAA,SACA,UAAA;EAAA,SACA,UAAA,EAAY,MAAA;AAAA;;;;;AAAM;AAU7B;;UAAiB,wBAAA;EAAA,SACN,OAAA;EAAA,SACA,UAAA;EAAA,SACA,UAAA,GAAa,MAAM;AAAA;;;AAAA;AAQ9B;;iBAAgB,qBAAA,CAAsB,KAAA,EAAO,wBAAA,GAA2B,mBAAmB;;;;;;iBAc3E,qBAAA,CAAsB,KAAA,YAAiB,KAAA,IAAS,mBAAmB;;;AAjDnF;;;;AAA4D;AAU5D;;AAVA,KCUY,mBAAA,GAAsB,mBAAA,GAAsB,wBAAwB;AAAA,UAE/D,uBAAA;EAAA,SACN,EAAA;EAAA,SACA,OAAA,EAAS,QAAA,CAAS,MAAA,SAAe,QAAA,CAAS,MAAA;AAAA;AAAA,UAGpC,eAAA;EAAA,SACN,WAAA,EAAa,eAAA,CAAgB,KAAA;EAAA,SAC7B,KAAA,GAAQ,MAAA,SAAe,mBAAA;EAAA,SACvB,UAAA,EAAY,QAAA,CAAS,MAAA,SAAe,YAAA;AAAA;;;;;ADNlB;AAU7B;;;;;;;;;AAG8B;AAQ9B;;;;;;;;AAA2F;AAc3F;;;KCCY,mBAAA,GAAsB,QAAA,CAAS,MAAA,SAAe,QAAA,CAAS,MAAA;EAAA,SACxD,KAAA,GAAQ,QAAA,CAAS,MAAA,SAAe,YAAA;EAAA,SAChC,QAAA,GAAW,QAAA,CAAS,MAAA,SAAe,eAAA;AAAA;;ADHqC;;;;ACvCnF;;KAoDY,YAAA,GAAe,SAAA;EAAA,SAChB,OAAA,EAAS,mBAAmB;EArDyC;AAEhF;;;;;EA0DE,YAAA,EAAc,SAAA;AAAA;AAAA,cAGH,UAAA,wCAAkD,OAAA,YAAmB,OAAA;EAAA,SACvE,WAAA,EAAa,eAAA,CAAgB,KAAA;EAAA,SAC7B,UAAA,EAAY,QAAA,CAAS,MAAA,SAAe,YAAA;EAAA,SAC5B,KAAA,GAAQ,QAAA,CAAS,MAAA,SAAe,mBAAA;cAErC,KAAA,EAAO,eAAA,CAAgB,KAAA;AAAA"}
@@ -1,6 +1,5 @@
1
1
  import { n as ForeignKeyInput, o as SqlNode, t as ForeignKey } from "./foreign-key-BATxB95l.mjs";
2
- import { Namespace, Storage, StorageType } from "@prisma-next/framework-components/ir";
3
- import { ColumnDefault, ControlPolicy, StorageHashBase, ValueSetRef } from "@prisma-next/contract/types";
2
+ import { ColumnDefault, ControlPolicy, JsonValue, ValueSetRef } from "@prisma-next/contract/types";
4
3
 
5
4
  //#region src/ir/check-constraint.d.ts
6
5
  /**
@@ -164,54 +163,6 @@ declare class StorageTable extends SqlNode {
164
163
  constructor(input: StorageTableInput);
165
164
  }
166
165
  //#endregion
167
- //#region src/ir/storage-type-instance.d.ts
168
- /**
169
- * Sentinel kind for the legacy codec-triple shape persisted under
170
- * `SqlStorage.types`. Plain JSON-clean object literals carry this
171
- * discriminator so the polymorphic slot dispatch can route them down
172
- * the codec path while target-specific IR class instances (e.g. the
173
- * Postgres enum class) keep their own narrower `kind` literal.
174
- */
175
- declare const CODEC_INSTANCE_KIND: "codec-instance";
176
- /**
177
- * Structural sub-interface of {@link StorageType} for codec-typed entries
178
- * in `SqlStorage.types`. These are plain object literals — there is no
179
- * runtime IR class, the JSON envelope round-trips through the slot
180
- * unchanged. The `kind: 'codec-instance'` discriminator is the dispatch
181
- * key that distinguishes codec-typed entries from class-instance entries
182
- * (e.g. `PostgresEnumType`) sharing the polymorphic slot.
183
- */
184
- interface StorageTypeInstance extends StorageType {
185
- readonly kind: typeof CODEC_INSTANCE_KIND;
186
- readonly codecId: string;
187
- readonly nativeType: string;
188
- readonly typeParams: Record<string, unknown>;
189
- }
190
- /**
191
- * Construction-time input for a codec-triple entry. Symmetric with the
192
- * structural runtime shape minus the `kind` discriminator — callers may
193
- * omit `kind`; the helper {@link toStorageTypeInstance} stamps it on.
194
- * `typeParams` may be omitted on input; the constructor normalises a
195
- * missing value to `{}` so the in-memory shape is always present.
196
- */
197
- interface StorageTypeInstanceInput {
198
- readonly codecId: string;
199
- readonly nativeType: string;
200
- readonly typeParams?: Record<string, unknown>;
201
- }
202
- /**
203
- * Stamp the codec-instance `kind` discriminator on a caller-supplied
204
- * codec triple. Idempotent: input that already carries the discriminator
205
- * passes through unchanged. Missing `typeParams` is normalised to `{}`.
206
- */
207
- declare function toStorageTypeInstance(input: StorageTypeInstanceInput): StorageTypeInstance;
208
- /**
209
- * Type-guard for codec-typed entries on the polymorphic
210
- * `SqlStorage.types` slot. Distinguishes `StorageTypeInstance` from
211
- * class-instance kinds (e.g. `PostgresEnumType`).
212
- */
213
- declare function isStorageTypeInstance(value: unknown): value is StorageTypeInstance;
214
- //#endregion
215
166
  //#region src/ir/storage-value-set.d.ts
216
167
  /**
217
168
  * Hydration / construction input shape for {@link StorageValueSet}.
@@ -219,9 +170,9 @@ declare function isStorageTypeInstance(value: unknown): value is StorageTypeInst
219
170
  * walker can hand a validated literal straight to `new`.
220
171
  */
221
172
  interface StorageValueSetInput {
222
- readonly kind: 'value-set';
173
+ readonly kind: 'valueSet';
223
174
  /** Ordered permitted values, codec-encoded. Declaration order is preserved. */
224
- readonly values: readonly string[];
175
+ readonly values: readonly JsonValue[];
225
176
  }
226
177
  /**
227
178
  * SQL Contract IR node for a value-set entry in a namespace's `valueSet`
@@ -232,7 +183,7 @@ interface StorageValueSetInput {
232
183
  * column that references it already holds the codec; the value-set holds
233
184
  * only the permitted values.
234
185
  *
235
- * The node's `kind` is enumerable (`'value-set'`) so the JSON envelope
186
+ * The node's `kind` is enumerable (`'valueSet'`) so the JSON envelope
236
187
  * carries the discriminator and the serializer hydration walker can
237
188
  * dispatch on it. This follows the per-leaf enumerable-kind convention
238
189
  * established in the SQL-node comment (future polymorphic dispatch on
@@ -242,73 +193,10 @@ interface StorageValueSetInput {
242
193
  * the parent namespace's `valueSet: Record<string, StorageValueSet>` map.
243
194
  */
244
195
  declare class StorageValueSet extends SqlNode {
245
- readonly kind: "value-set";
246
- readonly values: readonly string[];
196
+ readonly kind: "valueSet";
197
+ readonly values: readonly JsonValue[];
247
198
  constructor(input: StorageValueSetInput);
248
199
  }
249
200
  //#endregion
250
- //#region src/ir/sql-storage.d.ts
251
- /**
252
- * Polymorphic value type for document-scoped `SqlStorage.types` entries
253
- * (codec aliases / parameterised native type registrations).
254
- *
255
- * Postgres native enum registrations live under the postgres-specific
256
- * `entries.type` slot on `PostgresSchema` (target layer), not here.
257
- */
258
- type SqlStorageTypeEntry = StorageTypeInstance | StorageTypeInstanceInput;
259
- interface SqlNamespaceTablesInput {
260
- readonly id: string;
261
- readonly entries: {
262
- readonly table: Record<string, StorageTable | StorageTableInput>;
263
- readonly valueSet?: Record<string, StorageValueSet | StorageValueSetInput>;
264
- };
265
- }
266
- interface SqlStorageInput<THash extends string = string> {
267
- readonly storageHash: StorageHashBase<THash>;
268
- readonly types?: Record<string, SqlStorageTypeEntry>;
269
- readonly namespaces: Readonly<Record<string, SqlNamespace>>;
270
- }
271
- /**
272
- * SQL Contract IR root node for the `storage` field.
273
- *
274
- * Single concrete family-shared class — both Postgres and SQLite
275
- * consume this class today. Per-target storage subclasses are
276
- * introduced when each target's namespace shape earns its
277
- * target-specific concretion (target-specific derived fields,
278
- * target-specific storage extensions).
279
- *
280
- * Honours the framework `Storage` interface: every SQL IR carries a
281
- * `namespaces` map keyed by namespace id. Callers must supply fully
282
- * constructed `Namespace` instances — construction discipline lives
283
- * in the authoring builders and deserializer hydration paths.
284
- *
285
- * The constructor normalises optional `types` into class instances.
286
- * `types` is polymorphic per Decision 18 Option B: codec-triple inputs
287
- * are stamped with `kind: 'codec-instance'`; hydration of raw JSON
288
- * class-instance entries (carrying their narrower `kind` literal) is
289
- * the per-target serializer's responsibility (so the family base does
290
- * not import target-specific subclasses).
291
- */
292
- type SqlNamespace = Namespace & {
293
- readonly entries: Readonly<{
294
- readonly table: Readonly<Record<string, StorageTable>>;
295
- readonly valueSet?: Readonly<Record<string, StorageValueSet>>;
296
- }>;
297
- /**
298
- * Render a dialect-qualified table reference for runtime SQL emission.
299
- * Present on materialised target concretions (`PostgresSchema`,
300
- * `SqliteDatabase`, …) and family placeholders; omitted on emitted
301
- * contract structural namespace literals (methods are not serialised).
302
- */
303
- qualifyTable?(tableName: string): string;
304
- };
305
- declare class SqlStorage<THash extends string = string> extends SqlNode implements Storage {
306
- readonly storageHash: StorageHashBase<THash>;
307
- readonly namespaces: Readonly<Record<string, SqlNamespace>>;
308
- readonly types?: Readonly<Record<string, StorageTypeInstance>>;
309
- constructor(input: SqlStorageInput<THash>);
310
- }
311
- declare function storageTableAt(storage: SqlStorage, namespaceId: string, tableName: string): StorageTable | undefined;
312
- //#endregion
313
- export { PrimaryKeyInput as C, PrimaryKey as S, CheckConstraintInput as T, UniqueConstraintInput as _, SqlStorageTypeEntry as a, Index as b, StorageValueSetInput as c, StorageTypeInstanceInput as d, isStorageTypeInstance as f, UniqueConstraint as g, StorageTableInput as h, SqlStorageInput as i, CODEC_INSTANCE_KIND as l, StorageTable as m, SqlNamespaceTablesInput as n, storageTableAt as o, toStorageTypeInstance as p, SqlStorage as r, StorageValueSet as s, SqlNamespace as t, StorageTypeInstance as u, StorageColumn as v, CheckConstraint as w, IndexInput as x, StorageColumnInput as y };
314
- //# sourceMappingURL=sql-storage-CXf9xjAL.d.mts.map
201
+ export { UniqueConstraint as a, StorageColumnInput as c, PrimaryKey as d, PrimaryKeyInput as f, StorageTableInput as i, Index as l, CheckConstraintInput as m, StorageValueSetInput as n, UniqueConstraintInput as o, CheckConstraint as p, StorageTable as r, StorageColumn as s, StorageValueSet as t, IndexInput as u };
202
+ //# sourceMappingURL=storage-value-set-WnYsIFM8.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage-value-set-WnYsIFM8.d.mts","names":[],"sources":["../src/ir/check-constraint.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"],"mappings":";;;;;;AASA;;;UAAiB,oBAAA;EAAA,SACN,IAAA;EAAA,SACA,MAAA;EAAA,SACA,QAAA,EAAU,WAAW;AAAA;;AAAA;AAiBhC;;;;;;;;;;;;cAAa,eAAA,SAAwB,OAAA;EAAA,SAC1B,IAAA;EAAA,SACA,MAAA;EAAA,SACA,QAAA,EAAU,WAAA;cAEP,KAAA,EAAO,oBAAA;AAAA;;;UC/BJ,eAAA;EAAA,SACN,OAAA;EAAA,SACA,IAAI;AAAA;;;;cAMF,UAAA,SAAmB,OAAO;EAAA,SAC5B,OAAA;EAAA,SACQ,IAAA;cAEL,KAAA,EAAO,eAAA;AAAA;;;UCZJ,UAAA;EAAA,SACN,OAAA;EAAA,SACA,IAAA;EAAA,SACA,IAAA;EAAA,SACA,OAAA,GAAU,MAAM;AAAA;;;;;;;AFKK;AAiBhC;cEXa,KAAA,SAAc,OAAA;EAAA,SAChB,OAAA;EAAA,SACQ,IAAA;EAAA,SACA,IAAA;EAAA,SACA,OAAA,GAAU,MAA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;EAAA,SACvB,WAAA,EAAa,aAAA,CAAc,UAAA;EAAA,SACnB,UAAA,GAAa,UAAA;EAAA,SACb,OAAA,GAAU,aAAA;EAAA,SACV,MAAA,GAAS,aAAA,CAAc,eAAA;cAE5B,KAAA,EAAO,iBAAA;AAAA;;;;;ALhCrB;;;UMAiB,oBAAA;EAAA,SACN,IAAA;ENCA;EAAA,SMCA,MAAA,WAAiB,SAAS;AAAA;;ANAL;AAiBhC;;;;;;;;;;;;;;;;cMIa,eAAA,SAAwB,OAAA;EAAA,SACjB,IAAA;EAAA,SACT,MAAA,WAAiB,SAAA;cAEd,KAAA,EAAO,oBAAA;AAAA"}
@@ -0,0 +1,191 @@
1
+ import { p as SqlNode, t as composeSqlEntityKinds } from "./entity-kinds-Cl36zL5j.mjs";
2
+ import { NamespaceBase, UNBOUND_NAMESPACE_ID, freezeNode, hydrateNamespaceEntities } from "@prisma-next/framework-components/ir";
3
+ import { blindCast } from "@prisma-next/utils/casts";
4
+ //#region src/ir/sql-unbound-namespace.ts
5
+ /**
6
+ * Family-layer placeholder for the SQL unbound-namespace singleton —
7
+ * the late-bound slot whose binding the target resolves at connection
8
+ * time rather than at authoring time.
9
+ *
10
+ * SQL contracts honour the framework `Storage.namespaces` invariant from
11
+ * the moment they appear in the IR. Today `SqlStorage` is family-shared
12
+ * (Postgres + SQLite consume the same class); a per-target namespace
13
+ * concretion (`PostgresSchema.unbound`, `SqliteUnboundDatabase.instance`)
14
+ * earns its existence when each target's namespace shape lands. Until
15
+ * then the family ships a single placeholder singleton so the JSON
16
+ * envelope and runtime walk are honest at every layer.
17
+ *
18
+ * The `kind` discriminator is installed as a non-enumerable own property
19
+ * so the JSON envelope reads `{ "id": "__unbound__", "entries": { … } }`
20
+ * — symmetric with the family-level non-enumerable `kind` on `SqlNode`
21
+ * and bounded to the minimum data the framework `Namespace` interface
22
+ * promises.
23
+ *
24
+ * **Freeze-trap warning.** The leaf constructor calls
25
+ * `freezeNode(this)` after installing `kind`. The leaf-class shape
26
+ * works today only because `NamespaceBase` does NOT freeze in its
27
+ * constructor — the `Object.defineProperty(this, 'kind', …)` call after
28
+ * `super()` succeeds because the instance is still mutable at that
29
+ * point. Subclasses that add instance fields will still hit the freeze
30
+ * trap once leaf-class `freezeNode(this)` runs; and if a future
31
+ * framework change lifts the freeze to `NamespaceBase`, even the
32
+ * `defineProperty` here would silently fail. To add subclass instance
33
+ * fields safely, lift `freezeNode` to a leaf-class `seal()` hook each
34
+ * leaf calls explicitly at the end of its own constructor.
35
+ */
36
+ var SqlUnboundNamespace = class SqlUnboundNamespace extends NamespaceBase {
37
+ static instance = new SqlUnboundNamespace();
38
+ id = UNBOUND_NAMESPACE_ID;
39
+ entries = Object.freeze({ table: blindCast(Object.freeze({})) });
40
+ constructor() {
41
+ super();
42
+ Object.defineProperty(this, "kind", {
43
+ value: "sql-namespace",
44
+ writable: false,
45
+ enumerable: false,
46
+ configurable: true
47
+ });
48
+ freezeNode(this);
49
+ }
50
+ get table() {
51
+ return blindCast(this.entries["table"]);
52
+ }
53
+ qualifyTable(tableName) {
54
+ return `"${tableName}"`;
55
+ }
56
+ };
57
+ //#endregion
58
+ //#region src/ir/build-sql-namespace.ts
59
+ const SQL_NAMESPACE_KIND = "sql-namespace";
60
+ function isMaterializedSqlNamespace(ns) {
61
+ if (typeof ns !== "object" || ns === null) return false;
62
+ const proto = Object.getPrototypeOf(ns);
63
+ if (proto === Object.prototype || proto === null) return false;
64
+ return ns.kind === SQL_NAMESPACE_KIND;
65
+ }
66
+ var SqlBoundNamespace = class SqlBoundNamespace extends NamespaceBase {
67
+ id;
68
+ entries;
69
+ static fromTablesInput(input) {
70
+ const tableKind = input.entries["table"];
71
+ const tableCount = tableKind !== void 0 ? Object.keys(tableKind).length : 0;
72
+ const valueSetKind = input.entries["valueSet"];
73
+ const hasValueSets = valueSetKind !== void 0 && Object.keys(valueSetKind).length > 0;
74
+ const hasUnknownKinds = Object.keys(input.entries).some((kind) => kind !== "table" && kind !== "valueSet");
75
+ if (input.id === UNBOUND_NAMESPACE_ID && tableCount === 0 && !hasValueSets && !hasUnknownKinds) return SqlUnboundNamespace.instance;
76
+ return new SqlBoundNamespace(input);
77
+ }
78
+ constructor(input) {
79
+ super();
80
+ this.id = input.id;
81
+ const dispatched = hydrateNamespaceEntities(input.entries, composeSqlEntityKinds(), "carry");
82
+ this.entries = Object.freeze(blindCast(dispatched));
83
+ Object.defineProperty(this, "kind", {
84
+ value: SQL_NAMESPACE_KIND,
85
+ writable: false,
86
+ enumerable: false,
87
+ configurable: true
88
+ });
89
+ freezeNode(this);
90
+ }
91
+ get table() {
92
+ return this.entries.table ?? Object.freeze({});
93
+ }
94
+ get valueSet() {
95
+ return this.entries.valueSet;
96
+ }
97
+ qualifyTable(tableName) {
98
+ if (this.id === UNBOUND_NAMESPACE_ID) return `"${tableName}"`;
99
+ return `"${this.id}"."${tableName}"`;
100
+ }
101
+ };
102
+ function buildSqlNamespace(input) {
103
+ return SqlBoundNamespace.fromTablesInput(input);
104
+ }
105
+ function buildSqlNamespaceMap(namespaces) {
106
+ return Object.fromEntries(Object.entries(namespaces).map(([nsKey, ns]) => [nsKey, isMaterializedSqlNamespace(ns) ? ns : SqlBoundNamespace.fromTablesInput(blindCast(ns))]));
107
+ }
108
+ //#endregion
109
+ //#region src/ir/storage-type-instance.ts
110
+ /**
111
+ * Sentinel kind for the legacy codec-triple shape persisted under
112
+ * `SqlStorage.types`. Plain JSON-clean object literals carry this
113
+ * discriminator so the polymorphic slot dispatch can route them down
114
+ * the codec path while target-specific IR class instances (e.g. the
115
+ * Postgres enum class) keep their own narrower `kind` literal.
116
+ */
117
+ const CODEC_INSTANCE_KIND = "codec-instance";
118
+ /**
119
+ * Stamp the codec-instance `kind` discriminator on a caller-supplied
120
+ * codec triple. Idempotent: input that already carries the discriminator
121
+ * passes through unchanged. Missing `typeParams` is normalised to `{}`.
122
+ */
123
+ function toStorageTypeInstance(input) {
124
+ return {
125
+ kind: CODEC_INSTANCE_KIND,
126
+ codecId: input.codecId,
127
+ nativeType: input.nativeType,
128
+ typeParams: input.typeParams ?? {}
129
+ };
130
+ }
131
+ /**
132
+ * Type-guard for codec-typed entries on the polymorphic
133
+ * `SqlStorage.types` slot. Distinguishes `StorageTypeInstance` from
134
+ * any class-instance kinds a target pack contributes.
135
+ */
136
+ function isStorageTypeInstance(value) {
137
+ if (typeof value !== "object" || value === null) return false;
138
+ return value.kind === CODEC_INSTANCE_KIND;
139
+ }
140
+ //#endregion
141
+ //#region src/ir/sql-storage.ts
142
+ var SqlStorage = class extends SqlNode {
143
+ storageHash;
144
+ namespaces;
145
+ constructor(input) {
146
+ super();
147
+ this.storageHash = input.storageHash;
148
+ this.namespaces = Object.freeze(input.namespaces);
149
+ if (input.types !== void 0) this.types = Object.freeze(Object.fromEntries(Object.entries(input.types).map(([name, ti]) => [name, normaliseTypeEntry(name, ti)])));
150
+ freezeNode(this);
151
+ }
152
+ };
153
+ /**
154
+ * Strict polymorphic-slot dispatch for `SqlStorage.types` entries.
155
+ * Every entry must carry a `kind: 'codec-instance'` discriminator or
156
+ * be an already-constructed `StorageTypeInstance`. Untagged or
157
+ * unrecognised inputs throw a diagnostic naming the entry and its
158
+ * `kind`, so format drift surfaces loudly at the deserializer
159
+ * boundary instead of slipping past the seam and corrupting
160
+ * downstream IR walks.
161
+ *
162
+ * Codec-triple authors that have an untagged shape on hand can call
163
+ * `toStorageTypeInstance(...)` (which stamps the `'codec-instance'`
164
+ * discriminator) before constructing `SqlStorage`. On-disk reads
165
+ * cross `familyInstance.deserializeContract` first; the structural
166
+ * arktype schema rejects untagged entries earlier, so this throw
167
+ * only fires for in-memory authoring bugs.
168
+ */
169
+ function normaliseTypeEntry(name, entry) {
170
+ if (isStorageTypeInstance(entry)) {
171
+ if ("typeParams" in entry) return entry;
172
+ return toStorageTypeInstance(entry);
173
+ }
174
+ const rawKind = entry.kind;
175
+ const kindDescription = rawKind === void 0 ? "missing `kind` discriminator" : `unrecognised \`kind\` discriminator ${JSON.stringify(rawKind)}`;
176
+ throw new Error(`storage.types[${JSON.stringify(name)}] has ${kindDescription}; expected ${JSON.stringify("codec-instance")}. Untagged codec triples should be wrapped with toStorageTypeInstance(...) before construction.`);
177
+ }
178
+ //#endregion
179
+ //#region src/types.ts
180
+ const DEFAULT_FK_CONSTRAINT = true;
181
+ const DEFAULT_FK_INDEX = true;
182
+ function applyFkDefaults(fk, overrideDefaults) {
183
+ return {
184
+ constraint: fk.constraint ?? overrideDefaults?.constraint ?? true,
185
+ index: fk.index ?? overrideDefaults?.index ?? true
186
+ };
187
+ }
188
+ //#endregion
189
+ export { CODEC_INSTANCE_KIND as a, buildSqlNamespace as c, SqlStorage as i, buildSqlNamespaceMap as l, DEFAULT_FK_INDEX as n, isStorageTypeInstance as o, applyFkDefaults as r, toStorageTypeInstance as s, DEFAULT_FK_CONSTRAINT as t, SqlUnboundNamespace as u };
190
+
191
+ //# sourceMappingURL=types-B-eiQXff.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types-B-eiQXff.mjs","names":[],"sources":["../src/ir/sql-unbound-namespace.ts","../src/ir/build-sql-namespace.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 { blindCast } from '@prisma-next/utils/casts';\nimport type { SqlNamespaceEntries } from './sql-storage';\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: SqlNamespaceEntries = Object.freeze({\n table: blindCast<\n Readonly<Record<string, StorageTable>>,\n 'empty frozen map is a valid Readonly<Record<string, StorageTable>>'\n >(Object.freeze({})),\n });\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 get table(): Readonly<Record<string, StorageTable>> {\n return blindCast<\n Readonly<Record<string, StorageTable>>,\n 'entries[table] holds only StorageTable by construction'\n >(this.entries['table']);\n }\n\n qualifyTable(tableName: string): string {\n return `\"${tableName}\"`;\n }\n}\n","import {\n freezeNode,\n hydrateNamespaceEntities,\n type Namespace,\n NamespaceBase,\n UNBOUND_NAMESPACE_ID,\n} from '@prisma-next/framework-components/ir';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport { composeSqlEntityKinds } from '../entity-kinds';\nimport type { SqlNamespace, SqlNamespaceEntries, SqlNamespaceTablesInput } from './sql-storage';\nimport { SqlUnboundNamespace } from './sql-unbound-namespace';\nimport type { StorageTable } from './storage-table';\nimport type { 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: SqlNamespaceEntries;\n\n static fromTablesInput(input: SqlNamespaceTablesInput): SqlNamespace {\n const tableKind = input.entries['table'];\n const tableCount = tableKind !== undefined ? Object.keys(tableKind).length : 0;\n const valueSetKind = input.entries['valueSet'];\n const hasValueSets = valueSetKind !== undefined && Object.keys(valueSetKind).length > 0;\n const hasUnknownKinds = Object.keys(input.entries).some(\n (kind) => kind !== 'table' && kind !== 'valueSet',\n );\n if (\n input.id === UNBOUND_NAMESPACE_ID &&\n tableCount === 0 &&\n !hasValueSets &&\n !hasUnknownKinds\n ) {\n return SqlUnboundNamespace.instance;\n }\n return new SqlBoundNamespace(input);\n }\n\n private constructor(input: SqlNamespaceTablesInput) {\n super();\n this.id = input.id;\n\n const dispatched = hydrateNamespaceEntities(input.entries, composeSqlEntityKinds(), 'carry');\n\n this.entries = Object.freeze(\n blindCast<\n SqlNamespaceEntries,\n 'composeSqlEntityKinds() supplies table→StorageTable and valueSet→StorageValueSet descriptors, so this open-dict result holds exactly the typed members SqlNamespaceEntries declares; the descriptor Map erases those per-kind Node types from the return.'\n >(dispatched),\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 get table(): Readonly<Record<string, StorageTable>> {\n return this.entries.table ?? Object.freeze({});\n }\n\n get valueSet(): Readonly<Record<string, StorageValueSet>> | undefined {\n return this.entries.valueSet;\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 ? 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 { 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 any class-instance\n * kinds a target pack contributes to 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 * any class-instance kinds a target pack contributes.\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 } from './storage-table';\nimport {\n isStorageTypeInstance,\n type StorageTypeInstance,\n type StorageTypeInstanceInput,\n toStorageTypeInstance,\n} from './storage-type-instance';\nimport type { StorageValueSet } 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: Readonly<Record<string, Readonly<Record<string, unknown>>>>;\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/**\n * The typed `entries` shape for SQL family namespaces. The open dictionary\n * is intersected with optional known-kind maps so that `ns.entries.table`\n * and `ns.entries.valueSet` resolve without a cast, while unknown pack-\n * contributed kinds remain valid (the `Record` part allows any string key).\n */\nexport type SqlNamespaceEntries = Readonly<Record<string, Readonly<Record<string, unknown>>>> & {\n readonly table?: Readonly<Record<string, StorageTable>>;\n readonly valueSet?: Readonly<Record<string, StorageValueSet>>;\n};\n\n/**\n * SQL family namespace. `entries` is the open ADR 224 dictionary —\n * `entries[entityKind][entityName]` addresses any entity. Emitted\n * contract literals satisfy this structurally (no prototype getters\n * needed). For typed access to specific kinds, use the class getters\n * on the concretion or `ns.entries.table` / `ns.entries.valueSet` directly.\n */\nexport type SqlNamespace = Namespace & {\n readonly entries: SqlNamespaceEntries;\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\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 { PrimaryKey, type PrimaryKeyInput } from './ir/primary-key';\nexport { Index, type IndexInput } from './ir/sql-index';\nexport { SqlNode } from './ir/sql-node';\nexport {\n type SqlNamespace,\n type SqlNamespaceEntries,\n type SqlNamespaceTablesInput,\n SqlStorage,\n type SqlStorageInput,\n type SqlStorageTypeEntry,\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\n// Field-type maps nested by namespace coordinate: `[namespaceId][model][field]`.\n// Shared by the output and input field-type maps and their extractors.\nexport type NamespacedFieldTypeMap = Record<string, Record<string, Record<string, unknown>>>;\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 NamespacedFieldTypeMap = Record<string, never>,\n TFieldInputTypes extends NamespacedFieldTypeMap = 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 NamespacedFieldTypeMap\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 NamespacedFieldTypeMap\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwC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