{"_id":"@amga/protoc-gen-ts","name":"@amga/protoc-gen-ts","dist-tags":{"latest":"0.8.11"},"versions":{"0.8.11":{"name":"@amga/protoc-gen-ts","description":"Compile protocol buffers descriptors to Typescript.","version":"0.8.11","license":"MIT","author":{"name":"thesayyn","email":"thesayyn@gmail.com","url":"https://github.com/thesayyn"},"funding":{"type":"individual","url":"https://www.buymeacoffee.com/thesayyn"},"repository":{"type":"git","url":"git+https://github.com/thesayyn/protoc-gen-ts.git"},"scripts":{"test":"bazel test //...","update_checked_in":"bazel query --noshow_progress 'attr(tags, \"checked_in_update\", //...)' | xargs -n 1 bazel run --ui_event_filters=-info,-stderr --noshow_progress","update_checked_in_test":"bazel query --noshow_progress 'attr(tags, \"checked_in_update\", //test/...)' | xargs -n 1 bazel run --ui_event_filters=-info,-stderr --noshow_progress","update_checked_in_src":"bazel query --noshow_progress 'attr(tags, \"checked_in_update\", //src/...)' | xargs -n 1 bazel run --ui_event_filters=-info,-stderr --noshow_progress","release":"bazel run //:package.publish -- --access public --tag latest --registry https://registry.npmjs.org"},"bin":{"protoc-gen-ts":"bin/protoc-gen-ts.js"},"peerDependencies":{"google-protobuf":"^3.13.0","typescript":">=4"},"devDependencies":{"@bazel/bazelisk":"^1.9.0","@bazel/jasmine":"^5.0.0","@bazel/typescript":"^5.0.0","@grpc/grpc-js":"^1.3.4","@types/google-protobuf":"^3.15.5","@types/jasmine":"^3.7.7","@types/node":"^15.12.5","google-protobuf":"^3.17.3","jasmine":"^3.7.0","jasmine-core":"^3.7.1","typescript":"^4.3.4"},"gitHead":"f00521aba845803f4efae4686c5757c04962a532","bugs":{"url":"https://github.com/thesayyn/protoc-gen-ts/issues"},"homepage":"https://github.com/thesayyn/protoc-gen-ts#readme","_id":"@amga/protoc-gen-ts@0.8.11","_nodeVersion":"16.12.0","_npmVersion":"8.1.0","dist":{"integrity":"sha512-bGqHljdxinBOZ/CfWIyxIVRTpCy4LCxSBF6eZ1tp3AKOvXhIWUbDyFEoyDNXMTGVqd0O7P7Bpi3xfyG4JAu7fg==","shasum":"7071ef23a578cd2f52f410b65dc40b9ad056f1f7","tarball":"https://registry.npmjs.org/@amga/protoc-gen-ts/-/protoc-gen-ts-0.8.11.tgz","fileCount":14,"unpackedSize":298300,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIAxSbJJGviSbwkl7lL+CQN90ow52EtwtJgcEy2c1xIGbAiEA+KHX8xVNfbCjvy17lMXPbi95UVP7MInsmkPrMxj9vUM="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJivGXhACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrrlBAAo36EroQqHKRV7eDRNzGTriWF+6opc4ZHEQNcZpPYgizWzuaT\r\nYrdvElj3bAhi2KYb79Nb4sDQTZywpKb56poVIBGoDLQVYEmFKamUfDg4QYin\r\nTO6aB/g4Qg0nfEQ5DD/L0aY4dRfP5CoJLVrmjEt8Vd7vG/LwIgfOlqG7j40S\r\nxhEKNt1p6DlCZSidHZCcrAVHZe8vH5oib0N3nYcHjF1VU8g/q+9K/bzCsL6C\r\nd9fGysnKOsubkqnNDU/3wK7Clr3qLJDq4mB4JkEPIm8gytFJ5xPbVcCIu8gw\r\niyRHw+QN55pwLdAYpwuWZfFoVkgFBgA68xJpcRe07R92IfJ4oanRsj4Ek6ZC\r\nwE5UwGOFRdpDgpdhDfiHVykuss/H7Lc7ujVl1asrQt6RjmVTbRCcbi/7wIjx\r\nyIfukIB3prAcVr2EiiQ8n2c/soLwW9hy+RqDbOPB5JPxWfoi2TVhQkDaInZz\r\n0OnuUnbAk181rTxrbQP9Kgyhw+0OMS11Zn6CbBKKhNx4do3UB+9QPzGxGu/B\r\nGvGDficJpL/wgi80avAXtToC5Os8pqB3oYpb/nvRrCVRnCcH+7nVF1LeCVfg\r\nZIFiHMxZi8evonCyLFRrPjghf2faUGXo1Ki9uhMw4eiKyLrdh/kQ3KRQDjMY\r\n36GlvMWQh1Eosvp3ygV3YVvD+zTNw45WeBA=\r\n=qZC2\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"amga","email":"alfonmga@icloud.com"},"directories":{},"maintainers":[{"name":"amga","email":"alfonmga@icloud.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/protoc-gen-ts_0.8.11_1656514017757_0.8942452530045024"},"_hasShrinkwrap":false}},"time":{"created":"2022-06-29T14:46:57.697Z","0.8.11":"2022-06-29T14:46:57.956Z","modified":"2022-06-29T14:46:58.088Z"},"maintainers":[{"name":"amga","email":"alfonmga@icloud.com"}],"description":"Compile protocol buffers descriptors to Typescript.","homepage":"https://github.com/thesayyn/protoc-gen-ts#readme","repository":{"type":"git","url":"git+https://github.com/thesayyn/protoc-gen-ts.git"},"author":{"name":"thesayyn","email":"thesayyn@gmail.com","url":"https://github.com/thesayyn"},"bugs":{"url":"https://github.com/thesayyn/protoc-gen-ts/issues"},"license":"MIT","readme":"# Protoc Gen Typescript \r\n\r\n[![test](https://github.com/thesayyn/protoc-gen-ts/actions/workflows/test.yaml/badge.svg?branch=master)](https://github.com/thesayyn/protoc-gen-ts/actions/workflows/test.yaml)\r\n[![npm](https://img.shields.io/npm/v/protoc-gen-ts)](https://www.npmjs.com/package/protoc-gen-ts?activeTab=versions)\r\n[![npm](https://img.shields.io/npm/dm/protoc-gen-ts)](https://www.npmjs.com/package/protoc-gen-ts?activeTab=versions)\r\n[![npm](https://opencollective.com/protoc-gen-ts/tiers/backer/badge.svg?label=Backer&color=brightgreen)](https://opencollective.com/protoc-gen-ts)\r\n\r\nAim of this protoc plugin is to make usage of protocol buffers easy in Javascript/Typescript by taking a modern approach. \r\nThis plugin generates plain **TypeScript** sources that can be used in ESM, AMD, UMD, and CommonJS module system.\r\n\r\n## Key Differences\r\n\r\n- No `d.ts` files. Just plain typescript sources with actual code.\r\n- Fields as **getter** **setters**.\r\n- Enums as **enums**.\r\n- Messages within a **namespace** if the proto has a **package** directive. (can be controlled via --ts_opt=no_namespace)\r\n- **fromObject** and **toObject** methods to work with json data.\r\n- Support for gRPC Node and gRPC Web (Work-in-progress) [#102](https://github.com/thesayyn/protoc-gen-ts/pull/102)\r\n- You get what you define in proto files. No such prefixes as \"getField\" or \"getFieldList\".\r\n- Generates bindings with either as-is names (`message.field_name`) or JSON-compatible names (`message.fieldName`).\r\n\r\n## Example\r\n\r\n```proto\r\nsyntax = \"proto3\";\r\n\r\nmessage Author {\r\n    string name = 1;\r\n    string role = 2;\r\n}\r\n\r\nmessage Change {\r\n    Kind kind = 1;\r\n    string patch = 2;\r\n    repeated string tags = 3; \r\n    oneof name_or_id {\r\n        string name = 4;\r\n        string id = 5;\r\n    }\r\n    Author author = 6;\r\n}\r\n\r\nenum Kind {\r\n    UPDATED = 0;\r\n    DELETED = 1;\r\n}\r\n```\r\n\r\n\r\n```typescript\r\n// Constructed message\r\nconst change = new Change({\r\n    kind: Kind.UPDATED,\r\n    patch: \"@@ -7,11 +7,15 @@\",\r\n    tags: [\"no prefix\", \"as is\"],\r\n    name: \"patch for typescript 4.5\",\r\n    author: new Author({\r\n        name: \"mary poppins\",\r\n        role: \"maintainer\"\r\n    })\r\n});\r\n\r\n// Sent over the wire\r\nconst bytes: Uint8Array = change.serialize();\r\n\r\nconst receivedChange: Change = Change.deserialize(bytes);\r\n\r\nconsole.log(receivedChange.kind == Kind.UPDATED) // true\r\nconsole.log(receivedChange.patch) // \"@@ -7,11 +7,15 @@\"\r\nconsole.log(receivedChange.tags) // [\"no prefix\", \"as is\"]\r\nconsole.log(receivedChange.name) // \"patch for typescript 4.5\"\r\n// see which one of the fields were filled\r\nconsole.log(receivedChange.name_or_id) // \"name\"\r\nconsole.log(receivedChange.author.name) // \"mary poppins\"\r\n```\r\n\r\n## Support for Message.fromObject and Message.toObject\r\n\r\nWhen mapping raw json data to message classes, dealing with nested structures can be rather annoying.\r\nTo overcome this problem, every generated message class has a static method called `fromObject` and `toObject` \r\nwhich can handle the mapping bidirectionally for you, even with the deeply structured messages. since it is \r\naware of the field graph, it does not rely on any runtime type information thus we get the chance to keep it fast.\r\n\r\nOne can write code as;\r\n\r\n```typescript\r\nconst change = Change.fromObject({\r\n    kind: Kind.UPDATED,\r\n    patch: \"@@ -7,11 +7,15 @@\",\r\n    tags: [\"no prefix\", \"as is\"],\r\n    name: \"patch for typescript 4.5\",\r\n    author: {\r\n        name: \"mary poppins\",\r\n        role: \"maintainer\"\r\n    }\r\n});\r\n\r\nconsole.log(change.author instanceof Author) // true\r\n```\r\n\r\n\r\n## Usage with `@grpc/grpc-js` or `grpc`\r\n\r\nThere is a seperate documentation for the usage of protoc-gen-ts along with either `@grpc/grpc-js` or `grpc`.  By default\r\nthis generated gRPC interfaces will use `@grpc/grpc-js`.\r\n\r\nCheckout [rpcs](docs/rpc.md).\r\n\r\n## Usage\r\n\r\n### Without Bazel\r\n```properties\r\nnpm install -g protoc-gen-ts\r\n\r\nprotoc -I=sourcedir --ts_out=dist myproto.proto\r\n```\r\n### With Bazel\r\n```py\r\n# Add protoc-gen-ts to dependencies section of your package.json file.\r\n\r\nload(\"@npm//protoc-gen-ts:index.bzl\", \"ts_proto_library\")\r\n\r\nts_proto_library(\r\n    name = \"protos\",\r\n    deps = [\r\n        \":some_proto_library_target\"\r\n    ]\r\n)\r\n\r\n# Checkout the examples/bazel directory for an example.\r\n```\r\n\r\n## Supported Options\r\n\r\n* With `--ts_opt=unary_rpc_promise=true`, the service definition will contain a promise based rpc with a calling pattern of `const result = await client.METHOD(message)`.  Note: all of the `metadata` and `options` parameters are still available to you.\r\n\r\n* With `--ts_opt=grpc_package=xxxx`, you can specify a different package to import rather than `@grpc/grpc-js`.\r\n\r\n* With `--ts_opt=no_namespace`, you can control whether you get nested messages inside namespaces or prefixed with their parent message or directive.\r\n\r\n* With `--ts_opt=json_names`, fields will be converted to lowerCamelCase, for compatibility with the [JSON mapping][] done by the first-party protobuf libraries.\r\n\r\n[JSON mapping]: https://developers.google.com/protocol-buffers/docs/proto3#json\r\n\r\n* With `--ts_opt=explicit_override`, inherited methods are generated with `override` modifier, this fixes transpilation error when `noImplicitOverride` is enabled.\r\n\r\n## Support\r\n\r\nWe need your constant support to keep protoc-gen-ts well maintained and add new features.\r\n\r\nIf your corporate has a OSS funding scheme, please consider supporting us monthly through open collective.\r\n\r\n<a href=\"https://opencollective.com/protoc-gen-ts\">\r\n<img height=\"100px\" src=\"https://opencollective.com/protoc-gen-ts/tiers/backer.svg?avatarHeight=36\">\r\n</a>\r\n\r\n## Roadmap\r\n\r\n- <s>Support for repeated non-integer fields</s>\r\n- <s>Generate appropriate service code that is usable with node **grpc** package.</s>\r\n- <s>Support for creating protocol buffer messages directly from their constructors with an object.</s>\r\n- <s>Support for `import` directive.</s>\r\n- <s>Support for `Promise` in rpcs.</s>\r\n- <s>Make services strongly typed.</s>\r\n- <s>Support oneof fields</s>\r\n- <s>Support `map<TYPE, TYPE>` types as ES `Map`.</s>\r\n- <s>Support for `@deprecated` annotations via deprecated option.</s>\r\n- Support for grpc-web without any manual intervention.\r\n- Interopability with well knowns.\r\n\r\n\r\n## Alternatives\r\n\r\n| Plugin | google-protobuf | Typescript | Declarations | gRPC Node | gRPC Web | ES6 Support | Notes |\r\n|------------------------------|-----------------|:----------:|:------------:|:---------:|:--------:|:-----------:|:-----------------------------------------------------------------------------------------------------------------------------------:|\r\n| thesayyn/protoc-gen-ts | Yes | Yes | Yes | Yes | Partial | Yes | The generated messages are compatible with ever-green browsers.<br>However, you might need to use third-party packages to use rpcs. |\r\n| improbable-eng/ts-protoc-gen | Yes | No | Yes | No | Yes | Partial | Drawback: You can't bundle generated files with rollup since<br>they are not >= ES6 compatible. |\r\n| stephenh/ts-proto | No | Yes | Yes | No | No | Yes | There is no support for rpcs.<br>See: https://github.com/stephenh/ts-proto/issues/2 |\r\n\r\n\r\n## Development\r\n\r\nGenerates appropriate Protocol Buffer sources from Proto files directly through _TypeScript Compiler API_.\r\n\r\n```sh\r\n# when you make changes to the plugin, you will have to run the command below\r\nyarn update_checked_in_test\r\n# this command will run the plugin with your changes and update generated test source accordingly.\r\n\r\n# then invoke the tests\r\nyarn test\r\n# additionally if you want to see error details\r\nyarn test --test_output=errors\r\n```\r\n\r\n## Contributors\r\n\r\n![GitHub Contributors Image](https://contrib.rocks/image?repo=thesayyn/protoc-gen-ts)\r\n","readmeFilename":"README.md"}