{"id":13782391,"url":"https://github.com/meketh/parcel-plugin-pbf-ts","last_synced_at":"2026-05-05T04:36:06.525Z","repository":{"id":57319066,"uuid":"296491645","full_name":"Meketh/parcel-plugin-pbf-ts","owner":"Meketh","description":"Protocol Buffers support in Parcel via Pbf with Typescript","archived":false,"fork":false,"pushed_at":"2020-09-19T03:51:31.000Z","size":95,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-11T18:54:42.930Z","etag":null,"topics":["binary","decode","encode","format","parcel-bundler","parceljs","protobuf","protocol-buffers","serialization","typescript"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Meketh.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-09-18T02:22:01.000Z","updated_at":"2020-09-19T03:50:55.000Z","dependencies_parsed_at":"2022-08-25T20:40:13.405Z","dependency_job_id":null,"html_url":"https://github.com/Meketh/parcel-plugin-pbf-ts","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Meketh%2Fparcel-plugin-pbf-ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Meketh%2Fparcel-plugin-pbf-ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Meketh%2Fparcel-plugin-pbf-ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Meketh%2Fparcel-plugin-pbf-ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Meketh","download_url":"https://codeload.github.com/Meketh/parcel-plugin-pbf-ts/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244094273,"owners_count":20397020,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["binary","decode","encode","format","parcel-bundler","parceljs","protobuf","protocol-buffers","serialization","typescript"],"created_at":"2024-08-03T18:01:36.193Z","updated_at":"2026-05-05T04:36:06.459Z","avatar_url":"https://github.com/Meketh.png","language":"JavaScript","funding_links":[],"categories":["Plugins"],"sub_categories":["Templates"],"readme":"# parcel-plugin-pbf-ts\n\n[Protocol Buffers](https://developers.google.com/protocol-buffers/) support in [Parcel](https://parceljs.org/) via [Pbf](https://npmjs.com/package/pbf) with [Typescript](https://www.typescriptlang.org/)\n\nInspired by [parcel-plugin-pbf](https://github.com/jabher/parcel-plugin-pbf) with some diferencies\n\n- Declares missing types\n- Generates types for your `.proto` on bundle\n- Imports `.protos` as a string and compile them in runtime\n- Adds extra functionality to the proto `factories`\n- Lets you extend your `messages` to add custom `methods` or `constructor` (init)\n\n## How to install\n\n```shell\nyarn add parcel-plugin-pbf-ts\n# or\nnpm install parcel-plugin-pbf-ts\n```\n\nParcel will detect `parcel-plugin-pbf-ts` and bundle your `.proto` files.\n\n## How to use\n\nYou can `import` the `.proto` files from different `.ts` files but you need to compile them somewhere.\n\nYou can have multiple `roots` but the bundler will define everything under the namespace `Proto.Root`, be aware of that.\n\n### Example:\n\n```\nproject/\n|-protos/\n  |-Some.proto\n  |-Other.proto\n  |-Moar.proto\n  |-index.ts \u003c-- Root\n  |-index.d.ts \u003c-- extension definitions\n```\n\n#### project/protos/index.ts\n\n```ts\n/// \u003creference types='parcel-plugin-pbf-ts' /\u003e\n/// \u003creference types='./' /\u003e\nimport { makeRoot, extend } from \"parcel-plugin-pbf-ts/utils\";\nimport Some from \"./Some.proto\";\nimport Other from \"./Other.proto\";\n\nconst root = makeRoot(Some, Other);\nroot.Some.init = (o) =\u003e (o.magicNumber = 42);\nextend(root.Some, {\n  print() {\n    console.log({ text: this.text });\n    return this.text;\n  },\n});\n\nexport = root;\n```\n\n#### project/protos/index.d.ts\n\n```ts\nnamespace Proto.Root {\n  interface Some {\n    magicNumber: number;\n    print(): string;\n  }\n}\n```\n\n#### project/protos/Some.proto\n\n```protobuf\nsyntax = \"proto3\";\n\nmessage Some {\n  string text = 1;\n}\n```\n\n## API\n\nTypes are under `@types/` folder in the module.\n\nThe compiled objects from `makeRoot` are a little different from the ones in `Pbf`. In fact they are `factory` functions.\n\nThanks to that you can do the following:\n\n```ts\nimport { ok, strictEqual, deepStrictEqual } from \"assert\";\nimport Protos from \"./protos\";\nconst { Some } = Protos;\n\nconst text = Math.random().toString(16).slice(2);\nconst some = new Some({ text });\nok(some instanceof Some);\nstrictEqual(some.magicNumber, 42);\nstrictEqual(some.print(), text); // logs text\n\nconst bin = some.encode();\nok(bin instanceof Uint8Array);\ndeepStrictEqual(bin, Some.encode(some));\ndeepStrictEqual(some, Some.decode(bin));\ndeepStrictEqual(some, Some(bin));\n```\n\nInternally `encode` reuses the same `Pbf` instance for better performance.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmeketh%2Fparcel-plugin-pbf-ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmeketh%2Fparcel-plugin-pbf-ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmeketh%2Fparcel-plugin-pbf-ts/lists"}