fastify 5.11.2 → 6.0.0-alpha.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 (64) hide show
  1. package/README.md +9 -9
  2. package/SPONSORS.md +1 -0
  3. package/build/build-validation.js +20 -34
  4. package/docs/Guides/Getting-Started.md +2 -2
  5. package/docs/Guides/Serverless.md +34 -2
  6. package/docs/Reference/Encapsulation.md +31 -2
  7. package/docs/Reference/Errors.md +81 -6
  8. package/docs/Reference/Hooks.md +0 -4
  9. package/docs/Reference/LTS.md +6 -5
  10. package/docs/Reference/Request.md +18 -6
  11. package/docs/Reference/Routes.md +13 -0
  12. package/docs/Reference/Server.md +8 -88
  13. package/docs/Reference/TypeScript.md +3 -49
  14. package/docs/Reference/Warnings.md +4 -11
  15. package/fastify.d.ts +10 -24
  16. package/fastify.js +17 -34
  17. package/lib/config-validator.js +368 -475
  18. package/lib/content-type-parser.js +4 -0
  19. package/lib/decorate.js +1 -1
  20. package/lib/errors.js +9 -3
  21. package/lib/log-controller.js +3 -5
  22. package/lib/logger-factory.js +1 -1
  23. package/lib/reply.js +7 -3
  24. package/lib/route.js +4 -9
  25. package/lib/server.js +2 -3
  26. package/lib/warnings.js +2 -46
  27. package/package.json +2 -3
  28. package/test/404s.test.js +0 -49
  29. package/test/allow-unsafe-regex.test.js +12 -4
  30. package/test/case-insensitive.test.js +12 -4
  31. package/test/content-parser.test.js +32 -0
  32. package/test/custom-querystring-parser.test.js +0 -16
  33. package/test/decorator-instance-properties.test.js +49 -0
  34. package/test/hooks.test.js +6 -1
  35. package/test/http-methods/custom-http-methods.test.js +12 -17
  36. package/test/http-methods/trace.test.js +1 -1
  37. package/test/https/custom-https-server.test.js +1 -1
  38. package/test/internals/errors.test.js +15 -5
  39. package/test/internals/initial-config.test.js +56 -38
  40. package/test/internals/logger.test.js +17 -4
  41. package/test/internals/reply.test.js +1 -1
  42. package/test/internals/request.test.js +8 -24
  43. package/test/logger/logging.test.js +2 -121
  44. package/test/logger/request.test.js +1 -36
  45. package/test/plugin.4.test.js +5 -4
  46. package/test/reply-trailers.test.js +92 -4
  47. package/test/route-prefix.test.js +46 -18
  48. package/test/route.1.test.js +2 -2
  49. package/test/router-options.test.js +25 -523
  50. package/test/set-error-handler.test.js +7 -9
  51. package/test/types/errors.tst.ts +2 -1
  52. package/test/types/fastify.tst.ts +44 -48
  53. package/test/types/instance.tst.ts +4 -5
  54. package/test/types/logger.tst.ts +3 -7
  55. package/test/use-semicolon-delimiter.test.js +0 -60
  56. package/types/context.d.ts +0 -20
  57. package/types/errors.d.ts +2 -1
  58. package/types/instance.d.ts +0 -4
  59. package/types/logger.d.ts +2 -17
  60. package/types/plugin.d.ts +0 -9
  61. package/types/request.d.ts +0 -4
  62. package/.pi/bash-confirm-whitelist.json +0 -180
  63. package/lib/promise.js +0 -23
  64. package/test/internals/promise.test.js +0 -63
