@enriqcg/protobufjs-wrapper-types
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Protobufjs with support for .google.protobuf.Timestamp

NPM

Why does this package exist?

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.

How to use the custom loader 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',
  },
});

Thanks to

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.

Readme

Keywords

none

Package Sidebar

Install

npm i @enriqcg/protobufjs-wrapper-types

Weekly Downloads

3

Version

1.0.1

License

MIT

Unpacked Size

3.71 kB

Total Files

4

Last publish

Collaborators

  • enriqcg