@hodfords/nestjs-grpc-helper 10.4.12 → 11.0.1
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 +3 -39
- package/clients/custom-grpc.client.d.ts +1 -0
- package/clients/custom-grpc.client.js +7 -0
- package/clients/custom-grpc.client.js.map +1 -1
- package/commands/generate-sdk.command.js +4 -8
- package/commands/generate-sdk.command.js.map +1 -1
- package/decorators/property.decorator.js +3 -0
- package/decorators/property.decorator.js.map +1 -1
- package/documents/microservice-document.module.js +1 -1
- package/documents/microservice-document.module.js.map +1 -1
- package/helpers/api-property.helper.d.ts +2 -2
- package/helpers/api-property.helper.js.map +1 -1
- package/helpers/generate.helper.d.ts +1 -2
- package/helpers/generate.helper.js +2 -2
- package/helpers/generate.helper.js.map +1 -1
- package/helpers/property.helper.d.ts +1 -1
- package/helpers/property.helper.js.map +1 -1
- package/helpers/proto-type.helper.d.ts +3 -3
- package/helpers/proto-type.helper.js +2 -2
- package/helpers/proto-type.helper.js.map +1 -1
- package/index.d.ts +0 -1
- package/index.js +0 -1
- package/index.js.map +1 -1
- package/package.json +32 -33
- package/services/generate-document.service.d.ts +2 -1
- package/services/generate-document.service.js +7 -20
- package/services/generate-document.service.js.map +1 -1
- package/services/generate-microservice.service.d.ts +22 -31
- package/services/generate-microservice.service.js +52 -105
- package/services/generate-microservice.service.js.map +1 -1
- package/services/generate-proto.service.d.ts +2 -1
- package/services/generate-proto.service.js +33 -32
- package/services/generate-proto.service.js.map +1 -1
- package/services/hbs-generator.service.d.ts +3 -0
- package/services/hbs-generator.service.js +48 -0
- package/services/hbs-generator.service.js.map +1 -0
- package/services/method-template.service.d.ts +3 -1
- package/services/method-template.service.js +13 -40
- package/services/method-template.service.js.map +1 -1
- package/services/mock-module-template.service.d.ts +2 -1
- package/services/mock-module-template.service.js +13 -22
- package/services/mock-module-template.service.js.map +1 -1
- package/services/module-template.service.d.ts +2 -1
- package/services/module-template.service.js +9 -46
- package/services/module-template.service.js.map +1 -1
- package/services/service-template.service.d.ts +14 -8
- package/services/service-template.service.js +24 -53
- package/services/service-template.service.js.map +1 -1
- package/templates/body-method-template.hbs +21 -0
- package/templates/grpc-service-template.hbs +5 -0
- package/templates/index-template.hbs +5 -0
- package/templates/method-template.hbs +9 -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-service-definition.hbs +6 -0
- package/templates/service-interface.hbs +7 -0
- package/templates/service-template.hbs +45 -0
- package/templates/usage-doc-template.hbs +17 -0
- package/types/property-option.type.d.ts +1 -0
- package/helpers/shell.helper.d.ts +0 -1
- package/helpers/shell.helper.js +0 -12
- package/helpers/shell.helper.js.map +0 -1
- package/types/sdk-build-config.type.d.ts +0 -11
- package/types/sdk-build-config.type.js +0 -3
- package/types/sdk-build-config.type.js.map +0 -1
|
@@ -2,58 +2,21 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ModuleTemplateService = void 0;
|
|
4
4
|
const lodash_1 = require("lodash");
|
|
5
|
-
|
|
5
|
+
const hbs_generator_service_1 = require("./hbs-generator.service");
|
|
6
|
+
class ModuleTemplateService extends hbs_generator_service_1.HbsGeneratorService {
|
|
6
7
|
constructor(packageName, fileName) {
|
|
8
|
+
super();
|
|
7
9
|
this.packageName = packageName;
|
|
8
10
|
this.fileName = fileName;
|
|
9
11
|
}
|
|
10
12
|
template(services) {
|
|
11
13
|
const moduleName = (0, lodash_1.upperFirst)((0, lodash_1.camelCase)(this.packageName));
|
|
12
|
-
return
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
import { CustomGrpcClient } from '@hodfords/nestjs-grpc-helper';
|
|
19
|
-
import * as grpc from '@grpc/grpc-js';
|
|
20
|
-
|
|
21
|
-
@Global()
|
|
22
|
-
@Module({})
|
|
23
|
-
export class ${moduleName}Module {
|
|
24
|
-
static register(options: MicroserviceModuleOptionType): DynamicModule {
|
|
25
|
-
return {
|
|
26
|
-
module: ${moduleName}Module,
|
|
27
|
-
providers: [
|
|
28
|
-
${services.join(',')},
|
|
29
|
-
{
|
|
30
|
-
provide: '${this.packageName}_OPTIONS',
|
|
31
|
-
useValue: options
|
|
32
|
-
}
|
|
33
|
-
],
|
|
34
|
-
exports: [${services.join(',')}],
|
|
35
|
-
imports: [
|
|
36
|
-
ClientsModule.register([
|
|
37
|
-
{
|
|
38
|
-
name: '${this.packageName}_PACKAGE',
|
|
39
|
-
customClass: CustomGrpcClient,
|
|
40
|
-
options: {
|
|
41
|
-
url: options.url,
|
|
42
|
-
package: '${this.packageName}',
|
|
43
|
-
protoPath: path.join(__dirname, 'microservice.proto'),
|
|
44
|
-
credentials: options.ssl ? grpc.credentials.createSsl() : undefined,
|
|
45
|
-
maxReceiveMessageLength: options.maxReceiveMessageLength ?? 4 * 1024 * 1024,
|
|
46
|
-
loader: {
|
|
47
|
-
arrays: options.shouldLoadEmptyArray ?? false
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
])
|
|
52
|
-
]
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
`;
|
|
14
|
+
return this.compileTemplate('module-template.hbs', {
|
|
15
|
+
moduleName,
|
|
16
|
+
services,
|
|
17
|
+
packageName: this.packageName,
|
|
18
|
+
fileName: this.fileName
|
|
19
|
+
});
|
|
57
20
|
}
|
|
58
21
|
}
|
|
59
22
|
exports.ModuleTemplateService = ModuleTemplateService;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module-template.service.js","sourceRoot":"","sources":["../../../lib/services/module-template.service.ts"],"names":[],"mappings":";;;AAAA,mCAA+C;
|
|
1
|
+
{"version":3,"file":"module-template.service.js","sourceRoot":"","sources":["../../../lib/services/module-template.service.ts"],"names":[],"mappings":";;;AAAA,mCAA+C;AAC/C,mEAA8D;AAE9D,MAAa,qBAAsB,SAAQ,2CAAmB;IAC1D,YACY,WAAmB,EACnB,QAAgB;QAExB,KAAK,EAAE,CAAC;QAHA,gBAAW,GAAX,WAAW,CAAQ;QACnB,aAAQ,GAAR,QAAQ,CAAQ;IAG5B,CAAC;IAED,QAAQ,CAAC,QAAkB;QACvB,MAAM,UAAU,GAAG,IAAA,mBAAU,EAAC,IAAA,kBAAS,EAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;QAC3D,OAAO,IAAI,CAAC,eAAe,CAAC,qBAAqB,EAAE;YAC/C,UAAU;YACV,QAAQ;YACR,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,QAAQ,EAAE,IAAI,CAAC,QAAQ;SAC1B,CAAC,CAAC;IACP,CAAC;CACJ;AAjBD,sDAiBC"}
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import { ApiPropertyOptions } from '@nestjs/swagger';
|
|
2
|
-
import {
|
|
3
|
-
export declare class ServiceTemplateService {
|
|
4
|
-
private
|
|
5
|
-
constructor(
|
|
6
|
-
templateServiceAndModel(serviceContent:
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
import { HbsGeneratorService } from './hbs-generator.service';
|
|
3
|
+
export declare class ServiceTemplateService extends HbsGeneratorService {
|
|
4
|
+
private packageName;
|
|
5
|
+
constructor(packageName: string);
|
|
6
|
+
templateServiceAndModel(serviceContent: any, modelContent: any, enumContent: any): string;
|
|
7
|
+
modelTemplate(name: string, properties: string[], parentClass: Function): {
|
|
8
|
+
name: string;
|
|
9
|
+
properties: string[];
|
|
10
|
+
extendClass: string;
|
|
11
|
+
};
|
|
12
|
+
enumTemplate(options: ApiPropertyOptions): {
|
|
13
|
+
enumName: string;
|
|
14
|
+
keys: string[];
|
|
15
|
+
};
|
|
10
16
|
propertyTemplate(property: any, type: string): string;
|
|
11
17
|
}
|
|
@@ -3,68 +3,36 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ServiceTemplateService = void 0;
|
|
4
4
|
const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
|
5
5
|
const api_property_helper_1 = require("../helpers/api-property.helper");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
const hbs_generator_service_1 = require("./hbs-generator.service");
|
|
7
|
+
class ServiceTemplateService extends hbs_generator_service_1.HbsGeneratorService {
|
|
8
|
+
constructor(packageName) {
|
|
9
|
+
super();
|
|
10
|
+
this.packageName = packageName;
|
|
9
11
|
}
|
|
10
12
|
templateServiceAndModel(serviceContent, modelContent, enumContent) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
${this.config.addAllowDecorator ? "import { Allow } from 'class-validator'" : ''};
|
|
18
|
-
import { Property, sample, AnyType } from '@hodfords/nestjs-grpc-helper';
|
|
19
|
-
|
|
20
|
-
${enumContent}
|
|
21
|
-
|
|
22
|
-
${modelContent}
|
|
23
|
-
|
|
24
|
-
${serviceContent}
|
|
25
|
-
`;
|
|
26
|
-
}
|
|
27
|
-
templateService(serviceName, method, isMock) {
|
|
28
|
-
if (isMock) {
|
|
29
|
-
return `
|
|
30
|
-
export class Mock${serviceName} {
|
|
31
|
-
${method.join('\n')}
|
|
32
|
-
}
|
|
33
|
-
`;
|
|
34
|
-
}
|
|
35
|
-
return `
|
|
36
|
-
@Injectable()
|
|
37
|
-
export class ${serviceName} {
|
|
38
|
-
constructor(
|
|
39
|
-
@Inject('${this.config.packageName}_PACKAGE') private client: ClientGrpc,
|
|
40
|
-
@Inject('${this.config.packageName}_OPTIONS') private options: MicroserviceModuleOptionType
|
|
41
|
-
) {}
|
|
42
|
-
${method.join('\n')}
|
|
43
|
-
}
|
|
44
|
-
`;
|
|
13
|
+
const data = {
|
|
14
|
+
enumContent,
|
|
15
|
+
modelContent,
|
|
16
|
+
serviceContent
|
|
17
|
+
};
|
|
18
|
+
return this.compileTemplate('./service-template.hbs', data);
|
|
45
19
|
}
|
|
46
20
|
modelTemplate(name, properties, parentClass) {
|
|
47
21
|
let extendClass = '';
|
|
48
22
|
if (parentClass.name) {
|
|
49
23
|
extendClass = `extends ${parentClass.name}`;
|
|
50
24
|
}
|
|
51
|
-
return
|
|
52
|
-
export class ${name} ${extendClass} {
|
|
53
|
-
${properties.join('\n')}
|
|
54
|
-
}
|
|
55
|
-
`;
|
|
25
|
+
return { name, properties, extendClass };
|
|
56
26
|
}
|
|
57
27
|
enumTemplate(options) {
|
|
58
28
|
const { enum: properties, enumName, type } = options;
|
|
59
29
|
const valueFormatter = (value) => (type === 'string' ? `'${value}'` : value);
|
|
60
|
-
return
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
`;
|
|
30
|
+
return {
|
|
31
|
+
enumName,
|
|
32
|
+
keys: Object.keys(properties)
|
|
33
|
+
.filter((key) => !parseInt(key))
|
|
34
|
+
.map((key) => `${key} = ${valueFormatter(properties[key])}`)
|
|
35
|
+
};
|
|
68
36
|
}
|
|
69
37
|
propertyTemplate(property, type) {
|
|
70
38
|
const isPrimitiveType = ['object', 'string', 'number', 'bool', 'boolean', 'any'].includes(type);
|
|
@@ -92,11 +60,14 @@ class ServiceTemplateService {
|
|
|
92
60
|
propertyOption = JSON.stringify({ ...options, type: type }).replaceAll(`"type":"${type}"`, `"type":${type}`);
|
|
93
61
|
}
|
|
94
62
|
}
|
|
95
|
-
|
|
63
|
+
let propertyDecorator = `
|
|
96
64
|
@Property(${propertyOption})
|
|
97
|
-
${this.config.addAllowDecorator ? `@Allow()` : ''}
|
|
98
|
-
${type === 'any' ? `@AnyType()` : ''}
|
|
99
65
|
`;
|
|
66
|
+
if (type === 'any') {
|
|
67
|
+
propertyDecorator += `
|
|
68
|
+
@AnyType()
|
|
69
|
+
`;
|
|
70
|
+
}
|
|
100
71
|
return `
|
|
101
72
|
${propertyDecorator}
|
|
102
73
|
${typeDecorator}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service-template.service.js","sourceRoot":"","sources":["../../../lib/services/service-template.service.ts"],"names":[],"mappings":";;;AACA,oEAA+D;AAE/D,wEAAgE;
|
|
1
|
+
{"version":3,"file":"service-template.service.js","sourceRoot":"","sources":["../../../lib/services/service-template.service.ts"],"names":[],"mappings":";;;AACA,oEAA+D;AAE/D,wEAAgE;AAEhE,mEAA8D;AAE9D,MAAa,sBAAuB,SAAQ,2CAAmB;IAC3D,YAAoB,WAAmB;QACnC,KAAK,EAAE,CAAC;QADQ,gBAAW,GAAX,WAAW,CAAQ;IAEvC,CAAC;IAED,uBAAuB,CAAC,cAAc,EAAE,YAAY,EAAE,WAAW;QAC7D,MAAM,IAAI,GAAG;YACT,WAAW;YACX,YAAY;YACZ,cAAc;SACjB,CAAC;QAEF,OAAO,IAAI,CAAC,eAAe,CAAC,wBAAwB,EAAE,IAAI,CAAC,CAAC;IAChE,CAAC;IAED,aAAa,CAAC,IAAY,EAAE,UAAoB,EAAE,WAAqB;QACnE,IAAI,WAAW,GAAG,EAAE,CAAC;QACrB,IAAI,WAAW,CAAC,IAAI,EAAE,CAAC;YACnB,WAAW,GAAG,WAAW,WAAW,CAAC,IAAI,EAAE,CAAC;QAChD,CAAC;QAED,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC;IAC7C,CAAC;IAED,YAAY,CAAC,OAA2B;QACpC,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,OAA6B,CAAC;QAC3E,MAAM,cAAc,GAAG,CAAC,KAAU,EAAE,EAAE,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QAElF,OAAO;YACH,QAAQ;YACR,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC;iBACxB,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;iBAC/B,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,GAAG,MAAM,cAAc,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;SACnE,CAAC;IACN,CAAC;IAED,gBAAgB,CAAC,QAAQ,EAAE,IAAY;QACnC,MAAM,eAAe,GAAG,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAChG,MAAM,UAAU,GAAG,IAAA,oCAAc,EAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QACnD,MAAM,YAAY,GAAG,CAAC,eAAe,IAAI,CAAC,UAAU,CAAC;QACrD,IAAI,YAAY,GAAG,EAAE,CAAC;QACtB,IAAI,YAAY,EAAE,CAAC;YACf,YAAY,GAAG,qBAAqB,IAAI,IAAI,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC;QACvF,CAAC;aAAM,CAAC;YACJ,YAAY,GAAG,GAAG,IAAI,IAAI,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;QACpE,CAAC;QAED,MAAM,YAAY,GAAG,GAAG,QAAQ,CAAC,IAAI,GAAG,QAAQ,CAAC,MAAM,CAAC,QAAQ,KAAK,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,YAAY,EAAE,CAAC;QACzG,IAAI,aAAa,GAAG,EAAE,CAAC;QACvB,IAAI,YAAY,EAAE,CAAC;YACf,aAAa,GAAG,eAAe,IAAI,GAAG,CAAC;QAC3C,CAAC;QAED,MAAM,OAAO,GAAG,EAAE,GAAG,QAAQ,CAAC,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,CAAC;QAE9D,IAAI,cAAc,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;QAC7C,IAAI,IAAA,yBAAU,EAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;YACnC,IAAI,YAAY,EAAE,CAAC;gBACf,cAAc,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,UAAU,CAClE,WAAW,IAAI,GAAG,EAClB,iBAAiB,IAAI,EAAE,CAC1B,CAAC;YACN,CAAC;iBAAM,CAAC;gBACJ,cAAc,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,UAAU,CAClE,WAAW,IAAI,GAAG,EAClB,UAAU,IAAI,EAAE,CACnB,CAAC;YACN,CAAC;QACL,CAAC;QAED,IAAI,iBAAiB,GAAG;wBACR,cAAc;SAC7B,CAAC;QACF,IAAI,IAAI,KAAK,KAAK,EAAE,CAAC;YACjB,iBAAiB,IAAI;;aAEpB,CAAC;QACN,CAAC;QAED,OAAO;UACL,iBAAiB;UACjB,aAAa;UACb,YAAY;SACb,CAAC;IACN,CAAC;CACJ;AArFD,wDAqFC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{{#if response}}
|
|
2
|
+
{{#if response.isArray}}
|
|
3
|
+
return await GrpcHelper.with(this.client, {{{response.responseClass.name}}}, this.options)
|
|
4
|
+
.service('{{{serviceName}}}')
|
|
5
|
+
.method('{{{method}}}')
|
|
6
|
+
.data({{#if parameterName}}param{{else}}{}{{/if}}{{#if parameterType}}, {{{parameterType}}}{{/if}})
|
|
7
|
+
.getMany();
|
|
8
|
+
{{else}}
|
|
9
|
+
return await GrpcHelper.with(this.client, {{{response.responseClass.name}}}, this.options)
|
|
10
|
+
.service('{{{serviceName}}}')
|
|
11
|
+
.method('{{{method}}}')
|
|
12
|
+
.data({{#if parameterName}}param{{else}}{}{{/if}}{{#if parameterType}}, {{{parameterType}}}{{/if}})
|
|
13
|
+
.getOne();
|
|
14
|
+
{{/if}}
|
|
15
|
+
{{else}}
|
|
16
|
+
await GrpcHelper.with(this.client, null as any, this.options)
|
|
17
|
+
.service('{{{serviceName}}}')
|
|
18
|
+
.method('{{{method}}}')
|
|
19
|
+
.data({{#if parameterName}}param{{else}}{}{{/if}}{{#if parameterType}}, {{{parameterType}}}{{/if}})
|
|
20
|
+
.getMany();
|
|
21
|
+
{{/if}}
|
|
@@ -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,
|
|
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,45 @@
|
|
|
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
|
+
import { Property, AnyType, sample } from '@hodfords/nestjs-grpc-helper';
|
|
7
|
+
|
|
8
|
+
{{#each serviceContent}}
|
|
9
|
+
{{#if isMock}}
|
|
10
|
+
export class Mock{{ serviceName }} {
|
|
11
|
+
{{#each methods}}
|
|
12
|
+
{{{this}}}
|
|
13
|
+
{{/each}}
|
|
14
|
+
}
|
|
15
|
+
{{else}}
|
|
16
|
+
@Injectable()
|
|
17
|
+
export class {{ serviceName }} {
|
|
18
|
+
constructor(
|
|
19
|
+
@Inject('{{ ../packageName }}_PACKAGE') private client: ClientGrpc,
|
|
20
|
+
@Inject('{{ ../packageName }}_OPTIONS') private options: MicroserviceModuleOptionType
|
|
21
|
+
) {}
|
|
22
|
+
|
|
23
|
+
{{#each methods}}
|
|
24
|
+
{{{this}}}
|
|
25
|
+
{{/each}}
|
|
26
|
+
}
|
|
27
|
+
{{/if}}
|
|
28
|
+
{{/each}}
|
|
29
|
+
|
|
30
|
+
{{#each modelContent}}
|
|
31
|
+
export class {{ name }} {
|
|
32
|
+
{{#each properties}}
|
|
33
|
+
{{{this}}}
|
|
34
|
+
{{/each}}
|
|
35
|
+
}
|
|
36
|
+
{{/each}}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
{{#each enumContent}}
|
|
40
|
+
export enum {{ enumName }} {
|
|
41
|
+
{{#each keys}}
|
|
42
|
+
{{{this}}},
|
|
43
|
+
{{/each}}
|
|
44
|
+
}
|
|
45
|
+
{{/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
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function runCommand(command: string, cwd?: string): any;
|
package/helpers/shell.helper.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.runCommand = runCommand;
|
|
4
|
-
const shelljs_1 = require("shelljs");
|
|
5
|
-
function runCommand(command, cwd = process.cwd()) {
|
|
6
|
-
const result = (0, shelljs_1.exec)(command, { silent: true, cwd: cwd });
|
|
7
|
-
if (result.code !== 0) {
|
|
8
|
-
throw new Error(result.stderr || result.stdout);
|
|
9
|
-
}
|
|
10
|
-
return result;
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=shell.helper.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"shell.helper.js","sourceRoot":"","sources":["../../../lib/helpers/shell.helper.ts"],"names":[],"mappings":";;AAEA,gCAMC;AARD,qCAA+B;AAE/B,SAAgB,UAAU,CAAC,OAAe,EAAE,MAAc,OAAO,CAAC,GAAG,EAAE;IACnE,MAAM,MAAM,GAAG,IAAA,cAAI,EAAC,OAAO,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC;IACzD,IAAI,MAAM,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,CAAC,CAAC;IACpD,CAAC;IACD,OAAO,MAAM,CAAC;AAClB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sdk-build-config.type.js","sourceRoot":"","sources":["../../../lib/types/sdk-build-config.type.ts"],"names":[],"mappings":""}
|