npm.io
2.2.6 • Published 11 months ago

@types/koa-generic-session

Licence
MIT
Version
2.2.6
Deps
2
Size
7 kB
Vulns
0
Weekly
0
Stars
51.4K

Installation

npm install --save @types/koa-generic-session

Summary

This package contains type definitions for koa-generic-session (https://github.com/koajs/generic-session).

Details

Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/koa-generic-session.

index.d.ts

import Cookies = require("cookies");
import Koa = require("koa");

declare namespace koaSession {
    interface Session {
        cookie: Cookies.SetOption;
    }

    interface SessionIdStore<Ctx = Koa.Context> {
        get(this: Ctx): string | undefined;
        set(this: Ctx, sid: string, session: Session): void;
        reset(this: Ctx): void;
    }

    interface SessionStore {
        get(sid: string): Session | undefined | Promise<Session | undefined>;
        set(sid: string, session: Session, ttl?: number): void | Promise<void>;
        destroy(sid: string): void | Promise<void>;
    }

    interface SessionOptions {
        key?: string | undefined;
        store?: SessionStore | undefined;
        ttl?: number | undefined;
        prefix?: string | undefined;
        cookie?: Cookies.SetOption | undefined;
        allowEmpty?: boolean | undefined;
        defer?: boolean | undefined;
        reconnectTimeout?: number | undefined;
        rolling?: boolean | undefined;
        sessionIdStore?: SessionIdStore | undefined;
        genSid?(this: Koa.Context, length: number): string | Promise<string>;
        errorHandler?(error: Error, type: string, ctx: Koa.Context): void;
        valid?(ctx: Koa.Context, session: Session): boolean;
        beforeSave?(ctx: Koa.Context, session: Session): void;
    }

    class MemoryStore implements SessionStore {
        get(sid: string): Session | undefined;
        set(sid: string, session: Session): void;
        destroy(sid: string): void;
    }
}

declare module "koa" {
    interface ExtendableContext {
        sessionId: string;
        session: koaSession.Session | null;
        sessionSave: boolean | null;
        regenerateSession(): Promise<void>;
    }
}

declare function koaSession(options: koaSession.SessionOptions): Koa.Middleware;
export = koaSession;

Additional Details

Credits

These definitions were written by Nick Simmons, and Javier Garcia.