11import { blue , bold , white } from "@std/fmt/colors" ;
2- import { ConsoleHandler , getLogger , LevelName } from "@std/log" ;
2+ import { ConsoleHandler , getLogger , type LevelName , type Logger } from "@std/log" ;
33import { DDL } from "./ddl.ts" ;
4- import { Class , Identifiable , Parameter , Row , Schema } from "./types.ts" ;
4+ import type { Class , Identifiable , Parameter , Row , Schema } from "./types.ts" ;
55import { Repository } from "./repository.ts" ;
66
77const TTY = Deno . stderr . isTerminal ( ) ;
@@ -161,16 +161,16 @@ export class DB {
161161 static readonly ALL = Number . MAX_SAFE_INTEGER ;
162162 static client : Client ;
163163 static debug = false ;
164- static schemas = new Map < string , Schema > ( ) ;
164+ static # schemas = new Map < string , Schema > ( ) ;
165165 static type : string ;
166166 static capacity = this . DEFAULT_CAPACITY ;
167167
168- static get logger ( ) {
168+ static get logger ( ) : Logger {
169169 return this . mainLogger ( ) ;
170170 }
171171
172172 // Get parent logger and if the logger has not been set, it will add a handler and level
173- static mainLogger ( level : LevelName = "INFO" ) {
173+ static mainLogger ( level : LevelName = "INFO" ) : Logger {
174174 const logger = getLogger ( "gateways" ) ;
175175 if ( logger . handlers . length === 0 ) logger . handlers . push ( new ConsoleHandler ( "DEBUG" ) ) ;
176176 const debug = Deno . env . get ( "DEBUG" ) ?. includes ( logger . loggerName ) || this . debug ;
@@ -190,8 +190,8 @@ export class DB {
190190
191191 // Iterate over the schemas and map them by name and type if it exists
192192 schemas ?. forEach ( ( s ) => {
193- DB . schemas . set ( s . name , s ) ;
194- if ( s . type ) DB . schemas . set ( s . type , s ) ;
193+ DB . # schemas. set ( s . name , s ) ;
194+ if ( s . type ) DB . # schemas. set ( s . type , s ) ;
195195 } ) ;
196196 if ( DB . client ) return Promise . resolve ( DB . client ) ;
197197 DB . type = config . type ;
@@ -251,7 +251,7 @@ export class DB {
251251 }
252252 }
253253
254- static execute ( sql : string , parameters ?: Parameter [ ] | { [ key : string ] : Parameter } , debug ?: boolean ) {
254+ static execute ( sql : string , parameters ?: Parameter [ ] | { [ key : string ] : Parameter } , debug ?: boolean ) : Promise < { affectedRows ?: number ; lastInsertId ?: number } > {
255255 // If values are not an array, they need to be transformed (as well as the SQL)
256256 const arrayParameters : Parameter [ ] = [ ] ;
257257 if ( parameters && ! Array . isArray ( parameters ) ) {
@@ -285,21 +285,21 @@ export class DB {
285285 }
286286
287287 // Repository cache
288- static repositories = new Map < string | Class < Identifiable > , Repository < Identifiable > > ( ) ;
288+ static # repositories = new Map < string | Class < Identifiable > , Repository < Identifiable > > ( ) ;
289289
290290 // deno-lint-ignore no-explicit-any
291291 static getRepository ( tableName : string ) : Repository < any > ;
292292 static getRepository < T extends Identifiable > ( target : Class < T > ) : Repository < T > ;
293293 static getRepository < T extends Identifiable > ( target : string | Class < T > , schema ?: Schema ) : Repository < T > {
294- let repository = this . repositories . get ( target ) as Repository < T > ;
294+ let repository = this . # repositories. get ( target ) as Repository < T > ;
295295 if ( repository ) return repository ;
296296
297297 // Figure out target, schema and name
298298 const name = typeof target === "string" ? target : target . name ;
299299 if ( typeof target === "string" ) target = Object as unknown as Class < T > ;
300- if ( ! schema ) schema = DB . schemas . get ( name ) ;
300+ if ( ! schema ) schema = DB . # schemas. get ( name ) ;
301301 repository = new Repository ( target , schema , schema ?. name ?? name , this . capacity ) ;
302- this . repositories . set ( target , repository as Repository < Identifiable > ) ;
302+ this . # repositories. set ( target , repository as Repository < Identifiable > ) ;
303303
304304 // Return repository
305305 return repository ;
0 commit comments