Interface AnyPathObject

Represents a PathObject 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

Methods

  • Collection types support obtaining a PathObject with a fully-qualified string path, which is evaluated from the current path. Using this method loses rich compile-time type information.

    Type Parameters

    Parameters

    • path: string

      A fully-qualified path string to navigate to, relative to the current path.

    Returns PathObject<T>

    A PathObject for the specified path.

  • Batch multiple operations together using a batch context, which wraps the underlying PathObject or Instance from which the batch was called. The batch context always contains a resolved instance, even when called from a PathObject. If an instance cannot be resolved from the referenced path, or if the instance is not a LiveObject, this method throws an error.

    Batching enables you to group multiple operations together and send them to the Ably service in a single channel message. As a result, other clients will receive the changes in a single channel message once the batch function has completed.

    The objects' data is not modified inside the batch function. Instead, the objects will be updated when the batched operations are applied by the Ably service and echoed back to the client.

    Type Parameters

    Parameters

    Returns Promise<void>

    A promise which resolves upon success of the batch operation and rejects with an ErrorInfo object upon its failure.

  • Get an in-memory JavaScript object representation of the object at this path. 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 path does not resolve to any specific entry, returns undefined.

    Use compactJson() for a JSON-serializable representation.

    Type Parameters

    Returns undefined | CompactedValue<T>

  • Get a JSON-serializable representation of the object at this path. 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 path does not resolve to any specific entry, returns undefined.

    Use compact() for an in-memory representation.

    Type Parameters

    Returns undefined | CompactedJsonValue<T>

  • An alias for calling increment(-amount)

    Parameters

    • Optional amount: number

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

    Returns Promise<void>

    A promise which resolves upon success of the operation and rejects with an ErrorInfo object upon its failure.

  • Returns an iterable of key-value pairs for each entry in the map, if the path resolves to a LiveMap. Each value is represented as a PathObject corresponding to its key.

    If the path does not resolve to a map object, returns an empty iterator.

    Type Parameters

    • T extends Record<string, Value>

    Returns IterableIterator<[keyof T, PathObject<T[keyof T]>]>

  • Navigate to a child path within the collection by obtaining a PathObject for that path. The next path segment in a collection is identified with a string key.

    Type Parameters

    Parameters

    • key: string

      A string key for the next path segment within the collection.

    Returns PathObject<T>

    A PathObject for the specified key.

  • Sends an operation to the Ably system to increment the value of the underlying counter when using AnyInstance, or of the counter instance resolved from the path when using AnyPathObject.

    If called via AnyInstance and the underlying instance at runtime is not a counter, or if called via AnyPathObject and the counter instance at the specified path cannot be resolved at the time of the call, 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 Promise<void>

    A promise which resolves upon success of the operation and rejects with an ErrorInfo object upon its failure.

  • Get the specific object instance currently at this path. If the path does not resolve to any specific instance, returns undefined.

    Type Parameters

    Returns undefined | Instance<T>

    The object instance at this path, or undefined if none exists.

  • Returns an iterable of keys in the map, if the path resolves to a LiveMap.

    If the path does not resolve to a map object, returns an empty iterator.

    Type Parameters

    • T extends Record<string, Value>

    Returns IterableIterator<keyof T>

  • Get the fully-qualified path string for this PathObject.

    Path segments with dots in them are escaped with a backslash. For example, a path with segments ['a', 'b.c', 'd'] will be represented as a.b\.c.d.

    Returns string

  • Sends an operation to the Ably system to remove a key from the underlying map when using AnyInstance, or from the map instance resolved from the path when using AnyPathObject.

    If called via AnyInstance and the underlying instance at runtime is not a map, or if called via AnyPathObject and the map instance at the specified path cannot be resolved at the time of the call, 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 Promise<void>

    A promise which resolves upon success of the operation and rejects with an ErrorInfo object upon its failure.

  • Sends an operation to the Ably system to set a key to a specified value on the underlying map when using AnyInstance, or on the map instance resolved from the path when using AnyPathObject.

    If called via AnyInstance and the underlying instance at runtime is not a map, or if called via AnyPathObject and the map instance at the specified path cannot be resolved at the time of the call, 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 Promise<void>

    A promise which resolves upon success of the operation and rejects with an ErrorInfo object upon its failure.

  • Registers a listener that is called each time the object or a primitive value at this path is updated.

    The provided listener receives a PathObject representing the path at which there was an object change, and, if applicable, an ObjectMessage that carried the operation that led to the change.

    By default, subscriptions observe nested changes, but you can configure the observation depth using the options parameter.

    A PathObject subscription observes whichever value currently exists at this path. The subscription remains active even if the path temporarily does not resolve to any value (for example, if an entry is removed from a map). If the object instance at this path changes, the subscription automatically switches to observe the new instance and stops observing the old one.

    Parameters

    Returns Subscription

    A Subscription object that allows the provided listener to be deregistered from future updates.

  • Get the current value of the LiveCounter or primitive currently at this path. If the path does not resolve to any specific entry, returns undefined.

    Type Parameters

    Returns undefined | T

Generated using TypeDoc