@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.
Files changed (66) hide show
  1. package/README.md +3 -39
  2. package/clients/custom-grpc.client.d.ts +1 -0
  3. package/clients/custom-grpc.client.js +7 -0
  4. package/clients/custom-grpc.client.js.map +1 -1
  5. package/commands/generate-sdk.command.js +4 -8
  6. package/commands/generate-sdk.command.js.map +1 -1
  7. package/decorators/property.decorator.js +3 -0
  8. package/decorators/property.decorator.js.map +1 -1
  9. package/documents/microservice-document.module.js +1 -1
  10. package/documents/microservice-document.module.js.map +1 -1
  11. package/helpers/api-property.helper.d.ts +2 -2
  12. package/helpers/api-property.helper.js.map +1 -1
  13. package/helpers/generate.helper.d.ts +1 -2
  14. package/helpers/generate.helper.js +2 -2
  15. package/helpers/generate.helper.js.map +1 -1
  16. package/helpers/property.helper.d.ts +1 -1
  17. package/helpers/property.helper.js.map +1 -1
  18. package/helpers/proto-type.helper.d.ts +3 -3
  19. package/helpers/proto-type.helper.js +2 -2
  20. package/helpers/proto-type.helper.js.map +1 -1
  21. package/index.d.ts +0 -1
  22. package/index.js +0 -1
  23. package/index.js.map +1 -1
  24. package/package.json +32 -33
  25. package/services/generate-document.service.d.ts +2 -1
  26. package/services/generate-document.service.js +7 -20
  27. package/services/generate-document.service.js.map +1 -1
  28. package/services/generate-microservice.service.d.ts +22 -31
  29. package/services/generate-microservice.service.js +52 -105
  30. package/services/generate-microservice.service.js.map +1 -1
  31. package/services/generate-proto.service.d.ts +2 -1
  32. package/services/generate-proto.service.js +33 -32
  33. package/services/generate-proto.service.js.map +1 -1
  34. package/services/hbs-generator.service.d.ts +3 -0
  35. package/services/hbs-generator.service.js +48 -0
  36. package/services/hbs-generator.service.js.map +1 -0
  37. package/services/method-template.service.d.ts +3 -1
  38. package/services/method-template.service.js +13 -40
  39. package/services/method-template.service.js.map +1 -1
  40. package/services/mock-module-template.service.d.ts +2 -1
  41. package/services/mock-module-template.service.js +13 -22
  42. package/services/mock-module-template.service.js.map +1 -1
  43. package/services/module-template.service.d.ts +2 -1
  44. package/services/module-template.service.js +9 -46
  45. package/services/module-template.service.js.map +1 -1
  46. package/services/service-template.service.d.ts +14 -8
  47. package/services/service-template.service.js +24 -53
  48. package/services/service-template.service.js.map +1 -1
  49. package/templates/body-method-template.hbs +21 -0
  50. package/templates/grpc-service-template.hbs +5 -0
  51. package/templates/index-template.hbs +5 -0
  52. package/templates/method-template.hbs +9 -0
  53. package/templates/mock-module-template.hbs +12 -0
  54. package/templates/mock-providers-template.hbs +6 -0
  55. package/templates/module-template.hbs +44 -0
  56. package/templates/proto-service-definition.hbs +6 -0
  57. package/templates/service-interface.hbs +7 -0
  58. package/templates/service-template.hbs +45 -0
  59. package/templates/usage-doc-template.hbs +17 -0
  60. package/types/property-option.type.d.ts +1 -0
  61. package/helpers/shell.helper.d.ts +0 -1
  62. package/helpers/shell.helper.js +0 -12
  63. package/helpers/shell.helper.js.map +0 -1
  64. package/types/sdk-build-config.type.d.ts +0 -11
  65. package/types/sdk-build-config.type.js +0 -3
  66. 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
