Skip to content

Commit f0fb8bc

Browse files
build - v1.8.2
1 parent c89e74c commit f0fb8bc

File tree

9 files changed

+58
-72
lines changed

9 files changed

+58
-72
lines changed

dist/src/cli.js

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,20 @@
33
Object.defineProperty(exports, "__esModule", { value: true });
44
const index_1 = require("./index");
55
const constants_1 = require("./constants");
6-
async function main() {
6+
function main() {
77
const definedOptions = process.argv.filter((option) => option.startsWith('--'));
8-
const options = {
9-
_DO_NOT_USE_cli: true
10-
};
8+
const options = {};
9+
process.env.mysqlmsn_internal_DO_NOT_USE_cli = 'true';
1110
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+
}
1215
const index = process.argv.indexOf(opt);
1316
const optionValue = process.argv[index + 1];
1417
if (optionValue === undefined) {
15-
throw `Option ${opt} must have a value.`;
18+
console.error(`Option ${opt} must have a value.`);
19+
return;
1620
}
1721
const optionName = opt.slice(2);
1822
const optionType = constants_1.OPTION_TYPE_CHECKS[optionName].definedType;
@@ -39,17 +43,18 @@ async function main() {
3943
}
4044
}
4145
console.log('Creating ephemeral MySQL database...');
42-
const db = await (0, index_1.createDB)(options);
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`);
44-
if (process.platform === 'win32') {
45-
//The connection information logs will be different for Windows compared to other platforms.
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.
47-
//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
48-
//should only be displayed for non-Windows platforms.
49-
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.`);
50-
}
51-
else {
52-
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.`);
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+
});
5459
}
5560
main();

dist/src/constants.d.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,12 @@ export declare const LOG_LEVELS: {
77
readonly WARN: 1;
88
readonly ERROR: 2;
99
};
10-
export declare const INTERNAL_OPTIONS: readonly ["_DO_NOT_USE_deleteDBAfterStopped", "_DO_NOT_USE_dbPath", "_DO_NOT_USE_binaryDirectoryPath", "_DO_NOT_USE_beforeSignalCleanup", "_DO_NOT_USE_afterSignalCleanup"];
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;
1117
export declare const OPTION_TYPE_CHECKS: OptionTypeChecks;
18+
export {};

dist/src/constants.js

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use strict";
22
Object.defineProperty(exports, "__esModule", { value: true });
3-
exports.OPTION_TYPE_CHECKS = exports.INTERNAL_OPTIONS = exports.LOG_LEVELS = exports.DEFAULT_OPTIONS_KEYS = exports.DEFAULT_OPTIONS_GENERATOR = exports.MIN_SUPPORTED_MYSQL = void 0;
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;
45
const crypto_1 = require("crypto");
56
const path_1 = require("path");
67
const os_1 = require("os");
@@ -20,12 +21,7 @@ const DEFAULT_OPTIONS_GENERATOR = () => ({
2021
xPort: 0,
2122
downloadRetries: 10,
2223
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
2925
});
3026
exports.DEFAULT_OPTIONS_GENERATOR = DEFAULT_OPTIONS_GENERATOR;
3127
exports.DEFAULT_OPTIONS_KEYS = Object.freeze(Object.keys((0, exports.DEFAULT_OPTIONS_GENERATOR)()));
@@ -34,7 +30,16 @@ exports.LOG_LEVELS = {
3430
'WARN': 1,
3531
'ERROR': 2
3632
};
37-
exports.INTERNAL_OPTIONS = ['_DO_NOT_USE_deleteDBAfterStopped', '_DO_NOT_USE_dbPath', '_DO_NOT_USE_binaryDirectoryPath', '_DO_NOT_USE_beforeSignalCleanup', '_DO_NOT_USE_afterSignalCleanup'];
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+
}
3843
const allowedArches = ['x64', 'arm64', undefined];
3944
exports.OPTION_TYPE_CHECKS = {
4045
version: {
@@ -106,25 +111,5 @@ exports.OPTION_TYPE_CHECKS = {
106111
check: (opt) => allowedArches.includes(opt),
107112
errorMessage: `Option arch must be either of the following: ${allowedArches.join(', ')}`,
108113
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'
129114
}
130115
};

dist/src/index.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,6 @@ const constants_1 = require("./constants");
4848
async function createDB(opts) {
4949
const suppliedOpts = opts || {};
5050
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-
}
5651
const options = (0, constants_1.DEFAULT_OPTIONS_GENERATOR)();
5752
for (const opt of suppliedOptsKeys) {
5853
if (!constants_1.DEFAULT_OPTIONS_KEYS.includes(opt)) {

dist/src/libraries/Downloader.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const path_1 = require("path");
4646
const crypto_1 = require("crypto");
4747
const child_process_1 = require("child_process");
4848
const FileLock_1 = require("./FileLock");
49+
const constants_1 = require("../constants");
4950
function getZipData(entry) {
5051
return new Promise((resolve, reject) => {
5152
entry.getDataAsync((data, err) => {
@@ -208,7 +209,7 @@ function extractBinary(url, archiveLocation, extractedLocation, logger) {
208209
function downloadBinary(binaryInfo, options, logger) {
209210
return new Promise(async (resolve, reject) => {
210211
const { url, version } = binaryInfo;
211-
const dirpath = options._DO_NOT_USE_binaryDirectoryPath;
212+
const dirpath = (0, constants_1.getInternalEnvVariable)('binaryDirectoryPath');
212213
logger.log('Binary path:', dirpath);
213214
await fsPromises.mkdir(dirpath, { recursive: true });
214215
const lastDashIndex = url.lastIndexOf('-');

dist/src/libraries/Executor.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const path_1 = require("path");
4949
const FileLock_1 = require("./FileLock");
5050
const signal_exit_1 = require("signal-exit");
5151
const crypto_1 = require("crypto");
52+
const constants_1 = require("../constants");
5253
class Executor {
5354
constructor(logger) {
5455
_Executor_instances.add(this);
@@ -118,13 +119,13 @@ class Executor {
118119
this.version = installedMySQLBinary.version;
119120
this.versionInstalledOnSystem = installedMySQLBinary.installedOnSystem;
120121
this.removeExitHandler = (0, signal_exit_1.onExit)(() => {
121-
if (options._DO_NOT_USE_cli) {
122+
if ((0, constants_1.getInternalEnvVariable)('cli') === 'true') {
122123
console.log('\nShutting down the ephemeral MySQL database and cleaning all related files...');
123124
}
124125
this.DBDestroySignal.abort();
125-
if (options._DO_NOT_USE_deleteDBAfterStopped) {
126+
if ((0, constants_1.getInternalEnvVariable)('deleteDBAfterStopped') === 'true') {
126127
try {
127-
fs.rmSync(options._DO_NOT_USE_dbPath, { recursive: true, maxRetries: 50, force: true });
128+
fs.rmSync((0, constants_1.getInternalEnvVariable)('dbPath'), { recursive: true, maxRetries: 50, force: true });
128129
}
129130
catch (e) {
130131
this.logger.error('An error occurred while deleting database directory path:', e);
@@ -139,12 +140,12 @@ class Executor {
139140
this.logger.error('An error occurred while deleting database binary:', e);
140141
}
141142
}
142-
if (options._DO_NOT_USE_cli) {
143+
if ((0, constants_1.getInternalEnvVariable)('cli') === 'true') {
143144
console.log('Shutdown and cleanup is complete.');
144145
}
145146
});
146147
let retries = 0;
147-
const datadir = (0, path_1.normalize)(`${options._DO_NOT_USE_dbPath}/data`);
148+
const datadir = (0, path_1.normalize)(`${(0, constants_1.getInternalEnvVariable)('dbPath')}/data`);
148149
do {
149150
await __classPrivateFieldGet(this, _Executor_instances, "m", _Executor_setupDataDirectories).call(this, options, installedMySQLBinary.path, datadir, true);
150151
this.logger.log('Setting up directories was successful');
@@ -153,7 +154,7 @@ class Executor {
153154
this.logger.log('Using port:', port, 'and MySQLX port:', mySQLXPort, 'on retry:', retries);
154155
try {
155156
this.logger.log('Starting MySQL process');
156-
const resolved = await __classPrivateFieldGet(this, _Executor_instances, "m", _Executor_startMySQLProcess).call(this, options, port, mySQLXPort, datadir, options._DO_NOT_USE_dbPath, installedMySQLBinary.path);
157+
const resolved = await __classPrivateFieldGet(this, _Executor_instances, "m", _Executor_startMySQLProcess).call(this, options, port, mySQLXPort, datadir, (0, constants_1.getInternalEnvVariable)('dbPath'), installedMySQLBinary.path);
157158
this.logger.log('Starting process was successful');
158159
return resolved;
159160
}
@@ -253,7 +254,7 @@ _Executor_instances = new WeakSet(), _Executor_executeFile = function _Executor_
253254
if (portIssue || xPortIssue) {
254255
this.logger.log('Error log when exiting for port in use error:', errorLog);
255256
try {
256-
await __classPrivateFieldGet(this, _Executor_instances, "m", _Executor_deleteDatabaseDirectory).call(this, options._DO_NOT_USE_dbPath);
257+
await __classPrivateFieldGet(this, _Executor_instances, "m", _Executor_deleteDatabaseDirectory).call(this, (0, constants_1.getInternalEnvVariable)('dbPath'));
257258
}
258259
catch (e) {
259260
this.logger.error(e);
@@ -262,7 +263,7 @@ _Executor_instances = new WeakSet(), _Executor_executeFile = function _Executor_
262263
return reject('Port is already in use');
263264
}
264265
try {
265-
if (options._DO_NOT_USE_deleteDBAfterStopped) {
266+
if ((0, constants_1.getInternalEnvVariable)('deleteDBAfterStopped') === 'true') {
266267
await __classPrivateFieldGet(this, _Executor_instances, "m", _Executor_deleteDatabaseDirectory).call(this, dbPath);
267268
}
268269
}
@@ -477,7 +478,7 @@ _Executor_instances = new WeakSet(), _Executor_executeFile = function _Executor_
477478
initText += `\n${options.initSQLString}`;
478479
}
479480
this.logger.log('Writing init file');
480-
await fsPromises.writeFile(`${options._DO_NOT_USE_dbPath}/init.sql`, initText, { encoding: 'utf8' });
481+
await fsPromises.writeFile(`${(0, constants_1.getInternalEnvVariable)('dbPath')}/init.sql`, initText, { encoding: 'utf8' });
481482
this.logger.log('Finished writing init file');
482483
};
483484
exports.default = Executor;

dist/types/index.d.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ export type ServerOptions = {
1515
downloadRetries?: number | undefined;
1616
initSQLString?: string | undefined;
1717
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;
2218
};
2319
export type InternalServerOptions = {
2420
version?: string | undefined;
@@ -35,10 +31,6 @@ export type InternalServerOptions = {
3531
downloadRetries: number;
3632
initSQLString: string;
3733
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;
4234
};
4335
export type ExecutorOptions = {
4436
logLevel: LOG_LEVEL;

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mysql-memory-server",
3-
"version": "1.8.1",
3+
"version": "1.8.2",
44
"description": "Spin up an ephemeral MySQL database from your JavaScript code",
55
"main": "dist/src/index.js",
66
"types": "dist/src/index.d.ts",

0 commit comments

Comments
 (0)