@technicity/data-service-generator 0.15.0 → 0.16.1-next.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.
- package/dist/generation/generate.d.ts +3 -3
- package/dist/generation/generate.js +1 -2
- package/dist/lib/capitalizeFirstLetter.js +1 -2
- package/dist/lib/getDuplicates.js +1 -2
- package/dist/lib/isNotNullOrUndefined.js +1 -2
- package/dist/runtime/Cache.d.ts +1 -1
- package/dist/runtime/IRuntime.d.ts +32 -33
- package/dist/runtime/RuntimeMySQL.d.ts +8 -5
- package/dist/runtime/RuntimeMySQL.js +5 -7
- package/dist/runtime/RuntimeSQLite.d.ts +1 -1
- package/dist/runtime/Stats.d.ts +0 -4
- package/dist/runtime/Stats.js +1 -2
- package/dist/runtime/lib/MySQL.d.ts +9 -5
- package/dist/runtime/lib/MySQL.js +82 -35
- package/dist/runtime/lib/addNullFallbacks.js +1 -2
- package/dist/runtime/lib/cursor.js +2 -3
- package/dist/runtime/lib/getDateTimeStringMySQL.js +1 -2
- package/dist/runtime/lib/getOrderBy.js +1 -2
- package/dist/runtime/lib/getSqlAst.js +1 -2
- package/dist/runtime/lib/getWhere.js +1 -2
- package/dist/runtime/lib/shared.js +5 -5
- package/dist/runtime/lib/stringifyWhere.d.ts +2 -2
- package/dist/runtime/lib/stringifyWhere.js +3 -4
- package/dist/runtime/lib/typeCastMSSQL.d.ts +1 -1
- package/dist/runtime/lib/typeCastMSSQL.js +1 -2
- package/dist/runtime/lib/utility.js +2 -3
- package/dist/traverseFieldArgs.js +1 -2
- package/package.json +3 -4
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { IDialect, ISupplementClientOpts } from "../runtime/IRuntime";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
type ISpecialCaseUuidColumn = boolean;
|
|
3
|
+
type IIncludeMappedFields = boolean;
|
|
4
|
+
type IGenerateInput = {
|
|
5
5
|
dialect: IDialect;
|
|
6
6
|
database: string;
|
|
7
7
|
user: string;
|
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.generate =
|
|
29
|
+
exports.generate = generate;
|
|
30
30
|
const path = __importStar(require("node:path"));
|
|
31
31
|
const fs = __importStar(require("node:fs"));
|
|
32
32
|
const os = __importStar(require("node:os"));
|
|
@@ -202,7 +202,6 @@ async function generate(input) {
|
|
|
202
202
|
fse.copySync(tmpBuildOutputPath, sdkOutputPath);
|
|
203
203
|
fse.removeSync(tmpDirPath);
|
|
204
204
|
}
|
|
205
|
-
exports.generate = generate;
|
|
206
205
|
function init(input) {
|
|
207
206
|
const { database, user, password, host, port, server } = input;
|
|
208
207
|
if (dialect === "mysql") {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.capitalizeFirstLetter =
|
|
3
|
+
exports.capitalizeFirstLetter = capitalizeFirstLetter;
|
|
4
4
|
function capitalizeFirstLetter(str) {
|
|
5
5
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
6
6
|
}
|
|
7
|
-
exports.capitalizeFirstLetter = capitalizeFirstLetter;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getDuplicates =
|
|
3
|
+
exports.getDuplicates = getDuplicates;
|
|
4
4
|
function getDuplicates(arr) {
|
|
5
5
|
return arr.reduce((agg, col) => {
|
|
6
6
|
agg.filter[col] = agg.filter[col] ? agg.dup.push(col) : 2;
|
|
7
7
|
return agg;
|
|
8
8
|
}, { filter: {}, dup: [] }).dup;
|
|
9
9
|
}
|
|
10
|
-
exports.getDuplicates = getDuplicates;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isNotNullOrUndefined =
|
|
3
|
+
exports.isNotNullOrUndefined = isNotNullOrUndefined;
|
|
4
4
|
// https://github.com/Microsoft/TypeScript/issues/16069
|
|
5
5
|
function isNotNullOrUndefined(input) {
|
|
6
6
|
return input != null;
|
|
7
7
|
}
|
|
8
|
-
exports.isNotNullOrUndefined = isNotNullOrUndefined;
|
package/dist/runtime/Cache.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
3
2
|
export interface IRuntime {
|
|
4
3
|
resolve(input: TResolveParams): Promise<any>;
|
|
@@ -11,8 +10,8 @@ export interface IRuntime {
|
|
|
11
10
|
isolationLevel?: "READ UNCOMMITTED" | "READ COMMITTED" | "REPEATABLE READ" | "SERIALIZABLE";
|
|
12
11
|
}): Promise<TBeginTransactionResult>;
|
|
13
12
|
}
|
|
14
|
-
export
|
|
15
|
-
export
|
|
13
|
+
export type TAction = "findUnique" | "findMany" | "findManyPaginated" | "create" | "update" | "updateMany" | "delete" | "deleteMany";
|
|
14
|
+
export type TResolveParams = {
|
|
16
15
|
resource: string;
|
|
17
16
|
action: TAction;
|
|
18
17
|
args?: IArgs;
|
|
@@ -30,60 +29,60 @@ export declare type TResolveParams = {
|
|
|
30
29
|
}>;
|
|
31
30
|
sdk?: unknown;
|
|
32
31
|
};
|
|
33
|
-
export
|
|
32
|
+
export type TOnHandler = (sdk: unknown, input: unknown, output: unknown) => Promise<void>;
|
|
34
33
|
export declare class EventOnHandlerError<T> extends Event {
|
|
35
34
|
error: T;
|
|
36
35
|
constructor(message: string, data: ConstructorParameters<typeof Event>[1] & {
|
|
37
36
|
error: T;
|
|
38
37
|
});
|
|
39
38
|
}
|
|
40
|
-
export
|
|
39
|
+
export type TContext = {
|
|
41
40
|
[k: string]: any;
|
|
42
41
|
};
|
|
43
|
-
export
|
|
44
|
-
export
|
|
45
|
-
export
|
|
46
|
-
export
|
|
47
|
-
export
|
|
48
|
-
|
|
42
|
+
export type TMiddleware = (params: TResolveParams, next: (params: TResolveParams) => Promise<any>) => Promise<any>;
|
|
43
|
+
export type IDialect = "mysql" | "mssql" | "sqlite";
|
|
44
|
+
export type TDbCall = (q: string) => Promise<any>;
|
|
45
|
+
export type TFormatQuery = (q: string, values: any[]) => string;
|
|
46
|
+
export type TBeginTransaction = () => Promise<TBeginTransactionResult>;
|
|
47
|
+
type TBeginTransactionResult = {
|
|
49
48
|
dbCall: (q: string) => Promise<any>;
|
|
50
49
|
commit: () => Promise<void>;
|
|
51
50
|
rollback: () => Promise<void>;
|
|
52
51
|
};
|
|
53
|
-
export
|
|
54
|
-
export
|
|
52
|
+
export type ISupplementClientOpts = boolean;
|
|
53
|
+
export type IOrderBy = {
|
|
55
54
|
column: string;
|
|
56
55
|
direction: any;
|
|
57
56
|
}[];
|
|
58
|
-
export
|
|
57
|
+
export type IArgs = {
|
|
59
58
|
[k: string]: any;
|
|
60
59
|
};
|
|
61
|
-
export
|
|
60
|
+
export type TSelect = {
|
|
62
61
|
[k: string]: boolean | {
|
|
63
62
|
$fields?: TSelect;
|
|
64
63
|
};
|
|
65
64
|
};
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
type IWhere = (table: string, args: IArgs) => string | undefined;
|
|
66
|
+
type IASTChildColumn = {
|
|
68
67
|
type: "column";
|
|
69
68
|
name: string;
|
|
70
69
|
fieldName: string;
|
|
71
70
|
as: string;
|
|
72
71
|
fromOtherTable?: string;
|
|
73
72
|
};
|
|
74
|
-
|
|
73
|
+
type IASTChildComposite = {
|
|
75
74
|
type: "composite";
|
|
76
75
|
name: string[];
|
|
77
76
|
fieldName: string;
|
|
78
77
|
as: string;
|
|
79
78
|
fromOtherTable?: string;
|
|
80
79
|
};
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
type ISqlJoin = (t1: string, t2: string, args: IArgs) => string;
|
|
81
|
+
type ISqlBatch = {
|
|
83
82
|
thisKey: IASTChildColumn;
|
|
84
83
|
parentKey: IASTChildColumn;
|
|
85
84
|
};
|
|
86
|
-
|
|
85
|
+
type IJunction = {
|
|
87
86
|
sqlTable: string;
|
|
88
87
|
as: string;
|
|
89
88
|
uniqueKey: string | string[];
|
|
@@ -99,7 +98,7 @@ declare type IJunction = {
|
|
|
99
98
|
where?: IWhere;
|
|
100
99
|
sqlJoins: ISqlJoin[];
|
|
101
100
|
};
|
|
102
|
-
export
|
|
101
|
+
export type IGetSQLASTInput = {
|
|
103
102
|
table: string;
|
|
104
103
|
fieldName: string;
|
|
105
104
|
fields: TSelect;
|
|
@@ -116,17 +115,17 @@ export declare type IGetSQLASTInput = {
|
|
|
116
115
|
dialect: IDialect;
|
|
117
116
|
firstChild?: IASTChildColumn | IASTChildComposite;
|
|
118
117
|
};
|
|
119
|
-
export
|
|
118
|
+
export type IRelation = {
|
|
120
119
|
table: string;
|
|
121
120
|
foreignKey: string;
|
|
122
121
|
referencedTable: string;
|
|
123
122
|
referencedKey: string;
|
|
124
123
|
nullable: boolean;
|
|
125
124
|
};
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
export
|
|
125
|
+
type IOneToManyOrManyToOne = "one-to-many__many-to-one";
|
|
126
|
+
type IManyToMany = "many-to-many";
|
|
127
|
+
type IRelationKind = "one-to-many" | "many-to-one";
|
|
128
|
+
export type IRelationOneToManyOrManyToOne = {
|
|
130
129
|
type: IOneToManyOrManyToOne;
|
|
131
130
|
kind: IRelationKind;
|
|
132
131
|
grabMany: boolean;
|
|
@@ -135,7 +134,7 @@ export declare type IRelationOneToManyOrManyToOne = {
|
|
|
135
134
|
relation: IRelation;
|
|
136
135
|
nullable: boolean;
|
|
137
136
|
};
|
|
138
|
-
export
|
|
137
|
+
export type IRelationManyToMany = {
|
|
139
138
|
type: IManyToMany;
|
|
140
139
|
grabMany: boolean;
|
|
141
140
|
table: string;
|
|
@@ -143,8 +142,8 @@ export declare type IRelationManyToMany = {
|
|
|
143
142
|
name: string;
|
|
144
143
|
relations: IRelation[];
|
|
145
144
|
};
|
|
146
|
-
export
|
|
147
|
-
export
|
|
145
|
+
export type IRelationField = IRelationOneToManyOrManyToOne | IRelationManyToMany;
|
|
146
|
+
export type IMappedField = {
|
|
148
147
|
name: string;
|
|
149
148
|
as: string;
|
|
150
149
|
type: string;
|
|
@@ -154,7 +153,7 @@ export declare type IMappedField = {
|
|
|
154
153
|
referencedTable: string;
|
|
155
154
|
referencedKey: string;
|
|
156
155
|
};
|
|
157
|
-
export
|
|
156
|
+
export type IArtifacts = {
|
|
158
157
|
[k: string]: {
|
|
159
158
|
table: string;
|
|
160
159
|
primaryKey: string;
|
|
@@ -180,8 +179,8 @@ export declare type IArtifacts = {
|
|
|
180
179
|
} | null;
|
|
181
180
|
};
|
|
182
181
|
};
|
|
183
|
-
export
|
|
184
|
-
export
|
|
182
|
+
export type TFieldType = "string" | "boolean" | "number" | "integer";
|
|
183
|
+
export type TField = {
|
|
185
184
|
kind: "scalar";
|
|
186
185
|
type: TFieldType;
|
|
187
186
|
name: string;
|
|
@@ -1,22 +1,25 @@
|
|
|
1
1
|
import { RedisConfig } from "./Cache";
|
|
2
2
|
import type { IRuntime, TMiddleware, TResolveParams, IArtifacts, ISupplementClientOpts } from "./IRuntime";
|
|
3
|
+
import { MySQL } from "./lib/MySQL";
|
|
3
4
|
export declare class RuntimeMySQL implements IRuntime {
|
|
4
5
|
#private;
|
|
5
|
-
constructor(clientOpts: {
|
|
6
|
-
[k: string]: any;
|
|
7
|
-
}, otherOpts: {
|
|
6
|
+
constructor(clientOpts: ConstructorParameters<typeof MySQL>[0], otherOpts: {
|
|
8
7
|
supplementClientOpts?: ISupplementClientOpts;
|
|
9
8
|
redis?: RedisConfig;
|
|
10
9
|
}, artifacts: IArtifacts);
|
|
11
10
|
resolve(input: TResolveParams): Promise<any>;
|
|
12
|
-
$queryRaw(sql: string, values?: any[]): Promise<
|
|
11
|
+
$queryRaw(sql: string, values?: any[]): Promise<import("mysql2").OkPacket | import("mysql2").ResultSetHeader | import("mysql2").ResultSetHeader[] | import("mysql2").RowDataPacket[] | import("mysql2").RowDataPacket[][] | import("mysql2").OkPacket[] | [import("mysql2").RowDataPacket[], import("mysql2").ResultSetHeader]>;
|
|
13
12
|
$use(middleware: TMiddleware): Promise<void>;
|
|
14
13
|
$whereNeedsProcessing(where: any): boolean;
|
|
15
14
|
$prepareWhere(artifacts: IArtifacts, table: string, data: any): Promise<{}>;
|
|
16
15
|
$shutdown(): Promise<void>;
|
|
17
16
|
$startTransaction(input?: {
|
|
18
17
|
isolationLevel?: "READ UNCOMMITTED" | "READ COMMITTED" | "REPEATABLE READ" | "SERIALIZABLE";
|
|
19
|
-
}): Promise<
|
|
18
|
+
}): Promise<{
|
|
19
|
+
commit: () => Promise<void>;
|
|
20
|
+
rollback: () => Promise<void>;
|
|
21
|
+
dbCall: (q: string) => Promise<import("mysql2").OkPacket | import("mysql2").ResultSetHeader | import("mysql2").ResultSetHeader[] | import("mysql2").RowDataPacket[] | import("mysql2").RowDataPacket[][] | import("mysql2").OkPacket[] | [import("mysql2").RowDataPacket[], import("mysql2").ResultSetHeader]>;
|
|
22
|
+
}>;
|
|
20
23
|
private dbCall;
|
|
21
24
|
private formatQuery;
|
|
22
25
|
}
|
|
@@ -64,13 +64,11 @@ class RuntimeMySQL {
|
|
|
64
64
|
// if (field.type === "DATE") {
|
|
65
65
|
// return field.string();
|
|
66
66
|
// }
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
// return new Date(field.string()).toISOString();
|
|
73
|
-
// }
|
|
67
|
+
if (field.type === "TIMESTAMP" ||
|
|
68
|
+
field.type === "DATE" ||
|
|
69
|
+
field.type === "DATETIME") {
|
|
70
|
+
return new Date(field.string()).toISOString();
|
|
71
|
+
}
|
|
74
72
|
if (field.type === "VAR_STRING" || field.type === "STRING") {
|
|
75
73
|
return field.string();
|
|
76
74
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Database from "better-sqlite3";
|
|
2
2
|
import type { IRuntime, TMiddleware, TResolveParams, IArtifacts, ISupplementClientOpts } from "./IRuntime";
|
|
3
3
|
import { MiddlewareHandler } from "./lib/shared";
|
|
4
|
-
|
|
4
|
+
type TClientOpts = {
|
|
5
5
|
filename: string;
|
|
6
6
|
} & Parameters<typeof Database>[1];
|
|
7
7
|
export declare class RuntimeSQLite implements IRuntime {
|
package/dist/runtime/Stats.d.ts
CHANGED
|
@@ -4,9 +4,5 @@ declare class Stats {
|
|
|
4
4
|
constructor(client: Redis | Cluster);
|
|
5
5
|
updateStats: (ms: number, category: string) => Promise<void>;
|
|
6
6
|
}
|
|
7
|
-
declare namespace timer {
|
|
8
|
-
type Callback = (time: number, ...params: any[]) => void;
|
|
9
|
-
type Params<T> = T extends (ms: number, ...params: infer U) => any ? U : never;
|
|
10
|
-
}
|
|
11
7
|
export declare function timer(): <T extends timer.Callback>(callback: T, ...args: timer.Params<T>) => void;
|
|
12
8
|
export default Stats;
|
package/dist/runtime/Stats.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.timer =
|
|
3
|
+
exports.timer = timer;
|
|
4
4
|
const perf_hooks_1 = require("perf_hooks");
|
|
5
5
|
class Stats {
|
|
6
6
|
constructor(client) {
|
|
@@ -28,5 +28,4 @@ function timer() {
|
|
|
28
28
|
callback(perf_hooks_1.performance.now() - start, ...args);
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
|
-
exports.timer = timer;
|
|
32
31
|
exports.default = Stats;
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
import * as mysql from "mysql2/promise";
|
|
1
2
|
export declare class MySQL {
|
|
2
|
-
pool:
|
|
3
|
-
constructor(opts:
|
|
4
|
-
query(...args: any[]):
|
|
5
|
-
beginTransaction(isolationLevel?: "READ UNCOMMITTED" | "READ COMMITTED" | "REPEATABLE READ" | "SERIALIZABLE"): Promise<
|
|
6
|
-
|
|
3
|
+
pool: mysql.Pool;
|
|
4
|
+
constructor(opts: Parameters<typeof mysql.createPool>[0]);
|
|
5
|
+
query(...args: any[]): Promise<mysql.OkPacket | mysql.ResultSetHeader | mysql.ResultSetHeader[] | mysql.RowDataPacket[] | mysql.RowDataPacket[][] | mysql.OkPacket[] | [mysql.RowDataPacket[], mysql.ResultSetHeader]>;
|
|
6
|
+
beginTransaction(isolationLevel?: "READ UNCOMMITTED" | "READ COMMITTED" | "REPEATABLE READ" | "SERIALIZABLE"): Promise<{
|
|
7
|
+
commit: () => Promise<void>;
|
|
8
|
+
rollback: () => Promise<void>;
|
|
9
|
+
dbCall: (q: string) => Promise<mysql.OkPacket | mysql.ResultSetHeader | mysql.ResultSetHeader[] | mysql.RowDataPacket[] | mysql.RowDataPacket[][] | mysql.OkPacket[] | [mysql.RowDataPacket[], mysql.ResultSetHeader]>;
|
|
10
|
+
}>;
|
|
7
11
|
endPool(): Promise<void>;
|
|
8
12
|
}
|
|
@@ -1,52 +1,99 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.MySQL = void 0;
|
|
4
|
-
const mysql = require("
|
|
5
|
-
const P = require("bluebird");
|
|
6
|
-
P.promisifyAll(require("mysql/lib/Connection").prototype);
|
|
7
|
-
P.promisifyAll(require("mysql/lib/Pool").prototype);
|
|
27
|
+
const mysql = __importStar(require("mysql2/promise"));
|
|
8
28
|
class MySQL {
|
|
9
29
|
constructor(opts) {
|
|
10
30
|
this.pool = mysql.createPool(opts);
|
|
31
|
+
if (opts.debug) {
|
|
32
|
+
this.pool.on("acquire", (connection) => {
|
|
33
|
+
console.log("Connection %d acquired", connection.threadId);
|
|
34
|
+
});
|
|
35
|
+
this.pool.on("connection", (connection) => {
|
|
36
|
+
console.log("Connection %d connected", connection.threadId);
|
|
37
|
+
});
|
|
38
|
+
this.pool.on("enqueue", () => {
|
|
39
|
+
console.log("Waiting for available connection slot");
|
|
40
|
+
});
|
|
41
|
+
this.pool.on("release", (connection) => {
|
|
42
|
+
console.log("Connection %d released", connection.threadId);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
11
45
|
}
|
|
12
|
-
// http://bluebirdjs.com/docs/api/promise.using.html
|
|
13
46
|
query(...args) {
|
|
14
|
-
return
|
|
47
|
+
return this.pool
|
|
48
|
+
.query(
|
|
49
|
+
// @ts-expect-error
|
|
50
|
+
...args)
|
|
51
|
+
.then(([rows]) => rows);
|
|
15
52
|
}
|
|
16
53
|
async beginTransaction(isolationLevel) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
54
|
+
const connection = await this.pool.getConnection();
|
|
55
|
+
// https://dev.mysql.com/doc/refman/8.0/en/set-transaction.html#set-transaction-isolation-level
|
|
56
|
+
// Without any SESSION or GLOBAL keyword:
|
|
57
|
+
// The statement applies only to the next single transaction performed within the session.
|
|
58
|
+
if (isolationLevel != null) {
|
|
59
|
+
if (isolationLevel !== "READ UNCOMMITTED" &&
|
|
60
|
+
isolationLevel !== "READ COMMITTED" &&
|
|
61
|
+
isolationLevel !== "REPEATABLE READ" &&
|
|
62
|
+
isolationLevel !== "SERIALIZABLE") {
|
|
63
|
+
throw new Error(`Invalid isolationLevel: ${isolationLevel}`);
|
|
21
64
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
65
|
+
await connection.query(`SET TRANSACTION ISOLATION LEVEL ${isolationLevel};`);
|
|
66
|
+
}
|
|
67
|
+
await connection.beginTransaction();
|
|
68
|
+
return {
|
|
69
|
+
commit: () => connection
|
|
70
|
+
.commit()
|
|
71
|
+
.catch(async (err) => {
|
|
72
|
+
await connection.rollback();
|
|
73
|
+
throw err;
|
|
74
|
+
})
|
|
75
|
+
.finally(() => {
|
|
76
|
+
connection.release();
|
|
77
|
+
}),
|
|
78
|
+
rollback: () => connection.rollback().finally(() => {
|
|
79
|
+
connection.release();
|
|
80
|
+
}),
|
|
81
|
+
dbCall: (q) => connection
|
|
82
|
+
.query(q)
|
|
83
|
+
.then(([rows]) => rows)
|
|
84
|
+
.catch(async (err) => {
|
|
85
|
+
try {
|
|
86
|
+
await connection.rollback();
|
|
31
87
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
dbCall: (q) => connection.queryAsync(q).catch(handleError)
|
|
39
|
-
};
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
// http://bluebirdjs.com/docs/api/disposer.html
|
|
43
|
-
async getConnection() {
|
|
44
|
-
return this.pool
|
|
45
|
-
.getConnectionAsync()
|
|
46
|
-
.disposer((connection) => connection.release());
|
|
88
|
+
finally {
|
|
89
|
+
connection.release();
|
|
90
|
+
}
|
|
91
|
+
throw err;
|
|
92
|
+
})
|
|
93
|
+
};
|
|
47
94
|
}
|
|
48
95
|
async endPool() {
|
|
49
|
-
await this.pool.
|
|
96
|
+
await this.pool.end();
|
|
50
97
|
}
|
|
51
98
|
}
|
|
52
99
|
exports.MySQL = MySQL;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// If a many-to-one relation's ID field is null, we want the
|
|
3
3
|
// relation field to be null as well, not undefined.
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.addNullFallbacks =
|
|
5
|
+
exports.addNullFallbacks = addNullFallbacks;
|
|
6
6
|
function addNullFallbacks(sqlAST, data) {
|
|
7
7
|
if (data == null) {
|
|
8
8
|
return;
|
|
@@ -30,4 +30,3 @@ function addNullFallbacks(sqlAST, data) {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
exports.addNullFallbacks = addNullFallbacks;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.encodeCursor = encodeCursor;
|
|
4
|
+
exports.decodeCursor = decodeCursor;
|
|
4
5
|
function encodeCursor(cursor) {
|
|
5
6
|
return Buffer.from(JSON.stringify(cursor)).toString("base64");
|
|
6
7
|
}
|
|
7
|
-
exports.encodeCursor = encodeCursor;
|
|
8
8
|
function decodeCursor(cursor) {
|
|
9
9
|
return JSON.parse(Buffer.from(cursor, "base64").toString("utf8"));
|
|
10
10
|
}
|
|
11
|
-
exports.decodeCursor = decodeCursor;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getDateTimeStringMySQL =
|
|
3
|
+
exports.getDateTimeStringMySQL = getDateTimeStringMySQL;
|
|
4
4
|
// Assumes input uses zero offset
|
|
5
5
|
function getDateTimeStringMySQL(dateTimeString) {
|
|
6
6
|
return dateTimeString.replace("T", " ").slice(0, 19);
|
|
7
7
|
}
|
|
8
|
-
exports.getDateTimeStringMySQL = getDateTimeStringMySQL;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getOrderBy =
|
|
3
|
+
exports.getOrderBy = getOrderBy;
|
|
4
4
|
// https://gist.github.com/pcattori/2bb645d587e45c9fdbcabf5cef7a7106
|
|
5
5
|
function getOrderBy(args, primaryKey) {
|
|
6
6
|
let out = undefined;
|
|
@@ -41,7 +41,6 @@ function getOrderBy(args, primaryKey) {
|
|
|
41
41
|
}
|
|
42
42
|
return { orderBy: out, flip };
|
|
43
43
|
}
|
|
44
|
-
exports.getOrderBy = getOrderBy;
|
|
45
44
|
function getFlip(args) {
|
|
46
45
|
return args?.$paginate?.last != null;
|
|
47
46
|
}
|
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.getSqlAst =
|
|
29
|
+
exports.getSqlAst = getSqlAst;
|
|
30
30
|
const SqlString = __importStar(require("sqlstring"));
|
|
31
31
|
// @ts-ignore
|
|
32
32
|
const TSqlString = __importStar(require("tsqlstring"));
|
|
@@ -220,7 +220,6 @@ function getSqlAst(input) {
|
|
|
220
220
|
}))
|
|
221
221
|
};
|
|
222
222
|
}
|
|
223
|
-
exports.getSqlAst = getSqlAst;
|
|
224
223
|
function keyToASTChild(key, namespace, fromOtherTable) {
|
|
225
224
|
if (Array.isArray(key)) {
|
|
226
225
|
const clumsyName = toClumsyName(key);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getWhere =
|
|
3
|
+
exports.getWhere = getWhere;
|
|
4
4
|
const stringifyWhere_1 = require("./stringifyWhere");
|
|
5
5
|
function getWhere(
|
|
6
6
|
// Note: `table` is not escaped in getWhere, so it should be escaped beforehand.
|
|
@@ -18,4 +18,3 @@ table, args, dialect, orderBy, rowWithMatchingCursor) {
|
|
|
18
18
|
rowWithMatchingCursor,
|
|
19
19
|
}) || null);
|
|
20
20
|
}
|
|
21
|
-
exports.getWhere = getWhere;
|
|
@@ -26,7 +26,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.
|
|
29
|
+
exports.MiddlewareHandler = void 0;
|
|
30
|
+
exports.resolve = resolve;
|
|
31
|
+
exports.postProcess = postProcess;
|
|
32
|
+
exports.whereNeedsProcessing = whereNeedsProcessing;
|
|
33
|
+
exports._prepareWhere = _prepareWhere;
|
|
30
34
|
// @ts-ignore
|
|
31
35
|
// import * as queryAST from "join-monster/dist/query-ast-to-sql-ast";
|
|
32
36
|
// @ts-ignore
|
|
@@ -95,7 +99,6 @@ async function resolve(input, dbCall, formatQuery, beginTransaction, dialect, mi
|
|
|
95
99
|
}
|
|
96
100
|
return p;
|
|
97
101
|
}
|
|
98
|
-
exports.resolve = resolve;
|
|
99
102
|
function _resolve(input, dbCall, formatQuery, beginTransaction, dialect, context, cache) {
|
|
100
103
|
switch (input.action) {
|
|
101
104
|
case "findMany":
|
|
@@ -871,7 +874,6 @@ function postProcess(data, fields, shouldRemoveExtraKeys) {
|
|
|
871
874
|
removeExtraKeys(data, fields);
|
|
872
875
|
}
|
|
873
876
|
}
|
|
874
|
-
exports.postProcess = postProcess;
|
|
875
877
|
function removeExtraKeys(data, fields) {
|
|
876
878
|
if (data == null || (Array.isArray(data) && data[0] == null)) {
|
|
877
879
|
return;
|
|
@@ -967,7 +969,6 @@ function typeCastSqlite(data, fields, table, artifacts) {
|
|
|
967
969
|
function whereNeedsProcessing(where) {
|
|
968
970
|
return JSON.stringify(where).includes("Uuid");
|
|
969
971
|
}
|
|
970
|
-
exports.whereNeedsProcessing = whereNeedsProcessing;
|
|
971
972
|
async function _prepareWhere(artifacts, table, data, dbCall, formatQuery) {
|
|
972
973
|
const mappedFields = artifacts[table].mappedFields;
|
|
973
974
|
let out = {};
|
|
@@ -1063,7 +1064,6 @@ async function _prepareWhere(artifacts, table, data, dbCall, formatQuery) {
|
|
|
1063
1064
|
});
|
|
1064
1065
|
return out;
|
|
1065
1066
|
}
|
|
1066
|
-
exports._prepareWhere = _prepareWhere;
|
|
1067
1067
|
function getPrepareWhereNotFoundMessage(mappedField, value) {
|
|
1068
1068
|
return `Not found: unable to map \`${mappedField.referencedTable}\`.\`${mappedField.name}\` to \`${mappedField.referencedTable}\`.\`${mappedField.referencedKey}\` for the value \`${value}\`.`;
|
|
1069
1069
|
}
|
|
@@ -23,7 +23,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
26
|
+
exports.stringifyWhere = stringifyWhere;
|
|
27
|
+
exports.getEscapeId = getEscapeId;
|
|
28
|
+
exports.getEscape = getEscape;
|
|
27
29
|
const _ = __importStar(require("lodash/fp"));
|
|
28
30
|
const MySqlString = __importStar(require("sqlstring"));
|
|
29
31
|
// @ts-expect-error
|
|
@@ -49,7 +51,6 @@ function stringifyWhere(input) {
|
|
|
49
51
|
}
|
|
50
52
|
return result;
|
|
51
53
|
}
|
|
52
|
-
exports.stringifyWhere = stringifyWhere;
|
|
53
54
|
function _stringifyWhere(where, table, escapeId, escape, result) {
|
|
54
55
|
if (Object.prototype.hasOwnProperty.call(where, "$and")) {
|
|
55
56
|
if (Object.keys(where).length !== 1) {
|
|
@@ -239,7 +240,6 @@ function getEscapeId(dialect) {
|
|
|
239
240
|
}
|
|
240
241
|
throw new Error("Unsupported dialect: " + dialect);
|
|
241
242
|
}
|
|
242
|
-
exports.getEscapeId = getEscapeId;
|
|
243
243
|
function getEscape(dialect) {
|
|
244
244
|
if (dialect === "mysql") {
|
|
245
245
|
return MySqlString.escape.bind(MySqlString);
|
|
@@ -252,4 +252,3 @@ function getEscape(dialect) {
|
|
|
252
252
|
}
|
|
253
253
|
throw new Error("Unsupported dialect: " + dialect);
|
|
254
254
|
}
|
|
255
|
-
exports.getEscape = getEscape;
|
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.typeCastMSSQL =
|
|
26
|
+
exports.typeCastMSSQL = typeCastMSSQL;
|
|
27
27
|
const mssql = __importStar(require("mssql"));
|
|
28
28
|
// TODO: see https://github.com/tediousjs/node-mssql/pull/1171
|
|
29
29
|
function typeCastMSSQL(customTypeCast) {
|
|
@@ -60,4 +60,3 @@ function typeCastMSSQL(customTypeCast) {
|
|
|
60
60
|
});
|
|
61
61
|
};
|
|
62
62
|
}
|
|
63
|
-
exports.typeCastMSSQL = typeCastMSSQL;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.mapAsync = mapAsync;
|
|
4
|
+
exports.flatten = flatten;
|
|
4
5
|
/**
|
|
5
6
|
* Eagerly resolve and map input values then concatinate.
|
|
6
7
|
*/
|
|
@@ -8,8 +9,6 @@ async function mapAsync(source, mapFunction) {
|
|
|
8
9
|
const output = (await source).map(mapFunction);
|
|
9
10
|
return Promise.all(flatten(output)).then(flatten);
|
|
10
11
|
}
|
|
11
|
-
exports.mapAsync = mapAsync;
|
|
12
12
|
function flatten(array) {
|
|
13
13
|
return [].concat(...array);
|
|
14
14
|
}
|
|
15
|
-
exports.flatten = flatten;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.traverseFieldArgs =
|
|
3
|
+
exports.traverseFieldArgs = traverseFieldArgs;
|
|
4
4
|
function traverseFieldArgs(fields, cb) {
|
|
5
5
|
const values = Object.values(fields);
|
|
6
6
|
for (let x of values) {
|
|
@@ -15,4 +15,3 @@ function traverseFieldArgs(fields, cb) {
|
|
|
15
15
|
traverseFieldArgs(fields, cb);
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
-
exports.traverseFieldArgs = traverseFieldArgs;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@technicity/data-service-generator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.1-next.0",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@types/better-sqlite3": "^7.6.3",
|
|
17
17
|
"better-sqlite3": "^8.1.0",
|
|
18
|
-
"bluebird": "^3.7.2",
|
|
19
18
|
"change-case": "^4.1.1",
|
|
20
19
|
"fs-extra": "10.0.0",
|
|
21
20
|
"graphql": "15.8.0",
|
|
@@ -26,7 +25,7 @@
|
|
|
26
25
|
"lodash": "^4.17.20",
|
|
27
26
|
"loglevel": "^1.8.1",
|
|
28
27
|
"mssql": "^6.3.1",
|
|
29
|
-
"
|
|
28
|
+
"mysql2": "^3.10.1",
|
|
30
29
|
"prettier": "^2.1.2",
|
|
31
30
|
"sqlstring": "^2.3.2",
|
|
32
31
|
"sqlstring-sqlite": "^0.1.1",
|
|
@@ -47,7 +46,7 @@
|
|
|
47
46
|
"jest": "^29.4.3",
|
|
48
47
|
"sinon": "12.0.1",
|
|
49
48
|
"testcontainers": "^9.1.3",
|
|
50
|
-
"typescript": "
|
|
49
|
+
"typescript": "5.5.2"
|
|
51
50
|
},
|
|
52
51
|
"resolutions": {
|
|
53
52
|
"xml2js": "0.5.0",
|