Skip to content

Commit

Permalink
Release 0.4.3
Browse files Browse the repository at this point in the history
  • Loading branch information
dennemark committed Aug 8, 2024
1 parent 7f5187f commit ee5fb67
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 41 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@


## [0.4.3](https://github.com/dennemark/prisma-extension-casl/compare/0.4.2...0.4.3) (2024-08-08)


### Bug Fixes

* :bug: consider nested or and and conditions in rule relations ([7f5187f](https://github.com/dennemark/prisma-extension-casl/commit/7f5187fa48a953960cb8cea5ac5018f5c11af715))

## [0.4.2](https://github.com/dennemark/prisma-extension-casl/compare/0.4.1...0.4.2) (2024-08-08)


Expand Down
34 changes: 14 additions & 20 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1022,35 +1022,29 @@ var applyIncludeSelectQuery = (abilities, args, model) => {
};

// src/applyRuleRelationsQuery.ts
function flattenAst(ast) {
if (["and", "or"].includes(ast.operator.toLowerCase())) {
return ast.value.flatMap((childAst) => flattenAst(childAst));
} else {
return [ast];
}
}
function getRuleRelationsQuery(model, ast) {
const obj = {};
if (ast) {
if (typeof ast.value === "object") {
if (Array.isArray(ast.value)) {
ast.value.map((childAst) => {
const relation = relationFieldsByModel[model];
if (childAst.field) {
if (childAst.field in relation) {
obj[childAst.field] = {
select: getRuleRelationsQuery(relation[childAst.field].type, childAst.value)
};
} else {
obj[childAst.field] = true;
}
}
});
} else {
flattenAst(ast).map((childAst) => {
const relation = relationFieldsByModel[model];
if (ast.field) {
if (ast.field in relation) {
obj[ast.field] = {
select: getRuleRelationsQuery(relation[ast.field].type, ast.value)
if (childAst.field) {
if (childAst.field in relation) {
obj[childAst.field] = {
select: getRuleRelationsQuery(relation[childAst.field].type, childAst.value)
};
} else {
obj[ast.field] = true;
obj[childAst.field] = true;
}
}
}
});
} else {
obj[ast.field] = true;
}
Expand Down
34 changes: 14 additions & 20 deletions dist/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -997,35 +997,29 @@ var applyIncludeSelectQuery = (abilities, args, model) => {
};

// src/applyRuleRelationsQuery.ts
function flattenAst(ast) {
if (["and", "or"].includes(ast.operator.toLowerCase())) {
return ast.value.flatMap((childAst) => flattenAst(childAst));
} else {
return [ast];
}
}
function getRuleRelationsQuery(model, ast) {
const obj = {};
if (ast) {
if (typeof ast.value === "object") {
if (Array.isArray(ast.value)) {
ast.value.map((childAst) => {
const relation = relationFieldsByModel[model];
if (childAst.field) {
if (childAst.field in relation) {
obj[childAst.field] = {
select: getRuleRelationsQuery(relation[childAst.field].type, childAst.value)
};
} else {
obj[childAst.field] = true;
}
}
});
} else {
flattenAst(ast).map((childAst) => {
const relation = relationFieldsByModel[model];
if (ast.field) {
if (ast.field in relation) {
obj[ast.field] = {
select: getRuleRelationsQuery(relation[ast.field].type, ast.value)
if (childAst.field) {
if (childAst.field in relation) {
obj[childAst.field] = {
select: getRuleRelationsQuery(relation[childAst.field].type, childAst.value)
};
} else {
obj[ast.field] = true;
obj[childAst.field] = true;
}
}
}
});
} else {
obj[ast.field] = true;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "prisma-extension-casl",
"version": "0.4.2",
"version": "0.4.3",
"description": "Enforce casl abilities on prisma client ",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down

0 comments on commit ee5fb67

Please sign in to comment.