@prisma-next/sql-contract 0.12.0-dev.7 → 0.12.0-dev.70
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.
- package/dist/canonicalization-hooks.mjs +10 -5
- package/dist/canonicalization-hooks.mjs.map +1 -1
- package/dist/factories.d.mts +4 -2
- package/dist/factories.d.mts.map +1 -1
- package/dist/factories.mjs +3 -2
- package/dist/factories.mjs.map +1 -1
- package/dist/foreign-key-BATxB95l.d.mts +121 -0
- package/dist/foreign-key-BATxB95l.d.mts.map +1 -0
- package/dist/index-type-validation.d.mts +2 -2
- package/dist/index-type-validation.mjs +1 -1
- package/dist/index-type-validation.mjs.map +1 -1
- package/dist/{index-types-B1cf5N0F.d.mts → index-types-Czsyu7Iw.d.mts} +1 -1
- package/dist/{index-types-B1cf5N0F.d.mts.map → index-types-Czsyu7Iw.d.mts.map} +1 -1
- package/dist/index-types.d.mts +1 -1
- package/dist/pack-types.d.mts +1 -1
- package/dist/referential-action-sql.d.mts +12 -0
- package/dist/referential-action-sql.d.mts.map +1 -0
- package/dist/referential-action-sql.mjs +17 -0
- package/dist/referential-action-sql.mjs.map +1 -0
- package/dist/resolve-storage-table.d.mts +17 -0
- package/dist/resolve-storage-table.d.mts.map +1 -0
- package/dist/resolve-storage-table.mjs +26 -0
- package/dist/resolve-storage-table.mjs.map +1 -0
- package/dist/sql-storage-BQDI6Xrg.d.mts +312 -0
- package/dist/sql-storage-BQDI6Xrg.d.mts.map +1 -0
- package/dist/{types-YQrDHy-b.mjs → types-BulBf1Cm.mjs} +102 -26
- package/dist/types-BulBf1Cm.mjs.map +1 -0
- package/dist/types-CMsiBhc7.d.mts +208 -0
- package/dist/types-CMsiBhc7.d.mts.map +1 -0
- package/dist/types.d.mts +4 -2
- package/dist/types.mjs +2 -2
- package/dist/validators.d.mts +50 -14
- package/dist/validators.d.mts.map +1 -1
- package/dist/validators.mjs +87 -25
- package/dist/validators.mjs.map +1 -1
- package/package.json +11 -9
- package/src/canonicalization-hooks.ts +5 -5
- package/src/exports/referential-action-sql.ts +1 -0
- package/src/exports/resolve-storage-table.ts +1 -0
- package/src/exports/types.ts +6 -0
- package/src/factories.ts +2 -1
- package/src/index-type-validation.ts +1 -1
- package/src/ir/build-sql-namespace.ts +33 -19
- package/src/ir/check-constraint.ts +42 -0
- package/src/ir/foreign-key-reference.ts +23 -0
- package/src/ir/sql-storage.ts +44 -50
- package/src/ir/sql-unbound-namespace.ts +11 -4
- package/src/ir/storage-column.ts +4 -1
- package/src/ir/storage-table.ts +6 -0
- package/src/ir/storage-value-set.ts +42 -0
- package/src/referential-action-sql.ts +14 -0
- package/src/resolve-storage-table.ts +41 -0
- package/src/types.ts +13 -0
- package/src/validators.ts +122 -40
- package/dist/types-Cx_5A_L0.d.mts +0 -513
- package/dist/types-Cx_5A_L0.d.mts.map +0 -1
- package/dist/types-YQrDHy-b.mjs.map +0 -1
|
@@ -0,0 +1,312 @@
|
|
|
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
|
+
*/
|
|
195
|
+
interface StorageTypeInstanceInput {
|
|
196
|
+
readonly codecId: string;
|
|
197
|
+
readonly nativeType: string;
|
|
198
|
+
readonly typeParams: Record<string, unknown>;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Stamp the codec-instance `kind` discriminator on a caller-supplied
|
|
202
|
+
* codec triple. Idempotent: input that already carries the discriminator
|
|
203
|
+
* passes through unchanged.
|
|
204
|
+
*/
|
|
205
|
+
declare function toStorageTypeInstance(input: StorageTypeInstanceInput): StorageTypeInstance;
|
|
206
|
+
/**
|
|
207
|
+
* Type-guard for codec-typed entries on the polymorphic
|
|
208
|
+
* `SqlStorage.types` slot. Distinguishes `StorageTypeInstance` from
|
|
209
|
+
* class-instance kinds (e.g. `PostgresEnumType`).
|
|
210
|
+
*/
|
|
211
|
+
declare function isStorageTypeInstance(value: unknown): value is StorageTypeInstance;
|
|
212
|
+
//#endregion
|
|
213
|
+
//#region src/ir/storage-value-set.d.ts
|
|
214
|
+
/**
|
|
215
|
+
* Hydration / construction input shape for {@link StorageValueSet}.
|
|
216
|
+
* Mirrors the on-disk storage JSON envelope so the serializer hydration
|
|
217
|
+
* walker can hand a validated literal straight to `new`.
|
|
218
|
+
*/
|
|
219
|
+
interface StorageValueSetInput {
|
|
220
|
+
readonly kind: 'value-set';
|
|
221
|
+
/** Ordered permitted values, codec-encoded. Declaration order is preserved. */
|
|
222
|
+
readonly values: readonly string[];
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* SQL Contract IR node for a value-set entry in a namespace's `valueSet`
|
|
226
|
+
* map (`SqlNamespace.entries.valueSet`).
|
|
227
|
+
*
|
|
228
|
+
* A value-set records the ordered set of permitted codec-encoded values for
|
|
229
|
+
* an enum-like column restriction. It does not carry a `codecId` — the
|
|
230
|
+
* column that references it already holds the codec; the value-set holds
|
|
231
|
+
* only the permitted values.
|
|
232
|
+
*
|
|
233
|
+
* The node's `kind` is enumerable (`'value-set'`) so the JSON envelope
|
|
234
|
+
* carries the discriminator and the serializer hydration walker can
|
|
235
|
+
* dispatch on it. This follows the per-leaf enumerable-kind convention
|
|
236
|
+
* established in the SQL-node comment (future polymorphic dispatch on
|
|
237
|
+
* namespace entries needs the discriminator in JSON).
|
|
238
|
+
*
|
|
239
|
+
* The entry's name is not on the class — value-sets are keyed by name in
|
|
240
|
+
* the parent namespace's `valueSet: Record<string, StorageValueSet>` map.
|
|
241
|
+
*/
|
|
242
|
+
declare class StorageValueSet extends SqlNode {
|
|
243
|
+
readonly kind: "value-set";
|
|
244
|
+
readonly values: readonly string[];
|
|
245
|
+
constructor(input: StorageValueSetInput);
|
|
246
|
+
}
|
|
247
|
+
//#endregion
|
|
248
|
+
//#region src/ir/sql-storage.d.ts
|
|
249
|
+
/**
|
|
250
|
+
* Polymorphic value type for document-scoped `SqlStorage.types` entries
|
|
251
|
+
* (codec aliases / parameterised native type registrations).
|
|
252
|
+
*
|
|
253
|
+
* Postgres native enum registrations live under the postgres-specific
|
|
254
|
+
* `entries.type` slot on `PostgresSchema` (target layer), not here.
|
|
255
|
+
*/
|
|
256
|
+
type SqlStorageTypeEntry = StorageTypeInstance | StorageTypeInstanceInput;
|
|
257
|
+
interface SqlNamespaceTablesInput {
|
|
258
|
+
readonly id: string;
|
|
259
|
+
readonly entries: {
|
|
260
|
+
readonly table: Record<string, StorageTable | StorageTableInput>;
|
|
261
|
+
readonly valueSet?: Record<string, StorageValueSet | StorageValueSetInput>;
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
interface SqlStorageInput<THash extends string = string> {
|
|
265
|
+
readonly storageHash: StorageHashBase<THash>;
|
|
266
|
+
readonly types?: Record<string, SqlStorageTypeEntry>;
|
|
267
|
+
readonly namespaces: Readonly<Record<string, SqlNamespace>>;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* SQL Contract IR root node for the `storage` field.
|
|
271
|
+
*
|
|
272
|
+
* Single concrete family-shared class — both Postgres and SQLite
|
|
273
|
+
* consume this class today. Per-target storage subclasses are
|
|
274
|
+
* introduced when each target's namespace shape earns its
|
|
275
|
+
* target-specific concretion (target-specific derived fields,
|
|
276
|
+
* target-specific storage extensions).
|
|
277
|
+
*
|
|
278
|
+
* Honours the framework `Storage` interface: every SQL IR carries a
|
|
279
|
+
* `namespaces` map keyed by namespace id. Callers must supply fully
|
|
280
|
+
* constructed `Namespace` instances — construction discipline lives
|
|
281
|
+
* in the authoring builders and deserializer hydration paths.
|
|
282
|
+
*
|
|
283
|
+
* The constructor normalises optional `types` into class instances.
|
|
284
|
+
* `types` is polymorphic per Decision 18 Option B: codec-triple inputs
|
|
285
|
+
* are stamped with `kind: 'codec-instance'`; hydration of raw JSON
|
|
286
|
+
* class-instance entries (carrying their narrower `kind` literal) is
|
|
287
|
+
* the per-target serializer's responsibility (so the family base does
|
|
288
|
+
* not import target-specific subclasses).
|
|
289
|
+
*/
|
|
290
|
+
type SqlNamespace = Namespace & {
|
|
291
|
+
readonly entries: Readonly<{
|
|
292
|
+
readonly table: Readonly<Record<string, StorageTable>>;
|
|
293
|
+
readonly valueSet?: Readonly<Record<string, StorageValueSet>>;
|
|
294
|
+
}>;
|
|
295
|
+
/**
|
|
296
|
+
* Render a dialect-qualified table reference for runtime SQL emission.
|
|
297
|
+
* Present on materialised target concretions (`PostgresSchema`,
|
|
298
|
+
* `SqliteDatabase`, …) and family placeholders; omitted on emitted
|
|
299
|
+
* contract structural namespace literals (methods are not serialised).
|
|
300
|
+
*/
|
|
301
|
+
qualifyTable?(tableName: string): string;
|
|
302
|
+
};
|
|
303
|
+
declare class SqlStorage<THash extends string = string> extends SqlNode implements Storage {
|
|
304
|
+
readonly storageHash: StorageHashBase<THash>;
|
|
305
|
+
readonly namespaces: Readonly<Record<string, SqlNamespace>>;
|
|
306
|
+
readonly types?: Readonly<Record<string, StorageTypeInstance>>;
|
|
307
|
+
constructor(input: SqlStorageInput<THash>);
|
|
308
|
+
}
|
|
309
|
+
declare function storageTableAt(storage: SqlStorage, namespaceId: string, tableName: string): StorageTable | undefined;
|
|
310
|
+
//#endregion
|
|
311
|
+
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 };
|
|
312
|
+
//# sourceMappingURL=sql-storage-BQDI6Xrg.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sql-storage-BQDI6Xrg.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,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AAA;;;;;;;;;;KClBT,mBAAA,GAAsB,mBAAA,GAAsB,wBAAwB;AAAA,UAE/D,uBAAA;EAAA,SACN,EAAA;EAAA,SACA,OAAA;IAAA,SACE,KAAA,EAAO,MAAA,SAAe,YAAA,GAAe,iBAAA;IAAA,SACrC,QAAA,GAAW,MAAA,SAAe,eAAA,GAAkB,oBAAA;EAAA;AAAA;AAAA,UAIxC,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;;;;;;;ARGN;;;;AC/BzC;;;;AAEe;AAMf;;;;;;KOkDY,YAAA,GAAe,SAAA;EAAA,SAChB,OAAA,EAAS,QAAA;IAAA,SACP,KAAA,EAAO,QAAA,CAAS,MAAA,SAAe,YAAA;IAAA,SAC/B,QAAA,GAAW,QAAA,CAAS,MAAA,SAAe,eAAA;EAAA;EPjDZ;;;;ACZpC;;EMqEE,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;AAAA,iBAerB,cAAA,CACd,OAAA,EAAS,UAAA,EACT,WAAA,UACA,SAAA,WACC,YAAY"}
|
|
@@ -16,9 +16,10 @@ import { asNamespaceId } from "@prisma-next/contract/types";
|
|
|
16
16
|
* envelope and runtime walk are honest at every layer.
|
|
17
17
|
*
|
|
18
18
|
* The `kind` discriminator is installed as a non-enumerable own property
|
|
19
|
-
* so the JSON envelope reads `{ "id": "__unbound__" }`
|
|
20
|
-
* with the family-level non-enumerable `kind` on `SqlNode`
|
|
21
|
-
* to the minimum data the framework `Namespace` interface
|
|
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.
|
|
22
23
|
*
|
|
23
24
|
* **Freeze-trap warning.** The leaf constructor calls
|
|
24
25
|
* `freezeNode(this)` after installing `kind`. The leaf-class shape
|
|
@@ -35,7 +36,7 @@ import { asNamespaceId } from "@prisma-next/contract/types";
|
|
|
35
36
|
var SqlUnboundNamespace = class SqlUnboundNamespace extends NamespaceBase {
|
|
36
37
|
static instance = new SqlUnboundNamespace();
|
|
37
38
|
id = UNBOUND_NAMESPACE_ID;
|
|
38
|
-
|
|
39
|
+
entries = Object.freeze({ table: Object.freeze({}) });
|
|
39
40
|
constructor() {
|
|
40
41
|
super();
|
|
41
42
|
Object.defineProperty(this, "kind", {
|
|
@@ -46,6 +47,9 @@ var SqlUnboundNamespace = class SqlUnboundNamespace extends NamespaceBase {
|
|
|
46
47
|
});
|
|
47
48
|
freezeNode(this);
|
|
48
49
|
}
|
|
50
|
+
qualifyTable(tableName) {
|
|
51
|
+
return `"${tableName}"`;
|
|
52
|
+
}
|
|
49
53
|
};
|
|
50
54
|
//#endregion
|
|
51
55
|
//#region src/ir/sql-node.ts
|
|
@@ -94,11 +98,48 @@ var SqlNode = class extends IRNodeBase {
|
|
|
94
98
|
}
|
|
95
99
|
};
|
|
96
100
|
//#endregion
|
|
101
|
+
//#region src/ir/check-constraint.ts
|
|
102
|
+
/**
|
|
103
|
+
* SQL Contract IR node for a table-level check constraint that restricts
|
|
104
|
+
* a column to the permitted values of a value-set.
|
|
105
|
+
*
|
|
106
|
+
* The constraint is **structured** (names a column and a value-set
|
|
107
|
+
* reference), not a raw SQL expression. Each target renders its own DDL
|
|
108
|
+
* from the structured form, keeping the contract target-agnostic.
|
|
109
|
+
*
|
|
110
|
+
* Construction is idempotent: passing an existing `CheckConstraint`
|
|
111
|
+
* instance as input produces a new instance with identical fields.
|
|
112
|
+
* The constructor does not use `instanceof` for input discrimination —
|
|
113
|
+
* it reads plain named properties, which is sufficient since
|
|
114
|
+
* `CheckConstraintInput` is a structural type.
|
|
115
|
+
*/
|
|
116
|
+
var CheckConstraint = class extends SqlNode {
|
|
117
|
+
name;
|
|
118
|
+
column;
|
|
119
|
+
valueSet;
|
|
120
|
+
constructor(input) {
|
|
121
|
+
super();
|
|
122
|
+
this.name = input.name;
|
|
123
|
+
this.column = input.column;
|
|
124
|
+
this.valueSet = input.valueSet;
|
|
125
|
+
freezeNode(this);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
//#endregion
|
|
97
129
|
//#region src/ir/foreign-key-reference.ts
|
|
98
130
|
/**
|
|
99
131
|
* SQL Contract IR node for one side (source or target) of a foreign-key
|
|
100
132
|
* declaration. Carries the full coordinate: namespace, table, and columns.
|
|
101
133
|
*
|
|
134
|
+
* Cross-space discrimination is based on `spaceId` presence: absent means
|
|
135
|
+
* local (same contract-space); present means cross-space (the referenced
|
|
136
|
+
* table lives in the contract-space identified by `spaceId`).
|
|
137
|
+
*
|
|
138
|
+
* For local references `spaceId` is absent from JSON, keeping the serialized
|
|
139
|
+
* shape byte-identical to contracts authored before cross-space support was
|
|
140
|
+
* added. For cross-space references `spaceId` appears in JSON so round-trips
|
|
141
|
+
* are lossless.
|
|
142
|
+
*
|
|
102
143
|
* Use `UNBOUND_NAMESPACE_ID` from `@prisma-next/framework-components/ir`
|
|
103
144
|
* as the sentinel `namespaceId` for single-namespace (unbound) references.
|
|
104
145
|
*/
|
|
@@ -111,6 +152,7 @@ var ForeignKeyReference = class extends SqlNode {
|
|
|
111
152
|
this.namespaceId = asNamespaceId(input.namespaceId);
|
|
112
153
|
this.tableName = input.tableName;
|
|
113
154
|
this.columns = input.columns;
|
|
155
|
+
if (input.spaceId !== void 0) this.spaceId = input.spaceId;
|
|
114
156
|
freezeNode(this);
|
|
115
157
|
}
|
|
116
158
|
};
|
|
@@ -208,6 +250,7 @@ var StorageColumn = class extends SqlNode {
|
|
|
208
250
|
if (input.typeRef !== void 0) this.typeRef = input.typeRef;
|
|
209
251
|
if (input.default !== void 0) this.default = input.default;
|
|
210
252
|
if (input.control !== void 0) this.control = input.control;
|
|
253
|
+
if (input.valueSet !== void 0) this.valueSet = input.valueSet;
|
|
211
254
|
freezeNode(this);
|
|
212
255
|
}
|
|
213
256
|
};
|
|
@@ -252,6 +295,36 @@ var StorageTable = class extends SqlNode {
|
|
|
252
295
|
this.indexes = Object.freeze(input.indexes.map((i) => i instanceof Index ? i : new Index(i)));
|
|
253
296
|
this.foreignKeys = Object.freeze(input.foreignKeys.map((fk) => fk instanceof ForeignKey ? fk : new ForeignKey(fk)));
|
|
254
297
|
if (input.control !== void 0) this.control = input.control;
|
|
298
|
+
if (input.checks !== void 0 && input.checks.length > 0) this.checks = Object.freeze(input.checks.map((cc) => new CheckConstraint(cc)));
|
|
299
|
+
freezeNode(this);
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
//#endregion
|
|
303
|
+
//#region src/ir/storage-value-set.ts
|
|
304
|
+
/**
|
|
305
|
+
* SQL Contract IR node for a value-set entry in a namespace's `valueSet`
|
|
306
|
+
* map (`SqlNamespace.entries.valueSet`).
|
|
307
|
+
*
|
|
308
|
+
* A value-set records the ordered set of permitted codec-encoded values for
|
|
309
|
+
* an enum-like column restriction. It does not carry a `codecId` — the
|
|
310
|
+
* column that references it already holds the codec; the value-set holds
|
|
311
|
+
* only the permitted values.
|
|
312
|
+
*
|
|
313
|
+
* The node's `kind` is enumerable (`'value-set'`) so the JSON envelope
|
|
314
|
+
* carries the discriminator and the serializer hydration walker can
|
|
315
|
+
* dispatch on it. This follows the per-leaf enumerable-kind convention
|
|
316
|
+
* established in the SQL-node comment (future polymorphic dispatch on
|
|
317
|
+
* namespace entries needs the discriminator in JSON).
|
|
318
|
+
*
|
|
319
|
+
* The entry's name is not on the class — value-sets are keyed by name in
|
|
320
|
+
* the parent namespace's `valueSet: Record<string, StorageValueSet>` map.
|
|
321
|
+
*/
|
|
322
|
+
var StorageValueSet = class extends SqlNode {
|
|
323
|
+
kind = "value-set";
|
|
324
|
+
values;
|
|
325
|
+
constructor(input) {
|
|
326
|
+
super();
|
|
327
|
+
this.values = Object.freeze([...input.values]);
|
|
255
328
|
freezeNode(this);
|
|
256
329
|
}
|
|
257
330
|
};
|
|
@@ -266,23 +339,24 @@ function isMaterializedSqlNamespace(ns) {
|
|
|
266
339
|
}
|
|
267
340
|
var SqlBoundNamespace = class SqlBoundNamespace extends NamespaceBase {
|
|
268
341
|
id;
|
|
269
|
-
|
|
342
|
+
entries;
|
|
270
343
|
static fromTablesInput(input) {
|
|
271
|
-
const tableCount = Object.keys(input.
|
|
272
|
-
const
|
|
273
|
-
if (input.id === UNBOUND_NAMESPACE_ID && tableCount === 0 &&
|
|
344
|
+
const tableCount = Object.keys(input.entries.table).length;
|
|
345
|
+
const hasValueSets = input.entries.valueSet !== void 0 && Object.keys(input.entries.valueSet).length > 0;
|
|
346
|
+
if (input.id === UNBOUND_NAMESPACE_ID && tableCount === 0 && !hasValueSets) return castAs(SqlUnboundNamespace.instance);
|
|
274
347
|
return castAs(new SqlBoundNamespace(input));
|
|
275
348
|
}
|
|
276
349
|
constructor(input) {
|
|
277
350
|
super();
|
|
278
351
|
this.id = input.id;
|
|
279
|
-
|
|
280
|
-
if (input.
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
352
|
+
const table = Object.freeze(Object.fromEntries(Object.entries(input.entries.table).map(([k, v]) => [k, new StorageTable(v)])));
|
|
353
|
+
if (input.entries.valueSet !== void 0) {
|
|
354
|
+
const valueSet = Object.freeze(Object.fromEntries(Object.entries(input.entries.valueSet).map(([k, v]) => [k, new StorageValueSet(v)])));
|
|
355
|
+
this.entries = Object.freeze({
|
|
356
|
+
table,
|
|
357
|
+
valueSet
|
|
358
|
+
});
|
|
359
|
+
} else this.entries = Object.freeze({ table });
|
|
286
360
|
Object.defineProperty(this, "kind", {
|
|
287
361
|
value: SQL_NAMESPACE_KIND,
|
|
288
362
|
writable: false,
|
|
@@ -291,12 +365,16 @@ var SqlBoundNamespace = class SqlBoundNamespace extends NamespaceBase {
|
|
|
291
365
|
});
|
|
292
366
|
freezeNode(this);
|
|
293
367
|
}
|
|
368
|
+
qualifyTable(tableName) {
|
|
369
|
+
if (this.id === UNBOUND_NAMESPACE_ID) return `"${tableName}"`;
|
|
370
|
+
return `"${this.id}"."${tableName}"`;
|
|
371
|
+
}
|
|
294
372
|
};
|
|
295
373
|
function buildSqlNamespace(input) {
|
|
296
374
|
return SqlBoundNamespace.fromTablesInput(input);
|
|
297
375
|
}
|
|
298
376
|
function buildSqlNamespaceMap(namespaces) {
|
|
299
|
-
return Object.fromEntries(Object.entries(namespaces).map(([nsKey, ns]) => [nsKey, isMaterializedSqlNamespace(ns) ? blindCast(ns) : SqlBoundNamespace.fromTablesInput(ns)]));
|
|
377
|
+
return Object.fromEntries(Object.entries(namespaces).map(([nsKey, ns]) => [nsKey, isMaterializedSqlNamespace(ns) ? blindCast(ns) : SqlBoundNamespace.fromTablesInput(blindCast(ns))]));
|
|
300
378
|
}
|
|
301
379
|
//#endregion
|
|
302
380
|
//#region src/ir/postgres-enum-storage-entry.ts
|
|
@@ -370,11 +448,13 @@ var SqlStorage = class extends SqlNode {
|
|
|
370
448
|
freezeNode(this);
|
|
371
449
|
}
|
|
372
450
|
};
|
|
451
|
+
function storageTableAt(storage, namespaceId, tableName) {
|
|
452
|
+
return storage.namespaces[namespaceId]?.entries.table[tableName];
|
|
453
|
+
}
|
|
373
454
|
/**
|
|
374
455
|
* Strict polymorphic-slot dispatch for `SqlStorage.types` entries.
|
|
375
|
-
* Every entry must carry a
|
|
376
|
-
*
|
|
377
|
-
* `'postgres-enum'` (target-specific IR class). Untagged or
|
|
456
|
+
* Every entry must carry a `kind: 'codec-instance'` discriminator or
|
|
457
|
+
* be an already-constructed `StorageTypeInstance`. Untagged or
|
|
378
458
|
* unrecognised inputs throw a diagnostic naming the entry and its
|
|
379
459
|
* `kind`, so format drift surfaces loudly at the deserializer
|
|
380
460
|
* boundary instead of slipping past the seam and corrupting
|
|
@@ -388,14 +468,10 @@ var SqlStorage = class extends SqlNode {
|
|
|
388
468
|
* only fires for in-memory authoring bugs.
|
|
389
469
|
*/
|
|
390
470
|
function normaliseTypeEntry(name, entry) {
|
|
391
|
-
if (isPostgresEnumStorageEntry(entry)) {
|
|
392
|
-
if (entry instanceof SqlNode) return entry;
|
|
393
|
-
throw new Error(`Encountered raw postgres-enum JSON in storage.types[${JSON.stringify(name)}] without serializer hydration; use a target ContractSerializer that registers the matching entity-type factory.`);
|
|
394
|
-
}
|
|
395
471
|
if (isStorageTypeInstance(entry)) return entry;
|
|
396
472
|
const rawKind = entry.kind;
|
|
397
473
|
const kindDescription = rawKind === void 0 ? "missing `kind` discriminator" : `unrecognised \`kind\` discriminator ${JSON.stringify(rawKind)}`;
|
|
398
|
-
throw new Error(`storage.types[${JSON.stringify(name)}] has ${kindDescription}; expected ${JSON.stringify("codec-instance")}
|
|
474
|
+
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.`);
|
|
399
475
|
}
|
|
400
476
|
//#endregion
|
|
401
477
|
//#region src/types.ts
|
|
@@ -408,6 +484,6 @@ function applyFkDefaults(fk, overrideDefaults) {
|
|
|
408
484
|
};
|
|
409
485
|
}
|
|
410
486
|
//#endregion
|
|
411
|
-
export {
|
|
487
|
+
export { SqlUnboundNamespace as C, SqlNode as S, Index as _, storageTableAt as a, ForeignKeyReference as b, toStorageTypeInstance as c, buildSqlNamespace as d, buildSqlNamespaceMap as f, StorageColumn as g, UniqueConstraint as h, SqlStorage as i, POSTGRES_ENUM_KIND as l, StorageTable as m, DEFAULT_FK_INDEX as n, CODEC_INSTANCE_KIND as o, StorageValueSet as p, applyFkDefaults as r, isStorageTypeInstance as s, DEFAULT_FK_CONSTRAINT as t, isPostgresEnumStorageEntry as u, PrimaryKey as v, CheckConstraint as x, ForeignKey as y };
|
|
412
488
|
|
|
413
|
-
//# sourceMappingURL=types-
|
|
489
|
+
//# sourceMappingURL=types-BulBf1Cm.mjs.map
|