spice-js 2.6.56 → 2.6.58
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.
|
@@ -12,7 +12,8 @@ var crypto = require("crypto");
|
|
|
12
12
|
|
|
13
13
|
function generateCacheKey(input) {
|
|
14
14
|
// Create an MD5 hash of the input string and return it in hexadecimal format
|
|
15
|
-
return crypto.createHash("md5").update(input).digest("hex");
|
|
15
|
+
//return crypto.createHash("md5").update(input).digest("hex");
|
|
16
|
+
return input;
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
module.exports = class SpiceCache {
|
|
@@ -53,8 +54,9 @@ module.exports = class SpiceCache {
|
|
|
53
54
|
namespace = ""
|
|
54
55
|
} = working_options;
|
|
55
56
|
var workingKey = namespace + key;
|
|
57
|
+
var cacheKey = generateCacheKey(workingKey);
|
|
56
58
|
|
|
57
|
-
_this2.client.set(
|
|
59
|
+
_this2.client.set(cacheKey, value, ttl === undefined ? 60 : ttl);
|
|
58
60
|
})();
|
|
59
61
|
}
|
|
60
62
|
|
|
@@ -79,11 +81,19 @@ module.exports = class SpiceCache {
|
|
|
79
81
|
})();
|
|
80
82
|
}
|
|
81
83
|
|
|
82
|
-
exists(key) {
|
|
84
|
+
exists(key, options) {
|
|
83
85
|
var _this4 = this;
|
|
84
86
|
|
|
85
87
|
return _asyncToGenerator(function* () {
|
|
86
|
-
|
|
88
|
+
if (options === void 0) {
|
|
89
|
+
options = {};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
var {
|
|
93
|
+
namespace = ""
|
|
94
|
+
} = options;
|
|
95
|
+
var workingKey = namespace + key;
|
|
96
|
+
var cacheKey = generateCacheKey(workingKey);
|
|
87
97
|
return yield _this4.client.has(cacheKey);
|
|
88
98
|
})();
|
|
89
99
|
}
|
|
@@ -542,7 +542,6 @@ class SpiceModel {
|
|
|
542
542
|
}
|
|
543
543
|
|
|
544
544
|
if (monitor_record.time > (response == null ? void 0 : response.time)) {
|
|
545
|
-
if (_this3.type == "resourcedetail") console.log("Will Force Refresh");
|
|
546
545
|
return true;
|
|
547
546
|
}
|
|
548
547
|
|
|
@@ -574,7 +573,7 @@ class SpiceModel {
|
|
|
574
573
|
}
|
|
575
574
|
|
|
576
575
|
if (_.isString(args.id)) {
|
|
577
|
-
if (args.skip_hooks
|
|
576
|
+
if (args.skip_hooks !== true) {
|
|
578
577
|
yield _this4.run_hook(args, "get", "before");
|
|
579
578
|
}
|
|
580
579
|
|
|
@@ -582,34 +581,43 @@ class SpiceModel {
|
|
|
582
581
|
var results = {};
|
|
583
582
|
|
|
584
583
|
if (_this4.shouldUseCache(_this4.type)) {
|
|
585
|
-
|
|
586
|
-
|
|
584
|
+
// Retrieve the cached results
|
|
585
|
+
var cached_results = yield _this4.getCacheProviderObject(_this4.type).get(key); // Check if the cache is empty
|
|
586
|
+
|
|
587
|
+
var isCacheEmpty = (cached_results == null ? void 0 : cached_results.value) === undefined; // Check if the cached result should be refreshed
|
|
587
588
|
|
|
588
|
-
|
|
589
|
+
var shouldRefresh = yield _this4.shouldForceRefresh(cached_results); // Force a refresh for "workflow" type if needed
|
|
590
|
+
|
|
591
|
+
if (isCacheEmpty || shouldRefresh) {
|
|
592
|
+
// Retrieve from the database and update cache
|
|
589
593
|
results = yield _this4.database.get(args.id);
|
|
590
594
|
yield _this4.getCacheProviderObject(_this4.type).set(key, {
|
|
591
595
|
value: results,
|
|
592
596
|
time: new Date().getTime()
|
|
593
597
|
}, _this4.getCacheConfig(_this4.type));
|
|
598
|
+
} else {
|
|
599
|
+
// Use the cached value
|
|
600
|
+
results = cached_results.value;
|
|
594
601
|
}
|
|
595
602
|
} else {
|
|
603
|
+
// Directly fetch from the database if caching is disabled
|
|
596
604
|
results = yield _this4.database.get(args.id);
|
|
597
605
|
}
|
|
598
606
|
|
|
599
|
-
if (results.type
|
|
600
|
-
|
|
607
|
+
if (results.type !== undefined && results.type !== _this4.type) {
|
|
608
|
+
throw new Error(_this4.type + " does not exist type");
|
|
601
609
|
}
|
|
602
610
|
|
|
603
|
-
if (results._type
|
|
604
|
-
|
|
611
|
+
if (results._type !== undefined && results._type !== _this4.type) {
|
|
612
|
+
throw new Error(_this4.type + " does not exist _type");
|
|
605
613
|
}
|
|
606
614
|
|
|
607
|
-
if (results.deleted
|
|
608
|
-
if (args.skip_read_serialize
|
|
615
|
+
if (results.deleted === undefined || results.deleted === false) {
|
|
616
|
+
if (args.skip_read_serialize !== true && args.skip_serialize !== true) {
|
|
609
617
|
results = yield _this4.do_serialize(results, "read", {}, args, (yield _this4.propsToBeRemoved(results)));
|
|
610
618
|
}
|
|
611
619
|
|
|
612
|
-
if (args.skip_hooks
|
|
620
|
+
if (args.skip_hooks !== true) {
|
|
613
621
|
yield _this4.run_hook(results, "get", "after");
|
|
614
622
|
}
|
|
615
623
|
|
|
@@ -996,10 +1004,10 @@ class SpiceModel {
|
|
|
996
1004
|
parts[0] = "`" + parts[0] + "`";
|
|
997
1005
|
return parts.join(" ");
|
|
998
1006
|
}
|
|
999
|
-
|
|
1000
|
-
removeSpaceAndSpecialCharacters(str) {
|
|
1007
|
+
/* removeSpaceAndSpecialCharacters(str) {
|
|
1001
1008
|
return str.replace(/[^a-zA-Z0-9]/g, "");
|
|
1002
|
-
}
|
|
1009
|
+
} */
|
|
1010
|
+
|
|
1003
1011
|
|
|
1004
1012
|
fixColumnName(columns) {
|
|
1005
1013
|
// Guard clause: if columns is not provided or not a string, return it as-is.
|
|
@@ -1116,24 +1124,25 @@ class SpiceModel {
|
|
|
1116
1124
|
yield _this12.run_hook(_this12, "list", "before");
|
|
1117
1125
|
}
|
|
1118
1126
|
|
|
1119
|
-
var cacheKey =
|
|
1120
|
-
|
|
1127
|
+
var cacheKey = "list::" + _this12.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;
|
|
1121
1128
|
var results;
|
|
1122
1129
|
|
|
1123
1130
|
if (_this12.shouldUseCache(_this12.type)) {
|
|
1124
1131
|
var cachedResults = yield _this12.getCacheProviderObject(_this12.type).get(cacheKey);
|
|
1125
|
-
results = cachedResults == null ? void 0 : cachedResults.value;
|
|
1132
|
+
results = cachedResults == null ? void 0 : cachedResults.value; // Check if there is no cached value
|
|
1126
1133
|
|
|
1127
|
-
|
|
1134
|
+
var isCacheEmpty = (cachedResults == null ? void 0 : cachedResults.value) === undefined; // Check if the cached value should be refreshed (e.g., due to the monitor's timestamp)
|
|
1135
|
+
|
|
1136
|
+
var shouldRefresh = yield _this12.shouldForceRefresh(cachedResults); // Always force a refresh for "workflow" type
|
|
1137
|
+
|
|
1138
|
+
if (isCacheEmpty || shouldRefresh) {
|
|
1139
|
+
// Force a database read and cache update
|
|
1128
1140
|
results = yield _this12.fetchResults(args, query);
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
results
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
time: new Date().getTime()
|
|
1135
|
-
}, _this12.getCacheConfig(_this12.type));
|
|
1136
|
-
}
|
|
1141
|
+
|
|
1142
|
+
_this12.getCacheProviderObject(_this12.type).set(cacheKey, {
|
|
1143
|
+
value: results,
|
|
1144
|
+
time: new Date().getTime()
|
|
1145
|
+
}, _this12.getCacheConfig(_this12.type));
|
|
1137
1146
|
}
|
|
1138
1147
|
} else {
|
|
1139
1148
|
results = yield _this12.fetchResults(args, query);
|
package/package.json
CHANGED
|
@@ -3,7 +3,8 @@ const crypto = require("crypto");
|
|
|
3
3
|
|
|
4
4
|
function generateCacheKey(input) {
|
|
5
5
|
// Create an MD5 hash of the input string and return it in hexadecimal format
|
|
6
|
-
return crypto.createHash("md5").update(input).digest("hex");
|
|
6
|
+
//return crypto.createHash("md5").update(input).digest("hex");
|
|
7
|
+
return input;
|
|
7
8
|
}
|
|
8
9
|
|
|
9
10
|
module.exports = class SpiceCache {
|
|
@@ -20,11 +21,8 @@ module.exports = class SpiceCache {
|
|
|
20
21
|
let working_options = { ...this.options, ...options };
|
|
21
22
|
const { ttl, namespace = "" } = working_options;
|
|
22
23
|
const workingKey = namespace + key;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
value,
|
|
26
|
-
ttl == undefined ? 60 : ttl
|
|
27
|
-
);
|
|
24
|
+
const cacheKey = generateCacheKey(workingKey);
|
|
25
|
+
this.client.set(cacheKey, value, ttl === undefined ? 60 : ttl);
|
|
28
26
|
}
|
|
29
27
|
|
|
30
28
|
async get(key, options = {}) {
|
|
@@ -38,8 +36,10 @@ module.exports = class SpiceCache {
|
|
|
38
36
|
}
|
|
39
37
|
}
|
|
40
38
|
|
|
41
|
-
async exists(key) {
|
|
42
|
-
const
|
|
39
|
+
async exists(key, options = {}) {
|
|
40
|
+
const { namespace = "" } = options;
|
|
41
|
+
const workingKey = namespace + key;
|
|
42
|
+
const cacheKey = generateCacheKey(workingKey);
|
|
43
43
|
return await this.client.has(cacheKey);
|
|
44
44
|
}
|
|
45
45
|
};
|
package/src/models/SpiceModel.js
CHANGED
|
@@ -468,7 +468,6 @@ export default class SpiceModel {
|
|
|
468
468
|
return false;
|
|
469
469
|
}
|
|
470
470
|
if (monitor_record.time > response?.time) {
|
|
471
|
-
if (this.type == "resourcedetail") console.log("Will Force Refresh");
|
|
472
471
|
return true;
|
|
473
472
|
}
|
|
474
473
|
return false;
|
|
@@ -490,45 +489,51 @@ export default class SpiceModel {
|
|
|
490
489
|
args = {};
|
|
491
490
|
}
|
|
492
491
|
if (_.isString(args.id)) {
|
|
493
|
-
if (args.skip_hooks
|
|
492
|
+
if (args.skip_hooks !== true) {
|
|
494
493
|
await this.run_hook(args, "get", "before");
|
|
495
494
|
}
|
|
496
495
|
let key = `get::${this.type}::${args.id}`;
|
|
497
496
|
let results = {};
|
|
498
|
-
if (this.shouldUseCache(this.type)) {
|
|
499
|
-
let cached_results = await this.getCacheProviderObject(this.type).get(
|
|
500
|
-
key
|
|
501
|
-
);
|
|
502
497
|
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
498
|
+
if (this.shouldUseCache(this.type)) {
|
|
499
|
+
// Retrieve the cached results
|
|
500
|
+
const cached_results = await this.getCacheProviderObject(
|
|
501
|
+
this.type
|
|
502
|
+
).get(key);
|
|
503
|
+
// Check if the cache is empty
|
|
504
|
+
const isCacheEmpty = cached_results?.value === undefined;
|
|
505
|
+
// Check if the cached result should be refreshed
|
|
506
|
+
const shouldRefresh = await this.shouldForceRefresh(cached_results);
|
|
507
|
+
// Force a refresh for "workflow" type if needed
|
|
508
|
+
|
|
509
|
+
if (isCacheEmpty || shouldRefresh) {
|
|
510
|
+
// Retrieve from the database and update cache
|
|
509
511
|
results = await this.database.get(args.id);
|
|
510
512
|
await this.getCacheProviderObject(this.type).set(
|
|
511
513
|
key,
|
|
512
514
|
{ value: results, time: new Date().getTime() },
|
|
513
515
|
this.getCacheConfig(this.type)
|
|
514
516
|
);
|
|
517
|
+
} else {
|
|
518
|
+
// Use the cached value
|
|
519
|
+
results = cached_results.value;
|
|
515
520
|
}
|
|
516
521
|
} else {
|
|
522
|
+
// Directly fetch from the database if caching is disabled
|
|
517
523
|
results = await this.database.get(args.id);
|
|
518
524
|
}
|
|
519
525
|
|
|
520
|
-
if (results.type
|
|
521
|
-
|
|
522
|
-
throw new Error(`${this.type} does not exist type`);
|
|
526
|
+
if (results.type !== undefined && results.type !== this.type) {
|
|
527
|
+
throw new Error(`${this.type} does not exist type`);
|
|
523
528
|
}
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
if (results._type != this.type)
|
|
527
|
-
throw new Error(`${this.type} does not exist _type`);
|
|
529
|
+
if (results._type !== undefined && results._type !== this.type) {
|
|
530
|
+
throw new Error(`${this.type} does not exist _type`);
|
|
528
531
|
}
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
+
if (results.deleted === undefined || results.deleted === false) {
|
|
533
|
+
if (
|
|
534
|
+
args.skip_read_serialize !== true &&
|
|
535
|
+
args.skip_serialize !== true
|
|
536
|
+
) {
|
|
532
537
|
results = await this.do_serialize(
|
|
533
538
|
results,
|
|
534
539
|
"read",
|
|
@@ -537,7 +542,7 @@ export default class SpiceModel {
|
|
|
537
542
|
await this.propsToBeRemoved(results)
|
|
538
543
|
);
|
|
539
544
|
}
|
|
540
|
-
if (args.skip_hooks
|
|
545
|
+
if (args.skip_hooks !== true) {
|
|
541
546
|
await this.run_hook(results, "get", "after");
|
|
542
547
|
}
|
|
543
548
|
return results;
|
|
@@ -919,9 +924,9 @@ export default class SpiceModel {
|
|
|
919
924
|
return parts.join(" ");
|
|
920
925
|
}
|
|
921
926
|
|
|
922
|
-
removeSpaceAndSpecialCharacters(str) {
|
|
927
|
+
/* removeSpaceAndSpecialCharacters(str) {
|
|
923
928
|
return str.replace(/[^a-zA-Z0-9]/g, "");
|
|
924
|
-
}
|
|
929
|
+
} */
|
|
925
930
|
|
|
926
931
|
fixColumnName(columns) {
|
|
927
932
|
// Guard clause: if columns is not provided or not a string, return it as-is.
|
|
@@ -1052,10 +1057,7 @@ export default class SpiceModel {
|
|
|
1052
1057
|
await this.run_hook(this, "list", "before");
|
|
1053
1058
|
}
|
|
1054
1059
|
|
|
1055
|
-
const cacheKey = this.
|
|
1056
|
-
`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}`
|
|
1057
|
-
);
|
|
1058
|
-
|
|
1060
|
+
const cacheKey = `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}`;
|
|
1059
1061
|
let results;
|
|
1060
1062
|
if (this.shouldUseCache(this.type)) {
|
|
1061
1063
|
const cachedResults = await this.getCacheProviderObject(this.type).get(
|
|
@@ -1063,17 +1065,21 @@ export default class SpiceModel {
|
|
|
1063
1065
|
);
|
|
1064
1066
|
results = cachedResults?.value;
|
|
1065
1067
|
|
|
1066
|
-
if
|
|
1068
|
+
// Check if there is no cached value
|
|
1069
|
+
const isCacheEmpty = cachedResults?.value === undefined;
|
|
1070
|
+
|
|
1071
|
+
// Check if the cached value should be refreshed (e.g., due to the monitor's timestamp)
|
|
1072
|
+
const shouldRefresh = await this.shouldForceRefresh(cachedResults);
|
|
1073
|
+
|
|
1074
|
+
// Always force a refresh for "workflow" type
|
|
1075
|
+
if (isCacheEmpty || shouldRefresh) {
|
|
1076
|
+
// Force a database read and cache update
|
|
1067
1077
|
results = await this.fetchResults(args, query);
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
results
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
{ value: results, time: new Date().getTime() },
|
|
1074
|
-
this.getCacheConfig(this.type)
|
|
1075
|
-
);
|
|
1076
|
-
}
|
|
1078
|
+
this.getCacheProviderObject(this.type).set(
|
|
1079
|
+
cacheKey,
|
|
1080
|
+
{ value: results, time: new Date().getTime() },
|
|
1081
|
+
this.getCacheConfig(this.type)
|
|
1082
|
+
);
|
|
1077
1083
|
}
|
|
1078
1084
|
} else {
|
|
1079
1085
|
results = await this.fetchResults(args, query);
|