@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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"canonicalization-hooks.d.mts","names":[],"sources":["../src/canonicalization-hooks.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"canonicalization-hooks.d.mts","names":[],"sources":["../src/canonicalization-hooks.ts"],"mappings":";;;cAoDa,gCAAA;EAAA,SACF,mBAAA,EAAqB,sBAAA;EAAA,SACrB,WAAA,EAAa,WAAW;AAAA"}
|
|
@@ -1,55 +1,75 @@
|
|
|
1
|
-
import { createPreserveEmptyPredicate, createStorageSort } from "@prisma-next/contract/hashing-utils";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
import { createPreserveEmptyPredicate, createStorageSort, matchesPathPattern } from "@prisma-next/contract/hashing-utils";
|
|
2
|
+
//#region src/canonicalization-hooks.ts
|
|
3
|
+
const preserveEmptyPatterns = [
|
|
4
|
+
[
|
|
5
|
+
"storage",
|
|
6
|
+
"namespaces",
|
|
7
|
+
"*",
|
|
8
|
+
"entries",
|
|
9
|
+
"table"
|
|
10
|
+
],
|
|
11
|
+
[
|
|
12
|
+
"storage",
|
|
13
|
+
"namespaces",
|
|
14
|
+
"*",
|
|
15
|
+
"entries",
|
|
16
|
+
"table",
|
|
17
|
+
"*"
|
|
18
|
+
],
|
|
19
|
+
[
|
|
20
|
+
"storage",
|
|
21
|
+
"namespaces",
|
|
22
|
+
"*",
|
|
23
|
+
"entries",
|
|
24
|
+
"table",
|
|
25
|
+
"*",
|
|
19
26
|
[
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"entries",
|
|
24
|
-
"table",
|
|
25
|
-
"*",
|
|
26
|
-
[
|
|
27
|
-
"uniques",
|
|
28
|
-
"indexes",
|
|
29
|
-
"foreignKeys"
|
|
30
|
-
]
|
|
31
|
-
],
|
|
32
|
-
[
|
|
33
|
-
"storage",
|
|
34
|
-
"namespaces",
|
|
35
|
-
"*",
|
|
36
|
-
"entries",
|
|
37
|
-
"table",
|
|
38
|
-
"*",
|
|
39
|
-
"foreignKeys",
|
|
40
|
-
["constraint", "index"]
|
|
27
|
+
"uniques",
|
|
28
|
+
"indexes",
|
|
29
|
+
"foreignKeys"
|
|
41
30
|
]
|
|
42
|
-
]
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
31
|
+
],
|
|
32
|
+
[
|
|
33
|
+
"storage",
|
|
34
|
+
"namespaces",
|
|
35
|
+
"*",
|
|
36
|
+
"entries",
|
|
37
|
+
"table",
|
|
38
|
+
"*",
|
|
39
|
+
"columns",
|
|
40
|
+
"*",
|
|
41
|
+
"default",
|
|
42
|
+
"value"
|
|
43
|
+
]
|
|
44
|
+
];
|
|
45
|
+
const columnDefaultValuePrefix = [
|
|
46
|
+
"storage",
|
|
47
|
+
"namespaces",
|
|
48
|
+
"*",
|
|
49
|
+
"entries",
|
|
50
|
+
"table",
|
|
51
|
+
"*",
|
|
52
|
+
"columns",
|
|
53
|
+
"*",
|
|
54
|
+
"default",
|
|
55
|
+
"value"
|
|
56
|
+
];
|
|
57
|
+
const isColumnDefaultValuePath = (path) => path.length >= columnDefaultValuePrefix.length && matchesPathPattern(path.slice(0, columnDefaultValuePrefix.length), columnDefaultValuePrefix);
|
|
58
|
+
const sortTargets = [{
|
|
59
|
+
path: [
|
|
60
|
+
"namespaces",
|
|
61
|
+
"*",
|
|
62
|
+
"entries",
|
|
63
|
+
"table",
|
|
64
|
+
"*"
|
|
65
|
+
],
|
|
66
|
+
arrayKeys: ["indexes", "uniques"]
|
|
67
|
+
}];
|
|
68
|
+
const matchesPreserveEmptyPattern = createPreserveEmptyPredicate(preserveEmptyPatterns);
|
|
69
|
+
const shouldPreserveEmpty = (path) => isColumnDefaultValuePath(path) || matchesPreserveEmptyPattern(path);
|
|
70
|
+
const sqlContractCanonicalizationHooks = {
|
|
71
|
+
shouldPreserveEmpty,
|
|
72
|
+
sortStorage: createStorageSort(sortTargets)
|
|
53
73
|
};
|
|
54
74
|
//#endregion
|
|
55
75
|
export { sqlContractCanonicalizationHooks };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"canonicalization-hooks.mjs","names":[],"sources":["../src/canonicalization-hooks.ts"],"sourcesContent":["import type { PreserveEmptyPredicate, StorageSort } from '@prisma-next/contract/hashing';\nimport {\n createPreserveEmptyPredicate,\n createStorageSort,\n type NamedArraySortTarget,\n type PathPattern,\n} from '@prisma-next/contract/hashing-utils';\n\nconst preserveEmptyPatterns = [\n ['storage', 'namespaces', '*', 'entries', 'table'],\n ['storage', 'namespaces', '*', 'entries', 'table', '*'],\n ['storage', 'namespaces', '*', 'entries', 'table', '*', ['uniques', 'indexes', 'foreignKeys']],\n ['storage', 'namespaces', '*', 'entries', 'table', '*', '
|
|
1
|
+
{"version":3,"file":"canonicalization-hooks.mjs","names":[],"sources":["../src/canonicalization-hooks.ts"],"sourcesContent":["import type { PreserveEmptyPredicate, StorageSort } from '@prisma-next/contract/hashing';\nimport {\n createPreserveEmptyPredicate,\n createStorageSort,\n matchesPathPattern,\n type NamedArraySortTarget,\n type PathPattern,\n} from '@prisma-next/contract/hashing-utils';\n\nconst preserveEmptyPatterns = [\n ['storage', 'namespaces', '*', 'entries', 'table'],\n ['storage', 'namespaces', '*', 'entries', 'table', '*'],\n ['storage', 'namespaces', '*', 'entries', 'table', '*', ['uniques', 'indexes', 'foreignKeys']],\n // A column default's literal payload is data, not shape — `{ kind:\n // 'literal', value: false }` (or `value: []`) must survive the\n // default-omission walk or the emitted contract fails its own\n // validation on the next read (PN-CLI-4003 on `Boolean @default(false)`).\n ['storage', 'namespaces', '*', 'entries', 'table', '*', 'columns', '*', 'default', 'value'],\n] as const satisfies readonly PathPattern[];\n\n// A literal column default's value is user data, not omittable structure:\n// `@default(false)` (and empty objects/arrays at any depth inside the value)\n// must survive canonicalization, or the emitted contract fails the runtime's\n// structural validation with `default.value … (was missing)`.\nconst columnDefaultValuePrefix = [\n 'storage',\n 'namespaces',\n '*',\n 'entries',\n 'table',\n '*',\n 'columns',\n '*',\n 'default',\n 'value',\n] as const satisfies PathPattern;\n\nconst isColumnDefaultValuePath = (path: readonly string[]): boolean =>\n path.length >= columnDefaultValuePrefix.length &&\n matchesPathPattern(path.slice(0, columnDefaultValuePrefix.length), columnDefaultValuePrefix);\n\nconst sortTargets = [\n { path: ['namespaces', '*', 'entries', 'table', '*'], arrayKeys: ['indexes', 'uniques'] },\n] as const satisfies readonly NamedArraySortTarget[];\n\nconst matchesPreserveEmptyPattern = createPreserveEmptyPredicate(preserveEmptyPatterns);\n\nconst shouldPreserveEmpty: PreserveEmptyPredicate = (path) =>\n isColumnDefaultValuePath(path) || matchesPreserveEmptyPattern(path);\n\nconst sortStorage: StorageSort = createStorageSort(sortTargets);\n\nexport const sqlContractCanonicalizationHooks: {\n readonly shouldPreserveEmpty: PreserveEmptyPredicate;\n readonly sortStorage: StorageSort;\n} = {\n shouldPreserveEmpty,\n sortStorage,\n};\n"],"mappings":";;AASA,MAAM,wBAAwB;CAC5B;EAAC;EAAW;EAAc;EAAK;EAAW;CAAO;CACjD;EAAC;EAAW;EAAc;EAAK;EAAW;EAAS;CAAG;CACtD;EAAC;EAAW;EAAc;EAAK;EAAW;EAAS;EAAK;GAAC;GAAW;GAAW;EAAa;CAAC;CAK7F;EAAC;EAAW;EAAc;EAAK;EAAW;EAAS;EAAK;EAAW;EAAK;EAAW;CAAO;AAC5F;AAMA,MAAM,2BAA2B;CAC/B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,MAAM,4BAA4B,SAChC,KAAK,UAAU,yBAAyB,UACxC,mBAAmB,KAAK,MAAM,GAAG,yBAAyB,MAAM,GAAG,wBAAwB;AAE7F,MAAM,cAAc,CAClB;CAAE,MAAM;EAAC;EAAc;EAAK;EAAW;EAAS;CAAG;CAAG,WAAW,CAAC,WAAW,SAAS;AAAE,CAC1F;AAEA,MAAM,8BAA8B,6BAA6B,qBAAqB;AAEtF,MAAM,uBAA+C,SACnD,yBAAyB,IAAI,KAAK,4BAA4B,IAAI;AAIpE,MAAa,mCAGT;CACF;CACA,aAP+B,kBAAkB,WAOjD;AACF"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { s as SqlStorage } from "./sql-storage-p-Wzt_MO.mjs";
|
|
2
|
+
import { DefaultNamespaceEntries, NamespacedEntities, SingleNamespaceView } from "@prisma-next/framework-components/ir";
|
|
3
|
+
import { Contract } from "@prisma-next/contract/types";
|
|
4
|
+
|
|
5
|
+
//#region src/contract-view.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* The SQL family's statically-named built-in entity kinds. `table` and
|
|
8
|
+
* `valueSet` are promoted to top-level view accessors; pack-contributed kinds
|
|
9
|
+
* (e.g. `policy`) stay under `.entries`.
|
|
10
|
+
*/
|
|
11
|
+
declare const SQL_BUILTIN_KINDS: readonly ["table", "valueSet"];
|
|
12
|
+
type SqlBuiltinKind = (typeof SQL_BUILTIN_KINDS)[number];
|
|
13
|
+
type SqlEntries<TContract extends Contract<SqlStorage>> = DefaultNamespaceEntries<TContract['storage']>;
|
|
14
|
+
/**
|
|
15
|
+
* The single-namespace SQL accessors: `table`/`valueSet` top-level, pack kinds
|
|
16
|
+
* under `entries`. A target that never emits a built-in kind (SQLite has
|
|
17
|
+
* `sql.enums: false`, so it emits no `valueSet`) resolves that slot to an empty
|
|
18
|
+
* map.
|
|
19
|
+
*/
|
|
20
|
+
type SqlSingleNamespaceAccessors<TContract extends Contract<SqlStorage>> = SingleNamespaceView<SqlEntries<TContract>, SqlBuiltinKind>;
|
|
21
|
+
/**
|
|
22
|
+
* Single-namespace SQL view: the deserialized contract intersected with the
|
|
23
|
+
* by-name accessors, so the value is substitutable for `Contract` while also
|
|
24
|
+
* exposing:
|
|
25
|
+
* - `view.table.<name>` / `view.valueSet.<name>` — built-in kinds, sole
|
|
26
|
+
* namespace unwrapped to the root; pack kinds under `view.entries.<kind>`.
|
|
27
|
+
* - `view.namespace.<id>` — the namespace-keyed entity map (SQLite's sole
|
|
28
|
+
* namespace is `__unbound__`). Mirrors the runtime `db.enums` pattern.
|
|
29
|
+
*/
|
|
30
|
+
type SqlSingleNamespaceView<TContract extends Contract<SqlStorage>> = TContract & SqlSingleNamespaceAccessors<TContract> & {
|
|
31
|
+
readonly namespace: NamespacedEntities<TContract['storage'], SqlBuiltinKind>;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Builds the single-namespace SQL view: unwraps the sole namespace's SQL
|
|
35
|
+
* built-in kinds (`table`, `valueSet`) to the root, attaches the namespace-keyed
|
|
36
|
+
* `namespace` map, and layers both over the deserialized contract. Targets with
|
|
37
|
+
* one default namespace (SQLite) call this directly; Postgres qualifies by
|
|
38
|
+
* schema.
|
|
39
|
+
*/
|
|
40
|
+
declare function buildSqlSingleNamespaceView<TContract extends Contract<SqlStorage>>(contract: TContract): SqlSingleNamespaceView<TContract>;
|
|
41
|
+
/**
|
|
42
|
+
* Schema-qualified SQL view: the deserialized contract intersected with a single
|
|
43
|
+
* `view.namespace.<id>` member — every schema reached by raw id
|
|
44
|
+
* (`view.namespace.public.table.users`), mirroring the runtime `db.enums.<ns>`
|
|
45
|
+
* keying exactly (the default schema keeps its literal `__unbound__` id). There
|
|
46
|
+
* is NO root schema-name promotion, so there is no collision with contract
|
|
47
|
+
* envelope fields — `view.storage` is always the contract's `storage`. Postgres
|
|
48
|
+
* uses this; SQLite (single default namespace) uses
|
|
49
|
+
* {@link buildSqlSingleNamespaceView}.
|
|
50
|
+
*/
|
|
51
|
+
type SqlSchemaQualifiedView<TContract extends Contract<SqlStorage>> = TContract & {
|
|
52
|
+
readonly namespace: NamespacedEntities<TContract['storage'], SqlBuiltinKind>;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Builds the schema-qualified SQL view: attaches the namespace-keyed `namespace`
|
|
56
|
+
* map over the deserialized contract. Postgres uses this.
|
|
57
|
+
*/
|
|
58
|
+
declare function buildSqlSchemaQualifiedView<TContract extends Contract<SqlStorage>>(contract: TContract): SqlSchemaQualifiedView<TContract>;
|
|
59
|
+
//#endregion
|
|
60
|
+
export { SQL_BUILTIN_KINDS, type SqlBuiltinKind, type SqlSchemaQualifiedView, type SqlSingleNamespaceAccessors, type SqlSingleNamespaceView, buildSqlSchemaQualifiedView, buildSqlSingleNamespaceView };
|
|
61
|
+
//# sourceMappingURL=contract-view.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract-view.d.mts","names":[],"sources":["../src/contract-view.ts"],"mappings":";;;;;;;AAeA;;;cAAa,iBAAA;AAAA,KACD,cAAA,WAAyB,iBAAiB;AAAA,KAEjD,UAAA,mBAA6B,QAAA,CAAS,UAAA,KAAe,uBAAA,CACxD,SAAA;;;;AAHoD;AAAU;;KAYpD,2BAAA,mBAA8C,QAAA,CAAS,UAAA,KACjE,mBAAA,CAAoB,UAAA,CAAW,SAAA,GAAY,cAAA;;;;;;;;;;KAWjC,sBAAA,mBAAyC,QAAA,CAAS,UAAA,KAAe,SAAA,GAC3E,2BAAA,CAA4B,SAAA;EAAA,SACjB,SAAA,EAAW,kBAAA,CAAmB,SAAA,aAAsB,cAAA;AAAA;AAvBtD;AASX;;;;;;AATW,iBAiCK,2BAAA,mBAA8C,QAAA,CAAS,UAAA,GACrE,QAAA,EAAU,SAAA,GACT,sBAAA,CAAuB,SAAA;;;;;;;;;;;KAyBd,sBAAA,mBAAyC,QAAA,CAAS,UAAA,KAAe,SAAA;EAAA,SAClE,SAAA,EAAW,kBAAA,CAAmB,SAAA,aAAsB,cAAA;AAAA;AAxC/D;;;;AAAA,iBA+CgB,2BAAA,mBAA8C,QAAA,CAAS,UAAA,GACrE,QAAA,EAAU,SAAA,GACT,sBAAA,CAAuB,SAAA"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { buildNamespacedEntities, buildSingleNamespaceView } from "@prisma-next/framework-components/ir";
|
|
2
|
+
//#region src/contract-view.ts
|
|
3
|
+
/**
|
|
4
|
+
* The SQL family's statically-named built-in entity kinds. `table` and
|
|
5
|
+
* `valueSet` are promoted to top-level view accessors; pack-contributed kinds
|
|
6
|
+
* (e.g. `policy`) stay under `.entries`.
|
|
7
|
+
*/
|
|
8
|
+
const SQL_BUILTIN_KINDS = ["table", "valueSet"];
|
|
9
|
+
/**
|
|
10
|
+
* Builds the single-namespace SQL view: unwraps the sole namespace's SQL
|
|
11
|
+
* built-in kinds (`table`, `valueSet`) to the root, attaches the namespace-keyed
|
|
12
|
+
* `namespace` map, and layers both over the deserialized contract. Targets with
|
|
13
|
+
* one default namespace (SQLite) call this directly; Postgres qualifies by
|
|
14
|
+
* schema.
|
|
15
|
+
*/
|
|
16
|
+
function buildSqlSingleNamespaceView(contract) {
|
|
17
|
+
const rootAccessors = buildSingleNamespaceView(contract.storage, SQL_BUILTIN_KINDS);
|
|
18
|
+
const namespace = buildNamespacedEntities(contract.storage, SQL_BUILTIN_KINDS);
|
|
19
|
+
return {
|
|
20
|
+
...contract,
|
|
21
|
+
...rootAccessors,
|
|
22
|
+
namespace
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Builds the schema-qualified SQL view: attaches the namespace-keyed `namespace`
|
|
27
|
+
* map over the deserialized contract. Postgres uses this.
|
|
28
|
+
*/
|
|
29
|
+
function buildSqlSchemaQualifiedView(contract) {
|
|
30
|
+
const namespace = buildNamespacedEntities(contract.storage, SQL_BUILTIN_KINDS);
|
|
31
|
+
return {
|
|
32
|
+
...contract,
|
|
33
|
+
namespace
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
37
|
+
export { SQL_BUILTIN_KINDS, buildSqlSchemaQualifiedView, buildSqlSingleNamespaceView };
|
|
38
|
+
|
|
39
|
+
//# sourceMappingURL=contract-view.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract-view.mjs","names":[],"sources":["../src/contract-view.ts"],"sourcesContent":["import type { Contract } from '@prisma-next/contract/types';\nimport {\n buildNamespacedEntities,\n buildSingleNamespaceView,\n type DefaultNamespaceEntries,\n type NamespacedEntities,\n type SingleNamespaceView,\n} from '@prisma-next/framework-components/ir';\nimport type { SqlStorage } from './ir/sql-storage';\n\n/**\n * The SQL family's statically-named built-in entity kinds. `table` and\n * `valueSet` are promoted to top-level view accessors; pack-contributed kinds\n * (e.g. `policy`) stay under `.entries`.\n */\nexport const SQL_BUILTIN_KINDS = ['table', 'valueSet'] as const;\nexport type SqlBuiltinKind = (typeof SQL_BUILTIN_KINDS)[number];\n\ntype SqlEntries<TContract extends Contract<SqlStorage>> = DefaultNamespaceEntries<\n TContract['storage']\n>;\n\n/**\n * The single-namespace SQL accessors: `table`/`valueSet` top-level, pack kinds\n * under `entries`. A target that never emits a built-in kind (SQLite has\n * `sql.enums: false`, so it emits no `valueSet`) resolves that slot to an empty\n * map.\n */\nexport type SqlSingleNamespaceAccessors<TContract extends Contract<SqlStorage>> =\n SingleNamespaceView<SqlEntries<TContract>, SqlBuiltinKind>;\n\n/**\n * Single-namespace SQL view: the deserialized contract intersected with the\n * by-name accessors, so the value is substitutable for `Contract` while also\n * exposing:\n * - `view.table.<name>` / `view.valueSet.<name>` — built-in kinds, sole\n * namespace unwrapped to the root; pack kinds under `view.entries.<kind>`.\n * - `view.namespace.<id>` — the namespace-keyed entity map (SQLite's sole\n * namespace is `__unbound__`). Mirrors the runtime `db.enums` pattern.\n */\nexport type SqlSingleNamespaceView<TContract extends Contract<SqlStorage>> = TContract &\n SqlSingleNamespaceAccessors<TContract> & {\n readonly namespace: NamespacedEntities<TContract['storage'], SqlBuiltinKind>;\n };\n\n/**\n * Builds the single-namespace SQL view: unwraps the sole namespace's SQL\n * built-in kinds (`table`, `valueSet`) to the root, attaches the namespace-keyed\n * `namespace` map, and layers both over the deserialized contract. Targets with\n * one default namespace (SQLite) call this directly; Postgres qualifies by\n * schema.\n */\nexport function buildSqlSingleNamespaceView<TContract extends Contract<SqlStorage>>(\n contract: TContract,\n): SqlSingleNamespaceView<TContract> {\n const rootAccessors = buildSingleNamespaceView<SqlSingleNamespaceAccessors<TContract>>(\n contract.storage,\n SQL_BUILTIN_KINDS,\n );\n const namespace = buildNamespacedEntities<\n NamespacedEntities<TContract['storage'], SqlBuiltinKind>\n >(contract.storage, SQL_BUILTIN_KINDS);\n return {\n ...contract,\n ...rootAccessors,\n namespace,\n };\n}\n\n/**\n * Schema-qualified SQL view: the deserialized contract intersected with a single\n * `view.namespace.<id>` member — every schema reached by raw id\n * (`view.namespace.public.table.users`), mirroring the runtime `db.enums.<ns>`\n * keying exactly (the default schema keeps its literal `__unbound__` id). There\n * is NO root schema-name promotion, so there is no collision with contract\n * envelope fields — `view.storage` is always the contract's `storage`. Postgres\n * uses this; SQLite (single default namespace) uses\n * {@link buildSqlSingleNamespaceView}.\n */\nexport type SqlSchemaQualifiedView<TContract extends Contract<SqlStorage>> = TContract & {\n readonly namespace: NamespacedEntities<TContract['storage'], SqlBuiltinKind>;\n};\n\n/**\n * Builds the schema-qualified SQL view: attaches the namespace-keyed `namespace`\n * map over the deserialized contract. Postgres uses this.\n */\nexport function buildSqlSchemaQualifiedView<TContract extends Contract<SqlStorage>>(\n contract: TContract,\n): SqlSchemaQualifiedView<TContract> {\n const namespace = buildNamespacedEntities<\n NamespacedEntities<TContract['storage'], SqlBuiltinKind>\n >(contract.storage, SQL_BUILTIN_KINDS);\n return {\n ...contract,\n namespace,\n };\n}\n"],"mappings":";;;;;;;AAeA,MAAa,oBAAoB,CAAC,SAAS,UAAU;;;;;;;;AAqCrD,SAAgB,4BACd,UACmC;CACnC,MAAM,gBAAgB,yBACpB,SAAS,SACT,iBACF;CACA,MAAM,YAAY,wBAEhB,SAAS,SAAS,iBAAiB;CACrC,OAAO;EACL,GAAG;EACH,GAAG;EACH;CACF;AACF;;;;;AAoBA,SAAgB,4BACd,UACmC;CACnC,MAAM,YAAY,wBAEhB,SAAS,SAAS,iBAAiB;CACrC,OAAO;EACL,GAAG;EACH;CACF;AACF"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
//#region src/entity-handle-lowering-hook.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* SQL-family extension to the pack authoring contributions: a pack whose
|
|
4
|
+
* `entityTypes` registers entity kinds may implement a batch lowering hook
|
|
5
|
+
* that turns author-declared pack-entity handles (the generic `entities`
|
|
6
|
+
* list on the TS contract input) into `entries` rows.
|
|
7
|
+
*
|
|
8
|
+
* The generic contract build (`contract-ts`) owns the kind-agnostic walk: it
|
|
9
|
+
* groups handles by the pack that registered each `entityKind`, resolves
|
|
10
|
+
* each handle's declared model refs to storage table coordinates using the
|
|
11
|
+
* same model→table maps the relation lowering uses, and calls the owning
|
|
12
|
+
* pack's hook once with all of its claimed handles — batch, so the hook's
|
|
13
|
+
* diagnostics can see sibling handles. Neither the walk nor these types name
|
|
14
|
+
* any specific entity kind.
|
|
15
|
+
*
|
|
16
|
+
* SQL-family concept — the resolved-ref shape is a table coordinate, so the
|
|
17
|
+
* hook lives here beside {@link ../value-set-derivation-hook} instead of on
|
|
18
|
+
* the framework contributions type.
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* An authored pack-entity handle: branded by the `entityKind` its owning
|
|
22
|
+
* pack registered, optionally declaring model refs under `refs` (actual
|
|
23
|
+
* model-handle objects, resolved by the generic walk before lowering).
|
|
24
|
+
*/
|
|
25
|
+
interface PackEntityHandle {
|
|
26
|
+
readonly entityKind: string;
|
|
27
|
+
readonly refs?: Readonly<Record<string, unknown>>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* A declared model ref after the generic walk resolved it: a storage table
|
|
31
|
+
* coordinate for a model of this contract, the coordinate plus `spaceId` for
|
|
32
|
+
* a cross-space (extensionModel) handle, or `unresolved` when the handle
|
|
33
|
+
* does not correspond to any model in the contract. `modelName` is carried
|
|
34
|
+
* for diagnostics where the handle declares one.
|
|
35
|
+
*/
|
|
36
|
+
type ResolvedEntityHandleRef = {
|
|
37
|
+
readonly kind: 'resolved';
|
|
38
|
+
readonly namespaceId: string;
|
|
39
|
+
readonly tableName: string;
|
|
40
|
+
readonly modelName?: string;
|
|
41
|
+
} | {
|
|
42
|
+
readonly kind: 'cross-space';
|
|
43
|
+
readonly spaceId: string;
|
|
44
|
+
readonly namespaceId: string;
|
|
45
|
+
readonly tableName: string;
|
|
46
|
+
readonly modelName?: string;
|
|
47
|
+
} | {
|
|
48
|
+
readonly kind: 'unresolved';
|
|
49
|
+
readonly modelName?: string;
|
|
50
|
+
};
|
|
51
|
+
/** One claimed handle paired with its resolved declared refs. */
|
|
52
|
+
interface ResolvedPackEntityHandle {
|
|
53
|
+
readonly handle: PackEntityHandle;
|
|
54
|
+
readonly refs: Readonly<Record<string, ResolvedEntityHandleRef>>;
|
|
55
|
+
}
|
|
56
|
+
interface EntityHandleLoweringInput {
|
|
57
|
+
/** Every handle in the `entities` list whose `entityKind` this pack registered, in authored order. */
|
|
58
|
+
readonly handles: readonly ResolvedPackEntityHandle[];
|
|
59
|
+
readonly defaultNamespaceId: string;
|
|
60
|
+
}
|
|
61
|
+
/** One lowered entity row: filed into `storage.namespaces[namespaceId].entries[entityKind][key]`. */
|
|
62
|
+
interface LoweredPackEntity {
|
|
63
|
+
readonly namespaceId: string;
|
|
64
|
+
readonly entityKind: string;
|
|
65
|
+
readonly key: string;
|
|
66
|
+
readonly entity: unknown;
|
|
67
|
+
}
|
|
68
|
+
interface SqlEntityHandleLoweringContribution {
|
|
69
|
+
/**
|
|
70
|
+
* Method syntax keeps the declaration bivariant, so a pack's concretely
|
|
71
|
+
* typed implementation stays structurally compatible (the same convention
|
|
72
|
+
* as `SqlValueSetDerivingEntityTypeOutput.deriveValueSet`).
|
|
73
|
+
*/
|
|
74
|
+
lowerEntityHandles(input: EntityHandleLoweringInput): readonly LoweredPackEntity[];
|
|
75
|
+
}
|
|
76
|
+
/** Structural check for {@link SqlEntityHandleLoweringContribution}: no casts. */
|
|
77
|
+
declare function providesEntityHandleLowering(authoring: unknown): authoring is SqlEntityHandleLoweringContribution;
|
|
78
|
+
/**
|
|
79
|
+
* PSL-side twin of {@link ResolvedEntityHandleRef}: the family interpreter
|
|
80
|
+
* resolves an extension block's descriptor-declared model ref parameters
|
|
81
|
+
* (`{ kind: 'ref', refKind: 'model' }`) to storage table names and annotates
|
|
82
|
+
* the block with this map (keyed by parameter name) before invoking the
|
|
83
|
+
* entity factory. An unresolved required ref is the interpreter's
|
|
84
|
+
* diagnostic; a factory never sees one.
|
|
85
|
+
*/
|
|
86
|
+
type ResolvedPslModelRefs = Readonly<Record<string, {
|
|
87
|
+
readonly tableName: string;
|
|
88
|
+
}>>;
|
|
89
|
+
//#endregion
|
|
90
|
+
export { type EntityHandleLoweringInput, type LoweredPackEntity, type PackEntityHandle, type ResolvedEntityHandleRef, type ResolvedPackEntityHandle, type ResolvedPslModelRefs, type SqlEntityHandleLoweringContribution, providesEntityHandleLowering };
|
|
91
|
+
//# sourceMappingURL=entity-handle-lowering-hook.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity-handle-lowering-hook.d.mts","names":[],"sources":["../src/entity-handle-lowering-hook.ts"],"mappings":";;AAwBA;;;;;;;;;AAEiC;AAUjC;;;;;;;;;;;;UAZiB,gBAAA;EAAA,SACN,UAAA;EAAA,SACA,IAAA,GAAO,QAAQ,CAAC,MAAA;AAAA;AA0BH;AAIxB;;;;;;AAJwB,KAhBZ,uBAAA;EAAA,SAEG,IAAA;EAAA,SACA,WAAA;EAAA,SACA,SAAA;EAAA,SACA,SAAA;AAAA;EAAA,SAGA,IAAA;EAAA,SACA,OAAA;EAAA,SACA,WAAA;EAAA,SACA,SAAA;EAAA,SACA,SAAA;AAAA;EAAA,SAGA,IAAA;EAAA,SACA,SAAA;AAAA;;UAIE,wBAAA;EAAA,SACN,MAAA,EAAQ,gBAAA;EAAA,SACR,IAAA,EAAM,QAAA,CAAS,MAAA,SAAe,uBAAA;AAAA;AAAA,UAGxB,yBAAA;EAOiB;EAAA,SALvB,OAAA,WAAkB,wBAAwB;EAAA,SAC1C,kBAAA;AAAA;;UAIM,iBAAA;EAAA,SACN,WAAA;EAAA,SACA,UAAA;EAAA,SACA,GAAA;EAAA,SACA,MAAA;AAAA;AAAA,UAGM,mCAAA;EAMiE;;;;;EAAhF,kBAAA,CAAmB,KAAA,EAAO,yBAAA,YAAqC,iBAAiB;AAAA;AAIlF;AAAA,iBAAgB,4BAAA,CACd,SAAA,YACC,SAAA,IAAa,mCAAmC;;;;;;;AAAA;AAgBnD;KAAY,oBAAA,GAAuB,QAAQ,CAAC,MAAA;EAAA,SAA0B,SAAA;AAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/entity-handle-lowering-hook.ts
|
|
2
|
+
/** Structural check for {@link SqlEntityHandleLoweringContribution}: no casts. */
|
|
3
|
+
function providesEntityHandleLowering(authoring) {
|
|
4
|
+
if (typeof authoring !== "object" || authoring === null || !("lowerEntityHandles" in authoring)) return false;
|
|
5
|
+
const { lowerEntityHandles } = authoring;
|
|
6
|
+
return typeof lowerEntityHandles === "function";
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { providesEntityHandleLowering };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=entity-handle-lowering-hook.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity-handle-lowering-hook.mjs","names":[],"sources":["../src/entity-handle-lowering-hook.ts"],"sourcesContent":["/**\n * SQL-family extension to the pack authoring contributions: a pack whose\n * `entityTypes` registers entity kinds may implement a batch lowering hook\n * that turns author-declared pack-entity handles (the generic `entities`\n * list on the TS contract input) into `entries` rows.\n *\n * The generic contract build (`contract-ts`) owns the kind-agnostic walk: it\n * groups handles by the pack that registered each `entityKind`, resolves\n * each handle's declared model refs to storage table coordinates using the\n * same model→table maps the relation lowering uses, and calls the owning\n * pack's hook once with all of its claimed handles — batch, so the hook's\n * diagnostics can see sibling handles. Neither the walk nor these types name\n * any specific entity kind.\n *\n * SQL-family concept — the resolved-ref shape is a table coordinate, so the\n * hook lives here beside {@link ../value-set-derivation-hook} instead of on\n * the framework contributions type.\n */\n\n/**\n * An authored pack-entity handle: branded by the `entityKind` its owning\n * pack registered, optionally declaring model refs under `refs` (actual\n * model-handle objects, resolved by the generic walk before lowering).\n */\nexport interface PackEntityHandle {\n readonly entityKind: string;\n readonly refs?: Readonly<Record<string, unknown>>;\n}\n\n/**\n * A declared model ref after the generic walk resolved it: a storage table\n * coordinate for a model of this contract, the coordinate plus `spaceId` for\n * a cross-space (extensionModel) handle, or `unresolved` when the handle\n * does not correspond to any model in the contract. `modelName` is carried\n * for diagnostics where the handle declares one.\n */\nexport type ResolvedEntityHandleRef =\n | {\n readonly kind: 'resolved';\n readonly namespaceId: string;\n readonly tableName: string;\n readonly modelName?: string;\n }\n | {\n readonly kind: 'cross-space';\n readonly spaceId: string;\n readonly namespaceId: string;\n readonly tableName: string;\n readonly modelName?: string;\n }\n | {\n readonly kind: 'unresolved';\n readonly modelName?: string;\n };\n\n/** One claimed handle paired with its resolved declared refs. */\nexport interface ResolvedPackEntityHandle {\n readonly handle: PackEntityHandle;\n readonly refs: Readonly<Record<string, ResolvedEntityHandleRef>>;\n}\n\nexport interface EntityHandleLoweringInput {\n /** Every handle in the `entities` list whose `entityKind` this pack registered, in authored order. */\n readonly handles: readonly ResolvedPackEntityHandle[];\n readonly defaultNamespaceId: string;\n}\n\n/** One lowered entity row: filed into `storage.namespaces[namespaceId].entries[entityKind][key]`. */\nexport interface LoweredPackEntity {\n readonly namespaceId: string;\n readonly entityKind: string;\n readonly key: string;\n readonly entity: unknown;\n}\n\nexport interface SqlEntityHandleLoweringContribution {\n /**\n * Method syntax keeps the declaration bivariant, so a pack's concretely\n * typed implementation stays structurally compatible (the same convention\n * as `SqlValueSetDerivingEntityTypeOutput.deriveValueSet`).\n */\n lowerEntityHandles(input: EntityHandleLoweringInput): readonly LoweredPackEntity[];\n}\n\n/** Structural check for {@link SqlEntityHandleLoweringContribution}: no casts. */\nexport function providesEntityHandleLowering(\n authoring: unknown,\n): authoring is SqlEntityHandleLoweringContribution {\n if (typeof authoring !== 'object' || authoring === null || !('lowerEntityHandles' in authoring)) {\n return false;\n }\n const { lowerEntityHandles } = authoring;\n return typeof lowerEntityHandles === 'function';\n}\n\n/**\n * PSL-side twin of {@link ResolvedEntityHandleRef}: the family interpreter\n * resolves an extension block's descriptor-declared model ref parameters\n * (`{ kind: 'ref', refKind: 'model' }`) to storage table names and annotates\n * the block with this map (keyed by parameter name) before invoking the\n * entity factory. An unresolved required ref is the interpreter's\n * diagnostic; a factory never sees one.\n */\nexport type ResolvedPslModelRefs = Readonly<Record<string, { readonly tableName: string }>>;\n"],"mappings":";;AAqFA,SAAgB,6BACd,WACkD;CAClD,IAAI,OAAO,cAAc,YAAY,cAAc,QAAQ,EAAE,wBAAwB,YACnF,OAAO;CAET,MAAM,EAAE,uBAAuB;CAC/B,OAAO,OAAO,uBAAuB;AACvC"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { t as StorageTable } from "./storage-table-DBpYBmty.mjs";
|
|
2
|
+
import { t as StorageValueSet } from "./storage-value-set-3BKuha5q.mjs";
|
|
3
|
+
import { type } from "arktype";
|
|
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
|
+
"many?": "boolean",
|
|
30
|
+
"typeParams?": "Record<string, unknown>",
|
|
31
|
+
"typeRef?": "string",
|
|
32
|
+
"default?": ColumnDefaultSchema,
|
|
33
|
+
"control?": ControlPolicySchema,
|
|
34
|
+
"valueSet?": StorageValueSetRefSchema
|
|
35
|
+
}).narrow((col, ctx) => {
|
|
36
|
+
if (col.typeParams !== void 0 && col.typeRef !== void 0) return ctx.mustBe("a column with either typeParams or typeRef, not both");
|
|
37
|
+
return true;
|
|
38
|
+
});
|
|
39
|
+
/**
|
|
40
|
+
* Storage value-set entry under `storage.namespaces[id].entries.valueSet[name]`.
|
|
41
|
+
* Carries a `kind: 'valueSet'` discriminator (enumerable, survives JSON) and an
|
|
42
|
+
* ordered `values` array of codec-encoded permitted values.
|
|
43
|
+
*/
|
|
44
|
+
const StorageValueSetSchema = type({
|
|
45
|
+
kind: "'valueSet'",
|
|
46
|
+
values: type("string | number | boolean | null | unknown[] | Record<string, unknown>").array().readonly()
|
|
47
|
+
});
|
|
48
|
+
const PrimaryKeySchema = type.declare().type({
|
|
49
|
+
columns: type.string.array().readonly(),
|
|
50
|
+
"name?": "string"
|
|
51
|
+
});
|
|
52
|
+
const UniqueConstraintSchema = type.declare().type({
|
|
53
|
+
columns: type.string.array().readonly(),
|
|
54
|
+
"name?": "string"
|
|
55
|
+
});
|
|
56
|
+
const IndexSchema = type({
|
|
57
|
+
columns: type.string.array().readonly(),
|
|
58
|
+
"name?": "string",
|
|
59
|
+
"type?": "string",
|
|
60
|
+
"options?": "Record<string, unknown>"
|
|
61
|
+
});
|
|
62
|
+
const ForeignKeyReferenceSchema = type({
|
|
63
|
+
"+": "reject",
|
|
64
|
+
namespaceId: "string",
|
|
65
|
+
tableName: "string",
|
|
66
|
+
columns: type.string.array().readonly(),
|
|
67
|
+
"spaceId?": "string"
|
|
68
|
+
});
|
|
69
|
+
const ForeignKeySourceSchema = type({
|
|
70
|
+
"+": "reject",
|
|
71
|
+
namespaceId: "string",
|
|
72
|
+
tableName: "string",
|
|
73
|
+
columns: type.string.array().readonly()
|
|
74
|
+
});
|
|
75
|
+
const ReferentialActionSchema = type.declare().type("'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault'");
|
|
76
|
+
const ForeignKeySchema = type.declare().type({
|
|
77
|
+
source: ForeignKeySourceSchema,
|
|
78
|
+
target: ForeignKeyReferenceSchema,
|
|
79
|
+
"name?": "string",
|
|
80
|
+
"onDelete?": ReferentialActionSchema,
|
|
81
|
+
"onUpdate?": ReferentialActionSchema
|
|
82
|
+
});
|
|
83
|
+
const CheckConstraintSchema = type({
|
|
84
|
+
"+": "reject",
|
|
85
|
+
name: "string",
|
|
86
|
+
column: "string",
|
|
87
|
+
valueSet: StorageValueSetRefSchema
|
|
88
|
+
});
|
|
89
|
+
const StorageTableSchema = type({
|
|
90
|
+
"+": "reject",
|
|
91
|
+
columns: type({ "[string]": StorageColumnSchema }),
|
|
92
|
+
"primaryKey?": PrimaryKeySchema,
|
|
93
|
+
uniques: UniqueConstraintSchema.array().readonly(),
|
|
94
|
+
indexes: IndexSchema.array().readonly(),
|
|
95
|
+
foreignKeys: ForeignKeySchema.array().readonly(),
|
|
96
|
+
"control?": ControlPolicySchema,
|
|
97
|
+
"checks?": CheckConstraintSchema.array().readonly()
|
|
98
|
+
});
|
|
99
|
+
//#endregion
|
|
100
|
+
//#region src/entity-kinds.ts
|
|
101
|
+
const tableEntityKind = {
|
|
102
|
+
kind: "table",
|
|
103
|
+
schema: StorageTableSchema,
|
|
104
|
+
construct: (input) => new StorageTable(input)
|
|
105
|
+
};
|
|
106
|
+
const valueSetEntityKind = {
|
|
107
|
+
kind: "valueSet",
|
|
108
|
+
schema: StorageValueSetSchema,
|
|
109
|
+
construct: (input) => new StorageValueSet(input)
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* Assembles the `kind → descriptor` registry for SQL namespaces: the built-in
|
|
113
|
+
* `table` and `valueSet` kinds plus any target `packKinds`. This builds the
|
|
114
|
+
* lookup table — it does not touch contract data. `hydrateNamespaceEntities`
|
|
115
|
+
* later consumes this registry to turn a namespace's raw entries into IR
|
|
116
|
+
* instances, and `createSqlContractSchema` derives validation from the same
|
|
117
|
+
* registry. Throws on a duplicate kind.
|
|
118
|
+
*/
|
|
119
|
+
function composeSqlEntityKinds(packKinds = []) {
|
|
120
|
+
const kinds = /* @__PURE__ */ new Map([["table", tableEntityKind], ["valueSet", valueSetEntityKind]]);
|
|
121
|
+
for (const descriptor of packKinds) {
|
|
122
|
+
if (kinds.has(descriptor.kind)) throw new Error(`composeSqlEntityKinds: duplicate entity kind "${descriptor.kind}" — each kind may be registered only once`);
|
|
123
|
+
kinds.set(descriptor.kind, descriptor);
|
|
124
|
+
}
|
|
125
|
+
return kinds;
|
|
126
|
+
}
|
|
127
|
+
//#endregion
|
|
128
|
+
export { ColumnDefaultFunctionSchema as a, ForeignKeyReferenceSchema as c, IndexSchema as d, ReferentialActionSchema as f, CheckConstraintSchema as i, ForeignKeySchema as l, StorageValueSetSchema as m, tableEntityKind as n, ColumnDefaultLiteralSchema as o, StorageTableSchema as p, valueSetEntityKind as r, ColumnDefaultSchema as s, composeSqlEntityKinds as t, ForeignKeySourceSchema as u };
|
|
129
|
+
|
|
130
|
+
//# sourceMappingURL=entity-kinds-CVg6HzG2.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity-kinds-CVg6HzG2.mjs","names":[],"sources":["../src/ir/storage-entry-schemas.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 'many?': '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});\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 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,SAAS;CACT,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;AAED,MAAM,yBAAyB,KAAK,QAA+B,CAAC,CAAC,KAAK;CACxE,SAAS,KAAK,OAAO,MAAM,CAAC,CAAC,SAAS;CACtC,SAAS;AACX,CAAC;AAED,MAAa,cAAc,KAAK;CAC9B,SAAS,KAAK,OAAO,MAAM,CAAC,CAAC,SAAS;CACtC,SAAS;CACT,SAAS;CACT,YAAY;AACd,CAAC;AAED,MAAa,4BAA4B,KAAK;CAC5C,KAAK;CACL,aAAa;CACb,WAAW;CACX,SAAS,KAAK,OAAO,MAAM,CAAC,CAAC,SAAS;CACtC,YAAY;AACd,CAAC;AAED,MAAa,yBAAyB,KAAK;CACzC,KAAK;CACL,aAAa;CACb,WAAW;CACX,SAAS,KAAK,OAAO,MAAM,CAAC,CAAC,SAAS;AACxC,CAAC;AAED,MAAa,0BAA0B,KACpC,QAA2B,CAAC,CAC5B,KAAK,gEAAgE;AAExE,MAAa,mBAAmB,KAAK,QAAyB,CAAC,CAAC,KAAK;CACnE,QAAQ;CACR,QAAQ;CACR,SAAS;CACT,aAAa;CACb,aAAa;AACf,CAAC;AAED,MAAa,wBAAwB,KAAK;CACxC,KAAK;CACL,MAAM;CACN,QAAQ;CACR,UAAU;AACZ,CAAC;AAED,MAAa,qBAAqB,KAAK;CACrC,KAAK;CACL,SAAS,KAAK,EAAE,YAAY,oBAAoB,CAAC;CACjD,eAAe;CACf,SAAS,uBAAuB,MAAM,CAAC,CAAC,SAAS;CACjD,SAAS,YAAY,MAAM,CAAC,CAAC,SAAS;CACtC,aAAa,iBAAiB,MAAM,CAAC,CAAC,SAAS;CAC/C,YAAY;CACZ,WAAW,sBAAsB,MAAM,CAAC,CAAC,SAAS;AACpD,CAAC;;;ACtHD,MAAa,kBAAyE;CACpF,MAAM;CACN,QAAQ;CACR,YAAY,UAAU,IAAI,aAAa,KAAK;AAC9C;AAEA,MAAa,qBAAkF;CAC7F,MAAM;CACN,QAAQ;CACR,YAAY,UAAU,IAAI,gBAAgB,KAAK;AACjD;;;;;;;;;AAUA,SAAgB,sBACd,YAAgD,CAAC,GACH;CAC9C,MAAM,wBAAQ,IAAI,IAAqC,CACrD,CAAC,SAAS,eAAe,GACzB,CAAC,YAAY,kBAAkB,CACjC,CAAC;CACD,KAAK,MAAM,cAAc,WAAW;EAClC,IAAI,MAAM,IAAI,WAAW,IAAI,GAC3B,MAAM,IAAI,MACR,iDAAiD,WAAW,KAAK,0CACnE;EAEF,MAAM,IAAI,WAAW,MAAM,UAAU;CACvC;CACA,OAAO;AACT"}
|
package/dist/entity-kinds.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as StorageTableInput, t as StorageTable } from "./storage-table-CE-Ns6wa.mjs";
|
|
2
|
+
import { n as StorageValueSetInput, t as StorageValueSet } from "./storage-value-set-D-jww77l.mjs";
|
|
2
3
|
import { AnyEntityKindDescriptor, EntityKindDescriptor } from "@prisma-next/framework-components/ir";
|
|
3
4
|
|
|
4
5
|
//#region src/entity-kinds.d.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity-kinds.d.mts","names":[],"sources":["../src/entity-kinds.ts"],"mappings":"
|
|
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;AAN5E;;;;;;;;AAAA,iBAoBgB,qBAAA,CACd,SAAA,YAAoB,uBAAA,KACnB,WAAA,SAAoB,uBAAA"}
|
package/dist/entity-kinds.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as tableEntityKind, r as valueSetEntityKind, t as composeSqlEntityKinds } from "./entity-kinds-
|
|
1
|
+
import { n as tableEntityKind, r as valueSetEntityKind, t as composeSqlEntityKinds } from "./entity-kinds-CVg6HzG2.mjs";
|
|
2
2
|
export { composeSqlEntityKinds, tableEntityKind, valueSetEntityKind };
|
package/dist/factories.d.mts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { i as StorageColumnInput, r as StorageColumn, t as StorageTable } from "./storage-table-CE-Ns6wa.mjs";
|
|
2
|
+
import { t as ForeignKey } from "./foreign-key-DuCoGJCf.mjs";
|
|
3
|
+
import { a as PrimaryKey, r as Index, t as UniqueConstraint } from "./unique-constraint-C0De4sLU.mjs";
|
|
4
|
+
import { T as SqlModelStorage, m as ForeignKeyOptions, w as SqlModelFieldStorage } from "./types-3vOIrnvp.mjs";
|
|
4
5
|
import { ScalarFieldType } from "@prisma-next/contract/types";
|
|
5
6
|
|
|
6
7
|
//#region src/factories.d.ts
|
|
7
|
-
declare function col(nativeType: string, codecId: string, nullable?: boolean
|
|
8
|
+
declare function col(nativeType: string, codecId: string, nullable?: boolean, opts?: {
|
|
9
|
+
readonly many?: boolean;
|
|
10
|
+
}): StorageColumn;
|
|
8
11
|
declare function pk(...columns: readonly string[]): PrimaryKey;
|
|
9
12
|
declare function unique(...columns: readonly string[]): UniqueConstraint;
|
|
10
13
|
declare function index(...columns: readonly string[]): Index;
|
|
11
14
|
declare function fk(srcTableName: string, srcColumns: readonly string[], targetTableName: string, targetColumns: readonly string[], opts?: ForeignKeyOptions & {
|
|
12
|
-
constraint?: boolean;
|
|
13
|
-
index?: boolean;
|
|
14
15
|
namespaceId?: string;
|
|
15
16
|
}): ForeignKey;
|
|
16
17
|
declare function table(columns: Record<string, StorageColumn | StorageColumnInput>, opts?: {
|
package/dist/factories.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factories.d.mts","names":[],"sources":["../src/factories.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"factories.d.mts","names":[],"sources":["../src/factories.ts"],"mappings":";;;;;;;iBAegB,GAAA,CACd,UAAA,UACA,OAAA,UACA,QAAA,YACA,IAAA;EAAA,SAAkB,IAAA;AAAA,IACjB,aAAa;AAAA,iBASA,EAAA,IAAM,OAAA,sBAA6B,UAAU;AAAA,iBAI7C,MAAA,IAAU,OAAA,sBAA6B,gBAAgB;AAAA,iBAIvD,KAAA,IAAS,OAAA,sBAA6B,KAAK;AAAA,iBAI3C,EAAA,CACd,YAAA,UACA,UAAA,qBACA,eAAA,UACA,aAAA,qBACA,IAAA,GAAO,iBAAA;EAAsB,WAAA;AAAA,IAC5B,UAAU;AAAA,iBAWG,KAAA,CACd,OAAA,EAAS,MAAA,SAAe,aAAA,GAAgB,kBAAA,GACxC,IAAA;EACE,EAAA,GAAK,UAAA;EACL,OAAA,YAAmB,gBAAA;EACnB,OAAA,YAAmB,KAAA;EACnB,GAAA,YAAe,UAAA;AAAA,IAEhB,YAAA;AAAA,iBAUa,KAAA,CACd,SAAA,UACA,MAAA,EAAQ,MAAA,SAAe,oBAAA,GACvB,SAAA,GAAW,MAAA,mBACX,WAAA;EAEA,OAAA,EAAS,eAAA;EACT,MAAA,EAAQ,MAAA;IAAA,SAA0B,QAAA;IAAA,SAA4B,IAAA,EAAM,eAAA;EAAA;EACpE,SAAA,EAAW,MAAA;AAAA"}
|
package/dist/factories.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
import { r as applyFkDefaults } from "./types-B-eiQXff.mjs";
|
|
1
|
+
import { a as PrimaryKey, i as Index, n as UniqueConstraint, o as ForeignKey, r as StorageColumn, t as StorageTable } from "./storage-table-DBpYBmty.mjs";
|
|
3
2
|
import { UNBOUND_NAMESPACE_ID } from "@prisma-next/framework-components/ir";
|
|
4
3
|
import { asNamespaceId } from "@prisma-next/contract/types";
|
|
5
4
|
//#region src/factories.ts
|
|
6
|
-
function col(nativeType, codecId, nullable = false) {
|
|
5
|
+
function col(nativeType, codecId, nullable = false, opts) {
|
|
7
6
|
return new StorageColumn({
|
|
8
7
|
nativeType,
|
|
9
8
|
codecId,
|
|
10
|
-
nullable
|
|
9
|
+
nullable,
|
|
10
|
+
...opts?.many !== void 0 && { many: opts.many }
|
|
11
11
|
});
|
|
12
12
|
}
|
|
13
13
|
function pk(...columns) {
|
|
@@ -20,10 +20,6 @@ function index(...columns) {
|
|
|
20
20
|
return new Index({ columns });
|
|
21
21
|
}
|
|
22
22
|
function fk(srcTableName, srcColumns, targetTableName, targetColumns, opts) {
|
|
23
|
-
const defaults = applyFkDefaults({
|
|
24
|
-
constraint: opts?.constraint,
|
|
25
|
-
index: opts?.index
|
|
26
|
-
});
|
|
27
23
|
const namespaceId = asNamespaceId(opts?.namespaceId ?? UNBOUND_NAMESPACE_ID);
|
|
28
24
|
return new ForeignKey({
|
|
29
25
|
source: {
|
|
@@ -38,9 +34,7 @@ function fk(srcTableName, srcColumns, targetTableName, targetColumns, opts) {
|
|
|
38
34
|
},
|
|
39
35
|
...opts?.name !== void 0 && { name: opts.name },
|
|
40
36
|
...opts?.onDelete !== void 0 && { onDelete: opts.onDelete },
|
|
41
|
-
...opts?.onUpdate !== void 0 && { onUpdate: opts.onUpdate }
|
|
42
|
-
constraint: defaults.constraint,
|
|
43
|
-
index: defaults.index
|
|
37
|
+
...opts?.onUpdate !== void 0 && { onUpdate: opts.onUpdate }
|
|
44
38
|
});
|
|
45
39
|
}
|
|
46
40
|
function table(columns, opts) {
|