@zenstackhq/language 3.0.0 → 3.1.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.js CHANGED
@@ -6985,6 +6985,20 @@ var FunctionInvocationValidator = class {
6985
6985
  });
6986
6986
  }
6987
6987
  }
6988
+ if ([
6989
+ "uuid",
6990
+ "ulid",
6991
+ "cuid",
6992
+ "nanoid"
6993
+ ].includes(funcDecl.name)) {
6994
+ const formatParamIdx = funcDecl.params.findIndex((param) => param.name === "format");
6995
+ const formatArg = getLiteral(expr.args[formatParamIdx]?.value);
6996
+ if (formatArg !== void 0 && !/(?<!\\)%s/g.test(formatArg)) {
6997
+ accept("error", 'argument must include "%s"', {
6998
+ node: expr.args[formatParamIdx]
6999
+ });
7000
+ }
7001
+ }
6988
7002
  const checker = invocationCheckers.get(expr.function.$refText);
6989
7003
  if (checker) {
6990
7004
  checker.value.call(this, expr, accept);
@@ -7062,6 +7076,39 @@ var FunctionInvocationValidator = class {
7062
7076
  }
7063
7077
  return true;
7064
7078
  }
7079
+ _checkUuid(expr, accept) {
7080
+ const versionArg = expr.args[0]?.value;
7081
+ if (versionArg) {
7082
+ const version = getLiteral(versionArg);
7083
+ if (version !== void 0 && version !== 4 && version !== 7) {
7084
+ accept("error", "first argument must be 4 or 7", {
7085
+ node: expr.args[0]
7086
+ });
7087
+ }
7088
+ }
7089
+ }
7090
+ _checkCuid(expr, accept) {
7091
+ const versionArg = expr.args[0]?.value;
7092
+ if (versionArg) {
7093
+ const version = getLiteral(versionArg);
7094
+ if (version !== void 0 && version !== 1 && version !== 2) {
7095
+ accept("error", "first argument must be 1 or 2", {
7096
+ node: expr.args[0]
7097
+ });
7098
+ }
7099
+ }
7100
+ }
7101
+ _checkNanoid(expr, accept) {
7102
+ const lengthArg = expr.args[0]?.value;
7103
+ if (lengthArg) {
7104
+ const length = getLiteral(lengthArg);
7105
+ if (length !== void 0 && length <= 0) {
7106
+ accept("error", "first argument must be a positive number", {
7107
+ node: expr.args[0]
7108
+ });
7109
+ }
7110
+ }
7111
+ }
7065
7112
  _checkAuth(expr, accept) {
7066
7113
  if (!expr.$resolvedType) {
7067
7114
  accept("error", 'cannot resolve `auth()` - make sure you have a model or type with `@auth` attribute or named "User"', {
@@ -7178,6 +7225,33 @@ var FunctionInvocationValidator = class {
7178
7225
  }
7179
7226
  }
7180
7227
  };
7228
+ _ts_decorate2([
7229
+ func("uuid"),
7230
+ _ts_metadata2("design:type", Function),
7231
+ _ts_metadata2("design:paramtypes", [
7232
+ typeof InvocationExpr === "undefined" ? Object : InvocationExpr,
7233
+ typeof ValidationAcceptor === "undefined" ? Object : ValidationAcceptor
7234
+ ]),
7235
+ _ts_metadata2("design:returntype", void 0)
7236
+ ], FunctionInvocationValidator.prototype, "_checkUuid", null);
7237
+ _ts_decorate2([
7238
+ func("cuid"),
7239
+ _ts_metadata2("design:type", Function),
7240
+ _ts_metadata2("design:paramtypes", [
7241
+ typeof InvocationExpr === "undefined" ? Object : InvocationExpr,
7242
+ typeof ValidationAcceptor === "undefined" ? Object : ValidationAcceptor
7243
+ ]),
7244
+ _ts_metadata2("design:returntype", void 0)
7245
+ ], FunctionInvocationValidator.prototype, "_checkCuid", null);
7246
+ _ts_decorate2([
7247
+ func("nanoid"),
7248
+ _ts_metadata2("design:type", Function),
7249
+ _ts_metadata2("design:paramtypes", [
7250
+ typeof InvocationExpr === "undefined" ? Object : InvocationExpr,
7251
+ typeof ValidationAcceptor === "undefined" ? Object : ValidationAcceptor
7252
+ ]),
7253
+ _ts_metadata2("design:returntype", void 0)
7254
+ ], FunctionInvocationValidator.prototype, "_checkNanoid", null);
7181
7255
  _ts_decorate2([
7182
7256
  func("auth"),
7183
7257
  _ts_metadata2("design:type", Function),