@eryx/http/ServerSession Module

Summary

Functions

SessionMethods:get(key: string)any
SessionMethods:set(key: string, value: any)()
SessionMethods:delete(key: string)()
SessionMethods:clear()()
SessionMethods:regenerate()string
SessionMethods:destroy()()
MemoryStoreMethods:get(id: string)SessionRecord?
MemoryStoreMethods:set(id: string, data: { [string]: any }, expiresAt: number?)()
MemoryStoreMethods:delete(id: string)()
MemoryStoreMethods:touch(id: string, expiresAt: number?)()
FileStoreMethods:_pathFor(id: string)string
FileStoreMethods:get(id: string)SessionRecord?
FileStoreMethods:set(id: string, data: { [string]: any }, expiresAt: number?)()
FileStoreMethods:delete(id: string)()
FileStoreMethods:touch(id: string, expiresAt: number?)()
SqliteStoreMethods:get(id: string)SessionRecord?
SqliteStoreMethods:set(id: string, data: { [string]: any }, expiresAt: number?)()
SqliteStoreMethods:delete(id: string)()
SqliteStoreMethods:touch(id: string, expiresAt: number?)()
ServerSession.sqliteStore(database: string | SqliteDatabase, tableName: string?)SessionStore
ServerSession.middleware(options: SessionOptions?)((ctx: any, next: (() → any)) → any)

API Reference

Functions

SessionMethods:get

SessionMethods:get(key: string)any

SessionMethods:set

SessionMethods:set(key: string, value: any)()

SessionMethods:delete

SessionMethods:delete(key: string)()

SessionMethods:clear

SessionMethods:clear()()

SessionMethods:regenerate

SessionMethods:regenerate()string

SessionMethods:destroy

SessionMethods:destroy()()

MemoryStoreMethods:get

MemoryStoreMethods:get(id: string)SessionRecord?

MemoryStoreMethods:set

MemoryStoreMethods:set(id: string, data: { [string]: any }, expiresAt: number?)()

MemoryStoreMethods:delete

MemoryStoreMethods:delete(id: string)()

MemoryStoreMethods:touch

MemoryStoreMethods:touch(id: string, expiresAt: number?)()

FileStoreMethods:_pathFor

FileStoreMethods:_pathFor(id: string)string

FileStoreMethods:get

FileStoreMethods:get(id: string)SessionRecord?

FileStoreMethods:set

FileStoreMethods:set(id: string, data: { [string]: any }, expiresAt: number?)()

FileStoreMethods:delete

FileStoreMethods:delete(id: string)()

FileStoreMethods:touch

FileStoreMethods:touch(id: string, expiresAt: number?)()

SqliteStoreMethods:get

SqliteStoreMethods:get(id: string)SessionRecord?

SqliteStoreMethods:set

SqliteStoreMethods:set(id: string, data: { [string]: any }, expiresAt: number?)()

SqliteStoreMethods:delete

SqliteStoreMethods:delete(id: string)()

SqliteStoreMethods:touch

SqliteStoreMethods:touch(id: string, expiresAt: number?)()

ServerSession.memoryStore

Creates an in-memory session store.

ServerSession.memoryStore()SessionStore

Returns

SessionStore

ServerSession.fileStore

Creates a filesystem-backed session store where each session is stored as JSON.

ServerSession.fileStore(directory: string)SessionStore

Parameters

directory: string

Directory used for session files.

Returns

SessionStore

ServerSession.sqliteStore

Creates an SQLite-backed session store.

ServerSession.sqliteStore(database: string | SqliteDatabase, tableName: string?)SessionStore

Parameters

database: string | SqliteDatabase

Either a path string or an open @eryx/sqlite3 database.

tableName: string?

Optional table name. Defaults to "http_sessions".

Returns

SessionStore

ServerSession.middleware

Creates app middleware that attaches a server-side session to ctx.session.

The middleware loads the session from a cookie before the handler runs and persists it back to the configured store after the handler completes.

ServerSession.middleware(options: SessionOptions?)((ctx: any, next: (() → any)) → any)

Parameters

options: SessionOptions?

Session configuration and backing store.

Returns

((ctx: any, next: (() → any)) → any)

(ctx: any, next: () -> any) -> any

Types

SessionRecord

type SessionRecord = { data: { [string]: any }, expiresAt: number? }
data: { [string]: any }
expiresAt: number?

SessionStore

type SessionStore = { get: ((self: SessionStore, id: string) → SessionRecord?), set: ( self: SessionStore, id: string, data: { [string]: any }, expiresAt: number? )(), delete: ((self: SessionStore, id: string) → ()), touch: (((self: SessionStore, id: string, expiresAt: number?) → ()))? }
SessionStore:get(id: string)SessionRecord?
SessionStore:set(id: string, data: { [string]: any }, expiresAt: number?)()
SessionStore:delete(id: string)()
touch: (((self: SessionStore, id: string, expiresAt: number?) → ()))?

SessionCookieOptions

type SessionCookieOptions = { path: string?, domain: string?, secure: boolean?, httpOnly: boolean?, sameSite: "Strict" | "Lax" | "None"? }
path: string?
domain: string?
secure: boolean?
httpOnly: boolean?
sameSite: "Strict" | "Lax" | "None"?

SessionOptions

type SessionOptions = { store: SessionStore?, cookieName: string?, ttl: number?, rolling: boolean?, cookie: SessionCookieOptions? }
store: SessionStore?
cookieName: string?
ttl: number?
rolling: boolean?

Session

type Session = { id: string?, data: { [string]: any }, isNew: boolean, destroyed: boolean, get: ((self: Session, key: string) → any), set: ((self: Session, key: string, value: any) → ()), delete: ((self: Session, key: string) → ()), clear: ((self: Session) → ()), regenerate: ((self: Session) → string), destroy: ((self: Session) → ()) }
Session:get(key: string)any

Returns a value from the session data table.

Session:set(key: string, value: any)()

Sets a value and marks the session dirty for persistence.

Session:delete(key: string)()

Removes a value and marks the session dirty.

Session:clear()()

Clears all session data.

Session:regenerate()string

Assigns a fresh session id and preserves the current data.

Session:destroy()()

Deletes the session from the backing store and clears the cookie.

id: string?
data: { [string]: any }
isNew: boolean
destroyed: boolean