{"_id":"protons@10.0.6","bin":{"protons":"dist/bin/protons.js"},"bugs":{"url":"https://github.com/ipfs/protons/issues"},"dist":{"shasum":"ece6d7593422becd0a6cebeaffb607a27b44d777","tarball":"http://registry-npm.ywwl.com/protons/download/protons-10.0.6.tgz","fileCount":62,"integrity":"sha512-s2siEwrCkMJ2/TuyNR8esrqHINW4QPFV1DZgRuplZur1wMJkEWws85oQvBiz/eXSL5+G+xeWjOAHeaRZt9n6vg==","signatures":[{"sig":"MEQCIBo711AWGR2oLNt2e4QLVud+XmflOaxPwiwBsouckuTgAiAcl4Gw2BrzFlf+kSc5N7InxhzA/MwnvHu4sxjvsh4sYQ==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDY1g3RWCG+qAOXUwH73FATe8E5oiE8W9ajqDkD9v7howIgFwe9BjpLSyHR+1XHXpoWiAQSigajKUx7yNlUIWhos98="}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/protons@10.0.6","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":227274,"size":43150,"noattachment":false,"key":"/protons/-/protons-10.0.6.tgz"},"name":"protons","type":"module","types":"./dist/src/index.d.ts","exports":{".":{"types":"./dist/src/index.d.ts","import":"./dist/src/index.js"}},"gitHead":"efaf9e3853665d5ff2c456cf94a1c8778525cccb","license":"Apache-2.0 OR MIT","release":{"plugins":[["@semantic-release/commit-analyzer",{"preset":"conventionalcommits","releaseRules":[{"release":"major","breaking":true},{"revert":true,"release":"patch"},{"type":"feat","release":"minor"},{"type":"fix","release":"patch"},{"type":"docs","release":"patch"},{"type":"test","release":"patch"},{"type":"deps","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":"Documentation"},{"type":"deps","section":"Dependencies"},{"type":"test","section":"Tests"}]}}],"@semantic-release/changelog","@semantic-release/npm","@semantic-release/github",["@semantic-release/git",{"assets":["CHANGELOG.md","package.json"]}]],"branches":["main"]},"scripts":{"lint":"aegir lint","test":"aegir test -t node","build":"aegir build","clean":"aegir clean","release":"aegir release","generate":"node ./dist/bin/protons.js test/fixtures/*.proto","dep-check":"aegir dep-check","test:node":"aegir test -t node --cov"},"version":"10.0.6","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"7e2427fa-ab17-4e19-b60a-3c82c4bdac42"}},"homepage":"https://github.com/ipfs/protons/tree/main/packages/protons#readme","repository":{"url":"git+https://github.com/ipfs/protons.git","type":"git"},"_npmVersion":"11.21.1","description":"Protobuf to ts transpiler","directories":{},"maintainers":[{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@ipfs.tech"}],"_nodeVersion":"24.21.0","dependencies":{"meow":"^14.1.0","protobufjs-cli":"^2.7.0","protons-runtime":"^8.0.0"},"publishConfig":{"access":"public","provenance":true},"_hasShrinkwrap":false,"devDependencies":{"long":"^5.3.2","pbjs":"^0.0.14","aegir":"^48.0.1","it-all":"^3.0.9","protobufjs":"^8.8.0","uint8arrays":"^6.0.0","uint8arraylist":"^3.0.0"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/protons_10.0.6_1792785236507_0.9464869836481928"},"readme":"# protons\n\n[![ipfs.tech](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](https://ipfs.tech)\n[![Discuss](https://img.shields.io/discourse/https/discuss.ipfs.tech/posts.svg?style=flat-square)](https://discuss.ipfs.tech)\n[![codecov](https://img.shields.io/codecov/c/github/ipfs/protons.svg?style=flat-square)](https://codecov.io/gh/ipfs/protons)\n[![CI](https://img.shields.io/github/actions/workflow/status/ipfs/protons/js-test-and-release.yml?branch=main\\&style=flat-square)](https://github.com/ipfs/protons/actions/workflows/js-test-and-release.yml?query=branch%3Amain)\n\n> Protobuf to ts transpiler\n\n# About\n\n<!--\n\n!IMPORTANT!\n\nEverything in this README between \"# About\" and \"# Install\" is automatically\ngenerated and will be overwritten the next time the doc generator is run.\n\nTo make changes to this section, please update the @packageDocumentation section\nof src/index.js or src/index.ts\n\nTo experiment with formatting, please run \"npm run docs\" from the root of this\nrepo and examine the changes made.\n\n-->\n\n`protons` is a high performance implementation of [Protocol Buffers v3](https://protobuf.dev/programming-guides/proto3/).\n\nIt transpiles code to TypeScript and supports BigInts for 64 bit types.\n\nThe `protons` module 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.\n\nPlease ensure you declare them as the correct type of dependencies:\n\n```console\n$ npm install --save-dev protons\n$ npm install --save protons-runtime\n```\n\n## Usage\n\nFirst generate your `.ts` files:\n\n```console\n$ protons ./path/to/foo.proto ./path/to/output.ts\n```\n\nThen run tsc over them as normal:\n\n```console\n$ tsc\n```\n\nIn your code import the generated classes and use them to transform to/from bytes:\n\n```js\nimport { Foo } from './foo.ts'\n\nconst foo = {\n  message: 'hello world'\n}\n\nconst encoded = Foo.encode(foo)\nconst decoded = Foo.decode(encoded)\n\nconsole.info(decoded.message)\n// 'hello world'\n```\n\n## Differences from protobuf.js\n\nThis module uses the internal reader/writer from `protobuf.js` as it is highly optimized and there's no point reinventing the wheel.\n\nIt does have one or two differences:\n\n1. Supports `proto3` semantics only\n2. All 64 bit values are represented as `BigInt`s and not `Long`s (e.g. `int64`, `uint64`, `sint64` etc)\n3. Unset `optional` fields are set on the deserialized object forms as `undefined` instead of the default values\n4. `singular` fields set to default values are not serialized and are set to default values when deserialized if not set - protobuf.js [diverges from the language guide](https://github.com/protobufjs/protobuf.js/issues/1468#issuecomment-745177012) around this feature\n5. `map` fields can have keys of any type - protobufs.js [only supports strings](https://github.com/protobufjs/protobuf.js/issues/1203#issuecomment-488637338)\n6. `map` fields are deserialized as ES6 `Map`s - protobuf.js uses `Object`s\n\n## .proto Message naming conventions\n\nProtobuf messages in `.proto` files are transformed into TypeScript classes,\nso they must not conflict with built-in JavaScript types (`Number`, `Error`,\netc).\n\nMessage names are not encoded onto the wire, only field types and ids so you\ncan name things in your `.proto` file however you like, as long as the above\nrule is respected.\n\n## Extra features\n\n### Limiting the size of repeated/map elements\n\nTo protect decoders from malicious payloads, it's possible to limit the maximum size of repeated/map elements.\n\nYou can either do this at compile time by using the [protons.options](https://github.com/protocolbuffers/protobuf/blob/6f1d88107f268b8ebdad6690d116e74c403e366e/docs/options.md?plain=1#L490-L493) extension:\n\n```\nmessage MyMessage {\n  // repeatedField cannot have more than 10 entries\n  repeated uint32 repeatedField = 1 [(protons.options).limit = 10];\n\n  // stringMap cannot have more than 10 keys\n  map<string, string> stringMap = 2 [(protons.options).limit = 10];\n}\n```\n\nOr at runtime by passing objects to the `.decode` function of your message:\n\n```TypeScript\nconst message = MyMessage.decode(buf, {\n  limits: {\n    repeatedField: 10,\n    stringMap: 10\n  }\n})\n```\n\n#### Limiting repeating fields of nested messages at runtime\n\nSub messages with repeating elements can be limited in a similar way:\n\n```\nmessage SubMessage {\n  repeated uint32 repeatedField = 1;\n}\n\nmessage MyMessage {\n  SubMessage message = 1;\n}\n```\n\n```TypeScript\nconst message = MyMessage.decode(buf, {\n  limits: {\n    messages: {\n      repeatedField: 5 // the SubMessage can not have more than 5 repeatedField entries\n    }\n  }\n})\n```\n\n#### Limiting repeating fields of repeating messages at runtime\n\nSub messages defined in repeating elements can be limited by appending `$` to the field name in the runtime limit options:\n\n```\nmessage SubMessage {\n repeated uint32 repeatedField = 1;\n}\n\nmessage MyMessage {\n  repeated SubMessage messages = 1;\n}\n```\n\n```TypeScript\nconst message = MyMessage.decode(buf, {\n  limits: {\n    messages: 5 // max 5x SubMessages\n    messages$: {\n      repeatedField: 5 // no SubMessage can have more than 5 repeatedField entries\n    }\n  }\n})\n```\n\n#### Limiting repeating fields of map entries at runtime\n\nRepeating fields in map entries can be limited by appending `$value` to the field name in the runtime limit options:\n\n```\nmessage SubMessage {\n repeated uint32 repeatedField = 1;\n}\n\nmessage MyMessage {\n  map<string, SubMessage> messages = 1;\n}\n```\n\n```TypeScript\nconst message = MyMessage.decode(buf, {\n  limits: {\n    messages: 5 // max 5x SubMessages in the map\n    messages$value: {\n      repeatedField: 5 // no SubMessage in the map can have more than 5 repeatedField entries\n    }\n  }\n})\n```\n\n### Overriding 64 bit types\n\nBy default 64 bit types are implemented as [BigInt](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt)s.\n\nSometimes this is undesirable due to [performance issues](https://betterprogramming.pub/the-downsides-of-bigints-in-javascript-6350fd807d) or code legibility.\n\nIt's possible to override the JavaScript type 64 bit fields will deserialize\nto, including repeated fields and map key/values:\n\n```\nmessage MyMessage {\n  int64 bigintField = 1;\n  int64 numberField = 2 [jstype = JS_NUMBER];\n  repeated int64 stringArray = 3 [jstype = JS_STRING];\n  map<int64, int64, bigintMap = 4 [jskeytype = JS_STRING, jsvaluetype = JS_STRING];\n}\n```\n\n```TypeScript\nconst message = MyMessage.decode(buf)\n\nconsole.info(typeof message.bigintField) // bigint\nconsole.info(typeof message.numberField) // number\nconsole.info(typeof message.stringArray[0]) // string\nconsole.info(typeof message.bigintMap.get('5')) // string\n```\n\n## Missing features\n\nSome features may be missing due to them not being needed in ipfs/libp2p so far.\n\nIf these features are important to you, please open PRs implementing them along with tests comparing the generated bytes to `protobuf.js` and `pbjs`.\n\n# Install\n\n```console\n$ npm i protons\n```\n\n# API Docs\n\n- <https://ipfs.github.io/protons/modules/protons.html>\n\n# License\n\nLicensed under either of\n\n- Apache 2.0, ([LICENSE-APACHE](https://github.com/ipfs/protons/blob/main/packages/protons/LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)\n- MIT ([LICENSE-MIT](https://github.com/ipfs/protons/blob/main/packages/protons/LICENSE-MIT) / <http://opensource.org/licenses/MIT>)\n\n# Contribute\n\nContributions welcome! Please check out [the issues](https://github.com/ipfs/protons/issues).\n\nAlso see our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general.\n\nPlease be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n\n[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)\n","publish_time":1792785236608,"_cnpm_publish_time":1792785236608,"dist-tags":{"latest":"10.0.6"}}