@hodfords/nestjs-grpc-helper 11.4.0 → 11.5.0
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 +22 -0
- package/commands/generate-proto.command.d.ts +4 -0
- package/commands/generate-proto.command.js +33 -0
- package/commands/generate-proto.command.js.map +1 -0
- package/documents/microservice-document.module.js +3 -1
- package/documents/microservice-document.module.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,6 +22,8 @@ import { generateProtoService } from '@hodfords/nestjs-grpc-helper';
|
|
|
22
22
|
generateProtoService(camelCase(env.APP_NAME), env.ROOT_PATH + '/../');
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
+
Alternatively, generate it on demand with the `make:proto` command (see [Create proto file](#create-proto-file)).
|
|
26
|
+
|
|
25
27
|
## Usage 🚀
|
|
26
28
|
|
|
27
29
|
### Creating microservices
|
|
@@ -103,6 +105,26 @@ This command will:
|
|
|
103
105
|
2. **Generate proto file**: Automatically generates the necessary proto files based on the collected types.
|
|
104
106
|
3. **Create JavaScript Package**: Packages the generated code into a JavaScript SDK. The SDK will be published using the name and version specified in your package.json, making it available for other services to import and use. The arguments, response structure, and method names remain consistent with the definitions in your gRPC service, ensuring seamless integration and functionality across services.
|
|
105
107
|
|
|
108
|
+
### Create proto file
|
|
109
|
+
|
|
110
|
+
To generate only the proto file, without building the whole SDK, use the `make:proto` command. It reuses the same
|
|
111
|
+
`sdk-config.json` file as `make-sdk`: `name` is used as the proto package and `output` as the destination directory.
|
|
112
|
+
|
|
113
|
+
```shell
|
|
114
|
+
npm run wz-command make:proto
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Both arguments are optional:
|
|
118
|
+
|
|
119
|
+
```shell
|
|
120
|
+
npm run wz-command make:proto sdk-config.json ./proto
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
| Argument | Description |
|
|
124
|
+
|------------|------------------------------------------------------------------------|
|
|
125
|
+
| configFile | Config file to read. Defaults to `sdk-config.json` |
|
|
126
|
+
| outputPath | Directory the `microservice.proto` file is written into. Defaults to the `output` field of the config file |
|
|
127
|
+
|
|
106
128
|
### SDK usage
|
|
107
129
|
|
|
108
130
|
After publishing the SDK, other services can easily integrate it. Here’s an example of how to use the generated SDK
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.GenerateProtoCommand = void 0;
|
|
10
|
+
const nestjs_command_1 = require("@hodfords/nestjs-command");
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const generate_helper_1 = require("../helpers/generate.helper");
|
|
13
|
+
let GenerateProtoCommand = class GenerateProtoCommand extends nestjs_command_1.BaseCommand {
|
|
14
|
+
handle() {
|
|
15
|
+
let [configFile] = this.params;
|
|
16
|
+
const [, outputPath] = this.params;
|
|
17
|
+
if (!configFile) {
|
|
18
|
+
configFile = 'sdk-config.json';
|
|
19
|
+
}
|
|
20
|
+
const options = require(configFile);
|
|
21
|
+
(0, generate_helper_1.generateProtoService)(options.name, outputPath || options.output);
|
|
22
|
+
this.success(`Create proto file successfully!`);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
exports.GenerateProtoCommand = GenerateProtoCommand;
|
|
26
|
+
exports.GenerateProtoCommand = GenerateProtoCommand = __decorate([
|
|
27
|
+
(0, nestjs_command_1.Command)({
|
|
28
|
+
signature: 'make:proto [configFile] [outputPath]',
|
|
29
|
+
description: 'Make proto file'
|
|
30
|
+
}),
|
|
31
|
+
(0, common_1.Injectable)()
|
|
32
|
+
], GenerateProtoCommand);
|
|
33
|
+
//# sourceMappingURL=generate-proto.command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-proto.command.js","sourceRoot":"","sources":["../../../lib/commands/generate-proto.command.ts"],"names":[],"mappings":";;;;;;;;;AAAA,6DAAgE;AAChE,2CAA4C;AAC5C,gEAAmE;AAQ5D,IAAM,oBAAoB,GAA1B,MAAM,oBAAqB,SAAQ,4BAAW;IAC1C,MAAM;QACT,IAAI,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC;QAC/B,MAAM,CAAC,EAAE,UAAU,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC;QACnC,IAAI,CAAC,UAAU,EAAE,CAAC;YACd,UAAU,GAAG,iBAAiB,CAAC;QACnC,CAAC;QAED,MAAM,OAAO,GAAuB,OAAO,CAAC,UAAU,CAAC,CAAC;QACxD,IAAA,sCAAoB,EAAC,OAAO,CAAC,IAAI,EAAE,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;QACjE,IAAI,CAAC,OAAO,CAAC,iCAAiC,CAAC,CAAC;IACpD,CAAC;CACJ,CAAA;AAZY,oDAAoB;+BAApB,oBAAoB;IALhC,IAAA,wBAAO,EAAC;QACL,SAAS,EAAE,sCAAsC;QACjD,WAAW,EAAE,iBAAiB;KACjC,CAAC;IACD,IAAA,mBAAU,GAAE;GACA,oBAAoB,CAYhC"}
|
|
@@ -17,6 +17,7 @@ const microservices_1 = require("@nestjs/microservices");
|
|
|
17
17
|
const serve_static_1 = require("@nestjs/serve-static");
|
|
18
18
|
const path_1 = __importDefault(require("path"));
|
|
19
19
|
const generate_sdk_command_1 = require("../commands/generate-sdk.command");
|
|
20
|
+
const generate_proto_command_1 = require("../commands/generate-proto.command");
|
|
20
21
|
let MicroserviceDocumentModule = MicroserviceDocumentModule_1 = class MicroserviceDocumentModule {
|
|
21
22
|
static async register(options) {
|
|
22
23
|
if (!options.isEnable) {
|
|
@@ -37,7 +38,8 @@ let MicroserviceDocumentModule = MicroserviceDocumentModule_1 = class Microservi
|
|
|
37
38
|
provide: 'DOCUMENT_OPTIONS',
|
|
38
39
|
useValue: options
|
|
39
40
|
},
|
|
40
|
-
generate_sdk_command_1.GenerateSdkCommand
|
|
41
|
+
generate_sdk_command_1.GenerateSdkCommand,
|
|
42
|
+
generate_proto_command_1.GenerateProtoCommand
|
|
41
43
|
],
|
|
42
44
|
controllers: [microservice_document_controller_1.MicroserviceDocumentController],
|
|
43
45
|
imports: [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"microservice-document.module.js","sourceRoot":"","sources":["../../../lib/documents/microservice-document.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAuD;AACvD,yFAAoF;AAEpF,yDAAsD;AACtD,uDAAyD;AACzD,gDAAwB;AACxB,2EAAsE;
|
|
1
|
+
{"version":3,"file":"microservice-document.module.js","sourceRoot":"","sources":["../../../lib/documents/microservice-document.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAuD;AACvD,yFAAoF;AAEpF,yDAAsD;AACtD,uDAAyD;AACzD,gDAAwB;AACxB,2EAAsE;AACtE,+EAA0E;AAGnE,IAAM,0BAA0B,kCAAhC,MAAM,0BAA0B;IACnC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAiC;QACnD,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;YACpB,OAAO;gBACH,MAAM,EAAE,4BAA0B;aACrC,CAAC;QACN,CAAC;QAED,IAAI,SAAS,GAAG,yBAAyB,CAAC;QAC1C,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;YACjB,SAAS,GAAG,IAAI,OAAO,CAAC,MAAM,GAAG,S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