@prisma-next/sql-contract-psl 0.3.0-dev.71 → 0.3.0
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/README.md +18 -17
- package/dist/default-function-registry-DUMRIhJH.d.mts +71 -0
- package/dist/default-function-registry-DUMRIhJH.d.mts.map +1 -0
- package/dist/index.d.mts +18 -42
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/interpreter-iFCRN9nb.mjs +2343 -0
- package/dist/interpreter-iFCRN9nb.mjs.map +1 -0
- package/dist/provider.d.mts +14 -12
- package/dist/provider.d.mts.map +1 -1
- package/dist/provider.mjs +20 -13
- package/dist/provider.mjs.map +1 -1
- package/package.json +9 -6
- package/src/default-function-registry.ts +52 -300
- package/src/exports/index.ts +10 -2
- package/src/interpreter.ts +1074 -1326
- package/src/provider.ts +44 -25
- package/src/psl-attribute-parsing.ts +303 -0
- package/src/psl-authoring-arguments.ts +454 -0
- package/src/psl-column-resolution.ts +600 -0
- package/src/psl-field-resolution.ts +335 -0
- package/src/psl-relation-resolution.ts +371 -0
- package/dist/interpreter-IXr5c7s7.mjs +0 -1376
- package/dist/interpreter-IXr5c7s7.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -1,26 +1,29 @@
|
|
|
1
1
|
# @prisma-next/sql-contract-psl
|
|
2
2
|
|
|
3
|
-
PSL-first SQL contract interpretation
|
|
3
|
+
PSL-first SQL contract interpretation for Prisma Next.
|
|
4
4
|
|
|
5
5
|
## Overview
|
|
6
6
|
|
|
7
7
|
`@prisma-next/sql-contract-psl` provides two entrypoints:
|
|
8
8
|
|
|
9
|
-
- **Pure interpreter** (`@prisma-next/sql-contract-psl`): parsed PSL document -> SQL `
|
|
9
|
+
- **Pure interpreter** (`@prisma-next/sql-contract-psl`): parsed PSL document -> SQL `Contract`
|
|
10
10
|
- **Provider helper** (`@prisma-next/sql-contract-psl/provider`): read file -> parse -> interpret -> `ContractConfig`
|
|
11
11
|
|
|
12
12
|
This keeps core/CLI source-agnostic while giving PSL-first SQL users a one-line config helper.
|
|
13
13
|
|
|
14
14
|
## Responsibilities
|
|
15
15
|
|
|
16
|
-
- Interpret `ParsePslDocumentResult` into SQL `
|
|
16
|
+
- Interpret `ParsePslDocumentResult` into SQL `Contract`
|
|
17
17
|
- Interpret generic PSL attributes into SQL contract semantics (`@id`, `@unique`, `@default`, `@relation`, `@map`, `@@map`)
|
|
18
|
-
- Lower
|
|
19
|
-
-
|
|
18
|
+
- Lower shared constructor expressions in both `types {}` blocks and inline field positions (for example `ShortName = sql.String(length: 35)` and `embedding pgvector.Vector(length: 1536)?`)
|
|
19
|
+
- Lower supported default functions through composed registry inputs
|
|
20
|
+
- Support selected Postgres native-type attributes on named types for brownfield round-trips (`@db.Char`, `@db.VarChar`, `@db.Numeric`, `@db.Uuid`, `@db.SmallInt`, `@db.Real`, `@db.Timestamp`, `@db.Timestamptz`, `@db.Date`, `@db.Time`, `@db.Timetz`, `@db.Json`)
|
|
20
21
|
- Map PSL relation action tokens to SQL contract referential actions and emit diagnostics for unsupported values
|
|
21
|
-
- Emit deterministic relation metadata in `models.<Model>.relations`
|
|
22
|
-
- Enforce extension composition for
|
|
23
|
-
-
|
|
22
|
+
- Emit deterministic relation metadata in `models.<Model>.relations`
|
|
23
|
+
- Enforce extension composition for namespaced constructor expressions and emit strict diagnostics for unsupported namespaced attributes
|
|
24
|
+
- Validate generator applicability by declared `codecId` support on composed generator descriptors
|
|
25
|
+
- Consume target-bound scalar descriptors, shared authoring contributions, and mutation-default registries assembled by composition layers
|
|
26
|
+
- Compose provider flow for SQL PSL-first config (`read -> parse -> interpret`) without local registry assembly
|
|
24
27
|
- Preserve parser diagnostics and add interpreter diagnostics with stable codes
|
|
25
28
|
- Return `notOk` with structured diagnostics for unsupported constructs
|
|
26
29
|
- Keep interpretation deterministic for equivalent AST inputs
|
|
@@ -39,7 +42,7 @@ The **pure interpreter entrypoint** specifically excludes:
|
|
|
39
42
|
- Artifact emission (`contract.json`, `contract.d.ts`) and hashing
|
|
40
43
|
- CLI or ControlClient orchestration
|
|
41
44
|
|
|
42
|
-
Current scope is SQL/Postgres-first:
|
|
45
|
+
Current scope is SQL/Postgres-first: callers pass Postgres-oriented scalar descriptors and target context in v1.
|
|
43
46
|
|
|
44
47
|
Unsupported PSL constructs in v1 (strict errors):
|
|
45
48
|
|
|
@@ -53,7 +56,7 @@ Unsupported PSL constructs in v1 (strict errors):
|
|
|
53
56
|
- **Implicit Prisma ORM many-to-many remains unsupported** (list navigation on both sides without explicit join model)
|
|
54
57
|
- Represent many-to-many with an explicit join model (two foreign keys)
|
|
55
58
|
|
|
56
|
-
Supported `@default(...)` surface in v1:
|
|
59
|
+
Supported `@default(...)` surface in v1 when composed contributors provide handlers:
|
|
57
60
|
|
|
58
61
|
- Storage defaults: `autoincrement()`, `now()`, literals, `dbgenerated("...")`
|
|
59
62
|
- Execution defaults: `uuid()`, `uuid(4)`, `uuid(7)`, `cuid(2)`, `ulid()`, `nanoid()`, `nanoid(<2-255>)`
|
|
@@ -63,23 +66,21 @@ Supported `@default(...)` surface in v1:
|
|
|
63
66
|
## Public API
|
|
64
67
|
|
|
65
68
|
- `@prisma-next/sql-contract-psl`
|
|
66
|
-
- `
|
|
69
|
+
- `interpretPslDocumentToSqlContract({ document, target, scalarTypeDescriptors, authoringContributions?, controlMutationDefaults?, composedExtensionPacks? })`
|
|
67
70
|
- `@prisma-next/sql-contract-psl/provider`
|
|
68
|
-
- `prismaContract(schemaPath, { output?, target?, composedExtensionPacks? })`
|
|
69
|
-
-
|
|
70
|
-
availability checks (for example `['pgvector']`); plan to evolve to richer composed pack
|
|
71
|
-
metadata/manifest inputs before broadening namespaced-attribute validation.
|
|
71
|
+
- `prismaContract(schemaPath, { output?, target, scalarTypeDescriptors, authoringContributions?, controlMutationDefaults?, composedExtensionPacks? })`
|
|
72
|
+
- Provider input is fully preassembled by composition layers (for example `@prisma-next/family-sql/control` helpers).
|
|
72
73
|
|
|
73
74
|
## Dependencies
|
|
74
75
|
|
|
75
76
|
- **Depends on**
|
|
76
77
|
- `@prisma-next/psl-parser` for parser + parser result types
|
|
77
78
|
- `@prisma-next/sql-contract-ts` for SQL authoring builder composition
|
|
78
|
-
- `@prisma-next/core-control-plane` for contract source diagnostics types
|
|
79
79
|
- `pathe` for provider path resolution
|
|
80
80
|
- `@prisma-next/contract` and `@prisma-next/utils`
|
|
81
81
|
- **Used by**
|
|
82
82
|
- PSL contract providers configured via `contract.source`
|
|
83
|
+
- Composition helpers such as `@prisma-next/family-sql/control` that assemble provider inputs
|
|
83
84
|
|
|
84
85
|
## Architecture
|
|
85
86
|
|
|
@@ -90,7 +91,7 @@ flowchart LR
|
|
|
90
91
|
fsRead --> parser[@prisma-next/psl-parser]
|
|
91
92
|
parser --> parsed[ParsePslDocumentResult]
|
|
92
93
|
parsed --> interpreter[@prisma-next/sql-contract-psl]
|
|
93
|
-
interpreter --> irResult[
|
|
94
|
+
interpreter --> irResult[Result_Contract_Diagnostics]
|
|
94
95
|
irResult --> emit[Framework emit pipeline]
|
|
95
96
|
```
|
|
96
97
|
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { PslSpan } from "@prisma-next/psl-parser";
|
|
2
|
+
import { ContractSourceDiagnostic } from "@prisma-next/config/config-types";
|
|
3
|
+
import { ColumnDefault, ExecutionMutationDefaultValue } from "@prisma-next/contract/types";
|
|
4
|
+
|
|
5
|
+
//#region src/default-function-registry.d.ts
|
|
6
|
+
interface DefaultFunctionArgument {
|
|
7
|
+
readonly raw: string;
|
|
8
|
+
readonly span: PslSpan;
|
|
9
|
+
}
|
|
10
|
+
interface ParsedDefaultFunctionCall {
|
|
11
|
+
readonly name: string;
|
|
12
|
+
readonly raw: string;
|
|
13
|
+
readonly args: readonly DefaultFunctionArgument[];
|
|
14
|
+
readonly span: PslSpan;
|
|
15
|
+
}
|
|
16
|
+
interface DefaultFunctionLoweringContext {
|
|
17
|
+
readonly sourceId: string;
|
|
18
|
+
readonly modelName: string;
|
|
19
|
+
readonly fieldName: string;
|
|
20
|
+
readonly columnCodecId?: string;
|
|
21
|
+
}
|
|
22
|
+
type LoweredDefaultValue = {
|
|
23
|
+
readonly kind: 'storage';
|
|
24
|
+
readonly defaultValue: ColumnDefault;
|
|
25
|
+
} | {
|
|
26
|
+
readonly kind: 'execution';
|
|
27
|
+
readonly generated: ExecutionMutationDefaultValue;
|
|
28
|
+
};
|
|
29
|
+
type LoweredDefaultResult = {
|
|
30
|
+
readonly ok: true;
|
|
31
|
+
readonly value: LoweredDefaultValue;
|
|
32
|
+
} | {
|
|
33
|
+
readonly ok: false;
|
|
34
|
+
readonly diagnostic: ContractSourceDiagnostic;
|
|
35
|
+
};
|
|
36
|
+
type DefaultFunctionLoweringHandler = (input: {
|
|
37
|
+
readonly call: ParsedDefaultFunctionCall;
|
|
38
|
+
readonly context: DefaultFunctionLoweringContext;
|
|
39
|
+
}) => LoweredDefaultResult;
|
|
40
|
+
interface DefaultFunctionRegistryEntry {
|
|
41
|
+
readonly lower: DefaultFunctionLoweringHandler;
|
|
42
|
+
readonly usageSignatures?: readonly string[];
|
|
43
|
+
}
|
|
44
|
+
type DefaultFunctionRegistry = ReadonlyMap<string, DefaultFunctionRegistryEntry>;
|
|
45
|
+
interface MutationDefaultGeneratorDescriptor {
|
|
46
|
+
readonly id: string;
|
|
47
|
+
readonly applicableCodecIds: readonly string[];
|
|
48
|
+
readonly resolveGeneratedColumnDescriptor?: (input: {
|
|
49
|
+
readonly generated: ExecutionMutationDefaultValue;
|
|
50
|
+
}) => {
|
|
51
|
+
readonly codecId: string;
|
|
52
|
+
readonly nativeType: string;
|
|
53
|
+
readonly typeRef?: string;
|
|
54
|
+
readonly typeParams?: Record<string, unknown>;
|
|
55
|
+
} | undefined;
|
|
56
|
+
}
|
|
57
|
+
interface ControlMutationDefaultEntry {
|
|
58
|
+
readonly lower: (input: {
|
|
59
|
+
readonly call: ParsedDefaultFunctionCall;
|
|
60
|
+
readonly context: DefaultFunctionLoweringContext;
|
|
61
|
+
}) => LoweredDefaultResult;
|
|
62
|
+
readonly usageSignatures?: readonly string[];
|
|
63
|
+
}
|
|
64
|
+
type ControlMutationDefaultRegistry = ReadonlyMap<string, ControlMutationDefaultEntry>;
|
|
65
|
+
interface ControlMutationDefaults {
|
|
66
|
+
readonly defaultFunctionRegistry: ControlMutationDefaultRegistry;
|
|
67
|
+
readonly generatorDescriptors: readonly MutationDefaultGeneratorDescriptor[];
|
|
68
|
+
}
|
|
69
|
+
//#endregion
|
|
70
|
+
export { DefaultFunctionRegistryEntry as a, DefaultFunctionRegistry as i, DefaultFunctionLoweringContext as n, MutationDefaultGeneratorDescriptor as o, DefaultFunctionLoweringHandler as r, ControlMutationDefaults as t };
|
|
71
|
+
//# sourceMappingURL=default-function-registry-DUMRIhJH.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default-function-registry-DUMRIhJH.d.mts","names":[],"sources":["../src/default-function-registry.ts"],"sourcesContent":[],"mappings":";;;;;UAIU,uBAAA;;EAAA,SAAA,IAAA,EAEO,OAFP;AAKV;AAOiB,UAPA,yBAAA,CAO8B;EAOnC,SAAA,IAAA,EAAA,MAAA;EAIA,SAAA,GAAA,EAAA,MAAA;EAIA,SAAA,IAAA,EAAA,SAnBc,uBAmBgB,EAAA;EACzB,SAAA,IAAA,EAnBA,OAmBA;;AAEX,UAlBW,8BAAA,CAkBX;EAAoB,SAAA,QAAA,EAAA,MAAA;EAET,SAAA,SAAA,EAAA,MAAA;EAKL,SAAA,SAAA,EAAA,MAAuB;EAElB,SAAA,aAAA,CAAA,EAAA,MAAA;AAejB;AAEmB,KArCP,mBAAA,GAqCO;EACG,SAAA,IAAA,EAAA,SAAA;EACd,SAAA,YAAA,EAtC+C,aAsC/C;CAAoB,GAAA;EAIhB,SAAA,IAAA,EAAA,WAAA;EAEK,SAAA,SAAA,EA3CqC,6BA4ClB;;KA1CxB,oBAAA;;kBAC6B;;;uBACM;;KAEnC,8BAAA;iBACK;oBACG;MACd;UAEW,4BAAA;kBACC;;;KAIN,uBAAA,GAA0B,oBAAoB;UAEzC,kCAAA;;;;wBAIO;;;;;0BAMM;;;UAKb,2BAAA;;mBAEE;sBACG;QACd;;;KAII,8BAAA,GAAiC,oBAAoB;UAEhD,uBAAA;oCACmB;0CACM"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,54 +1,30 @@
|
|
|
1
|
+
import { a as DefaultFunctionRegistryEntry, i as DefaultFunctionRegistry, n as DefaultFunctionLoweringContext, o as MutationDefaultGeneratorDescriptor, r as DefaultFunctionLoweringHandler, t as ControlMutationDefaults } from "./default-function-registry-DUMRIhJH.mjs";
|
|
2
|
+
import { AuthoringContributions } from "@prisma-next/framework-components/authoring";
|
|
1
3
|
import { Result } from "@prisma-next/utils/result";
|
|
2
4
|
import { ParsePslDocumentResult, PslSpan } from "@prisma-next/psl-parser";
|
|
3
5
|
import { ContractSourceDiagnostic, ContractSourceDiagnostics } from "@prisma-next/config/config-types";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { ColumnDefault, ExecutionMutationDefaultValue } from "@prisma-next/contract/types";
|
|
6
|
+
import { ColumnDefault, Contract, ExecutionMutationDefaultValue } from "@prisma-next/contract/types";
|
|
7
|
+
import { ExtensionPackRef, TargetPackRef } from "@prisma-next/framework-components/components";
|
|
7
8
|
|
|
8
|
-
//#region src/
|
|
9
|
-
|
|
10
|
-
readonly
|
|
11
|
-
readonly
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
readonly name: string;
|
|
15
|
-
readonly raw: string;
|
|
16
|
-
readonly args: readonly DefaultFunctionArgument[];
|
|
17
|
-
readonly span: PslSpan;
|
|
18
|
-
}
|
|
19
|
-
interface DefaultFunctionLoweringContext {
|
|
20
|
-
readonly sourceId: string;
|
|
21
|
-
readonly modelName: string;
|
|
22
|
-
readonly fieldName: string;
|
|
23
|
-
}
|
|
24
|
-
type LoweredDefaultValue = {
|
|
25
|
-
readonly kind: 'storage';
|
|
26
|
-
readonly defaultValue: ColumnDefault;
|
|
27
|
-
} | {
|
|
28
|
-
readonly kind: 'execution';
|
|
29
|
-
readonly generated: ExecutionMutationDefaultValue;
|
|
30
|
-
};
|
|
31
|
-
type LoweredDefaultResult = {
|
|
32
|
-
readonly ok: true;
|
|
33
|
-
readonly value: LoweredDefaultValue;
|
|
34
|
-
} | {
|
|
35
|
-
readonly ok: false;
|
|
36
|
-
readonly diagnostic: ContractSourceDiagnostic;
|
|
9
|
+
//#region src/psl-column-resolution.d.ts
|
|
10
|
+
type ColumnDescriptor = {
|
|
11
|
+
readonly codecId: string;
|
|
12
|
+
readonly nativeType: string;
|
|
13
|
+
readonly typeRef?: string;
|
|
14
|
+
readonly typeParams?: Record<string, unknown>;
|
|
37
15
|
};
|
|
38
|
-
type DefaultFunctionLoweringHandler = (input: {
|
|
39
|
-
readonly call: ParsedDefaultFunctionCall;
|
|
40
|
-
readonly context: DefaultFunctionLoweringContext;
|
|
41
|
-
}) => LoweredDefaultResult;
|
|
42
|
-
type DefaultFunctionRegistry = ReadonlyMap<string, DefaultFunctionLoweringHandler>;
|
|
43
16
|
//#endregion
|
|
44
17
|
//#region src/interpreter.d.ts
|
|
45
|
-
interface
|
|
18
|
+
interface InterpretPslDocumentToSqlContractInput {
|
|
46
19
|
readonly document: ParsePslDocumentResult;
|
|
47
|
-
readonly target
|
|
20
|
+
readonly target: TargetPackRef<'sql', 'postgres'>;
|
|
21
|
+
readonly scalarTypeDescriptors: ReadonlyMap<string, ColumnDescriptor>;
|
|
48
22
|
readonly composedExtensionPacks?: readonly string[];
|
|
49
|
-
readonly
|
|
23
|
+
readonly composedExtensionPackRefs?: readonly ExtensionPackRef<'sql', 'postgres'>[];
|
|
24
|
+
readonly controlMutationDefaults?: ControlMutationDefaults;
|
|
25
|
+
readonly authoringContributions?: AuthoringContributions;
|
|
50
26
|
}
|
|
51
|
-
declare function
|
|
27
|
+
declare function interpretPslDocumentToSqlContract(input: InterpretPslDocumentToSqlContractInput): Result<Contract, ContractSourceDiagnostics>;
|
|
52
28
|
//#endregion
|
|
53
|
-
export { type
|
|
29
|
+
export { type ControlMutationDefaults, type DefaultFunctionLoweringContext, type DefaultFunctionLoweringHandler, type DefaultFunctionRegistry, type DefaultFunctionRegistryEntry, type InterpretPslDocumentToSqlContractInput, type MutationDefaultGeneratorDescriptor, interpretPslDocumentToSqlContract };
|
|
54
30
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/psl-column-resolution.ts","../src/interpreter.ts"],"sourcesContent":[],"mappings":";;;;;;;;;KAmCY,gBAAA;;;;EAAA,SAAA,UAAgB,CAAA,EAIJ,MAJI,CAAA,MAIJ,EAAA,OAAM,CAAA;;;;UCsCb,sCAAA;ED1CL,SAAA,QAAA,EC2CS,sBDvCS;mBCwCX;kCACe,oBAAoB;;EAHrC,SAAA,yBAAA,CAAA,EAAA,SAK+B,gBALO,CAAA,KAAA,EAAA,UAAA,CAAA,EAAA;EAClC,SAAA,uBAAA,CAAA,EAKgB,uBALhB;EACF,SAAA,sBAAA,CAAA,EAKiB,sBALjB;;AACe,iBAu/BlB,iCAAA,CAv/BkB,KAAA,EAw/BzB,sCAx/ByB,CAAA,EAy/B/B,MAz/B+B,CAy/BxB,QAz/BwB,EAy/Bd,yBAz/Bc,CAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { t as
|
|
1
|
+
import { t as interpretPslDocumentToSqlContract } from "./interpreter-iFCRN9nb.mjs";
|
|
2
2
|
|
|
3
|
-
export {
|
|
3
|
+
export { interpretPslDocumentToSqlContract };
|