A TypeScript validation library for Protobuf messages using Spine Validation options, built on @bufbuild/protobuf (Protobuf-ES v2).
π§ This library is in its experimental stage, the public API should not be considered stable.
This library lets you:
- β Reuse the same validation rules in your frontend that you defined in your backend.
- β
Maintain a single source of truth β validation logic lives in your
.protofiles. - β Keep frontend and backend validation in sync automatically.
- β Get type-safe validation with full TypeScript support.
- β Display the same error messages to users that your backend generates.
Even if you're not using Spine Event Engine, this library provides a powerful way to add runtime validation to your Protobuf-based TypeScript applications:
- β
Define validation in
.protofiles using declarative Spine Validation options. - β Type-safe, runtime validation for your Protobuf messages.
- β Clear, customizable error messages for better UX.
- β Works with Protobuf-ES v2 and modern tooling.
- β Extensible architecture for custom validation logic.
Comprehensive Validation Support
(required)β Ensure fields have non-default values.(pattern)β Regex validation for strings.(min)/(max)β Numeric bounds with inclusive/exclusive support.(range)β Bounded ranges with bracket notation(min..max].(distinct)β Enforce uniqueness in repeated fields.(validate)β Recursive nested message validation.(goes)β Field dependency constraints.(require)β Complex required field combinations with boolean logic.(choice)β Require that aoneofgroup has at least one field set.
Developer Experience
- π Full TypeScript type safety.
- π Custom error messages.
- π§ͺ 200+ comprehensive tests.
- π Extensive documentation.
- π¨ Clean, readable error formatting.
(set_once)β Not currently supported. This option requires state tracking across multiple validations, which is outside the scope of single-message validation.
See the package-level README for complete installation instructions and usage guide.
Quick install:
npm install @spine-event-engine/validation-ts@snapshot @bufbuild/protobufThis repository is structured as an npm workspace:
validation-ts/
βββ packages/
β βββ spine-validation-ts/ # π¦ Main validation package
β β βββ src/ # Source code
β β βββ tests/ # 200+ comprehensive tests
β β βββ proto/ # Spine validation proto definitions
β β βββ README.md # Full package documentation
β β
β βββ example/ # π― Example project
β βββ proto/ # Example proto files
β βββ src/ # Example usage code
β βββ README.md # Example documentation
β
βββ README.md # You are here
See the package-level README for more details.
# Clone the repository
git clone <repository-url>
cd validation-ts
# Install dependencies
npm install# Build the validation package
npm run build
# Run all tests
npm test
# Run the example project
npm run example| Command | Description |
|---|---|
npm run build |
Build the validation package |
npm test |
Run all validation tests |
npm run example |
Run the example project |
Contributions are welcome! Please ensure:
- All tests pass:
npm test - Code follows existing patterns
- New features include tests
- Documentation is updated
Apache 2.0.
- Protobuf-ES β Protocol Buffers for ECMAScript
- Buf β Modern Protobuf tooling
Made with β€οΈ for the Spine Event Engine ecosystem.
Documentation Β· Examples Β· Report Bug