2.2.4 • Published 6 months ago

@types/koa-generic-session v2.2.4

Weekly downloads
12,051
License
MIT
Repository
github
Last release
6 months ago

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

// Type definitions for koa-generic-session 2.2
// Project: https://github.com/koajs/generic-session
// Definitions by: Nick Simmons <https://github.com/nsimmons>
//                 Javier Garcia <https://github.com/javiertury>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

import * as Koa from 'koa';
import * as Cookies from 'cookies';

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 Context {
        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.

2.2.3

7 months ago

2.2.2

8 months ago

2.2.4

6 months ago

2.2.1

2 years ago

2.2.0

2 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

4 years ago

1.0.3

5 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago