1.1.3 • Published 4 years ago

babel-plugin-import-proto v1.1.3

Weekly downloads
4
License
MIT
Repository
github
Last release
4 years ago

npm Version npm Downloads npm License

babel-plugin-import-proto

Babel plugin enabling import syntax for .proto files.

Prerequisites

npm install -D @babel/core @grpc/proto-loader
npm install @grpc/grpc-js

Install

npm install -D babel-plugin-import-proto

In .babelrc

{
  'plugins': ['import-proto']
}

Each time you modify a Protobuf file, the cache must be cleared for the changes to take effect.

Options

OptionTypeDefaultDescription
keepCaseBooleanfalsePreserve field names. The default is to change them to camel case.
longs'String' | 'Number' | 'Long''Number'The constructor name of type to use to represent long values.
enums'String' | 'Number''String'The constructor name of type to use to represent enum values.
bytes'String' | 'Array' | 'Buffer''String'The constructor name of type to use to represent bytes values.
defaultsBooleanfalseSet default values on output objects.
arraysBooleanfalseSet empty arrays for missing array values even if defaults is false.
objectsBooleanfalseSet empty objects for missing object values even if defaults is false.
oneofsBooleanfalseSet virtual oneof properties to the present field's name.
includeDirsArray<String>[]A list of search paths for imported .proto files.

Examples

import { test } from './test/fixtures/example.proto'
import grpc from 'grpc'

// server.js
const server = new grpc.Server()
server.addProtoService(test.fixture.exampleService.service, new ExampleServiceServerImplem())
server.bind('0.0.0.0:50051', grpc.ServerCredentials.createInsecure())
server.start()

// client.js
const client = new test.fixture.exampleService('localhost:50051', grpc.credentials.createInsecure())
client.getExampleEntity({ id: 0 }, function (err, exampleEntity) {
  if (err) {
    // do something
  } else {
    // do something
  }
})