- class ModuleTemplateService {
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
- import { DynamicModule, Module, Global } from '@nestjs/common';
14
- import { ClientsModule } from '@nestjs/microservices';
15
- import path from 'path';
16
- import { MicroserviceModuleOptionType } from './types/microservice-option.type';
17
- import { ${services.join(',')} } from './services/${this.fileName}.service';
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;AAE/C,MAAa,qBAAqB;IAC9B,YACY,WAAmB,EACnB,QAAgB;QADhB,gBAAW,GAAX,WAAW,CAAQ;QACnB,aAAQ,GAAR,QAAQ,CAAQ;IACzB,CAAC;IAEJ,QAAQ,CAAC,QAAkB;QACvB,MAAM,UAAU,GAAG,IAAA,mBAAU,EAAC,IAAA,kBAAS,EAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;QAC3D,OAAO;;;;;mBAKI,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,uBAAuB,IAAI,CAAC,QAAQ;;;;;;uBAMlD,UAAU;;;8BAGH,UAAU;;0BAEd,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC;;wCAEJ,IAAI,CAAC,WAAW;;;;gCAIxB,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC;;;;yCAIT,IAAI,CAAC,WAAW;;;;gDAIT,IAAI,CAAC,WAAW;;;;;;;;;;;;;;SAcvD,CAAC;IACN,CAAC;CACJ;AAtDD,sDAsDC"}
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 { SdkBuildConfigType } from '@hodfords/nestjs-grpc-helper';
3
- export declare class ServiceTemplateService {
4
- private config;
5
- constructor(config: SdkBuildConfigType);
6
- templateServiceAndModel(serviceContent: string, modelContent: string, enumContent: string): string;
7
- templateService(serviceName: string, method: string[], isMock: boolean): string;
8
- modelTemplate(name: string, properties: string[], parentClass: Function): string;
9
- enumTemplate(options: ApiPropertyOptions): string;
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
- class ServiceTemplateService {
7
- constructor(config) {
8
- this.config = config;
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
- return `
12
- import { GrpcHelper } from '../helpers/grpc.helper';
13
- import { Inject, Injectable } from '@nestjs/common';
14
- import { ClientGrpc } from '@nestjs/microservices';
15
- import { MicroserviceModuleOptionType } from '../types/microservice-option.type';
16
- import { Type } from 'class-transformer';
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
- export enum ${enumName} {
62
- ${Object.keys(properties)
63
- .filter((key) => !parseInt(key))
64
- .map((key) => `${key} = ${valueFormatter(properties[key])}`)
65
- .join(',\n')}
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
- const propertyDecorator = `
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;A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,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,MAAM,iBAAiB,GAAG;wBACV,cAAc;cACxB,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE;cAC/C,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE;SACvC,CAAC;QAEF,OAAO;UACL,iBAAiB;UACjB,aAAa;UACb,YAAY;SACb,CAAC;IACN,CAAC;CACJ;AAhHD,wDAgHC"}
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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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,5 @@
1
+ service {{name}} {
2
+ {{#each rpcMethods}}
3
+ {{this}}
4
+ {{/each}}
5
+ }
@@ -0,0 +1,5 @@
1
+ export * from './helpers/grpc.helper'
2
+ export * from './{{{ fileName }}}.module'
3
+ export * from './/{{{ fileName }}}.mock.module'
4
+ export * from './services/{{{ fileName }}}.service';
5
+ export * from './types/microservice-option.type';
@@ -0,0 +1,9 @@
1
+ {{#if params}}
2
+ async {{method}}(param: {{params}}): Promise<{{returnType}}> {
3
+ {{{body}}}
4
+ }
5
+ {{else}}
6
+ async {{method}}(): Promise<{{returnType}}> {
7
+ {{{body}}}
8
+ }
9
+ {{/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,6 @@
1
+ {{#each services}}
2
+ {
3
+ provide: {{this}},
4
+ useClass: Mock{{this}}
5
+ }{{#unless @last}},{{/unless}}
6
+ {{/each}}
@@ -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,6 @@
1
+ syntax = "proto3";
2
+ import "google/protobuf/empty.proto";
3
+ package {{packageName}};
4
+
5
+ {{{ microserviceContent}}}
6
+ {{{ modelContent }}}
@@ -0,0 +1,7 @@
1
+ message {{{name}}} {
2
+ {{{propertyContent}}}
3
+ }
4
+ message Proto{{{name}}}List {
5
+ repeated {{{name}}} items = 1;
6
+ bool grpcArray = 2;
7
+ }
@@ -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
+ }
@@ -11,5 +11,6 @@ export type PropertyOptionType = {
11
11
  description?: string;
12
12
  default?: any;
13
13
  mock?: MockOptionType;
14
+ enumName?: string;
14
15
  isAutoGenerated?: boolean;
15
16
  } & ApiPropertyOptions;
@@ -1 +0,0 @@
1
- export declare function runCommand(command: string, cwd?: string): any;
@@ -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,11 +0,0 @@
1
- export type SdkBuildConfigType = {
2
- name: string;
3
- packageName: string;
4
- format?: boolean;
5
- build?: boolean;
6
- addAllowDecorator?: boolean;
7
- output: string;
8
- outputBuild?: string;
9
- removeOutput?: boolean;
10
- tsconfig?: any;
11
- };
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=sdk-build-config.type.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sdk-build-config.type.js","sourceRoot":"","sources":["../../../lib/types/sdk-build-config.type.ts"],"names":[],"mappings":""}