@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.cjs
CHANGED
|
@@ -96,7 +96,6 @@ __name(isLiteralExpr, "isLiteralExpr");
|
|
|
96
96
|
var MemberAccessTarget = "MemberAccessTarget";
|
|
97
97
|
var ReferenceTarget = "ReferenceTarget";
|
|
98
98
|
var TypeDeclaration = "TypeDeclaration";
|
|
99
|
-
var TypeDefFieldTypes = "TypeDefFieldTypes";
|
|
100
99
|
var Argument = "Argument";
|
|
101
100
|
var ArrayExpr = "ArrayExpr";
|
|
102
101
|
function isArrayExpr(item) {
|
|
@@ -129,6 +128,21 @@ __name(isConfigArrayExpr, "isConfigArrayExpr");
|
|
|
129
128
|
var ConfigField = "ConfigField";
|
|
130
129
|
var ConfigInvocationArg = "ConfigInvocationArg";
|
|
131
130
|
var ConfigInvocationExpr = "ConfigInvocationExpr";
|
|
131
|
+
var DataField = "DataField";
|
|
132
|
+
function isDataField(item) {
|
|
133
|
+
return reflection.isInstance(item, DataField);
|
|
134
|
+
}
|
|
135
|
+
__name(isDataField, "isDataField");
|
|
136
|
+
var DataFieldAttribute = "DataFieldAttribute";
|
|
137
|
+
function isDataFieldAttribute(item) {
|
|
138
|
+
return reflection.isInstance(item, DataFieldAttribute);
|
|
139
|
+
}
|
|
140
|
+
__name(isDataFieldAttribute, "isDataFieldAttribute");
|
|
141
|
+
var DataFieldType = "DataFieldType";
|
|
142
|
+
function isDataFieldType(item) {
|
|
143
|
+
return reflection.isInstance(item, DataFieldType);
|
|
144
|
+
}
|
|
145
|
+
__name(isDataFieldType, "isDataFieldType");
|
|
132
146
|
var DataModel = "DataModel";
|
|
133
147
|
function isDataModel(item) {
|
|
134
148
|
return reflection.isInstance(item, DataModel);
|
|
@@ -139,21 +153,6 @@ function isDataModelAttribute(item) {
|
|
|
139
153
|
return reflection.isInstance(item, DataModelAttribute);
|
|
140
154
|
}
|
|
141
155
|
__name(isDataModelAttribute, "isDataModelAttribute");
|
|
142
|
-
var DataModelField = "DataModelField";
|
|
143
|
-
function isDataModelField(item) {
|
|
144
|
-
return reflection.isInstance(item, DataModelField);
|
|
145
|
-
}
|
|
146
|
-
__name(isDataModelField, "isDataModelField");
|
|
147
|
-
var DataModelFieldAttribute = "DataModelFieldAttribute";
|
|
148
|
-
function isDataModelFieldAttribute(item) {
|
|
149
|
-
return reflection.isInstance(item, DataModelFieldAttribute);
|
|
150
|
-
}
|
|
151
|
-
__name(isDataModelFieldAttribute, "isDataModelFieldAttribute");
|
|
152
|
-
var DataModelFieldType = "DataModelFieldType";
|
|
153
|
-
function isDataModelFieldType(item) {
|
|
154
|
-
return reflection.isInstance(item, DataModelFieldType);
|
|
155
|
-
}
|
|
156
|
-
__name(isDataModelFieldType, "isDataModelFieldType");
|
|
157
156
|
var DataSource = "DataSource";
|
|
158
157
|
function isDataSource(item) {
|
|
159
158
|
return reflection.isInstance(item, DataSource);
|
|
@@ -207,6 +206,10 @@ function isObjectExpr(item) {
|
|
|
207
206
|
}
|
|
208
207
|
__name(isObjectExpr, "isObjectExpr");
|
|
209
208
|
var Plugin = "Plugin";
|
|
209
|
+
function isPlugin(item) {
|
|
210
|
+
return reflection.isInstance(item, Plugin);
|
|
211
|
+
}
|
|
212
|
+
__name(isPlugin, "isPlugin");
|
|
210
213
|
var PluginField = "PluginField";
|
|
211
214
|
var Procedure = "Procedure";
|
|
212
215
|
var ProcedureParam = "ProcedureParam";
|
|
@@ -231,12 +234,6 @@ function isTypeDef(item) {
|
|
|
231
234
|
return reflection.isInstance(item, TypeDef);
|
|
232
235
|
}
|
|
233
236
|
__name(isTypeDef, "isTypeDef");
|
|
234
|
-
var TypeDefField = "TypeDefField";
|
|
235
|
-
function isTypeDefField(item) {
|
|
236
|
-
return reflection.isInstance(item, TypeDefField);
|
|
237
|
-
}
|
|
238
|
-
__name(isTypeDefField, "isTypeDefField");
|
|
239
|
-
var TypeDefFieldType = "TypeDefFieldType";
|
|
240
237
|
var UnaryExpr = "UnaryExpr";
|
|
241
238
|
var UnsupportedFieldType = "UnsupportedFieldType";
|
|
242
239
|
var ZModelAstReflection = class extends langium.AbstractAstReflection {
|
|
@@ -259,11 +256,11 @@ var ZModelAstReflection = class extends langium.AbstractAstReflection {
|
|
|
259
256
|
ConfigField,
|
|
260
257
|
ConfigInvocationArg,
|
|
261
258
|
ConfigInvocationExpr,
|
|
259
|
+
DataField,
|
|
260
|
+
DataFieldAttribute,
|
|
261
|
+
DataFieldType,
|
|
262
262
|
DataModel,
|
|
263
263
|
DataModelAttribute,
|
|
264
|
-
DataModelField,
|
|
265
|
-
DataModelFieldAttribute,
|
|
266
|
-
DataModelFieldType,
|
|
267
264
|
DataSource,
|
|
268
265
|
Enum,
|
|
269
266
|
EnumField,
|
|
@@ -294,9 +291,6 @@ var ZModelAstReflection = class extends langium.AbstractAstReflection {
|
|
|
294
291
|
ThisExpr,
|
|
295
292
|
TypeDeclaration,
|
|
296
293
|
TypeDef,
|
|
297
|
-
TypeDefField,
|
|
298
|
-
TypeDefFieldType,
|
|
299
|
-
TypeDefFieldTypes,
|
|
300
294
|
UnaryExpr,
|
|
301
295
|
UnsupportedFieldType
|
|
302
296
|
];
|
|
@@ -329,16 +323,13 @@ var ZModelAstReflection = class extends langium.AbstractAstReflection {
|
|
|
329
323
|
case ConfigArrayExpr: {
|
|
330
324
|
return this.isSubtype(ConfigExpr, supertype);
|
|
331
325
|
}
|
|
332
|
-
case
|
|
333
|
-
return this.isSubtype(AbstractDeclaration, supertype) || this.isSubtype(TypeDeclaration, supertype);
|
|
334
|
-
}
|
|
335
|
-
case DataModelField:
|
|
336
|
-
case TypeDefField: {
|
|
326
|
+
case DataField: {
|
|
337
327
|
return this.isSubtype(MemberAccessTarget, supertype) || this.isSubtype(ReferenceTarget, supertype);
|
|
338
328
|
}
|
|
329
|
+
case DataModel:
|
|
339
330
|
case Enum:
|
|
340
331
|
case TypeDef: {
|
|
341
|
-
return this.isSubtype(AbstractDeclaration, supertype) || this.isSubtype(TypeDeclaration, supertype)
|
|
332
|
+
return this.isSubtype(AbstractDeclaration, supertype) || this.isSubtype(TypeDeclaration, supertype);
|
|
342
333
|
}
|
|
343
334
|
case EnumField:
|
|
344
335
|
case FunctionParam: {
|
|
@@ -357,18 +348,22 @@ var ZModelAstReflection = class extends langium.AbstractAstReflection {
|
|
|
357
348
|
const referenceId = `${refInfo.container.$type}:${refInfo.property}`;
|
|
358
349
|
switch (referenceId) {
|
|
359
350
|
case "AttributeParamType:reference":
|
|
360
|
-
case "
|
|
351
|
+
case "DataFieldType:reference":
|
|
361
352
|
case "FunctionParamType:reference": {
|
|
362
353
|
return TypeDeclaration;
|
|
363
354
|
}
|
|
364
|
-
case "
|
|
365
|
-
return DataModel;
|
|
366
|
-
}
|
|
355
|
+
case "DataFieldAttribute:decl":
|
|
367
356
|
case "DataModelAttribute:decl":
|
|
368
|
-
case "DataModelFieldAttribute:decl":
|
|
369
357
|
case "InternalAttribute:decl": {
|
|
370
358
|
return Attribute;
|
|
371
359
|
}
|
|
360
|
+
case "DataModel:baseModel": {
|
|
361
|
+
return DataModel;
|
|
362
|
+
}
|
|
363
|
+
case "DataModel:mixins":
|
|
364
|
+
case "TypeDef:mixins": {
|
|
365
|
+
return TypeDef;
|
|
366
|
+
}
|
|
372
367
|
case "InvocationExpr:function": {
|
|
373
368
|
return FunctionDecl;
|
|
374
369
|
}
|
|
@@ -378,9 +373,6 @@ var ZModelAstReflection = class extends langium.AbstractAstReflection {
|
|
|
378
373
|
case "ReferenceExpr:target": {
|
|
379
374
|
return ReferenceTarget;
|
|
380
375
|
}
|
|
381
|
-
case "TypeDefFieldType:reference": {
|
|
382
|
-
return TypeDefFieldTypes;
|
|
383
|
-
}
|
|
384
376
|
default: {
|
|
385
377
|
throw new Error(`${referenceId} is not a valid reference id.`);
|
|
386
378
|
}
|
|
@@ -567,9 +559,9 @@ var ZModelAstReflection = class extends langium.AbstractAstReflection {
|
|
|
567
559
|
]
|
|
568
560
|
};
|
|
569
561
|
}
|
|
570
|
-
case
|
|
562
|
+
case DataField: {
|
|
571
563
|
return {
|
|
572
|
-
name:
|
|
564
|
+
name: DataField,
|
|
573
565
|
properties: [
|
|
574
566
|
{
|
|
575
567
|
name: "attributes",
|
|
@@ -579,31 +571,18 @@ var ZModelAstReflection = class extends langium.AbstractAstReflection {
|
|
|
579
571
|
name: "comments",
|
|
580
572
|
defaultValue: []
|
|
581
573
|
},
|
|
582
|
-
{
|
|
583
|
-
name: "fields",
|
|
584
|
-
defaultValue: []
|
|
585
|
-
},
|
|
586
|
-
{
|
|
587
|
-
name: "isAbstract",
|
|
588
|
-
defaultValue: false
|
|
589
|
-
},
|
|
590
|
-
{
|
|
591
|
-
name: "isView",
|
|
592
|
-
defaultValue: false
|
|
593
|
-
},
|
|
594
574
|
{
|
|
595
575
|
name: "name"
|
|
596
576
|
},
|
|
597
577
|
{
|
|
598
|
-
name: "
|
|
599
|
-
defaultValue: []
|
|
578
|
+
name: "type"
|
|
600
579
|
}
|
|
601
580
|
]
|
|
602
581
|
};
|
|
603
582
|
}
|
|
604
|
-
case
|
|
583
|
+
case DataFieldAttribute: {
|
|
605
584
|
return {
|
|
606
|
-
name:
|
|
585
|
+
name: DataFieldAttribute,
|
|
607
586
|
properties: [
|
|
608
587
|
{
|
|
609
588
|
name: "args",
|
|
@@ -615,61 +594,73 @@ var ZModelAstReflection = class extends langium.AbstractAstReflection {
|
|
|
615
594
|
]
|
|
616
595
|
};
|
|
617
596
|
}
|
|
618
|
-
case
|
|
597
|
+
case DataFieldType: {
|
|
619
598
|
return {
|
|
620
|
-
name:
|
|
599
|
+
name: DataFieldType,
|
|
621
600
|
properties: [
|
|
622
601
|
{
|
|
623
|
-
name: "
|
|
624
|
-
defaultValue:
|
|
602
|
+
name: "array",
|
|
603
|
+
defaultValue: false
|
|
625
604
|
},
|
|
626
605
|
{
|
|
627
|
-
name: "
|
|
628
|
-
defaultValue:
|
|
606
|
+
name: "optional",
|
|
607
|
+
defaultValue: false
|
|
629
608
|
},
|
|
630
609
|
{
|
|
631
|
-
name: "
|
|
610
|
+
name: "reference"
|
|
632
611
|
},
|
|
633
612
|
{
|
|
634
613
|
name: "type"
|
|
614
|
+
},
|
|
615
|
+
{
|
|
616
|
+
name: "unsupported"
|
|
635
617
|
}
|
|
636
618
|
]
|
|
637
619
|
};
|
|
638
620
|
}
|
|
639
|
-
case
|
|
621
|
+
case DataModel: {
|
|
640
622
|
return {
|
|
641
|
-
name:
|
|
623
|
+
name: DataModel,
|
|
642
624
|
properties: [
|
|
643
625
|
{
|
|
644
|
-
name: "
|
|
626
|
+
name: "attributes",
|
|
645
627
|
defaultValue: []
|
|
646
628
|
},
|
|
647
629
|
{
|
|
648
|
-
name: "
|
|
649
|
-
}
|
|
650
|
-
]
|
|
651
|
-
};
|
|
652
|
-
}
|
|
653
|
-
case DataModelFieldType: {
|
|
654
|
-
return {
|
|
655
|
-
name: DataModelFieldType,
|
|
656
|
-
properties: [
|
|
630
|
+
name: "baseModel"
|
|
631
|
+
},
|
|
657
632
|
{
|
|
658
|
-
name: "
|
|
659
|
-
defaultValue:
|
|
633
|
+
name: "comments",
|
|
634
|
+
defaultValue: []
|
|
660
635
|
},
|
|
661
636
|
{
|
|
662
|
-
name: "
|
|
637
|
+
name: "fields",
|
|
638
|
+
defaultValue: []
|
|
639
|
+
},
|
|
640
|
+
{
|
|
641
|
+
name: "isView",
|
|
663
642
|
defaultValue: false
|
|
664
643
|
},
|
|
665
644
|
{
|
|
666
|
-
name: "
|
|
645
|
+
name: "mixins",
|
|
646
|
+
defaultValue: []
|
|
667
647
|
},
|
|
668
648
|
{
|
|
669
|
-
name: "
|
|
649
|
+
name: "name"
|
|
650
|
+
}
|
|
651
|
+
]
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
case DataModelAttribute: {
|
|
655
|
+
return {
|
|
656
|
+
name: DataModelAttribute,
|
|
657
|
+
properties: [
|
|
658
|
+
{
|
|
659
|
+
name: "args",
|
|
660
|
+
defaultValue: []
|
|
670
661
|
},
|
|
671
662
|
{
|
|
672
|
-
name: "
|
|
663
|
+
name: "decl"
|
|
673
664
|
}
|
|
674
665
|
]
|
|
675
666
|
};
|
|
@@ -1043,49 +1034,11 @@ var ZModelAstReflection = class extends langium.AbstractAstReflection {
|
|
|
1043
1034
|
defaultValue: []
|
|
1044
1035
|
},
|
|
1045
1036
|
{
|
|
1046
|
-
name: "
|
|
1047
|
-
}
|
|
1048
|
-
]
|
|
1049
|
-
};
|
|
1050
|
-
}
|
|
1051
|
-
case TypeDefField: {
|
|
1052
|
-
return {
|
|
1053
|
-
name: TypeDefField,
|
|
1054
|
-
properties: [
|
|
1055
|
-
{
|
|
1056
|
-
name: "attributes",
|
|
1057
|
-
defaultValue: []
|
|
1058
|
-
},
|
|
1059
|
-
{
|
|
1060
|
-
name: "comments",
|
|
1037
|
+
name: "mixins",
|
|
1061
1038
|
defaultValue: []
|
|
1062
1039
|
},
|
|
1063
1040
|
{
|
|
1064
1041
|
name: "name"
|
|
1065
|
-
},
|
|
1066
|
-
{
|
|
1067
|
-
name: "type"
|
|
1068
|
-
}
|
|
1069
|
-
]
|
|
1070
|
-
};
|
|
1071
|
-
}
|
|
1072
|
-
case TypeDefFieldType: {
|
|
1073
|
-
return {
|
|
1074
|
-
name: TypeDefFieldType,
|
|
1075
|
-
properties: [
|
|
1076
|
-
{
|
|
1077
|
-
name: "array",
|
|
1078
|
-
defaultValue: false
|
|
1079
|
-
},
|
|
1080
|
-
{
|
|
1081
|
-
name: "optional",
|
|
1082
|
-
defaultValue: false
|
|
1083
|
-
},
|
|
1084
|
-
{
|
|
1085
|
-
name: "reference"
|
|
1086
|
-
},
|
|
1087
|
-
{
|
|
1088
|
-
name: "type"
|
|
1089
1042
|
}
|
|
1090
1043
|
]
|
|
1091
1044
|
};
|
|
@@ -1246,7 +1199,7 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
|
|
|
1246
1199
|
{
|
|
1247
1200
|
"$type": "RuleCall",
|
|
1248
1201
|
"rule": {
|
|
1249
|
-
"$ref": "#/rules@
|
|
1202
|
+
"$ref": "#/rules@42"
|
|
1250
1203
|
},
|
|
1251
1204
|
"arguments": []
|
|
1252
1205
|
},
|
|
@@ -3040,16 +2993,6 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
|
|
|
3040
2993
|
{
|
|
3041
2994
|
"$type": "Group",
|
|
3042
2995
|
"elements": [
|
|
3043
|
-
{
|
|
3044
|
-
"$type": "Assignment",
|
|
3045
|
-
"feature": "isAbstract",
|
|
3046
|
-
"operator": "?=",
|
|
3047
|
-
"terminal": {
|
|
3048
|
-
"$type": "Keyword",
|
|
3049
|
-
"value": "abstract"
|
|
3050
|
-
},
|
|
3051
|
-
"cardinality": "?"
|
|
3052
|
-
},
|
|
3053
2996
|
{
|
|
3054
2997
|
"$type": "Keyword",
|
|
3055
2998
|
"value": "model"
|
|
@@ -3067,45 +3010,59 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
|
|
|
3067
3010
|
}
|
|
3068
3011
|
},
|
|
3069
3012
|
{
|
|
3070
|
-
"$type": "
|
|
3013
|
+
"$type": "Alternatives",
|
|
3071
3014
|
"elements": [
|
|
3072
3015
|
{
|
|
3073
|
-
"$type": "
|
|
3074
|
-
"
|
|
3016
|
+
"$type": "RuleCall",
|
|
3017
|
+
"rule": {
|
|
3018
|
+
"$ref": "#/rules@38"
|
|
3019
|
+
},
|
|
3020
|
+
"arguments": []
|
|
3021
|
+
},
|
|
3022
|
+
{
|
|
3023
|
+
"$type": "RuleCall",
|
|
3024
|
+
"rule": {
|
|
3025
|
+
"$ref": "#/rules@39"
|
|
3026
|
+
},
|
|
3027
|
+
"arguments": []
|
|
3075
3028
|
},
|
|
3076
3029
|
{
|
|
3077
|
-
"$type": "
|
|
3078
|
-
"
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3030
|
+
"$type": "Group",
|
|
3031
|
+
"elements": [
|
|
3032
|
+
{
|
|
3033
|
+
"$type": "RuleCall",
|
|
3034
|
+
"rule": {
|
|
3035
|
+
"$ref": "#/rules@39"
|
|
3036
|
+
},
|
|
3037
|
+
"arguments": []
|
|
3084
3038
|
},
|
|
3085
|
-
|
|
3086
|
-
|
|
3039
|
+
{
|
|
3040
|
+
"$type": "RuleCall",
|
|
3041
|
+
"rule": {
|
|
3042
|
+
"$ref": "#/rules@38"
|
|
3043
|
+
},
|
|
3044
|
+
"arguments": []
|
|
3045
|
+
}
|
|
3046
|
+
]
|
|
3087
3047
|
},
|
|
3088
3048
|
{
|
|
3089
3049
|
"$type": "Group",
|
|
3090
3050
|
"elements": [
|
|
3091
3051
|
{
|
|
3092
|
-
"$type": "
|
|
3093
|
-
"
|
|
3052
|
+
"$type": "RuleCall",
|
|
3053
|
+
"rule": {
|
|
3054
|
+
"$ref": "#/rules@38"
|
|
3055
|
+
},
|
|
3056
|
+
"arguments": []
|
|
3094
3057
|
},
|
|
3095
3058
|
{
|
|
3096
|
-
"$type": "
|
|
3097
|
-
"
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
"type": {
|
|
3102
|
-
"$ref": "#/rules@37"
|
|
3103
|
-
},
|
|
3104
|
-
"deprecatedSyntax": false
|
|
3105
|
-
}
|
|
3059
|
+
"$type": "RuleCall",
|
|
3060
|
+
"rule": {
|
|
3061
|
+
"$ref": "#/rules@39"
|
|
3062
|
+
},
|
|
3063
|
+
"arguments": []
|
|
3106
3064
|
}
|
|
3107
|
-
]
|
|
3108
|
-
"cardinality": "*"
|
|
3065
|
+
]
|
|
3109
3066
|
}
|
|
3110
3067
|
],
|
|
3111
3068
|
"cardinality": "?"
|
|
@@ -3154,7 +3111,7 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
|
|
|
3154
3111
|
"terminal": {
|
|
3155
3112
|
"$type": "RuleCall",
|
|
3156
3113
|
"rule": {
|
|
3157
|
-
"$ref": "#/rules@
|
|
3114
|
+
"$ref": "#/rules@40"
|
|
3158
3115
|
},
|
|
3159
3116
|
"arguments": []
|
|
3160
3117
|
}
|
|
@@ -3189,7 +3146,92 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
|
|
|
3189
3146
|
},
|
|
3190
3147
|
{
|
|
3191
3148
|
"$type": "ParserRule",
|
|
3192
|
-
"
|
|
3149
|
+
"fragment": true,
|
|
3150
|
+
"name": "WithClause",
|
|
3151
|
+
"definition": {
|
|
3152
|
+
"$type": "Group",
|
|
3153
|
+
"elements": [
|
|
3154
|
+
{
|
|
3155
|
+
"$type": "Keyword",
|
|
3156
|
+
"value": "with"
|
|
3157
|
+
},
|
|
3158
|
+
{
|
|
3159
|
+
"$type": "Assignment",
|
|
3160
|
+
"feature": "mixins",
|
|
3161
|
+
"operator": "+=",
|
|
3162
|
+
"terminal": {
|
|
3163
|
+
"$type": "CrossReference",
|
|
3164
|
+
"type": {
|
|
3165
|
+
"$ref": "#/rules@42"
|
|
3166
|
+
},
|
|
3167
|
+
"deprecatedSyntax": false
|
|
3168
|
+
}
|
|
3169
|
+
},
|
|
3170
|
+
{
|
|
3171
|
+
"$type": "Group",
|
|
3172
|
+
"elements": [
|
|
3173
|
+
{
|
|
3174
|
+
"$type": "Keyword",
|
|
3175
|
+
"value": ",",
|
|
3176
|
+
"cardinality": "?"
|
|
3177
|
+
},
|
|
3178
|
+
{
|
|
3179
|
+
"$type": "Assignment",
|
|
3180
|
+
"feature": "mixins",
|
|
3181
|
+
"operator": "+=",
|
|
3182
|
+
"terminal": {
|
|
3183
|
+
"$type": "CrossReference",
|
|
3184
|
+
"type": {
|
|
3185
|
+
"$ref": "#/rules@42"
|
|
3186
|
+
},
|
|
3187
|
+
"deprecatedSyntax": false
|
|
3188
|
+
}
|
|
3189
|
+
}
|
|
3190
|
+
],
|
|
3191
|
+
"cardinality": "*"
|
|
3192
|
+
}
|
|
3193
|
+
]
|
|
3194
|
+
},
|
|
3195
|
+
"definesHiddenTokens": false,
|
|
3196
|
+
"entry": false,
|
|
3197
|
+
"hiddenTokens": [],
|
|
3198
|
+
"parameters": [],
|
|
3199
|
+
"wildcard": false
|
|
3200
|
+
},
|
|
3201
|
+
{
|
|
3202
|
+
"$type": "ParserRule",
|
|
3203
|
+
"fragment": true,
|
|
3204
|
+
"name": "ExtendsClause",
|
|
3205
|
+
"definition": {
|
|
3206
|
+
"$type": "Group",
|
|
3207
|
+
"elements": [
|
|
3208
|
+
{
|
|
3209
|
+
"$type": "Keyword",
|
|
3210
|
+
"value": "extends"
|
|
3211
|
+
},
|
|
3212
|
+
{
|
|
3213
|
+
"$type": "Assignment",
|
|
3214
|
+
"feature": "baseModel",
|
|
3215
|
+
"operator": "=",
|
|
3216
|
+
"terminal": {
|
|
3217
|
+
"$type": "CrossReference",
|
|
3218
|
+
"type": {
|
|
3219
|
+
"$ref": "#/rules@37"
|
|
3220
|
+
},
|
|
3221
|
+
"deprecatedSyntax": false
|
|
3222
|
+
}
|
|
3223
|
+
}
|
|
3224
|
+
]
|
|
3225
|
+
},
|
|
3226
|
+
"definesHiddenTokens": false,
|
|
3227
|
+
"entry": false,
|
|
3228
|
+
"hiddenTokens": [],
|
|
3229
|
+
"parameters": [],
|
|
3230
|
+
"wildcard": false
|
|
3231
|
+
},
|
|
3232
|
+
{
|
|
3233
|
+
"$type": "ParserRule",
|
|
3234
|
+
"name": "DataField",
|
|
3193
3235
|
"definition": {
|
|
3194
3236
|
"$type": "Group",
|
|
3195
3237
|
"elements": [
|
|
@@ -3225,7 +3267,7 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
|
|
|
3225
3267
|
"terminal": {
|
|
3226
3268
|
"$type": "RuleCall",
|
|
3227
3269
|
"rule": {
|
|
3228
|
-
"$ref": "#/rules@
|
|
3270
|
+
"$ref": "#/rules@41"
|
|
3229
3271
|
},
|
|
3230
3272
|
"arguments": []
|
|
3231
3273
|
}
|
|
@@ -3254,7 +3296,7 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
|
|
|
3254
3296
|
},
|
|
3255
3297
|
{
|
|
3256
3298
|
"$type": "ParserRule",
|
|
3257
|
-
"name": "
|
|
3299
|
+
"name": "DataFieldType",
|
|
3258
3300
|
"definition": {
|
|
3259
3301
|
"$type": "Group",
|
|
3260
3302
|
"elements": [
|
|
@@ -3292,7 +3334,7 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
|
|
|
3292
3334
|
"terminal": {
|
|
3293
3335
|
"$type": "CrossReference",
|
|
3294
3336
|
"type": {
|
|
3295
|
-
"$ref": "#/types@
|
|
3337
|
+
"$ref": "#/types@2"
|
|
3296
3338
|
},
|
|
3297
3339
|
"terminal": {
|
|
3298
3340
|
"$type": "RuleCall",
|
|
@@ -3379,188 +3421,51 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
|
|
|
3379
3421
|
"arguments": []
|
|
3380
3422
|
}
|
|
3381
3423
|
},
|
|
3382
|
-
{
|
|
3383
|
-
"$type": "
|
|
3384
|
-
"
|
|
3385
|
-
|
|
3386
|
-
{
|
|
3387
|
-
"$type": "Alternatives",
|
|
3388
|
-
"elements": [
|
|
3389
|
-
{
|
|
3390
|
-
"$type": "Assignment",
|
|
3391
|
-
"feature": "fields",
|
|
3392
|
-
"operator": "+=",
|
|
3393
|
-
"terminal": {
|
|
3394
|
-
"$type": "RuleCall",
|
|
3395
|
-
"rule": {
|
|
3396
|
-
"$ref": "#/rules@41"
|
|
3397
|
-
},
|
|
3398
|
-
"arguments": []
|
|
3399
|
-
}
|
|
3400
|
-
},
|
|
3401
|
-
{
|
|
3402
|
-
"$type": "Assignment",
|
|
3403
|
-
"feature": "attributes",
|
|
3404
|
-
"operator": "+=",
|
|
3405
|
-
"terminal": {
|
|
3406
|
-
"$type": "RuleCall",
|
|
3407
|
-
"rule": {
|
|
3408
|
-
"$ref": "#/rules@57"
|
|
3409
|
-
},
|
|
3410
|
-
"arguments": []
|
|
3411
|
-
}
|
|
3412
|
-
}
|
|
3413
|
-
],
|
|
3414
|
-
"cardinality": "*"
|
|
3415
|
-
},
|
|
3416
|
-
{
|
|
3417
|
-
"$type": "Keyword",
|
|
3418
|
-
"value": "}"
|
|
3419
|
-
}
|
|
3420
|
-
]
|
|
3421
|
-
},
|
|
3422
|
-
"definesHiddenTokens": false,
|
|
3423
|
-
"entry": false,
|
|
3424
|
-
"fragment": false,
|
|
3425
|
-
"hiddenTokens": [],
|
|
3426
|
-
"parameters": [],
|
|
3427
|
-
"wildcard": false
|
|
3428
|
-
},
|
|
3429
|
-
{
|
|
3430
|
-
"$type": "ParserRule",
|
|
3431
|
-
"name": "TypeDefField",
|
|
3432
|
-
"definition": {
|
|
3433
|
-
"$type": "Group",
|
|
3434
|
-
"elements": [
|
|
3435
|
-
{
|
|
3436
|
-
"$type": "Assignment",
|
|
3437
|
-
"feature": "comments",
|
|
3438
|
-
"operator": "+=",
|
|
3439
|
-
"terminal": {
|
|
3440
|
-
"$type": "RuleCall",
|
|
3441
|
-
"rule": {
|
|
3442
|
-
"$ref": "#/rules@71"
|
|
3443
|
-
},
|
|
3444
|
-
"arguments": []
|
|
3445
|
-
},
|
|
3446
|
-
"cardinality": "*"
|
|
3447
|
-
},
|
|
3448
|
-
{
|
|
3449
|
-
"$type": "Assignment",
|
|
3450
|
-
"feature": "name",
|
|
3451
|
-
"operator": "=",
|
|
3452
|
-
"terminal": {
|
|
3453
|
-
"$type": "RuleCall",
|
|
3454
|
-
"rule": {
|
|
3455
|
-
"$ref": "#/rules@52"
|
|
3456
|
-
},
|
|
3457
|
-
"arguments": []
|
|
3458
|
-
}
|
|
3459
|
-
},
|
|
3460
|
-
{
|
|
3461
|
-
"$type": "Assignment",
|
|
3462
|
-
"feature": "type",
|
|
3463
|
-
"operator": "=",
|
|
3464
|
-
"terminal": {
|
|
3465
|
-
"$type": "RuleCall",
|
|
3466
|
-
"rule": {
|
|
3467
|
-
"$ref": "#/rules@42"
|
|
3468
|
-
},
|
|
3469
|
-
"arguments": []
|
|
3470
|
-
}
|
|
3471
|
-
},
|
|
3472
|
-
{
|
|
3473
|
-
"$type": "Assignment",
|
|
3474
|
-
"feature": "attributes",
|
|
3475
|
-
"operator": "+=",
|
|
3476
|
-
"terminal": {
|
|
3477
|
-
"$type": "RuleCall",
|
|
3478
|
-
"rule": {
|
|
3479
|
-
"$ref": "#/rules@56"
|
|
3480
|
-
},
|
|
3481
|
-
"arguments": []
|
|
3424
|
+
{
|
|
3425
|
+
"$type": "RuleCall",
|
|
3426
|
+
"rule": {
|
|
3427
|
+
"$ref": "#/rules@38"
|
|
3482
3428
|
},
|
|
3483
|
-
"
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
|
|
3487
|
-
|
|
3488
|
-
|
|
3489
|
-
|
|
3490
|
-
"hiddenTokens": [],
|
|
3491
|
-
"parameters": [],
|
|
3492
|
-
"wildcard": false
|
|
3493
|
-
},
|
|
3494
|
-
{
|
|
3495
|
-
"$type": "ParserRule",
|
|
3496
|
-
"name": "TypeDefFieldType",
|
|
3497
|
-
"definition": {
|
|
3498
|
-
"$type": "Group",
|
|
3499
|
-
"elements": [
|
|
3429
|
+
"arguments": [],
|
|
3430
|
+
"cardinality": "?"
|
|
3431
|
+
},
|
|
3432
|
+
{
|
|
3433
|
+
"$type": "Keyword",
|
|
3434
|
+
"value": "{"
|
|
3435
|
+
},
|
|
3500
3436
|
{
|
|
3501
3437
|
"$type": "Alternatives",
|
|
3502
3438
|
"elements": [
|
|
3503
3439
|
{
|
|
3504
3440
|
"$type": "Assignment",
|
|
3505
|
-
"feature": "
|
|
3506
|
-
"operator": "
|
|
3441
|
+
"feature": "fields",
|
|
3442
|
+
"operator": "+=",
|
|
3507
3443
|
"terminal": {
|
|
3508
3444
|
"$type": "RuleCall",
|
|
3509
3445
|
"rule": {
|
|
3510
|
-
"$ref": "#/rules@
|
|
3446
|
+
"$ref": "#/rules@40"
|
|
3511
3447
|
},
|
|
3512
3448
|
"arguments": []
|
|
3513
3449
|
}
|
|
3514
3450
|
},
|
|
3515
3451
|
{
|
|
3516
3452
|
"$type": "Assignment",
|
|
3517
|
-
"feature": "
|
|
3518
|
-
"operator": "
|
|
3453
|
+
"feature": "attributes",
|
|
3454
|
+
"operator": "+=",
|
|
3519
3455
|
"terminal": {
|
|
3520
|
-
"$type": "
|
|
3521
|
-
"
|
|
3522
|
-
"$ref": "#/
|
|
3523
|
-
},
|
|
3524
|
-
"terminal": {
|
|
3525
|
-
"$type": "RuleCall",
|
|
3526
|
-
"rule": {
|
|
3527
|
-
"$ref": "#/rules@51"
|
|
3528
|
-
},
|
|
3529
|
-
"arguments": []
|
|
3456
|
+
"$type": "RuleCall",
|
|
3457
|
+
"rule": {
|
|
3458
|
+
"$ref": "#/rules@57"
|
|
3530
3459
|
},
|
|
3531
|
-
"
|
|
3532
|
-
}
|
|
3533
|
-
}
|
|
3534
|
-
]
|
|
3535
|
-
},
|
|
3536
|
-
{
|
|
3537
|
-
"$type": "Group",
|
|
3538
|
-
"elements": [
|
|
3539
|
-
{
|
|
3540
|
-
"$type": "Assignment",
|
|
3541
|
-
"feature": "array",
|
|
3542
|
-
"operator": "?=",
|
|
3543
|
-
"terminal": {
|
|
3544
|
-
"$type": "Keyword",
|
|
3545
|
-
"value": "["
|
|
3460
|
+
"arguments": []
|
|
3546
3461
|
}
|
|
3547
|
-
},
|
|
3548
|
-
{
|
|
3549
|
-
"$type": "Keyword",
|
|
3550
|
-
"value": "]"
|
|
3551
3462
|
}
|
|
3552
3463
|
],
|
|
3553
|
-
"cardinality": "
|
|
3464
|
+
"cardinality": "*"
|
|
3554
3465
|
},
|
|
3555
3466
|
{
|
|
3556
|
-
"$type": "
|
|
3557
|
-
"
|
|
3558
|
-
"operator": "?=",
|
|
3559
|
-
"terminal": {
|
|
3560
|
-
"$type": "Keyword",
|
|
3561
|
-
"value": "?"
|
|
3562
|
-
},
|
|
3563
|
-
"cardinality": "?"
|
|
3467
|
+
"$type": "Keyword",
|
|
3468
|
+
"value": "}"
|
|
3564
3469
|
}
|
|
3565
3470
|
]
|
|
3566
3471
|
},
|
|
@@ -3971,7 +3876,7 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
|
|
|
3971
3876
|
"terminal": {
|
|
3972
3877
|
"$type": "CrossReference",
|
|
3973
3878
|
"type": {
|
|
3974
|
-
"$ref": "#/types@
|
|
3879
|
+
"$ref": "#/types@2"
|
|
3975
3880
|
},
|
|
3976
3881
|
"terminal": {
|
|
3977
3882
|
"$type": "RuleCall",
|
|
@@ -4585,7 +4490,7 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
|
|
|
4585
4490
|
"terminal": {
|
|
4586
4491
|
"$type": "CrossReference",
|
|
4587
4492
|
"type": {
|
|
4588
|
-
"$ref": "#/types@
|
|
4493
|
+
"$ref": "#/types@2"
|
|
4589
4494
|
},
|
|
4590
4495
|
"terminal": {
|
|
4591
4496
|
"$type": "RuleCall",
|
|
@@ -4639,7 +4544,7 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
|
|
|
4639
4544
|
},
|
|
4640
4545
|
{
|
|
4641
4546
|
"$type": "ParserRule",
|
|
4642
|
-
"name": "
|
|
4547
|
+
"name": "DataFieldAttribute",
|
|
4643
4548
|
"definition": {
|
|
4644
4549
|
"$type": "Group",
|
|
4645
4550
|
"elements": [
|
|
@@ -5156,13 +5061,7 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
|
|
|
5156
5061
|
{
|
|
5157
5062
|
"$type": "SimpleType",
|
|
5158
5063
|
"typeRef": {
|
|
5159
|
-
"$ref": "#/rules@
|
|
5160
|
-
}
|
|
5161
|
-
},
|
|
5162
|
-
{
|
|
5163
|
-
"$type": "SimpleType",
|
|
5164
|
-
"typeRef": {
|
|
5165
|
-
"$ref": "#/rules@41"
|
|
5064
|
+
"$ref": "#/rules@40"
|
|
5166
5065
|
}
|
|
5167
5066
|
},
|
|
5168
5067
|
{
|
|
@@ -5178,42 +5077,10 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
|
|
|
5178
5077
|
"$type": "Type",
|
|
5179
5078
|
"name": "MemberAccessTarget",
|
|
5180
5079
|
"type": {
|
|
5181
|
-
"$type": "
|
|
5182
|
-
"
|
|
5183
|
-
|
|
5184
|
-
|
|
5185
|
-
"typeRef": {
|
|
5186
|
-
"$ref": "#/rules@38"
|
|
5187
|
-
}
|
|
5188
|
-
},
|
|
5189
|
-
{
|
|
5190
|
-
"$type": "SimpleType",
|
|
5191
|
-
"typeRef": {
|
|
5192
|
-
"$ref": "#/rules@41"
|
|
5193
|
-
}
|
|
5194
|
-
}
|
|
5195
|
-
]
|
|
5196
|
-
}
|
|
5197
|
-
},
|
|
5198
|
-
{
|
|
5199
|
-
"$type": "Type",
|
|
5200
|
-
"name": "TypeDefFieldTypes",
|
|
5201
|
-
"type": {
|
|
5202
|
-
"$type": "UnionType",
|
|
5203
|
-
"types": [
|
|
5204
|
-
{
|
|
5205
|
-
"$type": "SimpleType",
|
|
5206
|
-
"typeRef": {
|
|
5207
|
-
"$ref": "#/rules@40"
|
|
5208
|
-
}
|
|
5209
|
-
},
|
|
5210
|
-
{
|
|
5211
|
-
"$type": "SimpleType",
|
|
5212
|
-
"typeRef": {
|
|
5213
|
-
"$ref": "#/rules@44"
|
|
5214
|
-
}
|
|
5215
|
-
}
|
|
5216
|
-
]
|
|
5080
|
+
"$type": "SimpleType",
|
|
5081
|
+
"typeRef": {
|
|
5082
|
+
"$ref": "#/rules@40"
|
|
5083
|
+
}
|
|
5217
5084
|
}
|
|
5218
5085
|
},
|
|
5219
5086
|
{
|
|
@@ -5231,7 +5098,7 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
|
|
|
5231
5098
|
{
|
|
5232
5099
|
"$type": "SimpleType",
|
|
5233
5100
|
"typeRef": {
|
|
5234
|
-
"$ref": "#/rules@
|
|
5101
|
+
"$ref": "#/rules@42"
|
|
5235
5102
|
}
|
|
5236
5103
|
},
|
|
5237
5104
|
{
|
|
@@ -5274,9 +5141,10 @@ var import_langium3 = require("langium");
|
|
|
5274
5141
|
var import_pluralize = __toESM(require("pluralize"), 1);
|
|
5275
5142
|
|
|
5276
5143
|
// src/utils.ts
|
|
5144
|
+
var import_common_helpers = require("@zenstackhq/common-helpers");
|
|
5277
5145
|
var import_langium2 = require("langium");
|
|
5278
|
-
var import_path = __toESM(require("path"), 1);
|
|
5279
5146
|
var import_node_fs = __toESM(require("fs"), 1);
|
|
5147
|
+
var import_path = __toESM(require("path"), 1);
|
|
5280
5148
|
function hasAttribute(decl, name) {
|
|
5281
5149
|
return !!getAttribute(decl, name);
|
|
5282
5150
|
}
|
|
@@ -5348,10 +5216,10 @@ function isEnumFieldReference(node) {
|
|
|
5348
5216
|
return isReferenceExpr(node) && isEnumField(node.target.ref);
|
|
5349
5217
|
}
|
|
5350
5218
|
__name(isEnumFieldReference, "isEnumFieldReference");
|
|
5351
|
-
function
|
|
5352
|
-
return isReferenceExpr(node) &&
|
|
5219
|
+
function isDataFieldReference(node) {
|
|
5220
|
+
return isReferenceExpr(node) && isDataField(node.target.ref);
|
|
5353
5221
|
}
|
|
5354
|
-
__name(
|
|
5222
|
+
__name(isDataFieldReference, "isDataFieldReference");
|
|
5355
5223
|
function isRelationshipField(field) {
|
|
5356
5224
|
return isDataModel(field.type.reference?.ref);
|
|
5357
5225
|
}
|
|
@@ -5371,43 +5239,14 @@ function resolved(ref) {
|
|
|
5371
5239
|
return ref.ref;
|
|
5372
5240
|
}
|
|
5373
5241
|
__name(resolved, "resolved");
|
|
5374
|
-
function
|
|
5375
|
-
for (const base of start.superTypes) {
|
|
5376
|
-
if (base.ref === target) {
|
|
5377
|
-
return [
|
|
5378
|
-
base.ref
|
|
5379
|
-
];
|
|
5380
|
-
}
|
|
5381
|
-
const path4 = findUpInheritance(base.ref, target);
|
|
5382
|
-
if (path4) {
|
|
5383
|
-
return [
|
|
5384
|
-
base.ref,
|
|
5385
|
-
...path4
|
|
5386
|
-
];
|
|
5387
|
-
}
|
|
5388
|
-
}
|
|
5389
|
-
return void 0;
|
|
5390
|
-
}
|
|
5391
|
-
__name(findUpInheritance, "findUpInheritance");
|
|
5392
|
-
function getModelFieldsWithBases(model, includeDelegate = true) {
|
|
5393
|
-
if (model.$baseMerged) {
|
|
5394
|
-
return model.fields;
|
|
5395
|
-
} else {
|
|
5396
|
-
return [
|
|
5397
|
-
...model.fields,
|
|
5398
|
-
...getRecursiveBases(model, includeDelegate).flatMap((base) => base.fields)
|
|
5399
|
-
];
|
|
5400
|
-
}
|
|
5401
|
-
}
|
|
5402
|
-
__name(getModelFieldsWithBases, "getModelFieldsWithBases");
|
|
5403
|
-
function getRecursiveBases(dataModel, includeDelegate = true, seen = /* @__PURE__ */ new Set()) {
|
|
5242
|
+
function getRecursiveBases(decl, includeDelegate = true, seen = /* @__PURE__ */ new Set()) {
|
|
5404
5243
|
const result = [];
|
|
5405
|
-
if (seen.has(
|
|
5244
|
+
if (seen.has(decl)) {
|
|
5406
5245
|
return result;
|
|
5407
5246
|
}
|
|
5408
|
-
seen.add(
|
|
5409
|
-
|
|
5410
|
-
const baseDecl =
|
|
5247
|
+
seen.add(decl);
|
|
5248
|
+
decl.mixins.forEach((mixin) => {
|
|
5249
|
+
const baseDecl = mixin.ref;
|
|
5411
5250
|
if (baseDecl) {
|
|
5412
5251
|
if (!includeDelegate && isDelegateModel(baseDecl)) {
|
|
5413
5252
|
return;
|
|
@@ -5420,14 +5259,13 @@ function getRecursiveBases(dataModel, includeDelegate = true, seen = /* @__PURE_
|
|
|
5420
5259
|
}
|
|
5421
5260
|
__name(getRecursiveBases, "getRecursiveBases");
|
|
5422
5261
|
function getModelIdFields(model) {
|
|
5423
|
-
const modelsToCheck =
|
|
5424
|
-
model
|
|
5425
|
-
] : [
|
|
5262
|
+
const modelsToCheck = [
|
|
5426
5263
|
model,
|
|
5427
5264
|
...getRecursiveBases(model)
|
|
5428
5265
|
];
|
|
5429
5266
|
for (const modelToCheck of modelsToCheck) {
|
|
5430
|
-
const
|
|
5267
|
+
const allAttributes = getAllAttributes(modelToCheck);
|
|
5268
|
+
const idAttr = allAttributes.find((attr) => attr.decl.$refText === "@@id");
|
|
5431
5269
|
if (!idAttr) {
|
|
5432
5270
|
continue;
|
|
5433
5271
|
}
|
|
@@ -5441,14 +5279,13 @@ function getModelIdFields(model) {
|
|
|
5441
5279
|
}
|
|
5442
5280
|
__name(getModelIdFields, "getModelIdFields");
|
|
5443
5281
|
function getModelUniqueFields(model) {
|
|
5444
|
-
const modelsToCheck =
|
|
5445
|
-
model
|
|
5446
|
-
] : [
|
|
5282
|
+
const modelsToCheck = [
|
|
5447
5283
|
model,
|
|
5448
5284
|
...getRecursiveBases(model)
|
|
5449
5285
|
];
|
|
5450
5286
|
for (const modelToCheck of modelsToCheck) {
|
|
5451
|
-
const
|
|
5287
|
+
const allAttributes = getAllAttributes(modelToCheck);
|
|
5288
|
+
const uniqueAttr = allAttributes.find((attr) => attr.decl.$refText === "@@unique");
|
|
5452
5289
|
if (!uniqueAttr) {
|
|
5453
5290
|
continue;
|
|
5454
5291
|
}
|
|
@@ -5687,6 +5524,42 @@ function isMemberContainer(node) {
|
|
|
5687
5524
|
return isDataModel(node) || isTypeDef(node);
|
|
5688
5525
|
}
|
|
5689
5526
|
__name(isMemberContainer, "isMemberContainer");
|
|
5527
|
+
function getAllFields(decl, includeIgnored = false, seen = /* @__PURE__ */ new Set()) {
|
|
5528
|
+
if (seen.has(decl)) {
|
|
5529
|
+
return [];
|
|
5530
|
+
}
|
|
5531
|
+
seen.add(decl);
|
|
5532
|
+
const fields = [];
|
|
5533
|
+
for (const mixin of decl.mixins) {
|
|
5534
|
+
(0, import_common_helpers.invariant)(mixin.ref, `Mixin ${mixin.$refText} is not resolved`);
|
|
5535
|
+
fields.push(...getAllFields(mixin.ref, includeIgnored, seen));
|
|
5536
|
+
}
|
|
5537
|
+
if (isDataModel(decl) && decl.baseModel) {
|
|
5538
|
+
(0, import_common_helpers.invariant)(decl.baseModel.ref, `Base model ${decl.baseModel.$refText} is not resolved`);
|
|
5539
|
+
fields.push(...getAllFields(decl.baseModel.ref, includeIgnored, seen));
|
|
5540
|
+
}
|
|
5541
|
+
fields.push(...decl.fields.filter((f) => includeIgnored || !hasAttribute(f, "@ignore")));
|
|
5542
|
+
return fields;
|
|
5543
|
+
}
|
|
5544
|
+
__name(getAllFields, "getAllFields");
|
|
5545
|
+
function getAllAttributes(decl, seen = /* @__PURE__ */ new Set()) {
|
|
5546
|
+
if (seen.has(decl)) {
|
|
5547
|
+
return [];
|
|
5548
|
+
}
|
|
5549
|
+
seen.add(decl);
|
|
5550
|
+
const attributes = [];
|
|
5551
|
+
for (const mixin of decl.mixins) {
|
|
5552
|
+
(0, import_common_helpers.invariant)(mixin.ref, `Mixin ${mixin.$refText} is not resolved`);
|
|
5553
|
+
attributes.push(...getAllAttributes(mixin.ref, seen));
|
|
5554
|
+
}
|
|
5555
|
+
if (isDataModel(decl) && decl.baseModel) {
|
|
5556
|
+
(0, import_common_helpers.invariant)(decl.baseModel.ref, `Base model ${decl.baseModel.$refText} is not resolved`);
|
|
5557
|
+
attributes.push(...getAllAttributes(decl.baseModel.ref, seen));
|
|
5558
|
+
}
|
|
5559
|
+
attributes.push(...decl.attributes);
|
|
5560
|
+
return attributes;
|
|
5561
|
+
}
|
|
5562
|
+
__name(getAllAttributes, "getAllAttributes");
|
|
5690
5563
|
|
|
5691
5564
|
// src/validators/attribute-application-validator.ts
|
|
5692
5565
|
function _ts_decorate(decorators, target, key, desc) {
|
|
@@ -5714,7 +5587,7 @@ var AttributeApplicationValidator = class {
|
|
|
5714
5587
|
static {
|
|
5715
5588
|
__name(this, "AttributeApplicationValidator");
|
|
5716
5589
|
}
|
|
5717
|
-
validate(attr, accept) {
|
|
5590
|
+
validate(attr, accept, contextDataModel) {
|
|
5718
5591
|
const decl = attr.decl.ref;
|
|
5719
5592
|
if (!decl) {
|
|
5720
5593
|
return;
|
|
@@ -5726,21 +5599,13 @@ var AttributeApplicationValidator = class {
|
|
|
5726
5599
|
});
|
|
5727
5600
|
return;
|
|
5728
5601
|
}
|
|
5729
|
-
if (
|
|
5602
|
+
if (isDataField(targetDecl) && !isValidAttributeTarget(decl, targetDecl)) {
|
|
5730
5603
|
accept("error", `attribute "${decl.name}" cannot be used on this type of field`, {
|
|
5731
5604
|
node: attr
|
|
5732
5605
|
});
|
|
5733
5606
|
}
|
|
5734
|
-
|
|
5735
|
-
|
|
5736
|
-
node: attr
|
|
5737
|
-
});
|
|
5738
|
-
}
|
|
5739
|
-
if (isTypeDef(targetDecl) && !hasAttribute(decl, "@@@supportTypeDef")) {
|
|
5740
|
-
accept("error", `attribute "${decl.name}" cannot be used on type declarations`, {
|
|
5741
|
-
node: attr
|
|
5742
|
-
});
|
|
5743
|
-
}
|
|
5607
|
+
this.checkDeprecation(attr, accept);
|
|
5608
|
+
this.checkDuplicatedAttributes(attr, accept, contextDataModel);
|
|
5744
5609
|
const filledParams = /* @__PURE__ */ new Set();
|
|
5745
5610
|
for (const arg of attr.args) {
|
|
5746
5611
|
let paramDecl;
|
|
@@ -5788,6 +5653,28 @@ var AttributeApplicationValidator = class {
|
|
|
5788
5653
|
checker.value.call(this, attr, accept);
|
|
5789
5654
|
}
|
|
5790
5655
|
}
|
|
5656
|
+
checkDeprecation(attr, accept) {
|
|
5657
|
+
const deprecateAttr = attr.decl.ref?.attributes.find((a) => a.decl.ref?.name === "@@@deprecated");
|
|
5658
|
+
if (deprecateAttr) {
|
|
5659
|
+
const message = getStringLiteral(deprecateAttr.args[0]?.value) ?? `Attribute "${attr.decl.ref?.name}" is deprecated`;
|
|
5660
|
+
accept("warning", message, {
|
|
5661
|
+
node: attr
|
|
5662
|
+
});
|
|
5663
|
+
}
|
|
5664
|
+
}
|
|
5665
|
+
checkDuplicatedAttributes(attr, accept, contextDataModel) {
|
|
5666
|
+
const attrDecl = attr.decl.ref;
|
|
5667
|
+
if (!attrDecl?.attributes.some((a) => a.decl.ref?.name === "@@@once")) {
|
|
5668
|
+
return;
|
|
5669
|
+
}
|
|
5670
|
+
const allAttributes = contextDataModel ? getAllAttributes(contextDataModel) : attr.$container.attributes;
|
|
5671
|
+
const duplicates = allAttributes.filter((a) => a.decl.ref === attrDecl && a !== attr);
|
|
5672
|
+
if (duplicates.length > 0) {
|
|
5673
|
+
accept("error", `Attribute "${attrDecl.name}" can only be applied once`, {
|
|
5674
|
+
node: attr
|
|
5675
|
+
});
|
|
5676
|
+
}
|
|
5677
|
+
}
|
|
5791
5678
|
_checkModelLevelPolicy(attr, accept) {
|
|
5792
5679
|
const kind = getStringLiteral(attr.args[0]?.value);
|
|
5793
5680
|
if (!kind) {
|
|
@@ -5836,7 +5723,7 @@ var AttributeApplicationValidator = class {
|
|
|
5836
5723
|
}
|
|
5837
5724
|
_checkValidate(attr, accept) {
|
|
5838
5725
|
const condition = attr.args[0]?.value;
|
|
5839
|
-
if (condition && import_langium3.AstUtils.streamAst(condition).some((node) =>
|
|
5726
|
+
if (condition && import_langium3.AstUtils.streamAst(condition).some((node) => isDataFieldReference(node) && isDataModel(node.$resolvedType?.decl))) {
|
|
5840
5727
|
accept("error", `\`@@validate\` condition cannot use relation fields`, {
|
|
5841
5728
|
node: condition
|
|
5842
5729
|
});
|
|
@@ -5845,9 +5732,18 @@ var AttributeApplicationValidator = class {
|
|
|
5845
5732
|
_checkUnique(attr, accept) {
|
|
5846
5733
|
const fields = attr.args[0]?.value;
|
|
5847
5734
|
if (!fields) {
|
|
5735
|
+
accept("error", `expects an array of field references`, {
|
|
5736
|
+
node: attr.args[0]
|
|
5737
|
+
});
|
|
5848
5738
|
return;
|
|
5849
5739
|
}
|
|
5850
5740
|
if (isArrayExpr(fields)) {
|
|
5741
|
+
if (fields.items.length === 0) {
|
|
5742
|
+
accept("error", `\`@@unique\` expects at least one field reference`, {
|
|
5743
|
+
node: fields
|
|
5744
|
+
});
|
|
5745
|
+
return;
|
|
5746
|
+
}
|
|
5851
5747
|
fields.items.forEach((item) => {
|
|
5852
5748
|
if (!isReferenceExpr(item)) {
|
|
5853
5749
|
accept("error", `Expecting a field reference`, {
|
|
@@ -5855,7 +5751,7 @@ var AttributeApplicationValidator = class {
|
|
|
5855
5751
|
});
|
|
5856
5752
|
return;
|
|
5857
5753
|
}
|
|
5858
|
-
if (!
|
|
5754
|
+
if (!isDataField(item.target.ref)) {
|
|
5859
5755
|
accept("error", `Expecting a field reference`, {
|
|
5860
5756
|
node: item
|
|
5861
5757
|
});
|
|
@@ -5875,7 +5771,7 @@ var AttributeApplicationValidator = class {
|
|
|
5875
5771
|
}
|
|
5876
5772
|
rejectEncryptedFields(attr, accept) {
|
|
5877
5773
|
import_langium3.AstUtils.streamAllContents(attr).forEach((node) => {
|
|
5878
|
-
if (
|
|
5774
|
+
if (isDataFieldReference(node) && hasAttribute(node.target.ref, "@encrypted")) {
|
|
5879
5775
|
accept("error", `Encrypted fields cannot be used in policy rules`, {
|
|
5880
5776
|
node
|
|
5881
5777
|
});
|
|
@@ -5925,6 +5821,7 @@ _ts_decorate([
|
|
|
5925
5821
|
], AttributeApplicationValidator.prototype, "_checkValidate", null);
|
|
5926
5822
|
_ts_decorate([
|
|
5927
5823
|
check("@@unique"),
|
|
5824
|
+
check("@@id"),
|
|
5928
5825
|
_ts_metadata("design:type", Function),
|
|
5929
5826
|
_ts_metadata("design:paramtypes", [
|
|
5930
5827
|
typeof AttributeApplication === "undefined" ? Object : AttributeApplication,
|
|
@@ -5940,7 +5837,7 @@ function assignableToAttributeParam(arg, param, attr) {
|
|
|
5940
5837
|
let dstType = param.type.type;
|
|
5941
5838
|
let dstIsArray = param.type.array;
|
|
5942
5839
|
if (dstType === "ContextType") {
|
|
5943
|
-
if (
|
|
5840
|
+
if (isDataField(attr.$container)) {
|
|
5944
5841
|
dstIsArray = attr.$container.type.array;
|
|
5945
5842
|
}
|
|
5946
5843
|
}
|
|
@@ -5957,14 +5854,14 @@ function assignableToAttributeParam(arg, param, attr) {
|
|
|
5957
5854
|
}
|
|
5958
5855
|
if (dstType === "FieldReference" || dstType === "TransitiveFieldReference") {
|
|
5959
5856
|
if (dstIsArray) {
|
|
5960
|
-
return isArrayExpr(arg.value) && !arg.value.items.find((item) => !isReferenceExpr(item) || !
|
|
5857
|
+
return isArrayExpr(arg.value) && !arg.value.items.find((item) => !isReferenceExpr(item) || !isDataField(item.target.ref));
|
|
5961
5858
|
} else {
|
|
5962
|
-
return isReferenceExpr(arg.value) &&
|
|
5859
|
+
return isReferenceExpr(arg.value) && isDataField(arg.value.target.ref);
|
|
5963
5860
|
}
|
|
5964
5861
|
}
|
|
5965
5862
|
if (isEnum(argResolvedType.decl)) {
|
|
5966
5863
|
let attrArgDeclType = dstRef?.ref;
|
|
5967
|
-
if (dstType === "ContextType" &&
|
|
5864
|
+
if (dstType === "ContextType" && isDataField(attr.$container) && attr.$container?.type?.reference) {
|
|
5968
5865
|
attrArgDeclType = resolved(attr.$container.type.reference);
|
|
5969
5866
|
dstIsArray = attr.$container.type.array;
|
|
5970
5867
|
}
|
|
@@ -5974,7 +5871,7 @@ function assignableToAttributeParam(arg, param, attr) {
|
|
|
5974
5871
|
return false;
|
|
5975
5872
|
}
|
|
5976
5873
|
if (dstType === "ContextType") {
|
|
5977
|
-
if (
|
|
5874
|
+
if (isDataField(attr.$container)) {
|
|
5978
5875
|
if (!attr.$container?.type?.type) {
|
|
5979
5876
|
return false;
|
|
5980
5877
|
}
|
|
@@ -6042,8 +5939,8 @@ function isValidAttributeTarget(attrDecl, targetDecl) {
|
|
|
6042
5939
|
return allowed;
|
|
6043
5940
|
}
|
|
6044
5941
|
__name(isValidAttributeTarget, "isValidAttributeTarget");
|
|
6045
|
-
function validateAttributeApplication(attr, accept) {
|
|
6046
|
-
new AttributeApplicationValidator().validate(attr, accept);
|
|
5942
|
+
function validateAttributeApplication(attr, accept, contextDataModel) {
|
|
5943
|
+
new AttributeApplicationValidator().validate(attr, accept, contextDataModel);
|
|
6047
5944
|
}
|
|
6048
5945
|
__name(validateAttributeApplication, "validateAttributeApplication");
|
|
6049
5946
|
|
|
@@ -6058,6 +5955,7 @@ var AttributeValidator = class {
|
|
|
6058
5955
|
};
|
|
6059
5956
|
|
|
6060
5957
|
// src/validators/datamodel-validator.ts
|
|
5958
|
+
var import_common_helpers2 = require("@zenstackhq/common-helpers");
|
|
6061
5959
|
var import_langium4 = require("langium");
|
|
6062
5960
|
|
|
6063
5961
|
// src/validators/common.ts
|
|
@@ -6070,8 +5968,8 @@ function validateDuplicatedDeclarations(container, decls, accept) {
|
|
|
6070
5968
|
for (const [name, decls2] of Object.entries(groupByName)) {
|
|
6071
5969
|
if (decls2.length > 1) {
|
|
6072
5970
|
let errorField = decls2[1];
|
|
6073
|
-
if (
|
|
6074
|
-
const nonInheritedFields = decls2.filter((x) => !(
|
|
5971
|
+
if (isDataField(decls2[0])) {
|
|
5972
|
+
const nonInheritedFields = decls2.filter((x) => !(isDataField(x) && x.$container !== container));
|
|
6075
5973
|
if (nonInheritedFields.length > 0) {
|
|
6076
5974
|
errorField = nonInheritedFields.slice(-1)[0];
|
|
6077
5975
|
}
|
|
@@ -6090,22 +5988,21 @@ var DataModelValidator = class {
|
|
|
6090
5988
|
__name(this, "DataModelValidator");
|
|
6091
5989
|
}
|
|
6092
5990
|
validate(dm, accept) {
|
|
6093
|
-
|
|
6094
|
-
this.validateBaseDelegateModel(dm, accept);
|
|
6095
|
-
validateDuplicatedDeclarations(dm, getModelFieldsWithBases(dm), accept);
|
|
5991
|
+
validateDuplicatedDeclarations(dm, getAllFields(dm), accept);
|
|
6096
5992
|
this.validateAttributes(dm, accept);
|
|
6097
5993
|
this.validateFields(dm, accept);
|
|
6098
|
-
if (dm.
|
|
6099
|
-
this.
|
|
5994
|
+
if (dm.mixins.length > 0) {
|
|
5995
|
+
this.validateMixins(dm, accept);
|
|
6100
5996
|
}
|
|
5997
|
+
this.validateInherits(dm, accept);
|
|
6101
5998
|
}
|
|
6102
5999
|
validateFields(dm, accept) {
|
|
6103
|
-
const allFields =
|
|
6000
|
+
const allFields = getAllFields(dm);
|
|
6104
6001
|
const idFields = allFields.filter((f) => f.attributes.find((attr) => attr.decl.ref?.name === "@id"));
|
|
6105
6002
|
const uniqueFields = allFields.filter((f) => f.attributes.find((attr) => attr.decl.ref?.name === "@unique"));
|
|
6106
6003
|
const modelLevelIds = getModelIdFields(dm);
|
|
6107
6004
|
const modelUniqueFields = getModelUniqueFields(dm);
|
|
6108
|
-
if (
|
|
6005
|
+
if (idFields.length === 0 && modelLevelIds.length === 0 && uniqueFields.length === 0 && modelUniqueFields.length === 0) {
|
|
6109
6006
|
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.", {
|
|
6110
6007
|
node: dm
|
|
6111
6008
|
});
|
|
@@ -6136,11 +6033,9 @@ var DataModelValidator = class {
|
|
|
6136
6033
|
});
|
|
6137
6034
|
}
|
|
6138
6035
|
dm.fields.forEach((field) => this.validateField(field, accept));
|
|
6139
|
-
|
|
6140
|
-
|
|
6141
|
-
|
|
6142
|
-
});
|
|
6143
|
-
}
|
|
6036
|
+
allFields.filter((x) => isDataModel(x.type.reference?.ref)).forEach((y) => {
|
|
6037
|
+
this.validateRelationField(dm, y, accept);
|
|
6038
|
+
});
|
|
6144
6039
|
}
|
|
6145
6040
|
validateField(field, accept) {
|
|
6146
6041
|
if (field.type.array && field.type.optional) {
|
|
@@ -6182,7 +6077,7 @@ var DataModelValidator = class {
|
|
|
6182
6077
|
return getLiteral(provider.value);
|
|
6183
6078
|
}
|
|
6184
6079
|
validateAttributes(dm, accept) {
|
|
6185
|
-
dm.
|
|
6080
|
+
getAllAttributes(dm).forEach((attr) => validateAttributeApplication(attr, accept, dm));
|
|
6186
6081
|
}
|
|
6187
6082
|
parseRelation(field, accept) {
|
|
6188
6083
|
const relAttr = field.attributes.find((attr) => attr.decl.ref?.name === "@relation");
|
|
@@ -6301,11 +6196,20 @@ var DataModelValidator = class {
|
|
|
6301
6196
|
if (!thisRelation.valid) {
|
|
6302
6197
|
return;
|
|
6303
6198
|
}
|
|
6304
|
-
if (this.isFieldInheritedFromDelegateModel(field
|
|
6199
|
+
if (this.isFieldInheritedFromDelegateModel(field)) {
|
|
6305
6200
|
return;
|
|
6306
6201
|
}
|
|
6202
|
+
if (this.isSelfRelation(field)) {
|
|
6203
|
+
if (!thisRelation.name) {
|
|
6204
|
+
accept("error", "Self-relation field must have a name in @relation attribute", {
|
|
6205
|
+
node: field
|
|
6206
|
+
});
|
|
6207
|
+
return;
|
|
6208
|
+
}
|
|
6209
|
+
}
|
|
6307
6210
|
const oppositeModel = field.type.reference.ref;
|
|
6308
|
-
let oppositeFields =
|
|
6211
|
+
let oppositeFields = getAllFields(oppositeModel, false).filter((f) => f !== field && // exclude self in case of self relation
|
|
6212
|
+
f.type.reference?.ref?.name === contextModel.name);
|
|
6309
6213
|
oppositeFields = oppositeFields.filter((f) => {
|
|
6310
6214
|
const fieldRel = this.parseRelation(f);
|
|
6311
6215
|
return fieldRel.valid && fieldRel.name === thisRelation.name;
|
|
@@ -6342,26 +6246,37 @@ var DataModelValidator = class {
|
|
|
6342
6246
|
const oppositeField = oppositeFields[0];
|
|
6343
6247
|
const oppositeRelation = this.parseRelation(oppositeField);
|
|
6344
6248
|
let relationOwner;
|
|
6345
|
-
if (
|
|
6346
|
-
|
|
6347
|
-
|
|
6348
|
-
|
|
6349
|
-
|
|
6350
|
-
|
|
6351
|
-
|
|
6352
|
-
|
|
6353
|
-
|
|
6354
|
-
|
|
6355
|
-
if (thisRelation?.references || thisRelation?.fields) {
|
|
6356
|
-
accept("error", '"fields" and "references" must be provided only on one side of relation field', {
|
|
6357
|
-
node: field
|
|
6358
|
-
});
|
|
6359
|
-
return;
|
|
6360
|
-
} else {
|
|
6361
|
-
relationOwner = field;
|
|
6249
|
+
if (field.type.array && oppositeField.type.array) {
|
|
6250
|
+
for (const r of [
|
|
6251
|
+
thisRelation,
|
|
6252
|
+
oppositeRelation
|
|
6253
|
+
]) {
|
|
6254
|
+
if (r.fields?.length || r.references?.length) {
|
|
6255
|
+
accept("error", 'Implicit many-to-many relation cannot have "fields" or "references" in @relation attribute', {
|
|
6256
|
+
node: r === thisRelation ? field : oppositeField
|
|
6257
|
+
});
|
|
6258
|
+
}
|
|
6362
6259
|
}
|
|
6363
6260
|
} else {
|
|
6364
|
-
if (
|
|
6261
|
+
if (thisRelation?.references?.length && thisRelation.fields?.length) {
|
|
6262
|
+
if (oppositeRelation?.references || oppositeRelation?.fields) {
|
|
6263
|
+
accept("error", '"fields" and "references" must be provided only on one side of relation field', {
|
|
6264
|
+
node: oppositeField
|
|
6265
|
+
});
|
|
6266
|
+
return;
|
|
6267
|
+
} else {
|
|
6268
|
+
relationOwner = oppositeField;
|
|
6269
|
+
}
|
|
6270
|
+
} else if (oppositeRelation?.references?.length && oppositeRelation.fields?.length) {
|
|
6271
|
+
if (thisRelation?.references || thisRelation?.fields) {
|
|
6272
|
+
accept("error", '"fields" and "references" must be provided only on one side of relation field', {
|
|
6273
|
+
node: field
|
|
6274
|
+
});
|
|
6275
|
+
return;
|
|
6276
|
+
} else {
|
|
6277
|
+
relationOwner = field;
|
|
6278
|
+
}
|
|
6279
|
+
} else {
|
|
6365
6280
|
[
|
|
6366
6281
|
field,
|
|
6367
6282
|
oppositeField
|
|
@@ -6372,78 +6287,85 @@ var DataModelValidator = class {
|
|
|
6372
6287
|
});
|
|
6373
6288
|
}
|
|
6374
6289
|
});
|
|
6290
|
+
return;
|
|
6375
6291
|
}
|
|
6376
|
-
|
|
6377
|
-
|
|
6378
|
-
|
|
6379
|
-
|
|
6380
|
-
|
|
6381
|
-
});
|
|
6382
|
-
return;
|
|
6383
|
-
}
|
|
6384
|
-
if (relationOwner !== field && !relationOwner.type.array) {
|
|
6385
|
-
const containingModel = field.$container;
|
|
6386
|
-
const uniqueFieldList = getUniqueFields(containingModel);
|
|
6387
|
-
if (containingModel !== contextModel) {
|
|
6388
|
-
uniqueFieldList.push(...getUniqueFields(contextModel));
|
|
6292
|
+
if (!relationOwner.type.array && !relationOwner.type.optional) {
|
|
6293
|
+
accept("error", "Relation field needs to be list or optional", {
|
|
6294
|
+
node: relationOwner
|
|
6295
|
+
});
|
|
6296
|
+
return;
|
|
6389
6297
|
}
|
|
6390
|
-
|
|
6391
|
-
const
|
|
6392
|
-
|
|
6393
|
-
|
|
6394
|
-
|
|
6395
|
-
}
|
|
6396
|
-
if (uniqueFieldList.some((list) => list.includes(refField))) {
|
|
6397
|
-
return;
|
|
6398
|
-
}
|
|
6399
|
-
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`, {
|
|
6400
|
-
node: refField
|
|
6401
|
-
});
|
|
6298
|
+
if (relationOwner !== field && !relationOwner.type.array) {
|
|
6299
|
+
const containingModel = field.$container;
|
|
6300
|
+
const uniqueFieldList = getUniqueFields(containingModel);
|
|
6301
|
+
if (containingModel !== contextModel) {
|
|
6302
|
+
uniqueFieldList.push(...getUniqueFields(contextModel));
|
|
6402
6303
|
}
|
|
6403
|
-
|
|
6304
|
+
thisRelation.fields?.forEach((ref) => {
|
|
6305
|
+
const refField = ref.target.ref;
|
|
6306
|
+
if (refField) {
|
|
6307
|
+
if (refField.attributes.find((a) => a.decl.ref?.name === "@id" || a.decl.ref?.name === "@unique")) {
|
|
6308
|
+
return;
|
|
6309
|
+
}
|
|
6310
|
+
if (uniqueFieldList.some((list) => list.includes(refField))) {
|
|
6311
|
+
return;
|
|
6312
|
+
}
|
|
6313
|
+
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`, {
|
|
6314
|
+
node: refField
|
|
6315
|
+
});
|
|
6316
|
+
}
|
|
6317
|
+
});
|
|
6318
|
+
}
|
|
6404
6319
|
}
|
|
6405
6320
|
}
|
|
6406
6321
|
// checks if the given field is inherited directly or indirectly from a delegate model
|
|
6407
|
-
isFieldInheritedFromDelegateModel(field
|
|
6408
|
-
|
|
6409
|
-
if (basePath && basePath.some(isDelegateModel)) {
|
|
6410
|
-
return true;
|
|
6411
|
-
} else {
|
|
6412
|
-
return false;
|
|
6413
|
-
}
|
|
6414
|
-
}
|
|
6415
|
-
validateBaseAbstractModel(model, accept) {
|
|
6416
|
-
model.superTypes.forEach((superType, index) => {
|
|
6417
|
-
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"`, {
|
|
6418
|
-
node: model,
|
|
6419
|
-
property: "superTypes",
|
|
6420
|
-
index
|
|
6421
|
-
});
|
|
6422
|
-
});
|
|
6322
|
+
isFieldInheritedFromDelegateModel(field) {
|
|
6323
|
+
return isDelegateModel(field.$container);
|
|
6423
6324
|
}
|
|
6424
|
-
|
|
6425
|
-
if (model.
|
|
6426
|
-
|
|
6325
|
+
validateInherits(model, accept) {
|
|
6326
|
+
if (!model.baseModel) {
|
|
6327
|
+
return;
|
|
6328
|
+
}
|
|
6329
|
+
(0, import_common_helpers2.invariant)(model.baseModel.ref, "baseModel must be resolved");
|
|
6330
|
+
if (!isDelegateModel(model.baseModel.ref)) {
|
|
6331
|
+
accept("error", `Model ${model.baseModel.$refText} cannot be extended because it's not a delegate model`, {
|
|
6427
6332
|
node: model,
|
|
6428
|
-
property: "
|
|
6333
|
+
property: "baseModel"
|
|
6429
6334
|
});
|
|
6335
|
+
return;
|
|
6430
6336
|
}
|
|
6431
|
-
|
|
6432
|
-
|
|
6433
|
-
|
|
6434
|
-
dm
|
|
6337
|
+
const seen = [];
|
|
6338
|
+
const todo = [
|
|
6339
|
+
model.baseModel.ref
|
|
6435
6340
|
];
|
|
6436
|
-
const todo = dm.superTypes.map((superType) => superType.ref);
|
|
6437
6341
|
while (todo.length > 0) {
|
|
6438
6342
|
const current = todo.shift();
|
|
6439
6343
|
if (seen.includes(current)) {
|
|
6440
|
-
accept("error", `
|
|
6344
|
+
accept("error", `Cyclic inheritance detected: ${seen.map((m) => m.name).join(" -> ")} -> ${current.name}`, {
|
|
6345
|
+
node: model
|
|
6346
|
+
});
|
|
6347
|
+
return;
|
|
6348
|
+
}
|
|
6349
|
+
seen.push(current);
|
|
6350
|
+
if (current.baseModel) {
|
|
6351
|
+
(0, import_common_helpers2.invariant)(current.baseModel.ref, "baseModel must be resolved");
|
|
6352
|
+
todo.push(current.baseModel.ref);
|
|
6353
|
+
}
|
|
6354
|
+
}
|
|
6355
|
+
}
|
|
6356
|
+
validateMixins(dm, accept) {
|
|
6357
|
+
const seen = [];
|
|
6358
|
+
const todo = dm.mixins.map((mixin) => mixin.ref);
|
|
6359
|
+
while (todo.length > 0) {
|
|
6360
|
+
const current = todo.shift();
|
|
6361
|
+
if (seen.includes(current)) {
|
|
6362
|
+
accept("error", `Cyclic mixin detected: ${seen.map((m) => m.name).join(" -> ")} -> ${current.name}`, {
|
|
6441
6363
|
node: dm
|
|
6442
6364
|
});
|
|
6443
6365
|
return;
|
|
6444
6366
|
}
|
|
6445
6367
|
seen.push(current);
|
|
6446
|
-
todo.push(...current.
|
|
6368
|
+
todo.push(...current.mixins.map((mixin) => mixin.ref));
|
|
6447
6369
|
}
|
|
6448
6370
|
}
|
|
6449
6371
|
};
|
|
@@ -6650,7 +6572,7 @@ var ExpressionValidator = class {
|
|
|
6650
6572
|
case "==":
|
|
6651
6573
|
case "!=": {
|
|
6652
6574
|
if (this.isInValidationContext(expr)) {
|
|
6653
|
-
if (
|
|
6575
|
+
if (isDataFieldReference(expr.left) && isNullExpr(expr.right) || isDataFieldReference(expr.right) && isNullExpr(expr.left)) {
|
|
6654
6576
|
return;
|
|
6655
6577
|
}
|
|
6656
6578
|
}
|
|
@@ -6679,11 +6601,11 @@ var ExpressionValidator = class {
|
|
|
6679
6601
|
node: expr
|
|
6680
6602
|
});
|
|
6681
6603
|
}
|
|
6682
|
-
if (
|
|
6604
|
+
if (isDataFieldReference(expr.left) && (isThisExpr(expr.right) || isDataFieldReference(expr.right))) {
|
|
6683
6605
|
accept("error", "comparison between model-typed fields are not supported", {
|
|
6684
6606
|
node: expr
|
|
6685
6607
|
});
|
|
6686
|
-
} else if (
|
|
6608
|
+
} else if (isDataFieldReference(expr.right) && (isThisExpr(expr.left) || isDataFieldReference(expr.left))) {
|
|
6687
6609
|
accept("error", "comparison between model-typed fields are not supported", {
|
|
6688
6610
|
node: expr
|
|
6689
6611
|
});
|
|
@@ -6778,7 +6700,7 @@ var FunctionInvocationValidator = class {
|
|
|
6778
6700
|
let curr = expr.$container;
|
|
6779
6701
|
let containerAttribute;
|
|
6780
6702
|
while (curr) {
|
|
6781
|
-
if (isDataModelAttribute(curr) ||
|
|
6703
|
+
if (isDataModelAttribute(curr) || isDataFieldAttribute(curr)) {
|
|
6782
6704
|
containerAttribute = curr;
|
|
6783
6705
|
break;
|
|
6784
6706
|
}
|
|
@@ -6879,7 +6801,7 @@ var FunctionInvocationValidator = class {
|
|
|
6879
6801
|
_checkCheck(expr, accept) {
|
|
6880
6802
|
let valid = true;
|
|
6881
6803
|
const fieldArg = expr.args[0].value;
|
|
6882
|
-
if (!
|
|
6804
|
+
if (!isDataFieldReference(fieldArg) || !isDataModel(fieldArg.$resolvedType?.decl)) {
|
|
6883
6805
|
accept("error", "argument must be a relation field", {
|
|
6884
6806
|
node: expr.args[0]
|
|
6885
6807
|
});
|
|
@@ -7181,8 +7103,8 @@ var ZModelLinker = class extends import_langium7.DefaultLinker {
|
|
|
7181
7103
|
case DataModel:
|
|
7182
7104
|
this.resolveDataModel(node, document, extraScopes);
|
|
7183
7105
|
break;
|
|
7184
|
-
case
|
|
7185
|
-
this.
|
|
7106
|
+
case DataField:
|
|
7107
|
+
this.resolveDataField(node, document, extraScopes);
|
|
7186
7108
|
break;
|
|
7187
7109
|
default:
|
|
7188
7110
|
this.resolveDefault(node, document, extraScopes);
|
|
@@ -7328,10 +7250,10 @@ var ZModelLinker = class extends import_langium7.DefaultLinker {
|
|
|
7328
7250
|
resolveAttributeArg(node, document, extraScopes) {
|
|
7329
7251
|
const attrParam = this.findAttrParamForArg(node);
|
|
7330
7252
|
const attrAppliedOn = node.$container.$container;
|
|
7331
|
-
if (attrParam?.type.type === "TransitiveFieldReference" &&
|
|
7253
|
+
if (attrParam?.type.type === "TransitiveFieldReference" && isDataField(attrAppliedOn)) {
|
|
7332
7254
|
const transitiveDataModel = attrAppliedOn.type.reference?.ref;
|
|
7333
7255
|
if (transitiveDataModel) {
|
|
7334
|
-
const scopeProvider = /* @__PURE__ */ __name((name) =>
|
|
7256
|
+
const scopeProvider = /* @__PURE__ */ __name((name) => getAllFields(transitiveDataModel).find((f) => f.name === name), "scopeProvider");
|
|
7335
7257
|
if (isArrayExpr(node.value)) {
|
|
7336
7258
|
node.value.items.forEach((item) => {
|
|
7337
7259
|
if (isReferenceExpr(item)) {
|
|
@@ -7387,7 +7309,7 @@ var ZModelLinker = class extends import_langium7.DefaultLinker {
|
|
|
7387
7309
|
resolveDataModel(node, document, extraScopes) {
|
|
7388
7310
|
return this.resolveDefault(node, document, extraScopes);
|
|
7389
7311
|
}
|
|
7390
|
-
|
|
7312
|
+
resolveDataField(node, document, extraScopes) {
|
|
7391
7313
|
this.resolve(node.type, document, extraScopes);
|
|
7392
7314
|
let scopes = extraScopes;
|
|
7393
7315
|
if (node.type.reference?.ref && isEnum(node.type.reference.ref)) {
|
|
@@ -7416,7 +7338,7 @@ var ZModelLinker = class extends import_langium7.DefaultLinker {
|
|
|
7416
7338
|
//#region Utils
|
|
7417
7339
|
resolveToDeclaredType(node, type) {
|
|
7418
7340
|
let nullable = false;
|
|
7419
|
-
if (
|
|
7341
|
+
if (isDataFieldType(type)) {
|
|
7420
7342
|
nullable = type.optional;
|
|
7421
7343
|
if (type.unsupported) {
|
|
7422
7344
|
node.$resolvedType = {
|
|
@@ -7477,6 +7399,14 @@ var ZModelScopeComputation = class extends import_langium8.DefaultScopeComputati
|
|
|
7477
7399
|
}
|
|
7478
7400
|
processNode(node, document, scopes) {
|
|
7479
7401
|
super.processNode(node, document, scopes);
|
|
7402
|
+
if (isDataModel(node)) {
|
|
7403
|
+
const bases = getRecursiveBases(node);
|
|
7404
|
+
for (const base of bases) {
|
|
7405
|
+
for (const field of base.fields) {
|
|
7406
|
+
scopes.add(node, this.descriptions.createDescription(field, this.nameProvider.getName(field)));
|
|
7407
|
+
}
|
|
7408
|
+
}
|
|
7409
|
+
}
|
|
7480
7410
|
}
|
|
7481
7411
|
};
|
|
7482
7412
|
var ZModelScopeProvider = class extends import_langium8.DefaultScopeProvider {
|
|
@@ -7524,16 +7454,13 @@ var ZModelScopeProvider = class extends import_langium8.DefaultScopeProvider {
|
|
|
7524
7454
|
);
|
|
7525
7455
|
return (0, import_ts_pattern3.match)(node.operand).when(isReferenceExpr, (operand) => {
|
|
7526
7456
|
const ref = operand.target.ref;
|
|
7527
|
-
if (
|
|
7457
|
+
if (isDataField(ref)) {
|
|
7528
7458
|
return this.createScopeForContainer(ref.type.reference?.ref, globalScope, allowTypeDefScope);
|
|
7529
7459
|
}
|
|
7530
7460
|
return import_langium8.EMPTY_SCOPE;
|
|
7531
7461
|
}).when(isMemberAccessExpr, (operand) => {
|
|
7532
7462
|
const ref = operand.member.ref;
|
|
7533
|
-
if (
|
|
7534
|
-
return this.createScopeForContainer(ref.type.reference?.ref, globalScope, allowTypeDefScope);
|
|
7535
|
-
}
|
|
7536
|
-
if (isTypeDefField(ref) && !ref.type.array) {
|
|
7463
|
+
if (isDataField(ref) && !ref.type.array) {
|
|
7537
7464
|
return this.createScopeForContainer(ref.type.reference?.ref, globalScope, allowTypeDefScope);
|
|
7538
7465
|
}
|
|
7539
7466
|
return import_langium8.EMPTY_SCOPE;
|
|
@@ -7556,13 +7483,13 @@ var ZModelScopeProvider = class extends import_langium8.DefaultScopeProvider {
|
|
|
7556
7483
|
const allowTypeDefScope = false;
|
|
7557
7484
|
return (0, import_ts_pattern3.match)(collection).when(isReferenceExpr, (expr) => {
|
|
7558
7485
|
const ref = expr.target.ref;
|
|
7559
|
-
if (
|
|
7486
|
+
if (isDataField(ref)) {
|
|
7560
7487
|
return this.createScopeForContainer(ref.type.reference?.ref, globalScope, allowTypeDefScope);
|
|
7561
7488
|
}
|
|
7562
7489
|
return import_langium8.EMPTY_SCOPE;
|
|
7563
7490
|
}).when(isMemberAccessExpr, (expr) => {
|
|
7564
7491
|
const ref = expr.member.ref;
|
|
7565
|
-
if (
|
|
7492
|
+
if (isDataField(ref)) {
|
|
7566
7493
|
return this.createScopeForContainer(ref.type.reference?.ref, globalScope, allowTypeDefScope);
|
|
7567
7494
|
}
|
|
7568
7495
|
return import_langium8.EMPTY_SCOPE;
|
|
@@ -7587,7 +7514,7 @@ var ZModelScopeProvider = class extends import_langium8.DefaultScopeProvider {
|
|
|
7587
7514
|
}
|
|
7588
7515
|
createScopeForContainer(node, globalScope, includeTypeDefScope = false) {
|
|
7589
7516
|
if (isDataModel(node)) {
|
|
7590
|
-
return this.createScopeForNodes(
|
|
7517
|
+
return this.createScopeForNodes(getAllFields(node), globalScope);
|
|
7591
7518
|
} else if (includeTypeDefScope && isTypeDef(node)) {
|
|
7592
7519
|
return this.createScopeForNodes(node.fields, globalScope);
|
|
7593
7520
|
} else {
|
|
@@ -7663,6 +7590,67 @@ var ZModelWorkspaceManager = class extends import_langium9.DefaultWorkspaceManag
|
|
|
7663
7590
|
}
|
|
7664
7591
|
const stdlib = await this.documentFactory.fromUri(import_langium9.URI.file(stdLibPath));
|
|
7665
7592
|
collector(stdlib);
|
|
7593
|
+
const documents = this.langiumDocuments.all;
|
|
7594
|
+
const pluginModels = /* @__PURE__ */ new Set();
|
|
7595
|
+
documents.forEach((doc) => {
|
|
7596
|
+
const parsed = doc.parseResult.value;
|
|
7597
|
+
parsed.declarations.forEach((decl) => {
|
|
7598
|
+
if (isPlugin(decl)) {
|
|
7599
|
+
const providerField = decl.fields.find((f) => f.name === "provider");
|
|
7600
|
+
if (providerField) {
|
|
7601
|
+
const provider = getLiteral(providerField.value);
|
|
7602
|
+
if (provider) {
|
|
7603
|
+
pluginModels.add(provider);
|
|
7604
|
+
}
|
|
7605
|
+
}
|
|
7606
|
+
}
|
|
7607
|
+
});
|
|
7608
|
+
});
|
|
7609
|
+
if (pluginModels.size > 0) {
|
|
7610
|
+
console.log(`Used plugin modules: ${Array.from(pluginModels)}`);
|
|
7611
|
+
const pendingPluginModules = new Set(pluginModels);
|
|
7612
|
+
await Promise.all(folders.map((wf) => [
|
|
7613
|
+
wf,
|
|
7614
|
+
this.getRootFolder(wf)
|
|
7615
|
+
]).map(async (entry) => this.loadPluginModels(...entry, pendingPluginModules, collector)));
|
|
7616
|
+
}
|
|
7617
|
+
}
|
|
7618
|
+
async loadPluginModels(workspaceFolder, folderPath, pendingPluginModels, collector) {
|
|
7619
|
+
const content = (await this.fileSystemProvider.readDirectory(folderPath)).sort((a, b) => {
|
|
7620
|
+
if (a.isDirectory && b.isDirectory) {
|
|
7621
|
+
const aName = import_langium9.UriUtils.basename(a.uri);
|
|
7622
|
+
if (aName === "node_modules") {
|
|
7623
|
+
return -1;
|
|
7624
|
+
} else {
|
|
7625
|
+
return 1;
|
|
7626
|
+
}
|
|
7627
|
+
} else {
|
|
7628
|
+
return 0;
|
|
7629
|
+
}
|
|
7630
|
+
});
|
|
7631
|
+
for (const entry of content) {
|
|
7632
|
+
if (entry.isDirectory) {
|
|
7633
|
+
const name = import_langium9.UriUtils.basename(entry.uri);
|
|
7634
|
+
if (name === "node_modules") {
|
|
7635
|
+
for (const plugin of Array.from(pendingPluginModels)) {
|
|
7636
|
+
const path4 = import_langium9.UriUtils.joinPath(entry.uri, plugin, PLUGIN_MODULE_NAME);
|
|
7637
|
+
try {
|
|
7638
|
+
await this.fileSystemProvider.readFile(path4);
|
|
7639
|
+
const document = await this.langiumDocuments.getOrCreateDocument(path4);
|
|
7640
|
+
collector(document);
|
|
7641
|
+
console.log(`Adding plugin document from ${path4.path}`);
|
|
7642
|
+
pendingPluginModels.delete(plugin);
|
|
7643
|
+
if (pendingPluginModels.size === 0) {
|
|
7644
|
+
return;
|
|
7645
|
+
}
|
|
7646
|
+
} catch {
|
|
7647
|
+
}
|
|
7648
|
+
}
|
|
7649
|
+
} else {
|
|
7650
|
+
await this.loadPluginModels(workspaceFolder, entry.uri, pendingPluginModels, collector);
|
|
7651
|
+
}
|
|
7652
|
+
}
|
|
7653
|
+
}
|
|
7666
7654
|
}
|
|
7667
7655
|
};
|
|
7668
7656
|
|