@zenstackhq/plugin-policy 3.3.0-beta.3 → 3.3.0-beta.5

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
@@ -311,6 +311,7 @@ var ExpressionTransformer = class {
311
311
  }
312
312
  client;
313
313
  dialect;
314
+ eb = (0, import_kysely2.expressionBuilder)();
314
315
  constructor(client) {
315
316
  this.client = client;
316
317
  this.dialect = (0, import_orm3.getCrudDialect)(this.schema, this.clientOptions);
@@ -335,13 +336,15 @@ var ExpressionTransformer = class {
335
336
  if (!handler) {
336
337
  throw new Error(`Unsupported expression kind: ${expression.kind}`);
337
338
  }
338
- return handler.value.call(this, expression, context);
339
+ const result = handler.value.call(this, expression, context);
340
+ (0, import_common_helpers2.invariant)("kind" in result, `expression handler must return an OperationNode: transforming ${expression.kind}`);
341
+ return result;
339
342
  }
340
343
  _literal(expr2) {
341
344
  return this.transformValue(expr2.value, typeof expr2.value === "string" ? "String" : typeof expr2.value === "boolean" ? "Boolean" : "Int");
342
345
  }
343
346
  _array(expr2, context) {
344
- return import_kysely2.ValueListNode.create(expr2.items.map((item) => this.transform(item, context)));
347
+ return this.dialect.buildArrayValue(expr2.items.map((item) => new import_kysely2.ExpressionWrapper(this.transform(item, context))), expr2.type).toOperationNode();
345
348
  }
346
349
  _field(expr2, context) {
347
350
  if (context.contextValue) {
@@ -628,9 +631,11 @@ var ExpressionTransformer = class {
628
631
  return trueNode(this.dialect);
629
632
  } else if (value === false) {
630
633
  return falseNode(this.dialect);
634
+ } else if (Array.isArray(value)) {
635
+ return this.dialect.buildArrayValue(value.map((v) => new import_kysely2.ExpressionWrapper(this.transformValue(v, type))), type).toOperationNode();
631
636
  } else {
632
637
  const transformed = this.dialect.transformInput(value, type, false) ?? null;
633
- if (!Array.isArray(transformed)) {
638
+ if (typeof transformed !== "string") {
634
639
  return import_kysely2.ValueNode.createImmediate(transformed);
635
640
  } else {
636
641
  return import_kysely2.ValueNode.create(transformed);
@@ -654,8 +659,7 @@ var ExpressionTransformer = class {
654
659
  if (!func) {
655
660
  throw createUnsupportedError(`Function not implemented: ${expr2.function}`);
656
661
  }
657
- const eb = (0, import_kysely2.expressionBuilder)();
658
- return func(eb, (expr2.args ?? []).map((arg) => this.transformCallArg(eb, arg, context)), {
662
+ return func(this.eb, (expr2.args ?? []).map((arg) => this.transformCallArg(arg, context)), {
659
663
  client: this.client,
660
664
  dialect: this.dialect,
661
665
  model: context.modelOrType,
@@ -675,21 +679,12 @@ var ExpressionTransformer = class {
675
679
  }
676
680
  return func;
677
681
  }
678
- transformCallArg(eb, arg, context) {
679
- if (import_schema3.ExpressionUtils.isLiteral(arg)) {
680
- return eb.val(arg.value);
681
- }
682
+ transformCallArg(arg, context) {
682
683
  if (import_schema3.ExpressionUtils.isField(arg)) {
683
- return eb.ref(arg.field);
684
- }
685
- if (import_schema3.ExpressionUtils.isCall(arg)) {
686
- return this.transformCall(arg, context);
687
- }
688
- if (this.isAuthMember(arg)) {
689
- const valNode = this.valueMemberAccess(this.auth, arg, this.authType);
690
- return valNode ? eb.val(valNode.value) : eb.val(null);
684
+ return this.eb.ref(arg.field);
685
+ } else {
686
+ return new import_kysely2.ExpressionWrapper(this.transform(arg, context));
691
687
  }
692
- throw createUnsupportedError(`Unsupported argument expression: ${arg.kind}`);
693
688
  }
694
689
  _member(expr2, context) {
695
690
  if (import_schema3.ExpressionUtils.isBinding(expr2.receiver)) {
@@ -1584,8 +1579,9 @@ var PolicyHandler = class extends import_kysely3.OperationNodeTransformer {
1584
1579
  value = this.dialect.transformInput(item, fieldDef.type, !!fieldDef.array);
1585
1580
  }
1586
1581
  if (Array.isArray(value)) {
1582
+ const fieldDef = import_orm4.QueryUtils.requireField(this.client.$schema, model, fields[i]);
1587
1583
  result.push({
1588
- node: this.dialect.buildArrayLiteralSQL(value).toOperationNode(),
1584
+ node: this.dialect.buildArrayValue(value, fieldDef.type).toOperationNode(),
1589
1585
  raw: value
1590
1586
  });
1591
1587
  } else {