@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.
@@ -1,4 +1,8 @@
1
- import { iC6Object } from "./types/ormInterfaces";
2
- export default function <RestTableInterfaces extends {
1
+ import { iC6Object, iRestMethods, RequestQueryBody } from "./types/ormInterfaces";
2
+ export default function <RequestMethod extends iRestMethods, RestTableInterface extends {
3
3
  [key: string]: any;
4
- }>(restfulObject: RestTableInterfaces, tableName: string | string[], C6: iC6Object, regexErrorHandler?: (message: string) => void): {};
4
+ }, CustomAndRequiredFields extends {
5
+ [key: string]: any;
6
+ } = {}, RequestTableOverrides extends {
7
+ [K in keyof RestTableInterface]?: any;
8
+ } = {}>(restfulObject: RequestQueryBody<RequestMethod, RestTableInterface, CustomAndRequiredFields, RequestTableOverrides>, tableName: string | string[], C6: iC6Object, regexErrorHandler?: (message: string) => void): {};
@@ -1,5 +1,4 @@
1
- import { apiReturn, DetermineResponseDataType, iAPI, iRest, iRestMethods, iRestReactiveLifecycle } from "@carbonorm/carbonnode";
2
- import { Modify } from "../types/modifyTypes";
1
+ import { apiReturn, DetermineResponseDataType, iRest, iRestMethods, iRestReactiveLifecycle, RequestQueryBody } from "@carbonorm/carbonnode";
3
2
  export declare abstract class Executor<RequestMethod extends iRestMethods, RestShortTableName extends string = any, RestTableInterface extends {
4
3
  [key: string]: any;
5
4
  } = any, PrimaryKey extends Extract<keyof RestTableInterface, string> = Extract<keyof RestTableInterface, string>, CustomAndRequiredFields extends {
@@ -10,8 +9,8 @@ export declare abstract class Executor<RequestMethod extends iRestMethods, RestS
10
9
  [key in keyof RestTableInterface]: any;
11
10
  }> {
12
11
  protected config: iRest<RestShortTableName, RestTableInterface, PrimaryKey>;
13
- protected request: iAPI<Modify<RestTableInterface, RequestTableOverrides>> & CustomAndRequiredFields;
14
- constructor(config: iRest<RestShortTableName, RestTableInterface, PrimaryKey>, request?: iAPI<Modify<RestTableInterface, RequestTableOverrides>> & CustomAndRequiredFields);
12
+ protected request: RequestQueryBody<RequestMethod, RestTableInterface, CustomAndRequiredFields, RequestTableOverrides>;
13
+ constructor(config: iRest<RestShortTableName, RestTableInterface, PrimaryKey>, request: RequestQueryBody<RequestMethod, RestTableInterface, CustomAndRequiredFields, RequestTableOverrides>);
15
14
  abstract execute(): Promise<apiReturn<DetermineResponseDataType<RequestMethod, RestTableInterface>>>;
16
15
  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>;
17
16
  }
@@ -1,6 +1,5 @@
1
1
  import { AxiosResponse } from "axios";
2
- import { Modify } from "../types/modifyTypes";
3
- import { apiReturn, DetermineResponseDataType, iAPI, iRestMethods } from "../types/ormInterfaces";
2
+ import { apiReturn, DetermineResponseDataType, iRestMethods, RequestQueryBody } from "../types/ormInterfaces";
4
3
  import { Executor } from "./Executor";
5
4
  export declare class HttpExecutor<RequestMethod extends iRestMethods, RestShortTableName extends string = any, RestTableInterface extends {
6
5
  [key: string]: any;
@@ -11,8 +10,8 @@ export declare class HttpExecutor<RequestMethod extends iRestMethods, RestShortT
11
10
  } = {
12
11
  [key in keyof RestTableInterface]: any;
13
12
  }> 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;
