spice-js 2.6.4 → 2.6.6
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/bootstrap/cache.js +2 -2
- package/build/models/SpiceModel.js +152 -139
- package/package.json +1 -2
- package/src/bootstrap/cache.js +1 -1
- package/src/models/SpiceModel.js +16 -10
package/build/bootstrap/cache.js
CHANGED
|
@@ -12,11 +12,11 @@ function _connect() {
|
|
|
12
12
|
_connect = _asyncToGenerator(function* () {
|
|
13
13
|
try {
|
|
14
14
|
spice.cache_providers = {};
|
|
15
|
-
spice.monitor =
|
|
15
|
+
spice.monitor = new Map();
|
|
16
16
|
|
|
17
17
|
for (var key of Object.keys(spice.config.cache.providers)) {
|
|
18
18
|
spice.cache_providers[key] = new spice.config.cache.providers[key](spice.config.cache.drivers[key] || {});
|
|
19
|
-
|
|
19
|
+
spice.cache_providers[key].initialize();
|
|
20
20
|
}
|
|
21
21
|
} catch (e) {
|
|
22
22
|
console.log(e.stack);
|
|
@@ -433,7 +433,9 @@ class SpiceModel {
|
|
|
433
433
|
}
|
|
434
434
|
|
|
435
435
|
shouldCache(resource_type) {
|
|
436
|
-
|
|
436
|
+
var _spice$systemconfig, _spice$systemconfig$c;
|
|
437
|
+
|
|
438
|
+
return spice.cache[resource_type] != undefined || ((_spice$systemconfig = spice.systemconfig) == null ? void 0 : (_spice$systemconfig$c = _spice$systemconfig.cache) == null ? void 0 : _spice$systemconfig$c.status) == "disable";
|
|
437
439
|
}
|
|
438
440
|
|
|
439
441
|
getCacheConfig(resource_type) {
|
|
@@ -441,7 +443,7 @@ class SpiceModel {
|
|
|
441
443
|
}
|
|
442
444
|
|
|
443
445
|
getCacheProviderObject(resource_type) {
|
|
444
|
-
return spice.cache_providers[this.getCacheConfig(resource_type).driver || spice.config.cache.default_driver];
|
|
446
|
+
return spice.cache_providers[this.getCacheConfig(resource_type).driver || this.getCacheConfig(resource_type).provider || spice.config.cache.default_driver];
|
|
445
447
|
}
|
|
446
448
|
|
|
447
449
|
exists(item_type, key) {
|
|
@@ -456,26 +458,37 @@ class SpiceModel {
|
|
|
456
458
|
}
|
|
457
459
|
|
|
458
460
|
shouldForceRefresh(response) {
|
|
459
|
-
var
|
|
461
|
+
var _this3 = this;
|
|
460
462
|
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
}
|
|
463
|
+
return _asyncToGenerator(function* () {
|
|
464
|
+
var obj = _this3.getCacheProviderObject();
|
|
464
465
|
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
466
|
+
var monitor_record = yield obj.get("monitor::" + _this3.type);
|
|
467
|
+
|
|
468
|
+
if (monitor_record == undefined) {
|
|
469
|
+
return false;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
if (monitor_record.time > (response == null ? void 0 : response.time)) {
|
|
473
|
+
return true;
|
|
474
|
+
}
|
|
468
475
|
|
|
469
|
-
|
|
476
|
+
return false;
|
|
477
|
+
})();
|
|
470
478
|
}
|
|
471
479
|
|
|
472
480
|
setMonitor() {
|
|
473
481
|
var current_time = new Date().getTime();
|
|
474
|
-
|
|
482
|
+
var obj = this.getCacheProviderObject();
|
|
483
|
+
obj.set("monitor::" + this.type, {
|
|
484
|
+
time: current_time
|
|
485
|
+
}, {
|
|
486
|
+
ttl: 0
|
|
487
|
+
}); //console.log("Monitor Set", spice.monitor);
|
|
475
488
|
}
|
|
476
489
|
|
|
477
490
|
get(args) {
|
|
478
|
-
var
|
|
491
|
+
var _this4 = this;
|
|
479
492
|
|
|
480
493
|
return _asyncToGenerator(function* () {
|
|
481
494
|
try {
|
|
@@ -484,39 +497,39 @@ class SpiceModel {
|
|
|
484
497
|
}
|
|
485
498
|
|
|
486
499
|
if (_.isString(args.id)) {
|
|
487
|
-
yield
|
|
488
|
-
var key =
|
|
500
|
+
yield _this4.run_hook(args, "get", "before");
|
|
501
|
+
var key = _this4.type + "::" + args.id;
|
|
489
502
|
var results = {};
|
|
490
503
|
|
|
491
|
-
if (
|
|
492
|
-
var cached_results = yield
|
|
504
|
+
if (_this4.shouldCache(_this4.type)) {
|
|
505
|
+
var cached_results = yield _this4.getCacheProviderObject(_this4.type).get(key);
|
|
493
506
|
results = cached_results == null ? void 0 : cached_results.value;
|
|
494
507
|
|
|
495
|
-
if ((cached_results == null ? void 0 : cached_results.value) == undefined ||
|
|
496
|
-
results = yield
|
|
497
|
-
yield
|
|
508
|
+
if ((cached_results == null ? void 0 : cached_results.value) == undefined || (yield _this4.shouldForceRefresh(cached_results))) {
|
|
509
|
+
results = yield _this4.database.get(args.id);
|
|
510
|
+
yield _this4.getCacheProviderObject(_this4.type).set(key, {
|
|
498
511
|
value: results,
|
|
499
512
|
time: new Date().getTime()
|
|
500
|
-
},
|
|
513
|
+
}, _this4.getCacheConfig(_this4.type));
|
|
501
514
|
}
|
|
502
515
|
} else {
|
|
503
|
-
results = yield
|
|
516
|
+
results = yield _this4.database.get(args.id);
|
|
504
517
|
}
|
|
505
518
|
|
|
506
519
|
if (results.type != undefined) {
|
|
507
|
-
if (results.type !=
|
|
520
|
+
if (results.type != _this4.type) throw new Error(_this4.type + " does not exist type");
|
|
508
521
|
}
|
|
509
522
|
|
|
510
523
|
if (results._type != undefined) {
|
|
511
|
-
if (results._type !=
|
|
524
|
+
if (results._type != _this4.type) throw new Error(_this4.type + " does not exist _type");
|
|
512
525
|
}
|
|
513
526
|
|
|
514
527
|
if (results.deleted == undefined || results.deleted == false) {
|
|
515
|
-
yield
|
|
516
|
-
results = yield
|
|
528
|
+
yield _this4.run_hook(results, "get", "after");
|
|
529
|
+
results = yield _this4.do_serialize(results, "read", {}, args, (yield _this4.propsToBeRemoved(results)));
|
|
517
530
|
return results;
|
|
518
531
|
} else {
|
|
519
|
-
throw new Error(
|
|
532
|
+
throw new Error(_this4.type + " does not exist");
|
|
520
533
|
}
|
|
521
534
|
}
|
|
522
535
|
} catch (e) {
|
|
@@ -526,11 +539,11 @@ class SpiceModel {
|
|
|
526
539
|
}
|
|
527
540
|
|
|
528
541
|
query(query, scope) {
|
|
529
|
-
var
|
|
542
|
+
var _this5 = this;
|
|
530
543
|
|
|
531
544
|
return _asyncToGenerator(function* () {
|
|
532
545
|
try {
|
|
533
|
-
var results = yield
|
|
546
|
+
var results = yield _this5.database.query(query, scope);
|
|
534
547
|
return results;
|
|
535
548
|
} catch (error) {
|
|
536
549
|
throw error;
|
|
@@ -539,7 +552,7 @@ class SpiceModel {
|
|
|
539
552
|
}
|
|
540
553
|
|
|
541
554
|
getMulti(args) {
|
|
542
|
-
var
|
|
555
|
+
var _this6 = this;
|
|
543
556
|
|
|
544
557
|
return _asyncToGenerator(function* () {
|
|
545
558
|
try {
|
|
@@ -547,36 +560,36 @@ class SpiceModel {
|
|
|
547
560
|
args = {};
|
|
548
561
|
}
|
|
549
562
|
|
|
550
|
-
yield
|
|
563
|
+
yield _this6.run_hook(_this6, "list", "before");
|
|
551
564
|
|
|
552
565
|
_.remove(args.ids, o => o == undefined);
|
|
553
566
|
|
|
554
|
-
var key =
|
|
567
|
+
var key = _this6.type + "::" + _.join(args.ids, "|");
|
|
555
568
|
|
|
556
569
|
var results = [];
|
|
557
570
|
|
|
558
571
|
if (args.ids.length > 0) {
|
|
559
|
-
if (
|
|
560
|
-
var cached_results = yield
|
|
572
|
+
if (_this6.shouldCache(_this6.type)) {
|
|
573
|
+
var cached_results = yield _this6.getCacheProviderObject(_this6.type).get(key);
|
|
561
574
|
results = cached_results == null ? void 0 : cached_results.value;
|
|
562
575
|
|
|
563
|
-
if ((cached_results == null ? void 0 : cached_results.value) == undefined ||
|
|
564
|
-
results = yield
|
|
576
|
+
if ((cached_results == null ? void 0 : cached_results.value) == undefined || (yield _this6.shouldForceRefresh(cached_results))) {
|
|
577
|
+
results = yield _this6.database.multi_get(args.ids, true);
|
|
565
578
|
|
|
566
|
-
|
|
579
|
+
_this6.getCacheProviderObject(_this6.type).set(key, {
|
|
567
580
|
value: results,
|
|
568
581
|
time: new Date().getTime()
|
|
569
|
-
},
|
|
582
|
+
}, _this6.getCacheConfig(_this6.type));
|
|
570
583
|
}
|
|
571
584
|
} else {
|
|
572
|
-
results = yield
|
|
585
|
+
results = yield _this6.database.multi_get(args.ids, true);
|
|
573
586
|
}
|
|
574
587
|
}
|
|
575
588
|
|
|
576
|
-
_.remove(results, o => o.type !=
|
|
589
|
+
_.remove(results, o => o.type != _this6.type);
|
|
577
590
|
|
|
578
|
-
yield
|
|
579
|
-
results = yield
|
|
591
|
+
yield _this6.run_hook(results, "list", "after", args.context);
|
|
592
|
+
results = yield _this6.do_serialize(results, "read", {}, args, (yield _this6.propsToBeRemoved(results)));
|
|
580
593
|
return results;
|
|
581
594
|
} catch (e) {
|
|
582
595
|
console.log(e.stack);
|
|
@@ -586,23 +599,23 @@ class SpiceModel {
|
|
|
586
599
|
}
|
|
587
600
|
|
|
588
601
|
exist(data) {
|
|
589
|
-
var
|
|
602
|
+
var _this7 = this;
|
|
590
603
|
|
|
591
604
|
return _asyncToGenerator(function* () {
|
|
592
605
|
try {
|
|
593
606
|
if (_.isString(data)) {
|
|
594
|
-
var result = yield
|
|
595
|
-
if (result.type) if (result.type !=
|
|
607
|
+
var result = yield _this7.database.get(data);
|
|
608
|
+
if (result.type) if (result.type != _this7.type) {
|
|
596
609
|
return false;
|
|
597
610
|
}
|
|
598
|
-
if (result._type) if (result._type !=
|
|
611
|
+
if (result._type) if (result._type != _this7.type) {
|
|
599
612
|
return false;
|
|
600
613
|
}
|
|
601
614
|
} else {
|
|
602
|
-
if (data.type) if (data.type !=
|
|
615
|
+
if (data.type) if (data.type != _this7.type) {
|
|
603
616
|
return false;
|
|
604
617
|
}
|
|
605
|
-
if (data._type) if (data._type !=
|
|
618
|
+
if (data._type) if (data._type != _this7.type) {
|
|
606
619
|
return false;
|
|
607
620
|
}
|
|
608
621
|
}
|
|
@@ -615,54 +628,54 @@ class SpiceModel {
|
|
|
615
628
|
}
|
|
616
629
|
|
|
617
630
|
update(args) {
|
|
618
|
-
var
|
|
631
|
+
var _this8 = this;
|
|
619
632
|
|
|
620
633
|
return _asyncToGenerator(function* () {
|
|
621
634
|
try {
|
|
622
|
-
|
|
623
|
-
var results = yield
|
|
624
|
-
var item_exist = yield
|
|
635
|
+
_this8.updated_at = new SDate().now();
|
|
636
|
+
var results = yield _this8.database.get(args.id);
|
|
637
|
+
var item_exist = yield _this8.exist(results);
|
|
625
638
|
|
|
626
639
|
if (!item_exist) {
|
|
627
|
-
throw new Error(
|
|
640
|
+
throw new Error(_this8.type + " does not exist. in update");
|
|
628
641
|
}
|
|
629
642
|
|
|
630
643
|
delete results["id"];
|
|
631
644
|
|
|
632
|
-
_.defaults(
|
|
645
|
+
_.defaults(_this8, results);
|
|
633
646
|
|
|
634
647
|
var cover_obj = {
|
|
635
648
|
old: results,
|
|
636
|
-
new:
|
|
649
|
+
new: _this8,
|
|
637
650
|
id: args.id
|
|
638
651
|
};
|
|
639
652
|
|
|
640
653
|
if (args.skip_hooks != true) {
|
|
641
|
-
yield
|
|
654
|
+
yield _this8.run_hook(cover_obj, "update", "before", results);
|
|
642
655
|
}
|
|
643
656
|
|
|
644
657
|
var form;
|
|
645
658
|
|
|
646
659
|
if (args.skip_write_serialize != true && args.skip_serialize != true) {
|
|
647
|
-
form = yield
|
|
660
|
+
form = yield _this8.do_serialize(_this8, "write", cover_obj.new, args);
|
|
648
661
|
}
|
|
649
662
|
|
|
650
|
-
var db_data = form ||
|
|
651
|
-
yield
|
|
663
|
+
var db_data = form || _this8;
|
|
664
|
+
yield _this8.database.update(args.id, db_data);
|
|
652
665
|
|
|
653
|
-
|
|
666
|
+
_this8.setMonitor();
|
|
654
667
|
|
|
655
668
|
if (args.skip_hooks != true) {
|
|
656
|
-
yield
|
|
669
|
+
yield _this8.run_hook(_extends({}, _this8, {
|
|
657
670
|
id: args.id
|
|
658
671
|
}), "update", "after", results);
|
|
659
672
|
}
|
|
660
673
|
|
|
661
674
|
if (args.skip_read_serialize != true && args.skip_serialize != true) {
|
|
662
|
-
form = yield
|
|
675
|
+
form = yield _this8.do_serialize(form, "read", {}, args, (yield _this8.propsToBeRemoved(form)));
|
|
663
676
|
}
|
|
664
677
|
|
|
665
|
-
|
|
678
|
+
_this8.id = args.id;
|
|
666
679
|
return _extends({}, form, {
|
|
667
680
|
id: args.id
|
|
668
681
|
});
|
|
@@ -674,38 +687,38 @@ class SpiceModel {
|
|
|
674
687
|
}
|
|
675
688
|
|
|
676
689
|
create(args) {
|
|
677
|
-
var
|
|
690
|
+
var _this9 = this;
|
|
678
691
|
|
|
679
692
|
return _asyncToGenerator(function* () {
|
|
680
693
|
try {
|
|
681
694
|
var form;
|
|
682
|
-
|
|
695
|
+
_this9.created_at = new SDate().now();
|
|
683
696
|
|
|
684
697
|
if (args.body) {
|
|
685
698
|
form = _.defaults({}, args.body);
|
|
686
|
-
form.created_at =
|
|
687
|
-
form.updated_at =
|
|
699
|
+
form.created_at = _this9.created_at;
|
|
700
|
+
form.updated_at = _this9.created_at;
|
|
688
701
|
delete form["bucket"];
|
|
689
702
|
}
|
|
690
703
|
|
|
691
|
-
var workingForm = form ||
|
|
692
|
-
|
|
704
|
+
var workingForm = form || _this9;
|
|
705
|
+
_this9.updated_at = new SDate().now();
|
|
693
706
|
var id = args.id_prefix + "-" + UUID.v4();
|
|
694
707
|
|
|
695
708
|
if (args && args.id) {
|
|
696
709
|
id = args.id;
|
|
697
710
|
}
|
|
698
711
|
|
|
699
|
-
yield
|
|
700
|
-
workingForm = yield
|
|
701
|
-
var results = yield
|
|
712
|
+
yield _this9.run_hook(workingForm, "create", "before");
|
|
713
|
+
workingForm = yield _this9.do_serialize(workingForm, "write", {}, args);
|
|
714
|
+
var results = yield _this9.database.insert(id, workingForm, args.expiry);
|
|
702
715
|
|
|
703
|
-
|
|
716
|
+
_this9.setMonitor();
|
|
704
717
|
|
|
705
|
-
yield
|
|
718
|
+
yield _this9.run_hook(_extends({}, results, {
|
|
706
719
|
id
|
|
707
720
|
}), "create", "after");
|
|
708
|
-
results = yield
|
|
721
|
+
results = yield _this9.do_serialize(results, "read", {}, args, (yield _this9.propsToBeRemoved(results)));
|
|
709
722
|
return _extends({}, results, {
|
|
710
723
|
id
|
|
711
724
|
});
|
|
@@ -717,32 +730,32 @@ class SpiceModel {
|
|
|
717
730
|
}
|
|
718
731
|
|
|
719
732
|
delete(args) {
|
|
720
|
-
var
|
|
733
|
+
var _this10 = this;
|
|
721
734
|
|
|
722
735
|
return _asyncToGenerator(function* () {
|
|
723
|
-
var item_exist = yield
|
|
736
|
+
var item_exist = yield _this10.exist(args.id);
|
|
724
737
|
|
|
725
738
|
if (!item_exist) {
|
|
726
|
-
throw new Error(
|
|
739
|
+
throw new Error(_this10.type + " does not exist.");
|
|
727
740
|
}
|
|
728
741
|
|
|
729
|
-
var results = yield
|
|
742
|
+
var results = yield _this10.database.get(args.id);
|
|
730
743
|
|
|
731
744
|
try {
|
|
732
|
-
yield
|
|
745
|
+
yield _this10.run_hook(args, "delete", "before");
|
|
733
746
|
var delete_response = {};
|
|
734
747
|
|
|
735
748
|
if (args.hard) {
|
|
736
|
-
delete_response = yield
|
|
749
|
+
delete_response = yield _this10.database.delete(args.id);
|
|
737
750
|
|
|
738
|
-
|
|
751
|
+
_this10.setMonitor();
|
|
739
752
|
} else {
|
|
740
753
|
delete results["id"];
|
|
741
754
|
results.deleted = true;
|
|
742
|
-
delete_response = yield
|
|
755
|
+
delete_response = yield _this10.database.update(args.id, "");
|
|
743
756
|
}
|
|
744
757
|
|
|
745
|
-
yield
|
|
758
|
+
yield _this10.run_hook(results, "delete", "after", results);
|
|
746
759
|
return {};
|
|
747
760
|
} catch (e) {
|
|
748
761
|
console.log(e.stack);
|
|
@@ -756,7 +769,7 @@ class SpiceModel {
|
|
|
756
769
|
}
|
|
757
770
|
|
|
758
771
|
list(args) {
|
|
759
|
-
var
|
|
772
|
+
var _this11 = this;
|
|
760
773
|
|
|
761
774
|
return _asyncToGenerator(function* () {
|
|
762
775
|
function filterResultsByColumns(data, columns) {
|
|
@@ -784,7 +797,7 @@ class SpiceModel {
|
|
|
784
797
|
query = args.query;
|
|
785
798
|
} else {
|
|
786
799
|
if (args.filters) {
|
|
787
|
-
query =
|
|
800
|
+
query = _this11.makeQueryFromFilter(args.filters);
|
|
788
801
|
} else {
|
|
789
802
|
if (args.query) {
|
|
790
803
|
query = args.query + " AND (deleted = false OR deleted IS MISSING) ";
|
|
@@ -806,69 +819,69 @@ class SpiceModel {
|
|
|
806
819
|
args.sort = "created_at DESC";
|
|
807
820
|
}
|
|
808
821
|
|
|
809
|
-
yield
|
|
822
|
+
yield _this11.run_hook(_this11, "list", "before");
|
|
810
823
|
|
|
811
824
|
function removeSpaceAndSpecialCharacters(str) {
|
|
812
825
|
return str.replace(/[^a-zA-Z0-9]/g, "");
|
|
813
826
|
}
|
|
814
827
|
|
|
815
|
-
var key = removeSpaceAndSpecialCharacters(
|
|
828
|
+
var key = removeSpaceAndSpecialCharacters(_this11.type + "::" + query + "::" + args.limit + "::" + args.offset + "::" + args.sort + "::" + args.do_count + "::" + args.statement_consistent + "::" + args.columns + "::" + args.is_full_text + "::" + args.is_custom_query);
|
|
816
829
|
var results;
|
|
817
830
|
|
|
818
831
|
if (args.is_custom_query && args.is_custom_query === "true") {
|
|
819
832
|
if (args.ids.length > 0) {
|
|
820
|
-
if (
|
|
821
|
-
var cached_results = yield
|
|
833
|
+
if (_this11.shouldCache(_this11.type)) {
|
|
834
|
+
var cached_results = yield _this11.getCacheProviderObject(_this11.type).get(key);
|
|
822
835
|
results = cached_results == null ? void 0 : cached_results.value;
|
|
823
836
|
|
|
824
|
-
if ((cached_results == null ? void 0 : cached_results.value) == undefined ||
|
|
825
|
-
results = yield
|
|
837
|
+
if ((cached_results == null ? void 0 : cached_results.value) == undefined || (yield _this11.shouldForceRefresh(cached_results))) {
|
|
838
|
+
results = yield _this11.database.query(query);
|
|
826
839
|
|
|
827
|
-
|
|
840
|
+
_this11.getCacheProviderObject(_this11.type).set(key, {
|
|
828
841
|
value: results,
|
|
829
842
|
time: new Date().getTime()
|
|
830
|
-
},
|
|
843
|
+
}, _this11.getCacheConfig(_this11.type));
|
|
831
844
|
}
|
|
832
845
|
} else {
|
|
833
|
-
results = yield
|
|
846
|
+
results = yield _this11.database.query(query);
|
|
834
847
|
}
|
|
835
848
|
}
|
|
836
849
|
} else {
|
|
837
850
|
if (args.is_full_text && args.is_full_text === "true") {
|
|
838
|
-
if (
|
|
839
|
-
var _cached_results = yield
|
|
851
|
+
if (_this11.shouldCache(_this11.type)) {
|
|
852
|
+
var _cached_results = yield _this11.getCacheProviderObject(_this11.type).get(key);
|
|
840
853
|
|
|
841
854
|
results = _cached_results == null ? void 0 : _cached_results.value;
|
|
842
855
|
|
|
843
|
-
if ((_cached_results == null ? void 0 : _cached_results.value) == undefined ||
|
|
844
|
-
results = yield
|
|
856
|
+
if ((_cached_results == null ? void 0 : _cached_results.value) == undefined || (yield _this11.shouldForceRefresh(_cached_results))) {
|
|
857
|
+
results = yield _this11.database.full_text_search(_this11.type, query || "", args.limit, args.offset);
|
|
845
858
|
|
|
846
|
-
|
|
859
|
+
_this11.getCacheProviderObject(_this11.type).set(key, {
|
|
847
860
|
value: results,
|
|
848
861
|
time: new Date().getTime()
|
|
849
|
-
},
|
|
862
|
+
}, _this11.getCacheConfig(_this11.type));
|
|
850
863
|
}
|
|
851
864
|
} else {
|
|
852
|
-
results = yield
|
|
865
|
+
results = yield _this11.database.full_text_search(_this11.type, query || "", args.limit, args.offset);
|
|
853
866
|
}
|
|
854
867
|
} else {
|
|
855
|
-
if (
|
|
856
|
-
var _cached_results2 = yield
|
|
868
|
+
if (_this11.shouldCache(_this11.type)) {
|
|
869
|
+
var _cached_results2 = yield _this11.getCacheProviderObject(_this11.type).get(key);
|
|
857
870
|
|
|
858
871
|
results = _cached_results2 == null ? void 0 : _cached_results2.value;
|
|
859
872
|
|
|
860
|
-
if ((_cached_results2 == null ? void 0 : _cached_results2.value) == undefined ||
|
|
861
|
-
results = yield
|
|
873
|
+
if ((_cached_results2 == null ? void 0 : _cached_results2.value) == undefined || (yield _this11.shouldForceRefresh(_cached_results2))) {
|
|
874
|
+
results = yield _this11.database.search(_this11.type, args.columns || "", query || "", args.limit, args.offset, args.sort, args.do_count, args.statement_consistent);
|
|
862
875
|
|
|
863
|
-
|
|
876
|
+
_this11.getCacheProviderObject(_this11.type).set(key, {
|
|
864
877
|
value: results,
|
|
865
878
|
time: new Date().getTime()
|
|
866
|
-
},
|
|
879
|
+
}, _this11.getCacheConfig(_this11.type));
|
|
867
880
|
}
|
|
868
881
|
} else {
|
|
869
|
-
results = yield
|
|
882
|
+
results = yield _this11.database.search(_this11.type, args.columns || "", query || "", args.limit, args.offset, args.sort, args.do_count, args.statement_consistent);
|
|
870
883
|
|
|
871
|
-
if (
|
|
884
|
+
if (_this11.type == "user") {
|
|
872
885
|
console.log("results from DB No Chache available", results);
|
|
873
886
|
}
|
|
874
887
|
}
|
|
@@ -876,8 +889,8 @@ class SpiceModel {
|
|
|
876
889
|
}
|
|
877
890
|
|
|
878
891
|
try {
|
|
879
|
-
yield
|
|
880
|
-
results.data = yield
|
|
892
|
+
yield _this11.run_hook(results.data, "list", "after");
|
|
893
|
+
results.data = yield _this11.do_serialize(results.data, "read", {}, args, (yield _this11.propsToBeRemoved(results.data)));
|
|
881
894
|
} catch (e) {
|
|
882
895
|
console.log(e);
|
|
883
896
|
}
|
|
@@ -903,26 +916,26 @@ class SpiceModel {
|
|
|
903
916
|
}
|
|
904
917
|
|
|
905
918
|
run_hook(data, op, when, old_data) {
|
|
906
|
-
var
|
|
919
|
+
var _this12 = this;
|
|
907
920
|
|
|
908
921
|
return _asyncToGenerator(function* () {
|
|
909
922
|
try {
|
|
910
|
-
if (
|
|
923
|
+
if (_this12[_disable_lifecycle_events] == false) {
|
|
911
924
|
var resourceLifecycleTriggered = new _ResourceLifecycleTriggered.default({
|
|
912
925
|
data: {
|
|
913
926
|
data,
|
|
914
927
|
operation: op,
|
|
915
928
|
when,
|
|
916
929
|
old_data,
|
|
917
|
-
resource:
|
|
918
|
-
ctx:
|
|
930
|
+
resource: _this12.type,
|
|
931
|
+
ctx: _this12[_ctx]
|
|
919
932
|
}
|
|
920
933
|
});
|
|
921
934
|
resourceLifecycleTriggered.dispatch();
|
|
922
935
|
}
|
|
923
936
|
|
|
924
|
-
if (
|
|
925
|
-
for (var i of
|
|
937
|
+
if (_this12[_hooks] && _this12[_hooks][op] && _this12[_hooks][op][when]) {
|
|
938
|
+
for (var i of _this12[_hooks][op][when]) {
|
|
926
939
|
data = yield i(data, old_data);
|
|
927
940
|
}
|
|
928
941
|
}
|
|
@@ -955,7 +968,7 @@ class SpiceModel {
|
|
|
955
968
|
}
|
|
956
969
|
|
|
957
970
|
mapToObject(data, Class, source_property, store_property, property) {
|
|
958
|
-
var
|
|
971
|
+
var _this13 = this;
|
|
959
972
|
|
|
960
973
|
return _asyncToGenerator(function* () {
|
|
961
974
|
var original_is_array = _.isArray(data);
|
|
@@ -984,7 +997,7 @@ class SpiceModel {
|
|
|
984
997
|
});
|
|
985
998
|
|
|
986
999
|
var returned_all = yield Promise.allSettled(_.map(classes, obj => {
|
|
987
|
-
return new obj(
|
|
1000
|
+
return new obj(_this13[_args]).getMulti({
|
|
988
1001
|
ids: ids
|
|
989
1002
|
});
|
|
990
1003
|
}));
|
|
@@ -1006,7 +1019,7 @@ class SpiceModel {
|
|
|
1006
1019
|
}
|
|
1007
1020
|
|
|
1008
1021
|
mapToObjectArray(data, Class, source_property, store_property, property) {
|
|
1009
|
-
var
|
|
1022
|
+
var _this14 = this;
|
|
1010
1023
|
|
|
1011
1024
|
return _asyncToGenerator(function* () {
|
|
1012
1025
|
var original_is_array = _.isArray(data);
|
|
@@ -1035,7 +1048,7 @@ class SpiceModel {
|
|
|
1035
1048
|
|
|
1036
1049
|
var classes = _.isArray(Class) ? Class : [Class];
|
|
1037
1050
|
var returned_all = yield Promise.allSettled(_.map(classes, obj => {
|
|
1038
|
-
return new obj(
|
|
1051
|
+
return new obj(_this14[_args]).getMulti({
|
|
1039
1052
|
ids: ids
|
|
1040
1053
|
});
|
|
1041
1054
|
}));
|
|
@@ -1095,7 +1108,7 @@ class SpiceModel {
|
|
|
1095
1108
|
}
|
|
1096
1109
|
|
|
1097
1110
|
createMofifier(properties) {
|
|
1098
|
-
var
|
|
1111
|
+
var _this15 = this;
|
|
1099
1112
|
|
|
1100
1113
|
var _loop = function _loop(i) {
|
|
1101
1114
|
if (properties[i].map) {
|
|
@@ -1106,11 +1119,11 @@ class SpiceModel {
|
|
|
1106
1119
|
case String:
|
|
1107
1120
|
case "string":
|
|
1108
1121
|
{
|
|
1109
|
-
|
|
1122
|
+
_this15.addModifier({
|
|
1110
1123
|
when: properties[i].map.when || "read",
|
|
1111
1124
|
execute: function () {
|
|
1112
1125
|
var _execute = _asyncToGenerator(function* (data) {
|
|
1113
|
-
return yield
|
|
1126
|
+
return yield _this15.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]);
|
|
1114
1127
|
});
|
|
1115
1128
|
|
|
1116
1129
|
function execute(_x) {
|
|
@@ -1127,11 +1140,11 @@ class SpiceModel {
|
|
|
1127
1140
|
case Array:
|
|
1128
1141
|
case "array":
|
|
1129
1142
|
{
|
|
1130
|
-
|
|
1143
|
+
_this15.addModifier({
|
|
1131
1144
|
when: properties[i].map.when || "read",
|
|
1132
1145
|
execute: function () {
|
|
1133
1146
|
var _execute2 = _asyncToGenerator(function* (data) {
|
|
1134
|
-
return yield
|
|
1147
|
+
return yield _this15.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]);
|
|
1135
1148
|
});
|
|
1136
1149
|
|
|
1137
1150
|
function execute(_x2) {
|
|
@@ -1163,7 +1176,7 @@ class SpiceModel {
|
|
|
1163
1176
|
}
|
|
1164
1177
|
|
|
1165
1178
|
do_serialize(data, type, old_data, args, path_to_be_removed) {
|
|
1166
|
-
var
|
|
1179
|
+
var _this16 = this;
|
|
1167
1180
|
|
|
1168
1181
|
return _asyncToGenerator(function* () {
|
|
1169
1182
|
//console.log("CTX INside Model DO", this[_ctx]);
|
|
@@ -1173,16 +1186,16 @@ class SpiceModel {
|
|
|
1173
1186
|
path_to_be_removed = [];
|
|
1174
1187
|
}
|
|
1175
1188
|
|
|
1176
|
-
if (
|
|
1177
|
-
if (
|
|
1178
|
-
|
|
1189
|
+
if (_this16.shouldSerializerRun(args, type)) {
|
|
1190
|
+
if (_this16.type != "" && _this16.type != undefined && _this16[_external_modifier_loaded] != true) {
|
|
1191
|
+
_this16.addExternalModifiers(_this16.type);
|
|
1179
1192
|
|
|
1180
|
-
|
|
1193
|
+
_this16[_external_modifier_loaded] = true;
|
|
1181
1194
|
}
|
|
1182
1195
|
|
|
1183
|
-
for (var i of
|
|
1196
|
+
for (var i of _this16[_serializers][type]["modifiers"]) {
|
|
1184
1197
|
try {
|
|
1185
|
-
data = yield i(data, old_data,
|
|
1198
|
+
data = yield i(data, old_data, _this16[_ctx], _this16.type);
|
|
1186
1199
|
} catch (e) {
|
|
1187
1200
|
console.log(e.stack);
|
|
1188
1201
|
}
|
|
@@ -1198,12 +1211,12 @@ class SpiceModel {
|
|
|
1198
1211
|
|
|
1199
1212
|
var defaults = {};
|
|
1200
1213
|
|
|
1201
|
-
for (var _i in
|
|
1202
|
-
if (
|
|
1203
|
-
defaults[_i] = _.isFunction(
|
|
1214
|
+
for (var _i in _this16.props) {
|
|
1215
|
+
if (_this16.props[_i].defaults != undefined && _this16.props[_i].defaults[type] != undefined && _this16.props[_i].defaults[type] != undefined) {
|
|
1216
|
+
defaults[_i] = _.isFunction(_this16.props[_i].defaults[type]) ? _this16.props[_i].defaults[type]({
|
|
1204
1217
|
old_data: data,
|
|
1205
1218
|
new_data: old_data
|
|
1206
|
-
}) :
|
|
1219
|
+
}) : _this16.props[_i].defaults[type];
|
|
1207
1220
|
}
|
|
1208
1221
|
} // apply defaults
|
|
1209
1222
|
|
|
@@ -1216,8 +1229,8 @@ class SpiceModel {
|
|
|
1216
1229
|
if (type == "read") {
|
|
1217
1230
|
var props_to_clean = ["deleted", "type", ...path_to_be_removed];
|
|
1218
1231
|
|
|
1219
|
-
for (var _i3 in
|
|
1220
|
-
if (
|
|
1232
|
+
for (var _i3 in _this16.props) {
|
|
1233
|
+
if (_this16.props[_i3].hide) {
|
|
1221
1234
|
props_to_clean.push(_i3);
|
|
1222
1235
|
}
|
|
1223
1236
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "spice-js",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.6",
|
|
4
4
|
"description": "spice",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"repository": {
|
|
@@ -39,7 +39,6 @@
|
|
|
39
39
|
"regenerator-runtime": "^0.13.7",
|
|
40
40
|
"socket.io-client": "^4.0.1",
|
|
41
41
|
"sonover-date": "^1.0.1",
|
|
42
|
-
"spice-couchbase": "^2.0.14",
|
|
43
42
|
"uuid": "^3.3.3",
|
|
44
43
|
"winston": "^3.2.1"
|
|
45
44
|
},
|
package/src/bootstrap/cache.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
async function connect() {
|
|
4
4
|
try {
|
|
5
5
|
spice.cache_providers = {};
|
|
6
|
-
spice.monitor =
|
|
6
|
+
spice.monitor = new Map();
|
|
7
7
|
for (let key of Object.keys(spice.config.cache.providers)) {
|
|
8
8
|
spice.cache_providers[key] = new spice.config.cache.providers[key](
|
|
9
9
|
spice.config.cache.drivers[key] || {}
|
package/src/models/SpiceModel.js
CHANGED
|
@@ -366,7 +366,10 @@ export default class SpiceModel {
|
|
|
366
366
|
}
|
|
367
367
|
|
|
368
368
|
shouldCache(resource_type) {
|
|
369
|
-
return
|
|
369
|
+
return (
|
|
370
|
+
spice.cache[resource_type] != undefined ||
|
|
371
|
+
spice.systemconfig?.cache?.status == "disable"
|
|
372
|
+
);
|
|
370
373
|
}
|
|
371
374
|
|
|
372
375
|
getCacheConfig(resource_type) {
|
|
@@ -376,6 +379,7 @@ export default class SpiceModel {
|
|
|
376
379
|
getCacheProviderObject(resource_type) {
|
|
377
380
|
return spice.cache_providers[
|
|
378
381
|
this.getCacheConfig(resource_type).driver ||
|
|
382
|
+
this.getCacheConfig(resource_type).provider ||
|
|
379
383
|
spice.config.cache.default_driver
|
|
380
384
|
];
|
|
381
385
|
}
|
|
@@ -386,12 +390,13 @@ export default class SpiceModel {
|
|
|
386
390
|
return false;
|
|
387
391
|
}
|
|
388
392
|
|
|
389
|
-
shouldForceRefresh(response) {
|
|
390
|
-
let
|
|
393
|
+
async shouldForceRefresh(response) {
|
|
394
|
+
let obj = this.getCacheProviderObject();
|
|
395
|
+
let monitor_record = await obj.get(`monitor::${this.type}`);
|
|
391
396
|
if (monitor_record == undefined) {
|
|
392
397
|
return false;
|
|
393
398
|
}
|
|
394
|
-
if (monitor_record > response?.time) {
|
|
399
|
+
if (monitor_record.time > response?.time) {
|
|
395
400
|
return true;
|
|
396
401
|
}
|
|
397
402
|
return false;
|
|
@@ -399,7 +404,8 @@ export default class SpiceModel {
|
|
|
399
404
|
|
|
400
405
|
setMonitor() {
|
|
401
406
|
let current_time = new Date().getTime();
|
|
402
|
-
|
|
407
|
+
let obj = this.getCacheProviderObject();
|
|
408
|
+
obj.set(`monitor::${this.type}`, { time: current_time }, { ttl: 0 });
|
|
403
409
|
//console.log("Monitor Set", spice.monitor);
|
|
404
410
|
}
|
|
405
411
|
|
|
@@ -419,7 +425,7 @@ export default class SpiceModel {
|
|
|
419
425
|
results = cached_results?.value;
|
|
420
426
|
if (
|
|
421
427
|
cached_results?.value == undefined ||
|
|
422
|
-
this.shouldForceRefresh(cached_results)
|
|
428
|
+
(await this.shouldForceRefresh(cached_results))
|
|
423
429
|
) {
|
|
424
430
|
results = await this.database.get(args.id);
|
|
425
431
|
await this.getCacheProviderObject(this.type).set(
|
|
@@ -488,7 +494,7 @@ export default class SpiceModel {
|
|
|
488
494
|
results = cached_results?.value;
|
|
489
495
|
if (
|
|
490
496
|
cached_results?.value == undefined ||
|
|
491
|
-
this.shouldForceRefresh(cached_results)
|
|
497
|
+
(await this.shouldForceRefresh(cached_results))
|
|
492
498
|
) {
|
|
493
499
|
results = await this.database.multi_get(args.ids, true);
|
|
494
500
|
this.getCacheProviderObject(this.type).set(
|
|
@@ -743,7 +749,7 @@ export default class SpiceModel {
|
|
|
743
749
|
results = cached_results?.value;
|
|
744
750
|
if (
|
|
745
751
|
cached_results?.value == undefined ||
|
|
746
|
-
this.shouldForceRefresh(cached_results)
|
|
752
|
+
(await this.shouldForceRefresh(cached_results))
|
|
747
753
|
) {
|
|
748
754
|
results = await this.database.query(query);
|
|
749
755
|
this.getCacheProviderObject(this.type).set(
|
|
@@ -765,7 +771,7 @@ export default class SpiceModel {
|
|
|
765
771
|
results = cached_results?.value;
|
|
766
772
|
if (
|
|
767
773
|
cached_results?.value == undefined ||
|
|
768
|
-
this.shouldForceRefresh(cached_results)
|
|
774
|
+
(await this.shouldForceRefresh(cached_results))
|
|
769
775
|
) {
|
|
770
776
|
results = await this.database.full_text_search(
|
|
771
777
|
this.type,
|
|
@@ -795,7 +801,7 @@ export default class SpiceModel {
|
|
|
795
801
|
results = cached_results?.value;
|
|
796
802
|
if (
|
|
797
803
|
cached_results?.value == undefined ||
|
|
798
|
-
this.shouldForceRefresh(cached_results)
|
|
804
|
+
(await this.shouldForceRefresh(cached_results))
|
|
799
805
|
) {
|
|
800
806
|
results = await this.database.search(
|
|
801
807
|
this.type,
|