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