@@ -459,7 +459,9 @@ test('prefix "/prefix/" does not match "/prefix" with a / route', (t, testDone)
459
459
  test('matches both /prefix and /prefix/ with a / route - ignoreTrailingSlash: true', (t, testDone) => {
460
460
  t.plan(4)
461
461
  const fastify = Fastify({
462
- ignoreTrailingSlash: true
462
+ routerOptions: {
463
+ ignoreTrailingSlash: true
464
+ }
463
465
  })
464
466
 
465
467
  fastify.register(function (fastify, opts, done) {
@@ -493,7 +495,9 @@ test('matches both /prefix and /prefix/ with a / route - ignoreTrailingSlash: tr
493
495
  test('matches both /prefix and /prefix/ with a / route - ignoreDuplicateSlashes: true', (t, testDone) => {
494
496
  t.plan(4)
495
497
  const fastify = Fastify({
496
- ignoreDuplicateSlashes: true
498
+ routerOptions: {
499
+ ignoreDuplicateSlashes: true
500
+ }
497
501
  })
498
502
 
499
503
  fastify.register(function (fastify, opts, done) {
@@ -527,7 +531,9 @@ test('matches both /prefix and /prefix/ with a / route - ignoreDuplicateSlashes:
527
531
  test('matches both /prefix and /prefix/ with a / route - prefixTrailingSlash: "both", ignoreTrailingSlash: false', (t, testDone) => {
528
532
  t.plan(4)
529
533
  const fastify = Fastify({
530
- ignoreTrailingSlash: false
534
+ routerOptions: {
535
+ ignoreTrailingSlash: false
536
+ }
531
537
  })
532
538
 
533
539
  fastify.register(function (fastify, opts, done) {
@@ -566,7 +572,9 @@ test('matches both /prefix and /prefix/ with a / route - prefixTrailingSlash: "
566
572
  test('matches both /prefix and /prefix/ with a / route - prefixTrailingSlash: "both", ignoreDuplicateSlashes: false', (t, testDone) => {
567
573
  t.plan(4)
568
574
  const fastify = Fastify({
569
- ignoreDuplicateSlashes: false
575
+ routerOptions: {
576
+ ignoreDuplicateSlashes: false
577
+ }
570
578
  })
571
579
 
572
580
  fastify.register(function (fastify, opts, done) {
@@ -605,8 +613,10 @@ test('matches both /prefix and /prefix/ with a / route - prefixTrailingSlash: "
605
613
  test('matches both /prefix and /prefix/ with a / route - ignoreTrailingSlash: true, ignoreDuplicateSlashes: true', (t, testDone) => {
606
614
  t.plan(4)
607
615
  const fastify = Fastify({
608
- ignoreTrailingSlash: true,
609
- ignoreDuplicateSlashes: true
616
+ routerOptions: {
617
+ ignoreTrailingSlash: true,
618
+ ignoreDuplicateSlashes: true
619
+ }
610
620
  })
611
621
 
612
622
  fastify.register(function (fastify, opts, done) {
@@ -640,8 +650,10 @@ test('matches both /prefix and /prefix/ with a / route - ignoreTrailingSlash: tr
640
650
  test('matches both /prefix and /prefix/ with a / route - ignoreTrailingSlash: true, ignoreDuplicateSlashes: false', (t, testDone) => {
641
651
  t.plan(4)
642
652
  const fastify = Fastify({
643
- ignoreTrailingSlash: true,
644
- ignoreDuplicateSlashes: false
653
+ routerOptions: {
654
+ ignoreTrailingSlash: true,
655
+ ignoreDuplicateSlashes: false
656
+ }
645
657
  })
646
658
 
647
659
  fastify.register(function (fastify, opts, done) {
@@ -675,7 +687,9 @@ test('matches both /prefix and /prefix/ with a / route - ignoreTrailingSlash: tr
675
687
  test('returns 404 status code with /prefix/ and / route - prefixTrailingSlash: "both" (default), ignoreTrailingSlash: true', (t, testDone) => {
676
688
  t.plan(2)
677
689
  const fastify = Fastify({
678
- ignoreTrailingSlash: true
690
+ routerOptions: {
691
+ ignoreTrailingSlash: true
692
+ }
679
693
  })
680
694
 
681
695
  fastify.register(function (fastify, opts, done) {
@@ -707,7 +721,9 @@ test('returns 404 status code with /prefix/ and / route - prefixTrailingSlash: "
707
721
  test('matches both /prefix and /prefix/ with a / route - prefixTrailingSlash: "both", ignoreDuplicateSlashes: true', (t, testDone) => {
708
722
  t.plan(2)
709
723
  const fastify = Fastify({
710
- ignoreDuplicateSlashes: true
724
+ routerOptions: {
725
+ ignoreDuplicateSlashes: true
726
+ }
711
727
  })
712
728
 
713
729
  fastify.register(function (fastify, opts, done) {
@@ -735,8 +751,10 @@ test('matches both /prefix and /prefix/ with a / route - prefixTrailingSlash: "
735
751
  test('matches both /prefix and /prefix/ with a / route - prefixTrailingSlash: "both", ignoreTrailingSlash: true, ignoreDuplicateSlashes: true', (t, testDone) => {
736
752
  t.plan(2)
737
753
  const fastify = Fastify({
738
- ignoreTrailingSlash: true,
739
- ignoreDuplicateSlashes: true
754
+ routerOptions: {
755
+ ignoreTrailingSlash: true,
756
+ ignoreDuplicateSlashes: true
757
+ }
740
758
  })
741
759
 
742
760
  fastify.register(function (fastify, opts, done) {
@@ -764,8 +782,10 @@ test('matches both /prefix and /prefix/ with a / route - prefixTrailingSlash: "
764
782
  test('matches both /prefix and /prefix/ with a / route - prefixTrailingSlash: "both", ignoreDuplicateSlashes: true', (t, testDone) => {
765
783
  t.plan(2)
766
784
  const fastify = Fastify({
767
- ignoreTrailingSlash: true,
768
- ignoreDuplicateSlashes: true
785
+ routerOptions: {
786
+ ignoreTrailingSlash: true,
787
+ ignoreDuplicateSlashes: true
788
+ }
769
789
  })
770
790
 
771
791
  fastify.register(function (fastify, opts, done) {
@@ -793,7 +813,9 @@ test('matches both /prefix and /prefix/ with a / route - prefixTrailingSlash: "
793
813
  test('matches only /prefix with a / route - prefixTrailingSlash: "no-slash", ignoreTrailingSlash: false', (t, testDone) => {
794
814
  t.plan(4)
795
815
  const fastify = Fastify({
796
- ignoreTrailingSlash: false
816
+ routerOptions: {
817
+ ignoreTrailingSlash: false
818
+ }
797
819
  })
798
820
 
799
821
  fastify.register(function (fastify, opts, done) {
@@ -832,7 +854,9 @@ test('matches only /prefix with a / route - prefixTrailingSlash: "no-slash", ig
832
854
  test('matches only /prefix with a / route - prefixTrailingSlash: "no-slash", ignoreDuplicateSlashes: false', (t, testDone) => {
833
855
  t.plan(4)
834
856
  const fastify = Fastify({
835
- ignoreDuplicateSlashes: false
857
+ routerOptions: {
858
+ ignoreDuplicateSlashes: false
859
+ }
836
860
  })
837
861
 
838
862
  fastify.register(function (fastify, opts, done) {
@@ -871,7 +895,9 @@ test('matches only /prefix with a / route - prefixTrailingSlash: "no-slash", ig
871
895
  test('matches only /prefix/ with a / route - prefixTrailingSlash: "slash", ignoreTrailingSlash: false', (t, testDone) => {
872
896
  t.plan(4)
873
897
  const fastify = Fastify({
874
- ignoreTrailingSlash: false
898
+ routerOptions: {
899
+ ignoreTrailingSlash: false
900
+ }
875
901
  })
876
902
 
877
903
  fastify.register(function (fastify, opts, done) {
@@ -910,7 +936,9 @@ test('matches only /prefix/ with a / route - prefixTrailingSlash: "slash", igno
910
936
  test('calls onRoute only once when prefixing', async t => {
911
937
  t.plan(1)
912
938
  const fastify = Fastify({
913
- ignoreTrailingSlash: false,
939
+ routerOptions: {
940
+ ignoreTrailingSlash: false
941
+ },
914
942
  exposeHeadRoutes: false
915
943
  })
916
944
 
@@ -3,7 +3,7 @@
3
3
  const { test } = require('node:test')
4
4
  const Fastify = require('..')
5
5
  const {
6
- FST_ERR_INSTANCE_ALREADY_LISTENING,
6
+ FST_ERR_INSTANCE_ALREADY_STARTED,
7
7
  FST_ERR_ROUTE_METHOD_INVALID
8
8
  } = require('../lib/errors')
9
9
  const { getServerUrl } = require('./helper')
@@ -230,7 +230,7 @@ test('route', async t => {
230
230
  handler: function (req, reply) {
231
231
  reply.send({ hello: 'world' })
232
232
  }
233
- }), new FST_ERR_INSTANCE_ALREADY_LISTENING('Cannot add route!'))
233
+ }), new FST_ERR_INSTANCE_ALREADY_STARTED('Cannot add route!'))
234
234
  })
235
235
  })
236
236