@prisma-next/sql-contract 0.8.0 → 0.9.0-dev.1
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/README.md +13 -11
- package/dist/factories.d.mts +2 -2
- package/dist/factories.d.mts.map +1 -1
- package/dist/factories.mjs +16 -14
- package/dist/factories.mjs.map +1 -1
- 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-DqVqGHwg.d.mts → index-types-B1cf5N0F.d.mts} +1 -1
- package/dist/{index-types-DqVqGHwg.d.mts.map → index-types-B1cf5N0F.d.mts.map} +1 -1
- package/dist/index-types.d.mts +1 -1
- package/dist/types-B0lbr9cb.d.mts +498 -0
- package/dist/types-B0lbr9cb.d.mts.map +1 -0
- package/dist/types-iqFGDcJp.mjs +389 -0
- package/dist/types-iqFGDcJp.mjs.map +1 -0
- package/dist/types.d.mts +2 -2
- package/dist/types.mjs +2 -2
- package/dist/validators.d.mts +27 -15
- package/dist/validators.d.mts.map +1 -1
- package/dist/validators.mjs +409 -2
- package/dist/validators.mjs.map +1 -0
- package/package.json +6 -7
- package/src/exports/types.ts +30 -9
- package/src/factories.ts +19 -32
- package/src/index-type-validation.ts +1 -1
- package/src/index.ts +0 -1
- package/src/ir/foreign-key-references.ts +26 -0
- package/src/ir/foreign-key.ts +50 -0
- package/src/ir/postgres-enum-storage-entry.ts +55 -0
- package/src/ir/primary-key.ts +22 -0
- package/src/ir/sql-index.ts +33 -0
- package/src/ir/sql-node.ts +52 -0
- package/src/ir/sql-storage.ts +154 -0
- package/src/ir/sql-unspecified-namespace.ts +51 -0
- package/src/ir/storage-column.ts +55 -0
- package/src/ir/storage-table.ts +63 -0
- package/src/ir/storage-type-instance.ts +60 -0
- package/src/ir/unique-constraint.ts +22 -0
- package/src/types.ts +38 -99
- package/src/validators.ts +268 -28
- package/dist/types-hgzy8ME1.mjs +0 -13
- package/dist/types-hgzy8ME1.mjs.map +0 -1
- package/dist/types-njsiV-Ck.d.mts +0 -186
- package/dist/types-njsiV-Ck.d.mts.map +0 -1
- package/dist/validate.d.mts +0 -9
- package/dist/validate.d.mts.map +0 -1
- package/dist/validate.mjs +0 -106
- package/dist/validate.mjs.map +0 -1
- package/dist/validators-Dm5X-Hvg.mjs +0 -294
- package/dist/validators-Dm5X-Hvg.mjs.map +0 -1
- package/src/exports/validate.ts +0 -1
- package/src/validate.ts +0 -227
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
import { IRNodeBase, NamespaceBase, UNSPECIFIED_NAMESPACE_ID, freezeNode } from "@prisma-next/framework-components/ir";
|
|
2
|
+
//#region src/ir/sql-node.ts
|
|
3
|
+
/**
|
|
4
|
+
* SQL family IR node base. Carries the family-level `kind` discriminator
|
|
5
|
+
* `'sql'` and inherits the framework's `freezeNode` affordance.
|
|
6
|
+
*
|
|
7
|
+
* Single family-level discriminator (not per-leaf) reflects the fact that
|
|
8
|
+
* SQL IR has no polymorphic dispatch today — verifiers and serializers
|
|
9
|
+
* walk by structural position (`storage.tables[name].columns[name]`),
|
|
10
|
+
* not by inspecting `kind`. The abstract bar for per-leaf discriminators
|
|
11
|
+
* isn't earned until a future polymorphic consumer arrives.
|
|
12
|
+
*
|
|
13
|
+
* `kind` is installed as a non-enumerable own property on every instance,
|
|
14
|
+
* which keeps three things clean simultaneously:
|
|
15
|
+
*
|
|
16
|
+
* - `JSON.stringify(node)` produces the canonical pre-lift JSON envelope
|
|
17
|
+
* shape (no `kind` field), so emitted contract.json files and the
|
|
18
|
+
* `validateSqlContractFully` arktype schemas stay unchanged.
|
|
19
|
+
* - Test assertions that use `toEqual({...})` against the pre-lift flat
|
|
20
|
+
* shape continue to pass — only enumerable own properties are
|
|
21
|
+
* compared.
|
|
22
|
+
* - Direct access (`node.kind`) and runtime narrowing
|
|
23
|
+
* (`if (node.kind === 'sql')`) still work, so future polymorphic
|
|
24
|
+
* dispatch can begin reading `kind` without a runtime change.
|
|
25
|
+
*
|
|
26
|
+
* Future per-leaf overrides land cleanly: a class that gains a
|
|
27
|
+
* polymorphic-dispatch consumer (e.g. an enum type instance walked
|
|
28
|
+
* alongside other types) overrides `kind` with its narrower literal
|
|
29
|
+
* at that leaf level. Per-leaf overrides will use enumerable kind
|
|
30
|
+
* (matching the Mongo per-class-discriminator precedent) because they
|
|
31
|
+
* encode dispatch-relevant information that callers need to see in
|
|
32
|
+
* JSON envelopes; the family-level `'sql'` is uniform across all SQL
|
|
33
|
+
* IR and carries no dispatch-relevant information.
|
|
34
|
+
*/
|
|
35
|
+
var SqlNode = class extends IRNodeBase {
|
|
36
|
+
kind;
|
|
37
|
+
constructor() {
|
|
38
|
+
super();
|
|
39
|
+
Object.defineProperty(this, "kind", {
|
|
40
|
+
value: "sql",
|
|
41
|
+
writable: false,
|
|
42
|
+
enumerable: false,
|
|
43
|
+
configurable: true
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/ir/foreign-key-references.ts
|
|
49
|
+
/**
|
|
50
|
+
* SQL Contract IR node for the referenced side of a foreign key.
|
|
51
|
+
*
|
|
52
|
+
* The class is shaped around single-namespace references today; a
|
|
53
|
+
* future milestone introduces a cross-namespace coordinate on top of
|
|
54
|
+
* `(table, columns)` when namespace-keyed storage lands.
|
|
55
|
+
*/
|
|
56
|
+
var ForeignKeyReferences = class extends SqlNode {
|
|
57
|
+
table;
|
|
58
|
+
columns;
|
|
59
|
+
constructor(input) {
|
|
60
|
+
super();
|
|
61
|
+
this.table = input.table;
|
|
62
|
+
this.columns = input.columns;
|
|
63
|
+
freezeNode(this);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region src/ir/foreign-key.ts
|
|
68
|
+
/**
|
|
69
|
+
* SQL Contract IR node for a table-level foreign-key declaration.
|
|
70
|
+
*
|
|
71
|
+
* The nested `references` field is normalised to a
|
|
72
|
+
* {@link ForeignKeyReferences} instance inside the constructor so
|
|
73
|
+
* downstream walks see a uniform AST regardless of whether the input
|
|
74
|
+
* was a JSON literal or an already-constructed class instance.
|
|
75
|
+
*/
|
|
76
|
+
var ForeignKey = class extends SqlNode {
|
|
77
|
+
columns;
|
|
78
|
+
references;
|
|
79
|
+
constraint;
|
|
80
|
+
index;
|
|
81
|
+
constructor(input) {
|
|
82
|
+
super();
|
|
83
|
+
this.columns = input.columns;
|
|
84
|
+
this.references = input.references instanceof ForeignKeyReferences ? input.references : new ForeignKeyReferences(input.references);
|
|
85
|
+
this.constraint = input.constraint;
|
|
86
|
+
this.index = input.index;
|
|
87
|
+
if (input.name !== void 0) this.name = input.name;
|
|
88
|
+
if (input.onDelete !== void 0) this.onDelete = input.onDelete;
|
|
89
|
+
if (input.onUpdate !== void 0) this.onUpdate = input.onUpdate;
|
|
90
|
+
freezeNode(this);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
//#endregion
|
|
94
|
+
//#region src/ir/postgres-enum-storage-entry.ts
|
|
95
|
+
/**
|
|
96
|
+
* Discriminator literal for the Postgres-enum variant on the polymorphic
|
|
97
|
+
* `SqlStorage.types` slot.
|
|
98
|
+
*
|
|
99
|
+
* Enums are a target-level concept: Postgres ships native
|
|
100
|
+
* `CREATE TYPE … AS ENUM` while other SQL targets approximate enums via
|
|
101
|
+
* constraints. The literal lives at the SQL family layer because every
|
|
102
|
+
* SQL-family consumer (verifier, planner, lowering, …) needs to
|
|
103
|
+
* discriminate enum-typed slot entries from codec-typed ones. The
|
|
104
|
+
* concrete IR class (`PostgresEnumType`) lives in the target-postgres
|
|
105
|
+
* package and implements this structural contract; cross-domain
|
|
106
|
+
* layering rules forbid the SQL family from importing the concrete
|
|
107
|
+
* target class directly, so the discriminator and structural interface
|
|
108
|
+
* carry the dispatch.
|
|
109
|
+
*/
|
|
110
|
+
const POSTGRES_ENUM_KIND = "postgres-enum";
|
|
111
|
+
/**
|
|
112
|
+
* Narrow a polymorphic `StorageType` entry to the Postgres-enum shape
|
|
113
|
+
* via its enumerable `kind` discriminator. Type guard returns true for
|
|
114
|
+
* both live `PostgresEnumType` instances and raw JSON envelopes.
|
|
115
|
+
*/
|
|
116
|
+
function isPostgresEnumStorageEntry(value) {
|
|
117
|
+
if (typeof value !== "object" || value === null) return false;
|
|
118
|
+
return value.kind === POSTGRES_ENUM_KIND;
|
|
119
|
+
}
|
|
120
|
+
//#endregion
|
|
121
|
+
//#region src/ir/primary-key.ts
|
|
122
|
+
/**
|
|
123
|
+
* SQL Contract IR node for a table's primary-key constraint.
|
|
124
|
+
*/
|
|
125
|
+
var PrimaryKey = class extends SqlNode {
|
|
126
|
+
columns;
|
|
127
|
+
constructor(input) {
|
|
128
|
+
super();
|
|
129
|
+
this.columns = input.columns;
|
|
130
|
+
if (input.name !== void 0) this.name = input.name;
|
|
131
|
+
freezeNode(this);
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
//#endregion
|
|
135
|
+
//#region src/ir/sql-index.ts
|
|
136
|
+
/**
|
|
137
|
+
* SQL Contract IR node for a table-level secondary index.
|
|
138
|
+
*
|
|
139
|
+
* Note that this class shadows the global TypeScript `Index` lib type
|
|
140
|
+
* at the family-shared name; consumer files that need both should
|
|
141
|
+
* alias one (e.g.
|
|
142
|
+
* `import { Index as SqlIndexNode } from '@prisma-next/sql-contract/types'`).
|
|
143
|
+
*/
|
|
144
|
+
var Index = class extends SqlNode {
|
|
145
|
+
columns;
|
|
146
|
+
constructor(input) {
|
|
147
|
+
super();
|
|
148
|
+
this.columns = input.columns;
|
|
149
|
+
if (input.name !== void 0) this.name = input.name;
|
|
150
|
+
if (input.type !== void 0) this.type = input.type;
|
|
151
|
+
if (input.options !== void 0) this.options = input.options;
|
|
152
|
+
freezeNode(this);
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
//#endregion
|
|
156
|
+
//#region src/ir/sql-unspecified-namespace.ts
|
|
157
|
+
/**
|
|
158
|
+
* Family-layer placeholder for the SQL unspecified-namespace singleton.
|
|
159
|
+
*
|
|
160
|
+
* SQL contracts honour the framework `Storage.namespaces` invariant from
|
|
161
|
+
* the moment they appear in the IR. Today `SqlStorage` is family-shared
|
|
162
|
+
* (Postgres + SQLite consume the same class); a per-target namespace
|
|
163
|
+
* concretion (`PostgresSchema.unspecified`, `SqliteUnspecifiedDatabase.instance`)
|
|
164
|
+
* earns its existence when each target's namespace shape lands. Until
|
|
165
|
+
* then the family ships a single placeholder singleton so the JSON
|
|
166
|
+
* envelope and runtime walk are honest at every layer.
|
|
167
|
+
*
|
|
168
|
+
* The `kind` discriminator is installed as a non-enumerable own property
|
|
169
|
+
* so the JSON envelope reads `{ "id": "__unspecified__" }` — symmetric
|
|
170
|
+
* with the family-level non-enumerable `kind` on `SqlNode` and bounded
|
|
171
|
+
* to the minimum data the framework `Namespace` interface promises.
|
|
172
|
+
*
|
|
173
|
+
* **Freeze-trap warning.** The leaf constructor calls
|
|
174
|
+
* `freezeNode(this)` after installing `kind`. The leaf-class shape
|
|
175
|
+
* works today only because `NamespaceBase` does NOT freeze in its
|
|
176
|
+
* constructor — the `Object.defineProperty(this, 'kind', …)` call after
|
|
177
|
+
* `super()` succeeds because the instance is still mutable at that
|
|
178
|
+
* point. Subclasses that add instance fields will still hit the freeze
|
|
179
|
+
* trap once leaf-class `freezeNode(this)` runs; and if a future
|
|
180
|
+
* framework change lifts the freeze to `NamespaceBase`, even the
|
|
181
|
+
* `defineProperty` here would silently fail. To add subclass instance
|
|
182
|
+
* fields safely, lift `freezeNode` to a leaf-class `seal()` hook each
|
|
183
|
+
* leaf calls explicitly at the end of its own constructor.
|
|
184
|
+
*/
|
|
185
|
+
var SqlUnspecifiedNamespace = class SqlUnspecifiedNamespace extends NamespaceBase {
|
|
186
|
+
static instance = new SqlUnspecifiedNamespace();
|
|
187
|
+
id = UNSPECIFIED_NAMESPACE_ID;
|
|
188
|
+
constructor() {
|
|
189
|
+
super();
|
|
190
|
+
Object.defineProperty(this, "kind", {
|
|
191
|
+
value: "sql-namespace",
|
|
192
|
+
writable: false,
|
|
193
|
+
enumerable: false,
|
|
194
|
+
configurable: true
|
|
195
|
+
});
|
|
196
|
+
freezeNode(this);
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
//#endregion
|
|
200
|
+
//#region src/ir/storage-column.ts
|
|
201
|
+
/**
|
|
202
|
+
* SQL Contract IR node for a single column entry in `StorageTable.columns`.
|
|
203
|
+
*
|
|
204
|
+
* Single concrete family-shared class — every SQL target reads the
|
|
205
|
+
* same column shape today, so there is no per-target subclass. The
|
|
206
|
+
* class type accepts any caller that constructs via
|
|
207
|
+
* `new StorageColumn(input)`; literal construction sites must pass
|
|
208
|
+
* through the constructor or the family-base hydration walker.
|
|
209
|
+
*
|
|
210
|
+
* The column's `name` is not on the class — columns are keyed by name
|
|
211
|
+
* in the parent `StorageTable.columns: Record<string, StorageColumn>`
|
|
212
|
+
* map, so a `name` field would be redundant with the key.
|
|
213
|
+
*/
|
|
214
|
+
var StorageColumn = class extends SqlNode {
|
|
215
|
+
nativeType;
|
|
216
|
+
codecId;
|
|
217
|
+
nullable;
|
|
218
|
+
constructor(input) {
|
|
219
|
+
super();
|
|
220
|
+
this.nativeType = input.nativeType;
|
|
221
|
+
this.codecId = input.codecId;
|
|
222
|
+
this.nullable = input.nullable;
|
|
223
|
+
if (input.typeParams !== void 0) this.typeParams = input.typeParams;
|
|
224
|
+
if (input.typeRef !== void 0) this.typeRef = input.typeRef;
|
|
225
|
+
if (input.default !== void 0) this.default = input.default;
|
|
226
|
+
freezeNode(this);
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
//#endregion
|
|
230
|
+
//#region src/ir/unique-constraint.ts
|
|
231
|
+
/**
|
|
232
|
+
* SQL Contract IR node for a table-level unique constraint.
|
|
233
|
+
*/
|
|
234
|
+
var UniqueConstraint = class extends SqlNode {
|
|
235
|
+
columns;
|
|
236
|
+
constructor(input) {
|
|
237
|
+
super();
|
|
238
|
+
this.columns = input.columns;
|
|
239
|
+
if (input.name !== void 0) this.name = input.name;
|
|
240
|
+
freezeNode(this);
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
//#endregion
|
|
244
|
+
//#region src/ir/storage-table.ts
|
|
245
|
+
/**
|
|
246
|
+
* SQL Contract IR node for a single table entry in `SqlStorage.tables`.
|
|
247
|
+
*
|
|
248
|
+
* The constructor normalises nested IR-class fields (columns, primary
|
|
249
|
+
* key, uniques, indexes, foreign keys) into the appropriate class
|
|
250
|
+
* instances so downstream walks see a uniform AST regardless of whether
|
|
251
|
+
* the input was a JSON literal or an already-constructed class.
|
|
252
|
+
*
|
|
253
|
+
* The table's `name` is not on the class — tables are keyed by name in
|
|
254
|
+
* the parent `SqlStorage.tables: Record<string, StorageTable>` map.
|
|
255
|
+
* A future namespace-aware milestone will add a `namespaceId` field
|
|
256
|
+
* when namespace-keyed storage lands; today's single-namespace shape
|
|
257
|
+
* needs neither field.
|
|
258
|
+
*/
|
|
259
|
+
var StorageTable = class extends SqlNode {
|
|
260
|
+
columns;
|
|
261
|
+
uniques;
|
|
262
|
+
indexes;
|
|
263
|
+
foreignKeys;
|
|
264
|
+
constructor(input) {
|
|
265
|
+
super();
|
|
266
|
+
this.columns = Object.freeze(Object.fromEntries(Object.entries(input.columns).map(([name, col]) => [name, col instanceof StorageColumn ? col : new StorageColumn(col)])));
|
|
267
|
+
if (input.primaryKey !== void 0) this.primaryKey = input.primaryKey instanceof PrimaryKey ? input.primaryKey : new PrimaryKey(input.primaryKey);
|
|
268
|
+
this.uniques = Object.freeze(input.uniques.map((u) => u instanceof UniqueConstraint ? u : new UniqueConstraint(u)));
|
|
269
|
+
this.indexes = Object.freeze(input.indexes.map((i) => i instanceof Index ? i : new Index(i)));
|
|
270
|
+
this.foreignKeys = Object.freeze(input.foreignKeys.map((fk) => fk instanceof ForeignKey ? fk : new ForeignKey(fk)));
|
|
271
|
+
freezeNode(this);
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
//#endregion
|
|
275
|
+
//#region src/ir/storage-type-instance.ts
|
|
276
|
+
/**
|
|
277
|
+
* Sentinel kind for the legacy codec-triple shape persisted under
|
|
278
|
+
* `SqlStorage.types`. Plain JSON-clean object literals carry this
|
|
279
|
+
* discriminator so the polymorphic slot dispatch can route them down
|
|
280
|
+
* the codec path while target-specific IR class instances (e.g. the
|
|
281
|
+
* Postgres enum class) keep their own narrower `kind` literal.
|
|
282
|
+
*/
|
|
283
|
+
const CODEC_INSTANCE_KIND = "codec-instance";
|
|
284
|
+
/**
|
|
285
|
+
* Stamp the codec-instance `kind` discriminator on a caller-supplied
|
|
286
|
+
* codec triple. Idempotent: input that already carries the discriminator
|
|
287
|
+
* passes through unchanged.
|
|
288
|
+
*/
|
|
289
|
+
function toStorageTypeInstance(input) {
|
|
290
|
+
return {
|
|
291
|
+
kind: CODEC_INSTANCE_KIND,
|
|
292
|
+
codecId: input.codecId,
|
|
293
|
+
nativeType: input.nativeType,
|
|
294
|
+
typeParams: input.typeParams
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Type-guard for codec-typed entries on the polymorphic
|
|
299
|
+
* `SqlStorage.types` slot. Distinguishes `StorageTypeInstance` from
|
|
300
|
+
* class-instance kinds (e.g. `PostgresEnumType`).
|
|
301
|
+
*/
|
|
302
|
+
function isStorageTypeInstance(value) {
|
|
303
|
+
if (typeof value !== "object" || value === null) return false;
|
|
304
|
+
return value.kind === CODEC_INSTANCE_KIND;
|
|
305
|
+
}
|
|
306
|
+
//#endregion
|
|
307
|
+
//#region src/ir/sql-storage.ts
|
|
308
|
+
const DEFAULT_NAMESPACES = Object.freeze({ [UNSPECIFIED_NAMESPACE_ID]: SqlUnspecifiedNamespace.instance });
|
|
309
|
+
/**
|
|
310
|
+
* SQL Contract IR root node for the `storage` field.
|
|
311
|
+
*
|
|
312
|
+
* Single concrete family-shared class — both Postgres and SQLite
|
|
313
|
+
* consume this same class today. Per-target storage subclasses are
|
|
314
|
+
* introduced when each target's namespace shape earns its
|
|
315
|
+
* target-specific concretion (target-specific derived fields,
|
|
316
|
+
* target-specific storage extensions).
|
|
317
|
+
*
|
|
318
|
+
* Honours the framework `Storage` interface: every SQL IR carries a
|
|
319
|
+
* `namespaces` map keyed by namespace id. The default singleton
|
|
320
|
+
* (`{ [UNSPECIFIED_NAMESPACE_ID]: SqlUnspecifiedNamespace.instance }`)
|
|
321
|
+
* binds every contract authored before per-target namespace concretions
|
|
322
|
+
* land; per-target namespace classes (`PostgresSchema.unspecified`,
|
|
323
|
+
* `SqliteUnspecifiedDatabase.instance`) earn their slots when each
|
|
324
|
+
* target's namespace shape lands.
|
|
325
|
+
*
|
|
326
|
+
* The constructor normalises nested IR-class fields (`tables`, optional
|
|
327
|
+
* `types`) into class instances so downstream walks see a uniform AST.
|
|
328
|
+
* `types` is polymorphic per Decision 18 Option B: codec-triple inputs
|
|
329
|
+
* are stamped with `kind: 'codec-instance'`; class-instance kinds
|
|
330
|
+
* (e.g. Postgres-enum entries satisfying `PostgresEnumStorageEntry`)
|
|
331
|
+
* pass through; hydration of raw JSON class-instance entries (carrying
|
|
332
|
+
* their narrower `kind` literal) is the per-target serializer's
|
|
333
|
+
* responsibility (so the family base does not import target-specific
|
|
334
|
+
* subclasses).
|
|
335
|
+
*/
|
|
336
|
+
var SqlStorage = class extends SqlNode {
|
|
337
|
+
storageHash;
|
|
338
|
+
tables;
|
|
339
|
+
namespaces;
|
|
340
|
+
constructor(input) {
|
|
341
|
+
super();
|
|
342
|
+
this.storageHash = input.storageHash;
|
|
343
|
+
this.tables = Object.freeze(Object.fromEntries(Object.entries(input.tables).map(([name, t]) => [name, t instanceof StorageTable ? t : new StorageTable(t)])));
|
|
344
|
+
this.namespaces = input.namespaces ?? DEFAULT_NAMESPACES;
|
|
345
|
+
if (input.types !== void 0) this.types = Object.freeze(Object.fromEntries(Object.entries(input.types).map(([name, ti]) => [name, normaliseTypeEntry(name, ti)])));
|
|
346
|
+
freezeNode(this);
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
/**
|
|
350
|
+
* Strict polymorphic-slot dispatch for `SqlStorage.types` entries
|
|
351
|
+
* (TML-2536). Every entry must carry a recognised `kind` discriminator
|
|
352
|
+
* — either `'codec-instance'` (codec triple, family-shared) or
|
|
353
|
+
* `'postgres-enum'` (target-specific IR class). Untagged or
|
|
354
|
+
* unrecognised inputs throw a diagnostic naming the entry and its
|
|
355
|
+
* `kind`, so format drift surfaces loudly at the deserializer
|
|
356
|
+
* boundary instead of slipping past the seam and corrupting
|
|
357
|
+
* downstream IR walks.
|
|
358
|
+
*
|
|
359
|
+
* Codec-triple authors that have an untagged shape on hand can call
|
|
360
|
+
* `toStorageTypeInstance(...)` (which stamps the `'codec-instance'`
|
|
361
|
+
* discriminator) before constructing `SqlStorage`. On-disk reads
|
|
362
|
+
* cross `familyInstance.deserializeContract` first; the structural
|
|
363
|
+
* arktype schema rejects untagged entries earlier, so this throw
|
|
364
|
+
* only fires for in-memory authoring bugs.
|
|
365
|
+
*/
|
|
366
|
+
function normaliseTypeEntry(name, entry) {
|
|
367
|
+
if (isPostgresEnumStorageEntry(entry)) {
|
|
368
|
+
if (entry instanceof SqlNode) return entry;
|
|
369
|
+
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.`);
|
|
370
|
+
}
|
|
371
|
+
if (isStorageTypeInstance(entry)) return entry;
|
|
372
|
+
const rawKind = entry.kind;
|
|
373
|
+
const kindDescription = rawKind === void 0 ? "missing `kind` discriminator" : `unrecognised \`kind\` discriminator ${JSON.stringify(rawKind)}`;
|
|
374
|
+
throw new Error(`storage.types[${JSON.stringify(name)}] has ${kindDescription}; expected ${JSON.stringify("codec-instance")} or ${JSON.stringify("postgres-enum")}. Untagged codec triples should be wrapped with toStorageTypeInstance(...) before construction.`);
|
|
375
|
+
}
|
|
376
|
+
//#endregion
|
|
377
|
+
//#region src/types.ts
|
|
378
|
+
const DEFAULT_FK_CONSTRAINT = true;
|
|
379
|
+
const DEFAULT_FK_INDEX = true;
|
|
380
|
+
function applyFkDefaults(fk, overrideDefaults) {
|
|
381
|
+
return {
|
|
382
|
+
constraint: fk.constraint ?? overrideDefaults?.constraint ?? true,
|
|
383
|
+
index: fk.index ?? overrideDefaults?.index ?? true
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
//#endregion
|
|
387
|
+
export { ForeignKeyReferences as _, CODEC_INSTANCE_KIND as a, StorageTable as c, SqlUnspecifiedNamespace as d, Index as f, ForeignKey as g, isPostgresEnumStorageEntry as h, SqlStorage as i, UniqueConstraint as l, POSTGRES_ENUM_KIND as m, DEFAULT_FK_INDEX as n, isStorageTypeInstance as o, PrimaryKey as p, applyFkDefaults as r, toStorageTypeInstance as s, DEFAULT_FK_CONSTRAINT as t, StorageColumn as u, SqlNode as v };
|
|
388
|
+
|
|
389
|
+
//# sourceMappingURL=types-iqFGDcJp.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-iqFGDcJp.mjs","names":[],"sources":["../src/ir/sql-node.ts","../src/ir/foreign-key-references.ts","../src/ir/foreign-key.ts","../src/ir/postgres-enum-storage-entry.ts","../src/ir/primary-key.ts","../src/ir/sql-index.ts","../src/ir/sql-unspecified-namespace.ts","../src/ir/storage-column.ts","../src/ir/unique-constraint.ts","../src/ir/storage-table.ts","../src/ir/storage-type-instance.ts","../src/ir/sql-storage.ts","../src/types.ts"],"sourcesContent":["import { IRNodeBase } from '@prisma-next/framework-components/ir';\n\n/**\n * SQL family IR node base. Carries the family-level `kind` discriminator\n * `'sql'` and inherits the framework's `freezeNode` affordance.\n *\n * Single family-level discriminator (not per-leaf) reflects the fact that\n * SQL IR has no polymorphic dispatch today — verifiers and serializers\n * walk by structural position (`storage.tables[name].columns[name]`),\n * not by inspecting `kind`. The abstract bar for per-leaf discriminators\n * isn't earned until a future polymorphic consumer arrives.\n *\n * `kind` is installed as a non-enumerable own property on every instance,\n * which keeps three things clean simultaneously:\n *\n * - `JSON.stringify(node)` produces the canonical pre-lift JSON envelope\n * shape (no `kind` field), so emitted contract.json files and the\n * `validateSqlContractFully` arktype schemas stay unchanged.\n * - Test assertions that use `toEqual({...})` against the pre-lift flat\n * shape continue to pass — only enumerable own properties are\n * compared.\n * - Direct access (`node.kind`) and runtime narrowing\n * (`if (node.kind === 'sql')`) still work, so future polymorphic\n * dispatch can begin reading `kind` without a runtime change.\n *\n * Future per-leaf overrides land cleanly: a class that gains a\n * polymorphic-dispatch consumer (e.g. an enum type instance walked\n * alongside other types) overrides `kind` with its narrower literal\n * at that leaf level. Per-leaf overrides will use enumerable kind\n * (matching the Mongo per-class-discriminator precedent) because they\n * encode dispatch-relevant information that callers need to see in\n * JSON envelopes; the family-level `'sql'` is uniform across all SQL\n * IR and carries no dispatch-relevant information.\n */\nexport abstract class SqlNode extends IRNodeBase {\n readonly kind?: string;\n\n constructor() {\n super();\n Object.defineProperty(this, 'kind', {\n value: 'sql',\n writable: false,\n enumerable: false,\n // configurable so per-leaf subclasses (e.g. PostgresEnumType in\n // target-postgres) can override `kind` with their narrower\n // enumerable literal via a class-field initializer. SqlNode\n // itself never needs to mutate the property again, so\n // configurability has no surface impact at this layer.\n configurable: true,\n });\n }\n}\n","import { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from './sql-node';\n\nexport interface ForeignKeyReferencesInput {\n readonly table: string;\n readonly columns: readonly string[];\n}\n\n/**\n * SQL Contract IR node for the referenced side of a foreign key.\n *\n * The class is shaped around single-namespace references today; a\n * future milestone introduces a cross-namespace coordinate on top of\n * `(table, columns)` when namespace-keyed storage lands.\n */\nexport class ForeignKeyReferences extends SqlNode {\n readonly table: string;\n readonly columns: readonly string[];\n\n constructor(input: ForeignKeyReferencesInput) {\n super();\n this.table = input.table;\n this.columns = input.columns;\n freezeNode(this);\n }\n}\n","import { freezeNode } from '@prisma-next/framework-components/ir';\nimport { ForeignKeyReferences, type ForeignKeyReferencesInput } from './foreign-key-references';\nimport { SqlNode } from './sql-node';\n\nexport type ReferentialAction = 'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault';\n\nexport interface ForeignKeyInput {\n readonly columns: readonly string[];\n readonly references: ForeignKeyReferences | ForeignKeyReferencesInput;\n readonly name?: string;\n readonly onDelete?: ReferentialAction;\n readonly onUpdate?: ReferentialAction;\n /** Whether to emit FK constraint DDL (ALTER TABLE … ADD CONSTRAINT … FOREIGN KEY). */\n readonly constraint: boolean;\n /** Whether to emit a backing index for the FK columns. */\n readonly index: boolean;\n}\n\n/**\n * SQL Contract IR node for a table-level foreign-key declaration.\n *\n * The nested `references` field is normalised to a\n * {@link ForeignKeyReferences} instance inside the constructor so\n * downstream walks see a uniform AST regardless of whether the input\n * was a JSON literal or an already-constructed class instance.\n */\nexport class ForeignKey extends SqlNode {\n readonly columns: readonly string[];\n readonly references: ForeignKeyReferences;\n readonly constraint: boolean;\n readonly index: boolean;\n declare readonly name?: string;\n declare readonly onDelete?: ReferentialAction;\n declare readonly onUpdate?: ReferentialAction;\n\n constructor(input: ForeignKeyInput) {\n super();\n this.columns = input.columns;\n this.references =\n input.references instanceof ForeignKeyReferences\n ? input.references\n : new ForeignKeyReferences(input.references);\n this.constraint = input.constraint;\n this.index = input.index;\n if (input.name !== undefined) this.name = input.name;\n if (input.onDelete !== undefined) this.onDelete = input.onDelete;\n if (input.onUpdate !== undefined) this.onUpdate = input.onUpdate;\n freezeNode(this);\n }\n}\n","import type { StorageType } from '@prisma-next/framework-components/ir';\n\n/**\n * Discriminator literal for the Postgres-enum variant on the polymorphic\n * `SqlStorage.types` slot.\n *\n * Enums are a target-level concept: Postgres ships native\n * `CREATE TYPE … AS ENUM` while other SQL targets approximate enums via\n * constraints. The literal lives at the SQL family layer because every\n * SQL-family consumer (verifier, planner, lowering, …) needs to\n * discriminate enum-typed slot entries from codec-typed ones. The\n * concrete IR class (`PostgresEnumType`) lives in the target-postgres\n * package and implements this structural contract; cross-domain\n * layering rules forbid the SQL family from importing the concrete\n * target class directly, so the discriminator and structural interface\n * carry the dispatch.\n */\nexport const POSTGRES_ENUM_KIND = 'postgres-enum' as const;\n\n/**\n * Structural contract every Postgres-enum slot entry honours — both\n * the live `PostgresEnumType` IR-class instance and the raw JSON\n * envelope shape that survives `JSON.stringify` round-trips. SQL\n * family-layer dispatch narrows polymorphic `StorageType` slot\n * entries to this shape via `isPostgresEnumStorageEntry`.\n *\n * The `codecBinding` field is accessor-shaped (live class instance) on\n * the IR class and undefined on the raw JSON envelope; consumers that\n * need it must guard for its presence (the JSON path synthesises an\n * equivalent shape from `codecId` + `values`).\n */\nexport interface PostgresEnumStorageEntry extends StorageType {\n readonly kind: typeof POSTGRES_ENUM_KIND;\n readonly name: string;\n readonly nativeType: string;\n readonly values: readonly string[];\n /**\n * Enumerable own property on the persisted JSON envelope; the live\n * IR-class instance carries it too. Family-shared dispatch sites\n * read `codecId` directly rather than going through the IR-class\n * `codecBinding` accessor (which lives on the prototype and isn't\n * present on raw JSON envelopes).\n */\n readonly codecId: string;\n}\n\n/**\n * Narrow a polymorphic `StorageType` entry to the Postgres-enum shape\n * via its enumerable `kind` discriminator. Type guard returns true for\n * both live `PostgresEnumType` instances and raw JSON envelopes.\n */\nexport function isPostgresEnumStorageEntry(value: unknown): value is PostgresEnumStorageEntry {\n if (typeof value !== 'object' || value === null) return false;\n return (value as { kind?: unknown }).kind === POSTGRES_ENUM_KIND;\n}\n","import { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from './sql-node';\n\nexport interface PrimaryKeyInput {\n readonly columns: readonly string[];\n readonly name?: string;\n}\n\n/**\n * SQL Contract IR node for a table's primary-key constraint.\n */\nexport class PrimaryKey extends SqlNode {\n readonly columns: readonly string[];\n declare readonly name?: string;\n\n constructor(input: PrimaryKeyInput) {\n super();\n this.columns = input.columns;\n if (input.name !== undefined) this.name = input.name;\n freezeNode(this);\n }\n}\n","import { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from './sql-node';\n\nexport interface IndexInput {\n readonly columns: readonly string[];\n readonly name?: string;\n readonly type?: string;\n readonly options?: Record<string, unknown>;\n}\n\n/**\n * SQL Contract IR node for a table-level secondary index.\n *\n * Note that this class shadows the global TypeScript `Index` lib type\n * at the family-shared name; consumer files that need both should\n * alias one (e.g.\n * `import { Index as SqlIndexNode } from '@prisma-next/sql-contract/types'`).\n */\nexport class Index extends SqlNode {\n readonly columns: readonly string[];\n declare readonly name?: string;\n declare readonly type?: string;\n declare readonly options?: Record<string, unknown>;\n\n constructor(input: IndexInput) {\n super();\n this.columns = input.columns;\n if (input.name !== undefined) this.name = input.name;\n if (input.type !== undefined) this.type = input.type;\n if (input.options !== undefined) this.options = input.options;\n freezeNode(this);\n }\n}\n","import {\n freezeNode,\n NamespaceBase,\n UNSPECIFIED_NAMESPACE_ID,\n} from '@prisma-next/framework-components/ir';\n\n/**\n * Family-layer placeholder for the SQL unspecified-namespace singleton.\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.unspecified`, `SqliteUnspecifiedDatabase.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\": \"__unspecified__\" }` — symmetric\n * with the family-level non-enumerable `kind` on `SqlNode` and bounded\n * to the minimum data the framework `Namespace` interface 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 SqlUnspecifiedNamespace extends NamespaceBase {\n static readonly instance: SqlUnspecifiedNamespace = new SqlUnspecifiedNamespace();\n\n readonly id = UNSPECIFIED_NAMESPACE_ID;\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","import type { ColumnDefault } from '@prisma-next/contract/types';\nimport { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from './sql-node';\n\n/**\n * Hydration / construction input shape for {@link StorageColumn}. Mirrors\n * the on-disk storage JSON envelope exactly so the family-base\n * serializer's hydration walker can hand an arktype-validated literal\n * straight to `new`.\n *\n * `typeParams` and `typeRef` remain mutually exclusive (one or the\n * other, not both); the constructor preserves whichever caller-side\n * choice the input encodes.\n */\nexport interface StorageColumnInput {\n readonly nativeType: string;\n readonly codecId: string;\n readonly nullable: boolean;\n readonly typeParams?: Record<string, unknown>;\n readonly typeRef?: string;\n readonly default?: ColumnDefault;\n}\n\n/**\n * SQL Contract IR node for a single column entry in `StorageTable.columns`.\n *\n * Single concrete family-shared class — every SQL target reads the\n * same column shape today, so there is no per-target subclass. The\n * class type accepts any caller that constructs via\n * `new StorageColumn(input)`; literal construction sites must pass\n * through the constructor or the family-base hydration walker.\n *\n * The column's `name` is not on the class — columns are keyed by name\n * in the parent `StorageTable.columns: Record<string, StorageColumn>`\n * map, so a `name` field would be redundant with the key.\n */\nexport class StorageColumn extends SqlNode {\n readonly nativeType: string;\n readonly codecId: string;\n readonly nullable: boolean;\n declare readonly typeParams?: Record<string, unknown>;\n declare readonly typeRef?: string;\n declare readonly default?: ColumnDefault;\n\n constructor(input: StorageColumnInput) {\n super();\n this.nativeType = input.nativeType;\n this.codecId = input.codecId;\n this.nullable = input.nullable;\n if (input.typeParams !== undefined) this.typeParams = input.typeParams;\n if (input.typeRef !== undefined) this.typeRef = input.typeRef;\n if (input.default !== undefined) this.default = input.default;\n freezeNode(this);\n }\n}\n","import { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from './sql-node';\n\nexport interface UniqueConstraintInput {\n readonly columns: readonly string[];\n readonly name?: string;\n}\n\n/**\n * SQL Contract IR node for a table-level unique constraint.\n */\nexport class UniqueConstraint extends SqlNode {\n readonly columns: readonly string[];\n declare readonly name?: string;\n\n constructor(input: UniqueConstraintInput) {\n super();\n this.columns = input.columns;\n if (input.name !== undefined) this.name = input.name;\n freezeNode(this);\n }\n}\n","import { freezeNode } from '@prisma-next/framework-components/ir';\nimport { ForeignKey, type ForeignKeyInput } from './foreign-key';\nimport { PrimaryKey, type PrimaryKeyInput } from './primary-key';\nimport { Index, type IndexInput } from './sql-index';\nimport { SqlNode } from './sql-node';\nimport { StorageColumn, type StorageColumnInput } from './storage-column';\nimport { UniqueConstraint, type UniqueConstraintInput } from './unique-constraint';\n\nexport interface StorageTableInput {\n readonly columns: Record<string, StorageColumn | StorageColumnInput>;\n readonly primaryKey?: PrimaryKey | PrimaryKeyInput;\n readonly uniques: ReadonlyArray<UniqueConstraint | UniqueConstraintInput>;\n readonly indexes: ReadonlyArray<Index | IndexInput>;\n readonly foreignKeys: ReadonlyArray<ForeignKey | ForeignKeyInput>;\n}\n\n/**\n * SQL Contract IR node for a single table entry in `SqlStorage.tables`.\n *\n * The constructor normalises nested IR-class fields (columns, primary\n * key, uniques, indexes, foreign keys) into the appropriate class\n * instances so downstream walks see a uniform AST regardless of whether\n * the input was a JSON literal or an already-constructed class.\n *\n * The table's `name` is not on the class — tables are keyed by name in\n * the parent `SqlStorage.tables: Record<string, StorageTable>` map.\n * A future namespace-aware milestone will add a `namespaceId` field\n * when namespace-keyed storage lands; today's single-namespace shape\n * needs neither field.\n */\nexport class StorageTable extends SqlNode {\n readonly columns: Readonly<Record<string, StorageColumn>>;\n readonly uniques: ReadonlyArray<UniqueConstraint>;\n readonly indexes: ReadonlyArray<Index>;\n readonly foreignKeys: ReadonlyArray<ForeignKey>;\n declare readonly primaryKey?: PrimaryKey;\n\n constructor(input: StorageTableInput) {\n super();\n this.columns = Object.freeze(\n Object.fromEntries(\n Object.entries(input.columns).map(([name, col]) => [\n name,\n col instanceof StorageColumn ? col : new StorageColumn(col),\n ]),\n ),\n );\n if (input.primaryKey !== undefined) {\n this.primaryKey =\n input.primaryKey instanceof PrimaryKey\n ? input.primaryKey\n : new PrimaryKey(input.primaryKey);\n }\n this.uniques = Object.freeze(\n input.uniques.map((u) => (u instanceof UniqueConstraint ? u : new UniqueConstraint(u))),\n );\n this.indexes = Object.freeze(input.indexes.map((i) => (i instanceof Index ? i : new Index(i))));\n this.foreignKeys = Object.freeze(\n input.foreignKeys.map((fk) => (fk instanceof ForeignKey ? fk : new ForeignKey(fk))),\n );\n freezeNode(this);\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 class-instance entries\n * (e.g. `PostgresEnumType`) sharing the polymorphic slot.\n */\nexport interface StorageTypeInstance extends StorageType {\n readonly kind: typeof CODEC_INSTANCE_KIND;\n readonly codecId: string;\n readonly nativeType: string;\n readonly typeParams: Record<string, unknown>;\n}\n\n/**\n * Construction-time input for a codec-triple entry. Symmetric with the\n * structural runtime shape minus the `kind` discriminator — callers may\n * omit `kind`; the helper {@link toStorageTypeInstance} stamps it on.\n */\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.\n */\nexport function toStorageTypeInstance(input: StorageTypeInstanceInput): StorageTypeInstance {\n return {\n kind: CODEC_INSTANCE_KIND,\n codecId: input.codecId,\n nativeType: input.nativeType,\n typeParams: input.typeParams,\n };\n}\n\n/**\n * Type-guard for codec-typed entries on the polymorphic\n * `SqlStorage.types` slot. Distinguishes `StorageTypeInstance` from\n * class-instance kinds (e.g. `PostgresEnumType`).\n */\nexport function isStorageTypeInstance(value: unknown): value is StorageTypeInstance {\n if (typeof value !== 'object' || value === null) return false;\n return (value as { kind?: unknown }).kind === CODEC_INSTANCE_KIND;\n}\n","import type { StorageHashBase } from '@prisma-next/contract/types';\nimport {\n freezeNode,\n type Namespace,\n type Storage,\n UNSPECIFIED_NAMESPACE_ID,\n} from '@prisma-next/framework-components/ir';\nimport {\n isPostgresEnumStorageEntry,\n type PostgresEnumStorageEntry,\n} from './postgres-enum-storage-entry';\nimport { SqlNode } from './sql-node';\nimport { SqlUnspecifiedNamespace } from './sql-unspecified-namespace';\nimport { StorageTable, type StorageTableInput } from './storage-table';\nimport {\n isStorageTypeInstance,\n type StorageTypeInstance,\n type StorageTypeInstanceInput,\n} from './storage-type-instance';\n\n/**\n * Polymorphic value type for `SqlStorage.types` entries (Decision 18,\n * Option B). The slot's framework alphabet is `StorageType` — codec\n * triples (`StorageTypeInstance` with `kind: 'codec-instance'`) and\n * target-specific IR class instances structurally satisfying\n * `PostgresEnumStorageEntry` (with `kind: 'postgres-enum'`) are the\n * two variants the SQL family ships today. The construction side also\n * accepts {@link StorageTypeInstanceInput} so callers can pass raw\n * codec triples; the constructor stamps the discriminator.\n */\nexport type SqlStorageTypeEntry =\n | StorageTypeInstance\n | PostgresEnumStorageEntry\n | StorageTypeInstanceInput;\n\nconst DEFAULT_NAMESPACES: Readonly<Record<string, Namespace>> = Object.freeze({\n [UNSPECIFIED_NAMESPACE_ID]: SqlUnspecifiedNamespace.instance,\n});\n\nexport interface SqlStorageInput<THash extends string = string> {\n readonly storageHash: StorageHashBase<THash>;\n readonly tables: Record<string, StorageTable | StorageTableInput>;\n readonly types?: Record<string, SqlStorageTypeEntry>;\n readonly namespaces?: Readonly<Record<string, Namespace>>;\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 same 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. The default singleton\n * (`{ [UNSPECIFIED_NAMESPACE_ID]: SqlUnspecifiedNamespace.instance }`)\n * binds every contract authored before per-target namespace concretions\n * land; per-target namespace classes (`PostgresSchema.unspecified`,\n * `SqliteUnspecifiedDatabase.instance`) earn their slots when each\n * target's namespace shape lands.\n *\n * The constructor normalises nested IR-class fields (`tables`, optional\n * `types`) into class instances so downstream walks see a uniform AST.\n * `types` is polymorphic per Decision 18 Option B: codec-triple inputs\n * are stamped with `kind: 'codec-instance'`; class-instance kinds\n * (e.g. Postgres-enum entries satisfying `PostgresEnumStorageEntry`)\n * pass through; hydration of raw JSON class-instance entries (carrying\n * their narrower `kind` literal) is the per-target serializer's\n * responsibility (so the family base does not import target-specific\n * subclasses).\n */\nexport class SqlStorage<THash extends string = string> extends SqlNode implements Storage {\n readonly storageHash: StorageHashBase<THash>;\n readonly tables: Readonly<Record<string, StorageTable>>;\n readonly namespaces: Readonly<Record<string, Namespace>>;\n // SQL-family slot view: the two structural variants the family ships\n // today (codec triples + Postgres-enum structural entries). Each\n // variant extends the framework `StorageType` alphabet; the SQL\n // narrowing keeps cross-domain layering clean — SQL-family consumers\n // dispatch via `isStorageTypeInstance` / `isPostgresEnumStorageEntry`\n // type guards rather than importing the target's concrete IR class\n // (cross-domain rule: SQL may not import `target-*`).\n declare readonly types?: Readonly<Record<string, StorageTypeInstance | PostgresEnumStorageEntry>>;\n\n constructor(input: SqlStorageInput<THash>) {\n super();\n this.storageHash = input.storageHash;\n this.tables = Object.freeze(\n Object.fromEntries(\n Object.entries(input.tables).map(([name, t]) => [\n name,\n t instanceof StorageTable ? t : new StorageTable(t),\n ]),\n ),\n );\n this.namespaces = input.namespaces ?? DEFAULT_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 * (TML-2536). Every entry must carry a recognised `kind` discriminator\n * — either `'codec-instance'` (codec triple, family-shared) or\n * `'postgres-enum'` (target-specific IR class). 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(\n name: string,\n entry: SqlStorageTypeEntry,\n): StorageTypeInstance | PostgresEnumStorageEntry {\n if (isPostgresEnumStorageEntry(entry)) {\n // Live class instances pass through unchanged; raw JSON envelopes\n // (e.g. `kind: 'postgres-enum'` without the class identity) are\n // rejected so the target serializer's hydration path is the only\n // way IR class instances enter the slot.\n if (entry instanceof SqlNode) {\n return entry;\n }\n throw new Error(\n `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.`,\n );\n }\n if (isStorageTypeInstance(entry)) {\n return 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')} or ${JSON.stringify('postgres-enum')}. Untagged codec triples should be wrapped with toStorageTypeInstance(...) before construction.`,\n );\n}\n","import type { CodecTrait } from '@prisma-next/framework-components/codec';\nimport type { ReferentialAction } from './ir/foreign-key';\n\nexport {\n ForeignKey,\n type ForeignKeyInput,\n type ReferentialAction,\n} from './ir/foreign-key';\nexport {\n ForeignKeyReferences,\n type ForeignKeyReferencesInput,\n} from './ir/foreign-key-references';\nexport {\n isPostgresEnumStorageEntry,\n POSTGRES_ENUM_KIND,\n type PostgresEnumStorageEntry,\n} from './ir/postgres-enum-storage-entry';\nexport { PrimaryKey, type PrimaryKeyInput } from './ir/primary-key';\nexport { Index, type IndexInput } from './ir/sql-index';\nexport { SqlNode } from './ir/sql-node';\nexport {\n SqlStorage,\n type SqlStorageInput,\n type SqlStorageTypeEntry,\n} from './ir/sql-storage';\nexport { SqlUnspecifiedNamespace } from './ir/sql-unspecified-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 {\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 fields: Record<string, SqlModelFieldStorage>;\n};\n\nexport const DEFAULT_FK_CONSTRAINT = true;\nexport const DEFAULT_FK_INDEX = true;\n\nexport function applyFkDefaults(\n fk: { constraint?: boolean | undefined; index?: boolean | undefined },\n overrideDefaults?: { constraint?: boolean | undefined; index?: boolean | undefined },\n): { constraint: boolean; index: boolean } {\n return {\n constraint: fk.constraint ?? overrideDefaults?.constraint ?? DEFAULT_FK_CONSTRAINT,\n index: fk.index ?? overrideDefaults?.index ?? DEFAULT_FK_INDEX,\n };\n}\n\nexport type TypeMaps<\n TCodecTypes extends Record<string, { output: unknown }> = Record<string, never>,\n TQueryOperationTypes extends Record<string, unknown> = Record<string, never>,\n TFieldOutputTypes extends Record<string, Record<string, unknown>> = Record<string, never>,\n TFieldInputTypes extends Record<string, Record<string, unknown>> = Record<string, never>,\n> = {\n readonly codecTypes: TCodecTypes;\n readonly queryOperationTypes: TQueryOperationTypes;\n readonly fieldOutputTypes: TFieldOutputTypes;\n readonly fieldInputTypes: TFieldInputTypes;\n};\n\nexport type CodecTypesOf<T> = [T] extends [never]\n ? Record<string, never>\n : T extends { readonly codecTypes: infer C }\n ? C extends Record<string, { output: unknown }>\n ? C\n : Record<string, never>\n : Record<string, never>;\n\n/**\n * Dispatch hint identifying the first-argument target of an operation.\n *\n * Used by ORM column helpers to decide whether an operation is reachable on a\n * field. Either names a concrete codec identity or a set of capability traits\n * that the field's codec must carry.\n */\nexport type QueryOperationSelfSpec =\n | { readonly codecId: string; readonly traits?: never }\n | { readonly traits: readonly CodecTrait[]; readonly codecId?: never };\n\n/**\n * Structural shape an operation's impl must return: any value carrying a\n * codec-exact `returnType` descriptor. `Expression<T>` (from\n * `@prisma-next/sql-relational-core/expression`, with `T extends ScopeField`)\n * extends this. Trait-targeted returns are deliberately excluded — predicate\n * detection and result decoding both depend on knowing the concrete return\n * codec.\n */\nexport type QueryOperationReturn = {\n readonly returnType: { readonly codecId: string; readonly nullable: boolean };\n};\n\nexport type QueryOperationTypeEntry = {\n readonly self?: QueryOperationSelfSpec;\n readonly impl: (...args: never[]) => QueryOperationReturn;\n};\n\nexport type SqlQueryOperationTypes<\n _CT extends Record<string, { readonly input: unknown; readonly output: unknown }>,\n T extends Record<string, QueryOperationTypeEntry>,\n> = T;\n\nexport type QueryOperationTypesBase = Record<string, QueryOperationTypeEntry>;\n\nexport type QueryOperationTypesOf<T> = [T] extends [never]\n ? Record<string, never>\n : T extends { readonly queryOperationTypes: infer Q }\n ? Q extends Record<string, unknown>\n ? Q\n : Record<string, never>\n : Record<string, never>;\n\nexport type TypeMapsPhantomKey = '__@prisma-next/sql-contract/typeMaps@__';\n\nexport type ContractWithTypeMaps<TContract, TTypeMaps> = TContract & {\n readonly [K in TypeMapsPhantomKey]?: TTypeMaps;\n};\n\nexport type ExtractTypeMapsFromContract<T> = TypeMapsPhantomKey extends keyof T\n ? NonNullable<T[TypeMapsPhantomKey & keyof T]>\n : never;\n\nexport type FieldOutputTypesOf<T> = [T] extends [never]\n ? Record<string, never>\n : T extends { readonly fieldOutputTypes: infer F }\n ? F extends Record<string, Record<string, unknown>>\n ? F\n : Record<string, never>\n : Record<string, never>;\n\nexport type FieldInputTypesOf<T> = [T] extends [never]\n ? Record<string, never>\n : T extends { readonly fieldInputTypes: infer F }\n ? F extends Record<string, Record<string, unknown>>\n ? F\n : Record<string, never>\n : Record<string, never>;\n\nexport type ExtractCodecTypes<T> = CodecTypesOf<ExtractTypeMapsFromContract<T>>;\nexport type ExtractQueryOperationTypes<T> = QueryOperationTypesOf<ExtractTypeMapsFromContract<T>>;\nexport type ExtractFieldOutputTypes<T> = FieldOutputTypesOf<ExtractTypeMapsFromContract<T>>;\nexport type ExtractFieldInputTypes<T> = FieldInputTypesOf<ExtractTypeMapsFromContract<T>>;\n\nexport type ResolveCodecTypes<TContract, TTypeMaps> = [TTypeMaps] extends [never]\n ? ExtractCodecTypes<TContract>\n : CodecTypesOf<TTypeMaps>;\n"],"mappings":"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"}
|
package/dist/types.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as StorageTypeInstance, C as
|
|
2
|
-
export { type CodecTypesOf, type ContractWithTypeMaps, DEFAULT_FK_CONSTRAINT, DEFAULT_FK_INDEX, type ExtractCodecTypes, type ExtractFieldInputTypes, type ExtractFieldOutputTypes, type ExtractQueryOperationTypes, type ExtractTypeMapsFromContract, type FieldInputTypesOf, type FieldOutputTypesOf, type
|
|
1
|
+
import { A as StorageTypeInstance, B as Index, C as TypeMapsPhantomKey, D as SqlStorageInput, E as SqlStorage, F as StorageTableInput, G as PostgresEnumStorageEntry, H as PrimaryKey, I as UniqueConstraint, J as ForeignKeyInput, K as isPostgresEnumStorageEntry, L as UniqueConstraintInput, M as isStorageTypeInstance, N as toStorageTypeInstance, O as SqlStorageTypeEntry, P as StorageTable, Q as SqlNode, R as StorageColumn, S as TypeMaps, T as SqlUnspecifiedNamespace, U as PrimaryKeyInput, V as IndexInput, W as POSTGRES_ENUM_KIND, X as ForeignKeyReferences, Y as ReferentialAction, Z as ForeignKeyReferencesInput, _ as QueryOperationTypesOf, a as ExtractCodecTypes, b as SqlModelStorage, c as ExtractQueryOperationTypes, d as FieldOutputTypesOf, f as ForeignKeyOptions, g as QueryOperationTypesBase, h as QueryOperationTypeEntry, i as DEFAULT_FK_INDEX, j as StorageTypeInstanceInput, k as CODEC_INSTANCE_KIND, l as ExtractTypeMapsFromContract, m as QueryOperationSelfSpec, n as ContractWithTypeMaps, o as ExtractFieldInputTypes, p as QueryOperationReturn, q as ForeignKey, r as DEFAULT_FK_CONSTRAINT, s as ExtractFieldOutputTypes, t as CodecTypesOf, u as FieldInputTypesOf, v as ResolveCodecTypes, w as applyFkDefaults, x as SqlQueryOperationTypes, y as SqlModelFieldStorage, z as StorageColumnInput } from "./types-B0lbr9cb.mjs";
|
|
2
|
+
export { CODEC_INSTANCE_KIND, type CodecTypesOf, type ContractWithTypeMaps, DEFAULT_FK_CONSTRAINT, DEFAULT_FK_INDEX, type ExtractCodecTypes, type ExtractFieldInputTypes, type ExtractFieldOutputTypes, type ExtractQueryOperationTypes, type ExtractTypeMapsFromContract, type FieldInputTypesOf, type FieldOutputTypesOf, ForeignKey, type ForeignKeyInput, type ForeignKeyOptions, ForeignKeyReferences, type ForeignKeyReferencesInput, Index, type IndexInput, POSTGRES_ENUM_KIND, type PostgresEnumStorageEntry, PrimaryKey, type PrimaryKeyInput, type QueryOperationReturn, type QueryOperationSelfSpec, type QueryOperationTypeEntry, type QueryOperationTypesBase, type QueryOperationTypesOf, type ReferentialAction, type ResolveCodecTypes, type SqlModelFieldStorage, type SqlModelStorage, SqlNode, type SqlQueryOperationTypes, SqlStorage, type SqlStorageInput, type SqlStorageTypeEntry, SqlUnspecifiedNamespace, StorageColumn, type StorageColumnInput, StorageTable, type StorageTableInput, type StorageTypeInstance, type StorageTypeInstanceInput, type TypeMaps, type TypeMapsPhantomKey, UniqueConstraint, type UniqueConstraintInput, applyFkDefaults, isPostgresEnumStorageEntry, isStorageTypeInstance, toStorageTypeInstance };
|
package/dist/types.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as DEFAULT_FK_INDEX, r as applyFkDefaults, t as DEFAULT_FK_CONSTRAINT } from "./types-
|
|
2
|
-
export { DEFAULT_FK_CONSTRAINT, DEFAULT_FK_INDEX, applyFkDefaults };
|
|
1
|
+
import { _ as ForeignKeyReferences, a as CODEC_INSTANCE_KIND, c as StorageTable, d as SqlUnspecifiedNamespace, f as Index, g as ForeignKey, h as isPostgresEnumStorageEntry, i as SqlStorage, l as UniqueConstraint, m as POSTGRES_ENUM_KIND, n as DEFAULT_FK_INDEX, o as isStorageTypeInstance, p as PrimaryKey, r as applyFkDefaults, s as toStorageTypeInstance, t as DEFAULT_FK_CONSTRAINT, u as StorageColumn, v as SqlNode } from "./types-iqFGDcJp.mjs";
|
|
2
|
+
export { CODEC_INSTANCE_KIND, DEFAULT_FK_CONSTRAINT, DEFAULT_FK_INDEX, ForeignKey, ForeignKeyReferences, Index, POSTGRES_ENUM_KIND, PrimaryKey, SqlNode, SqlStorage, SqlUnspecifiedNamespace, StorageColumn, StorageTable, UniqueConstraint, applyFkDefaults, isPostgresEnumStorageEntry, isStorageTypeInstance, toStorageTypeInstance };
|
package/dist/validators.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { E as SqlStorage, J as ForeignKeyInput, Y as ReferentialAction, Z as ForeignKeyReferencesInput } from "./types-B0lbr9cb.mjs";
|
|
2
2
|
import { Contract } from "@prisma-next/contract/types";
|
|
3
3
|
import * as _$arktype_internal_variants_object_ts0 from "arktype/internal/variants/object.ts";
|
|
4
4
|
import * as _$arktype_internal_variants_string_ts0 from "arktype/internal/variants/string.ts";
|
|
@@ -21,9 +21,9 @@ declare const IndexSchema: _$arktype_internal_variants_object_ts0.ObjectType<{
|
|
|
21
21
|
type?: string;
|
|
22
22
|
options?: Record<string, unknown>;
|
|
23
23
|
}, {}>;
|
|
24
|
-
declare const ForeignKeyReferencesSchema: _$arktype_internal_variants_object_ts0.ObjectType<
|
|
24
|
+
declare const ForeignKeyReferencesSchema: _$arktype_internal_variants_object_ts0.ObjectType<ForeignKeyReferencesInput, {}>;
|
|
25
25
|
declare const ReferentialActionSchema: _$arktype_internal_variants_string_ts0.StringType<ReferentialAction, {}>;
|
|
26
|
-
declare const ForeignKeySchema: _$arktype_internal_variants_object_ts0.ObjectType<
|
|
26
|
+
declare const ForeignKeySchema: _$arktype_internal_variants_object_ts0.ObjectType<ForeignKeyInput, {}>;
|
|
27
27
|
/**
|
|
28
28
|
* Validates the structural shape of SqlStorage using Arktype.
|
|
29
29
|
*
|
|
@@ -33,17 +33,6 @@ declare const ForeignKeySchema: _$arktype_internal_variants_object_ts0.ObjectTyp
|
|
|
33
33
|
*/
|
|
34
34
|
declare function validateStorage(value: unknown): SqlStorage;
|
|
35
35
|
declare function validateModel(value: unknown): unknown;
|
|
36
|
-
/**
|
|
37
|
-
* Validates the structural shape of an SQL contract using Arktype.
|
|
38
|
-
*
|
|
39
|
-
* Ensures all required fields are present and have the correct types,
|
|
40
|
-
* including SQL-specific storage structure (tables, columns, constraints).
|
|
41
|
-
*
|
|
42
|
-
* @param value - The contract value to validate (typically from a JSON import)
|
|
43
|
-
* @returns The validated contract if structure is valid
|
|
44
|
-
* @throws ContractValidationError if the contract structure is invalid
|
|
45
|
-
*/
|
|
46
|
-
declare function validateSqlContract<T extends Contract<SqlStorage>>(value: unknown): T;
|
|
47
36
|
/**
|
|
48
37
|
* Validates semantic constraints on SqlStorage that cannot be expressed in Arktype schemas.
|
|
49
38
|
*
|
|
@@ -58,6 +47,29 @@ declare function validateSqlContract<T extends Contract<SqlStorage>>(value: unkn
|
|
|
58
47
|
* - `setDefault` referential action on a non-nullable FK column without a DEFAULT (would fail at runtime)
|
|
59
48
|
*/
|
|
60
49
|
declare function validateStorageSemantics(storage: SqlStorage): string[];
|
|
50
|
+
/**
|
|
51
|
+
* SQL storage logical-consistency checks: every model.storage.table
|
|
52
|
+
* resolves to a real table, every model.storage.fields[*].column
|
|
53
|
+
* resolves to a real column, and value-object fields land on JSON-native
|
|
54
|
+
* columns. Throws `ContractValidationError` on the first mismatch.
|
|
55
|
+
*/
|
|
56
|
+
declare function validateModelStorageReferences(contract: Contract<SqlStorage>): void;
|
|
57
|
+
/**
|
|
58
|
+
* Cross-table consistency checks for SQL storage: primary key, unique,
|
|
59
|
+
* index, and foreign key column references resolve to real columns;
|
|
60
|
+
* NOT NULL columns don't carry a literal `null` default; FK column
|
|
61
|
+
* counts match their referenced columns. Throws on the first mismatch.
|
|
62
|
+
*/
|
|
63
|
+
declare function validateSqlStorageConsistency(contract: Contract<SqlStorage>): void;
|
|
64
|
+
/**
|
|
65
|
+
* Full SQL contract validation: structural (arktype) +
|
|
66
|
+
* framework-shared domain + SQL storage logical-consistency + SQL
|
|
67
|
+
* storage semantic + model ↔ storage reference checks. Throws
|
|
68
|
+
* `ContractValidationError` on the first failure. Returns the
|
|
69
|
+
* validated flat-data shape; IR class hydration happens in the SPI
|
|
70
|
+
* base on top of this helper.
|
|
71
|
+
*/
|
|
72
|
+
declare function validateSqlContractFully<T extends Contract<SqlStorage>>(value: unknown): T;
|
|
61
73
|
//#endregion
|
|
62
|
-
export { ColumnDefaultFunctionSchema, ColumnDefaultLiteralSchema, ColumnDefaultSchema, ForeignKeyReferencesSchema, ForeignKeySchema, IndexSchema, ReferentialActionSchema, validateModel,
|
|
74
|
+
export { ColumnDefaultFunctionSchema, ColumnDefaultLiteralSchema, ColumnDefaultSchema, ForeignKeyReferencesSchema, ForeignKeySchema, IndexSchema, ReferentialActionSchema, validateModel, validateModelStorageReferences, validateSqlContractFully, validateSqlStorageConsistency, validateStorage, validateStorageSemantics };
|
|
63
75
|
//# sourceMappingURL=validators.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validators.d.mts","names":[],"sources":["../src/validators.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"validators.d.mts","names":[],"sources":["../src/validators.ts"],"mappings":";;;;;;KAgBK,oBAAA;EAAA,SACM,IAAA;EAAA,SACA,KAAA,8BAAmC,MAAA;AAAA;AAAA,KAEzC,qBAAA;EAAA,SAAmC,IAAA;EAAA,SAA2B,UAAA;AAAA;AAAA,cAQtD,0BAAA,EAA0B,sCAAA,CAAA,UAAA,CAAA,oBAAA;AAAA,cAK1B,2BAAA,EAA2B,sCAAA,CAAA,UAAA,CAAA,qBAAA;AAAA,cAK3B,mBAAA,EAAmB,sCAAA,CAAA,UAAA,CAAA,oBAAA,GAAA,qBAAA;AAAA,cA4GnB,WAAA,EAKX,sCAAA,CALsB,UAAA;;;;YAKtB,MAAA;AAAA;AAAA,cAEW,0BAAA,EAA0B,sCAAA,CAAA,UAAA,CAAA,yBAAA;AAAA,cAK1B,uBAAA,EAAuB,sCAAA,CAAA,UAAA,CAAA,iBAAA;AAAA,cAIvB,gBAAA,EAAgB,sCAAA,CAAA,UAAA,CAAA,eAAA;;;;AAjI7B;;;;iBA8QgB,eAAA,CAAgB,KAAA,YAAiB,UAAA;AAAA,iBAajC,aAAA,CAAc,KAAA;;;;;;;;;;;;;AA1K9B;iBAqOgB,wBAAA,CAAyB,OAAA,EAAS,UAAA;;;;;;;iBAmJlC,8BAAA,CAA+B,QAAA,EAAU,QAAA,CAAS,UAAA;;;;AAjXlE;;;iBAkagB,6BAAA,CAA8B,QAAA,EAAU,QAAA,CAAS,UAAA;;AA7ZjE;;;;;AAIA;;iBAwfgB,wBAAA,WAAmC,QAAA,CAAS,UAAA,EAAA,CAAa,KAAA,YAAiB,CAAA"}
|