av6-core 1.5.3 → 1.5.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/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();
@@ -724,7 +758,8 @@ var commonRepository = (serviceDeps) => {
724
758
  fixedNotSearch,
725
759
  // same structure
726
760
  shortCodeData,
727
- includes
761
+ includes,
762
+ logic
728
763
  }) {
729
764
  logger.info("entering::fixedSearch::repository");
730
765
  const tableName = shortCodeData.tableName;
@@ -736,7 +771,8 @@ var commonRepository = (serviceDeps) => {
736
771
  fixedNotSearch,
737
772
  fixedSearch,
738
773
  includes,
739
- sortDir
774
+ sortDir,
775
+ logic
740
776
  });
741
777
  const skip = (pageNo - 1) * pageSize;
742
778
  const take = pageSize;
@@ -795,7 +831,8 @@ var commonRepository = (serviceDeps) => {
795
831
  fixedNotSearch,
796
832
  // same structure
797
833
  shortCodeData,
798
- includes
834
+ includes,
835
+ logic
799
836
  }) {
800
837
  logger.info("entering::fixedSearchWoPagination::repository");
801
838
  const tableName = shortCodeData.tableName;
@@ -807,7 +844,8 @@ var commonRepository = (serviceDeps) => {
807
844
  fixedNotSearch,
808
845
  fixedSearch,
809
846
  includes,
810
- sortDir
847
+ sortDir,
848
+ logic
811
849
  });
812
850
  const model = db[tableName];
813
851
  if (!model) {
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();
@@ -674,7 +708,8 @@ var commonRepository = (serviceDeps) => {
674
708
  fixedNotSearch,
675
709
  // same structure
676
710
  shortCodeData,
677
- includes
711
+ includes,
712
+ logic
678
713
  }) {
679
714
  logger.info("entering::fixedSearch::repository");
680
715
  const tableName = shortCodeData.tableName;
@@ -686,7 +721,8 @@ var commonRepository = (serviceDeps) => {
686
721
  fixedNotSearch,
687
722
  fixedSearch,
688
723
  includes,
689
- sortDir
724
+ sortDir,
725
+ logic
690
726
  });
691
727
  const skip = (pageNo - 1) * pageSize;
692
728
  const take = pageSize;
@@ -745,7 +781,8 @@ var commonRepository = (serviceDeps) => {
745
781
  fixedNotSearch,
746
782
  // same structure
747
783
  shortCodeData,
748
- includes
784
+ includes,
785
+ logic
749
786
  }) {
750
787
  logger.info("entering::fixedSearchWoPagination::repository");
751
788
  const tableName = shortCodeData.tableName;
@@ -757,7 +794,8 @@ var commonRepository = (serviceDeps) => {
757
794
  fixedNotSearch,
758
795
  fixedSearch,
759
796
  includes,
760
- sortDir
797
+ sortDir,
798
+ logic
761
799
  });
762
800
  const model = db[tableName];
763
801
  if (!model) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "av6-core",
3
- "version": "1.5.3",
3
+ "version": "1.5.5",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",