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. - Head
Inputs - What
publish_headreads of a state. Two states with equal inputs publish the same head, so a publisher holding the head of one keeps it for the other. - 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_
MEMBER - What the value of an
applymember of a group is: the schema it is checked against is published once, onapplyitself. - 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.
#[resource]implements it for a#[derive(Model)]record, which is how every app declares its own. The SDK implements it by hand for the shared types with a storage layout of their own (a rich-text document, plain text), which apps hold as fields; an app never does (docs/architecture/resources.md §8). - 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 one app keeps for all 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, kept in the person’s own scope, which no route carries yet. Only
OWNERandEDITORSchange 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, found by its text. Items of a record holding several collections are listed under each collection’s title (its doc comment’s first line: “Folders”, “Articles”), so the kinds read apart. An item is found by all of its text, which is no preview of it: the palette shows none for it. 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. - head_
inputs HeadInputsofstate: what its head is published from, read without publishing a child or an action.- 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.- publish_
head_ of publish_headof a state whose inputs areinputs.- scope_
contains - Whether
anchorisscopeor lies beneath it in the anchor path. - spec_
kind - What kind of action a published spec is: the kind its contract carries, which the code that built it derived (a view only reads, a document action changes only the document when the host’s undo reverts it, else it reaches outside).
- state_
from_ reading - A record’s state from the reading a document host publishes for it
(
Resource::state_json,crate::Model::to_json): what an app’s process reads when the record lives in the session’s document host and it holds no document of its own (docs/architecture/apps.md§2–§3). - unreadable_
parts - The resource tree published for one open document (
publish) whose state its holder could not read: its declared actions,APPLY,GROUPand the field edit, each unavailable forreason, so a caller learns why they do not apply instead of finding a hole in the surface. What a state would offer — its children, its views, which actions can be taken now — is not published: there is no state to read it from. - 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.