Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
resolve-protobuf-schema
Advanced tools
Read a protobuf schema from the disk, parse it and resolve all imports
The resolve-protobuf-schema npm package is used to parse and resolve Protocol Buffers (protobuf) schema definitions. It helps in converting .proto files into JavaScript objects that can be used for further processing or validation.
Parsing .proto files
This feature allows you to read and parse a .proto file into a JavaScript object. The parsed schema can then be used for various purposes such as validation or code generation.
const fs = require('fs');
const resolve = require('resolve-protobuf-schema');
const schema = resolve(fs.readFileSync('path/to/your.proto', 'utf-8'));
console.log(schema);
Resolving imports in .proto files
This feature allows you to resolve imports within .proto files. If your .proto file imports other .proto files, you can provide a custom resolveImport function to handle these imports.
const fs = require('fs');
const resolve = require('resolve-protobuf-schema');
const schema = resolve(fs.readFileSync('path/to/your.proto', 'utf-8'), {
resolveImport: (importPath) => fs.readFileSync(importPath, 'utf-8')
});
console.log(schema);
protobufjs is a comprehensive library for working with Protocol Buffers in JavaScript. It provides functionality for parsing .proto files, generating static code, and runtime message encoding/decoding. Compared to resolve-protobuf-schema, protobufjs offers a broader range of features including message serialization and deserialization.
proto-loader is a package that works with grpc and allows you to load .proto files into JavaScript objects. It supports resolving imports and is often used in conjunction with grpc libraries. While it offers similar schema resolution capabilities, it is more focused on gRPC service definitions and usage.
Read a protobuf schema from the disk, parse it and resolve all imports
npm install resolve-protobuf-schema
Store the following example protobuf schema in test.proto
message Test {
optional string test = 1;
}
Then run
var resolve = require('resolve-protobuf-schema')
console.log(resolve.sync('test.proto')) // prints the parsed schema
Schema imports will resolved as well
import "./test.proto"
message AnotherTest {
optional string test = 1;
}
console.log(resolve.sync('./another-test.proto')) // will print a combined parsed schema
resolve(path, cb)
read and resolve a schemaresolve.sync(path)
sync version of resolve
MIT
FAQs
Read a protobuf schema from the disk, parse it and resolve all imports
The npm package resolve-protobuf-schema receives a total of 1,306,830 weekly downloads. As such, resolve-protobuf-schema popularity was classified as popular.
We found that resolve-protobuf-schema demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.