Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,14 @@ Loro Mirror provides a declarative schema system that enables:
- `schema.String<T extends string = string>(options?)` - String type with optional generic constraint
- `schema.Number(options?)` - Number type
- `schema.Boolean(options?)` - Boolean type
- `schema.Any(options?)` - Runtime-inferred value/container type for JSON-like dynamic fields
- `schema.Ignore(options?)` - Field that won't sync with Loro, useful for local computed fields

`schema.Any` options:

- `defaultLoroText?: boolean` (defaults to `false` for `Any` when omitted)
- `defaultMovableList?: boolean` (inherits from global inference options)

- **Container Types**:
- `schema.LoroMap(definition, options?)` - Object container that can nest arbitrary field schemas
- Supports dynamic key-value definition with `catchall`: `schema.LoroMap({...}).catchall(valueSchema)`
Expand Down Expand Up @@ -331,6 +337,7 @@ Loro Mirror uses a typed schema to map your app state to Loro containers. Common
- `schema.String(options?)`: string
- `schema.Number(options?)`: number
- `schema.Boolean(options?)`: boolean
- `schema.Any(options?)`: JSON-like unknown (runtime-inferred)
- `schema.Ignore(options?)`: exclude from sync (app-only)
- `schema.LoroText(options?)`: rich text (`LoroText`)
- `schema.LoroMap(definition, options?)`: object (`LoroMap`)
Expand Down
5 changes: 5 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ All schema builders live under the `schema` namespace and are exported at the pa
- `schema.String<T = string>(options?)`
- `schema.Number(options?)`
- `schema.Boolean(options?)`
- `schema.Any(options?)` — runtime-inferred value/container type (useful for dynamic JSON-like fields)
- `schema.Ignore(options?)` — present in state, ignored for Loro diffs/validation

- Containers
Expand All @@ -123,6 +124,10 @@ All schema builders live under the `schema` namespace and are exported at the pa
- `description?: string`
- `validate?: (value) => boolean | string` — custom validator message when not true

- `schema.Any` options (per-Any inference overrides)
- `defaultLoroText?: boolean` — default `false` for `Any` when omitted (primitive string), overriding the global `inferOptions.defaultLoroText`.
- `defaultMovableList?: boolean` — inherits from the global inference options unless explicitly set.

- Type inference
- `InferType<S>` — state type produced by a schema
- `InferInputType<S>` — input type accepted by `setState` (map `$cid` optional)
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"test": "vitest run",
"lint": "oxlint --type-aware",
"format": "prettier --write .",
"typecheck": "pnpm -r typecheck"
"typecheck": "pnpm -r typecheck",
"check": "pnpm build && pnpm test && pnpm lint && pnpm typecheck"
},
"keywords": [
"loro",
Expand Down
8 changes: 7 additions & 1 deletion packages/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Types: `SyncDirection`, `UpdateMetadata`, `SetStateOptions`.
### Schema Builder

- Root: `schema({ ...fields })`
- Primitives: `schema.String`, `schema.Number`, `schema.Boolean`, `schema.Ignore`
- Primitives: `schema.String`, `schema.Number`, `schema.Boolean`, `schema.Any`, `schema.Ignore`
- Containers (core):
- `schema.LoroMap({ ...fields })`
- `schema.LoroList(itemSchema, idSelector?)`
Expand All @@ -113,6 +113,12 @@ Signatures:

SchemaOptions for any field: `{ required?: boolean; defaultValue?: unknown; description?: string; validate?: (value) => boolean | string }`.

Any options:

- `schema.Any({ defaultLoroText?: boolean; defaultMovableList?: boolean })`
- `defaultLoroText` defaults to `false` for Any when omitted (primitive string), overriding the global `inferOptions.defaultLoroText`.
- `defaultMovableList` inherits from the global inference options unless specified.

Reserved key `$cid`:

- `$cid` is injected into mirrored state for all `LoroMap` schemas; it is never written back to Loro and is ignored by diffs/updates. It’s useful as a stable identifier (e.g., `schema.LoroList(map, x => x.$cid)`).
Expand Down
Loading