spice-js 2.6.35 → 2.6.36

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.
@@ -49,8 +49,6 @@ if (!Promise.allSettled) {
49
49
 
50
50
  class SpiceModel {
51
51
  constructor(args) {
52
- var _args$props$i;
53
-
54
52
  if (args === void 0) {
55
53
  args = {};
56
54
  }
@@ -168,7 +166,7 @@ class SpiceModel {
168
166
  for (var i in args.props) {
169
167
  if (args.args != undefined) {
170
168
  if (args.args[i] != undefined) {
171
- switch ((_args$props$i = args.props[i]) == null ? void 0 : _args$props$i.type) {
169
+ switch (args.props[i].type) {
172
170
  case String:
173
171
  case "string":
174
172
  {
@@ -260,7 +258,7 @@ class SpiceModel {
260
258
  var _this$_ctx, _this$_ctx$state;
261
259
 
262
260
  if ((_this$_ctx = _this[_ctx]) == null ? void 0 : (_this$_ctx$state = _this$_ctx.state) == null ? void 0 : _this$_ctx$state.process_fields) {
263
- var returned = yield new _this[_ctx].state.process_fields().process(_this[_ctx], data, _this == null ? void 0 : _this.type);
261
+ var returned = yield new _this[_ctx].state.process_fields().process(_this[_ctx], data, _this.type);
264
262
  return returned;
265
263
  } else {
266
264
  return data;
@@ -531,7 +529,7 @@ class SpiceModel {
531
529
  return _asyncToGenerator(function* () {
532
530
  var obj = _this3.getCacheProviderObject();
533
531
 
534
- var monitor_record = yield obj.get("monitor::" + (_this3 == null ? void 0 : _this3.type));
532
+ var monitor_record = yield obj.get("monitor::" + _this3.type);
535
533
 
536
534
  if (monitor_record == undefined) {
537
535
  return false;
@@ -548,7 +546,7 @@ class SpiceModel {
548
546
  setMonitor() {
549
547
  var current_time = new Date().getTime();
550
548
  var obj = this.getCacheProviderObject();
551
- var key = "monitor::" + (this == null ? void 0 : this.type);
549
+ var key = "monitor::" + this.type;
552
550
  var value = {
553
551
  time: current_time
554
552
  };
@@ -567,43 +565,37 @@ class SpiceModel {
567
565
  }
568
566
 
569
567
  if (_.isString(args.id)) {
570
- var _results, _results3, _results5, _results6;
571
-
572
568
  if (args.skip_hooks != true) {
573
569
  yield _this4.run_hook(args, "get", "before");
574
570
  }
575
571
 
576
- var key = "get::" + (_this4 == null ? void 0 : _this4.type) + "::" + args.id;
572
+ var key = "get::" + _this4.type + "::" + args.id;
577
573
  var results = {};
578
574
 
579
- if (_this4.shouldUseCache(_this4 == null ? void 0 : _this4.type)) {
580
- var cached_results = yield _this4.getCacheProviderObject(_this4 == null ? void 0 : _this4.type).get(key);
575
+ if (_this4.shouldUseCache(_this4.type)) {
576
+ var cached_results = yield _this4.getCacheProviderObject(_this4.type).get(key);
581
577
  results = cached_results == null ? void 0 : cached_results.value;
582
578
 
583
- if ((cached_results == null ? void 0 : cached_results.value) == undefined || (yield _this4.shouldForceRefresh(cached_results)) || (_this4 == null ? void 0 : _this4.type) == "workflow") {
579
+ if ((cached_results == null ? void 0 : cached_results.value) == undefined || (yield _this4.shouldForceRefresh(cached_results)) || _this4.type == "workflow") {
584
580
  results = yield _this4.database.get(args.id);
585
- yield _this4.getCacheProviderObject(_this4 == null ? void 0 : _this4.type).set(key, {
581
+ yield _this4.getCacheProviderObject(_this4.type).set(key, {
586
582
  value: results,
587
583
  time: new Date().getTime()
588
- }, _this4.getCacheConfig(_this4 == null ? void 0 : _this4.type));
584
+ }, _this4.getCacheConfig(_this4.type));
589
585
  }
590
586
  } else {
591
587
  results = yield _this4.database.get(args.id);
592
588
  }
593
589
 
594
- if (((_results = results) == null ? void 0 : _results.type) != undefined) {
595
- var _results2;
596
-
597
- if (((_results2 = results) == null ? void 0 : _results2.type) != (_this4 == null ? void 0 : _this4.type)) throw new Error((_this4 == null ? void 0 : _this4.type) + " does not exist type");
590
+ if (results.type != undefined) {
591
+ if (results.type != _this4.type) throw new Error(_this4.type + " does not exist type");
598
592
  }
599
593
 
600
- if (((_results3 = results) == null ? void 0 : _results3._type) != undefined) {
601
- var _results4;
602
-
603
- if (((_results4 = results) == null ? void 0 : _results4._type) != (_this4 == null ? void 0 : _this4.type)) throw new Error((_this4 == null ? void 0 : _this4.type) + " does not exist _type");
594
+ if (results._type != undefined) {
595
+ if (results._type != _this4.type) throw new Error(_this4.type + " does not exist _type");
604
596
  }
605
597
 
606
- if (((_results5 = results) == null ? void 0 : _results5.deleted) == undefined || ((_results6 = results) == null ? void 0 : _results6.deleted) == false) {
598
+ if (results.deleted == undefined || results.deleted == false) {
607
599
  if (args.skip_read_serialize != true && args.skip_serialize != true) {
608
600
  results = yield _this4.do_serialize(results, "read", {}, args, (yield _this4.propsToBeRemoved(results)));
609
601
  }
@@ -614,7 +606,7 @@ class SpiceModel {
614
606
 
615
607
  return results;
616
608
  } else {
617
- throw new Error((_this4 == null ? void 0 : _this4.type) + " does not exist");
609
+ throw new Error(_this4.type + " does not exist");
618
610
  }
619
611
  }
620
612
  } catch (e) {
@@ -652,29 +644,29 @@ class SpiceModel {
652
644
 
653
645
  _.remove(args.ids, o => o == undefined);
654
646
 
655
- var key = "multi-get::" + (_this6 == null ? void 0 : _this6.type) + "::" + _.join(args.ids, "|");
647
+ var key = "multi-get::" + _this6.type + "::" + _.join(args.ids, "|");
656
648
 
657
649
  var results = [];
658
650
 
659
651
  if (args.ids.length > 0) {
660
- if (_this6.shouldUseCache(_this6 == null ? void 0 : _this6.type)) {
661
- var cached_results = yield _this6.getCacheProviderObject(_this6 == null ? void 0 : _this6.type).get(key);
652
+ if (_this6.shouldUseCache(_this6.type)) {
653
+ var cached_results = yield _this6.getCacheProviderObject(_this6.type).get(key);
662
654
  results = cached_results == null ? void 0 : cached_results.value;
663
655
 
664
656
  if ((cached_results == null ? void 0 : cached_results.value) == undefined || (yield _this6.shouldForceRefresh(cached_results))) {
665
657
  results = yield _this6.database.multi_get(args.ids, true);
666
658
 
667
- _this6.getCacheProviderObject(_this6 == null ? void 0 : _this6.type).set(key, {
659
+ _this6.getCacheProviderObject(_this6.type).set(key, {
668
660
  value: results,
669
661
  time: new Date().getTime()
670
- }, _this6.getCacheConfig(_this6 == null ? void 0 : _this6.type));
662
+ }, _this6.getCacheConfig(_this6.type));
671
663
  }
672
664
  } else {
673
665
  results = yield _this6.database.multi_get(args.ids, true);
674
666
  }
675
667
  }
676
668
 
677
- _.remove(results, o => (o == null ? void 0 : o.type) != (_this6 == null ? void 0 : _this6.type));
669
+ _.remove(results, o => o.type != _this6.type);
678
670
 
679
671
  if (args.skip_read_serialize != true && args.skip_serialize != true) {
680
672
  results = yield _this6.do_serialize(results, "read", {}, args, (yield _this6.propsToBeRemoved(results)));
@@ -699,17 +691,17 @@ class SpiceModel {
699
691
  try {
700
692
  if (_.isString(data)) {
701
693
  var result = yield _this7.database.get(data);
702
- if (result == null ? void 0 : result.type) if (result.type != (_this7 == null ? void 0 : _this7.type)) {
694
+ if (result.type) if (result.type != _this7.type) {
703
695
  return false;
704
696
  }
705
- if (result == null ? void 0 : result._type) if (result._type != (_this7 == null ? void 0 : _this7.type)) {
697
+ if (result._type) if (result._type != _this7.type) {
706
698
  return false;
707
699
  }
708
700
  } else {
709
- if (data == null ? void 0 : data.type) if (data.type != (_this7 == null ? void 0 : _this7.type)) {
701
+ if (data.type) if (data.type != _this7.type) {
710
702
  return false;
711
703
  }
712
- if (data == null ? void 0 : data._type) if (data._type != (_this7 == null ? void 0 : _this7.type)) {
704
+ if (data._type) if (data._type != _this7.type) {
713
705
  return false;
714
706
  }
715
707
  }
@@ -731,7 +723,7 @@ class SpiceModel {
731
723
  var item_exist = yield _this8.exist(results);
732
724
 
733
725
  if (!item_exist) {
734
- throw new Error((_this8 == null ? void 0 : _this8.type) + " does not exist. in update");
726
+ throw new Error(_this8.type + " does not exist. in update");
735
727
  }
736
728
 
737
729
  delete results["id"];
@@ -791,7 +783,7 @@ class SpiceModel {
791
783
  var form;
792
784
  _this9.created_at = new SDate().now();
793
785
  args = _.defaults(args, {
794
- id_prefix: _this9 == null ? void 0 : _this9.type
786
+ id_prefix: _this9.type
795
787
  });
796
788
 
797
789
  if (args.body) {
@@ -848,7 +840,7 @@ class SpiceModel {
848
840
  var item_exist = yield _this10.exist(args.id);
849
841
 
850
842
  if (!item_exist) {
851
- throw new Error((_this10 == null ? void 0 : _this10.type) + " does not exist.");
843
+ throw new Error(_this10.type + " does not exist.");
852
844
  }
853
845
 
854
846
  var results = yield _this10.database.get(args.id);
@@ -891,7 +883,7 @@ class SpiceModel {
891
883
 
892
884
  return _asyncToGenerator(function* () {
893
885
  try {
894
- var _args4, _args5, _args6;
886
+ var _args4, _args5, _args6, _args7;
895
887
 
896
888
  if (!args) {
897
889
  args = {};
@@ -946,18 +938,58 @@ class SpiceModel {
946
938
  }
947
939
 
948
940
  function extractNestings(string, localType) {
949
- var returnVal = [];
950
- var regex = /(\w+)\./g;
941
+ var returnVal = []; // Regex for nested properties, including backtick-quoted ones
942
+
943
+ var regex = /(`?\w+`?)\.(`?\w+`?)/g;
951
944
  var match;
952
945
 
953
- while (match = regex.exec(string)) {
954
- if (match[1] != localType) returnVal.push(match[1]);
946
+ while ((match = regex.exec(string)) !== null) {
947
+ var first = match[1].replace(/`/g, "");
948
+ var second = match[2].replace(/`/g, "");
949
+
950
+ if (first !== localType) {
951
+ returnVal.push(first);
952
+ }
953
+ } // Regex for ANY/EVERY clauses
954
+
955
+
956
+ var queryRegex = /(ANY|EVERY)\s+\w+\s+IN\s+`?(\w+)`?/g;
957
+ var queryMatch;
958
+
959
+ while ((queryMatch = queryRegex.exec(string)) !== null) {
960
+ returnVal.push(queryMatch[2]);
955
961
  }
956
962
 
957
- return returnVal;
963
+ return [...new Set(returnVal)]; // Remove duplicates
958
964
  }
965
+ /* function extractNestings(string, localType) {
966
+ let returnVal = [];
967
+ let regex = /(\w+)\.(\w+)/g;
968
+ let match;
969
+ while ((match = regex.exec(string)) !== null) {
970
+ if (match[1] !== localType) {
971
+ returnVal.push(match[1]);
972
+ } else {
973
+ returnVal.push(match[2]);
974
+ }
975
+ }
976
+ return [...new Set(returnVal)]; // Remove duplicates
977
+ } */
978
+
979
+ /* function extractNestings(string, localType) {
980
+ let returnVal = [];
981
+ let regex = /(\w+)\./g;
982
+ let match = regex.exec(string);
983
+ console.log("Local:", localType, match);
984
+ while (match) {
985
+ if (match[1] != localType) returnVal.push(match[1]);
986
+ }
987
+ return returnVal;
988
+ } */
989
+ //console.log("Query", args?.query);
990
+
959
991
 
960
- var nestings = [...extractNestings((_args4 = args) == null ? void 0 : _args4.query, _this11 == null ? void 0 : _this11.type), ...extractNestings((_args5 = args) == null ? void 0 : _args5.columns, _this11 == null ? void 0 : _this11.type), ...extractNestings((_args6 = args) == null ? void 0 : _args6.sort, _this11 == null ? void 0 : _this11.type)];
992
+ var nestings = [...extractNestings((_args4 = args) == null ? void 0 : _args4.query, _this11.type), ...extractNestings((_args5 = args) == null ? void 0 : _args5.columns, _this11.type), ...extractNestings((_args6 = args) == null ? void 0 : _args6.sort, _this11.type)];
961
993
 
962
994
  var mappedNestings = _.compact(_.map(_.uniq(nestings), nesting => {
963
995
  var prop = _this11.props[nesting];
@@ -968,6 +1000,7 @@ class SpiceModel {
968
1000
  return {
969
1001
  alias: nesting,
970
1002
  reference: prop.map.reference.toLowerCase(),
1003
+ type: prop.type,
971
1004
  value_field: prop.map.value_field
972
1005
  };
973
1006
  }
@@ -980,7 +1013,11 @@ class SpiceModel {
980
1013
  var joinSection = "";
981
1014
 
982
1015
  _.each(nestings, nesting => {
983
- joinSection += "LEFT JOIN `" + nesting.reference + "` AS `" + nesting.alias + "` ON KEYS `" + that.type + "`.`" + nesting.alias + "` ";
1016
+ if (nesting.type == _2.DataType.ARRAY || nesting.type == Array || nesting.type == "array") {
1017
+ joinSection += "NEST `" + nesting.reference + "` AS `" + nesting.alias + "` ON KEYS `" + that.type + "`.`" + nesting.alias + "` ";
1018
+ } else {
1019
+ joinSection += "LEFT JOIN `" + nesting.reference + "` AS `" + nesting.alias + "` ON KEYS `" + that.type + "`.`" + nesting.alias + "` ";
1020
+ }
984
1021
  });
985
1022
 
986
1023
  return joinSection;
@@ -988,6 +1025,7 @@ class SpiceModel {
988
1025
 
989
1026
  var _join = createJoinSection(mappedNestings);
990
1027
 
1028
+ console.log("Props", that.type, nestings, _join, (_args7 = args) == null ? void 0 : _args7.query);
991
1029
  args._join = _join;
992
1030
 
993
1031
  if (args.is_full_text && args.is_full_text === "true" || args.is_custom_query && args.is_custom_query === "true") {
@@ -997,9 +1035,9 @@ class SpiceModel {
997
1035
  query = _this11.makeQueryFromFilter(args.filters);
998
1036
  } else {
999
1037
  if (args.query) {
1000
- query = args.query + (" AND (`" + (_this11 == null ? void 0 : _this11.type) + "`.deleted = false OR `" + (_this11 == null ? void 0 : _this11.type) + "`.deleted IS MISSING) ");
1038
+ query = args.query + (" AND (`" + _this11.type + "`.deleted = false OR `" + _this11.type + "`.deleted IS MISSING) ");
1001
1039
  } else {
1002
- query = "(`" + (_this11 == null ? void 0 : _this11.type) + "`.deleted = false OR `" + (_this11 == null ? void 0 : _this11.type) + "`.deleted IS MISSING) ";
1040
+ query = "(`" + _this11.type + "`.deleted = false OR `" + _this11.type + "`.deleted IS MISSING) ";
1003
1041
  }
1004
1042
  }
1005
1043
  }
@@ -1026,7 +1064,7 @@ class SpiceModel {
1026
1064
  }
1027
1065
 
1028
1066
  if (!args.sort) {
1029
- args.sort = "`" + (_this11 == null ? void 0 : _this11.type) + "`.created_at DESC";
1067
+ args.sort = "`" + _this11.type + "`.created_at DESC";
1030
1068
  } else {
1031
1069
  var sort_array = args.sort.split(","); // check the first string in each item in the array to see if it contains a . if not then add the type
1032
1070
 
@@ -1034,7 +1072,7 @@ class SpiceModel {
1034
1072
 
1035
1073
  for (var i = 0; i < sort_array.length; i++) {
1036
1074
  if (!sort_array[i].includes(".")) {
1037
- new_sort_array.push("`" + (_this11 == null ? void 0 : _this11.type) + "`." + formatSortComponent(sort_array[i]));
1075
+ new_sort_array.push("`" + _this11.type + "`." + formatSortComponent(sort_array[i]));
1038
1076
  } else {
1039
1077
  new_sort_array.push(sort_array[i]);
1040
1078
  }
@@ -1051,22 +1089,22 @@ class SpiceModel {
1051
1089
  return str.replace(/[^a-zA-Z0-9]/g, "");
1052
1090
  }
1053
1091
 
1054
- var key = removeSpaceAndSpecialCharacters("list::" + (_this11 == null ? void 0 : _this11.type) + "::" + args._join + "::" + query + "::" + args.limit + "::" + args.offset + "::" + args.sort + "::" + args.do_count + "::" + args.statement_consistent + "::" + args.columns + "::" + args.is_full_text + "::" + args.is_custom_query);
1092
+ var key = removeSpaceAndSpecialCharacters("list::" + _this11.type + "::" + args._join + "::" + query + "::" + args.limit + "::" + args.offset + "::" + args.sort + "::" + args.do_count + "::" + args.statement_consistent + "::" + args.columns + "::" + args.is_full_text + "::" + args.is_custom_query);
1055
1093
  var results;
1056
1094
 
1057
1095
  if (args.is_custom_query && args.is_custom_query === "true") {
1058
1096
  if (args.ids.length > 0) {
1059
- if (_this11.shouldUseCache(_this11 == null ? void 0 : _this11.type)) {
1060
- var cached_results = yield _this11.getCacheProviderObject(_this11 == null ? void 0 : _this11.type).get(key);
1097
+ if (_this11.shouldUseCache(_this11.type)) {
1098
+ var cached_results = yield _this11.getCacheProviderObject(_this11.type).get(key);
1061
1099
  results = cached_results == null ? void 0 : cached_results.value;
1062
1100
 
1063
1101
  if ((cached_results == null ? void 0 : cached_results.value) == undefined || (yield _this11.shouldForceRefresh(cached_results))) {
1064
1102
  results = yield _this11.database.query(query);
1065
1103
 
1066
- _this11.getCacheProviderObject(_this11 == null ? void 0 : _this11.type).set(key, {
1104
+ _this11.getCacheProviderObject(_this11.type).set(key, {
1067
1105
  value: results,
1068
1106
  time: new Date().getTime()
1069
- }, _this11.getCacheConfig(_this11 == null ? void 0 : _this11.type));
1107
+ }, _this11.getCacheConfig(_this11.type));
1070
1108
  }
1071
1109
  } else {
1072
1110
  results = yield _this11.database.query(query);
@@ -1074,39 +1112,39 @@ class SpiceModel {
1074
1112
  }
1075
1113
  } else {
1076
1114
  if (args.is_full_text && args.is_full_text === "true") {
1077
- if (_this11.shouldUseCache(_this11 == null ? void 0 : _this11.type)) {
1078
- var _cached_results = yield _this11.getCacheProviderObject(_this11 == null ? void 0 : _this11.type).get(key);
1115
+ if (_this11.shouldUseCache(_this11.type)) {
1116
+ var _cached_results = yield _this11.getCacheProviderObject(_this11.type).get(key);
1079
1117
 
1080
1118
  results = _cached_results == null ? void 0 : _cached_results.value;
1081
1119
 
1082
1120
  if ((_cached_results == null ? void 0 : _cached_results.value) == undefined || (yield _this11.shouldForceRefresh(_cached_results))) {
1083
- results = yield _this11.database.full_text_search(_this11 == null ? void 0 : _this11.type, query || "", args.limit, args.offset, args._join);
1121
+ results = yield _this11.database.full_text_search(_this11.type, query || "", args.limit, args.offset, args._join);
1084
1122
 
1085
- _this11.getCacheProviderObject(_this11 == null ? void 0 : _this11.type).set(key, {
1123
+ _this11.getCacheProviderObject(_this11.type).set(key, {
1086
1124
  value: results,
1087
1125
  time: new Date().getTime()
1088
- }, _this11.getCacheConfig(_this11 == null ? void 0 : _this11.type));
1126
+ }, _this11.getCacheConfig(_this11.type));
1089
1127
  }
1090
1128
  } else {
1091
- results = yield _this11.database.full_text_search(_this11 == null ? void 0 : _this11.type, query || "", args.limit, args.offset, args._join);
1129
+ results = yield _this11.database.full_text_search(_this11.type, query || "", args.limit, args.offset, args._join);
1092
1130
  }
1093
1131
  } else {
1094
- if (_this11.shouldUseCache(_this11 == null ? void 0 : _this11.type)) {
1095
- var _cached_results2 = yield _this11.getCacheProviderObject(_this11 == null ? void 0 : _this11.type).get(key);
1132
+ if (_this11.shouldUseCache(_this11.type)) {
1133
+ var _cached_results2 = yield _this11.getCacheProviderObject(_this11.type).get(key);
1096
1134
 
1097
1135
  results = _cached_results2 == null ? void 0 : _cached_results2.value;
1098
1136
  var shouleForceRefresh = yield _this11.shouldForceRefresh(_cached_results2);
1099
1137
 
1100
1138
  if ((_cached_results2 == null ? void 0 : _cached_results2.value) == undefined || shouleForceRefresh) {
1101
- results = yield _this11.database.search(_this11 == null ? void 0 : _this11.type, args.columns || "", query || "", args.limit, args.offset, args.sort, args.do_count, args.statement_consistent, args._join);
1139
+ results = yield _this11.database.search(_this11.type, args.columns || "", query || "", args.limit, args.offset, args.sort, args.do_count, args.statement_consistent, args._join);
1102
1140
 
1103
- _this11.getCacheProviderObject(_this11 == null ? void 0 : _this11.type).set(key, {
1141
+ _this11.getCacheProviderObject(_this11.type).set(key, {
1104
1142
  value: results,
1105
1143
  time: new Date().getTime()
1106
- }, _this11.getCacheConfig(_this11 == null ? void 0 : _this11.type));
1144
+ }, _this11.getCacheConfig(_this11.type));
1107
1145
  }
1108
1146
  } else {
1109
- results = yield _this11.database.search(_this11 == null ? void 0 : _this11.type, args.columns || "", query || "", args.limit, args.offset, args.sort, args.do_count, args.statement_consistent, args._join);
1147
+ results = yield _this11.database.search(_this11.type, args.columns || "", query || "", args.limit, args.offset, args.sort, args.do_count, args.statement_consistent, args._join);
1110
1148
  }
1111
1149
  }
1112
1150
  }
@@ -1116,7 +1154,7 @@ class SpiceModel {
1116
1154
  results.data = yield _this11.do_serialize(results.data, "read", {}, args, (yield _this11.propsToBeRemoved(results.data)));
1117
1155
  }
1118
1156
 
1119
- if ((_this11 == null ? void 0 : _this11.type) == "resourcedetail") ;
1157
+ if (_this11.type == "resourcedetail") ;
1120
1158
 
1121
1159
  if (args.skip_hooks != true) {
1122
1160
  yield _this11.run_hook(results.data, "list", "after");
@@ -1156,7 +1194,7 @@ class SpiceModel {
1156
1194
  operation: op,
1157
1195
  when,
1158
1196
  old_data,
1159
- resource: _this12 == null ? void 0 : _this12.type,
1197
+ resource: _this12.type,
1160
1198
  ctx: _this12[_ctx]
1161
1199
  }
1162
1200
  });
@@ -1210,10 +1248,6 @@ class SpiceModel {
1210
1248
  var ids = [];
1211
1249
 
1212
1250
  _.each(data, result => {
1213
- if (!result || result == "undefined") {
1214
- result = {};
1215
- }
1216
-
1217
1251
  if (_.isString(result[source_property]) && result[source_property] != "") {
1218
1252
  ids = _.union(ids, [result[source_property]]);
1219
1253
  }
@@ -1233,10 +1267,6 @@ class SpiceModel {
1233
1267
  })));
1234
1268
 
1235
1269
  data = _.map(data, result => {
1236
- if (!result || result == "undefined") {
1237
- result = {};
1238
- }
1239
-
1240
1270
  var result_found = _.find(ug, g => {
1241
1271
  return g.id == result[source_property];
1242
1272
  }) || {};
@@ -1262,10 +1292,6 @@ class SpiceModel {
1262
1292
  _.each(data, result => {
1263
1293
  var value = [];
1264
1294
 
1265
- if (!result || result == "undefined") {
1266
- result = {};
1267
- }
1268
-
1269
1295
  if (_.isArray(result[source_property])) {
1270
1296
  value = result[source_property];
1271
1297
  }
@@ -1298,10 +1324,6 @@ class SpiceModel {
1298
1324
 
1299
1325
 
1300
1326
  _.each(data, result => {
1301
- if (!result || result == "undefined") {
1302
- result = {};
1303
- }
1304
-
1305
1327
  if (_.isString(result[store_property])) {
1306
1328
  result[store_property] = [result[store_property]];
1307
1329
  }
@@ -1427,15 +1449,15 @@ class SpiceModel {
1427
1449
  }
1428
1450
 
1429
1451
  if (_this16.shouldSerializerRun(args, type)) {
1430
- if ((_this16 == null ? void 0 : _this16.type) != "" && (_this16 == null ? void 0 : _this16.type) != undefined && _this16[_external_modifier_loaded] != true) {
1431
- _this16.addExternalModifiers(_this16 == null ? void 0 : _this16.type);
1452
+ if (_this16.type != "" && _this16.type != undefined && _this16[_external_modifier_loaded] != true) {
1453
+ _this16.addExternalModifiers(_this16.type);
1432
1454
 
1433
1455
  _this16[_external_modifier_loaded] = true;
1434
1456
  }
1435
1457
 
1436
1458
  for (var i of _this16[_serializers][type]["modifiers"]) {
1437
1459
  try {
1438
- data = yield i(data, old_data, _this16[_ctx], _this16 == null ? void 0 : _this16.type);
1460
+ data = yield i(data, old_data, _this16[_ctx], _this16.type);
1439
1461
  } catch (e) {
1440
1462
  console.log(e.stack);
1441
1463
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spice-js",
3
- "version": "2.6.35",
3
+ "version": "2.6.36",
4
4
  "description": "spice",
5
5
  "main": "build/index.js",
6
6
  "repository": {
@@ -151,7 +151,7 @@ export default class SpiceModel {
151
151
  for (let i in args.props) {
152
152
  if (args.args != undefined) {
153
153
  if (args.args[i] != undefined) {
154
- switch (args.props[i]?.type) {
154
+ switch (args.props[i].type) {
155
155
  case String:
156
156
  case "string": {
157
157
  this[i] = args.args[i];
@@ -236,7 +236,7 @@ export default class SpiceModel {
236
236
  let returned = await new this[_ctx].state.process_fields().process(
237
237
  this[_ctx],
238
238
  data,
239
- this?.type
239
+ this.type
240
240
  );
241
241
  return returned;
242
242
  } else {
@@ -453,7 +453,7 @@ export default class SpiceModel {
453
453
 
454
454
  async shouldForceRefresh(response) {
455
455
  let obj = this.getCacheProviderObject();
456
- let monitor_record = await obj.get(`monitor::${this?.type}`);
456
+ let monitor_record = await obj.get(`monitor::${this.type}`);
457
457
  if (monitor_record == undefined) {
458
458
  return false;
459
459
  }
@@ -466,7 +466,7 @@ export default class SpiceModel {
466
466
  setMonitor() {
467
467
  let current_time = new Date().getTime();
468
468
  let obj = this.getCacheProviderObject();
469
- let key = `monitor::${this?.type}`;
469
+ let key = `monitor::${this.type}`;
470
470
  let value = { time: current_time };
471
471
  obj.set(key, value, { ttl: 0 });
472
472
  }
@@ -480,41 +480,41 @@ export default class SpiceModel {
480
480
  if (args.skip_hooks != true) {
481
481
  await this.run_hook(args, "get", "before");
482
482
  }
483
- let key = `get::${this?.type}::${args.id}`;
483
+ let key = `get::${this.type}::${args.id}`;
484
484
  let results = {};
485
- if (this.shouldUseCache(this?.type)) {
486
- let cached_results = await this.getCacheProviderObject(
487
- this?.type
488
- ).get(key);
485
+ if (this.shouldUseCache(this.type)) {
486
+ let cached_results = await this.getCacheProviderObject(this.type).get(
487
+ key
488
+ );
489
489
 
490
490
  results = cached_results?.value;
491
491
  if (
492
492
  cached_results?.value == undefined ||
493
493
  (await this.shouldForceRefresh(cached_results)) ||
494
- this?.type == "workflow"
494
+ this.type == "workflow"
495
495
  ) {
496
496
  results = await this.database.get(args.id);
497
- await this.getCacheProviderObject(this?.type).set(
497
+ await this.getCacheProviderObject(this.type).set(
498
498
  key,
499
499
  { value: results, time: new Date().getTime() },
500
- this.getCacheConfig(this?.type)
500
+ this.getCacheConfig(this.type)
501
501
  );
502
502
  }
503
503
  } else {
504
504
  results = await this.database.get(args.id);
505
505
  }
506
506
 
507
- if (results?.type != undefined) {
508
- if (results?.type != this?.type)
509
- throw new Error(`${this?.type} does not exist type`);
507
+ if (results.type != undefined) {
508
+ if (results.type != this.type)
509
+ throw new Error(`${this.type} does not exist type`);
510
510
  }
511
511
 
512
- if (results?._type != undefined) {
513
- if (results?._type != this?.type)
514
- throw new Error(`${this?.type} does not exist _type`);
512
+ if (results._type != undefined) {
513
+ if (results._type != this.type)
514
+ throw new Error(`${this.type} does not exist _type`);
515
515
  }
516
516
 
517
- if (results?.deleted == undefined || results?.deleted == false) {
517
+ if (results.deleted == undefined || results.deleted == false) {
518
518
  if (args.skip_read_serialize != true && args.skip_serialize != true) {
519
519
  results = await this.do_serialize(
520
520
  results,
@@ -529,7 +529,7 @@ export default class SpiceModel {
529
529
  }
530
530
  return results;
531
531
  } else {
532
- throw new Error(`${this?.type} does not exist`);
532
+ throw new Error(`${this.type} does not exist`);
533
533
  }
534
534
  }
535
535
  } catch (e) {
@@ -556,30 +556,30 @@ export default class SpiceModel {
556
556
  await this.run_hook(this, "list", "before");
557
557
  }
558
558
  _.remove(args.ids, (o) => o == undefined);
559
- let key = `multi-get::${this?.type}::${_.join(args.ids, "|")}`;
559
+ let key = `multi-get::${this.type}::${_.join(args.ids, "|")}`;
560
560
  let results = [];
561
561
  if (args.ids.length > 0) {
562
- if (this.shouldUseCache(this?.type)) {
563
- let cached_results = await this.getCacheProviderObject(
564
- this?.type
565
- ).get(key);
562
+ if (this.shouldUseCache(this.type)) {
563
+ let cached_results = await this.getCacheProviderObject(this.type).get(
564
+ key
565
+ );
566
566
  results = cached_results?.value;
567
567
  if (
568
568
  cached_results?.value == undefined ||
569
569
  (await this.shouldForceRefresh(cached_results))
570
570
  ) {
571
571
  results = await this.database.multi_get(args.ids, true);
572
- this.getCacheProviderObject(this?.type).set(
572
+ this.getCacheProviderObject(this.type).set(
573
573
  key,
574
574
  { value: results, time: new Date().getTime() },
575
- this.getCacheConfig(this?.type)
575
+ this.getCacheConfig(this.type)
576
576
  );
577
577
  }
578
578
  } else {
579
579
  results = await this.database.multi_get(args.ids, true);
580
580
  }
581
581
  }
582
- _.remove(results, (o) => o?.type != this?.type);
582
+ _.remove(results, (o) => o.type != this.type);
583
583
  if (args.skip_read_serialize != true && args.skip_serialize != true) {
584
584
  results = await this.do_serialize(
585
585
  results,
@@ -605,22 +605,22 @@ export default class SpiceModel {
605
605
  try {
606
606
  if (_.isString(data)) {
607
607
  let result = await this.database.get(data);
608
- if (result?.type)
609
- if (result.type != this?.type) {
608
+ if (result.type)
609
+ if (result.type != this.type) {
610
610
  return false;
611
611
  }
612
- if (result?._type)
613
- if (result._type != this?.type) {
612
+ if (result._type)
613
+ if (result._type != this.type) {
614
614
  return false;
615
615
  }
616
616
  } else {
617
- if (data?.type)
618
- if (data.type != this?.type) {
617
+ if (data.type)
618
+ if (data.type != this.type) {
619
619
  return false;
620
620
  }
621
621
 
622
- if (data?._type)
623
- if (data._type != this?.type) {
622
+ if (data._type)
623
+ if (data._type != this.type) {
624
624
  return false;
625
625
  }
626
626
  }
@@ -636,7 +636,7 @@ export default class SpiceModel {
636
636
  let results = await this.database.get(args.id);
637
637
  let item_exist = await this.exist(results);
638
638
  if (!item_exist) {
639
- throw new Error(`${this?.type} does not exist. in update`);
639
+ throw new Error(`${this.type} does not exist. in update`);
640
640
  }
641
641
  delete results["id"];
642
642
  _.defaults(this, results);
@@ -697,7 +697,7 @@ export default class SpiceModel {
697
697
  try {
698
698
  let form;
699
699
  this.created_at = new SDate().now();
700
- args = _.defaults(args, { id_prefix: this?.type });
700
+ args = _.defaults(args, { id_prefix: this.type });
701
701
  if (args.body) {
702
702
  form = _.defaults({}, args.body);
703
703
  form.created_at = this.created_at;
@@ -753,7 +753,7 @@ export default class SpiceModel {
753
753
  let item_exist = await this.exist(args.id);
754
754
 
755
755
  if (!item_exist) {
756
- throw new Error(`${this?.type} does not exist.`);
756
+ throw new Error(`${this.type} does not exist.`);
757
757
  }
758
758
  let results = await this.database.get(args.id);
759
759
  try {
@@ -831,20 +831,64 @@ export default class SpiceModel {
831
831
  }
832
832
  return data;
833
833
  }
834
+
834
835
  function extractNestings(string, localType) {
835
836
  let returnVal = [];
836
- let regex = /(\w+)\./g;
837
+
838
+ // Regex for nested properties, including backtick-quoted ones
839
+ let regex = /(`?\w+`?)\.(`?\w+`?)/g;
837
840
  let match;
838
- while ((match = regex.exec(string))) {
841
+
842
+ while ((match = regex.exec(string)) !== null) {
843
+ let first = match[1].replace(/`/g, "");
844
+ let second = match[2].replace(/`/g, "");
845
+ if (first !== localType) {
846
+ returnVal.push(first);
847
+ }
848
+ }
849
+ // Regex for ANY/EVERY clauses
850
+ let queryRegex = /(ANY|EVERY)\s+\w+\s+IN\s+`?(\w+)`?/g;
851
+ let queryMatch;
852
+
853
+ while ((queryMatch = queryRegex.exec(string)) !== null) {
854
+ returnVal.push(queryMatch[2]);
855
+ }
856
+
857
+ return [...new Set(returnVal)]; // Remove duplicates
858
+ }
859
+
860
+ /* function extractNestings(string, localType) {
861
+ let returnVal = [];
862
+ let regex = /(\w+)\.(\w+)/g;
863
+ let match;
864
+
865
+ while ((match = regex.exec(string)) !== null) {
866
+ if (match[1] !== localType) {
867
+ returnVal.push(match[1]);
868
+ } else {
869
+ returnVal.push(match[2]);
870
+ }
871
+ }
872
+
873
+ return [...new Set(returnVal)]; // Remove duplicates
874
+ } */
875
+ /* function extractNestings(string, localType) {
876
+ let returnVal = [];
877
+ let regex = /(\w+)\./g;
878
+ let match = regex.exec(string);
879
+ console.log("Local:", localType, match);
880
+ while (match) {
839
881
  if (match[1] != localType) returnVal.push(match[1]);
840
882
  }
841
883
  return returnVal;
842
- }
884
+ } */
885
+
886
+ //console.log("Query", args?.query);
843
887
 
844
888
  let nestings = [
845
- ...extractNestings(args?.query, this?.type),
846
- ...extractNestings(args?.columns, this?.type),
847
- ...extractNestings(args?.sort, this?.type),
889
+ ...extractNestings(args?.query, this.type),
890
+ ...extractNestings(args?.columns, this.type),
891
+ ...extractNestings(args?.sort, this.type),
848
892
  ];
849
893
  let mappedNestings = _.compact(
850
894
  _.map(_.uniq(nestings), (nesting) => {
@@ -855,6 +899,7 @@ export default class SpiceModel {
855
899
  return {
856
900
  alias: nesting,
857
901
  reference: prop.map.reference.toLowerCase(),
902
+ type: prop.type,
858
903
  value_field: prop.map.value_field,
859
904
  };
860
905
  }
@@ -867,11 +912,21 @@ export default class SpiceModel {
867
912
  //create join section with nestings
868
913
  let joinSection = "";
869
914
  _.each(nestings, (nesting) => {
870
- joinSection += `LEFT JOIN \`${nesting.reference}\` AS \`${nesting.alias}\` ON KEYS \`${that.type}\`.\`${nesting.alias}\` `;
915
+ if (
916
+ nesting.type == DataType.ARRAY ||
917
+ nesting.type == Array ||
918
+ nesting.type == "array"
919
+ ) {
920
+ joinSection += `NEST \`${nesting.reference}\` AS \`${nesting.alias}\` ON KEYS \`${that.type}\`.\`${nesting.alias}\` `;
921
+ } else {
922
+ joinSection += `LEFT JOIN \`${nesting.reference}\` AS \`${nesting.alias}\` ON KEYS \`${that.type}\`.\`${nesting.alias}\` `;
923
+ }
871
924
  });
872
925
  return joinSection;
873
926
  }
874
927
  let _join = createJoinSection(mappedNestings);
928
+ console.log("Props", that.type, nestings, _join, args?.query);
929
+
875
930
  args._join = _join;
876
931
 
877
932
  if (
@@ -886,9 +941,9 @@ export default class SpiceModel {
886
941
  if (args.query) {
887
942
  query =
888
943
  args.query +
889
- ` AND (\`${this?.type}\`.deleted = false OR \`${this?.type}\`.deleted IS MISSING) `;
944
+ ` AND (\`${this.type}\`.deleted = false OR \`${this.type}\`.deleted IS MISSING) `;
890
945
  } else {
891
- query = `(\`${this?.type}\`.deleted = false OR \`${this?.type}\`.deleted IS MISSING) `;
946
+ query = `(\`${this.type}\`.deleted = false OR \`${this.type}\`.deleted IS MISSING) `;
892
947
  }
893
948
  }
894
949
  }
@@ -913,7 +968,7 @@ export default class SpiceModel {
913
968
  }
914
969
 
915
970
  if (!args.sort) {
916
- args.sort = `\`${this?.type}\`.created_at DESC`;
971
+ args.sort = `\`${this.type}\`.created_at DESC`;
917
972
  } else {
918
973
  let sort_array = args.sort.split(",");
919
974
  // check the first string in each item in the array to see if it contains a . if not then add the type
@@ -921,7 +976,7 @@ export default class SpiceModel {
921
976
  for (let i = 0; i < sort_array.length; i++) {
922
977
  if (!sort_array[i].includes(".")) {
923
978
  new_sort_array.push(
924
- `\`${this?.type}\`.${formatSortComponent(sort_array[i])}`
979
+ `\`${this.type}\`.${formatSortComponent(sort_array[i])}`
925
980
  );
926
981
  } else {
927
982
  new_sort_array.push(sort_array[i]);
@@ -936,15 +991,15 @@ export default class SpiceModel {
936
991
  return str.replace(/[^a-zA-Z0-9]/g, "");
937
992
  }
938
993
  let key = removeSpaceAndSpecialCharacters(
939
- `list::${this?.type}::${args._join}::${query}::${args.limit}::${args.offset}::${args.sort}::${args.do_count}::${args.statement_consistent}::${args.columns}::${args.is_full_text}::${args.is_custom_query}`
994
+ `list::${this.type}::${args._join}::${query}::${args.limit}::${args.offset}::${args.sort}::${args.do_count}::${args.statement_consistent}::${args.columns}::${args.is_full_text}::${args.is_custom_query}`
940
995
  );
941
996
 
942
997
  let results;
943
998
  if (args.is_custom_query && args.is_custom_query === "true") {
944
999
  if (args.ids.length > 0) {
945
- if (this.shouldUseCache(this?.type)) {
1000
+ if (this.shouldUseCache(this.type)) {
946
1001
  let cached_results = await this.getCacheProviderObject(
947
- this?.type
1002
+ this.type
948
1003
  ).get(key);
949
1004
  results = cached_results?.value;
950
1005
  if (
@@ -952,10 +1007,10 @@ export default class SpiceModel {
952
1007
  (await this.shouldForceRefresh(cached_results))
953
1008
  ) {
954
1009
  results = await this.database.query(query);
955
- this.getCacheProviderObject(this?.type).set(
1010
+ this.getCacheProviderObject(this.type).set(
956
1011
  key,
957
1012
  { value: results, time: new Date().getTime() },
958
- this.getCacheConfig(this?.type)
1013
+ this.getCacheConfig(this.type)
959
1014
  );
960
1015
  }
961
1016
  } else {
@@ -964,9 +1019,9 @@ export default class SpiceModel {
964
1019
  }
965
1020
  } else {
966
1021
  if (args.is_full_text && args.is_full_text === "true") {
967
- if (this.shouldUseCache(this?.type)) {
1022
+ if (this.shouldUseCache(this.type)) {
968
1023
  let cached_results = await this.getCacheProviderObject(
969
- this?.type
1024
+ this.type
970
1025
  ).get(key);
971
1026
  results = cached_results?.value;
972
1027
  if (
@@ -974,21 +1029,21 @@ export default class SpiceModel {
974
1029
  (await this.shouldForceRefresh(cached_results))
975
1030
  ) {
976
1031
  results = await this.database.full_text_search(
977
- this?.type,
1032
+ this.type,
978
1033
  query || "",
979
1034
  args.limit,
980
1035
  args.offset,
981
1036
  args._join
982
1037
  );
983
- this.getCacheProviderObject(this?.type).set(
1038
+ this.getCacheProviderObject(this.type).set(
984
1039
  key,
985
1040
  { value: results, time: new Date().getTime() },
986
- this.getCacheConfig(this?.type)
1041
+ this.getCacheConfig(this.type)
987
1042
  );
988
1043
  }
989
1044
  } else {
990
1045
  results = await this.database.full_text_search(
991
- this?.type,
1046
+ this.type,
992
1047
  query || "",
993
1048
  args.limit,
994
1049
  args.offset,
@@ -996,16 +1051,16 @@ export default class SpiceModel {
996
1051
  );
997
1052
  }
998
1053
  } else {
999
- if (this.shouldUseCache(this?.type)) {
1054
+ if (this.shouldUseCache(this.type)) {
1000
1055
  let cached_results = await this.getCacheProviderObject(
1001
- this?.type
1056
+ this.type
1002
1057
  ).get(key);
1003
1058
  results = cached_results?.value;
1004
1059
  let shouleForceRefresh =
1005
1060
  await this.shouldForceRefresh(cached_results);
1006
1061
  if (cached_results?.value == undefined || shouleForceRefresh) {
1007
1062
  results = await this.database.search(
1008
- this?.type,
1063
+ this.type,
1009
1064
  args.columns || "",
1010
1065
  query || "",
1011
1066
  args.limit,
@@ -1015,15 +1070,15 @@ export default class SpiceModel {
1015
1070
  args.statement_consistent,
1016
1071
  args._join
1017
1072
  );
1018
- this.getCacheProviderObject(this?.type).set(
1073
+ this.getCacheProviderObject(this.type).set(
1019
1074
  key,
1020
1075
  { value: results, time: new Date().getTime() },
1021
- this.getCacheConfig(this?.type)
1076
+ this.getCacheConfig(this.type)
1022
1077
  );
1023
1078
  }
1024
1079
  } else {
1025
1080
  results = await this.database.search(
1026
- this?.type,
1081
+ this.type,
1027
1082
  args.columns || "",
1028
1083
  query || "",
1029
1084
  args.limit,
@@ -1046,7 +1101,7 @@ export default class SpiceModel {
1046
1101
  await this.propsToBeRemoved(results.data)
1047
1102
  );
1048
1103
  }
1049
- if (this?.type == "resourcedetail");
1104
+ if (this.type == "resourcedetail");
1050
1105
 
1051
1106
  if (args.skip_hooks != true) {
1052
1107
  await this.run_hook(results.data, "list", "after");
@@ -1075,7 +1130,7 @@ export default class SpiceModel {
1075
1130
  operation: op,
1076
1131
  when,
1077
1132
  old_data,
1078
- resource: this?.type,
1133
+ resource: this.type,
1079
1134
  ctx: this[_ctx],
1080
1135
  },
1081
1136
  });
@@ -1120,9 +1175,6 @@ export default class SpiceModel {
1120
1175
 
1121
1176
  let ids = [];
1122
1177
  _.each(data, (result) => {
1123
- if (!result || result == "undefined") {
1124
- result = {};
1125
- }
1126
1178
  if (
1127
1179
  _.isString(result[source_property]) &&
1128
1180
  result[source_property] != ""
@@ -1151,9 +1203,6 @@ export default class SpiceModel {
1151
1203
  );
1152
1204
 
1153
1205
  data = _.map(data, (result) => {
1154
- if (!result || result == "undefined") {
1155
- result = {};
1156
- }
1157
1206
  let result_found =
1158
1207
  _.find(ug, (g) => {
1159
1208
  return g.id == result[source_property];
@@ -1178,9 +1227,6 @@ export default class SpiceModel {
1178
1227
  let ids = [];
1179
1228
  _.each(data, (result) => {
1180
1229
  let value = [];
1181
- if (!result || result == "undefined") {
1182
- result = {};
1183
- }
1184
1230
 
1185
1231
  if (_.isArray(result[source_property])) {
1186
1232
  value = result[source_property];
@@ -1219,9 +1265,6 @@ export default class SpiceModel {
1219
1265
  ids: ids,
1220
1266
  }); */
1221
1267
  _.each(data, (result) => {
1222
- if (!result || result == "undefined") {
1223
- result = {};
1224
- }
1225
1268
  if (_.isString(result[store_property])) {
1226
1269
  result[store_property] = [result[store_property]];
1227
1270
  }
@@ -1324,16 +1367,16 @@ export default class SpiceModel {
1324
1367
 
1325
1368
  if (this.shouldSerializerRun(args, type)) {
1326
1369
  if (
1327
- this?.type != "" &&
1328
- this?.type != undefined &&
1370
+ this.type != "" &&
1371
+ this.type != undefined &&
1329
1372
  this[_external_modifier_loaded] != true
1330
1373
  ) {
1331
- this.addExternalModifiers(this?.type);
1374
+ this.addExternalModifiers(this.type);
1332
1375
  this[_external_modifier_loaded] = true;
1333
1376
  }
1334
1377
  for (let i of this[_serializers][type]["modifiers"]) {
1335
1378
  try {
1336
- data = await i(data, old_data, this[_ctx], this?.type);
1379
+ data = await i(data, old_data, this[_ctx], this.type);
1337
1380
  } catch (e) {
1338
1381
  console.log(e.stack);
1339
1382
  }