mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-23 12:56:46 +08:00
add typing for bluebird Promise.promisify, and new typing for hapi v8.2.0. old hapi definition renamed to "hapi-pre-8.2.d.ts" as what version it targets is unknown.
This commit is contained in:
7
bluebird/bluebird.d.ts
vendored
7
bluebird/bluebird.d.ts
vendored
@@ -404,7 +404,12 @@ declare class Promise<R> implements Promise.Thenable<R>, Promise.Inspection<R> {
|
||||
*
|
||||
* If you pass a `receiver`, the `nodeFunction` will be called as a method on the `receiver`.
|
||||
*/
|
||||
// TODO how to model promisify?
|
||||
static promisify<T>(func: (callback: (err:any, result: T) => void) => void, receiver?: any): () => Promise<T>;
|
||||
static promisify<T, A1>(func: (arg1: A1, callback: (err: any, result: T) => void) => void, receiver?: any): (arg1: A1) => Promise<T>;
|
||||
static promisify<T, A1, A2>(func: (arg1: A1, arg2: A2, callback: (err: any, result: T) => void) => void, receiver?: any): (arg1: A1, arg2: A2) => Promise<T>;
|
||||
static promisify<T, A1, A2, A3>(func: (arg1: A1, arg2: A2, arg3: A3, callback: (err: any, result: T) => void) => void, receiver?: any): (arg1: A1, arg2: A2, arg3: A3) => Promise<T>;
|
||||
static promisify<T, A1, A2, A3, A4>(func: (arg1: A1, arg2: A2, arg3: A3, arg4: A4, callback: (err: any, result: T) => void) => void, receiver?: any): (arg1: A1, arg2: A2, arg3: A3, arg4: A4) => Promise<T>;
|
||||
static promisify<T, A1, A2, A3, A4, A5>(func: (arg1: A1, arg2: A2, arg3: A3, arg4: A4, arg5: A5, callback: (err: any, result: T) => void) => void, receiver?: any): (arg1: A1, arg2: A2, arg3: A3, arg4: A4, arg5: A5) => Promise<T>;
|
||||
static promisify(nodeFunction: Function, receiver?: any): Function;
|
||||
|
||||
/**
|
||||
|
||||
76
hapi/hapi-pre-8.2-tests.ts
Normal file
76
hapi/hapi-pre-8.2-tests.ts
Normal file
@@ -0,0 +1,76 @@
|
||||
/// <reference path="hapi-pre-8.2.d.ts" />
|
||||
|
||||
import Hapi = require('hapi');
|
||||
|
||||
// Create a server with a host and port
|
||||
var server = Hapi.createServer('localhost', 8000);
|
||||
|
||||
// Add plugins
|
||||
var plugin: any = {
|
||||
register: function (plugin: Object, options: Object, next: Function) {
|
||||
next();
|
||||
}
|
||||
};
|
||||
|
||||
plugin.register.attributes = {
|
||||
name: 'test',
|
||||
version: '1.0.0'
|
||||
};
|
||||
|
||||
server.pack.register(plugin, (err: Object) => {
|
||||
if (err) { throw err; }
|
||||
});
|
||||
|
||||
server.pack.register([plugin], (err: Object) => {
|
||||
if (err) { throw err; }
|
||||
});
|
||||
|
||||
// Add server method
|
||||
var add = function (a: number, b: number, next: (err: any, result?: any, ttl?: number) => void) {
|
||||
next(null, a + b);
|
||||
};
|
||||
|
||||
server.method('sum', add, { cache: { expiresIn: 2000 } });
|
||||
|
||||
server.methods.sum(4, 5, (err: any, result: any) => {
|
||||
console.log(result);
|
||||
});
|
||||
|
||||
var addArray = function (array: Array<number>, next: (err: any, result?: any, ttl?: number) => void) {
|
||||
var sum: number = 0;
|
||||
array.forEach((item: number) => {
|
||||
sum += item;
|
||||
});
|
||||
next(null, sum);
|
||||
};
|
||||
|
||||
server.method('sumObj', addArray, {
|
||||
cache: { expiresIn: 2000 },
|
||||
generateKey: (array: Array<number>) => {
|
||||
return array.join(',');
|
||||
}
|
||||
});
|
||||
|
||||
server.methods.sumObj([5, 6], (err: any, result: any) => {
|
||||
console.log(result);
|
||||
});
|
||||
|
||||
// Add the route
|
||||
server.route({
|
||||
method: 'GET',
|
||||
path: '/hello',
|
||||
handler: function (request: Hapi.Request, reply: Function) {
|
||||
reply('hello world');
|
||||
}
|
||||
});
|
||||
|
||||
server.route([{
|
||||
method: 'GET',
|
||||
path: '/hello2',
|
||||
handler: function (request: Hapi.Request, reply: Function) {
|
||||
reply('hello world2');
|
||||
}
|
||||
}]);
|
||||
|
||||
// Start the server
|
||||
server.start();
|
||||
459
hapi/hapi-pre-8.2.d.ts
vendored
Normal file
459
hapi/hapi-pre-8.2.d.ts
vendored
Normal file
@@ -0,0 +1,459 @@
|
||||
// Type definitions for hapi
|
||||
// Project: http://github.com/spumko/hapi
|
||||
// Definitions by: Hakubo <http://github.com/hakubo>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
/// <reference path="../node/node.d.ts" />
|
||||
|
||||
declare module Hapi {
|
||||
export interface ServerOptions {
|
||||
app?: any;
|
||||
// cache?: string;
|
||||
// cache?: {
|
||||
// engine: any;
|
||||
// };
|
||||
cache?: any;
|
||||
// cors?: boolean;
|
||||
// cors?: {
|
||||
// origin?: Array<string>;
|
||||
// isOriginExposed?: boolean;
|
||||
// matchOrigin?: boolean;
|
||||
// maxAge?: number;
|
||||
// headers?: Array<string>;
|
||||
// additionalHeaders?: Array<string>;
|
||||
// methods?: Array<string>;
|
||||
// additionalMethods?: Array<string>;
|
||||
// exposedHeaders?: Array<string>;
|
||||
// additionalExposedHeaders?: Array<string>;
|
||||
// credentials?: boolean;
|
||||
// };
|
||||
cors?: any;
|
||||
// security?: boolean;
|
||||
// security?: {
|
||||
// hsts?: boolean;
|
||||
// hsts?: {
|
||||
// maxAge: number;
|
||||
// includeSubdomains: boolean;
|
||||
// };
|
||||
// xframe?: boolean;
|
||||
// xframe?: string;
|
||||
// xframe?: {
|
||||
// rule: string;
|
||||
// source: any;
|
||||
// };
|
||||
// xss?: boolean;
|
||||
// noOpen?: boolean;
|
||||
// noSniff?: boolean;
|
||||
// };
|
||||
security?: any;
|
||||
debug?: {
|
||||
request: Array<string>;
|
||||
};
|
||||
files?: {
|
||||
relativeTo: string;
|
||||
etagsCacheMaxSize: number;
|
||||
};
|
||||
json?: {
|
||||
// replacer?: () => void;
|
||||
// replacer?: Array<() => void>;
|
||||
replacer?: any;
|
||||
space?: number;
|
||||
};
|
||||
labels?: Array<string>;
|
||||
load?: {
|
||||
maxHeapUsedBytes?: number;
|
||||
maxRssBytes?: number;
|
||||
maxEventLoopDelay?: number;
|
||||
sampleInterval?: number;
|
||||
};
|
||||
location?: string;
|
||||
payload?: {
|
||||
maxBytes: number;
|
||||
uploads: string;
|
||||
};
|
||||
plugins?: any;
|
||||
router?: {
|
||||
isCaseSensitive?: boolean;
|
||||
stripTrailingSlash?: boolean;
|
||||
};
|
||||
state?: {
|
||||
cookies: {
|
||||
parse?: boolean;
|
||||
failAction?: string;
|
||||
clearInvalid?: boolean;
|
||||
strictHeader?: boolean;
|
||||
}
|
||||
};
|
||||
timeout?: {
|
||||
// server?: boolean;
|
||||
// server?: number;
|
||||
server?: any;
|
||||
// client?: boolean;
|
||||
// client?: number;
|
||||
client?: any;
|
||||
// socket?: boolean;
|
||||
// socket?: number;
|
||||
socket?: any;
|
||||
};
|
||||
tls?: any; //This should be Node.tls
|
||||
maxSockets?: number;
|
||||
validation?: any;
|
||||
views?: ServerView;
|
||||
}
|
||||
|
||||
export class Pack {
|
||||
require(name: string, options: {}, callback: Function): void;
|
||||
register(plugins: any, options?: Object, callback?: Function, state?: Object): void;
|
||||
}
|
||||
|
||||
export interface ServerView {
|
||||
engines: {
|
||||
[extension: string]: string;
|
||||
module?: string;
|
||||
// compile: (
|
||||
// template: string,
|
||||
// options: any
|
||||
// ) => void;
|
||||
// compile: (
|
||||
// template: string,
|
||||
// options: any,
|
||||
// callback: (
|
||||
// err: any,
|
||||
// compiled: (
|
||||
// context: any,
|
||||
// options: any,
|
||||
// callback: (
|
||||
// err: any,
|
||||
// rendered: boolean
|
||||
// ) => void
|
||||
// ) => void
|
||||
// ) => void
|
||||
// ) => void;
|
||||
compile?: any;
|
||||
};
|
||||
defaultExtension?: string;
|
||||
path?: string;
|
||||
partialsPath?: string;
|
||||
helpersPath?: string;
|
||||
basePath?: string;
|
||||
layout?: boolean;
|
||||
layoutPath?: string;
|
||||
layoutKeyword?: string;
|
||||
encoding?: string;
|
||||
isCached?: boolean;
|
||||
allowAbsolutePaths?: boolean;
|
||||
allowInsecureAccess?: boolean;
|
||||
compileOptions?: any;
|
||||
runtimeOptions?: any;
|
||||
contentType?: string;
|
||||
compileMode?: string;
|
||||
}
|
||||
|
||||
export interface RouteOptions {
|
||||
path: string;
|
||||
method: string;
|
||||
// vhost?: string;
|
||||
// vhost?: Array<string>;
|
||||
vhost?: any;
|
||||
// handler: string;
|
||||
// handler: (request: Request, reply: Function) => void;
|
||||
// handler: {
|
||||
// file: string;
|
||||
// file: (request: Request) => void;
|
||||
// file: {
|
||||
// path: string;
|
||||
// filename?: string;
|
||||
// mode?: boolean;
|
||||
// mode?: string;
|
||||
// lookupCompressed: boolean;
|
||||
// };
|
||||
// directory: {
|
||||
// path: string;
|
||||
// path: Array<string>;
|
||||
// path: (request: Request) => string;
|
||||
// path: (request: Request) => Array<string>;
|
||||
// index?: boolean;
|
||||
// listing?: boolean;
|
||||
// showHidden?: boolean;
|
||||
// redirectToSlash?: boolean;
|
||||
// lookupCompressed?: boolean;
|
||||
// defaultExtension?: string;
|
||||
// };
|
||||
// proxy?: {
|
||||
// host?: string;
|
||||
// port?: number;
|
||||
// protocol?: string;
|
||||
// uri?: string;
|
||||
// passThrough?: boolean;
|
||||
// rejectUnauthorized?: boolean;
|
||||
// xforward?: boolean;
|
||||
// redirects?: boolean;
|
||||
// redirects?: number;
|
||||
// timeout?: number;
|
||||
//
|
||||
// mapUri?: (request: Request, callback: (err: any, uri: string, headers: {[key: string]: string}) => void) => void;
|
||||
// onResponse: (
|
||||
// err: any,
|
||||
// res: any,//Node Response
|
||||
// req: any,//Node Request
|
||||
// reply: () => void,
|
||||
// settings: any,
|
||||
// ttl: number
|
||||
// ) => void;
|
||||
// ttl: number;
|
||||
// };
|
||||
// view: string;
|
||||
// view: {
|
||||
// template: string;
|
||||
// context: {
|
||||
// payload: any;
|
||||
// params: any;
|
||||
// query: any;
|
||||
// pre: any;
|
||||
// }
|
||||
// };
|
||||
// config: {
|
||||
// handler: any;
|
||||
// bind: any;
|
||||
// app: any;
|
||||
// plugins: {
|
||||
// [name: string]: any;
|
||||
// };
|
||||
// pre: Array<() => void>;
|
||||
// validate: {
|
||||
// headers: any;
|
||||
// params: any;
|
||||
// query: any;
|
||||
// payload: any;
|
||||
// errorFields?: any;
|
||||
// failAction?: string;
|
||||
// failAction?: (source: string, error: any, next: () => void) => void;
|
||||
// };
|
||||
// payload: {
|
||||
// output: {
|
||||
// data: any;
|
||||
// stream: any;
|
||||
// file: any;
|
||||
// };
|
||||
// parse?: any;
|
||||
// allow?: string;
|
||||
// allow?: Array<string>;
|
||||
// override?: string;
|
||||
// maxBytes?: number;
|
||||
// uploads?: number;
|
||||
// failAction?: string;
|
||||
// };
|
||||
// response: {
|
||||
// schema: any;
|
||||
// sample: number;
|
||||
// failAction: string;
|
||||
// };
|
||||
// cache: {
|
||||
// privacy: string;
|
||||
// expiresIn: number;
|
||||
// expiresAt: number;
|
||||
// };
|
||||
// auth: string;
|
||||
// auth: boolean;
|
||||
// auth: {
|
||||
// mode: string;
|
||||
// strategies: Array<string>;
|
||||
// payload?: boolean;
|
||||
// payload?: string;
|
||||
// tos?: boolean;
|
||||
// tos?: string;
|
||||
// scope?: string;
|
||||
// scope?: Array<string>;
|
||||
// entity: string;
|
||||
// };
|
||||
// cors?: boolean;
|
||||
// jsonp?: string;
|
||||
// description?: string;
|
||||
// notes?: string;
|
||||
// notes?: Array<string>;
|
||||
// tags?: Array<string>;
|
||||
// }
|
||||
// };
|
||||
handler: any;
|
||||
}
|
||||
|
||||
export class Server {
|
||||
app: any;
|
||||
methods: any;
|
||||
info: {
|
||||
port: number;
|
||||
host?: string;
|
||||
protocol?: string;
|
||||
uri?: string;
|
||||
};
|
||||
listener: any;// Node Http server
|
||||
load: {
|
||||
eventLoopDelay: number;
|
||||
heapUsed: number;
|
||||
rss: number;
|
||||
};
|
||||
pack: Pack;
|
||||
plugins: {
|
||||
[pluginName: string]: any;
|
||||
};
|
||||
|
||||
start(callback?: () => void): void;
|
||||
stop(options?: {timeout: number;}, callback?: () => void): void;
|
||||
route(options: RouteOptions): void;
|
||||
route(routes: Array<RouteOptions>): void;
|
||||
table(host?: string): Array<RouteOptions>;
|
||||
log(tags: string, data?: string, timestamp?: number): void;
|
||||
log(tags: Array<string>, data?: string, timestamp?: number): void;
|
||||
log(tags: string, data?: any, timestamp?: number): void;
|
||||
log(tags: Array<string>, data?: any, timestamp?: number): void;
|
||||
connection(options?: ServerOptions): void;
|
||||
state(name: string, options?: {
|
||||
ttl: number;
|
||||
isSecure: boolean;
|
||||
isHttpOnly: boolean;
|
||||
path: string;
|
||||
domain: string;
|
||||
autoValue: (request: Request, next: (err: any, value: any) => void) => void;
|
||||
encoding?: string;
|
||||
sign: any;
|
||||
password: string;
|
||||
iron: any;
|
||||
}): void;
|
||||
views(options: ServerView): void;
|
||||
cache(name: string, options: {
|
||||
expiresIn: number;
|
||||
expiresAt: number;
|
||||
staleIn: number;
|
||||
staleTimeout: number;
|
||||
cache: string;
|
||||
}): void;
|
||||
|
||||
auth: {
|
||||
scheme(name: string, scheme: {
|
||||
name: string;
|
||||
scheme: (server: Server, options: any) => (authenticate: any, payload: any, response: any) => void;
|
||||
}): void;
|
||||
strategy: any;
|
||||
};
|
||||
ext(event: any, method: string, options?: any): void;
|
||||
method(method: Array<{name: string; fn: () => void; options: any}>): void;
|
||||
method(name: string, fn: Function, options: any): void;
|
||||
inject(options: any, callback: any): void;
|
||||
handler(name: string, method: (name: string, options: any) => void): void;
|
||||
}
|
||||
|
||||
export interface Request {
|
||||
app: any;
|
||||
auth: {
|
||||
isAuthenticated: boolean;
|
||||
credentials: any;
|
||||
artifacts: any;
|
||||
session: any
|
||||
};
|
||||
domain: any;
|
||||
headers: any;
|
||||
id: number;
|
||||
info: {
|
||||
received: number;
|
||||
remoteAddress: string;
|
||||
remotePort: number;
|
||||
referrer: string;
|
||||
host: string;
|
||||
};
|
||||
method: string;
|
||||
mime?: string;
|
||||
params: any;
|
||||
path: string;
|
||||
payload: any;
|
||||
plugins: any;
|
||||
pre: any;
|
||||
response: any;
|
||||
responses: any;
|
||||
query: any;
|
||||
raw: {
|
||||
req: any; //http.ClientRequest
|
||||
res: any; //http.ClientResponse
|
||||
};
|
||||
route: string;
|
||||
server: Server;
|
||||
session: any;
|
||||
state: any;
|
||||
url: any;
|
||||
|
||||
setUrl? (url: string): void;
|
||||
setMethod? (method: string): void;
|
||||
log (tags: string, data?: string, timestamp?: number): void;
|
||||
log (tags: string, data?: any, timestamp?: number): void;
|
||||
log (tags: string[], data?: string, timestamp?: number): void;
|
||||
log (tags: string[], data?: any, timestamp?: number): void;
|
||||
getLog(): string[];
|
||||
getLog(tag: string): string[];
|
||||
getLog(tags: string[]): string[];
|
||||
tail(name?: string): Function;
|
||||
}
|
||||
|
||||
export interface Response {
|
||||
statusCode: number;
|
||||
headers: any;
|
||||
source: any;
|
||||
variety: string;
|
||||
app: any;
|
||||
plugins: any;
|
||||
settings: {
|
||||
encoding: string;
|
||||
charset: string;
|
||||
location: string;
|
||||
ttl: number;
|
||||
stringify: any;
|
||||
passThrough: boolean;
|
||||
}
|
||||
|
||||
code (statusCode: number): void;
|
||||
header (name: string, value: string, options?: {
|
||||
append: boolean;
|
||||
separator: string;
|
||||
override: boolean;
|
||||
}): void;
|
||||
type (mimeType: string): void;
|
||||
bytes (length: number): void;
|
||||
vary (header: string): void;
|
||||
location (location: string): void;
|
||||
created (location: string): void;
|
||||
redirect (location: string): void;
|
||||
encoding (encoding: string): void;
|
||||
charset (charset: string): void;
|
||||
ttl (ttl: number): void;
|
||||
state (name: string, value: string, options?: any): void;
|
||||
unstate (name: string): void;
|
||||
|
||||
replacer (method: Function): void;
|
||||
replacer (method: Array<Function>): void;
|
||||
spaces (count: number): void;
|
||||
|
||||
temporary (isTemporary: boolean): void;
|
||||
permanent (isPermanent: boolean): void;
|
||||
rewritable (isRewritable: boolean): void;
|
||||
}
|
||||
|
||||
export module reply {
|
||||
function file(path: string, options: {
|
||||
filePath: string;
|
||||
options: {
|
||||
filename: string;
|
||||
mode: string
|
||||
}
|
||||
}): void;
|
||||
|
||||
function view(template: string, context?: any, options?: any): Response;
|
||||
function close(options?: any): void;
|
||||
function proxy(options: any): void;
|
||||
|
||||
export function reply(result: any): any;
|
||||
}
|
||||
|
||||
export function createServer (host: string, port: number, options?: ServerOptions): Server;
|
||||
}
|
||||
|
||||
declare module "hapi" {
|
||||
export = Hapi;
|
||||
}
|
||||
@@ -1,9 +1,13 @@
|
||||
/// <reference path="hapi.d.ts" />
|
||||
|
||||
import Hapi = require('hapi');
|
||||
import Hapi = require("hapi");
|
||||
|
||||
// Create a server with a host and port
|
||||
var server = Hapi.createServer('localhost', 8000);
|
||||
var server = new Hapi.Server();
|
||||
server.connection({
|
||||
host: "localhost",
|
||||
port: 8000,
|
||||
});
|
||||
|
||||
// Add plugins
|
||||
var plugin: any = {
|
||||
@@ -13,26 +17,26 @@ var plugin: any = {
|
||||
};
|
||||
|
||||
plugin.register.attributes = {
|
||||
name: 'test',
|
||||
version: '1.0.0'
|
||||
name: "test",
|
||||
version: "1.0.0"
|
||||
};
|
||||
|
||||
server.pack.register(plugin, (err: Object) => {
|
||||
if (err) { throw err; }
|
||||
});
|
||||
//server.pack.register(plugin, (err: Object) => {
|
||||
// if (err) { throw err; }
|
||||
//});
|
||||
|
||||
server.pack.register([plugin], (err: Object) => {
|
||||
if (err) { throw err; }
|
||||
});
|
||||
//server.pack.register([plugin], (err: Object) => {
|
||||
// if (err) { throw err; }
|
||||
//});
|
||||
|
||||
// Add server method
|
||||
var add = function (a: number, b: number, next: (err: any, result?: any, ttl?: number) => void) {
|
||||
next(null, a + b);
|
||||
};
|
||||
|
||||
server.method('sum', add, { cache: { expiresIn: 2000 } });
|
||||
server.method("sum", add);//, { cache: { expiresIn: 2000 } });
|
||||
|
||||
server.methods.sum(4, 5, (err: any, result: any) => {
|
||||
server.methods["sum"](4, 5, (err: any, result: any) => {
|
||||
console.log(result);
|
||||
});
|
||||
|
||||
@@ -44,14 +48,14 @@ var addArray = function (array: Array<number>, next: (err: any, result?: any, tt
|
||||
next(null, sum);
|
||||
};
|
||||
|
||||
server.method('sumObj', addArray, {
|
||||
cache: { expiresIn: 2000 },
|
||||
server.method("sumObj", addArray, {
|
||||
//cache: { expiresIn: 2000 },
|
||||
generateKey: (array: Array<number>) => {
|
||||
return array.join(',');
|
||||
}
|
||||
});
|
||||
|
||||
server.methods.sumObj([5, 6], (err: any, result: any) => {
|
||||
server.methods["sumObj"]([5, 6], (err: any, result: any) => {
|
||||
console.log(result);
|
||||
});
|
||||
|
||||
|
||||
2556
hapi/hapi.d.ts
vendored
2556
hapi/hapi.d.ts
vendored
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user