vsrepo 1.1.4 → 1.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  ![npm](https://img.shields.io/npm/v/vsrepo?style=flat-square)
4
4
  ![license](https://img.shields.io/github/license/jaobrabo123/vsrepository?style=flat-square)
5
+ ![NPM Downloads](https://img.shields.io/npm/d18m/vsrepo.svg)
5
6
 
6
7
  Biblioteca de repository pattern para projetos que usam **Prisma**, com suporte completo a **TypeScript** e **type inference** automático.
7
8
 
@@ -1,6 +1,29 @@
1
1
  import z from "zod";
2
2
  import { VSRepoConfigError, VSRepoBuildError } from "./VSRepoError.js";
3
3
 
4
+ export function mergeWheres(currentWhere, restrictWhere) {
5
+ const restrictWhereKeys = Object.keys(restrictWhere);
6
+ for (let i = 0; i < restrictWhereKeys.length; i++) {
7
+ const restrictWhereKey = restrictWhereKeys[i];
8
+ const restrictWhereField = restrictWhere[restrictWhereKey];
9
+
10
+ if (restrictWhereField === null || typeof restrictWhereField !== "object") {
11
+ currentWhere[restrictWhereKey] = restrictWhereField;
12
+ } else if (Array.isArray(restrictWhereField)) {
13
+ currentWhere[restrictWhereKey] = Array.isArray(currentWhere[restrictWhereKey]) ?
14
+ restrictWhereField.concat(currentWhere[restrictWhereKey]) :
15
+ restrictWhereField;
16
+ } else {
17
+ currentWhere[restrictWhereKey] =
18
+ currentWhere[restrictWhereKey] != null &&
19
+ typeof currentWhere[restrictWhereKey] === "object" &&
20
+ !Array.isArray(currentWhere[restrictWhereKey]) ?
21
+ Object.assign(currentWhere[restrictWhereKey], restrictWhereField) :
22
+ restrictWhereField;
23
+ }
24
+ }
25
+ }
26
+
4
27
  const stringSchema = z.string().trim().nonempty();
5
28
  const objectSchema = z.looseObject({});
6
29
  const booleanSchema = z.boolean();
@@ -9,7 +9,7 @@ export * from "./VSRepoError.js";
9
9
 
10
10
  // * Importando classes de erro
11
11
  import { VSRepoBuildError, VSRepoExtendError, VSRepoRuntimeError } from "./VSRepoError.js";
12
- import { validateBuildConfig, validateConfig } from "./VSRepoUtils.js";
12
+ import { mergeWheres, validateBuildConfig, validateConfig } from "./VSRepoUtils.js";
13
13
 
14
14
  // * Essa é a classe pincipal, é a partir dela que serão criados os objetos dos repositories
15
15
  export class VSRepository {
@@ -593,15 +593,11 @@ export class VSRepository {
593
593
  const assignWhere = (where) => {
594
594
  if(whereType==='extending' && buildInstance.requiredWhere) {
595
595
  let safeRequiredWhere = structuredClone(buildInstance.requiredWhere);
596
- if(where.OR && safeRequiredWhere.OR) safeRequiredWhere.OR = safeRequiredWhere.OR.concat(where.OR)
597
- if(where.AND && safeRequiredWhere.AND) safeRequiredWhere.AND = safeRequiredWhere.AND.concat(where.AND)
598
- Object.assign(where, safeRequiredWhere);
596
+ mergeWheres(where, safeRequiredWhere);
599
597
  }
600
598
  if(pushWhere !== undefined) {
601
599
  let safePushWhere = structuredClone(pushWhere);
602
- if(where.OR && safePushWhere.OR) safePushWhere.OR = safePushWhere.OR.concat(where.OR)
603
- if(where.AND && safePushWhere.AND) safePushWhere.AND = safePushWhere.AND.concat(where.AND)
604
- Object.assign(where, safePushWhere);
600
+ mergeWheres(where, safePushWhere);
605
601
  }
606
602
  }
607
603
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vsrepo",
3
- "version": "1.1.4",
3
+ "version": "1.1.5",
4
4
  "description": "Uma biblioteca de repository pattern para Prisma",
5
5
  "homepage": "https://github.com/jaobrabo123/VSRepository#readme",
6
6
  "repository": {