@izara_project/izara-shared-search-and-sort 1.0.8 → 1.0.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@izara_project/izara-shared-search-and-sort",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "description": "Shared Libraries frontend/backend for Search and Sort stack",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -22,29 +22,33 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
22
22
  // let { pattern } = validatorSchema.stringNotEmpty();
23
23
  // export default [...]
24
24
 
25
- import { objectHash as hash } from '@izara_project/izara-shared-core'; //const hash = require('@izara_project/izara-shared-core').objectHash;
25
+ import { objectHash as hash } from '@izara_project/izara-shared-core';
26
26
  import lodash from 'lodash';
27
27
  const { isEmpty } = lodash;
28
- import filtersSharedLib from './FiltersSharedLib.js'; //const filtersSharedLib = require('./FiltersSharedLib');
28
+ import filtersSharedLib from './FiltersSharedLib.js';
29
+ import LogicalStructureSharedLib from './LogicalStructureSharedLib'
29
30
 
30
31
  async function createRequiredData(
31
32
  objType,
33
+ initialLogicalElementId,
34
+ logicalElements,
32
35
  requiredDataFields,
33
36
  complexFilterCombinations,
34
37
  perParentCombinations,
35
38
  requiredDataLinkStepObjects,
36
39
  requiredDataLinkSteps,
37
40
  values,
38
- getSchemaFn
39
41
  ) {
40
42
  console.log('createRequiredData: ', {
41
43
  objType,
44
+ initialLogicalElementId,
45
+ logicalElements,
42
46
  requiredDataFields,
43
47
  complexFilterCombinations,
44
48
  perParentCombinations,
45
49
  requiredDataLinkStepObjects,
50
+ requiredDataLinkSteps,
46
51
  values,
47
- getSchemaFn
48
52
  });
49
53
 
50
54
  let errorsObject = {};
@@ -270,6 +274,8 @@ async function createLinkPath(
270
274
  perParentCombinations,
271
275
  complexFilterCombinations,
272
276
  values,
277
+ filtersStructure,
278
+ path,
273
279
  errorsObject,
274
280
  errorsFound,
275
281
  index = 0,
@@ -283,6 +289,8 @@ async function createLinkPath(
283
289
  perParentCombinations,
284
290
  complexFilterCombinations,
285
291
  values,
292
+ filtersStructure,
293
+ path,
286
294
  errorsObject,
287
295
  errorsFound,
288
296
  index,
@@ -292,6 +300,8 @@ async function createLinkPath(
292
300
  let fieldName = null;
293
301
  let returnValue = {}; //* must return only linkPath params
294
302
 
303
+ let sortObj = null;
304
+
295
305
  let linkStepId = linkSteps[index];
296
306
  console.log('linkStepId: ', linkStepId);
297
307
 
@@ -302,12 +312,32 @@ async function createLinkPath(
302
312
  // last link that has only fieldName
303
313
  console.log('---------- is final link ----------', { index, linkStep });
304
314
 
305
- return [linkStep.fieldName, returnValue, errorsObject, errorsFound]
315
+ let sortValueObj = null;
316
+
317
+ if (linkStep.hasOwnProperty("dataType")) {
318
+
319
+ sortValueObj = {
320
+ dataType: linkStep.dataType,
321
+ value: linkStep.value
322
+ }
323
+
324
+ }
325
+
326
+ return [linkStep.fieldName, returnValue, errorsObject, errorsFound, sortValueObj]
306
327
 
307
328
  } else {
308
329
  // has nextLink
309
330
  console.log('---------- is next link ----------', { index, linkStep });
310
331
 
332
+ if (linkStep.hasOwnProperty("pathLinkType")) {
333
+ path.push({
334
+ objType: objType,
335
+ pathLinkType: linkStep.pathLinkType
336
+ });
337
+ console.log("path", path);
338
+ // console.log('---------- is next link ----------', hhhh);
339
+ }
340
+
311
341
  let conditionsPromise = checkConditionsLink(
312
342
  // let [conditions, conditionErrObject, conditionErrFound] = await this.checkConditionsLink(
313
343
  linkStep.pathLinkType.objType,
@@ -318,17 +348,20 @@ async function createLinkPath(
318
348
  linkSteps,
319
349
  requiredDataLinkStepObjects,
320
350
  requiredDataLinkSteps,
351
+ path,
321
352
  errorsObject,
322
353
  errorsFound
323
354
  );
324
355
 
325
- [fieldName, returnValue, errorsObject, errorsFound] = await createLinkPath(
356
+ [fieldName, returnValue, errorsObject, errorsFound, sortObj] = await createLinkPath(
326
357
  linkSteps,
327
358
  requiredDataLinkStepObjects,
328
359
  requiredDataLinkSteps,
329
360
  perParentCombinations,
330
361
  complexFilterCombinations,
331
362
  values,
363
+ filtersStructure,
364
+ path,
332
365
  errorsObject,
333
366
  errorsFound,
334
367
  index + 1
@@ -606,9 +639,11 @@ async function checkConditionsLink(
606
639
  perParentCombinations,
607
640
  complexFilterCombinations,
608
641
  values,
642
+ filtersStructure,
609
643
  linkSteps,
610
644
  requiredDataLinkStepObjects,
611
645
  requiredDataLinkSteps,
646
+ path,
612
647
  errorsObject,
613
648
  errorsFound
614
649
  ) {
@@ -618,23 +653,76 @@ async function checkConditionsLink(
618
653
  perParentCombinations,
619
654
  complexFilterCombinations,
620
655
  values,
656
+ filtersStructure,
621
657
  linkSteps,
622
658
  requiredDataLinkStepObjects,
623
659
  requiredDataLinkSteps,
660
+ path,
624
661
  errorsObject,
625
662
  errorsFound
626
663
  });
627
664
 
628
665
 
629
- let conditionLinkObject = {}
666
+ let conditionLinkObject = {};
667
+ let filterMainRequest = null
668
+
669
+ if (linkStepObject.hasOwnProperty("addFilterMain") && linkStepObject.addFilterMain === true) {
670
+
671
+ path.push({ objType: objType });
672
+ console.log('path', path);
673
+
674
+ let [filterStructureCurrent, filterErrorObject, filterErrorFound] = await LogicalStructureSharedLib.changeObjTypePath(
675
+ objType,
676
+ filtersStructure,
677
+ path
678
+ );
679
+
680
+ console.log('changeObjTypePath', {
681
+ filterStructureCurrent,
682
+ filterErrorObject,
683
+ filterErrorFound
684
+ });
685
+
686
+ if (filterErrorFound.length > 0) {
687
+ Object.assign(errorsObject, filterErrorObject);
688
+ errorsFound = errorsFound.concat('filterErrorFound');
689
+ } else {
690
+ filterMainRequest = filterStructureCurrent;
691
+ }
692
+
693
+ }
630
694
 
631
695
  if (linkStepObject.hasOwnProperty('filterElements')) {
632
696
  console.log('------------ has filterElements ------------');
633
697
 
698
+ let filters = {};
699
+
700
+ if (filterMainRequest !== null) {
701
+ if (hash(filterMainRequest.objType) !== hash(linkStepObject.filterElements.objType)) {
702
+ errorsObject[linkStepObject.filterElements.objType.objectType] = 'this linkStep has error when combine filterMain in link';
703
+ errorsFound.push(`${linkStepObject.filterElements.objType.objectType}: this linkStep has error when combine filterMain in link`);
704
+ return [null, errorsObject, errorsFound];
705
+ }
706
+
707
+ filters = filtersSharedLib.combineLogicalElements(
708
+ filterMainRequest,
709
+ linkStepObject.filterElements
710
+ );
711
+
712
+
713
+ } else {
714
+ filters = {
715
+ objType: linkStepObject.filterElements.objType,
716
+ initialLogicalElementId: linkStepObject.filterElements.initialLogicalElementId,
717
+ logicalElements: linkStepObject.filterElements.logicalElements,
718
+ }
719
+ }
720
+ console.log('filters: ', filters);
721
+
634
722
  let [complexFilterRequest, status, filterErrorsObject, filterErrorsFound] = filtersSharedLib.createFiltersRequest(
635
- linkStepObject.filterElements.objType,
636
- linkStepObject.filterElements.initialLogicalElementId,
637
- linkStepObject.filterElements.logicalElements,
723
+ filters.objType,
724
+ filters.initialLogicalElementId,
725
+ filters.logicalElements,
638
726
  values
639
727
  );
640
728
  console.log('return complexFilter for filterElements: ', {
@@ -646,13 +734,40 @@ async function checkConditionsLink(
646
734
 
647
735
  if (filterErrorsFound.length > 0) {
648
736
  Object.assign(errorsObject, filterErrorsObject)
649
- errorsFound = errorsFound.concat(filterErrorsFound);
650
- return [null, errorsObject, errorsFound]
737
+ errorsFound = errorsFound.concat(filterErrorsFound)
651
738
  };
739
+
652
740
  conditionLinkObject.filterElements = complexFilterRequest.filterElements;
653
741
  console.log('conditionLinkObject in condition link: ', conditionLinkObject);
742
+
654
743
  }
655
744
 
745
+
746
+ // if (linkStepObject.hasOwnProperty('filterElements')) {
747
+ // console.log('------------ has filterElements ------------');
748
+
749
+ // let [complexFilterRequest, status, filterErrorsObject, filterErrorsFound] = filtersSharedLib.createFiltersRequest(
750
+ // linkStepObject.filterElements.objType,
751
+ // linkStepObject.filterElements.initialLogicalElementId,
752
+ // linkStepObject.filterElements.logicalElements,
753
+ // values
754
+ // );
755
+ // console.log('return complexFilter for filterElements: ', {
756
+ // complexFilterRequest,
757
+ // status,
758
+ // filterErrorsObject,
759
+ // filterErrorsFound
760
+ // });
761
+
762
+ // if (filterErrorsFound.length > 0) {
763
+ // Object.assign(errorsObject, filterErrorsObject)
764
+ // errorsFound = errorsFound.concat(filterErrorsFound);
765
+ // return [null, errorsObject, errorsFound]
766
+ // };
767
+ // conditionLinkObject.filterElements = complexFilterRequest.filterElements;
768
+ // console.log('conditionLinkObject in condition link: ', conditionLinkObject);
769
+ // }
770
+
656
771
  if (linkStepObject.hasOwnProperty('aggregate')) {
657
772
  console.log('------------ has aggregate ------------');
658
773
  if (!linkStepObject.hasOwnProperty('sortFields')) {
@@ -696,6 +811,8 @@ async function checkConditionsLink(
696
811
  perParentCombinations,
697
812
  complexFilterCombinations,
698
813
  values,
814
+ filtersStructure,
815
+ [],
699
816
  errorsObject,
700
817
  errorsFound
701
818
  );
@@ -766,10 +883,19 @@ async function checkConditionsLink(
766
883
  });
767
884
  };
768
885
 
769
- sortFieldObjects.push({
886
+ let sortObject = {
770
887
  fieldName: fieldName,
771
- dataType: sortField.dataType
772
- });
888
+ // dataType: sortField.dataType
889
+ }
890
+
891
+ if (sortObj !== null) {
892
+ if (sortObj.dataType === "array") {
893
+ sortObject.dataType = sortObj.dataType
894
+ sortObject.values = sortObj.value;
895
+ }
896
+ }
897
+
898
+ sortFieldObjects.push(sortObject);
773
899
  console.log('sortFieldObjects: ', sortFieldObjects);
774
900
 
775
901
  };
@@ -17,10 +17,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
17
17
 
18
18
  "use strict";
19
19
 
20
- import { objectHash as hash } from '@izara_project/izara-shared-core'; //const hash = require('@izara_project/izara-shared-core').objectHash;
20
+ import { objectHash as hash } from '@izara_project/izara-shared-core';
21
21
  import lodash from 'lodash';
22
22
  const { isEmpty } = lodash;
23
- import complexFilterShared from '@izara_project/izara-core-library-complex-filter';
24
23
 
25
24
  function validateFilterElement(
26
25
  filterElements,
@@ -162,18 +161,6 @@ function createFiltersRequest(
162
161
  };
163
162
  console.log('complexFilterRequest: ', complexFilterRequest);
164
163
 
165
- // let validate = validateFilterElement(
166
- // complexFilterRequest.filterElements,
167
- // logicalElements
168
- // );
169
- // _izContext.logger.debug('validate: ', validate);
170
-
171
- // if (validate === false) {
172
- // errorsObject[initialLogicalElementId] = 'filterElements has create fail';
173
- // errorsFound.push("filterElements has create fail");
174
- // return [null, "error", errorsObject, errorsFound]
175
- // }
176
-
177
164
  return [
178
165
  complexFilterRequest,
179
166
  status,
@@ -1005,7 +992,6 @@ function filterLogicalElements(
1005
992
 
1006
993
  if (lastNextLogicalElementId !== null) {
1007
994
 
1008
- // [runningFilterMainId, runningFilterObject, operation, operationErrorsFound] = complexFilterShared.validateOperation(
1009
995
  [runningFilterMainId, runningFilterObject, operation, operationErrorsFound] = validateOperation(
1010
996
  objType,
1011
997
  runningFilterMainId,
@@ -1203,7 +1189,7 @@ export default {
1203
1189
  //* create filter
1204
1190
  createFiltersRequest,
1205
1191
  validateCombinationStructure,
1206
- // validateOperation,
1207
1192
  filterLogicalElements,
1193
+ // validateOperation,
1208
1194
  // splitFilterElements,
1209
1195
  }
@@ -18,8 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
18
18
  'use strict';
19
19
  import LogicalStructureSharedLib from './LogicalStructureSharedLib.js';
20
20
 
21
- function initSchemaFn(getObjSchemaS3WithoutHierarchy, getObjectRelationship) { //getObjectLinks
22
- return LogicalStructureSharedLib.initSchemaFn(getObjSchemaS3WithoutHierarchy, getObjectRelationship);
21
+ function initSchemaFn(getObjSchemaS3WithHierarchyShared, getObjectLinksShared) {
22
+ return LogicalStructureSharedLib.initSchemaFn(getObjSchemaS3WithHierarchyShared, getObjectLinksShared);
23
23
  }
24
24
 
25
25
  export default {
@@ -18,24 +18,23 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
18
18
  'use strict';
19
19
 
20
20
 
21
- import { objectHash as hash } from '@izara_project/izara-shared-core'; //const hash = require('@izara_project/izara-shared-core').objectHash;
21
+ import { objectHash as hash } from '@izara_project/izara-shared-core';
22
22
  import lodash from 'lodash';
23
23
  const { isEmpty } = lodash;
24
- import { v4 as uuidV4 } from 'uuid'; //const { v4: uuidv4 } = require('uuid');
25
- // import { getObjectSchema } from '@izara_project/izara-core-library-service-schemas';
24
+ import { v4 as uuidV4 } from 'uuid';
26
25
  const MAX_ITER = 4;
27
26
 
28
27
  let getObjectSchema = {};
29
28
 
30
- function initSchemaFn(getObjSchemaS3WithoutHierarchy, getObjectRelationship) { //getObjectLinks
29
+ function initSchemaFn(getObjSchemaS3WithHierarchyShared, getObjectLinksShared) {
31
30
  getObjectSchema = {
32
- getObjSchemaS3WithoutHierarchy,
33
- getObjectRelationship: getObjectRelationship // getObjectRelationship: getObjectLinks
31
+ getObjSchemaS3WithHierarchyShared,
32
+ getObjectLinksShared
34
33
  }
35
-
36
34
  return getObjectSchema;
37
35
  }
38
36
 
37
+
39
38
  function combineLogicalStructure(
40
39
  objType,
41
40
  initialLogicalElementId,
@@ -752,7 +751,7 @@ async function changeObjTypePath(
752
751
  if (!childLogicalElement.hasOwnProperty('childLogicalElementId')) {
753
752
 
754
753
  // let childSchema = await getObjectSchema.getObjSchemaS3WithCache(
755
- let childSchema = await getObjectSchema.getObjSchemaS3WithoutHierarchyV2(
754
+ let childSchema = await getObjectSchema.getObjSchemaS3WithHierarchyShared(
756
755
  childLogicalElement.objType
757
756
  );
758
757
  console.log('childSchema: ', childSchema);
@@ -810,7 +809,6 @@ async function changeObjTypePath(
810
809
 
811
810
  let logicalStructure = {};
812
811
  [previousLogicalElementId, previousLogicalElement, logicalStructure, errorsFound] = createChildComplexFilterStructure(
813
- _izContext,
814
812
  logicalElements,
815
813
  previousLogicalElementId,
816
814
  previousLogicalElement,
@@ -860,7 +858,6 @@ async function changeObjTypePath(
860
858
  let logicalStructure = {};
861
859
  // change function name ==> set logicalElementId
862
860
  [previousLogicalElementId, previousLogicalElement, logicalStructure, errorsFound] = createChildComplexFilterStructure(
863
- _izContext,
864
861
  logicalElements,
865
862
  previousLogicalElementId,
866
863
  previousLogicalElement,
@@ -1028,9 +1025,7 @@ async function recursiveFindObjTypeTypePathToAnotherObjType(
1028
1025
  return [null, errorsObject, errorsFound];
1029
1026
  };
1030
1027
 
1031
- // let objectRelationship = await getObjectSchema.getObjectRelationshipWithCache(
1032
- const objectRelationship = await getObjectSchema.getObjectRelationship(
1033
- {}, //_izContext maybe delete
1028
+ const objectRelationship = await getObjectSchema.getObjectLinksShared(
1034
1029
  fromObjType
1035
1030
  );
1036
1031
  console.log("objectRelationship: ", { fromObjType, objectRelationship });
@@ -1063,8 +1058,7 @@ async function recursiveFindObjTypeTypePathToAnotherObjType(
1063
1058
  };
1064
1059
 
1065
1060
  // const objectSchema = await getObjectSchema.getObjSchemaS3WithCache(
1066
- const objectSchema = await getObjectSchema.getObjSchemaS3WithoutHierarchy(
1067
- {}, //_izContext maybe delete
1061
+ const objectSchema = await getObjectSchema.getObjSchemaS3WithHierarchyShared(
1068
1062
  toObjType,
1069
1063
  );
1070
1064
  console.log('objectSchema: ', objectSchema);
@@ -18,12 +18,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
18
18
  "use strict";
19
19
 
20
20
  //* searchResultMain record
21
- import { objectHash as hash } from '@izara_project/izara-shared-core'; //const hash = require('@izara_project/izara-shared-core').objectHash;
21
+ import { objectHash as hash } from '@izara_project/izara-shared-core';
22
22
  import lodash from 'lodash';
23
23
  const { isEmpty } = lodash;
24
- import filtersSharedLib from './FiltersSharedLib.js'; //const filtersSharedLib = require('./FiltersSharedLib');
24
+ import filtersSharedLib from './FiltersSharedLib.js';
25
25
  import dataFieldsSharedLib from './DataFieldsSharedLib.js';
26
- import LogicalStructureSharedLib from './LogicalStructureSharedLib.js';
26
+
27
27
 
28
28
  async function createSearchRequest(
29
29
  objType,
@@ -105,11 +105,11 @@ async function createSearchRequest(
105
105
  let requiredData = await requiredDataPromise;
106
106
  console.log('return create requiredData: ', requiredData);
107
107
 
108
- // if (requiredData.status === 'invalid' || requiredData.errorsFound.length > 0) {
109
- // Object.assign(errorsObject, requiredData.errorsObject)
110
- // errorsFound.push('requiredData cannot create');
111
- // errorsFound = errorsFound.concat(requiredData.errorsFound);
112
- // }
108
+ if (requiredData.status === 'invalid' || requiredData.errorsFound.length > 0) {
109
+ Object.assign(errorsObject, requiredData.errorsObject)
110
+ errorsFound.push('requiredData cannot create');
111
+ errorsFound = errorsFound.concat(requiredData.errorsFound);
112
+ }
113
113
 
114
114
  if (errorsFound.length > 0) {
115
115
  return [null, 'invalid', errorsObject, errorsFound]