@zenstackhq/language 3.0.0-alpha.9 → 3.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -46,39 +46,6 @@ var import_node_fs3 = __toESM(require("fs"), 1);
46
46
  var import_node_path2 = __toESM(require("path"), 1);
47
47
  var import_node_url2 = require("url");
48
48
 
49
- // src/constants.ts
50
- var SUPPORTED_PROVIDERS = [
51
- "sqlite",
52
- "postgresql"
53
- ];
54
- var SCALAR_TYPES = [
55
- "String",
56
- "Int",
57
- "Float",
58
- "Decimal",
59
- "BigInt",
60
- "Boolean",
61
- "Bytes",
62
- "DateTime"
63
- ];
64
- var STD_LIB_MODULE_NAME = "stdlib.zmodel";
65
- var PLUGIN_MODULE_NAME = "plugin.zmodel";
66
- var IssueCodes = /* @__PURE__ */ function(IssueCodes2) {
67
- IssueCodes2["MissingOppositeRelation"] = "miss-opposite-relation";
68
- return IssueCodes2;
69
- }({});
70
- var ExpressionContext = /* @__PURE__ */ function(ExpressionContext2) {
71
- ExpressionContext2["DefaultValue"] = "DefaultValue";
72
- ExpressionContext2["AccessPolicy"] = "AccessPolicy";
73
- ExpressionContext2["ValidationRule"] = "ValidationRule";
74
- ExpressionContext2["Index"] = "Index";
75
- return ExpressionContext2;
76
- }({});
77
-
78
- // src/module.ts
79
- var import_langium10 = require("langium");
80
- var import_lsp = require("langium/lsp");
81
-
82
49
  // src/generated/ast.ts
83
50
  var langium = __toESM(require("langium"), 1);
84
51
  var AbstractDeclaration = "AbstractDeclaration";
@@ -96,7 +63,6 @@ __name(isLiteralExpr, "isLiteralExpr");
96
63
  var MemberAccessTarget = "MemberAccessTarget";
97
64
  var ReferenceTarget = "ReferenceTarget";
98
65
  var TypeDeclaration = "TypeDeclaration";
99
- var TypeDefFieldTypes = "TypeDefFieldTypes";
100
66
  var Argument = "Argument";
101
67
  var ArrayExpr = "ArrayExpr";
