Skip to content

Commit

Permalink
Release 0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dennemark committed Jul 31, 2024
1 parent 12aa007 commit 63f22f8
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 1 deletion.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@


## [0.4.0](https://github.com/dennemark/prisma-extension-casl/compare/0.3.0...0.4.0) (2024-07-31)


### Features

* :technologist: add debugCasl flag to query ([12aa007](https://github.com/dennemark/prisma-extension-casl/commit/12aa007cdbb599562ca458ec6f45272d99a2ac9b))

## [0.3.0](https://github.com/dennemark/prisma-extension-casl/compare/0.2.0...0.3.0) (2024-07-31)


Expand Down
34 changes: 34 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1183,13 +1183,47 @@ var useCaslAbilities = (getAbilities) => {
query: {
$allModels: {
async $allOperations({ args, query, model, operation, ...rest }) {
const debug = process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test" && args.debugCasl;
delete args.debugCasl;
const perf = debug ? performance : void 0;
const logger = debug ? console : void 0;
perf?.clearMeasures("prisma-casl-extension-Overall");
perf?.clearMeasures("prisma-casl-extension-Create Abilities");
perf?.clearMeasures("prisma-casl-extension-Create Casl Query");
perf?.clearMeasures("prisma-casl-extension-Finish Query");
perf?.clearMeasures("prisma-casl-extension-Filtering Results");
perf?.clearMarks("prisma-casl-extension-0");
perf?.clearMarks("prisma-casl-extension-1");
perf?.clearMarks("prisma-casl-extension-2");
perf?.clearMarks("prisma-casl-extension-3");
perf?.clearMarks("prisma-casl-extension-4");
if (!(operation in caslOperationDict)) {
return query(args);
}
perf?.mark("prisma-casl-extension-0");
const abilities = getAbilities();
perf?.mark("prisma-casl-extension-1");
const caslQuery = applyCaslToQuery(operation, args, abilities, model);
perf?.mark("prisma-casl-extension-2");
logger?.log("Query Args", JSON.stringify(caslQuery.args));
logger?.log("Query Mask", JSON.stringify(caslQuery.mask));
return query(caslQuery.args).then((result) => {
perf?.mark("prisma-casl-extension-3");
const res = filterQueryResults(result, caslQuery.mask, abilities, getFluentModel(model, rest));
if (perf) {
perf.mark("prisma-casl-extension-4");
logger?.log(
[
perf.measure("prisma-casl-extension-Overall", "prisma-casl-extension-0", "prisma-casl-extension-4"),
perf.measure("prisma-casl-extension-Create Abilities", "prisma-casl-extension-0", "prisma-casl-extension-1"),
perf.measure("prisma-casl-extension-Create Casl Query", "prisma-casl-extension-1", "prisma-casl-extension-2"),
perf.measure("prisma-casl-extension-Finish Query", "prisma-casl-extension-2", "prisma-casl-extension-3"),
perf.measure("prisma-casl-extension-Filtering Results", "prisma-casl-extension-3", "prisma-casl-extension-4")
].map((measure) => {
return `${measure.name.replace("prisma-casl-extension-", "")}: ${measure.duration}`;
})
);
}
return res;
});
}
Expand Down
34 changes: 34 additions & 0 deletions dist/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1158,13 +1158,47 @@ var useCaslAbilities = (getAbilities) => {
query: {
$allModels: {
async $allOperations({ args, query, model, operation, ...rest }) {
const debug = process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test" && args.debugCasl;
delete args.debugCasl;
const perf = debug ? performance : void 0;
const logger = debug ? console : void 0;
perf?.clearMeasures("prisma-casl-extension-Overall");
perf?.clearMeasures("prisma-casl-extension-Create Abilities");
perf?.clearMeasures("prisma-casl-extension-Create Casl Query");
perf?.clearMeasures("prisma-casl-extension-Finish Query");
perf?.clearMeasures("prisma-casl-extension-Filtering Results");
perf?.clearMarks("prisma-casl-extension-0");
perf?.clearMarks("prisma-casl-extension-1");
perf?.clearMarks("prisma-casl-extension-2");
perf?.clearMarks("prisma-casl-extension-3");
perf?.clearMarks("prisma-casl-extension-4");
if (!(operation in caslOperationDict)) {
return query(args);
}
perf?.mark("prisma-casl-extension-0");
const abilities = getAbilities();
perf?.mark("prisma-casl-extension-1");
const caslQuery = applyCaslToQuery(operation, args, abilities, model);
perf?.mark("prisma-casl-extension-2");
logger?.log("Query Args", JSON.stringify(caslQuery.args));
logger?.log("Query Mask", JSON.stringify(caslQuery.mask));
return query(caslQuery.args).then((result) => {
perf?.mark("prisma-casl-extension-3");
const res = filterQueryResults(result, caslQuery.mask, abilities, getFluentModel(model, rest));
if (perf) {
perf.mark("prisma-casl-extension-4");
logger?.log(
[
perf.measure("prisma-casl-extension-Overall", "prisma-casl-extension-0", "prisma-casl-extension-4"),
perf.measure("prisma-casl-extension-Create Abilities", "prisma-casl-extension-0", "prisma-casl-extension-1"),
perf.measure("prisma-casl-extension-Create Casl Query", "prisma-casl-extension-1", "prisma-casl-extension-2"),
perf.measure("prisma-casl-extension-Finish Query", "prisma-casl-extension-2", "prisma-casl-extension-3"),
perf.measure("prisma-casl-extension-Filtering Results", "prisma-casl-extension-3", "prisma-casl-extension-4")
].map((measure) => {
return `${measure.name.replace("prisma-casl-extension-", "")}: ${measure.duration}`;
})
);
}
return res;
});
}
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.3.0",
"version": "0.4.0",
"description": "Enforce casl abilities on prisma client ",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down

0 comments on commit 63f22f8

Please sign in to comment.