@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.
Files changed (41) 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 +18 -0
  4. package/dist/api/executors/HttpExecutor.d.ts +15 -0
  5. package/dist/api/executors/SqlExecutor.d.ts +11 -0
  6. package/dist/api/restRequest.d.ts +5 -164
  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 +223 -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/logger.d.ts +7 -0
  14. package/dist/api/utils/sortAndSerializeQueryObject.d.ts +1 -0
  15. package/dist/api/utils/testHelpers.d.ts +1 -0
  16. package/dist/api/utils/toastNotifier.d.ts +2 -0
  17. package/dist/index.cjs.js +614 -605
  18. package/dist/index.cjs.js.map +1 -1
  19. package/dist/index.d.ts +14 -2
  20. package/dist/index.esm.js +603 -607
  21. package/dist/index.esm.js.map +1 -1
  22. package/package.json +22 -6
  23. package/src/api/builders/sqlBuilder.ts +173 -0
  24. package/src/api/convertForRequestBody.ts +1 -2
  25. package/src/api/executors/Executor.ts +26 -0
  26. package/src/api/executors/HttpExecutor.ts +790 -0
  27. package/src/api/executors/SqlExecutor.ts +90 -0
  28. package/src/api/restRequest.ts +20 -1273
  29. package/src/api/types/dynamicFetching.ts +10 -0
  30. package/src/api/types/modifyTypes.ts +25 -0
  31. package/src/api/types/mysqlTypes.ts +33 -0
  32. package/src/api/types/ormInterfaces.ts +287 -0
  33. package/src/api/utils/apiHelpers.ts +83 -0
  34. package/src/api/utils/cacheManager.ts +67 -0
  35. package/src/api/utils/logger.ts +24 -0
  36. package/src/api/utils/sortAndSerializeQueryObject.ts +12 -0
  37. package/src/api/utils/testHelpers.ts +24 -0
  38. package/src/api/utils/toastNotifier.ts +11 -0
  39. package/src/index.ts +14 -2
  40. package/src/api/carbonSqlExecutor.ts +0 -279
  41. package/src/api/interfaces/ormInterfaces.ts +0 -87
