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