Skip to content

Commit

Permalink
feat(listener): add support for includeAllVersions
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoerge committed Feb 6, 2025
1 parent 99cfa97 commit 20a44bf
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/data/listen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const possibleOptions = [
'includePreviousRevision',
'includeResult',
'includeMutations',
'includeAllVersions',
'visibility',
'effectFormat',
'tag',
Expand Down
11 changes: 11 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,17 @@ export interface ListenOptions {
*/
includePreviousRevision?: boolean

/**
* Whether to include events for drafts and versions. As of API Version >= v2025-02-19, only events
* for published documents will be included by default.
* If you need events from drafts and versions, set this to `true`.
* Note: Keep in mind that additional document variants may be introduced in the future, so it's
* recommended to respond to events in a way that's tolerant of potential future variants, e.g. by
* explicitly checking whether the event is for a draft or a version.
* @defaultValue `false`
*/
includeAllVersions?: boolean

/**
* Whether events should be sent as soon as a transaction has been committed (`transaction`, default),
* or only after they are available for queries (query). Note that this is on a best-effort basis,
Expand Down
16 changes: 16 additions & 0 deletions test/listen.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,22 @@ describe.skipIf(typeof EdgeRuntime === 'string' || typeof document !== 'undefine
server.close()
})

test('listener sends includeAllVersions=true if given', async () => {
expect.assertions(1)

const {server, client} = await testSse(({request, channel}) => {
expect(request.url).toContain('includeAllVersions=true')

channel!.send({event: 'welcome'})
})

await firstValueFrom(
client.listen('*', {}, {events: ['welcome'], includeAllVersions: true}),
{defaultValue: null},
)
server.close()
})

test('reconnects if disconnected', async () => {
expect.assertions(1)

Expand Down

0 comments on commit 20a44bf

Please sign in to comment.