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