Skip to content

Commit

Permalink
refactor: remove _ prefix from all private properties
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Jan 12, 2020
1 parent 2785397 commit c925b45
Show file tree
Hide file tree
Showing 25 changed files with 278 additions and 339 deletions.
8 changes: 7 additions & 1 deletion adonis-typings/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ declare module '@ioc:Adonis/Lucid/Database' {
*/
export interface DialectContract {
readonly name: string
supportsAdvisoryLocks: boolean
readonly supportsAdvisoryLocks: boolean
getAdvisoryLock (key: string | number, timeout?: number): Promise<boolean>
releaseAdvisoryLock (key: string | number): Promise<boolean>
}
Expand Down Expand Up @@ -155,6 +155,12 @@ declare module '@ioc:Adonis/Lucid/Database' {
* Get instance of transaction client
*/
transaction (): Promise<TransactionClientContract>,

/**
* Work with advisory locks
*/
getAdvisoryLock (key: string | number, timeout?: number): Promise<boolean>
releaseAdvisoryLock (key: string | number): Promise<boolean>
}

/**
Expand Down
2 changes: 1 addition & 1 deletion adonis-typings/migrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
*/

declare module '@ioc:Adonis/Lucid/Migrator' {
import { SchemaConstructorContract } from '@ioc:Adonis/Lucid/Schema'
import { EventEmitter } from 'events'
import { SchemaConstructorContract } from '@ioc:Adonis/Lucid/Schema'

/**
* Migration node returned by the migration source
Expand Down
90 changes: 0 additions & 90 deletions adonis-typings/model.txt

This file was deleted.

4 changes: 4 additions & 0 deletions src/Connection/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

import { LoggerContract } from '@ioc:Adonis/Core/Logger'

/**
* Custom knex logger that uses adonisjs logger under the
* hood.
*/
export class Logger {
public warn = function (message: any) {
this.adonisLogger.warn(message)
Expand Down
25 changes: 13 additions & 12 deletions src/Connection/Manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ export class ConnectionManager extends EventEmitter implements ConnectionManager
* Connections for which the config was patched. They must get removed
* overtime, unless application is behaving unstable.
*/
private _orphanConnections: Set<ConnectionContract> = new Set()
private orphanConnections: Set<ConnectionContract> = new Set()

constructor (private _logger: LoggerContract) {
constructor (private logger: LoggerContract) {
super()
}

/**
* Monitors a given connection by listening for lifecycle events
*/
private _monitorConnection (connection: ConnectionContract): void {
private monitorConnection (connection: ConnectionContract): void {
/**
* Listens for disconnect to set the connection state and cleanup
* memory
Expand All @@ -54,11 +54,11 @@ export class ConnectionManager extends EventEmitter implements ConnectionManager
* We received the close event on the orphan connection and not the connection
* that is in use
*/
if (this._orphanConnections.has($connection)) {
this._orphanConnections.delete($connection)
if (this.orphanConnections.has($connection)) {
this.orphanConnections.delete($connection)

this.emit('disconnect', $connection)
this._logger.trace({ connection: $connection.name }, 'disconnecting connection inside manager')
this.logger.trace({ connection: $connection.name }, 'disconnecting connection inside manager')
return
}

Expand All @@ -73,7 +73,7 @@ export class ConnectionManager extends EventEmitter implements ConnectionManager
}

this.emit('disconnect', $connection)
this._logger.trace({ connection: $connection.name }, 'disconnecting connection inside manager')
this.logger.trace({ connection: $connection.name }, 'disconnecting connection inside manager')

delete internalConnection.connection
internalConnection.state = 'closed'
Expand Down Expand Up @@ -113,7 +113,7 @@ export class ConnectionManager extends EventEmitter implements ConnectionManager
return
}

this._logger.trace({ connection: connectionName }, 'adding new connection to the manager')
this.logger.trace({ connection: connectionName }, 'adding new connection to the manager')
this.connections.set(connectionName, {
name: connectionName,
config: config,
Expand Down Expand Up @@ -144,8 +144,8 @@ export class ConnectionManager extends EventEmitter implements ConnectionManager
/**
* Create a new connection and monitor it's state
*/
connection.connection = new Connection(connection.name, connection.config, this._logger)
this._monitorConnection(connection.connection)
connection.connection = new Connection(connection.name, connection.config, this.logger)
this.monitorConnection(connection.connection)
connection.connection.connect()
}

Expand All @@ -168,12 +168,13 @@ export class ConnectionManager extends EventEmitter implements ConnectionManager
* they cleanup after some time
*/
if (connection.connection) {
this._orphanConnections.add(connection.connection)
this.orphanConnections.add(connection.connection)
connection.connection.disconnect()
}

/**
* Updating config and state. Next call to connect will use this
* Updating config and state. Next call to connect will use the
* new config
*/
connection.state = 'migrating'
connection.config = config
Expand Down
Loading

0 comments on commit c925b45

Please sign in to comment.