From b8622c4b93b0202f19bf48043ac1c1e5890dd0fd Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Fri, 20 Nov 2015 11:12:53 -0500 Subject: [PATCH 1/6] Updating Hapi's IServerInject --- hapi/hapi.d.ts | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/hapi/hapi.d.ts b/hapi/hapi.d.ts index 7f2fab90e..23db49446 100644 --- a/hapi/hapi.d.ts +++ b/hapi/hapi.d.ts @@ -904,15 +904,25 @@ declare module "hapi" { url: string; /** an object with optional request headers where each key is the header name and the value is the header content. Defaults to no additions to the default Shot headers.*/ headers: IDictionary; - /**- an optional string or buffer containing the request payload (object must be manually converted to a string first). Defaults to no payload. Note that payload processing defaults to 'application/json' if no 'Content-Type' header provided.*/ - payload: string|Buffer; - /**an optional credentials object containing authentication information. The credentials are used to bypass the default authentication strategies, and are validated directly as if they were received via an authentication scheme. Defaults to no credentials.*/ - credentials: any; + /** n optional string, buffer or object containing the request payload. In case of an object it will be converted to a string for you. Defaults to no payload. Note that payload processing defaults to 'application/json' if no 'Content-Type' header provided.*/ + payload?: string|{}|Buffer; + /** an optional credentials object containing authentication information. The credentials are used to bypass the default authentication strategies, and are validated directly as if they were received via an authentication scheme. Defaults to no credentials.*/ + credentials?: any; + /** an optional artifacts object containing authentication artifact information. The artifacts are used to bypass the default authentication strategies, and are validated directly as if they were received via an authentication scheme. Ignored if set without credentials. Defaults to no artifacts.*/ + artifacts?: any; + /** sets the initial value of request.app*/ + app?: any; + /** sets the initial value of request.plugins*/ + plugins?: any; + /** allows access to routes with config.isInternal set to true. Defaults to false.*/ + allowInternals?: boolean; + /** sets the remote address for the incoming connection.*/ + remoteAddress?: boolean; /**object with options used to simulate client request stream conditions for testing: error - if true, emits an 'error' event after payload transmission (if any). Defaults to false. close - if true, emits a 'close' event after payload transmission (if any). Defaults to false. end - if false, does not end the stream. Defaults to true.*/ - simulate: { + simulate?: { error: boolean; close: boolean; end: boolean; From 1c5ba17bf0d7e95d9164582509c69e4eff491251 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Fri, 20 Nov 2015 11:20:49 -0500 Subject: [PATCH 2/6] Headers is also optional --- hapi/hapi.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hapi/hapi.d.ts b/hapi/hapi.d.ts index 23db49446..8fd84de08 100644 --- a/hapi/hapi.d.ts +++ b/hapi/hapi.d.ts @@ -903,7 +903,7 @@ declare module "hapi" { /** the request URL. If the URI includes an authority (e.g. 'example.com:8080'), it is used to automatically set an HTTP 'Host' header, unless one was specified in headers.*/ url: string; /** an object with optional request headers where each key is the header name and the value is the header content. Defaults to no additions to the default Shot headers.*/ - headers: IDictionary; + headers?: IDictionary; /** n optional string, buffer or object containing the request payload. In case of an object it will be converted to a string for you. Defaults to no payload. Note that payload processing defaults to 'application/json' if no 'Content-Type' header provided.*/ payload?: string|{}|Buffer; /** an optional credentials object containing authentication information. The credentials are used to bypass the default authentication strategies, and are validated directly as if they were received via an authentication scheme. Defaults to no credentials.*/ From 59e1cd247aa0509666f3bbdbff318ca20e27de5f Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Fri, 20 Nov 2015 11:48:28 -0500 Subject: [PATCH 3/6] Options could be a string --- hapi/hapi.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hapi/hapi.d.ts b/hapi/hapi.d.ts index 8fd84de08..727bada75 100644 --- a/hapi/hapi.d.ts +++ b/hapi/hapi.d.ts @@ -897,7 +897,7 @@ declare module "hapi" { export interface IServerInject { - (options: { + (options: string | { /** the request HTTP method (e.g. 'POST'). Defaults to 'GET'.*/ method: string; /** the request URL. If the URI includes an authority (e.g. 'example.com:8080'), it is used to automatically set an HTTP 'Host' header, unless one was specified in headers.*/ From 088b384ad6d5897529d43934ded1d8c43a7a6b94 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Mon, 23 Nov 2015 09:17:32 -0500 Subject: [PATCH 4/6] Hapi does not use bluebird --- hapi/hapi.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hapi/hapi.d.ts b/hapi/hapi.d.ts index 727bada75..644f07e09 100644 --- a/hapi/hapi.d.ts +++ b/hapi/hapi.d.ts @@ -7,7 +7,7 @@ /// -/// +/// From 88d8553e62a0b552ac70aaf8cd1f844463b9eb52 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Mon, 30 Nov 2015 09:38:59 -0500 Subject: [PATCH 5/6] Adding duck typed Promise Interface --- hapi/hapi.d.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/hapi/hapi.d.ts b/hapi/hapi.d.ts index 644f07e09..fe9e17b5b 100644 --- a/hapi/hapi.d.ts +++ b/hapi/hapi.d.ts @@ -7,10 +7,6 @@ /// -/// - - - declare module "hapi" { import http = require("http"); @@ -21,6 +17,10 @@ declare module "hapi" { [key: string]: T; } + interface IPromise { + + } + /** Boom Module for errors. https://github.com/hapijs/boom * boom provides a set of utilities for returning HTTP errors. Each utility returns a Boom error response object (instance of Error) which includes the following properties: */ export interface IBoom extends Error { @@ -234,12 +234,12 @@ declare module "hapi" { When calling reply(), the framework waits until process.nextTick() to continue processing the request and transmit the response. This enables making changes to the returned response object before the response is sent. This means the framework will resume as soon as the handler method exits. To suspend this behavior, the returned response object supports the following methods: hold(), send() */ export interface IReply { (err: Error, - result?: string|number|boolean|Buffer|stream.Stream | Promise | T, + result?: string|number|boolean|Buffer|stream.Stream | IPromise | T, /** Note that when used to return both an error and credentials in the authentication methods, reply() must be called with three arguments function(err, null, data) where data is the additional authentication information. */ credentialData?: any ): IBoom; /** Note that if result is a Stream with a statusCode property, that status code will be used as the default response code. */ - (result: string|number|boolean|Buffer|stream.Stream | Promise | T): Response; + (result: string|number|boolean|Buffer|stream.Stream | IPromise | T): Response; /** Returns control back to the framework without setting a response. If called in the handler, the response defaults to an empty payload with status code 200. * The data argument is only used for passing back authentication data and is ignored elsewhere. */ From af9d89e7251afc795f4ed6aa37eeb27a8971231b Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Mon, 30 Nov 2015 11:51:47 -0500 Subject: [PATCH 6/6] Basing the duck typed Promise interface on es6 --- hapi/hapi.d.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/hapi/hapi.d.ts b/hapi/hapi.d.ts index fe9e17b5b..b31c24b16 100644 --- a/hapi/hapi.d.ts +++ b/hapi/hapi.d.ts @@ -17,8 +17,15 @@ declare module "hapi" { [key: string]: T; } - interface IPromise { + interface IThenable { + then(onFulfilled?: (value: R) => U | IThenable, onRejected?: (error: any) => U | IThenable): IThenable; + then(onFulfilled?: (value: R) => U | IThenable, onRejected?: (error: any) => void): IThenable; + } + interface IPromise extends IThenable { + then(onFulfilled?: (value: R) => U | IThenable, onRejected?: (error: any) => U | IThenable): IPromise; + then(onFulfilled?: (value: R) => U | IThenable, onRejected?: (error: any) => void): IPromise; + catch(onRejected?: (error: any) => U | IThenable): IPromise; } /** Boom Module for errors. https://github.com/hapijs/boom