@@ -1559,6 +1559,13 @@ export type DeregisterCallback = (device: DeviceDetails, callback: StandardCallb
1559
1559
*/
1560
1560
export type ErrorCallback = ( error : ErrorInfo | null ) => void ;
1561
1561
1562
+ /**
1563
+ * A callback used in {@link LiveObject} to listen for updates to the Live Object.
1564
+ *
1565
+ * @param update - The update object describing the changes made to the Live Object.
1566
+ */
1567
+ export type LiveObjectUpdateCallback < T > = ( update : T ) => void ;
1568
+
1562
1569
// Internal Interfaces
1563
1570
1564
1571
// To allow a uniform (callback) interface between on and once even in the
@@ -2028,7 +2035,124 @@ export declare interface PushChannel {
2028
2035
/**
2029
2036
* Enables the LiveObjects state to be subscribed to for a channel.
2030
2037
*/
2031
- export declare interface LiveObjects { }
2038
+ export declare interface LiveObjects {
2039
+ /**
2040
+ * Retrieves the root {@link LiveMap} object for state on a channel.
2041
+ *
2042
+ * @returns A promise which, upon success, will be fulfilled with a {@link LiveMap} object. Upon failure, the promise will be rejected with an {@link ErrorInfo} object which explains the error.
2043
+ */
2044
+ getRoot ( ) : Promise < LiveMap > ;
2045
+ }
2046
+
2047
+ /**
2048
+ * The `LiveMap` class represents a synchronized key/value storage, similar to a JavaScript Map, where all changes are synchronized across clients in realtime.
2049
+ * Conflict-free resolution for updates follows Last Write Wins (LWW) semantics, meaning that if two clients update the same key in the map, the last change wins.
2050
+ *
2051
+ * Keys must be strings. Values can be another Live Object, or a primitive type, such as a string, number, boolean, or binary data (see {@link StateValue}).
2052
+ */
2053
+ export declare interface LiveMap extends LiveObject < LiveMapUpdate > {
2054
+ /**
2055
+ * Returns the value associated with a given key. Returns `undefined` if the key doesn't exist in a map.
2056
+ *
2057
+ * @param key - The key to retrieve the value for.
2058
+ * @returns A {@link LiveObject}, a primitive type (string, number, boolean, or binary data) or `undefined` if the key doesn't exist in a map.
2059
+ */
2060
+ get ( key : string ) : LiveObject | StateValue | undefined ;
2061
+
2062
+ /**
2063
+ * Returns the number of key/value pairs in the map.
2064
+ */
2065
+ size ( ) : number ;
2066
+ }
2067
+
2068
+ /**
2069
+ * Represents an update to a {@link LiveMap} object, describing the keys that were updated or removed.
2070
+ */
2071
+ export declare interface LiveMapUpdate extends LiveObjectUpdate {
2072
+ /**
2073
+ * An object containing keys from a `LiveMap` that have changed, along with their change status:
2074
+ * - `updated` - the value of a key in the map was updated.
2075
+ * - `removed` - the key was removed from the map.
2076
+ */
2077
+ update : { [ keyName : string ] : 'updated' | 'removed' } ;
2078
+ }
2079
+
2080
+ /**
2081
+ * Represents a primitive value that can be stored in a {@link LiveMap}.
2082
+ *
2083
+ * For binary data, the resulting type depends on the platform (`Buffer` in Node.js, `ArrayBuffer` elsewhere).
2084
+ */
2085
+ export type StateValue = string | number | boolean | Buffer | ArrayBuffer ;
2086
+
2087
+ /**
2088
+ * The `LiveCounter` class represents a synchronized counter that can be incremented or decremented and is synchronized across clients in realtime.
2089
+ */
2090
+ export declare interface LiveCounter extends LiveObject < LiveCounterUpdate > {
2091
+ /**
2092
+ * Returns the current value of the counter.
2093
+ */
2094
+ value ( ) : number ;
2095
+ }
2096
+
2097
+ /**
2098
+ * Represents an update to a {@link LiveCounter} object.
2099
+ */
2100
+ export declare interface LiveCounterUpdate extends LiveObjectUpdate {
2101
+ /**
2102
+ * Holds the numerical change to the counter value.
2103
+ */
2104
+ update : {
2105
+ /**
2106
+ * The value by which the counter was incremented or decremented.
2107
+ */
2108
+ inc : number ;
2109
+ } ;
2110
+ }
2111
+
2112
+ /**
2113
+ * Describes the common interface for all conflict-free data structures supported by the `LiveObjects`.
2114
+ */
2115
+ export declare interface LiveObject < TUpdate extends LiveObjectUpdate = LiveObjectUpdate > {
2116
+ /**
2117
+ * Registers a listener that is called each time this Live Object is updated.
2118
+ *
2119
+ * @param listener - An event listener function that is called with an update object whenever this Live Object is updated.
2120
+ * @returns A {@link SubscribeResponse} object that allows the provided listener to be deregistered from future updates.
2121
+ */
2122
+ subscribe ( listener : LiveObjectUpdateCallback < TUpdate > ) : SubscribeResponse ;
2123
+
2124
+ /**
2125
+ * Deregisters the given listener from updates for this Live Object.
2126
+ *
2127
+ * @param listener - An event listener function.
2128
+ */
2129
+ unsubscribe ( listener : LiveObjectUpdateCallback < TUpdate > ) : void ;
2130
+
2131
+ /**
2132
+ * Deregisters all listeners from updates for this Live Object.
2133
+ */
2134
+ unsubscribeAll ( ) : void ;
2135
+ }
2136
+
2137
+ /**
2138
+ * Represents a generic update object describing the changes that occurred on a Live Object.
2139
+ */
2140
+ export declare interface LiveObjectUpdate {
2141
+ /**
2142
+ * Holds an update object which describe changes applied to the object.
2143
+ */
2144
+ update : any ;
2145
+ }
2146
+
2147
+ /**
2148
+ * Object returned from a `subscribe` call, allowing the listener provided in that call to be deregistered.
2149
+ */
2150
+ export declare interface SubscribeResponse {
2151
+ /**
2152
+ * Deregisters the listener passed to the `subscribe` call.
2153
+ */
2154
+ unsubscribe ( ) : void ;
2155
+ }
2032
2156
2033
2157
/**
2034
2158
* Enables messages to be published and historic messages to be retrieved for a channel.
0 commit comments