Skip to content

Commit 214bdd6

Browse files
committed
feat: denote end of injected subset snapshot with an additional message
1 parent 32ea8f0 commit 214bdd6

4 files changed

Lines changed: 18 additions & 12 deletions

File tree

.changeset/swift-brooms-double.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@electric-sql/client': minor
3+
---
4+
5+
feat: denote end of injected subset snapshot with an additional message

packages/typescript-client/src/client.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
GetExtensions,
88
ChangeMessage,
99
SnapshotMetadata,
10+
SubsetParams,
1011
} from './types'
1112
import { MessageParser, Parser, TransformFunction } from './parser'
1213
import { ColumnMapper, encodeWhereClause } from './column-mapper'
@@ -128,14 +129,6 @@ export type ExternalParamsRecord<T extends Row<unknown> = Row> = {
128129
[K in string]: ParamValue | undefined
129130
} & Partial<PostgresParams<T>> & { [K in ReservedParamKeys]?: never }
130131

131-
export type SubsetParams = {
132-
where?: string
133-
params?: Record<string, string>
134-
limit?: number
135-
offset?: number
136-
orderBy?: string
137-
}
138-
139132
type ReservedParamKeys =
140133
| typeof LIVE_CACHE_BUSTER_QUERY_PARAM
141134
| typeof SHAPE_HANDLE_QUERY_PARAM
@@ -1457,6 +1450,7 @@ export class ShapeStream<T extends Row<unknown> = Row>
14571450

14581451
const dataWithEndBoundary = (data as Array<Message<T>>).concat([
14591452
{ headers: { control: `snapshot-end`, ...metadata } },
1453+
{ headers: { control: `subset-end`, ...opts } },
14601454
])
14611455

14621456
this.#snapshotTracker.addSnapshot(

packages/typescript-client/src/helpers.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,9 @@ export function isUpToDateMessage<T extends Row<unknown> = Row>(
6666
* If we are not in SSE mode this function will return undefined.
6767
*/
6868
export function getOffset(message: ControlMessage): Offset | undefined {
69+
if (message.headers.control != 'up-to-date') return
6970
const lsn = message.headers.global_last_seen_lsn
70-
if (!lsn) {
71-
return
72-
}
73-
return `${lsn}_0` as Offset
71+
return lsn ? (`${lsn}_0` as Offset) : undefined
7472
}
7573

7674
/**

packages/typescript-client/src/types.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,22 @@ export type MoveTag = string
6868
*/
6969
export type MoveOutPattern = { pos: number; value: string }
7070

71+
export type SubsetParams = {
72+
where?: string
73+
params?: Record<string, string>
74+
limit?: number
75+
offset?: number
76+
orderBy?: string
77+
}
78+
7179
export type ControlMessage = {
7280
headers:
7381
| (Header & {
7482
control: `up-to-date` | `must-refetch`
7583
global_last_seen_lsn?: string
7684
})
7785
| (Header & { control: `snapshot-end` } & PostgresSnapshot)
86+
| ({ control: `subset-end` } & SubsetParams)
7887
}
7988

8089
export type EventMessage = {

0 commit comments

Comments
 (0)