mysql-memory-server 1.8.1 → 1.9.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 +9 -49
- package/dist/src/cli.js +22 -17
- package/dist/src/constants.d.ts +80 -3
- package/dist/src/constants.js +100 -38
- package/dist/src/index.js +2 -57
- package/dist/src/libraries/Downloader.d.ts +0 -1
- package/dist/src/libraries/Downloader.js +132 -84
- package/dist/src/libraries/Executor.d.ts +2 -0
- package/dist/src/libraries/Executor.js +108 -88
- package/dist/src/libraries/FileLock.js +2 -2
- package/dist/src/libraries/LinuxOSRelease.d.ts +3 -0
- package/dist/src/libraries/LinuxOSRelease.js +18 -0
- package/dist/src/libraries/Version.d.ts +2 -5
- package/dist/src/libraries/Version.js +87 -22
- package/dist/types/index.d.ts +14 -18
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# MySQL Memory Server
|
|
2
2
|
|
|
3
|
-
This package allows you to create ephemeral MySQL databases from JavaScript and/or TypeScript code and also the CLI, great for testing, CI, and learning MySQL. When creating a new database, if the version selected is not installed on the system, the binary is downloaded from MySQL's CDN (cdn.mysql.com)
|
|
3
|
+
This package allows you to create ephemeral MySQL databases from JavaScript and/or TypeScript code and also the CLI, great for testing, CI, and learning MySQL. When creating a new database, if the version selected is not installed on the system, the binary is downloaded from MySQL's CDN (cdn.mysql.com). This package supports Linux, macOS, and Windows.
|
|
4
4
|
|
|
5
5
|
You can run multiple MySQL databases with this package at the same time. Each database will use a random free port. The databases will automatically shutdown when the JS runtime process exits. A `stop()` method is also provided to stop each database instance.
|
|
6
6
|
|
|
@@ -11,24 +11,13 @@ Download with your package manager of choice. The package name is `mysql-memory-
|
|
|
11
11
|
#### Requirements
|
|
12
12
|
|
|
13
13
|
- Node.js >=16.6.0 or Bun >= 1.0.0
|
|
14
|
-
- macOS 13+, Windows, or Linux (This package is only tested on Ubuntu 20.04, 22.04, 24.04, and Fedora 40. Other Linux distributions may or may not work at this time.)
|
|
15
|
-
|
|
16
|
-
#### Requirements for downloaded MySQL versions
|
|
17
|
-
|
|
18
|
-
The following requirements only apply if you intend to have `mysql-memory-server` download a version of MySQL to use instead of using an already installed version of MySQL on the system:
|
|
19
|
-
|
|
20
|
-
Requirements for Windows:
|
|
21
|
-
- `Microsoft Visual C++ 2019 Redistributable Package` needs to be installed
|
|
22
|
-
|
|
23
|
-
Requirements for Linux:
|
|
24
|
-
- The `libaio1` or `libaio1t64` package needs to be installed
|
|
25
|
-
- If `libaio1` is not available but `libaio1t64` is, the `ldconfig` command needs to be available to run
|
|
26
|
-
- The `tar` package needs to be installed
|
|
27
14
|
|
|
28
15
|
#### Currently supported MySQL versions
|
|
29
16
|
|
|
30
|
-
-
|
|
31
|
-
-
|
|
17
|
+
- ```mysql-memory-server``` can run MySQL versions 5.7.19 and newer (if the version is already installed on your system)
|
|
18
|
+
- ```mysql-memory-server``` can download and run MySQL versions 5.7.19 - 9.2.0 (if the version is not already installed on your system)
|
|
19
|
+
|
|
20
|
+
Extra system requirements apply when ```mysql-memory-server``` is downloading MySQL instead of running a version of MySQL that is already installed on the system. To see the requirements and learn more about the supported versions for download, [read the doc](https://github.com/Sebastian-Webster/mysql-memory-server-nodejs/blob/v1.9.0/docs/SUPPORTED_MYSQL_DOWNLOADS.md)
|
|
32
21
|
|
|
33
22
|
## Example Usage - Application Code
|
|
34
23
|
|
|
@@ -112,11 +101,11 @@ Default: undefined
|
|
|
112
101
|
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.
|
|
113
102
|
|
|
114
103
|
If left undefined:
|
|
115
|
-
- If the system has MySQL installed, the system-installed version will be used. If the installed version is not supported by this package (currently <
|
|
104
|
+
- If the system has MySQL installed, the system-installed version will be used. If the installed version is not supported by this package (currently <5.7.19), an error will be thrown unless `ignoreUnsupportedSystemVersion` is set to `true`.
|
|
116
105
|
- If the system does not have MySQL installed, the latest version of MySQL in the `versions.json` file in this package will be downloaded.
|
|
117
106
|
|
|
118
107
|
If defined:
|
|
119
|
-
- If the version is
|
|
108
|
+
- If the version is older than 5.7.19, an error will be thrown as this package does not currently support those versions of MySQL.
|
|
120
109
|
- If the desired version of MySQL is installed on the system, the installed version will be used. Otherwise the selected version will be downloaded from the MySQL CDN as long as it can be found in the `versions.json` file. If it cannot be found in that file, an error will be thrown.
|
|
121
110
|
|
|
122
111
|
- `dbName: string`
|
|
@@ -179,11 +168,11 @@ Description: The port that the MySQL X Plugin will listen on. If set to 0, a ran
|
|
|
179
168
|
|
|
180
169
|
Default: false
|
|
181
170
|
|
|
182
|
-
Description: This option only applies if the system-installed MySQL version is lower than the oldest supported MySQL version for this package (
|
|
171
|
+
Description: This option only applies if the system-installed MySQL version is lower than the oldest supported MySQL version for this package (5.7.19) 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.
|
|
183
172
|
|
|
184
173
|
- `downloadRetries: number`
|
|
185
174
|
|
|
186
|
-
Default:
|
|
175
|
+
Default: 10
|
|
187
176
|
|
|
188
177
|
Description: The number of times to try to download a MySQL binary before giving up and rejecting the `createDB()` promise.
|
|
189
178
|
|
|
@@ -200,32 +189,3 @@ The internal queries that are ran before the queries in ```initSQLString``` are
|
|
|
200
189
|
Default: process.arch
|
|
201
190
|
|
|
202
191
|
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
|
-
|
|
204
|
-
***
|
|
205
|
-
### :warning: Internal Options :warning:
|
|
206
|
-
|
|
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.
|
|
208
|
-
|
|
209
|
-
- `_DO_NOT_USE_deleteDBAfterStopped: boolean`
|
|
210
|
-
|
|
211
|
-
Default: true
|
|
212
|
-
|
|
213
|
-
Description: Changes whether or not the database will be deleted after it has been stopped. If set to `true`, the database WILL be deleted after it has been stopped.
|
|
214
|
-
|
|
215
|
-
- `_DO_NOT_USE_dbPath: string`
|
|
216
|
-
|
|
217
|
-
Default: `TMPDIR/mysqlmsn/dbs/UUID` (replacing TMPDIR with the OS temp directory and UUID with a UUIDv4 without seperating dashes).
|
|
218
|
-
|
|
219
|
-
Description: The folder to store database-related data in
|
|
220
|
-
|
|
221
|
-
- `_DO_NOT_USE_binaryDirectoryPath: string`
|
|
222
|
-
|
|
223
|
-
Default: `TMPDIR/mysqlmsn/binaries` (replacing TMPDIR with the OS temp directory)
|
|
224
|
-
|
|
225
|
-
Description: The folder to store the MySQL binaries when they are downloaded from the CDN.
|
|
226
|
-
|
|
227
|
-
- `_DO_NOT_USE_cli: boolean`
|
|
228
|
-
|
|
229
|
-
Default: ```false``` if the package is not being executed via the CLI and ```true``` if it is.
|
|
230
|
-
|
|
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
|
@@ -3,16 +3,20 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
const index_1 = require("./index");
|
|
5
5
|
const constants_1 = require("./constants");
|
|
6
|
-
|
|
6
|
+
function main() {
|
|
7
7
|
const definedOptions = process.argv.filter((option) => option.startsWith('--'));
|
|
8
|
-
const options = {
|
|
9
|
-
|
|
10
|
-
};
|
|
8
|
+
const options = {};
|
|
9
|
+
process.env.mysqlmsn_internal_DO_NOT_USE_cli = 'true';
|
|
11
10
|
for (const opt of definedOptions) {
|
|
11
|
+
if (!constants_1.DEFAULT_OPTIONS_KEYS.includes(opt.replace('--', ''))) {
|
|
12
|
+
console.error(`Option ${opt} is not a valid option.`);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
12
15
|
const index = process.argv.indexOf(opt);
|
|
13
16
|
const optionValue = process.argv[index + 1];
|
|
14
17
|
if (optionValue === undefined) {
|
|
15
|
-
|
|
18
|
+
console.error(`Option ${opt} must have a value.`);
|
|
19
|
+
return;
|
|
16
20
|
}
|
|
17
21
|
const optionName = opt.slice(2);
|
|
18
22
|
const optionType = constants_1.OPTION_TYPE_CHECKS[optionName].definedType;
|
|
@@ -39,17 +43,18 @@ async function main() {
|
|
|
39
43
|
}
|
|
40
44
|
}
|
|
41
45
|
console.log('Creating ephemeral MySQL database...');
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
46
|
+
(0, index_1.createDB)(options).then(db => {
|
|
47
|
+
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`);
|
|
48
|
+
if (process.platform === 'win32') {
|
|
49
|
+
//The connection information logs will be different for Windows compared to other platforms.
|
|
50
|
+
//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.
|
|
51
|
+
//Also according to https://bugs.mysql.com/bug.php?id=106852, you cannot log into a MySQL database with a named pipe for the first connection so a socket connection suggestion
|
|
52
|
+
//should only be displayed for non-Windows platforms.
|
|
53
|
+
console.log(`If you want to use the MySQL CLI client to connect to the database, you can use the following command: \nmysqlsh --sql -u ${db.username} -P ${db.port}\nIf prompted for a password, leave the password field blank. The database does not have a password set.`);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
console.log(`If you want to use the MySQL CLI client to connect to the database, you can use either commands: \nmysql -u ${db.username} -P ${db.port} --protocol tcp \nOR\nmysql -u ${db.username} --socket ${db.socket}\nIf prompted for a password, leave the password field blank. The database does not have a password set.`);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
54
59
|
}
|
|
55
60
|
main();
|
package/dist/src/constants.d.ts
CHANGED
|
@@ -1,11 +1,88 @@
|
|
|
1
1
|
import { InternalServerOptions, OptionTypeChecks } from "../types";
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const DEFAULT_OPTIONS_GENERATOR: () => InternalServerOptions;
|
|
2
|
+
export declare const DEFAULT_OPTIONS: InternalServerOptions;
|
|
4
3
|
export declare const DEFAULT_OPTIONS_KEYS: readonly string[];
|
|
5
4
|
export declare const LOG_LEVELS: {
|
|
6
5
|
readonly LOG: 0;
|
|
7
6
|
readonly WARN: 1;
|
|
8
7
|
readonly ERROR: 2;
|
|
9
8
|
};
|
|
10
|
-
|
|
9
|
+
declare const internalOptions: {
|
|
10
|
+
deleteDBAfterStopped: string;
|
|
11
|
+
databaseDirectoryPath: string;
|
|
12
|
+
binaryDirectoryPath: string;
|
|
13
|
+
cli: string;
|
|
14
|
+
};
|
|
15
|
+
export declare function getInternalEnvVariable(envVar: keyof typeof internalOptions): string;
|
|
11
16
|
export declare const OPTION_TYPE_CHECKS: OptionTypeChecks;
|
|
17
|
+
export declare const MIN_SUPPORTED_MYSQL = "5.7.19";
|
|
18
|
+
export declare const downloadsBaseURL = "https://cdn.mysql.com//Downloads/MySQL-";
|
|
19
|
+
export declare const archiveBaseURL = "https://cdn.mysql.com/archives/mysql-";
|
|
20
|
+
export declare const DOWNLOADABLE_MYSQL_VERSIONS: readonly ["5.7.19", "5.7.20", "5.7.21", "5.7.22", "5.7.23", "5.7.24", "5.7.25", "5.7.26", "5.7.27", "5.7.28", "5.7.29", "5.7.30", "5.7.31", "5.7.32", "5.7.33", "5.7.34", "5.7.35", "5.7.36", "5.7.37", "5.7.38", "5.7.39", "5.7.40", "5.7.41", "5.7.42", "5.7.43", "5.7.44", "8.0.0", "8.0.1", "8.0.2", "8.0.3", "8.0.4", "8.0.11", "8.0.12", "8.0.13", "8.0.14", "8.0.15", "8.0.16", "8.0.17", "8.0.18", "8.0.19", "8.0.20", "8.0.21", "8.0.22", "8.0.23", "8.0.24", "8.0.25", "8.0.26", "8.0.27", "8.0.28", "8.0.30", "8.0.31", "8.0.32", "8.0.33", "8.0.34", "8.0.35", "8.0.36", "8.0.37", "8.0.39", "8.0.40", "8.0.41", "8.1.0", "8.2.0", "8.3.0", "8.4.0", "8.4.2", "8.4.3", "8.4.4", "9.0.1", "9.1.0", "9.2.0"];
|
|
21
|
+
export declare const MYSQL_ARCH_SUPPORT: {
|
|
22
|
+
readonly darwin: {
|
|
23
|
+
readonly arm64: "8.0.26 - 9.2.0";
|
|
24
|
+
readonly x64: "5.7.19 - 9.2.0";
|
|
25
|
+
};
|
|
26
|
+
readonly linux: {
|
|
27
|
+
readonly arm64: "8.0.31 - 9.2.0";
|
|
28
|
+
readonly x64: "5.7.19 - 9.2.0";
|
|
29
|
+
};
|
|
30
|
+
readonly win32: {
|
|
31
|
+
readonly x64: "5.7.19 - 9.2.0";
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
export declare const MYSQL_MIN_OS_SUPPORT: {
|
|
35
|
+
readonly win32: {
|
|
36
|
+
readonly x: "0.0.0";
|
|
37
|
+
};
|
|
38
|
+
readonly linux: {
|
|
39
|
+
readonly x: "0.0.0";
|
|
40
|
+
};
|
|
41
|
+
readonly darwin: {
|
|
42
|
+
readonly '5.7.19 - 5.7.23 || 8.0.1 - 8.0.3 || 8.0.11 - 8.0.12': "16.0.0";
|
|
43
|
+
readonly '5.7.24 - 5.7.29 || 8.0.4 || 8.0.13 - 8.0.18': "17.0.0";
|
|
44
|
+
readonly '5.7.30 - 5.7.31 || 8.0.19 - 8.0.22': "18.0.0";
|
|
45
|
+
readonly '8.0.0': "13.0.0";
|
|
46
|
+
readonly '8.0.23 - 8.0.27': "19.0.0";
|
|
47
|
+
readonly '8.0.28 - 8.0.31': "20.0.0";
|
|
48
|
+
readonly '8.0.32 - 8.0.34': "21.0.0";
|
|
49
|
+
readonly '8.0.35 - 8.0.39 || 8.1.0 - 8.4.2 || 9.0.1': "22.0.0";
|
|
50
|
+
readonly '8.0.40 - 8.0.41 || 8.4.3 - 8.4.4 || 9.1.0 - 9.2.0': "23.0.0";
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
export declare const DMR_MYSQL_VERSIONS = "8.0.0 - 8.0.2";
|
|
54
|
+
export declare const RC_MYSQL_VERSIONS = "8.0.3 - 8.0.4";
|
|
55
|
+
export declare const MYSQL_MACOS_VERSIONS_IN_FILENAME: {
|
|
56
|
+
readonly '5.7.19 - 5.7.20 || 8.0.1 - 8.0.3': "macos10.12";
|
|
57
|
+
readonly '5.7.21 - 5.7.23 || 8.0.4 - 8.0.12': "macos10.13";
|
|
58
|
+
readonly '5.7.24 - 5.7.31 || 8.0.13 - 8.0.18': "macos10.14";
|
|
59
|
+
readonly '8.0.0': "osx10.11";
|
|
60
|
+
readonly '8.0.19 - 8.0.23': "macos10.15";
|
|
61
|
+
readonly '8.0.24 - 8.0.28': "macos11";
|
|
62
|
+
readonly '8.0.30 - 8.0.31': "macos12";
|
|
63
|
+
readonly '8.0.32 - 8.0.35 || 8.1.0 - 8.2.0': "macos13";
|
|
64
|
+
readonly '8.0.36 - 8.0.40 || 8.3.0 - 8.4.3 || 9.0.1 - 9.1.0': "macos14";
|
|
65
|
+
readonly '8.0.41 || 8.4.4 || 9.2.0': "macos15";
|
|
66
|
+
};
|
|
67
|
+
export declare const MYSQL_LINUX_GLIBC_VERSIONS: {
|
|
68
|
+
readonly '5.7.19 - 8.0.20': "2.12";
|
|
69
|
+
readonly '8.0.21 - 9.2.0': "2.17";
|
|
70
|
+
};
|
|
71
|
+
export declare const MYSQL_LINUX_MINIMAL_INSTALL_AVAILABLE: {
|
|
72
|
+
readonly '5.7.19 - 8.0.15': "no";
|
|
73
|
+
readonly '8.0.16 - 8.0.20': "no-glibc-tag";
|
|
74
|
+
readonly '8.0.21 - 9.2.0': "glibc-tag";
|
|
75
|
+
};
|
|
76
|
+
export declare const MYSQL_LINUX_MINIMAL_INSTALL_AVAILABLE_ARM64 = ">=8.0.33";
|
|
77
|
+
export declare const MYSQL_LINUX_FILE_EXTENSIONS: {
|
|
78
|
+
readonly x64: {
|
|
79
|
+
readonly '5.7.19 - 8.0.11': "gz";
|
|
80
|
+
readonly '8.0.12 - 9.2.0': "xz";
|
|
81
|
+
};
|
|
82
|
+
readonly arm64: {
|
|
83
|
+
readonly '8.0.31 - 8.0.32': "gz";
|
|
84
|
+
readonly '8.0.33 - 9.2.0': "xz";
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
export declare const MYSQL_LINUX_MINIMAL_REBUILD_VERSIONS = "8.0.26";
|
|
88
|
+
export {};
|
package/dist/src/constants.js
CHANGED
|
@@ -1,41 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
3
|
+
exports.MYSQL_LINUX_MINIMAL_REBUILD_VERSIONS = exports.MYSQL_LINUX_FILE_EXTENSIONS = exports.MYSQL_LINUX_MINIMAL_INSTALL_AVAILABLE_ARM64 = exports.MYSQL_LINUX_MINIMAL_INSTALL_AVAILABLE = exports.MYSQL_LINUX_GLIBC_VERSIONS = exports.MYSQL_MACOS_VERSIONS_IN_FILENAME = exports.RC_MYSQL_VERSIONS = exports.DMR_MYSQL_VERSIONS = exports.MYSQL_MIN_OS_SUPPORT = exports.MYSQL_ARCH_SUPPORT = exports.DOWNLOADABLE_MYSQL_VERSIONS = exports.archiveBaseURL = exports.downloadsBaseURL = exports.MIN_SUPPORTED_MYSQL = exports.OPTION_TYPE_CHECKS = exports.LOG_LEVELS = exports.DEFAULT_OPTIONS_KEYS = exports.DEFAULT_OPTIONS = void 0;
|
|
4
|
+
exports.getInternalEnvVariable = getInternalEnvVariable;
|
|
5
5
|
const path_1 = require("path");
|
|
6
6
|
const os_1 = require("os");
|
|
7
7
|
const semver_1 = require("semver");
|
|
8
|
-
exports.
|
|
9
|
-
const DEFAULT_OPTIONS_GENERATOR = () => ({
|
|
8
|
+
exports.DEFAULT_OPTIONS = {
|
|
10
9
|
version: undefined,
|
|
11
10
|
dbName: 'dbdata',
|
|
12
11
|
logLevel: 'ERROR',
|
|
13
12
|
portRetries: 10,
|
|
14
13
|
downloadBinaryOnce: true,
|
|
15
|
-
lockRetries:
|
|
16
|
-
lockRetryWait:
|
|
14
|
+
lockRetries: 1_000,
|
|
15
|
+
lockRetryWait: 1_000,
|
|
17
16
|
username: 'root',
|
|
18
17
|
ignoreUnsupportedSystemVersion: false,
|
|
19
18
|
port: 0,
|
|
20
19
|
xPort: 0,
|
|
21
20
|
downloadRetries: 10,
|
|
22
21
|
initSQLString: '',
|
|
23
|
-
arch: process.arch
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
_DO_NOT_USE_dbPath: (0, path_1.normalize)(`${(0, os_1.tmpdir)()}/mysqlmsn/dbs/${(0, crypto_1.randomUUID)().replace(/-/g, '')}`),
|
|
27
|
-
_DO_NOT_USE_binaryDirectoryPath: `${(0, os_1.tmpdir)()}/mysqlmsn/binaries`,
|
|
28
|
-
_DO_NOT_USE_cli: false
|
|
29
|
-
});
|
|
30
|
-
exports.DEFAULT_OPTIONS_GENERATOR = DEFAULT_OPTIONS_GENERATOR;
|
|
31
|
-
exports.DEFAULT_OPTIONS_KEYS = Object.freeze(Object.keys((0, exports.DEFAULT_OPTIONS_GENERATOR)()));
|
|
22
|
+
arch: process.arch
|
|
23
|
+
};
|
|
24
|
+
exports.DEFAULT_OPTIONS_KEYS = Object.freeze(Object.keys(exports.DEFAULT_OPTIONS));
|
|
32
25
|
exports.LOG_LEVELS = {
|
|
33
26
|
'LOG': 0,
|
|
34
27
|
'WARN': 1,
|
|
35
28
|
'ERROR': 2
|
|
36
29
|
};
|
|
37
|
-
|
|
38
|
-
|
|
30
|
+
const internalOptions = {
|
|
31
|
+
deleteDBAfterStopped: 'true',
|
|
32
|
+
//mysqlmsn = MySQL Memory Server Node.js
|
|
33
|
+
databaseDirectoryPath: (0, path_1.normalize)(`${(0, os_1.tmpdir)()}/mysqlmsn/dbs`),
|
|
34
|
+
binaryDirectoryPath: `${(0, os_1.tmpdir)()}/mysqlmsn/binaries`,
|
|
35
|
+
cli: 'false'
|
|
36
|
+
};
|
|
37
|
+
function getInternalEnvVariable(envVar) {
|
|
38
|
+
return process.env['mysqlmsn_internal_DO_NOT_USE_' + envVar] || internalOptions[envVar];
|
|
39
|
+
}
|
|
40
|
+
const allowedArches = ['x64', 'arm64'];
|
|
39
41
|
exports.OPTION_TYPE_CHECKS = {
|
|
40
42
|
version: {
|
|
41
43
|
check: (opt) => opt === undefined || typeof opt === 'string' && (0, semver_1.valid)((0, semver_1.coerce)(opt)) !== null,
|
|
@@ -103,28 +105,88 @@ exports.OPTION_TYPE_CHECKS = {
|
|
|
103
105
|
definedType: 'string'
|
|
104
106
|
},
|
|
105
107
|
arch: {
|
|
106
|
-
check: (opt) => allowedArches.includes(opt),
|
|
108
|
+
check: (opt) => opt === undefined || allowedArches.includes(opt),
|
|
107
109
|
errorMessage: `Option arch must be either of the following: ${allowedArches.join(', ')}`,
|
|
108
110
|
definedType: 'string'
|
|
109
|
-
},
|
|
110
|
-
_DO_NOT_USE_deleteDBAfterStopped: {
|
|
111
|
-
check: (opt) => opt === undefined || typeof opt === 'boolean',
|
|
112
|
-
errorMessage: 'Option _DO_NOT_USE_deleteDBAfterStopped must be either undefined or a boolean.',
|
|
113
|
-
definedType: 'boolean'
|
|
114
|
-
},
|
|
115
|
-
_DO_NOT_USE_dbPath: {
|
|
116
|
-
check: (opt) => opt === undefined || typeof opt === 'string',
|
|
117
|
-
errorMessage: 'Option _DO_NOT_USE_dbPath must be either undefined or a string.',
|
|
118
|
-
definedType: 'string'
|
|
119
|
-
},
|
|
120
|
-
_DO_NOT_USE_binaryDirectoryPath: {
|
|
121
|
-
check: (opt) => opt === undefined || typeof opt === 'string',
|
|
122
|
-
errorMessage: 'Option _DO_NOT_USE_binaryDirectoryPath must be either undefined or a string.',
|
|
123
|
-
definedType: 'string'
|
|
124
|
-
},
|
|
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'
|
|
129
111
|
}
|
|
130
112
|
};
|
|
113
|
+
exports.MIN_SUPPORTED_MYSQL = '5.7.19';
|
|
114
|
+
exports.downloadsBaseURL = 'https://cdn.mysql.com//Downloads/MySQL-';
|
|
115
|
+
exports.archiveBaseURL = 'https://cdn.mysql.com/archives/mysql-';
|
|
116
|
+
// Versions 8.0.29, 8.0.38, 8.4.1, and 9.0.0 have been purposefully left out of this list as MySQL has removed them from the CDN due to critical issues.
|
|
117
|
+
exports.DOWNLOADABLE_MYSQL_VERSIONS = [
|
|
118
|
+
'5.7.19', '5.7.20', '5.7.21', '5.7.22', '5.7.23', '5.7.24', '5.7.25', '5.7.26', '5.7.27', '5.7.28', '5.7.29', '5.7.30', '5.7.31', '5.7.32', '5.7.33', '5.7.34', '5.7.35', '5.7.36', '5.7.37', '5.7.38', '5.7.39', '5.7.40', '5.7.41', '5.7.42', '5.7.43', '5.7.44',
|
|
119
|
+
'8.0.0', '8.0.1', '8.0.2', '8.0.3', '8.0.4',
|
|
120
|
+
'8.0.11', '8.0.12', '8.0.13', '8.0.14', '8.0.15', '8.0.16', '8.0.17', '8.0.18', '8.0.19', '8.0.20', '8.0.21', '8.0.22', '8.0.23', '8.0.24', '8.0.25', '8.0.26', '8.0.27', '8.0.28', '8.0.30', '8.0.31', '8.0.32', '8.0.33', '8.0.34', '8.0.35', '8.0.36', '8.0.37', '8.0.39', '8.0.40', '8.0.41',
|
|
121
|
+
'8.1.0', '8.2.0', '8.3.0',
|
|
122
|
+
'8.4.0', '8.4.2', '8.4.3', '8.4.4',
|
|
123
|
+
'9.0.1', '9.1.0', '9.2.0'
|
|
124
|
+
];
|
|
125
|
+
exports.MYSQL_ARCH_SUPPORT = {
|
|
126
|
+
darwin: {
|
|
127
|
+
arm64: '8.0.26 - 9.2.0',
|
|
128
|
+
x64: '5.7.19 - 9.2.0'
|
|
129
|
+
},
|
|
130
|
+
linux: {
|
|
131
|
+
arm64: '8.0.31 - 9.2.0',
|
|
132
|
+
x64: '5.7.19 - 9.2.0'
|
|
133
|
+
},
|
|
134
|
+
win32: {
|
|
135
|
+
x64: '5.7.19 - 9.2.0'
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
exports.MYSQL_MIN_OS_SUPPORT = {
|
|
139
|
+
win32: {
|
|
140
|
+
x: '0.0.0' // No minimum version is documented as far as I can tell, so allow any minimum version
|
|
141
|
+
},
|
|
142
|
+
linux: {
|
|
143
|
+
x: '0.0.0' // No minimum version is documented as far as I can tell, so allow any minimum version
|
|
144
|
+
},
|
|
145
|
+
darwin: {
|
|
146
|
+
'5.7.19 - 5.7.23 || 8.0.1 - 8.0.3 || 8.0.11 - 8.0.12': '16.0.0',
|
|
147
|
+
'5.7.24 - 5.7.29 || 8.0.4 || 8.0.13 - 8.0.18': '17.0.0',
|
|
148
|
+
'5.7.30 - 5.7.31 || 8.0.19 - 8.0.22': '18.0.0',
|
|
149
|
+
//5.7.32 - 5.7.44 is not supported for macOS by MySQL. Those versions are not appearing in this list
|
|
150
|
+
'8.0.0': '13.0.0',
|
|
151
|
+
'8.0.23 - 8.0.27': '19.0.0',
|
|
152
|
+
'8.0.28 - 8.0.31': '20.0.0',
|
|
153
|
+
'8.0.32 - 8.0.34': '21.0.0',
|
|
154
|
+
'8.0.35 - 8.0.39 || 8.1.0 - 8.4.2 || 9.0.1': '22.0.0',
|
|
155
|
+
'8.0.40 - 8.0.41 || 8.4.3 - 8.4.4 || 9.1.0 - 9.2.0': '23.0.0'
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
exports.DMR_MYSQL_VERSIONS = '8.0.0 - 8.0.2';
|
|
159
|
+
exports.RC_MYSQL_VERSIONS = '8.0.3 - 8.0.4';
|
|
160
|
+
exports.MYSQL_MACOS_VERSIONS_IN_FILENAME = {
|
|
161
|
+
'5.7.19 - 5.7.20 || 8.0.1 - 8.0.3': 'macos10.12',
|
|
162
|
+
'5.7.21 - 5.7.23 || 8.0.4 - 8.0.12': 'macos10.13',
|
|
163
|
+
'5.7.24 - 5.7.31 || 8.0.13 - 8.0.18': 'macos10.14',
|
|
164
|
+
'8.0.0': 'osx10.11',
|
|
165
|
+
'8.0.19 - 8.0.23': 'macos10.15',
|
|
166
|
+
'8.0.24 - 8.0.28': 'macos11',
|
|
167
|
+
'8.0.30 - 8.0.31': 'macos12',
|
|
168
|
+
'8.0.32 - 8.0.35 || 8.1.0 - 8.2.0': 'macos13',
|
|
169
|
+
'8.0.36 - 8.0.40 || 8.3.0 - 8.4.3 || 9.0.1 - 9.1.0': 'macos14',
|
|
170
|
+
'8.0.41 || 8.4.4 || 9.2.0': 'macos15'
|
|
171
|
+
};
|
|
172
|
+
exports.MYSQL_LINUX_GLIBC_VERSIONS = {
|
|
173
|
+
'5.7.19 - 8.0.20': '2.12',
|
|
174
|
+
'8.0.21 - 9.2.0': '2.17'
|
|
175
|
+
};
|
|
176
|
+
exports.MYSQL_LINUX_MINIMAL_INSTALL_AVAILABLE = {
|
|
177
|
+
'5.7.19 - 8.0.15': 'no',
|
|
178
|
+
'8.0.16 - 8.0.20': 'no-glibc-tag',
|
|
179
|
+
'8.0.21 - 9.2.0': 'glibc-tag'
|
|
180
|
+
};
|
|
181
|
+
exports.MYSQL_LINUX_MINIMAL_INSTALL_AVAILABLE_ARM64 = '>=8.0.33';
|
|
182
|
+
exports.MYSQL_LINUX_FILE_EXTENSIONS = {
|
|
183
|
+
x64: {
|
|
184
|
+
'5.7.19 - 8.0.11': 'gz',
|
|
185
|
+
'8.0.12 - 9.2.0': 'xz'
|
|
186
|
+
},
|
|
187
|
+
arm64: {
|
|
188
|
+
'8.0.31 - 8.0.32': 'gz',
|
|
189
|
+
'8.0.33 - 9.2.0': 'xz'
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
exports.MYSQL_LINUX_MINIMAL_REBUILD_VERSIONS = '8.0.26';
|
package/dist/src/index.js
CHANGED
|
@@ -1,59 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
4
|
};
|
|
38
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
6
|
exports.createDB = createDB;
|
|
40
7
|
const Logger_1 = __importDefault(require("./libraries/Logger"));
|
|
41
|
-
const os = __importStar(require("node:os"));
|
|
42
8
|
const Executor_1 = __importDefault(require("./libraries/Executor"));
|
|
43
9
|
const semver_1 = require("semver");
|
|
44
10
|
const Version_1 = __importDefault(require("./libraries/Version"));
|
|
45
|
-
const versions_json_1 = __importDefault(require("./versions.json"));
|
|
46
11
|
const Downloader_1 = require("./libraries/Downloader");
|
|
47
12
|
const constants_1 = require("./constants");
|
|
48
13
|
async function createDB(opts) {
|
|
49
14
|
const suppliedOpts = opts || {};
|
|
50
15
|
const suppliedOptsKeys = Object.keys(suppliedOpts);
|
|
51
|
-
|
|
52
|
-
if (suppliedOptsKeys.includes(opt)) {
|
|
53
|
-
console.warn(`[ mysql-memory-server - Options WARN ]: Creating MySQL database with option ${opt}. This is considered unstable and should not be used externally. Please consider removing this option.`);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
const options = (0, constants_1.DEFAULT_OPTIONS_GENERATOR)();
|
|
16
|
+
const options = { ...constants_1.DEFAULT_OPTIONS };
|
|
57
17
|
for (const opt of suppliedOptsKeys) {
|
|
58
18
|
if (!constants_1.DEFAULT_OPTIONS_KEYS.includes(opt)) {
|
|
59
19
|
throw `Option ${opt} is not a valid option.`;
|
|
@@ -78,22 +38,7 @@ async function createDB(opts) {
|
|
|
78
38
|
if (version === null || (options.version && !(0, semver_1.satisfies)(version.version, options.version)) || unsupportedMySQLIsInstalled) {
|
|
79
39
|
let binaryInfo;
|
|
80
40
|
let binaryFilepath;
|
|
81
|
-
|
|
82
|
-
binaryInfo = (0, Version_1.default)(versions_json_1.default, options.version, options);
|
|
83
|
-
logger.log('Using MySQL binary version:', binaryInfo.version, 'from URL:', binaryInfo.url);
|
|
84
|
-
}
|
|
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
|
-
logger.error(e);
|
|
92
|
-
if (options.version) {
|
|
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!`;
|
|
94
|
-
}
|
|
95
|
-
throw `A MySQL 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 your OS and CPU architecture, feel free to make a pull request to add support!`;
|
|
96
|
-
}
|
|
41
|
+
binaryInfo = (0, Version_1.default)(options.version, options.arch);
|
|
97
42
|
try {
|
|
98
43
|
binaryFilepath = await (0, Downloader_1.downloadBinary)(binaryInfo, options, logger);
|
|
99
44
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import Logger from './Logger';
|
|
2
2
|
import { BinaryInfo, InternalServerOptions } from '../../types';
|
|
3
|
-
export declare function downloadVersions(): Promise<string>;
|
|
4
3
|
export declare function downloadBinary(binaryInfo: BinaryInfo, options: InternalServerOptions, logger: Logger): Promise<string>;
|