/** * The session storage module provides apis for storing session data. * * "app.session.enable" must be set to true in order for these apis to work, * they fail silently otherwise. */ /** imports */ import * as express from 'express'; import { Future } from '@quenk/noni/lib/control/monad/future'; import { Object, Value } from '@quenk/noni/lib/data/jsonx'; import { Maybe } from '@quenk/noni/lib/data/maybe'; import { Storage } from './'; export declare const SESSION_DATA = "tendril.$data"; export declare const SESSION_DESCRIPTORS = "tendril.$descriptors"; /** * Descriptor is the internal configuration of a session property. * * The settings specified here have an impact no the treatment of the session * property. */ export interface Descriptor { /** * ttl if set is the number of requests a session value should be retained * for. When this reaches zero the propety will be automatically removed. */ ttl?: number; } /** * SessionStorage acts as a bridge between the tendril applications and * the underlying express session store API. */ export interface SessionStorage extends Storage { /** * isEnabled returns true if session storage is enabled, false otherwise. */ isEnabled(): boolean; /** * setWithDescriptor sets the value of a key in session storage along with * a descriptor. */ setWithDescriptor(key: string, value: Value, desc: Descriptor): SessionStorage; /** * save the session data. * * Call this method to immediately persist any data written to the session. */ save(): Future; /** * regenerate the session. * * This hooks into the lower level API to invalidate the current session id * supplied by the client and issue a new one. All data stored in the * session will be lost, including data not set through this API. */ regenerate(): Future; /** * destroy the session. * * Everything comes to an end here. */ destroy(): Future; } /** * @private */ export declare class DisabledSessionStorage implements SessionStorage { warn(method: string): void; isEnabled(): boolean; get(_key: string): Maybe; getOrElse(_key: string, alt: Value): Value; getAll(): Object; exists(_key: string): boolean; set(_key: string, _value: Value): DisabledSessionStorage; setWithDescriptor(_key: string, _value: Value, _desc: Descriptor): DisabledSessionStorage; remove(_: string): DisabledSessionStorage; reset(): DisabledSessionStorage; save(): Future; regenerate(): Future; destroy(): Future; } /** * EnabledSessionStorage class. */ export declare class EnabledSessionStorage implements SessionStorage { data: Object; /** * @private */ constructor(data: Object); /** * fromExpress constructs a SessionStorage instance from an express * Request. * * If session support is not enabled, a DisabledSessionStorage will be * provided instead. */ static fromExpress(r: express.Request): SessionStorage; /** * @private */ target(): Object; /** * @private */ descriptors(): Object; isEnabled(): boolean; get(key: string): Maybe; getOrElse(key: string, alt: Value): Value; getAll(): Object; exists(key: string): boolean; set(key: string, value: Value): EnabledSessionStorage; setWithDescriptor(key: string, value: Value, desc: Descriptor): EnabledSessionStorage; remove(key: string): EnabledSessionStorage; reset(): EnabledSessionStorage; save(): Future; regenerate(): Future; destroy(): Future; } /** * @private */ export declare const getSessionValue: (session: Object, key: string) => Maybe; /** * @private */ export declare const getSessionValueAsString: (session: Object, key: string) => string; /** * @private */ export declare const getSessionValueOrElse: (session: Object, key: string, other: Value) => Value; /** * @private */ export declare const setSessionValue: (session: Object, key: string, value: Value, desc: Descriptor) => void; /** * @private */ export declare const deleteSessionKey: (session: Object, key: string) => void;