spice-js 2.5.38 → 2.6.1

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,51 @@ 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
+ shouldForceRefresh(response) {
459
+ var monitor_record = _.get(spice.monitor, this.type);
460
+
461
+ if (monitor_record == undefined) {
462
+ return false;
463
+ }
464
+
465
+ if (monitor_record > (response == null ? void 0 : response.time)) {
466
+ return true;
467
+ }
468
+
469
+ return false;
470
+ }
471
+
472
+ setMonitor() {
473
+ var current_time = new Date().getTime();
474
+ spice.monitor[this.type] = current_time; //console.log("Monitor Set", spice.monitor);
475
+ }
476
+
477
+ get(args) {
478
+ var _this3 = this;
479
+
452
480
  return _asyncToGenerator(function* () {
453
481
  try {
454
482
  if (!args) {
@@ -456,23 +484,39 @@ class SpiceModel {
456
484
  }
457
485
 
458
486
  if (_.isString(args.id)) {
459
- yield _this2.run_hook(args, "get", "before");
460
- var results = yield _this2.database.get(args.id);
487
+ yield _this3.run_hook(args, "get", "before");
488
+ var key = _this3.type + "::" + args.id;
489
+ var results = {};
490
+
491
+ if (_this3.shouldCache(_this3.type)) {
492
+ var cached_results = yield _this3.getCacheProviderObject(_this3.type).get(key);
493
+ results = cached_results == null ? void 0 : cached_results.value;
494
+
495
+ if ((cached_results == null ? void 0 : cached_results.value) == undefined || _this3.shouldForceRefresh(cached_results)) {
496
+ results = yield _this3.database.get(args.id);
497
+ yield _this3.getCacheProviderObject(_this3.type).set(key, {
498
+ value: results,
499
+ time: new Date().getTime()
500
+ }, _this3.getCacheConfig(_this3.type));
501
+ }
502
+ } else {
503
+ results = yield _this3.database.get(args.id);
504
+ }
461
505
 
462
506
  if (results.type != undefined) {
463
- if (results.type != _this2.type) throw new Error(_this2.type + " does not exist type");
507
+ if (results.type != _this3.type) throw new Error(_this3.type + " does not exist type");
464
508
  }
465
509
 
466
510
  if (results._type != undefined) {
467
- if (results._type != _this2.type) throw new Error(_this2.type + " does not exist _type");
511
+ if (results._type != _this3.type) throw new Error(_this3.type + " does not exist _type");
468
512
  }
469
513
 
470
514
  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)));
515
+ yield _this3.run_hook(results, "get", "after");
516
+ results = yield _this3.do_serialize(results, "read", {}, args, (yield _this3.propsToBeRemoved(results)));
473
517
  return results;
474
518
  } else {
475
- throw new Error(_this2.type + " does not exist");
519
+ throw new Error(_this3.type + " does not exist");
476
520
  }
477
521
  }
478
522
  } catch (e) {
@@ -482,11 +526,11 @@ class SpiceModel {
482
526
  }
483
527
 
484
528
  query(query, scope) {
485
- var _this3 = this;
529
+ var _this4 = this;
486
530
 
487
531
  return _asyncToGenerator(function* () {
488
532
  try {
489
- var results = yield _this3.database.query(query, scope);
533
+ var results = yield _this4.database.query(query, scope);
490
534
  return results;
491
535
  } catch (error) {
492
536
  throw error;
@@ -495,7 +539,7 @@ class SpiceModel {
495
539
  }
496
540
 
497
541
  getMulti(args) {
498
- var _this4 = this;
542
+ var _this5 = this;
499
543
 
500
544
  return _asyncToGenerator(function* () {
501
545
  try {
@@ -503,20 +547,36 @@ class SpiceModel {
503
547
  args = {};
504
548
  }
505
549
 
506
- yield _this4.run_hook(_this4, "list", "before");
550
+ yield _this5.run_hook(_this5, "list", "before");
507
551
 
508
552
  _.remove(args.ids, o => o == undefined);
509
553
 
554
+ var key = _this5.type + "::" + _.join(args.ids, "|");
555
+
510
556
  var results = [];
511
557
 
512
558
  if (args.ids.length > 0) {
513
- results = yield _this4.database.multi_get(args.ids, true);
559
+ if (_this5.shouldCache(_this5.type)) {
560
+ var cached_results = yield _this5.getCacheProviderObject(_this5.type).get(key);
561
+ results = cached_results == null ? void 0 : cached_results.value;
562
+
563
+ if ((cached_results == null ? void 0 : cached_results.value) == undefined || _this5.shouldForceRefresh(cached_results)) {
564
+ results = yield _this5.database.multi_get(args.ids, true);
565
+
566
+ _this5.getCacheProviderObject(_this5.type).set(key, {
567
+ value: results,
568
+ time: new Date().getTime()
569
+ }, _this5.getCacheConfig(_this5.type));
570
+ }
571
+ } else {
572
+ results = yield _this5.database.multi_get(args.ids, true);
573
+ }
514
574
  }
515
575
 
516
- _.remove(results, o => o.type != _this4.type);
576
+ _.remove(results, o => o.type != _this5.type);
517
577
 
518
- yield _this4.run_hook(results, "list", "after", args.context);
519
- results = yield _this4.do_serialize(results, "read", {}, args, (yield _this4.propsToBeRemoved(results)));
578
+ yield _this5.run_hook(results, "list", "after", args.context);
579
+ results = yield _this5.do_serialize(results, "read", {}, args, (yield _this5.propsToBeRemoved(results)));
520
580
  return results;
521
581
  } catch (e) {
522
582
  console.log(e.stack);
@@ -526,23 +586,23 @@ class SpiceModel {
526
586
  }
527
587
 
528
588
  exist(data) {
529
- var _this5 = this;
589
+ var _this6 = this;
530
590
 
531
591
  return _asyncToGenerator(function* () {
532
592
  try {
533
593
  if (_.isString(data)) {
534
- var result = yield _this5.database.get(data);
535
- if (result.type) if (result.type != _this5.type) {
594
+ var result = yield _this6.database.get(data);
595
+ if (result.type) if (result.type != _this6.type) {
536
596
  return false;
537
597
  }
538
- if (result._type) if (result._type != _this5.type) {
598
+ if (result._type) if (result._type != _this6.type) {
539
599
  return false;
540
600
  }
541
601
  } else {
542
- if (data.type) if (data.type != _this5.type) {
602
+ if (data.type) if (data.type != _this6.type) {
543
603
  return false;
544
604
  }
545
- if (data._type) if (data._type != _this5.type) {
605
+ if (data._type) if (data._type != _this6.type) {
546
606
  return false;
547
607
  }
548
608
  }
@@ -555,56 +615,54 @@ class SpiceModel {
555
615
  }
556
616
 
557
617
  update(args) {
558
- var _this6 = this;
618
+ var _this7 = this;
559
619
 
560
620
  return _asyncToGenerator(function* () {
561
621
  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);
622
+ _this7.updated_at = new SDate().now();
623
+ var results = yield _this7.database.get(args.id);
624
+ var item_exist = yield _this7.exist(results);
567
625
 
568
626
  if (!item_exist) {
569
- throw new Error(_this6.type + " does not exist. in update");
627
+ throw new Error(_this7.type + " does not exist. in update");
570
628
  }
571
629
 
572
630
  delete results["id"];
573
631
 
574
- _.defaults(_this6, results);
632
+ _.defaults(_this7, results);
575
633
 
576
634
  var cover_obj = {
577
635
  old: results,
578
- new: _this6,
636
+ new: _this7,
579
637
  id: args.id
580
638
  };
581
639
 
582
640
  if (args.skip_hooks != true) {
583
- yield _this6.run_hook(cover_obj, "update", "before", results);
641
+ yield _this7.run_hook(cover_obj, "update", "before", results);
584
642
  }
585
643
 
586
644
  var form;
587
645
 
588
646
  if (args.skip_write_serialize != true && args.skip_serialize != true) {
589
- form = yield _this6.do_serialize(_this6, "write", cover_obj.new, args);
647
+ form = yield _this7.do_serialize(_this7, "write", cover_obj.new, args);
590
648
  }
591
649
 
592
- var db_data = form || _this6; //console.log("New Data Inside Update::::", db_data);
593
- // console.log("After ITF::::", db_data);
650
+ var db_data = form || _this7;
651
+ yield _this7.database.update(args.id, db_data);
594
652
 
595
- yield _this6.database.update(args.id, db_data); //console.log("Old Data Inside Update::::", results);
653
+ _this7.setMonitor();
596
654
 
597
655
  if (args.skip_hooks != true) {
598
- yield _this6.run_hook(_extends({}, _this6, {
656
+ yield _this7.run_hook(_extends({}, _this7, {
599
657
  id: args.id
600
658
  }), "update", "after", results);
601
659
  }
602
660
 
603
661
  if (args.skip_read_serialize != true && args.skip_serialize != true) {
604
- form = yield _this6.do_serialize(form, "read", {}, args, (yield _this6.propsToBeRemoved(form)));
662
+ form = yield _this7.do_serialize(form, "read", {}, args, (yield _this7.propsToBeRemoved(form)));
605
663
  }
606
664
 
607
- _this6.id = args.id;
665
+ _this7.id = args.id;
608
666
  return _extends({}, form, {
609
667
  id: args.id
610
668
  });
@@ -616,35 +674,38 @@ class SpiceModel {
616
674
  }
617
675
 
618
676
  create(args) {
619
- var _this7 = this;
677
+ var _this8 = this;
620
678
 
621
679
  return _asyncToGenerator(function* () {
622
680
  try {
623
681
  var form;
624
- _this7.created_at = new SDate().now();
682
+ _this8.created_at = new SDate().now();
625
683
 
626
684
  if (args.body) {
627
685
  form = _.defaults({}, args.body);
628
- form.created_at = _this7.created_at;
629
- form.updated_at = _this7.created_at;
686
+ form.created_at = _this8.created_at;
687
+ form.updated_at = _this8.created_at;
630
688
  delete form["bucket"];
631
689
  }
632
690
 
633
- var workingForm = form || _this7;
634
- _this7.updated_at = new SDate().now();
691
+ var workingForm = form || _this8;
692
+ _this8.updated_at = new SDate().now();
635
693
  var id = args.id_prefix + "-" + UUID.v4();
636
694
 
637
695
  if (args && args.id) {
638
696
  id = args.id;
639
697
  }
640
698
 
641
- yield _this7.run_hook(workingForm, "create", "before");
642
- workingForm = yield _this7.do_serialize(workingForm, "write", {}, args);
643
- var results = yield _this7.database.insert(id, workingForm, args.expiry);
644
- yield _this7.run_hook(_extends({}, results, {
699
+ yield _this8.run_hook(workingForm, "create", "before");
700
+ workingForm = yield _this8.do_serialize(workingForm, "write", {}, args);
701
+ var results = yield _this8.database.insert(id, workingForm, args.expiry);
702
+
703
+ _this8.setMonitor();
704
+
705
+ yield _this8.run_hook(_extends({}, results, {
645
706
  id
646
707
  }), "create", "after");
647
- results = yield _this7.do_serialize(results, "read", {}, args, (yield _this7.propsToBeRemoved(results)));
708
+ results = yield _this8.do_serialize(results, "read", {}, args, (yield _this8.propsToBeRemoved(results)));
648
709
  return _extends({}, results, {
649
710
  id
650
711
  });
@@ -656,30 +717,32 @@ class SpiceModel {
656
717
  }
657
718
 
658
719
  delete(args) {
659
- var _this8 = this;
720
+ var _this9 = this;
660
721
 
661
722
  return _asyncToGenerator(function* () {
662
- var item_exist = yield _this8.exist(args.id);
723
+ var item_exist = yield _this9.exist(args.id);
663
724
 
664
725
  if (!item_exist) {
665
- throw new Error(_this8.type + " does not exist.");
726
+ throw new Error(_this9.type + " does not exist.");
666
727
  }
667
728
 
668
- var results = yield _this8.database.get(args.id);
729
+ var results = yield _this9.database.get(args.id);
669
730
 
670
731
  try {
671
- yield _this8.run_hook(args, "delete", "before");
732
+ yield _this9.run_hook(args, "delete", "before");
672
733
  var delete_response = {};
673
734
 
674
735
  if (args.hard) {
675
- delete_response = yield _this8.database.delete(args.id);
736
+ delete_response = yield _this9.database.delete(args.id);
737
+
738
+ _this9.setMonitor();
676
739
  } else {
677
740
  delete results["id"];
678
741
  results.deleted = true;
679
- delete_response = yield _this8.database.update(args.id, "");
742
+ delete_response = yield _this9.database.update(args.id, "");
680
743
  }
681
744
 
682
- yield _this8.run_hook(results, "delete", "after", results);
745
+ yield _this9.run_hook(results, "delete", "after", results);
683
746
  return {};
684
747
  } catch (e) {
685
748
  console.log(e.stack);
@@ -693,7 +756,7 @@ class SpiceModel {
693
756
  }
694
757
 
695
758
  list(args) {
696
- var _this9 = this;
759
+ var _this10 = this;
697
760
 
698
761
  return _asyncToGenerator(function* () {
699
762
  try {
@@ -707,7 +770,7 @@ class SpiceModel {
707
770
  query = args.query;
708
771
  } else {
709
772
  if (args.filters) {
710
- query = yield _this9.makeQueryFromFilter(args.filters);
773
+ query = _this10.makeQueryFromFilter(args.filters);
711
774
  } else {
712
775
  if (args.query) {
713
776
  query = args.query + " AND (deleted = false OR deleted IS MISSING) ";
@@ -729,22 +792,78 @@ class SpiceModel {
729
792
  args.sort = "created_at DESC";
730
793
  }
731
794
 
732
- yield _this9.run_hook(_this9, "list", "before");
795
+ yield _this10.run_hook(_this10, "list", "before");
796
+
797
+ function removeSpaceAndSpecialCharacters(str) {
798
+ return str.replace(/[^a-zA-Z0-9]/g, "");
799
+ }
800
+
801
+ 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);
733
802
  var results;
734
803
 
735
804
  if (args.is_custom_query && args.is_custom_query === "true") {
736
- results = yield _this9.database.query(query);
805
+ if (args.ids.length > 0) {
806
+ if (_this10.shouldCache(_this10.type)) {
807
+ var cached_results = yield _this10.getCacheProviderObject(_this10.type).get(key);
808
+ results = cached_results == null ? void 0 : cached_results.value;
809
+
810
+ if ((cached_results == null ? void 0 : cached_results.value) == undefined || _this10.shouldForceRefresh(cached_results)) {
811
+ results = yield _this10.database.query(query);
812
+
813
+ _this10.getCacheProviderObject(_this10.type).set(key, {
814
+ value: results,
815
+ time: new Date().getTime()
816
+ }, _this10.getCacheConfig(_this10.type));
817
+ }
818
+ } else {
819
+ results = yield _this10.database.query(query);
820
+ }
821
+ }
737
822
  } else {
738
823
  if (args.is_full_text && args.is_full_text === "true") {
739
- results = yield _this9.database.full_text_search(_this9.type, query || "", args.limit, args.offset);
824
+ if (_this10.shouldCache(_this10.type)) {
825
+ var _cached_results = yield _this10.getCacheProviderObject(_this10.type).get(key);
826
+
827
+ results = _cached_results == null ? void 0 : _cached_results.value;
828
+
829
+ if ((_cached_results == null ? void 0 : _cached_results.value) == undefined || _this10.shouldForceRefresh(_cached_results)) {
830
+ results = yield _this10.database.full_text_search(_this10.type, query || "", args.limit, args.offset);
831
+
832
+ _this10.getCacheProviderObject(_this10.type).set(key, {
833
+ value: results,
834
+ time: new Date().getTime()
835
+ }, _this10.getCacheConfig(_this10.type));
836
+ }
837
+ } else {
838
+ results = yield _this10.database.full_text_search(_this10.type, query || "", args.limit, args.offset);
839
+ }
740
840
  } else {
741
- results = yield _this9.database.search(_this9.type, args.columns || "", query || "", args.limit, args.offset, args.sort, args.do_count, args.statement_consistent);
841
+ if (_this10.shouldCache(_this10.type)) {
842
+ var _cached_results2 = yield _this10.getCacheProviderObject(_this10.type).get(key);
843
+
844
+ results = _cached_results2 == null ? void 0 : _cached_results2.value;
845
+
846
+ if ((_cached_results2 == null ? void 0 : _cached_results2.value) == undefined || _this10.shouldForceRefresh(_cached_results2)) {
847
+ results = yield _this10.database.search(_this10.type, args.columns || "", query || "", args.limit, args.offset, args.sort, args.do_count, args.statement_consistent);
848
+
849
+ _this10.getCacheProviderObject(_this10.type).set(key, {
850
+ value: results,
851
+ time: new Date().getTime()
852
+ }, _this10.getCacheConfig(_this10.type));
853
+ }
854
+ } else {
855
+ results = yield _this10.database.search(_this10.type, args.columns || "", query || "", args.limit, args.offset, args.sort, args.do_count, args.statement_consistent);
856
+
857
+ if (_this10.type == "user") {
858
+ console.log("results from DB No Chache available", results);
859
+ }
860
+ }
742
861
  }
743
862
  }
744
863
 
745
864
  try {
746
- yield _this9.run_hook(results.data, "list", "after");
747
- results.data = yield _this9.do_serialize(results.data, "read", {}, args, (yield _this9.propsToBeRemoved(results.data)));
865
+ yield _this10.run_hook(results.data, "list", "after");
866
+ results.data = yield _this10.do_serialize(results.data, "read", {}, args, (yield _this10.propsToBeRemoved(results.data)));
748
867
  } catch (e) {
749
868
  console.log(e);
750
869
  }
@@ -768,26 +887,26 @@ class SpiceModel {
768
887
  }
769
888
 
770
889
  run_hook(data, op, when, old_data) {
771
- var _this10 = this;
890
+ var _this11 = this;
772
891
 
773
892
  return _asyncToGenerator(function* () {
774
893
  try {
775
- if (_this10[_disable_lifecycle_events] == false) {
894
+ if (_this11[_disable_lifecycle_events] == false) {
776
895
  var resourceLifecycleTriggered = new _ResourceLifecycleTriggered.default({
777
896
  data: {
778
897
  data,
779
898
  operation: op,
780
899
  when,
781
900
  old_data,
782
- resource: _this10.type,
783
- ctx: _this10[_ctx]
901
+ resource: _this11.type,
902
+ ctx: _this11[_ctx]
784
903
  }
785
904
  });
786
905
  resourceLifecycleTriggered.dispatch();
787
906
  }
788
907
 
789
- if (_this10[_hooks] && _this10[_hooks][op] && _this10[_hooks][op][when]) {
790
- for (var i of _this10[_hooks][op][when]) {
908
+ if (_this11[_hooks] && _this11[_hooks][op] && _this11[_hooks][op][when]) {
909
+ for (var i of _this11[_hooks][op][when]) {
791
910
  data = yield i(data, old_data);
792
911
  }
793
912
  }
@@ -820,7 +939,7 @@ class SpiceModel {
820
939
  }
821
940
 
822
941
  mapToObject(data, Class, source_property, store_property, property) {
823
- var _this11 = this;
942
+ var _this12 = this;
824
943
 
825
944
  return _asyncToGenerator(function* () {
826
945
  var original_is_array = _.isArray(data);
@@ -849,7 +968,7 @@ class SpiceModel {
849
968
  });
850
969
 
851
970
  var returned_all = yield Promise.allSettled(_.map(classes, obj => {
852
- return new obj(_this11[_args]).getMulti({
971
+ return new obj(_this12[_args]).getMulti({
853
972
  ids: ids
854
973
  });
855
974
  }));
@@ -871,7 +990,7 @@ class SpiceModel {
871
990
  }
872
991
 
873
992
  mapToObjectArray(data, Class, source_property, store_property, property) {
874
- var _this12 = this;
993
+ var _this13 = this;
875
994
 
876
995
  return _asyncToGenerator(function* () {
877
996
  var original_is_array = _.isArray(data);
@@ -900,7 +1019,7 @@ class SpiceModel {
900
1019
 
901
1020
  var classes = _.isArray(Class) ? Class : [Class];
902
1021
  var returned_all = yield Promise.allSettled(_.map(classes, obj => {
903
- return new obj(_this12[_args]).getMulti({
1022
+ return new obj(_this13[_args]).getMulti({
904
1023
  ids: ids
905
1024
  });
906
1025
  }));
@@ -960,7 +1079,7 @@ class SpiceModel {
960
1079
  }
961
1080
 
962
1081
  createMofifier(properties) {
963
- var _this13 = this;
1082
+ var _this14 = this;
964
1083
 
965
1084
  var _loop = function _loop(i) {
966
1085
  if (properties[i].map) {
@@ -971,11 +1090,11 @@ class SpiceModel {
971
1090
  case String:
972
1091
  case "string":
973
1092
  {
974
- _this13.addModifier({
1093
+ _this14.addModifier({
975
1094
  when: properties[i].map.when || "read",
976
1095
  execute: function () {
977
1096
  var _execute = _asyncToGenerator(function* (data) {
978
- 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]);
1097
+ 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]);
979
1098
  });
980
1099
 
981
1100
  function execute(_x) {
@@ -992,11 +1111,11 @@ class SpiceModel {
992
1111
  case Array:
993
1112
  case "array":
994
1113
  {
995
- _this13.addModifier({
1114
+ _this14.addModifier({
996
1115
  when: properties[i].map.when || "read",
997
1116
  execute: function () {
998
1117
  var _execute2 = _asyncToGenerator(function* (data) {
999
- 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]);
1118
+ 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]);
1000
1119
  });
1001
1120
 
1002
1121
  function execute(_x2) {
@@ -1028,7 +1147,7 @@ class SpiceModel {
1028
1147
  }
1029
1148
 
1030
1149
  do_serialize(data, type, old_data, args, path_to_be_removed) {
1031
- var _this14 = this;
1150
+ var _this15 = this;
1032
1151
 
1033
1152
  return _asyncToGenerator(function* () {
1034
1153
  //console.log("CTX INside Model DO", this[_ctx]);
@@ -1038,16 +1157,16 @@ class SpiceModel {
1038
1157
  path_to_be_removed = [];
1039
1158
  }
1040
1159
 
1041
- if (_this14.shouldSerializerRun(args, type)) {
1042
- if (_this14.type != "" && _this14.type != undefined && _this14[_external_modifier_loaded] != true) {
1043
- _this14.addExternalModifiers(_this14.type);
1160
+ if (_this15.shouldSerializerRun(args, type)) {
1161
+ if (_this15.type != "" && _this15.type != undefined && _this15[_external_modifier_loaded] != true) {
1162
+ _this15.addExternalModifiers(_this15.type);
1044
1163
 
1045
- _this14[_external_modifier_loaded] = true;
1164
+ _this15[_external_modifier_loaded] = true;
1046
1165
  }
1047
1166
 
1048
- for (var i of _this14[_serializers][type]["modifiers"]) {
1167
+ for (var i of _this15[_serializers][type]["modifiers"]) {
1049
1168
  try {
1050
- data = yield i(data, old_data, _this14[_ctx], _this14.type);
1169
+ data = yield i(data, old_data, _this15[_ctx], _this15.type);
1051
1170
  } catch (e) {
1052
1171
  console.log(e.stack);
1053
1172
  }
@@ -1063,12 +1182,12 @@ class SpiceModel {
1063
1182
 
1064
1183
  var defaults = {};
1065
1184
 
1066
- for (var _i in _this14.props) {
1067
- if (_this14.props[_i].defaults != undefined && _this14.props[_i].defaults[type] != undefined && _this14.props[_i].defaults[type] != undefined) {
1068
- defaults[_i] = _.isFunction(_this14.props[_i].defaults[type]) ? _this14.props[_i].defaults[type]({
1185
+ for (var _i in _this15.props) {
1186
+ if (_this15.props[_i].defaults != undefined && _this15.props[_i].defaults[type] != undefined && _this15.props[_i].defaults[type] != undefined) {
1187
+ defaults[_i] = _.isFunction(_this15.props[_i].defaults[type]) ? _this15.props[_i].defaults[type]({
1069
1188
  old_data: data,
1070
1189
  new_data: old_data
1071
- }) : _this14.props[_i].defaults[type];
1190
+ }) : _this15.props[_i].defaults[type];
1072
1191
  }
1073
1192
  } // apply defaults
1074
1193
 
@@ -1081,8 +1200,8 @@ class SpiceModel {
1081
1200
  if (type == "read") {
1082
1201
  var props_to_clean = ["deleted", "type", ...path_to_be_removed];
1083
1202
 
1084
- for (var _i3 in _this14.props) {
1085
- if (_this14.props[_i3].hide) {
1203
+ for (var _i3 in _this15.props) {
1204
+ if (_this15.props[_i3].hide) {
1086
1205
  props_to_clean.push(_i3);
1087
1206
  }
1088
1207
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spice-js",
3
- "version": "2.5.38",
3
+ "version": "2.6.1",
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",