diff --git a/types/hapi/v17/definitions/request/request-events.d.ts b/types/hapi/v17/definitions/request/request-events.d.ts new file mode 100644 index 0000000000..c61b3ed65c --- /dev/null +++ b/types/hapi/v17/definitions/request/request-events.d.ts @@ -0,0 +1,45 @@ +import * as Podium from "podium"; + +/** + * 'peek' - emitted for each chunk of payload data read from the client connection. The event method signature is function(chunk, encoding). + * 'finish' - emitted when the request payload finished reading. The event method signature is function (). + * 'disconnect' - emitted when a request errors or aborts unexpectedly. + * For context [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestevents) + */ +export type RequestEventType = "peek" | "finish" | "disconnect"; + +/** + * Access: read only and the public podium interface. + * The request.events supports the following events: + * * 'peek' - emitted for each chunk of payload data read from the client connection. The event method signature is function(chunk, encoding). + * * 'finish' - emitted when the request payload finished reading. The event method signature is function (). + * * 'disconnect' - emitted when a request errors or aborts unexpectedly. + * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestevents) + */ +export interface RequestEvents extends Podium { + + /** + * Access: read only and the public podium interface. + * The request.events supports the following events: + * * 'peek' - emitted for each chunk of payload data read from the client connection. The event method signature is function(chunk, encoding). + * * 'finish' - emitted when the request payload finished reading. The event method signature is function (). + * * 'disconnect' - emitted when a request errors or aborts unexpectedly. + * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestevents) + */ + on(criteria: RequestEventType, listener: Function): void; + + /** + * Access: read only and the public podium interface. + * The request.events supports the following events: + * * 'peek' - emitted for each chunk of payload data read from the client connection. The event method signature is function(chunk, encoding). + * * 'finish' - emitted when the request payload finished reading. The event method signature is function (). + * * 'disconnect' - emitted when a request errors or aborts unexpectedly. + * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestevents) + */ + once(criteria: RequestEventType, listener: Function): void; + + + + // TODO is it necessary to implement "emmit" event here? + +} diff --git a/types/hapi/v17/definitions/request/request.d.ts b/types/hapi/v17/definitions/request/request.d.ts index c77614ee9d..8d004553da 100644 --- a/types/hapi/v17/definitions/request/request.d.ts +++ b/types/hapi/v17/definitions/request/request.d.ts @@ -9,6 +9,7 @@ import {RequestRoute} from "./request-route"; import {RequestAuth} from "./request-auth"; import {RequestInfo} from "./request-info"; import * as Podium from "podium"; +import {RequestEvents} from "hapi"; /** * TODO both objects ReplyValue and _ReplyValue I found in the v16 TS definition, but I don't found it in the documentation. Need review. @@ -61,7 +62,7 @@ export interface Request extends Podium { * * 'disconnect' - emitted when a request errors or aborts unexpectedly. * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestevents) */ - events: 'peek' | 'finish' | 'disconnect'; // TODO I think it's wrong. Maybe is events.on(' ', ' '). It needs revision. + events: RequestEvents; /** * The raw request headers (references request.raw.req.headers).