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