Skip to content

Commit

Permalink
Release 1.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
dennemark committed Nov 29, 2024
1 parent 3fdf5f6 commit 8410850
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 17 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@


## [1.1.3](https://github.com/dennemark/prisma-extension-casl/compare/1.1.2...1.1.3) (2024-11-29)

### Bug Fixes

* :bug: correct return of empty values ([2effde5](https://github.com/dennemark/prisma-extension-casl/commit/2effde52f184a70c50031fe74e7a04d4f94e9dfa))
## [1.0.2](https://github.com/dennemark/prisma-extension-casl/compare/1.1.2...1.1.3) (2024-11-28)

### Bug Fixes

* :bug: deep merge nested rule relations ([ecd8741](https://github.com/dennemark/prisma-extension-casl/commit/ecd87416b69ed3c477629bbaf891e182070283f5))

## [1.1.2](https://github.com/dennemark/prisma-extension-casl/compare/1.1.1...1.1.2) (2024-11-28)

### Bug Fixes
Expand Down
14 changes: 6 additions & 8 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -861,9 +861,9 @@ var caslOperationDict = {
findMany: { action: "read", dataQuery: false, whereQuery: true, includeSelectQuery: true },
findUnique: { action: "read", dataQuery: false, whereQuery: true, includeSelectQuery: true },
findUniqueOrThrow: { action: "read", dataQuery: false, whereQuery: true, includeSelectQuery: true },
aggregate: { action: "read", dataQuery: false, whereQuery: true, includeSelectQuery: false, operationFields: ["_min", "_max", "_avg", "_count", "_sum"] },
aggregate: { action: "read", dataQuery: false, whereQuery: true, includeSelectQuery: false },
count: { action: "read", dataQuery: false, whereQuery: true, includeSelectQuery: false },
groupBy: { action: "read", dataQuery: false, whereQuery: true, includeSelectQuery: false, operationFields: ["_min", "_max", "_avg", "_count", "_sum"] },
groupBy: { action: "read", dataQuery: false, whereQuery: true, includeSelectQuery: false },
update: { action: "update", dataQuery: true, whereQuery: true, includeSelectQuery: true },
updateMany: { action: "update", dataQuery: true, whereQuery: true, includeSelectQuery: false },
delete: { action: "delete", dataQuery: false, whereQuery: true, includeSelectQuery: true },
Expand Down Expand Up @@ -1399,7 +1399,7 @@ function filterQueryResults(result, mask, creationTree, abilities, model, operat
if (!prismaModel) {
throw new Error(`Model ${model} does not exist on Prisma Client`);
}
const operationFields = caslOperationDict[operation].operationFields;
const operationFields = ["_min", "_max", "_avg", "_count", "_sum"];
const filterPermittedFields = (entry) => {
if (!entry) {
return null;
Expand Down Expand Up @@ -1452,15 +1452,12 @@ function filterQueryResults(result, mask, creationTree, abilities, model, operat
if (relationField) {
const nestedCreationTree = creationTree && field in creationTree.children ? creationTree.children[field] : void 0;
const res = filterQueryResults(entry[field], mask?.[field], nestedCreationTree, abilities, relationField.type, operation);
entry[field] = Array.isArray(res) ? res.length > 0 ? res : null : res;
entry[field] = res;
}
if (!permittedFields.includes(field) && !relationField || mask?.[field] === true) {
delete entry[field];
} else if (relationField) {
hasKeys = true;
if (entry[field] === null) {
delete entry[field];
}
} else {
hasKeys = true;
}
Expand All @@ -1484,6 +1481,7 @@ function useCaslAbilities(getAbilityFactory, opts) {
const [fluentRelationModel, fluentRelationField] = (fluentModel !== model ? Object.entries(relationFieldsByModel[model]).find(([k2, v4]) => v4.type === fluentModel) : void 0) ?? [void 0, void 0];
const transaction = rest.__internalParams.transaction;
const debug = (process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") && args.debugCasl;
const debugAllErrors = args.debugCasl;
delete args.debugCasl;
const perf = debug ? performance : void 0;
const logger = debug ? console : void 0;
Expand All @@ -1510,7 +1508,7 @@ function useCaslAbilities(getAbilityFactory, opts) {
try {
return applyCaslToQuery(operation, args, abilities, model, opts?.permissionField ? true : false);
} catch (e4) {
if (args.debugCasl || caslOperationDict[operation].action !== "read") {
if (debugAllErrors || caslOperationDict[operation].action !== "read") {
throw e4;
}
}
Expand Down
14 changes: 6 additions & 8 deletions dist/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -836,9 +836,9 @@ var caslOperationDict = {
findMany: { action: "read", dataQuery: false, whereQuery: true, includeSelectQuery: true },
findUnique: { action: "read", dataQuery: false, whereQuery: true, includeSelectQuery: true },
findUniqueOrThrow: { action: "read", dataQuery: false, whereQuery: true, includeSelectQuery: true },
aggregate: { action: "read", dataQuery: false, whereQuery: true, includeSelectQuery: false, operationFields: ["_min", "_max", "_avg", "_count", "_sum"] },
aggregate: { action: "read", dataQuery: false, whereQuery: true, includeSelectQuery: false },
count: { action: "read", dataQuery: false, whereQuery: true, includeSelectQuery: false },
groupBy: { action: "read", dataQuery: false, whereQuery: true, includeSelectQuery: false, operationFields: ["_min", "_max", "_avg", "_count", "_sum"] },
groupBy: { action: "read", dataQuery: false, whereQuery: true, includeSelectQuery: false },
update: { action: "update", dataQuery: true, whereQuery: true, includeSelectQuery: true },
updateMany: { action: "update", dataQuery: true, whereQuery: true, includeSelectQuery: false },
delete: { action: "delete", dataQuery: false, whereQuery: true, includeSelectQuery: true },
Expand Down Expand Up @@ -1374,7 +1374,7 @@ function filterQueryResults(result, mask, creationTree, abilities, model, operat
if (!prismaModel) {
throw new Error(`Model ${model} does not exist on Prisma Client`);
}
const operationFields = caslOperationDict[operation].operationFields;
const operationFields = ["_min", "_max", "_avg", "_count", "_sum"];
const filterPermittedFields = (entry) => {
if (!entry) {
return null;
Expand Down Expand Up @@ -1427,15 +1427,12 @@ function filterQueryResults(result, mask, creationTree, abilities, model, operat
if (relationField) {
const nestedCreationTree = creationTree && field in creationTree.children ? creationTree.children[field] : void 0;
const res = filterQueryResults(entry[field], mask?.[field], nestedCreationTree, abilities, relationField.type, operation);
entry[field] = Array.isArray(res) ? res.length > 0 ? res : null : res;
entry[field] = res;
}
if (!permittedFields.includes(field) && !relationField || mask?.[field] === true) {
delete entry[field];
} else if (relationField) {
hasKeys = true;
if (entry[field] === null) {
delete entry[field];
}
} else {
hasKeys = true;
}
Expand All @@ -1459,6 +1456,7 @@ function useCaslAbilities(getAbilityFactory, opts) {
const [fluentRelationModel, fluentRelationField] = (fluentModel !== model ? Object.entries(relationFieldsByModel[model]).find(([k2, v4]) => v4.type === fluentModel) : void 0) ?? [void 0, void 0];
const transaction = rest.__internalParams.transaction;
const debug = (process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") && args.debugCasl;
const debugAllErrors = args.debugCasl;
delete args.debugCasl;
const perf = debug ? performance : void 0;
const logger = debug ? console : void 0;
Expand All @@ -1485,7 +1483,7 @@ function useCaslAbilities(getAbilityFactory, opts) {
try {
return applyCaslToQuery(operation, args, abilities, model, opts?.permissionField ? true : false);
} catch (e4) {
if (args.debugCasl || caslOperationDict[operation].action !== "read") {
if (debugAllErrors || caslOperationDict[operation].action !== "read") {
throw e4;
}
}
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": "1.1.2",
"version": "1.1.3",
"description": "Enforce casl abilities on prisma client ",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down

0 comments on commit 8410850

Please sign in to comment.