From 2d3747f9986d74f8e793a7c042c1a5619d693c2e Mon Sep 17 00:00:00 2001 From: Simon Schick Date: Wed, 25 Apr 2018 01:06:35 +0200 Subject: [PATCH] fix(hapi): make all ext options properties optional (#25214) --- types/hapi/index.d.ts | 6 +++--- types/hapi/test/request/event-types.ts | 10 ++++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/types/hapi/index.d.ts b/types/hapi/index.d.ts index d4072b0cd7..f0730e6f67 100644 --- a/types/hapi/index.d.ts +++ b/types/hapi/index.d.ts @@ -2472,15 +2472,15 @@ export interface ServerExtOptions { /** * a string or array of strings of plugin names this method must execute before (on the same event). Otherwise, extension methods are executed in the order added. */ - before: string | string[]; + before?: string | string[]; /** * a string or array of strings of plugin names this method must execute after (on the same event). Otherwise, extension methods are executed in the order added. */ - after: string | string[]; + after?: string | string[]; /** * a context object passed back to the provided method (via this) when called. Ignored if the method is an arrow function. */ - bind: object; + bind?: object; /** * if set to 'plugin' when adding a request extension points the extension is only added to routes defined by the current plugin. Not allowed when configuring route-level extensions, or when * adding server extensions. Defaults to 'server' which applies to any route added to the server the extension is added to. diff --git a/types/hapi/test/request/event-types.ts b/types/hapi/test/request/event-types.ts index 386b93e19d..4d4f3f01ca 100644 --- a/types/hapi/test/request/event-types.ts +++ b/types/hapi/test/request/event-types.ts @@ -1,6 +1,6 @@ // https://github.com/hapijs/hapi/blob/master/API.md#-servereventevents // https://github.com/hapijs/hapi/blob/master/API.md#-requestevents -import { Lifecycle, Request, ResponseToolkit, RouteOptions, Server, ServerOptions, ServerRoute } from "hapi"; +import { Lifecycle, Request, Server, ServerOptions, ServerRoute } from "hapi"; import * as Crypto from 'crypto'; const options: ServerOptions = { @@ -10,7 +10,7 @@ const options: ServerOptions = { const serverRoute: ServerRoute = { path: '/', method: 'GET', - handler(request, h) { + handler(request) { return 'ok: ' + request.path; } }; @@ -42,7 +42,7 @@ const onRequest: Lifecycle.Method = (request, h) => { */ const hash = Crypto.createHash('sha1'); - request.events.on("peek", (chunk, encoding) => { + request.events.on("peek", (chunk) => { hash.update(chunk); }); @@ -59,7 +59,9 @@ const onRequest: Lifecycle.Method = (request, h) => { const server = new Server(options); server.route(serverRoute); -server.ext('onRequest', onRequest); +server.ext('onRequest', onRequest, { + before: 'test', +}); server.start(); console.log('Server started at: ' + server.info.uri);