Apply a preset to a given entity. The preset is a special transaction.
Clone an existing entity, optionally overwriting some fields.
Note that ts by default doesn't correctly type the output. To get correctly typed output, do:
const tonematrix = t.create("tonematrix", {})
const tonematrix2 = t.clone<"tonematrix">(tonematrix)
Optionalargs: DeepPartial<EntityConstructorType<T>>Clone a list of entities, in such a way that pointers that
are both from to entities in this list are updated to point to
the cloned versions. The resulting creates command are ordered in such a way
that all pointers are always valid, and no transaction errors occur.
Each element in the past list can either be an entity itself, or an object
{
entity: NexusEntity<T>,
overwrites?: ConstructorTypes[T]
}
where overwrites work the same as the second parameter of t.clone() or t.create().
Pointers from and to entities not in the list remain unchanged, unless overwritten.
Returns the cloned version of the entities in order. Robust towards duplicates in the passed entities list.
Let's say we have entities a, b, c, d, e, with pointers between each
other like this:
a ──► b ──► c ──► d
▲
│
e
And we call cloneLinked(b, c). Then:
b and c is updated to duplicatesb or c to other entities remain untouchedb or c remain untouchedLeading to a graph like this:
b'──► c' ───┐
▼
a ──► b ──► c ──► d
▲
│
e
If overwrite arguments are given for a specific entity, they overwrite any value after the links have been adjusted.
Create a new entity with default values
Create a preset of a given entity. This doesn't modify the nexus document.
Delete an entity with id id from the document
Delete an entity with id, after all entities with pointers to it, transitively,
are deleted. In other words, remove entity id, after all entities are deleted
that would result in dangling pointers if id was removed.
Let's say we have entities a, b, c, d, e, with pointers between each
other like this:
a ─► b ─┐
│ ├──► d ─► e
│ │
└──► c ─┘
Then calling removeWithDependencies(d.id) will remove all entities except e,
in an order that keeps all existing pointers valid after every modification.
Release the transaction lock and send the modifications to the backend. After this method
is called, this TransactionBuilder can't be used anymore.
Try to update a primitive field. Don't throw if it fails; return a string explaining the error
instead. If this returns undefined, the update was applied. Useful when e.g. a user enters a value
and it's not possible to know if the value is valid or not.
Update a primitive field value
A transaction builder can be used to make changes on a document.
All changes made using the same transaction builder will be part of the same transaction, and as such applied atomically to the backend.
While a transaction builder exists, the document is locked, and no other builders can be created, to avoid race conditions.
To finish a transaction, call send, which will unlock the document and let other builders be created. After send is called, all methods of the builder will throw.
Modifications to the document with a builder are applied to the local document immediately, and only sent to the backend when send is called.
Note that if receiving a builder through SyncedDocument.modify, then send method is called automatically once the function returns. See Overview for more information.