@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.
Files changed (134) hide show
  1. package/CHANGELOG.md +10 -1
  2. package/docs/assets/navigation.js +1 -1
  3. package/docs/assets/search.js +1 -1
  4. package/docs/classes/Application.html +66 -64
  5. package/docs/classes/BackendAuthenticationMiddleware.html +3 -3
  6. package/docs/classes/CORSMiddleware.html +3 -3
  7. package/docs/classes/ConfigLoader.html +3 -3
  8. package/docs/classes/Database.html +2 -2
  9. package/docs/classes/DatabaseCastObject.html +2 -2
  10. package/docs/classes/DatabaseConnection.html +21 -19
  11. package/docs/classes/DatabaseQueryError.html +5 -5
  12. package/docs/classes/DeadLockError.html +5 -5
  13. package/docs/classes/DiskSpaceError.html +5 -5
  14. package/docs/classes/DropTemporaryTableQuery.html +6 -6
  15. package/docs/classes/DuplicateEntryError.html +5 -5
  16. package/docs/classes/EntityNotFoundError.html +5 -5
  17. package/docs/classes/ExpiredTokenError.html +5 -5
  18. package/docs/classes/Handler.html +2 -2
  19. package/docs/classes/InternalError.html +5 -5
  20. package/docs/classes/InvalidCredentialsError.html +5 -5
  21. package/docs/classes/InvalidValueError.html +5 -5
  22. package/docs/classes/LineString.html +2 -2
  23. package/docs/classes/LockWaitTimeoutError.html +5 -5
  24. package/docs/classes/ManagedDatabaseConnection.html +4 -2
  25. package/docs/classes/Middleware.html +2 -2
  26. package/docs/classes/MissingConfigError.html +5 -5
  27. package/docs/classes/MissingParameterError.html +5 -5
  28. package/docs/classes/MySQLConnection.html +28 -20
  29. package/docs/classes/MySQLDatabase.html +2 -2
  30. package/docs/classes/NotImplementedError.html +5 -5
  31. package/docs/classes/Point.html +2 -2
  32. package/docs/classes/Polygon.html +2 -2
  33. package/docs/classes/Query.html +6 -6
  34. package/docs/classes/RawError.html +5 -5
  35. package/docs/classes/RawQuery.html +6 -6
  36. package/docs/classes/Request.html +2 -2
  37. package/docs/classes/Response.html +2 -2
  38. package/docs/classes/ResponseData.html +2 -2
  39. package/docs/classes/ServiceProvider.html +2 -2
  40. package/docs/classes/ServiceResponse.html +2 -2
  41. package/docs/classes/SetSessionVariableQuery.html +6 -6
  42. package/docs/classes/StormError.html +5 -5
  43. package/docs/classes/TemporaryTableQuery.html +6 -6
  44. package/docs/classes/TimeoutError.html +24 -0
  45. package/docs/classes/Token.html +2 -2
  46. package/docs/classes/TokenManager.html +2 -2
  47. package/docs/classes/Transaction.html +2 -2
  48. package/docs/classes/UnauthorizedAccessError.html +5 -5
  49. package/docs/enums/ErrorCode.html +2 -2
  50. package/docs/enums/ExitCode.html +2 -2
  51. package/docs/enums/HTTPMethod.html +2 -2
  52. package/docs/enums/IsolationLevel.html +2 -2
  53. package/docs/enums/JWTError.html +2 -2
  54. package/docs/enums/StatusCode.html +2 -2
  55. package/docs/functions/getInstance.html +1 -1
  56. package/docs/hierarchy.html +1 -1
  57. package/docs/index.html +2 -0
  58. package/docs/interfaces/IAdditionalErrorDetails.html +1 -1
  59. package/docs/interfaces/ICloudwatchConfig.html +2 -2
  60. package/docs/interfaces/ICloudwatchCredentials.html +2 -2
  61. package/docs/interfaces/ICloudwatchStreamConfig.html +2 -2
  62. package/docs/interfaces/IConfig.html +2 -2
  63. package/docs/interfaces/IDatabaseConfig.html +2 -2
  64. package/docs/interfaces/IDatabaseConnection.html +4 -2
  65. package/docs/interfaces/IDatabasePosition.html +4 -0
  66. package/docs/interfaces/IErrorResponse.html +2 -2
  67. package/docs/interfaces/IFormData.html +2 -2
  68. package/docs/interfaces/IHandler.html +2 -2
  69. package/docs/interfaces/IInsertQueryResult.html +2 -2
  70. package/docs/interfaces/IJWTVerifyOptions.html +2 -2
  71. package/docs/interfaces/IOKPacket.html +2 -2
  72. package/docs/interfaces/IParameterMap.html +1 -1
  73. package/docs/interfaces/IQueryable.html +2 -2
  74. package/docs/interfaces/IRequestResponse.html +2 -2
  75. package/docs/interfaces/IServiceHeaders.html +1 -1
  76. package/docs/interfaces/ISetSessionVariableQueryInput.html +2 -2
  77. package/docs/interfaces/IStormCLIArgs.html +2 -2
  78. package/docs/interfaces/ITemporaryTableQueryInput.html +2 -2
  79. package/docs/interfaces/IUpdateQueryResult.html +2 -2
  80. package/docs/types/IDeleteQueryResult.html +1 -1
  81. package/docs/types/IHandlerError.html +1 -1
  82. package/docs/types/IHandlerResponse.html +1 -1
  83. package/docs/types/IStoredProcedureResult.html +1 -1
  84. package/docs/types/TCoordinate.html +1 -1
  85. package/lib/Database.d.ts +3 -2
  86. package/lib/Database.js +2 -2
  87. package/lib/Database.js.map +1 -1
  88. package/lib/DatabaseConnection.d.ts +5 -0
  89. package/lib/DatabaseConnection.js.map +1 -1
  90. package/lib/IDatabaseConnection.d.ts +5 -0
  91. package/lib/IDatabasePosition.d.ts +7 -0
  92. package/lib/IDatabasePosition.js +18 -0
  93. package/lib/IDatabasePosition.js.map +1 -0
  94. package/lib/ManagedDatabaseConnection.d.ts +2 -0
  95. package/lib/ManagedDatabaseConnection.js +4 -0
  96. package/lib/ManagedDatabaseConnection.js.map +1 -1
  97. package/lib/MySQLConnection.d.ts +9 -0
  98. package/lib/MySQLConnection.js +20 -0
  99. package/lib/MySQLConnection.js.map +1 -1
  100. package/lib/MySQLDatabase.d.ts +3 -1
  101. package/lib/MySQLDatabase.js +26 -3
  102. package/lib/MySQLDatabase.js.map +1 -1
  103. package/lib/TimeoutError.d.ts +13 -0
  104. package/lib/TimeoutError.js +43 -0
  105. package/lib/TimeoutError.js.map +1 -0
  106. package/lib/api.d.ts +2 -0
  107. package/lib/api.js +4 -2
  108. package/lib/api.js.map +1 -1
  109. package/lib/private/ConnectionReplicationWaiter.d.ts +24 -0
  110. package/lib/private/ConnectionReplicationWaiter.js +92 -0
  111. package/lib/private/ConnectionReplicationWaiter.js.map +1 -0
  112. package/lib/private/GetBinLogPositionQuery.d.ts +12 -0
  113. package/lib/private/GetBinLogPositionQuery.js +49 -0
  114. package/lib/private/GetBinLogPositionQuery.js.map +1 -0
  115. package/lib/private/GetMasterPositionQuery.d.ts +11 -0
  116. package/lib/private/GetMasterPositionQuery.js +32 -0
  117. package/lib/private/GetMasterPositionQuery.js.map +1 -0
  118. package/lib/private/GetSlavePositionQuery.d.ts +11 -0
  119. package/lib/private/GetSlavePositionQuery.js +32 -0
  120. package/lib/private/GetSlavePositionQuery.js.map +1 -0
  121. package/package.json +10 -10
  122. package/src/Database.ts +4 -3
  123. package/src/DatabaseConnection.ts +6 -0
  124. package/src/IDatabaseConnection.ts +6 -0
  125. package/src/IDatabasePosition.ts +23 -0
  126. package/src/ManagedDatabaseConnection.ts +6 -0
  127. package/src/MySQLConnection.ts +27 -0
  128. package/src/MySQLDatabase.ts +32 -4
  129. package/src/TimeoutError.ts +44 -0
  130. package/src/api.ts +2 -0
  131. package/src/private/ConnectionReplicationWaiter.ts +110 -0
  132. package/src/private/GetBinLogPositionQuery.ts +59 -0
  133. package/src/private/GetMasterPositionQuery.ts +37 -0
  134. 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
+ }