Browse Source

chore: renames HTTP_METHOD to HttpMethod

e22m4u 1 year ago
parent
commit
ab67b886f5

+ 5 - 5
dist/cjs/index.cjs

@@ -1842,9 +1842,9 @@ __export(src_exports, {
   EXPOSED_ERROR_PROPERTIES: () => EXPOSED_ERROR_PROPERTIES,
   EXPOSED_ERROR_PROPERTIES: () => EXPOSED_ERROR_PROPERTIES,
   ErrorSender: () => ErrorSender,
   ErrorSender: () => ErrorSender,
   HOOK_NAME: () => HOOK_NAME,
   HOOK_NAME: () => HOOK_NAME,
-  HTTP_METHOD: () => HTTP_METHOD,
   HookInvoker: () => HookInvoker,
   HookInvoker: () => HookInvoker,
   HookRegistry: () => HookRegistry,
   HookRegistry: () => HookRegistry,
+  HttpMethod: () => HttpMethod,
   METHODS_WITH_BODY: () => METHODS_WITH_BODY,
   METHODS_WITH_BODY: () => METHODS_WITH_BODY,
   QueryParser: () => QueryParser,
   QueryParser: () => QueryParser,
   RequestContext: () => RequestContext,
   RequestContext: () => RequestContext,
@@ -2512,7 +2512,7 @@ var HookInvoker = class extends DebuggableService {
 };
 };
 
 
 // src/route.js
 // src/route.js
-var HTTP_METHOD = {
+var HttpMethod = {
   GET: "GET",
   GET: "GET",
   POST: "POST",
   POST: "POST",
   PUT: "PUT",
   PUT: "PUT",
@@ -3501,7 +3501,7 @@ var TrieRouter = class extends DebuggableService {
    * ```
    * ```
    * const router = new TrieRouter();
    * const router = new TrieRouter();
    * router.defineRoute({
    * router.defineRoute({
-   *   method: HTTP_METHOD.GET,        // Request method.
+   *   method: HttpMethod.GET,        // Request method.
    *   path: '/',                      // Path template.
    *   path: '/',                      // Path template.
    *   handler: ctx => 'Hello world!', // Request handler.
    *   handler: ctx => 'Hello world!', // Request handler.
    * });
    * });
@@ -3511,7 +3511,7 @@ var TrieRouter = class extends DebuggableService {
    * ```
    * ```
    * const router = new TrieRouter();
    * const router = new TrieRouter();
    * router.defineRoute({
    * router.defineRoute({
-   *   method: HTTP_METHOD.POST,       // Request method.
+   *   method: HttpMethod.POST,       // Request method.
    *   path: '/users/:id',             // The path template may have parameters.
    *   path: '/users/:id',             // The path template may have parameters.
    *   preHandler(ctx) { ... },        // The "preHandler" is executed before a route handler.
    *   preHandler(ctx) { ... },        // The "preHandler" is executed before a route handler.
    *   handler(ctx) { ... },           // Request handler function.
    *   handler(ctx) { ... },           // Request handler function.
@@ -3646,9 +3646,9 @@ var TrieRouter = class extends DebuggableService {
   EXPOSED_ERROR_PROPERTIES,
   EXPOSED_ERROR_PROPERTIES,
   ErrorSender,
   ErrorSender,
   HOOK_NAME,
   HOOK_NAME,
-  HTTP_METHOD,
   HookInvoker,
   HookInvoker,
   HookRegistry,
   HookRegistry,
+  HttpMethod,
   METHODS_WITH_BODY,
   METHODS_WITH_BODY,
   QueryParser,
   QueryParser,
   RequestContext,
   RequestContext,

+ 2 - 2
examples/cookie-parsing-example.js

@@ -1,13 +1,13 @@
 import http from 'http';
 import http from 'http';
 import {TrieRouter} from '../src/index.js';
 import {TrieRouter} from '../src/index.js';
-import {HTTP_METHOD} from '../src/route.js';
+import {HttpMethod} from '../src/route.js';
 
 
 const router = new TrieRouter();
 const router = new TrieRouter();
 
 
 // регистрация роута для вывода
 // регистрация роута для вывода
 // переданных Cookie
 // переданных Cookie
 router.defineRoute({
 router.defineRoute({
-  method: HTTP_METHOD.GET,
+  method: HttpMethod.GET,
   path: '/showCookie',
   path: '/showCookie',
   handler: ({cookie}) => cookie,
   handler: ({cookie}) => cookie,
 });
 });

+ 2 - 2
examples/params-parsing-example.js

@@ -1,13 +1,13 @@
 import http from 'http';
 import http from 'http';
 import {TrieRouter} from '../src/index.js';
 import {TrieRouter} from '../src/index.js';
-import {HTTP_METHOD} from '../src/route.js';
+import {HttpMethod} from '../src/route.js';
 
 
 const router = new TrieRouter();
 const router = new TrieRouter();
 
 
 // регистрация роута для вывода
 // регистрация роута для вывода
 // переданных параметров пути
 // переданных параметров пути
 router.defineRoute({
 router.defineRoute({
-  method: HTTP_METHOD.GET,
+  method: HttpMethod.GET,
   path: '/showParams/:p1/:p2',
   path: '/showParams/:p1/:p2',
   handler: ({params}) => params,
   handler: ({params}) => params,
 });
 });

+ 2 - 2
examples/query-parsing-example.js

@@ -1,13 +1,13 @@
 import http from 'http';
 import http from 'http';
 import {TrieRouter} from '../src/index.js';
 import {TrieRouter} from '../src/index.js';
-import {HTTP_METHOD} from '../src/route.js';
+import {HttpMethod} from '../src/route.js';
 
 
 const router = new TrieRouter();
 const router = new TrieRouter();
 
 
 // регистрация роута для вывода
 // регистрация роута для вывода
 // переданных "query" параметров
 // переданных "query" параметров
 router.defineRoute({
 router.defineRoute({
-  method: HTTP_METHOD.GET,
+  method: HttpMethod.GET,
   path: '/showQuery',
   path: '/showQuery',
   handler: ({query}) => query,
   handler: ({query}) => query,
 });
 });

+ 2 - 2
examples/uptime-example.js

@@ -1,13 +1,13 @@
 import http from 'http';
 import http from 'http';
 import {TrieRouter} from '../src/index.js';
 import {TrieRouter} from '../src/index.js';
-import {HTTP_METHOD} from '../src/route.js';
+import {HttpMethod} from '../src/route.js';
 
 
 const router = new TrieRouter();
 const router = new TrieRouter();
 
 
 // регистрация роута для вывода
 // регистрация роута для вывода
 // времени работы сервера
 // времени работы сервера
 router.defineRoute({
 router.defineRoute({
-  method: HTTP_METHOD.GET,
+  method: HttpMethod.GET,
   path: '/',
   path: '/',
   handler() {
   handler() {
     const uptimeSec = process.uptime();
     const uptimeSec = process.uptime();

+ 14 - 14
src/hooks/hook-invoker.spec.js

@@ -1,6 +1,6 @@
 import {expect} from '../chai.js';
 import {expect} from '../chai.js';
 import {Route} from '../route.js';
 import {Route} from '../route.js';
-import {HTTP_METHOD} from '../route.js';
+import {HttpMethod} from '../route.js';
 import {format} from '@e22m4u/js-format';
 import {format} from '@e22m4u/js-format';
 import {HOOK_NAME} from './hook-registry.js';
 import {HOOK_NAME} from './hook-registry.js';
 import {HookInvoker} from './hook-invoker.js';
 import {HookInvoker} from './hook-invoker.js';
@@ -33,7 +33,7 @@ describe('HookInvoker', function () {
       expect(throwable(undefined)).to.throw(error('undefined'));
       expect(throwable(undefined)).to.throw(error('undefined'));
       throwable(
       throwable(
         new Route({
         new Route({
-          method: HTTP_METHOD.GET,
+          method: HttpMethod.GET,
           path: '/',
           path: '/',
           handler: () => undefined,
           handler: () => undefined,
         }),
         }),
@@ -43,7 +43,7 @@ describe('HookInvoker', function () {
     it('requires the parameter "hookName" to be a non-empty String', function () {
     it('requires the parameter "hookName" to be a non-empty String', function () {
       const s = new HookInvoker();
       const s = new HookInvoker();
       const route = new Route({
       const route = new Route({
-        method: HTTP_METHOD.GET,
+        method: HttpMethod.GET,
         path: '/',
         path: '/',
         handler: () => undefined,
         handler: () => undefined,
       });
       });
@@ -72,7 +72,7 @@ describe('HookInvoker', function () {
     it('requires the parameter "hookName" to be a supported hook', function () {
     it('requires the parameter "hookName" to be a supported hook', function () {
       const s = new HookInvoker();
       const s = new HookInvoker();
       const route = new Route({
       const route = new Route({
-        method: HTTP_METHOD.GET,
+        method: HttpMethod.GET,
         path: '/',
         path: '/',
         handler: () => undefined,
         handler: () => undefined,
       });
       });
@@ -88,7 +88,7 @@ describe('HookInvoker', function () {
     it('requires the parameter "response" to be an instance of ServerResponse', function () {
     it('requires the parameter "response" to be an instance of ServerResponse', function () {
       const s = new HookInvoker();
       const s = new HookInvoker();
       const route = new Route({
       const route = new Route({
-        method: HTTP_METHOD.GET,
+        method: HttpMethod.GET,
         path: '/',
         path: '/',
         handler: () => undefined,
         handler: () => undefined,
       });
       });
@@ -124,7 +124,7 @@ describe('HookInvoker', function () {
         order.push('globalHook2');
         order.push('globalHook2');
       });
       });
       const route = new Route({
       const route = new Route({
-        method: HTTP_METHOD.GET,
+        method: HttpMethod.GET,
         path: '/',
         path: '/',
         preHandler: [
         preHandler: [
           () => {
           () => {
@@ -164,7 +164,7 @@ describe('HookInvoker', function () {
         order.push('globalHook3');
         order.push('globalHook3');
       });
       });
       const route = new Route({
       const route = new Route({
-        method: HTTP_METHOD.GET,
+        method: HttpMethod.GET,
         path: '/',
         path: '/',
         preHandler: [
         preHandler: [
           () => {
           () => {
@@ -196,7 +196,7 @@ describe('HookInvoker', function () {
         order.push('globalHook2');
         order.push('globalHook2');
       });
       });
       const route = new Route({
       const route = new Route({
-        method: HTTP_METHOD.GET,
+        method: HttpMethod.GET,
         path: '/',
         path: '/',
         preHandler: [
         preHandler: [
           () => {
           () => {
@@ -241,7 +241,7 @@ describe('HookInvoker', function () {
         order.push('globalHook3');
         order.push('globalHook3');
       });
       });
       const route = new Route({
       const route = new Route({
-        method: HTTP_METHOD.GET,
+        method: HttpMethod.GET,
         path: '/',
         path: '/',
         preHandler: [
         preHandler: [
           () => {
           () => {
@@ -273,7 +273,7 @@ describe('HookInvoker', function () {
         order.push('globalHook2');
         order.push('globalHook2');
       });
       });
       const route = new Route({
       const route = new Route({
-        method: HTTP_METHOD.GET,
+        method: HttpMethod.GET,
         path: '/',
         path: '/',
         preHandler: [
         preHandler: [
           () => {
           () => {
@@ -316,7 +316,7 @@ describe('HookInvoker', function () {
         order.push('globalHook3');
         order.push('globalHook3');
       });
       });
       const route = new Route({
       const route = new Route({
-        method: HTTP_METHOD.GET,
+        method: HttpMethod.GET,
         path: '/',
         path: '/',
         preHandler: [
         preHandler: [
           () => {
           () => {
@@ -354,7 +354,7 @@ describe('HookInvoker', function () {
         order.push('globalHook2');
         order.push('globalHook2');
       });
       });
       const route = new Route({
       const route = new Route({
-        method: HTTP_METHOD.GET,
+        method: HttpMethod.GET,
         path: '/',
         path: '/',
         preHandler: [
         preHandler: [
           () => {
           () => {
@@ -391,7 +391,7 @@ describe('HookInvoker', function () {
         order.push('globalHook2');
         order.push('globalHook2');
       });
       });
       const route = new Route({
       const route = new Route({
-        method: HTTP_METHOD.GET,
+        method: HttpMethod.GET,
         path: '/',
         path: '/',
         preHandler: [
         preHandler: [
           () => {
           () => {
@@ -432,7 +432,7 @@ describe('HookInvoker', function () {
         order.push('globalHook2');
         order.push('globalHook2');
       });
       });
       const route = new Route({
       const route = new Route({
-        method: HTTP_METHOD.GET,
+        method: HttpMethod.GET,
         path: '/',
         path: '/',
         preHandler: [
         preHandler: [
           async () => {
           async () => {

+ 11 - 11
src/parsers/body-parser.spec.js

@@ -1,5 +1,5 @@
 import {expect} from '../chai.js';
 import {expect} from '../chai.js';
-import {HTTP_METHOD} from '../route.js';
+import {HttpMethod} from '../route.js';
 import {format} from '@e22m4u/js-format';
 import {format} from '@e22m4u/js-format';
 import {BodyParser} from './body-parser.js';
 import {BodyParser} from './body-parser.js';
 import {METHODS_WITH_BODY} from './body-parser.js';
 import {METHODS_WITH_BODY} from './body-parser.js';
@@ -167,7 +167,7 @@ describe('BodyParser', function () {
 
 
     it('returns undefined if no "content-type" header', async function () {
     it('returns undefined if no "content-type" header', async function () {
       const parser = new BodyParser();
       const parser = new BodyParser();
-      const req = createRequestMock({method: HTTP_METHOD.POST});
+      const req = createRequestMock({method: HttpMethod.POST});
       const result = await parser.parse(req);
       const result = await parser.parse(req);
       expect(result).to.be.undefined;
       expect(result).to.be.undefined;
     });
     });
@@ -176,7 +176,7 @@ describe('BodyParser', function () {
       const parser = new BodyParser();
       const parser = new BodyParser();
       for await (const mediaType of UNPARSABLE_MEDIA_TYPES) {
       for await (const mediaType of UNPARSABLE_MEDIA_TYPES) {
         const req = createRequestMock({
         const req = createRequestMock({
-          method: HTTP_METHOD.POST,
+          method: HttpMethod.POST,
           headers: {'content-type': mediaType},
           headers: {'content-type': mediaType},
           body: 'Lorem Ipsum is simply dummy text.',
           body: 'Lorem Ipsum is simply dummy text.',
         });
         });
@@ -199,7 +199,7 @@ describe('BodyParser', function () {
     it('throws an error for unsupported media type', function () {
     it('throws an error for unsupported media type', function () {
       const parser = new BodyParser();
       const parser = new BodyParser();
       const req = createRequestMock({
       const req = createRequestMock({
-        method: HTTP_METHOD.POST,
+        method: HttpMethod.POST,
         headers: {'content-type': 'media/unknown'},
         headers: {'content-type': 'media/unknown'},
       });
       });
       const throwable = () => parser.parse(req);
       const throwable = () => parser.parse(req);
@@ -212,7 +212,7 @@ describe('BodyParser', function () {
       const parser = new BodyParser();
       const parser = new BodyParser();
       parser.getService(RouterOptions).setRequestBodyBytesLimit(1);
       parser.getService(RouterOptions).setRequestBodyBytesLimit(1);
       const req = createRequestMock({
       const req = createRequestMock({
-        method: HTTP_METHOD.POST,
+        method: HttpMethod.POST,
         headers: {
         headers: {
           'content-type': 'text/plain',
           'content-type': 'text/plain',
           'content-length': '2',
           'content-length': '2',
@@ -226,7 +226,7 @@ describe('BodyParser', function () {
       it('returns undefined if no request body', async function () {
       it('returns undefined if no request body', async function () {
         const parser = new BodyParser();
         const parser = new BodyParser();
         const req = createRequestMock({
         const req = createRequestMock({
-          method: HTTP_METHOD.POST,
+          method: HttpMethod.POST,
           headers: {'content-type': 'text/plain'},
           headers: {'content-type': 'text/plain'},
         });
         });
         const result = await parser.parse(req);
         const result = await parser.parse(req);
@@ -237,7 +237,7 @@ describe('BodyParser', function () {
         const body = 'Lorem Ipsum is simply dummy text.';
         const body = 'Lorem Ipsum is simply dummy text.';
         const parser = new BodyParser();
         const parser = new BodyParser();
         const req = createRequestMock({
         const req = createRequestMock({
-          method: HTTP_METHOD.POST,
+          method: HttpMethod.POST,
           headers: {'content-type': 'text/plain'},
           headers: {'content-type': 'text/plain'},
           body,
           body,
         });
         });
@@ -249,7 +249,7 @@ describe('BodyParser', function () {
         const body = 'Lorem Ipsum is simply dummy text.';
         const body = 'Lorem Ipsum is simply dummy text.';
         const parser = new BodyParser();
         const parser = new BodyParser();
         const req = createRequestMock({
         const req = createRequestMock({
-          method: HTTP_METHOD.POST,
+          method: HttpMethod.POST,
           headers: {'content-type': 'text/plain'},
           headers: {'content-type': 'text/plain'},
           body: Buffer.from(body, 'utf-8'),
           body: Buffer.from(body, 'utf-8'),
         });
         });
@@ -262,7 +262,7 @@ describe('BodyParser', function () {
       it('returns undefined if no request body', async function () {
       it('returns undefined if no request body', async function () {
         const parser = new BodyParser();
         const parser = new BodyParser();
         const req = createRequestMock({
         const req = createRequestMock({
-          method: HTTP_METHOD.POST,
+          method: HttpMethod.POST,
           headers: {'content-type': 'application/json'},
           headers: {'content-type': 'application/json'},
         });
         });
         const result = await parser.parse(req);
         const result = await parser.parse(req);
@@ -273,7 +273,7 @@ describe('BodyParser', function () {
         const body = {foo: 'bar'};
         const body = {foo: 'bar'};
         const parser = new BodyParser();
         const parser = new BodyParser();
         const req = createRequestMock({
         const req = createRequestMock({
-          method: HTTP_METHOD.POST,
+          method: HttpMethod.POST,
           headers: {'content-type': 'application/json'},
           headers: {'content-type': 'application/json'},
           body: JSON.stringify(body),
           body: JSON.stringify(body),
         });
         });
@@ -285,7 +285,7 @@ describe('BodyParser', function () {
         const body = {foo: 'bar'};
         const body = {foo: 'bar'};
         const parser = new BodyParser();
         const parser = new BodyParser();
         const req = createRequestMock({
         const req = createRequestMock({
-          method: HTTP_METHOD.POST,
+          method: HttpMethod.POST,
           headers: {'content-type': 'application/json'},
           headers: {'content-type': 'application/json'},
           body: Buffer.from(JSON.stringify(body)),
           body: Buffer.from(JSON.stringify(body)),
         });
         });

+ 4 - 4
src/parsers/request-parser.spec.js

@@ -1,5 +1,5 @@
 import {expect} from '../chai.js';
 import {expect} from '../chai.js';
-import {HTTP_METHOD} from '../route.js';
+import {HttpMethod} from '../route.js';
 import {format} from '@e22m4u/js-format';
 import {format} from '@e22m4u/js-format';
 import {RequestParser} from './request-parser.js';
 import {RequestParser} from './request-parser.js';
 import {createRequestMock} from '../utils/create-request-mock.js';
 import {createRequestMock} from '../utils/create-request-mock.js';
@@ -45,7 +45,7 @@ describe('RequestParser', function () {
       const s = new RequestParser();
       const s = new RequestParser();
       const body = 'Lorem Ipsum is simply dummy text.';
       const body = 'Lorem Ipsum is simply dummy text.';
       const req = createRequestMock({
       const req = createRequestMock({
-        method: HTTP_METHOD.POST,
+        method: HttpMethod.POST,
         headers: {'content-type': 'text/plain'},
         headers: {'content-type': 'text/plain'},
         body,
         body,
       });
       });
@@ -95,7 +95,7 @@ describe('RequestParser', function () {
       const s = new RequestParser();
       const s = new RequestParser();
       const body = 'Lorem Ipsum is simply dummy text.';
       const body = 'Lorem Ipsum is simply dummy text.';
       const req = createRequestMock({
       const req = createRequestMock({
-        method: HTTP_METHOD.POST,
+        method: HttpMethod.POST,
         headers: {'content-type': 'text/plain'},
         headers: {'content-type': 'text/plain'},
         body,
         body,
       });
       });
@@ -117,7 +117,7 @@ describe('RequestParser', function () {
       const body = {foo: 'bar', baz: 'qux'};
       const body = {foo: 'bar', baz: 'qux'};
       const json = JSON.stringify(body);
       const json = JSON.stringify(body);
       const req = createRequestMock({
       const req = createRequestMock({
-        method: HTTP_METHOD.POST,
+        method: HttpMethod.POST,
         headers: {'content-type': 'application/json'},
         headers: {'content-type': 'application/json'},
         body,
         body,
       });
       });

+ 7 - 7
src/route-registry.spec.js

@@ -1,6 +1,6 @@
 import {Route} from './route.js';
 import {Route} from './route.js';
 import {expect} from './chai.js';
 import {expect} from './chai.js';
-import {HTTP_METHOD} from './route.js';
+import {HttpMethod} from './route.js';
 import {format} from '@e22m4u/js-format';
 import {format} from '@e22m4u/js-format';
 import {RouteRegistry} from './route-registry.js';
 import {RouteRegistry} from './route-registry.js';
 import {ServiceContainer} from '@e22m4u/js-service';
 import {ServiceContainer} from '@e22m4u/js-service';
@@ -23,7 +23,7 @@ describe('RouteRegistry', function () {
       expect(throwable(undefined)).to.throw(error('undefined'));
       expect(throwable(undefined)).to.throw(error('undefined'));
       expect(throwable(() => undefined)).to.throw(error('Function'));
       expect(throwable(() => undefined)).to.throw(error('Function'));
       throwable({
       throwable({
-        method: HTTP_METHOD.GET,
+        method: HttpMethod.GET,
         path: '/path',
         path: '/path',
         handler: () => undefined,
         handler: () => undefined,
       })();
       })();
@@ -31,7 +31,7 @@ describe('RouteRegistry', function () {
 
 
     it('returns a new route with the given "method", "path" and "handler"', function () {
     it('returns a new route with the given "method", "path" and "handler"', function () {
       const s = new RouteRegistry();
       const s = new RouteRegistry();
-      const method = HTTP_METHOD.PATCH;
+      const method = HttpMethod.PATCH;
       const path = '/myPath';
       const path = '/myPath';
       const handler = () => undefined;
       const handler = () => undefined;
       const route = s.defineRoute({method, path, handler});
       const route = s.defineRoute({method, path, handler});
@@ -42,7 +42,7 @@ describe('RouteRegistry', function () {
 
 
     it('adds a new route to the Trie', function () {
     it('adds a new route to the Trie', function () {
       const s = new RouteRegistry();
       const s = new RouteRegistry();
-      const method = HTTP_METHOD.PATCH;
+      const method = HttpMethod.PATCH;
       const path = '/myPath';
       const path = '/myPath';
       const handler = () => undefined;
       const handler = () => undefined;
       const route = s.defineRoute({method, path, handler});
       const route = s.defineRoute({method, path, handler});
@@ -58,17 +58,17 @@ describe('RouteRegistry', function () {
       const s = new RouteRegistry(new ServiceContainer());
       const s = new RouteRegistry(new ServiceContainer());
       const handler = () => undefined;
       const handler = () => undefined;
       s.defineRoute({
       s.defineRoute({
-        method: HTTP_METHOD.GET,
+        method: HttpMethod.GET,
         path: '/foo/:p1/bar/:p2',
         path: '/foo/:p1/bar/:p2',
         handler,
         handler,
       });
       });
       const res = s.matchRouteByRequest({
       const res = s.matchRouteByRequest({
         url: '/foo/baz/bar/qux',
         url: '/foo/baz/bar/qux',
-        method: HTTP_METHOD.GET,
+        method: HttpMethod.GET,
       });
       });
       expect(typeof res).to.be.eq('object');
       expect(typeof res).to.be.eq('object');
       expect(res.route).to.be.instanceof(Route);
       expect(res.route).to.be.instanceof(Route);
-      expect(res.route.method).to.be.eq(HTTP_METHOD.GET);
+      expect(res.route.method).to.be.eq(HttpMethod.GET);
       expect(res.route.path).to.be.eq('/foo/:p1/bar/:p2');
       expect(res.route.path).to.be.eq('/foo/:p1/bar/:p2');
       expect(res.route.handler).to.be.eq(handler);
       expect(res.route.handler).to.be.eq(handler);
       expect(res.params).to.be.eql({p1: 'baz', p2: 'qux'});
       expect(res.params).to.be.eql({p1: 'baz', p2: 'qux'});

+ 1 - 1
src/route.d.ts

@@ -5,7 +5,7 @@ import {RequestContext} from './request-context.js';
 /**
 /**
  * Http method.
  * Http method.
  */
  */
-export enum HTTP_METHOD {
+export enum HttpMethod {
   GET = 'get',
   GET = 'get',
   POST = 'post',
   POST = 'post',
   PUT = 'put',
   PUT = 'put',

+ 1 - 1
src/route.js

@@ -29,7 +29,7 @@ import {getRequestPathname} from './utils/index.js';
  *   DELETE: 'DELETE',
  *   DELETE: 'DELETE',
  * }}
  * }}
  */
  */
-export const HTTP_METHOD = {
+export const HttpMethod = {
   GET: 'GET',
   GET: 'GET',
   POST: 'POST',
   POST: 'POST',
   PUT: 'PUT',
   PUT: 'PUT',

+ 16 - 16
src/route.spec.js

@@ -1,6 +1,6 @@
 import {Route} from './route.js';
 import {Route} from './route.js';
 import {expect} from './chai.js';
 import {expect} from './chai.js';
-import {HTTP_METHOD} from './route.js';
+import {HttpMethod} from './route.js';
 import {format} from '@e22m4u/js-format';
 import {format} from '@e22m4u/js-format';
 import {HOOK_NAME} from './hooks/index.js';
 import {HOOK_NAME} from './hooks/index.js';
 import {RequestContext} from './request-context.js';
 import {RequestContext} from './request-context.js';
@@ -29,7 +29,7 @@ describe('Route', function () {
       expect(throwable(undefined)).to.throw(error('undefined'));
       expect(throwable(undefined)).to.throw(error('undefined'));
       expect(throwable(() => undefined)).to.throw(error('Function'));
       expect(throwable(() => undefined)).to.throw(error('Function'));
       throwable({
       throwable({
-        method: HTTP_METHOD.GET,
+        method: HttpMethod.GET,
         path: '/',
         path: '/',
         handler: () => undefined,
         handler: () => undefined,
       })();
       })();
@@ -58,13 +58,13 @@ describe('Route', function () {
       expect(throwable([])).to.throw(error('Array'));
       expect(throwable([])).to.throw(error('Array'));
       expect(throwable(undefined)).to.throw(error('undefined'));
       expect(throwable(undefined)).to.throw(error('undefined'));
       expect(throwable(() => undefined)).to.throw(error('Function'));
       expect(throwable(() => undefined)).to.throw(error('Function'));
-      throwable(HTTP_METHOD.GET)();
+      throwable(HttpMethod.GET)();
     });
     });
 
 
     it('requires the option "path" to be a non-empty String', function () {
     it('requires the option "path" to be a non-empty String', function () {
       const throwable = v => () =>
       const throwable = v => () =>
         new Route({
         new Route({
-          method: HTTP_METHOD.GET,
+          method: HttpMethod.GET,
           path: v,
           path: v,
           handler: () => undefined,
           handler: () => undefined,
         });
         });
@@ -90,7 +90,7 @@ describe('Route', function () {
     it('requires the option "handler" to be a non-empty String', function () {
     it('requires the option "handler" to be a non-empty String', function () {
       const throwable = v => () =>
       const throwable = v => () =>
         new Route({
         new Route({
-          method: HTTP_METHOD.GET,
+          method: HttpMethod.GET,
           path: '/',
           path: '/',
           handler: v,
           handler: v,
         });
         });
@@ -116,7 +116,7 @@ describe('Route', function () {
     it('requires the option "preHandler" to be a Function or an Array of Function', function () {
     it('requires the option "preHandler" to be a Function or an Array of Function', function () {
       const throwable1 = v => () =>
       const throwable1 = v => () =>
         new Route({
         new Route({
-          method: HTTP_METHOD.GET,
+          method: HttpMethod.GET,
           path: '/',
           path: '/',
           preHandler: v,
           preHandler: v,
           handler: () => undefined,
           handler: () => undefined,
@@ -136,7 +136,7 @@ describe('Route', function () {
       throwable1(undefined)();
       throwable1(undefined)();
       const throwable2 = v => () =>
       const throwable2 = v => () =>
         new Route({
         new Route({
-          method: HTTP_METHOD.GET,
+          method: HttpMethod.GET,
           path: '/',
           path: '/',
           preHandler: [v],
           preHandler: [v],
           handler: () => undefined,
           handler: () => undefined,
@@ -157,7 +157,7 @@ describe('Route', function () {
     it('requires the option "postHandler" to be a Function or an Array of Function', function () {
     it('requires the option "postHandler" to be a Function or an Array of Function', function () {
       const throwable1 = v => () =>
       const throwable1 = v => () =>
         new Route({
         new Route({
-          method: HTTP_METHOD.GET,
+          method: HttpMethod.GET,
           path: '/',
           path: '/',
           handler: () => undefined,
           handler: () => undefined,
           postHandler: v,
           postHandler: v,
@@ -177,7 +177,7 @@ describe('Route', function () {
       throwable1(undefined)();
       throwable1(undefined)();
       const throwable2 = v => () =>
       const throwable2 = v => () =>
         new Route({
         new Route({
-          method: HTTP_METHOD.GET,
+          method: HttpMethod.GET,
           path: '/',
           path: '/',
           handler: () => undefined,
           handler: () => undefined,
           postHandler: [v],
           postHandler: [v],
@@ -207,7 +207,7 @@ describe('Route', function () {
     it('sets the option "path" to the "path" property', function () {
     it('sets the option "path" to the "path" property', function () {
       const value = '/myPath';
       const value = '/myPath';
       const route = new Route({
       const route = new Route({
-        method: HTTP_METHOD.GET,
+        method: HttpMethod.GET,
         path: value,
         path: value,
         handler: () => undefined,
         handler: () => undefined,
       });
       });
@@ -217,7 +217,7 @@ describe('Route', function () {
     it('sets the option "handler" to the "handler" property', function () {
     it('sets the option "handler" to the "handler" property', function () {
       const value = () => undefined;
       const value = () => undefined;
       const route = new Route({
       const route = new Route({
-        method: HTTP_METHOD.GET,
+        method: HttpMethod.GET,
         path: '/',
         path: '/',
         handler: value,
         handler: value,
       });
       });
@@ -227,7 +227,7 @@ describe('Route', function () {
     it('adds a Function to "preHandler" hooks', function () {
     it('adds a Function to "preHandler" hooks', function () {
       const value = () => undefined;
       const value = () => undefined;
       const route = new Route({
       const route = new Route({
-        method: HTTP_METHOD.GET,
+        method: HttpMethod.GET,
         path: '/',
         path: '/',
         preHandler: value,
         preHandler: value,
         handler: () => undefined,
         handler: () => undefined,
@@ -239,7 +239,7 @@ describe('Route', function () {
     it('adds Function items of an Array to "preHandler" hooks', function () {
     it('adds Function items of an Array to "preHandler" hooks', function () {
       const value = [() => undefined, () => undefined];
       const value = [() => undefined, () => undefined];
       const route = new Route({
       const route = new Route({
-        method: HTTP_METHOD.GET,
+        method: HttpMethod.GET,
         path: '/',
         path: '/',
         preHandler: value,
         preHandler: value,
         handler: () => undefined,
         handler: () => undefined,
@@ -253,7 +253,7 @@ describe('Route', function () {
     it('adds a Function to "postHandler" hooks', function () {
     it('adds a Function to "postHandler" hooks', function () {
       const value = () => undefined;
       const value = () => undefined;
       const route = new Route({
       const route = new Route({
-        method: HTTP_METHOD.GET,
+        method: HttpMethod.GET,
         path: '/',
         path: '/',
         handler: () => undefined,
         handler: () => undefined,
         postHandler: value,
         postHandler: value,
@@ -265,7 +265,7 @@ describe('Route', function () {
     it('adds Function items of an Array to "postHandler" hooks', function () {
     it('adds Function items of an Array to "postHandler" hooks', function () {
       const value = [() => undefined, () => undefined];
       const value = [() => undefined, () => undefined];
       const route = new Route({
       const route = new Route({
-        method: HTTP_METHOD.GET,
+        method: HttpMethod.GET,
         path: '/',
         path: '/',
         handler: () => undefined,
         handler: () => undefined,
         postHandler: value,
         postHandler: value,
@@ -284,7 +284,7 @@ describe('Route', function () {
         return 'OK';
         return 'OK';
       };
       };
       const route = new Route({
       const route = new Route({
-        method: HTTP_METHOD.GET,
+        method: HttpMethod.GET,
         path: '/',
         path: '/',
         handler,
         handler,
       });
       });

+ 2 - 2
src/trie-router.d.ts

@@ -16,7 +16,7 @@ export declare class TrieRouter extends DebuggableService {
    * ```
    * ```
    * const router = new TrieRouter();
    * const router = new TrieRouter();
    * router.defineRoute({
    * router.defineRoute({
-   *   method: HTTP_METHOD.GET,        // Request method.
+   *   method: HttpMethod.GET,        // Request method.
    *   path: '/',                      // Path template.
    *   path: '/',                      // Path template.
    *   handler: ctx => 'Hello world!', // Request handler.
    *   handler: ctx => 'Hello world!', // Request handler.
    * });
    * });
@@ -26,7 +26,7 @@ export declare class TrieRouter extends DebuggableService {
    * ```
    * ```
    * const router = new TrieRouter();
    * const router = new TrieRouter();
    * router.defineRoute({
    * router.defineRoute({
-   *   method: HTTP_METHOD.POST,       // Request method.
+   *   method: HttpMethod.POST,       // Request method.
    *   path: '/users/:id',             // The path template may have parameters.
    *   path: '/users/:id',             // The path template may have parameters.
    *   preHandler(ctx) { ... },        // The "preHandler" is executed before a route handler.
    *   preHandler(ctx) { ... },        // The "preHandler" is executed before a route handler.
    *   handler(ctx) { ... },           // Request handler function.
    *   handler(ctx) { ... },           // Request handler function.

+ 2 - 2
src/trie-router.js

@@ -21,7 +21,7 @@ export class TrieRouter extends DebuggableService {
    * ```
    * ```
    * const router = new TrieRouter();
    * const router = new TrieRouter();
    * router.defineRoute({
    * router.defineRoute({
-   *   method: HTTP_METHOD.GET,        // Request method.
+   *   method: HttpMethod.GET,        // Request method.
    *   path: '/',                      // Path template.
    *   path: '/',                      // Path template.
    *   handler: ctx => 'Hello world!', // Request handler.
    *   handler: ctx => 'Hello world!', // Request handler.
    * });
    * });
@@ -31,7 +31,7 @@ export class TrieRouter extends DebuggableService {
    * ```
    * ```
    * const router = new TrieRouter();
    * const router = new TrieRouter();
    * router.defineRoute({
    * router.defineRoute({
-   *   method: HTTP_METHOD.POST,       // Request method.
+   *   method: HttpMethod.POST,       // Request method.
    *   path: '/users/:id',             // The path template may have parameters.
    *   path: '/users/:id',             // The path template may have parameters.
    *   preHandler(ctx) { ... },        // The "preHandler" is executed before a route handler.
    *   preHandler(ctx) { ... },        // The "preHandler" is executed before a route handler.
    *   handler(ctx) { ... },           // Request handler function.
    *   handler(ctx) { ... },           // Request handler function.

+ 23 - 23
src/trie-router.spec.js

@@ -1,7 +1,7 @@
 import {describe} from 'mocha';
 import {describe} from 'mocha';
 import {Route} from './route.js';
 import {Route} from './route.js';
 import {expect} from './chai.js';
 import {expect} from './chai.js';
-import {HTTP_METHOD} from './route.js';
+import {HttpMethod} from './route.js';
 import {TrieRouter} from './trie-router.js';
 import {TrieRouter} from './trie-router.js';
 import {HOOK_NAME} from './hooks/index.js';
 import {HOOK_NAME} from './hooks/index.js';
 import {HookRegistry} from './hooks/index.js';
 import {HookRegistry} from './hooks/index.js';
@@ -17,9 +17,9 @@ describe('TrieRouter', function () {
       const router = new TrieRouter();
       const router = new TrieRouter();
       const path = '/path';
       const path = '/path';
       const handler = () => 'ok';
       const handler = () => 'ok';
-      const res = router.defineRoute({method: HTTP_METHOD.GET, path, handler});
+      const res = router.defineRoute({method: HttpMethod.GET, path, handler});
       expect(res).to.be.instanceof(Route);
       expect(res).to.be.instanceof(Route);
-      expect(res.method).to.be.eq(HTTP_METHOD.GET);
+      expect(res.method).to.be.eq(HttpMethod.GET);
       expect(res.path).to.be.eq(path);
       expect(res.path).to.be.eq(path);
       expect(res.handler).to.be.eq(handler);
       expect(res.handler).to.be.eq(handler);
     });
     });
@@ -34,7 +34,7 @@ describe('TrieRouter', function () {
     it('passes request context to the route handler', function (done) {
     it('passes request context to the route handler', function (done) {
       const router = new TrieRouter();
       const router = new TrieRouter();
       router.defineRoute({
       router.defineRoute({
-        method: HTTP_METHOD.GET,
+        method: HttpMethod.GET,
         path: '/test',
         path: '/test',
         handler: ctx => {
         handler: ctx => {
           expect(ctx).to.be.instanceof(RequestContext);
           expect(ctx).to.be.instanceof(RequestContext);
@@ -49,7 +49,7 @@ describe('TrieRouter', function () {
     it('passes path parameters to the request context', function (done) {
     it('passes path parameters to the request context', function (done) {
       const router = new TrieRouter();
       const router = new TrieRouter();
       router.defineRoute({
       router.defineRoute({
-        method: HTTP_METHOD.GET,
+        method: HttpMethod.GET,
         path: '/:p1-:p2',
         path: '/:p1-:p2',
         handler: ({params}) => {
         handler: ({params}) => {
           expect(params).to.be.eql({p1: 'foo', p2: 'bar'});
           expect(params).to.be.eql({p1: 'foo', p2: 'bar'});
@@ -64,7 +64,7 @@ describe('TrieRouter', function () {
     it('passes query parameters to the request context', function (done) {
     it('passes query parameters to the request context', function (done) {
       const router = new TrieRouter();
       const router = new TrieRouter();
       router.defineRoute({
       router.defineRoute({
-        method: HTTP_METHOD.GET,
+        method: HttpMethod.GET,
         path: '/',
         path: '/',
         handler: ({query}) => {
         handler: ({query}) => {
           expect(query).to.be.eql({p1: 'foo', p2: 'bar'});
           expect(query).to.be.eql({p1: 'foo', p2: 'bar'});
@@ -79,7 +79,7 @@ describe('TrieRouter', function () {
     it('passes parsed cookie to the request context', function (done) {
     it('passes parsed cookie to the request context', function (done) {
       const router = new TrieRouter();
       const router = new TrieRouter();
       router.defineRoute({
       router.defineRoute({
-        method: HTTP_METHOD.GET,
+        method: HttpMethod.GET,
         path: '/',
         path: '/',
         handler: ({cookie}) => {
         handler: ({cookie}) => {
           expect(cookie).to.be.eql({p1: 'foo', p2: 'bar'});
           expect(cookie).to.be.eql({p1: 'foo', p2: 'bar'});
@@ -95,14 +95,14 @@ describe('TrieRouter', function () {
       const router = new TrieRouter();
       const router = new TrieRouter();
       const body = 'Lorem Ipsum is simply dummy text.';
       const body = 'Lorem Ipsum is simply dummy text.';
       router.defineRoute({
       router.defineRoute({
-        method: HTTP_METHOD.POST,
+        method: HttpMethod.POST,
         path: '/',
         path: '/',
         handler: ctx => {
         handler: ctx => {
           expect(ctx.body).to.be.eq(body);
           expect(ctx.body).to.be.eq(body);
           done();
           done();
         },
         },
       });
       });
-      const req = createRequestMock({method: HTTP_METHOD.POST, body});
+      const req = createRequestMock({method: HttpMethod.POST, body});
       const res = createResponseMock();
       const res = createResponseMock();
       router.requestListener(req, res);
       router.requestListener(req, res);
     });
     });
@@ -111,14 +111,14 @@ describe('TrieRouter', function () {
       const router = new TrieRouter();
       const router = new TrieRouter();
       const data = {p1: 'foo', p2: 'bar'};
       const data = {p1: 'foo', p2: 'bar'};
       router.defineRoute({
       router.defineRoute({
-        method: HTTP_METHOD.POST,
+        method: HttpMethod.POST,
         path: '/',
         path: '/',
         handler: ({body}) => {
         handler: ({body}) => {
           expect(body).to.be.eql(data);
           expect(body).to.be.eql(data);
           done();
           done();
         },
         },
       });
       });
-      const req = createRequestMock({method: HTTP_METHOD.POST, body: data});
+      const req = createRequestMock({method: HttpMethod.POST, body: data});
       const res = createResponseMock();
       const res = createResponseMock();
       router.requestListener(req, res);
       router.requestListener(req, res);
     });
     });
@@ -126,7 +126,7 @@ describe('TrieRouter', function () {
     it('passes headers to the request context', function (done) {
     it('passes headers to the request context', function (done) {
       const router = new TrieRouter();
       const router = new TrieRouter();
       router.defineRoute({
       router.defineRoute({
-        method: HTTP_METHOD.GET,
+        method: HttpMethod.GET,
         path: '/',
         path: '/',
         handler: ({headers}) => {
         handler: ({headers}) => {
           expect(headers).to.be.eql({
           expect(headers).to.be.eql({
@@ -145,7 +145,7 @@ describe('TrieRouter', function () {
       const router = new TrieRouter();
       const router = new TrieRouter();
       const resBody = 'Lorem Ipsum is simply dummy text.';
       const resBody = 'Lorem Ipsum is simply dummy text.';
       router.defineRoute({
       router.defineRoute({
-        method: HTTP_METHOD.GET,
+        method: HttpMethod.GET,
         path: '/',
         path: '/',
         handler: () => resBody,
         handler: () => resBody,
       });
       });
@@ -165,7 +165,7 @@ describe('TrieRouter', function () {
       const router = new TrieRouter();
       const router = new TrieRouter();
       const error = new Error();
       const error = new Error();
       router.defineRoute({
       router.defineRoute({
-        method: HTTP_METHOD.GET,
+        method: HttpMethod.GET,
         path: '/',
         path: '/',
         handler: () => {
         handler: () => {
           throw error;
           throw error;
@@ -190,7 +190,7 @@ describe('TrieRouter', function () {
         const order = [];
         const order = [];
         const body = 'OK';
         const body = 'OK';
         router.defineRoute({
         router.defineRoute({
-          method: HTTP_METHOD.GET,
+          method: HttpMethod.GET,
           path: '/',
           path: '/',
           preHandler: [
           preHandler: [
             () => {
             () => {
@@ -218,7 +218,7 @@ describe('TrieRouter', function () {
         const order = [];
         const order = [];
         const body = 'OK';
         const body = 'OK';
         router.defineRoute({
         router.defineRoute({
-          method: HTTP_METHOD.GET,
+          method: HttpMethod.GET,
           path: '/',
           path: '/',
           handler: () => {
           handler: () => {
             order.push('handler');
             order.push('handler');
@@ -246,7 +246,7 @@ describe('TrieRouter', function () {
         const order = [];
         const order = [];
         const body = 'OK';
         const body = 'OK';
         router.defineRoute({
         router.defineRoute({
-          method: HTTP_METHOD.GET,
+          method: HttpMethod.GET,
           path: '/',
           path: '/',
           preHandler: [
           preHandler: [
             ctx => {
             ctx => {
@@ -278,7 +278,7 @@ describe('TrieRouter', function () {
         const body = 'OK';
         const body = 'OK';
         let requestContext;
         let requestContext;
         router.defineRoute({
         router.defineRoute({
-          method: HTTP_METHOD.GET,
+          method: HttpMethod.GET,
           path: '/',
           path: '/',
           handler: ctx => {
           handler: ctx => {
             order.push('handler');
             order.push('handler');
@@ -312,7 +312,7 @@ describe('TrieRouter', function () {
         const order = [];
         const order = [];
         const body = 'OK';
         const body = 'OK';
         router.defineRoute({
         router.defineRoute({
-          method: HTTP_METHOD.GET,
+          method: HttpMethod.GET,
           path: '/',
           path: '/',
           preHandler: [
           preHandler: [
             () => {
             () => {
@@ -342,7 +342,7 @@ describe('TrieRouter', function () {
         const order = [];
         const order = [];
         const body = 'OK';
         const body = 'OK';
         router.defineRoute({
         router.defineRoute({
-          method: HTTP_METHOD.GET,
+          method: HttpMethod.GET,
           path: '/',
           path: '/',
           handler: () => {
           handler: () => {
             order.push('handler');
             order.push('handler');
@@ -374,7 +374,7 @@ describe('TrieRouter', function () {
         const handlerBody = 'bar';
         const handlerBody = 'bar';
         const postHandlerBody = 'baz';
         const postHandlerBody = 'baz';
         router.defineRoute({
         router.defineRoute({
-          method: HTTP_METHOD.GET,
+          method: HttpMethod.GET,
           path: '/',
           path: '/',
           preHandler() {
           preHandler() {
             order.push('preHandler');
             order.push('preHandler');
@@ -405,7 +405,7 @@ describe('TrieRouter', function () {
         const handlerBody = 'foo';
         const handlerBody = 'foo';
         const postHandlerBody = 'bar';
         const postHandlerBody = 'bar';
         router.defineRoute({
         router.defineRoute({
-          method: HTTP_METHOD.GET,
+          method: HttpMethod.GET,
           path: '/',
           path: '/',
           preHandler() {
           preHandler() {
             order.push('preHandler');
             order.push('preHandler');
@@ -433,7 +433,7 @@ describe('TrieRouter', function () {
         const order = [];
         const order = [];
         const body = 'OK';
         const body = 'OK';
         router.defineRoute({
         router.defineRoute({
-          method: HTTP_METHOD.GET,
+          method: HttpMethod.GET,
           path: '/',
           path: '/',
           preHandler() {
           preHandler() {
             order.push('preHandler');
             order.push('preHandler');