av6-core 1.5.4 → 1.5.6

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/dist/index.js CHANGED
@@ -375,6 +375,39 @@ function smartAndMerge(a, b) {
375
375
  if (merged !== void 0) return merged;
376
376
  return andWrap(a, b);
377
377
  }
378
+ function normalizeWhere(where) {
379
+ if (Array.isArray(where)) return where.map(normalizeWhere);
380
+ if (!isPlainObject(where)) return where;
381
+ for (const k of Object.keys(where)) {
382
+ where[k] = normalizeWhere(where[k]);
383
+ }
384
+ if (Array.isArray(where.OR) && where.OR.length > 0) {
385
+ const orItems = where.OR;
386
+ const keys = orItems.map((it) => isPlainObject(it) ? Object.keys(it) : []);
387
+ const allSingleKey = keys.every((k) => k.length === 1);
388
+ if (allSingleKey) {
389
+ const commonKey = keys[0][0];
390
+ const allSameKey = keys.every((k) => k[0] === commonKey);
391
+ const isLogicalKey = commonKey === "AND" || commonKey === "OR" || commonKey === "NOT";
392
+ if (allSameKey && !isLogicalKey) {
393
+ const inner = orItems.map((it) => it[commonKey]).filter((v) => isPlainObject(v));
394
+ const foldedRel = { OR: inner };
395
+ if (isPlainObject(where[commonKey])) {
396
+ where[commonKey] = { ...where[commonKey], ...foldedRel };
397
+ if (Array.isArray(where[commonKey].OR) && Array.isArray(foldedRel.OR)) {
398
+ }
399
+ } else {
400
+ where[commonKey] = foldedRel;
401
+ }
402
+ delete where.OR;
403
+ }
404
+ }
405
+ }
406
+ if (Array.isArray(where.AND)) {
407
+ where.AND = where.AND.map(normalizeWhere);
408
+ }
409
+ return where;
410
+ }
378
411
 
379
412
  // src/repository/common.repository.ts
380
413
  var import_util2 = require("util");
@@ -702,6 +735,7 @@ var commonRepository = (serviceDeps) => {
702
735
  if (searchOR?.length) {
703
736
  whereClause = smartAndMerge(whereClause, { OR: searchOR });
704
737
  }
738
+ whereClause = normalizeWhere(whereClause);
705
739
  const orderByClause = {};
706
740
  if (sortBy && sortDir) {
707
741
  orderByClause[sortBy] = sortDir.toLowerCase();
package/dist/index.mjs CHANGED
@@ -325,6 +325,39 @@ function smartAndMerge(a, b) {
325
325
  if (merged !== void 0) return merged;
326
326
  return andWrap(a, b);
327
327
  }
328
+ function normalizeWhere(where) {
329
+ if (Array.isArray(where)) return where.map(normalizeWhere);
330
+ if (!isPlainObject(where)) return where;
331
+ for (const k of Object.keys(where)) {
332
+ where[k] = normalizeWhere(where[k]);
333
+ }
334
+ if (Array.isArray(where.OR) && where.OR.length > 0) {
335
+ const orItems = where.OR;
336
+ const keys = orItems.map((it) => isPlainObject(it) ? Object.keys(it) : []);
337
+ const allSingleKey = keys.every((k) => k.length === 1);
338
+ if (allSingleKey) {
339
+ const commonKey = keys[0][0];
340
+ const allSameKey = keys.every((k) => k[0] === commonKey);
341
+ const isLogicalKey = commonKey === "AND" || commonKey === "OR" || commonKey === "NOT";
342
+ if (allSameKey && !isLogicalKey) {
343
+ const inner = orItems.map((it) => it[commonKey]).filter((v) => isPlainObject(v));
344
+ const foldedRel = { OR: inner };
345
+ if (isPlainObject(where[commonKey])) {
346
+ where[commonKey] = { ...where[commonKey], ...foldedRel };
347
+ if (Array.isArray(where[commonKey].OR) && Array.isArray(foldedRel.OR)) {
348
+ }
349
+ } else {
350
+ where[commonKey] = foldedRel;
351
+ }
352
+ delete where.OR;
353
+ }
354
+ }
355
+ }
356
+ if (Array.isArray(where.AND)) {
357
+ where.AND = where.AND.map(normalizeWhere);
358
+ }
359
+ return where;
360
+ }
328
361
 
329
362
  // src/repository/common.repository.ts
330
363
  import { isDeepStrictEqual as isDeepStrictEqual2 } from "util";
@@ -652,6 +685,7 @@ var commonRepository = (serviceDeps) => {
652
685
  if (searchOR?.length) {
653
686
  whereClause = smartAndMerge(whereClause, { OR: searchOR });
654
687
  }
688
+ whereClause = normalizeWhere(whereClause);
655
689
  const orderByClause = {};
656
690
  if (sortBy && sortDir) {
657
691
  orderByClause[sortBy] = sortDir.toLowerCase();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "av6-core",
3
- "version": "1.5.4",
3
+ "version": "1.5.6",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",