@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.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CRUD, KyselyUtils, ORMError, ORMErrorReason, QueryUtils, RejectedByPolicyReason, SchemaUtils, getCrudDialect } from "@zenstackhq/orm";
|
|
2
2
|
import { invariant } from "@zenstackhq/common-helpers";
|
|
3
|
-
import { AliasNode, AndNode, BinaryOperationNode, ColumnNode, DeleteQueryNode, ExpressionWrapper, FromNode, FunctionNode, IdentifierNode, InsertQueryNode, JoinNode, OperationNodeTransformer, OperatorNode, OrNode, ParensNode, PrimitiveValueListNode, RawNode, ReferenceNode, ReturningNode, SelectAllNode, SelectQueryNode, SelectionNode, TableNode, UnaryOperationNode, UpdateQueryNode, ValueListNode, ValueNode, ValuesNode, WhereNode, expressionBuilder, sql } from "kysely";
|
|
3
|
+
import { AliasNode, AndNode, BinaryOperationNode, ColumnNode, DefaultInsertValueNode, DeleteQueryNode, ExpressionWrapper, FromNode, FunctionNode, IdentifierNode, InsertQueryNode, JoinNode, OperationNodeTransformer, OperatorNode, OrNode, ParensNode, PrimitiveValueListNode, RawNode, ReferenceNode, ReturningNode, SelectAllNode, SelectQueryNode, SelectionNode, TableNode, UnaryOperationNode, UpdateQueryNode, ValueListNode, ValueNode, ValuesNode, WhereNode, expressionBuilder, sql } from "kysely";
|
|
4
4
|
import { ExpressionUtils } from "@zenstackhq/orm/schema";
|
|
5
5
|
import { match } from "ts-pattern";
|
|
6
6
|
//#region src/column-collector.ts
|
|
@@ -1176,6 +1176,9 @@ var PolicyHandler = class extends OperationNodeTransformer {
|
|
|
1176
1176
|
async enforcePreCreatePolicy(node, mutationModel, isManyToManyJoinTable, proceed) {
|
|
1177
1177
|
const fields = node.columns?.map((c) => c.column.name) ?? [];
|
|
1178
1178
|
const valueRows = node.values ? this.unwrapCreateValueRows(node.values, mutationModel, fields, isManyToManyJoinTable) : [[]];
|
|
1179
|
+
if (!isManyToManyJoinTable) {
|
|
1180
|
+
if (isTrueNode(this.buildPolicyFilter(mutationModel, void 0, "create"))) return;
|
|
1181
|
+
}
|
|
1179
1182
|
for (const values of valueRows) if (isManyToManyJoinTable) await this.enforcePreCreatePolicyForManyToManyJoinTable(mutationModel, fields, values.map((v) => v.node), proceed);
|
|
1180
1183
|
else await this.enforcePreCreatePolicyForOne(mutationModel, fields, values.map((v) => v.node), proceed);
|
|
1181
1184
|
}
|
|
@@ -1219,17 +1222,18 @@ var PolicyHandler = class extends OperationNodeTransformer {
|
|
|
1219
1222
|
})).rows[0]?.$condition) throw createRejectedByPolicyError(model, RejectedByPolicyReason.NO_ACCESS);
|
|
1220
1223
|
}
|
|
1221
1224
|
unwrapCreateValueRows(node, model, fields, isManyToManyJoinTable) {
|
|
1222
|
-
if (ValuesNode.is(node)) return node.values.map((v) => this.unwrapCreateValueRow(v.values, model, fields, isManyToManyJoinTable));
|
|
1223
|
-
else if (PrimitiveValueListNode.is(node)) return [this.unwrapCreateValueRow(node.values, model, fields, isManyToManyJoinTable)];
|
|
1225
|
+
if (ValuesNode.is(node)) return node.values.map((v) => this.unwrapCreateValueRow(v.values, model, fields, isManyToManyJoinTable, ValueListNode.is(v)));
|
|
1226
|
+
else if (PrimitiveValueListNode.is(node)) return [this.unwrapCreateValueRow(node.values, model, fields, isManyToManyJoinTable, false)];
|
|
1224
1227
|
else invariant(false, `Unexpected node kind: ${node.kind} for unwrapping create values`);
|
|
1225
1228
|
}
|
|
1226
|
-
unwrapCreateValueRow(data, model, fields, isImplicitManyToManyJoinTable) {
|
|
1229
|
+
unwrapCreateValueRow(data, model, fields, isImplicitManyToManyJoinTable, itemsAreNodes) {
|
|
1227
1230
|
invariant(data.length === fields.length, "data length must match fields length");
|
|
1228
1231
|
const result = [];
|
|
1229
1232
|
for (let i = 0; i < data.length; i++) {
|
|
1230
1233
|
const item = data[i];
|
|
1231
|
-
if (
|
|
1232
|
-
|
|
1234
|
+
if (itemsAreNodes) {
|
|
1235
|
+
const itemNode = item;
|
|
1236
|
+
if (DefaultInsertValueNode.is(itemNode)) {
|
|
1233
1237
|
result.push({
|
|
1234
1238
|
node: ValueNode.create(null),
|
|
1235
1239
|
raw: null
|
|
@@ -1237,10 +1241,10 @@ var PolicyHandler = class extends OperationNodeTransformer {
|
|
|
1237
1241
|
continue;
|
|
1238
1242
|
}
|
|
1239
1243
|
const fieldDef = QueryUtils.requireField(this.client.$schema, model, fields[i]);
|
|
1240
|
-
invariant(
|
|
1244
|
+
invariant(ValueNode.is(itemNode), `expecting a ValueNode, got ${itemNode.kind}`);
|
|
1241
1245
|
result.push({
|
|
1242
|
-
node: ValueNode.create(this.dialect.transformInput(
|
|
1243
|
-
raw:
|
|
1246
|
+
node: ValueNode.create(this.dialect.transformInput(itemNode.value, fieldDef.type, !!fieldDef.array)),
|
|
1247
|
+
raw: itemNode.value
|
|
1244
1248
|
});
|
|
1245
1249
|
} else {
|
|
1246
1250
|
let value = item;
|