@carbonorm/carbonnode 3.10.0 → 4.0.0

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 (33) hide show
  1. package/dist/api/C6Constants.d.ts +20 -0
  2. package/dist/api/orm/builders/ConditionBuilder.d.ts +8 -0
  3. package/dist/api/orm/builders/JoinBuilder.d.ts +9 -0
  4. package/dist/api/orm/queries/PostQueryBuilder.d.ts +1 -1
  5. package/dist/api/restOrm.d.ts +4 -4
  6. package/dist/api/types/ormInterfaces.d.ts +32 -12
  7. package/dist/api/utils/cacheManager.d.ts +7 -8
  8. package/dist/index.cjs.js +566 -142
  9. package/dist/index.cjs.js.map +1 -1
  10. package/dist/index.esm.js +562 -141
  11. package/dist/index.esm.js.map +1 -1
  12. package/package.json +1 -1
  13. package/src/__tests__/cacheManager.test.ts +67 -0
  14. package/src/__tests__/expressServer.e2e.test.ts +104 -2
  15. package/src/__tests__/fixtures/c6.fixture.ts +5 -0
  16. package/src/__tests__/httpExecutorSingular.e2e.test.ts +35 -4
  17. package/src/__tests__/sakila-db/C6.js +1 -1
  18. package/src/__tests__/sakila-db/C6.ts +1 -1
  19. package/src/__tests__/sqlBuilders.complex.test.ts +85 -0
  20. package/src/__tests__/sqlBuilders.test.ts +28 -0
  21. package/src/api/C6Constants.ts +12 -2
  22. package/src/api/axiosInstance.ts +29 -0
  23. package/src/api/executors/HttpExecutor.ts +73 -97
  24. package/src/api/handlers/ExpressHandler.ts +30 -7
  25. package/src/api/orm/builders/ConditionBuilder.ts +227 -0
  26. package/src/api/orm/builders/JoinBuilder.ts +150 -1
  27. package/src/api/orm/queries/PostQueryBuilder.ts +4 -2
  28. package/src/api/orm/queries/SelectQueryBuilder.ts +5 -0
  29. package/src/api/orm/queries/UpdateQueryBuilder.ts +3 -1
  30. package/src/api/types/ormInterfaces.ts +32 -18
  31. package/src/api/utils/cacheManager.ts +75 -34
  32. package/src/api/utils/testHelpers.ts +5 -3
  33. package/src/variables/isNode.ts +1 -8
