@prisma-next/sql-contract 0.14.0-dev.80 → 0.14.0-dev.82

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,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"}
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "@prisma-next/sql-contract",
3
- "version": "0.14.0-dev.80",
3
+ "version": "0.14.0-dev.82",
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.80",
10
- "@prisma-next/framework-components": "0.14.0-dev.80",
11
- "@prisma-next/utils": "0.14.0-dev.80",
9
+ "@prisma-next/contract": "0.14.0-dev.82",
10
+ "@prisma-next/framework-components": "0.14.0-dev.82",
11
+ "@prisma-next/utils": "0.14.0-dev.82",
12
12
  "arktype": "^2.2.2"
13
13
  },
14
14
  "devDependencies": {
15
- "@prisma-next/test-utils": "0.14.0-dev.80",
16
- "@prisma-next/tsconfig": "0.14.0-dev.80",
17
- "@prisma-next/tsdown": "0.14.0-dev.80",
15
+ "@prisma-next/test-utils": "0.14.0-dev.82",
16
+ "@prisma-next/tsconfig": "0.14.0-dev.82",
17
+ "@prisma-next/tsdown": "0.14.0-dev.82",
18
18
  "tsdown": "0.22.3",
19
19
  "typescript": "5.9.3",
20
20
  "vitest": "4.1.10"
@@ -34,6 +34,7 @@
34
34
  "exports": {
35
35
  "./canonicalization-hooks": "./dist/canonicalization-hooks.mjs",
36
36
  "./contract-view": "./dist/contract-view.mjs",
37
+ "./entity-handle-lowering-hook": "./dist/entity-handle-lowering-hook.mjs",
37
38
  "./entity-kinds": "./dist/entity-kinds.mjs",
38
39
  "./factories": "./dist/factories.mjs",
39
40
  "./index-type-validation": "./dist/index-type-validation.mjs",
@@ -0,0 +1,104 @@
1
+ /**
2
+ * SQL-family extension to the pack authoring contributions: a pack whose
3
+ * `entityTypes` registers entity kinds may implement a batch lowering hook
4
+ * that turns author-declared pack-entity handles (the generic `entities`
5
+ * list on the TS contract input) into `entries` rows.
6
+ *
7
+ * The generic contract build (`contract-ts`) owns the kind-agnostic walk: it
8
+ * groups handles by the pack that registered each `entityKind`, resolves
9
+ * each handle's declared model refs to storage table coordinates using the
10
+ * same model→table maps the relation lowering uses, and calls the owning
11
+ * pack's hook once with all of its claimed handles — batch, so the hook's
12
+ * diagnostics can see sibling handles. Neither the walk nor these types name
13
+ * any specific entity kind.
14
+ *
15
+ * SQL-family concept — the resolved-ref shape is a table coordinate, so the
16
+ * hook lives here beside {@link ../value-set-derivation-hook} instead of on
17
+ * the framework contributions type.
18
+ */
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
+ export interface PackEntityHandle {
26
+ readonly entityKind: string;
27
+ readonly refs?: Readonly<Record<string, unknown>>;
28
+ }
29
+
30
+ /**
31
+ * A declared model ref after the generic walk resolved it: a storage table
32
+ * coordinate for a model of this contract, the coordinate plus `spaceId` for
33
+ * a cross-space (extensionModel) handle, or `unresolved` when the handle
34
+ * does not correspond to any model in the contract. `modelName` is carried
35
+ * for diagnostics where the handle declares one.
36
+ */
37
+ export type ResolvedEntityHandleRef =
38
+ | {
39
+ readonly kind: 'resolved';
40
+ readonly namespaceId: string;
41
+ readonly tableName: string;
42
+ readonly modelName?: string;
43
+ }
44
+ | {
45
+ readonly kind: 'cross-space';
46
+ readonly spaceId: string;
47
+ readonly namespaceId: string;
48
+ readonly tableName: string;
49
+ readonly modelName?: string;
50
+ }
51
+ | {
52
+ readonly kind: 'unresolved';
53
+ readonly modelName?: string;
54
+ };
55
+
56
+ /** One claimed handle paired with its resolved declared refs. */
57
+ export interface ResolvedPackEntityHandle {
58
+ readonly handle: PackEntityHandle;
59
+ readonly refs: Readonly<Record<string, ResolvedEntityHandleRef>>;
60
+ }
61
+
62
+ export interface EntityHandleLoweringInput {
63
+ /** Every handle in the `entities` list whose `entityKind` this pack registered, in authored order. */
64
+ readonly handles: readonly ResolvedPackEntityHandle[];
65
+ readonly defaultNamespaceId: string;
66
+ }
67
+
68
+ /** One lowered entity row: filed into `storage.namespaces[namespaceId].entries[entityKind][key]`. */
69
+ export interface LoweredPackEntity {
70
+ readonly namespaceId: string;
71
+ readonly entityKind: string;
72
+ readonly key: string;
73
+ readonly entity: unknown;
74
+ }
75
+
76
+ export interface SqlEntityHandleLoweringContribution {
77
+ /**
78
+ * Method syntax keeps the declaration bivariant, so a pack's concretely
79
+ * typed implementation stays structurally compatible (the same convention
80
+ * as `SqlValueSetDerivingEntityTypeOutput.deriveValueSet`).
81
+ */
82
+ lowerEntityHandles(input: EntityHandleLoweringInput): readonly LoweredPackEntity[];
83
+ }
84
+
85
+ /** Structural check for {@link SqlEntityHandleLoweringContribution}: no casts. */
86
+ export function providesEntityHandleLowering(
87
+ authoring: unknown,
88
+ ): authoring is SqlEntityHandleLoweringContribution {
89
+ if (typeof authoring !== 'object' || authoring === null || !('lowerEntityHandles' in authoring)) {
90
+ return false;
91
+ }
92
+ const { lowerEntityHandles } = authoring;
93
+ return typeof lowerEntityHandles === 'function';
94
+ }
95
+
96
+ /**
97
+ * PSL-side twin of {@link ResolvedEntityHandleRef}: the family interpreter
98
+ * resolves an extension block's descriptor-declared model ref parameters
99
+ * (`{ kind: 'ref', refKind: 'model' }`) to storage table names and annotates
100
+ * the block with this map (keyed by parameter name) before invoking the
101
+ * entity factory. An unresolved required ref is the interpreter's
102
+ * diagnostic; a factory never sees one.
103
+ */
104
+ export type ResolvedPslModelRefs = Readonly<Record<string, { readonly tableName: string }>>;
@@ -0,0 +1,10 @@
1
+ export {
2
+ type EntityHandleLoweringInput,
3
+ type LoweredPackEntity,
4
+ type PackEntityHandle,
5
+ providesEntityHandleLowering,
6
+ type ResolvedEntityHandleRef,
7
+ type ResolvedPackEntityHandle,
8
+ type ResolvedPslModelRefs,
9
+ type SqlEntityHandleLoweringContribution,
10
+ } from '../entity-handle-lowering-hook';