@prisma/orm-framework 8.0.0-rc.13 → 8.0.0-rc.13-dev.3
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/{authoring-BffMNBO5.d.mts → authoring-DhT5W5e0.d.mts} +3 -3
- package/dist/{authoring-BffMNBO5.d.mts.map → authoring-DhT5W5e0.d.mts.map} +1 -1
- package/dist/{authoring-DbG78eh2.mjs → authoring-DhgHAcho.mjs} +2 -2
- package/dist/{authoring-DbG78eh2.mjs.map → authoring-DhgHAcho.mjs.map} +1 -1
- package/dist/{components-CTkZKWVB.d.mts → components-WdVKzR2I.d.mts} +2 -2
- package/dist/{components-CTkZKWVB.d.mts.map → components-WdVKzR2I.d.mts.map} +1 -1
- package/dist/components.d.mts +10 -10
- package/dist/components.mjs +5 -5
- package/dist/components__authoring.d.mts +4 -4
- package/dist/components__authoring.mjs +2 -2
- package/dist/components__components.d.mts +2 -2
- package/dist/components__control.d.mts +3 -3
- package/dist/components__control.mjs +2 -2
- package/dist/components__execution.d.mts +1 -1
- package/dist/components__psl-ast.d.mts +4 -4
- package/dist/components__psl-ast.mjs +2 -2
- package/dist/{config-types-CWeyMWBV.d.mts → config-types-ChFDZpdy.d.mts} +4 -4
- package/dist/{config-types-CWeyMWBV.d.mts.map → config-types-ChFDZpdy.d.mts.map} +1 -1
- package/dist/config.d.mts +1 -1
- package/dist/config__config-types.d.mts +1 -1
- package/dist/contract-authoring.d.mts +2 -2
- package/dist/contract-authoring.mjs +1 -1
- package/dist/{control-BTo8rNKi.d.mts → control-BCjP3x_F.d.mts} +5 -5
- package/dist/{control-BTo8rNKi.d.mts.map → control-BCjP3x_F.d.mts.map} +1 -1
- package/dist/{control-CS45l6kB.mjs → control-CJHZj7vF.mjs} +2 -2
- package/dist/{control-CS45l6kB.mjs.map → control-CJHZj7vF.mjs.map} +1 -1
- package/dist/{declarations-43E1JFHg-DGBa0YH_.mjs → declarations-BrSntcPa-Bm0uutX8.mjs} +15 -3
- package/dist/declarations-BrSntcPa-Bm0uutX8.mjs.map +1 -0
- package/dist/errors.d.mts +1 -1
- package/dist/errors__execution.d.mts +1 -1
- package/dist/{execution-BsiK0DjS.d.mts → execution-BcrxxJSJ.d.mts} +2 -2
- package/dist/{execution-BsiK0DjS.d.mts.map → execution-BcrxxJSJ.d.mts.map} +1 -1
- package/dist/{execution-CmKm3jvH.d.mts → execution-DEsldtrH.d.mts} +2 -2
- package/dist/{execution-CmKm3jvH.d.mts.map → execution-DEsldtrH.d.mts.map} +1 -1
- package/dist/{framework-authoring-C9VTqnML-BXtBl2dJ.d.mts → framework-authoring-BEHHwGOv-mQMbHGI_.d.mts} +19 -173
- package/dist/framework-authoring-BEHHwGOv-mQMbHGI_.d.mts.map +1 -0
- package/dist/{framework-components-dUUePWt8-DpoUmGO3.d.mts → framework-components-PQoZtnmv-B_lFgPip.d.mts} +3 -3
- package/dist/{framework-components-dUUePWt8-DpoUmGO3.d.mts.map → framework-components-PQoZtnmv-B_lFgPip.d.mts.map} +1 -1
- package/dist/{parse-Km2Ne67K-CakfHP9f.mjs → parse-CfZKsx8i-D2Oz7q-X.mjs} +4 -4
- package/dist/{parse-Km2Ne67K-CakfHP9f.mjs.map → parse-CfZKsx8i-D2Oz7q-X.mjs.map} +1 -1
- package/dist/{parse-DZRO_CK2-D8YAg23m.d.mts → parse-DZRO_CK2-Dxl0WwMz.d.mts} +5 -5
- package/dist/{parse-DZRO_CK2-D8YAg23m.d.mts.map → parse-DZRO_CK2-Dxl0WwMz.d.mts.map} +1 -1
- package/dist/{psl-ast-BePuKena-AYNqFKCE.d.mts → psl-ast-CjO3JX8O-CyqkfgDM.d.mts} +4 -39
- package/dist/psl-ast-CjO3JX8O-CyqkfgDM.d.mts.map +1 -0
- package/dist/psl-ast-CyvE6CR-.mjs +116 -0
- package/dist/psl-ast-CyvE6CR-.mjs.map +1 -0
- package/dist/psl-ast-f9IZqFG7.d.mts +2 -0
- package/dist/psl-parser.d.mts +107 -25
- package/dist/psl-parser.d.mts.map +1 -1
- package/dist/psl-parser.mjs +532 -317
- package/dist/psl-parser.mjs.map +1 -1
- package/dist/psl-parser__format.mjs +2 -2
- package/dist/psl-parser__format.mjs.map +1 -1
- package/dist/psl-parser__interpret.d.mts +6 -6
- package/dist/psl-parser__interpret.mjs +2 -2
- package/dist/psl-parser__interpret.mjs.map +1 -1
- package/dist/psl-parser__syntax.d.mts +1 -1
- package/dist/psl-parser__syntax.mjs +2 -2
- package/dist/psl-parser__syntax.mjs.map +1 -1
- package/dist/psl-printer.d.mts +4 -19
- package/dist/psl-printer.d.mts.map +1 -1
- package/dist/psl-printer.mjs +8 -87
- package/dist/psl-printer.mjs.map +1 -1
- package/dist/{symbol-table-CRtoii4t-DubuO_5j.d.mts → symbol-table-EcNdXojD-B-bUCgem.d.mts} +5 -9
- package/dist/symbol-table-EcNdXojD-B-bUCgem.d.mts.map +1 -0
- package/dist/{temporal-presets-L05Tl534-jgcrZX_O.d.mts → temporal-presets-Cj9AecXJ-gUtNP82K.d.mts} +3 -3
- package/dist/{temporal-presets-L05Tl534-jgcrZX_O.d.mts.map → temporal-presets-Cj9AecXJ-gUtNP82K.d.mts.map} +1 -1
- package/dist/{temporal-presets-DABMpaxB-DDEaCwpa.mjs → temporal-presets-Cqi6Fnl--DNtY0oCw.mjs} +10 -32
- package/dist/temporal-presets-Cqi6Fnl--DNtY0oCw.mjs.map +1 -0
- package/package.json +15 -15
- package/dist/declarations-43E1JFHg-DGBa0YH_.mjs.map +0 -1
- package/dist/framework-authoring-C9VTqnML-BXtBl2dJ.d.mts.map +0 -1
- package/dist/psl-ast-BePuKena-AYNqFKCE.d.mts.map +0 -1
- package/dist/psl-ast-Cec7KbOn.d.mts +0 -37
- package/dist/psl-ast-Cec7KbOn.d.mts.map +0 -1
- package/dist/psl-ast-DYtFdynZ.mjs +0 -244
- package/dist/psl-ast-DYtFdynZ.mjs.map +0 -1
- package/dist/symbol-table-CRtoii4t-DubuO_5j.d.mts.map +0 -1
- package/dist/temporal-presets-DABMpaxB-DDEaCwpa.mjs.map +0 -1
package/dist/psl-parser.mjs
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { t as blindCast } from "./casts-DpaahrlC-Bd5n2coI.mjs";
|
|
2
2
|
import { t as InternalError } from "./internal-error-ChGYPVpq-DhUD05u0.mjs";
|
|
3
3
|
import { a as or, i as okVoid, n as notOk, r as ok, t as and } from "./result-8OXF26MN.mjs";
|
|
4
|
-
import { _ as isAuthoringModelAttributeDescriptor, v as isAuthoringPslBlockDescriptor, y as isAuthoringTypeConstructorDescriptor } from "./temporal-presets-
|
|
5
|
-
import { a as flatPslModels, c as namespacePslExtensionBlocks
|
|
4
|
+
import { _ as isAuthoringModelAttributeDescriptor, v as isAuthoringPslBlockDescriptor, y as isAuthoringTypeConstructorDescriptor } from "./temporal-presets-Cqi6Fnl--DNtY0oCw.mjs";
|
|
5
|
+
import { a as flatPslModels, c as namespacePslExtensionBlocks } from "./psl-ast-CyvE6CR-.mjs";
|
|
6
6
|
import { n as isPslIdentifier } from "./tokenizer-BMz7z2KR-J0yZ4im3.mjs";
|
|
7
|
-
import { l as
|
|
8
|
-
import { S as TaggedLiteralExprAst, _ as NumberLiteralExprAst, a as CompositeTypeDeclarationAst, d as IdentifierAst, g as NamespaceDeclarationAst, i as BooleanLiteralExprAst, l as FunctionCallAst, m as ModelDeclarationAst, t as ArrayLiteralAst, u as GenericBlockDeclarationAst, w as TypesBlockAst, x as StringLiteralExprAst, y as ObjectLiteralExprAst } from "./declarations-43E1JFHg-DGBa0YH_.mjs";
|
|
7
|
+
import { S as TaggedLiteralExprAst, _ as NumberLiteralExprAst, a as CompositeTypeDeclarationAst, d as IdentifierAst, g as NamespaceDeclarationAst, i as BooleanLiteralExprAst, l as FunctionCallAst, m as ModelDeclarationAst, t as ArrayLiteralAst, u as GenericBlockDeclarationAst, w as TypesBlockAst, x as StringLiteralExprAst, y as ObjectLiteralExprAst } from "./declarations-BrSntcPa-Bm0uutX8.mjs";
|
|
9
8
|
import { a as mapPslDiagnostics, c as readResolvedAttributes, i as keywordPslSpan, l as readResolvedConstructorCall, n as diagnosticFromSpan, o as nodePslSpan, r as diagnosticSource, s as readResolvedAttribute, t as createPslDiagnosticCollector } from "./resolve-D_lZ54qh-DqOQkoMT.mjs";
|
|
10
9
|
//#region ../../../1-framework/2-authoring/psl-parser/dist/index.mjs
|
|
11
10
|
function getPositionalArgument(attribute, index = 0) {
|
|
@@ -104,9 +103,6 @@ function describeResolution(resolution) {
|
|
|
104
103
|
default: return resolution.kind;
|
|
105
104
|
}
|
|
106
105
|
}
|
|
107
|
-
function unbound(name) {
|
|
108
|
-
throw new InternalError(`The binder on this attribute context bound nothing for "${name}". A reference argument is always examined, so the binder must be built over the same snapshot - the same symbol table and sources - as the interpretation consuming it.`);
|
|
109
|
-
}
|
|
110
106
|
function entityRef(expected) {
|
|
111
107
|
const label = `${expected.kind === "block" ? expected.keyword : expected.kind} reference`;
|
|
112
108
|
return {
|
|
@@ -116,8 +112,8 @@ function entityRef(expected) {
|
|
|
116
112
|
parse: (arg, ctx) => {
|
|
117
113
|
const name = IdentifierAst.cast(arg.syntax)?.name();
|
|
118
114
|
if (name === void 0) return notOk([leafDiagnostic(ctx, arg, `Expected ${label}`)]);
|
|
119
|
-
const resolution = ctx.binder.symbolForNode(arg.syntax)
|
|
120
|
-
if (resolution.kind === "unresolved") return notOk([]);
|
|
115
|
+
const resolution = ctx.binder.symbolForNode(arg.syntax);
|
|
116
|
+
if (resolution === void 0 || resolution.kind === "unresolved") return notOk([]);
|
|
121
117
|
const reference = entityReference(resolution);
|
|
122
118
|
if (reference === void 0 || !matchesSelector(reference, expected)) return notOk([leafDiagnostic(ctx, arg, `Expected ${label} "${name}", found ${describeResolution(resolution)}`)]);
|
|
123
119
|
return ok(reference);
|
|
@@ -130,7 +126,7 @@ function parseFieldName(arg, ctx) {
|
|
|
130
126
|
const name = identifier.name();
|
|
131
127
|
if (name === void 0) return notOk([leafDiagnostic(ctx, arg, "Expected a field name")]);
|
|
132
128
|
const resolution = ctx.binder.symbolForNode(arg.syntax);
|
|
133
|
-
if (resolution === void 0)
|
|
129
|
+
if (resolution === void 0) return notOk([]);
|
|
134
130
|
if (resolution.kind === "field") return ok(resolution.symbol.name);
|
|
135
131
|
if (resolution.kind === "crossSpace") return ok(name);
|
|
136
132
|
return notOk([]);
|
|
@@ -139,14 +135,14 @@ function fieldRef() {
|
|
|
139
135
|
return {
|
|
140
136
|
kind: "fieldRef",
|
|
141
137
|
label: "field name",
|
|
142
|
-
parse:
|
|
138
|
+
parse: parseFieldName
|
|
143
139
|
};
|
|
144
140
|
}
|
|
145
141
|
function referencedFieldRef() {
|
|
146
142
|
return {
|
|
147
143
|
kind: "referencedFieldRef",
|
|
148
144
|
label: "field name",
|
|
149
|
-
parse:
|
|
145
|
+
parse: parseFieldName
|
|
150
146
|
};
|
|
151
147
|
}
|
|
152
148
|
function interpretArgs(args, spec, ctx, span, sourceNode) {
|
|
@@ -365,46 +361,6 @@ function list(of, opts) {
|
|
|
365
361
|
}
|
|
366
362
|
};
|
|
367
363
|
}
|
|
368
|
-
function num(value) {
|
|
369
|
-
if (value === void 0) return {
|
|
370
|
-
kind: "num",
|
|
371
|
-
label: "number",
|
|
372
|
-
value: void 0,
|
|
373
|
-
parse: (arg, ctx) => {
|
|
374
|
-
const literal = NumberLiteralExprAst.cast(arg.syntax);
|
|
375
|
-
if (literal !== void 0) {
|
|
376
|
-
const parsed = literal.value();
|
|
377
|
-
if (parsed !== void 0) return ok(parsed);
|
|
378
|
-
}
|
|
379
|
-
return notOk([leafDiagnostic(ctx, arg, "Expected a number literal")]);
|
|
380
|
-
}
|
|
381
|
-
};
|
|
382
|
-
return {
|
|
383
|
-
kind: "num",
|
|
384
|
-
label: String(value),
|
|
385
|
-
value,
|
|
386
|
-
parse: (arg, ctx) => {
|
|
387
|
-
const literal = NumberLiteralExprAst.cast(arg.syntax);
|
|
388
|
-
if (literal !== void 0) {
|
|
389
|
-
if (literal.value() === value) return ok(value);
|
|
390
|
-
}
|
|
391
|
-
return notOk([leafDiagnostic(ctx, arg, `Expected ${value}`)]);
|
|
392
|
-
}
|
|
393
|
-
};
|
|
394
|
-
}
|
|
395
|
-
/** A number literal kept as its source text, for consumers that must not round it through a JS number. */
|
|
396
|
-
function numLiteral() {
|
|
397
|
-
return {
|
|
398
|
-
kind: "num",
|
|
399
|
-
label: "number",
|
|
400
|
-
value: void 0,
|
|
401
|
-
parse: (arg, ctx) => {
|
|
402
|
-
const text = NumberLiteralExprAst.cast(arg.syntax)?.token()?.text;
|
|
403
|
-
if (text !== void 0) return ok({ text });
|
|
404
|
-
return notOk([leafDiagnostic(ctx, arg, "Expected a number literal")]);
|
|
405
|
-
}
|
|
406
|
-
};
|
|
407
|
-
}
|
|
408
364
|
function oneOf(...alts) {
|
|
409
365
|
const label = alts.map((alt) => alt.label).join(" | ");
|
|
410
366
|
return {
|
|
@@ -491,6 +447,80 @@ function str(value) {
|
|
|
491
447
|
}
|
|
492
448
|
};
|
|
493
449
|
}
|
|
450
|
+
function jsonValue() {
|
|
451
|
+
const self = {
|
|
452
|
+
kind: "oneOf",
|
|
453
|
+
label: "JSON value",
|
|
454
|
+
get alternatives() {
|
|
455
|
+
return composed.alternatives;
|
|
456
|
+
},
|
|
457
|
+
parse: (arg, ctx) => composed.parse(arg, ctx)
|
|
458
|
+
};
|
|
459
|
+
const composed = oneOf(str(), finiteNumber(), bool(), jsonNull(), list(self), record(self));
|
|
460
|
+
return self;
|
|
461
|
+
}
|
|
462
|
+
function finiteNumber() {
|
|
463
|
+
return {
|
|
464
|
+
kind: "num",
|
|
465
|
+
value: void 0,
|
|
466
|
+
label: "number",
|
|
467
|
+
parse: (arg, ctx) => {
|
|
468
|
+
const value = NumberLiteralExprAst.cast(arg.syntax)?.value();
|
|
469
|
+
if (value === void 0 || Number.isNaN(value) || !Number.isFinite(value)) return notOk([leafDiagnostic(ctx, arg, "Expected a finite number literal")]);
|
|
470
|
+
return ok(value);
|
|
471
|
+
}
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
function jsonNull() {
|
|
475
|
+
return {
|
|
476
|
+
kind: "null",
|
|
477
|
+
label: "null",
|
|
478
|
+
parse: (arg, ctx) => {
|
|
479
|
+
if (IdentifierAst.cast(arg.syntax)?.name() === "null") return ok(null);
|
|
480
|
+
return notOk([leafDiagnostic(ctx, arg, "Expected null")]);
|
|
481
|
+
}
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
function num(value) {
|
|
485
|
+
if (value === void 0) return {
|
|
486
|
+
kind: "num",
|
|
487
|
+
label: "number",
|
|
488
|
+
value: void 0,
|
|
489
|
+
parse: (arg, ctx) => {
|
|
490
|
+
const literal = NumberLiteralExprAst.cast(arg.syntax);
|
|
491
|
+
if (literal !== void 0) {
|
|
492
|
+
const parsed = literal.value();
|
|
493
|
+
if (parsed !== void 0) return ok(parsed);
|
|
494
|
+
}
|
|
495
|
+
return notOk([leafDiagnostic(ctx, arg, "Expected a number literal")]);
|
|
496
|
+
}
|
|
497
|
+
};
|
|
498
|
+
return {
|
|
499
|
+
kind: "num",
|
|
500
|
+
label: String(value),
|
|
501
|
+
value,
|
|
502
|
+
parse: (arg, ctx) => {
|
|
503
|
+
const literal = NumberLiteralExprAst.cast(arg.syntax);
|
|
504
|
+
if (literal !== void 0) {
|
|
505
|
+
if (literal.value() === value) return ok(value);
|
|
506
|
+
}
|
|
507
|
+
return notOk([leafDiagnostic(ctx, arg, `Expected ${value}`)]);
|
|
508
|
+
}
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
/** A number literal kept as its source text, for consumers that must not round it through a JS number. */
|
|
512
|
+
function numLiteral() {
|
|
513
|
+
return {
|
|
514
|
+
kind: "num",
|
|
515
|
+
label: "number",
|
|
516
|
+
value: void 0,
|
|
517
|
+
parse: (arg, ctx) => {
|
|
518
|
+
const text = NumberLiteralExprAst.cast(arg.syntax)?.token()?.text;
|
|
519
|
+
if (text !== void 0) return ok({ text });
|
|
520
|
+
return notOk([leafDiagnostic(ctx, arg, "Expected a number literal")]);
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
}
|
|
494
524
|
/**
|
|
495
525
|
* A `` tag`...` ``, `tag"..."`, or `tag'...'` argument. `tags` and `documentation` describe the
|
|
496
526
|
* registered tags for tooling; parsing accepts any tag.
|
|
@@ -545,6 +575,9 @@ function optional(type, ...rest) {
|
|
|
545
575
|
defaultValue: rest[0]
|
|
546
576
|
};
|
|
547
577
|
}
|
|
578
|
+
function blockSpecFactoryOf(descriptor) {
|
|
579
|
+
return blindCast(descriptor.spec);
|
|
580
|
+
}
|
|
548
581
|
const scopes = /* @__PURE__ */ new WeakMap();
|
|
549
582
|
function contributedTypeScope(typeConstructors) {
|
|
550
583
|
const existing = scopes.get(typeConstructors);
|
|
@@ -574,6 +607,18 @@ function collect(namespace, prefix) {
|
|
|
574
607
|
}
|
|
575
608
|
return members;
|
|
576
609
|
}
|
|
610
|
+
function findBlockDescriptor(descriptors, keyword) {
|
|
611
|
+
if (descriptors === void 0) return void 0;
|
|
612
|
+
for (const value of Object.values(descriptors)) {
|
|
613
|
+
if (value === void 0) continue;
|
|
614
|
+
if (isAuthoringPslBlockDescriptor(value)) {
|
|
615
|
+
if (value.keyword === keyword) return value;
|
|
616
|
+
continue;
|
|
617
|
+
}
|
|
618
|
+
const nested = findBlockDescriptor(value, keyword);
|
|
619
|
+
if (nested !== void 0) return nested;
|
|
620
|
+
}
|
|
621
|
+
}
|
|
577
622
|
function contributedResolution(member) {
|
|
578
623
|
return member.kind === "contributedType" ? {
|
|
579
624
|
kind: "contributedType",
|
|
@@ -728,10 +773,12 @@ function walkEntities(symbolTable, stack, visit) {
|
|
|
728
773
|
}
|
|
729
774
|
function createBinder(options) {
|
|
730
775
|
const { sources, symbolTable, typeConstructors, attributeSpecs, controlMutationDefaults, describeUnsupportedAttribute } = options;
|
|
776
|
+
const pslBlockDescriptors = options.pslBlockDescriptors ?? {};
|
|
731
777
|
const stack = new ScopeStack(documentScope(symbolTable.topLevel, contributedScope(contributedTypeScope(typeConstructors))));
|
|
732
778
|
const declarations = /* @__PURE__ */ new WeakMap();
|
|
733
779
|
const references = /* @__PURE__ */ new WeakMap();
|
|
734
780
|
const diagnostics = [];
|
|
781
|
+
const binder = new PslBinder(declarations, references);
|
|
735
782
|
for (const symbol of Object.values(symbolTable.topLevel.namedTypes)) declarations.set(symbol.node.syntax, symbol);
|
|
736
783
|
for (const symbol of Object.values(symbolTable.topLevel.blocks)) declarations.set(symbol.node.syntax, symbol);
|
|
737
784
|
for (const namespace of Object.values(symbolTable.topLevel.namespaces)) {
|
|
@@ -785,11 +832,208 @@ function createBinder(options) {
|
|
|
785
832
|
field
|
|
786
833
|
});
|
|
787
834
|
});
|
|
835
|
+
const blockContext = {
|
|
836
|
+
pslBlockDescriptors,
|
|
837
|
+
symbolTable,
|
|
838
|
+
sources,
|
|
839
|
+
references,
|
|
840
|
+
diagnostics
|
|
841
|
+
};
|
|
842
|
+
const bindBlocks = (blocks) => {
|
|
843
|
+
const context = {
|
|
844
|
+
...blockContext,
|
|
845
|
+
scope: stack.current()
|
|
846
|
+
};
|
|
847
|
+
for (const block of Object.values(blocks)) bindBlock(block, context);
|
|
848
|
+
};
|
|
849
|
+
bindBlocks(symbolTable.topLevel.blocks);
|
|
850
|
+
for (const namespace of Object.values(symbolTable.topLevel.namespaces)) {
|
|
851
|
+
stack.push(namespaceScope(namespace, stack.current()));
|
|
852
|
+
bindBlocks(namespace.blocks);
|
|
853
|
+
stack.pop();
|
|
854
|
+
}
|
|
788
855
|
return {
|
|
789
|
-
binder
|
|
856
|
+
binder,
|
|
790
857
|
diagnostics
|
|
791
858
|
};
|
|
792
859
|
}
|
|
860
|
+
function bindBlock(block, ctx) {
|
|
861
|
+
const descriptor = findBlockDescriptor(ctx.pslBlockDescriptors, block.keyword);
|
|
862
|
+
if (descriptor === void 0) return;
|
|
863
|
+
const spec = blockSpecFactoryOf(descriptor)({
|
|
864
|
+
symbols: ctx.symbolTable,
|
|
865
|
+
block
|
|
866
|
+
});
|
|
867
|
+
for (const entry of block.node.entries()) {
|
|
868
|
+
const key = entry.key()?.name();
|
|
869
|
+
if (key === void 0) continue;
|
|
870
|
+
const rule = spec.mode === "struct" ? Object.hasOwn(spec.parameters, key) ? spec.parameters[key]?.type : void 0 : spec.value.type;
|
|
871
|
+
const value = entry.value();
|
|
872
|
+
if (rule === void 0 || value === void 0) continue;
|
|
873
|
+
bindExpression(rule, value, ctx);
|
|
874
|
+
}
|
|
875
|
+
const attributeSpecs = descriptor.attributes ?? {};
|
|
876
|
+
if (Object.keys(attributeSpecs).length === 0) return;
|
|
877
|
+
for (const attribute of readResolvedAttributes(block.node.attributes(), ctx.sources)) {
|
|
878
|
+
const factory = attributeSpecs[attribute.name];
|
|
879
|
+
if (factory === void 0) continue;
|
|
880
|
+
bindArguments(attribute, blindCast(factory)({
|
|
881
|
+
symbols: ctx.symbolTable,
|
|
882
|
+
block
|
|
883
|
+
}), ctx);
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
function bindExpression(rule, expression, ctx, modelContext) {
|
|
887
|
+
const trial = tryBindExpression(rule, expression, ctx, modelContext);
|
|
888
|
+
for (const [node, resolution] of trial.references) ctx.references.set(node, resolution);
|
|
889
|
+
ctx.diagnostics.push(...trial.diagnostics.values());
|
|
890
|
+
}
|
|
891
|
+
function tryBindExpression(rule, expression, ctx, modelContext) {
|
|
892
|
+
const references = /* @__PURE__ */ new Map();
|
|
893
|
+
const diagnostics = /* @__PURE__ */ new Map();
|
|
894
|
+
switch (rule.kind) {
|
|
895
|
+
case "oneOf":
|
|
896
|
+
for (const alternative of rule.alternatives) {
|
|
897
|
+
const trial = tryBindExpression(alternative, expression, ctx, modelContext);
|
|
898
|
+
if (trial.matched) return trial;
|
|
899
|
+
for (const [node, diagnostic] of trial.diagnostics) diagnostics.set(node, diagnostic);
|
|
900
|
+
for (const [node, resolution] of trial.references) if (resolution.kind === "unresolved") references.set(node, resolution);
|
|
901
|
+
}
|
|
902
|
+
return {
|
|
903
|
+
matched: false,
|
|
904
|
+
references,
|
|
905
|
+
diagnostics
|
|
906
|
+
};
|
|
907
|
+
case "list":
|
|
908
|
+
case "record": {
|
|
909
|
+
const children = rule.kind === "list" ? ArrayLiteralAst.cast(expression.syntax)?.elements() : recordValues(expression);
|
|
910
|
+
if (children === void 0) return {
|
|
911
|
+
matched: false,
|
|
912
|
+
references,
|
|
913
|
+
diagnostics
|
|
914
|
+
};
|
|
915
|
+
let matched = true;
|
|
916
|
+
for (const child of children) {
|
|
917
|
+
const trial = tryBindExpression(rule.of, child, ctx, modelContext);
|
|
918
|
+
matched = trial.matched && matched;
|
|
919
|
+
for (const [node, resolution] of trial.references) references.set(node, resolution);
|
|
920
|
+
for (const [node, diagnostic] of trial.diagnostics) diagnostics.set(node, diagnostic);
|
|
921
|
+
}
|
|
922
|
+
return {
|
|
923
|
+
matched,
|
|
924
|
+
references,
|
|
925
|
+
diagnostics
|
|
926
|
+
};
|
|
927
|
+
}
|
|
928
|
+
case "funcCall": {
|
|
929
|
+
const call = FunctionCallAst.cast(expression.syntax);
|
|
930
|
+
const name = call?.name();
|
|
931
|
+
if (call === void 0 || name === void 0 || name.dot() !== void 0 || name.colon() !== void 0 || name.identifier()?.name() !== rule.name) return {
|
|
932
|
+
matched: false,
|
|
933
|
+
references,
|
|
934
|
+
diagnostics
|
|
935
|
+
};
|
|
936
|
+
let matched = true;
|
|
937
|
+
let positional = 0;
|
|
938
|
+
for (const arg of call.args()) {
|
|
939
|
+
const key = arg.name()?.name();
|
|
940
|
+
const parameter = argumentParameter(rule.signature, key, key === void 0 ? positional++ : positional);
|
|
941
|
+
const value = arg.value();
|
|
942
|
+
if (parameter === void 0 || value === void 0) {
|
|
943
|
+
matched = false;
|
|
944
|
+
continue;
|
|
945
|
+
}
|
|
946
|
+
const trial = tryBindExpression(parameter.type, value, ctx, modelContext);
|
|
947
|
+
matched = trial.matched && matched;
|
|
948
|
+
for (const [node, resolution] of trial.references) references.set(node, resolution);
|
|
949
|
+
for (const [node, diagnostic] of trial.diagnostics) diagnostics.set(node, diagnostic);
|
|
950
|
+
}
|
|
951
|
+
return {
|
|
952
|
+
matched,
|
|
953
|
+
references,
|
|
954
|
+
diagnostics
|
|
955
|
+
};
|
|
956
|
+
}
|
|
957
|
+
case "entityRef": {
|
|
958
|
+
const node = expression.syntax;
|
|
959
|
+
const name = IdentifierAst.cast(node)?.name();
|
|
960
|
+
if (name === void 0) return {
|
|
961
|
+
matched: false,
|
|
962
|
+
references,
|
|
963
|
+
diagnostics
|
|
964
|
+
};
|
|
965
|
+
const failures = [];
|
|
966
|
+
const resolution = resolveEntity(name, node, {
|
|
967
|
+
...ctx,
|
|
968
|
+
diagnostics: failures
|
|
969
|
+
});
|
|
970
|
+
references.set(node, resolution);
|
|
971
|
+
for (const diagnostic of failures) diagnostics.set(node, diagnostic);
|
|
972
|
+
return {
|
|
973
|
+
matched: resolution.kind !== "unresolved",
|
|
974
|
+
references,
|
|
975
|
+
diagnostics
|
|
976
|
+
};
|
|
977
|
+
}
|
|
978
|
+
case "fieldRef": {
|
|
979
|
+
const node = expression.syntax;
|
|
980
|
+
const name = IdentifierAst.cast(node)?.name();
|
|
981
|
+
if (name === void 0 || modelContext === void 0) return {
|
|
982
|
+
matched: false,
|
|
983
|
+
references,
|
|
984
|
+
diagnostics
|
|
985
|
+
};
|
|
986
|
+
const failures = [];
|
|
987
|
+
const resolution = resolveOwnerField(name, node, {
|
|
988
|
+
...modelContext,
|
|
989
|
+
diagnostics: failures
|
|
990
|
+
});
|
|
991
|
+
references.set(node, resolution);
|
|
992
|
+
for (const diagnostic of failures) diagnostics.set(node, diagnostic);
|
|
993
|
+
return {
|
|
994
|
+
matched: resolution.kind !== "unresolved",
|
|
995
|
+
references,
|
|
996
|
+
diagnostics
|
|
997
|
+
};
|
|
998
|
+
}
|
|
999
|
+
case "referencedFieldRef": {
|
|
1000
|
+
const node = expression.syntax;
|
|
1001
|
+
const name = IdentifierAst.cast(node)?.name();
|
|
1002
|
+
if (name === void 0 || modelContext === void 0) return {
|
|
1003
|
+
matched: false,
|
|
1004
|
+
references,
|
|
1005
|
+
diagnostics
|
|
1006
|
+
};
|
|
1007
|
+
const failures = [];
|
|
1008
|
+
const resolution = resolveReferencedField(name, node, {
|
|
1009
|
+
...modelContext,
|
|
1010
|
+
diagnostics: failures
|
|
1011
|
+
});
|
|
1012
|
+
references.set(node, resolution);
|
|
1013
|
+
for (const diagnostic of failures) diagnostics.set(node, diagnostic);
|
|
1014
|
+
return {
|
|
1015
|
+
matched: resolution.kind !== "unresolved",
|
|
1016
|
+
references,
|
|
1017
|
+
diagnostics
|
|
1018
|
+
};
|
|
1019
|
+
}
|
|
1020
|
+
default: return {
|
|
1021
|
+
matched: true,
|
|
1022
|
+
references,
|
|
1023
|
+
diagnostics
|
|
1024
|
+
};
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
function recordValues(expression) {
|
|
1028
|
+
const record = ObjectLiteralExprAst.cast(expression.syntax);
|
|
1029
|
+
if (record === void 0) return void 0;
|
|
1030
|
+
return (function* () {
|
|
1031
|
+
for (const field of record.fields()) {
|
|
1032
|
+
const value = field.value();
|
|
1033
|
+
if (value !== void 0) yield value;
|
|
1034
|
+
}
|
|
1035
|
+
})();
|
|
1036
|
+
}
|
|
793
1037
|
function bindAttributes(holder, attributes, specs, instantiate, ctx) {
|
|
794
1038
|
const declared = holder.node.attributes();
|
|
795
1039
|
const nodes = Array.from(declared);
|
|
@@ -818,30 +1062,20 @@ function bindAttributes(holder, attributes, specs, instantiate, ctx) {
|
|
|
818
1062
|
spec
|
|
819
1063
|
}
|
|
820
1064
|
});
|
|
821
|
-
bindArguments(attribute, spec, ctx);
|
|
1065
|
+
bindArguments(attribute, spec, ctx, ctx);
|
|
822
1066
|
});
|
|
823
1067
|
}
|
|
824
|
-
function bindArguments(attribute, spec, ctx) {
|
|
1068
|
+
function bindArguments(attribute, spec, ctx, modelContext) {
|
|
825
1069
|
let positional = 0;
|
|
826
1070
|
for (const arg of attribute.args) {
|
|
827
|
-
const
|
|
828
|
-
if (
|
|
829
|
-
|
|
830
|
-
if (kind === void 0) continue;
|
|
831
|
-
for (const node of referenceNodes(arg.expression)) {
|
|
832
|
-
const resolution = resolveArgument(kind, node, ctx);
|
|
833
|
-
if (resolution !== void 0) ctx.references.set(node, resolution);
|
|
834
|
-
}
|
|
1071
|
+
const parameter = argumentParameter(spec, arg.name, arg.name === void 0 ? positional++ : positional);
|
|
1072
|
+
if (parameter === void 0 || arg.expression === void 0) continue;
|
|
1073
|
+
bindExpression(parameter.type, arg.expression, ctx, modelContext);
|
|
835
1074
|
}
|
|
836
1075
|
}
|
|
837
|
-
function
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
switch (kind) {
|
|
841
|
-
case "fieldRef": return resolveOwnerField(name, node, ctx);
|
|
842
|
-
case "referencedFieldRef": return resolveReferencedField(name, node, ctx);
|
|
843
|
-
case "entityRef": return resolveEntity(name, node, ctx);
|
|
844
|
-
}
|
|
1076
|
+
function argumentParameter(spec, name, position) {
|
|
1077
|
+
if (name === void 0) return spec.positional?.[position];
|
|
1078
|
+
return spec.named === void 0 ? void 0 : own(spec.named, name);
|
|
845
1079
|
}
|
|
846
1080
|
function resolveOwnerField(name, node, ctx) {
|
|
847
1081
|
const field = ctx.owner.fields[name];
|
|
@@ -897,23 +1131,6 @@ function report(message, node, ctx, reference) {
|
|
|
897
1131
|
...diagnosticSource(ctx.sources, node).at()
|
|
898
1132
|
});
|
|
899
1133
|
}
|
|
900
|
-
function referenceKind(type) {
|
|
901
|
-
if (typeof type !== "object" || type === null) return void 0;
|
|
902
|
-
if ("kind" in type) {
|
|
903
|
-
const kind = type.kind;
|
|
904
|
-
if (kind === "fieldRef" || kind === "referencedFieldRef" || kind === "entityRef") return kind;
|
|
905
|
-
}
|
|
906
|
-
if ("of" in type) return referenceKind(type.of);
|
|
907
|
-
if ("alternatives" in type && Array.isArray(type.alternatives)) for (const alternative of type.alternatives) {
|
|
908
|
-
const kind = referenceKind(alternative);
|
|
909
|
-
if (kind !== void 0) return kind;
|
|
910
|
-
}
|
|
911
|
-
}
|
|
912
|
-
function referenceNodes(expression) {
|
|
913
|
-
const array = ArrayLiteralAst.cast(expression.syntax);
|
|
914
|
-
if (array === void 0) return [expression.syntax];
|
|
915
|
-
return Array.from(array.elements(), (element) => element.syntax);
|
|
916
|
-
}
|
|
917
1134
|
function resolveTypeReference(field, scope) {
|
|
918
1135
|
if (field.malformedType === true) return void 0;
|
|
919
1136
|
if (field.typeContractSpaceId !== void 0) return { resolution: { kind: "crossSpace" } };
|
|
@@ -971,240 +1188,248 @@ function describeQualifier(resolution) {
|
|
|
971
1188
|
function own(record, name) {
|
|
972
1189
|
return Object.hasOwn(record, name) ? record[name] : void 0;
|
|
973
1190
|
}
|
|
974
|
-
function
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
1191
|
+
function structBlock(config) {
|
|
1192
|
+
return {
|
|
1193
|
+
mode: "struct",
|
|
1194
|
+
parameters: config.parameters
|
|
1195
|
+
};
|
|
1196
|
+
}
|
|
1197
|
+
function mapBlock(config) {
|
|
1198
|
+
return {
|
|
1199
|
+
mode: "map",
|
|
1200
|
+
value: config.value,
|
|
1201
|
+
allowBare: config.allowBare ?? false
|
|
1202
|
+
};
|
|
1203
|
+
}
|
|
1204
|
+
function interpretExtensionBlock(input) {
|
|
1205
|
+
const { block, descriptor, spec, symbols, sources, binder } = input;
|
|
1206
|
+
const ctx = {
|
|
1207
|
+
sources,
|
|
1208
|
+
symbols,
|
|
1209
|
+
binder
|
|
1210
|
+
};
|
|
1211
|
+
const entries = spec.mode === "struct" ? interpretStructBlock(block, spec, ctx) : interpretMapBlock(block, spec, ctx);
|
|
1212
|
+
const diagnostics = [...entries.diagnostics];
|
|
1213
|
+
const interpretedAttributes = interpretExtensionBlockAttributes({
|
|
1214
|
+
block,
|
|
1215
|
+
descriptor,
|
|
1216
|
+
symbols,
|
|
1217
|
+
sources,
|
|
1218
|
+
binder
|
|
1219
|
+
});
|
|
1220
|
+
diagnostics.push(...interpretedAttributes.diagnostics);
|
|
1221
|
+
if (entries.failed || diagnostics.length > 0) return notOk(diagnostics);
|
|
1222
|
+
return ok({
|
|
1223
|
+
kind: descriptor.discriminator,
|
|
1224
|
+
keyword: block.keyword,
|
|
1225
|
+
name: block.name,
|
|
1226
|
+
values: blindCast(entries.values),
|
|
1227
|
+
parameterSpans: entries.parameterSpans,
|
|
1228
|
+
attributes: interpretedAttributes.attributes,
|
|
1229
|
+
span: block.span
|
|
1230
|
+
});
|
|
1231
|
+
}
|
|
1232
|
+
function interpretStructBlock(block, spec, ctx) {
|
|
1233
|
+
const diagnostics = [];
|
|
1234
|
+
let failed = false;
|
|
1235
|
+
const values = Object.create(null);
|
|
1236
|
+
const parameterSpans = Object.create(null);
|
|
1237
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1238
|
+
for (const entry of block.node.entries()) {
|
|
1239
|
+
const key = entry.key()?.name();
|
|
1240
|
+
if (key === void 0) continue;
|
|
1241
|
+
const span = nodePslSpan(entry.syntax, ctx.sources);
|
|
1242
|
+
if (seen.has(key)) {
|
|
1243
|
+
diagnostics.push(duplicateParameterDiagnostic(block, key, ctx, entry, span));
|
|
980
1244
|
continue;
|
|
981
1245
|
}
|
|
982
|
-
|
|
983
|
-
|
|
1246
|
+
seen.add(key);
|
|
1247
|
+
const rule = Object.hasOwn(spec.parameters, key) ? spec.parameters[key]?.type : void 0;
|
|
1248
|
+
if (rule === void 0) {
|
|
1249
|
+
diagnostics.push(entryDiagnostic("PSL_EXTENSION_UNKNOWN_PARAMETER", `Unknown parameter "${key}" in "${block.keyword}" block "${block.name}". The block does not declare this parameter.`, ctx, entry, span));
|
|
1250
|
+
continue;
|
|
1251
|
+
}
|
|
1252
|
+
parameterSpans[key] = span;
|
|
1253
|
+
const value = entry.value();
|
|
1254
|
+
if (value === void 0) {
|
|
1255
|
+
diagnostics.push(bareEntryDiagnostic(block, key, ctx, entry, span));
|
|
1256
|
+
continue;
|
|
1257
|
+
}
|
|
1258
|
+
const parsed = rule.parse(value, ctx);
|
|
1259
|
+
if (parsed.ok) values[key] = parsed.value;
|
|
1260
|
+
else {
|
|
1261
|
+
failed = true;
|
|
1262
|
+
diagnostics.push(...parsed.failure);
|
|
1263
|
+
}
|
|
984
1264
|
}
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
offset: 0,
|
|
993
|
-
line: 1,
|
|
994
|
-
column: 1
|
|
995
|
-
},
|
|
996
|
-
end: {
|
|
997
|
-
offset: 0,
|
|
998
|
-
line: 1,
|
|
999
|
-
column: 1
|
|
1265
|
+
for (const [key, param] of Object.entries(spec.parameters)) {
|
|
1266
|
+
if (seen.has(key)) continue;
|
|
1267
|
+
if (isOptionalArgType(param.type)) {
|
|
1268
|
+
if (param.type.hasDefault) values[key] = param.type.defaultValue;
|
|
1269
|
+
continue;
|
|
1270
|
+
}
|
|
1271
|
+
diagnostics.push(entryDiagnostic("PSL_EXTENSION_MISSING_REQUIRED_PARAMETER", `Required parameter "${key}" is missing from "${block.keyword}" block "${block.name}".`, ctx, block.node, block.span));
|
|
1000
1272
|
}
|
|
1001
|
-
};
|
|
1002
|
-
function buildRefResolutionContext(symbolTable, block) {
|
|
1003
|
-
const unspecifiedNamespace = makeNamespace(UNSPECIFIED_PSL_NAMESPACE_ID, Object.values(symbolTable.topLevel.models));
|
|
1004
|
-
const allNamespaces = [unspecifiedNamespace, ...Object.values(symbolTable.topLevel.namespaces).map((namespace) => makeNamespace(namespace.name, Object.values(namespace.models)))];
|
|
1005
|
-
const ownerNamespaceName = findOwnerNamespaceName(symbolTable, block);
|
|
1006
1273
|
return {
|
|
1007
|
-
|
|
1008
|
-
|
|
1274
|
+
values,
|
|
1275
|
+
parameterSpans,
|
|
1276
|
+
diagnostics,
|
|
1277
|
+
failed
|
|
1009
1278
|
};
|
|
1010
1279
|
}
|
|
1011
|
-
function
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
}
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1280
|
+
function interpretMapBlock(block, spec, ctx) {
|
|
1281
|
+
const diagnostics = [];
|
|
1282
|
+
let failed = false;
|
|
1283
|
+
const values = Object.create(null);
|
|
1284
|
+
const parameterSpans = Object.create(null);
|
|
1285
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1286
|
+
for (const entry of block.node.entries()) {
|
|
1287
|
+
const key = entry.key()?.name();
|
|
1288
|
+
if (key === void 0) continue;
|
|
1289
|
+
const span = nodePslSpan(entry.syntax, ctx.sources);
|
|
1290
|
+
if (seen.has(key)) {
|
|
1291
|
+
diagnostics.push(duplicateParameterDiagnostic(block, key, ctx, entry, span));
|
|
1292
|
+
continue;
|
|
1293
|
+
}
|
|
1294
|
+
seen.add(key);
|
|
1295
|
+
parameterSpans[key] = span;
|
|
1296
|
+
const value = entry.value();
|
|
1297
|
+
if (value === void 0) {
|
|
1298
|
+
if (spec.allowBare) {
|
|
1299
|
+
values[key] = void 0;
|
|
1300
|
+
continue;
|
|
1301
|
+
}
|
|
1302
|
+
diagnostics.push(bareEntryDiagnostic(block, key, ctx, entry, span));
|
|
1303
|
+
continue;
|
|
1304
|
+
}
|
|
1305
|
+
const parsed = spec.value.type.parse(value, ctx);
|
|
1306
|
+
if (parsed.ok) values[key] = parsed.value;
|
|
1307
|
+
else {
|
|
1308
|
+
failed = true;
|
|
1309
|
+
diagnostics.push(...parsed.failure);
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
return {
|
|
1313
|
+
values,
|
|
1314
|
+
parameterSpans,
|
|
1315
|
+
diagnostics,
|
|
1316
|
+
failed
|
|
1317
|
+
};
|
|
1028
1318
|
}
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
*/
|
|
1032
|
-
const NAME_THE_PSL_SOURCE_LOSES = "__proto__";
|
|
1033
|
-
const DIRECTIVE = /^(\s*\/\/ *use +)(prisma-8|prisma-next)( *)(?!\S)/;
|
|
1034
|
-
const LEGACY_NAME = "prisma-next";
|
|
1035
|
-
function isPrismaNextSchema(text) {
|
|
1036
|
-
return DIRECTIVE.test(text);
|
|
1319
|
+
function duplicateParameterDiagnostic(block, key, ctx, node, span) {
|
|
1320
|
+
return entryDiagnostic("PSL_EXTENSION_DUPLICATE_PARAMETER", `Duplicate parameter "${key}" in "${block.keyword}" block "${block.name}"; first occurrence wins`, ctx, node, span);
|
|
1037
1321
|
}
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
return text.replace(DIRECTIVE, (whole, lead, name, trail) => name === LEGACY_NAME ? `${lead}prisma-8${trail}` : whole);
|
|
1322
|
+
function bareEntryDiagnostic(block, key, ctx, node, span) {
|
|
1323
|
+
return entryDiagnostic("PSL_INVALID_EXTENSION_BLOCK_MEMBER", `Parameter "${key}" in "${block.keyword}" block "${block.name}" must be written as "${key} = <value>".`, ctx, node, span);
|
|
1041
1324
|
}
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
const
|
|
1048
|
-
const
|
|
1049
|
-
const blockName = node.name()?.name() ?? "";
|
|
1050
|
-
const blockAttributes = [];
|
|
1051
|
-
for (const attribute of node.attributes()) {
|
|
1325
|
+
function interpretExtensionBlockAttributes(input) {
|
|
1326
|
+
const { block, descriptor, symbols, sources, binder } = input;
|
|
1327
|
+
const declared = descriptor.attributes ?? {};
|
|
1328
|
+
const attributes = Object.create(null);
|
|
1329
|
+
const diagnostics = [];
|
|
1330
|
+
const seenNames = /* @__PURE__ */ new Set();
|
|
1331
|
+
for (const attribute of block.node.attributes()) {
|
|
1052
1332
|
const name = attribute.name()?.path().join(".") ?? "";
|
|
1053
|
-
const args = Array.from(attribute.argList()?.args() ?? [], (arg) => {
|
|
1054
|
-
const value = arg.value();
|
|
1055
|
-
return {
|
|
1056
|
-
kind: "positional",
|
|
1057
|
-
value: value === void 0 ? "" : printSyntax(value.syntax).trim(),
|
|
1058
|
-
span: nodePslSpan(arg.syntax, sources)
|
|
1059
|
-
};
|
|
1060
|
-
});
|
|
1061
1333
|
const span = nodePslSpan(attribute.syntax, sources);
|
|
1062
|
-
|
|
1063
|
-
name,
|
|
1064
|
-
args,
|
|
1065
|
-
span
|
|
1066
|
-
});
|
|
1067
|
-
}
|
|
1068
|
-
const parameters = {};
|
|
1069
|
-
for (const entry of node.entries()) {
|
|
1070
|
-
const key = entry.key()?.name();
|
|
1071
|
-
if (key === void 0) continue;
|
|
1072
|
-
const span = nodePslSpan(entry.syntax, sources);
|
|
1073
|
-
if (Object.hasOwn(parameters, key)) {
|
|
1334
|
+
if (!Object.hasOwn(declared, name)) {
|
|
1074
1335
|
diagnostics.push({
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1336
|
+
code: "PSL_EXTENSION_UNKNOWN_BLOCK_ATTRIBUTE",
|
|
1337
|
+
message: `Unknown attribute "@@${name}" in "${block.keyword}" block "${block.name}"`,
|
|
1338
|
+
...diagnosticSource(sources, attribute.syntax).at(span)
|
|
1339
|
+
});
|
|
1340
|
+
continue;
|
|
1341
|
+
}
|
|
1342
|
+
if (seenNames.has(name)) {
|
|
1343
|
+
diagnostics.push({
|
|
1344
|
+
code: "PSL_INVALID_EXTENSION_BLOCK_ATTRIBUTE",
|
|
1345
|
+
message: `Duplicate attribute "@@${name}" in "${block.keyword}" block "${block.name}"; first occurrence wins`,
|
|
1346
|
+
...diagnosticSource(sources, attribute.syntax).at(span)
|
|
1082
1347
|
});
|
|
1083
1348
|
continue;
|
|
1084
1349
|
}
|
|
1085
|
-
|
|
1350
|
+
seenNames.add(name);
|
|
1351
|
+
const spec = blindCast(declared[name])({
|
|
1352
|
+
symbols,
|
|
1353
|
+
block
|
|
1354
|
+
});
|
|
1355
|
+
const result = interpretAttribute(attribute, spec, {
|
|
1356
|
+
sources,
|
|
1357
|
+
symbols,
|
|
1358
|
+
binder
|
|
1359
|
+
});
|
|
1360
|
+
if (result.ok) {
|
|
1361
|
+
const argSpans = Object.create(null);
|
|
1362
|
+
let positionalSlot = 0;
|
|
1363
|
+
for (const arg of readResolvedAttribute(attribute, sources).args) {
|
|
1364
|
+
const key = arg.name ?? spec.positional[positionalSlot++]?.key;
|
|
1365
|
+
if (key !== void 0) argSpans[key] = arg.span;
|
|
1366
|
+
}
|
|
1367
|
+
attributes[name] = {
|
|
1368
|
+
args: result.value,
|
|
1369
|
+
argSpans,
|
|
1370
|
+
span
|
|
1371
|
+
};
|
|
1372
|
+
} else diagnostics.push(...result.failure);
|
|
1086
1373
|
}
|
|
1087
1374
|
return {
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
name: blockName,
|
|
1091
|
-
parameters,
|
|
1092
|
-
blockAttributes,
|
|
1093
|
-
attributes: {},
|
|
1094
|
-
span: nodePslSpan(node.syntax, sources)
|
|
1375
|
+
attributes,
|
|
1376
|
+
diagnostics
|
|
1095
1377
|
};
|
|
1096
1378
|
}
|
|
1097
|
-
function
|
|
1098
|
-
const seenNames = /* @__PURE__ */ new Set();
|
|
1099
|
-
for (const attribute of symbol.node.attributes()) {
|
|
1100
|
-
const name = attribute.name()?.path().join(".") ?? "";
|
|
1101
|
-
const parsed = parseBlockAttribute(attribute, name, nodePslSpan(attribute.syntax, sources), descriptor, seenNames, symbol.keyword, symbol.name, sources, symbols);
|
|
1102
|
-
if (parsed.ok) Object.assign(symbol.block.attributes, { [name]: parsed.value });
|
|
1103
|
-
else diagnostics.push(...parsed.diagnostics);
|
|
1104
|
-
}
|
|
1105
|
-
}
|
|
1106
|
-
function parseBlockAttribute(attribute, name, span, descriptor, seenNames, keyword, blockName, sources, symbols) {
|
|
1107
|
-
const sourceFile = sources.sourceFileFor(attribute.syntax);
|
|
1108
|
-
const range = sourceFile.pslSpanToRange(span);
|
|
1109
|
-
const declared = descriptor.attributes ?? {};
|
|
1110
|
-
if (!Object.hasOwn(declared, name)) return {
|
|
1111
|
-
ok: false,
|
|
1112
|
-
diagnostics: [{
|
|
1113
|
-
filename: sourceFile.filename,
|
|
1114
|
-
code: "PSL_EXTENSION_UNKNOWN_BLOCK_ATTRIBUTE",
|
|
1115
|
-
message: `Unknown attribute "@@${name}" in "${keyword}" block "${blockName}"`,
|
|
1116
|
-
range
|
|
1117
|
-
}]
|
|
1118
|
-
};
|
|
1119
|
-
if (seenNames.has(name)) return {
|
|
1120
|
-
ok: false,
|
|
1121
|
-
diagnostics: [{
|
|
1122
|
-
filename: sourceFile.filename,
|
|
1123
|
-
code: "PSL_INVALID_EXTENSION_BLOCK_ATTRIBUTE",
|
|
1124
|
-
message: `Duplicate attribute "@@${name}" in "${keyword}" block "${blockName}"; first occurrence wins`,
|
|
1125
|
-
range
|
|
1126
|
-
}]
|
|
1127
|
-
};
|
|
1128
|
-
seenNames.add(name);
|
|
1129
|
-
const result = interpretAttribute(attribute, blindCast(declared[name])(), {
|
|
1130
|
-
sources,
|
|
1131
|
-
symbols
|
|
1132
|
-
});
|
|
1133
|
-
if (!result.ok) return {
|
|
1134
|
-
ok: false,
|
|
1135
|
-
diagnostics: result.failure
|
|
1136
|
-
};
|
|
1379
|
+
function entryDiagnostic(code, message, ctx, node, span) {
|
|
1137
1380
|
return {
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
span
|
|
1142
|
-
}
|
|
1381
|
+
code,
|
|
1382
|
+
message,
|
|
1383
|
+
...diagnosticSource(ctx.sources, node.syntax).at(span)
|
|
1143
1384
|
};
|
|
1144
1385
|
}
|
|
1145
|
-
function
|
|
1146
|
-
const
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
}
|
|
1167
|
-
});
|
|
1168
|
-
return {
|
|
1169
|
-
kind: "value",
|
|
1170
|
-
raw,
|
|
1171
|
-
span
|
|
1172
|
-
};
|
|
1173
|
-
}
|
|
1174
|
-
const items = [];
|
|
1175
|
-
for (const element of array.elements()) items.push(reconstructFromExpression(element, param.of, nodePslSpan(element.syntax, sources), sources, diagnostics));
|
|
1176
|
-
return {
|
|
1177
|
-
kind: "list",
|
|
1178
|
-
items,
|
|
1179
|
-
span
|
|
1180
|
-
};
|
|
1181
|
-
}
|
|
1182
|
-
switch (param?.kind) {
|
|
1183
|
-
case "ref": return {
|
|
1184
|
-
kind: "ref",
|
|
1185
|
-
identifier: raw,
|
|
1186
|
-
span
|
|
1187
|
-
};
|
|
1188
|
-
case "option": return {
|
|
1189
|
-
kind: "option",
|
|
1190
|
-
token: raw,
|
|
1191
|
-
span
|
|
1192
|
-
};
|
|
1193
|
-
default: return {
|
|
1194
|
-
kind: "value",
|
|
1195
|
-
raw,
|
|
1196
|
-
span
|
|
1197
|
-
};
|
|
1386
|
+
function interpretExtensionBlocks(input) {
|
|
1387
|
+
const { symbolTable, sources, pslBlockDescriptors, binder } = input;
|
|
1388
|
+
const parsedBlocks = /* @__PURE__ */ new Map();
|
|
1389
|
+
const diagnostics = [];
|
|
1390
|
+
const scopes = [symbolTable.topLevel, ...Object.values(symbolTable.topLevel.namespaces)];
|
|
1391
|
+
for (const scope of scopes) for (const block of Object.values(scope.blocks)) {
|
|
1392
|
+
const descriptor = findBlockDescriptor(pslBlockDescriptors, block.keyword);
|
|
1393
|
+
if (descriptor === void 0) continue;
|
|
1394
|
+
const parsed = interpretExtensionBlock({
|
|
1395
|
+
block,
|
|
1396
|
+
descriptor,
|
|
1397
|
+
spec: blockSpecFactoryOf(descriptor)({
|
|
1398
|
+
symbols: symbolTable,
|
|
1399
|
+
block
|
|
1400
|
+
}),
|
|
1401
|
+
symbols: symbolTable,
|
|
1402
|
+
sources,
|
|
1403
|
+
binder
|
|
1404
|
+
});
|
|
1405
|
+
if (parsed.ok) parsedBlocks.set(block, parsed.value);
|
|
1406
|
+
else diagnostics.push(...parsed.failure);
|
|
1198
1407
|
}
|
|
1408
|
+
return {
|
|
1409
|
+
parsedBlocks,
|
|
1410
|
+
diagnostics
|
|
1411
|
+
};
|
|
1412
|
+
}
|
|
1413
|
+
/**
|
|
1414
|
+
* A name that is lost when a PSL file is read. The parser keeps block members, and the PSL contract sources keep other names, as keys of plain objects, where assigning this key sets the object's prototype instead of adding a key. Code that writes PSL must not write this name anywhere a PSL source reads a name, including inside `@map` and `@@map`.
|
|
1415
|
+
*/
|
|
1416
|
+
const NAME_THE_PSL_SOURCE_LOSES = "__proto__";
|
|
1417
|
+
const DIRECTIVE = /^(\s*\/\/ *use +)(prisma-8|prisma-next)( *)(?!\S)/;
|
|
1418
|
+
const LEGACY_NAME = "prisma-next";
|
|
1419
|
+
function isPrismaNextSchema(text) {
|
|
1420
|
+
return DIRECTIVE.test(text);
|
|
1421
|
+
}
|
|
1422
|
+
/** The document with the directive earlier releases wrote replaced by the current one. */
|
|
1423
|
+
function renameLegacyDirective(text) {
|
|
1424
|
+
return text.replace(DIRECTIVE, (whole, lead, name, trail) => name === LEGACY_NAME ? `${lead}prisma-8${trail}` : whole);
|
|
1199
1425
|
}
|
|
1200
1426
|
/**
|
|
1201
1427
|
* Owns duplicate-declaration detection for all PSL scopes; downstream consumers
|
|
1202
1428
|
* should consume first-wins symbols rather than re-emitting duplicate diagnostics.
|
|
1203
1429
|
*/
|
|
1204
1430
|
function buildSymbolTable(options) {
|
|
1205
|
-
const { documents, sources
|
|
1431
|
+
const { documents, sources } = options;
|
|
1206
1432
|
const diagnostics = [];
|
|
1207
|
-
const collectedBlocks = [];
|
|
1208
1433
|
const namespaces = Object.create(null);
|
|
1209
1434
|
const namedTypes = Object.create(null);
|
|
1210
1435
|
const blocks = Object.create(null);
|
|
@@ -1237,7 +1462,7 @@ function buildSymbolTable(options) {
|
|
|
1237
1462
|
if (name !== void 0) compositeTypes[name] = buildCompositeType(name, declaration, sources, diagnostics);
|
|
1238
1463
|
} else if (declaration instanceof GenericBlockDeclarationAst) {
|
|
1239
1464
|
const name = claim(topLevelNames, declaration.name());
|
|
1240
|
-
if (name !== void 0) blocks[name] = buildBlock(name, declaration, sources
|
|
1465
|
+
if (name !== void 0) blocks[name] = buildBlock(name, declaration, sources);
|
|
1241
1466
|
} else if (declaration instanceof NamespaceDeclarationAst) {
|
|
1242
1467
|
const declaredName = declaration.name()?.name();
|
|
1243
1468
|
if (declaredName === void 0) continue;
|
|
@@ -1255,7 +1480,7 @@ function buildSymbolTable(options) {
|
|
|
1255
1480
|
};
|
|
1256
1481
|
namespaces[name] = namespace;
|
|
1257
1482
|
}
|
|
1258
|
-
extendNamespace(namespace, declaration, diagnostics, sources
|
|
1483
|
+
extendNamespace(namespace, declaration, diagnostics, sources);
|
|
1259
1484
|
} else if (declaration instanceof TypesBlockAst) for (const binding of declaration.declarations()) {
|
|
1260
1485
|
const name = claim(topLevelNames, binding.name());
|
|
1261
1486
|
if (name === void 0) continue;
|
|
@@ -1269,19 +1494,14 @@ function buildSymbolTable(options) {
|
|
|
1269
1494
|
};
|
|
1270
1495
|
}
|
|
1271
1496
|
}
|
|
1272
|
-
const symbolTable = { topLevel: {
|
|
1273
|
-
namespaces,
|
|
1274
|
-
namedTypes,
|
|
1275
|
-
blocks,
|
|
1276
|
-
models,
|
|
1277
|
-
compositeTypes
|
|
1278
|
-
} };
|
|
1279
|
-
for (const block of collectedBlocks) {
|
|
1280
|
-
const descriptor = findBlockDescriptor(pslBlockDescriptors, block.keyword);
|
|
1281
|
-
if (descriptor !== void 0) interpretBlockAttributes(block, descriptor, sources, symbolTable, diagnostics);
|
|
1282
|
-
}
|
|
1283
1497
|
return {
|
|
1284
|
-
symbolTable
|
|
1498
|
+
symbolTable: { topLevel: {
|
|
1499
|
+
namespaces,
|
|
1500
|
+
namedTypes,
|
|
1501
|
+
blocks,
|
|
1502
|
+
models,
|
|
1503
|
+
compositeTypes
|
|
1504
|
+
} },
|
|
1285
1505
|
diagnostics
|
|
1286
1506
|
};
|
|
1287
1507
|
}
|
|
@@ -1305,21 +1525,16 @@ function buildCompositeType(name, node, sources, diagnostics) {
|
|
|
1305
1525
|
attributes: readResolvedAttributes(node.attributes(), sources)
|
|
1306
1526
|
};
|
|
1307
1527
|
}
|
|
1308
|
-
function buildBlock(name, node, sources
|
|
1309
|
-
|
|
1310
|
-
const descriptor = findBlockDescriptor(pslBlockDescriptors, keyword);
|
|
1311
|
-
const symbol = {
|
|
1528
|
+
function buildBlock(name, node, sources) {
|
|
1529
|
+
return {
|
|
1312
1530
|
kind: "block",
|
|
1313
1531
|
name,
|
|
1314
|
-
keyword,
|
|
1532
|
+
keyword: node.keyword()?.text ?? "",
|
|
1315
1533
|
node,
|
|
1316
|
-
span: nodePslSpan(node.syntax, sources)
|
|
1317
|
-
block: reconstructExtensionBlock(node, descriptor, sources, diagnostics)
|
|
1534
|
+
span: nodePslSpan(node.syntax, sources)
|
|
1318
1535
|
};
|
|
1319
|
-
collectedBlocks.push(symbol);
|
|
1320
|
-
return symbol;
|
|
1321
1536
|
}
|
|
1322
|
-
function extendNamespace(namespace, node, diagnostics, sources
|
|
1537
|
+
function extendNamespace(namespace, node, diagnostics, sources) {
|
|
1323
1538
|
const { models, compositeTypes, blocks } = namespace;
|
|
1324
1539
|
namespace.declarations.push({
|
|
1325
1540
|
node,
|
|
@@ -1340,7 +1555,7 @@ function extendNamespace(namespace, node, diagnostics, sources, pslBlockDescript
|
|
|
1340
1555
|
}
|
|
1341
1556
|
if (member instanceof ModelDeclarationAst) models[memberName] = buildModel(memberName, member, sources, diagnostics);
|
|
1342
1557
|
else if (member instanceof CompositeTypeDeclarationAst) compositeTypes[memberName] = buildCompositeType(memberName, member, sources, diagnostics);
|
|
1343
|
-
else if (member instanceof GenericBlockDeclarationAst) blocks[memberName] = buildBlock(memberName, member, sources
|
|
1558
|
+
else if (member instanceof GenericBlockDeclarationAst) blocks[memberName] = buildBlock(memberName, member, sources);
|
|
1344
1559
|
}
|
|
1345
1560
|
}
|
|
1346
1561
|
function buildFields(ownerName, fields, sources, diagnostics) {
|
|
@@ -1435,6 +1650,6 @@ function nodeRange(node, sources) {
|
|
|
1435
1650
|
};
|
|
1436
1651
|
}
|
|
1437
1652
|
//#endregion
|
|
1438
|
-
export { NAME_THE_PSL_SOURCE_LOSES, PSL_UNRESOLVED_REFERENCE, assembleAttributeSpecs, blockAttribute, bool, buildSymbolTable, createBinder, createPslDiagnosticCollector, diagnosticFromSpan, diagnosticSource, entityRef, fieldAttribute, fieldRef, findBlockDescriptor, flatPslModels, funcCall, getPositionalArgument, identifier, int, interpretArgs, interpretAttribute, isPrismaNextSchema, isPslIdentifier, json, keywordPslSpan, leafDiagnostic, list, mapPslDiagnostics, modelAttribute, namespacePslExtensionBlocks, nodePslSpan, num, numLiteral, oneOf, optional, parseQuotedStringLiteral, readResolvedAttribute, readResolvedAttributes, readResolvedConstructorCall, record, referencedFieldRef, renameLegacyDirective, str,
|
|
1653
|
+
export { NAME_THE_PSL_SOURCE_LOSES, PSL_UNRESOLVED_REFERENCE, assembleAttributeSpecs, blockAttribute, blockSpecFactoryOf, bool, buildSymbolTable, createBinder, createPslDiagnosticCollector, diagnosticFromSpan, diagnosticSource, entityRef, fieldAttribute, fieldRef, findBlockDescriptor, flatPslModels, funcCall, getPositionalArgument, identifier, int, interpretArgs, interpretAttribute, interpretExtensionBlock, interpretExtensionBlockAttributes, interpretExtensionBlocks, isPrismaNextSchema, isPslIdentifier, json, jsonValue, keywordPslSpan, leafDiagnostic, list, mapBlock, mapPslDiagnostics, modelAttribute, namespacePslExtensionBlocks, nodePslSpan, num, numLiteral, oneOf, optional, parseQuotedStringLiteral, readResolvedAttribute, readResolvedAttributes, readResolvedConstructorCall, record, referencedFieldRef, renameLegacyDirective, str, structBlock, taggedLiteral };
|
|
1439
1654
|
|
|
1440
1655
|
//# sourceMappingURL=psl-parser.mjs.map
|