@rsdk/grpc.clients 2.6.0-next.1 → 2.6.0-next.11
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 +36 -0
- package/dist/decorators/inject-client-factory.decorator.js +7 -3
- package/dist/decorators/inject-client-factory.decorator.js.map +1 -1
- package/dist/decorators/inject-client.decorator.js +1 -1
- package/dist/decorators/inject-client.decorator.js.map +1 -1
- package/dist/metadata/constants.d.ts +1 -0
- package/dist/metadata/constants.js +2 -1
- package/dist/metadata/constants.js.map +1 -1
- package/dist/metadata/grpc-clients-factory.autodoc-resolver.d.ts +8 -0
- package/dist/metadata/grpc-clients-factory.autodoc-resolver.js +19 -0
- package/dist/metadata/grpc-clients-factory.autodoc-resolver.js.map +1 -0
- package/dist/module.generator.d.ts +2 -1
- package/dist/module.generator.js +28 -1
- package/dist/module.generator.js.map +1 -1
- package/dist/repository/grpc-client.repository.d.ts +0 -3
- package/dist/repository/grpc-client.repository.js +0 -5
- package/dist/repository/grpc-client.repository.js.map +1 -1
- package/dist/servers/types.d.ts +3 -0
- package/package.json +8 -8
- package/src/decorators/inject-client-factory.decorator.ts +13 -4
- package/src/decorators/inject-client.decorator.ts +1 -1
- package/src/metadata/constants.ts +1 -0
- package/src/metadata/grpc-clients-factory.autodoc-resolver.ts +31 -0
- package/src/module.generator.ts +61 -4
- package/src/repository/grpc-client.repository.ts +0 -7
- package/src/servers/types.ts +4 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,42 @@
|
|
|
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
|
+
# [2.6.0-next.11](https://github.com/R-Vision/rsdk/compare/v2.6.0-next.10...v2.6.0-next.11) (2023-07-26)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @rsdk/grpc.clients
|
|
9
|
+
|
|
10
|
+
# [2.6.0-next.10](https://github.com/R-Vision/rsdk/compare/v2.6.0-next.9...v2.6.0-next.10) (2023-07-25)
|
|
11
|
+
|
|
12
|
+
**Note:** Version bump only for package @rsdk/grpc.clients
|
|
13
|
+
|
|
14
|
+
# [2.6.0-next.9](https://github.com/R-Vision/rsdk/compare/v2.6.0-next.8...v2.6.0-next.9) (2023-07-25)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @rsdk/grpc.clients
|
|
17
|
+
|
|
18
|
+
# [2.6.0-next.8](https://github.com/R-Vision/rsdk/compare/v2.6.0-next.7...v2.6.0-next.8) (2023-07-23)
|
|
19
|
+
|
|
20
|
+
**Note:** Version bump only for package @rsdk/grpc.clients
|
|
21
|
+
|
|
22
|
+
# [2.6.0-next.7](https://github.com/R-Vision/rsdk/compare/v2.6.0-next.6...v2.6.0-next.7) (2023-07-23)
|
|
23
|
+
|
|
24
|
+
**Note:** Version bump only for package @rsdk/grpc.clients
|
|
25
|
+
|
|
26
|
+
# [2.6.0-next.6](https://github.com/R-Vision/rsdk/compare/v2.6.0-next.5...v2.6.0-next.6) (2023-07-22)
|
|
27
|
+
|
|
28
|
+
**Note:** Version bump only for package @rsdk/grpc.clients
|
|
29
|
+
|
|
30
|
+
# [2.6.0-next.5](https://github.com/R-Vision/rsdk/compare/v2.6.0-next.4...v2.6.0-next.5) (2023-07-22)
|
|
31
|
+
|
|
32
|
+
### Bug Fixes
|
|
33
|
+
|
|
34
|
+
* remove unused properties ([ccbeba0](https://github.com/R-Vision/rsdk/commit/ccbeba0751bc35a47101723661bc94688c35ed57))
|
|
35
|
+
|
|
36
|
+
# [2.6.0-next.3](https://github.com/R-Vision/rsdk/compare/v2.6.0-next.2...v2.6.0-next.3) (2023-07-07)
|
|
37
|
+
|
|
38
|
+
### Features
|
|
39
|
+
|
|
40
|
+
* **grpc-clients:** added support grpc client factory ([#78](https://github.com/R-Vision/rsdk/issues/78)) ([4f9d761](https://github.com/R-Vision/rsdk/commit/4f9d761516abfa0264ee4c707fdd784f7ad9fd0c))
|
|
41
|
+
|
|
6
42
|
# [2.6.0-next.1](https://github.com/R-Vision/rsdk/compare/v2.6.0-next.0...v2.6.0-next.1) (2023-07-04)
|
|
7
43
|
|
|
8
44
|
### Bug Fixes
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.InjectGrpcClientsFactory = void 0;
|
|
4
4
|
const common_1 = require("@nestjs/common");
|
|
5
|
+
const constants_1 = require("@rsdk/core/dist/rsdk-metadata/constants");
|
|
6
|
+
const metadata_1 = require("@rsdk/metadata");
|
|
7
|
+
const module_generator_1 = require("../module.generator");
|
|
5
8
|
const token_factories_1 = require("../token.factories");
|
|
6
9
|
/**
|
|
7
10
|
* Injects factory of grpc clients for specific grpc-service. Main
|
|
@@ -11,9 +14,10 @@ const token_factories_1 = require("../token.factories");
|
|
|
11
14
|
* @returns ParameterDecorator
|
|
12
15
|
*/
|
|
13
16
|
const InjectGrpcClientsFactory = (definition) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
return (target, propertyKey, parameterIndex) => {
|
|
18
|
+
(0, common_1.Inject)((0, token_factories_1.getFactoryToken)(definition))(target, propertyKey, parameterIndex);
|
|
19
|
+
metadata_1.RsdkMetadata.setWithScope(target, constants_1.PLATFORM_RAW_GLOBAL_METADATA_SCOPE, definition.fullName, module_generator_1.ModuleGenerator.createClientFactoryModuleDefinition(definition), true);
|
|
20
|
+
};
|
|
17
21
|
};
|
|
18
22
|
exports.InjectGrpcClientsFactory = InjectGrpcClientsFactory;
|
|
19
23
|
//# sourceMappingURL=inject-client-factory.decorator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inject-client-factory.decorator.js","sourceRoot":"","sources":["../../src/decorators/inject-client-factory.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAAwC;
|
|
1
|
+
{"version":3,"file":"inject-client-factory.decorator.js","sourceRoot":"","sources":["../../src/decorators/inject-client-factory.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAAwC;AACxC,uEAA6F;AAC7F,6CAA8C;AAG9C,0DAAsD;AACtD,wDAAqD;AAWrD;;;;;;GAMG;AACI,MAAM,wBAAwB,GAAG,CACtC,UAAmC,EACf,EAAE;IACtB,OAAO,CAAC,MAAM,EAAE,WAAW,EAAE,cAAc,EAAE,EAAE;QAC7C,IAAA,eAAM,EAAC,IAAA,iCAAe,EAAC,UAAU,CAAC,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,cAAc,CAAC,CAAC;QACzE,uBAAY,CAAC,YAAY,CACvB,MAAM,EACN,8CAAkC,EAClC,UAAU,CAAC,QAAQ,EACnB,kCAAe,CAAC,mCAAmC,CAAC,UAAU,CAAC,EAC/D,IAAI,CACL,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC,CAAC;AAbW,QAAA,wBAAwB,4BAanC"}
|
|
@@ -17,7 +17,7 @@ const token_factories_1 = require("../token.factories");
|
|
|
17
17
|
const InjectGrpcClient = (grpcServerDeclarationValue) => {
|
|
18
18
|
return (target, propertyKey, parameterIndex) => {
|
|
19
19
|
(0, common_1.Inject)((0, token_factories_1.getClientToken)(grpcServerDeclarationValue.definition))(target, propertyKey, parameterIndex);
|
|
20
|
-
metadata_1.RsdkMetadata.setWithScope(target, constants_1.PLATFORM_RAW_GLOBAL_METADATA_SCOPE, `${grpcServerDeclarationValue.serverName}.${grpcServerDeclarationValue.serviceName}`, module_generator_1.ModuleGenerator.
|
|
20
|
+
metadata_1.RsdkMetadata.setWithScope(target, constants_1.PLATFORM_RAW_GLOBAL_METADATA_SCOPE, `${grpcServerDeclarationValue.serverName}.${grpcServerDeclarationValue.serviceName}`, module_generator_1.ModuleGenerator.createClientModuleDefinition(grpcServerDeclarationValue.serverName, grpcServerDeclarationValue.definition), true);
|
|
21
21
|
};
|
|
22
22
|
};
|
|
23
23
|
exports.InjectGrpcClient = InjectGrpcClient;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inject-client.decorator.js","sourceRoot":"","sources":["../../src/decorators/inject-client.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAAwC;AACxC,uEAA6F;AAC7F,6CAA8C;AAE9C,0DAAsD;AAEtD,wDAAoD;AAEpD;;;;;;;GAOG;AACI,MAAM,gBAAgB,GAAG,CAI9B,0BAGC,EACmB,EAAE;IACtB,OAAO,CAAC,MAAM,EAAE,WAAW,EAAE,cAAc,EAAE,EAAE;QAC7C,IAAA,eAAM,EAAC,IAAA,gCAAc,EAAC,0BAA0B,CAAC,UAAU,CAAC,CAAC,CAC3D,MAAM,EACN,WAAW,EACX,cAAc,CACf,CAAC;QACF,uBAAY,CAAC,YAAY,CACvB,MAAM,EACN,8CAAkC,EAClC,GAAG,0BAA0B,CAAC,UAAU,IAAI,0BAA0B,CAAC,WAAW,EAAE,EACpF,kCAAe,CAAC,
|
|
1
|
+
{"version":3,"file":"inject-client.decorator.js","sourceRoot":"","sources":["../../src/decorators/inject-client.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAAwC;AACxC,uEAA6F;AAC7F,6CAA8C;AAE9C,0DAAsD;AAEtD,wDAAoD;AAEpD;;;;;;;GAOG;AACI,MAAM,gBAAgB,GAAG,CAI9B,0BAGC,EACmB,EAAE;IACtB,OAAO,CAAC,MAAM,EAAE,WAAW,EAAE,cAAc,EAAE,EAAE;QAC7C,IAAA,eAAM,EAAC,IAAA,gCAAc,EAAC,0BAA0B,CAAC,UAAU,CAAC,CAAC,CAC3D,MAAM,EACN,WAAW,EACX,cAAc,CACf,CAAC;QACF,uBAAY,CAAC,YAAY,CACvB,MAAM,EACN,8CAAkC,EAClC,GAAG,0BAA0B,CAAC,UAAU,IAAI,0BAA0B,CAAC,WAAW,EAAE,EACpF,kCAAe,CAAC,4BAA4B,CAC1C,0BAA0B,CAAC,UAAU,EACrC,0BAA0B,CAAC,UAAU,CACtC,EACD,IAAI,CACL,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC,CAAC;AA1BW,QAAA,gBAAgB,oBA0B3B"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GRPC_CLIENTS_RSDK_METADATA_SCOPE = void 0;
|
|
3
|
+
exports.GRPC_CLIENTS_FACTORY_RSDK_METADATA_SCOPE = exports.GRPC_CLIENTS_RSDK_METADATA_SCOPE = void 0;
|
|
4
4
|
exports.GRPC_CLIENTS_RSDK_METADATA_SCOPE = 'grpc-clients';
|
|
5
|
+
exports.GRPC_CLIENTS_FACTORY_RSDK_METADATA_SCOPE = 'grpc-clients-factory';
|
|
5
6
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/metadata/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,gCAAgC,GAAG,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/metadata/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,gCAAgC,GAAG,cAAc,CAAC;AAClD,QAAA,wCAAwC,GAAG,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { DocumentNode, DocumentResolver } from '@rsdk/autodoc.protocol';
|
|
2
|
+
import type { RsdkMetadataProvider } from '@rsdk/metadata';
|
|
3
|
+
import type { Promisable } from 'type-fest';
|
|
4
|
+
declare class GrpcClientsFactoryAutodocResolver implements DocumentResolver {
|
|
5
|
+
getNode(rsdkMetadata: RsdkMetadataProvider): Promisable<DocumentNode | null>;
|
|
6
|
+
}
|
|
7
|
+
export declare const grpcClientsFactoryAutodocResolver: GrpcClientsFactoryAutodocResolver;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.grpcClientsFactoryAutodocResolver = void 0;
|
|
4
|
+
const autodoc_protocol_1 = require("@rsdk/autodoc.protocol");
|
|
5
|
+
const constants_1 = require("./constants");
|
|
6
|
+
class GrpcClientsFactoryAutodocResolver {
|
|
7
|
+
getNode(rsdkMetadata) {
|
|
8
|
+
const resources = rsdkMetadata.get(constants_1.GRPC_CLIENTS_FACTORY_RSDK_METADATA_SCOPE);
|
|
9
|
+
if (!resources) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
return new autodoc_protocol_1.Composite(new autodoc_protocol_1.Table(resources.map(({ value: { definition } }) => ({
|
|
13
|
+
name: definition.name.toString(),
|
|
14
|
+
fullName: definition.fullName.toString(),
|
|
15
|
+
}))), 'Grpc clients factory');
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.grpcClientsFactoryAutodocResolver = new GrpcClientsFactoryAutodocResolver();
|
|
19
|
+
//# sourceMappingURL=grpc-clients-factory.autodoc-resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grpc-clients-factory.autodoc-resolver.js","sourceRoot":"","sources":["../../src/metadata/grpc-clients-factory.autodoc-resolver.ts"],"names":[],"mappings":";;;AACA,6DAA0D;AAM1D,2CAAuE;AAEvE,MAAM,iCAAiC;IACrC,OAAO,CAAC,YAAkC;QACxC,MAAM,SAAS,GAAG,YAAY,CAAC,GAAG,CAChC,oDAAwC,CACzC,CAAC;QACF,IAAI,CAAC,SAAS,EAAE;YACd,OAAO,IAAI,CAAC;SACb;QACD,OAAO,IAAI,4BAAS,CAClB,IAAI,wBAAK,CACP,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;YAC5C,IAAI,EAAE,UAAU,CAAC,IAAI,CAAC,QAAQ,EAAE;YAChC,QAAQ,EAAE,UAAU,CAAC,QAAQ,CAAC,QAAQ,EAAE;SACzC,CAAC,CAAC,CACJ,EACD,sBAAsB,CACvB,CAAC;IACJ,CAAC;CACF;AAEY,QAAA,iCAAiC,GAC5C,IAAI,iCAAiC,EAAE,CAAC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { DynamicModule } from '@nestjs/common';
|
|
2
2
|
import type { CompatServiceDefinition } from 'nice-grpc/lib/service-definitions';
|
|
3
3
|
export declare class ModuleGenerator {
|
|
4
|
-
static
|
|
4
|
+
static createClientModuleDefinition(serverName: string, definition: CompatServiceDefinition): DynamicModule;
|
|
5
|
+
static createClientFactoryModuleDefinition(definition: CompatServiceDefinition): DynamicModule;
|
|
5
6
|
private static createChannelProvider;
|
|
6
7
|
private static createClientProvider;
|
|
7
8
|
}
|
package/dist/module.generator.js
CHANGED
|
@@ -7,11 +7,12 @@ const grpc_common_1 = require("@rsdk/grpc.common");
|
|
|
7
7
|
const metadata_1 = require("@rsdk/metadata");
|
|
8
8
|
const constants_1 = require("./metadata/constants");
|
|
9
9
|
const grpc_clients_autodoc_resolver_1 = require("./metadata/grpc-clients.autodoc-resolver");
|
|
10
|
+
const grpc_clients_factory_autodoc_resolver_1 = require("./metadata/grpc-clients-factory.autodoc-resolver");
|
|
10
11
|
const grpc_client_repository_1 = require("./repository/grpc-client.repository");
|
|
11
12
|
const grpc_client_repository_module_1 = require("./repository/grpc-client-repository.module");
|
|
12
13
|
const token_factories_1 = require("./token.factories");
|
|
13
14
|
class ModuleGenerator {
|
|
14
|
-
static
|
|
15
|
+
static createClientModuleDefinition(serverName, definition) {
|
|
15
16
|
const CONFIG_PROPERTY_ALIAS = (0, token_factories_1.getPropertyKey)(serverName);
|
|
16
17
|
const propertyToken = (0, core_1.getPropertyToken)(CONFIG_PROPERTY_ALIAS);
|
|
17
18
|
const clientToken = (0, token_factories_1.getClientToken)(definition);
|
|
@@ -42,6 +43,32 @@ class ModuleGenerator {
|
|
|
42
43
|
autodoc_protocol_1.AutodocMetadata.defineResolver(moduleDefinition, constants_1.GRPC_CLIENTS_RSDK_METADATA_SCOPE, grpc_clients_autodoc_resolver_1.grpcClientAutodocResolver);
|
|
43
44
|
return moduleDefinition;
|
|
44
45
|
}
|
|
46
|
+
static createClientFactoryModuleDefinition(definition) {
|
|
47
|
+
const token = (0, token_factories_1.getFactoryToken)(definition);
|
|
48
|
+
const factoryProvider = {
|
|
49
|
+
provide: token,
|
|
50
|
+
inject: [grpc_client_repository_1.GrpcClientRepository],
|
|
51
|
+
useFactory(grpcClientRepository) {
|
|
52
|
+
return {
|
|
53
|
+
create(address) {
|
|
54
|
+
return grpcClientRepository.resolveClient(definition, grpcClientRepository.resolveChannel(address, (0, token_factories_1.getChannelToken)(address)), (0, token_factories_1.getClientToken)(definition));
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
const moduleDefinition = {
|
|
60
|
+
global: true,
|
|
61
|
+
imports: [grpc_client_repository_module_1.GrpcClientRepositoryModule],
|
|
62
|
+
module: ModuleGenerator,
|
|
63
|
+
providers: [factoryProvider],
|
|
64
|
+
exports: [factoryProvider],
|
|
65
|
+
};
|
|
66
|
+
metadata_1.RsdkMetadata.add(moduleDefinition, {
|
|
67
|
+
definition,
|
|
68
|
+
}, constants_1.GRPC_CLIENTS_FACTORY_RSDK_METADATA_SCOPE);
|
|
69
|
+
autodoc_protocol_1.AutodocMetadata.defineResolver(moduleDefinition, constants_1.GRPC_CLIENTS_FACTORY_RSDK_METADATA_SCOPE, grpc_clients_factory_autodoc_resolver_1.grpcClientsFactoryAutodocResolver);
|
|
70
|
+
return moduleDefinition;
|
|
71
|
+
}
|
|
45
72
|
static createChannelProvider(channelToken, propertyToken) {
|
|
46
73
|
return {
|
|
47
74
|
provide: channelToken,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.generator.js","sourceRoot":"","sources":["../src/module.generator.ts"],"names":[],"mappings":";;;AACA,6DAAyD;AACzD,qCAIoB;AACpB,mDAAsD;AACtD,6CAA8C;
|
|
1
|
+
{"version":3,"file":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,EAAE,6CAAoB,CAAC;YAC7C,UAAU,EAAE,CAAC,OAAe,EAAE,IAA0B,EAAW,EAAE;gBACnE,OAAO,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;YACpD,CAAC;SACF,CAAC;IACJ,CAAC;IAEO,MAAM,CAAC,oBAAoB,CACjC,WAAmB,EACnB,YAAoB,EACpB,UAAmC;QAEnC,OAAO;YACL,OAAO,EAAE,WAAW;YAEpB,MAAM,EAAE,CAAC,YAAY,EAAE,6CAAoB,CAAC;YAC5C,UAAU,EAAE,CACV,OAAgB,EAChB,IAA0B,EACO,EAAE;gBACnC,OAAO,IAAI,CAAC,aAAa,CAAC,UAAU,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC;YAC9D,CAAC;SACF,CAAC;IACJ,CAAC;CACF;AAxID,0CAwIC"}
|
|
@@ -6,9 +6,6 @@ import type { CompatServiceDefinition } from 'nice-grpc/lib/service-definitions'
|
|
|
6
6
|
*/
|
|
7
7
|
export declare class GrpcClientRepository {
|
|
8
8
|
private static factory;
|
|
9
|
-
readonly logger: import("@rsdk/logging").ILogger;
|
|
10
|
-
readonly servers: Set<string>;
|
|
11
|
-
readonly definitions: Set<CompatServiceDefinition>;
|
|
12
9
|
readonly channels: Map<string, ChannelImplementation>;
|
|
13
10
|
readonly clients: Map<string, Client<CompatServiceDefinition>>;
|
|
14
11
|
resolveChannel(address: string, channelToken: string): ChannelImplementation;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GrpcClientRepository = void 0;
|
|
4
|
-
const logging_1 = require("@rsdk/logging");
|
|
5
4
|
const nice_grpc_1 = require("nice-grpc");
|
|
6
5
|
const nice_grpc_opentelemetry_1 = require("nice-grpc-opentelemetry");
|
|
7
6
|
const exception_mapper_middleware_1 = require("../middleware/exception-mapper.middleware");
|
|
@@ -12,10 +11,6 @@ class GrpcClientRepository {
|
|
|
12
11
|
static factory = (0, nice_grpc_1.createClientFactory)()
|
|
13
12
|
.use((0, nice_grpc_opentelemetry_1.openTelemetryClientMiddleware)())
|
|
14
13
|
.use((0, exception_mapper_middleware_1.exceptionMapperMiddleware)());
|
|
15
|
-
logger = logging_1.LoggerFactory.create(GrpcClientRepository);
|
|
16
|
-
// Registration
|
|
17
|
-
servers = new Set();
|
|
18
|
-
definitions = new Set();
|
|
19
14
|
// Caches
|
|
20
15
|
channels = new Map();
|
|
21
16
|
clients = new Map();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grpc-client.repository.js","sourceRoot":"","sources":["../../src/repository/grpc-client.repository.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"grpc-client.repository.js","sourceRoot":"","sources":["../../src/repository/grpc-client.repository.ts"],"names":[],"mappings":";;;AAEA,yCAA+D;AAE/D,qEAAwE;AAExE,2FAAsF;AAEtF;;GAEG;AACH,MAAa,oBAAoB;IACvB,MAAM,CAAC,OAAO,GAAG,IAAA,+BAAmB,GAAE;SAC3C,GAAG,CAAC,IAAA,uDAA6B,GAAE,CAAC;SACpC,GAAG,CAAC,IAAA,uDAAyB,GAAE,CAAC,CAAC;IAEpC,SAAS;IACA,QAAQ,GAAG,IAAI,GAAG,EAAmB,CAAC;IACtC,OAAO,GAAG,IAAI,GAAG,EAA2C,CAAC;IAEtE,cAAc,CAAC,OAAe,EAAE,YAAoB;QAClD,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,IAAA,yBAAa,EAAC,OAAO,CAAC,CAAC;QAE1E,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;QAEzC,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,aAAa,CACX,UAAmC,EACnC,OAA8B,EAC9B,WAAmB;QAEnB,MAAM,OAAO,GACX,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;YAC7B,oBAAoB,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QAE3D,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;QAEvC,OAAO,OAAO,CAAC;IACjB,CAAC;;AA7BH,oDA8BC"}
|
package/dist/servers/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsdk/grpc.clients",
|
|
3
|
-
"version": "2.6.0-next.
|
|
3
|
+
"version": "2.6.0-next.11",
|
|
4
4
|
"description": "Grpc clients infrastructure",
|
|
5
5
|
"license": "Apache License 2.0",
|
|
6
6
|
"publishConfig": {
|
|
@@ -17,15 +17,15 @@
|
|
|
17
17
|
"@grpc/grpc-js": "^1.8.7",
|
|
18
18
|
"@nestjs/common": "^9.0.0",
|
|
19
19
|
"@nestjs/microservices": "^9.0.0",
|
|
20
|
-
"@rsdk/autodoc.protocol": "^2.
|
|
21
|
-
"@rsdk/common": "^2.
|
|
22
|
-
"@rsdk/core": "^2.6.0-next.
|
|
23
|
-
"@rsdk/grpc.common": "^2.6.0-next.
|
|
24
|
-
"@rsdk/logging": "^2.
|
|
25
|
-
"@rsdk/metadata": "^2.
|
|
20
|
+
"@rsdk/autodoc.protocol": "^2.6.0-next.11",
|
|
21
|
+
"@rsdk/common": "^2.6.0-next.11",
|
|
22
|
+
"@rsdk/core": "^2.6.0-next.11",
|
|
23
|
+
"@rsdk/grpc.common": "^2.6.0-next.11",
|
|
24
|
+
"@rsdk/logging": "^2.6.0-next.11",
|
|
25
|
+
"@rsdk/metadata": "^2.6.0-next.11",
|
|
26
26
|
"nice-grpc": "^2.1.4",
|
|
27
27
|
"nice-grpc-opentelemetry": "^0.1.2",
|
|
28
28
|
"rxjs": "^7.0.0"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "d2183c898b6e46a7293e5d47eb6d9d6aa56419c5"
|
|
31
31
|
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { Inject } from '@nestjs/common';
|
|
2
|
+
import { PLATFORM_RAW_GLOBAL_METADATA_SCOPE } from '@rsdk/core/dist/rsdk-metadata/constants';
|
|
3
|
+
import { RsdkMetadata } from '@rsdk/metadata';
|
|
2
4
|
import type { CompatServiceDefinition } from 'nice-grpc/lib/service-definitions';
|
|
3
5
|
|
|
6
|
+
import { ModuleGenerator } from '../module.generator';
|
|
4
7
|
import { getFactoryToken } from '../token.factories';
|
|
5
8
|
|
|
6
9
|
// Factory for grpc-clients
|
|
@@ -22,8 +25,14 @@ export interface GrpcClientsFactory<T> {
|
|
|
22
25
|
export const InjectGrpcClientsFactory = (
|
|
23
26
|
definition: CompatServiceDefinition,
|
|
24
27
|
): ParameterDecorator => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
return (target, propertyKey, parameterIndex) => {
|
|
29
|
+
Inject(getFactoryToken(definition))(target, propertyKey, parameterIndex);
|
|
30
|
+
RsdkMetadata.setWithScope(
|
|
31
|
+
target,
|
|
32
|
+
PLATFORM_RAW_GLOBAL_METADATA_SCOPE,
|
|
33
|
+
definition.fullName,
|
|
34
|
+
ModuleGenerator.createClientFactoryModuleDefinition(definition),
|
|
35
|
+
true,
|
|
36
|
+
);
|
|
37
|
+
};
|
|
29
38
|
};
|
|
@@ -33,7 +33,7 @@ export const InjectGrpcClient = <
|
|
|
33
33
|
target,
|
|
34
34
|
PLATFORM_RAW_GLOBAL_METADATA_SCOPE,
|
|
35
35
|
`${grpcServerDeclarationValue.serverName}.${grpcServerDeclarationValue.serviceName}`,
|
|
36
|
-
ModuleGenerator.
|
|
36
|
+
ModuleGenerator.createClientModuleDefinition(
|
|
37
37
|
grpcServerDeclarationValue.serverName,
|
|
38
38
|
grpcServerDeclarationValue.definition,
|
|
39
39
|
),
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { DocumentNode, DocumentResolver } from '@rsdk/autodoc.protocol';
|
|
2
|
+
import { Composite, Table } from '@rsdk/autodoc.protocol';
|
|
3
|
+
import type { RsdkMetadataProvider } from '@rsdk/metadata';
|
|
4
|
+
import type { Promisable } from 'type-fest';
|
|
5
|
+
|
|
6
|
+
import type { GrpcFactoryMetadataValue } from '../servers/types';
|
|
7
|
+
|
|
8
|
+
import { GRPC_CLIENTS_FACTORY_RSDK_METADATA_SCOPE } from './constants';
|
|
9
|
+
|
|
10
|
+
class GrpcClientsFactoryAutodocResolver implements DocumentResolver {
|
|
11
|
+
getNode(rsdkMetadata: RsdkMetadataProvider): Promisable<DocumentNode | null> {
|
|
12
|
+
const resources = rsdkMetadata.get<GrpcFactoryMetadataValue>(
|
|
13
|
+
GRPC_CLIENTS_FACTORY_RSDK_METADATA_SCOPE,
|
|
14
|
+
);
|
|
15
|
+
if (!resources) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
return new Composite(
|
|
19
|
+
new Table(
|
|
20
|
+
resources.map(({ value: { definition } }) => ({
|
|
21
|
+
name: definition.name.toString(),
|
|
22
|
+
fullName: definition.fullName.toString(),
|
|
23
|
+
})),
|
|
24
|
+
),
|
|
25
|
+
'Grpc clients factory',
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const grpcClientsFactoryAutodocResolver =
|
|
31
|
+
new GrpcClientsFactoryAutodocResolver();
|
package/src/module.generator.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DynamicModule, FactoryProvider } from '@nestjs/common';
|
|
1
|
+
import type { DynamicModule, FactoryProvider, Provider } from '@nestjs/common';
|
|
2
2
|
import { AutodocMetadata } from '@rsdk/autodoc.protocol';
|
|
3
3
|
import {
|
|
4
4
|
ConfigMetadataRegistry,
|
|
@@ -10,19 +10,28 @@ import { RsdkMetadata } from '@rsdk/metadata';
|
|
|
10
10
|
import type { Channel, Client } from 'nice-grpc';
|
|
11
11
|
import type { CompatServiceDefinition } from 'nice-grpc/lib/service-definitions';
|
|
12
12
|
|
|
13
|
-
import {
|
|
13
|
+
import type { GrpcClientsFactory } from './decorators/inject-client-factory.decorator';
|
|
14
|
+
import {
|
|
15
|
+
GRPC_CLIENTS_FACTORY_RSDK_METADATA_SCOPE,
|
|
16
|
+
GRPC_CLIENTS_RSDK_METADATA_SCOPE,
|
|
17
|
+
} from './metadata/constants';
|
|
14
18
|
import { grpcClientAutodocResolver } from './metadata/grpc-clients.autodoc-resolver';
|
|
19
|
+
import { grpcClientsFactoryAutodocResolver } from './metadata/grpc-clients-factory.autodoc-resolver';
|
|
15
20
|
import { GrpcClientRepository } from './repository/grpc-client.repository';
|
|
16
21
|
import { GrpcClientRepositoryModule } from './repository/grpc-client-repository.module';
|
|
17
|
-
import type {
|
|
22
|
+
import type {
|
|
23
|
+
GrpcFactoryMetadataValue,
|
|
24
|
+
GrpcServerMetadataValue,
|
|
25
|
+
} from './servers/types';
|
|
18
26
|
import {
|
|
19
27
|
getChannelToken,
|
|
20
28
|
getClientToken,
|
|
29
|
+
getFactoryToken,
|
|
21
30
|
getPropertyKey,
|
|
22
31
|
} from './token.factories';
|
|
23
32
|
|
|
24
33
|
export class ModuleGenerator {
|
|
25
|
-
static
|
|
34
|
+
static createClientModuleDefinition(
|
|
26
35
|
serverName: string,
|
|
27
36
|
definition: CompatServiceDefinition,
|
|
28
37
|
): DynamicModule {
|
|
@@ -78,6 +87,54 @@ export class ModuleGenerator {
|
|
|
78
87
|
return moduleDefinition;
|
|
79
88
|
}
|
|
80
89
|
|
|
90
|
+
static createClientFactoryModuleDefinition(
|
|
91
|
+
definition: CompatServiceDefinition,
|
|
92
|
+
): DynamicModule {
|
|
93
|
+
const token = getFactoryToken(definition);
|
|
94
|
+
const factoryProvider: Provider = {
|
|
95
|
+
provide: token,
|
|
96
|
+
inject: [GrpcClientRepository],
|
|
97
|
+
useFactory(
|
|
98
|
+
grpcClientRepository: GrpcClientRepository,
|
|
99
|
+
): GrpcClientsFactory<any> {
|
|
100
|
+
return {
|
|
101
|
+
create(address: string): any {
|
|
102
|
+
return grpcClientRepository.resolveClient(
|
|
103
|
+
definition,
|
|
104
|
+
grpcClientRepository.resolveChannel(
|
|
105
|
+
address,
|
|
106
|
+
getChannelToken(address),
|
|
107
|
+
),
|
|
108
|
+
getClientToken(definition),
|
|
109
|
+
);
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
const moduleDefinition = {
|
|
115
|
+
global: true,
|
|
116
|
+
imports: [GrpcClientRepositoryModule],
|
|
117
|
+
module: ModuleGenerator,
|
|
118
|
+
providers: [factoryProvider],
|
|
119
|
+
exports: [factoryProvider],
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
RsdkMetadata.add<GrpcFactoryMetadataValue>(
|
|
123
|
+
moduleDefinition,
|
|
124
|
+
{
|
|
125
|
+
definition,
|
|
126
|
+
},
|
|
127
|
+
GRPC_CLIENTS_FACTORY_RSDK_METADATA_SCOPE,
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
AutodocMetadata.defineResolver(
|
|
131
|
+
moduleDefinition,
|
|
132
|
+
GRPC_CLIENTS_FACTORY_RSDK_METADATA_SCOPE,
|
|
133
|
+
grpcClientsFactoryAutodocResolver,
|
|
134
|
+
);
|
|
135
|
+
return moduleDefinition;
|
|
136
|
+
}
|
|
137
|
+
|
|
81
138
|
private static createChannelProvider(
|
|
82
139
|
channelToken: string,
|
|
83
140
|
propertyToken: `STANDALONE_CONFIG_PROPERTY_${string}`,
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { ChannelImplementation } from '@grpc/grpc-js/build/src/channel';
|
|
2
|
-
import { LoggerFactory } from '@rsdk/logging';
|
|
3
2
|
import type { Channel, Client } from 'nice-grpc';
|
|
4
3
|
import { createChannel, createClientFactory } from 'nice-grpc';
|
|
5
4
|
import type { CompatServiceDefinition } from 'nice-grpc/lib/service-definitions';
|
|
@@ -15,12 +14,6 @@ export class GrpcClientRepository {
|
|
|
15
14
|
.use(openTelemetryClientMiddleware())
|
|
16
15
|
.use(exceptionMapperMiddleware());
|
|
17
16
|
|
|
18
|
-
readonly logger = LoggerFactory.create(GrpcClientRepository);
|
|
19
|
-
|
|
20
|
-
// Registration
|
|
21
|
-
readonly servers = new Set<string>();
|
|
22
|
-
readonly definitions = new Set<CompatServiceDefinition>();
|
|
23
|
-
|
|
24
17
|
// Caches
|
|
25
18
|
readonly channels = new Map<string, Channel>();
|
|
26
19
|
readonly clients = new Map<string, Client<CompatServiceDefinition>>();
|