@zenstackhq/language 3.0.0-beta.2 → 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 +1644 -294
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +84 -20
- package/dist/index.d.ts +84 -20
- package/dist/index.js +1595 -248
- package/dist/index.js.map +1 -1
- package/dist/utils.cjs +112 -28
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +7 -6
- package/dist/utils.d.ts +7 -6
- package/dist/utils.js +105 -23
- package/dist/utils.js.map +1 -1
- package/package.json +11 -7
- package/res/stdlib.zmodel +49 -77
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,20 +53,20 @@ __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,
|
|
58
60
|
hasAttribute: () => hasAttribute,
|
|
59
61
|
isAuthInvocation: () => isAuthInvocation,
|
|
60
62
|
isAuthOrAuthMemberAccess: () => isAuthOrAuthMemberAccess,
|
|
63
|
+
isBeforeInvocation: () => isBeforeInvocation,
|
|
61
64
|
isCheckInvocation: () => isCheckInvocation,
|
|
62
65
|
isCollectionPredicate: () => isCollectionPredicate,
|
|
63
66
|
isDataFieldReference: () => isDataFieldReference,
|
|
64
67
|
isDelegateModel: () => isDelegateModel,
|
|
65
68
|
isEnumFieldReference: () => isEnumFieldReference,
|
|
66
69
|
isFromStdlib: () => isFromStdlib,
|
|
67
|
-
isFutureExpr: () => isFutureExpr,
|
|
68
|
-
isFutureInvocation: () => isFutureInvocation,
|
|
69
70
|
isMemberContainer: () => isMemberContainer,
|
|
70
71
|
isRelationshipField: () => isRelationshipField,
|
|
71
72
|
mapBuiltinTypeToExpressionType: () => mapBuiltinTypeToExpressionType,
|
|
@@ -76,13 +77,15 @@ __export(utils_exports, {
|
|
|
76
77
|
typeAssignable: () => typeAssignable
|
|
77
78
|
});
|
|
78
79
|
module.exports = __toCommonJS(utils_exports);
|
|
79
|
-
var import_common_helpers = require("@zenstackhq/common-helpers");
|
|
80
80
|
var import_langium = require("langium");
|
|
81
81
|
var import_node_fs = __toESM(require("fs"), 1);
|
|
82
|
-
var
|
|
82
|
+
var import_node_module = require("module");
|
|
83
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
84
|
+
var import_node_url = require("url");
|
|
83
85
|
|
|
84
86
|
// src/constants.ts
|
|
85
87
|
var STD_LIB_MODULE_NAME = "stdlib.zmodel";
|
|
88
|
+
var PLUGIN_MODULE_NAME = "plugin.zmodel";
|
|
86
89
|
|
|
87
90
|
// src/generated/ast.ts
|
|
88
91
|
var langium = __toESM(require("langium"), 1);
|
|
@@ -175,6 +178,10 @@ function isObjectExpr(item) {
|
|
|
175
178
|
}
|
|
176
179
|
__name(isObjectExpr, "isObjectExpr");
|
|
177
180
|
var Plugin = "Plugin";
|
|
181
|
+
function isPlugin(item) {
|
|
182
|
+
return reflection.isInstance(item, Plugin);
|
|
183
|
+
}
|
|
184
|
+
__name(isPlugin, "isPlugin");
|
|
178
185
|
var PluginField = "PluginField";
|
|
179
186
|
var Procedure = "Procedure";
|
|
180
187
|
var ProcedureParam = "ProcedureParam";
|
|
@@ -1039,6 +1046,7 @@ var ZModelAstReflection = class extends langium.AbstractAstReflection {
|
|
|
1039
1046
|
var reflection = new ZModelAstReflection();
|
|
1040
1047
|
|
|
1041
1048
|
// src/utils.ts
|
|
1049
|
+
var import_meta = {};
|
|
1042
1050
|
function hasAttribute(decl, name) {
|
|
1043
1051
|
return !!getAttribute(decl, name);
|
|
1044
1052
|
}
|
|
@@ -1118,10 +1126,6 @@ function isRelationshipField(field) {
|
|
|
1118
1126
|
return isDataModel(field.type.reference?.ref);
|
|
1119
1127
|
}
|
|
1120
1128
|
__name(isRelationshipField, "isRelationshipField");
|
|
1121
|
-
function isFutureExpr(node) {
|
|
1122
|
-
return isInvocationExpr(node) && node.function.ref?.name === "future" && isFromStdlib(node.function.ref);
|
|
1123
|
-
}
|
|
1124
|
-
__name(isFutureExpr, "isFutureExpr");
|
|
1125
1129
|
function isDelegateModel(node) {
|
|
1126
1130
|
return isDataModel(node) && hasAttribute(node, "@@delegate");
|
|
1127
1131
|
}
|
|
@@ -1139,8 +1143,14 @@ function getRecursiveBases(decl, includeDelegate = true, seen = /* @__PURE__ */
|
|
|
1139
1143
|
return result;
|
|
1140
1144
|
}
|
|
1141
1145
|
seen.add(decl);
|
|
1142
|
-
|
|
1143
|
-
|
|
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);
|
|
1144
1154
|
if (baseDecl) {
|
|
1145
1155
|
if (!includeDelegate && isDelegateModel(baseDecl)) {
|
|
1146
1156
|
return;
|
|
@@ -1263,6 +1273,10 @@ function getArray(expr) {
|
|
|
1263
1273
|
return isArrayExpr(expr) || isConfigArrayExpr(expr) ? expr.items : void 0;
|
|
1264
1274
|
}
|
|
1265
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");
|
|
1266
1280
|
function getAttributeArgLiteral(attr, name) {
|
|
1267
1281
|
for (const arg of attr.args) {
|
|
1268
1282
|
if (arg.$resolvedParam?.name === name) {
|
|
@@ -1299,7 +1313,7 @@ function getFieldReference(expr) {
|
|
|
1299
1313
|
}
|
|
1300
1314
|
__name(getFieldReference, "getFieldReference");
|
|
1301
1315
|
function isCheckInvocation(node) {
|
|
1302
|
-
return isInvocationExpr(node) && node.function.ref?.name === "check"
|
|
1316
|
+
return isInvocationExpr(node) && node.function.ref?.name === "check";
|
|
1303
1317
|
}
|
|
1304
1318
|
__name(isCheckInvocation, "isCheckInvocation");
|
|
1305
1319
|
function resolveTransitiveImports(documents, model) {
|
|
@@ -1349,9 +1363,9 @@ function resolveImportUri(imp) {
|
|
|
1349
1363
|
return void 0;
|
|
1350
1364
|
}
|
|
1351
1365
|
const doc = import_langium.AstUtils.getDocument(imp);
|
|
1352
|
-
const dir =
|
|
1366
|
+
const dir = import_node_path.default.dirname(doc.uri.fsPath);
|
|
1353
1367
|
const importPath = imp.path.endsWith(".zmodel") ? imp.path : `${imp.path}.zmodel`;
|
|
1354
|
-
return import_langium.URI.file(
|
|
1368
|
+
return import_langium.URI.file(import_node_path.default.resolve(dir, importPath));
|
|
1355
1369
|
}
|
|
1356
1370
|
__name(resolveImportUri, "resolveImportUri");
|
|
1357
1371
|
function getDataModelAndTypeDefs(model, includeIgnored = false) {
|
|
@@ -1369,17 +1383,17 @@ function getAllDeclarationsIncludingImports(documents, model) {
|
|
|
1369
1383
|
}
|
|
1370
1384
|
__name(getAllDeclarationsIncludingImports, "getAllDeclarationsIncludingImports");
|
|
1371
1385
|
function getAuthDecl(decls) {
|
|
1372
|
-
let authModel = decls.find((
|
|
1386
|
+
let authModel = decls.find((d) => hasAttribute(d, "@@auth"));
|
|
1373
1387
|
if (!authModel) {
|
|
1374
|
-
authModel = decls.find((
|
|
1388
|
+
authModel = decls.find((d) => d.name === "User");
|
|
1375
1389
|
}
|
|
1376
1390
|
return authModel;
|
|
1377
1391
|
}
|
|
1378
1392
|
__name(getAuthDecl, "getAuthDecl");
|
|
1379
|
-
function
|
|
1380
|
-
return isInvocationExpr(node) && node.function.ref?.name === "
|
|
1393
|
+
function isBeforeInvocation(node) {
|
|
1394
|
+
return isInvocationExpr(node) && node.function.ref?.name === "before";
|
|
1381
1395
|
}
|
|
1382
|
-
__name(
|
|
1396
|
+
__name(isBeforeInvocation, "isBeforeInvocation");
|
|
1383
1397
|
function isCollectionPredicate(node) {
|
|
1384
1398
|
return isBinaryExpr(node) && [
|
|
1385
1399
|
"?",
|
|
@@ -1434,12 +1448,14 @@ function getAllFields(decl, includeIgnored = false, seen = /* @__PURE__ */ new S
|
|
|
1434
1448
|
seen.add(decl);
|
|
1435
1449
|
const fields = [];
|
|
1436
1450
|
for (const mixin of decl.mixins) {
|
|
1437
|
-
|
|
1438
|
-
|
|
1451
|
+
if (mixin.ref) {
|
|
1452
|
+
fields.push(...getAllFields(mixin.ref, includeIgnored, seen));
|
|
1453
|
+
}
|
|
1439
1454
|
}
|
|
1440
1455
|
if (isDataModel(decl) && decl.baseModel) {
|
|
1441
|
-
|
|
1442
|
-
|
|
1456
|
+
if (decl.baseModel.ref) {
|
|
1457
|
+
fields.push(...getAllFields(decl.baseModel.ref, includeIgnored, seen));
|
|
1458
|
+
}
|
|
1443
1459
|
}
|
|
1444
1460
|
fields.push(...decl.fields.filter((f) => includeIgnored || !hasAttribute(f, "@ignore")));
|
|
1445
1461
|
return fields;
|
|
@@ -1452,12 +1468,14 @@ function getAllAttributes(decl, seen = /* @__PURE__ */ new Set()) {
|
|
|
1452
1468
|
seen.add(decl);
|
|
1453
1469
|
const attributes = [];
|
|
1454
1470
|
for (const mixin of decl.mixins) {
|
|
1455
|
-
|
|
1456
|
-
|
|
1471
|
+
if (mixin.ref) {
|
|
1472
|
+
attributes.push(...getAllAttributes(mixin.ref, seen));
|
|
1473
|
+
}
|
|
1457
1474
|
}
|
|
1458
1475
|
if (isDataModel(decl) && decl.baseModel) {
|
|
1459
|
-
|
|
1460
|
-
|
|
1476
|
+
if (decl.baseModel.ref) {
|
|
1477
|
+
attributes.push(...getAllAttributes(decl.baseModel.ref, seen));
|
|
1478
|
+
}
|
|
1461
1479
|
}
|
|
1462
1480
|
attributes.push(...decl.attributes);
|
|
1463
1481
|
return attributes;
|
|
@@ -1472,6 +1490,71 @@ function getDocument(node) {
|
|
|
1472
1490
|
return result;
|
|
1473
1491
|
}
|
|
1474
1492
|
__name(getDocument, "getDocument");
|
|
1493
|
+
function getPluginDocuments(model, schemaPath) {
|
|
1494
|
+
const result = [];
|
|
1495
|
+
for (const decl of model.declarations.filter(isPlugin)) {
|
|
1496
|
+
const providerField = decl.fields.find((f) => f.name === "provider");
|
|
1497
|
+
if (!providerField) {
|
|
1498
|
+
continue;
|
|
1499
|
+
}
|
|
1500
|
+
const provider = getLiteral(providerField.value);
|
|
1501
|
+
if (!provider) {
|
|
1502
|
+
continue;
|
|
1503
|
+
}
|
|
1504
|
+
let pluginModelFile;
|
|
1505
|
+
let providerPath = import_node_path.default.resolve(import_node_path.default.dirname(schemaPath), provider);
|
|
1506
|
+
if (import_node_fs.default.existsSync(providerPath)) {
|
|
1507
|
+
if (import_node_fs.default.statSync(providerPath).isDirectory()) {
|
|
1508
|
+
providerPath = import_node_path.default.join(providerPath, "index.js");
|
|
1509
|
+
}
|
|
1510
|
+
pluginModelFile = import_node_path.default.resolve(import_node_path.default.dirname(providerPath), PLUGIN_MODULE_NAME);
|
|
1511
|
+
if (!import_node_fs.default.existsSync(pluginModelFile)) {
|
|
1512
|
+
pluginModelFile = findUp([
|
|
1513
|
+
PLUGIN_MODULE_NAME
|
|
1514
|
+
], import_node_path.default.dirname(providerPath));
|
|
1515
|
+
}
|
|
1516
|
+
}
|
|
1517
|
+
if (!pluginModelFile) {
|
|
1518
|
+
if (typeof import_meta.resolve === "function") {
|
|
1519
|
+
try {
|
|
1520
|
+
const resolvedUrl = import_meta.resolve(`${provider}/${PLUGIN_MODULE_NAME}`);
|
|
1521
|
+
pluginModelFile = (0, import_node_url.fileURLToPath)(resolvedUrl);
|
|
1522
|
+
} catch {
|
|
1523
|
+
}
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
if (!pluginModelFile) {
|
|
1527
|
+
try {
|
|
1528
|
+
const require2 = (0, import_node_module.createRequire)((0, import_node_url.pathToFileURL)(schemaPath));
|
|
1529
|
+
pluginModelFile = require2.resolve(`${provider}/${PLUGIN_MODULE_NAME}`);
|
|
1530
|
+
} catch {
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
if (pluginModelFile && import_node_fs.default.existsSync(pluginModelFile)) {
|
|
1534
|
+
result.push(pluginModelFile);
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
return result;
|
|
1538
|
+
}
|
|
1539
|
+
__name(getPluginDocuments, "getPluginDocuments");
|
|
1540
|
+
function findUp(names, cwd = process.cwd(), multiple = false, result = []) {
|
|
1541
|
+
if (!names.some((name) => !!name)) {
|
|
1542
|
+
return void 0;
|
|
1543
|
+
}
|
|
1544
|
+
const target = names.find((name) => import_node_fs.default.existsSync(import_node_path.default.join(cwd, name)));
|
|
1545
|
+
if (multiple === false && target) {
|
|
1546
|
+
return import_node_path.default.join(cwd, target);
|
|
1547
|
+
}
|
|
1548
|
+
if (target) {
|
|
1549
|
+
result.push(import_node_path.default.join(cwd, target));
|
|
1550
|
+
}
|
|
1551
|
+
const up = import_node_path.default.resolve(cwd, "..");
|
|
1552
|
+
if (up === cwd) {
|
|
1553
|
+
return multiple && result.length > 0 ? result : void 0;
|
|
1554
|
+
}
|
|
1555
|
+
return findUp(names, up, multiple, result);
|
|
1556
|
+
}
|
|
1557
|
+
__name(findUp, "findUp");
|
|
1475
1558
|
function findRootNode(node) {
|
|
1476
1559
|
while (node.$container) {
|
|
1477
1560
|
node = node.$container;
|
|
@@ -1490,6 +1573,7 @@ __name(findRootNode, "findRootNode");
|
|
|
1490
1573
|
getAllLoadedAndReachableDataModelsAndTypeDefs,
|
|
1491
1574
|
getAllLoadedDataModelsAndTypeDefs,
|
|
1492
1575
|
getAttribute,
|
|
1576
|
+
getAttributeArg,
|
|
1493
1577
|
getAttributeArgLiteral,
|
|
1494
1578
|
getAuthDecl,
|
|
1495
1579
|
getContainingDataModel,
|
|
@@ -1502,20 +1586,20 @@ __name(findRootNode, "findRootNode");
|
|
|
1502
1586
|
getModelIdFields,
|
|
1503
1587
|
getModelUniqueFields,
|
|
1504
1588
|
getObjectLiteral,
|
|
1589
|
+
getPluginDocuments,
|
|
1505
1590
|
getRecursiveBases,
|
|
1506
1591
|
getStringLiteral,
|
|
1507
1592
|
getUniqueFields,
|
|
1508
1593
|
hasAttribute,
|
|
1509
1594
|
isAuthInvocation,
|
|
1510
1595
|
isAuthOrAuthMemberAccess,
|
|
1596
|
+
isBeforeInvocation,
|
|
1511
1597
|
isCheckInvocation,
|
|
1512
1598
|
isCollectionPredicate,
|
|
1513
1599
|
isDataFieldReference,
|
|
1514
1600
|
isDelegateModel,
|
|
1515
1601
|
isEnumFieldReference,
|
|
1516
1602
|
isFromStdlib,
|
|
1517
|
-
isFutureExpr,
|
|
1518
|
-
isFutureInvocation,
|
|
1519
1603
|
isMemberContainer,
|
|
1520
1604
|
isRelationshipField,
|
|
1521
1605
|
mapBuiltinTypeToExpressionType,
|