@carbonorm/carbonnode 1.5.1 → 1.6.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/README.md +1 -1
- package/dist/api/interfaces/ormInterfaces.d.ts +12 -4
- package/dist/api/restRequest.d.ts +17 -4
- package/dist/index.cjs.js +213 -54
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +214 -55
- package/dist/index.esm.js.map +1 -1
- package/package.json +2 -2
- package/scripts/assets/handlebars/C6.ts.handlebars +39 -0
- package/scripts/assets/handlebars/C6RestApi.ts.handlebars +23 -0
- package/scripts/generateRestBindings.cjs +6 -2
- package/scripts/generateRestBindings.ts +6 -5
- package/src/api/interfaces/ormInterfaces.ts +27 -2
- package/src/api/restRequest.ts +133 -30
- package/scripts/assets/handlebars/WsLiveUpdates.ts.handlebars +0 -22
package/README.md
CHANGED
|
@@ -63,7 +63,7 @@ generate. Here are the templates used to generate the code:
|
|
|
63
63
|
|
|
64
64
|
1) [C6.ts.handlebars](https://github.com/CarbonORM/CarbonNode/blob/main/scripts/assets/handlebars/C6.ts.handlebars)
|
|
65
65
|
2) [Table.ts.handlebars](https://github.com/CarbonORM/CarbonNode/blob/main/scripts/assets/handlebars/Table.ts.handlebars)
|
|
66
|
-
3) [Websocket.ts.handlebars](https://github.com/CarbonORM/CarbonNode/blob/main/scripts/assets/handlebars/
|
|
66
|
+
3) [Websocket.ts.handlebars](https://github.com/CarbonORM/CarbonNode/blob/main/scripts/assets/handlebars/C6RestApi.ts.handlebars)
|
|
67
67
|
|
|
68
68
|
#### Generation Example
|
|
69
69
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { apiReturn, iAPI, iDeleteC6RestResponse, iPostC6RestResponse, iGetC6RestResponse, iPutC6RestResponse } from "api/restRequest";
|
|
1
2
|
export interface stringMap {
|
|
2
3
|
[key: string]: string;
|
|
3
4
|
}
|
|
@@ -37,15 +38,22 @@ export interface iC6RestfulModel<RestShortTableNames extends string = string> {
|
|
|
37
38
|
[columnName: string]: iConstraint[];
|
|
38
39
|
};
|
|
39
40
|
}
|
|
40
|
-
export
|
|
41
|
+
export interface iRestApiFunctions {
|
|
42
|
+
Delete: (request?: (iAPI<any> & any)) => apiReturn<iDeleteC6RestResponse<any>>;
|
|
43
|
+
Post: (request?: (iAPI<any> & any)) => apiReturn<iPostC6RestResponse<any>>;
|
|
44
|
+
Get: (request?: (iAPI<any> & any)) => apiReturn<iGetC6RestResponse<any>>;
|
|
45
|
+
Put: (request?: (iAPI<any> & any)) => apiReturn<iPutC6RestResponse<any>>;
|
|
46
|
+
}
|
|
47
|
+
export interface tC6Tables {
|
|
41
48
|
[key: string]: (iC6RestfulModel & {
|
|
42
49
|
[key: string]: any;
|
|
43
50
|
});
|
|
44
|
-
}
|
|
45
|
-
export
|
|
51
|
+
}
|
|
52
|
+
export interface tC6RestApi {
|
|
46
53
|
[key: string]: {
|
|
54
|
+
REST: iRestApiFunctions;
|
|
47
55
|
PUT: Function;
|
|
48
56
|
POST: Function;
|
|
49
57
|
DELETE: Function;
|
|
50
58
|
};
|
|
51
|
-
}
|
|
59
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { iC6RestfulModel } from "api/interfaces/ormInterfaces";
|
|
1
|
+
import { iC6RestfulModel, iRestApiFunctions, tC6RestApi } from "api/interfaces/ormInterfaces";
|
|
2
2
|
import { AxiosInstance, AxiosPromise, AxiosResponse } from "axios";
|
|
3
3
|
export declare function TestRestfulResponse(response: AxiosResponse | any, success: ((r: AxiosResponse) => (string | void)) | string | undefined, error: ((r: AxiosResponse) => (string | void)) | string | undefined): string | boolean | number;
|
|
4
4
|
export declare function removeInvalidKeys<iRestObject>(request: any, c6Tables: {
|
|
@@ -14,12 +14,20 @@ type AnyObject = Record<string, any>;
|
|
|
14
14
|
type DeepPartialAny<T> = {
|
|
15
15
|
[P in keyof T]?: T[P] extends AnyObject ? DeepPartialAny<T[P]> : any;
|
|
16
16
|
};
|
|
17
|
+
export declare enum eFetchDependencies {
|
|
18
|
+
NONE = 0,
|
|
19
|
+
REFERENCED = 1,
|
|
20
|
+
CHILDREN = 1,
|
|
21
|
+
REFERENCES = 2,
|
|
22
|
+
PARENTS = 2,
|
|
23
|
+
ALL = 3
|
|
24
|
+
}
|
|
17
25
|
export type iAPI<RestTableInterfaces extends {
|
|
18
26
|
[key: string]: any;
|
|
19
27
|
}> = RestTableInterfaces & {
|
|
20
28
|
dataInsertMultipleRows?: RestTableInterfaces[];
|
|
21
29
|
cacheResults?: boolean;
|
|
22
|
-
fetchDependencies?:
|
|
30
|
+
fetchDependencies?: eFetchDependencies | Promise<apiReturn<iGetC6RestResponse<any>>>[];
|
|
23
31
|
debug?: boolean;
|
|
24
32
|
success?: string | ((r: AxiosResponse) => (string | void));
|
|
25
33
|
error?: string | ((r: AxiosResponse) => (string | void));
|
|
@@ -82,12 +90,16 @@ export interface iPutC6RestResponse<RestData = any, RequestData = any> extends i
|
|
|
82
90
|
updated: boolean | number | string | RequestData;
|
|
83
91
|
}
|
|
84
92
|
export interface iC6Object {
|
|
93
|
+
C6VERSION: string;
|
|
85
94
|
TABLES: {
|
|
86
95
|
[key: string]: iC6RestfulModel & {
|
|
87
96
|
[key: string]: string | number;
|
|
88
97
|
};
|
|
89
98
|
};
|
|
90
99
|
PREFIX: string;
|
|
100
|
+
IMPORT: (tableName: string) => Promise<{
|
|
101
|
+
default: iRestApiFunctions;
|
|
102
|
+
}>;
|
|
91
103
|
[key: string]: any;
|
|
92
104
|
}
|
|
93
105
|
export type iGetC6RestResponse<ResponseDataType, ResponseDataOverrides = {}> = iC6RestResponse<Modify<ResponseDataType, ResponseDataOverrides> | Modify<ResponseDataType, ResponseDataOverrides>[]>;
|
|
@@ -100,6 +112,7 @@ interface iRest<CustomAndRequiredFields extends {
|
|
|
100
112
|
[key in keyof RestTableInterfaces]: any;
|
|
101
113
|
}, ResponseDataType = any, RestShortTableNames extends string = any> {
|
|
102
114
|
C6: iC6Object;
|
|
115
|
+
C6RestApi: () => tC6RestApi;
|
|
103
116
|
axios?: AxiosInstance;
|
|
104
117
|
restURL?: string;
|
|
105
118
|
withCredentials?: boolean;
|
|
@@ -121,7 +134,7 @@ export declare function extendedTypeHints<RestTableInterfaces extends {
|
|
|
121
134
|
} = any>(argv: any) => (request?: Omit<RequestTableTypes, keyof RequestTableOverrides> & RequestTableOverrides & {
|
|
122
135
|
dataInsertMultipleRows?: Modify<RequestTableTypes, RequestTableOverrides>[] | undefined;
|
|
123
136
|
cacheResults?: boolean | undefined;
|
|
124
|
-
fetchDependencies?:
|
|
137
|
+
fetchDependencies?: eFetchDependencies | Promise<apiReturn<iGetC6RestResponse<any, {}>>>[] | undefined;
|
|
125
138
|
debug?: boolean | undefined;
|
|
126
139
|
success?: string | ((r: AxiosResponse<any, any>) => string | void) | undefined;
|
|
127
140
|
error?: string | ((r: AxiosResponse<any, any>) => string | void) | undefined;
|
|
@@ -133,5 +146,5 @@ export default function restApi<CustomAndRequiredFields extends {
|
|
|
133
146
|
[key: string]: any;
|
|
134
147
|
} = any, RequestTableOverrides extends {
|
|
135
148
|
[key: string]: any;
|
|
136
|
-
} = any, ResponseDataType = any, RestShortTableNames extends string = any>({ C6, axios, restURL, withCredentials, tableName, requestMethod, queryCallback, responseCallback, skipPrimaryCheck, clearCache }: iRest<CustomAndRequiredFields, RestTableInterfaces, RequestTableOverrides, ResponseDataType, RestShortTableNames>): (request?: iAPI<Modify<RestTableInterfaces, RequestTableOverrides>> & CustomAndRequiredFields) => apiReturn<ResponseDataType>;
|
|
149
|
+
} = any, ResponseDataType = any, RestShortTableNames extends string = any>({ C6, C6RestApi, axios, restURL, withCredentials, tableName, requestMethod, queryCallback, responseCallback, skipPrimaryCheck, clearCache }: iRest<CustomAndRequiredFields, RestTableInterfaces, RequestTableOverrides, ResponseDataType, RestShortTableNames>): (request?: iAPI<Modify<RestTableInterfaces, RequestTableOverrides>> & CustomAndRequiredFields) => apiReturn<ResponseDataType>;
|
|
137
150
|
export {};
|
package/dist/index.cjs.js
CHANGED
|
@@ -261,6 +261,54 @@ var __assign = function() {
|
|
|
261
261
|
return __assign.apply(this, arguments);
|
|
262
262
|
};
|
|
263
263
|
|
|
264
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
265
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
266
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
267
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
268
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
269
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
270
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function __generator(thisArg, body) {
|
|
275
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
276
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
277
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
278
|
+
function step(op) {
|
|
279
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
280
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
281
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
282
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
283
|
+
switch (op[0]) {
|
|
284
|
+
case 0: case 1: t = op; break;
|
|
285
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
286
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
287
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
288
|
+
default:
|
|
289
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
290
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
291
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
292
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
293
|
+
if (t[2]) _.ops.pop();
|
|
294
|
+
_.trys.pop(); continue;
|
|
295
|
+
}
|
|
296
|
+
op = body.call(thisArg, _);
|
|
297
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
298
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function __spreadArray(to, from, pack) {
|
|
303
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
304
|
+
if (ar || !(i in from)) {
|
|
305
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
306
|
+
ar[i] = from[i];
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
310
|
+
}
|
|
311
|
+
|
|
264
312
|
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
265
313
|
var e = new Error(message);
|
|
266
314
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
@@ -400,6 +448,15 @@ function removeInvalidKeys(request, c6Tables) {
|
|
|
400
448
|
isTest || console.log('intersection', intersection);
|
|
401
449
|
return intersection;
|
|
402
450
|
}
|
|
451
|
+
exports.eFetchDependencies = void 0;
|
|
452
|
+
(function (eFetchDependencies) {
|
|
453
|
+
eFetchDependencies[eFetchDependencies["NONE"] = 0] = "NONE";
|
|
454
|
+
eFetchDependencies[eFetchDependencies["REFERENCED"] = 1] = "REFERENCED";
|
|
455
|
+
eFetchDependencies[eFetchDependencies["CHILDREN"] = 1] = "CHILDREN";
|
|
456
|
+
eFetchDependencies[eFetchDependencies["REFERENCES"] = 2] = "REFERENCES";
|
|
457
|
+
eFetchDependencies[eFetchDependencies["PARENTS"] = 2] = "PARENTS";
|
|
458
|
+
eFetchDependencies[eFetchDependencies["ALL"] = 3] = "ALL";
|
|
459
|
+
})(exports.eFetchDependencies || (exports.eFetchDependencies = {}));
|
|
403
460
|
// do not remove entries from this array. It is used to track the progress of API requests.
|
|
404
461
|
// position in array is important. Do not sort. To not add to begging.
|
|
405
462
|
var apiRequestCache = [];
|
|
@@ -472,7 +529,7 @@ function extendedTypeHints() {
|
|
|
472
529
|
return function (argv) { return restApi(argv); };
|
|
473
530
|
}
|
|
474
531
|
function restApi(_a) {
|
|
475
|
-
var C6 = _a.C6, _b = _a.axios, axios = _b === void 0 ? axiosInstance : _b, _c = _a.restURL, restURL = _c === void 0 ? '/rest/' : _c, _d = _a.withCredentials, withCredentials = _d === void 0 ? true : _d, tableName = _a.tableName, _e = _a.requestMethod, requestMethod = _e === void 0 ? GET : _e, _f = _a.queryCallback, queryCallback = _f === void 0 ? {} : _f, responseCallback = _a.responseCallback, _g = _a.skipPrimaryCheck, skipPrimaryCheck = _g === void 0 ? false : _g, _h = _a.clearCache, clearCache = _h === void 0 ? undefined : _h;
|
|
532
|
+
var C6 = _a.C6, C6RestApi = _a.C6RestApi, _b = _a.axios, axios = _b === void 0 ? axiosInstance : _b, _c = _a.restURL, restURL = _c === void 0 ? '/rest/' : _c, _d = _a.withCredentials, withCredentials = _d === void 0 ? true : _d, tableName = _a.tableName, _e = _a.requestMethod, requestMethod = _e === void 0 ? GET : _e, _f = _a.queryCallback, queryCallback = _f === void 0 ? {} : _f, responseCallback = _a.responseCallback, _g = _a.skipPrimaryCheck, skipPrimaryCheck = _g === void 0 ? false : _g, _h = _a.clearCache, clearCache = _h === void 0 ? undefined : _h;
|
|
476
533
|
var fullTableList = Array.isArray(tableName) ? tableName : [tableName];
|
|
477
534
|
var operatingTableFullName = fullTableList[0];
|
|
478
535
|
var operatingTable = operatingTableFullName.replace(C6.PREFIX, '');
|
|
@@ -522,6 +579,7 @@ function restApi(_a) {
|
|
|
522
579
|
}
|
|
523
580
|
// this could return itself with a new page number, or undefined if the end is reached
|
|
524
581
|
function apiRequest() {
|
|
582
|
+
var _this = this;
|
|
525
583
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
526
584
|
(_a = request.cacheResults) !== null && _a !== void 0 ? _a : (request.cacheResults = C6.GET === requestMethod);
|
|
527
585
|
if (C6.GET === requestMethod
|
|
@@ -652,32 +710,51 @@ function restApi(_a) {
|
|
|
652
710
|
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');
|
|
653
711
|
console.trace();
|
|
654
712
|
console.groupEnd();
|
|
655
|
-
var axiosActiveRequest = axios[requestMethod.toLowerCase()](
|
|
713
|
+
var axiosActiveRequest = axios[requestMethod.toLowerCase()].apply(axios, __spreadArray([restRequestUri], ((function () {
|
|
714
|
+
// @link - https://axios-http.com/docs/instance
|
|
715
|
+
// How configuration vs data is passed is variable, use documentation above for reference
|
|
656
716
|
if (requestMethod === GET) {
|
|
657
|
-
return {
|
|
658
|
-
|
|
659
|
-
|
|
717
|
+
return [{
|
|
718
|
+
withCredentials: withCredentials,
|
|
719
|
+
params: query
|
|
720
|
+
}];
|
|
660
721
|
}
|
|
661
722
|
else if (requestMethod === POST) {
|
|
662
723
|
if (undefined !== (request === null || request === void 0 ? void 0 : request.dataInsertMultipleRows)) {
|
|
663
|
-
return
|
|
664
|
-
|
|
665
|
-
|
|
724
|
+
return [
|
|
725
|
+
request.dataInsertMultipleRows.map(function (data) {
|
|
726
|
+
return convertForRequestBody(data, fullTableList, C6, function (message) { return reactToastify.toast.error(message, toastOptions); });
|
|
727
|
+
}),
|
|
728
|
+
{
|
|
729
|
+
withCredentials: withCredentials,
|
|
730
|
+
}
|
|
731
|
+
];
|
|
666
732
|
}
|
|
667
|
-
return
|
|
733
|
+
return [
|
|
734
|
+
convertForRequestBody(query, fullTableList, C6, function (message) { return reactToastify.toast.error(message, toastOptions); }),
|
|
735
|
+
{
|
|
736
|
+
withCredentials: withCredentials,
|
|
737
|
+
}
|
|
738
|
+
];
|
|
668
739
|
}
|
|
669
740
|
else if (requestMethod === PUT) {
|
|
670
|
-
return
|
|
741
|
+
return [
|
|
742
|
+
convertForRequestBody(query, fullTableList, C6, function (message) { return reactToastify.toast.error(message, toastOptions); }),
|
|
743
|
+
{
|
|
744
|
+
withCredentials: withCredentials,
|
|
745
|
+
}
|
|
746
|
+
];
|
|
671
747
|
}
|
|
672
748
|
else if (requestMethod === DELETE) {
|
|
673
|
-
return {
|
|
674
|
-
|
|
675
|
-
|
|
749
|
+
return [{
|
|
750
|
+
withCredentials: withCredentials,
|
|
751
|
+
data: convertForRequestBody(query, fullTableList, C6, function (message) { return reactToastify.toast.error(message, toastOptions); })
|
|
752
|
+
}];
|
|
676
753
|
}
|
|
677
754
|
else {
|
|
678
755
|
throw new Error('The request method (' + requestMethod + ') was not recognized.');
|
|
679
756
|
}
|
|
680
|
-
})())));
|
|
757
|
+
})()), false));
|
|
681
758
|
if (cachingConfirmed) {
|
|
682
759
|
// push to cache so we do not repeat the request
|
|
683
760
|
apiRequestCache.push({
|
|
@@ -688,51 +765,133 @@ function restApi(_a) {
|
|
|
688
765
|
// todo - wip verify this works
|
|
689
766
|
// we had removed the value from the request to add to the URI.
|
|
690
767
|
addBackPK === null || addBackPK === void 0 ? void 0 : addBackPK(); // adding back so post-processing methods work
|
|
768
|
+
// returning the promise with this then is important for tests. todo - we could make that optional.
|
|
691
769
|
// https://rapidapi.com/guides/axios-async-await
|
|
692
|
-
return axiosActiveRequest.then(function (response) {
|
|
693
|
-
var
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
770
|
+
return axiosActiveRequest.then(function (response) { return __awaiter(_this, void 0, void 0, function () {
|
|
771
|
+
var cacheIndex, responseData_1, C6FullApi_1, fetchDependencies, dependencies, _a, referencedBy, references, _b;
|
|
772
|
+
var _this = this;
|
|
773
|
+
var _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
774
|
+
return __generator(this, function (_m) {
|
|
775
|
+
switch (_m.label) {
|
|
776
|
+
case 0:
|
|
777
|
+
if (typeof response.data === 'string') {
|
|
778
|
+
if (isTest) {
|
|
779
|
+
console.trace();
|
|
780
|
+
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 + ')');
|
|
781
|
+
}
|
|
782
|
+
return [2 /*return*/, Promise.reject(response)];
|
|
783
|
+
}
|
|
784
|
+
if (cachingConfirmed) {
|
|
785
|
+
cacheIndex = apiRequestCache.findIndex(function (cache) { return cache.requestArgumentsSerialized === querySerialized; });
|
|
786
|
+
apiRequestCache[cacheIndex].final = false === returnGetNextPageFunction;
|
|
787
|
+
// only cache get method requests
|
|
788
|
+
apiRequestCache[cacheIndex].response = response;
|
|
789
|
+
}
|
|
790
|
+
apiResponse = TestRestfulResponse(response, request === null || request === void 0 ? void 0 : request.success, (_c = request === null || request === void 0 ? void 0 : request.error) !== null && _c !== void 0 ? _c : "An unexpected API error occurred!");
|
|
791
|
+
if (false === apiResponse) {
|
|
792
|
+
if (request.debug && isLocal) {
|
|
793
|
+
reactToastify.toast.warning("DEVS: TestRestfulResponse returned false for (" + operatingTable + ").", toastOptionsDevs);
|
|
794
|
+
}
|
|
795
|
+
return [2 /*return*/, response];
|
|
796
|
+
}
|
|
797
|
+
responseCallback(response, request, apiResponse);
|
|
798
|
+
if (!(C6.GET === requestMethod)) return [3 /*break*/, 9];
|
|
799
|
+
responseData_1 = response.data;
|
|
800
|
+
returnGetNextPageFunction = 1 !== ((_d = query === null || query === void 0 ? void 0 : query[C6.PAGINATION]) === null || _d === void 0 ? void 0 : _d[C6.LIMIT]) &&
|
|
801
|
+
((_e = query === null || query === void 0 ? void 0 : query[C6.PAGINATION]) === null || _e === void 0 ? void 0 : _e[C6.LIMIT]) === responseData_1.rest.length;
|
|
802
|
+
if (false === isTest || true === isVerbose) {
|
|
803
|
+
console.groupCollapsed('%c API: Response 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');
|
|
804
|
+
console.log('%c ' + requestMethod + ' ' + tableName, 'color: #0c0');
|
|
805
|
+
console.log('%c Request Data (note you may see the success and/or error prompt):', 'color: #0c0', request);
|
|
806
|
+
console.log('%c Response Data:', 'color: #0c0', responseData_1.rest);
|
|
807
|
+
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);
|
|
808
|
+
console.trace();
|
|
809
|
+
console.groupEnd();
|
|
810
|
+
}
|
|
811
|
+
if (false === returnGetNextPageFunction
|
|
812
|
+
&& true === request.debug
|
|
813
|
+
&& isLocal) {
|
|
814
|
+
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);
|
|
815
|
+
}
|
|
816
|
+
if (!(exports.eFetchDependencies.NONE !== request.fetchDependencies)) return [3 /*break*/, 8];
|
|
817
|
+
C6FullApi_1 = C6RestApi();
|
|
818
|
+
console.groupCollapsed('%c API: fetchDependencies segment', 'color: #0c0');
|
|
711
819
|
console.log('%c ' + requestMethod + ' ' + tableName, 'color: #0c0');
|
|
712
|
-
console.log('%c Request Data (note you may see the success and/or error prompt):', 'color: #0c0', request);
|
|
713
|
-
console.log('%c Response Data:', 'color: #0c0', responseData.rest);
|
|
714
|
-
console.log('%c Will return get next page function:' + (1 !== ((_f = query === null || query === void 0 ? void 0 : query[C6.PAGINATION]) === null || _f === void 0 ? void 0 : _f[C6.LIMIT]) ? '' : ' (Will not return with explicit limit 1 set)'), 'color: #0c0', true === returnGetNextPageFunction);
|
|
715
820
|
console.trace();
|
|
821
|
+
fetchDependencies = function (fetchData) { return __awaiter(_this, void 0, void 0, function () {
|
|
822
|
+
var _this = this;
|
|
823
|
+
return __generator(this, function (_a) {
|
|
824
|
+
return [2 /*return*/, Object.keys(fetchData).map(function (column) {
|
|
825
|
+
// check if the column is in the response
|
|
826
|
+
if (undefined === responseData_1.rest[column]) {
|
|
827
|
+
return false;
|
|
828
|
+
}
|
|
829
|
+
return fetchData[column].map(function (constraint) { return __awaiter(_this, void 0, void 0, function () {
|
|
830
|
+
var fetchTable, RestApi;
|
|
831
|
+
var _a, _b;
|
|
832
|
+
return __generator(this, function (_c) {
|
|
833
|
+
switch (_c.label) {
|
|
834
|
+
case 0:
|
|
835
|
+
console.log(C6FullApi_1, column, constraint.TABLE);
|
|
836
|
+
return [4 /*yield*/, C6.IMPORT(constraint.TABLE)];
|
|
837
|
+
case 1:
|
|
838
|
+
fetchTable = _c.sent();
|
|
839
|
+
RestApi = fetchTable.default;
|
|
840
|
+
return [2 /*return*/, RestApi.Get((_a = {},
|
|
841
|
+
_a[C6.WHERE] = (_b = {},
|
|
842
|
+
_b[constraint.COLUMN] = responseData_1.rest[column],
|
|
843
|
+
_b),
|
|
844
|
+
_a))];
|
|
845
|
+
}
|
|
846
|
+
});
|
|
847
|
+
}); });
|
|
848
|
+
})];
|
|
849
|
+
});
|
|
850
|
+
}); };
|
|
851
|
+
dependencies = [];
|
|
852
|
+
_a = request.fetchDependencies;
|
|
853
|
+
switch (_a) {
|
|
854
|
+
case exports.eFetchDependencies.ALL: return [3 /*break*/, 1];
|
|
855
|
+
case exports.eFetchDependencies.CHILDREN: return [3 /*break*/, 1];
|
|
856
|
+
case exports.eFetchDependencies.REFERENCED: return [3 /*break*/, 1];
|
|
857
|
+
case exports.eFetchDependencies.PARENTS: return [3 /*break*/, 3];
|
|
858
|
+
case exports.eFetchDependencies.REFERENCES: return [3 /*break*/, 3];
|
|
859
|
+
}
|
|
860
|
+
return [3 /*break*/, 5];
|
|
861
|
+
case 1:
|
|
862
|
+
referencedBy = C6.TABLES[operatingTable].TABLE_REFERENCED_BY;
|
|
863
|
+
return [4 /*yield*/, fetchDependencies(referencedBy)];
|
|
864
|
+
case 2:
|
|
865
|
+
dependencies = (_m.sent()).flat(Infinity);
|
|
866
|
+
if (request.fetchDependencies !== exports.eFetchDependencies.ALL) {
|
|
867
|
+
return [3 /*break*/, 6];
|
|
868
|
+
}
|
|
869
|
+
_m.label = 3;
|
|
870
|
+
case 3:
|
|
871
|
+
references = C6.TABLES[operatingTable].TABLE_REFERENCES;
|
|
872
|
+
_b = [__spreadArray([], dependencies, true)];
|
|
873
|
+
return [4 /*yield*/, fetchDependencies(references)];
|
|
874
|
+
case 4:
|
|
875
|
+
dependencies = __spreadArray.apply(void 0, _b.concat([[(_m.sent()).flat(Infinity)], false]));
|
|
876
|
+
return [3 /*break*/, 6];
|
|
877
|
+
case 5: throw new Error('The value of fetchDependencies (' + ((_l = request.fetchDependencies) === null || _l === void 0 ? void 0 : _l.toString()) + ') was not recognized.');
|
|
878
|
+
case 6:
|
|
879
|
+
request.fetchDependencies = dependencies;
|
|
880
|
+
return [4 /*yield*/, Promise.all(dependencies)];
|
|
881
|
+
case 7:
|
|
882
|
+
_m.sent();
|
|
883
|
+
_m.label = 8;
|
|
884
|
+
case 8:
|
|
716
885
|
console.groupEnd();
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
886
|
+
_m.label = 9;
|
|
887
|
+
case 9:
|
|
888
|
+
if (request.debug && isLocal) {
|
|
889
|
+
reactToastify.toast.success("DEVS: (" + requestMethod + ") request complete.", toastOptionsDevs);
|
|
890
|
+
}
|
|
891
|
+
return [2 /*return*/, response];
|
|
723
892
|
}
|
|
724
|
-
}
|
|
725
|
-
|
|
726
|
-
var cacheIndex = apiRequestCache.findIndex(function (cache) { return cache.requestArgumentsSerialized === querySerialized; });
|
|
727
|
-
apiRequestCache[cacheIndex].final = false === returnGetNextPageFunction;
|
|
728
|
-
// only cache get method requests
|
|
729
|
-
apiRequestCache[cacheIndex].response = response;
|
|
730
|
-
}
|
|
731
|
-
if (request.debug && isLocal) {
|
|
732
|
-
reactToastify.toast.success("DEVS: (" + requestMethod + ") request complete.", toastOptionsDevs);
|
|
733
|
-
}
|
|
734
|
-
return response;
|
|
735
|
-
});
|
|
893
|
+
});
|
|
894
|
+
}); });
|
|
736
895
|
}
|
|
737
896
|
catch (error) {
|
|
738
897
|
if (isTest) {
|