@zenstackhq/language 3.1.0 → 3.2.0

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
@@ -1,4 +1,4 @@
1
- import { Model, DataSource, GeneratorDecl, DataModel, TypeDef, Enum, Attribute, Expression, InvocationExpr, FunctionDecl } from './ast.cjs';
1
+ import { Model, DataSource, GeneratorDecl, DataModel, TypeDef, Enum, Attribute, Expression, InvocationExpr, FunctionDecl, Procedure } from './ast.cjs';
2
2
  import { ValidationAcceptor, Module, DeepPartial, AstNode } from 'langium';
3
3
  import { LangiumServices, PartialLangiumServices, LangiumSharedServices, DefaultSharedModuleContext } from 'langium/lsp';
4
4
 
@@ -48,6 +48,7 @@ declare class ZModelValidator {
48
48
  checkExpression(node: Expression, accept: ValidationAcceptor): void;
49
49
  checkFunctionInvocation(node: InvocationExpr, accept: ValidationAcceptor): void;
50
50
  checkFunctionDecl(node: FunctionDecl, accept: ValidationAcceptor): void;
51
+ checkProcedure(node: Procedure, accept: ValidationAcceptor): void;
51
52
  }
52
53
 
53
54
  /**
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Model, DataSource, GeneratorDecl, DataModel, TypeDef, Enum, Attribute, Expression, InvocationExpr, FunctionDecl } from './ast.js';
1
+ import { Model, DataSource, GeneratorDecl, DataModel, TypeDef, Enum, Attribute, Expression, InvocationExpr, FunctionDecl, Procedure } from './ast.js';
2
2
  import { ValidationAcceptor, Module, DeepPartial, AstNode } from 'langium';
3
3
  import { LangiumServices, PartialLangiumServices, LangiumSharedServices, DefaultSharedModuleContext } from 'langium/lsp';
4
4
 
@@ -48,6 +48,7 @@ declare class ZModelValidator {
48
48
  checkExpression(node: Expression, accept: ValidationAcceptor): void;
49
49
  checkFunctionInvocation(node: InvocationExpr, accept: ValidationAcceptor): void;
50
50
  checkFunctionDecl(node: FunctionDecl, accept: ValidationAcceptor): void;
51
+ checkProcedure(node: Procedure, accept: ValidationAcceptor): void;
51
52
  }
52
53
 
53
54
  /**
package/dist/index.js CHANGED
@@ -4022,7 +4022,8 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
4022
4022
  "terminal": {
4023
4023
  "$type": "Keyword",
4024
4024
  "value": "mutation"
4025
- }
4025
+ },
4026
+ "cardinality": "?"
4026
4027
  },
4027
4028
  {
4028
4029
  "$type": "Keyword",
@@ -4073,7 +4074,7 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
4073
4074
  "terminal": {
4074
4075
  "$type": "RuleCall",
4075
4076
  "rule": {
4076
- "$ref": "#/rules@47"
4077
+ "$ref": "#/rules@49"
4077
4078
  },
4078
4079
  "arguments": []
4079
4080
  }
@@ -4251,6 +4252,10 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
4251
4252
  "$type": "Keyword",
4252
4253
  "value": "Any"
4253
4254
  },
4255
+ {
4256
+ "$type": "Keyword",
4257
+ "value": "Void"
4258
+ },
4254
4259
  {
4255
4260
  "$type": "Keyword",
4256
4261
  "value": "Unsupported"
@@ -4861,10 +4866,26 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
4861
4866
  "$type": "Keyword",
4862
4867
  "value": "Boolean"
4863
4868
  },
4869
+ {
4870
+ "$type": "Keyword",
4871
+ "value": "BigInt"
4872
+ },
4873
+ {
4874
+ "$type": "Keyword",
4875
+ "value": "Decimal"
4876
+ },
4864
4877
  {
4865
4878
  "$type": "Keyword",
4866
4879
  "value": "DateTime"
4867
4880
  },
4881
+ {
4882
+ "$type": "Keyword",
4883
+ "value": "Json"
4884
+ },
4885
+ {
4886
+ "$type": "Keyword",
4887
+ "value": "Bytes"
4888
+ },
4868
4889
  {
4869
4890
  "$type": "Keyword",
4870
4891
  "value": "Null"
@@ -4877,6 +4898,14 @@ var ZModelGrammar = /* @__PURE__ */ __name(() => loadedZModelGrammar ?? (loadedZ
4877
4898
  "$type": "Keyword",
4878
4899
  "value": "Any"
4879
4900
  },
4901
+ {
4902
+ "$type": "Keyword",
4903
+ "value": "Void"
4904
+ },
4905
+ {
4906
+ "$type": "Keyword",
4907
+ "value": "Undefined"
4908
+ },
4880
4909
  {
4881
4910
  "$type": "Keyword",
4882
4911
  "value": "Unsupported"
@@ -5212,6 +5241,10 @@ function mapBuiltinTypeToExpressionType(type) {
5212
5241
  case "Int":
5213
5242
  case "Float":
5214
5243
  case "Null":
5244
+ case "Object":
5245
+ case "Unsupported":
5246
+ case "Void":
5247
+ case "Undefined":
5215
5248
  return type;
5216
5249
  case "BigInt":
5217
5250
  return "Int";
@@ -5220,10 +5253,6 @@ function mapBuiltinTypeToExpressionType(type) {
5220
5253
  case "Json":
5221
5254
  case "Bytes":
5222
5255
  return "Any";
5223
- case "Object":
5224
- return "Object";
5225
- case "Unsupported":
5226
- return "Unsupported";
5227
5256
  }
5228
5257
  }
5229
5258
  __name(mapBuiltinTypeToExpressionType, "mapBuiltinTypeToExpressionType");
@@ -5243,6 +5272,10 @@ function isRelationshipField(field) {
5243
5272
  return isDataModel(field.type.reference?.ref);
5244
5273
  }
5245
5274
  __name(isRelationshipField, "isRelationshipField");
5275
+ function isComputedField(field) {
5276
+ return hasAttribute(field, "@computed");
5277
+ }
5278
+ __name(isComputedField, "isComputedField");
5246
5279
  function isDelegateModel(node) {
5247
5280
  return isDataModel(node) && hasAttribute(node, "@@delegate");
5248
5281
  }
@@ -5864,24 +5897,27 @@ var AttributeApplicationValidator = class {
5864
5897
  });
5865
5898
  return;
5866
5899
  }