@@ -27,10 +27,12 @@ export declare const C6Constants: {
27
27
  DATE_FORMAT: string;
28
28
  DESC: string;
29
29
  DISTINCT: string;
30
+ EXISTS: string;
30
31
  EXTRACT: string;
31
32
  EQUAL: string;
32
33
  EQUAL_NULL_SAFE: string;
33
34
  FALSE: string;
35
+ FORCE: string;
34
36
  FULL_OUTER: string;
35
37
  FROM_DAYS: string;
36
38
  FROM_UNIXTIME: string;
@@ -46,6 +48,7 @@ export declare const C6Constants: {
46
48
  HOUR_SECOND: string;
47
49
  HOUR_MINUTE: string;
48
50
  IN: string;
51
+ INDEX: string;
49
52
  IS: string;
50
53
  IS_NOT: string;
51
54
  INNER: string;
@@ -63,6 +66,7 @@ export declare const C6Constants: {
63
66
  MAKEDATE: string;
64
67
  MAKETIME: string;
65
68
  MATCH_AGAINST: string;
69
+ MBRCONTAINS: string;
66
70
  MONTHNAME: string;
67
71
  MICROSECOND: string;
68
72
  MINUTE: string;
@@ -78,8 +82,14 @@ export declare const C6Constants: {
78
82
  NULL: string;
79
83
  ORDER: string;
80
84
  OR: string;
85
+ INDEX_HINTS: string;
86
+ FORCE_INDEX: string;
87
+ USE_INDEX: string;
88
+ IGNORE_INDEX: string;
81
89
  PAGE: string;
82
90
  PAGINATION: string;
91
+ POLYGON: string;
92
+ POINT: string;
83
93
  RIGHT_OUTER: string;
84
94
  SECOND: string;
85
95
  SECOND_MICROSECOND: string;
@@ -188,10 +198,12 @@ export declare const C6C: {
188
198
  DATE_FORMAT: string;
189
199
  DESC: string;
190
200
  DISTINCT: string;
201
+ EXISTS: string;
191
202
  EXTRACT: string;
192
203
  EQUAL: string;
193
204
  EQUAL_NULL_SAFE: string;
194
205
  FALSE: string;
206
+ FORCE: string;
195
207
  FULL_OUTER: string;
196
208
  FROM_DAYS: string;
197
209
  FROM_UNIXTIME: string;
@@ -207,6 +219,7 @@ export declare const C6C: {
207
219
  HOUR_SECOND: string;
208
220
  HOUR_MINUTE: string;
209
221
  IN: string;
222
+ INDEX: string;
210
223
  IS: string;
211
224
  IS_NOT: string;
212
225
  INNER: string;
@@ -224,6 +237,7 @@ export declare const C6C: {
224
237
  MAKEDATE: string;
225
238
  MAKETIME: string;
226
239
  MATCH_AGAINST: string;
240
+ MBRCONTAINS: string;
227
241
  MONTHNAME: string;
228
242
  MICROSECOND: string;
229
243
  MINUTE: string;
@@ -239,8 +253,14 @@ export declare const C6C: {
239
253
  NULL: string;
240
254
  ORDER: string;
241
255
  OR: string;
256
+ INDEX_HINTS: string;
257
+ FORCE_INDEX: string;
258
+ USE_INDEX: string;
259
+ IGNORE_INDEX: string;
242
260
  PAGE: string;
243
261
  PAGINATION: string;
262
+ POLYGON: string;
263
+ POINT: string;
244
264
  RIGHT_OUTER: string;
245
265
  SECOND: string;
246
266
  SECOND_MICROSECOND: string;
@@ -13,6 +13,7 @@ export declare abstract class ConditionBuilder<G extends OrmGenerics> extends Ag
13
13
  execute(): Promise<DetermineResponseDataType<G['RequestMethod'], G['RestTableInterface']>>;
14
14
  private readonly BOOLEAN_OPERATORS;
15
15
  private readonly OPERATOR_ALIASES;
16
+ private readonly BOOLEAN_FUNCTION_KEYS;
16
17
  private isTableReference;
17
18
  addParam(params: any[] | Record<string, any>, column: string, value: any): string;
18
19
  private normalizeOperatorKey;
@@ -24,6 +25,13 @@ export declare abstract class ConditionBuilder<G extends OrmGenerics> extends Ag
24
25
  private normalizeFunctionField;
25
26
  private buildFunctionCall;
26
27
  private serializeOperand;
28
+ private isPlainArrayLiteral;
29
+ private isPlainObjectLiteral;
30
+ protected serializeUpdateValue(value: any, params: any[] | Record<string, any>, contextColumn?: string): string;
31
+ private ensurePlainObject;
32
+ private resolveExistsInnerColumn;
33
+ private normalizeExistsSpec;
34
+ private buildExistsExpression;
27
35
  private buildOperatorExpression;
28
36
  private buildLegacyColumnCondition;
29
37
  private buildBooleanExpression;
@@ -1,12 +1,21 @@
1
1
  import { OrmGenerics } from "../../types/ormGenerics";
2
2
  import { ConditionBuilder } from "./ConditionBuilder";
3
3
  export declare abstract class JoinBuilder<G extends OrmGenerics> extends ConditionBuilder<G> {
4
+ private indexHintCache?;
4
5
  protected createSelectBuilder(_request: any): {
5
6
  build(table: string, isSubSelect: boolean): {
6
7
  sql: string;
7
8
  params: any[] | Record<string, any>;
8
9
  };
9
10
  };
11
+ protected resetIndexHints(): void;
12
+ private normalizeIndexHintKey;
13
+ private normalizeHintTargetKey;
14
+ private hasIndexHintKeys;
15
+ private normalizeHintSpec;
16
+ private formatIndexHintClause;
17
+ private normalizeIndexHints;
18
+ protected getIndexHintClause(table: string, alias?: string): string;
10
19
  buildJoinClauses(joinArgs: any, params: any[] | Record<string, any>): string;
11
20
  protected integrateSubSelectParams(subSql: string, subParams: any[] | Record<string, any>, target: any[] | Record<string, any>): string;
12
21
  protected buildScalarSubSelect(subRequest: any, params: any[] | Record<string, any>): string;
@@ -4,6 +4,6 @@ export declare class PostQueryBuilder<G extends OrmGenerics> extends ConditionBu
4
4
  private trimTablePrefix;
5
5
  build(table: string): {
6
6
  sql: string;
7
- params: any[];
7
+ params: any[] | Record<string, any>;
8
8
  };
9
9
  }
@@ -4,9 +4,9 @@ type WithMethod<G extends Omit<OrmGenerics, "RequestMethod">, M extends iRestMet
4
4
  RequestMethod: M;
5
5
  };
6
6
  export declare function restOrm<G extends Omit<OrmGenerics, "RequestMethod">>(configFn: () => Omit<iRest<G['RestShortTableName'], G['RestTableInterface'], G['PrimaryKey']>, "requestMethod">): {
7
- Get: (request: import("./types/ormInterfaces").RequestQueryBody<WithMethod<G, "GET">["RequestMethod"], WithMethod<G, "GET">["RestTableInterface"], WithMethod<G, "GET">["CustomAndRequiredFields"], WithMethod<G, "GET">["RequestTableOverrides"]>) => Promise<import("./types/ormInterfaces").DetermineResponseDataType<WithMethod<G, "GET">["RequestMethod"], WithMethod<G, "GET">["RestTableInterface"]>>;
8
- Put: (request: import("./types/ormInterfaces").RequestQueryBody<WithMethod<G, "PUT">["RequestMethod"], WithMethod<G, "PUT">["RestTableInterface"], WithMethod<G, "PUT">["CustomAndRequiredFields"], WithMethod<G, "PUT">["RequestTableOverrides"]>) => Promise<import("./types/ormInterfaces").DetermineResponseDataType<WithMethod<G, "PUT">["RequestMethod"], WithMethod<G, "PUT">["RestTableInterface"]>>;
9
- Post: (request: import("./types/ormInterfaces").RequestQueryBody<WithMethod<G, "POST">["RequestMethod"], WithMethod<G, "POST">["RestTableInterface"], WithMethod<G, "POST">["CustomAndRequiredFields"], WithMethod<G, "POST">["RequestTableOverrides"]>) => Promise<import("./types/ormInterfaces").DetermineResponseDataType<WithMethod<G, "POST">["RequestMethod"], WithMethod<G, "POST">["RestTableInterface"]>>;
10
- Delete: (request: import("./types/ormInterfaces").RequestQueryBody<WithMethod<G, "DELETE">["RequestMethod"], WithMethod<G, "DELETE">["RestTableInterface"], WithMethod<G, "DELETE">["CustomAndRequiredFields"], WithMethod<G, "DELETE">["RequestTableOverrides"]>) => Promise<import("./types/ormInterfaces").DetermineResponseDataType<WithMethod<G, "DELETE">["RequestMethod"], WithMethod<G, "DELETE">["RestTableInterface"]>>;
7
+ Get: (request: import("./types/ormInterfaces").RequestQueryBody<WithMethod<G, "GET">["RequestMethod"], WithMethod<G, "GET">["RestTableInterface"], WithMethod<G, "GET">["CustomAndRequiredFields"], WithMethod<G, "GET">["RequestTableOverrides"]>) => Promise<import("./types/ormInterfaces").DetermineResponseDataType<WithMethod<G, "GET">["RequestMethod"], WithMethod<G, "GET">["RestTableInterface"], {}>>;
8
+ Put: (request: import("./types/ormInterfaces").RequestQueryBody<WithMethod<G, "PUT">["RequestMethod"], WithMethod<G, "PUT">["RestTableInterface"], WithMethod<G, "PUT">["CustomAndRequiredFields"], WithMethod<G, "PUT">["RequestTableOverrides"]>) => Promise<import("./types/ormInterfaces").DetermineResponseDataType<WithMethod<G, "PUT">["RequestMethod"], WithMethod<G, "PUT">["RestTableInterface"], {}>>;
9
+ Post: (request: import("./types/ormInterfaces").RequestQueryBody<WithMethod<G, "POST">["RequestMethod"], WithMethod<G, "POST">["RestTableInterface"], WithMethod<G, "POST">["CustomAndRequiredFields"], WithMethod<G, "POST">["RequestTableOverrides"]>) => Promise<import("./types/ormInterfaces").DetermineResponseDataType<WithMethod<G, "POST">["RequestMethod"], WithMethod<G, "POST">["RestTableInterface"], {}>>;
10
+ Delete: (request: import("./types/ormInterfaces").RequestQueryBody<WithMethod<G, "DELETE">["RequestMethod"], WithMethod<G, "DELETE">["RestTableInterface"], WithMethod<G, "DELETE">["CustomAndRequiredFields"], WithMethod<G, "DELETE">["RequestTableOverrides"]>) => Promise<import("./types/ormInterfaces").DetermineResponseDataType<WithMethod<G, "DELETE">["RequestMethod"], WithMethod<G, "DELETE">["RestTableInterface"], {}>>;
11
11
  };
12
12
  export {};
@@ -87,34 +87,54 @@ export type RequestQueryBody<Method extends iRestMethods, T extends {
87
87
  export interface iCacheAPI<ResponseDataType = any> {
88
88
  requestArgumentsSerialized: string;
89
89
  request: AxiosPromise<ResponseDataType>;
90
- response?: AxiosResponse;
90
+ response?: AxiosResponse & {
91
+ __carbonTiming?: {
92
+ start: number;
93
+ end: number;
94
+ duration: number;
95
+ };
96
+ };
91
97
  final?: boolean;
92
98
  }
93
99
  export interface iChangeC6Data {
94
100
  rowCount: number;
95
101
  }
96
- export interface iDeleteC6RestResponse<RestData = any, RequestData = any> extends iChangeC6Data, iC6RestResponse<RestData> {
102
+ export type C6RestResponse<Method extends iRestMethods, RestData extends {
103
+ [key: string]: any;
104
+ }, Overrides = {}> = {
105
+ rest: Method extends 'GET' ? Modify<RestData, Overrides>[] : Modify<RestData, Overrides>;
106
+ session?: any;
107
+ sql?: any;
108
+ } & (Method extends 'GET' ? {
109
+ next?: () => Promise<DetermineResponseDataType<'GET', RestData, Overrides>>;
110
+ } : {});
111
+ export interface iC6RestResponse<RestData> {
112
+ rest: RestData;
113
+ session?: any;
114
+ sql?: any;
115
+ }
116
+ export interface iDeleteC6RestResponse<RestData extends {
117
+ [key: string]: any;
118
+ }, RequestData = any> extends iChangeC6Data, C6RestResponse<'DELETE', RestData> {
97
119
  deleted: boolean | number | string | RequestData;
98
120
  }
99
- export interface iPostC6RestResponse<RestData = any> extends iC6RestResponse<RestData> {
121
+ export interface iPostC6RestResponse<RestData extends {
122
+ [key: string]: any;
123
+ }> extends C6RestResponse<'POST', RestData> {
100
124
  created: boolean | number | string;
101
125
  }
102
- export interface iPutC6RestResponse<RestData = any, RequestData = any> extends iChangeC6Data, iC6RestResponse<RestData> {
126
+ export interface iPutC6RestResponse<RestData extends {
127
+ [key: string]: any;
128
+ }, RequestData = any> extends iChangeC6Data, C6RestResponse<'PUT', RestData> {
103
129
  updated: boolean | number | string | RequestData;
104
130
  }
105
- export interface iC6RestResponse<RestData> {
106
- rest: RestData;
107
- session?: any;
108
- sql?: any;
109
- }
110
131
  export interface iGetC6RestResponse<ResponseDataType extends {
111
132
  [key: string]: any;
112
- }, ResponseDataOverrides = {}> extends iC6RestResponse<Modify<ResponseDataType, ResponseDataOverrides>[]> {
113
- next?: () => Promise<DetermineResponseDataType<"GET", ResponseDataType, ResponseDataOverrides>>;
133
+ }, ResponseDataOverrides = {}> extends C6RestResponse<'GET', ResponseDataType, ResponseDataOverrides> {
114
134
  }
115
135
  export type DetermineResponseDataType<Method extends iRestMethods, RestTableInterface extends {
116
136
  [key: string]: any;
117
- }, ResponseDataOverrides = {}> = null | (Method extends 'POST' ? iPostC6RestResponse<RestTableInterface> : Method extends 'GET' ? iGetC6RestResponse<RestTableInterface, ResponseDataOverrides> : Method extends 'PUT' ? iPutC6RestResponse<RestTableInterface> : Method extends 'DELETE' ? iDeleteC6RestResponse<RestTableInterface> : never);
137
+ }, ResponseDataOverrides = {}> = (Method extends 'POST' ? iPostC6RestResponse<RestTableInterface> : Method extends 'GET' ? iGetC6RestResponse<RestTableInterface, ResponseDataOverrides> : Method extends 'PUT' ? iPutC6RestResponse<RestTableInterface> : Method extends 'DELETE' ? iDeleteC6RestResponse<RestTableInterface> : never);
118
138
  export interface iRest<RestShortTableName extends string = any, RestTableInterface extends Record<string, any> = any, PrimaryKey extends keyof RestTableInterface & string = keyof RestTableInterface & string> {
119
139
  C6: iC6Object;
120
140
  axios?: AxiosInstance;
@@ -1,10 +1,9 @@
1
1
  import { AxiosPromise } from "axios";
2
2
  import { iCacheAPI } from "../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 | AxiosPromise<ResponseDataType>;
10
- export {};
3
+ export declare const apiRequestCache: Map<string, iCacheAPI<any>>;
4
+ export declare const userCustomClearCache: (() => void)[];
5
+ export declare function clearCache(props?: {
6
+ ignoreWarning?: boolean;
7
+ }): void;
8
+ export declare function checkCache<ResponseDataType = any>(method: string, tableName: string | string[], requestData: any): AxiosPromise<ResponseDataType> | false;
9
+ export declare function setCache<ResponseDataType = any>(method: string, tableName: string | string[], requestData: any, cacheEntry: iCacheAPI<ResponseDataType>): void;