mysql-memory-server 1.7.0 → 1.8.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/README.md +21 -20
- package/dist/src/cli.js +2 -3
- package/dist/src/constants.js +13 -12
- package/dist/src/index.js +4 -4
- package/dist/src/libraries/Executor.d.ts +5 -3
- package/dist/src/libraries/Executor.js +19 -12
- 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
|
@@ -78,7 +78,7 @@ If using Jest, information about how to do this can be found here: https://jestj
|
|
|
78
78
|
```sh
|
|
79
79
|
# Options are added by doing --{optionName} {optionValue}
|
|
80
80
|
# See Options below for the options you can use with this package
|
|
81
|
-
npx mysql-memory-server --version 8.4.x
|
|
81
|
+
npx mysql-memory-server@latest --version 8.4.x
|
|
82
82
|
```
|
|
83
83
|
|
|
84
84
|
## Documentation
|
|
@@ -98,10 +98,13 @@ 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
|
+
##### For options that are not required, using ```undefined``` as a value will use the option's default value.
|
|
105
108
|
- `version: string`
|
|
106
109
|
|
|
107
110
|
Required: No
|
|
@@ -132,7 +135,7 @@ Required: No
|
|
|
132
135
|
|
|
133
136
|
Default: "ERROR"
|
|
134
137
|
|
|
135
|
-
Description: Log level for
|
|
138
|
+
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
139
|
|
|
137
140
|
- `portRetries: number`
|
|
138
141
|
|
|
@@ -140,7 +143,7 @@ Required: No
|
|
|
140
143
|
|
|
141
144
|
Default: 10
|
|
142
145
|
|
|
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.
|
|
146
|
+
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
147
|
|
|
145
148
|
- `downloadBinaryOnce: boolean`
|
|
146
149
|
|
|
@@ -158,7 +161,7 @@ Required: No
|
|
|
158
161
|
|
|
159
162
|
Default: 1,000
|
|
160
163
|
|
|
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.
|
|
164
|
+
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
165
|
|
|
163
166
|
- `lockRetryWait: number`
|
|
164
167
|
|
|
@@ -166,7 +169,7 @@ Required: No
|
|
|
166
169
|
|
|
167
170
|
Default: 1,000
|
|
168
171
|
|
|
169
|
-
Description: If `downloadBinaryOnce` is set to `true
|
|
172
|
+
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
173
|
|
|
171
174
|
- `username: string`
|
|
172
175
|
|
|
@@ -214,14 +217,22 @@ Required: No
|
|
|
214
217
|
|
|
215
218
|
Default: ""
|
|
216
219
|
|
|
217
|
-
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)
|
|
220
|
+
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
221
|
|
|
219
222
|
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
223
|
|
|
224
|
+
- `arch: "arm64" | "x64"`
|
|
225
|
+
|
|
226
|
+
Required: No
|
|
227
|
+
|
|
228
|
+
Default: process.arch
|
|
229
|
+
|
|
230
|
+
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.
|
|
231
|
+
|
|
221
232
|
***
|
|
222
233
|
### :warning: Internal Options :warning:
|
|
223
234
|
|
|
224
|
-
The following options are only meant for internal use (such as
|
|
235
|
+
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
236
|
|
|
226
237
|
- `_DO_NOT_USE_deleteDBAfterStopped: boolean`
|
|
227
238
|
|
|
@@ -241,18 +252,8 @@ Default: `TMPDIR/mysqlmsn/binaries` (replacing TMPDIR with the OS temp directory
|
|
|
241
252
|
|
|
242
253
|
Description: The folder to store the MySQL binaries when they are downloaded from the CDN.
|
|
243
254
|
|
|
244
|
-
- `
|
|
245
|
-
|
|
246
|
-
Required: No
|
|
247
|
-
|
|
248
|
-
Default: undefined
|
|
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`
|
|
255
|
+
- `_DO_NOT_USE_cli: boolean`
|
|
253
256
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
Default: undefined
|
|
257
|
+
Default: ```false``` if the package is not being executed via the CLI and ```true``` if it is.
|
|
257
258
|
|
|
258
|
-
Description:
|
|
259
|
+
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
|
|
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];
|
|
@@ -84,7 +84,7 @@ async function createDB(opts) {
|
|
|
84
84
|
let binaryInfo;
|
|
85
85
|
let binaryFilepath;
|
|
86
86
|
try {
|
|
87
|
-
binaryInfo = (0, Version_1.default)(versions_json_1.default, options.version);
|
|
87
|
+
binaryInfo = (0, Version_1.default)(versions_json_1.default, options.version, options);
|
|
88
88
|
logger.log('Using MySQL binary version:', binaryInfo.version, 'from URL:', binaryInfo.url);
|
|
89
89
|
}
|
|
90
90
|
catch (e) {
|
|
@@ -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;
|
|
@@ -48,6 +48,7 @@ const Port_1 = require("./Port");
|
|
|
48
48
|
const path_1 = require("path");
|
|
49
49
|
const FileLock_1 = require("./FileLock");
|
|
50
50
|
const signal_exit_1 = require("signal-exit");
|
|
51
|
+
const crypto_1 = require("crypto");
|
|
51
52
|
class Executor {
|
|
52
53
|
constructor(logger) {
|
|
53
54
|
_Executor_instances.add(this);
|
|
@@ -77,7 +78,7 @@ class Executor {
|
|
|
77
78
|
return reject('Could not get MySQL version');
|
|
78
79
|
}
|
|
79
80
|
else {
|
|
80
|
-
versions.push({ version: version.version, path });
|
|
81
|
+
versions.push({ version: version.version, path, installedOnSystem: true });
|
|
81
82
|
}
|
|
82
83
|
}
|
|
83
84
|
if (preferredVersion) {
|
|
@@ -107,16 +108,18 @@ class Executor {
|
|
|
107
108
|
reject('Could not get installed MySQL version');
|
|
108
109
|
}
|
|
109
110
|
else {
|
|
110
|
-
resolve({ version: version.version, path: 'mysqld' });
|
|
111
|
+
resolve({ version: version.version, path: 'mysqld', installedOnSystem: true });
|
|
111
112
|
}
|
|
112
113
|
}
|
|
113
114
|
}
|
|
114
115
|
});
|
|
115
116
|
}
|
|
116
|
-
async startMySQL(options,
|
|
117
|
+
async startMySQL(options, installedMySQLBinary) {
|
|
118
|
+
this.version = installedMySQLBinary.version;
|
|
119
|
+
this.versionInstalledOnSystem = installedMySQLBinary.installedOnSystem;
|
|
117
120
|
this.removeExitHandler = (0, signal_exit_1.onExit)(() => {
|
|
118
|
-
if (options.
|
|
119
|
-
console.log(
|
|
121
|
+
if (options._DO_NOT_USE_cli) {
|
|
122
|
+
console.log('\nShutting down the ephemeral MySQL database and cleaning all related files...');
|
|
120
123
|
}
|
|
121
124
|
this.DBDestroySignal.abort();
|
|
122
125
|
if (options._DO_NOT_USE_deleteDBAfterStopped) {
|
|
@@ -127,7 +130,7 @@ class Executor {
|
|
|
127
130
|
this.logger.error('An error occurred while deleting database directory path:', e);
|
|
128
131
|
}
|
|
129
132
|
}
|
|
130
|
-
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);
|
|
131
134
|
if (binaryPathToDelete) {
|
|
132
135
|
try {
|
|
133
136
|
fs.rmSync(binaryPathToDelete, { force: true, recursive: true, maxRetries: 50 });
|
|
@@ -136,21 +139,21 @@ class Executor {
|
|
|
136
139
|
this.logger.error('An error occurred while deleting database binary:', e);
|
|
137
140
|
}
|
|
138
141
|
}
|
|
139
|
-
if (options.
|
|
140
|
-
console.log(
|
|
142
|
+
if (options._DO_NOT_USE_cli) {
|
|
143
|
+
console.log('Shutdown and cleanup is complete.');
|
|
141
144
|
}
|
|
142
145
|
});
|
|
143
146
|
let retries = 0;
|
|
144
147
|
const datadir = (0, path_1.normalize)(`${options._DO_NOT_USE_dbPath}/data`);
|
|
145
148
|
do {
|
|
146
|
-
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);
|
|
147
150
|
this.logger.log('Setting up directories was successful');
|
|
148
151
|
const port = options.port || (0, Port_1.GenerateRandomPort)();
|
|
149
152
|
const mySQLXPort = options.xPort || (0, Port_1.GenerateRandomPort)();
|
|
150
153
|
this.logger.log('Using port:', port, 'and MySQLX port:', mySQLXPort, 'on retry:', retries);
|
|
151
154
|
try {
|
|
152
155
|
this.logger.log('Starting MySQL process');
|
|
153
|
-
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);
|
|
154
157
|
this.logger.log('Starting process was successful');
|
|
155
158
|
return resolved;
|
|
156
159
|
}
|
|
@@ -229,8 +232,8 @@ _Executor_instances = new WeakSet(), _Executor_executeFile = function _Executor_
|
|
|
229
232
|
const errorLogFile = `${datadir}/errorlog.err`;
|
|
230
233
|
return new Promise(async (resolve, reject) => {
|
|
231
234
|
await fsPromises.rm(logFile, { force: true });
|
|
232
|
-
const socket = os.platform() === 'win32' ? `MySQL-${
|
|
233
|
-
const xSocket = os.platform() === 'win32' ? `MySQLX-${
|
|
235
|
+
const socket = os.platform() === 'win32' ? `MySQL-${(0, crypto_1.randomUUID)()}` : `${dbPath}/m.sock`;
|
|
236
|
+
const xSocket = os.platform() === 'win32' ? `MySQLX-${(0, crypto_1.randomUUID)()}` : `${dbPath}/x.sock`;
|
|
234
237
|
const process = (0, child_process_1.spawn)(binaryFilepath, ['--no-defaults', `--port=${port}`, `--datadir=${datadir}`, `--mysqlx-port=${mySQLXPort}`, `--mysqlx-socket=${xSocket}`, `--socket=${socket}`, `--general-log-file=${logFile}`, '--general-log=1', `--init-file=${dbPath}/init.sql`, '--bind-address=127.0.0.1', '--innodb-doublewrite=OFF', '--mysqlx=FORCE', `--log-error=${errorLogFile}`, `--user=${os.userInfo().username}`], { signal: this.DBDestroySignal.signal, killSignal: 'SIGKILL' });
|
|
235
238
|
//resolveFunction is the function that will be called to resolve the promise that stops the database.
|
|
236
239
|
//If resolveFunction is not undefined, the database has received a kill signal and data cleanup procedures should run.
|
|
@@ -326,6 +329,10 @@ _Executor_instances = new WeakSet(), _Executor_executeFile = function _Executor_
|
|
|
326
329
|
xSocket,
|
|
327
330
|
dbName: options.dbName,
|
|
328
331
|
username: options.username,
|
|
332
|
+
mysql: {
|
|
333
|
+
version: this.version,
|
|
334
|
+
versionIsInstalledOnSystem: this.versionInstalledOnSystem
|
|
335
|
+
},
|
|
329
336
|
stop: () => {
|
|
330
337
|
return new Promise(async (resolve, reject) => {
|
|
331
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;
|