From 20a44bf6a756cf6ef27385e87fe69e66deb5c0e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rge=20N=C3=A6ss?= Date: Wed, 5 Feb 2025 11:40:16 +0100 Subject: [PATCH] feat(listener): add support for includeAllVersions --- src/data/listen.ts | 1 + src/types.ts | 11 +++++++++++ test/listen.test.ts | 16 ++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/src/data/listen.ts b/src/data/listen.ts index 5805175d..7a050cdc 100644 --- a/src/data/listen.ts +++ b/src/data/listen.ts @@ -26,6 +26,7 @@ const possibleOptions = [ 'includePreviousRevision', 'includeResult', 'includeMutations', + 'includeAllVersions', 'visibility', 'effectFormat', 'tag', diff --git a/src/types.ts b/src/types.ts index ca4b7127..61038fbe 100644 --- a/src/types.ts +++ b/src/types.ts @@ -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, diff --git a/test/listen.test.ts b/test/listen.test.ts index 9cfdd8d8..d20fa0d1 100644 --- a/test/listen.test.ts +++ b/test/listen.test.ts @@ -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)