@zenstackhq/language 3.0.0-beta.7 → 3.0.0-beta.8
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.cjs +69 -44
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +70 -45
- package/dist/index.js.map +1 -1
- package/dist/utils.cjs +5 -11
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +2 -3
- package/dist/utils.d.ts +2 -3
- package/dist/utils.js +4 -9
- package/dist/utils.js.map +1 -1
- package/package.json +5 -5
- package/res/stdlib.zmodel +4 -4
package/dist/index.cjs
CHANGED
|
@@ -5223,10 +5223,6 @@ function isRelationshipField(field) {
|
|
|
5223
5223
|
return isDataModel(field.type.reference?.ref);
|
|
5224
5224
|
}
|
|
5225
5225
|
__name(isRelationshipField, "isRelationshipField");
|
|
5226
|
-
function isFutureExpr(node) {
|
|
5227
|
-
return isInvocationExpr(node) && node.function.ref?.name === "future" && isFromStdlib(node.function.ref);
|
|
5228
|
-
}
|
|
5229
|
-
__name(isFutureExpr, "isFutureExpr");
|
|
5230
5226
|
function isDelegateModel(node) {
|
|
5231
5227
|
return isDataModel(node) && hasAttribute(node, "@@delegate");
|
|
5232
5228
|
}
|
|
@@ -5462,10 +5458,10 @@ function getAuthDecl(decls) {
|
|
|
5462
5458
|
return authModel;
|
|
5463
5459
|
}
|
|
5464
5460
|
__name(getAuthDecl, "getAuthDecl");
|
|
5465
|
-
function
|
|
5466
|
-
return isInvocationExpr(node) && node.function.ref?.name === "
|
|
5461
|
+
function isBeforeInvocation(node) {
|
|
5462
|
+
return isInvocationExpr(node) && node.function.ref?.name === "before" && isFromStdlib(node.function.ref);
|
|
5467
5463
|
}
|
|
5468
|
-
__name(
|
|
5464
|
+
__name(isBeforeInvocation, "isBeforeInvocation");
|
|
5469
5465
|
function isCollectionPredicate(node) {
|
|
5470
5466
|
return isBinaryExpr(node) && [
|
|
5471
5467
|
"?",
|
|
@@ -5697,12 +5693,21 @@ var AttributeApplicationValidator = class {
|
|
|
5697
5693
|
"create",
|
|
5698
5694
|
"read",
|
|
5699
5695
|
"update",
|
|
5696
|
+
"post-update",
|
|
5700
5697
|
"delete",
|
|
5701
5698
|
"all"
|
|
5702
5699
|
], attr, accept);
|
|
5703
5700
|
if ((kind === "create" || kind === "all") && attr.args[1]?.value) {
|
|
5704
5701
|
this.rejectNonOwnedRelationInExpression(attr.args[1].value, accept);
|
|
5705
5702
|
}
|
|
5703
|
+
if (kind !== "post-update" && attr.args[1]?.value) {
|
|
5704
|
+
const beforeCall = import_langium3.AstUtils.streamAst(attr.args[1]?.value).find(isBeforeInvocation);
|
|
5705
|
+
if (beforeCall) {
|
|
5706
|
+
accept("error", `"before()" is only allowed in "post-update" policy rules`, {
|
|
5707
|
+
node: beforeCall
|
|
5708
|
+
});
|
|
5709
|
+
}
|
|
5710
|
+
}
|
|
5706
5711
|
}
|
|
5707
5712
|
rejectNonOwnedRelationInExpression(expr, accept) {
|
|
5708
5713
|
const contextModel = import_langium3.AstUtils.getContainerOfType(expr, isDataModel);
|
|
@@ -5757,8 +5762,8 @@ var AttributeApplicationValidator = class {
|
|
|
5757
5762
|
"all"
|
|
5758
5763
|
], attr, accept);
|
|
5759
5764
|
const expr = attr.args[1]?.value;
|
|
5760
|
-
if (expr && import_langium3.AstUtils.streamAst(expr).some((node) =>
|
|
5761
|
-
accept("error", `"
|
|
5765
|
+
if (expr && import_langium3.AstUtils.streamAst(expr).some((node) => isBeforeInvocation(node))) {
|
|
5766
|
+
accept("error", `"before()" is not allowed in field-level policy rules`, {
|
|
5762
5767
|
node: expr
|
|
5763
5768
|
});
|
|
5764
5769
|
}
|
|
@@ -6519,11 +6524,21 @@ var ExpressionValidator = class {
|
|
|
6519
6524
|
}
|
|
6520
6525
|
}
|
|
6521
6526
|
switch (expr.$type) {
|
|
6527
|
+
case "MemberAccessExpr":
|
|
6528
|
+
this.validateMemberAccessExpr(expr, accept);
|
|
6529
|
+
break;
|
|
6522
6530
|
case "BinaryExpr":
|
|
6523
6531
|
this.validateBinaryExpr(expr, accept);
|
|
6524
6532
|
break;
|
|
6525
6533
|
}
|
|
6526
6534
|
}
|
|
6535
|
+
validateMemberAccessExpr(expr, accept) {
|
|
6536
|
+
if (isBeforeInvocation(expr.operand) && isDataModel(expr.$resolvedType?.decl)) {
|
|
6537
|
+
accept("error", "relation fields cannot be accessed from `before()`", {
|
|
6538
|
+
node: expr
|
|
6539
|
+
});
|
|
6540
|
+
}
|
|
6541
|
+
}
|
|
6527
6542
|
validateBinaryExpr(expr, accept) {
|
|
6528
6543
|
switch (expr.operator) {
|
|
6529
6544
|
case "in": {
|
|
@@ -7046,18 +7061,26 @@ var ZModelDocumentBuilder = class extends import_langium7.DefaultDocumentBuilder
|
|
|
7046
7061
|
static {
|
|
7047
7062
|
__name(this, "ZModelDocumentBuilder");
|
|
7048
7063
|
}
|
|
7049
|
-
|
|
7050
|
-
|
|
7051
|
-
|
|
7052
|
-
|
|
7053
|
-
|
|
7054
|
-
|
|
7055
|
-
|
|
7056
|
-
|
|
7057
|
-
|
|
7058
|
-
|
|
7059
|
-
|
|
7060
|
-
|
|
7064
|
+
constructor(services) {
|
|
7065
|
+
super(services);
|
|
7066
|
+
let validationOptions = this.updateBuildOptions.validation;
|
|
7067
|
+
const stopFlags = {
|
|
7068
|
+
stopAfterLinkingErrors: true,
|
|
7069
|
+
stopAfterLexingErrors: true,
|
|
7070
|
+
stopAfterParsingErrors: true
|
|
7071
|
+
};
|
|
7072
|
+
if (validationOptions === true) {
|
|
7073
|
+
validationOptions = stopFlags;
|
|
7074
|
+
} else if (typeof validationOptions === "object") {
|
|
7075
|
+
validationOptions = {
|
|
7076
|
+
...validationOptions,
|
|
7077
|
+
...stopFlags
|
|
7078
|
+
};
|
|
7079
|
+
}
|
|
7080
|
+
this.updateBuildOptions = {
|
|
7081
|
+
...this.updateBuildOptions,
|
|
7082
|
+
validation: validationOptions
|
|
7083
|
+
};
|
|
7061
7084
|
}
|
|
7062
7085
|
};
|
|
7063
7086
|
|
|
@@ -7084,21 +7107,19 @@ var ZModelLinker = class extends import_langium8.DefaultLinker {
|
|
|
7084
7107
|
}
|
|
7085
7108
|
document.state = import_langium8.DocumentState.Linked;
|
|
7086
7109
|
}
|
|
7087
|
-
linkReference(
|
|
7088
|
-
|
|
7110
|
+
linkReference(refInfo, document, extraScopes) {
|
|
7111
|
+
const defaultRef = refInfo.reference;
|
|
7112
|
+
if (defaultRef._ref) {
|
|
7113
|
+
return;
|
|
7114
|
+
}
|
|
7115
|
+
if (this.resolveFromScopeProviders(refInfo.reference, document, extraScopes)) {
|
|
7089
7116
|
return;
|
|
7090
7117
|
}
|
|
7091
|
-
|
|
7092
|
-
this.doLink({
|
|
7093
|
-
reference,
|
|
7094
|
-
container,
|
|
7095
|
-
property
|
|
7096
|
-
}, document);
|
|
7118
|
+
this.doLink(refInfo, document);
|
|
7097
7119
|
}
|
|
7098
7120
|
//#endregion
|
|
7099
7121
|
//#region Expression type resolving
|
|
7100
|
-
resolveFromScopeProviders(
|
|
7101
|
-
const reference = node[property];
|
|
7122
|
+
resolveFromScopeProviders(reference, document, providers) {
|
|
7102
7123
|
for (const provider of providers) {
|
|
7103
7124
|
const target = provider(reference.$refText);
|
|
7104
7125
|
if (target) {
|
|
@@ -7227,7 +7248,11 @@ var ZModelLinker = class extends import_langium8.DefaultLinker {
|
|
|
7227
7248
|
}
|
|
7228
7249
|
}
|
|
7229
7250
|
resolveInvocation(node, document, extraScopes) {
|
|
7230
|
-
this.linkReference(
|
|
7251
|
+
this.linkReference({
|
|
7252
|
+
reference: node.function,
|
|
7253
|
+
container: node,
|
|
7254
|
+
property: "function"
|
|
7255
|
+
}, document, extraScopes);
|
|
7231
7256
|
node.args.forEach((arg) => this.resolve(arg, document, extraScopes));
|
|
7232
7257
|
if (node.function.ref) {
|
|
7233
7258
|
const funcDecl = node.function.ref;
|
|
@@ -7240,7 +7265,7 @@ var ZModelLinker = class extends import_langium8.DefaultLinker {
|
|
|
7240
7265
|
nullable: true
|
|
7241
7266
|
};
|
|
7242
7267
|
}
|
|
7243
|
-
} else if (
|
|
7268
|
+
} else if (isBeforeInvocation(node)) {
|
|
7244
7269
|
node.$resolvedType = {
|
|
7245
7270
|
decl: getContainingDataModel(node)
|
|
7246
7271
|
};
|
|
@@ -7304,7 +7329,7 @@ var ZModelLinker = class extends import_langium8.DefaultLinker {
|
|
|
7304
7329
|
if (isArrayExpr(node.value)) {
|
|
7305
7330
|
node.value.items.forEach((item) => {
|
|
7306
7331
|
if (isReferenceExpr(item)) {
|
|
7307
|
-
const resolved2 = this.resolveFromScopeProviders(item
|
|
7332
|
+
const resolved2 = this.resolveFromScopeProviders(item.target, document, [
|
|
7308
7333
|
scopeProvider
|
|
7309
7334
|
]);
|
|
7310
7335
|
if (resolved2) {
|
|
@@ -7318,7 +7343,7 @@ var ZModelLinker = class extends import_langium8.DefaultLinker {
|
|
|
7318
7343
|
this.resolveToBuiltinTypeOrDecl(node.value, node.value.items[0].$resolvedType.decl, true);
|
|
7319
7344
|
}
|
|
7320
7345
|
} else if (isReferenceExpr(node.value)) {
|
|
7321
|
-
const resolved2 = this.resolveFromScopeProviders(node.value
|
|
7346
|
+
const resolved2 = this.resolveFromScopeProviders(node.value.target, document, [
|
|
7322
7347
|
scopeProvider
|
|
7323
7348
|
]);
|
|
7324
7349
|
if (resolved2) {
|
|
@@ -7370,13 +7395,9 @@ var ZModelLinker = class extends import_langium8.DefaultLinker {
|
|
|
7370
7395
|
this.resolveDefault(node, document, scopes);
|
|
7371
7396
|
}
|
|
7372
7397
|
resolveDefault(node, document, extraScopes) {
|
|
7373
|
-
|
|
7374
|
-
|
|
7375
|
-
|
|
7376
|
-
this.linkReference(node, property, document, extraScopes);
|
|
7377
|
-
}
|
|
7378
|
-
}
|
|
7379
|
-
}
|
|
7398
|
+
import_langium8.AstUtils.streamReferences(node).forEach((ref) => {
|
|
7399
|
+
this.linkReference(ref, document, extraScopes);
|
|
7400
|
+
});
|
|
7380
7401
|
for (const child of import_langium8.AstUtils.streamContents(node)) {
|
|
7381
7402
|
this.resolve(child, document, extraScopes);
|
|
7382
7403
|
}
|
|
@@ -7517,7 +7538,7 @@ var ZModelScopeProvider = class extends import_langium9.DefaultScopeProvider {
|
|
|
7517
7538
|
if (isAuthInvocation(operand)) {
|
|
7518
7539
|
return this.createScopeForAuth(node, globalScope);
|
|
7519
7540
|
}
|
|
7520
|
-
if (
|
|
7541
|
+
if (isBeforeInvocation(operand)) {
|
|
7521
7542
|
return this.createScopeForContainingModel(node, globalScope);
|
|
7522
7543
|
}
|
|
7523
7544
|
return import_langium9.EMPTY_SCOPE;
|
|
@@ -7786,7 +7807,11 @@ async function loadDocument(fileName, pluginModelFiles = []) {
|
|
|
7786
7807
|
document,
|
|
7787
7808
|
...importedDocuments
|
|
7788
7809
|
], {
|
|
7789
|
-
validation:
|
|
7810
|
+
validation: {
|
|
7811
|
+
stopAfterLexingErrors: true,
|
|
7812
|
+
stopAfterParsingErrors: true,
|
|
7813
|
+
stopAfterLinkingErrors: true
|
|
7814
|
+
}
|
|
7790
7815
|
});
|
|
7791
7816
|
const diagnostics = langiumDocuments.all.flatMap((doc) => (doc.diagnostics ?? []).map((diag) => ({
|
|
7792
7817
|
doc,
|