@carbonorm/carbonnode 3.0.9 → 3.0.11

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.cjs.js CHANGED
@@ -311,8 +311,7 @@ function convertForRequestBody (restfulObject, tableName, C6, regexErrorHandler)
311
311
  }, {});
312
312
  }
313
313
 
314
- var _a;
315
- var isNode = typeof process !== 'undefined' && !!((_a = process.versions) === null || _a === void 0 ? void 0 : _a.node);
314
+ var isNode = function () { var _a; return typeof process !== 'undefined' && !!((_a = process.versions) === null || _a === void 0 ? void 0 : _a.node); };
316
315
 
317
316
  /**
318
317
  * Facade: routes API calls to SQL or HTTP executors based on runtime context.
@@ -325,7 +324,7 @@ function restRequest(configX) {
325
324
  switch (_a.label) {
326
325
  case 0:
327
326
  config = typeof configX === "function" ? configX() : configX;
328
- if (!(isNode && config.mysqlPool)) return [3 /*break*/, 2];
327
+ if (!(isNode() && config.mysqlPool)) return [3 /*break*/, 2];
329
328
  return [4 /*yield*/, Promise.resolve().then(function () { return SqlExecutor$1; })];
330
329
  case 1:
331
330
  SqlExecutor = (_a.sent()).SqlExecutor;
@@ -342,12 +341,11 @@ function restRequest(configX) {
342
341
  }
343
342
 
344
343
  function restOrm(config) {
345
- return {
346
- Get: restRequest(function () { return (tslib.__assign(tslib.__assign({}, config()), { requestMethod: "GET" })); }),
347
- Put: restRequest(function () { return (tslib.__assign(tslib.__assign({}, config()), { requestMethod: "PUT" })); }),
348
- Post: restRequest(function () { return (tslib.__assign(tslib.__assign({}, config()), { requestMethod: "POST" })); }),
349
- Delete: restRequest(function () { return (tslib.__assign(tslib.__assign({}, config()), { requestMethod: "DELETE" })); }),
350
- };
344
+ var methods = ["GET", "PUT", "POST", "DELETE"];
345
+ return Object.fromEntries(methods.map(function (method) { return [
346
+ method[0] + method.slice(1).toLowerCase(), // Capitalize e.g. "Get"
347
+ restRequest(function () { return (tslib.__assign(tslib.__assign({}, config()), { requestMethod: method })); })
348
+ ]; }));
351
349
  }
352
350
 
