@zenstackhq/plugin-policy 3.8.0-beta.3 → 3.8.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.mjs CHANGED
@@ -285,7 +285,11 @@ var ExpressionTransformer = class {
285
285
  const right = this.transform(normalizedRight, context);
286
286
  if (op === "in") if (this.isNullNode(left)) return this.transformValue(false, "Boolean");
287
287
  else if (ValueListNode.is(right)) return BinaryOperationNode.create(left, OperatorNode.create("in"), right);
288
- else return BinaryOperationNode.create(left, OperatorNode.create("="), FunctionNode.create("any", [right]));
288
+ else {
289
+ const leftFieldDef = this.getFieldDefFromFieldRef(normalizedLeft, context);
290
+ const comparand = leftFieldDef && QueryUtils.isEnum(this.schema, leftFieldDef.type) ? this.dialect.castText(new ExpressionWrapper(left)).toOperationNode() : left;
291
+ return BinaryOperationNode.create(comparand, OperatorNode.create("="), FunctionNode.create("any", [right]));
292
+ }
289
293
  if (this.isNullNode(right)) return this.transformNullCheck(left, expr.op);
290
294
  else if (this.isNullNode(left)) return this.transformNullCheck(right, expr.op);
291
295
  else {
@@ -1296,29 +1300,26 @@ var PolicyHandler = class extends OperationNodeTransformer {
1296
1300
  return result;
1297
1301
  }
1298
1302
  resolveManyToManyJoinTable(tableName) {
1299
- for (const model of Object.values(this.client.$schema.models)) for (const field of Object.values(model.fields)) {
1300
- const m2m = QueryUtils.getManyToManyRelation(this.client.$schema, model.name, field.name);
1301
- if (m2m?.joinTable === tableName) {
1302
- const sortedRecord = [{
1303
- model: model.name,
1304
- field: field.name
1305
- }, {
1306
- model: m2m.otherModel,
1307
- field: m2m.otherField
1308
- }].sort(this.manyToManySorter);
1309
- const firstIdFields = QueryUtils.requireIdFields(this.client.$schema, sortedRecord[0].model);
1310
- const secondIdFields = QueryUtils.requireIdFields(this.client.$schema, sortedRecord[1].model);
1311
- invariant(firstIdFields.length === 1 && secondIdFields.length === 1, "only single-field id is supported for implicit many-to-many join table");
1312
- return {
1313
- firstModel: sortedRecord[0].model,
1314
- firstField: sortedRecord[0].field,
1315
- firstIdField: firstIdFields[0],
1316
- secondModel: sortedRecord[1].model,
1317
- secondField: sortedRecord[1].field,
1318
- secondIdField: secondIdFields[0]
1319
- };
1320
- }
1321
- }
1303
+ const endpoints = QueryUtils.getManyToManyJoinTable(this.client.$schema, tableName);
1304
+ if (!endpoints) return;
1305
+ const sortedRecord = [{
1306
+ model: endpoints.model,
1307
+ field: endpoints.field
1308
+ }, {
1309
+ model: endpoints.otherModel,
1310
+ field: endpoints.otherField
1311
+ }].sort(this.manyToManySorter);
1312
+ const firstIdFields = QueryUtils.requireIdFields(this.client.$schema, sortedRecord[0].model);
1313
+ const secondIdFields = QueryUtils.requireIdFields(this.client.$schema, sortedRecord[1].model);
1314
+ invariant(firstIdFields.length === 1 && secondIdFields.length === 1, "only single-field id is supported for implicit many-to-many join table");
1315
+ return {
1316
+ firstModel: sortedRecord[0].model,
1317
+ firstField: sortedRecord[0].field,
1318
+ firstIdField: firstIdFields[0],
1319
+ secondModel: sortedRecord[1].model,
1320
+ secondField: sortedRecord[1].field,
1321
+ secondIdField: secondIdFields[0]
1322
+ };
1322
1323
  }
1323
1324
  manyToManySorter(a, b) {
1324
1325
  return a.model !== b.model ? a.model.localeCompare(b.model) : a.field.localeCompare(b.field);