Skip to content

Commit

Permalink
Release 1.1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
dennemark committed Dec 6, 2024
1 parent 5afde2e commit d59821f
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 43 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.7](https://github.com/dennemark/prisma-extension-casl/compare/1.1.6...1.1.7) (2024-12-06)

### Bug Fixes

* :bug: fluent list relation mask ([5afde2e](https://github.com/dennemark/prisma-extension-casl/commit/5afde2e26c42b0da7bf28460bb3a36801f090eef))

## [1.1.6](https://github.com/dennemark/prisma-extension-casl/compare/1.1.5...1.1.6) (2024-12-05)

### Bug Fixes
Expand Down
47 changes: 26 additions & 21 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,7 @@ function mergeArgsAndRelationQuery(args, relationQuery) {
...args.include ?? {},
[k2]: v4
};
mask[k2] = removeNestedIncludeSelect(v4.select);
mask[k2] = args.where ? true : removeNestedIncludeSelect(v4.select);
}
});
}
Expand Down Expand Up @@ -1276,30 +1276,35 @@ function getNestedQueryRelations(args, abilities, action, model, creationSelectQ
inverted: false
};
}));
const ast = d4(ability, action, model);
const queryRelations = getRuleRelationsQuery(model, ast, creationSelectQuery === true ? {} : creationSelectQuery);
["include", "select"].map((method) => {
if (args && args[method]) {
for (const relation in args[method]) {
if (model in relationFieldsByModel && relation in relationFieldsByModel[model]) {
const relationField = relationFieldsByModel[model][relation];
if (relationField) {
const nestedQueryRelations = deepMerge(
getNestedQueryRelations(args[method][relation], abilities, action === "all" ? "all" : "read", relationField.type),
typeof queryRelations[relation]?.select === "object" ? queryRelations[relation]?.select : {}
);
if (nestedQueryRelations && Object.keys(nestedQueryRelations).length > 0) {
queryRelations[relation] = {
...queryRelations[relation] ?? {},
select: nestedQueryRelations
};
try {
const ast = d4(ability, action, model);
const queryRelations = getRuleRelationsQuery(model, ast, creationSelectQuery === true ? {} : creationSelectQuery);
["include", "select"].map((method) => {
if (args && args[method]) {
for (const relation in args[method]) {
if (model in relationFieldsByModel && relation in relationFieldsByModel[model]) {
const relationField = relationFieldsByModel[model][relation];
if (relationField) {
const nestedQueryRelations = deepMerge(
getNestedQueryRelations(args[method][relation], abilities, action === "all" ? "all" : "read", relationField.type),
typeof queryRelations[relation]?.select === "object" ? queryRelations[relation]?.select : {}
);
if (nestedQueryRelations && Object.keys(nestedQueryRelations).length > 0) {
queryRelations[relation] = {
...queryRelations[relation] ?? {},
select: nestedQueryRelations
};
}
}
}
}
}
}
});
return queryRelations;
});
return queryRelations;
} catch (e4) {
console.error(`Your ability relation probably is missing an 'is': [relation]: { is: { id: 0 } }`);
throw e4;
}
}

// src/transformDataToWhereQuery.ts
Expand Down
47 changes: 26 additions & 21 deletions dist/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,7 @@ function mergeArgsAndRelationQuery(args, relationQuery) {
...args.include ?? {},
[k2]: v4
};
mask[k2] = removeNestedIncludeSelect(v4.select);
mask[k2] = args.where ? true : removeNestedIncludeSelect(v4.select);
}
});
}
Expand Down Expand Up @@ -1250,30 +1250,35 @@ function getNestedQueryRelations(args, abilities, action, model, creationSelectQ
inverted: false
};
}));
const ast = d4(ability, action, model);
const queryRelations = getRuleRelationsQuery(model, ast, creationSelectQuery === true ? {} : creationSelectQuery);
["include", "select"].map((method) => {
if (args && args[method]) {
for (const relation in args[method]) {
if (model in relationFieldsByModel && relation in relationFieldsByModel[model]) {
const relationField = relationFieldsByModel[model][relation];
if (relationField) {
const nestedQueryRelations = deepMerge(
getNestedQueryRelations(args[method][relation], abilities, action === "all" ? "all" : "read", relationField.type),
typeof queryRelations[relation]?.select === "object" ? queryRelations[relation]?.select : {}
);
if (nestedQueryRelations && Object.keys(nestedQueryRelations).length > 0) {
queryRelations[relation] = {
...queryRelations[relation] ?? {},
select: nestedQueryRelations
};
try {
const ast = d4(ability, action, model);
const queryRelations = getRuleRelationsQuery(model, ast, creationSelectQuery === true ? {} : creationSelectQuery);
["include", "select"].map((method) => {
if (args && args[method]) {
for (const relation in args[method]) {
if (model in relationFieldsByModel && relation in relationFieldsByModel[model]) {
const relationField = relationFieldsByModel[model][relation];
if (relationField) {
const nestedQueryRelations = deepMerge(
getNestedQueryRelations(args[method][relation], abilities, action === "all" ? "all" : "read", relationField.type),
typeof queryRelations[relation]?.select === "object" ? queryRelations[relation]?.select : {}
);
if (nestedQueryRelations && Object.keys(nestedQueryRelations).length > 0) {
queryRelations[relation] = {
...queryRelations[relation] ?? {},
select: nestedQueryRelations
};
}
}
}
}
}
}
});
return queryRelations;
});
return queryRelations;
} catch (e4) {
console.error(`Your ability relation probably is missing an 'is': [relation]: { is: { id: 0 } }`);
throw e4;
}
}

// src/transformDataToWhereQuery.ts
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.6",
"version": "1.1.7",
"description": "Enforce casl abilities on prisma client ",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down

0 comments on commit d59821f

Please sign in to comment.