353
351
  function timeout(shouldContinueAfterTimeout, cb, timeoutMs) {
@@ -831,458 +829,466 @@ var HttpExecutor = /** @class */ (function (_super) {
831
829
  var _a, debug, _b, cacheResults, dataInsertMultipleRows, success, _c, fetchDependencies, _d, error, querySerialized, cacheResult, cachingConfirmed, cacheCheck, cacheCheck, addBackPK, apiResponse, returnGetNextPageFunction, restRequestUri, needsConditionOrPrimaryCheck, TABLES, primaryKey, removedPkValue_1, axiosActiveRequest;
832
830
  var _e;
833
831
  var _this = this;
834
- var _f, _g, _h, _j, _k, _l;
835
- return tslib.__generator(this, function (_m) {
836
- _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 ? exports.eFetchDependencies.NONE : _c, _d = _a.error, error = _d === void 0 ? "An unexpected API error occurred!" : _d;
837
- if (C6.GET === requestMethod
838
- && undefined !== ((_f = query === null || query === void 0 ? void 0 : query[C6.PAGINATION]) === null || _f === void 0 ? void 0 : _f[C6.PAGE])
839
- && 1 !== query[C6.PAGINATION][C6.PAGE]) {
840
- console.groupCollapsed('Request on table (' + tableName + ') is firing for page (' + query[C6.PAGINATION][C6.PAGE] + '), please wait!');
841
- console.log('Request Data (note you may see the success and/or error prompt):', this.request);
842
- console.trace();
843
- console.groupEnd();
844
- }
845
- querySerialized = sortAndSerializeQueryObject(tables, query !== null && query !== void 0 ? query : {});
846
- cacheResult = exports.apiRequestCache.find(function (cache) { return cache.requestArgumentsSerialized === querySerialized; });
847
- cachingConfirmed = false;
848
- // determine if we need to paginate.
849
- if (requestMethod === C6.GET) {
850
- if (undefined === (query === null || query === void 0 ? void 0 : query[C6.PAGINATION])) {
851
- if (undefined === query || null === query) {
852
- query = {};
832
+ var _f, _g, _h, _j, _k, _l, _m, _o;
833
+ return tslib.__generator(this, function (_p) {
834
+ switch (_p.label) {
835
+ case 0:
836
+ _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 ? exports.eFetchDependencies.NONE : _c, _d = _a.error, error = _d === void 0 ? "An unexpected API error occurred!" : _d;
837
+ if (C6.GET === requestMethod
838
+ && undefined !== ((_f = query === null || query === void 0 ? void 0 : query[C6.PAGINATION]) === null || _f === void 0 ? void 0 : _f[C6.PAGE])
839
+ && 1 !== query[C6.PAGINATION][C6.PAGE]) {
840
+ console.groupCollapsed('Request on table (' + tableName + ') is firing for page (' + query[C6.PAGINATION][C6.PAGE] + '), please wait!');
841
+ console.log('Request Data (note you may see the success and/or error prompt):', this.request);
842
+ console.trace();
843
+ console.groupEnd();
853
844
  }
854
- query[C6.PAGINATION] = {};
855
- }
856
- query[C6.PAGINATION][C6.PAGE] = query[C6.PAGINATION][C6.PAGE] || 1;
857
- query[C6.PAGINATION][C6.LIMIT] = query[C6.PAGINATION][C6.LIMIT] || 100;
858
- // this will evaluate true most the time
859
- if (true === cacheResults) {
860
- // just find the next, non-fetched, page and return a function to request it
861
- if (undefined !== cacheResult) {
862
- do {
863
- cacheCheck = checkCache(cacheResult, requestMethod, tableName, this.request);
864
- if (false !== cacheCheck) {
865
- return [2 /*return*/, cacheCheck];
866
- }
867
- // this line incrementing page is why we return recursively
868
- ++query[C6.PAGINATION][C6.PAGE];
869
- // this json stringify is to capture the new page number
870
- querySerialized = sortAndSerializeQueryObject(tables, query !== null && query !== void 0 ? query : {});
871
- cacheResult = exports.apiRequestCache.find(function (cache) { return cache.requestArgumentsSerialized === querySerialized; });
872
- } while (undefined !== cacheResult);
873
- if (debug && isDevelopment) {
874
- reactToastify.toast.warning("DEVS: Request in cache. (" + exports.apiRequestCache.findIndex(function (cache) { return cache.requestArgumentsSerialized === querySerialized; }) + "). Returning function to request page (" + query[C6.PAGINATION][C6.PAGE] + ")", toastOptionsDevs);
845
+ querySerialized = sortAndSerializeQueryObject(tables, query !== null && query !== void 0 ? query : {});
846
+ cacheResult = exports.apiRequestCache.find(function (cache) { return cache.requestArgumentsSerialized === querySerialized; });
847
+ cachingConfirmed = false;
848
+ if (!(requestMethod === C6.GET)) return [3 /*break*/, 9];
849
+ if (undefined === (query === null || query === void 0 ? void 0 : query[C6.PAGINATION])) {
850
+ if (undefined === query || null === query) {
851
+ query = {};
875
852
  }
876
- // @ts-ignore - this is an incorrect warning on TS, it's well typed
877
- return [2 /*return*/, apiRequest];
853
+ query[C6.PAGINATION] = {};
878
854
  }
855
+ query[C6.PAGINATION][C6.PAGE] = query[C6.PAGINATION][C6.PAGE] || 1;
856
+ query[C6.PAGINATION][C6.LIMIT] = query[C6.PAGINATION][C6.LIMIT] || 100;
857
+ if (!(true === cacheResults)) return [3 /*break*/, 7];
858
+ if (!(undefined !== cacheResult)) return [3 /*break*/, 6];
859
+ _p.label = 1;
860
+ case 1:
861
+ cacheCheck = checkCache(cacheResult, requestMethod, tableName, this.request);
862
+ if (!(false !== cacheCheck)) return [3 /*break*/, 3];
863
+ return [4 /*yield*/, cacheCheck];
864
+ case 2: return [2 /*return*/, (_g = (_p.sent())) === null || _g === void 0 ? void 0 : _g.data];
865
+ case 3:
866
+ // this line incrementing page is why we return recursively
867
+ ++query[C6.PAGINATION][C6.PAGE];
868
+ // this json stringify is to capture the new page number
869
+ querySerialized = sortAndSerializeQueryObject(tables, query !== null && query !== void 0 ? query : {});
870
+ cacheResult = exports.apiRequestCache.find(function (cache) { return cache.requestArgumentsSerialized === querySerialized; });
871
+ _p.label = 4;
872
+ case 4:
873
+ if (undefined !== cacheResult) return [3 /*break*/, 1];
874
+ _p.label = 5;
875
+ case 5:
876
+ if (debug && isDevelopment) {
877
+ reactToastify.toast.warning("DEVS: Request in cache. (" + exports.apiRequestCache.findIndex(function (cache) { return cache.requestArgumentsSerialized === querySerialized; }) + "). Returning function to request page (" + query[C6.PAGINATION][C6.PAGE] + ")", toastOptionsDevs);
878
+ }
879
+ // @ts-ignore - this is an incorrect warning on TS, it's well typed
880
+ return [2 /*return*/, apiRequest];
881
+ case 6:
879
882
  cachingConfirmed = true;
880
- }
881
- else {
883
+ return [3 /*break*/, 8];
884
+ case 7:
882
885
  if (debug && isDevelopment) {
883
886
  reactToastify.toast.info("DEVS: Ignore cache was set to true.", toastOptionsDevs);
884
887
  }
885
- }
886
- if (debug && isDevelopment) {
887
- reactToastify.toast.success("DEVS: Request not in cache." + (requestMethod === C6.GET ? "Page (" + query[C6.PAGINATION][C6.PAGE] + ")." : '') + " Logging cache 2 console.", toastOptionsDevs);
888
- }
889
- }
890
- else if (cacheResults) { // if we are not getting, we are updating, deleting, or inserting
891
- if (cacheResult) {
892
- cacheCheck = checkCache(cacheResult, requestMethod, tableName, this.request);
893
- if (false !== cacheCheck) {
894
- return [2 /*return*/, cacheCheck];
895
- }
896
- }
897
- cachingConfirmed = true;
898
- // push to cache so we do not repeat the request
899
- }
900
- returnGetNextPageFunction = false;
901
- restRequestUri = restURL + operatingTable + '/';
902
- needsConditionOrPrimaryCheck = (PUT === requestMethod || DELETE === requestMethod)
903
- && false === skipPrimaryCheck;
904
- TABLES = C6.TABLES;
905
- primaryKey = (_k = (_j = (_h = structuredClone((_g = TABLES[operatingTable]) === null || _g === void 0 ? void 0 : _g.PRIMARY)) === null || _h === void 0 ? void 0 : _h.pop()) === null || _j === void 0 ? void 0 : _j.split('.')) === null || _k === void 0 ? void 0 : _k.pop();
906
- if (needsConditionOrPrimaryCheck) {
907
- if (undefined === primaryKey) {
908
- if (null === query
909
- || undefined === query
910
- || undefined === (query === null || query === void 0 ? void 0 : query[C6.WHERE])
911
- || (true === Array.isArray(query[C6.WHERE])
912
- || query[C6.WHERE].length === 0)
913
- || (Object.keys(query === null || query === void 0 ? void 0 : query[C6.WHERE]).length === 0)) {
914
- console.error(query);
915
- throw Error('Failed to parse primary key information. Query: (' + JSON.stringify(query) + ') Primary Key: (' + JSON.stringify(primaryKey) + ') TABLES[operatingTable]?.PRIMARY: (' + JSON.stringify((_l = TABLES[operatingTable]) === null || _l === void 0 ? void 0 : _l.PRIMARY) + ') for operatingTable (' + operatingTable + ').');
888
+ _p.label = 8;
889
+ case 8:
890
+ if (debug && isDevelopment) {
891
+ reactToastify.toast.success("DEVS: Request not in cache." + (requestMethod === C6.GET ? "Page (" + query[C6.PAGINATION][C6.PAGE] + ")." : '') + " Logging cache 2 console.", toastOptionsDevs);
916
892
  }
917
- }
918
- else {
919
- if (undefined === query
920
- || null === query
921
- || false === primaryKey in query) {
922
- if (true === debug && isDevelopment) {
923
- reactToastify.toast.error('DEVS: The primary key (' + primaryKey + ') was not provided!!');
893
+ return [3 /*break*/, 12];
894
+ case 9:
895
+ if (!cacheResults) return [3 /*break*/, 12];
896
+ if (!cacheResult) return [3 /*break*/, 11];
897
+ cacheCheck = checkCache(cacheResult, requestMethod, tableName, this.request);
898
+ if (!(false !== cacheCheck)) return [3 /*break*/, 11];
899
+ return [4 /*yield*/, cacheCheck];
900
+ case 10: return [2 /*return*/, (_h = (_p.sent())) === null || _h === void 0 ? void 0 : _h.data];
901
+ case 11:
902
+ cachingConfirmed = true;
903
+ _p.label = 12;
904
+ case 12:
905
+ returnGetNextPageFunction = false;
906
+ restRequestUri = restURL + operatingTable + '/';
907
+ needsConditionOrPrimaryCheck = (PUT === requestMethod || DELETE === requestMethod)
908
+ && false === skipPrimaryCheck;
909
+ TABLES = C6.TABLES;
910
+ primaryKey = (_m = (_l = (_k = structuredClone((_j = TABLES[operatingTable]) === null || _j === void 0 ? void 0 : _j.PRIMARY)) === null || _k === void 0 ? void 0 : _k.pop()) === null || _l === void 0 ? void 0 : _l.split('.')) === null || _m === void 0 ? void 0 : _m.pop();
911
+ if (needsConditionOrPrimaryCheck) {
912
+ if (undefined === primaryKey) {
913
+ if (null === query
914
+ || undefined === query
915
+ || undefined === (query === null || query === void 0 ? void 0 : query[C6.WHERE])
916
+ || (true === Array.isArray(query[C6.WHERE])
917
+ || query[C6.WHERE].length === 0)
918
+ || (Object.keys(query === null || query === void 0 ? void 0 : query[C6.WHERE]).length === 0)) {
919
+ console.error(query);
920
+ throw Error('Failed to parse primary key information. Query: (' + JSON.stringify(query) + ') Primary Key: (' + JSON.stringify(primaryKey) + ') TABLES[operatingTable]?.PRIMARY: (' + JSON.stringify((_o = TABLES[operatingTable]) === null || _o === void 0 ? void 0 : _o.PRIMARY) + ') for operatingTable (' + operatingTable + ').');
921
+ }
922
+ }
923
+ else {
924
+ if (undefined === query
925
+ || null === query
926
+ || false === primaryKey in query) {
927
+ if (true === debug && isDevelopment) {
928
+ reactToastify.toast.error('DEVS: The primary key (' + primaryKey + ') was not provided!!');
929
+ }
930
+ throw Error('You must provide the primary key (' + primaryKey + ') for table (' + operatingTable + '). Request (' + JSON.stringify(this.request, undefined, 4) + ') Query (' + JSON.stringify(query) + ')');
931
+ }
932
+ if (undefined === (query === null || query === void 0 ? void 0 : query[primaryKey])
933
+ || null === (query === null || query === void 0 ? void 0 : query[primaryKey])) {
934
+ reactToastify.toast.error('The primary key (' + primaryKey + ') provided is undefined or null explicitly!!');
935
+ throw Error('The primary key (' + primaryKey + ') provided in the request was exactly equal to undefined.');
936
+ }
924
937
  }
925
- throw Error('You must provide the primary key (' + primaryKey + ') for table (' + operatingTable + '). Request (' + JSON.stringify(this.request, undefined, 4) + ') Query (' + JSON.stringify(query) + ')');
926
938
  }
927
- if (undefined === (query === null || query === void 0 ? void 0 : query[primaryKey])
928
- || null === (query === null || query === void 0 ? void 0 : query[primaryKey])) {
929
- reactToastify.toast.error('The primary key (' + primaryKey + ') provided is undefined or null explicitly!!');
930
- throw Error('The primary key (' + primaryKey + ') provided in the request was exactly equal to undefined.');
939
+ // A part of me exists that wants to remove this, but it's a good feature
940
+ // this allows developers the ability to cache requests based on primary key
941
+ // for tables like `photos` this can be a huge performance boost
942
+ if (undefined !== query
943
+ && null !== query
944
+ && undefined !== primaryKey
945
+ && primaryKey in query) {
946
+ restRequestUri += query[primaryKey] + '/';
947
+ removedPkValue_1 = query[primaryKey];
948
+ addBackPK = function () {
949
+ query !== null && query !== void 0 ? query : (query = {});
950
+ query[primaryKey] = removedPkValue_1;
951
+ };
952
+ delete query[primaryKey];
953
+ console.log('query', query, 'primaryKey', primaryKey, 'removedPkValue', removedPkValue_1);
931
954
  }
932
- }
933
- }
934
- // A part of me exists that wants to remove this, but it's a good feature
935
- // this allows developers the ability to cache requests based on primary key
936
- // for tables like `photos` this can be a huge performance boost
937
- if (undefined !== query
938
- && null !== query
939
- && undefined !== primaryKey
940
- && primaryKey in query) {
941
- restRequestUri += query[primaryKey] + '/';
942
- removedPkValue_1 = query[primaryKey];
943
- addBackPK = function () {
944
- query !== null && query !== void 0 ? query : (query = {});
945
- query[primaryKey] = removedPkValue_1;
946
- };
947
- delete query[primaryKey];
948
- console.log('query', query, 'primaryKey', primaryKey, 'removedPkValue', removedPkValue_1);
949
- }
950
- else {
951
- console.log('query', query);
952
- }
953
- try {
954
- console.groupCollapsed('%c API: (' + requestMethod + ') Request Query for (' + operatingTable + ') is about to fire, will return with promise!', 'color: #A020F0');
955
- console.log(this.request);
956
- 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');
957
- 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');
958
- console.trace();
959
- console.groupEnd();
960
- this.runLifecycleHooks("beforeExecution", {
961
- config: this.config,
962
- request: this.request
963
- });
964
- axiosActiveRequest = (_e = axios)[requestMethod.toLowerCase()].apply(_e, tslib.__spreadArray([restRequestUri], (function () {
965
- var convert = function (data) {
966
- return convertForRequestBody(data, fullTableList, C6, function (message) { return reactToastify.toast.error(message, toastOptions); });
967
- };
968
- var baseConfig = {
969
- withCredentials: withCredentials,
970
- };
971
- switch (requestMethod) {
972
- case GET:
973
- return [tslib.__assign(tslib.__assign({}, baseConfig), { params: query })];
974
- case POST:
975
- if (dataInsertMultipleRows !== undefined) {
976
- return [
977
- dataInsertMultipleRows.map(convert),
978
- baseConfig
979
- ];
980
- }
981
- return [convert(query), baseConfig];
982
- case PUT:
983
- return [convert(query), baseConfig];
984
- case DELETE:
985
- return [tslib.__assign(tslib.__assign({}, baseConfig), { data: convert(query) })];
986
- default:
987
- throw new Error("The request method (".concat(requestMethod, ") was not recognized."));
955
+ else {
956
+ console.log('query', query);
988
957
  }
989
- })(), false));
990
- if (cachingConfirmed) {
991
- // push to cache so we do not repeat the request
992
- exports.apiRequestCache.push({
993
- requestArgumentsSerialized: querySerialized,
994
- request: axiosActiveRequest
995
- });
996
- }
997
- // todo - wip verify this works
998
- // we had removed the value from the request to add to the URI.
999
- addBackPK === null || addBackPK === void 0 ? void 0 : addBackPK(); // adding back so post-processing methods work
1000
- // returning the promise with this then is important for tests. todo - we could make that optional.
1001
- // https://rapidapi.com/guides/axios-async-await
1002
- return [2 /*return*/, axiosActiveRequest.then(function (response) { return tslib.__awaiter(_this, void 0, void 0, function () {
1003
- var cacheIndex, callback, responseData_1, dependencies_1, fetchReferences_1, apiRequestPromises, _loop_1, _a, _b, _c, _i, tableToFetch;
1004
- var _this = this;
1005
- var _d, _e, _f, _g, _h, _j, _k;
1006
- return tslib.__generator(this, function (_l) {
1007
- switch (_l.label) {
1008
- case 0:
1009
- // noinspection SuspiciousTypeOfGuard
1010
- if (typeof response.data === 'string') {
1011
- if (isTest) {
1012
- console.trace();
1013
- throw new Error('The response data was a string this typically indicated html was sent. Make sure all cookies (' + JSON.stringify(response.config.headers) + ') needed are present! (' + response.data + ')');
1014
- }
1015
- return [2 /*return*/, Promise.reject(response)];
1016
- }
1017
- if (cachingConfirmed) {
1018
- cacheIndex = exports.apiRequestCache.findIndex(function (cache) { return cache.requestArgumentsSerialized === querySerialized; });
1019
- exports.apiRequestCache[cacheIndex].final = false === returnGetNextPageFunction;
1020
- // only cache get method requests
1021
- exports.apiRequestCache[cacheIndex].response = response;
1022
- }
1023
- this.runLifecycleHooks("afterExecution", {
1024
- config: this.config,
1025
- request: this.request,
1026
- response: response
1027
- });
1028
- // todo - this feels dumb now, but i digress
1029
- apiResponse = TestRestfulResponse(response, success, error);
1030
- if (false === apiResponse) {
1031
- if (debug && isDevelopment) {
1032
- reactToastify.toast.warning("DEVS: TestRestfulResponse returned false for (" + operatingTable + ").", toastOptionsDevs);
1033
- }
1034
- return [2 /*return*/, response];
1035
- }
1036
- callback = function () { return _this.runLifecycleHooks("afterCommit", {
1037
- config: _this.config,
1038
- request: _this.request,
1039
- response: response
1040
- }); };
1041
- if (undefined !== reactBootstrap && response) {
1042
- switch (requestMethod) {
1043
- case GET:
1044
- reactBootstrap.updateRestfulObjectArrays({
1045
- dataOrCallback: Array.isArray(response.data.rest) ? response.data.rest : [response.data.rest],
1046
- stateKey: this.config.restModel.TABLE_NAME,
1047
- uniqueObjectId: this.config.restModel.PRIMARY_SHORT,
1048
- callback: callback
1049
- });
1050
- break;
1051
- case POST:
1052
- this.postState(response, this.request, callback);
1053
- break;
1054
- case PUT:
1055
- this.putState(response, this.request, callback);
1056
- break;
1057
- case DELETE:
1058
- this.deleteState(response, this.request, callback);
1059
- break;
1060
- }
1061
- }
1062
- else {
1063
- callback();
1064
- }
1065
- if (!(C6.GET === requestMethod)) return [3 /*break*/, 6];
1066
- responseData_1 = response.data;
1067
- returnGetNextPageFunction = 1 !== ((_d = query === null || query === void 0 ? void 0 : query[C6.PAGINATION]) === null || _d === void 0 ? void 0 : _d[C6.LIMIT]) &&
1068
- ((_e = query === null || query === void 0 ? void 0 : query[C6.PAGINATION]) === null || _e === void 0 ? void 0 : _e[C6.LIMIT]) === responseData_1.rest.length;
1069
- if (false === isTest || true === isVerbose) {
1070
- console.groupCollapsed('%c API: Response (' + requestMethod + ' ' + tableName + ') returned length (' + ((_f = responseData_1.rest) === null || _f === void 0 ? void 0 : _f.length) + ') of possible (' + ((_g = query === null || query === void 0 ? void 0 : query[C6.PAGINATION]) === null || _g === void 0 ? void 0 : _g[C6.LIMIT]) + ') limit!', 'color: #0c0');
1071
- console.log('%c ' + requestMethod + ' ' + tableName, 'color: #0c0');
1072
- console.log('%c Request Data (note you may see the success and/or error prompt):', 'color: #0c0', this.request);
1073
- console.log('%c Response Data:', 'color: #0c0', responseData_1.rest);
1074
- console.log('%c Will return get next page function:' + (1 !== ((_h = query === null || query === void 0 ? void 0 : query[C6.PAGINATION]) === null || _h === void 0 ? void 0 : _h[C6.LIMIT]) ? '' : ' (Will not return with explicit limit 1 set)'), 'color: #0c0', true === returnGetNextPageFunction);
1075
- console.trace();
1076
- console.groupEnd();
1077
- }
1078
- if (false === returnGetNextPageFunction
1079
- && true === debug
1080
- && isDevelopment) {
1081
- reactToastify.toast.success("DEVS: Response returned length (" + ((_j = responseData_1.rest) === null || _j === void 0 ? void 0 : _j.length) + ") less than limit (" + ((_k = query === null || query === void 0 ? void 0 : query[C6.PAGINATION]) === null || _k === void 0 ? void 0 : _k[C6.LIMIT]) + ").", toastOptionsDevs);
958
+ try {
959
+ console.groupCollapsed('%c API: (' + requestMethod + ') Request Query for (' + operatingTable + ') is about to fire, will return with promise!', 'color: #A020F0');
960
+ console.log(this.request);
961
+ 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');
962
+ 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');
963
+ console.trace();
964
+ console.groupEnd();
965
+ this.runLifecycleHooks("beforeExecution", {
966
+ config: this.config,
967
+ request: this.request
968
+ });
969
+ axiosActiveRequest = (_e = axios)[requestMethod.toLowerCase()].apply(_e, tslib.__spreadArray([restRequestUri], (function () {
970
+ var convert = function (data) {
971
+ return convertForRequestBody(data, fullTableList, C6, function (message) { return reactToastify.toast.error(message, toastOptions); });
972
+ };
973
+ var baseConfig = {
974
+ withCredentials: withCredentials,
975
+ };
976
+ switch (requestMethod) {
977
+ case GET:
978
+ return [tslib.__assign(tslib.__assign({}, baseConfig), { params: query })];
979
+ case POST:
980
+ if (dataInsertMultipleRows !== undefined) {
981
+ return [
982
+ dataInsertMultipleRows.map(convert),
983
+ baseConfig
984
+ ];
1082
985
  }
1083
- if (!(fetchDependencies
1084
- && 'number' === typeof fetchDependencies
1085
- && responseData_1.rest.length > 0)) return [3 /*break*/, 6];
1086
- console.groupCollapsed('%c API: Fetch Dependencies segment (' + requestMethod + ' ' + tableName + ')'
1087
- + (fetchDependencies & exports.eFetchDependencies.CHILDREN ? ' | (CHILDREN|REFERENCED) ' : '')
1088
- + (fetchDependencies & exports.eFetchDependencies.PARENTS ? ' | (PARENTS|REFERENCED_BY)' : '')
1089
- + (fetchDependencies & exports.eFetchDependencies.C6ENTITY ? ' | (C6ENTITY)' : '')
1090
- + (fetchDependencies & exports.eFetchDependencies.RECURSIVE ? ' | (RECURSIVE)' : ''), 'color: #33ccff');
1091
- console.groupCollapsed('Collapsed JS Trace');
1092
- console.trace(); // hidden in collapsed group
1093
- console.groupEnd();
1094
- dependencies_1 = {};
1095
- if (fetchDependencies & exports.eFetchDependencies.C6ENTITY) {
1096
- dependencies_1 = operatingTable.endsWith("carbon_carbons")
1097
- ? tslib.__assign(tslib.__assign({}, fetchDependencies & exports.eFetchDependencies.CHILDREN // REFERENCED === CHILDREN
1098
- ? C6.TABLES[operatingTable].TABLE_REFERENCED_BY
1099
- : {}), fetchDependencies & exports.eFetchDependencies.PARENTS // REFERENCES === PARENTS
1100
- ? C6.TABLES[operatingTable].TABLE_REFERENCES
1101
- : {}) : tslib.__assign(tslib.__assign({}, fetchDependencies & exports.eFetchDependencies.CHILDREN // REFERENCED === CHILDREN
1102
- ? tslib.__assign(tslib.__assign({}, Object.keys(C6.TABLES[operatingTable].TABLE_REFERENCES).reduce(function (accumulator, columnName) {
1103
- if (!C6.TABLES[operatingTable].PRIMARY_SHORT.includes(columnName)) {
1104
- accumulator[columnName] = C6.TABLES[operatingTable].TABLE_REFERENCES[columnName];
986
+ return [convert(query), baseConfig];
987
+ case PUT:
988
+ return [convert(query), baseConfig];
989
+ case DELETE:
990
+ return [tslib.__assign(tslib.__assign({}, baseConfig), { data: convert(query) })];
991
+ default:
992
+ throw new Error("The request method (".concat(requestMethod, ") was not recognized."));
993
+ }
994
+ })(), false));
995
+ if (cachingConfirmed) {
996
+ // push to cache so we do not repeat the request
997
+ exports.apiRequestCache.push({
998
+ requestArgumentsSerialized: querySerialized,
999
+ request: axiosActiveRequest
1000
+ });
1001
+ }
1002
+ // todo - wip verify this works
1003
+ // we had removed the value from the request to add to the URI.
1004
+ addBackPK === null || addBackPK === void 0 ? void 0 : addBackPK(); // adding back so post-processing methods work
1005
+ // returning the promise with this then is important for tests. todo - we could make that optional.
1006
+ // https://rapidapi.com/guides/axios-async-await
1007
+ return [2 /*return*/, axiosActiveRequest.then(function (response) { return tslib.__awaiter(_this, void 0, void 0, function () {
1008
+ var cacheIndex, callback, responseData_1, dependencies_1, fetchReferences_1, apiRequestPromises, _loop_1, _a, _b, _c, _i, tableToFetch;
1009
+ var _this = this;
1010
+ var _d, _e, _f, _g, _h, _j, _k;
1011
+ return tslib.__generator(this, function (_l) {
1012
+ switch (_l.label) {
1013
+ case 0:
1014
+ // noinspection SuspiciousTypeOfGuard
1015
+ if (typeof response.data === 'string') {
1016
+ if (isTest) {
1017
+ console.trace();
1018
+ throw new Error('The response data was a string this typically indicated html was sent. Make sure all cookies (' + JSON.stringify(response.config.headers) + ') needed are present! (' + response.data + ')');
1105
1019
  }
1106
- return accumulator;
1107
- }, {})), C6.TABLES[operatingTable].TABLE_REFERENCED_BY // it is unlikely that a C6 table will have any TABLE_REFERENCED_BY
1108
- ) : {}), fetchDependencies & exports.eFetchDependencies.PARENTS // REFERENCES === PARENTS
1109
- ? C6.TABLES[operatingTable].PRIMARY_SHORT.reduce(function (accumulator, primaryKey) {
1110
- if (primaryKey in C6.TABLES[operatingTable].TABLE_REFERENCES) {
1111
- accumulator[primaryKey] = C6.TABLES[operatingTable].TABLE_REFERENCES[primaryKey];
1020
+ return [2 /*return*/, Promise.reject(response)];
1021
+ }
1022
+ if (cachingConfirmed) {
1023
+ cacheIndex = exports.apiRequestCache.findIndex(function (cache) { return cache.requestArgumentsSerialized === querySerialized; });
1024
+ exports.apiRequestCache[cacheIndex].final = false === returnGetNextPageFunction;
1025
+ // only cache get method requests
1026
+ exports.apiRequestCache[cacheIndex].response = response;
1027
+ }
1028
+ this.runLifecycleHooks("afterExecution", {
1029
+ config: this.config,
1030
+ request: this.request,
1031
+ response: response
1032
+ });
1033
+ // todo - this feels dumb now, but i digress
1034
+ apiResponse = TestRestfulResponse(response, success, error);
1035
+ if (false === apiResponse) {
1036
+ if (debug && isDevelopment) {
1037
+ reactToastify.toast.warning("DEVS: TestRestfulResponse returned false for (" + operatingTable + ").", toastOptionsDevs);
1112
1038
  }
1113
- return accumulator;
1114
- }, {})
1115
- : {});
1116
- }
1117
- else {
1118
- // this is the natural mysql context
1119
- dependencies_1 = tslib.__assign(tslib.__assign({}, fetchDependencies & exports.eFetchDependencies.REFERENCED // REFERENCED === CHILDREN
1120
- ? C6.TABLES[operatingTable].TABLE_REFERENCED_BY
1121
- : {}), fetchDependencies & exports.eFetchDependencies.REFERENCES // REFERENCES === PARENTS
1122
- ? C6.TABLES[operatingTable].TABLE_REFERENCES
1123
- : {});
1124
- }
1125
- fetchReferences_1 = {};
1126
- apiRequestPromises = [];
1127
- console.log('%c Dependencies', 'color: #005555', dependencies_1);
1128
- Object.keys(dependencies_1)
1129
- .forEach(function (column) { return dependencies_1[column]
1130
- .forEach(function (constraint) {
1131
- var _a, _b, _c, _d;
1132
- var _e, _f, _g;
1133
- var columnValues = (_b = (_a = responseData_1.rest[column]) !== null && _a !== void 0 ? _a : responseData_1.rest.map(function (row) {
1134
- if (operatingTable.endsWith("carbons")
1135
- && 'entity_tag' in row
1136
- && !constraint.TABLE.endsWith(row['entity_tag'].split('\\').pop().toLowerCase())) {
1137
- return false; // map
1039
+ return [2 /*return*/, response];
1138
1040
  }
1139
- if (!(column in row)) {
1140
- return false;
1041
+ callback = function () { return _this.runLifecycleHooks("afterCommit", {
1042
+ config: _this.config,
1043
+ request: _this.request,
1044
+ response: response
1045
+ }); };
1046
+ if (undefined !== reactBootstrap && response) {
1047
+ switch (requestMethod) {
1048
+ case GET:
1049
+ reactBootstrap.updateRestfulObjectArrays({
1050
+ dataOrCallback: Array.isArray(response.data.rest) ? response.data.rest : [response.data.rest],
1051
+ stateKey: this.config.restModel.TABLE_NAME,
1052
+ uniqueObjectId: this.config.restModel.PRIMARY_SHORT,
1053
+ callback: callback
1054
+ });
1055
+ break;
1056
+ case POST:
1057
+ this.postState(response, this.request, callback);
1058
+ break;
1059
+ case PUT:
1060
+ this.putState(response, this.request, callback);
1061
+ break;
1062
+ case DELETE:
1063
+ this.deleteState(response, this.request, callback);
1064
+ break;
1065
+ }
1141
1066
  }
1142
- // todo - row[column] is a FK value, we should optionally remove values that are already in state
1143
- // this could be any column in the table constraint.TABLE, not just the primary key
1144
- return row[column];
1145
- }).filter(function (n) { return n; })) !== null && _b !== void 0 ? _b : [];
1146
- if (columnValues.length === 0) {
1147
- return; // forEach
1148
- }
1149
- (_c = fetchReferences_1[_e = constraint.TABLE]) !== null && _c !== void 0 ? _c : (fetchReferences_1[_e] = {});
1150
- (_d = (_f = fetchReferences_1[constraint.TABLE])[_g = constraint.COLUMN]) !== null && _d !== void 0 ? _d : (_f[_g] = []);
1151
- fetchReferences_1[constraint.TABLE][constraint.COLUMN].push(columnValues);
1152
- }); });
1153
- console.log('fetchReferences', fetchReferences_1);
1154
- _loop_1 = function (tableToFetch) {
1155
- var referencesTables, shouldContinue, fetchTable, RestApi, nextFetchDependencies;
1156
- var _m;
1157
- return tslib.__generator(this, function (_o) {
1158
- switch (_o.label) {
1159
- case 0:
1160
- if (fetchDependencies & exports.eFetchDependencies.C6ENTITY
1161
- && 'string' === typeof tableName
1162
- && tableName.endsWith("carbon_carbons")) {
1163
- referencesTables = responseData_1.rest.reduce(function (accumulator, row) {
1164
- if ('entity_tag' in row && !accumulator.includes(row['entity_tag'])) {
1165
- accumulator.push(row['entity_tag']);
1166
- }
1167
- return accumulator;
1168
- }, []).map(function (entityTag) { return entityTag.split('\\').pop().toLowerCase(); });
1169
- shouldContinue = referencesTables.find(function (referencesTable) { return tableToFetch.endsWith(referencesTable); });
1170
- if (!shouldContinue) {
1171
- console.log('%c C6ENTITY: The constraintTableName (' + tableToFetch + ') did not end with any value in referencesTables', 'color: #c00', referencesTables);
1172
- return [2 /*return*/, "continue"];
1067
+ else {
1068
+ callback();
1069
+ }
1070
+ if (!(C6.GET === requestMethod)) return [3 /*break*/, 6];
1071
+ responseData_1 = response.data;
1072
+ returnGetNextPageFunction = 1 !== ((_d = query === null || query === void 0 ? void 0 : query[C6.PAGINATION]) === null || _d === void 0 ? void 0 : _d[C6.LIMIT]) &&
1073
+ ((_e = query === null || query === void 0 ? void 0 : query[C6.PAGINATION]) === null || _e === void 0 ? void 0 : _e[C6.LIMIT]) === responseData_1.rest.length;
1074
+ if (false === isTest || true === isVerbose) {
1075
+ console.groupCollapsed('%c API: Response (' + requestMethod + ' ' + tableName + ') returned length (' + ((_f = responseData_1.rest) === null || _f === void 0 ? void 0 : _f.length) + ') of possible (' + ((_g = query === null || query === void 0 ? void 0 : query[C6.PAGINATION]) === null || _g === void 0 ? void 0 : _g[C6.LIMIT]) + ') limit!', 'color: #0c0');
1076
+ console.log('%c ' + requestMethod + ' ' + tableName, 'color: #0c0');
1077
+ console.log('%c Request Data (note you may see the success and/or error prompt):', 'color: #0c0', this.request);
1078
+ console.log('%c Response Data:', 'color: #0c0', responseData_1.rest);
1079
+ console.log('%c Will return get next page function:' + (1 !== ((_h = query === null || query === void 0 ? void 0 : query[C6.PAGINATION]) === null || _h === void 0 ? void 0 : _h[C6.LIMIT]) ? '' : ' (Will not return with explicit limit 1 set)'), 'color: #0c0', true === returnGetNextPageFunction);
1080
+ console.trace();
1081
+ console.groupEnd();
1082
+ }
1083
+ if (false === returnGetNextPageFunction
1084
+ && true === debug
1085
+ && isDevelopment) {
1086
+ reactToastify.toast.success("DEVS: Response returned length (" + ((_j = responseData_1.rest) === null || _j === void 0 ? void 0 : _j.length) + ") less than limit (" + ((_k = query === null || query === void 0 ? void 0 : query[C6.PAGINATION]) === null || _k === void 0 ? void 0 : _k[C6.LIMIT]) + ").", toastOptionsDevs);
1087
+ }
1088
+ if (!(fetchDependencies
1089
+ && 'number' === typeof fetchDependencies
1090
+ && responseData_1.rest.length > 0)) return [3 /*break*/, 6];
1091
+ console.groupCollapsed('%c API: Fetch Dependencies segment (' + requestMethod + ' ' + tableName + ')'
1092
+ + (fetchDependencies & exports.eFetchDependencies.CHILDREN ? ' | (CHILDREN|REFERENCED) ' : '')
1093
+ + (fetchDependencies & exports.eFetchDependencies.PARENTS ? ' | (PARENTS|REFERENCED_BY)' : '')
1094
+ + (fetchDependencies & exports.eFetchDependencies.C6ENTITY ? ' | (C6ENTITY)' : '')
1095
+ + (fetchDependencies & exports.eFetchDependencies.RECURSIVE ? ' | (RECURSIVE)' : ''), 'color: #33ccff');
1096
+ console.groupCollapsed('Collapsed JS Trace');
1097
+ console.trace(); // hidden in collapsed group
1098
+ console.groupEnd();
1099
+ dependencies_1 = {};
1100
+ if (fetchDependencies & exports.eFetchDependencies.C6ENTITY) {
1101
+ dependencies_1 = operatingTable.endsWith("carbon_carbons")
1102
+ ? tslib.__assign(tslib.__assign({}, fetchDependencies & exports.eFetchDependencies.CHILDREN // REFERENCED === CHILDREN
1103
+ ? C6.TABLES[operatingTable].TABLE_REFERENCED_BY
1104
+ : {}), fetchDependencies & exports.eFetchDependencies.PARENTS // REFERENCES === PARENTS
1105
+ ? C6.TABLES[operatingTable].TABLE_REFERENCES
1106
+ : {}) : tslib.__assign(tslib.__assign({}, fetchDependencies & exports.eFetchDependencies.CHILDREN // REFERENCED === CHILDREN
1107
+ ? tslib.__assign(tslib.__assign({}, Object.keys(C6.TABLES[operatingTable].TABLE_REFERENCES).reduce(function (accumulator, columnName) {
1108
+ if (!C6.TABLES[operatingTable].PRIMARY_SHORT.includes(columnName)) {
1109
+ accumulator[columnName] = C6.TABLES[operatingTable].TABLE_REFERENCES[columnName];
1173
1110
  }
1174
- console.log('%c C6ENTITY: The constraintTableName (' + tableToFetch + ') will be fetched.', 'color: #0c0');
1175
- }
1176
- return [4 /*yield*/, C6.IMPORT(tableToFetch)];
1177
- case 1:
1178
- fetchTable = _o.sent();
1179
- RestApi = fetchTable.default;
1180
- console.log('%c Fetch Dependencies will select (' + tableToFetch + ') using GET request', 'color: #33ccff');
1181
- nextFetchDependencies = exports.eFetchDependencies.NONE;
1182
- if (fetchDependencies & exports.eFetchDependencies.RECURSIVE) {
1183
- if (fetchDependencies & exports.eFetchDependencies.ALL) {
1184
- throw Error('Recursive fetch dependencies with both PARENT and CHILD reference will result in an infin1ite loop. As there is not real ending condition, this is not supported.');
1111
+ return accumulator;
1112
+ }, {})), C6.TABLES[operatingTable].TABLE_REFERENCED_BY // it is unlikely that a C6 table will have any TABLE_REFERENCED_BY
1113
+ ) : {}), fetchDependencies & exports.eFetchDependencies.PARENTS // REFERENCES === PARENTS
1114
+ ? C6.TABLES[operatingTable].PRIMARY_SHORT.reduce(function (accumulator, primaryKey) {
1115
+ if (primaryKey in C6.TABLES[operatingTable].TABLE_REFERENCES) {
1116
+ accumulator[primaryKey] = C6.TABLES[operatingTable].TABLE_REFERENCES[primaryKey];
1185
1117
  }
1186
- nextFetchDependencies = fetchDependencies;
1118
+ return accumulator;
1119
+ }, {})
1120
+ : {});
1121
+ }
1122
+ else {
1123
+ // this is the natural mysql context
1124
+ dependencies_1 = tslib.__assign(tslib.__assign({}, fetchDependencies & exports.eFetchDependencies.REFERENCED // REFERENCED === CHILDREN
1125
+ ? C6.TABLES[operatingTable].TABLE_REFERENCED_BY
1126
+ : {}), fetchDependencies & exports.eFetchDependencies.REFERENCES // REFERENCES === PARENTS
1127
+ ? C6.TABLES[operatingTable].TABLE_REFERENCES
1128
+ : {});
1129
+ }
1130
+ fetchReferences_1 = {};
1131
+ apiRequestPromises = [];
1132
+ console.log('%c Dependencies', 'color: #005555', dependencies_1);
1133
+ Object.keys(dependencies_1)
1134
+ .forEach(function (column) { return dependencies_1[column]
1135
+ .forEach(function (constraint) {
1136
+ var _a, _b, _c, _d;
1137
+ var _e, _f, _g;
1138
+ var columnValues = (_b = (_a = responseData_1.rest[column]) !== null && _a !== void 0 ? _a : responseData_1.rest.map(function (row) {
1139
+ if (operatingTable.endsWith("carbons")
1140
+ && 'entity_tag' in row
1141
+ && !constraint.TABLE.endsWith(row['entity_tag'].split('\\').pop().toLowerCase())) {
1142
+ return false; // map
1187
1143
  }
1188
- else if (fetchDependencies & exports.eFetchDependencies.C6ENTITY) {
1189
- if (tableToFetch === "carbon_carbons") {
1190
- nextFetchDependencies = fetchDependencies;
1191
- }
1192
- else {
1193
- nextFetchDependencies = fetchDependencies ^ exports.eFetchDependencies.C6ENTITY;
1194
- }
1144
+ if (!(column in row)) {
1145
+ return false;
1195
1146
  }
1196
- console.log('fetchReferences', fetchReferences_1[tableToFetch], "Current fetchDependencies for (" + operatingTable + "):", fetchDependencies, "New fetchDependencies for (" + tableToFetch + "): ", nextFetchDependencies);
1197
- // todo - filter out ids that exist in state?!? note - remember that this does not necessarily mean the pk, but only known is its an FK to somewhere
1198
- // it not certain that they are using carbons' entities either
1199
- // this is a dynamic call to the rest api, any generated table may resolve with (RestApi)
1200
- // todo - using value to avoid joins.... but. maybe this should be a parameterizable option -- think race conditions; its safer to join
1201
- apiRequestPromises.push(RestApi.Get((_m = {},
1202
- _m[C6.WHERE] = {
1203
- 0: Object.keys(fetchReferences_1[tableToFetch]).reduce(function (sum, column) {
1204
- fetchReferences_1[tableToFetch][column] = fetchReferences_1[tableToFetch][column].flat(Infinity);
1205
- if (0 === fetchReferences_1[tableToFetch][column].length) {
1206
- console.warn('The column (' + column + ') was not found in the response data. We will not fetch.', responseData_1);
1207
- return false;
1147
+ // todo - row[column] is a FK value, we should optionally remove values that are already in state
1148
+ // this could be any column in the table constraint.TABLE, not just the primary key
1149
+ return row[column];
1150
+ }).filter(function (n) { return n; })) !== null && _b !== void 0 ? _b : [];
1151
+ if (columnValues.length === 0) {
1152
+ return; // forEach
1153
+ }
1154
+ (_c = fetchReferences_1[_e = constraint.TABLE]) !== null && _c !== void 0 ? _c : (fetchReferences_1[_e] = {});
1155
+ (_d = (_f = fetchReferences_1[constraint.TABLE])[_g = constraint.COLUMN]) !== null && _d !== void 0 ? _d : (_f[_g] = []);
1156
+ fetchReferences_1[constraint.TABLE][constraint.COLUMN].push(columnValues);
1157
+ }); });
1158
+ console.log('fetchReferences', fetchReferences_1);
1159
+ _loop_1 = function (tableToFetch) {
1160
+ var referencesTables, shouldContinue, fetchTable, RestApi, nextFetchDependencies;
1161
+ var _m;
1162
+ return tslib.__generator(this, function (_o) {
1163
+ switch (_o.label) {
1164
+ case 0:
1165
+ if (fetchDependencies & exports.eFetchDependencies.C6ENTITY
1166
+ && 'string' === typeof tableName
1167
+ && tableName.endsWith("carbon_carbons")) {
1168
+ referencesTables = responseData_1.rest.reduce(function (accumulator, row) {
1169
+ if ('entity_tag' in row && !accumulator.includes(row['entity_tag'])) {
1170
+ accumulator.push(row['entity_tag']);
1171
+ }
1172
+ return accumulator;
1173
+ }, []).map(function (entityTag) { return entityTag.split('\\').pop().toLowerCase(); });
1174
+ shouldContinue = referencesTables.find(function (referencesTable) { return tableToFetch.endsWith(referencesTable); });
1175
+ if (!shouldContinue) {
1176
+ console.log('%c C6ENTITY: The constraintTableName (' + tableToFetch + ') did not end with any value in referencesTables', 'color: #c00', referencesTables);
1177
+ return [2 /*return*/, "continue"];
1208
1178
  }
1209
- sum[column] = fetchReferences_1[tableToFetch][column].length === 1
1210
- ? fetchReferences_1[tableToFetch][column][0]
1211
- : [
1212
- C6.IN, fetchReferences_1[tableToFetch][column]
1213
- ];
1214
- return sum;
1215
- }, {})
1216
- },
1217
- _m.fetchDependencies = nextFetchDependencies,
1218
- _m)));
1219
- return [2 /*return*/];
1220
- }
1221
- });
1222
- };
1223
- _a = fetchReferences_1;
1224
- _b = [];
1225
- for (_c in _a)
1226
- _b.push(_c);
1227
- _i = 0;
1228
- _l.label = 1;
1229
- case 1:
1230
- if (!(_i < _b.length)) return [3 /*break*/, 4];
1231
- _c = _b[_i];
1232
- if (!(_c in _a)) return [3 /*break*/, 3];
1233
- tableToFetch = _c;
1234
- return [5 /*yield**/, _loop_1(tableToFetch)];
1235
- case 2:
1236
- _l.sent();
1237
- _l.label = 3;
1238
- case 3:
1239
- _i++;
1240
- return [3 /*break*/, 1];
1241
- case 4:
1242
- console.groupEnd();
1243
- return [4 /*yield*/, Promise.all(apiRequestPromises)];
1244
- case 5:
1245
- _l.sent();
1246
- apiRequestPromises.map(function (promise) { return tslib.__awaiter(_this, void 0, void 0, function () {
1247
- var _a, _b;
1248
- return tslib.__generator(this, function (_c) {
1249
- switch (_c.label) {
1250
- case 0:
1251
- if (!Array.isArray(this.request.fetchDependencies)) {
1252
- // to reassign value we must ref the root
1253
- this.request.fetchDependencies = [];
1179
+ console.log('%c C6ENTITY: The constraintTableName (' + tableToFetch + ') will be fetched.', 'color: #0c0');
1180
+ }
1181
+ return [4 /*yield*/, C6.IMPORT(tableToFetch)];
1182
+ case 1:
1183
+ fetchTable = _o.sent();
1184
+ RestApi = fetchTable.default;
1185
+ console.log('%c Fetch Dependencies will select (' + tableToFetch + ') using GET request', 'color: #33ccff');
1186
+ nextFetchDependencies = exports.eFetchDependencies.NONE;
1187
+ if (fetchDependencies & exports.eFetchDependencies.RECURSIVE) {
1188
+ if (fetchDependencies & exports.eFetchDependencies.ALL) {
1189
+ throw Error('Recursive fetch dependencies with both PARENT and CHILD reference will result in an infin1ite loop. As there is not real ending condition, this is not supported.');
1190
+ }
1191
+ nextFetchDependencies = fetchDependencies;
1192
+ }
1193
+ else if (fetchDependencies & exports.eFetchDependencies.C6ENTITY) {
1194
+ if (tableToFetch === "carbon_carbons") {
1195
+ nextFetchDependencies = fetchDependencies;
1196
+ }
1197
+ else {
1198
+ nextFetchDependencies = fetchDependencies ^ exports.eFetchDependencies.C6ENTITY;
1199
+ }
1200
+ }
1201
+ console.log('fetchReferences', fetchReferences_1[tableToFetch], "Current fetchDependencies for (" + operatingTable + "):", fetchDependencies, "New fetchDependencies for (" + tableToFetch + "): ", nextFetchDependencies);
1202
+ // todo - filter out ids that exist in state?!? note - remember that this does not necessarily mean the pk, but only known is its an FK to somewhere
1203
+ // it not certain that they are using carbons' entities either
1204
+ // this is a dynamic call to the rest api, any generated table may resolve with (RestApi)
1205
+ // todo - using value to avoid joins.... but. maybe this should be a parameterizable option -- think race conditions; its safer to join
1206
+ apiRequestPromises.push(RestApi.Get((_m = {},
1207
+ _m[C6.WHERE] = {
1208
+ 0: Object.keys(fetchReferences_1[tableToFetch]).reduce(function (sum, column) {
1209
+ fetchReferences_1[tableToFetch][column] = fetchReferences_1[tableToFetch][column].flat(Infinity);
1210
+ if (0 === fetchReferences_1[tableToFetch][column].length) {
1211
+ console.warn('The column (' + column + ') was not found in the response data. We will not fetch.', responseData_1);
1212
+ return false;
1213
+ }
1214
+ sum[column] = fetchReferences_1[tableToFetch][column].length === 1
1215
+ ? fetchReferences_1[tableToFetch][column][0]
1216
+ : [
1217
+ C6.IN, fetchReferences_1[tableToFetch][column]
1218
+ ];
1219
+ return sum;
1220
+ }, {})
1221
+ },
1222
+ _m.fetchDependencies = nextFetchDependencies,
1223
+ _m)));
1224
+ return [2 /*return*/];
1225
+ }
1226
+ });
1227
+ };
1228
+ _a = fetchReferences_1;
1229
+ _b = [];
1230
+ for (_c in _a)
1231
+ _b.push(_c);
1232
+ _i = 0;
1233
+ _l.label = 1;
1234
+ case 1:
1235
+ if (!(_i < _b.length)) return [3 /*break*/, 4];
1236
+ _c = _b[_i];
1237
+ if (!(_c in _a)) return [3 /*break*/, 3];
1238
+ tableToFetch = _c;
1239
+ return [5 /*yield**/, _loop_1(tableToFetch)];
1240
+ case 2:
1241
+ _l.sent();
1242
+ _l.label = 3;
1243
+ case 3:
1244
+ _i++;
1245
+ return [3 /*break*/, 1];
1246
+ case 4:
1247
+ console.groupEnd();
1248
+ return [4 /*yield*/, Promise.all(apiRequestPromises)];
1249
+ case 5:
1250
+ _l.sent();
1251
+ apiRequestPromises.map(function (promise) { return tslib.__awaiter(_this, void 0, void 0, function () {
1252
+ var _a, _b;
1253
+ return tslib.__generator(this, function (_c) {
1254
+ switch (_c.label) {
1255
+ case 0:
1256
+ if (!Array.isArray(this.request.fetchDependencies)) {
1257
+ // to reassign value we must ref the root
1258
+ this.request.fetchDependencies = [];
1259
+ }
1260
+ _b = (_a = this.request.fetchDependencies).push;
1261
+ return [4 /*yield*/, promise];
1262
+ case 1:
1263
+ _b.apply(_a, [_c.sent()]);
1264
+ return [2 /*return*/];
1254
1265
  }
1255
- _b = (_a = this.request.fetchDependencies).push;
1256
- return [4 /*yield*/, promise];
1257
- case 1:
1258
- _b.apply(_a, [_c.sent()]);
1259
- return [2 /*return*/];
1266
+ });
1267
+ }); });
1268
+ _l.label = 6;
1269
+ case 6:
1270
+ if (debug && isDevelopment) {
1271
+ reactToastify.toast.success("DEVS: (" + requestMethod + ") request complete.", toastOptionsDevs);
1260
1272
  }
1261
- });
1262
- }); });
1263
- _l.label = 6;
1264
- case 6:
1265
- if (debug && isDevelopment) {
1266
- reactToastify.toast.success("DEVS: (" + requestMethod + ") request complete.", toastOptionsDevs);
1273
+ return [2 /*return*/, response];
1267
1274
  }
1268
- return [2 /*return*/, response];
1269
- }
1270
- });
1271
- }); })];
1272
- }
1273
- catch (throwableError) {
1274
- if (isTest) {
1275
- throw new Error(JSON.stringify(throwableError));
1276
- }
1277
- console.groupCollapsed('%c API: An error occurred in the try catch block. returning null!', 'color: #ff0000');
1278
- console.log('%c ' + requestMethod + ' ' + tableName, 'color: #A020F0');
1279
- console.warn(throwableError);
1280
- console.trace();
1281
- console.groupEnd();
1282
- TestRestfulResponse(throwableError, success, error);
1283
- return [2 /*return*/, null];
1275
+ });
1276
+ }); }).then(function (response) { return response.data; })];
1277
+ }
1278
+ catch (throwableError) {
1279
+ if (isTest) {
1280
+ throw new Error(JSON.stringify(throwableError));
1281
+ }
1282
+ console.groupCollapsed('%c API: An error occurred in the try catch block. returning null!', 'color: #ff0000');
1283
+ console.log('%c ' + requestMethod + ' ' + tableName, 'color: #A020F0');
1284
+ console.warn(throwableError);
1285
+ console.trace();
1286
+ console.groupEnd();
1287
+ TestRestfulResponse(throwableError, success, error);
1288
+ return [2 /*return*/, null];
1289
+ }
1290
+ return [2 /*return*/];
1284
1291
  }
1285
- return [2 /*return*/];
1286
1292
  });
1287
1293
  }); };
1288
1294
  return [4 /*yield*/, apiRequest()];
@@ -1305,17 +1311,43 @@ var SqlExecutor = /** @class */ (function (_super) {
1305
1311
  return _super !== null && _super.apply(this, arguments) || this;
1306
1312
  }
1307
1313
  SqlExecutor.prototype.execute = function () {
1308
- switch (this.config.requestMethod) {
1309
- case 'GET':
1310
- // were about to use this and its fucked
1311
- return this.select(this.config.restModel.TABLE_NAME, undefined, this.request).then(function (rows) { return ({ rest: rows }); });
1312
- case 'POST':
1313
- return this.insert(this.config.restModel.TABLE_NAME, this.request);
1314
- case 'PUT':
1315
- return this.update(this.config.restModel.TABLE_NAME, undefined, this.request);
1316
- case 'DELETE':
1317
- return this.delete(this.config.restModel.TABLE_NAME, undefined, this.request);
1318
- }
1314
+ return tslib.__awaiter(this, void 0, void 0, function () {
1315
+ var _a, TABLE_NAME, PRIMARY, _b, rest, result, created, result, updated, result, deleted;
1316
+ return tslib.__generator(this, function (_c) {
1317
+ switch (_c.label) {
1318
+ case 0:
1319
+ _a = this.config.restModel, TABLE_NAME = _a.TABLE_NAME, PRIMARY = _a.PRIMARY;
1320
+ _b = this.config.requestMethod;
1321
+ switch (_b) {
1322
+ case 'GET': return [3 /*break*/, 1];
1323
+ case 'POST': return [3 /*break*/, 3];
1324
+ case 'PUT': return [3 /*break*/, 5];
1325
+ case 'DELETE': return [3 /*break*/, 7];
1326
+ }
1327
+ return [3 /*break*/, 9];
1328
+ case 1: return [4 /*yield*/, this.select(TABLE_NAME, undefined, this.request)];
1329
+ case 2:
1330
+ rest = _c.sent();
1331
+ return [2 /*return*/, { rest: rest }];
1332
+ case 3: return [4 /*yield*/, this.insert(TABLE_NAME, this.request)];
1333
+ case 4:
1334
+ result = _c.sent();
1335
+ created = { rest: result, created: true };
1336
+ return [2 /*return*/, created];
1337
+ case 5: return [4 /*yield*/, this.update(TABLE_NAME, PRIMARY, this.request)];
1338
+ case 6:
1339
+ result = _c.sent();
1340
+ updated = { rest: result, updated: true, rowCount: result.affectedRows };
1341
+ return [2 /*return*/, updated];
1342
+ case 7: return [4 /*yield*/, this.delete(TABLE_NAME, PRIMARY, this.request)];
1343
+ case 8:
1344
+ result = _c.sent();
1345
+ deleted = { rest: result, deleted: true, rowCount: result.affectedRows };
1346
+ return [2 /*return*/, deleted];
1347
+ case 9: throw new Error("Unsupported request method: ".concat(this.config.requestMethod));
1348
+ }
1349
+ });
1350
+ });
1319
1351
  };
1320
1352
  SqlExecutor.prototype.withConnection = function (cb) {
1321
1353
  return tslib.__awaiter(this, void 0, void 0, function () {
@@ -1398,14 +1430,13 @@ var SqlExecutor = /** @class */ (function (_super) {
1398
1430
  return tslib.__generator(this, function (_a) {
1399
1431
  switch (_a.label) {
1400
1432
  case 0:
1401
- if (!primary) {
1433
+ if (!(primary === null || primary === void 0 ? void 0 : primary.length))
1402
1434
  throw new Error('Primary key is required for update');
1403
- }
1404
1435
  keys = Object.keys(data);
1405
1436
  values = keys.map(function (k) { return data[k]; });
1406
1437
  updates = keys.map(function (k) { return "`".concat(k, "` = ?"); }).join(', ');
1407
- sql = "UPDATE `".concat(table, "` SET ").concat(updates, " WHERE `").concat(primary, "` = ?");
1408
- values.push(data[primary]);
1438
+ sql = "UPDATE `".concat(table, "` SET ").concat(updates, " WHERE `").concat(primary[0], "` = ?");
1439
+ values.push(data[primary[0]]);
1409
1440
  return [4 /*yield*/, this.withConnection(function (conn) { return tslib.__awaiter(_this, void 0, void 0, function () {
1410
1441
  var result;
1411
1442
  return tslib.__generator(this, function (_a) {
@@ -1424,20 +1455,20 @@ var SqlExecutor = /** @class */ (function (_super) {
1424
1455
  };
1425
1456
  SqlExecutor.prototype.delete = function (table, primary, args) {
1426
1457
  return tslib.__awaiter(this, void 0, void 0, function () {
1427
- var sql;
1458
+ var key, sql;
1428
1459
  var _this = this;
1429
1460
  return tslib.__generator(this, function (_a) {
1430
1461
  switch (_a.label) {
1431
1462
  case 0:
1432
- if (!primary || !(args === null || args === void 0 ? void 0 : args[primary])) {
1463
+ key = primary === null || primary === void 0 ? void 0 : primary[0];
1464
+ if (!key || !(args === null || args === void 0 ? void 0 : args[key]))
1433
1465
  throw new Error('Primary key and value required for delete');
1434
- }
1435
- sql = "DELETE FROM `".concat(table, "` WHERE `").concat(primary, "` = ?");
1466
+ sql = "DELETE FROM `".concat(table, "` WHERE `").concat(key, "` = ?");
1436
1467
  return [4 /*yield*/, this.withConnection(function (conn) { return tslib.__awaiter(_this, void 0, void 0, function () {
1437
1468
  var result;
1438
1469
  return tslib.__generator(this, function (_a) {
1439
1470
  switch (_a.label) {
1440
- case 0: return [4 /*yield*/, conn.execute(sql, [args[primary]])];
1471
+ case 0: return [4 /*yield*/, conn.execute(sql, [args[key]])];
1441
1472
  case 1:
1442
1473
  result = (_a.sent())[0];
1443
1474
  return [2 /*return*/, result];
@@ -1501,7 +1532,8 @@ function ExpressHandler(_a) {
1501
1532
  })(payload)];
1502
1533
  case 1:
1503
1534
  response = _a.sent();
1504
- res.status(200).json({ success: true, rest: response });
1535
+ console.log('response', JSON.stringify(response));
1536
+ res.status(200).json(tslib.__assign({ success: true }, response));
1505
1537
  return [3 /*break*/, 3];
1506
1538
  case 2:
1507
1539
  err_1 = _a.sent();