@carbonorm/carbonnode 3.0.9 → 3.0.10

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