Skip to content

Commit 8fb8479

Browse files
kanongilMarsup
authored andcommitted
Cleanup http methods typings
1 parent d492bbf commit 8fb8479

File tree

4 files changed

+15
-24
lines changed

4 files changed

+15
-24
lines changed

lib/types/index.d.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,4 @@ export namespace Utils {
1818
interface Dictionary<T> {
1919
[key: string]: T;
2020
}
21-
22-
type HTTP_METHODS_PARTIAL_LOWERCASE = 'get' | 'post' | 'put' | 'patch' | 'delete' | 'options';
23-
24-
type HTTP_METHODS_PARTIAL = Uppercase<HTTP_METHODS_PARTIAL_LOWERCASE> | HTTP_METHODS_PARTIAL_LOWERCASE;
25-
26-
type HTTP_METHODS = 'HEAD' | 'head' | HTTP_METHODS_PARTIAL;
2721
}

lib/types/request.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { PluginsStates, ServerRealm } from './plugin';
99
import { ResponseValue, ResponseObject } from "./response";
1010
import { RouteRules, RouteSettings } from './route';
1111
import { Server, ServerAuthSchemeObjectApi } from './server';
12-
import { HTTP_METHODS_PARTIAL, HTTP_METHODS_PARTIAL_LOWERCASE, PeekListener } from './utils';
12+
import { HTTP_METHODS, PeekListener } from './utils';
1313

1414
/**
1515
* User extensible types user credentials.
@@ -192,7 +192,7 @@ export interface RequestInfo {
192192
*/
193193
export interface RequestRoute<Refs extends ReqRef = ReqRefDefaults> {
194194
/** the route HTTP method. */
195-
method: HTTP_METHODS_PARTIAL;
195+
method: Exclude<Lowercase<HTTP_METHODS>, 'head'> | '*';
196196

197197
/** the route path. */
198198
path: string;
@@ -374,7 +374,7 @@ export interface Request<Refs extends ReqRef = ReqRefDefaults> extends Podium {
374374
/**
375375
* The request method in lower case (e.g. 'get', 'post').
376376
*/
377-
readonly method: HTTP_METHODS_PARTIAL_LOWERCASE;
377+
readonly method: Lowercase<HTTP_METHODS>;
378378

379379
/**
380380
* The parsed content-type header. Only available when payload parsing enabled and no payload error occurred.
@@ -506,7 +506,7 @@ export interface Request<Refs extends ReqRef = ReqRefDefaults> extends Podium {
506506
* Can only be called from an 'onRequest' extension method.
507507
* [See docs](https://hapijs.com/api/17.0.1#-requestsetmethodmethod)
508508
*/
509-
setMethod(method: HTTP_METHODS_PARTIAL): void;
509+
setMethod(method: HTTP_METHODS | Lowercase<HTTP_METHODS>): void;
510510

511511
/**
512512
* Changes the request URI before the router begins processing the request where:

lib/types/route.d.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ObjectSchema, ValidationOptions, SchemaMap, Schema } from 'joi';
44
import { PluginSpecificConfiguration} from './plugin';
55
import { MergeType, ReqRef, ReqRefDefaults, MergeRefs, AuthMode } from './request';
66
import { ContentDecoders, ContentEncoders, RouteRequestExtType, RouteExtObject, Server } from './server';
7-
import { Lifecycle, Json, HTTP_METHODS_PARTIAL } from './utils';
7+
import { Lifecycle, Json, HTTP_METHODS } from './utils';
88

99
/**
1010
* Overrides for `InternalRouteOptionType`. Extend this to have
@@ -924,6 +924,8 @@ export interface RulesProcessor<Refs extends ReqRef = ReqRefDefaults> {
924924
(rules: MergeRefs<Refs>['Rules'] | null, info: RulesInfo): Partial<RouteOptions<Refs>> | null;
925925
}
926926

927+
type RouteDefMethods = Exclude<HTTP_METHODS | Lowercase<HTTP_METHODS>, 'HEAD' | 'head'>;
928+
927929
/**
928930
* A route configuration object or an array of configuration objects where each object contains:
929931
* * 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
@@ -952,7 +954,7 @@ export interface ServerRoute<Refs extends ReqRef = ReqRefDefaults> {
952954
* (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
953955
* result as adding the same route with different methods manually.
954956
*/
955-
method: HTTP_METHODS_PARTIAL | HTTP_METHODS_PARTIAL[] | string | string[];
957+
method: RouteDefMethods | RouteDefMethods[] | '*';
956958

957959
/**
958960
* (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

lib/types/utils.d.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,13 @@ import {
1111
Request} from './request';
1212
import { ResponseToolkit, Auth } from './response';
1313

14-
export type HTTP_METHODS_PARTIAL_LOWERCASE = 'get' | 'post' | 'put' | 'patch' | 'delete' | 'options';
15-
16-
export type HTTP_METHODS_PARTIAL =
17-
'GET'
18-
| 'POST'
19-
| 'PUT'
20-
| 'PATCH'
21-
| 'DELETE'
22-
| 'OPTIONS'
23-
| HTTP_METHODS_PARTIAL_LOWERCASE;
24-
25-
export type HTTP_METHODS = 'HEAD' | 'head' | HTTP_METHODS_PARTIAL;
14+
/**
15+
* All http parser [supported HTTP methods](https://nodejs.org/api/http.html#httpmethods).
16+
*/
17+
export type HTTP_METHODS = 'ACL' | 'BIND' | 'CHECKOUT' | 'CONNECT' | 'COPY' | 'DELETE' | 'GET' | 'HEAD' | 'LINK' | 'LOCK' |
18+
'M-SEARCH' | 'MERGE' | 'MKACTIVITY' | 'MKCALENDAR' | 'MKCOL' | 'MOVE' | 'NOTIFY' | 'OPTIONS' | 'PATCH' | 'POST' |
19+
'PROPFIND' | 'PROPPATCH' | 'PURGE' | 'PUT' | 'REBIND' | 'REPORT' | 'SEARCH' | 'SOURCE' | 'SUBSCRIBE' | 'TRACE' |
20+
'UNBIND' | 'UNLINK' | 'UNLOCK' | 'UNSUBSCRIBE';
2621

2722
export type PeekListener = (chunk: string, encoding: string) => void;
2823

0 commit comments

Comments
 (0)