@carbonorm/carbonnode 3.0.2 → 3.0.4

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
@@ -1,6 +1,6 @@
1
1
  import axios from 'axios';
2
2
  import Qs from 'qs';
3
- import { __assign, __awaiter, __spreadArray, __generator, __extends } from 'tslib';
3
+ import { __assign, __awaiter, __generator, __extends, __spreadArray } from 'tslib';
4
4
  import { toast } from 'react-toastify';
5
5
 
6
6
  var C6Constants = {
@@ -236,65 +236,70 @@ function convertForRequestBody (restfulObject, tableName, C6, regexErrorHandler)
236
236
  if (regexErrorHandler === void 0) { regexErrorHandler = alert; }
237
237
  var payload = {};
238
238
  var tableNames = Array.isArray(tableName) ? tableName : [tableName];
239
- var tableDefinitions = [];
240
- tableNames.forEach(function (tableName) {
241
- var tableDefinition = Object.values(C6.TABLES).find(function (tableDefinition) { return tableDefinition.TABLE_NAME === tableName; });
242
- if (undefined === tableDefinition) {
243
- console.error("Table name (".concat(tableName, ") is not found in the C6.TABLES object."), C6.TABLES);
244
- throw new Error("Table name (".concat(tableName, ") is not found in the C6.TABLES object."));
239
+ var tableDefinitions = tableNames.map(function (name) {
240
+ var tableDefinition = Object.values(C6.TABLES).find(function (t) { return t.TABLE_NAME === name; });
241
+ if (!tableDefinition) {
242
+ console.error("Table name (".concat(name, ") is not found in the C6.TABLES object."), C6.TABLES);
243
+ throw new Error("Table name (".concat(name, ") is not found in the C6.TABLES object."));
245
244
  }
246
- tableDefinitions.push(tableDefinition);
245
+ return tableDefinition;
247
246
  });
248
- tableDefinitions.forEach(function (tableDefinition) {
249
- Object.keys(restfulObject).forEach(function (value) {
250
- var _a;
247
+ for (var _i = 0, tableDefinitions_1 = tableDefinitions; _i < tableDefinitions_1.length; _i++) {
248
+ var tableDefinition = tableDefinitions_1[_i];
249
+ var _loop_1 = function (value) {
251
250
  var shortReference = value.toUpperCase();
252
- switch (value) {
253
- case C6Constants.GET:
254
- case C6Constants.POST:
255
- case C6Constants.UPDATE:
256
- case C6Constants.REPLACE:
257
- case C6Constants.DELETE:
258
- case C6Constants.WHERE:
259
- case C6Constants.JOIN:
260
- case C6Constants.PAGINATION:
261
- if (Array.isArray(restfulObject[value])) {
262
- payload[value] = restfulObject[value].sort();
263
- }
264
- else if (typeof restfulObject[value] === 'object' && restfulObject[value] !== null) {
265
- payload[value] = Object.keys(restfulObject[value])
266
- .sort()
267
- .reduce(function (acc, key) {
268
- var _a;
269
- return (__assign(__assign({}, acc), (_a = {}, _a[key] = restfulObject[value][key], _a)));
270
- }, {});
271
- }
272
- return;
251
+ if ([
252
+ C6Constants.GET,
253
+ C6Constants.POST,
254
+ C6Constants.UPDATE,
255
+ C6Constants.REPLACE,
256
+ C6Constants.DELETE,
257
+ C6Constants.WHERE,
258
+ C6Constants.JOIN,
259
+ C6Constants.PAGINATION
260
+ ].includes(value)) {
261
+ var val_1 = restfulObject[value];
262
+ if (Array.isArray(val_1)) {
263
+ payload[value] = val_1.sort();
264
+ }
265
+ else if (typeof val_1 === 'object' && val_1 !== null) {
266
+ payload[value] = Object.keys(val_1)
267
+ .sort()
268
+ .reduce(function (acc, key) {
269
+ var _a;
270
+ return (__assign(__assign({}, acc), (_a = {}, _a[key] = val_1[key], _a)));
271
+ }, {});
272
+ }
273
+ return "continue";
273
274
  }
274
275
  if (shortReference in tableDefinition) {
275
- var longName_1 = tableDefinition[shortReference];
276
- payload[longName_1] = restfulObject[value];
277
- var regexValidations_1 = tableDefinition.REGEX_VALIDATION[longName_1];
278
- if (regexValidations_1 instanceof RegExp) {
279
- if (false === regexValidations_1.test(restfulObject[value])) {
280
- regexErrorHandler('Failed to match regex (' + regexValidations_1 + ') for column (' + longName_1 + ')');
281
- throw Error('Failed to match regex (' + regexValidations_1 + ') for column (' + longName_1 + ')');
276
+ var longName = tableDefinition[shortReference];
277
+ var columnValue = restfulObject[value];
278
+ payload[longName] = columnValue;
279
+ var regexValidations = tableDefinition.REGEX_VALIDATION[longName];
280
+ if (regexValidations instanceof RegExp) {
281
+ if (!regexValidations.test(columnValue)) {
282
+ regexErrorHandler("Failed to match regex (".concat(regexValidations, ") for column (").concat(longName, ")"));
283
+ throw new Error("Failed to match regex (".concat(regexValidations, ") for column (").concat(longName, ")"));
282
284
  }
283
285
  }
284
- else if (typeof regexValidations_1 === 'object' && regexValidations_1 !== null) {
285
- (_a = Object.keys(regexValidations_1)) === null || _a === void 0 ? void 0 : _a.forEach(function (errorMessage) {
286
- var regex = regexValidations_1[errorMessage];
287
- if (false === regex.test(restfulObject[value])) {
288
- var devErrorMessage = 'Failed to match regex (' + regex + ') for column (' + longName_1 + ')';
289
- regexErrorHandler(errorMessage !== null && errorMessage !== void 0 ? errorMessage : devErrorMessage);
290
- throw Error(devErrorMessage);
286
+ else if (typeof regexValidations === 'object' && regexValidations !== null) {
287
+ for (var errorMessage in regexValidations) {
288
+ var regex = regexValidations[errorMessage];
289
+ if (!regex.test(columnValue)) {
290
+ var devErrorMessage = "Failed to match regex (".concat(regex, ") for column (").concat(longName, ")");
291
+ regexErrorHandler(errorMessage || devErrorMessage);
292
+ throw new Error(devErrorMessage);
291
293
  }
292
- });
294
+ }
293
295
  }
294
296
  }
295
- });
296
- return true;
297
- });
297
+ };
298
+ for (var _a = 0, _b = Object.keys(restfulObject); _a < _b.length; _a++) {
299
+ var value = _b[_a];
300
+ _loop_1(value);
301
+ }
302
+ }
298
303
  return Object.keys(payload)
299
304
  .sort()
300
305
  .reduce(function (acc, key) {
@@ -311,31 +316,33 @@ var isNode = typeof process !== 'undefined' && !!((_a = process.versions) === nu
311
316
  */
312
317
  function restRequest(config) {
313
318
  var _this = this;
314
- return function () {
315
- var args_1 = [];
316
- for (var _i = 0; _i < arguments.length; _i++) {
317
- args_1[_i] = arguments[_i];
318
- }
319
- return __awaiter(_this, __spreadArray([], args_1, true), void 0, function (request) {
320
- var SqlExecutor, executor, HttpExecutor, http;
321
- if (request === void 0) { request = {}; }
322
- return __generator(this, function (_a) {
323
- switch (_a.label) {
324
- case 0:
325
- if (!(isNode && config.mysqlPool)) return [3 /*break*/, 2];
326
- return [4 /*yield*/, Promise.resolve().then(function () { return SqlExecutor$1; })];
327
- case 1:
328
- SqlExecutor = (_a.sent()).SqlExecutor;
329
- executor = new SqlExecutor(config, request);
330
- return [2 /*return*/, executor.execute()];
331
- case 2: return [4 /*yield*/, Promise.resolve().then(function () { return HttpExecutor$1; })];
332
- case 3:
333
- HttpExecutor = (_a.sent()).HttpExecutor;
334
- http = new HttpExecutor(config, request);
335
- return [2 /*return*/, http.execute()];
336
- }
337
- });
319
+ return function (request) { return __awaiter(_this, void 0, void 0, function () {
320
+ var SqlExecutor, executor, HttpExecutor, http;
321
+ return __generator(this, function (_a) {
322
+ switch (_a.label) {
323
+ case 0:
324
+ if (!(isNode && config.mysqlPool)) return [3 /*break*/, 2];
325
+ return [4 /*yield*/, Promise.resolve().then(function () { return SqlExecutor$1; })];
326
+ case 1:
327
+ SqlExecutor = (_a.sent()).SqlExecutor;
328
+ executor = new SqlExecutor(config, request);
329
+ return [2 /*return*/, executor.execute()];
330
+ case 2: return [4 /*yield*/, Promise.resolve().then(function () { return HttpExecutor$1; })];
331
+ case 3:
332
+ HttpExecutor = (_a.sent()).HttpExecutor;
333
+ http = new HttpExecutor(config, request);
334
+ return [2 /*return*/, http.execute()];
335
+ }
338
336
  });
337
+ }); };
338
+ }
339
+
340
+ function restOrm(config) {
341
+ return {
342
+ Get: restRequest(__assign(__assign({}, config), { requestMethod: "GET" })),
343
+ Put: restRequest(__assign(__assign({}, config), { requestMethod: "PUT" })),
344
+ Post: restRequest(__assign(__assign({}, config), { requestMethod: "POST" })),
345
+ Delete: restRequest(__assign(__assign({}, config), { requestMethod: "DELETE" })),
339
346
  };
340
347
  }
341
348
 
@@ -512,15 +519,6 @@ function buildSelectQuery(table, primary, args, isSubSelect) {
512
519
  return sql;
513
520
  }
514
521
 
515
- var Executor = /** @class */ (function () {
516
- function Executor(config, request) {
517
- if (request === void 0) { request = {}; }
518
- this.config = config;
519
- this.request = request;
520
- }
521
- return Executor;
522
- }());
523
-
524
522
  function getEnvVar(key, fallback) {
525
523
  if (fallback === void 0) { fallback = ''; }
526
524
  // Vite-style injection
@@ -536,15 +534,67 @@ function getEnvVar(key, fallback) {
536
534
  return fallback;
537
535
  }
538
536
 
537
+ var envVerbose = getEnvVar('VERBOSE') || getEnvVar('REACT_APP_VERBOSE') || getEnvVar('VITE_VERBOSE') || '';
538
+ var isVerbose = ['true', '1', 'yes', 'on'].includes(envVerbose.toLowerCase());
539
+
540
+ var Executor = /** @class */ (function () {
541
+ function Executor(config, request) {
542
+ this.config = config;
543
+ this.request = request;
544
+ }
545
+ Executor.prototype.runLifecycleHooks = function (phase, args) {
546
+ return __awaiter(this, void 0, void 0, function () {
547
+ var lifecycleGroup, _i, _a, _b, key, fn, err_1;
548
+ var _c;
549
+ return __generator(this, function (_d) {
550
+ switch (_d.label) {
551
+ case 0:
552
+ lifecycleGroup = (_c = this.config.restModel.LIFECYCLE_HOOKS[this.config.requestMethod]) === null || _c === void 0 ? void 0 : _c[phase];
553
+ if (!lifecycleGroup)
554
+ return [2 /*return*/];
555
+ _i = 0, _a = Object.entries(lifecycleGroup);
556
+ _d.label = 1;
557
+ case 1:
558
+ if (!(_i < _a.length)) return [3 /*break*/, 6];
559
+ _b = _a[_i], key = _b[0], fn = _b[1];
560
+ if (!(typeof fn === "function")) return [3 /*break*/, 5];
561
+ if (isVerbose || args.request.debug) {
562
+ console.groupCollapsed("[LIFECYCLE] ".concat(this.config.requestMethod, ".").concat(String(phase), ":").concat(key));
563
+ console.log("config:", args.config);
564
+ console.log("request:", args.request);
565
+ if ("response" in args) {
566
+ console.log("response:", args.response);
567
+ }
568
+ console.groupEnd();
569
+ }
570
+ _d.label = 2;
571
+ case 2:
572
+ _d.trys.push([2, 4, , 5]);
573
+ return [4 /*yield*/, fn(args)];
574
+ case 3:
575
+ _d.sent();
576
+ return [3 /*break*/, 5];
577
+ case 4:
578
+ err_1 = _d.sent();
579
+ console.error("[LIFECYCLE ERROR] ".concat(this.config.requestMethod, ".").concat(String(phase), ":").concat(key), err_1);
580
+ throw err_1;
581
+ case 5:
582
+ _i++;
583
+ return [3 /*break*/, 1];
584
+ case 6: return [2 /*return*/];
585
+ }
586
+ });
587
+ });
588
+ };
589
+ return Executor;
590
+ }());
591
+
539
592
  var isDevelopment = getEnvVar('NODE_ENV', '') === 'development';
540
593
 
541
594
  var isTest = getEnvVar('JEST_WORKER_ID') || getEnvVar('NODE_ENV') === 'test'
542
595
  || getEnvVar('REACT_APP_TEST') === 'true' || getEnvVar('VITE_TEST') === 'true'
543
596
  || getEnvVar('MODE') === 'test' || getEnvVar('VITE_TEST_MODE') === 'true';
544
597
 
545
- var envVerbose = getEnvVar('VERBOSE') || getEnvVar('REACT_APP_VERBOSE') || getEnvVar('VITE_VERBOSE') || '';
546
- var isVerbose = ['true', '1', 'yes', 'on'].includes(envVerbose.toLowerCase());
547
-
548
598
  var eFetchDependencies;
549
599
  (function (eFetchDependencies) {
550
600
  eFetchDependencies[eFetchDependencies["NONE"] = 0] = "NONE";
@@ -557,23 +607,11 @@ var eFetchDependencies;
557
607
  eFetchDependencies[eFetchDependencies["RECURSIVE"] = 8] = "RECURSIVE";
558
608
  })(eFetchDependencies || (eFetchDependencies = {}));
559
609
 
560
- /**
561
- * the first argument ....
562
- *
563
- * Our api returns a zero argument function iff the method is get and the previous request reached the predefined limit.
564
- * This function can be aliased as GetNextPageOfResults(). If the end is reached undefined will be returned.
565
- *
566
- *
567
- * For POST, PUT, and DELETE requests one can expect the primary key of the new or modified index, or a boolean success
568
- * indication if no primary key exists.
569
- **/
610
+ // Refined TypeScript types for CarbonORM
570
611
  var POST = 'POST';
571
612
  var PUT = 'PUT';
572
613
  var GET = 'GET';
573
614
  var DELETE = 'DELETE';
574
- function isPromise(x) {
575
- return Object(x).constructor === Promise;
576
- }
577
615
 
578
616
  var toastOptions = {
579
617
  position: "bottom-left",
@@ -685,14 +723,68 @@ var HttpExecutor = /** @class */ (function (_super) {
685
723
  function HttpExecutor() {
686
724
  return _super !== null && _super.apply(this, arguments) || this;
687
725
  }
726
+ HttpExecutor.prototype.putState = function (response, request, callback) {
727
+ var _a, _b;
728
+ (_a = this.config.reactBootstrap) === null || _a === void 0 ? void 0 : _a.updateRestfulObjectArrays({
729
+ callback: callback,
730
+ dataOrCallback: [
731
+ removeInvalidKeys(__assign(__assign({}, request), (_b = response === null || response === void 0 ? void 0 : response.data) === null || _b === void 0 ? void 0 : _b.rest), this.config.C6.TABLES)
732
+ ],
733
+ stateKey: this.config.restModel.TABLE_NAME,
734
+ uniqueObjectId: this.config.restModel.PRIMARY_SHORT
735
+ });
736
+ };
737
+ HttpExecutor.prototype.postState = function (response, request, callback) {
738
+ var _this = this;
739
+ var _a, _b, _c;
740
+ if (1 !== this.config.restModel.PRIMARY_SHORT.length) {
741
+ console.error("C6 received unexpected result's given the primary key length");
742
+ }
743
+ else {
744
+ var pk = this.config.restModel.PRIMARY_SHORT[0];
745
+ // TODO - should overrides be handled differently? Why override: (react/php), driver missmatches, aux data..
746
+ // @ts-ignore - this is technically a correct error, but we allow it anyway...
747
+ request[pk] = (_a = response.data) === null || _a === void 0 ? void 0 : _a.created;
748
+ }
749
+ (_b = this.config.reactBootstrap) === null || _b === void 0 ? void 0 : _b.updateRestfulObjectArrays({
750
+ callback: callback,
751
+ dataOrCallback: undefined !== request.dataInsertMultipleRows
752
+ ? request.dataInsertMultipleRows.map(function (request, index) {
753
+ var _a;
754
+ return removeInvalidKeys(__assign(__assign({}, request), (index === 0 ? (_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.rest : {})), _this.config.C6.TABLES);
755
+ })
756
+ : [
757
+ removeInvalidKeys(__assign(__assign({}, request), (_c = response === null || response === void 0 ? void 0 : response.data) === null || _c === void 0 ? void 0 : _c.rest), this.config.C6.TABLES)
758
+ ],
759
+ stateKey: this.config.restModel.TABLE_NAME,
760
+ uniqueObjectId: this.config.restModel.PRIMARY_SHORT
761
+ });
762
+ };
763
+ HttpExecutor.prototype.deleteState = function (_response, request, callback) {
764
+ var _a;
765
+ (_a = this.config.reactBootstrap) === null || _a === void 0 ? void 0 : _a.deleteRestfulObjectArrays({
766
+ callback: callback,
767
+ dataOrCallback: [
768
+ request,
769
+ ],
770
+ stateKey: this.config.restModel.TABLE_NAME,
771
+ uniqueObjectId: this.config.restModel.PRIMARY_SHORT
772
+ });
773
+ };
688
774
  HttpExecutor.prototype.execute = function () {
689
775
  return __awaiter(this, void 0, void 0, function () {
690
- var _a, C6, axios, restURL, withCredentials, restModel, requestMethod, queryCallback, responseCallback, skipPrimaryCheck, clearCache, tableName, fullTableList, operatingTableFullName, operatingTable, tables, query, apiRequest;
776
+ var _a, C6, axios, restURL, withCredentials, restModel, reactBootstrap, requestMethod, skipPrimaryCheck, clearCache, tableName, fullTableList, operatingTableFullName, operatingTable, tables, query, apiRequest;
691
777
  var _this = this;
692
778
  return __generator(this, function (_b) {
693
779
  switch (_b.label) {
694
780
  case 0:
695
- _a = this.config, C6 = _a.C6, axios = _a.axios, restURL = _a.restURL, withCredentials = _a.withCredentials, restModel = _a.restModel, requestMethod = _a.requestMethod, queryCallback = _a.queryCallback, responseCallback = _a.responseCallback, skipPrimaryCheck = _a.skipPrimaryCheck, clearCache = _a.clearCache;
781
+ _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;
782
+ return [4 /*yield*/, this.runLifecycleHooks("beforeProcessing", {
783
+ config: this.config,
784
+ request: this.request,
785
+ })];
786
+ case 1:
787
+ _b.sent();
696
788
  tableName = restModel.TABLE_NAME;
697
789
  fullTableList = Array.isArray(tableName) ? tableName : [tableName];
698
790
  operatingTableFullName = fullTableList[0];
@@ -713,22 +805,16 @@ var HttpExecutor = /** @class */ (function (_super) {
713
805
  console.groupCollapsed('%c API: (' + requestMethod + ') Request for (' + tableName + ')', 'color: #0c0');
714
806
  console.log('request', this.request);
715
807
  console.groupEnd();
716
- if ('function' === typeof queryCallback) {
717
- query = queryCallback(this.request); // obj or obj[]
718
- }
719
- else {
720
- query = queryCallback;
721
- }
722
- if (undefined === query || null === query) {
723
- if (this.request.debug && isDevelopment) {
724
- toast.warning("DEV: queryCallback returned undefined, signaling in Custom Cache. (returning null)", toastOptionsDevs);
725
- }
726
- console.groupCollapsed('%c API: (' + requestMethod + ') Request Query for (' + tableName + ') undefined, returning null (will not fire ajax)!', 'color: #c00');
808
+ // an undefined query would indicate queryCallback returned undefined,
809
+ // thus the request shouldn't fire as is in custom cache
810
+ if (undefined === this.request || null === this.request) {
811
+ console.groupCollapsed('%c API: (' + requestMethod + ') Request Query for (' + tableName + ') undefined, returning null (will not fire)!', 'color: #c00');
727
812
  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');
728
813
  console.trace();
729
814
  console.groupEnd();
730
815
  return [2 /*return*/, null];
731
816
  }
817
+ query = this.request;
732
818
  if (C6.GET === requestMethod) {
733
819
  if (undefined === query[C6.PAGINATION]) {
734
820
  query[C6.PAGINATION] = {};
@@ -866,51 +952,36 @@ var HttpExecutor = /** @class */ (function (_super) {
866
952
  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');
867
953
  console.trace();
868
954
  console.groupEnd();
869
- axiosActiveRequest = (_e = axios)[requestMethod.toLowerCase()].apply(_e, __spreadArray([restRequestUri], ((function () {
870
- // @link - https://axios-http.com/docs/instance
871
- // How configuration vs data is passed is variable, use documentation above for reference
872
- if (requestMethod === GET) {
873
- return [{
874
- withCredentials: withCredentials,
875
- params: query
876
- }];
877
- }
878
- else if (requestMethod === POST) {
879
- if (undefined !== dataInsertMultipleRows) {
880
- return [
881
- dataInsertMultipleRows.map(function (data) {
882
- return convertForRequestBody(data, fullTableList, C6, function (message) { return toast.error(message, toastOptions); });
883
- }),
884
- {
885
- withCredentials: withCredentials,
886
- }
887
- ];
888
- }
889
- return [
890
- convertForRequestBody(query, fullTableList, C6, function (message) { return toast.error(message, toastOptions); }),
891
- {
892
- withCredentials: withCredentials,
893
- }
894
- ];
895
- }
896
- else if (requestMethod === PUT) {
897
- return [
898
- convertForRequestBody(query, fullTableList, C6, function (message) { return toast.error(message, toastOptions); }),
899
- {
900
- withCredentials: withCredentials,
955
+ this.runLifecycleHooks("beforeExecution", {
956
+ config: this.config,
957
+ request: this.request
958
+ });
959
+ axiosActiveRequest = (_e = axios)[requestMethod.toLowerCase()].apply(_e, __spreadArray([restRequestUri], (function () {
960
+ var convert = function (data) {
961
+ return convertForRequestBody(data, fullTableList, C6, function (message) { return toast.error(message, toastOptions); });
962
+ };
963
+ var baseConfig = {
964
+ withCredentials: withCredentials,
965
+ };
966
+ switch (requestMethod) {
967
+ case GET:
968
+ return [__assign(__assign({}, baseConfig), { params: query })];
969
+ case POST:
970
+ if (dataInsertMultipleRows !== undefined) {
971
+ return [
972
+ dataInsertMultipleRows.map(convert),
973
+ baseConfig
974
+ ];
901
975
  }
902
- ];
976
+ return [convert(query), baseConfig];
977
+ case PUT:
978
+ return [convert(query), baseConfig];
979
+ case DELETE:
980
+ return [__assign(__assign({}, baseConfig), { data: convert(query) })];
981
+ default:
982
+ throw new Error("The request method (".concat(requestMethod, ") was not recognized."));
903
983
  }
904
- else if (requestMethod === DELETE) {
905
- return [{
906
- withCredentials: withCredentials,
907
- data: convertForRequestBody(query, fullTableList, C6, function (message) { return toast.error(message, toastOptions); })
908
- }];
909
- }
910
- else {
911
- throw new Error('The request method (' + requestMethod + ') was not recognized.');
912
- }
913
- })()), false));
984
+ })(), false));
914
985
  if (cachingConfirmed) {
915
986
  // push to cache so we do not repeat the request
916
987
  apiRequestCache.push({
@@ -924,12 +995,13 @@ var HttpExecutor = /** @class */ (function (_super) {
924
995
  // returning the promise with this then is important for tests. todo - we could make that optional.
925
996
  // https://rapidapi.com/guides/axios-async-await
926
997
  return [2 /*return*/, axiosActiveRequest.then(function (response) { return __awaiter(_this, void 0, void 0, function () {
927
- var cacheIndex, responseData_1, dependencies_1, fetchReferences_1, apiRequestPromises, _loop_1, _a, _b, _c, _i, tableToFetch;
998
+ var cacheIndex, callback, responseData_1, dependencies_1, fetchReferences_1, apiRequestPromises, _loop_1, _a, _b, _c, _i, tableToFetch;
928
999
  var _this = this;
929
1000
  var _d, _e, _f, _g, _h, _j, _k;
930
1001
  return __generator(this, function (_l) {
931
1002
  switch (_l.label) {
932
1003
  case 0:
1004
+ // noinspection SuspiciousTypeOfGuard
933
1005
  if (typeof response.data === 'string') {
934
1006
  if (isTest) {
935
1007
  console.trace();
@@ -943,6 +1015,12 @@ var HttpExecutor = /** @class */ (function (_super) {
943
1015
  // only cache get method requests
944
1016
  apiRequestCache[cacheIndex].response = response;
945
1017
  }
1018
+ this.runLifecycleHooks("afterExecution", {
1019
+ config: this.config,
1020
+ request: this.request,
1021
+ response: response
1022
+ });
1023
+ // todo - this feels dumb now, but i digress
946
1024
  apiResponse = TestRestfulResponse(response, success, error);
947
1025
  if (false === apiResponse) {
948
1026
  if (debug && isDevelopment) {
@@ -950,9 +1028,34 @@ var HttpExecutor = /** @class */ (function (_super) {
950
1028
  }
951
1029
  return [2 /*return*/, response];
952
1030
  }
953
- // stateful operations are done in the response callback - its leverages rest generated functions
954
- if (responseCallback) {
955
- responseCallback(response, this.request, apiResponse);
1031
+ callback = function () { return _this.runLifecycleHooks("afterCommit", {
1032
+ config: _this.config,
1033
+ request: _this.request,
1034
+ response: response
1035
+ }); };
1036
+ if (undefined !== reactBootstrap && response) {
1037
+ switch (requestMethod) {
1038
+ case GET:
1039
+ reactBootstrap.updateRestfulObjectArrays({
1040
+ dataOrCallback: Array.isArray(response.data.rest) ? response.data.rest : [response.data.rest],
1041
+ stateKey: this.config.restModel.TABLE_NAME,
1042
+ uniqueObjectId: this.config.restModel.PRIMARY_SHORT,
1043
+ callback: callback
1044
+ });
1045
+ break;
1046
+ case POST:
1047
+ this.postState(response, this.request, callback);
1048
+ break;
1049
+ case PUT:
1050
+ this.putState(response, this.request, callback);
1051
+ break;
1052
+ case DELETE:
1053
+ this.deleteState(response, this.request, callback);
1054
+ break;
1055
+ }
1056
+ }
1057
+ else {
1058
+ callback();
956
1059
  }
957
1060
  if (!(C6.GET === requestMethod)) return [3 /*break*/, 6];
958
1061
  responseData_1 = response.data;
@@ -1178,7 +1281,7 @@ var HttpExecutor = /** @class */ (function (_super) {
1178
1281
  });
1179
1282
  }); };
1180
1283
  return [4 /*yield*/, apiRequest()];
1181
- case 1: return [2 /*return*/, _b.sent()];
1284
+ case 2: return [2 /*return*/, _b.sent()];
1182
1285
  }
1183
1286
  });
1184
1287
  });
@@ -1446,5 +1549,5 @@ function onError(message) {
1446
1549
  toast.error(message, isDevelopment ? toastOptionsDevs : toastOptions);
1447
1550
  }
1448
1551
 
1449
- export { C6Constants, DELETE, Executor, GET, HttpExecutor, POST, PUT, SqlExecutor, TestRestfulResponse, apiRequestCache, axiosInstance, buildAggregateField, buildBooleanJoinedConditions, buildSelectQuery, checkAllRequestsComplete, checkCache, clearCache, convertForRequestBody, determineRuntimeJsType, eFetchDependencies, error, getEnvVar, getPrimaryKeyTypes, group, info, isDevelopment as isLocal, isNode, isPromise, isTest, isVerbose, onError, onSuccess, removeInvalidKeys, removePrefixIfExists, restRequest, sortAndSerializeQueryObject, timeout, toastOptions, toastOptionsDevs, userCustomClearCache, warn };
1552
+ export { C6Constants, DELETE, Executor, GET, HttpExecutor, POST, PUT, SqlExecutor, TestRestfulResponse, apiRequestCache, axiosInstance, buildAggregateField, buildBooleanJoinedConditions, buildSelectQuery, checkAllRequestsComplete, checkCache, clearCache, convertForRequestBody, determineRuntimeJsType, eFetchDependencies, error, getEnvVar, getPrimaryKeyTypes, group, info, isDevelopment as isLocal, isNode, isTest, isVerbose, onError, onSuccess, removeInvalidKeys, removePrefixIfExists, restOrm, restRequest, sortAndSerializeQueryObject, timeout, toastOptions, toastOptionsDevs, userCustomClearCache, warn };
1450
1553
  //# sourceMappingURL=index.esm.js.map