Skip to content

WriteOneRelationInstance

Defined in: runtime/relation.ts:70

A relation instance where the cardinality is “1”.

TItem extends WriteItem

readonly type: "one"

Defined in: runtime/relation.ts:64

Indicates that an abstract relation instance is cardinality “1”.

ReadOneRelationInstance.type

clear(): Promise<boolean>

Defined in: runtime/relation.ts:78

Clears the target of this relation. If no target is currently set this method returns with no effect.

Promise<boolean>

true if this was a definite action: something was cleared. Otherwise false if the clear did not modify any entires.


get(): Promise<RelatedItem<TItem> | undefined>

Defined in: runtime/relation.ts:59

Get the currently assigned target for this relation instance. If no current value is set, this will return undefined.

Promise<RelatedItem<TItem> | undefined>

ReadOneRelationInstance.get


isType(item): item is TItem

Defined in: runtime/relation.ts:48

True if the supplied item is of the correct type for this side of the relation.

BaseReadItem

item is TItem

ReadOneRelationInstance.isType


set(target): Promise<boolean>

Defined in: runtime/relation.ts:90

Sets the target of this relation instance to the supplied item. A subsequent get will return that item. The supplied target item must match the templates specified in the relationship. For example, if the relation is TemplateA -> TemplateB, you could not supply an item of TemplateC.

TItem

Promise<boolean>

true if this was a definite action: the set was applied. Otherwise false: the value already existed and no action was necessary.


setIfNotExists(target, condition?): Promise<boolean>

Defined in: runtime/relation.ts:111

Conditionally sets this the relation, but only if this relation has not been set already (with a condition).

Conditions include specifying a max age for any existing relations. With this approach existing relations can be “expired” after a given duration.

This operation is atomic. If this set operation occurs, it will apply at the end of the transaction. If two concurrent tranactions with “setIfNotExists” occur, the latter transaction will error and rollback.

TODO: depending on usage, this might get split into two methods. Current behaviour would be renamed to trySetIfNotExists returning boolean, and a new method called setIfNotExists that throws.

TItem

IfNotExistCondition

Promise<boolean>

true if the set operation succeeded, false if there is already a value set that satisifes the supplied condition.