WriteOneRelationInstance
Defined in: runtime/relation.ts:70
A relation instance where the cardinality is “1”.
Extends
Section titled “Extends”ReadOneRelationInstance<TItem>
Type Parameters
Section titled “Type Parameters”TItem extends WriteItem
Properties
Section titled “Properties”
readonlytype:"one"
Defined in: runtime/relation.ts:64
Indicates that an abstract relation instance is cardinality “1”.
Inherited from
Section titled “Inherited from”Methods
Section titled “Methods”clear()
Section titled “clear()”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.
Returns
Section titled “Returns”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.
Returns
Section titled “Returns”Promise<RelatedItem<TItem> | undefined>
Inherited from
Section titled “Inherited from”isType()
Section titled “isType()”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.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”item is TItem
Inherited from
Section titled “Inherited from”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.
Parameters
Section titled “Parameters”target
Section titled “target”TItem
Returns
Section titled “Returns”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()
Section titled “setIfNotExists()”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.
Parameters
Section titled “Parameters”target
Section titled “target”TItem
condition?
Section titled “condition?”Returns
Section titled “Returns”Promise<boolean>
true if the set operation succeeded, false if there is already a value set that satisifes the supplied condition.