@prisma-next/sql-contract 0.14.0-dev.30 → 0.14.0-dev.32

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.
@@ -0,0 +1,61 @@
1
+ import { s as SqlStorage } from "./sql-storage-CUP3mD3c.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"}
@@ -1,8 +1,8 @@
1
1
  import { n as ForeignKeyInput, r as ReferentialAction } from "./foreign-key-BATxB95l.mjs";
2
2
  import { c as UniqueConstraintInput, m as PrimaryKeyInput } from "./storage-value-set-B1Xmb6D2.mjs";
3
3
  import { s as SqlStorage } from "./sql-storage-CUP3mD3c.mjs";
4
- import { Type } from "arktype";
5
4
  import { AnyEntityKindDescriptor } from "@prisma-next/framework-components/ir";
5
+ import { Type } from "arktype";
6
6
  import { Contract } from "@prisma-next/contract/types";
7
7
 
8
8
  //#region src/ir/storage-entry-schemas.d.ts
@@ -1,6 +1,6 @@
1
1
  import { a as ColumnDefaultFunctionSchema, c as ForeignKeyReferenceSchema, d as IndexSchema, f as ReferentialActionSchema, i as CheckConstraintSchema, l as ForeignKeySchema, m as StorageValueSetSchema, o as ColumnDefaultLiteralSchema, p as StorageTableSchema, s as ColumnDefaultSchema, t as composeSqlEntityKinds, u as ForeignKeySourceSchema } from "./entity-kinds-BSGvSPI8.mjs";
2
- import { type } from "arktype";
3
2
  import { isPlainRecord } from "@prisma-next/framework-components/ir";
3
+ import { type } from "arktype";
4
4
  import { CrossReferenceSchema } from "@prisma-next/contract/types";
5
5
  import { ContractValidationError } from "@prisma-next/contract/contract-validation-error";
6
6
  import { validateContractDomain } from "@prisma-next/contract/validate-domain";
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "@prisma-next/sql-contract",
3
- "version": "0.14.0-dev.30",
3
+ "version": "0.14.0-dev.32",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "description": "SQL contract types, validators, and IR factories for Prisma Next",
8
8
  "dependencies": {
9
- "@prisma-next/contract": "0.14.0-dev.30",
10
- "@prisma-next/framework-components": "0.14.0-dev.30",
11
- "@prisma-next/utils": "0.14.0-dev.30",
9
+ "@prisma-next/contract": "0.14.0-dev.32",
10
+ "@prisma-next/framework-components": "0.14.0-dev.32",
11
+ "@prisma-next/utils": "0.14.0-dev.32",
12
12
  "arktype": "^2.2.0"
13
13
  },
14
14
  "devDependencies": {
15
- "@prisma-next/test-utils": "0.14.0-dev.30",
16
- "@prisma-next/tsconfig": "0.14.0-dev.30",
17
- "@prisma-next/tsdown": "0.14.0-dev.30",
15
+ "@prisma-next/test-utils": "0.14.0-dev.32",
16
+ "@prisma-next/tsconfig": "0.14.0-dev.32",
17
+ "@prisma-next/tsdown": "0.14.0-dev.32",
18
18
  "tsdown": "0.22.1",
19
19
  "typescript": "5.9.3",
20
20
  "vitest": "4.1.8"
@@ -33,6 +33,7 @@
33
33
  ],
