@breautek/storm 8.2.0 → 8.4.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/CHANGELOG.md +14 -0
- package/docs/assets/hierarchy.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/Application.html +17 -17
- package/docs/classes/BackendAuthenticationMiddleware.html +3 -3
- package/docs/classes/CORSMiddleware.html +3 -3
- package/docs/classes/ConfigLoader.html +3 -3
- package/docs/classes/Database.html +2 -2
- package/docs/classes/DatabaseCastObject.html +2 -2
- package/docs/classes/DatabaseConnection.html +22 -20
- package/docs/classes/DatabaseQueryError.html +5 -5
- package/docs/classes/DeadLockError.html +5 -5
- package/docs/classes/DiskSpaceError.html +5 -5
- package/docs/classes/DropTemporaryTableQuery.html +12 -6
- package/docs/classes/DuplicateEntryError.html +5 -5
- package/docs/classes/EntityNotFoundError.html +5 -5
- package/docs/classes/ExpiredTokenError.html +5 -5
- package/docs/classes/Handler.html +2 -2
- package/docs/classes/InternalError.html +5 -5
- package/docs/classes/InvalidCredentialsError.html +5 -5
- package/docs/classes/InvalidValueError.html +5 -5
- package/docs/classes/LineString.html +2 -2
- package/docs/classes/LockWaitTimeoutError.html +5 -5
- package/docs/classes/ManagedDatabaseConnection.html +5 -3
- package/docs/classes/Middleware.html +2 -2
- package/docs/classes/MissingConfigError.html +5 -5
- package/docs/classes/MissingParameterError.html +5 -5
- package/docs/classes/MySQLConnection.html +23 -21
- package/docs/classes/MySQLDatabase.html +2 -2
- package/docs/classes/NotImplementedError.html +5 -5
- package/docs/classes/Point.html +2 -2
- package/docs/classes/Polygon.html +2 -2
- package/docs/classes/Query.html +12 -6
- package/docs/classes/RawError.html +5 -5
- package/docs/classes/RawQuery.html +12 -6
- package/docs/classes/Request.html +2 -2
- package/docs/classes/Response.html +2 -2
- package/docs/classes/ResponseData.html +2 -2
- package/docs/classes/ServiceProvider.html +2 -2
- package/docs/classes/ServiceResponse.html +2 -2
- package/docs/classes/SetSessionVariableQuery.html +12 -6
- package/docs/classes/StormError.html +5 -5
- package/docs/classes/TemporaryTableQuery.html +12 -6
- package/docs/classes/TimeoutError.html +5 -5
- package/docs/classes/Token.html +2 -2
- package/docs/classes/TokenManager.html +2 -2
- package/docs/classes/Transaction.html +3 -2
- package/docs/classes/UnauthorizedAccessError.html +5 -5
- package/docs/enums/ErrorCode.html +2 -2
- package/docs/enums/ExitCode.html +2 -2
- package/docs/enums/HTTPMethod.html +2 -2
- package/docs/enums/IsolationLevel.html +2 -2
- package/docs/enums/JWTError.html +2 -2
- package/docs/enums/StatusCode.html +2 -2
- package/docs/functions/getInstance.html +1 -1
- package/docs/hierarchy.html +1 -1
- package/docs/interfaces/IAdditionalErrorDetails.html +1 -1
- package/docs/interfaces/ICloudwatchConfig.html +2 -2
- package/docs/interfaces/ICloudwatchCredentials.html +2 -2
- package/docs/interfaces/ICloudwatchStreamConfig.html +2 -2
- package/docs/interfaces/IConfig.html +2 -2
- package/docs/interfaces/IDatabaseConfig.html +2 -2
- package/docs/interfaces/IDatabaseConnection.html +5 -3
- package/docs/interfaces/IDatabasePosition.html +2 -2
- package/docs/interfaces/IErrorResponse.html +2 -2
- package/docs/interfaces/IFormData.html +2 -2
- package/docs/interfaces/IHandler.html +2 -2
- package/docs/interfaces/IInsertQueryResult.html +2 -2
- package/docs/interfaces/IJWTVerifyOptions.html +2 -2
- package/docs/interfaces/IOKPacket.html +2 -2
- package/docs/interfaces/IParameterMap.html +1 -1
- package/docs/interfaces/IQueryable.html +3 -2
- package/docs/interfaces/IRequestResponse.html +2 -2
- package/docs/interfaces/IServiceHeaders.html +1 -1
- package/docs/interfaces/ISetSessionVariableQueryInput.html +2 -2
- package/docs/interfaces/IStormCLIArgs.html +2 -2
- package/docs/interfaces/ITemporaryTableQueryInput.html +2 -2
- package/docs/interfaces/IUpdateQueryResult.html +2 -2
- package/docs/types/IDeleteQueryResult.html +1 -1
- package/docs/types/IHandlerError.html +1 -1
- package/docs/types/IHandlerResponse.html +1 -1
- package/docs/types/IStoredProcedureResult.html +1 -1
- package/docs/types/TCoordinate.html +1 -1
- package/eslint.config.js +14 -0
- package/lib/Application.js +2 -0
- package/lib/Application.js.map +1 -1
- package/lib/BackendAuthenticationMiddleware.js +0 -1
- package/lib/BackendAuthenticationMiddleware.js.map +1 -1
- package/lib/ConfigLoader.js +1 -0
- package/lib/ConfigLoader.js.map +1 -1
- package/lib/DatabaseConnection.d.ts +1 -0
- package/lib/DatabaseConnection.js +14 -3
- package/lib/DatabaseConnection.js.map +1 -1
- package/lib/DatabaseQueryError.js +0 -1
- package/lib/DatabaseQueryError.js.map +1 -1
- package/lib/DropTemporaryTableQuery.js.map +1 -1
- package/lib/ExpiredTokenError.js +0 -1
- package/lib/ExpiredTokenError.js.map +1 -1
- package/lib/IDatabaseConnection.d.ts +6 -0
- package/lib/IQueryable.d.ts +1 -0
- package/lib/InternalError.js +0 -1
- package/lib/InternalError.js.map +1 -1
- package/lib/InvalidCredentialsError.js +0 -1
- package/lib/InvalidCredentialsError.js.map +1 -1
- package/lib/InvalidValueError.js +0 -1
- package/lib/InvalidValueError.js.map +1 -1
- package/lib/ManagedDatabaseConnection.d.ts +2 -0
- package/lib/ManagedDatabaseConnection.js +5 -2
- package/lib/ManagedDatabaseConnection.js.map +1 -1
- package/lib/Middleware.js +0 -1
- package/lib/Middleware.js.map +1 -1
- package/lib/MySQLConnection.d.ts +2 -0
- package/lib/MySQLConnection.js +15 -13
- package/lib/MySQLConnection.js.map +1 -1
- package/lib/MySQLDatabase.js +0 -2
- package/lib/MySQLDatabase.js.map +1 -1
- package/lib/Query.d.ts +13 -0
- package/lib/Query.js +15 -0
- package/lib/Query.js.map +1 -1
- package/lib/Request.js.map +1 -1
- package/lib/Response.js.map +1 -1
- package/lib/ServiceProvider.js +0 -5
- package/lib/ServiceProvider.js.map +1 -1
- package/lib/TokenManager.js.map +1 -1
- package/lib/Transaction.d.ts +1 -0
- package/lib/Transaction.js +1 -0
- package/lib/Transaction.js.map +1 -1
- package/lib/mysql/queryFormatter.d.ts +1 -0
- package/lib/mysql/queryFormatter.js +17 -0
- package/lib/mysql/queryFormatter.js.map +1 -0
- package/lib/private/ConnectionReplicationWaiter.js +2 -1
- package/lib/private/ConnectionReplicationWaiter.js.map +1 -1
- package/package.json +11 -14
- package/src/Application.ts +3 -1
- package/src/BackendAuthenticationMiddleware.ts +0 -1
- package/src/ConfigLoader.ts +2 -1
- package/src/DatabaseConnection.ts +21 -6
- package/src/DatabaseQueryError.ts +0 -1
- package/src/DropTemporaryTableQuery.ts +3 -3
- package/src/ExpiredTokenError.ts +0 -1
- package/src/IDatabaseConnection.ts +7 -0
- package/src/IQueryable.ts +1 -0
- package/src/InternalError.ts +0 -1
- package/src/InvalidCredentialsError.ts +0 -1
- package/src/InvalidValueError.ts +0 -1
- package/src/ManagedDatabaseConnection.ts +7 -2
- package/src/Middleware.ts +0 -1
- package/src/MySQLConnection.ts +18 -12
- package/src/MySQLDatabase.ts +0 -2
- package/src/Query.ts +17 -1
- package/src/Request.ts +2 -1
- package/src/Response.ts +1 -1
- package/src/ServiceProvider.ts +0 -5
- package/src/TokenManager.ts +1 -1
- package/src/Transaction.ts +1 -0
- package/src/mysql/queryFormatter.ts +14 -0
- package/src/private/ConnectionReplicationWaiter.ts +2 -1
- package/.eslintrc.js +0 -61
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@breautek/storm",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.4.0",
|
|
4
4
|
"description": "Object-Oriented REST API framework",
|
|
5
5
|
"main": "lib/api.js",
|
|
6
6
|
"types": "lib/api.d.ts",
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
"build:release": "NODE_ENV=production tsc",
|
|
13
13
|
"build-lib": "rm -rf ./lib && tsc",
|
|
14
14
|
"build-docs": "typedoc --excludePrivate --readme none --out ./docs ./src/api.ts",
|
|
15
|
-
"lint": "eslint
|
|
16
|
-
"lint:fix": "eslint --
|
|
15
|
+
"lint": "eslint ./src ./spec",
|
|
16
|
+
"lint:fix": "eslint --fix ./src ./spec",
|
|
17
17
|
"unit": "jest",
|
|
18
18
|
"test": "npm run-script lint && jest",
|
|
19
19
|
"coverage": "codecov",
|
|
@@ -51,19 +51,19 @@
|
|
|
51
51
|
"@types/formidable": "3.4.5",
|
|
52
52
|
"@types/jsonwebtoken": "9.0.7",
|
|
53
53
|
"@types/mysql": "2.15.26",
|
|
54
|
-
"@types/node": "22.13.
|
|
54
|
+
"@types/node": "22.13.10",
|
|
55
55
|
"@types/uuid": "10.0.0",
|
|
56
56
|
"ajv": "8.17.1",
|
|
57
57
|
"body-parser": "1.20.3",
|
|
58
|
-
"commander": "
|
|
58
|
+
"commander": "13.1.0",
|
|
59
59
|
"express": "4.21.2",
|
|
60
60
|
"form-data": "4.0.2",
|
|
61
61
|
"formidable": "3.5.2",
|
|
62
62
|
"jsonwebtoken": "9.0.2",
|
|
63
63
|
"mysql": "2.18.1",
|
|
64
|
-
"sql-formatter": "15.4.
|
|
64
|
+
"sql-formatter": "15.4.11",
|
|
65
65
|
"tslib": "2.8.1",
|
|
66
|
-
"uuid": "11.0
|
|
66
|
+
"uuid": "11.1.0"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
69
|
"@arashi/interfaces": "1.x",
|
|
@@ -72,18 +72,15 @@
|
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"@arashi/interfaces": "1.2.1",
|
|
74
74
|
"@arashi/logger": "4.1.3",
|
|
75
|
-
"@totalpave/eslint-plugin": "
|
|
75
|
+
"@totalpave/eslint-plugin": "7.0.10",
|
|
76
76
|
"@types/jest": "29.5.14",
|
|
77
|
-
"@typescript-eslint/eslint-plugin": "7.18.0",
|
|
78
|
-
"@typescript-eslint/parser": "7.18.0",
|
|
79
77
|
"auto-changelog": "2.5.0",
|
|
80
|
-
"eslint": "8.57.1",
|
|
81
78
|
"jest": "29.7.0",
|
|
82
79
|
"jest-jasmine2": "29.7.0",
|
|
83
|
-
"ts-jest": "29.2.
|
|
80
|
+
"ts-jest": "29.2.6",
|
|
84
81
|
"ts-node": "10.9.2",
|
|
85
|
-
"typedoc": "0.27.
|
|
82
|
+
"typedoc": "0.27.9",
|
|
86
83
|
"typedoc-plugin-markdown": "4.4.2",
|
|
87
|
-
"typescript": "5.
|
|
84
|
+
"typescript": "5.8.2"
|
|
88
85
|
}
|
|
89
86
|
}
|
package/src/Application.ts
CHANGED
|
@@ -26,6 +26,7 @@ import {Response} from './Response';
|
|
|
26
26
|
import {ConfigLoader} from './ConfigLoader';
|
|
27
27
|
import {ICloudwatchConfig, IConfig} from './IConfig';
|
|
28
28
|
import {Command} from 'commander';
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
29
30
|
import Express = require('express');
|
|
30
31
|
import * as BodyParser from 'body-parser';
|
|
31
32
|
import * as http from 'http';
|
|
@@ -300,11 +301,12 @@ export abstract class Application
|
|
|
300
301
|
}
|
|
301
302
|
|
|
302
303
|
private $getVersionString(): string {
|
|
304
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
303
305
|
let pkg: any = require('../package.json');
|
|
304
306
|
return `${this._getVersion()} (Storm ${pkg.version})`;
|
|
305
307
|
}
|
|
306
308
|
|
|
307
|
-
private $buildArgOptions() {
|
|
309
|
+
private $buildArgOptions(): void {
|
|
308
310
|
this.$program = new Command();
|
|
309
311
|
|
|
310
312
|
this.$program.version(this.$getVersionString(), '-v, --version');
|
|
@@ -42,7 +42,6 @@ export class BackendAuthenticationMiddleware {
|
|
|
42
42
|
* @param response
|
|
43
43
|
* @param options Arbituary object containing any relevant information used for authentication.
|
|
44
44
|
*/
|
|
45
|
-
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
46
45
|
public execute(request: Request, options?: any): Promise<any> {
|
|
47
46
|
let config: IConfig = getInstance().getConfig();
|
|
48
47
|
|
package/src/ConfigLoader.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-require-imports */
|
|
1
2
|
/// <reference path="./defs/merge-change.d.ts" />
|
|
2
3
|
|
|
3
4
|
/*
|
|
@@ -85,7 +86,7 @@ export class ConfigLoader<TConfig extends IConfig = IConfig> {
|
|
|
85
86
|
|
|
86
87
|
await this.$validateSchema(config);
|
|
87
88
|
|
|
88
|
-
return
|
|
89
|
+
return config as TConfig;
|
|
89
90
|
}
|
|
90
91
|
|
|
91
92
|
/**
|
|
@@ -75,7 +75,7 @@ export abstract class DatabaseConnection<TAPI> implements IDatabaseConnection {
|
|
|
75
75
|
return this.$instantiationStack;
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
private $armLingerWarning() {
|
|
78
|
+
private $armLingerWarning(): void {
|
|
79
79
|
if (this.$lingerTimer) {
|
|
80
80
|
clearTimeout(this.$lingerTimer);
|
|
81
81
|
}
|
|
@@ -93,6 +93,8 @@ export abstract class DatabaseConnection<TAPI> implements IDatabaseConnection {
|
|
|
93
93
|
return this.$api;
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
+
public abstract formatQuery(query: IQueryable<any>, params?: any): string;
|
|
97
|
+
|
|
96
98
|
/**
|
|
97
99
|
* Returns true if connection was created without
|
|
98
100
|
* write access
|
|
@@ -138,8 +140,24 @@ export abstract class DatabaseConnection<TAPI> implements IDatabaseConnection {
|
|
|
138
140
|
let params: Record<string, any> = query.getParametersForQuery();
|
|
139
141
|
|
|
140
142
|
await query.onPreQuery(this);
|
|
141
|
-
|
|
142
|
-
|
|
143
|
+
|
|
144
|
+
let out: TQueryResult = null;
|
|
145
|
+
let e: unknown = null;
|
|
146
|
+
try {
|
|
147
|
+
let results: TQueryResult = await this._query<TQueryResult>(queryStr, params);
|
|
148
|
+
out = await (query.onPostProcess(this, results as any) as any);
|
|
149
|
+
}
|
|
150
|
+
catch (ex) {
|
|
151
|
+
e = ex;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
await query.onPostQuery(this);
|
|
155
|
+
|
|
156
|
+
if (e !== null) {
|
|
157
|
+
throw e;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return out;
|
|
143
161
|
}
|
|
144
162
|
|
|
145
163
|
/**
|
|
@@ -149,7 +167,6 @@ export abstract class DatabaseConnection<TAPI> implements IDatabaseConnection {
|
|
|
149
167
|
* @param streamOptions Stream options
|
|
150
168
|
* @returns Readable
|
|
151
169
|
*/
|
|
152
|
-
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
153
170
|
public stream(query: IQueryable<any>, streamOptions?: any): Readable {
|
|
154
171
|
this.$armLingerWarning();
|
|
155
172
|
let queryStr: string = null;
|
|
@@ -247,7 +264,6 @@ export abstract class DatabaseConnection<TAPI> implements IDatabaseConnection {
|
|
|
247
264
|
* @async
|
|
248
265
|
* @returns Promise
|
|
249
266
|
*/
|
|
250
|
-
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
251
267
|
protected abstract _query<TQueryResult>(query: string, params?: any): Promise<TQueryResult>;
|
|
252
268
|
|
|
253
269
|
/**
|
|
@@ -259,7 +275,6 @@ export abstract class DatabaseConnection<TAPI> implements IDatabaseConnection {
|
|
|
259
275
|
* @param streamOptions `Readable` stream options
|
|
260
276
|
* @returns `Readable`
|
|
261
277
|
*/
|
|
262
|
-
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
263
278
|
protected abstract _stream(query: string, params?: any, streamOptions?: any): Readable;
|
|
264
279
|
|
|
265
280
|
/**
|
|
@@ -22,11 +22,11 @@ export interface IDropTemporaryTableQueryInput {
|
|
|
22
22
|
|
|
23
23
|
export class DropTemporaryTableQuery extends Query<IDropTemporaryTableQueryInput> {
|
|
24
24
|
|
|
25
|
-
public getParameters(): IDropTemporaryTableQueryInput {
|
|
26
|
-
return
|
|
25
|
+
public override getParameters(): IDropTemporaryTableQueryInput {
|
|
26
|
+
return super.getParameters();
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
protected _getQuery(): string {
|
|
29
|
+
protected override _getQuery(): string {
|
|
30
30
|
return `
|
|
31
31
|
DROP TEMPORARY TABLE \`${this.getParameters().tableName}\`
|
|
32
32
|
`;
|
package/src/ExpiredTokenError.ts
CHANGED
|
@@ -19,7 +19,6 @@ import {ErrorCode} from './ErrorCode';
|
|
|
19
19
|
import {StatusCode} from './StatusCode';
|
|
20
20
|
|
|
21
21
|
export class ExpiredTokenError extends StormError<any> {
|
|
22
|
-
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
23
22
|
public constructor(details?: any) {
|
|
24
23
|
super(details);
|
|
25
24
|
}
|
|
@@ -35,6 +35,13 @@ export interface IDatabaseConnection {
|
|
|
35
35
|
commit(): Promise<void>;
|
|
36
36
|
rollback(): Promise<void>;
|
|
37
37
|
|
|
38
|
+
/**
|
|
39
|
+
* @since 8.4.0
|
|
40
|
+
* @param query
|
|
41
|
+
* @param params
|
|
42
|
+
*/
|
|
43
|
+
formatQuery(query: IQueryable<any>): string;
|
|
44
|
+
|
|
38
45
|
/**
|
|
39
46
|
* @since 8.1.0
|
|
40
47
|
*/
|
package/src/IQueryable.ts
CHANGED
|
@@ -18,6 +18,7 @@ import { IDatabaseConnection } from './IDatabaseConnection';
|
|
|
18
18
|
|
|
19
19
|
export interface IQueryable<T> {
|
|
20
20
|
onPreQuery(connection: IDatabaseConnection): Promise<void>;
|
|
21
|
+
onPostQuery(connection: IDatabaseConnection): Promise<void>;
|
|
21
22
|
getQuery(connection: IDatabaseConnection): string;
|
|
22
23
|
execute(connection: IDatabaseConnection): Promise<T>;
|
|
23
24
|
getParametersForQuery(): Record<string, any>;
|
package/src/InternalError.ts
CHANGED
|
@@ -19,7 +19,6 @@ import {ErrorCode} from './ErrorCode';
|
|
|
19
19
|
import {StatusCode} from './StatusCode';
|
|
20
20
|
|
|
21
21
|
export class InternalError extends StormError<any> {
|
|
22
|
-
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
23
22
|
public constructor(details?: any) {
|
|
24
23
|
super(details);
|
|
25
24
|
}
|
|
@@ -19,7 +19,6 @@ import {ErrorCode} from './ErrorCode';
|
|
|
19
19
|
import {StatusCode} from './StatusCode';
|
|
20
20
|
|
|
21
21
|
export class InvalidCredentialsError extends StormError<any> {
|
|
22
|
-
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
23
22
|
public constructor(details?: any) {
|
|
24
23
|
super(details);
|
|
25
24
|
}
|
package/src/InvalidValueError.ts
CHANGED
|
@@ -23,7 +23,6 @@ export class InvalidValueError extends StormError<{
|
|
|
23
23
|
expected: any;
|
|
24
24
|
got: any;
|
|
25
25
|
}> {
|
|
26
|
-
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
27
26
|
public constructor(variable: string, expected: any, got: any) {
|
|
28
27
|
super({
|
|
29
28
|
variable: variable,
|
|
@@ -20,6 +20,7 @@ import {Readable} from 'stream';
|
|
|
20
20
|
import { Query } from './Query';
|
|
21
21
|
import { IsolationLevel } from './IsolationLevel';
|
|
22
22
|
import { IDatabasePosition } from './IDatabasePosition';
|
|
23
|
+
import { IQueryable } from './IQueryable';
|
|
23
24
|
|
|
24
25
|
const TAG: string = 'ManagedDatabaseConnection';
|
|
25
26
|
|
|
@@ -42,6 +43,10 @@ export class ManagedDatabaseConnection implements IDatabaseConnection {
|
|
|
42
43
|
this.$instantionStack = new Error().stack;
|
|
43
44
|
}
|
|
44
45
|
|
|
46
|
+
public formatQuery(query: IQueryable<any>): string {
|
|
47
|
+
throw new Error('Unsupported API call');
|
|
48
|
+
}
|
|
49
|
+
|
|
45
50
|
// TODO(Breaking): Turn this API into async
|
|
46
51
|
public setConnection(connection: IDatabaseConnection): void {
|
|
47
52
|
if (this.$connection) {
|
|
@@ -130,6 +135,8 @@ export class ManagedDatabaseConnection implements IDatabaseConnection {
|
|
|
130
135
|
public setTimeout(timeout: number): void {
|
|
131
136
|
this.$getConnection().then((connection: IDatabaseConnection) => {
|
|
132
137
|
connection.setTimeout(timeout);
|
|
138
|
+
}).catch((error: unknown) => {
|
|
139
|
+
console.error(error);
|
|
133
140
|
});
|
|
134
141
|
}
|
|
135
142
|
|
|
@@ -142,7 +149,6 @@ export class ManagedDatabaseConnection implements IDatabaseConnection {
|
|
|
142
149
|
}
|
|
143
150
|
}
|
|
144
151
|
|
|
145
|
-
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
146
152
|
public query(query: Query, params?: any): Promise<any> {
|
|
147
153
|
return new Promise<any>((resolve, reject) => {
|
|
148
154
|
this.$getConnection().then((connection: IDatabaseConnection) => {
|
|
@@ -151,7 +157,6 @@ export class ManagedDatabaseConnection implements IDatabaseConnection {
|
|
|
151
157
|
})
|
|
152
158
|
}
|
|
153
159
|
|
|
154
|
-
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
155
160
|
public stream(query: Query, params?: any, streamOptions?: any): Readable {
|
|
156
161
|
throw new Error('stream is not supported on Managed Connections');
|
|
157
162
|
}
|
package/src/Middleware.ts
CHANGED
|
@@ -19,7 +19,6 @@ import {Response} from './Response';
|
|
|
19
19
|
import {IRequestResponse} from './IRequestResponse';
|
|
20
20
|
|
|
21
21
|
export abstract class Middleware {
|
|
22
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
23
22
|
public constructor() {}
|
|
24
23
|
|
|
25
24
|
protected abstract _execute(request: Request, response: Response): Promise<IRequestResponse>;
|
package/src/MySQLConnection.ts
CHANGED
|
@@ -35,6 +35,8 @@ import { IDatabasePosition } from './IDatabasePosition';
|
|
|
35
35
|
import { GetBinLogPositionQuery } from './private/GetBinLogPositionQuery';
|
|
36
36
|
import { GetSlavePositionQuery } from './private/GetSlavePositionQuery';
|
|
37
37
|
import { GetMasterPositionQuery } from './private/GetMasterPositionQuery';
|
|
38
|
+
import { IQueryable } from './IQueryable';
|
|
39
|
+
import { queryFormatter } from './mysql/queryFormatter';
|
|
38
40
|
|
|
39
41
|
const DEFAULT_HIGH_WATERMARK: number = 512; // in number of result objects
|
|
40
42
|
const TAG: string = 'MySQLConnection';
|
|
@@ -70,17 +72,19 @@ export class MySQLConnection extends DatabaseConnection<MySQL.PoolConnection> {
|
|
|
70
72
|
this.$transaction = false;
|
|
71
73
|
this.$isMasterConnection = null;
|
|
72
74
|
|
|
73
|
-
connection.config.queryFormat =
|
|
74
|
-
if (!values) return query;
|
|
75
|
+
connection.config.queryFormat = queryFormatter.bind(this);
|
|
75
76
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
77
|
+
// connection.config.queryFormat = function(query: string, values: any) {
|
|
78
|
+
// if (!values) return query;
|
|
79
|
+
|
|
80
|
+
// return query.replace(/:(\w+)/g, function(this: any, txt: string, key: string): string {
|
|
81
|
+
// // eslint-disable-next-line no-prototype-builtins
|
|
82
|
+
// if (values.hasOwnProperty(key)) {
|
|
83
|
+
// return this.escape(values[key]);
|
|
84
|
+
// }
|
|
85
|
+
// return txt;
|
|
86
|
+
// }.bind(this));
|
|
87
|
+
// };
|
|
84
88
|
}
|
|
85
89
|
|
|
86
90
|
/**
|
|
@@ -91,6 +95,10 @@ export class MySQLConnection extends DatabaseConnection<MySQL.PoolConnection> {
|
|
|
91
95
|
this.$isMasterConnection = result === null;
|
|
92
96
|
}
|
|
93
97
|
|
|
98
|
+
public override formatQuery(query: IQueryable<any>): string {
|
|
99
|
+
return this.getAPI().config.queryFormat(query.getQuery(this), query.getParametersForQuery());
|
|
100
|
+
}
|
|
101
|
+
|
|
94
102
|
public isMaster(): boolean {
|
|
95
103
|
return this.$isMasterConnection;
|
|
96
104
|
}
|
|
@@ -112,7 +120,6 @@ export class MySQLConnection extends DatabaseConnection<MySQL.PoolConnection> {
|
|
|
112
120
|
return await statusQuery.execute(this);
|
|
113
121
|
}
|
|
114
122
|
|
|
115
|
-
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
116
123
|
protected _query(query: string, params?: any): Promise<any> {
|
|
117
124
|
let logger: BaseLogger = getInstance().getLogger();
|
|
118
125
|
return new Promise((resolve, reject) => {
|
|
@@ -170,7 +177,6 @@ export class MySQLConnection extends DatabaseConnection<MySQL.PoolConnection> {
|
|
|
170
177
|
});
|
|
171
178
|
}
|
|
172
179
|
|
|
173
|
-
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
174
180
|
protected _stream(query: string, params?: any, streamOptions?: any): Readable {
|
|
175
181
|
if (!streamOptions) {
|
|
176
182
|
streamOptions = {};
|
package/src/MySQLDatabase.ts
CHANGED
|
@@ -38,12 +38,10 @@ export class MySQLDatabase extends Database<MySQL.PoolConfig, MySQL.PoolConnecti
|
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
42
41
|
public escape(value: any): string {
|
|
43
42
|
return MySQLDatabase.escape(value);
|
|
44
43
|
}
|
|
45
44
|
|
|
46
|
-
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
47
45
|
public static escape(value: any): string {
|
|
48
46
|
return MySQL.escape(value);
|
|
49
47
|
}
|
package/src/Query.ts
CHANGED
|
@@ -57,6 +57,22 @@ export abstract class Query<TQueryParameters = any, TQueryResultSet = any, TQuer
|
|
|
57
57
|
return Promise.resolve();
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
/**
|
|
61
|
+
* Overridable to execute statements after the main query.
|
|
62
|
+
* Can be used to clean up session variables or temporary tables, etc
|
|
63
|
+
*
|
|
64
|
+
* Unlike {@link onPostProcess}, this hook does not provide the result set,
|
|
65
|
+
* and will be invoked even if the main query produces an error.
|
|
66
|
+
*
|
|
67
|
+
* @since 8.3.0
|
|
68
|
+
*
|
|
69
|
+
* @param connection
|
|
70
|
+
* @returns {void}
|
|
71
|
+
*/
|
|
72
|
+
public onPostQuery(connection: IDatabaseConnection): Promise<void> {
|
|
73
|
+
return Promise.resolve();
|
|
74
|
+
}
|
|
75
|
+
|
|
60
76
|
/**
|
|
61
77
|
* Override to augment/manipulate the returned result set.
|
|
62
78
|
*
|
|
@@ -65,7 +81,7 @@ export abstract class Query<TQueryParameters = any, TQueryResultSet = any, TQuer
|
|
|
65
81
|
*/
|
|
66
82
|
public async onPostProcess(connection: IDatabaseConnection, resultSet: TQueryResultSet): Promise<TQueryPostProcessedResultSet> {
|
|
67
83
|
// By default, simply return the result set without any post processing.
|
|
68
|
-
return Promise.resolve(
|
|
84
|
+
return Promise.resolve(resultSet as any);
|
|
69
85
|
}
|
|
70
86
|
|
|
71
87
|
public async execute(connection: IDatabaseConnection): Promise<TQueryPostProcessedResultSet> {
|
package/src/Request.ts
CHANGED
|
@@ -30,6 +30,7 @@ import { JWTError } from './JWTError';
|
|
|
30
30
|
import { ResponseData } from './ResponseData';
|
|
31
31
|
import {StatusCode} from './StatusCode';
|
|
32
32
|
import { InternalError } from './InternalError';
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
33
34
|
import IncomingForm = require('formidable/Formidable');
|
|
34
35
|
|
|
35
36
|
export interface IParameterMap {
|
|
@@ -133,7 +134,7 @@ export class Request<TBody = any, TAuthToken extends IAuthTokenData = IAuthToken
|
|
|
133
134
|
let authHeader: string = getInstance().getConfig().authentication_header;
|
|
134
135
|
let tdata: TAuthToken = null;
|
|
135
136
|
try {
|
|
136
|
-
tdata =
|
|
137
|
+
tdata = (await getInstance().getTokenManager().verify(new Token(this.getHeader(authHeader)))) as TAuthToken;
|
|
137
138
|
}
|
|
138
139
|
catch (ex) {
|
|
139
140
|
let error: ResponseData = null;
|
package/src/Response.ts
CHANGED
|
@@ -140,7 +140,7 @@ export class Response<TResponse = SendableData, TErrorResponse = Error | IErrorR
|
|
|
140
140
|
}
|
|
141
141
|
// If it was not ResponseData<TResponse> then
|
|
142
142
|
// the method signature should have caught it
|
|
143
|
-
this.send((
|
|
143
|
+
this.send((error as unknown as TErrorResponse));
|
|
144
144
|
}
|
|
145
145
|
else {
|
|
146
146
|
this.send(new InternalError(error));
|
package/src/ServiceProvider.ts
CHANGED
|
@@ -78,7 +78,6 @@ export abstract class ServiceProvider {
|
|
|
78
78
|
return `/api/${this._getBase()}/${this.getVersion()}/${url}${this.urlSuffix()}${queryString}`;
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
82
81
|
public request(method: HTTPMethod, url: string, accessToken: string, data: any, headers?: IServiceHeaders, additionalOptions?: any): Promise<ServiceResponse> {
|
|
83
82
|
return new Promise<ServiceResponse>((resolve, reject) => {
|
|
84
83
|
let httpOpts: http.RequestOptions = {
|
|
@@ -138,22 +137,18 @@ export abstract class ServiceProvider {
|
|
|
138
137
|
request.end();
|
|
139
138
|
}
|
|
140
139
|
|
|
141
|
-
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
142
140
|
public get(url: string, accessToken: string, data?: any, headers?: IServiceHeaders, additionalOptions?: any): Promise<ServiceResponse> {
|
|
143
141
|
return this.request(HTTPMethod.GET, this._createURL(url, data), accessToken, NO_DATA, headers, additionalOptions);
|
|
144
142
|
}
|
|
145
143
|
|
|
146
|
-
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
147
144
|
public post(url: string, accessToken: string, data?: any, headers?: IServiceHeaders, additionalOptions?: any): Promise<ServiceResponse> {
|
|
148
145
|
return this.request(HTTPMethod.POST, this._createURL(url), accessToken, data, headers, additionalOptions);
|
|
149
146
|
}
|
|
150
147
|
|
|
151
|
-
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
152
148
|
public put(url: string, accessToken: string, data?: any, headers?: IServiceHeaders, additionalOptions?: any): Promise<ServiceResponse> {
|
|
153
149
|
return this.request(HTTPMethod.PUT, this._createURL(url), accessToken, data, headers, additionalOptions);
|
|
154
150
|
}
|
|
155
151
|
|
|
156
|
-
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
157
152
|
public delete(url: string, accessToken: string, data?: any, headers?: IServiceHeaders, additionalOptions?: any): Promise<ServiceResponse> {
|
|
158
153
|
return this.request(HTTPMethod.DELETE, this._createURL(url), accessToken, data, headers, additionalOptions);
|
|
159
154
|
}
|
package/src/TokenManager.ts
CHANGED
|
@@ -78,7 +78,7 @@ export class TokenManager<TAuthToken extends IAuthTokenData = IAuthTokenData> {
|
|
|
78
78
|
public decode(token: Token): Promise<TAuthToken> {
|
|
79
79
|
return new Promise<any>((resolve, reject) => {
|
|
80
80
|
try {
|
|
81
|
-
let decoded: TAuthToken =
|
|
81
|
+
let decoded: TAuthToken = jwt.decode(token.getSignature()) as TAuthToken;
|
|
82
82
|
resolve(decoded);
|
|
83
83
|
}
|
|
84
84
|
catch (ex) {
|
package/src/Transaction.ts
CHANGED
|
@@ -60,6 +60,7 @@ export class Transaction implements IQueryable<void> {
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
public async onPreQuery(connection: IDatabaseConnection): Promise<void> {}
|
|
63
|
+
public async onPostQuery(connection: IDatabaseConnection): Promise<void> {}
|
|
63
64
|
|
|
64
65
|
public getQuery(connection: IDatabaseConnection): string {
|
|
65
66
|
return null;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
|
|
2
|
+
import * as MySQL from 'mysql';
|
|
3
|
+
|
|
4
|
+
export function queryFormatter(query: string, values: any): string {
|
|
5
|
+
if (!values) return query;
|
|
6
|
+
|
|
7
|
+
return query.replace(/:(\w+)/g, function(this: any, txt: string, key: string): string {
|
|
8
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
9
|
+
if (values.hasOwnProperty(key)) {
|
|
10
|
+
return MySQL.escape(values[key]);
|
|
11
|
+
}
|
|
12
|
+
return txt;
|
|
13
|
+
});
|
|
14
|
+
}
|
|
@@ -66,7 +66,6 @@ export class ConnectionReplicationWaiter {
|
|
|
66
66
|
shouldTimeout = true;
|
|
67
67
|
}, timeout);
|
|
68
68
|
|
|
69
|
-
// eslint-disable-next-line no-constant-condition
|
|
70
69
|
while (true) {
|
|
71
70
|
if (shouldTimeout) {
|
|
72
71
|
didTimeout = true;
|
|
@@ -75,6 +74,8 @@ export class ConnectionReplicationWaiter {
|
|
|
75
74
|
|
|
76
75
|
let currentPos: IDatabasePosition = await this.$conn.getCurrentDatabasePosition();
|
|
77
76
|
|
|
77
|
+
// TODO: I have no idea what my intent is here, but it's obviously wrong
|
|
78
|
+
// eslint-disable-next-line no-constant-binary-expression
|
|
78
79
|
if (currentPos === null || (currentPos && !currentPos.page === null) || (currentPos && !currentPos.position === null)) {
|
|
79
80
|
throw new InternalError('Database Position not supported');
|
|
80
81
|
}
|
package/.eslintrc.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2017-2021 Norman Breau
|
|
3
|
-
|
|
4
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
you may not use this file except in compliance with the License.
|
|
6
|
-
You may obtain a copy of the License at
|
|
7
|
-
|
|
8
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
|
|
10
|
-
Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
See the License for the specific language governing permissions and
|
|
14
|
-
limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
module.exports = {
|
|
18
|
-
"extends": [
|
|
19
|
-
"eslint:recommended",
|
|
20
|
-
"plugin:@typescript-eslint/eslint-recommended",
|
|
21
|
-
"plugin:@typescript-eslint/recommended",
|
|
22
|
-
"plugin:@totalpave/recommendedTS"
|
|
23
|
-
],
|
|
24
|
-
"parser": "@typescript-eslint/parser",
|
|
25
|
-
"parserOptions": {
|
|
26
|
-
"project": "./spec/tsconfig.json",
|
|
27
|
-
"sourceType": "module",
|
|
28
|
-
"tsconfigRootDir": __dirname
|
|
29
|
-
},
|
|
30
|
-
"plugins": [
|
|
31
|
-
"@typescript-eslint",
|
|
32
|
-
"@totalpave"
|
|
33
|
-
],
|
|
34
|
-
"env": {
|
|
35
|
-
"node": true,
|
|
36
|
-
"jasmine": true
|
|
37
|
-
},
|
|
38
|
-
"rules": {
|
|
39
|
-
"@typescript-eslint/explicit-function-return-type": "off",
|
|
40
|
-
"@typescript-eslint/no-explicit-any": "off",
|
|
41
|
-
"@typescript-eslint/no-inferrable-types": "off",
|
|
42
|
-
"prefer-const": "off",
|
|
43
|
-
"@typescript-eslint/no-unused-vars": [
|
|
44
|
-
"error",
|
|
45
|
-
{
|
|
46
|
-
"args": "none",
|
|
47
|
-
"vars": "local"
|
|
48
|
-
}
|
|
49
|
-
],
|
|
50
|
-
"@typescript-eslint/consistent-type-definitions": "off",
|
|
51
|
-
"@typescript-eslint/consistent-type-assertions": [
|
|
52
|
-
"error",
|
|
53
|
-
{
|
|
54
|
-
"assertionStyle": "angle-bracket"
|
|
55
|
-
}
|
|
56
|
-
],
|
|
57
|
-
"no-empty-function": "off",
|
|
58
|
-
"@typescript-eslint/no-empty-function": "off",
|
|
59
|
-
"@typescript-eslint/camelcase": "off"
|
|
60
|
-
}
|
|
61
|
-
};
|