diff --git a/src/Model.test.ts b/src/Model.test.ts index e764b0e9..193d9d13 100644 --- a/src/Model.test.ts +++ b/src/Model.test.ts @@ -33,7 +33,7 @@ vi.mock('./stream/StreamFactory', () => { async subscribe() {} unsubscribe(): void {} async dispose() {} - async sync() {} + async replay() {} } const streams: { [key: string]: IStream } = {}; @@ -157,7 +157,7 @@ describe('Model', () => { it('rewinds to the correct point in the stream', async ({ channelName, ably, logger, streams }) => { const stream = streams.newStream({ channelName }); - stream.sync = vi.fn(); + stream.replay = vi.fn(); let i = 0; const sync = vi.fn(async () => { @@ -182,13 +182,13 @@ describe('Model', () => { }); expect(sync).toHaveBeenCalledOnce(); - expect(stream.sync).toHaveBeenCalledOnce(); - expect(stream.sync).toHaveBeenNthCalledWith(1, '123'); + expect(stream.replay).toHaveBeenCalledOnce(); + expect(stream.replay).toHaveBeenNthCalledWith(1, '123'); await model.$sync(); expect(sync).toHaveBeenCalledTimes(2); - expect(stream.sync).toHaveBeenCalledTimes(2); - expect(stream.sync).toHaveBeenNthCalledWith(2, '456'); + expect(stream.replay).toHaveBeenCalledTimes(2); + expect(stream.replay).toHaveBeenNthCalledWith(2, '456'); }); it('pauses and resumes the model', async ({ channelName, ably, logger, streams }) => { diff --git a/src/Model.ts b/src/Model.ts index 23f5beeb..0a941b2b 100644 --- a/src/Model.ts +++ b/src/Model.ts @@ -322,7 +322,7 @@ export default class Model extends EventEmitter { ); const stream = new Stream({ ably, logger, channelName: 'foobar' }); - const synced = stream.sync('0'); + const replayPromise = stream.replay('0'); await statePromise(stream, StreamState.PREPARING); - await expect(synced).resolves.toBeUndefined(); + await expect(replayPromise).resolves.toBeUndefined(); expect(stream.state).toBe(StreamState.READY); expect(channel.subscribe).toHaveBeenCalledOnce(); @@ -82,10 +82,10 @@ describe('Stream', () => { ); const stream = new Stream({ ably, logger, channelName: 'foobar' }); - const synced = stream.sync('0'); + const replayPromise = stream.replay('0'); await statePromise(stream, StreamState.PREPARING); - await expect(synced).rejects.toThrow(/the channel was already attached when calling subscribe()/); + await expect(replayPromise).rejects.toThrow(/the channel was already attached when calling subscribe()/); expect(stream.state).toBe(StreamState.ERRORED); expect(channel.subscribe).toHaveBeenCalledTimes(1); @@ -123,10 +123,10 @@ describe('Stream', () => { }); const stream = new Stream({ ably, logger, channelName: 'foobar' }); - let synced = stream.sync('1'); + let replayPromise = stream.replay('1'); await statePromise(stream, StreamState.PREPARING); - await expect(synced).rejects.toThrow(/insufficient history to seek to sequenceID 1 in stream/); + await expect(replayPromise).rejects.toThrow(/insufficient history to seek to sequenceID 1 in stream/); expect(stream.state).toBe(StreamState.ERRORED); expect(channel.subscribe).toHaveBeenCalledOnce(); @@ -135,10 +135,10 @@ describe('Stream', () => { expect(channel.history).toHaveBeenNthCalledWith(2, { untilAttach: true, limit: HISTORY_PAGE_SIZE }); i = 0; - synced = stream.sync('2'); + replayPromise = stream.replay('2'); await statePromise(stream, StreamState.PREPARING); - await expect(synced).resolves.toBeUndefined(); + await expect(replayPromise).resolves.toBeUndefined(); expect(stream.state).toBe(StreamState.READY); expect(ably.channels.release).toHaveBeenCalledOnce(); @@ -184,10 +184,10 @@ describe('Stream', () => { }); const stream = new Stream({ ably, logger, channelName: 'foobar' }); - let synced = stream.sync('1'); + let replayPromise = stream.replay('1'); await statePromise(stream, StreamState.PREPARING); - await expect(synced).rejects.toThrow(/insufficient history to seek to sequenceID 1 in stream/); + await expect(replayPromise).rejects.toThrow(/insufficient history to seek to sequenceID 1 in stream/); expect(stream.state).toBe(StreamState.ERRORED); expect(channel.subscribe).toHaveBeenCalledOnce(); @@ -197,10 +197,10 @@ describe('Stream', () => { expect(channel.history).toHaveBeenNthCalledWith(3, { untilAttach: true, limit: HISTORY_PAGE_SIZE }); i = 0; - synced = stream.sync('2'); + replayPromise = stream.replay('2'); await statePromise(stream, StreamState.PREPARING); - await expect(synced).resolves.toBeUndefined(); + await expect(replayPromise).resolves.toBeUndefined(); expect(stream.state).toBe(StreamState.READY); expect(ably.channels.release).toHaveBeenCalledOnce(); @@ -230,7 +230,7 @@ describe('Stream', () => { }); const stream = new Stream({ ably, logger, channelName }); - await stream.sync('0'); + await stream.replay('0'); await statePromise(stream, StreamState.READY); const subscriptionSpy = vi.fn(); @@ -273,7 +273,7 @@ describe('Stream', () => { const subscriptionSpy = vi.fn(); stream.subscribe(subscriptionSpy); - await stream.sync('3'); + await stream.replay('3'); await statePromise(stream, StreamState.READY); // live messages @@ -322,7 +322,7 @@ describe('Stream', () => { const subscriptionSpy = vi.fn(); stream.subscribe(subscriptionSpy); - await stream.sync('1'); + await stream.replay('1'); await statePromise(stream, StreamState.READY); // live messages @@ -359,7 +359,7 @@ describe('Stream', () => { ); const stream = new Stream({ ably, logger, channelName }); - await stream.sync('0'); + await stream.replay('0'); await statePromise(stream, StreamState.READY); const subscriptionSpy1 = vi.fn(); @@ -402,7 +402,7 @@ describe('Stream', () => { ); const stream = new Stream({ ably, logger, channelName }); - await stream.sync('0'); + await stream.replay('0'); await statePromise(stream, StreamState.READY); const subscriptionSpy = vi.fn(); @@ -443,7 +443,7 @@ describe('Stream', () => { ); const stream = new Stream({ ably, logger, channelName }); - await stream.sync('0'); + await stream.replay('0'); await statePromise(stream, StreamState.READY); const subscriptionSpy1 = vi.fn(); @@ -488,7 +488,7 @@ describe('Stream', () => { ); const stream = new Stream({ ably, logger, channelName }); - await stream.sync('0'); + await stream.replay('0'); await statePromise(stream, StreamState.READY); expect(channel.subscribe).toHaveBeenCalledOnce(); @@ -519,7 +519,7 @@ describe('Stream', () => { ably.channels.release = vi.fn(); const stream = new Stream({ ably, logger, channelName }); - await stream.sync('0'); + await stream.replay('0'); await statePromise(stream, StreamState.READY); expect(channel.subscribe).toHaveBeenCalledOnce(); @@ -555,7 +555,7 @@ describe('Stream', () => { }); const stream = new Stream({ ably, logger, channelName }); - await stream.sync('0'); + await stream.replay('0'); await statePromise(stream, StreamState.READY); expect(channel.subscribe).toHaveBeenCalledOnce(); diff --git a/src/stream/Stream.ts b/src/stream/Stream.ts index c0eade3a..1670bd86 100644 --- a/src/stream/Stream.ts +++ b/src/stream/Stream.ts @@ -82,7 +82,7 @@ export interface IStream { get channelName(): string; pause(): Promise; resume(): Promise; - sync(sequenceID: string): Promise; + replay(sequenceID: string): Promise; subscribe(callback: StandardCallback): void; unsubscribe(callback: StandardCallback): void; dispose(reason?: AblyTypes.ErrorInfo | string): Promise; @@ -170,8 +170,8 @@ export default class Stream extends EventEmitter