The ts-proto library recently incorporated support for Wrapper Types, as detailed in stephenh/ts-proto#762. See the original issue for further understanding of what this library tried to fix, and the comment announcing the fix.
Protobuf.js does not have support for Wrapper Types other than .google.protobuf.Any
.
This (small) package adds Javascript support for google.protobuf.Timestamp
through the Date class. Any Date object with Protobuf type google.protobuf.Timestamp
will be serialized to Google's Wrapper Type, and be deserialized back into a Date object.
This package is a superset of Protobuf.js. It just injects a custom handler for google.protobuf.Timestamp
and then calls the upstream protobufjs.loader()
. Just the synchronous loader function is implemented as this is intended to be used with NestJS.
npm i @enriqcg/protobufjs-wrapper-types
app.connectMicroservice<MicroserviceOptions>({
transport: Transport.GRPC,
options: {
url: '0.0.0.0:5000',
package: 'package.name',
protoPath: join(__dirname, 'path_to_proto'),
// use this package as the custom protoloader
protoLoader: '@enriqcg/protobufjs-wrapper-types',
},
});
Pull Requests have been created on protobuf.js to address this issue, but are still open and don't look like they are going to be merged any time soon. I've based the code of this package on existing opened PRs and adapted it to make it work with Nest.JS.