spice-js 2.6.32 → 2.6.34
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/index.js +3 -1
- package/package.json +1 -1
- package/src/index.js +1 -1
- package/src/models/SpiceModel.js +77 -65
package/build/index.js
CHANGED
package/package.json
CHANGED
package/src/index.js
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 {
|
|
@@ -842,9 +842,9 @@ export default class SpiceModel {
|
|
|
842
842
|
}
|
|
843
843
|
|
|
844
844
|
let nestings = [
|
|
845
|
-
...extractNestings(args?.query, this
|
|
846
|
-
...extractNestings(args?.columns, this
|
|
847
|
-
...extractNestings(args?.sort, this
|
|
845
|
+
...extractNestings(args?.query, this?.type),
|
|
846
|
+
...extractNestings(args?.columns, this?.type),
|
|
847
|
+
...extractNestings(args?.sort, this?.type),
|
|
848
848
|
];
|
|
849
849
|
let mappedNestings = _.compact(
|
|
850
850
|
_.map(_.uniq(nestings), (nesting) => {
|
|
@@ -886,9 +886,9 @@ export default class SpiceModel {
|
|
|
886
886
|
if (args.query) {
|
|
887
887
|
query =
|
|
888
888
|
args.query +
|
|
889
|
-
` AND (\`${this
|
|
889
|
+
` AND (\`${this?.type}\`.deleted = false OR \`${this?.type}\`.deleted IS MISSING) `;
|
|
890
890
|
} else {
|
|
891
|
-
query = `(\`${this
|
|
891
|
+
query = `(\`${this?.type}\`.deleted = false OR \`${this?.type}\`.deleted IS MISSING) `;
|
|
892
892
|
}
|
|
893
893
|
}
|
|
894
894
|
}
|
|
@@ -913,7 +913,7 @@ export default class SpiceModel {
|
|
|
913
913
|
}
|
|
914
914
|
|
|
915
915
|
if (!args.sort) {
|
|
916
|
-
args.sort = `\`${this
|
|
916
|
+
args.sort = `\`${this?.type}\`.created_at DESC`;
|
|
917
917
|
} else {
|
|
918
918
|
let sort_array = args.sort.split(",");
|
|
919
919
|
// check the first string in each item in the array to see if it contains a . if not then add the type
|
|
@@ -921,7 +921,7 @@ export default class SpiceModel {
|
|
|
921
921
|
for (let i = 0; i < sort_array.length; i++) {
|
|
922
922
|
if (!sort_array[i].includes(".")) {
|
|
923
923
|
new_sort_array.push(
|
|
924
|
-
`\`${this
|
|
924
|
+
`\`${this?.type}\`.${formatSortComponent(sort_array[i])}`
|
|
925
925
|
);
|
|
926
926
|
} else {
|
|
927
927
|
new_sort_array.push(sort_array[i]);
|
|
@@ -936,15 +936,15 @@ export default class SpiceModel {
|
|
|
936
936
|
return str.replace(/[^a-zA-Z0-9]/g, "");
|
|
937
937
|
}
|
|
938
938
|
let key = removeSpaceAndSpecialCharacters(
|
|
939
|
-
`list::${this
|
|
939
|
+
`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
940
|
);
|
|
941
941
|
|
|
942
942
|
let results;
|
|
943
943
|
if (args.is_custom_query && args.is_custom_query === "true") {
|
|
944
944
|
if (args.ids.length > 0) {
|
|
945
|
-
if (this.shouldUseCache(this
|
|
945
|
+
if (this.shouldUseCache(this?.type)) {
|
|
946
946
|
let cached_results = await this.getCacheProviderObject(
|
|
947
|
-
this
|
|
947
|
+
this?.type
|
|
948
948
|
).get(key);
|
|
949
949
|
results = cached_results?.value;
|
|
950
950
|
if (
|
|
@@ -952,10 +952,10 @@ export default class SpiceModel {
|
|
|
952
952
|
(await this.shouldForceRefresh(cached_results))
|
|
953
953
|
) {
|
|
954
954
|
results = await this.database.query(query);
|
|
955
|
-
this.getCacheProviderObject(this
|
|
955
|
+
this.getCacheProviderObject(this?.type).set(
|
|
956
956
|
key,
|
|
957
957
|
{ value: results, time: new Date().getTime() },
|
|
958
|
-
this.getCacheConfig(this
|
|
958
|
+
this.getCacheConfig(this?.type)
|
|
959
959
|
);
|
|
960
960
|
}
|
|
961
961
|
} else {
|
|
@@ -964,9 +964,9 @@ export default class SpiceModel {
|
|
|
964
964
|
}
|
|
965
965
|
} else {
|
|
966
966
|
if (args.is_full_text && args.is_full_text === "true") {
|
|
967
|
-
if (this.shouldUseCache(this
|
|
967
|
+
if (this.shouldUseCache(this?.type)) {
|
|
968
968
|
let cached_results = await this.getCacheProviderObject(
|
|
969
|
-
this
|
|
969
|
+
this?.type
|
|
970
970
|
).get(key);
|
|
971
971
|
results = cached_results?.value;
|
|
972
972
|
if (
|
|
@@ -974,21 +974,21 @@ export default class SpiceModel {
|
|
|
974
974
|
(await this.shouldForceRefresh(cached_results))
|
|
975
975
|
) {
|
|
976
976
|
results = await this.database.full_text_search(
|
|
977
|
-
this
|
|
977
|
+
this?.type,
|
|
978
978
|
query || "",
|
|
979
979
|
args.limit,
|
|
980
980
|
args.offset,
|
|
981
981
|
args._join
|
|
982
982
|
);
|
|
983
|
-
this.getCacheProviderObject(this
|
|
983
|
+
this.getCacheProviderObject(this?.type).set(
|
|
984
984
|
key,
|
|
985
985
|
{ value: results, time: new Date().getTime() },
|
|
986
|
-
this.getCacheConfig(this
|
|
986
|
+
this.getCacheConfig(this?.type)
|
|
987
987
|
);
|
|
988
988
|
}
|
|
989
989
|
} else {
|
|
990
990
|
results = await this.database.full_text_search(
|
|
991
|
-
this
|
|
991
|
+
this?.type,
|
|
992
992
|
query || "",
|
|
993
993
|
args.limit,
|
|
994
994
|
args.offset,
|
|
@@ -996,16 +996,16 @@ export default class SpiceModel {
|
|
|
996
996
|
);
|
|
997
997
|
}
|
|
998
998
|
} else {
|
|
999
|
-
if (this.shouldUseCache(this
|
|
999
|
+
if (this.shouldUseCache(this?.type)) {
|
|
1000
1000
|
let cached_results = await this.getCacheProviderObject(
|
|
1001
|
-
this
|
|
1001
|
+
this?.type
|
|
1002
1002
|
).get(key);
|
|
1003
1003
|
results = cached_results?.value;
|
|
1004
1004
|
let shouleForceRefresh =
|
|
1005
1005
|
await this.shouldForceRefresh(cached_results);
|
|
1006
1006
|
if (cached_results?.value == undefined || shouleForceRefresh) {
|
|
1007
1007
|
results = await this.database.search(
|
|
1008
|
-
this
|
|
1008
|
+
this?.type,
|
|
1009
1009
|
args.columns || "",
|
|
1010
1010
|
query || "",
|
|
1011
1011
|
args.limit,
|
|
@@ -1015,15 +1015,15 @@ export default class SpiceModel {
|
|
|
1015
1015
|
args.statement_consistent,
|
|
1016
1016
|
args._join
|
|
1017
1017
|
);
|
|
1018
|
-
this.getCacheProviderObject(this
|
|
1018
|
+
this.getCacheProviderObject(this?.type).set(
|
|
1019
1019
|
key,
|
|
1020
1020
|
{ value: results, time: new Date().getTime() },
|
|
1021
|
-
this.getCacheConfig(this
|
|
1021
|
+
this.getCacheConfig(this?.type)
|
|
1022
1022
|
);
|
|
1023
1023
|
}
|
|
1024
1024
|
} else {
|
|
1025
1025
|
results = await this.database.search(
|
|
1026
|
-
this
|
|
1026
|
+
this?.type,
|
|
1027
1027
|
args.columns || "",
|
|
1028
1028
|
query || "",
|
|
1029
1029
|
args.limit,
|
|
@@ -1046,7 +1046,7 @@ export default class SpiceModel {
|
|
|
1046
1046
|
await this.propsToBeRemoved(results.data)
|
|
1047
1047
|
);
|
|
1048
1048
|
}
|
|
1049
|
-
if (this
|
|
1049
|
+
if (this?.type == "resourcedetail");
|
|
1050
1050
|
|
|
1051
1051
|
if (args.skip_hooks != true) {
|
|
1052
1052
|
await this.run_hook(results.data, "list", "after");
|
|
@@ -1075,7 +1075,7 @@ export default class SpiceModel {
|
|
|
1075
1075
|
operation: op,
|
|
1076
1076
|
when,
|
|
1077
1077
|
old_data,
|
|
1078
|
-
resource: this
|
|
1078
|
+
resource: this?.type,
|
|
1079
1079
|
ctx: this[_ctx],
|
|
1080
1080
|
},
|
|
1081
1081
|
});
|
|
@@ -1120,6 +1120,9 @@ export default class SpiceModel {
|
|
|
1120
1120
|
|
|
1121
1121
|
let ids = [];
|
|
1122
1122
|
_.each(data, (result) => {
|
|
1123
|
+
if (!result || result== "undefined") {
|
|
1124
|
+
result = {};
|
|
1125
|
+
}
|
|
1123
1126
|
if (
|
|
1124
1127
|
_.isString(result[source_property]) &&
|
|
1125
1128
|
result[source_property] != ""
|
|
@@ -1148,6 +1151,9 @@ export default class SpiceModel {
|
|
|
1148
1151
|
);
|
|
1149
1152
|
|
|
1150
1153
|
data = _.map(data, (result) => {
|
|
1154
|
+
if (!result || result== "undefined") {
|
|
1155
|
+
result = {};
|
|
1156
|
+
}
|
|
1151
1157
|
let result_found =
|
|
1152
1158
|
_.find(ug, (g) => {
|
|
1153
1159
|
return g.id == result[source_property];
|
|
@@ -1172,6 +1178,9 @@ export default class SpiceModel {
|
|
|
1172
1178
|
let ids = [];
|
|
1173
1179
|
_.each(data, (result) => {
|
|
1174
1180
|
let value = [];
|
|
1181
|
+
if (!result || result== "undefined") {
|
|
1182
|
+
result = {};
|
|
1183
|
+
}
|
|
1175
1184
|
|
|
1176
1185
|
if (_.isArray(result[source_property])) {
|
|
1177
1186
|
value = result[source_property];
|
|
@@ -1210,6 +1219,9 @@ export default class SpiceModel {
|
|
|
1210
1219
|
ids: ids,
|
|
1211
1220
|
}); */
|
|
1212
1221
|
_.each(data, (result) => {
|
|
1222
|
+
if (!result || result== "undefined") {
|
|
1223
|
+
result = {};
|
|
1224
|
+
}
|
|
1213
1225
|
if (_.isString(result[store_property])) {
|
|
1214
1226
|
result[store_property] = [result[store_property]];
|
|
1215
1227
|
}
|
|
@@ -1312,16 +1324,16 @@ export default class SpiceModel {
|
|
|
1312
1324
|
|
|
1313
1325
|
if (this.shouldSerializerRun(args, type)) {
|
|
1314
1326
|
if (
|
|
1315
|
-
this
|
|
1316
|
-
this
|
|
1327
|
+
this?.type != "" &&
|
|
1328
|
+
this?.type != undefined &&
|
|
1317
1329
|
this[_external_modifier_loaded] != true
|
|
1318
1330
|
) {
|
|
1319
|
-
this.addExternalModifiers(this
|
|
1331
|
+
this.addExternalModifiers(this?.type);
|
|
1320
1332
|
this[_external_modifier_loaded] = true;
|
|
1321
1333
|
}
|
|
1322
1334
|
for (let i of this[_serializers][type]["modifiers"]) {
|
|
1323
1335
|
try {
|
|
1324
|
-
data = await i(data, old_data, this[_ctx], this
|
|
1336
|
+
data = await i(data, old_data, this[_ctx], this?.type);
|
|
1325
1337
|
} catch (e) {
|
|
1326
1338
|
console.log(e.stack);
|
|
1327
1339
|
}
|