Skip to content

Commit 88bdc70

Browse files
build - v1.8.0
1 parent e48f40c commit 88bdc70

File tree

12 files changed

+58
-58
lines changed

12 files changed

+58
-58
lines changed

dist/src/cli.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ const constants_1 = require("./constants");
66
async function main() {
77
const definedOptions = process.argv.filter((option) => option.startsWith('--'));
88
const options = {
9-
_DO_NOT_USE_beforeSignalCleanupMessage: '\nShutting down the ephemeral MySQL database and cleaning all related files...',
10-
_DO_NOT_USE_afterSignalCleanupMessage: 'Shutdown and cleanup is complete.'
9+
_DO_NOT_USE_cli: true
1110
};
1211
for (const opt of definedOptions) {
1312
const index = process.argv.indexOf(opt);
@@ -41,7 +40,7 @@ async function main() {
4140
}
4241
console.log('Creating ephemeral MySQL database...');
4342
const db = await (0, index_1.createDB)(options);
44-
console.log(`A MySQL database has been successfully created with the following parameters:\n\nUsername: ${db.username} \nDatabase Name: ${db.dbName} \nPort: ${db.port} \nX Plugin Port: ${db.xPort} \nSocket: ${db.socket} \nX Plugin Socket: ${db.xSocket}\n`);
43+
console.log(`A MySQL database has been successfully created with the following parameters:\n\nMySQL Version: ${db.mysql.version} (${db.mysql.versionIsInstalledOnSystem ? 'installed on this system' : 'not installed on this system - downloaded from the MySQL CDN'}) \nUsername: ${db.username} \nDatabase Name: ${db.dbName} \nPort: ${db.port} \nX Plugin Port: ${db.xPort} \nSocket: ${db.socket} \nX Plugin Socket: ${db.xSocket}\n`);
4544
if (process.platform === 'win32') {
4645
//The connection information logs will be different for Windows compared to other platforms.
4746
//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.

dist/src/constants.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ const DEFAULT_OPTIONS_GENERATOR = () => ({
2020
xPort: 0,
2121
downloadRetries: 10,
2222
initSQLString: '',
23+
arch: process.arch,
2324
_DO_NOT_USE_deleteDBAfterStopped: true,
2425
//mysqlmsn = MySQL Memory Server Node.js
2526
_DO_NOT_USE_dbPath: (0, path_1.normalize)(`${(0, os_1.tmpdir)()}/mysqlmsn/dbs/${(0, crypto_1.randomUUID)().replace(/-/g, '')}`),
2627
_DO_NOT_USE_binaryDirectoryPath: `${(0, os_1.tmpdir)()}/mysqlmsn/binaries`,
27-
_DO_NOT_USE_beforeSignalCleanupMessage: '',
28-
_DO_NOT_USE_afterSignalCleanupMessage: ''
28+
_DO_NOT_USE_cli: false
2929
});
3030
exports.DEFAULT_OPTIONS_GENERATOR = DEFAULT_OPTIONS_GENERATOR;
3131
exports.DEFAULT_OPTIONS_KEYS = Object.freeze(Object.keys((0, exports.DEFAULT_OPTIONS_GENERATOR)()));
@@ -35,9 +35,10 @@ exports.LOG_LEVELS = {
3535
'ERROR': 2
3636
};
3737
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];
3839
exports.OPTION_TYPE_CHECKS = {
3940
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,
4142
errorMessage: 'Option version must be either undefined or a valid semver string.',
4243
definedType: 'string'
4344
},
@@ -101,6 +102,11 @@ exports.OPTION_TYPE_CHECKS = {
101102
errorMessage: 'Option initSQLString must be either undefined or a string.',
102103
definedType: 'string'
103104
},
105+
arch: {
106+
check: (opt) => allowedArches.includes(opt),
107+
errorMessage: `Option arch must be either of the following: ${allowedArches.join(', ')}`,
108+
definedType: 'string'
109+
},
104110
_DO_NOT_USE_deleteDBAfterStopped: {
105111
check: (opt) => opt === undefined || typeof opt === 'boolean',
106112
errorMessage: 'Option _DO_NOT_USE_deleteDBAfterStopped must be either undefined or a boolean.',
@@ -116,14 +122,9 @@ exports.OPTION_TYPE_CHECKS = {
116122
errorMessage: 'Option _DO_NOT_USE_binaryDirectoryPath must be either undefined or a string.',
117123
definedType: 'string'
118124
},
119-
_DO_NOT_USE_beforeSignalCleanupMessage: {
120-
check: (opt) => opt === undefined || typeof opt === 'string',
121-
errorMessage: 'Option _DO_NOT_USE_beforeSignalCleanup must be either undefined or a string.',
122-
definedType: 'string'
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'
128129
}
129130
};

dist/src/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ async function createDB(opts) {
6060
}
6161
if (!constants_1.OPTION_TYPE_CHECKS[opt].check(suppliedOpts[opt])) {
6262
//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]})`;
6464
}
6565
if (suppliedOpts[opt] !== undefined) {
6666
options[opt] = suppliedOpts[opt];
@@ -84,7 +84,7 @@ async function createDB(opts) {
8484
let binaryInfo;
8585
let binaryFilepath;
8686
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);
8888
logger.log('Using MySQL binary version:', binaryInfo.version, 'from URL:', binaryInfo.url);
8989
}
9090
catch (e) {
@@ -102,10 +102,10 @@ async function createDB(opts) {
102102
throw `Failed to download binary. The error was: "${error}"`;
103103
}
104104
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 });
106106
}
107107
else {
108108
logger.log(version);
109-
return await executor.startMySQL(options, version.path);
109+
return await executor.startMySQL(options, version);
110110
}
111111
}

