@carbonorm/carbonnode 3.1.3 → 3.2.1
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 +38 -41
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +38 -41
- 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
- package/src/api/utils/cacheManager.ts +7 -28
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// Refined TypeScript types for CarbonORM
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
3
|
+
import {AxiosInstance, AxiosPromise, AxiosResponse} from "axios";
|
|
4
|
+
import {Pool} from "mysql2/promise";
|
|
5
|
+
import {eFetchDependencies} from "./dynamicFetching";
|
|
6
|
+
import {Modify} from "./modifyTypes";
|
|
7
|
+
import {JoinType, OrderDirection, SQLComparisonOperator, SQLFunction} from "./mysqlTypes";
|
|
8
|
+
import {CarbonReact} from "@carbonorm/carbonreact";
|
|
9
9
|
import {OrmGenerics} from "./ormGenerics";
|
|
10
10
|
|
|
11
11
|
export type iRestMethods = 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
@@ -14,10 +14,21 @@ export const PUT = 'PUT';
|
|
|
14
14
|
export const GET = 'GET';
|
|
15
15
|
export const DELETE = 'DELETE';
|
|
16
16
|
|
|
17
|
-
export interface stringMap {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
export interface stringMap {
|
|
18
|
+
[key: string]: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface stringNumberMap {
|
|
22
|
+
[key: string]: string | number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface RegExpMap {
|
|
26
|
+
[key: string]: RegExp | RegExpMap;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface complexMap {
|
|
30
|
+
[key: string]: stringMap | stringNumberMap | stringMap[] | RegExpMap;
|
|
31
|
+
}
|
|
21
32
|
|
|
22
33
|
export interface iTypeValidation {
|
|
23
34
|
MYSQL_TYPE: string;
|
|
@@ -66,7 +77,7 @@ export type RequestGetPutDeleteBody<T extends { [key: string]: any } = any> = {
|
|
|
66
77
|
export type iAPI<T extends { [key: string]: any }> = T & {
|
|
67
78
|
dataInsertMultipleRows?: T[];
|
|
68
79
|
cacheResults?: boolean;
|
|
69
|
-
fetchDependencies?: number | eFetchDependencies | Awaited<
|
|
80
|
+
fetchDependencies?: number | eFetchDependencies | Awaited<iGetC6RestResponse<any>>[];
|
|
70
81
|
debug?: boolean;
|
|
71
82
|
success?: string | ((r: AxiosResponse) => string | void);
|
|
72
83
|
error?: string | ((r: AxiosResponse) => string | void);
|
|
@@ -88,7 +99,9 @@ export interface iCacheAPI<ResponseDataType = any> {
|
|
|
88
99
|
final?: boolean;
|
|
89
100
|
}
|
|
90
101
|
|
|
91
|
-
export interface iChangeC6Data {
|
|
102
|
+
export interface iChangeC6Data {
|
|
103
|
+
rowCount: number;
|
|
104
|
+
}
|
|
92
105
|
|
|
93
106
|
export interface iDeleteC6RestResponse<RestData = any, RequestData = any> extends iChangeC6Data, iC6RestResponse<RestData> {
|
|
94
107
|
deleted: boolean | number | string | RequestData;
|
|
@@ -108,28 +121,31 @@ export interface iC6RestResponse<RestData> {
|
|
|
108
121
|
sql?: any;
|
|
109
122
|
}
|
|
110
123
|
|
|
111
|
-
export
|
|
124
|
+
export interface iGetC6RestResponse<
|
|
125
|
+
ResponseDataType extends { [key: string]: any },
|
|
126
|
+
ResponseDataOverrides = {}
|
|
127
|
+
> extends iC6RestResponse<
|
|
112
128
|
Modify<ResponseDataType, ResponseDataOverrides> | Modify<ResponseDataType, ResponseDataOverrides>[]
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
| null
|
|
117
|
-
| undefined
|
|
118
|
-
| Response
|
|
119
|
-
| (Response extends iPutC6RestResponse | iDeleteC6RestResponse | iPostC6RestResponse ? null : () => apiReturn<Response>);
|
|
129
|
+
> {
|
|
130
|
+
next?: () => Promise<DetermineResponseDataType<"GET", ResponseDataType, ResponseDataOverrides>>;
|
|
131
|
+
}
|
|
120
132
|
|
|
121
133
|
export type DetermineResponseDataType<
|
|
122
134
|
Method extends iRestMethods,
|
|
123
|
-
RestTableInterface extends { [key: string]: any }
|
|
124
|
-
|
|
135
|
+
RestTableInterface extends { [key: string]: any },
|
|
136
|
+
ResponseDataOverrides = {}
|
|
137
|
+
> =
|
|
138
|
+
null
|
|
139
|
+
| undefined
|
|
140
|
+
| (Method extends 'POST'
|
|
125
141
|
? iPostC6RestResponse<RestTableInterface>
|
|
126
142
|
: Method extends 'GET'
|
|
127
|
-
? iGetC6RestResponse<RestTableInterface>
|
|
143
|
+
? iGetC6RestResponse<RestTableInterface, ResponseDataOverrides>
|
|
128
144
|
: Method extends 'PUT'
|
|
129
145
|
? iPutC6RestResponse<RestTableInterface>
|
|
130
146
|
: Method extends 'DELETE'
|
|
131
147
|
? iDeleteC6RestResponse<RestTableInterface>
|
|
132
|
-
: never;
|
|
148
|
+
: never);
|
|
133
149
|
|
|
134
150
|
export interface iRest<
|
|
135
151
|
RestShortTableName extends string = any,
|
|
@@ -217,10 +233,10 @@ export interface iDynamicApiImport<RestData extends { [key: string]: any } = any
|
|
|
217
233
|
}
|
|
218
234
|
|
|
219
235
|
export interface iRestApiFunctions<RestData extends { [key: string]: any } = any> {
|
|
220
|
-
Delete: (request?: RequestQueryBody<'DELETE', RestData>) =>
|
|
221
|
-
Post: (request?: RequestQueryBody<'POST', RestData>) =>
|
|
222
|
-
Get: (request?: RequestQueryBody<'GET', RestData>) =>
|
|
223
|
-
Put: (request?: RequestQueryBody<'PUT', RestData>) =>
|
|
236
|
+
Delete: (request?: RequestQueryBody<'DELETE', RestData>) => iDeleteC6RestResponse<RestData>;
|
|
237
|
+
Post: (request?: RequestQueryBody<'POST', RestData>) => iPostC6RestResponse<RestData>;
|
|
238
|
+
Get: (request?: RequestQueryBody<'GET', RestData>) => iGetC6RestResponse<RestData>;
|
|
239
|
+
Put: (request?: RequestQueryBody<'PUT', RestData>) => iPutC6RestResponse<RestData>;
|
|
224
240
|
}
|
|
225
241
|
|
|
226
242
|
export interface iC6Object<
|
|
@@ -236,6 +252,7 @@ export interface iC6Object<
|
|
|
236
252
|
};
|
|
237
253
|
PREFIX: string;
|
|
238
254
|
IMPORT: (tableName: string) => Promise<iDynamicApiImport>;
|
|
255
|
+
|
|
239
256
|
[key: string]: any;
|
|
240
257
|
}
|
|
241
258
|
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import {AxiosPromise} from "axios";
|
|
2
|
-
import isTest from "../../variables/isTest";
|
|
3
|
-
import isVerbose from "../../variables/isVerbose";
|
|
4
2
|
import { iCacheAPI } from "api/types/ormInterfaces";
|
|
5
3
|
|
|
6
4
|
// do not remove entries from this array. It is used to track the progress of API requests.
|
|
@@ -29,39 +27,20 @@ export function clearCache(props?: iClearCache) {
|
|
|
29
27
|
|
|
30
28
|
export function checkCache<ResponseDataType = any, RestShortTableNames = string>(cacheResult: iCacheAPI<ResponseDataType>, requestMethod: string, tableName: RestShortTableNames | RestShortTableNames[], request: any): false | undefined | null | AxiosPromise<ResponseDataType> {
|
|
31
29
|
|
|
32
|
-
if (undefined === cacheResult
|
|
30
|
+
if (undefined === cacheResult) {
|
|
33
31
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
console.log('%c ' + requestMethod + ' ' + tableName, 'color: #0c0')
|
|
37
|
-
|
|
38
|
-
console.log('%c Request Data (note you may see the success and/or error prompt):', 'color: #0c0', request)
|
|
39
|
-
|
|
40
|
-
console.groupEnd()
|
|
41
|
-
|
|
42
|
-
return cacheResult.request;
|
|
32
|
+
return false;
|
|
43
33
|
|
|
44
34
|
}
|
|
45
35
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if (false === isTest() || true === isVerbose()) {
|
|
36
|
+
console.groupCollapsed('%c API: The request on (' + tableName + ') is in cache. Returning the request Promise!', 'color: #0c0')
|
|
49
37
|
|
|
50
|
-
|
|
38
|
+
console.log('%c ' + requestMethod + ' ' + tableName, 'color: #0c0')
|
|
51
39
|
|
|
52
|
-
|
|
40
|
+
console.log('%c Request Data (note you may see the success and/or error prompt):', 'color: #0c0', request)
|
|
53
41
|
|
|
54
|
-
|
|
42
|
+
console.groupEnd()
|
|
55
43
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
console.groupEnd()
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return undefined;
|
|
63
|
-
|
|
64
|
-
}
|
|
44
|
+
return cacheResult.request;
|
|
65
45
|
|
|
66
|
-
return false;
|
|
67
46
|
}
|