@rsdk/grpc.server 5.0.2-next.1 → 5.0.3-next.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/CHANGELOG.md +10 -0
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +2 -1
- package/dist/constants.js.map +1 -1
- package/dist/grpc.transport.d.ts +2 -1
- package/dist/grpc.transport.js +18 -1
- package/dist/grpc.transport.js.map +1 -1
- package/package.json +2 -2
- package/src/constants.ts +1 -0
- package/src/grpc.transport.ts +23 -3
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,16 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [5.0.3-next.0](https://github.com/R-Vision/rsdk/compare/v5.0.2...v5.0.3-next.0) (2024-07-23)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* default GRPC-address ([4273784](https://github.com/R-Vision/rsdk/commit/427378463286fda531e57b682d54914aeb34191f))
|
|
11
|
+
|
|
12
|
+
## [5.0.2](https://github.com/R-Vision/rsdk/compare/v5.0.2-next.1...v5.0.2) (2024-07-19)
|
|
13
|
+
|
|
14
|
+
**Note:** Version bump only for package @rsdk/grpc.server
|
|
15
|
+
|
|
6
16
|
## [5.0.2-next.1](https://github.com/R-Vision/rsdk/compare/v5.0.2-next.0...v5.0.2-next.1) (2024-07-19)
|
|
7
17
|
|
|
8
18
|
**Note:** Version bump only for package @rsdk/grpc.server
|
package/dist/constants.d.ts
CHANGED
package/dist/constants.js
CHANGED
|
@@ -3,12 +3,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.systemPackages = exports.GRPC_PROTOCOL = void 0;
|
|
6
|
+
exports.systemPackages = exports.DEFAULT_GRPC_HOST = exports.GRPC_PROTOCOL = void 0;
|
|
7
7
|
const grpc_health_v1_1 = __importDefault(require("@rsdk/builtin-contract/dist/grpc.health.v1"));
|
|
8
8
|
const grpc_metrics_v1_1 = __importDefault(require("@rsdk/builtin-contract/dist/grpc.metrics.v1"));
|
|
9
9
|
const grpc_reflection_v1_1 = __importDefault(require("@rsdk/builtin-contract/dist/grpc.reflection.v1"));
|
|
10
10
|
const grpc_reflection_v1alpha_1 = __importDefault(require("@rsdk/builtin-contract/dist/grpc.reflection.v1alpha"));
|
|
11
11
|
exports.GRPC_PROTOCOL = 'grpc';
|
|
12
|
+
exports.DEFAULT_GRPC_HOST = '0.0.0.0';
|
|
12
13
|
exports.systemPackages = [
|
|
13
14
|
grpc_health_v1_1.default,
|
|
14
15
|
grpc_metrics_v1_1.default,
|
package/dist/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;;;;AAAA,gGAA2E;AAC3E,kGAA6E;AAC7E,wGAAqF;AACrF,kHAA+F;AAGlF,QAAA,aAAa,GAAG,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;;;;AAAA,gGAA2E;AAC3E,kGAA6E;AAC7E,wGAAqF;AACrF,kHAA+F;AAGlF,QAAA,aAAa,GAAG,MAAM,CAAC;AACvB,QAAA,iBAAiB,GAAG,SAAS,CAAC;AAE9B,QAAA,cAAc,GAAc;IACvC,wBAAiB;IACjB,yBAAkB;IAClB,4BAAuB;IACvB,iCAA4B;CAC7B,CAAC"}
|
package/dist/grpc.transport.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Controller, ExecutionContext } from '@nestjs/common/interfaces';
|
|
2
2
|
import type { MicroserviceOptions } from '@nestjs/microservices';
|
|
3
|
-
import type
|
|
3
|
+
import { type Constructor } from '@rsdk/common';
|
|
4
4
|
import type { ConfigContext, GenericHeaders, IErrorsFormatter, IErrorsSender, IErrorsTransformer, IMicroserviceTransport, NestModuleDefinitions } from '@rsdk/core';
|
|
5
5
|
import type { Package } from '@rsdk/grpc.loader';
|
|
6
6
|
export declare class GrpcTransport implements IMicroserviceTransport {
|
|
@@ -27,6 +27,7 @@ export declare class GrpcTransport implements IMicroserviceTransport {
|
|
|
27
27
|
init(configContext: ConfigContext): void;
|
|
28
28
|
createMicroserviceOptions(): MicroserviceOptions;
|
|
29
29
|
onStart(): void;
|
|
30
|
+
private prepareGrpcAddress;
|
|
30
31
|
private checkIsInitialized;
|
|
31
32
|
/**
|
|
32
33
|
* Checks the value must be defined and not null
|
package/dist/grpc.transport.js
CHANGED
|
@@ -3,9 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.GrpcTransport = void 0;
|
|
4
4
|
const server_call_1 = require("@grpc/grpc-js/build/src/server-call");
|
|
5
5
|
const core_1 = require("@nestjs/core");
|
|
6
|
+
const common_1 = require("@rsdk/common");
|
|
6
7
|
const core_2 = require("@rsdk/core");
|
|
7
8
|
const grpc_loader_1 = require("@rsdk/grpc.loader");
|
|
8
9
|
const logging_1 = require("@rsdk/logging");
|
|
10
|
+
const node_net_1 = require("node:net");
|
|
9
11
|
const constants_1 = require("./constants");
|
|
10
12
|
const controllers_1 = require("./controllers");
|
|
11
13
|
const grpc_config_1 = require("./grpc.config");
|
|
@@ -77,7 +79,7 @@ class GrpcTransport {
|
|
|
77
79
|
*/
|
|
78
80
|
init(configContext) {
|
|
79
81
|
const { address, maxRecv, maxSend } = configContext.resolve(grpc_config_1.GRPCConfig);
|
|
80
|
-
this.address = address;
|
|
82
|
+
this.address = this.prepareGrpcAddress(address);
|
|
81
83
|
this.maxRecv = maxRecv;
|
|
82
84
|
this.maxSend = maxSend;
|
|
83
85
|
this.isInitialized = true;
|
|
@@ -103,6 +105,21 @@ class GrpcTransport {
|
|
|
103
105
|
this.checkIsInitialized();
|
|
104
106
|
this.logger.info(`Grpc server is listening on port ${this.address}`);
|
|
105
107
|
}
|
|
108
|
+
prepareGrpcAddress(address) {
|
|
109
|
+
/**
|
|
110
|
+
* NOTE: It's ok while we have /^([\w.-_]+):(\d{4,5})$/ as
|
|
111
|
+
* address pattern (see grpc-address.parser.ts). But this
|
|
112
|
+
* will not work with IPv6
|
|
113
|
+
*/
|
|
114
|
+
const [host, port] = address.split(':');
|
|
115
|
+
if ((0, node_net_1.isIPv4)(host)) {
|
|
116
|
+
return address;
|
|
117
|
+
}
|
|
118
|
+
this.logger.warn((0, common_1.text) `
|
|
119
|
+
${host} is not a valid IPv4 address.
|
|
120
|
+
Replacing with ${constants_1.DEFAULT_GRPC_HOST}...`);
|
|
121
|
+
return `${constants_1.DEFAULT_GRPC_HOST}:${port}`;
|
|
122
|
+
}
|
|
106
123
|
checkIsInitialized() {
|
|
107
124
|
if (!this.isInitialized) {
|
|
108
125
|
throw new core_2.SequenceException('You should call init() method first!');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grpc.transport.js","sourceRoot":"","sources":["../src/grpc.transport.ts"],"names":[],"mappings":";;;AAAA,qEAK6C;AAE7C,uCAA+C;
|
|
1
|
+
{"version":3,"file":"grpc.transport.js","sourceRoot":"","sources":["../src/grpc.transport.ts"],"names":[],"mappings":";;;AAAA,qEAK6C;AAE7C,uCAA+C;AAE/C,yCAAsD;AAUtD,qCAA+C;AAE/C,mDAAsD;AACtD,2CAA8C;AAC9C,uCAAkC;AAElC,2CAA+E;AAC/E,+CAAoE;AACpE,+CAA2C;AAC3C,iDAA6C;AAC7C,6CAAoD;AACpD,mEAA8D;AAC9D,6DAAwD;AACxD,uEAAkE;AAClE,2DAAuD;AAEvD,MAAa,aAAa;IACP,MAAM,GAAG,uBAAa,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;IAC7C,QAAQ,CAAe;IAEhC,OA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,IAAI,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAExC,IAAI,IAAA,iBAAM,EAAC,IAAI,CAAC,EAAE,CAAC;YACjB,OAAO,OAAO,CAAC;QACjB,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAA,aAAI,EAAA;QACjB,IAAI;uBACW,6BAAiB,KAAK,CAAC,CAAC;QAE3C,OAAO,GAAG,6BAAiB,IAAI,IAAI,EAAE,CAAC;IACxC,CAAC;IAEO,kBAAkB;QACxB,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;YACxB,MAAM,IAAI,wBAAiB,CAAC,sCAAsC,CAAC,CAAC;QACtE,CAAC;IACH,CAAC;IAED;;;OAGG;IACK,eAAe,CAAI,KAAQ;QACjC,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YAC1C,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,iBAAiB,CAAC,CAAC;QAC7C,CAAC;IACH,CAAC;IAED;;;OAGG;IACK,iBAAiB;QACvB,MAAM,QAAQ,GAAG,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC;QAEpC,KAAK,MAAM,GAAG,IAAI,0BAAc,EAAE,CAAC;YACjC,IAAI,IAAA,iCAAoB,EAAC,QAAQ,EAAE,GAAG,CAAC,EAAE,CAAC;gBACxC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACrB,CAAC;QACH,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF;AAjKD,sCAiKC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsdk/grpc.server",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.3-next.0",
|
|
4
4
|
"description": "Grpc transport for platform, clients and common grpc stuff",
|
|
5
5
|
"license": "Apache License 2.0",
|
|
6
6
|
"publishConfig": {
|
|
@@ -28,5 +28,5 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@bufbuild/protobuf": "^1.4.2"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "59c3a86e96c4c12daa6a74fd481d21cb76380c16"
|
|
32
32
|
}
|
package/src/constants.ts
CHANGED
|
@@ -5,6 +5,7 @@ import ReflectionGrpcPackageV1alpha from '@rsdk/builtin-contract/dist/grpc.refle
|
|
|
5
5
|
import type { Package } from '@rsdk/grpc.loader';
|
|
6
6
|
|
|
7
7
|
export const GRPC_PROTOCOL = 'grpc';
|
|
8
|
+
export const DEFAULT_GRPC_HOST = '0.0.0.0';
|
|
8
9
|
|
|
9
10
|
export const systemPackages: Package[] = [
|
|
10
11
|
HealthGrpcPackage,
|
package/src/grpc.transport.ts
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
import type { Controller, ExecutionContext } from '@nestjs/common/interfaces';
|
|
8
8
|
import { APP_INTERCEPTOR } from '@nestjs/core';
|
|
9
9
|
import type { MicroserviceOptions } from '@nestjs/microservices';
|
|
10
|
-
import type
|
|
10
|
+
import { type Constructor, text } from '@rsdk/common';
|
|
11
11
|
import type {
|
|
12
12
|
ConfigContext,
|
|
13
13
|
GenericHeaders,
|
|
@@ -21,8 +21,9 @@ import { SequenceException } from '@rsdk/core';
|
|
|
21
21
|
import type { Package } from '@rsdk/grpc.loader';
|
|
22
22
|
import { createGrpcOptions } from '@rsdk/grpc.loader';
|
|
23
23
|
import { LoggerFactory } from '@rsdk/logging';
|
|
24
|
+
import { isIPv4 } from 'node:net';
|
|
24
25
|
|
|
25
|
-
import { GRPC_PROTOCOL, systemPackages } from './constants';
|
|
26
|
+
import { DEFAULT_GRPC_HOST, GRPC_PROTOCOL, systemPackages } from './constants';
|
|
26
27
|
import { HealthController, MetricsController } from './controllers';
|
|
27
28
|
import { GRPCConfig } from './grpc.config';
|
|
28
29
|
import { GrpcHeaders } from './grpc.headers';
|
|
@@ -110,7 +111,7 @@ export class GrpcTransport implements IMicroserviceTransport {
|
|
|
110
111
|
init(configContext: ConfigContext): void {
|
|
111
112
|
const { address, maxRecv, maxSend } = configContext.resolve(GRPCConfig);
|
|
112
113
|
|
|
113
|
-
this.address = address;
|
|
114
|
+
this.address = this.prepareGrpcAddress(address);
|
|
114
115
|
this.maxRecv = maxRecv;
|
|
115
116
|
this.maxSend = maxSend;
|
|
116
117
|
this.isInitialized = true;
|
|
@@ -143,6 +144,25 @@ export class GrpcTransport implements IMicroserviceTransport {
|
|
|
143
144
|
this.logger.info(`Grpc server is listening on port ${this.address}`);
|
|
144
145
|
}
|
|
145
146
|
|
|
147
|
+
private prepareGrpcAddress(address: string): string {
|
|
148
|
+
/**
|
|
149
|
+
* NOTE: It's ok while we have /^([\w.-_]+):(\d{4,5})$/ as
|
|
150
|
+
* address pattern (see grpc-address.parser.ts). But this
|
|
151
|
+
* will not work with IPv6
|
|
152
|
+
*/
|
|
153
|
+
const [host, port] = address.split(':');
|
|
154
|
+
|
|
155
|
+
if (isIPv4(host)) {
|
|
156
|
+
return address;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
this.logger.warn(text`
|
|
160
|
+
${host} is not a valid IPv4 address.
|
|
161
|
+
Replacing with ${DEFAULT_GRPC_HOST}...`);
|
|
162
|
+
|
|
163
|
+
return `${DEFAULT_GRPC_HOST}:${port}`;
|
|
164
|
+
}
|
|
165
|
+
|
|
146
166
|
private checkIsInitialized(): void {
|
|
147
167
|
if (!this.isInitialized) {
|
|
148
168
|
throw new SequenceException('You should call init() method first!');
|