33 */
44
55import { SQLiteCloudConfig , SQLiteCloudError , ErrorCallback , ResultsCallback } from './types'
6- import { parseConnectionString , parseBoolean , isBrowser } from './utilities'
7-
8- /** Default timeout value for queries */
9- export const DEFAULT_TIMEOUT = 300 * 1000
10- /** Default tls connection port */
11- export const DEFAULT_PORT = 9960
6+ import { validateConfiguration , isBrowser } from './utilities'
127
138/**
149 * Base class for SQLiteCloudConnection handles basics and defines methods.
@@ -18,9 +13,9 @@ export class SQLiteCloudConnection {
1813 /** Parse and validate provided connectionString or configuration */
1914 constructor ( config : SQLiteCloudConfig | string , callback ?: ErrorCallback ) {
2015 if ( typeof config === 'string' ) {
21- this . config = this . validateConfiguration ( { connectionString : config } )
16+ this . config = validateConfiguration ( { connectionString : config } )
2217 } else {
23- this . config = this . validateConfiguration ( config )
18+ this . config = validateConfiguration ( config )
2419 }
2520
2621 // connect transport layer to server
@@ -93,41 +88,6 @@ export class SQLiteCloudConnection {
9388 // private methods
9489 //
9590
96- /** Validate configuration, apply defaults, throw if something is missing or misconfigured */
97- protected validateConfiguration ( config : SQLiteCloudConfig ) : SQLiteCloudConfig {
98- if ( config . connectionString ) {
99- config = {
100- ...config ,
101- ...parseConnectionString ( config . connectionString ) ,
102- connectionString : config . connectionString // keep original connection string
103- }
104- }
105-
106- // apply defaults where needed
107- config . port ||= DEFAULT_PORT
108- config . timeout = config . timeout && config . timeout > 0 ? config . timeout : DEFAULT_TIMEOUT
109- config . clientId ||= 'SQLiteCloud'
110-
111- config . verbose = parseBoolean ( config . verbose )
112- config . noBlob = parseBoolean ( config . noBlob )
113- config . compression = parseBoolean ( config . compression )
114- config . createDatabase = parseBoolean ( config . createDatabase )
115- config . nonlinearizable = parseBoolean ( config . nonlinearizable )
116-
117- if ( ! config . username || ! config . password || ! config . host ) {
118- console . error ( 'SQLiteCloudConnection.validateConfiguration - missing arguments' , config )
119- throw new SQLiteCloudError ( 'The user, password and host arguments must be specified.' , { errorCode : 'ERR_MISSING_ARGS' } )
120- }
121-
122- if ( ! config . connectionString ) {
123- // build connection string from configuration, values are already validated
124- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
125- config . connectionString = `sqlitecloud://${ config . username } :${ config . password } @${ config . host } :${ config . port } /${ config . database } `
126- }
127-
128- return config
129- }
130-
13191 /** Will log to console if verbose mode is enabled */
13292 protected log ( message : string , ...optionalParams : any [ ] ) : void {
13393 if ( this . config . verbose ) {
0 commit comments