@prisma-next/psl-parser 0.14.0-dev.6 → 0.14.0-dev.60
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/{declarations-D9h_ihD3.mjs → declarations-DR6To8_k.mjs} +295 -55
- package/dist/declarations-DR6To8_k.mjs.map +1 -0
- package/dist/format.d.mts +1 -1
- package/dist/format.mjs +2 -2
- package/dist/index.d.mts +95 -112
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +373 -60
- package/dist/index.mjs.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/{parse-DhEV6av6.mjs → parse-3-vr14ej.mjs} +26 -5
- package/dist/parse-3-vr14ej.mjs.map +1 -0
- package/dist/{parse-BjZ1LPe6.d.mts → parse-BazJr7Ye.d.mts} +128 -51
- package/dist/parse-BazJr7Ye.d.mts.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/dist/syntax.d.mts +20 -2
- package/dist/syntax.d.mts.map +1 -1
- package/dist/syntax.mjs +43 -3
- package/dist/syntax.mjs.map +1 -0
- package/package.json +7 -5
- package/src/attribute-spec/combinators/bool.ts +19 -0
- package/src/attribute-spec/combinators/diagnostic.ts +15 -0
- package/src/attribute-spec/combinators/entity-ref.ts +24 -0
- package/src/attribute-spec/combinators/field-ref.ts +36 -0
- package/src/attribute-spec/combinators/identifier.ts +16 -0
- package/src/attribute-spec/combinators/int.ts +19 -0
- package/src/attribute-spec/combinators/list.ts +43 -0
- package/src/attribute-spec/combinators/one-of.ts +29 -0
- package/src/attribute-spec/combinators/record.ts +43 -0
- package/src/attribute-spec/combinators/str.ts +19 -0
- package/src/attribute-spec/field-attribute.ts +27 -0
- package/src/attribute-spec/interpret.ts +154 -0
- package/src/attribute-spec/model-attribute.ts +27 -0
- package/src/attribute-spec/optional.ts +8 -0
- package/src/attribute-spec/types.ts +72 -0
- package/src/exports/index.ts +30 -0
- package/src/exports/interpret.ts +2 -0
- package/src/exports/syntax.ts +25 -5
- package/src/interpret.ts +40 -0
- package/src/parse.ts +23 -5
- package/src/resolve.ts +4 -1
- package/src/source-file.ts +25 -0
- package/src/syntax/ast/attributes.ts +5 -6
- package/src/syntax/ast/declarations.ts +51 -26
- package/src/syntax/ast/expressions.ts +12 -13
- package/src/syntax/ast/identifier.ts +2 -3
- package/src/syntax/ast/qualified-name.ts +28 -19
- package/src/syntax/ast/type-annotation.ts +4 -5
- package/src/syntax/ast-helpers.ts +27 -3
- package/src/syntax/navigation.ts +55 -0
- package/src/syntax/red.ts +317 -42
- package/dist/declarations-D9h_ihD3.mjs.map +0 -1
- package/dist/parse-BjZ1LPe6.d.mts.map +0 -1
- package/dist/parse-DhEV6av6.mjs.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { b as ObjectLiteralExprAst, c as NamespaceDeclarationAst, g as BooleanLiteralExprAst, i as GenericBlockDeclarationAst, k as printSyntax, l as TypesBlockAst, m as ArrayLiteralAst, o as ModelDeclarationAst, t as CompositeTypeDeclarationAst, v as NumberLiteralExprAst, w as IdentifierAst, x as StringLiteralExprAst } from "./declarations-DR6To8_k.mjs";
|
|
2
2
|
import { UNSPECIFIED_PSL_NAMESPACE_ID, flatPslModels, makePslNamespace, makePslNamespaceEntries, namespacePslExtensionBlocks, validateExtensionBlock } from "@prisma-next/framework-components/psl-ast";
|
|
3
|
+
import { notOk, ok } from "@prisma-next/utils/result";
|
|
4
|
+
import { blindCast } from "@prisma-next/utils/casts";
|
|
3
5
|
import { isAuthoringPslBlockDescriptor } from "@prisma-next/framework-components/authoring";
|
|
4
6
|
//#region src/attribute-helpers.ts
|
|
5
7
|
function getPositionalArgument(attribute, index = 0) {
|
|
@@ -11,63 +13,6 @@ function parseQuotedStringLiteral(value) {
|
|
|
11
13
|
return match[2] ?? "";
|
|
12
14
|
}
|
|
13
15
|
//#endregion
|
|
14
|
-
//#region src/extension-block.ts
|
|
15
|
-
function findBlockDescriptor(descriptors, keyword) {
|
|
16
|
-
if (descriptors === void 0) return void 0;
|
|
17
|
-
for (const value of Object.values(descriptors)) {
|
|
18
|
-
if (value === void 0) continue;
|
|
19
|
-
if (isAuthoringPslBlockDescriptor(value)) {
|
|
20
|
-
if (value.keyword === keyword) return value;
|
|
21
|
-
continue;
|
|
22
|
-
}
|
|
23
|
-
const nested = findBlockDescriptor(value, keyword);
|
|
24
|
-
if (nested !== void 0) return nested;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
function validateExtensionBlockFromSymbol(input) {
|
|
28
|
-
const refCtx = buildRefResolutionContext(input.symbolTable, input.block);
|
|
29
|
-
return validateExtensionBlock(input.block.block, input.descriptor, input.sourceId, input.codecLookup, refCtx);
|
|
30
|
-
}
|
|
31
|
-
const ZERO_SPAN = {
|
|
32
|
-
start: {
|
|
33
|
-
offset: 0,
|
|
34
|
-
line: 1,
|
|
35
|
-
column: 1
|
|
36
|
-
},
|
|
37
|
-
end: {
|
|
38
|
-
offset: 0,
|
|
39
|
-
line: 1,
|
|
40
|
-
column: 1
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
function buildRefResolutionContext(symbolTable, block) {
|
|
44
|
-
const unspecifiedNamespace = makeNamespace(UNSPECIFIED_PSL_NAMESPACE_ID, Object.values(symbolTable.topLevel.models));
|
|
45
|
-
const allNamespaces = [unspecifiedNamespace, ...Object.values(symbolTable.topLevel.namespaces).map((namespace) => makeNamespace(namespace.name, Object.values(namespace.models)))];
|
|
46
|
-
const ownerNamespaceName = findOwnerNamespaceName(symbolTable, block);
|
|
47
|
-
return {
|
|
48
|
-
ownerNamespace: allNamespaces.find((namespace) => namespace.name === ownerNamespaceName) ?? unspecifiedNamespace,
|
|
49
|
-
allNamespaces
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
function makeNamespace(name, models) {
|
|
53
|
-
return makePslNamespace({
|
|
54
|
-
kind: "namespace",
|
|
55
|
-
name,
|
|
56
|
-
entries: makePslNamespaceEntries(models.map((model) => ({
|
|
57
|
-
kind: "model",
|
|
58
|
-
name: model.name,
|
|
59
|
-
fields: [],
|
|
60
|
-
attributes: [],
|
|
61
|
-
span: ZERO_SPAN
|
|
62
|
-
})), [], []),
|
|
63
|
-
span: ZERO_SPAN
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
function findOwnerNamespaceName(symbolTable, block) {
|
|
67
|
-
for (const namespace of Object.values(symbolTable.topLevel.namespaces)) if (Object.values(namespace.blocks).some((candidate) => candidate === block)) return namespace.name;
|
|
68
|
-
return UNSPECIFIED_PSL_NAMESPACE_ID;
|
|
69
|
-
}
|
|
70
|
-
//#endregion
|
|
71
16
|
//#region src/resolve.ts
|
|
72
17
|
function readResolvedAttribute(attribute, sourceFile) {
|
|
73
18
|
return {
|
|
@@ -93,10 +38,12 @@ function readResolvedArgList(argList, sourceFile) {
|
|
|
93
38
|
const args = [];
|
|
94
39
|
for (const arg of argList.args()) {
|
|
95
40
|
const name = arg.name()?.name();
|
|
41
|
+
const expression = arg.value();
|
|
96
42
|
args.push({
|
|
97
43
|
kind: name !== void 0 ? "named" : "positional",
|
|
98
44
|
...name !== void 0 ? { name } : {},
|
|
99
|
-
value: renderExpression(
|
|
45
|
+
value: renderExpression(expression),
|
|
46
|
+
...expression !== void 0 ? { expression } : {},
|
|
100
47
|
span: nodePslSpan(arg.syntax, sourceFile)
|
|
101
48
|
});
|
|
102
49
|
}
|
|
@@ -141,6 +88,372 @@ function offsetToPslPosition(offset, sourceFile) {
|
|
|
141
88
|
};
|
|
142
89
|
}
|
|
143
90
|
//#endregion
|
|
91
|
+
//#region src/attribute-spec/combinators/diagnostic.ts
|
|
92
|
+
const ATTRIBUTE_DIAGNOSTIC_CODE = "PSL_INVALID_ATTRIBUTE_SYNTAX";
|
|
93
|
+
function leafDiagnostic(ctx, node, message) {
|
|
94
|
+
return {
|
|
95
|
+
code: ATTRIBUTE_DIAGNOSTIC_CODE,
|
|
96
|
+
message,
|
|
97
|
+
sourceId: ctx.sourceId,
|
|
98
|
+
span: nodePslSpan(node.syntax, ctx.sourceFile)
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
//#endregion
|
|
102
|
+
//#region src/attribute-spec/combinators/bool.ts
|
|
103
|
+
function bool() {
|
|
104
|
+
return {
|
|
105
|
+
kind: "bool",
|
|
106
|
+
label: "boolean",
|
|
107
|
+
parse: (arg, ctx) => {
|
|
108
|
+
if (arg instanceof BooleanLiteralExprAst) {
|
|
109
|
+
const value = arg.value();
|
|
110
|
+
if (value !== void 0) return ok(value);
|
|
111
|
+
}
|
|
112
|
+
return notOk([leafDiagnostic(ctx, arg, "Expected a boolean literal")]);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
//#endregion
|
|
117
|
+
//#region src/attribute-spec/combinators/entity-ref.ts
|
|
118
|
+
function entityRef() {
|
|
119
|
+
return {
|
|
120
|
+
kind: "entityRef",
|
|
121
|
+
label: "model name",
|
|
122
|
+
parse: (arg, ctx) => {
|
|
123
|
+
if (!(arg instanceof IdentifierAst)) return notOk([leafDiagnostic(ctx, arg, "Expected a model name")]);
|
|
124
|
+
const name = arg.name();
|
|
125
|
+
if (name === void 0) return notOk([leafDiagnostic(ctx, arg, "Expected a model name")]);
|
|
126
|
+
return ok(name);
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
//#endregion
|
|
131
|
+
//#region src/attribute-spec/combinators/field-ref.ts
|
|
132
|
+
function fieldRef(scope) {
|
|
133
|
+
return {
|
|
134
|
+
kind: "fieldRef",
|
|
135
|
+
label: "field name",
|
|
136
|
+
scope,
|
|
137
|
+
parse: (arg, ctx) => {
|
|
138
|
+
if (!(arg instanceof IdentifierAst)) return notOk([leafDiagnostic(ctx, arg, "Expected a field name")]);
|
|
139
|
+
const name = arg.name();
|
|
140
|
+
if (name === void 0) return notOk([leafDiagnostic(ctx, arg, "Expected a field name")]);
|
|
141
|
+
const model = scope === "self" ? ctx.selfModel : ctx.resolveReferencedModel();
|
|
142
|
+
if (model !== void 0 && !Object.hasOwn(model.fields, name)) return notOk([leafDiagnostic(ctx, arg, `Field "${name}" does not exist on model "${model.name}"`)]);
|
|
143
|
+
return ok(name);
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
//#endregion
|
|
148
|
+
//#region src/attribute-spec/combinators/identifier.ts
|
|
149
|
+
function identifier(name) {
|
|
150
|
+
return {
|
|
151
|
+
kind: "identifier",
|
|
152
|
+
label: name,
|
|
153
|
+
parse: (arg, ctx) => {
|
|
154
|
+
if (arg instanceof IdentifierAst && arg.name() === name) return ok(name);
|
|
155
|
+
return notOk([leafDiagnostic(ctx, arg, `Expected ${name}`)]);
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
//#endregion
|
|
160
|
+
//#region src/attribute-spec/combinators/int.ts
|
|
161
|
+
function int() {
|
|
162
|
+
return {
|
|
163
|
+
kind: "int",
|
|
164
|
+
label: "integer",
|
|
165
|
+
parse: (arg, ctx) => {
|
|
166
|
+
if (arg instanceof NumberLiteralExprAst) {
|
|
167
|
+
const value = arg.value();
|
|
168
|
+
if (value !== void 0 && Number.isInteger(value)) return ok(value);
|
|
169
|
+
}
|
|
170
|
+
return notOk([leafDiagnostic(ctx, arg, "Expected an integer literal")]);
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
//#endregion
|
|
175
|
+
//#region src/attribute-spec/combinators/list.ts
|
|
176
|
+
function list(of, opts) {
|
|
177
|
+
return {
|
|
178
|
+
kind: "list",
|
|
179
|
+
label: `${of.label}[]`,
|
|
180
|
+
parse: (arg, ctx) => {
|
|
181
|
+
if (!(arg instanceof ArrayLiteralAst)) return notOk([leafDiagnostic(ctx, arg, `Expected a list of ${of.label}`)]);
|
|
182
|
+
const diagnostics = [];
|
|
183
|
+
const parsed = [];
|
|
184
|
+
let count = 0;
|
|
185
|
+
for (const element of arg.elements()) {
|
|
186
|
+
count += 1;
|
|
187
|
+
const result = of.parse(element, ctx);
|
|
188
|
+
if (result.ok) parsed.push({
|
|
189
|
+
node: element,
|
|
190
|
+
value: result.value
|
|
191
|
+
});
|
|
192
|
+
else diagnostics.push(...result.failure);
|
|
193
|
+
}
|
|
194
|
+
if (opts?.nonEmpty === true && count === 0) diagnostics.push(leafDiagnostic(ctx, arg, "Expected a non-empty list"));
|
|
195
|
+
if (opts?.unique === true) {
|
|
196
|
+
const seen = /* @__PURE__ */ new Set();
|
|
197
|
+
for (const { node, value } of parsed) if (seen.has(value)) diagnostics.push(leafDiagnostic(ctx, node, "Duplicate list entry"));
|
|
198
|
+
else seen.add(value);
|
|
199
|
+
}
|
|
200
|
+
if (diagnostics.length > 0) return notOk(diagnostics);
|
|
201
|
+
return ok(parsed.map((entry) => entry.value));
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
//#endregion
|
|
206
|
+
//#region src/attribute-spec/combinators/one-of.ts
|
|
207
|
+
function oneOf(...alts) {
|
|
208
|
+
const label = alts.map((alt) => alt.label).join(" | ");
|
|
209
|
+
return {
|
|
210
|
+
kind: "oneOf",
|
|
211
|
+
label,
|
|
212
|
+
parse: (arg, ctx) => {
|
|
213
|
+
for (const alt of alts) {
|
|
214
|
+
const result = alt.parse(arg, ctx);
|
|
215
|
+
if (result.ok) return ok(blindCast(result.value));
|
|
216
|
+
}
|
|
217
|
+
return notOk([leafDiagnostic(ctx, arg, `Expected one of: ${label}`)]);
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
//#endregion
|
|
222
|
+
//#region src/attribute-spec/combinators/record.ts
|
|
223
|
+
function record(of) {
|
|
224
|
+
return {
|
|
225
|
+
kind: "record",
|
|
226
|
+
label: `{ [key]: ${of.label} }`,
|
|
227
|
+
parse: (arg, ctx) => {
|
|
228
|
+
if (!(arg instanceof ObjectLiteralExprAst)) return notOk([leafDiagnostic(ctx, arg, "Expected an object literal")]);
|
|
229
|
+
const diagnostics = [];
|
|
230
|
+
const result = {};
|
|
231
|
+
for (const field of arg.fields()) {
|
|
232
|
+
const key = field.keyName();
|
|
233
|
+
if (key === void 0) {
|
|
234
|
+
diagnostics.push(leafDiagnostic(ctx, field, "Expected a key"));
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
const value = field.value();
|
|
238
|
+
if (value === void 0) {
|
|
239
|
+
diagnostics.push(leafDiagnostic(ctx, field, `Expected a value for key "${key}"`));
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
const parsed = of.parse(value, ctx);
|
|
243
|
+
if (!parsed.ok) {
|
|
244
|
+
diagnostics.push(...parsed.failure);
|
|
245
|
+
continue;
|
|
246
|
+
}
|
|
247
|
+
if (Object.hasOwn(result, key)) {
|
|
248
|
+
diagnostics.push(leafDiagnostic(ctx, field, `Duplicate key "${key}"`));
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
result[key] = parsed.value;
|
|
252
|
+
}
|
|
253
|
+
if (diagnostics.length > 0) return notOk(diagnostics);
|
|
254
|
+
return ok(result);
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
//#endregion
|
|
259
|
+
//#region src/attribute-spec/combinators/str.ts
|
|
260
|
+
function str() {
|
|
261
|
+
return {
|
|
262
|
+
kind: "str",
|
|
263
|
+
label: "string",
|
|
264
|
+
parse: (arg, ctx) => {
|
|
265
|
+
if (arg instanceof StringLiteralExprAst) {
|
|
266
|
+
const value = arg.value();
|
|
267
|
+
if (value !== void 0) return ok(value);
|
|
268
|
+
}
|
|
269
|
+
return notOk([leafDiagnostic(ctx, arg, "Expected a string literal")]);
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
//#endregion
|
|
274
|
+
//#region src/attribute-spec/field-attribute.ts
|
|
275
|
+
function fieldAttribute(name, config) {
|
|
276
|
+
return {
|
|
277
|
+
level: "field",
|
|
278
|
+
name,
|
|
279
|
+
positional: config.positional ?? [],
|
|
280
|
+
named: config.named ?? {},
|
|
281
|
+
...config.refine !== void 0 ? { refine: config.refine } : {}
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
//#endregion
|
|
285
|
+
//#region src/attribute-spec/interpret.ts
|
|
286
|
+
function interpretAttribute(attrNode, spec, ctx) {
|
|
287
|
+
const diagnostics = [];
|
|
288
|
+
const attributeSpan = nodePslSpan(attrNode.syntax, ctx.sourceFile);
|
|
289
|
+
const output = {};
|
|
290
|
+
const seen = /* @__PURE__ */ new Set();
|
|
291
|
+
let positionalSlot = 0;
|
|
292
|
+
let reportedExcess = false;
|
|
293
|
+
for (const arg of attrNode.argList()?.args() ?? []) {
|
|
294
|
+
const name = arg.name()?.name();
|
|
295
|
+
let key;
|
|
296
|
+
let param;
|
|
297
|
+
if (name === void 0) {
|
|
298
|
+
const posParam = spec.positional[positionalSlot];
|
|
299
|
+
if (posParam === void 0) {
|
|
300
|
+
if (!reportedExcess) {
|
|
301
|
+
diagnostics.push(diagnostic(`Attribute "${spec.name}" received too many positional arguments`, ctx, attributeSpan));
|
|
302
|
+
reportedExcess = true;
|
|
303
|
+
}
|
|
304
|
+
continue;
|
|
305
|
+
}
|
|
306
|
+
positionalSlot += 1;
|
|
307
|
+
key = posParam.key;
|
|
308
|
+
param = posParam.type;
|
|
309
|
+
} else {
|
|
310
|
+
const namedParam = Object.hasOwn(spec.named, name) ? spec.named[name] : void 0;
|
|
311
|
+
if (namedParam === void 0) {
|
|
312
|
+
diagnostics.push(diagnostic(`Attribute "${spec.name}" received unknown argument "${name}"`, ctx, nodePslSpan(arg.syntax, ctx.sourceFile)));
|
|
313
|
+
continue;
|
|
314
|
+
}
|
|
315
|
+
key = name;
|
|
316
|
+
param = namedParam;
|
|
317
|
+
}
|
|
318
|
+
if (seen.has(key)) {
|
|
319
|
+
diagnostics.push(diagnostic(`Attribute "${spec.name}" received duplicate argument "${key}"`, ctx, nodePslSpan(arg.syntax, ctx.sourceFile)));
|
|
320
|
+
continue;
|
|
321
|
+
}
|
|
322
|
+
seen.add(key);
|
|
323
|
+
const result = parseArgValue(arg, param, ctx, diagnostics);
|
|
324
|
+
if (result.ok) output[key] = result.value;
|
|
325
|
+
}
|
|
326
|
+
const finalized = /* @__PURE__ */ new Set();
|
|
327
|
+
const finalizeAbsentKey = (key, positionalParam, namedParam) => {
|
|
328
|
+
if (finalized.has(key) || seen.has(key)) return;
|
|
329
|
+
finalized.add(key);
|
|
330
|
+
const effective = namedParam ?? positionalParam;
|
|
331
|
+
if (effective === void 0) return;
|
|
332
|
+
if (isOptionalArgType(effective)) {
|
|
333
|
+
if (effective.hasDefault) output[key] = effective.defaultValue;
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
diagnostics.push(diagnostic(`Attribute "${spec.name}" is missing required argument "${key}"`, ctx, attributeSpan));
|
|
337
|
+
};
|
|
338
|
+
for (const param of spec.positional) {
|
|
339
|
+
const namedParam = Object.hasOwn(spec.named, param.key) ? spec.named[param.key] : void 0;
|
|
340
|
+
finalizeAbsentKey(param.key, param.type, namedParam);
|
|
341
|
+
}
|
|
342
|
+
for (const key of Object.keys(spec.named)) finalizeAbsentKey(key, void 0, spec.named[key]);
|
|
343
|
+
if (diagnostics.length > 0) return notOk(diagnostics);
|
|
344
|
+
const value = blindCast(output);
|
|
345
|
+
if (spec.refine !== void 0) {
|
|
346
|
+
const refineDiagnostics = spec.refine(value, ctx);
|
|
347
|
+
if (refineDiagnostics.length > 0) return notOk(refineDiagnostics);
|
|
348
|
+
}
|
|
349
|
+
return ok(value);
|
|
350
|
+
}
|
|
351
|
+
function parseArgValue(arg, argType, ctx, diagnostics) {
|
|
352
|
+
const value = arg.value();
|
|
353
|
+
if (value === void 0) {
|
|
354
|
+
const missing = diagnostic("Attribute argument is missing a value", ctx, nodePslSpan(arg.syntax, ctx.sourceFile));
|
|
355
|
+
diagnostics.push(missing);
|
|
356
|
+
return notOk([missing]);
|
|
357
|
+
}
|
|
358
|
+
const result = argType.parse(value, ctx);
|
|
359
|
+
if (!result.ok) for (const failure of result.failure) diagnostics.push(failure);
|
|
360
|
+
return result;
|
|
361
|
+
}
|
|
362
|
+
function isOptionalArgType(param) {
|
|
363
|
+
return "optional" in param && param.optional === true;
|
|
364
|
+
}
|
|
365
|
+
function diagnostic(message, ctx, span) {
|
|
366
|
+
return {
|
|
367
|
+
code: ATTRIBUTE_DIAGNOSTIC_CODE,
|
|
368
|
+
message,
|
|
369
|
+
sourceId: ctx.sourceId,
|
|
370
|
+
span
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
//#endregion
|
|
374
|
+
//#region src/attribute-spec/model-attribute.ts
|
|
375
|
+
function modelAttribute(name, config) {
|
|
376
|
+
return {
|
|
377
|
+
level: "model",
|
|
378
|
+
name,
|
|
379
|
+
positional: config.positional ?? [],
|
|
380
|
+
named: config.named ?? {},
|
|
381
|
+
...config.refine !== void 0 ? { refine: config.refine } : {}
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
//#endregion
|
|
385
|
+
//#region src/attribute-spec/optional.ts
|
|
386
|
+
function optional(type, ...rest) {
|
|
387
|
+
if (rest.length === 0) return {
|
|
388
|
+
...type,
|
|
389
|
+
optional: true,
|
|
390
|
+
hasDefault: false
|
|
391
|
+
};
|
|
392
|
+
return {
|
|
393
|
+
...type,
|
|
394
|
+
optional: true,
|
|
395
|
+
hasDefault: true,
|
|
396
|
+
defaultValue: rest[0]
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
//#endregion
|
|
400
|
+
//#region src/extension-block.ts
|
|
401
|
+
function findBlockDescriptor(descriptors, keyword) {
|
|
402
|
+
if (descriptors === void 0) return void 0;
|
|
403
|
+
for (const value of Object.values(descriptors)) {
|
|
404
|
+
if (value === void 0) continue;
|
|
405
|
+
if (isAuthoringPslBlockDescriptor(value)) {
|
|
406
|
+
if (value.keyword === keyword) return value;
|
|
407
|
+
continue;
|
|
408
|
+
}
|
|
409
|
+
const nested = findBlockDescriptor(value, keyword);
|
|
410
|
+
if (nested !== void 0) return nested;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
function validateExtensionBlockFromSymbol(input) {
|
|
414
|
+
const refCtx = buildRefResolutionContext(input.symbolTable, input.block);
|
|
415
|
+
return validateExtensionBlock(input.block.block, input.descriptor, input.sourceId, input.codecLookup, refCtx);
|
|
416
|
+
}
|
|
417
|
+
const ZERO_SPAN = {
|
|
418
|
+
start: {
|
|
419
|
+
offset: 0,
|
|
420
|
+
line: 1,
|
|
421
|
+
column: 1
|
|
422
|
+
},
|
|
423
|
+
end: {
|
|
424
|
+
offset: 0,
|
|
425
|
+
line: 1,
|
|
426
|
+
column: 1
|
|
427
|
+
}
|
|
428
|
+
};
|
|
429
|
+
function buildRefResolutionContext(symbolTable, block) {
|
|
430
|
+
const unspecifiedNamespace = makeNamespace(UNSPECIFIED_PSL_NAMESPACE_ID, Object.values(symbolTable.topLevel.models));
|
|
431
|
+
const allNamespaces = [unspecifiedNamespace, ...Object.values(symbolTable.topLevel.namespaces).map((namespace) => makeNamespace(namespace.name, Object.values(namespace.models)))];
|
|
432
|
+
const ownerNamespaceName = findOwnerNamespaceName(symbolTable, block);
|
|
433
|
+
return {
|
|
434
|
+
ownerNamespace: allNamespaces.find((namespace) => namespace.name === ownerNamespaceName) ?? unspecifiedNamespace,
|
|
435
|
+
allNamespaces
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
function makeNamespace(name, models) {
|
|
439
|
+
return makePslNamespace({
|
|
440
|
+
kind: "namespace",
|
|
441
|
+
name,
|
|
442
|
+
entries: makePslNamespaceEntries(models.map((model) => ({
|
|
443
|
+
kind: "model",
|
|
444
|
+
name: model.name,
|
|
445
|
+
fields: [],
|
|
446
|
+
attributes: [],
|
|
447
|
+
span: ZERO_SPAN
|
|
448
|
+
})), [], []),
|
|
449
|
+
span: ZERO_SPAN
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
function findOwnerNamespaceName(symbolTable, block) {
|
|
453
|
+
for (const namespace of Object.values(symbolTable.topLevel.namespaces)) if (Object.values(namespace.blocks).some((candidate) => candidate === block)) return namespace.name;
|
|
454
|
+
return UNSPECIFIED_PSL_NAMESPACE_ID;
|
|
455
|
+
}
|
|
456
|
+
//#endregion
|
|
144
457
|
//#region src/block-reconstruction.ts
|
|
145
458
|
/**
|
|
146
459
|
* Descriptor-free and unknown parameters become `value` stubs so validation can
|
|
@@ -479,6 +792,6 @@ function nodeRange(node, sourceFile) {
|
|
|
479
792
|
};
|
|
480
793
|
}
|
|
481
794
|
//#endregion
|
|
482
|
-
export { buildSymbolTable, findBlockDescriptor, flatPslModels, getPositionalArgument, keywordPslSpan, namespacePslExtensionBlocks, nodePslSpan, parseQuotedStringLiteral, rangeToPslSpan, readResolvedAttribute, readResolvedAttributes, readResolvedConstructorCall, validateExtensionBlockFromSymbol };
|
|
795
|
+
export { bool, buildSymbolTable, entityRef, fieldAttribute, fieldRef, findBlockDescriptor, flatPslModels, getPositionalArgument, identifier, int, interpretAttribute, keywordPslSpan, leafDiagnostic, list, modelAttribute, namespacePslExtensionBlocks, nodePslSpan, oneOf, optional, parseQuotedStringLiteral, rangeToPslSpan, readResolvedAttribute, readResolvedAttributes, readResolvedConstructorCall, record, str, validateExtensionBlockFromSymbol };
|
|
483
796
|
|
|
484
797
|
//# sourceMappingURL=index.mjs.map
|