@eryx/http/ServerSession Module

JSON

Summary

Classes

touch: (((self: SessionStore, id: string, expiresAt: number?) → ()))?
SessionStore:set(id: string, data: { [string]: any }, expiresAt: number?)()
SessionStore:delete(id: string)()
id: string?
data: { [string]: any }
isNew: boolean
destroyed: boolean
Session:get(key: string)any
Session:set(key: string, value: any)()
Session:delete(key: string)()
Session:clear()()
Session:regenerate()string

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.fileStore(directory: string)SessionStore
ServerSession.sqliteStore(database: string | sqlite3.Database, tableName: string?)SessionStore
ServerSession.middleware(options: SessionOptions?)((ctx: any, next: (() → any)) → any)

API Reference

Classes

SessionStore

Properties

touch: (((self: SessionStore, id: string, expiresAt: number?) → ()))?

SessionStore:get

SessionStore:get(id: string)SessionRecord?

SessionStore:set

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

SessionStore:delete

SessionStore:delete(id: string)()

Session

Properties

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

Session:get

Returns a value from the session data table.

Session:get(key: string)any

Session:set

Sets a value and marks the session dirty for persistence.

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

Session:delete

Removes a value and marks the session dirty.

Session:delete(key: string)()

Session:clear

Clears all session data.

Session:clear()()

Session:regenerate

Assigns a fresh session id and preserves the current data.

Session:regenerate()string

Session:destroy

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

Session:destroy()()

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 | sqlite3.Database, tableName: string?)SessionStore

Parameters

database: string | sqlite3.Database

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

data: { [string]: any }
expiresAt: number?

SessionCookieOptions

path: string?
domain: string?
secure: boolean?
httpOnly: boolean?
sameSite: "Strict" | "Lax" | "None"?

SessionOptions

store: SessionStore?
cookieName: string?
ttl: number?
rolling: boolean?