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,12 +1,13 @@
import {Model} from "../model/Model";
import {Field} from "../model/Field";
import {FieldType} from "../types";
import {Model} from '../model/Model'
import {Field} from '../model/Field'
import {FieldType} from '../types'
/**
* A model instance which stores records from the ORMCache driver.
*/
export class CacheModel extends Model<CacheModel> {
protected static table = 'caches'; // FIXME allow configuring
protected static key = 'cache_key';
@Field(FieldType.varchar, 'cache_key')

View File

@@ -1,6 +1,6 @@
import {Container} from "../../di"
import {Cache} from "../../util"
import {CacheModel} from "./CacheModel"
import {Container} from '../../di'
import {Cache} from '../../util'
import {CacheModel} from './CacheModel'
/**
* A cache driver whose records are stored in a database table using the CacheModel.

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
}
}

View File

@@ -1,12 +1,13 @@
import {Model} from "../model/Model";
import {Field} from "../model/Field";
import {FieldType} from "../types";
import {Model} from '../model/Model'
import {Field} from '../model/Field'
import {FieldType} from '../types'
/**
* Model used to fetch & store sessions from the ORMSession driver.
*/
export class SessionModel extends Model<SessionModel> {
protected static table = 'sessions'; // FIXME allow configuring
protected static key = 'session_uuid';
@Field(FieldType.varchar, 'session_uuid')