Skip to content

Commit

Permalink
Release 1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
dennemark committed Nov 27, 2024
1 parent bb933e1 commit 8643f6d
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.1.1](https://github.com/dennemark/prisma-extension-casl/compare/1.1.0...1.1.1) (2024-11-27)

### Bug Fixes

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

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

### Features
Expand Down
28 changes: 24 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,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 @@ -1263,10 +1283,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 @@ -1142,6 +1142,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 @@ -1238,10 +1258,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.1.0",
"version": "1.1.1",
"description": "Enforce casl abilities on prisma client ",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down

0 comments on commit 8643f6d

Please sign in to comment.