@hodfords/nestjs-grpc-helper 11.4.0-rc.2 → 11.4.0-rc.3
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/package.json +4 -3
- package/templates/body-method-template.hbs +28 -0
- package/templates/grpc-service-template.hbs +5 -0
- package/templates/index-template.hbs +5 -0
- package/templates/method-template.hbs +19 -0
- package/templates/mock-method-template.hbs +19 -0
- package/templates/mock-module-template.hbs +12 -0
- package/templates/mock-providers-template.hbs +6 -0
- package/templates/module-template.hbs +44 -0
- package/templates/proto-native-list.hbs +4 -0
- package/templates/proto-service-definition.hbs +6 -0
- package/templates/service-interface.hbs +7 -0
- package/templates/service-template.hbs +49 -0
- package/templates/usage-doc-template.hbs +17 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hodfords/nestjs-grpc-helper",
|
|
3
|
-
"version": "11.4.0-rc.
|
|
3
|
+
"version": "11.4.0-rc.3",
|
|
4
4
|
"description": "A utility for simplifying gRPC integration and communication in NestJS applications",
|
|
5
5
|
"author": "",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -43,10 +43,11 @@
|
|
|
43
43
|
"@grpc/grpc-js": "*",
|
|
44
44
|
"@grpc/proto-loader": "*",
|
|
45
45
|
"@hodfords/nestjs-cls-translation": "*",
|
|
46
|
-
"
|
|
47
|
-
"
|
|
46
|
+
"chalk": "*",
|
|
47
|
+
"shelljs": "*"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
+
"@hodfords/nestjs-exception": "^11.0.2",
|
|
50
51
|
"@hodfords/nestjs-cls-translation": "11.0.2",
|
|
51
52
|
"@hodfords/nestjs-command": "11.0.6",
|
|
52
53
|
"@hodfords/nestjs-eslint-config": "11.0.2",
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{{#hasItems directParams}}
|
|
2
|
+
const param = {
|
|
3
|
+
{{#each directParams}}
|
|
4
|
+
{{this.name}},
|
|
5
|
+
{{/each}}
|
|
6
|
+
};
|
|
7
|
+
{{/hasItems}}
|
|
8
|
+
{{#if response}}
|
|
9
|
+
{{#if response.isArray}}
|
|
10
|
+
return await GrpcHelper.with(this.client, {{{response.responseClass.name}}}, this.options)
|
|
11
|
+
.service('{{{serviceName}}}')
|
|
12
|
+
.method('{{{method}}}')
|
|
13
|
+
.data({{#if parameterName}}param{{else}}{}{{/if}}{{#if parameterType}}, {{{parameterType}}}{{/if}})
|
|
14
|
+
.getMany() as any;
|
|
15
|
+
{{else}}
|
|
16
|
+
return await GrpcHelper.with(this.client, {{{response.responseClass.name}}}, this.options)
|
|
17
|
+
.service('{{{serviceName}}}')
|
|
18
|
+
.method('{{{method}}}')
|
|
19
|
+
.data({{#if parameterName}}param{{else}}{}{{/if}}{{#if parameterType}}, {{{parameterType}}}{{/if}})
|
|
20
|
+
.getOne() as any;
|
|
21
|
+
{{/if}}
|
|
22
|
+
{{else}}
|
|
23
|
+
await GrpcHelper.with(this.client, null as any, this.options)
|
|
24
|
+
.service('{{{serviceName}}}')
|
|
25
|
+
.method('{{{method}}}')
|
|
26
|
+
.data({{#if parameterName}}param{{else}}{}{{/if}}{{#if parameterType}}, {{{parameterType}}}{{/if}})
|
|
27
|
+
.getMany();
|
|
28
|
+
{{/if}}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{{#hasItems directParams}}
|
|
2
|
+
async {{method}}(
|
|
3
|
+
{{#each directParams}}
|
|
4
|
+
{{this.name}}{{#unless this.required}}?{{/unless}}: {{this.type}}{{#if this.isArray}}[]{{/if}}{{#unless @last}}, {{/unless}}
|
|
5
|
+
{{/each}}
|
|
6
|
+
): Promise<{{returnType}}> {
|
|
7
|
+
{{{body}}}
|
|
8
|
+
}
|
|
9
|
+
{{else}}
|
|
10
|
+
{{#if params}}
|
|
11
|
+
async {{method}}(param: {{params}}): Promise<{{returnType}}> {
|
|
12
|
+
{{{body}}}
|
|
13
|
+
}
|
|
14
|
+
{{else}}
|
|
15
|
+
async {{method}}(): Promise<{{returnType}}> {
|
|
16
|
+
{{{body}}}
|
|
17
|
+
}
|
|
18
|
+
{{/if}}
|
|
19
|
+
{{/hasItems}}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{{#hasItems directParams}}
|
|
2
|
+
async {{method}}(
|
|
3
|
+
{{#each directParams}}
|
|
4
|
+
{{this.name}}{{#unless this.required}}?{{/unless}}: {{this.type}}{{#if this.isArray}}[]{{/if}}{{#unless @last}}, {{/unless}}
|
|
5
|
+
{{/each}}
|
|
6
|
+
): Promise<{{returnType}}> {
|
|
7
|
+
{{{body}}}
|
|
8
|
+
}
|
|
9
|
+
{{else}}
|
|
10
|
+
{{#if params}}
|
|
11
|
+
async {{method}}(param: {{params}}): Promise<{{returnType}}> {
|
|
12
|
+
{{{body}}}
|
|
13
|
+
}
|
|
14
|
+
{{else}}
|
|
15
|
+
async {{method}}(): Promise<{{returnType}}> {
|
|
16
|
+
{{{body}}}
|
|
17
|
+
}
|
|
18
|
+
{{/if}}
|
|
19
|
+
{{/hasItems}}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Module, Global } from '@nestjs/common';
|
|
2
|
+
import { {{#each importServices}}{{this}}{{#unless @last}},{{/unless}}{{/each}} } from './services/{{fileName}}.service';
|
|
3
|
+
|
|
4
|
+
@Global()
|
|
5
|
+
@Module({
|
|
6
|
+
providers: [
|
|
7
|
+
{{providers}}
|
|
8
|
+
],
|
|
9
|
+
exports: [{{#each services}}{{this}}{{#unless @last}},{{/unless}}{{/each}}]
|
|
10
|
+
})
|
|
11
|
+
export class Mock{{moduleName}}Module {
|
|
12
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { DynamicModule, Module, Global } from '@nestjs/common';
|
|
2
|
+
import { ClientsModule } from '@nestjs/microservices';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { MicroserviceModuleOptionType } from './types/microservice-option.type';
|
|
5
|
+
import { {{#each services}}{{this}}{{#unless @last}},{{/unless}}{{/each}} } from './services/{{fileName}}.service';
|
|
6
|
+
import { CustomGrpcClient } from '@hodfords/nestjs-grpc-helper';
|
|
7
|
+
import * as grpc from '@grpc/grpc-js';
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@Global()
|
|
11
|
+
@Module({})
|
|
12
|
+
export class {{moduleName}}Module {
|
|
13
|
+
static register(options: MicroserviceModuleOptionType): DynamicModule {
|
|
14
|
+
return {
|
|
15
|
+
module: {{moduleName}}Module,
|
|
16
|
+
providers: [
|
|
17
|
+
{{#each services}}{{this}}{{#unless @last}},{{/unless}}{{/each}},
|
|
18
|
+
{
|
|
19
|
+
provide: '{{packageName}}_OPTIONS',
|
|
20
|
+
useValue: options
|
|
21
|
+
}
|
|
22
|
+
],
|
|
23
|
+
exports: [{{#each services}}{{this}}{{#unless @last}},{{/unless}}{{/each}}],
|
|
24
|
+
imports: [
|
|
25
|
+
ClientsModule.register([
|
|
26
|
+
{
|
|
27
|
+
name: '{{packageName}}_PACKAGE',
|
|
28
|
+
customClass: CustomGrpcClient as any,
|
|
29
|
+
options: {
|
|
30
|
+
url: options.url,
|
|
31
|
+
package: '{{packageName}}',
|
|
32
|
+
protoPath: path.join(__dirname, 'microservice.proto'),
|
|
33
|
+
credentials: options.ssl ? grpc.credentials.createSsl() : undefined,
|
|
34
|
+
maxReceiveMessageLength: options.maxReceiveMessageLength ?? 4 * 1024 * 1024,
|
|
35
|
+
loader: {
|
|
36
|
+
arrays: options.shouldLoadEmptyArray ?? false
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
])
|
|
41
|
+
]
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { GrpcHelper } from '../helpers/grpc.helper';
|
|
2
|
+
import { Inject, Injectable } from '@nestjs/common';
|
|
3
|
+
import { ClientGrpc } from '@nestjs/microservices';
|
|
4
|
+
import { MicroserviceModuleOptionType } from '../types/microservice-option.type';
|
|
5
|
+
import { Type } from 'class-transformer';
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
7
|
+
import { Property, AnyType, sample, sampleMethod } from '@hodfords/nestjs-grpc-helper';
|
|
8
|
+
{{#if addAllowDecorator}}
|
|
9
|
+
import { Allow } from 'class-validator';
|
|
10
|
+
{{/if}}
|
|
11
|
+
|
|
12
|
+
{{#each serviceContent}}
|
|
13
|
+
{{#if isMock}}
|
|
14
|
+
export class Mock{{ serviceName }} {
|
|
15
|
+
{{#each methods}}
|
|
16
|
+
{{{this}}}
|
|
17
|
+
{{/each}}
|
|
18
|
+
}
|
|
19
|
+
{{else}}
|
|
20
|
+
@Injectable()
|
|
21
|
+
export class {{ serviceName }} {
|
|
22
|
+
constructor(
|
|
23
|
+
@Inject('{{ ../packageName }}_PACKAGE') private client: ClientGrpc,
|
|
24
|
+
@Inject('{{ ../packageName }}_OPTIONS') private options: MicroserviceModuleOptionType
|
|
25
|
+
) {}
|
|
26
|
+
|
|
27
|
+
{{#each methods}}
|
|
28
|
+
{{{this}}}
|
|
29
|
+
{{/each}}
|
|
30
|
+
}
|
|
31
|
+
{{/if}}
|
|
32
|
+
{{/each}}
|
|
33
|
+
|
|
34
|
+
{{#each modelContent}}
|
|
35
|
+
export class {{ name }} {
|
|
36
|
+
{{#each properties}}
|
|
37
|
+
{{{this}}}
|
|
38
|
+
{{/each}}
|
|
39
|
+
}
|
|
40
|
+
{{/each}}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
{{#each enumContent}}
|
|
44
|
+
export enum {{ enumName }} {
|
|
45
|
+
{{#each keys}}
|
|
46
|
+
{{{this}}},
|
|
47
|
+
{{/each}}
|
|
48
|
+
}
|
|
49
|
+
{{/each}}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Import module
|
|
2
|
+
|
|
3
|
+
{{moduleName}}Module.register({
|
|
4
|
+
timeout: 5000,
|
|
5
|
+
url: 'localhost:50051'
|
|
6
|
+
})
|
|
7
|
+
|
|
8
|
+
// Use in service
|
|
9
|
+
export class ExampleService {
|
|
10
|
+
constructor(private {{packageName}}Microservice: {{moduleName}}Microservice) {
|
|
11
|
+
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
findOne() {
|
|
15
|
+
return this.{{packageName}}Microservice.findOne({ id: 1 });
|
|
16
|
+
}
|
|
17
|
+
}
|