@carbonorm/carbonnode 3.0.2 → 3.0.3
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 +8 -7
- package/dist/api/executors/HttpExecutor.d.ts +10 -5
- package/dist/api/executors/SqlExecutor.d.ts +5 -5
- package/dist/api/restOrm.d.ts +43 -0
- package/dist/api/restRequest.d.ts +4 -4
- package/dist/api/types/ormInterfaces.d.ts +53 -27
- package/dist/index.cjs.js +125 -473
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +125 -474
- 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 +30 -4
- package/scripts/generateRestBindings.cjs +2 -7
- package/scripts/generateRestBindings.ts +2 -14
- package/src/api/executors/Executor.ts +63 -13
- package/src/api/executors/HttpExecutor.ts +150 -27
- package/src/api/executors/SqlExecutor.ts +6 -6
- package/src/api/rest/C6.test.ts +88 -0
- package/src/api/rest/C6.ts +5338 -0
- package/src/api/restOrm.ts +61 -0
- package/src/api/restRequest.ts +14 -12
- package/src/api/types/ormInterfaces.ts +102 -19
- 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
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import { apiReturn, iAPI, iRest } from "@carbonorm/carbonnode";
|
|
1
|
+
import { apiReturn, DetermineResponseDataType, iAPI, iRest, iRestMethods, iRestReactiveLifecycle } from "@carbonorm/carbonnode";
|
|
2
2
|
import { Modify } from "../types/modifyTypes";
|
|
3
|
-
export declare abstract class Executor<RestShortTableName extends string = any, RestTableInterface extends {
|
|
3
|
+
export declare abstract class Executor<RequestMethod extends iRestMethods, RestShortTableName extends string = any, RestTableInterface extends {
|
|
4
4
|
[key: string]: any;
|
|
5
5
|
} = any, PrimaryKey extends Extract<keyof RestTableInterface, string> = Extract<keyof RestTableInterface, string>, CustomAndRequiredFields extends {
|
|
6
6
|
[key: string]: any;
|
|
7
7
|
} = any, RequestTableOverrides extends {
|
|
8
|
-
[key
|
|
8
|
+
[key in keyof RestTableInterface]: any;
|
|
9
9
|
} = {
|
|
10
10
|
[key in keyof RestTableInterface]: any;
|
|
11
|
-
}
|
|
12
|
-
protected config: iRest<RestShortTableName, RestTableInterface, PrimaryKey
|
|
11
|
+
}> {
|
|
12
|
+
protected config: iRest<RestShortTableName, RestTableInterface, PrimaryKey>;
|
|
13
13
|
protected request: iAPI<Modify<RestTableInterface, RequestTableOverrides>> & CustomAndRequiredFields;
|
|
14
|
-
constructor(config: iRest<RestShortTableName, RestTableInterface, PrimaryKey
|
|
15
|
-
abstract execute(): Promise<apiReturn<
|
|
14
|
+
constructor(config: iRest<RestShortTableName, RestTableInterface, PrimaryKey>, request?: iAPI<Modify<RestTableInterface, RequestTableOverrides>> & CustomAndRequiredFields);
|
|
15
|
+
abstract execute(): Promise<apiReturn<DetermineResponseDataType<RequestMethod, RestTableInterface>>>;
|
|
16
|
+
runLifecycleHooks<Phase extends keyof iRestReactiveLifecycle<RequestMethod, RestShortTableName, RestTableInterface, PrimaryKey, CustomAndRequiredFields, RequestTableOverrides>>(phase: Phase, args: Parameters<NonNullable<iRestReactiveLifecycle<RequestMethod, RestShortTableName, RestTableInterface, PrimaryKey, CustomAndRequiredFields, RequestTableOverrides>[Phase]>[string]>[0]): Promise<void>;
|
|
16
17
|
}
|
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AxiosResponse } from "axios";
|
|
2
|
+
import { Modify } from "../types/modifyTypes";
|
|
3
|
+
import { apiReturn, DetermineResponseDataType, iAPI, iRestMethods } from "../types/ormInterfaces";
|
|
2
4
|
import { Executor } from "./Executor";
|
|
3
|
-
export declare class HttpExecutor<RestShortTableName extends string = any, RestTableInterface extends {
|
|
5
|
+
export declare class HttpExecutor<RequestMethod extends iRestMethods, RestShortTableName extends string = any, RestTableInterface extends {
|
|
4
6
|
[key: string]: any;
|
|
5
7
|
} = any, PrimaryKey extends Extract<keyof RestTableInterface, string> = Extract<keyof RestTableInterface, string>, CustomAndRequiredFields extends {
|
|
6
8
|
[key: string]: any;
|
|
7
9
|
} = any, RequestTableOverrides extends {
|
|
8
|
-
[key
|
|
10
|
+
[key in keyof RestTableInterface]: any;
|
|
9
11
|
} = {
|
|
10
12
|
[key in keyof RestTableInterface]: any;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
+
}> extends Executor<RequestMethod, RestShortTableName, RestTableInterface, PrimaryKey, CustomAndRequiredFields, RequestTableOverrides> {
|
|
14
|
+
putState(response: AxiosResponse<DetermineResponseDataType<RequestMethod, RestTableInterface>>, request: iAPI<Modify<RestTableInterface, RequestTableOverrides>> & CustomAndRequiredFields, callback: () => void): void;
|
|
15
|
+
postState(response: AxiosResponse<DetermineResponseDataType<RequestMethod, RestTableInterface>>, request: iAPI<Modify<RestTableInterface, RequestTableOverrides>> & CustomAndRequiredFields, callback: () => void): void;
|
|
16
|
+
deleteState(_response: AxiosResponse<DetermineResponseDataType<RequestMethod, RestTableInterface>>, request: iAPI<Modify<RestTableInterface, RequestTableOverrides>> & CustomAndRequiredFields, callback: () => void): void;
|
|
17
|
+
execute(): Promise<apiReturn<DetermineResponseDataType<RequestMethod, RestTableInterface>>>;
|
|
13
18
|
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { iRestMethods } from "@carbonorm/carbonnode";
|
|
2
2
|
import { RowDataPacket } from 'mysql2/promise';
|
|
3
3
|
import { Executor } from "./Executor";
|
|
4
|
-
export declare class SqlExecutor<RestShortTableName extends string = any, RestTableInterface extends {
|
|
4
|
+
export declare class SqlExecutor<RequestMethod extends iRestMethods, RestShortTableName extends string = any, RestTableInterface extends {
|
|
5
5
|
[key: string]: any;
|
|
6
6
|
} = any, PrimaryKey extends Extract<keyof RestTableInterface, string> = Extract<keyof RestTableInterface, string>, CustomAndRequiredFields extends {
|
|
7
7
|
[key: string]: any;
|
|
8
8
|
} = any, RequestTableOverrides extends {
|
|
9
|
-
[key
|
|
9
|
+
[key in keyof RestTableInterface]: any;
|
|
10
10
|
} = {
|
|
11
11
|
[key in keyof RestTableInterface]: any;
|
|
12
|
-
}
|
|
13
|
-
execute():
|
|
12
|
+
}> extends Executor<RequestMethod, RestShortTableName, RestTableInterface, PrimaryKey, CustomAndRequiredFields, RequestTableOverrides> {
|
|
13
|
+
execute(): any;
|
|
14
14
|
private withConnection;
|
|
15
15
|
select<RestShortTableNames>(table: RestShortTableNames, primary: string | undefined, args: any): Promise<RowDataPacket[]>;
|
|
16
16
|
insert<RestShortTableNames>(table: RestShortTableNames, data: any): Promise<import("mysql2/promise").QueryResult>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { iRest } from "./types/ormInterfaces";
|
|
2
|
+
export declare function restOrm<RestShortTableName extends string = any, RestTableInterface extends {
|
|
3
|
+
[key: string]: any;
|
|
4
|
+
} = any, PrimaryKey extends Extract<keyof RestTableInterface, string> = Extract<keyof RestTableInterface, string>, CustomAndRequiredFields extends {
|
|
5
|
+
[key: string]: any;
|
|
6
|
+
} = any, RequestTableOverrides extends {
|
|
7
|
+
[key in keyof RestTableInterface]: any;
|
|
8
|
+
} = {
|
|
9
|
+
[key in keyof RestTableInterface]: any;
|
|
10
|
+
}>(config: Omit<iRest<RestShortTableName, RestTableInterface, PrimaryKey>, "requestMethod">): {
|
|
11
|
+
Get: (request?: Omit<RestTableInterface, keyof RequestTableOverrides> & RequestTableOverrides & {
|
|
12
|
+
dataInsertMultipleRows?: import("..").Modify<RestTableInterface, RequestTableOverrides>[] | undefined;
|
|
13
|
+
cacheResults?: boolean;
|
|
14
|
+
fetchDependencies?: number | import("..").eFetchDependencies | Awaited<import("./types/ormInterfaces").apiReturn<import("./types/ormInterfaces").iGetC6RestResponse<any>>>[];
|
|
15
|
+
debug?: boolean;
|
|
16
|
+
success?: string | ((r: import("axios").AxiosResponse) => (string | void));
|
|
17
|
+
error?: string | ((r: import("axios").AxiosResponse) => (string | void));
|
|
18
|
+
} & CustomAndRequiredFields) => Promise<import("./types/ormInterfaces").apiReturn<import("./types/ormInterfaces").iGetC6RestResponse<RestTableInterface, {}>>>;
|
|
19
|
+
Put: (request?: Omit<RestTableInterface, keyof RequestTableOverrides> & RequestTableOverrides & {
|
|
20
|
+
dataInsertMultipleRows?: import("..").Modify<RestTableInterface, RequestTableOverrides>[] | undefined;
|
|
21
|
+
cacheResults?: boolean;
|
|
22
|
+
fetchDependencies?: number | import("..").eFetchDependencies | Awaited<import("./types/ormInterfaces").apiReturn<import("./types/ormInterfaces").iGetC6RestResponse<any>>>[];
|
|
23
|
+
debug?: boolean;
|
|
24
|
+
success?: string | ((r: import("axios").AxiosResponse) => (string | void));
|
|
25
|
+
error?: string | ((r: import("axios").AxiosResponse) => (string | void));
|
|
26
|
+
} & CustomAndRequiredFields) => Promise<import("./types/ormInterfaces").apiReturn<import("./types/ormInterfaces").iPutC6RestResponse<RestTableInterface, any>>>;
|
|
27
|
+
Post: (request?: Omit<RestTableInterface, keyof RequestTableOverrides> & RequestTableOverrides & {
|
|
28
|
+
dataInsertMultipleRows?: import("..").Modify<RestTableInterface, RequestTableOverrides>[] | undefined;
|
|
29
|
+
cacheResults?: boolean;
|
|
30
|
+
fetchDependencies?: number | import("..").eFetchDependencies | Awaited<import("./types/ormInterfaces").apiReturn<import("./types/ormInterfaces").iGetC6RestResponse<any>>>[];
|
|
31
|
+
debug?: boolean;
|
|
32
|
+
success?: string | ((r: import("axios").AxiosResponse) => (string | void));
|
|
33
|
+
error?: string | ((r: import("axios").AxiosResponse) => (string | void));
|
|
34
|
+
} & CustomAndRequiredFields) => Promise<import("./types/ormInterfaces").apiReturn<import("./types/ormInterfaces").iPostC6RestResponse<RestTableInterface>>>;
|
|
35
|
+
Delete: (request?: Omit<RestTableInterface, keyof RequestTableOverrides> & RequestTableOverrides & {
|
|
36
|
+
dataInsertMultipleRows?: import("..").Modify<RestTableInterface, RequestTableOverrides>[] | undefined;
|
|
37
|
+
cacheResults?: boolean;
|
|
38
|
+
fetchDependencies?: number | import("..").eFetchDependencies | Awaited<import("./types/ormInterfaces").apiReturn<import("./types/ormInterfaces").iGetC6RestResponse<any>>>[];
|
|
39
|
+
debug?: boolean;
|
|
40
|
+
success?: string | ((r: import("axios").AxiosResponse) => (string | void));
|
|
41
|
+
error?: string | ((r: import("axios").AxiosResponse) => (string | void));
|
|
42
|
+
} & CustomAndRequiredFields) => Promise<import("./types/ormInterfaces").apiReturn<import("./types/ormInterfaces").iDeleteC6RestResponse<RestTableInterface, any>>>;
|
|
43
|
+
};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { Modify } from "./types/modifyTypes";
|
|
2
|
-
import { apiReturn, iAPI, iRest } from "./types/ormInterfaces";
|
|
2
|
+
import { apiReturn, DetermineResponseDataType, iAPI, iRest, iRestMethods } 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<RestShortTableName extends string = any, RestTableInterface extends {
|
|
6
|
+
export default function restRequest<RequestMethod extends iRestMethods, RestShortTableName extends string = any, RestTableInterface extends {
|
|
7
7
|
[key: string]: any;
|
|
8
8
|
} = any, PrimaryKey extends Extract<keyof RestTableInterface, string> = Extract<keyof RestTableInterface, string>, CustomAndRequiredFields extends {
|
|
9
9
|
[key: string]: any;
|
|
10
10
|
} = any, RequestTableOverrides extends {
|
|
11
|
-
[key
|
|
11
|
+
[key in keyof RestTableInterface]: any;
|
|
12
12
|
} = {
|
|
13
13
|
[key in keyof RestTableInterface]: any;
|
|
14
|
-
}
|
|
14
|
+
}>(config: iRest<RestShortTableName, RestTableInterface, PrimaryKey>): (request?: iAPI<Modify<RestTableInterface, RequestTableOverrides>> & CustomAndRequiredFields) => Promise<apiReturn<DetermineResponseDataType<RequestMethod, RestTableInterface>>>;
|
|
@@ -3,6 +3,7 @@ import { Pool } from "mysql2/promise";
|
|
|
3
3
|
import { eFetchDependencies } from "./dynamicFetching";
|
|
4
4
|
import { Modify } from "./modifyTypes";
|
|
5
5
|
import { JoinType, OrderDirection, SQLComparisonOperator, SQLFunction } from "./mysqlTypes";
|
|
6
|
+
import { CarbonReact } from "@carbonorm/carbonreact";
|
|
6
7
|
export interface stringMap {
|
|
7
8
|
[key: string]: string;
|
|
8
9
|
}
|
|
@@ -21,25 +22,52 @@ export interface iTypeValidation {
|
|
|
21
22
|
AUTO_INCREMENT: boolean;
|
|
22
23
|
SKIP_COLUMN_IN_POST: boolean;
|
|
23
24
|
}
|
|
24
|
-
export type iRestReactiveLifecycle<
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
25
|
+
export type iRestReactiveLifecycle<RequestMethod extends iRestMethods, RestShortTableName extends string = any, RestTableInterface extends {
|
|
26
|
+
[key: string]: any;
|
|
27
|
+
} = any, PrimaryKey extends keyof RestTableInterface & string = any, CustomAndRequiredFields extends {
|
|
28
|
+
[key: string]: any;
|
|
29
|
+
} = any, RequestTableOverrides extends {
|
|
30
|
+
[key: string]: any;
|
|
31
|
+
} = {
|
|
32
|
+
[key in keyof RestTableInterface]: any;
|
|
33
|
+
}> = {
|
|
34
|
+
beforeProcessing?: {
|
|
35
|
+
[key: string]: (args: {
|
|
36
|
+
config: iRest<RestShortTableName, RestTableInterface, PrimaryKey>;
|
|
37
|
+
request: iAPI<Modify<RestTableInterface, RequestTableOverrides>> & CustomAndRequiredFields;
|
|
38
|
+
}) => void | Promise<void>;
|
|
39
|
+
};
|
|
40
|
+
beforeExecution?: {
|
|
41
|
+
[key: string]: (args: {
|
|
42
|
+
config: iRest<RestShortTableName, RestTableInterface, PrimaryKey>;
|
|
43
|
+
request: iAPI<Modify<RestTableInterface, RequestTableOverrides>> & CustomAndRequiredFields;
|
|
44
|
+
}) => void | Promise<void>;
|
|
45
|
+
};
|
|
46
|
+
afterExecution?: {
|
|
47
|
+
[key: string]: (args: {
|
|
48
|
+
config: iRest<RestShortTableName, RestTableInterface, PrimaryKey>;
|
|
49
|
+
request: iAPI<Modify<RestTableInterface, RequestTableOverrides>> & CustomAndRequiredFields;
|
|
50
|
+
response: AxiosResponse<DetermineResponseDataType<RequestMethod, RestTableInterface>>;
|
|
51
|
+
}) => void | Promise<void>;
|
|
52
|
+
};
|
|
53
|
+
afterCommit?: {
|
|
54
|
+
[key: string]: (args: {
|
|
55
|
+
config: iRest<RestShortTableName, RestTableInterface, PrimaryKey>;
|
|
56
|
+
request: iAPI<Modify<RestTableInterface, RequestTableOverrides>> & CustomAndRequiredFields;
|
|
57
|
+
response: AxiosResponse<DetermineResponseDataType<RequestMethod, RestTableInterface>>;
|
|
58
|
+
}) => void | Promise<void>;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
export type iRestHooks<RestShortTableName extends string = any, RestTableInterface extends {
|
|
62
|
+
[key: string]: any;
|
|
63
|
+
} = any, PrimaryKey extends keyof RestTableInterface & string = any, CustomAndRequiredFields extends {
|
|
64
|
+
[key: string]: any;
|
|
65
|
+
} = any, RequestTableOverrides extends {
|
|
66
|
+
[key: string]: any;
|
|
67
|
+
} = {
|
|
68
|
+
[key in keyof RestTableInterface]: any;
|
|
69
|
+
}> = {
|
|
70
|
+
[Method in iRestMethods]: iRestReactiveLifecycle<Method, RestShortTableName, RestTableInterface, PrimaryKey, CustomAndRequiredFields, RequestTableOverrides>;
|
|
43
71
|
};
|
|
44
72
|
export interface iConstraint {
|
|
45
73
|
TABLE: string;
|
|
@@ -63,7 +91,7 @@ export interface iC6RestfulModel<RestShortTableNames extends string, RestTableIn
|
|
|
63
91
|
[key: string]: iTypeValidation;
|
|
64
92
|
};
|
|
65
93
|
REGEX_VALIDATION: RegExpMap;
|
|
66
|
-
LIFECYCLE_HOOKS:
|
|
94
|
+
LIFECYCLE_HOOKS: iRestHooks<RestShortTableNames, RestTableInterfaces, PK>;
|
|
67
95
|
TABLE_REFERENCES: {
|
|
68
96
|
[columnName: string]: iConstraint[];
|
|
69
97
|
};
|
|
@@ -197,23 +225,21 @@ export interface iC6Object<RestShortTableName extends string = any, RestTableInt
|
|
|
197
225
|
}
|
|
198
226
|
export type iGetC6RestResponse<ResponseDataType, ResponseDataOverrides = {}> = iC6RestResponse<Modify<ResponseDataType, ResponseDataOverrides> | Modify<ResponseDataType, ResponseDataOverrides>[]>;
|
|
199
227
|
export type apiReturn<Response> = null | undefined | AxiosPromise<Response> | (Response extends iPutC6RestResponse | iDeleteC6RestResponse | iPostC6RestResponse ? null : (() => apiReturn<Response>));
|
|
200
|
-
export
|
|
228
|
+
export type DetermineResponseDataType<RequestMethod extends iRestMethods, RestTableInterface extends {
|
|
201
229
|
[key: string]: any;
|
|
202
|
-
} =
|
|
230
|
+
}> = RequestMethod extends "POST" ? iPostC6RestResponse<RestTableInterface> : RequestMethod extends "GET" ? iGetC6RestResponse<RestTableInterface> : RequestMethod extends "PUT" ? iPutC6RestResponse<RestTableInterface> : RequestMethod extends "DELETE" ? iDeleteC6RestResponse<RestTableInterface> : any;
|
|
231
|
+
export interface iRest<RestShortTableName extends string = any, RestTableInterface extends {
|
|
203
232
|
[key: string]: any;
|
|
204
|
-
} = any,
|
|
205
|
-
[key in keyof RestTableInterface]: any;
|
|
206
|
-
}, ResponseDataType = any> {
|
|
233
|
+
} = any, PrimaryKey extends keyof RestTableInterface & string = any> {
|
|
207
234
|
C6: iC6Object;
|
|
208
235
|
axios?: AxiosInstance;
|
|
209
236
|
restURL?: string;
|
|
210
237
|
mysqlPool?: Pool;
|
|
211
238
|
withCredentials?: boolean;
|
|
212
239
|
restModel: iC6RestfulModel<RestShortTableName, RestTableInterface, PrimaryKey>;
|
|
240
|
+
reactBootstrap?: CarbonReact<any, any>;
|
|
213
241
|
requestMethod: iRestMethods;
|
|
214
242
|
clearCache?: () => void;
|
|
215
243
|
skipPrimaryCheck?: boolean;
|
|
216
|
-
queryCallback: RequestQueryBody<Modify<RestTableInterface, RequestTableOverrides>> | ((request: iAPI<Modify<RestTableInterface, RequestTableOverrides>> & CustomAndRequiredFields) => (null | undefined | RequestQueryBody<Modify<RestTableInterface, RequestTableOverrides>>));
|
|
217
|
-
responseCallback?: (response: AxiosResponse<ResponseDataType>, request: iAPI<Modify<RestTableInterface, RequestTableOverrides>> & CustomAndRequiredFields, success: (ResponseDataType extends iPutC6RestResponse | iDeleteC6RestResponse ? RequestQueryBody<Modify<RestTableInterface, RequestTableOverrides>> : string) | RestTableInterface[PrimaryKey] | string | number | boolean) => any;
|
|
218
244
|
}
|
|
219
245
|
export {};
|