Document Schemas
Define and validate the shape of your data with Logic Bee's schema system.
Overview
Document schemas provide a declarative way to define the structure of your collections, enabling automatic validation, type-safety, and documentation generation.
Defining a Schema
import { Schema } from '@logic-bee/core';
const AccountSchema = new Schema({
name: { type: String, required: true },
email: { type: String, required: true, unique: true },
status: { type: String, enum: ['active', 'inactive'], default: 'active' },
createdAt: { type: Date, default: Date.now },
});
Validation
Schemas automatically validate incoming data before it reaches your hooks, ensuring data integrity at the framework level.
Schema Features
- Type coercion — Automatic type conversion where safe
- Default values — Pre-populate fields when not provided
- Enum constraints — Restrict values to a defined set
- Nested schemas — Compose complex document structures
More examples coming soon.