@prisma-next/psl-parser 0.14.0-dev.55 → 0.14.0-dev.57
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/index.d.mts +3 -123
- package/dist/index.d.mts.map +1 -1
- package/dist/interpret.d.mts +29 -0
- package/dist/interpret.d.mts.map +1 -0
- package/dist/interpret.mjs +9 -0
- package/dist/interpret.mjs.map +1 -0
- package/dist/symbol-table-C-AH04Ug.d.mts +127 -0
- package/dist/symbol-table-C-AH04Ug.d.mts.map +1 -0
- package/package.json +7 -5
- package/src/exports/interpret.ts +2 -0
- package/src/interpret.ts +40 -0
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { P as AstNode, T as ExpressionAst, b as FieldAttributeAst, et as SourceFile, x as ModelAttributeAst } from "./parse-BazJr7Ye.mjs";
|
|
2
|
+
import { S as readResolvedConstructorCall, _ as keywordPslSpan, a as ModelSymbol, b as readResolvedAttribute, c as ScalarSymbol, d as TopLevelScope, f as TypeAliasSymbol, g as ResolvedTypeConstructorCall, h as ResolvedAttributeArg, i as FieldSymbol, l as SymbolTable, m as ResolvedAttribute, n as BuildSymbolTableOptions, o as NamespaceSymbol, p as buildSymbolTable, r as CompositeTypeSymbol, s as ResolvedNamedTypeBinding, t as BlockSymbol, u as SymbolTableResult, v as nodePslSpan, x as readResolvedAttributes, y as rangeToPslSpan } from "./symbol-table-C-AH04Ug.mjs";
|
|
3
|
+
import { PslAttribute, PslAttribute as PslAttribute$1, PslAttributeArgument, PslAttributeNamedArgument, PslAttributePositionalArgument, PslAttributeTarget, PslCompositeType, PslDefaultFunctionValue, PslDefaultLiteralValue, PslDefaultValue, PslDiagnostic, PslDiagnostic as PslDiagnostic$1, PslDiagnosticCode, PslDiagnosticCode as PslDiagnosticCode$1, PslDocumentAst, PslExtensionBlock, PslExtensionBlockAttribute, PslExtensionBlockAttributeArg, PslExtensionBlockParamBare, PslExtensionBlockParamList, PslExtensionBlockParamOption, PslExtensionBlockParamRef, PslExtensionBlockParamScalarValue, PslExtensionBlockParamValue, PslField, PslFieldAttribute, PslModel, PslModelAttribute, PslNamedTypeDeclaration, PslNamespace, PslPosition, PslSpan, PslTypeConstructorCall, PslTypesBlock, flatPslModels, namespacePslExtensionBlocks } from "@prisma-next/framework-components/psl-ast";
|
|
3
4
|
import { Result } from "@prisma-next/utils/result";
|
|
4
5
|
import { AuthoringPslBlockDescriptor, AuthoringPslBlockDescriptorNamespace } from "@prisma-next/framework-components/authoring";
|
|
5
6
|
import { Simplify, UnionToIntersection } from "@prisma-next/utils/types";
|
|
@@ -9,127 +10,6 @@ import { CodecLookup } from "@prisma-next/framework-components/codec";
|
|
|
9
10
|
declare function getPositionalArgument(attribute: PslAttribute$1, index?: number): string | undefined;
|
|
10
11
|
declare function parseQuotedStringLiteral(value: string): string | undefined;
|
|
11
12
|
//#endregion
|
|
12
|
-
//#region src/resolve.d.ts
|
|
13
|
-
interface ResolvedAttributeArg {
|
|
14
|
-
readonly kind: 'positional' | 'named';
|
|
15
|
-
readonly name?: string;
|
|
16
|
-
readonly value: string;
|
|
17
|
-
readonly expression?: ExpressionAst;
|
|
18
|
-
readonly span: PslSpan$1;
|
|
19
|
-
}
|
|
20
|
-
interface ResolvedAttribute {
|
|
21
|
-
readonly name: string;
|
|
22
|
-
readonly args: readonly ResolvedAttributeArg[];
|
|
23
|
-
readonly span: PslSpan$1;
|
|
24
|
-
}
|
|
25
|
-
interface ResolvedTypeConstructorCall {
|
|
26
|
-
readonly path: readonly string[];
|
|
27
|
-
readonly args: readonly ResolvedAttributeArg[];
|
|
28
|
-
readonly span: PslSpan$1;
|
|
29
|
-
}
|
|
30
|
-
declare function readResolvedAttribute(attribute: FieldAttributeAst | ModelAttributeAst, sourceFile: SourceFile): ResolvedAttribute;
|
|
31
|
-
declare function readResolvedAttributes(attributes: Iterable<FieldAttributeAst | ModelAttributeAst>, sourceFile: SourceFile): readonly ResolvedAttribute[];
|
|
32
|
-
declare function readResolvedConstructorCall(annotation: TypeAnnotationAst | undefined, sourceFile: SourceFile): ResolvedTypeConstructorCall | undefined;
|
|
33
|
-
declare function nodePslSpan(node: SyntaxNode, sourceFile: SourceFile): PslSpan$1;
|
|
34
|
-
/** Unsupported-top-level-block diagnostics are anchored to the keyword token. */
|
|
35
|
-
declare function keywordPslSpan(node: SyntaxNode, keyword: string, sourceFile: SourceFile): PslSpan$1;
|
|
36
|
-
declare function rangeToPslSpan(range: Range, sourceFile: SourceFile): PslSpan$1;
|
|
37
|
-
//#endregion
|
|
38
|
-
//#region src/symbol-table.d.ts
|
|
39
|
-
interface SymbolTable {
|
|
40
|
-
readonly topLevel: TopLevelScope;
|
|
41
|
-
}
|
|
42
|
-
interface TopLevelScope {
|
|
43
|
-
readonly namespaces: Record<string, NamespaceSymbol>;
|
|
44
|
-
readonly scalars: Record<string, ScalarSymbol>;
|
|
45
|
-
readonly typeAliases: Record<string, TypeAliasSymbol>;
|
|
46
|
-
readonly blocks: Record<string, BlockSymbol>;
|
|
47
|
-
readonly models: Record<string, ModelSymbol>;
|
|
48
|
-
readonly compositeTypes: Record<string, CompositeTypeSymbol>;
|
|
49
|
-
}
|
|
50
|
-
interface NamespaceSymbol {
|
|
51
|
-
readonly kind: 'namespace';
|
|
52
|
-
readonly name: string;
|
|
53
|
-
readonly node: NamespaceDeclarationAst;
|
|
54
|
-
readonly span: PslSpan$1;
|
|
55
|
-
readonly models: Record<string, ModelSymbol>;
|
|
56
|
-
readonly compositeTypes: Record<string, CompositeTypeSymbol>;
|
|
57
|
-
readonly blocks: Record<string, BlockSymbol>;
|
|
58
|
-
}
|
|
59
|
-
interface ModelSymbol {
|
|
60
|
-
readonly kind: 'model';
|
|
61
|
-
readonly name: string;
|
|
62
|
-
readonly node: ModelDeclarationAst;
|
|
63
|
-
readonly span: PslSpan$1;
|
|
64
|
-
readonly fields: Record<string, FieldSymbol>;
|
|
65
|
-
readonly attributes: readonly ResolvedAttribute[];
|
|
66
|
-
}
|
|
67
|
-
interface CompositeTypeSymbol {
|
|
68
|
-
readonly kind: 'compositeType';
|
|
69
|
-
readonly name: string;
|
|
70
|
-
readonly node: CompositeTypeDeclarationAst;
|
|
71
|
-
readonly span: PslSpan$1;
|
|
72
|
-
readonly fields: Record<string, FieldSymbol>;
|
|
73
|
-
readonly attributes: readonly ResolvedAttribute[];
|
|
74
|
-
}
|
|
75
|
-
interface BlockSymbol {
|
|
76
|
-
readonly kind: 'block';
|
|
77
|
-
readonly name: string;
|
|
78
|
-
readonly keyword: string;
|
|
79
|
-
readonly node: GenericBlockDeclarationAst;
|
|
80
|
-
readonly span: PslSpan$1;
|
|
81
|
-
/** Resolved once so consumers do not independently classify block parameters. */
|
|
82
|
-
readonly block: PslExtensionBlock$1;
|
|
83
|
-
}
|
|
84
|
-
interface ResolvedNamedTypeBinding {
|
|
85
|
-
readonly baseType?: string;
|
|
86
|
-
readonly typeConstructor?: ResolvedTypeConstructorCall;
|
|
87
|
-
readonly isConstructor: boolean;
|
|
88
|
-
readonly attributes: readonly ResolvedAttribute[];
|
|
89
|
-
}
|
|
90
|
-
interface ScalarSymbol extends ResolvedNamedTypeBinding {
|
|
91
|
-
readonly kind: 'scalar';
|
|
92
|
-
readonly name: string;
|
|
93
|
-
readonly node: NamedTypeDeclarationAst;
|
|
94
|
-
readonly span: PslSpan$1;
|
|
95
|
-
}
|
|
96
|
-
interface TypeAliasSymbol extends ResolvedNamedTypeBinding {
|
|
97
|
-
readonly kind: 'typeAlias';
|
|
98
|
-
readonly name: string;
|
|
99
|
-
readonly node: NamedTypeDeclarationAst;
|
|
100
|
-
readonly span: PslSpan$1;
|
|
101
|
-
}
|
|
102
|
-
interface FieldSymbol {
|
|
103
|
-
readonly kind: 'field';
|
|
104
|
-
readonly name: string;
|
|
105
|
-
readonly node: FieldDeclarationAst;
|
|
106
|
-
readonly span: PslSpan$1;
|
|
107
|
-
readonly typeName: string;
|
|
108
|
-
readonly typeNamespaceId?: string;
|
|
109
|
-
readonly typeContractSpaceId?: string;
|
|
110
|
-
readonly optional: boolean;
|
|
111
|
-
readonly list: boolean;
|
|
112
|
-
readonly typeConstructor?: ResolvedTypeConstructorCall;
|
|
113
|
-
readonly attributes: readonly ResolvedAttribute[];
|
|
114
|
-
/** Prevents cascading unsupported-type diagnostics after invalid qualification. */
|
|
115
|
-
readonly malformedType?: boolean;
|
|
116
|
-
}
|
|
117
|
-
interface BuildSymbolTableOptions {
|
|
118
|
-
readonly document: DocumentAst;
|
|
119
|
-
readonly sourceFile: SourceFile;
|
|
120
|
-
readonly scalarTypes: readonly string[];
|
|
121
|
-
readonly pslBlockDescriptors: AuthoringPslBlockDescriptorNamespace;
|
|
122
|
-
}
|
|
123
|
-
interface SymbolTableResult {
|
|
124
|
-
readonly table: SymbolTable;
|
|
125
|
-
readonly diagnostics: readonly ParseDiagnostic[];
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Owns duplicate-declaration detection for all PSL scopes; downstream consumers
|
|
129
|
-
* should consume first-wins symbols rather than re-emitting duplicate diagnostics.
|
|
130
|
-
*/
|
|
131
|
-
declare function buildSymbolTable(options: BuildSymbolTableOptions): SymbolTableResult;
|
|
132
|
-
//#endregion
|
|
133
13
|
//#region src/attribute-spec/types.d.ts
|
|
134
14
|
type AttributeLevel = 'field' | 'model' | 'block';
|
|
135
15
|
interface ArgType<T> {
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/attribute-helpers.ts","../src/
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/attribute-helpers.ts","../src/attribute-spec/types.ts","../src/attribute-spec/combinators/bool.ts","../src/attribute-spec/combinators/diagnostic.ts","../src/attribute-spec/combinators/entity-ref.ts","../src/attribute-spec/combinators/field-ref.ts","../src/attribute-spec/combinators/identifier.ts","../src/attribute-spec/combinators/int.ts","../src/attribute-spec/combinators/list.ts","../src/attribute-spec/combinators/one-of.ts","../src/attribute-spec/combinators/record.ts","../src/attribute-spec/combinators/str.ts","../src/attribute-spec/field-attribute.ts","../src/attribute-spec/interpret.ts","../src/attribute-spec/model-attribute.ts","../src/attribute-spec/optional.ts","../src/extension-block.ts"],"mappings":";;;;;;;;;iBAEgB,qBAAA,CAAsB,SAAA,EAAW,cAAY,EAAE,KAAA;AAAA,iBAK/C,wBAAA,CAAyB,KAAa;;;KCA1C,cAAA;AAAA,UAEK,OAAA;EAAA,SACN,IAAA;EAAA,SACA,KAAA;EAAA,SAEA,IAAA,GAAO,CAAA;EAChB,KAAA,CAAM,GAAA,EAAK,aAAA,EAAe,GAAA,EAAK,YAAA,GAAe,MAAA,CAAO,CAAA,WAAY,eAAA;AAAA;AAAA,UAGlD,YAAA;EAAA,SACN,KAAA,EAAO,cAAA;EAAA,SACP,QAAA;EAAA,SACA,UAAA,EAAY,UAAA;EAAA,SACZ,SAAA,EAAW,WAAA;EACpB,sBAAA,IAA0B,WAAA;EAAA,SACjB,KAAA,GAAQ,WAAA;AAAA;AAAA,UAGF,eAAA,YAA2B,OAAA,CAAQ,CAAA;EAAA,SAEzC,QAAA;EAAA,SACA,UAAA;EAAA,SACA,YAAA,GAAe,CAAA;AAAA;AAAA,KAGd,KAAA,MAAW,OAAO,CAAC,CAAA;AAAA,UAEd,eAAA;EAAA,SACN,GAAA;EAAA,SACA,IAAA,EAAM,KAAK,CAAC,CAAA;AAAA;AAAA,UAGN,aAAA;EAAA,SACN,KAAA,EAAO,cAAA;EAAA,SACP,IAAA;EAAA,SACA,UAAA,WAAqB,eAAA;EAAA,SACrB,KAAA,EAAO,QAAA,CAAS,MAAA,SAAe,KAAA;EAAA,SAC/B,MAAA,IAAU,MAAA,EAAQ,GAAA,EAAK,GAAA,EAAK,YAAA,cAA0B,eAAA;AAAA;AAAA,KAGrD,KAAA,MAAW,CAAA,SAAU,OAAO,YAAY,CAAA;AAAA,KAExC,QAAA,W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c,CAAA,SAAU,eAAA,CAAgB,CAAA;;;iBCgBhF,mBAAA,CACd,WAAA,EAAa,oCAAA,cACb,OAAA,WACC,2BAA2B;AAAA,iBAcd,gCAAA,CAAiC,KAAA;EAAA,SACtC,KAAA,EAAO,WAAA;EAAA,SACP,UAAA,EAAY,2BAAA;EAAA,SACZ,WAAA,EAAa,WAAA;EAAA,SACb,UAAA,EAAY,UAAA;EAAA,SACZ,QAAA;EAAA,SACA,WAAA,EAAa,WAAA;AAAA,aACX,eAAA"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { c as DocumentAst, et as SourceFile } from "./parse-BazJr7Ye.mjs";
|
|
2
|
+
import { l as SymbolTable } from "./symbol-table-C-AH04Ug.mjs";
|
|
3
|
+
import { ContractSourceContext, ContractSourceDiagnostic, ContractSourceProvider, PslContractSourceProvider } from "@prisma-next/config/config-types";
|
|
4
|
+
|
|
5
|
+
//#region src/interpret.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Lets editor tooling that already parses incrementally (e.g. the language
|
|
8
|
+
* server) hand cached artifacts to the interpreter instead of forcing a
|
|
9
|
+
* disk re-parse.
|
|
10
|
+
*/
|
|
11
|
+
interface PslInterpretInput {
|
|
12
|
+
readonly document: DocumentAst;
|
|
13
|
+
readonly sourceFile: SourceFile;
|
|
14
|
+
readonly symbolTable: SymbolTable;
|
|
15
|
+
readonly sourceId: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Declared here — the authoring layer that owns `DocumentAst` / `SourceFile` /
|
|
19
|
+
* `SymbolTable` — because `@prisma-next/config` (core) cannot name authoring
|
|
20
|
+
* types.
|
|
21
|
+
*/
|
|
22
|
+
interface PslInterpretCapable extends PslContractSourceProvider {
|
|
23
|
+
interpret(input: PslInterpretInput, context: ContractSourceContext): readonly ContractSourceDiagnostic[];
|
|
24
|
+
}
|
|
25
|
+
/** The single seam that narrows a contract source to the interpret capability. */
|
|
26
|
+
declare function hasPslInterpreter(source: ContractSourceProvider): source is PslInterpretCapable;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { type PslInterpretCapable, type PslInterpretInput, hasPslInterpreter };
|
|
29
|
+
//# sourceMappingURL=interpret.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interpret.d.mts","names":[],"sources":["../src/interpret.ts"],"mappings":";;;;;;AAeA;;;;UAAiB,iBAAA;EAAA,SACN,QAAA,EAAU,WAAA;EAAA,SACV,UAAA,EAAY,UAAA;EAAA,SACZ,WAAA,EAAa,WAAA;EAAA,SACb,QAAA;AAAA;;;;;;UAQM,mBAAA,SAA4B,yBAAA;EAC3C,SAAA,CACE,KAAA,EAAO,iBAAA,EACP,OAAA,EAAS,qBAAA,YACC,wBAAA;AAAA;;iBAIE,iBAAA,CAAkB,MAAA,EAAQ,sBAAA,GAAyB,MAAA,IAAU,mBAAmB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/interpret.ts
|
|
2
|
+
/** The single seam that narrows a contract source to the interpret capability. */
|
|
3
|
+
function hasPslInterpreter(source) {
|
|
4
|
+
return source.sourceFormat === "psl" && "interpret" in source && typeof source.interpret === "function";
|
|
5
|
+
}
|
|
6
|
+
//#endregion
|
|
7
|
+
export { hasPslInterpreter };
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=interpret.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interpret.mjs","names":[],"sources":["../src/interpret.ts"],"sourcesContent":["import type {\n ContractSourceContext,\n ContractSourceDiagnostic,\n ContractSourceProvider,\n PslContractSourceProvider,\n} from '@prisma-next/config/config-types';\nimport type { SourceFile } from './source-file';\nimport type { SymbolTable } from './symbol-table';\nimport type { DocumentAst } from './syntax/ast/declarations';\n\n/**\n * Lets editor tooling that already parses incrementally (e.g. the language\n * server) hand cached artifacts to the interpreter instead of forcing a\n * disk re-parse.\n */\nexport interface PslInterpretInput {\n readonly document: DocumentAst;\n readonly sourceFile: SourceFile;\n readonly symbolTable: SymbolTable;\n readonly sourceId: string;\n}\n\n/**\n * Declared here — the authoring layer that owns `DocumentAst` / `SourceFile` /\n * `SymbolTable` — because `@prisma-next/config` (core) cannot name authoring\n * types.\n */\nexport interface PslInterpretCapable extends PslContractSourceProvider {\n interpret(\n input: PslInterpretInput,\n context: ContractSourceContext,\n ): readonly ContractSourceDiagnostic[];\n}\n\n/** The single seam that narrows a contract source to the interpret capability. */\nexport function hasPslInterpreter(source: ContractSourceProvider): source is PslInterpretCapable {\n return (\n source.sourceFormat === 'psl' && 'interpret' in source && typeof source.interpret === 'function'\n );\n}\n"],"mappings":";;AAmCA,SAAgB,kBAAkB,QAA+D;CAC/F,OACE,OAAO,iBAAiB,SAAS,eAAe,UAAU,OAAO,OAAO,cAAc;AAE1F"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { $ as Range, H as SyntaxNode, T as ExpressionAst, b as FieldAttributeAst, c as DocumentAst, et as SourceFile, h as NamespaceDeclarationAst, l as FieldDeclarationAst, m as NamedTypeDeclarationAst, o as CompositeTypeDeclarationAst, p as ModelDeclarationAst, t as ParseDiagnostic, u as GenericBlockDeclarationAst, v as TypeAnnotationAst, x as ModelAttributeAst } from "./parse-BazJr7Ye.mjs";
|
|
2
|
+
import { PslExtensionBlock, PslSpan } from "@prisma-next/framework-components/psl-ast";
|
|
3
|
+
import { AuthoringPslBlockDescriptorNamespace } from "@prisma-next/framework-components/authoring";
|
|
4
|
+
|
|
5
|
+
//#region src/resolve.d.ts
|
|
6
|
+
interface ResolvedAttributeArg {
|
|
7
|
+
readonly kind: 'positional' | 'named';
|
|
8
|
+
readonly name?: string;
|
|
9
|
+
readonly value: string;
|
|
10
|
+
readonly expression?: ExpressionAst;
|
|
11
|
+
readonly span: PslSpan;
|
|
12
|
+
}
|
|
13
|
+
interface ResolvedAttribute {
|
|
14
|
+
readonly name: string;
|
|
15
|
+
readonly args: readonly ResolvedAttributeArg[];
|
|
16
|
+
readonly span: PslSpan;
|
|
17
|
+
}
|
|
18
|
+
interface ResolvedTypeConstructorCall {
|
|
19
|
+
readonly path: readonly string[];
|
|
20
|
+
readonly args: readonly ResolvedAttributeArg[];
|
|
21
|
+
readonly span: PslSpan;
|
|
22
|
+
}
|
|
23
|
+
declare function readResolvedAttribute(attribute: FieldAttributeAst | ModelAttributeAst, sourceFile: SourceFile): ResolvedAttribute;
|
|
24
|
+
declare function readResolvedAttributes(attributes: Iterable<FieldAttributeAst | ModelAttributeAst>, sourceFile: SourceFile): readonly ResolvedAttribute[];
|
|
25
|
+
declare function readResolvedConstructorCall(annotation: TypeAnnotationAst | undefined, sourceFile: SourceFile): ResolvedTypeConstructorCall | undefined;
|
|
26
|
+
declare function nodePslSpan(node: SyntaxNode, sourceFile: SourceFile): PslSpan;
|
|
27
|
+
/** Unsupported-top-level-block diagnostics are anchored to the keyword token. */
|
|
28
|
+
declare function keywordPslSpan(node: SyntaxNode, keyword: string, sourceFile: SourceFile): PslSpan;
|
|
29
|
+
declare function rangeToPslSpan(range: Range, sourceFile: SourceFile): PslSpan;
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/symbol-table.d.ts
|
|
32
|
+
interface SymbolTable {
|
|
33
|
+
readonly topLevel: TopLevelScope;
|
|
34
|
+
}
|
|
35
|
+
interface TopLevelScope {
|
|
36
|
+
readonly namespaces: Record<string, NamespaceSymbol>;
|
|
37
|
+
readonly scalars: Record<string, ScalarSymbol>;
|
|
38
|
+
readonly typeAliases: Record<string, TypeAliasSymbol>;
|
|
39
|
+
readonly blocks: Record<string, BlockSymbol>;
|
|
40
|
+
readonly models: Record<string, ModelSymbol>;
|
|
41
|
+
readonly compositeTypes: Record<string, CompositeTypeSymbol>;
|
|
42
|
+
}
|
|
43
|
+
interface NamespaceSymbol {
|
|
44
|
+
readonly kind: 'namespace';
|
|
45
|
+
readonly name: string;
|
|
46
|
+
readonly node: NamespaceDeclarationAst;
|
|
47
|
+
readonly span: PslSpan;
|
|
48
|
+
readonly models: Record<string, ModelSymbol>;
|
|
49
|
+
readonly compositeTypes: Record<string, CompositeTypeSymbol>;
|
|
50
|
+
readonly blocks: Record<string, BlockSymbol>;
|
|
51
|
+
}
|
|
52
|
+
interface ModelSymbol {
|
|
53
|
+
readonly kind: 'model';
|
|
54
|
+
readonly name: string;
|
|
55
|
+
readonly node: ModelDeclarationAst;
|
|
56
|
+
readonly span: PslSpan;
|
|
57
|
+
readonly fields: Record<string, FieldSymbol>;
|
|
58
|
+
readonly attributes: readonly ResolvedAttribute[];
|
|
59
|
+
}
|
|
60
|
+
interface CompositeTypeSymbol {
|
|
61
|
+
readonly kind: 'compositeType';
|
|
62
|
+
readonly name: string;
|
|
63
|
+
readonly node: CompositeTypeDeclarationAst;
|
|
64
|
+
readonly span: PslSpan;
|
|
65
|
+
readonly fields: Record<string, FieldSymbol>;
|
|
66
|
+
readonly attributes: readonly ResolvedAttribute[];
|
|
67
|
+
}
|
|
68
|
+
interface BlockSymbol {
|
|
69
|
+
readonly kind: 'block';
|
|
70
|
+
readonly name: string;
|
|
71
|
+
readonly keyword: string;
|
|
72
|
+
readonly node: GenericBlockDeclarationAst;
|
|
73
|
+
readonly span: PslSpan;
|
|
74
|
+
/** Resolved once so consumers do not independently classify block parameters. */
|
|
75
|
+
readonly block: PslExtensionBlock;
|
|
76
|
+
}
|
|
77
|
+
interface ResolvedNamedTypeBinding {
|
|
78
|
+
readonly baseType?: string;
|
|
79
|
+
readonly typeConstructor?: ResolvedTypeConstructorCall;
|
|
80
|
+
readonly isConstructor: boolean;
|
|
81
|
+
readonly attributes: readonly ResolvedAttribute[];
|
|
82
|
+
}
|
|
83
|
+
interface ScalarSymbol extends ResolvedNamedTypeBinding {
|
|
84
|
+
readonly kind: 'scalar';
|
|
85
|
+
readonly name: string;
|
|
86
|
+
readonly node: NamedTypeDeclarationAst;
|
|
87
|
+
readonly span: PslSpan;
|
|
88
|
+
}
|
|
89
|
+
interface TypeAliasSymbol extends ResolvedNamedTypeBinding {
|
|
90
|
+
readonly kind: 'typeAlias';
|
|
91
|
+
readonly name: string;
|
|
92
|
+
readonly node: NamedTypeDeclarationAst;
|
|
93
|
+
readonly span: PslSpan;
|
|
94
|
+
}
|
|
95
|
+
interface FieldSymbol {
|
|
96
|
+
readonly kind: 'field';
|
|
97
|
+
readonly name: string;
|
|
98
|
+
readonly node: FieldDeclarationAst;
|
|
99
|
+
readonly span: PslSpan;
|
|
100
|
+
readonly typeName: string;
|
|
101
|
+
readonly typeNamespaceId?: string;
|
|
102
|
+
readonly typeContractSpaceId?: string;
|
|
103
|
+
readonly optional: boolean;
|
|
104
|
+
readonly list: boolean;
|
|
105
|
+
readonly typeConstructor?: ResolvedTypeConstructorCall;
|
|
106
|
+
readonly attributes: readonly ResolvedAttribute[];
|
|
107
|
+
/** Prevents cascading unsupported-type diagnostics after invalid qualification. */
|
|
108
|
+
readonly malformedType?: boolean;
|
|
109
|
+
}
|
|
110
|
+
interface BuildSymbolTableOptions {
|
|
111
|
+
readonly document: DocumentAst;
|
|
112
|
+
readonly sourceFile: SourceFile;
|
|
113
|
+
readonly scalarTypes: readonly string[];
|
|
114
|
+
readonly pslBlockDescriptors: AuthoringPslBlockDescriptorNamespace;
|
|
115
|
+
}
|
|
116
|
+
interface SymbolTableResult {
|
|
117
|
+
readonly table: SymbolTable;
|
|
118
|
+
readonly diagnostics: readonly ParseDiagnostic[];
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Owns duplicate-declaration detection for all PSL scopes; downstream consumers
|
|
122
|
+
* should consume first-wins symbols rather than re-emitting duplicate diagnostics.
|
|
123
|
+
*/
|
|
124
|
+
declare function buildSymbolTable(options: BuildSymbolTableOptions): SymbolTableResult;
|
|
125
|
+
//#endregion
|
|
126
|
+
export { readResolvedConstructorCall as S, keywordPslSpan as _, ModelSymbol as a, readResolvedAttribute as b, ScalarSymbol as c, TopLevelScope as d, TypeAliasSymbol as f, ResolvedTypeConstructorCall as g, ResolvedAttributeArg as h, FieldSymbol as i, SymbolTable as l, ResolvedAttribute as m, BuildSymbolTableOptions as n, NamespaceSymbol as o, buildSymbolTable as p, CompositeTypeSymbol as r, ResolvedNamedTypeBinding as s, BlockSymbol as t, SymbolTableResult as u, nodePslSpan as v, readResolvedAttributes as x, rangeToPslSpan as y };
|
|
127
|
+
//# sourceMappingURL=symbol-table-C-AH04Ug.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"symbol-table-C-AH04Ug.d.mts","names":[],"sources":["../src/resolve.ts","../src/symbol-table.ts"],"mappings":";;;;;UAaiB,oBAAA;EAAA,SACN,IAAA;EAAA,SACA,IAAA;EAAA,SACA,KAAA;EAAA,SACA,UAAA,GAAa,aAAA;EAAA,SACb,IAAA,EAAM,OAAO;AAAA;AAAA,UAGP,iBAAA;EAAA,SACN,IAAA;EAAA,SACA,IAAA,WAAe,oBAAA;EAAA,SACf,IAAA,EAAM,OAAO;AAAA;AAAA,UAGP,2BAAA;EAAA,SACN,IAAA;EAAA,SACA,IAAA,WAAe,oBAAA;EAAA,SACf,IAAA,EAAM,OAAO;AAAA;AAAA,iBAGR,qBAAA,CACd,SAAA,EAAW,iBAAA,GAAoB,iBAAA,EAC/B,UAAA,EAAY,UAAA,GACX,iBAAA;AAAA,iBAQa,sBAAA,CACd,UAAA,EAAY,QAAA,CAAS,iBAAA,GAAoB,iBAAA,GACzC,UAAA,EAAY,UAAA,YACF,iBAAA;AAAA,iBAII,2BAAA,CACd,UAAA,EAAY,iBAAA,cACZ,UAAA,EAAY,UAAA,GACX,2BAAA;AAAA,iBAuCa,WAAA,CAAY,IAAA,EAAM,UAAA,EAAY,UAAA,EAAY,UAAA,GAAa,OAAA;;iBAUvD,cAAA,CAAe,IAAA,EAAM,UAAA,EAAY,OAAA,UAAiB,UAAA,EAAY,UAAA,GAAa,OAAA;AAAA,iBAS3E,cAAA,CAAe,KAAA,EAAO,KAAA,EAAO,UAAA,EAAY,UAAA,GAAa,OAAA;;;UChFrD,WAAA;EAAA,SAC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AiB;AAAA;AAAA,UAGhC,YAAA,SAAqB,wBAAA;EAAA,SAC3B,IAAA;EAAA,SACA,IAAA;EAAA,SACA,IAAA,EAAM,uBAAA;EAAA,SACN,IAAA,EAAM,OAAA;AAAA;AAAA,UAGA,eAAA,SAAwB,wBAAA;EAAA,SAC9B,IAAA;EAAA,SACA,IAAA;EAAA,SACA,IAAA,EAAM,uBAAA;EAAA,SACN,IAAA,EAAM,OAAA;AAAA;AAAA,UAGA,WAAA;EAAA,SACN,IAAA;EAAA,SACA,IAAA;EAAA,SACA,IAAA,EAAM,mBAAA;EAAA,SACN,IAAA,EAAM,OAAA;EAAA,SACN,QAAA;EAAA,SACA,eAAA;EAAA,SACA,mBAAA;EAAA,SACA,QAAA;EAAA,SACA,IAAA;EAAA,SACA,eAAA,GAAkB,2BAAA;EAAA,SAClB,UAAA,WAAqB,iBAAA;ED7DF;EAAA,SC+DnB,aAAA;AAAA;AAAA,UAGM,uBAAA;EAAA,SACN,QAAA,EAAU,WAAA;EAAA,SACV,UAAA,EAAY,UAAA;EAAA,SACZ,WAAA;EAAA,SACA,mBAAA,EAAqB,oCAAA;AAAA;AAAA,UAGf,iBAAA;EAAA,SACN,KAAA,EAAO,WAAA;EAAA,SACP,WAAA,WAAsB,eAAe;AAAA;;;;;iBAOhC,gBAAA,CAAiB,OAAA,EAAS,uBAAA,GAA0B,iBAAiB"}
|
package/package.json
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/psl-parser",
|
|
3
|
-
"version": "0.14.0-dev.
|
|
3
|
+
"version": "0.14.0-dev.57",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"description": "Reusable parser for Prisma Schema Language (PSL)",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@prisma-next/
|
|
10
|
-
"@prisma-next/
|
|
9
|
+
"@prisma-next/config": "0.14.0-dev.57",
|
|
10
|
+
"@prisma-next/framework-components": "0.14.0-dev.57",
|
|
11
|
+
"@prisma-next/utils": "0.14.0-dev.57"
|
|
11
12
|
},
|
|
12
13
|
"devDependencies": {
|
|
13
|
-
"@prisma-next/tsconfig": "0.14.0-dev.
|
|
14
|
-
"@prisma-next/tsdown": "0.14.0-dev.
|
|
14
|
+
"@prisma-next/tsconfig": "0.14.0-dev.57",
|
|
15
|
+
"@prisma-next/tsdown": "0.14.0-dev.57",
|
|
15
16
|
"tsdown": "0.22.1",
|
|
16
17
|
"typescript": "5.9.3",
|
|
17
18
|
"vitest": "4.1.8"
|
|
@@ -32,6 +33,7 @@
|
|
|
32
33
|
"exports": {
|
|
33
34
|
".": "./dist/index.mjs",
|
|
34
35
|
"./format": "./dist/format.mjs",
|
|
36
|
+
"./interpret": "./dist/interpret.mjs",
|
|
35
37
|
"./syntax": "./dist/syntax.mjs",
|
|
36
38
|
"./tokenizer": "./dist/tokenizer.mjs",
|
|
37
39
|
"./package.json": "./package.json"
|
package/src/interpret.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ContractSourceContext,
|
|
3
|
+
ContractSourceDiagnostic,
|
|
4
|
+
ContractSourceProvider,
|
|
5
|
+
PslContractSourceProvider,
|
|
6
|
+
} from '@prisma-next/config/config-types';
|
|
7
|
+
import type { SourceFile } from './source-file';
|
|
8
|
+
import type { SymbolTable } from './symbol-table';
|
|
9
|
+
import type { DocumentAst } from './syntax/ast/declarations';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Lets editor tooling that already parses incrementally (e.g. the language
|
|
13
|
+
* server) hand cached artifacts to the interpreter instead of forcing a
|
|
14
|
+
* disk re-parse.
|
|
15
|
+
*/
|
|
16
|
+
export interface PslInterpretInput {
|
|
17
|
+
readonly document: DocumentAst;
|
|
18
|
+
readonly sourceFile: SourceFile;
|
|
19
|
+
readonly symbolTable: SymbolTable;
|
|
20
|
+
readonly sourceId: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Declared here — the authoring layer that owns `DocumentAst` / `SourceFile` /
|
|
25
|
+
* `SymbolTable` — because `@prisma-next/config` (core) cannot name authoring
|
|
26
|
+
* types.
|
|
27
|
+
*/
|
|
28
|
+
export interface PslInterpretCapable extends PslContractSourceProvider {
|
|
29
|
+
interpret(
|
|
30
|
+
input: PslInterpretInput,
|
|
31
|
+
context: ContractSourceContext,
|
|
32
|
+
): readonly ContractSourceDiagnostic[];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** The single seam that narrows a contract source to the interpret capability. */
|
|
36
|
+
export function hasPslInterpreter(source: ContractSourceProvider): source is PslInterpretCapable {
|
|
37
|
+
return (
|
|
38
|
+
source.sourceFormat === 'psl' && 'interpret' in source && typeof source.interpret === 'function'
|
|
39
|
+
);
|
|
40
|
+
}
|