Creating a Schema

Why use a Schema?

Schemas are the key to providing predictable data, autocomplete and type-checking in your ActiveClasses.

VS Code Autocomplete with Fireactive

Writing a basic Schema

Let's say that we want to model a user. Here's how we might do it.

import { Schema } from 'fireactive'
const userSchema = {
name: Schema.string, // users must have a name
age: Schema.number({ optional: true }), // age is optional
role: Schema.enum(['admin', 'basic']), // role must be 'admin' or 'basic'
isVerified: Schema.boolean({ default: false }) // defaults to false
}

Schema fields are all required, unless explicitly passed either { optional: true } or { required: false } as options.

Now you've written a Schema, you're ready to create your first Fireactive ActiveClass!