@carbonorm/carbonnode 3.0.2 → 3.0.4
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/convertForRequestBody.d.ts +7 -3
- package/dist/api/executors/Executor.d.ts +9 -9
- package/dist/api/executors/HttpExecutor.d.ts +9 -5
- package/dist/api/executors/SqlExecutor.d.ts +5 -5
- package/dist/api/restOrm.d.ts +15 -0
- package/dist/api/restRequest.d.ts +4 -5
- package/dist/api/types/ormInterfaces.d.ts +165 -139
- package/dist/index.cjs.js +263 -160
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +264 -161
- package/dist/index.esm.js.map +1 -1
- package/package.json +5 -4
- package/scripts/assets/handlebars/C6.test.ts.handlebars +88 -0
- package/scripts/assets/handlebars/C6.ts.handlebars +45 -12
- package/scripts/generateRestBindings.cjs +3 -7
- package/scripts/generateRestBindings.ts +3 -14
- package/src/api/convertForRequestBody.ts +62 -90
- package/src/api/executors/Executor.ts +67 -13
- package/src/api/executors/HttpExecutor.ts +224 -90
- package/src/api/executors/SqlExecutor.ts +6 -6
- package/src/api/restOrm.ts +61 -0
- package/src/api/restRequest.ts +19 -14
- package/src/api/types/ormInterfaces.ts +208 -246
- package/src/api/utils/apiHelpers.ts +4 -0
- package/src/index.ts +1 -0
- package/scripts/assets/handlebars/Table.test.ts.handlebars +0 -126
- package/scripts/assets/handlebars/Table.ts.handlebars +0 -193
package/dist/index.cjs.js
CHANGED
|
@@ -239,65 +239,70 @@ function convertForRequestBody (restfulObject, tableName, C6, regexErrorHandler)
|
|
|
239
239
|
if (regexErrorHandler === void 0) { regexErrorHandler = alert; }
|
|
240
240
|
var payload = {};
|
|
241
241
|
var tableNames = Array.isArray(tableName) ? tableName : [tableName];
|
|
242
|
-
var tableDefinitions =
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
throw new Error("Table name (".concat(tableName, ") is not found in the C6.TABLES object."));
|
|
242
|
+
var tableDefinitions = tableNames.map(function (name) {
|
|
243
|
+
var tableDefinition = Object.values(C6.TABLES).find(function (t) { return t.TABLE_NAME === name; });
|
|
244
|
+
if (!tableDefinition) {
|
|
245
|
+
console.error("Table name (".concat(name, ") is not found in the C6.TABLES object."), C6.TABLES);
|
|
246
|
+
throw new Error("Table name (".concat(name, ") is not found in the C6.TABLES object."));
|
|
248
247
|
}
|
|
249
|
-
|
|
248
|
+
return tableDefinition;
|
|
250
249
|
});
|
|
251
|
-
tableDefinitions.
|
|
252
|
-
|
|
253
|
-
|
|
250
|
+
for (var _i = 0, tableDefinitions_1 = tableDefinitions; _i < tableDefinitions_1.length; _i++) {
|
|
251
|
+
var tableDefinition = tableDefinitions_1[_i];
|
|
252
|
+
var _loop_1 = function (value) {
|
|
254
253
|
var shortReference = value.toUpperCase();
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
254
|
+
if ([
|
|
255
|
+
C6Constants.GET,
|
|
256
|
+
C6Constants.POST,
|
|
257
|
+
C6Constants.UPDATE,
|
|
258
|
+
C6Constants.REPLACE,
|
|
259
|
+
C6Constants.DELETE,
|
|
260
|
+
C6Constants.WHERE,
|
|
261
|
+
C6Constants.JOIN,
|
|
262
|
+
C6Constants.PAGINATION
|
|
263
|
+
].includes(value)) {
|
|
264
|
+
var val_1 = restfulObject[value];
|
|
265
|
+
if (Array.isArray(val_1)) {
|
|
266
|
+
payload[value] = val_1.sort();
|
|
267
|
+
}
|
|
268
|
+
else if (typeof val_1 === 'object' && val_1 !== null) {
|
|
269
|
+
payload[value] = Object.keys(val_1)
|
|
270
|
+
.sort()
|
|
271
|
+
.reduce(function (acc, key) {
|
|
272
|
+
var _a;
|
|
273
|
+
return (tslib.__assign(tslib.__assign({}, acc), (_a = {}, _a[key] = val_1[key], _a)));
|
|
274
|
+
}, {});
|
|
275
|
+
}
|
|
276
|
+
return "continue";
|
|
276
277
|
}
|
|
277
278
|
if (shortReference in tableDefinition) {
|
|
278
|
-
var
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
279
|
+
var longName = tableDefinition[shortReference];
|
|
280
|
+
var columnValue = restfulObject[value];
|
|
281
|
+
payload[longName] = columnValue;
|
|
282
|
+
var regexValidations = tableDefinition.REGEX_VALIDATION[longName];
|
|
283
|
+
if (regexValidations instanceof RegExp) {
|
|
284
|
+
if (!regexValidations.test(columnValue)) {
|
|
285
|
+
regexErrorHandler("Failed to match regex (".concat(regexValidations, ") for column (").concat(longName, ")"));
|
|
286
|
+
throw new Error("Failed to match regex (".concat(regexValidations, ") for column (").concat(longName, ")"));
|
|
285
287
|
}
|
|
286
288
|
}
|
|
287
|
-
else if (typeof
|
|
288
|
-
|
|
289
|
-
var regex =
|
|
290
|
-
if (
|
|
291
|
-
var devErrorMessage =
|
|
292
|
-
regexErrorHandler(errorMessage
|
|
293
|
-
throw Error(devErrorMessage);
|
|
289
|
+
else if (typeof regexValidations === 'object' && regexValidations !== null) {
|
|
290
|
+
for (var errorMessage in regexValidations) {
|
|
291
|
+
var regex = regexValidations[errorMessage];
|
|
292
|
+
if (!regex.test(columnValue)) {
|
|
293
|
+
var devErrorMessage = "Failed to match regex (".concat(regex, ") for column (").concat(longName, ")");
|
|
294
|
+
regexErrorHandler(errorMessage || devErrorMessage);
|
|
295
|
+
throw new Error(devErrorMessage);
|
|
294
296
|
}
|
|
295
|
-
}
|
|
297
|
+
}
|
|
296
298
|
}
|
|
297
299
|
}
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
|
|
300
|
+
};
|
|
301
|
+
for (var _a = 0, _b = Object.keys(restfulObject); _a < _b.length; _a++) {
|
|
302
|
+
var value = _b[_a];
|
|
303
|
+
_loop_1(value);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
301
306
|
return Object.keys(payload)
|
|
302
307
|
.sort()
|
|
303
308
|
.reduce(function (acc, key) {
|
|
@@ -314,31 +319,33 @@ var isNode = typeof process !== 'undefined' && !!((_a = process.versions) === nu
|
|
|
314
319
|
*/
|
|
315
320
|
function restRequest(config) {
|
|
316
321
|
var _this = this;
|
|
317
|
-
return function () {
|
|
318
|
-
var
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
case 2: return [4 /*yield*/, Promise.resolve().then(function () { return HttpExecutor$1; })];
|
|
335
|
-
case 3:
|
|
336
|
-
HttpExecutor = (_a.sent()).HttpExecutor;
|
|
337
|
-
http = new HttpExecutor(config, request);
|
|
338
|
-
return [2 /*return*/, http.execute()];
|
|
339
|
-
}
|
|
340
|
-
});
|
|
322
|
+
return function (request) { return tslib.__awaiter(_this, void 0, void 0, function () {
|
|
323
|
+
var SqlExecutor, executor, HttpExecutor, http;
|
|
324
|
+
return tslib.__generator(this, function (_a) {
|
|
325
|
+
switch (_a.label) {
|
|
326
|
+
case 0:
|
|
327
|
+
if (!(isNode && config.mysqlPool)) return [3 /*break*/, 2];
|
|
328
|
+
return [4 /*yield*/, Promise.resolve().then(function () { return SqlExecutor$1; })];
|
|
329
|
+
case 1:
|
|
330
|
+
SqlExecutor = (_a.sent()).SqlExecutor;
|
|
331
|
+
executor = new SqlExecutor(config, request);
|
|
332
|
+
return [2 /*return*/, executor.execute()];
|
|
333
|
+
case 2: return [4 /*yield*/, Promise.resolve().then(function () { return HttpExecutor$1; })];
|
|
334
|
+
case 3:
|
|
335
|
+
HttpExecutor = (_a.sent()).HttpExecutor;
|
|
336
|
+
http = new HttpExecutor(config, request);
|
|
337
|
+
return [2 /*return*/, http.execute()];
|
|
338
|
+
}
|
|
341
339
|
});
|
|
340
|
+
}); };
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
function restOrm(config) {
|
|
344
|
+
return {
|
|
345
|
+
Get: restRequest(tslib.__assign(tslib.__assign({}, config), { requestMethod: "GET" })),
|
|
346
|
+
Put: restRequest(tslib.__assign(tslib.__assign({}, config), { requestMethod: "PUT" })),
|
|
347
|
+
Post: restRequest(tslib.__assign(tslib.__assign({}, config), { requestMethod: "POST" })),
|
|
348
|
+
Delete: restRequest(tslib.__assign(tslib.__assign({}, config), { requestMethod: "DELETE" })),
|
|
342
349
|
};
|
|
343
350
|
}
|
|
344
351
|
|
|
@@ -515,15 +522,6 @@ function buildSelectQuery(table, primary, args, isSubSelect) {
|
|
|
515
522
|
return sql;
|
|
516
523
|
}
|
|
517
524
|
|
|
518
|
-
var Executor = /** @class */ (function () {
|
|
519
|
-
function Executor(config, request) {
|
|
520
|
-
if (request === void 0) { request = {}; }
|
|
521
|
-
this.config = config;
|
|
522
|
-
this.request = request;
|
|
523
|
-
}
|
|
524
|
-
return Executor;
|
|
525
|
-
}());
|
|
526
|
-
|
|
527
525
|
function getEnvVar(key, fallback) {
|
|
528
526
|
if (fallback === void 0) { fallback = ''; }
|
|
529
527
|
// Vite-style injection
|
|
@@ -539,15 +537,67 @@ function getEnvVar(key, fallback) {
|
|
|
539
537
|
return fallback;
|
|
540
538
|
}
|
|
541
539
|
|
|
540
|
+
var envVerbose = getEnvVar('VERBOSE') || getEnvVar('REACT_APP_VERBOSE') || getEnvVar('VITE_VERBOSE') || '';
|
|
541
|
+
var isVerbose = ['true', '1', 'yes', 'on'].includes(envVerbose.toLowerCase());
|
|
542
|
+
|
|
543
|
+
var Executor = /** @class */ (function () {
|
|
544
|
+
function Executor(config, request) {
|
|
545
|
+
this.config = config;
|
|
546
|
+
this.request = request;
|
|
547
|
+
}
|
|
548
|
+
Executor.prototype.runLifecycleHooks = function (phase, args) {
|
|
549
|
+
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
550
|
+
var lifecycleGroup, _i, _a, _b, key, fn, err_1;
|
|
551
|
+
var _c;
|
|
552
|
+
return tslib.__generator(this, function (_d) {
|
|
553
|
+
switch (_d.label) {
|
|
554
|
+
case 0:
|
|
555
|
+
lifecycleGroup = (_c = this.config.restModel.LIFECYCLE_HOOKS[this.config.requestMethod]) === null || _c === void 0 ? void 0 : _c[phase];
|
|
556
|
+
if (!lifecycleGroup)
|
|
557
|
+
return [2 /*return*/];
|
|
558
|
+
_i = 0, _a = Object.entries(lifecycleGroup);
|
|
559
|
+
_d.label = 1;
|
|
560
|
+
case 1:
|
|
561
|
+
if (!(_i < _a.length)) return [3 /*break*/, 6];
|
|
562
|
+
_b = _a[_i], key = _b[0], fn = _b[1];
|
|
563
|
+
if (!(typeof fn === "function")) return [3 /*break*/, 5];
|
|
564
|
+
if (isVerbose || args.request.debug) {
|
|
565
|
+
console.groupCollapsed("[LIFECYCLE] ".concat(this.config.requestMethod, ".").concat(String(phase), ":").concat(key));
|
|
566
|
+
console.log("config:", args.config);
|
|
567
|
+
console.log("request:", args.request);
|
|
568
|
+
if ("response" in args) {
|
|
569
|
+
console.log("response:", args.response);
|
|
570
|
+
}
|
|
571
|
+
console.groupEnd();
|
|
572
|
+
}
|
|
573
|
+
_d.label = 2;
|
|
574
|
+
case 2:
|
|
575
|
+
_d.trys.push([2, 4, , 5]);
|
|
576
|
+
return [4 /*yield*/, fn(args)];
|
|
577
|
+
case 3:
|
|
578
|
+
_d.sent();
|
|
579
|
+
return [3 /*break*/, 5];
|
|
580
|
+
case 4:
|
|
581
|
+
err_1 = _d.sent();
|
|
582
|
+
console.error("[LIFECYCLE ERROR] ".concat(this.config.requestMethod, ".").concat(String(phase), ":").concat(key), err_1);
|
|
583
|
+
throw err_1;
|
|
584
|
+
case 5:
|
|
585
|
+
_i++;
|
|
586
|
+
return [3 /*break*/, 1];
|
|
587
|
+
case 6: return [2 /*return*/];
|
|
588
|
+
}
|
|
589
|
+
});
|
|
590
|
+
});
|
|
591
|
+
};
|
|
592
|
+
return Executor;
|
|
593
|
+
}());
|
|
594
|
+
|
|
542
595
|
var isDevelopment = getEnvVar('NODE_ENV', '') === 'development';
|
|
543
596
|
|
|
544
597
|
var isTest = getEnvVar('JEST_WORKER_ID') || getEnvVar('NODE_ENV') === 'test'
|
|
545
598
|
|| getEnvVar('REACT_APP_TEST') === 'true' || getEnvVar('VITE_TEST') === 'true'
|
|
546
599
|
|| getEnvVar('MODE') === 'test' || getEnvVar('VITE_TEST_MODE') === 'true';
|
|
547
600
|
|
|
548
|
-
var envVerbose = getEnvVar('VERBOSE') || getEnvVar('REACT_APP_VERBOSE') || getEnvVar('VITE_VERBOSE') || '';
|
|
549
|
-
var isVerbose = ['true', '1', 'yes', 'on'].includes(envVerbose.toLowerCase());
|
|
550
|
-
|
|
551
601
|
exports.eFetchDependencies = void 0;
|
|
552
602
|
(function (eFetchDependencies) {
|
|
553
603
|
eFetchDependencies[eFetchDependencies["NONE"] = 0] = "NONE";
|
|
@@ -560,23 +610,11 @@ exports.eFetchDependencies = void 0;
|
|
|
560
610
|
eFetchDependencies[eFetchDependencies["RECURSIVE"] = 8] = "RECURSIVE";
|
|
561
611
|
})(exports.eFetchDependencies || (exports.eFetchDependencies = {}));
|
|
562
612
|
|
|
563
|
-
|
|
564
|
-
* the first argument ....
|
|
565
|
-
*
|
|
566
|
-
* Our api returns a zero argument function iff the method is get and the previous request reached the predefined limit.
|
|
567
|
-
* This function can be aliased as GetNextPageOfResults(). If the end is reached undefined will be returned.
|
|
568
|
-
*
|
|
569
|
-
*
|
|
570
|
-
* For POST, PUT, and DELETE requests one can expect the primary key of the new or modified index, or a boolean success
|
|
571
|
-
* indication if no primary key exists.
|
|
572
|
-
**/
|
|
613
|
+
// Refined TypeScript types for CarbonORM
|
|
573
614
|
var POST = 'POST';
|
|
574
615
|
var PUT = 'PUT';
|
|
575
616
|
var GET = 'GET';
|
|
576
617
|
var DELETE = 'DELETE';
|
|
577
|
-
function isPromise(x) {
|
|
578
|
-
return Object(x).constructor === Promise;
|
|
579
|
-
}
|
|
580
618
|
|
|
581
619
|
var toastOptions = {
|
|
582
620
|
position: "bottom-left",
|
|
@@ -688,14 +726,68 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
688
726
|
function HttpExecutor() {
|
|
689
727
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
690
728
|
}
|
|
729
|
+
HttpExecutor.prototype.putState = function (response, request, callback) {
|
|
730
|
+
var _a, _b;
|
|
731
|
+
(_a = this.config.reactBootstrap) === null || _a === void 0 ? void 0 : _a.updateRestfulObjectArrays({
|
|
732
|
+
callback: callback,
|
|
733
|
+
dataOrCallback: [
|
|
734
|
+
removeInvalidKeys(tslib.__assign(tslib.__assign({}, request), (_b = response === null || response === void 0 ? void 0 : response.data) === null || _b === void 0 ? void 0 : _b.rest), this.config.C6.TABLES)
|
|
735
|
+
],
|
|
736
|
+
stateKey: this.config.restModel.TABLE_NAME,
|
|
737
|
+
uniqueObjectId: this.config.restModel.PRIMARY_SHORT
|
|
738
|
+
});
|
|
739
|
+
};
|
|
740
|
+
HttpExecutor.prototype.postState = function (response, request, callback) {
|
|
741
|
+
var _this = this;
|
|
742
|
+
var _a, _b, _c;
|
|
743
|
+
if (1 !== this.config.restModel.PRIMARY_SHORT.length) {
|
|
744
|
+
console.error("C6 received unexpected result's given the primary key length");
|
|
745
|
+
}
|
|
746
|
+
else {
|
|
747
|
+
var pk = this.config.restModel.PRIMARY_SHORT[0];
|
|
748
|
+
// TODO - should overrides be handled differently? Why override: (react/php), driver missmatches, aux data..
|
|
749
|
+
// @ts-ignore - this is technically a correct error, but we allow it anyway...
|
|
750
|
+
request[pk] = (_a = response.data) === null || _a === void 0 ? void 0 : _a.created;
|
|
751
|
+
}
|
|
752
|
+
(_b = this.config.reactBootstrap) === null || _b === void 0 ? void 0 : _b.updateRestfulObjectArrays({
|
|
753
|
+
callback: callback,
|
|
754
|
+
dataOrCallback: undefined !== request.dataInsertMultipleRows
|
|
755
|
+
? request.dataInsertMultipleRows.map(function (request, index) {
|
|
756
|
+
var _a;
|
|
757
|
+
return removeInvalidKeys(tslib.__assign(tslib.__assign({}, request), (index === 0 ? (_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.rest : {})), _this.config.C6.TABLES);
|
|
758
|
+
})
|
|
759
|
+
: [
|
|
760
|
+
removeInvalidKeys(tslib.__assign(tslib.__assign({}, request), (_c = response === null || response === void 0 ? void 0 : response.data) === null || _c === void 0 ? void 0 : _c.rest), this.config.C6.TABLES)
|
|
761
|
+
],
|
|
762
|
+
stateKey: this.config.restModel.TABLE_NAME,
|
|
763
|
+
uniqueObjectId: this.config.restModel.PRIMARY_SHORT
|
|
764
|
+
});
|
|
765
|
+
};
|
|
766
|
+
HttpExecutor.prototype.deleteState = function (_response, request, callback) {
|
|
767
|
+
var _a;
|
|
768
|
+
(_a = this.config.reactBootstrap) === null || _a === void 0 ? void 0 : _a.deleteRestfulObjectArrays({
|
|
769
|
+
callback: callback,
|
|
770
|
+
dataOrCallback: [
|
|
771
|
+
request,
|
|
772
|
+
],
|
|
773
|
+
stateKey: this.config.restModel.TABLE_NAME,
|
|
774
|
+
uniqueObjectId: this.config.restModel.PRIMARY_SHORT
|
|
775
|
+
});
|
|
776
|
+
};
|
|
691
777
|
HttpExecutor.prototype.execute = function () {
|
|
692
778
|
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
693
|
-
var _a, C6, axios, restURL, withCredentials, restModel,
|
|
779
|
+
var _a, C6, axios, restURL, withCredentials, restModel, reactBootstrap, requestMethod, skipPrimaryCheck, clearCache, tableName, fullTableList, operatingTableFullName, operatingTable, tables, query, apiRequest;
|
|
694
780
|
var _this = this;
|
|
695
781
|
return tslib.__generator(this, function (_b) {
|
|
696
782
|
switch (_b.label) {
|
|
697
783
|
case 0:
|
|
698
|
-
_a = this.config, C6 = _a.C6, axios = _a.axios, restURL = _a.restURL, withCredentials = _a.withCredentials, restModel = _a.restModel,
|
|
784
|
+
_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;
|
|
785
|
+
return [4 /*yield*/, this.runLifecycleHooks("beforeProcessing", {
|
|
786
|
+
config: this.config,
|
|
787
|
+
request: this.request,
|
|
788
|
+
})];
|
|
789
|
+
case 1:
|
|
790
|
+
_b.sent();
|
|
699
791
|
tableName = restModel.TABLE_NAME;
|
|
700
792
|
fullTableList = Array.isArray(tableName) ? tableName : [tableName];
|
|
701
793
|
operatingTableFullName = fullTableList[0];
|
|
@@ -716,22 +808,16 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
716
808
|
console.groupCollapsed('%c API: (' + requestMethod + ') Request for (' + tableName + ')', 'color: #0c0');
|
|
717
809
|
console.log('request', this.request);
|
|
718
810
|
console.groupEnd();
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
query = queryCallback;
|
|
724
|
-
}
|
|
725
|
-
if (undefined === query || null === query) {
|
|
726
|
-
if (this.request.debug && isDevelopment) {
|
|
727
|
-
reactToastify.toast.warning("DEV: queryCallback returned undefined, signaling in Custom Cache. (returning null)", toastOptionsDevs);
|
|
728
|
-
}
|
|
729
|
-
console.groupCollapsed('%c API: (' + requestMethod + ') Request Query for (' + tableName + ') undefined, returning null (will not fire ajax)!', 'color: #c00');
|
|
811
|
+
// an undefined query would indicate queryCallback returned undefined,
|
|
812
|
+
// thus the request shouldn't fire as is in custom cache
|
|
813
|
+
if (undefined === this.request || null === this.request) {
|
|
814
|
+
console.groupCollapsed('%c API: (' + requestMethod + ') Request Query for (' + tableName + ') undefined, returning null (will not fire)!', 'color: #c00');
|
|
730
815
|
console.log('%c Returning (undefined|null) for a query would indicate a custom cache hit (outside API.tsx), thus the request should not fire.', 'color: #c00');
|
|
731
816
|
console.trace();
|
|
732
817
|
console.groupEnd();
|
|
733
818
|
return [2 /*return*/, null];
|
|
734
819
|
}
|
|
820
|
+
query = this.request;
|
|
735
821
|
if (C6.GET === requestMethod) {
|
|
736
822
|
if (undefined === query[C6.PAGINATION]) {
|
|
737
823
|
query[C6.PAGINATION] = {};
|
|
@@ -869,51 +955,36 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
869
955
|
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');
|
|
870
956
|
console.trace();
|
|
871
957
|
console.groupEnd();
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
return [
|
|
893
|
-
convertForRequestBody(query, fullTableList, C6, function (message) { return reactToastify.toast.error(message, toastOptions); }),
|
|
894
|
-
{
|
|
895
|
-
withCredentials: withCredentials,
|
|
896
|
-
}
|
|
897
|
-
];
|
|
898
|
-
}
|
|
899
|
-
else if (requestMethod === PUT) {
|
|
900
|
-
return [
|
|
901
|
-
convertForRequestBody(query, fullTableList, C6, function (message) { return reactToastify.toast.error(message, toastOptions); }),
|
|
902
|
-
{
|
|
903
|
-
withCredentials: withCredentials,
|
|
958
|
+
this.runLifecycleHooks("beforeExecution", {
|
|
959
|
+
config: this.config,
|
|
960
|
+
request: this.request
|
|
961
|
+
});
|
|
962
|
+
axiosActiveRequest = (_e = axios)[requestMethod.toLowerCase()].apply(_e, tslib.__spreadArray([restRequestUri], (function () {
|
|
963
|
+
var convert = function (data) {
|
|
964
|
+
return convertForRequestBody(data, fullTableList, C6, function (message) { return reactToastify.toast.error(message, toastOptions); });
|
|
965
|
+
};
|
|
966
|
+
var baseConfig = {
|
|
967
|
+
withCredentials: withCredentials,
|
|
968
|
+
};
|
|
969
|
+
switch (requestMethod) {
|
|
970
|
+
case GET:
|
|
971
|
+
return [tslib.__assign(tslib.__assign({}, baseConfig), { params: query })];
|
|
972
|
+
case POST:
|
|
973
|
+
if (dataInsertMultipleRows !== undefined) {
|
|
974
|
+
return [
|
|
975
|
+
dataInsertMultipleRows.map(convert),
|
|
976
|
+
baseConfig
|
|
977
|
+
];
|
|
904
978
|
}
|
|
905
|
-
|
|
979
|
+
return [convert(query), baseConfig];
|
|
980
|
+
case PUT:
|
|
981
|
+
return [convert(query), baseConfig];
|
|
982
|
+
case DELETE:
|
|
983
|
+
return [tslib.__assign(tslib.__assign({}, baseConfig), { data: convert(query) })];
|
|
984
|
+
default:
|
|
985
|
+
throw new Error("The request method (".concat(requestMethod, ") was not recognized."));
|
|
906
986
|
}
|
|
907
|
-
|
|
908
|
-
return [{
|
|
909
|
-
withCredentials: withCredentials,
|
|
910
|
-
data: convertForRequestBody(query, fullTableList, C6, function (message) { return reactToastify.toast.error(message, toastOptions); })
|
|
911
|
-
}];
|
|
912
|
-
}
|
|
913
|
-
else {
|
|
914
|
-
throw new Error('The request method (' + requestMethod + ') was not recognized.');
|
|
915
|
-
}
|
|
916
|
-
})()), false));
|
|
987
|
+
})(), false));
|
|
917
988
|
if (cachingConfirmed) {
|
|
918
989
|
// push to cache so we do not repeat the request
|
|
919
990
|
exports.apiRequestCache.push({
|
|
@@ -927,12 +998,13 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
927
998
|
// returning the promise with this then is important for tests. todo - we could make that optional.
|
|
928
999
|
// https://rapidapi.com/guides/axios-async-await
|
|
929
1000
|
return [2 /*return*/, axiosActiveRequest.then(function (response) { return tslib.__awaiter(_this, void 0, void 0, function () {
|
|
930
|
-
var cacheIndex, responseData_1, dependencies_1, fetchReferences_1, apiRequestPromises, _loop_1, _a, _b, _c, _i, tableToFetch;
|
|
1001
|
+
var cacheIndex, callback, responseData_1, dependencies_1, fetchReferences_1, apiRequestPromises, _loop_1, _a, _b, _c, _i, tableToFetch;
|
|
931
1002
|
var _this = this;
|
|
932
1003
|
var _d, _e, _f, _g, _h, _j, _k;
|
|
933
1004
|
return tslib.__generator(this, function (_l) {
|
|
934
1005
|
switch (_l.label) {
|
|
935
1006
|
case 0:
|
|
1007
|
+
// noinspection SuspiciousTypeOfGuard
|
|
936
1008
|
if (typeof response.data === 'string') {
|
|
937
1009
|
if (isTest) {
|
|
938
1010
|
console.trace();
|
|
@@ -946,6 +1018,12 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
946
1018
|
// only cache get method requests
|
|
947
1019
|
exports.apiRequestCache[cacheIndex].response = response;
|
|
948
1020
|
}
|
|
1021
|
+
this.runLifecycleHooks("afterExecution", {
|
|
1022
|
+
config: this.config,
|
|
1023
|
+
request: this.request,
|
|
1024
|
+
response: response
|
|
1025
|
+
});
|
|
1026
|
+
// todo - this feels dumb now, but i digress
|
|
949
1027
|
apiResponse = TestRestfulResponse(response, success, error);
|
|
950
1028
|
if (false === apiResponse) {
|
|
951
1029
|
if (debug && isDevelopment) {
|
|
@@ -953,9 +1031,34 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
953
1031
|
}
|
|
954
1032
|
return [2 /*return*/, response];
|
|
955
1033
|
}
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
1034
|
+
callback = function () { return _this.runLifecycleHooks("afterCommit", {
|
|
1035
|
+
config: _this.config,
|
|
1036
|
+
request: _this.request,
|
|
1037
|
+
response: response
|
|
1038
|
+
}); };
|
|
1039
|
+
if (undefined !== reactBootstrap && response) {
|
|
1040
|
+
switch (requestMethod) {
|
|
1041
|
+
case GET:
|
|
1042
|
+
reactBootstrap.updateRestfulObjectArrays({
|
|
1043
|
+
dataOrCallback: Array.isArray(response.data.rest) ? response.data.rest : [response.data.rest],
|
|
1044
|
+
stateKey: this.config.restModel.TABLE_NAME,
|
|
1045
|
+
uniqueObjectId: this.config.restModel.PRIMARY_SHORT,
|
|
1046
|
+
callback: callback
|
|
1047
|
+
});
|
|
1048
|
+
break;
|
|
1049
|
+
case POST:
|
|
1050
|
+
this.postState(response, this.request, callback);
|
|
1051
|
+
break;
|
|
1052
|
+
case PUT:
|
|
1053
|
+
this.putState(response, this.request, callback);
|
|
1054
|
+
break;
|
|
1055
|
+
case DELETE:
|
|
1056
|
+
this.deleteState(response, this.request, callback);
|
|
1057
|
+
break;
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
else {
|
|
1061
|
+
callback();
|
|
959
1062
|
}
|
|
960
1063
|
if (!(C6.GET === requestMethod)) return [3 /*break*/, 6];
|
|
961
1064
|
responseData_1 = response.data;
|
|
@@ -1181,7 +1284,7 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1181
1284
|
});
|
|
1182
1285
|
}); };
|
|
1183
1286
|
return [4 /*yield*/, apiRequest()];
|
|
1184
|
-
case
|
|
1287
|
+
case 2: return [2 /*return*/, _b.sent()];
|
|
1185
1288
|
}
|
|
1186
1289
|
});
|
|
1187
1290
|
});
|
|
@@ -1474,13 +1577,13 @@ exports.group = group;
|
|
|
1474
1577
|
exports.info = info;
|
|
1475
1578
|
exports.isLocal = isDevelopment;
|
|
1476
1579
|
exports.isNode = isNode;
|
|
1477
|
-
exports.isPromise = isPromise;
|
|
1478
1580
|
exports.isTest = isTest;
|
|
1479
1581
|
exports.isVerbose = isVerbose;
|
|
1480
1582
|
exports.onError = onError;
|
|
1481
1583
|
exports.onSuccess = onSuccess;
|
|
1482
1584
|
exports.removeInvalidKeys = removeInvalidKeys;
|
|
1483
1585
|
exports.removePrefixIfExists = removePrefixIfExists;
|
|
1586
|
+
exports.restOrm = restOrm;
|
|
1484
1587
|
exports.restRequest = restRequest;
|
|
1485
1588
|
exports.sortAndSerializeQueryObject = sortAndSerializeQueryObject;
|
|
1486
1589
|
exports.timeout = timeout;
|