ts-proto
ts-proto copied to clipboard
Value/ListValue do not include the required dependencies when using nestJs=true
For content-delivery.proto file:
syntax = "proto3";
package content_delivery;
import "google/protobuf/struct.proto";
...
message Test {
// optional google.protobuf.Value data = 5; // If this replaces the next line, it does not work
optional google.protobuf.Struct data = 5;
}
Using Struct correctly requires the dependencies in the built content-delivery.ts, but does not if Value or ListValue is used.
The missing lines are as follows, the files otherwise being identical:
- import { wrappers } from "protobufjs";
import { Observable } from "rxjs";
import { ContentElement_MetaProps, Course, CourseMetaProps, Page } from "./content.pb";
- import { Struct } from "./google/protobuf/struct.pb";
...
+ data?:
+ | any
+ | undefined;
- data?: { [key: string]: any } | undefined;
...
- wrappers[".google.protobuf.Struct"] = { fromObject: Struct.wrap, toObject: Struct.unwrap } as any;
As you can see, the types seem to be correct, but the import is not there. This only happens with the Nestjs option - without it, the generated files are working, i.e. they only have expected differences (using Value. vs Struct).
EDIT: Also, it seems Struct is there only if it's part of at least one root message, but not if all messages containing it are nested:
message TestFirst {
message TestSecond {
google.protobuf.Struct dataSecond = 1;
}
TestSecond dataFirst = 1;
}
In this case, even Struct will not be correctly imported (again, only in the case of Nest plugin). Should I open another issue for that, since it looks like a different problem?
Version: Initially tried on 1.156.6, then tried bumping to latest 1.166.2
I have a similar bug:
I have a gRPC service
syntax = "proto3";
import "google/protobuf/struct.proto";
service SharedDomainsEventsService {
rpc HandleEvent (Event) returns (Event) {}
}
message Event {
string name = 1;
google.protobuf.Struct data = 2;
string correlationId = 3;
}
And the following payload being sent by the client:
const event: Event = {
name: 'Workflow',
correlationId: '48f60676-c03d-477d-a20f-c42e05086350',
data: { hello: 'world' },
};
The message is received by the gRPC server, however the data parameter is empty, on the logs of the gRPC server it shows:
[Nest] 275137 - 09/07/2024, 9:34:30 PM DEBUG [SharedDomainsService] handleEvent called. Input: {"name":"Workflow","data":{},"correlationId":"48f60676-c03d-477d-a20f-c42e05086350"}
@dbettini any luck on solving this?
@dbettini any luck on solving this?
It seems you're using Struct, which works for me (as long as it's present in one of the root messages), only Value/ListValue don't. I recommend you check the built files to see if Struct is not being imported, but your issue could be somewhere else