mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 06:47:03 +00:00
Added more Server types
This commit is contained in:
+1
-2
@@ -4,7 +4,6 @@ export interface PluginsStates {
|
||||
[pluginName: string]: any;
|
||||
}
|
||||
|
||||
// Similar to v16, using that interface without any definition.
|
||||
export interface PluginSpecificConfiguration {
|
||||
|
||||
}
|
||||
@@ -32,7 +31,7 @@ export interface Plugin {
|
||||
* registry) should use the same name as the name field in their 'package.json' file. Names must be
|
||||
* unique within each application.
|
||||
*/
|
||||
name?: string;
|
||||
name: string;
|
||||
|
||||
/** optional plugin version. The version is only used informatively to enable other plugins to find out the versions loaded. The version should be the same as the one specified in the plugin's 'package.json' file. */
|
||||
version?: string;
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
import * as catbox from "catbox";
|
||||
|
||||
/**
|
||||
* The method function with a signature async function(...args, [flags]) where:
|
||||
* * ...args - the method function arguments (can be any number of arguments or none).
|
||||
* * flags - when caching is enabled, an object used to set optional method result flags:
|
||||
* * * ttl - 0 if result is valid but cannot be cached. Defaults to cache policy.
|
||||
* For reference [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-servermethodname-method-options)
|
||||
*/
|
||||
export interface ServerMethod {
|
||||
(args: any[], flags: {ttl?: number}): any;
|
||||
}
|
||||
|
||||
/**
|
||||
* The same cache configuration used in server.cache().
|
||||
* The generateTimeout option is required.
|
||||
* For reference [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-servermethodname-method-options)
|
||||
* For reference [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-servercacheoptions)
|
||||
*/
|
||||
export interface ServerMethodCache extends catbox.PolicyOptions {
|
||||
/**
|
||||
* Required
|
||||
*/
|
||||
generateTimeout: number | false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configuration object:
|
||||
* * bind - a context object passed back to the method function (via this) when called. Defaults to active context (set via server.bind() when the method is registered. Ignored if the method is an arrow function.
|
||||
* * cache - the same cache configuration used in server.cache(). The generateTimeout option is required.
|
||||
* * generateKey - a function used to generate a unique key (for caching) from the arguments passed to the method function (the flags argument is not passed as input). The server will automatically generate a unique key if the function's arguments are all of types 'string', 'number', or 'boolean'. However if the method uses other types of arguments, a key generation function must be provided which takes the same arguments as the function and returns a unique string (or null if no key can be generated).
|
||||
* For reference [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-servermethodname-method-options)
|
||||
*/
|
||||
export interface ServerMethodOptions {
|
||||
bind: any;
|
||||
cache: ServerMethodCache;
|
||||
generateKey: Function;
|
||||
}
|
||||
|
||||
/**
|
||||
* An object or an array of objects where each one contains:
|
||||
* * name - the method name.
|
||||
* * method - the method function.
|
||||
* * options - (optional) settings.
|
||||
* For reference [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-servermethodmethods)
|
||||
*/
|
||||
export interface ServerMethodConfigurationObject {
|
||||
name: string;
|
||||
method: ServerMethod;
|
||||
options?: ServerMethodOptions;
|
||||
}
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
import {ServerOptionsCache} from "./server-options-cache";
|
||||
import * as http from "http";
|
||||
import * as https from "https";
|
||||
import * as Catbox from "catbox";
|
||||
import * as catbox from "catbox";
|
||||
import {MimosOptions} from "mimos";
|
||||
import {PluginSpecificConfiguration, RouteOptions} from "hapi";
|
||||
|
||||
@@ -47,7 +47,7 @@ export interface ServerOptions {
|
||||
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).
|
||||
*/
|
||||
cache?: Catbox.EnginePrototype | ServerOptionsCache | ServerOptionsCache[];
|
||||
cache?: catbox.EnginePrototype | ServerOptionsCache | ServerOptionsCache[];
|
||||
|
||||
/**
|
||||
Default value: { minBytes: 1024 }.
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import {Plugin} from "hapi";
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* * * vhost - virtual host string (or array of strings) applied to every route. The outer-most vhost overrides the any nested configuration.
|
||||
* For reference [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-await-serverregisterplugins-options)
|
||||
*/
|
||||
export interface ServerRegisterOptions {
|
||||
|
||||
once?: boolean;
|
||||
routes?: {
|
||||
prefix: string;
|
||||
vhost: string | string[];
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* An object with the following:
|
||||
* * plugin - a plugin object.
|
||||
* * options - (optional) options passed to the plugin during registration.
|
||||
* * 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.
|
||||
* * * vhost - virtual host string (or array of strings) applied to every route. The outer-most vhost overrides the any nested configuration.
|
||||
* For reference [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-await-serverregisterplugins-options)
|
||||
*/
|
||||
export interface ServerRegisterPluginObject extends ServerRegisterOptions {
|
||||
|
||||
plugin: Plugin;
|
||||
options?: any;
|
||||
|
||||
}
|
||||
+63
-8
@@ -11,7 +11,9 @@ import {ServerState} from "./server-state";
|
||||
import {MimosOptions} from "../../../../mimos/index";
|
||||
import {
|
||||
ServerOptionsCache, ServerEventCriteria, ServerEventsApplication, ServerEventsApplicationObject,
|
||||
PayloadCompressionDecoderSettings, RouteCompressionEncoderSettings, HTTP_METHODS
|
||||
PayloadCompressionDecoderSettings, RouteCompressionEncoderSettings, HTTP_METHODS, ServerMethodOptions, ServerMethod,
|
||||
ServerMethodConfigurationObject,
|
||||
Plugin,
|
||||
} from "hapi";
|
||||
import {
|
||||
RequestExtPointFunction, ServerExtEventsObject, ServerExtEventsRequestObject, ServerExtOptions,
|
||||
@@ -20,10 +22,7 @@ import {
|
||||
import {ServerInjectOptions, ServerInjectResponse} from "./server-inject";
|
||||
import {RequestRoute} from "../request/request-route";
|
||||
import {ServerAuth, ServerAuthConfig} from "./server-auth";
|
||||
|
||||
export interface ServerMethod {
|
||||
// (...args: any[], ttl?: number): any;
|
||||
}
|
||||
import {ServerRegisterPluginObject, ServerRegisterOptions} from "./server-register";
|
||||
|
||||
/**
|
||||
* The server object is the main application container. The server manages all incoming requests along with all
|
||||
@@ -524,7 +523,65 @@ export class Server extends events.EventEmitter {
|
||||
* 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: Function, options?: any): void;
|
||||
method(name: string, method: ServerMethod, options?: ServerMethodOptions): void;
|
||||
|
||||
/**
|
||||
* Registers a server method function as described in server.method() using a configuration object where:
|
||||
* @param methods - an object or an array of objects where each one contains:
|
||||
* * name - the method name.
|
||||
* * method - the method function.
|
||||
* * options - (optional) settings.
|
||||
* @return Return value: none.
|
||||
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-servermethodmethods)
|
||||
*/
|
||||
method(methods: ServerMethodConfigurationObject): void;
|
||||
method(methods: ServerMethodConfigurationObject[]): void;
|
||||
|
||||
/**
|
||||
* Sets the path prefix used to locate static resources (files and view templates) when relative paths are used where:
|
||||
* @param relativeTo - the path prefix added to any relative file path starting with '.'.
|
||||
* @return Return value: none.
|
||||
* Note that setting a path within a plugin only applies to resources accessed by plugin methods. If no path is set, the server default route configuration files.relativeTo settings is used. The path only applies to routes added after it has been set.
|
||||
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverpathrelativeto)
|
||||
*/
|
||||
path(relativeTo: string): void;
|
||||
|
||||
/**
|
||||
* Registers a plugin where:
|
||||
* @param plugins - one or an array of:
|
||||
* * a plugin object.
|
||||
* * an object with the following:
|
||||
* * * 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):
|
||||
* * 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.
|
||||
* * * vhost - virtual host string (or array of strings) applied to every route. The outer-most vhost overrides the any nested configuration.
|
||||
* @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;
|
||||
|
||||
/**
|
||||
* Adds a route where:
|
||||
* @param route - a route configuration object or an array of configuration objects where each object contains:
|
||||
* * path - (required) the absolute path used to match incoming requests (must begin with '/'). Incoming requests are compared to the configured paths based on the server's router configuration. The path can include named parameters enclosed in {} which will be matched against literal values in the request as described in Path parameters.
|
||||
* * method - (required) the HTTP method. Typically one of 'GET', 'POST', 'PUT', 'PATCH', 'DELETE', or 'OPTIONS'. Any HTTP method is allowed, except for 'HEAD'. Use '*' to match against any HTTP method (only when an exact match was not found, and any match with a specific method will be given a higher priority over a wildcard match). Can be assigned an array of methods which has the same result as adding the same route with different methods manually.
|
||||
* * vhost - (optional) a domain string or an array of domain strings for limiting the route to only requests with a matching host header field. Matching is done against the hostname part of the header only (excluding the port). Defaults to all hosts.
|
||||
* * handler - (required when handler is not set) the route handler function called to generate the response after successful authentication and validation.
|
||||
* * options - additional route options. The options value can be an object or a function that returns an object using the signature function(server) where server is the server the route is being added to and this is bound to the current realm's bind option.
|
||||
* * rules - route custom rules object. The object is passed to each rules processor registered with server.rules(). Cannot be used if route.options.rules is defined.
|
||||
* @return Return value: none.
|
||||
* 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: any): void; // TODO needs to be implemented. Depends of the route options TODO as well.
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -545,6 +602,4 @@ export class Server extends events.EventEmitter {
|
||||
*/
|
||||
start(): void;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Vendored
+2
@@ -41,9 +41,11 @@ export * from './definitions/server/server-events'
|
||||
export * from './definitions/server/server-ext'
|
||||
export * from './definitions/server/server-info'
|
||||
export * from './definitions/server/server-inject'
|
||||
export * from './definitions/server/server-method'
|
||||
export * from './definitions/server/server-options'
|
||||
export * from './definitions/server/server-options-cache'
|
||||
export * from './definitions/server/server-realm'
|
||||
export * from './definitions/server/server-register'
|
||||
export * from './definitions/server/server-state'
|
||||
export * from './definitions/server/server-state-options'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user