Skip to content

Commit 578965a

Browse files
add valid option check
1 parent d30ac8b commit 578965a

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ export const LOG_LEVELS = {
3030
'ERROR': 2
3131
} as const;
3232

33+
export const INTERNAL_OPTIONS = ['_DO_NOT_USE_deleteDBAfterStopped', '_DO_NOT_USE_dbPath', '_DO_NOT_USE_binaryDirectoryPath'] as const;
34+
3335
export const OPTION_TYPE_CHECKS: OptionTypeChecks = {
3436
dbName: {
3537
check: (opt: any) => typeof opt === 'string' && opt.length <= 64,

src/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,23 @@ 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 } from './constants'
9+
import { MIN_SUPPORTED_MYSQL, DEFAULT_OPTIONS, OPTION_TYPE_CHECKS, INTERNAL_OPTIONS } from './constants'
1010

1111
export async function createDB(opts?: ServerOptions) {
1212
const suppliedOpts = opts || {};
1313
const suppliedOptsKeys = Object.keys(suppliedOpts);
14-
const internalOpts = ['_DO_NOT_USE_deleteDBAfterStopped', '_DO_NOT_USE_dbPath', '_DO_NOT_USE_binaryDirectoryPath'];
14+
const defaultOptionsKeys = Object.keys(DEFAULT_OPTIONS);
1515

16-
for (const opt of internalOpts) {
16+
for (const opt of INTERNAL_OPTIONS) {
1717
if (suppliedOptsKeys.includes(opt)) {
1818
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.`)
1919
}
2020
}
2121

2222
for (const opt of suppliedOptsKeys) {
23+
if (!defaultOptionsKeys.includes(opt)) {
24+
throw `Option ${opt} is not a valid option.`
25+
}
2326
if (suppliedOpts[opt] !== undefined && !OPTION_TYPE_CHECKS[opt].check(suppliedOpts[opt])) {
2427
//Supplied option failed the check
2528
throw OPTION_TYPE_CHECKS[opt].errorMessage

0 commit comments

Comments
 (0)