5867
- const kindItems = this.validatePolicyKinds(kind, [
5900
+ this.validatePolicyKinds(kind, [
5868
5901
  "read",
5869
5902
  "update",
5870
5903
  "all"
5871
5904
  ], attr, accept);
5872
5905
  const expr = attr.args[1]?.value;
5873
5906
  if (expr && AstUtils2.streamAst(expr).some((node) => isBeforeInvocation(node))) {
5874
- accept("error", `"before()" is not allowed in field-level policy rules`, {
5907
+ accept("error", `"before()" is not allowed in field-level policies`, {
5875
5908
  node: expr
5876
5909
  });
5877
5910
  }
5878
- if (kindItems.includes("update") || kindItems.includes("all")) {
5879
- const field = attr.$container;
5880
- if (isRelationshipField(field)) {
5881
- accept("error", `Field-level policy rules with "update" or "all" kind are not allowed for relation fields. Put rules on foreign-key fields instead.`, {
5882
- node: attr
5883
- });
5884
- }
5911
+ const field = attr.$container;
5912
+ if (isRelationshipField(field)) {
5913
+ accept("error", `Field-level policies are not allowed for relation fields.`, {
5914
+ node: attr
5915
+ });
5916
+ }
5917
+ if (isComputedField(field)) {
5918
+ accept("error", `Field-level policies are not allowed for computed fields.`, {
5919
+ node: attr
5920
+ });
5885
5921
  }
5886
5922
  }
5887
5923
  _checkValidate(attr, accept) {
@@ -6177,7 +6213,7 @@ function validateDuplicatedDeclarations(container, decls, accept) {
6177
6213
  group[decl.name] = group[decl.name] ?? [];
6178
6214
  group[decl.name].push(decl);
6179
6215
  return group;
6180
- }, {});
6216
+ }, /* @__PURE__ */ Object.create(null));
6181
6217
  for (const [name, decls2] of Object.entries(groupByName)) {
6182
6218
  if (decls2.length > 1) {
6183
6219
  let errorField = decls2[1];
@@ -7060,7 +7096,9 @@ var FunctionInvocationValidator = class {
7060
7096
  return true;
7061
7097
  }
7062
7098
  if (typeof argResolvedType.decl === "string") {
7063
- if (!typeAssignable(dstType, argResolvedType.decl, arg.value) || dstIsArray !== argResolvedType.array) {
7099
+ const dstScalarType = mapBuiltinTypeToExpressionType(dstType);
7100
+ const srcScalarType = mapBuiltinTypeToExpressionType(argResolvedType.decl);
7101
+ if (!typeAssignable(dstScalarType, srcScalarType, arg.value) || dstIsArray !== argResolvedType.array) {
7064
7102
  accept("error", `argument is not assignable to parameter`, {
7065
7103
  node: arg
7066
7104
  });
@@ -7289,6 +7327,30 @@ _ts_decorate2([
7289
7327
  _ts_metadata2("design:returntype", void 0)
7290
7328
  ], FunctionInvocationValidator.prototype, "_checkCheck", null);
7291
7329
 
7330
+ // src/validators/procedure-validator.ts
7331
+ var RESERVED_PROCEDURE_NAMES = /* @__PURE__ */ new Set([
7332
+ "__proto__",
7333
+ "prototype",
7334
+ "constructor"
7335
+ ]);
7336
+ var ProcedureValidator = class {
7337
+ static {
7338
+ __name(this, "ProcedureValidator");
7339
+ }
7340
+ validate(proc, accept) {
7341
+ this.validateName(proc, accept);
7342
+ proc.attributes.forEach((attr) => validateAttributeApplication(attr, accept));
7343
+ }
7344
+ validateName(proc, accept) {
7345
+ if (RESERVED_PROCEDURE_NAMES.has(proc.name)) {
7346
+ accept("error", `Procedure name "${proc.name}" is reserved`, {
7347
+ node: proc,
7348
+ property: "name"
7349
+ });
7350
+ }
7351
+ }
7352
+ };
7353
+
7292
7354
  // src/validators/schema-validator.ts
7293
7355
  var SchemaValidator = class {
7294
7356
  static {
@@ -7376,7 +7438,8 @@ function registerValidationChecks(services) {
7376
7438
  Attribute: validator.checkAttribute,
7377
7439
  Expression: validator.checkExpression,
7378
7440
  InvocationExpr: validator.checkFunctionInvocation,
7379
- FunctionDecl: validator.checkFunctionDecl
7441
+ FunctionDecl: validator.checkFunctionDecl,
7442
+ Procedure: validator.checkProcedure
7380
7443
  };
7381
7444
  registry.register(checks, validator);
7382
7445
  }
@@ -7421,6 +7484,9 @@ var ZModelValidator = class {
7421
7484
  checkFunctionDecl(node, accept) {
7422
7485
  new FunctionDeclValidator().validate(node, accept);
7423
7486
  }
7487
+ checkProcedure(node, accept) {
7488
+ new ProcedureValidator().validate(node, accept);
7489
+ }
7424
7490
  };
7425
7491
 
7426
7492
  // src/zmodel-comment-provider.ts