mysql-memory-server 1.7.1 → 1.8.1
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/README.md +17 -44
- package/dist/src/cli.js +2 -3
- package/dist/src/constants.js +13 -12
- package/dist/src/index.js +9 -9
- package/dist/src/libraries/Executor.d.ts +5 -3
- package/dist/src/libraries/Executor.js +16 -10
- package/dist/src/libraries/Version.d.ts +2 -2
- package/dist/src/libraries/Version.js +3 -3
- package/dist/types/index.d.ts +10 -5
- package/package.json +1 -1
- package/dist/src/libraries/AbortSignal.d.ts +0 -2
- package/dist/src/libraries/AbortSignal.js +0 -11
package/README.md
CHANGED
|
@@ -98,14 +98,15 @@ The name of the user to use to login to the database
|
|
|
98
98
|
If on Windows, this is the name of the named pipe that MySQL is listening on. If not on Windows, this is the path to the socket that MySQL is listening on.
|
|
99
99
|
- `xSocket: string`
|
|
100
100
|
If on Windows, this is the name of the named pipe that the MySQL X Plugin is listening on. If not on Windows, this is the path that the MySQL X Plugin is listening on.
|
|
101
|
+
- `mysql: {version: string, versionIsInstalledOnSystem: boolean}`
|
|
102
|
+
An object with two properties. ```version``` is the version of MySQL used to create the database. ```versionIsInstalledOnSystem``` will be true if the MySQL version used is already installed on the system and false if the version had to be downloaded from MySQL's CDN.
|
|
101
103
|
- `stop: () => Promise<void>`
|
|
102
104
|
The method to stop the database. The returned promise resolves when the database has successfully stopped.
|
|
103
105
|
|
|
104
106
|
#### Options:
|
|
107
|
+
##### All options are not required to be set. Using ```undefined``` as a value will use the option's default value.
|
|
105
108
|
- `version: string`
|
|
106
109
|
|
|
107
|
-
Required: No
|
|
108
|
-
|
|
109
110
|
Default: undefined
|
|
110
111
|
|
|
111
112
|
Description: Version of MySQL to use for the database. Uses semver for getting the version, so valid semver versions are allowed. For example, `8.x` is a valid version and will use the latest 8.x MySQL version.
|
|
@@ -120,32 +121,24 @@ If defined:
|
|
|
120
121
|
|
|
121
122
|
- `dbName: string`
|
|
122
123
|
|
|
123
|
-
Required: No
|
|
124
|
-
|
|
125
124
|
Default: "dbdata"
|
|
126
125
|
|
|
127
126
|
Description: The name of the database to create when initializing MySQL. You'd use this name to connect to the database.
|
|
128
127
|
|
|
129
128
|
- `logLevel: "LOG" | "WARN" | "ERROR"`
|
|
130
129
|
|
|
131
|
-
Required: No
|
|
132
|
-
|
|
133
130
|
Default: "ERROR"
|
|
134
131
|
|
|
135
|
-
Description: Log level for
|
|
132
|
+
Description: Log level for this package. If "ERROR" is used, only errors from this package will show up in the console. If "WARN" is used, warnings and errors from this package will show up in the console. If "LOG" is used, every log from this package will show up in the console.
|
|
136
133
|
|
|
137
134
|
- `portRetries: number`
|
|
138
135
|
|
|
139
|
-
Required: No
|
|
140
|
-
|
|
141
136
|
Default: 10
|
|
142
137
|
|
|
143
|
-
Description: Number of times to try connecting MySQL to a randomly generated port before giving up. According to the [MySQL Documentation](https://dev.mysql.com/doc/refman/en/server-options.html#option_mysqld_port "MySQL Documentation") if port 0 is used as the MySQL server port, the default value (3306) will be used. To get around this, a random number between 1025 - 65535 (inclusive) is generated and used for the database's port. If MySQL cannot successfully listen on a randomly generated port after `portRetries` then the `createDB()` promise is rejected. A warning is created when MySQL tries connecting to a port that is already in use.
|
|
138
|
+
Description: Number of times to try connecting MySQL to a randomly generated port before giving up. According to the [MySQL Documentation](https://dev.mysql.com/doc/refman/en/server-options.html#option_mysqld_port "MySQL Documentation") if port 0 is used as the MySQL server port, the default value (3306) will be used. To get around this, a random number between 1025 - 65535 (inclusive) is generated and used for the database's port. If MySQL cannot successfully listen on a randomly generated port after `portRetries` then the `createDB()` promise is rejected. A warning is created when MySQL tries connecting to a port that is already in use. This option only applies for the MySQL port if the MySQL port is not explicitly set or if it's set to 0. This option also only applies for the MySQL X port if the MySQL X port is not explicitly set or if it's set to 0.
|
|
144
139
|
|
|
145
140
|
- `downloadBinaryOnce: boolean`
|
|
146
141
|
|
|
147
|
-
Required: No
|
|
148
|
-
|
|
149
142
|
Default: true
|
|
150
143
|
|
|
151
144
|
Description: If set to true, all versions requested that need to be downloaded from MySQL's CDN will be downloaded once and will stay on the system after the database stops. If set to false, the binaries that need to be downloaded will be downloaded for each database creation and will be deleted when the database is stopped.
|
|
@@ -154,74 +147,64 @@ Use `false` to save disk space after the databases have been stopped, or use `tr
|
|
|
154
147
|
|
|
155
148
|
- `lockRetries: number`
|
|
156
149
|
|
|
157
|
-
Required: No
|
|
158
|
-
|
|
159
150
|
Default: 1,000
|
|
160
151
|
|
|
161
|
-
Description: If `downloadBinaryOnce` is set to `true`, `lockRetries` is the number of times to check to see if the lock for the binary has been released (meaning it has been successfully downloaded and extracted). If the number of retries exceeds `lockRetries`, the `createDB()` promise gets rejected.
|
|
152
|
+
Description: If `downloadBinaryOnce` is set to `true`, `lockRetries` is the number of times to check to see if the lock for the binary has been released (meaning it has been successfully downloaded and extracted). If the number of retries exceeds `lockRetries`, the `createDB()` promise gets rejected. This option is also used for the number of times to check to see if the lock for libaio has been released (only on Linux distros that use libaio1t64 instead of libaio1)
|
|
162
153
|
|
|
163
154
|
- `lockRetryWait: number`
|
|
164
155
|
|
|
165
|
-
Required: No
|
|
166
|
-
|
|
167
156
|
Default: 1,000
|
|
168
157
|
|
|
169
|
-
Description: If `downloadBinaryOnce` is set to `true
|
|
158
|
+
Description: If `downloadBinaryOnce` is set to `true` and/or on Linux distros that use libaio1t64 instead of libaio1, `lockRetryWait` is the number of milliseconds to wait before checking if the lock has been released.
|
|
170
159
|
|
|
171
160
|
- `username: string`
|
|
172
161
|
|
|
173
|
-
Required: No
|
|
174
|
-
|
|
175
162
|
Default: root
|
|
176
163
|
|
|
177
164
|
Description: The username of the user that is used to login to the database.
|
|
178
165
|
|
|
179
166
|
- `port: number`
|
|
180
167
|
|
|
181
|
-
Required: No
|
|
182
|
-
|
|
183
168
|
Default: 0
|
|
184
169
|
|
|
185
170
|
Description: The port that the database will listen on. If set to 0, a randomly generated port is used.
|
|
186
171
|
|
|
187
172
|
- `xPort: number`
|
|
188
173
|
|
|
189
|
-
Required: No
|
|
190
|
-
|
|
191
174
|
Default: 0
|
|
192
175
|
|
|
193
176
|
Description: The port that the MySQL X Plugin will listen on. If set to 0, a randomly generated port is used.
|
|
194
177
|
|
|
195
178
|
- `ignoreUnsupportedSystemVersion: boolean`
|
|
196
179
|
|
|
197
|
-
Required: No
|
|
198
|
-
|
|
199
180
|
Default: false
|
|
200
181
|
|
|
201
182
|
Description: This option only applies if the system-installed MySQL version is lower than the oldest supported MySQL version for this package (8.0.20) and the `version` option is not defined. If set to `true`, this package will use the latest version of MySQL instead of the system-installed version. If `false`, the package will throw an error.
|
|
202
183
|
|
|
203
184
|
- `downloadRetries: number`
|
|
204
185
|
|
|
205
|
-
Required: No
|
|
206
|
-
|
|
207
186
|
Default: 3
|
|
208
187
|
|
|
209
188
|
Description: The number of times to try to download a MySQL binary before giving up and rejecting the `createDB()` promise.
|
|
210
189
|
|
|
211
190
|
- `initSQLString: string`
|
|
212
191
|
|
|
213
|
-
Required: No
|
|
214
|
-
|
|
215
192
|
Default: ""
|
|
216
193
|
|
|
217
194
|
Description: A string with MySQL queries to run before the database starts to accept connections. This option can be used for things like initialising tables without having to first connect to the database to do that. The queries in the string get executed after ```mysql-memory-server```'s queries run. Uses the ```--init-file``` MySQL server option under the hood. Learn more at the [--init-file MySQL Documentation](https://dev.mysql.com/doc/refman/8.4/en/server-system-variables.html#sysvar_init_file)
|
|
218
195
|
|
|
219
196
|
The internal queries that are ran before the queries in ```initSQLString``` are renaming the user from ```root``` to the username specified in the ```username``` option if it's set, and creating a database with the name from the ```dbName``` option.
|
|
220
197
|
|
|
198
|
+
- `arch: "arm64" | "x64"`
|
|
199
|
+
|
|
200
|
+
Default: process.arch
|
|
201
|
+
|
|
202
|
+
Description: The MySQL binary architecture to execute. MySQL does not offer server builds for Windows on ARM, so to get this package working on Windows on ARM, set the arch option to "x64" and Windows will emulate MySQL.
|
|
203
|
+
|
|
221
204
|
***
|
|
222
205
|
### :warning: Internal Options :warning:
|
|
223
206
|
|
|
224
|
-
The following options are only meant for internal use (such as
|
|
207
|
+
The following options are only meant for internal use (such as for testing this package or the internals for running this package via the CLI). Their behaviour may change or they may get removed between major/minor/patch versions and they are not to be considered stable. The options below will not follow Semantic Versioning so it is advised to not use them.
|
|
225
208
|
|
|
226
209
|
- `_DO_NOT_USE_deleteDBAfterStopped: boolean`
|
|
227
210
|
|
|
@@ -241,18 +224,8 @@ Default: `TMPDIR/mysqlmsn/binaries` (replacing TMPDIR with the OS temp directory
|
|
|
241
224
|
|
|
242
225
|
Description: The folder to store the MySQL binaries when they are downloaded from the CDN.
|
|
243
226
|
|
|
244
|
-
- `
|
|
245
|
-
|
|
246
|
-
Required: No
|
|
227
|
+
- `_DO_NOT_USE_cli: boolean`
|
|
247
228
|
|
|
248
|
-
Default:
|
|
249
|
-
|
|
250
|
-
Description: The message to get displayed in the console before the cleanup that happens when the Node.js process is stopped without the ```stop()``` method being called first.
|
|
251
|
-
|
|
252
|
-
- `_DO_NOT_USE_afterSignalCleanupMessage: string`
|
|
253
|
-
|
|
254
|
-
Required: No
|
|
255
|
-
|
|
256
|
-
Default: undefined
|
|
229
|
+
Default: ```false``` if the package is not being executed via the CLI and ```true``` if it is.
|
|
257
230
|
|
|
258
|
-
Description:
|
|
231
|
+
Description: If set to ```true```, this enables certain CLI-only functionality. For example, when ran by the CLI, logging a message to the console when a shutdown signal (like CTRL + C) has been received and the MySQL database is shutting down and getting deleted.
|
package/dist/src/cli.js
CHANGED
|
@@ -6,8 +6,7 @@ const constants_1 = require("./constants");
|
|
|
6
6
|
async function main() {
|
|
7
7
|
const definedOptions = process.argv.filter((option) => option.startsWith('--'));
|
|
8
8
|
const options = {
|
|
9
|
-
|
|
10
|
-
_DO_NOT_USE_afterSignalCleanupMessage: 'Shutdown and cleanup is complete.'
|
|
9
|
+
_DO_NOT_USE_cli: true
|
|
11
10
|
};
|
|
12
11
|
for (const opt of definedOptions) {
|
|
13
12
|
const index = process.argv.indexOf(opt);
|
|
@@ -41,7 +40,7 @@ async function main() {
|
|
|
41
40
|
}
|
|
42
41
|
console.log('Creating ephemeral MySQL database...');
|
|
43
42
|
const db = await (0, index_1.createDB)(options);
|
|
44
|
-
console.log(`A MySQL database has been successfully created with the following parameters:\n\nUsername: ${db.username} \nDatabase Name: ${db.dbName} \nPort: ${db.port} \nX Plugin Port: ${db.xPort} \nSocket: ${db.socket} \nX Plugin Socket: ${db.xSocket}\n`);
|
|
43
|
+
console.log(`A MySQL database has been successfully created with the following parameters:\n\nMySQL Version: ${db.mysql.version} (${db.mysql.versionIsInstalledOnSystem ? 'installed on this system' : 'not installed on this system - downloaded from the MySQL CDN'}) \nUsername: ${db.username} \nDatabase Name: ${db.dbName} \nPort: ${db.port} \nX Plugin Port: ${db.xPort} \nSocket: ${db.socket} \nX Plugin Socket: ${db.xSocket}\n`);
|
|
45
44
|
if (process.platform === 'win32') {
|
|
46
45
|
//The connection information logs will be different for Windows compared to other platforms.
|
|
47
46
|
//Windows uses mysqlsh instead of mysql to invoke the client shell, needs a --sql flag to be put into SQL mode, and also does not have a protocol flag.
|
package/dist/src/constants.js
CHANGED
|
@@ -20,12 +20,12 @@ const DEFAULT_OPTIONS_GENERATOR = () => ({
|
|
|
20
20
|
xPort: 0,
|
|
21
21
|
downloadRetries: 10,
|
|
22
22
|
initSQLString: '',
|
|
23
|
+
arch: process.arch,
|
|
23
24
|
_DO_NOT_USE_deleteDBAfterStopped: true,
|
|
24
25
|
//mysqlmsn = MySQL Memory Server Node.js
|
|
25
26
|
_DO_NOT_USE_dbPath: (0, path_1.normalize)(`${(0, os_1.tmpdir)()}/mysqlmsn/dbs/${(0, crypto_1.randomUUID)().replace(/-/g, '')}`),
|
|
26
27
|
_DO_NOT_USE_binaryDirectoryPath: `${(0, os_1.tmpdir)()}/mysqlmsn/binaries`,
|
|
27
|
-
|
|
28
|
-
_DO_NOT_USE_afterSignalCleanupMessage: ''
|
|
28
|
+
_DO_NOT_USE_cli: false
|
|
29
29
|
});
|
|
30
30
|
exports.DEFAULT_OPTIONS_GENERATOR = DEFAULT_OPTIONS_GENERATOR;
|
|
31
31
|
exports.DEFAULT_OPTIONS_KEYS = Object.freeze(Object.keys((0, exports.DEFAULT_OPTIONS_GENERATOR)()));
|
|
@@ -35,9 +35,10 @@ exports.LOG_LEVELS = {
|
|
|
35
35
|
'ERROR': 2
|
|
36
36
|
};
|
|
37
37
|
exports.INTERNAL_OPTIONS = ['_DO_NOT_USE_deleteDBAfterStopped', '_DO_NOT_USE_dbPath', '_DO_NOT_USE_binaryDirectoryPath', '_DO_NOT_USE_beforeSignalCleanup', '_DO_NOT_USE_afterSignalCleanup'];
|
|
38
|
+
const allowedArches = ['x64', 'arm64', undefined];
|
|
38
39
|
exports.OPTION_TYPE_CHECKS = {
|
|
39
40
|
version: {
|
|
40
|
-
check: (opt) => opt === undefined || typeof opt === 'string' && (0, semver_1.valid)(opt) !== null,
|
|
41
|
+
check: (opt) => opt === undefined || typeof opt === 'string' && (0, semver_1.valid)((0, semver_1.coerce)(opt)) !== null,
|
|
41
42
|
errorMessage: 'Option version must be either undefined or a valid semver string.',
|
|
42
43
|
definedType: 'string'
|
|
43
44
|
},
|
|
@@ -101,6 +102,11 @@ exports.OPTION_TYPE_CHECKS = {
|
|
|
101
102
|
errorMessage: 'Option initSQLString must be either undefined or a string.',
|
|
102
103
|
definedType: 'string'
|
|
103
104
|
},
|
|
105
|
+
arch: {
|
|
106
|
+
check: (opt) => allowedArches.includes(opt),
|
|
107
|
+
errorMessage: `Option arch must be either of the following: ${allowedArches.join(', ')}`,
|
|
108
|
+
definedType: 'string'
|
|
109
|
+
},
|
|
104
110
|
_DO_NOT_USE_deleteDBAfterStopped: {
|
|
105
111
|
check: (opt) => opt === undefined || typeof opt === 'boolean',
|
|
106
112
|
errorMessage: 'Option _DO_NOT_USE_deleteDBAfterStopped must be either undefined or a boolean.',
|
|
@@ -116,14 +122,9 @@ exports.OPTION_TYPE_CHECKS = {
|
|
|
116
122
|
errorMessage: 'Option _DO_NOT_USE_binaryDirectoryPath must be either undefined or a string.',
|
|
117
123
|
definedType: 'string'
|
|
118
124
|
},
|
|
119
|
-
|
|
120
|
-
check: (opt) => opt === undefined || typeof opt === '
|
|
121
|
-
errorMessage: 'Option
|
|
122
|
-
definedType: '
|
|
123
|
-
},
|
|
124
|
-
_DO_NOT_USE_afterSignalCleanupMessage: {
|
|
125
|
-
check: (opt) => opt === undefined || typeof opt === 'string',
|
|
126
|
-
errorMessage: 'Option _DO_NOT_USE_afterSignalCleanup must be either undefined or a string.',
|
|
127
|
-
definedType: 'string'
|
|
125
|
+
_DO_NOT_USE_cli: {
|
|
126
|
+
check: (opt) => opt === undefined || typeof opt === 'boolean',
|
|
127
|
+
errorMessage: 'Option _DO_NOT_USE_cli must be either undefined or a boolean.',
|
|
128
|
+
definedType: 'boolean'
|
|
128
129
|
}
|
|
129
130
|
};
|
package/dist/src/index.js
CHANGED
|
@@ -60,7 +60,7 @@ async function createDB(opts) {
|
|
|
60
60
|
}
|
|
61
61
|
if (!constants_1.OPTION_TYPE_CHECKS[opt].check(suppliedOpts[opt])) {
|
|
62
62
|
//Supplied option failed the check
|
|
63
|
-
throw constants_1.OPTION_TYPE_CHECKS[opt].errorMessage
|
|
63
|
+
throw `${constants_1.OPTION_TYPE_CHECKS[opt].errorMessage} | Received value: ${suppliedOpts[opt]} (type: ${typeof suppliedOpts[opt]})`;
|
|
64
64
|
}
|
|
65
65
|
if (suppliedOpts[opt] !== undefined) {
|
|
66
66
|
options[opt] = suppliedOpts[opt];
|
|
@@ -74,20 +74,20 @@ async function createDB(opts) {
|
|
|
74
74
|
if (throwUnsupportedError) {
|
|
75
75
|
throw `A version of MySQL is installed on your system that is not supported by this package. If you want to download a MySQL binary instead of getting this error, please set the option "ignoreUnsupportedSystemVersion" to true.`;
|
|
76
76
|
}
|
|
77
|
-
if (options.version && (0, semver_1.lt)(options.version, constants_1.MIN_SUPPORTED_MYSQL)) {
|
|
78
|
-
//The difference between the throw here and the throw above is this throw is because the selected "version" is not supported.
|
|
79
|
-
//The throw above is because the system-installed MySQL is out of date and "ignoreUnsupportedSystemVersion" is not set to true.
|
|
80
|
-
throw `The selected version of MySQL (${options.version}) is not currently supported by this package. Please choose a different version to use.`;
|
|
81
|
-
}
|
|
82
77
|
logger.log('Version currently installed:', version);
|
|
83
78
|
if (version === null || (options.version && !(0, semver_1.satisfies)(version.version, options.version)) || unsupportedMySQLIsInstalled) {
|
|
84
79
|
let binaryInfo;
|
|
85
80
|
let binaryFilepath;
|
|
86
81
|
try {
|
|
87
|
-
binaryInfo = (0, Version_1.default)(versions_json_1.default, options.version);
|
|
82
|
+
binaryInfo = (0, Version_1.default)(versions_json_1.default, options.version, options);
|
|
88
83
|
logger.log('Using MySQL binary version:', binaryInfo.version, 'from URL:', binaryInfo.url);
|
|
89
84
|
}
|
|
90
85
|
catch (e) {
|
|
86
|
+
if (options.version && (0, semver_1.lt)((0, semver_1.coerce)(options.version), constants_1.MIN_SUPPORTED_MYSQL)) {
|
|
87
|
+
//The difference between the throw here and the throw above is this throw is because the selected "version" is not supported.
|
|
88
|
+
//The throw above is because the system-installed MySQL is out of date and "ignoreUnsupportedSystemVersion" is not set to true.
|
|
89
|
+
throw `The selected version of MySQL (${options.version}) is not currently supported by this package. Please choose a different version to use.`;
|
|
90
|
+
}
|
|
91
91
|
logger.error(e);
|
|
92
92
|
if (options.version) {
|
|
93
93
|
throw `A MySQL version ${options.version} binary could not be found that supports your OS (${os.platform()} | ${os.version()} | ${os.release()}) and CPU architecture (${os.arch()}). Please check you have the latest version of mysql-memory-server. If the latest version still doesn't support the version you want to use, feel free to make a pull request to add support!`;
|
|
@@ -102,10 +102,10 @@ async function createDB(opts) {
|
|
|
102
102
|
throw `Failed to download binary. The error was: "${error}"`;
|
|
103
103
|
}
|
|
104
104
|
logger.log('Running downloaded binary');
|
|
105
|
-
return await executor.startMySQL(options, binaryFilepath);
|
|
105
|
+
return await executor.startMySQL(options, { path: binaryFilepath, version: binaryInfo.version, installedOnSystem: false });
|
|
106
106
|
}
|
|
107
107
|
else {
|
|
108
108
|
logger.log(version);
|
|
109
|
-
return await executor.startMySQL(options, version
|
|
109
|
+
return await executor.startMySQL(options, version);
|
|
110
110
|
}
|
|
111
111
|
}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import Logger from "./Logger";
|
|
2
|
-
import {
|
|
2
|
+
import { DownloadedMySQLVersion, InternalServerOptions, MySQLDB } from "../../types";
|
|
3
3
|
declare class Executor {
|
|
4
4
|
#private;
|
|
5
5
|
logger: Logger;
|
|
6
6
|
DBDestroySignal: AbortController;
|
|
7
7
|
removeExitHandler: () => void;
|
|
8
|
+
version: string;
|
|
9
|
+
versionInstalledOnSystem: boolean;
|
|
8
10
|
constructor(logger: Logger);
|
|
9
|
-
getMySQLVersion(preferredVersion?: string): Promise<
|
|
10
|
-
startMySQL(options: InternalServerOptions,
|
|
11
|
+
getMySQLVersion(preferredVersion?: string): Promise<DownloadedMySQLVersion | null>;
|
|
12
|
+
startMySQL(options: InternalServerOptions, installedMySQLBinary: DownloadedMySQLVersion): Promise<MySQLDB>;
|
|
11
13
|
}
|
|
12
14
|
export default Executor;
|
|
@@ -78,7 +78,7 @@ class Executor {
|
|
|
78
78
|
return reject('Could not get MySQL version');
|
|
79
79
|
}
|
|
80
80
|
else {
|
|
81
|
-
versions.push({ version: version.version, path });
|
|
81
|
+
versions.push({ version: version.version, path, installedOnSystem: true });
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
if (preferredVersion) {
|
|
@@ -108,16 +108,18 @@ class Executor {
|
|
|
108
108
|
reject('Could not get installed MySQL version');
|
|
109
109
|
}
|
|
110
110
|
else {
|
|
111
|
-
resolve({ version: version.version, path: 'mysqld' });
|
|
111
|
+
resolve({ version: version.version, path: 'mysqld', installedOnSystem: true });
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
});
|
|
116
116
|
}
|
|
117
|
-
async startMySQL(options,
|
|
117
|
+
async startMySQL(options, installedMySQLBinary) {
|
|
118
|
+
this.version = installedMySQLBinary.version;
|
|
119
|
+
this.versionInstalledOnSystem = installedMySQLBinary.installedOnSystem;
|
|
118
120
|
this.removeExitHandler = (0, signal_exit_1.onExit)(() => {
|
|
119
|
-
if (options.
|
|
120
|
-
console.log(
|
|
121
|
+
if (options._DO_NOT_USE_cli) {
|
|
122
|
+
console.log('\nShutting down the ephemeral MySQL database and cleaning all related files...');
|
|
121
123
|
}
|
|
122
124
|
this.DBDestroySignal.abort();
|
|
123
125
|
if (options._DO_NOT_USE_deleteDBAfterStopped) {
|
|
@@ -128,7 +130,7 @@ class Executor {
|
|
|
128
130
|
this.logger.error('An error occurred while deleting database directory path:', e);
|
|
129
131
|
}
|
|
130
132
|
}
|
|
131
|
-
const binaryPathToDelete = __classPrivateFieldGet(this, _Executor_instances, "m", _Executor_returnBinaryPathToDelete).call(this,
|
|
133
|
+
const binaryPathToDelete = __classPrivateFieldGet(this, _Executor_instances, "m", _Executor_returnBinaryPathToDelete).call(this, installedMySQLBinary.path, options);
|
|
132
134
|
if (binaryPathToDelete) {
|
|
133
135
|
try {
|
|
134
136
|
fs.rmSync(binaryPathToDelete, { force: true, recursive: true, maxRetries: 50 });
|
|
@@ -137,21 +139,21 @@ class Executor {
|
|
|
137
139
|
this.logger.error('An error occurred while deleting database binary:', e);
|
|
138
140
|
}
|
|
139
141
|
}
|
|
140
|
-
if (options.
|
|
141
|
-
console.log(
|
|
142
|
+
if (options._DO_NOT_USE_cli) {
|
|
143
|
+
console.log('Shutdown and cleanup is complete.');
|
|
142
144
|
}
|
|
143
145
|
});
|
|
144
146
|
let retries = 0;
|
|
145
147
|
const datadir = (0, path_1.normalize)(`${options._DO_NOT_USE_dbPath}/data`);
|
|
146
148
|
do {
|
|
147
|
-
await __classPrivateFieldGet(this, _Executor_instances, "m", _Executor_setupDataDirectories).call(this, options,
|
|
149
|
+
await __classPrivateFieldGet(this, _Executor_instances, "m", _Executor_setupDataDirectories).call(this, options, installedMySQLBinary.path, datadir, true);
|
|
148
150
|
this.logger.log('Setting up directories was successful');
|
|
149
151
|
const port = options.port || (0, Port_1.GenerateRandomPort)();
|
|
150
152
|
const mySQLXPort = options.xPort || (0, Port_1.GenerateRandomPort)();
|
|
151
153
|
this.logger.log('Using port:', port, 'and MySQLX port:', mySQLXPort, 'on retry:', retries);
|
|
152
154
|
try {
|
|
153
155
|
this.logger.log('Starting MySQL process');
|
|
154
|
-
const resolved = await __classPrivateFieldGet(this, _Executor_instances, "m", _Executor_startMySQLProcess).call(this, options, port, mySQLXPort, datadir, options._DO_NOT_USE_dbPath,
|
|
156
|
+
const resolved = await __classPrivateFieldGet(this, _Executor_instances, "m", _Executor_startMySQLProcess).call(this, options, port, mySQLXPort, datadir, options._DO_NOT_USE_dbPath, installedMySQLBinary.path);
|
|
155
157
|
this.logger.log('Starting process was successful');
|
|
156
158
|
return resolved;
|
|
157
159
|
}
|
|
@@ -327,6 +329,10 @@ _Executor_instances = new WeakSet(), _Executor_executeFile = function _Executor_
|
|
|
327
329
|
xSocket,
|
|
328
330
|
dbName: options.dbName,
|
|
329
331
|
username: options.username,
|
|
332
|
+
mysql: {
|
|
333
|
+
version: this.version,
|
|
334
|
+
versionIsInstalledOnSystem: this.versionInstalledOnSystem
|
|
335
|
+
},
|
|
330
336
|
stop: () => {
|
|
331
337
|
return new Promise(async (resolve, reject) => {
|
|
332
338
|
resolveFunction = resolve;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { MySQLVersion } from "../../types";
|
|
2
|
-
export default function getBinaryURL(versions: MySQLVersion[], versionToGet
|
|
1
|
+
import { InternalServerOptions, MySQLVersion } from "../../types";
|
|
2
|
+
export default function getBinaryURL(versions: MySQLVersion[], versionToGet: string, options: InternalServerOptions): {
|
|
3
3
|
url: string;
|
|
4
4
|
version: string;
|
|
5
5
|
};
|
|
@@ -36,11 +36,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.default = getBinaryURL;
|
|
37
37
|
const os = __importStar(require("os"));
|
|
38
38
|
const semver_1 = require("semver");
|
|
39
|
-
function getBinaryURL(versions, versionToGet = "
|
|
39
|
+
function getBinaryURL(versions, versionToGet = "x", options) {
|
|
40
40
|
let availableVersions = versions;
|
|
41
|
-
availableVersions = availableVersions.filter(v => v.arch ===
|
|
41
|
+
availableVersions = availableVersions.filter(v => v.arch === options.arch);
|
|
42
42
|
if (availableVersions.length === 0)
|
|
43
|
-
throw `No MySQL binary could be found for your CPU architecture: ${process.arch}`;
|
|
43
|
+
throw `No MySQL binary could be found for your CPU architecture: ${options.arch}. ${process.platform === 'win32' && process.arch === 'arm64' ? 'This package has detected you are running Windows on ARM. MySQL does not support Windows on ARM. To get this package working, please try setting the "arch" option to "x64".' : ''}`;
|
|
44
44
|
availableVersions = availableVersions.filter(v => v.os === process.platform);
|
|
45
45
|
if (availableVersions.length === 0)
|
|
46
46
|
throw `No MySQL binary could be found for your OS: ${process.platform}`;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -14,11 +14,11 @@ export type ServerOptions = {
|
|
|
14
14
|
xPort?: number | undefined;
|
|
15
15
|
downloadRetries?: number | undefined;
|
|
16
16
|
initSQLString?: string | undefined;
|
|
17
|
+
arch?: "arm64" | "x64" | undefined;
|
|
17
18
|
_DO_NOT_USE_deleteDBAfterStopped?: boolean | undefined;
|
|
18
19
|
_DO_NOT_USE_dbPath?: string | undefined;
|
|
19
20
|
_DO_NOT_USE_binaryDirectoryPath?: string | undefined;
|
|
20
|
-
|
|
21
|
-
_DO_NOT_USE_afterSignalCleanupMessage?: string | undefined;
|
|
21
|
+
_DO_NOT_USE_cli?: boolean | undefined;
|
|
22
22
|
};
|
|
23
23
|
export type InternalServerOptions = {
|
|
24
24
|
version?: string | undefined;
|
|
@@ -34,11 +34,11 @@ export type InternalServerOptions = {
|
|
|
34
34
|
xPort: number;
|
|
35
35
|
downloadRetries: number;
|
|
36
36
|
initSQLString: string;
|
|
37
|
+
arch: string;
|
|
37
38
|
_DO_NOT_USE_deleteDBAfterStopped: boolean;
|
|
38
39
|
_DO_NOT_USE_dbPath: string;
|
|
39
40
|
_DO_NOT_USE_binaryDirectoryPath: string;
|
|
40
|
-
|
|
41
|
-
_DO_NOT_USE_afterSignalCleanupMessage: string;
|
|
41
|
+
_DO_NOT_USE_cli: boolean;
|
|
42
42
|
};
|
|
43
43
|
export type ExecutorOptions = {
|
|
44
44
|
logLevel: LOG_LEVEL;
|
|
@@ -55,6 +55,10 @@ export type MySQLDB = {
|
|
|
55
55
|
xSocket: string;
|
|
56
56
|
dbName: string;
|
|
57
57
|
username: string;
|
|
58
|
+
mysql: {
|
|
59
|
+
version: string;
|
|
60
|
+
versionIsInstalledOnSystem: boolean;
|
|
61
|
+
};
|
|
58
62
|
stop: () => Promise<void>;
|
|
59
63
|
};
|
|
60
64
|
export type MySQLVersion = {
|
|
@@ -64,9 +68,10 @@ export type MySQLVersion = {
|
|
|
64
68
|
osKernelVersionsSupported: string;
|
|
65
69
|
url: string;
|
|
66
70
|
};
|
|
67
|
-
export type
|
|
71
|
+
export type DownloadedMySQLVersion = {
|
|
68
72
|
version: string;
|
|
69
73
|
path: string;
|
|
74
|
+
installedOnSystem: boolean;
|
|
70
75
|
};
|
|
71
76
|
export type BinaryInfo = {
|
|
72
77
|
url: string;
|
package/package.json
CHANGED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const DBDestroySignal = new AbortController();
|
|
4
|
-
function abortSignal() {
|
|
5
|
-
if (!DBDestroySignal.signal.aborted) {
|
|
6
|
-
DBDestroySignal.abort('Process is exiting');
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
process.on('beforeExit', abortSignal);
|
|
10
|
-
process.on('exit', abortSignal);
|
|
11
|
-
exports.default = DBDestroySignal;
|