spice-js 2.5.37 → 2.6.0

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.
@@ -58,8 +58,7 @@ class SpiceModel {
58
58
  var Database = require("spice-" + dbtype);
59
59
 
60
60
  this.type = "";
61
- this.collection = args.connection; //console.log("Args -- Type::", args.type);
62
-
61
+ this.collection = args.connection;
63
62
  this[_args] = args.args;
64
63
  this[_external_modifier_loaded] = false;
65
64
  this[_disable_lifecycle_events] = ((_args$args = args.args) == null ? void 0 : _args$args.disable_lifecycle_events) || false;
@@ -179,19 +178,6 @@ class SpiceModel {
179
178
  } // }
180
179
 
181
180
  }
182
- /* get type() {
183
- return this._type;
184
- }
185
- // Setter for 'type'
186
- set type(value) {
187
- if (typeof value !== "string") {
188
- // example validation
189
- throw new Error("Type must be a string.");
190
- }
191
- this._type = value;
192
- //console.log("Type Setted::", value);
193
- } */
194
-
195
181
 
196
182
  get database() {
197
183
  return this[_database];
@@ -446,9 +432,32 @@ class SpiceModel {
446
432
  return return_string;
447
433
  }
448
434
 
449
- get(args) {
435
+ shouldCache(resource_type) {
436
+ return spice.cache[resource_type] != undefined;
437
+ }
438
+
439
+ getCacheConfig(resource_type) {
440
+ return spice.cache[resource_type] || {};
441
+ }
442
+
443
+ getCacheProviderObject(resource_type) {
444
+ return spice.cache_providers[this.getCacheConfig(resource_type).driver || spice.config.cache.default_driver];
445
+ }
446
+
447
+ exists(item_type, key) {
450
448
  var _this2 = this;
451
449
 
450
+ return _asyncToGenerator(function* () {
451
+ var obj = _this2.getCacheProviderObject(item_type);
452
+
453
+ if (obj) return yield obj.exists(key);
454
+ return false;
455
+ })();
456
+ }
457
+
458
+ get(args) {
459
+ var _this3 = this;
460
+
452
461
  return _asyncToGenerator(function* () {
453
462
  try {
454
463
  if (!args) {
@@ -456,23 +465,45 @@ class SpiceModel {
456
465
  }
457
466
 
458
467
  if (_.isString(args.id)) {
459
- yield _this2.run_hook(args, "get", "before");
460
- var results = yield _this2.database.get(args.id);
468
+ yield _this3.run_hook(args, "get", "before");
469
+ var key = _this3.type + "::" + args.id;
470
+ var results = {};
471
+
472
+ if (_this3.shouldCache(_this3.type)) {
473
+ var cached_results = yield _this3.getCacheProviderObject(_this3.type).get(key);
474
+
475
+ if (cached_results) {
476
+ //calculate time taken to get data from Cache
477
+ results = cached_results;
478
+ /* if (this.type == "user") {
479
+ console.log("results from Cache", results);
480
+ } */
481
+ } else {
482
+ results = yield _this3.database.get(args.id);
483
+ /* if (this.type == "user") {
484
+ console.log("results from DB", results);
485
+ } */
486
+
487
+ yield _this3.getCacheProviderObject(_this3.type).set(key, results, _this3.getCacheConfig(_this3.type));
488
+ }
489
+ } else {
490
+ results = yield _this3.database.get(args.id);
491
+ }
461
492
 
462
493
  if (results.type != undefined) {
463
- if (results.type != _this2.type) throw new Error(_this2.type + " does not exist type");
494
+ if (results.type != _this3.type) throw new Error(_this3.type + " does not exist type");
464
495
  }
465
496
 
466
497
  if (results._type != undefined) {
467
- if (results._type != _this2.type) throw new Error(_this2.type + " does not exist _type");
498
+ if (results._type != _this3.type) throw new Error(_this3.type + " does not exist _type");
468
499
  }
469
500
 
470
501
  if (results.deleted == undefined || results.deleted == false) {
471
- yield _this2.run_hook(results, "get", "after");
472
- results = yield _this2.do_serialize(results, "read", {}, args, (yield _this2.propsToBeRemoved(results)));
502
+ yield _this3.run_hook(results, "get", "after");
503
+ results = yield _this3.do_serialize(results, "read", {}, args, (yield _this3.propsToBeRemoved(results)));
473
504
  return results;
474
505
  } else {
475
- throw new Error(_this2.type + " does not exist");
506
+ throw new Error(_this3.type + " does not exist");
476
507
  }
477
508
  }
478
509
  } catch (e) {
@@ -482,11 +513,11 @@ class SpiceModel {
482
513
  }
483
514
 
484
515
  query(query, scope) {
485
- var _this3 = this;
516
+ var _this4 = this;
486
517
 
487
518
  return _asyncToGenerator(function* () {
488
519
  try {
489
- var results = yield _this3.database.query(query, scope);
520
+ var results = yield _this4.database.query(query, scope);
490
521
  return results;
491
522
  } catch (error) {
492
523
  throw error;
@@ -495,7 +526,7 @@ class SpiceModel {
495
526
  }
496
527
 
497
528
  getMulti(args) {
498
- var _this4 = this;
529
+ var _this5 = this;
499
530
 
500
531
  return _asyncToGenerator(function* () {
501
532
  try {
@@ -503,20 +534,34 @@ class SpiceModel {
503
534
  args = {};
504
535
  }
505
536
 
506
- yield _this4.run_hook(_this4, "list", "before");
537
+ yield _this5.run_hook(_this5, "list", "before");
507
538
 
508
539
  _.remove(args.ids, o => o == undefined);
509
540
 
541
+ var key = _this5.type + "::" + _.join(args.ids, "|");
542
+
510
543
  var results = [];
511
544
 
512
545
  if (args.ids.length > 0) {
513
- results = yield _this4.database.multi_get(args.ids, true);
546
+ if (_this5.shouldCache(_this5.type)) {
547
+ var cached_results = yield _this5.getCacheProviderObject(_this5.type).get(key);
548
+
549
+ if (cached_results) {
550
+ results = cached_results;
551
+ } else {
552
+ results = yield _this5.database.multi_get(args.ids, true);
553
+
554
+ _this5.getCacheProviderObject(_this5.type).set(key, results, _this5.getCacheConfig(_this5.type));
555
+ }
556
+ } else {
557
+ results = yield _this5.database.multi_get(args.ids, true);
558
+ }
514
559
  }
515
560
 
516
- _.remove(results, o => o.type != _this4.type);
561
+ _.remove(results, o => o.type != _this5.type);
517
562
 
518
- yield _this4.run_hook(results, "list", "after", args.context);
519
- results = yield _this4.do_serialize(results, "read", {}, args, (yield _this4.propsToBeRemoved(results)));
563
+ yield _this5.run_hook(results, "list", "after", args.context);
564
+ results = yield _this5.do_serialize(results, "read", {}, args, (yield _this5.propsToBeRemoved(results)));
520
565
  return results;
521
566
  } catch (e) {
522
567
  console.log(e.stack);
@@ -526,23 +571,23 @@ class SpiceModel {
526
571
  }
527
572
 
528
573
  exist(data) {
529
- var _this5 = this;
574
+ var _this6 = this;
530
575
 
531
576
  return _asyncToGenerator(function* () {
532
577
  try {
533
578
  if (_.isString(data)) {
534
- var result = yield _this5.database.get(data);
535
- if (result.type) if (result.type != _this5.type) {
579
+ var result = yield _this6.database.get(data);
580
+ if (result.type) if (result.type != _this6.type) {
536
581
  return false;
537
582
  }
538
- if (result._type) if (result._type != _this5.type) {
583
+ if (result._type) if (result._type != _this6.type) {
539
584
  return false;
540
585
  }
541
586
  } else {
542
- if (data.type) if (data.type != _this5.type) {
587
+ if (data.type) if (data.type != _this6.type) {
543
588
  return false;
544
589
  }
545
- if (data._type) if (data._type != _this5.type) {
590
+ if (data._type) if (data._type != _this6.type) {
546
591
  return false;
547
592
  }
548
593
  }
@@ -555,58 +600,52 @@ class SpiceModel {
555
600
  }
556
601
 
557
602
  update(args) {
558
- var _this6 = this;
603
+ var _this7 = this;
559
604
 
560
605
  return _asyncToGenerator(function* () {
561
606
  try {
562
- _this6.updated_at = new SDate().now();
563
- var results = yield _this6.database.get(args.id);
564
- console.log("Results", results);
565
- var item_exist = yield _this6.exist(results);
566
- console.log("Item Exist", item_exist);
607
+ _this7.updated_at = new SDate().now();
608
+ var results = yield _this7.database.get(args.id);
609
+ var item_exist = yield _this7.exist(results);
567
610
 
568
611
  if (!item_exist) {
569
- throw new Error(_this6.type + " does not exist. in update");
612
+ throw new Error(_this7.type + " does not exist. in update");
570
613
  }
571
614
 
572
615
  delete results["id"];
573
616
 
574
- _.defaults(_this6, results);
617
+ _.defaults(_this7, results);
575
618
 
576
619
  var cover_obj = {
577
620
  old: results,
578
- new: _this6,
621
+ new: _this7,
579
622
  id: args.id
580
623
  };
581
624
 
582
625
  if (args.skip_hooks != true) {
583
- yield _this6.run_hook(cover_obj, "update", "before", results);
626
+ yield _this7.run_hook(cover_obj, "update", "before", results);
584
627
  }
585
628
 
586
629
  var form;
587
630
 
588
631
  if (args.skip_write_serialize != true && args.skip_serialize != true) {
589
- form = yield _this6.do_serialize(_this6, "write", cover_obj.new, args);
632
+ form = yield _this7.do_serialize(_this7, "write", cover_obj.new, args);
590
633
  }
591
634
 
592
- var db_data = form || _this6; //console.log("New Data Inside Update::::", db_data);
593
-
594
- _this6.implementTypeFix(db_data); // console.log("After ITF::::", db_data);
595
-
596
-
597
- yield _this6.database.update(args.id, db_data); //console.log("Old Data Inside Update::::", results);
635
+ var db_data = form || _this7;
636
+ yield _this7.database.update(args.id, db_data);
598
637
 
599
638
  if (args.skip_hooks != true) {
600
- yield _this6.run_hook(_extends({}, _this6, {
639
+ yield _this7.run_hook(_extends({}, _this7, {
601
640
  id: args.id
602
641
  }), "update", "after", results);
603
642
  }
604
643
 
605
644
  if (args.skip_read_serialize != true && args.skip_serialize != true) {
606
- form = yield _this6.do_serialize(form, "read", {}, args, (yield _this6.propsToBeRemoved(form)));
645
+ form = yield _this7.do_serialize(form, "read", {}, args, (yield _this7.propsToBeRemoved(form)));
607
646
  }
608
647
 
609
- _this6.id = args.id;
648
+ _this7.id = args.id;
610
649
  return _extends({}, form, {
611
650
  id: args.id
612
651
  });
@@ -617,48 +656,36 @@ class SpiceModel {
617
656
  })();
618
657
  }
619
658
 
620
- implementTypeFix(item) {
621
- /* console.log("Type Before Fix", item.type, item._type);
622
- let _new_type = item.type || item._type;
623
- //item.type = type;
624
- console.log("New type", _new_type);
625
- item = { ...item, type: _new_type };
626
- delete item._type; */
627
- //console.log("Type After Fix", item.type, item._type);
628
- //if (item._type) delete item["_type"];
629
- //console.log("Type After Fix", item.type);
630
- }
631
-
632
659
  create(args) {
633
- var _this7 = this;
660
+ var _this8 = this;
634
661
 
635
662
  return _asyncToGenerator(function* () {
636
663
  try {
637
664
  var form;
638
- _this7.created_at = new SDate().now();
665
+ _this8.created_at = new SDate().now();
639
666
 
640
667
  if (args.body) {
641
668
  form = _.defaults({}, args.body);
642
- form.created_at = _this7.created_at;
643
- form.updated_at = _this7.created_at;
669
+ form.created_at = _this8.created_at;
670
+ form.updated_at = _this8.created_at;
644
671
  delete form["bucket"];
645
672
  }
646
673
 
647
- var workingForm = form || _this7;
648
- _this7.updated_at = new SDate().now();
674
+ var workingForm = form || _this8;
675
+ _this8.updated_at = new SDate().now();
649
676
  var id = args.id_prefix + "-" + UUID.v4();
650
677
 
651
678
  if (args && args.id) {
652
679
  id = args.id;
653
680
  }
654
681
 
655
- yield _this7.run_hook(workingForm, "create", "before");
656
- workingForm = _this7.implementTypeFix((yield _this7.do_serialize(workingForm, "write", {}, args)));
657
- var results = yield _this7.database.insert(id, workingForm, args.expiry);
658
- yield _this7.run_hook(_extends({}, results, {
682
+ yield _this8.run_hook(workingForm, "create", "before");
683
+ workingForm = yield _this8.do_serialize(workingForm, "write", {}, args);
684
+ var results = yield _this8.database.insert(id, workingForm, args.expiry);
685
+ yield _this8.run_hook(_extends({}, results, {
659
686
  id
660
687
  }), "create", "after");
661
- results = yield _this7.do_serialize(results, "read", {}, args, (yield _this7.propsToBeRemoved(results)));
688
+ results = yield _this8.do_serialize(results, "read", {}, args, (yield _this8.propsToBeRemoved(results)));
662
689
  return _extends({}, results, {
663
690
  id
664
691
  });
@@ -670,30 +697,30 @@ class SpiceModel {
670
697
  }
671
698
 
672
699
  delete(args) {
673
- var _this8 = this;
700
+ var _this9 = this;
674
701
 
675
702
  return _asyncToGenerator(function* () {
676
- var item_exist = yield _this8.exist(args.id);
703
+ var item_exist = yield _this9.exist(args.id);
677
704
 
678
705
  if (!item_exist) {
679
- throw new Error(_this8.type + " does not exist.");
706
+ throw new Error(_this9.type + " does not exist.");
680
707
  }
681
708
 
682
- var results = yield _this8.database.get(args.id);
709
+ var results = yield _this9.database.get(args.id);
683
710
 
684
711
  try {
685
- yield _this8.run_hook(args, "delete", "before");
712
+ yield _this9.run_hook(args, "delete", "before");
686
713
  var delete_response = {};
687
714
 
688
715
  if (args.hard) {
689
- delete_response = yield _this8.database.delete(args.id);
716
+ delete_response = yield _this9.database.delete(args.id);
690
717
  } else {
691
718
  delete results["id"];
692
719
  results.deleted = true;
693
- delete_response = yield _this8.database.update(args.id, "");
720
+ delete_response = yield _this9.database.update(args.id, "");
694
721
  }
695
722
 
696
- yield _this8.run_hook(results, "delete", "after", results);
723
+ yield _this9.run_hook(results, "delete", "after", results);
697
724
  return {};
698
725
  } catch (e) {
699
726
  console.log(e.stack);
@@ -707,7 +734,7 @@ class SpiceModel {
707
734
  }
708
735
 
709
736
  list(args) {
710
- var _this9 = this;
737
+ var _this10 = this;
711
738
 
712
739
  return _asyncToGenerator(function* () {
713
740
  try {
@@ -721,7 +748,7 @@ class SpiceModel {
721
748
  query = args.query;
722
749
  } else {
723
750
  if (args.filters) {
724
- query = yield _this9.makeQueryFromFilter(args.filters);
751
+ query = _this10.makeQueryFromFilter(args.filters);
725
752
  } else {
726
753
  if (args.query) {
727
754
  query = args.query + " AND (deleted = false OR deleted IS MISSING) ";
@@ -743,22 +770,70 @@ class SpiceModel {
743
770
  args.sort = "created_at DESC";
744
771
  }
745
772
 
746
- yield _this9.run_hook(_this9, "list", "before");
773
+ yield _this10.run_hook(_this10, "list", "before");
774
+
775
+ function removeSpaceAndSpecialCharacters(str) {
776
+ return str.replace(/[^a-zA-Z0-9]/g, "");
777
+ }
778
+
779
+ var key = removeSpaceAndSpecialCharacters(_this10.type + "::" + query + "::" + args.limit + "::" + args.offset + "::" + args.sort + "::" + args.do_count + "::" + args.statement_consistent + "::" + args.columns + "::" + args.is_full_text + "::" + args.is_custom_query);
747
780
  var results;
748
781
 
749
782
  if (args.is_custom_query && args.is_custom_query === "true") {
750
- results = yield _this9.database.query(query);
783
+ if (args.ids.length > 0) {
784
+ if (_this10.shouldCache(_this10.type)) {
785
+ var cached_results = yield _this10.getCacheProviderObject(_this10.type).get(key);
786
+
787
+ if (cached_results) {
788
+ results = cached_results;
789
+ } else {
790
+ results = yield _this10.database.query(query);
791
+
792
+ _this10.getCacheProviderObject(_this10.type).set(key, results, _this10.getCacheConfig(_this10.type));
793
+ }
794
+ } else {
795
+ results = yield _this10.database.query(query);
796
+ }
797
+ }
751
798
  } else {
752
799
  if (args.is_full_text && args.is_full_text === "true") {
753
- results = yield _this9.database.full_text_search(_this9.type, query || "", args.limit, args.offset);
800
+ if (_this10.shouldCache(_this10.type)) {
801
+ var _cached_results = yield _this10.getCacheProviderObject(_this10.type).get(key);
802
+
803
+ if (_cached_results) {
804
+ results = _cached_results;
805
+ } else {
806
+ results = yield _this10.database.full_text_search(_this10.type, query || "", args.limit, args.offset);
807
+
808
+ _this10.getCacheProviderObject(_this10.type).set(key, results, _this10.getCacheConfig(_this10.type));
809
+ }
810
+ } else {
811
+ results = yield _this10.database.full_text_search(_this10.type, query || "", args.limit, args.offset);
812
+ }
754
813
  } else {
755
- results = yield _this9.database.search(_this9.type, args.columns || "", query || "", args.limit, args.offset, args.sort, args.do_count, args.statement_consistent);
814
+ if (_this10.shouldCache(_this10.type)) {
815
+ var _cached_results2 = yield _this10.getCacheProviderObject(_this10.type).get(key);
816
+
817
+ if (_cached_results2) {
818
+ results = _cached_results2;
819
+ } else {
820
+ results = yield _this10.database.search(_this10.type, args.columns || "", query || "", args.limit, args.offset, args.sort, args.do_count, args.statement_consistent);
821
+
822
+ _this10.getCacheProviderObject(_this10.type).set(key, results, _this10.getCacheConfig(_this10.type));
823
+ }
824
+ } else {
825
+ results = yield _this10.database.search(_this10.type, args.columns || "", query || "", args.limit, args.offset, args.sort, args.do_count, args.statement_consistent);
826
+
827
+ if (_this10.type == "user") {
828
+ console.log("results from DB No Chache available", results);
829
+ }
830
+ }
756
831
  }
757
832
  }
758
833
 
759
834
  try {
760
- yield _this9.run_hook(results.data, "list", "after");
761
- results.data = yield _this9.do_serialize(results.data, "read", {}, args, (yield _this9.propsToBeRemoved(results.data)));
835
+ yield _this10.run_hook(results.data, "list", "after");
836
+ results.data = yield _this10.do_serialize(results.data, "read", {}, args, (yield _this10.propsToBeRemoved(results.data)));
762
837
  } catch (e) {
763
838
  console.log(e);
764
839
  }
@@ -782,26 +857,26 @@ class SpiceModel {
782
857
  }
783
858
 
784
859
  run_hook(data, op, when, old_data) {
785
- var _this10 = this;
860
+ var _this11 = this;
786
861
 
787
862
  return _asyncToGenerator(function* () {
788
863
  try {
789
- if (_this10[_disable_lifecycle_events] == false) {
864
+ if (_this11[_disable_lifecycle_events] == false) {
790
865
  var resourceLifecycleTriggered = new _ResourceLifecycleTriggered.default({
791
866
  data: {
792
867
  data,
793
868
  operation: op,
794
869
  when,
795
870
  old_data,
796
- resource: _this10.type,
797
- ctx: _this10[_ctx]
871
+ resource: _this11.type,
872
+ ctx: _this11[_ctx]
798
873
  }
799
874
  });
800
875
  resourceLifecycleTriggered.dispatch();
801
876
  }
802
877
 
803
- if (_this10[_hooks] && _this10[_hooks][op] && _this10[_hooks][op][when]) {
804
- for (var i of _this10[_hooks][op][when]) {
878
+ if (_this11[_hooks] && _this11[_hooks][op] && _this11[_hooks][op][when]) {
879
+ for (var i of _this11[_hooks][op][when]) {
805
880
  data = yield i(data, old_data);
806
881
  }
807
882
  }
@@ -834,7 +909,7 @@ class SpiceModel {
834
909
  }
835
910
 
836
911
  mapToObject(data, Class, source_property, store_property, property) {
837
- var _this11 = this;
912
+ var _this12 = this;
838
913
 
839
914
  return _asyncToGenerator(function* () {
840
915
  var original_is_array = _.isArray(data);
@@ -863,7 +938,7 @@ class SpiceModel {
863
938
  });
864
939
 
865
940
  var returned_all = yield Promise.allSettled(_.map(classes, obj => {
866
- return new obj(_this11[_args]).getMulti({
941
+ return new obj(_this12[_args]).getMulti({
867
942
  ids: ids
868
943
  });
869
944
  }));
@@ -885,7 +960,7 @@ class SpiceModel {
885
960
  }
886
961
 
887
962
  mapToObjectArray(data, Class, source_property, store_property, property) {
888
- var _this12 = this;
963
+ var _this13 = this;
889
964
 
890
965
  return _asyncToGenerator(function* () {
891
966
  var original_is_array = _.isArray(data);
@@ -914,7 +989,7 @@ class SpiceModel {
914
989
 
915
990
  var classes = _.isArray(Class) ? Class : [Class];
916
991
  var returned_all = yield Promise.allSettled(_.map(classes, obj => {
917
- return new obj(_this12[_args]).getMulti({
992
+ return new obj(_this13[_args]).getMulti({
918
993
  ids: ids
919
994
  });
920
995
  }));
@@ -974,7 +1049,7 @@ class SpiceModel {
974
1049
  }
975
1050
 
976
1051
  createMofifier(properties) {
977
- var _this13 = this;
1052
+ var _this14 = this;
978
1053
 
979
1054
  var _loop = function _loop(i) {
980
1055
  if (properties[i].map) {
@@ -985,11 +1060,11 @@ class SpiceModel {
985
1060
  case String:
986
1061
  case "string":
987
1062
  {
988
- _this13.addModifier({
1063
+ _this14.addModifier({
989
1064
  when: properties[i].map.when || "read",
990
1065
  execute: function () {
991
1066
  var _execute = _asyncToGenerator(function* (data) {
992
- return yield _this13.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]);
1067
+ return yield _this14.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]);
993
1068
  });
994
1069
 
995
1070
  function execute(_x) {
@@ -1006,11 +1081,11 @@ class SpiceModel {
1006
1081
  case Array:
1007
1082
  case "array":
1008
1083
  {
1009
- _this13.addModifier({
1084
+ _this14.addModifier({
1010
1085
  when: properties[i].map.when || "read",
1011
1086
  execute: function () {
1012
1087
  var _execute2 = _asyncToGenerator(function* (data) {
1013
- return yield _this13.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]);
1088
+ return yield _this14.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]);
1014
1089
  });
1015
1090
 
1016
1091
  function execute(_x2) {
@@ -1042,7 +1117,7 @@ class SpiceModel {
1042
1117
  }
1043
1118
 
1044
1119
  do_serialize(data, type, old_data, args, path_to_be_removed) {
1045
- var _this14 = this;
1120
+ var _this15 = this;
1046
1121
 
1047
1122
  return _asyncToGenerator(function* () {
1048
1123
  //console.log("CTX INside Model DO", this[_ctx]);
@@ -1052,16 +1127,16 @@ class SpiceModel {
1052
1127
  path_to_be_removed = [];
1053
1128
  }
1054
1129
 
1055
- if (_this14.shouldSerializerRun(args, type)) {
1056
- if (_this14.type != "" && _this14.type != undefined && _this14[_external_modifier_loaded] != true) {
1057
- _this14.addExternalModifiers(_this14.type);
1130
+ if (_this15.shouldSerializerRun(args, type)) {
1131
+ if (_this15.type != "" && _this15.type != undefined && _this15[_external_modifier_loaded] != true) {
1132
+ _this15.addExternalModifiers(_this15.type);
1058
1133
 
1059
- _this14[_external_modifier_loaded] = true;
1134
+ _this15[_external_modifier_loaded] = true;
1060
1135
  }
1061
1136
 
1062
- for (var i of _this14[_serializers][type]["modifiers"]) {
1137
+ for (var i of _this15[_serializers][type]["modifiers"]) {
1063
1138
  try {
1064
- data = yield i(data, old_data, _this14[_ctx], _this14.type);
1139
+ data = yield i(data, old_data, _this15[_ctx], _this15.type);
1065
1140
  } catch (e) {
1066
1141
  console.log(e.stack);
1067
1142
  }
@@ -1077,12 +1152,12 @@ class SpiceModel {
1077
1152
 
1078
1153
  var defaults = {};
1079
1154
 
1080
- for (var _i in _this14.props) {
1081
- if (_this14.props[_i].defaults != undefined && _this14.props[_i].defaults[type] != undefined && _this14.props[_i].defaults[type] != undefined) {
1082
- defaults[_i] = _.isFunction(_this14.props[_i].defaults[type]) ? _this14.props[_i].defaults[type]({
1155
+ for (var _i in _this15.props) {
1156
+ if (_this15.props[_i].defaults != undefined && _this15.props[_i].defaults[type] != undefined && _this15.props[_i].defaults[type] != undefined) {
1157
+ defaults[_i] = _.isFunction(_this15.props[_i].defaults[type]) ? _this15.props[_i].defaults[type]({
1083
1158
  old_data: data,
1084
1159
  new_data: old_data
1085
- }) : _this14.props[_i].defaults[type];
1160
+ }) : _this15.props[_i].defaults[type];
1086
1161
  }
1087
1162
  } // apply defaults
1088
1163
 
@@ -1095,8 +1170,8 @@ class SpiceModel {
1095
1170
  if (type == "read") {
1096
1171
  var props_to_clean = ["deleted", "type", ...path_to_be_removed];
1097
1172
 
1098
- for (var _i3 in _this14.props) {
1099
- if (_this14.props[_i3].hide) {
1173
+ for (var _i3 in _this15.props) {
1174
+ if (_this15.props[_i3].hide) {
1100
1175
  props_to_clean.push(_i3);
1101
1176
  }
1102
1177
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spice-js",
3
- "version": "2.5.37",
3
+ "version": "2.6.0",
4
4
  "description": "spice",
5
5
  "main": "build/index.js",
6
6
  "repository": {
@@ -32,6 +32,7 @@
32
32
  "koa-views": "^6.2.3",
33
33
  "koa2-swagger-ui": "^5.5.1",
34
34
  "lodash": "^4.17.15",
35
+ "node-cache": "^5.1.2",
35
36
  "nunjucks": "^3.2.0",
36
37
  "open": "7.0.0",
37
38
  "parse-comments": "^1.0.0",
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ async function connect() {
4
+ try {
5
+ spice.cache_providers = {};
6
+ for (let key of Object.keys(spice.config.cache.providers)) {
7
+ spice.cache_providers[key] = new spice.config.cache.providers[key](
8
+ spice.config.cache.drivers[key] || {}
9
+ );
10
+ await spice.cache_providers[key].initialize();
11
+ }
12
+ } catch (e) {
13
+ console.log(e.stack);
14
+ throw e;
15
+ }
16
+ }
17
+ module.exports = connect;