@prisma-next/sql-contract 0.14.0 → 0.15.0-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/canonicalization-hooks.d.mts.map +1 -1
- package/dist/canonicalization-hooks.mjs +70 -50
- package/dist/canonicalization-hooks.mjs.map +1 -1
- package/dist/contract-view.d.mts +61 -0
- package/dist/contract-view.d.mts.map +1 -0
- package/dist/contract-view.mjs +39 -0
- package/dist/contract-view.mjs.map +1 -0
- package/dist/entity-handle-lowering-hook.d.mts +91 -0
- package/dist/entity-handle-lowering-hook.d.mts.map +1 -0
- package/dist/entity-handle-lowering-hook.mjs +11 -0
- package/dist/entity-handle-lowering-hook.mjs.map +1 -0
- package/dist/entity-kinds-CVg6HzG2.mjs +130 -0
- package/dist/entity-kinds-CVg6HzG2.mjs.map +1 -0
- package/dist/entity-kinds.d.mts +2 -1
- package/dist/entity-kinds.d.mts.map +1 -1
- package/dist/entity-kinds.mjs +1 -1
- package/dist/factories.d.mts +7 -6
- package/dist/factories.d.mts.map +1 -1
- package/dist/factories.mjs +5 -11
- package/dist/factories.mjs.map +1 -1
- package/dist/{foreign-key-BATxB95l.d.mts → foreign-key-DuCoGJCf.d.mts} +12 -48
- package/dist/foreign-key-DuCoGJCf.d.mts.map +1 -0
- package/dist/foreign-key-materialization.d.mts +64 -0
- package/dist/foreign-key-materialization.d.mts.map +1 -0
- package/dist/foreign-key-materialization.mjs +67 -0
- package/dist/foreign-key-materialization.mjs.map +1 -0
- package/dist/index-type-validation.d.mts +1 -1
- package/dist/referential-action-sql.d.mts +1 -1
- package/dist/resolve-storage-table.d.mts +2 -2
- package/dist/sql-node-V214WXQD.d.mts +42 -0
- package/dist/sql-node-V214WXQD.d.mts.map +1 -0
- package/dist/{sql-storage-Dga0jwP2.d.mts → sql-storage-p-Wzt_MO.d.mts} +63 -20
- package/dist/sql-storage-p-Wzt_MO.d.mts.map +1 -0
- package/dist/{storage-value-set-WnYsIFM8.d.mts → storage-table-CE-Ns6wa.d.mts} +17 -90
- package/dist/storage-table-CE-Ns6wa.d.mts.map +1 -0
- package/dist/{entity-kinds-Cl36zL5j.mjs → storage-table-DBpYBmty.mjs} +26 -162
- package/dist/storage-table-DBpYBmty.mjs.map +1 -0
- package/dist/storage-value-set-3BKuha5q.mjs +38 -0
- package/dist/storage-value-set-3BKuha5q.mjs.map +1 -0
- package/dist/storage-value-set-D-jww77l.d.mts +41 -0
- package/dist/storage-value-set-D-jww77l.d.mts.map +1 -0
- package/dist/{types-B1N8w0I2.d.mts → types-3vOIrnvp.d.mts} +25 -55
- package/dist/types-3vOIrnvp.d.mts.map +1 -0
- package/dist/types.d.mts +14 -5
- package/dist/types.d.mts.map +1 -0
- package/dist/types.mjs +115 -3
- package/dist/types.mjs.map +1 -0
- package/dist/unique-constraint-C0De4sLU.d.mts +55 -0
- package/dist/unique-constraint-C0De4sLU.d.mts.map +1 -0
- package/dist/validators.d.mts +10 -7
- package/dist/validators.d.mts.map +1 -1
- package/dist/validators.mjs +111 -21
- package/dist/validators.mjs.map +1 -1
- package/dist/value-set-derivation-hook.d.mts +35 -0
- package/dist/value-set-derivation-hook.d.mts.map +1 -0
- package/dist/value-set-derivation-hook.mjs +22 -0
- package/dist/value-set-derivation-hook.mjs.map +1 -0
- package/package.json +15 -10
- package/src/canonicalization-hooks.ts +31 -3
- package/src/column-type-resolution.ts +26 -0
- package/src/contract-view.ts +98 -0
- package/src/entity-handle-lowering-hook.ts +104 -0
- package/src/exports/contract-view.ts +11 -0
- package/src/exports/entity-handle-lowering-hook.ts +10 -0
- package/src/exports/foreign-key-materialization.ts +8 -0
- package/src/exports/types.ts +17 -4
- package/src/exports/value-set-derivation-hook.ts +2 -0
- package/src/factories.ts +13 -7
- package/src/foreign-key-materialization.ts +107 -0
- package/src/ir/foreign-key.ts +9 -9
- package/src/ir/sql-storage.ts +81 -17
- package/src/ir/storage-column.ts +3 -0
- package/src/ir/storage-entry-schemas.ts +1 -2
- package/src/ir/storage-table.ts +21 -0
- package/src/ir/storage-value-set.ts +5 -0
- package/src/types.ts +51 -8
- package/src/validators.ts +215 -42
- package/src/value-set-derivation-hook.ts +47 -0
- package/dist/entity-kinds-Cl36zL5j.mjs.map +0 -1
- package/dist/foreign-key-BATxB95l.d.mts.map +0 -1
- package/dist/sql-storage-Dga0jwP2.d.mts.map +0 -1
- package/dist/storage-value-set-WnYsIFM8.d.mts.map +0 -1
- package/dist/types-B-eiQXff.mjs +0 -191
- package/dist/types-B-eiQXff.mjs.map +0 -1
- package/dist/types-B1N8w0I2.d.mts.map +0 -1
- package/src/ir/build-sql-namespace.ts +0 -110
- package/src/ir/sql-unbound-namespace.ts +0 -74
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
|
|
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 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(\n nativeType: string,\n codecId: string,\n nullable = false,\n opts?: { readonly many?: boolean },\n): StorageColumn {\n return new StorageColumn({\n nativeType,\n codecId,\n nullable,\n ...(opts?.many !== undefined && { many: opts.many }),\n });\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 & { namespaceId?: string },\n): ForeignKey {\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 });\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":";;;;AAeA,SAAgB,IACd,YACA,SACA,WAAW,OACX,MACe;CACf,OAAO,IAAI,cAAc;EACvB;EACA;EACA;EACA,GAAI,MAAM,SAAS,KAAA,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C9E,CACF,CAAC,CAIkB;EACnB;CACF;AACF"}
|
|
@@ -1,44 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as SqlNode } from "./sql-node-V214WXQD.mjs";
|
|
2
2
|
import { NamespaceId } from "@prisma-next/contract/types";
|
|
3
3
|
|
|
4
|
-
//#region src/ir/sql-node.d.ts
|
|
5
|
-
/**
|
|
6
|
-
* SQL family IR node base. Carries the family-level `kind` discriminator
|
|
7
|
-
* `'sql'` and inherits the framework's `freezeNode` affordance.
|
|
8
|
-
*
|
|
9
|
-
* Single family-level discriminator (not per-leaf) reflects the fact that
|
|
10
|
-
* SQL IR has no polymorphic dispatch today — verifiers and serializers
|
|
11
|
-
* walk by structural position (`storage.tables[name].columns[name]`),
|
|
12
|
-
* not by inspecting `kind`. The abstract bar for per-leaf discriminators
|
|
13
|
-
* isn't earned until a future polymorphic consumer arrives.
|
|
14
|
-
*
|
|
15
|
-
* `kind` is installed as a non-enumerable own property on every instance,
|
|
16
|
-
* which keeps three things clean simultaneously:
|
|
17
|
-
*
|
|
18
|
-
* - `JSON.stringify(node)` produces the canonical pre-lift JSON envelope
|
|
19
|
-
* shape (no `kind` field), so emitted contract.json files and the
|
|
20
|
-
* `validateSqlContractFully` arktype schemas stay unchanged.
|
|
21
|
-
* - Test assertions that use `toEqual({...})` against the pre-lift flat
|
|
22
|
-
* shape continue to pass — only enumerable own properties are
|
|
23
|
-
* compared.
|
|
24
|
-
* - Direct access (`node.kind`) and runtime narrowing
|
|
25
|
-
* (`if (node.kind === 'sql')`) still work, so future polymorphic
|
|
26
|
-
* dispatch can begin reading `kind` without a runtime change.
|
|
27
|
-
*
|
|
28
|
-
* Future per-leaf overrides land cleanly: a class that gains a
|
|
29
|
-
* polymorphic-dispatch consumer (e.g. an enum type instance walked
|
|
30
|
-
* alongside other types) overrides `kind` with its narrower literal
|
|
31
|
-
* at that leaf level. Per-leaf overrides will use enumerable kind
|
|
32
|
-
* (matching the Mongo per-class-discriminator precedent) because they
|
|
33
|
-
* encode dispatch-relevant information that callers need to see in
|
|
34
|
-
* JSON envelopes; the family-level `'sql'` is uniform across all SQL
|
|
35
|
-
* IR and carries no dispatch-relevant information.
|
|
36
|
-
*/
|
|
37
|
-
declare abstract class SqlNode extends IRNodeBase {
|
|
38
|
-
readonly kind?: string;
|
|
39
|
-
constructor();
|
|
40
|
-
}
|
|
41
|
-
//#endregion
|
|
42
4
|
//#region src/ir/foreign-key-reference.d.ts
|
|
43
5
|
/**
|
|
44
6
|
* Input for a foreign-key reference (one side of a foreign-key declaration).
|
|
@@ -89,13 +51,17 @@ interface ForeignKeyInput {
|
|
|
89
51
|
readonly name?: string;
|
|
90
52
|
readonly onDelete?: ReferentialAction;
|
|
91
53
|
readonly onUpdate?: ReferentialAction;
|
|
92
|
-
/** Whether to emit FK constraint DDL (ALTER TABLE … ADD CONSTRAINT … FOREIGN KEY). */
|
|
93
|
-
readonly constraint: boolean;
|
|
94
|
-
/** Whether to emit a backing index for the FK columns. */
|
|
95
|
-
readonly index: boolean;
|
|
96
54
|
}
|
|
97
55
|
/**
|
|
98
|
-
* SQL Contract IR node for a table-level foreign-key declaration
|
|
56
|
+
* SQL Contract IR node for a table-level foreign-key declaration — the
|
|
57
|
+
* referential constraint only (source, target, `onDelete`/`onUpdate`).
|
|
58
|
+
*
|
|
59
|
+
* A persisted `foreignKeys[]` entry always denotes a real constraint: whether
|
|
60
|
+
* to emit the constraint at all, and whether to back it with an index, are
|
|
61
|
+
* authoring-time decisions (PSL `@relation(index:)`, TS `fk({ constraint,
|
|
62
|
+
* index })`) resolved once at `contract emit` — a `constraint: false` FK
|
|
63
|
+
* simply has no entry here, and a backing index (if any) is its own discrete,
|
|
64
|
+
* named entry in the table's `indexes[]`.
|
|
99
65
|
*
|
|
100
66
|
* Each FK carries explicit `source` and `target` {@link ForeignKeyReference}
|
|
101
67
|
* coordinates (namespace, table, columns). For single-namespace contracts the
|
|
@@ -109,13 +75,11 @@ interface ForeignKeyInput {
|
|
|
109
75
|
declare class ForeignKey extends SqlNode {
|
|
110
76
|
readonly source: ForeignKeyReference;
|
|
111
77
|
readonly target: ForeignKeyReference;
|
|
112
|
-
readonly constraint: boolean;
|
|
113
|
-
readonly index: boolean;
|
|
114
78
|
readonly name?: string;
|
|
115
79
|
readonly onDelete?: ReferentialAction;
|
|
116
80
|
readonly onUpdate?: ReferentialAction;
|
|
117
81
|
constructor(input: ForeignKeyInput);
|
|
118
82
|
}
|
|
119
83
|
//#endregion
|
|
120
|
-
export { ForeignKeyReferenceInput as a, ForeignKeyReference as i, ForeignKeyInput as n,
|
|
121
|
-
//# sourceMappingURL=foreign-key-
|
|
84
|
+
export { ForeignKeyReferenceInput as a, ForeignKeyReference as i, ForeignKeyInput as n, ReferentialAction as r, ForeignKey as t };
|
|
85
|
+
//# sourceMappingURL=foreign-key-DuCoGJCf.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"foreign-key-DuCoGJCf.d.mts","names":[],"sources":["../src/ir/foreign-key-reference.ts","../src/ir/foreign-key.ts"],"mappings":";;;;;;AAeA;;;;;;;;;UAAiB,wBAAA;EAAA,SACN,WAAA;EAAA,SACA,SAAA;EAAA,SACA,OAAA;EAAA,SACA,OAAA;AAAA;;;;;;;;;;;;;;AAyBkC;;;cANhC,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,wBAAA;EAAA,SAC9B,IAAA;EAAA,SACA,QAAA,GAAW,iBAAA;EAAA,SACX,QAAA,GAAW,iBAAA;AAAA;;;;ADQJ;AAmBlB;;;;;;;;;;;;;;;;cCJa,UAAA,SAAmB,OAAA;EAAA,SACrB,MAAA,EAAQ,mBAAA;EAAA,SACR,MAAA,EAAQ,mBAAA;EAAA,SACA,IAAA;EAAA,SACA,QAAA,GAAW,iBAAA;EAAA,SACX,QAAA,GAAW,iBAAA;cAEhB,KAAA,EAAO,eAAA;AAAA"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { a as ForeignKeyReferenceInput, n as ForeignKeyInput, r as ReferentialAction } from "./foreign-key-DuCoGJCf.mjs";
|
|
2
|
+
import { i as IndexInput, n as UniqueConstraintInput, o as PrimaryKeyInput } from "./unique-constraint-C0De4sLU.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/foreign-key-materialization.d.ts
|
|
5
|
+
type BackingIndexCandidates = {
|
|
6
|
+
readonly indexes: readonly {
|
|
7
|
+
readonly columns: readonly string[];
|
|
8
|
+
}[];
|
|
9
|
+
readonly uniques: readonly {
|
|
10
|
+
readonly columns: readonly string[];
|
|
11
|
+
}[];
|
|
12
|
+
readonly primaryKey?: {
|
|
13
|
+
readonly columns: readonly string[];
|
|
14
|
+
} | undefined;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* The column-list keys (`"colA,colB"`, order preserved) a table's own
|
|
18
|
+
* indexes, unique constraints, and primary key already back. A foreign key
|
|
19
|
+
* whose source columns join to one of these keys needs no separately
|
|
20
|
+
* derived backing index.
|
|
21
|
+
*
|
|
22
|
+
* Shared by {@link isBackedByColumnKeys}'s callers: `materializeForeignKeysAndIndexes`
|
|
23
|
+
* (deriving the discrete backing-index entities persisted at `contract emit`)
|
|
24
|
+
* and the postgres PSL inferrer (deciding whether an introspected relation
|
|
25
|
+
* needs an explicit `index: false`).
|
|
26
|
+
*/
|
|
27
|
+
declare function backingIndexColumnKeys(table: BackingIndexCandidates): readonly string[];
|
|
28
|
+
/**
|
|
29
|
+
* Whether `columns`, in order, matches one of `backingKeys` (see
|
|
30
|
+
* {@link backingIndexColumnKeys}). Order-sensitive: `(a, b)` does not
|
|
31
|
+
* satisfy a backing index declared as `(b, a)`.
|
|
32
|
+
*/
|
|
33
|
+
declare function isBackedByColumnKeys(columns: readonly string[], backingKeys: readonly string[]): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* A foreign key as authored, before FK1 materialization: the referential
|
|
36
|
+
* coordinates plus the `constraint`/`index` intent booleans that drive
|
|
37
|
+
* whether — and how — it survives into the persisted contract.
|
|
38
|
+
*/
|
|
39
|
+
interface ForeignKeyAuthoringInput {
|
|
40
|
+
readonly source: ForeignKeyReferenceInput;
|
|
41
|
+
readonly target: ForeignKeyReferenceInput;
|
|
42
|
+
readonly name?: string;
|
|
43
|
+
readonly onDelete?: ReferentialAction;
|
|
44
|
+
readonly onUpdate?: ReferentialAction;
|
|
45
|
+
readonly constraint: boolean;
|
|
46
|
+
readonly index: boolean;
|
|
47
|
+
}
|
|
48
|
+
interface MaterializedTableConstraints {
|
|
49
|
+
readonly foreignKeys: readonly ForeignKeyInput[];
|
|
50
|
+
readonly indexes: readonly IndexInput[];
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Lowers a table's authored foreign keys into the discrete entities
|
|
54
|
+
* `contract.json` persists: a `constraint: false` FK contributes no
|
|
55
|
+
* `foreignKeys[]` entry, and an `index: true` FK whose columns aren't already
|
|
56
|
+
* backed by a declared index/unique/primary-key contributes a named
|
|
57
|
+
* `indexes[]` entry (`defaultIndexName`). Declared indexes always survive
|
|
58
|
+
* unchanged; a second FK sharing already-synthesized backing columns does not
|
|
59
|
+
* mint a duplicate index.
|
|
60
|
+
*/
|
|
61
|
+
declare function materializeForeignKeysAndIndexes(tableName: string, foreignKeys: readonly ForeignKeyAuthoringInput[], declaredIndexes: readonly IndexInput[], uniques: readonly UniqueConstraintInput[], primaryKey: PrimaryKeyInput | undefined): MaterializedTableConstraints;
|
|
62
|
+
//#endregion
|
|
63
|
+
export { type BackingIndexCandidates, type ForeignKeyAuthoringInput, type MaterializedTableConstraints, backingIndexColumnKeys, isBackedByColumnKeys, materializeForeignKeysAndIndexes };
|
|
64
|
+
//# sourceMappingURL=foreign-key-materialization.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"foreign-key-materialization.d.mts","names":[],"sources":["../src/foreign-key-materialization.ts"],"mappings":";;;;KAOY,sBAAA;EAAA,SACD,OAAA;IAAA,SAA6B,OAAA;EAAA;EAAA,SAC7B,OAAA;IAAA,SAA6B,OAAA;EAAA;EAAA,SAC7B,UAAA;IAAA,SAAwB,OAAA;EAAA;AAAA;AAcnC;;;;AAAoE;AAapE;;;;AAEgC;AAUhC;AAzBA,iBAAgB,sBAAA,CAAuB,KAA6B,EAAtB,sBAAsB;;;;;;iBAapD,oBAAA,CACd,OAAA,qBACA,WAA8B;;;;;;UAUf,wBAAA;EAAA,SACN,MAAA,EAAQ,wBAAA;EAAA,SACR,MAAA,EAAQ,wBAAA;EAAA,SACR,IAAA;EAAA,SACA,QAAA,GAAW,iBAAA;EAAA,SACX,QAAA,GAAW,iBAAA;EAAA,SACX,UAAA;EAAA,SACA,KAAA;AAAA;AAAA,UAGM,4BAAA;EAAA,SACN,WAAA,WAAsB,eAAA;EAAA,SACtB,OAAA,WAAkB,UAAU;AAAA;;;;;;AAAA;AAYvC;;;iBAAgB,gCAAA,CACd,SAAA,UACA,WAAA,WAAsB,wBAAA,IACtB,eAAA,WAA0B,UAAA,IAC1B,OAAA,WAAkB,qBAAA,IAClB,UAAA,EAAY,eAAA,eACX,4BAAA"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { defaultIndexName } from "@prisma-next/sql-schema-ir/naming";
|
|
2
|
+
//#region src/foreign-key-materialization.ts
|
|
3
|
+
/**
|
|
4
|
+
* The column-list keys (`"colA,colB"`, order preserved) a table's own
|
|
5
|
+
* indexes, unique constraints, and primary key already back. A foreign key
|
|
6
|
+
* whose source columns join to one of these keys needs no separately
|
|
7
|
+
* derived backing index.
|
|
8
|
+
*
|
|
9
|
+
* Shared by {@link isBackedByColumnKeys}'s callers: `materializeForeignKeysAndIndexes`
|
|
10
|
+
* (deriving the discrete backing-index entities persisted at `contract emit`)
|
|
11
|
+
* and the postgres PSL inferrer (deciding whether an introspected relation
|
|
12
|
+
* needs an explicit `index: false`).
|
|
13
|
+
*/
|
|
14
|
+
function backingIndexColumnKeys(table) {
|
|
15
|
+
return [
|
|
16
|
+
...table.indexes.map((index) => index.columns.join(",")),
|
|
17
|
+
...table.uniques.map((unique) => unique.columns.join(",")),
|
|
18
|
+
...table.primaryKey ? [table.primaryKey.columns.join(",")] : []
|
|
19
|
+
];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Whether `columns`, in order, matches one of `backingKeys` (see
|
|
23
|
+
* {@link backingIndexColumnKeys}). Order-sensitive: `(a, b)` does not
|
|
24
|
+
* satisfy a backing index declared as `(b, a)`.
|
|
25
|
+
*/
|
|
26
|
+
function isBackedByColumnKeys(columns, backingKeys) {
|
|
27
|
+
return backingKeys.includes(columns.join(","));
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Lowers a table's authored foreign keys into the discrete entities
|
|
31
|
+
* `contract.json` persists: a `constraint: false` FK contributes no
|
|
32
|
+
* `foreignKeys[]` entry, and an `index: true` FK whose columns aren't already
|
|
33
|
+
* backed by a declared index/unique/primary-key contributes a named
|
|
34
|
+
* `indexes[]` entry (`defaultIndexName`). Declared indexes always survive
|
|
35
|
+
* unchanged; a second FK sharing already-synthesized backing columns does not
|
|
36
|
+
* mint a duplicate index.
|
|
37
|
+
*/
|
|
38
|
+
function materializeForeignKeysAndIndexes(tableName, foreignKeys, declaredIndexes, uniques, primaryKey) {
|
|
39
|
+
const satisfiedIndexColumns = new Set(backingIndexColumnKeys({
|
|
40
|
+
indexes: declaredIndexes,
|
|
41
|
+
uniques,
|
|
42
|
+
primaryKey
|
|
43
|
+
}));
|
|
44
|
+
const synthesizedIndexes = [];
|
|
45
|
+
const materializedForeignKeys = [];
|
|
46
|
+
for (const { constraint, index, ...reference } of foreignKeys) {
|
|
47
|
+
if (constraint !== false) materializedForeignKeys.push(reference);
|
|
48
|
+
if (index !== false) {
|
|
49
|
+
const key = reference.source.columns.join(",");
|
|
50
|
+
if (!satisfiedIndexColumns.has(key)) {
|
|
51
|
+
synthesizedIndexes.push({
|
|
52
|
+
columns: reference.source.columns,
|
|
53
|
+
name: defaultIndexName(tableName, reference.source.columns)
|
|
54
|
+
});
|
|
55
|
+
satisfiedIndexColumns.add(key);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
foreignKeys: materializedForeignKeys,
|
|
61
|
+
indexes: [...declaredIndexes, ...synthesizedIndexes]
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
//#endregion
|
|
65
|
+
export { backingIndexColumnKeys, isBackedByColumnKeys, materializeForeignKeysAndIndexes };
|
|
66
|
+
|
|
67
|
+
//# sourceMappingURL=foreign-key-materialization.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"foreign-key-materialization.mjs","names":[],"sources":["../src/foreign-key-materialization.ts"],"sourcesContent":["import { defaultIndexName } from '@prisma-next/sql-schema-ir/naming';\nimport type { ForeignKeyInput, ReferentialAction } from './ir/foreign-key';\nimport type { ForeignKeyReferenceInput } from './ir/foreign-key-reference';\nimport type { PrimaryKeyInput } from './ir/primary-key';\nimport type { IndexInput } from './ir/sql-index';\nimport type { UniqueConstraintInput } from './ir/unique-constraint';\n\nexport type BackingIndexCandidates = {\n readonly indexes: readonly { readonly columns: readonly string[] }[];\n readonly uniques: readonly { readonly columns: readonly string[] }[];\n readonly primaryKey?: { readonly columns: readonly string[] } | undefined;\n};\n\n/**\n * The column-list keys (`\"colA,colB\"`, order preserved) a table's own\n * indexes, unique constraints, and primary key already back. A foreign key\n * whose source columns join to one of these keys needs no separately\n * derived backing index.\n *\n * Shared by {@link isBackedByColumnKeys}'s callers: `materializeForeignKeysAndIndexes`\n * (deriving the discrete backing-index entities persisted at `contract emit`)\n * and the postgres PSL inferrer (deciding whether an introspected relation\n * needs an explicit `index: false`).\n */\nexport function backingIndexColumnKeys(table: BackingIndexCandidates): readonly string[] {\n return [\n ...table.indexes.map((index) => index.columns.join(',')),\n ...table.uniques.map((unique) => unique.columns.join(',')),\n ...(table.primaryKey ? [table.primaryKey.columns.join(',')] : []),\n ];\n}\n\n/**\n * Whether `columns`, in order, matches one of `backingKeys` (see\n * {@link backingIndexColumnKeys}). Order-sensitive: `(a, b)` does not\n * satisfy a backing index declared as `(b, a)`.\n */\nexport function isBackedByColumnKeys(\n columns: readonly string[],\n backingKeys: readonly string[],\n): boolean {\n return backingKeys.includes(columns.join(','));\n}\n\n/**\n * A foreign key as authored, before FK1 materialization: the referential\n * coordinates plus the `constraint`/`index` intent booleans that drive\n * whether — and how — it survives into the persisted contract.\n */\nexport interface ForeignKeyAuthoringInput {\n readonly source: ForeignKeyReferenceInput;\n readonly target: ForeignKeyReferenceInput;\n readonly name?: string;\n readonly onDelete?: ReferentialAction;\n readonly onUpdate?: ReferentialAction;\n readonly constraint: boolean;\n readonly index: boolean;\n}\n\nexport interface MaterializedTableConstraints {\n readonly foreignKeys: readonly ForeignKeyInput[];\n readonly indexes: readonly IndexInput[];\n}\n\n/**\n * Lowers a table's authored foreign keys into the discrete entities\n * `contract.json` persists: a `constraint: false` FK contributes no\n * `foreignKeys[]` entry, and an `index: true` FK whose columns aren't already\n * backed by a declared index/unique/primary-key contributes a named\n * `indexes[]` entry (`defaultIndexName`). Declared indexes always survive\n * unchanged; a second FK sharing already-synthesized backing columns does not\n * mint a duplicate index.\n */\nexport function materializeForeignKeysAndIndexes(\n tableName: string,\n foreignKeys: readonly ForeignKeyAuthoringInput[],\n declaredIndexes: readonly IndexInput[],\n uniques: readonly UniqueConstraintInput[],\n primaryKey: PrimaryKeyInput | undefined,\n): MaterializedTableConstraints {\n const satisfiedIndexColumns = new Set(\n backingIndexColumnKeys({ indexes: declaredIndexes, uniques, primaryKey }),\n );\n const synthesizedIndexes: IndexInput[] = [];\n const materializedForeignKeys: ForeignKeyInput[] = [];\n\n for (const { constraint, index, ...reference } of foreignKeys) {\n if (constraint !== false) {\n materializedForeignKeys.push(reference);\n }\n if (index !== false) {\n const key = reference.source.columns.join(',');\n if (!satisfiedIndexColumns.has(key)) {\n synthesizedIndexes.push({\n columns: reference.source.columns,\n name: defaultIndexName(tableName, reference.source.columns),\n });\n satisfiedIndexColumns.add(key);\n }\n }\n }\n\n return {\n foreignKeys: materializedForeignKeys,\n indexes: [...declaredIndexes, ...synthesizedIndexes],\n };\n}\n"],"mappings":";;;;;;;;;;;;;AAwBA,SAAgB,uBAAuB,OAAkD;CACvF,OAAO;EACL,GAAG,MAAM,QAAQ,KAAK,UAAU,MAAM,QAAQ,KAAK,GAAG,CAAC;EACvD,GAAG,MAAM,QAAQ,KAAK,WAAW,OAAO,QAAQ,KAAK,GAAG,CAAC;EACzD,GAAI,MAAM,aAAa,CAAC,MAAM,WAAW,QAAQ,KAAK,GAAG,CAAC,IAAI,CAAC;CACjE;AACF;;;;;;AAOA,SAAgB,qBACd,SACA,aACS;CACT,OAAO,YAAY,SAAS,QAAQ,KAAK,GAAG,CAAC;AAC/C;;;;;;;;;;AA+BA,SAAgB,iCACd,WACA,aACA,iBACA,SACA,YAC8B;CAC9B,MAAM,wBAAwB,IAAI,IAChC,uBAAuB;EAAE,SAAS;EAAiB;EAAS;CAAW,CAAC,CAC1E;CACA,MAAM,qBAAmC,CAAC;CAC1C,MAAM,0BAA6C,CAAC;CAEpD,KAAK,MAAM,EAAE,YAAY,OAAO,GAAG,eAAe,aAAa;EAC7D,IAAI,eAAe,OACjB,wBAAwB,KAAK,SAAS;EAExC,IAAI,UAAU,OAAO;GACnB,MAAM,MAAM,UAAU,OAAO,QAAQ,KAAK,GAAG;GAC7C,IAAI,CAAC,sBAAsB,IAAI,GAAG,GAAG;IACnC,mBAAmB,KAAK;KACtB,SAAS,UAAU,OAAO;KAC1B,MAAM,iBAAiB,WAAW,UAAU,OAAO,OAAO;IAC5D,CAAC;IACD,sBAAsB,IAAI,GAAG;GAC/B;EACF;CACF;CAEA,OAAO;EACL,aAAa;EACb,SAAS,CAAC,GAAG,iBAAiB,GAAG,kBAAkB;CACrD;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { t as StorageTable } from "./storage-table-CE-Ns6wa.mjs";
|
|
2
|
+
import { s as SqlStorage } from "./sql-storage-p-Wzt_MO.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/resolve-storage-table.d.ts
|
|
5
5
|
interface ResolvedStorageTable {
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { IRNodeBase } from "@prisma-next/framework-components/ir";
|
|
2
|
+
|
|
3
|
+
//#region src/ir/sql-node.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* SQL family IR node base. Carries the family-level `kind` discriminator
|
|
6
|
+
* `'sql'` and inherits the framework's `freezeNode` affordance.
|
|
7
|
+
*
|
|
8
|
+
* Single family-level discriminator (not per-leaf) reflects the fact that
|
|
9
|
+
* SQL IR has no polymorphic dispatch today — verifiers and serializers
|
|
10
|
+
* walk by structural position (`storage.tables[name].columns[name]`),
|
|
11
|
+
* not by inspecting `kind`. The abstract bar for per-leaf discriminators
|
|
12
|
+
* isn't earned until a future polymorphic consumer arrives.
|
|
13
|
+
*
|
|
14
|
+
* `kind` is installed as a non-enumerable own property on every instance,
|
|
15
|
+
* which keeps three things clean simultaneously:
|
|
16
|
+
*
|
|
17
|
+
* - `JSON.stringify(node)` produces the canonical pre-lift JSON envelope
|
|
18
|
+
* shape (no `kind` field), so emitted contract.json files and the
|
|
19
|
+
* `validateSqlContractFully` arktype schemas stay unchanged.
|
|
20
|
+
* - Test assertions that use `toEqual({...})` against the pre-lift flat
|
|
21
|
+
* shape continue to pass — only enumerable own properties are
|
|
22
|
+
* compared.
|
|
23
|
+
* - Direct access (`node.kind`) and runtime narrowing
|
|
24
|
+
* (`if (node.kind === 'sql')`) still work, so future polymorphic
|
|
25
|
+
* dispatch can begin reading `kind` without a runtime change.
|
|
26
|
+
*
|
|
27
|
+
* Future per-leaf overrides land cleanly: a class that gains a
|
|
28
|
+
* polymorphic-dispatch consumer (e.g. an enum type instance walked
|
|
29
|
+
* alongside other types) overrides `kind` with its narrower literal
|
|
30
|
+
* at that leaf level. Per-leaf overrides will use enumerable kind
|
|
31
|
+
* (matching the Mongo per-class-discriminator precedent) because they
|
|
32
|
+
* encode dispatch-relevant information that callers need to see in
|
|
33
|
+
* JSON envelopes; the family-level `'sql'` is uniform across all SQL
|
|
34
|
+
* IR and carries no dispatch-relevant information.
|
|
35
|
+
*/
|
|
36
|
+
declare abstract class SqlNode extends IRNodeBase {
|
|
37
|
+
readonly kind?: string;
|
|
38
|
+
constructor();
|
|
39
|
+
}
|
|
40
|
+
//#endregion
|
|
41
|
+
export { SqlNode as t };
|
|
42
|
+
//# sourceMappingURL=sql-node-V214WXQD.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sql-node-V214WXQD.d.mts","names":[],"sources":["../src/ir/sql-node.ts"],"mappings":";;;;;AAkCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uBAAsB,OAAA,SAAgB,UAAU;EAAA,SACrC,IAAA"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { t as SqlNode } from "./sql-node-V214WXQD.mjs";
|
|
2
|
+
import { t as StorageTable } from "./storage-table-CE-Ns6wa.mjs";
|
|
3
|
+
import { t as StorageValueSet } from "./storage-value-set-D-jww77l.mjs";
|
|
4
|
+
import { Namespace, NamespaceBase, Storage, StorageType } from "@prisma-next/framework-components/ir";
|
|
4
5
|
import { StorageHashBase } from "@prisma-next/contract/types";
|
|
6
|
+
import { AuthoringContributions } from "@prisma-next/framework-components/authoring";
|
|
5
7
|
|
|
6
8
|
//#region src/ir/storage-type-instance.d.ts
|
|
7
9
|
/**
|
|
@@ -60,14 +62,34 @@ declare function isStorageTypeInstance(value: unknown): value is StorageTypeInst
|
|
|
60
62
|
* `entries.type` slot on `PostgresSchema` (target layer), not here.
|
|
61
63
|
*/
|
|
62
64
|
type SqlStorageTypeEntry = StorageTypeInstance | StorageTypeInstanceInput;
|
|
63
|
-
interface
|
|
65
|
+
interface SqlNamespaceInput {
|
|
64
66
|
readonly id: string;
|
|
65
67
|
readonly entries: Readonly<Record<string, Readonly<Record<string, unknown>>>>;
|
|
66
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Target-supplied factory that materializes a `Namespace` from a SQL
|
|
71
|
+
* `SqlNamespaceInput` (used to populate `SqlStorage.namespaces`).
|
|
72
|
+
*/
|
|
73
|
+
type SqlNamespaceFactory = (input: SqlNamespaceInput) => Namespace;
|
|
74
|
+
/**
|
|
75
|
+
* SQL-family extension of the framework `AuthoringContributions`. SQL target
|
|
76
|
+
* packs add a `createNamespace` factory so the PSL/TS authoring paths can
|
|
77
|
+
* materialize namespaces (and merge lowered extension-block entities) without
|
|
78
|
+
* each consumer re-specifying it. The factory is SQL-specific, so it lives here
|
|
79
|
+
* rather than on the framework `AuthoringContributions` base.
|
|
80
|
+
*/
|
|
81
|
+
interface SqlAuthoringContributions extends AuthoringContributions {
|
|
82
|
+
readonly createNamespace?: SqlNamespaceFactory;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Narrows framework `AuthoringContributions` to the SQL-family shape by testing
|
|
86
|
+
* for the SQL-specific `createNamespace` capability.
|
|
87
|
+
*/
|
|
88
|
+
declare function isSqlAuthoringContributions(authoring: AuthoringContributions | undefined): authoring is SqlAuthoringContributions;
|
|
67
89
|
interface SqlStorageInput<THash extends string = string> {
|
|
68
90
|
readonly storageHash: StorageHashBase<THash>;
|
|
69
91
|
readonly types?: Record<string, SqlStorageTypeEntry>;
|
|
70
|
-
readonly namespaces: Readonly<Record<string,
|
|
92
|
+
readonly namespaces: Readonly<Record<string, SqlNamespaceBase>>;
|
|
71
93
|
}
|
|
72
94
|
/**
|
|
73
95
|
* SQL Contract IR root node for the `storage` field.
|
|
@@ -101,22 +123,43 @@ type SqlNamespaceEntries = Readonly<Record<string, Readonly<Record<string, unkno
|
|
|
101
123
|
readonly valueSet?: Readonly<Record<string, StorageValueSet>>;
|
|
102
124
|
};
|
|
103
125
|
/**
|
|
104
|
-
* SQL family
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
126
|
+
* Structural interface for SQL family namespaces. Generated `.d.ts` contract
|
|
127
|
+
* types satisfy this structurally (no prototype methods). The runtime
|
|
128
|
+
* abstract class `SqlNamespaceBase` extends this.
|
|
129
|
+
*
|
|
130
|
+
* `qualifyTable` and `isUnbound` are optional so JSON-shaped contract types
|
|
131
|
+
* (which carry no methods) are accepted where `SqlNamespace` is required.
|
|
132
|
+
* Hydrated `SqlNamespaceBase` instances always have both.
|
|
109
133
|
*/
|
|
110
|
-
|
|
134
|
+
interface SqlNamespace {
|
|
135
|
+
readonly kind: string;
|
|
136
|
+
readonly id: string;
|
|
111
137
|
readonly entries: SqlNamespaceEntries;
|
|
112
|
-
|
|
113
|
-
* Render a dialect-qualified table reference for runtime SQL emission.
|
|
114
|
-
* Present on materialised target concretions (`PostgresSchema`,
|
|
115
|
-
* `SqliteDatabase`, …) and family placeholders; omitted on emitted
|
|
116
|
-
* contract structural namespace literals (methods are not serialised).
|
|
117
|
-
*/
|
|
138
|
+
readonly isUnbound?: boolean;
|
|
118
139
|
qualifyTable?(tableName: string): string;
|
|
119
|
-
}
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Abstract SQL family namespace base class. Target concretions (`PostgresSchema`,
|
|
143
|
+
* `SqliteDatabase`, …) extend this — it is never instantiated directly.
|
|
144
|
+
* `entries` is the open ADR 224 dictionary: `entries[entityKind][entityName]`
|
|
145
|
+
* addresses any entity.
|
|
146
|
+
*/
|
|
147
|
+
declare abstract class SqlNamespaceBase extends NamespaceBase implements SqlNamespace {
|
|
148
|
+
abstract readonly id: string;
|
|
149
|
+
abstract readonly entries: SqlNamespaceEntries;
|
|
150
|
+
abstract qualifyTable(tableName: string): string;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Realm-safe guard for hydrated `SqlNamespaceBase` concretions. Checks
|
|
154
|
+
* `qualifyTable` structurally instead of `instanceof NamespaceBase`, so it
|
|
155
|
+
* survives duplicate-module boundaries (e.g. dist e2e where the target and
|
|
156
|
+
* the family carry separate copies of `@prisma-next/framework-components`).
|
|
157
|
+
*
|
|
158
|
+
* Every concrete `SqlNamespaceBase` subclass (`PostgresSchema`, `SqliteDatabase`,
|
|
159
|
+
* `TestSqlNamespace`, …) implements `qualifyTable`. Raw `SqlNamespaceInput`
|
|
160
|
+
* objects (`{ id, entries }`) do not.
|
|
161
|
+
*/
|
|
162
|
+
declare function isMaterializedSqlNamespace(x: unknown): x is SqlNamespaceBase;
|
|
120
163
|
declare class SqlStorage<THash extends string = string> extends SqlNode implements Storage {
|
|
121
164
|
readonly storageHash: StorageHashBase<THash>;
|
|
122
165
|
readonly namespaces: Readonly<Record<string, SqlNamespace>>;
|
|
@@ -124,5 +167,5 @@ declare class SqlStorage<THash extends string = string> extends SqlNode implemen
|
|
|
124
167
|
constructor(input: SqlStorageInput<THash>);
|
|
125
168
|
}
|
|
126
169
|
//#endregion
|
|
127
|
-
export {
|
|
128
|
-
//# sourceMappingURL=sql-storage-
|
|
170
|
+
export { SqlNamespaceFactory as a, SqlStorageInput as c, isSqlAuthoringContributions as d, CODEC_INSTANCE_KIND as f, toStorageTypeInstance as g, isStorageTypeInstance as h, SqlNamespaceEntries as i, SqlStorageTypeEntry as l, StorageTypeInstanceInput as m, SqlNamespace as n, SqlNamespaceInput as o, StorageTypeInstance as p, SqlNamespaceBase as r, SqlStorage as s, SqlAuthoringContributions as t, isMaterializedSqlNamespace as u };
|
|
171
|
+
//# sourceMappingURL=sql-storage-p-Wzt_MO.d.mts.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AA,CAAS,MAAA;EAAA,SACxD,KAAA,GAAQ,QAAA,CAAS,MAAA,SAAe,YAAA;EAAA,SAChC,QAAA,GAAW,QAAA,CAAS,MAAA,SAAe,eAAA;AAAA;;;;;;;;AApEa;AAO3D;UAyEiB,YAAA;EAAA,SACN,IAAA;EAAA,SACA,EAAA;EAAA,SACA,OAAA,EAAS,mBAAmB;EAAA,SAC5B,SAAA;EACT,YAAA,EAAc,SAAA;AAAA;AA9EyD;AASzE;;;;;AATyE,uBAuFnD,gBAAA,SAAyB,aAAA,YAAyB,YAAA;EAAA,kBAC3C,EAAA;EAAA,kBACA,OAAA,EAAS,mBAAA;EAAA,SAE3B,YAAA,CAAa,SAAA;AAAA;;;;;;;;;AAxEiB;AAOzC;iBA8EgB,0BAAA,CAA2B,CAAA,YAAa,CAAA,IAAK,gBAAgB;AAAA,cAKhE,UAAA,wCAAkD,OAAA,YAAmB,OAAA;EAAA,SACvE,WAAA,EAAa,eAAA,CAAgB,KAAA;EAAA,SAC7B,UAAA,EAAY,QAAA,CAAS,MAAA,SAAe,YAAA;EAAA,SAC5B,KAAA,GAAQ,QAAA,CAAS,MAAA,SAAe,mBAAA;cAErC,KAAA,EAAO,eAAA,CAAgB,KAAA;AAAA"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { t as SqlNode } from "./sql-node-V214WXQD.mjs";
|
|
2
|
+
import { n as ForeignKeyInput, t as ForeignKey } from "./foreign-key-DuCoGJCf.mjs";
|
|
3
|
+
import { a as PrimaryKey, i as IndexInput, n as UniqueConstraintInput, o as PrimaryKeyInput, r as Index, t as UniqueConstraint } from "./unique-constraint-C0De4sLU.mjs";
|
|
4
|
+
import { ColumnDefault, ControlPolicy, ValueSetRef } from "@prisma-next/contract/types";
|
|
3
5
|
|
|
4
6
|
//#region src/ir/check-constraint.d.ts
|
|
5
7
|
/**
|
|
@@ -33,43 +35,6 @@ declare class CheckConstraint extends SqlNode {
|
|
|
33
35
|
constructor(input: CheckConstraintInput);
|
|
34
36
|
}
|
|
35
37
|
//#endregion
|
|
36
|
-
//#region src/ir/primary-key.d.ts
|
|
37
|
-
interface PrimaryKeyInput {
|
|
38
|
-
readonly columns: readonly string[];
|
|
39
|
-
readonly name?: string;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* SQL Contract IR node for a table's primary-key constraint.
|
|
43
|
-
*/
|
|
44
|
-
declare class PrimaryKey extends SqlNode {
|
|
45
|
-
readonly columns: readonly string[];
|
|
46
|
-
readonly name?: string;
|
|
47
|
-
constructor(input: PrimaryKeyInput);
|
|
48
|
-
}
|
|
49
|
-
//#endregion
|
|
50
|
-
//#region src/ir/sql-index.d.ts
|
|
51
|
-
interface IndexInput {
|
|
52
|
-
readonly columns: readonly string[];
|
|
53
|
-
readonly name?: string;
|
|
54
|
-
readonly type?: string;
|
|
55
|
-
readonly options?: Record<string, unknown>;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* SQL Contract IR node for a table-level secondary index.
|
|
59
|
-
*
|
|
60
|
-
* Note that this class shadows the global TypeScript `Index` lib type
|
|
61
|
-
* at the family-shared name; consumer files that need both should
|
|
62
|
-
* alias one (e.g.
|
|
63
|
-
* `import { Index as SqlIndexNode } from '@prisma-next/sql-contract/types'`).
|
|
64
|
-
*/
|
|
65
|
-
declare class Index extends SqlNode {
|
|
66
|
-
readonly columns: readonly string[];
|
|
67
|
-
readonly name?: string;
|
|
68
|
-
readonly type?: string;
|
|
69
|
-
readonly options?: Record<string, unknown>;
|
|
70
|
-
constructor(input: IndexInput);
|
|
71
|
-
}
|
|
72
|
-
//#endregion
|
|
73
38
|
//#region src/ir/storage-column.d.ts
|
|
74
39
|
/**
|
|
75
40
|
* Hydration / construction input shape for {@link StorageColumn}. Mirrors
|
|
@@ -85,6 +50,7 @@ interface StorageColumnInput {
|
|
|
85
50
|
readonly nativeType: string;
|
|
86
51
|
readonly codecId: string;
|
|
87
52
|
readonly nullable: boolean;
|
|
53
|
+
readonly many?: boolean;
|
|
88
54
|
readonly typeParams?: Record<string, unknown>;
|
|
89
55
|
readonly typeRef?: string;
|
|
90
56
|
readonly default?: ColumnDefault;
|
|
@@ -108,6 +74,7 @@ declare class StorageColumn extends SqlNode {
|
|
|
108
74
|
readonly nativeType: string;
|
|
109
75
|
readonly codecId: string;
|
|
110
76
|
readonly nullable: boolean;
|
|
77
|
+
readonly many?: boolean;
|
|
111
78
|
readonly typeParams?: Record<string, unknown>;
|
|
112
79
|
readonly typeRef?: string;
|
|
113
80
|
readonly default?: ColumnDefault;
|
|
@@ -116,20 +83,6 @@ declare class StorageColumn extends SqlNode {
|
|
|
116
83
|
constructor(input: StorageColumnInput);
|
|
117
84
|
}
|
|
118
85
|
//#endregion
|
|
119
|
-
//#region src/ir/unique-constraint.d.ts
|
|
120
|
-
interface UniqueConstraintInput {
|
|
121
|
-
readonly columns: readonly string[];
|
|
122
|
-
readonly name?: string;
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* SQL Contract IR node for a table-level unique constraint.
|
|
126
|
-
*/
|
|
127
|
-
declare class UniqueConstraint extends SqlNode {
|
|
128
|
-
readonly columns: readonly string[];
|
|
129
|
-
readonly name?: string;
|
|
130
|
-
constructor(input: UniqueConstraintInput);
|
|
131
|
-
}
|
|
132
|
-
//#endregion
|
|
133
86
|
//#region src/ir/storage-table.d.ts
|
|
134
87
|
interface StorageTableInput {
|
|
135
88
|
readonly columns: Record<string, StorageColumn | StorageColumnInput>;
|
|
@@ -161,42 +114,16 @@ declare class StorageTable extends SqlNode {
|
|
|
161
114
|
readonly control?: ControlPolicy;
|
|
162
115
|
readonly checks?: ReadonlyArray<CheckConstraint>;
|
|
163
116
|
constructor(input: StorageTableInput);
|
|
117
|
+
/**
|
|
118
|
+
* Runtime guard that a namespace `table` entry is really a `StorageTable`.
|
|
119
|
+
* The compiler already types the entry as `StorageTable`, but a
|
|
120
|
+
* freshly-deserialized contract may carry plain JSON at that slot until
|
|
121
|
+
* hydration; this duck-types the structural shape. Accepts `undefined` so
|
|
122
|
+
* optional-chained entry lookups pass straight through.
|
|
123
|
+
*/
|
|
124
|
+
static is(value: StorageTable | undefined): value is StorageTable;
|
|
125
|
+
static assert(value: StorageTable | undefined, coordinate: string): asserts value is StorageTable;
|
|
164
126
|
}
|
|
165
127
|
//#endregion
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
* Hydration / construction input shape for {@link StorageValueSet}.
|
|
169
|
-
* Mirrors the on-disk storage JSON envelope so the serializer hydration
|
|
170
|
-
* walker can hand a validated literal straight to `new`.
|
|
171
|
-
*/
|
|
172
|
-
interface StorageValueSetInput {
|
|
173
|
-
readonly kind: 'valueSet';
|
|
174
|
-
/** Ordered permitted values, codec-encoded. Declaration order is preserved. */
|
|
175
|
-
readonly values: readonly JsonValue[];
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* SQL Contract IR node for a value-set entry in a namespace's `valueSet`
|
|
179
|
-
* map (`SqlNamespace.entries.valueSet`).
|
|
180
|
-
*
|
|
181
|
-
* A value-set records the ordered set of permitted codec-encoded values for
|
|
182
|
-
* an enum-like column restriction. It does not carry a `codecId` — the
|
|
183
|
-
* column that references it already holds the codec; the value-set holds
|
|
184
|
-
* only the permitted values.
|
|
185
|
-
*
|
|
186
|
-
* The node's `kind` is enumerable (`'valueSet'`) so the JSON envelope
|
|
187
|
-
* carries the discriminator and the serializer hydration walker can
|
|
188
|
-
* dispatch on it. This follows the per-leaf enumerable-kind convention
|
|
189
|
-
* established in the SQL-node comment (future polymorphic dispatch on
|
|
190
|
-
* namespace entries needs the discriminator in JSON).
|
|
191
|
-
*
|
|
192
|
-
* The entry's name is not on the class — value-sets are keyed by name in
|
|
193
|
-
* the parent namespace's `valueSet: Record<string, StorageValueSet>` map.
|
|
194
|
-
*/
|
|
195
|
-
declare class StorageValueSet extends SqlNode {
|
|
196
|
-
readonly kind: "valueSet";
|
|
197
|
-
readonly values: readonly JsonValue[];
|
|
198
|
-
constructor(input: StorageValueSetInput);
|
|
199
|
-
}
|
|
200
|
-
//#endregion
|
|
201
|
-
export { UniqueConstraint as a, StorageColumnInput as c, PrimaryKey as d, PrimaryKeyInput as f, StorageTableInput as i, Index as l, CheckConstraintInput as m, StorageValueSetInput as n, UniqueConstraintInput as o, CheckConstraint as p, StorageTable as r, StorageColumn as s, StorageValueSet as t, IndexInput as u };
|
|
202
|
-
//# sourceMappingURL=storage-value-set-WnYsIFM8.d.mts.map
|
|
128
|
+
export { CheckConstraint as a, StorageColumnInput as i, StorageTableInput as n, CheckConstraintInput as o, StorageColumn as r, StorageTable as t };
|
|
129
|
+
//# sourceMappingURL=storage-table-CE-Ns6wa.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage-table-CE-Ns6wa.d.mts","names":[],"sources":["../src/ir/check-constraint.ts","../src/ir/storage-column.ts","../src/ir/storage-table.ts"],"mappings":";;;;;;;;;;AASA;UAAiB,oBAAA;EAAA,SACN,IAAA;EAAA,SACA,MAAA;EAAA,SACA,QAAA,EAAU,WAAW;AAAA;;;;AAAA;AAiBhC;;;;;;;;;;cAAa,eAAA,SAAwB,OAAA;EAAA,SAC1B,IAAA;EAAA,SACA,MAAA;EAAA,SACA,QAAA,EAAU,WAAA;cAEP,KAAA,EAAO,oBAAA;AAAA;;;;;;;AAzBrB;;;;;;UCKiB,kBAAA;EAAA,SACN,UAAA;EAAA,SACA,OAAA;EAAA,SACA,QAAA;EAAA,SACA,IAAA;EAAA,SACA,UAAA,GAAa,MAAA;EAAA,SACb,OAAA;EAAA,SACA,OAAA,GAAU,aAAA;EAAA,SACV,OAAA,GAAU,aAAA;EAAA,SACV,QAAA,GAAW,WAAA;AAAA;;;;;;;;;;;ADWmB;;;cCK5B,aAAA,SAAsB,OAAA;EAAA,SACxB,UAAA;EAAA,SACA,OAAA;EAAA,SACA,QAAA;EAAA,SACQ,IAAA;EAAA,SACA,UAAA,GAAa,MAAA;EAAA,SACb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