@delali/sirannon-db 0.3.4-next.62 → 0.3.4

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.
Files changed (108) hide show
  1. package/README.md +79 -56
  2. package/dist/backup/index.d.ts +44 -45
  3. package/dist/backup/index.mjs +7 -7
  4. package/dist/backup-scheduler/index.d.ts +42 -41
  5. package/dist/backup-scheduler/index.mjs +4 -4
  6. package/dist/baseline-Co3iIsN_.d.ts +19 -0
  7. package/dist/change-tracker-DqCdeEyx.d.ts +128 -0
  8. package/dist/{chunk-VOSJBZ6Q.mjs → chunk-2ES3DT4A.mjs} +71 -33
  9. package/dist/{chunk-6CMCO7S4.mjs → chunk-2O3PP4CF.mjs} +1 -1
  10. package/dist/{chunk-E7Q7HE46.mjs → chunk-3BZLZ47R.mjs} +26 -26
  11. package/dist/chunk-4KASJKKK.mjs +2501 -0
  12. package/dist/{chunk-MYNI2WFS.mjs → chunk-52XW3Z76.mjs} +40 -8
  13. package/dist/chunk-55YRLSM2.mjs +57 -0
  14. package/dist/{chunk-KDAHYFW7.mjs → chunk-6AOJCNRU.mjs} +5 -5
  15. package/dist/{chunk-KXTYR2OQ.mjs → chunk-A3PHCO6W.mjs} +39 -111
  16. package/dist/chunk-ADNWEHGZ.mjs +299 -0
  17. package/dist/{chunk-2QLXDHAP.mjs → chunk-BLMRNSUG.mjs} +11 -2
  18. package/dist/chunk-BVMZJOVM.mjs +5 -0
  19. package/dist/{chunk-IWGIYDMZ.mjs → chunk-BZWDPF4G.mjs} +1 -1
  20. package/dist/{chunk-YVF2ZJTE.mjs → chunk-CZL4D3BM.mjs} +1 -1
  21. package/dist/{chunk-7SC2TZAS.mjs → chunk-DX4WGJL7.mjs} +2 -2
  22. package/dist/{chunk-45MKELYA.mjs → chunk-ESTZZPT5.mjs} +132 -13
  23. package/dist/{chunk-QP5L5DFJ.mjs → chunk-FJPR2CJX.mjs} +3 -3
  24. package/dist/chunk-HR7K3GZW.mjs +36 -0
  25. package/dist/{chunk-LXCGPZPA.mjs → chunk-IEKIYO4V.mjs} +1 -1
  26. package/dist/{chunk-TUD5CJ76.mjs → chunk-KB4OLJAD.mjs} +26 -19
  27. package/dist/{chunk-PBRXXISQ.mjs → chunk-KINDFBQP.mjs} +3 -2
  28. package/dist/{chunk-E6IMX7RS.mjs → chunk-KJLNYOOL.mjs} +2 -2
  29. package/dist/{chunk-BTTFW4Z4.mjs → chunk-KU32OT4H.mjs} +2 -10
  30. package/dist/{chunk-JQWGHSEH.mjs → chunk-NVSQ2T5Q.mjs} +71 -70
  31. package/dist/{chunk-W4EUTJNT.mjs → chunk-NZGSDALX.mjs} +94 -96
  32. package/dist/{chunk-U445A3C4.mjs → chunk-QGVRRKB2.mjs} +1 -1
  33. package/dist/{chunk-GYCEJNU4.mjs → chunk-R7GBXNTO.mjs} +1 -1
  34. package/dist/{chunk-7C36BCSN.mjs → chunk-VDN6FHU4.mjs} +1 -1
  35. package/dist/{chunk-6IYS4WLH.mjs → chunk-VO3ZWA2G.mjs} +142 -115
  36. package/dist/chunk-WOMADPM4.mjs +12 -0
  37. package/dist/{chunk-OUSWVNWT.mjs → chunk-YCMB6GR4.mjs} +1 -1
  38. package/dist/{chunk-YNTDOFTN.mjs → chunk-YW7IKQ7T.mjs} +1 -1
  39. package/dist/{chunk-M2BEAH5I.mjs → chunk-ZN4HI5FK.mjs} +126 -72
  40. package/dist/{chunk-SBL6GN43.mjs → chunk-ZYWI45EN.mjs} +1 -1
  41. package/dist/client/index.d.ts +135 -137
  42. package/dist/client/index.mjs +177 -82
  43. package/dist/client/topology.d.ts +31 -31
  44. package/dist/client/topology.mjs +42 -23
  45. package/dist/client-base-BxTocU1x.d.ts +398 -0
  46. package/dist/client-streams-YKANXMWO.mjs +112 -0
  47. package/dist/codegen/cli.mjs +4 -4
  48. package/dist/codegen/index.d.ts +36 -29
  49. package/dist/codegen/index.mjs +4 -4
  50. package/dist/core/index.d.ts +130 -115
  51. package/dist/core/index.mjs +387 -297
  52. package/dist/core/writer-worker.mjs +3 -3
  53. package/dist/database-CGDsXW1K.d.ts +959 -0
  54. package/dist/database-backup-DcLhxoa1.d.ts +143 -0
  55. package/dist/driver/better-sqlite3.d.ts +11 -10
  56. package/dist/driver/better-sqlite3.mjs +11 -11
  57. package/dist/driver/bun.d.ts +9 -8
  58. package/dist/driver/expo.d.ts +6 -7
  59. package/dist/driver/node.d.ts +11 -10
  60. package/dist/driver/node.mjs +13 -11
  61. package/dist/driver/wa-sqlite.d.ts +6 -6
  62. package/dist/errors-CJUkQ-KL.d.ts +199 -0
  63. package/dist/file-migrations/index.d.ts +20 -18
  64. package/dist/file-migrations/index.mjs +3 -3
  65. package/dist/forward-rpc-VRWFZXHN.mjs +44 -0
  66. package/dist/operation-registry-CGhNT-Sn.d.ts +96 -0
  67. package/dist/primary-wins-CHNOYuN7.d.ts +81 -0
  68. package/dist/protocol-DFpNNsIT.d.ts +153 -0
  69. package/dist/query-types-5B02ixH0.d.ts +129 -0
  70. package/dist/react/index.d.ts +22 -22
  71. package/dist/replication/coordinator/etcd.d.ts +37 -31
  72. package/dist/replication/coordinator/etcd.mjs +296 -131
  73. package/dist/replication/index.d.ts +201 -161
  74. package/dist/replication/index.mjs +630 -529
  75. package/dist/restore-options-CH8mE-Tb.d.ts +84 -0
  76. package/dist/server/index.d.ts +201 -191
  77. package/dist/server/index.mjs +736 -619
  78. package/dist/server-options-aYtCkefX.d.ts +317 -0
  79. package/dist/server-streams-24XL4T43.mjs +254 -0
  80. package/dist/sirannon-J3EgPVD7.d.ts +179 -0
  81. package/dist/transport/grpc.d.ts +37 -24
  82. package/dist/transport/grpc.mjs +83 -3199
  83. package/dist/transport/memory.d.ts +25 -26
  84. package/dist/transport/memory.mjs +18 -9
  85. package/dist/types-BrAiDGOb.d.ts +505 -0
  86. package/dist/types-CEJG0eFS.d.ts +88 -0
  87. package/dist/types-Dc8oWlxj.d.ts +1580 -0
  88. package/dist/types-DqODKeOq.d.ts +123 -0
  89. package/dist/types-guEKSzMr.d.ts +367 -0
  90. package/package.json +7 -7
  91. package/dist/baseline-D93hcIEE.d.ts +0 -17
  92. package/dist/change-tracker-CjRFuZdB.d.ts +0 -144
  93. package/dist/client-base-Cmd9EVme.d.ts +0 -397
  94. package/dist/database-BLQvqjsw.d.ts +0 -917
  95. package/dist/database-backup-B7oszQ2n.d.ts +0 -141
  96. package/dist/errors-Dei4GdBb.d.ts +0 -196
  97. package/dist/operation-registry-oiPuSYI6.d.ts +0 -94
  98. package/dist/primary-wins-B0np8JS3.d.ts +0 -85
  99. package/dist/protocol-HI-nY8DD.d.ts +0 -152
  100. package/dist/query-types-p1liOP-b.d.ts +0 -127
  101. package/dist/restore-options-CksYsH1l.d.ts +0 -83
  102. package/dist/server-options-Bj5iJnjx.d.ts +0 -292
  103. package/dist/sirannon-BPxC5tC2.d.ts +0 -178
  104. package/dist/types-B0EhgDbr.d.ts +0 -340
  105. package/dist/types-CbjfRwrK.d.ts +0 -499
  106. package/dist/types-CjhxcjhA.d.ts +0 -123
  107. package/dist/types-DPSmjU54.d.ts +0 -1518
  108. package/dist/types-DTO4CYhW.d.ts +0 -88
