@zenstackhq/language 3.7.0-beta.1 → 3.7.1
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 +78 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +77 -8
- package/dist/index.mjs.map +1 -1
- package/dist/{utils-BB6L7ug2.mjs → utils-CCU55PfR.mjs} +14 -3
- package/dist/utils-CCU55PfR.mjs.map +1 -0
- package/dist/{utils-CfXGZkv7.cjs → utils-b3dJKmYr.cjs} +18 -1
- package/dist/utils-b3dJKmYr.cjs.map +1 -0
- package/dist/utils.cjs +2 -1
- package/dist/utils.d.cts +6 -1
- package/dist/utils.d.mts +6 -1
- package/dist/utils.mjs +2 -2
- package/package.json +6 -6
- package/res/stdlib.zmodel +22 -1
- package/dist/utils-BB6L7ug2.mjs.map +0 -1
- package/dist/utils-CfXGZkv7.cjs.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_ast = require("./ast-Clidp86c.cjs");
|
|
3
3
|
const require_ast$1 = require("./ast.cjs");
|
|
4
|
-
const require_utils = require("./utils-
|
|
4
|
+
const require_utils = require("./utils-b3dJKmYr.cjs");
|
|
5
5
|
let _zenstackhq_common_helpers = require("@zenstackhq/common-helpers");
|
|
6
6
|
let langium = require("langium");
|
|
7
7
|
let node_fs = require("node:fs");
|
|
@@ -4317,6 +4317,18 @@ var AttributeApplicationValidator = class {
|
|
|
4317
4317
|
});
|
|
4318
4318
|
} else accept("error", `Expected an array of field references`, { node: fields });
|
|
4319
4319
|
}
|
|
4320
|
+
_checkFuzzy(attr, accept) {
|
|
4321
|
+
const zmodel = langium.AstUtils.getContainerOfType(attr, require_ast.isModel);
|
|
4322
|
+
if (!zmodel) return;
|
|
4323
|
+
const provider = require_utils.getDataSourceProvider(zmodel);
|
|
4324
|
+
if (provider && provider !== "postgresql") accept("error", `\`@fuzzy\` is only supported for the \`postgresql\` provider`, { node: attr });
|
|
4325
|
+
}
|
|
4326
|
+
_checkFullText(attr, accept) {
|
|
4327
|
+
const zmodel = langium.AstUtils.getContainerOfType(attr, require_ast.isModel);
|
|
4328
|
+
if (!zmodel) return;
|
|
4329
|
+
const provider = require_utils.getDataSourceProvider(zmodel);
|
|
4330
|
+
if (provider && provider !== "postgresql") accept("error", `\`@fullText\` is only supported for the \`postgresql\` provider`, { node: attr });
|
|
4331
|
+
}
|
|
4320
4332
|
_checkSchema(attr, accept) {
|
|
4321
4333
|
const schemaName = require_utils.getStringLiteral(attr.args[0]?.value);
|
|
4322
4334
|
(0, _zenstackhq_common_helpers.invariant)(schemaName, `@@schema expects a string literal`);
|
|
@@ -4370,6 +4382,18 @@ __decorate([
|
|
|
4370
4382
|
__decorateMetadata("design:paramtypes", [Object, Object]),
|
|
4371
4383
|
__decorateMetadata("design:returntype", void 0)
|
|
4372
4384
|
], AttributeApplicationValidator.prototype, "_checkConstraint", null);
|
|
4385
|
+
__decorate([
|
|
4386
|
+
check("@fuzzy"),
|
|
4387
|
+
__decorateMetadata("design:type", Function),
|
|
4388
|
+
__decorateMetadata("design:paramtypes", [Object, Object]),
|
|
4389
|
+
__decorateMetadata("design:returntype", void 0)
|
|
4390
|
+
], AttributeApplicationValidator.prototype, "_checkFuzzy", null);
|
|
4391
|
+
__decorate([
|
|
4392
|
+
check("@fullText"),
|
|
4393
|
+
__decorateMetadata("design:type", Function),
|
|
4394
|
+
__decorateMetadata("design:paramtypes", [Object, Object]),
|
|
4395
|
+
__decorateMetadata("design:returntype", void 0)
|
|
4396
|
+
], AttributeApplicationValidator.prototype, "_checkFullText", null);
|
|
4373
4397
|
__decorate([
|
|
4374
4398
|
check("@@schema"),
|
|
4375
4399
|
__decorateMetadata("design:type", Function),
|
|
@@ -4553,6 +4577,7 @@ var DataModelValidator = class {
|
|
|
4553
4577
|
this.validateFields(dm, accept);
|
|
4554
4578
|
if (dm.mixins.length > 0) this.validateMixins(dm, accept);
|
|
4555
4579
|
this.validateInherits(dm, accept);
|
|
4580
|
+
this.validateDelegateMap(dm, accept);
|
|
4556
4581
|
}
|
|
4557
4582
|
validateFields(dm, accept) {
|
|
4558
4583
|
const allFields = require_utils.getAllFields(dm);
|
|
@@ -4783,6 +4808,57 @@ var DataModelValidator = class {
|
|
|
4783
4808
|
todo.push(...current.mixins.map((mixin) => mixin.ref));
|
|
4784
4809
|
}
|
|
4785
4810
|
}
|
|
4811
|
+
validateDelegateMap(dm, accept) {
|
|
4812
|
+
const delegateMapAttrs = dm.attributes.filter((attr) => attr.decl.$refText === "@@delegateMap");
|
|
4813
|
+
if (delegateMapAttrs.length > 1) accept("error", "Model can include at most one @@delegateMap attribute", { node: delegateMapAttrs[1] });
|
|
4814
|
+
const delegateMapAttr = delegateMapAttrs[0];
|
|
4815
|
+
if (delegateMapAttr) {
|
|
4816
|
+
if (!dm.baseModel) accept("error", "`@@delegateMap` can only be used on models that extend a delegate base model", { node: delegateMapAttr });
|
|
4817
|
+
else if (dm.baseModel.ref) this.validateDelegateMapValue(dm.baseModel.ref, delegateMapAttr, accept);
|
|
4818
|
+
}
|
|
4819
|
+
if (!require_utils.hasAttribute(dm, "@@delegate")) return;
|
|
4820
|
+
const subModels = dm.$container.declarations.filter(require_ast.isDataModel).filter((model) => model.baseModel?.ref === dm);
|
|
4821
|
+
if (subModels.length === 0) return;
|
|
4822
|
+
const seen = /* @__PURE__ */ new Map();
|
|
4823
|
+
subModels.forEach((model) => {
|
|
4824
|
+
const value = this.getDelegateMapRawValue(model) ?? model.name;
|
|
4825
|
+
const existing = seen.get(value);
|
|
4826
|
+
if (existing) accept("error", `Duplicate @@delegateMap value "${value}" on models "${existing.name}" and "${model.name}"`, { node: model });
|
|
4827
|
+
else seen.set(value, model);
|
|
4828
|
+
});
|
|
4829
|
+
}
|
|
4830
|
+
getDelegateMapRawValue(dm) {
|
|
4831
|
+
const valueExpr = dm.attributes.find((attr) => attr.decl.$refText === "@@delegateMap")?.args[0]?.value;
|
|
4832
|
+
if (!valueExpr) return;
|
|
4833
|
+
if (require_ast.isStringLiteral(valueExpr)) return valueExpr.value;
|
|
4834
|
+
if (require_utils.isEnumFieldReference(valueExpr)) return valueExpr.target.ref?.name;
|
|
4835
|
+
}
|
|
4836
|
+
validateDelegateMapValue(baseModel, attr, accept) {
|
|
4837
|
+
const delegateMapValueExpr = attr.args[0]?.value;
|
|
4838
|
+
if (!delegateMapValueExpr) {
|
|
4839
|
+
accept("error", "`@@delegateMap` expects a value", { node: attr });
|
|
4840
|
+
return;
|
|
4841
|
+
}
|
|
4842
|
+
const delegateAttr = require_utils.getAttribute(baseModel, "@@delegate");
|
|
4843
|
+
const discriminatorArg = delegateAttr && require_utils.getAttributeArg(delegateAttr, "discriminator");
|
|
4844
|
+
const discriminatorRef = discriminatorArg && require_ast.isReferenceExpr(discriminatorArg) ? discriminatorArg.target.ref : void 0;
|
|
4845
|
+
if (!discriminatorRef || !require_ast.isDataField(discriminatorRef)) return;
|
|
4846
|
+
const discriminatorType = discriminatorRef.type;
|
|
4847
|
+
const discriminatorEnum = discriminatorType.reference?.ref;
|
|
4848
|
+
if (require_utils.isEnumFieldReference(delegateMapValueExpr)) {
|
|
4849
|
+
if (!require_ast.isEnum(discriminatorEnum)) {
|
|
4850
|
+
accept("error", "`@@delegateMap` enum value cannot be used when the discriminator field is String", { node: delegateMapValueExpr });
|
|
4851
|
+
return;
|
|
4852
|
+
}
|
|
4853
|
+
if (delegateMapValueExpr.target.ref?.$container !== discriminatorEnum) accept("error", "`@@delegateMap` enum value must come from the discriminator enum type", { node: delegateMapValueExpr });
|
|
4854
|
+
return;
|
|
4855
|
+
}
|
|
4856
|
+
if (require_ast.isStringLiteral(delegateMapValueExpr)) {
|
|
4857
|
+
if (discriminatorType.type !== "String") accept("error", "`@@delegateMap` string value must match a String discriminator field", { node: delegateMapValueExpr });
|
|
4858
|
+
return;
|
|
4859
|
+
}
|
|
4860
|
+
accept("error", "`@@delegateMap` expects a string literal or enum value", { node: delegateMapValueExpr });
|
|
4861
|
+
}
|
|
4786
4862
|
};
|
|
4787
4863
|
//#endregion
|
|
4788
4864
|
//#region src/validators/datasource-validator.ts
|
|
@@ -6884,7 +6960,7 @@ function validationAfterImportMerge(model) {
|
|
|
6884
6960
|
if (dataSources.length === 0) errors.push("Validation error: schema must have a datasource declaration");
|
|
6885
6961
|
else if (dataSources.length > 1) errors.push("Validation error: multiple datasource declarations are not allowed");
|
|
6886
6962
|
if (require_utils.getDataModelAndTypeDefs(model, true).filter((d) => require_utils.hasAttribute(d, "@@auth")).length > 1) errors.push("Validation error: Multiple `@@auth` declarations are not allowed");
|
|
6887
|
-
const provider = getDataSourceProvider(model);
|
|
6963
|
+
const provider = require_utils.getDataSourceProvider(model);
|
|
6888
6964
|
(0, _zenstackhq_common_helpers.invariant)(provider !== void 0, "Datasource provider should be defined at this point");
|
|
6889
6965
|
for (const decl of model.declarations.filter(require_ast.isDataModel)) {
|
|
6890
6966
|
const fields = require_utils.getAllFields(decl, true);
|
|
@@ -6912,13 +6988,6 @@ async function formatDocument(content) {
|
|
|
6912
6988
|
});
|
|
6913
6989
|
return langium.TextDocument.applyEdits(document.textDocument, edits);
|
|
6914
6990
|
}
|
|
6915
|
-
function getDataSourceProvider(model) {
|
|
6916
|
-
const dataSource = model.declarations.find(require_ast.isDataSource);
|
|
6917
|
-
if (!dataSource) return;
|
|
6918
|
-
const provider = dataSource?.fields.find((f) => f.name === "provider");
|
|
6919
|
-
if (!provider) return;
|
|
6920
|
-
return require_utils.getLiteral(provider.value);
|
|
6921
|
-
}
|
|
6922
6991
|
//#endregion
|
|
6923
6992
|
exports.ZModelCodeGenerator = ZModelCodeGenerator;
|
|
6924
6993
|
exports.ZModelLanguageMetaData = ZModelLanguageMetaData;
|