Protocol Buffers for ECMAScript. The only JavaScript Protobuf library that is fully-compliant with Protobuf conformance tests.
Full Changelog: https://github.com/bufbuild/protobuf-es/compare/v1.8.0...v1.9.0
To support Protobuf editions, we have to make breaking changes that also affect users of proto2 and proto3. This prompted us to make more extensive changes that take feedback from version 1 into account:
We no longer uses classes. Instead, we generate a type and a descriptor for every message, and provide functions to create a new instance, for serialization, and other concerns. Here is a simple example:
import { create, toBinary, fromBinary, fromJsonString } from "@bufbuild/protobuf";
import { UserDesc } from "./gen/user_pb.js";
let user = create(UserDesc, {
firstName: "Homer",
lastName: "Simpson",
active: true,
locations: ["Springfield"],
projects: { SPP: "Springfield Power Plant" },
manager: {
firstName: "Montgomery",
lastName: "Burns",
},
});
const bytes = toBinary(UserDesc, user);
user = fromBinary(UserDesc, bytes);
user = fromJsonString(UserDesc, '{"firstName": "Homer", "lastName": "Simpson"}');
This approach solves several outstanding issues, such as:
If you use proto3, messages are now plain objects. Files with proto2 and editions use the prototype chain to track field presence.
Please note that this is an alpha release, and APIs might still change. We're also missing documentation yet. But if you want to try it out, we welcome your feedback!
This release is published with the alpha
tag. To install the alpha packages, you can run:
npm install @bufbuild/protobuf@alpha @bufbuild/protoc-gen-es@alpha
Thanks to @srikrsna-buf for his contributions to v2!
/*@__PURE__*/
annotation for better tree-shaking support by @pmzi in https://github.com/bufbuild/protobuf-es/pull/470
Full Changelog: https://github.com/bufbuild/protobuf-es/compare/v1.7.2...v1.8.0
Full Changelog: https://github.com/bufbuild/protobuf-es/compare/v1.7.1...v1.7.2
Full Changelog: https://github.com/bufbuild/protobuf-es/compare/v1.7.0...v1.7.1
This release adds support for extensions, a Protobuf language feature that allows to extend a message with an additional field.
For example:
syntax = "proto2";
message User {
extensions 100 to 200;
}
extend User {
optional uint32 age = 100;
}
For the extension age
, we generate a new export const age: Extension<User, number>
. You can set the extension field with the function setExtension
:
import { setExtension } from "@bufbuild/protobuf";
import { User, age } from "./example_pb.js";
const user = new User();
setExtension(user, age, 77);
To learn more about the details, see the API documentation.
For plugin authors: Since extensions provide a better way to access custom options in a plugin, we are deprecating the findCustom*Option
functions from @bufbuild/protoplugin/ecmascript
. We recommend to switch to extensions for better type safety and flexibility, see the PR for details.
Full Changelog: https://github.com/bufbuild/protobuf-es/compare/v1.6.0...v1.7.0
GeneratedFile.jsDoc()
and other features to @bufbuild/protoplugin
by @timostamm in #649
Full Changelog: https://github.com/bufbuild/protobuf-es/compare/v1.5.1...v1.6.0
@bufbuild/protoplugin
by @timostamm in https://github.com/bufbuild/protobuf-es/pull/644
@bufbuild/protoplugin
, improve error messages by @timostamm in https://github.com/bufbuild/protobuf-es/pull/642
Full Changelog: https://github.com/bufbuild/protobuf-es/compare/v1.5.0...v1.5.1
This release includes preliminary support for editions. Please note that it's still an experimental feature.
Full Changelog: https://github.com/bufbuild/protobuf-es/compare/v1.4.2...v1.5.0
@bufbuild/protobuf
to the direct dependencies of protoc-gen-es by @timostamm in https://github.com/bufbuild/protobuf-es/pull/601
Full Changelog: https://github.com/bufbuild/protobuf-es/compare/v1.4.1...v1.4.2