Skip to content

Commit 65e9121

Browse files
fix databases being made in the same directory
1 parent 0702ae6 commit 65e9121

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/constants.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { valid as validSemver } from "semver";
66

77
export const MIN_SUPPORTED_MYSQL = '8.0.20';
88

9-
export const DEFAULT_OPTIONS: InternalServerOptions = {
9+
export const DEFAULT_OPTIONS_GENERATOR: () => InternalServerOptions = () => ({
1010
version: undefined,
1111
dbName: 'dbdata',
1212
logLevel: 'ERROR',
@@ -24,7 +24,9 @@ export const DEFAULT_OPTIONS: InternalServerOptions = {
2424
//mysqlmsn = MySQL Memory Server Node.js
2525
_DO_NOT_USE_dbPath: normalizePath(`${tmpdir()}/mysqlmsn/dbs/${randomUUID().replace(/-/g, '')}`),
2626
_DO_NOT_USE_binaryDirectoryPath: `${tmpdir()}/mysqlmsn/binaries`
27-
} as const;
27+
});
28+
29+
export const DEFAULT_OPTIONS_KEYS = Object.freeze(Object.keys(DEFAULT_OPTIONS_GENERATOR()))
2830

2931
export const LOG_LEVELS = {
3032
'LOG': 0,

src/index.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,34 @@ import { BinaryInfo, InternalServerOptions, ServerOptions } from '../types'
66
import getBinaryURL from './libraries/Version'
77
import MySQLVersions from './versions.json'
88
import { downloadBinary } from './libraries/Downloader'
9-
import { MIN_SUPPORTED_MYSQL, DEFAULT_OPTIONS, OPTION_TYPE_CHECKS, INTERNAL_OPTIONS } from './constants'
9+
import { MIN_SUPPORTED_MYSQL, DEFAULT_OPTIONS_KEYS, OPTION_TYPE_CHECKS, INTERNAL_OPTIONS, DEFAULT_OPTIONS_GENERATOR } from './constants'
1010

1111
export async function createDB(opts?: ServerOptions) {
1212
const suppliedOpts = opts || {};
1313
const suppliedOptsKeys = Object.keys(suppliedOpts);
14-
const defaultOptionsKeys = Object.keys(DEFAULT_OPTIONS);
1514

1615
for (const opt of INTERNAL_OPTIONS) {
1716
if (suppliedOptsKeys.includes(opt)) {
1817
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.`)
1918
}
2019
}
2120

21+
const options = DEFAULT_OPTIONS_GENERATOR();
22+
2223
for (const opt of suppliedOptsKeys) {
23-
if (!defaultOptionsKeys.includes(opt)) {
24+
if (!DEFAULT_OPTIONS_KEYS.includes(opt)) {
2425
throw `Option ${opt} is not a valid option.`
2526
}
27+
2628
if (!OPTION_TYPE_CHECKS[opt].check(suppliedOpts[opt])) {
2729
//Supplied option failed the check
2830
throw OPTION_TYPE_CHECKS[opt].errorMessage
2931
}
32+
33+
if (suppliedOpts[opt] !== undefined) {
34+
options[opt] = suppliedOpts[opt]
35+
}
3036
}
31-
32-
const options: InternalServerOptions = {...DEFAULT_OPTIONS, ...opts}
3337

3438
const logger = new Logger(options.logLevel)
3539

0 commit comments

Comments
 (0)