@zenstackhq/language 3.0.0-alpha.14 → 3.0.0-alpha.16
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 +140 -56
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +141 -57
- package/dist/index.js.map +1 -1
- package/dist/utils.cjs +24 -25
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +15 -5
- package/dist/utils.d.ts +15 -5
- package/dist/utils.js +22 -30
- package/dist/utils.js.map +1 -1
- package/package.json +6 -4
package/dist/index.cjs
CHANGED
|
@@ -46,39 +46,6 @@ var import_node_fs3 = __toESM(require("fs"), 1);
|
|
|
46
46
|
var import_node_path2 = __toESM(require("path"), 1);
|
|
47
47
|
var import_node_url2 = require("url");
|
|
48
48
|
|
|
49
|
-
// src/constants.ts
|
|
50
|
-
var SUPPORTED_PROVIDERS = [
|
|
51
|
-
"sqlite",
|
|
52
|
-
"postgresql"
|
|
53
|
-
];
|
|
54
|
-
var SCALAR_TYPES = [
|
|
55
|
-
"String",
|
|
56
|
-
"Int",
|
|
57
|
-
"Float",
|
|
58
|
-
"Decimal",
|
|
59
|
-
"BigInt",
|
|
60
|
-
"Boolean",
|
|
61
|
-
"Bytes",
|
|
62
|
-
"DateTime"
|
|
63
|
-
];
|
|
64
|
-
var STD_LIB_MODULE_NAME = "stdlib.zmodel";
|
|
65
|
-
var PLUGIN_MODULE_NAME = "plugin.zmodel";
|
|
66
|
-
var IssueCodes = /* @__PURE__ */ function(IssueCodes2) {
|
|
67
|
-
IssueCodes2["MissingOppositeRelation"] = "miss-opposite-relation";
|
|
68
|
-
return IssueCodes2;
|
|
69
|
-
}({});
|
|
70
|
-
var ExpressionContext = /* @__PURE__ */ function(ExpressionContext2) {
|
|
71
|
-
ExpressionContext2["DefaultValue"] = "DefaultValue";
|
|
72
|
-
ExpressionContext2["AccessPolicy"] = "AccessPolicy";
|
|
73
|
-
ExpressionContext2["ValidationRule"] = "ValidationRule";
|
|
74
|
-
ExpressionContext2["Index"] = "Index";
|
|
75
|
-
return ExpressionContext2;
|
|
76
|
-
}({});
|
|
77
|
-
|
|
78
|
-
// src/module.ts
|
|
79
|
-
var import_langium10 = require("langium");
|
|
80
|
-
var import_lsp = require("langium/lsp");
|
|
81
|
-
|
|
82
49
|
// src/generated/ast.ts
|
|
83
50
|
var langium = __toESM(require("langium"), 1);
|
|
84
51
|
var AbstractDeclaration = "AbstractDeclaration";
|
|
@@ -1077,6 +1044,39 @@ var ZModelAstReflection = class extends langium.AbstractAstReflection {
|
|
|
1077
1044
|
};
|
|
1078
1045
|
var reflection = new ZModelAstReflection();
|
|
1079
1046
|
|
|
1047
|
+
// src/constants.ts
|
|
1048
|
+
var SUPPORTED_PROVIDERS = [
|
|
1049
|
+
"sqlite",
|
|
1050
|
+
"postgresql"
|
|
1051
|
+
];
|
|
1052
|
+
var SCALAR_TYPES = [
|
|
1053
|
+
"String",
|
|
1054
|
+
"Int",
|
|
1055
|
+
"Float",
|
|
1056
|
+
"Decimal",
|
|
1057
|
+
"BigInt",
|
|
1058
|
+
"Boolean",
|
|
1059
|
+
"Bytes",
|
|
1060
|
+
"DateTime"
|
|
1061
|
+
];
|
|
1062
|
+
var STD_LIB_MODULE_NAME = "stdlib.zmodel";
|
|
1063
|
+
var PLUGIN_MODULE_NAME = "plugin.zmodel";
|
|
1064
|
+
var IssueCodes = /* @__PURE__ */ function(IssueCodes2) {
|
|
1065
|
+
IssueCodes2["MissingOppositeRelation"] = "miss-opposite-relation";
|
|
1066
|
+
return IssueCodes2;
|
|
1067
|
+
}({});
|
|
1068
|
+
var ExpressionContext = /* @__PURE__ */ function(ExpressionContext2) {
|
|
1069
|
+
ExpressionContext2["DefaultValue"] = "DefaultValue";
|
|
1070
|
+
ExpressionContext2["AccessPolicy"] = "AccessPolicy";
|
|
1071
|
+
ExpressionContext2["ValidationRule"] = "ValidationRule";
|
|
1072
|
+
ExpressionContext2["Index"] = "Index";
|
|
1073
|
+
return ExpressionContext2;
|
|
1074
|
+
}({});
|
|
1075
|
+
|
|
1076
|
+
// src/module.ts
|
|
1077
|
+
var import_langium10 = require("langium");
|
|
1078
|
+
var import_lsp = require("langium/lsp");
|
|
1079
|
+
|
|
1080
1080
|
// src/generated/grammar.ts
|
|
1081
1081
|
var import_langium = require("langium");
|
|
1082
1082
|
var loadedZModelGrammar;
|
|
@@ -5432,34 +5432,24 @@ function resolveImport(documents, imp) {
|
|
|
5432
5432
|
}
|
|
5433
5433
|
__name(resolveImport, "resolveImport");
|
|
5434
5434
|
function resolveImportUri(imp) {
|
|
5435
|
-
if (!imp.path)
|
|
5436
|
-
|
|
5437
|
-
imp.path += ".zmodel";
|
|
5438
|
-
}
|
|
5439
|
-
if (!imp.path.startsWith(".") && // Respect relative paths
|
|
5440
|
-
!import_path.default.isAbsolute(imp.path)) {
|
|
5441
|
-
const contextPath = imp.$container.$document ? import_path.default.dirname(imp.$container.$document.uri.fsPath) : process.cwd();
|
|
5442
|
-
imp.path = findNodeModulesFile(imp.path, contextPath) ?? imp.path;
|
|
5435
|
+
if (!imp.path) {
|
|
5436
|
+
return void 0;
|
|
5443
5437
|
}
|
|
5444
5438
|
const doc = import_langium2.AstUtils.getDocument(imp);
|
|
5445
5439
|
const dir = import_path.default.dirname(doc.uri.fsPath);
|
|
5446
|
-
|
|
5440
|
+
const importPath = imp.path.endsWith(".zmodel") ? imp.path : `${imp.path}.zmodel`;
|
|
5441
|
+
return import_langium2.URI.file(import_path.default.resolve(dir, importPath));
|
|
5447
5442
|
}
|
|
5448
5443
|
__name(resolveImportUri, "resolveImportUri");
|
|
5449
|
-
function
|
|
5450
|
-
|
|
5451
|
-
|
|
5452
|
-
|
|
5453
|
-
|
|
5454
|
-
|
|
5455
|
-
]
|
|
5456
|
-
});
|
|
5457
|
-
return resolvedPath;
|
|
5458
|
-
} catch {
|
|
5459
|
-
return void 0;
|
|
5444
|
+
function getDataModelAndTypeDefs(model, includeIgnored = false) {
|
|
5445
|
+
const r = model.declarations.filter((d) => isDataModel(d) || isTypeDef(d));
|
|
5446
|
+
if (includeIgnored) {
|
|
5447
|
+
return r;
|
|
5448
|
+
} else {
|
|
5449
|
+
return r.filter((model2) => !hasAttribute(model2, "@@ignore"));
|
|
5460
5450
|
}
|
|
5461
5451
|
}
|
|
5462
|
-
__name(
|
|
5452
|
+
__name(getDataModelAndTypeDefs, "getDataModelAndTypeDefs");
|
|
5463
5453
|
function getAllDeclarationsIncludingImports(documents, model) {
|
|
5464
5454
|
const imports = resolveTransitiveImports(documents, model);
|
|
5465
5455
|
return model.declarations.concat(...imports.map((imp) => imp.declarations));
|
|
@@ -5560,6 +5550,22 @@ function getAllAttributes(decl, seen = /* @__PURE__ */ new Set()) {
|
|
|
5560
5550
|
return attributes;
|
|
5561
5551
|
}
|
|
5562
5552
|
__name(getAllAttributes, "getAllAttributes");
|
|
5553
|
+
function getDocument(node) {
|
|
5554
|
+
const rootNode = findRootNode(node);
|
|
5555
|
+
const result = rootNode.$document;
|
|
5556
|
+
if (!result) {
|
|
5557
|
+
throw new Error("AST node has no document.");
|
|
5558
|
+
}
|
|
5559
|
+
return result;
|
|
5560
|
+
}
|
|
5561
|
+
__name(getDocument, "getDocument");
|
|
5562
|
+
function findRootNode(node) {
|
|
5563
|
+
while (node.$container) {
|
|
5564
|
+
node = node.$container;
|
|
5565
|
+
}
|
|
5566
|
+
return node;
|
|
5567
|
+
}
|
|
5568
|
+
__name(findRootNode, "findRootNode");
|
|
5563
5569
|
|
|
5564
5570
|
// src/validators/attribute-application-validator.ts
|
|
5565
5571
|
function _ts_decorate(decorators, target, key, desc) {
|
|
@@ -6916,8 +6922,8 @@ var SchemaValidator = class {
|
|
|
6916
6922
|
validateImports(model, accept) {
|
|
6917
6923
|
model.imports.forEach((imp) => {
|
|
6918
6924
|
const importedModel = resolveImport(this.documents, imp);
|
|
6919
|
-
const importPath = imp.path.endsWith(".zmodel") ? imp.path : `${imp.path}.zmodel`;
|
|
6920
6925
|
if (!importedModel) {
|
|
6926
|
+
const importPath = imp.path.endsWith(".zmodel") ? imp.path : `${imp.path}.zmodel`;
|
|
6921
6927
|
accept("error", `Cannot find model file ${importPath}`, {
|
|
6922
6928
|
node: imp
|
|
6923
6929
|
});
|
|
@@ -7727,10 +7733,16 @@ async function loadDocument(fileName, pluginModelFiles = []) {
|
|
|
7727
7733
|
const pluginDocs = await Promise.all(pluginModelFiles.map((file) => services.shared.workspace.LangiumDocuments.getOrCreateDocument(import_langium11.URI.file(import_node_path2.default.resolve(file)))));
|
|
7728
7734
|
const langiumDocuments = services.shared.workspace.LangiumDocuments;
|
|
7729
7735
|
const document = await langiumDocuments.getOrCreateDocument(import_langium11.URI.file(import_node_path2.default.resolve(fileName)));
|
|
7736
|
+
const importedURIs = await loadImports(document, langiumDocuments);
|
|
7737
|
+
const importedDocuments = [];
|
|
7738
|
+
for (const uri of importedURIs) {
|
|
7739
|
+
importedDocuments.push(await langiumDocuments.getOrCreateDocument(uri));
|
|
7740
|
+
}
|
|
7730
7741
|
await services.shared.workspace.DocumentBuilder.build([
|
|
7731
7742
|
stdLib,
|
|
7732
7743
|
...pluginDocs,
|
|
7733
|
-
document
|
|
7744
|
+
document,
|
|
7745
|
+
...importedDocuments
|
|
7734
7746
|
], {
|
|
7735
7747
|
validation: true
|
|
7736
7748
|
});
|
|
@@ -7757,6 +7769,20 @@ async function loadDocument(fileName, pluginModelFiles = []) {
|
|
|
7757
7769
|
warnings
|
|
7758
7770
|
};
|
|
7759
7771
|
}
|
|
7772
|
+
const model = document.parseResult.value;
|
|
7773
|
+
const imported = mergeImportsDeclarations(langiumDocuments, model);
|
|
7774
|
+
imported.forEach((model2) => {
|
|
7775
|
+
langiumDocuments.deleteDocument(model2.$document.uri);
|
|
7776
|
+
services.shared.workspace.IndexManager.remove(model2.$document.uri);
|
|
7777
|
+
});
|
|
7778
|
+
const additionalErrors = validationAfterImportMerge(model);
|
|
7779
|
+
if (additionalErrors.length > 0) {
|
|
7780
|
+
return {
|
|
7781
|
+
success: false,
|
|
7782
|
+
errors: additionalErrors,
|
|
7783
|
+
warnings
|
|
7784
|
+
};
|
|
7785
|
+
}
|
|
7760
7786
|
return {
|
|
7761
7787
|
success: true,
|
|
7762
7788
|
model: document.parseResult.value,
|
|
@@ -7764,6 +7790,64 @@ async function loadDocument(fileName, pluginModelFiles = []) {
|
|
|
7764
7790
|
};
|
|
7765
7791
|
}
|
|
7766
7792
|
__name(loadDocument, "loadDocument");
|
|
7793
|
+
async function loadImports(document, documents, uris = /* @__PURE__ */ new Set()) {
|
|
7794
|
+
const uriString = document.uri.toString();
|
|
7795
|
+
if (!uris.has(uriString)) {
|
|
7796
|
+
uris.add(uriString);
|
|
7797
|
+
const model = document.parseResult.value;
|
|
7798
|
+
for (const imp of model.imports) {
|
|
7799
|
+
const importedModel = resolveImport(documents, imp);
|
|
7800
|
+
if (importedModel) {
|
|
7801
|
+
const importedDoc = getDocument(importedModel);
|
|
7802
|
+
await loadImports(importedDoc, documents, uris);
|
|
7803
|
+
}
|
|
7804
|
+
}
|
|
7805
|
+
}
|
|
7806
|
+
return Array.from(uris).filter((x) => uriString != x).map((e) => import_langium11.URI.parse(e));
|
|
7807
|
+
}
|
|
7808
|
+
__name(loadImports, "loadImports");
|
|
7809
|
+
function mergeImportsDeclarations(documents, model) {
|
|
7810
|
+
const importedModels = resolveTransitiveImports(documents, model);
|
|
7811
|
+
const importedDeclarations = importedModels.flatMap((m) => m.declarations);
|
|
7812
|
+
model.declarations.push(...importedDeclarations);
|
|
7813
|
+
model.imports = [];
|
|
7814
|
+
linkContentToContainer(model);
|
|
7815
|
+
return importedModels;
|
|
7816
|
+
}
|
|
7817
|
+
__name(mergeImportsDeclarations, "mergeImportsDeclarations");
|
|
7818
|
+
function linkContentToContainer(node) {
|
|
7819
|
+
for (const [name, value] of Object.entries(node)) {
|
|
7820
|
+
if (!name.startsWith("$")) {
|
|
7821
|
+
if (Array.isArray(value)) {
|
|
7822
|
+
value.forEach((item, index) => {
|
|
7823
|
+
if ((0, import_langium11.isAstNode)(item)) {
|
|
7824
|
+
item.$container = node;
|
|
7825
|
+
item.$containerProperty = name;
|
|
7826
|
+
item.$containerIndex = index;
|
|
7827
|
+
}
|
|
7828
|
+
});
|
|
7829
|
+
} else if ((0, import_langium11.isAstNode)(value)) {
|
|
7830
|
+
value.$container = node;
|
|
7831
|
+
value.$containerProperty = name;
|
|
7832
|
+
}
|
|
7833
|
+
}
|
|
7834
|
+
}
|
|
7835
|
+
}
|
|
7836
|
+
__name(linkContentToContainer, "linkContentToContainer");
|
|
7837
|
+
function validationAfterImportMerge(model) {
|
|
7838
|
+
const errors = [];
|
|
7839
|
+
const dataSources = model.declarations.filter((d) => isDataSource(d));
|
|
7840
|
+
if (dataSources.length > 1) {
|
|
7841
|
+
errors.push("Validation error: Multiple datasource declarations are not allowed");
|
|
7842
|
+
}
|
|
7843
|
+
const decls = getDataModelAndTypeDefs(model, true);
|
|
7844
|
+
const authDecls = decls.filter((d) => hasAttribute(d, "@@auth"));
|
|
7845
|
+
if (authDecls.length > 1) {
|
|
7846
|
+
errors.push("Validation error: Multiple `@@auth` declarations are not allowed");
|
|
7847
|
+
}
|
|
7848
|
+
return errors;
|
|
7849
|
+
}
|
|
7850
|
+
__name(validationAfterImportMerge, "validationAfterImportMerge");
|
|
7767
7851
|
// Annotate the CommonJS export names for ESM import in node:
|
|
7768
7852
|
0 && (module.exports = {
|
|
7769
7853
|
DocumentLoadError,
|