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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/dist/canonicalization-hooks.d.mts.map +1 -1
  2. package/dist/canonicalization-hooks.mjs +10 -11
  3. package/dist/canonicalization-hooks.mjs.map +1 -1
  4. package/dist/factories.d.mts +4 -2
  5. package/dist/factories.d.mts.map +1 -1
  6. package/dist/factories.mjs +3 -2
  7. package/dist/factories.mjs.map +1 -1
  8. package/dist/foreign-key-BATxB95l.d.mts +121 -0
  9. package/dist/foreign-key-BATxB95l.d.mts.map +1 -0
  10. package/dist/index-type-validation.d.mts +2 -2
  11. package/dist/index-type-validation.mjs +1 -1
  12. package/dist/index-type-validation.mjs.map +1 -1
  13. package/dist/{index-types-B1cf5N0F.d.mts → index-types-Czsyu7Iw.d.mts} +1 -1
  14. package/dist/{index-types-B1cf5N0F.d.mts.map → index-types-Czsyu7Iw.d.mts.map} +1 -1
  15. package/dist/index-types.d.mts +1 -1
  16. package/dist/pack-types.d.mts +1 -1
  17. package/dist/referential-action-sql.d.mts +12 -0
  18. package/dist/referential-action-sql.d.mts.map +1 -0
  19. package/dist/referential-action-sql.mjs +17 -0
  20. package/dist/referential-action-sql.mjs.map +1 -0
  21. package/dist/resolve-storage-table.d.mts +20 -0
  22. package/dist/resolve-storage-table.d.mts.map +1 -0
  23. package/dist/resolve-storage-table.mjs +42 -0
  24. package/dist/resolve-storage-table.mjs.map +1 -0
  25. package/dist/sql-storage-CXf9xjAL.d.mts +314 -0
  26. package/dist/sql-storage-CXf9xjAL.d.mts.map +1 -0
  27. package/dist/types-DEnWD3xB.d.mts +208 -0
  28. package/dist/types-DEnWD3xB.d.mts.map +1 -0
  29. package/dist/{types-DPkj4y3_.mjs → types-DqhaAjCH.mjs} +109 -28
  30. package/dist/types-DqhaAjCH.mjs.map +1 -0
  31. package/dist/types.d.mts +4 -2
  32. package/dist/types.mjs +2 -2
  33. package/dist/validators.d.mts +51 -14
  34. package/dist/validators.d.mts.map +1 -1
  35. package/dist/validators.mjs +116 -32
  36. package/dist/validators.mjs.map +1 -1
  37. package/package.json +11 -9
  38. package/src/canonicalization-hooks.ts +5 -6
  39. package/src/exports/referential-action-sql.ts +1 -0
  40. package/src/exports/resolve-storage-table.ts +1 -0
  41. package/src/exports/types.ts +6 -0
  42. package/src/factories.ts +2 -1
  43. package/src/index-type-validation.ts +1 -1
  44. package/src/ir/build-sql-namespace.ts +33 -19
  45. package/src/ir/check-constraint.ts +42 -0
  46. package/src/ir/foreign-key-reference.ts +23 -0
  47. package/src/ir/postgres-enum-storage-entry.ts +2 -0
  48. package/src/ir/sql-storage.ts +53 -50
  49. package/src/ir/sql-unbound-namespace.ts +11 -4
  50. package/src/ir/storage-column.ts +7 -1
  51. package/src/ir/storage-table.ts +10 -0
  52. package/src/ir/storage-type-instance.ts +5 -3
  53. package/src/ir/storage-value-set.ts +42 -0
  54. package/src/referential-action-sql.ts +14 -0
  55. package/src/resolve-storage-table.ts +61 -0
  56. package/src/types.ts +13 -0
  57. package/src/validators.ts +156 -46
  58. package/dist/types-ChlHcJCu.d.mts +0 -508
  59. package/dist/types-ChlHcJCu.d.mts.map +0 -1
  60. package/dist/types-DPkj4y3_.mjs.map +0 -1
