Setup eslint and enforce rules
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import {NoSessionKeyError, Session, SessionData, SessionNotLoadedError} from "./Session";
|
||||
import {Injectable} from "../../di";
|
||||
import {NoSessionKeyError, Session, SessionData, SessionNotLoadedError} from './Session'
|
||||
import {Injectable} from '../../di'
|
||||
|
||||
/**
|
||||
* Implementation of the session driver that stores session data in memory.
|
||||
@@ -31,44 +31,66 @@ export class MemorySession extends Session {
|
||||
/** The associated data for this session. */
|
||||
protected data?: SessionData
|
||||
|
||||
constructor() { super() }
|
||||
constructor() {
|
||||
super()
|
||||
}
|
||||
|
||||
public getKey(): string {
|
||||
if ( !this.sessionID ) throw new NoSessionKeyError()
|
||||
if ( !this.sessionID ) {
|
||||
throw new NoSessionKeyError()
|
||||
}
|
||||
return this.sessionID
|
||||
}
|
||||
|
||||
public setKey(key: string) {
|
||||
public setKey(key: string): void {
|
||||
this.sessionID = key
|
||||
}
|
||||
|
||||
public load() {
|
||||
if ( !this.sessionID ) throw new NoSessionKeyError()
|
||||
public load(): void {
|
||||
if ( !this.sessionID ) {
|
||||
throw new NoSessionKeyError()
|
||||
}
|
||||
|
||||
this.data = MemorySession.getSession(this.sessionID)
|
||||
}
|
||||
|
||||
public persist() {
|
||||
if ( !this.sessionID ) throw new NoSessionKeyError()
|
||||
if ( !this.data ) throw new SessionNotLoadedError()
|
||||
public persist(): void {
|
||||
if ( !this.sessionID ) {
|
||||
throw new NoSessionKeyError()
|
||||
}
|
||||
|
||||
if ( !this.data ) {
|
||||
throw new SessionNotLoadedError()
|
||||
}
|
||||
|
||||
MemorySession.setSession(this.sessionID, this.data)
|
||||
}
|
||||
|
||||
public getData(): SessionData {
|
||||
if ( !this.data ) throw new SessionNotLoadedError()
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user