From 55e66bcf7d8eb112071087ced4f60cf145b88989 Mon Sep 17 00:00:00 2001 From: rafaelsouzaf Date: Tue, 28 Nov 2017 21:44:54 -0300 Subject: [PATCH] Creating namespace Lifecycle and moving FailAction to inside. --- .../v17/definitions/util/fail-action.d.ts | 4 -- .../hapi/v17/definitions/util/lifecycle.d.ts | 63 ++++++++++++------- 2 files changed, 39 insertions(+), 28 deletions(-) delete mode 100644 types/hapi/v17/definitions/util/fail-action.d.ts diff --git a/types/hapi/v17/definitions/util/fail-action.d.ts b/types/hapi/v17/definitions/util/fail-action.d.ts deleted file mode 100644 index 7b2eb4c4b8..0000000000 --- a/types/hapi/v17/definitions/util/fail-action.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -// TODO It should be replaced by FailAction definition (with lifecycle method) in the future. -// https://github.com/hapijs/hapi/blob/master/API.md#lifecycle-failAction -export type FailAction = 'error' | 'log' | 'ignore' | any; - diff --git a/types/hapi/v17/definitions/util/lifecycle.d.ts b/types/hapi/v17/definitions/util/lifecycle.d.ts index 9dba7980d4..41864a6bdf 100644 --- a/types/hapi/v17/definitions/util/lifecycle.d.ts +++ b/types/hapi/v17/definitions/util/lifecycle.d.ts @@ -1,28 +1,43 @@ -/** - * Lifecycle methods are the interface between the framework and the application. Many of the request lifecycle steps: - * extensions, authentication, handlers, pre-handler methods, and failAction function values are lifecyle methods - * provided by the developer and executed by the framework. - * Each lifecycle method is a function with the signature await function(request, h, [err]) where: - * * request - the request object. - * * h - the response toolkit the handler must call to set a response and return control back to the framework. - * * err - an error object availble only when the method is used as a failAction value. - */ -export interface LifecycleMethod { +export namespace Lifecycle { - // TODO need to be implemented. Ideally with Generics types. + /** + * Lifecycle methods are the interface between the framework and the application. Many of the request lifecycle steps: + * extensions, authentication, handlers, pre-handler methods, and failAction function values are lifecyle methods + * provided by the developer and executed by the framework. + * Each lifecycle method is a function with the signature await function(request, h, [err]) where: + * * request - the request object. + * * h - the response toolkit the handler must call to set a response and return control back to the framework. + * * err - an error object availble only when the method is used as a failAction value. + */ + export interface LifecycleMethod { + + // TODO needs to be implemented. + + } + + /** + * Each lifecycle method must return a value or a promise that resolves into a value. If a lifecycle method returns + * without a value or resolves to an undefined value, an Internal Server Error (500) error response is sent. + * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#lifecycle-methods) + */ + export interface LifecycleReturnValue { + + // TODO needs to be implemented. + + } + + /** + * Various configuration options allows defining how errors are handled. For example, when invalid payload is received or malformed cookie, instead of returning an error, the framework can be configured to perform another action. When supported the failAction option supports the following values: + * * 'error' - return the error object as the response. + * * 'log' - report the error but continue processing the request. + * * 'ignore' - take no action and continue processing the request. + * * a lifecycle method with the signature async function(request, h, err) where: + * * * request - the request object. + * * * h - the response toolkit. + * * * err - the error object. + * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-failaction-configuration) + */ + export type FailAction = 'error' | 'log' | 'ignore' | LifecycleMethod; } -/** - * Each lifecycle method must return a value or a promise that resolves into a value. If a lifecycle method returns - * without a value or resolves to an undefined value, an Internal Server Error (500) error response is sent. - * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#lifecycle-methods) - */ -export interface LifecycleReturnValue { - - - -} - - -