1- const CONSTANTS = {
2- MIN_SUPPORTED_MYSQL : '8.0.20'
3- }
1+ import { InternalServerOptions , OptionTypeChecks } from "../types" ;
2+ import { randomUUID } from "crypto" ;
3+ import { normalize as normalizePath } from 'path'
4+ import { tmpdir } from "os" ;
5+ import { valid as validSemver } from "semver" ;
46
5- export default CONSTANTS
7+ export const MIN_SUPPORTED_MYSQL = '8.0.20' ;
8+
9+ export const DEFAULT_OPTIONS_GENERATOR : ( ) => InternalServerOptions = ( ) => ( {
10+ version : undefined ,
11+ dbName : 'dbdata' ,
12+ logLevel : 'ERROR' ,
13+ portRetries : 10 ,
14+ downloadBinaryOnce : true ,
15+ lockRetries : 1_000 ,
16+ lockRetryWait : 1_000 ,
17+ username : 'root' ,
18+ ignoreUnsupportedSystemVersion : false ,
19+ port : 0 ,
20+ xPort : 0 ,
21+ downloadRetries : 10 ,
22+ initSQLString : '' ,
23+ _DO_NOT_USE_deleteDBAfterStopped : true ,
24+ //mysqlmsn = MySQL Memory Server Node.js
25+ _DO_NOT_USE_dbPath : normalizePath ( `${ tmpdir ( ) } /mysqlmsn/dbs/${ randomUUID ( ) . replace ( / - / g, '' ) } ` ) ,
26+ _DO_NOT_USE_binaryDirectoryPath : `${ tmpdir ( ) } /mysqlmsn/binaries`
27+ } ) ;
28+
29+ export const DEFAULT_OPTIONS_KEYS = Object . freeze ( Object . keys ( DEFAULT_OPTIONS_GENERATOR ( ) ) )
30+
31+ export const LOG_LEVELS = {
32+ 'LOG' : 0 ,
33+ 'WARN' : 1 ,
34+ 'ERROR' : 2
35+ } as const ;
36+
37+ export const INTERNAL_OPTIONS = [ '_DO_NOT_USE_deleteDBAfterStopped' , '_DO_NOT_USE_dbPath' , '_DO_NOT_USE_binaryDirectoryPath' ] as const ;
38+
39+ export const OPTION_TYPE_CHECKS : OptionTypeChecks = {
40+ version : {
41+ check : ( opt : any ) => opt === undefined || typeof opt === 'string' && validSemver ( opt ) !== null ,
42+ errorMessage : 'Option version must be either undefined or a valid semver string.'
43+ } ,
44+ dbName : {
45+ check : ( opt : any ) => opt === undefined || typeof opt === 'string' && opt . length <= 64 ,
46+ errorMessage : 'Option dbName must be either undefined or a string that is not longer than 64 characters.'
47+ } ,
48+ logLevel : {
49+ check : ( opt : any ) => opt === undefined || Object . keys ( LOG_LEVELS ) . includes ( opt ) ,
50+ errorMessage : 'Option logLevel must be either undefined or "LOG", "WARN", or "ERROR".'
51+ } ,
52+ portRetries : {
53+ check : ( opt : any ) => opt === undefined || typeof opt === 'number' && opt >= 0 ,
54+ errorMessage : 'Option portRetries must be either undefined, a positive number, or 0.'
55+ } ,
56+ downloadBinaryOnce : {
57+ check : ( opt : any ) => opt === undefined || typeof opt === 'boolean' ,
58+ errorMessage : 'Option downloadBinaryOnce must be either undefined or a boolean.'
59+ } ,
60+ lockRetries : {
61+ check : ( opt : any ) => opt === undefined || typeof opt === 'number' && opt >= 0 ,
62+ errorMessage : 'Option lockRetries must be either undefined, a positive number, or 0.'
63+ } ,
64+ lockRetryWait : {
65+ check : ( opt : any ) => opt === undefined || typeof opt === 'number' && opt >= 0 ,
66+ errorMessage : 'Option lockRetryWait must be either undefined, a positive number, or 0.'
67+ } ,
68+ username : {
69+ check : ( opt : any ) => opt === undefined || typeof opt === 'string' && opt . length <= 32 ,
70+ errorMessage : 'Option username must be either undefined or a string that is not longer than 32 characters.'
71+ } ,
72+ ignoreUnsupportedSystemVersion : {
73+ check : ( opt : any ) => opt === undefined || typeof opt === 'boolean' ,
74+ errorMessage : 'Option ignoreUnsupportedSystemVersion must be either undefined or a boolean.'
75+ } ,
76+ port : {
77+ check : ( opt : any ) => opt === undefined || typeof opt === 'number' && opt >= 0 && opt <= 65535 ,
78+ errorMessage : 'Option port must be either undefined or a number that is between 0 and 65535 inclusive.'
79+ } ,
80+ xPort : {
81+ check : ( opt : any ) => opt === undefined || typeof opt === 'number' && opt >= 0 && opt <= 65535 ,
82+ errorMessage : 'Option xPort must be either undefined or a number that is between 0 and 65535 inclusive.'
83+ } ,
84+ downloadRetries : {
85+ check : ( opt : any ) => opt === undefined || typeof opt === 'number' && opt >= 0 ,
86+ errorMessage : 'Option downloadRetries must be either undefined, a positive number, or 0.'
87+ } ,
88+ initSQLString : {
89+ check : ( opt : any ) => opt === undefined || typeof opt === 'string' ,
90+ errorMessage : 'Option initSQLString must be either undefined or a string.'
91+ } ,
92+ _DO_NOT_USE_deleteDBAfterStopped : {
93+ check : ( opt : any ) => opt === undefined || typeof opt === 'boolean' ,
94+ errorMessage : 'Option _DO_NOT_USE_deleteDBAfterStopped must be either undefined or a boolean.'
95+ } ,
96+ _DO_NOT_USE_dbPath : {
97+ check : ( opt : any ) => opt === undefined || typeof opt === 'string' ,
98+ errorMessage : 'Option _DO_NOT_USE_dbPath must be either undefined or a string.'
99+ } ,
100+ _DO_NOT_USE_binaryDirectoryPath : {
101+ check : ( opt : any ) => opt === undefined || typeof opt === 'string' ,
102+ errorMessage : 'Option _DO_NOT_USE_binaryDirectoryPath must be either undefined or a string.'
103+ }
104+ } as const ;
0 commit comments