Setup eslint and enforce rules
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2021-06-02 22:36:25 -05:00
parent 82e7a1f299
commit 1d5056b753
149 changed files with 6104 additions and 3114 deletions

View File

@@ -1,16 +1,16 @@
import {Unit} from "../lifecycle/Unit"
import {Inject, Singleton} from "../di"
import {Config} from "./Config"
import {Logging} from "./Logging"
import {Filesystem, ErrorWithContext} from "../util"
import {Unit} from '../lifecycle/Unit'
import {Inject, Singleton} from '../di'
import {Config} from './Config'
import {Logging} from './Logging'
import {Filesystem, ErrorWithContext} from '../util'
/**
* Error thrown when a function is called on a filesystem that does not exists in code.
*/
export class FilesystemDoesNotExist extends ErrorWithContext {
constructor(
message: string = 'The specified filesystem does not exist.',
context: {[key: string]: any} = {}
message = 'The specified filesystem does not exist.',
context: {[key: string]: any} = {},
) {
super(message, context)
}
@@ -57,6 +57,7 @@ export class FilesystemDoesNotExist extends ErrorWithContext {
@Singleton()
export class Files extends Unit {
protected filesystems: {[key: string]: Filesystem} = {}
protected defaultFilesystem?: Filesystem
@Inject()
@@ -65,11 +66,14 @@ export class Files extends Unit {
@Inject()
protected readonly logging!: Logging
async up() {
async up(): Promise<void> {
const config = this.config.get('server.filesystems', {})
const promises = []
for ( const key in config ) {
if ( !config.hasOwnProperty(key) ) continue;
if ( !Object.prototype.hasOwnProperty.call(config, key) ) {
continue
}
if ( config[key]?.driver?.prototype instanceof Filesystem ) {
this.logging.verbose(`Registering filesystem '${key}' with driver ${config[key].driver.name}...`)
@@ -108,7 +112,7 @@ export class Files extends Unit {
}
}
async down() {
async down(): Promise<void> {
await Promise.all(Object.values(this.filesystems).map(fs => fs.close()))
}
@@ -116,12 +120,12 @@ export class Files extends Unit {
* Returns true if a filesystem with the given name exists.
* @param key
*/
hasFilesystem(key?: string) {
hasFilesystem(key?: string): boolean {
if ( !key ) {
return !!this.defaultFilesystem
return Boolean(this.defaultFilesystem)
}
return !!this.filesystems[key]
return Boolean(this.filesystems[key])
}
/**
@@ -149,7 +153,7 @@ export class Files extends Unit {
* @param key
* @param fs
*/
registerFilesystem(key: string, fs: Filesystem) {
registerFilesystem(key: string, fs: Filesystem): void {
if ( this.hasFilesystem(key) ) {
this.logging.warn(`Overwriting filesystem with duplicate name: ${key}`)
}