From 9a6eaf8f25fe488d0007fab99fd070143e37c2f3 Mon Sep 17 00:00:00 2001 From: James Arthur Date: Mon, 18 Nov 2024 19:37:46 +0100 Subject: [PATCH] client: expose `shape|stream.lastOffset`. --- packages/typescript-client/src/client.ts | 5 +++++ packages/typescript-client/src/shape.ts | 4 ++++ packages/typescript-client/test/client.test.ts | 17 +++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/packages/typescript-client/src/client.ts b/packages/typescript-client/src/client.ts index 57c0695596..8089b33e24 100644 --- a/packages/typescript-client/src/client.ts +++ b/packages/typescript-client/src/client.ts @@ -144,6 +144,7 @@ export interface ShapeStreamInterface = Row> { isConnected(): boolean isUpToDate: boolean + lastOffset: Offset shapeHandle?: string } @@ -249,6 +250,10 @@ export class ShapeStream = Row> return this.#isUpToDate } + get lastOffset() { + return this.#lastOffset + } + get error() { return this.#error } diff --git a/packages/typescript-client/src/shape.ts b/packages/typescript-client/src/shape.ts index 6ea1529f3c..1b9e7fdfd9 100644 --- a/packages/typescript-client/src/shape.ts +++ b/packages/typescript-client/src/shape.ts @@ -70,6 +70,10 @@ export class Shape = Row> { return this.#stream.isUpToDate } + get lastOffset(): boolean { + return this.#stream.lastOffset + } + get rows(): Promise { return this.value.then((v) => Array.from(v.values())) } diff --git a/packages/typescript-client/test/client.test.ts b/packages/typescript-client/test/client.test.ts index 168447a160..7485d93981 100644 --- a/packages/typescript-client/test/client.test.ts +++ b/packages/typescript-client/test/client.test.ts @@ -339,6 +339,23 @@ describe(`Shape`, () => { expect(shapeStream.isLoading()).false }) + it(`should expose lastOffset`, async ({ issuesTableUrl }) => { + const shapeStream = new ShapeStream({ + url: `${BASE_URL}/v1/shape`, + table: issuesTableUrl, + fetchClient: async (input, init) => { + await sleep(20) + return fetch(input, init) + }, + }) + const shape = new Shape(shapeStream) + + expect(shapeStream.lastOffset).toBe("-1") + expect(shape.lastOffset).toBe(shapeStream.lastOffset) + + shape.unsubscribeAll() + }) + it(`should honour replica: full`, async ({ insertIssues, updateIssue,