Comparing version 2.0.3 to 3.0.0
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" | ||
} | ||
} |
155
README.md
@@ -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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
2
4
Yes
27042
9
1
80
458
1
63
1
+ Addedmeow@^10.1.2
+ Addedprotobufjs@^6.11.2
+ Added@babel/code-frame@7.25.7(transitive)
+ Added@babel/helper-validator-identifier@7.25.7(transitive)
+ Added@babel/highlight@7.25.7(transitive)
+ Added@protobufjs/aspromise@1.1.2(transitive)
+ Added@protobufjs/base64@1.1.2(transitive)
+ Added@protobufjs/codegen@2.0.4(transitive)
+ Added@protobufjs/eventemitter@1.1.0(transitive)
+ Added@protobufjs/fetch@1.1.0(transitive)
+ Added@protobufjs/float@1.0.2(transitive)
+ Added@protobufjs/inquire@1.1.0(transitive)
+ Added@protobufjs/path@1.1.2(transitive)
+ Added@protobufjs/pool@1.1.0(transitive)
+ Added@protobufjs/utf8@1.1.0(transitive)
+ Added@types/long@4.0.2(transitive)
+ Added@types/minimist@1.2.5(transitive)
+ Added@types/node@22.7.4(transitive)
+ Added@types/normalize-package-data@2.4.4(transitive)
+ Addedansi-styles@3.2.1(transitive)
+ Addedarrify@1.0.1(transitive)
+ Addedcamelcase@6.3.0(transitive)
+ Addedcamelcase-keys@7.0.2(transitive)
+ Addedchalk@2.4.2(transitive)
+ Addedcolor-convert@1.9.3(transitive)
+ Addedcolor-name@1.1.3(transitive)
+ Addeddecamelize@1.2.05.0.1(transitive)
+ Addeddecamelize-keys@1.1.1(transitive)
+ Addederror-ex@1.3.2(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedfind-up@5.0.0(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedhard-rejection@2.1.0(transitive)
+ Addedhas-flag@3.0.0(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedhosted-git-info@4.1.0(transitive)
+ Addedindent-string@5.0.0(transitive)
+ Addedis-arrayish@0.2.1(transitive)
+ Addedis-core-module@2.15.1(transitive)
+ Addedis-plain-obj@1.1.0(transitive)
+ Addedjs-tokens@4.0.0(transitive)
+ Addedjson-parse-even-better-errors@2.3.1(transitive)
+ Addedkind-of@6.0.3(transitive)
+ Addedlines-and-columns@1.2.4(transitive)
+ Addedlocate-path@6.0.0(transitive)
+ Addedlong@4.0.0(transitive)
+ Addedlru-cache@6.0.0(transitive)
+ Addedmap-obj@1.0.14.3.0(transitive)
+ Addedmeow@10.1.5(transitive)
+ Addedmin-indent@1.0.1(transitive)
+ Addedminimist-options@4.1.0(transitive)
+ Addednormalize-package-data@3.0.3(transitive)
+ Addedp-limit@3.1.0(transitive)
+ Addedp-locate@5.0.0(transitive)
+ Addedparse-json@5.2.0(transitive)
+ Addedpath-exists@4.0.0(transitive)
+ Addedpicocolors@1.1.0(transitive)
+ Addedprotobufjs@6.11.4(transitive)
+ Addedquick-lru@5.1.1(transitive)
+ Addedread-pkg@6.0.0(transitive)
+ Addedread-pkg-up@8.0.0(transitive)
+ Addedredent@4.0.0(transitive)
+ Addedsemver@7.6.3(transitive)
+ Addedspdx-correct@3.2.0(transitive)
+ Addedspdx-exceptions@2.5.0(transitive)
+ Addedspdx-expression-parse@3.0.1(transitive)
+ Addedspdx-license-ids@3.0.20(transitive)
+ Addedstrip-indent@4.0.0(transitive)
+ Addedsupports-color@5.5.0(transitive)
+ Addedtrim-newlines@4.1.1(transitive)
+ Addedtype-fest@1.4.0(transitive)
+ Addedundici-types@6.19.8(transitive)
+ Addedvalidate-npm-package-license@3.0.4(transitive)
+ Addedyallist@4.0.0(transitive)
+ Addedyargs-parser@20.2.9(transitive)
+ Addedyocto-queue@0.1.0(transitive)
- Removedprotocol-buffers-schema@^3.3.1
- Removedsigned-varint@^2.0.1
- Removeduint8arrays@^3.0.0
- Removedvarint@^5.0.0
- Removedmultiformats@9.9.0(transitive)
- Removedprotocol-buffers-schema@3.6.0(transitive)
- Removedsigned-varint@2.0.1(transitive)
- Removeduint8arrays@3.1.1(transitive)
- Removedvarint@5.0.2(transitive)