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§
- Action
Decl - One mutation offered by name: a [
Declaration] of the resourceR, whose fields it derefs to. - Scope
Decl - Search
Body - A
SearchTextan 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. - Search
Entry - A search index entry.
anchoraddresses 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. - Search
Piece - One run of a
SearchTextsegment: styled text, say. - Search
Row
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.
- Search
RowShape - Search
Weight - How much a match in one of a
SearchEntry’s fields counts. The title ranks asSelf::Title, the subtitle asSelf::Subtitleand the text asSelf::Body;SearchEntry::fieldadds others.
Constants§
- APPLY
- The id of the action every resource publishes that applies one typed
Resource::Actiongiven 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
APPLYcarrying the JSON-encoded action. - EDIT_
PARAM - The parameter of
FIELD_EDITcarrying the edit. - FIELD_
EDIT - The id of the action a resource with field edits (
Resource::EDITS) publishes for them: oneEditgiven 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. - Search
Text - 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.
- Shared
Record - 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
OWNERand theEDITORSchange it; every other app reads it (ViewCx::shared_personintilo-app).
Functions§
- bind_
declaration resourcewith the bound editdeclpublished 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
idofstate, read fromdocwithiddemanded whenstatehas 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
itemof the collectionfield: 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
actionis, 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
APPLYandGROUPactions, the namedResource::views, and the nested resources. - publish_
head publishwithout the children: the resource’s identity, actions and views exactly aspublishgives them, at a cost that does not grow with the children (Resource::children_offer_bound). What controls bind to.- scope_
contains - Whether
anchorisscopeor 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
fwith the origin clock readingnow_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§
- Build
Action - Builds a resource’s action from arguments already bound against the
declaration’s parameters.
now_msis the origin’s clock, captured once so replay is deterministic.