@carbonorm/carbonnode 3.1.3 → 3.2.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/Executor.d.ts +2 -2
- package/dist/api/executors/HttpExecutor.d.ts +2 -2
- package/dist/api/executors/SqlExecutor.d.ts +2 -2
- package/dist/api/orm/builders/ConditionBuilder.d.ts +2 -2
- package/dist/api/restOrm.d.ts +1 -1
- package/dist/api/restRequest.d.ts +2 -2
- package/dist/api/types/ormInterfaces.d.ts +11 -8
- package/dist/index.cjs.js +31 -23
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +31 -23
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/api/executors/Executor.ts +1 -2
- package/src/api/executors/HttpExecutor.ts +21 -15
- package/src/api/executors/SqlExecutor.ts +5 -6
- package/src/api/orm/builders/ConditionBuilder.ts +2 -2
- package/src/api/restRequest.ts +2 -2
- package/src/api/types/ormInterfaces.ts +45 -28
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { OrmGenerics } from "../types/ormGenerics";
|
|
2
|
-
import {
|
|
2
|
+
import { DetermineResponseDataType, iRest, iRestReactiveLifecycle, RequestQueryBody } from "../types/ormInterfaces";
|
|
3
3
|
export declare abstract class Executor<G extends OrmGenerics> {
|
|
4
4
|
protected config: iRest<G['RestShortTableName'], G['RestTableInterface'], G['PrimaryKey']>;
|
|
5
5
|
protected request: RequestQueryBody<G['RequestMethod'], G['RestTableInterface'], G['CustomAndRequiredFields'], G['RequestTableOverrides']>;
|
|
6
6
|
protected useNamedParams: boolean;
|
|
7
7
|
constructor(config: iRest<G['RestShortTableName'], G['RestTableInterface'], G['PrimaryKey']>, request: RequestQueryBody<G['RequestMethod'], G['RestTableInterface'], G['CustomAndRequiredFields'], G['RequestTableOverrides']>, useNamedParams?: boolean);
|
|
8
|
-
abstract execute(): Promise<
|
|
8
|
+
abstract execute(): Promise<DetermineResponseDataType<G['RequestMethod'], G['RestTableInterface']>>;
|
|
9
9
|
runLifecycleHooks<Phase extends keyof iRestReactiveLifecycle<G>>(phase: Phase, args: Parameters<NonNullable<iRestReactiveLifecycle<G>[Phase]>[string]>[0]): Promise<void>;
|
|
10
10
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { AxiosResponse } from "axios";
|
|
2
2
|
import { OrmGenerics } from "../types/ormGenerics";
|
|
3
|
-
import {
|
|
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
6
|
putState(response: AxiosResponse<DetermineResponseDataType<G['RequestMethod'], G['RestTableInterface']>>, request: RequestQueryBody<G['RequestMethod'], G['RestTableInterface'], G['CustomAndRequiredFields'], G['RequestTableOverrides']>, callback: () => void): void;
|
|
7
7
|
postState(response: AxiosResponse<DetermineResponseDataType<G['RequestMethod'], G['RestTableInterface']>>, request: RequestQueryBody<G['RequestMethod'], G['RestTableInterface'], G['CustomAndRequiredFields'], G['RequestTableOverrides']>, callback: () => void): void;
|
|
8
8
|
deleteState(_response: AxiosResponse<DetermineResponseDataType<G['RequestMethod'], G['RestTableInterface']>>, request: RequestQueryBody<G['RequestMethod'], G['RestTableInterface'], G['CustomAndRequiredFields'], G['RequestTableOverrides']>, callback: () => void): void;
|
|
9
|
-
execute(): Promise<
|
|
9
|
+
execute(): Promise<DetermineResponseDataType<G['RequestMethod'], G['RestTableInterface']>>;
|
|
10
10
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { OrmGenerics } from "../types/ormGenerics";
|
|
2
|
-
import {
|
|
2
|
+
import { DetermineResponseDataType } from "../types/ormInterfaces";
|
|
3
3
|
import { ResultSetHeader } from 'mysql2/promise';
|
|
4
4
|
import { Executor } from "./Executor";
|
|
5
5
|
export declare class SqlExecutor<G extends OrmGenerics> extends Executor<G> {
|
|
6
|
-
execute(): Promise<
|
|
6
|
+
execute(): Promise<DetermineResponseDataType<G['RequestMethod'], G['RestTableInterface']>>;
|
|
7
7
|
private withConnection;
|
|
8
8
|
serialize: (row: any) => {
|
|
9
9
|
[k: string]: unknown;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { OrmGenerics } from "../../types/ormGenerics";
|
|
2
|
-
import {
|
|
2
|
+
import { DetermineResponseDataType } from "../../types/ormInterfaces";
|
|
3
3
|
import { AggregateBuilder } from "./AggregateBuilder";
|
|
4
4
|
export declare class ConditionBuilder<G extends OrmGenerics> extends AggregateBuilder<G> {
|
|
5
|
-
execute(): Promise<
|
|
5
|
+
execute(): Promise<DetermineResponseDataType<G['RequestMethod'], G['RestTableInterface']>>;
|
|
6
6
|
private readonly OPERATORS;
|
|
7
7
|
private validateOperator;
|
|
8
8
|
private addParam;
|
package/dist/api/restOrm.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { OrmGenerics } from "./types/ormGenerics";
|
|
2
2
|
import { iRest } from "./types/ormInterfaces";
|
|
3
3
|
export declare function restOrm<G extends Omit<OrmGenerics, "requestMethod">>(config: () => Omit<iRest<G['RestShortTableName'], G['RestTableInterface'], G['PrimaryKey']>, "requestMethod">): {
|
|
4
|
-
[k: string]: (request: import("./types/ormInterfaces").RequestQueryBody<G["RequestMethod"], G["RestTableInterface"], G["CustomAndRequiredFields"], G["RequestTableOverrides"]>) => Promise<import("./types/ormInterfaces").
|
|
4
|
+
[k: string]: (request: import("./types/ormInterfaces").RequestQueryBody<G["RequestMethod"], G["RestTableInterface"], G["CustomAndRequiredFields"], G["RequestTableOverrides"]>) => Promise<import("./types/ormInterfaces").DetermineResponseDataType<G["RequestMethod"], G["RestTableInterface"]>>;
|
|
5
5
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { OrmGenerics } from "./types/ormGenerics";
|
|
2
|
-
import {
|
|
2
|
+
import { DetermineResponseDataType, iRest, RequestQueryBody } from "./types/ormInterfaces";
|
|
3
3
|
/**
|
|
4
4
|
* Facade: routes API calls to SQL or HTTP executors based on runtime context.
|
|
5
5
|
*/
|
|
6
|
-
export default function restRequest<G extends OrmGenerics>(configX: (() => iRest<G['RestTableInterface'], G['RestShortTableName'], G['PrimaryKey']>) | iRest<G['RestShortTableName'], G['RestTableInterface'], G['PrimaryKey']>): (request: RequestQueryBody<G["RequestMethod"], G["RestTableInterface"], G["CustomAndRequiredFields"], G["RequestTableOverrides"]>) => Promise<
|
|
6
|
+
export default function restRequest<G extends OrmGenerics>(configX: (() => iRest<G['RestTableInterface'], G['RestShortTableName'], G['PrimaryKey']>) | iRest<G['RestShortTableName'], G['RestTableInterface'], G['PrimaryKey']>): (request: RequestQueryBody<G["RequestMethod"], G["RestTableInterface"], G["CustomAndRequiredFields"], G["RequestTableOverrides"]>) => Promise<DetermineResponseDataType<G["RequestMethod"], G["RestTableInterface"]>>;
|
|
@@ -71,7 +71,7 @@ export type iAPI<T extends {
|
|
|
71
71
|
}> = T & {
|
|
72
72
|
dataInsertMultipleRows?: T[];
|
|
73
73
|
cacheResults?: boolean;
|
|
74
|
-
fetchDependencies?: number | eFetchDependencies | Awaited<
|
|
74
|
+
fetchDependencies?: number | eFetchDependencies | Awaited<iGetC6RestResponse<any>>[];
|
|
75
75
|
debug?: boolean;
|
|
76
76
|
success?: string | ((r: AxiosResponse) => string | void);
|
|
77
77
|
error?: string | ((r: AxiosResponse) => string | void);
|
|
@@ -106,11 +106,14 @@ export interface iC6RestResponse<RestData> {
|
|
|
106
106
|
session?: any;
|
|
107
107
|
sql?: any;
|
|
108
108
|
}
|
|
109
|
-
export
|
|
110
|
-
|
|
109
|
+
export interface iGetC6RestResponse<ResponseDataType extends {
|
|
110
|
+
[key: string]: any;
|
|
111
|
+
}, ResponseDataOverrides = {}> extends iC6RestResponse<Modify<ResponseDataType, ResponseDataOverrides> | Modify<ResponseDataType, ResponseDataOverrides>[]> {
|
|
112
|
+
next?: () => Promise<DetermineResponseDataType<"GET", ResponseDataType, ResponseDataOverrides>>;
|
|
113
|
+
}
|
|
111
114
|
export type DetermineResponseDataType<Method extends iRestMethods, RestTableInterface extends {
|
|
112
115
|
[key: string]: any;
|
|
113
|
-
}> = Method extends 'POST' ? iPostC6RestResponse<RestTableInterface> : Method extends 'GET' ? iGetC6RestResponse<RestTableInterface> : Method extends 'PUT' ? iPutC6RestResponse<RestTableInterface> : Method extends 'DELETE' ? iDeleteC6RestResponse<RestTableInterface> : never;
|
|
116
|
+
}, ResponseDataOverrides = {}> = null | undefined | (Method extends 'POST' ? iPostC6RestResponse<RestTableInterface> : Method extends 'GET' ? iGetC6RestResponse<RestTableInterface, ResponseDataOverrides> : Method extends 'PUT' ? iPutC6RestResponse<RestTableInterface> : Method extends 'DELETE' ? iDeleteC6RestResponse<RestTableInterface> : never);
|
|
114
117
|
export interface iRest<RestShortTableName extends string = any, RestTableInterface extends Record<string, any> = any, PrimaryKey extends keyof RestTableInterface & string = keyof RestTableInterface & string> {
|
|
115
118
|
C6: iC6Object;
|
|
116
119
|
axios?: AxiosInstance;
|
|
@@ -193,10 +196,10 @@ export interface iDynamicApiImport<RestData extends {
|
|
|
193
196
|
export interface iRestApiFunctions<RestData extends {
|
|
194
197
|
[key: string]: any;
|
|
195
198
|
} = any> {
|
|
196
|
-
Delete: (request?: RequestQueryBody<'DELETE', RestData>) =>
|
|
197
|
-
Post: (request?: RequestQueryBody<'POST', RestData>) =>
|
|
198
|
-
Get: (request?: RequestQueryBody<'GET', RestData>) =>
|
|
199
|
-
Put: (request?: RequestQueryBody<'PUT', RestData>) =>
|
|
199
|
+
Delete: (request?: RequestQueryBody<'DELETE', RestData>) => iDeleteC6RestResponse<RestData>;
|
|
200
|
+
Post: (request?: RequestQueryBody<'POST', RestData>) => iPostC6RestResponse<RestData>;
|
|
201
|
+
Get: (request?: RequestQueryBody<'GET', RestData>) => iGetC6RestResponse<RestData>;
|
|
202
|
+
Put: (request?: RequestQueryBody<'PUT', RestData>) => iPutC6RestResponse<RestData>;
|
|
200
203
|
}
|
|
201
204
|
export interface iC6Object<RestShortTableName extends string = any, RestTableInterface extends {
|
|
202
205
|
[key: string]: any;
|
package/dist/index.cjs.js
CHANGED
|
@@ -899,9 +899,9 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
899
899
|
return [2 /*return*/, axiosActiveRequest.then(function (response) { return tslib.__awaiter(_this, void 0, void 0, function () {
|
|
900
900
|
var cacheIndex, callback, responseData_1, dependencies_1, fetchReferences_1, apiRequestPromises, _loop_1, _a, _b, _c, _i, tableToFetch;
|
|
901
901
|
var _this = this;
|
|
902
|
-
var _d, _e, _f, _g, _h, _j
|
|
903
|
-
return tslib.__generator(this, function (
|
|
904
|
-
switch (
|
|
902
|
+
var _d, _e, _f, _g, _h, _j;
|
|
903
|
+
return tslib.__generator(this, function (_k) {
|
|
904
|
+
switch (_k.label) {
|
|
905
905
|
case 0:
|
|
906
906
|
// noinspection SuspiciousTypeOfGuard
|
|
907
907
|
if (typeof response.data === 'string') {
|
|
@@ -913,6 +913,7 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
913
913
|
}
|
|
914
914
|
if (cachingConfirmed) {
|
|
915
915
|
cacheIndex = exports.apiRequestCache.findIndex(function (cache) { return cache.requestArgumentsSerialized === querySerialized; });
|
|
916
|
+
// TODO - currently nonthing is setting this correctly
|
|
916
917
|
exports.apiRequestCache[cacheIndex].final = false === returnGetNextPageFunction;
|
|
917
918
|
// only cache get method requests
|
|
918
919
|
exports.apiRequestCache[cacheIndex].response = response;
|
|
@@ -938,7 +939,7 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
938
939
|
if (undefined !== reactBootstrap && response) {
|
|
939
940
|
switch (requestMethod) {
|
|
940
941
|
case GET:
|
|
941
|
-
reactBootstrap.updateRestfulObjectArrays({
|
|
942
|
+
response.data && reactBootstrap.updateRestfulObjectArrays({
|
|
942
943
|
dataOrCallback: Array.isArray(response.data.rest) ? response.data.rest : [response.data.rest],
|
|
943
944
|
stateKey: this.config.restModel.TABLE_NAME,
|
|
944
945
|
uniqueObjectId: this.config.restModel.PRIMARY_SHORT,
|
|
@@ -968,14 +969,19 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
968
969
|
console.log('%c ' + requestMethod + ' ' + tableName, 'color: #0c0');
|
|
969
970
|
console.log('%c Request Data (note you may see the success and/or error prompt):', 'color: #0c0', this.request);
|
|
970
971
|
console.log('%c Response Data:', 'color: #0c0', responseData_1.rest);
|
|
971
|
-
console.log('%c Will return get next page function:' + (
|
|
972
|
+
console.log('%c Will return get next page function:' + (returnGetNextPageFunction ? '' : ' (Will not return with explicit limit 1 set)'), 'color: #0c0', true === returnGetNextPageFunction);
|
|
972
973
|
console.trace();
|
|
973
974
|
console.groupEnd();
|
|
974
975
|
}
|
|
975
|
-
if (false === returnGetNextPageFunction
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
976
|
+
if (false === returnGetNextPageFunction) {
|
|
977
|
+
responseData_1.next = apiRequest;
|
|
978
|
+
}
|
|
979
|
+
else {
|
|
980
|
+
responseData_1.next = undefined;
|
|
981
|
+
if (true === debug
|
|
982
|
+
&& isLocal()) {
|
|
983
|
+
reactToastify.toast.success("DEVS: Response returned length (" + ((_h = responseData_1.rest) === null || _h === void 0 ? void 0 : _h.length) + ") less than limit (" + ((_j = query === null || query === void 0 ? void 0 : query[C6.PAGINATION]) === null || _j === void 0 ? void 0 : _j[C6.LIMIT]) + ").", toastOptionsDevs);
|
|
984
|
+
}
|
|
979
985
|
}
|
|
980
986
|
if (!(fetchDependencies
|
|
981
987
|
&& 'number' === typeof fetchDependencies
|
|
@@ -989,6 +995,7 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
989
995
|
console.trace(); // hidden in collapsed group
|
|
990
996
|
console.groupEnd();
|
|
991
997
|
dependencies_1 = {};
|
|
998
|
+
// Remember this is a binary bitwise operation, so we can check for multiple dependencies at once
|
|
992
999
|
if (fetchDependencies & exports.eFetchDependencies.C6ENTITY) {
|
|
993
1000
|
dependencies_1 = operatingTable.endsWith("carbon_carbons")
|
|
994
1001
|
? tslib.__assign(tslib.__assign({}, fetchDependencies & exports.eFetchDependencies.CHILDREN // REFERENCED === CHILDREN
|
|
@@ -1050,9 +1057,9 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1050
1057
|
console.log('fetchReferences', fetchReferences_1);
|
|
1051
1058
|
_loop_1 = function (tableToFetch) {
|
|
1052
1059
|
var referencesTables, shouldContinue, fetchTable, RestApi, nextFetchDependencies;
|
|
1053
|
-
var
|
|
1054
|
-
return tslib.__generator(this, function (
|
|
1055
|
-
switch (
|
|
1060
|
+
var _l;
|
|
1061
|
+
return tslib.__generator(this, function (_m) {
|
|
1062
|
+
switch (_m.label) {
|
|
1056
1063
|
case 0:
|
|
1057
1064
|
if (fetchDependencies & exports.eFetchDependencies.C6ENTITY
|
|
1058
1065
|
&& 'string' === typeof tableName
|
|
@@ -1072,7 +1079,7 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1072
1079
|
}
|
|
1073
1080
|
return [4 /*yield*/, C6.IMPORT(tableToFetch)];
|
|
1074
1081
|
case 1:
|
|
1075
|
-
fetchTable =
|
|
1082
|
+
fetchTable = _m.sent();
|
|
1076
1083
|
RestApi = fetchTable.default;
|
|
1077
1084
|
console.log('%c Fetch Dependencies will select (' + tableToFetch + ') using GET request', 'color: #33ccff');
|
|
1078
1085
|
nextFetchDependencies = exports.eFetchDependencies.NONE;
|
|
@@ -1095,8 +1102,8 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1095
1102
|
// it not certain that they are using carbons' entities either
|
|
1096
1103
|
// this is a dynamic call to the rest api, any generated table may resolve with (RestApi)
|
|
1097
1104
|
// todo - using value to avoid joins.... but. maybe this should be a parameterizable option -- think race conditions; its safer to join
|
|
1098
|
-
apiRequestPromises.push(RestApi.Get((
|
|
1099
|
-
|
|
1105
|
+
apiRequestPromises.push(RestApi.Get((_l = {},
|
|
1106
|
+
_l[C6.WHERE] = {
|
|
1100
1107
|
0: Object.keys(fetchReferences_1[tableToFetch]).reduce(function (sum, column) {
|
|
1101
1108
|
fetchReferences_1[tableToFetch][column] = fetchReferences_1[tableToFetch][column].flat(Infinity);
|
|
1102
1109
|
if (0 === fetchReferences_1[tableToFetch][column].length) {
|
|
@@ -1111,8 +1118,8 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1111
1118
|
return sum;
|
|
1112
1119
|
}, {})
|
|
1113
1120
|
},
|
|
1114
|
-
|
|
1115
|
-
|
|
1121
|
+
_l.fetchDependencies = nextFetchDependencies,
|
|
1122
|
+
_l)));
|
|
1116
1123
|
return [2 /*return*/];
|
|
1117
1124
|
}
|
|
1118
1125
|
});
|
|
@@ -1122,7 +1129,7 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1122
1129
|
for (_c in _a)
|
|
1123
1130
|
_b.push(_c);
|
|
1124
1131
|
_i = 0;
|
|
1125
|
-
|
|
1132
|
+
_k.label = 1;
|
|
1126
1133
|
case 1:
|
|
1127
1134
|
if (!(_i < _b.length)) return [3 /*break*/, 4];
|
|
1128
1135
|
_c = _b[_i];
|
|
@@ -1130,8 +1137,8 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1130
1137
|
tableToFetch = _c;
|
|
1131
1138
|
return [5 /*yield**/, _loop_1(tableToFetch)];
|
|
1132
1139
|
case 2:
|
|
1133
|
-
|
|
1134
|
-
|
|
1140
|
+
_k.sent();
|
|
1141
|
+
_k.label = 3;
|
|
1135
1142
|
case 3:
|
|
1136
1143
|
_i++;
|
|
1137
1144
|
return [3 /*break*/, 1];
|
|
@@ -1139,7 +1146,7 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1139
1146
|
console.groupEnd();
|
|
1140
1147
|
return [4 /*yield*/, Promise.all(apiRequestPromises)];
|
|
1141
1148
|
case 5:
|
|
1142
|
-
|
|
1149
|
+
_k.sent();
|
|
1143
1150
|
apiRequestPromises.map(function (promise) { return tslib.__awaiter(_this, void 0, void 0, function () {
|
|
1144
1151
|
var _a, _b;
|
|
1145
1152
|
return tslib.__generator(this, function (_c) {
|
|
@@ -1157,15 +1164,16 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1157
1164
|
}
|
|
1158
1165
|
});
|
|
1159
1166
|
}); });
|
|
1160
|
-
|
|
1167
|
+
_k.label = 6;
|
|
1161
1168
|
case 6:
|
|
1162
1169
|
if (debug && isLocal()) {
|
|
1163
1170
|
reactToastify.toast.success("DEVS: (" + requestMethod + ") request complete.", toastOptionsDevs);
|
|
1164
1171
|
}
|
|
1172
|
+
// this is the literal axios return
|
|
1165
1173
|
return [2 /*return*/, response];
|
|
1166
1174
|
}
|
|
1167
1175
|
});
|
|
1168
|
-
}); }).then(function (response) { return response.data; })];
|
|
1176
|
+
}); }).then(function (response) { return response.data; })]; // this escapes from axios context
|
|
1169
1177
|
}
|
|
1170
1178
|
catch (throwableError) {
|
|
1171
1179
|
if (isTest()) {
|