Skip to content

Commit

Permalink
Include @theefer's work in DefinitelyTyped#16416
Browse files Browse the repository at this point in the history
  • Loading branch information
AJamesPhillips committed May 11, 2017
1 parent b5143b1 commit 1557cef
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 19 deletions.
18 changes: 10 additions & 8 deletions types/hapi/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -826,23 +826,25 @@ export interface RouteAuthAccessConfiguationObject {
/**
* For context see RouteAdditionalConfigurationOptions > cache
*/
export interface RouteCacheOptions {
export type RouteCacheOptions = {
/**
* determines the privacy flag included in client-side caching using the 'Cache-Control' header. Values are:
* * 'default' - no privacy flag. This is the default setting.
* * 'public' - mark the response as suitable for public caching.
* * 'private' - mark the response as suitable only for private caching.
*/
privacy?: 'default' | 'public' | 'private';
/** relative expiration expressed in the number of milliseconds since the item was saved in the cache. Cannot be used together with expiresAt. */
expiresIn?: number;
/** time of day expressed in 24h notation using the 'HH:MM' format, at which point all cache records for the route expire. Cannot be used together with expiresIn. */
expiresAt?: string;
/** an array of HTTP response status codes (e.g. 200) which are allowed to include a valid caching directive. Defaults to [200]. */
statuses?: [number];
statuses?: number[];
/** a string with the value of the 'Cache-Control' header when caching is disabled. Defaults to 'no-cache'. */
otherwise?: string;
}
} & ({
/** relative expiration expressed in the number of milliseconds since the item was saved in the cache. Cannot be used together with expiresAt. */
expiresIn: number;
} | {
/** time of day expressed in 24h notation using the 'HH:MM' format, at which point all cache records for the route expire. Cannot be used together with expiresIn. */
expiresAt: string;
} | {}
);

/**
* For context see RouteAdditionalConfigurationOptions > cors
Expand Down
30 changes: 30 additions & 0 deletions types/hapi/test/route/additional-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,33 @@ const user: Hapi.RouteAdditionalConfigurationOptions = {
return reply({ name: 'John' });
}
};


// Add in addition to examples in docs

var cache: Hapi.RouteCacheOptions = {
privacy: 'default',
statuses: [200, 201],
expiresIn: 5000,
};

cache = {
privacy: 'default',
statuses: [200, 201],
expiresAt: '22:44',
};

cache = {
privacy: 'default',
statuses: [200, 201],
/* typings should cause this to error, but currently does not
expiresAt: 5000,
*/
};

/* typings should cause this to error, but currently does not
var cache: Hapi.RouteCacheOptions = {
expiresIn: 5000,
expiresAt: '22:44',
};
*/
30 changes: 19 additions & 11 deletions types/hapi/v15/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,17 +470,7 @@ export interface IRouteAdditionalConfigurationOptions {
/** an object passed back to the provided handler (via this) when called. */
bind?: any;
/** if the route method is 'GET', the route can be configured to include caching directives in the response using the following options */
cache?: {
/** mines the privacy flag included in clientside caching using the 'Cache-Control' header.Values are:
fault'no privacy flag.This is the default setting.
'public'mark the response as suitable for public caching.
'private'mark the response as suitable only for private caching. */
privacy: string;
/** relative expiration expressed in the number of milliseconds since the item was saved in the cache.Cannot be used together with expiresAt. */
expiresIn: number;
/** time of day expressed in 24h notation using the 'HH:MM' format, at which point all cache records for the route expire.Cannot be used together with expiresIn. */
expiresAt: string;
};
cache?: IRouteAdditionalConfigurationCache;
/** the Cross- Origin Resource Sharing protocol allows browsers to make cross- origin API calls.CORS is required by web applications running inside a browser which are loaded from a different domain than the API server.CORS headers are disabled by default. To enable, set cors to true, or to an object with the following options: */
cors?: {
/** a strings array of allowed origin servers ('Access-Control-Allow-Origin').The array can contain any combination of fully qualified origins along with origin strings containing a wildcard '' character, or a single `''origin string. Defaults to any origin['*']`. */
Expand Down Expand Up @@ -728,6 +718,24 @@ export interface IRouteAdditionalConfigurationAuthAccess {
entity?: string;
}

export type IRouteAdditionalConfigurationCache = {
/** determines the privacy flag included in clientside caching using the 'Cache-Control' header. Values are:
'Default': no privacy flag.This is the default setting.
'public': mark the response as suitable for public caching.
'private': mark the response as suitable only for private caching. */
privacy?: 'default' | 'public' | 'private';
/** an array of HTTP response status codes (e.g. 200) which are allowed to include a valid caching directive. Defaults to [200]. */
statuses?: number[];
/** a string with the value of the 'Cache-Control' header when caching is disabled. Defaults to 'no-cache'. */
otherwise?: string;
} & ({
/** relative expiration expressed in the number of milliseconds since the item was saved in the cache. Cannot be used together with expiresAt. */
expiresIn: number;
} | {
/** time of day expressed in 24h notation using the 'HH:MM' format, at which point all cache records for the route expire. Cannot be used together with expiresIn. */
expiresAt: string;
} | {});

/** server.realm http://hapijs.com/api#serverrealm
The realm object contains server-wide or plugin-specific state that can be shared across various methods. For example, when calling server.bind(),
the active realm settings.bind property is set which is then used by routes and extensions added at the same level (server root or plugin).
Expand Down

0 comments on commit 1557cef

Please sign in to comment.