@carbonorm/carbonnode 3.0.13 → 3.1.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.
- package/dist/api/C6Constants.d.ts +184 -0
- package/dist/api/builders/queryHelpers.d.ts +4 -0
- package/dist/api/builders/sqlBuilder.d.ts +17 -5
- package/dist/api/executors/Executor.d.ts +9 -15
- package/dist/api/executors/HttpExecutor.d.ts +7 -14
- package/dist/api/executors/SqlExecutor.d.ts +43 -14
- package/dist/api/orm/SqlBuilder.d.ts +17 -0
- package/dist/api/orm/builders/AggregateBuilder.d.ts +5 -0
- package/dist/api/orm/builders/ConditionBuilder.d.ts +11 -0
- package/dist/api/orm/builders/JoinBuilder.d.ts +5 -0
- package/dist/api/orm/builders/PaginationBuilder.d.ts +5 -0
- package/dist/api/orm/queries/DeleteQueryBuilder.d.ts +6 -0
- package/dist/api/orm/queries/SelectQueryBuilder.d.ts +6 -0
- package/dist/api/orm/queries/UpdateQueryBuilder.d.ts +6 -0
- package/dist/api/orm/queryHelpers.d.ts +4 -0
- package/dist/api/orm/utils/sqlUtils.d.ts +7 -0
- package/dist/api/restOrm.d.ts +3 -10
- package/dist/api/restRequest.d.ts +3 -10
- package/dist/api/types/ormGenerics.d.ts +13 -0
- package/dist/api/types/ormInterfaces.d.ts +23 -40
- package/dist/index.cjs.js +444 -249
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.esm.js +432 -249
- package/dist/index.esm.js.map +1 -1
- package/package.json +7 -2
- package/scripts/assets/handlebars/C6.ts.handlebars +2 -4
- package/scripts/generateRestBindings.cjs +1 -1
- package/scripts/generateRestBindings.ts +1 -1
- package/src/api/C6Constants.ts +38 -2
- package/src/api/executors/Executor.ts +18 -36
- package/src/api/executors/HttpExecutor.ts +46 -59
- package/src/api/executors/SqlExecutor.ts +89 -58
- package/src/api/handlers/ExpressHandler.ts +3 -2
- package/src/api/orm/builders/AggregateBuilder.ts +38 -0
- package/src/api/orm/builders/ConditionBuilder.ts +113 -0
- package/src/api/orm/builders/JoinBuilder.ts +25 -0
- package/src/api/orm/builders/PaginationBuilder.ts +28 -0
- package/src/api/orm/queries/DeleteQueryBuilder.ts +28 -0
- package/src/api/orm/queries/SelectQueryBuilder.ts +49 -0
- package/src/api/orm/queries/UpdateQueryBuilder.ts +42 -0
- package/src/api/orm/queryHelpers.ts +18 -0
- package/src/api/orm/utils/sqlUtils.ts +24 -0
- package/src/api/restOrm.ts +4 -14
- package/src/api/restRequest.ts +16 -34
- package/src/api/types/ormGenerics.ts +18 -0
- package/src/api/types/ormInterfaces.ts +28 -43
- package/src/index.ts +10 -1
- package/src/api/builders/sqlBuilder.ts +0 -223
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import isVerbose from "../../../variables/isVerbose";
|
|
2
|
+
import {OrmGenerics} from "../../types/ormGenerics";
|
|
3
|
+
import {ConditionBuilder} from "./ConditionBuilder";
|
|
4
|
+
|
|
5
|
+
export class JoinBuilder<G extends OrmGenerics> extends ConditionBuilder<G>{
|
|
6
|
+
|
|
7
|
+
buildJoinClauses(joinArgs: any, params: any[] | Record<string, any>): string {
|
|
8
|
+
let sql = '';
|
|
9
|
+
|
|
10
|
+
for (const joinType in joinArgs) {
|
|
11
|
+
const joinKind = joinType.replace('_', ' ').toUpperCase();
|
|
12
|
+
|
|
13
|
+
for (const raw in joinArgs[joinType]) {
|
|
14
|
+
const [table, alias] = raw.split(' ');
|
|
15
|
+
const onClause = this.buildBooleanJoinedConditions(joinArgs[joinType][raw], true, params);
|
|
16
|
+
const joinSql = alias ? `\`${table}\` AS \`${alias}\`` : `\`${table}\``;
|
|
17
|
+
sql += ` ${joinKind} JOIN ${joinSql} ON ${onClause}`;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
isVerbose() && console.log(`[JOIN] ${sql.trim()}`);
|
|
22
|
+
|
|
23
|
+
return sql;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {C6Constants} from "api/C6Constants";
|
|
2
|
+
import isVerbose from "../../../variables/isVerbose";
|
|
3
|
+
import {OrmGenerics} from "../../types/ormGenerics";
|
|
4
|
+
import {JoinBuilder} from "./JoinBuilder";
|
|
5
|
+
|
|
6
|
+
export class PaginationBuilder<G extends OrmGenerics> extends JoinBuilder<G> {
|
|
7
|
+
|
|
8
|
+
buildPaginationClause(pagination: any): string {
|
|
9
|
+
let sql = '';
|
|
10
|
+
|
|
11
|
+
if (pagination?.[C6Constants.ORDER]) {
|
|
12
|
+
const orderParts = Object.entries(pagination[C6Constants.ORDER])
|
|
13
|
+
.map(([col, dir]) => `${Array.isArray(col) ? this.buildAggregateField(col) : col} ${String(dir).toUpperCase()}`);
|
|
14
|
+
sql += ` ORDER BY ${orderParts.join(', ')}`;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (pagination?.[C6Constants.LIMIT] != null) {
|
|
18
|
+
const lim = parseInt(pagination[C6Constants.LIMIT], 10);
|
|
19
|
+
const page = parseInt(pagination[C6Constants.PAGE] ?? 1, 10);
|
|
20
|
+
const offset = (page - 1) * lim;
|
|
21
|
+
sql += ` LIMIT ${offset}, ${lim}`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
isVerbose() && console.log(`[PAGINATION] ${sql.trim()}`);
|
|
25
|
+
|
|
26
|
+
return sql;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {OrmGenerics} from "../../types/ormGenerics";
|
|
2
|
+
import {PaginationBuilder} from "../builders/PaginationBuilder";
|
|
3
|
+
import {SqlBuilderResult} from "../utils/sqlUtils";
|
|
4
|
+
|
|
5
|
+
export class DeleteQueryBuilder<G extends OrmGenerics>
|
|
6
|
+
extends PaginationBuilder<G> {
|
|
7
|
+
|
|
8
|
+
build(table: string, args: any = {}): SqlBuilderResult {
|
|
9
|
+
const params = this.useNamedParams ? {} : [];
|
|
10
|
+
let sql = args.JOIN ? `DELETE ${table}
|
|
11
|
+
FROM \`${table}\`` : `DELETE
|
|
12
|
+
FROM \`${table}\``;
|
|
13
|
+
|
|
14
|
+
if (args.JOIN) {
|
|
15
|
+
sql += this.buildJoinClauses(args.JOIN, params);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (args.WHERE) {
|
|
19
|
+
sql += this.buildWhereClause(args.WHERE, params);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (args.PAGINATION) {
|
|
23
|
+
sql += this.buildPaginationClause(args.PAGINATION);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return {sql, params};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import {OrmGenerics} from "../../types/ormGenerics";
|
|
2
|
+
import {PaginationBuilder} from "../builders/PaginationBuilder";
|
|
3
|
+
import {SqlBuilderResult} from "../utils/sqlUtils";
|
|
4
|
+
|
|
5
|
+
export class SelectQueryBuilder<G extends OrmGenerics> extends PaginationBuilder<G>{
|
|
6
|
+
|
|
7
|
+
build(
|
|
8
|
+
table: string,
|
|
9
|
+
args: any,
|
|
10
|
+
primary?: string,
|
|
11
|
+
isSubSelect: boolean = false
|
|
12
|
+
): SqlBuilderResult {
|
|
13
|
+
const params = this.useNamedParams ? {} : [];
|
|
14
|
+
|
|
15
|
+
const selectList = args.SELECT ?? ['*'];
|
|
16
|
+
const selectFields = selectList
|
|
17
|
+
.map((f: any) => this.buildAggregateField(f))
|
|
18
|
+
.join(', ');
|
|
19
|
+
|
|
20
|
+
let sql = `SELECT ${selectFields} FROM \`${table}\``;
|
|
21
|
+
|
|
22
|
+
if (args.JOIN) {
|
|
23
|
+
sql += this.buildJoinClauses(args.JOIN, params);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (args.WHERE) {
|
|
27
|
+
sql += this.buildWhereClause(args.WHERE, params);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (args.GROUP_BY) {
|
|
31
|
+
const groupBy = Array.isArray(args.GROUP_BY)
|
|
32
|
+
? args.GROUP_BY.join(', ')
|
|
33
|
+
: args.GROUP_BY;
|
|
34
|
+
sql += ` GROUP BY ${groupBy}`;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (args.HAVING) {
|
|
38
|
+
sql += ` HAVING ${this.buildBooleanJoinedConditions(args.HAVING, true, params)}`;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (args.PAGINATION) {
|
|
42
|
+
sql += this.buildPaginationClause(args.PAGINATION);
|
|
43
|
+
} else if (!isSubSelect) {
|
|
44
|
+
sql += primary ? ` ORDER BY ${primary} ASC LIMIT 1` : ` LIMIT 100`;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return { sql, params };
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import {OrmGenerics} from "../../types/ormGenerics";
|
|
2
|
+
import { PaginationBuilder } from '../builders/PaginationBuilder';
|
|
3
|
+
import {SqlBuilderResult} from "../utils/sqlUtils";
|
|
4
|
+
|
|
5
|
+
export class UpdateQueryBuilder<G extends OrmGenerics> extends PaginationBuilder<G>{
|
|
6
|
+
|
|
7
|
+
build(
|
|
8
|
+
table: string,
|
|
9
|
+
data: Record<string, any>,
|
|
10
|
+
args: any = {}
|
|
11
|
+
): SqlBuilderResult {
|
|
12
|
+
const params = this.useNamedParams ? {} : [];
|
|
13
|
+
let sql = `UPDATE \`${table}\``;
|
|
14
|
+
|
|
15
|
+
if (args.JOIN) {
|
|
16
|
+
sql += this.buildJoinClauses(args.JOIN, params);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const setClauses = Object.entries(data).map(([col, val]) => {
|
|
20
|
+
if (Array.isArray(params)) {
|
|
21
|
+
params.push(val);
|
|
22
|
+
return `\`${col}\` = ?`;
|
|
23
|
+
} else {
|
|
24
|
+
const key = `param${Object.keys(params).length}`;
|
|
25
|
+
params[key] = val;
|
|
26
|
+
return `\`${col}\` = :${key}`;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
sql += ` SET ${setClauses.join(', ')}`;
|
|
31
|
+
|
|
32
|
+
if (args.WHERE) {
|
|
33
|
+
sql += this.buildWhereClause(args.WHERE, params);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (args.PAGINATION) {
|
|
37
|
+
sql += this.buildPaginationClause(args.PAGINATION);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return { sql, params };
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Alias a table name with a given alias
|
|
2
|
+
import {C6C} from "../C6Constants";
|
|
3
|
+
|
|
4
|
+
export const A = (tableName: string, alias: string): string =>
|
|
5
|
+
`${tableName} ${alias}`;
|
|
6
|
+
|
|
7
|
+
// Qualify a column constant (e.g. 'property_units.parcel_id') to an alias
|
|
8
|
+
export const F = (qualifiedCol: string, alias: string): string =>
|
|
9
|
+
`${alias}.${qualifiedCol.split('.').pop()}`;
|
|
10
|
+
|
|
11
|
+
// Equal join condition using full-qualified column constants
|
|
12
|
+
export const fieldEq = (leftCol: string, rightCol: string, leftAlias: string, rightAlias: string): Record<string, string> => ({
|
|
13
|
+
[F(leftCol, leftAlias)]: F(rightCol, rightAlias)
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
// ST_Distance_Sphere for aliased fields
|
|
17
|
+
export const distSphere = (fromCol: string, toCol: string, fromAlias: string, toAlias: string): any[] =>
|
|
18
|
+
[C6C.ST_DISTANCE_SPHERE, F(fromCol, fromAlias), F(toCol, toAlias)];
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export interface SqlBuilderResult {
|
|
5
|
+
sql: string;
|
|
6
|
+
params: any[] | { [key: string]: any }; // params can be an array or an object for named placeholders
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
export function convertHexIfBinary(
|
|
11
|
+
_col: string,
|
|
12
|
+
val: any,
|
|
13
|
+
columnDef?: any
|
|
14
|
+
): any {
|
|
15
|
+
if (
|
|
16
|
+
typeof val === 'string' &&
|
|
17
|
+
/^[0-9a-fA-F]{32}$/.test(val) &&
|
|
18
|
+
typeof columnDef === 'object' &&
|
|
19
|
+
columnDef.MYSQL_TYPE.toUpperCase().includes('BINARY')
|
|
20
|
+
) {
|
|
21
|
+
return Buffer.from(val, 'hex');
|
|
22
|
+
}
|
|
23
|
+
return val;
|
|
24
|
+
}
|
package/src/api/restOrm.ts
CHANGED
|
@@ -1,27 +1,17 @@
|
|
|
1
1
|
import restRequest from "./restRequest";
|
|
2
|
+
import {OrmGenerics} from "./types/ormGenerics";
|
|
2
3
|
import { iRest, iRestMethods } from "./types/ormInterfaces";
|
|
3
4
|
|
|
4
5
|
export function restOrm<
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
PrimaryKey extends Extract<keyof RestTableInterface, string> = Extract<keyof RestTableInterface, string>,
|
|
8
|
-
CustomAndRequiredFields extends { [key: string]: any } = any,
|
|
9
|
-
RequestTableOverrides extends { [key in keyof RestTableInterface]: any } = { [key in keyof RestTableInterface]: any }
|
|
10
|
-
>(config: () => Omit<iRest<RestShortTableName, RestTableInterface, PrimaryKey>, "requestMethod">) {
|
|
6
|
+
G extends Omit<OrmGenerics, "requestMethod">
|
|
7
|
+
>(config: () => Omit<iRest<G['RestShortTableName'], G['RestTableInterface'], G['PrimaryKey']>, "requestMethod">) {
|
|
11
8
|
|
|
12
9
|
const methods: iRestMethods[] = ["GET", "PUT", "POST", "DELETE"];
|
|
13
10
|
|
|
14
11
|
return Object.fromEntries(
|
|
15
12
|
methods.map(method => [
|
|
16
13
|
method[0] + method.slice(1).toLowerCase(), // Capitalize e.g. "Get"
|
|
17
|
-
restRequest<
|
|
18
|
-
typeof method,
|
|
19
|
-
RestShortTableName,
|
|
20
|
-
RestTableInterface,
|
|
21
|
-
PrimaryKey,
|
|
22
|
-
CustomAndRequiredFields,
|
|
23
|
-
RequestTableOverrides
|
|
24
|
-
>(() => ({
|
|
14
|
+
restRequest<G>(() => ({
|
|
25
15
|
...config(),
|
|
26
16
|
requestMethod: method as iRestMethods,
|
|
27
17
|
}))
|
package/src/api/restRequest.ts
CHANGED
|
@@ -1,65 +1,47 @@
|
|
|
1
1
|
import isNode from '../variables/isNode';
|
|
2
|
+
import {OrmGenerics} from "./types/ormGenerics";
|
|
2
3
|
import {
|
|
3
4
|
apiReturn, DetermineResponseDataType,
|
|
4
|
-
iRest,
|
|
5
|
+
iRest, RequestQueryBody
|
|
5
6
|
} from "./types/ormInterfaces";
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Facade: routes API calls to SQL or HTTP executors based on runtime context.
|
|
9
10
|
*/
|
|
10
11
|
export default function restRequest<
|
|
11
|
-
|
|
12
|
-
RestShortTableName extends string = any,
|
|
13
|
-
RestTableInterface extends { [key: string]: any } = any,
|
|
14
|
-
PrimaryKey extends Extract<keyof RestTableInterface, string> = Extract<keyof RestTableInterface, string>,
|
|
15
|
-
CustomAndRequiredFields extends { [key: string]: any } = any,
|
|
16
|
-
RequestTableOverrides extends { [key in keyof RestTableInterface]: any } = { [key in keyof RestTableInterface]: any }
|
|
12
|
+
G extends OrmGenerics
|
|
17
13
|
>(
|
|
18
14
|
configX: (() => iRest<
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
PrimaryKey
|
|
15
|
+
G['RestTableInterface'],
|
|
16
|
+
G['RestShortTableName'],
|
|
17
|
+
G['PrimaryKey']
|
|
22
18
|
>) | iRest<
|
|
23
|
-
RestShortTableName,
|
|
24
|
-
RestTableInterface,
|
|
25
|
-
PrimaryKey
|
|
19
|
+
G['RestShortTableName'],
|
|
20
|
+
G['RestTableInterface'],
|
|
21
|
+
G['PrimaryKey']
|
|
26
22
|
>
|
|
27
23
|
) {
|
|
28
24
|
return async (
|
|
29
25
|
request: RequestQueryBody<
|
|
30
|
-
RequestMethod,
|
|
31
|
-
RestTableInterface,
|
|
32
|
-
CustomAndRequiredFields,
|
|
33
|
-
RequestTableOverrides
|
|
26
|
+
G['RequestMethod'],
|
|
27
|
+
G['RestTableInterface'],
|
|
28
|
+
G['CustomAndRequiredFields'],
|
|
29
|
+
G['RequestTableOverrides']
|
|
34
30
|
>,
|
|
35
|
-
): Promise<apiReturn<DetermineResponseDataType<RequestMethod, RestTableInterface>>> => {
|
|
31
|
+
): Promise<apiReturn<DetermineResponseDataType<G['RequestMethod'], G['RestTableInterface']>>> => {
|
|
36
32
|
|
|
37
33
|
const config = typeof configX === "function" ? configX() : configX;
|
|
38
34
|
|
|
39
35
|
// SQL path if on Node with a provided pool
|
|
40
36
|
if (isNode() && config.mysqlPool) {
|
|
41
37
|
const {SqlExecutor} = await import('./executors/SqlExecutor');
|
|
42
|
-
const executor = new SqlExecutor<
|
|
43
|
-
RequestMethod,
|
|
44
|
-
RestShortTableName,
|
|
45
|
-
RestTableInterface,
|
|
46
|
-
PrimaryKey,
|
|
47
|
-
CustomAndRequiredFields,
|
|
48
|
-
RequestTableOverrides
|
|
49
|
-
>(config, request);
|
|
38
|
+
const executor = new SqlExecutor<G>(config, request);
|
|
50
39
|
return executor.execute();
|
|
51
40
|
}
|
|
52
41
|
|
|
53
42
|
// HTTP path fallback
|
|
54
43
|
const {HttpExecutor} = await import('./executors/HttpExecutor');
|
|
55
|
-
const http = new HttpExecutor<
|
|
56
|
-
RequestMethod,
|
|
57
|
-
RestShortTableName,
|
|
58
|
-
RestTableInterface,
|
|
59
|
-
PrimaryKey,
|
|
60
|
-
CustomAndRequiredFields,
|
|
61
|
-
RequestTableOverrides
|
|
62
|
-
>(config, request);
|
|
44
|
+
const http = new HttpExecutor<G>(config, request);
|
|
63
45
|
return http.execute();
|
|
64
46
|
};
|
|
65
47
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// types/ormGenerics.ts
|
|
2
|
+
import { iRestMethods } from './ormInterfaces';
|
|
3
|
+
|
|
4
|
+
export type OrmGenerics<
|
|
5
|
+
RequestMethod extends iRestMethods = iRestMethods,
|
|
6
|
+
RestShortTableName extends string | string[] = any,
|
|
7
|
+
RestTableInterface extends Record<string, any> = any,
|
|
8
|
+
PrimaryKey extends keyof RestTableInterface & string = keyof RestTableInterface & string,
|
|
9
|
+
CustomAndRequiredFields extends Record<string, any> = any,
|
|
10
|
+
RequestTableOverrides extends { [key in keyof RestTableInterface]: any } = { [key in keyof RestTableInterface]: any }
|
|
11
|
+
> = {
|
|
12
|
+
RequestMethod: RequestMethod;
|
|
13
|
+
RestShortTableName: RestShortTableName;
|
|
14
|
+
RestTableInterface: RestTableInterface;
|
|
15
|
+
PrimaryKey: PrimaryKey;
|
|
16
|
+
CustomAndRequiredFields: CustomAndRequiredFields;
|
|
17
|
+
RequestTableOverrides: RequestTableOverrides;
|
|
18
|
+
};
|
|
@@ -6,6 +6,7 @@ import { eFetchDependencies } from "./dynamicFetching";
|
|
|
6
6
|
import { Modify } from "./modifyTypes";
|
|
7
7
|
import { JoinType, OrderDirection, SQLComparisonOperator, SQLFunction } from "./mysqlTypes";
|
|
8
8
|
import { CarbonReact } from "@carbonorm/carbonreact";
|
|
9
|
+
import {OrmGenerics} from "./ormGenerics";
|
|
9
10
|
|
|
10
11
|
export type iRestMethods = 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
11
12
|
export const POST = 'POST';
|
|
@@ -132,8 +133,8 @@ export type DetermineResponseDataType<
|
|
|
132
133
|
|
|
133
134
|
export interface iRest<
|
|
134
135
|
RestShortTableName extends string = any,
|
|
135
|
-
RestTableInterface extends
|
|
136
|
-
PrimaryKey extends keyof RestTableInterface & string =
|
|
136
|
+
RestTableInterface extends Record<string, any> = any,
|
|
137
|
+
PrimaryKey extends keyof RestTableInterface & string = keyof RestTableInterface & string
|
|
137
138
|
> {
|
|
138
139
|
C6: iC6Object;
|
|
139
140
|
axios?: AxiosInstance;
|
|
@@ -159,69 +160,53 @@ export type tColumns<TableName extends string, T extends { [key: string]: any }>
|
|
|
159
160
|
|
|
160
161
|
export type tPrimaryKeys<TableName extends string, PK extends string> = `${TableName}.${PK}`;
|
|
161
162
|
|
|
162
|
-
export interface iC6RestfulModel<
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
163
|
+
export interface iC6RestfulModel<
|
|
164
|
+
RestShortTableName extends string,
|
|
165
|
+
RestTableInterface extends Record<string, any> = any,
|
|
166
|
+
PrimaryKey extends keyof RestTableInterface & string = keyof RestTableInterface & string,
|
|
167
|
+
> {
|
|
168
|
+
TABLE_NAME: RestShortTableName;
|
|
169
|
+
PRIMARY: tPrimaryKeys<RestShortTableName, PrimaryKey>[];
|
|
170
|
+
PRIMARY_SHORT: PrimaryKey[];
|
|
171
|
+
COLUMNS: tColumns<RestShortTableName, RestTableInterface>;
|
|
167
172
|
TYPE_VALIDATION: { [key: string]: iTypeValidation };
|
|
168
173
|
REGEX_VALIDATION: RegExpMap;
|
|
169
|
-
LIFECYCLE_HOOKS: iRestHooks<
|
|
174
|
+
LIFECYCLE_HOOKS: iRestHooks<OrmGenerics<any, RestShortTableName, RestTableInterface, PrimaryKey>>;
|
|
170
175
|
TABLE_REFERENCES: { [columnName: string]: iConstraint[] };
|
|
171
176
|
TABLE_REFERENCED_BY: { [columnName: string]: iConstraint[] };
|
|
172
177
|
}
|
|
173
178
|
|
|
174
|
-
export type iRestReactiveLifecycle<
|
|
175
|
-
Method extends iRestMethods,
|
|
176
|
-
RestShortTableName extends string,
|
|
177
|
-
RestTableInterface extends { [key: string]: any },
|
|
178
|
-
PrimaryKey extends keyof RestTableInterface & string,
|
|
179
|
-
CustomAndRequiredFields extends { [key: string]: any },
|
|
180
|
-
RequestTableOverrides extends { [key: string]: any }
|
|
181
|
-
> = {
|
|
179
|
+
export type iRestReactiveLifecycle<G extends OrmGenerics> = {
|
|
182
180
|
beforeProcessing?: {
|
|
183
181
|
[key: string]: (args: {
|
|
184
|
-
config: iRest<RestShortTableName, RestTableInterface, PrimaryKey>;
|
|
185
|
-
request: RequestQueryBody<
|
|
182
|
+
config: iRest<G['RestShortTableName'], G['RestTableInterface'], G['PrimaryKey']>;
|
|
183
|
+
request: RequestQueryBody<G['RequestMethod'], G['RestTableInterface'], G['CustomAndRequiredFields'], G['RequestTableOverrides']>;
|
|
186
184
|
}) => void | Promise<void>;
|
|
187
185
|
};
|
|
188
186
|
beforeExecution?: {
|
|
189
187
|
[key: string]: (args: {
|
|
190
|
-
config: iRest<RestShortTableName, RestTableInterface, PrimaryKey>;
|
|
191
|
-
request: RequestQueryBody<
|
|
188
|
+
config: iRest<G['RestShortTableName'], G['RestTableInterface'], G['PrimaryKey']>;
|
|
189
|
+
request: RequestQueryBody<G['RequestMethod'], G['RestTableInterface'], G['CustomAndRequiredFields'], G['RequestTableOverrides']>;
|
|
192
190
|
}) => void | Promise<void>;
|
|
193
191
|
};
|
|
194
192
|
afterExecution?: {
|
|
195
193
|
[key: string]: (args: {
|
|
196
|
-
config: iRest<RestShortTableName, RestTableInterface, PrimaryKey>;
|
|
197
|
-
request: RequestQueryBody<
|
|
198
|
-
response: AxiosResponse<DetermineResponseDataType<
|
|
194
|
+
config: iRest<G['RestShortTableName'], G['RestTableInterface'], G['PrimaryKey']>;
|
|
195
|
+
request: RequestQueryBody<G['RequestMethod'], G['RestTableInterface'], G['CustomAndRequiredFields'], G['RequestTableOverrides']>;
|
|
196
|
+
response: AxiosResponse<DetermineResponseDataType<G['RequestMethod'], G['RestTableInterface']>>;
|
|
199
197
|
}) => void | Promise<void>;
|
|
200
198
|
};
|
|
201
199
|
afterCommit?: {
|
|
202
200
|
[key: string]: (args: {
|
|
203
|
-
config: iRest<RestShortTableName, RestTableInterface, PrimaryKey>;
|
|
204
|
-
request: RequestQueryBody<
|
|
205
|
-
response: AxiosResponse<DetermineResponseDataType<
|
|
201
|
+
config: iRest<G['RestShortTableName'], G['RestTableInterface'], G['PrimaryKey']>;
|
|
202
|
+
request: RequestQueryBody<G['RequestMethod'], G['RestTableInterface'], G['CustomAndRequiredFields'], G['RequestTableOverrides']>;
|
|
203
|
+
response: AxiosResponse<DetermineResponseDataType<G['RequestMethod'], G['RestTableInterface']>>;
|
|
206
204
|
}) => void | Promise<void>;
|
|
207
205
|
};
|
|
208
206
|
};
|
|
209
207
|
|
|
210
|
-
export type iRestHooks<
|
|
211
|
-
|
|
212
|
-
RestTableInterface extends { [key: string]: any },
|
|
213
|
-
PrimaryKey extends keyof RestTableInterface & string,
|
|
214
|
-
CustomAndRequiredFields extends { [key: string]: any } = any,
|
|
215
|
-
RequestTableOverrides extends { [key: string]: any } = { [key in keyof RestTableInterface]: any }
|
|
216
|
-
> = {
|
|
217
|
-
[Method in iRestMethods]: iRestReactiveLifecycle<
|
|
218
|
-
Method,
|
|
219
|
-
RestShortTableName,
|
|
220
|
-
RestTableInterface,
|
|
221
|
-
PrimaryKey,
|
|
222
|
-
CustomAndRequiredFields,
|
|
223
|
-
RequestTableOverrides
|
|
224
|
-
>;
|
|
208
|
+
export type iRestHooks<G extends OrmGenerics> = {
|
|
209
|
+
[Method in iRestMethods]: iRestReactiveLifecycle<G>;
|
|
225
210
|
};
|
|
226
211
|
|
|
227
212
|
export interface iDynamicApiImport<RestData extends { [key: string]: any } = any> {
|
|
@@ -241,7 +226,7 @@ export interface iRestApiFunctions<RestData extends { [key: string]: any } = any
|
|
|
241
226
|
export interface iC6Object<
|
|
242
227
|
RestShortTableName extends string = any,
|
|
243
228
|
RestTableInterface extends { [key: string]: any } = any,
|
|
244
|
-
PrimaryKey extends
|
|
229
|
+
PrimaryKey extends keyof RestTableInterface & string = keyof RestTableInterface & string
|
|
245
230
|
> {
|
|
246
231
|
C6VERSION: string;
|
|
247
232
|
TABLES: {
|
|
@@ -257,7 +242,7 @@ export interface iC6Object<
|
|
|
257
242
|
export interface tC6Tables<
|
|
258
243
|
RestShortTableName extends string = any,
|
|
259
244
|
RestTableInterface extends { [key: string]: any } = any,
|
|
260
|
-
PrimaryKey extends
|
|
245
|
+
PrimaryKey extends keyof RestTableInterface & string = keyof RestTableInterface & string
|
|
261
246
|
> {
|
|
262
247
|
[key: string]: iC6RestfulModel<RestShortTableName, RestTableInterface, PrimaryKey> & { [key: string]: any };
|
|
263
248
|
}
|
package/src/index.ts
CHANGED
|
@@ -12,14 +12,23 @@ export { default as restRequest } from "./api/restRequest";
|
|
|
12
12
|
export * from "./api/restRequest";
|
|
13
13
|
export { default as timeout } from "./api/timeout";
|
|
14
14
|
export * from "./api/timeout";
|
|
15
|
-
export * from "./api/builders/sqlBuilder";
|
|
16
15
|
export * from "./api/executors/Executor";
|
|
17
16
|
export * from "./api/executors/HttpExecutor";
|
|
18
17
|
export * from "./api/executors/SqlExecutor";
|
|
19
18
|
export * from "./api/handlers/ExpressHandler";
|
|
19
|
+
export * from "./api/orm/queryHelpers";
|
|
20
|
+
export * from "./api/orm/builders/AggregateBuilder";
|
|
21
|
+
export * from "./api/orm/builders/ConditionBuilder";
|
|
22
|
+
export * from "./api/orm/builders/JoinBuilder";
|
|
23
|
+
export * from "./api/orm/builders/PaginationBuilder";
|
|
24
|
+
export * from "./api/orm/queries/DeleteQueryBuilder";
|
|
25
|
+
export * from "./api/orm/queries/SelectQueryBuilder";
|
|
26
|
+
export * from "./api/orm/queries/UpdateQueryBuilder";
|
|
27
|
+
export * from "./api/orm/utils/sqlUtils";
|
|
20
28
|
export * from "./api/types/dynamicFetching";
|
|
21
29
|
export * from "./api/types/modifyTypes";
|
|
22
30
|
export * from "./api/types/mysqlTypes";
|
|
31
|
+
export * from "./api/types/ormGenerics";
|
|
23
32
|
export * from "./api/types/ormInterfaces";
|
|
24
33
|
export * from "./api/utils/apiHelpers";
|
|
25
34
|
export * from "./api/utils/cacheManager";
|