13
+ putState(response: AxiosResponse<DetermineResponseDataType<RequestMethod, RestTableInterface>>, request: RequestQueryBody<RequestMethod, RestTableInterface, CustomAndRequiredFields, RequestTableOverrides>, callback: () => void): void;
14
+ postState(response: AxiosResponse<DetermineResponseDataType<RequestMethod, RestTableInterface>>, request: RequestQueryBody<RequestMethod, RestTableInterface, CustomAndRequiredFields, RequestTableOverrides>, callback: () => void): void;
15
+ deleteState(_response: AxiosResponse<DetermineResponseDataType<RequestMethod, RestTableInterface>>, request: RequestQueryBody<RequestMethod, RestTableInterface, CustomAndRequiredFields, RequestTableOverrides>, callback: () => void): void;
17
16
  execute(): Promise<apiReturn<DetermineResponseDataType<RequestMethod, RestTableInterface>>>;
18
17
  }
@@ -8,36 +8,8 @@ export declare function restOrm<RestShortTableName extends string = any, RestTab
8
8
  } = {
9
9
  [key in keyof RestTableInterface]: any;
10
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>>>;
11
+ Get: (request: import("./types/ormInterfaces").iAPI<import("./types/ormInterfaces").RequestGetPutDeleteBody<Omit<RestTableInterface, keyof RequestTableOverrides> & RequestTableOverrides & CustomAndRequiredFields>>) => Promise<import("./types/ormInterfaces").apiReturn<import("./types/ormInterfaces").iGetC6RestResponse<RestTableInterface, {}>>>;
12
+ Put: (request: import("./types/ormInterfaces").iAPI<import("./types/ormInterfaces").RequestGetPutDeleteBody<Omit<RestTableInterface, keyof RequestTableOverrides> & RequestTableOverrides & CustomAndRequiredFields>>) => Promise<import("./types/ormInterfaces").apiReturn<import("./types/ormInterfaces").iPutC6RestResponse<RestTableInterface, any>>>;
13
+ Post: (request: import("./types/ormInterfaces").iAPI<Omit<RestTableInterface, keyof RequestTableOverrides> & RequestTableOverrides & CustomAndRequiredFields>) => Promise<import("./types/ormInterfaces").apiReturn<import("./types/ormInterfaces").iPostC6RestResponse<RestTableInterface>>>;
14
+ Delete: (request: import("./types/ormInterfaces").iAPI<import("./types/ormInterfaces").RequestGetPutDeleteBody<Omit<RestTableInterface, keyof RequestTableOverrides> & RequestTableOverrides & CustomAndRequiredFields>>) => Promise<import("./types/ormInterfaces").apiReturn<import("./types/ormInterfaces").iDeleteC6RestResponse<RestTableInterface, any>>>;
43
15
  };
@@ -1,5 +1,4 @@
1
- import { Modify } from "./types/modifyTypes";
2
- import { apiReturn, DetermineResponseDataType, iAPI, iRest, iRestMethods } from "./types/ormInterfaces";
1
+ import { apiReturn, DetermineResponseDataType, iRest, iRestMethods, RequestQueryBody } from "./types/ormInterfaces";
3
2
  /**
4
3
  * Facade: routes API calls to SQL or HTTP executors based on runtime context.
5
4
  */
@@ -11,4 +10,4 @@ export default function restRequest<RequestMethod extends iRestMethods, RestShor
11
10
  [key in keyof RestTableInterface]: any;
12
11
  } = {
13
12
  [key in keyof RestTableInterface]: any;
14
- }>(config: iRest<RestShortTableName, RestTableInterface, PrimaryKey>): (request?: iAPI<Modify<RestTableInterface, RequestTableOverrides>> & CustomAndRequiredFields) => Promise<apiReturn<DetermineResponseDataType<RequestMethod, RestTableInterface>>>;
13
+ }>(config: iRest<RestShortTableName, RestTableInterface, PrimaryKey>): (request: RequestQueryBody<RequestMethod, RestTableInterface, CustomAndRequiredFields, RequestTableOverrides>) => Promise<apiReturn<DetermineResponseDataType<RequestMethod, RestTableInterface>>>;
@@ -4,6 +4,11 @@ import { eFetchDependencies } from "./dynamicFetching";
4
4
  import { Modify } from "./modifyTypes";
