fastify 3.24.0 → 3.25.2
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.md +30 -29
- package/docs/{Benchmarking.md → Guides/Benchmarking.md} +14 -5
- package/docs/Guides/Ecosystem.md +513 -0
- package/docs/{Fluent-Schema.md → Guides/Fluent-Schema.md} +16 -7
- package/docs/{Getting-Started.md → Guides/Getting-Started.md} +180 -60
- package/docs/Guides/Index.md +30 -4
- package/docs/{Migration-Guide-V3.md → Guides/Migration-Guide-V3.md} +43 -37
- package/docs/{Plugins-Guide.md → Guides/Plugins-Guide.md} +196 -82
- package/docs/{Recommendations.md → Guides/Recommendations.md} +17 -10
- package/docs/{Serverless.md → Guides/Serverless.md} +200 -42
- package/docs/Guides/Style-Guide.md +246 -0
- package/docs/{Testing.md → Guides/Testing.md} +26 -12
- package/docs/Guides/Write-Plugin.md +102 -0
- package/docs/{ContentTypeParser.md → Reference/ContentTypeParser.md} +68 -30
- package/docs/{Decorators.md → Reference/Decorators.md} +52 -47
- package/docs/{Encapsulation.md → Reference/Encapsulation.md} +3 -3
- package/docs/{Errors.md → Reference/Errors.md} +77 -47
- package/docs/{HTTP2.md → Reference/HTTP2.md} +13 -13
- package/docs/{Hooks.md → Reference/Hooks.md} +157 -70
- package/docs/Reference/Index.md +71 -0
- package/docs/{LTS.md → Reference/LTS.md} +31 -32
- package/docs/{Lifecycle.md → Reference/Lifecycle.md} +15 -7
- package/docs/{Logging.md → Reference/Logging.md} +68 -28
- package/docs/Reference/Middleware.md +78 -0
- package/docs/{Plugins.md → Reference/Plugins.md} +91 -34
- package/docs/{Reply.md → Reference/Reply.md} +205 -94
- package/docs/{Request.md → Reference/Request.md} +32 -16
- package/docs/{Routes.md → Reference/Routes.md} +243 -113
- package/docs/{Server.md → Reference/Server.md} +516 -267
- package/docs/{TypeScript.md → Reference/TypeScript.md} +451 -191
- package/docs/{Validation-and-Serialization.md → Reference/Validation-and-Serialization.md} +178 -86
- package/docs/index.md +24 -0
- package/examples/typescript-server.ts +1 -1
- package/fastify.js +2 -3
- package/lib/contentTypeParser.js +11 -6
- package/lib/decorate.js +6 -3
- package/lib/logger.js +1 -1
- package/lib/route.js +1 -1
- package/lib/server.js +9 -8
- package/package.json +9 -4
- package/test/als.test.js +74 -0
- package/test/constrained-routes.test.js +220 -0
- package/test/custom-parser.test.js +11 -2
- package/test/decorator.test.js +38 -0
- package/test/handler-context.test.js +11 -4
- package/test/http2/closing.test.js +14 -5
- package/test/http2/constraint.test.js +91 -0
- package/test/listen.test.js +36 -22
- package/test/logger.test.js +16 -0
- package/test/maxRequestsPerSocket.test.js +10 -0
- package/test/request-error.test.js +2 -8
- package/test/requestTimeout.test.js +4 -1
- package/test/router-options.test.js +10 -1
- package/test/schema-feature.test.js +146 -0
- package/test/stream.test.js +14 -3
- package/test/trust-proxy.test.js +15 -7
- package/test/types/instance.test-d.ts +52 -1
- package/test/types/request.test-d.ts +7 -1
- package/test/types/route.test-d.ts +21 -0
- package/types/hooks.d.ts +12 -1
- package/types/instance.d.ts +16 -6
- package/types/request.d.ts +4 -1
- package/types/route.d.ts +1 -1
- package/docs/Ecosystem.md +0 -211
- package/docs/Middleware.md +0 -53
- package/docs/Style-Guide.md +0 -185
- package/docs/Write-Plugin.md +0 -58
package/docs/Style-Guide.md
DELETED
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
# Fastify Style Guide
|
|
2
|
-
|
|
3
|
-
## Welcome
|
|
4
|
-
|
|
5
|
-
Welcome to *Fastify Style Guide*. This guide is here to provide you with a conventional writing style for users writing developer documentation on our Open Source framework. Each topic is precise and well explained to help you write documentation users can easily understand and implement.
|
|
6
|
-
|
|
7
|
-
## Who is this guide for?
|
|
8
|
-
|
|
9
|
-
This guide is for anyone who loves to build with Fastify or wants to contribute to our documentation. You do not need to be an expert in writing technical documentation. This guide is here to help you.
|
|
10
|
-
|
|
11
|
-
Visit the [contribute](https://www.fastify.io/contribute) page on our website or read the [CONTRIBUTING.md](/CONTRIBUTING.md) file on GitHub to join our Open Source folks.
|
|
12
|
-
|
|
13
|
-
## Before you write
|
|
14
|
-
|
|
15
|
-
You need to know the following:
|
|
16
|
-
|
|
17
|
-
* JavaScript
|
|
18
|
-
* Node.js
|
|
19
|
-
* Git
|
|
20
|
-
* GitHub
|
|
21
|
-
* Markdown
|
|
22
|
-
* HTTP
|
|
23
|
-
* NPM
|
|
24
|
-
|
|
25
|
-
### Consider your Audience
|
|
26
|
-
|
|
27
|
-
Before you start writing, think about your audience. In this case, your audience should already know HTTP, JavaScript, NPM, and Node.js. It is necessary to keep your readers in mind because they are the ones consuming your content. You want to give as much useful information as possible. Consider the vital things they need to know and how they can understand them. Use words and references that readers can relate to easily. Ask for feedback from the community, it can help you write better documentation that focuses on the user and what you want to achieve.
|
|
28
|
-
|
|
29
|
-
### Get straight to the point
|
|
30
|
-
|
|
31
|
-
Give your readers a clear and precise action to take. Start with what is most important. This way, you can help them find what they need faster. Mostly, readers tend to read the first content on a page, and many will not scroll further.
|
|
32
|
-
|
|
33
|
-
**Example**
|
|
34
|
-
|
|
35
|
-
Less like this: Colons are very important to register a parametric path. It lets the framework know there is a new parameter created. You can place the colon before the parameter name so the parametric path can be created.
|
|
36
|
-
|
|
37
|
-
More Like this: To register a parametric path, put a colon before the parameter name. Using a colon lets the framework know it is a parametric path and not a static path.
|
|
38
|
-
|
|
39
|
-
### Avoid adding video or image content
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
Do not add videos or screenshots in the documentation. It is easier to keep under version control. Videos and images will eventually end up becoming outdated as new updates keep developing. Instead, make a referral link or a YouTube video. You can add links by using `[Title](www.websitename.com)` in the markdown.
|
|
43
|
-
|
|
44
|
-
**Example**
|
|
45
|
-
|
|
46
|
-
```
|
|
47
|
-
To learn more about hooks, see [Fastify hooks](https://www.fastify.io/docs/latest/Hooks).
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
Result:
|
|
51
|
-
>To learn more about hooks, see [Fastify hooks](https://www.fastify.io/docs/latest/Hooks/).
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
### Avoid plagiarism
|
|
56
|
-
|
|
57
|
-
Make sure you avoid copying other people's work. Keep it as original as possible. You can learn from what they have done and reference where it is from if you used a particular quote from their work.
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
## Word Choice
|
|
61
|
-
|
|
62
|
-
There are a few things you need to use and avoid when writing your documentation to improve readability for readers and make documentation neat, direct, and clean.
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
### When to use the second person "you" as the pronoun
|
|
66
|
-
|
|
67
|
-
When writing articles or guides, your content should communicate directly to readers in the second person ("you") addressed form. It is easier to give them direct instruction on what to do on a particular topic. To see an example, visit the [Plugins-guide.md](/docs/Plugins-Guide.md) page on Github.
|
|
68
|
-
|
|
69
|
-
**Example**
|
|
70
|
-
|
|
71
|
-
Less like this: we can use the following plugins.
|
|
72
|
-
|
|
73
|
-
More like this: You can use the following plugins.
|
|
74
|
-
|
|
75
|
-
> According to [Wikipedia](#), ***You*** is usually a second person pronoun. Also, used to refer to an indeterminate person, as a more common alternative to a very formal indefinite pronoun.
|
|
76
|
-
|
|
77
|
-
## When to avoid the second person "you" as the pronoun
|
|
78
|
-
|
|
79
|
-
One of the main rules of formal writing such as reference documentation, or API documentation, is to avoid the second person ("you") or directly addressing the reader.
|
|
80
|
-
|
|
81
|
-
**Example**
|
|
82
|
-
|
|
83
|
-
Less like this: You can use the following recommendation as an example.
|
|
84
|
-
|
|
85
|
-
More like this: As an example, the following recommendations should be referenced.
|
|
86
|
-
|
|
87
|
-
To view a live example, refer to the [Decorators.md](/docs/Decorators.md) reference document.
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
### Avoid using contractions
|
|
91
|
-
|
|
92
|
-
Contractions are the shortened version of written and spoken forms of a word, i.e. using "don't" instead of "do not".
|
|
93
|
-
Avoid contractions to provide a more formal tone.
|
|
94
|
-
|
|
95
|
-
### Avoid using condescending terms
|
|
96
|
-
|
|
97
|
-
Condescending terms are words that include:
|
|
98
|
-
|
|
99
|
-
* Just
|
|
100
|
-
* Easy
|
|
101
|
-
* Simply
|
|
102
|
-
* Basically
|
|
103
|
-
* Obviously
|
|
104
|
-
|
|
105
|
-
The reader may not find it easy to use Fastify's framework and plugins; avoid words that make it sound simple, easy, offensive, or insensitive. Not everyone who reads the documentation has the same level of understanding.
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
### Starting with a verb
|
|
109
|
-
|
|
110
|
-
Mostly start your description with a verb, which makes it simple and precise for the reader to follow. Prefer using present tense because it is easier to read and understand than the past or future tense.
|
|
111
|
-
|
|
112
|
-
**Example**
|
|
113
|
-
|
|
114
|
-
Less like this: There is a need for Node.js to be installed before you can be able to use Fastify.
|
|
115
|
-
|
|
116
|
-
More like this: Install Node.js to make use of Fastify.
|
|
117
|
-
|
|
118
|
-
### Grammatical moods
|
|
119
|
-
|
|
120
|
-
Grammatical moods are a great way to express your writing. Avoid sounding too bossy while making a direct statement. Know when to switch between indicative, imperative, and subjunctive moods.
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
**Indicative** - Use when making a factual statement or question.
|
|
124
|
-
|
|
125
|
-
Example: Since there is no testing framework available, "Fastify recommends ways to write tests".
|
|
126
|
-
|
|
127
|
-
**Imperative** - Use when giving instructions, actions, commands, or when you write your headings.
|
|
128
|
-
|
|
129
|
-
Example: Install dependencies before starting development.
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
**Subjunctive** - Use when making suggestions, hypotheses, or non-factual statements.
|
|
133
|
-
|
|
134
|
-
Example: Reading the documentation on our website is recommended to get comprehensive knowledge of the framework.
|
|
135
|
-
|
|
136
|
-
### Use **active** voice instead of **passive**
|
|
137
|
-
|
|
138
|
-
Using active voice is a more compact and direct way of conveying your documentation.
|
|
139
|
-
|
|
140
|
-
**Example**
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
Passive: The node dependencies and packages are installed by npm.
|
|
144
|
-
|
|
145
|
-
Active: npm installs packages and node dependencies.
|
|
146
|
-
|
|
147
|
-
## Writing Style
|
|
148
|
-
|
|
149
|
-
### Documentation titles
|
|
150
|
-
|
|
151
|
-
When creating a new guide, API, or reference in the `/docs/` directory, use short titles that best describe the topic of your documentation. Name your files in kebab-cases and avoid Raw or camelCase. To learn more about kebab-case you can visit this medium article on [Case Styles](https://medium.com/better-programming/string-case-styles-camel-pascal-snake-and-kebab-case-981407998841).
|
|
152
|
-
|
|
153
|
-
**Examples**: <br>
|
|
154
|
-
>`hook-and-plugins.md`, <br>
|
|
155
|
-
`adding-test-plugins.md`, <br>
|
|
156
|
-
`removing-requests.md`.
|
|
157
|
-
|
|
158
|
-
### Hyperlinks
|
|
159
|
-
|
|
160
|
-
Hyperlinks should have a clear title of what it references.
|
|
161
|
-
Here is how your hyperlink should look:
|
|
162
|
-
|
|
163
|
-
```MD
|
|
164
|
-
<!-- More like this -->
|
|
165
|
-
|
|
166
|
-
// Add clear & brief description
|
|
167
|
-
[Fastify Plugins] (https://www.fastify.io/docs/latest/Plugins/)
|
|
168
|
-
|
|
169
|
-
<!--Less like this -->
|
|
170
|
-
|
|
171
|
-
// incomplete description
|
|
172
|
-
[Fastify] (https://www.fastify.io/docs/latest/Plugins/)
|
|
173
|
-
|
|
174
|
-
// Adding title in link brackets
|
|
175
|
-
[](https://www.fastify.io/docs/latest/Plugins/ "fastify plugin")
|
|
176
|
-
|
|
177
|
-
// Empty title
|
|
178
|
-
[](https://www.fastify.io/docs/latest/Plugins/)
|
|
179
|
-
|
|
180
|
-
// Adding links localhost URLs instead of using code strings (``)
|
|
181
|
-
[http://localhost:3000/](http://localhost:3000/)
|
|
182
|
-
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
Include in your documentation as many essential references as possible, but avoid having numerous links when writing for beginners to avoid distractions.
|
package/docs/Write-Plugin.md
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
<h1 align="center">Fastify</h1>
|
|
2
|
-
|
|
3
|
-
# How to write a good plugin
|
|
4
|
-
First, thank you for deciding to write a plugin for Fastify. Fastify is a minimal framework and plugins are its strength, so thank you.<br>
|
|
5
|
-
The core principles of Fastify are performance, low overhead, and providing a good experience to our users. When writing a plugin, it is important to keep these principles in mind. Therefore, in this document, we will analyze what characterizes a quality plugin.
|
|
6
|
-
|
|
7
|
-
*Need some inspiration? You can use the label ["plugin suggestion"](https://github.com/fastify/fastify/issues?q=is%3Aissue+is%3Aopen+label%3A%22plugin+suggestion%22) in our issue tracker!*
|
|
8
|
-
|
|
9
|
-
## Code
|
|
10
|
-
Fastify uses different techniques to optimize its code, many of them are documented in our Guides. We highly recommend you read [the hitchhiker's guide to plugins](Plugins-Guide.md) to discover all the APIs you can use to build your plugin and learn how to use them.
|
|
11
|
-
|
|
12
|
-
Do you have a question or need some advice? We are more than happy to help you! Just open an issue in our [help repository](https://github.com/fastify/help).
|
|
13
|
-
|
|
14
|
-
Once you submit a plugin to our [ecosystem list](Ecosystem.md), we will review your code and help you improve it if necessary.
|
|
15
|
-
|
|
16
|
-
## Documentation
|
|
17
|
-
Documentation is extremely important. If your plugin is not well documented we will not accept it to the ecosystem list. Lack of quality documentation makes it more difficult for people to use your plugin, and will likely result in it going unused.<br>
|
|
18
|
-
If you want to see some good examples on how to document a plugin take a look at:
|
|
19
|
-
- [`fastify-caching`](https://github.com/fastify/fastify-caching)
|
|
20
|
-
- [`fastify-compress`](https://github.com/fastify/fastify-compress)
|
|
21
|
-
- [`fastify-cookie`](https://github.com/fastify/fastify-cookie)
|
|
22
|
-
- [`point-of-view`](https://github.com/fastify/point-of-view)
|
|
23
|
-
- [`under-pressure`](https://github.com/fastify/under-pressure)
|
|
24
|
-
|
|
25
|
-
## License
|
|
26
|
-
You can license your plugin as you prefer, we do not enforce any kind of license.<br>
|
|
27
|
-
We prefer the [MIT license](https://choosealicense.com/licenses/mit/) because we think it allows more people to use the code freely. For a list of alternative licenses see the [OSI list](https://opensource.org/licenses) or GitHub's [choosealicense.com](https://choosealicense.com/).
|
|
28
|
-
|
|
29
|
-
## Examples
|
|
30
|
-
Always put an example file in your repository. Examples are very helpful for users and give a very fast way to test your plugin. Your users will be grateful.
|
|
31
|
-
|
|
32
|
-
## Test
|
|
33
|
-
It is extremely important that a plugin is thoroughly tested to verify that is working properly.<br>
|
|
34
|
-
A plugin without tests will not be accepted to the ecosystem list. A lack of tests does not inspire trust nor guarantee that the code will continue to work among different versions of its dependencies.
|
|
35
|
-
|
|
36
|
-
We do not enforce any testing library. We use [`tap`](https://www.node-tap.org/) since it offers out-of-the-box parallel testing and code coverage, but it is up to you to choose your library of preference.
|
|
37
|
-
|
|
38
|
-
## Code Linter
|
|
39
|
-
It is not mandatory, but we highly recommend you use a code linter in your plugin. It will ensure a consistent code style and help you to avoid many errors.
|
|
40
|
-
|
|
41
|
-
We use [`standard`](https://standardjs.com/) since it works without the need to configure it and is very easy to integrate into a test suite.
|
|
42
|
-
|
|
43
|
-
## Continuous Integration
|
|
44
|
-
It is not mandatory, but if you release your code as open source, it helps to use Continuous Integration to ensure contributions do not break your plugin and to show that the plugin works as intended. Both [CircleCI](https://circleci.com/) and [GitHub Actions](https://github.com/features/actions) are free for open source projects and easy to set up.<br>
|
|
45
|
-
In addition, you can enable services like [Dependabot](https://dependabot.com/) or [Snyk](https://snyk.io/), which will help you keep your dependencies up to date and discover if a new release of Fastify has some issues with your plugin.
|
|
46
|
-
|
|
47
|
-
## Let's start!
|
|
48
|
-
Awesome, now you know everything you need to know about how to write a good plugin for Fastify!
|
|
49
|
-
After you have built one (or more!) let us know! We will add it to the [ecosystem](https://github.com/fastify/fastify#ecosystem) section of our documentation!
|
|
50
|
-
|
|
51
|
-
If you want to see some real world examples, check out:
|
|
52
|
-
- [`point-of-view`](https://github.com/fastify/point-of-view)
|
|
53
|
-
Templates rendering (*ejs, pug, handlebars, marko*) plugin support for Fastify.
|
|
54
|
-
- [`fastify-mongodb`](https://github.com/fastify/fastify-mongodb)
|
|
55
|
-
Fastify MongoDB connection plugin, with this you can share the same MongoDB connection pool in every part of your server.
|
|
56
|
-
- [`fastify-multipart`](https://github.com/fastify/fastify-multipart)
|
|
57
|
-
Multipart support for Fastify.
|
|
58
|
-
- [`fastify-helmet`](https://github.com/fastify/fastify-helmet) Important security headers for Fastify.
|