@carbonorm/carbonnode 3.0.0 → 3.0.2

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.
Files changed (47) hide show
  1. package/dist/api/builders/sqlBuilder.d.ts +3 -0
  2. package/dist/api/convertForRequestBody.d.ts +1 -1
  3. package/dist/api/executors/Executor.d.ts +16 -0
  4. package/dist/api/executors/HttpExecutor.d.ts +13 -0
  5. package/dist/api/executors/SqlExecutor.d.ts +19 -0
  6. package/dist/api/restRequest.d.ts +9 -166
  7. package/dist/api/types/dynamicFetching.d.ts +10 -0
  8. package/dist/api/types/modifyTypes.d.ts +9 -0
  9. package/dist/api/types/mysqlTypes.d.ts +4 -0
  10. package/dist/api/types/ormInterfaces.d.ts +219 -0
  11. package/dist/api/utils/apiHelpers.d.ts +9 -0
  12. package/dist/api/utils/cacheManager.d.ts +10 -0
  13. package/dist/api/utils/determineRuntimeJsType.d.ts +5 -0
  14. package/dist/api/utils/logger.d.ts +7 -0
  15. package/dist/api/utils/sortAndSerializeQueryObject.d.ts +1 -0
  16. package/dist/api/utils/testHelpers.d.ts +1 -0
  17. package/dist/api/utils/toastNotifier.d.ts +2 -0
  18. package/dist/index.cjs.js +665 -614
  19. package/dist/index.cjs.js.map +1 -1
  20. package/dist/index.d.ts +15 -2
  21. package/dist/index.esm.js +655 -618
  22. package/dist/index.esm.js.map +1 -1
  23. package/package.json +22 -6
  24. package/scripts/assets/handlebars/C6.ts.handlebars +13 -5
  25. package/scripts/assets/handlebars/Table.ts.handlebars +44 -12
  26. package/scripts/generateRestBindings.cjs +1 -1
  27. package/scripts/generateRestBindings.ts +1 -1
  28. package/src/api/builders/sqlBuilder.ts +173 -0
  29. package/src/api/convertForRequestBody.ts +2 -3
  30. package/src/api/executors/Executor.ts +28 -0
  31. package/src/api/executors/HttpExecutor.ts +794 -0
  32. package/src/api/executors/SqlExecutor.ts +104 -0
  33. package/src/api/restRequest.ts +50 -1287
  34. package/src/api/types/dynamicFetching.ts +10 -0
  35. package/src/api/types/modifyTypes.ts +25 -0
  36. package/src/api/types/mysqlTypes.ts +33 -0
  37. package/src/api/types/ormInterfaces.ts +310 -0
  38. package/src/api/utils/apiHelpers.ts +82 -0
  39. package/src/api/utils/cacheManager.ts +67 -0
  40. package/src/api/utils/determineRuntimeJsType.ts +46 -0
  41. package/src/api/utils/logger.ts +24 -0
  42. package/src/api/utils/sortAndSerializeQueryObject.ts +12 -0
  43. package/src/api/utils/testHelpers.ts +24 -0
  44. package/src/api/utils/toastNotifier.ts +11 -0
  45. package/src/index.ts +15 -2
  46. package/src/api/carbonSqlExecutor.ts +0 -279
  47. 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 "api/restRequest";
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,16 @@
1
+ import { apiReturn, iAPI, iRest } from "@carbonorm/carbonnode";
2
+ import { Modify } from "../types/modifyTypes";
3
+ export declare abstract class Executor<RestShortTableName extends string = any, RestTableInterface extends {
4
+ [key: string]: any;
5
+ } = any, PrimaryKey extends Extract<keyof RestTableInterface, string> = Extract<keyof RestTableInterface, string>, CustomAndRequiredFields extends {
6
+ [key: string]: any;
7
+ } = any, RequestTableOverrides extends {
8
+ [key: string]: any;
9
+ } = {
10
+ [key in keyof RestTableInterface]: any;
11
+ }, ResponseDataType = any> {
12
+ protected config: iRest<RestShortTableName, RestTableInterface, PrimaryKey, CustomAndRequiredFields, RequestTableOverrides, ResponseDataType>;
13
+ protected request: iAPI<Modify<RestTableInterface, RequestTableOverrides>> & CustomAndRequiredFields;
14
+ constructor(config: iRest<RestShortTableName, RestTableInterface, PrimaryKey, CustomAndRequiredFields, RequestTableOverrides, ResponseDataType>, request?: iAPI<Modify<RestTableInterface, RequestTableOverrides>> & CustomAndRequiredFields);
15
+ abstract execute(): Promise<apiReturn<ResponseDataType>>;
16
+ }
@@ -0,0 +1,13 @@
1
+ import { apiReturn } from "../types/ormInterfaces";
2
+ import { Executor } from "./Executor";
3
+ export declare class HttpExecutor<RestShortTableName extends string = any, RestTableInterface extends {
4
+ [key: string]: any;
5
+ } = any, PrimaryKey extends Extract<keyof RestTableInterface, string> = Extract<keyof RestTableInterface, string>, CustomAndRequiredFields extends {
6
+ [key: string]: any;
7
+ } = any, RequestTableOverrides extends {
8
+ [key: string]: any;
9
+ } = {
10
+ [key in keyof RestTableInterface]: any;
11
+ }, ResponseDataType = any> extends Executor<RestShortTableName, RestTableInterface, PrimaryKey, CustomAndRequiredFields, RequestTableOverrides, ResponseDataType> {
12
+ execute(): Promise<apiReturn<ResponseDataType>>;
13
+ }
@@ -0,0 +1,19 @@
1
+ import { apiReturn } from "@carbonorm/carbonnode";
2
+ import { RowDataPacket } from 'mysql2/promise';
3
+ import { Executor } from "./Executor";
4
+ export declare class SqlExecutor<RestShortTableName extends string = any, RestTableInterface extends {
5
+ [key: string]: any;
6
+ } = any, PrimaryKey extends Extract<keyof RestTableInterface, string> = Extract<keyof RestTableInterface, string>, CustomAndRequiredFields extends {
7
+ [key: string]: any;
8
+ } = any, RequestTableOverrides extends {
9
+ [key: string]: any;
10
+ } = {
11
+ [key in keyof RestTableInterface]: any;
12
+ }, ResponseDataType = any> extends Executor<RestShortTableName, RestTableInterface, PrimaryKey, CustomAndRequiredFields, RequestTableOverrides, ResponseDataType> {
13
+ execute(): Promise<apiReturn<ResponseDataType>>;
14
+ private withConnection;
15
+ select<RestShortTableNames>(table: RestShortTableNames, primary: string | undefined, args: any): Promise<RowDataPacket[]>;
16
+ insert<RestShortTableNames>(table: RestShortTableNames, data: any): Promise<import("mysql2/promise").QueryResult>;
17
+ update<RestShortTableNames>(table: RestShortTableNames, primary: string | undefined, data: any): Promise<import("mysql2/promise").QueryResult>;
18
+ delete<RestShortTableNames>(table: RestShortTableNames, primary: string | undefined, args: any): Promise<import("mysql2/promise").QueryResult>;
19
+ }
@@ -1,171 +1,14 @@
1
- import { iC6RestfulModel, iDynamicApiImport } from "api/interfaces/ormInterfaces";
2
- import { AxiosInstance, AxiosPromise, AxiosResponse } from "axios";
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
- * the first argument ....
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>;
164
- export default function restRequest<CustomAndRequiredFields extends {
4
+ * Facade: routes API calls to SQL or HTTP executors based on runtime context.
5
+ */
6
+ export default function restRequest<RestShortTableName extends string = any, RestTableInterface extends {
165
7
  [key: string]: any;
166
- } = any, RestTableInterfaces extends {
8
+ } = any, PrimaryKey extends Extract<keyof RestTableInterface, string> = Extract<keyof RestTableInterface, string>, CustomAndRequiredFields extends {
167
9
  [key: string]: any;
168
10
  } = any, RequestTableOverrides extends {
169
11
  [key: string]: any;
170
- } = any, ResponseDataType = any, RestShortTableNames extends string = any>({ C6, axios, restURL, mysqlPool, withCredentials, tableName, requestMethod, queryCallback, responseCallback, skipPrimaryCheck, clearCache }: iRest<CustomAndRequiredFields, RestTableInterfaces, RequestTableOverrides, ResponseDataType, RestShortTableNames>): (request?: iAPI<Modify<RestTableInterfaces, RequestTableOverrides>> & CustomAndRequiredFields) => Promise<(ResponseDataType extends iPutC6RestResponse<any, any> | iDeleteC6RestResponse<any, any> | iPostC6RestResponse<any> ? null : () => apiReturn<ResponseDataType>) | AxiosResponse<ResponseDataType, any> | null | undefined>;
171
- export {};
12
+ } = {
13
+ [key in keyof RestTableInterface]: any;
14
+ }, ResponseDataType = any>(config: iRest<RestShortTableName, RestTableInterface, PrimaryKey, CustomAndRequiredFields, RequestTableOverrides, ResponseDataType>): (request?: iAPI<Modify<RestTableInterface, RequestTableOverrides>> & CustomAndRequiredFields) => Promise<apiReturn<ResponseDataType>>;
@@ -0,0 +1,10 @@
1
+ export declare enum eFetchDependencies {
2
+ NONE = 0,
3
+ REFERENCED = 1,
4
+ CHILDREN = 1,
5
+ REFERENCES = 2,
6
+ PARENTS = 2,
7
+ ALL = 3,
8
+ C6ENTITY = 4,
9
+ RECURSIVE = 8
10
+ }
@@ -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,219 @@
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 type tColumns<TableName extends string, T extends {
50
+ [key: string]: any;
51
+ }> = {
52
+ [K in keyof T & string as `${TableName}.${K}`]: K;
53
+ };
54
+ export type tPrimaryKeys<TableName extends string, PK extends string> = `${TableName}.${PK}`;
55
+ export interface iC6RestfulModel<RestShortTableNames extends string, RestTableInterfaces extends {
56
+ [key: string]: any;
57
+ }, PK extends keyof RestTableInterfaces & string> {
58
+ TABLE_NAME: RestShortTableNames;
59
+ PRIMARY: tPrimaryKeys<RestShortTableNames, PK>[];
60
+ PRIMARY_SHORT: PK[];
61
+ COLUMNS: tColumns<RestShortTableNames, RestTableInterfaces>;
62
+ TYPE_VALIDATION: {
63
+ [key: string]: iTypeValidation;
64
+ };
65
+ REGEX_VALIDATION: RegExpMap;
66
+ LIFECYCLE_HOOKS: iRestReactiveLifecycle<RequestGetPutDeleteBody>[];
67
+ TABLE_REFERENCES: {
68
+ [columnName: string]: iConstraint[];
69
+ };
70
+ TABLE_REFERENCED_BY: {
71
+ [columnName: string]: iConstraint[];
72
+ };
73
+ }
74
+ export interface iRestApiFunctions<RestData = any> {
75
+ Delete: (request?: (iAPI<any> & any)) => apiReturn<iDeleteC6RestResponse<RestData>>;
76
+ Post: (request?: (iAPI<any> & any)) => apiReturn<iPostC6RestResponse<RestData>>;
77
+ Get: (request?: (iAPI<any> & any)) => apiReturn<iGetC6RestResponse<RestData>>;
78
+ Put: (request?: (iAPI<any> & any)) => apiReturn<iPutC6RestResponse<RestData>>;
79
+ }
80
+ export interface iDynamicApiImport<RestData = any> {
81
+ default: iRestApiFunctions<RestData>;
82
+ postState?: (response: AxiosResponse<iPostC6RestResponse<RestData>>, request: iAPI<any>, id: string | number | boolean) => void;
83
+ deleteState?: (response: AxiosResponse<iDeleteC6RestResponse<RestData>>, request: iAPI<any>) => void;
84
+ putState?: (response: AxiosResponse<iPutC6RestResponse<RestData>>, request: iAPI<any>) => void;
85
+ }
86
+ export interface tC6Tables<RestShortTableName extends string = any, RestTableInterface extends {
87
+ [key: string]: any;
88
+ } = any, PrimaryKey extends Extract<keyof RestTableInterface, string> = Extract<keyof RestTableInterface, string>> {
89
+ [key: string]: iC6RestfulModel<RestShortTableName, RestTableInterface, PrimaryKey> & {
90
+ [key: string]: any;
91
+ };
92
+ }
93
+ export interface tC6RestApi {
94
+ [key: string]: {
95
+ REST: iRestApiFunctions;
96
+ PUT: Function;
97
+ POST: Function;
98
+ DELETE: Function;
99
+ };
100
+ }
101
+ export type iAPI<RestTableInterfaces extends {
102
+ [key: string]: any;
103
+ }> = RestTableInterfaces & {
104
+ dataInsertMultipleRows?: RestTableInterfaces[];
105
+ cacheResults?: boolean;
106
+ fetchDependencies?: number | eFetchDependencies | Awaited<apiReturn<iGetC6RestResponse<any>>>[];
107
+ debug?: boolean;
108
+ success?: string | ((r: AxiosResponse) => (string | void));
109
+ error?: string | ((r: AxiosResponse) => (string | void));
110
+ };
111
+ export interface iCacheAPI<ResponseDataType = any> {
112
+ requestArgumentsSerialized: string;
113
+ request: AxiosPromise<ResponseDataType>;
114
+ response?: AxiosResponse;
115
+ final?: boolean;
116
+ }
117
+ /**
118
+ * the first argument ....
119
+ *
120
+ * Our api returns a zero argument function iff the method is get and the previous request reached the predefined limit.
121
+ * This function can be aliased as GetNextPageOfResults(). If the end is reached undefined will be returned.
122
+ *
123
+ *
124
+ * For POST, PUT, and DELETE requests one can expect the primary key of the new or modified index, or a boolean success
125
+ * indication if no primary key exists.
126
+ **/
127
+ export declare const POST = "POST";
128
+ export declare const PUT = "PUT";
129
+ export declare const GET = "GET";
130
+ export declare const DELETE = "DELETE";
131
+ export type iRestMethods = 'GET' | 'POST' | 'PUT' | 'DELETE';
132
+ export type SubSelect<T = any> = {
133
+ subSelect: true;
134
+ table: string;
135
+ args: RequestGetPutDeleteBody<T>;
136
+ alias: string;
137
+ };
138
+ export type SelectField<T = any> = keyof T | [keyof T, 'AS', string] | [SQLFunction, keyof T] | [SQLFunction, keyof T, string] | SubSelect<T>;
139
+ export type WhereClause<T = any> = Partial<T> | LogicalGroup<T> | ComparisonClause<T>;
140
+ export type LogicalGroup<T = any> = {
141
+ [logicalGroup: string]: Array<WhereClause<T>>;
142
+ };
143
+ export type ComparisonClause<T = any> = [keyof T, SQLComparisonOperator, any];
144
+ export type JoinTableCondition<T = any> = Partial<T> | WhereClause<T>[] | ComparisonClause<T>[];
145
+ export type JoinClause<T = any> = {
146
+ [table: string]: JoinTableCondition<T>;
147
+ };
148
+ export type Join<T = any> = {
149
+ [K in JoinType]?: JoinClause<T>;
150
+ };
151
+ export type Pagination<T = any> = {
152
+ PAGE?: number;
153
+ LIMIT?: number | null;
154
+ ORDER?: Partial<Record<keyof T, OrderDirection>>;
155
+ };
156
+ export type RequestGetPutDeleteBody<T = any> = {
157
+ SELECT?: SelectField<T>[];
158
+ UPDATE?: Partial<T>;
159
+ DELETE?: boolean;
160
+ WHERE?: WhereClause<T>;
161
+ JOIN?: Join<T>;
162
+ PAGINATION?: Pagination<T>;
163
+ };
164
+ export type RequestQueryBody<RestTableInterfaces extends {
165
+ [key: string]: any;
166
+ }> = iAPI<RestTableInterfaces> | RequestGetPutDeleteBody;
167
+ export declare function isPromise(x: any): boolean;
168
+ interface iC6RestResponse<RestData> {
169
+ rest: RestData;
170
+ session?: any;
171
+ sql?: any;
172
+ }
173
+ interface iChangeC6Data {
174
+ rowCount: number;
175
+ }
176
+ export interface iDeleteC6RestResponse<RestData = any, RequestData = any> extends iChangeC6Data, iC6RestResponse<RestData> {
177
+ deleted: boolean | number | string | RequestData;
178
+ }
179
+ export interface iPostC6RestResponse<RestData = any> extends iC6RestResponse<RestData> {
180
+ created: boolean | number | string;
181
+ }
182
+ export interface iPutC6RestResponse<RestData = any, RequestData = any> extends iChangeC6Data, iC6RestResponse<RestData> {
183
+ updated: boolean | number | string | RequestData;
184
+ }
185
+ export interface iC6Object<RestShortTableName extends string = any, RestTableInterface extends {
186
+ [key: string]: any;
187
+ } = any, PrimaryKey extends Extract<keyof RestTableInterface, string> = Extract<keyof RestTableInterface, string>> {
188
+ C6VERSION: string;
189
+ TABLES: {
190
+ [key: string]: iC6RestfulModel<RestShortTableName, RestTableInterface, PrimaryKey> & {
191
+ [key: string]: string | number;
192
+ };
193
+ };
194
+ PREFIX: string;
195
+ IMPORT: (tableName: string) => Promise<iDynamicApiImport>;
196
+ [key: string]: any;
197
+ }
198
+ export type iGetC6RestResponse<ResponseDataType, ResponseDataOverrides = {}> = iC6RestResponse<Modify<ResponseDataType, ResponseDataOverrides> | Modify<ResponseDataType, ResponseDataOverrides>[]>;
199
+ export type apiReturn<Response> = null | undefined | AxiosPromise<Response> | (Response extends iPutC6RestResponse | iDeleteC6RestResponse | iPostC6RestResponse ? null : (() => apiReturn<Response>));
200
+ export interface iRest<RestShortTableName extends string = any, RestTableInterface extends {
201
+ [key: string]: any;
202
+ } = any, PrimaryKey extends Extract<keyof RestTableInterface, string> = Extract<keyof RestTableInterface, string>, CustomAndRequiredFields extends {
203
+ [key: string]: any;
204
+ } = any, RequestTableOverrides = {
205
+ [key in keyof RestTableInterface]: any;
206
+ }, ResponseDataType = any> {
207
+ C6: iC6Object;
208
+ axios?: AxiosInstance;
209
+ restURL?: string;
210
+ mysqlPool?: Pool;
211
+ withCredentials?: boolean;
212
+ restModel: iC6RestfulModel<RestShortTableName, RestTableInterface, PrimaryKey>;
213
+ requestMethod: iRestMethods;
214
+ clearCache?: () => void;
215
+ 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
+ }
219
+ 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<any, any, any> & {
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,5 @@
1
+ import { iC6RestfulModel } from "../types/ormInterfaces";
2
+ type JsPrimitive = 'string' | 'number' | 'boolean' | 'buffer' | 'object';
3
+ export declare function determineRuntimeJsType(mysqlType: string): JsPrimitive;
4
+ export declare function getPrimaryKeyTypes(table: iC6RestfulModel<string, any, any>): Record<string, JsPrimitive>;
5
+ 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[]);
@@ -0,0 +1,2 @@
1
+ export declare function onSuccess(message: string): void;
2
+ export declare function onError(message: string): void;