spice-js 2.5.38 → 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.
- package/build/bootstrap/{error copy.js → cache.js} +16 -18
- package/build/bootstrap/map.js +1 -1
- package/build/cache/Cache.js +1 -0
- package/build/cache/providers/SpiceCache.js +78 -0
- package/build/config/cache.js +3 -0
- package/build/index.js +5 -1
- package/build/models/SpiceModel.js +199 -110
- package/package.json +2 -1
- package/src/bootstrap/cache.js +17 -0
- package/src/bootstrap/map.js +2 -2
- package/src/cache/Cache.js +0 -0
- package/src/cache/providers/SpiceCache.js +30 -0
- package/src/config/cache.js +3 -0
- package/src/index.js +1 -0
- package/src/models/SpiceModel.js +159 -21
- package/build/bootstrap/agenda.js +0 -36
- package/build/events/Stage.js +0 -24
- package/build/events/index.js +0 -12
- package/build/events/providers/SpiceEventDriver copy.js +0 -23
- package/build/storage/providers/File.js +0 -53
- package/build/utility/DataType copy.js +0 -28
- package/build/validators/UserGroup.js +0 -44
- package/build/validators/Utility.js +0 -17
|
@@ -58,8 +58,7 @@ class SpiceModel {
|
|
|
58
58
|
var Database = require("spice-" + dbtype);
|
|
59
59
|
|
|
60
60
|
this.type = "";
|
|
61
|
-
this.collection = args.connection;
|
|
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
|
-
|
|
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
|
|
460
|
-
var
|
|
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 !=
|
|
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 !=
|
|
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
|
|
472
|
-
results = yield
|
|
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(
|
|
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
|
|
516
|
+
var _this4 = this;
|
|
486
517
|
|
|
487
518
|
return _asyncToGenerator(function* () {
|
|
488
519
|
try {
|
|
489
|
-
var results = yield
|
|
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
|
|
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
|
|
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
|
-
|
|
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 !=
|
|
561
|
+
_.remove(results, o => o.type != _this5.type);
|
|
517
562
|
|
|
518
|
-
yield
|
|
519
|
-
results = yield
|
|
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
|
|
574
|
+
var _this6 = this;
|
|
530
575
|
|
|
531
576
|
return _asyncToGenerator(function* () {
|
|
532
577
|
try {
|
|
533
578
|
if (_.isString(data)) {
|
|
534
|
-
var result = yield
|
|
535
|
-
if (result.type) if (result.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 !=
|
|
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 !=
|
|
587
|
+
if (data.type) if (data.type != _this6.type) {
|
|
543
588
|
return false;
|
|
544
589
|
}
|
|
545
|
-
if (data._type) if (data._type !=
|
|
590
|
+
if (data._type) if (data._type != _this6.type) {
|
|
546
591
|
return false;
|
|
547
592
|
}
|
|
548
593
|
}
|
|
@@ -555,56 +600,52 @@ class SpiceModel {
|
|
|
555
600
|
}
|
|
556
601
|
|
|
557
602
|
update(args) {
|
|
558
|
-
var
|
|
603
|
+
var _this7 = this;
|
|
559
604
|
|
|
560
605
|
return _asyncToGenerator(function* () {
|
|
561
606
|
try {
|
|
562
|
-
|
|
563
|
-
var results = yield
|
|
564
|
-
|
|
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(
|
|
612
|
+
throw new Error(_this7.type + " does not exist. in update");
|
|
570
613
|
}
|
|
571
614
|
|
|
572
615
|
delete results["id"];
|
|
573
616
|
|
|
574
|
-
_.defaults(
|
|
617
|
+
_.defaults(_this7, results);
|
|
575
618
|
|
|
576
619
|
var cover_obj = {
|
|
577
620
|
old: results,
|
|
578
|
-
new:
|
|
621
|
+
new: _this7,
|
|
579
622
|
id: args.id
|
|
580
623
|
};
|
|
581
624
|
|
|
582
625
|
if (args.skip_hooks != true) {
|
|
583
|
-
yield
|
|
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
|
|
632
|
+
form = yield _this7.do_serialize(_this7, "write", cover_obj.new, args);
|
|
590
633
|
}
|
|
591
634
|
|
|
592
|
-
var db_data = form ||
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
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);
|
|
596
637
|
|
|
597
638
|
if (args.skip_hooks != true) {
|
|
598
|
-
yield
|
|
639
|
+
yield _this7.run_hook(_extends({}, _this7, {
|
|
599
640
|
id: args.id
|
|
600
641
|
}), "update", "after", results);
|
|
601
642
|
}
|
|
602
643
|
|
|
603
644
|
if (args.skip_read_serialize != true && args.skip_serialize != true) {
|
|
604
|
-
form = yield
|
|
645
|
+
form = yield _this7.do_serialize(form, "read", {}, args, (yield _this7.propsToBeRemoved(form)));
|
|
605
646
|
}
|
|
606
647
|
|
|
607
|
-
|
|
648
|
+
_this7.id = args.id;
|
|
608
649
|
return _extends({}, form, {
|
|
609
650
|
id: args.id
|
|
610
651
|
});
|
|
@@ -616,35 +657,35 @@ class SpiceModel {
|
|
|
616
657
|
}
|
|
617
658
|
|
|
618
659
|
create(args) {
|
|
619
|
-
var
|
|
660
|
+
var _this8 = this;
|
|
620
661
|
|
|
621
662
|
return _asyncToGenerator(function* () {
|
|
622
663
|
try {
|
|
623
664
|
var form;
|
|
624
|
-
|
|
665
|
+
_this8.created_at = new SDate().now();
|
|
625
666
|
|
|
626
667
|
if (args.body) {
|
|
627
668
|
form = _.defaults({}, args.body);
|
|
628
|
-
form.created_at =
|
|
629
|
-
form.updated_at =
|
|
669
|
+
form.created_at = _this8.created_at;
|
|
670
|
+
form.updated_at = _this8.created_at;
|
|
630
671
|
delete form["bucket"];
|
|
631
672
|
}
|
|
632
673
|
|
|
633
|
-
var workingForm = form ||
|
|
634
|
-
|
|
674
|
+
var workingForm = form || _this8;
|
|
675
|
+
_this8.updated_at = new SDate().now();
|
|
635
676
|
var id = args.id_prefix + "-" + UUID.v4();
|
|
636
677
|
|
|
637
678
|
if (args && args.id) {
|
|
638
679
|
id = args.id;
|
|
639
680
|
}
|
|
640
681
|
|
|
641
|
-
yield
|
|
642
|
-
workingForm = yield
|
|
643
|
-
var results = yield
|
|
644
|
-
yield
|
|
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, {
|
|
645
686
|
id
|
|
646
687
|
}), "create", "after");
|
|
647
|
-
results = yield
|
|
688
|
+
results = yield _this8.do_serialize(results, "read", {}, args, (yield _this8.propsToBeRemoved(results)));
|
|
648
689
|
return _extends({}, results, {
|
|
649
690
|
id
|
|
650
691
|
});
|
|
@@ -656,30 +697,30 @@ class SpiceModel {
|
|
|
656
697
|
}
|
|
657
698
|
|
|
658
699
|
delete(args) {
|
|
659
|
-
var
|
|
700
|
+
var _this9 = this;
|
|
660
701
|
|
|
661
702
|
return _asyncToGenerator(function* () {
|
|
662
|
-
var item_exist = yield
|
|
703
|
+
var item_exist = yield _this9.exist(args.id);
|
|
663
704
|
|
|
664
705
|
if (!item_exist) {
|
|
665
|
-
throw new Error(
|
|
706
|
+
throw new Error(_this9.type + " does not exist.");
|
|
666
707
|
}
|
|
667
708
|
|
|
668
|
-
var results = yield
|
|
709
|
+
var results = yield _this9.database.get(args.id);
|
|
669
710
|
|
|
670
711
|
try {
|
|
671
|
-
yield
|
|
712
|
+
yield _this9.run_hook(args, "delete", "before");
|
|
672
713
|
var delete_response = {};
|
|
673
714
|
|
|
674
715
|
if (args.hard) {
|
|
675
|
-
delete_response = yield
|
|
716
|
+
delete_response = yield _this9.database.delete(args.id);
|
|
676
717
|
} else {
|
|
677
718
|
delete results["id"];
|
|
678
719
|
results.deleted = true;
|
|
679
|
-
delete_response = yield
|
|
720
|
+
delete_response = yield _this9.database.update(args.id, "");
|
|
680
721
|
}
|
|
681
722
|
|
|
682
|
-
yield
|
|
723
|
+
yield _this9.run_hook(results, "delete", "after", results);
|
|
683
724
|
return {};
|
|
684
725
|
} catch (e) {
|
|
685
726
|
console.log(e.stack);
|
|
@@ -693,7 +734,7 @@ class SpiceModel {
|
|
|
693
734
|
}
|
|
694
735
|
|
|
695
736
|
list(args) {
|
|
696
|
-
var
|
|
737
|
+
var _this10 = this;
|
|
697
738
|
|
|
698
739
|
return _asyncToGenerator(function* () {
|
|
699
740
|
try {
|
|
@@ -707,7 +748,7 @@ class SpiceModel {
|
|
|
707
748
|
query = args.query;
|
|
708
749
|
} else {
|
|
709
750
|
if (args.filters) {
|
|
710
|
-
query =
|
|
751
|
+
query = _this10.makeQueryFromFilter(args.filters);
|
|
711
752
|
} else {
|
|
712
753
|
if (args.query) {
|
|
713
754
|
query = args.query + " AND (deleted = false OR deleted IS MISSING) ";
|
|
@@ -729,22 +770,70 @@ class SpiceModel {
|
|
|
729
770
|
args.sort = "created_at DESC";
|
|
730
771
|
}
|
|
731
772
|
|
|
732
|
-
yield
|
|
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);
|
|
733
780
|
var results;
|
|
734
781
|
|
|
735
782
|
if (args.is_custom_query && args.is_custom_query === "true") {
|
|
736
|
-
|
|
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
|
+
}
|
|
737
798
|
} else {
|
|
738
799
|
if (args.is_full_text && args.is_full_text === "true") {
|
|
739
|
-
|
|
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
|
+
}
|
|
740
813
|
} else {
|
|
741
|
-
|
|
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
|
+
}
|
|
742
831
|
}
|
|
743
832
|
}
|
|
744
833
|
|
|
745
834
|
try {
|
|
746
|
-
yield
|
|
747
|
-
results.data = yield
|
|
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)));
|
|
748
837
|
} catch (e) {
|
|
749
838
|
console.log(e);
|
|
750
839
|
}
|
|
@@ -768,26 +857,26 @@ class SpiceModel {
|
|
|
768
857
|
}
|
|
769
858
|
|
|
770
859
|
run_hook(data, op, when, old_data) {
|
|
771
|
-
var
|
|
860
|
+
var _this11 = this;
|
|
772
861
|
|
|
773
862
|
return _asyncToGenerator(function* () {
|
|
774
863
|
try {
|
|
775
|
-
if (
|
|
864
|
+
if (_this11[_disable_lifecycle_events] == false) {
|
|
776
865
|
var resourceLifecycleTriggered = new _ResourceLifecycleTriggered.default({
|
|
777
866
|
data: {
|
|
778
867
|
data,
|
|
779
868
|
operation: op,
|
|
780
869
|
when,
|
|
781
870
|
old_data,
|
|
782
|
-
resource:
|
|
783
|
-
ctx:
|
|
871
|
+
resource: _this11.type,
|
|
872
|
+
ctx: _this11[_ctx]
|
|
784
873
|
}
|
|
785
874
|
});
|
|
786
875
|
resourceLifecycleTriggered.dispatch();
|
|
787
876
|
}
|
|
788
877
|
|
|
789
|
-
if (
|
|
790
|
-
for (var i of
|
|
878
|
+
if (_this11[_hooks] && _this11[_hooks][op] && _this11[_hooks][op][when]) {
|
|
879
|
+
for (var i of _this11[_hooks][op][when]) {
|
|
791
880
|
data = yield i(data, old_data);
|
|
792
881
|
}
|
|
793
882
|
}
|
|
@@ -820,7 +909,7 @@ class SpiceModel {
|
|
|
820
909
|
}
|
|
821
910
|
|
|
822
911
|
mapToObject(data, Class, source_property, store_property, property) {
|
|
823
|
-
var
|
|
912
|
+
var _this12 = this;
|
|
824
913
|
|
|
825
914
|
return _asyncToGenerator(function* () {
|
|
826
915
|
var original_is_array = _.isArray(data);
|
|
@@ -849,7 +938,7 @@ class SpiceModel {
|
|
|
849
938
|
});
|
|
850
939
|
|
|
851
940
|
var returned_all = yield Promise.allSettled(_.map(classes, obj => {
|
|
852
|
-
return new obj(
|
|
941
|
+
return new obj(_this12[_args]).getMulti({
|
|
853
942
|
ids: ids
|
|
854
943
|
});
|
|
855
944
|
}));
|
|
@@ -871,7 +960,7 @@ class SpiceModel {
|
|
|
871
960
|
}
|
|
872
961
|
|
|
873
962
|
mapToObjectArray(data, Class, source_property, store_property, property) {
|
|
874
|
-
var
|
|
963
|
+
var _this13 = this;
|
|
875
964
|
|
|
876
965
|
return _asyncToGenerator(function* () {
|
|
877
966
|
var original_is_array = _.isArray(data);
|
|
@@ -900,7 +989,7 @@ class SpiceModel {
|
|
|
900
989
|
|
|
901
990
|
var classes = _.isArray(Class) ? Class : [Class];
|
|
902
991
|
var returned_all = yield Promise.allSettled(_.map(classes, obj => {
|
|
903
|
-
return new obj(
|
|
992
|
+
return new obj(_this13[_args]).getMulti({
|
|
904
993
|
ids: ids
|
|
905
994
|
});
|
|
906
995
|
}));
|
|
@@ -960,7 +1049,7 @@ class SpiceModel {
|
|
|
960
1049
|
}
|
|
961
1050
|
|
|
962
1051
|
createMofifier(properties) {
|
|
963
|
-
var
|
|
1052
|
+
var _this14 = this;
|
|
964
1053
|
|
|
965
1054
|
var _loop = function _loop(i) {
|
|
966
1055
|
if (properties[i].map) {
|
|
@@ -971,11 +1060,11 @@ class SpiceModel {
|
|
|
971
1060
|
case String:
|
|
972
1061
|
case "string":
|
|
973
1062
|
{
|
|
974
|
-
|
|
1063
|
+
_this14.addModifier({
|
|
975
1064
|
when: properties[i].map.when || "read",
|
|
976
1065
|
execute: function () {
|
|
977
1066
|
var _execute = _asyncToGenerator(function* (data) {
|
|
978
|
-
return yield
|
|
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]);
|
|
979
1068
|
});
|
|
980
1069
|
|
|
981
1070
|
function execute(_x) {
|
|
@@ -992,11 +1081,11 @@ class SpiceModel {
|
|
|
992
1081
|
case Array:
|
|
993
1082
|
case "array":
|
|
994
1083
|
{
|
|
995
|
-
|
|
1084
|
+
_this14.addModifier({
|
|
996
1085
|
when: properties[i].map.when || "read",
|
|
997
1086
|
execute: function () {
|
|
998
1087
|
var _execute2 = _asyncToGenerator(function* (data) {
|
|
999
|
-
return yield
|
|
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]);
|
|
1000
1089
|
});
|
|
1001
1090
|
|
|
1002
1091
|
function execute(_x2) {
|
|
@@ -1028,7 +1117,7 @@ class SpiceModel {
|
|
|
1028
1117
|
}
|
|
1029
1118
|
|
|
1030
1119
|
do_serialize(data, type, old_data, args, path_to_be_removed) {
|
|
1031
|
-
var
|
|
1120
|
+
var _this15 = this;
|
|
1032
1121
|
|
|
1033
1122
|
return _asyncToGenerator(function* () {
|
|
1034
1123
|
//console.log("CTX INside Model DO", this[_ctx]);
|
|
@@ -1038,16 +1127,16 @@ class SpiceModel {
|
|
|
1038
1127
|
path_to_be_removed = [];
|
|
1039
1128
|
}
|
|
1040
1129
|
|
|
1041
|
-
if (
|
|
1042
|
-
if (
|
|
1043
|
-
|
|
1130
|
+
if (_this15.shouldSerializerRun(args, type)) {
|
|
1131
|
+
if (_this15.type != "" && _this15.type != undefined && _this15[_external_modifier_loaded] != true) {
|
|
1132
|
+
_this15.addExternalModifiers(_this15.type);
|
|
1044
1133
|
|
|
1045
|
-
|
|
1134
|
+
_this15[_external_modifier_loaded] = true;
|
|
1046
1135
|
}
|
|
1047
1136
|
|
|
1048
|
-
for (var i of
|
|
1137
|
+
for (var i of _this15[_serializers][type]["modifiers"]) {
|
|
1049
1138
|
try {
|
|
1050
|
-
data = yield i(data, old_data,
|
|
1139
|
+
data = yield i(data, old_data, _this15[_ctx], _this15.type);
|
|
1051
1140
|
} catch (e) {
|
|
1052
1141
|
console.log(e.stack);
|
|
1053
1142
|
}
|
|
@@ -1063,12 +1152,12 @@ class SpiceModel {
|
|
|
1063
1152
|
|
|
1064
1153
|
var defaults = {};
|
|
1065
1154
|
|
|
1066
|
-
for (var _i in
|
|
1067
|
-
if (
|
|
1068
|
-
defaults[_i] = _.isFunction(
|
|
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]({
|
|
1069
1158
|
old_data: data,
|
|
1070
1159
|
new_data: old_data
|
|
1071
|
-
}) :
|
|
1160
|
+
}) : _this15.props[_i].defaults[type];
|
|
1072
1161
|
}
|
|
1073
1162
|
} // apply defaults
|
|
1074
1163
|
|
|
@@ -1081,8 +1170,8 @@ class SpiceModel {
|
|
|
1081
1170
|
if (type == "read") {
|
|
1082
1171
|
var props_to_clean = ["deleted", "type", ...path_to_be_removed];
|
|
1083
1172
|
|
|
1084
|
-
for (var _i3 in
|
|
1085
|
-
if (
|
|
1173
|
+
for (var _i3 in _this15.props) {
|
|
1174
|
+
if (_this15.props[_i3].hide) {
|
|
1086
1175
|
props_to_clean.push(_i3);
|
|
1087
1176
|
}
|
|
1088
1177
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "spice-js",
|
|
3
|
-
"version": "2.
|
|
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;
|
package/src/bootstrap/map.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import _ from "lodash";
|
|
3
3
|
try {
|
|
4
|
-
let resources = ["models", "controllers", "schemas"];
|
|
4
|
+
let resources = ["models", "controllers", "schemas", "cache"];
|
|
5
5
|
_.each(resources, async function (resource) {
|
|
6
6
|
let paths = path.join(spice.root_path, resource);
|
|
7
7
|
spice[resource] = {};
|
|
@@ -16,7 +16,7 @@ try {
|
|
|
16
16
|
if (resource == "models") {
|
|
17
17
|
new spice[resource][file_name]({});
|
|
18
18
|
}
|
|
19
|
-
}
|
|
19
|
+
}
|
|
20
20
|
});
|
|
21
21
|
} catch (error) {
|
|
22
22
|
console.log("Error Happened", error);
|
|
File without changes
|