@zenstackhq/language 3.0.0-alpha.9 → 3.0.0-beta.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/ast.cjs +85 -156
- package/dist/ast.cjs.map +1 -1
- package/dist/ast.d.cts +45 -80
- package/dist/ast.d.ts +45 -80
- package/dist/ast.js +79 -144
- package/dist/ast.js.map +1 -1
- package/dist/index.cjs +693 -623
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +695 -625
- package/dist/index.js.map +1 -1
- package/dist/utils.cjs +1528 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.cts +94 -0
- package/dist/utils.d.ts +94 -0
- package/dist/utils.js +1453 -0
- package/dist/utils.js.map +1 -0
- package/package.json +18 -4
- package/res/stdlib.zmodel +47 -101
package/dist/index.js
CHANGED
|
@@ -8,45 +8,12 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
8
8
|
});
|
|
9
9
|
|
|
10
10
|
// src/index.ts
|
|
11
|
-
import { URI as URI3 } from "langium";
|
|
11
|
+
import { isAstNode, URI as URI3 } from "langium";
|
|
12
12
|
import { NodeFileSystem } from "langium/node";
|
|
13
13
|
import fs3 from "fs";
|
|
14
14
|
import path3 from "path";
|
|
15
15
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
16
16
|
|
|
17
|
-
// src/constants.ts
|
|
18
|
-
var SUPPORTED_PROVIDERS = [
|
|
19
|
-
"sqlite",
|
|
20
|
-
"postgresql"
|
|
21
|
-
];
|
|
22
|
-
var SCALAR_TYPES = [
|
|
23
|
-
"String",
|
|
24
|
-
"Int",
|
|
25
|
-
"Float",
|
|
26
|
-
"Decimal",
|
|
27
|
-
"BigInt",
|
|
28
|
-
"Boolean",
|
|
29
|
-
"Bytes",
|
|
30
|
-
"DateTime"
|
|
31
|
-
];
|
|
32
|
-
var STD_LIB_MODULE_NAME = "stdlib.zmodel";
|
|
33
|
-
var PLUGIN_MODULE_NAME = "plugin.zmodel";
|
|
34
|
-
var IssueCodes = /* @__PURE__ */ function(IssueCodes2) {
|
|
35
|
-
IssueCodes2["MissingOppositeRelation"] = "miss-opposite-relation";
|
|
36
|
-
return IssueCodes2;
|
|
37
|
-
}({});
|
|
38
|
-
var ExpressionContext = /* @__PURE__ */ function(ExpressionContext2) {
|
|
39
|
-
ExpressionContext2["DefaultValue"] = "DefaultValue";
|
|
40
|
-
ExpressionContext2["AccessPolicy"] = "AccessPolicy";
|
|
41
|
-
ExpressionContext2["ValidationRule"] = "ValidationRule";
|
|
42
|
-
ExpressionContext2["Index"] = "Index";
|
|
43
|
-
return ExpressionContext2;
|
|
44
|
-
}({});
|
|
45
|
-
|
|
46
|
-
// src/module.ts
|
|
47
|
-
import { inject } from "langium";
|
|
48
|
-
import { createDefaultModule, createDefaultSharedModule } from "langium/lsp";
|
|
49
|
-
|
|
50
17
|
// src/generated/ast.ts
|
|
51
18
|
import * as langium from "langium";
|
|
52
19
|
var AbstractDeclaration = "AbstractDeclaration";
|
|
@@ -64,7 +31,6 @@ __name(isLiteralExpr, "isLiteralExpr");
|
|
|
64
31
|
var MemberAccessTarget = "MemberAccessTarget";
|
|
65
32
|
var ReferenceTarget = "ReferenceTarget";
|
|
66
33
|
var TypeDeclaration = "TypeDeclaration";
|
|
67
|
-
var TypeDefFieldTypes = "TypeDefFieldTypes";
|
|
68
34
|
var Argument = "Argument";
|
|
69
35
|
var ArrayExpr = "ArrayExpr";
|
|
70
36
|
function isArrayExpr(item) {
|
|
@@ -97,6 +63,21 @@ __name(isConfigArrayExpr, "isConfigArrayExpr");
|
|
|
97
63
|
var ConfigField = "ConfigField";
|
|
98
64
|
var ConfigInvocationArg = "ConfigInvocationArg";
|
|
99
65
|
var ConfigInvocationExpr = "ConfigInvocationExpr";
|
|
66
|
+
var DataField = "DataField";
|
|
67
|
+
function isDataField(item) {
|
|
68
|
+
return reflection.isInstance(item, DataField);
|
|
69
|
+
}
|
|
70
|
+
__name(isDataField, "isDataField");
|
|
71
|
+
var DataFieldAttribute = "DataFieldAttribute";
|
|
72
|
+
function isDataFieldAttribute(item) {
|
|
73
|
+
return reflection.isInstance(item, DataFieldAttribute);
|
|
74
|
+
}
|
|
75
|
+
__name(isDataFieldAttribute, "isDataFieldAttribute");
|
|
76
|
+
var DataFieldType = "DataFieldType";
|
|
77
|
+
function isDataFieldType(item) {
|
|
78
|
+
return reflection.isInstance(item, DataFieldType);
|
|
79
|
+
}
|
|
80
|
+
__name(isDataFieldType, "isDataFieldType");
|
|
100
81
|
var DataModel = "DataModel";
|
|
101
82
|
function isDataModel(item) {
|
|
102
83
|
return reflection.isInstance(item, DataModel);
|
|
@@ -107,21 +88,6 @@ function isDataModelAttribute(item) {
|
|
|
107
88
|
return reflection.isInstance(item, DataModelAttribute);
|
|
108
89
|
}
|
|
109
90
|
__name(isDataModelAttribute, "isDataModelAttribute");
|
|
110
|
-
var DataModelField = "DataModelField";
|
|
111
|
-
function isDataModelField(item) {
|
|
112
|
-
return reflection.isInstance(item, DataModelField);
|
|
113
|
-
}
|
|
114
|
-
__name(isDataModelField, "isDataModelField");
|
|
115
|
-
var DataModelFieldAttribute = "DataModelFieldAttribute";
|
|
116
|
-
function isDataModelFieldAttribute(item) {
|
|
117
|
-
return reflection.isInstance(item, DataModelFieldAttribute);
|
|
118
|
-
}
|
|
119
|
-
__name(isDataModelFieldAttribute, "isDataModelFieldAttribute");
|
|
120
|
-
var DataModelFieldType = "DataModelFieldType";
|
|
121
|
-
function isDataModelFieldType(item) {
|
|
122
|
-
return reflection.isInstance(item, DataModelFieldType);
|
|
123
|
-
}
|
|
124
|
-
__name(isDataModelFieldType, "isDataModelFieldType");
|
|
125
91
|
var DataSource = "DataSource";
|
|
126
92
|
function isDataSource(item) {
|
|
127
93
|
return reflection.isInstance(item, DataSource);
|
|
@@ -175,6 +141,10 @@ function isObjectExpr(item) {
|
|
|
175
141
|
}
|
|
176
142
|
__name(isObjectExpr, "isObjectExpr");
|
|
177
143
|
var Plugin = "Plugin";
|
|
144
|
+
function isPlugin(item) {
|
|
145
|
+
return reflection.isInstance(item, Plugin);
|
|
146
|
+
}
|
|
147
|
+
__name(isPlugin, "isPlugin");
|
|
178
148
|
var PluginField = "PluginField";
|
|
179
149
|
var Procedure = "Procedure";
|
|
180
150
|
var ProcedureParam = "ProcedureParam";
|
|
@@ -199,12 +169,6 @@ function isTypeDef(item) {
|
|
|
199
169
|
return reflection.isInstance(item, TypeDef);
|
|
200
170
|
}
|
|
201
171
|
__name(isTypeDef, "isTypeDef");
|
|
202
|
-
var TypeDefField = "TypeDefField";
|
|
203
|
-
function isTypeDefField(item) {
|
|
204
|
-
return reflection.isInstance(item, TypeDefField);
|
|
205
|
-
}
|
|
206
|
-
__name(isTypeDefField, "isTypeDefField");
|
|
207
|
-
var TypeDefFieldType = "TypeDefFieldType";
|
|
208
172
|
var UnaryExpr = "UnaryExpr";
|
|
209
173
|
var UnsupportedFieldType = "UnsupportedFieldType";
|
|
210
174
|
var ZModelAstReflection = class extends langium.AbstractAstReflection {
|
|
@@ -227,11 +191,11 @@ var ZModelAstReflection = class extends langium.AbstractAstReflection {
|
|
|
227
191
|
ConfigField,
|
|
228
192
|
ConfigInvocationArg,
|
|
229
193
|
ConfigInvocationExpr,
|
|
194
|
+
DataField,
|
|
195
|
+
DataFieldAttribute,
|
|
196
|
+
DataFieldType,
|
|
230
197
|
DataModel,
|
|
231
198
|
DataModelAttribute,
|
|
232
|
-
DataModelField,
|
|
233
|
-
DataModelFieldAttribute,
|
|
234
|
-
DataModelFieldType,
|
|
235
199
|
DataSource,
|
|
236
200
|
Enum,
|
|
237
201
|
EnumField,
|
|
@@ -262,9 +226,6 @@ var ZModelAstReflection = class extends langium.AbstractAstReflection {
|
|
|
262
226
|
ThisExpr,
|
|
263
227
|
TypeDeclaration,
|
|
264
228
|
TypeDef,
|
|
265
|
-
TypeDefField,
|
|
266
|
-
TypeDefFieldType,
|
|
267
|
-
TypeDefFieldTypes,
|
|
268
229
|
UnaryExpr,
|
|
269
230
|
UnsupportedFieldType
|
|
270
231
|
];
|
|
@@ -297,16 +258,13 @@ var ZModelAstReflection = class extends langium.AbstractAstReflection {
|
|
|
297
258
|
case ConfigArrayExpr: {
|
|
298
259
|
return this.isSubtype(ConfigExpr, supertype);
|
|
299
260
|
}
|
|
300
|
-
case
|
|
301
|
-
return this.isSubtype(AbstractDeclaration, supertype) || this.isSubtype(TypeDeclaration, supertype);
|
|
302
|
-
}
|
|
303
|
-
case DataModelField:
|
|
304
|
-
case TypeDefField: {
|
|
261
|
+
case DataField: {
|
|
305
262
|
return this.isSubtype(MemberAccessTarget, supertype) || this.isSubtype(ReferenceTarget, supertype);
|
|
306
263
|
}
|
|
264
|
+
case DataModel:
|
|
307
265
|
case Enum:
|
|
308
266
|
case TypeDef: {
|
|
309
|
-
return this.isSubtype(AbstractDeclaration, supertype) || this.isSubtype(TypeDeclaration, supertype)
|
|
267
|
+
return this.isSubtype(AbstractDeclaration, supertype) || this.isSubtype(TypeDeclaration, supertype);
|
|
310
268
|
}
|
|
311
269
|
case EnumField:
|
|
312
270
|
case FunctionParam: {
|
|
@@ -325,18 +283,22 @@ var ZModelAstReflection = class extends langium.AbstractAstReflection {
|
|
|
325
283
|
const referenceId = `${refInfo.container.$type}:${refInfo.property}`;
|
|
326
284
|
switch (referenceId) {
|
|
327
285
|
case "AttributeParamType:reference":
|
|
328
|
-
case "
|
|
286
|
+
case "DataFieldType:reference":
|
|
329
287
|
case "FunctionParamType:reference": {
|
|
330
288
|
return TypeDeclaration;
|
|
331
289
|
}
|
|
332
|
-
case "
|
|
333
|
-
return DataModel;
|
|
334
|
-
}
|
|
290
|
+
case "DataFieldAttribute:decl":
|
|
335
291
|
case "DataModelAttribute:decl":
|
|
336
|
-
case "DataModelFieldAttribute:decl":
|
|
337
292
|
case "InternalAttribute:decl": {
|
|
338
293
|
return Attribute;
|
|
339
294
|
}
|
|
295
|
+
case "DataModel:baseModel": {
|
|
296
|
+
return DataModel;
|
|
297
|
+
}
|
|
298
|
+
case "DataModel:mixins":
|
|
299
|
+
case "TypeDef:mixins": {
|
|
300
|
+
return TypeDef;
|
|
301
|
+
}
|
|
340
302
|
case "InvocationExpr:function": {
|
|
341
303
|
return FunctionDecl;
|
|
342
304
|
}
|
|
@@ -346,9 +308,6 @@ var ZModelAstReflection = class extends langium.AbstractAstReflection {
|
|
|
346
308
|
case "ReferenceExpr:target": {
|
|
347
309
|
return ReferenceTarget;
|
|
348
310
|
}
|
|
349
|
-
case "TypeDefFieldType:reference": {
|
|
350
|
-
return TypeDefFieldTypes;
|
|
351
|
-
}
|
|
352
311
|
default: {
|
|
353
312
|
throw new Error(`${referenceId} is not a valid reference id.`);
|
|
354
313
|
}
|
|
@@ -535,9 +494,9 @@ var ZModelAstReflection = class extends langium.AbstractAstReflection {
|
|
|
535
494
|
]
|
|
536
495
|
};
|
|
537
496
|
}
|
|
538
|
-
case
|
|
497
|
+
case DataField: {
|
|
539
498
|
return {
|
|
540
|
-
name:
|
|
499
|
+
name: DataField,
|
|
541
500
|
properties: [
|
|
542
501
|
{
|
|
543
502
|
name: "attributes",
|
|
@@ -547,31 +506,18 @@ var ZModelAstReflection = class extends langium.AbstractAstReflection {
|
|
|
547
506
|
name: "comments",
|
|
548
507
|
defaultValue: []
|
|
549
508
|
},
|
|
550
|
-
{
|
|
551
|
-
name: "fields",
|
|
552
|
-
defaultValue: []
|
|
553
|
-
},
|
|
554
|
-
{
|
|
555
|
-
name: "isAbstract",
|
|
556
|
-
defaultValue: false
|
|
557
|
-
},
|
|
558
|
-
{
|
|
559
|
-
name: "isView",
|
|
560
|
-
defaultValue: false
|
|
561
|
-
},
|
|
562
509
|
{
|
|
563
510
|
name: "name"
|
|
564
511
|
},
|
|
565
512
|
{
|
|
566
|
-
name: "
|
|
567
|
-
defaultValue: []
|
|
513
|
+
name: "type"
|
|
568
514
|
}
|
|
569
515
|
]
|
|
570
516
|
};
|
|
571
517
|
}
|
|
572
|
-
case
|
|
518
|
+
case DataFieldAttribute: {
|
|
573
519
|
return {
|
|
574
|
-
name:
|
|
520
|
+
name: DataFieldAttribute,
|
|
575
521
|
properties: [
|
|
576
522
|
{
|
|
577
523
|
name: "args",
|
|
@@ -583,61 +529,73 @@ var ZModelAstReflection = class extends langium.AbstractAstReflection {
|
|
|
583
529
|
]
|
|
584
530
|
};
|
|
585
531
|
}
|
|
586
|
-
case
|
|
532
|
+
case DataFieldType: {
|
|
587
533
|
return {
|
|
588
|
-
name:
|
|
534
|
+
name: DataFieldType,
|
|
589
535
|
properties: [
|
|
590
536
|
{
|
|
591
|
-
name: "
|
|
592
|
-
defaultValue:
|
|
537
|
+
name: "array",
|
|
538
|
+
defaultValue: false
|
|
593
539
|
},
|
|
594
540
|
{
|
|
595
|
-
name: "
|
|
596
|
-
defaultValue:
|
|
541
|
+
name: "optional",
|
|
542
|
+
defaultValue: false
|
|
597
543
|
},
|
|
598
544
|
{
|
|
599
|
-
name: "
|
|
545
|
+
name: "reference"
|
|
600
546
|
},
|
|
601
547
|
{
|
|
602
548
|
name: "type"
|
|
549
|
+
},
|
|
550
|
+
{
|
|
551
|
+
name: "unsupported"
|
|
603
552
|
}
|
|
604
553
|
]
|
|
605
554
|
};
|
|
606
555
|
}
|
|
607
|
-
case
|
|
556
|
+
case DataModel: {
|
|
608
557
|
return {
|
|
609
|
-
name:
|
|
558
|
+
name: DataModel,
|
|
610
559
|
properties: [
|
|
611
560
|
{
|
|
612
|
-
name: "
|
|
561
|
+
name: "attributes",
|
|
613
562
|
defaultValue: []
|
|
614
563
|
},
|
|
615
564
|
{
|
|
616
|
-
name: "
|
|
617
|
-
}
|
|
618
|
-
]
|
|
619
|
-
};
|
|
620
|
-
}
|
|
621
|
-
case DataModelFieldType: {
|
|
622
|
-
return {
|
|
623
|
-
name: DataModelFieldType,
|
|
624
|
-
properties: [
|
|
565
|
+
name: "baseModel"
|
|
566
|
+
},
|
|
625
567
|
{
|
|
626
|
-
name: "
|
|
627
|
-
defaultValue:
|
|
568
|
+
name: "comments",
|
|
569
|
+
defaultValue: []
|
|
628
570
|
},
|
|
629
571
|
{
|
|
630
|
-
name: "
|
|
572
|
+
name: "fields",
|
|
573
|
+
defaultValue: []
|
|
574
|
+
},
|
|
575
|
+
{
|
|
576
|
+
name: "isView",
|
|
631
577
|
defaultValue: false
|
|
632
578
|
},
|
|
633
579
|
{
|
|
634
|
-
name: "
|
|
580
|
+
name: "mixins",
|
|
581
|
+
defaultValue: []
|
|
635
582
|
},
|
|
636
583
|
{
|
|
637
|
-
name: "
|
|
584
|
+
name: "name"
|
|
585
|
+
}
|
|
586
|
+
]
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
case DataModelAttribute: {
|
|
590
|
+
return {
|
|
591
|
+
name: DataModelAttribute,
|
|
592
|
+
properties: [
|
|
593
|
+
{
|
|
594
|
+
name: "args",
|
|
595
|
+
defaultValue: []
|
|
638
596
|
},
|
|
639
597
|
{
|
|
640
|
-
name: "
|
|
598
|
+
name: "decl"
|
|
641
599
|
}
|
|
642
600
|
]
|
|
643
601
|
};
|
|
@@ -1011,49 +969,11 @@ var ZModelAstReflection = class extends langium.AbstractAstReflection {
|
|
|
1011
969
|
defaultValue: []
|
|
1012
970
|
},
|
|
1013
971
|
{
|
|
1014
|
-
name: "
|
|
1015
|
-
}
|
|
1016
|
-
]
|
|
1017
|
-
};
|
|
1018
|
-
}
|
|
1019
|
-
case TypeDefField: {
|
|
1020
|
-
return {
|
|
1021
|
-
name: TypeDefField,
|
|
1022
|
-
properties: [
|
|
1023
|
-
{
|
|
1024
|
-
name: "attributes",
|
|
1025
|
-
defaultValue: []
|
|
1026
|
-
},
|
|
1027
|
-
{
|
|
1028
|
-
name: "comments",
|
|
972
|
+
name: "mixins",
|
|
1029
973
|
defaultValue: []
|
|
1030
974
|
},
|
|
1031
975
|
{
|
|
1032
976
|
name: "name"
|
|
1033
|
-
},
|
|
1034
|
-
{
|
|
1035
|
-
name: "type"
|
|
1036
|
-
}
|
|
1037
|
-
]
|
|
1038
|
-
};
|
|
1039
|
-
}
|
|
1040
|
-
case TypeDefFieldType: {
|
|
1041
|
-
return {
|
|
1042
|
-
name: TypeDefFieldType,
|
|
1043
|
-
properties: [
|
|
1044
|
-
{
|
|
1045
|
-
name: "array",
|
|
1046
|
-
defaultValue: false
|
|
1047
|
-
},
|
|
1048
|
-
{
|
|
1049
|
-
name: "optional",
|
|
1050
|
-
defaultValue: false
|
|
1051
|
-
},
|
|
1052
|
-
{
|
|
1053
|
-
name: "reference"
|
|
1054
|
-
},
|
|
1055
|
-
{
|
|
1056
|
-
name: "type"
|
|
1057
977
|
}
|
|
1058
978
|
]
|
|
1059
979
|
};
|
|
@@ -1092,6 +1012,39 @@ var ZModelAstReflection = class extends langium.AbstractAstReflection {
|
|
|
1092
1012
|
};
|
|
1093
1013
|
var reflection = new ZModelAstReflection();
|
|
1094
1014
|
|
|
1015
|
+
// src/constants.ts
|
|
1016
|
+
var SUPPORTED_PROVIDERS = [
|
|
1017
|
+
"sqlite",
|
|
1018
|
+
"postgresql"
|
|
1019
|
+
];
|
|
1020
|
+
var SCALAR_TYPES = [
|
|
1021
|
+
"String",
|
|
1022
|
+
"Int",
|
|
1023
|
+
"Float",
|
|
1024
|
+
"Decimal",
|
|
1025
|
+
"BigInt",
|
|
1026
|
+
"Boolean",
|
|
1027
|
+
"Bytes",
|
|
1028
|
+
"DateTime"
|
|
1029
|
+
];
|
|
1030
|
+
var STD_LIB_MODULE_NAME = "stdlib.zmodel";
|
|
1031
|
+
var PLUGIN_MODULE_NAME = "plugin.zmodel";
|
|
1032
|
+
var IssueCodes = /* @__PURE__ */ function(IssueCodes2) {
|
|
1033
|
+
IssueCodes2["MissingOppositeRelation"] = "miss-opposite-relation";
|
|
1034
|
+
return IssueCodes2;
|
|
1035
|
+
}({});
|
|
1036
|
+
var ExpressionContext = /* @__PURE__ */ function(ExpressionContext2) {
|
|
1037
|
+
ExpressionContext2["DefaultValue"] = "DefaultValue";
|
|
1038
|
+
ExpressionContext2["AccessPolicy"] = "AccessPolicy";
|
|
1039
|
+
ExpressionContext2["ValidationRule"] = "ValidationRule";
|
|
1040
|
+
ExpressionContext2["Index"] = "Index";
|
|
1041
|
+
return ExpressionContext2;
|
|
1042
|
+
}({});
|
|
1043
|
+
|
|
1044
|
+
// src/module.ts
|
|
1045
|
+
import { inject } from "langium";
|
|
1046
|
+
import { createDefaultModule, createDefaultSharedModule } from "langium/lsp";
|
|
1047
|
+
|
|
1095
1048
|
// src/generated/grammar.ts
|
|
1096
1049
|
import { loadGrammarFromJson } from "langium";
|
|
1097
1050
|
var loadedZModelGrammar;
|
|
@@ -1214,7 +1167,7 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
|
|
|
1214
1167
|
{
|
|
1215
1168
|
"$type": "RuleCall",
|
|
1216
1169
|
"rule": {
|
|
1217
|
-
"$ref": "#/rules@
|
|
1170
|
+
"$ref": "#/rules@42"
|
|
1218
1171
|
},
|
|
1219
1172
|
"arguments": []
|
|
1220
1173
|
},
|
|
@@ -3008,16 +2961,6 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
|
|
|
3008
2961
|
{
|
|
3009
2962
|
"$type": "Group",
|
|
3010
2963
|
"elements": [
|
|
3011
|
-
{
|
|
3012
|
-
"$type": "Assignment",
|
|
3013
|
-
"feature": "isAbstract",
|
|
3014
|
-
"operator": "?=",
|
|
3015
|
-
"terminal": {
|
|
3016
|
-
"$type": "Keyword",
|
|
3017
|
-
"value": "abstract"
|
|
3018
|
-
},
|
|
3019
|
-
"cardinality": "?"
|
|
3020
|
-
},
|
|
3021
2964
|
{
|
|
3022
2965
|
"$type": "Keyword",
|
|
3023
2966
|
"value": "model"
|
|
@@ -3035,45 +2978,59 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
|
|
|
3035
2978
|
}
|
|
3036
2979
|
},
|
|
3037
2980
|
{
|
|
3038
|
-
"$type": "
|
|
2981
|
+
"$type": "Alternatives",
|
|
3039
2982
|
"elements": [
|
|
3040
2983
|
{
|
|
3041
|
-
"$type": "
|
|
3042
|
-
"
|
|
2984
|
+
"$type": "RuleCall",
|
|
2985
|
+
"rule": {
|
|
2986
|
+
"$ref": "#/rules@38"
|
|
2987
|
+
},
|
|
2988
|
+
"arguments": []
|
|
3043
2989
|
},
|
|
3044
2990
|
{
|
|
3045
|
-
"$type": "
|
|
3046
|
-
"
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
2991
|
+
"$type": "RuleCall",
|
|
2992
|
+
"rule": {
|
|
2993
|
+
"$ref": "#/rules@39"
|
|
2994
|
+
},
|
|
2995
|
+
"arguments": []
|
|
2996
|
+
},
|
|
2997
|
+
{
|
|
2998
|
+
"$type": "Group",
|
|
2999
|
+
"elements": [
|
|
3000
|
+
{
|
|
3001
|
+
"$type": "RuleCall",
|
|
3002
|
+
"rule": {
|
|
3003
|
+
"$ref": "#/rules@39"
|
|
3004
|
+
},
|
|
3005
|
+
"arguments": []
|
|
3052
3006
|
},
|
|
3053
|
-
|
|
3054
|
-
|
|
3007
|
+
{
|
|
3008
|
+
"$type": "RuleCall",
|
|
3009
|
+
"rule": {
|
|
3010
|
+
"$ref": "#/rules@38"
|
|
3011
|
+
},
|
|
3012
|
+
"arguments": []
|
|
3013
|
+
}
|
|
3014
|
+
]
|
|
3055
3015
|
},
|
|
3056
3016
|
{
|
|
3057
3017
|
"$type": "Group",
|
|
3058
3018
|
"elements": [
|
|
3059
3019
|
{
|
|
3060
|
-
"$type": "
|
|
3061
|
-
"
|
|
3020
|
+
"$type": "RuleCall",
|
|
3021
|
+
"rule": {
|
|
3022
|
+
"$ref": "#/rules@38"
|
|
3023
|
+
},
|
|
3024
|
+
"arguments": []
|
|
3062
3025
|
},
|
|
3063
3026
|
{
|
|
3064
|
-
"$type": "
|
|
3065
|
-
"
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
"type": {
|
|
3070
|
-
"$ref": "#/rules@37"
|
|
3071
|
-
},
|
|
3072
|
-
"deprecatedSyntax": false
|
|
3073
|
-
}
|
|
3027
|
+
"$type": "RuleCall",
|
|
3028
|
+
"rule": {
|
|
3029
|
+
"$ref": "#/rules@39"
|
|
3030
|
+
},
|
|
3031
|
+
"arguments": []
|
|
3074
3032
|
}
|
|
3075
|
-
]
|
|
3076
|
-
"cardinality": "*"
|
|
3033
|
+
]
|
|
3077
3034
|
}
|
|
3078
3035
|
],
|
|
3079
3036
|
"cardinality": "?"
|
|
@@ -3122,7 +3079,7 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
|
|
|
3122
3079
|
"terminal": {
|
|
3123
3080
|
"$type": "RuleCall",
|
|
3124
3081
|
"rule": {
|
|
3125
|
-
"$ref": "#/rules@
|
|
3082
|
+
"$ref": "#/rules@40"
|
|
3126
3083
|
},
|
|
3127
3084
|
"arguments": []
|
|
3128
3085
|
}
|
|
@@ -3157,7 +3114,92 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
|
|
|
3157
3114
|
},
|
|
3158
3115
|
{
|
|
3159
3116
|
"$type": "ParserRule",
|
|
3160
|
-
"
|
|
3117
|
+
"fragment": true,
|
|
3118
|
+
"name": "WithClause",
|
|
3119
|
+
"definition": {
|
|
3120
|
+
"$type": "Group",
|
|
3121
|
+
"elements": [
|
|
3122
|
+
{
|
|
3123
|
+
"$type": "Keyword",
|
|
3124
|
+
"value": "with"
|
|
3125
|
+
},
|
|
3126
|
+
{
|
|
3127
|
+
"$type": "Assignment",
|
|
3128
|
+
"feature": "mixins",
|
|
3129
|
+
"operator": "+=",
|
|
3130
|
+
"terminal": {
|
|
3131
|
+
"$type": "CrossReference",
|
|
3132
|
+
"type": {
|
|
3133
|
+
"$ref": "#/rules@42"
|
|
3134
|
+
},
|
|
3135
|
+
"deprecatedSyntax": false
|
|
3136
|
+
}
|
|
3137
|
+
},
|
|
3138
|
+
{
|
|
3139
|
+
"$type": "Group",
|
|
3140
|
+
"elements": [
|
|
3141
|
+
{
|
|
3142
|
+
"$type": "Keyword",
|
|
3143
|
+
"value": ",",
|
|
3144
|
+
"cardinality": "?"
|
|
3145
|
+
},
|
|
3146
|
+
{
|
|
3147
|
+
"$type": "Assignment",
|
|
3148
|
+
"feature": "mixins",
|
|
3149
|
+
"operator": "+=",
|
|
3150
|
+
"terminal": {
|
|
3151
|
+
"$type": "CrossReference",
|
|
3152
|
+
"type": {
|
|
3153
|
+
"$ref": "#/rules@42"
|
|
3154
|
+
},
|
|
3155
|
+
"deprecatedSyntax": false
|
|
3156
|
+
}
|
|
3157
|
+
}
|
|
3158
|
+
],
|
|
3159
|
+
"cardinality": "*"
|
|
3160
|
+
}
|
|
3161
|
+
]
|
|
3162
|
+
},
|
|
3163
|
+
"definesHiddenTokens": false,
|
|
3164
|
+
"entry": false,
|
|
3165
|
+
"hiddenTokens": [],
|
|
3166
|
+
"parameters": [],
|
|
3167
|
+
"wildcard": false
|
|
3168
|
+
},
|
|
3169
|
+
{
|
|
3170
|
+
"$type": "ParserRule",
|
|
3171
|
+
"fragment": true,
|
|
3172
|
+
"name": "ExtendsClause",
|
|
3173
|
+
"definition": {
|
|
3174
|
+
"$type": "Group",
|
|
3175
|
+
"elements": [
|
|
3176
|
+
{
|
|
3177
|
+
"$type": "Keyword",
|
|
3178
|
+
"value": "extends"
|
|
3179
|
+
},
|
|
3180
|
+
{
|
|
3181
|
+
"$type": "Assignment",
|
|
3182
|
+
"feature": "baseModel",
|
|
3183
|
+
"operator": "=",
|
|
3184
|
+
"terminal": {
|
|
3185
|
+
"$type": "CrossReference",
|
|
3186
|
+
"type": {
|
|
3187
|
+
"$ref": "#/rules@37"
|
|
3188
|
+
},
|
|
3189
|
+
"deprecatedSyntax": false
|
|
3190
|
+
}
|
|
3191
|
+
}
|
|
3192
|
+
]
|
|
3193
|
+
},
|
|
3194
|
+
"definesHiddenTokens": false,
|
|
3195
|
+
"entry": false,
|
|
3196
|
+
"hiddenTokens": [],
|
|
3197
|
+
"parameters": [],
|
|
3198
|
+
"wildcard": false
|
|
3199
|
+
},
|
|
3200
|
+
{
|
|
3201
|
+
"$type": "ParserRule",
|
|
3202
|
+
"name": "DataField",
|
|
3161
3203
|
"definition": {
|
|
3162
3204
|
"$type": "Group",
|
|
3163
3205
|
"elements": [
|
|
@@ -3193,7 +3235,7 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
|
|
|
3193
3235
|
"terminal": {
|
|
3194
3236
|
"$type": "RuleCall",
|
|
3195
3237
|
"rule": {
|
|
3196
|
-
"$ref": "#/rules@
|
|
3238
|
+
"$ref": "#/rules@41"
|
|
3197
3239
|
},
|
|
3198
3240
|
"arguments": []
|
|
3199
3241
|
}
|
|
@@ -3222,7 +3264,7 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
|
|
|
3222
3264
|
},
|
|
3223
3265
|
{
|
|
3224
3266
|
"$type": "ParserRule",
|
|
3225
|
-
"name": "
|
|
3267
|
+
"name": "DataFieldType",
|
|
3226
3268
|
"definition": {
|
|
3227
3269
|
"$type": "Group",
|
|
3228
3270
|
"elements": [
|
|
@@ -3260,7 +3302,7 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
|
|
|
3260
3302
|
"terminal": {
|
|
3261
3303
|
"$type": "CrossReference",
|
|
3262
3304
|
"type": {
|
|
3263
|
-
"$ref": "#/types@
|
|
3305
|
+
"$ref": "#/types@2"
|
|
3264
3306
|
},
|
|
3265
3307
|
"terminal": {
|
|
3266
3308
|
"$type": "RuleCall",
|
|
@@ -3347,6 +3389,14 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
|
|
|
3347
3389
|
"arguments": []
|
|
3348
3390
|
}
|
|
3349
3391
|
},
|
|
3392
|
+
{
|
|
3393
|
+
"$type": "RuleCall",
|
|
3394
|
+
"rule": {
|
|
3395
|
+
"$ref": "#/rules@38"
|
|
3396
|
+
},
|
|
3397
|
+
"arguments": [],
|
|
3398
|
+
"cardinality": "?"
|
|
3399
|
+
},
|
|
3350
3400
|
{
|
|
3351
3401
|
"$type": "Keyword",
|
|
3352
3402
|
"value": "{"
|
|
@@ -3361,174 +3411,29 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
|
|
|
3361
3411
|
"terminal": {
|
|
3362
3412
|
"$type": "RuleCall",
|
|
3363
3413
|
"rule": {
|
|
3364
|
-
"$ref": "#/rules@
|
|
3365
|
-
},
|
|
3366
|
-
"arguments": []
|
|
3367
|
-
}
|
|
3368
|
-
},
|
|
3369
|
-
{
|
|
3370
|
-
"$type": "Assignment",
|
|
3371
|
-
"feature": "attributes",
|
|
3372
|
-
"operator": "+=",
|
|
3373
|
-
"terminal": {
|
|
3374
|
-
"$type": "RuleCall",
|
|
3375
|
-
"rule": {
|
|
3376
|
-
"$ref": "#/rules@57"
|
|
3414
|
+
"$ref": "#/rules@40"
|
|
3377
3415
|
},
|
|
3378
3416
|
"arguments": []
|
|
3379
|
-
}
|
|
3380
|
-
}
|
|
3381
|
-
],
|
|
3382
|
-
"cardinality": "*"
|
|
3383
|
-
},
|
|
3384
|
-
{
|
|
3385
|
-
"$type": "Keyword",
|
|
3386
|
-
"value": "}"
|
|
3387
|
-
}
|
|
3388
|
-
]
|
|
3389
|
-
},
|
|
3390
|
-
"definesHiddenTokens": false,
|
|
3391
|
-
"entry": false,
|
|
3392
|
-
"fragment": false,
|
|
3393
|
-
"hiddenTokens": [],
|
|
3394
|
-
"parameters": [],
|
|
3395
|
-
"wildcard": false
|
|
3396
|
-
},
|
|
3397
|
-
{
|
|
3398
|
-
"$type": "ParserRule",
|
|
3399
|
-
"name": "TypeDefField",
|
|
3400
|
-
"definition": {
|
|
3401
|
-
"$type": "Group",
|
|
3402
|
-
"elements": [
|
|
3403
|
-
{
|
|
3404
|
-
"$type": "Assignment",
|
|
3405
|
-
"feature": "comments",
|
|
3406
|
-
"operator": "+=",
|
|
3407
|
-
"terminal": {
|
|
3408
|
-
"$type": "RuleCall",
|
|
3409
|
-
"rule": {
|
|
3410
|
-
"$ref": "#/rules@71"
|
|
3411
|
-
},
|
|
3412
|
-
"arguments": []
|
|
3413
|
-
},
|
|
3414
|
-
"cardinality": "*"
|
|
3415
|
-
},
|
|
3416
|
-
{
|
|
3417
|
-
"$type": "Assignment",
|
|
3418
|
-
"feature": "name",
|
|
3419
|
-
"operator": "=",
|
|
3420
|
-
"terminal": {
|
|
3421
|
-
"$type": "RuleCall",
|
|
3422
|
-
"rule": {
|
|
3423
|
-
"$ref": "#/rules@52"
|
|
3424
|
-
},
|
|
3425
|
-
"arguments": []
|
|
3426
|
-
}
|
|
3427
|
-
},
|
|
3428
|
-
{
|
|
3429
|
-
"$type": "Assignment",
|
|
3430
|
-
"feature": "type",
|
|
3431
|
-
"operator": "=",
|
|
3432
|
-
"terminal": {
|
|
3433
|
-
"$type": "RuleCall",
|
|
3434
|
-
"rule": {
|
|
3435
|
-
"$ref": "#/rules@42"
|
|
3436
|
-
},
|
|
3437
|
-
"arguments": []
|
|
3438
|
-
}
|
|
3439
|
-
},
|
|
3440
|
-
{
|
|
3441
|
-
"$type": "Assignment",
|
|
3442
|
-
"feature": "attributes",
|
|
3443
|
-
"operator": "+=",
|
|
3444
|
-
"terminal": {
|
|
3445
|
-
"$type": "RuleCall",
|
|
3446
|
-
"rule": {
|
|
3447
|
-
"$ref": "#/rules@56"
|
|
3448
|
-
},
|
|
3449
|
-
"arguments": []
|
|
3450
|
-
},
|
|
3451
|
-
"cardinality": "*"
|
|
3452
|
-
}
|
|
3453
|
-
]
|
|
3454
|
-
},
|
|
3455
|
-
"definesHiddenTokens": false,
|
|
3456
|
-
"entry": false,
|
|
3457
|
-
"fragment": false,
|
|
3458
|
-
"hiddenTokens": [],
|
|
3459
|
-
"parameters": [],
|
|
3460
|
-
"wildcard": false
|
|
3461
|
-
},
|
|
3462
|
-
{
|
|
3463
|
-
"$type": "ParserRule",
|
|
3464
|
-
"name": "TypeDefFieldType",
|
|
3465
|
-
"definition": {
|
|
3466
|
-
"$type": "Group",
|
|
3467
|
-
"elements": [
|
|
3468
|
-
{
|
|
3469
|
-
"$type": "Alternatives",
|
|
3470
|
-
"elements": [
|
|
3471
|
-
{
|
|
3472
|
-
"$type": "Assignment",
|
|
3473
|
-
"feature": "type",
|
|
3474
|
-
"operator": "=",
|
|
3475
|
-
"terminal": {
|
|
3476
|
-
"$type": "RuleCall",
|
|
3477
|
-
"rule": {
|
|
3478
|
-
"$ref": "#/rules@62"
|
|
3479
|
-
},
|
|
3480
|
-
"arguments": []
|
|
3481
|
-
}
|
|
3482
|
-
},
|
|
3483
|
-
{
|
|
3484
|
-
"$type": "Assignment",
|
|
3485
|
-
"feature": "reference",
|
|
3486
|
-
"operator": "=",
|
|
3487
|
-
"terminal": {
|
|
3488
|
-
"$type": "CrossReference",
|
|
3489
|
-
"type": {
|
|
3490
|
-
"$ref": "#/types@2"
|
|
3491
|
-
},
|
|
3492
|
-
"terminal": {
|
|
3493
|
-
"$type": "RuleCall",
|
|
3494
|
-
"rule": {
|
|
3495
|
-
"$ref": "#/rules@51"
|
|
3496
|
-
},
|
|
3497
|
-
"arguments": []
|
|
3498
|
-
},
|
|
3499
|
-
"deprecatedSyntax": false
|
|
3500
|
-
}
|
|
3501
|
-
}
|
|
3502
|
-
]
|
|
3503
|
-
},
|
|
3504
|
-
{
|
|
3505
|
-
"$type": "Group",
|
|
3506
|
-
"elements": [
|
|
3417
|
+
}
|
|
3418
|
+
},
|
|
3507
3419
|
{
|
|
3508
3420
|
"$type": "Assignment",
|
|
3509
|
-
"feature": "
|
|
3510
|
-
"operator": "
|
|
3421
|
+
"feature": "attributes",
|
|
3422
|
+
"operator": "+=",
|
|
3511
3423
|
"terminal": {
|
|
3512
|
-
"$type": "
|
|
3513
|
-
"
|
|
3424
|
+
"$type": "RuleCall",
|
|
3425
|
+
"rule": {
|
|
3426
|
+
"$ref": "#/rules@57"
|
|
3427
|
+
},
|
|
3428
|
+
"arguments": []
|
|
3514
3429
|
}
|
|
3515
|
-
},
|
|
3516
|
-
{
|
|
3517
|
-
"$type": "Keyword",
|
|
3518
|
-
"value": "]"
|
|
3519
3430
|
}
|
|
3520
3431
|
],
|
|
3521
|
-
"cardinality": "
|
|
3432
|
+
"cardinality": "*"
|
|
3522
3433
|
},
|
|
3523
3434
|
{
|
|
3524
|
-
"$type": "
|
|
3525
|
-
"
|
|
3526
|
-
"operator": "?=",
|
|
3527
|
-
"terminal": {
|
|
3528
|
-
"$type": "Keyword",
|
|
3529
|
-
"value": "?"
|
|
3530
|
-
},
|
|
3531
|
-
"cardinality": "?"
|
|
3435
|
+
"$type": "Keyword",
|
|
3436
|
+
"value": "}"
|
|
3532
3437
|
}
|
|
3533
3438
|
]
|
|
3534
3439
|
},
|
|
@@ -3939,7 +3844,7 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
|
|
|
3939
3844
|
"terminal": {
|
|
3940
3845
|
"$type": "CrossReference",
|
|
3941
3846
|
"type": {
|
|
3942
|
-
"$ref": "#/types@
|
|
3847
|
+
"$ref": "#/types@2"
|
|
3943
3848
|
},
|
|
3944
3849
|
"terminal": {
|
|
3945
3850
|
"$type": "RuleCall",
|
|
@@ -4553,7 +4458,7 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
|
|
|
4553
4458
|
"terminal": {
|
|
4554
4459
|
"$type": "CrossReference",
|
|
4555
4460
|
"type": {
|
|
4556
|
-
"$ref": "#/types@
|
|
4461
|
+
"$ref": "#/types@2"
|
|
4557
4462
|
},
|
|
4558
4463
|
"terminal": {
|
|
4559
4464
|
"$type": "RuleCall",
|
|
@@ -4607,7 +4512,7 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
|
|
|
4607
4512
|
},
|
|
4608
4513
|
{
|
|
4609
4514
|
"$type": "ParserRule",
|
|
4610
|
-
"name": "
|
|
4515
|
+
"name": "DataFieldAttribute",
|
|
4611
4516
|
"definition": {
|
|
4612
4517
|
"$type": "Group",
|
|
4613
4518
|
"elements": [
|
|
@@ -5124,13 +5029,7 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
|
|
|
5124
5029
|
{
|
|
5125
5030
|
"$type": "SimpleType",
|
|
5126
5031
|
"typeRef": {
|
|
5127
|
-
"$ref": "#/rules@
|
|
5128
|
-
}
|
|
5129
|
-
},
|
|
5130
|
-
{
|
|
5131
|
-
"$type": "SimpleType",
|
|
5132
|
-
"typeRef": {
|
|
5133
|
-
"$ref": "#/rules@41"
|
|
5032
|
+
"$ref": "#/rules@40"
|
|
5134
5033
|
}
|
|
5135
5034
|
},
|
|
5136
5035
|
{
|
|
@@ -5146,42 +5045,10 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
|
|
|
5146
5045
|
"$type": "Type",
|
|
5147
5046
|
"name": "MemberAccessTarget",
|
|
5148
5047
|
"type": {
|
|
5149
|
-
"$type": "
|
|
5150
|
-
"
|
|
5151
|
-
|
|
5152
|
-
|
|
5153
|
-
"typeRef": {
|
|
5154
|
-
"$ref": "#/rules@38"
|
|
5155
|
-
}
|
|
5156
|
-
},
|
|
5157
|
-
{
|
|
5158
|
-
"$type": "SimpleType",
|
|
5159
|
-
"typeRef": {
|
|
5160
|
-
"$ref": "#/rules@41"
|
|
5161
|
-
}
|
|
5162
|
-
}
|
|
5163
|
-
]
|
|
5164
|
-
}
|
|
5165
|
-
},
|
|
5166
|
-
{
|
|
5167
|
-
"$type": "Type",
|
|
5168
|
-
"name": "TypeDefFieldTypes",
|
|
5169
|
-
"type": {
|
|
5170
|
-
"$type": "UnionType",
|
|
5171
|
-
"types": [
|
|
5172
|
-
{
|
|
5173
|
-
"$type": "SimpleType",
|
|
5174
|
-
"typeRef": {
|
|
5175
|
-
"$ref": "#/rules@40"
|
|
5176
|
-
}
|
|
5177
|
-
},
|
|
5178
|
-
{
|
|
5179
|
-
"$type": "SimpleType",
|
|
5180
|
-
"typeRef": {
|
|
5181
|
-
"$ref": "#/rules@44"
|
|
5182
|
-
}
|
|
5183
|
-
}
|
|
5184
|
-
]
|
|
5048
|
+
"$type": "SimpleType",
|
|
5049
|
+
"typeRef": {
|
|
5050
|
+
"$ref": "#/rules@40"
|
|
5051
|
+
}
|
|
5185
5052
|
}
|
|
5186
5053
|
},
|
|
5187
5054
|
{
|
|
@@ -5199,7 +5066,7 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
|
|
|
5199
5066
|
{
|
|
5200
5067
|
"$type": "SimpleType",
|
|
5201
5068
|
"typeRef": {
|
|
5202
|
-
"$ref": "#/rules@
|
|
5069
|
+
"$ref": "#/rules@42"
|
|
5203
5070
|
}
|
|
5204
5071
|
},
|
|
5205
5072
|
{
|
|
@@ -5221,7 +5088,7 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
|
|
|
5221
5088
|
|
|
5222
5089
|
// src/generated/module.ts
|
|
5223
5090
|
var ZModelLanguageMetaData = {
|
|
5224
|
-
languageId: "zmodel",
|
|
5091
|
+
languageId: "zmodel-v3",
|
|
5225
5092
|
fileExtensions: [
|
|
5226
5093
|
".zmodel"
|
|
5227
5094
|
],
|
|
@@ -5242,9 +5109,10 @@ import { AstUtils as AstUtils2 } from "langium";
|
|
|
5242
5109
|
import pluralize from "pluralize";
|
|
5243
5110
|
|
|
5244
5111
|
// src/utils.ts
|
|
5112
|
+
import { invariant } from "@zenstackhq/common-helpers";
|
|
5245
5113
|
import { AstUtils, URI } from "langium";
|
|
5246
|
-
import path from "path";
|
|
5247
5114
|
import fs from "fs";
|
|
5115
|
+
import path from "path";
|
|
5248
5116
|
function hasAttribute(decl, name) {
|
|
5249
5117
|
return !!getAttribute(decl, name);
|
|
5250
5118
|
}
|
|
@@ -5316,10 +5184,10 @@ function isEnumFieldReference(node) {
|
|
|
5316
5184
|
return isReferenceExpr(node) && isEnumField(node.target.ref);
|
|
5317
5185
|
}
|
|
5318
5186
|
__name(isEnumFieldReference, "isEnumFieldReference");
|
|
5319
|
-
function
|
|
5320
|
-
return isReferenceExpr(node) &&
|
|
5187
|
+
function isDataFieldReference(node) {
|
|
5188
|
+
return isReferenceExpr(node) && isDataField(node.target.ref);
|
|
5321
5189
|
}
|
|
5322
|
-
__name(
|
|
5190
|
+
__name(isDataFieldReference, "isDataFieldReference");
|
|
5323
5191
|
function isRelationshipField(field) {
|
|
5324
5192
|
return isDataModel(field.type.reference?.ref);
|
|
5325
5193
|
}
|
|
@@ -5339,43 +5207,14 @@ function resolved(ref) {
|
|
|
5339
5207
|
return ref.ref;
|
|
5340
5208
|
}
|
|
5341
5209
|
__name(resolved, "resolved");
|
|
5342
|
-
function
|
|
5343
|
-
for (const base of start.superTypes) {
|
|
5344
|
-
if (base.ref === target) {
|
|
5345
|
-
return [
|
|
5346
|
-
base.ref
|
|
5347
|
-
];
|
|
5348
|
-
}
|
|
5349
|
-
const path4 = findUpInheritance(base.ref, target);
|
|
5350
|
-
if (path4) {
|
|
5351
|
-
return [
|
|
5352
|
-
base.ref,
|
|
5353
|
-
...path4
|
|
5354
|
-
];
|
|
5355
|
-
}
|
|
5356
|
-
}
|
|
5357
|
-
return void 0;
|
|
5358
|
-
}
|
|
5359
|
-
__name(findUpInheritance, "findUpInheritance");
|
|
5360
|
-
function getModelFieldsWithBases(model, includeDelegate = true) {
|
|
5361
|
-
if (model.$baseMerged) {
|
|
5362
|
-
return model.fields;
|
|
5363
|
-
} else {
|
|
5364
|
-
return [
|
|
5365
|
-
...model.fields,
|
|
5366
|
-
...getRecursiveBases(model, includeDelegate).flatMap((base) => base.fields)
|
|
5367
|
-
];
|
|
5368
|
-
}
|
|
5369
|
-
}
|
|
5370
|
-
__name(getModelFieldsWithBases, "getModelFieldsWithBases");
|
|
5371
|
-
function getRecursiveBases(dataModel, includeDelegate = true, seen = /* @__PURE__ */ new Set()) {
|
|
5210
|
+
function getRecursiveBases(decl, includeDelegate = true, seen = /* @__PURE__ */ new Set()) {
|
|
5372
5211
|
const result = [];
|
|
5373
|
-
if (seen.has(
|
|
5212
|
+
if (seen.has(decl)) {
|
|
5374
5213
|
return result;
|
|
5375
5214
|
}
|
|
5376
|
-
seen.add(
|
|
5377
|
-
|
|
5378
|
-
const baseDecl =
|
|
5215
|
+
seen.add(decl);
|
|
5216
|
+
decl.mixins.forEach((mixin) => {
|
|
5217
|
+
const baseDecl = mixin.ref;
|
|
5379
5218
|
if (baseDecl) {
|
|
5380
5219
|
if (!includeDelegate && isDelegateModel(baseDecl)) {
|
|
5381
5220
|
return;
|
|
@@ -5388,14 +5227,13 @@ function getRecursiveBases(dataModel, includeDelegate = true, seen = /* @__PURE_
|
|
|
5388
5227
|
}
|
|
5389
5228
|
__name(getRecursiveBases, "getRecursiveBases");
|
|
5390
5229
|
function getModelIdFields(model) {
|
|
5391
|
-
const modelsToCheck =
|
|
5392
|
-
model
|
|
5393
|
-
] : [
|
|
5230
|
+
const modelsToCheck = [
|
|
5394
5231
|
model,
|
|
5395
5232
|
...getRecursiveBases(model)
|
|
5396
5233
|
];
|
|
5397
5234
|
for (const modelToCheck of modelsToCheck) {
|
|
5398
|
-
const
|
|
5235
|
+
const allAttributes = getAllAttributes(modelToCheck);
|
|
5236
|
+
const idAttr = allAttributes.find((attr) => attr.decl.$refText === "@@id");
|
|
5399
5237
|
if (!idAttr) {
|
|
5400
5238
|
continue;
|
|
5401
5239
|
}
|
|
@@ -5409,14 +5247,13 @@ function getModelIdFields(model) {
|
|
|
5409
5247
|
}
|
|
5410
5248
|
__name(getModelIdFields, "getModelIdFields");
|
|
5411
5249
|
function getModelUniqueFields(model) {
|
|
5412
|
-
const modelsToCheck =
|
|
5413
|
-
model
|
|
5414
|
-
] : [
|
|
5250
|
+
const modelsToCheck = [
|
|
5415
5251
|
model,
|
|
5416
5252
|
...getRecursiveBases(model)
|
|
5417
5253
|
];
|
|
5418
5254
|
for (const modelToCheck of modelsToCheck) {
|
|
5419
|
-
const
|
|
5255
|
+
const allAttributes = getAllAttributes(modelToCheck);
|
|
5256
|
+
const uniqueAttr = allAttributes.find((attr) => attr.decl.$refText === "@@unique");
|
|
5420
5257
|
if (!uniqueAttr) {
|
|
5421
5258
|
continue;
|
|
5422
5259
|
}
|
|
@@ -5563,34 +5400,24 @@ function resolveImport(documents, imp) {
|
|
|
5563
5400
|
}
|
|
5564
5401
|
__name(resolveImport, "resolveImport");
|
|
5565
5402
|
function resolveImportUri(imp) {
|
|
5566
|
-
if (!imp.path)
|
|
5567
|
-
|
|
5568
|
-
imp.path += ".zmodel";
|
|
5569
|
-
}
|
|
5570
|
-
if (!imp.path.startsWith(".") && // Respect relative paths
|
|
5571
|
-
!path.isAbsolute(imp.path)) {
|
|
5572
|
-
const contextPath = imp.$container.$document ? path.dirname(imp.$container.$document.uri.fsPath) : process.cwd();
|
|
5573
|
-
imp.path = findNodeModulesFile(imp.path, contextPath) ?? imp.path;
|
|
5403
|
+
if (!imp.path) {
|
|
5404
|
+
return void 0;
|
|
5574
5405
|
}
|
|
5575
5406
|
const doc = AstUtils.getDocument(imp);
|
|
5576
5407
|
const dir = path.dirname(doc.uri.fsPath);
|
|
5577
|
-
|
|
5408
|
+
const importPath = imp.path.endsWith(".zmodel") ? imp.path : `${imp.path}.zmodel`;
|
|
5409
|
+
return URI.file(path.resolve(dir, importPath));
|
|
5578
5410
|
}
|
|
5579
5411
|
__name(resolveImportUri, "resolveImportUri");
|
|
5580
|
-
function
|
|
5581
|
-
|
|
5582
|
-
|
|
5583
|
-
|
|
5584
|
-
|
|
5585
|
-
|
|
5586
|
-
]
|
|
5587
|
-
});
|
|
5588
|
-
return resolvedPath;
|
|
5589
|
-
} catch {
|
|
5590
|
-
return void 0;
|
|
5412
|
+
function getDataModelAndTypeDefs(model, includeIgnored = false) {
|
|
5413
|
+
const r = model.declarations.filter((d) => isDataModel(d) || isTypeDef(d));
|
|
5414
|
+
if (includeIgnored) {
|
|
5415
|
+
return r;
|
|
5416
|
+
} else {
|
|
5417
|
+
return r.filter((model2) => !hasAttribute(model2, "@@ignore"));
|
|
5591
5418
|
}
|
|
5592
5419
|
}
|
|
5593
|
-
__name(
|
|
5420
|
+
__name(getDataModelAndTypeDefs, "getDataModelAndTypeDefs");
|
|
5594
5421
|
function getAllDeclarationsIncludingImports(documents, model) {
|
|
5595
5422
|
const imports = resolveTransitiveImports(documents, model);
|
|
5596
5423
|
return model.declarations.concat(...imports.map((imp) => imp.declarations));
|
|
@@ -5655,6 +5482,58 @@ function isMemberContainer(node) {
|
|
|
5655
5482
|
return isDataModel(node) || isTypeDef(node);
|
|
5656
5483
|
}
|
|
5657
5484
|
__name(isMemberContainer, "isMemberContainer");
|
|
5485
|
+
function getAllFields(decl, includeIgnored = false, seen = /* @__PURE__ */ new Set()) {
|
|
5486
|
+
if (seen.has(decl)) {
|
|
5487
|
+
return [];
|
|
5488
|
+
}
|
|
5489
|
+
seen.add(decl);
|
|
5490
|
+
const fields = [];
|
|
5491
|
+
for (const mixin of decl.mixins) {
|
|
5492
|
+
invariant(mixin.ref, `Mixin ${mixin.$refText} is not resolved`);
|
|
5493
|
+
fields.push(...getAllFields(mixin.ref, includeIgnored, seen));
|
|
5494
|
+
}
|
|
5495
|
+
if (isDataModel(decl) && decl.baseModel) {
|
|
5496
|
+
invariant(decl.baseModel.ref, `Base model ${decl.baseModel.$refText} is not resolved`);
|
|
5497
|
+
fields.push(...getAllFields(decl.baseModel.ref, includeIgnored, seen));
|
|
5498
|
+
}
|
|
5499
|
+
fields.push(...decl.fields.filter((f) => includeIgnored || !hasAttribute(f, "@ignore")));
|
|
5500
|
+
return fields;
|
|
5501
|
+
}
|
|
5502
|
+
__name(getAllFields, "getAllFields");
|
|
5503
|
+
function getAllAttributes(decl, seen = /* @__PURE__ */ new Set()) {
|
|
5504
|
+
if (seen.has(decl)) {
|
|
5505
|
+
return [];
|
|
5506
|
+
}
|
|
5507
|
+
seen.add(decl);
|
|
5508
|
+
const attributes = [];
|
|
5509
|
+
for (const mixin of decl.mixins) {
|
|
5510
|
+
invariant(mixin.ref, `Mixin ${mixin.$refText} is not resolved`);
|
|
5511
|
+
attributes.push(...getAllAttributes(mixin.ref, seen));
|
|
5512
|
+
}
|
|
5513
|
+
if (isDataModel(decl) && decl.baseModel) {
|
|
5514
|
+
invariant(decl.baseModel.ref, `Base model ${decl.baseModel.$refText} is not resolved`);
|
|
5515
|
+
attributes.push(...getAllAttributes(decl.baseModel.ref, seen));
|
|
5516
|
+
}
|
|
5517
|
+
attributes.push(...decl.attributes);
|
|
5518
|
+
return attributes;
|
|
5519
|
+
}
|
|
5520
|
+
__name(getAllAttributes, "getAllAttributes");
|
|
5521
|
+
function getDocument(node) {
|
|
5522
|
+
const rootNode = findRootNode(node);
|
|
5523
|
+
const result = rootNode.$document;
|
|
5524
|
+
if (!result) {
|
|
5525
|
+
throw new Error("AST node has no document.");
|
|
5526
|
+
}
|
|
5527
|
+
return result;
|
|
5528
|
+
}
|
|
5529
|
+
__name(getDocument, "getDocument");
|
|
5530
|
+
function findRootNode(node) {
|
|
5531
|
+
while (node.$container) {
|
|
5532
|
+
node = node.$container;
|
|
5533
|
+
}
|
|
5534
|
+
return node;
|
|
5535
|
+
}
|
|
5536
|
+
__name(findRootNode, "findRootNode");
|
|
5658
5537
|
|
|
5659
5538
|
// src/validators/attribute-application-validator.ts
|
|
5660
5539
|
function _ts_decorate(decorators, target, key, desc) {
|
|
@@ -5682,7 +5561,7 @@ var AttributeApplicationValidator = class {
|
|
|
5682
5561
|
static {
|
|
5683
5562
|
__name(this, "AttributeApplicationValidator");
|
|
5684
5563
|
}
|
|
5685
|
-
validate(attr, accept) {
|
|
5564
|
+
validate(attr, accept, contextDataModel) {
|
|
5686
5565
|
const decl = attr.decl.ref;
|
|
5687
5566
|
if (!decl) {
|
|
5688
5567
|
return;
|
|
@@ -5694,21 +5573,13 @@ var AttributeApplicationValidator = class {
|
|
|
5694
5573
|
});
|
|
5695
5574
|
return;
|
|
5696
5575
|
}
|
|
5697
|
-
if (
|
|
5576
|
+
if (isDataField(targetDecl) && !isValidAttributeTarget(decl, targetDecl)) {
|
|
5698
5577
|
accept("error", `attribute "${decl.name}" cannot be used on this type of field`, {
|
|
5699
5578
|
node: attr
|
|
5700
5579
|
});
|
|
5701
5580
|
}
|
|
5702
|
-
|
|
5703
|
-
|
|
5704
|
-
node: attr
|
|
5705
|
-
});
|
|
5706
|
-
}
|
|
5707
|
-
if (isTypeDef(targetDecl) && !hasAttribute(decl, "@@@supportTypeDef")) {
|
|
5708
|
-
accept("error", `attribute "${decl.name}" cannot be used on type declarations`, {
|
|
5709
|
-
node: attr
|
|
5710
|
-
});
|
|
5711
|
-
}
|
|
5581
|
+
this.checkDeprecation(attr, accept);
|
|
5582
|
+
this.checkDuplicatedAttributes(attr, accept, contextDataModel);
|
|
5712
5583
|
const filledParams = /* @__PURE__ */ new Set();
|
|
5713
5584
|
for (const arg of attr.args) {
|
|
5714
5585
|
let paramDecl;
|
|
@@ -5756,6 +5627,28 @@ var AttributeApplicationValidator = class {
|
|
|
5756
5627
|
checker.value.call(this, attr, accept);
|
|
5757
5628
|
}
|
|
5758
5629
|
}
|
|
5630
|
+
checkDeprecation(attr, accept) {
|
|
5631
|
+
const deprecateAttr = attr.decl.ref?.attributes.find((a) => a.decl.ref?.name === "@@@deprecated");
|
|
5632
|
+
if (deprecateAttr) {
|
|
5633
|
+
const message = getStringLiteral(deprecateAttr.args[0]?.value) ?? `Attribute "${attr.decl.ref?.name}" is deprecated`;
|
|
5634
|
+
accept("warning", message, {
|
|
5635
|
+
node: attr
|
|
5636
|
+
});
|
|
5637
|
+
}
|
|
5638
|
+
}
|
|
5639
|
+
checkDuplicatedAttributes(attr, accept, contextDataModel) {
|
|
5640
|
+
const attrDecl = attr.decl.ref;
|
|
5641
|
+
if (!attrDecl?.attributes.some((a) => a.decl.ref?.name === "@@@once")) {
|
|
5642
|
+
return;
|
|
5643
|
+
}
|
|
5644
|
+
const allAttributes = contextDataModel ? getAllAttributes(contextDataModel) : attr.$container.attributes;
|
|
5645
|
+
const duplicates = allAttributes.filter((a) => a.decl.ref === attrDecl && a !== attr);
|
|
5646
|
+
if (duplicates.length > 0) {
|
|
5647
|
+
accept("error", `Attribute "${attrDecl.name}" can only be applied once`, {
|
|
5648
|
+
node: attr
|
|
5649
|
+
});
|
|
5650
|
+
}
|
|
5651
|
+
}
|
|
5759
5652
|
_checkModelLevelPolicy(attr, accept) {
|
|
5760
5653
|
const kind = getStringLiteral(attr.args[0]?.value);
|
|
5761
5654
|
if (!kind) {
|
|
@@ -5804,7 +5697,7 @@ var AttributeApplicationValidator = class {
|
|
|
5804
5697
|
}
|
|
5805
5698
|
_checkValidate(attr, accept) {
|
|
5806
5699
|
const condition = attr.args[0]?.value;
|
|
5807
|
-
if (condition && AstUtils2.streamAst(condition).some((node) =>
|
|
5700
|
+
if (condition && AstUtils2.streamAst(condition).some((node) => isDataFieldReference(node) && isDataModel(node.$resolvedType?.decl))) {
|
|
5808
5701
|
accept("error", `\`@@validate\` condition cannot use relation fields`, {
|
|
5809
5702
|
node: condition
|
|
5810
5703
|
});
|
|
@@ -5813,9 +5706,18 @@ var AttributeApplicationValidator = class {
|
|
|
5813
5706
|
_checkUnique(attr, accept) {
|
|
5814
5707
|
const fields = attr.args[0]?.value;
|
|
5815
5708
|
if (!fields) {
|
|
5709
|
+
accept("error", `expects an array of field references`, {
|
|
5710
|
+
node: attr.args[0]
|
|
5711
|
+
});
|
|
5816
5712
|
return;
|
|
5817
5713
|
}
|
|
5818
5714
|
if (isArrayExpr(fields)) {
|
|
5715
|
+
if (fields.items.length === 0) {
|
|
5716
|
+
accept("error", `\`@@unique\` expects at least one field reference`, {
|
|
5717
|
+
node: fields
|
|
5718
|
+
});
|
|
5719
|
+
return;
|
|
5720
|
+
}
|
|
5819
5721
|
fields.items.forEach((item) => {
|
|
5820
5722
|
if (!isReferenceExpr(item)) {
|
|
5821
5723
|
accept("error", `Expecting a field reference`, {
|
|
@@ -5823,7 +5725,7 @@ var AttributeApplicationValidator = class {
|
|
|
5823
5725
|
});
|
|
5824
5726
|
return;
|
|
5825
5727
|
}
|
|
5826
|
-
if (!
|
|
5728
|
+
if (!isDataField(item.target.ref)) {
|
|
5827
5729
|
accept("error", `Expecting a field reference`, {
|
|
5828
5730
|
node: item
|
|
5829
5731
|
});
|
|
@@ -5843,7 +5745,7 @@ var AttributeApplicationValidator = class {
|
|
|
5843
5745
|
}
|
|
5844
5746
|
rejectEncryptedFields(attr, accept) {
|
|
5845
5747
|
AstUtils2.streamAllContents(attr).forEach((node) => {
|
|
5846
|
-
if (
|
|
5748
|
+
if (isDataFieldReference(node) && hasAttribute(node.target.ref, "@encrypted")) {
|
|
5847
5749
|
accept("error", `Encrypted fields cannot be used in policy rules`, {
|
|
5848
5750
|
node
|
|
5849
5751
|
});
|
|
@@ -5893,6 +5795,7 @@ _ts_decorate([
|
|
|
5893
5795
|
], AttributeApplicationValidator.prototype, "_checkValidate", null);
|
|
5894
5796
|
_ts_decorate([
|
|
5895
5797
|
check("@@unique"),
|
|
5798
|
+
check("@@id"),
|
|
5896
5799
|
_ts_metadata("design:type", Function),
|
|
5897
5800
|
_ts_metadata("design:paramtypes", [
|
|
5898
5801
|
typeof AttributeApplication === "undefined" ? Object : AttributeApplication,
|
|
@@ -5908,7 +5811,7 @@ function assignableToAttributeParam(arg, param, attr) {
|
|
|
5908
5811
|
let dstType = param.type.type;
|
|
5909
5812
|
let dstIsArray = param.type.array;
|
|
5910
5813
|
if (dstType === "ContextType") {
|
|
5911
|
-
if (
|
|
5814
|
+
if (isDataField(attr.$container)) {
|
|
5912
5815
|
dstIsArray = attr.$container.type.array;
|
|
5913
5816
|
}
|
|
5914
5817
|
}
|
|
@@ -5925,14 +5828,14 @@ function assignableToAttributeParam(arg, param, attr) {
|
|
|
5925
5828
|
}
|
|
5926
5829
|
if (dstType === "FieldReference" || dstType === "TransitiveFieldReference") {
|
|
5927
5830
|
if (dstIsArray) {
|
|
5928
|
-
return isArrayExpr(arg.value) && !arg.value.items.find((item) => !isReferenceExpr(item) || !
|
|
5831
|
+
return isArrayExpr(arg.value) && !arg.value.items.find((item) => !isReferenceExpr(item) || !isDataField(item.target.ref));
|
|
5929
5832
|
} else {
|
|
5930
|
-
return isReferenceExpr(arg.value) &&
|
|
5833
|
+
return isReferenceExpr(arg.value) && isDataField(arg.value.target.ref);
|
|
5931
5834
|
}
|
|
5932
5835
|
}
|
|
5933
5836
|
if (isEnum(argResolvedType.decl)) {
|
|
5934
5837
|
let attrArgDeclType = dstRef?.ref;
|
|
5935
|
-
if (dstType === "ContextType" &&
|
|
5838
|
+
if (dstType === "ContextType" && isDataField(attr.$container) && attr.$container?.type?.reference) {
|
|
5936
5839
|
attrArgDeclType = resolved(attr.$container.type.reference);
|
|
5937
5840
|
dstIsArray = attr.$container.type.array;
|
|
5938
5841
|
}
|
|
@@ -5942,7 +5845,7 @@ function assignableToAttributeParam(arg, param, attr) {
|
|
|
5942
5845
|
return false;
|
|
5943
5846
|
}
|
|
5944
5847
|
if (dstType === "ContextType") {
|
|
5945
|
-
if (
|
|
5848
|
+
if (isDataField(attr.$container)) {
|
|
5946
5849
|
if (!attr.$container?.type?.type) {
|
|
5947
5850
|
return false;
|
|
5948
5851
|
}
|
|
@@ -6010,8 +5913,8 @@ function isValidAttributeTarget(attrDecl, targetDecl) {
|
|
|
6010
5913
|
return allowed;
|
|
6011
5914
|
}
|
|
6012
5915
|
__name(isValidAttributeTarget, "isValidAttributeTarget");
|
|
6013
|
-
function validateAttributeApplication(attr, accept) {
|
|
6014
|
-
new AttributeApplicationValidator().validate(attr, accept);
|
|
5916
|
+
function validateAttributeApplication(attr, accept, contextDataModel) {
|
|
5917
|
+
new AttributeApplicationValidator().validate(attr, accept, contextDataModel);
|
|
6015
5918
|
}
|
|
6016
5919
|
__name(validateAttributeApplication, "validateAttributeApplication");
|
|
6017
5920
|
|
|
@@ -6026,6 +5929,7 @@ var AttributeValidator = class {
|
|
|
6026
5929
|
};
|
|
6027
5930
|
|
|
6028
5931
|
// src/validators/datamodel-validator.ts
|
|
5932
|
+
import { invariant as invariant2 } from "@zenstackhq/common-helpers";
|
|
6029
5933
|
import { AstUtils as AstUtils3 } from "langium";
|
|
6030
5934
|
|
|
6031
5935
|
// src/validators/common.ts
|
|
@@ -6038,8 +5942,8 @@ function validateDuplicatedDeclarations(container, decls, accept) {
|
|
|
6038
5942
|
for (const [name, decls2] of Object.entries(groupByName)) {
|
|
6039
5943
|
if (decls2.length > 1) {
|
|
6040
5944
|
let errorField = decls2[1];
|
|
6041
|
-
if (
|
|
6042
|
-
const nonInheritedFields = decls2.filter((x) => !(
|
|
5945
|
+
if (isDataField(decls2[0])) {
|
|
5946
|
+
const nonInheritedFields = decls2.filter((x) => !(isDataField(x) && x.$container !== container));
|
|
6043
5947
|
if (nonInheritedFields.length > 0) {
|
|
6044
5948
|
errorField = nonInheritedFields.slice(-1)[0];
|
|
6045
5949
|
}
|
|
@@ -6058,22 +5962,21 @@ var DataModelValidator = class {
|
|
|
6058
5962
|
__name(this, "DataModelValidator");
|
|
6059
5963
|
}
|
|
6060
5964
|
validate(dm, accept) {
|
|
6061
|
-
|
|
6062
|
-
this.validateBaseDelegateModel(dm, accept);
|
|
6063
|
-
validateDuplicatedDeclarations(dm, getModelFieldsWithBases(dm), accept);
|
|
5965
|
+
validateDuplicatedDeclarations(dm, getAllFields(dm), accept);
|
|
6064
5966
|
this.validateAttributes(dm, accept);
|
|
6065
5967
|
this.validateFields(dm, accept);
|
|
6066
|
-
if (dm.
|
|
6067
|
-
this.
|
|
5968
|
+
if (dm.mixins.length > 0) {
|
|
5969
|
+
this.validateMixins(dm, accept);
|
|
6068
5970
|
}
|
|
5971
|
+
this.validateInherits(dm, accept);
|
|
6069
5972
|
}
|
|
6070
5973
|
validateFields(dm, accept) {
|
|
6071
|
-
const allFields =
|
|
5974
|
+
const allFields = getAllFields(dm);
|
|
6072
5975
|
const idFields = allFields.filter((f) => f.attributes.find((attr) => attr.decl.ref?.name === "@id"));
|
|
6073
5976
|
const uniqueFields = allFields.filter((f) => f.attributes.find((attr) => attr.decl.ref?.name === "@unique"));
|
|
6074
5977
|
const modelLevelIds = getModelIdFields(dm);
|
|
6075
5978
|
const modelUniqueFields = getModelUniqueFields(dm);
|
|
6076
|
-
if (
|
|
5979
|
+
if (idFields.length === 0 && modelLevelIds.length === 0 && uniqueFields.length === 0 && modelUniqueFields.length === 0) {
|
|
6077
5980
|
accept("error", "Model must have at least one unique criteria. Either mark a single field with `@id`, `@unique` or add a multi field criterion with `@@id([])` or `@@unique([])` to the model.", {
|
|
6078
5981
|
node: dm
|
|
6079
5982
|
});
|
|
@@ -6104,11 +6007,9 @@ var DataModelValidator = class {
|
|
|
6104
6007
|
});
|
|
6105
6008
|
}
|
|
6106
6009
|
dm.fields.forEach((field) => this.validateField(field, accept));
|
|
6107
|
-
|
|
6108
|
-
|
|
6109
|
-
|
|
6110
|
-
});
|
|
6111
|
-
}
|
|
6010
|
+
allFields.filter((x) => isDataModel(x.type.reference?.ref)).forEach((y) => {
|
|
6011
|
+
this.validateRelationField(dm, y, accept);
|
|
6012
|
+
});
|
|
6112
6013
|
}
|
|
6113
6014
|
validateField(field, accept) {
|
|
6114
6015
|
if (field.type.array && field.type.optional) {
|
|
@@ -6124,7 +6025,7 @@ var DataModelValidator = class {
|
|
|
6124
6025
|
if (field.type.array && !isDataModel(field.type.reference?.ref)) {
|
|
6125
6026
|
const provider = this.getDataSourceProvider(AstUtils3.getContainerOfType(field, isModel));
|
|
6126
6027
|
if (provider === "sqlite") {
|
|
6127
|
-
accept("error", `
|
|
6028
|
+
accept("error", `List type is not supported for "${provider}" provider.`, {
|
|
6128
6029
|
node: field.type
|
|
6129
6030
|
});
|
|
6130
6031
|
}
|
|
@@ -6150,7 +6051,7 @@ var DataModelValidator = class {
|
|
|
6150
6051
|
return getLiteral(provider.value);
|
|
6151
6052
|
}
|
|
6152
6053
|
validateAttributes(dm, accept) {
|
|
6153
|
-
dm.
|
|
6054
|
+
getAllAttributes(dm).forEach((attr) => validateAttributeApplication(attr, accept, dm));
|
|
6154
6055
|
}
|
|
6155
6056
|
parseRelation(field, accept) {
|
|
6156
6057
|
const relAttr = field.attributes.find((attr) => attr.decl.ref?.name === "@relation");
|
|
@@ -6269,11 +6170,20 @@ var DataModelValidator = class {
|
|
|
6269
6170
|
if (!thisRelation.valid) {
|
|
6270
6171
|
return;
|
|
6271
6172
|
}
|
|
6272
|
-
if (this.isFieldInheritedFromDelegateModel(field
|
|
6173
|
+
if (this.isFieldInheritedFromDelegateModel(field)) {
|
|
6273
6174
|
return;
|
|
6274
6175
|
}
|
|
6176
|
+
if (this.isSelfRelation(field)) {
|
|
6177
|
+
if (!thisRelation.name) {
|
|
6178
|
+
accept("error", "Self-relation field must have a name in @relation attribute", {
|
|
6179
|
+
node: field
|
|
6180
|
+
});
|
|
6181
|
+
return;
|
|
6182
|
+
}
|
|
6183
|
+
}
|
|
6275
6184
|
const oppositeModel = field.type.reference.ref;
|
|
6276
|
-
let oppositeFields =
|
|
6185
|
+
let oppositeFields = getAllFields(oppositeModel, false).filter((f) => f !== field && // exclude self in case of self relation
|
|
6186
|
+
f.type.reference?.ref?.name === contextModel.name);
|
|
6277
6187
|
oppositeFields = oppositeFields.filter((f) => {
|
|
6278
6188
|
const fieldRel = this.parseRelation(f);
|
|
6279
6189
|
return fieldRel.valid && fieldRel.name === thisRelation.name;
|
|
@@ -6310,26 +6220,37 @@ var DataModelValidator = class {
|
|
|
6310
6220
|
const oppositeField = oppositeFields[0];
|
|
6311
6221
|
const oppositeRelation = this.parseRelation(oppositeField);
|
|
6312
6222
|
let relationOwner;
|
|
6313
|
-
if (
|
|
6314
|
-
|
|
6315
|
-
|
|
6316
|
-
|
|
6317
|
-
|
|
6318
|
-
|
|
6319
|
-
|
|
6320
|
-
|
|
6321
|
-
|
|
6322
|
-
|
|
6323
|
-
if (thisRelation?.references || thisRelation?.fields) {
|
|
6324
|
-
accept("error", '"fields" and "references" must be provided only on one side of relation field', {
|
|
6325
|
-
node: field
|
|
6326
|
-
});
|
|
6327
|
-
return;
|
|
6328
|
-
} else {
|
|
6329
|
-
relationOwner = field;
|
|
6223
|
+
if (field.type.array && oppositeField.type.array) {
|
|
6224
|
+
for (const r of [
|
|
6225
|
+
thisRelation,
|
|
6226
|
+
oppositeRelation
|
|
6227
|
+
]) {
|
|
6228
|
+
if (r.fields?.length || r.references?.length) {
|
|
6229
|
+
accept("error", 'Implicit many-to-many relation cannot have "fields" or "references" in @relation attribute', {
|
|
6230
|
+
node: r === thisRelation ? field : oppositeField
|
|
6231
|
+
});
|
|
6232
|
+
}
|
|
6330
6233
|
}
|
|
6331
6234
|
} else {
|
|
6332
|
-
if (
|
|
6235
|
+
if (thisRelation?.references?.length && thisRelation.fields?.length) {
|
|
6236
|
+
if (oppositeRelation?.references || oppositeRelation?.fields) {
|
|
6237
|
+
accept("error", '"fields" and "references" must be provided only on one side of relation field', {
|
|
6238
|
+
node: oppositeField
|
|
6239
|
+
});
|
|
6240
|
+
return;
|
|
6241
|
+
} else {
|
|
6242
|
+
relationOwner = oppositeField;
|
|
6243
|
+
}
|
|
6244
|
+
} else if (oppositeRelation?.references?.length && oppositeRelation.fields?.length) {
|
|
6245
|
+
if (thisRelation?.references || thisRelation?.fields) {
|
|
6246
|
+
accept("error", '"fields" and "references" must be provided only on one side of relation field', {
|
|
6247
|
+
node: field
|
|
6248
|
+
});
|
|
6249
|
+
return;
|
|
6250
|
+
} else {
|
|
6251
|
+
relationOwner = field;
|
|
6252
|
+
}
|
|
6253
|
+
} else {
|
|
6333
6254
|
[
|
|
6334
6255
|
field,
|
|
6335
6256
|
oppositeField
|
|
@@ -6340,78 +6261,85 @@ var DataModelValidator = class {
|
|
|
6340
6261
|
});
|
|
6341
6262
|
}
|
|
6342
6263
|
});
|
|
6264
|
+
return;
|
|
6343
6265
|
}
|
|
6344
|
-
|
|
6345
|
-
|
|
6346
|
-
|
|
6347
|
-
|
|
6348
|
-
|
|
6349
|
-
});
|
|
6350
|
-
return;
|
|
6351
|
-
}
|
|
6352
|
-
if (relationOwner !== field && !relationOwner.type.array) {
|
|
6353
|
-
const containingModel = field.$container;
|
|
6354
|
-
const uniqueFieldList = getUniqueFields(containingModel);
|
|
6355
|
-
if (containingModel !== contextModel) {
|
|
6356
|
-
uniqueFieldList.push(...getUniqueFields(contextModel));
|
|
6266
|
+
if (!relationOwner.type.array && !relationOwner.type.optional) {
|
|
6267
|
+
accept("error", "Relation field needs to be list or optional", {
|
|
6268
|
+
node: relationOwner
|
|
6269
|
+
});
|
|
6270
|
+
return;
|
|
6357
6271
|
}
|
|
6358
|
-
|
|
6359
|
-
const
|
|
6360
|
-
|
|
6361
|
-
|
|
6362
|
-
|
|
6363
|
-
}
|
|
6364
|
-
if (uniqueFieldList.some((list) => list.includes(refField))) {
|
|
6365
|
-
return;
|
|
6366
|
-
}
|
|
6367
|
-
accept("error", `Field "${refField.name}" on model "${containingModel.name}" is part of a one-to-one relation and must be marked as @unique or be part of a model-level @@unique attribute`, {
|
|
6368
|
-
node: refField
|
|
6369
|
-
});
|
|
6272
|
+
if (relationOwner !== field && !relationOwner.type.array) {
|
|
6273
|
+
const containingModel = field.$container;
|
|
6274
|
+
const uniqueFieldList = getUniqueFields(containingModel);
|
|
6275
|
+
if (containingModel !== contextModel) {
|
|
6276
|
+
uniqueFieldList.push(...getUniqueFields(contextModel));
|
|
6370
6277
|
}
|
|
6371
|
-
|
|
6278
|
+
thisRelation.fields?.forEach((ref) => {
|
|
6279
|
+
const refField = ref.target.ref;
|
|
6280
|
+
if (refField) {
|
|
6281
|
+
if (refField.attributes.find((a) => a.decl.ref?.name === "@id" || a.decl.ref?.name === "@unique")) {
|
|
6282
|
+
return;
|
|
6283
|
+
}
|
|
6284
|
+
if (uniqueFieldList.some((list) => list.includes(refField))) {
|
|
6285
|
+
return;
|
|
6286
|
+
}
|
|
6287
|
+
accept("error", `Field "${refField.name}" on model "${containingModel.name}" is part of a one-to-one relation and must be marked as @unique or be part of a model-level @@unique attribute`, {
|
|
6288
|
+
node: refField
|
|
6289
|
+
});
|
|
6290
|
+
}
|
|
6291
|
+
});
|
|
6292
|
+
}
|
|
6372
6293
|
}
|
|
6373
6294
|
}
|
|
6374
6295
|
// checks if the given field is inherited directly or indirectly from a delegate model
|
|
6375
|
-
isFieldInheritedFromDelegateModel(field
|
|
6376
|
-
|
|
6377
|
-
if (basePath && basePath.some(isDelegateModel)) {
|
|
6378
|
-
return true;
|
|
6379
|
-
} else {
|
|
6380
|
-
return false;
|
|
6381
|
-
}
|
|
6382
|
-
}
|
|
6383
|
-
validateBaseAbstractModel(model, accept) {
|
|
6384
|
-
model.superTypes.forEach((superType, index) => {
|
|
6385
|
-
if (!superType.ref?.isAbstract && !superType.ref?.attributes.some((attr) => attr.decl.ref?.name === "@@delegate")) accept("error", `Model ${superType.$refText} cannot be extended because it's neither abstract nor marked as "@@delegate"`, {
|
|
6386
|
-
node: model,
|
|
6387
|
-
property: "superTypes",
|
|
6388
|
-
index
|
|
6389
|
-
});
|
|
6390
|
-
});
|
|
6296
|
+
isFieldInheritedFromDelegateModel(field) {
|
|
6297
|
+
return isDelegateModel(field.$container);
|
|
6391
6298
|
}
|
|
6392
|
-
|
|
6393
|
-
if (model.
|
|
6394
|
-
|
|
6299
|
+
validateInherits(model, accept) {
|
|
6300
|
+
if (!model.baseModel) {
|
|
6301
|
+
return;
|
|
6302
|
+
}
|
|
6303
|
+
invariant2(model.baseModel.ref, "baseModel must be resolved");
|
|
6304
|
+
if (!isDelegateModel(model.baseModel.ref)) {
|
|
6305
|
+
accept("error", `Model ${model.baseModel.$refText} cannot be extended because it's not a delegate model`, {
|
|
6395
6306
|
node: model,
|
|
6396
|
-
property: "
|
|
6307
|
+
property: "baseModel"
|
|
6397
6308
|
});
|
|
6309
|
+
return;
|
|
6398
6310
|
}
|
|
6399
|
-
|
|
6400
|
-
|
|
6401
|
-
|
|
6402
|
-
dm
|
|
6311
|
+
const seen = [];
|
|
6312
|
+
const todo = [
|
|
6313
|
+
model.baseModel.ref
|
|
6403
6314
|
];
|
|
6404
|
-
const todo = dm.superTypes.map((superType) => superType.ref);
|
|
6405
6315
|
while (todo.length > 0) {
|
|
6406
6316
|
const current = todo.shift();
|
|
6407
6317
|
if (seen.includes(current)) {
|
|
6408
|
-
accept("error", `
|
|
6318
|
+
accept("error", `Cyclic inheritance detected: ${seen.map((m) => m.name).join(" -> ")} -> ${current.name}`, {
|
|
6319
|
+
node: model
|
|
6320
|
+
});
|
|
6321
|
+
return;
|
|
6322
|
+
}
|
|
6323
|
+
seen.push(current);
|
|
6324
|
+
if (current.baseModel) {
|
|
6325
|
+
invariant2(current.baseModel.ref, "baseModel must be resolved");
|
|
6326
|
+
todo.push(current.baseModel.ref);
|
|
6327
|
+
}
|
|
6328
|
+
}
|
|
6329
|
+
}
|
|
6330
|
+
validateMixins(dm, accept) {
|
|
6331
|
+
const seen = [];
|
|
6332
|
+
const todo = dm.mixins.map((mixin) => mixin.ref);
|
|
6333
|
+
while (todo.length > 0) {
|
|
6334
|
+
const current = todo.shift();
|
|
6335
|
+
if (seen.includes(current)) {
|
|
6336
|
+
accept("error", `Cyclic mixin detected: ${seen.map((m) => m.name).join(" -> ")} -> ${current.name}`, {
|
|
6409
6337
|
node: dm
|
|
6410
6338
|
});
|
|
6411
6339
|
return;
|
|
6412
6340
|
}
|
|
6413
6341
|
seen.push(current);
|
|
6414
|
-
todo.push(...current.
|
|
6342
|
+
todo.push(...current.mixins.map((mixin) => mixin.ref));
|
|
6415
6343
|
}
|
|
6416
6344
|
}
|
|
6417
6345
|
};
|
|
@@ -6447,26 +6375,15 @@ var DataSourceValidator = class {
|
|
|
6447
6375
|
}
|
|
6448
6376
|
}
|
|
6449
6377
|
validateUrl(ds, accept) {
|
|
6450
|
-
const
|
|
6451
|
-
if (!
|
|
6452
|
-
|
|
6453
|
-
node: ds
|
|
6454
|
-
});
|
|
6378
|
+
const urlField = ds.fields.find((f) => f.name === "url");
|
|
6379
|
+
if (!urlField) {
|
|
6380
|
+
return;
|
|
6455
6381
|
}
|
|
6456
|
-
|
|
6457
|
-
|
|
6458
|
-
"
|
|
6459
|
-
|
|
6460
|
-
|
|
6461
|
-
if (!field) {
|
|
6462
|
-
continue;
|
|
6463
|
-
}
|
|
6464
|
-
const value = getStringLiteral(field.value);
|
|
6465
|
-
if (!value && !(isInvocationExpr(field.value) && field.value.function.ref?.name === "env")) {
|
|
6466
|
-
accept("error", `"${fieldName}" must be set to a string literal or an invocation of "env" function`, {
|
|
6467
|
-
node: field.value
|
|
6468
|
-
});
|
|
6469
|
-
}
|
|
6382
|
+
const value = getStringLiteral(urlField.value);
|
|
6383
|
+
if (!value && !(isInvocationExpr(urlField.value) && urlField.value.function.ref?.name === "env")) {
|
|
6384
|
+
accept("error", `"${urlField.name}" must be set to a string literal or an invocation of "env" function`, {
|
|
6385
|
+
node: urlField.value
|
|
6386
|
+
});
|
|
6470
6387
|
}
|
|
6471
6388
|
}
|
|
6472
6389
|
validateRelationMode(ds, accept) {
|
|
@@ -6618,7 +6535,7 @@ var ExpressionValidator = class {
|
|
|
6618
6535
|
case "==":
|
|
6619
6536
|
case "!=": {
|
|
6620
6537
|
if (this.isInValidationContext(expr)) {
|
|
6621
|
-
if (
|
|
6538
|
+
if (isDataFieldReference(expr.left) && isNullExpr(expr.right) || isDataFieldReference(expr.right) && isNullExpr(expr.left)) {
|
|
6622
6539
|
return;
|
|
6623
6540
|
}
|
|
6624
6541
|
}
|
|
@@ -6647,11 +6564,11 @@ var ExpressionValidator = class {
|
|
|
6647
6564
|
node: expr
|
|
6648
6565
|
});
|
|
6649
6566
|
}
|
|
6650
|
-
if (
|
|
6567
|
+
if (isDataFieldReference(expr.left) && (isThisExpr(expr.right) || isDataFieldReference(expr.right))) {
|
|
6651
6568
|
accept("error", "comparison between model-typed fields are not supported", {
|
|
6652
6569
|
node: expr
|
|
6653
6570
|
});
|
|
6654
|
-
} else if (
|
|
6571
|
+
} else if (isDataFieldReference(expr.right) && (isThisExpr(expr.left) || isDataFieldReference(expr.left))) {
|
|
6655
6572
|
accept("error", "comparison between model-typed fields are not supported", {
|
|
6656
6573
|
node: expr
|
|
6657
6574
|
});
|
|
@@ -6746,7 +6663,7 @@ var FunctionInvocationValidator = class {
|
|
|
6746
6663
|
let curr = expr.$container;
|
|
6747
6664
|
let containerAttribute;
|
|
6748
6665
|
while (curr) {
|
|
6749
|
-
if (isDataModelAttribute(curr) ||
|
|
6666
|
+
if (isDataModelAttribute(curr) || isDataFieldAttribute(curr)) {
|
|
6750
6667
|
containerAttribute = curr;
|
|
6751
6668
|
break;
|
|
6752
6669
|
}
|
|
@@ -6847,7 +6764,7 @@ var FunctionInvocationValidator = class {
|
|
|
6847
6764
|
_checkCheck(expr, accept) {
|
|
6848
6765
|
let valid = true;
|
|
6849
6766
|
const fieldArg = expr.args[0].value;
|
|
6850
|
-
if (!
|
|
6767
|
+
if (!isDataFieldReference(fieldArg) || !isDataModel(fieldArg.$resolvedType?.decl)) {
|
|
6851
6768
|
accept("error", "argument must be a relation field", {
|
|
6852
6769
|
node: expr.args[0]
|
|
6853
6770
|
});
|
|
@@ -6962,8 +6879,8 @@ var SchemaValidator = class {
|
|
|
6962
6879
|
validateImports(model, accept) {
|
|
6963
6880
|
model.imports.forEach((imp) => {
|
|
6964
6881
|
const importedModel = resolveImport(this.documents, imp);
|
|
6965
|
-
const importPath = imp.path.endsWith(".zmodel") ? imp.path : `${imp.path}.zmodel`;
|
|
6966
6882
|
if (!importedModel) {
|
|
6883
|
+
const importPath = imp.path.endsWith(".zmodel") ? imp.path : `${imp.path}.zmodel`;
|
|
6967
6884
|
accept("error", `Cannot find model file ${importPath}`, {
|
|
6968
6885
|
node: imp
|
|
6969
6886
|
});
|
|
@@ -6989,6 +6906,11 @@ var TypeDefValidator = class {
|
|
|
6989
6906
|
typeDef.fields.forEach((field) => this.validateField(field, accept));
|
|
6990
6907
|
}
|
|
6991
6908
|
validateField(field, accept) {
|
|
6909
|
+
if (isDataModel(field.type.reference?.ref)) {
|
|
6910
|
+
accept("error", "Type field cannot be a relation", {
|
|
6911
|
+
node: field.type
|
|
6912
|
+
});
|
|
6913
|
+
}
|
|
6992
6914
|
field.attributes.forEach((attr) => validateAttributeApplication(attr, accept));
|
|
6993
6915
|
}
|
|
6994
6916
|
};
|
|
@@ -7149,8 +7071,8 @@ var ZModelLinker = class extends DefaultLinker {
|
|
|
7149
7071
|
case DataModel:
|
|
7150
7072
|
this.resolveDataModel(node, document, extraScopes);
|
|
7151
7073
|
break;
|
|
7152
|
-
case
|
|
7153
|
-
this.
|
|
7074
|
+
case DataField:
|
|
7075
|
+
this.resolveDataField(node, document, extraScopes);
|
|
7154
7076
|
break;
|
|
7155
7077
|
default:
|
|
7156
7078
|
this.resolveDefault(node, document, extraScopes);
|
|
@@ -7296,10 +7218,10 @@ var ZModelLinker = class extends DefaultLinker {
|
|
|
7296
7218
|
resolveAttributeArg(node, document, extraScopes) {
|
|
7297
7219
|
const attrParam = this.findAttrParamForArg(node);
|
|
7298
7220
|
const attrAppliedOn = node.$container.$container;
|
|
7299
|
-
if (attrParam?.type.type === "TransitiveFieldReference" &&
|
|
7221
|
+
if (attrParam?.type.type === "TransitiveFieldReference" && isDataField(attrAppliedOn)) {
|
|
7300
7222
|
const transitiveDataModel = attrAppliedOn.type.reference?.ref;
|
|
7301
7223
|
if (transitiveDataModel) {
|
|
7302
|
-
const scopeProvider = /* @__PURE__ */ __name((name) =>
|
|
7224
|
+
const scopeProvider = /* @__PURE__ */ __name((name) => getAllFields(transitiveDataModel).find((f) => f.name === name), "scopeProvider");
|
|
7303
7225
|
if (isArrayExpr(node.value)) {
|
|
7304
7226
|
node.value.items.forEach((item) => {
|
|
7305
7227
|
if (isReferenceExpr(item)) {
|
|
@@ -7355,7 +7277,7 @@ var ZModelLinker = class extends DefaultLinker {
|
|
|
7355
7277
|
resolveDataModel(node, document, extraScopes) {
|
|
7356
7278
|
return this.resolveDefault(node, document, extraScopes);
|
|
7357
7279
|
}
|
|
7358
|
-
|
|
7280
|
+
resolveDataField(node, document, extraScopes) {
|
|
7359
7281
|
this.resolve(node.type, document, extraScopes);
|
|
7360
7282
|
let scopes = extraScopes;
|
|
7361
7283
|
if (node.type.reference?.ref && isEnum(node.type.reference.ref)) {
|
|
@@ -7384,7 +7306,7 @@ var ZModelLinker = class extends DefaultLinker {
|
|
|
7384
7306
|
//#region Utils
|
|
7385
7307
|
resolveToDeclaredType(node, type) {
|
|
7386
7308
|
let nullable = false;
|
|
7387
|
-
if (
|
|
7309
|
+
if (isDataFieldType(type)) {
|
|
7388
7310
|
nullable = type.optional;
|
|
7389
7311
|
if (type.unsupported) {
|
|
7390
7312
|
node.$resolvedType = {
|
|
@@ -7445,6 +7367,14 @@ var ZModelScopeComputation = class extends DefaultScopeComputation {
|
|
|
7445
7367
|
}
|
|
7446
7368
|
processNode(node, document, scopes) {
|
|
7447
7369
|
super.processNode(node, document, scopes);
|
|
7370
|
+
if (isDataModel(node)) {
|
|
7371
|
+
const bases = getRecursiveBases(node);
|
|
7372
|
+
for (const base of bases) {
|
|
7373
|
+
for (const field of base.fields) {
|
|
7374
|
+
scopes.add(node, this.descriptions.createDescription(field, this.nameProvider.getName(field)));
|
|
7375
|
+
}
|
|
7376
|
+
}
|
|
7377
|
+
}
|
|
7448
7378
|
}
|
|
7449
7379
|
};
|
|
7450
7380
|
var ZModelScopeProvider = class extends DefaultScopeProvider {
|
|
@@ -7492,16 +7422,13 @@ var ZModelScopeProvider = class extends DefaultScopeProvider {
|
|
|
7492
7422
|
);
|
|
7493
7423
|
return match3(node.operand).when(isReferenceExpr, (operand) => {
|
|
7494
7424
|
const ref = operand.target.ref;
|
|
7495
|
-
if (
|
|
7425
|
+
if (isDataField(ref)) {
|
|
7496
7426
|
return this.createScopeForContainer(ref.type.reference?.ref, globalScope, allowTypeDefScope);
|
|
7497
7427
|
}
|
|
7498
7428
|
return EMPTY_SCOPE;
|
|
7499
7429
|
}).when(isMemberAccessExpr, (operand) => {
|
|
7500
7430
|
const ref = operand.member.ref;
|
|
7501
|
-
if (
|
|
7502
|
-
return this.createScopeForContainer(ref.type.reference?.ref, globalScope, allowTypeDefScope);
|
|
7503
|
-
}
|
|
7504
|
-
if (isTypeDefField(ref) && !ref.type.array) {
|
|
7431
|
+
if (isDataField(ref) && !ref.type.array) {
|
|
7505
7432
|
return this.createScopeForContainer(ref.type.reference?.ref, globalScope, allowTypeDefScope);
|
|
7506
7433
|
}
|
|
7507
7434
|
return EMPTY_SCOPE;
|
|
@@ -7524,13 +7451,13 @@ var ZModelScopeProvider = class extends DefaultScopeProvider {
|
|
|
7524
7451
|
const allowTypeDefScope = false;
|
|
7525
7452
|
return match3(collection).when(isReferenceExpr, (expr) => {
|
|
7526
7453
|
const ref = expr.target.ref;
|
|
7527
|
-
if (
|
|
7454
|
+
if (isDataField(ref)) {
|
|
7528
7455
|
return this.createScopeForContainer(ref.type.reference?.ref, globalScope, allowTypeDefScope);
|
|
7529
7456
|
}
|
|
7530
7457
|
return EMPTY_SCOPE;
|
|
7531
7458
|
}).when(isMemberAccessExpr, (expr) => {
|
|
7532
7459
|
const ref = expr.member.ref;
|
|
7533
|
-
if (
|
|
7460
|
+
if (isDataField(ref)) {
|
|
7534
7461
|
return this.createScopeForContainer(ref.type.reference?.ref, globalScope, allowTypeDefScope);
|
|
7535
7462
|
}
|
|
7536
7463
|
return EMPTY_SCOPE;
|
|
@@ -7555,7 +7482,7 @@ var ZModelScopeProvider = class extends DefaultScopeProvider {
|
|
|
7555
7482
|
}
|
|
7556
7483
|
createScopeForContainer(node, globalScope, includeTypeDefScope = false) {
|
|
7557
7484
|
if (isDataModel(node)) {
|
|
7558
|
-
return this.createScopeForNodes(
|
|
7485
|
+
return this.createScopeForNodes(getAllFields(node), globalScope);
|
|
7559
7486
|
} else if (includeTypeDefScope && isTypeDef(node)) {
|
|
7560
7487
|
return this.createScopeForNodes(node.fields, globalScope);
|
|
7561
7488
|
} else {
|
|
@@ -7585,7 +7512,7 @@ function getCollectionPredicateContext(node) {
|
|
|
7585
7512
|
__name(getCollectionPredicateContext, "getCollectionPredicateContext");
|
|
7586
7513
|
|
|
7587
7514
|
// src/zmodel-workspace-manager.ts
|
|
7588
|
-
import { DefaultWorkspaceManager, URI as URI2 } from "langium";
|
|
7515
|
+
import { DefaultWorkspaceManager, URI as URI2, UriUtils as UriUtils2 } from "langium";
|
|
7589
7516
|
import fs2 from "fs";
|
|
7590
7517
|
import path2 from "path";
|
|
7591
7518
|
import { fileURLToPath } from "url";
|
|
@@ -7630,6 +7557,67 @@ var ZModelWorkspaceManager = class extends DefaultWorkspaceManager {
|
|
|
7630
7557
|
}
|
|
7631
7558
|
const stdlib = await this.documentFactory.fromUri(URI2.file(stdLibPath));
|
|
7632
7559
|
collector(stdlib);
|
|
7560
|
+
const documents = this.langiumDocuments.all;
|
|
7561
|
+
const pluginModels = /* @__PURE__ */ new Set();
|
|
7562
|
+
documents.forEach((doc) => {
|
|
7563
|
+
const parsed = doc.parseResult.value;
|
|
7564
|
+
parsed.declarations.forEach((decl) => {
|
|
7565
|
+
if (isPlugin(decl)) {
|
|
7566
|
+
const providerField = decl.fields.find((f) => f.name === "provider");
|
|
7567
|
+
if (providerField) {
|
|
7568
|
+
const provider = getLiteral(providerField.value);
|
|
7569
|
+
if (provider) {
|
|
7570
|
+
pluginModels.add(provider);
|
|
7571
|
+
}
|
|
7572
|
+
}
|
|
7573
|
+
}
|
|
7574
|
+
});
|
|
7575
|
+
});
|
|
7576
|
+
if (pluginModels.size > 0) {
|
|
7577
|
+
console.log(`Used plugin modules: ${Array.from(pluginModels)}`);
|
|
7578
|
+
const pendingPluginModules = new Set(pluginModels);
|
|
7579
|
+
await Promise.all(folders.map((wf) => [
|
|
7580
|
+
wf,
|
|
7581
|
+
this.getRootFolder(wf)
|
|
7582
|
+
]).map(async (entry) => this.loadPluginModels(...entry, pendingPluginModules, collector)));
|
|
7583
|
+
}
|
|
7584
|
+
}
|
|
7585
|
+
async loadPluginModels(workspaceFolder, folderPath, pendingPluginModels, collector) {
|
|
7586
|
+
const content = (await this.fileSystemProvider.readDirectory(folderPath)).sort((a, b) => {
|
|
7587
|
+
if (a.isDirectory && b.isDirectory) {
|
|
7588
|
+
const aName = UriUtils2.basename(a.uri);
|
|
7589
|
+
if (aName === "node_modules") {
|
|
7590
|
+
return -1;
|
|
7591
|
+
} else {
|
|
7592
|
+
return 1;
|
|
7593
|
+
}
|
|
7594
|
+
} else {
|
|
7595
|
+
return 0;
|
|
7596
|
+
}
|
|
7597
|
+
});
|
|
7598
|
+
for (const entry of content) {
|
|
7599
|
+
if (entry.isDirectory) {
|
|
7600
|
+
const name = UriUtils2.basename(entry.uri);
|
|
7601
|
+
if (name === "node_modules") {
|
|
7602
|
+
for (const plugin of Array.from(pendingPluginModels)) {
|
|
7603
|
+
const path4 = UriUtils2.joinPath(entry.uri, plugin, PLUGIN_MODULE_NAME);
|
|
7604
|
+
try {
|
|
7605
|
+
await this.fileSystemProvider.readFile(path4);
|
|
7606
|
+
const document = await this.langiumDocuments.getOrCreateDocument(path4);
|
|
7607
|
+
collector(document);
|
|
7608
|
+
console.log(`Adding plugin document from ${path4.path}`);
|
|
7609
|
+
pendingPluginModels.delete(plugin);
|
|
7610
|
+
if (pendingPluginModels.size === 0) {
|
|
7611
|
+
return;
|
|
7612
|
+
}
|
|
7613
|
+
} catch {
|
|
7614
|
+
}
|
|
7615
|
+
}
|
|
7616
|
+
} else {
|
|
7617
|
+
await this.loadPluginModels(workspaceFolder, entry.uri, pendingPluginModels, collector);
|
|
7618
|
+
}
|
|
7619
|
+
}
|
|
7620
|
+
}
|
|
7633
7621
|
}
|
|
7634
7622
|
};
|
|
7635
7623
|
|
|
@@ -7705,10 +7693,16 @@ async function loadDocument(fileName, pluginModelFiles = []) {
|
|
|
7705
7693
|
const pluginDocs = await Promise.all(pluginModelFiles.map((file) => services.shared.workspace.LangiumDocuments.getOrCreateDocument(URI3.file(path3.resolve(file)))));
|
|
7706
7694
|
const langiumDocuments = services.shared.workspace.LangiumDocuments;
|
|
7707
7695
|
const document = await langiumDocuments.getOrCreateDocument(URI3.file(path3.resolve(fileName)));
|
|
7696
|
+
const importedURIs = await loadImports(document, langiumDocuments);
|
|
7697
|
+
const importedDocuments = [];
|
|
7698
|
+
for (const uri of importedURIs) {
|
|
7699
|
+
importedDocuments.push(await langiumDocuments.getOrCreateDocument(uri));
|
|
7700
|
+
}
|
|
7708
7701
|
await services.shared.workspace.DocumentBuilder.build([
|
|
7709
7702
|
stdLib,
|
|
7710
7703
|
...pluginDocs,
|
|
7711
|
-
document
|
|
7704
|
+
document,
|
|
7705
|
+
...importedDocuments
|
|
7712
7706
|
], {
|
|
7713
7707
|
validation: true
|
|
7714
7708
|
});
|
|
@@ -7735,6 +7729,20 @@ async function loadDocument(fileName, pluginModelFiles = []) {
|
|
|
7735
7729
|
warnings
|
|
7736
7730
|
};
|
|
7737
7731
|
}
|
|
7732
|
+
const model = document.parseResult.value;
|
|
7733
|
+
const imported = mergeImportsDeclarations(langiumDocuments, model);
|
|
7734
|
+
imported.forEach((model2) => {
|
|
7735
|
+
langiumDocuments.deleteDocument(model2.$document.uri);
|
|
7736
|
+
services.shared.workspace.IndexManager.remove(model2.$document.uri);
|
|
7737
|
+
});
|
|
7738
|
+
const additionalErrors = validationAfterImportMerge(model);
|
|
7739
|
+
if (additionalErrors.length > 0) {
|
|
7740
|
+
return {
|
|
7741
|
+
success: false,
|
|
7742
|
+
errors: additionalErrors,
|
|
7743
|
+
warnings
|
|
7744
|
+
};
|
|
7745
|
+
}
|
|
7738
7746
|
return {
|
|
7739
7747
|
success: true,
|
|
7740
7748
|
model: document.parseResult.value,
|
|
@@ -7742,6 +7750,68 @@ async function loadDocument(fileName, pluginModelFiles = []) {
|
|
|
7742
7750
|
};
|
|
7743
7751
|
}
|
|
7744
7752
|
__name(loadDocument, "loadDocument");
|
|
7753
|
+
async function loadImports(document, documents, uris = /* @__PURE__ */ new Set()) {
|
|
7754
|
+
const uriString = document.uri.toString();
|
|
7755
|
+
if (!uris.has(uriString)) {
|
|
7756
|
+
uris.add(uriString);
|
|
7757
|
+
const model = document.parseResult.value;
|
|
7758
|
+
for (const imp of model.imports) {
|
|
7759
|
+
const importedModel = resolveImport(documents, imp);
|
|
7760
|
+
if (importedModel) {
|
|
7761
|
+
const importedDoc = getDocument(importedModel);
|
|
7762
|
+
await loadImports(importedDoc, documents, uris);
|
|
7763
|
+
}
|
|
7764
|
+
}
|
|
7765
|
+
}
|
|
7766
|
+
return Array.from(uris).filter((x) => uriString != x).map((e) => URI3.parse(e));
|
|
7767
|
+
}
|
|
7768
|
+
__name(loadImports, "loadImports");
|
|
7769
|
+
function mergeImportsDeclarations(documents, model) {
|
|
7770
|
+
const importedModels = resolveTransitiveImports(documents, model);
|
|
7771
|
+
const importedDeclarations = importedModels.flatMap((m) => m.declarations);
|
|
7772
|
+
model.declarations.push(...importedDeclarations);
|
|
7773
|
+
model.imports = [];
|
|
7774
|
+
linkContentToContainer(model);
|
|
7775
|
+
return importedModels;
|
|
7776
|
+
}
|
|
7777
|
+
__name(mergeImportsDeclarations, "mergeImportsDeclarations");
|
|
7778
|
+
function linkContentToContainer(node) {
|
|
7779
|
+
for (const [name, value] of Object.entries(node)) {
|
|
7780
|
+
if (!name.startsWith("$")) {
|
|
7781
|
+
if (Array.isArray(value)) {
|
|
7782
|
+
value.forEach((item, index) => {
|
|
7783
|
+
if (isAstNode(item)) {
|
|
7784
|
+
item.$container = node;
|
|
7785
|
+
item.$containerProperty = name;
|
|
7786
|
+
item.$containerIndex = index;
|
|
7787
|
+
}
|
|
7788
|
+
});
|
|
7789
|
+
} else if (isAstNode(value)) {
|
|
7790
|
+
value.$container = node;
|
|
7791
|
+
value.$containerProperty = name;
|
|
7792
|
+
}
|
|
7793
|
+
}
|
|
7794
|
+
}
|
|
7795
|
+
}
|
|
7796
|
+
__name(linkContentToContainer, "linkContentToContainer");
|
|
7797
|
+
function validationAfterImportMerge(model) {
|
|
7798
|
+
const errors = [];
|
|
7799
|
+
const dataSources = model.declarations.filter((d) => isDataSource(d));
|
|
7800
|
+
if (dataSources.length === 0) {
|
|
7801
|
+
errors.push("Validation error: schema must have a datasource declaration");
|
|
7802
|
+
} else {
|
|
7803
|
+
if (dataSources.length > 1) {
|
|
7804
|
+
errors.push("Validation error: multiple datasource declarations are not allowed");
|
|
7805
|
+
}
|
|
7806
|
+
}
|
|
7807
|
+
const decls = getDataModelAndTypeDefs(model, true);
|
|
7808
|
+
const authDecls = decls.filter((d) => hasAttribute(d, "@@auth"));
|
|
7809
|
+
if (authDecls.length > 1) {
|
|
7810
|
+
errors.push("Validation error: Multiple `@@auth` declarations are not allowed");
|
|
7811
|
+
}
|
|
7812
|
+
return errors;
|
|
7813
|
+
}
|
|
7814
|
+
__name(validationAfterImportMerge, "validationAfterImportMerge");
|
|
7745
7815
|
export {
|
|
7746
7816
|
DocumentLoadError,
|
|
7747
7817
|
ZModelLanguageMetaData,
|