Skip to content

WriteOneRelationInstance

Sets and clears the single target of a Relation side.

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.

TItem extends WriteItem

The type of the target Item.

readonly type: "one"

Discriminates this side as holding at most one target.

ReadOneRelationInstance.type

clear(): Promise<boolean>

Removes the current target of this Relation.

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.

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.

ReadOneRelationInstance.get


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.

BaseReadItem

The Item to test.

item is TItem

ReadOneRelationInstance.isType


set(target): Promise<boolean>

Makes an Item the target of this Relation, replacing any other target.

TItem

The Item to relate; its Template must be the target Template or a member of the target Union.

Promise<boolean>

true when the Relation was created; false when the Item was already the target.

(error-012-incorrect-item-for-relation) when the Item’s Template is not accepted by the Relation.

Set the sides of a recognition

await recognition.relations.sender.set(sender);
await recognition.relations.recipient.set(recipient);

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.

TItem

The Item to relate.

IfNotExistCondition

Treats an existing target older than existingMaxAge milliseconds as absent.

Promise<boolean>

true when the target was set; false when an existing target blocked it, including one set by a concurrent execution.

The check and the write are one atomic operation. Without a condition any existing target blocks the write.

IfNotExistCondition