@breautek/storm 9.2.0 → 9.2.2

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 (121) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/docs/assets/hierarchy.js +1 -1
  3. package/docs/assets/navigation.js +1 -1
  4. package/docs/assets/search.js +1 -1
  5. package/docs/classes/Application.html +17 -17
  6. package/docs/classes/ConfigLoader.html +3 -3
  7. package/docs/classes/Database.html +2 -2
  8. package/docs/classes/DatabaseCastObject.html +2 -2
  9. package/docs/classes/DatabaseConnection.html +21 -21
  10. package/docs/classes/DatabaseQueryError.html +6 -6
  11. package/docs/classes/DeadLockError.html +6 -6
  12. package/docs/classes/DiskSpaceError.html +5 -5
  13. package/docs/classes/DropTemporaryTableQuery.html +7 -7
  14. package/docs/classes/DuplicateEntryError.html +5 -5
  15. package/docs/classes/EntityNotFoundError.html +5 -5
  16. package/docs/classes/ExpiredTokenError.html +5 -5
  17. package/docs/classes/GetMySQLVersion.html +25 -0
  18. package/docs/classes/Handler.html +2 -2
  19. package/docs/classes/IllegalStateError.html +5 -5
  20. package/docs/classes/InternalError.html +5 -5
  21. package/docs/classes/InvalidCredentialsError.html +5 -5
  22. package/docs/classes/InvalidValueError.html +5 -5
  23. package/docs/classes/LineString.html +2 -2
  24. package/docs/classes/LockWaitTimeoutError.html +6 -6
  25. package/docs/classes/ManagedDatabaseConnection.html +5 -5
  26. package/docs/classes/Middleware.html +2 -2
  27. package/docs/classes/MissingConfigError.html +5 -5
  28. package/docs/classes/MissingParameterError.html +5 -5
  29. package/docs/classes/MySQLConnection.html +26 -25
  30. package/docs/classes/MySQLDatabase.html +2 -2
  31. package/docs/classes/NotImplementedError.html +5 -5
  32. package/docs/classes/Point.html +2 -2
  33. package/docs/classes/Polygon.html +2 -2
  34. package/docs/classes/Query.html +7 -7
  35. package/docs/classes/RawError.html +5 -5
  36. package/docs/classes/RawQuery.html +7 -7
  37. package/docs/classes/Request.html +3 -3
  38. package/docs/classes/Response.html +2 -2
  39. package/docs/classes/ResponseData.html +3 -3
  40. package/docs/classes/ServiceProvider.html +2 -2
  41. package/docs/classes/ServiceResponse.html +2 -2
  42. package/docs/classes/SetSessionVariableQuery.html +7 -7
  43. package/docs/classes/StormError.html +5 -5
  44. package/docs/classes/TemporaryTableQuery.html +7 -7
  45. package/docs/classes/TimeoutError.html +5 -5
  46. package/docs/classes/Token.html +2 -2
  47. package/docs/classes/TokenManager.html +2 -2
  48. package/docs/classes/Transaction.html +2 -2
  49. package/docs/classes/UnauthorizedAccessError.html +5 -5
  50. package/docs/enums/ErrorCode.html +2 -2
  51. package/docs/enums/ExitCode.html +2 -2
  52. package/docs/enums/HTTPMethod.html +2 -2
  53. package/docs/enums/IsolationLevel.html +2 -2
  54. package/docs/enums/JWTError.html +2 -2
  55. package/docs/enums/StatusCode.html +2 -2
  56. package/docs/enums/TransactionAccessLevel.html +2 -2
  57. package/docs/functions/getInstance.html +1 -1
  58. package/docs/hierarchy.html +1 -1
  59. package/docs/index.html +1 -1
  60. package/docs/interfaces/IAdditionalErrorDetails.html +1 -1
  61. package/docs/interfaces/ICloudwatchConfig.html +2 -2
  62. package/docs/interfaces/ICloudwatchCredentials.html +2 -2
  63. package/docs/interfaces/ICloudwatchStreamConfig.html +2 -2
  64. package/docs/interfaces/IConfig.html +15 -2
  65. package/docs/interfaces/IDatabaseConfig.html +2 -2
  66. package/docs/interfaces/IDatabaseConnection.html +5 -5
  67. package/docs/interfaces/IDatabasePosition.html +2 -2
  68. package/docs/interfaces/IErrorResponse.html +2 -2
  69. package/docs/interfaces/IFormData.html +2 -2
  70. package/docs/interfaces/IGetMySQLVersionResult.html +5 -0
  71. package/docs/interfaces/IGetMySQLVersionRow.html +2 -0
  72. package/docs/interfaces/IInsertQueryResult.html +2 -2
  73. package/docs/interfaces/IJWTVerifyOptions.html +2 -2
  74. package/docs/interfaces/IOKPacket.html +2 -2
  75. package/docs/interfaces/IParameterMap.html +1 -1
  76. package/docs/interfaces/IQueryable.html +2 -2
  77. package/docs/interfaces/IRequestResponse.html +2 -2
  78. package/docs/interfaces/ISetSessionVariableQueryInput.html +2 -2
  79. package/docs/interfaces/IStormCLIArgs.html +2 -2
  80. package/docs/interfaces/ITemporaryTableQueryInput.html +2 -2
  81. package/docs/interfaces/IUpdateQueryResult.html +2 -2
  82. package/docs/interfaces/formidable.FileJSON.html +1 -1
  83. package/docs/interfaces/formidable.Part.html +1 -1
  84. package/docs/types/IDeleteQueryResult.html +1 -1
  85. package/docs/types/IStoredProcedureResult.html +1 -1
  86. package/docs/types/TCoordinate.html +1 -1
  87. package/docs/types/TExpiresIn.html +1 -1
  88. package/docs/types/TSerializableResponse.html +1 -1
  89. package/docs/types/TSupportedResponsePrimitives.html +1 -1
  90. package/docs/types/TSupportedResponseTypes.html +1 -1
  91. package/jest.config.js +1 -0
  92. package/lib/ConfigLoader.js +1 -0
  93. package/lib/ConfigLoader.js.map +1 -1
  94. package/lib/GetMySQLVersion.d.ts +15 -0
  95. package/lib/GetMySQLVersion.js +28 -0
  96. package/lib/GetMySQLVersion.js.map +1 -0
  97. package/lib/IConfig.d.ts +16 -0
  98. package/lib/MySQLConnection.d.ts +3 -0
  99. package/lib/MySQLConnection.js +42 -12
  100. package/lib/MySQLConnection.js.map +1 -1
  101. package/lib/api.d.ts +1 -0
  102. package/lib/api.js +4 -2
  103. package/lib/api.js.map +1 -1
  104. package/lib/mysql/queryFormatter.d.ts +11 -0
  105. package/lib/mysql/queryFormatter.js +11 -0
  106. package/lib/mysql/queryFormatter.js.map +1 -1
  107. package/lib/private/GetMasterPositionQuery.d.ts +4 -0
  108. package/lib/private/GetMasterPositionQuery.js +4 -0
  109. package/lib/private/GetMasterPositionQuery.js.map +1 -1
  110. package/lib/private/GetPrimaryPositionQuery.d.ts +14 -0
  111. package/lib/private/GetPrimaryPositionQuery.js +35 -0
  112. package/lib/private/GetPrimaryPositionQuery.js.map +1 -0
  113. package/package.json +1 -1
  114. package/src/ConfigLoader.ts +1 -0
  115. package/src/GetMySQLVersion.ts +41 -0
  116. package/src/IConfig.ts +17 -0
  117. package/src/MySQLConnection.ts +55 -15
  118. package/src/api.ts +1 -0
  119. package/src/mysql/queryFormatter.ts +11 -0
  120. package/src/private/GetMasterPositionQuery.ts +4 -0
  121. package/src/private/GetPrimaryPositionQuery.ts +40 -0
