@sanpuru/prisma-session-store
Version:
Prisma express-session store
162 lines (161 loc) • 7.61 kB
TypeScript
/// <reference types="node" />
/// <reference types="express-session" />
/// <reference types="express-serve-static-core" />
/// <reference types="qs" />
/// <reference types="express" />
import type { PartialDeep } from 'type-fest';
import type { IOptions, IPrisma, ISession, ISessions } from '../@types';
import { ManagedLogger } from './logger';
declare const _default: (expressSession: ISession) => {
new (prisma: IPrisma, options: IOptions): {
readonly prisma: IPrisma;
readonly options: IOptions;
/**
* @description The currently active interval created with `startInterval()` and removed with `stopInterval()`
*/
checkInterval?: NodeJS.Timeout | undefined;
/**
* @description A flag indicating to use the session ID as the Prisma Record ID
*
* Note: If undefined and dbRecordIdFunction is also undefined then a random
* CUID will be used instead.
*/
readonly dbRecordIdIsSessionId: boolean | undefined;
/**
* @description whether or not the prisma connection has been tested to be invalid
*/
invalidConnection: boolean;
/**
* @description A object that handles logging to a given logger based on the logging level
*/
readonly logger: ManagedLogger;
/**
* @description Some serializer that will transform objects into strings
* and vice versa
*/
readonly serializer: import("../@types/serializer").ISerializer | JSON;
/**
* Fetch all sessions
*
* @param callback a callback providing all session data
* or an error that occurred
*/
readonly all: (callback?: ((err?: unknown, all?: ISessions | undefined) => void) | undefined) => Promise<void | ISessions>;
/**
* Delete all sessions from the store
*
* @param callback a callback notifying that all sessions
* were deleted or that an error occurred
*/
readonly clear: (callback?: ((err?: unknown) => void) | undefined) => Promise<void>;
/**
* Destroy the session associated with the given `sid`(s).
*
* @param sid a single or multiple id(s) to remove data for
* @param callback a callback notifying that the session(s) have
* been destroyed or that an error occurred
*/
readonly destroy: (sid: string | string[], callback?: ((err?: unknown) => void) | undefined) => Promise<void>;
/**
* Attempt to fetch session by the given `sid`.
*
* @param sid the sid to attempt to fetch
* @param callback a function to call with the results
*/
readonly get: (sid: string, callback?: ((err?: unknown, val?: Express.SessionData | undefined) => void) | undefined) => Promise<void | Express.SessionData>;
/**
* Fetch all sessions' ids
*
* @param callback a callback providing all session id
* or an error that occurred
*/
readonly ids: (callback?: ((err?: unknown, ids?: number[] | undefined) => void) | undefined) => Promise<void | string[]>;
/**
* Get the count of all sessions in the store
*
* @param callback a callback providing either the number of sessions
* or an error that occurred
*/
readonly length: (callback?: ((err?: unknown, length?: number | undefined) => void) | undefined) => Promise<number | void>;
/**
* Remove only expired entries from the store
*/
readonly prune: () => Promise<void>;
/**
* Commit the given `session` object associated with the given `sid`.
*
* @param sid the ID to save the session data under
* @param session the session data to save
* @param callback a callback with the results of saving the data
* or an error that occurred
*/
readonly set: (sid: string, session: PartialDeep<Express.SessionData>, callback?: ((err?: unknown) => void) | undefined) => Promise<void>;
/**
* A function to stop any ongoing intervals and disconnect from the `PrismaClient`
*/
shutdown(): Promise<void>;
/**
* Start an interval to prune expired sessions
*/
startInterval(): void;
/**
* Stop checking if sessions have expired
*/
stopInterval(): void;
/**
* Refresh the time-to-live for the session with the given `sid`.
*
* @param sid the id of the session to refresh
* @param session the data of the session to resave
* @param callback a callback notifying that the refresh was completed
* or that an error occurred
*/
readonly touch: (sid: string, session: PartialDeep<Express.SessionData>, callback?: ((err?: unknown) => void) | undefined) => Promise<void>;
/**
* Attempts to connect to Prisma, displaying a pretty error if the connection is not possible.
*/
connect(): Promise<void>;
/**
* @description A function to generate the Prisma Record ID for a given session ID
*
* Note: If undefined and dbRecordIdIsSessionId is also undefined then a random
* CUID will be used instead.
*/
readonly dbRecordIdFunction: (sid: string) => string;
/**
* Disables store, used when prisma cannot be connected to
*/
disable(): void;
/**
* Returns if the connect is valid or not, logging an error if it is not.
*/
validateConnection(): Promise<boolean>;
regenerate: (req: import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs>, fn: (err?: any) => any) => void;
load: (sid: string, fn: (err: any, session?: Express.SessionData | null | undefined) => any) => void;
createSession: (req: import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs>, sess: Express.SessionData) => void;
addListener(event: string | symbol, listener: (...args: any[]) => void): any;
on(event: string | symbol, listener: (...args: any[]) => void): any;
once(event: string | symbol, listener: (...args: any[]) => void): any;
removeListener(event: string | symbol, listener: (...args: any[]) => void): any;
off(event: string | symbol, listener: (...args: any[]) => void): any;
removeAllListeners(event?: string | symbol | undefined): any;
setMaxListeners(n: number): any;
getMaxListeners(): number;
listeners(event: string | symbol): Function[];
rawListeners(event: string | symbol): Function[];
emit(event: string | symbol, ...args: any[]): boolean;
listenerCount(type: string | symbol): number;
prependListener(event: string | symbol, listener: (...args: any[]) => void): any;
prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): any;
eventNames(): (string | symbol)[];
};
listenerCount(emitter: import("events").EventEmitter, event: string | symbol): number;
defaultMaxListeners: number;
readonly errorMonitor: unique symbol;
};
/**
* Returns a `PrismaSessionStore` extending the `session` Store class.
*
* @param session the `express-session` object which will be used to extend a store from
*/
export default _default;