Registry / serialization / protocol-buffers-schema

protocol-buffers-schema

JSON →
library3.6.1jsnpmunverified

protocol-buffers-schema is a minimalist JavaScript library designed for parsing Protocol Buffers (.proto) schema files into a structured JavaScript object and stringifying such objects back into the .proto format. It explicitly focuses on schema definition parsing rather than binary serialization or deserialization of actual Protobuf messages. The current stable version is 3.6.1, though the last npm publication (for 3.6.0) was approximately four years ago, suggesting a maintenance mode with an infrequent release cadence, if any. Its primary differentiator is its straightforward API for schema manipulation, contrasting with more comprehensive Protobuf libraries that include code generation, runtime encoding/decoding, and gRPC support. This package serves as a foundational component for tools that need to inspect or modify Protobuf definitions programmatically.

npm install protocol-buffers-schema
INSTALL
IMPORT
SIG · PROTOCOL-BUFFERS-S
P
protocol-buffers-schema
serializationjavascriptv3.6.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

schema
import schema from 'protocol-buffers-schema'
const { parse } = require('protocol-buffers-schema')
The package is a CommonJS module. In ESM, `import schema from 'protocol-buffers-schema'` or `import * as schema from 'protocol-buffers-schema'` is the correct way to import the module's default export, which is the object containing `parse` and `stringify`.
parse
import schema from 'protocol-buffers-schema'; schema.parse(protoString);
import { parse } from 'protocol-buffers-schema'
The `parse` function is a property of the default exported module object, not a named export. Attempting to destructure it directly as a named export will result in `undefined`.
stringify
const schema = require('protocol-buffers-schema'); schema.stringify(schemaObject);
require('protocol-buffers-schema').stringify(schemaObject)
While functional, chaining directly off `require()` is less readable and can complicate mocking in tests. Assigning to a variable first is preferred for clarity and consistency.

Demonstrates parsing a Protobuf schema string into a JavaScript object and then stringifying it back, also showing how to access parsed schema elements.

import { readFileSync } from 'fs'; import schema from 'protocol-buffers-schema'; // Create a dummy .proto file for demonstration const protoContent = ` syntax = "proto2"; message Point { required int32 x = 1; required int32 y = 2; optional string label = 3; } message Line { required Point start = 1; required Point end = 2; optional string label = 3; } `; // In a real scenario, this would be fs.writeFileSync('example.proto', protoContent); // For this quickstart, we'll parse the string directly. // Parse the .proto schema const parsedSchema = schema.parse(protoContent); // Log the parsed JavaScript object representation of the schema console.log('Parsed Protobuf Schema:'); console.log(JSON.stringify(parsedSchema, null, 2)); // You can also stringify it back to .proto format const stringifiedSchema = schema.stringify(parsedSchema); console.log('\nStringified Protobuf Schema (reconstructed):'); console.log(stringifiedSchema); // Example of accessing elements console.log('\nFirst message name:', parsedSchema.messages[0].name); console.log('First field of first message:', parsedSchema.messages[0].fields[0].name);
Debug
Known issues
gotchaThis package is a schema parser only. It does NOT provide functionality for encoding or decoding actual Protocol Buffers binary messages. For binary serialization/deserialization, consider libraries like `protobuf.js`, `google-protobuf`, or `protobuf-es`.
fix
Use a dedicated Protobuf runtime library (e.g., `npm install protobufjs`) for encoding and decoding binary data.
affects: >=1.0.0
gotchaThe package (v3.6.1, last published ~4 years ago for 3.6.0) might not fully support all modern Protocol Buffers language features introduced in newer `proto3` specifications or `Protobuf Editions`. Ensure compatibility if working with very recent .proto syntax.
fix
Review the parsed output carefully for newer syntax. If issues arise, consider alternative, more actively maintained Protobuf parsing solutions or pre-process your .proto files to simpler forms if possible.
affects: >=3.0.0
breakingOlder versions of `protocol-buffers-schema` may have handled certain Protobuf syntax nuances differently. While no specific major breaking changes for schema parsing are widely documented for this library, the broader Protobuf ecosystem has had breaking changes, especially concerning generated code and runtime compatibility.
fix
Always use the latest stable version (3.6.1) to benefit from bug fixes and improved parsing logic. Consult the GitHub repository's commit history for specific changes between major versions if migrating from a very old version.
affects: <3.0.0
Errors
Common errors & fixes
TypeError: schema.encode is not a function
Attempting to use `protocol-buffers-schema` for binary encoding/decoding, which it does not support.
fix
This library only parses and stringifies Protobuf schema definitions. To encode or decode binary Protobuf messages, use a different library such as `protobuf.js` or `google-protobuf`.
TypeError: Cannot read properties of undefined (reading 'parse')
Incorrectly importing the `parse` function as a named export instead of accessing it from the default module object.
fix
For CommonJS, use `const schema = require('protocol-buffers-schema'); schema.parse(...)`. For ESM, use `import schema from 'protocol-buffers-schema'; schema.parse(...)`.
SyntaxError: Unexpected token 'required' / 'optional'
Parsing a `proto3` file that uses `required` or `optional` keywords for field rules without explicitly setting `syntax = "proto2"`. While `protocol-buffers-schema` supports both, `proto3` has different default field behaviors and `required`/`optional` are not standard field rules (except with Editions).
fix
Ensure `syntax = "proto2";` is present in your `.proto` file if you intend to use explicit `required`/`optional` field rules. If using `proto3` without Editions, these keywords are not valid for field rules.
Upgrade
Version history
3.6.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
protocol-buffers-schema — npm install protocol-buffers-schema · libregistry