You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
980 B
40 lines
980 B
3 years ago
|
import {Injectable, Inject} from "@extollo/di"
|
||
|
import {ErrorWithContext} from "@extollo/util"
|
||
|
import {Request} from "../lifecycle/Request"
|
||
|
|
||
|
export type SessionData = {[key: string]: any}
|
||
|
|
||
|
export class NoSessionKeyError extends ErrorWithContext {
|
||
|
constructor() {
|
||
|
super('No session ID has been set.')
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export class SessionNotLoadedError extends ErrorWithContext {
|
||
|
constructor() {
|
||
|
super('Cannot access session data; data is not loaded.')
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@Injectable()
|
||
|
export abstract class Session {
|
||
|
@Inject()
|
||
|
protected readonly request!: Request
|
||
|
|
||
|
public abstract getKey(): string
|
||
|
|
||
|
public abstract setKey(key: string): void
|
||
|
|
||
|
public abstract load(): void | Promise<void>
|
||
|
|
||
|
public abstract persist(): void | Promise<void>
|
||
|
|
||
|
public abstract getData(): SessionData
|
||
|
|
||
|
public abstract setData(data: SessionData): void
|
||
|
|
||
|
public abstract get(key: string, fallback?: any): any
|
||
|
|
||
|
public abstract set(key: string, value: any): void
|
||
|
}
|