@breautek/storm 8.0.0 → 8.1.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 +10 -1
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/Application.html +66 -64
- 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 +21 -19
- 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 +6 -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 +4 -2
- 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 +28 -20
- 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 +6 -6
- package/docs/classes/RawError.html +5 -5
- package/docs/classes/RawQuery.html +6 -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 +6 -6
- package/docs/classes/StormError.html +5 -5
- package/docs/classes/TemporaryTableQuery.html +6 -6
- package/docs/classes/TimeoutError.html +24 -0
- package/docs/classes/Token.html +2 -2
- package/docs/classes/TokenManager.html +2 -2
- package/docs/classes/Transaction.html +2 -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/index.html +2 -0
- 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 +4 -2
- package/docs/interfaces/IDatabasePosition.html +4 -0
- 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 +2 -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/lib/Database.d.ts +3 -2
- package/lib/Database.js +2 -2
- package/lib/Database.js.map +1 -1
- package/lib/DatabaseConnection.d.ts +5 -0
- package/lib/DatabaseConnection.js.map +1 -1
- package/lib/IDatabaseConnection.d.ts +5 -0
- package/lib/IDatabasePosition.d.ts +7 -0
- package/lib/IDatabasePosition.js +18 -0
- package/lib/IDatabasePosition.js.map +1 -0
- package/lib/ManagedDatabaseConnection.d.ts +2 -0
- package/lib/ManagedDatabaseConnection.js +4 -0
- package/lib/ManagedDatabaseConnection.js.map +1 -1
- package/lib/MySQLConnection.d.ts +9 -0
- package/lib/MySQLConnection.js +20 -0
- package/lib/MySQLConnection.js.map +1 -1
- package/lib/MySQLDatabase.d.ts +3 -1
- package/lib/MySQLDatabase.js +26 -3
- package/lib/MySQLDatabase.js.map +1 -1
- package/lib/TimeoutError.d.ts +13 -0
- package/lib/TimeoutError.js +43 -0
- package/lib/TimeoutError.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/lib/private/ConnectionReplicationWaiter.d.ts +24 -0
- package/lib/private/ConnectionReplicationWaiter.js +92 -0
- package/lib/private/ConnectionReplicationWaiter.js.map +1 -0
- package/lib/private/GetBinLogPositionQuery.d.ts +12 -0
- package/lib/private/GetBinLogPositionQuery.js +49 -0
- package/lib/private/GetBinLogPositionQuery.js.map +1 -0
- package/lib/private/GetMasterPositionQuery.d.ts +11 -0
- package/lib/private/GetMasterPositionQuery.js +32 -0
- package/lib/private/GetMasterPositionQuery.js.map +1 -0
- package/lib/private/GetSlavePositionQuery.d.ts +11 -0
- package/lib/private/GetSlavePositionQuery.js +32 -0
- package/lib/private/GetSlavePositionQuery.js.map +1 -0
- package/package.json +10 -10
- package/src/Database.ts +4 -3
- package/src/DatabaseConnection.ts +6 -0
- package/src/IDatabaseConnection.ts +6 -0
- package/src/IDatabasePosition.ts +23 -0
- package/src/ManagedDatabaseConnection.ts +6 -0
- package/src/MySQLConnection.ts +27 -0
- package/src/MySQLDatabase.ts +32 -4
- package/src/TimeoutError.ts +44 -0
- package/src/api.ts +2 -0
- package/src/private/ConnectionReplicationWaiter.ts +110 -0
- package/src/private/GetBinLogPositionQuery.ts +59 -0
- package/src/private/GetMasterPositionQuery.ts +37 -0
- package/src/private/GetSlavePositionQuery.ts +37 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
|
|
2
|
+
/*
|
|
3
|
+
Copyright 2017-2024 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
|
+
|
|
18
|
+
import { IDatabaseConnection } from '../IDatabaseConnection';
|
|
19
|
+
import { IDatabasePosition } from '../IDatabasePosition';
|
|
20
|
+
import { InternalError } from '../InternalError';
|
|
21
|
+
import { TimeoutError } from '../TimeoutError';
|
|
22
|
+
|
|
23
|
+
export class ConnectionReplicationWaiter {
|
|
24
|
+
/**
|
|
25
|
+
* The default retry delay in milliseconds.
|
|
26
|
+
* Defaults to 1 second.
|
|
27
|
+
*
|
|
28
|
+
* This is the value used in between status query iterations.
|
|
29
|
+
*/
|
|
30
|
+
public static readonly DEFAULT_RETRY_DELAY: number = 1000;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The default timeout delay. Defaults to 120 seconds.
|
|
34
|
+
* If the connection could not reach the target position in time,
|
|
35
|
+
* then the wait will timeout
|
|
36
|
+
*
|
|
37
|
+
* Using `Infinity` will disable the timeout
|
|
38
|
+
*/
|
|
39
|
+
public static readonly DEFAULT_TIMEOUT = 120 * 1000; // 120 seconds in ms
|
|
40
|
+
|
|
41
|
+
private $conn: IDatabaseConnection;
|
|
42
|
+
private $retryDelay: number;
|
|
43
|
+
|
|
44
|
+
public constructor(conn: IDatabaseConnection, retryDelay: number = ConnectionReplicationWaiter.DEFAULT_RETRY_DELAY) {
|
|
45
|
+
this.$conn = conn;
|
|
46
|
+
this.$retryDelay = retryDelay;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
private $sleep(timeout: number): Promise<void> {
|
|
50
|
+
return new Promise((resolve, reject) => {
|
|
51
|
+
setTimeout(() => {
|
|
52
|
+
resolve();
|
|
53
|
+
}, timeout);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public async wait(target: IDatabasePosition, timeout: number = ConnectionReplicationWaiter.DEFAULT_TIMEOUT): Promise<void> {
|
|
58
|
+
if (!this.$conn.isReadOnly()) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
let shouldTimeout: boolean = false;
|
|
63
|
+
let didTimeout: boolean = false;
|
|
64
|
+
|
|
65
|
+
let timeoutTimer = setTimeout(() => {
|
|
66
|
+
shouldTimeout = true;
|
|
67
|
+
}, timeout);
|
|
68
|
+
|
|
69
|
+
// eslint-disable-next-line no-constant-condition
|
|
70
|
+
while (true) {
|
|
71
|
+
if (shouldTimeout) {
|
|
72
|
+
didTimeout = true;
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
let currentPos: IDatabasePosition = await this.$conn.getCurrentDatabasePosition();
|
|
77
|
+
|
|
78
|
+
if (currentPos === null || (currentPos && !currentPos.page === null) || (currentPos && !currentPos.position === null)) {
|
|
79
|
+
throw new InternalError('Database Position not supported');
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// If the current page is greater than the target page,
|
|
83
|
+
// then the position doesn't matter, we are ahead of the
|
|
84
|
+
// desired target position.
|
|
85
|
+
if (currentPos.page > target.page) {
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// If the pages are equal, we need to check the position
|
|
90
|
+
// and ensure we are at or greater than the target.
|
|
91
|
+
if (currentPos.page === target.page && currentPos.position >= target.position) {
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// If we made it here, it means the position state checks failed
|
|
96
|
+
// so wait a short while and then re-iterate
|
|
97
|
+
await this.$sleep(this.$retryDelay);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (didTimeout) {
|
|
101
|
+
// If the while loop exited due to the timeout,
|
|
102
|
+
// then throw a timeout error
|
|
103
|
+
throw new TimeoutError();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Otherwise we are good to go!
|
|
107
|
+
clearTimeout(timeoutTimer);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2017-2024 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 {Query} from '../Query';
|
|
18
|
+
import {IDatabasePosition} from '../IDatabasePosition';
|
|
19
|
+
import { IDatabaseConnection } from '../IDatabaseConnection';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @since 8.1.0
|
|
23
|
+
*/
|
|
24
|
+
export abstract class GetBinLogPositionQuery<TStatusRow = unknown> extends Query<void, TStatusRow[], IDatabasePosition> {
|
|
25
|
+
protected abstract _getQuery(): string;
|
|
26
|
+
|
|
27
|
+
protected abstract _getFile(row: TStatusRow): string;
|
|
28
|
+
protected abstract _getPosition(row: TStatusRow): string;
|
|
29
|
+
|
|
30
|
+
public async onPostProcess(connection: IDatabaseConnection, resultSet: TStatusRow[]): Promise<IDatabasePosition> {
|
|
31
|
+
let row: TStatusRow = null;
|
|
32
|
+
if (resultSet.length > 0) {
|
|
33
|
+
row = resultSet[0];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (!row) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
let pageParts: string[] = this._getFile(row).split('.');
|
|
41
|
+
let strPage: string = pageParts[pageParts.length - 1];
|
|
42
|
+
|
|
43
|
+
let page: number = parseInt(strPage);
|
|
44
|
+
|
|
45
|
+
if (isNaN(page)) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
let position: number = parseInt(this._getPosition(row));
|
|
50
|
+
if (isNaN(position)) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
page: page,
|
|
56
|
+
position: position
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2017-2024 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 { GetBinLogPositionQuery } from './GetBinLogPositionQuery';
|
|
18
|
+
|
|
19
|
+
interface IStatus {
|
|
20
|
+
File: string;
|
|
21
|
+
Position: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export class GetMasterPositionQuery extends GetBinLogPositionQuery<IStatus> {
|
|
25
|
+
|
|
26
|
+
protected override _getQuery(): string {
|
|
27
|
+
return 'SHOW MASTER STATUS';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
protected override _getFile(row: IStatus): string {
|
|
31
|
+
return row.File;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
protected override _getPosition(row: IStatus): string {
|
|
35
|
+
return row.Position;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2017-2024 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 { GetBinLogPositionQuery } from './GetBinLogPositionQuery';
|
|
18
|
+
|
|
19
|
+
interface IStatus {
|
|
20
|
+
Master_Log_File: string;
|
|
21
|
+
Read_Master_Log_Pos: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export class GetSlavePositionQuery extends GetBinLogPositionQuery<IStatus> {
|
|
25
|
+
|
|
26
|
+
protected override _getQuery(): string {
|
|
27
|
+
return 'SHOW SLAVE STATUS';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
protected override _getFile(row: IStatus): string {
|
|
31
|
+
return row.Master_Log_File;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
protected override _getPosition(row: IStatus): string {
|
|
35
|
+
return row.Read_Master_Log_Pos;
|
|
36
|
+
}
|
|
37
|
+
}
|