@zenstackhq/plugin-policy 3.9.5 → 3.9.6
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 +12 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +13 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -1177,6 +1177,9 @@ var PolicyHandler = class extends kysely.OperationNodeTransformer {
|
|
|
1177
1177
|
async enforcePreCreatePolicy(node, mutationModel, isManyToManyJoinTable, proceed) {
|
|
1178
1178
|
const fields = node.columns?.map((c) => c.column.name) ?? [];
|
|
1179
1179
|
const valueRows = node.values ? this.unwrapCreateValueRows(node.values, mutationModel, fields, isManyToManyJoinTable) : [[]];
|
|
1180
|
+
if (!isManyToManyJoinTable) {
|
|
1181
|
+
if (isTrueNode(this.buildPolicyFilter(mutationModel, void 0, "create"))) return;
|
|
1182
|
+
}
|
|
1180
1183
|
for (const values of valueRows) if (isManyToManyJoinTable) await this.enforcePreCreatePolicyForManyToManyJoinTable(mutationModel, fields, values.map((v) => v.node), proceed);
|
|
1181
1184
|
else await this.enforcePreCreatePolicyForOne(mutationModel, fields, values.map((v) => v.node), proceed);
|
|
1182
1185
|
}
|
|
@@ -1220,17 +1223,18 @@ var PolicyHandler = class extends kysely.OperationNodeTransformer {
|
|
|
1220
1223
|
})).rows[0]?.$condition) throw createRejectedByPolicyError(model, _zenstackhq_orm.RejectedByPolicyReason.NO_ACCESS);
|
|
1221
1224
|
}
|
|
1222
1225
|
unwrapCreateValueRows(node, model, fields, isManyToManyJoinTable) {
|
|
1223
|
-
if (kysely.ValuesNode.is(node)) return node.values.map((v) => this.unwrapCreateValueRow(v.values, model, fields, isManyToManyJoinTable));
|
|
1224
|
-
else if (kysely.PrimitiveValueListNode.is(node)) return [this.unwrapCreateValueRow(node.values, model, fields, isManyToManyJoinTable)];
|
|
1226
|
+
if (kysely.ValuesNode.is(node)) return node.values.map((v) => this.unwrapCreateValueRow(v.values, model, fields, isManyToManyJoinTable, kysely.ValueListNode.is(v)));
|
|
1227
|
+
else if (kysely.PrimitiveValueListNode.is(node)) return [this.unwrapCreateValueRow(node.values, model, fields, isManyToManyJoinTable, false)];
|
|
1225
1228
|
else (0, _zenstackhq_common_helpers.invariant)(false, `Unexpected node kind: ${node.kind} for unwrapping create values`);
|
|
1226
1229
|
}
|
|
1227
|
-
unwrapCreateValueRow(data, model, fields, isImplicitManyToManyJoinTable) {
|
|
1230
|
+
unwrapCreateValueRow(data, model, fields, isImplicitManyToManyJoinTable, itemsAreNodes) {
|
|
1228
1231
|
(0, _zenstackhq_common_helpers.invariant)(data.length === fields.length, "data length must match fields length");
|
|
1229
1232
|
const result = [];
|
|
1230
1233
|
for (let i = 0; i < data.length; i++) {
|
|
1231
1234
|
const item = data[i];
|
|
1232
|
-
if (
|
|
1233
|
-
|
|
1235
|
+
if (itemsAreNodes) {
|
|
1236
|
+
const itemNode = item;
|
|
1237
|
+
if (kysely.DefaultInsertValueNode.is(itemNode)) {
|
|
1234
1238
|
result.push({
|
|
1235
1239
|
node: kysely.ValueNode.create(null),
|
|
1236
1240
|
raw: null
|
|
@@ -1238,10 +1242,10 @@ var PolicyHandler = class extends kysely.OperationNodeTransformer {
|
|
|
1238
1242
|
continue;
|
|
1239
1243
|
}
|
|
1240
1244
|
const fieldDef = _zenstackhq_orm.QueryUtils.requireField(this.client.$schema, model, fields[i]);
|
|
1241
|
-
(0, _zenstackhq_common_helpers.invariant)(
|
|
1245
|
+
(0, _zenstackhq_common_helpers.invariant)(kysely.ValueNode.is(itemNode), `expecting a ValueNode, got ${itemNode.kind}`);
|
|
1242
1246
|
result.push({
|
|
1243
|
-
node: kysely.ValueNode.create(this.dialect.transformInput(
|
|
1244
|
-
raw:
|
|
1247
|
+
node: kysely.ValueNode.create(this.dialect.transformInput(itemNode.value, fieldDef.type, !!fieldDef.array)),
|
|
1248
|
+
raw: itemNode.value
|
|
1245
1249
|
});
|
|
1246
1250
|
} else {
|
|
1247
1251
|
let value = item;
|