Interface AnyBatchContext

Represents a BatchContext when its underlying type is not known. Provides a unified interface that includes all possible methods.

Each method supports type parameters to specify the expected underlying type when needed.

Hierarchy

Properties

id: undefined | string

Get the object ID of the underlying instance.

If the underlying instance at runtime is not a LiveObject, returns undefined.

Methods

  • Get an in-memory JavaScript object representation of the object instance. For primitive types, this is an alias for calling value().

    When compacting a LiveMap, cyclic references are handled through memoization, returning shared compacted object references for previously visited objects. This means the value returned from compact() cannot be directly JSON-stringified if the object may contain cycles.

    If the underlying instance's value is not of the expected type at runtime, returns undefined.

    Use compactJson() for a JSON-serializable representation.

    Type Parameters

    Returns undefined | CompactedValue<T>

  • Get a JSON-serializable representation of the object instance. Binary values are converted to base64-encoded strings.

    When compacting a LiveMap, cyclic references are represented as { objectId: string } instead of in-memory pointers, making the result safe to pass to JSON.stringify().

    If the underlying instance's value is not of the expected type at runtime, returns undefined.

    Use compact() for an in-memory representation.

    Type Parameters

    Returns undefined | CompactedJsonValue<T>

  • Navigate to a child entry within the collection by obtaining the BatchContext at that entry. The entry in a collection is identified with a string key.

    Returns undefined if:

    • The underlying instance at runtime is not a collection object.
    • The specified key does not exist in the collection.
    • The referenced LiveObject has been deleted.
    • This collection object itself has been deleted.

    Type Parameters

    Parameters

    • key: string

      The key to retrieve the value for.

    Returns undefined | BatchContext<T>

    A BatchContext representing either a LiveObject or a primitive value (string, number, boolean, JSON-serializable object or array, or binary data), or undefined if the underlying instance at runtime is not a collection object, the key does not exist, the referenced LiveObject has been deleted, or this collection object itself has been deleted.

  • Adds an operation to the current batch to increment the value of the underlying LiveCounterInstance. All queued operations are sent together in a single message once the batch function completes.

    If the underlying instance at runtime is not a counter, this method throws an error.

    This does not modify the underlying data of the counter. Instead, the change is applied when the published operation is echoed back to the client and applied to the object. To get notified when object gets updated, use PathObject.subscribe or Instance.subscribe, as appropriate.

    Parameters

    • Optional amount: number

      The amount by which to increase the counter value. If not provided, defaults to 1.

    Returns void

  • Returns an iterable of keys in the map.

    If the underlying instance at runtime is not a map, returns an empty iterator.

    Type Parameters

    • T extends Record<string, Value>

    Returns IterableIterator<keyof T>

  • Adds an operation to the current batch to remove a key from the underlying LiveMapInstance. All queued operations are sent together in a single message once the batch function completes.

    If the underlying instance at runtime is not a map, this method throws an error.

    This does not modify the underlying data of the map. Instead, the change is applied when the published operation is echoed back to the client and applied to the object. To get notified when object gets updated, use PathObject.subscribe or Instance.subscribe, as appropriate.

    Type Parameters

    • T extends Record<string, Value> = Record<string, Value>

    Parameters

    • key: keyof T & string

      The key to remove.

    Returns void

  • Adds an operation to the current batch to set a key to a specified value on the underlying LiveMapInstance. All queued operations are sent together in a single message once the batch function completes.

    If the underlying instance at runtime is not a map, this method throws an error.

    This does not modify the underlying data of the map. Instead, the change is applied when the published operation is echoed back to the client and applied to the object. To get notified when object gets updated, use PathObject.subscribe or Instance.subscribe, as appropriate.

    Type Parameters

    • T extends Record<string, Value> = Record<string, Value>

    Parameters

    • key: keyof T & string

      The key to set the value for.

    • value: T[keyof T]

      The value to assign to the key.

    Returns void

  • Get the current value of the underlying counter or primitive.

    If the underlying instance at runtime is neither a counter nor a primitive value, returns undefined.

    Type Parameters

    Returns undefined | T

    The current value of the underlying primitive or counter, or undefined if the value cannot be retrieved.

Generated using TypeDoc