Skip to content

Commit e56a7b3

Browse files
committed
Update Objects docstrings to not use "root" terminology
1 parent be5eb4b commit e56a7b3

File tree

4 files changed

+39
-39
lines changed

4 files changed

+39
-39
lines changed

ably.d.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2288,32 +2288,32 @@ export type LiveObjectLifecycleEvent = LiveObjectLifecycleEvents.DELETED;
22882288
*/
22892289
export declare interface RealtimeObject {
22902290
/**
2291-
* Retrieves the root {@link LiveMap} object for Objects on a channel.
2291+
* Retrieves the {@link LiveMap} object - the entrypoint for Objects on a channel.
22922292
*
22932293
* A type parameter can be provided to describe the structure of the Objects on the channel. By default, it uses types from the globally defined `AblyObjectsTypes` interface.
22942294
*
2295-
* You can specify custom types for Objects by defining a global `AblyObjectsTypes` interface with a `root` property that conforms to {@link LiveMapType}.
2295+
* You can specify custom types for Objects by defining a global `AblyObjectsTypes` interface with a `object` property that conforms to {@link LiveMapType}.
22962296
*
22972297
* Example:
22982298
*
22992299
* ```typescript
23002300
* import { LiveCounter } from 'ably';
23012301
*
2302-
* type MyRoot = {
2302+
* type MyObject = {
23032303
* myTypedKey: LiveCounter;
23042304
* };
23052305
*
23062306
* declare global {
23072307
* export interface AblyObjectsTypes {
2308-
* root: MyRoot;
2308+
* object: MyObject;
23092309
* }
23102310
* }
23112311
* ```
23122312
*
23132313
* @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.
23142314
* @experimental
23152315
*/
2316-
get<T extends LiveMapType = DefaultRoot>(): Promise<LiveMap<T>>;
2316+
get<T extends LiveMapType = AblyDefaultObject>(): Promise<LiveMap<T>>;
23172317

23182318
/**
23192319
* Creates a new {@link LiveMap} object instance with the provided entries.
@@ -2392,20 +2392,20 @@ declare global {
23922392
export type LiveMapType = { [key: string]: PrimitiveObjectValue | LiveMap<LiveMapType> | LiveCounter | undefined };
23932393

23942394
/**
2395-
* The default type for the `root` object for Objects on a channel, based on the globally defined {@link AblyObjectsTypes} interface.
2395+
* The default type for the entrypoint {@link LiveMap} object on a channel, based on the globally defined {@link AblyObjectsTypes} interface.
23962396
*
2397-
* - If no custom types are provided in `AblyObjectsTypes`, defaults to an untyped root map representation using the {@link LiveMapType} interface.
2398-
* - If a `root` type exists in `AblyObjectsTypes` and conforms to the {@link LiveMapType} interface, it is used as the type for the `root` object.
2399-
* - If the provided `root` type does not match {@link LiveMapType}, a type error message is returned.
2397+
* - If no custom types are provided in `AblyObjectsTypes`, defaults to an untyped map representation using the {@link LiveMapType} interface.
2398+
* - If an `object` key exists in `AblyObjectsTypes` and its type conforms to the {@link LiveMapType} interface, it is used as the type for the entrypoint {@link LiveMap} object.
2399+
* - If the provided type in `object` key does not match {@link LiveMapType}, a type error message is returned.
24002400
*/
2401-
export type DefaultRoot =
2401+
export type AblyDefaultObject =
24022402
// we need a way to know when no types were provided by the user.
2403-
// we expect a "root" property to be set on AblyObjectsTypes interface, e.g. it won't be "unknown" anymore
2404-
unknown extends AblyObjectsTypes['root']
2405-
? LiveMapType // no custom types provided; use the default untyped map representation for the root
2406-
: AblyObjectsTypes['root'] extends LiveMapType
2407-
? AblyObjectsTypes['root'] // "root" property exists, and it is of an expected type, we can use this interface for the root object in Objects.
2408-
: `Provided type definition for the "root" object in AblyObjectsTypes is not of an expected LiveMapType`;
2403+
// we expect an "object" property to be set on AblyObjectsTypes interface, e.g. it won't be "unknown" anymore
2404+
unknown extends AblyObjectsTypes['object']
2405+
? LiveMapType // no custom types provided; use the default untyped map representation for the entrypoint map
2406+
: AblyObjectsTypes['object'] extends LiveMapType
2407+
? AblyObjectsTypes['object'] // "object" property exists, and it is of an expected type, we can use this interface for the entrypoint map
2408+
: `Provided type definition for the "object" object in AblyObjectsTypes is not of an expected LiveMapType`;
24092409

24102410
/**
24112411
* Object returned from an `on` call, allowing the listener provided in that call to be deregistered.
@@ -2424,12 +2424,12 @@ export declare interface OnObjectsEventResponse {
24242424
*/
24252425
export declare interface BatchContext {
24262426
/**
2427-
* Mirrors the {@link RealtimeObject.get} method and returns a {@link BatchContextLiveMap} wrapper for the root object on a channel.
2427+
* Mirrors the {@link RealtimeObject.get} method and returns a {@link BatchContextLiveMap} wrapper for the entrypoint {@link LiveMap} object on a channel.
24282428
*
24292429
* @returns A {@link BatchContextLiveMap} object.
24302430
* @experimental
24312431
*/
2432-
get<T extends LiveMapType = DefaultRoot>(): BatchContextLiveMap<T>;
2432+
get<T extends LiveMapType = AblyDefaultObject>(): BatchContextLiveMap<T>;
24332433
}
24342434

24352435
/**

src/plugins/objects/batchcontext.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class BatchContext {
2323
this._wrappedObjects.set(this._root.getObjectId(), new BatchContextLiveMap(this, this._realtimeObject, this._root));
2424
}
2525

26-
get<T extends API.LiveMapType = API.DefaultRoot>(): BatchContextLiveMap<T> {
26+
get<T extends API.LiveMapType = API.AblyDefaultObject>(): BatchContextLiveMap<T> {
2727
this._realtimeObject.throwIfInvalidAccessApiConfiguration();
2828
this.throwIfClosed();
2929
return this.getWrappedObject(ROOT_OBJECT_ID) as BatchContextLiveMap<T>;

src/plugins/objects/realtimeobject.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export class RealtimeObject {
7979
* This is useful when working with multiple channels with different underlying data structure.
8080
* @spec RTO1
8181
*/
82-
async get<T extends API.LiveMapType = API.DefaultRoot>(): Promise<LiveMap<T>> {
82+
async get<T extends API.LiveMapType = API.AblyDefaultObject>(): Promise<LiveMap<T>> {
8383
this.throwIfInvalidAccessApiConfiguration(); // RTO1a, RTO1b
8484

8585
// if we're not synced yet, wait for sync sequence to finish before returning root

test/package/browser/template/src/index-objects.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ declare module globalThis {
88
var testAblyPackage: () => Promise<void>;
99
}
1010

11-
type CustomRoot = {
11+
type MyCustomObject = {
1212
numberKey: number;
1313
stringKey: string;
1414
booleanKey: boolean;
@@ -24,11 +24,11 @@ type CustomRoot = {
2424

2525
declare global {
2626
export interface AblyObjectsTypes {
27-
root: CustomRoot;
27+
object: MyCustomObject;
2828
}
2929
}
3030

31-
type ExplicitRootType = {
31+
type ExplicitObjectType = {
3232
someOtherKey: string;
3333
};
3434

@@ -40,32 +40,32 @@ globalThis.testAblyPackage = async function () {
4040
const channel = realtime.channels.get('channel', { modes: ['OBJECT_SUBSCRIBE', 'OBJECT_PUBLISH'] });
4141
// check Objects can be accessed
4242
await channel.attach();
43-
// expect root to be a LiveMap instance with Objects types defined via the global AblyObjectsTypes interface
43+
// expect entrypoint to be a LiveMap instance with Objects types defined via the global AblyObjectsTypes interface
4444
// also checks that we can refer to the Objects types exported from 'ably' by referencing a LiveMap interface
45-
const root: Ably.LiveMap<CustomRoot> = await channel.object.get();
45+
const myObject: Ably.LiveMap<MyCustomObject> = await channel.object.get();
4646

47-
// check root has expected LiveMap TypeScript type methods
48-
const size: number = root.size();
47+
// check entrypoint has expected LiveMap TypeScript type methods
48+
const size: number = myObject.size();
4949

5050
// check custom user provided typings via AblyObjectsTypes are working:
5151
// any LiveMap.get() call can return undefined, as the LiveMap itself can be tombstoned (has empty state),
5252
// or referenced object is tombstoned.
53-
// keys on a root:
54-
const aNumber: number | undefined = root.get('numberKey');
55-
const aString: string | undefined = root.get('stringKey');
56-
const aBoolean: boolean | undefined = root.get('booleanKey');
57-
const userProvidedUndefined: string | undefined = root.get('couldBeUndefined');
58-
// objects on a root:
59-
const counter: Ably.LiveCounter | undefined = root.get('counterKey');
60-
const map: AblyObjectsTypes['root']['mapKey'] | undefined = root.get('mapKey');
53+
// keys on the entrypoint:
54+
const aNumber: number | undefined = myObject.get('numberKey');
55+
const aString: string | undefined = myObject.get('stringKey');
56+
const aBoolean: boolean | undefined = myObject.get('booleanKey');
57+
const userProvidedUndefined: string | undefined = myObject.get('couldBeUndefined');
58+
// objects on the entrypoint:
59+
const counter: Ably.LiveCounter | undefined = myObject.get('counterKey');
60+
const map: AblyObjectsTypes['object']['mapKey'] | undefined = myObject.get('mapKey');
6161
// check string literal types works
62-
// need to use nullish coalescing as we didn't actually create any data on the root,
62+
// need to use nullish coalescing as we didn't actually create any data on the entrypoint object,
6363
// so the next calls would fail. we only need to check that TypeScript types work
6464
const foo: 'bar' = map?.get('foo')!;
6565
const baz: 'qux' = map?.get('nestedMap')?.get('baz')!;
6666

6767
// check LiveMap subscription callback has correct TypeScript types
68-
const { unsubscribe } = root.subscribe(({ update }) => {
68+
const { unsubscribe } = myObject.subscribe(({ update }) => {
6969
// check update object infers keys from map type
7070
const typedKeyOnMap = update.stringKey;
7171
switch (typedKeyOnMap) {
@@ -89,6 +89,6 @@ globalThis.testAblyPackage = async function () {
8989
counterSubscribeResponse?.unsubscribe();
9090

9191
// check can provide custom types for the object.get() method, ignoring global AblyObjectsTypes interface
92-
const explicitRoot: Ably.LiveMap<ExplicitRootType> = await channel.object.get<ExplicitRootType>();
93-
const someOtherKey: string | undefined = explicitRoot.get('someOtherKey');
92+
const explicitObjectType: Ably.LiveMap<ExplicitObjectType> = await channel.object.get<ExplicitObjectType>();
93+
const someOtherKey: string | undefined = explicitObjectType.get('someOtherKey');
9494
};

0 commit comments

Comments
 (0)