mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 23:07:06 +00:00
fix(hapi): make cache generic (#29904)
This commit is contained in:
committed by
Steve Ognibene
parent
01d1a10091
commit
fa01268068
Vendored
+1
-1
@@ -2,7 +2,7 @@
|
||||
// Project: https://github.com/hapijs/bell
|
||||
// Definitions by: Simon Schick <https://github.com/SimonSchick>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.7
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
import { Server, Request, Plugin, AuthCredentials } from 'hapi';
|
||||
|
||||
|
||||
@@ -144,12 +144,12 @@ const boomifiedError = Boom.boomify(new Error('test'), { statusCode: 400, messag
|
||||
|
||||
// isBoom
|
||||
|
||||
const isBoomError = new Boom('test')
|
||||
const isBoomError = new Boom('test');
|
||||
|
||||
Boom.isBoom(isBoomError);
|
||||
|
||||
const maybeBoom = <any>new Boom('test');
|
||||
if(Boom.isBoom(maybeBoom)) {
|
||||
const maybeBoom = <any> new Boom('test');
|
||||
if (Boom.isBoom(maybeBoom)) {
|
||||
// isBoom is a type guard that allows accessing these properties:
|
||||
maybeBoom.output.headers;
|
||||
}
|
||||
@@ -183,7 +183,8 @@ interface CustomPayload extends Boom.Payload {
|
||||
/**
|
||||
* Test assignment of custom error data:
|
||||
*/
|
||||
const errorWithData = Boom.badImplementation('', { custom1: 'test', customType: 'Custom1', isCustom: true } as CustomData1);
|
||||
// tslint:disable-next-line:no-object-literal-type-assertion
|
||||
const errorWithData = Boom.badImplementation('', <CustomData1> { custom1: 'test', customType: 'Custom1', isCustom: true });
|
||||
const errorWithNoExplicitDataType: Boom = errorWithData; // can assign to error without explicit data type
|
||||
const errorWithExplicitType: Boom<CustomData> = errorWithData; // can assign to union data type
|
||||
const errorWithConcreteCustomData: Boom<CustomData1> = errorWithData; // can assign to concrete data type
|
||||
|
||||
Vendored
+86
-63
@@ -1,4 +1,4 @@
|
||||
// Type definitions for boom 7.2.0
|
||||
// Type definitions for boom 7.2
|
||||
// Project: https://github.com/hapijs/boom
|
||||
// Definitions by: Igor Rogatty <https://github.com/rogatty>
|
||||
// AJP <https://github.com/AJamesPhillips>
|
||||
@@ -10,28 +10,31 @@
|
||||
|
||||
export = Boom;
|
||||
/**
|
||||
* boom provides a set of utilities for returning HTTP errors. Each utility returns a Boom error response object (instance of Error) which includes the following properties:
|
||||
* @see {@link https://github.com/hapijs/boom#boom}
|
||||
*/
|
||||
* boom provides a set of utilities for returning HTTP errors. Each utility returns a Boom error response object (instance of Error) which includes the following properties:
|
||||
* @see {@link https://github.com/hapijs/boom#boom}
|
||||
*/
|
||||
declare class Boom<Data = any> extends Error {
|
||||
|
||||
/** Creates a new Boom object using the provided message and then calling boomify() to decorate the error with the Boom properties. */
|
||||
constructor(message?: string | Error, options?: Boom.Options<Data>);
|
||||
/** isBoom - if true, indicates this is a Boom object instance. */
|
||||
isBoom: boolean;
|
||||
/** isServer - convenience bool indicating status code >= 500. */
|
||||
isServer: boolean;
|
||||
/** message - the error message. */
|
||||
message: string;
|
||||
/** output - the formatted response. Can be directly manipulated after object construction to return a custom error response. Allowed root keys: */
|
||||
output: Boom.Output;
|
||||
/** reformat() - rebuilds error.output using the other object properties. */
|
||||
reformat: () => string;
|
||||
/** "If message is unset, the 'error' segment of the header will not be present and isMissing will be true on the error object." mentioned in @see {@link https://github.com/hapijs/boom#boomunauthorizedmessage-scheme-attributes} */
|
||||
isMissing?: boolean;
|
||||
/** https://github.com/hapijs/boom#createstatuscode-message-data and https://github.com/hapijs/boom/blob/v4.3.0/lib/index.js#L99 */
|
||||
data: Data;
|
||||
}
|
||||
/** Creates a new Boom object using the provided message and then calling boomify() to decorate the error with the Boom properties. */
|
||||
constructor(message?: string | Error, options?: Boom.Options<Data>);
|
||||
/** isBoom - if true, indicates this is a Boom object instance. */
|
||||
isBoom: boolean;
|
||||
/** isServer - convenience bool indicating status code >= 500. */
|
||||
isServer: boolean;
|
||||
/** message - the error message. */
|
||||
message: string;
|
||||
/** output - the formatted response. Can be directly manipulated after object construction to return a custom error response. Allowed root keys: */
|
||||
output: Boom.Output;
|
||||
/** reformat() - rebuilds error.output using the other object properties. */
|
||||
reformat(): string;
|
||||
/**
|
||||
* "If message is unset, the 'error' segment of the header will not be present and
|
||||
* isMissing will be true on the error object." mentioned in
|
||||
* @see {@link https://github.com/hapijs/boom#boomunauthorizedmessage-scheme-attributes}
|
||||
*/
|
||||
isMissing?: boolean;
|
||||
/** https://github.com/hapijs/boom#createstatuscode-message-data and https://github.com/hapijs/boom/blob/v4.3.0/lib/index.js#L99 */
|
||||
data: Data;
|
||||
}
|
||||
declare namespace Boom {
|
||||
interface Options<Data> {
|
||||
/** statusCode - the HTTP status code. Defaults to 500 if no status code is already set. */
|
||||
@@ -44,20 +47,32 @@ declare namespace Boom {
|
||||
ctor?: any;
|
||||
/** message - error message string. If the error already has a message, the provided message is added as a prefix. Defaults to no message. */
|
||||
message?: string;
|
||||
/** override - if false, the err provided is a Boom object, and a statusCode or message are provided, the values are ignored. Defaults to true (apply the provided statusCode and message options to the error regardless of its type, Error or Boom object). */
|
||||
/**
|
||||
* override - if false, the err provided is a Boom object, and a statusCode or message are
|
||||
* provided, the values are ignored. Defaults to true (apply the provided statusCode and
|
||||
* message options to the error regardless of its type, Error or Boom object).
|
||||
*/
|
||||
override?: boolean;
|
||||
}
|
||||
|
||||
interface Output {
|
||||
/** statusCode - the HTTP status code (typically 4xx or 5xx). */
|
||||
statusCode: number;
|
||||
/** headers - an object containing any HTTP headers where each key is a header name and value is the header content. (Limited value type to string https://github.com/hapijs/boom/issues/151 ) */
|
||||
/**
|
||||
* headers - an object containing any HTTP headers where each key is a header name and
|
||||
* value is the header content. (Limited value type to string
|
||||
* https://github.com/hapijs/boom/issues/151 )
|
||||
*/
|
||||
headers: {[index: string]: string};
|
||||
/** payload - the formatted object used as the response payload (stringified). Can be directly manipulated but any changes will be lost if reformat() is called. Any content allowed and by default includes the following content: */
|
||||
/**
|
||||
* payload - the formatted object used as the response payload (stringified).
|
||||
* Can be directly manipulated but any changes will be lost if reformat() is called.
|
||||
* Any content allowed and by default includes the following content:
|
||||
*/
|
||||
payload: Payload;
|
||||
}
|
||||
|
||||
interface Payload {
|
||||
interface Payload {
|
||||
/** statusCode - the HTTP status code, derived from error.output.statusCode. */
|
||||
statusCode: number;
|
||||
/** error - the HTTP status message (e.g. 'Bad Request', 'Internal Server Error') derived from statusCode. */
|
||||
@@ -79,13 +94,13 @@ declare namespace Boom {
|
||||
* @param options optional additional options
|
||||
* @see {@link https://github.com/hapijs/boom#boomifyerror-options}
|
||||
*/
|
||||
function boomify(error: Error, options?: { statusCode?: number, message?: string, override?: boolean }): Boom<null>;
|
||||
function boomify(error: Error, options?: { statusCode?: number, message?: string, override?: boolean }): Boom<null>;
|
||||
|
||||
/**
|
||||
* Identifies whether an error is a Boom object. Same as calling instanceof Boom.
|
||||
* @param error the error object to identify.
|
||||
*/
|
||||
function isBoom(error: Error): error is Boom
|
||||
function isBoom(error: Error): error is Boom;
|
||||
|
||||
// 4xx
|
||||
/**
|
||||
@@ -94,7 +109,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boombadrequestmessage-data}
|
||||
*/
|
||||
function badRequest<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
function badRequest<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 401 Unauthorized error
|
||||
@@ -102,13 +117,21 @@ declare namespace Boom {
|
||||
* @param scheme can be one of the following:
|
||||
* * an authentication scheme name
|
||||
* * an array of string values. These values will be separated by ', ' and set to the 'WWW-Authenticate' header.
|
||||
* @param attributes an object of values to use while setting the 'WWW-Authenticate' header. This value is only used when scheme is a string, otherwise it is ignored. Every key/value pair will be included in the 'WWW-Authenticate' in the format of 'key="value"' as well as in the response payload under the attributes key. Alternatively value can be a string which is use to set the value of the scheme, for example setting the token value for negotiate header. If string is used message parameter must be null. null and undefined will be replaced with an empty string. If attributes is set, message will be used as the 'error' segment of the 'WWW-Authenticate' header. If message is unset, the 'error' segment of the header will not be present and isMissing will be true on the error object.
|
||||
* @param attributes an object of values to use while setting the 'WWW-Authenticate' header.
|
||||
* This value is only used when scheme is a string, otherwise it is ignored.
|
||||
* Every key/value pair will be included in the 'WWW-Authenticate' in the format of
|
||||
* 'key="value"' as well as in the response payload under the attributes key.
|
||||
* Alternatively value can be a string which is use to set the value of the scheme,
|
||||
* for example setting the token value for negotiate header.
|
||||
* If string is used message parameter must be null.
|
||||
* null and undefined will be replaced with an empty string. If attributes is set,
|
||||
* message will be used as the 'error' segment of the 'WWW-Authenticate' header.
|
||||
* If message is unset, the 'error' segment of the header will not be present and isMissing will be true on the error object.
|
||||
* @see {@link https://github.com/hapijs/boom#boomunauthorizedmessage-scheme-attributes}
|
||||
*/
|
||||
function unauthorized(message?: string, scheme?: string, attributes?: {[index: string]: string}): Boom<null>;
|
||||
function unauthorized(message?: string, scheme?: string[]): Boom<null>;
|
||||
function unauthorized(message?: null, scheme?: string, attributes?: {[index: string]: string} | string): Boom<null>;
|
||||
function unauthorized(message?: null, scheme?: string[]): Boom<null>;
|
||||
function unauthorized(message?: string, scheme?: string, attributes?: {[index: string]: string}): Boom<null>;
|
||||
function unauthorized(message?: string, scheme?: string[]): Boom<null>;
|
||||
function unauthorized(message?: null, scheme?: string, attributes?: {[index: string]: string} | string): Boom<null>;
|
||||
|
||||
/**
|
||||
* Returns a 402 Payment Required error
|
||||
@@ -116,7 +139,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boompaymentrequiredmessage-data}
|
||||
*/
|
||||
function paymentRequired<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
function paymentRequired<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 403 Forbidden error
|
||||
@@ -124,7 +147,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomforbiddenmessage-data}
|
||||
*/
|
||||
function forbidden<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
function forbidden<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 404 Not Found error
|
||||
@@ -132,7 +155,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomnotfoundmessage-data}
|
||||
*/
|
||||
function notFound<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
function notFound<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 405 Method Not Allowed error
|
||||
@@ -141,7 +164,7 @@ declare namespace Boom {
|
||||
* @param allow optional string or array of strings (to be combined and separated by ', ') which is set to the 'Allow' header.
|
||||
* @see {@link https://github.com/hapijs/boom#boommethodnotallowedmessage-data-allow}
|
||||
*/
|
||||
function methodNotAllowed<Data = null>(message?: string, data?: Data, allow?: string | string[]): Boom<Data>;
|
||||
function methodNotAllowed<Data = null>(message?: string, data?: Data, allow?: string | string[]): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 406 Not Acceptable error
|
||||
@@ -149,7 +172,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomnotacceptablemessage-data}
|
||||
*/
|
||||
function notAcceptable<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
function notAcceptable<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 407 Proxy Authentication Required error
|
||||
@@ -157,7 +180,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomproxyauthrequiredmessage-data}
|
||||
*/
|
||||
function proxyAuthRequired<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
function proxyAuthRequired<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 408 Request Time-out error
|
||||
@@ -165,7 +188,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomclienttimeoutmessage-data}
|
||||
*/
|
||||
function clientTimeout<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
function clientTimeout<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 409 Conflict error
|
||||
@@ -173,7 +196,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomconflictmessage-data}
|
||||
*/
|
||||
function conflict<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
function conflict<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 410 Gone error
|
||||
@@ -181,7 +204,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomresourcegonemessage-data}
|
||||
*/
|
||||
function resourceGone<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
function resourceGone<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 411 Length Required error
|
||||
@@ -189,7 +212,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomlengthrequiredmessage-data}
|
||||
*/
|
||||
function lengthRequired<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
function lengthRequired<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 412 Precondition Failed error
|
||||
@@ -197,7 +220,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boompreconditionfailedmessage-data}
|
||||
*/
|
||||
function preconditionFailed<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
function preconditionFailed<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 413 Request Entity Too Large error
|
||||
@@ -205,7 +228,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomentitytoolargemessage-data}
|
||||
*/
|
||||
function entityTooLarge<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
function entityTooLarge<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 414 Request-URI Too Large error
|
||||
@@ -213,7 +236,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomuritoolongmessage-data}
|
||||
*/
|
||||
function uriTooLong<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
function uriTooLong<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 415 Unsupported Media Type error
|
||||
@@ -221,7 +244,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomunsupportedmediatypemessage-data}
|
||||
*/
|
||||
function unsupportedMediaType<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
function unsupportedMediaType<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 416 Requested Range Not Satisfiable error
|
||||
@@ -229,7 +252,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomrangenotsatisfiablemessage-data}
|
||||
*/
|
||||
function rangeNotSatisfiable<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
function rangeNotSatisfiable<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 417 Expectation Failed error
|
||||
@@ -237,7 +260,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomexpectationfailedmessage-data}
|
||||
*/
|
||||
function expectationFailed<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
function expectationFailed<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 418 I'm a Teapot error
|
||||
@@ -245,7 +268,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomteapotmessage-data}
|
||||
*/
|
||||
function teapot<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
function teapot<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 422 Unprocessable Entity error
|
||||
@@ -253,7 +276,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boombaddatamessage-data}
|
||||
*/
|
||||
function badData<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
function badData<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 423 Locked error
|
||||
@@ -261,7 +284,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomlockedmessage-data}
|
||||
*/
|
||||
function locked<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
function locked<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 424 Failed Dependency error
|
||||
@@ -269,7 +292,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomfaileddependencymessage-data}
|
||||
*/
|
||||
function failedDependency<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
function failedDependency<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 428 Precondition Required error
|
||||
@@ -277,7 +300,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boompreconditionrequiredmessage-data}
|
||||
*/
|
||||
function preconditionRequired<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
function preconditionRequired<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 429 Too Many Requests error
|
||||
@@ -285,7 +308,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomtoomanyrequestsmessage-data}
|
||||
*/
|
||||
function tooManyRequests<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
function tooManyRequests<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 451 Unavailable For Legal Reasons error
|
||||
@@ -293,7 +316,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomillegalmessage-data}
|
||||
*/
|
||||
function illegal<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
function illegal<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
// 5xx
|
||||
/**
|
||||
@@ -303,7 +326,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boombadimplementationmessage-data---alias-internal}
|
||||
*/
|
||||
function badImplementation<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
function badImplementation<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 500 Internal Server Error error
|
||||
@@ -312,7 +335,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boombadimplementationmessage-data---alias-internal}
|
||||
*/
|
||||
function internal<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
function internal<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 501 Not Implemented error with your error message to the user
|
||||
@@ -320,7 +343,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomnotimplementedmessage-data}
|
||||
*/
|
||||
function notImplemented<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
function notImplemented<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 502 Bad Gateway error with your error message to the user
|
||||
@@ -328,7 +351,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boombadgatewaymessage-data}
|
||||
*/
|
||||
function badGateway<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
function badGateway<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 503 Service Unavailable error with your error message to the user
|
||||
@@ -336,7 +359,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomserverunavailablemessage-data}
|
||||
*/
|
||||
function serverUnavailable<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
function serverUnavailable<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 504 Gateway Time-out error with your error message to the user
|
||||
@@ -344,5 +367,5 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomgatewaytimeoutmessage-data}
|
||||
*/
|
||||
function gatewayTimeout<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
function gatewayTimeout<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
}
|
||||
|
||||
+1
-77
@@ -1,79 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"adjacent-overload-signatures": false,
|
||||
"array-type": false,
|
||||
"arrow-return-shorthand": false,
|
||||
"ban-types": false,
|
||||
"callable-types": false,
|
||||
"comment-format": false,
|
||||
"dt-header": false,
|
||||
"eofline": false,
|
||||
"export-just-namespace": false,
|
||||
"import-spacing": false,
|
||||
"interface-name": false,
|
||||
"interface-over-type-literal": false,
|
||||
"jsdoc-format": false,
|
||||
"max-line-length": false,
|
||||
"member-access": false,
|
||||
"new-parens": false,
|
||||
"no-any-union": false,
|
||||
"no-boolean-literal-compare": false,
|
||||
"no-conditional-assignment": false,
|
||||
"no-consecutive-blank-lines": false,
|
||||
"no-construct": false,
|
||||
"no-declare-current-package": false,
|
||||
"no-duplicate-imports": false,
|
||||
"no-duplicate-variable": false,
|
||||
"no-empty-interface": false,
|
||||
"no-for-in-array": false,
|
||||
"no-inferrable-types": false,
|
||||
"no-internal-module": false,
|
||||
"no-irregular-whitespace": false,
|
||||
"no-mergeable-namespace": false,
|
||||
"no-misused-new": false,
|
||||
"no-namespace": false,
|
||||
"no-object-literal-type-assertion": false,
|
||||
"no-padding": false,
|
||||
"no-redundant-jsdoc": false,
|
||||
"no-redundant-jsdoc-2": false,
|
||||
"no-redundant-undefined": false,
|
||||
"no-reference-import": false,
|
||||
"no-relative-import-in-test": false,
|
||||
"no-self-import": false,
|
||||
"no-single-declare-module": false,
|
||||
"no-string-throw": false,
|
||||
"no-unnecessary-callback-wrapper": false,
|
||||
"no-unnecessary-class": false,
|
||||
"no-unnecessary-generics": false,
|
||||
"no-unnecessary-qualifier": false,
|
||||
"no-unnecessary-type-assertion": false,
|
||||
"no-useless-files": false,
|
||||
"no-var-keyword": false,
|
||||
"no-var-requires": false,
|
||||
"no-void-expression": false,
|
||||
"no-trailing-whitespace": false,
|
||||
"object-literal-key-quotes": false,
|
||||
"object-literal-shorthand": false,
|
||||
"one-line": false,
|
||||
"one-variable-per-declaration": false,
|
||||
"only-arrow-functions": false,
|
||||
"prefer-conditional-expression": false,
|
||||
"prefer-const": false,
|
||||
"prefer-declare-function": false,
|
||||
"prefer-for-of": false,
|
||||
"prefer-method-signature": false,
|
||||
"prefer-template": false,
|
||||
"radix": false,
|
||||
"semicolon": false,
|
||||
"space-before-function-paren": false,
|
||||
"space-within-parens": false,
|
||||
"strict-export-declare-modifiers": false,
|
||||
"trim-file": false,
|
||||
"triple-equals": false,
|
||||
"typedef-whitespace": false,
|
||||
"unified-signatures": false,
|
||||
"void-return": false,
|
||||
"whitespace": false
|
||||
}
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
|
||||
@@ -25,4 +25,4 @@
|
||||
"index.d.ts",
|
||||
"boom-tests.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as CatbotRedis from 'catbox-redis';
|
||||
|
||||
const cache = new CatbotRedis({
|
||||
const cache = new CatbotRedis<string>({
|
||||
host: 'localhost',
|
||||
partition: 'test',
|
||||
port: 2018,
|
||||
@@ -10,3 +10,8 @@ cache.get({
|
||||
segment: 'test',
|
||||
id: 'test',
|
||||
});
|
||||
|
||||
cache.set({
|
||||
segment: 'test',
|
||||
id: 'test',
|
||||
}, 'test', 123);
|
||||
|
||||
Vendored
+1
-1
@@ -53,7 +53,7 @@ declare module 'catbox-redis' {
|
||||
sentinelName?: string;
|
||||
}
|
||||
}
|
||||
class CatboxRedis extends Client {
|
||||
class CatboxRedis<T> extends Client<T> {
|
||||
constructor(options: CatboxRedis.CatboxRedisOptions);
|
||||
}
|
||||
export = CatboxRedis;
|
||||
|
||||
@@ -1,16 +1,22 @@
|
||||
import { CacheItem, Client, Policy, EnginePrototypeOrObject } from "catbox";
|
||||
import { Client, Policy, EnginePrototypeOrObject, DecoratedResult, CachedObject } from "catbox";
|
||||
|
||||
const Memory: EnginePrototypeOrObject = {
|
||||
async start(): Promise<void> {},
|
||||
stop(): void {},
|
||||
async get(): Promise<null | CacheItem> {},
|
||||
async get(): Promise<null | CachedObject<string>> {
|
||||
return {
|
||||
item: 'asd',
|
||||
stored: 12,
|
||||
ttl: 123,
|
||||
};
|
||||
},
|
||||
async set(): Promise<void> {},
|
||||
async drop(): Promise<void> {},
|
||||
isReady(): boolean { return true; },
|
||||
validateSegmentName(segment: string): null { return null; },
|
||||
};
|
||||
|
||||
const client = new Client(Memory, { partition: 'cache' });
|
||||
const client = new Client<string>(Memory, { partition: 'cache' });
|
||||
|
||||
const cache = new Policy({
|
||||
expiresIn: 5000,
|
||||
@@ -25,3 +31,11 @@ cache.drop('foo').then(() => {});
|
||||
cache.isReady();
|
||||
|
||||
cache.stats();
|
||||
|
||||
const decoratedCache = new Policy({
|
||||
getDecoratedValue: true,
|
||||
}, client, 'cache2');
|
||||
|
||||
decoratedCache.get('test').then((a: DecoratedResult<string>) => {
|
||||
const res: string = a.value;
|
||||
});
|
||||
|
||||
Vendored
+63
-78
@@ -4,7 +4,7 @@
|
||||
// AJP <https://github.com/AJamesPhillips>
|
||||
// Rodrigo Saboya <https://github.com/saboya>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.4
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
/**
|
||||
* Client
|
||||
@@ -17,7 +17,7 @@
|
||||
* the Riak bucket, or as a key prefix in Redis and Memcached. To share the cache across multiple clients, use the same partition name.
|
||||
* @see {@link https://github.com/hapijs/catbox#client}
|
||||
*/
|
||||
export class Client implements ClientApi {
|
||||
export class Client<T> implements ClientApi<T> {
|
||||
constructor(engine: EnginePrototypeOrObject, options: ClientOptions);
|
||||
|
||||
/** start() - creates a connection to the cache server. Must be called before any other method is available. */
|
||||
@@ -28,14 +28,14 @@ export class Client implements ClientApi {
|
||||
* get(key, callback) - retrieve an item from the cache engine if found where:
|
||||
* * key - a cache key object (see [ICacheKey]).
|
||||
*/
|
||||
get(key: CacheKey): Promise<null | CachedObject>;
|
||||
get(key: CacheKey): Promise<null | CachedObject<T>>;
|
||||
/**
|
||||
* set(key, value, ttl, callback) - store an item in the cache for a specified length of time, where:
|
||||
* * key - a cache key object (see [ICacheKey]).
|
||||
* * value - the string or object value to be stored.
|
||||
* * ttl - a time-to-live value in milliseconds after which the item is automatically removed from the cache (or is marked invalid).
|
||||
*/
|
||||
set(key: CacheKey, value: CacheItem, ttl: number): Promise<void>;
|
||||
set(key: CacheKey, value: T, ttl: number): Promise<void>;
|
||||
/**
|
||||
* drop(key, callback) - remove an item from cache where:
|
||||
* * key - a cache key object (see [ICacheKey]).
|
||||
@@ -47,13 +47,13 @@ export class Client implements ClientApi {
|
||||
validateSegmentName(segment: string): null | Error;
|
||||
}
|
||||
|
||||
export type EnginePrototypeOrObject = EnginePrototype | ClientApi;
|
||||
export type EnginePrototypeOrObject = EnginePrototype<any> | ClientApi<any>;
|
||||
|
||||
/**
|
||||
* A prototype CatBox engine function
|
||||
*/
|
||||
export interface EnginePrototype {
|
||||
new(settings: ClientOptions): ClientApi;
|
||||
export interface EnginePrototype<T> {
|
||||
new(settings: ClientOptions): ClientApi<T>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,7 +61,7 @@ export interface EnginePrototype {
|
||||
* The Client object provides the following methods:
|
||||
* @see {@link https://github.com/hapijs/catbox#api}
|
||||
*/
|
||||
export interface ClientApi {
|
||||
export interface ClientApi<T> {
|
||||
/** start() - creates a connection to the cache server. Must be called before any other method is available. */
|
||||
start(): Promise<void>;
|
||||
/** stop() - terminates the connection to the cache server. */
|
||||
@@ -70,14 +70,14 @@ export interface ClientApi {
|
||||
* get(key, callback) - retrieve an item from the cache engine if found where:
|
||||
* * key - a cache key object (see [ICacheKey]).
|
||||
*/
|
||||
get(key: CacheKey): Promise<null | CachedObject>;
|
||||
get(key: CacheKey): Promise<null | CachedObject<T>>;
|
||||
/**
|
||||
* set(key, value, ttl) - store an item in the cache for a specified length of time, where:
|
||||
* * key - a cache key object (see [ICacheKey]).
|
||||
* * value - the string or object value to be stored.
|
||||
* * ttl - a time-to-live value in milliseconds after which the item is automatically removed from the cache (or is marked invalid).
|
||||
*/
|
||||
set(key: CacheKey, value: CacheItem, ttl: number): Promise<void>;
|
||||
set(key: CacheKey, value: T, ttl: number): Promise<void>;
|
||||
/**
|
||||
* drop(key) - remove an item from cache where:
|
||||
* * key - a cache key object (see [ICacheKey]).
|
||||
@@ -100,17 +100,15 @@ export interface CacheKey {
|
||||
}
|
||||
|
||||
/** Cached object contains the following: */
|
||||
export interface CachedObject {
|
||||
export interface CachedObject<T> {
|
||||
/** item - the value stored in the cache using set(). */
|
||||
item: any;
|
||||
item: T;
|
||||
/** stored - the timestamp when the item was stored in the cache (in milliseconds). */
|
||||
stored: number;
|
||||
/** ttl - the remaining time-to-live (not the original value used when storing the object). */
|
||||
ttl: number;
|
||||
}
|
||||
|
||||
export type CacheItem = any;
|
||||
|
||||
export interface ClientOptions {
|
||||
/**
|
||||
* this will store items under keys that start with this value.
|
||||
@@ -118,89 +116,69 @@ export interface ClientOptions {
|
||||
partition: string;
|
||||
}
|
||||
|
||||
export type PolicyOptionVariants<T> = PolicyOptions<T> | DecoratedPolicyOptions<T>;
|
||||
|
||||
/**
|
||||
* The Policy object provides a convenient cache interface by setting a global policy which is automatically applied to every storage action.
|
||||
* The Policy object provides a convenient cache interface by setting a
|
||||
* global policy which is automatically applied to every storage action.
|
||||
* The object is constructed using new Policy(options, [cache, segment]) where:
|
||||
* * options - an object with the IPolicyOptions structure
|
||||
* * cache - a Client instance (which has already been started).
|
||||
* * segment - required when cache is provided. The segment name used to isolate cached items within the cache partition.
|
||||
* * segment - required when cache is provided. The segment name used to
|
||||
* isolate cached items within the cache partition.
|
||||
* @see {@link https://github.com/hapijs/catbox#policy}
|
||||
*/
|
||||
export class Policy implements PolicyAPI {
|
||||
constructor(options: PolicyOptions, cache: Client, segment: string);
|
||||
export class Policy<T, O extends PolicyOptionVariants<T>> {
|
||||
constructor(options: O, cache: Client<T>, segment: string);
|
||||
/**
|
||||
* get(id) - retrieve an item from the cache. If the item is not found and the generateFunc method was provided,
|
||||
* a new value is generated, stored in the cache, and returned. Multiple concurrent requests are queued and processed once. The method arguments are:
|
||||
* * id - the unique item identifier (within the policy segment). Can be a string or an object with the required 'id' key.
|
||||
* retrieve an item from the cache. If the item is not
|
||||
* found and the generateFunc method was provided,
|
||||
* a new value is generated, stored in the cache, and returned.
|
||||
* Multiple concurrent requests are queued and processed once. The method arguments are:
|
||||
* @param id the unique item identifier (within the policy segment).
|
||||
* Can be a string or an object with the required 'id' key.
|
||||
*/
|
||||
get(id: string | { id: string }): Promise<PolicyGetPromiseResult | null>;
|
||||
get(id: string | { id: string }): Promise<O extends DecoratedPolicyOptions<T> ? DecoratedResult<T> : T | null>;
|
||||
|
||||
/**
|
||||
* set(id, value, ttl) - store an item in the cache where:
|
||||
* * id - the unique item identifier (within the policy segment).
|
||||
* * value - the string or object value to be stored.
|
||||
* * ttl - a time-to-live override value in milliseconds after which the item is automatically removed from the cache (or is marked invalid).
|
||||
* store an item in the cache where:
|
||||
* @param id - the unique item identifier (within the policy segment).
|
||||
* @param value - the string or object value to be stored.
|
||||
* @param ttl - a time-to-live override value in milliseconds after which the item is automatically
|
||||
* removed from the cache (or is marked invalid).
|
||||
* This should be set to 0 in order to use the caching rules configured when creating the Policy object.
|
||||
*/
|
||||
set(id: string | { id: string }, value: CacheItem, ttl: number | null): Promise<void>;
|
||||
set(id: string | { id: string }, value: T, ttl?: number): Promise<void>;
|
||||
/**
|
||||
* drop(id) - remove the item from cache where:
|
||||
* * id - the unique item identifier (within the policy segment).
|
||||
* remove the item from cache where:
|
||||
* @param id the unique item identifier (within the policy segment).
|
||||
*/
|
||||
drop(id: string | { id: string }): Promise<void>;
|
||||
/** ttl(created) - given a created timestamp in milliseconds, returns the time-to-live left based on the configured rules. */
|
||||
/**
|
||||
* given a created timestamp in milliseconds, returns the time-to-live left
|
||||
* based on the configured rules.
|
||||
*/
|
||||
ttl(created: number): number;
|
||||
/** rules(options) - changes the policy rules after construction (note that items already stored will not be affected) */
|
||||
rules(options: PolicyOptions): void;
|
||||
/** isReady() - returns true if cache engine determines itself as ready, false if it is not ready or if there is no cache engine set. */
|
||||
/** changes the policy rules after construction (note that items already stored will not be affected) */
|
||||
rules(options: PolicyOptions<T>): void;
|
||||
/**
|
||||
* returns true if cache engine determines itself as ready, false if it is not ready or if
|
||||
* here is no cache engine set.
|
||||
*/
|
||||
isReady(): boolean;
|
||||
/** stats - an object with cache statistics */
|
||||
/** an object with cache statistics */
|
||||
stats(): CacheStatisticsObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Policy API
|
||||
* The Policy object provides the following methods:
|
||||
* @see {@link https://github.com/hapijs/catbox#api-1}
|
||||
*/
|
||||
export interface PolicyAPI {
|
||||
/**
|
||||
* get(id) - retrieve an item from the cache. If the item is not found and the generateFunc method was provided,
|
||||
* a new value is generated, stored in the cache, and returned. Multiple concurrent requests are queued and processed once. The method arguments are:
|
||||
* * id - the unique item identifier (within the policy segment). Can be a string or an object with the required 'id' key.
|
||||
*/
|
||||
get(id: string | { id: string }): Promise<PolicyGetPromiseResult | null>;
|
||||
/**
|
||||
* set(id, value, ttl) - store an item in the cache where:
|
||||
* * id - the unique item identifier (within the policy segment).
|
||||
* * value - the string or object value to be stored.
|
||||
* * ttl - a time-to-live override value in milliseconds after which the item is automatically removed from the cache (or is marked invalid).
|
||||
* This should be set to 0 in order to use the caching rules configured when creating the Policy object.
|
||||
*/
|
||||
set(id: string | { id: string }, value: CacheItem, ttl: number | null): Promise<void>;
|
||||
/**
|
||||
* drop(id) - remove the item from cache where:
|
||||
* * id - the unique item identifier (within the policy segment).
|
||||
*/
|
||||
drop(id: string | { id: string }): Promise<void>;
|
||||
/** ttl(created) - given a created timestamp in milliseconds, returns the time-to-live left based on the configured rules. */
|
||||
ttl(created: number): number;
|
||||
/** rules(options) - changes the policy rules after construction (note that items already stored will not be affected) */
|
||||
rules(options: PolicyOptions): void;
|
||||
/** isReady() - returns true if cache engine determines itself as ready, false if it is not ready or if there is no cache engine set. */
|
||||
isReady(): boolean;
|
||||
/** stats - an object with cache statistics */
|
||||
stats(): CacheStatisticsObject;
|
||||
}
|
||||
|
||||
export interface PolicyGetPromiseResult {
|
||||
value: CacheItem;
|
||||
cached: PolicyGetCachedOptions;
|
||||
export interface DecoratedResult<T> {
|
||||
value: T;
|
||||
cached: PolicyGetCachedOptions<T>;
|
||||
report: PolicyGetReportLog;
|
||||
}
|
||||
|
||||
export interface PolicyGetCachedOptions {
|
||||
export interface PolicyGetCachedOptions<T> {
|
||||
/** item - the cached value. */
|
||||
item: CacheItem;
|
||||
item: T;
|
||||
/** stored - the timestamp when the item was stored in the cache. */
|
||||
stored: number;
|
||||
/** ttl - the cache ttl value for the record. */
|
||||
@@ -212,13 +190,13 @@ export interface PolicyGetCachedOptions {
|
||||
/**
|
||||
* @see {@link https://github.com/hapijs/catbox#policy}
|
||||
*/
|
||||
export interface PolicyOptions {
|
||||
export interface PolicyOptions<T> {
|
||||
/** expiresIn - relative expiration expressed in the number of milliseconds since the item was saved in the cache. Cannot be used together with expiresAt. */
|
||||
expiresIn?: number;
|
||||
/** expiresAt - time of day expressed in 24h notation using the 'HH:MM' format, at which point all cache records for the route expire. Uses local time. Cannot be used together with expiresIn. */
|
||||
expiresAt?: string;
|
||||
/** generateFunc - a function used to generate a new cache item if one is not found in the cache when calling get(). The method's signature is function(id, next) where: */
|
||||
generateFunc?: GenerateFunc;
|
||||
generateFunc?: GenerateFunc<T>;
|
||||
/**
|
||||
* staleIn - number of milliseconds to mark an item stored in cache as stale and attempt to regenerate it when generateFunc is provided.
|
||||
* Must be less than expiresIn. Alternatively function that returns staleIn value in milliseconds. The function signature is function(stored, ttl) where:
|
||||
@@ -242,11 +220,18 @@ export interface PolicyOptions {
|
||||
generateIgnoreWriteError?: boolean;
|
||||
/**
|
||||
* pendingGenerateTimeout - number of milliseconds while generateFunc call is in progress for a given id, before a subsequent generateFunc call is allowed.
|
||||
* Defaults to 0, no blocking of concurrent generateFunc calls beyond staleTimeout.
|
||||
* @default 0, no blocking of concurrent generateFunc calls beyond staleTimeout.
|
||||
*/
|
||||
pendingGenerateTimeout?: number;
|
||||
}
|
||||
|
||||
export interface DecoratedPolicyOptions<T> extends PolicyOptions<T> {
|
||||
/**
|
||||
* @default false
|
||||
*/
|
||||
getDecoratedValue?: boolean;
|
||||
}
|
||||
|
||||
export interface GenerateFuncFlags {
|
||||
ttl: number;
|
||||
}
|
||||
@@ -262,7 +247,7 @@ export interface GenerateFuncFlags {
|
||||
* * ttl - the cache ttl value in milliseconds. Set to 0 to skip storing in the cache. Defaults to the cache global policy.
|
||||
* @see {@link https://github.com/hapijs/catbox#policy}
|
||||
*/
|
||||
export type GenerateFunc = (id: string, flags: GenerateFuncFlags) => Promise<CacheItem>;
|
||||
export type GenerateFunc<T> = (id: string, flags: GenerateFuncFlags) => Promise<T>;
|
||||
|
||||
/**
|
||||
* An object with logging information about the generation operation containing the following keys (as relevant):
|
||||
|
||||
Vendored
+1
-1
@@ -2,7 +2,7 @@
|
||||
// Project: https://github.com/hapijs/glue
|
||||
// Definitions by: Gareth Parker <https://github.com/garfty>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.4
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
import { Server, ServerOptions } from "hapi";
|
||||
|
||||
|
||||
Vendored
+1
-1
@@ -2,7 +2,7 @@
|
||||
// Project: https://github.com/hapijs/catbox
|
||||
// Definitions by: Jason Swearingen <https://github.com/jasonswearingen>, AJP <https://github.com/AJamesPhillips>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.4
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
|
||||
@@ -23,9 +23,6 @@
|
||||
"hapi": [
|
||||
"hapi/v16"
|
||||
],
|
||||
"inert": [
|
||||
"inert/v4"
|
||||
],
|
||||
"wreck": [
|
||||
"wreck/v7"
|
||||
]
|
||||
|
||||
Vendored
+1
-1
@@ -3,7 +3,7 @@
|
||||
// Definitions by: AJP <https://github.com/AJamesPhillips>
|
||||
// Rodrigo Saboya <https://github.com/saboya>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.4
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
import { Plugin, Request, ResponseToolkit } from 'hapi';
|
||||
|
||||
|
||||
Vendored
+1
-1
@@ -3,7 +3,7 @@
|
||||
// Definitions by: Warren Seymour <https://github.com/warrenseymour>
|
||||
// Simon Schick <https://github.com/SimonSchick>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.4
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
import { Request, ResponseObject, Plugin, ResponseToolkit } from 'hapi';
|
||||
import { VerifyOptions } from 'jsonwebtoken';
|
||||
|
||||
@@ -25,9 +25,6 @@
|
||||
],
|
||||
"hapi": [
|
||||
"hapi/v16"
|
||||
],
|
||||
"inert": [
|
||||
"inert/v4"
|
||||
]
|
||||
},
|
||||
"noEmit": true,
|
||||
|
||||
Vendored
+1
-1
@@ -2,7 +2,7 @@
|
||||
// Project: https://github.com/knownasilya/hapi-decorators
|
||||
// Definitions by: Ken Howard <https://github.com/kenhowardpdx>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.4
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
import * as hapi from 'hapi';
|
||||
import * as Joi from 'joi';
|
||||
|
||||
@@ -24,9 +24,6 @@
|
||||
],
|
||||
"hapi": [
|
||||
"hapi/v16"
|
||||
],
|
||||
"inert": [
|
||||
"inert/v4"
|
||||
]
|
||||
},
|
||||
"noEmit": true,
|
||||
|
||||
Vendored
+13
-8
@@ -4,7 +4,7 @@
|
||||
// Justin Simms <https://github.com/jhsimms>
|
||||
// Simon Schick <https://github.com/SimonSchick>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.4
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
|
||||
+ +
|
||||
@@ -19,7 +19,6 @@
|
||||
/// <reference types='node' />
|
||||
|
||||
import * as Boom from 'boom';
|
||||
import * as catbox from 'catbox';
|
||||
import * as http from 'http';
|
||||
import * as https from 'https';
|
||||
import * as Shot from 'shot';
|
||||
@@ -31,6 +30,7 @@ import { MimosOptions } from 'mimos';
|
||||
import { SealOptions, SealOptionsSub } from 'iron';
|
||||
import { AnySchema, ValidationOptions } from 'joi';
|
||||
import Podium = require('podium');
|
||||
import { PolicyOptionVariants, EnginePrototypeOrObject, PolicyOptions, EnginePrototype, Policy } from 'catbox';
|
||||
|
||||
/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
|
||||
+ +
|
||||
@@ -2103,6 +2103,11 @@ export interface ServerAuth {
|
||||
test(strategy: string, request: Request): Promise<any>;
|
||||
}
|
||||
|
||||
export type CachePolicyOptions<T> = PolicyOptionVariants<T> & {
|
||||
cache?: string;
|
||||
segment?: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-servercacheoptions)
|
||||
*/
|
||||
@@ -2132,7 +2137,7 @@ export interface ServerCache {
|
||||
* @return Catbox Policy.
|
||||
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-servercacheoptions)
|
||||
*/
|
||||
(options: ServerOptionsCache): catbox.Policy;
|
||||
<T, O extends CachePolicyOptions<T> = CachePolicyOptions<T>>(options: O): Policy<T, O>;
|
||||
|
||||
/**
|
||||
* Provisions a server cache as described in server.cache where:
|
||||
@@ -2661,7 +2666,7 @@ export type ServerMethod = (...args: any[]) => Promise<any>;
|
||||
* 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 {
|
||||
export interface ServerMethodCache extends PolicyOptions<any> {
|
||||
generateTimeout: number | false;
|
||||
}
|
||||
|
||||
@@ -2690,7 +2695,7 @@ export interface ServerMethodOptions {
|
||||
* 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).
|
||||
*/
|
||||
generateKey?: (...args: any[]) => string | null;
|
||||
generateKey?(...args: any[]): string | null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2720,9 +2725,9 @@ export interface ServerMethodConfigurationObject {
|
||||
* 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 {
|
||||
export interface ServerOptionsCache extends PolicyOptions<any> {
|
||||
/** a class, a prototype function, or a catbox engine object. */
|
||||
engine?: catbox.EnginePrototypeOrObject;
|
||||
engine?: EnginePrototypeOrObject;
|
||||
|
||||
/**
|
||||
* 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
|
||||
@@ -2800,7 +2805,7 @@ export interface ServerOptions {
|
||||
* * * 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[];
|
||||
cache?: EnginePrototype<any> | ServerOptionsCache | ServerOptionsCache[];
|
||||
|
||||
/**
|
||||
* Default value: { minBytes: 1024 }.
|
||||
|
||||
@@ -8,7 +8,7 @@ const server = new Server({
|
||||
server.initialize();
|
||||
server.cache.provision({engine: require('catbox-memory'), name: 'countries' });
|
||||
|
||||
const cache: catbox.Policy = server.cache({segment: 'countries', cache: 'countries', expiresIn: 60 * 60 * 1000 });
|
||||
const cache = server.cache<string>({segment: 'countries', cache: 'countries', expiresIn: 60 * 60 * 1000 });
|
||||
cache.set('norway', 'oslo', 10 * 1000).then(() => {});
|
||||
const value = cache.get('norway').then(() => {});
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ const catboxOptions: ServerOptionsCache = {
|
||||
segment: 'countries',
|
||||
expiresIn: 60 * 60 * 1000
|
||||
};
|
||||
const cache: catbox.Policy = server.cache(catboxOptions);
|
||||
const cache = server.cache<string>(catboxOptions);
|
||||
cache.set('norway', 'oslo', 10 * 1000).then(() => {});
|
||||
|
||||
const value = cache.get('norway').then(() => {});
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
import Hapi = require('hapi');
|
||||
import Inert = require('inert');
|
||||
|
||||
const server = new Hapi.Server();
|
||||
|
||||
// from https://hapijs.com/tutorials/getting-started#creating-static-pages-and-content
|
||||
|
||||
server.register(Inert, (err) => {
|
||||
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
server.route({
|
||||
method: 'GET',
|
||||
path: '/hello',
|
||||
handler: function (request, reply) {
|
||||
reply.file('./public/hello.html');
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -8,6 +8,6 @@ var register: Hapi.PluginFunction<{}> = function (server, options, next) {
|
||||
// Assuming the Inert plugin was registered previously
|
||||
|
||||
server.path(__dirname + '../static');
|
||||
server.route({ path: '/file', method: 'GET', handler: { file: './test.html' } });
|
||||
server.route({ path: '/file', method: 'GET', handler() {} });
|
||||
next();
|
||||
};
|
||||
|
||||
@@ -22,9 +22,6 @@
|
||||
],
|
||||
"hapi": [
|
||||
"hapi/v16"
|
||||
],
|
||||
"inert": [
|
||||
"inert/v4"
|
||||
]
|
||||
},
|
||||
"noEmit": true,
|
||||
@@ -36,7 +33,6 @@
|
||||
"test/continuation/errors.ts",
|
||||
"test/getting-started/01-creating-a-server.ts",
|
||||
"test/getting-started/02-adding-routes.ts",
|
||||
"test/getting-started/03-serving-static-content.ts",
|
||||
"test/getting-started/04-using-plugins.ts",
|
||||
"test/path/catch-all.ts",
|
||||
"test/path/parameters.ts",
|
||||
|
||||
Vendored
+1
-1
@@ -4,7 +4,7 @@
|
||||
// Alexander James Phillips <https://github.com/AJamesPhillips>
|
||||
// Silas Rech <https://github.com/lenovouser>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.4
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
import {
|
||||
Plugin,
|
||||
|
||||
Vendored
+1
-1
@@ -3,7 +3,7 @@
|
||||
// Definitions by: Ivo Stratev <https://github.com/NoHomey>
|
||||
// Rodrigo Saboya <https://github.com/saboya>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.4
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
|
||||
+ +
|
||||
|
||||
Vendored
+1
-1
@@ -2,7 +2,7 @@
|
||||
// Project: https://github.com/apollostack/optics-agent-js#readme
|
||||
// Definitions by: Crevil <https://github.com/crevil>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.6
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
import { GraphQLSchema } from "graphql";
|
||||
import { Request, Response } from "express";
|
||||
|
||||
@@ -22,9 +22,6 @@
|
||||
],
|
||||
"hapi": [
|
||||
"hapi/v16"
|
||||
],
|
||||
"inert": [
|
||||
"inert/v4"
|
||||
]
|
||||
},
|
||||
"noEmit": true,
|
||||
|
||||
Vendored
+1
-1
@@ -2,7 +2,7 @@
|
||||
// Project: https://github.com/apigee-127/swagger-hapi#readme
|
||||
// Definitions by: Michael Mrowetz <https://github.com/micmro>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.4
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
/* =================== USAGE ===================
|
||||
|
||||
|
||||
@@ -22,9 +22,6 @@
|
||||
],
|
||||
"hapi": [
|
||||
"hapi/v16"
|
||||
],
|
||||
"inert": [
|
||||
"inert/v4"
|
||||
]
|
||||
},
|
||||
"noEmit": true,
|
||||
|
||||
@@ -22,9 +22,6 @@
|
||||
],
|
||||
"hapi": [
|
||||
"hapi/v16"
|
||||
],
|
||||
"inert": [
|
||||
"inert/v4"
|
||||
]
|
||||
},
|
||||
"noEmit": true,
|
||||
|
||||
@@ -22,9 +22,6 @@
|
||||
],
|
||||
"hapi": [
|
||||
"hapi/v16"
|
||||
],
|
||||
"inert": [
|
||||
"inert/v4"
|
||||
]
|
||||
},
|
||||
"noEmit": true,
|
||||
|
||||
@@ -22,9 +22,6 @@
|
||||
],
|
||||
"hapi": [
|
||||
"hapi/v16"
|
||||
],
|
||||
"inert": [
|
||||
"inert/v4"
|
||||
]
|
||||
},
|
||||
"noEmit": true,
|
||||
|
||||
Vendored
+1
-1
@@ -4,7 +4,7 @@
|
||||
// Alexander James Phillips <https://github.com/AJamesPhillips>
|
||||
// Silas Rech <https://github.com/lenovouser>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.4
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
import {
|
||||
Plugin,
|
||||
|
||||
@@ -23,9 +23,6 @@
|
||||
"hapi": [
|
||||
"hapi/v16"
|
||||
],
|
||||
"inert": [
|
||||
"inert/v4"
|
||||
],
|
||||
"vision": [
|
||||
"vision/v4"
|
||||
]
|
||||
|
||||
Vendored
+1
-1
@@ -2,7 +2,7 @@
|
||||
// Project: https://github.com/hapijs/yar#readme
|
||||
// Definitions by: Simon Schick <https://github.com/SimonSchick>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.4
|
||||
// TypeScript Version: 2.8
|
||||
// From https://github.com/hapijs/yar/blob/master/API.md
|
||||
|
||||
import {
|
||||
|
||||
Reference in New Issue
Block a user