Skip to content

Commit

Permalink
Release 1.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
dennemark committed Dec 4, 2024
1 parent 56cde5f commit 5234086
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@


## [1.1.4](https://github.com/dennemark/prisma-extension-casl/compare/1.1.3...1.1.4) (2024-12-04)

### Bug Fixes

* :bug: try fixing batching ([56cde5f](https://github.com/dennemark/prisma-extension-casl/commit/56cde5fba2b61c9968ca1f4ea8d9b27c093bffec))

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

### Bug Fixes
Expand Down
3 changes: 2 additions & 1 deletion dist/index.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,6 @@ declare function useCaslAbilities(getAbilityFactory: () => AbilityBuilder<PureAb
};
};
};
declare function getBatchId(query: any): string | undefined;

export { applyCaslToQuery, useCaslAbilities };
export { applyCaslToQuery, getBatchId, useCaslAbilities };
3 changes: 2 additions & 1 deletion dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,6 @@ declare function useCaslAbilities(getAbilityFactory: () => AbilityBuilder<PureAb
};
};
};
declare function getBatchId(query: any): string | undefined;

export { applyCaslToQuery, useCaslAbilities };
export { applyCaslToQuery, getBatchId, useCaslAbilities };
33 changes: 33 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
var src_exports = {};
__export(src_exports, {
applyCaslToQuery: () => applyCaslToQuery,
getBatchId: () => getBatchId,
useCaslAbilities: () => useCaslAbilities
});
module.exports = __toCommonJS(src_exports);
Expand Down Expand Up @@ -1585,6 +1586,7 @@ 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);
}, {
//https://github.com/prisma/prisma/issues/20015
Expand All @@ -1594,6 +1596,12 @@ function useCaslAbilities(getAbilityFactory, opts) {
}
}
});
client._requestHandler.dataloader.options.batchBy = (request) => {
if (request.transaction?.id && !request.transaction?.id?.toString().startsWith("casl-extension-")) {
return `transaction-${request.transaction.id}`;
}
return getBatchId(request.protocolQuery);
};
return client.$extends({
name: "prisma-extension-casl",
client: {
Expand Down Expand Up @@ -1621,8 +1629,33 @@ function useCaslAbilities(getAbilityFactory, opts) {
});
});
}
function getBatchId(query) {
if (query.action !== "findUnique" && query.action !== "findUniqueOrThrow") {
return void 0;
}
const parts = [];
if (query.modelName) {
parts.push(query.modelName);
}
if (query.query.arguments) {
parts.push(buildKeysString(query.query.arguments));
}
parts.push(buildKeysString(query.query.selection));
return parts.join("");
}
function buildKeysString(obj) {
const keysArray = Object.keys(obj).sort().map((key) => {
const value = obj[key];
if (typeof value === "object" && value !== null) {
return `(${key} ${buildKeysString(value)})`;
}
return key;
});
return `(${keysArray.join(" ")})`;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
applyCaslToQuery,
getBatchId,
useCaslAbilities
});
32 changes: 32 additions & 0 deletions dist/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1560,6 +1560,7 @@ 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);
}, {
//https://github.com/prisma/prisma/issues/20015
Expand All @@ -1569,6 +1570,12 @@ function useCaslAbilities(getAbilityFactory, opts) {
}
}
});
client._requestHandler.dataloader.options.batchBy = (request) => {
if (request.transaction?.id && !request.transaction?.id?.toString().startsWith("casl-extension-")) {
return `transaction-${request.transaction.id}`;
}
return getBatchId(request.protocolQuery);
};
return client.$extends({
name: "prisma-extension-casl",
client: {
Expand Down Expand Up @@ -1596,7 +1603,32 @@ function useCaslAbilities(getAbilityFactory, opts) {
});
});
}
function getBatchId(query) {
if (query.action !== "findUnique" && query.action !== "findUniqueOrThrow") {
return void 0;
}
const parts = [];
if (query.modelName) {
parts.push(query.modelName);
}
if (query.query.arguments) {
parts.push(buildKeysString(query.query.arguments));
}
parts.push(buildKeysString(query.query.selection));
return parts.join("");
}
function buildKeysString(obj) {
const keysArray = Object.keys(obj).sort().map((key) => {
const value = obj[key];
if (typeof value === "object" && value !== null) {
return `(${key} ${buildKeysString(value)})`;
}
return key;
});
return `(${keysArray.join(" ")})`;
}
export {
applyCaslToQuery,
getBatchId,
useCaslAbilities
};
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.3",
"version": "1.1.4",
"description": "Enforce casl abilities on prisma client ",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down

0 comments on commit 5234086

Please sign in to comment.