spice-js 2.6.33 → 2.6.35

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,6 +49,8 @@ if (!Promise.allSettled) {
49
49
 
50
50
  class SpiceModel {
51
51
  constructor(args) {
52
+ var _args$props$i;
53
+
52
54
  if (args === void 0) {
53
55
  args = {};
54
56
  }
@@ -166,7 +168,7 @@ class SpiceModel {
166
168
  for (var i in args.props) {
167
169
  if (args.args != undefined) {
168
170
  if (args.args[i] != undefined) {
169
- switch (args.props[i].type) {
171
+ switch ((_args$props$i = args.props[i]) == null ? void 0 : _args$props$i.type) {
170
172
  case String:
171
173
  case "string":
172
174
  {
@@ -258,7 +260,7 @@ class SpiceModel {
258
260
  var _this$_ctx, _this$_ctx$state;
259
261
 
260
262
  if ((_this$_ctx = _this[_ctx]) == null ? void 0 : (_this$_ctx$state = _this$_ctx.state) == null ? void 0 : _this$_ctx$state.process_fields) {
261
- var returned = yield new _this[_ctx].state.process_fields().process(_this[_ctx], data, _this.type);
263
+ var returned = yield new _this[_ctx].state.process_fields().process(_this[_ctx], data, _this == null ? void 0 : _this.type);
262
264
  return returned;
263
265
  } else {
264
266
  return data;
@@ -529,7 +531,7 @@ class SpiceModel {
529
531
  return _asyncToGenerator(function* () {
530
532
  var obj = _this3.getCacheProviderObject();
531
533
 
532
- var monitor_record = yield obj.get("monitor::" + _this3.type);
534
+ var monitor_record = yield obj.get("monitor::" + (_this3 == null ? void 0 : _this3.type));
533
535
 
534
536
  if (monitor_record == undefined) {
535
537
  return false;
@@ -546,7 +548,7 @@ class SpiceModel {
546
548
  setMonitor() {
547
549
  var current_time = new Date().getTime();
548
550
  var obj = this.getCacheProviderObject();
549
- var key = "monitor::" + this.type;
551
+ var key = "monitor::" + (this == null ? void 0 : this.type);
550
552
  var value = {
551
553
  time: current_time
552
554
  };
@@ -565,37 +567,43 @@ class SpiceModel {
565
567
  }
566
568
 
567
569
  if (_.isString(args.id)) {
570
+ var _results, _results3, _results5, _results6;
571
+
568
572
  if (args.skip_hooks != true) {
569
573
  yield _this4.run_hook(args, "get", "before");
570
574
  }
571
575
 
572
- var key = "get::" + _this4.type + "::" + args.id;
576
+ var key = "get::" + (_this4 == null ? void 0 : _this4.type) + "::" + args.id;
573
577
  var results = {};
574
578
 
575
- if (_this4.shouldUseCache(_this4.type)) {
576
- var cached_results = yield _this4.getCacheProviderObject(_this4.type).get(key);
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);
577
581
  results = cached_results == null ? void 0 : cached_results.value;
578
582
 
579
- if ((cached_results == null ? void 0 : cached_results.value) == undefined || (yield _this4.shouldForceRefresh(cached_results)) || _this4.type == "workflow") {
583
+ if ((cached_results == null ? void 0 : cached_results.value) == undefined || (yield _this4.shouldForceRefresh(cached_results)) || (_this4 == null ? void 0 : _this4.type) == "workflow") {
580
584
  results = yield _this4.database.get(args.id);
581
- yield _this4.getCacheProviderObject(_this4.type).set(key, {
585
+ yield _this4.getCacheProviderObject(_this4 == null ? void 0 : _this4.type).set(key, {
582
586
  value: results,
583
587
  time: new Date().getTime()
584
- }, _this4.getCacheConfig(_this4.type));
588
+ }, _this4.getCacheConfig(_this4 == null ? void 0 : _this4.type));
585
589
  }
586
590
  } else {
587
591
  results = yield _this4.database.get(args.id);
588
592
  }
589
593
 
590
- if (results.type != undefined) {
591
- if (results.type != _this4.type) throw new Error(_this4.type + " does not exist type");
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");
592
598
  }
593
599
 
594
- if (results._type != undefined) {
595
- if (results._type != _this4.type) throw new Error(_this4.type + " does not exist _type");
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");
596
604
  }
597
605
 
598
- if (results.deleted == undefined || results.deleted == false) {
606
+ if (((_results5 = results) == null ? void 0 : _results5.deleted) == undefined || ((_results6 = results) == null ? void 0 : _results6.deleted) == false) {
599
607
  if (args.skip_read_serialize != true && args.skip_serialize != true) {
600
608
  results = yield _this4.do_serialize(results, "read", {}, args, (yield _this4.propsToBeRemoved(results)));
601
609
  }
@@ -606,7 +614,7 @@ class SpiceModel {
606
614
 
607
615
  return results;
608
616
  } else {
609
- throw new Error(_this4.type + " does not exist");
617
+ throw new Error((_this4 == null ? void 0 : _this4.type) + " does not exist");
610
618
  }
611
619
  }
612
620
  } catch (e) {
@@ -644,29 +652,29 @@ class SpiceModel {
644
652
 
645
653
  _.remove(args.ids, o => o == undefined);
646
654
 
647
- var key = "multi-get::" + _this6.type + "::" + _.join(args.ids, "|");
655
+ var key = "multi-get::" + (_this6 == null ? void 0 : _this6.type) + "::" + _.join(args.ids, "|");
648
656
 
649
657
  var results = [];
650
658
 
651
659
  if (args.ids.length > 0) {
652
- if (_this6.shouldUseCache(_this6.type)) {
653
- var cached_results = yield _this6.getCacheProviderObject(_this6.type).get(key);
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);
654
662
  results = cached_results == null ? void 0 : cached_results.value;
655
663
 
656
664
  if ((cached_results == null ? void 0 : cached_results.value) == undefined || (yield _this6.shouldForceRefresh(cached_results))) {
657
665
  results = yield _this6.database.multi_get(args.ids, true);
658
666
 
659
- _this6.getCacheProviderObject(_this6.type).set(key, {
667
+ _this6.getCacheProviderObject(_this6 == null ? void 0 : _this6.type).set(key, {
660
668
  value: results,
661
669
  time: new Date().getTime()
662
- }, _this6.getCacheConfig(_this6.type));
670
+ }, _this6.getCacheConfig(_this6 == null ? void 0 : _this6.type));
663
671
  }
664
672
  } else {
665
673
  results = yield _this6.database.multi_get(args.ids, true);
666
674
  }
667
675
  }
668
676
 
669
- _.remove(results, o => o.type != _this6.type);
677
+ _.remove(results, o => (o == null ? void 0 : o.type) != (_this6 == null ? void 0 : _this6.type));
670
678
 
671
679
  if (args.skip_read_serialize != true && args.skip_serialize != true) {
672
680
  results = yield _this6.do_serialize(results, "read", {}, args, (yield _this6.propsToBeRemoved(results)));
@@ -691,17 +699,17 @@ class SpiceModel {
691
699
  try {
692
700
  if (_.isString(data)) {
693
701
  var result = yield _this7.database.get(data);
694
- if (result.type) if (result.type != _this7.type) {
702
+ if (result == null ? void 0 : result.type) if (result.type != (_this7 == null ? void 0 : _this7.type)) {
695
703
  return false;
696
704
  }
697
- if (result._type) if (result._type != _this7.type) {
705
+ if (result == null ? void 0 : result._type) if (result._type != (_this7 == null ? void 0 : _this7.type)) {
698
706
  return false;
699
707
  }
700
708
  } else {
701
- if (data.type) if (data.type != _this7.type) {
709
+ if (data == null ? void 0 : data.type) if (data.type != (_this7 == null ? void 0 : _this7.type)) {
702
710
  return false;
703
711
  }
704
- if (data._type) if (data._type != _this7.type) {
712
+ if (data == null ? void 0 : data._type) if (data._type != (_this7 == null ? void 0 : _this7.type)) {
705
713
  return false;
706
714
  }
707
715
  }
@@ -723,7 +731,7 @@ class SpiceModel {
723
731
  var item_exist = yield _this8.exist(results);
724
732
 
725
733
  if (!item_exist) {
726
- throw new Error(_this8.type + " does not exist. in update");
734
+ throw new Error((_this8 == null ? void 0 : _this8.type) + " does not exist. in update");
727
735
  }
728
736
 
729
737
  delete results["id"];
@@ -783,7 +791,7 @@ class SpiceModel {
783
791
  var form;
784
792
  _this9.created_at = new SDate().now();
785
793
  args = _.defaults(args, {
786
- id_prefix: _this9.type
794
+ id_prefix: _this9 == null ? void 0 : _this9.type
787
795
  });
788
796
 
789
797
  if (args.body) {
@@ -840,7 +848,7 @@ class SpiceModel {
840
848
  var item_exist = yield _this10.exist(args.id);
841
849
 
842
850
  if (!item_exist) {
843
- throw new Error(_this10.type + " does not exist.");
851
+ throw new Error((_this10 == null ? void 0 : _this10.type) + " does not exist.");
844
852
  }
845
853
 
846
854
  var results = yield _this10.database.get(args.id);
@@ -949,7 +957,7 @@ class SpiceModel {
949
957
  return returnVal;
950
958
  }
951
959
 
952
- 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)];
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)];
953
961
 
954
962
  var mappedNestings = _.compact(_.map(_.uniq(nestings), nesting => {
955
963
  var prop = _this11.props[nesting];
@@ -989,9 +997,9 @@ class SpiceModel {
989
997
  query = _this11.makeQueryFromFilter(args.filters);
990
998
  } else {
991
999
  if (args.query) {
992
- query = args.query + (" AND (`" + _this11.type + "`.deleted = false OR `" + _this11.type + "`.deleted IS MISSING) ");
1000
+ query = args.query + (" AND (`" + (_this11 == null ? void 0 : _this11.type) + "`.deleted = false OR `" + (_this11 == null ? void 0 : _this11.type) + "`.deleted IS MISSING) ");
993
1001
  } else {
994
- query = "(`" + _this11.type + "`.deleted = false OR `" + _this11.type + "`.deleted IS MISSING) ";
1002
+ query = "(`" + (_this11 == null ? void 0 : _this11.type) + "`.deleted = false OR `" + (_this11 == null ? void 0 : _this11.type) + "`.deleted IS MISSING) ";
995
1003
  }
996
1004
  }
997
1005
  }
@@ -1018,7 +1026,7 @@ class SpiceModel {
1018
1026
  }
1019
1027
 
1020
1028
  if (!args.sort) {
1021
- args.sort = "`" + _this11.type + "`.created_at DESC";
1029
+ args.sort = "`" + (_this11 == null ? void 0 : _this11.type) + "`.created_at DESC";
1022
1030
  } else {
1023
1031
  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
1024
1032
 
@@ -1026,7 +1034,7 @@ class SpiceModel {
1026
1034
 
1027
1035
  for (var i = 0; i < sort_array.length; i++) {
1028
1036
  if (!sort_array[i].includes(".")) {
1029
- new_sort_array.push("`" + _this11.type + "`." + formatSortComponent(sort_array[i]));
1037
+ new_sort_array.push("`" + (_this11 == null ? void 0 : _this11.type) + "`." + formatSortComponent(sort_array[i]));
1030
1038
  } else {
1031
1039
  new_sort_array.push(sort_array[i]);
1032
1040
  }
@@ -1043,22 +1051,22 @@ class SpiceModel {
1043
1051
  return str.replace(/[^a-zA-Z0-9]/g, "");
1044
1052
  }
1045
1053
 
1046
- 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);
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);
1047
1055
  var results;
1048
1056
 
1049
1057
  if (args.is_custom_query && args.is_custom_query === "true") {
1050
1058
  if (args.ids.length > 0) {
1051
- if (_this11.shouldUseCache(_this11.type)) {
1052
- var cached_results = yield _this11.getCacheProviderObject(_this11.type).get(key);
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);
1053
1061
  results = cached_results == null ? void 0 : cached_results.value;
1054
1062
 
1055
1063
  if ((cached_results == null ? void 0 : cached_results.value) == undefined || (yield _this11.shouldForceRefresh(cached_results))) {
1056
1064
  results = yield _this11.database.query(query);
1057
1065
 
1058
- _this11.getCacheProviderObject(_this11.type).set(key, {
1066
+ _this11.getCacheProviderObject(_this11 == null ? void 0 : _this11.type).set(key, {
1059
1067
  value: results,
1060
1068
  time: new Date().getTime()
1061
- }, _this11.getCacheConfig(_this11.type));
1069
+ }, _this11.getCacheConfig(_this11 == null ? void 0 : _this11.type));
1062
1070
  }
1063
1071
  } else {
1064
1072
  results = yield _this11.database.query(query);
@@ -1066,39 +1074,39 @@ class SpiceModel {
1066
1074
  }
1067
1075
  } else {
1068
1076
  if (args.is_full_text && args.is_full_text === "true") {
1069
- if (_this11.shouldUseCache(_this11.type)) {
1070
- var _cached_results = yield _this11.getCacheProviderObject(_this11.type).get(key);
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);
1071
1079
 
1072
1080
  results = _cached_results == null ? void 0 : _cached_results.value;
1073
1081
 
1074
1082
  if ((_cached_results == null ? void 0 : _cached_results.value) == undefined || (yield _this11.shouldForceRefresh(_cached_results))) {
1075
- results = yield _this11.database.full_text_search(_this11.type, query || "", args.limit, args.offset, args._join);
1083
+ results = yield _this11.database.full_text_search(_this11 == null ? void 0 : _this11.type, query || "", args.limit, args.offset, args._join);
1076
1084
 
1077
- _this11.getCacheProviderObject(_this11.type).set(key, {
1085
+ _this11.getCacheProviderObject(_this11 == null ? void 0 : _this11.type).set(key, {
1078
1086
  value: results,
1079
1087
  time: new Date().getTime()
1080
- }, _this11.getCacheConfig(_this11.type));
1088
+ }, _this11.getCacheConfig(_this11 == null ? void 0 : _this11.type));
1081
1089
  }
1082
1090
  } else {
1083
- results = yield _this11.database.full_text_search(_this11.type, query || "", args.limit, args.offset, args._join);
1091
+ results = yield _this11.database.full_text_search(_this11 == null ? void 0 : _this11.type, query || "", args.limit, args.offset, args._join);
1084
1092
  }
1085
1093
  } else {
1086
- if (_this11.shouldUseCache(_this11.type)) {
1087
- var _cached_results2 = yield _this11.getCacheProviderObject(_this11.type).get(key);
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);
1088
1096
 
1089
1097
  results = _cached_results2 == null ? void 0 : _cached_results2.value;
1090
1098
  var shouleForceRefresh = yield _this11.shouldForceRefresh(_cached_results2);
1091
1099
 
1092
1100
  if ((_cached_results2 == null ? void 0 : _cached_results2.value) == undefined || shouleForceRefresh) {
1093
- results = yield _this11.database.search(_this11.type, args.columns || "", query || "", args.limit, args.offset, args.sort, args.do_count, args.statement_consistent, args._join);
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);
1094
1102
 
1095
- _this11.getCacheProviderObject(_this11.type).set(key, {
1103
+ _this11.getCacheProviderObject(_this11 == null ? void 0 : _this11.type).set(key, {
1096
1104
  value: results,
1097
1105
  time: new Date().getTime()
1098
- }, _this11.getCacheConfig(_this11.type));
1106
+ }, _this11.getCacheConfig(_this11 == null ? void 0 : _this11.type));
1099
1107
  }
1100
1108
  } else {
1101
- results = yield _this11.database.search(_this11.type, args.columns || "", query || "", args.limit, args.offset, args.sort, args.do_count, args.statement_consistent, args._join);
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);
1102
1110
  }
1103
1111
  }
1104
1112
  }
@@ -1108,7 +1116,7 @@ class SpiceModel {
1108
1116
  results.data = yield _this11.do_serialize(results.data, "read", {}, args, (yield _this11.propsToBeRemoved(results.data)));
1109
1117
  }
1110
1118
 
1111
- if (_this11.type == "resourcedetail") ;
1119
+ if ((_this11 == null ? void 0 : _this11.type) == "resourcedetail") ;
1112
1120
 
1113
1121
  if (args.skip_hooks != true) {
1114
1122
  yield _this11.run_hook(results.data, "list", "after");
@@ -1148,7 +1156,7 @@ class SpiceModel {
1148
1156
  operation: op,
1149
1157
  when,
1150
1158
  old_data,
1151
- resource: _this12.type,
1159
+ resource: _this12 == null ? void 0 : _this12.type,
1152
1160
  ctx: _this12[_ctx]
1153
1161
  }
1154
1162
  });
@@ -1202,6 +1210,10 @@ class SpiceModel {
1202
1210
  var ids = [];
1203
1211
 
1204
1212
  _.each(data, result => {
1213
+ if (!result || result == "undefined") {
1214
+ result = {};
1215
+ }
1216
+
1205
1217
  if (_.isString(result[source_property]) && result[source_property] != "") {
1206
1218
  ids = _.union(ids, [result[source_property]]);
1207
1219
  }
@@ -1221,6 +1233,10 @@ class SpiceModel {
1221
1233
  })));
1222
1234
 
1223
1235
  data = _.map(data, result => {
1236
+ if (!result || result == "undefined") {
1237
+ result = {};
1238
+ }
1239
+
1224
1240
  var result_found = _.find(ug, g => {
1225
1241
  return g.id == result[source_property];
1226
1242
  }) || {};
@@ -1246,6 +1262,10 @@ class SpiceModel {
1246
1262
  _.each(data, result => {
1247
1263
  var value = [];
1248
1264
 
1265
+ if (!result || result == "undefined") {
1266
+ result = {};
1267
+ }
1268
+
1249
1269
  if (_.isArray(result[source_property])) {
1250
1270
  value = result[source_property];
1251
1271
  }
@@ -1278,6 +1298,10 @@ class SpiceModel {
1278
1298
 
1279
1299
 
1280
1300
  _.each(data, result => {
1301
+ if (!result || result == "undefined") {
1302
+ result = {};
1303
+ }
1304
+
1281
1305
  if (_.isString(result[store_property])) {
1282
1306
  result[store_property] = [result[store_property]];
1283
1307
  }
@@ -1403,15 +1427,15 @@ class SpiceModel {
1403
1427
  }
1404
1428
 
1405
1429
  if (_this16.shouldSerializerRun(args, type)) {
1406
- if (_this16.type != "" && _this16.type != undefined && _this16[_external_modifier_loaded] != true) {
1407
- _this16.addExternalModifiers(_this16.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);
1408
1432
 
1409
1433
  _this16[_external_modifier_loaded] = true;
1410
1434
  }
1411
1435
 
1412
1436
  for (var i of _this16[_serializers][type]["modifiers"]) {
1413
1437
  try {
1414
- data = yield i(data, old_data, _this16[_ctx], _this16.type);
1438
+ data = yield i(data, old_data, _this16[_ctx], _this16 == null ? void 0 : _this16.type);
1415
1439
  } catch (e) {
1416
1440
  console.log(e.stack);
1417
1441
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spice-js",
3
- "version": "2.6.33",
3
+ "version": "2.6.35",
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(this.type).get(
487
- key
488
- );
485
+ if (this.shouldUseCache(this?.type)) {
486
+ let cached_results = await this.getCacheProviderObject(
487
+ this?.type
488
+ ).get(key);
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(this.type).get(
564
- key
565
- );
562
+ if (this.shouldUseCache(this?.type)) {
563
+ let cached_results = await this.getCacheProviderObject(
564
+ this?.type
565
+ ).get(key);
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 {
@@ -842,9 +842,9 @@ export default class SpiceModel {
842
842
  }
843
843
 
844
844
  let nestings = [
845
- ...extractNestings(args?.query, this.type),
846
- ...extractNestings(args?.columns, this.type),
847
- ...extractNestings(args?.sort, this.type),
845
+ ...extractNestings(args?.query, this?.type),
846
+ ...extractNestings(args?.columns, this?.type),
847
+ ...extractNestings(args?.sort, this?.type),
848
848
  ];
849
849
  let mappedNestings = _.compact(
850
850
  _.map(_.uniq(nestings), (nesting) => {
@@ -886,9 +886,9 @@ export default class SpiceModel {
886
886
  if (args.query) {
887
887
  query =
888
888
  args.query +
889
- ` AND (\`${this.type}\`.deleted = false OR \`${this.type}\`.deleted IS MISSING) `;
889
+ ` AND (\`${this?.type}\`.deleted = false OR \`${this?.type}\`.deleted IS MISSING) `;
890
890
  } else {
891
- query = `(\`${this.type}\`.deleted = false OR \`${this.type}\`.deleted IS MISSING) `;
891
+ query = `(\`${this?.type}\`.deleted = false OR \`${this?.type}\`.deleted IS MISSING) `;
892
892
  }
893
893
  }
894
894
  }
@@ -913,7 +913,7 @@ export default class SpiceModel {
913
913
  }
914
914
 
915
915
  if (!args.sort) {
916
- args.sort = `\`${this.type}\`.created_at DESC`;
916
+ args.sort = `\`${this?.type}\`.created_at DESC`;
917
917
  } else {
918
918
  let sort_array = args.sort.split(",");
919
919
  // check the first string in each item in the array to see if it contains a . if not then add the type
@@ -921,7 +921,7 @@ export default class SpiceModel {
921
921
  for (let i = 0; i < sort_array.length; i++) {
922
922
  if (!sort_array[i].includes(".")) {
923
923
  new_sort_array.push(
924
- `\`${this.type}\`.${formatSortComponent(sort_array[i])}`
924
+ `\`${this?.type}\`.${formatSortComponent(sort_array[i])}`
925
925
  );
926
926
  } else {
927
927
  new_sort_array.push(sort_array[i]);
@@ -936,15 +936,15 @@ export default class SpiceModel {
936
936
  return str.replace(/[^a-zA-Z0-9]/g, "");
937
937
  }
938
938
  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}`
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}`
940
940
  );
941
941
 
942
942
  let results;
943
943
  if (args.is_custom_query && args.is_custom_query === "true") {
944
944
  if (args.ids.length > 0) {
945
- if (this.shouldUseCache(this.type)) {
945
+ if (this.shouldUseCache(this?.type)) {
946
946
  let cached_results = await this.getCacheProviderObject(
947
- this.type
947
+ this?.type
948
948
  ).get(key);
949
949
  results = cached_results?.value;
950
950
  if (
@@ -952,10 +952,10 @@ export default class SpiceModel {
952
952
  (await this.shouldForceRefresh(cached_results))
953
953
  ) {
954
954
  results = await this.database.query(query);
955
- this.getCacheProviderObject(this.type).set(
955
+ this.getCacheProviderObject(this?.type).set(
956
956
  key,
957
957
  { value: results, time: new Date().getTime() },
958
- this.getCacheConfig(this.type)
958
+ this.getCacheConfig(this?.type)
959
959
  );
960
960
  }
961
961
  } else {
@@ -964,9 +964,9 @@ export default class SpiceModel {
964
964
  }
965
965
  } else {
966
966
  if (args.is_full_text && args.is_full_text === "true") {
967
- if (this.shouldUseCache(this.type)) {
967
+ if (this.shouldUseCache(this?.type)) {
968
968
  let cached_results = await this.getCacheProviderObject(
969
- this.type
969
+ this?.type
970
970
  ).get(key);
971
971
  results = cached_results?.value;
972
972
  if (
@@ -974,21 +974,21 @@ export default class SpiceModel {
974
974
  (await this.shouldForceRefresh(cached_results))
975
975
  ) {
976
976
  results = await this.database.full_text_search(
977
- this.type,
977
+ this?.type,
978
978
  query || "",
979
979
  args.limit,
980
980
  args.offset,
981
981
  args._join
982
982
  );
983
- this.getCacheProviderObject(this.type).set(
983
+ this.getCacheProviderObject(this?.type).set(
984
984
  key,
985
985
  { value: results, time: new Date().getTime() },
986
- this.getCacheConfig(this.type)
986
+ this.getCacheConfig(this?.type)
987
987
  );
988
988
  }
989
989
  } else {
990
990
  results = await this.database.full_text_search(
991
- this.type,
991
+ this?.type,
992
992
  query || "",
993
993
  args.limit,
994
994
  args.offset,
@@ -996,16 +996,16 @@ export default class SpiceModel {
996
996
  );
997
997
  }
998
998
  } else {
999
- if (this.shouldUseCache(this.type)) {
999
+ if (this.shouldUseCache(this?.type)) {
1000
1000
  let cached_results = await this.getCacheProviderObject(
1001
- this.type
1001
+ this?.type
1002
1002
  ).get(key);
1003
1003
  results = cached_results?.value;
1004
1004
  let shouleForceRefresh =
1005
1005
  await this.shouldForceRefresh(cached_results);
1006
1006
  if (cached_results?.value == undefined || shouleForceRefresh) {
1007
1007
  results = await this.database.search(
1008
- this.type,
1008
+ this?.type,
1009
1009
  args.columns || "",
1010
1010
  query || "",
1011
1011
  args.limit,
@@ -1015,15 +1015,15 @@ export default class SpiceModel {
1015
1015
  args.statement_consistent,
1016
1016
  args._join
1017
1017
  );
1018
- this.getCacheProviderObject(this.type).set(
1018
+ this.getCacheProviderObject(this?.type).set(
1019
1019
  key,
1020
1020
  { value: results, time: new Date().getTime() },
1021
- this.getCacheConfig(this.type)
1021
+ this.getCacheConfig(this?.type)
1022
1022
  );
1023
1023
  }
1024
1024
  } else {
1025
1025
  results = await this.database.search(
1026
- this.type,
1026
+ this?.type,
1027
1027
  args.columns || "",
1028
1028
  query || "",
1029
1029
  args.limit,
@@ -1046,7 +1046,7 @@ export default class SpiceModel {
1046
1046
  await this.propsToBeRemoved(results.data)
1047
1047
  );
1048
1048
  }
1049
- if (this.type == "resourcedetail");
1049
+ if (this?.type == "resourcedetail");
1050
1050
 
1051
1051
  if (args.skip_hooks != true) {
1052
1052
  await this.run_hook(results.data, "list", "after");
@@ -1075,7 +1075,7 @@ export default class SpiceModel {
1075
1075
  operation: op,
1076
1076
  when,
1077
1077
  old_data,
1078
- resource: this.type,
1078
+ resource: this?.type,
1079
1079
  ctx: this[_ctx],
1080
1080
  },
1081
1081
  });
@@ -1120,6 +1120,9 @@ export default class SpiceModel {
1120
1120
 
1121
1121
  let ids = [];
1122
1122
  _.each(data, (result) => {
1123
+ if (!result || result == "undefined") {
1124
+ result = {};
1125
+ }
1123
1126
  if (
1124
1127
  _.isString(result[source_property]) &&
1125
1128
  result[source_property] != ""
@@ -1148,6 +1151,9 @@ export default class SpiceModel {
1148
1151
  );
1149
1152
 
1150
1153
  data = _.map(data, (result) => {
1154
+ if (!result || result == "undefined") {
1155
+ result = {};
1156
+ }
1151
1157
  let result_found =
1152
1158
  _.find(ug, (g) => {
1153
1159
  return g.id == result[source_property];
@@ -1172,6 +1178,9 @@ export default class SpiceModel {
1172
1178
  let ids = [];
1173
1179
  _.each(data, (result) => {
1174
1180
  let value = [];
1181
+ if (!result || result == "undefined") {
1182
+ result = {};
1183
+ }
1175
1184
 
1176
1185
  if (_.isArray(result[source_property])) {
1177
1186
  value = result[source_property];
@@ -1210,6 +1219,9 @@ export default class SpiceModel {
1210
1219
  ids: ids,
1211
1220
  }); */
1212
1221
  _.each(data, (result) => {
1222
+ if (!result || result == "undefined") {
1223
+ result = {};
1224
+ }
1213
1225
  if (_.isString(result[store_property])) {
1214
1226
  result[store_property] = [result[store_property]];
1215
1227
  }
@@ -1312,16 +1324,16 @@ export default class SpiceModel {
1312
1324
 
1313
1325
  if (this.shouldSerializerRun(args, type)) {
1314
1326
  if (
1315
- this.type != "" &&
1316
- this.type != undefined &&
1327
+ this?.type != "" &&
1328
+ this?.type != undefined &&
1317
1329
  this[_external_modifier_loaded] != true
1318
1330
  ) {
1319
- this.addExternalModifiers(this.type);
1331
+ this.addExternalModifiers(this?.type);
1320
1332
  this[_external_modifier_loaded] = true;
1321
1333
  }
1322
1334
  for (let i of this[_serializers][type]["modifiers"]) {
1323
1335
  try {
1324
- data = await i(data, old_data, this[_ctx], this.type);
1336
+ data = await i(data, old_data, this[_ctx], this?.type);
1325
1337
  } catch (e) {
1326
1338
  console.log(e.stack);
1327
1339
  }