@electric-sql/client 0.7.3 → 0.9.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 CHANGED
@@ -51,17 +51,19 @@ import { ShapeStream } from '@electric-sql/client'
51
51
  // Passes subscribers rows as they're inserted, updated, or deleted
52
52
  const stream = new ShapeStream({
53
53
  url: `${BASE_URL}/v1/shape`,
54
- table: `foo`,
54
+ params: {
55
+ table: `foo`
56
+ }
55
57
  })
56
58
 
57
59
  // You can also add custom headers and URL parameters
58
60
  const streamWithParams = new ShapeStream({
59
61
  url: `${BASE_URL}/v1/shape`,
60
- table: `foo`,
61
62
  headers: {
62
63
  'Authorization': 'Bearer token'
63
64
  },
64
65
  params: {
66
+ table: `foo`,
65
67
  'custom-param': 'value'
66
68
  }
67
69
  })
@@ -80,7 +82,9 @@ import { ShapeStream, Shape } from '@electric-sql/client'
80
82
 
81
83
  const stream = new ShapeStream({
82
84
  url: `${BASE_URL}/v1/shape`,
83
- table: `foo`,
85
+ params: {
86
+ table: `foo`
87
+ }
84
88
  })
85
89
  const shape = new Shape(stream)
86
90
 
@@ -93,4 +97,81 @@ shape.subscribe(({ rows }) => {
93
97
  }
94
98
  ```
95
99
 
96
- See the [Docs](https://electric-sql.com) and [Examples](https://electric-sql.com/examples/basic) for more information.
100
+ ### Error Handling
101
+
102
+ The ShapeStream provides two ways to handle errors:
103
+
104
+ 1. Using the `onError` handler:
105
+ ```typescript
106
+ const stream = new ShapeStream({
107
+ url: `${BASE_URL}/v1/shape`,
108
+ params: {
109
+ table: `foo`
110
+ },
111
+ onError: (error) => {
112
+ // Handle all stream errors here
113
+ console.error('Stream error:', error)
114
+ }
115
+ })
116
+ ```
117
+
118
+ If no `onError` handler is provided, the ShapeStream will throw errors that occur during streaming.
119
+
120
+ 2. Individual subscribers can optionally handle errors specific to their subscription:
121
+ ```typescript
122
+ stream.subscribe(
123
+ (messages) => {
124
+ // Handle messages
125
+ },
126
+ (error) => {
127
+ // Handle errors for this specific subscription
128
+ console.error('Subscription error:', error)
129
+ }
130
+ )
131
+ ```
132
+
133
+ Common error types include:
134
+ - `MissingShapeUrlError`: Missing required URL parameter
135
+ - `InvalidSignalError`: Invalid AbortSignal instance
136
+ - `ReservedParamError`: Using reserved parameter names
137
+
138
+ Runtime errors:
139
+ - `FetchError`: HTTP errors during shape fetching
140
+ - `FetchBackoffAbortError`: Fetch aborted using AbortSignal
141
+ - `MissingShapeHandleError`: Missing required shape handle
142
+ - `ParserNullValueError`: Parser encountered NULL value in a column that doesn't allow NULL values
143
+
144
+ See the [typescript client docs on the website](https://electric-sql.com/docs/api/clients/typescript#error-handling) for more details on error handling.
145
+
146
+ And in general, see the [docs website](https://electric-sql.com) and [examples folder](https://electric-sql.com/examples/basic) for more information.
147
+
148
+ ## Develop
149
+
150
+ Install the pnpm workspace at the repo root:
151
+
152
+ ```shell
153
+ pnpm install
154
+ ```
155
+
156
+ Build the package:
157
+
158
+ ```shell
159
+ cd packages/typescript-client
160
+ pnpm build
161
+ ```
162
+
163
+ ## Test
164
+
165
+ In one terminal, start the backend running:
166
+
167
+ ```shell
168
+ cd ../sync-service
169
+ mix deps.get
170
+ mix stop_dev && mix compile && mix start_dev && ies -S mix
171
+ ```
172
+
173
+ Then in this folder:
174
+
175
+ ```shell
176
+ pnpm test
177
+ ```