5
5
  import { JoinType, OrderDirection, SQLComparisonOperator, SQLFunction } from "./mysqlTypes";
6
6
  import { CarbonReact } from "@carbonorm/carbonreact";
7
+ export type iRestMethods = 'GET' | 'POST' | 'PUT' | 'DELETE';
8
+ export declare const POST = "POST";
9
+ export declare const PUT = "PUT";
10
+ export declare const GET = "GET";
11
+ export declare const DELETE = "DELETE";
7
12
  export interface stringMap {
8
13
  [key: string]: string;
9
14
  }
@@ -22,53 +27,103 @@ export interface iTypeValidation {
22
27
  AUTO_INCREMENT: boolean;
23
28
  SKIP_COLUMN_IN_POST: boolean;
24
29
  }
25
- export type iRestReactiveLifecycle<RequestMethod extends iRestMethods, RestShortTableName extends string = any, RestTableInterface extends {
30
+ export type SubSelect<T extends {
26
31
  [key: string]: any;
27
- } = any, PrimaryKey extends keyof RestTableInterface & string = any, CustomAndRequiredFields extends {
32
+ } = any> = {
33
+ subSelect: true;
34
+ table: string;
35
+ args: RequestQueryBody<'GET', T>;
36
+ alias: string;
37
+ };
38
+ export type SelectField<T extends {
28
39
  [key: string]: any;
29
- } = any, RequestTableOverrides extends {
40
+ } = any> = keyof T | [keyof T, 'AS', string] | [SQLFunction, keyof T] | [SQLFunction, keyof T, string] | SubSelect<T>;
41
+ export type WhereClause<T = any> = Partial<T> | LogicalGroup<T> | ComparisonClause<T>;
42
+ export type LogicalGroup<T = any> = {
43
+ [logicalGroup: string]: Array<WhereClause<T>>;
44
+ };
45
+ export type ComparisonClause<T = any> = [keyof T, SQLComparisonOperator, any];
46
+ export type JoinTableCondition<T = any> = Partial<T> | WhereClause<T>[] | ComparisonClause<T>[];
47
+ export type JoinClause<T = any> = {
48
+ [table: string]: JoinTableCondition<T>;
49
+ };
50
+ export type Join<T = any> = {
51
+ [K in JoinType]?: JoinClause<T>;
52
+ };
53
+ export type Pagination<T = any> = {
54
+ PAGE?: number;
55
+ LIMIT?: number | null;
56
+ ORDER?: Partial<Record<keyof T, OrderDirection>>;
57
+ };
58
+ export type RequestGetPutDeleteBody<T extends {
30
59
  [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
+ } = any> = {
61
+ SELECT?: SelectField<T>[];
62
+ UPDATE?: Partial<T>;
63
+ DELETE?: boolean;
64
+ WHERE?: WhereClause<T>;
65
+ JOIN?: Join<T>;
66
+ PAGINATION?: Pagination<T>;
60
67
  };
61
- export type iRestHooks<RestShortTableName extends string = any, RestTableInterface extends {
68
+ export type iAPI<T extends {
62
69
  [key: string]: any;
63
- } = any, PrimaryKey extends keyof RestTableInterface & string = any, CustomAndRequiredFields extends {
70
+ }> = T & {
71
+ dataInsertMultipleRows?: T[];
72
+ cacheResults?: boolean;
73
+ fetchDependencies?: number | eFetchDependencies | Awaited<apiReturn<iGetC6RestResponse<any>>>[];
74
+ debug?: boolean;
75
+ success?: string | ((r: AxiosResponse) => string | void);
76
+ error?: string | ((r: AxiosResponse) => string | void);
77
+ };
78
+ export type RequestQueryBody<Method extends iRestMethods, T extends {
64
79
  [key: string]: any;
65
- } = any, RequestTableOverrides extends {
80
+ }, Custom extends {
66
81
  [key: string]: any;
67
- } = {
68
- [key in keyof RestTableInterface]: any;
69
- }> = {
70
- [Method in iRestMethods]: iRestReactiveLifecycle<Method, RestShortTableName, RestTableInterface, PrimaryKey, CustomAndRequiredFields, RequestTableOverrides>;
71
- };
82
+ } = {}, Overrides extends {
83
+ [key: string]: any;
84
+ } = {}> = Method extends 'GET' | 'PUT' | 'DELETE' ? iAPI<RequestGetPutDeleteBody<Modify<T, Overrides> & Custom>> : iAPI<Modify<T, Overrides> & Custom>;
85
+ export interface iCacheAPI<ResponseDataType = any> {
86
+ requestArgumentsSerialized: string;
87
+ request: AxiosPromise<ResponseDataType>;
88
+ response?: AxiosResponse;
89
+ final?: boolean;
90
+ }
91
+ export interface iChangeC6Data {
92
+ rowCount: number;
93
+ }
94
+ export interface iDeleteC6RestResponse<RestData = any, RequestData = any> extends iChangeC6Data, iC6RestResponse<RestData> {
95
+ deleted: boolean | number | string | RequestData;
96
+ }
97
+ export interface iPostC6RestResponse<RestData = any> extends iC6RestResponse<RestData> {
98
+ created: boolean | number | string;
99
+ }
100
+ export interface iPutC6RestResponse<RestData = any, RequestData = any> extends iChangeC6Data, iC6RestResponse<RestData> {
101
+ updated: boolean | number | string | RequestData;
102
+ }
103
+ export interface iC6RestResponse<RestData> {
104
+ rest: RestData;
105
+ session?: any;
106
+ sql?: any;
107
+ }
108
+ export type iGetC6RestResponse<ResponseDataType, ResponseDataOverrides = {}> = iC6RestResponse<Modify<ResponseDataType, ResponseDataOverrides> | Modify<ResponseDataType, ResponseDataOverrides>[]>;
109
+ export type apiReturn<Response> = null | undefined | AxiosPromise<Response> | (Response extends iPutC6RestResponse | iDeleteC6RestResponse | iPostC6RestResponse ? null : () => apiReturn<Response>);
110
+ export type DetermineResponseDataType<Method extends iRestMethods, RestTableInterface extends {
111
+ [key: string]: any;
112
+ }> = Method extends 'POST' ? iPostC6RestResponse<RestTableInterface> : Method extends 'GET' ? iGetC6RestResponse<RestTableInterface> : Method extends 'PUT' ? iPutC6RestResponse<RestTableInterface> : Method extends 'DELETE' ? iDeleteC6RestResponse<RestTableInterface> : never;
113
+ export interface iRest<RestShortTableName extends string = any, RestTableInterface extends {
114
+ [key: string]: any;
115
+ } = any, PrimaryKey extends keyof RestTableInterface & string = any> {
116
+ C6: iC6Object;
117
+ axios?: AxiosInstance;
118
+ restURL?: string;
119
+ mysqlPool?: Pool;
120
+ withCredentials?: boolean;
121
+ restModel: iC6RestfulModel<RestShortTableName, RestTableInterface, PrimaryKey>;
122
+ reactBootstrap?: CarbonReact<any, any>;
123
+ requestMethod: iRestMethods;
124
+ clearCache?: () => void;
125
+ skipPrimaryCheck?: boolean;
126
+ }
72
127
  export interface iConstraint {
73
128
  TABLE: string;
74
129
  COLUMN: string;
@@ -99,116 +154,66 @@ export interface iC6RestfulModel<RestShortTableNames extends string, RestTableIn
99
154
  [columnName: string]: iConstraint[];
100
155
  };
101
156
  }
102
- export interface iRestApiFunctions<RestData = any> {
103
- Delete: (request?: (iAPI<any> & any)) => apiReturn<iDeleteC6RestResponse<RestData>>;
104
- Post: (request?: (iAPI<any> & any)) => apiReturn<iPostC6RestResponse<RestData>>;
105
- Get: (request?: (iAPI<any> & any)) => apiReturn<iGetC6RestResponse<RestData>>;
106
- Put: (request?: (iAPI<any> & any)) => apiReturn<iPutC6RestResponse<RestData>>;
107
- }
108
- export interface iDynamicApiImport<RestData = any> {
109
- default: iRestApiFunctions<RestData>;
110
- postState?: (response: AxiosResponse<iPostC6RestResponse<RestData>>, request: iAPI<any>, id: string | number | boolean) => void;
111
- deleteState?: (response: AxiosResponse<iDeleteC6RestResponse<RestData>>, request: iAPI<any>) => void;
112
- putState?: (response: AxiosResponse<iPutC6RestResponse<RestData>>, request: iAPI<any>) => void;
113
- }
114
- export interface tC6Tables<RestShortTableName extends string = any, RestTableInterface extends {
157
+ export type iRestReactiveLifecycle<Method extends iRestMethods, RestShortTableName extends string, RestTableInterface extends {
115
158
  [key: string]: any;
116
- } = any, PrimaryKey extends Extract<keyof RestTableInterface, string> = Extract<keyof RestTableInterface, string>> {
117
- [key: string]: iC6RestfulModel<RestShortTableName, RestTableInterface, PrimaryKey> & {
118
- [key: string]: any;
159
+ }, PrimaryKey extends keyof RestTableInterface & string, CustomAndRequiredFields extends {
160
+ [key: string]: any;
161
+ }, RequestTableOverrides extends {
162
+ [key: string]: any;
163
+ }> = {
164
+ beforeProcessing?: {
165
+ [key: string]: (args: {
166
+ config: iRest<RestShortTableName, RestTableInterface, PrimaryKey>;
167
+ request: RequestQueryBody<Method, RestTableInterface, CustomAndRequiredFields, RequestTableOverrides>;
168
+ }) => void | Promise<void>;
119
169
  };
120
- }
121
- export interface tC6RestApi {
122
- [key: string]: {
123
- REST: iRestApiFunctions;
124
- PUT: Function;
125
- POST: Function;
126
- DELETE: Function;
170
+ beforeExecution?: {
171
+ [key: string]: (args: {
172
+ config: iRest<RestShortTableName, RestTableInterface, PrimaryKey>;
173
+ request: RequestQueryBody<Method, RestTableInterface, CustomAndRequiredFields, RequestTableOverrides>;
174
+ }) => void | Promise<void>;
175
+ };
176
+ afterExecution?: {
177
+ [key: string]: (args: {
178
+ config: iRest<RestShortTableName, RestTableInterface, PrimaryKey>;
179
+ request: RequestQueryBody<Method, RestTableInterface, CustomAndRequiredFields, RequestTableOverrides>;
180
+ response: AxiosResponse<DetermineResponseDataType<Method, RestTableInterface>>;
181
+ }) => void | Promise<void>;
182
+ };
183
+ afterCommit?: {
184
+ [key: string]: (args: {
185
+ config: iRest<RestShortTableName, RestTableInterface, PrimaryKey>;
186
+ request: RequestQueryBody<Method, RestTableInterface, CustomAndRequiredFields, RequestTableOverrides>;
187
+ response: AxiosResponse<DetermineResponseDataType<Method, RestTableInterface>>;
188
+ }) => void | Promise<void>;
127
189
  };
128
- }
129
- export type iAPI<RestTableInterfaces extends {
130
- [key: string]: any;
131
- }> = RestTableInterfaces & {
132
- dataInsertMultipleRows?: RestTableInterfaces[];
133
- cacheResults?: boolean;
134
- fetchDependencies?: number | eFetchDependencies | Awaited<apiReturn<iGetC6RestResponse<any>>>[];
135
- debug?: boolean;
136
- success?: string | ((r: AxiosResponse) => (string | void));
137
- error?: string | ((r: AxiosResponse) => (string | void));
138
- };
139
- export interface iCacheAPI<ResponseDataType = any> {
140
- requestArgumentsSerialized: string;
141
- request: AxiosPromise<ResponseDataType>;
142
- response?: AxiosResponse;
143
- final?: boolean;
144
- }
145
- /**
146
- * the first argument ....
147
- *
148
- * Our api returns a zero argument function iff the method is get and the previous request reached the predefined limit.
149
- * This function can be aliased as GetNextPageOfResults(). If the end is reached undefined will be returned.
150
- *
151
- *
152
- * For POST, PUT, and DELETE requests one can expect the primary key of the new or modified index, or a boolean success
153
- * indication if no primary key exists.
154
- **/
155
- export declare const POST = "POST";
156
- export declare const PUT = "PUT";
157
- export declare const GET = "GET";
158
- export declare const DELETE = "DELETE";
159
- export type iRestMethods = 'GET' | 'POST' | 'PUT' | 'DELETE';
160
- export type SubSelect<T = any> = {
161
- subSelect: true;
162
- table: string;
163
- args: RequestGetPutDeleteBody<T>;
164
- alias: string;
165
- };
166
- export type SelectField<T = any> = keyof T | [keyof T, 'AS', string] | [SQLFunction, keyof T] | [SQLFunction, keyof T, string] | SubSelect<T>;
167
- export type WhereClause<T = any> = Partial<T> | LogicalGroup<T> | ComparisonClause<T>;
168
- export type LogicalGroup<T = any> = {
169
- [logicalGroup: string]: Array<WhereClause<T>>;
170
- };
171
- export type ComparisonClause<T = any> = [keyof T, SQLComparisonOperator, any];
172
- export type JoinTableCondition<T = any> = Partial<T> | WhereClause<T>[] | ComparisonClause<T>[];
173
- export type JoinClause<T = any> = {
174
- [table: string]: JoinTableCondition<T>;
175
- };
176
- export type Join<T = any> = {
177
- [K in JoinType]?: JoinClause<T>;
178
- };
179
- export type Pagination<T = any> = {
180
- PAGE?: number;
181
- LIMIT?: number | null;
182
- ORDER?: Partial<Record<keyof T, OrderDirection>>;
183
190
  };
184
- export type RequestGetPutDeleteBody<T = any> = {
185
- SELECT?: SelectField<T>[];
186
- UPDATE?: Partial<T>;
187
- DELETE?: boolean;
188
- WHERE?: WhereClause<T>;
189
- JOIN?: Join<T>;
190
- PAGINATION?: Pagination<T>;
191
+ export type iRestHooks<RestShortTableName extends string, RestTableInterface extends {
192
+ [key: string]: any;
193
+ }, PrimaryKey extends keyof RestTableInterface & string, CustomAndRequiredFields extends {
194
+ [key: string]: any;
195
+ } = any, RequestTableOverrides extends {
196
+ [key: string]: any;
197
+ } = {
198
+ [key in keyof RestTableInterface]: any;
199
+ }> = {
200
+ [Method in iRestMethods]: iRestReactiveLifecycle<Method, RestShortTableName, RestTableInterface, PrimaryKey, CustomAndRequiredFields, RequestTableOverrides>;
191
201
  };
192
- export type RequestQueryBody<RestTableInterfaces extends {
202
+ export interface iDynamicApiImport<RestData extends {
193
203
  [key: string]: any;
194
- }> = iAPI<RestTableInterfaces> | RequestGetPutDeleteBody;
195
- export declare function isPromise(x: any): boolean;
196
- interface iC6RestResponse<RestData> {
197
- rest: RestData;
198
- session?: any;
199
- sql?: any;
200
- }
201
- interface iChangeC6Data {
202
- rowCount: number;
203
- }
204
- export interface iDeleteC6RestResponse<RestData = any, RequestData = any> extends iChangeC6Data, iC6RestResponse<RestData> {
205
- deleted: boolean | number | string | RequestData;
206
- }
207
- export interface iPostC6RestResponse<RestData = any> extends iC6RestResponse<RestData> {
208
- created: boolean | number | string;
204
+ } = any> {
205
+ default: iRestApiFunctions<RestData>;
206
+ postState?: (response: AxiosResponse<iPostC6RestResponse<RestData>>, request: iAPI<any>, id: string | number | boolean) => void;
207
+ deleteState?: (response: AxiosResponse<iDeleteC6RestResponse<RestData>>, request: iAPI<any>) => void;
208
+ putState?: (response: AxiosResponse<iPutC6RestResponse<RestData>>, request: iAPI<any>) => void;
209
209
  }
210
- export interface iPutC6RestResponse<RestData = any, RequestData = any> extends iChangeC6Data, iC6RestResponse<RestData> {
211
- updated: boolean | number | string | RequestData;
210
+ export interface iRestApiFunctions<RestData extends {
211
+ [key: string]: any;
212
+ } = any> {
213
+ Delete: (request?: RequestQueryBody<'DELETE', RestData>) => apiReturn<iDeleteC6RestResponse<RestData>>;
214
+ Post: (request?: RequestQueryBody<'POST', RestData>) => apiReturn<iPostC6RestResponse<RestData>>;
215
+ Get: (request?: RequestQueryBody<'GET', RestData>) => apiReturn<iGetC6RestResponse<RestData>>;
216
+ Put: (request?: RequestQueryBody<'PUT', RestData>) => apiReturn<iPutC6RestResponse<RestData>>;
212
217
  }
213
218
  export interface iC6Object<RestShortTableName extends string = any, RestTableInterface extends {
214
219
  [key: string]: any;
@@ -223,23 +228,18 @@ export interface iC6Object<RestShortTableName extends string = any, RestTableInt
223
228
  IMPORT: (tableName: string) => Promise<iDynamicApiImport>;
224
229
  [key: string]: any;
225
230
  }
226
- export type iGetC6RestResponse<ResponseDataType, ResponseDataOverrides = {}> = iC6RestResponse<Modify<ResponseDataType, ResponseDataOverrides> | Modify<ResponseDataType, ResponseDataOverrides>[]>;
227
- export type apiReturn<Response> = null | undefined | AxiosPromise<Response> | (Response extends iPutC6RestResponse | iDeleteC6RestResponse | iPostC6RestResponse ? null : (() => apiReturn<Response>));
228
- export type DetermineResponseDataType<RequestMethod extends iRestMethods, RestTableInterface extends {
229
- [key: string]: any;
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 {
231
+ export interface tC6Tables<RestShortTableName extends string = any, RestTableInterface extends {
232
232
  [key: string]: any;
233
- } = any, PrimaryKey extends keyof RestTableInterface & string = any> {
234
- C6: iC6Object;
235
- axios?: AxiosInstance;
236
- restURL?: string;
237
- mysqlPool?: Pool;
238
- withCredentials?: boolean;
239
- restModel: iC6RestfulModel<RestShortTableName, RestTableInterface, PrimaryKey>;
240
- reactBootstrap?: CarbonReact<any, any>;
241
- requestMethod: iRestMethods;
242
- clearCache?: () => void;
243
- skipPrimaryCheck?: boolean;
233
+ } = any, PrimaryKey extends Extract<keyof RestTableInterface, string> = Extract<keyof RestTableInterface, string>> {
234
+ [key: string]: iC6RestfulModel<RestShortTableName, RestTableInterface, PrimaryKey> & {
235
+ [key: string]: any;
236
+ };
237
+ }
238
+ export interface tC6RestApi {
239
+ [key: string]: {
240
+ REST: iRestApiFunctions;
241
+ PUT: Function;
242
+ POST: Function;
243
+ DELETE: Function;
244
+ };
244
245
  }
245
- export {};