Skip to content

Commit

Permalink
Release 1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
dennemark committed Nov 28, 2024
1 parent ecd8741 commit de1d86b
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@


## [1.0.2](https://github.com/dennemark/prisma-extension-casl/compare/1.0.1...1.0.2) (2024-11-28)

### Bug Fixes

* :bug: deep merge nested rule relations ([ecd8741](https://github.com/dennemark/prisma-extension-casl/commit/ecd87416b69ed3c477629bbaf891e182070283f5))

## [1.0.1](https://github.com/dennemark/prisma-extension-casl/compare/1.0.0...1.0.1) (2024-10-29)

### Bug Fixes
Expand Down
28 changes: 24 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1159,6 +1159,26 @@ function convertCreationTreeToSelect(abilities, relationQuery) {
return Object.keys(relationResult).length > 0 ? relationResult : relationQuery.action === "create" ? {} : null;
}

// src/deepMerge.ts
function isObject(item) {
return item && typeof item === "object" && !Array.isArray(item);
}
function deepMerge(target, ...sources) {
if (!sources.length) return target;
const source = sources.shift();
if (isObject(target) && isObject(source)) {
for (const key in source) {
if (isObject(source[key])) {
if (!target[key]) Object.assign(target, { [key]: {} });
deepMerge(target[key], source[key]);
} else {
Object.assign(target, { [key]: source[key] });
}
}
}
return deepMerge(target, ...sources);
}

// src/applyRuleRelationsQuery.ts
function mergeArgsAndRelationQuery(args, relationQuery) {
const mask = {};
Expand Down Expand Up @@ -1255,10 +1275,10 @@ function getNestedQueryRelations(args, abilities, action, model, creationSelectQ
if (model in relationFieldsByModel && relation in relationFieldsByModel[model]) {
const relationField = relationFieldsByModel[model][relation];
if (relationField) {
const nestedQueryRelations = {
...getNestedQueryRelations(args[method][relation], abilities, action === "all" ? "all" : "read", relationField.type),
...queryRelations[relation]?.select ?? {}
};
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] ?? {},
Expand Down
28 changes: 24 additions & 4 deletions dist/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1134,6 +1134,26 @@ function convertCreationTreeToSelect(abilities, relationQuery) {
return Object.keys(relationResult).length > 0 ? relationResult : relationQuery.action === "create" ? {} : null;
}

// src/deepMerge.ts
function isObject(item) {
return item && typeof item === "object" && !Array.isArray(item);
}
function deepMerge(target, ...sources) {
if (!sources.length) return target;
const source = sources.shift();
if (isObject(target) && isObject(source)) {
for (const key in source) {
if (isObject(source[key])) {
if (!target[key]) Object.assign(target, { [key]: {} });
deepMerge(target[key], source[key]);
} else {
Object.assign(target, { [key]: source[key] });
}
}
}
return deepMerge(target, ...sources);
}

// src/applyRuleRelationsQuery.ts
function mergeArgsAndRelationQuery(args, relationQuery) {
const mask = {};
Expand Down Expand Up @@ -1230,10 +1250,10 @@ function getNestedQueryRelations(args, abilities, action, model, creationSelectQ
if (model in relationFieldsByModel && relation in relationFieldsByModel[model]) {
const relationField = relationFieldsByModel[model][relation];
if (relationField) {
const nestedQueryRelations = {
...getNestedQueryRelations(args[method][relation], abilities, action === "all" ? "all" : "read", relationField.type),
...queryRelations[relation]?.select ?? {}
};
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] ?? {},
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.0.1",
"version": "1.0.2",
"description": "Enforce casl abilities on prisma client ",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down

0 comments on commit de1d86b

Please sign in to comment.