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