@zenstackhq/language 3.0.0-beta.20 → 3.0.0-beta.21
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 +77 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +77 -24
- package/dist/index.js.map +1 -1
- package/dist/utils.cjs +7 -1
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +4 -3
- package/dist/utils.d.ts +4 -3
- package/dist/utils.js +6 -1
- package/dist/utils.js.map +1 -1
- package/package.json +5 -5
- package/res/stdlib.zmodel +6 -6
package/dist/index.js
CHANGED
|
@@ -5267,7 +5267,7 @@ function getRecursiveBases(decl, includeDelegate = true, seen = /* @__PURE__ */
|
|
|
5267
5267
|
] : []
|
|
5268
5268
|
];
|
|
5269
5269
|
bases.forEach((base) => {
|
|
5270
|
-
const baseDecl = decl.$container.declarations.find((d) => isTypeDef(d) || isDataModel(d) && d.name === base.$refText);
|
|
5270
|
+
const baseDecl = decl.$container.declarations.find((d) => (isTypeDef(d) || isDataModel(d)) && d.name === base.$refText);
|
|
5271
5271
|
if (baseDecl) {
|
|
5272
5272
|
if (!includeDelegate && isDelegateModel(baseDecl)) {
|
|
5273
5273
|
return;
|
|
@@ -5390,6 +5390,10 @@ function getArray(expr) {
|
|
|
5390
5390
|
return isArrayExpr(expr) || isConfigArrayExpr(expr) ? expr.items : void 0;
|
|
5391
5391
|
}
|
|
5392
5392
|
__name(getArray, "getArray");
|
|
5393
|
+
function getAttributeArg(attr, name) {
|
|
5394
|
+
return attr.args.find((arg) => arg.$resolvedParam?.name === name)?.value;
|
|
5395
|
+
}
|
|
5396
|
+
__name(getAttributeArg, "getAttributeArg");
|
|
5393
5397
|
function getFunctionExpressionContext(funcDecl) {
|
|
5394
5398
|
const funcAllowedContext = [];
|
|
5395
5399
|
const funcAttr = funcDecl.attributes.find((attr) => attr.decl.$refText === "@@@expressionContext");
|
|
@@ -5658,6 +5662,7 @@ function findRootNode(node) {
|
|
|
5658
5662
|
__name(findRootNode, "findRootNode");
|
|
5659
5663
|
|
|
5660
5664
|
// src/validators/attribute-application-validator.ts
|
|
5665
|
+
import { invariant } from "@zenstackhq/common-helpers";
|
|
5661
5666
|
import { AstUtils as AstUtils2 } from "langium";
|
|
5662
5667
|
import pluralize from "pluralize";
|
|
5663
5668
|
function _ts_decorate(decorators, target, key, desc) {
|
|
@@ -5878,7 +5883,7 @@ var AttributeApplicationValidator = class {
|
|
|
5878
5883
|
}
|
|
5879
5884
|
}
|
|
5880
5885
|
_checkConstraint(attr, accept) {
|
|
5881
|
-
const fields = attr
|
|
5886
|
+
const fields = getAttributeArg(attr, "fields");
|
|
5882
5887
|
const attrName = attr.decl.ref?.name;
|
|
5883
5888
|
if (!fields) {
|
|
5884
5889
|
accept("error", `expects an array of field references`, {
|
|
@@ -5918,6 +5923,24 @@ var AttributeApplicationValidator = class {
|
|
|
5918
5923
|
});
|
|
5919
5924
|
}
|
|
5920
5925
|
}
|
|
5926
|
+
_checkSchema(attr, accept) {
|
|
5927
|
+
const schemaName = getStringLiteral(attr.args[0]?.value);
|
|
5928
|
+
invariant(schemaName, `@@schema expects a string literal`);
|
|
5929
|
+
const zmodel = AstUtils2.getContainerOfType(attr, isModel);
|
|
5930
|
+
const datasource = zmodel.declarations.find(isDataSource);
|
|
5931
|
+
if (datasource) {
|
|
5932
|
+
let found = false;
|
|
5933
|
+
const schemas = datasource.fields.find((f) => f.name === "schemas");
|
|
5934
|
+
if (schemas && isConfigArrayExpr(schemas.value)) {
|
|
5935
|
+
found = schemas.value.items.some((item) => isLiteralExpr(item) && item.value === schemaName);
|
|
5936
|
+
}
|
|
5937
|
+
if (!found) {
|
|
5938
|
+
accept("error", `Schema "${schemaName}" is not defined in the datasource`, {
|
|
5939
|
+
node: attr
|
|
5940
|
+
});
|
|
5941
|
+
}
|
|
5942
|
+
}
|
|
5943
|
+
}
|
|
5921
5944
|
validatePolicyKinds(kind, candidates, attr, accept) {
|
|
5922
5945
|
const items = kind.split(",").map((x) => x.trim());
|
|
5923
5946
|
items.forEach((item) => {
|
|
@@ -5970,6 +5993,15 @@ _ts_decorate([
|
|
|
5970
5993
|
]),
|
|
5971
5994
|
_ts_metadata("design:returntype", void 0)
|
|
5972
5995
|
], AttributeApplicationValidator.prototype, "_checkConstraint", null);
|
|
5996
|
+
_ts_decorate([
|
|
5997
|
+
check("@@schema"),
|
|
5998
|
+
_ts_metadata("design:type", Function),
|
|
5999
|
+
_ts_metadata("design:paramtypes", [
|
|
6000
|
+
typeof AttributeApplication === "undefined" ? Object : AttributeApplication,
|
|
6001
|
+
typeof ValidationAcceptor === "undefined" ? Object : ValidationAcceptor
|
|
6002
|
+
]),
|
|
6003
|
+
_ts_metadata("design:returntype", void 0)
|
|
6004
|
+
], AttributeApplicationValidator.prototype, "_checkSchema", null);
|
|
5973
6005
|
function assignableToAttributeParam(arg, param, attr) {
|
|
5974
6006
|
const argResolvedType = arg.$resolvedType;
|
|
5975
6007
|
if (!argResolvedType) {
|
|
@@ -6103,7 +6135,7 @@ var AttributeValidator = class {
|
|
|
6103
6135
|
};
|
|
6104
6136
|
|
|
6105
6137
|
// src/validators/datamodel-validator.ts
|
|
6106
|
-
import { invariant } from "@zenstackhq/common-helpers";
|
|
6138
|
+
import { invariant as invariant2 } from "@zenstackhq/common-helpers";
|
|
6107
6139
|
import { AstUtils as AstUtils3 } from "langium";
|
|
6108
6140
|
|
|
6109
6141
|
// src/validators/common.ts
|
|
@@ -6474,7 +6506,7 @@ var DataModelValidator = class {
|
|
|
6474
6506
|
if (!model.baseModel) {
|
|
6475
6507
|
return;
|
|
6476
6508
|
}
|
|
6477
|
-
|
|
6509
|
+
invariant2(model.baseModel.ref, "baseModel must be resolved");
|
|
6478
6510
|
if (!isDelegateModel(model.baseModel.ref)) {
|
|
6479
6511
|
accept("error", `Model ${model.baseModel.$refText} cannot be extended because it's not a delegate model`, {
|
|
6480
6512
|
node: model,
|
|
@@ -6496,7 +6528,7 @@ var DataModelValidator = class {
|
|
|
6496
6528
|
}
|
|
6497
6529
|
seen.push(current);
|
|
6498
6530
|
if (current.baseModel) {
|
|
6499
|
-
|
|
6531
|
+
invariant2(current.baseModel.ref, "baseModel must be resolved");
|
|
6500
6532
|
todo.push(current.baseModel.ref);
|
|
6501
6533
|
}
|
|
6502
6534
|
}
|
|
@@ -6527,7 +6559,6 @@ var DataSourceValidator = class {
|
|
|
6527
6559
|
validateDuplicatedDeclarations(ds, ds.fields, accept);
|
|
6528
6560
|
this.validateProvider(ds, accept);
|
|
6529
6561
|
this.validateUrl(ds, accept);
|
|
6530
|
-
this.validateRelationMode(ds, accept);
|
|
6531
6562
|
}
|
|
6532
6563
|
validateProvider(ds, accept) {
|
|
6533
6564
|
const provider = ds.fields.find((f) => f.name === "provider");
|
|
@@ -6537,16 +6568,52 @@ var DataSourceValidator = class {
|
|
|
6537
6568
|
});
|
|
6538
6569
|
return;
|
|
6539
6570
|
}
|
|
6540
|
-
const
|
|
6541
|
-
if (!
|
|
6571
|
+
const providerValue = getStringLiteral(provider.value);
|
|
6572
|
+
if (!providerValue) {
|
|
6542
6573
|
accept("error", '"provider" must be set to a string literal', {
|
|
6543
6574
|
node: provider.value
|
|
6544
6575
|
});
|
|
6545
|
-
} else if (!SUPPORTED_PROVIDERS.includes(
|
|
6546
|
-
accept("error", `Provider "${
|
|
6576
|
+
} else if (!SUPPORTED_PROVIDERS.includes(providerValue)) {
|
|
6577
|
+
accept("error", `Provider "${providerValue}" is not supported. Choose from ${SUPPORTED_PROVIDERS.map((p) => '"' + p + '"').join(" | ")}.`, {
|
|
6547
6578
|
node: provider.value
|
|
6548
6579
|
});
|
|
6549
6580
|
}
|
|
6581
|
+
const defaultSchemaField = ds.fields.find((f) => f.name === "defaultSchema");
|
|
6582
|
+
let defaultSchemaValue;
|
|
6583
|
+
if (defaultSchemaField) {
|
|
6584
|
+
if (providerValue !== "postgresql") {
|
|
6585
|
+
accept("error", '"defaultSchema" is only supported for "postgresql" provider', {
|
|
6586
|
+
node: defaultSchemaField
|
|
6587
|
+
});
|
|
6588
|
+
}
|
|
6589
|
+
defaultSchemaValue = getStringLiteral(defaultSchemaField.value);
|
|
6590
|
+
if (!defaultSchemaValue) {
|
|
6591
|
+
accept("error", '"defaultSchema" must be a string literal', {
|
|
6592
|
+
node: defaultSchemaField.value
|
|
6593
|
+
});
|
|
6594
|
+
}
|
|
6595
|
+
}
|
|
6596
|
+
const schemasField = ds.fields.find((f) => f.name === "schemas");
|
|
6597
|
+
if (schemasField) {
|
|
6598
|
+
if (providerValue !== "postgresql") {
|
|
6599
|
+
accept("error", '"schemas" is only supported for "postgresql" provider', {
|
|
6600
|
+
node: schemasField
|
|
6601
|
+
});
|
|
6602
|
+
}
|
|
6603
|
+
const schemasValue = schemasField.value;
|
|
6604
|
+
if (!isConfigArrayExpr(schemasValue) || !schemasValue.items.every((e) => isLiteralExpr(e) && typeof getStringLiteral(e) === "string")) {
|
|
6605
|
+
accept("error", '"schemas" must be an array of string literals', {
|
|
6606
|
+
node: schemasField
|
|
6607
|
+
});
|
|
6608
|
+
} else if (
|
|
6609
|
+
// validate `defaultSchema` is included in `schemas`
|
|
6610
|
+
defaultSchemaValue && !schemasValue.items.some((e) => getStringLiteral(e) === defaultSchemaValue)
|
|
6611
|
+
) {
|
|
6612
|
+
accept("error", `"${defaultSchemaValue}" must be included in the "schemas" array`, {
|
|
6613
|
+
node: schemasField
|
|
6614
|
+
});
|
|
6615
|
+
}
|
|
6616
|
+
}
|
|
6550
6617
|
}
|
|
6551
6618
|
validateUrl(ds, accept) {
|
|
6552
6619
|
const urlField = ds.fields.find((f) => f.name === "url");
|
|
@@ -6560,20 +6627,6 @@ var DataSourceValidator = class {
|
|
|
6560
6627
|
});
|
|
6561
6628
|
}
|
|
6562
6629
|
}
|
|
6563
|
-
validateRelationMode(ds, accept) {
|
|
6564
|
-
const field = ds.fields.find((f) => f.name === "relationMode");
|
|
6565
|
-
if (field) {
|
|
6566
|
-
const val = getStringLiteral(field.value);
|
|
6567
|
-
if (!val || ![
|
|
6568
|
-
"foreignKeys",
|
|
6569
|
-
"prisma"
|
|
6570
|
-
].includes(val)) {
|
|
6571
|
-
accept("error", '"relationMode" must be set to "foreignKeys" or "prisma"', {
|
|
6572
|
-
node: field.value
|
|
6573
|
-
});
|
|
6574
|
-
}
|
|
6575
|
-
}
|
|
6576
|
-
}
|
|
6577
6630
|
};
|
|
6578
6631
|
|
|
6579
6632
|
// src/validators/enum-validator.ts
|