Skip to content

Commit 28ee7a9

Browse files
committed
docs(content): Pluralise class names
Fix #1176 According to @kamilmysliwiec, "plural form is recommended". I updated some of the singularly named classes and updated them, along with file names. Signed-off-by: Stanislas Lange <[email protected]>
1 parent badad7b commit 28ee7a9

File tree

4 files changed

+51
-51
lines changed

4 files changed

+51
-51
lines changed

content/microservices/grpc.md

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,15 @@ The <strong>gRPC</strong> transporter options object exposes the properties desc
9090

9191
#### Sample gRPC service
9292

93-
Let's define our sample gRPC service called `HeroService`. In the above `options` object, the`protoPath` property sets a path to the `.proto` definitions file `hero.proto`. The `hero.proto` file is structured using <a href="https://developers.google.com/protocol-buffers">protocol buffers</a>. Here's what it looks like:
93+
Let's define our sample gRPC service called `HeroesService`. In the above `options` object, the`protoPath` property sets a path to the `.proto` definitions file `hero.proto`. The `hero.proto` file is structured using <a href="https://developers.google.com/protocol-buffers">protocol buffers</a>. Here's what it looks like:
9494

9595
```typescript
9696
// hero/hero.proto
9797
syntax = "proto3";
9898

9999
package hero;
100100

101-
service HeroService {
101+
service HeroesService {
102102
rpc FindOne (HeroById) returns (Hero) {}
103103
}
104104

@@ -112,17 +112,17 @@ message Hero {
112112
}
113113
```
114114

115-
Our `HeroService` exposes a `FindOne()` method. This method expects an input argument of type `HeroById` and returns a `Hero` message (protocol buffers use `message` elements to define both parameter types and return types).
115+
Our `HeroesService` exposes a `FindOne()` method. This method expects an input argument of type `HeroById` and returns a `Hero` message (protocol buffers use `message` elements to define both parameter types and return types).
116116

117117
Next, we need to implement the service. To define a handler that fulfills this definition, we use the `@GrpcMethod()` decorator in a controller, as shown below. This decorator provides the metadata needed to declare a method as a gRPC service method.
118118

