@zenstackhq/language 3.0.0-beta.8 → 3.0.0
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 +1607 -238
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +89 -19
- package/dist/index.d.ts +89 -19
- package/dist/index.js +1553 -188
- package/dist/index.js.map +1 -1
- package/dist/utils.cjs +106 -9
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +7 -5
- package/dist/utils.d.ts +7 -5
- package/dist/utils.js +100 -6
- package/dist/utils.js.map +1 -1
- package/package.json +10 -11
- package/res/stdlib.zmodel +42 -108
package/dist/utils.cjs
CHANGED
|
@@ -40,6 +40,7 @@ __export(utils_exports, {
|
|
|
40
40
|
getAllLoadedAndReachableDataModelsAndTypeDefs: () => getAllLoadedAndReachableDataModelsAndTypeDefs,
|
|
41
41
|
getAllLoadedDataModelsAndTypeDefs: () => getAllLoadedDataModelsAndTypeDefs,
|
|
42
42
|
getAttribute: () => getAttribute,
|
|
43
|
+
getAttributeArg: () => getAttributeArg,
|
|
43
44
|
getAttributeArgLiteral: () => getAttributeArgLiteral,
|
|
44
45
|
getAuthDecl: () => getAuthDecl,
|
|
45
46
|
getContainingDataModel: () => getContainingDataModel,
|
|
@@ -52,6 +53,7 @@ __export(utils_exports, {
|
|
|
52
53
|
getModelIdFields: () => getModelIdFields,
|
|
53
54
|
getModelUniqueFields: () => getModelUniqueFields,
|
|
54
55
|
getObjectLiteral: () => getObjectLiteral,
|
|
56
|
+
getPluginDocuments: () => getPluginDocuments,
|
|
55
57
|
getRecursiveBases: () => getRecursiveBases,
|
|
56
58
|
getStringLiteral: () => getStringLiteral,
|
|
57
59
|
getUniqueFields: () => getUniqueFields,
|
|
@@ -77,10 +79,13 @@ __export(utils_exports, {
|
|
|
77
79
|
module.exports = __toCommonJS(utils_exports);
|
|
78
80
|
var import_langium = require("langium");
|
|
79
81
|
var import_node_fs = __toESM(require("fs"), 1);
|
|
80
|
-
var
|
|
82
|
+
var import_node_module = require("module");
|
|
83
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
84
|
+
var import_node_url = require("url");
|
|
81
85
|
|
|
82
86
|
// src/constants.ts
|
|
83
87
|
var STD_LIB_MODULE_NAME = "stdlib.zmodel";
|
|
88
|
+
var PLUGIN_MODULE_NAME = "plugin.zmodel";
|
|
84
89
|
|
|
85
90
|
// src/generated/ast.ts
|
|
86
91
|
var langium = __toESM(require("langium"), 1);
|
|
@@ -173,6 +178,10 @@ function isObjectExpr(item) {
|
|
|
173
178
|
}
|
|
174
179
|
__name(isObjectExpr, "isObjectExpr");
|
|
175
180
|
var Plugin = "Plugin";
|
|
181
|
+
function isPlugin(item) {
|
|
182
|
+
return reflection.isInstance(item, Plugin);
|
|
183
|
+
}
|
|
184
|
+
__name(isPlugin, "isPlugin");
|
|
176
185
|
var PluginField = "PluginField";
|
|
177
186
|
var Procedure = "Procedure";
|
|
178
187
|
var ProcedureParam = "ProcedureParam";
|
|
@@ -1037,6 +1046,7 @@ var ZModelAstReflection = class extends langium.AbstractAstReflection {
|
|
|
1037
1046
|
var reflection = new ZModelAstReflection();
|
|
1038
1047
|
|
|
1039
1048
|
// src/utils.ts
|
|
1049
|
+
var import_meta = {};
|
|
1040
1050
|
function hasAttribute(decl, name) {
|
|
1041
1051
|
return !!getAttribute(decl, name);
|
|
1042
1052
|
}
|
|
@@ -1133,8 +1143,14 @@ function getRecursiveBases(decl, includeDelegate = true, seen = /* @__PURE__ */
|
|
|
1133
1143
|
return result;
|
|
1134
1144
|
}
|
|
1135
1145
|
seen.add(decl);
|
|
1136
|
-
|
|
1137
|
-
|
|
1146
|
+
const bases = [
|
|
1147
|
+
...decl.mixins,
|
|
1148
|
+
...isDataModel(decl) && decl.baseModel ? [
|
|
1149
|
+
decl.baseModel
|
|
1150
|
+
] : []
|
|
1151
|
+
];
|
|
1152
|
+
bases.forEach((base) => {
|
|
1153
|
+
const baseDecl = decl.$container.declarations.find((d) => (isTypeDef(d) || isDataModel(d)) && d.name === base.$refText);
|
|
1138
1154
|
if (baseDecl) {
|
|
1139
1155
|
if (!includeDelegate && isDelegateModel(baseDecl)) {
|
|
1140
1156
|
return;
|
|
@@ -1257,6 +1273,10 @@ function getArray(expr) {
|
|
|
1257
1273
|
return isArrayExpr(expr) || isConfigArrayExpr(expr) ? expr.items : void 0;
|
|
1258
1274
|
}
|
|
1259
1275
|
__name(getArray, "getArray");
|
|
1276
|
+
function getAttributeArg(attr, name) {
|
|
1277
|
+
return attr.args.find((arg) => arg.$resolvedParam?.name === name)?.value;
|
|
1278
|
+
}
|
|
1279
|
+
__name(getAttributeArg, "getAttributeArg");
|
|
1260
1280
|
function getAttributeArgLiteral(attr, name) {
|
|
1261
1281
|
for (const arg of attr.args) {
|
|
1262
1282
|
if (arg.$resolvedParam?.name === name) {
|
|
@@ -1343,9 +1363,9 @@ function resolveImportUri(imp) {
|
|
|
1343
1363
|
return void 0;
|
|
1344
1364
|
}
|
|
1345
1365
|
const doc = import_langium.AstUtils.getDocument(imp);
|
|
1346
|
-
const dir =
|
|
1366
|
+
const dir = import_node_path.default.dirname(doc.uri.fsPath);
|
|
1347
1367
|
const importPath = imp.path.endsWith(".zmodel") ? imp.path : `${imp.path}.zmodel`;
|
|
1348
|
-
return import_langium.URI.file(
|
|
1368
|
+
return import_langium.URI.file(import_node_path.default.resolve(dir, importPath));
|
|
1349
1369
|
}
|
|
1350
1370
|
__name(resolveImportUri, "resolveImportUri");
|
|
1351
1371
|
function getDataModelAndTypeDefs(model, includeIgnored = false) {
|
|
@@ -1363,15 +1383,15 @@ function getAllDeclarationsIncludingImports(documents, model) {
|
|
|
1363
1383
|
}
|
|
1364
1384
|
__name(getAllDeclarationsIncludingImports, "getAllDeclarationsIncludingImports");
|
|
1365
1385
|
function getAuthDecl(decls) {
|
|
1366
|
-
let authModel = decls.find((
|
|
1386
|
+
let authModel = decls.find((d) => hasAttribute(d, "@@auth"));
|
|
1367
1387
|
if (!authModel) {
|
|
1368
|
-
authModel = decls.find((
|
|
1388
|
+
authModel = decls.find((d) => d.name === "User");
|
|
1369
1389
|
}
|
|
1370
1390
|
return authModel;
|
|
1371
1391
|
}
|
|
1372
1392
|
__name(getAuthDecl, "getAuthDecl");
|
|
1373
1393
|
function isBeforeInvocation(node) {
|
|
1374
|
-
return isInvocationExpr(node) && node.function.ref?.name === "before"
|
|
1394
|
+
return isInvocationExpr(node) && node.function.ref?.name === "before";
|
|
1375
1395
|
}
|
|
1376
1396
|
__name(isBeforeInvocation, "isBeforeInvocation");
|
|
1377
1397
|
function isCollectionPredicate(node) {
|
|
@@ -1454,13 +1474,23 @@ function getAllAttributes(decl, seen = /* @__PURE__ */ new Set()) {
|
|
|
1454
1474
|
}
|
|
1455
1475
|
if (isDataModel(decl) && decl.baseModel) {
|
|
1456
1476
|
if (decl.baseModel.ref) {
|
|
1457
|
-
|
|
1477
|
+
const attrs = getAllAttributes(decl.baseModel.ref, seen).filter((attr) => !isNonInheritableAttribute(attr));
|
|
1478
|
+
attributes.push(...attrs);
|
|
1458
1479
|
}
|
|
1459
1480
|
}
|
|
1460
1481
|
attributes.push(...decl.attributes);
|
|
1461
1482
|
return attributes;
|
|
1462
1483
|
}
|
|
1463
1484
|
__name(getAllAttributes, "getAllAttributes");
|
|
1485
|
+
function isNonInheritableAttribute(attr) {
|
|
1486
|
+
const attrName = attr.decl.ref?.name ?? attr.decl.$refText;
|
|
1487
|
+
return [
|
|
1488
|
+
"@@map",
|
|
1489
|
+
"@@unique",
|
|
1490
|
+
"@@index"
|
|
1491
|
+
].includes(attrName);
|
|
1492
|
+
}
|
|
1493
|
+
__name(isNonInheritableAttribute, "isNonInheritableAttribute");
|
|
1464
1494
|
function getDocument(node) {
|
|
1465
1495
|
const rootNode = findRootNode(node);
|
|
1466
1496
|
const result = rootNode.$document;
|
|
@@ -1470,6 +1500,71 @@ function getDocument(node) {
|
|
|
1470
1500
|
return result;
|
|
1471
1501
|
}
|
|
1472
1502
|
__name(getDocument, "getDocument");
|
|
1503
|
+
function getPluginDocuments(model, schemaPath) {
|
|
1504
|
+
const result = [];
|
|
1505
|
+
for (const decl of model.declarations.filter(isPlugin)) {
|
|
1506
|
+
const providerField = decl.fields.find((f) => f.name === "provider");
|
|
1507
|
+
if (!providerField) {
|
|
1508
|
+
continue;
|
|
1509
|
+
}
|
|
1510
|
+
const provider = getLiteral(providerField.value);
|
|
1511
|
+
if (!provider) {
|
|
1512
|
+
continue;
|
|
1513
|
+
}
|
|
1514
|
+
let pluginModelFile;
|
|
1515
|
+
let providerPath = import_node_path.default.resolve(import_node_path.default.dirname(schemaPath), provider);
|
|
1516
|
+
if (import_node_fs.default.existsSync(providerPath)) {
|
|
1517
|
+
if (import_node_fs.default.statSync(providerPath).isDirectory()) {
|
|
1518
|
+
providerPath = import_node_path.default.join(providerPath, "index.js");
|
|
1519
|
+
}
|
|
1520
|
+
pluginModelFile = import_node_path.default.resolve(import_node_path.default.dirname(providerPath), PLUGIN_MODULE_NAME);
|
|
1521
|
+
if (!import_node_fs.default.existsSync(pluginModelFile)) {
|
|
1522
|
+
pluginModelFile = findUp([
|
|
1523
|
+
PLUGIN_MODULE_NAME
|
|
1524
|
+
], import_node_path.default.dirname(providerPath));
|
|
1525
|
+
}
|
|
1526
|
+
}
|
|
1527
|
+
if (!pluginModelFile) {
|
|
1528
|
+
if (typeof import_meta.resolve === "function") {
|
|
1529
|
+
try {
|
|
1530
|
+
const resolvedUrl = import_meta.resolve(`${provider}/${PLUGIN_MODULE_NAME}`);
|
|
1531
|
+
pluginModelFile = (0, import_node_url.fileURLToPath)(resolvedUrl);
|
|
1532
|
+
} catch {
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
}
|
|
1536
|
+
if (!pluginModelFile) {
|
|
1537
|
+
try {
|
|
1538
|
+
const require2 = (0, import_node_module.createRequire)((0, import_node_url.pathToFileURL)(schemaPath));
|
|
1539
|
+
pluginModelFile = require2.resolve(`${provider}/${PLUGIN_MODULE_NAME}`);
|
|
1540
|
+
} catch {
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
if (pluginModelFile && import_node_fs.default.existsSync(pluginModelFile)) {
|
|
1544
|
+
result.push(pluginModelFile);
|
|
1545
|
+
}
|
|
1546
|
+
}
|
|
1547
|
+
return result;
|
|
1548
|
+
}
|
|
1549
|
+
__name(getPluginDocuments, "getPluginDocuments");
|
|
1550
|
+
function findUp(names, cwd = process.cwd(), multiple = false, result = []) {
|
|
1551
|
+
if (!names.some((name) => !!name)) {
|
|
1552
|
+
return void 0;
|
|
1553
|
+
}
|
|
1554
|
+
const target = names.find((name) => import_node_fs.default.existsSync(import_node_path.default.join(cwd, name)));
|
|
1555
|
+
if (multiple === false && target) {
|
|
1556
|
+
return import_node_path.default.join(cwd, target);
|
|
1557
|
+
}
|
|
1558
|
+
if (target) {
|
|
1559
|
+
result.push(import_node_path.default.join(cwd, target));
|
|
1560
|
+
}
|
|
1561
|
+
const up = import_node_path.default.resolve(cwd, "..");
|
|
1562
|
+
if (up === cwd) {
|
|
1563
|
+
return multiple && result.length > 0 ? result : void 0;
|
|
1564
|
+
}
|
|
1565
|
+
return findUp(names, up, multiple, result);
|
|
1566
|
+
}
|
|
1567
|
+
__name(findUp, "findUp");
|
|
1473
1568
|
function findRootNode(node) {
|
|
1474
1569
|
while (node.$container) {
|
|
1475
1570
|
node = node.$container;
|
|
@@ -1488,6 +1583,7 @@ __name(findRootNode, "findRootNode");
|
|
|
1488
1583
|
getAllLoadedAndReachableDataModelsAndTypeDefs,
|
|
1489
1584
|
getAllLoadedDataModelsAndTypeDefs,
|
|
1490
1585
|
getAttribute,
|
|
1586
|
+
getAttributeArg,
|
|
1491
1587
|
getAttributeArgLiteral,
|
|
1492
1588
|
getAuthDecl,
|
|
1493
1589
|
getContainingDataModel,
|
|
@@ -1500,6 +1596,7 @@ __name(findRootNode, "findRootNode");
|
|
|
1500
1596
|
getModelIdFields,
|
|
1501
1597
|
getModelUniqueFields,
|
|
1502
1598
|
getObjectLiteral,
|
|
1599
|
+
getPluginDocuments,
|
|
1503
1600
|
getRecursiveBases,
|
|
1504
1601
|
getStringLiteral,
|
|
1505
1602
|
getUniqueFields,
|