| Crates.io | domainstack-wasm |
| lib.rs | domainstack-wasm |
| version | 1.0.0 |
| created_at | 2026-01-06 14:55:34.368806+00 |
| updated_at | 2026-01-06 14:55:34.368806+00 |
| description | WASM browser validation for domainstack: run the same validation logic in browser and server |
| homepage | |
| repository | https://github.com/blackwell-systems/domainstack |
| max_upload_size | |
| id | 2026025 |
| size | 50,574 |
WASM browser validation for domainstack. Run the same validation logic in both browser and server.
# Build WASM package
wasm-pack build --target web --release
import init, { createValidator, validate } from '@domainstack/wasm';
// Initialize WASM module
await init();
// Create validator instance
const validator = createValidator();
// Validate data
const result = validator.validate('Booking', JSON.stringify({
guest_email: 'invalid',
rooms: 15
}));
if (!result.ok) {
result.errors?.forEach(e => {
console.log(`${e.path}: ${e.message}`);
});
}
Types must be registered before validation:
use domainstack::prelude::*;
use domainstack_wasm::register_type;
use serde::Deserialize;
#[derive(Debug, Validate, Deserialize)]
struct Booking {
#[validate(email)]
guest_email: String,
#[validate(range(min = 1, max = 10))]
rooms: u8,
}
// Register at app initialization
register_type::<Booking>("Booking");
| 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 |
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;
}
# Install WASM target
rustup target add wasm32-unknown-unknown
# Build with wasm-pack
wasm-pack build --target web --release
# Output in pkg/
ls pkg/
MIT OR Apache-2.0