ts-proto 2.14.0 → 2.15.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.markdown
CHANGED
|
@@ -465,11 +465,17 @@ With `--ts_proto_opt=protoJsonFormat=false`, strict proto3 compliance is disable
|
|
|
465
465
|
|
|
466
466
|
(Requires `nestJs=true`.)
|
|
467
467
|
|
|
468
|
+
- With `--ts_proto_opt=useNestjsFqnServiceName=true`, the generated `@FooServiceControllerMethods()` decorator will pass the fully qualified service name (i.e. `package.FooService` instead of `FooService`) to the `@GrpcMethod`/`@GrpcStreamMethod` decorators of `@nestjs/microservices`.
|
|
469
|
+
|
|
470
|
+
NestJS falls back to resolving a handler by the `package.Service` segment of the gRPC method path, so the handlers are found regardless of which `package` the gRPC server was configured with, and services with the same name in different packages no longer collide. The `FOO_SERVICE_NAME` const is not affected, since `client.getService()` expects the package-relative name.
|
|
471
|
+
|
|
472
|
+
(Requires `nestJs=true`.)
|
|
473
|
+
|
|
468
474
|
- With `--ts_proto_opt=nestJs=true`, the defaults will change to generate [NestJS protobuf](https://docs.nestjs.com/microservices/grpc) friendly types & service interfaces that can be used in both the client-side and server-side of NestJS protobuf implementations. See the [nestjs readme](NESTJS.markdown) for more information and implementation examples.
|
|
469
475
|
|
|
470
476
|
Specifically `outputEncodeMethods`, `outputJsonMethods`, and `outputClientImpl` will all be false, `lowerCaseServiceMethods` will be true and `outputServices` will be ignored.
|
|
471
477
|
|
|
472
|
-
Note that `addGrpcMetadata`, `addNestjsRestParameter` and `
|
|
478
|
+
Note that `addGrpcMetadata`, `addNestjsRestParameter`, `returnObservable` and `useNestjsFqnServiceName` will still be false.
|
|
473
479
|
|
|
474
480
|
- With `--ts_proto_opt=useDate=false`, fields of type `google.protobuf.Timestamp` will not be mapped to type `Date` in the generated types. See [Timestamp](#timestamp) for more details.
|
|
475
481
|
|
|
@@ -4,4 +4,4 @@ import SourceInfo from "./sourceInfo";
|
|
|
4
4
|
import { Context } from "./context";
|
|
5
5
|
export declare function generateNestjsServiceController(ctx: Context, fileDesc: FileDescriptorProto, sourceInfo: SourceInfo, serviceDesc: ServiceDescriptorProto): Code;
|
|
6
6
|
export declare function generateNestjsServiceClient(ctx: Context, fileDesc: FileDescriptorProto, sourceInfo: SourceInfo, serviceDesc: ServiceDescriptorProto): Code;
|
|
7
|
-
export declare function generateNestjsGrpcServiceMethodsDecorator(ctx: Context, serviceDesc: ServiceDescriptorProto): Code;
|
|
7
|
+
export declare function generateNestjsGrpcServiceMethodsDecorator(ctx: Context, fileDesc: FileDescriptorProto, serviceDesc: ServiceDescriptorProto): Code;
|
|
@@ -118,10 +118,13 @@ function generateNestjsServiceClient(ctx, fileDesc, sourceInfo, serviceDesc) {
|
|
|
118
118
|
chunks.push((0, ts_poet_1.code) `}`);
|
|
119
119
|
return (0, ts_poet_1.joinCode)(chunks, { on: "\n\n" });
|
|
120
120
|
}
|
|
121
|
-
function generateNestjsGrpcServiceMethodsDecorator(ctx, serviceDesc) {
|
|
121
|
+
function generateNestjsGrpcServiceMethodsDecorator(ctx, fileDesc, serviceDesc) {
|
|
122
122
|
const { options } = ctx;
|
|
123
123
|
const GrpcMethod = (0, ts_poet_1.imp)("GrpcMethod@@nestjs/microservices");
|
|
124
124
|
const GrpcStreamMethod = (0, ts_poet_1.imp)("GrpcStreamMethod@@nestjs/microservices");
|
|
125
|
+
const serviceName = options.useNestjsFqnServiceName
|
|
126
|
+
? (0, utils_1.maybePrefixPackage)(fileDesc, serviceDesc.name)
|
|
127
|
+
: serviceDesc.name;
|
|
125
128
|
const grpcMethods = serviceDesc.method
|
|
126
129
|
.filter((m) => !m.clientStreaming)
|
|
127
130
|
.map((m) => {
|
|
@@ -142,13 +145,13 @@ function generateNestjsGrpcServiceMethodsDecorator(ctx, serviceDesc) {
|
|
|
142
145
|
const grpcMethods: string[] = [${grpcMethods.join(", ")}];
|
|
143
146
|
for (const method of grpcMethods) {
|
|
144
147
|
const descriptor: any = Reflect.getOwnPropertyDescriptor(constructor.prototype, method);
|
|
145
|
-
${GrpcMethod}('${
|
|
148
|
+
${GrpcMethod}('${serviceName}', method)(constructor.prototype[method], method, descriptor);
|
|
146
149
|
Object.defineProperty(constructor.prototype, method, descriptor);
|
|
147
150
|
}
|
|
148
151
|
const grpcStreamMethods: string[] = [${grpcStreamMethods.join(", ")}];
|
|
149
152
|
for (const method of grpcStreamMethods) {
|
|
150
153
|
const descriptor: any = Reflect.getOwnPropertyDescriptor(constructor.prototype, method);
|
|
151
|
-
${GrpcStreamMethod}('${
|
|
154
|
+
${GrpcStreamMethod}('${serviceName}', method)(constructor.prototype[method], method, descriptor);
|
|
152
155
|
Object.defineProperty(constructor.prototype, method, descriptor);
|
|
153
156
|
}
|
|
154
157
|
};
|
package/build/src/main.js
CHANGED
|
@@ -233,7 +233,7 @@ function generateFile(ctx, fileDesc) {
|
|
|
233
233
|
// and the service controller interface
|
|
234
234
|
chunks.push((0, generate_nestjs_1.generateNestjsServiceController)(ctx, fileDesc, sInfo, serviceDesc));
|
|
235
235
|
// generate nestjs grpc service controller decorator
|
|
236
|
-
chunks.push((0, generate_nestjs_1.generateNestjsGrpcServiceMethodsDecorator)(ctx, serviceDesc));
|
|
236
|
+
chunks.push((0, generate_nestjs_1.generateNestjsGrpcServiceMethodsDecorator)(ctx, fileDesc, serviceDesc));
|
|
237
237
|
let serviceConstName = `${(0, case_1.camelToSnake)(serviceDesc.name)}_NAME`;
|
|
238
238
|
if (!serviceDesc.name.toLowerCase().endsWith("service")) {
|
|
239
239
|
serviceConstName = `${(0, case_1.camelToSnake)(serviceDesc.name)}_SERVICE_NAME`;
|
package/build/src/options.d.ts
CHANGED
package/build/src/options.js
CHANGED
|
@@ -98,6 +98,7 @@ function defaultOptions() {
|
|
|
98
98
|
addGrpcMetadata: false,
|
|
99
99
|
metadataType: undefined,
|
|
100
100
|
addNestjsRestParameter: false,
|
|
101
|
+
useNestjsFqnServiceName: false,
|
|
101
102
|
nestJs: false,
|
|
102
103
|
env: EnvOption.BOTH,
|
|
103
104
|
unrecognizedEnum: true,
|
|
@@ -238,6 +239,10 @@ function optionsFromParameter(parameter) {
|
|
|
238
239
|
if (options.nestJs) {
|
|
239
240
|
options.initializeFieldsAsUndefined = false;
|
|
240
241
|
}
|
|
242
|
+
else {
|
|
243
|
+
// useNestjsFqnServiceName requires nestJs=true
|
|
244
|
+
options.useNestjsFqnServiceName = false;
|
|
245
|
+
}
|
|
241
246
|
if (options.outputIndex) {
|
|
242
247
|
options.exportCommonSymbols = false;
|
|
243
248
|
}
|