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,13 +1,15 @@
import {SessionModel} from "./SessionModel"
import {Container} from "../../di"
import {NoSessionKeyError, Session, SessionData, SessionNotLoadedError} from "../../http/session/Session";
import {SessionModel} from './SessionModel'
import {Container} from '../../di'
import {NoSessionKeyError, Session, SessionData, SessionNotLoadedError} from '../../http/session/Session'
/**
* An implementation of the Session driver whose records are stored in a database table.
*/
export class ORMSession extends Session {
protected key?: string
protected data?: SessionData
protected session?: SessionModel
public getKey(): string {
@@ -22,7 +24,7 @@ export class ORMSession extends Session {
this.key = key
}
public async load() {
public async load(): Promise<void> {
if ( !this.key ) {
throw new NoSessionKeyError()
}
@@ -38,31 +40,41 @@ export class ORMSession extends Session {
}
}
public async persist() {
if ( !this.key ) throw new NoSessionKeyError()
if ( !this.data || !this.session ) throw new SessionNotLoadedError()
public async persist(): Promise<void> {
if ( !this.key ) {
throw new NoSessionKeyError()
}
if ( !this.data || !this.session ) {
throw new SessionNotLoadedError()
}
this.session.uuid = this.key
this.session.json = JSON.stringify(this.data)
await this.session.save()
}
public getData() {
if ( !this.data ) throw new SessionNotLoadedError()
public getData(): SessionData {
if ( !this.data ) {
throw new SessionNotLoadedError()
}
return this.data
}
public setData(data: SessionData) {
public setData(data: SessionData): void {
this.data = data
}
public get(key: string, fallback?: any): any {
if ( !this.data ) throw new SessionNotLoadedError()
public get(key: string, fallback?: unknown): any {
if ( !this.data ) {
throw new SessionNotLoadedError()
}
return this.data[key] ?? fallback
}
public set(key: string, value: any) {
if ( !this.data ) throw new SessionNotLoadedError()
public set(key: string, value: unknown): void {
if ( !this.data ) {
throw new SessionNotLoadedError()
}
this.data[key] = value
}
}