@audiotool/nexus - v0.0.12
    Preparing search index...

    Type Alias TransactionBuilder

    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.

    type TransactionBuilder = {
        entities: EntityQuery;
        applyPresetTo(
            entity: NexusEntity<DevicePresetEntityType>,
            preset: NexusPreset,
        ): void;
        clone<T extends keyof EntityTypes>(
            entity: NexusEntity<T>,
            args?: DeepPartial<EntityConstructorType<T>>,
        ): NexusEntityUnion<T>;
        cloneLinked(
            ...entities: (NexusEntity<(keyof EntityTypes)> | EntityWithOverwrites)[],
        ): NexusEntity<keyof EntityTypes>[];
        create<T extends keyof EntityTypes>(
            name: T,
            args: EntityConstructorType<T>,
        ): NexusEntityUnion<T>;
        createPresetFor(entity: NexusEntity<DevicePresetEntityType>): Preset;
        remove(idOrEntity: string | NexusEntity<keyof EntityTypes>): void;
        removeWithDependencies(
            idOrEntity: string | NexusEntity<keyof EntityTypes>,
        ): void;
        send(): void;
        tryUpdate<P extends PrimitiveType>(
            field: PrimitiveField<P, "mut">,
            value: P,
        ): undefined | string;
        update<P extends PrimitiveType>(
            field: PrimitiveField<P, "mut">,
            value: P,
        ): void;
    }
    Index

    Properties

    entities: EntityQuery

    Allows querying all entities of the document.

    Methods

    • 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.

      Example

      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:

      • the relationship between b and c is updated to duplicates
      • relationships from b or c to other entities remain untouched
      • relationships from other entities to b or c remain untouched

      Leading 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.

      Parameters

      Returns NexusEntity<keyof EntityTypes>[]

    • 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.

      Example

      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.

      Parameters

      Returns void

    • 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.

      Type Parameters

      Parameters

      Returns undefined | string