@zenstackhq/plugin-policy 3.8.0 → 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 CHANGED
@@ -1301,29 +1301,26 @@ var PolicyHandler = class extends kysely.OperationNodeTransformer {
1301
1301
  return result;
1302
1302
  }
1303
1303
  resolveManyToManyJoinTable(tableName) {
1304
- for (const model of Object.values(this.client.$schema.models)) for (const field of Object.values(model.fields)) {
1305
- const m2m = _zenstackhq_orm.QueryUtils.getManyToManyRelation(this.client.$schema, model.name, field.name);
1306
- if (m2m?.joinTable === tableName) {
1307
- const sortedRecord = [{
1308
- model: model.name,
1309
- field: field.name
1310
- }, {
1311
- model: m2m.otherModel,
1312
- field: m2m.otherField
1313
- }].sort(this.manyToManySorter);
1314
- const firstIdFields = _zenstackhq_orm.QueryUtils.requireIdFields(this.client.$schema, sortedRecord[0].model);
1315
- const secondIdFields = _zenstackhq_orm.QueryUtils.requireIdFields(this.client.$schema, sortedRecord[1].model);
1316
- (0, _zenstackhq_common_helpers.invariant)(firstIdFields.length === 1 && secondIdFields.length === 1, "only single-field id is supported for implicit many-to-many join table");
1317
- return {
1318
- firstModel: sortedRecord[0].model,
1319
- firstField: sortedRecord[0].field,
1320
- firstIdField: firstIdFields[0],
1321
- secondModel: sortedRecord[1].model,
1322
- secondField: sortedRecord[1].field,
1323
- secondIdField: secondIdFields[0]
1324
- };
1325
- }
1326
- }
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
+ };
1327
1324
  }
1328
1325
  manyToManySorter(a, b) {
1329
1326
  return a.model !== b.model ? a.model.localeCompare(b.model) : a.field.localeCompare(b.field);