@electric-sql/client 0.7.3 → 0.8.0
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/README.md +76 -1
- package/dist/cjs/index.cjs +230 -215
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.browser.mjs +5 -4
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.d.ts +19 -9
- package/dist/index.legacy-esm.js +226 -211
- package/dist/index.legacy-esm.js.map +1 -1
- package/dist/index.mjs +230 -215
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +71 -76
- package/src/error.ts +55 -0
- package/src/fetch.ts +1 -1
- package/src/parser.ts +2 -1
- package/src/shape.ts +4 -9
package/src/error.ts
CHANGED
|
@@ -46,6 +46,60 @@ export class FetchError extends Error {
|
|
|
46
46
|
export class FetchBackoffAbortError extends Error {
|
|
47
47
|
constructor() {
|
|
48
48
|
super(`Fetch with backoff aborted`)
|
|
49
|
+
this.name = `FetchBackoffAbortError`
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export class InvalidShapeOptionsError extends Error {
|
|
54
|
+
constructor(message: string) {
|
|
55
|
+
super(message)
|
|
56
|
+
this.name = `InvalidShapeOptionsError`
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export class MissingShapeUrlError extends Error {
|
|
61
|
+
constructor() {
|
|
62
|
+
super(`Invalid shape options: missing required url parameter`)
|
|
63
|
+
this.name = `MissingShapeUrlError`
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export class InvalidSignalError extends Error {
|
|
68
|
+
constructor() {
|
|
69
|
+
super(`Invalid signal option. It must be an instance of AbortSignal.`)
|
|
70
|
+
this.name = `InvalidSignalError`
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export class MissingShapeHandleError extends Error {
|
|
75
|
+
constructor() {
|
|
76
|
+
super(
|
|
77
|
+
`shapeHandle is required if this isn't an initial fetch (i.e. offset > -1)`
|
|
78
|
+
)
|
|
79
|
+
this.name = `MissingShapeHandleError`
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export class ReservedParamError extends Error {
|
|
84
|
+
constructor(reservedParams: string[]) {
|
|
85
|
+
super(
|
|
86
|
+
`Cannot use reserved Electric parameter names in custom params: ${reservedParams.join(`, `)}`
|
|
87
|
+
)
|
|
88
|
+
this.name = `ReservedParamError`
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export class ParserNullValueError extends Error {
|
|
93
|
+
constructor(columnName: string) {
|
|
94
|
+
super(`Column "${columnName ?? `unknown`}" does not allow NULL values`)
|
|
95
|
+
this.name = `ParserNullValueError`
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export class ShapeStreamAlreadyRunningError extends Error {
|
|
100
|
+
constructor() {
|
|
101
|
+
super(`ShapeStream is already running`)
|
|
102
|
+
this.name = `ShapeStreamAlreadyRunningError`
|
|
49
103
|
}
|
|
50
104
|
}
|
|
51
105
|
|
|
@@ -56,6 +110,7 @@ export class MissingHeadersError extends Error {
|
|
|
56
110
|
msg += `- ${h}\n`
|
|
57
111
|
})
|
|
58
112
|
msg += `\nThis is often due to a proxy not setting CORS correctly so that all Electric headers can be read by the client.`
|
|
113
|
+
msg += `\nFor more information visit the troubleshooting guide: /docs/guides/troubleshooting/missing-headers`
|
|
59
114
|
super(msg)
|
|
60
115
|
}
|
|
61
116
|
}
|
package/src/fetch.ts
CHANGED
|
@@ -171,7 +171,7 @@ export function createFetchWithResponseHeadersCheck(
|
|
|
171
171
|
const missingHeaders: Array<string> = []
|
|
172
172
|
|
|
173
173
|
const addMissingHeaders = (requiredHeaders: Array<string>) =>
|
|
174
|
-
requiredHeaders.filter((h) => !headers.has(h))
|
|
174
|
+
missingHeaders.push(...requiredHeaders.filter((h) => !headers.has(h)))
|
|
175
175
|
addMissingHeaders(requiredElectricResponseHeaders)
|
|
176
176
|
|
|
177
177
|
const input = args[0]
|
package/src/parser.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ColumnInfo, GetExtensions, Message, Row, Schema, Value } from './types'
|
|
2
|
+
import { ParserNullValueError } from './error'
|
|
2
3
|
|
|
3
4
|
type NullToken = null | `NULL`
|
|
4
5
|
type Token = Exclude<string, NullToken>
|
|
@@ -162,7 +163,7 @@ function makeNullableParser<Extensions>(
|
|
|
162
163
|
return (value: NullableToken) => {
|
|
163
164
|
if (isPgNull(value)) {
|
|
164
165
|
if (!isNullable) {
|
|
165
|
-
throw new
|
|
166
|
+
throw new ParserNullValueError(columnName ?? `unknown`)
|
|
166
167
|
}
|
|
167
168
|
return null
|
|
168
169
|
}
|
package/src/shape.ts
CHANGED
|
@@ -55,15 +55,6 @@ export class Shape<T extends Row<unknown> = Row> {
|
|
|
55
55
|
this.#process.bind(this),
|
|
56
56
|
this.#handleError.bind(this)
|
|
57
57
|
)
|
|
58
|
-
const unsubscribe = this.#stream.subscribeOnceToUpToDate(
|
|
59
|
-
() => {
|
|
60
|
-
unsubscribe()
|
|
61
|
-
},
|
|
62
|
-
(e) => {
|
|
63
|
-
this.#handleError(e)
|
|
64
|
-
throw e
|
|
65
|
-
}
|
|
66
|
-
)
|
|
67
58
|
}
|
|
68
59
|
|
|
69
60
|
get isUpToDate(): boolean {
|
|
@@ -74,6 +65,10 @@ export class Shape<T extends Row<unknown> = Row> {
|
|
|
74
65
|
return this.#stream.lastOffset
|
|
75
66
|
}
|
|
76
67
|
|
|
68
|
+
get handle(): string | undefined {
|
|
69
|
+
return this.#stream.shapeHandle
|
|
70
|
+
}
|
|
71
|
+
|
|
77
72
|
get rows(): Promise<T[]> {
|
|
78
73
|
return this.value.then((v) => Array.from(v.values()))
|
|
79
74
|
}
|