119119
> info **Hint** The `@MessagePattern()` decorator (<a href="microservices/basics#request-response">read more</a>) introduced in previous microservices chapters is not used with gRPC-based microservices. The `@GrpcMethod()` decorator effectively takes its place for gRPC-based microservices.
120120
121121
```typescript
122-
@@filename(hero.controller)
122+
@@filename(heroes.controller)
123123
@Controller()
124-
export class HeroController {
125-
@GrpcMethod('HeroService', 'FindOne')
124+
export class HeroesController {
125+
@GrpcMethod('HeroesService', 'FindOne')
126126
findOne(data: HeroById, metadata: any): Hero {
127127
const items = [
128128
{ id: 1, name: 'John' },
@@ -133,8 +133,8 @@ export class HeroController {
133133
}
134134
@@switch
135135
@Controller()
136-
export class HeroController {
137-
@GrpcMethod('HeroService', 'FindOne')
136+
export class HeroesController {
137+
@GrpcMethod('HeroesService', 'FindOne')
138138
findOne(data, metadata) {
139139
const items = [
140140
{ id: 1, name: 'John' },
@@ -147,17 +147,17 @@ export class HeroController {
147147

148148
> info **Hint** The `@GrpcMethod()` decorator is imported from the `@nestjs/microservices` package.
149149
150-
The decorator shown above takes two arguments. The first is the service name (e.g., `'HeroService'`), corresponding to the `HeroService` service definition in `hero.proto`. The second (the string `'FindOne'`) corresponds to the `FindOne()` rpc method defined within `HeroService` in the `hero.proto` file.
150+
The decorator shown above takes two arguments. The first is the service name (e.g., `'HeroesService'`), corresponding to the `HeroesService` service definition in `hero.proto`. The second (the string `'FindOne'`) corresponds to the `FindOne()` rpc method defined within `HeroesService` in the `hero.proto` file.
151151

152152
The `findOne()` handler method takes two arguments, the `data` passed from the caller and `metadata` that stores gRPC request metadata.
153153

154154
Both `@GrpcMethod()` decorator arguments are optional. If called without the second argument (e.g., `'FindOne'`), Nest will automatically associate the `.proto` file rpc method with the handler based on converting the handler name to upper camel case (e.g., the `findOne` handler is associated with the `FindOne` rpc call definition). This is shown below.
155155

156156
```typescript
157-
@@filename(hero.controller)
157+
@@filename(heroes.controller)
158158
@Controller()
159-
export class HeroController {
160-
@GrpcMethod('HeroService')
159+
export class HeroesController {
160+
@GrpcMethod('HeroesService')
161161
findOne(data: HeroById, metadata: any): Hero {
162162
const items = [
163163
{ id: 1, name: 'John' },
@@ -168,8 +168,8 @@ export class HeroController {
168168
}
169169
@@switch
170170
@Controller()
171-
export class HeroController {
172-
@GrpcMethod('HeroService')
171+
export class HeroesController {
172+
@GrpcMethod('HeroesService')
173173
findOne(data, metadata) {
174174
const items = [
175175
{ id: 1, name: 'John' },
@@ -180,12 +180,12 @@ export class HeroController {
180180
}
181181
```
182182

183-
You can also omit the first `@GrpcMethod()` argument. In this case, Nest automatically associates the handler with the service definition from the proto definitions file based on the **class** name where the handler is defined. For example, in the following code, class `HeroService` associates its handler methods with the `HeroService` service definition in the `hero.proto` file based on the matching of the name `'HeroService'`.
183+
You can also omit the first `@GrpcMethod()` argument. In this case, Nest automatically associates the handler with the service definition from the proto definitions file based on the **class** name where the handler is defined. For example, in the following code, class `HeroesService` associates its handler methods with the `HeroesService` service definition in the `hero.proto` file based on the matching of the name `'HeroesService'`.
184184

185185
```typescript
186-
@@filename(hero.controller)
186+
@@filename(heroes.controller)
187187
@Controller()
188-
export class HeroService {
188+
export class HeroesService {
189189
@GrpcMethod()
190190
findOne(data: HeroById, metadata: any): Hero {
191191
const items = [
@@ -197,7 +197,7 @@ export class HeroService {
197197
}
198198
@@switch
199199
@Controller()
200-
export class HeroService {
200+
export class HeroesService {
201201
@GrpcMethod()
202202
findOne(data, metadata) {
203203
const items = [
@@ -237,12 +237,12 @@ Once registered, we can inject the configured `ClientGrpc` object with `@Inject(
237237
```typescript
238238
@Injectable()
239239
export class AppService implements OnModuleInit {
240-
private heroService: HeroService;
240+
private heroService: HeroesService;
241241

242242
constructor(@Inject('HERO_PACKAGE') private client: ClientGrpc) {}
243243

244244
onModuleInit() {
245-
this.heroService = this.client.getService<HeroService>('HeroService');
245+
this.heroService = this.client.getService<HeroesService>('HeroesService');
246246
}
247247

248248
getHero(): Observable<string> {
@@ -267,10 +267,10 @@ export class AppService implements OnModuleInit {
267267
})
268268
client: ClientGrpc;
269269

270-
private heroService: HeroService;
270+
private heroService: HeroesService;
271271

272272
onModuleInit() {
273-
this.heroService = this.client.getService<HeroService>('HeroService');
273+
this.heroService = this.client.getService<HeroesService>('HeroesService');
274274
}
275275

276276
getHero(): Observable<string> {
@@ -281,20 +281,20 @@ export class AppService implements OnModuleInit {
281281

282282
Finally, for more complex scenarios, we can inject a dynamically configured client using the `ClientProxyFactory` class as described <a href="/microservices/basics#client">here</a>.
283283

284-
In either case, we end up with a reference to our `HeroService` proxy object, which exposes the same set of methods that are defined inside the `.proto` file. Now, when we access this proxy object (i.e., `heroService`), the gRPC system automatically serializes requests, forwards them to the remote system, returns a response, and deserializes the response. Because gRPC shields us from these network communication details, `heroService` looks and acts like a local provider.
284+
In either case, we end up with a reference to our `HeroesService` proxy object, which exposes the same set of methods that are defined inside the `.proto` file. Now, when we access this proxy object (i.e., `heroService`), the gRPC system automatically serializes requests, forwards them to the remote system, returns a response, and deserializes the response. Because gRPC shields us from these network communication details, `heroService` looks and acts like a local provider.
285285

286-
Note, all service methods are **lower camel cased** (in order to follow the natural convention of the language). So, for example, while our `.proto` file `HeroService` definition contains the `FindOne()` function, the `heroService` instance will provide the `findOne()` method.
286+
Note, all service methods are **lower camel cased** (in order to follow the natural convention of the language). So, for example, while our `.proto` file `HeroesService` definition contains the `FindOne()` function, the `heroService` instance will provide the `findOne()` method.
287287

288288
```typescript
289-
interface HeroService {
289+
interface HeroesService {
290290
findOne(data: { id: number }): Observable<any>;
291291
}
292292
```
293293

294294
A message handler is also able to return an `Observable`, in which case the result values will be emitted until the stream is completed.
295295

296296
```typescript
297-
@@filename(hero.controller)
297+
@@filename(heroes.controller)
298298
@Get()
299299
call(): Observable<any> {
300300
return this.heroService.findOne({ id: 1 });

content/microservices/kafka.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ client: ClientKafka;
168168
The `ClientKafka` class provides the `subscribeToResponseOf()` method. The `subscribeToResponseOf()` method takes a request's topic name as an argument and adds the derived reply topic name to a collection of reply topics. This method is required when implementing the message pattern.
169169

170170
```typescript
171-
@@filename(hero.controller)
171+
@@filename(heroes.controller)
172172
onModuleInit() {
173173
this.client.subscribeToResponseOf('hero.kill.dragon');
174174
}
@@ -177,7 +177,7 @@ onModuleInit() {
177177
If the `ClientKafka` instance is created asynchronously, the `subscribeToResponseOf()` method must be called before calling the `connect()` method.
178178

179179
```typescript
180-
@@filename(hero.controller)
180+
@@filename(heroes.controller)
181181
async onModuleInit() {
182182
this.client.subscribeToResponseOf('hero.kill.dragon');
183183
await this.client.connect();
@@ -205,9 +205,9 @@ Nest receives incoming Kafka messages as an object with `key`, `value`, and `hea
205205
Nest sends outgoing Kafka messages after a serialization process when publishing events or sending messages. This occurs on arguments passed to the `ClientKafka` `emit()` and `send()` methods or on values returned from a `@MessagePattern` method. This serialization "stringifies" objects that are not strings or buffers by using `JSON.stringify()` or the `toString()` prototype method.
206206

207207
```typescript
208-
@@filename(hero.controller)
208+
@@filename(heroes.controller)
209209
@Controller()
210-
export class HeroController {
210+
export class HeroesController {
211211
@MessagePattern('hero.kill.dragon')
212212
killDragon(@Payload() message: KillDragonMessage): any {
213213
const dragonId = message.dragonId;
@@ -225,9 +225,9 @@ export class HeroController {
225225
Outgoing messages can also be keyed by passing an object with the `key` and `value` properties. Keying messages is important for meeting the [co-partitioning requirement](https://docs.confluent.io/current/ksql/docs/developer-guide/partition-data.html#co-partitioning-requirements).
226226

227227
```typescript
228-
@@filename(hero.controller)
228+
@@filename(heroes.controller)
229229
@Controller()
230-
export class HeroController {
230+
export class HeroesController {
231231
@MessagePattern('hero.kill.dragon')
232232
killDragon(@Payload() message: KillDragonMessage): any {
233233
const realm = 'Nest';
@@ -253,9 +253,9 @@ export class HeroController {
253253
Additionally, messages passed in this format can also contain custom headers set in the `headers` hash property. Header hash property values must be either of type `string` or type `Buffer`.
254254

255255
```typescript
256-
@@filename(hero.controller)
256+
@@filename(heroes.controller)
257257
@Controller()
258-
export class HeroController {
258+
export class HeroesController {
259259
@MessagePattern('hero.kill.dragon')
260260
killDragon(@Payload() message: KillDragonMessage): any {
261261
const realm = 'Nest';
@@ -355,7 +355,7 @@ const app = await NestFactory.createMicroservice(ApplicationModule, {
355355
And for the client:
356356

357357
```typescript
358-
@@filename(hero.controller)
358+
@@filename(heroes.controller)
359359
@Client({
360360
transport: Transport.KAFKA,
361361
options: {
@@ -376,7 +376,7 @@ client: ClientKafka;
376376
Since the Kafka microservice message pattern utilizes two topics for the request and reply channels, a reply pattern should be derived from the request topic. By default, the name of the reply topic is the composite of the request topic name with `.reply` appended.
377377

378378
```typescript
379-
@@filename(hero.controller)
379+
@@filename(heroes.controller)
380380
onModuleInit() {
381381
this.client.subscribeToResponseOf('hero.get'); // hero.get.reply
382382
}

content/techniques/authentication.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ We've followed the recipe described earlier for all Passport strategies. In our
264264

265265
We've also implemented the `validate()` method. For each strategy, Passport will call the verify function (implemented with the `validate()` method in `@nestjs/passport`) using an appropriate strategy-specific set of parameters. For the local-strategy, Passport expects a `validate()` method with the following signature: `validate(username: string, password:string): any`.
266266

267-
Most of the validation work is done in our `AuthService` (with the help of our `UserService`), so this method is quite straightforward. The `validate()` method for **any** Passport strategy will follow a similar pattern, varying only in the details of how credentials are represented. If a user is found and the credentials are valid, the user is returned so Passport can complete its tasks (e.g., creating the `user` property on the `Request` object), and the request handling pipeline can continue. If it's not found, we throw an exception and let our <a href="exception-filters">exceptions layer</a> handle it.
267+
Most of the validation work is done in our `AuthService` (with the help of our `UsersService`), so this method is quite straightforward. The `validate()` method for **any** Passport strategy will follow a similar pattern, varying only in the details of how credentials are represented. If a user is found and the credentials are valid, the user is returned so Passport can complete its tasks (e.g., creating the `user` property on the `Request` object), and the request handling pipeline can continue. If it's not found, we throw an exception and let our <a href="exception-filters">exceptions layer</a> handle it.
268268

269269
Typically, the only significant difference in the `validate()` method for each strategy is **how** you determine if a user exists and is valid. For example, in a JWT strategy, depending on requirements, we may evaluate whether the `userId` carried in the decoded token matches a record in our user database, or matches a list of revoked tokens. Hence, this pattern of sub-classing and implementing strategy-specific validation is consistent, elegant and extensible.
270270

@@ -959,6 +959,6 @@ To use above decorator in your resolver, be sure to include it as a parameter of
959959
@Query(returns => User)
960960
@UseGuards(GqlAuthGuard)
961961
whoAmI(@CurrentUser() user: User) {
962-
return this.userService.findById(user.id);
962+
return this.UsersService.findById(user.id);
963963
}
964964
```

content/techniques/sql.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ import { User } from './user.entity';
229229

230230
@Injectable()
231231
@Dependencies(getRepositoryToken(User))
232-
export class UserService {
232+
export class UsersService {
233233
constructor(usersRepository) {
234234
this.usersRepository = usersRepository;
235235
}
@@ -272,13 +272,13 @@ Now if we import `UsersModule` in `UserHttpModule`, we can use `@InjectRepositor
272272
@@filename(users-http.module)
273273
import { Module } from '@nestjs/common';
274274
import { UsersModule } from './user.module';
275-
import { UserService } from './user.service';
276-
import { UserController } from './user.controller';
275+
import { UsersService } from './users.service';
276+
import { UsersController } from './users.controller';
277277

278278
@Module({
279279
imports: [UsersModule],
280-
providers: [UserService],
281-
controllers: [UserController]
280+
providers: [UsersService],
281+
controllers: [UsersController]
282282
})
283283
export class UserHttpModule {}
284284
```
@@ -543,7 +543,7 @@ The `@nestjs/typeorm` package exposes the `getRepositoryToken()` function which
543543
```typescript
544544
@Module({
545545
providers: [
546-
UserService,
546+
UsersService,
547547
{
548548
provide: getRepositoryToken(User),
549549
useValue: mockRepository,
@@ -553,7 +553,7 @@ The `@nestjs/typeorm` package exposes the `getRepositoryToken()` function which
553553
export class UsersModule {}
554554
```
555555

556-
Now a substitute `mockRepository` will be used as the `UserRepository`. Whenever any class asks for `UserRepository` using an `@InjectRepository()` decorator, Nest will use the registered `mockRepository` object.
556+
Now a substitute `mockRepository` will be used as the `UsersRepository`. Whenever any class asks for `UsersRepository` using an `@InjectRepository()` decorator, Nest will use the registered `mockRepository` object.
557557

558558
#### Custom repository
559559

@@ -862,7 +862,7 @@ import { User } from './user.model';
862862

863863
@Injectable()
864864
@Dependencies(getModelToken(User))
865-
export class UserService {
865+
export class UsersService {
866866
constructor(usersRepository) {
867867
this.usersRepository = usersRepository;
868868
}
@@ -910,13 +910,13 @@ Now if we import `UsersModule` in `UserHttpModule`, we can use `@InjectModel(Use
910910
@@filename(users-http.module)
911911
import { Module } from '@nestjs/common';
912912
import { UsersModule } from './user.module';
913-
import { UserService } from './user.service';
914-
import { UserController } from './user.controller';
913+
import { UsersService } from './users.service';
914+
import { UsersController } from './users.controller';
915915

916916
@Module({
917917
imports: [UsersModule],
918-
providers: [UserService],
919-
controllers: [UserController]
918+
providers: [UsersService],
919+
controllers: [UsersController]
920920
})
921921
export class UserHttpModule {}
922922
```
@@ -1112,7 +1112,7 @@ The `@nestjs/sequelize` package exposes the `getModelToken()` function which ret
11121112
```typescript
11131113
@Module({
11141114
providers: [
1115-
UserService,
1115+
UsersService,
11161116
{
11171117
provide: getModelToken(User),
11181118
useValue: mockModel,

0 commit comments

Comments
 (0)