Skip to content

Commit d1e4568

Browse files
add version and type enforcement to OptionTypeChecks
1 parent c3bd410 commit d1e4568

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/constants.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { InternalServerOptions, OptionTypeChecks } from "../types";
22
import { randomUUID } from "crypto";
33
import {normalize as normalizePath} from 'path'
44
import { tmpdir } from "os";
5+
import { valid as validSemver } from "semver";
56

67
export const MIN_SUPPORTED_MYSQL = '8.0.20';
78

@@ -34,6 +35,10 @@ export const LOG_LEVELS = {
3435
export const INTERNAL_OPTIONS = ['_DO_NOT_USE_deleteDBAfterStopped', '_DO_NOT_USE_dbPath', '_DO_NOT_USE_binaryDirectoryPath'] as const;
3536

3637
export const OPTION_TYPE_CHECKS: OptionTypeChecks = {
38+
version: {
39+
check: (opt: any) => typeof opt === 'string' && validSemver(opt) !== null,
40+
errorMessage: 'Option version must be a valid semver string.'
41+
},
3742
dbName: {
3843
check: (opt: any) => typeof opt === 'string' && opt.length <= 64,
3944
errorMessage: 'Option dbName must be a string and must not be longer than 64 characters.'

types/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export type BinaryInfo = {
7979
}
8080

8181
export type OptionTypeChecks = {
82-
[key in keyof ServerOptions]: {
82+
[key in keyof Required<ServerOptions>]: {
8383
check: (opt: any) => boolean,
8484
errorMessage: string
8585
}

0 commit comments

Comments
 (0)