@carbonorm/carbonnode 3.5.2 → 3.5.4
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/orm/builders/ConditionBuilder.d.ts +1 -0
- package/dist/index.cjs.js +54 -44
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +54 -44
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/api/executors/Executor.ts +1 -2
- package/src/api/executors/HttpExecutor.ts +1 -2
- package/src/api/executors/SqlExecutor.ts +4 -1
- package/src/api/orm/builders/AggregateBuilder.ts +1 -2
- package/src/api/orm/builders/ConditionBuilder.ts +14 -9
- package/src/api/orm/builders/JoinBuilder.ts +4 -2
- package/src/api/orm/builders/PaginationBuilder.ts +1 -2
- package/src/api/orm/queries/DeleteQueryBuilder.ts +1 -0
- package/src/api/orm/queries/PostQueryBuilder.ts +1 -0
- package/src/api/orm/queries/SelectQueryBuilder.ts +1 -0
- package/src/api/orm/queries/UpdateQueryBuilder.ts +1 -0
- package/src/api/restRequest.ts +2 -0
- package/src/api/utils/logger.ts +0 -4
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
iRestReactiveLifecycle,
|
|
6
6
|
RequestQueryBody
|
|
7
7
|
} from "../types/ormInterfaces";
|
|
8
|
-
import isVerbose from "../../variables/isVerbose";
|
|
9
8
|
|
|
10
9
|
export abstract class Executor<
|
|
11
10
|
G extends OrmGenerics
|
|
@@ -40,7 +39,7 @@ export abstract class Executor<
|
|
|
40
39
|
|
|
41
40
|
for (const [key, fn] of Object.entries(lifecycleGroup)) {
|
|
42
41
|
if (typeof fn === "function") {
|
|
43
|
-
if (
|
|
42
|
+
if (this.config.verbose || (args.request as any).debug) {
|
|
44
43
|
console.groupCollapsed(`[LIFECYCLE] ${this.config.requestMethod}.${String(phase)}:${key}`);
|
|
45
44
|
console.log("config:", args.config);
|
|
46
45
|
console.log("request:", args.request);
|
|
@@ -2,7 +2,6 @@ import {AxiosPromise, AxiosResponse} from "axios";
|
|
|
2
2
|
import {toast} from "react-toastify";
|
|
3
3
|
import isLocal from "../../variables/isLocal";
|
|
4
4
|
import isTest from "../../variables/isTest";
|
|
5
|
-
import isVerbose from "../../variables/isVerbose";
|
|
6
5
|
import convertForRequestBody from "../convertForRequestBody";
|
|
7
6
|
import {eFetchDependencies} from "../types/dynamicFetching";
|
|
8
7
|
import {OrmGenerics} from "../types/ormGenerics";
|
|
@@ -609,7 +608,7 @@ export class HttpExecutor<
|
|
|
609
608
|
returnGetNextPageFunction = 1 !== query?.[C6.PAGINATION]?.[C6.LIMIT] &&
|
|
610
609
|
query?.[C6.PAGINATION]?.[C6.LIMIT] === responseData.rest.length
|
|
611
610
|
|
|
612
|
-
if (false === isTest() ||
|
|
611
|
+
if (false === isTest() || this.config.verbose) {
|
|
613
612
|
|
|
614
613
|
console.groupCollapsed('%c API: Response (' + requestMethod + ' ' + tableName + ') returned length (' + responseData.rest?.length + ') of possible (' + query?.[C6.PAGINATION]?.[C6.LIMIT] + ') limit!', 'color: #0c0')
|
|
615
614
|
|
|
@@ -19,7 +19,10 @@ export class SqlExecutor<
|
|
|
19
19
|
const {TABLE_NAME} = this.config.restModel;
|
|
20
20
|
const method = this.config.requestMethod;
|
|
21
21
|
|
|
22
|
-
console.log(`[SQL EXECUTOR] ▶️ Executing ${method} on table "${TABLE_NAME}"`);
|
|
22
|
+
this.config.verbose && console.log(`[SQL EXECUTOR] ▶️ Executing ${method} on table "${TABLE_NAME}"`);
|
|
23
|
+
this.config.verbose && console.log(`[SQL EXECUTOR] 🧩 Request body:`, this.request.body);
|
|
24
|
+
this.config.verbose && console.log(`[SQL EXECUTOR] 🧩 Request query:`, this.request.query);
|
|
25
|
+
|
|
23
26
|
|
|
24
27
|
switch (method) {
|
|
25
28
|
case 'GET': {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import isVerbose from "../../../variables/isVerbose";
|
|
2
1
|
import {Executor} from "../../executors/Executor";
|
|
3
2
|
import {OrmGenerics} from "../../types/ormGenerics";
|
|
4
3
|
|
|
@@ -31,7 +30,7 @@ export abstract class AggregateBuilder<G extends OrmGenerics> extends Executor<G
|
|
|
31
30
|
expr += ` AS ${alias}`;
|
|
32
31
|
}
|
|
33
32
|
|
|
34
|
-
|
|
33
|
+
this.config.verbose && console.log(`[SELECT] ${expr}`);
|
|
35
34
|
|
|
36
35
|
return expr;
|
|
37
36
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {C6C} from "api/C6Constants";
|
|
2
|
-
import isVerbose from "../../../variables/isVerbose";
|
|
3
2
|
import {OrmGenerics} from "../../types/ormGenerics";
|
|
4
3
|
import {DetermineResponseDataType} from "../../types/ormInterfaces";
|
|
5
4
|
import {convertHexIfBinary, SqlBuilderResult} from "../utils/sqlUtils";
|
|
@@ -9,6 +8,8 @@ export abstract class ConditionBuilder<
|
|
|
9
8
|
G extends OrmGenerics
|
|
10
9
|
> extends AggregateBuilder<G> {
|
|
11
10
|
|
|
11
|
+
protected aliasMappings: Record<string, string> = {};
|
|
12
|
+
|
|
12
13
|
abstract build(table: string): SqlBuilderResult;
|
|
13
14
|
|
|
14
15
|
execute(): Promise<DetermineResponseDataType<G['RequestMethod'], G['RestTableInterface']>> {
|
|
@@ -27,13 +28,13 @@ export abstract class ConditionBuilder<
|
|
|
27
28
|
]);
|
|
28
29
|
|
|
29
30
|
private isTableReference(val: any): boolean {
|
|
30
|
-
|
|
31
|
-
const [
|
|
32
|
-
const
|
|
31
|
+
if (typeof val !== 'string' || !val.includes('.')) return false;
|
|
32
|
+
const [prefix, column] = val.split('.');
|
|
33
|
+
const tableName = this.aliasMappings[prefix] ?? prefix;
|
|
34
|
+
return (
|
|
33
35
|
typeof this.config.C6?.TABLES[tableName] === 'object' &&
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return is
|
|
36
|
+
column in this.config.C6.TABLES[tableName].COLUMNS
|
|
37
|
+
);
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
private validateOperator(op: string) {
|
|
@@ -111,7 +112,7 @@ export abstract class ConditionBuilder<
|
|
|
111
112
|
throw new Error(`MATCH_AGAINST requires a table reference as the left operand. Column '${column}' is not a valid table reference.`);
|
|
112
113
|
}
|
|
113
114
|
const matchClause = `(MATCH(${column}) ${againstClause})`;
|
|
114
|
-
|
|
115
|
+
this.config.verbose && console.log(`[MATCH_AGAINST] ${matchClause}`);
|
|
115
116
|
return matchClause;
|
|
116
117
|
}
|
|
117
118
|
|
|
@@ -141,6 +142,10 @@ export abstract class ConditionBuilder<
|
|
|
141
142
|
return `(${column}) ${op} ${value}`;
|
|
142
143
|
}
|
|
143
144
|
|
|
145
|
+
if (leftIsRef && !rightIsRef) {
|
|
146
|
+
return `(${column}) ${op} ${this.addParam(params, column, value)}`;
|
|
147
|
+
}
|
|
148
|
+
|
|
144
149
|
if (rightIsRef) {
|
|
145
150
|
return `(${this.addParam(params, column, column)}) ${op} ${value}`;
|
|
146
151
|
}
|
|
@@ -195,7 +200,7 @@ export abstract class ConditionBuilder<
|
|
|
195
200
|
const clause = this.buildBooleanJoinedConditions(whereArg, true, params);
|
|
196
201
|
if (!clause) return '';
|
|
197
202
|
const trimmed = clause.replace(/^\((.*)\)$/, '$1');
|
|
198
|
-
|
|
203
|
+
this.config.verbose && console.log(`[WHERE] ${trimmed}`);
|
|
199
204
|
return ` WHERE ${trimmed}`;
|
|
200
205
|
}
|
|
201
206
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import isVerbose from "../../../variables/isVerbose";
|
|
2
1
|
import {OrmGenerics} from "../../types/ormGenerics";
|
|
3
2
|
import {ConditionBuilder} from "./ConditionBuilder";
|
|
4
3
|
|
|
@@ -12,13 +11,16 @@ export abstract class JoinBuilder<G extends OrmGenerics> extends ConditionBuilde
|
|
|
12
11
|
|
|
13
12
|
for (const raw in joinArgs[joinType]) {
|
|
14
13
|
const [table, alias] = raw.split(' ');
|
|
14
|
+
if (alias) {
|
|
15
|
+
this.aliasMappings[alias] = table;
|
|
16
|
+
}
|
|
15
17
|
const onClause = this.buildBooleanJoinedConditions(joinArgs[joinType][raw], true, params);
|
|
16
18
|
const joinSql = alias ? `\`${table}\` AS \`${alias}\`` : `\`${table}\``;
|
|
17
19
|
sql += ` ${joinKind} JOIN ${joinSql} ON ${onClause}`;
|
|
18
20
|
}
|
|
19
21
|
}
|
|
20
22
|
|
|
21
|
-
|
|
23
|
+
this.config.verbose && console.log(`[JOIN] ${sql.trim()}`);
|
|
22
24
|
|
|
23
25
|
return sql;
|
|
24
26
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {C6Constants} from "api/C6Constants";
|
|
2
|
-
import isVerbose from "../../../variables/isVerbose";
|
|
3
2
|
import {OrmGenerics} from "../../types/ormGenerics";
|
|
4
3
|
import {JoinBuilder} from "./JoinBuilder";
|
|
5
4
|
|
|
@@ -50,7 +49,7 @@ export abstract class PaginationBuilder<G extends OrmGenerics> extends JoinBuild
|
|
|
50
49
|
sql += ` LIMIT ${offset}, ${lim}`;
|
|
51
50
|
}
|
|
52
51
|
|
|
53
|
-
|
|
52
|
+
this.config.verbose && console.log(`[PAGINATION] ${sql.trim()}`);
|
|
54
53
|
return sql;
|
|
55
54
|
}
|
|
56
55
|
}
|
|
@@ -14,6 +14,7 @@ export class PostQueryBuilder<G extends OrmGenerics> extends ConditionBuilder<G>
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
build(table: string) {
|
|
17
|
+
this.aliasMappings = {};
|
|
17
18
|
const verb = C6C.REPLACE in this.request ? C6C.REPLACE : C6C.INSERT;
|
|
18
19
|
const body = verb in this.request ? this.request[verb] : this.request;
|
|
19
20
|
const keys = Object.keys(body);
|
|
@@ -8,6 +8,7 @@ export class SelectQueryBuilder<G extends OrmGenerics> extends PaginationBuilder
|
|
|
8
8
|
table: string,
|
|
9
9
|
isSubSelect: boolean = false
|
|
10
10
|
): SqlBuilderResult {
|
|
11
|
+
this.aliasMappings = {};
|
|
11
12
|
const args = this.request;
|
|
12
13
|
const params = this.useNamedParams ? {} : [];
|
|
13
14
|
const selectList = args.SELECT ?? ['*'];
|
|
@@ -8,6 +8,7 @@ export class UpdateQueryBuilder<G extends OrmGenerics> extends PaginationBuilder
|
|
|
8
8
|
build(
|
|
9
9
|
table: string,
|
|
10
10
|
): SqlBuilderResult {
|
|
11
|
+
this.aliasMappings = {};
|
|
11
12
|
const args = this.request;
|
|
12
13
|
const params = this.useNamedParams ? {} : [];
|
|
13
14
|
let sql = `UPDATE \`${table}\``;
|
package/src/api/restRequest.ts
CHANGED
|
@@ -32,6 +32,8 @@ export default function restRequest<
|
|
|
32
32
|
|
|
33
33
|
const config = typeof configX === "function" ? configX() : configX;
|
|
34
34
|
|
|
35
|
+
config.verbose ??= true; // Default to verbose logging if not set
|
|
36
|
+
|
|
35
37
|
// SQL path if on Node with a provided pool
|
|
36
38
|
if (isNode() && config.mysqlPool) {
|
|
37
39
|
const {SqlExecutor} = await import('./executors/SqlExecutor');
|
package/src/api/utils/logger.ts
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
import isVerbose from "variables/isVerbose";
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* Conditionally group a log if verbose.
|
|
5
3
|
*/
|
|
6
4
|
export function group(title: string, data?: any): void {
|
|
7
|
-
if (!isVerbose()) return;
|
|
8
5
|
console.groupCollapsed(`%c${title}`, "color: #007acc");
|
|
9
6
|
if (data !== undefined) console.log(data);
|
|
10
7
|
console.groupEnd();
|
|
11
8
|
}
|
|
12
9
|
|
|
13
10
|
export function info(message: string, ...optional: any[]): void {
|
|
14
|
-
if (!isVerbose()) return;
|
|
15
11
|
console.info(`%cINFO: ${message}`, "color: #0a0", ...optional);
|
|
16
12
|
}
|
|
17
13
|
|