@electric-sql/client 1.2.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +4 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +34 -3
- package/dist/index.browser.mjs +2 -2
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.d.ts +34 -3
- package/dist/index.legacy-esm.js +4 -1
- package/dist/index.legacy-esm.js.map +1 -1
- package/dist/index.mjs +4 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/client.ts +7 -1
- package/src/types.ts +33 -2
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@electric-sql/client",
|
|
3
3
|
"description": "Postgres everywhere - your data, in sync, wherever you need it.",
|
|
4
|
-
"version": "1.2.
|
|
4
|
+
"version": "1.2.1",
|
|
5
5
|
"author": "ElectricSQL team and contributors.",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://github.com/electric-sql/electric/issues"
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"@types/uuid": "^10.0.0",
|
|
15
15
|
"@typescript-eslint/eslint-plugin": "^7.14.1",
|
|
16
16
|
"@typescript-eslint/parser": "^7.14.1",
|
|
17
|
-
"@vitest/coverage-istanbul": "
|
|
17
|
+
"@vitest/coverage-istanbul": "4.0.15",
|
|
18
18
|
"cache-control-parser": "^2.0.6",
|
|
19
19
|
"concurrently": "^8.2.2",
|
|
20
20
|
"eslint": "^8.57.0",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"tsup": "^8.0.1",
|
|
29
29
|
"typescript": "^5.5.2",
|
|
30
30
|
"uuid": "^10.0.0",
|
|
31
|
-
"vitest": "^
|
|
31
|
+
"vitest": "^4.0.15",
|
|
32
32
|
"vitest-localstorage-mock": "^0.1.2"
|
|
33
33
|
},
|
|
34
34
|
"type": "module",
|
package/src/client.ts
CHANGED
|
@@ -1132,10 +1132,16 @@ export class ShapeStream<T extends Row<unknown> = Row>
|
|
|
1132
1132
|
// Track when the SSE connection starts
|
|
1133
1133
|
this.#lastSseConnectionStartTime = Date.now()
|
|
1134
1134
|
|
|
1135
|
+
// Add Accept header for SSE requests
|
|
1136
|
+
const sseHeaders = {
|
|
1137
|
+
...headers,
|
|
1138
|
+
Accept: `text/event-stream`,
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1135
1141
|
try {
|
|
1136
1142
|
let buffer: Array<Message<T>> = []
|
|
1137
1143
|
await fetchEventSource(fetchUrl.toString(), {
|
|
1138
|
-
headers,
|
|
1144
|
+
headers: sseHeaders,
|
|
1139
1145
|
fetch,
|
|
1140
1146
|
onopen: async (response: Response) => {
|
|
1141
1147
|
this.#connected = true
|
package/src/types.ts
CHANGED
|
@@ -43,10 +43,30 @@ export type NormalizedPgSnapshot = {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
interface Header {
|
|
46
|
-
[key: Exclude<string, `operation` | `control`>]: Value
|
|
46
|
+
[key: Exclude<string, `operation` | `control` | `event`>]: Value
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
export type Operation = `insert` | `update` | `delete`
|
|
50
|
+
/**
|
|
51
|
+
* A tag is a string identifying a reason for this row to be part of the shape.
|
|
52
|
+
*
|
|
53
|
+
* Tags can be composite, but they are always sent as a single string. Compound tags
|
|
54
|
+
* are separated by `|`. It's up to the client to split the tag into its components
|
|
55
|
+
* in order to react to move-outs correctly. Tag parts are guaranteed to not contain an
|
|
56
|
+
* unescaped `|` character (escaped as `\\|`) or be a literal `*`.
|
|
57
|
+
*
|
|
58
|
+
* Composite tag width is guaranteed to be fixed for a given shape.
|
|
59
|
+
*/
|
|
60
|
+
export type MoveTag = string
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* A move-out pattern is a position and a value. The position is the index of the column
|
|
64
|
+
* that is being moved out. The value is the value of the column that is being moved out.
|
|
65
|
+
*
|
|
66
|
+
* Tag width and value order is fixed for a given shape, so the client can determine
|
|
67
|
+
* which tags match this pattern.
|
|
68
|
+
*/
|
|
69
|
+
export type MoveOutPattern = { pos: number; value: string }
|
|
50
70
|
|
|
51
71
|
export type ControlMessage = {
|
|
52
72
|
headers:
|
|
@@ -57,16 +77,27 @@ export type ControlMessage = {
|
|
|
57
77
|
| (Header & { control: `snapshot-end` } & PostgresSnapshot)
|
|
58
78
|
}
|
|
59
79
|
|
|
80
|
+
export type EventMessage = {
|
|
81
|
+
headers: Header & { event: `move-out`; patterns: MoveOutPattern[] }
|
|
82
|
+
}
|
|
83
|
+
|
|
60
84
|
export type ChangeMessage<T extends Row<unknown> = Row> = {
|
|
61
85
|
key: string
|
|
62
86
|
value: T
|
|
63
87
|
old_value?: Partial<T> // Only provided for updates if `replica` is `full`
|
|
64
|
-
headers: Header & {
|
|
88
|
+
headers: Header & {
|
|
89
|
+
operation: Operation
|
|
90
|
+
txids?: number[]
|
|
91
|
+
/** Tags will always be present for changes if the shape has a subquery in its where clause, and are omitted otherwise.*/
|
|
92
|
+
tags?: MoveTag[]
|
|
93
|
+
removed_tags?: MoveTag[]
|
|
94
|
+
}
|
|
65
95
|
}
|
|
66
96
|
|
|
67
97
|
// Define the type for a record
|
|
68
98
|
export type Message<T extends Row<unknown> = Row> =
|
|
69
99
|
| ControlMessage
|
|
100
|
+
| EventMessage
|
|
70
101
|
| ChangeMessage<T>
|
|
71
102
|
|
|
72
103
|
/**
|