This commit is contained in:
rsouza
2017-12-11 15:06:56 -03:00
parent 6a92487939
commit d780053e7f
8 changed files with 42 additions and 79 deletions

View File

@@ -182,9 +182,7 @@ export interface Request extends Podium {
* @return ResponseObject
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestgenerateresponsesource-options)
*/
generateResponse(source: object, options?: {variety?: string; prepare?: Function; marshal?: Function; close?: Function; }): ResponseObject;
generateResponse(source: string, options?: {variety?: string; prepare?: Function; marshal?: Function; close?: Function; }): ResponseObject;
generateResponse(source: null, options?: {variety?: string; prepare?: Function; marshal?: Function; close?: Function; }): ResponseObject;
generateResponse(source: string | object | null, options?: {variety?: string; prepare?: Function; marshal?: Function; close?: Function; }): ResponseObject;
/**
* Logs request-specific events. When called, the server emits a 'request' event which can be used by other listeners or plugins. The arguments are:
@@ -194,8 +192,7 @@ export interface Request extends Podium {
* @return void
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestlogtags-data)
*/
log(tags: string, data?: string | object | (() => string | object)): void;
log(tags: string[], data?: string | object | (() => string | object)): void;
log(tags: string | string[], data?: string | object | (() => string | object)): void;
/**
* Changes the request method before the router begins processing the request where:

View File

@@ -14,6 +14,11 @@ export interface ResponseEvents extends Podium {
* 'finish' - emitted when the response finished writing but before the client response connection is ended. The event method signature is function ().
*/
on(criteria: 'peek' | 'finish', listener: Function): void;
/**
* 'peek' - emitted for each chunk of data written back to the client connection. The event method signature is function(chunk, encoding).
* 'finish' - emitted when the response finished writing but before the client response connection is ended. The event method signature is function ().
*/
once(criteria: 'peek' | 'finish', listener: Function): void;
}

View File

@@ -150,8 +150,7 @@ export interface ResponseObject extends Podium {
* @return Return value: the current response object.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responseetagtag-options)
*/
etag(tag: string): ResponseObject;
etag(tag: string, options: {weak: boolean, vary: boolean}): ResponseObject;
etag(tag: string, options?: {weak: boolean, vary: boolean}): ResponseObject;
/**
* Sets an HTTP header where:
@@ -165,8 +164,7 @@ export interface ResponseObject extends Podium {
* @return Return value: the current response object.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responseheadername-value-options)
*/
header(name: string, value: string): ResponseObject;
header(name: string, value: string, options: ResponseObjectHeaderOptions): ResponseObject;
header(name: string, value: string, options?: ResponseObjectHeaderOptions): ResponseObject;
/**
* Sets the HTTP 'Location' header where:
@@ -209,8 +207,7 @@ export interface ResponseObject extends Podium {
* @return Return value: the current response object.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsestatename-value-options)
*/
state(name: string, value: object): ResponseObject;
state(name: string, value: object, options: ServerStateCookieOptions): ResponseObject;
state(name: string, value: object, options?: ServerStateCookieOptions): ResponseObject;
/**
* Sets a string suffix when the response is process via JSON.stringify() where:
@@ -244,8 +241,7 @@ export interface ResponseObject extends Podium {
* @return Return value: the current response object.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responseunstatename-options)
*/
unstate(name: string): ResponseObject;
unstate(name: string, options: ServerStateCookieOptions): ResponseObject;
unstate(name: string, options?: ServerStateCookieOptions): ResponseObject;
/**
* Adds the provided header to the list of inputs affected the response generation via the HTTP 'Vary' header where:

View File

@@ -77,8 +77,7 @@ export interface ResponseToolkit {
* it should be used as the return value (but may be customize using the response methods).
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-hentityoptions)
*/
entity(): ResponseObject | undefined;
entity(options: {etag?: string, modified?: string, vary?: boolean}): ResponseObject | undefined;
entity(options?: {etag?: string, modified?: string, vary?: boolean}): ResponseObject | undefined;
/**
* Redirects the client to the specified uri. Same as calling h.response().redirect(uri).
@@ -86,8 +85,7 @@ export interface ResponseToolkit {
* @return Returns a response object.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-hredirecturi)
*/
redirect(): ResponseObject;
redirect(uri: string): ResponseObject;
redirect(uri?: string): ResponseObject;
/**
* Wraps the provided value and returns a response object which allows customizing the response
@@ -96,9 +94,7 @@ export interface ResponseToolkit {
* @return Returns a response object.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-hresponsevalue)
*/
response(): ResponseObject;
response(value: string): ResponseObject;
response(value: object): ResponseObject;
response(value?: string | object): ResponseObject;
/**
* Sets a response cookie using the same arguments as response.state().
@@ -108,8 +104,7 @@ export interface ResponseToolkit {
* @return Return value: none.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-hstatename-value-options)
*/
state(name: string, value: string): void;
state(name: string, value: string, options: ServerStateCookieOptions): void;
state(name: string, value: string, options?: ServerStateCookieOptions): void;
/**
* Used by the [authentication] method to indicate authentication failed and pass back the credentials received where:
@@ -124,8 +119,7 @@ export interface ResponseToolkit {
* There is no difference between throwing the error or passing it with the h.unauthenticated() method is no credentials are passed, but it might still be helpful for code clarity.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-hunauthenticatederror-data)
*/
unauthenticated(error: Error): void;
unauthenticated(error: Error, data: {credentials: object, artifacts?: object}): void;
unauthenticated(error: Error, data?: {credentials: object, artifacts?: object}): void;
/**
* Clears a response cookie using the same arguments as
@@ -134,7 +128,6 @@ export interface ResponseToolkit {
* @return void.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-hunstatename-options)
*/
unstate(name: string): void;
unstate(name: string, options: ServerStateCookieOptions): void;
unstate(name: string, options?: ServerStateCookieOptions): void;
}

