Skip to content

Commit 0702ae6

Browse files
mention that types can be undefined
1 parent cc06485 commit 0702ae6

File tree

2 files changed

+39
-39
lines changed

2 files changed

+39
-39
lines changed

src/constants.ts

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -36,67 +36,67 @@ export const INTERNAL_OPTIONS = ['_DO_NOT_USE_deleteDBAfterStopped', '_DO_NOT_US
3636

3737
export const OPTION_TYPE_CHECKS: OptionTypeChecks = {
3838
version: {
39-
check: (opt: any) => typeof opt === 'string' && validSemver(opt) !== null,
40-
errorMessage: 'Option version must be a valid semver string.'
39+
check: (opt: any) => opt === undefined || typeof opt === 'string' && validSemver(opt) !== null,
40+
errorMessage: 'Option version must be either undefined or a valid semver string.'
4141
},
4242
dbName: {
43-
check: (opt: any) => typeof opt === 'string' && opt.length <= 64,
44-
errorMessage: 'Option dbName must be a string and must not be longer than 64 characters.'
43+
check: (opt: any) => opt === undefined || typeof opt === 'string' && opt.length <= 64,
44+
errorMessage: 'Option dbName must be either undefined or a string that is not longer than 64 characters.'
4545
},
4646
logLevel: {
47-
check: (opt: any) => Object.keys(LOG_LEVELS).includes(opt),
48-
errorMessage: 'Option logLevel must be either "LOG", "WARN", or "ERROR".'
47+
check: (opt: any) => opt === undefined || Object.keys(LOG_LEVELS).includes(opt),
48+
errorMessage: 'Option logLevel must be either undefined or "LOG", "WARN", or "ERROR".'
4949
},
5050
portRetries: {
51-
check: (opt: any) => typeof opt === 'number' && opt >= 0,
52-
errorMessage: 'Option portRetries must be a positive number or 0.'
51+
check: (opt: any) => opt === undefined || typeof opt === 'number' && opt >= 0,
52+
errorMessage: 'Option portRetries must be either undefined, a positive number, or 0.'
5353
},
5454
downloadBinaryOnce: {
55-
check: (opt: any) => typeof opt === 'boolean',
56-
errorMessage: 'Option downloadBinaryOnce must be a boolean.'
55+
check: (opt: any) => opt === undefined || typeof opt === 'boolean',
56+
errorMessage: 'Option downloadBinaryOnce must be either undefined or a boolean.'
5757
},
5858
lockRetries: {
59-
check: (opt: any) => typeof opt === 'number' && opt >= 0,
60-
errorMessage: 'Option lockRetries must be a positive number or 0.'
59+
check: (opt: any) => opt === undefined || typeof opt === 'number' && opt >= 0,
60+
errorMessage: 'Option lockRetries must be either undefined, a positive number, or 0.'
6161
},
6262
lockRetryWait: {
63-
check: (opt: any) => typeof opt === 'number' && opt >= 0,
64-
errorMessage: 'Option lockRetryWait must be a positive number or 0.'
63+
check: (opt: any) => opt === undefined || typeof opt === 'number' && opt >= 0,
64+
errorMessage: 'Option lockRetryWait must be either undefined, a positive number, or 0.'
6565
},
6666
username: {
67-
check: (opt: any) => typeof opt === 'string' && opt.length <= 32,
68-
errorMessage: 'Option username must be a string and must not be longer than 32 characters.'
69-
},
70-
_DO_NOT_USE_deleteDBAfterStopped: {
71-
check: (opt: any) => typeof opt === 'boolean',
72-
errorMessage: 'Option _DO_NOT_USE_deleteDBAfterStopped must be a boolean.'
73-
},
74-
_DO_NOT_USE_dbPath: {
75-
check: (opt: any) => typeof opt === 'string',
76-
errorMessage: 'Option _DO_NOT_USE_dbPath must be a string.'
67+
check: (opt: any) => opt === undefined || typeof opt === 'string' && opt.length <= 32,
68+
errorMessage: 'Option username must be either undefined or a string that is not longer than 32 characters.'
7769
},
7870
ignoreUnsupportedSystemVersion: {
79-
check: (opt: any) => typeof opt === 'boolean',
80-
errorMessage: 'Option ignoreUnsupportedSystemVersion must be a boolean.'
71+
check: (opt: any) => opt === undefined || typeof opt === 'boolean',
72+
errorMessage: 'Option ignoreUnsupportedSystemVersion must be either undefined or a boolean.'
8173
},
8274
port: {
83-
check: (opt: any) => typeof opt === 'number' && opt >= 0 && opt <= 65535,
84-
errorMessage: 'Option port must be a number and between 0 and 65535 inclusive.'
75+
check: (opt: any) => opt === undefined || typeof opt === 'number' && opt >= 0 && opt <= 65535,
76+
errorMessage: 'Option port must be either undefined or a number that is between 0 and 65535 inclusive.'
8577
},
8678
xPort: {
87-
check: (opt: any) => typeof opt === 'number' && opt >= 0 && opt <= 65535,
88-
errorMessage: 'Option xPort must be a number and between 0 and 65535 inclusive.'
89-
},
90-
_DO_NOT_USE_binaryDirectoryPath: {
91-
check: (opt: any) => typeof opt === 'string',
92-
errorMessage: 'Option _DO_NOT_USE_binaryDirectoryPath must be a string.'
79+
check: (opt: any) => opt === undefined || typeof opt === 'number' && opt >= 0 && opt <= 65535,
80+
errorMessage: 'Option xPort must be either undefined or a number that is between 0 and 65535 inclusive.'
9381
},
9482
downloadRetries: {
95-
check: (opt: any) => typeof opt === 'number' && opt >= 0,
96-
errorMessage: 'Option downloadRetries must be a positive number or 0.'
83+
check: (opt: any) => opt === undefined || typeof opt === 'number' && opt >= 0,
84+
errorMessage: 'Option downloadRetries must be either undefined, a positive number, or 0.'
9785
},
9886
initSQLString: {
99-
check: (opt: any) => typeof opt === 'string',
100-
errorMessage: 'Option initSQLString must be a string.'
87+
check: (opt: any) => opt === undefined || typeof opt === 'string',
88+
errorMessage: 'Option initSQLString must be either undefined or a string.'
89+
},
90+
_DO_NOT_USE_deleteDBAfterStopped: {
91+
check: (opt: any) => opt === undefined || typeof opt === 'boolean',
92+
errorMessage: 'Option _DO_NOT_USE_deleteDBAfterStopped must be either undefined or a boolean.'
93+
},
94+
_DO_NOT_USE_dbPath: {
95+
check: (opt: any) => opt === undefined || typeof opt === 'string',
96+
errorMessage: 'Option _DO_NOT_USE_dbPath must be either undefined or a string.'
97+
},
98+
_DO_NOT_USE_binaryDirectoryPath: {
99+
check: (opt: any) => opt === undefined || typeof opt === 'string',
100+
errorMessage: 'Option _DO_NOT_USE_binaryDirectoryPath must be either undefined or a string.'
101101
}
102102
} as const;

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export async function createDB(opts?: ServerOptions) {
2323
if (!defaultOptionsKeys.includes(opt)) {
2424
throw `Option ${opt} is not a valid option.`
2525
}
26-
if (suppliedOpts[opt] !== undefined && !OPTION_TYPE_CHECKS[opt].check(suppliedOpts[opt])) {
26+
if (!OPTION_TYPE_CHECKS[opt].check(suppliedOpts[opt])) {
2727
//Supplied option failed the check
2828
throw OPTION_TYPE_CHECKS[opt].errorMessage
2929
}

0 commit comments

Comments
 (0)