spice-js 2.6.72 → 2.6.73
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/models/SpiceModel.js +457 -348
- package/package.json +1 -1
- package/src/models/SpiceModel.js +109 -70
|
@@ -566,95 +566,112 @@ class SpiceModel {
|
|
|
566
566
|
var _this4 = this;
|
|
567
567
|
|
|
568
568
|
return _asyncToGenerator(function* () {
|
|
569
|
-
var _this4$_ctx
|
|
569
|
+
var _this4$_ctx;
|
|
570
570
|
|
|
571
|
-
// Profiling:
|
|
572
|
-
var p = (_this4$_ctx = _this4[_ctx]) == null ? void 0 : _this4$_ctx.profiler
|
|
573
|
-
c = p == null ? void 0 : p.start(_this4.type + ".get", {
|
|
574
|
-
id: (_args6 = args) == null ? void 0 : _args6.id
|
|
575
|
-
});
|
|
576
|
-
|
|
577
|
-
try {
|
|
578
|
-
if (args.mapping_dept) _this4[_mapping_dept] = args.mapping_dept;
|
|
571
|
+
// Profiling: use track() for proper async context forking
|
|
572
|
+
var p = (_this4$_ctx = _this4[_ctx]) == null ? void 0 : _this4$_ctx.profiler;
|
|
579
573
|
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
574
|
+
var doGet =
|
|
575
|
+
/*#__PURE__*/
|
|
576
|
+
function () {
|
|
577
|
+
var _ref2 = _asyncToGenerator(function* () {
|
|
578
|
+
if (args.mapping_dept) _this4[_mapping_dept] = args.mapping_dept;
|
|
583
579
|
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
yield _this4.run_hook(args, "get", "before");
|
|
580
|
+
if (!args) {
|
|
581
|
+
args = {};
|
|
587
582
|
}
|
|
588
583
|
|
|
589
|
-
|
|
590
|
-
|
|
584
|
+
if (_.isString(args.id)) {
|
|
585
|
+
if (args.skip_hooks !== true) {
|
|
586
|
+
yield _this4.run_hook(args, "get", "before");
|
|
587
|
+
}
|
|
591
588
|
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
var cached_results = yield _this4.getCacheProviderObject(_this4.type).get(key); // Check if the cache is empty
|
|
589
|
+
var key = "get::" + _this4.type + "::" + args.id;
|
|
590
|
+
var results = {};
|
|
595
591
|
|
|
596
|
-
|
|
592
|
+
if (_this4.shouldUseCache(_this4.type)) {
|
|
593
|
+
// Retrieve the cached results
|
|
594
|
+
var cached_results = yield _this4.getCacheProviderObject(_this4.type).get(key); // Check if the cache is empty
|
|
597
595
|
|
|
598
|
-
|
|
596
|
+
var isCacheEmpty = (cached_results == null ? void 0 : cached_results.value) === undefined; // Check if the cached result should be refreshed
|
|
599
597
|
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
598
|
+
var shouldRefresh = yield _this4.shouldForceRefresh(cached_results); // Force a refresh for "workflow" type if needed
|
|
599
|
+
|
|
600
|
+
if (isCacheEmpty || shouldRefresh) {
|
|
601
|
+
// Retrieve from the database and update cache
|
|
602
|
+
if (p) {
|
|
603
|
+
results = yield p.track(_this4.type + ".get.database",
|
|
604
|
+
/*#__PURE__*/
|
|
605
|
+
_asyncToGenerator(function* () {
|
|
606
|
+
return yield _this4.database.get(args.id);
|
|
607
|
+
}));
|
|
608
|
+
} else {
|
|
609
|
+
results = yield _this4.database.get(args.id);
|
|
610
|
+
}
|
|
604
611
|
|
|
605
|
-
|
|
612
|
+
yield _this4.getCacheProviderObject(_this4.type).set(key, {
|
|
613
|
+
value: results,
|
|
614
|
+
time: new Date().getTime()
|
|
615
|
+
}, _this4.getCacheConfig(_this4.type));
|
|
616
|
+
} else {
|
|
617
|
+
// Use the cached value
|
|
618
|
+
results = cached_results.value;
|
|
619
|
+
}
|
|
620
|
+
} else {
|
|
621
|
+
// Directly fetch from the database if caching is disabled
|
|
622
|
+
if (p) {
|
|
623
|
+
results = yield p.track(_this4.type + ".get.database",
|
|
624
|
+
/*#__PURE__*/
|
|
625
|
+
_asyncToGenerator(function* () {
|
|
626
|
+
return yield _this4.database.get(args.id);
|
|
627
|
+
}));
|
|
628
|
+
} else {
|
|
606
629
|
results = yield _this4.database.get(args.id);
|
|
607
|
-
} finally {
|
|
608
|
-
cDb && pDb.end(cDb);
|
|
609
630
|
}
|
|
631
|
+
}
|
|
610
632
|
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
time: new Date().getTime()
|
|
614
|
-
}, _this4.getCacheConfig(_this4.type));
|
|
615
|
-
} else {
|
|
616
|
-
// Use the cached value
|
|
617
|
-
results = cached_results.value;
|
|
633
|
+
if (results.type !== undefined && results.type !== _this4.type) {
|
|
634
|
+
throw new Error(_this4.type + " does not exist type");
|
|
618
635
|
}
|
|
619
|
-
} else {
|
|
620
|
-
// Directly fetch from the database if caching is disabled
|
|
621
|
-
var _pDb = p,
|
|
622
|
-
_cDb = _pDb == null ? void 0 : _pDb.start(_this4.type + ".get.database");
|
|
623
636
|
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
} finally {
|
|
627
|
-
_cDb && _pDb.end(_cDb);
|
|
637
|
+
if (results._type !== undefined && results._type !== _this4.type) {
|
|
638
|
+
throw new Error(_this4.type + " does not exist _type");
|
|
628
639
|
}
|
|
629
|
-
}
|
|
630
640
|
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
641
|
+
if (results.deleted === undefined || results.deleted === false) {
|
|
642
|
+
if (args.skip_read_serialize !== true && args.skip_serialize !== true) {
|
|
643
|
+
results = yield _this4.do_serialize(results, "read", {}, args, (yield _this4.propsToBeRemoved(results)));
|
|
644
|
+
}
|
|
634
645
|
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
646
|
+
if (args.skip_hooks !== true) {
|
|
647
|
+
yield _this4.run_hook(results, "get", "after");
|
|
648
|
+
}
|
|
638
649
|
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
650
|
+
return results;
|
|
651
|
+
} else {
|
|
652
|
+
throw new Error(_this4.type + " does not exist");
|
|
642
653
|
}
|
|
654
|
+
}
|
|
655
|
+
});
|
|
643
656
|
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
657
|
+
return function doGet() {
|
|
658
|
+
return _ref2.apply(this, arguments);
|
|
659
|
+
};
|
|
660
|
+
}();
|
|
647
661
|
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
662
|
+
try {
|
|
663
|
+
if (p) {
|
|
664
|
+
var _args6;
|
|
665
|
+
|
|
666
|
+
return yield p.track(_this4.type + ".get", doGet, {
|
|
667
|
+
id: (_args6 = args) == null ? void 0 : _args6.id
|
|
668
|
+
});
|
|
652
669
|
}
|
|
670
|
+
|
|
671
|
+
return yield doGet();
|
|
653
672
|
} catch (e) {
|
|
654
673
|
console.log(e.message, e);
|
|
655
674
|
throw e;
|
|
656
|
-
} finally {
|
|
657
|
-
c && p.end(c);
|
|
658
675
|
}
|
|
659
676
|
})();
|
|
660
677
|
}
|
|
@@ -762,71 +779,86 @@ class SpiceModel {
|
|
|
762
779
|
return _asyncToGenerator(function* () {
|
|
763
780
|
var _this8$_ctx;
|
|
764
781
|
|
|
765
|
-
// Profiling:
|
|
766
|
-
var p = (_this8$_ctx = _this8[_ctx]) == null ? void 0 : _this8$_ctx.profiler
|
|
767
|
-
c = p == null ? void 0 : p.start(_this8.type + ".update", {
|
|
768
|
-
id: args == null ? void 0 : args.id
|
|
769
|
-
});
|
|
782
|
+
// Profiling: use track() for proper async context forking
|
|
783
|
+
var p = (_this8$_ctx = _this8[_ctx]) == null ? void 0 : _this8$_ctx.profiler;
|
|
770
784
|
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
var
|
|
785
|
+
var doUpdate =
|
|
786
|
+
/*#__PURE__*/
|
|
787
|
+
function () {
|
|
788
|
+
var _ref5 = _asyncToGenerator(function* () {
|
|
789
|
+
_this8.updated_at = new SDate().now();
|
|
790
|
+
var results = yield _this8.database.get(args.id);
|
|
791
|
+
var item_exist = yield _this8.exist(results);
|
|
775
792
|
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
793
|
+
if (!item_exist) {
|
|
794
|
+
throw new Error(_this8.type + " does not exist. in update");
|
|
795
|
+
}
|
|
779
796
|
|
|
780
|
-
|
|
797
|
+
delete results["id"];
|
|
781
798
|
|
|
782
|
-
|
|
799
|
+
_.defaults(_this8, results);
|
|
783
800
|
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
801
|
+
var cover_obj = {
|
|
802
|
+
old: results,
|
|
803
|
+
new: _this8,
|
|
804
|
+
id: args.id
|
|
805
|
+
};
|
|
806
|
+
var form;
|
|
790
807
|
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
808
|
+
if (args.skip_write_serialize != true && args.skip_serialize != true) {
|
|
809
|
+
cover_obj.new = yield _this8.do_serialize(_this8, "write", cover_obj.new, args);
|
|
810
|
+
}
|
|
794
811
|
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
812
|
+
if (args.skip_hooks != true) {
|
|
813
|
+
yield _this8.run_hook(cover_obj, "update", "before", results);
|
|
814
|
+
}
|
|
798
815
|
|
|
799
|
-
|
|
800
|
-
var pDb = p,
|
|
801
|
-
cDb = pDb == null ? void 0 : pDb.start(_this8.type + ".update.database");
|
|
816
|
+
var db_data = cover_obj.new || _this8;
|
|
802
817
|
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
818
|
+
if (p) {
|
|
819
|
+
yield p.track(_this8.type + ".update.database",
|
|
820
|
+
/*#__PURE__*/
|
|
821
|
+
_asyncToGenerator(function* () {
|
|
822
|
+
yield _this8.database.update(args.id, db_data, args._ttl);
|
|
823
|
+
}));
|
|
824
|
+
} else {
|
|
825
|
+
yield _this8.database.update(args.id, db_data, args._ttl);
|
|
826
|
+
}
|
|
808
827
|
|
|
809
|
-
|
|
828
|
+
_this8.setMonitor();
|
|
810
829
|
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
830
|
+
if (args.skip_read_serialize != true && args.skip_serialize != true) {
|
|
831
|
+
cover_obj.new = yield _this8.do_serialize(cover_obj.new, "read", {}, args, (yield _this8.propsToBeRemoved(cover_obj.new)));
|
|
832
|
+
}
|
|
814
833
|
|
|
815
|
-
|
|
816
|
-
|
|
834
|
+
if (args.skip_hooks != true) {
|
|
835
|
+
yield _this8.run_hook(_extends({}, _this8, {
|
|
836
|
+
id: args.id
|
|
837
|
+
}), "update", "after", results);
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
_this8.id = args.id;
|
|
841
|
+
return _extends({}, cover_obj.new, {
|
|
817
842
|
id: args.id
|
|
818
|
-
})
|
|
843
|
+
});
|
|
844
|
+
});
|
|
845
|
+
|
|
846
|
+
return function doUpdate() {
|
|
847
|
+
return _ref5.apply(this, arguments);
|
|
848
|
+
};
|
|
849
|
+
}();
|
|
850
|
+
|
|
851
|
+
try {
|
|
852
|
+
if (p) {
|
|
853
|
+
return yield p.track(_this8.type + ".update", doUpdate, {
|
|
854
|
+
id: args == null ? void 0 : args.id
|
|
855
|
+
});
|
|
819
856
|
}
|
|
820
857
|
|
|
821
|
-
|
|
822
|
-
return _extends({}, cover_obj.new, {
|
|
823
|
-
id: args.id
|
|
824
|
-
});
|
|
858
|
+
return yield doUpdate();
|
|
825
859
|
} catch (e) {
|
|
826
860
|
console.log("Error on update", e, e.stack);
|
|
827
861
|
throw e;
|
|
828
|
-
} finally {
|
|
829
|
-
c && p.end(c);
|
|
830
862
|
}
|
|
831
863
|
})();
|
|
832
864
|
}
|
|
@@ -841,70 +873,85 @@ class SpiceModel {
|
|
|
841
873
|
args = {};
|
|
842
874
|
}
|
|
843
875
|
|
|
844
|
-
// Profiling:
|
|
845
|
-
var p = (_this9$_ctx = _this9[_ctx]) == null ? void 0 : _this9$_ctx.profiler
|
|
846
|
-
|
|
876
|
+
// Profiling: use track() for proper async context forking
|
|
877
|
+
var p = (_this9$_ctx = _this9[_ctx]) == null ? void 0 : _this9$_ctx.profiler;
|
|
878
|
+
|
|
879
|
+
var doCreate =
|
|
880
|
+
/*#__PURE__*/
|
|
881
|
+
function () {
|
|
882
|
+
var _ref7 = _asyncToGenerator(function* () {
|
|
883
|
+
var form;
|
|
884
|
+
_this9.created_at = new SDate().now();
|
|
885
|
+
args = _.defaults(args, {
|
|
886
|
+
id_prefix: _this9.type
|
|
887
|
+
});
|
|
847
888
|
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
889
|
+
if (args.body) {
|
|
890
|
+
form = _.defaults({}, args.body);
|
|
891
|
+
form.created_at = _this9.created_at;
|
|
892
|
+
form.updated_at = _this9.created_at;
|
|
893
|
+
delete form["bucket"];
|
|
894
|
+
}
|
|
854
895
|
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
form.updated_at = _this9.created_at;
|
|
859
|
-
delete form["bucket"];
|
|
860
|
-
}
|
|
896
|
+
var workingForm = form || _this9;
|
|
897
|
+
_this9.updated_at = new SDate().now();
|
|
898
|
+
var id = args.id_prefix + "-" + UUID.v4();
|
|
861
899
|
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
900
|
+
if (args && args.id) {
|
|
901
|
+
id = args.id;
|
|
902
|
+
}
|
|
865
903
|
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
904
|
+
if (args.skip_write_serialize != true && args.skip_serialize != true) {
|
|
905
|
+
workingForm = yield _this9.do_serialize(workingForm, "write", {}, args);
|
|
906
|
+
}
|
|
869
907
|
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
908
|
+
if (args.skip_hooks != true) {
|
|
909
|
+
yield _this9.run_hook(workingForm, "create", "before");
|
|
910
|
+
}
|
|
873
911
|
|
|
874
|
-
|
|
875
|
-
yield _this9.run_hook(workingForm, "create", "before");
|
|
876
|
-
}
|
|
912
|
+
var results;
|
|
877
913
|
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
914
|
+
if (p) {
|
|
915
|
+
results = yield p.track(_this9.type + ".create.database",
|
|
916
|
+
/*#__PURE__*/
|
|
917
|
+
_asyncToGenerator(function* () {
|
|
918
|
+
return yield _this9.database.insert(id, workingForm, args._ttl);
|
|
919
|
+
}));
|
|
920
|
+
} else {
|
|
921
|
+
results = yield _this9.database.insert(id, workingForm, args._ttl);
|
|
922
|
+
}
|
|
881
923
|
|
|
882
|
-
|
|
883
|
-
results = yield _this9.database.insert(id, workingForm, args._ttl);
|
|
884
|
-
} finally {
|
|
885
|
-
cDb && pDb.end(cDb);
|
|
886
|
-
}
|
|
924
|
+
_this9.setMonitor();
|
|
887
925
|
|
|
888
|
-
|
|
926
|
+
if (args.skip_read_serialize != true && args.skip_serialize != true) {
|
|
927
|
+
results = yield _this9.do_serialize(results, "read", {}, args, (yield _this9.propsToBeRemoved(results)));
|
|
928
|
+
}
|
|
889
929
|
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
930
|
+
if (args.skip_hooks != true) {
|
|
931
|
+
yield _this9.run_hook(_extends({}, results, {
|
|
932
|
+
id
|
|
933
|
+
}), "create", "after");
|
|
934
|
+
}
|
|
893
935
|
|
|
894
|
-
|
|
895
|
-
yield _this9.run_hook(_extends({}, results, {
|
|
936
|
+
return _extends({}, results, {
|
|
896
937
|
id
|
|
897
|
-
})
|
|
938
|
+
});
|
|
939
|
+
});
|
|
940
|
+
|
|
941
|
+
return function doCreate() {
|
|
942
|
+
return _ref7.apply(this, arguments);
|
|
943
|
+
};
|
|
944
|
+
}();
|
|
945
|
+
|
|
946
|
+
try {
|
|
947
|
+
if (p) {
|
|
948
|
+
return yield p.track(_this9.type + ".create", doCreate);
|
|
898
949
|
}
|
|
899
950
|
|
|
900
|
-
return
|
|
901
|
-
id
|
|
902
|
-
});
|
|
951
|
+
return yield doCreate();
|
|
903
952
|
} catch (e) {
|
|
904
953
|
console.log(e.stack);
|
|
905
954
|
throw e;
|
|
906
|
-
} finally {
|
|
907
|
-
c && p.end(c);
|
|
908
955
|
}
|
|
909
956
|
})();
|
|
910
957
|
}
|
|
@@ -936,53 +983,76 @@ class SpiceModel {
|
|
|
936
983
|
return _asyncToGenerator(function* () {
|
|
937
984
|
var _this11$_ctx;
|
|
938
985
|
|
|
939
|
-
// Profiling:
|
|
940
|
-
var p = (_this11$_ctx = _this11[_ctx]) == null ? void 0 : _this11$_ctx.profiler
|
|
941
|
-
c = p == null ? void 0 : p.start(_this11.type + ".delete", {
|
|
942
|
-
id: args == null ? void 0 : args.id
|
|
943
|
-
});
|
|
986
|
+
// Profiling: use track() for proper async context forking
|
|
987
|
+
var p = (_this11$_ctx = _this11[_ctx]) == null ? void 0 : _this11$_ctx.profiler;
|
|
944
988
|
|
|
945
|
-
|
|
946
|
-
|
|
989
|
+
var doDelete =
|
|
990
|
+
/*#__PURE__*/
|
|
991
|
+
function () {
|
|
992
|
+
var _ref9 = _asyncToGenerator(function* () {
|
|
993
|
+
var item_exist = yield _this11.exist(args.id);
|
|
947
994
|
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
995
|
+
if (!item_exist) {
|
|
996
|
+
throw new Error(_this11.type + " does not exist.");
|
|
997
|
+
}
|
|
951
998
|
|
|
952
|
-
|
|
999
|
+
var results = yield _this11.database.get(args.id);
|
|
953
1000
|
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
1001
|
+
if (args.skip_hooks != true) {
|
|
1002
|
+
yield _this11.run_hook(args, "delete", "before");
|
|
1003
|
+
}
|
|
957
1004
|
|
|
958
|
-
|
|
959
|
-
var pDb = p,
|
|
960
|
-
cDb = pDb == null ? void 0 : pDb.start(_this11.type + ".delete.database");
|
|
1005
|
+
var delete_response = {};
|
|
961
1006
|
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
1007
|
+
var dbOperation =
|
|
1008
|
+
/*#__PURE__*/
|
|
1009
|
+
function () {
|
|
1010
|
+
var _ref10 = _asyncToGenerator(function* () {
|
|
1011
|
+
if (args.hard) {
|
|
1012
|
+
delete_response = yield _this11.database.delete(args.id);
|
|
965
1013
|
|
|
966
|
-
|
|
1014
|
+
_this11.setMonitor();
|
|
1015
|
+
} else {
|
|
1016
|
+
delete results["id"];
|
|
1017
|
+
results.deleted = true;
|
|
1018
|
+
delete_response = yield _this11.database.update(args.id, results);
|
|
1019
|
+
}
|
|
1020
|
+
});
|
|
1021
|
+
|
|
1022
|
+
return function dbOperation() {
|
|
1023
|
+
return _ref10.apply(this, arguments);
|
|
1024
|
+
};
|
|
1025
|
+
}();
|
|
1026
|
+
|
|
1027
|
+
if (p) {
|
|
1028
|
+
yield p.track(_this11.type + ".delete.database", dbOperation);
|
|
967
1029
|
} else {
|
|
968
|
-
|
|
969
|
-
results.deleted = true;
|
|
970
|
-
delete_response = yield _this11.database.update(args.id, results);
|
|
1030
|
+
yield dbOperation();
|
|
971
1031
|
}
|
|
972
|
-
} finally {
|
|
973
|
-
cDb && pDb.end(cDb);
|
|
974
|
-
}
|
|
975
1032
|
|
|
976
|
-
|
|
977
|
-
|
|
1033
|
+
if (args.skip_hooks != true) {
|
|
1034
|
+
yield _this11.run_hook(results, "delete", "after", results);
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
return {};
|
|
1038
|
+
});
|
|
1039
|
+
|
|
1040
|
+
return function doDelete() {
|
|
1041
|
+
return _ref9.apply(this, arguments);
|
|
1042
|
+
};
|
|
1043
|
+
}();
|
|
1044
|
+
|
|
1045
|
+
try {
|
|
1046
|
+
if (p) {
|
|
1047
|
+
return yield p.track(_this11.type + ".delete", doDelete, {
|
|
1048
|
+
id: args == null ? void 0 : args.id
|
|
1049
|
+
});
|
|
978
1050
|
}
|
|
979
1051
|
|
|
980
|
-
return
|
|
1052
|
+
return yield doDelete();
|
|
981
1053
|
} catch (e) {
|
|
982
1054
|
console.log(e.stack);
|
|
983
1055
|
throw e;
|
|
984
|
-
} finally {
|
|
985
|
-
c && p.end(c);
|
|
986
1056
|
}
|
|
987
1057
|
})();
|
|
988
1058
|
}
|
|
@@ -1137,12 +1207,12 @@ class SpiceModel {
|
|
|
1137
1207
|
|
|
1138
1208
|
createJoinSection(mappedNestings) {
|
|
1139
1209
|
if (!mappedNestings || mappedNestings.length === 0) return "";
|
|
1140
|
-
return mappedNestings.map((
|
|
1210
|
+
return mappedNestings.map((_ref11) => {
|
|
1141
1211
|
var {
|
|
1142
1212
|
alias,
|
|
1143
1213
|
reference,
|
|
1144
1214
|
is_array
|
|
1145
|
-
} =
|
|
1215
|
+
} = _ref11;
|
|
1146
1216
|
var keyspace = (0, _fix.fixCollection)(reference);
|
|
1147
1217
|
|
|
1148
1218
|
if (is_array === true) {
|
|
@@ -1226,117 +1296,132 @@ class SpiceModel {
|
|
|
1226
1296
|
var _this12 = this;
|
|
1227
1297
|
|
|
1228
1298
|
return _asyncToGenerator(function* () {
|
|
1229
|
-
var _this12$_ctx
|
|
1299
|
+
var _this12$_ctx;
|
|
1230
1300
|
|
|
1231
1301
|
if (args === void 0) {
|
|
1232
1302
|
args = {};
|
|
1233
1303
|
}
|
|
1234
1304
|
|
|
1235
|
-
// Profiling:
|
|
1236
|
-
var p = (_this12$_ctx = _this12[_ctx]) == null ? void 0 : _this12$_ctx.profiler
|
|
1237
|
-
c = p == null ? void 0 : p.start(_this12.type + ".list", {
|
|
1238
|
-
limit: (_args7 = args) == null ? void 0 : _args7.limit,
|
|
1239
|
-
offset: (_args8 = args) == null ? void 0 : _args8.offset
|
|
1240
|
-
});
|
|
1305
|
+
// Profiling: use track() for proper async context forking
|
|
1306
|
+
var p = (_this12$_ctx = _this12[_ctx]) == null ? void 0 : _this12$_ctx.profiler;
|
|
1241
1307
|
|
|
1242
|
-
|
|
1243
|
-
|
|
1308
|
+
var doList =
|
|
1309
|
+
/*#__PURE__*/
|
|
1310
|
+
function () {
|
|
1311
|
+
var _ref12 = _asyncToGenerator(function* () {
|
|
1312
|
+
var _args7, _args8, _args9;
|
|
1244
1313
|
|
|
1245
|
-
|
|
1314
|
+
if (args.mapping_dept) _this12[_mapping_dept] = args.mapping_dept; // Find alias tokens from query/columns/sort
|
|
1246
1315
|
|
|
1247
|
-
|
|
1316
|
+
var nestings = [..._this12.extractNestings(((_args7 = args) == null ? void 0 : _args7.query) || "", _this12.type), ..._this12.extractNestings(((_args8 = args) == null ? void 0 : _args8.columns) || "", _this12.type), ..._this12.extractNestings(((_args9 = args) == null ? void 0 : _args9.sort) || "", _this12.type)]; // Decide which aliases we can join: only when map.type===MODEL AND reference is a STRING keyspace.
|
|
1248
1317
|
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1318
|
+
var mappedNestings = _.compact(_.uniq(nestings).map(alias => {
|
|
1319
|
+
var prop = _this12.props[alias];
|
|
1320
|
+
if (!(prop == null ? void 0 : prop.map) || prop.map.type !== _2.MapType.MODEL) return null;
|
|
1321
|
+
var ref = prop.map.reference;
|
|
1253
1322
|
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
var is_array = prop.type === "array" || prop.type === Array || prop.type === _2.DataType.ARRAY;
|
|
1260
|
-
return {
|
|
1261
|
-
alias,
|
|
1262
|
-
reference: ref.toLowerCase(),
|
|
1263
|
-
// keyspace to join
|
|
1264
|
-
is_array,
|
|
1265
|
-
type: prop.type,
|
|
1266
|
-
value_field: prop.map.value_field,
|
|
1267
|
-
destination: prop.map.destination || alias
|
|
1268
|
-
};
|
|
1269
|
-
}));
|
|
1270
|
-
|
|
1271
|
-
var protectedAliases = mappedNestings.map(m => m.alias);
|
|
1272
|
-
var arrayAliases = mappedNestings.filter(m => m.is_array).map(m => m.alias); // Columns: first prepare (prefix base table, rewrite array alias.field → ARRAY proj),
|
|
1273
|
-
// then normalize names and add default aliases
|
|
1323
|
+
if (typeof ref !== "string") {
|
|
1324
|
+
// reference is a class/function/array-of-classes → no SQL join; serializer will handle it
|
|
1325
|
+
return null;
|
|
1326
|
+
}
|
|
1274
1327
|
|
|
1275
|
-
|
|
1276
|
-
|
|
1328
|
+
var is_array = prop.type === "array" || prop.type === Array || prop.type === _2.DataType.ARRAY;
|
|
1329
|
+
return {
|
|
1330
|
+
alias,
|
|
1331
|
+
reference: ref.toLowerCase(),
|
|
1332
|
+
// keyspace to join
|
|
1333
|
+
is_array,
|
|
1334
|
+
type: prop.type,
|
|
1335
|
+
value_field: prop.map.value_field,
|
|
1336
|
+
destination: prop.map.destination || alias
|
|
1337
|
+
};
|
|
1338
|
+
}));
|
|
1339
|
+
|
|
1340
|
+
var protectedAliases = mappedNestings.map(m => m.alias);
|
|
1341
|
+
var arrayAliases = mappedNestings.filter(m => m.is_array).map(m => m.alias); // Columns: first prepare (prefix base table, rewrite array alias.field → ARRAY proj),
|
|
1342
|
+
// then normalize names and add default aliases
|
|
1343
|
+
|
|
1344
|
+
args.columns = _this12.prepColumns(args.columns, protectedAliases, arrayAliases);
|
|
1345
|
+
args.columns = _this12.fixColumnName(args.columns, protectedAliases); // Build JOIN/NEST from the mapped keyspaces
|
|
1346
|
+
|
|
1347
|
+
args._join = _this12.createJoinSection(mappedNestings); // WHERE
|
|
1348
|
+
|
|
1349
|
+
var query = "";
|
|
1350
|
+
var deletedCondition = "(`" + _this12.type + "`.deleted = false OR `" + _this12.type + "`.deleted IS MISSING)";
|
|
1351
|
+
|
|
1352
|
+
if (args.is_full_text === "true" || args.is_custom_query === "true") {
|
|
1353
|
+
query = args.query || "";
|
|
1354
|
+
} else if (args.filters) {
|
|
1355
|
+
query = _this12.makeQueryFromFilter(args.filters);
|
|
1356
|
+
} else if (args.query) {
|
|
1357
|
+
query = args.query + " AND " + deletedCondition;
|
|
1358
|
+
} else {
|
|
1359
|
+
query = deletedCondition;
|
|
1360
|
+
}
|
|
1277
1361
|
|
|
1278
|
-
|
|
1362
|
+
if ((0, _Security.hasSQLInjection)(query)) return []; // LIMIT/OFFSET/SORT
|
|
1279
1363
|
|
|
1280
|
-
|
|
1281
|
-
|
|
1364
|
+
args.limit = Number(args.limit) || undefined;
|
|
1365
|
+
args.offset = Number(args.offset) || 0;
|
|
1366
|
+
args.sort = args.sort ? args.sort.split(",").map(item => item.includes(".") ? item : "`" + _this12.type + "`." + _this12.formatSortComponent(item)).join(",") : "`" + _this12.type + "`.created_at DESC";
|
|
1282
1367
|
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
query = _this12.makeQueryFromFilter(args.filters);
|
|
1287
|
-
} else if (args.query) {
|
|
1288
|
-
query = args.query + " AND " + deletedCondition;
|
|
1289
|
-
} else {
|
|
1290
|
-
query = deletedCondition;
|
|
1291
|
-
}
|
|
1368
|
+
if (args.skip_hooks !== true) {
|
|
1369
|
+
yield _this12.run_hook(_this12, "list", "before");
|
|
1370
|
+
}
|
|
1292
1371
|
|
|
1293
|
-
|
|
1372
|
+
var cacheKey = "list::" + _this12.type + "::" + args._join + "::" + query + "::" + args.limit + "::" + args.offset + "::" + args.sort + "::" + args.do_count + "::" + args.statement_consistent + "::" + args.columns + "::" + args.is_full_text + "::" + args.is_custom_query;
|
|
1373
|
+
var results;
|
|
1294
1374
|
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1375
|
+
if (_this12.shouldUseCache(_this12.type)) {
|
|
1376
|
+
var cached = yield _this12.getCacheProviderObject(_this12.type).get(cacheKey);
|
|
1377
|
+
results = cached == null ? void 0 : cached.value;
|
|
1378
|
+
var isEmpty = (cached == null ? void 0 : cached.value) === undefined;
|
|
1379
|
+
var refresh = yield _this12.shouldForceRefresh(cached);
|
|
1298
1380
|
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
}
|
|
1381
|
+
if (isEmpty || refresh) {
|
|
1382
|
+
results = yield _this12.fetchResults(args, query);
|
|
1302
1383
|
|
|
1303
|
-
|
|
1304
|
-
|
|
1384
|
+
_this12.getCacheProviderObject(_this12.type).set(cacheKey, {
|
|
1385
|
+
value: results,
|
|
1386
|
+
time: new Date().getTime()
|
|
1387
|
+
}, _this12.getCacheConfig(_this12.type));
|
|
1388
|
+
}
|
|
1389
|
+
} else {
|
|
1390
|
+
results = yield _this12.fetchResults(args, query);
|
|
1391
|
+
} // Serializer still handles class-based refs and value_field
|
|
1305
1392
|
|
|
1306
|
-
if (_this12.shouldUseCache(_this12.type)) {
|
|
1307
|
-
var cached = yield _this12.getCacheProviderObject(_this12.type).get(cacheKey);
|
|
1308
|
-
results = cached == null ? void 0 : cached.value;
|
|
1309
|
-
var isEmpty = (cached == null ? void 0 : cached.value) === undefined;
|
|
1310
|
-
var refresh = yield _this12.shouldForceRefresh(cached);
|
|
1311
1393
|
|
|
1312
|
-
if (
|
|
1313
|
-
results = yield _this12.
|
|
1394
|
+
if (args.skip_read_serialize !== true && args.skip_serialize !== true) {
|
|
1395
|
+
results.data = yield _this12.do_serialize(results.data, "read", {}, args, (yield _this12.propsToBeRemoved(results.data)));
|
|
1396
|
+
}
|
|
1314
1397
|
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
time: new Date().getTime()
|
|
1318
|
-
}, _this12.getCacheConfig(_this12.type));
|
|
1398
|
+
if (args.skip_hooks !== true) {
|
|
1399
|
+
yield _this12.run_hook(results.data, "list", "after");
|
|
1319
1400
|
}
|
|
1320
|
-
} else {
|
|
1321
|
-
results = yield _this12.fetchResults(args, query);
|
|
1322
|
-
} // Serializer still handles class-based refs and value_field
|
|
1323
1401
|
|
|
1402
|
+
results.data = _this12.filterResultsByColumns(results.data, args.columns);
|
|
1403
|
+
return results;
|
|
1404
|
+
});
|
|
1324
1405
|
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
}
|
|
1406
|
+
return function doList() {
|
|
1407
|
+
return _ref12.apply(this, arguments);
|
|
1408
|
+
};
|
|
1409
|
+
}();
|
|
1328
1410
|
|
|
1329
|
-
|
|
1330
|
-
|
|
1411
|
+
try {
|
|
1412
|
+
if (p) {
|
|
1413
|
+
var _args10, _args11;
|
|
1414
|
+
|
|
1415
|
+
return yield p.track(_this12.type + ".list", doList, {
|
|
1416
|
+
limit: (_args10 = args) == null ? void 0 : _args10.limit,
|
|
1417
|
+
offset: (_args11 = args) == null ? void 0 : _args11.offset
|
|
1418
|
+
});
|
|
1331
1419
|
}
|
|
1332
1420
|
|
|
1333
|
-
|
|
1334
|
-
return results;
|
|
1421
|
+
return yield doList();
|
|
1335
1422
|
} catch (e) {
|
|
1336
1423
|
console.log(e.stack);
|
|
1337
1424
|
throw e;
|
|
1338
|
-
} finally {
|
|
1339
|
-
c && p.end(c);
|
|
1340
1425
|
}
|
|
1341
1426
|
})();
|
|
1342
1427
|
}
|
|
@@ -1347,31 +1432,42 @@ class SpiceModel {
|
|
|
1347
1432
|
return _asyncToGenerator(function* () {
|
|
1348
1433
|
var _this13$_ctx;
|
|
1349
1434
|
|
|
1350
|
-
// Profiling:
|
|
1351
|
-
var p = (_this13$_ctx = _this13[_ctx]) == null ? void 0 : _this13$_ctx.profiler
|
|
1352
|
-
|
|
1435
|
+
// Profiling: use track() for proper async context forking
|
|
1436
|
+
var p = (_this13$_ctx = _this13[_ctx]) == null ? void 0 : _this13$_ctx.profiler;
|
|
1437
|
+
|
|
1438
|
+
var doFetch =
|
|
1439
|
+
/*#__PURE__*/
|
|
1440
|
+
function () {
|
|
1441
|
+
var _ref13 = _asyncToGenerator(function* () {
|
|
1442
|
+
if (args.is_custom_query === "true" && args.ids.length > 0) {
|
|
1443
|
+
return yield _this13.database.query(query);
|
|
1444
|
+
} else if (args.is_full_text === "true") {
|
|
1445
|
+
return yield _this13.database.full_text_search(_this13.type, query || "", args.limit, args.offset, args._join);
|
|
1446
|
+
} else {
|
|
1447
|
+
var result = yield _this13.database.search(_this13.type, args.columns || "", query || "", args.limit, args.offset, args.sort, args.do_count, args.statement_consistent, args._join);
|
|
1448
|
+
return result;
|
|
1449
|
+
}
|
|
1450
|
+
});
|
|
1353
1451
|
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
return result;
|
|
1362
|
-
}
|
|
1363
|
-
} finally {
|
|
1364
|
-
c && p.end(c);
|
|
1452
|
+
return function doFetch() {
|
|
1453
|
+
return _ref13.apply(this, arguments);
|
|
1454
|
+
};
|
|
1455
|
+
}();
|
|
1456
|
+
|
|
1457
|
+
if (p) {
|
|
1458
|
+
return yield p.track(_this13.type + ".fetchResults", doFetch);
|
|
1365
1459
|
}
|
|
1460
|
+
|
|
1461
|
+
return yield doFetch();
|
|
1366
1462
|
})();
|
|
1367
1463
|
}
|
|
1368
1464
|
|
|
1369
|
-
addHook(
|
|
1465
|
+
addHook(_ref14) {
|
|
1370
1466
|
var {
|
|
1371
1467
|
operation,
|
|
1372
1468
|
when,
|
|
1373
1469
|
execute
|
|
1374
|
-
} =
|
|
1470
|
+
} = _ref14;
|
|
1375
1471
|
|
|
1376
1472
|
this[_hooks][operation][when].push(execute);
|
|
1377
1473
|
}
|
|
@@ -1596,11 +1692,11 @@ class SpiceModel {
|
|
|
1596
1692
|
})();
|
|
1597
1693
|
}
|
|
1598
1694
|
|
|
1599
|
-
addModifier(
|
|
1695
|
+
addModifier(_ref15) {
|
|
1600
1696
|
var {
|
|
1601
1697
|
when,
|
|
1602
1698
|
execute
|
|
1603
|
-
} =
|
|
1699
|
+
} = _ref15;
|
|
1604
1700
|
|
|
1605
1701
|
if (this[_serializers][when]) {
|
|
1606
1702
|
this[_serializers][when]["modifiers"].push(execute);
|
|
@@ -1702,91 +1798,104 @@ class SpiceModel {
|
|
|
1702
1798
|
path_to_be_removed = [];
|
|
1703
1799
|
}
|
|
1704
1800
|
|
|
1705
|
-
// Profiling:
|
|
1706
|
-
var p = (_this18$_ctx = _this18[_ctx]) == null ? void 0 : _this18$_ctx.profiler
|
|
1707
|
-
c = p == null ? void 0 : p.start(_this18.type + ".do_serialize", {
|
|
1708
|
-
type
|
|
1709
|
-
});
|
|
1801
|
+
// Profiling: use track() for proper async context forking
|
|
1802
|
+
var p = (_this18$_ctx = _this18[_ctx]) == null ? void 0 : _this18$_ctx.profiler;
|
|
1710
1803
|
|
|
1711
|
-
|
|
1712
|
-
|
|
1804
|
+
var doSerialize =
|
|
1805
|
+
/*#__PURE__*/
|
|
1806
|
+
function () {
|
|
1807
|
+
var _ref16 = _asyncToGenerator(function* () {
|
|
1808
|
+
var _this18$_serializers, _this18$_serializers$;
|
|
1713
1809
|
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1810
|
+
// Early exit if serialization should not run.
|
|
1811
|
+
if (!_this18.shouldSerializerRun(args, type)) {
|
|
1812
|
+
return data;
|
|
1813
|
+
} // Add external modifiers only once.
|
|
1718
1814
|
|
|
1719
1815
|
|
|
1720
|
-
|
|
1721
|
-
|
|
1816
|
+
if (_this18.type && !_this18[_external_modifier_loaded]) {
|
|
1817
|
+
_this18.addExternalModifiers(_this18.type);
|
|
1722
1818
|
|
|
1723
|
-
|
|
1724
|
-
|
|
1819
|
+
_this18[_external_modifier_loaded] = true;
|
|
1820
|
+
} // Cache the modifiers lookup for the specified type.
|
|
1725
1821
|
|
|
1726
1822
|
|
|
1727
|
-
|
|
1823
|
+
var modifiers = ((_this18$_serializers = _this18[_serializers]) == null ? void 0 : (_this18$_serializers$ = _this18$_serializers[type]) == null ? void 0 : _this18$_serializers$.modifiers) || [];
|
|
1728
1824
|
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1825
|
+
for (var modifier of modifiers) {
|
|
1826
|
+
try {
|
|
1827
|
+
data = yield modifier(data, old_data, _this18[_ctx], _this18.type);
|
|
1828
|
+
} catch (error) {
|
|
1829
|
+
console.error("Modifier error in do_serialize:", error.stack);
|
|
1830
|
+
}
|
|
1831
|
+
} // Ensure data is always an array for consistent processing.
|
|
1736
1832
|
|
|
1737
1833
|
|
|
1738
|
-
|
|
1834
|
+
var originalIsArray = Array.isArray(data);
|
|
1739
1835
|
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1836
|
+
if (!originalIsArray) {
|
|
1837
|
+
data = [data];
|
|
1838
|
+
} // ⚡ OPTIMIZED: Use cached defaults metadata instead of computing every time
|
|
1743
1839
|
|
|
1744
1840
|
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1841
|
+
var {
|
|
1842
|
+
staticDefaults,
|
|
1843
|
+
dynamicDefaults,
|
|
1844
|
+
hasDefaults
|
|
1845
|
+
} = _this18.getDefaultsMetadata(type);
|
|
1750
1846
|
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1847
|
+
if (hasDefaults) {
|
|
1848
|
+
data = data.map(item => {
|
|
1849
|
+
// Apply static defaults first (fast - no function calls)
|
|
1850
|
+
var result = _.defaults({}, item, staticDefaults); // Only compute dynamic defaults if there are any
|
|
1755
1851
|
|
|
1756
1852
|
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1853
|
+
for (var {
|
|
1854
|
+
key,
|
|
1855
|
+
fn
|
|
1856
|
+
} of dynamicDefaults) {
|
|
1857
|
+
if (result[key] === undefined) {
|
|
1858
|
+
result[key] = fn({
|
|
1859
|
+
old_data: data,
|
|
1860
|
+
new_data: old_data
|
|
1861
|
+
});
|
|
1862
|
+
}
|
|
1766
1863
|
}
|
|
1767
|
-
}
|
|
1768
1864
|
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1865
|
+
return result;
|
|
1866
|
+
});
|
|
1867
|
+
} // If type is "read", clean the data by omitting certain props.
|
|
1868
|
+
|
|
1869
|
+
|
|
1870
|
+
if (type === "read") {
|
|
1871
|
+
// ⚡ OPTIMIZED: Use cached hidden props instead of computing every time
|
|
1872
|
+
var hiddenProps = _this18.getHiddenProps(); // Combine default props to remove.
|
|
1873
|
+
|
|
1772
1874
|
|
|
1875
|
+
var propsToClean = ["deleted", "type", ...path_to_be_removed, ...hiddenProps];
|
|
1876
|
+
data = data.map(item => _.omit(item, propsToClean));
|
|
1877
|
+
} // Return in the original format (array or single object).
|
|
1773
1878
|
|
|
1774
|
-
if (type === "read") {
|
|
1775
|
-
// ⚡ OPTIMIZED: Use cached hidden props instead of computing every time
|
|
1776
|
-
var hiddenProps = _this18.getHiddenProps(); // Combine default props to remove.
|
|
1777
1879
|
|
|
1880
|
+
return originalIsArray ? data : data[0];
|
|
1881
|
+
});
|
|
1778
1882
|
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
}
|
|
1883
|
+
return function doSerialize() {
|
|
1884
|
+
return _ref16.apply(this, arguments);
|
|
1885
|
+
};
|
|
1886
|
+
}();
|
|
1782
1887
|
|
|
1888
|
+
try {
|
|
1889
|
+
if (p) {
|
|
1890
|
+
return yield p.track(_this18.type + ".do_serialize", doSerialize, {
|
|
1891
|
+
type
|
|
1892
|
+
});
|
|
1893
|
+
}
|
|
1783
1894
|
|
|
1784
|
-
return
|
|
1895
|
+
return yield doSerialize();
|
|
1785
1896
|
} catch (error) {
|
|
1786
1897
|
console.error("Error in do_serialize:", error.stack);
|
|
1787
1898
|
throw error;
|
|
1788
|
-
} finally {
|
|
1789
|
-
c && p.end(c);
|
|
1790
1899
|
}
|
|
1791
1900
|
})();
|
|
1792
1901
|
}
|