domainstack-wasm
WASM browser validation for domainstack. Run the same validation logic in both browser and server.
Quick Start
# Build WASM package
import init from '@domainstack/wasm';
// Initialize WASM module
await ;
// Create validator instance
const validator = ;
// Validate data
const result = validator.;
if
Why WASM?
- Zero drift — Same Rust validation code runs in browser and server
- Type safety — Validation errors match server response format exactly
- Small bundle — ~60KB uncompressed, smaller gzipped
Registering Types
Types must be registered before validation:
use *;
use register_type;
use Deserialize;
// Register at app initialization
;
API
Rust
| Function | Description |
|---|---|
register_type::<T>(name) |
Register a type for validation |
validate(type_name, json) |
Validate JSON string |
validate_object(type_name, value) |
Validate JS object |
createValidator() |
Create validator instance |
JavaScript/TypeScript
interface ValidationResult {
ok: boolean;
errors?: Violation[]; // Validation failures
error?: SystemError; // System error (unknown type, parse failure)
}
interface Violation {
path: string;
code: string;
message: string;
meta?: Record<string, string>;
}
interface SystemError {
code: 'unknown_type' | 'parse_error';
message: string;
}
Building
# Install WASM target
# Build with wasm-pack
# Output in pkg/
Documentation
- Implementation Guide — Architecture, API design, phases
- Publishing Guide — Dual crates.io + npm workflow
License
MIT OR Apache-2.0