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.