@prisma-next/sql-runtime 0.14.0-dev.6 → 0.14.0-dev.60
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/{exports-BXdIMaxT.mjs → exports-DDMKrdHY.mjs} +46 -4
- package/dist/exports-DDMKrdHY.mjs.map +1 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{prepared-statement-FQyyQnkC.d.mts → prepared-statement-BiwAFEou.d.mts} +14 -2
- package/dist/prepared-statement-BiwAFEou.d.mts.map +1 -0
- package/dist/test/utils.d.mts +413 -6
- package/dist/test/utils.d.mts.map +1 -1
- package/dist/test/utils.mjs +482 -8
- package/dist/test/utils.mjs.map +1 -1
- package/package.json +12 -12
- package/src/codecs/decoding.ts +40 -1
- package/src/codecs/encoding.ts +26 -0
- package/dist/exports-BXdIMaxT.mjs.map +0 -1
- package/dist/prepared-statement-FQyyQnkC.d.mts.map +0 -1
package/dist/test/utils.d.mts
CHANGED
|
@@ -1,14 +1,421 @@
|
|
|
1
|
-
import { C as SqlRuntimeTargetDescriptor, S as SqlRuntimeExtensionInstance, b as SqlRuntimeDriverInstance, f as ExecutionContext, i as Runtime, o as RuntimeOptions, v as SqlRuntimeAdapterDescriptor, x as SqlRuntimeExtensionDescriptor, y as SqlRuntimeAdapterInstance } from "../prepared-statement-
|
|
1
|
+
import { C as SqlRuntimeTargetDescriptor, H as decodeRow, S as SqlRuntimeExtensionInstance, V as buildDecodeContext, b as SqlRuntimeDriverInstance, f as ExecutionContext, i as Runtime, o as RuntimeOptions, v as SqlRuntimeAdapterDescriptor, x as SqlRuntimeExtensionDescriptor, y as SqlRuntimeAdapterInstance } from "../prepared-statement-BiwAFEou.mjs";
|
|
2
2
|
import { CodecDescriptor } from "@prisma-next/framework-components/codec";
|
|
3
3
|
import { ResultType } from "@prisma-next/framework-components/runtime";
|
|
4
4
|
import { Adapter, AnyQueryAst, Codec, ContractCodecRegistry, LoweredStatement, SelectAst } from "@prisma-next/sql-relational-core/ast";
|
|
5
5
|
import { RuntimeDriverDescriptor } from "@prisma-next/framework-components/execution";
|
|
6
|
-
import { Contract, ContractModelBase } from "@prisma-next/contract/types";
|
|
7
|
-
import {
|
|
6
|
+
import { ColumnDefault, Contract, ContractModelBase, ControlPolicy, JsonValue, NamespaceId, ValueSetRef } from "@prisma-next/contract/types";
|
|
7
|
+
import { IRNodeBase, NamespaceBase } from "@prisma-next/framework-components/ir";
|
|
8
|
+
import { SqlStorage, SqlStorageInput, StorageTableInput } from "@prisma-next/sql-contract/types";
|
|
8
9
|
import { DevDatabase, collectAsync, createDevDatabase, teardownTestDatabase, withClient } from "@prisma-next/test-utils";
|
|
9
10
|
import { SqlExecutionPlan, SqlQueryPlan } from "@prisma-next/sql-relational-core/plan";
|
|
10
11
|
import { Client } from "pg";
|
|
11
|
-
|
|
12
|
+
//#region ../1-core/contract/src/ir/sql-node.d.ts
|
|
13
|
+
/**
|
|
14
|
+
* SQL family IR node base. Carries the family-level `kind` discriminator
|
|
15
|
+
* `'sql'` and inherits the framework's `freezeNode` affordance.
|
|
16
|
+
*
|
|
17
|
+
* Single family-level discriminator (not per-leaf) reflects the fact that
|
|
18
|
+
* SQL IR has no polymorphic dispatch today — verifiers and serializers
|
|
19
|
+
* walk by structural position (`storage.tables[name].columns[name]`),
|
|
20
|
+
* not by inspecting `kind`. The abstract bar for per-leaf discriminators
|
|
21
|
+
* isn't earned until a future polymorphic consumer arrives.
|
|
22
|
+
*
|
|
23
|
+
* `kind` is installed as a non-enumerable own property on every instance,
|
|
24
|
+
* which keeps three things clean simultaneously:
|
|
25
|
+
*
|
|
26
|
+
* - `JSON.stringify(node)` produces the canonical pre-lift JSON envelope
|
|
27
|
+
* shape (no `kind` field), so emitted contract.json files and the
|
|
28
|
+
* `validateSqlContractFully` arktype schemas stay unchanged.
|
|
29
|
+
* - Test assertions that use `toEqual({...})` against the pre-lift flat
|
|
30
|
+
* shape continue to pass — only enumerable own properties are
|
|
31
|
+
* compared.
|
|
32
|
+
* - Direct access (`node.kind`) and runtime narrowing
|
|
33
|
+
* (`if (node.kind === 'sql')`) still work, so future polymorphic
|
|
34
|
+
* dispatch can begin reading `kind` without a runtime change.
|
|
35
|
+
*
|
|
36
|
+
* Future per-leaf overrides land cleanly: a class that gains a
|
|
37
|
+
* polymorphic-dispatch consumer (e.g. an enum type instance walked
|
|
38
|
+
* alongside other types) overrides `kind` with its narrower literal
|
|
39
|
+
* at that leaf level. Per-leaf overrides will use enumerable kind
|
|
40
|
+
* (matching the Mongo per-class-discriminator precedent) because they
|
|
41
|
+
* encode dispatch-relevant information that callers need to see in
|
|
42
|
+
* JSON envelopes; the family-level `'sql'` is uniform across all SQL
|
|
43
|
+
* IR and carries no dispatch-relevant information.
|
|
44
|
+
*/
|
|
45
|
+
declare abstract class SqlNode extends IRNodeBase {
|
|
46
|
+
readonly kind?: string;
|
|
47
|
+
constructor();
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region ../1-core/contract/src/ir/check-constraint.d.ts
|
|
51
|
+
/**
|
|
52
|
+
* Hydration / construction input shape for {@link CheckConstraint}.
|
|
53
|
+
* Mirrors the on-disk storage JSON envelope so the serializer hydration
|
|
54
|
+
* walker can hand a validated literal straight to `new`.
|
|
55
|
+
*/
|
|
56
|
+
interface CheckConstraintInput {
|
|
57
|
+
readonly name: string;
|
|
58
|
+
readonly column: string;
|
|
59
|
+
readonly valueSet: ValueSetRef;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* SQL Contract IR node for a table-level check constraint that restricts
|
|
63
|
+
* a column to the permitted values of a value-set.
|
|
64
|
+
*
|
|
65
|
+
* The constraint is **structured** (names a column and a value-set
|
|
66
|
+
* reference), not a raw SQL expression. Each target renders its own DDL
|
|
67
|
+
* from the structured form, keeping the contract target-agnostic.
|
|
68
|
+
*
|
|
69
|
+
* Construction is idempotent: passing an existing `CheckConstraint`
|
|
70
|
+
* instance as input produces a new instance with identical fields.
|
|
71
|
+
* The constructor does not use `instanceof` for input discrimination —
|
|
72
|
+
* it reads plain named properties, which is sufficient since
|
|
73
|
+
* `CheckConstraintInput` is a structural type.
|
|
74
|
+
*/
|
|
75
|
+
declare class CheckConstraint extends SqlNode {
|
|
76
|
+
readonly name: string;
|
|
77
|
+
readonly column: string;
|
|
78
|
+
readonly valueSet: ValueSetRef;
|
|
79
|
+
constructor(input: CheckConstraintInput);
|
|
80
|
+
}
|
|
81
|
+
//#endregion
|
|
82
|
+
//#region ../1-core/contract/src/ir/foreign-key-reference.d.ts
|
|
83
|
+
/**
|
|
84
|
+
* Input for a foreign-key reference (one side of a foreign-key declaration).
|
|
85
|
+
*
|
|
86
|
+
* When `spaceId` is absent the reference is local — the referenced table lives
|
|
87
|
+
* in the same contract-space. When `spaceId` is present the reference is
|
|
88
|
+
* cross-space — the referenced table lives in a different contract-space
|
|
89
|
+
* identified by `spaceId`.
|
|
90
|
+
*
|
|
91
|
+
* Presence-based discrimination keeps local FK JSON byte-identical to
|
|
92
|
+
* contracts authored before cross-space support was added.
|
|
93
|
+
*/
|
|
94
|
+
interface ForeignKeyReferenceInput {
|
|
95
|
+
readonly namespaceId: string;
|
|
96
|
+
readonly tableName: string;
|
|
97
|
+
readonly columns: readonly string[];
|
|
98
|
+
readonly spaceId?: string;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* SQL Contract IR node for one side (source or target) of a foreign-key
|
|
102
|
+
* declaration. Carries the full coordinate: namespace, table, and columns.
|
|
103
|
+
*
|
|
104
|
+
* Cross-space discrimination is based on `spaceId` presence: absent means
|
|
105
|
+
* local (same contract-space); present means cross-space (the referenced
|
|
106
|
+
* table lives in the contract-space identified by `spaceId`).
|
|
107
|
+
*
|
|
108
|
+
* For local references `spaceId` is absent from JSON, keeping the serialized
|
|
109
|
+
* shape byte-identical to contracts authored before cross-space support was
|
|
110
|
+
* added. For cross-space references `spaceId` appears in JSON so round-trips
|
|
111
|
+
* are lossless.
|
|
112
|
+
*
|
|
113
|
+
* Use `UNBOUND_NAMESPACE_ID` from `@prisma-next/framework-components/ir`
|
|
114
|
+
* as the sentinel `namespaceId` for single-namespace (unbound) references.
|
|
115
|
+
*/
|
|
116
|
+
declare class ForeignKeyReference extends SqlNode {
|
|
117
|
+
readonly namespaceId: NamespaceId;
|
|
118
|
+
readonly tableName: string;
|
|
119
|
+
readonly columns: readonly string[];
|
|
120
|
+
readonly spaceId?: string;
|
|
121
|
+
constructor(input: ForeignKeyReferenceInput);
|
|
122
|
+
}
|
|
123
|
+
//#endregion
|
|
124
|
+
//#region ../1-core/contract/src/ir/foreign-key.d.ts
|
|
125
|
+
type ReferentialAction = 'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault';
|
|
126
|
+
interface ForeignKeyInput {
|
|
127
|
+
readonly source: ForeignKeyReference | ForeignKeyReferenceInput;
|
|
128
|
+
readonly target: ForeignKeyReference | ForeignKeyReferenceInput;
|
|
129
|
+
readonly name?: string;
|
|
130
|
+
readonly onDelete?: ReferentialAction;
|
|
131
|
+
readonly onUpdate?: ReferentialAction;
|
|
132
|
+
/** Whether to emit FK constraint DDL (ALTER TABLE … ADD CONSTRAINT … FOREIGN KEY). */
|
|
133
|
+
readonly constraint: boolean;
|
|
134
|
+
/** Whether to emit a backing index for the FK columns. */
|
|
135
|
+
readonly index: boolean;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* SQL Contract IR node for a table-level foreign-key declaration.
|
|
139
|
+
*
|
|
140
|
+
* Each FK carries explicit `source` and `target` {@link ForeignKeyReference}
|
|
141
|
+
* coordinates (namespace, table, columns). For single-namespace contracts the
|
|
142
|
+
* sentinel `UNBOUND_NAMESPACE_ID` appears on both sides.
|
|
143
|
+
*
|
|
144
|
+
* The nested references are normalised to {@link ForeignKeyReference}
|
|
145
|
+
* instances inside the constructor so downstream walks see a uniform AST
|
|
146
|
+
* regardless of whether the input was a JSON literal or an already-constructed
|
|
147
|
+
* class instance.
|
|
148
|
+
*/
|
|
149
|
+
declare class ForeignKey extends SqlNode {
|
|
150
|
+
readonly source: ForeignKeyReference;
|
|
151
|
+
readonly target: ForeignKeyReference;
|
|
152
|
+
readonly constraint: boolean;
|
|
153
|
+
readonly index: boolean;
|
|
154
|
+
readonly name?: string;
|
|
155
|
+
readonly onDelete?: ReferentialAction;
|
|
156
|
+
readonly onUpdate?: ReferentialAction;
|
|
157
|
+
constructor(input: ForeignKeyInput);
|
|
158
|
+
}
|
|
159
|
+
//#endregion
|
|
160
|
+
//#region ../1-core/contract/src/ir/primary-key.d.ts
|
|
161
|
+
interface PrimaryKeyInput {
|
|
162
|
+
readonly columns: readonly string[];
|
|
163
|
+
readonly name?: string;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* SQL Contract IR node for a table's primary-key constraint.
|
|
167
|
+
*/
|
|
168
|
+
declare class PrimaryKey extends SqlNode {
|
|
169
|
+
readonly columns: readonly string[];
|
|
170
|
+
readonly name?: string;
|
|
171
|
+
constructor(input: PrimaryKeyInput);
|
|
172
|
+
}
|
|
173
|
+
//#endregion
|
|
174
|
+
//#region ../1-core/contract/src/ir/sql-index.d.ts
|
|
175
|
+
interface IndexInput {
|
|
176
|
+
readonly columns: readonly string[];
|
|
177
|
+
readonly name?: string;
|
|
178
|
+
readonly type?: string;
|
|
179
|
+
readonly options?: Record<string, unknown>;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* SQL Contract IR node for a table-level secondary index.
|
|
183
|
+
*
|
|
184
|
+
* Note that this class shadows the global TypeScript `Index` lib type
|
|
185
|
+
* at the family-shared name; consumer files that need both should
|
|
186
|
+
* alias one (e.g.
|
|
187
|
+
* `import { Index as SqlIndexNode } from '@prisma-next/sql-contract/types'`).
|
|
188
|
+
*/
|
|
189
|
+
declare class Index extends SqlNode {
|
|
190
|
+
readonly columns: readonly string[];
|
|
191
|
+
readonly name?: string;
|
|
192
|
+
readonly type?: string;
|
|
193
|
+
readonly options?: Record<string, unknown>;
|
|
194
|
+
constructor(input: IndexInput);
|
|
195
|
+
}
|
|
196
|
+
//#endregion
|
|
197
|
+
//#region ../1-core/contract/src/ir/storage-column.d.ts
|
|
198
|
+
/**
|
|
199
|
+
* Hydration / construction input shape for {@link StorageColumn}. Mirrors
|
|
200
|
+
* the on-disk storage JSON envelope exactly so the family-base
|
|
201
|
+
* serializer's hydration walker can hand an arktype-validated literal
|
|
202
|
+
* straight to `new`.
|
|
203
|
+
*
|
|
204
|
+
* `typeParams` and `typeRef` remain mutually exclusive (one or the
|
|
205
|
+
* other, not both); the constructor preserves whichever caller-side
|
|
206
|
+
* choice the input encodes.
|
|
207
|
+
*/
|
|
208
|
+
interface StorageColumnInput {
|
|
209
|
+
readonly nativeType: string;
|
|
210
|
+
readonly codecId: string;
|
|
211
|
+
readonly nullable: boolean;
|
|
212
|
+
readonly many?: boolean;
|
|
213
|
+
readonly typeParams?: Record<string, unknown>;
|
|
214
|
+
readonly typeRef?: string;
|
|
215
|
+
readonly default?: ColumnDefault;
|
|
216
|
+
readonly control?: ControlPolicy;
|
|
217
|
+
readonly valueSet?: ValueSetRef;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* SQL Contract IR node for a single column entry in `StorageTable.columns`.
|
|
221
|
+
*
|
|
222
|
+
* Single concrete family-shared class — every SQL target reads the
|
|
223
|
+
* same column shape today, so there is no per-target subclass. The
|
|
224
|
+
* class type accepts any caller that constructs via
|
|
225
|
+
* `new StorageColumn(input)`; literal construction sites must pass
|
|
226
|
+
* through the constructor or the family-base hydration walker.
|
|
227
|
+
*
|
|
228
|
+
* The column's `name` is not on the class — columns are keyed by name
|
|
229
|
+
* in the parent `StorageTable.columns: Record<string, StorageColumn>`
|
|
230
|
+
* map, so a `name` field would be redundant with the key.
|
|
231
|
+
*/
|
|
232
|
+
declare class StorageColumn extends SqlNode {
|
|
233
|
+
readonly nativeType: string;
|
|
234
|
+
readonly codecId: string;
|
|
235
|
+
readonly nullable: boolean;
|
|
236
|
+
readonly many?: boolean;
|
|
237
|
+
readonly typeParams?: Record<string, unknown>;
|
|
238
|
+
readonly typeRef?: string;
|
|
239
|
+
readonly default?: ColumnDefault;
|
|
240
|
+
readonly control?: ControlPolicy;
|
|
241
|
+
readonly valueSet?: ValueSetRef;
|
|
242
|
+
constructor(input: StorageColumnInput);
|
|
243
|
+
}
|
|
244
|
+
//#endregion
|
|
245
|
+
//#region ../1-core/contract/src/ir/unique-constraint.d.ts
|
|
246
|
+
interface UniqueConstraintInput {
|
|
247
|
+
readonly columns: readonly string[];
|
|
248
|
+
readonly name?: string;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* SQL Contract IR node for a table-level unique constraint.
|
|
252
|
+
*/
|
|
253
|
+
declare class UniqueConstraint extends SqlNode {
|
|
254
|
+
readonly columns: readonly string[];
|
|
255
|
+
readonly name?: string;
|
|
256
|
+
constructor(input: UniqueConstraintInput);
|
|
257
|
+
}
|
|
258
|
+
//#endregion
|
|
259
|
+
//#region ../1-core/contract/src/ir/storage-table.d.ts
|
|
260
|
+
interface StorageTableInput$1 {
|
|
261
|
+
readonly columns: Record<string, StorageColumn | StorageColumnInput>;
|
|
262
|
+
readonly primaryKey?: PrimaryKey | PrimaryKeyInput;
|
|
263
|
+
readonly uniques: ReadonlyArray<UniqueConstraint | UniqueConstraintInput>;
|
|
264
|
+
readonly indexes: ReadonlyArray<Index | IndexInput>;
|
|
265
|
+
readonly foreignKeys: ReadonlyArray<ForeignKey | ForeignKeyInput>;
|
|
266
|
+
readonly control?: ControlPolicy;
|
|
267
|
+
readonly checks?: ReadonlyArray<CheckConstraint | CheckConstraintInput>;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* SQL Contract IR node for a single table entry in a namespace's
|
|
271
|
+
* `tables` map.
|
|
272
|
+
*
|
|
273
|
+
* The constructor normalises nested IR-class fields (columns, primary
|
|
274
|
+
* key, uniques, indexes, foreign keys) into the appropriate class
|
|
275
|
+
* instances so downstream walks see a uniform AST regardless of whether
|
|
276
|
+
* the input was a JSON literal or an already-constructed class.
|
|
277
|
+
*
|
|
278
|
+
* The table's `name` is not on the class — tables are keyed by name in
|
|
279
|
+
* the parent namespace's `tables: Record<string, StorageTable>` map.
|
|
280
|
+
*/
|
|
281
|
+
declare class StorageTable extends SqlNode {
|
|
282
|
+
readonly columns: Readonly<Record<string, StorageColumn>>;
|
|
283
|
+
readonly uniques: ReadonlyArray<UniqueConstraint>;
|
|
284
|
+
readonly indexes: ReadonlyArray<Index>;
|
|
285
|
+
readonly foreignKeys: ReadonlyArray<ForeignKey>;
|
|
286
|
+
readonly primaryKey?: PrimaryKey;
|
|
287
|
+
readonly control?: ControlPolicy;
|
|
288
|
+
readonly checks?: ReadonlyArray<CheckConstraint>;
|
|
289
|
+
constructor(input: StorageTableInput$1);
|
|
290
|
+
/**
|
|
291
|
+
* Runtime guard that a namespace `table` entry is really a `StorageTable`.
|
|
292
|
+
* The compiler already types the entry as `StorageTable`, but a
|
|
293
|
+
* freshly-deserialized contract may carry plain JSON at that slot until
|
|
294
|
+
* hydration; this duck-types the structural shape. Accepts `undefined` so
|
|
295
|
+
* optional-chained entry lookups pass straight through.
|
|
296
|
+
*/
|
|
297
|
+
static is(value: StorageTable | undefined): value is StorageTable;
|
|
298
|
+
static assert(value: StorageTable | undefined, coordinate: string): asserts value is StorageTable;
|
|
299
|
+
}
|
|
300
|
+
//#endregion
|
|
301
|
+
//#region ../1-core/contract/src/ir/storage-value-set.d.ts
|
|
302
|
+
/**
|
|
303
|
+
* Hydration / construction input shape for {@link StorageValueSet}.
|
|
304
|
+
* Mirrors the on-disk storage JSON envelope so the serializer hydration
|
|
305
|
+
* walker can hand a validated literal straight to `new`.
|
|
306
|
+
*/
|
|
307
|
+
interface StorageValueSetInput {
|
|
308
|
+
readonly kind: 'valueSet';
|
|
309
|
+
/** Ordered permitted values, codec-encoded. Declaration order is preserved. */
|
|
310
|
+
readonly values: readonly JsonValue[];
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* SQL Contract IR node for a value-set entry in a namespace's `valueSet`
|
|
314
|
+
* map (`SqlNamespace.entries.valueSet`).
|
|
315
|
+
*
|
|
316
|
+
* A value-set records the ordered set of permitted codec-encoded values for
|
|
317
|
+
* an enum-like column restriction. It does not carry a `codecId` — the
|
|
318
|
+
* column that references it already holds the codec; the value-set holds
|
|
319
|
+
* only the permitted values.
|
|
320
|
+
*
|
|
321
|
+
* The node's `kind` is enumerable (`'valueSet'`) so the JSON envelope
|
|
322
|
+
* carries the discriminator and the serializer hydration walker can
|
|
323
|
+
* dispatch on it. This follows the per-leaf enumerable-kind convention
|
|
324
|
+
* established in the SQL-node comment (future polymorphic dispatch on
|
|
325
|
+
* namespace entries needs the discriminator in JSON).
|
|
326
|
+
*
|
|
327
|
+
* The entry's name is not on the class — value-sets are keyed by name in
|
|
328
|
+
* the parent namespace's `valueSet: Record<string, StorageValueSet>` map.
|
|
329
|
+
*/
|
|
330
|
+
declare class StorageValueSet extends SqlNode {
|
|
331
|
+
readonly kind: "valueSet";
|
|
332
|
+
readonly values: readonly JsonValue[];
|
|
333
|
+
constructor(input: StorageValueSetInput);
|
|
334
|
+
}
|
|
335
|
+
//#endregion
|
|
336
|
+
//#region ../1-core/contract/src/ir/sql-storage.d.ts
|
|
337
|
+
interface SqlNamespaceInput {
|
|
338
|
+
readonly id: string;
|
|
339
|
+
readonly entries: Readonly<Record<string, Readonly<Record<string, unknown>>>>;
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* SQL Contract IR root node for the `storage` field.
|
|
343
|
+
*
|
|
344
|
+
* Single concrete family-shared class — both Postgres and SQLite
|
|
345
|
+
* consume this class today. Per-target storage subclasses are
|
|
346
|
+
* introduced when each target's namespace shape earns its
|
|
347
|
+
* target-specific concretion (target-specific derived fields,
|
|
348
|
+
* target-specific storage extensions).
|
|
349
|
+
*
|
|
350
|
+
* Honours the framework `Storage` interface: every SQL IR carries a
|
|
351
|
+
* `namespaces` map keyed by namespace id. Callers must supply fully
|
|
352
|
+
* constructed `Namespace` instances — construction discipline lives
|
|
353
|
+
* in the authoring builders and deserializer hydration paths.
|
|
354
|
+
*
|
|
355
|
+
* The constructor normalises optional `types` into class instances.
|
|
356
|
+
* `types` is polymorphic per Decision 18 Option B: codec-triple inputs
|
|
357
|
+
* are stamped with `kind: 'codec-instance'`; hydration of raw JSON
|
|
358
|
+
* class-instance entries (carrying their narrower `kind` literal) is
|
|
359
|
+
* the per-target serializer's responsibility (so the family base does
|
|
360
|
+
* not import target-specific subclasses).
|
|
361
|
+
*/
|
|
362
|
+
/**
|
|
363
|
+
* The typed `entries` shape for SQL family namespaces. The open dictionary
|
|
364
|
+
* is intersected with optional known-kind maps so that `ns.entries.table`
|
|
365
|
+
* and `ns.entries.valueSet` resolve without a cast, while unknown pack-
|
|
366
|
+
* contributed kinds remain valid (the `Record` part allows any string key).
|
|
367
|
+
*/
|
|
368
|
+
type SqlNamespaceEntries = Readonly<Record<string, Readonly<Record<string, unknown>>>> & {
|
|
369
|
+
readonly table?: Readonly<Record<string, StorageTable>>;
|
|
370
|
+
readonly valueSet?: Readonly<Record<string, StorageValueSet>>;
|
|
371
|
+
};
|
|
372
|
+
/**
|
|
373
|
+
* Structural interface for SQL family namespaces. Generated `.d.ts` contract
|
|
374
|
+
* types satisfy this structurally (no prototype methods). The runtime
|
|
375
|
+
* abstract class `SqlNamespaceBase` extends this.
|
|
376
|
+
*
|
|
377
|
+
* `qualifyTable` and `isUnbound` are optional so JSON-shaped contract types
|
|
378
|
+
* (which carry no methods) are accepted where `SqlNamespace` is required.
|
|
379
|
+
* Hydrated `SqlNamespaceBase` instances always have both.
|
|
380
|
+
*/
|
|
381
|
+
interface SqlNamespace {
|
|
382
|
+
readonly kind: string;
|
|
383
|
+
readonly id: string;
|
|
384
|
+
readonly entries: SqlNamespaceEntries;
|
|
385
|
+
readonly isUnbound?: boolean;
|
|
386
|
+
qualifyTable?(tableName: string): string;
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Abstract SQL family namespace base class. Target concretions (`PostgresSchema`,
|
|
390
|
+
* `SqliteDatabase`, …) extend this — it is never instantiated directly.
|
|
391
|
+
* `entries` is the open ADR 224 dictionary: `entries[entityKind][entityName]`
|
|
392
|
+
* addresses any entity.
|
|
393
|
+
*/
|
|
394
|
+
declare abstract class SqlNamespaceBase extends NamespaceBase implements SqlNamespace {
|
|
395
|
+
abstract readonly id: string;
|
|
396
|
+
abstract readonly entries: SqlNamespaceEntries;
|
|
397
|
+
abstract qualifyTable(tableName: string): string;
|
|
398
|
+
}
|
|
399
|
+
//#endregion
|
|
400
|
+
//#region ../1-core/contract/test/test-support.d.ts
|
|
401
|
+
/**
|
|
402
|
+
* Minimal concrete `SqlNamespaceBase` for use in `packages/2-sql/**` unit tests.
|
|
403
|
+
*
|
|
404
|
+
* This is a legitimate target concretion — not a materialised family
|
|
405
|
+
* namespace. Production code never constructs one; the target-specific
|
|
406
|
+
* concretions (`PostgresSchema`, `SqliteDatabase`) are used in production.
|
|
407
|
+
*/
|
|
408
|
+
declare class TestSqlNamespace extends SqlNamespaceBase {
|
|
409
|
+
readonly kind: 'test-sql-namespace';
|
|
410
|
+
readonly id: string;
|
|
411
|
+
readonly entries: SqlNamespaceEntries;
|
|
412
|
+
constructor(input: SqlNamespaceInput);
|
|
413
|
+
get table(): Readonly<Record<string, StorageTable>>;
|
|
414
|
+
get valueSet(): Readonly<Record<string, StorageValueSet>> | undefined;
|
|
415
|
+
qualifyTable(tableName: string): string;
|
|
416
|
+
}
|
|
417
|
+
declare function createTestSqlNamespace(input: SqlNamespaceInput): TestSqlNamespace;
|
|
418
|
+
//#endregion
|
|
12
419
|
//#region test/utils.d.ts
|
|
13
420
|
type CreateTestRuntimeOptions<TContract extends Contract<SqlStorage>> = Omit<RuntimeOptions<TContract>, 'adapter'> & {
|
|
14
421
|
readonly stackInstance: {
|
|
@@ -99,7 +506,7 @@ type StubAdapter = Adapter<SelectAst, Contract<SqlStorage>, LoweredStatement> &
|
|
|
99
506
|
* The stub adapter includes simple codecs for common test types (pg/int4@1, pg/text@1, pg/timestamptz@1) to enable type inference in tests without requiring the postgres adapter package.
|
|
100
507
|
*/
|
|
101
508
|
declare function createStubAdapter(): StubAdapter;
|
|
102
|
-
declare function unboundNamespaceWithTables(tables: Record<string, StorageTableInput>): ReturnType<typeof
|
|
509
|
+
declare function unboundNamespaceWithTables(tables: Record<string, StorageTableInput>): ReturnType<typeof createTestSqlNamespace>;
|
|
103
510
|
declare function emptySqlTestDomain(): import("@prisma-next/contract/types").ApplicationDomain;
|
|
104
511
|
declare function createTestContract(contract: Partial<Omit<Contract<SqlStorage>, 'profileHash' | 'storage' | 'domain'>> & {
|
|
105
512
|
storageHash?: string;
|
|
@@ -110,5 +517,5 @@ declare function createTestContract(contract: Partial<Omit<Contract<SqlStorage>,
|
|
|
110
517
|
}): Contract<SqlStorage>;
|
|
111
518
|
declare function stubAst(): AnyQueryAst;
|
|
112
519
|
//#endregion
|
|
113
|
-
export { type DevDatabase, SeedMarkerInput, StubAdapter, buildTestContractCodecs, collectAsync, createDevDatabase, createStubAdapter, createTestAdapterDescriptor, createTestContext, createTestContract, createTestRuntime, createTestStackInstance, createTestTargetDescriptor, descriptorsFromCodecs, drainPlanExecution, emptySqlTestDomain, executePlanAndCollect, seedTestMarker, setupTestDatabase, stubAst, teardownTestDatabase, unboundNamespaceWithTables, withClient, writeTestContractMarker };
|
|
520
|
+
export { type DevDatabase, SeedMarkerInput, StubAdapter, buildDecodeContext, buildTestContractCodecs, collectAsync, createDevDatabase, createStubAdapter, createTestAdapterDescriptor, createTestContext, createTestContract, createTestRuntime, createTestStackInstance, createTestTargetDescriptor, decodeRow, descriptorsFromCodecs, drainPlanExecution, emptySqlTestDomain, executePlanAndCollect, seedTestMarker, setupTestDatabase, stubAst, teardownTestDatabase, unboundNamespaceWithTables, withClient, writeTestContractMarker };
|
|
114
521
|
//# sourceMappingURL=utils.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.mts","names":[],"sources":["../../test/utils.ts"],"mappings":";;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"utils.d.mts","names":[],"sources":["../../../1-core/contract/src/ir/sql-node.ts","../../../1-core/contract/src/ir/check-constraint.ts","../../../1-core/contract/src/ir/foreign-key-reference.ts","../../../1-core/contract/src/ir/foreign-key.ts","../../../1-core/contract/src/ir/primary-key.ts","../../../1-core/contract/src/ir/sql-index.ts","../../../1-core/contract/src/ir/storage-column.ts","../../../1-core/contract/src/ir/unique-constraint.ts","../../../1-core/contract/src/ir/storage-table.ts","../../../1-core/contract/src/ir/storage-value-set.ts","../../../1-core/contract/src/ir/sql-storage.ts","../../../1-core/contract/test/test-support.ts","../../test/utils.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAkCA;;;;;;;;;;;;ACzBA;;;;;;;uBDyBsB,OAAA,SAAgB,UAAU;EAAA,SACrC,IAAA;;;;;;;;;;UC1BM,oBAAA;EAAA,SACN,IAAA;EAAA,SACA,MAAA;EAAA,SACA,QAAA,EAAU,WAAW;AAAA;;;ADsBhC;;;;;;;;;;;;cCLa,eAAA,SAAwB,OAAA;EAAA,SAC1B,IAAA;EAAA,SACA,MAAA;EAAA,SACA,QAAA,EAAU,WAAA;cAEP,KAAA,EAAO,oBAAA;AAAA;;;;;;;;;;;;;;UCnBJ,wBAAA;EAAA,SACN,WAAA;EAAA,SACA,SAAA;EAAA,SACA,OAAA;EAAA,SACA,OAAA;AAAA;;;;;;;;ADVX;;;;;;;;;cC6Ba,mBAAA,SAA4B,OAAA;EAAA,SAC9B,WAAA,EAAa,WAAA;EAAA,SACb,SAAA;EAAA,SACA,OAAA;EAAA,SACQ,OAAA;cAEL,KAAA,EAAO,wBAAA;AAAA;;;KCxCT,iBAAA;AAAA,UAEK,eAAA;EAAA,SACN,MAAA,EAAQ,mBAAA,GAAsB,wBAAA;EAAA,SAC9B,MAAA,EAAQ,mBAAA,GAAsB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