@carbonorm/carbonnode 3.0.0 → 3.0.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/builders/sqlBuilder.d.ts +3 -0
- package/dist/api/convertForRequestBody.d.ts +1 -1
- package/dist/api/executors/Executor.d.ts +18 -0
- package/dist/api/executors/HttpExecutor.d.ts +15 -0
- package/dist/api/executors/SqlExecutor.d.ts +11 -0
- package/dist/api/restRequest.d.ts +5 -164
- package/dist/api/types/dynamicFetching.d.ts +10 -0
- package/dist/api/types/modifyTypes.d.ts +9 -0
- package/dist/api/types/mysqlTypes.d.ts +4 -0
- package/dist/api/types/ormInterfaces.d.ts +223 -0
- package/dist/api/utils/apiHelpers.d.ts +9 -0
- package/dist/api/utils/cacheManager.d.ts +10 -0
- package/dist/api/utils/logger.d.ts +7 -0
- package/dist/api/utils/sortAndSerializeQueryObject.d.ts +1 -0
- package/dist/api/utils/testHelpers.d.ts +1 -0
- package/dist/api/utils/toastNotifier.d.ts +2 -0
- package/dist/index.cjs.js +614 -605
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +14 -2
- package/dist/index.esm.js +603 -607
- package/dist/index.esm.js.map +1 -1
- package/package.json +22 -6
- package/src/api/builders/sqlBuilder.ts +173 -0
- package/src/api/convertForRequestBody.ts +1 -2
- package/src/api/executors/Executor.ts +26 -0
- package/src/api/executors/HttpExecutor.ts +790 -0
- package/src/api/executors/SqlExecutor.ts +90 -0
- package/src/api/restRequest.ts +20 -1273
- package/src/api/types/dynamicFetching.ts +10 -0
- package/src/api/types/modifyTypes.ts +25 -0
- package/src/api/types/mysqlTypes.ts +33 -0
- package/src/api/types/ormInterfaces.ts +287 -0
- package/src/api/utils/apiHelpers.ts +83 -0
- package/src/api/utils/cacheManager.ts +67 -0
- package/src/api/utils/logger.ts +24 -0
- package/src/api/utils/sortAndSerializeQueryObject.ts +12 -0
- package/src/api/utils/testHelpers.ts +24 -0
- package/src/api/utils/toastNotifier.ts +11 -0
- package/src/index.ts +14 -2
- package/src/api/carbonSqlExecutor.ts +0 -279
- package/src/api/interfaces/ormInterfaces.ts +0 -87
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare function buildBooleanJoinedConditions(set: any, andMode?: boolean): string;
|
|
2
|
+
export declare function buildAggregateField(field: string | any[]): string;
|
|
3
|
+
export declare function buildSelectQuery<RestShortTableNames>(table: RestShortTableNames, primary: string | undefined, args: any, isSubSelect?: boolean): string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { iC6Object } from "
|
|
1
|
+
import { iC6Object } from "./types/ormInterfaces";
|
|
2
2
|
export default function <RestTableInterfaces extends {
|
|
3
3
|
[key: string]: any;
|
|
4
4
|
}>(restfulObject: RestTableInterfaces, tableName: string | string[], C6: iC6Object, regexErrorHandler?: (message: string) => void): {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { apiReturn, iAPI, iRest } from "@carbonorm/carbonnode";
|
|
2
|
+
import { Modify } from "../types/modifyTypes";
|
|
3
|
+
export declare abstract class Executor<CustomAndRequiredFields extends {
|
|
4
|
+
[key: string]: any;
|
|
5
|
+
}, // CustomAndRequiredFields
|
|
6
|
+
RestTableInterfaces extends {
|
|
7
|
+
[key: string]: any;
|
|
8
|
+
}, // RestTableInterfaces
|
|
9
|
+
RequestTableOverrides = {
|
|
10
|
+
[key in keyof RestTableInterfaces]: any;
|
|
11
|
+
}, // RequestTableOverrides
|
|
12
|
+
ResponseDataType = any, // ResponseDataType
|
|
13
|
+
RestShortTableNames extends string = ""> {
|
|
14
|
+
protected config: iRest<CustomAndRequiredFields, RestTableInterfaces, RequestTableOverrides, ResponseDataType, RestShortTableNames>;
|
|
15
|
+
protected request: iAPI<Modify<RestTableInterfaces, RequestTableOverrides>> & CustomAndRequiredFields;
|
|
16
|
+
constructor(config: iRest<CustomAndRequiredFields, RestTableInterfaces, RequestTableOverrides, ResponseDataType, RestShortTableNames>, request?: iAPI<Modify<RestTableInterfaces, RequestTableOverrides>> & CustomAndRequiredFields);
|
|
17
|
+
abstract execute(): Promise<apiReturn<ResponseDataType>>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { apiReturn } from "../types/ormInterfaces";
|
|
2
|
+
import { Executor } from "./Executor";
|
|
3
|
+
export declare class HttpExecutor<CustomAndRequiredFields extends {
|
|
4
|
+
[key: string]: any;
|
|
5
|
+
}, // CustomAndRequiredFields
|
|
6
|
+
RestTableInterfaces extends {
|
|
7
|
+
[key: string]: any;
|
|
8
|
+
}, // RestTableInterfaces
|
|
9
|
+
RequestTableOverrides = {
|
|
10
|
+
[key in keyof RestTableInterfaces]: any;
|
|
11
|
+
}, // RequestTableOverrides
|
|
12
|
+
ResponseDataType = any, // ResponseDataType
|
|
13
|
+
RestShortTableNames extends string = ""> extends Executor<CustomAndRequiredFields, RestTableInterfaces, RequestTableOverrides, ResponseDataType, RestShortTableNames> {
|
|
14
|
+
execute(): Promise<apiReturn<ResponseDataType>>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { apiReturn } from "@carbonorm/carbonnode";
|
|
2
|
+
import { RowDataPacket } from 'mysql2/promise';
|
|
3
|
+
import { Executor } from "./Executor";
|
|
4
|
+
export declare class SqlExecutor<CustomAndRequiredFields extends object, RestTableInterfaces extends object, RequestTableOverrides extends object, ResponseDataType, RestShortTableNames extends string> extends Executor<CustomAndRequiredFields, RestTableInterfaces, RequestTableOverrides, ResponseDataType, RestShortTableNames> {
|
|
5
|
+
execute(): Promise<apiReturn<ResponseDataType>>;
|
|
6
|
+
private withConnection;
|
|
7
|
+
select<RestShortTableNames>(table: RestShortTableNames, primary: string | undefined, args: any): Promise<RowDataPacket[]>;
|
|
8
|
+
insert<RestShortTableNames>(table: RestShortTableNames, data: any): Promise<import("mysql2/promise").QueryResult>;
|
|
9
|
+
update<RestShortTableNames>(table: RestShortTableNames, primary: string | undefined, data: any): Promise<import("mysql2/promise").QueryResult>;
|
|
10
|
+
delete<RestShortTableNames>(table: RestShortTableNames, primary: string | undefined, args: any): Promise<import("mysql2/promise").QueryResult>;
|
|
11
|
+
}
|
|
@@ -1,171 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { Pool } from "mysql2/promise";
|
|
4
|
-
export declare function TestRestfulResponse(response: AxiosResponse | any, success: ((r: AxiosResponse) => (string | void)) | string | undefined, error: ((r: AxiosResponse) => (string | void)) | string | undefined): string | boolean | number;
|
|
5
|
-
export declare function removeInvalidKeys<iRestObject>(request: any, c6Tables: {
|
|
6
|
-
[key: string]: (iC6RestfulModel & {
|
|
7
|
-
[key: string]: any;
|
|
8
|
-
});
|
|
9
|
-
}): iRestObject;
|
|
10
|
-
export type Modify<T, R> = Omit<T, keyof R> & R;
|
|
11
|
-
export type ModifyDeep<A, B extends DeepPartialAny<A>> = {
|
|
12
|
-
[K in keyof A | keyof B]?: K extends keyof A ? K extends keyof B ? A[K] extends AnyObject ? B[K] extends AnyObject ? ModifyDeep<A[K], B[K]> : B[K] : B[K] : A[K] : B[K];
|
|
13
|
-
};
|
|
14
|
-
type AnyObject = Record<string, any>;
|
|
15
|
-
type DeepPartialAny<T> = {
|
|
16
|
-
[P in keyof T]?: T[P] extends AnyObject ? DeepPartialAny<T[P]> : any;
|
|
17
|
-
};
|
|
18
|
-
export declare enum eFetchDependencies {
|
|
19
|
-
NONE = 0,
|
|
20
|
-
REFERENCED = 1,
|
|
21
|
-
CHILDREN = 1,
|
|
22
|
-
REFERENCES = 2,
|
|
23
|
-
PARENTS = 2,
|
|
24
|
-
ALL = 3,
|
|
25
|
-
C6ENTITY = 4,
|
|
26
|
-
RECURSIVE = 8
|
|
27
|
-
}
|
|
28
|
-
export type iAPI<RestTableInterfaces extends {
|
|
29
|
-
[key: string]: any;
|
|
30
|
-
}> = RestTableInterfaces & {
|
|
31
|
-
dataInsertMultipleRows?: RestTableInterfaces[];
|
|
32
|
-
cacheResults?: boolean;
|
|
33
|
-
fetchDependencies?: number | eFetchDependencies | Awaited<apiReturn<iGetC6RestResponse<any>>>[];
|
|
34
|
-
debug?: boolean;
|
|
35
|
-
success?: string | ((r: AxiosResponse) => (string | void));
|
|
36
|
-
error?: string | ((r: AxiosResponse) => (string | void));
|
|
37
|
-
};
|
|
38
|
-
export declare function checkAllRequestsComplete(): true | (string[]);
|
|
39
|
-
interface iClearCache {
|
|
40
|
-
ignoreWarning: boolean;
|
|
41
|
-
}
|
|
42
|
-
export declare function clearCache(props?: iClearCache): void;
|
|
43
|
-
export declare function removePrefixIfExists(tableName: string, prefix: string): string;
|
|
1
|
+
import { Modify } from "./types/modifyTypes";
|
|
2
|
+
import { apiReturn, iAPI, iRest } from "./types/ormInterfaces";
|
|
44
3
|
/**
|
|
45
|
-
*
|
|
46
|
-
|
|
47
|
-
* Our api returns a zero argument function iff the method is get and the previous request reached the predefined limit.
|
|
48
|
-
* This function can be aliased as GetNextPageOfResults(). If the end is reached undefined will be returned.
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* For POST, PUT, and DELETE requests one can expect the primary key of the new or modified index, or a boolean success
|
|
52
|
-
* indication if no primary key exists.
|
|
53
|
-
**/
|
|
54
|
-
export declare const POST = "POST";
|
|
55
|
-
export declare const PUT = "PUT";
|
|
56
|
-
export declare const GET = "GET";
|
|
57
|
-
export declare const DELETE = "DELETE";
|
|
58
|
-
export type iRestMethods = 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
59
|
-
export type SQLFunction = 'COUNT' | 'GROUP_CONCAT' | 'MAX' | 'MIN' | 'SUM' | 'DISTINCT';
|
|
60
|
-
export type SQLComparisonOperator = '=' | '!=' | '<' | '<=' | '>' | '>=' | 'IN' | 'NOT IN' | 'LIKE' | 'IS NULL' | 'IS NOT NULL' | 'BETWEEN' | 'LESS_THAN' | 'GREATER_THAN';
|
|
61
|
-
export type JoinType = 'INNER' | 'LEFT_OUTER' | 'RIGHT_OUTER';
|
|
62
|
-
export type OrderDirection = 'ASC' | 'DESC';
|
|
63
|
-
export type SubSelect<T = any> = {
|
|
64
|
-
subSelect: true;
|
|
65
|
-
table: string;
|
|
66
|
-
args: RequestGetPutDeleteBody<T>;
|
|
67
|
-
alias: string;
|
|
68
|
-
};
|
|
69
|
-
export type SelectField<T = any> = keyof T | [keyof T, 'AS', string] | [SQLFunction, keyof T] | [SQLFunction, keyof T, string] | SubSelect<T>;
|
|
70
|
-
export type WhereClause<T = any> = Partial<T> | LogicalGroup<T> | ComparisonClause<T>;
|
|
71
|
-
export type LogicalGroup<T = any> = {
|
|
72
|
-
[logicalGroup: string]: Array<WhereClause<T>>;
|
|
73
|
-
};
|
|
74
|
-
export type ComparisonClause<T = any> = [keyof T, SQLComparisonOperator, any];
|
|
75
|
-
export type JoinTableCondition<T = any> = Partial<T> | WhereClause<T>[] | ComparisonClause<T>[];
|
|
76
|
-
export type JoinClause<T = any> = {
|
|
77
|
-
[table: string]: JoinTableCondition<T>;
|
|
78
|
-
};
|
|
79
|
-
export type Join<T = any> = {
|
|
80
|
-
[K in JoinType]?: JoinClause<T>;
|
|
81
|
-
};
|
|
82
|
-
export type Pagination<T = any> = {
|
|
83
|
-
PAGE?: number;
|
|
84
|
-
LIMIT?: number | null;
|
|
85
|
-
ORDER?: Partial<Record<keyof T, OrderDirection>>;
|
|
86
|
-
};
|
|
87
|
-
export type RequestGetPutDeleteBody<T = any> = {
|
|
88
|
-
SELECT?: SelectField<T>[];
|
|
89
|
-
UPDATE?: Partial<T>;
|
|
90
|
-
DELETE?: boolean;
|
|
91
|
-
WHERE?: WhereClause<T>;
|
|
92
|
-
JOIN?: Join<T>;
|
|
93
|
-
PAGINATION?: Pagination<T>;
|
|
94
|
-
};
|
|
95
|
-
export type RequestQueryBody<RestTableInterfaces extends {
|
|
96
|
-
[key: string]: any;
|
|
97
|
-
}> = iAPI<RestTableInterfaces> | RequestGetPutDeleteBody;
|
|
98
|
-
export declare function isPromise(x: any): boolean;
|
|
99
|
-
interface iC6RestResponse<RestData> {
|
|
100
|
-
rest: RestData;
|
|
101
|
-
session?: any;
|
|
102
|
-
sql?: any;
|
|
103
|
-
}
|
|
104
|
-
interface iChangeC6Data {
|
|
105
|
-
rowCount: number;
|
|
106
|
-
}
|
|
107
|
-
export interface iDeleteC6RestResponse<RestData = any, RequestData = any> extends iChangeC6Data, iC6RestResponse<RestData> {
|
|
108
|
-
deleted: boolean | number | string | RequestData;
|
|
109
|
-
}
|
|
110
|
-
export interface iPostC6RestResponse<RestData = any> extends iC6RestResponse<RestData> {
|
|
111
|
-
created: boolean | number | string;
|
|
112
|
-
}
|
|
113
|
-
export interface iPutC6RestResponse<RestData = any, RequestData = any> extends iChangeC6Data, iC6RestResponse<RestData> {
|
|
114
|
-
updated: boolean | number | string | RequestData;
|
|
115
|
-
}
|
|
116
|
-
export interface iC6Object {
|
|
117
|
-
C6VERSION: string;
|
|
118
|
-
TABLES: {
|
|
119
|
-
[key: string]: iC6RestfulModel & {
|
|
120
|
-
[key: string]: string | number;
|
|
121
|
-
};
|
|
122
|
-
};
|
|
123
|
-
PREFIX: string;
|
|
124
|
-
IMPORT: (tableName: string) => Promise<iDynamicApiImport>;
|
|
125
|
-
[key: string]: any;
|
|
126
|
-
}
|
|
127
|
-
export type iGetC6RestResponse<ResponseDataType, ResponseDataOverrides = {}> = iC6RestResponse<Modify<ResponseDataType, ResponseDataOverrides> | Modify<ResponseDataType, ResponseDataOverrides>[]>;
|
|
128
|
-
export type apiReturn<Response> = null | undefined | AxiosPromise<Response> | (Response extends iPutC6RestResponse | iDeleteC6RestResponse | iPostC6RestResponse ? null : (() => apiReturn<Response>));
|
|
129
|
-
interface iRest<CustomAndRequiredFields extends {
|
|
130
|
-
[key: string]: any;
|
|
131
|
-
}, RestTableInterfaces extends {
|
|
132
|
-
[key: string]: any;
|
|
133
|
-
}, RequestTableOverrides = {
|
|
134
|
-
[key in keyof RestTableInterfaces]: any;
|
|
135
|
-
}, ResponseDataType = any, RestShortTableNames extends string = any> {
|
|
136
|
-
C6: iC6Object;
|
|
137
|
-
axios?: AxiosInstance;
|
|
138
|
-
restURL?: string;
|
|
139
|
-
mysqlPool?: Pool;
|
|
140
|
-
withCredentials?: boolean;
|
|
141
|
-
tableName: RestShortTableNames | RestShortTableNames[];
|
|
142
|
-
requestMethod: iRestMethods;
|
|
143
|
-
clearCache?: () => void;
|
|
144
|
-
skipPrimaryCheck?: boolean;
|
|
145
|
-
queryCallback: RequestQueryBody<Modify<RestTableInterfaces, RequestTableOverrides>> | ((request: iAPI<Modify<RestTableInterfaces, RequestTableOverrides>> & CustomAndRequiredFields) => (null | undefined | RequestQueryBody<Modify<RestTableInterfaces, RequestTableOverrides>>));
|
|
146
|
-
responseCallback?: (response: AxiosResponse<ResponseDataType>, request: iAPI<Modify<RestTableInterfaces, RequestTableOverrides>> & CustomAndRequiredFields, success: (ResponseDataType extends iPutC6RestResponse | iDeleteC6RestResponse ? RequestQueryBody<Modify<RestTableInterfaces, RequestTableOverrides>> : string) | string | number | boolean) => any;
|
|
147
|
-
}
|
|
148
|
-
export declare function extendedTypeHints<RestTableInterfaces extends {
|
|
149
|
-
[key: string]: any;
|
|
150
|
-
}, RestShortTableNames extends string>(): <CustomAndRequiredFields extends {
|
|
151
|
-
[key: string]: any;
|
|
152
|
-
} = any, RequestTableTypes extends RestTableInterfaces = any, RequestTableOverrides extends {
|
|
153
|
-
[key: string]: any;
|
|
154
|
-
} = any, ResponseDataType extends {
|
|
155
|
-
[key: string]: any;
|
|
156
|
-
} = any>(argv: any) => (request?: Omit<RequestTableTypes, keyof RequestTableOverrides> & RequestTableOverrides & {
|
|
157
|
-
dataInsertMultipleRows?: Modify<RequestTableTypes, RequestTableOverrides>[] | undefined;
|
|
158
|
-
cacheResults?: boolean;
|
|
159
|
-
fetchDependencies?: number | eFetchDependencies | Awaited<apiReturn<iGetC6RestResponse<any>>>[];
|
|
160
|
-
debug?: boolean;
|
|
161
|
-
success?: string | ((r: AxiosResponse) => (string | void));
|
|
162
|
-
error?: string | ((r: AxiosResponse) => (string | void));
|
|
163
|
-
} & CustomAndRequiredFields) => Promise<(ResponseDataType extends iPutC6RestResponse<any, any> | iDeleteC6RestResponse<any, any> | iPostC6RestResponse<any> ? null : () => apiReturn<ResponseDataType>) | AxiosResponse<ResponseDataType, any> | null | undefined>;
|
|
4
|
+
* Facade: routes API calls to SQL or HTTP executors based on runtime context.
|
|
5
|
+
*/
|
|
164
6
|
export default function restRequest<CustomAndRequiredFields extends {
|
|
165
7
|
[key: string]: any;
|
|
166
8
|
} = any, RestTableInterfaces extends {
|
|
167
9
|
[key: string]: any;
|
|
168
10
|
} = any, RequestTableOverrides extends {
|
|
169
11
|
[key: string]: any;
|
|
170
|
-
} = any, ResponseDataType = any, RestShortTableNames extends string = any>(
|
|
171
|
-
export {};
|
|
12
|
+
} = any, ResponseDataType = any, RestShortTableNames extends string = any>(config: iRest<CustomAndRequiredFields, RestTableInterfaces, RequestTableOverrides, ResponseDataType, RestShortTableNames>): (request?: iAPI<Modify<RestTableInterfaces, RequestTableOverrides>> & CustomAndRequiredFields) => Promise<apiReturn<ResponseDataType>>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type Modify<T, R> = Omit<T, keyof R> & R;
|
|
2
|
+
export type ModifyDeep<A, B extends DeepPartialAny<A>> = {
|
|
3
|
+
[K in keyof A | keyof B]?: K extends keyof A ? K extends keyof B ? A[K] extends AnyObject ? B[K] extends AnyObject ? ModifyDeep<A[K], B[K]> : B[K] : B[K] : A[K] : B[K];
|
|
4
|
+
};
|
|
5
|
+
type AnyObject = Record<string, any>;
|
|
6
|
+
type DeepPartialAny<T> = {
|
|
7
|
+
[P in keyof T]?: T[P] extends AnyObject ? DeepPartialAny<T[P]> : any;
|
|
8
|
+
};
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type SQLFunction = 'COUNT' | 'GROUP_CONCAT' | 'MAX' | 'MIN' | 'SUM' | 'DISTINCT';
|
|
2
|
+
export type SQLComparisonOperator = '=' | '!=' | '<' | '<=' | '>' | '>=' | 'IN' | 'NOT IN' | 'LIKE' | 'IS NULL' | 'IS NOT NULL' | 'BETWEEN' | 'LESS_THAN' | 'GREATER_THAN';
|
|
3
|
+
export type JoinType = 'INNER' | 'LEFT_OUTER' | 'RIGHT_OUTER';
|
|
4
|
+
export type OrderDirection = 'ASC' | 'DESC';
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { AxiosInstance, AxiosPromise, AxiosResponse } from "axios";
|
|
2
|
+
import { Pool } from "mysql2/promise";
|
|
3
|
+
import { eFetchDependencies } from "./dynamicFetching";
|
|
4
|
+
import { Modify } from "./modifyTypes";
|
|
5
|
+
import { JoinType, OrderDirection, SQLComparisonOperator, SQLFunction } from "./mysqlTypes";
|
|
6
|
+
export interface stringMap {
|
|
7
|
+
[key: string]: string;
|
|
8
|
+
}
|
|
9
|
+
export interface stringNumberMap {
|
|
10
|
+
[key: string]: string | number;
|
|
11
|
+
}
|
|
12
|
+
export interface RegExpMap {
|
|
13
|
+
[key: string]: RegExp | RegExpMap;
|
|
14
|
+
}
|
|
15
|
+
export interface complexMap {
|
|
16
|
+
[key: string]: stringMap | stringNumberMap | stringMap[] | RegExpMap;
|
|
17
|
+
}
|
|
18
|
+
export interface iTypeValidation {
|
|
19
|
+
MYSQL_TYPE: string;
|
|
20
|
+
MAX_LENGTH: string;
|
|
21
|
+
AUTO_INCREMENT: boolean;
|
|
22
|
+
SKIP_COLUMN_IN_POST: boolean;
|
|
23
|
+
}
|
|
24
|
+
export type iRestReactiveLifecycle<T extends RequestGetPutDeleteBody> = {
|
|
25
|
+
beforeProcessing?: (args: {
|
|
26
|
+
request: T[];
|
|
27
|
+
requestMeta?: any;
|
|
28
|
+
}) => void | Promise<void>;
|
|
29
|
+
beforeExecution?: (args: {
|
|
30
|
+
request: T[];
|
|
31
|
+
requestMeta?: any;
|
|
32
|
+
}) => void | Promise<void>;
|
|
33
|
+
afterExecution?: (args: {
|
|
34
|
+
response: T[];
|
|
35
|
+
request: T[];
|
|
36
|
+
responseMeta?: any;
|
|
37
|
+
}) => void | Promise<void>;
|
|
38
|
+
afterCommit?: (args: {
|
|
39
|
+
response: T[];
|
|
40
|
+
request: T[];
|
|
41
|
+
responseMeta?: any;
|
|
42
|
+
}) => void | Promise<void>;
|
|
43
|
+
};
|
|
44
|
+
export interface iConstraint {
|
|
45
|
+
TABLE: string;
|
|
46
|
+
COLUMN: string;
|
|
47
|
+
CONSTRAINT: string;
|
|
48
|
+
}
|
|
49
|
+
export interface iC6RestfulModel<RestShortTableNames extends string = string> {
|
|
50
|
+
TABLE_NAME: RestShortTableNames;
|
|
51
|
+
PRIMARY: string[];
|
|
52
|
+
PRIMARY_SHORT: string[];
|
|
53
|
+
COLUMNS: stringMap;
|
|
54
|
+
LIFECYCLE_HOOKS: iRestReactiveLifecycle<RequestGetPutDeleteBody>[];
|
|
55
|
+
REGEX_VALIDATION: RegExpMap;
|
|
56
|
+
TYPE_VALIDATION: {
|
|
57
|
+
[key: string]: iTypeValidation;
|
|
58
|
+
};
|
|
59
|
+
TABLE_REFERENCES: {
|
|
60
|
+
[columnName: string]: iConstraint[];
|
|
61
|
+
};
|
|
62
|
+
TABLE_REFERENCED_BY: {
|
|
63
|
+
[columnName: string]: iConstraint[];
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
export interface iRestApiFunctions<RestData = any> {
|
|
67
|
+
Delete: (request?: (iAPI<any> & any)) => apiReturn<iDeleteC6RestResponse<RestData>>;
|
|
68
|
+
Post: (request?: (iAPI<any> & any)) => apiReturn<iPostC6RestResponse<RestData>>;
|
|
69
|
+
Get: (request?: (iAPI<any> & any)) => apiReturn<iGetC6RestResponse<RestData>>;
|
|
70
|
+
Put: (request?: (iAPI<any> & any)) => apiReturn<iPutC6RestResponse<RestData>>;
|
|
71
|
+
}
|
|
72
|
+
export interface iDynamicApiImport<RestData = any> {
|
|
73
|
+
default: iRestApiFunctions<RestData>;
|
|
74
|
+
postState?: (response: AxiosResponse<iPostC6RestResponse<RestData>>, request: iAPI<any>, id: string | number | boolean) => void;
|
|
75
|
+
deleteState?: (response: AxiosResponse<iDeleteC6RestResponse<RestData>>, request: iAPI<any>) => void;
|
|
76
|
+
putState?: (response: AxiosResponse<iPutC6RestResponse<RestData>>, request: iAPI<any>) => void;
|
|
77
|
+
}
|
|
78
|
+
export interface tC6Tables {
|
|
79
|
+
[key: string]: (iC6RestfulModel & {
|
|
80
|
+
[key: string]: any;
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
export interface tC6RestApi {
|
|
84
|
+
[key: string]: {
|
|
85
|
+
REST: iRestApiFunctions;
|
|
86
|
+
PUT: Function;
|
|
87
|
+
POST: Function;
|
|
88
|
+
DELETE: Function;
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
export type iAPI<RestTableInterfaces extends {
|
|
92
|
+
[key: string]: any;
|
|
93
|
+
}> = RestTableInterfaces & {
|
|
94
|
+
dataInsertMultipleRows?: RestTableInterfaces[];
|
|
95
|
+
cacheResults?: boolean;
|
|
96
|
+
fetchDependencies?: number | eFetchDependencies | Awaited<apiReturn<iGetC6RestResponse<any>>>[];
|
|
97
|
+
debug?: boolean;
|
|
98
|
+
success?: string | ((r: AxiosResponse) => (string | void));
|
|
99
|
+
error?: string | ((r: AxiosResponse) => (string | void));
|
|
100
|
+
};
|
|
101
|
+
export interface iCacheAPI<ResponseDataType = any> {
|
|
102
|
+
requestArgumentsSerialized: string;
|
|
103
|
+
request: AxiosPromise<ResponseDataType>;
|
|
104
|
+
response?: AxiosResponse;
|
|
105
|
+
final?: boolean;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* the first argument ....
|
|
109
|
+
*
|
|
110
|
+
* Our api returns a zero argument function iff the method is get and the previous request reached the predefined limit.
|
|
111
|
+
* This function can be aliased as GetNextPageOfResults(). If the end is reached undefined will be returned.
|
|
112
|
+
*
|
|
113
|
+
*
|
|
114
|
+
* For POST, PUT, and DELETE requests one can expect the primary key of the new or modified index, or a boolean success
|
|
115
|
+
* indication if no primary key exists.
|
|
116
|
+
**/
|
|
117
|
+
export declare const POST = "POST";
|
|
118
|
+
export declare const PUT = "PUT";
|
|
119
|
+
export declare const GET = "GET";
|
|
120
|
+
export declare const DELETE = "DELETE";
|
|
121
|
+
export type iRestMethods = 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
122
|
+
export type SubSelect<T = any> = {
|
|
123
|
+
subSelect: true;
|
|
124
|
+
table: string;
|
|
125
|
+
args: RequestGetPutDeleteBody<T>;
|
|
126
|
+
alias: string;
|
|
127
|
+
};
|
|
128
|
+
export type SelectField<T = any> = keyof T | [keyof T, 'AS', string] | [SQLFunction, keyof T] | [SQLFunction, keyof T, string] | SubSelect<T>;
|
|
129
|
+
export type WhereClause<T = any> = Partial<T> | LogicalGroup<T> | ComparisonClause<T>;
|
|
130
|
+
export type LogicalGroup<T = any> = {
|
|
131
|
+
[logicalGroup: string]: Array<WhereClause<T>>;
|
|
132
|
+
};
|
|
133
|
+
export type ComparisonClause<T = any> = [keyof T, SQLComparisonOperator, any];
|
|
134
|
+
export type JoinTableCondition<T = any> = Partial<T> | WhereClause<T>[] | ComparisonClause<T>[];
|
|
135
|
+
export type JoinClause<T = any> = {
|
|
136
|
+
[table: string]: JoinTableCondition<T>;
|
|
137
|
+
};
|
|
138
|
+
export type Join<T = any> = {
|
|
139
|
+
[K in JoinType]?: JoinClause<T>;
|
|
140
|
+
};
|
|
141
|
+
export type Pagination<T = any> = {
|
|
142
|
+
PAGE?: number;
|
|
143
|
+
LIMIT?: number | null;
|
|
144
|
+
ORDER?: Partial<Record<keyof T, OrderDirection>>;
|
|
145
|
+
};
|
|
146
|
+
export type RequestGetPutDeleteBody<T = any> = {
|
|
147
|
+
SELECT?: SelectField<T>[];
|
|
148
|
+
UPDATE?: Partial<T>;
|
|
149
|
+
DELETE?: boolean;
|
|
150
|
+
WHERE?: WhereClause<T>;
|
|
151
|
+
JOIN?: Join<T>;
|
|
152
|
+
PAGINATION?: Pagination<T>;
|
|
153
|
+
};
|
|
154
|
+
export type RequestQueryBody<RestTableInterfaces extends {
|
|
155
|
+
[key: string]: any;
|
|
156
|
+
}> = iAPI<RestTableInterfaces> | RequestGetPutDeleteBody;
|
|
157
|
+
export declare function isPromise(x: any): boolean;
|
|
158
|
+
interface iC6RestResponse<RestData> {
|
|
159
|
+
rest: RestData;
|
|
160
|
+
session?: any;
|
|
161
|
+
sql?: any;
|
|
162
|
+
}
|
|
163
|
+
interface iChangeC6Data {
|
|
164
|
+
rowCount: number;
|
|
165
|
+
}
|
|
166
|
+
export interface iDeleteC6RestResponse<RestData = any, RequestData = any> extends iChangeC6Data, iC6RestResponse<RestData> {
|
|
167
|
+
deleted: boolean | number | string | RequestData;
|
|
168
|
+
}
|
|
169
|
+
export interface iPostC6RestResponse<RestData = any> extends iC6RestResponse<RestData> {
|
|
170
|
+
created: boolean | number | string;
|
|
171
|
+
}
|
|
172
|
+
export interface iPutC6RestResponse<RestData = any, RequestData = any> extends iChangeC6Data, iC6RestResponse<RestData> {
|
|
173
|
+
updated: boolean | number | string | RequestData;
|
|
174
|
+
}
|
|
175
|
+
export interface iC6Object {
|
|
176
|
+
C6VERSION: string;
|
|
177
|
+
TABLES: {
|
|
178
|
+
[key: string]: iC6RestfulModel & {
|
|
179
|
+
[key: string]: string | number;
|
|
180
|
+
};
|
|
181
|
+
};
|
|
182
|
+
PREFIX: string;
|
|
183
|
+
IMPORT: (tableName: string) => Promise<iDynamicApiImport>;
|
|
184
|
+
[key: string]: any;
|
|
185
|
+
}
|
|
186
|
+
export type iGetC6RestResponse<ResponseDataType, ResponseDataOverrides = {}> = iC6RestResponse<Modify<ResponseDataType, ResponseDataOverrides> | Modify<ResponseDataType, ResponseDataOverrides>[]>;
|
|
187
|
+
export type apiReturn<Response> = null | undefined | AxiosPromise<Response> | (Response extends iPutC6RestResponse | iDeleteC6RestResponse | iPostC6RestResponse ? null : (() => apiReturn<Response>));
|
|
188
|
+
export interface iRest<CustomAndRequiredFields extends {
|
|
189
|
+
[key: string]: any;
|
|
190
|
+
}, RestTableInterfaces extends {
|
|
191
|
+
[key: string]: any;
|
|
192
|
+
}, RequestTableOverrides = {
|
|
193
|
+
[key in keyof RestTableInterfaces]: any;
|
|
194
|
+
}, ResponseDataType = any, RestShortTableNames extends string = any> {
|
|
195
|
+
C6: iC6Object;
|
|
196
|
+
axios?: AxiosInstance;
|
|
197
|
+
restURL?: string;
|
|
198
|
+
mysqlPool?: Pool;
|
|
199
|
+
withCredentials?: boolean;
|
|
200
|
+
tableName: RestShortTableNames | RestShortTableNames[];
|
|
201
|
+
requestMethod: iRestMethods;
|
|
202
|
+
clearCache?: () => void;
|
|
203
|
+
skipPrimaryCheck?: boolean;
|
|
204
|
+
queryCallback: RequestQueryBody<Modify<RestTableInterfaces, RequestTableOverrides>> | ((request: iAPI<Modify<RestTableInterfaces, RequestTableOverrides>> & CustomAndRequiredFields) => (null | undefined | RequestQueryBody<Modify<RestTableInterfaces, RequestTableOverrides>>));
|
|
205
|
+
responseCallback?: (response: AxiosResponse<ResponseDataType>, request: iAPI<Modify<RestTableInterfaces, RequestTableOverrides>> & CustomAndRequiredFields, success: (ResponseDataType extends iPutC6RestResponse | iDeleteC6RestResponse ? RequestQueryBody<Modify<RestTableInterfaces, RequestTableOverrides>> : string) | string | number | boolean) => any;
|
|
206
|
+
}
|
|
207
|
+
export declare function extendedTypeHints<RestTableInterfaces extends {
|
|
208
|
+
[key: string]: any;
|
|
209
|
+
}, RestShortTableNames extends string>(): <CustomAndRequiredFields extends {
|
|
210
|
+
[key: string]: any;
|
|
211
|
+
} = any, RequestTableTypes extends RestTableInterfaces = any, RequestTableOverrides extends {
|
|
212
|
+
[key: string]: any;
|
|
213
|
+
} = any, ResponseDataType extends {
|
|
214
|
+
[key: string]: any;
|
|
215
|
+
} = any>(argv: any) => (request?: Omit<RequestTableTypes, keyof RequestTableOverrides> & RequestTableOverrides & {
|
|
216
|
+
dataInsertMultipleRows?: Modify<RequestTableTypes, RequestTableOverrides>[] | undefined;
|
|
217
|
+
cacheResults?: boolean;
|
|
218
|
+
fetchDependencies?: number | eFetchDependencies | Awaited<apiReturn<iGetC6RestResponse<any>>>[];
|
|
219
|
+
debug?: boolean;
|
|
220
|
+
success?: string | ((r: AxiosResponse) => (string | void));
|
|
221
|
+
error?: string | ((r: AxiosResponse) => (string | void));
|
|
222
|
+
} & CustomAndRequiredFields) => Promise<apiReturn<ResponseDataType>>;
|
|
223
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AxiosResponse } from "axios";
|
|
2
|
+
import { iC6RestfulModel } from "../types/ormInterfaces";
|
|
3
|
+
export declare function TestRestfulResponse(response: AxiosResponse | any, success: ((r: AxiosResponse) => (string | void)) | string | undefined, error: ((r: AxiosResponse) => (string | void)) | string | undefined): string | boolean | number;
|
|
4
|
+
export declare function removePrefixIfExists(tableName: string, prefix: string): string;
|
|
5
|
+
export declare function removeInvalidKeys<iRestObject>(request: any, c6Tables: {
|
|
6
|
+
[key: string]: (iC6RestfulModel & {
|
|
7
|
+
[key: string]: any;
|
|
8
|
+
});
|
|
9
|
+
}): iRestObject;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AxiosPromise } from "axios";
|
|
2
|
+
import { iCacheAPI } from "api/types/ormInterfaces";
|
|
3
|
+
export declare let apiRequestCache: iCacheAPI[];
|
|
4
|
+
export declare let userCustomClearCache: (() => void)[];
|
|
5
|
+
interface iClearCache {
|
|
6
|
+
ignoreWarning: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare function clearCache(props?: iClearCache): void;
|
|
9
|
+
export declare function checkCache<ResponseDataType = any, RestShortTableNames = string>(cacheResult: iCacheAPI<ResponseDataType>, requestMethod: string, tableName: RestShortTableNames | RestShortTableNames[], request: any): false | undefined | null | AxiosPromise<ResponseDataType>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Conditionally group a log if verbose.
|
|
3
|
+
*/
|
|
4
|
+
export declare function group(title: string, data?: any): void;
|
|
5
|
+
export declare function info(message: string, ...optional: any[]): void;
|
|
6
|
+
export declare function warn(message: string, ...optional: any[]): void;
|
|
7
|
+
export declare function error(message: string, ...optional: any[]): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function sortAndSerializeQueryObject(tables: String, query: Object): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function checkAllRequestsComplete(): true | (string[]);
|