@zenstackhq/language 3.7.1 → 3.8.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -4184,6 +4184,7 @@ var AttributeApplicationValidator = class {
4184
4184
  if (require_ast.isDataField(targetDecl) && !isValidAttributeTarget(decl, targetDecl)) accept("error", `attribute "${decl.name}" cannot be used on this type of field`, { node: attr });
4185
4185
  this.checkDeprecation(attr, accept);
4186
4186
  this.checkDuplicatedAttributes(attr, accept, contextDataModel);
4187
+ this.checkOnceInModel(attr, accept);
4187
4188
  const filledParams = /* @__PURE__ */ new Set();
4188
4189
  for (const arg of attr.args) {
4189
4190
  let paramDecl;
@@ -4229,6 +4230,15 @@ var AttributeApplicationValidator = class {
4229
4230
  if (!attrDecl?.attributes.some((a) => a.decl.ref?.name === "@@@once")) return;
4230
4231
  if ((contextDataModel ? require_utils.getAllAttributes(contextDataModel) : attr.$container.attributes).filter((a) => a.decl.ref === attrDecl && a !== attr).length > 0) accept("error", `Attribute "${attrDecl.name}" can only be applied once`, { node: attr });
4231
4232
  }
4233
+ checkOnceInModel(attr, accept) {
4234
+ const attrDecl = attr.decl.ref;
4235
+ if (!attrDecl?.attributes.some((a) => a.decl.ref?.name === "@@@onceInModel")) return;
4236
+ const field = attr.$container;
4237
+ if (!require_ast.isDataField(field)) return;
4238
+ const dataModel = require_utils.getContainingDataModel(attr);
4239
+ if (!dataModel) return;
4240
+ if (require_utils.getAllFields(dataModel).filter((f) => f.attributes.some((a) => a.decl.ref === attrDecl)).length > 1) accept("error", `Attribute "${attrDecl.name}" can only be applied to one field per model`, { node: attr });
4241
+ }
4232
4242
  _checkModelLevelPolicy(attr, accept) {
4233
4243
  const kind = require_utils.getStringLiteral(attr.args[0]?.value);
4234
4244
  if (!kind) {