@carbonorm/carbonnode 3.0.3 → 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 +3 -4
- package/dist/api/executors/HttpExecutor.d.ts +4 -5
- package/dist/api/restOrm.d.ts +4 -32
- package/dist/api/restRequest.d.ts +2 -3
- package/dist/api/types/ormInterfaces.d.ts +161 -161
- package/dist/index.cjs.js +548 -97
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +550 -98
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/scripts/assets/handlebars/C6.ts.handlebars +30 -23
- package/scripts/generateRestBindings.cjs +1 -0
- package/scripts/generateRestBindings.ts +1 -0
- package/src/api/convertForRequestBody.ts +62 -90
- package/src/api/executors/Executor.ts +8 -4
- package/src/api/executors/HttpExecutor.ts +80 -69
- package/src/api/restRequest.ts +7 -4
- package/src/api/types/ormInterfaces.ts +200 -321
- package/src/api/rest/C6.test.ts +0 -88
- package/src/api/rest/C6.ts +0 -5338
|
@@ -5,18 +5,16 @@ import isTest from "../../variables/isTest";
|
|
|
5
5
|
import isVerbose from "../../variables/isVerbose";
|
|
6
6
|
import convertForRequestBody from "../convertForRequestBody";
|
|
7
7
|
import {eFetchDependencies} from "../types/dynamicFetching";
|
|
8
|
-
import {Modify} from "../types/modifyTypes";
|
|
9
8
|
import {
|
|
10
9
|
apiReturn,
|
|
11
10
|
DELETE, DetermineResponseDataType,
|
|
12
|
-
GET,
|
|
11
|
+
GET,
|
|
13
12
|
iCacheAPI,
|
|
14
13
|
iConstraint,
|
|
15
14
|
iGetC6RestResponse,
|
|
16
15
|
iRestMethods,
|
|
17
16
|
POST,
|
|
18
|
-
PUT,
|
|
19
|
-
RequestQueryBody
|
|
17
|
+
PUT, RequestQueryBody
|
|
20
18
|
} from "../types/ormInterfaces";
|
|
21
19
|
import {removeInvalidKeys, removePrefixIfExists, TestRestfulResponse} from "../utils/apiHelpers";
|
|
22
20
|
import {apiRequestCache, checkCache, userCustomClearCache} from "../utils/cacheManager";
|
|
@@ -43,7 +41,12 @@ export class HttpExecutor<
|
|
|
43
41
|
|
|
44
42
|
public putState(
|
|
45
43
|
response: AxiosResponse<DetermineResponseDataType<RequestMethod, RestTableInterface>>,
|
|
46
|
-
request:
|
|
44
|
+
request: RequestQueryBody<
|
|
45
|
+
RequestMethod,
|
|
46
|
+
RestTableInterface,
|
|
47
|
+
CustomAndRequiredFields,
|
|
48
|
+
RequestTableOverrides
|
|
49
|
+
>,
|
|
47
50
|
callback: () => void
|
|
48
51
|
) {
|
|
49
52
|
this.config.reactBootstrap?.updateRestfulObjectArrays<RestTableInterface>({
|
|
@@ -61,7 +64,12 @@ export class HttpExecutor<
|
|
|
61
64
|
|
|
62
65
|
public postState(
|
|
63
66
|
response: AxiosResponse<DetermineResponseDataType<RequestMethod, RestTableInterface>>,
|
|
64
|
-
request:
|
|
67
|
+
request: RequestQueryBody<
|
|
68
|
+
RequestMethod,
|
|
69
|
+
RestTableInterface,
|
|
70
|
+
CustomAndRequiredFields,
|
|
71
|
+
RequestTableOverrides
|
|
72
|
+
>,
|
|
65
73
|
callback: () => void
|
|
66
74
|
) {
|
|
67
75
|
|
|
@@ -101,7 +109,12 @@ export class HttpExecutor<
|
|
|
101
109
|
|
|
102
110
|
public deleteState(
|
|
103
111
|
_response: AxiosResponse<DetermineResponseDataType<RequestMethod, RestTableInterface>>,
|
|
104
|
-
request:
|
|
112
|
+
request: RequestQueryBody<
|
|
113
|
+
RequestMethod,
|
|
114
|
+
RestTableInterface,
|
|
115
|
+
CustomAndRequiredFields,
|
|
116
|
+
RequestTableOverrides
|
|
117
|
+
>,
|
|
105
118
|
callback: () => void
|
|
106
119
|
) {
|
|
107
120
|
this.config.reactBootstrap?.deleteRestfulObjectArrays<RestTableInterface>({
|
|
@@ -172,17 +185,9 @@ export class HttpExecutor<
|
|
|
172
185
|
|
|
173
186
|
// an undefined query would indicate queryCallback returned undefined,
|
|
174
187
|
// thus the request shouldn't fire as is in custom cache
|
|
175
|
-
|
|
188
|
+
if (undefined === this.request || null === this.request) {
|
|
176
189
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
if (this.request.debug && isLocal) {
|
|
180
|
-
|
|
181
|
-
toast.warning("DEV: queryCallback returned undefined, signaling in Custom Cache. (returning null)", toastOptionsDevs)
|
|
182
|
-
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
console.groupCollapsed('%c API: (' + requestMethod + ') Request Query for (' + tableName + ') undefined, returning null (will not fire ajax)!', 'color: #c00')
|
|
190
|
+
console.groupCollapsed('%c API: (' + requestMethod + ') Request Query for (' + tableName + ') undefined, returning null (will not fire)!', 'color: #c00')
|
|
186
191
|
|
|
187
192
|
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')
|
|
188
193
|
|
|
@@ -194,6 +199,8 @@ export class HttpExecutor<
|
|
|
194
199
|
|
|
195
200
|
}
|
|
196
201
|
|
|
202
|
+
let query = this.request;
|
|
203
|
+
|
|
197
204
|
if (C6.GET === requestMethod) {
|
|
198
205
|
|
|
199
206
|
if (undefined === query[C6.PAGINATION]) {
|
|
@@ -251,7 +258,12 @@ export class HttpExecutor<
|
|
|
251
258
|
|
|
252
259
|
if (undefined === query || null === query) {
|
|
253
260
|
|
|
254
|
-
query = {}
|
|
261
|
+
query = {} as RequestQueryBody<
|
|
262
|
+
RequestMethod,
|
|
263
|
+
RestTableInterface,
|
|
264
|
+
CustomAndRequiredFields,
|
|
265
|
+
RequestTableOverrides
|
|
266
|
+
>
|
|
255
267
|
|
|
256
268
|
}
|
|
257
269
|
|
|
@@ -412,8 +424,13 @@ export class HttpExecutor<
|
|
|
412
424
|
const removedPkValue = query[primaryKey];
|
|
413
425
|
|
|
414
426
|
addBackPK = () => {
|
|
415
|
-
query ??= {}
|
|
416
|
-
|
|
427
|
+
query ??= {} as RequestQueryBody<
|
|
428
|
+
RequestMethod,
|
|
429
|
+
RestTableInterface,
|
|
430
|
+
CustomAndRequiredFields,
|
|
431
|
+
RequestTableOverrides
|
|
432
|
+
>;
|
|
433
|
+
query[primaryKey] = removedPkValue;
|
|
417
434
|
}
|
|
418
435
|
|
|
419
436
|
delete query[primaryKey]
|
|
@@ -448,62 +465,56 @@ export class HttpExecutor<
|
|
|
448
465
|
|
|
449
466
|
const axiosActiveRequest: AxiosPromise<ResponseDataType> = axios![requestMethod.toLowerCase()]<ResponseDataType>(
|
|
450
467
|
restRequestUri,
|
|
451
|
-
...((
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
468
|
+
...(() => {
|
|
469
|
+
const convert = (data: any) =>
|
|
470
|
+
convertForRequestBody<
|
|
471
|
+
RequestMethod,
|
|
472
|
+
RestTableInterface,
|
|
473
|
+
CustomAndRequiredFields,
|
|
474
|
+
RequestTableOverrides
|
|
475
|
+
>(
|
|
476
|
+
data,
|
|
477
|
+
fullTableList,
|
|
478
|
+
C6,
|
|
479
|
+
(message) => toast.error(message, toastOptions)
|
|
480
|
+
);
|
|
481
|
+
|
|
482
|
+
const baseConfig = {
|
|
483
|
+
withCredentials: withCredentials,
|
|
484
|
+
};
|
|
485
|
+
|
|
486
|
+
switch (requestMethod) {
|
|
487
|
+
case GET:
|
|
488
|
+
return [{
|
|
489
|
+
...baseConfig,
|
|
490
|
+
params: query
|
|
491
|
+
}];
|
|
492
|
+
|
|
493
|
+
case POST:
|
|
494
|
+
if (dataInsertMultipleRows !== undefined) {
|
|
495
|
+
return [
|
|
496
|
+
dataInsertMultipleRows.map(convert),
|
|
497
|
+
baseConfig
|
|
498
|
+
];
|
|
480
499
|
}
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
} else if (requestMethod === PUT) {
|
|
500
|
+
return [convert(query), baseConfig];
|
|
484
501
|
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
{
|
|
488
|
-
withCredentials: withCredentials,
|
|
489
|
-
}
|
|
490
|
-
]
|
|
491
|
-
} else if (requestMethod === DELETE) {
|
|
502
|
+
case PUT:
|
|
503
|
+
return [convert(query), baseConfig];
|
|
492
504
|
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
} else {
|
|
499
|
-
|
|
500
|
-
throw new Error('The request method (' + requestMethod + ') was not recognized.')
|
|
505
|
+
case DELETE:
|
|
506
|
+
return [{
|
|
507
|
+
...baseConfig,
|
|
508
|
+
data: convert(query)
|
|
509
|
+
}];
|
|
501
510
|
|
|
511
|
+
default:
|
|
512
|
+
throw new Error(`The request method (${requestMethod}) was not recognized.`);
|
|
502
513
|
}
|
|
503
|
-
|
|
504
|
-
})())
|
|
514
|
+
})()
|
|
505
515
|
);
|
|
506
516
|
|
|
517
|
+
|
|
507
518
|
if (cachingConfirmed) {
|
|
508
519
|
|
|
509
520
|
// push to cache so we do not repeat the request
|
package/src/api/restRequest.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import isNode from '../variables/isNode';
|
|
2
|
-
import {Modify} from "./types/modifyTypes";
|
|
3
2
|
import {
|
|
4
3
|
apiReturn, DetermineResponseDataType,
|
|
5
|
-
|
|
6
|
-
iRest, iRestMethods
|
|
4
|
+
iRest, iRestMethods, RequestQueryBody
|
|
7
5
|
} from "./types/ormInterfaces";
|
|
8
6
|
|
|
9
7
|
/**
|
|
@@ -24,7 +22,12 @@ export default function restRequest<
|
|
|
24
22
|
>
|
|
25
23
|
) {
|
|
26
24
|
return async (
|
|
27
|
-
request:
|
|
25
|
+
request: RequestQueryBody<
|
|
26
|
+
RequestMethod,
|
|
27
|
+
RestTableInterface,
|
|
28
|
+
CustomAndRequiredFields,
|
|
29
|
+
RequestTableOverrides
|
|
30
|
+
>,
|
|
28
31
|
): Promise<apiReturn<DetermineResponseDataType<RequestMethod, RestTableInterface>>> => {
|
|
29
32
|
|
|
30
33
|
// SQL path if on Node with a provided pool
|