Skip to content

Commit 82832c8

Browse files
author
Tony133
committed
chore(): update branch with the master
2 parents fef9153 + 4bdf82a commit 82832c8

File tree

105 files changed

+25306
-9425
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+25306
-9425
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ dist/*
66
!/dist/v5
77
!/dist/v6
88
!/dist/v7
9+
!/dist/v8
910

1011
/tmp
1112
/out-tsc

.husky/pre-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/sh
22
. "$(dirname "$0")/_/husky.sh"
33

4-
npx lint-staged
4+
npx --no-install lint-staged

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
16.15.0
1+
16.16.0

content/cli/overview.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,4 @@ See [usage](/cli/usages) for detailed descriptions for each command.
9393
| `build` | | Compiles an application or workspace into an output folder. |
9494
| `start` | | Compiles and runs an application (or default project in a workspace). |
9595
| `add` | | Imports a library that has been packaged as a **nest library**, running its install schematic. |
96-
| `update` | `u` | Update `@nestjs` dependencies in the `package.json` `"dependencies"` list to their `@latest` version. |
9796
| `info` | `i` | Displays information about installed nest packages and other helpful system info. |

content/cli/usages.md

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Creates and initializes a new Nest project. Prompts for package manager.
3434
| `--package-manager [package-manager]` | Specify package manager. Use `npm`, `yarn`, or `pnpm`. Package manager must be installed globally.<br/> Alias: `-p` |
3535
| `--language [language]` | Specify programming language (`TS` or `JS`).<br/> Alias: `-l` |
3636
| `--collection [collectionName]` | Specify schematics collection. Use package name of installed npm package containing schematic.<br/> Alias: `-c` |
37+
| `--strict` | Start the project with the following TypeScript compiler flags enabled: `strictNullChecks`, `noImplicitAny`, `strictBindCallApply`, `forceConsistentCasingInFileNames`, `noFallthroughCasesInSwitch` |
3738

3839
#### nest generate
3940

@@ -63,8 +64,8 @@ $ nest g <schematic> <name> [options]
6364
| `filter` | `f` | Generate a filter declaration. |
6465
| `gateway` | `ga` | Generate a gateway declaration. |
6566
| `guard` | `gu` | Generate a guard declaration. |
66-
| `interface` | | Generate an interface. |
67-
| `interceptor` | `in` | Generate an interceptor declaration. |
67+
| `interface` | `itf` | Generate an interface. |
68+
| `interceptor` | `itc` | Generate an interceptor declaration. |
6869
| `middleware` | `mi` | Generate a middleware declaration. |
6970
| `module` | `mo` | Generate a module declaration. |
7071
| `pipe` | `pi` | Generate a pipe declaration. |
@@ -88,6 +89,12 @@ $ nest g <schematic> <name> [options]
8889

8990
Compiles an application or workspace into an output folder.
9091

92+
Also, the `build` command is responsible for:
93+
94+
- mapping paths (if using path aliases) via `tsconfig-paths`
95+
- annotating DTOs with OpenAPI decorators (if `@nestjs/swagger` CLI plugin is enabled)
96+
- annotating DTOs with GraphQL decorators (if `@nestjs/graphql` CLI plugin is enabled)
97+
9198
```bash
9299
$ nest build <name> [options]
93100
```
@@ -152,17 +159,6 @@ $ nest add <name> [options]
152159
| -------- | ---------------------------------- |
153160
| `<name>` | The name of the library to import. |
154161

155-
#### nest update
156-
157-
Updates `@nestjs` dependencies in the `package.json` `"dependencies"` list to their `@latest` version.
158-
159-
##### Options
160-
161-
| Option | Description |
162-
| --------- | ----------------------------------------------------------------------- |
163-
| `--force` | Do **upgrade** instead of update <br/>Alias `-f` |
164-
| `--tag` | Update to tagged version (use `@latest`, `@<tag>`, etc) <br/>Alias `-t` |
165-
166162
#### nest info
167163

168164
Displays information about installed nest packages and other helpful system info. For example:

content/cli/workspaces.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,9 @@ These properties specify the compiler to use as well as various options that aff
197197
These properties specify the default generate options to be used by the `nest generate` command.
198198

199199
| Property Name | Property Value Type | Description |
200-
| ------------- | ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
200+
|---------------|---------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
201201
| `spec` | boolean _or_ object | If the value is boolean, a value of `true` enables `spec` generation by default and a value of `false` disables it. A flag passed on the CLI command line overrides this setting, as does a project-specific `generateOptions` setting (more below). If the value is an object, each key represents a schematic name, and the boolean value determines whether the default spec generation is enabled / disabled for that specific schematic. |
202+
| `flat` | boolean | If true, all generate commands will generate a flat structure |
202203

203204
The following example uses a boolean value to specify that spec file generation should be disabled by default for all projects:
204205

@@ -211,6 +212,17 @@ The following example uses a boolean value to specify that spec file generation
211212
}
212213
```
213214

215+
The following example uses a boolean value to specify flat file generation should be the default for all projects:
216+
217+
```javascript
218+
{
219+
"generateOptions": {
220+
"flat": true
221+
},
222+
...
223+
}
224+
```
225+
214226
In the following example, `spec` file generation is disabled only for `service` schematics (e.g., `nest generate service...`):
215227

216228
```javascript

content/discover/who-uses.json

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,14 @@
190190
{
191191
"logo": "/assets/logo/vue-storefront.png",
192192
"url": "https://www.vuestorefront.io/"
193+
},
194+
{
195+
"logo": "/assets/logo/fuse-logo.svg",
196+
"url": "https://fuseautotech.com"
197+
},
198+
{
199+
"logo": "/assets/logo/amplication.svg",
200+
"url": "https://amplication.com"
193201
}
194202
],
195203
"Body": [
@@ -258,6 +266,9 @@
258266
"https://dyrector.io",
259267
"https://stijlbreuk.nl",
260268
"https://polygon-software.ch",
261-
"https://bewith.io"
269+
"https://bewith.io",
270+
"https://swetrix.com",
271+
"https://swyftlogistics.com",
272+
"https://evershop.io"
262273
]
263-
}
274+
}

content/exception-filters.md

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,24 @@ in the `response` argument. To override the entire JSON response body, pass an o
6060
The second constructor argument - `status` - should be a valid HTTP status code.
6161
Best practice is to use the `HttpStatus` enum imported from `@nestjs/common`.
6262

63-
Here's an example overriding the entire response body:
63+
There is a **third** constructor argument (optional) - `options` - that can be used to provide an error [cause](https://nodejs.org/en/blog/release/v16.9.0/#error-cause). This `cause` object is not serialized into the response object, but it can be useful for logging purposes, providing valuable information about the inner error that caused the `HttpException` to be thrown.
64+
65+
Here's an example overriding the entire response body and providing an error cause:
6466

6567
```typescript
6668
@@filename(cats.controller)
6769
@Get()
6870
async findAll() {
69-
throw new HttpException({
71+
try {
72+
await this.service.findAll()
73+
} catch (error) {
74+
throw new HttpException({
7075
status: HttpStatus.FORBIDDEN,
7176
error: 'This is a custom message',
72-
}, HttpStatus.FORBIDDEN);
77+
}, HttpStatus.FORBIDDEN, {
78+
cause: error
79+
});
80+
}
7381
}
7482
```
7583

@@ -130,6 +138,22 @@ Nest provides a set of standard exceptions that inherit from the base `HttpExcep
130138
- `GatewayTimeoutException`
131139
- `PreconditionFailedException`
132140

141+
All the built-in exceptions can also provide both an error `cause` and an error description using the `options` parameter:
142+
143+
```typescript
144+
throw new BadRequestException('Something bad happened', { cause: new Error(), description: 'Some error description' })
145+
```
146+
147+
Using the above, this is how the response would look:
148+
149+
```json
150+
{
151+
"message": "Something bad happened",
152+
"error": "Some error description",
153+
"statusCode": 400,
154+
}
155+
```
156+
133157
#### Exception filters
134158

135159
While the base (built-in) exception filter can automatically handle many cases for you, you may want **full control** over the exceptions layer. For example, you may want to add logging or use a different JSON schema based on some dynamic factors. **Exception filters** are designed for exactly this purpose. They let you control the exact flow of control and the content of the response sent back to the client.

content/faq/errors.md

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,49 @@ Potential solutions:
1717
})
1818
```
1919
20-
The most common culprit of the error, is not having the `provider` in the module's `providers` array. Please make sure that the provider is indeed in the `providers` array and following [standard NestJS provider practices](/fundamentals/custom-providers#di-fundamentals).
20+
The most common culprit of the error, is not having the `<provider>` in the module's `providers` array. Please make sure that the provider is indeed in the `providers` array and following [standard NestJS provider practices](/fundamentals/custom-providers#di-fundamentals).
2121

2222
There are a few gotchas, that are common. One is putting a provider in an `imports` array. If this is the case, the error will have the provider's name where `<module>` should be.
2323
24-
If you run across this error while developing, take a look at the module mentioned in the error message and look at its `providers`. For each provider in the `providers` array, make sure the module has access to all of the dependencies. Often times, `providers` are duplicated in a "Feature Module" and a "Root Module" which means Nest will try to instantiate the provider twice. More than likely, the module containing the `provider` being duplicated should be added in the "Root Module"'s `imports` array instead.
24+
If you run across this error while developing, take a look at the module mentioned in the error message and look at its `providers`. For each provider in the `providers` array, make sure the module has access to all of the dependencies. Often times, `providers` are duplicated in a "Feature Module" and a "Root Module" which means Nest will try to instantiate the provider twice. More than likely, the module containing the `<provider>` being duplicated should be added in the "Root Module"'s `imports` array instead.
2525

26-
If the `unknown_token` above is the string `dependency`, you might have a circular file import. This is different from the [circular dependency](./errors.md#circular-dependency-error) below because instead of having providers depend on each other in their constructors, it just means that two files end up importing each other. A common case would be a module file declaring a token and importing a provider, and the provider import the token constant from the module file. If you are using barrel files, ensure that your barrel imports do not end up creating these circular imports as well.
26+
If the `<unknown_token>` above is the string `dependency`, you might have a circular file import. This is different from the [circular dependency](/faq/common-errors#circular-dependency-error) below because instead of having providers depend on each other in their constructors, it just means that two files end up importing each other. A common case would be a module file declaring a token and importing a provider, and the provider import the token constant from the module file. If you are using barrel files, ensure that your barrel imports do not end up creating these circular imports as well.
27+
28+
If the `<unknown_token>` above is the string `Object`, it means that you're injecting using an type/interface without a proper provider's token. To fix that, make sure you're importing the class reference or use a custom token with `@Inject()` decorator. Read the [custom providers page](/fundamentals/custom-providers).
29+
30+
Also, make sure you didn't end up injecting the provider on itself because self-injections are not allowed in NestJS. When this happens, `<unknown_token>` will likely be equal to `<provider>`.
31+
32+
If you are in a **monorepo setup**, you may face the same error as above but for core provider called `ModuleRef` as a `<unknown_token>`:
33+
34+
```bash
35+
Nest can't resolve dependencies of the <provider> (?).
36+
Please make sure that the argument ModuleRef at index [<index>] is available in the <module> context.
37+
...
38+
```
39+
40+
This likely happens when your project end up loading two Node modules of the package `@nestjs/core`, like this:
41+
42+
```text
43+
.
44+
├── package.json
45+
├── apps
46+
│ └── api
47+
│ └── node_modules
48+
│ └── @nestjs/bull
49+
│ └── node_modules
50+
│ └── @nestjs/core
51+
└── node_modules
52+
├── (other packages)
53+
└── @nestjs/core
54+
```
55+
56+
Solutions:
57+
58+
- For **Yarn** Workspaces, use the [nohoist feature](https://classic.yarnpkg.com/blog/2018/02/15/nohoist) to prevent hoisting the package `@nestjs/core`.
2759
2860
#### "Circular dependency" error
2961
30-
Occasionally you'll find it difficult to avoid [circular dependencies](/fundamentals/circular-dependency) in your application. You'll need to take some steps to help Nest resolve these. Errors that arise from circular dependencies look like this:
62+
Occasionally you'll find it difficult to avoid [circular dependencies](https://docs.nestjs.com/fundamentals/circular-dependency) in your application. You'll need to take some steps to help Nest resolve these. Errors that arise from circular dependencies look like this:
3163
3264
```bash
3365
Nest cannot create the <module> instance.

content/faq/hybrid-application.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ const microserviceTcp = app.connectMicroservice<MicroserviceOptions>({
2727
const microserviceRedis = app.connectMicroservice<MicroserviceOptions>({
2828
transport: Transport.REDIS,
2929
options: {
30-
url: 'redis://localhost:6379',
30+
host: 'localhost',
31+
port: 6379,
3132
},
3233
});
3334

@@ -70,7 +71,10 @@ By default a hybrid application will not inherit global pipes, interceptors, gua
7071
To inherit these configuration properties from the main application, set the `inheritAppConfig` property in the second argument (an optional options object) of the `connectMicroservice()` call, as follow:
7172

7273
```typescript
73-
const microservice = app.connectMicroservice({
74-
transport: Transport.TCP
75-
}, { inheritAppConfig: true });
74+
const microservice = app.connectMicroservice(
75+
{
76+
transport: Transport.TCP,
77+
},
78+
{ inheritAppConfig: true },
79+
);
7680
```

0 commit comments

Comments
 (0)