spice-js 2.6.39 → 2.6.40
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/artificial_intelligence/AI.js +296 -0
- package/build/config/ai.js +3 -0
- package/build/index.js +8 -2
- package/build/mail/providers/File.js +9 -5
- package/build/models/SpiceModel.js +147 -265
- package/build/storage/providers/Local.js +6 -12
- package/build/utility/RestHelper.js +9 -3
- package/package.json +13 -13
- package/src/artificial_intelligence/Ai.js +244 -0
- package/src/config/ai.js +3 -0
- package/src/index.js +2 -1
- package/src/mail/providers/File.js +28 -28
- package/src/models/SpiceModel.js +174 -290
- package/src/storage/providers/Local.js +69 -60
- package/src/utility/RestHelper.js +33 -29
|
@@ -880,292 +880,159 @@ class SpiceModel {
|
|
|
880
880
|
JSON.stringify(this);
|
|
881
881
|
}
|
|
882
882
|
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
var _args4, _args5, _args6;
|
|
883
|
+
prepColumns(columns) {
|
|
884
|
+
if (columns && columns !== "") {
|
|
885
|
+
var columnList = columns.split(",");
|
|
886
|
+
return _.join(_.compact(columnList.map(column => {
|
|
887
|
+
if (column === "meta().id") return undefined;
|
|
889
888
|
|
|
890
|
-
if (!
|
|
891
|
-
|
|
889
|
+
if (!column.startsWith("`") && !column.endsWith("`")) {
|
|
890
|
+
column = "`" + column + "`";
|
|
892
891
|
}
|
|
893
892
|
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
var columnList = columns.split(","); // Convert comma-separated string to array
|
|
897
|
-
|
|
898
|
-
return _.join(_.compact(_.map(columnList, column => {
|
|
899
|
-
if (column == "meta().id") {
|
|
900
|
-
column = undefined;
|
|
901
|
-
} else if (!column.startsWith("`") && !column.endsWith("`")) {
|
|
902
|
-
"`" + column + "`";
|
|
903
|
-
}
|
|
904
|
-
|
|
905
|
-
if (column) {
|
|
906
|
-
if (!column.includes(".") && !column.startsWith(that.type)) {
|
|
907
|
-
column = "`" + that.type + "`." + column;
|
|
908
|
-
}
|
|
909
|
-
}
|
|
910
|
-
|
|
911
|
-
return column;
|
|
912
|
-
})), ",");
|
|
913
|
-
}
|
|
914
|
-
|
|
915
|
-
return columns;
|
|
893
|
+
if (column && !column.includes(".") && !column.startsWith(this.type)) {
|
|
894
|
+
column = "`" + this.type + "`." + column;
|
|
916
895
|
}
|
|
917
896
|
|
|
918
|
-
|
|
919
|
-
|
|
897
|
+
return column;
|
|
898
|
+
})), ",");
|
|
899
|
+
}
|
|
920
900
|
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
columns = columns.replace(/`/g, "");
|
|
924
|
-
columns = columns.replace(/meta\(\)\.id/g, "id");
|
|
925
|
-
var columnList = columns.split(",").map(column => {
|
|
926
|
-
//if colums has a . then remove the first part of the string
|
|
927
|
-
return column.includes(".") ? _.last(column.split(".")) : column;
|
|
928
|
-
}); // Convert comma-separated string to array
|
|
901
|
+
return columns;
|
|
902
|
+
}
|
|
929
903
|
|
|
930
|
-
|
|
904
|
+
filterResultsByColumns(data, columns) {
|
|
905
|
+
if (columns && columns !== "") {
|
|
906
|
+
columns = columns.replace(/`/g, "").replace(/meta\(\)\.id/g, "id");
|
|
907
|
+
var columnList = columns.split(",").map(column => column.includes(".") ? _.last(column.split(".")) : column);
|
|
908
|
+
columnList.push("_permissions", "_permissions_", "id");
|
|
909
|
+
return data.map(entry => _.pick(entry, columnList));
|
|
910
|
+
}
|
|
931
911
|
|
|
932
|
-
|
|
912
|
+
return data;
|
|
913
|
+
}
|
|
933
914
|
|
|
934
|
-
|
|
915
|
+
extractNestings(string, localType) {
|
|
916
|
+
var returnVal = [];
|
|
917
|
+
var regex = /(`?\w+`?)\.(`?\w+`?)/g;
|
|
918
|
+
var match;
|
|
935
919
|
|
|
936
|
-
|
|
937
|
-
|
|
920
|
+
while ((match = regex.exec(string)) !== null) {
|
|
921
|
+
var first = match[1].replace(/`/g, "");
|
|
938
922
|
|
|
939
|
-
|
|
940
|
-
|
|
923
|
+
if (first !== localType) {
|
|
924
|
+
returnVal.push(first);
|
|
925
|
+
}
|
|
926
|
+
}
|
|
941
927
|
|
|
942
|
-
|
|
943
|
-
|
|
928
|
+
var queryRegex = /(ANY|EVERY)\s+\w+\s+IN\s+`?(\w+)`?/g;
|
|
929
|
+
var queryMatch;
|
|
944
930
|
|
|
945
|
-
|
|
946
|
-
|
|
931
|
+
while ((queryMatch = queryRegex.exec(string)) !== null) {
|
|
932
|
+
returnVal.push(queryMatch[2]);
|
|
933
|
+
}
|
|
947
934
|
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
var second = match[2].replace(/`/g, "");
|
|
935
|
+
return [...new Set(returnVal)];
|
|
936
|
+
}
|
|
951
937
|
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
938
|
+
createJoinSection(nestings) {
|
|
939
|
+
return nestings.map(nesting => {
|
|
940
|
+
if (nesting.type === _2.DataType.ARRAY || nesting.type === Array || nesting.type === "array") {
|
|
941
|
+
return "LEFT NEST `" + (0, _fix.fixCollection)(nesting.reference) + "` AS `" + nesting.alias + "` ON KEYS `" + this.type + "`.`" + nesting.alias + "`";
|
|
942
|
+
} else {
|
|
943
|
+
return "LEFT JOIN `" + (0, _fix.fixCollection)(nesting.reference) + "` AS `" + nesting.alias + "` ON KEYS `" + this.type + "`.`" + nesting.alias + "`";
|
|
944
|
+
}
|
|
945
|
+
}).join(" ");
|
|
946
|
+
}
|
|
956
947
|
|
|
948
|
+
formatSortComponent(sortComponent) {
|
|
949
|
+
var parts = sortComponent.split(" ");
|
|
950
|
+
parts[0] = "`" + parts[0] + "`";
|
|
951
|
+
return parts.join(" ");
|
|
952
|
+
}
|
|
957
953
|
|
|
958
|
-
|
|
959
|
-
|
|
954
|
+
removeSpaceAndSpecialCharacters(str) {
|
|
955
|
+
return str.replace(/[^a-zA-Z0-9]/g, "");
|
|
956
|
+
}
|
|
960
957
|
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
}
|
|
958
|
+
list(args) {
|
|
959
|
+
var _this11 = this;
|
|
964
960
|
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
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);
|
|
961
|
+
return _asyncToGenerator(function* () {
|
|
962
|
+
if (args === void 0) {
|
|
963
|
+
args = {};
|
|
964
|
+
}
|
|
992
965
|
|
|
966
|
+
try {
|
|
967
|
+
var _args4, _args5, _args6;
|
|
993
968
|
|
|
994
|
-
|
|
969
|
+
args.columns = _this11.prepColumns(args.columns);
|
|
970
|
+
var nestings = [..._this11.extractNestings((_args4 = args) == null ? void 0 : _args4.query, _this11.type), ..._this11.extractNestings((_args5 = args) == null ? void 0 : _args5.columns, _this11.type), ..._this11.extractNestings((_args6 = args) == null ? void 0 : _args6.sort, _this11.type)];
|
|
971
|
+
|
|
972
|
+
var mappedNestings = _.compact(_.uniq(nestings).map(nesting => {
|
|
973
|
+
var _prop$map;
|
|
995
974
|
|
|
996
|
-
var mappedNestings = _.compact(_.map(_.uniq(nestings), nesting => {
|
|
997
975
|
var prop = _this11.props[nesting];
|
|
998
976
|
|
|
999
|
-
if (prop) {
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
value_field: prop.map.value_field
|
|
1007
|
-
};
|
|
1008
|
-
}
|
|
1009
|
-
}
|
|
977
|
+
if ((prop == null ? void 0 : (_prop$map = prop.map) == null ? void 0 : _prop$map.type) === _2.MapType.MODEL) {
|
|
978
|
+
return {
|
|
979
|
+
alias: nesting,
|
|
980
|
+
reference: prop.map.reference.toLowerCase(),
|
|
981
|
+
type: prop.type,
|
|
982
|
+
value_field: prop.map.value_field
|
|
983
|
+
};
|
|
1010
984
|
}
|
|
1011
985
|
}));
|
|
1012
986
|
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
var joinSection = "";
|
|
1016
|
-
|
|
1017
|
-
_.each(nestings, nesting => {
|
|
1018
|
-
if (nesting.type == _2.DataType.ARRAY || nesting.type == Array || nesting.type == "array") {
|
|
1019
|
-
joinSection += "LEFT 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
|
-
}
|
|
1023
|
-
});
|
|
1024
|
-
|
|
1025
|
-
return joinSection;
|
|
1026
|
-
}
|
|
1027
|
-
|
|
1028
|
-
var _join = createJoinSection(mappedNestings); //console.log("Props", that.type, nestings, _join, args?.query);
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
args._join = _join;
|
|
987
|
+
args._join = _this11.createJoinSection(mappedNestings);
|
|
988
|
+
var query = "";
|
|
1032
989
|
|
|
1033
|
-
if (args.is_full_text
|
|
990
|
+
if (args.is_full_text === "true" || args.is_custom_query === "true") {
|
|
1034
991
|
query = args.query;
|
|
1035
992
|
} else {
|
|
1036
|
-
|
|
1037
|
-
query = _this11.makeQueryFromFilter(args.filters);
|
|
1038
|
-
} else {
|
|
1039
|
-
if (args.query) {
|
|
1040
|
-
query = args.query + (" AND (`" + _this11.type + "`.deleted = false OR `" + _this11.type + "`.deleted IS MISSING) ");
|
|
1041
|
-
} else {
|
|
1042
|
-
query = "(`" + _this11.type + "`.deleted = false OR `" + _this11.type + "`.deleted IS MISSING) ";
|
|
1043
|
-
}
|
|
1044
|
-
}
|
|
1045
|
-
}
|
|
1046
|
-
|
|
1047
|
-
function formatSortComponent(sortComponent) {
|
|
1048
|
-
// Split the string by spaces to get individual parts
|
|
1049
|
-
var parts = sortComponent.split(" "); // Assuming the first part is the column name, add backticks around it
|
|
1050
|
-
|
|
1051
|
-
parts[0] = "`" + parts[0] + "`"; // Rejoin the parts back into a string and return
|
|
1052
|
-
|
|
1053
|
-
return parts.join(" ");
|
|
993
|
+
query = args.filters ? _this11.makeQueryFromFilter(args.filters) : args.query ? args.query + " AND (`" + _this11.type + "`.deleted = false OR `" + _this11.type + "`.deleted IS MISSING)" : "(`" + _this11.type + "`.deleted = false OR `" + _this11.type + "`.deleted IS MISSING)";
|
|
1054
994
|
}
|
|
1055
995
|
|
|
1056
996
|
if ((0, _Security.hasSQLInjection)(query)) {
|
|
1057
997
|
return [];
|
|
1058
998
|
}
|
|
1059
999
|
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
if (args.offset) {
|
|
1065
|
-
args.offset = Number(args.offset);
|
|
1066
|
-
}
|
|
1067
|
-
|
|
1068
|
-
if (!args.sort) {
|
|
1069
|
-
args.sort = "`" + _this11.type + "`.created_at DESC";
|
|
1070
|
-
} else {
|
|
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
|
|
1072
|
-
|
|
1073
|
-
var new_sort_array = [];
|
|
1074
|
-
|
|
1075
|
-
for (var i = 0; i < sort_array.length; i++) {
|
|
1076
|
-
if (!sort_array[i].includes(".")) {
|
|
1077
|
-
new_sort_array.push("`" + _this11.type + "`." + formatSortComponent(sort_array[i]));
|
|
1078
|
-
} else {
|
|
1079
|
-
new_sort_array.push(sort_array[i]);
|
|
1080
|
-
}
|
|
1081
|
-
}
|
|
1082
|
-
|
|
1083
|
-
args.sort = _.join(new_sort_array, ",");
|
|
1084
|
-
}
|
|
1000
|
+
args.limit = Number(args.limit) || undefined;
|
|
1001
|
+
args.offset = Number(args.offset) || 0;
|
|
1002
|
+
args.sort = args.sort ? args.sort.split(",").map(item => item.includes(".") ? item : "`" + _this11.type + "`." + _this11.formatSortComponent(item)).join(",") : "`" + _this11.type + "`.created_at DESC";
|
|
1085
1003
|
|
|
1086
|
-
if (args.skip_hooks
|
|
1004
|
+
if (args.skip_hooks !== true) {
|
|
1087
1005
|
yield _this11.run_hook(_this11, "list", "before");
|
|
1088
1006
|
}
|
|
1089
1007
|
|
|
1090
|
-
|
|
1091
|
-
return str.replace(/[^a-zA-Z0-9]/g, "");
|
|
1092
|
-
}
|
|
1008
|
+
var cacheKey = _this11.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);
|
|
1093
1009
|
|
|
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);
|
|
1095
1010
|
var results;
|
|
1096
1011
|
|
|
1097
|
-
if (
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
var cached_results = yield _this11.getCacheProviderObject(_this11.type).get(key);
|
|
1101
|
-
results = cached_results == null ? void 0 : cached_results.value;
|
|
1012
|
+
if (_this11.shouldUseCache(_this11.type)) {
|
|
1013
|
+
var cachedResults = yield _this11.getCacheProviderObject(_this11.type).get(cacheKey);
|
|
1014
|
+
results = cachedResults == null ? void 0 : cachedResults.value;
|
|
1102
1015
|
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
}, _this11.getCacheConfig(_this11.type));
|
|
1110
|
-
}
|
|
1111
|
-
} else {
|
|
1112
|
-
results = yield _this11.database.query(query);
|
|
1113
|
-
}
|
|
1016
|
+
if (!results || (yield _this11.shouldForceRefresh(cachedResults))) {
|
|
1017
|
+
results = yield _this11.fetchResults(args, query);
|
|
1018
|
+
yield _this11.getCacheProviderObject(_this11.type).set(cacheKey, {
|
|
1019
|
+
value: results,
|
|
1020
|
+
time: new Date().getTime()
|
|
1021
|
+
}, _this11.getCacheConfig(_this11.type));
|
|
1114
1022
|
}
|
|
1115
1023
|
} else {
|
|
1116
|
-
|
|
1117
|
-
if (_this11.shouldUseCache(_this11.type)) {
|
|
1118
|
-
var _cached_results = yield _this11.getCacheProviderObject(_this11.type).get(key);
|
|
1119
|
-
|
|
1120
|
-
results = _cached_results == null ? void 0 : _cached_results.value;
|
|
1121
|
-
|
|
1122
|
-
if ((_cached_results == null ? void 0 : _cached_results.value) == undefined || (yield _this11.shouldForceRefresh(_cached_results))) {
|
|
1123
|
-
results = yield _this11.database.full_text_search(_this11.type, query || "", args.limit, args.offset, args._join);
|
|
1124
|
-
|
|
1125
|
-
_this11.getCacheProviderObject(_this11.type).set(key, {
|
|
1126
|
-
value: results,
|
|
1127
|
-
time: new Date().getTime()
|
|
1128
|
-
}, _this11.getCacheConfig(_this11.type));
|
|
1129
|
-
}
|
|
1130
|
-
} else {
|
|
1131
|
-
results = yield _this11.database.full_text_search(_this11.type, query || "", args.limit, args.offset, args._join);
|
|
1132
|
-
}
|
|
1133
|
-
} else {
|
|
1134
|
-
if (_this11.shouldUseCache(_this11.type)) {
|
|
1135
|
-
var _cached_results2 = yield _this11.getCacheProviderObject(_this11.type).get(key);
|
|
1136
|
-
|
|
1137
|
-
results = _cached_results2 == null ? void 0 : _cached_results2.value;
|
|
1138
|
-
var shouleForceRefresh = yield _this11.shouldForceRefresh(_cached_results2);
|
|
1139
|
-
|
|
1140
|
-
if ((_cached_results2 == null ? void 0 : _cached_results2.value) == undefined || shouleForceRefresh) {
|
|
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);
|
|
1142
|
-
|
|
1143
|
-
_this11.getCacheProviderObject(_this11.type).set(key, {
|
|
1144
|
-
value: results,
|
|
1145
|
-
time: new Date().getTime()
|
|
1146
|
-
}, _this11.getCacheConfig(_this11.type));
|
|
1147
|
-
}
|
|
1148
|
-
} else {
|
|
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);
|
|
1150
|
-
}
|
|
1151
|
-
}
|
|
1024
|
+
results = yield _this11.fetchResults(args, query);
|
|
1152
1025
|
}
|
|
1153
1026
|
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
}
|
|
1158
|
-
|
|
1159
|
-
if (_this11.type == "resourcedetail") ;
|
|
1027
|
+
if (args.skip_read_serialize !== true && args.skip_serialize !== true) {
|
|
1028
|
+
results.data = yield _this11.do_serialize(results.data, "read", {}, args, (yield _this11.propsToBeRemoved(results.data)));
|
|
1029
|
+
}
|
|
1160
1030
|
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
}
|
|
1164
|
-
} catch (e) {
|
|
1165
|
-
console.log(e);
|
|
1031
|
+
if (args.skip_hooks !== true) {
|
|
1032
|
+
yield _this11.run_hook(results.data, "list", "after");
|
|
1166
1033
|
}
|
|
1167
1034
|
|
|
1168
|
-
results.data = filterResultsByColumns(results.data, args.columns);
|
|
1035
|
+
results.data = _this11.filterResultsByColumns(results.data, args.columns);
|
|
1169
1036
|
return results;
|
|
1170
1037
|
} catch (e) {
|
|
1171
1038
|
console.log(e.stack);
|
|
@@ -1174,6 +1041,21 @@ class SpiceModel {
|
|
|
1174
1041
|
})();
|
|
1175
1042
|
}
|
|
1176
1043
|
|
|
1044
|
+
fetchResults(args, query) {
|
|
1045
|
+
var _this12 = this;
|
|
1046
|
+
|
|
1047
|
+
return _asyncToGenerator(function* () {
|
|
1048
|
+
if (args.is_custom_query === "true" && args.ids.length > 0) {
|
|
1049
|
+
return yield _this12.database.query(query);
|
|
1050
|
+
} else if (args.is_full_text === "true") {
|
|
1051
|
+
return yield _this12.database.full_text_search(_this12.type, query || "", args.limit, args.offset, args._join);
|
|
1052
|
+
} else {
|
|
1053
|
+
var result = yield _this12.database.search(_this12.type, args.columns || "", query || "", args.limit, args.offset, args.sort, args.do_count, args.statement_consistent, args._join);
|
|
1054
|
+
return result;
|
|
1055
|
+
}
|
|
1056
|
+
})();
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1177
1059
|
addHook(_ref2) {
|
|
1178
1060
|
var {
|
|
1179
1061
|
operation,
|
|
@@ -1185,26 +1067,26 @@ class SpiceModel {
|
|
|
1185
1067
|
}
|
|
1186
1068
|
|
|
1187
1069
|
run_hook(data, op, when, old_data) {
|
|
1188
|
-
var
|
|
1070
|
+
var _this13 = this;
|
|
1189
1071
|
|
|
1190
1072
|
return _asyncToGenerator(function* () {
|
|
1191
1073
|
try {
|
|
1192
|
-
if (
|
|
1074
|
+
if (_this13[_disable_lifecycle_events] == false) {
|
|
1193
1075
|
var resourceLifecycleTriggered = new _ResourceLifecycleTriggered.default({
|
|
1194
1076
|
data: {
|
|
1195
1077
|
data,
|
|
1196
1078
|
operation: op,
|
|
1197
1079
|
when,
|
|
1198
1080
|
old_data,
|
|
1199
|
-
resource:
|
|
1200
|
-
ctx:
|
|
1081
|
+
resource: _this13.type,
|
|
1082
|
+
ctx: _this13[_ctx]
|
|
1201
1083
|
}
|
|
1202
1084
|
});
|
|
1203
1085
|
resourceLifecycleTriggered.dispatch();
|
|
1204
1086
|
}
|
|
1205
1087
|
|
|
1206
|
-
if (
|
|
1207
|
-
for (var i of
|
|
1088
|
+
if (_this13[_hooks] && _this13[_hooks][op] && _this13[_hooks][op][when]) {
|
|
1089
|
+
for (var i of _this13[_hooks][op][when]) {
|
|
1208
1090
|
data = yield i(data, old_data);
|
|
1209
1091
|
}
|
|
1210
1092
|
}
|
|
@@ -1237,7 +1119,7 @@ class SpiceModel {
|
|
|
1237
1119
|
}
|
|
1238
1120
|
|
|
1239
1121
|
mapToObject(data, Class, source_property, store_property, property) {
|
|
1240
|
-
var
|
|
1122
|
+
var _this14 = this;
|
|
1241
1123
|
|
|
1242
1124
|
return _asyncToGenerator(function* () {
|
|
1243
1125
|
var original_is_array = _.isArray(data);
|
|
@@ -1256,8 +1138,8 @@ class SpiceModel {
|
|
|
1256
1138
|
});
|
|
1257
1139
|
|
|
1258
1140
|
var returned_all = yield Promise.allSettled(_.map(classes, obj => {
|
|
1259
|
-
return new obj(_extends({},
|
|
1260
|
-
skip_cache:
|
|
1141
|
+
return new obj(_extends({}, _this14[_args], {
|
|
1142
|
+
skip_cache: _this14[_skip_cache]
|
|
1261
1143
|
})).getMulti({
|
|
1262
1144
|
skip_hooks: true,
|
|
1263
1145
|
ids: ids
|
|
@@ -1280,7 +1162,7 @@ class SpiceModel {
|
|
|
1280
1162
|
}
|
|
1281
1163
|
|
|
1282
1164
|
mapToObjectArray(data, Class, source_property, store_property, property) {
|
|
1283
|
-
var
|
|
1165
|
+
var _this15 = this;
|
|
1284
1166
|
|
|
1285
1167
|
return _asyncToGenerator(function* () {
|
|
1286
1168
|
var original_is_array = _.isArray(data);
|
|
@@ -1309,8 +1191,8 @@ class SpiceModel {
|
|
|
1309
1191
|
|
|
1310
1192
|
var classes = _.isArray(Class) ? Class : [Class];
|
|
1311
1193
|
var returned_all = yield Promise.allSettled(_.map(classes, obj => {
|
|
1312
|
-
return new obj(_extends({},
|
|
1313
|
-
skip_cache:
|
|
1194
|
+
return new obj(_extends({}, _this15[_args], {
|
|
1195
|
+
skip_cache: _this15[_skip_cache]
|
|
1314
1196
|
})).getMulti({
|
|
1315
1197
|
skip_hooks: true,
|
|
1316
1198
|
ids: ids
|
|
@@ -1372,7 +1254,7 @@ class SpiceModel {
|
|
|
1372
1254
|
}
|
|
1373
1255
|
|
|
1374
1256
|
createMofifier(properties) {
|
|
1375
|
-
var
|
|
1257
|
+
var _this16 = this;
|
|
1376
1258
|
|
|
1377
1259
|
var _loop = function _loop(i) {
|
|
1378
1260
|
if (properties[i].map) {
|
|
@@ -1383,11 +1265,11 @@ class SpiceModel {
|
|
|
1383
1265
|
case String:
|
|
1384
1266
|
case "string":
|
|
1385
1267
|
{
|
|
1386
|
-
|
|
1268
|
+
_this16.addModifier({
|
|
1387
1269
|
when: properties[i].map.when || "read",
|
|
1388
1270
|
execute: function () {
|
|
1389
1271
|
var _execute = _asyncToGenerator(function* (data) {
|
|
1390
|
-
return yield
|
|
1272
|
+
return yield _this16.mapToObject(data, _.isString(properties[i].map.reference) ? spice.models[properties[i].map.reference] : properties[i].map.reference, i, properties[i].map.destination || i, properties[i]);
|
|
1391
1273
|
});
|
|
1392
1274
|
|
|
1393
1275
|
function execute(_x) {
|
|
@@ -1404,11 +1286,11 @@ class SpiceModel {
|
|
|
1404
1286
|
case Array:
|
|
1405
1287
|
case "array":
|
|
1406
1288
|
{
|
|
1407
|
-
|
|
1289
|
+
_this16.addModifier({
|
|
1408
1290
|
when: properties[i].map.when || "read",
|
|
1409
1291
|
execute: function () {
|
|
1410
1292
|
var _execute2 = _asyncToGenerator(function* (data) {
|
|
1411
|
-
return yield
|
|
1293
|
+
return yield _this16.mapToObjectArray(data, _.isString(properties[i].map.reference) ? spice.models[properties[i].map.reference] : properties[i].map.reference, i, properties[i].map.destination || i, properties[i]);
|
|
1412
1294
|
});
|
|
1413
1295
|
|
|
1414
1296
|
function execute(_x2) {
|
|
@@ -1440,7 +1322,7 @@ class SpiceModel {
|
|
|
1440
1322
|
}
|
|
1441
1323
|
|
|
1442
1324
|
do_serialize(data, type, old_data, args, path_to_be_removed) {
|
|
1443
|
-
var
|
|
1325
|
+
var _this17 = this;
|
|
1444
1326
|
|
|
1445
1327
|
return _asyncToGenerator(function* () {
|
|
1446
1328
|
//console.log("CTX INside Model DO", this[_ctx]);
|
|
@@ -1450,16 +1332,16 @@ class SpiceModel {
|
|
|
1450
1332
|
path_to_be_removed = [];
|
|
1451
1333
|
}
|
|
1452
1334
|
|
|
1453
|
-
if (
|
|
1454
|
-
if (
|
|
1455
|
-
|
|
1335
|
+
if (_this17.shouldSerializerRun(args, type)) {
|
|
1336
|
+
if (_this17.type != "" && _this17.type != undefined && _this17[_external_modifier_loaded] != true) {
|
|
1337
|
+
_this17.addExternalModifiers(_this17.type);
|
|
1456
1338
|
|
|
1457
|
-
|
|
1339
|
+
_this17[_external_modifier_loaded] = true;
|
|
1458
1340
|
}
|
|
1459
1341
|
|
|
1460
|
-
for (var i of
|
|
1342
|
+
for (var i of _this17[_serializers][type]["modifiers"]) {
|
|
1461
1343
|
try {
|
|
1462
|
-
data = yield i(data, old_data,
|
|
1344
|
+
data = yield i(data, old_data, _this17[_ctx], _this17.type);
|
|
1463
1345
|
} catch (e) {
|
|
1464
1346
|
console.log(e.stack);
|
|
1465
1347
|
}
|
|
@@ -1475,12 +1357,12 @@ class SpiceModel {
|
|
|
1475
1357
|
|
|
1476
1358
|
var defaults = {};
|
|
1477
1359
|
|
|
1478
|
-
for (var _i in
|
|
1479
|
-
if (
|
|
1480
|
-
defaults[_i] = _.isFunction(
|
|
1360
|
+
for (var _i in _this17.props) {
|
|
1361
|
+
if (_this17.props[_i].defaults != undefined && _this17.props[_i].defaults[type] != undefined && _this17.props[_i].defaults[type] != undefined) {
|
|
1362
|
+
defaults[_i] = _.isFunction(_this17.props[_i].defaults[type]) ? _this17.props[_i].defaults[type]({
|
|
1481
1363
|
old_data: data,
|
|
1482
1364
|
new_data: old_data
|
|
1483
|
-
}) :
|
|
1365
|
+
}) : _this17.props[_i].defaults[type];
|
|
1484
1366
|
}
|
|
1485
1367
|
} // apply defaults
|
|
1486
1368
|
|
|
@@ -1493,8 +1375,8 @@ class SpiceModel {
|
|
|
1493
1375
|
if (type == "read") {
|
|
1494
1376
|
var props_to_clean = ["deleted", "type", ...path_to_be_removed];
|
|
1495
1377
|
|
|
1496
|
-
for (var _i3 in
|
|
1497
|
-
if (
|
|
1378
|
+
for (var _i3 in _this17.props) {
|
|
1379
|
+
if (_this17.props[_i3].hide) {
|
|
1498
1380
|
props_to_clean.push(_i3);
|
|
1499
1381
|
}
|
|
1500
1382
|
}
|
|
@@ -11,13 +11,9 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try
|
|
|
11
11
|
|
|
12
12
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
13
13
|
|
|
14
|
-
var fs = require(
|
|
14
|
+
var fs = require("fs-extra");
|
|
15
15
|
|
|
16
|
-
var
|
|
17
|
-
|
|
18
|
-
var open = require("open");
|
|
19
|
-
|
|
20
|
-
var uuid = require('uuid');
|
|
16
|
+
var uuid = require("uuid");
|
|
21
17
|
|
|
22
18
|
class Local {
|
|
23
19
|
constructor(args) {
|
|
@@ -35,7 +31,7 @@ class Local {
|
|
|
35
31
|
path
|
|
36
32
|
} = _ref;
|
|
37
33
|
|
|
38
|
-
if (_lodash.default.has(files,
|
|
34
|
+
if (_lodash.default.has(files, "path") && _lodash.default.has(files, "size") && _lodash.default.has(files, "_writeStream")) {
|
|
39
35
|
files = {
|
|
40
36
|
files
|
|
41
37
|
};
|
|
@@ -55,14 +51,14 @@ class Local {
|
|
|
55
51
|
if (!fs.existsSync(dir)) {
|
|
56
52
|
fs.mkdirSync(dir);
|
|
57
53
|
}
|
|
58
|
-
} // Create folders
|
|
54
|
+
} // Create folders
|
|
59
55
|
|
|
60
56
|
|
|
61
|
-
var pathArray = path.split(
|
|
57
|
+
var pathArray = path.split("/");
|
|
62
58
|
|
|
63
59
|
_lodash.default.reduce(pathArray, (accu, item) => {
|
|
64
60
|
if (item != accu) {
|
|
65
|
-
accu = _lodash.default.join([accu, item],
|
|
61
|
+
accu = _lodash.default.join([accu, item], "/");
|
|
66
62
|
}
|
|
67
63
|
|
|
68
64
|
makeDirectory(accu);
|
|
@@ -78,8 +74,6 @@ class Local {
|
|
|
78
74
|
}); // Create Write Stream
|
|
79
75
|
|
|
80
76
|
|
|
81
|
-
;
|
|
82
|
-
|
|
83
77
|
var paths = _lodash.default.map(readStreams, item => {
|
|
84
78
|
var extension = _lodash.default.last(item.file.name.split("."));
|
|
85
79
|
|