mysql-memory-server 1.8.1 → 1.8.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.
- package/README.md +0 -29
- package/dist/src/cli.js +22 -17
- package/dist/src/constants.d.ts +8 -1
- package/dist/src/constants.js +13 -28
- package/dist/src/index.js +0 -5
- package/dist/src/libraries/Downloader.js +2 -1
- package/dist/src/libraries/Executor.js +10 -9
- package/dist/types/index.d.ts +0 -8
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -200,32 +200,3 @@ The internal queries that are ran before the queries in ```initSQLString``` are
|
|
|
200
200
|
Default: process.arch
|
|
201
201
|
|
|
202
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
|
-
|
|
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
|
@@ -7,5 +7,12 @@ export declare const LOG_LEVELS: {
|
|
|
7
7
|
readonly WARN: 1;
|
|
8
8
|
readonly ERROR: 2;
|
|
9
9
|
};
|
|
10
|
-
|
|
10
|
+
declare const internalOptions: {
|
|
11
|
+
deleteDBAfterStopped: string;
|
|
12
|
+
dbPath: string;
|
|
13
|
+
binaryDirectoryPath: string;
|
|
14
|
+
cli: string;
|
|
15
|
+
};
|
|
16
|
+
export declare function getInternalEnvVariable(envVar: keyof typeof internalOptions): string;
|
|
11
17
|
export declare const OPTION_TYPE_CHECKS: OptionTypeChecks;
|
|
18
|
+
export {};
|
package/dist/src/constants.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OPTION_TYPE_CHECKS = exports.
|
|
3
|
+
exports.OPTION_TYPE_CHECKS = exports.LOG_LEVELS = exports.DEFAULT_OPTIONS_KEYS = exports.DEFAULT_OPTIONS_GENERATOR = exports.MIN_SUPPORTED_MYSQL = void 0;
|
|
4
|
+
exports.getInternalEnvVariable = getInternalEnvVariable;
|
|
4
5
|
const crypto_1 = require("crypto");
|
|
5
6
|
const path_1 = require("path");
|
|
6
7
|
const os_1 = require("os");
|
|
@@ -20,12 +21,7 @@ const DEFAULT_OPTIONS_GENERATOR = () => ({
|
|
|
20
21
|
xPort: 0,
|
|
21
22
|
downloadRetries: 10,
|
|
22
23
|
initSQLString: '',
|
|
23
|
-
arch: process.arch
|
|
24
|
-
_DO_NOT_USE_deleteDBAfterStopped: true,
|
|
25
|
-
//mysqlmsn = MySQL Memory Server Node.js
|
|
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
|
|
24
|
+
arch: process.arch
|
|
29
25
|
});
|
|
30
26
|
exports.DEFAULT_OPTIONS_GENERATOR = DEFAULT_OPTIONS_GENERATOR;
|
|
31
27
|
exports.DEFAULT_OPTIONS_KEYS = Object.freeze(Object.keys((0, exports.DEFAULT_OPTIONS_GENERATOR)()));
|
|
@@ -34,7 +30,16 @@ exports.LOG_LEVELS = {
|
|
|
34
30
|
'WARN': 1,
|
|
35
31
|
'ERROR': 2
|
|
36
32
|
};
|
|
37
|
-
|
|
33
|
+
const internalOptions = {
|
|
34
|
+
deleteDBAfterStopped: 'true',
|
|
35
|
+
//mysqlmsn = MySQL Memory Server Node.js
|
|
36
|
+
dbPath: (0, path_1.normalize)(`${(0, os_1.tmpdir)()}/mysqlmsn/dbs/${(0, crypto_1.randomUUID)().replace(/-/g, '')}`),
|
|
37
|
+
binaryDirectoryPath: `${(0, os_1.tmpdir)()}/mysqlmsn/binaries`,
|
|
38
|
+
cli: 'false'
|
|
39
|
+
};
|
|
40
|
+
function getInternalEnvVariable(envVar) {
|
|
41
|
+
return process.env['mysqlmsn_internal_DO_NOT_USE_' + envVar] || internalOptions[envVar];
|
|
42
|
+
}
|
|
38
43
|
const allowedArches = ['x64', 'arm64', undefined];
|
|
39
44
|
exports.OPTION_TYPE_CHECKS = {
|
|
40
45
|
version: {
|
|
@@ -106,25 +111,5 @@ exports.OPTION_TYPE_CHECKS = {
|
|
|
106
111
|
check: (opt) => allowedArches.includes(opt),
|
|
107
112
|
errorMessage: `Option arch must be either of the following: ${allowedArches.join(', ')}`,
|
|
108
113
|
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
114
|
}
|
|
130
115
|
};
|
package/dist/src/index.js
CHANGED
|
@@ -48,11 +48,6 @@ const constants_1 = require("./constants");
|
|
|
48
48
|
async function createDB(opts) {
|
|
49
49
|
const suppliedOpts = opts || {};
|
|
50
50
|
const suppliedOptsKeys = Object.keys(suppliedOpts);
|
|
51
|
-
for (const opt of constants_1.INTERNAL_OPTIONS) {
|
|
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
51
|
const options = (0, constants_1.DEFAULT_OPTIONS_GENERATOR)();
|
|
57
52
|
for (const opt of suppliedOptsKeys) {
|
|
58
53
|
if (!constants_1.DEFAULT_OPTIONS_KEYS.includes(opt)) {
|
|
@@ -46,6 +46,7 @@ const path_1 = require("path");
|
|
|
46
46
|
const crypto_1 = require("crypto");
|
|
47
47
|
const child_process_1 = require("child_process");
|
|
48
48
|
const FileLock_1 = require("./FileLock");
|
|
49
|
+
const constants_1 = require("../constants");
|
|
49
50
|
function getZipData(entry) {
|
|
50
51
|
return new Promise((resolve, reject) => {
|
|
51
52
|
entry.getDataAsync((data, err) => {
|
|
@@ -208,7 +209,7 @@ function extractBinary(url, archiveLocation, extractedLocation, logger) {
|
|
|
208
209
|
function downloadBinary(binaryInfo, options, logger) {
|
|
209
210
|
return new Promise(async (resolve, reject) => {
|
|
210
211
|
const { url, version } = binaryInfo;
|
|
211
|
-
const dirpath =
|
|
212
|
+
const dirpath = (0, constants_1.getInternalEnvVariable)('binaryDirectoryPath');
|
|
212
213
|
logger.log('Binary path:', dirpath);
|
|
213
214
|
await fsPromises.mkdir(dirpath, { recursive: true });
|
|
214
215
|
const lastDashIndex = url.lastIndexOf('-');
|
|
@@ -49,6 +49,7 @@ const path_1 = require("path");
|
|
|
49
49
|
const FileLock_1 = require("./FileLock");
|
|
50
50
|
const signal_exit_1 = require("signal-exit");
|
|
51
51
|
const crypto_1 = require("crypto");
|
|
52
|
+
const constants_1 = require("../constants");
|
|
52
53
|
class Executor {
|
|
53
54
|
constructor(logger) {
|
|
54
55
|
_Executor_instances.add(this);
|
|
@@ -118,13 +119,13 @@ class Executor {
|
|
|
118
119
|
this.version = installedMySQLBinary.version;
|
|
119
120
|
this.versionInstalledOnSystem = installedMySQLBinary.installedOnSystem;
|
|
120
121
|
this.removeExitHandler = (0, signal_exit_1.onExit)(() => {
|
|
121
|
-
if (
|
|
122
|
+
if ((0, constants_1.getInternalEnvVariable)('cli') === 'true') {
|
|
122
123
|
console.log('\nShutting down the ephemeral MySQL database and cleaning all related files...');
|
|
123
124
|
}
|
|
124
125
|
this.DBDestroySignal.abort();
|
|
125
|
-
if (
|
|
126
|
+
if ((0, constants_1.getInternalEnvVariable)('deleteDBAfterStopped') === 'true') {
|
|
126
127
|
try {
|
|
127
|
-
fs.rmSync(
|
|
128
|
+
fs.rmSync((0, constants_1.getInternalEnvVariable)('dbPath'), { recursive: true, maxRetries: 50, force: true });
|
|
128
129
|
}
|
|
129
130
|
catch (e) {
|
|
130
131
|
this.logger.error('An error occurred while deleting database directory path:', e);
|
|
@@ -139,12 +140,12 @@ class Executor {
|
|
|
139
140
|
this.logger.error('An error occurred while deleting database binary:', e);
|
|
140
141
|
}
|
|
141
142
|
}
|
|
142
|
-
if (
|
|
143
|
+
if ((0, constants_1.getInternalEnvVariable)('cli') === 'true') {
|
|
143
144
|
console.log('Shutdown and cleanup is complete.');
|
|
144
145
|
}
|
|
145
146
|
});
|
|
146
147
|
let retries = 0;
|
|
147
|
-
const datadir = (0, path_1.normalize)(`${
|
|
148
|
+
const datadir = (0, path_1.normalize)(`${(0, constants_1.getInternalEnvVariable)('dbPath')}/data`);
|
|
148
149
|
do {
|
|
149
150
|
await __classPrivateFieldGet(this, _Executor_instances, "m", _Executor_setupDataDirectories).call(this, options, installedMySQLBinary.path, datadir, true);
|
|
150
151
|
this.logger.log('Setting up directories was successful');
|
|
@@ -153,7 +154,7 @@ class Executor {
|
|
|
153
154
|
this.logger.log('Using port:', port, 'and MySQLX port:', mySQLXPort, 'on retry:', retries);
|
|
154
155
|
try {
|
|
155
156
|
this.logger.log('Starting MySQL process');
|
|
156
|
-
const resolved = await __classPrivateFieldGet(this, _Executor_instances, "m", _Executor_startMySQLProcess).call(this, options, port, mySQLXPort, datadir,
|
|
157
|
+
const resolved = await __classPrivateFieldGet(this, _Executor_instances, "m", _Executor_startMySQLProcess).call(this, options, port, mySQLXPort, datadir, (0, constants_1.getInternalEnvVariable)('dbPath'), installedMySQLBinary.path);
|
|
157
158
|
this.logger.log('Starting process was successful');
|
|
158
159
|
return resolved;
|
|
159
160
|
}
|
|
@@ -253,7 +254,7 @@ _Executor_instances = new WeakSet(), _Executor_executeFile = function _Executor_
|
|
|
253
254
|
if (portIssue || xPortIssue) {
|
|
254
255
|
this.logger.log('Error log when exiting for port in use error:', errorLog);
|
|
255
256
|
try {
|
|
256
|
-
await __classPrivateFieldGet(this, _Executor_instances, "m", _Executor_deleteDatabaseDirectory).call(this,
|
|
257
|
+
await __classPrivateFieldGet(this, _Executor_instances, "m", _Executor_deleteDatabaseDirectory).call(this, (0, constants_1.getInternalEnvVariable)('dbPath'));
|
|
257
258
|
}
|
|
258
259
|
catch (e) {
|
|
259
260
|
this.logger.error(e);
|
|
@@ -262,7 +263,7 @@ _Executor_instances = new WeakSet(), _Executor_executeFile = function _Executor_
|
|
|
262
263
|
return reject('Port is already in use');
|
|
263
264
|
}
|
|
264
265
|
try {
|
|
265
|
-
if (
|
|
266
|
+
if ((0, constants_1.getInternalEnvVariable)('deleteDBAfterStopped') === 'true') {
|
|
266
267
|
await __classPrivateFieldGet(this, _Executor_instances, "m", _Executor_deleteDatabaseDirectory).call(this, dbPath);
|
|
267
268
|
}
|
|
268
269
|
}
|
|
@@ -477,7 +478,7 @@ _Executor_instances = new WeakSet(), _Executor_executeFile = function _Executor_
|
|
|
477
478
|
initText += `\n${options.initSQLString}`;
|
|
478
479
|
}
|
|
479
480
|
this.logger.log('Writing init file');
|
|
480
|
-
await fsPromises.writeFile(`${
|
|
481
|
+
await fsPromises.writeFile(`${(0, constants_1.getInternalEnvVariable)('dbPath')}/init.sql`, initText, { encoding: 'utf8' });
|
|
481
482
|
this.logger.log('Finished writing init file');
|
|
482
483
|
};
|
|
483
484
|
exports.default = Executor;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -15,10 +15,6 @@ export type ServerOptions = {
|
|
|
15
15
|
downloadRetries?: number | undefined;
|
|
16
16
|
initSQLString?: string | undefined;
|
|
17
17
|
arch?: "arm64" | "x64" | undefined;
|
|
18
|
-
_DO_NOT_USE_deleteDBAfterStopped?: boolean | undefined;
|
|
19
|
-
_DO_NOT_USE_dbPath?: string | undefined;
|
|
20
|
-
_DO_NOT_USE_binaryDirectoryPath?: string | undefined;
|
|
21
|
-
_DO_NOT_USE_cli?: boolean | undefined;
|
|
22
18
|
};
|
|
23
19
|
export type InternalServerOptions = {
|
|
24
20
|
version?: string | undefined;
|
|
@@ -35,10 +31,6 @@ export type InternalServerOptions = {
|
|
|
35
31
|
downloadRetries: number;
|
|
36
32
|
initSQLString: string;
|
|
37
33
|
arch: string;
|
|
38
|
-
_DO_NOT_USE_deleteDBAfterStopped: boolean;
|
|
39
|
-
_DO_NOT_USE_dbPath: string;
|
|
40
|
-
_DO_NOT_USE_binaryDirectoryPath: string;
|
|
41
|
-
_DO_NOT_USE_cli: boolean;
|
|
42
34
|
};
|
|
43
35
|
export type ExecutorOptions = {
|
|
44
36
|
logLevel: LOG_LEVEL;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mysql-memory-server",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.2",
|
|
4
4
|
"description": "Spin up an ephemeral MySQL database from your JavaScript code",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"types": "dist/src/index.d.ts",
|
|
@@ -31,12 +31,12 @@
|
|
|
31
31
|
"@babel/preset-env": "^7.25.9",
|
|
32
32
|
"@babel/preset-typescript": "^7.25.9",
|
|
33
33
|
"@types/adm-zip": "^0.5.5",
|
|
34
|
-
"@types/node": "^22.
|
|
34
|
+
"@types/node": "^22.10.6",
|
|
35
35
|
"@types/semver": "^7.5.8",
|
|
36
36
|
"babel-jest": "^29.7.0",
|
|
37
37
|
"jest": "^29.7.0",
|
|
38
|
-
"mysql2": "^3.
|
|
39
|
-
"typescript": "^5.7.
|
|
38
|
+
"mysql2": "^3.12.0",
|
|
39
|
+
"typescript": "^5.7.3"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"adm-zip": "^0.5.16",
|