@e22m4u/js-trie-router 0.4.4 → 0.5.0

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.
Files changed (55) hide show
  1. package/.mocharc.json +5 -0
  2. package/dist/cjs/index.cjs +82 -84
  3. package/eslint.config.js +5 -2
  4. package/examples/uptime-example.js +1 -1
  5. package/jsconfig.json +7 -0
  6. package/package.json +13 -16
  7. package/src/hooks/hook-invoker.spec.js +2 -4
  8. package/src/hooks/hook-registry.spec.js +1 -2
  9. package/src/parsers/body-parser.js +6 -3
  10. package/src/parsers/body-parser.spec.js +6 -3
  11. package/src/parsers/cookies-parser.js +1 -2
  12. package/src/route-registry.spec.js +1 -2
  13. package/src/route.spec.js +2 -4
  14. package/src/senders/error-sender.spec.js +3 -5
  15. package/src/trie-router.spec.js +5 -10
  16. package/src/utils/create-error.js +1 -2
  17. package/.mocharc.cjs +0 -5
  18. package/src/debuggable-service.d.ts +0 -6
  19. package/src/hooks/hook-invoker.d.ts +0 -25
  20. package/src/hooks/hook-registry.d.ts +0 -93
  21. package/src/hooks/index.d.ts +0 -2
  22. package/src/index.d.ts +0 -9
  23. package/src/parsers/body-parser.d.ts +0 -52
  24. package/src/parsers/cookies-parser.d.ts +0 -15
  25. package/src/parsers/index.d.ts +0 -4
  26. package/src/parsers/query-parser.d.ts +0 -21
  27. package/src/parsers/request-parser.d.ts +0 -34
  28. package/src/request-context.d.ts +0 -101
  29. package/src/route-registry.d.ts +0 -39
  30. package/src/route.d.ts +0 -100
  31. package/src/router-options.d.ts +0 -18
  32. package/src/senders/data-sender.d.ts +0 -15
  33. package/src/senders/error-sender.d.ts +0 -30
  34. package/src/senders/index.d.ts +0 -2
  35. package/src/trie-router.d.ts +0 -104
  36. package/src/types.d.ts +0 -19
  37. package/src/utils/clone-deep.d.ts +0 -6
  38. package/src/utils/create-cookies-string.d.ts +0 -6
  39. package/src/utils/create-debugger.d.ts +0 -11
  40. package/src/utils/create-error.d.ts +0 -14
  41. package/src/utils/create-request-mock.d.ts +0 -27
  42. package/src/utils/create-response-mock.d.ts +0 -17
  43. package/src/utils/create-route-mock.d.ts +0 -18
  44. package/src/utils/fetch-request-body.d.ts +0 -26
  45. package/src/utils/get-request-pathname.d.ts +0 -8
  46. package/src/utils/index.d.ts +0 -16
  47. package/src/utils/is-promise.d.ts +0 -10
  48. package/src/utils/is-readable-stream.d.ts +0 -9
  49. package/src/utils/is-response-sent.d.ts +0 -8
  50. package/src/utils/is-writable-stream.d.ts +0 -9
  51. package/src/utils/parse-content-type.d.ts +0 -15
  52. package/src/utils/parse-cookies.d.ts +0 -19
  53. package/src/utils/to-camel-case.d.ts +0 -6
  54. package/tsconfig.json +0 -11
  55. /package/{mocha-setup.js → mocha.setup.js} +0 -0
