diff --git a/CHANGELOG.md b/CHANGELOG.md index 56b9907..f046cfa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ +## [1.1.5](https://github.com/dennemark/prisma-extension-casl/compare/1.1.4...1.1.5) (2024-12-05) + +### Bug Fixes + +* :bug: use different method to check if transactionId should be used for batch ([5bd5dc7](https://github.com/dennemark/prisma-extension-casl/commit/5bd5dc7d92acf59e07a0a5a2acec1238c37c9935)) + ## [1.1.4](https://github.com/dennemark/prisma-extension-casl/compare/1.1.3...1.1.4) (2024-12-04) ### Bug Fixes diff --git a/dist/index.js b/dist/index.js index 3e17c5a..9279a64 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1476,6 +1476,7 @@ function filterQueryResults(result, mask, creationTree, abilities, model, operat // src/index.ts function useCaslAbilities(getAbilityFactory, opts) { return import_client2.Prisma.defineExtension((client) => { + const transactionsToBatch = /* @__PURE__ */ new Set(); const allOperations = (getAbilities) => ({ async $allOperations({ args, query, model, operation, ...rest }) { const fluentModel = getFluentModel(model, rest); @@ -1586,8 +1587,11 @@ function useCaslAbilities(getAbilityFactory, opts) { return transactionQuery(client._createItxClient(transaction)); } else { return client.$transaction(async (tx) => { - tx[Symbol.for("prisma.client.transaction.id")] = "casl-extension-" + tx[Symbol.for("prisma.client.transaction.id")]; - return transactionQuery(tx); + const transactionId = tx[Symbol.for("prisma.client.transaction.id")].toString(); + transactionsToBatch.add(transactionId); + return transactionQuery(tx).finally(() => { + transactionsToBatch.delete(transactionId); + }); }, { //https://github.com/prisma/prisma/issues/20015 maxWait: 1e4 @@ -1597,10 +1601,11 @@ function useCaslAbilities(getAbilityFactory, opts) { } }); client._requestHandler.dataloader.options.batchBy = (request) => { - if (request.transaction?.id && !request.transaction?.id?.toString().startsWith("casl-extension-")) { + const batchId = getBatchId(request.protocolQuery); + if (request.transaction?.id && (!transactionsToBatch.has(request.transaction.id.toString()) && batchId)) { return `transaction-${request.transaction.id}`; } - return getBatchId(request.protocolQuery); + return batchId; }; return client.$extends({ name: "prisma-extension-casl", diff --git a/dist/index.mjs b/dist/index.mjs index d0aee7c..ee6592d 100644 --- a/dist/index.mjs +++ b/dist/index.mjs @@ -1450,6 +1450,7 @@ function filterQueryResults(result, mask, creationTree, abilities, model, operat // src/index.ts function useCaslAbilities(getAbilityFactory, opts) { return Prisma2.defineExtension((client) => { + const transactionsToBatch = /* @__PURE__ */ new Set(); const allOperations = (getAbilities) => ({ async $allOperations({ args, query, model, operation, ...rest }) { const fluentModel = getFluentModel(model, rest); @@ -1560,8 +1561,11 @@ function useCaslAbilities(getAbilityFactory, opts) { return transactionQuery(client._createItxClient(transaction)); } else { return client.$transaction(async (tx) => { - tx[Symbol.for("prisma.client.transaction.id")] = "casl-extension-" + tx[Symbol.for("prisma.client.transaction.id")]; - return transactionQuery(tx); + const transactionId = tx[Symbol.for("prisma.client.transaction.id")].toString(); + transactionsToBatch.add(transactionId); + return transactionQuery(tx).finally(() => { + transactionsToBatch.delete(transactionId); + }); }, { //https://github.com/prisma/prisma/issues/20015 maxWait: 1e4 @@ -1571,10 +1575,11 @@ function useCaslAbilities(getAbilityFactory, opts) { } }); client._requestHandler.dataloader.options.batchBy = (request) => { - if (request.transaction?.id && !request.transaction?.id?.toString().startsWith("casl-extension-")) { + const batchId = getBatchId(request.protocolQuery); + if (request.transaction?.id && (!transactionsToBatch.has(request.transaction.id.toString()) && batchId)) { return `transaction-${request.transaction.id}`; } - return getBatchId(request.protocolQuery); + return batchId; }; return client.$extends({ name: "prisma-extension-casl", diff --git a/package.json b/package.json index 4783c97..14a54b5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "prisma-extension-casl", - "version": "1.1.4", + "version": "1.1.5", "description": "Enforce casl abilities on prisma client ", "main": "dist/index.js", "types": "dist/index.d.ts",