WriteOneRelationInstance
Sets and clears the single target of a Relation side.
Remarks
Section titled “Remarks”When the Relation declares an Event, every successful set publishes it with the action set, and
every cleared target, whether by clear or by replacing it, publishes it with the action cleared.
Extends
Section titled “Extends”ReadOneRelationInstance<TItem>
Type Parameters
Section titled “Type Parameters”TItem extends WriteItem
The type of the target Item.
Properties
Section titled “Properties”
readonlytype:"one"
Discriminates this side as holding at most one target.
Inherited from
Section titled “Inherited from”Methods
Section titled “Methods”clear()
Section titled “clear()”clear():
Promise<boolean>
Removes the current target of this Relation.
Returns
Section titled “Returns”Promise<boolean>
true when a target was cleared; false when no target was set.
get():
Promise<RelatedItem<TItem> |undefined>
Loads the current target of this Relation.
Returns
Section titled “Returns”Promise<RelatedItem<TItem> | undefined>
The target with its Relation metadata, or undefined when no target is set or the target is not
readable by the active principal.
Inherited from
Section titled “Inherited from”isType()
Section titled “isType()”isType(
item):item is TItem
Reports whether an Item may be a target on this side of the Relation: its Template is the target Template or a member of the target Union.
Parameters
Section titled “Parameters”The Item to test.
Returns
Section titled “Returns”item is TItem
Inherited from
Section titled “Inherited from”ReadOneRelationInstance.isType
set(
target):Promise<boolean>
Makes an Item the target of this Relation, replacing any other target.
Parameters
Section titled “Parameters”target
Section titled “target”TItem
The Item to relate; its Template must be the target Template or a member of the target Union.
Returns
Section titled “Returns”Promise<boolean>
true when the Relation was created; false when the Item was already the target.
Throws
Section titled “Throws”(error-012-incorrect-item-for-relation) when the Item’s Template is not accepted by the Relation.
Example
Section titled “Example”Set the sides of a recognition
await recognition.relations.sender.set(sender);await recognition.relations.recipient.set(recipient);setIfNotExists()
Section titled “setIfNotExists()”setIfNotExists(
target,condition?):Promise<boolean>
Makes an Item the target only when no target is set, or when the existing one has expired under the condition.
Parameters
Section titled “Parameters”target
Section titled “target”TItem
The Item to relate.
condition?
Section titled “condition?”Treats an existing target older than existingMaxAge milliseconds as absent.
Returns
Section titled “Returns”Promise<boolean>
true when the target was set; false when an existing target blocked it, including one set by a
concurrent execution.
Remarks
Section titled “Remarks”The check and the write are one atomic operation. Without a condition any existing target blocks the write.