102
68
  function isArrayExpr(item) {
@@ -129,6 +95,21 @@ __name(isConfigArrayExpr, "isConfigArrayExpr");
129
95
  var ConfigField = "ConfigField";
130
96
  var ConfigInvocationArg = "ConfigInvocationArg";
131
97
  var ConfigInvocationExpr = "ConfigInvocationExpr";
98
+ var DataField = "DataField";
99
+ function isDataField(item) {
100
+ return reflection.isInstance(item, DataField);
101
+ }
102
+ __name(isDataField, "isDataField");
103
+ var DataFieldAttribute = "DataFieldAttribute";
104
+ function isDataFieldAttribute(item) {
105
+ return reflection.isInstance(item, DataFieldAttribute);
106
+ }
107
+ __name(isDataFieldAttribute, "isDataFieldAttribute");
108
+ var DataFieldType = "DataFieldType";
109
+ function isDataFieldType(item) {
110
+ return reflection.isInstance(item, DataFieldType);
111
+ }
112
+ __name(isDataFieldType, "isDataFieldType");
132
113
  var DataModel = "DataModel";
133
114
  function isDataModel(item) {
134
115
  return reflection.isInstance(item, DataModel);
@@ -139,21 +120,6 @@ function isDataModelAttribute(item) {
139
120
  return reflection.isInstance(item, DataModelAttribute);
140
121
  }
141
122
  __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
123
  var DataSource = "DataSource";
158
124
  function isDataSource(item) {
159
125
  return reflection.isInstance(item, DataSource);
@@ -207,6 +173,10 @@ function isObjectExpr(item) {
207
173
  }
208
174
  __name(isObjectExpr, "isObjectExpr");
209
175
  var Plugin = "Plugin";
176
+ function isPlugin(item) {
177
+ return reflection.isInstance(item, Plugin);
178
+ }
179
+ __name(isPlugin, "isPlugin");
210
180
  var PluginField = "PluginField";
211
181
  var Procedure = "Procedure";
212
182
  var ProcedureParam = "ProcedureParam";
@@ -231,12 +201,6 @@ function isTypeDef(item) {
231
201
  return reflection.isInstance(item, TypeDef);
232
202
  }
233
203
  __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
204
  var UnaryExpr = "UnaryExpr";
241
205
  var UnsupportedFieldType = "UnsupportedFieldType";
242
206
  var ZModelAstReflection = class extends langium.AbstractAstReflection {
@@ -259,11 +223,11 @@ var ZModelAstReflection = class extends langium.AbstractAstReflection {
259
223
  ConfigField,
260
224
  ConfigInvocationArg,
261
225
  ConfigInvocationExpr,
226
+ DataField,
227
+ DataFieldAttribute,
228
+ DataFieldType,
262
229
  DataModel,
263
230
  DataModelAttribute,
264
- DataModelField,
265
- DataModelFieldAttribute,
266
- DataModelFieldType,
267
231
  DataSource,
268
232
  Enum,
269
233
  EnumField,
@@ -294,9 +258,6 @@ var ZModelAstReflection = class extends langium.AbstractAstReflection {
294
258
  ThisExpr,
295
259
  TypeDeclaration,
296
260
  TypeDef,
297
- TypeDefField,
298
- TypeDefFieldType,
299
- TypeDefFieldTypes,
300
261
  UnaryExpr,
301
262
  UnsupportedFieldType
302
263
  ];
@@ -329,16 +290,13 @@ var ZModelAstReflection = class extends langium.AbstractAstReflection {
329
290
  case ConfigArrayExpr: {
330
291
  return this.isSubtype(ConfigExpr, supertype);
331
292
  }
332
- case DataModel: {
333
- return this.isSubtype(AbstractDeclaration, supertype) || this.isSubtype(TypeDeclaration, supertype);
334
- }
335
- case DataModelField:
336
- case TypeDefField: {
293
+ case DataField: {
337
294
  return this.isSubtype(MemberAccessTarget, supertype) || this.isSubtype(ReferenceTarget, supertype);
338
295
  }
296
+ case DataModel:
339
297
  case Enum:
340
298
  case TypeDef: {
341
- return this.isSubtype(AbstractDeclaration, supertype) || this.isSubtype(TypeDeclaration, supertype) || this.isSubtype(TypeDefFieldTypes, supertype);
299
+ return this.isSubtype(AbstractDeclaration, supertype) || this.isSubtype(TypeDeclaration, supertype);
342
300
  }
343
301
  case EnumField:
344
302
  case FunctionParam: {
@@ -357,18 +315,22 @@ var ZModelAstReflection = class extends langium.AbstractAstReflection {
357
315
  const referenceId = `${refInfo.container.$type}:${refInfo.property}`;
358
316
  switch (referenceId) {
359
317
  case "AttributeParamType:reference":
360
- case "DataModelFieldType:reference":
318
+ case "DataFieldType:reference":
361
319
  case "FunctionParamType:reference": {
362
320
  return TypeDeclaration;
363
321
  }
364
- case "DataModel:superTypes": {
365
- return DataModel;
366
- }
322
+ case "DataFieldAttribute:decl":
367
323
  case "DataModelAttribute:decl":
368
- case "DataModelFieldAttribute:decl":
369
324
  case "InternalAttribute:decl": {
370
325
  return Attribute;
371
326
  }
327
+ case "DataModel:baseModel": {
328
+ return DataModel;
329
+ }
330
+ case "DataModel:mixins":
331
+ case "TypeDef:mixins": {
332
+ return TypeDef;
333
+ }
372
334
  case "InvocationExpr:function": {
373
335
  return FunctionDecl;
374
336
  }
@@ -378,9 +340,6 @@ var ZModelAstReflection = class extends langium.AbstractAstReflection {
378
340
  case "ReferenceExpr:target": {
379
341
  return ReferenceTarget;
380
342
  }
381
- case "TypeDefFieldType:reference": {
382
- return TypeDefFieldTypes;
383
- }
384
343
  default: {
385
344
  throw new Error(`${referenceId} is not a valid reference id.`);
386
345
  }
@@ -567,9 +526,9 @@ var ZModelAstReflection = class extends langium.AbstractAstReflection {
567
526
  ]
568
527
  };
569
528
  }
570
- case DataModel: {
529
+ case DataField: {
571
530
  return {
572
- name: DataModel,
531
+ name: DataField,
573
532
  properties: [
574
533
  {
575
534
  name: "attributes",
@@ -579,31 +538,18 @@ var ZModelAstReflection = class extends langium.AbstractAstReflection {
579
538
  name: "comments",
580
539
  defaultValue: []
581
540
  },
582
- {
583
- name: "fields",
584
- defaultValue: []
585
- },
586
- {
587
- name: "isAbstract",
588
- defaultValue: false
589
- },
590
- {
591
- name: "isView",
592
- defaultValue: false
593
- },
594
541
  {
595
542
  name: "name"
596
543
  },
597
544
  {
598
- name: "superTypes",
599
- defaultValue: []
545
+ name: "type"
600
546
  }
601
547
  ]
602
548
  };
603
549
  }
604
- case DataModelAttribute: {
550
+ case DataFieldAttribute: {
605
551
  return {
606
- name: DataModelAttribute,
552
+ name: DataFieldAttribute,
607
553
  properties: [
608
554
  {
609
555
  name: "args",
@@ -615,61 +561,73 @@ var ZModelAstReflection = class extends langium.AbstractAstReflection {
615
561
  ]
616
562
  };
617
563
  }
618
- case DataModelField: {
564
+ case DataFieldType: {
619
565
  return {
620
- name: DataModelField,
566
+ name: DataFieldType,
621
567
  properties: [
622
568
  {
623
- name: "attributes",
624
- defaultValue: []
569
+ name: "array",
570
+ defaultValue: false
625
571
  },
626
572
  {
627
- name: "comments",
628
- defaultValue: []
573
+ name: "optional",
574
+ defaultValue: false
629
575
  },
630
576
  {
631
- name: "name"
577
+ name: "reference"
632
578
  },
633
579
  {
634
580
  name: "type"
581
+ },
582
+ {
583
+ name: "unsupported"
635
584
  }
636
585
  ]
637
586
  };
638
587
  }
639
- case DataModelFieldAttribute: {
588
+ case DataModel: {
640
589
  return {
641
- name: DataModelFieldAttribute,
590
+ name: DataModel,
642
591
  properties: [
643
592
  {
644
- name: "args",
593
+ name: "attributes",
645
594
  defaultValue: []
646
595
  },
647
596
  {
648
- name: "decl"
649
- }
650
- ]
651
- };
652
- }
653
- case DataModelFieldType: {
654
- return {
655
- name: DataModelFieldType,
656
- properties: [
597
+ name: "baseModel"
598
+ },
657
599
  {
658
- name: "array",
659
- defaultValue: false
600
+ name: "comments",
601
+ defaultValue: []
660
602
  },
661
603
  {
662
- name: "optional",
604
+ name: "fields",
605
+ defaultValue: []
606
+ },
607
+ {
608
+ name: "isView",
663
609
  defaultValue: false
664
610
  },
665
611
  {
666
- name: "reference"
612
+ name: "mixins",
613
+ defaultValue: []
667
614
  },
668
615
  {
669
- name: "type"
616
+ name: "name"
617
+ }
618
+ ]
619
+ };
620
+ }
621
+ case DataModelAttribute: {
622
+ return {
623
+ name: DataModelAttribute,
624
+ properties: [
625
+ {
626
+ name: "args",
627
+ defaultValue: []
670
628
  },
671
629
  {
672
- name: "unsupported"
630
+ name: "decl"
673
631
  }
674
632
  ]
675
633
  };
@@ -1043,49 +1001,11 @@ var ZModelAstReflection = class extends langium.AbstractAstReflection {
1043
1001
  defaultValue: []
1044
1002
  },
1045
1003
  {
1046
- name: "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",
1004
+ name: "mixins",
1061
1005
  defaultValue: []
1062
1006
  },
1063
1007
  {
1064
1008
  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
1009
  }
1090
1010
  ]
1091
1011
  };
@@ -1124,6 +1044,39 @@ var ZModelAstReflection = class extends langium.AbstractAstReflection {
1124
1044
  };
1125
1045
  var reflection = new ZModelAstReflection();
1126
1046
 
1047
+ // src/constants.ts
1048
+ var SUPPORTED_PROVIDERS = [
1049
+ "sqlite",
1050
+ "postgresql"
1051
+ ];
1052
+ var SCALAR_TYPES = [
1053
+ "String",
1054
+ "Int",
1055
+ "Float",
1056
+ "Decimal",
1057
+ "BigInt",
1058
+ "Boolean",
1059
+ "Bytes",
1060
+ "DateTime"
1061
+ ];
1062
+ var STD_LIB_MODULE_NAME = "stdlib.zmodel";
1063
+ var PLUGIN_MODULE_NAME = "plugin.zmodel";
1064
+ var IssueCodes = /* @__PURE__ */ function(IssueCodes2) {
1065
+ IssueCodes2["MissingOppositeRelation"] = "miss-opposite-relation";
1066
+ return IssueCodes2;
1067
+ }({});
1068
+ var ExpressionContext = /* @__PURE__ */ function(ExpressionContext2) {
1069
+ ExpressionContext2["DefaultValue"] = "DefaultValue";
1070
+ ExpressionContext2["AccessPolicy"] = "AccessPolicy";
1071
+ ExpressionContext2["ValidationRule"] = "ValidationRule";
1072
+ ExpressionContext2["Index"] = "Index";
1073
+ return ExpressionContext2;
1074
+ }({});
1075
+
1076
+ // src/module.ts
1077
+ var import_langium10 = require("langium");
1078
+ var import_lsp = require("langium/lsp");
1079
+
1127
1080
  // src/generated/grammar.ts
1128
1081
  var import_langium = require("langium");
1129
1082
  var loadedZModelGrammar;
@@ -1246,7 +1199,7 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
1246
1199
  {
1247
1200
  "$type": "RuleCall",
1248
1201
  "rule": {
1249
- "$ref": "#/rules@40"
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": "Group",
3013
+ "$type": "Alternatives",
3071
3014
  "elements": [
3072
3015
  {
3073
- "$type": "Keyword",
3074
- "value": "extends"
3016
+ "$type": "RuleCall",
3017
+ "rule": {
3018
+ "$ref": "#/rules@38"
3019
+ },
3020
+ "arguments": []
3075
3021
  },
3076
3022
  {
3077
- "$type": "Assignment",
3078
- "feature": "superTypes",
3079
- "operator": "+=",
3080
- "terminal": {
3081
- "$type": "CrossReference",
3082
- "type": {
3083
- "$ref": "#/rules@37"
3023
+ "$type": "RuleCall",
3024
+ "rule": {
3025
+ "$ref": "#/rules@39"
3026
+ },
3027
+ "arguments": []
3028
+ },
3029
+ {
3030
+ "$type": "Group",
3031
+ "elements": [
3032
+ {
3033
+ "$type": "RuleCall",
3034
+ "rule": {
3035
+ "$ref": "#/rules@39"
3036
+ },
3037
+ "arguments": []
3084
3038
  },
3085
- "deprecatedSyntax": false
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": "Keyword",
3093
- "value": ","
3052
+ "$type": "RuleCall",
3053
+ "rule": {
3054
+ "$ref": "#/rules@38"
3055
+ },
3056
+ "arguments": []
3094
3057
  },
3095
3058
  {
3096
- "$type": "Assignment",
3097
- "feature": "superTypes",
3098
- "operator": "+=",
3099
- "terminal": {
3100
- "$type": "CrossReference",
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@38"
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
- "name": "DataModelField",
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@39"
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": "DataModelFieldType",
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@3"
3337
+ "$ref": "#/types@2"
3296
3338
  },
3297
3339
  "terminal": {
3298
3340
  "$type": "RuleCall",
@@ -3379,6 +3421,14 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
3379
3421
  "arguments": []
3380
3422
  }
3381
3423
  },
3424
+ {
3425
+ "$type": "RuleCall",
3426
+ "rule": {
3427
+ "$ref": "#/rules@38"
3428
+ },
3429
+ "arguments": [],
3430
+ "cardinality": "?"
3431
+ },
3382
3432
  {
3383
3433
  "$type": "Keyword",
3384
3434
  "value": "{"
@@ -3393,174 +3443,29 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
3393
3443
  "terminal": {
3394
3444
  "$type": "RuleCall",
3395
3445
  "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"
3446
+ "$ref": "#/rules@40"
3409
3447
  },
3410
3448
  "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": []
3482
- },
3483
- "cardinality": "*"
3484
- }
3485
- ]
3486
- },
3487
- "definesHiddenTokens": false,
3488
- "entry": false,
3489
- "fragment": false,
3490
- "hiddenTokens": [],
3491
- "parameters": [],
3492
- "wildcard": false
3493
- },
3494
- {
3495
- "$type": "ParserRule",
3496
- "name": "TypeDefFieldType",
3497
- "definition": {
3498
- "$type": "Group",
3499
- "elements": [
3500
- {
3501
- "$type": "Alternatives",
3502
- "elements": [
3503
- {
3504
- "$type": "Assignment",
3505
- "feature": "type",
3506
- "operator": "=",
3507
- "terminal": {
3508
- "$type": "RuleCall",
3509
- "rule": {
3510
- "$ref": "#/rules@62"
3511
- },
3512
- "arguments": []
3513
- }
3514
- },
3515
- {
3516
- "$type": "Assignment",
3517
- "feature": "reference",
3518
- "operator": "=",
3519
- "terminal": {
3520
- "$type": "CrossReference",
3521
- "type": {
3522
- "$ref": "#/types@2"
3523
- },
3524
- "terminal": {
3525
- "$type": "RuleCall",
3526
- "rule": {
3527
- "$ref": "#/rules@51"
3528
- },
3529
- "arguments": []
3530
- },
3531
- "deprecatedSyntax": false
3532
- }
3533
- }
3534
- ]
3535
- },
3536
- {
3537
- "$type": "Group",
3538
- "elements": [
3449
+ }
3450
+ },
3539
3451
  {
3540
3452
  "$type": "Assignment",
3541
- "feature": "array",
3542
- "operator": "?=",
3453
+ "feature": "attributes",
3454
+ "operator": "+=",
3543
3455
  "terminal": {
3544
- "$type": "Keyword",
3545
- "value": "["
3456
+ "$type": "RuleCall",
3457
+ "rule": {
3458
+ "$ref": "#/rules@57"
3459
+ },
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": "Assignment",
3557
- "feature": "optional",
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@3"
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@3"
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": "DataModelFieldAttribute",
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@38"
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": "UnionType",
5182
- "types": [
5183
- {
5184
- "$type": "SimpleType",
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@40"
5101
+ "$ref": "#/rules@42"
5235
5102
  }
5236
5103
  },
5237
5104
  {
@@ -5253,7 +5120,7 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
5253
5120
 
5254
5121
  // src/generated/module.ts
5255
5122
  var ZModelLanguageMetaData = {
5256
- languageId: "zmodel",
5123
+ languageId: "zmodel-v3",
5257
5124
  fileExtensions: [
5258
5125
  ".zmodel"
5259
5126
  ],
@@ -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 isDataModelFieldReference(node) {
5352
- return isReferenceExpr(node) && isDataModelField(node.target.ref);
5219
+ function isDataFieldReference(node) {
5220
+ return isReferenceExpr(node) && isDataField(node.target.ref);
5353
5221
  }
5354
- __name(isDataModelFieldReference, "isDataModelFieldReference");
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 findUpInheritance(start, target) {
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(dataModel)) {
5244
+ if (seen.has(decl)) {
5406
5245
  return result;
5407
5246
  }
5408
- seen.add(dataModel);
5409
- dataModel.superTypes.forEach((superType) => {
5410
- const baseDecl = superType.ref;
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 = model.$baseMerged ? [
5424
- model
5425
- ] : [
5262
+ const modelsToCheck = [
5426
5263
  model,
5427
5264
  ...getRecursiveBases(model)
5428
5265
  ];
5429
5266
  for (const modelToCheck of modelsToCheck) {
5430
- const idAttr = modelToCheck.attributes.find((attr) => attr.decl.$refText === "@@id");
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 = model.$baseMerged ? [
5445
- model
5446
- ] : [
5282
+ const modelsToCheck = [
5447
5283
  model,
5448
5284
  ...getRecursiveBases(model)
5449
5285
  ];
5450
5286
  for (const modelToCheck of modelsToCheck) {
5451
- const uniqueAttr = modelToCheck.attributes.find((attr) => attr.decl.$refText === "@@unique");
5287
+ const allAttributes = getAllAttributes(modelToCheck);
5288
+ const uniqueAttr = allAttributes.find((attr) => attr.decl.$refText === "@@unique");
5452
5289
  if (!uniqueAttr) {
5453
5290
  continue;
5454
5291
  }
@@ -5595,34 +5432,24 @@ function resolveImport(documents, imp) {
5595
5432
  }
5596
5433
  __name(resolveImport, "resolveImport");
5597
5434
  function resolveImportUri(imp) {
5598
- if (!imp.path) return void 0;
5599
- if (!imp.path.endsWith(".zmodel")) {
5600
- imp.path += ".zmodel";
5601
- }
5602
- if (!imp.path.startsWith(".") && // Respect relative paths
5603
- !import_path.default.isAbsolute(imp.path)) {
5604
- const contextPath = imp.$container.$document ? import_path.default.dirname(imp.$container.$document.uri.fsPath) : process.cwd();
5605
- imp.path = findNodeModulesFile(imp.path, contextPath) ?? imp.path;
5435
+ if (!imp.path) {
5436
+ return void 0;
5606
5437
  }
5607
5438
  const doc = import_langium2.AstUtils.getDocument(imp);
5608
5439
  const dir = import_path.default.dirname(doc.uri.fsPath);
5609
- return import_langium2.URI.file(import_path.default.resolve(dir, imp.path));
5440
+ const importPath = imp.path.endsWith(".zmodel") ? imp.path : `${imp.path}.zmodel`;
5441
+ return import_langium2.URI.file(import_path.default.resolve(dir, importPath));
5610
5442
  }
5611
5443
  __name(resolveImportUri, "resolveImportUri");
5612
- function findNodeModulesFile(name, cwd = process.cwd()) {
5613
- if (!name) return void 0;
5614
- try {
5615
- const resolvedPath = require.resolve(name, {
5616
- paths: [
5617
- cwd
5618
- ]
5619
- });
5620
- return resolvedPath;
5621
- } catch {
5622
- return void 0;
5444
+ function getDataModelAndTypeDefs(model, includeIgnored = false) {
5445
+ const r = model.declarations.filter((d) => isDataModel(d) || isTypeDef(d));
5446
+ if (includeIgnored) {
5447
+ return r;
5448
+ } else {
5449
+ return r.filter((model2) => !hasAttribute(model2, "@@ignore"));
5623
5450
  }
5624
5451
  }
5625
- __name(findNodeModulesFile, "findNodeModulesFile");
5452
+ __name(getDataModelAndTypeDefs, "getDataModelAndTypeDefs");
5626
5453
  function getAllDeclarationsIncludingImports(documents, model) {
5627
5454
  const imports = resolveTransitiveImports(documents, model);
5628
5455
  return model.declarations.concat(...imports.map((imp) => imp.declarations));
@@ -5687,6 +5514,58 @@ function isMemberContainer(node) {
5687
5514
  return isDataModel(node) || isTypeDef(node);
5688
5515
  }
5689
5516
  __name(isMemberContainer, "isMemberContainer");
5517
+ function getAllFields(decl, includeIgnored = false, seen = /* @__PURE__ */ new Set()) {
5518
+ if (seen.has(decl)) {
5519
+ return [];
5520
+ }
5521
+ seen.add(decl);
5522
+ const fields = [];
5523
+ for (const mixin of decl.mixins) {
5524
+ (0, import_common_helpers.invariant)(mixin.ref, `Mixin ${mixin.$refText} is not resolved`);
5525
+ fields.push(...getAllFields(mixin.ref, includeIgnored, seen));
5526
+ }
5527
+ if (isDataModel(decl) && decl.baseModel) {
5528
+ (0, import_common_helpers.invariant)(decl.baseModel.ref, `Base model ${decl.baseModel.$refText} is not resolved`);
5529
+ fields.push(...getAllFields(decl.baseModel.ref, includeIgnored, seen));
5530
+ }
5531
+ fields.push(...decl.fields.filter((f) => includeIgnored || !hasAttribute(f, "@ignore")));
5532
+ return fields;
5533
+ }
5534
+ __name(getAllFields, "getAllFields");
5535
+ function getAllAttributes(decl, seen = /* @__PURE__ */ new Set()) {
5536
+ if (seen.has(decl)) {
5537
+ return [];
5538
+ }
5539
+ seen.add(decl);
5540
+ const attributes = [];
5541
+ for (const mixin of decl.mixins) {
5542
+ (0, import_common_helpers.invariant)(mixin.ref, `Mixin ${mixin.$refText} is not resolved`);
5543
+ attributes.push(...getAllAttributes(mixin.ref, seen));
5544
+ }
5545
+ if (isDataModel(decl) && decl.baseModel) {
5546
+ (0, import_common_helpers.invariant)(decl.baseModel.ref, `Base model ${decl.baseModel.$refText} is not resolved`);
5547
+ attributes.push(...getAllAttributes(decl.baseModel.ref, seen));
5548
+ }
5549
+ attributes.push(...decl.attributes);
5550
+ return attributes;
5551
+ }
5552
+ __name(getAllAttributes, "getAllAttributes");
5553
+ function getDocument(node) {
5554
+ const rootNode = findRootNode(node);
5555
+ const result = rootNode.$document;
5556
+ if (!result) {
5557
+ throw new Error("AST node has no document.");
5558
+ }
5559
+ return result;
5560
+ }
5561
+ __name(getDocument, "getDocument");
5562
+ function findRootNode(node) {
5563
+ while (node.$container) {
5564
+ node = node.$container;
5565
+ }
5566
+ return node;
5567
+ }
5568
+ __name(findRootNode, "findRootNode");
5690
5569
 
5691
5570
  // src/validators/attribute-application-validator.ts
5692
5571
  function _ts_decorate(decorators, target, key, desc) {
@@ -5714,7 +5593,7 @@ var AttributeApplicationValidator = class {
5714
5593
  static {
5715
5594
  __name(this, "AttributeApplicationValidator");
5716
5595
  }
5717
- validate(attr, accept) {
5596
+ validate(attr, accept, contextDataModel) {
5718
5597
  const decl = attr.decl.ref;
5719
5598
  if (!decl) {
5720
5599
  return;
@@ -5726,21 +5605,13 @@ var AttributeApplicationValidator = class {
5726
5605
  });
5727
5606
  return;
5728
5607
  }
5729
- if (isDataModelField(targetDecl) && !isValidAttributeTarget(decl, targetDecl)) {
5608
+ if (isDataField(targetDecl) && !isValidAttributeTarget(decl, targetDecl)) {
5730
5609
  accept("error", `attribute "${decl.name}" cannot be used on this type of field`, {
5731
5610
  node: attr
5732
5611
  });
5733
5612
  }
5734
- if (isTypeDefField(targetDecl) && !hasAttribute(decl, "@@@supportTypeDef")) {
5735
- accept("error", `attribute "${decl.name}" cannot be used on type declaration fields`, {
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
- }
5613
+ this.checkDeprecation(attr, accept);
5614
+ this.checkDuplicatedAttributes(attr, accept, contextDataModel);
5744
5615
  const filledParams = /* @__PURE__ */ new Set();
5745
5616
  for (const arg of attr.args) {
5746
5617
  let paramDecl;
@@ -5788,6 +5659,28 @@ var AttributeApplicationValidator = class {
5788
5659
  checker.value.call(this, attr, accept);
5789
5660
  }
5790
5661
  }
5662
+ checkDeprecation(attr, accept) {
5663
+ const deprecateAttr = attr.decl.ref?.attributes.find((a) => a.decl.ref?.name === "@@@deprecated");
5664
+ if (deprecateAttr) {
5665
+ const message = getStringLiteral(deprecateAttr.args[0]?.value) ?? `Attribute "${attr.decl.ref?.name}" is deprecated`;
5666
+ accept("warning", message, {
5667
+ node: attr
5668
+ });
5669
+ }
5670
+ }
5671
+ checkDuplicatedAttributes(attr, accept, contextDataModel) {
5672
+ const attrDecl = attr.decl.ref;
5673
+ if (!attrDecl?.attributes.some((a) => a.decl.ref?.name === "@@@once")) {
5674
+ return;
5675
+ }
5676
+ const allAttributes = contextDataModel ? getAllAttributes(contextDataModel) : attr.$container.attributes;
5677
+ const duplicates = allAttributes.filter((a) => a.decl.ref === attrDecl && a !== attr);
5678
+ if (duplicates.length > 0) {
5679
+ accept("error", `Attribute "${attrDecl.name}" can only be applied once`, {
5680
+ node: attr
5681
+ });
5682
+ }
5683
+ }
5791
5684
  _checkModelLevelPolicy(attr, accept) {
5792
5685
  const kind = getStringLiteral(attr.args[0]?.value);
5793
5686
  if (!kind) {
@@ -5836,7 +5729,7 @@ var AttributeApplicationValidator = class {
5836
5729
  }
5837
5730
  _checkValidate(attr, accept) {
5838
5731
  const condition = attr.args[0]?.value;
5839
- if (condition && import_langium3.AstUtils.streamAst(condition).some((node) => isDataModelFieldReference(node) && isDataModel(node.$resolvedType?.decl))) {
5732
+ if (condition && import_langium3.AstUtils.streamAst(condition).some((node) => isDataFieldReference(node) && isDataModel(node.$resolvedType?.decl))) {
5840
5733
  accept("error", `\`@@validate\` condition cannot use relation fields`, {
5841
5734
  node: condition
5842
5735
  });
@@ -5845,9 +5738,18 @@ var AttributeApplicationValidator = class {
5845
5738
  _checkUnique(attr, accept) {
5846
5739
  const fields = attr.args[0]?.value;
5847
5740
  if (!fields) {
5741
+ accept("error", `expects an array of field references`, {
5742
+ node: attr.args[0]
5743
+ });
5848
5744
  return;
5849
5745
  }
5850
5746
  if (isArrayExpr(fields)) {
5747
+ if (fields.items.length === 0) {
5748
+ accept("error", `\`@@unique\` expects at least one field reference`, {
5749
+ node: fields
5750
+ });
5751
+ return;
5752
+ }
5851
5753
  fields.items.forEach((item) => {
5852
5754
  if (!isReferenceExpr(item)) {
5853
5755
  accept("error", `Expecting a field reference`, {
@@ -5855,7 +5757,7 @@ var AttributeApplicationValidator = class {
5855
5757
  });
5856
5758
  return;
5857
5759
  }
5858
- if (!isDataModelField(item.target.ref)) {
5760
+ if (!isDataField(item.target.ref)) {
5859
5761
  accept("error", `Expecting a field reference`, {
5860
5762
  node: item
5861
5763
  });
@@ -5875,7 +5777,7 @@ var AttributeApplicationValidator = class {
5875
5777
  }
5876
5778
  rejectEncryptedFields(attr, accept) {
5877
5779
  import_langium3.AstUtils.streamAllContents(attr).forEach((node) => {
5878
- if (isDataModelFieldReference(node) && hasAttribute(node.target.ref, "@encrypted")) {
5780
+ if (isDataFieldReference(node) && hasAttribute(node.target.ref, "@encrypted")) {
5879
5781
  accept("error", `Encrypted fields cannot be used in policy rules`, {
5880
5782
  node
5881
5783
  });
@@ -5925,6 +5827,7 @@ _ts_decorate([
5925
5827
  ], AttributeApplicationValidator.prototype, "_checkValidate", null);
5926
5828
  _ts_decorate([
5927
5829
  check("@@unique"),
5830
+ check("@@id"),
5928
5831
  _ts_metadata("design:type", Function),
5929
5832
  _ts_metadata("design:paramtypes", [
5930
5833
  typeof AttributeApplication === "undefined" ? Object : AttributeApplication,
@@ -5940,7 +5843,7 @@ function assignableToAttributeParam(arg, param, attr) {
5940
5843
  let dstType = param.type.type;
5941
5844
  let dstIsArray = param.type.array;
5942
5845
  if (dstType === "ContextType") {
5943
- if (isDataModelField(attr.$container)) {
5846
+ if (isDataField(attr.$container)) {
5944
5847
  dstIsArray = attr.$container.type.array;
5945
5848
  }
5946
5849
  }
@@ -5957,14 +5860,14 @@ function assignableToAttributeParam(arg, param, attr) {
5957
5860
  }
5958
5861
  if (dstType === "FieldReference" || dstType === "TransitiveFieldReference") {
5959
5862
  if (dstIsArray) {
5960
- return isArrayExpr(arg.value) && !arg.value.items.find((item) => !isReferenceExpr(item) || !isDataModelField(item.target.ref));
5863
+ return isArrayExpr(arg.value) && !arg.value.items.find((item) => !isReferenceExpr(item) || !isDataField(item.target.ref));
5961
5864
  } else {
5962
- return isReferenceExpr(arg.value) && isDataModelField(arg.value.target.ref);
5865
+ return isReferenceExpr(arg.value) && isDataField(arg.value.target.ref);
5963
5866
  }
5964
5867
  }
5965
5868
  if (isEnum(argResolvedType.decl)) {
5966
5869
  let attrArgDeclType = dstRef?.ref;
5967
- if (dstType === "ContextType" && isDataModelField(attr.$container) && attr.$container?.type?.reference) {
5870
+ if (dstType === "ContextType" && isDataField(attr.$container) && attr.$container?.type?.reference) {
5968
5871
  attrArgDeclType = resolved(attr.$container.type.reference);
5969
5872
  dstIsArray = attr.$container.type.array;
5970
5873
  }
@@ -5974,7 +5877,7 @@ function assignableToAttributeParam(arg, param, attr) {
5974
5877
  return false;
5975
5878
  }
5976
5879
  if (dstType === "ContextType") {
5977
- if (isDataModelField(attr.$container)) {
5880
+ if (isDataField(attr.$container)) {
5978
5881
  if (!attr.$container?.type?.type) {
5979
5882
  return false;
5980
5883
  }
@@ -6042,8 +5945,8 @@ function isValidAttributeTarget(attrDecl, targetDecl) {
6042
5945
  return allowed;
6043
5946
  }
6044
5947
  __name(isValidAttributeTarget, "isValidAttributeTarget");
6045
- function validateAttributeApplication(attr, accept) {
6046
- new AttributeApplicationValidator().validate(attr, accept);
5948
+ function validateAttributeApplication(attr, accept, contextDataModel) {
5949
+ new AttributeApplicationValidator().validate(attr, accept, contextDataModel);
6047
5950
  }
6048
5951
  __name(validateAttributeApplication, "validateAttributeApplication");
6049
5952
 
@@ -6058,6 +5961,7 @@ var AttributeValidator = class {
6058
5961
  };
6059
5962
 
6060
5963
  // src/validators/datamodel-validator.ts
5964
+ var import_common_helpers2 = require("@zenstackhq/common-helpers");
6061
5965
  var import_langium4 = require("langium");
6062
5966
 
6063
5967
  // src/validators/common.ts
@@ -6070,8 +5974,8 @@ function validateDuplicatedDeclarations(container, decls, accept) {
6070
5974
  for (const [name, decls2] of Object.entries(groupByName)) {
6071
5975
  if (decls2.length > 1) {
6072
5976
  let errorField = decls2[1];
6073
- if (isDataModelField(decls2[0])) {
6074
- const nonInheritedFields = decls2.filter((x) => !(isDataModelField(x) && x.$container !== container));
5977
+ if (isDataField(decls2[0])) {
5978
+ const nonInheritedFields = decls2.filter((x) => !(isDataField(x) && x.$container !== container));
6075
5979
  if (nonInheritedFields.length > 0) {
6076
5980
  errorField = nonInheritedFields.slice(-1)[0];
6077
5981
  }
@@ -6090,22 +5994,21 @@ var DataModelValidator = class {
6090
5994
  __name(this, "DataModelValidator");
6091
5995
  }
6092
5996
  validate(dm, accept) {
6093
- this.validateBaseAbstractModel(dm, accept);
6094
- this.validateBaseDelegateModel(dm, accept);
6095
- validateDuplicatedDeclarations(dm, getModelFieldsWithBases(dm), accept);
5997
+ validateDuplicatedDeclarations(dm, getAllFields(dm), accept);
6096
5998
  this.validateAttributes(dm, accept);
6097
5999
  this.validateFields(dm, accept);
6098
- if (dm.superTypes.length > 0) {
6099
- this.validateInheritance(dm, accept);
6000
+ if (dm.mixins.length > 0) {
6001
+ this.validateMixins(dm, accept);
6100
6002
  }
6003
+ this.validateInherits(dm, accept);
6101
6004
  }
6102
6005
  validateFields(dm, accept) {
6103
- const allFields = getModelFieldsWithBases(dm);
6006
+ const allFields = getAllFields(dm);
6104
6007
  const idFields = allFields.filter((f) => f.attributes.find((attr) => attr.decl.ref?.name === "@id"));
6105
6008
  const uniqueFields = allFields.filter((f) => f.attributes.find((attr) => attr.decl.ref?.name === "@unique"));
6106
6009
  const modelLevelIds = getModelIdFields(dm);
6107
6010
  const modelUniqueFields = getModelUniqueFields(dm);
6108
- if (!dm.isAbstract && idFields.length === 0 && modelLevelIds.length === 0 && uniqueFields.length === 0 && modelUniqueFields.length === 0) {
6011
+ if (idFields.length === 0 && modelLevelIds.length === 0 && uniqueFields.length === 0 && modelUniqueFields.length === 0) {
6109
6012
  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
6013
  node: dm
6111
6014
  });
@@ -6136,11 +6039,9 @@ var DataModelValidator = class {
6136
6039
  });
6137
6040
  }
6138
6041
  dm.fields.forEach((field) => this.validateField(field, accept));
6139
- if (!dm.isAbstract) {
6140
- allFields.filter((x) => isDataModel(x.type.reference?.ref)).forEach((y) => {
6141
- this.validateRelationField(dm, y, accept);
6142
- });
6143
- }
6042
+ allFields.filter((x) => isDataModel(x.type.reference?.ref)).forEach((y) => {
6043
+ this.validateRelationField(dm, y, accept);
6044
+ });
6144
6045
  }
6145
6046
  validateField(field, accept) {
6146
6047
  if (field.type.array && field.type.optional) {
@@ -6156,7 +6057,7 @@ var DataModelValidator = class {
6156
6057
  if (field.type.array && !isDataModel(field.type.reference?.ref)) {
6157
6058
  const provider = this.getDataSourceProvider(import_langium4.AstUtils.getContainerOfType(field, isModel));
6158
6059
  if (provider === "sqlite") {
6159
- accept("error", `Array type is not supported for "${provider}" provider.`, {
6060
+ accept("error", `List type is not supported for "${provider}" provider.`, {
6160
6061
  node: field.type
6161
6062
  });
6162
6063
  }
@@ -6182,7 +6083,7 @@ var DataModelValidator = class {
6182
6083
  return getLiteral(provider.value);
6183
6084
  }
6184
6085
  validateAttributes(dm, accept) {
6185
- dm.attributes.forEach((attr) => validateAttributeApplication(attr, accept));
6086
+ getAllAttributes(dm).forEach((attr) => validateAttributeApplication(attr, accept, dm));
6186
6087
  }
6187
6088
  parseRelation(field, accept) {
6188
6089
  const relAttr = field.attributes.find((attr) => attr.decl.ref?.name === "@relation");
@@ -6301,11 +6202,20 @@ var DataModelValidator = class {
6301
6202
  if (!thisRelation.valid) {
6302
6203
  return;
6303
6204
  }
6304
- if (this.isFieldInheritedFromDelegateModel(field, contextModel)) {
6205
+ if (this.isFieldInheritedFromDelegateModel(field)) {
6305
6206
  return;
6306
6207
  }
6208
+ if (this.isSelfRelation(field)) {
6209
+ if (!thisRelation.name) {
6210
+ accept("error", "Self-relation field must have a name in @relation attribute", {
6211
+ node: field
6212
+ });
6213
+ return;
6214
+ }
6215
+ }
6307
6216
  const oppositeModel = field.type.reference.ref;
6308
- let oppositeFields = getModelFieldsWithBases(oppositeModel, false).filter((f) => f.type.reference?.ref?.name === contextModel.name);
6217
+ let oppositeFields = getAllFields(oppositeModel, false).filter((f) => f !== field && // exclude self in case of self relation
6218
+ f.type.reference?.ref?.name === contextModel.name);
6309
6219
  oppositeFields = oppositeFields.filter((f) => {
6310
6220
  const fieldRel = this.parseRelation(f);
6311
6221
  return fieldRel.valid && fieldRel.name === thisRelation.name;
@@ -6342,26 +6252,37 @@ var DataModelValidator = class {
6342
6252
  const oppositeField = oppositeFields[0];
6343
6253
  const oppositeRelation = this.parseRelation(oppositeField);
6344
6254
  let relationOwner;
6345
- if (thisRelation?.references?.length && thisRelation.fields?.length) {
6346
- if (oppositeRelation?.references || oppositeRelation?.fields) {
6347
- accept("error", '"fields" and "references" must be provided only on one side of relation field', {
6348
- node: oppositeField
6349
- });
6350
- return;
6351
- } else {
6352
- relationOwner = oppositeField;
6353
- }
6354
- } else if (oppositeRelation?.references?.length && oppositeRelation.fields?.length) {
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;
6255
+ if (field.type.array && oppositeField.type.array) {
6256
+ for (const r of [
6257
+ thisRelation,
6258
+ oppositeRelation
6259
+ ]) {
6260
+ if (r.fields?.length || r.references?.length) {
6261
+ accept("error", 'Implicit many-to-many relation cannot have "fields" or "references" in @relation attribute', {
6262
+ node: r === thisRelation ? field : oppositeField
6263
+ });
6264
+ }
6362
6265
  }
6363
6266
  } else {
6364
- if (!(field.type.array && oppositeField.type.array)) {
6267
+ if (thisRelation?.references?.length && thisRelation.fields?.length) {
6268
+ if (oppositeRelation?.references || oppositeRelation?.fields) {
6269
+ accept("error", '"fields" and "references" must be provided only on one side of relation field', {
6270
+ node: oppositeField
6271
+ });
6272
+ return;
6273
+ } else {
6274
+ relationOwner = oppositeField;
6275
+ }
6276
+ } else if (oppositeRelation?.references?.length && oppositeRelation.fields?.length) {
6277
+ if (thisRelation?.references || thisRelation?.fields) {
6278
+ accept("error", '"fields" and "references" must be provided only on one side of relation field', {
6279
+ node: field
6280
+ });
6281
+ return;
6282
+ } else {
6283
+ relationOwner = field;
6284
+ }
6285
+ } else {
6365
6286
  [
6366
6287
  field,
6367
6288
  oppositeField
@@ -6372,78 +6293,85 @@ var DataModelValidator = class {
6372
6293
  });
6373
6294
  }
6374
6295
  });
6296
+ return;
6375
6297
  }
6376
- return;
6377
- }
6378
- if (!relationOwner.type.array && !relationOwner.type.optional) {
6379
- accept("error", "Relation field needs to be list or optional", {
6380
- node: relationOwner
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));
6298
+ if (!relationOwner.type.array && !relationOwner.type.optional) {
6299
+ accept("error", "Relation field needs to be list or optional", {
6300
+ node: relationOwner
6301
+ });
6302
+ return;
6389
6303
  }
6390
- thisRelation.fields?.forEach((ref) => {
6391
- const refField = ref.target.ref;
6392
- if (refField) {
6393
- if (refField.attributes.find((a) => a.decl.ref?.name === "@id" || a.decl.ref?.name === "@unique")) {
6394
- return;
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
- });
6304
+ if (relationOwner !== field && !relationOwner.type.array) {
6305
+ const containingModel = field.$container;
6306
+ const uniqueFieldList = getUniqueFields(containingModel);
6307
+ if (containingModel !== contextModel) {
6308
+ uniqueFieldList.push(...getUniqueFields(contextModel));
6402
6309
  }
6403
- });
6310
+ thisRelation.fields?.forEach((ref) => {
6311
+ const refField = ref.target.ref;
6312
+ if (refField) {
6313
+ if (refField.attributes.find((a) => a.decl.ref?.name === "@id" || a.decl.ref?.name === "@unique")) {
6314
+ return;
6315
+ }
6316
+ if (uniqueFieldList.some((list) => list.includes(refField))) {
6317
+ return;
6318
+ }
6319
+ 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`, {
6320
+ node: refField
6321
+ });
6322
+ }
6323
+ });
6324
+ }
6404
6325
  }
6405
6326
  }
6406
6327
  // checks if the given field is inherited directly or indirectly from a delegate model
6407
- isFieldInheritedFromDelegateModel(field, contextModel) {
6408
- const basePath = findUpInheritance(contextModel, field.$container);
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
- });
6328
+ isFieldInheritedFromDelegateModel(field) {
6329
+ return isDelegateModel(field.$container);
6423
6330
  }
6424
- validateBaseDelegateModel(model, accept) {
6425
- if (model.superTypes.filter((base) => base.ref && isDelegateModel(base.ref)).length > 1) {
6426
- accept("error", "Extending from multiple delegate models is not supported", {
6331
+ validateInherits(model, accept) {
6332
+ if (!model.baseModel) {
6333
+ return;
6334
+ }
6335
+ (0, import_common_helpers2.invariant)(model.baseModel.ref, "baseModel must be resolved");
6336
+ if (!isDelegateModel(model.baseModel.ref)) {
6337
+ accept("error", `Model ${model.baseModel.$refText} cannot be extended because it's not a delegate model`, {
6427
6338
  node: model,
6428
- property: "superTypes"
6339
+ property: "baseModel"
6429
6340
  });
6341
+ return;
6430
6342
  }
6431
- }
6432
- validateInheritance(dm, accept) {
6433
- const seen = [
6434
- dm
6343
+ const seen = [];
6344
+ const todo = [
6345
+ model.baseModel.ref
6435
6346
  ];
6436
- const todo = dm.superTypes.map((superType) => superType.ref);
6437
6347
  while (todo.length > 0) {
6438
6348
  const current = todo.shift();
6439
6349
  if (seen.includes(current)) {
6440
- accept("error", `Circular inheritance detected: ${seen.map((m) => m.name).join(" -> ")} -> ${current.name}`, {
6350
+ accept("error", `Cyclic inheritance detected: ${seen.map((m) => m.name).join(" -> ")} -> ${current.name}`, {
6351
+ node: model
6352
+ });
6353
+ return;
6354
+ }
6355
+ seen.push(current);
6356
+ if (current.baseModel) {
6357
+ (0, import_common_helpers2.invariant)(current.baseModel.ref, "baseModel must be resolved");
6358
+ todo.push(current.baseModel.ref);
6359
+ }
6360
+ }
6361
+ }
6362
+ validateMixins(dm, accept) {
6363
+ const seen = [];
6364
+ const todo = dm.mixins.map((mixin) => mixin.ref);
6365
+ while (todo.length > 0) {
6366
+ const current = todo.shift();
6367
+ if (seen.includes(current)) {
6368
+ accept("error", `Cyclic mixin detected: ${seen.map((m) => m.name).join(" -> ")} -> ${current.name}`, {
6441
6369
  node: dm
6442
6370
  });
6443
6371
  return;
6444
6372
  }
6445
6373
  seen.push(current);
6446
- todo.push(...current.superTypes.map((superType) => superType.ref));
6374
+ todo.push(...current.mixins.map((mixin) => mixin.ref));
6447
6375
  }
6448
6376
  }
6449
6377
  };
@@ -6479,26 +6407,15 @@ var DataSourceValidator = class {
6479
6407
  }
6480
6408
  }
6481
6409
  validateUrl(ds, accept) {
6482
- const url = ds.fields.find((f) => f.name === "url");
6483
- if (!url) {
6484
- accept("error", 'datasource must include a "url" field', {
6485
- node: ds
6486
- });
6410
+ const urlField = ds.fields.find((f) => f.name === "url");
6411
+ if (!urlField) {
6412
+ return;
6487
6413
  }
6488
- for (const fieldName of [
6489
- "url",
6490
- "shadowDatabaseUrl"
6491
- ]) {
6492
- const field = ds.fields.find((f) => f.name === fieldName);
6493
- if (!field) {
6494
- continue;
6495
- }
6496
- const value = getStringLiteral(field.value);
6497
- if (!value && !(isInvocationExpr(field.value) && field.value.function.ref?.name === "env")) {
6498
- accept("error", `"${fieldName}" must be set to a string literal or an invocation of "env" function`, {
6499
- node: field.value
6500
- });
6501
- }
6414
+ const value = getStringLiteral(urlField.value);
6415
+ if (!value && !(isInvocationExpr(urlField.value) && urlField.value.function.ref?.name === "env")) {
6416
+ accept("error", `"${urlField.name}" must be set to a string literal or an invocation of "env" function`, {
6417
+ node: urlField.value
6418
+ });
6502
6419
  }
6503
6420
  }
6504
6421
  validateRelationMode(ds, accept) {
@@ -6650,7 +6567,7 @@ var ExpressionValidator = class {
6650
6567
  case "==":
6651
6568
  case "!=": {
6652
6569
  if (this.isInValidationContext(expr)) {
6653
- if (isDataModelFieldReference(expr.left) && isNullExpr(expr.right) || isDataModelFieldReference(expr.right) && isNullExpr(expr.left)) {
6570
+ if (isDataFieldReference(expr.left) && isNullExpr(expr.right) || isDataFieldReference(expr.right) && isNullExpr(expr.left)) {
6654
6571
  return;
6655
6572
  }
6656
6573
  }
@@ -6679,11 +6596,11 @@ var ExpressionValidator = class {
6679
6596
  node: expr
6680
6597
  });
6681
6598
  }
6682
- if (isDataModelFieldReference(expr.left) && (isThisExpr(expr.right) || isDataModelFieldReference(expr.right))) {
6599
+ if (isDataFieldReference(expr.left) && (isThisExpr(expr.right) || isDataFieldReference(expr.right))) {
6683
6600
  accept("error", "comparison between model-typed fields are not supported", {
6684
6601
  node: expr
6685
6602
  });
6686
- } else if (isDataModelFieldReference(expr.right) && (isThisExpr(expr.left) || isDataModelFieldReference(expr.left))) {
6603
+ } else if (isDataFieldReference(expr.right) && (isThisExpr(expr.left) || isDataFieldReference(expr.left))) {
6687
6604
  accept("error", "comparison between model-typed fields are not supported", {
6688
6605
  node: expr
6689
6606
  });
@@ -6778,7 +6695,7 @@ var FunctionInvocationValidator = class {
6778
6695
  let curr = expr.$container;
6779
6696
  let containerAttribute;
6780
6697
  while (curr) {
6781
- if (isDataModelAttribute(curr) || isDataModelFieldAttribute(curr)) {
6698
+ if (isDataModelAttribute(curr) || isDataFieldAttribute(curr)) {
6782
6699
  containerAttribute = curr;
6783
6700
  break;
6784
6701
  }
@@ -6879,7 +6796,7 @@ var FunctionInvocationValidator = class {
6879
6796
  _checkCheck(expr, accept) {
6880
6797
  let valid = true;
6881
6798
  const fieldArg = expr.args[0].value;
6882
- if (!isDataModelFieldReference(fieldArg) || !isDataModel(fieldArg.$resolvedType?.decl)) {
6799
+ if (!isDataFieldReference(fieldArg) || !isDataModel(fieldArg.$resolvedType?.decl)) {
6883
6800
  accept("error", "argument must be a relation field", {
6884
6801
  node: expr.args[0]
6885
6802
  });
@@ -6994,8 +6911,8 @@ var SchemaValidator = class {
6994
6911
  validateImports(model, accept) {
6995
6912
  model.imports.forEach((imp) => {
6996
6913
  const importedModel = resolveImport(this.documents, imp);
6997
- const importPath = imp.path.endsWith(".zmodel") ? imp.path : `${imp.path}.zmodel`;
6998
6914
  if (!importedModel) {
6915
+ const importPath = imp.path.endsWith(".zmodel") ? imp.path : `${imp.path}.zmodel`;
6999
6916
  accept("error", `Cannot find model file ${importPath}`, {
7000
6917
  node: imp
7001
6918
  });
@@ -7021,6 +6938,11 @@ var TypeDefValidator = class {
7021
6938
  typeDef.fields.forEach((field) => this.validateField(field, accept));
7022
6939
  }
7023
6940
  validateField(field, accept) {
6941
+ if (isDataModel(field.type.reference?.ref)) {
6942
+ accept("error", "Type field cannot be a relation", {
6943
+ node: field.type
6944
+ });
6945
+ }
7024
6946
  field.attributes.forEach((attr) => validateAttributeApplication(attr, accept));
7025
6947
  }
7026
6948
  };
@@ -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 DataModelField:
7185
- this.resolveDataModelField(node, document, extraScopes);
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" && isDataModelField(attrAppliedOn)) {
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) => getModelFieldsWithBases(transitiveDataModel).find((f) => f.name === name), "scopeProvider");
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
- resolveDataModelField(node, document, extraScopes) {
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 (isDataModelFieldType(type) || isTypeDefField(type)) {
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 (isDataModelField(ref) || isTypeDefField(ref)) {
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 (isDataModelField(ref) && !ref.type.array) {
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 (isDataModelField(ref) || isTypeDefField(ref)) {
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 (isDataModelField(ref) || isTypeDefField(ref)) {
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(getModelFieldsWithBases(node), globalScope);
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
 
@@ -7739,10 +7727,16 @@ async function loadDocument(fileName, pluginModelFiles = []) {
7739
7727
  const pluginDocs = await Promise.all(pluginModelFiles.map((file) => services.shared.workspace.LangiumDocuments.getOrCreateDocument(import_langium11.URI.file(import_node_path2.default.resolve(file)))));
7740
7728
  const langiumDocuments = services.shared.workspace.LangiumDocuments;
7741
7729
  const document = await langiumDocuments.getOrCreateDocument(import_langium11.URI.file(import_node_path2.default.resolve(fileName)));
7730
+ const importedURIs = await loadImports(document, langiumDocuments);
7731
+ const importedDocuments = [];
7732
+ for (const uri of importedURIs) {
7733
+ importedDocuments.push(await langiumDocuments.getOrCreateDocument(uri));
7734
+ }
7742
7735
  await services.shared.workspace.DocumentBuilder.build([
7743
7736
  stdLib,
7744
7737
  ...pluginDocs,
7745
- document
7738
+ document,
7739
+ ...importedDocuments
7746
7740
  ], {
7747
7741
  validation: true
7748
7742
  });
@@ -7769,6 +7763,20 @@ async function loadDocument(fileName, pluginModelFiles = []) {
7769
7763
  warnings
7770
7764
  };
7771
7765
  }
7766
+ const model = document.parseResult.value;
7767
+ const imported = mergeImportsDeclarations(langiumDocuments, model);
7768
+ imported.forEach((model2) => {
7769
+ langiumDocuments.deleteDocument(model2.$document.uri);
7770
+ services.shared.workspace.IndexManager.remove(model2.$document.uri);
7771
+ });
7772
+ const additionalErrors = validationAfterImportMerge(model);
7773
+ if (additionalErrors.length > 0) {
7774
+ return {
7775
+ success: false,
7776
+ errors: additionalErrors,
7777
+ warnings
7778
+ };
7779
+ }
7772
7780
  return {
7773
7781
  success: true,
7774
7782
  model: document.parseResult.value,
@@ -7776,6 +7784,68 @@ async function loadDocument(fileName, pluginModelFiles = []) {
7776
7784
  };
7777
7785
  }
7778
7786
  __name(loadDocument, "loadDocument");
7787
+ async function loadImports(document, documents, uris = /* @__PURE__ */ new Set()) {
7788
+ const uriString = document.uri.toString();
7789
+ if (!uris.has(uriString)) {
7790
+ uris.add(uriString);
7791
+ const model = document.parseResult.value;
7792
+ for (const imp of model.imports) {
7793
+ const importedModel = resolveImport(documents, imp);
7794
+ if (importedModel) {
7795
+ const importedDoc = getDocument(importedModel);
7796
+ await loadImports(importedDoc, documents, uris);
7797
+ }
7798
+ }
7799
+ }
7800
+ return Array.from(uris).filter((x) => uriString != x).map((e) => import_langium11.URI.parse(e));
7801
+ }
7802
+ __name(loadImports, "loadImports");
7803
+ function mergeImportsDeclarations(documents, model) {
7804
+ const importedModels = resolveTransitiveImports(documents, model);
7805
+ const importedDeclarations = importedModels.flatMap((m) => m.declarations);
7806
+ model.declarations.push(...importedDeclarations);
7807
+ model.imports = [];
7808
+ linkContentToContainer(model);
7809
+ return importedModels;
7810
+ }
7811
+ __name(mergeImportsDeclarations, "mergeImportsDeclarations");
7812
+ function linkContentToContainer(node) {
7813
+ for (const [name, value] of Object.entries(node)) {
7814
+ if (!name.startsWith("$")) {
7815
+ if (Array.isArray(value)) {
7816
+ value.forEach((item, index) => {
7817
+ if ((0, import_langium11.isAstNode)(item)) {
7818
+ item.$container = node;
7819
+ item.$containerProperty = name;
7820
+ item.$containerIndex = index;
7821
+ }
7822
+ });
7823
+ } else if ((0, import_langium11.isAstNode)(value)) {
7824
+ value.$container = node;
7825
+ value.$containerProperty = name;
7826
+ }
7827
+ }
7828
+ }
7829
+ }
7830
+ __name(linkContentToContainer, "linkContentToContainer");
7831
+ function validationAfterImportMerge(model) {
7832
+ const errors = [];
7833
+ const dataSources = model.declarations.filter((d) => isDataSource(d));
7834
+ if (dataSources.length === 0) {
7835
+ errors.push("Validation error: schema must have a datasource declaration");
7836
+ } else {
7837
+ if (dataSources.length > 1) {
7838
+ errors.push("Validation error: multiple datasource declarations are not allowed");
7839
+ }
7840
+ }
7841
+ const decls = getDataModelAndTypeDefs(model, true);
7842
+ const authDecls = decls.filter((d) => hasAttribute(d, "@@auth"));
7843
+ if (authDecls.length > 1) {
7844
+ errors.push("Validation error: Multiple `@@auth` declarations are not allowed");
7845
+ }
7846
+ return errors;
7847
+ }
7848
+ __name(validationAfterImportMerge, "validationAfterImportMerge");
7779
7849
  // Annotate the CommonJS export names for ESM import in node:
7780
7850
  0 && (module.exports = {
7781
7851
  DocumentLoadError,