Skip to content

Commit

Permalink
client: expose shape|stream.lastOffset.
Browse files Browse the repository at this point in the history
  • Loading branch information
thruflo committed Nov 18, 2024
1 parent 640fc04 commit 9a6eaf8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/typescript-client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export interface ShapeStreamInterface<T extends Row<unknown> = Row> {
isConnected(): boolean

isUpToDate: boolean
lastOffset: Offset
shapeHandle?: string
}

Expand Down Expand Up @@ -249,6 +250,10 @@ export class ShapeStream<T extends Row<unknown> = Row>
return this.#isUpToDate
}

get lastOffset() {
return this.#lastOffset
}

get error() {
return this.#error
}
Expand Down
4 changes: 4 additions & 0 deletions packages/typescript-client/src/shape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ export class Shape<T extends Row<unknown> = Row> {
return this.#stream.isUpToDate
}

get lastOffset(): boolean {
return this.#stream.lastOffset

Check failure on line 74 in packages/typescript-client/src/shape.ts

View workflow job for this annotation

GitHub Actions / Build and test (packages/typescript-client)

Unhandled error

TypeCheckError: Type 'Offset' is not assignable to type 'boolean'. Type '`${number}_${number}`' is not assignable to type 'boolean'. ❯ src/shape.ts:74:5
}

get rows(): Promise<T[]> {
return this.value.then((v) => Array.from(v.values()))
}
Expand Down
17 changes: 17 additions & 0 deletions packages/typescript-client/test/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Check failure on line 353 in packages/typescript-client/test/client.test.ts

View workflow job for this annotation

GitHub Actions / Check packages/typescript-client

Replace `"-1"` with `'-1'`

Check failure on line 353 in packages/typescript-client/test/client.test.ts

View workflow job for this annotation

GitHub Actions / Check packages/typescript-client

Strings must use backtick
expect(shape.lastOffset).toBe(shapeStream.lastOffset)

shape.unsubscribeAll()
})

it(`should honour replica: full`, async ({
insertIssues,
updateIssue,
Expand Down

0 comments on commit 9a6eaf8

Please sign in to comment.