From a7558ee74b6b8db3a433e719d2c2b870a0247b9a Mon Sep 17 00:00:00 2001 From: Lawrence Forooghian Date: Thu, 30 Nov 2023 11:05:43 -0300 Subject: [PATCH] Rename RealtimePresence module to RealtimePresenceModule MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To avoid a clash with the Types.RealtimePresence class (which describes the realtime presence API) when we remove the Types namespace in #909. This is ugly; it’s not consistent with the other modules, which don’t have "Module" in their name. I’d welcome suggestions of alternative things I could do here. --- README.md | 6 +++--- modules.d.ts | 10 +++++----- src/common/lib/client/baserealtime.ts | 2 +- src/common/lib/client/defaultrealtime.ts | 2 +- src/common/lib/client/modulesmap.ts | 2 +- src/common/lib/client/realtimechannel.ts | 2 +- src/platform/web/modules/realtimepresence.ts | 2 +- test/browser/modules.test.js | 18 +++++++++--------- 8 files changed, 22 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 309bae8705..6c95fc0bad 100644 --- a/README.md +++ b/README.md @@ -88,18 +88,18 @@ Aimed at those who are concerned about their app’s bundle size, the modular va The modular variant of the library provides: - a `BaseRealtime` class; -- various modules that add functionality to a `BaseRealtime` instance, such as `Rest`, `RealtimePresence`, etc. +- various modules that add functionality to a `BaseRealtime` instance, such as `Rest`, `RealtimePresenceModule`, etc. To use this variant of the library, import the `BaseRealtime` class from `ably/modules`, along with the modules that you wish to use. Then, pass these modules to the `BaseRealtime` constructor as shown in the example below: ```javascript -import { BaseRealtime, WebSocketTransport, FetchRequest, RealtimePresence } from 'ably/modules'; +import { BaseRealtime, WebSocketTransport, FetchRequest, RealtimePresenceModule } from 'ably/modules'; const options = { key: 'YOUR_ABLY_API_KEY' /* Replace with a real key from the Ably dashboard */ }; const client = new BaseRealtime(options, { WebSocketTransport, FetchRequest, - RealtimePresence + RealtimePresenceModule }); ``` diff --git a/modules.d.ts b/modules.d.ts index c621879024..88b80e2b50 100644 --- a/modules.d.ts +++ b/modules.d.ts @@ -70,13 +70,13 @@ export declare const MsgPack: unknown; * To create a client that includes this module, include it in the `ModulesMap` that you pass to the {@link BaseRealtime.constructor}: * * ```javascript - * import { BaseRealtime, WebSocketTransport, FetchRequest, RealtimePresence } from 'ably/modules'; - * const realtime = new BaseRealtime(options, { WebSocketTransport, FetchRequest, RealtimePresence }); + * import { BaseRealtime, WebSocketTransport, FetchRequest, RealtimePresenceModule } from 'ably/modules'; + * const realtime = new BaseRealtime(options, { WebSocketTransport, FetchRequest, RealtimePresenceModule }); * ``` * * If you do not provide this module, then attempting to access a channel’s {@link Types.RealtimeChannel.presence} property will cause a runtime error. */ -export declare const RealtimePresence: unknown; +export declare const RealtimePresenceModule: unknown; /** * Provides a {@link BaseRealtime} instance with the ability to establish a connection with the Ably realtime service using a [WebSocket](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API) connection. @@ -197,9 +197,9 @@ export interface ModulesMap { MsgPack?: typeof MsgPack; /** - * See {@link RealtimePresence | documentation for the `RealtimePresence` module}. + * See {@link RealtimePresenceModule | documentation for the `RealtimePresenceModule` module}. */ - RealtimePresence?: typeof RealtimePresence; + RealtimePresenceModule?: typeof RealtimePresenceModule; /** * See {@link WebSocketTransport | documentation for the `WebSocketTransport` module}. diff --git a/src/common/lib/client/baserealtime.ts b/src/common/lib/client/baserealtime.ts index 821b86b6e5..7d01dd3413 100644 --- a/src/common/lib/client/baserealtime.ts +++ b/src/common/lib/client/baserealtime.ts @@ -29,7 +29,7 @@ class BaseRealtime extends BaseClient { super(options, modules); Logger.logAction(Logger.LOG_MINOR, 'Realtime()', ''); this._additionalTransportImplementations = BaseRealtime.transportImplementationsFromModules(modules); - this._RealtimePresence = modules.RealtimePresence ?? null; + this._RealtimePresence = modules.RealtimePresenceModule ?? null; this._decodeVcdiff = (modules.Vcdiff ?? (Platform.Vcdiff.supported && Platform.Vcdiff.bundledDecode)) || null; this.connection = new Connection(this, this.options); this._channels = new Channels(this); diff --git a/src/common/lib/client/defaultrealtime.ts b/src/common/lib/client/defaultrealtime.ts index 9e5f581dff..5d82b628e1 100644 --- a/src/common/lib/client/defaultrealtime.ts +++ b/src/common/lib/client/defaultrealtime.ts @@ -30,7 +30,7 @@ export class DefaultRealtime extends BaseRealtime { ...allCommonModules, Crypto: DefaultRealtime.Crypto ?? undefined, MsgPack, - RealtimePresence: { + RealtimePresenceModule: { RealtimePresence, presenceMessageFromValues, presenceMessagesFromValuesArray, diff --git a/src/common/lib/client/modulesmap.ts b/src/common/lib/client/modulesmap.ts index 7a3fb55b5a..635cf1c8be 100644 --- a/src/common/lib/client/modulesmap.ts +++ b/src/common/lib/client/modulesmap.ts @@ -25,7 +25,7 @@ export interface ModulesMap { Rest?: typeof Rest; Crypto?: IUntypedCryptoStatic; MsgPack?: MsgPack; - RealtimePresence?: RealtimePresenceModule; + RealtimePresenceModule?: RealtimePresenceModule; WebSocketTransport?: TransportInitialiser; XHRPolling?: TransportInitialiser; XHRStreaming?: TransportInitialiser; diff --git a/src/common/lib/client/realtimechannel.ts b/src/common/lib/client/realtimechannel.ts index 27d409ea38..5896c1a312 100644 --- a/src/common/lib/client/realtimechannel.ts +++ b/src/common/lib/client/realtimechannel.ts @@ -67,7 +67,7 @@ class RealtimeChannel extends EventEmitter { private _presence: RealtimePresence | null; get presence(): RealtimePresence { if (!this._presence) { - Utils.throwMissingModuleError('RealtimePresence'); + Utils.throwMissingModuleError('RealtimePresenceModule'); } return this._presence; } diff --git a/src/platform/web/modules/realtimepresence.ts b/src/platform/web/modules/realtimepresence.ts index 850bcfa2ad..3f069459fd 100644 --- a/src/platform/web/modules/realtimepresence.ts +++ b/src/platform/web/modules/realtimepresence.ts @@ -11,4 +11,4 @@ const RealtimePresence: RealtimePresenceModule = { presenceMessagesFromValuesArray, }; -export { RealtimePresence }; +export { RealtimePresence as RealtimePresenceModule }; diff --git a/test/browser/modules.test.js b/test/browser/modules.test.js index 22b16f8672..6152441397 100644 --- a/test/browser/modules.test.js +++ b/test/browser/modules.test.js @@ -10,7 +10,7 @@ import { decodeEncryptedMessages, Crypto, MsgPack, - RealtimePresence, + RealtimePresenceModule, decodePresenceMessage, decodePresenceMessages, constructPresenceMessage, @@ -86,7 +86,7 @@ function registerAblyModulesTests(helper, registerDeltaTests) { }, { description: 'call channel’s `presence.history()`', - additionalRealtimeModules: { RealtimePresence }, + additionalRealtimeModules: { RealtimePresenceModule }, action: (client) => client.channels.get('channel').presence.history(), }, { @@ -452,13 +452,13 @@ function registerAblyModulesTests(helper, registerDeltaTests) { }); }); - describe('RealtimePresence', () => { - describe('BaseRealtime without RealtimePresence', () => { + describe('RealtimePresenceModule', () => { + describe('BaseRealtime without RealtimePresenceModule', () => { it('throws an error when attempting to access the `presence` property', () => { const client = new BaseRealtime(ablyClientOptions(), { WebSocketTransport, FetchRequest }); const channel = client.channels.get('channel'); - expect(() => channel.presence).to.throw('RealtimePresence module not provided'); + expect(() => channel.presence).to.throw('RealtimePresenceModule module not provided'); }); it('doesn’t break when it receives a PRESENCE ProtocolMessage', async () => { @@ -472,7 +472,7 @@ function registerAblyModulesTests(helper, registerDeltaTests) { const txClient = new BaseRealtime(ablyClientOptions({ clientId: randomString() }), { WebSocketTransport, FetchRequest, - RealtimePresence, + RealtimePresenceModule, }); const txChannel = txClient.channels.get('channel'); @@ -485,18 +485,18 @@ function registerAblyModulesTests(helper, registerDeltaTests) { }); }); - describe('BaseRealtime with RealtimePresence', () => { + describe('BaseRealtime with RealtimePresenceModule', () => { it('offers realtime presence functionality', async () => { const rxChannel = new BaseRealtime(ablyClientOptions(), { WebSocketTransport, FetchRequest, - RealtimePresence, + RealtimePresenceModule, }).channels.get('channel'); const txClientId = randomString(); const txChannel = new BaseRealtime(ablyClientOptions({ clientId: txClientId }), { WebSocketTransport, FetchRequest, - RealtimePresence, + RealtimePresenceModule, }).channels.get('channel'); let resolveRxPresenceMessagePromise;