From 84108500b9834625364840e7a1ababb9da3fc89d Mon Sep 17 00:00:00 2001 From: dennemark Date: Fri, 29 Nov 2024 18:12:10 +0100 Subject: [PATCH] Release 1.1.3 --- CHANGELOG.md | 11 +++++++++++ dist/index.js | 14 ++++++-------- dist/index.mjs | 14 ++++++-------- package.json | 2 +- 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 320bf1e..85c6c7b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/dist/index.js b/dist/index.js index 36ba80b..486abf7 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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 }, @@ -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; @@ -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; } @@ -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; @@ -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; } } diff --git a/dist/index.mjs b/dist/index.mjs index db652ea..bafd401 100644 --- a/dist/index.mjs +++ b/dist/index.mjs @@ -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 }, @@ -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; @@ -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; } @@ -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; @@ -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; } } diff --git a/package.json b/package.json index d5ce319..5332ec4 100644 --- a/package.json +++ b/package.json @@ -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",