View File

@@ -43,8 +43,7 @@ export interface ServerAuth {
* authentication configuration of a route, use server.auth.lookup(request.route).
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverauthdefaultoptions)
*/
default(options: string): void;
default(options: ServerAuthConfig): void;
default(options: string | ServerAuthConfig): void;
/**
* Registers an authentication scheme where:
@@ -65,8 +64,7 @@ export interface ServerAuth {
* @return Return value: none.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverauthstrategyname-scheme-options)
*/
strategy(name: string, scheme: string): void;
strategy(name: string, scheme: string, options: object): void;
strategy(name: string, scheme: string, options?: object): void;
/**
* Tests a request against an authentication strategy where:

View File

@@ -100,9 +100,7 @@ export interface ServerEvents extends Podium {
* See ['start' event](https://github.com/hapijs/hapi/blob/master/API.md#-start-event)
* See ['stop' event](https://github.com/hapijs/hapi/blob/master/API.md#-stop-event)
*/
on(criteria: string, listener: Function): void;
on(criteria: ServerEventsApplicationObject, listener: Function): void;
on(criteria: ServerEventCriteria, listener: Function): void;
on(criteria: string | ServerEventsApplicationObject | ServerEventCriteria, listener: Function): void;
/**
* Same as calling [server.events.on()](https://github.com/hapijs/hapi/blob/master/API.md#server.events.on()) with the count option set to 1.
@@ -114,9 +112,7 @@ export interface ServerEvents extends Podium {
* @return Return value: none.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-servereventsoncecriteria-listener)
*/
once(criteria: string, listener: (...args: any[]) => void): void; // TODO I am not sure if the best way (here and the functions above/below) is use Function or (...args: any[]) => void) considering the JSDocs "The function signature depends on the event argument"
once(criteria: ServerEventsApplicationObject, listener: Function): void;
once(criteria: ServerEventCriteria, listener: Function): void;
once(criteria: string | ServerEventsApplicationObject | ServerEventCriteria, listener: Function): void;
/**
* Same as calling server.events.on() with the count option set to 1.
@@ -127,9 +123,7 @@ export interface ServerEvents extends Podium {
* @return Return value: a promise that resolves when the event is emitted.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-await-servereventsoncecriteria)
*/
once(criteria: string): any;
once(criteria: ServerEventsApplicationObject): any;
once(criteria: ServerEventCriteria): any;
once(criteria: string | ServerEventsApplicationObject | ServerEventCriteria): any;
/**
* The follow method is only mentioned in Hapi API. The doc about that method can be found [here](https://github.com/hapijs/podium/blob/master/API.md#podiumremovelistenername-listener)

View File

@@ -43,8 +43,7 @@ export interface ServerState {
/**
* Same as calling [server.state()](https://github.com/hapijs/hapi/blob/master/API.md#server.state()).
*/
add(name: string): void;
add(name: string, options: ServerStateCookieOptions): void;
add(name: string, options?: ServerStateCookieOptions): void;
/**
* Formats an HTTP 'Set-Cookie' header based on the server.options.state where:
@@ -56,8 +55,7 @@ export interface ServerState {
* Note that this utility uses the server configuration but does not change the server state. It is provided for manual cookie formating (e.g. when headers are set manually).
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-async-serverstatesformatcookies)
*/
format(cookies: ServerStateFormat): string;
format(cookies: ServerStateFormat[]): string;
format(cookies: ServerStateFormat | ServerStateFormat[]): string;
/**
* Parses an HTTP 'Cookies' header based on the server.options.state where:

View File

@@ -99,8 +99,7 @@ export class Server extends Podium {
* @return Return value: none.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverevents)
*/
event(events: ServerEventsApplication): void;
event(events: ServerEventsApplication[]): void;
event(events: ServerEventsApplication | ServerEventsApplication[]): void;
/**
* Access: podium public interface.
@@ -278,10 +277,7 @@ export class Server extends Podium {
* The method does not provide version dependency which should be implemented using npm peer dependencies.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverdependencydependencies-after)
*/
dependency(dependencies: string): void;
dependency(dependencies: string, after: ((server: Server) => void)): void;
dependency(dependencies: string[]): void;
dependency(dependencies: string[], after: ((server: Server) => void)): void;
dependency(dependencies: string | string[], after?: ((server: Server) => void)): void;
/**
* Registers a custom content encoding compressor to extend the built-in support for 'gzip' and 'deflate' where:
@@ -333,18 +329,15 @@ export class Server extends Podium {
* @return void
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverextevents)
*/
ext(events: ServerExtEventsObject): void;
ext(events: ServerExtEventsObject[]): void;
ext(events: ServerExtEventsRequestObject): void;
ext(events: ServerExtEventsRequestObject[]): void;
ext(events: ServerExtEventsObject | ServerExtEventsObject[]): void;
ext(events: ServerExtEventsRequestObject | ServerExtEventsRequestObject[]): void;
/**
* Registers a single extension event using the same properties as used in server.ext(events), but passed as arguments.
* @return Return value: none.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverextevent-method-options)
*/
ext(event: ServerExtType, method: ServerExtPointFunction | Lifecycle.Method | Function): void;
ext(event: ServerExtType, method: ServerExtPointFunction | Lifecycle.Method | Function, options: ServerExtOptions): void;
ext(event: ServerExtType, method: ServerExtPointFunction | Lifecycle.Method | Function, options?: ServerExtOptions): void;
/**
* Initializes the server (starts the caches, finalizes plugin registration) but does not start listening on the connection port.
@@ -390,8 +383,7 @@ export class Server extends Podium {
* * request - the request object.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-await-serverinjectoptions)
*/
inject(options: string): ServerInjectResponse;
inject(options: ServerInjectOptions): ServerInjectResponse;
inject(options: string | ServerInjectOptions): ServerInjectResponse;
/**
* Logs server events that cannot be associated with a specific request. When called the server emits a 'log' event which can be used by other listeners or plugins to record the information or output to the console. The arguments are:
@@ -419,8 +411,7 @@ export class Server extends Podium {
* @return Return value: the route information if found, otherwise null.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-servermatchmethod-path-host)
*/
match(method: Util.HTTP_METHODS, path: string): RequestRoute | null;
match(method: Util.HTTP_METHODS, path: string, host: string): RequestRoute | null;
match(method: Util.HTTP_METHODS, path: string, host?: string): RequestRoute | null;
/**
* Registers a server method where:
@@ -438,8 +429,7 @@ export class Server extends Podium {
* When configured with caching enabled, server.methods[name].cache is assigned an object with the following properties and methods: - await drop(...args) - a function that can be used to clear the cache for a given key. - stats - an object with cache statistics, see catbox for stats documentation.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-servermethodname-method-options)
*/
method(name: string, method: ServerMethod): void;
method(name: string, method: ServerMethod, options: ServerMethodOptions): void;
method(name: string, method: ServerMethod, options?: ServerMethodOptions): void;
/**
* Registers a server method function as described in server.method() using a configuration object where:
@@ -450,8 +440,7 @@ export class Server extends Podium {
* @return Return value: none.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-servermethodmethods)
*/
method(methods: ServerMethodConfigurationObject): void;
method(methods: ServerMethodConfigurationObject[]): void;
method(methods: ServerMethodConfigurationObject | ServerMethodConfigurationObject[]): void;
/**
* Sets the path prefix used to locate static resources (files and view templates) when relative paths are used where:
@@ -470,7 +459,7 @@ export class Server extends Podium {
* * * plugin - a plugin object.
* * * options - (optional) options passed to the plugin during registration.
* * * once, routes - (optional) plugin-specific registration options as defined below.
* @paramoptions - (optional) registration options (different from the options passed to the registration function):
* @param options - (optional) registration options (different from the options passed to the registration function):
* * once - if true, subsequent registrations of the same plugin are skipped without error. Cannot be used with plugin options. Defaults to false. If not set to true, an error will be thrown the second time a plugin is registered on the server.
* * routes - modifiers applied to each route added by the plugin:
* * * prefix - string added as prefix to any route path (must begin with '/'). If a plugin registers a child plugin the prefix is passed on to the child or is added in front of the child-specific prefix.
@@ -478,10 +467,8 @@ export class Server extends Podium {
* @return Return value: none.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-await-serverregisterplugins-options)
*/
register(plugins: Plugin | ServerRegisterPluginObject): void;
register(plugins: Plugin | ServerRegisterPluginObject, options: ServerRegisterOptions): void;
register(plugins: Plugin[] | ServerRegisterPluginObject[]): void;
register(plugins: Plugin[] | ServerRegisterPluginObject[], options: ServerRegisterOptions): void;
register(plugins: Plugin | Plugin[], options?: ServerRegisterOptions): void;
register(plugins: ServerRegisterPluginObject | ServerRegisterPluginObject[], options?: ServerRegisterOptions): void;
/**
* Adds a route where:
@@ -496,8 +483,7 @@ export class Server extends Podium {
* Note that the options object is deeply cloned (with the exception of bind which is shallowly copied) and cannot contain any values that are unsafe to perform deep copy on.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverrouteroute)
*/
route(route: ServerRoute): void;
route(route: ServerRoute[]): void;
route(route: ServerRoute | ServerRoute[]): void;
/**
* Defines a route rules processor for converting route rules object into route configuration where:
@@ -506,7 +492,7 @@ export class Server extends Podium {
* * info - an object with the following properties:
* * * method - the route method.
* * * path - the route path.
* * *vhost - the route virtual host (if any defined).
* * * vhost - the route virtual host (if any defined).
* * returns a route config object.
* @param options - optional settings:
* * validate - rules object validation:
@@ -516,8 +502,7 @@ export class Server extends Podium {
* @return void
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverrulesprocessor-options)
*/
rules(processor: (rules: object, info: {method: string, path: string, vhost?: string}) => object): void;
rules(processor: (rules: object, info: {method: string, path: string, vhost?: string}) => object, options: {validate: object}): void; // TODO needs implementation
rules(processor: (rules: object, info: {method: string, path: string, vhost?: string}) => object, options?: {validate: object}): void; // TODO needs implementation
/**
* Starts the server by listening for incoming requests on the configured port (unless the connection was configured with autoListen set to false).
@@ -536,8 +521,7 @@ export class Server extends Podium {
* State defaults can be modified via the server default state configuration option.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverstatename-options)
*/
state(name: string): void;
state(name: string, options: ServerStateCookieOptions): void;
state(name: string, options?: ServerStateCookieOptions): void;
/**
* Stops the server's listener by refusing to accept any new connections or requests (existing connections will continue until closed or timeout), where:
@@ -546,8 +530,7 @@ export class Server extends Podium {
* @return Return value: none.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-await-serverstopoptions)
*/
stop(): void;
stop(options: {timeout: number}): void;
stop(options?: {timeout: number}): void;
/**
* Returns a copy of the routing table where:
@@ -558,7 +541,6 @@ export class Server extends Podium {
* * path - the route path.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-servertablehost)
*/
table(): {settings: ServerRoute; method: Util.HTTP_METHODS_PARTIAL_LOWERCASE, path: string}[]; // TODO I am not sure if the ServerRoute is the object expected here
table(host: string): {settings: ServerRoute; method: Util.HTTP_METHODS_PARTIAL_LOWERCASE, path: string}[];
table(host?: string): {settings: ServerRoute; method: Util.HTTP_METHODS_PARTIAL_LOWERCASE, path: string}[]; // TODO I am not sure if the ServerRoute is the object expected here
}