@@ -37,6 +37,8 @@ import { GetMasterPositionQuery } from './private/GetMasterPositionQuery';
37
37
  import { IQueryable } from './IQueryable';
38
38
  import { TransactionAccessLevel } from './TransactionAccessLevel';
39
39
  import { GetProcessList, IGetProcessListOutput } from './private/GetProcessList';
40
+ import { GetMySQLVersion, IGetMySQLVersionResult } from './GetMySQLVersion';
41
+ import { GetPrimaryPositionQuery } from './private/GetPrimaryPositionQuery';
40
42
 
41
43
  const DEFAULT_HIGH_WATERMARK: number = 512; // in number of result objects
42
44
  const TAG: string = 'MySQLConnection';
@@ -64,29 +66,47 @@ export class MySQLConnection extends DatabaseConnection<MySQL.PoolConnection> {
64
66
  private $opened: boolean;
65
67
  private $hasReplicationEnabled: boolean;
66
68
  private $isMasterConnection: boolean;
69
+ private $version: IGetMySQLVersionResult;
67
70
 
68
71
  public constructor(connection: MySQL.PoolConnection, instantiationStack: string, isReadOnly: boolean = true) {
69
72
  connection.config.namedPlaceholders = true;
73
+
74
+ if (!getInstance().getConfig().enableMySQL2BreakingChanges) {
75
+ connection.config.typeCast = function (field: MySQL.TypeCastField, next: MySQL.TypeCastNext): any {
76
+ // TODO: Expose a setting to opt out of these backwards-compatibility type casting
77
+ // So we can have a chance of a rolling refactor.
78
+ if (
79
+ [
80
+ 'DECIMAL',
81
+ 'NEWDECIMAL',
82
+ 'DOUBLE'
83
+ ].indexOf(field.type) > -1
84
+ ) {
85
+ let parsed: number = parseFloat(field.string());
86
+ if (isNaN(parsed)) {
87
+ return null;
88
+ }
89
+ return parsed;
90
+ }
91
+ else if (
92
+ ([
93
+ 'JSON'
94
+ ]).indexOf(field.type) > -1
95
+ ) {
96
+ return field.string();
97
+ }
98
+ else {
99
+ return next();
100
+ }
101
+ };
102
+ }
103
+
70
104
  super(connection, isReadOnly, instantiationStack);
71
105
 
72
106
  this.$hasReplicationEnabled = false;
73
107
  this.$opened = true;
74
108
  this.$transaction = false;
75
109
  this.$isMasterConnection = null;
76
-
77
- // connection.config.queryFormat = queryFormatter.bind(this);
78
-
79
- // connection.config.queryFormat = function(query: string, values: any) {
80
- // if (!values) return query;
81
-
82
- // return query.replace(/:(\w+)/g, function(this: any, txt: string, key: string): string {
83
- // // eslint-disable-next-line no-prototype-builtins
84
- // if (values.hasOwnProperty(key)) {
85
- // return this.escape(values[key]);
86
- // }
87
- // return txt;
88
- // }.bind(this));
89
- // };
90
110
  }
91
111
 
92
112
  /**
@@ -113,6 +133,14 @@ export class MySQLConnection extends DatabaseConnection<MySQL.PoolConnection> {
113
133
  }
114
134
  }
115
135
 
136
+ public async getVersion(): Promise<IGetMySQLVersionResult> {
137
+ if (!this.$version) {
138
+ this.$version = await new GetMySQLVersion().execute(this);
139
+ }
140
+
141
+ return {...this.$version};
142
+ }
143
+
116
144
  public override formatQuery(query: IQueryable<any>): string {
117
145
  return this.getAPI().format(query.getQuery(this), query.getParametersForQuery());
118
146
  }
@@ -148,7 +176,19 @@ export class MySQLConnection extends DatabaseConnection<MySQL.PoolConnection> {
148
176
  }
149
177
 
150
178
  public override async getCurrentDatabasePosition(): Promise<IDatabasePosition> {
151
- let statusQuery: GetBinLogPositionQuery = this.isReplication() ? new GetSlavePositionQuery() : new GetMasterPositionQuery();
179
+ let version: IGetMySQLVersionResult = await this.getVersion();
180
+ let statusQuery: GetBinLogPositionQuery = null;
181
+
182
+ if (
183
+ (version.major === 8 && version.minor >= 4) || version.major >= 9
184
+ ) {
185
+ // >= 8.4 we need to use a different setof master/slave queries
186
+ statusQuery = this.isReplication() ? new GetSlavePositionQuery() : new GetPrimaryPositionQuery();
187
+ }
188
+ else {
189
+ statusQuery = this.isReplication() ? new GetSlavePositionQuery() : new GetMasterPositionQuery();
190
+ }
191
+
152
192
  return await statusQuery.execute(this);
153
193
  }
154
194
 
package/src/api.ts CHANGED
@@ -43,6 +43,7 @@ export {Transaction} from './Transaction';
43
43
  export {IOKPacket} from './IOKPacket';
44
44
  export {IStoredProcedureResult} from './IStoredProcedureResult';
45
45
  export {TransactionAccessLevel} from './TransactionAccessLevel';
46
+ export {GetMySQLVersion, IGetMySQLVersionResult, IGetMySQLVersionRow} from './GetMySQLVersion';
46
47
 
47
48
  // Errors
48
49
  export {ErrorCode} from './ErrorCode';
@@ -1,6 +1,17 @@
1
1
 
2
2
  import * as MySQL from 'mysql2';
3
3
 
4
+ /**
5
+ * Formats a query by resolving named parameters.
6
+ *
7
+ * With older `mysql` driver, this was used to facilitate actual named parameters.
8
+ * @since 9.2.0 - this is now only used for logging/debugging purposes, as `mysql2`
9
+ * driver has built-in named parameter support.
10
+ *
11
+ * @param query
12
+ * @param values
13
+ * @returns
14
+ */
4
15
  export function queryFormatter(query: string, values: any): string {
5
16
  if (!values) return query;
6
17
 
@@ -21,6 +21,10 @@ interface IStatus {
21
21
  Position: string;
22
22
  }
23
23
 
24
+ /**
25
+ * For use with MySQL 8.0 and earlier. Obsolete since MySQL 8.4
26
+ * @deprecated
27
+ */
24
28
  export class GetMasterPositionQuery extends GetBinLogPositionQuery<IStatus> {
25
29
 
26
30
  protected override _getQuery(): string {
@@ -0,0 +1,40 @@
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
+ /**
25
+ * For use with MySQL 8.4 and later
26
+ */
27
+ export class GetPrimaryPositionQuery extends GetBinLogPositionQuery<IStatus> {
28
+
29
+ protected override _getQuery(): string {
30
+ return 'SHOW BINARY LOG STATUS';
31
+ }
32
+
33
+ protected override _getFile(row: IStatus): string {
34
+ return row.File;
35
+ }
36
+
37
+ protected override _getPosition(row: IStatus): string {
38
+ return row.Position;
39
+ }
40
+ }