@@ -0,0 +1,10 @@
1
+ export enum eFetchDependencies {
2
+ NONE = 0,
3
+ REFERENCED = 0b1,
4
+ CHILDREN = 0b1,
5
+ REFERENCES = 0b10,
6
+ PARENTS = 0b10,
7
+ ALL = 0b11,
8
+ C6ENTITY = 0b100,
9
+ RECURSIVE = 0b1000,
10
+ }
@@ -0,0 +1,25 @@
1
+ // if you can get away with modify over modifyDeep, use modify. The editor will be happier.
2
+ export type Modify<T, R> = Omit<T, keyof R> & R;
3
+
4
+ // @link https://stackoverflow.com/questions/41285211/overriding-interface-property-type-defined-in-typescript-d-ts-file/55032655#55032655
5
+ export type ModifyDeep<A, B extends DeepPartialAny<A>> = {
6
+ [K in keyof A | keyof B]?: // For all keys in A and B:
7
+ K extends keyof A // ───┐
8
+ ? K extends keyof B // ───┼─ key K exists in both A and B
9
+ ? A[K] extends AnyObject // │ ┴──┐
10
+ ? B[K] extends AnyObject // │ ───┼─ both A and B are objects
11
+ ? ModifyDeep<A[K], B[K]> // │ │ └─── We need to go deeper (recursively)
12
+ : B[K] // │ ├─ B is a primitive 🠆 use B as the final type (new type)
13
+ : B[K] // │ └─ A is a primitive 🠆 use B as the final type (new type)
14
+ : A[K] // ├─ key only exists in A 🠆 use A as the final type (original type)
15
+ : B[K] // └─ key only exists in B 🠆 use B as the final type (new type)
16
+ }
17
+
18
+ type AnyObject = Record<string, any>
19
+
20
+ // This type is here only for some intellisense for the overrides object
21
+ type DeepPartialAny<T> = {
22
+ /** Makes each property optional and turns each leaf property into any, allowing for type overrides by narrowing any. */
23
+ [P in keyof T]?: T[P] extends AnyObject ? DeepPartialAny<T[P]> : any
24
+ }
25
+
@@ -0,0 +1,33 @@
1
+
2
+ // ========================
3
+ // 🔧 SQL Operator & Helpers
4
+ // ========================
5
+
6
+ export type SQLFunction =
7
+ | 'COUNT'
8
+ | 'GROUP_CONCAT'
9
+ | 'MAX'
10
+ | 'MIN'
11
+ | 'SUM'
12
+ | 'DISTINCT';
13
+
14
+ export type SQLComparisonOperator =
15
+ | '='
16
+ | '!='
17
+ | '<'
18
+ | '<='
19
+ | '>'
20
+ | '>='
21
+ | 'IN'
22
+ | 'NOT IN'
23
+ | 'LIKE'
24
+ | 'IS NULL'
25
+ | 'IS NOT NULL'
26
+ | 'BETWEEN'
27
+ | 'LESS_THAN'
28
+ | 'GREATER_THAN';
29
+
30
+ export type JoinType = 'INNER' | 'LEFT_OUTER' | 'RIGHT_OUTER';
31
+
32
+ export type OrderDirection = 'ASC' | 'DESC';
33
+
@@ -0,0 +1,287 @@
1
+ import restRequest from "api/restRequest";
2
+ import {AxiosInstance, AxiosPromise, AxiosResponse} from "axios";
3
+ import {Pool} from "mysql2/promise";
4
+ import {eFetchDependencies} from "./dynamicFetching";
5
+ import {Modify} from "./modifyTypes";
6
+ import {JoinType, OrderDirection, SQLComparisonOperator, SQLFunction} from "./mysqlTypes";
7
+
8
+ export interface stringMap {
9
+ [key: string]: string;
10
+ }
11
+
12
+ export interface stringNumberMap {
13
+ [key: string]: string | number;
14
+ }
15
+
16
+ export interface RegExpMap {
17
+ [key: string]: RegExp | RegExpMap;
18
+ }
19
+
20
+ export interface complexMap {
21
+ [key: string]: stringMap | stringNumberMap | stringMap[] | RegExpMap;
22
+ }
23
+
24
+ export interface iTypeValidation {
25
+ MYSQL_TYPE: string,
26
+ MAX_LENGTH: string,
27
+ AUTO_INCREMENT: boolean,
28
+ SKIP_COLUMN_IN_POST: boolean
29
+ }
30
+
31
+ export type iRestReactiveLifecycle<T extends RequestGetPutDeleteBody> = {
32
+ beforeProcessing?: (args: { request: T[]; requestMeta?: any }) => void | Promise<void>;
33
+ beforeExecution?: (args: { request: T[]; requestMeta?: any }) => void | Promise<void>;
34
+ afterExecution?: (args: { response: T[]; request: T[]; responseMeta?: any }) => void | Promise<void>;
35
+ afterCommit?: (args: { response: T[]; request: T[]; responseMeta?: any }) => void | Promise<void>;
36
+ };
37
+
38
+ export interface iConstraint {
39
+ TABLE: string,
40
+ COLUMN: string,
41
+ CONSTRAINT: string
42
+ }
43
+
44
+ export interface iC6RestfulModel<RestShortTableNames extends string = string> {
45
+ TABLE_NAME: RestShortTableNames,
46
+ PRIMARY: string[],
47
+ PRIMARY_SHORT: string[],
48
+ COLUMNS: stringMap,
49
+ LIFECYCLE_HOOKS: iRestReactiveLifecycle<RequestGetPutDeleteBody>[],
50
+ REGEX_VALIDATION: RegExpMap,
51
+ TYPE_VALIDATION: { [key: string]: iTypeValidation },
52
+ TABLE_REFERENCES: { [columnName: string]: iConstraint[] },
53
+ TABLE_REFERENCED_BY: { [columnName: string]: iConstraint[] },
54
+ }
55
+
56
+ export interface iRestApiFunctions<RestData = any> {
57
+ Delete: (request?: (iAPI<any> & any)) => apiReturn<iDeleteC6RestResponse<RestData>>;
58
+ Post: (request?: (iAPI<any> & any)) => apiReturn<iPostC6RestResponse<RestData>>;
59
+ Get: (request?: (iAPI<any> & any)) => apiReturn<iGetC6RestResponse<RestData>>;
60
+ Put: (request?: (iAPI<any> & any)) => apiReturn<iPutC6RestResponse<RestData>>,
61
+ }
62
+
63
+ export interface iDynamicApiImport<RestData = any> {
64
+ default: iRestApiFunctions<RestData>
65
+ // the methods below are optional
66
+ postState?: (response: AxiosResponse<iPostC6RestResponse<RestData>>, request: iAPI<any>, id: string | number | boolean) => void,
67
+ deleteState?: (response: AxiosResponse<iDeleteC6RestResponse<RestData>>, request: iAPI<any>) => void,
68
+ putState?: (response: AxiosResponse<iPutC6RestResponse<RestData>>, request: iAPI<any>) => void
69
+ }
70
+
71
+ export interface tC6Tables { [key: string]: (iC6RestfulModel & { [key: string]: any }) }
72
+
73
+ export interface tC6RestApi {
74
+ [key: string]: {
75
+ REST: iRestApiFunctions,
76
+ PUT: Function;
77
+ POST: Function;
78
+ DELETE: Function;
79
+ };
80
+ }
81
+
82
+ // todo - I don't like that these essentially become reserved words.
83
+ export type iAPI<RestTableInterfaces extends { [key: string]: any }> = RestTableInterfaces & {
84
+ dataInsertMultipleRows?: RestTableInterfaces[],
85
+ cacheResults?: boolean, // aka ignoreCache
86
+ // todo - this should really only be used for get requests - add this to the Get interface or throw error (im actually inclined to ts ignore the function and add to iGetC6 atm; back later)
87
+ fetchDependencies?: number | eFetchDependencies | Awaited<apiReturn<iGetC6RestResponse<any>>>[],
88
+ debug?: boolean,
89
+ success?: string | ((r: AxiosResponse) => (string | void)),
90
+ error?: string | ((r: AxiosResponse) => (string | void)),
91
+ }
92
+
93
+ export interface iCacheAPI<ResponseDataType = any> {
94
+ requestArgumentsSerialized: string,
95
+ request: AxiosPromise<ResponseDataType>,
96
+ response?: AxiosResponse,
97
+ final?: boolean,
98
+ }
99
+
100
+
101
+
102
+ /**
103
+ * the first argument ....
104
+ *
105
+ * Our api returns a zero argument function iff the method is get and the previous request reached the predefined limit.
106
+ * This function can be aliased as GetNextPageOfResults(). If the end is reached undefined will be returned.
107
+ *
108
+ *
109
+ * For POST, PUT, and DELETE requests one can expect the primary key of the new or modified index, or a boolean success
110
+ * indication if no primary key exists.
111
+ **/
112
+ export const POST = 'POST';
113
+ export const PUT = 'PUT';
114
+ export const GET = 'GET';
115
+ export const DELETE = 'DELETE';
116
+
117
+
118
+ export type iRestMethods = 'GET' | 'POST' | 'PUT' | 'DELETE';
119
+
120
+ // ========================
121
+ // 📦 SELECT
122
+ // ========================
123
+
124
+ export type SubSelect<T = any> = {
125
+ subSelect: true;
126
+ table: string; // could be enum’d to known table names
127
+ args: RequestGetPutDeleteBody<T>;
128
+ alias: string;
129
+ };
130
+
131
+ export type SelectField<T = any> =
132
+ | keyof T
133
+ | [keyof T, 'AS', string]
134
+ | [SQLFunction, keyof T]
135
+ | [SQLFunction, keyof T, string] // With alias
136
+ | SubSelect<T>; // Fully nested sub-select
137
+
138
+
139
+ // ========================
140
+ // 🧠 WHERE (Recursive)
141
+ // ========================
142
+
143
+ export type WhereClause<T = any> =
144
+ | Partial<T>
145
+ | LogicalGroup<T>
146
+ | ComparisonClause<T>;
147
+
148
+ export type LogicalGroup<T = any> = {
149
+ [logicalGroup: string]: Array<WhereClause<T>>;
150
+ };
151
+
152
+ export type ComparisonClause<T = any> = [keyof T, SQLComparisonOperator, any];
153
+
154
+
155
+ // ========================
156
+ // 🔗 JOIN
157
+ // ========================
158
+
159
+ export type JoinTableCondition<T = any> =
160
+ | Partial<T>
161
+ | WhereClause<T>[]
162
+ | ComparisonClause<T>[];
163
+
164
+ export type JoinClause<T = any> = {
165
+ [table: string]: JoinTableCondition<T>;
166
+ };
167
+
168
+ export type Join<T = any> = {
169
+ [K in JoinType]?: JoinClause<T>;
170
+ };
171
+
172
+
173
+ // ========================
174
+ // 📄 PAGINATION
175
+ // ========================
176
+
177
+ export type Pagination<T = any> = {
178
+ PAGE?: number;
179
+ LIMIT?: number | null;
180
+ ORDER?: Partial<Record<keyof T, OrderDirection>>;
181
+ };
182
+
183
+
184
+ // ========================
185
+ // 🌐 MAIN API TYPE
186
+ // ========================
187
+
188
+ export type RequestGetPutDeleteBody<T = any> = {
189
+ SELECT?: SelectField<T>[];
190
+ UPDATE?: Partial<T>;
191
+ DELETE?: boolean;
192
+ WHERE?: WhereClause<T>;
193
+ JOIN?: Join<T>;
194
+ PAGINATION?: Pagination<T>;
195
+ };
196
+
197
+
198
+ export type RequestQueryBody<RestTableInterfaces extends { [key: string]: any }> =
199
+ iAPI<RestTableInterfaces>
200
+ | RequestGetPutDeleteBody;
201
+
202
+ export function isPromise(x) {
203
+ return Object(x).constructor === Promise
204
+ }
205
+
206
+ interface iC6RestResponse<RestData> {
207
+ rest: RestData,
208
+ session?: any,
209
+ sql?: any
210
+ }
211
+
212
+
213
+ interface iChangeC6Data {
214
+ rowCount: number,
215
+ }
216
+
217
+ export interface iDeleteC6RestResponse<RestData = any, RequestData = any> extends iChangeC6Data, iC6RestResponse<RestData> {
218
+ deleted: boolean | number | string | RequestData,
219
+ }
220
+
221
+ export interface iPostC6RestResponse<RestData = any> extends iC6RestResponse<RestData> {
222
+ created: boolean | number | string,
223
+ }
224
+
225
+ export interface iPutC6RestResponse<RestData = any, RequestData = any> extends iChangeC6Data, iC6RestResponse<RestData> {
226
+ updated: boolean | number | string | RequestData,
227
+ }
228
+
229
+ export interface iC6Object {
230
+ C6VERSION: string,
231
+ TABLES: {
232
+ [key: string]: iC6RestfulModel &
233
+ { [key: string]: string | number }
234
+ },
235
+ PREFIX: string,
236
+ IMPORT: (tableName: string) => Promise<iDynamicApiImport>,
237
+
238
+ [key: string]: any
239
+ }
240
+
241
+ // todo - I'm not sure that Modify<ResponseDataType, ResponseDataOverrides>[]> is needed?
242
+ export type iGetC6RestResponse<ResponseDataType, ResponseDataOverrides = {}> = iC6RestResponse<Modify<ResponseDataType, ResponseDataOverrides> | Modify<ResponseDataType, ResponseDataOverrides>[]>
243
+
244
+ // returning undefined means no more results are available, thus we've queried everything possible
245
+ // null means the request is currently being executed
246
+ // https://www.typescriptlang.org/docs/handbook/2/conditional-types.html
247
+ export type apiReturn<Response> =
248
+ null
249
+ | undefined
250
+ | AxiosPromise<Response>
251
+ | (Response extends iPutC6RestResponse | iDeleteC6RestResponse | iPostC6RestResponse ? null : (() => apiReturn<Response>))
252
+
253
+
254
+ export interface iRest<
255
+ CustomAndRequiredFields extends { [key: string]: any },
256
+ RestTableInterfaces extends { [key: string]: any },
257
+ RequestTableOverrides = { [key in keyof RestTableInterfaces]: any },
258
+ ResponseDataType = any,
259
+ RestShortTableNames extends string = any
260
+ > {
261
+ C6: iC6Object,
262
+ axios?: AxiosInstance,
263
+ restURL?: string,
264
+ mysqlPool?: Pool;
265
+ withCredentials?: boolean,
266
+ tableName: RestShortTableNames | RestShortTableNames[],
267
+ requestMethod: iRestMethods,
268
+ clearCache?: () => void,
269
+ skipPrimaryCheck?: boolean,
270
+ queryCallback: RequestQueryBody<Modify<RestTableInterfaces, RequestTableOverrides>> | ((request: iAPI<Modify<RestTableInterfaces, RequestTableOverrides>> & CustomAndRequiredFields) => (null | undefined | RequestQueryBody<Modify<RestTableInterfaces, RequestTableOverrides>>)),
271
+ responseCallback?: (response: AxiosResponse<ResponseDataType>,
272
+ request: iAPI<Modify<RestTableInterfaces, RequestTableOverrides>> & CustomAndRequiredFields,
273
+ success: (ResponseDataType extends iPutC6RestResponse | iDeleteC6RestResponse ? RequestQueryBody<Modify<RestTableInterfaces, RequestTableOverrides>> : string) | string | number | boolean) => any // keep this set to any, it allows easy arrow functions and the results unused here
274
+ }
275
+
276
+ export function extendedTypeHints<RestTableInterfaces extends {
277
+ [key: string]: any
278
+ }, RestShortTableNames extends string>() {
279
+ return <CustomAndRequiredFields extends {
280
+ [key: string]: any
281
+ } = any, RequestTableTypes extends RestTableInterfaces = any, RequestTableOverrides extends {
282
+ [key: string]: any
283
+ } = any, ResponseDataType extends {
284
+ [key: string]: any
285
+ } = any>(argv) => restRequest<CustomAndRequiredFields, RequestTableTypes, RequestTableOverrides, ResponseDataType, RestShortTableNames>(argv)
286
+ }
287
+
@@ -0,0 +1,83 @@
1
+ // When we capture DropExceptions and display them as a custom page, this will change.
2
+ import {toast} from "react-toastify";
3
+ import isTest from "../../variables/isTest";
4
+ import { AxiosResponse } from "axios";
5
+ import {toastOptions} from "../../variables/toastOptions";
6
+ import {iC6RestfulModel} from "../types/ormInterfaces";
7
+
8
+ export function TestRestfulResponse(response: AxiosResponse | any, success: ((r: AxiosResponse) => (string | void)) | string | undefined, error: ((r: AxiosResponse) => (string | void)) | string | undefined): string | boolean | number {
9
+
10
+ if (undefined === response.data?.['ERROR TYPE']
11
+ && (undefined !== response?.data?.rest
12
+ || undefined !== response.data?.created
13
+ || undefined !== response.data?.updated
14
+ || undefined !== response.data?.deleted)) {
15
+
16
+ let successReturn: string | undefined | void = 'function' === typeof success ? success?.(response) : success;
17
+
18
+ if (typeof successReturn === 'string') {
19
+
20
+ toast.success(successReturn, toastOptions);
21
+
22
+ }
23
+
24
+ // this could end up with bad results for deleting id's === 0
25
+ return response.data.created ?? response.data.updated ?? response.data.deleted ?? true;
26
+
27
+ }
28
+
29
+ let errorReturn: string | undefined | void = 'function' === typeof error ? error?.(response) : error;
30
+
31
+ if (typeof errorReturn === 'string') {
32
+
33
+ toast.error(errorReturn, toastOptions);
34
+
35
+ }
36
+
37
+ return false;
38
+
39
+
40
+ }
41
+
42
+ export function removePrefixIfExists(tableName: string, prefix: string): string {
43
+ if (tableName.startsWith(prefix.toLowerCase())) {
44
+ return tableName.slice(prefix.length);
45
+ }
46
+ return tableName;
47
+ }
48
+
49
+ export function removeInvalidKeys<iRestObject>(request: any, c6Tables: {
50
+ [key: string]: (iC6RestfulModel & { [key: string]: any })
51
+ }): iRestObject {
52
+
53
+ let intersection: iRestObject = {} as iRestObject
54
+
55
+ let restfulObjectKeys: string[] = [];
56
+
57
+ const tableList = Object.values(c6Tables)
58
+
59
+ tableList.forEach(table => Object.values(table.COLUMNS).forEach(column => {
60
+
61
+ if (false === restfulObjectKeys.includes(column)) {
62
+
63
+ restfulObjectKeys.push(column)
64
+
65
+ }
66
+
67
+ }))
68
+
69
+ Object.keys(request).forEach(key => {
70
+
71
+ if (restfulObjectKeys.includes(key)) {
72
+
73
+ intersection[key] = request[key]
74
+
75
+ }
76
+
77
+ });
78
+
79
+ isTest || console.log('intersection', intersection)
80
+
81
+ return intersection
82
+
83
+ }
@@ -0,0 +1,67 @@
1
+ import {AxiosPromise} from "axios";
2
+ import isTest from "../../variables/isTest";
3
+ import isVerbose from "../../variables/isVerbose";
4
+ import { iCacheAPI } from "api/types/ormInterfaces";
5
+
6
+ // do not remove entries from this array. It is used to track the progress of API requests.
7
+ // position in array is important. Do not sort. To not add to begging.
8
+ export let apiRequestCache: iCacheAPI[] = [];
9
+
10
+ export let userCustomClearCache: (() => void)[] = [];
11
+
12
+ interface iClearCache {
13
+ ignoreWarning: boolean
14
+ }
15
+
16
+ export function clearCache(props?: iClearCache) {
17
+
18
+ if (false === props?.ignoreWarning) {
19
+
20
+ console.warn('The rest api clearCache should only be used with extreme care! Avoid using this in favor of using `cacheResults : boolean`.')
21
+
22
+ }
23
+
24
+ userCustomClearCache.map((f) => 'function' === typeof f && f());
25
+
26
+ userCustomClearCache = apiRequestCache = []
27
+
28
+ }
29
+
30
+ export function checkCache<ResponseDataType = any, RestShortTableNames = string>(cacheResult: iCacheAPI<ResponseDataType>, requestMethod: string, tableName: RestShortTableNames | RestShortTableNames[], request: any): false | undefined | null | AxiosPromise<ResponseDataType> {
31
+
32
+ if (undefined === cacheResult?.response) {
33
+
34
+ console.groupCollapsed('%c API: The request on (' + tableName + ') is in cache and the response is undefined. The request has not finished. Returning the request Promise!', 'color: #0c0')
35
+
36
+ console.log('%c ' + requestMethod + ' ' + tableName, 'color: #0c0')
37
+
38
+ console.log('%c Request Data (note you may see the success and/or error prompt):', 'color: #0c0', request)
39
+
40
+ console.groupEnd()
41
+
42
+ return cacheResult.request;
43
+
44
+ }
45
+
46
+ if (true === cacheResult?.final) {
47
+
48
+ if (false === isTest || true === isVerbose) {
49
+
50
+ console.groupCollapsed('%c API: Rest api cache (' + requestMethod + ' ' + tableName + ') has reached the final result. Returning undefined!', 'color: #cc0')
51
+
52
+ console.log('%c ' + requestMethod + ' ' + tableName, 'color: #cc0')
53
+
54
+ console.log('%c Request Data (note you may see the success and/or error prompt):', 'color: #cc0', request)
55
+
56
+ console.log('%c Response Data:', 'color: #cc0', cacheResult?.response?.data?.rest || cacheResult?.response?.data || cacheResult?.response)
57
+
58
+ console.groupEnd()
59
+
60
+ }
61
+
62
+ return undefined;
63
+
64
+ }
65
+
66
+ return false;
67
+ }
@@ -0,0 +1,24 @@
1
+ import isVerbose from "variables/isVerbose";
2
+
3
+ /**
4
+ * Conditionally group a log if verbose.
5
+ */
6
+ export function group(title: string, data?: any): void {
7
+ if (!isVerbose) return;
8
+ console.groupCollapsed(`%c${title}`, "color: #007acc");
9
+ if (data !== undefined) console.log(data);
10
+ console.groupEnd();
11
+ }
12
+
13
+ export function info(message: string, ...optional: any[]): void {
14
+ if (!isVerbose) return;
15
+ console.info(`%cINFO: ${message}`, "color: #0a0", ...optional);
16
+ }
17
+
18
+ export function warn(message: string, ...optional: any[]): void {
19
+ console.warn(`%cWARN: ${message}`, "color: #e90", ...optional);
20
+ }
21
+
22
+ export function error(message: string, ...optional: any[]): void {
23
+ console.error(`%cERROR: ${message}`, "color: #c00", ...optional);
24
+ }
@@ -0,0 +1,12 @@
1
+
2
+ export function sortAndSerializeQueryObject(tables: String, query: Object) {
3
+ const orderedQuery = Object.keys(query).sort().reduce(
4
+ (obj, key) => {
5
+ obj[key] = query[key];
6
+ return obj;
7
+ },
8
+ {}
9
+ );
10
+
11
+ return tables + ' ' + JSON.stringify(orderedQuery);
12
+ }
@@ -0,0 +1,24 @@
1
+ import {apiRequestCache} from "./cacheManager";
2
+
3
+ export function checkAllRequestsComplete(): true | (string[]) {
4
+
5
+ const stillRunning = apiRequestCache.filter((cache) => undefined === cache.response)
6
+
7
+ if (stillRunning.length !== 0) {
8
+
9
+ if (document === null || document === undefined) {
10
+
11
+ throw new Error('document is undefined while waiting for API requests to complete (' + JSON.stringify(apiRequestCache) + ')')
12
+
13
+ }
14
+
15
+ // when requests return emtpy sets in full renders, it may not be possible to track their progress.
16
+ console.warn('stillRunning...', stillRunning)
17
+
18
+ return stillRunning.map((cache) => cache.requestArgumentsSerialized)
19
+
20
+ }
21
+
22
+ return true
23
+
24
+ }
@@ -0,0 +1,11 @@
1
+ import { toast } from "react-toastify";
2
+ import { toastOptions, toastOptionsDevs } from "variables/toastOptions";
3
+ import isLocal from "variables/isLocal";
4
+
5
+ export function onSuccess(message: string): void {
6
+ toast.success(message, isLocal ? toastOptionsDevs : toastOptions);
7
+ }
8
+
9
+ export function onError(message: string): void {
10
+ toast.error(message, isLocal ? toastOptionsDevs : toastOptions);
11
+ }
package/src/index.ts CHANGED
@@ -5,14 +5,26 @@
5
5
  export * from "./api/C6Constants";
