AI agents: fetch the documentation index at llms.txt. Markdown versions are available by appending .md to any page URL, including this page's markdown.
Model base class
The Model base class provides change tracking, hydration, serialization, and CRUD operations for synced entities.
Every synced entity extends Model. Decorators register it with the ModelRegistry and wire it into the sync lifecycle.
Creating a model
import { Model, ClientModel, Property, ManyToOne } from "@stratasync/core";@ClientModel("Task")class Task extends Model { @Property() title = ""; @Property() status = "todo"; @Property() priority = 0; @ManyToOne("Project", "tasks") project!: Project;}
@ClientModel registers the class as "Task". Each @Property marks a synced field for change tracking and delta processing.
Model properties
Property
Type
Description
id
string
Primary key (UUID). Set automatically on creation.
hydrated
boolean
Whether lazy references have been resolved.
__modelName
string
The registered model name (read-only getter).
Internals.__data holds raw backing data. store is the backing store reference injected by the sync client. You shouldn't need either in application code.
Instance methods
hydrate()
Resolves all lazy references and collections.
const task = await client.get<Task>("Task", taskId);const hydrated = await task.hydrate();// hydrated.project is a resolved Project instance
import type { Hydrated } from "@stratasync/core";// Before hydration: task.project is LazyReference<Project>// After hydration: task.project is Projectconst hydrated: Hydrated<Task> = await task.hydrate();
LazyReference<T>
A reference that may not yet be loaded. Access triggers lazy loading when the sync client is available.
import type { LazyReference } from "@stratasync/core";const project = await resolvePromise(task.project);