3.21.2-2 • Published 6 months ago

protobuf-javascript-with-from-object v3.21.2-2

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

kzolti/protobuf-javascript-with-from-object

Google Protocol Buffers for JavaScript with fromObject method

kzolti/protobuf-javascript submodule

This project uses a fork of protocolbuffers/protobuf-javascript as a submodule. The fork, located at kzolti/protobuf-javascript, includes the following differences compared to the upstream repository:

Changes Made

Added a fromObject method to the generated JavaScript protobuf classes.

Manual check differencies

https://github.com/protocolbuffers/protobuf-javascript/compare/main...kzolti:protobuf-javascript:main?diff=split&w=

git clone https://github.com/kzolti/protobuf-javascript.git                           && \ 
cd protobuf-javascript                                                                && \ 
git checkout main                                                                     && \
git remote add upstream https://github.com/protocolbuffers/protobuf-javascript.git    && \
git fetch upstream                                                                    && \
git diff upstream/main main   

Changes to made in js_generator.cc (2024-06-12)

diff --git a/generator/js_generator.cc b/generator/js_generator.cc
index 44d00b1..7b97962 100644
--- a/generator/js_generator.cc
+++ b/generator/js_generator.cc
@@ -1980,7 +1980,7 @@ void Generator::GenerateClass(const GeneratorOptions& options,
   if (!NamespaceOnly(desc)) {
     printer->Print("\n");
     GenerateClassFieldInfo(options, printer, desc);
-
+    GenerateClassFromObject(options, printer, desc);
     GenerateClassToObject(options, printer, desc);
     // These must come *before* the extension-field info generation in
     // GenerateClassRegistration so that references to the binary

Installation and usage

Note: This package only includes the Linux_x86_64 binary. For other platforms, follow the instructions at Building from Source.

npm install kzolti/protobuf-javascript-with-from-object --save

If other modules reference the google-protobuf package, add the following to package.json:

 "overrides": {
    "google-protobuf": "protobuf-javascript-with-from-object"
  }

or yarn resolutions.

Generate protobuf pb.js file

protoc --js_out=library=myproto_libs,binary:. messages.proto

Generate typescript definition files

Install protoc-gen-ts-with-from-object

npm install protoc-gen-ts-with-from-object --save
protoc --js_out=library=myproto_libs,binary:.  --ts_out=.  messages.proto

Using latest protoc binary from your project:

install latest-protoc-binary

npm i latest-protoc-binary
npx protoc --version

If necessary, install and set up module-alias:

npm install module-alias --save

In index.js:

const moduleAlias = require('module-alias');
moduleAlias.addAlias('google-protobuf', 'protobuf-javascript-with-from-object');

Building from source

Note: Bazel runtime environment is required to build the project.

git clone https://github.com/kzolti/protobuf-javascript-with-from-object.git
cd protobuf-javascript-with-from-object                                     
npm install
npm run build
npm pack
3.21.2-2

6 months ago

3.21.2

6 months ago