@carbonorm/carbonnode 3.7.23 → 3.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -167,6 +167,14 @@ var C6Constants = {
167
167
  var C6C = C6Constants;
168
168
 
169
169
  // @link https://www.npmjs.com/package/axios-cache-adapter
170
+ var carbonNodeQsStringify = function (params) {
171
+ return Qs.stringify(params, {
172
+ arrayFormat: "indices",
173
+ indices: true,
174
+ skipNulls: false,
175
+ strictNullHandling: true,
176
+ });
177
+ };
170
178
  // updating these values
171
179
  // @link https://github.com/axios/axios/issues/209
172
180
  //
@@ -175,7 +183,7 @@ var C6C = C6Constants;
175
183
  //
176
184
  // immediately affects this instance
177
185
  // axiosInstance.defaults.headers['Auth-Token'] = 'foo bar';
178
- var axiosInstance = (axios.create({
186
+ var carbonAxiosInstance = (axios.create({
179
187
  // `baseURL` will be prepended to `url` unless `url` is absolute.
180
188
  // It can be convenient to set `baseURL` for an instance of axios to pass relative URLs
181
189
  // to methods of that instance.
@@ -197,7 +205,7 @@ var axiosInstance = (axios.create({
197
205
  // (e.g. https://www.npmjs.com/package/qs, http://api.jquery.com/jquery.param/)
198
206
  paramsSerializer: function (params) {
199
207
  // Nested get params [][][,,,] do not serialize correctly without Qs
200
- return Qs.stringify(params, { arrayFormat: 'indices', indices: true, skipNulls: false, strictNullHandling: true });
208
+ return carbonNodeQsStringify(params);
201
209
  },
202
210
  // `data` is the data to be sent as the request body
203
211
  // Only applicable for request methods 'PUT', 'POST', and 'PATCH'
@@ -268,6 +276,20 @@ var axiosInstance = (axios.create({
268
276
  httpsAgent: new https.Agent({ keepAlive: true }),
269
277
  */
270
278
  }));
279
+ carbonAxiosInstance.interceptors.request.use(function (config) {
280
+ if (config.params) {
281
+ var serialized = carbonNodeQsStringify(config.params);
282
+ if (serialized.length > 2000) {
283
+ // Move params into body but keep track of intended method
284
+ config.method = "post";
285
+ config.data = config.params;
286
+ config.params = {
287
+ METHOD: "GET", // 👈 explicit signal for your REST parser
288
+ };
289
+ }
290
+ }
291
+ return config;
292
+ });
271
293
 
272
294
  function convertForRequestBody (restfulObject, tableName, C6, regexErrorHandler) {
273
295
  if (regexErrorHandler === void 0) { regexErrorHandler = alert; }
@@ -625,13 +647,20 @@ var HttpExecutor = /** @class */ (function (_super) {
625
647
  function HttpExecutor() {
626
648
  return _super !== null && _super.apply(this, arguments) || this;
627
649
  }
650
+ HttpExecutor.prototype.isRestResponse = function (r) {
651
+ return !!r && r.data != null && typeof r.data === 'object' && 'rest' in r.data;
652
+ };
628
653
  HttpExecutor.prototype.stripTableNameFromKeys = function (obj) {
629
- var columns = this.config.restModel.COLUMNS || {};
630
- return Object.keys(obj || {}).reduce(function (acc, key) {
631
- var shortKey = columns[key] || key.split('.').pop();
632
- acc[shortKey] = obj[key];
633
- return acc;
634
- }, {});
654
+ var _a;
655
+ var columns = this.config.restModel.COLUMNS;
656
+ var source = (obj !== null && obj !== void 0 ? obj : {});
657
+ var out = {};
658
+ for (var _i = 0, _b = Object.entries(source); _i < _b.length; _i++) {
659
+ var _c = _b[_i], key = _c[0], value = _c[1];
660
+ var short = (_a = columns[key]) !== null && _a !== void 0 ? _a : (key.includes('.') ? key.split('.').pop() : key);
661
+ out[short] = value;
662
+ }
663
+ return out;
635
664
  };
636
665
  HttpExecutor.prototype.putState = function (response, request, callback) {
637
666
  var _a, _b;
@@ -648,14 +677,15 @@ var HttpExecutor = /** @class */ (function (_super) {
648
677
  HttpExecutor.prototype.postState = function (response, request, callback) {
649
678
  var _this = this;
650
679
  var _a, _b, _c;
651
- if (1 !== this.config.restModel.PRIMARY_SHORT.length) {
652
- console.error("C6 received unexpected result's given the primary key length");
653
- }
654
- else {
680
+ if (this.config.restModel.PRIMARY_SHORT.length === 1) {
655
681
  var pk = this.config.restModel.PRIMARY_SHORT[0];
656
- // TODO - should overrides be handled differently? Why override: (react/php), driver missmatches, aux data..
657
- // @ts-ignore - this is technically a correct error, but we allow it anyway...
658
- request[pk] = (_a = response.data) === null || _a === void 0 ? void 0 : _a.created;
682
+ try {
683
+ request[pk] = (_a = response.data) === null || _a === void 0 ? void 0 : _a.created;
684
+ }
685
+ catch ( /* best-effort */_d) { /* best-effort */ }
686
+ }
687
+ else if (isLocal()) {
688
+ console.error("C6 received unexpected results given the primary key length");
659
689
  }
660
690
  (_b = this.config.reactBootstrap) === null || _b === void 0 ? void 0 : _b.updateRestfulObjectArrays({
661
691
  callback: callback,
@@ -688,8 +718,9 @@ var HttpExecutor = /** @class */ (function (_super) {
688
718
  return __awaiter(this, void 0, void 0, function () {
689
719
  var _a, C6, axios, restURL, withCredentials, restModel, reactBootstrap, requestMethod, skipPrimaryCheck, clearCache, tableName, fullTableList, operatingTableFullName, operatingTable, tables, query, apiRequest;
690
720
  var _this = this;
691
- return __generator(this, function (_b) {
692
- switch (_b.label) {
721
+ var _b;
722
+ return __generator(this, function (_c) {
723
+ switch (_c.label) {
693
724
  case 0:
694
725
  _a = this.config, C6 = _a.C6, axios = _a.axios, restURL = _a.restURL, withCredentials = _a.withCredentials, restModel = _a.restModel, reactBootstrap = _a.reactBootstrap, requestMethod = _a.requestMethod, skipPrimaryCheck = _a.skipPrimaryCheck, clearCache = _a.clearCache;
695
726
  return [4 /*yield*/, this.runLifecycleHooks("beforeProcessing", {
@@ -697,7 +728,7 @@ var HttpExecutor = /** @class */ (function (_super) {
697
728
  request: this.request,
698
729
  })];
699
730
  case 1:
700
- _b.sent();
731
+ _c.sent();
701
732
  tableName = restModel.TABLE_NAME;
702
733
  fullTableList = Array.isArray(tableName) ? tableName : [tableName];
703
734
  operatingTableFullName = fullTableList[0];
@@ -712,45 +743,40 @@ var HttpExecutor = /** @class */ (function (_super) {
712
743
  default:
713
744
  throw Error('Bad request method passed to getApi');
714
745
  }
715
- if (null !== clearCache || undefined !== clearCache) {
716
- userCustomClearCache[tables + requestMethod] = clearCache;
746
+ if (clearCache != null) {
747
+ userCustomClearCache.push(clearCache);
748
+ }
749
+ if (isLocal() && (this.config.verbose || ((_b = this.request) === null || _b === void 0 ? void 0 : _b.debug))) {
750
+ console.groupCollapsed('%c API:', 'color: #0c0', "(".concat(requestMethod, ") Request for (").concat(tableName, ")"));
751
+ console.log('request', this.request);
752
+ console.groupEnd();
717
753
  }
718
- console.groupCollapsed('%c API: (' + requestMethod + ') Request for (' + tableName + ')', 'color: #0c0');
719
- console.log('request', this.request);
720
- console.groupEnd();
721
754
  // an undefined query would indicate queryCallback returned undefined,
722
755
  // thus the request shouldn't fire as is in custom cache
723
756
  if (undefined === this.request || null === this.request) {
724
- console.groupCollapsed('%c API: (' + requestMethod + ') Request Query for (' + tableName + ') undefined, returning null (will not fire)!', 'color: #c00');
725
- console.log('request', this.request);
726
- console.log('%c Returning (undefined|null) for a query would indicate a custom cache hit (outside API.tsx), thus the request should not fire.', 'color: #c00');
727
- console.trace();
728
- console.groupEnd();
757
+ if (isLocal()) {
758
+ console.groupCollapsed("API: (".concat(requestMethod, ") (").concat(tableName, ") query undefined/null \u2192 returning null"));
759
+ console.log('request', this.request);
760
+ console.groupEnd();
761
+ }
729
762
  return [2 /*return*/, null];
730
763
  }
731
764
  query = this.request;
732
- if (C6.GET === requestMethod) {
733
- if (undefined === query[C6.PAGINATION]) {
734
- query[C6.PAGINATION] = {};
735
- }
736
- query[C6.PAGINATION][C6.PAGE] = query[C6.PAGINATION][C6.PAGE] || 1;
737
- query[C6.PAGINATION][C6.LIMIT] = query[C6.PAGINATION][C6.LIMIT] || 100;
738
- }
739
765
  apiRequest = function () { return __awaiter(_this, void 0, void 0, function () {
740
- var _a, debug, _b, cacheResults, dataInsertMultipleRows, success, _c, fetchDependencies, _d, error, querySerialized, cacheResult, cachingConfirmed, cacheCheck, cacheCheck, apiResponse, returnGetNextPageFunction, restRequestUri, needsConditionOrPrimaryCheck, TABLES, primaryKeyList, primaryKeyFullyQualified, primaryKey, providedPrimary, primaryVal, axiosActiveRequest;
766
+ var _a, debug, _b, cacheResults, dataInsertMultipleRows, success, _c, fetchDependencies, _d, error, querySerialized, cacheResult, cachingConfirmed, cacheCheck, cacheCheck, apiResponse, returnGetNextPageFunction, restRequestUri, needsConditionOrPrimaryCheck, TABLES, primaryKeyList, primaryKeyFullyQualified, primaryKey, whereVal, whereIsEmpty, providedPrimary, primaryVal, axiosActiveRequest;
741
767
  var _e;
742
768
  var _this = this;
743
- var _f, _g, _h, _j, _k, _l;
744
- return __generator(this, function (_m) {
745
- switch (_m.label) {
769
+ var _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
770
+ return __generator(this, function (_r) {
771
+ switch (_r.label) {
746
772
  case 0:
747
773
  _a = this.request, debug = _a.debug, _b = _a.cacheResults, cacheResults = _b === void 0 ? (C6.GET === requestMethod) : _b, dataInsertMultipleRows = _a.dataInsertMultipleRows, success = _a.success, _c = _a.fetchDependencies, fetchDependencies = _c === void 0 ? eFetchDependencies.NONE : _c, _d = _a.error, error = _d === void 0 ? "An unexpected API error occurred!" : _d;
748
774
  if (C6.GET === requestMethod
749
775
  && undefined !== ((_f = query === null || query === void 0 ? void 0 : query[C6.PAGINATION]) === null || _f === void 0 ? void 0 : _f[C6.PAGE])
750
- && 1 !== query[C6.PAGINATION][C6.PAGE]) {
751
- console.groupCollapsed('Request on table (' + tableName + ') is firing for page (' + query[C6.PAGINATION][C6.PAGE] + '), please wait!');
752
- console.log('Request Data (note you may see the success and/or error prompt):', this.request);
753
- console.trace();
776
+ && 1 !== query[C6.PAGINATION][C6.PAGE]
777
+ && isLocal()) {
778
+ console.groupCollapsed("Request (".concat(tableName, ") page (").concat(query[C6.PAGINATION][C6.PAGE], ")"));
779
+ console.log('request', this.request);
754
780
  console.groupEnd();
755
781
  }
756
782
  querySerialized = sortAndSerializeQueryObject(tables, query !== null && query !== void 0 ? query : {});
@@ -767,39 +793,35 @@ var HttpExecutor = /** @class */ (function (_super) {
767
793
  query[C6.PAGINATION][C6.LIMIT] = query[C6.PAGINATION][C6.LIMIT] || 100;
768
794
  if (!(true === cacheResults)) return [3 /*break*/, 7];
769
795
  if (!(undefined !== cacheResult)) return [3 /*break*/, 6];
770
- _m.label = 1;
796
+ _r.label = 1;
771
797
  case 1:
772
798
  cacheCheck = checkCache(cacheResult, requestMethod, tableName, this.request);
773
799
  if (!(false !== cacheCheck)) return [3 /*break*/, 3];
774
800
  return [4 /*yield*/, cacheCheck];
775
- case 2: return [2 /*return*/, (_m.sent()).data];
801
+ case 2: return [2 /*return*/, (_r.sent()).data];
776
802
  case 3:
777
- // this line incrementing page is why we return recursively
778
803
  ++query[C6.PAGINATION][C6.PAGE];
779
- // this json stringify is to capture the new page number
780
804
  querySerialized = sortAndSerializeQueryObject(tables, query !== null && query !== void 0 ? query : {});
781
805
  cacheResult = apiRequestCache.find(function (cache) { return cache.requestArgumentsSerialized === querySerialized; });
782
- _m.label = 4;
806
+ _r.label = 4;
783
807
  case 4:
784
808
  if (undefined !== cacheResult) return [3 /*break*/, 1];
785
- _m.label = 5;
809
+ _r.label = 5;
786
810
  case 5:
787
811
  if (debug && isLocal()) {
788
- toast.warning("DEVS: Request in cache. (" + apiRequestCache.findIndex(function (cache) { return cache.requestArgumentsSerialized === querySerialized; }) + "). Returning function to request page (" + query[C6.PAGINATION][C6.PAGE] + ")", toastOptionsDevs);
812
+ toast.warning("DEVS: Request pages exhausted in cache; firing network.", toastOptionsDevs);
789
813
  }
790
- // @ts-ignore - this is an incorrect warning on TS, it's well typed
791
- return [2 /*return*/, apiRequest];
814
+ _r.label = 6;
792
815
  case 6:
793
816
  cachingConfirmed = true;
794
817
  return [3 /*break*/, 8];
795
818
  case 7:
796
- if (debug && isLocal()) {
819
+ if (debug && isLocal())
797
820
  toast.info("DEVS: Ignore cache was set to true.", toastOptionsDevs);
798
- }
799
- _m.label = 8;
821
+ _r.label = 8;
800
822
  case 8:
801
823
  if (debug && isLocal()) {
802
- toast.success("DEVS: Request not in cache." + (requestMethod === C6.GET ? "Page (" + query[C6.PAGINATION][C6.PAGE] + ")." : '') + " Logging cache 2 console.", toastOptionsDevs);
824
+ toast.success("DEVS: Request not in cache." + (requestMethod === C6.GET ? " Page (" + query[C6.PAGINATION][C6.PAGE] + ")" : ''), toastOptionsDevs);
803
825
  }
804
826
  return [3 /*break*/, 12];
805
827
  case 9:
@@ -808,10 +830,10 @@ var HttpExecutor = /** @class */ (function (_super) {
808
830
  cacheCheck = checkCache(cacheResult, requestMethod, tableName, this.request);
809
831
  if (!(false !== cacheCheck)) return [3 /*break*/, 11];
810
832
  return [4 /*yield*/, cacheCheck];
811
- case 10: return [2 /*return*/, (_m.sent()).data];
833
+ case 10: return [2 /*return*/, (_r.sent()).data];
812
834
  case 11:
813
835
  cachingConfirmed = true;
814
- _m.label = 12;
836
+ _r.label = 12;
815
837
  case 12:
816
838
  returnGetNextPageFunction = false;
817
839
  restRequestUri = restURL + operatingTable + '/';
@@ -823,12 +845,11 @@ var HttpExecutor = /** @class */ (function (_super) {
823
845
  primaryKey = (_h = primaryKeyFullyQualified === null || primaryKeyFullyQualified === void 0 ? void 0 : primaryKeyFullyQualified.split('.')) === null || _h === void 0 ? void 0 : _h.pop();
824
846
  if (needsConditionOrPrimaryCheck) {
825
847
  if (undefined === primaryKey) {
826
- if (null === query
827
- || undefined === query
828
- || undefined === (query === null || query === void 0 ? void 0 : query[C6.WHERE])
829
- || (true === Array.isArray(query[C6.WHERE])
830
- || query[C6.WHERE].length === 0)
831
- || (Object.keys(query === null || query === void 0 ? void 0 : query[C6.WHERE]).length === 0)) {
848
+ whereVal = query === null || query === void 0 ? void 0 : query[C6.WHERE];
849
+ whereIsEmpty = whereVal == null ||
850
+ (Array.isArray(whereVal) && whereVal.length === 0) ||
851
+ (typeof whereVal === 'object' && !Array.isArray(whereVal) && Object.keys(whereVal).length === 0);
852
+ if (whereIsEmpty) {
832
853
  console.error(query);
833
854
  throw Error('Failed to parse primary key information. Query: (' + JSON.stringify(query) + ') Primary Key: (' + JSON.stringify(primaryKey) + ') TABLES[operatingTable]?.PRIMARY: (' + JSON.stringify((_j = TABLES[operatingTable]) === null || _j === void 0 ? void 0 : _j.PRIMARY) + ') for operatingTable (' + operatingTable + ').');
834
855
  }
@@ -859,22 +880,27 @@ var HttpExecutor = /** @class */ (function (_super) {
859
880
  primaryVal = (_l = query[primaryKey]) !== null && _l !== void 0 ? _l : (primaryKeyFullyQualified ? query[primaryKeyFullyQualified] : undefined);
860
881
  if (undefined !== primaryVal) {
861
882
  restRequestUri += primaryVal + '/';
862
- console.log('query', query, 'primaryKey', primaryKey);
883
+ if (isLocal() && (this.config.verbose || ((_m = this.request) === null || _m === void 0 ? void 0 : _m.debug))) {
884
+ console.log('query', query, 'primaryKey', primaryKey);
885
+ }
863
886
  }
864
887
  else {
865
- console.log('query', query);
888
+ if (isLocal() && (this.config.verbose || ((_o = this.request) === null || _o === void 0 ? void 0 : _o.debug))) {
889
+ console.log('query', query);
890
+ }
866
891
  }
867
892
  }
868
893
  else {
869
- console.log('query', query);
894
+ if (isLocal() && (this.config.verbose || ((_p = this.request) === null || _p === void 0 ? void 0 : _p.debug))) {
895
+ console.log('query', query);
896
+ }
870
897
  }
871
898
  try {
872
- console.groupCollapsed('%c API: (' + requestMethod + ') Request Query for (' + operatingTable + ') is about to fire, will return with promise!', 'color: #A020F0');
873
- console.log(this.request);
874
- console.log('%c If this is the first request for this datatype; thus the value being set is currently undefined, please remember to update the state to null.', 'color: #A020F0');
875
- console.log('%c Remember undefined indicated the request has not fired, null indicates the request is firing, an empty array would signal no data was returned for the sql stmt.', 'color: #A020F0');
876
- console.trace();
877
- console.groupEnd();
899
+ if (isLocal() && (this.config.verbose || ((_q = this.request) === null || _q === void 0 ? void 0 : _q.debug))) {
900
+ console.groupCollapsed('%c API:', 'color: #A020F0', "(".concat(requestMethod, ") (").concat(operatingTable, ") firing"));
901
+ console.log(this.request);
902
+ console.groupEnd();
903
+ }
878
904
  this.runLifecycleHooks("beforeExecution", {
879
905
  config: this.config,
880
906
  request: this.request
@@ -915,11 +941,11 @@ var HttpExecutor = /** @class */ (function (_super) {
915
941
  // returning the promise with this then is important for tests. todo - we could make that optional.
916
942
  // https://rapidapi.com/guides/axios-async-await
917
943
  return [2 /*return*/, axiosActiveRequest.then(function (response) { return __awaiter(_this, void 0, void 0, function () {
918
- var cacheIndex, callback, responseData_1, dependencies_1, fetchReferences_1, apiRequestPromises, _loop_1, tableToFetch;
944
+ var cacheIndex, callback, responseData_1, pageLimit, got, hasNext, cacheIndex, dependencies_1, fetchReferences_1, apiRequestPromises, _loop_1, tableToFetch;
919
945
  var _this = this;
920
- var _a, _b, _c, _d, _e, _f, _g;
921
- return __generator(this, function (_h) {
922
- switch (_h.label) {
946
+ var _a, _b, _c, _d;
947
+ return __generator(this, function (_e) {
948
+ switch (_e.label) {
923
949
  case 0:
924
950
  // noinspection SuspiciousTypeOfGuard
925
951
  if (typeof response.data === 'string') {
@@ -941,13 +967,13 @@ var HttpExecutor = /** @class */ (function (_super) {
941
967
  request: this.request,
942
968
  response: response
943
969
  });
944
- // todo - this feels dumb now, but i digress
945
970
  apiResponse = TestRestfulResponse(response, success, error);
946
971
  if (false === apiResponse) {
947
972
  if (debug && isLocal()) {
948
- toast.warning("DEVS: TestRestfulResponse returned false for (" + operatingTable + ").", toastOptionsDevs);
973
+ toast.warning("DEVS: TestRestfulResponse returned false.", toastOptionsDevs);
949
974
  }
950
- return [2 /*return*/, response];
975
+ // Force a null payload so the final .then(response => response.data) yields null
976
+ return [2 /*return*/, Promise.resolve(__assign(__assign({}, response), { data: null }))];
951
977
  }
952
978
  callback = function () { return _this.runLifecycleHooks("afterCommit", {
953
979
  config: _this.config,
@@ -979,28 +1005,29 @@ var HttpExecutor = /** @class */ (function (_super) {
979
1005
  else {
980
1006
  callback();
981
1007
  }
982
- if (!(C6.GET === requestMethod)) return [3 /*break*/, 2];
1008
+ if (!(C6.GET === requestMethod && this.isRestResponse(response))) return [3 /*break*/, 2];
983
1009
  responseData_1 = response.data;
984
- returnGetNextPageFunction = 1 !== ((_a = query === null || query === void 0 ? void 0 : query[C6.PAGINATION]) === null || _a === void 0 ? void 0 : _a[C6.LIMIT]) &&
985
- ((_b = query === null || query === void 0 ? void 0 : query[C6.PAGINATION]) === null || _b === void 0 ? void 0 : _b[C6.LIMIT]) === responseData_1.rest.length;
986
- if (false === isTest() || this.config.verbose) {
987
- console.groupCollapsed('%c API: Response (' + requestMethod + ' ' + tableName + ') returned length (' + ((_c = responseData_1.rest) === null || _c === void 0 ? void 0 : _c.length) + ') of possible (' + ((_d = query === null || query === void 0 ? void 0 : query[C6.PAGINATION]) === null || _d === void 0 ? void 0 : _d[C6.LIMIT]) + ') limit!', 'color: #0c0');
988
- console.log('%c ' + requestMethod + ' ' + tableName, 'color: #0c0');
989
- console.log('%c Request Data (note you may see the success and/or error prompt):', 'color: #0c0', this.request);
990
- console.log('%c Response Data:', 'color: #0c0', responseData_1.rest);
991
- console.log('%c Will return get next page function:' + (returnGetNextPageFunction ? '' : ' (Will not return with explicit limit 1 set)'), 'color: #0c0', true === returnGetNextPageFunction);
992
- console.trace();
993
- console.groupEnd();
994
- }
995
- if (false === returnGetNextPageFunction) {
996
- responseData_1.next = apiRequest;
1010
+ pageLimit = (_a = query === null || query === void 0 ? void 0 : query[C6.PAGINATION]) === null || _a === void 0 ? void 0 : _a[C6.LIMIT];
1011
+ got = responseData_1.rest.length;
1012
+ hasNext = pageLimit !== 1 && got === pageLimit;
1013
+ if (hasNext) {
1014
+ responseData_1.next = apiRequest; // there might be more
997
1015
  }
998
1016
  else {
999
- responseData_1.next = undefined;
1000
- if (true === debug
1001
- && isLocal()) {
1002
- toast.success("DEVS: Response returned length (" + ((_e = responseData_1.rest) === null || _e === void 0 ? void 0 : _e.length) + ") less than limit (" + ((_f = query === null || query === void 0 ? void 0 : query[C6.PAGINATION]) === null || _f === void 0 ? void 0 : _f[C6.LIMIT]) + ").", toastOptionsDevs);
1003
- }
1017
+ responseData_1.next = undefined; // short page => done
1018
+ }
1019
+ // If you keep this flag, make it reflect reality:
1020
+ returnGetNextPageFunction = hasNext;
1021
+ // and fix cache ‘final’ flag to match:
1022
+ if (cachingConfirmed) {
1023
+ cacheIndex = apiRequestCache.findIndex(function (c) { return c.requestArgumentsSerialized === querySerialized; });
1024
+ apiRequestCache[cacheIndex].final = !hasNext;
1025
+ }
1026
+ if ((this.config.verbose || debug) && isLocal()) {
1027
+ console.groupCollapsed("API: Response (".concat(requestMethod, " ").concat(tableName, ") len (").concat((_b = responseData_1.rest) === null || _b === void 0 ? void 0 : _b.length, ") of (").concat((_c = query === null || query === void 0 ? void 0 : query[C6.PAGINATION]) === null || _c === void 0 ? void 0 : _c[C6.LIMIT], ")"));
1028
+ console.log('request', this.request);
1029
+ console.log('response.rest', responseData_1.rest);
1030
+ console.groupEnd();
1004
1031
  }
1005
1032
  if (!(fetchDependencies
1006
1033
  && 'number' === typeof fetchDependencies
@@ -1075,7 +1102,7 @@ var HttpExecutor = /** @class */ (function (_super) {
1075
1102
  }); });
1076
1103
  console.log('fetchReferences', fetchReferences_1);
1077
1104
  _loop_1 = function (tableToFetch) {
1078
- var _j;
1105
+ var _f;
1079
1106
  if (fetchDependencies & eFetchDependencies.C6ENTITY
1080
1107
  && 'string' === typeof tableName
1081
1108
  && tableName.endsWith("carbon_carbons")) {
@@ -1098,7 +1125,7 @@ var HttpExecutor = /** @class */ (function (_super) {
1098
1125
  .split('_')
1099
1126
  .map(function (part) { return part.charAt(0).toUpperCase() + part.slice(1); })
1100
1127
  .join('_');
1101
- var RestApi = (_g = C6.ORM[ormKey]) !== null && _g !== void 0 ? _g : new Error("Fetch Dependencies could not find table (".concat(ormKey, ") in the set \u2209 [ ").concat(Object.keys(C6.ORM).join(', '), " ]"));
1128
+ var RestApi = (_d = C6.ORM[ormKey]) !== null && _d !== void 0 ? _d : new Error("Fetch Dependencies could not find table (".concat(ormKey, ") in the set \u2209 [ ").concat(Object.keys(C6.ORM).join(', '), " ]"));
1102
1129
  console.log('%c Fetch Dependencies will select (' + tableToFetch + ') using GET request', 'color: #33ccff');
1103
1130
  var nextFetchDependencies = eFetchDependencies.NONE;
1104
1131
  if (fetchDependencies & eFetchDependencies.RECURSIVE) {
@@ -1124,8 +1151,8 @@ var HttpExecutor = /** @class */ (function (_super) {
1124
1151
  console.log('RestApi object', RestApi);
1125
1152
  // this is a dynamic call to the rest api, any generated table may resolve with (RestApi)
1126
1153
  // todo - using value to avoid joins.... but. maybe this should be a parameterizable option -- think race conditions; its safer to join
1127
- apiRequestPromises.push(RestApi.Get((_j = {},
1128
- _j[C6.WHERE] = Object.keys(fetchReferences_1[tableToFetch]).reduce(function (sum, column) {
1154
+ apiRequestPromises.push(RestApi.Get((_f = {},
1155
+ _f[C6.WHERE] = Object.keys(fetchReferences_1[tableToFetch]).reduce(function (sum, column) {
1129
1156
  fetchReferences_1[tableToFetch][column] = fetchReferences_1[tableToFetch][column].flat(Infinity);
1130
1157
  if (0 === fetchReferences_1[tableToFetch][column].length) {
1131
1158
  console.warn('The column (' + column + ') was not found in the response data. We will not fetch.', responseData_1);
@@ -1138,8 +1165,8 @@ var HttpExecutor = /** @class */ (function (_super) {
1138
1165
  ];
1139
1166
  return sum;
1140
1167
  }, {}),
1141
- _j.fetchDependencies = nextFetchDependencies,
1142
- _j)));
1168
+ _f.fetchDependencies = nextFetchDependencies,
1169
+ _f)));
1143
1170
  };
1144
1171
  for (tableToFetch in fetchReferences_1) {
1145
1172
  _loop_1(tableToFetch);
@@ -1147,7 +1174,7 @@ var HttpExecutor = /** @class */ (function (_super) {
1147
1174
  console.groupEnd();
1148
1175
  return [4 /*yield*/, Promise.all(apiRequestPromises)];
1149
1176
  case 1:
1150
- _h.sent();
1177
+ _e.sent();
1151
1178
  apiRequestPromises.map(function (promise) { return __awaiter(_this, void 0, void 0, function () {
1152
1179
  var _a, _b;
1153
1180
  return __generator(this, function (_c) {
@@ -1165,7 +1192,7 @@ var HttpExecutor = /** @class */ (function (_super) {
1165
1192
  }
1166
1193
  });
1167
1194
  }); });
1168
- _h.label = 2;
1195
+ _e.label = 2;
1169
1196
  case 2:
1170
1197
  if (debug && isLocal()) {
1171
1198
  toast.success("DEVS: (" + requestMethod + ") request complete.", toastOptionsDevs);
@@ -1193,7 +1220,7 @@ var HttpExecutor = /** @class */ (function (_super) {
1193
1220
  });
1194
1221
  }); };
1195
1222
  return [4 /*yield*/, apiRequest()];
1196
- case 2: return [2 /*return*/, _b.sent()];
1223
+ case 2: return [2 /*return*/, _c.sent()];
1197
1224
  }
1198
1225
  });
1199
1226
  });
@@ -2086,16 +2113,31 @@ function ExpressHandler(_a) {
2086
2113
  var _this = this;
2087
2114
  var C6 = _a.C6, mysqlPool = _a.mysqlPool;
2088
2115
  return function (req, res, next) { return __awaiter(_this, void 0, void 0, function () {
2089
- var method, table, primary, payload, primaryKeys, primaryKeyName, response, err_1;
2090
- var _a, _b;
2091
- return __generator(this, function (_c) {
2092
- switch (_c.label) {
2116
+ var incomingMethod, table, primary, methodOverrideRaw, methodOverride, treatAsGet, method, payload, primaryKeys, primaryKeyName, response, err_1;
2117
+ var _a, _b, _c, _d, _e;
2118
+ return __generator(this, function (_f) {
2119
+ switch (_f.label) {
2093
2120
  case 0:
2094
- _c.trys.push([0, 2, , 3]);
2095
- method = req.method.toUpperCase();
2121
+ _f.trys.push([0, 2, , 3]);
2122
+ incomingMethod = req.method.toUpperCase();
2096
2123
  table = req.params.table;
2097
2124
  primary = req.params.primary;
2098
- payload = method === 'GET' ? req.query : req.body;
2125
+ methodOverrideRaw = ((_b = (_a = req.query) === null || _a === void 0 ? void 0 : _a.METHOD) !== null && _b !== void 0 ? _b : (_c = req.query) === null || _c === void 0 ? void 0 : _c.method);
2126
+ methodOverride = typeof methodOverrideRaw === 'string' ? methodOverrideRaw.toUpperCase() : undefined;
2127
+ treatAsGet = incomingMethod === 'POST' && methodOverride === 'GET';
2128
+ method = treatAsGet ? 'GET' : incomingMethod;
2129
+ payload = treatAsGet ? __assign({}, req.body) : (method === 'GET' ? req.query : req.body);
2130
+ // Remove transport-only METHOD flag so it never leaks into ORM parsing
2131
+ if (treatAsGet && 'METHOD' in payload) {
2132
+ try {
2133
+ delete payload.METHOD;
2134
+ }
2135
+ catch ( /* noop */_g) { /* noop */ }
2136
+ }
2137
+ // Warn for unsupported overrides but continue normally
2138
+ if (incomingMethod !== 'GET' && methodOverride && methodOverride !== 'GET') {
2139
+ console.warn("Ignoring unsupported METHOD override: ".concat(methodOverride));
2140
+ }
2099
2141
  if (!(table in C6.TABLES)) {
2100
2142
  res.status(400).json({ error: "Invalid table: ".concat(table) });
2101
2143
  return [2 /*return*/];
@@ -2118,11 +2160,11 @@ function ExpressHandler(_a) {
2118
2160
  if (primary) {
2119
2161
  if (payload[C6C.WHERE]) {
2120
2162
  payload[C6C.WHERE][primaryKeyName] =
2121
- (_a = payload[C6C.WHERE][primaryKeyName]) !== null && _a !== void 0 ? _a : primary;
2163
+ (_d = payload[C6C.WHERE][primaryKeyName]) !== null && _d !== void 0 ? _d : primary;
2122
2164
  }
2123
2165
  else {
2124
2166
  payload[primaryKeyName] =
2125
- (_b = payload[primaryKeyName]) !== null && _b !== void 0 ? _b : primary;
2167
+ (_e = payload[primaryKeyName]) !== null && _e !== void 0 ? _e : primary;
2126
2168
  }
2127
2169
  }
2128
2170
  return [4 /*yield*/, restRequest({
@@ -2132,11 +2174,11 @@ function ExpressHandler(_a) {
2132
2174
  restModel: C6.TABLES[table]
2133
2175
  })(payload)];
2134
2176
  case 1:
2135
- response = _c.sent();
2177
+ response = _f.sent();
2136
2178
  res.status(200).json(__assign({ success: true }, response));
2137
2179
  return [3 /*break*/, 3];
2138
2180
  case 2:
2139
- err_1 = _c.sent();
2181
+ err_1 = _f.sent();
2140
2182
  res.status(500).json({ success: false, error: err_1 });
2141
2183
  next(err_1);
2142
2184
  return [3 /*break*/, 3];
@@ -2280,5 +2322,5 @@ function isVerbose () {
2280
2322
  return ['true', '1', 'yes', 'on'].includes(envVerbose.toLowerCase());
2281
2323
  }
2282
2324
 
2283
- export { A, AggregateBuilder, C6C, C6Constants, ConditionBuilder, DELETE, DeleteQueryBuilder, Executor, ExpressHandler, F, GET, HttpExecutor, JoinBuilder, POST, PUT, PaginationBuilder, PostQueryBuilder, SelectQueryBuilder, SqlExecutor, TestRestfulResponse, UpdateQueryBuilder, apiRequestCache, axiosInstance, bbox, checkAllRequestsComplete, checkCache, clearCache, convertForRequestBody, convertHexIfBinary, determineRuntimeJsType, distSphere, eFetchDependencies, error, fieldEq, getEnvVar, getPrimaryKeyTypes, group, info, isLocal, isNode, isTest, isVerbose, normalizeSingularRequest, onError, onSuccess, removeInvalidKeys, removePrefixIfExists, restOrm, restRequest, sortAndSerializeQueryObject, stContains, timeout, toastOptions, toastOptionsDevs, userCustomClearCache, warn };
2325
+ export { A, AggregateBuilder, C6C, C6Constants, ConditionBuilder, DELETE, DeleteQueryBuilder, Executor, ExpressHandler, F, GET, HttpExecutor, JoinBuilder, POST, PUT, PaginationBuilder, PostQueryBuilder, SelectQueryBuilder, SqlExecutor, TestRestfulResponse, UpdateQueryBuilder, apiRequestCache, bbox, carbonNodeQsStringify, checkAllRequestsComplete, checkCache, clearCache, convertForRequestBody, convertHexIfBinary, determineRuntimeJsType, distSphere, eFetchDependencies, error, fieldEq, getEnvVar, getPrimaryKeyTypes, group, info, isLocal, isNode, isTest, isVerbose, normalizeSingularRequest, onError, onSuccess, removeInvalidKeys, removePrefixIfExists, restOrm, restRequest, sortAndSerializeQueryObject, stContains, timeout, toastOptions, toastOptionsDevs, userCustomClearCache, warn };
2284
2326
  //# sourceMappingURL=index.esm.js.map