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

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
@@ -31,7 +31,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  // src/index.ts
32
32
  var src_exports = {};
33
33
  __export(src_exports, {
34
- DocumentLoadError: () => DocumentLoadError,
35
34
  ZModelLanguageMetaData: () => ZModelLanguageMetaData,
36
35
  ZModelLanguageModule: () => ZModelLanguageModule,
37
36
  ZModelSharedModule: () => ZModelSharedModule,
@@ -40,44 +39,12 @@ __export(src_exports, {
40
39
  loadDocument: () => loadDocument
41
40
  });
42
41
  module.exports = __toCommonJS(src_exports);
43
- var import_langium11 = require("langium");
44
- var import_node = require("langium/node");
45
- var import_node_fs3 = __toESM(require("fs"), 1);
46
- var import_node_path2 = __toESM(require("path"), 1);
47
- var import_node_url2 = require("url");
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
42
 
78
- // src/module.ts
79
- var import_langium10 = require("langium");
80
- var import_lsp = require("langium/lsp");
43
+ // src/document.ts
44
+ var import_langium12 = require("langium");
45
+ var import_node_fs3 = __toESM(require("fs"), 1);
46
+ var import_node_path4 = __toESM(require("path"), 1);
47
+ var import_node_url4 = require("url");
81
48
 
82
49
  // src/generated/ast.ts
83
50
  var langium = __toESM(require("langium"), 1);
@@ -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,42 @@ 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_langium11 = require("langium");
1078
+ var import_lsp = require("langium/lsp");
1079
+ var import_node = require("langium/node");
1080
+ var import_node_path3 = __toESM(require("path"), 1);
1081
+ var import_node_url3 = require("url");
1082
+
1127
1083
  // src/generated/grammar.ts
1128
1084
  var import_langium = require("langium");
1129
1085
  var loadedZModelGrammar;
@@ -1246,7 +1202,7 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
1246
1202
  {
1247
1203
  "$type": "RuleCall",
1248
1204
  "rule": {
1249
- "$ref": "#/rules@40"
1205
+ "$ref": "#/rules@42"
1250
1206
  },
1251
1207
  "arguments": []
1252
1208
  },
@@ -3040,16 +2996,6 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
3040
2996
  {
3041
2997
  "$type": "Group",
3042
2998
  "elements": [
3043
- {
3044
- "$type": "Assignment",
3045
- "feature": "isAbstract",
3046
- "operator": "?=",
3047
- "terminal": {
3048
- "$type": "Keyword",
3049
- "value": "abstract"
3050
- },
3051
- "cardinality": "?"
3052
- },
3053
2999
  {
3054
3000
  "$type": "Keyword",
3055
3001
  "value": "model"
@@ -3067,45 +3013,59 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
3067
3013
  }
3068
3014
  },
3069
3015
  {
3070
- "$type": "Group",
3016
+ "$type": "Alternatives",
3071
3017
  "elements": [
3072
3018
  {
3073
- "$type": "Keyword",
3074
- "value": "extends"
3019
+ "$type": "RuleCall",
3020
+ "rule": {
3021
+ "$ref": "#/rules@38"
3022
+ },
3023
+ "arguments": []
3024
+ },
3025
+ {
3026
+ "$type": "RuleCall",
3027
+ "rule": {
3028
+ "$ref": "#/rules@39"
3029
+ },
3030
+ "arguments": []
3075
3031
  },
3076
3032
  {
3077
- "$type": "Assignment",
3078
- "feature": "superTypes",
3079
- "operator": "+=",
3080
- "terminal": {
3081
- "$type": "CrossReference",
3082
- "type": {
3083
- "$ref": "#/rules@37"
3033
+ "$type": "Group",
3034
+ "elements": [
3035
+ {
3036
+ "$type": "RuleCall",
3037
+ "rule": {
3038
+ "$ref": "#/rules@39"
3039
+ },
3040
+ "arguments": []
3084
3041
  },
3085
- "deprecatedSyntax": false
3086
- }
3042
+ {
3043
+ "$type": "RuleCall",
3044
+ "rule": {
3045
+ "$ref": "#/rules@38"
3046
+ },
3047
+ "arguments": []
3048
+ }
3049
+ ]
3087
3050
  },
3088
3051
  {
3089
3052
  "$type": "Group",
3090
3053
  "elements": [
3091
3054
  {
3092
- "$type": "Keyword",
3093
- "value": ","
3055
+ "$type": "RuleCall",
3056
+ "rule": {
3057
+ "$ref": "#/rules@38"
3058
+ },
3059
+ "arguments": []
3094
3060
  },
3095
3061
  {
3096
- "$type": "Assignment",
3097
- "feature": "superTypes",
3098
- "operator": "+=",
3099
- "terminal": {
3100
- "$type": "CrossReference",
3101
- "type": {
3102
- "$ref": "#/rules@37"
3103
- },
3104
- "deprecatedSyntax": false
3105
- }
3062
+ "$type": "RuleCall",
3063
+ "rule": {
3064
+ "$ref": "#/rules@39"
3065
+ },
3066
+ "arguments": []
3106
3067
  }
3107
- ],
3108
- "cardinality": "*"
3068
+ ]
3109
3069
  }
3110
3070
  ],
3111
3071
  "cardinality": "?"
@@ -3154,7 +3114,7 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
3154
3114
  "terminal": {
3155
3115
  "$type": "RuleCall",
3156
3116
  "rule": {
3157
- "$ref": "#/rules@38"
3117
+ "$ref": "#/rules@40"
3158
3118
  },
3159
3119
  "arguments": []
3160
3120
  }
@@ -3189,50 +3149,135 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
3189
3149
  },
3190
3150
  {
3191
3151
  "$type": "ParserRule",
3192
- "name": "DataModelField",
3152
+ "fragment": true,
3153
+ "name": "WithClause",
3193
3154
  "definition": {
3194
3155
  "$type": "Group",
3195
3156
  "elements": [
3196
3157
  {
3197
- "$type": "Assignment",
3198
- "feature": "comments",
3199
- "operator": "+=",
3200
- "terminal": {
3201
- "$type": "RuleCall",
3202
- "rule": {
3203
- "$ref": "#/rules@71"
3204
- },
3205
- "arguments": []
3206
- },
3207
- "cardinality": "*"
3158
+ "$type": "Keyword",
3159
+ "value": "with"
3208
3160
  },
3209
3161
  {
3210
3162
  "$type": "Assignment",
3211
- "feature": "name",
3212
- "operator": "=",
3163
+ "feature": "mixins",
3164
+ "operator": "+=",
3213
3165
  "terminal": {
3214
- "$type": "RuleCall",
3215
- "rule": {
3216
- "$ref": "#/rules@52"
3166
+ "$type": "CrossReference",
3167
+ "type": {
3168
+ "$ref": "#/rules@42"
3217
3169
  },
3218
- "arguments": []
3170
+ "deprecatedSyntax": false
3219
3171
  }
3220
3172
  },
3221
3173
  {
3222
- "$type": "Assignment",
3223
- "feature": "type",
3224
- "operator": "=",
3225
- "terminal": {
3226
- "$type": "RuleCall",
3227
- "rule": {
3228
- "$ref": "#/rules@39"
3174
+ "$type": "Group",
3175
+ "elements": [
3176
+ {
3177
+ "$type": "Keyword",
3178
+ "value": ",",
3179
+ "cardinality": "?"
3229
3180
  },
3230
- "arguments": []
3231
- }
3232
- },
3233
- {
3234
- "$type": "Assignment",
3235
- "feature": "attributes",
3181
+ {
3182
+ "$type": "Assignment",
3183
+ "feature": "mixins",
3184
+ "operator": "+=",
3185
+ "terminal": {
3186
+ "$type": "CrossReference",
3187
+ "type": {
3188
+ "$ref": "#/rules@42"
3189
+ },
3190
+ "deprecatedSyntax": false
3191
+ }
3192
+ }
3193
+ ],
3194
+ "cardinality": "*"
3195
+ }
3196
+ ]
3197
+ },
3198
+ "definesHiddenTokens": false,
3199
+ "entry": false,
3200
+ "hiddenTokens": [],
3201
+ "parameters": [],
3202
+ "wildcard": false
3203
+ },
3204
+ {
3205
+ "$type": "ParserRule",
3206
+ "fragment": true,
3207
+ "name": "ExtendsClause",
3208
+ "definition": {
3209
+ "$type": "Group",
3210
+ "elements": [
3211
+ {
3212
+ "$type": "Keyword",
3213
+ "value": "extends"
3214
+ },
3215
+ {
3216
+ "$type": "Assignment",
3217
+ "feature": "baseModel",
3218
+ "operator": "=",
3219
+ "terminal": {
3220
+ "$type": "CrossReference",
3221
+ "type": {
3222
+ "$ref": "#/rules@37"
3223
+ },
3224
+ "deprecatedSyntax": false
3225
+ }
3226
+ }
3227
+ ]
3228
+ },
3229
+ "definesHiddenTokens": false,
3230
+ "entry": false,
3231
+ "hiddenTokens": [],
3232
+ "parameters": [],
3233
+ "wildcard": false
3234
+ },
3235
+ {
3236
+ "$type": "ParserRule",
3237
+ "name": "DataField",
3238
+ "definition": {
3239
+ "$type": "Group",
3240
+ "elements": [
3241
+ {
3242
+ "$type": "Assignment",
3243
+ "feature": "comments",
3244
+ "operator": "+=",
3245
+ "terminal": {
3246
+ "$type": "RuleCall",
3247
+ "rule": {
3248
+ "$ref": "#/rules@71"
3249
+ },
3250
+ "arguments": []
3251
+ },
3252
+ "cardinality": "*"
3253
+ },
3254
+ {
3255
+ "$type": "Assignment",
3256
+ "feature": "name",
3257
+ "operator": "=",
3258
+ "terminal": {
3259
+ "$type": "RuleCall",
3260
+ "rule": {
3261
+ "$ref": "#/rules@52"
3262
+ },
3263
+ "arguments": []
3264
+ }
3265
+ },
3266
+ {
3267
+ "$type": "Assignment",
3268
+ "feature": "type",
3269
+ "operator": "=",
3270
+ "terminal": {
3271
+ "$type": "RuleCall",
3272
+ "rule": {
3273
+ "$ref": "#/rules@41"
3274
+ },
3275
+ "arguments": []
3276
+ }
3277
+ },
3278
+ {
3279
+ "$type": "Assignment",
3280
+ "feature": "attributes",
3236
3281
  "operator": "+=",
3237
3282
  "terminal": {
3238
3283
  "$type": "RuleCall",
@@ -3254,7 +3299,7 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
3254
3299
  },
3255
3300
  {
3256
3301
  "$type": "ParserRule",
3257
- "name": "DataModelFieldType",
3302
+ "name": "DataFieldType",
3258
3303
  "definition": {
3259
3304
  "$type": "Group",
3260
3305
  "elements": [
@@ -3292,7 +3337,7 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
3292
3337
  "terminal": {
3293
3338
  "$type": "CrossReference",
3294
3339
  "type": {
3295
- "$ref": "#/types@3"
3340
+ "$ref": "#/types@2"
3296
3341
  },
3297
3342
  "terminal": {
3298
3343
  "$type": "RuleCall",
@@ -3379,6 +3424,14 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
3379
3424
  "arguments": []
3380
3425
  }
3381
3426
  },
3427
+ {
3428
+ "$type": "RuleCall",
3429
+ "rule": {
3430
+ "$ref": "#/rules@38"
3431
+ },
3432
+ "arguments": [],
3433
+ "cardinality": "?"
3434
+ },
3382
3435
  {
3383
3436
  "$type": "Keyword",
3384
3437
  "value": "{"
@@ -3393,7 +3446,7 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
3393
3446
  "terminal": {
3394
3447
  "$type": "RuleCall",
3395
3448
  "rule": {
3396
- "$ref": "#/rules@41"
3449
+ "$ref": "#/rules@40"
3397
3450
  },
3398
3451
  "arguments": []
3399
3452
  }
@@ -3426,151 +3479,6 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
3426
3479
  "parameters": [],
3427
3480
  "wildcard": false
3428
3481
  },
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": [
3539
- {
3540
- "$type": "Assignment",
3541
- "feature": "array",
3542
- "operator": "?=",
3543
- "terminal": {
3544
- "$type": "Keyword",
3545
- "value": "["
3546
- }
3547
- },
3548
- {
3549
- "$type": "Keyword",
3550
- "value": "]"
3551
- }
3552
- ],
3553
- "cardinality": "?"
3554
- },
3555
- {
3556
- "$type": "Assignment",
3557
- "feature": "optional",
3558
- "operator": "?=",
3559
- "terminal": {
3560
- "$type": "Keyword",
3561
- "value": "?"
3562
- },
3563
- "cardinality": "?"
3564
- }
3565
- ]
3566
- },
3567
- "definesHiddenTokens": false,
3568
- "entry": false,
3569
- "fragment": false,
3570
- "hiddenTokens": [],
3571
- "parameters": [],
3572
- "wildcard": false
3573
- },
3574
3482
  {
3575
3483
  "$type": "ParserRule",
3576
3484
  "name": "UnsupportedFieldType",
@@ -3971,7 +3879,7 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
3971
3879
  "terminal": {
3972
3880
  "$type": "CrossReference",
3973
3881
  "type": {
3974
- "$ref": "#/types@3"
3882
+ "$ref": "#/types@2"
3975
3883
  },
3976
3884
  "terminal": {
3977
3885
  "$type": "RuleCall",
@@ -4585,7 +4493,7 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
4585
4493
  "terminal": {
4586
4494
  "$type": "CrossReference",
4587
4495
  "type": {
4588
- "$ref": "#/types@3"
4496
+ "$ref": "#/types@2"
4589
4497
  },
4590
4498
  "terminal": {
4591
4499
  "$type": "RuleCall",
@@ -4639,7 +4547,7 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
4639
4547
  },
4640
4548
  {
4641
4549
  "$type": "ParserRule",
4642
- "name": "DataModelFieldAttribute",
4550
+ "name": "DataFieldAttribute",
4643
4551
  "definition": {
4644
4552
  "$type": "Group",
4645
4553
  "elements": [
@@ -5156,13 +5064,7 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
5156
5064
  {
5157
5065
  "$type": "SimpleType",
5158
5066
  "typeRef": {
5159
- "$ref": "#/rules@38"
5160
- }
5161
- },
5162
- {
5163
- "$type": "SimpleType",
5164
- "typeRef": {
5165
- "$ref": "#/rules@41"
5067
+ "$ref": "#/rules@40"
5166
5068
  }
5167
5069
  },
5168
5070
  {
@@ -5178,42 +5080,10 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
5178
5080
  "$type": "Type",
5179
5081
  "name": "MemberAccessTarget",
5180
5082
  "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
- ]
5083
+ "$type": "SimpleType",
5084
+ "typeRef": {
5085
+ "$ref": "#/rules@40"
5086
+ }
5217
5087
  }
5218
5088
  },
5219
5089
  {
@@ -5231,7 +5101,7 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
5231
5101
  {
5232
5102
  "$type": "SimpleType",
5233
5103
  "typeRef": {
5234
- "$ref": "#/rules@40"
5104
+ "$ref": "#/rules@42"
5235
5105
  }
5236
5106
  },
5237
5107
  {
@@ -5253,7 +5123,7 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
5253
5123
 
5254
5124
  // src/generated/module.ts
5255
5125
  var ZModelLanguageMetaData = {
5256
- languageId: "zmodel",
5126
+ languageId: "zmodel-v3",
5257
5127
  fileExtensions: [
5258
5128
  ".zmodel"
5259
5129
  ],
@@ -5269,14 +5139,13 @@ var ZModelGeneratedModule = {
5269
5139
  parser: {}
5270
5140
  };
5271
5141
 
5272
- // src/validators/attribute-application-validator.ts
5273
- var import_langium3 = require("langium");
5274
- var import_pluralize = __toESM(require("pluralize"), 1);
5275
-
5276
5142
  // src/utils.ts
5277
5143
  var import_langium2 = require("langium");
5278
- var import_path = __toESM(require("path"), 1);
5279
5144
  var import_node_fs = __toESM(require("fs"), 1);
5145
+ var import_node_module = require("module");
5146
+ var import_node_path = __toESM(require("path"), 1);
5147
+ var import_node_url = require("url");
5148
+ var import_meta = {};
5280
5149
  function hasAttribute(decl, name) {
5281
5150
  return !!getAttribute(decl, name);
5282
5151
  }
@@ -5348,18 +5217,14 @@ function isEnumFieldReference(node) {
5348
5217
  return isReferenceExpr(node) && isEnumField(node.target.ref);
5349
5218
  }
5350
5219
  __name(isEnumFieldReference, "isEnumFieldReference");
5351
- function isDataModelFieldReference(node) {
5352
- return isReferenceExpr(node) && isDataModelField(node.target.ref);
5220
+ function isDataFieldReference(node) {
5221
+ return isReferenceExpr(node) && isDataField(node.target.ref);
5353
5222
  }
5354
- __name(isDataModelFieldReference, "isDataModelFieldReference");
5223
+ __name(isDataFieldReference, "isDataFieldReference");
5355
5224
  function isRelationshipField(field) {
5356
5225
  return isDataModel(field.type.reference?.ref);
5357
5226
  }
5358
5227
  __name(isRelationshipField, "isRelationshipField");
5359
- function isFutureExpr(node) {
5360
- return isInvocationExpr(node) && node.function.ref?.name === "future" && isFromStdlib(node.function.ref);
5361
- }
5362
- __name(isFutureExpr, "isFutureExpr");
5363
5228
  function isDelegateModel(node) {
5364
5229
  return isDataModel(node) && hasAttribute(node, "@@delegate");
5365
5230
  }
@@ -5371,43 +5236,20 @@ function resolved(ref) {
5371
5236
  return ref.ref;
5372
5237
  }
5373
5238
  __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()) {
5239
+ function getRecursiveBases(decl, includeDelegate = true, seen = /* @__PURE__ */ new Set()) {
5404
5240
  const result = [];
5405
- if (seen.has(dataModel)) {
5241
+ if (seen.has(decl)) {
5406
5242
  return result;
5407
5243
  }
5408
- seen.add(dataModel);
5409
- dataModel.superTypes.forEach((superType) => {
5410
- const baseDecl = superType.ref;
5244
+ seen.add(decl);
5245
+ const bases = [
5246
+ ...decl.mixins,
5247
+ ...isDataModel(decl) && decl.baseModel ? [
5248
+ decl.baseModel
5249
+ ] : []
5250
+ ];
5251
+ bases.forEach((base) => {
5252
+ const baseDecl = decl.$container.declarations.find((d) => isTypeDef(d) || isDataModel(d) && d.name === base.$refText);
5411
5253
  if (baseDecl) {
5412
5254
  if (!includeDelegate && isDelegateModel(baseDecl)) {
5413
5255
  return;
@@ -5420,14 +5262,13 @@ function getRecursiveBases(dataModel, includeDelegate = true, seen = /* @__PURE_
5420
5262
  }
5421
5263
  __name(getRecursiveBases, "getRecursiveBases");
5422
5264
  function getModelIdFields(model) {
5423
- const modelsToCheck = model.$baseMerged ? [
5424
- model
5425
- ] : [
5265
+ const modelsToCheck = [
5426
5266
  model,
5427
5267
  ...getRecursiveBases(model)
5428
5268
  ];
5429
5269
  for (const modelToCheck of modelsToCheck) {
5430
- const idAttr = modelToCheck.attributes.find((attr) => attr.decl.$refText === "@@id");
5270
+ const allAttributes = getAllAttributes(modelToCheck);
5271
+ const idAttr = allAttributes.find((attr) => attr.decl.$refText === "@@id");
5431
5272
  if (!idAttr) {
5432
5273
  continue;
5433
5274
  }
@@ -5441,14 +5282,13 @@ function getModelIdFields(model) {
5441
5282
  }
5442
5283
  __name(getModelIdFields, "getModelIdFields");
5443
5284
  function getModelUniqueFields(model) {
5444
- const modelsToCheck = model.$baseMerged ? [
5445
- model
5446
- ] : [
5285
+ const modelsToCheck = [
5447
5286
  model,
5448
5287
  ...getRecursiveBases(model)
5449
5288
  ];
5450
5289
  for (const modelToCheck of modelsToCheck) {
5451
- const uniqueAttr = modelToCheck.attributes.find((attr) => attr.decl.$refText === "@@unique");
5290
+ const allAttributes = getAllAttributes(modelToCheck);
5291
+ const uniqueAttr = allAttributes.find((attr) => attr.decl.$refText === "@@unique");
5452
5292
  if (!uniqueAttr) {
5453
5293
  continue;
5454
5294
  }
@@ -5549,7 +5389,7 @@ function getFunctionExpressionContext(funcDecl) {
5549
5389
  }
5550
5390
  __name(getFunctionExpressionContext, "getFunctionExpressionContext");
5551
5391
  function isCheckInvocation(node) {
5552
- return isInvocationExpr(node) && node.function.ref?.name === "check" && isFromStdlib(node.function.ref);
5392
+ return isInvocationExpr(node) && node.function.ref?.name === "check";
5553
5393
  }
5554
5394
  __name(isCheckInvocation, "isCheckInvocation");
5555
5395
  function resolveTransitiveImports(documents, model) {
@@ -5595,34 +5435,24 @@ function resolveImport(documents, imp) {
5595
5435
  }
5596
5436
  __name(resolveImport, "resolveImport");
5597
5437
  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;
5438
+ if (!imp.path) {
5439
+ return void 0;
5606
5440
  }
5607
5441
  const doc = import_langium2.AstUtils.getDocument(imp);
5608
- const dir = import_path.default.dirname(doc.uri.fsPath);
5609
- return import_langium2.URI.file(import_path.default.resolve(dir, imp.path));
5442
+ const dir = import_node_path.default.dirname(doc.uri.fsPath);
5443
+ const importPath = imp.path.endsWith(".zmodel") ? imp.path : `${imp.path}.zmodel`;
5444
+ return import_langium2.URI.file(import_node_path.default.resolve(dir, importPath));
5610
5445
  }
5611
5446
  __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;
5447
+ function getDataModelAndTypeDefs(model, includeIgnored = false) {
5448
+ const r = model.declarations.filter((d) => isDataModel(d) || isTypeDef(d));
5449
+ if (includeIgnored) {
5450
+ return r;
5451
+ } else {
5452
+ return r.filter((model2) => !hasAttribute(model2, "@@ignore"));
5623
5453
  }
5624
5454
  }
5625
- __name(findNodeModulesFile, "findNodeModulesFile");
5455
+ __name(getDataModelAndTypeDefs, "getDataModelAndTypeDefs");
5626
5456
  function getAllDeclarationsIncludingImports(documents, model) {
5627
5457
  const imports = resolveTransitiveImports(documents, model);
5628
5458
  return model.declarations.concat(...imports.map((imp) => imp.declarations));
@@ -5636,10 +5466,10 @@ function getAuthDecl(decls) {
5636
5466
  return authModel;
5637
5467
  }
5638
5468
  __name(getAuthDecl, "getAuthDecl");
5639
- function isFutureInvocation(node) {
5640
- return isInvocationExpr(node) && node.function.ref?.name === "future" && isFromStdlib(node.function.ref);
5469
+ function isBeforeInvocation(node) {
5470
+ return isInvocationExpr(node) && node.function.ref?.name === "before";
5641
5471
  }
5642
- __name(isFutureInvocation, "isFutureInvocation");
5472
+ __name(isBeforeInvocation, "isBeforeInvocation");
5643
5473
  function isCollectionPredicate(node) {
5644
5474
  return isBinaryExpr(node) && [
5645
5475
  "?",
@@ -5687,8 +5517,131 @@ function isMemberContainer(node) {
5687
5517
  return isDataModel(node) || isTypeDef(node);
5688
5518
  }
5689
5519
  __name(isMemberContainer, "isMemberContainer");
5520
+ function getAllFields(decl, includeIgnored = false, seen = /* @__PURE__ */ new Set()) {
5521
+ if (seen.has(decl)) {
5522
+ return [];
5523
+ }
5524
+ seen.add(decl);
5525
+ const fields = [];
5526
+ for (const mixin of decl.mixins) {
5527
+ if (mixin.ref) {
5528
+ fields.push(...getAllFields(mixin.ref, includeIgnored, seen));
5529
+ }
5530
+ }
5531
+ if (isDataModel(decl) && decl.baseModel) {
5532
+ if (decl.baseModel.ref) {
5533
+ fields.push(...getAllFields(decl.baseModel.ref, includeIgnored, seen));
5534
+ }
5535
+ }
5536
+ fields.push(...decl.fields.filter((f) => includeIgnored || !hasAttribute(f, "@ignore")));
5537
+ return fields;
5538
+ }
5539
+ __name(getAllFields, "getAllFields");
5540
+ function getAllAttributes(decl, seen = /* @__PURE__ */ new Set()) {
5541
+ if (seen.has(decl)) {
5542
+ return [];
5543
+ }
5544
+ seen.add(decl);
5545
+ const attributes = [];
5546
+ for (const mixin of decl.mixins) {
5547
+ if (mixin.ref) {
5548
+ attributes.push(...getAllAttributes(mixin.ref, seen));
5549
+ }
5550
+ }
5551
+ if (isDataModel(decl) && decl.baseModel) {
5552
+ if (decl.baseModel.ref) {
5553
+ attributes.push(...getAllAttributes(decl.baseModel.ref, seen));
5554
+ }
5555
+ }
5556
+ attributes.push(...decl.attributes);
5557
+ return attributes;
5558
+ }
5559
+ __name(getAllAttributes, "getAllAttributes");
5560
+ function getDocument(node) {
5561
+ const rootNode = findRootNode(node);
5562
+ const result = rootNode.$document;
5563
+ if (!result) {
5564
+ throw new Error("AST node has no document.");
5565
+ }
5566
+ return result;
5567
+ }
5568
+ __name(getDocument, "getDocument");
5569
+ function getPluginDocuments(model, schemaPath) {
5570
+ const result = [];
5571
+ for (const decl of model.declarations.filter(isPlugin)) {
5572
+ const providerField = decl.fields.find((f) => f.name === "provider");
5573
+ if (!providerField) {
5574
+ continue;
5575
+ }
5576
+ const provider = getLiteral(providerField.value);
5577
+ if (!provider) {
5578
+ continue;
5579
+ }
5580
+ let pluginModelFile;
5581
+ let providerPath = import_node_path.default.resolve(import_node_path.default.dirname(schemaPath), provider);
5582
+ if (import_node_fs.default.existsSync(providerPath)) {
5583
+ if (import_node_fs.default.statSync(providerPath).isDirectory()) {
5584
+ providerPath = import_node_path.default.join(providerPath, "index.js");
5585
+ }
5586
+ pluginModelFile = import_node_path.default.resolve(import_node_path.default.dirname(providerPath), PLUGIN_MODULE_NAME);
5587
+ if (!import_node_fs.default.existsSync(pluginModelFile)) {
5588
+ pluginModelFile = findUp([
5589
+ PLUGIN_MODULE_NAME
5590
+ ], import_node_path.default.dirname(providerPath));
5591
+ }
5592
+ }
5593
+ if (!pluginModelFile) {
5594
+ if (typeof import_meta.resolve === "function") {
5595
+ try {
5596
+ const resolvedUrl = import_meta.resolve(`${provider}/${PLUGIN_MODULE_NAME}`);
5597
+ pluginModelFile = (0, import_node_url.fileURLToPath)(resolvedUrl);
5598
+ } catch {
5599
+ }
5600
+ }
5601
+ }
5602
+ if (!pluginModelFile) {
5603
+ try {
5604
+ const require2 = (0, import_node_module.createRequire)((0, import_node_url.pathToFileURL)(schemaPath));
5605
+ pluginModelFile = require2.resolve(`${provider}/${PLUGIN_MODULE_NAME}`);
5606
+ } catch {
5607
+ }
5608
+ }
5609
+ if (pluginModelFile && import_node_fs.default.existsSync(pluginModelFile)) {
5610
+ result.push(pluginModelFile);
5611
+ }
5612
+ }
5613
+ return result;
5614
+ }
5615
+ __name(getPluginDocuments, "getPluginDocuments");
5616
+ function findUp(names, cwd = process.cwd(), multiple = false, result = []) {
5617
+ if (!names.some((name) => !!name)) {
5618
+ return void 0;
5619
+ }
5620
+ const target = names.find((name) => import_node_fs.default.existsSync(import_node_path.default.join(cwd, name)));
5621
+ if (multiple === false && target) {
5622
+ return import_node_path.default.join(cwd, target);
5623
+ }
5624
+ if (target) {
5625
+ result.push(import_node_path.default.join(cwd, target));
5626
+ }
5627
+ const up = import_node_path.default.resolve(cwd, "..");
5628
+ if (up === cwd) {
5629
+ return multiple && result.length > 0 ? result : void 0;
5630
+ }
5631
+ return findUp(names, up, multiple, result);
5632
+ }
5633
+ __name(findUp, "findUp");
5634
+ function findRootNode(node) {
5635
+ while (node.$container) {
5636
+ node = node.$container;
5637
+ }
5638
+ return node;
5639
+ }
5640
+ __name(findRootNode, "findRootNode");
5690
5641
 
5691
5642
  // src/validators/attribute-application-validator.ts
5643
+ var import_langium3 = require("langium");
5644
+ var import_pluralize = __toESM(require("pluralize"), 1);
5692
5645
  function _ts_decorate(decorators, target, key, desc) {
5693
5646
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
5694
5647
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -5714,7 +5667,7 @@ var AttributeApplicationValidator = class {
5714
5667
  static {
5715
5668
  __name(this, "AttributeApplicationValidator");
5716
5669
  }
5717
- validate(attr, accept) {
5670
+ validate(attr, accept, contextDataModel) {
5718
5671
  const decl = attr.decl.ref;
5719
5672
  if (!decl) {
5720
5673
  return;
@@ -5726,21 +5679,13 @@ var AttributeApplicationValidator = class {
5726
5679
  });
5727
5680
  return;
5728
5681
  }
5729
- if (isDataModelField(targetDecl) && !isValidAttributeTarget(decl, targetDecl)) {
5682
+ if (isDataField(targetDecl) && !isValidAttributeTarget(decl, targetDecl)) {
5730
5683
  accept("error", `attribute "${decl.name}" cannot be used on this type of field`, {
5731
5684
  node: attr
5732
5685
  });
5733
5686
  }
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
- }
5687
+ this.checkDeprecation(attr, accept);
5688
+ this.checkDuplicatedAttributes(attr, accept, contextDataModel);
5744
5689
  const filledParams = /* @__PURE__ */ new Set();
5745
5690
  for (const arg of attr.args) {
5746
5691
  let paramDecl;
@@ -5788,6 +5733,29 @@ var AttributeApplicationValidator = class {
5788
5733
  checker.value.call(this, attr, accept);
5789
5734
  }
5790
5735
  }
5736
+ checkDeprecation(attr, accept) {
5737
+ const deprecateAttr = attr.decl.ref?.attributes.find((a) => a.decl.ref?.name === "@@@deprecated");
5738
+ if (deprecateAttr) {
5739
+ const message = getStringLiteral(deprecateAttr.args[0]?.value) ?? `Attribute "${attr.decl.ref?.name}" is deprecated`;
5740
+ accept("warning", message, {
5741
+ node: attr
5742
+ });
5743
+ }
5744
+ }
5745
+ checkDuplicatedAttributes(attr, accept, contextDataModel) {
5746
+ const attrDecl = attr.decl.ref;
5747
+ if (!attrDecl?.attributes.some((a) => a.decl.ref?.name === "@@@once")) {
5748
+ return;
5749
+ }
5750
+ const allAttributes = contextDataModel ? getAllAttributes(contextDataModel) : attr.$container.attributes;
5751
+ const duplicates = allAttributes.filter((a) => a.decl.ref === attrDecl && a !== attr);
5752
+ if (duplicates.length > 0) {
5753
+ accept("error", `Attribute "${attrDecl.name}" can only be applied once`, {
5754
+ node: attr
5755
+ });
5756
+ }
5757
+ }
5758
+ // TODO: design a way to let plugin register validation
5791
5759
  _checkModelLevelPolicy(attr, accept) {
5792
5760
  const kind = getStringLiteral(attr.args[0]?.value);
5793
5761
  if (!kind) {
@@ -5800,11 +5768,61 @@ var AttributeApplicationValidator = class {
5800
5768
  "create",
5801
5769
  "read",
5802
5770
  "update",
5771
+ "post-update",
5803
5772
  "delete",
5804
5773
  "all"
5805
5774
  ], attr, accept);
5806
- this.rejectEncryptedFields(attr, accept);
5775
+ if ((kind === "create" || kind === "all") && attr.args[1]?.value) {
5776
+ this.rejectNonOwnedRelationInExpression(attr.args[1].value, accept);
5777
+ }
5778
+ if (kind !== "post-update" && attr.args[1]?.value) {
5779
+ const beforeCall = import_langium3.AstUtils.streamAst(attr.args[1]?.value).find(isBeforeInvocation);
5780
+ if (beforeCall) {
5781
+ accept("error", `"before()" is only allowed in "post-update" policy rules`, {
5782
+ node: beforeCall
5783
+ });
5784
+ }
5785
+ }
5807
5786
  }
5787
+ rejectNonOwnedRelationInExpression(expr, accept) {
5788
+ const contextModel = import_langium3.AstUtils.getContainerOfType(expr, isDataModel);
5789
+ if (!contextModel) {
5790
+ return;
5791
+ }
5792
+ if (import_langium3.AstUtils.streamAst(expr).some((node) => {
5793
+ if (!isDataFieldReference(node)) {
5794
+ return false;
5795
+ }
5796
+ if (node.target.ref?.$container !== contextModel) {
5797
+ return false;
5798
+ }
5799
+ const field = node.target.ref;
5800
+ if (!isRelationshipField(field)) {
5801
+ return false;
5802
+ }
5803
+ if (isAuthOrAuthMemberAccess(node)) {
5804
+ return false;
5805
+ }
5806
+ const startNode = isCollectionPredicate(node.$container) && node.$container.left === node ? node.$container : node;
5807
+ const collectionPredicate = import_langium3.AstUtils.getContainerOfType(startNode.$container, isCollectionPredicate);
5808
+ if (collectionPredicate && isAuthOrAuthMemberAccess(collectionPredicate.left)) {
5809
+ return false;
5810
+ }
5811
+ const relationAttr = field.attributes.find((attr) => attr.decl.ref?.name === "@relation");
5812
+ if (!relationAttr) {
5813
+ return true;
5814
+ }
5815
+ if (!relationAttr.args.some((arg) => arg.name === "fields")) {
5816
+ return true;
5817
+ }
5818
+ return false;
5819
+ })) {
5820
+ accept("error", `non-owned relation fields are not allowed in "create" rules`, {
5821
+ node: expr
5822
+ });
5823
+ }
5824
+ }
5825
+ // TODO: design a way to let plugin register validation
5808
5826
  _checkFieldLevelPolicy(attr, accept) {
5809
5827
  const kind = getStringLiteral(attr.args[0]?.value);
5810
5828
  if (!kind) {
@@ -5819,8 +5837,8 @@ var AttributeApplicationValidator = class {
5819
5837
  "all"
5820
5838
  ], attr, accept);
5821
5839
  const expr = attr.args[1]?.value;
5822
- if (expr && import_langium3.AstUtils.streamAst(expr).some((node) => isFutureExpr(node))) {
5823
- accept("error", `"future()" is not allowed in field-level policy rules`, {
5840
+ if (expr && import_langium3.AstUtils.streamAst(expr).some((node) => isBeforeInvocation(node))) {
5841
+ accept("error", `"before()" is not allowed in field-level policy rules`, {
5824
5842
  node: expr
5825
5843
  });
5826
5844
  }
@@ -5832,11 +5850,10 @@ var AttributeApplicationValidator = class {
5832
5850
  });
5833
5851
  }
5834
5852
  }
5835
- this.rejectEncryptedFields(attr, accept);
5836
5853
  }
5837
5854
  _checkValidate(attr, accept) {
5838
5855
  const condition = attr.args[0]?.value;
5839
- if (condition && import_langium3.AstUtils.streamAst(condition).some((node) => isDataModelFieldReference(node) && isDataModel(node.$resolvedType?.decl))) {
5856
+ if (condition && import_langium3.AstUtils.streamAst(condition).some((node) => isDataFieldReference(node) && isDataModel(node.$resolvedType?.decl))) {
5840
5857
  accept("error", `\`@@validate\` condition cannot use relation fields`, {
5841
5858
  node: condition
5842
5859
  });
@@ -5845,9 +5862,18 @@ var AttributeApplicationValidator = class {
5845
5862
  _checkUnique(attr, accept) {
5846
5863
  const fields = attr.args[0]?.value;
5847
5864
  if (!fields) {
5865
+ accept("error", `expects an array of field references`, {
5866
+ node: attr.args[0]
5867
+ });
5848
5868
  return;
5849
5869
  }
5850
5870
  if (isArrayExpr(fields)) {
5871
+ if (fields.items.length === 0) {
5872
+ accept("error", `\`@@unique\` expects at least one field reference`, {
5873
+ node: fields
5874
+ });
5875
+ return;
5876
+ }
5851
5877
  fields.items.forEach((item) => {
5852
5878
  if (!isReferenceExpr(item)) {
5853
5879
  accept("error", `Expecting a field reference`, {
@@ -5855,7 +5881,7 @@ var AttributeApplicationValidator = class {
5855
5881
  });
5856
5882
  return;
5857
5883
  }
5858
- if (!isDataModelField(item.target.ref)) {
5884
+ if (!isDataField(item.target.ref)) {
5859
5885
  accept("error", `Expecting a field reference`, {
5860
5886
  node: item
5861
5887
  });
@@ -5873,15 +5899,6 @@ var AttributeApplicationValidator = class {
5873
5899
  });
5874
5900
  }
5875
5901
  }
5876
- rejectEncryptedFields(attr, accept) {
5877
- import_langium3.AstUtils.streamAllContents(attr).forEach((node) => {
5878
- if (isDataModelFieldReference(node) && hasAttribute(node.target.ref, "@encrypted")) {
5879
- accept("error", `Encrypted fields cannot be used in policy rules`, {
5880
- node
5881
- });
5882
- }
5883
- });
5884
- }
5885
5902
  validatePolicyKinds(kind, candidates, attr, accept) {
5886
5903
  const items = kind.split(",").map((x) => x.trim());
5887
5904
  items.forEach((item) => {
@@ -5925,6 +5942,7 @@ _ts_decorate([
5925
5942
  ], AttributeApplicationValidator.prototype, "_checkValidate", null);
5926
5943
  _ts_decorate([
5927
5944
  check("@@unique"),
5945
+ check("@@id"),
5928
5946
  _ts_metadata("design:type", Function),
5929
5947
  _ts_metadata("design:paramtypes", [
5930
5948
  typeof AttributeApplication === "undefined" ? Object : AttributeApplication,
@@ -5940,7 +5958,11 @@ function assignableToAttributeParam(arg, param, attr) {
5940
5958
  let dstType = param.type.type;
5941
5959
  let dstIsArray = param.type.array;
5942
5960
  if (dstType === "ContextType") {
5943
- if (isDataModelField(attr.$container)) {
5961
+ if (isDataField(attr.$container)) {
5962
+ const dstIsTypedJson = hasAttribute(attr.$container, "@json");
5963
+ if (dstIsTypedJson && attr.decl.ref?.name === "@default") {
5964
+ return argResolvedType.decl === "String";
5965
+ }
5944
5966
  dstIsArray = attr.$container.type.array;
5945
5967
  }
5946
5968
  }
@@ -5957,14 +5979,14 @@ function assignableToAttributeParam(arg, param, attr) {
5957
5979
  }
5958
5980
  if (dstType === "FieldReference" || dstType === "TransitiveFieldReference") {
5959
5981
  if (dstIsArray) {
5960
- return isArrayExpr(arg.value) && !arg.value.items.find((item) => !isReferenceExpr(item) || !isDataModelField(item.target.ref));
5982
+ return isArrayExpr(arg.value) && !arg.value.items.find((item) => !isReferenceExpr(item) || !isDataField(item.target.ref));
5961
5983
  } else {
5962
- return isReferenceExpr(arg.value) && isDataModelField(arg.value.target.ref);
5984
+ return isReferenceExpr(arg.value) && isDataField(arg.value.target.ref);
5963
5985
  }
5964
5986
  }
5965
5987
  if (isEnum(argResolvedType.decl)) {
5966
5988
  let attrArgDeclType = dstRef?.ref;
5967
- if (dstType === "ContextType" && isDataModelField(attr.$container) && attr.$container?.type?.reference) {
5989
+ if (dstType === "ContextType" && isDataField(attr.$container) && attr.$container?.type?.reference) {
5968
5990
  attrArgDeclType = resolved(attr.$container.type.reference);
5969
5991
  dstIsArray = attr.$container.type.array;
5970
5992
  }
@@ -5974,7 +5996,7 @@ function assignableToAttributeParam(arg, param, attr) {
5974
5996
  return false;
5975
5997
  }
5976
5998
  if (dstType === "ContextType") {
5977
- if (isDataModelField(attr.$container)) {
5999
+ if (isDataField(attr.$container)) {
5978
6000
  if (!attr.$container?.type?.type) {
5979
6001
  return false;
5980
6002
  }
@@ -6032,6 +6054,9 @@ function isValidAttributeTarget(attrDecl, targetDecl) {
6032
6054
  case "TypeDefField":
6033
6055
  allowed = allowed || isTypeDef(targetDecl.type.reference?.ref);
6034
6056
  break;
6057
+ case "ListField":
6058
+ allowed = allowed || !isDataModel(targetDecl.type.reference?.ref) && targetDecl.type.array;
6059
+ break;
6035
6060
  default:
6036
6061
  break;
6037
6062
  }
@@ -6042,8 +6067,8 @@ function isValidAttributeTarget(attrDecl, targetDecl) {
6042
6067
  return allowed;
6043
6068
  }
6044
6069
  __name(isValidAttributeTarget, "isValidAttributeTarget");
6045
- function validateAttributeApplication(attr, accept) {
6046
- new AttributeApplicationValidator().validate(attr, accept);
6070
+ function validateAttributeApplication(attr, accept, contextDataModel) {
6071
+ new AttributeApplicationValidator().validate(attr, accept, contextDataModel);
6047
6072
  }
6048
6073
  __name(validateAttributeApplication, "validateAttributeApplication");
6049
6074
 
@@ -6058,6 +6083,7 @@ var AttributeValidator = class {
6058
6083
  };
6059
6084
 
6060
6085
  // src/validators/datamodel-validator.ts
6086
+ var import_common_helpers = require("@zenstackhq/common-helpers");
6061
6087
  var import_langium4 = require("langium");
6062
6088
 
6063
6089
  // src/validators/common.ts
@@ -6070,8 +6096,8 @@ function validateDuplicatedDeclarations(container, decls, accept) {
6070
6096
  for (const [name, decls2] of Object.entries(groupByName)) {
6071
6097
  if (decls2.length > 1) {
6072
6098
  let errorField = decls2[1];
6073
- if (isDataModelField(decls2[0])) {
6074
- const nonInheritedFields = decls2.filter((x) => !(isDataModelField(x) && x.$container !== container));
6099
+ if (isDataField(decls2[0])) {
6100
+ const nonInheritedFields = decls2.filter((x) => !(isDataField(x) && x.$container !== container));
6075
6101
  if (nonInheritedFields.length > 0) {
6076
6102
  errorField = nonInheritedFields.slice(-1)[0];
6077
6103
  }
@@ -6090,22 +6116,21 @@ var DataModelValidator = class {
6090
6116
  __name(this, "DataModelValidator");
6091
6117
  }
6092
6118
  validate(dm, accept) {
6093
- this.validateBaseAbstractModel(dm, accept);
6094
- this.validateBaseDelegateModel(dm, accept);
6095
- validateDuplicatedDeclarations(dm, getModelFieldsWithBases(dm), accept);
6119
+ validateDuplicatedDeclarations(dm, getAllFields(dm), accept);
6096
6120
  this.validateAttributes(dm, accept);
6097
6121
  this.validateFields(dm, accept);
6098
- if (dm.superTypes.length > 0) {
6099
- this.validateInheritance(dm, accept);
6122
+ if (dm.mixins.length > 0) {
6123
+ this.validateMixins(dm, accept);
6100
6124
  }
6125
+ this.validateInherits(dm, accept);
6101
6126
  }
6102
6127
  validateFields(dm, accept) {
6103
- const allFields = getModelFieldsWithBases(dm);
6128
+ const allFields = getAllFields(dm);
6104
6129
  const idFields = allFields.filter((f) => f.attributes.find((attr) => attr.decl.ref?.name === "@id"));
6105
6130
  const uniqueFields = allFields.filter((f) => f.attributes.find((attr) => attr.decl.ref?.name === "@unique"));
6106
6131
  const modelLevelIds = getModelIdFields(dm);
6107
6132
  const modelUniqueFields = getModelUniqueFields(dm);
6108
- if (!dm.isAbstract && idFields.length === 0 && modelLevelIds.length === 0 && uniqueFields.length === 0 && modelUniqueFields.length === 0) {
6133
+ if (idFields.length === 0 && modelLevelIds.length === 0 && uniqueFields.length === 0 && modelUniqueFields.length === 0) {
6109
6134
  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
6135
  node: dm
6111
6136
  });
@@ -6136,11 +6161,9 @@ var DataModelValidator = class {
6136
6161
  });
6137
6162
  }
6138
6163
  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
- }
6164
+ allFields.filter((x) => isDataModel(x.type.reference?.ref)).forEach((y) => {
6165
+ this.validateRelationField(dm, y, accept);
6166
+ });
6144
6167
  }
6145
6168
  validateField(field, accept) {
6146
6169
  if (field.type.array && field.type.optional) {
@@ -6156,7 +6179,7 @@ var DataModelValidator = class {
6156
6179
  if (field.type.array && !isDataModel(field.type.reference?.ref)) {
6157
6180
  const provider = this.getDataSourceProvider(import_langium4.AstUtils.getContainerOfType(field, isModel));
6158
6181
  if (provider === "sqlite") {
6159
- accept("error", `Array type is not supported for "${provider}" provider.`, {
6182
+ accept("error", `List type is not supported for "${provider}" provider.`, {
6160
6183
  node: field.type
6161
6184
  });
6162
6185
  }
@@ -6182,7 +6205,7 @@ var DataModelValidator = class {
6182
6205
  return getLiteral(provider.value);
6183
6206
  }
6184
6207
  validateAttributes(dm, accept) {
6185
- dm.attributes.forEach((attr) => validateAttributeApplication(attr, accept));
6208
+ getAllAttributes(dm).forEach((attr) => validateAttributeApplication(attr, accept, dm));
6186
6209
  }
6187
6210
  parseRelation(field, accept) {
6188
6211
  const relAttr = field.attributes.find((attr) => attr.decl.ref?.name === "@relation");
@@ -6301,11 +6324,20 @@ var DataModelValidator = class {
6301
6324
  if (!thisRelation.valid) {
6302
6325
  return;
6303
6326
  }
6304
- if (this.isFieldInheritedFromDelegateModel(field, contextModel)) {
6327
+ if (this.isFieldInheritedFromDelegateModel(field)) {
6305
6328
  return;
6306
6329
  }
6330
+ if (this.isSelfRelation(field)) {
6331
+ if (!thisRelation.name) {
6332
+ accept("error", "Self-relation field must have a name in @relation attribute", {
6333
+ node: field
6334
+ });
6335
+ return;
6336
+ }
6337
+ }
6307
6338
  const oppositeModel = field.type.reference.ref;
6308
- let oppositeFields = getModelFieldsWithBases(oppositeModel, false).filter((f) => f.type.reference?.ref?.name === contextModel.name);
6339
+ let oppositeFields = getAllFields(oppositeModel, false).filter((f) => f !== field && // exclude self in case of self relation
6340
+ f.type.reference?.ref?.name === contextModel.name);
6309
6341
  oppositeFields = oppositeFields.filter((f) => {
6310
6342
  const fieldRel = this.parseRelation(f);
6311
6343
  return fieldRel.valid && fieldRel.name === thisRelation.name;
@@ -6342,26 +6374,37 @@ var DataModelValidator = class {
6342
6374
  const oppositeField = oppositeFields[0];
6343
6375
  const oppositeRelation = this.parseRelation(oppositeField);
6344
6376
  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;
6377
+ if (field.type.array && oppositeField.type.array) {
6378
+ for (const r of [
6379
+ thisRelation,
6380
+ oppositeRelation
6381
+ ]) {
6382
+ if (r.fields?.length || r.references?.length) {
6383
+ accept("error", 'Implicit many-to-many relation cannot have "fields" or "references" in @relation attribute', {
6384
+ node: r === thisRelation ? field : oppositeField
6385
+ });
6386
+ }
6362
6387
  }
6363
6388
  } else {
6364
- if (!(field.type.array && oppositeField.type.array)) {
6389
+ if (thisRelation?.references?.length && thisRelation.fields?.length) {
6390
+ if (oppositeRelation?.references || oppositeRelation?.fields) {
6391
+ accept("error", '"fields" and "references" must be provided only on one side of relation field', {
6392
+ node: oppositeField
6393
+ });
6394
+ return;
6395
+ } else {
6396
+ relationOwner = oppositeField;
6397
+ }
6398
+ } else if (oppositeRelation?.references?.length && oppositeRelation.fields?.length) {
6399
+ if (thisRelation?.references || thisRelation?.fields) {
6400
+ accept("error", '"fields" and "references" must be provided only on one side of relation field', {
6401
+ node: field
6402
+ });
6403
+ return;
6404
+ } else {
6405
+ relationOwner = field;
6406
+ }
6407
+ } else {
6365
6408
  [
6366
6409
  field,
6367
6410
  oppositeField
@@ -6372,78 +6415,85 @@ var DataModelValidator = class {
6372
6415
  });
6373
6416
  }
6374
6417
  });
6418
+ return;
6375
6419
  }
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));
6420
+ if (!relationOwner.type.array && !relationOwner.type.optional) {
6421
+ accept("error", "Relation field needs to be list or optional", {
6422
+ node: relationOwner
6423
+ });
6424
+ return;
6389
6425
  }
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
- });
6426
+ if (relationOwner !== field && !relationOwner.type.array) {
6427
+ const containingModel = field.$container;
6428
+ const uniqueFieldList = getUniqueFields(containingModel);
6429
+ if (containingModel !== contextModel) {
6430
+ uniqueFieldList.push(...getUniqueFields(contextModel));
6402
6431
  }
6403
- });
6432
+ thisRelation.fields?.forEach((ref) => {
6433
+ const refField = ref.target.ref;
6434
+ if (refField) {
6435
+ if (refField.attributes.find((a) => a.decl.ref?.name === "@id" || a.decl.ref?.name === "@unique")) {
6436
+ return;
6437
+ }
6438
+ if (uniqueFieldList.some((list) => list.includes(refField))) {
6439
+ return;
6440
+ }
6441
+ 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`, {
6442
+ node: refField
6443
+ });
6444
+ }
6445
+ });
6446
+ }
6404
6447
  }
6405
6448
  }
6406
6449
  // 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
- });
6450
+ isFieldInheritedFromDelegateModel(field) {
6451
+ return isDelegateModel(field.$container);
6423
6452
  }
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", {
6453
+ validateInherits(model, accept) {
6454
+ if (!model.baseModel) {
6455
+ return;
6456
+ }
6457
+ (0, import_common_helpers.invariant)(model.baseModel.ref, "baseModel must be resolved");
6458
+ if (!isDelegateModel(model.baseModel.ref)) {
6459
+ accept("error", `Model ${model.baseModel.$refText} cannot be extended because it's not a delegate model`, {
6427
6460
  node: model,
6428
- property: "superTypes"
6461
+ property: "baseModel"
6429
6462
  });
6463
+ return;
6430
6464
  }
6431
- }
6432
- validateInheritance(dm, accept) {
6433
- const seen = [
6434
- dm
6465
+ const seen = [];
6466
+ const todo = [
6467
+ model.baseModel.ref
6435
6468
  ];
6436
- const todo = dm.superTypes.map((superType) => superType.ref);
6437
6469
  while (todo.length > 0) {
6438
6470
  const current = todo.shift();
6439
6471
  if (seen.includes(current)) {
6440
- accept("error", `Circular inheritance detected: ${seen.map((m) => m.name).join(" -> ")} -> ${current.name}`, {
6472
+ accept("error", `Cyclic inheritance detected: ${seen.map((m) => m.name).join(" -> ")} -> ${current.name}`, {
6473
+ node: model
6474
+ });
6475
+ return;
6476
+ }
6477
+ seen.push(current);
6478
+ if (current.baseModel) {
6479
+ (0, import_common_helpers.invariant)(current.baseModel.ref, "baseModel must be resolved");
6480
+ todo.push(current.baseModel.ref);
6481
+ }
6482
+ }
6483
+ }
6484
+ validateMixins(dm, accept) {
6485
+ const seen = [];
6486
+ const todo = dm.mixins.map((mixin) => mixin.ref);
6487
+ while (todo.length > 0) {
6488
+ const current = todo.shift();
6489
+ if (seen.includes(current)) {
6490
+ accept("error", `Cyclic mixin detected: ${seen.map((m) => m.name).join(" -> ")} -> ${current.name}`, {
6441
6491
  node: dm
6442
6492
  });
6443
6493
  return;
6444
6494
  }
6445
6495
  seen.push(current);
6446
- todo.push(...current.superTypes.map((superType) => superType.ref));
6496
+ todo.push(...current.mixins.map((mixin) => mixin.ref));
6447
6497
  }
6448
6498
  }
6449
6499
  };
@@ -6479,26 +6529,15 @@ var DataSourceValidator = class {
6479
6529
  }
6480
6530
  }
6481
6531
  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
- });
6532
+ const urlField = ds.fields.find((f) => f.name === "url");
6533
+ if (!urlField) {
6534
+ return;
6487
6535
  }
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
- }
6536
+ const value = getStringLiteral(urlField.value);
6537
+ if (!value && !(isInvocationExpr(urlField.value) && urlField.value.function.ref?.name === "env")) {
6538
+ accept("error", `"${urlField.name}" must be set to a string literal or an invocation of "env" function`, {
6539
+ node: urlField.value
6540
+ });
6502
6541
  }
6503
6542
  }
6504
6543
  validateRelationMode(ds, accept) {
@@ -6567,11 +6606,21 @@ var ExpressionValidator = class {
6567
6606
  }
6568
6607
  }
6569
6608
  switch (expr.$type) {
6609
+ case "MemberAccessExpr":
6610
+ this.validateMemberAccessExpr(expr, accept);
6611
+ break;
6570
6612
  case "BinaryExpr":
6571
6613
  this.validateBinaryExpr(expr, accept);
6572
6614
  break;
6573
6615
  }
6574
6616
  }
6617
+ validateMemberAccessExpr(expr, accept) {
6618
+ if (isBeforeInvocation(expr.operand) && isDataModel(expr.$resolvedType?.decl)) {
6619
+ accept("error", "relation fields cannot be accessed from `before()`", {
6620
+ node: expr
6621
+ });
6622
+ }
6623
+ }
6575
6624
  validateBinaryExpr(expr, accept) {
6576
6625
  switch (expr.operator) {
6577
6626
  case "in": {
@@ -6624,23 +6673,25 @@ var ExpressionValidator = class {
6624
6673
  "Any"
6625
6674
  ];
6626
6675
  }
6627
- if (typeof expr.left.$resolvedType?.decl !== "string" || !supportedShapes.includes(expr.left.$resolvedType.decl)) {
6676
+ const leftResolvedDecl = expr.left.$resolvedType?.decl;
6677
+ const rightResolvedDecl = expr.right.$resolvedType?.decl;
6678
+ if (leftResolvedDecl && (typeof leftResolvedDecl !== "string" || !supportedShapes.includes(leftResolvedDecl))) {
6628
6679
  accept("error", `invalid operand type for "${expr.operator}" operator`, {
6629
6680
  node: expr.left
6630
6681
  });
6631
6682
  return;
6632
6683
  }
6633
- if (typeof expr.right.$resolvedType?.decl !== "string" || !supportedShapes.includes(expr.right.$resolvedType.decl)) {
6684
+ if (rightResolvedDecl && (typeof rightResolvedDecl !== "string" || !supportedShapes.includes(rightResolvedDecl))) {
6634
6685
  accept("error", `invalid operand type for "${expr.operator}" operator`, {
6635
6686
  node: expr.right
6636
6687
  });
6637
6688
  return;
6638
6689
  }
6639
- if (expr.left.$resolvedType.decl === "DateTime" && expr.right.$resolvedType.decl !== "DateTime") {
6690
+ if (leftResolvedDecl === "DateTime" && rightResolvedDecl && rightResolvedDecl !== "DateTime") {
6640
6691
  accept("error", "incompatible operand types", {
6641
6692
  node: expr
6642
6693
  });
6643
- } else if (expr.right.$resolvedType.decl === "DateTime" && expr.left.$resolvedType.decl !== "DateTime") {
6694
+ } else if (rightResolvedDecl === "DateTime" && leftResolvedDecl && leftResolvedDecl !== "DateTime") {
6644
6695
  accept("error", "incompatible operand types", {
6645
6696
  node: expr
6646
6697
  });
@@ -6650,7 +6701,7 @@ var ExpressionValidator = class {
6650
6701
  case "==":
6651
6702
  case "!=": {
6652
6703
  if (this.isInValidationContext(expr)) {
6653
- if (isDataModelFieldReference(expr.left) && isNullExpr(expr.right) || isDataModelFieldReference(expr.right) && isNullExpr(expr.left)) {
6704
+ if (isDataFieldReference(expr.left) && isNullExpr(expr.right) || isDataFieldReference(expr.right) && isNullExpr(expr.left)) {
6654
6705
  return;
6655
6706
  }
6656
6707
  }
@@ -6679,12 +6730,12 @@ var ExpressionValidator = class {
6679
6730
  node: expr
6680
6731
  });
6681
6732
  }
6682
- if (isDataModelFieldReference(expr.left) && (isThisExpr(expr.right) || isDataModelFieldReference(expr.right))) {
6683
- accept("error", "comparison between model-typed fields are not supported", {
6733
+ if (isDataFieldReference(expr.left) && (isThisExpr(expr.right) || isDataFieldReference(expr.right))) {
6734
+ accept("error", "comparison between models is not supported", {
6684
6735
  node: expr
6685
6736
  });
6686
- } else if (isDataModelFieldReference(expr.right) && (isThisExpr(expr.left) || isDataModelFieldReference(expr.left))) {
6687
- accept("error", "comparison between model-typed fields are not supported", {
6737
+ } else if (isDataFieldReference(expr.right) && (isThisExpr(expr.left) || isDataFieldReference(expr.left))) {
6738
+ accept("error", "comparison between models is not supported", {
6688
6739
  node: expr
6689
6740
  });
6690
6741
  }
@@ -6774,41 +6825,39 @@ var FunctionInvocationValidator = class {
6774
6825
  if (!this.validateArgs(funcDecl, expr.args, accept)) {
6775
6826
  return;
6776
6827
  }
6777
- if (isFromStdlib(funcDecl)) {
6778
- let curr = expr.$container;
6779
- let containerAttribute;
6780
- while (curr) {
6781
- if (isDataModelAttribute(curr) || isDataModelFieldAttribute(curr)) {
6782
- containerAttribute = curr;
6783
- break;
6784
- }
6785
- curr = curr.$container;
6828
+ let curr = expr.$container;
6829
+ let containerAttribute;
6830
+ while (curr) {
6831
+ if (isDataModelAttribute(curr) || isDataFieldAttribute(curr)) {
6832
+ containerAttribute = curr;
6833
+ break;
6786
6834
  }
6787
- const exprContext = (0, import_ts_pattern.match)(containerAttribute?.decl.$refText).with("@default", () => ExpressionContext.DefaultValue).with(import_ts_pattern.P.union("@@allow", "@@deny", "@allow", "@deny"), () => ExpressionContext.AccessPolicy).with("@@validate", () => ExpressionContext.ValidationRule).with("@@index", () => ExpressionContext.Index).otherwise(() => void 0);
6788
- const funcAllowedContext = getFunctionExpressionContext(funcDecl);
6789
- if (exprContext && !funcAllowedContext.includes(exprContext)) {
6790
- accept("error", `function "${funcDecl.name}" is not allowed in the current context: ${exprContext}`, {
6791
- node: expr
6835
+ curr = curr.$container;
6836
+ }
6837
+ const exprContext = this.getExpressionContext(containerAttribute);
6838
+ const funcAllowedContext = getFunctionExpressionContext(funcDecl);
6839
+ if (exprContext && !funcAllowedContext.includes(exprContext)) {
6840
+ accept("error", `function "${funcDecl.name}" is not allowed in the current context: ${exprContext}`, {
6841
+ node: expr
6842
+ });
6843
+ return;
6844
+ }
6845
+ const allCasing = [
6846
+ "original",
6847
+ "upper",
6848
+ "lower",
6849
+ "capitalize",
6850
+ "uncapitalize"
6851
+ ];
6852
+ if ([
6853
+ "currentModel",
6854
+ "currentOperation"
6855
+ ].includes(funcDecl.name)) {
6856
+ const arg = getLiteral(expr.args[0]?.value);
6857
+ if (arg && !allCasing.includes(arg)) {
6858
+ accept("error", `argument must be one of: ${allCasing.map((c) => '"' + c + '"').join(", ")}`, {
6859
+ node: expr.args[0]
6792
6860
  });
6793
- return;
6794
- }
6795
- const allCasing = [
6796
- "original",
6797
- "upper",
6798
- "lower",
6799
- "capitalize",
6800
- "uncapitalize"
6801
- ];
6802
- if ([
6803
- "currentModel",
6804
- "currentOperation"
6805
- ].includes(funcDecl.name)) {
6806
- const arg = getLiteral(expr.args[0]?.value);
6807
- if (arg && !allCasing.includes(arg)) {
6808
- accept("error", `argument must be one of: ${allCasing.map((c) => '"' + c + '"').join(", ")}`, {
6809
- node: expr.args[0]
6810
- });
6811
- }
6812
6861
  }
6813
6862
  }
6814
6863
  const checker = invocationCheckers.get(expr.function.$refText);
@@ -6816,6 +6865,18 @@ var FunctionInvocationValidator = class {
6816
6865
  checker.value.call(this, expr, accept);
6817
6866
  }
6818
6867
  }
6868
+ getExpressionContext(containerAttribute) {
6869
+ if (!containerAttribute) {
6870
+ return void 0;
6871
+ }
6872
+ if (this.isValidationAttribute(containerAttribute)) {
6873
+ return ExpressionContext.ValidationRule;
6874
+ }
6875
+ return (0, import_ts_pattern.match)(containerAttribute?.decl.$refText).with("@default", () => ExpressionContext.DefaultValue).with(import_ts_pattern.P.union("@@allow", "@@deny", "@allow", "@deny"), () => ExpressionContext.AccessPolicy).with("@@index", () => ExpressionContext.Index).otherwise(() => void 0);
6876
+ }
6877
+ isValidationAttribute(attr) {
6878
+ return !!attr.decl.ref?.attributes.some((attr2) => attr2.decl.$refText === "@@@validation");
6879
+ }
6819
6880
  validateArgs(funcDecl, args, accept) {
6820
6881
  let success = true;
6821
6882
  for (let i = 0; i < funcDecl.params.length; i++) {
@@ -6876,10 +6937,48 @@ var FunctionInvocationValidator = class {
6876
6937
  }
6877
6938
  return true;
6878
6939
  }
6940
+ _checkLength(expr, accept) {
6941
+ const msg = "argument must be a string or list field";
6942
+ const fieldArg = expr.args[0].value;
6943
+ if (!isDataFieldReference(fieldArg)) {
6944
+ accept("error", msg, {
6945
+ node: expr.args[0]
6946
+ });
6947
+ return;
6948
+ }
6949
+ if (isDataModel(fieldArg.$resolvedType?.decl)) {
6950
+ accept("error", msg, {
6951
+ node: expr.args[0]
6952
+ });
6953
+ return;
6954
+ }
6955
+ if (!fieldArg.$resolvedType?.array && fieldArg.$resolvedType?.decl !== "String") {
6956
+ accept("error", msg, {
6957
+ node: expr.args[0]
6958
+ });
6959
+ }
6960
+ }
6961
+ _checkRegex(expr, accept) {
6962
+ const regex = expr.args[1]?.value;
6963
+ if (!isStringLiteral(regex)) {
6964
+ accept("error", "second argument must be a string literal", {
6965
+ node: expr.args[1]
6966
+ });
6967
+ return;
6968
+ }
6969
+ try {
6970
+ new RegExp(regex.value);
6971
+ } catch (e) {
6972
+ accept("error", "invalid regular expression: " + e.message, {
6973
+ node: expr.args[1]
6974
+ });
6975
+ }
6976
+ }
6977
+ // TODO: move this to policy plugin
6879
6978
  _checkCheck(expr, accept) {
6880
6979
  let valid = true;
6881
6980
  const fieldArg = expr.args[0].value;
6882
- if (!isDataModelFieldReference(fieldArg) || !isDataModel(fieldArg.$resolvedType?.decl)) {
6981
+ if (!isDataFieldReference(fieldArg) || !isDataModel(fieldArg.$resolvedType?.decl)) {
6883
6982
  accept("error", "argument must be a relation field", {
6884
6983
  node: expr.args[0]
6885
6984
  });
@@ -6947,6 +7046,24 @@ var FunctionInvocationValidator = class {
6947
7046
  }
6948
7047
  }
6949
7048
  };
7049
+ _ts_decorate2([
7050
+ func("length"),
7051
+ _ts_metadata2("design:type", Function),
7052
+ _ts_metadata2("design:paramtypes", [
7053
+ typeof InvocationExpr === "undefined" ? Object : InvocationExpr,
7054
+ typeof ValidationAcceptor === "undefined" ? Object : ValidationAcceptor
7055
+ ]),
7056
+ _ts_metadata2("design:returntype", void 0)
7057
+ ], FunctionInvocationValidator.prototype, "_checkLength", null);
7058
+ _ts_decorate2([
7059
+ func("regex"),
7060
+ _ts_metadata2("design:type", Function),
7061
+ _ts_metadata2("design:paramtypes", [
7062
+ typeof InvocationExpr === "undefined" ? Object : InvocationExpr,
7063
+ typeof ValidationAcceptor === "undefined" ? Object : ValidationAcceptor
7064
+ ]),
7065
+ _ts_metadata2("design:returntype", void 0)
7066
+ ], FunctionInvocationValidator.prototype, "_checkRegex", null);
6950
7067
  _ts_decorate2([
6951
7068
  func("check"),
6952
7069
  _ts_metadata2("design:type", Function),
@@ -6994,8 +7111,8 @@ var SchemaValidator = class {
6994
7111
  validateImports(model, accept) {
6995
7112
  model.imports.forEach((imp) => {
6996
7113
  const importedModel = resolveImport(this.documents, imp);
6997
- const importPath = imp.path.endsWith(".zmodel") ? imp.path : `${imp.path}.zmodel`;
6998
7114
  if (!importedModel) {
7115
+ const importPath = imp.path.endsWith(".zmodel") ? imp.path : `${imp.path}.zmodel`;
6999
7116
  accept("error", `Cannot find model file ${importPath}`, {
7000
7117
  node: imp
7001
7118
  });
@@ -7021,6 +7138,11 @@ var TypeDefValidator = class {
7021
7138
  typeDef.fields.forEach((field) => this.validateField(field, accept));
7022
7139
  }
7023
7140
  validateField(field, accept) {
7141
+ if (isDataModel(field.type.reference?.ref)) {
7142
+ accept("error", "Type field cannot be a relation", {
7143
+ node: field.type
7144
+ });
7145
+ }
7024
7146
  field.attributes.forEach((attr) => validateAttributeApplication(attr, accept));
7025
7147
  }
7026
7148
  };
@@ -7051,51 +7173,68 @@ var ZModelValidator = class {
7051
7173
  constructor(services) {
7052
7174
  this.services = services;
7053
7175
  }
7054
- shouldCheck(node) {
7055
- let doc;
7056
- let currNode = node;
7057
- while (currNode) {
7058
- if (currNode.$document) {
7059
- doc = currNode.$document;
7060
- break;
7061
- }
7062
- currNode = currNode.$container;
7063
- }
7064
- return doc?.parseResult.lexerErrors.length === 0 && doc?.parseResult.parserErrors.length === 0;
7065
- }
7066
7176
  checkModel(node, accept) {
7067
- this.shouldCheck(node) && new SchemaValidator(this.services.shared.workspace.LangiumDocuments).validate(node, accept);
7177
+ new SchemaValidator(this.services.shared.workspace.LangiumDocuments).validate(node, accept);
7068
7178
  }
7069
7179
  checkDataSource(node, accept) {
7070
- this.shouldCheck(node) && new DataSourceValidator().validate(node, accept);
7180
+ new DataSourceValidator().validate(node, accept);
7071
7181
  }
7072
7182
  checkDataModel(node, accept) {
7073
- this.shouldCheck(node) && new DataModelValidator().validate(node, accept);
7183
+ new DataModelValidator().validate(node, accept);
7074
7184
  }
7075
7185
  checkTypeDef(node, accept) {
7076
- this.shouldCheck(node) && new TypeDefValidator().validate(node, accept);
7186
+ new TypeDefValidator().validate(node, accept);
7077
7187
  }
7078
7188
  checkEnum(node, accept) {
7079
- this.shouldCheck(node) && new EnumValidator().validate(node, accept);
7189
+ new EnumValidator().validate(node, accept);
7080
7190
  }
7081
7191
  checkAttribute(node, accept) {
7082
- this.shouldCheck(node) && new AttributeValidator().validate(node, accept);
7192
+ new AttributeValidator().validate(node, accept);
7083
7193
  }
7084
7194
  checkExpression(node, accept) {
7085
- this.shouldCheck(node) && new ExpressionValidator().validate(node, accept);
7195
+ new ExpressionValidator().validate(node, accept);
7086
7196
  }
7087
7197
  checkFunctionInvocation(node, accept) {
7088
- this.shouldCheck(node) && new FunctionInvocationValidator().validate(node, accept);
7198
+ new FunctionInvocationValidator().validate(node, accept);
7089
7199
  }
7090
7200
  checkFunctionDecl(node, accept) {
7091
- this.shouldCheck(node) && new FunctionDeclValidator().validate(node, accept);
7201
+ new FunctionDeclValidator().validate(node, accept);
7092
7202
  }
7093
7203
  };
7094
7204
 
7095
- // src/zmodel-linker.ts
7205
+ // src/zmodel-document-builder.ts
7096
7206
  var import_langium7 = require("langium");
7207
+ var ZModelDocumentBuilder = class extends import_langium7.DefaultDocumentBuilder {
7208
+ static {
7209
+ __name(this, "ZModelDocumentBuilder");
7210
+ }
7211
+ constructor(services) {
7212
+ super(services);
7213
+ let validationOptions = this.updateBuildOptions.validation;
7214
+ const stopFlags = {
7215
+ stopAfterLinkingErrors: true,
7216
+ stopAfterLexingErrors: true,
7217
+ stopAfterParsingErrors: true
7218
+ };
7219
+ if (validationOptions === true) {
7220
+ validationOptions = stopFlags;
7221
+ } else if (typeof validationOptions === "object") {
7222
+ validationOptions = {
7223
+ ...validationOptions,
7224
+ ...stopFlags
7225
+ };
7226
+ }
7227
+ this.updateBuildOptions = {
7228
+ ...this.updateBuildOptions,
7229
+ validation: validationOptions
7230
+ };
7231
+ }
7232
+ };
7233
+
7234
+ // src/zmodel-linker.ts
7235
+ var import_langium8 = require("langium");
7097
7236
  var import_ts_pattern2 = require("ts-pattern");
7098
- var ZModelLinker = class extends import_langium7.DefaultLinker {
7237
+ var ZModelLinker = class extends import_langium8.DefaultLinker {
7099
7238
  static {
7100
7239
  __name(this, "ZModelLinker");
7101
7240
  }
@@ -7105,31 +7244,29 @@ var ZModelLinker = class extends import_langium7.DefaultLinker {
7105
7244
  this.descriptions = services.workspace.AstNodeDescriptionProvider;
7106
7245
  }
7107
7246
  //#region Reference linking
7108
- async link(document, cancelToken = import_langium7.Cancellation.CancellationToken.None) {
7247
+ async link(document, cancelToken = import_langium8.Cancellation.CancellationToken.None) {
7109
7248
  if (document.parseResult.lexerErrors?.length > 0 || document.parseResult.parserErrors?.length > 0) {
7110
7249
  return;
7111
7250
  }
7112
- for (const node of import_langium7.AstUtils.streamContents(document.parseResult.value)) {
7113
- await (0, import_langium7.interruptAndCheck)(cancelToken);
7251
+ for (const node of import_langium8.AstUtils.streamContents(document.parseResult.value)) {
7252
+ await (0, import_langium8.interruptAndCheck)(cancelToken);
7114
7253
  this.resolve(node, document);
7115
7254
  }
7116
- document.state = import_langium7.DocumentState.Linked;
7255
+ document.state = import_langium8.DocumentState.Linked;
7117
7256
  }
7118
- linkReference(container, property, document, extraScopes) {
7119
- if (this.resolveFromScopeProviders(container, property, document, extraScopes)) {
7257
+ linkReference(refInfo, document, extraScopes) {
7258
+ const defaultRef = refInfo.reference;
7259
+ if (defaultRef._ref) {
7260
+ return;
7261
+ }
7262
+ if (this.resolveFromScopeProviders(refInfo.reference, document, extraScopes)) {
7120
7263
  return;
7121
7264
  }
7122
- const reference = container[property];
7123
- this.doLink({
7124
- reference,
7125
- container,
7126
- property
7127
- }, document);
7265
+ this.doLink(refInfo, document);
7128
7266
  }
7129
7267
  //#endregion
7130
7268
  //#region Expression type resolving
7131
- resolveFromScopeProviders(node, property, document, providers) {
7132
- const reference = node[property];
7269
+ resolveFromScopeProviders(reference, document, providers) {
7133
7270
  for (const provider of providers) {
7134
7271
  const target = provider(reference.$refText);
7135
7272
  if (target) {
@@ -7181,8 +7318,8 @@ var ZModelLinker = class extends import_langium7.DefaultLinker {
7181
7318
  case DataModel:
7182
7319
  this.resolveDataModel(node, document, extraScopes);
7183
7320
  break;
7184
- case DataModelField:
7185
- this.resolveDataModelField(node, document, extraScopes);
7321
+ case DataField:
7322
+ this.resolveDataField(node, document, extraScopes);
7186
7323
  break;
7187
7324
  default:
7188
7325
  this.resolveDefault(node, document, extraScopes);
@@ -7258,12 +7395,16 @@ var ZModelLinker = class extends import_langium7.DefaultLinker {
7258
7395
  }
7259
7396
  }
7260
7397
  resolveInvocation(node, document, extraScopes) {
7261
- this.linkReference(node, "function", document, extraScopes);
7398
+ this.linkReference({
7399
+ reference: node.function,
7400
+ container: node,
7401
+ property: "function"
7402
+ }, document, extraScopes);
7262
7403
  node.args.forEach((arg) => this.resolve(arg, document, extraScopes));
7263
7404
  if (node.function.ref) {
7264
7405
  const funcDecl = node.function.ref;
7265
7406
  if (isAuthInvocation(node)) {
7266
- const allDecls = getAllLoadedAndReachableDataModelsAndTypeDefs(this.langiumDocuments(), import_langium7.AstUtils.getContainerOfType(node, isDataModel));
7407
+ const allDecls = getAllLoadedAndReachableDataModelsAndTypeDefs(this.langiumDocuments(), import_langium8.AstUtils.getContainerOfType(node, isDataModel));
7267
7408
  const authDecl = getAuthDecl(allDecls);
7268
7409
  if (authDecl) {
7269
7410
  node.$resolvedType = {
@@ -7271,7 +7412,7 @@ var ZModelLinker = class extends import_langium7.DefaultLinker {
7271
7412
  nullable: true
7272
7413
  };
7273
7414
  }
7274
- } else if (isFutureExpr(node)) {
7415
+ } else if (isBeforeInvocation(node)) {
7275
7416
  node.$resolvedType = {
7276
7417
  decl: getContainingDataModel(node)
7277
7418
  };
@@ -7328,14 +7469,14 @@ var ZModelLinker = class extends import_langium7.DefaultLinker {
7328
7469
  resolveAttributeArg(node, document, extraScopes) {
7329
7470
  const attrParam = this.findAttrParamForArg(node);
7330
7471
  const attrAppliedOn = node.$container.$container;
7331
- if (attrParam?.type.type === "TransitiveFieldReference" && isDataModelField(attrAppliedOn)) {
7472
+ if (attrParam?.type.type === "TransitiveFieldReference" && isDataField(attrAppliedOn)) {
7332
7473
  const transitiveDataModel = attrAppliedOn.type.reference?.ref;
7333
7474
  if (transitiveDataModel) {
7334
- const scopeProvider = /* @__PURE__ */ __name((name) => getModelFieldsWithBases(transitiveDataModel).find((f) => f.name === name), "scopeProvider");
7475
+ const scopeProvider = /* @__PURE__ */ __name((name) => getAllFields(transitiveDataModel).find((f) => f.name === name), "scopeProvider");
7335
7476
  if (isArrayExpr(node.value)) {
7336
7477
  node.value.items.forEach((item) => {
7337
7478
  if (isReferenceExpr(item)) {
7338
- const resolved2 = this.resolveFromScopeProviders(item, "target", document, [
7479
+ const resolved2 = this.resolveFromScopeProviders(item.target, document, [
7339
7480
  scopeProvider
7340
7481
  ]);
7341
7482
  if (resolved2) {
@@ -7349,7 +7490,7 @@ var ZModelLinker = class extends import_langium7.DefaultLinker {
7349
7490
  this.resolveToBuiltinTypeOrDecl(node.value, node.value.items[0].$resolvedType.decl, true);
7350
7491
  }
7351
7492
  } else if (isReferenceExpr(node.value)) {
7352
- const resolved2 = this.resolveFromScopeProviders(node.value, "target", document, [
7493
+ const resolved2 = this.resolveFromScopeProviders(node.value.target, document, [
7353
7494
  scopeProvider
7354
7495
  ]);
7355
7496
  if (resolved2) {
@@ -7387,7 +7528,7 @@ var ZModelLinker = class extends import_langium7.DefaultLinker {
7387
7528
  resolveDataModel(node, document, extraScopes) {
7388
7529
  return this.resolveDefault(node, document, extraScopes);
7389
7530
  }
7390
- resolveDataModelField(node, document, extraScopes) {
7531
+ resolveDataField(node, document, extraScopes) {
7391
7532
  this.resolve(node.type, document, extraScopes);
7392
7533
  let scopes = extraScopes;
7393
7534
  if (node.type.reference?.ref && isEnum(node.type.reference.ref)) {
@@ -7401,14 +7542,10 @@ var ZModelLinker = class extends import_langium7.DefaultLinker {
7401
7542
  this.resolveDefault(node, document, scopes);
7402
7543
  }
7403
7544
  resolveDefault(node, document, extraScopes) {
7404
- for (const [property, value] of Object.entries(node)) {
7405
- if (!property.startsWith("$")) {
7406
- if ((0, import_langium7.isReference)(value)) {
7407
- this.linkReference(node, property, document, extraScopes);
7408
- }
7409
- }
7410
- }
7411
- for (const child of import_langium7.AstUtils.streamContents(node)) {
7545
+ import_langium8.AstUtils.streamReferences(node).forEach((ref) => {
7546
+ this.linkReference(ref, document, extraScopes);
7547
+ });
7548
+ for (const child of import_langium8.AstUtils.streamContents(node)) {
7412
7549
  this.resolve(child, document, extraScopes);
7413
7550
  }
7414
7551
  }
@@ -7416,7 +7553,7 @@ var ZModelLinker = class extends import_langium7.DefaultLinker {
7416
7553
  //#region Utils
7417
7554
  resolveToDeclaredType(node, type) {
7418
7555
  let nullable = false;
7419
- if (isDataModelFieldType(type) || isTypeDefField(type)) {
7556
+ if (isDataFieldType(type)) {
7420
7557
  nullable = type.optional;
7421
7558
  if (type.unsupported) {
7422
7559
  node.$resolvedType = {
@@ -7452,9 +7589,9 @@ var ZModelLinker = class extends import_langium7.DefaultLinker {
7452
7589
  };
7453
7590
 
7454
7591
  // src/zmodel-scope.ts
7455
- var import_langium8 = require("langium");
7592
+ var import_langium9 = require("langium");
7456
7593
  var import_ts_pattern3 = require("ts-pattern");
7457
- var ZModelScopeComputation = class extends import_langium8.DefaultScopeComputation {
7594
+ var ZModelScopeComputation = class extends import_langium9.DefaultScopeComputation {
7458
7595
  static {
7459
7596
  __name(this, "ZModelScopeComputation");
7460
7597
  }
@@ -7464,9 +7601,9 @@ var ZModelScopeComputation = class extends import_langium8.DefaultScopeComputati
7464
7601
  }
7465
7602
  async computeExports(document, cancelToken) {
7466
7603
  const result = await super.computeExports(document, cancelToken);
7467
- for (const node of import_langium8.AstUtils.streamAllContents(document.parseResult.value)) {
7604
+ for (const node of import_langium9.AstUtils.streamAllContents(document.parseResult.value)) {
7468
7605
  if (cancelToken) {
7469
- await (0, import_langium8.interruptAndCheck)(cancelToken);
7606
+ await (0, import_langium9.interruptAndCheck)(cancelToken);
7470
7607
  }
7471
7608
  if (isEnumField(node)) {
7472
7609
  const desc = this.services.workspace.AstNodeDescriptionProvider.createDescription(node, node.name, document);
@@ -7477,9 +7614,17 @@ var ZModelScopeComputation = class extends import_langium8.DefaultScopeComputati
7477
7614
  }
7478
7615
  processNode(node, document, scopes) {
7479
7616
  super.processNode(node, document, scopes);
7617
+ if (isDataModel(node) || isTypeDef(node)) {
7618
+ const bases = getRecursiveBases(node);
7619
+ for (const base of bases) {
7620
+ for (const field of base.fields) {
7621
+ scopes.add(node, this.descriptions.createDescription(field, this.nameProvider.getName(field)));
7622
+ }
7623
+ }
7624
+ }
7480
7625
  }
7481
7626
  };
7482
- var ZModelScopeProvider = class extends import_langium8.DefaultScopeProvider {
7627
+ var ZModelScopeProvider = class extends import_langium9.DefaultScopeProvider {
7483
7628
  static {
7484
7629
  __name(this, "ZModelScopeProvider");
7485
7630
  }
@@ -7488,19 +7633,19 @@ var ZModelScopeProvider = class extends import_langium8.DefaultScopeProvider {
7488
7633
  super(services), this.services = services;
7489
7634
  }
7490
7635
  getGlobalScope(referenceType, context) {
7491
- const model = import_langium8.AstUtils.getContainerOfType(context.container, isModel);
7636
+ const model = import_langium9.AstUtils.getContainerOfType(context.container, isModel);
7492
7637
  if (!model) {
7493
- return import_langium8.EMPTY_SCOPE;
7638
+ return import_langium9.EMPTY_SCOPE;
7494
7639
  }
7495
7640
  const importedUris = model.imports.map(resolveImportUri).filter((url) => !!url);
7496
7641
  const importedElements = this.indexManager.allElements(referenceType).filter((des) => (
7497
7642
  // allow current document
7498
- import_langium8.UriUtils.equals(des.documentUri, model.$document?.uri) || // allow stdlib
7643
+ import_langium9.UriUtils.equals(des.documentUri, model.$document?.uri) || // allow stdlib
7499
7644
  des.documentUri.path.endsWith(STD_LIB_MODULE_NAME) || // allow plugin models
7500
7645
  des.documentUri.path.endsWith(PLUGIN_MODULE_NAME) || // allow imported documents
7501
- importedUris.some((importedUri) => import_langium8.UriUtils.equals(des.documentUri, importedUri))
7646
+ importedUris.some((importedUri) => import_langium9.UriUtils.equals(des.documentUri, importedUri))
7502
7647
  ));
7503
- return new import_langium8.StreamScope(importedElements);
7648
+ return new import_langium9.StreamScope(importedElements);
7504
7649
  }
7505
7650
  getScope(context) {
7506
7651
  if (isMemberAccessExpr(context.container) && context.container.operand && context.property === "member") {
@@ -7520,34 +7665,31 @@ var ZModelScopeProvider = class extends import_langium8.DefaultScopeProvider {
7520
7665
  const node = context.container;
7521
7666
  const allowTypeDefScope = (
7522
7667
  // isAuthOrAuthMemberAccess(node.operand) ||
7523
- !!import_langium8.AstUtils.getContainerOfType(node, isTypeDef)
7668
+ !!import_langium9.AstUtils.getContainerOfType(node, isTypeDef)
7524
7669
  );
7525
7670
  return (0, import_ts_pattern3.match)(node.operand).when(isReferenceExpr, (operand) => {
7526
7671
  const ref = operand.target.ref;
7527
- if (isDataModelField(ref) || isTypeDefField(ref)) {
7672
+ if (isDataField(ref)) {
7528
7673
  return this.createScopeForContainer(ref.type.reference?.ref, globalScope, allowTypeDefScope);
7529
7674
  }
7530
- return import_langium8.EMPTY_SCOPE;
7675
+ return import_langium9.EMPTY_SCOPE;
7531
7676
  }).when(isMemberAccessExpr, (operand) => {
7532
7677
  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) {
7678
+ if (isDataField(ref) && !ref.type.array) {
7537
7679
  return this.createScopeForContainer(ref.type.reference?.ref, globalScope, allowTypeDefScope);
7538
7680
  }
7539
- return import_langium8.EMPTY_SCOPE;
7681
+ return import_langium9.EMPTY_SCOPE;
7540
7682
  }).when(isThisExpr, () => {
7541
7683
  return this.createScopeForContainingModel(node, globalScope);
7542
7684
  }).when(isInvocationExpr, (operand) => {
7543
7685
  if (isAuthInvocation(operand)) {
7544
7686
  return this.createScopeForAuth(node, globalScope);
7545
7687
  }
7546
- if (isFutureInvocation(operand)) {
7688
+ if (isBeforeInvocation(operand)) {
7547
7689
  return this.createScopeForContainingModel(node, globalScope);
7548
7690
  }
7549
- return import_langium8.EMPTY_SCOPE;
7550
- }).otherwise(() => import_langium8.EMPTY_SCOPE);
7691
+ return import_langium9.EMPTY_SCOPE;
7692
+ }).otherwise(() => import_langium9.EMPTY_SCOPE);
7551
7693
  }
7552
7694
  getCollectionPredicateScope(context, collectionPredicate) {
7553
7695
  const referenceType = this.reflection.getReferenceType(context);
@@ -7556,51 +7698,51 @@ var ZModelScopeProvider = class extends import_langium8.DefaultScopeProvider {
7556
7698
  const allowTypeDefScope = false;
7557
7699
  return (0, import_ts_pattern3.match)(collection).when(isReferenceExpr, (expr) => {
7558
7700
  const ref = expr.target.ref;
7559
- if (isDataModelField(ref) || isTypeDefField(ref)) {
7701
+ if (isDataField(ref)) {
7560
7702
  return this.createScopeForContainer(ref.type.reference?.ref, globalScope, allowTypeDefScope);
7561
7703
  }
7562
- return import_langium8.EMPTY_SCOPE;
7704
+ return import_langium9.EMPTY_SCOPE;
7563
7705
  }).when(isMemberAccessExpr, (expr) => {
7564
7706
  const ref = expr.member.ref;
7565
- if (isDataModelField(ref) || isTypeDefField(ref)) {
7707
+ if (isDataField(ref)) {
7566
7708
  return this.createScopeForContainer(ref.type.reference?.ref, globalScope, allowTypeDefScope);
7567
7709
  }
7568
- return import_langium8.EMPTY_SCOPE;
7710
+ return import_langium9.EMPTY_SCOPE;
7569
7711
  }).when(isInvocationExpr, (expr) => {
7570
7712
  const returnTypeDecl = expr.function.ref?.returnType.reference?.ref;
7571
7713
  if (isDataModel(returnTypeDecl)) {
7572
7714
  return this.createScopeForContainer(returnTypeDecl, globalScope, allowTypeDefScope);
7573
7715
  } else {
7574
- return import_langium8.EMPTY_SCOPE;
7716
+ return import_langium9.EMPTY_SCOPE;
7575
7717
  }
7576
7718
  }).when(isAuthInvocation, (expr) => {
7577
7719
  return this.createScopeForAuth(expr, globalScope);
7578
- }).otherwise(() => import_langium8.EMPTY_SCOPE);
7720
+ }).otherwise(() => import_langium9.EMPTY_SCOPE);
7579
7721
  }
7580
7722
  createScopeForContainingModel(node, globalScope) {
7581
- const model = import_langium8.AstUtils.getContainerOfType(node, isDataModel);
7723
+ const model = import_langium9.AstUtils.getContainerOfType(node, isDataModel);
7582
7724
  if (model) {
7583
7725
  return this.createScopeForContainer(model, globalScope);
7584
7726
  } else {
7585
- return import_langium8.EMPTY_SCOPE;
7727
+ return import_langium9.EMPTY_SCOPE;
7586
7728
  }
7587
7729
  }
7588
7730
  createScopeForContainer(node, globalScope, includeTypeDefScope = false) {
7589
7731
  if (isDataModel(node)) {
7590
- return this.createScopeForNodes(getModelFieldsWithBases(node), globalScope);
7732
+ return this.createScopeForNodes(getAllFields(node), globalScope);
7591
7733
  } else if (includeTypeDefScope && isTypeDef(node)) {
7592
7734
  return this.createScopeForNodes(node.fields, globalScope);
7593
7735
  } else {
7594
- return import_langium8.EMPTY_SCOPE;
7736
+ return import_langium9.EMPTY_SCOPE;
7595
7737
  }
7596
7738
  }
7597
7739
  createScopeForAuth(node, globalScope) {
7598
- const decls = getAllLoadedAndReachableDataModelsAndTypeDefs(this.services.shared.workspace.LangiumDocuments, import_langium8.AstUtils.getContainerOfType(node, isDataModel));
7740
+ const decls = getAllLoadedAndReachableDataModelsAndTypeDefs(this.services.shared.workspace.LangiumDocuments, import_langium9.AstUtils.getContainerOfType(node, isDataModel));
7599
7741
  const authDecl = getAuthDecl(decls);
7600
7742
  if (authDecl) {
7601
7743
  return this.createScopeForContainer(authDecl, globalScope, true);
7602
7744
  } else {
7603
- return import_langium8.EMPTY_SCOPE;
7745
+ return import_langium9.EMPTY_SCOPE;
7604
7746
  }
7605
7747
  }
7606
7748
  };
@@ -7617,12 +7759,12 @@ function getCollectionPredicateContext(node) {
7617
7759
  __name(getCollectionPredicateContext, "getCollectionPredicateContext");
7618
7760
 
7619
7761
  // src/zmodel-workspace-manager.ts
7620
- var import_langium9 = require("langium");
7762
+ var import_langium10 = require("langium");
7621
7763
  var import_node_fs2 = __toESM(require("fs"), 1);
7622
- var import_node_path = __toESM(require("path"), 1);
7623
- var import_node_url = require("url");
7624
- var import_meta = {};
7625
- var ZModelWorkspaceManager = class extends import_langium9.DefaultWorkspaceManager {
7764
+ var import_node_path2 = __toESM(require("path"), 1);
7765
+ var import_node_url2 = require("url");
7766
+ var import_meta2 = {};
7767
+ var ZModelWorkspaceManager = class extends import_langium10.DefaultWorkspaceManager {
7626
7768
  static {
7627
7769
  __name(this, "ZModelWorkspaceManager");
7628
7770
  }
@@ -7643,8 +7785,8 @@ var ZModelWorkspaceManager = class extends import_langium9.DefaultWorkspaceManag
7643
7785
  folderPath
7644
7786
  ]
7645
7787
  });
7646
- const languagePackageDir = import_node_path.default.dirname(languagePackagePath);
7647
- const candidateStdlibPath = import_node_path.default.join(languagePackageDir, "res", STD_LIB_MODULE_NAME);
7788
+ const languagePackageDir = import_node_path2.default.dirname(languagePackagePath);
7789
+ const candidateStdlibPath = import_node_path2.default.join(languagePackageDir, "res", STD_LIB_MODULE_NAME);
7648
7790
  if (import_node_fs2.default.existsSync(candidateStdlibPath)) {
7649
7791
  installedStdlibPath = candidateStdlibPath;
7650
7792
  console.log(`Found installed zenstack package stdlib at: ${installedStdlibPath}`);
@@ -7657,11 +7799,11 @@ var ZModelWorkspaceManager = class extends import_langium9.DefaultWorkspaceManag
7657
7799
  if (installedStdlibPath) {
7658
7800
  stdLibPath = installedStdlibPath;
7659
7801
  } else {
7660
- const _dirname = typeof __dirname !== "undefined" ? __dirname : import_node_path.default.dirname((0, import_node_url.fileURLToPath)(import_meta.url));
7661
- stdLibPath = import_node_path.default.join(_dirname, "../res", STD_LIB_MODULE_NAME);
7802
+ const _dirname = typeof __dirname !== "undefined" ? __dirname : import_node_path2.default.dirname((0, import_node_url2.fileURLToPath)(import_meta2.url));
7803
+ stdLibPath = import_node_path2.default.join(_dirname, "../res", STD_LIB_MODULE_NAME);
7662
7804
  console.log(`Using bundled stdlib in extension:`, stdLibPath);
7663
7805
  }
7664
- const stdlib = await this.documentFactory.fromUri(import_langium9.URI.file(stdLibPath));
7806
+ const stdlib = await this.documentFactory.fromUri(import_langium10.URI.file(stdLibPath));
7665
7807
  collector(stdlib);
7666
7808
  }
7667
7809
  };
@@ -7679,12 +7821,13 @@ var ZModelLanguageModule = {
7679
7821
  };
7680
7822
  var ZModelSharedModule = {
7681
7823
  workspace: {
7824
+ DocumentBuilder: /* @__PURE__ */ __name((services) => new ZModelDocumentBuilder(services), "DocumentBuilder"),
7682
7825
  WorkspaceManager: /* @__PURE__ */ __name((services) => new ZModelWorkspaceManager(services), "WorkspaceManager")
7683
7826
  }
7684
7827
  };
7685
- function createZModelLanguageServices(context) {
7686
- const shared = (0, import_langium10.inject)((0, import_lsp.createDefaultSharedModule)(context), ZModelGeneratedSharedModule, ZModelSharedModule);
7687
- const ZModelLanguage = (0, import_langium10.inject)((0, import_lsp.createDefaultModule)({
7828
+ function createZModelLanguageServices(context, logToConsole = false) {
7829
+ const shared = (0, import_langium11.inject)((0, import_lsp.createDefaultSharedModule)(context), ZModelGeneratedSharedModule, ZModelSharedModule);
7830
+ const ZModelLanguage = (0, import_langium11.inject)((0, import_lsp.createDefaultModule)({
7688
7831
  shared
7689
7832
  }), ZModelGeneratedModule, ZModelLanguageModule);
7690
7833
  shared.ServiceRegistry.register(ZModelLanguage);
@@ -7692,31 +7835,39 @@ function createZModelLanguageServices(context) {
7692
7835
  if (!context.connection) {
7693
7836
  shared.workspace.ConfigurationProvider.initialized({});
7694
7837
  }
7838
+ shared.workspace.DocumentBuilder.onBuildPhase(import_langium11.DocumentState.Parsed, async (documents) => {
7839
+ for (const doc of documents) {
7840
+ if (doc.parseResult.lexerErrors.length > 0 || doc.parseResult.parserErrors.length > 0) {
7841
+ continue;
7842
+ }
7843
+ const schemaPath = (0, import_node_url3.fileURLToPath)(doc.uri.toString());
7844
+ const pluginSchemas = getPluginDocuments(doc.parseResult.value, schemaPath);
7845
+ for (const plugin of pluginSchemas) {
7846
+ const pluginDoc = await shared.workspace.LangiumDocuments.getOrCreateDocument(import_langium11.URI.file(import_node_path3.default.resolve(plugin)));
7847
+ shared.workspace.IndexManager.updateContent(pluginDoc);
7848
+ if (logToConsole) {
7849
+ console.log(`Loaded plugin model: ${plugin}`);
7850
+ }
7851
+ }
7852
+ }
7853
+ });
7695
7854
  return {
7696
7855
  shared,
7697
7856
  ZModelLanguage
7698
7857
  };
7699
7858
  }
7700
7859
  __name(createZModelLanguageServices, "createZModelLanguageServices");
7701
-
7702
- // src/index.ts
7703
- var import_meta2 = {};
7704
- function createZModelServices() {
7705
- return createZModelLanguageServices(import_node.NodeFileSystem);
7860
+ function createZModelServices(logToConsole = false) {
7861
+ return createZModelLanguageServices(import_node.NodeFileSystem, logToConsole);
7706
7862
  }
7707
7863
  __name(createZModelServices, "createZModelServices");
7708
- var DocumentLoadError = class extends Error {
7709
- static {
7710
- __name(this, "DocumentLoadError");
7711
- }
7712
- constructor(message) {
7713
- super(message);
7714
- }
7715
- };
7716
- async function loadDocument(fileName, pluginModelFiles = []) {
7717
- const { ZModelLanguage: services } = createZModelServices();
7864
+
7865
+ // src/document.ts
7866
+ var import_meta3 = {};
7867
+ async function loadDocument(fileName, additionalModelFiles = []) {
7868
+ const { ZModelLanguage: services } = createZModelServices(false);
7718
7869
  const extensions = services.LanguageMetaData.fileExtensions;
7719
- if (!extensions.includes(import_node_path2.default.extname(fileName))) {
7870
+ if (!extensions.includes(import_node_path4.default.extname(fileName))) {
7720
7871
  return {
7721
7872
  success: false,
7722
7873
  errors: [
@@ -7734,17 +7885,27 @@ async function loadDocument(fileName, pluginModelFiles = []) {
7734
7885
  warnings: []
7735
7886
  };
7736
7887
  }
7737
- const _dirname = typeof __dirname !== "undefined" ? __dirname : import_node_path2.default.dirname((0, import_node_url2.fileURLToPath)(import_meta2.url));
7738
- const stdLib = await services.shared.workspace.LangiumDocuments.getOrCreateDocument(import_langium11.URI.file(import_node_path2.default.resolve(import_node_path2.default.join(_dirname, "../res", STD_LIB_MODULE_NAME))));
7739
- const pluginDocs = await Promise.all(pluginModelFiles.map((file) => services.shared.workspace.LangiumDocuments.getOrCreateDocument(import_langium11.URI.file(import_node_path2.default.resolve(file)))));
7888
+ const _dirname = typeof __dirname !== "undefined" ? __dirname : import_node_path4.default.dirname((0, import_node_url4.fileURLToPath)(import_meta3.url));
7889
+ const stdLib = await services.shared.workspace.LangiumDocuments.getOrCreateDocument(import_langium12.URI.file(import_node_path4.default.resolve(import_node_path4.default.join(_dirname, "../res", STD_LIB_MODULE_NAME))));
7740
7890
  const langiumDocuments = services.shared.workspace.LangiumDocuments;
7741
- const document = await langiumDocuments.getOrCreateDocument(import_langium11.URI.file(import_node_path2.default.resolve(fileName)));
7891
+ const document = await langiumDocuments.getOrCreateDocument(import_langium12.URI.file(import_node_path4.default.resolve(fileName)));
7892
+ const importedURIs = await loadImports(document, langiumDocuments);
7893
+ const importedDocuments = [];
7894
+ for (const uri of importedURIs) {
7895
+ importedDocuments.push(await langiumDocuments.getOrCreateDocument(uri));
7896
+ }
7897
+ const additionalDocs = await Promise.all(additionalModelFiles.map((file) => services.shared.workspace.LangiumDocuments.getOrCreateDocument(import_langium12.URI.file(import_node_path4.default.resolve(file)))));
7742
7898
  await services.shared.workspace.DocumentBuilder.build([
7743
7899
  stdLib,
7744
- ...pluginDocs,
7745
- document
7900
+ ...additionalDocs,
7901
+ document,
7902
+ ...importedDocuments
7746
7903
  ], {
7747
- validation: true
7904
+ validation: {
7905
+ stopAfterLexingErrors: true,
7906
+ stopAfterParsingErrors: true,
7907
+ stopAfterLinkingErrors: true
7908
+ }
7748
7909
  });
7749
7910
  const diagnostics = langiumDocuments.all.flatMap((doc) => (doc.diagnostics ?? []).map((diag) => ({
7750
7911
  doc,
@@ -7754,7 +7915,7 @@ async function loadDocument(fileName, pluginModelFiles = []) {
7754
7915
  const warnings = [];
7755
7916
  if (diagnostics.length > 0) {
7756
7917
  for (const { doc, diag } of diagnostics) {
7757
- const message = `${import_node_path2.default.relative(process.cwd(), doc.uri.fsPath)}:${diag.range.start.line + 1}:${diag.range.start.character + 1} - ${diag.message}`;
7918
+ const message = `${import_node_path4.default.relative(process.cwd(), doc.uri.fsPath)}:${diag.range.start.line + 1}:${diag.range.start.character + 1} - ${diag.message}`;
7758
7919
  if (diag.severity === 1) {
7759
7920
  errors.push(message);
7760
7921
  } else {
@@ -7769,6 +7930,20 @@ async function loadDocument(fileName, pluginModelFiles = []) {
7769
7930
  warnings
7770
7931
  };
7771
7932
  }
7933
+ const model = document.parseResult.value;
7934
+ const imported = mergeImportsDeclarations(langiumDocuments, model);
7935
+ imported.forEach((model2) => {
7936
+ langiumDocuments.deleteDocument(model2.$document.uri);
7937
+ services.shared.workspace.IndexManager.remove(model2.$document.uri);
7938
+ });
7939
+ const additionalErrors = validationAfterImportMerge(model);
7940
+ if (additionalErrors.length > 0) {
7941
+ return {
7942
+ success: false,
7943
+ errors: additionalErrors,
7944
+ warnings
7945
+ };
7946
+ }
7772
7947
  return {
7773
7948
  success: true,
7774
7949
  model: document.parseResult.value,
@@ -7776,9 +7951,70 @@ async function loadDocument(fileName, pluginModelFiles = []) {
7776
7951
  };
7777
7952
  }
7778
7953
  __name(loadDocument, "loadDocument");
7954
+ async function loadImports(document, documents, uris = /* @__PURE__ */ new Set()) {
7955
+ const uriString = document.uri.toString();
7956
+ if (!uris.has(uriString)) {
7957
+ uris.add(uriString);
7958
+ const model = document.parseResult.value;
7959
+ for (const imp of model.imports) {
7960
+ const importedModel = resolveImport(documents, imp);
7961
+ if (importedModel) {
7962
+ const importedDoc = getDocument(importedModel);
7963
+ await loadImports(importedDoc, documents, uris);
7964
+ }
7965
+ }
7966
+ }
7967
+ return Array.from(uris).filter((x) => uriString != x).map((e) => import_langium12.URI.parse(e));
7968
+ }
7969
+ __name(loadImports, "loadImports");
7970
+ function mergeImportsDeclarations(documents, model) {
7971
+ const importedModels = resolveTransitiveImports(documents, model);
7972
+ const importedDeclarations = importedModels.flatMap((m) => m.declarations);
7973
+ model.declarations.push(...importedDeclarations);
7974
+ model.imports = [];
7975
+ linkContentToContainer(model);
7976
+ return importedModels;
7977
+ }
7978
+ __name(mergeImportsDeclarations, "mergeImportsDeclarations");
7979
+ function linkContentToContainer(node) {
7980
+ for (const [name, value] of Object.entries(node)) {
7981
+ if (!name.startsWith("$")) {
7982
+ if (Array.isArray(value)) {
7983
+ value.forEach((item, index) => {
7984
+ if ((0, import_langium12.isAstNode)(item)) {
7985
+ item.$container = node;
7986
+ item.$containerProperty = name;
7987
+ item.$containerIndex = index;
7988
+ }
7989
+ });
7990
+ } else if ((0, import_langium12.isAstNode)(value)) {
7991
+ value.$container = node;
7992
+ value.$containerProperty = name;
7993
+ }
7994
+ }
7995
+ }
7996
+ }
7997
+ __name(linkContentToContainer, "linkContentToContainer");
7998
+ function validationAfterImportMerge(model) {
7999
+ const errors = [];
8000
+ const dataSources = model.declarations.filter((d) => isDataSource(d));
8001
+ if (dataSources.length === 0) {
8002
+ errors.push("Validation error: schema must have a datasource declaration");
8003
+ } else {
8004
+ if (dataSources.length > 1) {
8005
+ errors.push("Validation error: multiple datasource declarations are not allowed");
8006
+ }
8007
+ }
8008
+ const decls = getDataModelAndTypeDefs(model, true);
8009
+ const authDecls = decls.filter((d) => hasAttribute(d, "@@auth"));
8010
+ if (authDecls.length > 1) {
8011
+ errors.push("Validation error: Multiple `@@auth` declarations are not allowed");
8012
+ }
8013
+ return errors;
8014
+ }
8015
+ __name(validationAfterImportMerge, "validationAfterImportMerge");
7779
8016
  // Annotate the CommonJS export names for ESM import in node:
7780
8017
  0 && (module.exports = {
7781
- DocumentLoadError,
7782
8018
  ZModelLanguageMetaData,
7783
8019
  ZModelLanguageModule,
7784
8020
  ZModelSharedModule,