spice-js 2.6.71 → 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.
@@ -566,67 +566,109 @@ class SpiceModel {
566
566
  var _this4 = this;
567
567
 
568
568
  return _asyncToGenerator(function* () {
569
- try {
570
- if (args.mapping_dept) _this4[_mapping_dept] = args.mapping_dept;
569
+ var _this4$_ctx;
571
570
 
572
- if (!args) {
573
- args = {};
574
- }
571
+ // Profiling: use track() for proper async context forking
572
+ var p = (_this4$_ctx = _this4[_ctx]) == null ? void 0 : _this4$_ctx.profiler;
575
573
 
576
- if (_.isString(args.id)) {
577
- if (args.skip_hooks !== true) {
578
- yield _this4.run_hook(args, "get", "before");
574
+ var doGet =
575
+ /*#__PURE__*/
576
+ function () {
577
+ var _ref2 = _asyncToGenerator(function* () {
578
+ if (args.mapping_dept) _this4[_mapping_dept] = args.mapping_dept;
579
+
580
+ if (!args) {
581
+ args = {};
579
582
  }
580
583
 
581
- var key = "get::" + _this4.type + "::" + args.id;
582
- var results = {};
584
+ if (_.isString(args.id)) {
585
+ if (args.skip_hooks !== true) {
586
+ yield _this4.run_hook(args, "get", "before");
587
+ }
583
588
 
584
- if (_this4.shouldUseCache(_this4.type)) {
585
- // Retrieve the cached results
586
- 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 = {};
587
591
 
588
- var isCacheEmpty = (cached_results == null ? void 0 : cached_results.value) === undefined; // Check if the cached result should be refreshed
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
589
595
 
590
- var shouldRefresh = yield _this4.shouldForceRefresh(cached_results); // Force a refresh for "workflow" type if needed
596
+ var isCacheEmpty = (cached_results == null ? void 0 : cached_results.value) === undefined; // Check if the cached result should be refreshed
591
597
 
592
- if (isCacheEmpty || shouldRefresh) {
593
- // Retrieve from the database and update cache
594
- results = yield _this4.database.get(args.id);
595
- yield _this4.getCacheProviderObject(_this4.type).set(key, {
596
- value: results,
597
- time: new Date().getTime()
598
- }, _this4.getCacheConfig(_this4.type));
599
- } else {
600
- // Use the cached value
601
- results = cached_results.value;
602
- }
603
- } else {
604
- // Directly fetch from the database if caching is disabled
605
- results = yield _this4.database.get(args.id);
606
- }
598
+ var shouldRefresh = yield _this4.shouldForceRefresh(cached_results); // Force a refresh for "workflow" type if needed
607
599
 
608
- if (results.type !== undefined && results.type !== _this4.type) {
609
- throw new Error(_this4.type + " does not exist type");
610
- }
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
+ }
611
611
 
612
- if (results._type !== undefined && results._type !== _this4.type) {
613
- throw new Error(_this4.type + " does not exist _type");
614
- }
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 {
629
+ results = yield _this4.database.get(args.id);
630
+ }
631
+ }
615
632
 
616
- if (results.deleted === undefined || results.deleted === false) {
617
- if (args.skip_read_serialize !== true && args.skip_serialize !== true) {
618
- results = yield _this4.do_serialize(results, "read", {}, args, (yield _this4.propsToBeRemoved(results)));
633
+ if (results.type !== undefined && results.type !== _this4.type) {
634
+ throw new Error(_this4.type + " does not exist type");
619
635
  }
620
636
 
621
- if (args.skip_hooks !== true) {
622
- yield _this4.run_hook(results, "get", "after");
637
+ if (results._type !== undefined && results._type !== _this4.type) {
638
+ throw new Error(_this4.type + " does not exist _type");
623
639
  }
624
640
 
625
- return results;
626
- } else {
627
- throw new Error(_this4.type + " does not exist");
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
+ }
645
+
646
+ if (args.skip_hooks !== true) {
647
+ yield _this4.run_hook(results, "get", "after");
648
+ }
649
+
650
+ return results;
651
+ } else {
652
+ throw new Error(_this4.type + " does not exist");
653
+ }
628
654
  }
655
+ });
656
+
657
+ return function doGet() {
658
+ return _ref2.apply(this, arguments);
659
+ };
660
+ }();
661
+
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
+ });
629
669
  }
670
+
671
+ return yield doGet();
630
672
  } catch (e) {
631
673
  console.log(e.message, e);
632
674
  throw e;
@@ -735,53 +777,85 @@ class SpiceModel {
735
777
  var _this8 = this;
736
778
 
737
779
  return _asyncToGenerator(function* () {
738
- try {
739
- _this8.updated_at = new SDate().now();
740
- var results = yield _this8.database.get(args.id);
741
- var item_exist = yield _this8.exist(results);
780
+ var _this8$_ctx;
742
781
 
743
- if (!item_exist) {
744
- throw new Error(_this8.type + " does not exist. in update");
745
- }
782
+ // Profiling: use track() for proper async context forking
783
+ var p = (_this8$_ctx = _this8[_ctx]) == null ? void 0 : _this8$_ctx.profiler;
746
784
 
747
- delete results["id"];
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);
748
792
 
749
- _.defaults(_this8, results);
793
+ if (!item_exist) {
794
+ throw new Error(_this8.type + " does not exist. in update");
795
+ }
750
796
 
751
- var cover_obj = {
752
- old: results,
753
- new: _this8,
754
- id: args.id
755
- };
756
- var form;
797
+ delete results["id"];
757
798
 
758
- if (args.skip_write_serialize != true && args.skip_serialize != true) {
759
- cover_obj.new = yield _this8.do_serialize(_this8, "write", cover_obj.new, args);
760
- }
799
+ _.defaults(_this8, results);
761
800
 
762
- if (args.skip_hooks != true) {
763
- yield _this8.run_hook(cover_obj, "update", "before", results);
764
- }
801
+ var cover_obj = {
802
+ old: results,
803
+ new: _this8,
804
+ id: args.id
805
+ };
806
+ var form;
765
807
 
766
- var db_data = cover_obj.new || _this8;
767
- yield _this8.database.update(args.id, db_data, args._ttl);
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
+ }
768
811
 
769
- _this8.setMonitor();
812
+ if (args.skip_hooks != true) {
813
+ yield _this8.run_hook(cover_obj, "update", "before", results);
814
+ }
770
815
 
771
- if (args.skip_read_serialize != true && args.skip_serialize != true) {
772
- cover_obj.new = yield _this8.do_serialize(cover_obj.new, "read", {}, args, (yield _this8.propsToBeRemoved(cover_obj.new)));
773
- }
816
+ var db_data = cover_obj.new || _this8;
774
817
 
775
- if (args.skip_hooks != true) {
776
- yield _this8.run_hook(_extends({}, _this8, {
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
+ }
827
+
828
+ _this8.setMonitor();
829
+
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
+ }
833
+
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, {
777
842
  id: args.id
778
- }), "update", "after", results);
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
+ });
779
856
  }
780
857
 
781
- _this8.id = args.id;
782
- return _extends({}, cover_obj.new, {
783
- id: args.id
784
- });
858
+ return yield doUpdate();
785
859
  } catch (e) {
786
860
  console.log("Error on update", e, e.stack);
787
861
  throw e;
@@ -793,57 +867,88 @@ class SpiceModel {
793
867
  var _this9 = this;
794
868
 
795
869
  return _asyncToGenerator(function* () {
870
+ var _this9$_ctx;
871
+
796
872
  if (args === void 0) {
797
873
  args = {};
798
874
  }
799
875
 
800
- try {
801
- var form;
802
- _this9.created_at = new SDate().now();
803
- args = _.defaults(args, {
804
- id_prefix: _this9.type
805
- });
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
+ });
806
888
 
807
- if (args.body) {
808
- form = _.defaults({}, args.body);
809
- form.created_at = _this9.created_at;
810
- form.updated_at = _this9.created_at;
811
- delete form["bucket"];
812
- }
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
+ }
813
895
 
814
- var workingForm = form || _this9;
815
- _this9.updated_at = new SDate().now();
816
- var id = args.id_prefix + "-" + UUID.v4();
896
+ var workingForm = form || _this9;
897
+ _this9.updated_at = new SDate().now();
898
+ var id = args.id_prefix + "-" + UUID.v4();
817
899
 
818
- if (args && args.id) {
819
- id = args.id;
820
- }
900
+ if (args && args.id) {
901
+ id = args.id;
902
+ }
821
903
 
822
- if (args.skip_write_serialize != true && args.skip_serialize != true) {
823
- workingForm = yield _this9.do_serialize(workingForm, "write", {}, args);
824
- }
904
+ if (args.skip_write_serialize != true && args.skip_serialize != true) {
905
+ workingForm = yield _this9.do_serialize(workingForm, "write", {}, args);
906
+ }
825
907
 
826
- if (args.skip_hooks != true) {
827
- yield _this9.run_hook(workingForm, "create", "before");
828
- }
908
+ if (args.skip_hooks != true) {
909
+ yield _this9.run_hook(workingForm, "create", "before");
910
+ }
829
911
 
830
- var results = yield _this9.database.insert(id, workingForm, args._ttl);
912
+ var results;
831
913
 
832
- _this9.setMonitor();
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
+ }
833
923
 
834
- if (args.skip_read_serialize != true && args.skip_serialize != true) {
835
- results = yield _this9.do_serialize(results, "read", {}, args, (yield _this9.propsToBeRemoved(results)));
836
- }
924
+ _this9.setMonitor();
837
925
 
838
- if (args.skip_hooks != true) {
839
- yield _this9.run_hook(_extends({}, results, {
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
+ }
929
+
930
+ if (args.skip_hooks != true) {
931
+ yield _this9.run_hook(_extends({}, results, {
932
+ id
933
+ }), "create", "after");
934
+ }
935
+
936
+ return _extends({}, results, {
840
937
  id
841
- }), "create", "after");
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);
842
949
  }
843
950
 
844
- return _extends({}, results, {
845
- id
846
- });
951
+ return yield doCreate();
847
952
  } catch (e) {
848
953
  console.log(e.stack);
849
954
  throw e;
@@ -876,36 +981,75 @@ class SpiceModel {
876
981
  var _this11 = this;
877
982
 
878
983
  return _asyncToGenerator(function* () {
879
- var item_exist = yield _this11.exist(args.id);
984
+ var _this11$_ctx;
880
985
 
881
- if (!item_exist) {
882
- throw new Error(_this11.type + " does not exist.");
883
- }
986
+ // Profiling: use track() for proper async context forking
987
+ var p = (_this11$_ctx = _this11[_ctx]) == null ? void 0 : _this11$_ctx.profiler;
884
988
 
885
- var results = yield _this11.database.get(args.id);
989
+ var doDelete =
990
+ /*#__PURE__*/
991
+ function () {
992
+ var _ref9 = _asyncToGenerator(function* () {
993
+ var item_exist = yield _this11.exist(args.id);
886
994
 
887
- try {
888
- if (args.skip_hooks != true) {
889
- yield _this11.run_hook(args, "delete", "before");
890
- }
995
+ if (!item_exist) {
996
+ throw new Error(_this11.type + " does not exist.");
997
+ }
891
998
 
892
- var delete_response = {};
999
+ var results = yield _this11.database.get(args.id);
893
1000
 
894
- if (args.hard) {
895
- delete_response = yield _this11.database.delete(args.id);
1001
+ if (args.skip_hooks != true) {
1002
+ yield _this11.run_hook(args, "delete", "before");
1003
+ }
896
1004
 
897
- _this11.setMonitor();
898
- } else {
899
- delete results["id"];
900
- results.deleted = true;
901
- delete_response = yield _this11.database.update(args.id, results);
902
- }
1005
+ var delete_response = {};
903
1006
 
904
- if (args.skip_hooks != true) {
905
- yield _this11.run_hook(results, "delete", "after", results);
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);
1013
+
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);
1029
+ } else {
1030
+ yield dbOperation();
1031
+ }
1032
+
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
+ });
906
1050
  }
907
1051
 
908
- return {};
1052
+ return yield doDelete();
909
1053
  } catch (e) {
910
1054
  console.log(e.stack);
911
1055
  throw e;
@@ -1063,12 +1207,12 @@ class SpiceModel {
1063
1207
 
1064
1208
  createJoinSection(mappedNestings) {
1065
1209
  if (!mappedNestings || mappedNestings.length === 0) return "";
1066
- return mappedNestings.map((_ref2) => {
1210
+ return mappedNestings.map((_ref11) => {
1067
1211
  var {
1068
1212
  alias,
1069
1213
  reference,
1070
1214
  is_array
1071
- } = _ref2;
1215
+ } = _ref11;
1072
1216
  var keyspace = (0, _fix.fixCollection)(reference);
1073
1217
 
1074
1218
  if (is_array === true) {
@@ -1152,103 +1296,129 @@ class SpiceModel {
1152
1296
  var _this12 = this;
1153
1297
 
1154
1298
  return _asyncToGenerator(function* () {
1299
+ var _this12$_ctx;
1300
+
1155
1301
  if (args === void 0) {
1156
1302
  args = {};
1157
1303
  }
1158
1304
 
1159
- try {
1160
- var _args6, _args7, _args8;
1305
+ // Profiling: use track() for proper async context forking
1306
+ var p = (_this12$_ctx = _this12[_ctx]) == null ? void 0 : _this12$_ctx.profiler;
1161
1307
 
1162
- if (args.mapping_dept) _this12[_mapping_dept] = args.mapping_dept; // Find alias tokens from query/columns/sort
1308
+ var doList =
1309
+ /*#__PURE__*/
1310
+ function () {
1311
+ var _ref12 = _asyncToGenerator(function* () {
1312
+ var _args7, _args8, _args9;
1163
1313
 
1164
- var nestings = [..._this12.extractNestings(((_args6 = args) == null ? void 0 : _args6.query) || "", _this12.type), ..._this12.extractNestings(((_args7 = args) == null ? void 0 : _args7.columns) || "", _this12.type), ..._this12.extractNestings(((_args8 = args) == null ? void 0 : _args8.sort) || "", _this12.type)]; // Decide which aliases we can join: only when map.type===MODEL AND reference is a STRING keyspace.
1314
+ if (args.mapping_dept) _this12[_mapping_dept] = args.mapping_dept; // Find alias tokens from query/columns/sort
1165
1315
 
1166
- var mappedNestings = _.compact(_.uniq(nestings).map(alias => {
1167
- var prop = _this12.props[alias];
1168
- if (!(prop == null ? void 0 : prop.map) || prop.map.type !== _2.MapType.MODEL) return null;
1169
- var ref = prop.map.reference;
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.
1170
1317
 
1171
- if (typeof ref !== "string") {
1172
- // reference is a class/function/array-of-classes → no SQL join; serializer will handle it
1173
- return null;
1174
- }
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;
1175
1322
 
1176
- var is_array = prop.type === "array" || prop.type === Array || prop.type === _2.DataType.ARRAY;
1177
- return {
1178
- alias,
1179
- reference: ref.toLowerCase(),
1180
- // keyspace to join
1181
- is_array,
1182
- type: prop.type,
1183
- value_field: prop.map.value_field,
1184
- destination: prop.map.destination || alias
1185
- };
1186
- }));
1187
-
1188
- var protectedAliases = mappedNestings.map(m => m.alias);
1189
- var arrayAliases = mappedNestings.filter(m => m.is_array).map(m => m.alias); // Columns: first prepare (prefix base table, rewrite array alias.field → ARRAY proj),
1190
- // 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
+ }
1191
1327
 
1192
- args.columns = _this12.prepColumns(args.columns, protectedAliases, arrayAliases);
1193
- args.columns = _this12.fixColumnName(args.columns, protectedAliases); // Build JOIN/NEST from the mapped keyspaces
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
+ }
1194
1361
 
1195
- args._join = _this12.createJoinSection(mappedNestings); // WHERE
1362
+ if ((0, _Security.hasSQLInjection)(query)) return []; // LIMIT/OFFSET/SORT
1196
1363
 
1197
- var query = "";
1198
- var deletedCondition = "(`" + _this12.type + "`.deleted = false OR `" + _this12.type + "`.deleted IS MISSING)";
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";
1199
1367
 
1200
- if (args.is_full_text === "true" || args.is_custom_query === "true") {
1201
- query = args.query || "";
1202
- } else if (args.filters) {
1203
- query = _this12.makeQueryFromFilter(args.filters);
1204
- } else if (args.query) {
1205
- query = args.query + " AND " + deletedCondition;
1206
- } else {
1207
- query = deletedCondition;
1208
- }
1368
+ if (args.skip_hooks !== true) {
1369
+ yield _this12.run_hook(_this12, "list", "before");
1370
+ }
1209
1371
 
1210
- if ((0, _Security.hasSQLInjection)(query)) return []; // LIMIT/OFFSET/SORT
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;
1211
1374
 
1212
- args.limit = Number(args.limit) || undefined;
1213
- args.offset = Number(args.offset) || 0;
1214
- args.sort = args.sort ? args.sort.split(",").map(item => item.includes(".") ? item : "`" + _this12.type + "`." + _this12.formatSortComponent(item)).join(",") : "`" + _this12.type + "`.created_at DESC";
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);
1215
1380
 
1216
- if (args.skip_hooks !== true) {
1217
- yield _this12.run_hook(_this12, "list", "before");
1218
- }
1381
+ if (isEmpty || refresh) {
1382
+ results = yield _this12.fetchResults(args, query);
1219
1383
 
1220
- 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;
1221
- var results;
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
1222
1392
 
1223
- if (_this12.shouldUseCache(_this12.type)) {
1224
- var cached = yield _this12.getCacheProviderObject(_this12.type).get(cacheKey);
1225
- results = cached == null ? void 0 : cached.value;
1226
- var isEmpty = (cached == null ? void 0 : cached.value) === undefined;
1227
- var refresh = yield _this12.shouldForceRefresh(cached);
1228
1393
 
1229
- if (isEmpty || refresh) {
1230
- results = yield _this12.fetchResults(args, query);
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
+ }
1231
1397
 
1232
- _this12.getCacheProviderObject(_this12.type).set(cacheKey, {
1233
- value: results,
1234
- time: new Date().getTime()
1235
- }, _this12.getCacheConfig(_this12.type));
1398
+ if (args.skip_hooks !== true) {
1399
+ yield _this12.run_hook(results.data, "list", "after");
1236
1400
  }
1237
- } else {
1238
- results = yield _this12.fetchResults(args, query);
1239
- } // Serializer still handles class-based refs and value_field
1240
1401
 
1402
+ results.data = _this12.filterResultsByColumns(results.data, args.columns);
1403
+ return results;
1404
+ });
1241
1405
 
1242
- if (args.skip_read_serialize !== true && args.skip_serialize !== true) {
1243
- results.data = yield _this12.do_serialize(results.data, "read", {}, args, (yield _this12.propsToBeRemoved(results.data)));
1244
- }
1406
+ return function doList() {
1407
+ return _ref12.apply(this, arguments);
1408
+ };
1409
+ }();
1245
1410
 
1246
- if (args.skip_hooks !== true) {
1247
- yield _this12.run_hook(results.data, "list", "after");
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
+ });
1248
1419
  }
1249
1420
 
1250
- results.data = _this12.filterResultsByColumns(results.data, args.columns);
1251
- return results;
1421
+ return yield doList();
1252
1422
  } catch (e) {
1253
1423
  console.log(e.stack);
1254
1424
  throw e;
@@ -1260,23 +1430,44 @@ class SpiceModel {
1260
1430
  var _this13 = this;
1261
1431
 
1262
1432
  return _asyncToGenerator(function* () {
1263
- if (args.is_custom_query === "true" && args.ids.length > 0) {
1264
- return yield _this13.database.query(query);
1265
- } else if (args.is_full_text === "true") {
1266
- return yield _this13.database.full_text_search(_this13.type, query || "", args.limit, args.offset, args._join);
1267
- } else {
1268
- 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);
1269
- return result;
1433
+ var _this13$_ctx;
1434
+
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
+ });
1451
+
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);
1270
1459
  }
1460
+
1461
+ return yield doFetch();
1271
1462
  })();
1272
1463
  }
1273
1464
 
1274
- addHook(_ref3) {
1465
+ addHook(_ref14) {
1275
1466
  var {
1276
1467
  operation,
1277
1468
  when,
1278
1469
  execute
1279
- } = _ref3;
1470
+ } = _ref14;
1280
1471
 
1281
1472
  this[_hooks][operation][when].push(execute);
1282
1473
  }
@@ -1501,11 +1692,11 @@ class SpiceModel {
1501
1692
  })();
1502
1693
  }
1503
1694
 
1504
- addModifier(_ref4) {
1695
+ addModifier(_ref15) {
1505
1696
  var {
1506
1697
  when,
1507
1698
  execute
1508
- } = _ref4;
1699
+ } = _ref15;
1509
1700
 
1510
1701
  if (this[_serializers][when]) {
1511
1702
  this[_serializers][when]["modifiers"].push(execute);
@@ -1601,84 +1792,107 @@ class SpiceModel {
1601
1792
  var _this18 = this;
1602
1793
 
1603
1794
  return _asyncToGenerator(function* () {
1795
+ var _this18$_ctx;
1796
+
1604
1797
  if (path_to_be_removed === void 0) {
1605
1798
  path_to_be_removed = [];
1606
1799
  }
1607
1800
 
1608
- try {
1609
- var _this18$_serializers, _this18$_serializers$;
1801
+ // Profiling: use track() for proper async context forking
1802
+ var p = (_this18$_ctx = _this18[_ctx]) == null ? void 0 : _this18$_ctx.profiler;
1610
1803
 
1611
- // Early exit if serialization should not run.
1612
- if (!_this18.shouldSerializerRun(args, type)) {
1613
- return data;
1614
- } // Add external modifiers only once.
1804
+ var doSerialize =
1805
+ /*#__PURE__*/
1806
+ function () {
1807
+ var _ref16 = _asyncToGenerator(function* () {
1808
+ var _this18$_serializers, _this18$_serializers$;
1615
1809
 
1810
+ // Early exit if serialization should not run.
1811
+ if (!_this18.shouldSerializerRun(args, type)) {
1812
+ return data;
1813
+ } // Add external modifiers only once.
1616
1814
 
1617
- if (_this18.type && !_this18[_external_modifier_loaded]) {
1618
- _this18.addExternalModifiers(_this18.type);
1619
1815
 
1620
- _this18[_external_modifier_loaded] = true;
1621
- } // Cache the modifiers lookup for the specified type.
1816
+ if (_this18.type && !_this18[_external_modifier_loaded]) {
1817
+ _this18.addExternalModifiers(_this18.type);
1622
1818
 
1819
+ _this18[_external_modifier_loaded] = true;
1820
+ } // Cache the modifiers lookup for the specified type.
1623
1821
 
1624
- var modifiers = ((_this18$_serializers = _this18[_serializers]) == null ? void 0 : (_this18$_serializers$ = _this18$_serializers[type]) == null ? void 0 : _this18$_serializers$.modifiers) || [];
1625
1822
 
1626
- for (var modifier of modifiers) {
1627
- try {
1628
- data = yield modifier(data, old_data, _this18[_ctx], _this18.type);
1629
- } catch (error) {
1630
- console.error("Modifier error in do_serialize:", error.stack);
1631
- }
1632
- } // Ensure data is always an array for consistent processing.
1823
+ var modifiers = ((_this18$_serializers = _this18[_serializers]) == null ? void 0 : (_this18$_serializers$ = _this18$_serializers[type]) == null ? void 0 : _this18$_serializers$.modifiers) || [];
1633
1824
 
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.
1634
1832
 
1635
- var originalIsArray = Array.isArray(data);
1636
1833
 
1637
- if (!originalIsArray) {
1638
- data = [data];
1639
- } // ⚡ OPTIMIZED: Use cached defaults metadata instead of computing every time
1834
+ var originalIsArray = Array.isArray(data);
1640
1835
 
1836
+ if (!originalIsArray) {
1837
+ data = [data];
1838
+ } // ⚡ OPTIMIZED: Use cached defaults metadata instead of computing every time
1641
1839
 
1642
- var {
1643
- staticDefaults,
1644
- dynamicDefaults,
1645
- hasDefaults
1646
- } = _this18.getDefaultsMetadata(type);
1647
1840
 
1648
- if (hasDefaults) {
1649
- data = data.map(item => {
1650
- // Apply static defaults first (fast - no function calls)
1651
- var result = _.defaults({}, item, staticDefaults); // Only compute dynamic defaults if there are any
1841
+ var {
1842
+ staticDefaults,
1843
+ dynamicDefaults,
1844
+ hasDefaults
1845
+ } = _this18.getDefaultsMetadata(type);
1652
1846
 
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
1653
1851
 
1654
- for (var {
1655
- key,
1656
- fn
1657
- } of dynamicDefaults) {
1658
- if (result[key] === undefined) {
1659
- result[key] = fn({
1660
- old_data: data,
1661
- new_data: old_data
1662
- });
1852
+
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
+ }
1663
1863
  }
1664
- }
1665
1864
 
1666
- return result;
1667
- });
1668
- } // If type is "read", clean the data by omitting certain props.
1865
+ return result;
1866
+ });
1867
+ } // If type is "read", clean the data by omitting certain props.
1669
1868
 
1670
1869
 
1671
- if (type === "read") {
1672
- // ⚡ OPTIMIZED: Use cached hidden props instead of computing every time
1673
- var hiddenProps = _this18.getHiddenProps(); // Combine default props to remove.
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.
1674
1873
 
1675
1874
 
1676
- var propsToClean = ["deleted", "type", ...path_to_be_removed, ...hiddenProps];
1677
- data = data.map(item => _.omit(item, propsToClean));
1678
- } // Return in the original format (array or single object).
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).
1878
+
1879
+
1880
+ return originalIsArray ? data : data[0];
1881
+ });
1679
1882
 
1883
+ return function doSerialize() {
1884
+ return _ref16.apply(this, arguments);
1885
+ };
1886
+ }();
1887
+
1888
+ try {
1889
+ if (p) {
1890
+ return yield p.track(_this18.type + ".do_serialize", doSerialize, {
1891
+ type
1892
+ });
1893
+ }
1680
1894
 
1681
- return originalIsArray ? data : data[0];
1895
+ return yield doSerialize();
1682
1896
  } catch (error) {
1683
1897
  console.error("Error in do_serialize:", error.stack);
1684
1898
  throw error;