{"id":29142390,"url":"https://github.com/bufbuild/protovalidate-es","last_synced_at":"2025-06-30T19:37:36.410Z","repository":{"id":291097505,"uuid":"974374823","full_name":"bufbuild/protovalidate-es","owner":"bufbuild","description":"Protocol Buffer Validation for ECMAScript","archived":false,"fork":false,"pushed_at":"2025-06-24T17:11:55.000Z","size":1743,"stargazers_count":43,"open_issues_count":2,"forks_count":1,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-06-24T18:27:04.774Z","etag":null,"topics":["cel","common-expression-language","javascript","protobuf","protocol-buffers","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bufbuild.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","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-04-28T17:19:16.000Z","updated_at":"2025-06-24T17:11:57.000Z","dependencies_parsed_at":"2025-05-02T12:22:57.747Z","dependency_job_id":"de61faa7-a8e3-4f03-9414-a371c5d27610","html_url":"https://github.com/bufbuild/protovalidate-es","commit_stats":null,"previous_names":["bufbuild/protovalidate-es"],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/bufbuild/protovalidate-es","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bufbuild%2Fprotovalidate-es","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bufbuild%2Fprotovalidate-es/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bufbuild%2Fprotovalidate-es/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bufbuild%2Fprotovalidate-es/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bufbuild","download_url":"https://codeload.github.com/bufbuild/protovalidate-es/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bufbuild%2Fprotovalidate-es/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262324995,"owners_count":23293757,"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":["cel","common-expression-language","javascript","protobuf","protocol-buffers","typescript"],"created_at":"2025-06-30T19:37:28.872Z","updated_at":"2025-06-30T19:37:36.393Z","avatar_url":"https://github.com/bufbuild.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"[![The Buf logo](.github/buf-logo.svg)][buf]\n\n# protovalidate-es\n\n[![License](https://img.shields.io/github/license/bufbuild/cel-es?color=blue)](./LICENSE) [![NPM Version](https://img.shields.io/npm/v/@bufbuild/protovalidate/latest?color=green\u0026label=%40bufbuild%2Fprotovalidate)](https://www.npmjs.com/package/@bufbuild/protovalidate)\n\n[Protovalidate][protovalidate] provides standard annotations to validate common rules on messages and fields, as well as the ability to use [CEL][cel] to write custom rules. It's the next generation of [protoc-gen-validate][protoc-gen-validate], the only widely used validation library for Protobuf.\n\nWith Protovalidate, you can annotate your Protobuf messages with both standard and custom validation rules:\n\n```protobuf\nsyntax = \"proto3\";\n\npackage banking.v1;\n\nimport \"buf/validate/validate.proto\";\n\nmessage MoneyTransfer {\n  string to_account_id = 1 [\n    // Standard rule: `to_account_id` must be a UUID.\n    (buf.validate.field).string.uuid = true\n  ];\n\n  string from_account_id = 2 [\n    // Standard rule: `from_account_id` must be a UUID.\n    (buf.validate.field).string.uuid = true\n  ];\n\n  // Custom rule: `to_account_id` and `from_account_id` can't be the same.\n  option (buf.validate.message).cel = {\n    id: \"to_account_id.not.from_account_id\"\n    message: \"to_account_id and from_account_id should not be the same value\"\n    expression: \"this.to_account_id != this.from_account_id\"\n  };\n}\n```\n\nOnce you've added `@bufbuild/protovalidate` to your project, validation is simple:\n\n```ts\nimport { create } from \"@bufbuild/protobuf\";\nimport { createValidator } from \"@bufbuild/protovalidate\";\nimport { MoneyTransferSchema } from \"./gen/banking_pb\";\n\nconst transfer = create(MoneyTransferSchema);\n\nconst validator = createValidator();\nconst result = validator.validate(MoneyTransferSchema, transfer);\nif (result.kind !== \"valid\") {\n  // Handle failure.\n}\n```\n\n\u003e [!TIP]\n\u003e \n\u003e The `string.pattern` rule supports regular expressions with CEL's standard [RE2 syntax](https://github.com/google/re2/wiki/syntax). \n\u003e \n\u003e Protovalidate translates RE2 to ECMAScript's regular expressions. This works except for some RE2 flags, but it cannot support RE2's most important property: Execution in linear time, which guards against [ReDoS](https://owasp.org/www-community/attacks/Regular_expression_Denial_of_Service_-_ReDoS).\n\u003e\n\u003e If you need full support for RE2, you can bring your own RE2 implementation:\n\u003e \n\u003e ```ts\n\u003e const validator = createValidator({\n\u003e   regexMatch: (pattern: string, against: string): boolean =\u003e new RE2(pattern).test(against),\n\u003e });\n\u003e ```\n\n\n## Packages\n\n- [@bufbuild/protovalidate](https://www.npmjs.com/package/@bufbuild/protovalidate):\n  Validates Protobuf messages at runtime based on user-defined validation rules.\n\nNote that protovalidate-es requires the Protobuf runtime [@bufbuild/protobuf](https://www.npmjs.com/package/@bufbuild/protobuf).\n\n\n## Additional Languages and Repositories\n\nProtovalidate isn't just for ECMAScript! You might be interested in sibling repositories for other languages:\n\n- [`protovalidate-go`][pv-go] (Go)\n- [`protovalidate-java`][pv-java] (Java)\n- [`protovalidate-python`][pv-python] (Python)\n- [`protovalidate-cc`][pv-cc] (C++)\n\nAdditionally, [protovalidate's core repository](https://github.com/bufbuild/protovalidate) provides:\n\n- [Protovalidate's Protobuf API][validate-proto]\n- [Example][examples] `.proto` files using `protovalidate`\n- [Conformance testing utilities][conformance] for acceptance testing of `protovalidate` implementations\n\n## Contribution\n\nWe genuinely appreciate any help! If you'd like to contribute, check out these resources:\n\n- [Contributing Guidelines][contributing]: Guidelines to make your contribution process straightforward and meaningful\n- [Conformance testing utilities](https://github.com/bufbuild/protovalidate/tree/main/docs/conformance.md): Utilities providing acceptance testing of `protovalidate` implementations\n- [Protovalidate-ES conformance executor][conformance-executable]: Conformance testing executor\n\n## Related Sites\n\n- [Buf][buf]: Enterprise-grade Kafka and gRPC for the modern age\n- [Common Expression Language (CEL)][cel]: The open-source technology at the core of Protovalidate\n\n## Legal\n\nOffered under the [Apache 2 license][license].\n\n[buf]: https://buf.build\n[cel]: https://cel.dev\n[pv-go]: https://github.com/bufbuild/protovalidate-go\n[pv-java]: https://github.com/bufbuild/protovalidate-java\n[pv-python]: https://github.com/bufbuild/protovalidate-python\n[pv-cc]: https://github.com/bufbuild/protovalidate-cc\n[license]: LICENSE\n[contributing]: .github/CONTRIBUTING.md\n[protoc-gen-validate]: https://github.com/bufbuild/protoc-gen-validate\n[protovalidate]: https://buf.build/docs/protovalidate\n[quickstart]: https://buf.build/docs/protovalidate/quickstart/\n[conformance-executable]: ./packages/protovalidate-testing/README.md\n[validate-proto]: https://buf.build/bufbuild/protovalidate/docs/main:buf.validate\n[conformance]: https://github.com/bufbuild/protovalidate/blob/main/docs/conformance.md\n[examples]: https://github.com/bufbuild/protovalidate/tree/main/examples\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbufbuild%2Fprotovalidate-es","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbufbuild%2Fprotovalidate-es","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbufbuild%2Fprotovalidate-es/lists"}