@@ -0,0 +1,314 @@
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";
4
+
5
+ //#region src/ir/check-constraint.d.ts
6
+ /**
7
+ * Hydration / construction input shape for {@link CheckConstraint}.
8
+ * Mirrors the on-disk storage JSON envelope so the serializer hydration
9
+ * walker can hand a validated literal straight to `new`.
10
+ */
11
+ interface CheckConstraintInput {
12
+ readonly name: string;
13
+ readonly column: string;
14
+ readonly valueSet: ValueSetRef;
15
+ }
16
+ /**
17
+ * SQL Contract IR node for a table-level check constraint that restricts
18
+ * a column to the permitted values of a value-set.
19
+ *
20
+ * The constraint is **structured** (names a column and a value-set
21
+ * reference), not a raw SQL expression. Each target renders its own DDL
22
+ * from the structured form, keeping the contract target-agnostic.
23
+ *
24
+ * Construction is idempotent: passing an existing `CheckConstraint`
25
+ * instance as input produces a new instance with identical fields.
26
+ * The constructor does not use `instanceof` for input discrimination —
27
+ * it reads plain named properties, which is sufficient since
28
+ * `CheckConstraintInput` is a structural type.
29
+ */
30
+ declare class CheckConstraint extends SqlNode {
31
+ readonly name: string;
32
+ readonly column: string;
33
+ readonly valueSet: ValueSetRef;
34
+ constructor(input: CheckConstraintInput);
35
+ }
36
+ //#endregion
37
+ //#region src/ir/primary-key.d.ts
38
+ interface PrimaryKeyInput {
39
+ readonly columns: readonly string[];
40
+ readonly name?: string;
41
+ }
42
+ /**
43
+ * SQL Contract IR node for a table's primary-key constraint.
44
+ */
45
+ declare class PrimaryKey extends SqlNode {
46
+ readonly columns: readonly string[];
47
+ readonly name?: string;
48
+ constructor(input: PrimaryKeyInput);
49
+ }
50
+ //#endregion
51
+ //#region src/ir/sql-index.d.ts
52
+ interface IndexInput {
53
+ readonly columns: readonly string[];
54
+ readonly name?: string;
55
+ readonly type?: string;
56
+ readonly options?: Record<string, unknown>;
57
+ }
58
+ /**
59
+ * SQL Contract IR node for a table-level secondary index.
60
+ *
61
+ * Note that this class shadows the global TypeScript `Index` lib type
62
+ * at the family-shared name; consumer files that need both should
63
+ * alias one (e.g.
64
+ * `import { Index as SqlIndexNode } from '@prisma-next/sql-contract/types'`).
65
+ */
66
+ declare class Index extends SqlNode {
67
+ readonly columns: readonly string[];
68
+ readonly name?: string;
69
+ readonly type?: string;
70
+ readonly options?: Record<string, unknown>;
71
+ constructor(input: IndexInput);
72
+ }
73
+ //#endregion
74
+ //#region src/ir/storage-column.d.ts
75
+ /**
76
+ * Hydration / construction input shape for {@link StorageColumn}. Mirrors
77
+ * the on-disk storage JSON envelope exactly so the family-base
78
+ * serializer's hydration walker can hand an arktype-validated literal
79
+ * straight to `new`.
80
+ *
81
+ * `typeParams` and `typeRef` remain mutually exclusive (one or the
82
+ * other, not both); the constructor preserves whichever caller-side
83
+ * choice the input encodes.
84
+ */
85
+ interface StorageColumnInput {
86
+ readonly nativeType: string;
87
+ readonly codecId: string;
88
+ readonly nullable: boolean;
89
+ readonly typeParams?: Record<string, unknown>;
90
+ readonly typeRef?: string;
91
+ readonly default?: ColumnDefault;
92
+ readonly control?: ControlPolicy;
93
+ readonly valueSet?: ValueSetRef;
94
+ }
95
+ /**
96
+ * SQL Contract IR node for a single column entry in `StorageTable.columns`.
97
+ *
98
+ * Single concrete family-shared class — every SQL target reads the
99
+ * same column shape today, so there is no per-target subclass. The
100
+ * class type accepts any caller that constructs via
101
+ * `new StorageColumn(input)`; literal construction sites must pass
102
+ * through the constructor or the family-base hydration walker.
103
+ *
104
+ * The column's `name` is not on the class — columns are keyed by name
105
+ * in the parent `StorageTable.columns: Record<string, StorageColumn>`
106
+ * map, so a `name` field would be redundant with the key.
107
+ */
108
+ declare class StorageColumn extends SqlNode {
109
+ readonly nativeType: string;
110
+ readonly codecId: string;
111
+ readonly nullable: boolean;
112
+ readonly typeParams?: Record<string, unknown>;
113
+ readonly typeRef?: string;
114
+ readonly default?: ColumnDefault;
115
+ readonly control?: ControlPolicy;
116
+ readonly valueSet?: ValueSetRef;
117
+ constructor(input: StorageColumnInput);
118
+ }
119
+ //#endregion
120
+ //#region src/ir/unique-constraint.d.ts
121
+ interface UniqueConstraintInput {
122
+ readonly columns: readonly string[];
123
+ readonly name?: string;
124
+ }
125
+ /**
126
+ * SQL Contract IR node for a table-level unique constraint.
127
+ */
128
+ declare class UniqueConstraint extends SqlNode {
129
+ readonly columns: readonly string[];
130
+ readonly name?: string;
131
+ constructor(input: UniqueConstraintInput);
132
+ }
133
+ //#endregion
134
+ //#region src/ir/storage-table.d.ts
135
+ interface StorageTableInput {
136
+ readonly columns: Record<string, StorageColumn | StorageColumnInput>;
137
+ readonly primaryKey?: PrimaryKey | PrimaryKeyInput;
138
+ readonly uniques: ReadonlyArray<UniqueConstraint | UniqueConstraintInput>;
139
+ readonly indexes: ReadonlyArray<Index | IndexInput>;
140
+ readonly foreignKeys: ReadonlyArray<ForeignKey | ForeignKeyInput>;
141
+ readonly control?: ControlPolicy;
142
+ readonly checks?: ReadonlyArray<CheckConstraint | CheckConstraintInput>;
143
+ }
144
+ /**
145
+ * SQL Contract IR node for a single table entry in a namespace's
146
+ * `tables` map.
147
+ *
148
+ * The constructor normalises nested IR-class fields (columns, primary
149
+ * key, uniques, indexes, foreign keys) into the appropriate class
150
+ * instances so downstream walks see a uniform AST regardless of whether
151
+ * the input was a JSON literal or an already-constructed class.
152
+ *
153
+ * The table's `name` is not on the class — tables are keyed by name in
154
+ * the parent namespace's `tables: Record<string, StorageTable>` map.
155
+ */
156
+ declare class StorageTable extends SqlNode {
157
+ readonly columns: Readonly<Record<string, StorageColumn>>;
158
+ readonly uniques: ReadonlyArray<UniqueConstraint>;
159
+ readonly indexes: ReadonlyArray<Index>;
160
+ readonly foreignKeys: ReadonlyArray<ForeignKey>;
161
+ readonly primaryKey?: PrimaryKey;
162
+ readonly control?: ControlPolicy;
163
+ readonly checks?: ReadonlyArray<CheckConstraint>;
164
+ constructor(input: StorageTableInput);
165
+ }
166
+ //#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
+ //#region src/ir/storage-value-set.d.ts
216
+ /**
217
+ * Hydration / construction input shape for {@link StorageValueSet}.
218
+ * Mirrors the on-disk storage JSON envelope so the serializer hydration
219
+ * walker can hand a validated literal straight to `new`.
220
+ */
221
+ interface StorageValueSetInput {
222
+ readonly kind: 'value-set';
223
+ /** Ordered permitted values, codec-encoded. Declaration order is preserved. */
224
+ readonly values: readonly string[];
225
+ }
226
+ /**
227
+ * SQL Contract IR node for a value-set entry in a namespace's `valueSet`
228
+ * map (`SqlNamespace.entries.valueSet`).
229
+ *
230
+ * A value-set records the ordered set of permitted codec-encoded values for
231
+ * an enum-like column restriction. It does not carry a `codecId` — the
232
+ * column that references it already holds the codec; the value-set holds
233
+ * only the permitted values.
234
+ *
235
+ * The node's `kind` is enumerable (`'value-set'`) so the JSON envelope
236
+ * carries the discriminator and the serializer hydration walker can
237
+ * dispatch on it. This follows the per-leaf enumerable-kind convention
238
+ * established in the SQL-node comment (future polymorphic dispatch on
239
+ * namespace entries needs the discriminator in JSON).
240
+ *
241
+ * The entry's name is not on the class — value-sets are keyed by name in
242
+ * the parent namespace's `valueSet: Record<string, StorageValueSet>` map.
243
+ */
244
+ declare class StorageValueSet extends SqlNode {
245
+ readonly kind: "value-set";
246
+ readonly values: readonly string[];
247
+ constructor(input: StorageValueSetInput);
248
+ }
249
+ //#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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sql-storage-CXf9xjAL.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-type-instance.ts","../src/ir/storage-value-set.ts","../src/ir/sql-storage.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;ADIf;;;AAAA,cCEa,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;cEMnB,KAAA,SAAc,OAAA;EAAA,SAChB,OAAA;EAAA,SACQ,IAAA;EAAA,SACA,IAAA;EAAA,SACA,OAAA,GAAU,MAAA;cAEf,KAAA,EAAO,UAAA;AAAA;;;;;;AFfrB;;;;;;;UGKiB,kBAAA;EAAA,SACN,UAAA;EAAA,SACA,OAAA;EAAA,SACA,QAAA;EAAA,SACA,UAAA,GAAa,MAAA;EAAA,SACb,OAAA;EAAA,SACA,OAAA,GAAU,aAAA;EAAA,SACV,OAAA,GAAU,aAAA;EAAA,SACV,QAAA,GAAW,WAAA;AAAA;;;;;;;;;;;AHYmB;;;cGI5B,aAAA,SAAsB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E,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;AAAA,iBAerB,cAAA,CACd,OAAA,EAAS,UAAA,EACT,WAAA,UACA,SAAA,WACC,YAAY"}
@@ -0,0 +1,208 @@
1
+ import { r as ReferentialAction } from "./foreign-key-BATxB95l.mjs";
2
+ import { m as StorageTable, n as SqlNamespaceTablesInput, t as SqlNamespace } from "./sql-storage-CXf9xjAL.mjs";
3
+ import { Namespace, NamespaceBase, StorageType } from "@prisma-next/framework-components/ir";
4
+ import { ControlPolicy } from "@prisma-next/contract/types";
5
+ import { CodecTrait } from "@prisma-next/framework-components/codec";
6
+ import { ControlDriverInstance } from "@prisma-next/framework-components/control";
7
+
8
+ //#region src/ir/build-sql-namespace.d.ts
9
+ declare function buildSqlNamespace(input: SqlNamespaceTablesInput): SqlNamespace;
10
+ declare function buildSqlNamespaceMap(namespaces: Readonly<Record<string, Namespace | SqlNamespaceTablesInput>>): Readonly<Record<string, SqlNamespace>>;
11
+ //#endregion
12
+ //#region src/ir/postgres-enum-storage-entry.d.ts
13
+ /**
14
+ * Discriminator literal for the Postgres-enum variant on the polymorphic
15
+ * `SqlStorage.types` slot.
16
+ *
17
+ * Enums are a target-level concept: Postgres ships native
18
+ * `CREATE TYPE … AS ENUM` while other SQL targets approximate enums via
19
+ * constraints. The literal lives at the SQL family layer because every
20
+ * SQL-family consumer (verifier, planner, lowering, …) needs to
21
+ * discriminate enum-typed slot entries from codec-typed ones. The
22
+ * concrete IR class (`PostgresEnumType`) lives in the target-postgres
23
+ * package and implements this structural contract; cross-domain
24
+ * layering rules forbid the SQL family from importing the concrete
25
+ * target class directly, so the discriminator and structural interface
26
+ * carry the dispatch.
27
+ */
28
+ declare const POSTGRES_ENUM_KIND: "postgres-enum";
29
+ /**
30
+ * Structural contract every Postgres-enum slot entry honours — both
31
+ * the live `PostgresEnumType` IR-class instance and the raw JSON
32
+ * envelope shape that survives `JSON.stringify` round-trips. SQL
33
+ * family-layer dispatch narrows polymorphic `StorageType` slot
34
+ * entries to this shape via `isPostgresEnumStorageEntry`.
35
+ *
36
+ * The `codecBinding` field is accessor-shaped (live class instance) on
37
+ * the IR class and undefined on the raw JSON envelope; consumers that
38
+ * need it must guard for its presence (the JSON path synthesises an
39
+ * equivalent shape from `codecId` + `values`).
40
+ */
41
+ interface PostgresEnumStorageEntry extends StorageType {
42
+ readonly kind: typeof POSTGRES_ENUM_KIND;
43
+ readonly name: string;
44
+ readonly nativeType: string;
45
+ readonly values: readonly string[];
46
+ /**
47
+ * Enumerable own property on the persisted JSON envelope; the live
48
+ * IR-class instance carries it too. Family-shared dispatch sites
49
+ * read `codecId` directly rather than going through the IR-class
50
+ * `codecBinding` accessor (which lives on the prototype and isn't
51
+ * present on raw JSON envelopes).
52
+ */
53
+ readonly codecId: string;
54
+ readonly control?: ControlPolicy;
55
+ }
56
+ /**
57
+ * Narrow a polymorphic `StorageType` entry to the Postgres-enum shape
58
+ * via its enumerable `kind` discriminator. Type guard returns true for
59
+ * both live `PostgresEnumType` instances and raw JSON envelopes.
60
+ */
61
+ declare function isPostgresEnumStorageEntry(value: unknown): value is PostgresEnumStorageEntry;
62
+ //#endregion
63
+ //#region src/ir/sql-unbound-namespace.d.ts
64
+ /**
65
+ * Family-layer placeholder for the SQL unbound-namespace singleton —
66
+ * the late-bound slot whose binding the target resolves at connection
67
+ * time rather than at authoring time.
68
+ *
69
+ * SQL contracts honour the framework `Storage.namespaces` invariant from
70
+ * the moment they appear in the IR. Today `SqlStorage` is family-shared
71
+ * (Postgres + SQLite consume the same class); a per-target namespace
72
+ * concretion (`PostgresSchema.unbound`, `SqliteUnboundDatabase.instance`)
73
+ * earns its existence when each target's namespace shape lands. Until
74
+ * then the family ships a single placeholder singleton so the JSON
75
+ * envelope and runtime walk are honest at every layer.
76
+ *
77
+ * The `kind` discriminator is installed as a non-enumerable own property
78
+ * so the JSON envelope reads `{ "id": "__unbound__", "entries": { … } }`
79
+ * — symmetric with the family-level non-enumerable `kind` on `SqlNode`
80
+ * and bounded to the minimum data the framework `Namespace` interface
81
+ * promises.
82
+ *
83
+ * **Freeze-trap warning.** The leaf constructor calls
84
+ * `freezeNode(this)` after installing `kind`. The leaf-class shape
85
+ * works today only because `NamespaceBase` does NOT freeze in its
86
+ * constructor — the `Object.defineProperty(this, 'kind', …)` call after
87
+ * `super()` succeeds because the instance is still mutable at that
88
+ * point. Subclasses that add instance fields will still hit the freeze
89
+ * trap once leaf-class `freezeNode(this)` runs; and if a future
90
+ * framework change lifts the freeze to `NamespaceBase`, even the
91
+ * `defineProperty` here would silently fail. To add subclass instance
92
+ * fields safely, lift `freezeNode` to a leaf-class `seal()` hook each
93
+ * leaf calls explicitly at the end of its own constructor.
94
+ */
95
+ declare class SqlUnboundNamespace extends NamespaceBase {
96
+ static readonly instance: SqlUnboundNamespace;
97
+ readonly id: "__unbound__";
98
+ readonly entries: Readonly<{
99
+ readonly table: Readonly<Record<string, StorageTable>>;
100
+ }>;
101
+ readonly kind: string;
102
+ private constructor();
103
+ qualifyTable(tableName: string): string;
104
+ }
105
+ //#endregion
106
+ //#region src/types.d.ts
107
+ interface SqlControlDriverInstance<T extends string = string> extends ControlDriverInstance<'sql', T> {
108
+ query<Row = Record<string, unknown>>(sql: string, params?: readonly unknown[]): Promise<{
109
+ readonly rows: Row[];
110
+ }>;
111
+ }
112
+ type ForeignKeyOptions = {
113
+ readonly name?: string;
114
+ readonly onDelete?: ReferentialAction;
115
+ readonly onUpdate?: ReferentialAction;
116
+ };
117
+ type SqlModelFieldStorage = {
118
+ readonly column: string;
119
+ readonly codecId?: string;
120
+ readonly nullable?: boolean;
121
+ };
122
+ type SqlModelStorage = {
123
+ readonly table: string;
124
+ readonly namespaceId: string;
125
+ readonly fields: Record<string, SqlModelFieldStorage>;
126
+ };
127
+ declare const DEFAULT_FK_CONSTRAINT = true;
128
+ declare const DEFAULT_FK_INDEX = true;
129
+ declare function applyFkDefaults(fk: {
130
+ constraint?: boolean | undefined;
131
+ index?: boolean | undefined;
132
+ }, overrideDefaults?: {
133
+ constraint?: boolean | undefined;
134
+ index?: boolean | undefined;
135
+ }): {
136
+ constraint: boolean;
137
+ index: boolean;
138
+ };
139
+ type TypeMaps<TCodecTypes extends Record<string, {
140
+ output: unknown;
141
+ }> = Record<string, never>, TQueryOperationTypes extends Record<string, unknown> = Record<string, never>, TFieldOutputTypes extends Record<string, Record<string, unknown>> = Record<string, never>, TFieldInputTypes extends Record<string, Record<string, unknown>> = Record<string, never>> = {
142
+ readonly codecTypes: TCodecTypes;
143
+ readonly queryOperationTypes: TQueryOperationTypes;
144
+ readonly fieldOutputTypes: TFieldOutputTypes;
145
+ readonly fieldInputTypes: TFieldInputTypes;
146
+ };
147
+ type CodecTypesOf<T> = [T] extends [never] ? Record<string, never> : T extends {
148
+ readonly codecTypes: infer C;
149
+ } ? C extends Record<string, {
150
+ output: unknown;
151
+ }> ? C : Record<string, never> : Record<string, never>;
152
+ /**
153
+ * Dispatch hint identifying the first-argument target of an operation.
154
+ *
155
+ * Used by ORM column helpers to decide whether an operation is reachable on a
156
+ * field. Either names a concrete codec identity or a set of capability traits
157
+ * that the field's codec must carry.
158
+ */
159
+ type QueryOperationSelfSpec = {
160
+ readonly codecId: string;
161
+ readonly traits?: never;
162
+ } | {
163
+ readonly traits: readonly CodecTrait[];
164
+ readonly codecId?: never;
165
+ };
166
+ /**
167
+ * Structural shape an operation's impl must return: any value carrying a
168
+ * codec-exact `returnType` descriptor. `Expression<T>` (from
169
+ * `@prisma-next/sql-relational-core/expression`, with `T extends ScopeField`)
170
+ * extends this. Trait-targeted returns are deliberately excluded — predicate
171
+ * detection and result decoding both depend on knowing the concrete return
172
+ * codec.
173
+ */
174
+ type QueryOperationReturn = {
175
+ readonly returnType: {
176
+ readonly codecId: string;
177
+ readonly nullable: boolean;
178
+ };
179
+ };
180
+ type QueryOperationTypeEntry = {
181
+ readonly self?: QueryOperationSelfSpec;
182
+ readonly impl: (...args: never[]) => QueryOperationReturn;
183
+ };
184
+ type SqlQueryOperationTypes<_CT extends Record<string, {
185
+ readonly input: unknown;
186
+ readonly output: unknown;
187
+ }>, T extends Record<string, QueryOperationTypeEntry>> = T;
188
+ type QueryOperationTypesBase = Record<string, QueryOperationTypeEntry>;
189
+ type QueryOperationTypesOf<T> = [T] extends [never] ? Record<string, never> : T extends {
190
+ readonly queryOperationTypes: infer Q;
191
+ } ? Q extends Record<string, unknown> ? Q : Record<string, never> : Record<string, never>;
192
+ type TypeMapsPhantomKey = '__@prisma-next/sql-contract/typeMaps@__';
193
+ type ContractWithTypeMaps<TContract, TTypeMaps> = TContract & { readonly [K in TypeMapsPhantomKey]?: TTypeMaps };
194
+ type ExtractTypeMapsFromContract<T> = TypeMapsPhantomKey extends keyof T ? NonNullable<T[TypeMapsPhantomKey & keyof T]> : never;
195
+ type FieldOutputTypesOf<T> = [T] extends [never] ? Record<string, never> : T extends {
196
+ readonly fieldOutputTypes: infer F;
197
+ } ? F extends Record<string, Record<string, unknown>> ? F : Record<string, never> : Record<string, never>;
198
+ type FieldInputTypesOf<T> = [T] extends [never] ? Record<string, never> : T extends {
199
+ readonly fieldInputTypes: infer F;
200
+ } ? F extends Record<string, Record<string, unknown>> ? F : Record<string, never> : Record<string, never>;
201
+ type ExtractCodecTypes<T> = CodecTypesOf<ExtractTypeMapsFromContract<T>>;
202
+ type ExtractQueryOperationTypes<T> = QueryOperationTypesOf<ExtractTypeMapsFromContract<T>>;
203
+ type ExtractFieldOutputTypes<T> = FieldOutputTypesOf<ExtractTypeMapsFromContract<T>>;
204
+ type ExtractFieldInputTypes<T> = FieldInputTypesOf<ExtractTypeMapsFromContract<T>>;
205
+ type ResolveCodecTypes<TContract, TTypeMaps> = [TTypeMaps] extends [never] ? ExtractCodecTypes<TContract> : CodecTypesOf<TTypeMaps>;
206
+ //#endregion
207
+ export { buildSqlNamespace as A, TypeMaps as C, POSTGRES_ENUM_KIND as D, SqlUnboundNamespace as E, PostgresEnumStorageEntry as O, SqlQueryOperationTypes as S, applyFkDefaults as T, QueryOperationTypesOf as _, ExtractCodecTypes as a, SqlModelFieldStorage as b, ExtractQueryOperationTypes as c, FieldOutputTypesOf as d, ForeignKeyOptions as f, QueryOperationTypesBase as g, QueryOperationTypeEntry as h, DEFAULT_FK_INDEX as i, buildSqlNamespaceMap as j, isPostgresEnumStorageEntry as k, ExtractTypeMapsFromContract as l, QueryOperationSelfSpec as m, ContractWithTypeMaps as n, ExtractFieldInputTypes as o, QueryOperationReturn as p, DEFAULT_FK_CONSTRAINT as r, ExtractFieldOutputTypes as s, CodecTypesOf as t, FieldInputTypesOf as u, ResolveCodecTypes as v, TypeMapsPhantomKey as w, SqlModelStorage as x, SqlControlDriverInstance as y };
208
+ //# sourceMappingURL=types-DEnWD3xB.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types-DEnWD3xB.d.mts","names":[],"sources":["../src/ir/build-sql-namespace.ts","../src/ir/postgres-enum-storage-entry.ts","../src/ir/sql-unbound-namespace.ts","../src/types.ts"],"mappings":";;;;;;;;iBA+EgB,iBAAA,CAAkB,KAAA,EAAO,uBAAA,GAA0B,YAAY;AAAA,iBAI/D,oBAAA,CACd,UAAA,EAAY,QAAA,CAAS,MAAA,SAAe,SAAA,GAAY,uBAAA,KAC/C,QAAA,CAAS,MAAA,SAAe,YAAA;;;;;;;;;AAN3B;;;;;;;;AAA+E;cC7DlE,kBAAA;;;;;;;;;;;;;UAcI,wBAAA,SAAiC,WAAA;EAAA,SACvC,IAAA,SAAa,kBAAA;EAAA,SACb,IAAA;EAAA,SACA,UAAA;EAAA,SACA,MAAA;EDiDC;;;AAA2B;;;;EAA3B,SCzCD,OAAA;EAAA,SACA,OAAA,GAAU,aAAA;AAAA;;AA3BqC;AAc1D;;;iBAqBgB,0BAAA,CAA2B,KA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