You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Move types required for user-provided LiveObjects typings to ably.d.ts
Add globally defined `LiveObjectsTypes` to `intentionallyNotExported` [1]
list for `typedoc`, as typedocs does not include documentation for the
globally defined interfaces and complains that "__global.LiveObjectsTypes,
defined in ./ably.d.ts, is referenced by ably.DefaultRoot but not
included in the documentation."
[1] https://typedoc.org/documents/Options.Validation.html#intentionallynotexported
* Retrieves the root {@link LiveMap} object for state on a channel.
2041
2041
*
2042
+
* A type parameter can be provided to describe the structure of the LiveObjects state on the channel. By default, it uses types from the globally defined `LiveObjectsTypes` interface.
2043
+
*
2044
+
* You can specify custom types for LiveObjects by defining a global `LiveObjectsTypes` interface with a `root` property that conforms to {@link LiveMapType}.
2045
+
*
2046
+
* Example:
2047
+
*
2048
+
* ```typescript
2049
+
* import { LiveCounter } from 'ably';
2050
+
*
2051
+
* type MyRoot = {
2052
+
* myTypedKey: LiveCounter;
2053
+
* };
2054
+
*
2055
+
* declare global {
2056
+
* export interface LiveObjectsTypes {
2057
+
* root: MyRoot;
2058
+
* }
2059
+
* }
2060
+
* ```
2061
+
*
2042
2062
* @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.
* The default type for the `root` object in the LiveObjects, based on the globally defined {@link LiveObjectsTypes} interface.
2084
+
*
2085
+
* - If no custom types are provided in `LiveObjectsTypes`, defaults to an untyped root map representation using the {@link LiveMapType} interface.
2086
+
* - If a `root` type exists in `LiveObjectsTypes` and conforms to the {@link LiveMapType} interface, it is used as the type for the `root` object.
2087
+
* - If the provided `root` type does not match {@link LiveMapType}, a type error message is returned.
2088
+
*/
2089
+
exporttypeDefaultRoot=
2090
+
// we need a way to know when no types were provided by the user.
2091
+
// we expect a "root" property to be set on LiveObjectsTypes interface, e.g. it won't be "unknown" anymore
2092
+
unknownextendsLiveObjectsTypes['root']
2093
+
? LiveMapType// no custom types provided; use the default untyped map representation for the root
2094
+
: LiveObjectsTypes['root']extendsLiveMapType
2095
+
? LiveObjectsTypes['root']// "root" property exists, and it is of an expected type, we can use this interface for the root object in LiveObjects.
2096
+
: `Provided type definition for the "root" object in LiveObjectsTypes is not of an expected LiveMapType`;
2097
+
2047
2098
/**
2048
2099
* The `LiveMap` class represents a synchronized key/value storage, similar to a JavaScript Map, where all changes are synchronized across clients in realtime.
2049
2100
* 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
2101
*
2051
2102
* 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}).
0 commit comments