@carbonorm/carbonnode 3.0.3 → 3.0.5
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 +549 -97
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +551 -98
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/scripts/assets/handlebars/C6.ts.handlebars +32 -24
- package/scripts/generateRestBindings.cjs +4 -0
- package/scripts/generateRestBindings.ts +4 -0
- package/src/api/convertForRequestBody.ts +62 -90
- package/src/api/executors/Executor.ts +8 -4
- package/src/api/executors/HttpExecutor.ts +81 -68
- 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,11 @@ 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
|
-
|
|
190
|
+
console.groupCollapsed('%c API: (' + requestMethod + ') Request Query for (' + tableName + ') undefined, returning null (will not fire)!', 'color: #c00')
|
|
178
191
|
|
|
179
|
-
|
|
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')
|
|
192
|
+
console.log('request', this.request)
|
|
186
193
|
|
|
187
194
|
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
195
|
|
|
@@ -194,6 +201,8 @@ export class HttpExecutor<
|
|
|
194
201
|
|
|
195
202
|
}
|
|
196
203
|
|
|
204
|
+
let query = this.request;
|
|
205
|
+
|
|
197
206
|
if (C6.GET === requestMethod) {
|
|
198
207
|
|
|
199
208
|
if (undefined === query[C6.PAGINATION]) {
|
|
@@ -251,7 +260,12 @@ export class HttpExecutor<
|
|
|
251
260
|
|
|
252
261
|
if (undefined === query || null === query) {
|
|
253
262
|
|
|
254
|
-
query = {}
|
|
263
|
+
query = {} as RequestQueryBody<
|
|
264
|
+
RequestMethod,
|
|
265
|
+
RestTableInterface,
|
|
266
|
+
CustomAndRequiredFields,
|
|
267
|
+
RequestTableOverrides
|
|
268
|
+
>
|
|
255
269
|
|
|
256
270
|
}
|
|
257
271
|
|
|
@@ -412,8 +426,13 @@ export class HttpExecutor<
|
|
|
412
426
|
const removedPkValue = query[primaryKey];
|
|
413
427
|
|
|
414
428
|
addBackPK = () => {
|
|
415
|
-
query ??= {}
|
|
416
|
-
|
|
429
|
+
query ??= {} as RequestQueryBody<
|
|
430
|
+
RequestMethod,
|
|
431
|
+
RestTableInterface,
|
|
432
|
+
CustomAndRequiredFields,
|
|
433
|
+
RequestTableOverrides
|
|
434
|
+
>;
|
|
435
|
+
query[primaryKey] = removedPkValue;
|
|
417
436
|
}
|
|
418
437
|
|
|
419
438
|
delete query[primaryKey]
|
|
@@ -448,62 +467,56 @@ export class HttpExecutor<
|
|
|
448
467
|
|
|
449
468
|
const axiosActiveRequest: AxiosPromise<ResponseDataType> = axios![requestMethod.toLowerCase()]<ResponseDataType>(
|
|
450
469
|
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
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
} else if (requestMethod === PUT) {
|
|
484
|
-
|
|
485
|
-
return [
|
|
486
|
-
convertForRequestBody<RestTableInterface>(query as RestTableInterface, fullTableList, C6, (message) => toast.error(message, toastOptions)),
|
|
487
|
-
{
|
|
488
|
-
withCredentials: withCredentials,
|
|
470
|
+
...(() => {
|
|
471
|
+
const convert = (data: any) =>
|
|
472
|
+
convertForRequestBody<
|
|
473
|
+
RequestMethod,
|
|
474
|
+
RestTableInterface,
|
|
475
|
+
CustomAndRequiredFields,
|
|
476
|
+
RequestTableOverrides
|
|
477
|
+
>(
|
|
478
|
+
data,
|
|
479
|
+
fullTableList,
|
|
480
|
+
C6,
|
|
481
|
+
(message) => toast.error(message, toastOptions)
|
|
482
|
+
);
|
|
483
|
+
|
|
484
|
+
const baseConfig = {
|
|
485
|
+
withCredentials: withCredentials,
|
|
486
|
+
};
|
|
487
|
+
|
|
488
|
+
switch (requestMethod) {
|
|
489
|
+
case GET:
|
|
490
|
+
return [{
|
|
491
|
+
...baseConfig,
|
|
492
|
+
params: query
|
|
493
|
+
}];
|
|
494
|
+
|
|
495
|
+
case POST:
|
|
496
|
+
if (dataInsertMultipleRows !== undefined) {
|
|
497
|
+
return [
|
|
498
|
+
dataInsertMultipleRows.map(convert),
|
|
499
|
+
baseConfig
|
|
500
|
+
];
|
|
489
501
|
}
|
|
490
|
-
|
|
491
|
-
} else if (requestMethod === DELETE) {
|
|
492
|
-
|
|
493
|
-
return [{
|
|
494
|
-
withCredentials: withCredentials,
|
|
495
|
-
data: convertForRequestBody<RestTableInterface>(query as RestTableInterface, fullTableList, C6, (message) => toast.error(message, toastOptions))
|
|
496
|
-
}]
|
|
502
|
+
return [convert(query), baseConfig];
|
|
497
503
|
|
|
498
|
-
|
|
504
|
+
case PUT:
|
|
505
|
+
return [convert(query), baseConfig];
|
|
499
506
|
|
|
500
|
-
|
|
507
|
+
case DELETE:
|
|
508
|
+
return [{
|
|
509
|
+
...baseConfig,
|
|
510
|
+
data: convert(query)
|
|
511
|
+
}];
|
|
501
512
|
|
|
513
|
+
default:
|
|
514
|
+
throw new Error(`The request method (${requestMethod}) was not recognized.`);
|
|
502
515
|
}
|
|
503
|
-
|
|
504
|
-
})())
|
|
516
|
+
})()
|
|
505
517
|
);
|
|
506
518
|
|
|
519
|
+
|
|
507
520
|
if (cachingConfirmed) {
|
|
508
521
|
|
|
509
522
|
// 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
|