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