@breautek/storm 4.6.3 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +31 -0
- package/docs/README.md +7 -5
- package/docs/classes/Application.md +26 -26
- package/docs/classes/BackendAuthenticationMiddleware.md +2 -2
- package/docs/classes/CORSMiddleware.md +6 -6
- package/docs/classes/ConfigLoader.md +1 -1
- package/docs/classes/Database.md +12 -12
- package/docs/classes/DatabaseCastObject.md +3 -3
- package/docs/classes/DatabaseConnection.md +21 -21
- package/docs/classes/DatabaseQueryError.md +10 -10
- package/docs/classes/DeadLockError.md +10 -10
- package/docs/classes/DiskSpaceError.md +10 -10
- package/docs/classes/DropTemporaryTableQuery.md +10 -10
- package/docs/classes/DumpStream.md +1 -1
- package/docs/classes/DuplicateEntryError.md +10 -10
- package/docs/classes/EntityNotFoundError.md +10 -10
- package/docs/classes/ExpiredTokenError.md +10 -10
- package/docs/classes/Handler.md +13 -34
- package/docs/classes/InternalError.md +10 -10
- package/docs/classes/InvalidCredentialsError.md +10 -10
- package/docs/classes/InvalidValueError.md +10 -10
- package/docs/classes/LineString.md +4 -4
- package/docs/classes/ManagedDatabaseConnection.md +19 -19
- package/docs/classes/Middleware.md +3 -3
- package/docs/classes/MissingConfigError.md +10 -10
- package/docs/classes/MissingParameterError.md +10 -10
- package/docs/classes/MySQLConnection.md +22 -22
- package/docs/classes/MySQLDatabase.md +13 -13
- package/docs/classes/NotImplementedError.md +10 -10
- package/docs/classes/Point.md +4 -4
- package/docs/classes/Polygon.md +4 -4
- package/docs/classes/Query.md +34 -10
- package/docs/classes/RawError.md +10 -10
- package/docs/classes/RawQuery.md +10 -10
- package/docs/classes/Request.md +18 -18
- package/docs/classes/Response.md +11 -11
- package/docs/classes/ResponseData.md +7 -7
- package/docs/classes/ServiceProvider.md +15 -15
- package/docs/classes/ServiceResponse.md +19 -4
- package/docs/classes/SetSessionVariableQuery.md +8 -8
- package/docs/classes/StormError.md +10 -10
- package/docs/classes/TemporaryTableQuery.md +8 -8
- package/docs/classes/Token.md +2 -2
- package/docs/classes/TokenManager.md +4 -4
- package/docs/classes/Transaction.md +161 -0
- package/docs/classes/UnauthorizedAccessError.md +10 -10
- package/docs/enums/ErrorCode.md +9 -9
- package/docs/enums/ExitCode.md +2 -2
- package/docs/enums/HTTPMethod.md +4 -4
- package/docs/enums/IsolationLevel.md +4 -4
- package/docs/enums/JWTError.md +2 -2
- package/docs/enums/StatusCode.md +48 -48
- package/docs/interfaces/IConfig.md +8 -8
- package/docs/interfaces/IDatabaseConfig.md +6 -6
- package/docs/interfaces/IDatabaseConnection.md +16 -16
- package/docs/interfaces/IErrorResponse.md +5 -5
- package/docs/interfaces/IFormData.md +2 -2
- package/docs/interfaces/IHandler.md +1 -1
- package/docs/interfaces/IInsertQueryResult.md +3 -3
- package/docs/interfaces/IJWTVerifyOptions.md +1 -1
- package/docs/interfaces/IQueryable.md +119 -0
- package/docs/interfaces/IRequestResponse.md +2 -2
- package/docs/interfaces/ISetSessionVariableQueryInput.md +2 -2
- package/docs/interfaces/ITemporaryTableQueryInput.md +2 -2
- package/docs/interfaces/IUpdateQueryResult.md +2 -2
- package/jest.config.js +9 -5
- package/lib/DatabaseConnection.d.ts +3 -3
- package/lib/DatabaseConnection.js.map +1 -1
- package/lib/Handler.d.ts +0 -1
- package/lib/Handler.js +0 -2
- package/lib/Handler.js.map +1 -1
- package/lib/IDatabaseConnection.d.ts +3 -3
- package/lib/IQueryable.d.ts +8 -0
- package/lib/IQueryable.js +18 -0
- package/lib/IQueryable.js.map +1 -0
- package/lib/MySQLConnection.js +15 -4
- package/lib/MySQLConnection.js.map +1 -1
- package/lib/Query.d.ts +3 -2
- package/lib/Query.js.map +1 -1
- package/lib/ServiceResponse.d.ts +2 -0
- package/lib/ServiceResponse.js +3 -0
- package/lib/ServiceResponse.js.map +1 -1
- package/lib/SetSessionVariableQuery.js +2 -2
- package/lib/SetSessionVariableQuery.js.map +1 -1
- package/lib/Transaction.d.ts +24 -0
- package/lib/Transaction.js +82 -0
- package/lib/Transaction.js.map +1 -0
- package/lib/api.d.ts +2 -0
- package/lib/api.js +4 -2
- package/lib/api.js.map +1 -1
- package/package.json +12 -12
- package/src/DatabaseConnection.ts +4 -4
- package/src/Handler.ts +0 -4
- package/src/IDatabaseConnection.ts +3 -3
- package/src/IQueryable.ts +25 -0
- package/src/MySQLConnection.ts +15 -4
- package/src/Query.ts +3 -2
- package/src/ServiceResponse.ts +5 -0
- package/src/SetSessionVariableQuery.ts +2 -2
- package/src/Transaction.ts +97 -0
- package/src/api.ts +2 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Readable } from 'stream';
|
|
3
|
+
import { IQueryable } from './IQueryable';
|
|
3
4
|
import { IsolationLevel } from './IsolationLevel';
|
|
4
|
-
import { Query } from './Query';
|
|
5
5
|
export interface IDatabaseConnection {
|
|
6
6
|
setInstantiationStack(stack: string): void;
|
|
7
7
|
getInstantiationStack(): string;
|
|
@@ -9,8 +9,8 @@ export interface IDatabaseConnection {
|
|
|
9
9
|
isReadOnly(): boolean;
|
|
10
10
|
setTimeout(timeout: number): void;
|
|
11
11
|
getTimeout(): number;
|
|
12
|
-
query(query:
|
|
13
|
-
stream(query:
|
|
12
|
+
query(query: IQueryable<any>, params?: any): Promise<any>;
|
|
13
|
+
stream(query: IQueryable<any>, params?: any, streamOptions?: any): Readable;
|
|
14
14
|
close(forceClose?: boolean): Promise<void>;
|
|
15
15
|
isClosed(): boolean;
|
|
16
16
|
startTransaction(level?: IsolationLevel): Promise<void>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IDatabaseConnection } from './IDatabaseConnection';
|
|
2
|
+
export interface IQueryable<T> {
|
|
3
|
+
onPreQuery(connection: IDatabaseConnection): Promise<void>;
|
|
4
|
+
getQuery(connection: IDatabaseConnection): string;
|
|
5
|
+
execute(connection: IDatabaseConnection): Promise<T>;
|
|
6
|
+
getParametersForQuery(): Record<string, any>;
|
|
7
|
+
onPostProcess(connection: IDatabaseConnection, results: any): Promise<T>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
Copyright 2017-2023 Norman Breau
|
|
4
|
+
|
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
you may not use this file except in compliance with the License.
|
|
7
|
+
You may obtain a copy of the License at
|
|
8
|
+
|
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
|
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
See the License for the specific language governing permissions and
|
|
15
|
+
limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
//# sourceMappingURL=IQueryable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IQueryable.js","sourceRoot":"","sources":["../src/IQueryable.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;EAcE"}
|
package/lib/MySQLConnection.js
CHANGED
|
@@ -29,9 +29,17 @@ const SetIsolationLevelQuery_1 = require("./private/SetIsolationLevelQuery");
|
|
|
29
29
|
const DEFAULT_HIGH_WATERMARK = 512; // in number of result objects
|
|
30
30
|
const TAG = 'MySQLConnection';
|
|
31
31
|
const SQL_FORMATTING_OPTIONS = {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
tabWidth: 4,
|
|
33
|
+
keywordCase: 'upper',
|
|
34
|
+
useTabs: false,
|
|
35
|
+
indentStyle: 'standard',
|
|
36
|
+
logicalOperatorNewline: 'after',
|
|
37
|
+
commaPosition: 'before',
|
|
38
|
+
linesBetweenQueries: 1,
|
|
39
|
+
denseOperators: false,
|
|
40
|
+
newlineBeforeSemicolon: false,
|
|
41
|
+
tabulateAlias: true,
|
|
42
|
+
expressionWidth: 4
|
|
35
43
|
};
|
|
36
44
|
let startTransactionQuery = new StartTransactionQuery_1.StartTransactionQuery();
|
|
37
45
|
let commitQuery = new CommitQuery_1.CommitQuery();
|
|
@@ -75,7 +83,10 @@ class MySQLConnection extends DatabaseConnection_1.DatabaseConnection {
|
|
|
75
83
|
// SQLFormatter doesn't understand all MySQL syntaxes, so this is to prevent
|
|
76
84
|
// potentially valid queries from becoming errors simply because we couldn't
|
|
77
85
|
// log them.
|
|
78
|
-
sql = SQLFormatter.
|
|
86
|
+
sql = SQLFormatter.formatDialect(queryObject.sql, {
|
|
87
|
+
...SQL_FORMATTING_OPTIONS,
|
|
88
|
+
dialect: SQLFormatter.mysql
|
|
89
|
+
});
|
|
79
90
|
}
|
|
80
91
|
catch (ex) {
|
|
81
92
|
logger.warn(TAG, 'Unable to format query...');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MySQLConnection.js","sourceRoot":"","sources":["../src/MySQLConnection.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;EAcE;;;AAEF,6DAAwD;AACxD,6DAAwD;AACxD,yCAAuC;AAIvC,2EAAwE;AACxE,uDAAoD;AACpD,2DAAwD;AACxD,8CAA8C;AAC9C,2CAAkD;AAElD,mDAAgD;AAEhD,6EAAwE;AAExE,MAAM,sBAAsB,GAAW,GAAG,CAAC,CAAC,8BAA8B;AAC1E,MAAM,GAAG,GAAW,iBAAiB,CAAC;AAEtC,MAAM,sBAAsB,GAA+B;IACvD,QAAQ,EAAE,OAAO;
|
|
1
|
+
{"version":3,"file":"MySQLConnection.js","sourceRoot":"","sources":["../src/MySQLConnection.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;EAcE;;;AAEF,6DAAwD;AACxD,6DAAwD;AACxD,yCAAuC;AAIvC,2EAAwE;AACxE,uDAAoD;AACpD,2DAAwD;AACxD,8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AAC,QAAQ,EAAE,CAAC;iBACrC;qBACI;oBACD,eAAe,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;iBACvC;aACJ;iBACI;gBACD,eAAe,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;aACvC;YAED,eAAe,CAAC,IAAI,CAAC,GAAG,EAAE;gBACtB,IAAI,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE,CAAC;gBACxB,OAAO,EAAE,CAAC;YACd,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,KAAU,EAAE,EAAE;gBACpB,IAAA,sBAAW,GAAE,CAAC,SAAS,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;gBAC5C,IAAI,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE,CAAC;gBACxB,OAAO,EAAE,CAAC;YACd,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAlMD,0CAkMC"}
|
package/lib/Query.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { IDatabaseConnection } from './IDatabaseConnection';
|
|
2
|
-
|
|
2
|
+
import { IQueryable } from './IQueryable';
|
|
3
|
+
export declare abstract class Query<TQueryParameters = any, TQueryResultSet = any, TQueryPostProcessedResultSet = TQueryResultSet> implements IQueryable<TQueryPostProcessedResultSet> {
|
|
3
4
|
private $params;
|
|
4
5
|
constructor(parameters?: TQueryParameters);
|
|
5
6
|
/**
|
|
@@ -11,7 +12,7 @@ export declare abstract class Query<TQueryParameters = any, TQueryResultSet = an
|
|
|
11
12
|
*
|
|
12
13
|
* @returns parameters that will be used when this query is ran.
|
|
13
14
|
*/
|
|
14
|
-
getParametersForQuery(): Record<
|
|
15
|
+
getParametersForQuery(): Record<string, any>;
|
|
15
16
|
protected abstract _getQuery(connection: IDatabaseConnection): string;
|
|
16
17
|
getQuery(connection: IDatabaseConnection): string;
|
|
17
18
|
/**
|
package/lib/Query.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Query.js","sourceRoot":"","sources":["../src/Query.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;EAcE;;;
|
|
1
|
+
{"version":3,"file":"Query.js","sourceRoot":"","sources":["../src/Query.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;EAcE;;;AAKF,MAAsB,KAAK;IAGvB,YAAmB,UAA6B;QAC5C,IAAI,CAAC,OAAO,GAAG,UAAU,CAAC;IAC9B,CAAC;IAED;;OAEG;IACI,aAAa;QAChB,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;IAED;;;;OAIG;IACI,qBAAqB;QACxB,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;IAIM,QAAQ,CAAC,UAA+B;QAC3C,OAAO,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;IACtC,CAAC;IAED;;;;;;OAMG;IACI,UAAU,CAAC,UAA+B;QAC7C,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC7B,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,aAAa,CAAC,UAA+B,EAAE,SAA0B;QAClF,wEAAwE;QACxE,OAAO,OAAO,CAAC,OAAO,CAAM,SAAS,CAAC,CAAC;IAC3C,CAAC;IAEM,KAAK,CAAC,OAAO,CAAC,UAA+B;QAChD,OAAO,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;CACJ;AAtDD,sBAsDC"}
|
package/lib/ServiceResponse.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
import { IncomingMessage } from 'http';
|
|
4
|
+
import { StatusCode } from './StatusCode';
|
|
4
5
|
export declare class ServiceResponse {
|
|
5
6
|
private $data;
|
|
6
7
|
private $response;
|
|
@@ -8,4 +9,5 @@ export declare class ServiceResponse {
|
|
|
8
9
|
getRaw(): Buffer;
|
|
9
10
|
getUTF8(): string;
|
|
10
11
|
getJSON(): any;
|
|
12
|
+
getStatusCode(): StatusCode;
|
|
11
13
|
}
|
package/lib/ServiceResponse.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServiceResponse.js","sourceRoot":"","sources":["../src/ServiceResponse.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;EAcE;;;
|
|
1
|
+
{"version":3,"file":"ServiceResponse.js","sourceRoot":"","sources":["../src/ServiceResponse.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;EAcE;;;AAKF,MAAa,eAAe;IAIxB,YAAmB,IAAY,EAAE,QAAyB;QACtD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC9B,CAAC;IAEM,MAAM;QACT,OAAO,IAAI,CAAC,KAAK,CAAC;IACtB,CAAC;IAEM,OAAO;QACV,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IACvC,CAAC;IAEM,OAAO;QACV,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;IACtC,CAAC;IAEM,aAAa;QAChB,OAAO,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC;IACrC,CAAC;CACJ;AAxBD,0CAwBC"}
|
|
@@ -5,11 +5,11 @@ const Query_1 = require("./Query");
|
|
|
5
5
|
class SetSessionVariableQuery extends Query_1.Query {
|
|
6
6
|
_getQuery() {
|
|
7
7
|
let params = this.getParameters();
|
|
8
|
-
if (
|
|
8
|
+
if (!/^([A-Za-z_])+([a-zA-Z0-9_])+$/g.test(params.name)) {
|
|
9
9
|
throw new Error('Illegal Variable Name');
|
|
10
10
|
}
|
|
11
11
|
// Only allow alpha letters & underscores for variable names
|
|
12
|
-
return `SET SESSION
|
|
12
|
+
return `SET SESSION \`${params.name}\` = :value`;
|
|
13
13
|
}
|
|
14
14
|
getParametersForQuery() {
|
|
15
15
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SetSessionVariableQuery.js","sourceRoot":"","sources":["../src/SetSessionVariableQuery.ts"],"names":[],"mappings":";;;AACA,mCAEiB;AAOjB,MAAa,uBAAwB,SAAQ,aAA0C;IACzE,SAAS;QACf,IAAI,MAAM,GAAkC,IAAI,CAAC,aAAa,EAAE,CAAC;QAEjE,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"SetSessionVariableQuery.js","sourceRoot":"","sources":["../src/SetSessionVariableQuery.ts"],"names":[],"mappings":";;;AACA,mCAEiB;AAOjB,MAAa,uBAAwB,SAAQ,aAA0C;IACzE,SAAS;QACf,IAAI,MAAM,GAAkC,IAAI,CAAC,aAAa,EAAE,CAAC;QAEjE,IAAI,CAAC,gCAAgC,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE;YACrD,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;SAC5C;QAED,4DAA4D;QAC5D,OAAO,iBAAiB,MAAM,CAAC,IAAI,aAAa,CAAC;IACrD,CAAC;IAEM,qBAAqB;QACxB,OAAO;YACH,KAAK,EAAE,IAAI,CAAC,aAAa,EAAE,CAAC,KAAK;SACpC,CAAC;IACN,CAAC;CACJ;AAjBD,0DAiBC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { IDatabaseConnection } from './IDatabaseConnection';
|
|
2
|
+
import { IQueryable } from './IQueryable';
|
|
3
|
+
import { Application } from './Application';
|
|
4
|
+
import { IsolationLevel } from './IsolationLevel';
|
|
5
|
+
export type ITransactionExecutor = (connection: IDatabaseConnection) => Promise<void>;
|
|
6
|
+
/**
|
|
7
|
+
* A class encapsulating an entire transaction from beginning to commitment.
|
|
8
|
+
*
|
|
9
|
+
* This encapsulates a routine to conduct for the transaction.
|
|
10
|
+
* Should the transaction fail due to a deadlock, the transaction will automatically
|
|
11
|
+
* be tried.
|
|
12
|
+
*/
|
|
13
|
+
export declare class Transaction implements IQueryable<void> {
|
|
14
|
+
private $retryLimit;
|
|
15
|
+
private $application;
|
|
16
|
+
private $isolationLevel;
|
|
17
|
+
private $executor;
|
|
18
|
+
constructor(app: Application, executor: ITransactionExecutor, retryLimit?: number, isolationLevel?: IsolationLevel);
|
|
19
|
+
onPreQuery(connection: IDatabaseConnection): Promise<void>;
|
|
20
|
+
getQuery(connection: IDatabaseConnection): string;
|
|
21
|
+
getParametersForQuery(): Record<string, any>;
|
|
22
|
+
onPostProcess(connection: IDatabaseConnection, results: any): Promise<void>;
|
|
23
|
+
execute(connection: IDatabaseConnection): Promise<void>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
Copyright 2017-2023 Norman Breau
|
|
4
|
+
|
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
you may not use this file except in compliance with the License.
|
|
7
|
+
You may obtain a copy of the License at
|
|
8
|
+
|
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
|
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
See the License for the specific language governing permissions and
|
|
15
|
+
limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.Transaction = void 0;
|
|
19
|
+
const IsolationLevel_1 = require("./IsolationLevel");
|
|
20
|
+
const InternalError_1 = require("./InternalError");
|
|
21
|
+
const DeadLockError_1 = require("./DeadLockError");
|
|
22
|
+
const InvalidValueError_1 = require("./InvalidValueError");
|
|
23
|
+
const TAG = 'Transaction';
|
|
24
|
+
/**
|
|
25
|
+
* A class encapsulating an entire transaction from beginning to commitment.
|
|
26
|
+
*
|
|
27
|
+
* This encapsulates a routine to conduct for the transaction.
|
|
28
|
+
* Should the transaction fail due to a deadlock, the transaction will automatically
|
|
29
|
+
* be tried.
|
|
30
|
+
*/
|
|
31
|
+
class Transaction {
|
|
32
|
+
constructor(app, executor, retryLimit = Infinity, isolationLevel = IsolationLevel_1.IsolationLevel.REPEATABLE_READ) {
|
|
33
|
+
this.$application = app;
|
|
34
|
+
this.$executor = executor;
|
|
35
|
+
if (retryLimit === null || retryLimit === undefined) {
|
|
36
|
+
retryLimit = Infinity;
|
|
37
|
+
}
|
|
38
|
+
else if (retryLimit <= 0) {
|
|
39
|
+
throw new InvalidValueError_1.InvalidValueError('retryLimit', 'integer > 0', retryLimit);
|
|
40
|
+
}
|
|
41
|
+
this.$retryLimit = retryLimit;
|
|
42
|
+
this.$isolationLevel = isolationLevel;
|
|
43
|
+
}
|
|
44
|
+
async onPreQuery(connection) { }
|
|
45
|
+
getQuery(connection) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
getParametersForQuery() {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
async onPostProcess(connection, results) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
async execute(connection) {
|
|
55
|
+
if (connection.isTransaction()) {
|
|
56
|
+
throw new InternalError_1.InternalError('Connection must not be in an active transaction. Commit your current transaction first.');
|
|
57
|
+
}
|
|
58
|
+
let attemptCount = 0;
|
|
59
|
+
do {
|
|
60
|
+
attemptCount++;
|
|
61
|
+
this.$application.getLogger().info(TAG, `Starting transaction attempt ${attemptCount} of ${this.$retryLimit === Infinity ? 'Infinity' : this.$retryLimit.toString()}`);
|
|
62
|
+
await connection.startTransaction(this.$isolationLevel);
|
|
63
|
+
try {
|
|
64
|
+
await this.$executor(connection);
|
|
65
|
+
await connection.commit();
|
|
66
|
+
// If we made it here, we can break out of our retry loop
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
catch (ex) {
|
|
70
|
+
if (attemptCount < this.$retryLimit && ex instanceof DeadLockError_1.DeadLockError) {
|
|
71
|
+
this.$application.getLogger().warn(TAG, `Deadlock received... retrying transaction`);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
await connection.rollback();
|
|
75
|
+
throw ex;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
} while (attemptCount < this.$retryLimit);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.Transaction = Transaction;
|
|
82
|
+
//# sourceMappingURL=Transaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Transaction.js","sourceRoot":"","sources":["../src/Transaction.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;EAcE;;;AAKF,qDAAkD;AAClD,mDAAgD;AAChD,mDAAgD;AAChD,2DAAwD;AAExD,MAAM,GAAG,GAAW,aAAa,CAAC;AAIlC;;;;;;GAMG;AACH,MAAa,WAAW;IAMpB,YAAmB,GAAgB,EAAE,QAA8B,EAAE,aAAqB,QAAQ,EAAE,iBAAiC,+BAAc,CAAC,eAAe;QAC/J,IAAI,CAAC,YAAY,GAAG,GAAG,CAAC;QACxB,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAE1B,IAAI,UAAU,KAAK,IAAI,IAAI,UAAU,KAAK,SAAS,EAAE;YACjD,UAAU,GAAG,QAAQ,CAAC;SACzB;aACI,IAAI,UAAU,IAAI,CAAC,EAAE;YACtB,MAAM,IAAI,qCAAiB,CAAC,YAAY,EAAE,aAAa,EAAE,UAAU,CAAC,CAAC;SACxE;QAED,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAC9B,IAAI,CAAC,eAAe,GAAG,cAAc,CAAC;IAC1C,CAAC;IAEM,KAAK,CAAC,UAAU,CAAC,UAA+B,IAAkB,CAAC;IAEnE,QAAQ,CAAC,UAA+B;QAC3C,OAAO,IAAI,CAAC;IAChB,CAAC;IACM,qBAAqB;QACxB,OAAO,IAAI,CAAC;IAChB,CAAC;IACM,KAAK,CAAC,aAAa,CAAC,UAA+B,EAAE,OAAY;QACpE,OAAO,IAAI,CAAC;IAChB,CAAC;IAEM,KAAK,CAAC,OAAO,CAAC,UAA+B;QAChD,IAAI,UAAU,CAAC,aAAa,EAAE,EAAE;YAC5B,MAAM,IAAI,6BAAa,CAAC,yFAAyF,CAAC,CAAC;SACtH;QAED,IAAI,YAAY,GAAW,CAAC,CAAC;QAC7B,GAAG;YACC,YAAY,EAAE,CAAC;YACf,IAAI,CAAC,YAAY,CAAC,SAAS,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,gCAAgC,YAAY,OAAO,IAAI,CAAC,WAAW,KAAK,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;YACvK,MAAM,UAAU,CAAC,gBAAgB,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;YACxD,IAAI;gBACA,MAAM,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;gBACjC,MAAM,UAAU,CAAC,MAAM,EAAE,CAAC;gBAE1B,yDAAyD;gBACzD,MAAM;aACT;YACD,OAAO,EAAE,EAAE;gBACP,IAAI,YAAY,GAAG,IAAI,CAAC,WAAW,IAAI,EAAE,YAAY,6BAAa,EAAE;oBAChE,IAAI,CAAC,YAAY,CAAC,SAAS,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,2CAA2C,CAAC,CAAC;iBACxF;qBACI;oBACD,MAAM,UAAU,CAAC,QAAQ,EAAE,CAAC;oBAC5B,MAAM,EAAE,CAAC;iBACZ;aACJ;SACJ,QAAQ,YAAY,GAAG,IAAI,CAAC,WAAW,EAAE;IAC9C,CAAC;CACJ;AA7DD,kCA6DC"}
|
package/lib/api.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export { IDeleteQueryResult } from './IDeleteQueryResult';
|
|
|
15
15
|
export { IUpdateQueryResult } from './IUpdateQueryResult';
|
|
16
16
|
export { SetSessionVariableQuery, ISetSessionVariableQueryInput } from './SetSessionVariableQuery';
|
|
17
17
|
export { IsolationLevel } from './IsolationLevel';
|
|
18
|
+
export { Transaction } from './Transaction';
|
|
18
19
|
export { ErrorCode } from './ErrorCode';
|
|
19
20
|
export { RawError } from './RawError';
|
|
20
21
|
export { StormError, IErrorResponse, IAdditionalErrorDetails } from './StormError';
|
|
@@ -52,6 +53,7 @@ export { IFormData } from './IFormData';
|
|
|
52
53
|
export { IDatabaseConnection } from './IDatabaseConnection';
|
|
53
54
|
export { IServiceHeaders } from './IServiceHeaders';
|
|
54
55
|
export { IAuthTokenData } from './IAuthTokenData';
|
|
56
|
+
export { IQueryable } from './IQueryable';
|
|
55
57
|
export { Token } from './Token';
|
|
56
58
|
export { TokenManager } from './TokenManager';
|
|
57
59
|
export { ExitCode } from './ExitCode';
|
package/lib/api.js
CHANGED
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.
|
|
19
|
-
exports.formidable = void 0;
|
|
18
|
+
exports.LineString = exports.Point = exports.DatabaseCastObject = exports.DumpStream = exports.ExitCode = exports.TokenManager = exports.Token = exports.BackendAuthenticationMiddleware = exports.ServiceResponse = exports.HTTPMethod = exports.ServiceProvider = exports.CORSMiddleware = exports.Handler = exports.ResponseData = exports.Response = exports.Request = exports.Middleware = exports.StatusCode = exports.DeadLockError = exports.NotImplementedError = exports.DatabaseQueryError = exports.MissingConfigError = exports.DuplicateEntryError = exports.DiskSpaceError = exports.EntityNotFoundError = exports.UnauthorizedAccessError = exports.InvalidValueError = exports.ExpiredTokenError = exports.InternalError = exports.InvalidCredentialsError = exports.MissingParameterError = exports.JWTError = exports.StormError = exports.RawError = exports.ErrorCode = exports.Transaction = exports.IsolationLevel = exports.SetSessionVariableQuery = exports.RawQuery = exports.DropTemporaryTableQuery = exports.TemporaryTableQuery = exports.Query = exports.ManagedDatabaseConnection = exports.MySQLConnection = exports.MySQLDatabase = exports.DatabaseConnection = exports.Database = exports.ConfigLoader = exports.Application = exports.getInstance = void 0;
|
|
19
|
+
exports.formidable = exports.Polygon = void 0;
|
|
20
20
|
// Application
|
|
21
21
|
var instance_1 = require("./instance");
|
|
22
22
|
Object.defineProperty(exports, "getInstance", { enumerable: true, get: function () { return instance_1.getInstance; } });
|
|
@@ -48,6 +48,8 @@ var SetSessionVariableQuery_1 = require("./SetSessionVariableQuery");
|
|
|
48
48
|
Object.defineProperty(exports, "SetSessionVariableQuery", { enumerable: true, get: function () { return SetSessionVariableQuery_1.SetSessionVariableQuery; } });
|
|
49
49
|
var IsolationLevel_1 = require("./IsolationLevel");
|
|
50
50
|
Object.defineProperty(exports, "IsolationLevel", { enumerable: true, get: function () { return IsolationLevel_1.IsolationLevel; } });
|
|
51
|
+
var Transaction_1 = require("./Transaction");
|
|
52
|
+
Object.defineProperty(exports, "Transaction", { enumerable: true, get: function () { return Transaction_1.Transaction; } });
|
|
51
53
|
// Errors
|
|
52
54
|
var ErrorCode_1 = require("./ErrorCode");
|
|
53
55
|
Object.defineProperty(exports, "ErrorCode", { enumerable: true, get: function () { return ErrorCode_1.ErrorCode; } });
|
package/lib/api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;EAcE;;;;AAEF,cAAc;AACd,uCAAuC;AAA/B,uGAAA,WAAW,OAAA;AACnB,6CAA0C;AAAlC,0GAAA,WAAW,OAAA;AAEnB,SAAS;AACT,+CAA4C;AAApC,4GAAA,YAAY,OAAA;AAEpB,WAAW;AACX,uCAAoC;AAA5B,oGAAA,QAAQ,OAAA;AAChB,2DAAwD;AAAhD,wHAAA,kBAAkB,OAAA;AAC1B,iDAA8C;AAAtC,8GAAA,aAAa,OAAA;AACrB,qDAAkD;AAA1C,kHAAA,eAAe,OAAA;AACvB,yEAAsE;AAA9D,sIAAA,y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AkB,OAAA;AAC1B,iCAA8B;AAAtB,8FAAA,KAAK,OAAA;AACb,2CAAwC;AAAhC,wGAAA,UAAU,OAAA;AAClB,qCAAkC;AAA1B,kGAAA,OAAO,OAAA;AAEf,cAAc;AACd,yCAAyC;AACjC,gCAAU"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@breautek/storm",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "Object-Oriented REST API framework",
|
|
5
5
|
"main": "lib/api.js",
|
|
6
6
|
"types": "lib/api.d.ts",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"breautek"
|
|
38
38
|
],
|
|
39
39
|
"engines": {
|
|
40
|
-
"node": ">=
|
|
40
|
+
"node": ">= 14.0.0"
|
|
41
41
|
},
|
|
42
42
|
"author": "norman@normanbreau.com",
|
|
43
43
|
"license": "Apache-2.0",
|
|
@@ -48,19 +48,19 @@
|
|
|
48
48
|
"@types/body-parser": "1.19.2",
|
|
49
49
|
"@types/express": "4.17.15",
|
|
50
50
|
"@types/formidable": "1.2.3",
|
|
51
|
-
"@types/jsonwebtoken": "9.0.
|
|
51
|
+
"@types/jsonwebtoken": "9.0.1",
|
|
52
52
|
"@types/mysql": "2.15.21",
|
|
53
53
|
"@types/node": "18.11.18",
|
|
54
54
|
"@types/uuid": "9.0.0",
|
|
55
55
|
"ajv": "8.12.0",
|
|
56
56
|
"body-parser": "1.20.1",
|
|
57
|
-
"commander": "
|
|
57
|
+
"commander": "10.0.0",
|
|
58
58
|
"express": "4.18.2",
|
|
59
59
|
"form-data": "4.0.0",
|
|
60
60
|
"formidable": "1.2.2",
|
|
61
61
|
"jsonwebtoken": "9.0.0",
|
|
62
62
|
"mysql": "2.18.1",
|
|
63
|
-
"sql-formatter": "
|
|
63
|
+
"sql-formatter": "12.0.6",
|
|
64
64
|
"tslib": "2.4.1",
|
|
65
65
|
"uuid": "9.0.0"
|
|
66
66
|
},
|
|
@@ -69,17 +69,17 @@
|
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"@arashi/logger": "2.1.0",
|
|
72
|
-
"@totalpave/eslint-plugin": "6.0.
|
|
73
|
-
"@types/jest": "29.2.
|
|
74
|
-
"@typescript-eslint/eslint-plugin": "5.48.
|
|
75
|
-
"@typescript-eslint/parser": "5.48.
|
|
72
|
+
"@totalpave/eslint-plugin": "6.0.8",
|
|
73
|
+
"@types/jest": "29.2.6",
|
|
74
|
+
"@typescript-eslint/eslint-plugin": "5.48.2",
|
|
75
|
+
"@typescript-eslint/parser": "5.48.2",
|
|
76
76
|
"auto-changelog": "2.4.0",
|
|
77
|
-
"eslint": "8.
|
|
77
|
+
"eslint": "8.32.0",
|
|
78
78
|
"jest": "29.3.1",
|
|
79
79
|
"jest-jasmine2": "29.3.1",
|
|
80
|
-
"ts-jest": "29.0.
|
|
80
|
+
"ts-jest": "29.0.5",
|
|
81
81
|
"ts-node": "10.9.1",
|
|
82
|
-
"typedoc": "0.23.
|
|
82
|
+
"typedoc": "0.23.24",
|
|
83
83
|
"typedoc-plugin-markdown": "3.14.0",
|
|
84
84
|
"typescript": "4.9.4"
|
|
85
85
|
}
|
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
} from './instance';
|
|
20
20
|
import {Readable} from 'stream';
|
|
21
21
|
import {IDatabaseConnection} from './IDatabaseConnection';
|
|
22
|
-
import {
|
|
22
|
+
import {IQueryable} from './IQueryable';
|
|
23
23
|
import { IConfig } from './IConfig';
|
|
24
24
|
import { IsolationLevel } from './IsolationLevel';
|
|
25
25
|
|
|
@@ -129,12 +129,12 @@ export abstract class DatabaseConnection<TAPI> implements IDatabaseConnection {
|
|
|
129
129
|
* @async
|
|
130
130
|
* @returns Promise<TQueryResult>
|
|
131
131
|
*/
|
|
132
|
-
public async query<TQueryResult = any>(query:
|
|
132
|
+
public async query<TQueryResult = any>(query: IQueryable<TQueryResult>): Promise<TQueryResult> {
|
|
133
133
|
this.$armLingerWarning();
|
|
134
134
|
|
|
135
135
|
let queryStr: string = null;
|
|
136
136
|
queryStr = query.getQuery(this);
|
|
137
|
-
let params: Record<
|
|
137
|
+
let params: Record<string, any> = query.getParametersForQuery();
|
|
138
138
|
|
|
139
139
|
await query.onPreQuery(this);
|
|
140
140
|
let results: TQueryResult = await this._query<TQueryResult>(queryStr, params);
|
|
@@ -149,7 +149,7 @@ export abstract class DatabaseConnection<TAPI> implements IDatabaseConnection {
|
|
|
149
149
|
* @returns Readable
|
|
150
150
|
*/
|
|
151
151
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
152
|
-
public stream(query:
|
|
152
|
+
public stream(query: IQueryable<any>, streamOptions?: any): Readable {
|
|
153
153
|
this.$armLingerWarning();
|
|
154
154
|
let queryStr: string = null;
|
|
155
155
|
let params: Record<any, any> = query.getParametersForQuery();
|
package/src/Handler.ts
CHANGED
|
@@ -144,10 +144,6 @@ export class Handler<
|
|
|
144
144
|
response.error(error);
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
-
public attach(app: Application): void {
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
|
|
151
147
|
public async get(request: Request<TGetRequest>, response: Response<TGetResponse>): Promise<void> {
|
|
152
148
|
this.getApplication().getLogger().info(TAG, `${request.getForwardedIP()} (${request.getIP()}) - ${request.getMethod()} ${request.getURL()} - UA(${request.getHeader('user-agent')})`);
|
|
153
149
|
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import { Readable } from 'stream';
|
|
18
|
+
import { IQueryable } from './IQueryable';
|
|
18
19
|
import { IsolationLevel } from './IsolationLevel';
|
|
19
|
-
import { Query } from './Query';
|
|
20
20
|
|
|
21
21
|
export interface IDatabaseConnection {
|
|
22
22
|
setInstantiationStack(stack: string): void;
|
|
@@ -25,8 +25,8 @@ export interface IDatabaseConnection {
|
|
|
25
25
|
isReadOnly(): boolean;
|
|
26
26
|
setTimeout(timeout: number): void;
|
|
27
27
|
getTimeout(): number;
|
|
28
|
-
query(query:
|
|
29
|
-
stream(query:
|
|
28
|
+
query(query: IQueryable<any>, params?: any): Promise<any>;
|
|
29
|
+
stream(query: IQueryable<any>, params?: any, streamOptions?: any): Readable;
|
|
30
30
|
close(forceClose?: boolean): Promise<void>;
|
|
31
31
|
isClosed(): boolean;
|
|
32
32
|
startTransaction(level?: IsolationLevel): Promise<void>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2017-2023 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
|
+
import { IDatabaseConnection } from './IDatabaseConnection';
|
|
18
|
+
|
|
19
|
+
export interface IQueryable<T> {
|
|
20
|
+
onPreQuery(connection: IDatabaseConnection): Promise<void>;
|
|
21
|
+
getQuery(connection: IDatabaseConnection): string;
|
|
22
|
+
execute(connection: IDatabaseConnection): Promise<T>;
|
|
23
|
+
getParametersForQuery(): Record<string, any>;
|
|
24
|
+
onPostProcess(connection: IDatabaseConnection, results: any): Promise<T>;
|
|
25
|
+
}
|
package/src/MySQLConnection.ts
CHANGED
|
@@ -34,9 +34,17 @@ const DEFAULT_HIGH_WATERMARK: number = 512; // in number of result objects
|
|
|
34
34
|
const TAG: string = 'MySQLConnection';
|
|
35
35
|
|
|
36
36
|
const SQL_FORMATTING_OPTIONS: SQLFormatter.FormatOptions = {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
tabWidth: 4,
|
|
38
|
+
keywordCase: 'upper',
|
|
39
|
+
useTabs: false,
|
|
40
|
+
indentStyle: 'standard',
|
|
41
|
+
logicalOperatorNewline: 'after',
|
|
42
|
+
commaPosition: 'before',
|
|
43
|
+
linesBetweenQueries: 1,
|
|
44
|
+
denseOperators: false,
|
|
45
|
+
newlineBeforeSemicolon: false,
|
|
46
|
+
tabulateAlias: true,
|
|
47
|
+
expressionWidth: 4
|
|
40
48
|
};
|
|
41
49
|
|
|
42
50
|
let startTransactionQuery: Query = new StartTransactionQuery();
|
|
@@ -90,7 +98,10 @@ export class MySQLConnection extends DatabaseConnection<MySQL.PoolConnection> {
|
|
|
90
98
|
// SQLFormatter doesn't understand all MySQL syntaxes, so this is to prevent
|
|
91
99
|
// potentially valid queries from becoming errors simply because we couldn't
|
|
92
100
|
// log them.
|
|
93
|
-
sql = SQLFormatter.
|
|
101
|
+
sql = SQLFormatter.formatDialect(queryObject.sql, {
|
|
102
|
+
...SQL_FORMATTING_OPTIONS,
|
|
103
|
+
dialect: SQLFormatter.mysql
|
|
104
|
+
});
|
|
94
105
|
}
|
|
95
106
|
catch (ex) {
|
|
96
107
|
logger.warn(TAG, 'Unable to format query...');
|
package/src/Query.ts
CHANGED
|
@@ -15,8 +15,9 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import { IDatabaseConnection } from './IDatabaseConnection';
|
|
18
|
+
import { IQueryable } from './IQueryable';
|
|
18
19
|
|
|
19
|
-
export abstract class Query<TQueryParameters = any, TQueryResultSet = any, TQueryPostProcessedResultSet = TQueryResultSet> {
|
|
20
|
+
export abstract class Query<TQueryParameters = any, TQueryResultSet = any, TQueryPostProcessedResultSet = TQueryResultSet> implements IQueryable<TQueryPostProcessedResultSet> {
|
|
20
21
|
private $params: TQueryParameters;
|
|
21
22
|
|
|
22
23
|
public constructor(parameters?: TQueryParameters) {
|
|
@@ -35,7 +36,7 @@ export abstract class Query<TQueryParameters = any, TQueryResultSet = any, TQuer
|
|
|
35
36
|
*
|
|
36
37
|
* @returns parameters that will be used when this query is ran.
|
|
37
38
|
*/
|
|
38
|
-
public getParametersForQuery(): Record<
|
|
39
|
+
public getParametersForQuery(): Record<string, any> {
|
|
39
40
|
return this.$params;
|
|
40
41
|
}
|
|
41
42
|
|
package/src/ServiceResponse.ts
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import {IncomingMessage} from 'http';
|
|
18
|
+
import { StatusCode } from './StatusCode';
|
|
18
19
|
|
|
19
20
|
export class ServiceResponse {
|
|
20
21
|
private $data: Buffer;
|
|
@@ -36,4 +37,8 @@ export class ServiceResponse {
|
|
|
36
37
|
public getJSON(): any {
|
|
37
38
|
return JSON.parse(this.getUTF8());
|
|
38
39
|
}
|
|
40
|
+
|
|
41
|
+
public getStatusCode(): StatusCode {
|
|
42
|
+
return this.$response.statusCode;
|
|
43
|
+
}
|
|
39
44
|
}
|
|
@@ -12,12 +12,12 @@ export class SetSessionVariableQuery extends Query<ISetSessionVariableQueryInput
|
|
|
12
12
|
protected _getQuery(): string {
|
|
13
13
|
let params: ISetSessionVariableQueryInput = this.getParameters();
|
|
14
14
|
|
|
15
|
-
if (
|
|
15
|
+
if (!/^([A-Za-z_])+([a-zA-Z0-9_])+$/g.test(params.name)) {
|
|
16
16
|
throw new Error('Illegal Variable Name');
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
// Only allow alpha letters & underscores for variable names
|
|
20
|
-
return `SET SESSION
|
|
20
|
+
return `SET SESSION \`${params.name}\` = :value`;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
public getParametersForQuery(): Record<any, any> {
|