@@ -1,397 +0,0 @@
1
- import { B as BulkLoadDurability, a as BulkLoadResult, C as ClientOptions } from './server-options-Bj5iJnjx.js';
2
- import { R as ResultOp, L as LiveQueryOptions, a as LiveQuery } from './types-DTO4CYhW.js';
3
- import { O as OperationRef, b as OperationArguments } from './operation-registry-oiPuSYI6.js';
4
- import { P as Params, R as ReadConcern, W as WriteConcern, C as ChangeEvent, Q as QueryOptions } from './query-types-p1liOP-b.js';
5
- import { Q as QueryResponse, E as ExecuteResponse, T as TransactionResponse, B as BatchResponse, L as LoadResponse } from './protocol-HI-nY8DD.js';
6
-
7
- /**
8
- * Message a client raises when the server accepts no SQL over the network.
9
- *
10
- * @internal
11
- */
12
- declare const SQL_REFUSED_MESSAGE = "This server does not accept SQL over the network. Call a registered operation by name, or start the server with acceptSql: true.";
13
- /**
14
- * Capability questions a remote database asks before it sends a statement.
15
- *
16
- * @public
17
- */
18
- interface ServerCapabilityCheck {
19
- /** Throws when the server accepts no SQL over the network, so a client refuses to send any. */
20
- assertSqlAccepted(): Promise<void>;
21
- /** Reads the digest of the server's operation registry, or undefined when the server announces none. */
22
- registryDigest(refresh?: boolean): Promise<string | undefined>;
23
- }
24
- /**
25
- * Reads and caches the capability report a server announces.
26
- *
27
- * @internal
28
- */
29
- declare class ServerCapabilities implements ServerCapabilityCheck {
30
- private readonly resolveUrl;
31
- private readonly headers;
32
- private readonly requestTimeoutMs;
33
- private pending;
34
- constructor(resolveUrl: () => string | Promise<string>, headers: Record<string, string> | undefined, requestTimeoutMs?: number);
35
- private read;
36
- registryDigest(refresh?: boolean): Promise<string | undefined>;
37
- assertSqlAccepted(): Promise<void>;
38
- private fetch;
39
- }
40
-
41
- /** Optional behaviours for a CDC subscription.
42
- * @public
43
- */
44
- interface SubscribeOptions {
45
- /**
46
- * Receives the failure of a change callback, and the error raised by a change frame the
47
- * client cannot decode. The subscription never waits for what the callback returns, so a
48
- * throw and a rejection both arrive here. Sirannon drops whatever this reporter itself throws.
49
- */
50
- onError?: (error: Error) => void;
51
- /**
52
- * Invoked when a reconnect cannot replay missed changes because they fell
53
- * outside the server's retained history. The subscription continues live
54
- * from the current moment; treat any prior state as stale and re-read.
55
- */
56
- onReset?: () => void;
57
- /** Identity of the device this subscription belongs to, which the server uses to withhold that device's own writes. */
58
- deviceId?: string;
59
- /** Tables one subscription covers, so a transaction spanning them arrives as one ascending stream. */
60
- tables?: readonly string[];
61
- /** Highest migration version this device has applied, which the server gates the subscription on. */
62
- schemaVersion?: number;
63
- /** Returns the sequence to resume from, read afresh on each reconnect so a durable cursor stays current. */
64
- getResumeSeq?: () => bigint | undefined;
65
- /** Sequence to resume after on the first subscribe. Where it is absent, the subscription starts live from now. */
66
- sinceSeq?: bigint;
67
- /** Change-log epoch the resume cursor belongs to, so a cursor from another database file forces a resync. */
68
- epoch?: string;
69
- /**
70
- * Declares that this device stages pulled changes durably and
71
- * acknowledges staged sequences so that the server may pack several events
72
- * per frame and pace the delivery window continuously. Send only to a
73
- * server that announces the `sync.staged-stream` capability.
74
- */
75
- stagedStream?: boolean;
76
- /** Receives what the server confirmed on subscribe: the baseline sequence, the epoch, whether a resync is due, and the delivery window. */
77
- onSubscribed?: (info: {
78
- seq: bigint | undefined;
79
- epoch: string | undefined;
80
- resync: boolean;
81
- maxUnacknowledgedChanges: number | undefined;
82
- }) => void;
83
- }
84
- /**
85
- * Callbacks a transport delivers a live query's updates through.
86
- *
87
- * @public
88
- */
89
- interface LiveHandlers<T = Record<string, unknown>> {
90
- /** Receives a complete replacement result set. */
91
- onRows(rows: T[]): void;
92
- /** Receives the individual edits that move the result set to its new state. */
93
- onOps(ops: ResultOp<T>[]): void;
94
- /** Called when the server starts re-reading the query. */
95
- onRevalidating(): void;
96
- /** Called when the query fails. */
97
- onError(error: RemoteError): void;
98
- }
99
- /**
100
- * Reads the digest of the server's operation registry so that a client notices when
101
- * the registered operations behind a live query change.
102
- *
103
- * @public
104
- */
105
- type RegistryDigestSource = (refresh: boolean) => Promise<string | undefined>;
106
- /**
107
- * Transport layer for communicating with a sirannon-db server.
108
- * Each transport instance is bound to a specific database.
109
- *
110
- * @public
111
- */
112
- interface Transport {
113
- /**
114
- * Whether a read concern passed to {@link Transport.query} or
115
- * {@link Transport.queryNamed} reaches the server. Topology routing applies
116
- * the client-wide setting when it chooses a node, so it leaves this unset and
117
- * a caller asking for a per-read concern is refused rather than served a read
118
- * at another level.
119
- */
120
- readonly carriesReadConcern?: boolean;
121
- /** Sends a read and returns its rows. */
122
- query(sql: string, params?: Params, readConcern?: ReadConcern): Promise<QueryResponse>;
123
- /** Sends one write. */
124
- execute(sql: string, params?: Params): Promise<ExecuteResponse>;
125
- /** Sends several statements the server runs in one transaction. */
126
- transaction(statements: Array<{
127
- sql: string;
128
- params?: Params;
129
- }>): Promise<TransactionResponse>;
130
- /** Sends one statement over many parameter sets, which the server runs in one transaction. */
131
- batch(sql: string, paramsBatch: Params[], writeConcern?: WriteConcern): Promise<BatchResponse>;
132
- /** Sends a bulk load, which the server runs at relaxed durability. */
133
- load(sql: string, paramsBatch: Params[], durability?: BulkLoadDurability, checkpoint?: boolean): Promise<LoadResponse>;
134
- /** Runs a registered read by name and returns its rows. */
135
- queryNamed(name: string, args?: Record<string, unknown>, readConcern?: ReadConcern): Promise<QueryResponse>;
136
- /** Runs a registered write by name. */
137
- executeNamed(name: string, args?: Record<string, unknown>, writeConcern?: WriteConcern): Promise<TransactionResponse>;
138
- /** Opens a live query on a registered read and delivers its updates to the handlers. */
139
- liveSubscribe(name: string, args: Record<string, unknown> | undefined, handlers: LiveHandlers, registryDigest?: RegistryDigestSource): Promise<RemoteSubscription>;
140
- /** Opens a change subscription on a watched table. */
141
- subscribe(table: string, filter: Record<string, unknown> | undefined, callback: (event: ChangeEvent) => void, options?: SubscribeOptions): Promise<RemoteSubscription>;
142
- /** Closes the transport and every subscription running on it. */
143
- close(): void;
144
- }
145
- /** Handle for an active remote subscription.
146
- * @public
147
- */
148
- interface RemoteSubscription {
149
- /** Ends the subscription, so the callback receives no further events. */
150
- unsubscribe(): void;
151
- }
152
- /** Builder for creating remote CDC subscriptions with optional filters.
153
- * @public
154
- */
155
- interface RemoteSubscriptionBuilder {
156
- /**
157
- * Narrows the subscription to rows whose columns equal the given values.
158
- *
159
- * The filter reports membership of the matching set, so an update that moves a row
160
- * into the set arrives as an insert carrying no `oldRow`, and one that moves a row
161
- * out arrives as a delete carrying the old row and an empty `row`. An update that
162
- * leaves the row in the set arrives unchanged, and one that never touches the set
163
- * is not delivered. A synthesised event is indistinguishable from a real insert or
164
- * delete, so read `type` as the row's arrival or departure from the filter.
165
- *
166
- * The subscriber chooses this filter, so it decides how much the server delivers,
167
- * and an operator who needs to bound what a caller may read does that in the
168
- * `authenticate` hook.
169
- */
170
- filter(conditions: Record<string, unknown>): RemoteSubscriptionBuilder;
171
- /**
172
- * Starts the subscription and calls back on each change.
173
- *
174
- * The subscription never waits for what your callback returns, so two calls to an
175
- * asynchronous callback can overlap. Chain the work onto one promise where each change
176
- * has to finish before the next one starts. A throw, and a rejection of what the callback
177
- * returns, both reach `options.onError`.
178
- *
179
- * @typeParam T - Shape of the rows this table holds, which types `row` and `oldRow`.
180
- * @param callback - Receives each change this subscription matches.
181
- * @param options - Carries `onError` and the device-sync fields.
182
- * @returns A handle whose `unsubscribe` ends the subscription.
183
- */
184
- subscribe<T = Record<string, unknown>>(callback: (event: ChangeEvent<T>) => void, options?: SubscribeOptions): Promise<RemoteSubscription>;
185
- }
186
- /**
187
- * Error originating from a remote sirannon-db server.
188
- * Carries the machine-readable error code from the server's error response.
189
- *
190
- * @public
191
- */
192
- declare class RemoteError extends Error {
193
- /** Machine-readable code the server sent with the error. */
194
- readonly code: string;
195
- constructor(code: string, message: string);
196
- }
197
-
198
- /** Options for {@link RemoteDatabase.loadAll}.
199
- * @public
200
- */
201
- interface LoadAllOptions {
202
- /**
203
- * Rows per batch sent to the server. Each batch is one request, so it must
204
- * fit under the server's `maxBodyBytes`; widen that cap or lower this for
205
- * wide rows. Default: 1000.
206
- */
207
- batchSize?: number;
208
- /** Durability during the load. Default: 'off'. */
209
- durability?: BulkLoadDurability;
210
- }
211
- /**
212
- * Proxy for a remote sirannon-db database. Mirrors the core
213
- * `Database` query interface with async methods that send
214
- * requests to the server via the configured transport.
215
- *
216
- * @public
217
- */
218
- declare class RemoteDatabase {
219
- /**
220
- * Identifier of the database on the server.
221
- */
222
- readonly id: string;
223
- private readonly transport;
224
- private readonly capabilities;
225
- private readonly onDispose?;
226
- constructor(
227
- /**
228
- * Identifier of the database on the server.
229
- */
230
- id: string, transport: Transport, capabilities: ServerCapabilityCheck, onDispose?: (() => void) | undefined);
231
- /**
232
- * Sends a read to the server and returns its rows.
233
- *
234
- * @param sql - The statement to run. The server refuses it unless it accepts SQL.
235
- * @param params - Values bound to the statement, named or positional.
236
- * @param options - Read concern for this statement.
237
- * @returns The rows the server returned.
238
- */
239
- query<T = Record<string, unknown>>(sql: string, params?: Params, options?: QueryOptions): Promise<T[]>;
240
- /**
241
- * Runs a registered read by name and returns its rows.
242
- *
243
- * @param operation - Reference to the registered read, which carries its argument and row types.
244
- * @param args - Arguments the read takes.
245
- * @param options - Read concern for this statement.
246
- * @returns The rows the server returned.
247
- */
248
- query<Args, Row>(operation: OperationRef<Args, Row>, args: Args, options?: QueryOptions): Promise<Row[]>;
249
- private assertReadConcernReaches;
250
- /**
251
- * Sends one write to the server.
252
- *
253
- * @param sql - The statement to run. The server refuses it unless it accepts SQL.
254
- * @param params - Values bound to the statement, named or positional.
255
- * @returns How many rows changed, and the last inserted row id.
256
- */
257
- execute(sql: string, params?: Params): Promise<ExecuteResponse>;
258
- /**
259
- * Runs a registered write by name.
260
- *
261
- * @param operation - Reference to the registered write, which carries its argument type.
262
- * @param args - Arguments the write takes.
263
- * @param writeConcern - Acknowledgements the write waits for.
264
- * @returns One result per statement the operation ran.
265
- */
266
- execute<Args>(operation: OperationRef<Args, unknown>, args: Args, writeConcern?: WriteConcern): Promise<ExecuteResponse[]>;
267
- /**
268
- * Opens a live query on a registered read, which keeps its rows current as the tables behind it change.
269
- *
270
- * @param name - Name of the registered read.
271
- * @param args - Arguments the read takes.
272
- * @param options - Carries `onError`, which receives a failure of any listener on this query.
273
- * @returns The live query, already subscribed.
274
- */
275
- live<T = Record<string, unknown>>(name: string, args?: OperationArguments, options?: LiveQueryOptions): Promise<LiveQuery<T>>;
276
- /**
277
- * Opens a live query on a registered read, which keeps its rows current as the tables behind it change.
278
- *
279
- * @param operation - Reference to the registered read, which carries its argument and row types.
280
- * @param args - Arguments the read takes.
281
- * @param options - Carries `onError`, which receives a failure of any listener on this query.
282
- * @returns The live query, already subscribed.
283
- */
284
- live<Args, Row>(operation: OperationRef<Args, Row>, args: Args, options?: LiveQueryOptions): Promise<LiveQuery<Row>>;
285
- /**
286
- * Execute multiple statements as a single atomic transaction.
287
- * Returns an array of results, one per statement.
288
- *
289
- * The whole list is sent in one request and commits or rolls back as a
290
- * unit, so the client is never in the loop between statements.
291
- */
292
- transaction(statements: Array<{
293
- sql: string;
294
- params?: Params;
295
- }>): Promise<ExecuteResponse[]>;
296
- /**
297
- * Run the same statement once per parameter set as a single atomic
298
- * transaction that commits with one fsync. Returns one result per
299
- * parameter set, in order. Use this for a burst of same-shape writes
300
- * (an import, a bulk insert) that must all commit or all roll back.
301
- */
302
- batch(sql: string, paramsBatch: Params[], writeConcern?: WriteConcern): Promise<ExecuteResponse[]>;
303
- /**
304
- * Load a whole dataset through the same statement, batching it into requests
305
- * for you and paying the one fsyncing WAL checkpoint once, after the final
306
- * batch. The configured durability is restored after every batch, so an
307
- * import that stops partway never leaves the writer at the relaxed level.
308
- * Prefer this over {@link RemoteDatabase.load} for anything larger than a single request:
309
- * it finalises the load itself, so there is no checkpoint flag to forget.
310
- *
311
- * Accepts a synchronous or asynchronous iterable of parameter sets so that rows
312
- * can stream from a file or the network without being held in memory at
313
- * once. Returns the total rows loaded and changes applied.
314
- *
315
- * ```ts
316
- * const summary = await db.loadAll(
317
- * 'INSERT INTO events (id, payload) VALUES (?, ?)',
318
- * rowStream,
319
- * { batchSize: 5000, durability: 'off' },
320
- * )
321
- * ```
322
- */
323
- loadAll(sql: string, rows: Iterable<Params> | AsyncIterable<Params>, options?: LoadAllOptions): Promise<BulkLoadResult>;
324
- /**
325
- * Load one batch of rows through the same statement with writer durability
326
- * relaxed for the duration, then restored before this resolves. This is the
327
- * low-level primitive; prefer {@link RemoteDatabase.loadAll} for a dataset that spans more
328
- * than one request, since it finalises the load itself rather than relying on
329
- * a `checkpoint` flag.
330
- *
331
- * Returns the total rows loaded and changes applied. When splitting a dataset
332
- * across many `load` calls by hand, pass `checkpoint: false` on every call
333
- * but the last so the one fsyncing WAL checkpoint runs once at the end; the
334
- * configured durability is restored after each call regardless.
335
- */
336
- load(sql: string, paramsBatch: Params[], durability?: BulkLoadDurability, checkpoint?: boolean): Promise<BulkLoadResult>;
337
- /**
338
- * Start building a CDC subscription for the given table.
339
- * Chain `.filter()` to narrow the events, then call `.subscribe()`
340
- * with a callback to begin receiving real-time change events.
341
- *
342
- * ```ts
343
- * const sub = await db
344
- * .on('orders')
345
- * .filter({ status: 'pending' })
346
- * .subscribe(event => console.log(event))
347
- *
348
- * // Later:
349
- * sub.unsubscribe()
350
- * ```
351
- *
352
- * Begins a change subscription on a watched table.
353
- *
354
- * @param table - Name of the watched table.
355
- * @returns A builder you narrow with a filter and then subscribe to.
356
- */
357
- on(table: string): RemoteSubscriptionBuilder;
358
- /**
359
- * Close the transport for this database. After calling `close()`,
360
- * all pending requests are rejected and new calls will throw.
361
- */
362
- close(): void;
363
- }
364
-
365
- interface TransportSettings {
366
- transport: 'websocket' | 'http';
367
- headers: Record<string, string> | undefined;
368
- webSocketProtocols: string | string[] | undefined;
369
- autoReconnect: boolean;
370
- reconnectInterval: number;
371
- requestTimeout: number | undefined;
372
- }
373
- /**
374
- * Opens one database handle per identifier and keeps it, so a later call for the same identifier returns the handle already open.
375
- */
376
- declare abstract class DatabaseClient {
377
- protected readonly settings: TransportSettings;
378
- private readonly databases;
379
- private closed;
380
- constructor(options?: ClientOptions);
381
- /**
382
- * Returns the handle a caller queries and writes one database through, opening it on the first call for that identifier.
383
- *
384
- * @param id - Identifier the server registered the database under.
385
- * @returns The database handle, which stays open until the caller closes it.
386
- */
387
- database(id: string): RemoteDatabase;
388
- protected createCapabilities(databaseId: string): ServerCapabilities;
389
- /**
390
- * Closes every database this client opened, which ends their transports and stops their subscriptions.
391
- */
392
- close(): void;
393
- protected abstract createTransport(databaseId: string): Transport;
394
- protected abstract resolveServerUrl(databaseId: string): string | Promise<string>;
395
- }
396
-
397
- export { DatabaseClient as D, type LiveHandlers as L, type RemoteSubscription as R, type SubscribeOptions as S, type Transport as T, type RemoteSubscriptionBuilder as a, type RegistryDigestSource as b, type LoadAllOptions as c, RemoteDatabase as d, RemoteError as e, SQL_REFUSED_MESSAGE as f, ServerCapabilities as g, type ServerCapabilityCheck as h };