@zenstackhq/language 3.0.0-alpha.12 → 3.0.0-alpha.14
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 +536 -548
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +537 -549
- package/dist/index.js.map +1 -1
- package/dist/utils.cjs +1529 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.cts +84 -0
- package/dist/utils.d.ts +84 -0
- package/dist/utils.js +1461 -0
- package/dist/utils.js.map +1 -0
- package/package.json +14 -3
- package/res/stdlib.zmodel +41 -26
package/dist/index.js
CHANGED
|
@@ -64,7 +64,6 @@ __name(isLiteralExpr, "isLiteralExpr");
|
|
|
64
64
|
var MemberAccessTarget = "MemberAccessTarget";
|
|
65
65
|
var ReferenceTarget = "ReferenceTarget";
|
|
66
66
|
var TypeDeclaration = "TypeDeclaration";
|
|
67
|
-
var TypeDefFieldTypes = "TypeDefFieldTypes";
|
|
68
67
|
var Argument = "Argument";
|
|
69
68
|
var ArrayExpr = "ArrayExpr";
|
|
70
69
|
function isArrayExpr(item) {
|
|
@@ -97,6 +96,21 @@ __name(isConfigArrayExpr, "isConfigArrayExpr");
|
|
|
97
96
|
var ConfigField = "ConfigField";
|
|
98
97
|
var ConfigInvocationArg = "ConfigInvocationArg";
|
|
99
98
|
var ConfigInvocationExpr = "ConfigInvocationExpr";
|
|
99
|
+
var DataField = "DataField";
|
|
100
|
+
function isDataField(item) {
|
|
101
|
+
return reflection.isInstance(item, DataField);
|
|
102
|
+
}
|
|
103
|
+
__name(isDataField, "isDataField");
|
|
104
|
+
var DataFieldAttribute = "DataFieldAttribute";
|
|
105
|
+
function isDataFieldAttribute(item) {
|
|
106
|
+
return reflection.isInstance(item, DataFieldAttribute);
|
|
107
|
+
}
|
|
108
|
+
__name(isDataFieldAttribute, "isDataFieldAttribute");
|
|
109
|
+
var DataFieldType = "DataFieldType";
|
|
110
|
+
function isDataFieldType(item) {
|
|
111
|
+
return reflection.isInstance(item, DataFieldType);
|
|
112
|
+
}
|
|
113
|
+
__name(isDataFieldType, "isDataFieldType");
|
|
100
114
|
var DataModel = "DataModel";
|
|
101
115
|
function isDataModel(item) {
|
|
102
116
|
return reflection.isInstance(item, DataModel);
|
|
@@ -107,21 +121,6 @@ function isDataModelAttribute(item) {
|
|
|
107
121
|
return reflection.isInstance(item, DataModelAttribute);
|
|
108
122
|
}
|
|
109
123
|
__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
124
|
var DataSource = "DataSource";
|
|
126
125
|
function isDataSource(item) {
|
|
127
126
|
return reflection.isInstance(item, DataSource);
|
|
@@ -175,6 +174,10 @@ function isObjectExpr(item) {
|
|
|
175
174
|
}
|
|
176
175
|
__name(isObjectExpr, "isObjectExpr");
|
|
177
176
|
var Plugin = "Plugin";
|
|
177
|
+
function isPlugin(item) {
|
|
178
|
+
return reflection.isInstance(item, Plugin);
|
|
179
|
+
}
|
|
180
|
+
__name(isPlugin, "isPlugin");
|
|
178
181
|
var PluginField = "PluginField";
|
|
179
182
|
var Procedure = "Procedure";
|
|
180
183
|
var ProcedureParam = "ProcedureParam";
|
|
@@ -199,12 +202,6 @@ function isTypeDef(item) {
|
|
|
199
202
|
return reflection.isInstance(item, TypeDef);
|
|
200
203
|
}
|
|
201
204
|
__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
205
|
var UnaryExpr = "UnaryExpr";
|
|
209
206
|
var UnsupportedFieldType = "UnsupportedFieldType";
|
|
210
207
|
var ZModelAstReflection = class extends langium.AbstractAstReflection {
|
|
@@ -227,11 +224,11 @@ var ZModelAstReflection = class extends langium.AbstractAstReflection {
|
|
|
227
224
|
ConfigField,
|
|
228
225
|
ConfigInvocationArg,
|
|
229
226
|
ConfigInvocationExpr,
|
|
227
|
+
DataField,
|
|
228
|
+
DataFieldAttribute,
|
|
229
|
+
DataFieldType,
|
|
230
230
|
DataModel,
|
|
231
231
|
DataModelAttribute,
|
|
232
|
-
DataModelField,
|
|
233
|
-
DataModelFieldAttribute,
|
|
234
|
-
DataModelFieldType,
|
|
235
232
|
DataSource,
|
|
236
233
|
Enum,
|
|
237
234
|
EnumField,
|
|
@@ -262,9 +259,6 @@ var ZModelAstReflection = class extends langium.AbstractAstReflection {
|
|
|
262
259
|
ThisExpr,
|
|
263
260
|
TypeDeclaration,
|
|
264
261
|
TypeDef,
|
|
265
|
-
TypeDefField,
|
|
266
|
-
TypeDefFieldType,
|
|
267
|
-
TypeDefFieldTypes,
|
|
268
262
|
UnaryExpr,
|
|
269
263
|
UnsupportedFieldType
|
|
270
264
|
];
|
|
@@ -297,16 +291,13 @@ var ZModelAstReflection = class extends langium.AbstractAstReflection {
|
|
|
297
291
|
case ConfigArrayExpr: {
|
|
298
292
|
return this.isSubtype(ConfigExpr, supertype);
|
|
299
293
|
}
|
|
300
|
-
case
|
|
301
|
-
return this.isSubtype(AbstractDeclaration, supertype) || this.isSubtype(TypeDeclaration, supertype);
|
|
302
|
-
}
|
|
303
|
-
case DataModelField:
|
|
304
|
-
case TypeDefField: {
|
|
294
|
+
case DataField: {
|
|
305
295
|
return this.isSubtype(MemberAccessTarget, supertype) || this.isSubtype(ReferenceTarget, supertype);
|
|
306
296
|
}
|
|
297
|
+
case DataModel:
|
|
307
298
|
case Enum:
|
|
308
299
|
case TypeDef: {
|
|
309
|
-
return this.isSubtype(AbstractDeclaration, supertype) || this.isSubtype(TypeDeclaration, supertype)
|
|
300
|
+
return this.isSubtype(AbstractDeclaration, supertype) || this.isSubtype(TypeDeclaration, supertype);
|
|
310
301
|
}
|
|
311
302
|
case EnumField:
|
|
312
303
|
case FunctionParam: {
|
|
@@ -325,18 +316,22 @@ var ZModelAstReflection = class extends langium.AbstractAstReflection {
|
|
|
325
316
|
const referenceId = `${refInfo.container.$type}:${refInfo.property}`;
|
|
326
317
|
switch (referenceId) {
|
|
327
318
|
case "AttributeParamType:reference":
|
|
328
|
-
case "
|
|
319
|
+
case "DataFieldType:reference":
|
|
329
320
|
case "FunctionParamType:reference": {
|
|
330
321
|
return TypeDeclaration;
|
|
331
322
|
}
|
|
332
|
-
case "
|
|
333
|
-
return DataModel;
|
|
334
|
-
}
|
|
323
|
+
case "DataFieldAttribute:decl":
|
|
335
324
|
case "DataModelAttribute:decl":
|
|
336
|
-
case "DataModelFieldAttribute:decl":
|
|
337
325
|
case "InternalAttribute:decl": {
|
|
338
326
|
return Attribute;
|
|
339
327
|
}
|
|
328
|
+
case "DataModel:baseModel": {
|
|
329
|
+
return DataModel;
|
|
330
|
+
}
|
|
331
|
+
case "DataModel:mixins":
|
|
332
|
+
case "TypeDef:mixins": {
|
|
333
|
+
return TypeDef;
|
|
334
|
+
}
|
|
340
335
|
case "InvocationExpr:function": {
|
|
341
336
|
return FunctionDecl;
|
|
342
337
|
}
|
|
@@ -346,9 +341,6 @@ var ZModelAstReflection = class extends langium.AbstractAstReflection {
|
|
|
346
341
|
case "ReferenceExpr:target": {
|
|
347
342
|
return ReferenceTarget;
|
|
348
343
|
}
|
|
349
|
-
case "TypeDefFieldType:reference": {
|
|
350
|
-
return TypeDefFieldTypes;
|
|
351
|
-
}
|
|
352
344
|
default: {
|
|
353
345
|
throw new Error(`${referenceId} is not a valid reference id.`);
|
|
354
346
|
}
|
|
@@ -535,9 +527,9 @@ var ZModelAstReflection = class extends langium.AbstractAstReflection {
|
|
|
535
527
|
]
|
|
536
528
|
};
|
|
537
529
|
}
|
|
538
|
-
case
|
|
530
|
+
case DataField: {
|
|
539
531
|
return {
|
|
540
|
-
name:
|
|
532
|
+
name: DataField,
|
|
541
533
|
properties: [
|
|
542
534
|
{
|
|
543
535
|
name: "attributes",
|
|
@@ -547,31 +539,18 @@ var ZModelAstReflection = class extends langium.AbstractAstReflection {
|
|
|
547
539
|
name: "comments",
|
|
548
540
|
defaultValue: []
|
|
549
541
|
},
|
|
550
|
-
{
|
|
551
|
-
name: "fields",
|
|
552
|
-
defaultValue: []
|
|
553
|
-
},
|
|
554
|
-
{
|
|
555
|
-
name: "isAbstract",
|
|
556
|
-
defaultValue: false
|
|
557
|
-
},
|
|
558
|
-
{
|
|
559
|
-
name: "isView",
|
|
560
|
-
defaultValue: false
|
|
561
|
-
},
|
|
562
542
|
{
|
|
563
543
|
name: "name"
|
|
564
544
|
},
|
|
565
545
|
{
|
|
566
|
-
name: "
|
|
567
|
-
defaultValue: []
|
|
546
|
+
name: "type"
|
|
568
547
|
}
|
|
569
548
|
]
|
|
570
549
|
};
|
|
571
550
|
}
|
|
572
|
-
case
|
|
551
|
+
case DataFieldAttribute: {
|
|
573
552
|
return {
|
|
574
|
-
name:
|
|
553
|
+
name: DataFieldAttribute,
|
|
575
554
|
properties: [
|
|
576
555
|
{
|
|
577
556
|
name: "args",
|
|
@@ -583,61 +562,73 @@ var ZModelAstReflection = class extends langium.AbstractAstReflection {
|
|
|
583
562
|
]
|
|
584
563
|
};
|
|
585
564
|
}
|
|
586
|
-
case
|
|
565
|
+
case DataFieldType: {
|
|
587
566
|
return {
|
|
588
|
-
name:
|
|
567
|
+
name: DataFieldType,
|
|
589
568
|
properties: [
|
|
590
569
|
{
|
|
591
|
-
name: "
|
|
592
|
-
defaultValue:
|
|
570
|
+
name: "array",
|
|
571
|
+
defaultValue: false
|
|
593
572
|
},
|
|
594
573
|
{
|
|
595
|
-
name: "
|
|
596
|
-
defaultValue:
|
|
574
|
+
name: "optional",
|
|
575
|
+
defaultValue: false
|
|
597
576
|
},
|
|
598
577
|
{
|
|
599
|
-
name: "
|
|
578
|
+
name: "reference"
|
|
600
579
|
},
|
|
601
580
|
{
|
|
602
581
|
name: "type"
|
|
582
|
+
},
|
|
583
|
+
{
|
|
584
|
+
name: "unsupported"
|
|
603
585
|
}
|
|
604
586
|
]
|
|
605
587
|
};
|
|
606
588
|
}
|
|
607
|
-
case
|
|
589
|
+
case DataModel: {
|
|
608
590
|
return {
|
|
609
|
-
name:
|
|
591
|
+
name: DataModel,
|
|
610
592
|
properties: [
|
|
611
593
|
{
|
|
612
|
-
name: "
|
|
594
|
+
name: "attributes",
|
|
613
595
|
defaultValue: []
|
|
614
596
|
},
|
|
615
597
|
{
|
|
616
|
-
name: "
|
|
617
|
-
}
|
|
618
|
-
]
|
|
619
|
-
};
|
|
620
|
-
}
|
|
621
|
-
case DataModelFieldType: {
|
|
622
|
-
return {
|
|
623
|
-
name: DataModelFieldType,
|
|
624
|
-
properties: [
|
|
598
|
+
name: "baseModel"
|
|
599
|
+
},
|
|
625
600
|
{
|
|
626
|
-
name: "
|
|
627
|
-
defaultValue:
|
|
601
|
+
name: "comments",
|
|
602
|
+
defaultValue: []
|
|
628
603
|
},
|
|
629
604
|
{
|
|
630
|
-
name: "
|
|
605
|
+
name: "fields",
|
|
606
|
+
defaultValue: []
|
|
607
|
+
},
|
|
608
|
+
{
|
|
609
|
+
name: "isView",
|
|
631
610
|
defaultValue: false
|
|
632
611
|
},
|
|
633
612
|
{
|
|
634
|
-
name: "
|
|
613
|
+
name: "mixins",
|
|
614
|
+
defaultValue: []
|
|
635
615
|
},
|
|
636
616
|
{
|
|
637
|
-
name: "
|
|
617
|
+
name: "name"
|
|
618
|
+
}
|
|
619
|
+
]
|
|
620
|
+
};
|
|
621
|
+
}
|
|
622
|
+
case DataModelAttribute: {
|
|
623
|
+
return {
|
|
624
|
+
name: DataModelAttribute,
|
|
625
|
+
properties: [
|
|
626
|
+
{
|
|
627
|
+
name: "args",
|
|
628
|
+
defaultValue: []
|
|
638
629
|
},
|
|
639
630
|
{
|
|
640
|
-
name: "
|
|
631
|
+
name: "decl"
|
|
641
632
|
}
|
|
642
633
|
]
|
|
643
634
|
};
|
|
@@ -1011,49 +1002,11 @@ var ZModelAstReflection = class extends langium.AbstractAstReflection {
|
|
|
1011
1002
|
defaultValue: []
|
|
1012
1003
|
},
|
|
1013
1004
|
{
|
|
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",
|
|
1005
|
+
name: "mixins",
|
|
1029
1006
|
defaultValue: []
|
|
1030
1007
|
},
|
|
1031
1008
|
{
|
|
1032
1009
|
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
1010
|
}
|
|
1058
1011
|
]
|
|
1059
1012
|
};
|
|
@@ -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": []
|
|
2989
|
+
},
|
|
2990
|
+
{
|
|
2991
|
+
"$type": "RuleCall",
|
|
2992
|
+
"rule": {
|
|
2993
|
+
"$ref": "#/rules@39"
|
|
2994
|
+
},
|
|
2995
|
+
"arguments": []
|
|
3043
2996
|
},
|
|
3044
2997
|
{
|
|
3045
|
-
"$type": "
|
|
3046
|
-
"
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
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,188 +3389,51 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
|
|
|
3347
3389
|
"arguments": []
|
|
3348
3390
|
}
|
|
3349
3391
|
},
|
|
3350
|
-
{
|
|
3351
|
-
"$type": "
|
|
3352
|
-
"
|
|
3353
|
-
|
|
3354
|
-
{
|
|
3355
|
-
"$type": "Alternatives",
|
|
3356
|
-
"elements": [
|
|
3357
|
-
{
|
|
3358
|
-
"$type": "Assignment",
|
|
3359
|
-
"feature": "fields",
|
|
3360
|
-
"operator": "+=",
|
|
3361
|
-
"terminal": {
|
|
3362
|
-
"$type": "RuleCall",
|
|
3363
|
-
"rule": {
|
|
3364
|
-
"$ref": "#/rules@41"
|
|
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"
|
|
3377
|
-
},
|
|
3378
|
-
"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": []
|
|
3392
|
+
{
|
|
3393
|
+
"$type": "RuleCall",
|
|
3394
|
+
"rule": {
|
|
3395
|
+
"$ref": "#/rules@38"
|
|
3450
3396
|
},
|
|
3451
|
-
"
|
|
3452
|
-
|
|
3453
|
-
|
|
3454
|
-
|
|
3455
|
-
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
"hiddenTokens": [],
|
|
3459
|
-
"parameters": [],
|
|
3460
|
-
"wildcard": false
|
|
3461
|
-
},
|
|
3462
|
-
{
|
|
3463
|
-
"$type": "ParserRule",
|
|
3464
|
-
"name": "TypeDefFieldType",
|
|
3465
|
-
"definition": {
|
|
3466
|
-
"$type": "Group",
|
|
3467
|
-
"elements": [
|
|
3397
|
+
"arguments": [],
|
|
3398
|
+
"cardinality": "?"
|
|
3399
|
+
},
|
|
3400
|
+
{
|
|
3401
|
+
"$type": "Keyword",
|
|
3402
|
+
"value": "{"
|
|
3403
|
+
},
|
|
3468
3404
|
{
|
|
3469
3405
|
"$type": "Alternatives",
|
|
3470
3406
|
"elements": [
|
|
3471
3407
|
{
|
|
3472
3408
|
"$type": "Assignment",
|
|
3473
|
-
"feature": "
|
|
3474
|
-
"operator": "
|
|
3409
|
+
"feature": "fields",
|
|
3410
|
+
"operator": "+=",
|
|
3475
3411
|
"terminal": {
|
|
3476
3412
|
"$type": "RuleCall",
|
|
3477
3413
|
"rule": {
|
|
3478
|
-
"$ref": "#/rules@
|
|
3414
|
+
"$ref": "#/rules@40"
|
|
3479
3415
|
},
|
|
3480
3416
|
"arguments": []
|
|
3481
3417
|
}
|
|
3482
3418
|
},
|
|
3483
3419
|
{
|
|
3484
3420
|
"$type": "Assignment",
|
|
3485
|
-
"feature": "
|
|
3486
|
-
"operator": "
|
|
3421
|
+
"feature": "attributes",
|
|
3422
|
+
"operator": "+=",
|
|
3487
3423
|
"terminal": {
|
|
3488
|
-
"$type": "
|
|
3489
|
-
"
|
|
3490
|
-
"$ref": "#/
|
|
3491
|
-
},
|
|
3492
|
-
"terminal": {
|
|
3493
|
-
"$type": "RuleCall",
|
|
3494
|
-
"rule": {
|
|
3495
|
-
"$ref": "#/rules@51"
|
|
3496
|
-
},
|
|
3497
|
-
"arguments": []
|
|
3424
|
+
"$type": "RuleCall",
|
|
3425
|
+
"rule": {
|
|
3426
|
+
"$ref": "#/rules@57"
|
|
3498
3427
|
},
|
|
3499
|
-
"
|
|
3500
|
-
}
|
|
3501
|
-
}
|
|
3502
|
-
]
|
|
3503
|
-
},
|
|
3504
|
-
{
|
|
3505
|
-
"$type": "Group",
|
|
3506
|
-
"elements": [
|
|
3507
|
-
{
|
|
3508
|
-
"$type": "Assignment",
|
|
3509
|
-
"feature": "array",
|
|
3510
|
-
"operator": "?=",
|
|
3511
|
-
"terminal": {
|
|
3512
|
-
"$type": "Keyword",
|
|
3513
|
-
"value": "["
|
|
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
|
{
|
|
@@ -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
|
}
|
|
@@ -5655,6 +5492,42 @@ function isMemberContainer(node) {
|
|
|
5655
5492
|
return isDataModel(node) || isTypeDef(node);
|
|
5656
5493
|
}
|
|
5657
5494
|
__name(isMemberContainer, "isMemberContainer");
|
|
5495
|
+
function getAllFields(decl, includeIgnored = false, seen = /* @__PURE__ */ new Set()) {
|
|
5496
|
+
if (seen.has(decl)) {
|
|
5497
|
+
return [];
|
|
5498
|
+
}
|
|
5499
|
+
seen.add(decl);
|
|
5500
|
+
const fields = [];
|
|
5501
|
+
for (const mixin of decl.mixins) {
|
|
5502
|
+
invariant(mixin.ref, `Mixin ${mixin.$refText} is not resolved`);
|
|
5503
|
+
fields.push(...getAllFields(mixin.ref, includeIgnored, seen));
|
|
5504
|
+
}
|
|
5505
|
+
if (isDataModel(decl) && decl.baseModel) {
|
|
5506
|
+
invariant(decl.baseModel.ref, `Base model ${decl.baseModel.$refText} is not resolved`);
|
|
5507
|
+
fields.push(...getAllFields(decl.baseModel.ref, includeIgnored, seen));
|
|
5508
|
+
}
|
|
5509
|
+
fields.push(...decl.fields.filter((f) => includeIgnored || !hasAttribute(f, "@ignore")));
|
|
5510
|
+
return fields;
|
|
5511
|
+
}
|
|
5512
|
+
__name(getAllFields, "getAllFields");
|
|
5513
|
+
function getAllAttributes(decl, seen = /* @__PURE__ */ new Set()) {
|
|
5514
|
+
if (seen.has(decl)) {
|
|
5515
|
+
return [];
|
|
5516
|
+
}
|
|
5517
|
+
seen.add(decl);
|
|
5518
|
+
const attributes = [];
|
|
5519
|
+
for (const mixin of decl.mixins) {
|
|
5520
|
+
invariant(mixin.ref, `Mixin ${mixin.$refText} is not resolved`);
|
|
5521
|
+
attributes.push(...getAllAttributes(mixin.ref, seen));
|
|
5522
|
+
}
|
|
5523
|
+
if (isDataModel(decl) && decl.baseModel) {
|
|
5524
|
+
invariant(decl.baseModel.ref, `Base model ${decl.baseModel.$refText} is not resolved`);
|
|
5525
|
+
attributes.push(...getAllAttributes(decl.baseModel.ref, seen));
|
|
5526
|
+
}
|
|
5527
|
+
attributes.push(...decl.attributes);
|
|
5528
|
+
return attributes;
|
|
5529
|
+
}
|
|
5530
|
+
__name(getAllAttributes, "getAllAttributes");
|
|
5658
5531
|
|
|
5659
5532
|
// src/validators/attribute-application-validator.ts
|
|
5660
5533
|
function _ts_decorate(decorators, target, key, desc) {
|
|
@@ -5682,7 +5555,7 @@ var AttributeApplicationValidator = class {
|
|
|
5682
5555
|
static {
|
|
5683
5556
|
__name(this, "AttributeApplicationValidator");
|
|
5684
5557
|
}
|
|
5685
|
-
validate(attr, accept) {
|
|
5558
|
+
validate(attr, accept, contextDataModel) {
|
|
5686
5559
|
const decl = attr.decl.ref;
|
|
5687
5560
|
if (!decl) {
|
|
5688
5561
|
return;
|
|
@@ -5694,21 +5567,13 @@ var AttributeApplicationValidator = class {
|
|
|
5694
5567
|
});
|
|
5695
5568
|
return;
|
|
5696
5569
|
}
|
|
5697
|
-
if (
|
|
5570
|
+
if (isDataField(targetDecl) && !isValidAttributeTarget(decl, targetDecl)) {
|
|
5698
5571
|
accept("error", `attribute "${decl.name}" cannot be used on this type of field`, {
|
|
5699
5572
|
node: attr
|
|
5700
5573
|
});
|
|
5701
5574
|
}
|
|
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
|
-
}
|
|
5575
|
+
this.checkDeprecation(attr, accept);
|
|
5576
|
+
this.checkDuplicatedAttributes(attr, accept, contextDataModel);
|
|
5712
5577
|
const filledParams = /* @__PURE__ */ new Set();
|
|
5713
5578
|
for (const arg of attr.args) {
|
|
5714
5579
|
let paramDecl;
|
|
@@ -5756,6 +5621,28 @@ var AttributeApplicationValidator = class {
|
|
|
5756
5621
|
checker.value.call(this, attr, accept);
|
|
5757
5622
|
}
|
|
5758
5623
|
}
|
|
5624
|
+
checkDeprecation(attr, accept) {
|
|
5625
|
+
const deprecateAttr = attr.decl.ref?.attributes.find((a) => a.decl.ref?.name === "@@@deprecated");
|
|
5626
|
+
if (deprecateAttr) {
|
|
5627
|
+
const message = getStringLiteral(deprecateAttr.args[0]?.value) ?? `Attribute "${attr.decl.ref?.name}" is deprecated`;
|
|
5628
|
+
accept("warning", message, {
|
|
5629
|
+
node: attr
|
|
5630
|
+
});
|
|
5631
|
+
}
|
|
5632
|
+
}
|
|
5633
|
+
checkDuplicatedAttributes(attr, accept, contextDataModel) {
|
|
5634
|
+
const attrDecl = attr.decl.ref;
|
|
5635
|
+
if (!attrDecl?.attributes.some((a) => a.decl.ref?.name === "@@@once")) {
|
|
5636
|
+
return;
|
|
5637
|
+
}
|
|
5638
|
+
const allAttributes = contextDataModel ? getAllAttributes(contextDataModel) : attr.$container.attributes;
|
|
5639
|
+
const duplicates = allAttributes.filter((a) => a.decl.ref === attrDecl && a !== attr);
|
|
5640
|
+
if (duplicates.length > 0) {
|
|
5641
|
+
accept("error", `Attribute "${attrDecl.name}" can only be applied once`, {
|
|
5642
|
+
node: attr
|
|
5643
|
+
});
|
|
5644
|
+
}
|
|
5645
|
+
}
|
|
5759
5646
|
_checkModelLevelPolicy(attr, accept) {
|
|
5760
5647
|
const kind = getStringLiteral(attr.args[0]?.value);
|
|
5761
5648
|
if (!kind) {
|
|
@@ -5804,7 +5691,7 @@ var AttributeApplicationValidator = class {
|
|
|
5804
5691
|
}
|
|
5805
5692
|
_checkValidate(attr, accept) {
|
|
5806
5693
|
const condition = attr.args[0]?.value;
|
|
5807
|
-
if (condition && AstUtils2.streamAst(condition).some((node) =>
|
|
5694
|
+
if (condition && AstUtils2.streamAst(condition).some((node) => isDataFieldReference(node) && isDataModel(node.$resolvedType?.decl))) {
|
|
5808
5695
|
accept("error", `\`@@validate\` condition cannot use relation fields`, {
|
|
5809
5696
|
node: condition
|
|
5810
5697
|
});
|
|
@@ -5813,9 +5700,18 @@ var AttributeApplicationValidator = class {
|
|
|
5813
5700
|
_checkUnique(attr, accept) {
|
|
5814
5701
|
const fields = attr.args[0]?.value;
|
|
5815
5702
|
if (!fields) {
|
|
5703
|
+
accept("error", `expects an array of field references`, {
|
|
5704
|
+
node: attr.args[0]
|
|
5705
|
+
});
|
|
5816
5706
|
return;
|
|
5817
5707
|
}
|
|
5818
5708
|
if (isArrayExpr(fields)) {
|
|
5709
|
+
if (fields.items.length === 0) {
|
|
5710
|
+
accept("error", `\`@@unique\` expects at least one field reference`, {
|
|
5711
|
+
node: fields
|
|
5712
|
+
});
|
|
5713
|
+
return;
|
|
5714
|
+
}
|
|
5819
5715
|
fields.items.forEach((item) => {
|
|
5820
5716
|
if (!isReferenceExpr(item)) {
|
|
5821
5717
|
accept("error", `Expecting a field reference`, {
|
|
@@ -5823,7 +5719,7 @@ var AttributeApplicationValidator = class {
|
|
|
5823
5719
|
});
|
|
5824
5720
|
return;
|
|
5825
5721
|
}
|
|
5826
|
-
if (!
|
|
5722
|
+
if (!isDataField(item.target.ref)) {
|
|
5827
5723
|
accept("error", `Expecting a field reference`, {
|
|
5828
5724
|
node: item
|
|
5829
5725
|
});
|
|
@@ -5843,7 +5739,7 @@ var AttributeApplicationValidator = class {
|
|
|
5843
5739
|
}
|
|
5844
5740
|
rejectEncryptedFields(attr, accept) {
|
|
5845
5741
|
AstUtils2.streamAllContents(attr).forEach((node) => {
|
|
5846
|
-
if (
|
|
5742
|
+
if (isDataFieldReference(node) && hasAttribute(node.target.ref, "@encrypted")) {
|
|
5847
5743
|
accept("error", `Encrypted fields cannot be used in policy rules`, {
|
|
5848
5744
|
node
|
|
5849
5745
|
});
|
|
@@ -5893,6 +5789,7 @@ _ts_decorate([
|
|
|
5893
5789
|
], AttributeApplicationValidator.prototype, "_checkValidate", null);
|
|
5894
5790
|
_ts_decorate([
|
|
5895
5791
|
check("@@unique"),
|
|
5792
|
+
check("@@id"),
|
|
5896
5793
|
_ts_metadata("design:type", Function),
|
|
5897
5794
|
_ts_metadata("design:paramtypes", [
|
|
5898
5795
|
typeof AttributeApplication === "undefined" ? Object : AttributeApplication,
|
|
@@ -5908,7 +5805,7 @@ function assignableToAttributeParam(arg, param, attr) {
|
|
|
5908
5805
|
let dstType = param.type.type;
|
|
5909
5806
|
let dstIsArray = param.type.array;
|
|
5910
5807
|
if (dstType === "ContextType") {
|
|
5911
|
-
if (
|
|
5808
|
+
if (isDataField(attr.$container)) {
|
|
5912
5809
|
dstIsArray = attr.$container.type.array;
|
|
5913
5810
|
}
|
|
5914
5811
|
}
|
|
@@ -5925,14 +5822,14 @@ function assignableToAttributeParam(arg, param, attr) {
|
|
|
5925
5822
|
}
|
|
5926
5823
|
if (dstType === "FieldReference" || dstType === "TransitiveFieldReference") {
|
|
5927
5824
|
if (dstIsArray) {
|
|
5928
|
-
return isArrayExpr(arg.value) && !arg.value.items.find((item) => !isReferenceExpr(item) || !
|
|
5825
|
+
return isArrayExpr(arg.value) && !arg.value.items.find((item) => !isReferenceExpr(item) || !isDataField(item.target.ref));
|
|
5929
5826
|
} else {
|
|
5930
|
-
return isReferenceExpr(arg.value) &&
|
|
5827
|
+
return isReferenceExpr(arg.value) && isDataField(arg.value.target.ref);
|
|
5931
5828
|
}
|
|
5932
5829
|
}
|
|
5933
5830
|
if (isEnum(argResolvedType.decl)) {
|
|
5934
5831
|
let attrArgDeclType = dstRef?.ref;
|
|
5935
|
-
if (dstType === "ContextType" &&
|
|
5832
|
+
if (dstType === "ContextType" && isDataField(attr.$container) && attr.$container?.type?.reference) {
|
|
5936
5833
|
attrArgDeclType = resolved(attr.$container.type.reference);
|
|
5937
5834
|
dstIsArray = attr.$container.type.array;
|
|
5938
5835
|
}
|
|
@@ -5942,7 +5839,7 @@ function assignableToAttributeParam(arg, param, attr) {
|
|
|
5942
5839
|
return false;
|
|
5943
5840
|
}
|
|
5944
5841
|
if (dstType === "ContextType") {
|
|
5945
|
-
if (
|
|
5842
|
+
if (isDataField(attr.$container)) {
|
|
5946
5843
|
if (!attr.$container?.type?.type) {
|
|
5947
5844
|
return false;
|
|
5948
5845
|
}
|
|
@@ -6010,8 +5907,8 @@ function isValidAttributeTarget(attrDecl, targetDecl) {
|
|
|
6010
5907
|
return allowed;
|
|
6011
5908
|
}
|
|
6012
5909
|
__name(isValidAttributeTarget, "isValidAttributeTarget");
|
|
6013
|
-
function validateAttributeApplication(attr, accept) {
|
|
6014
|
-
new AttributeApplicationValidator().validate(attr, accept);
|
|
5910
|
+
function validateAttributeApplication(attr, accept, contextDataModel) {
|
|
5911
|
+
new AttributeApplicationValidator().validate(attr, accept, contextDataModel);
|
|
6015
5912
|
}
|
|
6016
5913
|
__name(validateAttributeApplication, "validateAttributeApplication");
|
|
6017
5914
|
|
|
@@ -6026,6 +5923,7 @@ var AttributeValidator = class {
|
|
|
6026
5923
|
};
|
|
6027
5924
|
|
|
6028
5925
|
// src/validators/datamodel-validator.ts
|
|
5926
|
+
import { invariant as invariant2 } from "@zenstackhq/common-helpers";
|
|
6029
5927
|
import { AstUtils as AstUtils3 } from "langium";
|
|
6030
5928
|
|
|
6031
5929
|
// src/validators/common.ts
|
|
@@ -6038,8 +5936,8 @@ function validateDuplicatedDeclarations(container, decls, accept) {
|
|
|
6038
5936
|
for (const [name, decls2] of Object.entries(groupByName)) {
|
|
6039
5937
|
if (decls2.length > 1) {
|
|
6040
5938
|
let errorField = decls2[1];
|
|
6041
|
-
if (
|
|
6042
|
-
const nonInheritedFields = decls2.filter((x) => !(
|
|
5939
|
+
if (isDataField(decls2[0])) {
|
|
5940
|
+
const nonInheritedFields = decls2.filter((x) => !(isDataField(x) && x.$container !== container));
|
|
6043
5941
|
if (nonInheritedFields.length > 0) {
|
|
6044
5942
|
errorField = nonInheritedFields.slice(-1)[0];
|
|
6045
5943
|
}
|
|
@@ -6058,22 +5956,21 @@ var DataModelValidator = class {
|
|
|
6058
5956
|
__name(this, "DataModelValidator");
|
|
6059
5957
|
}
|
|
6060
5958
|
validate(dm, accept) {
|
|
6061
|
-
|
|
6062
|
-
this.validateBaseDelegateModel(dm, accept);
|
|
6063
|
-
validateDuplicatedDeclarations(dm, getModelFieldsWithBases(dm), accept);
|
|
5959
|
+
validateDuplicatedDeclarations(dm, getAllFields(dm), accept);
|
|
6064
5960
|
this.validateAttributes(dm, accept);
|
|
6065
5961
|
this.validateFields(dm, accept);
|
|
6066
|
-
if (dm.
|
|
6067
|
-
this.
|
|
5962
|
+
if (dm.mixins.length > 0) {
|
|
5963
|
+
this.validateMixins(dm, accept);
|
|
6068
5964
|
}
|
|
5965
|
+
this.validateInherits(dm, accept);
|
|
6069
5966
|
}
|
|
6070
5967
|
validateFields(dm, accept) {
|
|
6071
|
-
const allFields =
|
|
5968
|
+
const allFields = getAllFields(dm);
|
|
6072
5969
|
const idFields = allFields.filter((f) => f.attributes.find((attr) => attr.decl.ref?.name === "@id"));
|
|
6073
5970
|
const uniqueFields = allFields.filter((f) => f.attributes.find((attr) => attr.decl.ref?.name === "@unique"));
|
|
6074
5971
|
const modelLevelIds = getModelIdFields(dm);
|
|
6075
5972
|
const modelUniqueFields = getModelUniqueFields(dm);
|
|
6076
|
-
if (
|
|
5973
|
+
if (idFields.length === 0 && modelLevelIds.length === 0 && uniqueFields.length === 0 && modelUniqueFields.length === 0) {
|
|
6077
5974
|
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
5975
|
node: dm
|
|
6079
5976
|
});
|
|
@@ -6104,11 +6001,9 @@ var DataModelValidator = class {
|
|
|
6104
6001
|
});
|
|
6105
6002
|
}
|
|
6106
6003
|
dm.fields.forEach((field) => this.validateField(field, accept));
|
|
6107
|
-
|
|
6108
|
-
|
|
6109
|
-
|
|
6110
|
-
});
|
|
6111
|
-
}
|
|
6004
|
+
allFields.filter((x) => isDataModel(x.type.reference?.ref)).forEach((y) => {
|
|
6005
|
+
this.validateRelationField(dm, y, accept);
|
|
6006
|
+
});
|
|
6112
6007
|
}
|
|
6113
6008
|
validateField(field, accept) {
|
|
6114
6009
|
if (field.type.array && field.type.optional) {
|
|
@@ -6150,7 +6045,7 @@ var DataModelValidator = class {
|
|
|
6150
6045
|
return getLiteral(provider.value);
|
|
6151
6046
|
}
|
|
6152
6047
|
validateAttributes(dm, accept) {
|
|
6153
|
-
dm.
|
|
6048
|
+
getAllAttributes(dm).forEach((attr) => validateAttributeApplication(attr, accept, dm));
|
|
6154
6049
|
}
|
|
6155
6050
|
parseRelation(field, accept) {
|
|
6156
6051
|
const relAttr = field.attributes.find((attr) => attr.decl.ref?.name === "@relation");
|
|
@@ -6269,11 +6164,20 @@ var DataModelValidator = class {
|
|
|
6269
6164
|
if (!thisRelation.valid) {
|
|
6270
6165
|
return;
|
|
6271
6166
|
}
|
|
6272
|
-
if (this.isFieldInheritedFromDelegateModel(field
|
|
6167
|
+
if (this.isFieldInheritedFromDelegateModel(field)) {
|
|
6273
6168
|
return;
|
|
6274
6169
|
}
|
|
6170
|
+
if (this.isSelfRelation(field)) {
|
|
6171
|
+
if (!thisRelation.name) {
|
|
6172
|
+
accept("error", "Self-relation field must have a name in @relation attribute", {
|
|
6173
|
+
node: field
|
|
6174
|
+
});
|
|
6175
|
+
return;
|
|
6176
|
+
}
|
|
6177
|
+
}
|
|
6275
6178
|
const oppositeModel = field.type.reference.ref;
|
|
6276
|
-
let oppositeFields =
|
|
6179
|
+
let oppositeFields = getAllFields(oppositeModel, false).filter((f) => f !== field && // exclude self in case of self relation
|
|
6180
|
+
f.type.reference?.ref?.name === contextModel.name);
|
|
6277
6181
|
oppositeFields = oppositeFields.filter((f) => {
|
|
6278
6182
|
const fieldRel = this.parseRelation(f);
|
|
6279
6183
|
return fieldRel.valid && fieldRel.name === thisRelation.name;
|
|
@@ -6310,26 +6214,37 @@ var DataModelValidator = class {
|
|
|
6310
6214
|
const oppositeField = oppositeFields[0];
|
|
6311
6215
|
const oppositeRelation = this.parseRelation(oppositeField);
|
|
6312
6216
|
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;
|
|
6217
|
+
if (field.type.array && oppositeField.type.array) {
|
|
6218
|
+
for (const r of [
|
|
6219
|
+
thisRelation,
|
|
6220
|
+
oppositeRelation
|
|
6221
|
+
]) {
|
|
6222
|
+
if (r.fields?.length || r.references?.length) {
|
|
6223
|
+
accept("error", 'Implicit many-to-many relation cannot have "fields" or "references" in @relation attribute', {
|
|
6224
|
+
node: r === thisRelation ? field : oppositeField
|
|
6225
|
+
});
|
|
6226
|
+
}
|
|
6330
6227
|
}
|
|
6331
6228
|
} else {
|
|
6332
|
-
if (
|
|
6229
|
+
if (thisRelation?.references?.length && thisRelation.fields?.length) {
|
|
6230
|
+
if (oppositeRelation?.references || oppositeRelation?.fields) {
|
|
6231
|
+
accept("error", '"fields" and "references" must be provided only on one side of relation field', {
|
|
6232
|
+
node: oppositeField
|
|
6233
|
+
});
|
|
6234
|
+
return;
|
|
6235
|
+
} else {
|
|
6236
|
+
relationOwner = oppositeField;
|
|
6237
|
+
}
|
|
6238
|
+
} else if (oppositeRelation?.references?.length && oppositeRelation.fields?.length) {
|
|
6239
|
+
if (thisRelation?.references || thisRelation?.fields) {
|
|
6240
|
+
accept("error", '"fields" and "references" must be provided only on one side of relation field', {
|
|
6241
|
+
node: field
|
|
6242
|
+
});
|
|
6243
|
+
return;
|
|
6244
|
+
} else {
|
|
6245
|
+
relationOwner = field;
|
|
6246
|
+
}
|
|
6247
|
+
} else {
|
|
6333
6248
|
[
|
|
6334
6249
|
field,
|
|
6335
6250
|
oppositeField
|
|
@@ -6340,78 +6255,85 @@ var DataModelValidator = class {
|
|
|
6340
6255
|
});
|
|
6341
6256
|
}
|
|
6342
6257
|
});
|
|
6258
|
+
return;
|
|
6343
6259
|
}
|
|
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));
|
|
6260
|
+
if (!relationOwner.type.array && !relationOwner.type.optional) {
|
|
6261
|
+
accept("error", "Relation field needs to be list or optional", {
|
|
6262
|
+
node: relationOwner
|
|
6263
|
+
});
|
|
6264
|
+
return;
|
|
6357
6265
|
}
|
|
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
|
-
});
|
|
6266
|
+
if (relationOwner !== field && !relationOwner.type.array) {
|
|
6267
|
+
const containingModel = field.$container;
|
|
6268
|
+
const uniqueFieldList = getUniqueFields(containingModel);
|
|
6269
|
+
if (containingModel !== contextModel) {
|
|
6270
|
+
uniqueFieldList.push(...getUniqueFields(contextModel));
|
|
6370
6271
|
}
|
|
6371
|
-
|
|
6272
|
+
thisRelation.fields?.forEach((ref) => {
|
|
6273
|
+
const refField = ref.target.ref;
|
|
6274
|
+
if (refField) {
|
|
6275
|
+
if (refField.attributes.find((a) => a.decl.ref?.name === "@id" || a.decl.ref?.name === "@unique")) {
|
|
6276
|
+
return;
|
|
6277
|
+
}
|
|
6278
|
+
if (uniqueFieldList.some((list) => list.includes(refField))) {
|
|
6279
|
+
return;
|
|
6280
|
+
}
|
|
6281
|
+
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`, {
|
|
6282
|
+
node: refField
|
|
6283
|
+
});
|
|
6284
|
+
}
|
|
6285
|
+
});
|
|
6286
|
+
}
|
|
6372
6287
|
}
|
|
6373
6288
|
}
|
|
6374
6289
|
// 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
|
-
});
|
|
6290
|
+
isFieldInheritedFromDelegateModel(field) {
|
|
6291
|
+
return isDelegateModel(field.$container);
|
|
6391
6292
|
}
|
|
6392
|
-
|
|
6393
|
-
if (model.
|
|
6394
|
-
|
|
6293
|
+
validateInherits(model, accept) {
|
|
6294
|
+
if (!model.baseModel) {
|
|
6295
|
+
return;
|
|
6296
|
+
}
|
|
6297
|
+
invariant2(model.baseModel.ref, "baseModel must be resolved");
|
|
6298
|
+
if (!isDelegateModel(model.baseModel.ref)) {
|
|
6299
|
+
accept("error", `Model ${model.baseModel.$refText} cannot be extended because it's not a delegate model`, {
|
|
6395
6300
|
node: model,
|
|
6396
|
-
property: "
|
|
6301
|
+
property: "baseModel"
|
|
6397
6302
|
});
|
|
6303
|
+
return;
|
|
6398
6304
|
}
|
|
6399
|
-
|
|
6400
|
-
|
|
6401
|
-
|
|
6402
|
-
dm
|
|
6305
|
+
const seen = [];
|
|
6306
|
+
const todo = [
|
|
6307
|
+
model.baseModel.ref
|
|
6403
6308
|
];
|
|
6404
|
-
const todo = dm.superTypes.map((superType) => superType.ref);
|
|
6405
6309
|
while (todo.length > 0) {
|
|
6406
6310
|
const current = todo.shift();
|
|
6407
6311
|
if (seen.includes(current)) {
|
|
6408
|
-
accept("error", `
|
|
6312
|
+
accept("error", `Cyclic inheritance detected: ${seen.map((m) => m.name).join(" -> ")} -> ${current.name}`, {
|
|
6313
|
+
node: model
|
|
6314
|
+
});
|
|
6315
|
+
return;
|
|
6316
|
+
}
|
|
6317
|
+
seen.push(current);
|
|
6318
|
+
if (current.baseModel) {
|
|
6319
|
+
invariant2(current.baseModel.ref, "baseModel must be resolved");
|
|
6320
|
+
todo.push(current.baseModel.ref);
|
|
6321
|
+
}
|
|
6322
|
+
}
|
|
6323
|
+
}
|
|
6324
|
+
validateMixins(dm, accept) {
|
|
6325
|
+
const seen = [];
|
|
6326
|
+
const todo = dm.mixins.map((mixin) => mixin.ref);
|
|
6327
|
+
while (todo.length > 0) {
|
|
6328
|
+
const current = todo.shift();
|
|
6329
|
+
if (seen.includes(current)) {
|
|
6330
|
+
accept("error", `Cyclic mixin detected: ${seen.map((m) => m.name).join(" -> ")} -> ${current.name}`, {
|
|
6409
6331
|
node: dm
|
|
6410
6332
|
});
|
|
6411
6333
|
return;
|
|
6412
6334
|
}
|
|
6413
6335
|
seen.push(current);
|
|
6414
|
-
todo.push(...current.
|
|
6336
|
+
todo.push(...current.mixins.map((mixin) => mixin.ref));
|
|
6415
6337
|
}
|
|
6416
6338
|
}
|
|
6417
6339
|
};
|
|
@@ -6618,7 +6540,7 @@ var ExpressionValidator = class {
|
|
|
6618
6540
|
case "==":
|
|
6619
6541
|
case "!=": {
|
|
6620
6542
|
if (this.isInValidationContext(expr)) {
|
|
6621
|
-
if (
|
|
6543
|
+
if (isDataFieldReference(expr.left) && isNullExpr(expr.right) || isDataFieldReference(expr.right) && isNullExpr(expr.left)) {
|
|
6622
6544
|
return;
|
|
6623
6545
|
}
|
|
6624
6546
|
}
|
|
@@ -6647,11 +6569,11 @@ var ExpressionValidator = class {
|
|
|
6647
6569
|
node: expr
|
|
6648
6570
|
});
|
|
6649
6571
|
}
|
|
6650
|
-
if (
|
|
6572
|
+
if (isDataFieldReference(expr.left) && (isThisExpr(expr.right) || isDataFieldReference(expr.right))) {
|
|
6651
6573
|
accept("error", "comparison between model-typed fields are not supported", {
|
|
6652
6574
|
node: expr
|
|
6653
6575
|
});
|
|
6654
|
-
} else if (
|
|
6576
|
+
} else if (isDataFieldReference(expr.right) && (isThisExpr(expr.left) || isDataFieldReference(expr.left))) {
|
|
6655
6577
|
accept("error", "comparison between model-typed fields are not supported", {
|
|
6656
6578
|
node: expr
|
|
6657
6579
|
});
|
|
@@ -6746,7 +6668,7 @@ var FunctionInvocationValidator = class {
|
|
|
6746
6668
|
let curr = expr.$container;
|
|
6747
6669
|
let containerAttribute;
|
|
6748
6670
|
while (curr) {
|
|
6749
|
-
if (isDataModelAttribute(curr) ||
|
|
6671
|
+
if (isDataModelAttribute(curr) || isDataFieldAttribute(curr)) {
|
|
6750
6672
|
containerAttribute = curr;
|
|
6751
6673
|
break;
|
|
6752
6674
|
}
|
|
@@ -6847,7 +6769,7 @@ var FunctionInvocationValidator = class {
|
|
|
6847
6769
|
_checkCheck(expr, accept) {
|
|
6848
6770
|
let valid = true;
|
|
6849
6771
|
const fieldArg = expr.args[0].value;
|
|
6850
|
-
if (!
|
|
6772
|
+
if (!isDataFieldReference(fieldArg) || !isDataModel(fieldArg.$resolvedType?.decl)) {
|
|
6851
6773
|
accept("error", "argument must be a relation field", {
|
|
6852
6774
|
node: expr.args[0]
|
|
6853
6775
|
});
|
|
@@ -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
|
|