spice-js 2.6.34 → 2.6.36
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 +53 -7
- package/package.json +1 -1
- package/src/models/SpiceModel.js +124 -81
|
@@ -883,7 +883,7 @@ class SpiceModel {
|
|
|
883
883
|
|
|
884
884
|
return _asyncToGenerator(function* () {
|
|
885
885
|
try {
|
|
886
|
-
var _args4, _args5, _args6;
|
|
886
|
+
var _args4, _args5, _args6, _args7;
|
|
887
887
|
|
|
888
888
|
if (!args) {
|
|
889
889
|
args = {};
|
|
@@ -938,16 +938,56 @@ class SpiceModel {
|
|
|
938
938
|
}
|
|
939
939
|
|
|
940
940
|
function extractNestings(string, localType) {
|
|
941
|
-
var returnVal = [];
|
|
942
|
-
|
|
941
|
+
var returnVal = []; // Regex for nested properties, including backtick-quoted ones
|
|
942
|
+
|
|
943
|
+
var regex = /(`?\w+`?)\.(`?\w+`?)/g;
|
|
943
944
|
var match;
|
|
944
945
|
|
|
945
|
-
while (match = regex.exec(string)) {
|
|
946
|
-
|
|
946
|
+
while ((match = regex.exec(string)) !== null) {
|
|
947
|
+
var first = match[1].replace(/`/g, "");
|
|
948
|
+
var second = match[2].replace(/`/g, "");
|
|
949
|
+
|
|
950
|
+
if (first !== localType) {
|
|
951
|
+
returnVal.push(first);
|
|
952
|
+
}
|
|
953
|
+
} // Regex for ANY/EVERY clauses
|
|
954
|
+
|
|
955
|
+
|
|
956
|
+
var queryRegex = /(ANY|EVERY)\s+\w+\s+IN\s+`?(\w+)`?/g;
|
|
957
|
+
var queryMatch;
|
|
958
|
+
|
|
959
|
+
while ((queryMatch = queryRegex.exec(string)) !== null) {
|
|
960
|
+
returnVal.push(queryMatch[2]);
|
|
947
961
|
}
|
|
948
962
|
|
|
949
|
-
return returnVal;
|
|
963
|
+
return [...new Set(returnVal)]; // Remove duplicates
|
|
950
964
|
}
|
|
965
|
+
/* function extractNestings(string, localType) {
|
|
966
|
+
let returnVal = [];
|
|
967
|
+
let regex = /(\w+)\.(\w+)/g;
|
|
968
|
+
let match;
|
|
969
|
+
while ((match = regex.exec(string)) !== null) {
|
|
970
|
+
if (match[1] !== localType) {
|
|
971
|
+
returnVal.push(match[1]);
|
|
972
|
+
} else {
|
|
973
|
+
returnVal.push(match[2]);
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
return [...new Set(returnVal)]; // Remove duplicates
|
|
977
|
+
} */
|
|
978
|
+
|
|
979
|
+
/* function extractNestings(string, localType) {
|
|
980
|
+
let returnVal = [];
|
|
981
|
+
let regex = /(\w+)\./g;
|
|
982
|
+
let match = regex.exec(string);
|
|
983
|
+
console.log("Local:", localType, match);
|
|
984
|
+
while (match) {
|
|
985
|
+
if (match[1] != localType) returnVal.push(match[1]);
|
|
986
|
+
}
|
|
987
|
+
return returnVal;
|
|
988
|
+
} */
|
|
989
|
+
//console.log("Query", args?.query);
|
|
990
|
+
|
|
951
991
|
|
|
952
992
|
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)];
|
|
953
993
|
|
|
@@ -960,6 +1000,7 @@ class SpiceModel {
|
|
|
960
1000
|
return {
|
|
961
1001
|
alias: nesting,
|
|
962
1002
|
reference: prop.map.reference.toLowerCase(),
|
|
1003
|
+
type: prop.type,
|
|
963
1004
|
value_field: prop.map.value_field
|
|
964
1005
|
};
|
|
965
1006
|
}
|
|
@@ -972,7 +1013,11 @@ class SpiceModel {
|
|
|
972
1013
|
var joinSection = "";
|
|
973
1014
|
|
|
974
1015
|
_.each(nestings, nesting => {
|
|
975
|
-
|
|
1016
|
+
if (nesting.type == _2.DataType.ARRAY || nesting.type == Array || nesting.type == "array") {
|
|
1017
|
+
joinSection += "NEST `" + nesting.reference + "` AS `" + nesting.alias + "` ON KEYS `" + that.type + "`.`" + nesting.alias + "` ";
|
|
1018
|
+
} else {
|
|
1019
|
+
joinSection += "LEFT JOIN `" + nesting.reference + "` AS `" + nesting.alias + "` ON KEYS `" + that.type + "`.`" + nesting.alias + "` ";
|
|
1020
|
+
}
|
|
976
1021
|
});
|
|
977
1022
|
|
|
978
1023
|
return joinSection;
|
|
@@ -980,6 +1025,7 @@ class SpiceModel {
|
|
|
980
1025
|
|
|
981
1026
|
var _join = createJoinSection(mappedNestings);
|
|
982
1027
|
|
|
1028
|
+
console.log("Props", that.type, nestings, _join, (_args7 = args) == null ? void 0 : _args7.query);
|
|
983
1029
|
args._join = _join;
|
|
984
1030
|
|
|
985
1031
|
if (args.is_full_text && args.is_full_text === "true" || args.is_custom_query && args.is_custom_query === "true") {
|
package/package.json
CHANGED
package/src/models/SpiceModel.js
CHANGED
|
@@ -151,7 +151,7 @@ export default class SpiceModel {
|
|
|
151
151
|
for (let i in args.props) {
|
|
152
152
|
if (args.args != undefined) {
|
|
153
153
|
if (args.args[i] != undefined) {
|
|
154
|
-
switch (args.props[i]
|
|
154
|
+
switch (args.props[i].type) {
|
|
155
155
|
case String:
|
|
156
156
|
case "string": {
|
|
157
157
|
this[i] = args.args[i];
|
|
@@ -236,7 +236,7 @@ export default class SpiceModel {
|
|
|
236
236
|
let returned = await new this[_ctx].state.process_fields().process(
|
|
237
237
|
this[_ctx],
|
|
238
238
|
data,
|
|
239
|
-
this
|
|
239
|
+
this.type
|
|
240
240
|
);
|
|
241
241
|
return returned;
|
|
242
242
|
} else {
|
|
@@ -453,7 +453,7 @@ export default class SpiceModel {
|
|
|
453
453
|
|
|
454
454
|
async shouldForceRefresh(response) {
|
|
455
455
|
let obj = this.getCacheProviderObject();
|
|
456
|
-
let monitor_record = await obj.get(`monitor::${this
|
|
456
|
+
let monitor_record = await obj.get(`monitor::${this.type}`);
|
|
457
457
|
if (monitor_record == undefined) {
|
|
458
458
|
return false;
|
|
459
459
|
}
|
|
@@ -466,7 +466,7 @@ export default class SpiceModel {
|
|
|
466
466
|
setMonitor() {
|
|
467
467
|
let current_time = new Date().getTime();
|
|
468
468
|
let obj = this.getCacheProviderObject();
|
|
469
|
-
let key = `monitor::${this
|
|
469
|
+
let key = `monitor::${this.type}`;
|
|
470
470
|
let value = { time: current_time };
|
|
471
471
|
obj.set(key, value, { ttl: 0 });
|
|
472
472
|
}
|
|
@@ -480,10 +480,10 @@ export default class SpiceModel {
|
|
|
480
480
|
if (args.skip_hooks != true) {
|
|
481
481
|
await this.run_hook(args, "get", "before");
|
|
482
482
|
}
|
|
483
|
-
let key = `get::${this
|
|
483
|
+
let key = `get::${this.type}::${args.id}`;
|
|
484
484
|
let results = {};
|
|
485
|
-
if (this.shouldUseCache(this
|
|
486
|
-
let cached_results = await this.getCacheProviderObject(this
|
|
485
|
+
if (this.shouldUseCache(this.type)) {
|
|
486
|
+
let cached_results = await this.getCacheProviderObject(this.type).get(
|
|
487
487
|
key
|
|
488
488
|
);
|
|
489
489
|
|
|
@@ -491,30 +491,30 @@ export default class SpiceModel {
|
|
|
491
491
|
if (
|
|
492
492
|
cached_results?.value == undefined ||
|
|
493
493
|
(await this.shouldForceRefresh(cached_results)) ||
|
|
494
|
-
this
|
|
494
|
+
this.type == "workflow"
|
|
495
495
|
) {
|
|
496
496
|
results = await this.database.get(args.id);
|
|
497
|
-
await this.getCacheProviderObject(this
|
|
497
|
+
await this.getCacheProviderObject(this.type).set(
|
|
498
498
|
key,
|
|
499
499
|
{ value: results, time: new Date().getTime() },
|
|
500
|
-
this.getCacheConfig(this
|
|
500
|
+
this.getCacheConfig(this.type)
|
|
501
501
|
);
|
|
502
502
|
}
|
|
503
503
|
} else {
|
|
504
504
|
results = await this.database.get(args.id);
|
|
505
505
|
}
|
|
506
506
|
|
|
507
|
-
if (results
|
|
508
|
-
if (results.type != this
|
|
509
|
-
throw new Error(`${this
|
|
507
|
+
if (results.type != undefined) {
|
|
508
|
+
if (results.type != this.type)
|
|
509
|
+
throw new Error(`${this.type} does not exist type`);
|
|
510
510
|
}
|
|
511
511
|
|
|
512
|
-
if (results
|
|
513
|
-
if (results._type != this
|
|
514
|
-
throw new Error(`${this
|
|
512
|
+
if (results._type != undefined) {
|
|
513
|
+
if (results._type != this.type)
|
|
514
|
+
throw new Error(`${this.type} does not exist _type`);
|
|
515
515
|
}
|
|
516
516
|
|
|
517
|
-
if (results
|
|
517
|
+
if (results.deleted == undefined || results.deleted == false) {
|
|
518
518
|
if (args.skip_read_serialize != true && args.skip_serialize != true) {
|
|
519
519
|
results = await this.do_serialize(
|
|
520
520
|
results,
|
|
@@ -529,7 +529,7 @@ export default class SpiceModel {
|
|
|
529
529
|
}
|
|
530
530
|
return results;
|
|
531
531
|
} else {
|
|
532
|
-
throw new Error(`${this
|
|
532
|
+
throw new Error(`${this.type} does not exist`);
|
|
533
533
|
}
|
|
534
534
|
}
|
|
535
535
|
} catch (e) {
|
|
@@ -556,11 +556,11 @@ export default class SpiceModel {
|
|
|
556
556
|
await this.run_hook(this, "list", "before");
|
|
557
557
|
}
|
|
558
558
|
_.remove(args.ids, (o) => o == undefined);
|
|
559
|
-
let key = `multi-get::${this
|
|
559
|
+
let key = `multi-get::${this.type}::${_.join(args.ids, "|")}`;
|
|
560
560
|
let results = [];
|
|
561
561
|
if (args.ids.length > 0) {
|
|
562
|
-
if (this.shouldUseCache(this
|
|
563
|
-
let cached_results = await this.getCacheProviderObject(this
|
|
562
|
+
if (this.shouldUseCache(this.type)) {
|
|
563
|
+
let cached_results = await this.getCacheProviderObject(this.type).get(
|
|
564
564
|
key
|
|
565
565
|
);
|
|
566
566
|
results = cached_results?.value;
|
|
@@ -569,17 +569,17 @@ export default class SpiceModel {
|
|
|
569
569
|
(await this.shouldForceRefresh(cached_results))
|
|
570
570
|
) {
|
|
571
571
|
results = await this.database.multi_get(args.ids, true);
|
|
572
|
-
this.getCacheProviderObject(this
|
|
572
|
+
this.getCacheProviderObject(this.type).set(
|
|
573
573
|
key,
|
|
574
574
|
{ value: results, time: new Date().getTime() },
|
|
575
|
-
this.getCacheConfig(this
|
|
575
|
+
this.getCacheConfig(this.type)
|
|
576
576
|
);
|
|
577
577
|
}
|
|
578
578
|
} else {
|
|
579
579
|
results = await this.database.multi_get(args.ids, true);
|
|
580
580
|
}
|
|
581
581
|
}
|
|
582
|
-
_.remove(results, (o) => o
|
|
582
|
+
_.remove(results, (o) => o.type != this.type);
|
|
583
583
|
if (args.skip_read_serialize != true && args.skip_serialize != true) {
|
|
584
584
|
results = await this.do_serialize(
|
|
585
585
|
results,
|
|
@@ -605,22 +605,22 @@ export default class SpiceModel {
|
|
|
605
605
|
try {
|
|
606
606
|
if (_.isString(data)) {
|
|
607
607
|
let result = await this.database.get(data);
|
|
608
|
-
if (result
|
|
609
|
-
if (result.type != this
|
|
608
|
+
if (result.type)
|
|
609
|
+
if (result.type != this.type) {
|
|
610
610
|
return false;
|
|
611
611
|
}
|
|
612
|
-
if (result
|
|
613
|
-
if (result._type != this
|
|
612
|
+
if (result._type)
|
|
613
|
+
if (result._type != this.type) {
|
|
614
614
|
return false;
|
|
615
615
|
}
|
|
616
616
|
} else {
|
|
617
|
-
if (data
|
|
618
|
-
if (data.type != this
|
|
617
|
+
if (data.type)
|
|
618
|
+
if (data.type != this.type) {
|
|
619
619
|
return false;
|
|
620
620
|
}
|
|
621
621
|
|
|
622
|
-
if (data
|
|
623
|
-
if (data._type != this
|
|
622
|
+
if (data._type)
|
|
623
|
+
if (data._type != this.type) {
|
|
624
624
|
return false;
|
|
625
625
|
}
|
|
626
626
|
}
|
|
@@ -636,7 +636,7 @@ export default class SpiceModel {
|
|
|
636
636
|
let results = await this.database.get(args.id);
|
|
637
637
|
let item_exist = await this.exist(results);
|
|
638
638
|
if (!item_exist) {
|
|
639
|
-
throw new Error(`${this
|
|
639
|
+
throw new Error(`${this.type} does not exist. in update`);
|
|
640
640
|
}
|
|
641
641
|
delete results["id"];
|
|
642
642
|
_.defaults(this, results);
|
|
@@ -697,7 +697,7 @@ export default class SpiceModel {
|
|
|
697
697
|
try {
|
|
698
698
|
let form;
|
|
699
699
|
this.created_at = new SDate().now();
|
|
700
|
-
args = _.defaults(args, { id_prefix: this
|
|
700
|
+
args = _.defaults(args, { id_prefix: this.type });
|
|
701
701
|
if (args.body) {
|
|
702
702
|
form = _.defaults({}, args.body);
|
|
703
703
|
form.created_at = this.created_at;
|
|
@@ -753,7 +753,7 @@ export default class SpiceModel {
|
|
|
753
753
|
let item_exist = await this.exist(args.id);
|
|
754
754
|
|
|
755
755
|
if (!item_exist) {
|
|
756
|
-
throw new Error(`${this
|
|
756
|
+
throw new Error(`${this.type} does not exist.`);
|
|
757
757
|
}
|
|
758
758
|
let results = await this.database.get(args.id);
|
|
759
759
|
try {
|
|
@@ -831,20 +831,64 @@ export default class SpiceModel {
|
|
|
831
831
|
}
|
|
832
832
|
return data;
|
|
833
833
|
}
|
|
834
|
+
|
|
834
835
|
function extractNestings(string, localType) {
|
|
835
836
|
let returnVal = [];
|
|
836
|
-
|
|
837
|
+
|
|
838
|
+
// Regex for nested properties, including backtick-quoted ones
|
|
839
|
+
let regex = /(`?\w+`?)\.(`?\w+`?)/g;
|
|
840
|
+
let match;
|
|
841
|
+
|
|
842
|
+
while ((match = regex.exec(string)) !== null) {
|
|
843
|
+
let first = match[1].replace(/`/g, "");
|
|
844
|
+
let second = match[2].replace(/`/g, "");
|
|
845
|
+
if (first !== localType) {
|
|
846
|
+
returnVal.push(first);
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
// Regex for ANY/EVERY clauses
|
|
850
|
+
let queryRegex = /(ANY|EVERY)\s+\w+\s+IN\s+`?(\w+)`?/g;
|
|
851
|
+
let queryMatch;
|
|
852
|
+
|
|
853
|
+
while ((queryMatch = queryRegex.exec(string)) !== null) {
|
|
854
|
+
returnVal.push(queryMatch[2]);
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
return [...new Set(returnVal)]; // Remove duplicates
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
/* function extractNestings(string, localType) {
|
|
861
|
+
let returnVal = [];
|
|
862
|
+
let regex = /(\w+)\.(\w+)/g;
|
|
837
863
|
let match;
|
|
838
|
-
|
|
864
|
+
|
|
865
|
+
while ((match = regex.exec(string)) !== null) {
|
|
866
|
+
if (match[1] !== localType) {
|
|
867
|
+
returnVal.push(match[1]);
|
|
868
|
+
} else {
|
|
869
|
+
returnVal.push(match[2]);
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
return [...new Set(returnVal)]; // Remove duplicates
|
|
874
|
+
} */
|
|
875
|
+
/* function extractNestings(string, localType) {
|
|
876
|
+
let returnVal = [];
|
|
877
|
+
let regex = /(\w+)\./g;
|
|
878
|
+
let match = regex.exec(string);
|
|
879
|
+
console.log("Local:", localType, match);
|
|
880
|
+
while (match) {
|
|
839
881
|
if (match[1] != localType) returnVal.push(match[1]);
|
|
840
882
|
}
|
|
841
883
|
return returnVal;
|
|
842
|
-
}
|
|
884
|
+
} */
|
|
885
|
+
|
|
886
|
+
//console.log("Query", args?.query);
|
|
843
887
|
|
|
844
888
|
let nestings = [
|
|
845
|
-
...extractNestings(args?.query, this
|
|
846
|
-
...extractNestings(args?.columns, this
|
|
847
|
-
...extractNestings(args?.sort, this
|
|
889
|
+
...extractNestings(args?.query, this.type),
|
|
890
|
+
...extractNestings(args?.columns, this.type),
|
|
891
|
+
...extractNestings(args?.sort, this.type),
|
|
848
892
|
];
|
|
849
893
|
let mappedNestings = _.compact(
|
|
850
894
|
_.map(_.uniq(nestings), (nesting) => {
|
|
@@ -855,6 +899,7 @@ export default class SpiceModel {
|
|
|
855
899
|
return {
|
|
856
900
|
alias: nesting,
|
|
857
901
|
reference: prop.map.reference.toLowerCase(),
|
|
902
|
+
type: prop.type,
|
|
858
903
|
value_field: prop.map.value_field,
|
|
859
904
|
};
|
|
860
905
|
}
|
|
@@ -867,11 +912,21 @@ export default class SpiceModel {
|
|
|
867
912
|
//create join section with nestings
|
|
868
913
|
let joinSection = "";
|
|
869
914
|
_.each(nestings, (nesting) => {
|
|
870
|
-
|
|
915
|
+
if (
|
|
916
|
+
nesting.type == DataType.ARRAY ||
|
|
917
|
+
nesting.type == Array ||
|
|
918
|
+
nesting.type == "array"
|
|
919
|
+
) {
|
|
920
|
+
joinSection += `NEST \`${nesting.reference}\` AS \`${nesting.alias}\` ON KEYS \`${that.type}\`.\`${nesting.alias}\` `;
|
|
921
|
+
} else {
|
|
922
|
+
joinSection += `LEFT JOIN \`${nesting.reference}\` AS \`${nesting.alias}\` ON KEYS \`${that.type}\`.\`${nesting.alias}\` `;
|
|
923
|
+
}
|
|
871
924
|
});
|
|
872
925
|
return joinSection;
|
|
873
926
|
}
|
|
874
927
|
let _join = createJoinSection(mappedNestings);
|
|
928
|
+
console.log("Props", that.type, nestings, _join, args?.query);
|
|
929
|
+
|
|
875
930
|
args._join = _join;
|
|
876
931
|
|
|
877
932
|
if (
|
|
@@ -886,9 +941,9 @@ export default class SpiceModel {
|
|
|
886
941
|
if (args.query) {
|
|
887
942
|
query =
|
|
888
943
|
args.query +
|
|
889
|
-
` AND (\`${this
|
|
944
|
+
` AND (\`${this.type}\`.deleted = false OR \`${this.type}\`.deleted IS MISSING) `;
|
|
890
945
|
} else {
|
|
891
|
-
query = `(\`${this
|
|
946
|
+
query = `(\`${this.type}\`.deleted = false OR \`${this.type}\`.deleted IS MISSING) `;
|
|
892
947
|
}
|
|
893
948
|
}
|
|
894
949
|
}
|
|
@@ -913,7 +968,7 @@ export default class SpiceModel {
|
|
|
913
968
|
}
|
|
914
969
|
|
|
915
970
|
if (!args.sort) {
|
|
916
|
-
args.sort = `\`${this
|
|
971
|
+
args.sort = `\`${this.type}\`.created_at DESC`;
|
|
917
972
|
} else {
|
|
918
973
|
let sort_array = args.sort.split(",");
|
|
919
974
|
// check the first string in each item in the array to see if it contains a . if not then add the type
|
|
@@ -921,7 +976,7 @@ export default class SpiceModel {
|
|
|
921
976
|
for (let i = 0; i < sort_array.length; i++) {
|
|
922
977
|
if (!sort_array[i].includes(".")) {
|
|
923
978
|
new_sort_array.push(
|
|
924
|
-
`\`${this
|
|
979
|
+
`\`${this.type}\`.${formatSortComponent(sort_array[i])}`
|
|
925
980
|
);
|
|
926
981
|
} else {
|
|
927
982
|
new_sort_array.push(sort_array[i]);
|
|
@@ -936,15 +991,15 @@ export default class SpiceModel {
|
|
|
936
991
|
return str.replace(/[^a-zA-Z0-9]/g, "");
|
|
937
992
|
}
|
|
938
993
|
let key = removeSpaceAndSpecialCharacters(
|
|
939
|
-
`list::${this
|
|
994
|
+
`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
995
|
);
|
|
941
996
|
|
|
942
997
|
let results;
|
|
943
998
|
if (args.is_custom_query && args.is_custom_query === "true") {
|
|
944
999
|
if (args.ids.length > 0) {
|
|
945
|
-
if (this.shouldUseCache(this
|
|
1000
|
+
if (this.shouldUseCache(this.type)) {
|
|
946
1001
|
let cached_results = await this.getCacheProviderObject(
|
|
947
|
-
this
|
|
1002
|
+
this.type
|
|
948
1003
|
).get(key);
|
|
949
1004
|
results = cached_results?.value;
|
|
950
1005
|
if (
|
|
@@ -952,10 +1007,10 @@ export default class SpiceModel {
|
|
|
952
1007
|
(await this.shouldForceRefresh(cached_results))
|
|
953
1008
|
) {
|
|
954
1009
|
results = await this.database.query(query);
|
|
955
|
-
this.getCacheProviderObject(this
|
|
1010
|
+
this.getCacheProviderObject(this.type).set(
|
|
956
1011
|
key,
|
|
957
1012
|
{ value: results, time: new Date().getTime() },
|
|
958
|
-
this.getCacheConfig(this
|
|
1013
|
+
this.getCacheConfig(this.type)
|
|
959
1014
|
);
|
|
960
1015
|
}
|
|
961
1016
|
} else {
|
|
@@ -964,9 +1019,9 @@ export default class SpiceModel {
|
|
|
964
1019
|
}
|
|
965
1020
|
} else {
|
|
966
1021
|
if (args.is_full_text && args.is_full_text === "true") {
|
|
967
|
-
if (this.shouldUseCache(this
|
|
1022
|
+
if (this.shouldUseCache(this.type)) {
|
|
968
1023
|
let cached_results = await this.getCacheProviderObject(
|
|
969
|
-
this
|
|
1024
|
+
this.type
|
|
970
1025
|
).get(key);
|
|
971
1026
|
results = cached_results?.value;
|
|
972
1027
|
if (
|
|
@@ -974,21 +1029,21 @@ export default class SpiceModel {
|
|
|
974
1029
|
(await this.shouldForceRefresh(cached_results))
|
|
975
1030
|
) {
|
|
976
1031
|
results = await this.database.full_text_search(
|
|
977
|
-
this
|
|
1032
|
+
this.type,
|
|
978
1033
|
query || "",
|
|
979
1034
|
args.limit,
|
|
980
1035
|
args.offset,
|
|
981
1036
|
args._join
|
|
982
1037
|
);
|
|
983
|
-
this.getCacheProviderObject(this
|
|
1038
|
+
this.getCacheProviderObject(this.type).set(
|
|
984
1039
|
key,
|
|
985
1040
|
{ value: results, time: new Date().getTime() },
|
|
986
|
-
this.getCacheConfig(this
|
|
1041
|
+
this.getCacheConfig(this.type)
|
|
987
1042
|
);
|
|
988
1043
|
}
|
|
989
1044
|
} else {
|
|
990
1045
|
results = await this.database.full_text_search(
|
|
991
|
-
this
|
|
1046
|
+
this.type,
|
|
992
1047
|
query || "",
|
|
993
1048
|
args.limit,
|
|
994
1049
|
args.offset,
|
|
@@ -996,16 +1051,16 @@ export default class SpiceModel {
|
|
|
996
1051
|
);
|
|
997
1052
|
}
|
|
998
1053
|
} else {
|
|
999
|
-
if (this.shouldUseCache(this
|
|
1054
|
+
if (this.shouldUseCache(this.type)) {
|
|
1000
1055
|
let cached_results = await this.getCacheProviderObject(
|
|
1001
|
-
this
|
|
1056
|
+
this.type
|
|
1002
1057
|
).get(key);
|
|
1003
1058
|
results = cached_results?.value;
|
|
1004
1059
|
let shouleForceRefresh =
|
|
1005
1060
|
await this.shouldForceRefresh(cached_results);
|
|
1006
1061
|
if (cached_results?.value == undefined || shouleForceRefresh) {
|
|
1007
1062
|
results = await this.database.search(
|
|
1008
|
-
this
|
|
1063
|
+
this.type,
|
|
1009
1064
|
args.columns || "",
|
|
1010
1065
|
query || "",
|
|
1011
1066
|
args.limit,
|
|
@@ -1015,15 +1070,15 @@ export default class SpiceModel {
|
|
|
1015
1070
|
args.statement_consistent,
|
|
1016
1071
|
args._join
|
|
1017
1072
|
);
|
|
1018
|
-
this.getCacheProviderObject(this
|
|
1073
|
+
this.getCacheProviderObject(this.type).set(
|
|
1019
1074
|
key,
|
|
1020
1075
|
{ value: results, time: new Date().getTime() },
|
|
1021
|
-
this.getCacheConfig(this
|
|
1076
|
+
this.getCacheConfig(this.type)
|
|
1022
1077
|
);
|
|
1023
1078
|
}
|
|
1024
1079
|
} else {
|
|
1025
1080
|
results = await this.database.search(
|
|
1026
|
-
this
|
|
1081
|
+
this.type,
|
|
1027
1082
|
args.columns || "",
|
|
1028
1083
|
query || "",
|
|
1029
1084
|
args.limit,
|
|
@@ -1046,7 +1101,7 @@ export default class SpiceModel {
|
|
|
1046
1101
|
await this.propsToBeRemoved(results.data)
|
|
1047
1102
|
);
|
|
1048
1103
|
}
|
|
1049
|
-
if (this
|
|
1104
|
+
if (this.type == "resourcedetail");
|
|
1050
1105
|
|
|
1051
1106
|
if (args.skip_hooks != true) {
|
|
1052
1107
|
await this.run_hook(results.data, "list", "after");
|
|
@@ -1075,7 +1130,7 @@ export default class SpiceModel {
|
|
|
1075
1130
|
operation: op,
|
|
1076
1131
|
when,
|
|
1077
1132
|
old_data,
|
|
1078
|
-
resource: this
|
|
1133
|
+
resource: this.type,
|
|
1079
1134
|
ctx: this[_ctx],
|
|
1080
1135
|
},
|
|
1081
1136
|
});
|
|
@@ -1120,9 +1175,6 @@ export default class SpiceModel {
|
|
|
1120
1175
|
|
|
1121
1176
|
let ids = [];
|
|
1122
1177
|
_.each(data, (result) => {
|
|
1123
|
-
if (!result || result== "undefined") {
|
|
1124
|
-
result = {};
|
|
1125
|
-
}
|
|
1126
1178
|
if (
|
|
1127
1179
|
_.isString(result[source_property]) &&
|
|
1128
1180
|
result[source_property] != ""
|
|
@@ -1151,9 +1203,6 @@ export default class SpiceModel {
|
|
|
1151
1203
|
);
|
|
1152
1204
|
|
|
1153
1205
|
data = _.map(data, (result) => {
|
|
1154
|
-
if (!result || result== "undefined") {
|
|
1155
|
-
result = {};
|
|
1156
|
-
}
|
|
1157
1206
|
let result_found =
|
|
1158
1207
|
_.find(ug, (g) => {
|
|
1159
1208
|
return g.id == result[source_property];
|
|
@@ -1178,9 +1227,6 @@ export default class SpiceModel {
|
|
|
1178
1227
|
let ids = [];
|
|
1179
1228
|
_.each(data, (result) => {
|
|
1180
1229
|
let value = [];
|
|
1181
|
-
if (!result || result== "undefined") {
|
|
1182
|
-
result = {};
|
|
1183
|
-
}
|
|
1184
1230
|
|
|
1185
1231
|
if (_.isArray(result[source_property])) {
|
|
1186
1232
|
value = result[source_property];
|
|
@@ -1219,9 +1265,6 @@ export default class SpiceModel {
|
|
|
1219
1265
|
ids: ids,
|
|
1220
1266
|
}); */
|
|
1221
1267
|
_.each(data, (result) => {
|
|
1222
|
-
if (!result || result== "undefined") {
|
|
1223
|
-
result = {};
|
|
1224
|
-
}
|
|
1225
1268
|
if (_.isString(result[store_property])) {
|
|
1226
1269
|
result[store_property] = [result[store_property]];
|
|
1227
1270
|
}
|
|
@@ -1324,16 +1367,16 @@ export default class SpiceModel {
|
|
|
1324
1367
|
|
|
1325
1368
|
if (this.shouldSerializerRun(args, type)) {
|
|
1326
1369
|
if (
|
|
1327
|
-
this
|
|
1328
|
-
this
|
|
1370
|
+
this.type != "" &&
|
|
1371
|
+
this.type != undefined &&
|
|
1329
1372
|
this[_external_modifier_loaded] != true
|
|
1330
1373
|
) {
|
|
1331
|
-
this.addExternalModifiers(this
|
|
1374
|
+
this.addExternalModifiers(this.type);
|
|
1332
1375
|
this[_external_modifier_loaded] = true;
|
|
1333
1376
|
}
|
|
1334
1377
|
for (let i of this[_serializers][type]["modifiers"]) {
|
|
1335
1378
|
try {
|
|
1336
|
-
data = await i(data, old_data, this[_ctx], this
|
|
1379
|
+
data = await i(data, old_data, this[_ctx], this.type);
|
|
1337
1380
|
} catch (e) {
|
|
1338
1381
|
console.log(e.stack);
|
|
1339
1382
|
}
|