dist/src/libraries/AbortSignal.d.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

dist/src/libraries/AbortSignal.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

dist/src/libraries/Executor.d.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import Logger from "./Logger";
2-
import { InstalledMySQLVersion, InternalServerOptions, MySQLDB } from "../../types";
2+
import { DownloadedMySQLVersion, InternalServerOptions, MySQLDB } from "../../types";
33
declare class Executor {
44
#private;
55
logger: Logger;
66
DBDestroySignal: AbortController;
77
removeExitHandler: () => void;
8+
version: string;
9+
versionInstalledOnSystem: boolean;
810
constructor(logger: Logger);
9-
getMySQLVersion(preferredVersion?: string): Promise<InstalledMySQLVersion | null>;
10-
startMySQL(options: InternalServerOptions, binaryFilepath: string): Promise<MySQLDB>;
11+
getMySQLVersion(preferredVersion?: string): Promise<DownloadedMySQLVersion | null>;
12+
startMySQL(options: InternalServerOptions, installedMySQLBinary: DownloadedMySQLVersion): Promise<MySQLDB>;
1113
}
1214
export default Executor;

dist/src/libraries/Executor.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class Executor {
7878
return reject('Could not get MySQL version');
7979
}
8080
else {
81-
versions.push({ version: version.version, path });
81+
versions.push({ version: version.version, path, installedOnSystem: true });
8282
}
8383
}
8484
if (preferredVersion) {
@@ -108,16 +108,18 @@ class Executor {
108108
reject('Could not get installed MySQL version');
109109
}
110110
else {
111-
resolve({ version: version.version, path: 'mysqld' });
111+
resolve({ version: version.version, path: 'mysqld', installedOnSystem: true });
112112
}
113113
}
114114
}
115115
});
116116
}
117-
async startMySQL(options, binaryFilepath) {
117+
async startMySQL(options, installedMySQLBinary) {
118+
this.version = installedMySQLBinary.version;
119+
this.versionInstalledOnSystem = installedMySQLBinary.installedOnSystem;
118120
this.removeExitHandler = (0, signal_exit_1.onExit)(() => {
119-
if (options._DO_NOT_USE_beforeSignalCleanupMessage) {
120-
console.log(options._DO_NOT_USE_beforeSignalCleanupMessage);
121+
if (options._DO_NOT_USE_cli) {
122+
console.log('\nShutting down the ephemeral MySQL database and cleaning all related files...');
121123
}
122124
this.DBDestroySignal.abort();
123125
if (options._DO_NOT_USE_deleteDBAfterStopped) {
@@ -128,7 +130,7 @@ class Executor {
128130
this.logger.error('An error occurred while deleting database directory path:', e);
129131
}
130132
}
131-
const binaryPathToDelete = __classPrivateFieldGet(this, _Executor_instances, "m", _Executor_returnBinaryPathToDelete).call(this, binaryFilepath, options);
133+
const binaryPathToDelete = __classPrivateFieldGet(this, _Executor_instances, "m", _Executor_returnBinaryPathToDelete).call(this, installedMySQLBinary.path, options);
132134
if (binaryPathToDelete) {
133135
try {
134136
fs.rmSync(binaryPathToDelete, { force: true, recursive: true, maxRetries: 50 });
@@ -137,21 +139,21 @@ class Executor {
137139
this.logger.error('An error occurred while deleting database binary:', e);
138140
}
139141
}
140-
if (options._DO_NOT_USE_afterSignalCleanupMessage) {
141-
console.log(options._DO_NOT_USE_afterSignalCleanupMessage);
142+
if (options._DO_NOT_USE_cli) {
143+
console.log('Shutdown and cleanup is complete.');
142144
}
143145
});
144146
let retries = 0;
145147
const datadir = (0, path_1.normalize)(`${options._DO_NOT_USE_dbPath}/data`);
146148
do {
147-
await __classPrivateFieldGet(this, _Executor_instances, "m", _Executor_setupDataDirectories).call(this, options, binaryFilepath, datadir, true);
149+
await __classPrivateFieldGet(this, _Executor_instances, "m", _Executor_setupDataDirectories).call(this, options, installedMySQLBinary.path, datadir, true);
148150
this.logger.log('Setting up directories was successful');
149151
const port = options.port || (0, Port_1.GenerateRandomPort)();
150152
const mySQLXPort = options.xPort || (0, Port_1.GenerateRandomPort)();
151153
this.logger.log('Using port:', port, 'and MySQLX port:', mySQLXPort, 'on retry:', retries);
152154
try {
153155
this.logger.log('Starting MySQL process');
154-
const resolved = await __classPrivateFieldGet(this, _Executor_instances, "m", _Executor_startMySQLProcess).call(this, options, port, mySQLXPort, datadir, options._DO_NOT_USE_dbPath, binaryFilepath);
156+
const resolved = await __classPrivateFieldGet(this, _Executor_instances, "m", _Executor_startMySQLProcess).call(this, options, port, mySQLXPort, datadir, options._DO_NOT_USE_dbPath, installedMySQLBinary.path);
155157
this.logger.log('Starting process was successful');
156158
return resolved;
157159
}
@@ -327,6 +329,10 @@ _Executor_instances = new WeakSet(), _Executor_executeFile = function _Executor_
327329
xSocket,
328330
dbName: options.dbName,
329331
username: options.username,
332+
mysql: {
333+
version: this.version,
334+
versionIsInstalledOnSystem: this.versionInstalledOnSystem
335+
},
330336
stop: () => {
331337
return new Promise(async (resolve, reject) => {
332338
resolveFunction = resolve;

dist/src/libraries/Version.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { MySQLVersion } from "../../types";
2-
export default function getBinaryURL(versions: MySQLVersion[], versionToGet?: string): {
1+
import { InternalServerOptions, MySQLVersion } from "../../types";
2+
export default function getBinaryURL(versions: MySQLVersion[], versionToGet: string, options: InternalServerOptions): {
33
url: string;
44
version: string;
55
};

dist/src/libraries/Version.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3636
exports.default = getBinaryURL;
3737
const os = __importStar(require("os"));
3838
const semver_1 = require("semver");
39-
function getBinaryURL(versions, versionToGet = "9.x") {
39+
function getBinaryURL(versions, versionToGet = "x", options) {
4040
let availableVersions = versions;
41-
availableVersions = availableVersions.filter(v => v.arch === process.arch);
41+
availableVersions = availableVersions.filter(v => v.arch === options.arch);
4242
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".' : ''}`;
4444
availableVersions = availableVersions.filter(v => v.os === process.platform);
4545
if (availableVersions.length === 0)
4646
throw `No MySQL binary could be found for your OS: ${process.platform}`;

dist/types/index.d.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ export type ServerOptions = {
1414
xPort?: number | undefined;
1515
downloadRetries?: number | undefined;
1616
initSQLString?: string | undefined;
17+
arch?: "arm64" | "x64" | undefined;
1718
_DO_NOT_USE_deleteDBAfterStopped?: boolean | undefined;
1819
_DO_NOT_USE_dbPath?: string | undefined;
1920
_DO_NOT_USE_binaryDirectoryPath?: string | undefined;
20-
_DO_NOT_USE_beforeSignalCleanupMessage?: string | undefined;
21-
_DO_NOT_USE_afterSignalCleanupMessage?: string | undefined;
21+
_DO_NOT_USE_cli?: boolean | undefined;
2222
};
2323
export type InternalServerOptions = {
2424
version?: string | undefined;
@@ -34,11 +34,11 @@ export type InternalServerOptions = {
3434
xPort: number;
3535
downloadRetries: number;
3636
initSQLString: string;
37+
arch: string;
3738
_DO_NOT_USE_deleteDBAfterStopped: boolean;
3839
_DO_NOT_USE_dbPath: string;
3940
_DO_NOT_USE_binaryDirectoryPath: string;
40-
_DO_NOT_USE_beforeSignalCleanupMessage: string;
41-
_DO_NOT_USE_afterSignalCleanupMessage: string;
41+
_DO_NOT_USE_cli: boolean;
4242
};
4343
export type ExecutorOptions = {
4444
logLevel: LOG_LEVEL;
@@ -55,6 +55,10 @@ export type MySQLDB = {
5555
xSocket: string;
5656
dbName: string;
5757
username: string;
58+
mysql: {
59+
version: string;
60+
versionIsInstalledOnSystem: boolean;
61+
};
5862
stop: () => Promise<void>;
5963
};
6064
export type MySQLVersion = {
@@ -64,9 +68,10 @@ export type MySQLVersion = {
6468
osKernelVersionsSupported: string;
6569
url: string;
6670
};
67-
export type InstalledMySQLVersion = {
71+
export type DownloadedMySQLVersion = {
6872
version: string;
6973
path: string;
74+
installedOnSystem: boolean;
7075
};
7176
export type BinaryInfo = {
7277
url: string;

0 commit comments

Comments
 (0)