@izara_project/izara-shared-search-and-sort 1.0.5 → 1.0.7

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.
@@ -23,6 +23,7 @@ import lodash from 'lodash';
23
23
  const { isEmpty } = lodash;
24
24
  import { v4 as uuidV4 } from 'uuid'; //const { v4: uuidv4 } = require('uuid');
25
25
  import { getObjectSchema } from '@izara_project/izara-core-library-service-schemas';
26
+ // import { getObjectSchema } from '@izara_project/izara-shared-service-schemas';
26
27
  const MAX_ITER = 4;
27
28
 
28
29
 
@@ -428,146 +429,754 @@ function combineOperation(
428
429
 
429
430
  };
430
431
 
432
+ // function combineLogicalElements(
433
+ // firstFilterStructure,
434
+ // secondFilterStructure,
435
+ // operator = "AND"
436
+ // ) {
437
+ // console.log('combineLogicalElements: ', {
438
+ // firstFilterStructure,
439
+ // secondFilterStructure,
440
+ // operator
441
+ // });
442
+
443
+ // let objType = firstFilterStructure.objType;
444
+
445
+ // let [firstInitialLogicalElementId, firstLastLogicalElementId, firstFiltersStructureBrcket] = addBrackets(
446
+ // firstFilterStructure
447
+ // );
448
+ // console.log("first filterStructure addBrackets", {
449
+ // firstInitialLogicalElementId,
450
+ // firstLastLogicalElementId,
451
+ // firstFiltersStructureBrcket
452
+ // })
453
+
454
+ // let [secondInitialLogicalElementId, secondLastLogicalElementId, secondFiltersStructureBrcket] = addBrackets(
455
+ // secondFilterStructure
456
+ // );
457
+ // console.log("second filterStructure addBrackets", {
458
+ // secondInitialLogicalElementId,
459
+ // secondLastLogicalElementId,
460
+ // secondFiltersStructureBrcket
461
+ // })
462
+
463
+ // let uuid_operation = uuidV4();
464
+ // console.log('uuid_operation: ', uuid_operation);
465
+
466
+ // let operationObject = {
467
+ // logicalElementType: 'operation',
468
+ // previousLogicalElementId: firstLastLogicalElementId,
469
+ // nextLogicalElementId: secondInitialLogicalElementId,
470
+ // operation: operator
471
+ // };
472
+ // console.log('operationObject: ', operationObject);
473
+
474
+ // firstFiltersStructureBrcket.logicalElements[firstLastLogicalElementId].nextLogicalElementId = uuid_operation;
475
+ // secondFiltersStructureBrcket.logicalElements[secondInitialLogicalElementId].previousLogicalElementId = uuid_operation;
476
+
477
+ // let logicalElements = Object.assign(firstFiltersStructureBrcket.logicalElements, { [uuid_operation]: operationObject }, secondFiltersStructureBrcket.logicalElements);
478
+ // console.log('logicalElements: ', logicalElements);
479
+
480
+ // return {
481
+ // objType: objType,
482
+ // initialLogicalElementId: firstInitialLogicalElementId,
483
+ // logicalElements: logicalElements
484
+ // };
485
+
486
+ // }
487
+
488
+
489
+ //...function check exist bracket
490
+ function checkAndCreateBracket(filterLogicalStucture) {
491
+ console.log("checkAndCreateBracket params::::", filterLogicalStucture);
431
492
 
432
- function findLastLogicalElements(
433
- initialLogicalElementId,
434
- logicalElements
435
- ) {
436
- let lastCurrentLogicalId = null;
493
+ let errorsFound = [];
494
+
495
+ // if >1 element need to add brackets
496
+ if (filterLogicalStucture.logicalElements[filterLogicalStucture.initialLogicalElementId].nextLogicalElementId !== null) {
497
+ console.log("nextLogicalElementId != null", filterLogicalStucture.logicalElements[filterLogicalStucture.initialLogicalElementId].nextLogicalElementId);
498
+ [filterLogicalStucture, errorsFound] = createLogicalElementBracket(filterLogicalStucture);
499
+ }
500
+ console.log("nextLogicalElementId = null");
501
+ return [filterLogicalStucture, errorsFound];
502
+ }
437
503
 
504
+ function createLogicalElementBracket(filterLogicalStucture) {
505
+ console.log("createLogicalElementBracket params::::", filterLogicalStucture);
438
506
 
439
- let logicaclElement = logicalElements[initialLogicalElementId];
440
- _izContext.logger.debug('logicaclElement: ', logicaclElement);
507
+ // ---- add closeBracket
508
+ console.log("------create closeBracket------");
509
+ const MAX_LOGICAL_ELEMENTS = 1000;
441
510
 
442
- if (logicaclElement.nextLogicalElementId !== null) {
511
+ let working_logicalElementId = filterLogicalStucture.initialLogicalElementId;
443
512
 
444
- lastCurrentLogicalId = findLastLogicalElements(
445
- logicaclElement.nextLogicalElementId,
446
- logicalElements
447
- )
513
+ for (let infiniteCheck = 0; infiniteCheck <= MAX_LOGICAL_ELEMENTS; infiniteCheck++) {
514
+ //// 1000 should = limit CONST MAX_LOGICAL_ELEMENTS
515
+ // console.log("-----working_logicalElementId-----", working_logicalElementId);
516
+ if (filterLogicalStucture.logicalElements[working_logicalElementId].nextLogicalElementId === null) {
517
+ console.log("-----last logicalElement-----", filterLogicalStucture.logicalElements[working_logicalElementId]);
518
+ let closeBracket_uuid = uuidV4(); //uuidV4
519
+ console.log("closeBracket_uuid", closeBracket_uuid);
448
520
 
449
- } else {
450
- lastCurrentLogicalId = initialLogicalElementId;
521
+ filterLogicalStucture.logicalElements[closeBracket_uuid] = {
522
+ logicalElementType: "closeBracket",
523
+ previousLogicalElementId: working_logicalElementId,
524
+ nextLogicalElementId: null,
525
+ };
526
+
527
+ filterLogicalStucture.logicalElements[working_logicalElementId].nextLogicalElementId = closeBracket_uuid;
528
+ console.log("------filterLogicalStucture before break loop------", filterLogicalStucture);
529
+ break;
530
+ }
531
+ if (infiniteCheck >= MAX_LOGICAL_ELEMENTS) {
532
+ // throw no retry error
533
+ // throw new NoRetryError("Error: max count logicalElement");
534
+ return [null, ["Error: max count logicalElement"]]
535
+ }
536
+
537
+ working_logicalElementId = filterLogicalStucture.logicalElements[working_logicalElementId].nextLogicalElementId;
451
538
  }
452
539
 
453
- return lastCurrentLogicalId
540
+ console.log("------filterLogicalStucture before add open bracket------", filterLogicalStucture);
541
+
542
+ // ---- add openBracket
543
+
544
+ console.log("start create openBracket");
545
+ console.log("start logicalElement====>", filterLogicalStucture.logicalElements[filterLogicalStucture.initialLogicalElementId]);
546
+
547
+ let openBracket_uuid = uuidV4(); //uuidV4
548
+ console.log("openBracket_uuid", openBracket_uuid);
549
+ console.log("filterLogicalStucture before return:::::>>>>", filterLogicalStucture);
550
+
551
+ filterLogicalStucture.logicalElements[openBracket_uuid] = {
552
+ logicalElementType: "openBracket",
553
+ previousLogicalElementId: null,
554
+ nextLogicalElementId: filterLogicalStucture.initialLogicalElementId,
555
+ };
454
556
 
557
+ filterLogicalStucture.logicalElements[filterLogicalStucture.initialLogicalElementId].previousLogicalElementId = openBracket_uuid;
558
+ filterLogicalStucture.initialLogicalElementId = openBracket_uuid;
559
+ return [filterLogicalStucture, []];
455
560
  }
456
561
 
457
- function addBrackets(
458
- filtersStructure
562
+ function checkObjType(
563
+ fromObjType,
564
+ toObjType
459
565
  ) {
460
566
 
461
- let logicalElements = {};
567
+ let from = {
568
+ serviceTag: fromObjType.serviceTag,
569
+ objectType: fromObjType.objectType
570
+ };
462
571
 
463
- let uuid_openBracket = uuidV4();
464
- _izContext.logger.debug('uuid_openBracket: ', uuid_openBracket);
572
+ let to = {
573
+ serviceTag: toObjType.serviceTag,
574
+ objectType: toObjType.objectType
575
+ };
465
576
 
466
- let openBracketObject = {
467
- logicalElementType: "openBracket",
468
- previousLogicalElementId: null,
469
- nextLogicalElementId: filtersStructure.initialLogicalElementId
577
+ if (hash(to) === hash(from)) {
578
+ return true;
470
579
  };
471
- _izContext.logger.debug('openBracketObject: ', openBracketObject);
472
580
 
473
- filtersStructure.logicalElements[filtersStructure.initialLogicalElementId].previousLogicalElementId = uuid_openBracket;
581
+ return false;
474
582
 
475
- let lastLogicalElementId = findLastLogicalElements(
476
- filtersStructure.initialLogicalElementId,
477
- filtersStructure.logicalElements
478
- );
479
- _izContext.logger.debug('lastLogicalElementId: ', lastLogicalElementId);
583
+ };
584
+
585
+ // validate to changed searchType and filterType
586
+ /**
587
+ * recieved request thougth sortedResult??? case specail filter
588
+ * @param {string} requiredSearchType
589
+ * @param {string[]} filterArrays
590
+ *
591
+ * return [filters]
592
+ */
593
+ async function changeObjTypePath(
594
+ requiredObjType,
595
+ filtersStructure,
596
+ path = null,
597
+ // getSchemaFn,
598
+ PATHCONSTANCES = null,
599
+ ) {
600
+ try {
601
+ console.log('----- function validateSearchTypeFilterType -----', {
602
+ requiredObjType,
603
+ filtersStructure,
604
+ path,
605
+ // getSchemaFn,
606
+ });
607
+
608
+ let filterLogicalStructure = {};
609
+
610
+ let errorsObject = {};
611
+ let errorsFound = [];
612
+
613
+ if (path !== null) {
614
+ console.log('-------------- continue process path --------------');
615
+
616
+ let logicalElements = {};
617
+ let previousLogicalElementId = null;
618
+ let previousLogicalElement = null;
619
+ let currentLogicalElementId = null;
620
+ let currentLogicalElement = null;
621
+
622
+ if (path.length > 1) {
623
+
624
+ for (let i = 0; i < path.length; i++) {
625
+
626
+ let pathObject = path[i];
627
+ let logicalStructureElements = filtersStructure.logicalElements;
628
+ console.log('logicalStructureElements', logicalStructureElements);
629
+
630
+ let initialLogicalElementId = filtersStructure.initialLogicalElementId;
631
+ console.log('initialLogicalElementId', initialLogicalElementId);
480
632
 
481
- let uuid_closeBracket = uuidV4();
482
- _izContext.logger.debug('uuid_closeBracket: ', uuid_closeBracket);
633
+ if (i + 1 === path.length) {
634
+ console.log(`------------------- final path: ${i} ---------------------`);
483
635
 
484
- filtersStructure.logicalElements[lastLogicalElementId].nextLogicalElementId = uuid_closeBracket;
636
+ if (previousLogicalElementId !== null) {
485
637
 
486
- let closeBracket = {
487
- logicalElementType: "closeBracket",
488
- previousLogicalElementId: lastLogicalElementId,
489
- nextLogicalElementId: null
638
+ if (checkObjType(pathObject.objType, logicalElements[previousLogicalElementId].objType) !== true) {
639
+ errorsFound.push('objType is not equals in structure');
640
+ console.log('before return: ', {
641
+ filterLogicalStructure: {},
642
+ errorsObject,
643
+ errorsFound
644
+ });
645
+ return [{}, errorsObject, errorsFound];
646
+ };
647
+
648
+ filterLogicalStructure = {
649
+ objType: pathObject.objType,
650
+ initialLogicalElementId: previousLogicalElementId,
651
+ logicalElements: logicalElements
652
+ };
653
+ console.log('filterLogicalStructure: ', filterLogicalStructure);
654
+
655
+ } else {
656
+ if (checkObjType(requiredObjType, filtersStructure.objType) === true) {
657
+ filterLogicalStructure = filtersStructure;
658
+ } else {
659
+ errorsFound.push('objType is not equals in structure');
660
+ console.log('before return: ', {
661
+ filterLogicalStructure: {},
662
+ errorsObject,
663
+ errorsFound
664
+ });
665
+ return [{}, errorsObject, errorsFound];
666
+ };
667
+ };
668
+
669
+ } else {
670
+ console.log(`------------------- between path: ${i} ---------------------`);
671
+
672
+ let logicalElementsStructure = logicalStructureElements[initialLogicalElementId];
673
+ console.log('logicalElementsStructure', logicalElementsStructure);
674
+
675
+ if (previousLogicalElement !== null) {
676
+
677
+ currentLogicalElementId = uuidV4();
678
+ console.log('currentLogicalElementId: ', currentLogicalElementId);
679
+
680
+ currentLogicalElement = {
681
+ logicalElementType: 'childComplexFilter',
682
+ previousLogicalElementId: null,
683
+ nextLogicalElementId: null,
684
+ childLogicalElementId: filtersStructure.initialLogicalElementId,
685
+
686
+ objType: pathObject.pathLinkType.objType,
687
+ pathLinkType: {
688
+ objType: pathObject.objType,
689
+ relType: pathObject.pathLinkType.relType,
690
+ direction: pathObject.pathLinkType.direction
691
+ }
692
+ };
693
+ console.log('currentLogicalElement', currentLogicalElement);
694
+
695
+ let logicalStructure;
696
+ [previousLogicalElementId, previousLogicalElement, logicalStructure, errorsFound] = createChildComplexFilterStructure(
697
+ logicalElements,
698
+ previousLogicalElementId,
699
+ previousLogicalElement,
700
+ currentLogicalElementId,
701
+ currentLogicalElement,
702
+ filtersStructure
703
+ );
704
+ console.log('return create child ', {
705
+ previousLogicalElementId,
706
+ previousLogicalElement,
707
+ logicalStructure,
708
+ errorsFound
709
+ });
710
+
711
+ logicalElements = logicalStructure;
712
+
713
+ } else {
714
+
715
+ if (logicalElementsStructure.logicalElementType === 'childComplexFilter') {
716
+
717
+ let childLogicalElementId = logicalElementsStructure.childLogicalElementId;
718
+ console.log('childLogicalElementId', childLogicalElementId);
719
+
720
+ if (childLogicalElementId !== null) {
721
+ console.log('-------- has child filter structure --------');
722
+
723
+ let childLogicalElement = logicalStructureElements[childLogicalElementId];
724
+ console.log('childLogicalElement', childLogicalElement);
725
+
726
+ let pathCheck = false;
727
+
728
+ for (const pathObj of path) {
729
+ if (checkObjType(childLogicalElement.objType, pathObj.objType) === true) {
730
+ pathCheck = true;
731
+ };
732
+ };
733
+
734
+ if (pathCheck) {
735
+
736
+ if (logicalElementsStructure.nextLogicalElementId === null) {
737
+
738
+ //* delete level of objType
739
+ let checkChild = false;
740
+
741
+ if (PATHCONSTANCES != null) {
742
+
743
+ for (const objType of PATHCONSTANCES.objTypes) {
744
+ if (checkObjType(objType, childLogicalElement.objType) === true) {
745
+ if (!childLogicalElement.hasOwnProperty('childLogicalElementId')) {
746
+
747
+ // let childSchema = await getObjectSchema.getObjSchemaS3WithCache(
748
+ let childSchema = await getObjectSchema.getObjSchemaS3WithoutHierarchy(
749
+ {},// _izContext, maybe delete
750
+ childLogicalElement.objType
751
+ );
752
+ // let childSchema = await getObjectSchema.getObjSchemaWithoutHierarchy(
753
+ // getSchemaFn,
754
+ // childLogicalElement.objType
755
+ // );
756
+ console.log('childSchema: ', childSchema);
757
+
758
+ if (childSchema.hasOwnProperty('extendObjType')) {
759
+ if (checkObjType(requiredObjType, childSchema.extendObjType) === true) {
760
+ checkChild = false;
761
+ break;
762
+ };
763
+ };
764
+ };
765
+ checkChild = true;
766
+ break;
767
+ };
768
+ };
769
+ } else {
770
+ checkChild = true;
771
+ };
772
+
773
+ if (checkChild) {
774
+
775
+ delete filtersStructure.logicalElements[initialLogicalElementId];
776
+ console.log('filtersStructure: ', filtersStructure);
777
+
778
+ filtersStructure.objType = childLogicalElement.objType;
779
+ filtersStructure.initialLogicalElementId = childLogicalElementId;
780
+ filtersStructure.logicalElements[childLogicalElementId].previousLogicalElementId = null;
781
+ console.log('after filtersStructure: ', filtersStructure);
782
+
783
+ logicalElements = filtersStructure.logicalElements;
784
+
785
+ continue;
786
+
787
+ };
788
+ };
789
+ };
790
+
791
+ currentLogicalElementId = uuidV4();
792
+ console.log('currentLogicalElementId: ', currentLogicalElementId)
793
+
794
+ currentLogicalElement = {
795
+ logicalElementType: 'childComplexFilter',
796
+ previousLogicalElementId: null,
797
+ nextLogicalElementId: null,
798
+ childLogicalElementId: filtersStructure.initialLogicalElementId,
799
+
800
+ objType: pathObject.pathLinkType.objType,
801
+ pathLinkType: {
802
+ objType: pathObject.objType,
803
+ relType: pathObject.pathLinkType.relType,
804
+ direction: pathObject.pathLinkType.direction
805
+ }
806
+ };
807
+ console.log('currentLogicalElement', currentLogicalElement);
808
+
809
+ let logicalStructure = {};
810
+ [previousLogicalElementId, previousLogicalElement, logicalStructure, errorsFound] = createChildComplexFilterStructure(
811
+ logicalElements,
812
+ previousLogicalElementId,
813
+ previousLogicalElement,
814
+ currentLogicalElementId,
815
+ currentLogicalElement,
816
+ filtersStructure
817
+ )
818
+ console.log('return create child', {
819
+ previousLogicalElementId,
820
+ previousLogicalElement,
821
+ logicalStructure,
822
+ errorsFound
823
+ });
824
+
825
+ logicalElements = logicalStructure;
826
+ console.log('logicalElements: ', logicalElements);
827
+
828
+ // if (logicalElementsStructure.nextLogicalElementId !== null) {
829
+ // console.log("-------- no child filter structure --------", vvv);
830
+ // }
831
+
832
+ } else {
833
+ console.log('-------- no child filter structure --------', vvv);
834
+
835
+ }
836
+
837
+ } else {
838
+
839
+ currentLogicalElementId = uuidV4();
840
+ console.log('currentLogicalElementId: ', currentLogicalElementId);
841
+
842
+ currentLogicalElement = {
843
+ logicalElementType: 'childComplexFilter',
844
+ previousLogicalElementId: null,
845
+ nextLogicalElementId: null,
846
+ childLogicalElementId: filtersStructure.initialLogicalElementId,
847
+
848
+ objType: pathObject.pathLinkType.objType,
849
+ pathLinkType: {
850
+ objType: pathObject.objType,
851
+ relType: pathObject.pathLinkType.relType,
852
+ direction: pathObject.pathLinkType.direction
853
+ }
854
+ };
855
+ console.log('currentLogicalElement', currentLogicalElement);
856
+
857
+ let logicalStructure = {};
858
+ // change function name ==> set logicalElementId
859
+ [previousLogicalElementId, previousLogicalElement, logicalStructure, errorsFound] = createChildComplexFilterStructure(
860
+ logicalElements,
861
+ previousLogicalElementId,
862
+ previousLogicalElement,
863
+ currentLogicalElementId,
864
+ currentLogicalElement,
865
+ filtersStructure
866
+ )
867
+ console.log('return create child', {
868
+ previousLogicalElementId,
869
+ previousLogicalElement,
870
+ logicalStructure,
871
+ errorsFound
872
+ });
873
+ logicalElements = logicalStructure;
874
+ };
875
+ };
876
+ };
877
+ };
878
+ } else {
879
+ console.log('------------ path euals 1 -----------');
880
+ console.log('pathObject', path[0]);
881
+
882
+ if (checkObjType(requiredObjType, filtersStructure.objType) === true) {
883
+ filterLogicalStructure = filtersStructure;
884
+ } else {
885
+ errorsObject = {
886
+ [requiredObjType.objectType]: `is not equals objType in filter structure: objType: ${filtersStructure.objType.objectType}`
887
+ };
888
+ errorsFound.push(`${requiredObjType.objectType} is not equals objType in filter structure: objType: ${filtersStructure.objType.objectType}`);
889
+ return [filterLogicalStructure, errorsObject, errorsFound];
890
+ };
891
+ };
892
+ };
893
+
894
+ console.log('before return filterLogicalStructure: ', {
895
+ path,
896
+ filterLogicalStructure,
897
+ errorsObject,
898
+ errorsFound
899
+ });
900
+ return [filterLogicalStructure, errorsObject, errorsFound];
901
+
902
+ } catch (err) {
903
+ console.log('error ValidateSearchTypeFilterType: ', err)
904
+ throw (err);
490
905
  };
491
- _izContext.logger.debug('closeBracket: ', closeBracket);
492
-
493
- logicalElements = Object.assign({ [uuid_openBracket]: openBracketObject }, filtersStructure.logicalElements, { [uuid_closeBracket]: closeBracket });
494
- _izContext.logger.debug('logicalElements: ', logicalElements);
495
-
496
- return [
497
- uuid_openBracket,
498
- uuid_closeBracket,
499
- {
500
- objType: filtersStructure.objType,
501
- initialLogicalElementId: uuid_openBracket,
502
- logicalElements: logicalElements
503
- }
504
- ]
505
906
 
506
- }
907
+ };
908
+ //###################################################################################################################################################################################
507
909
 
508
- function combineLogicalElements(
509
- firstFilterStructure,
510
- secondFilterStructure,
511
- operator = "AND"
910
+ function createChildComplexFilterStructure(
911
+ logicalElements,
912
+ previousLogicalElementId,
913
+ previousLogicalElement,
914
+ currentLogicalElementId,
915
+ currentLogicalElement,
916
+ filtersStructure
512
917
  ) {
513
- _izContext.logger.debug('combineLogicalElements: ', {
514
- firstFilterStructure,
515
- secondFilterStructure,
516
- operator
918
+ console.log('createChildComplexFilterStructure: ', {
919
+ logicalElements,
920
+ previousLogicalElementId,
921
+ previousLogicalElement,
922
+ currentLogicalElementId,
923
+ currentLogicalElement,
924
+ filtersStructure
517
925
  });
518
926
 
519
- let objType = firstFilterStructure.objType;
927
+ let errorsFound = [];
520
928
 
521
- let [firstInitialLogicalElementId, firstLastLogicalElementId, firstFiltersStructureBrcket] = addBrackets(
522
- firstFilterStructure
523
- );
524
- _izContext.logger.debug("first filterStructure addBrackets", {
525
- firstInitialLogicalElementId,
526
- firstLastLogicalElementId,
527
- firstFiltersStructureBrcket
528
- })
529
-
530
- let [secondInitialLogicalElementId, secondLastLogicalElementId, secondFiltersStructureBrcket] = addBrackets(
531
- secondFilterStructure
929
+ if (!currentLogicalElement) {
930
+ errorsFound.push('no current logical element to process');
931
+ return [previousLogicalElementId, previousLogicalElement, logicalElements, errorsFound];
932
+ };
933
+
934
+ if (!previousLogicalElement) {
935
+ filtersStructure.logicalElements[filtersStructure.initialLogicalElementId].previousLogicalElementId = currentLogicalElementId;
936
+ logicalElements = Object.assign({ [currentLogicalElementId]: currentLogicalElement }, logicalElements, filtersStructure.logicalElements);
937
+ } else {
938
+
939
+ currentLogicalElement.childLogicalElementId = previousLogicalElementId;
940
+ console.log('currentLogicalElement', currentLogicalElement);
941
+
942
+ logicalElements[previousLogicalElementId].previousLogicalElementId = currentLogicalElementId;
943
+ console.log('logicalElements', logicalElements);
944
+
945
+ logicalElements = Object.assign({ [currentLogicalElementId]: currentLogicalElement }, logicalElements);
946
+ console.log('after logicalElements', logicalElements);
947
+
948
+ };
949
+
950
+ previousLogicalElementId = currentLogicalElementId;
951
+ previousLogicalElement = currentLogicalElement;
952
+
953
+ return [previousLogicalElementId, previousLogicalElement, logicalElements, errorsFound];
954
+ };
955
+
956
+ async function findObjTypePathToAnotherObjType(
957
+ fromObjType,
958
+ toObjType,
959
+ PATHCONSTANCES,
960
+ // getSchemaFn
961
+ ) {
962
+ console.log('----- function findObjTypePathToAnotherObjType -----', {
963
+ fromObjType,
964
+ toObjType,
965
+ PATHCONSTANCES,
966
+ // getSchemaFn
967
+ });
968
+
969
+ let [path, errorsObject, errorsFound] = await recursiveFindObjTypeTypePathToAnotherObjType(
970
+ PATHCONSTANCES,
971
+ fromObjType,
972
+ toObjType,
973
+ // getSchemaFn
532
974
  );
533
- _izContext.logger.debug("second filterStructure addBrackets", {
534
- secondInitialLogicalElementId,
535
- secondLastLogicalElementId,
536
- secondFiltersStructureBrcket
537
- })
538
-
539
- let uuid_operation = uuidV4();
540
- _izContext.logger.debug('uuid_operation: ', uuid_operation);
541
-
542
- let operationObject = {
543
- logicalElementType: 'operation',
544
- previousLogicalElementId: firstLastLogicalElementId,
545
- nextLogicalElementId: secondInitialLogicalElementId,
546
- operation: operator
975
+ console.log('return path', {
976
+ path,
977
+ errorsObject,
978
+ errorsFound
979
+ });
980
+
981
+ if (path !== null) {
982
+ console.log('--------------- will return -----------------');
983
+ return [path, errorsObject, errorsFound];
547
984
  };
548
- _izContext.logger.debug('operationObject: ', operationObject);
549
985
 
550
- firstFiltersStructureBrcket.logicalElements[firstLastLogicalElementId].nextLogicalElementId = uuid_operation;
551
- secondFiltersStructureBrcket.logicalElements[secondInitialLogicalElementId].previousLogicalElementId = uuid_operation;
986
+ return [path, errorsObject, errorsFound];
552
987
 
553
- let logicalElements = Object.assign(firstFiltersStructureBrcket.logicalElements, { [uuid_operation]: operationObject }, secondFiltersStructureBrcket.logicalElements);
554
- _izContext.logger.debug('logicalElements: ', logicalElements);
988
+ };
555
989
 
556
- return {
557
- objType: objType,
558
- initialLogicalElementId: firstInitialLogicalElementId,
559
- logicalElements: logicalElements
990
+ async function recursiveFindObjTypeTypePathToAnotherObjType(
991
+ PATHCONSTANCES,
992
+ fromObjType,
993
+ toObjType,
994
+ // getSchemaFn,
995
+ iter = 1
996
+ ) {
997
+ console.log('----- function recursiveFindObjTypeTypePathToAnotherObjType -----', {
998
+ PATHCONSTANCES,
999
+ fromObjType,
1000
+ toObjType,
1001
+ // getSchemaFn,
1002
+ iter
1003
+ });
1004
+
1005
+ let errorsObject = {};
1006
+ let errorsFound = [];
1007
+
1008
+ let continueProcess = false;
1009
+
1010
+ for (const objType of PATHCONSTANCES.objTypes) {
1011
+ console.log('objType: ', objType);
1012
+ if (checkObjType(fromObjType, objType) === true) {
1013
+ // if (hash(fromObjType) === hash(objType)) {
1014
+ continueProcess = true;
1015
+ };
560
1016
  };
561
1017
 
562
- }
1018
+ if (continueProcess) {
1019
+ console.log('------------ continue to find path --------------');
1020
+
1021
+ if (checkObjType(fromObjType, toObjType) === true) {
1022
+ // if (hash(fromObjType) === hash(toObjType)) {
1023
+ return [[{ objType: toObjType }], errorsObject, errorsFound];
1024
+ };
1025
+
1026
+ if (iter >= MAX_ITER) {
1027
+ return [null, errorsObject, errorsFound];
1028
+ };
1029
+
1030
+ // let objectRelationship = await getObjectSchema.getObjectRelationshipWithCache(
1031
+ const objectRelationship = await getObjectSchema.getObjectRelationship(
1032
+ {}, //_izContext maybe delete
1033
+ fromObjType
1034
+ );
1035
+ // const objectRelationship = await getObjectSchema.getObjectRelationship(
1036
+ // getSchemaFn,
1037
+ // fromObjType
1038
+ // )
1039
+ console.log("objectRelationship: ", { fromObjType, objectRelationship });
1040
+
1041
+ let path = null;
1042
+ let previousNextPath = null;
1043
+ let currentNextPath = null;
1044
+
1045
+ for (const relationshipObject of objectRelationship) {
1046
+ console.log('relationshipObject: ', relationshipObject);
563
1047
 
1048
+ let relType = relationshipObject.relType;
1049
+ console.log('relType: ', relType);
564
1050
 
1051
+ let otherObjType = relationshipObject.other.objType;
1052
+ console.log('otherObjType: ', otherObjType);
1053
+
1054
+ let relCheck = false;
1055
+
1056
+ for (const relPath of PATHCONSTANCES.relTypes) {
1057
+ if (hash(relType) === hash(relPath)) {
1058
+ relCheck = true;
1059
+ break;
1060
+ };
1061
+ };
1062
+
1063
+ if (!relCheck) {
1064
+ //* no relationshipTag in constance
1065
+ continue;
1066
+ };
1067
+
1068
+ // const objectSchema = await getObjectSchema.getObjSchemaS3WithCache(
1069
+ const objectSchema = await getObjectSchema.getObjSchemaS3WithoutHierarchy(
1070
+ {}, //_izContext maybe delete
1071
+ toObjType,
1072
+ );
1073
+ // const objectSchema = await getObjectSchema.getObjSchemaWithoutHierarchy(
1074
+ // getSchemaFn,
1075
+ // toObjType,
1076
+ // )
1077
+ console.log('objectSchema: ', objectSchema);
1078
+ console.log('before relationshipObject: ', {
1079
+ from: fromObjType,
1080
+ to: toObjType,
1081
+ next: otherObjType,
1082
+ relationshipObject
1083
+ });
1084
+
1085
+ if (objectSchema.hasOwnProperty('extendObjType')) {
1086
+ if (checkObjType(otherObjType, objectSchema.extendObjType) === true) {
1087
+ // if (hash(nextObjType) === hash(objectSchema.extendObjType)) {
1088
+ otherObjType = toObjType;
1089
+ };
1090
+ };
1091
+ console.log('after relationshipObject: ', {
1092
+ from: fromObjType,
1093
+ to: toObjType,
1094
+ next: otherObjType,
1095
+ relationshipObject
1096
+ });
1097
+
1098
+ let pathErrorsObject;
1099
+ let pathErrorsFound;
1100
+
1101
+ //* recurvsive path
1102
+ [currentNextPath, pathErrorsObject, pathErrorsFound] = await recursiveFindObjTypeTypePathToAnotherObjType(
1103
+ PATHCONSTANCES,
1104
+ otherObjType,
1105
+ toObjType,
1106
+ // getSchemaFn,
1107
+ iter + 1
1108
+ );
1109
+ console.log('return recursive path: ', {
1110
+ currentNextPath,
1111
+ pathErrorsObject,
1112
+ pathErrorsFound
1113
+ });
1114
+
1115
+ if (currentNextPath !== null) {
1116
+
1117
+ previousNextPath = currentNextPath;
1118
+
1119
+ let addPath = {
1120
+ objType: fromObjType,
1121
+ pathLinkType: {
1122
+ objType: otherObjType,
1123
+ relType: relType,
1124
+ direction: relationshipObject.other.direction
1125
+ }
1126
+ };
1127
+ console.log('addPath: ', addPath);
1128
+
1129
+ previousNextPath.unshift(addPath);
1130
+ console.log('path: ', path);
1131
+
1132
+ } else {
1133
+ continue;
1134
+ };
1135
+
1136
+ if (previousNextPath !== null) {
1137
+ if (path !== null) {
1138
+ if (path.length > previousNextPath.length) {
1139
+ path = previousNextPath;
1140
+ };
1141
+ console.log('path: ', path);
1142
+ return [path, errorsObject, errorsFound];
1143
+ } else {
1144
+ path = previousNextPath;
1145
+ };
1146
+ };
1147
+ };// end iterate relType
1148
+
1149
+ // if (previousNextPath !== null) {
1150
+ if (path !== null) {
1151
+ if (path.length > previousNextPath.length) {
1152
+ path = previousNextPath;
1153
+ };
1154
+ console.log('path: ', path);
1155
+ return [path, errorsObject, errorsFound];
1156
+ };
1157
+
1158
+ } else {
1159
+ errorsObject = {
1160
+ [fromObjType.objectType]: 'cannot found this objType that can process in path'
1161
+ };
1162
+ errorsFound.push(`${fromObjType.objectType}: cannot found objType that can process in path`);
1163
+ };
1164
+
1165
+ return [null, errorsObject, errorsFound];
1166
+
1167
+ };
565
1168
 
566
1169
 
567
1170
  export default {
1171
+ //* front-end
1172
+ changeObjTypePath,
1173
+ findObjTypePathToAnotherObjType,
1174
+
1175
+
1176
+ //* use in back-end
568
1177
  combineLogicalStructure,
569
- // combineOperation,
570
- combineLogicalElements,
571
- addBrackets,
572
- combineLogicalElements
1178
+ checkAndCreateBracket,
1179
+ // changeObjTypePath,
1180
+ // findObjTypePathToAnotherObjType,
1181
+
573
1182
  }