mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-22 08:26:35 +08:00
Merge pull request #17146 from kerol2r20/master
Add type definition for koa-session
This commit is contained in:
108
types/koa-session/index.d.ts
vendored
Normal file
108
types/koa-session/index.d.ts
vendored
Normal file
@@ -0,0 +1,108 @@
|
||||
// Type definitions for koa-session 3.0
|
||||
// Project: https://github.com/koajs/session
|
||||
// Definitions by: Yu Hsin Lu <https://github.com/kerol2r20/>
|
||||
// Definitions: https://github.com/kerol2r20/DefinitelyTyped
|
||||
|
||||
/* =================== USAGE ===================
|
||||
|
||||
import session = require("koa-session");
|
||||
import Koa = require('koa');
|
||||
|
||||
var app = new Koa();
|
||||
app.use(session(app));
|
||||
|
||||
=============================================== */
|
||||
|
||||
import * as Koa from "koa";
|
||||
|
||||
declare namespace session {
|
||||
interface sessionConfig {
|
||||
/**
|
||||
* cookie key (default is koa:sess)
|
||||
*/
|
||||
key?: string;
|
||||
|
||||
/**
|
||||
* maxAge in ms (default is 1 days)
|
||||
* 'session' will result in a cookie that expires when session/browser is closed
|
||||
* Warning: If a session cookie is stolen, this cookie will never expire
|
||||
*/
|
||||
maxAge?: number | 'session';
|
||||
|
||||
/**
|
||||
* can overwrite or not (default true)
|
||||
*/
|
||||
overwrite?: boolean;
|
||||
|
||||
/**
|
||||
* httpOnly or not (default true)
|
||||
*/
|
||||
httpOnly?: boolean;
|
||||
|
||||
/**
|
||||
* signed or not (default true)
|
||||
*/
|
||||
signed?: boolean;
|
||||
|
||||
/**
|
||||
* You can store the session content in external stores(redis, mongodb or other DBs)
|
||||
*/
|
||||
store?: session.stores;
|
||||
|
||||
/**
|
||||
* Hook: valid session value before use it
|
||||
*/
|
||||
valid(...rest: any[]): void;
|
||||
|
||||
/**
|
||||
* Hook: before save session
|
||||
*/
|
||||
beforeSave(...rest: any[]): void;
|
||||
}
|
||||
interface sessionProps {
|
||||
/**
|
||||
* Returns true if the session is new
|
||||
*/
|
||||
isNew: boolean;
|
||||
|
||||
/**
|
||||
* Set cookie's maxAge
|
||||
*/
|
||||
maxAge: number;
|
||||
|
||||
/**
|
||||
* Save this session no matter whether it is populated
|
||||
*/
|
||||
save(): void;
|
||||
[propName: string]: any;
|
||||
}
|
||||
|
||||
interface stores {
|
||||
/**
|
||||
* get session object by key
|
||||
*/
|
||||
get(key: any): any;
|
||||
|
||||
/**
|
||||
* set session object for key, with a maxAge (in ms)
|
||||
*/
|
||||
set(key: any, sess: any, maxAge?: number): any;
|
||||
|
||||
/**
|
||||
* destroy session for key
|
||||
*/
|
||||
destroy(key: any): void;
|
||||
}
|
||||
}
|
||||
|
||||
declare function session(CONFIG: session.sessionConfig, app: Koa): Koa.Middleware;
|
||||
|
||||
declare function session(app: Koa): Koa.Middleware;
|
||||
|
||||
declare module 'koa' {
|
||||
interface Context {
|
||||
session: session.sessionProps;
|
||||
}
|
||||
}
|
||||
|
||||
export = session;
|
||||
8
types/koa-session/koa-session-tests.ts
Normal file
8
types/koa-session/koa-session-tests.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import * as Koa from 'koa';
|
||||
import session = require('koa-session');
|
||||
|
||||
const app = new Koa();
|
||||
|
||||
app.use(session(app));
|
||||
|
||||
app.listen(3000);
|
||||
22
types/koa-session/tsconfig.json
Normal file
22
types/koa-session/tsconfig.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"koa-session-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/koa-session/tslint.json
Normal file
1
types/koa-session/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user