34
34
  "exports": {
35
35
  "./canonicalization-hooks": "./dist/canonicalization-hooks.mjs",
36
+ "./contract-view": "./dist/contract-view.mjs",
36
37
  "./entity-kinds": "./dist/entity-kinds.mjs",
37
38
  "./factories": "./dist/factories.mjs",
38
39
  "./index-type-validation": "./dist/index-type-validation.mjs",
@@ -0,0 +1,98 @@
1
+ import type { Contract } from '@prisma-next/contract/types';
2
+ import {
3
+ buildNamespacedEntities,
4
+ buildSingleNamespaceView,
5
+ type DefaultNamespaceEntries,
6
+ type NamespacedEntities,
7
+ type SingleNamespaceView,
8
+ } from '@prisma-next/framework-components/ir';
9
+ import type { SqlStorage } from './ir/sql-storage';
10
+
11
+ /**
12
+ * The SQL family's statically-named built-in entity kinds. `table` and
13
+ * `valueSet` are promoted to top-level view accessors; pack-contributed kinds
14
+ * (e.g. `policy`) stay under `.entries`.
15
+ */
16
+ export const SQL_BUILTIN_KINDS = ['table', 'valueSet'] as const;
17
+ export type SqlBuiltinKind = (typeof SQL_BUILTIN_KINDS)[number];
18
+
19
+ type SqlEntries<TContract extends Contract<SqlStorage>> = DefaultNamespaceEntries<
20
+ TContract['storage']
21
+ >;
22
+
23
+ /**
24
+ * The single-namespace SQL accessors: `table`/`valueSet` top-level, pack kinds
25
+ * under `entries`. A target that never emits a built-in kind (SQLite has
26
+ * `sql.enums: false`, so it emits no `valueSet`) resolves that slot to an empty
27
+ * map.
28
+ */
29
+ export type SqlSingleNamespaceAccessors<TContract extends Contract<SqlStorage>> =
30
+ SingleNamespaceView<SqlEntries<TContract>, SqlBuiltinKind>;
31
+
32
+ /**
33
+ * Single-namespace SQL view: the deserialized contract intersected with the
34
+ * by-name accessors, so the value is substitutable for `Contract` while also
35
+ * exposing:
36
+ * - `view.table.<name>` / `view.valueSet.<name>` — built-in kinds, sole
37
+ * namespace unwrapped to the root; pack kinds under `view.entries.<kind>`.
38
+ * - `view.namespace.<id>` — the namespace-keyed entity map (SQLite's sole
39
+ * namespace is `__unbound__`). Mirrors the runtime `db.enums` pattern.
40
+ */
41
+ export type SqlSingleNamespaceView<TContract extends Contract<SqlStorage>> = TContract &
42
+ SqlSingleNamespaceAccessors<TContract> & {
43
+ readonly namespace: NamespacedEntities<TContract['storage'], SqlBuiltinKind>;
44
+ };
45
+
46
+ /**
47
+ * Builds the single-namespace SQL view: unwraps the sole namespace's SQL
48
+ * built-in kinds (`table`, `valueSet`) to the root, attaches the namespace-keyed
49
+ * `namespace` map, and layers both over the deserialized contract. Targets with
50
+ * one default namespace (SQLite) call this directly; Postgres qualifies by
51
+ * schema.
52
+ */
53
+ export function buildSqlSingleNamespaceView<TContract extends Contract<SqlStorage>>(
54
+ contract: TContract,
55
+ ): SqlSingleNamespaceView<TContract> {
56
+ const rootAccessors = buildSingleNamespaceView<SqlSingleNamespaceAccessors<TContract>>(
57
+ contract.storage,
58
+ SQL_BUILTIN_KINDS,
59
+ );
60
+ const namespace = buildNamespacedEntities<
61
+ NamespacedEntities<TContract['storage'], SqlBuiltinKind>
62
+ >(contract.storage, SQL_BUILTIN_KINDS);
63
+ return {
64
+ ...contract,
65
+ ...rootAccessors,
66
+ namespace,
67
+ };
68
+ }
69
+
70
+ /**
71
+ * Schema-qualified SQL view: the deserialized contract intersected with a single
72
+ * `view.namespace.<id>` member — every schema reached by raw id
73
+ * (`view.namespace.public.table.users`), mirroring the runtime `db.enums.<ns>`
74
+ * keying exactly (the default schema keeps its literal `__unbound__` id). There
75
+ * is NO root schema-name promotion, so there is no collision with contract
76
+ * envelope fields — `view.storage` is always the contract's `storage`. Postgres
77
+ * uses this; SQLite (single default namespace) uses
78
+ * {@link buildSqlSingleNamespaceView}.
79
+ */
80
+ export type SqlSchemaQualifiedView<TContract extends Contract<SqlStorage>> = TContract & {
81
+ readonly namespace: NamespacedEntities<TContract['storage'], SqlBuiltinKind>;
82
+ };
83
+
84
+ /**
85
+ * Builds the schema-qualified SQL view: attaches the namespace-keyed `namespace`
86
+ * map over the deserialized contract. Postgres uses this.
87
+ */
88
+ export function buildSqlSchemaQualifiedView<TContract extends Contract<SqlStorage>>(
89
+ contract: TContract,
90
+ ): SqlSchemaQualifiedView<TContract> {
91
+ const namespace = buildNamespacedEntities<
92
+ NamespacedEntities<TContract['storage'], SqlBuiltinKind>
93
+ >(contract.storage, SQL_BUILTIN_KINDS);
94
+ return {
95
+ ...contract,
96
+ namespace,
97
+ };
98
+ }
@@ -0,0 +1,11 @@
1
+ export type {
2
+ SqlBuiltinKind,
3
+ SqlSchemaQualifiedView,
4
+ SqlSingleNamespaceAccessors,
5
+ SqlSingleNamespaceView,
6
+ } from '../contract-view';
7
+ export {
8
+ buildSqlSchemaQualifiedView,
9
+ buildSqlSingleNamespaceView,
10
+ SQL_BUILTIN_KINDS,
11
+ } from '../contract-view';