Skip to main content

Module resource

Module resource 

Expand description

The resource contract: what any resource type provides so that it gets history, undo, collaboration, permissions, palette/agent/script exposure, search and replay without writing any of them.

Structs§

ActionDecl
One mutation offered by name: a [Declaration] of the resource R, whose fields it derefs to.
ScopeDecl
SearchBody
A SearchText an entry carries. Cloning one is cheap, and two bodies are the same body only when they share one text, so an app that rebuilds its entries over mostly unchanged prose keeps its bodies and hands the same ones back.
SearchEntry
A search index entry. anchor addresses what a hit opens (an item id); action, when set, is the published action a hit invokes, so choosing it goes through the same door, permissions and history as the palette.
SearchPiece
One run of a SearchText segment: styled text, say.
SearchRow

Enums§

NoAction
The edits of a resource whose document holds nothing. An app whose data lives entirely outside any document — credentials in this device’s encrypted vault, a device’s hardware — publishes that data as live rows and effects, and its resource is only the door they are published on. No value exists, so nothing is ever applied, undone or synced.
Place
Where a participant is inside a resource, in the resource’s own terms: the same on every collaborator’s screen whatever its layout.
SearchRowShape
SearchWeight
How much a match in one of a SearchEntry’s fields counts. The title ranks as Self::Title, the subtitle as Self::Subtitle and the text as Self::Body; SearchEntry::field adds others.

Constants§

APPLY
The id of the action every resource publishes that applies one typed Resource::Action given as JSON. It is how a custom surface, an agent or a script submits an edit that has no named declaration (a drag with its final geometry) through the same permission-checked, undoable path.
APPLY_PARAM
The parameter of APPLY carrying the JSON-encoded action.
EDIT_PARAM
The parameter of FIELD_EDIT carrying the edit.
FIELD_EDIT
The id of the action a resource with field edits (Resource::EDITS) publishes for them: one Edit given as JSON, a path and an operation.

Traits§

Resource
A resource type. Implement it by hand for a type with its own storage layout and merge semantics (a timeline, a rich-text document, a photo edit stack); #[resource] implements it for a #[derive(Model)] record.
SearchText
Long text a search entry is found by, owned by the app: the index reads it while indexing and never copies it. It is a sequence of segments (the unit a hit can point at: a paragraph, a block), each a sequence of pieces. It must not change once handed to an entry; changed prose is a new body.
SharedRecord
A resource of the person’s own that one app keeps for every app of theirs: their accounts, which Settings keeps and Mail signs in to. Each app holds its copy in its own store; the copies are one record, the same on every device, and converge over the person’s own room. Only the OWNER and the EDITORS change it; every other app reads it (ViewCx::shared_person in tilo-app).

Functions§

bind_declaration
resource with the bound edit decl published on it.
build_action
Build the action a declaration produces for JSON arguments, validating them against its parameters exactly as the host does.
child_by_id
The nested resource id of state, read from doc with id demanded when state has not loaded it: an item past what a view shows or a tree pages still resolves by id (Resource::child, Resource::load).
declaration_spec
The published spec of one declared or bound mutation: what the palette, agents and scripts invoke, building the resource’s action from their arguments.
default_search
The default search entries of a record: one per item with a #[model(label)], anchored at its item resource, or else all of its text in one entry. A #[resource(search = path)] function extends it by calling it.
encode
Encode a resource action under its registry type id.
field_edit_spec_at
The field edit offered on the item at prefix (fields and item ids from the record, ending at an item): paths from the item, its editable paths described as the record’s are.
item_field_edit_spec
The field edit offered on the item item of the collection field: paths from the item, its editable paths described as the record’s are.
least_need_of
The least a caller needs to take any of the actions needs (kind and field each): the one that asks least.
need_of
What action is, for the grants deciding it.
origin_now_ms
Milliseconds since the Unix epoch on this machine (or the clock of the replica applying an action here). Only ever read on the origin, when an action is built; never inside apply.
publish
The resource tree published for one open resource: every declared and state-bound action, the generic APPLY and GROUP actions, the named Resource::views, and the nested resources.
publish_head
publish without the children: the resource’s identity, actions and views exactly as publish gives them, at a cost that does not grow with the children (Resource::children_offer_bound). What controls bind to.
scope_contains
Whether anchor is scope or lies beneath it in the anchor path.
spec_kind
What kind of action a published spec is: a view only reads, an effect reaches outside the document, and a document action changes only the document when the host’s undo reverts it, else it reaches outside.
with_origin_clock
Run f with the origin clock reading now_ms: every action built inside it is stamped with that time, so encoding the same invocation twice (once to ask for confirmation, once to check it) gives the same action.

Type Aliases§

BuildAction
Builds a resource’s action from arguments already bound against the declaration’s parameters. now_ms is the origin’s clock, captured once so replay is deterministic.