package/.mocharc.json ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "extension": ["js"],
3
+ "spec": "src/**/*.spec.js",
4
+ "require": "./mocha.setup.js"
5
+ }
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -71,11 +70,11 @@ __export(index_exports, {
71
70
  module.exports = __toCommonJS(index_exports);
72
71
 
73
72
  // src/route.js
74
- var import_js_format14 = require("@e22m4u/js-format");
73
+ var import_js_format13 = require("@e22m4u/js-format");
75
74
  var import_js_debug = require("@e22m4u/js-debug");
76
75
 
77
76
  // src/hooks/hook-invoker.js
78
- var import_js_format13 = require("@e22m4u/js-format");
77
+ var import_js_format12 = require("@e22m4u/js-format");
79
78
 
80
79
  // src/debuggable-service.js
81
80
  var import_js_service = require("@e22m4u/js-service");
@@ -131,15 +130,14 @@ __name(isPromise, "isPromise");
131
130
 
132
131
  // src/utils/create-error.js
133
132
  var import_js_format = require("@e22m4u/js-format");
134
- var import_js_format2 = require("@e22m4u/js-format");
135
133
  function createError(errorCtor, message, ...args) {
136
134
  if (typeof errorCtor !== "function")
137
- throw new import_js_format2.Errorf(
135
+ throw new import_js_format.Errorf(
138
136
  'The first argument of "createError" should be a constructor, but %v was given.',
139
137
  errorCtor
140
138
  );
141
139
  if (message != null && typeof message !== "string")
142
- throw new import_js_format2.Errorf(
140
+ throw new import_js_format.Errorf(
143
141
  'The second argument of "createError" should be a String, but %v was given.',
144
142
  message
145
143
  );
@@ -150,10 +148,10 @@ function createError(errorCtor, message, ...args) {
150
148
  __name(createError, "createError");
151
149
 
152
150
  // src/utils/parse-cookies.js
153
- var import_js_format3 = require("@e22m4u/js-format");
151
+ var import_js_format2 = require("@e22m4u/js-format");
154
152
  function parseCookies(input) {
155
153
  if (typeof input !== "string")
156
- throw new import_js_format3.Errorf(
154
+ throw new import_js_format2.Errorf(
157
155
  'The first parameter of "parseCookies" should be a String, but %v was given.',
158
156
  input
159
157
  );
@@ -167,10 +165,10 @@ function parseCookies(input) {
167
165
  __name(parseCookies, "parseCookies");
168
166
 
169
167
  // src/utils/to-camel-case.js
170
- var import_js_format4 = require("@e22m4u/js-format");
168
+ var import_js_format3 = require("@e22m4u/js-format");
171
169
  function toCamelCase(input) {
172
170
  if (typeof input !== "string")
173
- throw new import_js_format4.Errorf(
171
+ throw new import_js_format3.Errorf(
174
172
  'The first argument of "toCamelCase" should be a String, but %v was given.',
175
173
  input
176
174
  );
@@ -180,26 +178,26 @@ __name(toCamelCase, "toCamelCase");
180
178
 
181
179
  // src/utils/create-debugger.js
182
180
  var import_debug = __toESM(require("debug"), 1);
183
- var import_js_format5 = require("@e22m4u/js-format");
181
+ var import_js_format4 = require("@e22m4u/js-format");
184
182
  function createDebugger(name) {
185
183
  if (typeof name !== "string")
186
- throw new import_js_format5.Errorf(
184
+ throw new import_js_format4.Errorf(
187
185
  'The first argument of "createDebugger" should be a String, but %v was given.',
188
186
  name
189
187
  );
190
188
  const debug = (0, import_debug.default)(`jsTrieRouter:${name}`);
191
189
  return function(message, ...args) {
192
- const interpolatedMessage = (0, import_js_format5.format)(message, ...args);
190
+ const interpolatedMessage = (0, import_js_format4.format)(message, ...args);
193
191
  return debug(interpolatedMessage);
194
192
  };
195
193
  }
196
194
  __name(createDebugger, "createDebugger");
197
195
 
198
196
  // src/utils/is-response-sent.js
199
- var import_js_format6 = require("@e22m4u/js-format");
197
+ var import_js_format5 = require("@e22m4u/js-format");
200
198
  function isResponseSent(response) {
201
199
  if (!response || typeof response !== "object" || Array.isArray(response) || typeof response.headersSent !== "boolean") {
202
- throw new import_js_format6.Errorf(
200
+ throw new import_js_format5.Errorf(
203
201
  'The first argument of "isResponseSent" should be an instance of ServerResponse, but %v was given.',
204
202
  response
205
203
  );
@@ -226,10 +224,10 @@ function isReadableStream(value) {
226
224
  __name(isReadableStream, "isReadableStream");
227
225
 
228
226
  // src/utils/parse-content-type.js
229
- var import_js_format7 = require("@e22m4u/js-format");
227
+ var import_js_format6 = require("@e22m4u/js-format");
230
228
  function parseContentType(input) {
231
229
  if (typeof input !== "string")
232
- throw new import_js_format7.Errorf(
230
+ throw new import_js_format6.Errorf(
233
231
  'The parameter "input" of "parseContentType" should be a String, but %v was given.',
234
232
  input
235
233
  );
@@ -255,7 +253,7 @@ __name(isWritableStream, "isWritableStream");
255
253
  // src/utils/fetch-request-body.js
256
254
  var import_http_errors = __toESM(require("http-errors"), 1);
257
255
  var import_http = require("http");
258
- var import_js_format8 = require("@e22m4u/js-format");
256
+ var import_js_format7 = require("@e22m4u/js-format");
259
257
  var CHARACTER_ENCODING_LIST = [
260
258
  "ascii",
261
259
  "utf8",
@@ -268,12 +266,12 @@ var CHARACTER_ENCODING_LIST = [
268
266
  ];
269
267
  function fetchRequestBody(request, bodyBytesLimit = 0) {
270
268
  if (!(request instanceof import_http.IncomingMessage))
271
- throw new import_js_format8.Errorf(
269
+ throw new import_js_format7.Errorf(
272
270
  'The first parameter of "fetchRequestBody" should be an IncomingMessage instance, but %v was given.',
273
271
  request
274
272
  );
275
273
  if (typeof bodyBytesLimit !== "number")
276
- throw new import_js_format8.Errorf(
274
+ throw new import_js_format7.Errorf(
277
275
  'The parameter "bodyBytesLimit" of "fetchRequestBody" should be a number, but %v was given.',
278
276
  bodyBytesLimit
279
277
  );
@@ -351,13 +349,13 @@ var import_net = require("net");
351
349
  var import_tls = require("tls");
352
350
  var import_http2 = require("http");
353
351
  var import_querystring = __toESM(require("querystring"), 1);
354
- var import_js_format10 = require("@e22m4u/js-format");
352
+ var import_js_format9 = require("@e22m4u/js-format");
355
353
 
356
354
  // src/utils/create-cookies-string.js
357
- var import_js_format9 = require("@e22m4u/js-format");
355
+ var import_js_format8 = require("@e22m4u/js-format");
358
356
  function createCookiesString(data) {
359
357
  if (!data || typeof data !== "object" || Array.isArray(data))
360
- throw new import_js_format9.Errorf(
358
+ throw new import_js_format8.Errorf(
361
359
  'The first parameter of "createCookiesString" should be an Object, but %v was given.',
362
360
  data
363
361
  );
@@ -375,78 +373,78 @@ __name(createCookiesString, "createCookiesString");
375
373
  // src/utils/create-request-mock.js
376
374
  function createRequestMock(patch) {
377
375
  if (patch != null && typeof patch !== "object" || Array.isArray(patch)) {
378
- throw new import_js_format10.Errorf(
376
+ throw new import_js_format9.Errorf(
379
377
  'The first parameter of "createRequestMock" should be an Object, but %v was given.',
380
378
  patch
381
379
  );
382
380
  }
383
381
  patch = patch || {};
384
382
  if (patch.host != null && typeof patch.host !== "string")
385
- throw new import_js_format10.Errorf(
383
+ throw new import_js_format9.Errorf(
386
384
  'The parameter "host" of "createRequestMock" should be a String, but %v was given.',
387
385
  patch.host
388
386
  );
389
387
  if (patch.method != null && typeof patch.method !== "string")
390
- throw new import_js_format10.Errorf(
388
+ throw new import_js_format9.Errorf(
391
389
  'The parameter "method" of "createRequestMock" should be a String, but %v was given.',
392
390
  patch.method
393
391
  );
394
392
  if (patch.secure != null && typeof patch.secure !== "boolean")
395
- throw new import_js_format10.Errorf(
393
+ throw new import_js_format9.Errorf(
396
394
  'The parameter "secure" of "createRequestMock" should be a Boolean, but %v was given.',
397
395
  patch.secure
398
396
  );
399
397
  if (patch.path != null && typeof patch.path !== "string")
400
- throw new import_js_format10.Errorf(
398
+ throw new import_js_format9.Errorf(
401
399
  'The parameter "path" of "createRequestMock" should be a String, but %v was given.',
402
400
  patch.path
403
401
  );
404
402
  if (patch.query != null && typeof patch.query !== "object" && typeof patch.query !== "string" || Array.isArray(patch.query)) {
405
- throw new import_js_format10.Errorf(
403
+ throw new import_js_format9.Errorf(
406
404
  'The parameter "query" of "createRequestMock" should be a String or Object, but %v was given.',
407
405
  patch.query
408
406
  );
409
407
  }
410
408
  if (patch.cookies != null && typeof patch.cookies !== "string" && typeof patch.cookies !== "object" || Array.isArray(patch.cookies)) {
411
- throw new import_js_format10.Errorf(
409
+ throw new import_js_format9.Errorf(
412
410
  'The parameter "cookies" of "createRequestMock" should be a String or Object, but %v was given.',
413
411
  patch.cookies
414
412
  );
415
413
  }
416
414
  if (patch.headers != null && typeof patch.headers !== "object" || Array.isArray(patch.headers)) {
417
- throw new import_js_format10.Errorf(
415
+ throw new import_js_format9.Errorf(
418
416
  'The parameter "headers" of "createRequestMock" should be an Object, but %v was given.',
419
417
  patch.headers
420
418
  );
421
419
  }
422
420
  if (patch.stream != null && !isReadableStream(patch.stream))
423
- throw new import_js_format10.Errorf(
421
+ throw new import_js_format9.Errorf(
424
422
  'The parameter "stream" of "createRequestMock" should be a Stream, but %v was given.',
425
423
  patch.stream
426
424
  );
427
425
  if (patch.encoding != null) {
428
426
  if (typeof patch.encoding !== "string")
429
- throw new import_js_format10.Errorf(
427
+ throw new import_js_format9.Errorf(
430
428
  'The parameter "encoding" of "createRequestMock" should be a String, but %v was given.',
431
429
  patch.encoding
432
430
  );
433
431
  if (!CHARACTER_ENCODING_LIST.includes(patch.encoding))
434
- throw new import_js_format10.Errorf(
432
+ throw new import_js_format9.Errorf(
435
433
  "Character encoding %v is not supported.",
436
434
  patch.encoding
437
435
  );
438
436
  }
439
437
  if (patch.stream) {
440
438
  if (patch.secure != null)
441
- throw new import_js_format10.Errorf(
439
+ throw new import_js_format9.Errorf(
442
440
  'The "createRequestMock" does not allow specifying the "stream" and "secure" options simultaneously.'
443
441
  );
444
442
  if (patch.body != null)
445
- throw new import_js_format10.Errorf(
443
+ throw new import_js_format9.Errorf(
446
444
  'The "createRequestMock" does not allow specifying the "stream" and "body" options simultaneously.'
447
445
  );
448
446
  if (patch.encoding != null)
449
- throw new import_js_format10.Errorf(
447
+ throw new import_js_format9.Errorf(
450
448
  'The "createRequestMock" does not allow specifying the "stream" and "encoding" options simultaneously.'
451
449
  );
452
450
  }
@@ -466,7 +464,7 @@ function createRequestMock(patch) {
466
464
  __name(createRequestMock, "createRequestMock");
467
465
  function createRequestStream(secure, body, encoding) {
468
466
  if (encoding != null && typeof encoding !== "string")
469
- throw new import_js_format10.Errorf(
467
+ throw new import_js_format9.Errorf(
470
468
  'The parameter "encoding" of "createRequestStream" should be a String, but %v was given.',
471
469
  encoding
472
470
  );
@@ -489,12 +487,12 @@ function createRequestStream(secure, body, encoding) {
489
487
  __name(createRequestStream, "createRequestStream");
490
488
  function createRequestUrl(path, query) {
491
489
  if (typeof path !== "string")
492
- throw new import_js_format10.Errorf(
490
+ throw new import_js_format9.Errorf(
493
491
  'The parameter "path" of "createRequestUrl" should be a String, but %v was given.',
494
492
  path
495
493
  );
496
494
  if (query != null && typeof query !== "string" && typeof query !== "object" || Array.isArray(query)) {
497
- throw new import_js_format10.Errorf(
495
+ throw new import_js_format9.Errorf(
498
496
  'The parameter "query" of "createRequestUrl" should be a String or Object, but %v was given.',
499
497
  query
500
498
  );
@@ -511,32 +509,32 @@ function createRequestUrl(path, query) {
511
509
  __name(createRequestUrl, "createRequestUrl");
512
510
  function createRequestHeaders(host, secure, body, cookies, encoding, headers) {
513
511
  if (host != null && typeof host !== "string")
514
- throw new import_js_format10.Errorf(
512
+ throw new import_js_format9.Errorf(
515
513
  'The parameter "host" of "createRequestHeaders" a non-empty String, but %v was given.',
516
514
  host
517
515
  );
518
516
  host = host || "localhost";
519
517
  if (secure != null && typeof secure !== "boolean")
520
- throw new import_js_format10.Errorf(
518
+ throw new import_js_format9.Errorf(
521
519
  'The parameter "secure" of "createRequestHeaders" should be a String, but %v was given.',
522
520
  secure
523
521
  );
524
522
  secure = Boolean(secure);
525
523
  if (cookies != null && typeof cookies !== "object" && typeof cookies !== "string" || Array.isArray(cookies)) {
526
- throw new import_js_format10.Errorf(
524
+ throw new import_js_format9.Errorf(
527
525
  'The parameter "cookies" of "createRequestHeaders" should be a String or Object, but %v was given.',
528
526
  cookies
529
527
  );
530
528
  }
531
529
  if (headers != null && typeof headers !== "object" || Array.isArray(headers)) {
532
- throw new import_js_format10.Errorf(
530
+ throw new import_js_format9.Errorf(
533
531
  'The parameter "headers" of "createRequestHeaders" should be an Object, but %v was given.',
534
532
  headers
535
533
  );
536
534
  }
537
535
  headers = headers || {};
538
536
  if (encoding != null && typeof encoding !== "string")
539
- throw new import_js_format10.Errorf(
537
+ throw new import_js_format9.Errorf(
540
538
  'The parameter "encoding" of "createRequestHeaders" should be a String, but %v was given.',
541
539
  encoding
542
540
  );
@@ -685,10 +683,10 @@ function patchBody(response) {
685
683
  __name(patchBody, "patchBody");
686
684
 
687
685
  // src/utils/get-request-pathname.js
688
- var import_js_format11 = require("@e22m4u/js-format");
686
+ var import_js_format10 = require("@e22m4u/js-format");
689
687
  function getRequestPathname(request) {
690
688
  if (!request || typeof request !== "object" || Array.isArray(request) || typeof request.url !== "string") {
691
- throw new import_js_format11.Errorf(
689
+ throw new import_js_format10.Errorf(
692
690
  'The first argument of "getRequestPathname" should be an instance of IncomingMessage, but %v was given.',
693
691
  request
694
692
  );
@@ -698,7 +696,7 @@ function getRequestPathname(request) {
698
696
  __name(getRequestPathname, "getRequestPathname");
699
697
 
700
698
  // src/hooks/hook-registry.js
701
- var import_js_format12 = require("@e22m4u/js-format");
699
+ var import_js_format11 = require("@e22m4u/js-format");
702
700
  var RouterHookType = {
703
701
  PRE_HANDLER: "preHandler",
704
702
  POST_HANDLER: "postHandler"
@@ -720,11 +718,11 @@ var _HookRegistry = class _HookRegistry {
720
718
  */
721
719
  addHook(type, hook) {
722
720
  if (!type || typeof type !== "string")
723
- throw new import_js_format12.Errorf("The hook type is required, but %v was given.", type);
721
+ throw new import_js_format11.Errorf("The hook type is required, but %v was given.", type);
724
722
  if (!Object.values(RouterHookType).includes(type))
725
- throw new import_js_format12.Errorf("The hook type %v is not supported.", type);
723
+ throw new import_js_format11.Errorf("The hook type %v is not supported.", type);
726
724
  if (!hook || typeof hook !== "function")
727
- throw new import_js_format12.Errorf(
725
+ throw new import_js_format11.Errorf(
728
726
  "The hook %v should be a Function, but %v was given.",
729
727
  type,
730
728
  hook
@@ -743,11 +741,11 @@ var _HookRegistry = class _HookRegistry {
743
741
  */
744
742
  hasHook(type, hook) {
745
743
  if (!type || typeof type !== "string")
746
- throw new import_js_format12.Errorf("The hook type is required, but %v was given.", type);
744
+ throw new import_js_format11.Errorf("The hook type is required, but %v was given.", type);
747
745
  if (!Object.values(RouterHookType).includes(type))
748
- throw new import_js_format12.Errorf("The hook type %v is not supported.", type);
746
+ throw new import_js_format11.Errorf("The hook type %v is not supported.", type);
749
747
  if (!hook || typeof hook !== "function")
750
- throw new import_js_format12.Errorf(
748
+ throw new import_js_format11.Errorf(
751
749
  "The hook %v should be a Function, but %v was given.",
752
750
  type,
753
751
  hook
@@ -763,9 +761,9 @@ var _HookRegistry = class _HookRegistry {
763
761
  */
764
762
  getHooks(type) {
765
763
  if (!type || typeof type !== "string")
766
- throw new import_js_format12.Errorf("The hook type is required, but %v was given.", type);
764
+ throw new import_js_format11.Errorf("The hook type is required, but %v was given.", type);
767
765
  if (!Object.values(RouterHookType).includes(type))
768
- throw new import_js_format12.Errorf("The hook type %v is not supported.", type);
766
+ throw new import_js_format11.Errorf("The hook type %v is not supported.", type);
769
767
  return this._hooks.get(type) || [];
770
768
  }
771
769
  };
@@ -785,19 +783,19 @@ var _HookInvoker = class _HookInvoker extends DebuggableService {
785
783
  */
786
784
  invokeAndContinueUntilValueReceived(route, hookType, response, ...args) {
787
785
  if (!route || !(route instanceof Route))
788
- throw new import_js_format13.Errorf(
786
+ throw new import_js_format12.Errorf(
789
787
  'The parameter "route" of the HookInvoker.invokeAndContinueUntilValueReceived should be a Route instance, but %v was given.',
790
788
  route
791
789
  );
792
790
  if (!hookType || typeof hookType !== "string")
793
- throw new import_js_format13.Errorf(
791
+ throw new import_js_format12.Errorf(
794
792
  'The parameter "hookType" of the HookInvoker.invokeAndContinueUntilValueReceived should be a non-empty String, but %v was given.',
795
793
  hookType
796
794
  );
797
795
  if (!Object.values(RouterHookType).includes(hookType))
798
- throw new import_js_format13.Errorf("The hook type %v is not supported.", hookType);
796
+ throw new import_js_format12.Errorf("The hook type %v is not supported.", hookType);
799
797
  if (!response || typeof response !== "object" || Array.isArray(response) || typeof response.headersSent !== "boolean") {
800
- throw new import_js_format13.Errorf(
798
+ throw new import_js_format12.Errorf(
801
799
  'The parameter "response" of the HookInvoker.invokeAndContinueUntilValueReceived should be a ServerResponse instance, but %v was given.',
802
800
  response
803
801
  );
@@ -942,30 +940,30 @@ var _Route = class _Route extends import_js_debug.Debuggable {
942
940
  noInstantiationMessage: true
943
941
  });
944
942
  if (!routeDef || typeof routeDef !== "object" || Array.isArray(routeDef))
945
- throw new import_js_format14.Errorf(
943
+ throw new import_js_format13.Errorf(
946
944
  "The first parameter of Route.constructor should be an Object, but %v was given.",
947
945
  routeDef
948
946
  );
949
947
  if (!routeDef.method || typeof routeDef.method !== "string")
950
- throw new import_js_format14.Errorf(
948
+ throw new import_js_format13.Errorf(
951
949
  'The option "method" of the Route should be a non-empty String, but %v was given.',
952
950
  routeDef.method
953
951
  );
954
952
  this._method = routeDef.method.toUpperCase();
955
953
  if (typeof routeDef.path !== "string")
956
- throw new import_js_format14.Errorf(
954
+ throw new import_js_format13.Errorf(
957
955
  'The option "path" of the Route should be a String, but %v was given.',
958
956
  routeDef.path
959
957
  );
960
958
  this._path = routeDef.path;
961
959
  if (typeof routeDef.handler !== "function")
962
- throw new import_js_format14.Errorf(
960
+ throw new import_js_format13.Errorf(
963
961
  'The option "handler" of the Route should be a Function, but %v was given.',
964
962
  routeDef.handler
965
963
  );
966
964
  if (routeDef.meta != null) {
967
965
  if (typeof routeDef.meta !== "object" || Array.isArray(routeDef.meta))
968
- throw new import_js_format14.Errorf(
966
+ throw new import_js_format13.Errorf(
969
967
  'The option "meta" of the Route should be a plain Object, but %v was given.',
970
968
  routeDef.meta
971
969
  );
@@ -1008,10 +1006,10 @@ var Route = _Route;
1008
1006
 
1009
1007
  // src/parsers/body-parser.js
1010
1008
  var import_http_errors2 = __toESM(require("http-errors"), 1);
1011
- var import_js_format16 = require("@e22m4u/js-format");
1009
+ var import_js_format15 = require("@e22m4u/js-format");
1012
1010
 
1013
1011
  // src/router-options.js
1014
- var import_js_format15 = require("@e22m4u/js-format");
1012
+ var import_js_format14 = require("@e22m4u/js-format");
1015
1013
  var _RouterOptions = class _RouterOptions extends DebuggableService {
1016
1014
  /**
1017
1015
  * Request body bytes limit.
@@ -1037,7 +1035,7 @@ var _RouterOptions = class _RouterOptions extends DebuggableService {
1037
1035
  */
1038
1036
  setRequestBodyBytesLimit(input) {
1039
1037
  if (typeof input !== "number" || input < 0)
1040
- throw new import_js_format15.Errorf(
1038
+ throw new import_js_format14.Errorf(
1041
1039
  'The option "requestBodyBytesLimit" must be a positive Number or 0, but %v was given.',
1042
1040
  input
1043
1041
  );
@@ -1070,12 +1068,12 @@ var _BodyParser = class _BodyParser extends DebuggableService {
1070
1068
  */
1071
1069
  defineParser(mediaType, parser) {
1072
1070
  if (!mediaType || typeof mediaType !== "string")
1073
- throw new import_js_format16.Errorf(
1071
+ throw new import_js_format15.Errorf(
1074
1072
  'The parameter "mediaType" of BodyParser.defineParser should be a non-empty String, but %v was given.',
1075
1073
  mediaType
1076
1074
  );
1077
1075
  if (!parser || typeof parser !== "function")
1078
- throw new import_js_format16.Errorf(
1076
+ throw new import_js_format15.Errorf(
1079
1077
  'The parameter "parser" of BodyParser.defineParser should be a Function, but %v was given.',
1080
1078
  parser
1081
1079
  );
@@ -1090,7 +1088,7 @@ var _BodyParser = class _BodyParser extends DebuggableService {
1090
1088
  */
1091
1089
  hasParser(mediaType) {
1092
1090
  if (!mediaType || typeof mediaType !== "string")
1093
- throw new import_js_format16.Errorf(
1091
+ throw new import_js_format15.Errorf(
1094
1092
  'The parameter "mediaType" of BodyParser.hasParser should be a non-empty String, but %v was given.',
1095
1093
  mediaType
1096
1094
  );
@@ -1104,12 +1102,12 @@ var _BodyParser = class _BodyParser extends DebuggableService {
1104
1102
  */
1105
1103
  deleteParser(mediaType) {
1106
1104
  if (!mediaType || typeof mediaType !== "string")
1107
- throw new import_js_format16.Errorf(
1105
+ throw new import_js_format15.Errorf(
1108
1106
  'The parameter "mediaType" of BodyParser.deleteParser should be a non-empty String, but %v was given.',
1109
1107
  mediaType
1110
1108
  );
1111
1109
  const parser = this._parsers[mediaType];
1112
- if (!parser) throw new import_js_format16.Errorf("The parser of %v is not found.", mediaType);
1110
+ if (!parser) throw new import_js_format15.Errorf("The parser of %v is not found.", mediaType);
1113
1111
  delete this._parsers[mediaType];
1114
1112
  return this;
1115
1113
  }
@@ -1238,7 +1236,7 @@ var CookiesParser = _CookiesParser;
1238
1236
 
1239
1237
  // src/parsers/request-parser.js
1240
1238
  var import_http3 = require("http");
1241
- var import_js_format17 = require("@e22m4u/js-format");
1239
+ var import_js_format16 = require("@e22m4u/js-format");
1242
1240
  var _RequestParser = class _RequestParser extends DebuggableService {
1243
1241
  /**
1244
1242
  * Parse.
@@ -1248,7 +1246,7 @@ var _RequestParser = class _RequestParser extends DebuggableService {
1248
1246
  */
1249
1247
  parse(request) {
1250
1248
  if (!(request instanceof import_http3.IncomingMessage))
1251
- throw new import_js_format17.Errorf(
1249
+ throw new import_js_format16.Errorf(
1252
1250
  "The first argument of RequestParser.parse should be an instance of IncomingMessage, but %v was given.",
1253
1251
  request
1254
1252
  );
@@ -1280,7 +1278,7 @@ __name(_RequestParser, "RequestParser");
1280
1278
  var RequestParser = _RequestParser;
1281
1279
 
1282
1280
  // src/route-registry.js
1283
- var import_js_format18 = require("@e22m4u/js-format");
1281
+ var import_js_format17 = require("@e22m4u/js-format");
1284
1282
  var import_js_path_trie = require("@e22m4u/js-path-trie");
1285
1283
  var import_js_service2 = require("@e22m4u/js-service");
1286
1284
  var _RouteRegistry = class _RouteRegistry extends DebuggableService {
@@ -1302,7 +1300,7 @@ var _RouteRegistry = class _RouteRegistry extends DebuggableService {
1302
1300
  defineRoute(routeDef) {
1303
1301
  const debug = this.getDebuggerFor(this.defineRoute);
1304
1302
  if (!routeDef || typeof routeDef !== "object" || Array.isArray(routeDef))
1305
- throw new import_js_format18.Errorf(
1303
+ throw new import_js_format17.Errorf(
1306
1304
  "The route definition should be an Object, but %v was given.",
1307
1305
  routeDef
1308
1306
  );
@@ -1365,7 +1363,7 @@ __name(_RouteRegistry, "RouteRegistry");
1365
1363
  var RouteRegistry = _RouteRegistry;
1366
1364
 
1367
1365
  // src/request-context.js
1368
- var import_js_format19 = require("@e22m4u/js-format");
1366
+ var import_js_format18 = require("@e22m4u/js-format");
1369
1367
  var import_js_service3 = require("@e22m4u/js-service");
1370
1368
  var _RequestContext = class _RequestContext {
1371
1369
  /**
@@ -1511,27 +1509,27 @@ var _RequestContext = class _RequestContext {
1511
1509
  */
1512
1510
  constructor(container, request, response, route) {
1513
1511
  if (!(0, import_js_service3.isServiceContainer)(container))
1514
- throw new import_js_format19.Errorf(
1512
+ throw new import_js_format18.Errorf(
1515
1513
  'The parameter "container" of RequestContext.constructor should be an instance of ServiceContainer, but %v was given.',
1516
1514
  container
1517
1515
  );
1518
1516
  this._container = container;
1519
1517
  if (!request || typeof request !== "object" || Array.isArray(request) || !isReadableStream(request)) {
1520
- throw new import_js_format19.Errorf(
1518
+ throw new import_js_format18.Errorf(
1521
1519
  'The parameter "request" of RequestContext.constructor should be an instance of IncomingMessage, but %v was given.',
1522
1520
  request
1523
1521
  );
1524
1522
  }
1525
1523
  this._request = request;
1526
1524
  if (!response || typeof response !== "object" || Array.isArray(response) || !isWritableStream(response)) {
1527
- throw new import_js_format19.Errorf(
1525
+ throw new import_js_format18.Errorf(
1528
1526
  'The parameter "response" of RequestContext.constructor should be an instance of ServerResponse, but %v was given.',
1529
1527
  response
1530
1528
  );
1531
1529
  }
1532
1530
  this._response = response;
1533
1531
  if (!(route instanceof Route)) {
1534
- throw new import_js_format19.Errorf(
1532
+ throw new import_js_format18.Errorf(
1535
1533
  'The parameter "route" of RequestContext.constructor should be an instance of Route, but %v was given.',
1536
1534
  route
1537
1535
  );
@@ -1547,7 +1545,7 @@ var import_js_service4 = require("@e22m4u/js-service");
1547
1545
  var import_http4 = require("http");
1548
1546
 
1549
1547
  // src/senders/data-sender.js
1550
- var import_js_format20 = require("@e22m4u/js-format");
1548
+ var import_js_format19 = require("@e22m4u/js-format");
1551
1549
  var _DataSender = class _DataSender extends DebuggableService {
1552
1550
  /**
1553
1551
  * Send.
@@ -1586,7 +1584,7 @@ var _DataSender = class _DataSender extends DebuggableService {
1586
1584
  debugMsg = "The Buffer was sent as binary data.";
1587
1585
  } else {
1588
1586
  response.setHeader("content-type", "application/json");
1589
- debugMsg = (0, import_js_format20.format)("The %v was sent as JSON.", typeof data);
1587
+ debugMsg = (0, import_js_format19.format)("The %v was sent as JSON.", typeof data);
1590
1588
  data = JSON.stringify(data);
1591
1589
  }
1592
1590
  break;
package/eslint.config.js CHANGED
@@ -2,6 +2,7 @@ import globals from 'globals';
2
2
  import eslintJs from '@eslint/js';
3
3
  import eslintJsdocPlugin from 'eslint-plugin-jsdoc';
4
4
  import eslintMochaPlugin from 'eslint-plugin-mocha';
5
+ import eslintImportPlugin from 'eslint-plugin-import';
5
6
  import eslintPrettierConfig from 'eslint-config-prettier';
6
7
  import eslintChaiExpectPlugin from 'eslint-plugin-chai-expect';
7
8
 
@@ -16,15 +17,17 @@ export default [{
16
17
  plugins: {
17
18
  'jsdoc': eslintJsdocPlugin,
18
19
  'mocha': eslintMochaPlugin,
20
+ 'import': eslintImportPlugin,
19
21
  'chai-expect': eslintChaiExpectPlugin,
20
22
  },
21
23
  rules: {
22
24
  ...eslintJs.configs.recommended.rules,
23
25
  ...eslintPrettierConfig.rules,
24
- ...eslintJsdocPlugin.configs['flat/recommended-error'].rules,
26
+ ...eslintImportPlugin.flatConfigs.recommended.rules,
25
27
  ...eslintMochaPlugin.configs.recommended.rules,
26
28
  ...eslintChaiExpectPlugin.configs['recommended-flat'].rules,
27
- 'no-unused-vars': ['error', {'caughtErrors': 'none'}],
29
+ ...eslintJsdocPlugin.configs['flat/recommended-error'].rules,
30
+ 'no-duplicate-imports': 'error',
28
31
  'jsdoc/reject-any-type': 0,
29
32
  'jsdoc/reject-function-type': 0,
30
33
  'jsdoc/require-param-description': 0,
@@ -22,7 +22,7 @@ router.defineRoute({
22
22
  res += ` ${secs}s`;
23
23
  return res;
24
24
  },
25
- })
25
+ });
26
26
 
27
27
  // создание экземпляра HTTP сервера
28
28
  // и подключение обработчика запросов
package/jsconfig.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es2022",
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext"
6
+ }
7
+ }