@prisma-next/sql-contract 0.13.0 → 0.14.0-dev.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{types-DqhaAjCH.mjs → entity-kinds-Cl36zL5j.mjs} +121 -205
- package/dist/entity-kinds-Cl36zL5j.mjs.map +1 -0
- package/dist/entity-kinds.d.mts +18 -0
- package/dist/entity-kinds.d.mts.map +1 -0
- package/dist/entity-kinds.mjs +2 -0
- package/dist/factories.d.mts +2 -2
- package/dist/factories.mjs +2 -1
- package/dist/factories.mjs.map +1 -1
- package/dist/index-type-validation.d.mts +1 -1
- package/dist/index-type-validation.mjs +9 -12
- package/dist/index-type-validation.mjs.map +1 -1
- package/dist/resolve-storage-table.d.mts +2 -1
- package/dist/resolve-storage-table.d.mts.map +1 -1
- package/dist/resolve-storage-table.mjs +11 -8
- package/dist/resolve-storage-table.mjs.map +1 -1
- package/dist/sql-storage-Dga0jwP2.d.mts +128 -0
- package/dist/sql-storage-Dga0jwP2.d.mts.map +1 -0
- package/dist/{sql-storage-CXf9xjAL.d.mts → storage-value-set-WnYsIFM8.d.mts} +8 -120
- package/dist/storage-value-set-WnYsIFM8.d.mts.map +1 -0
- package/dist/types-B-eiQXff.mjs +191 -0
- package/dist/types-B-eiQXff.mjs.map +1 -0
- package/dist/{types-DEnWD3xB.d.mts → types-B1N8w0I2.d.mts} +11 -62
- package/dist/types-B1N8w0I2.d.mts.map +1 -0
- package/dist/types.d.mts +4 -3
- package/dist/types.mjs +3 -2
- package/dist/validators.d.mts +75 -40
- package/dist/validators.d.mts.map +1 -1
- package/dist/validators.mjs +54 -184
- package/dist/validators.mjs.map +1 -1
- package/package.json +8 -7
- package/src/entity-kinds.ts +45 -0
- package/src/exports/entity-kinds.ts +5 -0
- package/src/exports/types.ts +2 -4
- package/src/index-type-validation.ts +2 -3
- package/src/ir/build-sql-namespace.ts +39 -32
- package/src/ir/sql-node.ts +2 -2
- package/src/ir/sql-storage.ts +22 -24
- package/src/ir/sql-unbound-namespace.ts +15 -3
- package/src/ir/storage-entry-schemas.ts +128 -0
- package/src/ir/storage-type-instance.ts +3 -3
- package/src/ir/storage-value-set.ts +6 -5
- package/src/resolve-storage-table.ts +12 -17
- package/src/types.ts +10 -10
- package/src/validators.ts +84 -225
- package/dist/sql-storage-CXf9xjAL.d.mts.map +0 -1
- package/dist/types-DEnWD3xB.d.mts.map +0 -1
- package/dist/types-DqhaAjCH.mjs.map +0 -1
- package/src/ir/postgres-enum-storage-entry.ts +0 -57
|
@@ -1,56 +1,102 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { type } from "arktype";
|
|
2
|
+
import { IRNodeBase, freezeNode } from "@prisma-next/framework-components/ir";
|
|
3
3
|
import { asNamespaceId } from "@prisma-next/contract/types";
|
|
4
|
-
//#region src/ir/
|
|
4
|
+
//#region src/ir/storage-entry-schemas.ts
|
|
5
|
+
const literalKindSchema = type("'literal'");
|
|
6
|
+
const functionKindSchema = type("'function'");
|
|
7
|
+
const ControlPolicySchema = type("'managed' | 'tolerated' | 'external' | 'observed'");
|
|
8
|
+
const ColumnDefaultLiteralSchema = type.declare().type({
|
|
9
|
+
kind: literalKindSchema,
|
|
10
|
+
value: "string | number | boolean | null | unknown[] | Record<string, unknown>"
|
|
11
|
+
});
|
|
12
|
+
const ColumnDefaultFunctionSchema = type.declare().type({
|
|
13
|
+
kind: functionKindSchema,
|
|
14
|
+
expression: "string"
|
|
15
|
+
});
|
|
16
|
+
const ColumnDefaultSchema = ColumnDefaultLiteralSchema.or(ColumnDefaultFunctionSchema);
|
|
17
|
+
const StorageValueSetRefSchema = type({
|
|
18
|
+
plane: "'storage'",
|
|
19
|
+
namespaceId: "string",
|
|
20
|
+
entityKind: "'valueSet'",
|
|
21
|
+
entityName: "string",
|
|
22
|
+
"spaceId?": "string"
|
|
23
|
+
});
|
|
24
|
+
const StorageColumnSchema = type({
|
|
25
|
+
"+": "reject",
|
|
26
|
+
nativeType: "string",
|
|
27
|
+
codecId: "string",
|
|
28
|
+
nullable: "boolean",
|
|
29
|
+
"typeParams?": "Record<string, unknown>",
|
|
30
|
+
"typeRef?": "string",
|
|
31
|
+
"default?": ColumnDefaultSchema,
|
|
32
|
+
"control?": ControlPolicySchema,
|
|
33
|
+
"valueSet?": StorageValueSetRefSchema
|
|
34
|
+
}).narrow((col, ctx) => {
|
|
35
|
+
if (col.typeParams !== void 0 && col.typeRef !== void 0) return ctx.mustBe("a column with either typeParams or typeRef, not both");
|
|
36
|
+
return true;
|
|
37
|
+
});
|
|
5
38
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* SQL contracts honour the framework `Storage.namespaces` invariant from
|
|
11
|
-
* the moment they appear in the IR. Today `SqlStorage` is family-shared
|
|
12
|
-
* (Postgres + SQLite consume the same class); a per-target namespace
|
|
13
|
-
* concretion (`PostgresSchema.unbound`, `SqliteUnboundDatabase.instance`)
|
|
14
|
-
* earns its existence when each target's namespace shape lands. Until
|
|
15
|
-
* then the family ships a single placeholder singleton so the JSON
|
|
16
|
-
* envelope and runtime walk are honest at every layer.
|
|
17
|
-
*
|
|
18
|
-
* The `kind` discriminator is installed as a non-enumerable own property
|
|
19
|
-
* so the JSON envelope reads `{ "id": "__unbound__", "entries": { … } }`
|
|
20
|
-
* — symmetric with the family-level non-enumerable `kind` on `SqlNode`
|
|
21
|
-
* and bounded to the minimum data the framework `Namespace` interface
|
|
22
|
-
* promises.
|
|
23
|
-
*
|
|
24
|
-
* **Freeze-trap warning.** The leaf constructor calls
|
|
25
|
-
* `freezeNode(this)` after installing `kind`. The leaf-class shape
|
|
26
|
-
* works today only because `NamespaceBase` does NOT freeze in its
|
|
27
|
-
* constructor — the `Object.defineProperty(this, 'kind', …)` call after
|
|
28
|
-
* `super()` succeeds because the instance is still mutable at that
|
|
29
|
-
* point. Subclasses that add instance fields will still hit the freeze
|
|
30
|
-
* trap once leaf-class `freezeNode(this)` runs; and if a future
|
|
31
|
-
* framework change lifts the freeze to `NamespaceBase`, even the
|
|
32
|
-
* `defineProperty` here would silently fail. To add subclass instance
|
|
33
|
-
* fields safely, lift `freezeNode` to a leaf-class `seal()` hook each
|
|
34
|
-
* leaf calls explicitly at the end of its own constructor.
|
|
39
|
+
* Storage value-set entry under `storage.namespaces[id].entries.valueSet[name]`.
|
|
40
|
+
* Carries a `kind: 'valueSet'` discriminator (enumerable, survives JSON) and an
|
|
41
|
+
* ordered `values` array of codec-encoded permitted values.
|
|
35
42
|
*/
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
};
|
|
43
|
+
const StorageValueSetSchema = type({
|
|
44
|
+
kind: "'valueSet'",
|
|
45
|
+
values: type("string | number | boolean | null | unknown[] | Record<string, unknown>").array().readonly()
|
|
46
|
+
});
|
|
47
|
+
const PrimaryKeySchema = type.declare().type({
|
|
48
|
+
columns: type.string.array().readonly(),
|
|
49
|
+
"name?": "string"
|
|
50
|
+
});
|
|
51
|
+
const UniqueConstraintSchema = type.declare().type({
|
|
52
|
+
columns: type.string.array().readonly(),
|
|
53
|
+
"name?": "string"
|
|
54
|
+
});
|
|
55
|
+
const IndexSchema = type({
|
|
56
|
+
columns: type.string.array().readonly(),
|
|
57
|
+
"name?": "string",
|
|
58
|
+
"type?": "string",
|
|
59
|
+
"options?": "Record<string, unknown>"
|
|
60
|
+
});
|
|
61
|
+
const ForeignKeyReferenceSchema = type({
|
|
62
|
+
"+": "reject",
|
|
63
|
+
namespaceId: "string",
|
|
64
|
+
tableName: "string",
|
|
65
|
+
columns: type.string.array().readonly(),
|
|
66
|
+
"spaceId?": "string"
|
|
67
|
+
});
|
|
68
|
+
const ForeignKeySourceSchema = type({
|
|
69
|
+
"+": "reject",
|
|
70
|
+
namespaceId: "string",
|
|
71
|
+
tableName: "string",
|
|
72
|
+
columns: type.string.array().readonly()
|
|
73
|
+
});
|
|
74
|
+
const ReferentialActionSchema = type.declare().type("'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault'");
|
|
75
|
+
const ForeignKeySchema = type.declare().type({
|
|
76
|
+
source: ForeignKeySourceSchema,
|
|
77
|
+
target: ForeignKeyReferenceSchema,
|
|
78
|
+
"name?": "string",
|
|
79
|
+
"onDelete?": ReferentialActionSchema,
|
|
80
|
+
"onUpdate?": ReferentialActionSchema,
|
|
81
|
+
constraint: "boolean",
|
|
82
|
+
index: "boolean"
|
|
83
|
+
});
|
|
84
|
+
const CheckConstraintSchema = type({
|
|
85
|
+
"+": "reject",
|
|
86
|
+
name: "string",
|
|
87
|
+
column: "string",
|
|
88
|
+
valueSet: StorageValueSetRefSchema
|
|
89
|
+
});
|
|
90
|
+
const StorageTableSchema = type({
|
|
91
|
+
"+": "reject",
|
|
92
|
+
columns: type({ "[string]": StorageColumnSchema }),
|
|
93
|
+
"primaryKey?": PrimaryKeySchema,
|
|
94
|
+
uniques: UniqueConstraintSchema.array().readonly(),
|
|
95
|
+
indexes: IndexSchema.array().readonly(),
|
|
96
|
+
foreignKeys: ForeignKeySchema.array().readonly(),
|
|
97
|
+
"control?": ControlPolicySchema,
|
|
98
|
+
"checks?": CheckConstraintSchema.array().readonly()
|
|
99
|
+
});
|
|
54
100
|
//#endregion
|
|
55
101
|
//#region src/ir/sql-node.ts
|
|
56
102
|
/**
|
|
@@ -310,7 +356,7 @@ var StorageTable = class extends SqlNode {
|
|
|
310
356
|
* column that references it already holds the codec; the value-set holds
|
|
311
357
|
* only the permitted values.
|
|
312
358
|
*
|
|
313
|
-
* The node's `kind` is enumerable (`'
|
|
359
|
+
* The node's `kind` is enumerable (`'valueSet'`) so the JSON envelope
|
|
314
360
|
* carries the discriminator and the serializer hydration walker can
|
|
315
361
|
* dispatch on it. This follows the per-leaf enumerable-kind convention
|
|
316
362
|
* established in the SQL-node comment (future polymorphic dispatch on
|
|
@@ -320,7 +366,7 @@ var StorageTable = class extends SqlNode {
|
|
|
320
366
|
* the parent namespace's `valueSet: Record<string, StorageValueSet>` map.
|
|
321
367
|
*/
|
|
322
368
|
var StorageValueSet = class extends SqlNode {
|
|
323
|
-
kind = "
|
|
369
|
+
kind = "valueSet";
|
|
324
370
|
values;
|
|
325
371
|
constructor(input) {
|
|
326
372
|
super();
|
|
@@ -329,164 +375,34 @@ var StorageValueSet = class extends SqlNode {
|
|
|
329
375
|
}
|
|
330
376
|
};
|
|
331
377
|
//#endregion
|
|
332
|
-
//#region src/
|
|
333
|
-
const
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
if (proto === Object.prototype || proto === null) return false;
|
|
338
|
-
return ns.kind === SQL_NAMESPACE_KIND;
|
|
339
|
-
}
|
|
340
|
-
var SqlBoundNamespace = class SqlBoundNamespace extends NamespaceBase {
|
|
341
|
-
id;
|
|
342
|
-
entries;
|
|
343
|
-
static fromTablesInput(input) {
|
|
344
|
-
const tableCount = Object.keys(input.entries.table).length;
|
|
345
|
-
const hasValueSets = input.entries.valueSet !== void 0 && Object.keys(input.entries.valueSet).length > 0;
|
|
346
|
-
if (input.id === UNBOUND_NAMESPACE_ID && tableCount === 0 && !hasValueSets) return castAs(SqlUnboundNamespace.instance);
|
|
347
|
-
return castAs(new SqlBoundNamespace(input));
|
|
348
|
-
}
|
|
349
|
-
constructor(input) {
|
|
350
|
-
super();
|
|
351
|
-
this.id = input.id;
|
|
352
|
-
const table = Object.freeze(Object.fromEntries(Object.entries(input.entries.table).map(([k, v]) => [k, new StorageTable(v)])));
|
|
353
|
-
if (input.entries.valueSet !== void 0) {
|
|
354
|
-
const valueSet = Object.freeze(Object.fromEntries(Object.entries(input.entries.valueSet).map(([k, v]) => [k, new StorageValueSet(v)])));
|
|
355
|
-
this.entries = Object.freeze({
|
|
356
|
-
table,
|
|
357
|
-
valueSet
|
|
358
|
-
});
|
|
359
|
-
} else this.entries = Object.freeze({ table });
|
|
360
|
-
Object.defineProperty(this, "kind", {
|
|
361
|
-
value: SQL_NAMESPACE_KIND,
|
|
362
|
-
writable: false,
|
|
363
|
-
enumerable: false,
|
|
364
|
-
configurable: true
|
|
365
|
-
});
|
|
366
|
-
freezeNode(this);
|
|
367
|
-
}
|
|
368
|
-
qualifyTable(tableName) {
|
|
369
|
-
if (this.id === UNBOUND_NAMESPACE_ID) return `"${tableName}"`;
|
|
370
|
-
return `"${this.id}"."${tableName}"`;
|
|
371
|
-
}
|
|
378
|
+
//#region src/entity-kinds.ts
|
|
379
|
+
const tableEntityKind = {
|
|
380
|
+
kind: "table",
|
|
381
|
+
schema: StorageTableSchema,
|
|
382
|
+
construct: (input) => new StorageTable(input)
|
|
372
383
|
};
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
return Object.fromEntries(Object.entries(namespaces).map(([nsKey, ns]) => [nsKey, isMaterializedSqlNamespace(ns) ? blindCast(ns) : SqlBoundNamespace.fromTablesInput(blindCast(ns))]));
|
|
378
|
-
}
|
|
379
|
-
//#endregion
|
|
380
|
-
//#region src/ir/postgres-enum-storage-entry.ts
|
|
381
|
-
/**
|
|
382
|
-
* Discriminator literal for the Postgres-enum variant on the polymorphic
|
|
383
|
-
* `SqlStorage.types` slot.
|
|
384
|
-
*
|
|
385
|
-
* Enums are a target-level concept: Postgres ships native
|
|
386
|
-
* `CREATE TYPE … AS ENUM` while other SQL targets approximate enums via
|
|
387
|
-
* constraints. The literal lives at the SQL family layer because every
|
|
388
|
-
* SQL-family consumer (verifier, planner, lowering, …) needs to
|
|
389
|
-
* discriminate enum-typed slot entries from codec-typed ones. The
|
|
390
|
-
* concrete IR class (`PostgresEnumType`) lives in the target-postgres
|
|
391
|
-
* package and implements this structural contract; cross-domain
|
|
392
|
-
* layering rules forbid the SQL family from importing the concrete
|
|
393
|
-
* target class directly, so the discriminator and structural interface
|
|
394
|
-
* carry the dispatch.
|
|
395
|
-
*/
|
|
396
|
-
const POSTGRES_ENUM_KIND = "postgres-enum";
|
|
397
|
-
/**
|
|
398
|
-
* Narrow a polymorphic `StorageType` entry to the Postgres-enum shape
|
|
399
|
-
* via its enumerable `kind` discriminator. Type guard returns true for
|
|
400
|
-
* both live `PostgresEnumType` instances and raw JSON envelopes.
|
|
401
|
-
*/
|
|
402
|
-
function isPostgresEnumStorageEntry(value) {
|
|
403
|
-
if (typeof value !== "object" || value === null) return false;
|
|
404
|
-
return value.kind === POSTGRES_ENUM_KIND;
|
|
405
|
-
}
|
|
406
|
-
//#endregion
|
|
407
|
-
//#region src/ir/storage-type-instance.ts
|
|
408
|
-
/**
|
|
409
|
-
* Sentinel kind for the legacy codec-triple shape persisted under
|
|
410
|
-
* `SqlStorage.types`. Plain JSON-clean object literals carry this
|
|
411
|
-
* discriminator so the polymorphic slot dispatch can route them down
|
|
412
|
-
* the codec path while target-specific IR class instances (e.g. the
|
|
413
|
-
* Postgres enum class) keep their own narrower `kind` literal.
|
|
414
|
-
*/
|
|
415
|
-
const CODEC_INSTANCE_KIND = "codec-instance";
|
|
416
|
-
/**
|
|
417
|
-
* Stamp the codec-instance `kind` discriminator on a caller-supplied
|
|
418
|
-
* codec triple. Idempotent: input that already carries the discriminator
|
|
419
|
-
* passes through unchanged. Missing `typeParams` is normalised to `{}`.
|
|
420
|
-
*/
|
|
421
|
-
function toStorageTypeInstance(input) {
|
|
422
|
-
return {
|
|
423
|
-
kind: CODEC_INSTANCE_KIND,
|
|
424
|
-
codecId: input.codecId,
|
|
425
|
-
nativeType: input.nativeType,
|
|
426
|
-
typeParams: input.typeParams ?? {}
|
|
427
|
-
};
|
|
428
|
-
}
|
|
429
|
-
/**
|
|
430
|
-
* Type-guard for codec-typed entries on the polymorphic
|
|
431
|
-
* `SqlStorage.types` slot. Distinguishes `StorageTypeInstance` from
|
|
432
|
-
* class-instance kinds (e.g. `PostgresEnumType`).
|
|
433
|
-
*/
|
|
434
|
-
function isStorageTypeInstance(value) {
|
|
435
|
-
if (typeof value !== "object" || value === null) return false;
|
|
436
|
-
return value.kind === CODEC_INSTANCE_KIND;
|
|
437
|
-
}
|
|
438
|
-
//#endregion
|
|
439
|
-
//#region src/ir/sql-storage.ts
|
|
440
|
-
var SqlStorage = class extends SqlNode {
|
|
441
|
-
storageHash;
|
|
442
|
-
namespaces;
|
|
443
|
-
constructor(input) {
|
|
444
|
-
super();
|
|
445
|
-
this.storageHash = input.storageHash;
|
|
446
|
-
this.namespaces = Object.freeze(input.namespaces);
|
|
447
|
-
if (input.types !== void 0) this.types = Object.freeze(Object.fromEntries(Object.entries(input.types).map(([name, ti]) => [name, normaliseTypeEntry(name, ti)])));
|
|
448
|
-
freezeNode(this);
|
|
449
|
-
}
|
|
384
|
+
const valueSetEntityKind = {
|
|
385
|
+
kind: "valueSet",
|
|
386
|
+
schema: StorageValueSetSchema,
|
|
387
|
+
construct: (input) => new StorageValueSet(input)
|
|
450
388
|
};
|
|
451
|
-
function storageTableAt(storage, namespaceId, tableName) {
|
|
452
|
-
return storage.namespaces[namespaceId]?.entries.table[tableName];
|
|
453
|
-
}
|
|
454
389
|
/**
|
|
455
|
-
*
|
|
456
|
-
*
|
|
457
|
-
*
|
|
458
|
-
*
|
|
459
|
-
*
|
|
460
|
-
*
|
|
461
|
-
* downstream IR walks.
|
|
462
|
-
*
|
|
463
|
-
* Codec-triple authors that have an untagged shape on hand can call
|
|
464
|
-
* `toStorageTypeInstance(...)` (which stamps the `'codec-instance'`
|
|
465
|
-
* discriminator) before constructing `SqlStorage`. On-disk reads
|
|
466
|
-
* cross `familyInstance.deserializeContract` first; the structural
|
|
467
|
-
* arktype schema rejects untagged entries earlier, so this throw
|
|
468
|
-
* only fires for in-memory authoring bugs.
|
|
390
|
+
* Assembles the `kind → descriptor` registry for SQL namespaces: the built-in
|
|
391
|
+
* `table` and `valueSet` kinds plus any target `packKinds`. This builds the
|
|
392
|
+
* lookup table — it does not touch contract data. `hydrateNamespaceEntities`
|
|
393
|
+
* later consumes this registry to turn a namespace's raw entries into IR
|
|
394
|
+
* instances, and `createSqlContractSchema` derives validation from the same
|
|
395
|
+
* registry. Throws on a duplicate kind.
|
|
469
396
|
*/
|
|
470
|
-
function
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
397
|
+
function composeSqlEntityKinds(packKinds = []) {
|
|
398
|
+
const kinds = new Map([["table", tableEntityKind], ["valueSet", valueSetEntityKind]]);
|
|
399
|
+
for (const descriptor of packKinds) {
|
|
400
|
+
if (kinds.has(descriptor.kind)) throw new Error(`composeSqlEntityKinds: duplicate entity kind "${descriptor.kind}" — each kind may be registered only once`);
|
|
401
|
+
kinds.set(descriptor.kind, descriptor);
|
|
474
402
|
}
|
|
475
|
-
|
|
476
|
-
const kindDescription = rawKind === void 0 ? "missing `kind` discriminator" : `unrecognised \`kind\` discriminator ${JSON.stringify(rawKind)}`;
|
|
477
|
-
throw new Error(`storage.types[${JSON.stringify(name)}] has ${kindDescription}; expected ${JSON.stringify("codec-instance")}. Untagged codec triples should be wrapped with toStorageTypeInstance(...) before construction.`);
|
|
478
|
-
}
|
|
479
|
-
//#endregion
|
|
480
|
-
//#region src/types.ts
|
|
481
|
-
const DEFAULT_FK_CONSTRAINT = true;
|
|
482
|
-
const DEFAULT_FK_INDEX = true;
|
|
483
|
-
function applyFkDefaults(fk, overrideDefaults) {
|
|
484
|
-
return {
|
|
485
|
-
constraint: fk.constraint ?? overrideDefaults?.constraint ?? true,
|
|
486
|
-
index: fk.index ?? overrideDefaults?.index ?? true
|
|
487
|
-
};
|
|
403
|
+
return kinds;
|
|
488
404
|
}
|
|
489
405
|
//#endregion
|
|
490
|
-
export {
|
|
406
|
+
export { StorageTableSchema as C, ReferentialActionSchema as S, ColumnDefaultSchema as _, StorageTable as a, ForeignKeySourceSchema as b, Index as c, ForeignKeyReference as d, CheckConstraint as f, ColumnDefaultLiteralSchema as g, ColumnDefaultFunctionSchema as h, StorageValueSet as i, PrimaryKey as l, CheckConstraintSchema as m, tableEntityKind as n, UniqueConstraint as o, SqlNode as p, valueSetEntityKind as r, StorageColumn as s, composeSqlEntityKinds as t, ForeignKey as u, ForeignKeyReferenceSchema as v, StorageValueSetSchema as w, IndexSchema as x, ForeignKeySchema as y };
|
|
491
407
|
|
|
492
|
-
//# sourceMappingURL=
|
|
408
|
+
//# sourceMappingURL=entity-kinds-Cl36zL5j.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity-kinds-Cl36zL5j.mjs","names":[],"sources":["../src/ir/storage-entry-schemas.ts","../src/ir/sql-node.ts","../src/ir/check-constraint.ts","../src/ir/foreign-key-reference.ts","../src/ir/foreign-key.ts","../src/ir/primary-key.ts","../src/ir/sql-index.ts","../src/ir/storage-column.ts","../src/ir/unique-constraint.ts","../src/ir/storage-table.ts","../src/ir/storage-value-set.ts","../src/entity-kinds.ts"],"sourcesContent":["import { type Type, type } from 'arktype';\nimport type { ForeignKeyInput, ReferentialAction } from './foreign-key';\nimport type { ForeignKeyReferenceInput } from './foreign-key-reference';\nimport type { PrimaryKeyInput } from './primary-key';\nimport type { UniqueConstraintInput } from './unique-constraint';\n\ntype ColumnDefaultLiteral = {\n readonly kind: 'literal';\n readonly value: string | number | boolean | Record<string, unknown> | unknown[] | null;\n};\ntype ColumnDefaultFunction = { readonly kind: 'function'; readonly expression: string };\n\nconst literalKindSchema = type(\"'literal'\");\nconst functionKindSchema = type(\"'function'\");\nconst ControlPolicySchema = type(\"'managed' | 'tolerated' | 'external' | 'observed'\");\n\nexport const ColumnDefaultLiteralSchema = type.declare<ColumnDefaultLiteral>().type({\n kind: literalKindSchema,\n value: 'string | number | boolean | null | unknown[] | Record<string, unknown>',\n});\n\nexport const ColumnDefaultFunctionSchema = type.declare<ColumnDefaultFunction>().type({\n kind: functionKindSchema,\n expression: 'string',\n});\n\nexport const ColumnDefaultSchema = ColumnDefaultLiteralSchema.or(ColumnDefaultFunctionSchema);\n\nconst StorageValueSetRefSchema = type({\n plane: \"'storage'\",\n namespaceId: 'string',\n entityKind: \"'valueSet'\",\n entityName: 'string',\n 'spaceId?': 'string',\n});\n\nconst StorageColumnSchema = type({\n '+': 'reject',\n nativeType: 'string',\n codecId: 'string',\n nullable: 'boolean',\n 'typeParams?': 'Record<string, unknown>',\n 'typeRef?': 'string',\n 'default?': ColumnDefaultSchema,\n 'control?': ControlPolicySchema,\n 'valueSet?': StorageValueSetRefSchema,\n}).narrow((col, ctx) => {\n if (col.typeParams !== undefined && col.typeRef !== undefined) {\n return ctx.mustBe('a column with either typeParams or typeRef, not both');\n }\n return true;\n});\n\n/**\n * Storage value-set entry under `storage.namespaces[id].entries.valueSet[name]`.\n * Carries a `kind: 'valueSet'` discriminator (enumerable, survives JSON) and an\n * ordered `values` array of codec-encoded permitted values.\n */\nexport const StorageValueSetSchema = type({\n kind: \"'valueSet'\",\n values: type('string | number | boolean | null | unknown[] | Record<string, unknown>')\n .array()\n .readonly(),\n});\n\nconst PrimaryKeySchema = type.declare<PrimaryKeyInput>().type({\n columns: type.string.array().readonly(),\n 'name?': 'string',\n});\n\nconst UniqueConstraintSchema = type.declare<UniqueConstraintInput>().type({\n columns: type.string.array().readonly(),\n 'name?': 'string',\n});\n\nexport const IndexSchema = type({\n columns: type.string.array().readonly(),\n 'name?': 'string',\n 'type?': 'string',\n 'options?': 'Record<string, unknown>',\n});\n\nexport const ForeignKeyReferenceSchema = type({\n '+': 'reject',\n namespaceId: 'string',\n tableName: 'string',\n columns: type.string.array().readonly(),\n 'spaceId?': 'string',\n}) satisfies Type<ForeignKeyReferenceInput>;\n\nexport const ForeignKeySourceSchema = type({\n '+': 'reject',\n namespaceId: 'string',\n tableName: 'string',\n columns: type.string.array().readonly(),\n}) satisfies Type<ForeignKeyReferenceInput>;\n\nexport const ReferentialActionSchema = type\n .declare<ReferentialAction>()\n .type(\"'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault'\");\n\nexport const ForeignKeySchema = type.declare<ForeignKeyInput>().type({\n source: ForeignKeySourceSchema,\n target: ForeignKeyReferenceSchema,\n 'name?': 'string',\n 'onDelete?': ReferentialActionSchema,\n 'onUpdate?': ReferentialActionSchema,\n constraint: 'boolean',\n index: 'boolean',\n});\n\nexport const CheckConstraintSchema = type({\n '+': 'reject',\n name: 'string',\n column: 'string',\n valueSet: StorageValueSetRefSchema,\n});\n\nexport const StorageTableSchema = type({\n '+': 'reject',\n columns: type({ '[string]': StorageColumnSchema }),\n 'primaryKey?': PrimaryKeySchema,\n uniques: UniqueConstraintSchema.array().readonly(),\n indexes: IndexSchema.array().readonly(),\n foreignKeys: ForeignKeySchema.array().readonly(),\n 'control?': ControlPolicySchema,\n 'checks?': CheckConstraintSchema.array().readonly(),\n});\n","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. StorageValueSet)\n // 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 type { ValueSetRef } 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 CheckConstraint}.\n * Mirrors the on-disk storage JSON envelope so the serializer hydration\n * walker can hand a validated literal straight to `new`.\n */\nexport interface CheckConstraintInput {\n readonly name: string;\n readonly column: string;\n readonly valueSet: ValueSetRef;\n}\n\n/**\n * SQL Contract IR node for a table-level check constraint that restricts\n * a column to the permitted values of a value-set.\n *\n * The constraint is **structured** (names a column and a value-set\n * reference), not a raw SQL expression. Each target renders its own DDL\n * from the structured form, keeping the contract target-agnostic.\n *\n * Construction is idempotent: passing an existing `CheckConstraint`\n * instance as input produces a new instance with identical fields.\n * The constructor does not use `instanceof` for input discrimination —\n * it reads plain named properties, which is sufficient since\n * `CheckConstraintInput` is a structural type.\n */\nexport class CheckConstraint extends SqlNode {\n readonly name: string;\n readonly column: string;\n readonly valueSet: ValueSetRef;\n\n constructor(input: CheckConstraintInput) {\n super();\n this.name = input.name;\n this.column = input.column;\n this.valueSet = input.valueSet;\n freezeNode(this);\n }\n}\n","import { asNamespaceId, type NamespaceId } from '@prisma-next/contract/types';\nimport { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from './sql-node';\n\n/**\n * Input for a foreign-key reference (one side of a foreign-key declaration).\n *\n * When `spaceId` is absent the reference is local — the referenced table lives\n * in the same contract-space. When `spaceId` is present the reference is\n * cross-space — the referenced table lives in a different contract-space\n * identified by `spaceId`.\n *\n * Presence-based discrimination keeps local FK JSON byte-identical to\n * contracts authored before cross-space support was added.\n */\nexport interface ForeignKeyReferenceInput {\n readonly namespaceId: string;\n readonly tableName: string;\n readonly columns: readonly string[];\n readonly spaceId?: string;\n}\n\n/**\n * SQL Contract IR node for one side (source or target) of a foreign-key\n * declaration. Carries the full coordinate: namespace, table, and columns.\n *\n * Cross-space discrimination is based on `spaceId` presence: absent means\n * local (same contract-space); present means cross-space (the referenced\n * table lives in the contract-space identified by `spaceId`).\n *\n * For local references `spaceId` is absent from JSON, keeping the serialized\n * shape byte-identical to contracts authored before cross-space support was\n * added. For cross-space references `spaceId` appears in JSON so round-trips\n * are lossless.\n *\n * Use `UNBOUND_NAMESPACE_ID` from `@prisma-next/framework-components/ir`\n * as the sentinel `namespaceId` for single-namespace (unbound) references.\n */\nexport class ForeignKeyReference extends SqlNode {\n readonly namespaceId: NamespaceId;\n readonly tableName: string;\n readonly columns: readonly string[];\n declare readonly spaceId?: string;\n\n constructor(input: ForeignKeyReferenceInput) {\n super();\n this.namespaceId = asNamespaceId(input.namespaceId);\n this.tableName = input.tableName;\n this.columns = input.columns;\n if (input.spaceId !== undefined) this.spaceId = input.spaceId;\n freezeNode(this);\n }\n}\n","import { freezeNode } from '@prisma-next/framework-components/ir';\nimport { ForeignKeyReference, type ForeignKeyReferenceInput } from './foreign-key-reference';\nimport { SqlNode } from './sql-node';\n\nexport type ReferentialAction = 'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault';\n\nexport interface ForeignKeyInput {\n readonly source: ForeignKeyReference | ForeignKeyReferenceInput;\n readonly target: ForeignKeyReference | ForeignKeyReferenceInput;\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 * Each FK carries explicit `source` and `target` {@link ForeignKeyReference}\n * coordinates (namespace, table, columns). For single-namespace contracts the\n * sentinel `UNBOUND_NAMESPACE_ID` appears on both sides.\n *\n * The nested references are normalised to {@link ForeignKeyReference}\n * instances inside the constructor so downstream walks see a uniform AST\n * regardless of whether the input was a JSON literal or an already-constructed\n * class instance.\n */\nexport class ForeignKey extends SqlNode {\n readonly source: ForeignKeyReference;\n readonly target: ForeignKeyReference;\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.source =\n input.source instanceof ForeignKeyReference\n ? input.source\n : new ForeignKeyReference(input.source);\n this.target =\n input.target instanceof ForeignKeyReference\n ? input.target\n : new ForeignKeyReference(input.target);\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 { 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 type { ColumnDefault, ControlPolicy, ValueSetRef } 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 readonly control?: ControlPolicy;\n readonly valueSet?: ValueSetRef;\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 declare readonly control?: ControlPolicy;\n declare readonly valueSet?: ValueSetRef;\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 if (input.control !== undefined) this.control = input.control;\n if (input.valueSet !== undefined) this.valueSet = input.valueSet;\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 type { ControlPolicy } from '@prisma-next/contract/types';\nimport { freezeNode } from '@prisma-next/framework-components/ir';\nimport { CheckConstraint, type CheckConstraintInput } from './check-constraint';\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 readonly control?: ControlPolicy;\n readonly checks?: ReadonlyArray<CheckConstraint | CheckConstraintInput>;\n}\n\n/**\n * SQL Contract IR node for a single table entry in a namespace's\n * `tables` map.\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 namespace's `tables: Record<string, StorageTable>` map.\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 declare readonly control?: ControlPolicy;\n declare readonly checks?: ReadonlyArray<CheckConstraint>;\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 if (input.control !== undefined) this.control = input.control;\n if (input.checks !== undefined && input.checks.length > 0) {\n this.checks = Object.freeze(input.checks.map((cc) => new CheckConstraint(cc)));\n }\n freezeNode(this);\n }\n}\n","import type { JsonValue } 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 StorageValueSet}.\n * Mirrors the on-disk storage JSON envelope so the serializer hydration\n * walker can hand a validated literal straight to `new`.\n */\nexport interface StorageValueSetInput {\n readonly kind: 'valueSet';\n /** Ordered permitted values, codec-encoded. Declaration order is preserved. */\n readonly values: readonly JsonValue[];\n}\n\n/**\n * SQL Contract IR node for a value-set entry in a namespace's `valueSet`\n * map (`SqlNamespace.entries.valueSet`).\n *\n * A value-set records the ordered set of permitted codec-encoded values for\n * an enum-like column restriction. It does not carry a `codecId` — the\n * column that references it already holds the codec; the value-set holds\n * only the permitted values.\n *\n * The node's `kind` is enumerable (`'valueSet'`) so the JSON envelope\n * carries the discriminator and the serializer hydration walker can\n * dispatch on it. This follows the per-leaf enumerable-kind convention\n * established in the SQL-node comment (future polymorphic dispatch on\n * namespace entries needs the discriminator in JSON).\n *\n * The entry's name is not on the class — value-sets are keyed by name in\n * the parent namespace's `valueSet: Record<string, StorageValueSet>` map.\n */\nexport class StorageValueSet extends SqlNode {\n override readonly kind = 'valueSet' as const;\n readonly values: readonly JsonValue[];\n\n constructor(input: StorageValueSetInput) {\n super();\n this.values = Object.freeze([...input.values]);\n freezeNode(this);\n }\n}\n","import type {\n AnyEntityKindDescriptor,\n EntityKindDescriptor,\n} from '@prisma-next/framework-components/ir';\nimport { StorageTableSchema, StorageValueSetSchema } from './ir/storage-entry-schemas';\nimport { StorageTable, type StorageTableInput } from './ir/storage-table';\nimport { StorageValueSet, type StorageValueSetInput } from './ir/storage-value-set';\n\nexport const tableEntityKind: EntityKindDescriptor<StorageTableInput, StorageTable> = {\n kind: 'table',\n schema: StorageTableSchema,\n construct: (input) => new StorageTable(input),\n};\n\nexport const valueSetEntityKind: EntityKindDescriptor<StorageValueSetInput, StorageValueSet> = {\n kind: 'valueSet',\n schema: StorageValueSetSchema,\n construct: (input) => new StorageValueSet(input),\n};\n\n/**\n * Assembles the `kind → descriptor` registry for SQL namespaces: the built-in\n * `table` and `valueSet` kinds plus any target `packKinds`. This builds the\n * lookup table — it does not touch contract data. `hydrateNamespaceEntities`\n * later consumes this registry to turn a namespace's raw entries into IR\n * instances, and `createSqlContractSchema` derives validation from the same\n * registry. Throws on a duplicate kind.\n */\nexport function composeSqlEntityKinds(\n packKinds: readonly AnyEntityKindDescriptor[] = [],\n): ReadonlyMap<string, AnyEntityKindDescriptor> {\n const kinds = new Map<string, AnyEntityKindDescriptor>([\n ['table', tableEntityKind],\n ['valueSet', valueSetEntityKind],\n ]);\n for (const descriptor of packKinds) {\n if (kinds.has(descriptor.kind)) {\n throw new Error(\n `composeSqlEntityKinds: duplicate entity kind \"${descriptor.kind}\" — each kind may be registered only once`,\n );\n }\n kinds.set(descriptor.kind, descriptor);\n }\n return kinds;\n}\n"],"mappings":";;;;AAYA,MAAM,oBAAoB,KAAK,WAAW;AAC1C,MAAM,qBAAqB,KAAK,YAAY;AAC5C,MAAM,sBAAsB,KAAK,mDAAmD;AAEpF,MAAa,6BAA6B,KAAK,QAA8B,CAAC,CAAC,KAAK;CAClF,MAAM;CACN,OAAO;AACT,CAAC;AAED,MAAa,8BAA8B,KAAK,QAA+B,CAAC,CAAC,KAAK;CACpF,MAAM;CACN,YAAY;AACd,CAAC;AAED,MAAa,sBAAsB,2BAA2B,GAAG,2BAA2B;AAE5F,MAAM,2BAA2B,KAAK;CACpC,OAAO;CACP,aAAa;CACb,YAAY;CACZ,YAAY;CACZ,YAAY;AACd,CAAC;AAED,MAAM,sBAAsB,KAAK;CAC/B,KAAK;CACL,YAAY;CACZ,SAAS;CACT,UAAU;CACV,eAAe;CACf,YAAY;CACZ,YAAY;CACZ,YAAY;CACZ,aAAa;AACf,CAAC,CAAC,CAAC,QAAQ,KAAK,QAAQ;CACtB,IAAI,IAAI,eAAe,KAAA,KAAa,IAAI,YAAY,KAAA,GAClD,OAAO,IAAI,OAAO,sDAAsD;CAE1E,OAAO;AACT,CAAC;;;;;;AAOD,MAAa,wBAAwB,KAAK;CACxC,MAAM;CACN,QAAQ,KAAK,wEAAwE,CAAC,CACnF,MAAM,CAAC,CACP,SAAS;AACd,CAAC;AAED,MAAM,mBAAmB,KAAK,QAAyB,CAAC,CAAC,KAAK;CAC5D,SAAS,KAAK,OAAO,MAAM,CAAC,CAAC,SAAS;CACtC,SAAS;AACX,CAAC;A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EAEF,MAAM,IAAI,WAAW,MAAM,UAAU;CACvC;CACA,OAAO;AACT"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { i as StorageTableInput, n as StorageValueSetInput, r as StorageTable, t as StorageValueSet } from "./storage-value-set-WnYsIFM8.mjs";
|
|
2
|
+
import { AnyEntityKindDescriptor, EntityKindDescriptor } from "@prisma-next/framework-components/ir";
|
|
3
|
+
|
|
4
|
+
//#region src/entity-kinds.d.ts
|
|
5
|
+
declare const tableEntityKind: EntityKindDescriptor<StorageTableInput, StorageTable>;
|
|
6
|
+
declare const valueSetEntityKind: EntityKindDescriptor<StorageValueSetInput, StorageValueSet>;
|
|
7
|
+
/**
|
|
8
|
+
* Assembles the `kind → descriptor` registry for SQL namespaces: the built-in
|
|
9
|
+
* `table` and `valueSet` kinds plus any target `packKinds`. This builds the
|
|
10
|
+
* lookup table — it does not touch contract data. `hydrateNamespaceEntities`
|
|
11
|
+
* later consumes this registry to turn a namespace's raw entries into IR
|
|
12
|
+
* instances, and `createSqlContractSchema` derives validation from the same
|
|
13
|
+
* registry. Throws on a duplicate kind.
|
|
14
|
+
*/
|
|
15
|
+
declare function composeSqlEntityKinds(packKinds?: readonly AnyEntityKindDescriptor[]): ReadonlyMap<string, AnyEntityKindDescriptor>;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { composeSqlEntityKinds, tableEntityKind, valueSetEntityKind };
|
|
18
|
+
//# sourceMappingURL=entity-kinds.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity-kinds.d.mts","names":[],"sources":["../src/entity-kinds.ts"],"mappings":";;;;cAQa,eAAA,EAAiB,oBAAA,CAAqB,iBAAA,EAAmB,YAAA;AAAA,cAMzD,kBAAA,EAAoB,oBAAA,CAAqB,oBAAA,EAAsB,eAAA;;;;;;;;;iBAc5D,qBAAA,CACd,SAAA,YAAoB,uBAAA,KACnB,WAAA,SAAoB,uBAAA"}
|
package/dist/factories.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as ForeignKey } from "./foreign-key-BATxB95l.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import { b as SqlModelFieldStorage, f as ForeignKeyOptions, x as SqlModelStorage } from "./types-
|
|
2
|
+
import { a as UniqueConstraint, c as StorageColumnInput, d as PrimaryKey, l as Index, r as StorageTable, s as StorageColumn } from "./storage-value-set-WnYsIFM8.mjs";
|
|
3
|
+
import { b as SqlModelFieldStorage, f as ForeignKeyOptions, x as SqlModelStorage } from "./types-B1N8w0I2.mjs";
|
|
4
4
|
import { ScalarFieldType } from "@prisma-next/contract/types";
|
|
5
5
|
|
|
6
6
|
//#region src/factories.d.ts
|
package/dist/factories.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as StorageTable, c as Index, l as PrimaryKey, o as UniqueConstraint, s as StorageColumn, u as ForeignKey } from "./entity-kinds-Cl36zL5j.mjs";
|
|
2
|
+
import { r as applyFkDefaults } from "./types-B-eiQXff.mjs";
|
|
2
3
|
import { UNBOUND_NAMESPACE_ID } from "@prisma-next/framework-components/ir";
|
|
3
4
|
import { asNamespaceId } from "@prisma-next/contract/types";
|
|
4
5
|
//#region src/factories.ts
|
package/dist/factories.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factories.mjs","names":[],"sources":["../src/factories.ts"],"sourcesContent":["import { asNamespaceId, type ScalarFieldType } from '@prisma-next/contract/types';\nimport { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';\nimport {\n applyFkDefaults,\n ForeignKey,\n type ForeignKeyOptions,\n Index,\n PrimaryKey,\n type SqlModelFieldStorage,\n type SqlModelStorage,\n StorageColumn,\n type StorageColumnInput,\n StorageTable,\n UniqueConstraint,\n} from './types';\n\nexport function col(nativeType: string, codecId: string, nullable = false): StorageColumn {\n return new StorageColumn({ nativeType, codecId, nullable });\n}\n\nexport function pk(...columns: readonly string[]): PrimaryKey {\n return new PrimaryKey({ columns });\n}\n\nexport function unique(...columns: readonly string[]): UniqueConstraint {\n return new UniqueConstraint({ columns });\n}\n\nexport function index(...columns: readonly string[]): Index {\n return new Index({ columns });\n}\n\nexport function fk(\n srcTableName: string,\n srcColumns: readonly string[],\n targetTableName: string,\n targetColumns: readonly string[],\n opts?: ForeignKeyOptions & { constraint?: boolean; index?: boolean; namespaceId?: string },\n): ForeignKey {\n const defaults = applyFkDefaults({ constraint: opts?.constraint, index: opts?.index });\n const namespaceId = asNamespaceId(opts?.namespaceId ?? UNBOUND_NAMESPACE_ID);\n return new ForeignKey({\n source: { namespaceId, tableName: srcTableName, columns: srcColumns },\n target: { namespaceId, tableName: targetTableName, columns: targetColumns },\n ...(opts?.name !== undefined && { name: opts.name }),\n ...(opts?.onDelete !== undefined && { onDelete: opts.onDelete }),\n ...(opts?.onUpdate !== undefined && { onUpdate: opts.onUpdate }),\n constraint: defaults.constraint,\n index: defaults.index,\n });\n}\n\nexport function table(\n columns: Record<string, StorageColumn | StorageColumnInput>,\n opts?: {\n pk?: PrimaryKey;\n uniques?: readonly UniqueConstraint[];\n indexes?: readonly Index[];\n fks?: readonly ForeignKey[];\n },\n): StorageTable {\n return new StorageTable({\n columns,\n ...(opts?.pk !== undefined && { primaryKey: opts.pk }),\n uniques: opts?.uniques ?? [],\n indexes: opts?.indexes ?? [],\n foreignKeys: opts?.fks ?? [],\n });\n}\n\nexport function model(\n tableName: string,\n fields: Record<string, SqlModelFieldStorage>,\n relations: Record<string, unknown> = {},\n namespaceId: string = UNBOUND_NAMESPACE_ID,\n): {\n storage: SqlModelStorage;\n fields: Record<string, { readonly nullable: boolean; readonly type: ScalarFieldType }>;\n relations: Record<string, unknown>;\n} {\n const storage: SqlModelStorage = { table: tableName, namespaceId, fields };\n const domainFields = Object.fromEntries(\n Object.entries(fields).map(([name, field]) => [\n name,\n {\n nullable: field.nullable ?? false,\n type: { kind: 'scalar' as const, codecId: field.codecId ?? 'core/unknown@1' },\n },\n ]),\n ) as Record<string, { nullable: boolean; type: ScalarFieldType }>;\n return {\n storage,\n fields: domainFields,\n relations,\n };\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"factories.mjs","names":[],"sources":["../src/factories.ts"],"sourcesContent":["import { asNamespaceId, type ScalarFieldType } from '@prisma-next/contract/types';\nimport { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';\nimport {\n applyFkDefaults,\n ForeignKey,\n type ForeignKeyOptions,\n Index,\n PrimaryKey,\n type SqlModelFieldStorage,\n type SqlModelStorage,\n StorageColumn,\n type StorageColumnInput,\n StorageTable,\n UniqueConstraint,\n} from './types';\n\nexport function col(nativeType: string, codecId: string, nullable = false): StorageColumn {\n return new StorageColumn({ nativeType, codecId, nullable });\n}\n\nexport function pk(...columns: readonly string[]): PrimaryKey {\n return new PrimaryKey({ columns });\n}\n\nexport function unique(...columns: readonly string[]): UniqueConstraint {\n return new UniqueConstraint({ columns });\n}\n\nexport function index(...columns: readonly string[]): Index {\n return new Index({ columns });\n}\n\nexport function fk(\n srcTableName: string,\n srcColumns: readonly string[],\n targetTableName: string,\n targetColumns: readonly string[],\n opts?: ForeignKeyOptions & { constraint?: boolean; index?: boolean; namespaceId?: string },\n): ForeignKey {\n const defaults = applyFkDefaults({ constraint: opts?.constraint, index: opts?.index });\n const namespaceId = asNamespaceId(opts?.namespaceId ?? UNBOUND_NAMESPACE_ID);\n return new ForeignKey({\n source: { namespaceId, tableName: srcTableName, columns: srcColumns },\n target: { namespaceId, tableName: targetTableName, columns: targetColumns },\n ...(opts?.name !== undefined && { name: opts.name }),\n ...(opts?.onDelete !== undefined && { onDelete: opts.onDelete }),\n ...(opts?.onUpdate !== undefined && { onUpdate: opts.onUpdate }),\n constraint: defaults.constraint,\n index: defaults.index,\n });\n}\n\nexport function table(\n columns: Record<string, StorageColumn | StorageColumnInput>,\n opts?: {\n pk?: PrimaryKey;\n uniques?: readonly UniqueConstraint[];\n indexes?: readonly Index[];\n fks?: readonly ForeignKey[];\n },\n): StorageTable {\n return new StorageTable({\n columns,\n ...(opts?.pk !== undefined && { primaryKey: opts.pk }),\n uniques: opts?.uniques ?? [],\n indexes: opts?.indexes ?? [],\n foreignKeys: opts?.fks ?? [],\n });\n}\n\nexport function model(\n tableName: string,\n fields: Record<string, SqlModelFieldStorage>,\n relations: Record<string, unknown> = {},\n namespaceId: string = UNBOUND_NAMESPACE_ID,\n): {\n storage: SqlModelStorage;\n fields: Record<string, { readonly nullable: boolean; readonly type: ScalarFieldType }>;\n relations: Record<string, unknown>;\n} {\n const storage: SqlModelStorage = { table: tableName, namespaceId, fields };\n const domainFields = Object.fromEntries(\n Object.entries(fields).map(([name, field]) => [\n name,\n {\n nullable: field.nullable ?? false,\n type: { kind: 'scalar' as const, codecId: field.codecId ?? 'core/unknown@1' },\n },\n ]),\n ) as Record<string, { nullable: boolean; type: ScalarFieldType }>;\n return {\n storage,\n fields: domainFields,\n relations,\n };\n}\n"],"mappings":";;;;;AAgBA,SAAgB,IAAI,YAAoB,SAAiB,WAAW,OAAsB;CACxF,OAAO,IAAI,cAAc;EAAE;EAAY;EAAS;CAAS,CAAC;AAC5D;AAEA,SAAgB,GAAG,GAAG,SAAwC;CAC5D,OAAO,IAAI,WAAW,EAAE,QAAQ,CAAC;AACnC;AAEA,SAAgB,OAAO,GAAG,SAA8C;CACtE,OAAO,IAAI,iBAAiB,EAAE,QAAQ,CAAC;AACzC;AAEA,SAAgB,MAAM,GAAG,SAAmC;CAC1D,OAAO,IAAI,MAAM,EAAE,QAAQ,CAAC;AAC9B;AAEA,SAAgB,GACd,cACA,YACA,iBACA,eACA,MACY;CACZ,MAAM,WAAW,gBAAgB;EAAE,YAAY,MAAM;EAAY,OAAO,MAAM;CAAM,CAAC;CACrF,MAAM,cAAc,cAAc,MAAM,eAAe,oBAAoB;CAC3E,OAAO,IAAI,WAAW;EACpB,QAAQ;GAAE;GAAa,WAAW;GAAc,SAAS;EAAW;EACpE,QAAQ;GAAE;GAAa,WAAW;GAAiB,SAAS;EAAc;EAC1E,GAAI,MAAM,SAAS,KAAA,KAAa,EAAE,MAAM,KAAK,KAAK;EAClD,GAAI,MAAM,aAAa,KAAA,KAAa,EAAE,UAAU,KAAK,SAAS;EAC9D,GAAI,MAAM,aAAa,KAAA,KAAa,EAAE,UAAU,KAAK,SAAS;EAC9D,YAAY,SAAS;EACrB,OAAO,SAAS;CAClB,CAAC;AACH;AAEA,SAAgB,MACd,SACA,MAMc;CACd,OAAO,IAAI,aAAa;EACtB;EACA,GAAI,MAAM,OAAO,KAAA,KAAa,EAAE,YAAY,KAAK,GAAG;EACpD,SAAS,MAAM,WAAW,CAAC;EAC3B,SAAS,MAAM,WAAW,CAAC;EAC3B,aAAa,MAAM,OAAO,CAAC;CAC7B,CAAC;AACH;AAEA,SAAgB,MACd,WACA,QACA,YAAqC,CAAC,GACtC,cAAsB,sBAKtB;CAWA,OAAO;EACL,SAAA;GAXiC,OAAO;GAAW;GAAa;EAW1D;EACN,QAXmB,OAAO,YAC1B,OAAO,QAAQ,MAAM,CAAC,CAAC,KAAK,CAAC,MAAM,WAAW,CAC5C,MACA;GACE,UAAU,MAAM,YAAY;GAC5B,MAAM;IAAE,MAAM;IAAmB,SAAS,MAAM,WAAW;GAAiB;EAC9E,CACF,CAAC,CAIkB;EACnB;CACF;AACF"}
|
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
import { ContractValidationError } from "@prisma-next/contract/contract-validation-error";
|
|
2
1
|
import { type } from "arktype";
|
|
2
|
+
import { ContractValidationError } from "@prisma-next/contract/contract-validation-error";
|
|
3
3
|
//#region src/index-type-validation.ts
|
|
4
4
|
function validateIndexTypes(contract, indexTypeRegistry) {
|
|
5
|
-
for (const [namespaceId, ns] of Object.entries(contract.storage.namespaces)) for (const [tableName,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const result = entry.options(optionsValue);
|
|
14
|
-
if (result instanceof type.errors) throw new ContractValidationError(`Namespace "${namespaceId}" table "${tableName}" index on columns [${index.columns.join(", ")}] has invalid options for type "${index.type}": ${result.summary}`, "storage");
|
|
15
|
-
}
|
|
5
|
+
for (const [namespaceId, ns] of Object.entries(contract.storage.namespaces)) for (const [tableName, table] of Object.entries(ns.entries.table ?? {})) for (const index of table.indexes) {
|
|
6
|
+
if (index.type === void 0 && index.options !== void 0) throw new ContractValidationError(`Namespace "${namespaceId}" table "${tableName}" index on columns [${index.columns.join(", ")}] has options without a type`, "storage");
|
|
7
|
+
if (index.type === void 0) continue;
|
|
8
|
+
const entry = indexTypeRegistry.get(index.type);
|
|
9
|
+
if (entry === void 0) throw new ContractValidationError(`Namespace "${namespaceId}" table "${tableName}" index on columns [${index.columns.join(", ")}] uses unregistered index type "${index.type}"`, "storage");
|
|
10
|
+
const optionsValue = index.options ?? {};
|
|
11
|
+
const result = entry.options(optionsValue);
|
|
12
|
+
if (result instanceof type.errors) throw new ContractValidationError(`Namespace "${namespaceId}" table "${tableName}" index on columns [${index.columns.join(", ")}] has invalid options for type "${index.type}": ${result.summary}`, "storage");
|
|
16
13
|
}
|
|
17
14
|
}
|
|
18
15
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-type-validation.mjs","names":[],"sources":["../src/index-type-validation.ts"],"sourcesContent":["import { ContractValidationError } from '@prisma-next/contract/contract-validation-error';\nimport type { Contract } from '@prisma-next/contract/types';\nimport { type } from 'arktype';\nimport type { IndexTypeRegistry } from './index-types';\nimport type { SqlStorage
|
|
1
|
+
{"version":3,"file":"index-type-validation.mjs","names":[],"sources":["../src/index-type-validation.ts"],"sourcesContent":["import { ContractValidationError } from '@prisma-next/contract/contract-validation-error';\nimport type { Contract } from '@prisma-next/contract/types';\nimport { type } from 'arktype';\nimport type { IndexTypeRegistry } from './index-types';\nimport type { SqlStorage } from './types';\n\nexport function validateIndexTypes(\n contract: Contract<SqlStorage>,\n indexTypeRegistry: IndexTypeRegistry,\n): void {\n for (const [namespaceId, ns] of Object.entries(contract.storage.namespaces)) {\n for (const [tableName, table] of Object.entries(ns.entries.table ?? {})) {\n for (const index of table.indexes) {\n if (index.type === undefined && index.options !== undefined) {\n throw new ContractValidationError(\n `Namespace \"${namespaceId}\" table \"${tableName}\" index on columns [${index.columns.join(', ')}] has options without a type`,\n 'storage',\n );\n }\n if (index.type === undefined) continue;\n const entry = indexTypeRegistry.get(index.type);\n if (entry === undefined) {\n throw new ContractValidationError(\n `Namespace \"${namespaceId}\" table \"${tableName}\" index on columns [${index.columns.join(', ')}] uses unregistered index type \"${index.type}\"`,\n 'storage',\n );\n }\n const optionsValue = index.options ?? {};\n const result = entry.options(optionsValue);\n if (result instanceof type.errors) {\n throw new ContractValidationError(\n `Namespace \"${namespaceId}\" table \"${tableName}\" index on columns [${index.columns.join(', ')}] has invalid options for type \"${index.type}\": ${result.summary}`,\n 'storage',\n );\n }\n }\n }\n }\n}\n"],"mappings":";;;AAMA,SAAgB,mBACd,UACA,mBACM;CACN,KAAK,MAAM,CAAC,aAAa,OAAO,OAAO,QAAQ,SAAS,QAAQ,UAAU,GACxE,KAAK,MAAM,CAAC,WAAW,UAAU,OAAO,QAAQ,GAAG,QAAQ,SAAS,CAAC,CAAC,GACpE,KAAK,MAAM,SAAS,MAAM,SAAS;EACjC,IAAI,MAAM,SAAS,KAAA,KAAa,MAAM,YAAY,KAAA,GAChD,MAAM,IAAI,wBACR,cAAc,YAAY,WAAW,UAAU,sBAAsB,MAAM,QAAQ,KAAK,IAAI,EAAE,+BAC9F,SACF;EAEF,IAAI,MAAM,SAAS,KAAA,GAAW;EAC9B,MAAM,QAAQ,kBAAkB,IAAI,MAAM,IAAI;EAC9C,IAAI,UAAU,KAAA,GACZ,MAAM,IAAI,wBACR,cAAc,YAAY,WAAW,UAAU,sBAAsB,MAAM,QAAQ,KAAK,IAAI,EAAE,kCAAkC,MAAM,KAAK,IAC3I,SACF;EAEF,MAAM,eAAe,MAAM,WAAW,CAAC;EACvC,MAAM,SAAS,MAAM,QAAQ,YAAY;EACzC,IAAI,kBAAkB,KAAK,QACzB,MAAM,IAAI,wBACR,cAAc,YAAY,WAAW,UAAU,sBAAsB,MAAM,QAAQ,KAAK,IAAI,EAAE,kCAAkC,MAAM,KAAK,KAAK,OAAO,WACvJ,SACF;CAEJ;AAGN"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { r as StorageTable } from "./storage-value-set-WnYsIFM8.mjs";
|
|
2
|
+
import { i as SqlStorage } from "./sql-storage-Dga0jwP2.mjs";
|
|
2
3
|
|
|
3
4
|
//#region src/resolve-storage-table.d.ts
|
|
4
5
|
interface ResolvedStorageTable {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-storage-table.d.mts","names":[],"sources":["../src/resolve-storage-table.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"resolve-storage-table.d.mts","names":[],"sources":["../src/resolve-storage-table.ts"],"mappings":";;;;UAIiB,oBAAA;EAAA,SACN,WAAA;EAAA,SACA,KAAA,EAAO,YAAY;AAAA;;;;;;;AAAA;AAY9B;;iBAAgB,mBAAA,CACd,OAAA,EAAS,UAAA,EACT,SAAA,UACA,WAAA,YACC,oBAAoB"}
|
|
@@ -1,10 +1,5 @@
|
|
|
1
|
+
import { entityAt } from "@prisma-next/framework-components/ir";
|
|
1
2
|
//#region src/resolve-storage-table.ts
|
|
2
|
-
function tableInNamespace(namespace, tableName) {
|
|
3
|
-
if (namespace === void 0) return;
|
|
4
|
-
const tables = namespace.entries.table;
|
|
5
|
-
if (!Object.hasOwn(tables, tableName)) return;
|
|
6
|
-
return tables[tableName];
|
|
7
|
-
}
|
|
8
3
|
/**
|
|
9
4
|
* Resolve a bare storage table name to its namespace coordinate and table IR.
|
|
10
5
|
*
|
|
@@ -16,7 +11,11 @@ function tableInNamespace(namespace, tableName) {
|
|
|
16
11
|
*/
|
|
17
12
|
function resolveStorageTable(storage, tableName, namespaceId) {
|
|
18
13
|
if (namespaceId !== void 0) {
|
|
19
|
-
const table =
|
|
14
|
+
const table = entityAt(storage, {
|
|
15
|
+
namespaceId,
|
|
16
|
+
entityKind: "table",
|
|
17
|
+
entityName: tableName
|
|
18
|
+
});
|
|
20
19
|
return table === void 0 ? void 0 : {
|
|
21
20
|
namespaceId,
|
|
22
21
|
table
|
|
@@ -24,7 +23,11 @@ function resolveStorageTable(storage, tableName, namespaceId) {
|
|
|
24
23
|
}
|
|
25
24
|
const matches = [];
|
|
26
25
|
for (const candidateNamespaceId of Object.keys(storage.namespaces)) {
|
|
27
|
-
const table =
|
|
26
|
+
const table = entityAt(storage, {
|
|
27
|
+
namespaceId: candidateNamespaceId,
|
|
28
|
+
entityKind: "table",
|
|
29
|
+
entityName: tableName
|
|
30
|
+
});
|
|
28
31
|
if (table !== void 0) matches.push({
|
|
29
32
|
namespaceId: candidateNamespaceId,
|
|
30
33
|
table
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-storage-table.mjs","names":[],"sources":["../src/resolve-storage-table.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"resolve-storage-table.mjs","names":[],"sources":["../src/resolve-storage-table.ts"],"sourcesContent":["import { entityAt } from '@prisma-next/framework-components/ir';\nimport type { SqlStorage } from './ir/sql-storage';\nimport type { StorageTable } from './ir/storage-table';\n\nexport interface ResolvedStorageTable {\n readonly namespaceId: string;\n readonly table: StorageTable;\n}\n\n/**\n * Resolve a bare storage table name to its namespace coordinate and table IR.\n *\n * When `namespaceId` is supplied, the table is resolved strictly within that\n * namespace (no scan). When omitted, a bare name unique across namespaces\n * resolves to its sole namespace; a bare name declared in more than one\n * namespace throws a fail-fast diagnostic naming the candidate namespaces\n * rather than silently selecting the first match.\n */\nexport function resolveStorageTable(\n storage: SqlStorage,\n tableName: string,\n namespaceId?: string,\n): ResolvedStorageTable | undefined {\n if (namespaceId !== undefined) {\n const table = entityAt<StorageTable>(storage, {\n namespaceId,\n entityKind: 'table',\n entityName: tableName,\n });\n return table === undefined ? undefined : { namespaceId, table };\n }\n\n const matches: ResolvedStorageTable[] = [];\n for (const candidateNamespaceId of Object.keys(storage.namespaces)) {\n const table = entityAt<StorageTable>(storage, {\n namespaceId: candidateNamespaceId,\n entityKind: 'table',\n entityName: tableName,\n });\n if (table !== undefined) {\n matches.push({ namespaceId: candidateNamespaceId, table });\n }\n }\n\n if (matches.length > 1) {\n const candidates = matches\n .map((match) => match.namespaceId)\n .sort()\n .join(', ');\n throw new Error(\n `Storage table \"${tableName}\" is ambiguous across namespaces [${candidates}]; qualify it with a namespace coordinate.`,\n );\n }\n\n return matches[0];\n}\n"],"mappings":";;;;;;;;;;;AAkBA,SAAgB,oBACd,SACA,WACA,aACkC;CAClC,IAAI,gBAAgB,KAAA,GAAW;EAC7B,MAAM,QAAQ,SAAuB,SAAS;GAC5C;GACA,YAAY;GACZ,YAAY;EACd,CAAC;EACD,OAAO,UAAU,KAAA,IAAY,KAAA,IAAY;GAAE;GAAa;EAAM;CAChE;CAEA,MAAM,UAAkC,CAAC;CACzC,KAAK,MAAM,wBAAwB,OAAO,KAAK,QAAQ,UAAU,GAAG;EAClE,MAAM,QAAQ,SAAuB,SAAS;GAC5C,aAAa;GACb,YAAY;GACZ,YAAY;EACd,CAAC;EACD,IAAI,UAAU,KAAA,GACZ,QAAQ,KAAK;GAAE,aAAa;GAAsB;EAAM,CAAC;CAE7D;CAEA,IAAI,QAAQ,SAAS,GAAG;EACtB,MAAM,aAAa,QAChB,KAAK,UAAU,MAAM,WAAW,CAAC,CACjC,KAAK,CAAC,CACN,KAAK,IAAI;EACZ,MAAM,IAAI,MACR,kBAAkB,UAAU,oCAAoC,WAAW,2CAC7E;CACF;CAEA,OAAO,QAAQ;AACjB"}
|