Socket
Socket
Sign inDemoInstall

protons

Package Overview
Dependencies
Maintainers
4
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

protons - npm Package Compare versions

Comparing version 2.0.3 to 3.0.0

dist/bin/protons.js

220

package.json
{
"name": "protons",
"version": "2.0.3",
"description": "Protocol Buffers for Node.js without compiliation",
"leadMaintainer": "Alex Potsides <alex@achingbrain.net>",
"version": "3.0.0",
"description": "Protobuf to ts transpiler",
"license": "Apache-2.0 OR MIT",
"homepage": "https://github.com/ipfs/protons/tree/master/packages/protons#readme",
"repository": {
"type": "git",
"url": "https://github.com/ipfs/protons"
"url": "git+https://github.com/ipfs/protons.git"
},
"dependencies": {
"protocol-buffers-schema": "^3.3.1",
"signed-varint": "^2.0.1",
"uint8arrays": "^3.0.0",
"varint": "^5.0.0"
"bugs": {
"url": "https://github.com/ipfs/protons/issues"
},
"devDependencies": {
"aegir": "^25.1.0",
"benchmark": "^2.1.4",
"protocol-buffers": "^4.1.0",
"protons": "^1.0.0",
"tape": "^4.8.0",
"util": "^0.12.4"
"engines": {
"node": ">=16.0.0",
"npm": ">=7.0.0"
},
"bin": {
"protons": "./dist/bin/protons.js"
},
"type": "module",
"types": "./dist/src/index.d.ts",
"typesVersions": {
"*": {
"*": [
"*",
"dist/*",
"dist/src/*",
"dist/src/*/index"
],
"src/*": [
"*",
"dist/*",
"dist/src/*",
"dist/src/*/index"
]
}
},
"files": [
"src",
"dist/src",
"!dist/test",
"!**/*.tsbuildinfo"
],
"exports": {
".": {
"import": "./dist/src/index.js",
"types": "./dist/src/index.d.ts"
},
"./status": {
"import": "./dist/src/status.js",
"types": "./dist/src/status.d.ts"
}
},
"eslintConfig": {
"extends": "ipfs",
"parserOptions": {
"sourceType": "module"
}
},
"release": {
"branches": [
"master"
],
"plugins": [
[
"@semantic-release/commit-analyzer",
{
"preset": "conventionalcommits",
"releaseRules": [
{
"breaking": true,
"release": "major"
},
{
"revert": true,
"release": "patch"
},
{
"type": "feat",
"release": "minor"
},
{
"type": "fix",
"release": "patch"
},
{
"type": "chore",
"release": "patch"
},
{
"type": "docs",
"release": "patch"
},
{
"type": "test",
"release": "patch"
},
{
"scope": "no-release",
"release": false
}
]
}
],
[
"@semantic-release/release-notes-generator",
{
"preset": "conventionalcommits",
"presetConfig": {
"types": [
{
"type": "feat",
"section": "Features"
},
{
"type": "fix",
"section": "Bug Fixes"
},
{
"type": "chore",
"section": "Trivial Changes"
},
{
"type": "docs",
"section": "Trivial Changes"
},
{
"type": "test",
"section": "Tests"
}
]
}
}
],
"@semantic-release/changelog",
"@semantic-release/npm",
"@semantic-release/github",
"@semantic-release/git"
]
},
"scripts": {
"test": "aegir test",
"test:browser": "aegir test --target browser",
"test:node": "aegir test --target node",
"lint": "aegir lint",
"release": "aegir release",
"release-minor": "aegir release --type minor",
"release-major": "aegir release --type major",
"build": "aegir build",
"bench": "node bench"
"dep-check": "aegir dep-check dist/src/**/*.js dist/test/**/*.js",
"build": "tsc",
"pretest": "npm run build",
"test": "aegir test -t node -f ./dist/test/*.js -f ./dist/test/**/*.js",
"test:node": "npm run test -- -t node --cov",
"release": "semantic-release -e semantic-release-monorepo"
},
"bugs": {
"url": "https://github.com/ipfs/protons/issues"
"dependencies": {
"meow": "^10.1.2",
"protobufjs": "^6.11.2"
},
"homepage": "https://github.com/ipfs/protons",
"main": "src/index.js",
"directories": {
"test": "test"
},
"keywords": [
"protobuf",
"protocol",
"buffers",
"protocolbuffers",
"encode",
"decode",
"google",
"serialize",
"parse",
"levelup",
"encodings",
"encoding"
],
"author": "Friedel Ziegelmayer <dignifiedquire@gmail.com>",
"license": "MIT",
"contributors": [
"Mathias Buus <mathiasbuus@gmail.com>",
"achingbrain <alex@achingbrain.net>",
"dignifiedquire <dignifiedquire@gmail.com>",
"David Dias <daviddias.p@gmail.com>",
"Hector Sanjuan <code@hector.link>",
"Young Hahn <young@mapbox.com>",
"Mo Kamioner <mkamioner@gmail.com>",
"tcme <hi@this-connect.me>",
"Eduardo Sorribas <eduardo@sorribas.org>",
"Hugo Dias <hugomrdias@gmail.com>",
"Lars-Magnus Skog <ralphtheninja@riseup.net>",
"Patrick Pfeiffer <patrick@buzzle.at>",
"Kevin Ennis <kennis84@gmail.com>",
"Elijah Insua <tmpvar@gmail.com>",
"Astro <astro@spaceboyz.net>",
"Andreas Madsen <amwebdk@gmail.com>",
"Sergii Shutovskyi <sergii.shutovskyi@trademob.com>",
"Steven Allen <steven@stebalien.com>",
"David Bruant <bruant.d@gmail.com>",
"Irakli Gozalishvili <contact@gozala.io>",
"João Antunes <j.goncalo.antunes@gmail.com>",
"Brendan Ward <bcward@consbio.org>"
]
"devDependencies": {
"aegir": "^36.1.3",
"long": "^4.0.0",
"pbjs": "^0.0.14",
"protons-runtime": "^1.0.0"
}
}

@@ -1,155 +0,62 @@

⛔️ DEPRECATED: This module is no longer maintained <!-- omit in toc -->
# protons <!-- omit in toc -->
[![Dependency Status](https://david-dm.org/ipfs/protons.svg?style=flat-square)](https://david-dm.org/ipfs/protons)
[![Travis CI](https://travis-ci.org/ipfs/protons.svg?branch=master)](https://travis-ci.org/ipfs/protons)
> Generate typescript from .proto files
> [Protocol Buffers](https://developers.google.com/protocol-buffers/) for Node.js and the browser without compilation.
>
> Forked from [protocol-buffers](https://github.com/mafintosh/protocol-buffers).
## Table of contents <!-- omit in toc -->
## Lead Maintainer <!-- omit in toc -->
[Alex Potsides](https://github.com/achingbrain)
## Table of Contents <!-- omit in toc -->
- [Install](#install)
- [Usage](#usage)
- [Properties](#properties)
- [Performance](#performance)
- [Leveldb encoding compatibility](#leveldb-encoding-compatibility)
- [Contribute](#contribute)
- [License](#license)
## Install
## Install
```sh
> npm install protons
```
To use this project, add `protons` as a development dependency and `protons-runtime` as a runtime dependency.
## Usage
`protons` contains the code to compile `.proto` files to `.ts` files and `protons-runtime` contains the code to do serialization/deserialization to `Uint8Array`s during application execution.
Assuming the following `test.proto` file exists
```proto
enum FOO {
BAR = 1;
}
message Test {
required float num = 1;
required string payload = 2;
}
message AnotherOne {
repeated FOO list = 1;
}
message WithOptional {
optional string payload = 1;
}
```console
$ npm install --save-dev protons
$ npm install --save protons-runtime
```
Use the above proto file to encode/decode messages by doing
## Usage
``` js
const protons = require('protons')
First generate your `.ts` files:
// pass a proto file as a buffer/string or pass a parsed protobuf-schema object
const messages = protons(fs.readFileSync('test.proto'))
const buf = messages.Test.encode({
num: 42,
payload: 'hello world'
})
console.log(buf) // should print a buffer
```console
$ protons ./path/to/foo.proto ./path/to/output.ts
```
To decode a message use `Test.decode`
Then run tsc over them as normal:
``` js
const obj = messages.Test.decode(buf)
console.log(obj) // should print an object similar to above
```console
$ tsc
```
Enums are accessed in the same way as messages
In your code import the generated classes and use them to transform to/from bytes:
``` js
const buf = messages.AnotherOne.encode({
list: [
messages.FOO.BAR
]
})
```
```js
import { Foo } from './foo.js'
Nested emums are accessed as properties on the corresponding message
const foo = {
message: 'hello world'
}
``` js
const buf = message.SomeMessage.encode({
list: [
messages.SomeMessage.NESTED_ENUM.VALUE
]
})
```
const encoded = Foo.encode(foo)
const decoded = Foo.decode(encoded)
See the [Google Protocol Buffers docs](https://developers.google.com/protocol-buffers/) for more information about the
available types etc.
## Properties
Decoded object properties can be interacted with using accessor methods:
```javascript
const obj = messages.WithOptional.decode(messages.WithOptional.encode({}))
obj.hasPayload() // false
obj.getPayload() // ''
obj.setPayload('hello world')
obj.getPayload() // 'hello world'
obj.clearPayload()
obj.getPayload() // undefined
console.info(decoded.message)
// 'hello world'
```
## Performance
## Contribute
This module is pretty fast.
Feel free to join in. All welcome. Open an [issue](https://github.com/ipfs/protons/issues)!
You can run the benchmarks yourself by doing `npm run bench`.
This repository falls under the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).
On my Macbook Pro it gives the following results
[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/contributing.md)
```
JSON (encode) x 703,160 ops/sec ±2.06% (91 runs sampled)
JSON (decode) x 619,564 ops/sec ±1.60% (94 runs sampled)
JSON (encode + decode) x 308,635 ops/sec ±1.74% (92 runs sampled)
protocol-buffers@4.1.0 (encode) x 693,570 ops/sec ±1.55% (92 runs sampled)
protocol-buffers@4.1.0 (decode) x 1,894,031 ops/sec ±1.61% (93 runs sampled)
protocol-buffers@4.1.0 (encode + decode) x 444,229 ops/sec ±1.50% (93 runs sampled)
protons@1.0.1 (encode) x 435,058 ops/sec ±1.46% (91 runs sampled)
protons@1.0.1 (decode) x 29,548 ops/sec ±3.29% (78 runs sampled)
protons@1.0.1 (encode + decode) x 27,042 ops/sec ±4.41% (80 runs sampled)
```
Note that JSON parsing/serialization in node is a native function that is *really* fast.
## Leveldb encoding compatibility
Compiled protocol buffers messages are valid levelup encodings.
This means you can pass them as `valueEncoding` and `keyEncoding`.
``` js
const level = require('level')
const db = level('db')
db.put('hello', {payload:'world'}, {valueEncoding:messages.Test}, (err) => {
db.get('hello', {valueEncoding:messages.Test}, (err, message) => {
console.log(message)
})
})
```
## License
MIT
[Apache-2.0](LICENSE-APACHE) or [MIT](LICENSE-MIT) © Protocol Labs

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc