@carbonorm/carbonnode 3.7.22 → 3.8.0
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/HttpExecutor.d.ts +1 -0
- package/dist/api/handlers/createTestServer.d.ts +8 -0
- package/dist/index.cjs.js +111 -106
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +111 -106
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/scripts/assets/handlebars/C6.ts.handlebars +9 -4
- package/src/__tests__/sakila-db/C6.js +1 -1
- package/src/__tests__/sakila-db/C6.ts +2 -2
- package/src/api/executors/HttpExecutor.ts +98 -160
|
@@ -3,6 +3,7 @@ import { OrmGenerics } from "../types/ormGenerics";
|
|
|
3
3
|
import { DetermineResponseDataType, RequestQueryBody } from "../types/ormInterfaces";
|
|
4
4
|
import { Executor } from "./Executor";
|
|
5
5
|
export declare class HttpExecutor<G extends OrmGenerics> extends Executor<G> {
|
|
6
|
+
private isRestResponse;
|
|
6
7
|
private stripTableNameFromKeys;
|
|
7
8
|
putState(response: AxiosResponse<DetermineResponseDataType<G['RequestMethod'], G['RestTableInterface']>>, request: RequestQueryBody<G['RequestMethod'], G['RestTableInterface'], G['CustomAndRequiredFields'], G['RequestTableOverrides']>, callback: () => void): void;
|
|
8
9
|
postState(response: AxiosResponse<DetermineResponseDataType<G['RequestMethod'], G['RestTableInterface']>>, request: RequestQueryBody<G['RequestMethod'], G['RestTableInterface'], G['CustomAndRequiredFields'], G['RequestTableOverrides']>, callback: () => void): void;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Express } from "express";
|
|
2
|
+
import { Pool } from "mysql2/promise";
|
|
3
|
+
import { iC6Object } from "api/types/ormInterfaces";
|
|
4
|
+
export declare function createTestServer({ C6, mysqlPool }: {
|
|
5
|
+
C6: iC6Object;
|
|
6
|
+
mysqlPool: Pool;
|
|
7
|
+
}): Express;
|
|
8
|
+
export default createTestServer;
|
package/dist/index.cjs.js
CHANGED
|
@@ -628,13 +628,20 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
628
628
|
function HttpExecutor() {
|
|
629
629
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
630
630
|
}
|
|
631
|
+
HttpExecutor.prototype.isRestResponse = function (r) {
|
|
632
|
+
return !!r && r.data != null && typeof r.data === 'object' && 'rest' in r.data;
|
|
633
|
+
};
|
|
631
634
|
HttpExecutor.prototype.stripTableNameFromKeys = function (obj) {
|
|
632
|
-
var
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
635
|
+
var _a;
|
|
636
|
+
var columns = this.config.restModel.COLUMNS;
|
|
637
|
+
var source = (obj !== null && obj !== void 0 ? obj : {});
|
|
638
|
+
var out = {};
|
|
639
|
+
for (var _i = 0, _b = Object.entries(source); _i < _b.length; _i++) {
|
|
640
|
+
var _c = _b[_i], key = _c[0], value = _c[1];
|
|
641
|
+
var short = (_a = columns[key]) !== null && _a !== void 0 ? _a : (key.includes('.') ? key.split('.').pop() : key);
|
|
642
|
+
out[short] = value;
|
|
643
|
+
}
|
|
644
|
+
return out;
|
|
638
645
|
};
|
|
639
646
|
HttpExecutor.prototype.putState = function (response, request, callback) {
|
|
640
647
|
var _a, _b;
|
|
@@ -651,14 +658,15 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
651
658
|
HttpExecutor.prototype.postState = function (response, request, callback) {
|
|
652
659
|
var _this = this;
|
|
653
660
|
var _a, _b, _c;
|
|
654
|
-
if (
|
|
655
|
-
console.error("C6 received unexpected result's given the primary key length");
|
|
656
|
-
}
|
|
657
|
-
else {
|
|
661
|
+
if (this.config.restModel.PRIMARY_SHORT.length === 1) {
|
|
658
662
|
var pk = this.config.restModel.PRIMARY_SHORT[0];
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
663
|
+
try {
|
|
664
|
+
request[pk] = (_a = response.data) === null || _a === void 0 ? void 0 : _a.created;
|
|
665
|
+
}
|
|
666
|
+
catch ( /* best-effort */_d) { /* best-effort */ }
|
|
667
|
+
}
|
|
668
|
+
else if (isLocal()) {
|
|
669
|
+
console.error("C6 received unexpected results given the primary key length");
|
|
662
670
|
}
|
|
663
671
|
(_b = this.config.reactBootstrap) === null || _b === void 0 ? void 0 : _b.updateRestfulObjectArrays({
|
|
664
672
|
callback: callback,
|
|
@@ -691,8 +699,9 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
691
699
|
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
692
700
|
var _a, C6, axios, restURL, withCredentials, restModel, reactBootstrap, requestMethod, skipPrimaryCheck, clearCache, tableName, fullTableList, operatingTableFullName, operatingTable, tables, query, apiRequest;
|
|
693
701
|
var _this = this;
|
|
694
|
-
|
|
695
|
-
|
|
702
|
+
var _b;
|
|
703
|
+
return tslib.__generator(this, function (_c) {
|
|
704
|
+
switch (_c.label) {
|
|
696
705
|
case 0:
|
|
697
706
|
_a = this.config, C6 = _a.C6, axios = _a.axios, restURL = _a.restURL, withCredentials = _a.withCredentials, restModel = _a.restModel, reactBootstrap = _a.reactBootstrap, requestMethod = _a.requestMethod, skipPrimaryCheck = _a.skipPrimaryCheck, clearCache = _a.clearCache;
|
|
698
707
|
return [4 /*yield*/, this.runLifecycleHooks("beforeProcessing", {
|
|
@@ -700,7 +709,7 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
700
709
|
request: this.request,
|
|
701
710
|
})];
|
|
702
711
|
case 1:
|
|
703
|
-
|
|
712
|
+
_c.sent();
|
|
704
713
|
tableName = restModel.TABLE_NAME;
|
|
705
714
|
fullTableList = Array.isArray(tableName) ? tableName : [tableName];
|
|
706
715
|
operatingTableFullName = fullTableList[0];
|
|
@@ -715,45 +724,40 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
715
724
|
default:
|
|
716
725
|
throw Error('Bad request method passed to getApi');
|
|
717
726
|
}
|
|
718
|
-
if (
|
|
719
|
-
exports.userCustomClearCache
|
|
727
|
+
if (clearCache != null) {
|
|
728
|
+
exports.userCustomClearCache.push(clearCache);
|
|
729
|
+
}
|
|
730
|
+
if (isLocal() && (this.config.verbose || ((_b = this.request) === null || _b === void 0 ? void 0 : _b.debug))) {
|
|
731
|
+
console.groupCollapsed('%c API:', 'color: #0c0', "(".concat(requestMethod, ") Request for (").concat(tableName, ")"));
|
|
732
|
+
console.log('request', this.request);
|
|
733
|
+
console.groupEnd();
|
|
720
734
|
}
|
|
721
|
-
console.groupCollapsed('%c API: (' + requestMethod + ') Request for (' + tableName + ')', 'color: #0c0');
|
|
722
|
-
console.log('request', this.request);
|
|
723
|
-
console.groupEnd();
|
|
724
735
|
// an undefined query would indicate queryCallback returned undefined,
|
|
725
736
|
// thus the request shouldn't fire as is in custom cache
|
|
726
737
|
if (undefined === this.request || null === this.request) {
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
738
|
+
if (isLocal()) {
|
|
739
|
+
console.groupCollapsed("API: (".concat(requestMethod, ") (").concat(tableName, ") query undefined/null \u2192 returning null"));
|
|
740
|
+
console.log('request', this.request);
|
|
741
|
+
console.groupEnd();
|
|
742
|
+
}
|
|
732
743
|
return [2 /*return*/, null];
|
|
733
744
|
}
|
|
734
745
|
query = this.request;
|
|
735
|
-
if (C6.GET === requestMethod) {
|
|
736
|
-
if (undefined === query[C6.PAGINATION]) {
|
|
737
|
-
query[C6.PAGINATION] = {};
|
|
738
|
-
}
|
|
739
|
-
query[C6.PAGINATION][C6.PAGE] = query[C6.PAGINATION][C6.PAGE] || 1;
|
|
740
|
-
query[C6.PAGINATION][C6.LIMIT] = query[C6.PAGINATION][C6.LIMIT] || 100;
|
|
741
|
-
}
|
|
742
746
|
apiRequest = function () { return tslib.__awaiter(_this, void 0, void 0, function () {
|
|
743
|
-
var _a, debug, _b, cacheResults, dataInsertMultipleRows, success, _c, fetchDependencies, _d, error, querySerialized, cacheResult, cachingConfirmed, cacheCheck, cacheCheck, apiResponse, returnGetNextPageFunction, restRequestUri, needsConditionOrPrimaryCheck, TABLES, primaryKeyList, primaryKeyFullyQualified, primaryKey, providedPrimary, primaryVal, axiosActiveRequest;
|
|
747
|
+
var _a, debug, _b, cacheResults, dataInsertMultipleRows, success, _c, fetchDependencies, _d, error, querySerialized, cacheResult, cachingConfirmed, cacheCheck, cacheCheck, apiResponse, returnGetNextPageFunction, restRequestUri, needsConditionOrPrimaryCheck, TABLES, primaryKeyList, primaryKeyFullyQualified, primaryKey, whereVal, whereIsEmpty, providedPrimary, primaryVal, axiosActiveRequest;
|
|
744
748
|
var _e;
|
|
745
749
|
var _this = this;
|
|
746
|
-
var _f, _g, _h, _j, _k, _l;
|
|
747
|
-
return tslib.__generator(this, function (
|
|
748
|
-
switch (
|
|
750
|
+
var _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
751
|
+
return tslib.__generator(this, function (_r) {
|
|
752
|
+
switch (_r.label) {
|
|
749
753
|
case 0:
|
|
750
754
|
_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;
|
|
751
755
|
if (C6.GET === requestMethod
|
|
752
756
|
&& undefined !== ((_f = query === null || query === void 0 ? void 0 : query[C6.PAGINATION]) === null || _f === void 0 ? void 0 : _f[C6.PAGE])
|
|
753
|
-
&& 1 !== query[C6.PAGINATION][C6.PAGE]
|
|
754
|
-
|
|
755
|
-
console.
|
|
756
|
-
console.
|
|
757
|
+
&& 1 !== query[C6.PAGINATION][C6.PAGE]
|
|
758
|
+
&& isLocal()) {
|
|
759
|
+
console.groupCollapsed("Request (".concat(tableName, ") page (").concat(query[C6.PAGINATION][C6.PAGE], ")"));
|
|
760
|
+
console.log('request', this.request);
|
|
757
761
|
console.groupEnd();
|
|
758
762
|
}
|
|
759
763
|
querySerialized = sortAndSerializeQueryObject(tables, query !== null && query !== void 0 ? query : {});
|
|
@@ -770,39 +774,35 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
770
774
|
query[C6.PAGINATION][C6.LIMIT] = query[C6.PAGINATION][C6.LIMIT] || 100;
|
|
771
775
|
if (!(true === cacheResults)) return [3 /*break*/, 7];
|
|
772
776
|
if (!(undefined !== cacheResult)) return [3 /*break*/, 6];
|
|
773
|
-
|
|
777
|
+
_r.label = 1;
|
|
774
778
|
case 1:
|
|
775
779
|
cacheCheck = checkCache(cacheResult, requestMethod, tableName, this.request);
|
|
776
780
|
if (!(false !== cacheCheck)) return [3 /*break*/, 3];
|
|
777
781
|
return [4 /*yield*/, cacheCheck];
|
|
778
|
-
case 2: return [2 /*return*/, (
|
|
782
|
+
case 2: return [2 /*return*/, (_r.sent()).data];
|
|
779
783
|
case 3:
|
|
780
|
-
// this line incrementing page is why we return recursively
|
|
781
784
|
++query[C6.PAGINATION][C6.PAGE];
|
|
782
|
-
// this json stringify is to capture the new page number
|
|
783
785
|
querySerialized = sortAndSerializeQueryObject(tables, query !== null && query !== void 0 ? query : {});
|
|
784
786
|
cacheResult = exports.apiRequestCache.find(function (cache) { return cache.requestArgumentsSerialized === querySerialized; });
|
|
785
|
-
|
|
787
|
+
_r.label = 4;
|
|
786
788
|
case 4:
|
|
787
789
|
if (undefined !== cacheResult) return [3 /*break*/, 1];
|
|
788
|
-
|
|
790
|
+
_r.label = 5;
|
|
789
791
|
case 5:
|
|
790
792
|
if (debug && isLocal()) {
|
|
791
|
-
reactToastify.toast.warning("DEVS: Request
|
|
793
|
+
reactToastify.toast.warning("DEVS: Request pages exhausted in cache; firing network.", toastOptionsDevs);
|
|
792
794
|
}
|
|
793
|
-
|
|
794
|
-
return [2 /*return*/, apiRequest];
|
|
795
|
+
_r.label = 6;
|
|
795
796
|
case 6:
|
|
796
797
|
cachingConfirmed = true;
|
|
797
798
|
return [3 /*break*/, 8];
|
|
798
799
|
case 7:
|
|
799
|
-
if (debug && isLocal())
|
|
800
|
+
if (debug && isLocal())
|
|
800
801
|
reactToastify.toast.info("DEVS: Ignore cache was set to true.", toastOptionsDevs);
|
|
801
|
-
|
|
802
|
-
_m.label = 8;
|
|
802
|
+
_r.label = 8;
|
|
803
803
|
case 8:
|
|
804
804
|
if (debug && isLocal()) {
|
|
805
|
-
reactToastify.toast.success("DEVS: Request not in cache." + (requestMethod === C6.GET ? "Page (" + query[C6.PAGINATION][C6.PAGE] + ")
|
|
805
|
+
reactToastify.toast.success("DEVS: Request not in cache." + (requestMethod === C6.GET ? " Page (" + query[C6.PAGINATION][C6.PAGE] + ")" : ''), toastOptionsDevs);
|
|
806
806
|
}
|
|
807
807
|
return [3 /*break*/, 12];
|
|
808
808
|
case 9:
|
|
@@ -811,10 +811,10 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
811
811
|
cacheCheck = checkCache(cacheResult, requestMethod, tableName, this.request);
|
|
812
812
|
if (!(false !== cacheCheck)) return [3 /*break*/, 11];
|
|
813
813
|
return [4 /*yield*/, cacheCheck];
|
|
814
|
-
case 10: return [2 /*return*/, (
|
|
814
|
+
case 10: return [2 /*return*/, (_r.sent()).data];
|
|
815
815
|
case 11:
|
|
816
816
|
cachingConfirmed = true;
|
|
817
|
-
|
|
817
|
+
_r.label = 12;
|
|
818
818
|
case 12:
|
|
819
819
|
returnGetNextPageFunction = false;
|
|
820
820
|
restRequestUri = restURL + operatingTable + '/';
|
|
@@ -826,12 +826,11 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
826
826
|
primaryKey = (_h = primaryKeyFullyQualified === null || primaryKeyFullyQualified === void 0 ? void 0 : primaryKeyFullyQualified.split('.')) === null || _h === void 0 ? void 0 : _h.pop();
|
|
827
827
|
if (needsConditionOrPrimaryCheck) {
|
|
828
828
|
if (undefined === primaryKey) {
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|| (Object.keys(query === null || query === void 0 ? void 0 : query[C6.WHERE]).length === 0)) {
|
|
829
|
+
whereVal = query === null || query === void 0 ? void 0 : query[C6.WHERE];
|
|
830
|
+
whereIsEmpty = whereVal == null ||
|
|
831
|
+
(Array.isArray(whereVal) && whereVal.length === 0) ||
|
|
832
|
+
(typeof whereVal === 'object' && !Array.isArray(whereVal) && Object.keys(whereVal).length === 0);
|
|
833
|
+
if (whereIsEmpty) {
|
|
835
834
|
console.error(query);
|
|
836
835
|
throw Error('Failed to parse primary key information. Query: (' + JSON.stringify(query) + ') Primary Key: (' + JSON.stringify(primaryKey) + ') TABLES[operatingTable]?.PRIMARY: (' + JSON.stringify((_j = TABLES[operatingTable]) === null || _j === void 0 ? void 0 : _j.PRIMARY) + ') for operatingTable (' + operatingTable + ').');
|
|
837
836
|
}
|
|
@@ -862,22 +861,27 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
862
861
|
primaryVal = (_l = query[primaryKey]) !== null && _l !== void 0 ? _l : (primaryKeyFullyQualified ? query[primaryKeyFullyQualified] : undefined);
|
|
863
862
|
if (undefined !== primaryVal) {
|
|
864
863
|
restRequestUri += primaryVal + '/';
|
|
865
|
-
|
|
864
|
+
if (isLocal() && (this.config.verbose || ((_m = this.request) === null || _m === void 0 ? void 0 : _m.debug))) {
|
|
865
|
+
console.log('query', query, 'primaryKey', primaryKey);
|
|
866
|
+
}
|
|
866
867
|
}
|
|
867
868
|
else {
|
|
868
|
-
|
|
869
|
+
if (isLocal() && (this.config.verbose || ((_o = this.request) === null || _o === void 0 ? void 0 : _o.debug))) {
|
|
870
|
+
console.log('query', query);
|
|
871
|
+
}
|
|
869
872
|
}
|
|
870
873
|
}
|
|
871
874
|
else {
|
|
872
|
-
|
|
875
|
+
if (isLocal() && (this.config.verbose || ((_p = this.request) === null || _p === void 0 ? void 0 : _p.debug))) {
|
|
876
|
+
console.log('query', query);
|
|
877
|
+
}
|
|
873
878
|
}
|
|
874
879
|
try {
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
console.groupEnd();
|
|
880
|
+
if (isLocal() && (this.config.verbose || ((_q = this.request) === null || _q === void 0 ? void 0 : _q.debug))) {
|
|
881
|
+
console.groupCollapsed('%c API:', 'color: #A020F0', "(".concat(requestMethod, ") (").concat(operatingTable, ") firing"));
|
|
882
|
+
console.log(this.request);
|
|
883
|
+
console.groupEnd();
|
|
884
|
+
}
|
|
881
885
|
this.runLifecycleHooks("beforeExecution", {
|
|
882
886
|
config: this.config,
|
|
883
887
|
request: this.request
|
|
@@ -918,11 +922,11 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
918
922
|
// returning the promise with this then is important for tests. todo - we could make that optional.
|
|
919
923
|
// https://rapidapi.com/guides/axios-async-await
|
|
920
924
|
return [2 /*return*/, axiosActiveRequest.then(function (response) { return tslib.__awaiter(_this, void 0, void 0, function () {
|
|
921
|
-
var cacheIndex, callback, responseData_1, dependencies_1, fetchReferences_1, apiRequestPromises, _loop_1, tableToFetch;
|
|
925
|
+
var cacheIndex, callback, responseData_1, pageLimit, got, hasNext, cacheIndex, dependencies_1, fetchReferences_1, apiRequestPromises, _loop_1, tableToFetch;
|
|
922
926
|
var _this = this;
|
|
923
|
-
var _a, _b, _c, _d
|
|
924
|
-
return tslib.__generator(this, function (
|
|
925
|
-
switch (
|
|
927
|
+
var _a, _b, _c, _d;
|
|
928
|
+
return tslib.__generator(this, function (_e) {
|
|
929
|
+
switch (_e.label) {
|
|
926
930
|
case 0:
|
|
927
931
|
// noinspection SuspiciousTypeOfGuard
|
|
928
932
|
if (typeof response.data === 'string') {
|
|
@@ -944,13 +948,13 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
944
948
|
request: this.request,
|
|
945
949
|
response: response
|
|
946
950
|
});
|
|
947
|
-
// todo - this feels dumb now, but i digress
|
|
948
951
|
apiResponse = TestRestfulResponse(response, success, error);
|
|
949
952
|
if (false === apiResponse) {
|
|
950
953
|
if (debug && isLocal()) {
|
|
951
|
-
reactToastify.toast.warning("DEVS: TestRestfulResponse returned false
|
|
954
|
+
reactToastify.toast.warning("DEVS: TestRestfulResponse returned false.", toastOptionsDevs);
|
|
952
955
|
}
|
|
953
|
-
|
|
956
|
+
// Force a null payload so the final .then(response => response.data) yields null
|
|
957
|
+
return [2 /*return*/, Promise.resolve(tslib.__assign(tslib.__assign({}, response), { data: null }))];
|
|
954
958
|
}
|
|
955
959
|
callback = function () { return _this.runLifecycleHooks("afterCommit", {
|
|
956
960
|
config: _this.config,
|
|
@@ -982,28 +986,29 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
982
986
|
else {
|
|
983
987
|
callback();
|
|
984
988
|
}
|
|
985
|
-
if (!(C6.GET === requestMethod)) return [3 /*break*/, 2];
|
|
989
|
+
if (!(C6.GET === requestMethod && this.isRestResponse(response))) return [3 /*break*/, 2];
|
|
986
990
|
responseData_1 = response.data;
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
console.log('%c Request Data (note you may see the success and/or error prompt):', 'color: #0c0', this.request);
|
|
993
|
-
console.log('%c Response Data:', 'color: #0c0', responseData_1.rest);
|
|
994
|
-
console.log('%c Will return get next page function:' + (returnGetNextPageFunction ? '' : ' (Will not return with explicit limit 1 set)'), 'color: #0c0', true === returnGetNextPageFunction);
|
|
995
|
-
console.trace();
|
|
996
|
-
console.groupEnd();
|
|
997
|
-
}
|
|
998
|
-
if (false === returnGetNextPageFunction) {
|
|
999
|
-
responseData_1.next = apiRequest;
|
|
991
|
+
pageLimit = (_a = query === null || query === void 0 ? void 0 : query[C6.PAGINATION]) === null || _a === void 0 ? void 0 : _a[C6.LIMIT];
|
|
992
|
+
got = responseData_1.rest.length;
|
|
993
|
+
hasNext = pageLimit !== 1 && got === pageLimit;
|
|
994
|
+
if (hasNext) {
|
|
995
|
+
responseData_1.next = apiRequest; // there might be more
|
|
1000
996
|
}
|
|
1001
997
|
else {
|
|
1002
|
-
responseData_1.next = undefined;
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
998
|
+
responseData_1.next = undefined; // short page => done
|
|
999
|
+
}
|
|
1000
|
+
// If you keep this flag, make it reflect reality:
|
|
1001
|
+
returnGetNextPageFunction = hasNext;
|
|
1002
|
+
// and fix cache ‘final’ flag to match:
|
|
1003
|
+
if (cachingConfirmed) {
|
|
1004
|
+
cacheIndex = exports.apiRequestCache.findIndex(function (c) { return c.requestArgumentsSerialized === querySerialized; });
|
|
1005
|
+
exports.apiRequestCache[cacheIndex].final = !hasNext;
|
|
1006
|
+
}
|
|
1007
|
+
if ((this.config.verbose || debug) && isLocal()) {
|
|
1008
|
+
console.groupCollapsed("API: Response (".concat(requestMethod, " ").concat(tableName, ") len (").concat((_b = responseData_1.rest) === null || _b === void 0 ? void 0 : _b.length, ") of (").concat((_c = query === null || query === void 0 ? void 0 : query[C6.PAGINATION]) === null || _c === void 0 ? void 0 : _c[C6.LIMIT], ")"));
|
|
1009
|
+
console.log('request', this.request);
|
|
1010
|
+
console.log('response.rest', responseData_1.rest);
|
|
1011
|
+
console.groupEnd();
|
|
1007
1012
|
}
|
|
1008
1013
|
if (!(fetchDependencies
|
|
1009
1014
|
&& 'number' === typeof fetchDependencies
|
|
@@ -1078,7 +1083,7 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1078
1083
|
}); });
|
|
1079
1084
|
console.log('fetchReferences', fetchReferences_1);
|
|
1080
1085
|
_loop_1 = function (tableToFetch) {
|
|
1081
|
-
var
|
|
1086
|
+
var _f;
|
|
1082
1087
|
if (fetchDependencies & exports.eFetchDependencies.C6ENTITY
|
|
1083
1088
|
&& 'string' === typeof tableName
|
|
1084
1089
|
&& tableName.endsWith("carbon_carbons")) {
|
|
@@ -1101,7 +1106,7 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1101
1106
|
.split('_')
|
|
1102
1107
|
.map(function (part) { return part.charAt(0).toUpperCase() + part.slice(1); })
|
|
1103
1108
|
.join('_');
|
|
1104
|
-
var RestApi = (
|
|
1109
|
+
var RestApi = (_d = C6.ORM[ormKey]) !== null && _d !== void 0 ? _d : new Error("Fetch Dependencies could not find table (".concat(ormKey, ") in the set \u2209 [ ").concat(Object.keys(C6.ORM).join(', '), " ]"));
|
|
1105
1110
|
console.log('%c Fetch Dependencies will select (' + tableToFetch + ') using GET request', 'color: #33ccff');
|
|
1106
1111
|
var nextFetchDependencies = exports.eFetchDependencies.NONE;
|
|
1107
1112
|
if (fetchDependencies & exports.eFetchDependencies.RECURSIVE) {
|
|
@@ -1127,8 +1132,8 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1127
1132
|
console.log('RestApi object', RestApi);
|
|
1128
1133
|
// this is a dynamic call to the rest api, any generated table may resolve with (RestApi)
|
|
1129
1134
|
// todo - using value to avoid joins.... but. maybe this should be a parameterizable option -- think race conditions; its safer to join
|
|
1130
|
-
apiRequestPromises.push(RestApi.Get((
|
|
1131
|
-
|
|
1135
|
+
apiRequestPromises.push(RestApi.Get((_f = {},
|
|
1136
|
+
_f[C6.WHERE] = Object.keys(fetchReferences_1[tableToFetch]).reduce(function (sum, column) {
|
|
1132
1137
|
fetchReferences_1[tableToFetch][column] = fetchReferences_1[tableToFetch][column].flat(Infinity);
|
|
1133
1138
|
if (0 === fetchReferences_1[tableToFetch][column].length) {
|
|
1134
1139
|
console.warn('The column (' + column + ') was not found in the response data. We will not fetch.', responseData_1);
|
|
@@ -1141,8 +1146,8 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1141
1146
|
];
|
|
1142
1147
|
return sum;
|
|
1143
1148
|
}, {}),
|
|
1144
|
-
|
|
1145
|
-
|
|
1149
|
+
_f.fetchDependencies = nextFetchDependencies,
|
|
1150
|
+
_f)));
|
|
1146
1151
|
};
|
|
1147
1152
|
for (tableToFetch in fetchReferences_1) {
|
|
1148
1153
|
_loop_1(tableToFetch);
|
|
@@ -1150,7 +1155,7 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1150
1155
|
console.groupEnd();
|
|
1151
1156
|
return [4 /*yield*/, Promise.all(apiRequestPromises)];
|
|
1152
1157
|
case 1:
|
|
1153
|
-
|
|
1158
|
+
_e.sent();
|
|
1154
1159
|
apiRequestPromises.map(function (promise) { return tslib.__awaiter(_this, void 0, void 0, function () {
|
|
1155
1160
|
var _a, _b;
|
|
1156
1161
|
return tslib.__generator(this, function (_c) {
|
|
@@ -1168,7 +1173,7 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1168
1173
|
}
|
|
1169
1174
|
});
|
|
1170
1175
|
}); });
|
|
1171
|
-
|
|
1176
|
+
_e.label = 2;
|
|
1172
1177
|
case 2:
|
|
1173
1178
|
if (debug && isLocal()) {
|
|
1174
1179
|
reactToastify.toast.success("DEVS: (" + requestMethod + ") request complete.", toastOptionsDevs);
|
|
@@ -1196,7 +1201,7 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1196
1201
|
});
|
|
1197
1202
|
}); };
|
|
1198
1203
|
return [4 /*yield*/, apiRequest()];
|
|
1199
|
-
case 2: return [2 /*return*/,
|
|
1204
|
+
case 2: return [2 /*return*/, _c.sent()];
|
|
1200
1205
|
}
|
|
1201
1206
|
});
|
|
1202
1207
|
});
|