spice-js 2.6.21 → 2.6.23
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.
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _path = _interopRequireDefault(require("path"));
|
|
4
|
+
|
|
5
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
6
|
+
|
|
7
|
+
spice.routers = {};
|
|
8
|
+
|
|
9
|
+
var paths = _path.default.join(spice.root_path, "schema_extenders");
|
|
10
|
+
|
|
11
|
+
spice.schemaExtenders = {};
|
|
12
|
+
|
|
13
|
+
require("fs").readdirSync(paths).forEach(function (file) {
|
|
14
|
+
if (file != "index.js") {
|
|
15
|
+
var extender = require(_path.default.join(paths, file));
|
|
16
|
+
|
|
17
|
+
spice.schemaExtenders[file.split(".")[0]] = extender;
|
|
18
|
+
spice.schema_extenders = spice.schemaExtenders;
|
|
19
|
+
}
|
|
20
|
+
});
|
package/build/loaders/index.js
CHANGED
|
@@ -15,7 +15,7 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try
|
|
|
15
15
|
|
|
16
16
|
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); }); }; }
|
|
17
17
|
|
|
18
|
-
var ordered_modules = ["database", "map", "logger", "error"];
|
|
18
|
+
var ordered_modules = ["schema_extenders", "database", "map", "logger", "error"];
|
|
19
19
|
var last_modules = ["views", "routes"];
|
|
20
20
|
|
|
21
21
|
function load() {
|
|
@@ -117,7 +117,55 @@ class SpiceModel {
|
|
|
117
117
|
return returnVal;
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
|
|
120
|
+
function applySchemaOverrides(props, resource) {
|
|
121
|
+
spice.schema_extenders = spice.schema_extenders || [];
|
|
122
|
+
|
|
123
|
+
function applyExtenderModifier(prop, resource, extender) {
|
|
124
|
+
if (extender.modifier) {
|
|
125
|
+
return extender.modifier(prop, resource);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return prop;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function hasExtender(resource, prop, extender) {
|
|
132
|
+
if (extender.selector(prop, resource)) {
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function resourceHasExtender(resource, extender) {
|
|
140
|
+
return extender.resource.includes(resource) || extender.resource.includes("*");
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
for (var file_name in spice.schema_extenders) {
|
|
144
|
+
var extender = spice.schema_extenders[file_name];
|
|
145
|
+
|
|
146
|
+
if (resourceHasExtender(resource, extender)) {
|
|
147
|
+
console.log("Resource:", resource);
|
|
148
|
+
|
|
149
|
+
for (var j in props) {
|
|
150
|
+
if (hasExtender(resource, props[j], extender)) {
|
|
151
|
+
console.log("Modifying Prop:", props[j]);
|
|
152
|
+
props[j] = applyExtenderModifier(props[j], resource, extender);
|
|
153
|
+
console.log("Modified Prop", props[j]);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (extender == null ? void 0 : extender.creator) {
|
|
158
|
+
console.log("Applying Creator:", resource);
|
|
159
|
+
props = _.merge(props, extender.creator(resource));
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return props;
|
|
164
|
+
}
|
|
165
|
+
} //console.log("Applying Overrides to :", this.collection,'||', args.collection)
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
args.props = applySchemaOverrides(removeDynamicProps(args.props), args.collection);
|
|
121
169
|
this[_props] = args.props;
|
|
122
170
|
|
|
123
171
|
for (var i in args.props) {
|
|
@@ -526,14 +574,14 @@ class SpiceModel {
|
|
|
526
574
|
yield _this4.run_hook(args, "get", "before");
|
|
527
575
|
}
|
|
528
576
|
|
|
529
|
-
var key = _this4.type + "::" + args.id;
|
|
577
|
+
var key = "get::" + _this4.type + "::" + args.id;
|
|
530
578
|
var results = {};
|
|
531
579
|
|
|
532
580
|
if (_this4.shouldUseCache(_this4.type)) {
|
|
533
581
|
var cached_results = yield _this4.getCacheProviderObject(_this4.type).get(key);
|
|
534
582
|
results = cached_results == null ? void 0 : cached_results.value;
|
|
535
583
|
|
|
536
|
-
if ((cached_results == null ? void 0 : cached_results.value) == undefined || (yield _this4.shouldForceRefresh(cached_results))) {
|
|
584
|
+
if ((cached_results == null ? void 0 : cached_results.value) == undefined || (yield _this4.shouldForceRefresh(cached_results)) || _this4.type == "workflow") {
|
|
537
585
|
results = yield _this4.database.get(args.id);
|
|
538
586
|
yield _this4.getCacheProviderObject(_this4.type).set(key, {
|
|
539
587
|
value: results,
|
|
@@ -601,7 +649,7 @@ class SpiceModel {
|
|
|
601
649
|
|
|
602
650
|
_.remove(args.ids, o => o == undefined);
|
|
603
651
|
|
|
604
|
-
var key = _this6.type + "::" + _.join(args.ids, "|");
|
|
652
|
+
var key = "multi-get::" + _this6.type + "::" + _.join(args.ids, "|");
|
|
605
653
|
|
|
606
654
|
var results = [];
|
|
607
655
|
|
|
@@ -946,6 +994,15 @@ class SpiceModel {
|
|
|
946
994
|
}
|
|
947
995
|
}
|
|
948
996
|
|
|
997
|
+
function formatSortComponent(sortComponent) {
|
|
998
|
+
// Split the string by spaces to get individual parts
|
|
999
|
+
var parts = sortComponent.split(" "); // Assuming the first part is the column name, add backticks around it
|
|
1000
|
+
|
|
1001
|
+
parts[0] = "`" + parts[0] + "`"; // Rejoin the parts back into a string and return
|
|
1002
|
+
|
|
1003
|
+
return parts.join(" ");
|
|
1004
|
+
}
|
|
1005
|
+
|
|
949
1006
|
if ((0, _Security.hasSQLInjection)(query)) {
|
|
950
1007
|
return [];
|
|
951
1008
|
}
|
|
@@ -967,7 +1024,7 @@ class SpiceModel {
|
|
|
967
1024
|
|
|
968
1025
|
for (var i = 0; i < sort_array.length; i++) {
|
|
969
1026
|
if (!sort_array[i].includes(".")) {
|
|
970
|
-
new_sort_array.push("`" + _this11.type + "
|
|
1027
|
+
new_sort_array.push("`" + _this11.type + "`." + formatSortComponent(sort_array[i]));
|
|
971
1028
|
} else {
|
|
972
1029
|
new_sort_array.push(sort_array[i]);
|
|
973
1030
|
}
|
|
@@ -984,7 +1041,7 @@ class SpiceModel {
|
|
|
984
1041
|
return str.replace(/[^a-zA-Z0-9]/g, "");
|
|
985
1042
|
}
|
|
986
1043
|
|
|
987
|
-
var key = removeSpaceAndSpecialCharacters(_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);
|
|
1044
|
+
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);
|
|
988
1045
|
var results;
|
|
989
1046
|
|
|
990
1047
|
if (args.is_custom_query && args.is_custom_query === "true") {
|
|
@@ -1049,6 +1106,8 @@ class SpiceModel {
|
|
|
1049
1106
|
results.data = yield _this11.do_serialize(results.data, "read", {}, args, (yield _this11.propsToBeRemoved(results.data)));
|
|
1050
1107
|
}
|
|
1051
1108
|
|
|
1109
|
+
if (_this11.type == "resourcedetail") ;
|
|
1110
|
+
|
|
1052
1111
|
if (args.skip_hooks != true) {
|
|
1053
1112
|
yield _this11.run_hook(results.data, "list", "after");
|
|
1054
1113
|
}
|
|
@@ -1150,6 +1209,7 @@ class SpiceModel {
|
|
|
1150
1209
|
return new obj(_extends({}, _this13[_args], {
|
|
1151
1210
|
skip_cache: _this13[_skip_cache]
|
|
1152
1211
|
})).getMulti({
|
|
1212
|
+
skip_hooks: true,
|
|
1153
1213
|
ids: ids
|
|
1154
1214
|
});
|
|
1155
1215
|
}));
|
|
@@ -1202,6 +1262,7 @@ class SpiceModel {
|
|
|
1202
1262
|
return new obj(_extends({}, _this14[_args], {
|
|
1203
1263
|
skip_cache: _this14[_skip_cache]
|
|
1204
1264
|
})).getMulti({
|
|
1265
|
+
skip_hooks: true,
|
|
1205
1266
|
ids: ids
|
|
1206
1267
|
});
|
|
1207
1268
|
}));
|
package/package.json
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
|
|
3
|
+
spice.routers = {};
|
|
4
|
+
|
|
5
|
+
let paths = path.join(spice.root_path, "schema_extenders");
|
|
6
|
+
spice.schemaExtenders = {};
|
|
7
|
+
require("fs")
|
|
8
|
+
.readdirSync(paths)
|
|
9
|
+
.forEach(function (file) {
|
|
10
|
+
if (file != "index.js") {
|
|
11
|
+
let extender = require(path.join(paths, file));
|
|
12
|
+
spice.schemaExtenders[file.split(".")[0]] = extender;
|
|
13
|
+
spice.schema_extenders = spice.schemaExtenders;
|
|
14
|
+
}
|
|
15
|
+
});
|
package/src/loaders/index.js
CHANGED
|
@@ -2,7 +2,13 @@ import path from "path";
|
|
|
2
2
|
import fs from "fs";
|
|
3
3
|
import _ from "lodash";
|
|
4
4
|
|
|
5
|
-
let ordered_modules = [
|
|
5
|
+
let ordered_modules = [
|
|
6
|
+
"schema_extenders",
|
|
7
|
+
"database",
|
|
8
|
+
"map",
|
|
9
|
+
"logger",
|
|
10
|
+
"error",
|
|
11
|
+
];
|
|
6
12
|
let last_modules = ["views", "routes"];
|
|
7
13
|
export async function load() {
|
|
8
14
|
try {
|
package/src/models/SpiceModel.js
CHANGED
|
@@ -102,7 +102,55 @@ export default class SpiceModel {
|
|
|
102
102
|
}
|
|
103
103
|
return returnVal;
|
|
104
104
|
}
|
|
105
|
-
|
|
105
|
+
|
|
106
|
+
function applySchemaOverrides(props, resource) {
|
|
107
|
+
spice.schema_extenders = spice.schema_extenders || [];
|
|
108
|
+
|
|
109
|
+
function applyExtenderModifier(prop, resource, extender) {
|
|
110
|
+
if (extender.modifier) {
|
|
111
|
+
return extender.modifier(prop, resource);
|
|
112
|
+
}
|
|
113
|
+
return prop;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function hasExtender(resource, prop, extender) {
|
|
117
|
+
if (extender.selector(prop, resource)) {
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function resourceHasExtender(resource, extender) {
|
|
124
|
+
return (
|
|
125
|
+
extender.resource.includes(resource) ||
|
|
126
|
+
extender.resource.includes("*")
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
for (let file_name in spice.schema_extenders) {
|
|
131
|
+
let extender = spice.schema_extenders[file_name];
|
|
132
|
+
if (resourceHasExtender(resource, extender)) {
|
|
133
|
+
console.log("Resource:", resource);
|
|
134
|
+
for (let j in props) {
|
|
135
|
+
if (hasExtender(resource, props[j], extender)) {
|
|
136
|
+
console.log("Modifying Prop:", props[j]);
|
|
137
|
+
props[j] = applyExtenderModifier(props[j], resource, extender);
|
|
138
|
+
console.log("Modified Prop", props[j]);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if (extender?.creator) {
|
|
142
|
+
console.log("Applying Creator:", resource);
|
|
143
|
+
props = _.merge(props, extender.creator(resource));
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return props;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
//console.log("Applying Overrides to :", this.collection,'||', args.collection)
|
|
150
|
+
args.props = applySchemaOverrides(
|
|
151
|
+
removeDynamicProps(args.props),
|
|
152
|
+
args.collection
|
|
153
|
+
);
|
|
106
154
|
this[_props] = args.props;
|
|
107
155
|
for (let i in args.props) {
|
|
108
156
|
if (args.args != undefined) {
|