@e22m4u/js-trie-router 0.0.7 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README-ru.md +1 -1
- package/dist/cjs/index.cjs +20 -61
- package/examples/cookie-parsing-example.js +2 -2
- package/examples/params-parsing-example.js +2 -2
- package/examples/query-parsing-example.js +2 -2
- package/examples/uptime-example.js +2 -2
- package/package.json +1 -1
- package/src/{service.d.ts → debuggable-service.d.ts} +3 -3
- package/src/{service.js → debuggable-service.js} +3 -3
- package/src/{service.spec.js → debuggable-service.spec.js} +3 -3
- package/src/hooks/hook-invoker.d.ts +2 -2
- package/src/hooks/hook-invoker.js +2 -2
- package/src/hooks/hook-invoker.spec.js +14 -14
- package/src/hooks/hook-registry.d.ts +2 -2
- package/src/hooks/hook-registry.js +2 -2
- package/src/index.d.ts +8 -1
- package/src/index.js +2 -3
- package/src/parsers/body-parser.d.ts +2 -2
- package/src/parsers/body-parser.js +2 -2
- package/src/parsers/body-parser.spec.js +11 -11
- package/src/parsers/cookie-parser.d.ts +3 -9
- package/src/parsers/cookie-parser.js +2 -2
- package/src/parsers/query-parser.d.ts +2 -2
- package/src/parsers/query-parser.js +2 -2
- package/src/parsers/request-parser.d.ts +3 -3
- package/src/parsers/request-parser.js +2 -2
- package/src/parsers/request-parser.spec.js +4 -4
- package/src/request-context.d.ts +1 -1
- package/src/route-registry.d.ts +2 -2
- package/src/route-registry.js +2 -2
- package/src/route-registry.spec.js +7 -7
- package/src/route.d.ts +1 -1
- package/src/route.js +1 -1
- package/src/route.spec.js +16 -16
- package/src/router-options.d.ts +2 -2
- package/src/router-options.js +2 -2
- package/src/senders/data-sender.d.ts +2 -2
- package/src/senders/data-sender.js +2 -2
- package/src/senders/error-sender.d.ts +2 -2
- package/src/senders/error-sender.js +2 -2
- package/src/trie-router.d.ts +4 -4
- package/src/trie-router.js +4 -4
- package/src/trie-router.spec.js +23 -23
package/README-ru.md
CHANGED
|
@@ -236,7 +236,7 @@ router.addHook('postHandler', (ctx, data) => {
|
|
|
236
236
|
|
|
237
237
|
## Отладка
|
|
238
238
|
|
|
239
|
-
Установка переменной `DEBUG`
|
|
239
|
+
Установка переменной `DEBUG` включает вывод логов.
|
|
240
240
|
|
|
241
241
|
```bash
|
|
242
242
|
DEBUG=jsTrieRouter* npm run test
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1836,16 +1836,15 @@ var require_dist = __commonJS({
|
|
|
1836
1836
|
// src/index.js
|
|
1837
1837
|
var src_exports = {};
|
|
1838
1838
|
__export(src_exports, {
|
|
1839
|
-
BUFFER_ENCODING_LIST: () => BUFFER_ENCODING_LIST,
|
|
1840
1839
|
BodyParser: () => BodyParser,
|
|
1841
1840
|
CookieParser: () => CookieParser,
|
|
1842
1841
|
DataSender: () => DataSender,
|
|
1843
1842
|
EXPOSED_ERROR_PROPERTIES: () => EXPOSED_ERROR_PROPERTIES,
|
|
1844
1843
|
ErrorSender: () => ErrorSender,
|
|
1845
1844
|
HOOK_NAME: () => HOOK_NAME,
|
|
1846
|
-
HTTP_METHOD: () => HTTP_METHOD,
|
|
1847
1845
|
HookInvoker: () => HookInvoker,
|
|
1848
1846
|
HookRegistry: () => HookRegistry,
|
|
1847
|
+
HttpMethod: () => HttpMethod,
|
|
1849
1848
|
METHODS_WITH_BODY: () => METHODS_WITH_BODY,
|
|
1850
1849
|
QueryParser: () => QueryParser,
|
|
1851
1850
|
RequestContext: () => RequestContext,
|
|
@@ -1855,18 +1854,7 @@ __export(src_exports, {
|
|
|
1855
1854
|
RouterOptions: () => RouterOptions,
|
|
1856
1855
|
TrieRouter: () => TrieRouter,
|
|
1857
1856
|
UNPARSABLE_MEDIA_TYPES: () => UNPARSABLE_MEDIA_TYPES,
|
|
1858
|
-
|
|
1859
|
-
createDebugger: () => createDebugger,
|
|
1860
|
-
createError: () => createError,
|
|
1861
|
-
fetchRequestBody: () => fetchRequestBody,
|
|
1862
|
-
getRequestPathname: () => getRequestPathname,
|
|
1863
|
-
isPromise: () => isPromise,
|
|
1864
|
-
isReadableStream: () => isReadableStream,
|
|
1865
|
-
isResponseSent: () => isResponseSent,
|
|
1866
|
-
isWritableStream: () => isWritableStream,
|
|
1867
|
-
parseCookie: () => parseCookie,
|
|
1868
|
-
parseJsonBody: () => parseJsonBody,
|
|
1869
|
-
toCamelCase: () => toCamelCase
|
|
1857
|
+
parseJsonBody: () => parseJsonBody
|
|
1870
1858
|
});
|
|
1871
1859
|
module.exports = __toCommonJS(src_exports);
|
|
1872
1860
|
|
|
@@ -2161,23 +2149,6 @@ function fetchRequestBody(req, bodyBytesLimit = 0) {
|
|
|
2161
2149
|
});
|
|
2162
2150
|
}
|
|
2163
2151
|
|
|
2164
|
-
// src/utils/create-cookie-string.js
|
|
2165
|
-
function createCookieString(data) {
|
|
2166
|
-
if (!data || typeof data !== "object" || Array.isArray(data))
|
|
2167
|
-
throw new Errorf(
|
|
2168
|
-
'The first parameter of "createCookieString" should be an Object, but %v given.',
|
|
2169
|
-
data
|
|
2170
|
-
);
|
|
2171
|
-
let cookies = "";
|
|
2172
|
-
for (const key in data) {
|
|
2173
|
-
if (!Object.prototype.hasOwnProperty.call(data, key)) continue;
|
|
2174
|
-
const val = data[key];
|
|
2175
|
-
if (val == null) continue;
|
|
2176
|
-
cookies += `${key}=${val}; `;
|
|
2177
|
-
}
|
|
2178
|
-
return cookies.trim();
|
|
2179
|
-
}
|
|
2180
|
-
|
|
2181
2152
|
// src/utils/get-request-pathname.js
|
|
2182
2153
|
function getRequestPathname(req) {
|
|
2183
2154
|
if (!req || typeof req !== "object" || Array.isArray(req) || typeof req.url !== "string") {
|
|
@@ -2388,8 +2359,8 @@ var Service = class {
|
|
|
2388
2359
|
}
|
|
2389
2360
|
};
|
|
2390
2361
|
|
|
2391
|
-
// src/service.js
|
|
2392
|
-
var
|
|
2362
|
+
// src/debuggable-service.js
|
|
2363
|
+
var DebuggableService = class extends Service {
|
|
2393
2364
|
/**
|
|
2394
2365
|
* Debug.
|
|
2395
2366
|
*
|
|
@@ -2414,7 +2385,7 @@ var HOOK_NAME = {
|
|
|
2414
2385
|
PRE_HANDLER: "preHandler",
|
|
2415
2386
|
POST_HANDLER: "postHandler"
|
|
2416
2387
|
};
|
|
2417
|
-
var HookRegistry = class extends
|
|
2388
|
+
var HookRegistry = class extends DebuggableService {
|
|
2418
2389
|
/**
|
|
2419
2390
|
* Hooks.
|
|
2420
2391
|
*
|
|
@@ -2482,7 +2453,7 @@ var HookRegistry = class extends Service2 {
|
|
|
2482
2453
|
};
|
|
2483
2454
|
|
|
2484
2455
|
// src/hooks/hook-invoker.js
|
|
2485
|
-
var HookInvoker = class extends
|
|
2456
|
+
var HookInvoker = class extends DebuggableService {
|
|
2486
2457
|
/**
|
|
2487
2458
|
* Invoke and continue until value received.
|
|
2488
2459
|
*
|
|
@@ -2541,7 +2512,7 @@ var HookInvoker = class extends Service2 {
|
|
|
2541
2512
|
};
|
|
2542
2513
|
|
|
2543
2514
|
// src/route.js
|
|
2544
|
-
var
|
|
2515
|
+
var HttpMethod = {
|
|
2545
2516
|
GET: "GET",
|
|
2546
2517
|
POST: "POST",
|
|
2547
2518
|
PUT: "PUT",
|
|
@@ -2670,7 +2641,7 @@ var Route = class {
|
|
|
2670
2641
|
};
|
|
2671
2642
|
|
|
2672
2643
|
// src/senders/data-sender.js
|
|
2673
|
-
var DataSender = class extends
|
|
2644
|
+
var DataSender = class extends DebuggableService {
|
|
2674
2645
|
/**
|
|
2675
2646
|
* Send.
|
|
2676
2647
|
*
|
|
@@ -2726,7 +2697,7 @@ var DataSender = class extends Service2 {
|
|
|
2726
2697
|
var import_util = require("util");
|
|
2727
2698
|
var import_statuses = __toESM(require_statuses(), 1);
|
|
2728
2699
|
var EXPOSED_ERROR_PROPERTIES = ["code", "details"];
|
|
2729
|
-
var ErrorSender = class extends
|
|
2700
|
+
var ErrorSender = class extends DebuggableService {
|
|
2730
2701
|
/**
|
|
2731
2702
|
* Handle.
|
|
2732
2703
|
*
|
|
@@ -2800,7 +2771,7 @@ var ErrorSender = class extends Service2 {
|
|
|
2800
2771
|
var import_http_errors2 = __toESM(require_http_errors(), 1);
|
|
2801
2772
|
|
|
2802
2773
|
// src/router-options.js
|
|
2803
|
-
var RouterOptions = class extends
|
|
2774
|
+
var RouterOptions = class extends DebuggableService {
|
|
2804
2775
|
/**
|
|
2805
2776
|
* Request body bytes limit.
|
|
2806
2777
|
*
|
|
@@ -2837,7 +2808,7 @@ var RouterOptions = class extends Service2 {
|
|
|
2837
2808
|
// src/parsers/body-parser.js
|
|
2838
2809
|
var METHODS_WITH_BODY = ["POST", "PUT", "PATCH", "DELETE"];
|
|
2839
2810
|
var UNPARSABLE_MEDIA_TYPES = ["multipart/form-data"];
|
|
2840
|
-
var BodyParser = class extends
|
|
2811
|
+
var BodyParser = class extends DebuggableService {
|
|
2841
2812
|
/**
|
|
2842
2813
|
* Parsers.
|
|
2843
2814
|
*
|
|
@@ -2961,7 +2932,7 @@ function parseJsonBody(input) {
|
|
|
2961
2932
|
|
|
2962
2933
|
// src/parsers/query-parser.js
|
|
2963
2934
|
var import_querystring = __toESM(require("querystring"), 1);
|
|
2964
|
-
var QueryParser = class extends
|
|
2935
|
+
var QueryParser = class extends DebuggableService {
|
|
2965
2936
|
/**
|
|
2966
2937
|
* Parse
|
|
2967
2938
|
*
|
|
@@ -2988,7 +2959,7 @@ var QueryParser = class extends Service2 {
|
|
|
2988
2959
|
};
|
|
2989
2960
|
|
|
2990
2961
|
// src/parsers/cookie-parser.js
|
|
2991
|
-
var CookieParser = class extends
|
|
2962
|
+
var CookieParser = class extends DebuggableService {
|
|
2992
2963
|
/**
|
|
2993
2964
|
* Parse
|
|
2994
2965
|
*
|
|
@@ -3016,7 +2987,7 @@ var CookieParser = class extends Service2 {
|
|
|
3016
2987
|
|
|
3017
2988
|
// src/parsers/request-parser.js
|
|
3018
2989
|
var import_http2 = require("http");
|
|
3019
|
-
var RequestParser = class extends
|
|
2990
|
+
var RequestParser = class extends DebuggableService {
|
|
3020
2991
|
/**
|
|
3021
2992
|
* Parse.
|
|
3022
2993
|
*
|
|
@@ -3329,7 +3300,7 @@ var PathTrie = class {
|
|
|
3329
3300
|
};
|
|
3330
3301
|
|
|
3331
3302
|
// src/route-registry.js
|
|
3332
|
-
var RouteRegistry = class extends
|
|
3303
|
+
var RouteRegistry = class extends DebuggableService {
|
|
3333
3304
|
/**
|
|
3334
3305
|
* Constructor.
|
|
3335
3306
|
*
|
|
@@ -3522,7 +3493,7 @@ var RequestContext = class {
|
|
|
3522
3493
|
};
|
|
3523
3494
|
|
|
3524
3495
|
// src/trie-router.js
|
|
3525
|
-
var TrieRouter = class extends
|
|
3496
|
+
var TrieRouter = class extends DebuggableService {
|
|
3526
3497
|
/**
|
|
3527
3498
|
* Define route.
|
|
3528
3499
|
*
|
|
@@ -3530,7 +3501,7 @@ var TrieRouter = class extends Service2 {
|
|
|
3530
3501
|
* ```
|
|
3531
3502
|
* const router = new TrieRouter();
|
|
3532
3503
|
* router.defineRoute({
|
|
3533
|
-
* method:
|
|
3504
|
+
* method: HttpMethod.GET, // Request method.
|
|
3534
3505
|
* path: '/', // Path template.
|
|
3535
3506
|
* handler: ctx => 'Hello world!', // Request handler.
|
|
3536
3507
|
* });
|
|
@@ -3540,7 +3511,7 @@ var TrieRouter = class extends Service2 {
|
|
|
3540
3511
|
* ```
|
|
3541
3512
|
* const router = new TrieRouter();
|
|
3542
3513
|
* router.defineRoute({
|
|
3543
|
-
* method:
|
|
3514
|
+
* method: HttpMethod.POST, // Request method.
|
|
3544
3515
|
* path: '/users/:id', // The path template may have parameters.
|
|
3545
3516
|
* preHandler(ctx) { ... }, // The "preHandler" is executed before a route handler.
|
|
3546
3517
|
* handler(ctx) { ... }, // Request handler function.
|
|
@@ -3669,16 +3640,15 @@ var TrieRouter = class extends Service2 {
|
|
|
3669
3640
|
};
|
|
3670
3641
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3671
3642
|
0 && (module.exports = {
|
|
3672
|
-
BUFFER_ENCODING_LIST,
|
|
3673
3643
|
BodyParser,
|
|
3674
3644
|
CookieParser,
|
|
3675
3645
|
DataSender,
|
|
3676
3646
|
EXPOSED_ERROR_PROPERTIES,
|
|
3677
3647
|
ErrorSender,
|
|
3678
3648
|
HOOK_NAME,
|
|
3679
|
-
HTTP_METHOD,
|
|
3680
3649
|
HookInvoker,
|
|
3681
3650
|
HookRegistry,
|
|
3651
|
+
HttpMethod,
|
|
3682
3652
|
METHODS_WITH_BODY,
|
|
3683
3653
|
QueryParser,
|
|
3684
3654
|
RequestContext,
|
|
@@ -3688,18 +3658,7 @@ var TrieRouter = class extends Service2 {
|
|
|
3688
3658
|
RouterOptions,
|
|
3689
3659
|
TrieRouter,
|
|
3690
3660
|
UNPARSABLE_MEDIA_TYPES,
|
|
3691
|
-
|
|
3692
|
-
createDebugger,
|
|
3693
|
-
createError,
|
|
3694
|
-
fetchRequestBody,
|
|
3695
|
-
getRequestPathname,
|
|
3696
|
-
isPromise,
|
|
3697
|
-
isReadableStream,
|
|
3698
|
-
isResponseSent,
|
|
3699
|
-
isWritableStream,
|
|
3700
|
-
parseCookie,
|
|
3701
|
-
parseJsonBody,
|
|
3702
|
-
toCamelCase
|
|
3661
|
+
parseJsonBody
|
|
3703
3662
|
});
|
|
3704
3663
|
/*! Bundled license information:
|
|
3705
3664
|
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import http from 'http';
|
|
2
2
|
import {TrieRouter} from '../src/index.js';
|
|
3
|
-
import {
|
|
3
|
+
import {HttpMethod} from '../src/route.js';
|
|
4
4
|
|
|
5
5
|
const router = new TrieRouter();
|
|
6
6
|
|
|
7
7
|
// регистрация роута для вывода
|
|
8
8
|
// переданных Cookie
|
|
9
9
|
router.defineRoute({
|
|
10
|
-
method:
|
|
10
|
+
method: HttpMethod.GET,
|
|
11
11
|
path: '/showCookie',
|
|
12
12
|
handler: ({cookie}) => cookie,
|
|
13
13
|
});
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import http from 'http';
|
|
2
2
|
import {TrieRouter} from '../src/index.js';
|
|
3
|
-
import {
|
|
3
|
+
import {HttpMethod} from '../src/route.js';
|
|
4
4
|
|
|
5
5
|
const router = new TrieRouter();
|
|
6
6
|
|
|
7
7
|
// регистрация роута для вывода
|
|
8
8
|
// переданных параметров пути
|
|
9
9
|
router.defineRoute({
|
|
10
|
-
method:
|
|
10
|
+
method: HttpMethod.GET,
|
|
11
11
|
path: '/showParams/:p1/:p2',
|
|
12
12
|
handler: ({params}) => params,
|
|
13
13
|
});
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import http from 'http';
|
|
2
2
|
import {TrieRouter} from '../src/index.js';
|
|
3
|
-
import {
|
|
3
|
+
import {HttpMethod} from '../src/route.js';
|
|
4
4
|
|
|
5
5
|
const router = new TrieRouter();
|
|
6
6
|
|
|
7
7
|
// регистрация роута для вывода
|
|
8
8
|
// переданных "query" параметров
|
|
9
9
|
router.defineRoute({
|
|
10
|
-
method:
|
|
10
|
+
method: HttpMethod.GET,
|
|
11
11
|
path: '/showQuery',
|
|
12
12
|
handler: ({query}) => query,
|
|
13
13
|
});
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import http from 'http';
|
|
2
2
|
import {TrieRouter} from '../src/index.js';
|
|
3
|
-
import {
|
|
3
|
+
import {HttpMethod} from '../src/route.js';
|
|
4
4
|
|
|
5
5
|
const router = new TrieRouter();
|
|
6
6
|
|
|
7
7
|
// регистрация роута для вывода
|
|
8
8
|
// времени работы сервера
|
|
9
9
|
router.defineRoute({
|
|
10
|
-
method:
|
|
10
|
+
method: HttpMethod.GET,
|
|
11
11
|
path: '/',
|
|
12
12
|
handler() {
|
|
13
13
|
const uptimeSec = process.uptime();
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {Debugger} from './utils/index.js';
|
|
2
|
-
import {Service
|
|
2
|
+
import {Service} from '@e22m4u/js-service';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Debuggable service.
|
|
6
6
|
*/
|
|
7
|
-
declare class
|
|
7
|
+
declare class DebuggableService extends Service {
|
|
8
8
|
/**
|
|
9
9
|
* Debug.
|
|
10
10
|
*
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import {Service} from '@e22m4u/js-service';
|
|
1
2
|
import {toCamelCase} from './utils/index.js';
|
|
2
3
|
import {createDebugger} from './utils/index.js';
|
|
3
4
|
import {ServiceContainer} from '@e22m4u/js-service';
|
|
4
|
-
import {Service as BaseService} from '@e22m4u/js-service';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Debuggable service.
|
|
8
8
|
*/
|
|
9
|
-
export class
|
|
9
|
+
export class DebuggableService extends Service {
|
|
10
10
|
/**
|
|
11
11
|
* Debug.
|
|
12
12
|
*
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {expect} from './chai.js';
|
|
2
|
-
import {
|
|
2
|
+
import {DebuggableService} from './debuggable-service.js';
|
|
3
3
|
|
|
4
|
-
describe('
|
|
4
|
+
describe('DebuggableService', function () {
|
|
5
5
|
describe('constructor', function () {
|
|
6
6
|
it('sets the debugger to the "debug" property', function () {
|
|
7
|
-
const service = new
|
|
7
|
+
const service = new DebuggableService();
|
|
8
8
|
expect(service.debug).to.be.instanceof(Function);
|
|
9
9
|
});
|
|
10
10
|
});
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {Route} from '../route.js';
|
|
2
2
|
import {ServerResponse} from 'http';
|
|
3
|
-
import {Service} from '../service.js';
|
|
4
3
|
import {ValueOrPromise} from '../types.js';
|
|
5
4
|
import {HOOK_NAME} from './hook-registry.js';
|
|
5
|
+
import {DebuggableService} from '../debuggable-service.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Hook invoker.
|
|
9
9
|
*/
|
|
10
|
-
export declare class HookInvoker extends
|
|
10
|
+
export declare class HookInvoker extends DebuggableService {
|
|
11
11
|
/**
|
|
12
12
|
* Invoke and continue until value received.
|
|
13
13
|
*
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import {Route} from '../route.js';
|
|
2
|
-
import {Service} from '../service.js';
|
|
3
2
|
import {Errorf} from '@e22m4u/js-format';
|
|
4
3
|
import {isPromise} from '../utils/index.js';
|
|
5
4
|
import {HOOK_NAME} from './hook-registry.js';
|
|
6
5
|
import {HookRegistry} from './hook-registry.js';
|
|
7
6
|
import {isResponseSent} from '../utils/index.js';
|
|
7
|
+
import {DebuggableService} from '../debuggable-service.js';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Hook invoker.
|
|
11
11
|
*/
|
|
12
|
-
export class HookInvoker extends
|
|
12
|
+
export class HookInvoker extends DebuggableService {
|
|
13
13
|
/**
|
|
14
14
|
* Invoke and continue until value received.
|
|
15
15
|
*
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {expect} from '../chai.js';
|
|
2
2
|
import {Route} from '../route.js';
|
|
3
|
-
import {
|
|
3
|
+
import {HttpMethod} from '../route.js';
|
|
4
4
|
import {format} from '@e22m4u/js-format';
|
|
5
5
|
import {HOOK_NAME} from './hook-registry.js';
|
|
6
6
|
import {HookInvoker} from './hook-invoker.js';
|
|
@@ -33,7 +33,7 @@ describe('HookInvoker', function () {
|
|
|
33
33
|
expect(throwable(undefined)).to.throw(error('undefined'));
|
|
34
34
|
throwable(
|
|
35
35
|
new Route({
|
|
36
|
-
method:
|
|
36
|
+
method: HttpMethod.GET,
|
|
37
37
|
path: '/',
|
|
38
38
|
handler: () => undefined,
|
|
39
39
|
}),
|
|
@@ -43,7 +43,7 @@ describe('HookInvoker', function () {
|
|
|
43
43
|
it('requires the parameter "hookName" to be a non-empty String', function () {
|
|
44
44
|
const s = new HookInvoker();
|
|
45
45
|
const route = new Route({
|
|
46
|
-
method:
|
|
46
|
+
method: HttpMethod.GET,
|
|
47
47
|
path: '/',
|
|
48
48
|
handler: () => undefined,
|
|
49
49
|
});
|
|
@@ -72,7 +72,7 @@ describe('HookInvoker', function () {
|
|
|
72
72
|
it('requires the parameter "hookName" to be a supported hook', function () {
|
|
73
73
|
const s = new HookInvoker();
|
|
74
74
|
const route = new Route({
|
|
75
|
-
method:
|
|
75
|
+
method: HttpMethod.GET,
|
|
76
76
|
path: '/',
|
|
77
77
|
handler: () => undefined,
|
|
78
78
|
});
|
|
@@ -88,7 +88,7 @@ describe('HookInvoker', function () {
|
|
|
88
88
|
it('requires the parameter "response" to be an instance of ServerResponse', function () {
|
|
89
89
|
const s = new HookInvoker();
|
|
90
90
|
const route = new Route({
|
|
91
|
-
method:
|
|
91
|
+
method: HttpMethod.GET,
|
|
92
92
|
path: '/',
|
|
93
93
|
handler: () => undefined,
|
|
94
94
|
});
|
|
@@ -124,7 +124,7 @@ describe('HookInvoker', function () {
|
|
|
124
124
|
order.push('globalHook2');
|
|
125
125
|
});
|
|
126
126
|
const route = new Route({
|
|
127
|
-
method:
|
|
127
|
+
method: HttpMethod.GET,
|
|
128
128
|
path: '/',
|
|
129
129
|
preHandler: [
|
|
130
130
|
() => {
|
|
@@ -164,7 +164,7 @@ describe('HookInvoker', function () {
|
|
|
164
164
|
order.push('globalHook3');
|
|
165
165
|
});
|
|
166
166
|
const route = new Route({
|
|
167
|
-
method:
|
|
167
|
+
method: HttpMethod.GET,
|
|
168
168
|
path: '/',
|
|
169
169
|
preHandler: [
|
|
170
170
|
() => {
|
|
@@ -196,7 +196,7 @@ describe('HookInvoker', function () {
|
|
|
196
196
|
order.push('globalHook2');
|
|
197
197
|
});
|
|
198
198
|
const route = new Route({
|
|
199
|
-
method:
|
|
199
|
+
method: HttpMethod.GET,
|
|
200
200
|
path: '/',
|
|
201
201
|
preHandler: [
|
|
202
202
|
() => {
|
|
@@ -241,7 +241,7 @@ describe('HookInvoker', function () {
|
|
|
241
241
|
order.push('globalHook3');
|
|
242
242
|
});
|
|
243
243
|
const route = new Route({
|
|
244
|
-
method:
|
|
244
|
+
method: HttpMethod.GET,
|
|
245
245
|
path: '/',
|
|
246
246
|
preHandler: [
|
|
247
247
|
() => {
|
|
@@ -273,7 +273,7 @@ describe('HookInvoker', function () {
|
|
|
273
273
|
order.push('globalHook2');
|
|
274
274
|
});
|
|
275
275
|
const route = new Route({
|
|
276
|
-
method:
|
|
276
|
+
method: HttpMethod.GET,
|
|
277
277
|
path: '/',
|
|
278
278
|
preHandler: [
|
|
279
279
|
() => {
|
|
@@ -316,7 +316,7 @@ describe('HookInvoker', function () {
|
|
|
316
316
|
order.push('globalHook3');
|
|
317
317
|
});
|
|
318
318
|
const route = new Route({
|
|
319
|
-
method:
|
|
319
|
+
method: HttpMethod.GET,
|
|
320
320
|
path: '/',
|
|
321
321
|
preHandler: [
|
|
322
322
|
() => {
|
|
@@ -354,7 +354,7 @@ describe('HookInvoker', function () {
|
|
|
354
354
|
order.push('globalHook2');
|
|
355
355
|
});
|
|
356
356
|
const route = new Route({
|
|
357
|
-
method:
|
|
357
|
+
method: HttpMethod.GET,
|
|
358
358
|
path: '/',
|
|
359
359
|
preHandler: [
|
|
360
360
|
() => {
|
|
@@ -391,7 +391,7 @@ describe('HookInvoker', function () {
|
|
|
391
391
|
order.push('globalHook2');
|
|
392
392
|
});
|
|
393
393
|
const route = new Route({
|
|
394
|
-
method:
|
|
394
|
+
method: HttpMethod.GET,
|
|
395
395
|
path: '/',
|
|
396
396
|
preHandler: [
|
|
397
397
|
() => {
|
|
@@ -432,7 +432,7 @@ describe('HookInvoker', function () {
|
|
|
432
432
|
order.push('globalHook2');
|
|
433
433
|
});
|
|
434
434
|
const route = new Route({
|
|
435
|
-
method:
|
|
435
|
+
method: HttpMethod.GET,
|
|
436
436
|
path: '/',
|
|
437
437
|
preHandler: [
|
|
438
438
|
async () => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {Callable} from '../types.js';
|
|
2
|
-
import {
|
|
2
|
+
import {DebuggableService} from '../debuggable-service.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Hook type.
|
|
@@ -17,7 +17,7 @@ export type RouterHook<T = unknown> = Callable<T>;
|
|
|
17
17
|
/**
|
|
18
18
|
* Hook registry.
|
|
19
19
|
*/
|
|
20
|
-
export declare class HookRegistry extends
|
|
20
|
+
export declare class HookRegistry extends DebuggableService {
|
|
21
21
|
/**
|
|
22
22
|
* Add hook.
|
|
23
23
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {Service} from '../service.js';
|
|
2
1
|
import {Errorf} from '@e22m4u/js-format';
|
|
2
|
+
import {DebuggableService} from '../debuggable-service.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Router hook.
|
|
@@ -17,7 +17,7 @@ export const HOOK_NAME = {
|
|
|
17
17
|
/**
|
|
18
18
|
* Hook registry.
|
|
19
19
|
*/
|
|
20
|
-
export class HookRegistry extends
|
|
20
|
+
export class HookRegistry extends DebuggableService {
|
|
21
21
|
/**
|
|
22
22
|
* Hooks.
|
|
23
23
|
*
|
package/src/index.d.ts
CHANGED
|
@@ -1 +1,8 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './route.js';
|
|
2
|
+
export * from './hooks/index.js';
|
|
3
|
+
export * from './trie-router.js';
|
|
4
|
+
export * from './parsers/index.js';
|
|
5
|
+
export * from './senders/index.js';
|
|
6
|
+
export * from './route-registry.js';
|
|
7
|
+
export * from './router-options.js';
|
|
8
|
+
export * from './request-context.js';
|
package/src/index.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
export * from './route.js';
|
|
2
|
-
export * from './trie-router.js';
|
|
3
2
|
export * from './hooks/index.js';
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './senders/index.js';
|
|
3
|
+
export * from './trie-router.js';
|
|
6
4
|
export * from './parsers/index.js';
|
|
5
|
+
export * from './senders/index.js';
|
|
7
6
|
export * from './route-registry.js';
|
|
8
7
|
export * from './router-options.js';
|
|
9
8
|
export * from './request-context.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {IncomingMessage} from 'http';
|
|
2
|
-
import {Service} from '../service.js';
|
|
3
2
|
import {ValueOrPromise} from '../types.js';
|
|
3
|
+
import {DebuggableService} from '../debuggable-service.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Method names to be parsed.
|
|
@@ -20,7 +20,7 @@ export type BodyParserFunction = <T = unknown>(input: string) => T;
|
|
|
20
20
|
/**
|
|
21
21
|
* Body parser.
|
|
22
22
|
*/
|
|
23
|
-
export declare class BodyParser extends
|
|
23
|
+
export declare class BodyParser extends DebuggableService {
|
|
24
24
|
/**
|
|
25
25
|
* Define parser.
|
|
26
26
|
*
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import HttpErrors from 'http-errors';
|
|
2
|
-
import {Service} from '../service.js';
|
|
3
2
|
import {Errorf} from '@e22m4u/js-format';
|
|
4
3
|
import {createError} from '../utils/index.js';
|
|
5
4
|
import {RouterOptions} from '../router-options.js';
|
|
6
5
|
import {fetchRequestBody} from '../utils/index.js';
|
|
6
|
+
import {DebuggableService} from '../debuggable-service.js';
|
|
7
7
|
import {parseContentType} from '../utils/parse-content-type.js';
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -23,7 +23,7 @@ export const UNPARSABLE_MEDIA_TYPES = ['multipart/form-data'];
|
|
|
23
23
|
/**
|
|
24
24
|
* Body parser.
|
|
25
25
|
*/
|
|
26
|
-
export class BodyParser extends
|
|
26
|
+
export class BodyParser extends DebuggableService {
|
|
27
27
|
/**
|
|
28
28
|
* Parsers.
|
|
29
29
|
*
|