From f7e3fc1e8d42dab607bb4fec24c0fb0f921e92f2 Mon Sep 17 00:00:00 2001 From: rafaelsouzaf Date: Sun, 3 Dec 2017 15:57:40 -0300 Subject: [PATCH] Reviewed some server types. --- .../v17/definitions/server/server-auth.d.ts | 12 +- .../v17/definitions/server/server-method.d.ts | 3 - .../server/server-options-cache.d.ts | 2 +- .../definitions/server/server-options.d.ts | 132 +++++++++--------- types/hapi/v17/definitions/server/server.d.ts | 26 ++-- 5 files changed, 83 insertions(+), 92 deletions(-) diff --git a/types/hapi/v17/definitions/server/server-auth.d.ts b/types/hapi/v17/definitions/server/server-auth.d.ts index 370e16be6b..6b86c0e8a4 100644 --- a/types/hapi/v17/definitions/server/server-auth.d.ts +++ b/types/hapi/v17/definitions/server/server-auth.d.ts @@ -38,8 +38,6 @@ export interface ServerAuth { } /** - * server.auth.default - * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverauthdefaultoptions) * Sets a default strategy which is applied to every route where: * @param options - one of: * * a string with the default strategy name @@ -54,18 +52,19 @@ export interface ServerAuth { * before server.auth.default() is called if those routes lack any authentication config. * The default auth strategy configuration can be accessed via server.auth.settings.default. To obtain the active * 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 | ServerAuthConfig): void; + default(options: string): void; + default(options: ServerAuthConfig): void; /** - * server.auth.scheme - * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverauthschemename-scheme) * Registers an authentication scheme where: * @param name the scheme name. * @param scheme - the method implementing the scheme with signature function(server, options) where: * * server - a reference to the server object the scheme is added to. * * options - (optional) the scheme options argument passed to server.auth.strategy() when instantiation a strategy. * @return void. + * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverauthschemename-scheme) */ scheme(name: string, scheme: ServerAuthScheme): void; @@ -77,7 +76,8 @@ 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, options?: any): void; + strategy(name: string, scheme: string): void; + strategy(name: string, scheme: string, options: any): void; /** * Tests a request against an authentication strategy where: diff --git a/types/hapi/v17/definitions/server/server-method.d.ts b/types/hapi/v17/definitions/server/server-method.d.ts index 216fd6ce6f..9806ffc5cb 100644 --- a/types/hapi/v17/definitions/server/server-method.d.ts +++ b/types/hapi/v17/definitions/server/server-method.d.ts @@ -18,9 +18,6 @@ export interface ServerMethod { * For reference [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-servercacheoptions) */ export interface ServerMethodCache extends catbox.PolicyOptions { - /** - * Required - */ generateTimeout: number | false; } diff --git a/types/hapi/v17/definitions/server/server-options-cache.d.ts b/types/hapi/v17/definitions/server/server-options-cache.d.ts index 13b4df499a..1e75ebe857 100644 --- a/types/hapi/v17/definitions/server/server-options-cache.d.ts +++ b/types/hapi/v17/definitions/server/server-options-cache.d.ts @@ -1,9 +1,9 @@ import * as Catbox from "catbox"; /** - * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-cache) * hapi uses catbox for its cache implementation which includes support for common storage solutions (e.g. Redis, * MongoDB, Memcached, Riak, among others). Caching is only utilized if methods and plugins explicitly store their state in the cache. + * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-cache) */ export interface ServerOptionsCache extends Catbox.PolicyOptions { diff --git a/types/hapi/v17/definitions/server/server-options.d.ts b/types/hapi/v17/definitions/server/server-options.d.ts index 41b21e01fd..4273a01988 100644 --- a/types/hapi/v17/definitions/server/server-options.d.ts +++ b/types/hapi/v17/definitions/server/server-options.d.ts @@ -5,68 +5,71 @@ import * as catbox from "catbox"; import {MimosOptions} from "mimos"; import {PluginSpecificConfiguration, RouteOptions} from "hapi"; - /** - * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-server-options) * he server options control the behavior of the server object. Note that the options object is deeply cloned * (with the exception of listener which is shallowly copied) and should not contain any values that are unsafe to perform deep copy on. * All options are optionals. + * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-server-options) */ export interface ServerOptions { /** - Default value: '0.0.0.0' (all available network interfaces). - Sets the hostname or IP address the server will listen on. If not configured, defaults to host if present, otherwise to all available network interfaces. Set to '127.0.0.1' or 'localhost' to restrict the server to only those coming from the same host. + * Default value: '0.0.0.0' (all available network interfaces). + * Sets the hostname or IP address the server will listen on. If not configured, defaults to host if present, otherwise to all available network interfaces. Set to '127.0.0.1' or 'localhost' to restrict the server to only those coming from the same host. + * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serveroptionsaddress) */ address?: string; /** - Default value: {}. - Provides application-specific configuration which can later be accessed via server.settings.app. The framework does not interact with this object. It is simply a reference made available anywhere a server reference is provided. - Note the difference between server.settings.app which is used to store static configuration values and server.app which is meant for storing run-time state. + * Default value: {}. + * Provides application-specific configuration which can later be accessed via server.settings.app. The framework does not interact with this object. It is simply a reference made available anywhere a server reference is provided. + * Note the difference between server.settings.app which is used to store static configuration values and server.app which is meant for storing run-time state. + * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serveroptionsapp) */ app?: any; /** - Default value: true. - Used to disable the automatic initialization of the listener. When false, indicates that the listener will be started manually outside the framework. - Cannot be set to true along with a port value. + * Default value: true. + * Used to disable the automatic initialization of the listener. When false, indicates that the listener will be started manually outside the framework. + * Cannot be set to true along with a port value. + * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serveroptionsautolisten) */ autoListen?: boolean; /** - Default value: { engine: require('catbox-memory' }. - Sets up server-side caching providers. Every server includes a default cache for storing application state. By default, a simple memory-based cache is created which has limited capacity and capabilities. - hapi uses catbox for its cache implementation which includes support for common storage solutions (e.g. Redis, MongoDB, Memcached, Riak, among others). Caching is only utilized if methods and plugins explicitly store their state in the cache. - The server cache configuration only defines the storage container itself. The configuration can be assigned one or more (array): - a class or prototype function (usually obtained by calling require() on a catbox strategy such as require('catbox-redis')). A new catbox client will be created internally using this function. - a configuration object with the following: - engine - a class, a prototype function, or a catbox engine object. - name - an identifier used later when provisioning or configuring caching for server methods or plugins. Each cache name must be unique. A single item may omit the name option which defines the default cache. If every cache includes a name, a default memory cache is provisioned as well. - shared - if true, allows multiple cache users to share the same segment (e.g. multiple methods using the same cache storage container). Default to false. - partition - (optional) string used to isolate cached data. Defaults to 'hapi-cache'. - other options passed to the catbox strategy used. Other options are only passed to catbox when engine above is a class or function and ignored if engine is a catbox engine object). + * Default value: { engine: require('catbox-memory' }. + * Sets up server-side caching providers. Every server includes a default cache for storing application state. By default, a simple memory-based cache is created which has limited capacity and capabilities. + * hapi uses catbox for its cache implementation which includes support for common storage solutions (e.g. Redis, MongoDB, Memcached, Riak, among others). Caching is only utilized if methods and plugins explicitly store their state in the cache. + * The server cache configuration only defines the storage container itself. The configuration can be assigned one or more (array): + * * a class or prototype function (usually obtained by calling require() on a catbox strategy such as require('catbox-redis')). A new catbox client will be created internally using this function. + * * a configuration object with the following: + * * * engine - a class, a prototype function, or a catbox engine object. + * * * name - an identifier used later when provisioning or configuring caching for server methods or plugins. Each cache name must be unique. A single item may omit the name option which defines the default cache. If every cache includes a name, a default memory cache is provisioned as well. + * * * shared - if true, allows multiple cache users to share the same segment (e.g. multiple methods using the same cache storage container). Default to false. + * * * partition - (optional) string used to isolate cached data. Defaults to 'hapi-cache'. + * * * other options passed to the catbox strategy used. Other options are only passed to catbox when engine above is a class or function and ignored if engine is a catbox engine object). + * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serveroptionscache) */ cache?: catbox.EnginePrototype | ServerOptionsCache | ServerOptionsCache[]; /** - Default value: { minBytes: 1024 }. - Defines server handling of content encoding requests. If false, response content encoding is disabled and no compression is performed by the server. + * Default value: { minBytes: 1024 }. + * Defines server handling of content encoding requests. If false, response content encoding is disabled and no compression is performed by the server. */ compression?: boolean; /** - Default value: '1024'. - Sets the minimum response payload size in bytes that is required for content encoding compression. If the payload size is under the limit, no compression is performed. + * Default value: '1024'. + * Sets the minimum response payload size in bytes that is required for content encoding compression. If the payload size is under the limit, no compression is performed. */ minBytes?: number; /** - Default value: { request: ['implementation'] }. - Determines which logged events are sent to the console. This should only be used for development and does not affect which events are actually logged internally and recorded. Set to false to disable all console logging, or to an object with: - log - a string array of server log tags to be displayed via console.error() when the events are logged via server.log() as well as internally generated server logs. Defaults to no output. - request - a string array of request log tags to be displayed via console.error() when the events are logged via request.log() as well as internally generated request logs. For example, to display all errors, set the option to ['error']. To turn off all console debug messages set it to false. To display all request logs, set it to '*'. Defaults to uncaught errors thrown in external code (these errors are handled automatically and result in an Internal Server Error response) or runtime errors due to developer error. - For example, to display all errors, set the log or request to ['error']. To turn off all output set the log or request to false. To display all server logs, set the log or request to '*'. To disable all debug information, set debug to false. + * Default value: { request: ['implementation'] }. + * Determines which logged events are sent to the console. This should only be used for development and does not affect which events are actually logged internally and recorded. Set to false to disable all console logging, or to an object with: + * * log - a string array of server log tags to be displayed via console.error() when the events are logged via server.log() as well as internally generated server logs. Defaults to no output. + * * request - a string array of request log tags to be displayed via console.error() when the events are logged via request.log() as well as internally generated request logs. For example, to display all errors, set the option to ['error']. To turn off all console debug messages set it to false. To display all request logs, set it to '*'. Defaults to uncaught errors thrown in external code (these errors are handled automatically and result in an Internal Server Error response) or runtime errors due to developer error. + * For example, to display all errors, set the log or request to ['error']. To turn off all output set the log or request to false. To display all server logs, set the log or request to '*'. To disable all debug information, set debug to false. */ debug?: false | { log?: string[] | false; @@ -74,26 +77,26 @@ export interface ServerOptions { }; /** - Default value: the operating system hostname and if not available, to 'localhost'. - The public hostname or IP address. Used to set server.info.host and server.info.uri and as address is none provided. + * Default value: the operating system hostname and if not available, to 'localhost'. + * The public hostname or IP address. Used to set server.info.host and server.info.uri and as address is none provided. */ host?: string; /** - Default value: none. - An optional node HTTP (or HTTPS) http.Server object (or an object with a compatible interface). - If the listener needs to be manually started, set autoListen to false. - If the listener uses TLS, set tls to true. + * Default value: none. + * An optional node HTTP (or HTTPS) http.Server object (or an object with a compatible interface). + * If the listener needs to be manually started, set autoListen to false. + * If the listener uses TLS, set tls to true. */ listener?: http.Server; /** - Default value: { sampleInterval: 0 }. - Server excessive load handling limits where: - sampleInterval - the frequency of sampling in milliseconds. When set to 0, the other load options are ignored. Defaults to 0 (no sampling). - maxHeapUsedBytes - maximum V8 heap size over which incoming requests are rejected with an HTTP Server Timeout (503) response. Defaults to 0 (no limit). - maxRssBytes - maximum process RSS size over which incoming requests are rejected with an HTTP Server Timeout (503) response. Defaults to 0 (no limit). - maxEventLoopDelay - maximum event loop delay duration in milliseconds over which incoming requests are rejected with an HTTP Server Timeout (503) response. Defaults to 0 (no limit). + * Default value: { sampleInterval: 0 }. + * Server excessive load handling limits where: + * * sampleInterval - the frequency of sampling in milliseconds. When set to 0, the other load options are ignored. Defaults to 0 (no sampling). + * * maxHeapUsedBytes - maximum V8 heap size over which incoming requests are rejected with an HTTP Server Timeout (503) response. Defaults to 0 (no limit). + * * maxRssBytes - maximum process RSS size over which incoming requests are rejected with an HTTP Server Timeout (503) response. Defaults to 0 (no limit). + * * maxEventLoopDelay - maximum event loop delay duration in milliseconds over which incoming requests are rejected with an HTTP Server Timeout (503) response. Defaults to 0 (no limit). */ load?: { /** the frequency of sampling in milliseconds. When set to 0, the other load options are ignored. Defaults to 0 (no sampling). */ @@ -107,34 +110,35 @@ export interface ServerOptions { }; /** - Default value: none. - Options passed to the mimos module when generating the mime database used by the server (and accessed via server.mime): - override - an object hash that is merged into the built in mime information specified here. Each key value pair represents a single mime object. Each override value must contain: - key - the lower-cased mime-type string (e.g. 'application/javascript'). - value - an object following the specifications outlined here. Additional values include: - type - specify the type value of result objects, defaults to key. - predicate - method with signature function(mime) when this mime type is found in the database, this function will execute to allows customizations. + * Default value: none. + * Options passed to the mimos module when generating the mime database used by the server (and accessed via server.mime): + * * override - an object hash that is merged into the built in mime information specified here. Each key value pair represents a single mime object. Each override value must contain: + * * key - the lower-cased mime-type string (e.g. 'application/javascript'). + * * value - an object following the specifications outlined here. Additional values include: + * * * type - specify the type value of result objects, defaults to key. + * * * predicate - method with signature function(mime) when this mime type is found in the database, this function will execute to allows customizations. + * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serveroptionsmime) */ mime?: MimosOptions; /** - Default value: {}. - Plugin-specific configuration which can later be accessed via server.settings.plugins. plugins is an object where each key is a plugin name and the value is the configuration. Note the difference between server.settings.plugins which is used to store static configuration values and server.plugins which is meant for storing run-time state. + * Default value: {}. + * Plugin-specific configuration which can later be accessed via server.settings.plugins. plugins is an object where each key is a plugin name and the value is the configuration. Note the difference between server.settings.plugins which is used to store static configuration values and server.plugins which is meant for storing run-time state. */ plugins?: PluginSpecificConfiguration; /** - Default value: 0 (an ephemeral port). - The TCP port the server will listen to. Defaults the next available port when the server is started (and assigned to server.info.port). - If port is a string containing a '/' character, it is used as a UNIX domain socket path. If it starts with '\.\pipe', it is used as a Windows named pipe. + * Default value: 0 (an ephemeral port). + * The TCP port the server will listen to. Defaults the next available port when the server is started (and assigned to server.info.port). + * If port is a string containing a '/' character, it is used as a UNIX domain socket path. If it starts with '\.\pipe', it is used as a Windows named pipe. */ port?: number | string; /** - Default value: { isCaseSensitive: true, stripTrailingSlash: false }. - Controls how incoming request URIs are matched against the routing table: - isCaseSensitive - determines whether the paths '/example' and '/EXAMPLE' are considered different resources. Defaults to true. - stripTrailingSlash - removes trailing slashes on incoming paths. Defaults to false. + * Default value: { isCaseSensitive: true, stripTrailingSlash: false }. + * Controls how incoming request URIs are matched against the routing table: + * * isCaseSensitive - determines whether the paths '/example' and '/EXAMPLE' are considered different resources. Defaults to true. + * * stripTrailingSlash - removes trailing slashes on incoming paths. Defaults to false. */ router?: { isCaseSensitive?: boolean; @@ -142,8 +146,8 @@ export interface ServerOptions { }; /** - Default value: none. - A route options object used as the default configuration for every route. + * Default value: none. + * A route options object used as the default configuration for every route. */ routes?: RouteOptions; @@ -171,14 +175,14 @@ export interface ServerOptions { }; /** - Default value: none. - Used to create an HTTPS connection. The tls object is passed unchanged to the node HTTPS server as described in the node HTTPS documentation. + * Default value: none. + * Used to create an HTTPS connection. The tls object is passed unchanged to the node HTTPS server as described in the node HTTPS documentation. */ tls?: true | https.RequestOptions; /** - Default value: constructed from runtime server information. - The full public URI without the path (e.g. 'http://example.com:8080'). If present, used as the server server.info.uri, otherwise constructed from the server settings. + * Default value: constructed from runtime server information. + * The full public URI without the path (e.g. 'http://example.com:8080'). If present, used as the server server.info.uri, otherwise constructed from the server settings. */ uri?: string; diff --git a/types/hapi/v17/definitions/server/server.d.ts b/types/hapi/v17/definitions/server/server.d.ts index a18fcb7dc7..8045317d37 100644 --- a/types/hapi/v17/definitions/server/server.d.ts +++ b/types/hapi/v17/definitions/server/server.d.ts @@ -1,36 +1,26 @@ -import {ServerOptions} from "./server-options"; -import {ServerRealm} from "./server-realm"; -import {ServerInfo} from "./server-info"; -import {Request} from "../request/request"; import * as http from "http"; -import * as events from 'events'; import * as catbox from "catbox"; import * as zlib from "zlib"; -import {PluginsListRegistered} from "../plugin/plugin-registered"; -import {ServerState} from "./server-state"; -import {MimosOptions} from "../../../../mimos/index"; +import * as Podium from "podium"; +import {MimosOptions} from "mimos"; import { + ServerOptions, ServerRealm, ServerInfo, Request, PluginsListRegistered, ServerState, ServerOptionsCache, ServerEventCriteria, ServerEventsApplication, ServerEventsApplicationObject, PayloadCompressionDecoderSettings, RouteCompressionEncoderSettings, HTTP_METHODS, ServerMethodOptions, ServerMethod, ServerMethodConfigurationObject, + RequestExtPointFunction, ServerExtEventsObject, ServerExtEventsRequestObject, ServerExtOptions, + ServerExtPointFunction, ServerExtRequestType, ServerExtType, + ServerInjectOptions, ServerInjectResponse, + RequestRoute, ServerAuth, ServerRegisterPluginObject, ServerRegisterOptions, ServerRoute, Plugin, ResponseToolkit, Dictionary, ServerStateCookieOptions, HTTP_METHODS_PARTIAL_LOWERCASE, } from "hapi"; -import { - RequestExtPointFunction, ServerExtEventsObject, ServerExtEventsRequestObject, ServerExtOptions, - ServerExtPointFunction, ServerExtRequestType, ServerExtType -} from "./server-ext"; -import {ServerInjectOptions, ServerInjectResponse} from "./server-inject"; -import {RequestRoute} from "../request/request-route"; -import {ServerAuth, ServerAuthConfig} from "./server-auth"; -import {ServerRegisterPluginObject, ServerRegisterOptions} from "./server-register"; -import {ServerRoute} from "./server-route"; /** * The server object is the main application container. The server manages all incoming requests along with all * the facilities provided by the framework. Each server supports a single connection (e.g. listen to port 80). * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#server) */ -export class Server extends events.EventEmitter { +export class Server extends Podium { /** Creates a new server object