6
6
  export { default as axiosInstance } from "./api/axiosInstance";
7
7
  export * from "./api/axiosInstance";
8
- export * from "./api/carbonSqlExecutor";
9
8
  export { default as convertForRequestBody } from "./api/convertForRequestBody";
10
9
  export * from "./api/convertForRequestBody";
11
10
  export { default as restRequest } from "./api/restRequest";
12
11
  export * from "./api/restRequest";
13
12
  export { default as timeout } from "./api/timeout";
14
13
  export * from "./api/timeout";
15
- export * from "./api/interfaces/ormInterfaces";
14
+ export * from "./api/builders/sqlBuilder";
15
+ export * from "./api/executors/Executor";
16
+ export * from "./api/executors/HttpExecutor";
17
+ export * from "./api/executors/SqlExecutor";
18
+ export * from "./api/types/dynamicFetching";
19
+ export * from "./api/types/modifyTypes";
20
+ export * from "./api/types/mysqlTypes";
21
+ export * from "./api/types/ormInterfaces";
22
+ export * from "./api/utils/apiHelpers";
23
+ export * from "./api/utils/cacheManager";
24
+ export * from "./api/utils/logger";
25
+ export * from "./api/utils/sortAndSerializeQueryObject";
26
+ export * from "./api/utils/testHelpers";
27
+ export * from "./api/utils/toastNotifier";
16
28
  export * from "./variables/getEnvVar";
17
29
  export { default as isLocal } from "./variables/isLocal";
18
30
  export * from "./variables/isLocal";