Defining Schemas
import { defineSchema, encode } from '@axon-format/core';
const userSchema = defineSchema({
id: 'u8',
name: 'str',
email: 'str',
verified: 'bool',
createdAt: 'iso8601'
}); Schema Inheritance
// Base schema
const userSchema = defineSchema({
id: 'u8',
name: 'str',
email: 'str'
});
// Extended schema
const adminSchema = defineSchema({
...userSchema,
permissions: 'str[]',
level: 'u8'
}); Using Schemas
const data = [
{ id: 1, name: "Alice", email: "alice@example.com", verified: true }
];
// Encode with schema validation
const encoded = encode(data, { schema: userSchema }); Benefits
- Type safety: Catch errors before expensive API calls
- Reusability: Define once, use across your application
- Documentation: Schemas serve as inline documentation
- Validation: Automatic data validation on encode/decode