{"id":25854637,"url":"https://github.com/ilyhalight/elysia-protobuf","last_synced_at":"2026-06-20T20:31:34.316Z","repository":{"id":280035747,"uuid":"940825759","full_name":"ilyhalight/elysia-protobuf","owner":"ilyhalight","description":"Easy support protobuf integration for Elysia","archived":false,"fork":false,"pushed_at":"2025-06-13T00:21:15.000Z","size":109,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-11-24T01:16:59.536Z","etag":null,"topics":["elysia","protobuf"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ilyhalight.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-02-28T21:36:04.000Z","updated_at":"2025-11-10T15:32:53.000Z","dependencies_parsed_at":"2025-05-22T11:03:27.257Z","dependency_job_id":null,"html_url":"https://github.com/ilyhalight/elysia-protobuf","commit_stats":null,"previous_names":["ilyhalight/elysia-protobuf"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ilyhalight/elysia-protobuf","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ilyhalight%2Felysia-protobuf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ilyhalight%2Felysia-protobuf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ilyhalight%2Felysia-protobuf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ilyhalight%2Felysia-protobuf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ilyhalight","download_url":"https://codeload.github.com/ilyhalight/elysia-protobuf/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ilyhalight%2Felysia-protobuf/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34585195,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-20T02:00:06.407Z","response_time":98,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["elysia","protobuf"],"created_at":"2025-03-01T16:17:13.998Z","updated_at":"2026-06-20T20:31:34.310Z","avatar_url":"https://github.com/ilyhalight.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# elysia-protobuf\n\nEasy support protobuf integration for Elysia. To decode/encode we use [@bufbuild/protobuf](https://github.com/bufbuild/protobuf-es) lib and schemas generated by [ts-proto](https://github.com/stephenh/ts-proto)\n\n## Install\n\n```bash\nbun install elysia-protobuf\n```\n\n## Before starting\n\nLib is incompatible with default elysia body/response validation! Don't mix it with `parse: \"protobuf\"`!\n\n## Usage\n\n**✅ Do**: Use requestSchema field and import decode from context\n\n```ts\nimport Elysia from \"elysia\";\nimport {\n  protobuf,\n  ProtoRequestError,\n  ProtoResponseError,\n} from \"elysia-protobuf\";\nimport {\n  RequestMessage,\n  ResponseMessage,\n  ResponseStatus,\n} from \"./proto/message\";\n\nconst app = new Elysia()\n  .use(\n    protobuf({\n      schemas: {\n        \"post.request\": RequestMessage,\n        \"post.response\": ResponseMessage,\n      },\n      // (optional) verify body with signature\n      signature: {\n        enabled: true,\n        secret: \"test123\",\n        headerName: \"x-signature\",\n      },\n    }),\n  )\n  .post(\n    \"/post\",\n    async ({ body, decode, headers }) =\u003e {\n      // decode uint8array with your schema\n      const data = await decode(\"post.request\", body, headers);\n      console.log(data);\n      return {\n        status: ResponseStatus.SOME,\n        inlineTags: data.tags.join(\", \"),\n      };\n    },\n    {\n      // parse body as arrayBuffer -\u003e Uint8Array\n      parse: \"protobuf\",\n      // encode response with protobuf schema\n      responseSchema: \"post.response\",\n    },\n  )\n  .listen(3000);\n```\n\n**❌ Don't**: Use default body/response elysia validation with `parse: \"protobuf\"`\n\n```ts\n// ...\nconst app = new Elysia()\n  .use(\n    protobuf({\n      schemas: {\n        \"post.request\": RequestMessage,\n        \"post.response\": ResponseMessage,\n      },\n    }),\n  )\n  .post(\n    \"/post\",\n    async ({ body, decode }) =\u003e {\n      // decode uint8array with your schema\n      const data = await decode(\"post.request\", body);\n      console.log(data);\n      return {\n        status: ResponseStatus.SOME,\n        inlineTags: data.tags.join(\", \"),\n      };\n    },\n    {\n      parse: \"protobuf\",\n      responseSchema: \"post.response\",\n      // ! ❌ INCOMPATIBLE with `parse: \"protobuf\"`\n      //   body: t.Object({\n      //     title: t.String(),\n      //     updatedAt: t.Optional(t.Number()),\n      //     tags: t.Array(t.String()),\n      //   }),\n      // Doubtful But Okay\n      // body: t.Uint8Array(),\n    },\n  )\n  .post(\n    \"/json\",\n    ({ body }) =\u003e {\n      return body;\n    },\n    {\n      // OK if parse mode isn't protobuf\n      body: t.Object({\n        title: t.String(),\n        updatedAt: t.Optional(t.Number()),\n        tags: t.Array(t.String()),\n      }),\n    },\n  )\n  .listen(3000);\n```\n\nYou can handle plugin errors with onError event\n\n```ts\nimport { protobuf, ProtoRequestError, ProtoResponseError } from \"../../src\";\n// ...\n\nconst app = new Elysia()\n  .use(\n    protobuf({\n      schemas: {\n        \"post.request\": RequestMessage,\n        \"post.response\": ResponseMessage,\n      },\n    }),\n  )\n  .error({\n    PROTO_RESPONSE_ERROR: ProtoResponseError,\n    PROTO_REQUEST_ERROR: ProtoRequestError,\n  })\n  .onError(({ code, error, set }) =\u003e {\n    // something like that\n    switch (code) {\n      case \"PROTO_REQUEST_ERROR\": {\n        set.status = 400;\n        break;\n      }\n      case \"PROTO_RESPONSE_ERROR\": {\n        set.status = 500;\n        break;\n      }\n    }\n\n    return {\n      message: (error as Error).message,\n    };\n  });\n// ...\n```\n\nYou can only parse protobuf body as `Uint8Array` with use only `protobufParser`\n\n```ts\nimport { protobufParser } from \"../src\";\n\nconst app = new Elysia().use(protobufParser()).post(\"/a\", ({ body }) =\u003e body, {\n  parse: \"protobuf\",\n});\n```\n\n### Create protobuf schema:\n\n1. Install [protoc](https://github.com/protocolbuffers/protobuf/releases)\n2. Install [ts-proto](https://github.com/stephenh/ts-proto) package\n3. Convert `.proto` to `.ts` with ts-proto (see [example](./example/) for details):\n\n```bash\nprotoc --plugin=.\\\\node_modules\\\\.bin\\\\protoc-gen-ts_proto --ts_proto_opt=esModuleInterop=true --ts_proto_opt=importSuffix=.js --ts_proto_out=./src ./proto/*.proto\n```\n\n4. Import schemas from `./src/proto/YOUR_FILE.ts`\n\n## Options\n\n| Key       | Type      | Default   | Description        |\n| --------- | --------- | --------- | ------------------ |\n| schemas   | Schemas   | {}        | key - proto schema |\n| signature | Signature | undefined | signature settings |\n\n```ts\nnew Elysia().use(\n  protobuf({\n    schemas: {\n      // any string key: proto schema\n      \"post.request\": RequestMessage,\n      \"post.response\": ResponseMessage,\n    },\n    signature: {\n      // disabled by default\n      enabled: true,\n      secret: \"changeme\",\n      headerName: \"x-signature\",\n    },\n  }),\n);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Filyhalight%2Felysia-protobuf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Filyhalight%2Felysia-protobuf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Filyhalight%2Felysia-protobuf/lists"}