@zenstackhq/language 3.0.0-beta.6 → 3.0.0-beta.7

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.d.cts CHANGED
@@ -21,7 +21,6 @@ declare const ZModelLanguageMetaData: {
21
21
  declare class ZModelValidator {
22
22
  protected readonly services: ZModelServices;
23
23
  constructor(services: ZModelServices);
24
- private shouldCheck;
25
24
  checkModel(node: Model, accept: ValidationAcceptor): void;
26
25
  checkDataSource(node: DataSource, accept: ValidationAcceptor): void;
27
26
  checkDataModel(node: DataModel, accept: ValidationAcceptor): void;
package/dist/index.d.ts CHANGED
@@ -21,7 +21,6 @@ declare const ZModelLanguageMetaData: {
21
21
  declare class ZModelValidator {
22
22
  protected readonly services: ZModelServices;
23
23
  constructor(services: ZModelServices);
24
- private shouldCheck;
25
24
  checkModel(node: Model, accept: ValidationAcceptor): void;
26
25
  checkDataSource(node: DataSource, accept: ValidationAcceptor): void;
27
26
  checkDataModel(node: DataModel, accept: ValidationAcceptor): void;
package/dist/index.js CHANGED
@@ -5109,7 +5109,6 @@ import { AstUtils as AstUtils2 } from "langium";
5109
5109
  import pluralize from "pluralize";
5110
5110
 
5111
5111
  // src/utils.ts
5112
- import { invariant } from "@zenstackhq/common-helpers";
5113
5112
  import { AstUtils, URI } from "langium";
5114
5113
  import fs from "fs";
5115
5114
  import path from "path";
@@ -5214,7 +5213,7 @@ function getRecursiveBases(decl, includeDelegate = true, seen = /* @__PURE__ */
5214
5213
  }
5215
5214
  seen.add(decl);
5216
5215
  decl.mixins.forEach((mixin) => {
5217
- const baseDecl = mixin.ref;
5216
+ const baseDecl = decl.$container.declarations.find((d) => isTypeDef(d) && d.name === mixin.$refText);
5218
5217
  if (baseDecl) {
5219
5218
  if (!includeDelegate && isDelegateModel(baseDecl)) {
5220
5219
  return;
@@ -5489,12 +5488,14 @@ function getAllFields(decl, includeIgnored = false, seen = /* @__PURE__ */ new S
5489
5488
  seen.add(decl);
5490
5489
  const fields = [];
5491
5490
  for (const mixin of decl.mixins) {
5492
- invariant(mixin.ref, `Mixin ${mixin.$refText} is not resolved`);
5493
- fields.push(...getAllFields(mixin.ref, includeIgnored, seen));
5491
+ if (mixin.ref) {
5492
+ fields.push(...getAllFields(mixin.ref, includeIgnored, seen));
5493
+ }
5494
5494
  }
5495
5495
  if (isDataModel(decl) && decl.baseModel) {
5496
- invariant(decl.baseModel.ref, `Base model ${decl.baseModel.$refText} is not resolved`);
5497
- fields.push(...getAllFields(decl.baseModel.ref, includeIgnored, seen));
5496
+ if (decl.baseModel.ref) {
5497
+ fields.push(...getAllFields(decl.baseModel.ref, includeIgnored, seen));
5498
+ }
5498
5499
  }
5499
5500
  fields.push(...decl.fields.filter((f) => includeIgnored || !hasAttribute(f, "@ignore")));
5500
5501
  return fields;
@@ -5507,12 +5508,14 @@ function getAllAttributes(decl, seen = /* @__PURE__ */ new Set()) {
5507
5508
  seen.add(decl);
5508
5509
  const attributes = [];
5509
5510
  for (const mixin of decl.mixins) {
5510
- invariant(mixin.ref, `Mixin ${mixin.$refText} is not resolved`);
5511
- attributes.push(...getAllAttributes(mixin.ref, seen));
5511
+ if (mixin.ref) {
5512
+ attributes.push(...getAllAttributes(mixin.ref, seen));
5513
+ }
5512
5514
  }
5513
5515
  if (isDataModel(decl) && decl.baseModel) {
5514
- invariant(decl.baseModel.ref, `Base model ${decl.baseModel.$refText} is not resolved`);
5515
- attributes.push(...getAllAttributes(decl.baseModel.ref, seen));
5516
+ if (decl.baseModel.ref) {
5517
+ attributes.push(...getAllAttributes(decl.baseModel.ref, seen));
5518
+ }
5516
5519
  }
5517
5520
  attributes.push(...decl.attributes);
5518
5521
  return attributes;
@@ -5961,7 +5964,7 @@ var AttributeValidator = class {
5961
5964
  };
5962
5965
 
5963
5966
  // src/validators/datamodel-validator.ts
5964
- import { invariant as invariant2 } from "@zenstackhq/common-helpers";
5967
+ import { invariant } from "@zenstackhq/common-helpers";
5965
5968
  import { AstUtils as AstUtils3 } from "langium";
5966
5969
 
5967
5970
  // src/validators/common.ts
@@ -6332,7 +6335,7 @@ var DataModelValidator = class {
6332
6335
  if (!model.baseModel) {
6333
6336
  return;
6334
6337
  }
6335
- invariant2(model.baseModel.ref, "baseModel must be resolved");
6338
+ invariant(model.baseModel.ref, "baseModel must be resolved");
6336
6339
  if (!isDelegateModel(model.baseModel.ref)) {
6337
6340
  accept("error", `Model ${model.baseModel.$refText} cannot be extended because it's not a delegate model`, {
6338
6341
  node: model,
@@ -6354,7 +6357,7 @@ var DataModelValidator = class {
6354
6357
  }
6355
6358
  seen.push(current);
6356
6359
  if (current.baseModel) {
6357
- invariant2(current.baseModel.ref, "baseModel must be resolved");
6360
+ invariant(current.baseModel.ref, "baseModel must be resolved");
6358
6361
  todo.push(current.baseModel.ref);
6359
6362
  }
6360
6363
  }
@@ -6976,44 +6979,53 @@ var ZModelValidator = class {
6976
6979
  constructor(services) {
6977
6980
  this.services = services;
6978
6981
  }
6979
- shouldCheck(node) {
6980
- let doc;
6981
- let currNode = node;
6982
- while (currNode) {
6983
- if (currNode.$document) {
6984
- doc = currNode.$document;
6985
- break;
6986
- }
6987
- currNode = currNode.$container;
6988
- }
6989
- return doc?.parseResult.lexerErrors.length === 0 && doc?.parseResult.parserErrors.length === 0;
6990
- }
6991
6982
  checkModel(node, accept) {
6992
- this.shouldCheck(node) && new SchemaValidator(this.services.shared.workspace.LangiumDocuments).validate(node, accept);
6983
+ new SchemaValidator(this.services.shared.workspace.LangiumDocuments).validate(node, accept);
6993
6984
  }
6994
6985
  checkDataSource(node, accept) {
6995
- this.shouldCheck(node) && new DataSourceValidator().validate(node, accept);
6986
+ new DataSourceValidator().validate(node, accept);
6996
6987
  }
6997
6988
  checkDataModel(node, accept) {
6998
- this.shouldCheck(node) && new DataModelValidator().validate(node, accept);
6989
+ new DataModelValidator().validate(node, accept);
6999
6990
  }
7000
6991
  checkTypeDef(node, accept) {
7001
- this.shouldCheck(node) && new TypeDefValidator().validate(node, accept);
6992
+ new TypeDefValidator().validate(node, accept);
7002
6993
  }
7003
6994
  checkEnum(node, accept) {
7004
- this.shouldCheck(node) && new EnumValidator().validate(node, accept);
6995
+ new EnumValidator().validate(node, accept);
7005
6996
  }
7006
6997
  checkAttribute(node, accept) {
7007
- this.shouldCheck(node) && new AttributeValidator().validate(node, accept);
6998
+ new AttributeValidator().validate(node, accept);
7008
6999
  }
7009
7000
  checkExpression(node, accept) {
7010
- this.shouldCheck(node) && new ExpressionValidator().validate(node, accept);
7001
+ new ExpressionValidator().validate(node, accept);
7011
7002
  }
7012
7003
  checkFunctionInvocation(node, accept) {
7013
- this.shouldCheck(node) && new FunctionInvocationValidator().validate(node, accept);
7004
+ new FunctionInvocationValidator().validate(node, accept);
7014
7005
  }
7015
7006
  checkFunctionDecl(node, accept) {
7016
- this.shouldCheck(node) && new FunctionDeclValidator().validate(node, accept);
7007
+ new FunctionDeclValidator().validate(node, accept);
7008
+ }
7009
+ };
7010
+
7011
+ // src/zmodel-document-builder.ts
7012
+ import { DefaultDocumentBuilder } from "langium";
7013
+ var ZModelDocumentBuilder = class extends DefaultDocumentBuilder {
7014
+ static {
7015
+ __name(this, "ZModelDocumentBuilder");
7016
+ }
7017
+ buildDocuments(documents, options, cancelToken) {
7018
+ return super.buildDocuments(documents, {
7019
+ ...options,
7020
+ validation: (
7021
+ // force overriding validation options
7022
+ options.validation === false || options.validation === void 0 ? options.validation : {
7023
+ stopAfterLexingErrors: true,
7024
+ stopAfterParsingErrors: true,
7025
+ stopAfterLinkingErrors: true
7026
+ }
7027
+ )
7028
+ }, cancelToken);
7017
7029
  }
7018
7030
  };
7019
7031
 
@@ -7669,6 +7681,7 @@ var ZModelLanguageModule = {
7669
7681
  };
7670
7682
  var ZModelSharedModule = {
7671
7683
  workspace: {
7684
+ DocumentBuilder: /* @__PURE__ */ __name((services) => new ZModelDocumentBuilder(services), "DocumentBuilder"),
7672
7685
  WorkspaceManager: /* @__PURE__ */ __name((services) => new ZModelWorkspaceManager(services), "WorkspaceManager")
7673
7686
  }
7674
7687
  };