@delali/sirannon-db 0.1.6 → 0.1.7
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 +134 -19
- package/dist/backup-scheduler/index.d.ts +18 -3
- package/dist/backup-scheduler/index.mjs +2 -2
- package/dist/{change-tracker-CFTQ9TSn.d.ts → change-tracker-CbmaMO-N.d.ts} +12 -2
- package/dist/chunk-4IGMIJQK.mjs +318 -0
- package/dist/chunk-BNUTBHHH.mjs +22 -0
- package/dist/chunk-CJLYFDP5.mjs +26 -0
- package/dist/chunk-CW6S3WL5.mjs +222 -0
- package/dist/chunk-DJLX6CAE.mjs +20 -0
- package/dist/chunk-DVWQD3GF.mjs +49 -0
- package/dist/chunk-GEZUUIKV.mjs +268 -0
- package/dist/{chunk-UVMVN3OT.mjs → chunk-H5AB6NIR.mjs} +1 -1
- package/dist/{chunk-UTO3ZAFS.mjs → chunk-HHRMRFFR.mjs} +148 -28
- package/dist/chunk-TKGHYWQ6.mjs +35 -0
- package/dist/chunk-VLTICJOD.mjs +470 -0
- package/dist/{chunk-O7BHI3CF.mjs → chunk-YPYVQJ4C.mjs} +15 -1
- package/dist/client/index.d.ts +107 -15
- package/dist/client/index.mjs +348 -37
- package/dist/core/index.d.ts +70 -13
- package/dist/core/index.mjs +635 -192
- package/dist/core/writer-worker.d.ts +2 -0
- package/dist/core/writer-worker.mjs +107 -0
- package/dist/{database-BVY1GqE7.d.ts → database-DuGp0Rtr.d.ts} +51 -19
- package/dist/driver/better-sqlite3.d.ts +1 -1
- package/dist/driver/better-sqlite3.mjs +44 -6
- package/dist/driver/bun.mjs +35 -6
- package/dist/driver/expo.mjs +2 -2
- package/dist/driver/node.d.ts +1 -1
- package/dist/driver/node.mjs +48 -5
- package/dist/driver/wa-sqlite.d.ts +109 -0
- package/dist/driver/wa-sqlite.mjs +30 -2
- package/dist/{errors-C00ed08Q.d.ts → errors-5Nf5ZAEC.d.ts} +19 -1
- package/dist/file-migrations/index.d.ts +2 -3
- package/dist/file-migrations/index.mjs +1 -1
- package/dist/replication/coordinator/etcd.mjs +2 -2
- package/dist/replication/index.d.ts +7 -8
- package/dist/replication/index.mjs +79 -78
- package/dist/server/index.d.ts +111 -28
- package/dist/server/index.mjs +1016 -384
- package/dist/{sirannon-Cd-lK6T0.d.ts → sirannon-4SspRvP5.d.ts} +3 -3
- package/dist/transport/grpc.d.ts +3 -4
- package/dist/transport/grpc.mjs +2 -2
- package/dist/{types-Lc7ywFx7.d.ts → types-BsjobKbl.d.ts} +2 -2
- package/dist/{types-BeozgNPr.d.ts → types-D4p4UyDK.d.ts} +1 -1
- package/dist/types-D_hQW1hr.d.ts +494 -0
- package/package.json +3 -23
- package/dist/chunk-3MCMONVP.mjs +0 -115
- package/dist/chunk-74UN4DIE.mjs +0 -14
- package/dist/chunk-FB2U2Q3Y.mjs +0 -21
- package/dist/chunk-GS7T5YMI.mjs +0 -51
- package/dist/chunk-PXKAKK2V.mjs +0 -124
- package/dist/index-CLdNrcPz.d.ts +0 -16
- package/dist/types-BFSsG77t.d.ts +0 -29
- package/dist/types-D-74JiXb.d.ts +0 -265
package/dist/client/index.d.ts
CHANGED
|
@@ -24,6 +24,20 @@ interface ChangeEvent<T = Record<string, unknown>> {
|
|
|
24
24
|
seq: bigint;
|
|
25
25
|
timestamp: number;
|
|
26
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Durability level in force while a bulk load runs. SQLite sanctions 'off' for
|
|
29
|
+
* a from-scratch load that the operator can re-run after a power loss; 'off'
|
|
30
|
+
* gives up corruption safety, so it fits only a load that starts from nothing.
|
|
31
|
+
* 'normal' keeps WAL-mode corruption safety and suits loads into a database
|
|
32
|
+
* that already holds data the operator cannot afford to lose.
|
|
33
|
+
*/
|
|
34
|
+
type BulkLoadDurability = 'off' | 'normal';
|
|
35
|
+
/** Aggregate outcome of a bulk load. Summed rather than per-row so a
|
|
36
|
+
* million-row load never holds a million result objects in memory. */
|
|
37
|
+
interface BulkLoadResult {
|
|
38
|
+
rowsLoaded: number;
|
|
39
|
+
changes: number;
|
|
40
|
+
}
|
|
27
41
|
/** Options for the client SDK. */
|
|
28
42
|
interface ClientOptions {
|
|
29
43
|
/** Transport to use. Default: 'websocket'. */
|
|
@@ -36,22 +50,39 @@ interface ClientOptions {
|
|
|
36
50
|
autoReconnect?: boolean;
|
|
37
51
|
/** Reconnect interval in ms. Default: 1000. */
|
|
38
52
|
reconnectInterval?: number;
|
|
53
|
+
/**
|
|
54
|
+
* Per-request timeout in milliseconds for the WebSocket transport. A bulk
|
|
55
|
+
* load or batch of tens of millions of rows can legitimately run longer than
|
|
56
|
+
* the default, so raise this for large writes. Set to 0 to wait indefinitely.
|
|
57
|
+
* Default: 30000.
|
|
58
|
+
*/
|
|
59
|
+
requestTimeout?: number;
|
|
39
60
|
}
|
|
40
61
|
|
|
41
|
-
/** Response for a successful query. */
|
|
42
62
|
interface QueryResponse {
|
|
43
63
|
rows: Record<string, unknown>[];
|
|
44
64
|
}
|
|
45
|
-
/** Response for a successful execute. */
|
|
46
65
|
interface ExecuteResponse {
|
|
47
66
|
changes: number;
|
|
48
67
|
lastInsertRowId: number | string;
|
|
49
68
|
}
|
|
50
|
-
/** Response for a successful transaction. */
|
|
51
69
|
interface TransactionResponse {
|
|
52
70
|
results: ExecuteResponse[];
|
|
53
71
|
}
|
|
72
|
+
interface BatchResponse {
|
|
73
|
+
results: ExecuteResponse[];
|
|
74
|
+
}
|
|
75
|
+
type LoadResponse = BulkLoadResult;
|
|
54
76
|
|
|
77
|
+
/** Optional behaviours for a CDC subscription. */
|
|
78
|
+
interface SubscribeOptions {
|
|
79
|
+
/**
|
|
80
|
+
* Invoked when a reconnect cannot replay missed changes because they fell
|
|
81
|
+
* outside the server's retained history. The subscription continues live
|
|
82
|
+
* from the current moment; treat any prior state as stale and re-read.
|
|
83
|
+
*/
|
|
84
|
+
onReset?: () => void;
|
|
85
|
+
}
|
|
55
86
|
/**
|
|
56
87
|
* Transport layer for communicating with a sirannon-db server.
|
|
57
88
|
* Each transport instance is bound to a specific database.
|
|
@@ -63,7 +94,9 @@ interface Transport {
|
|
|
63
94
|
sql: string;
|
|
64
95
|
params?: Params;
|
|
65
96
|
}>): Promise<TransactionResponse>;
|
|
66
|
-
|
|
97
|
+
batch(sql: string, paramsBatch: Params[], writeConcern?: WriteConcern): Promise<BatchResponse>;
|
|
98
|
+
load(sql: string, paramsBatch: Params[], durability?: BulkLoadDurability, checkpoint?: boolean): Promise<LoadResponse>;
|
|
99
|
+
subscribe(table: string, filter: Record<string, unknown> | undefined, callback: (event: ChangeEvent) => void, options?: SubscribeOptions): Promise<RemoteSubscription>;
|
|
67
100
|
close(): void;
|
|
68
101
|
}
|
|
69
102
|
/** Handle for an active remote subscription. */
|
|
@@ -73,7 +106,7 @@ interface RemoteSubscription {
|
|
|
73
106
|
/** Builder for creating remote CDC subscriptions with optional filters. */
|
|
74
107
|
interface RemoteSubscriptionBuilder {
|
|
75
108
|
filter(conditions: Record<string, unknown>): RemoteSubscriptionBuilder;
|
|
76
|
-
subscribe(callback: (event: ChangeEvent) => void): Promise<RemoteSubscription>;
|
|
109
|
+
subscribe(callback: (event: ChangeEvent) => void, options?: SubscribeOptions): Promise<RemoteSubscription>;
|
|
77
110
|
}
|
|
78
111
|
/**
|
|
79
112
|
* Error originating from a remote sirannon-db server.
|
|
@@ -84,6 +117,17 @@ declare class RemoteError extends Error {
|
|
|
84
117
|
constructor(code: string, message: string);
|
|
85
118
|
}
|
|
86
119
|
|
|
120
|
+
/** Options for {@link RemoteDatabase.loadAll}. */
|
|
121
|
+
interface LoadAllOptions {
|
|
122
|
+
/**
|
|
123
|
+
* Rows per batch sent to the server. Each batch is one request, so it must
|
|
124
|
+
* fit under the server's `maxBodyBytes`; widen that cap or lower this for
|
|
125
|
+
* wide rows. Default: 1000.
|
|
126
|
+
*/
|
|
127
|
+
batchSize?: number;
|
|
128
|
+
/** Durability during the load. Default: 'off'. */
|
|
129
|
+
durability?: BulkLoadDurability;
|
|
130
|
+
}
|
|
87
131
|
/**
|
|
88
132
|
* Proxy for a remote sirannon-db database. Mirrors the core
|
|
89
133
|
* {@link Database} query interface with async methods that send
|
|
@@ -114,13 +158,54 @@ declare class RemoteDatabase {
|
|
|
114
158
|
* Execute multiple statements as a single atomic transaction.
|
|
115
159
|
* Returns an array of results, one per statement.
|
|
116
160
|
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
161
|
+
* The whole list travels in one request and commits or rolls back as a
|
|
162
|
+
* unit, so the client is never in the loop between statements.
|
|
119
163
|
*/
|
|
120
164
|
transaction(statements: Array<{
|
|
121
165
|
sql: string;
|
|
122
166
|
params?: Params;
|
|
123
167
|
}>): Promise<ExecuteResponse[]>;
|
|
168
|
+
/**
|
|
169
|
+
* Run the same statement once per parameter set as a single atomic
|
|
170
|
+
* transaction that commits with one fsync. Returns one result per
|
|
171
|
+
* parameter set, in order. Use this for a burst of same-shape writes
|
|
172
|
+
* (an import, a bulk insert) that must all commit or all roll back.
|
|
173
|
+
*/
|
|
174
|
+
batch(sql: string, paramsBatch: Params[], writeConcern?: WriteConcern): Promise<ExecuteResponse[]>;
|
|
175
|
+
/**
|
|
176
|
+
* Load a whole dataset through the same statement, batching it into requests
|
|
177
|
+
* for you and paying the one fsyncing WAL checkpoint once, after the final
|
|
178
|
+
* batch. The configured durability is restored after every batch, so an
|
|
179
|
+
* import that stops partway never leaves the writer at the relaxed level.
|
|
180
|
+
* Prefer this over {@link load} for anything larger than a single request:
|
|
181
|
+
* it runs the finalize itself, so there is no checkpoint flag to forget.
|
|
182
|
+
*
|
|
183
|
+
* Accepts a synchronous or asynchronous iterable of parameter sets, so rows
|
|
184
|
+
* can stream from a file or the network without being held in memory at
|
|
185
|
+
* once. Returns the total rows loaded and changes applied.
|
|
186
|
+
*
|
|
187
|
+
* ```ts
|
|
188
|
+
* const summary = await db.loadAll(
|
|
189
|
+
* 'INSERT INTO events (id, payload) VALUES (?, ?)',
|
|
190
|
+
* rowStream,
|
|
191
|
+
* { batchSize: 5000, durability: 'off' },
|
|
192
|
+
* )
|
|
193
|
+
* ```
|
|
194
|
+
*/
|
|
195
|
+
loadAll(sql: string, rows: Iterable<Params> | AsyncIterable<Params>, options?: LoadAllOptions): Promise<BulkLoadResult>;
|
|
196
|
+
/**
|
|
197
|
+
* Load one batch of rows through the same statement with writer durability
|
|
198
|
+
* relaxed for the duration, then restored before this resolves. This is the
|
|
199
|
+
* low-level primitive; prefer {@link loadAll} for a dataset that spans more
|
|
200
|
+
* than one request, since it runs the finalize itself rather than relying on
|
|
201
|
+
* a `checkpoint` flag.
|
|
202
|
+
*
|
|
203
|
+
* Returns the total rows loaded and changes applied. When splitting a dataset
|
|
204
|
+
* across many `load` calls by hand, pass `checkpoint: false` on every call
|
|
205
|
+
* but the last so the one fsyncing WAL checkpoint runs once at the end; the
|
|
206
|
+
* configured durability is restored after each call regardless.
|
|
207
|
+
*/
|
|
208
|
+
load(sql: string, paramsBatch: Params[], durability?: BulkLoadDurability, checkpoint?: boolean): Promise<BulkLoadResult>;
|
|
124
209
|
/**
|
|
125
210
|
* Start building a CDC subscription for the given table.
|
|
126
211
|
* Chain `.filter()` to narrow the events, then call `.subscribe()`
|
|
@@ -160,6 +245,7 @@ declare class SirannonClient {
|
|
|
160
245
|
private readonly webSocketProtocols;
|
|
161
246
|
private readonly autoReconnect;
|
|
162
247
|
private readonly reconnectInterval;
|
|
248
|
+
private readonly requestTimeout;
|
|
163
249
|
private readonly databases;
|
|
164
250
|
private closed;
|
|
165
251
|
private readonly topologyEnabled;
|
|
@@ -220,7 +306,9 @@ declare class TopologyAwareTransport implements Transport {
|
|
|
220
306
|
sql: string;
|
|
221
307
|
params?: Params;
|
|
222
308
|
}>): Promise<TransactionResponse>;
|
|
223
|
-
|
|
309
|
+
batch(sql: string, paramsBatch: Params[], writeConcern?: WriteConcern): Promise<BatchResponse>;
|
|
310
|
+
load(sql: string, paramsBatch: Params[], durability?: BulkLoadDurability, checkpoint?: boolean): Promise<LoadResponse>;
|
|
311
|
+
subscribe(table: string, filter: Record<string, unknown> | undefined, callback: (event: ChangeEvent) => void, options?: SubscribeOptions): Promise<RemoteSubscription>;
|
|
224
312
|
_handleClusterRoutingChanged(): Promise<void>;
|
|
225
313
|
close(): void;
|
|
226
314
|
private subscribeOnCurrentEndpoint;
|
|
@@ -249,14 +337,14 @@ declare class RemoteSubscriptionBuilderImpl implements RemoteSubscriptionBuilder
|
|
|
249
337
|
private conditions;
|
|
250
338
|
constructor(table: string, transport: Transport);
|
|
251
339
|
filter(conditions: Record<string, unknown>): RemoteSubscriptionBuilder;
|
|
252
|
-
subscribe(callback: (event: ChangeEvent) => void): Promise<RemoteSubscription>;
|
|
340
|
+
subscribe(callback: (event: ChangeEvent) => void, options?: SubscribeOptions): Promise<RemoteSubscription>;
|
|
253
341
|
}
|
|
254
342
|
|
|
255
343
|
/**
|
|
256
344
|
* HTTP transport for sirannon-db. Sends requests via `fetch` to the
|
|
257
|
-
* server's REST endpoints. Supports query, execute,
|
|
258
|
-
* operations. Real-time subscriptions are not available over
|
|
259
|
-
* use {@link WebSocketTransport} for CDC subscriptions.
|
|
345
|
+
* server's REST endpoints. Supports query, execute, transaction, batch,
|
|
346
|
+
* and load operations. Real-time subscriptions are not available over
|
|
347
|
+
* HTTP; use {@link WebSocketTransport} for CDC subscriptions.
|
|
260
348
|
*/
|
|
261
349
|
declare class HttpTransport implements Transport {
|
|
262
350
|
private readonly baseUrl;
|
|
@@ -269,6 +357,8 @@ declare class HttpTransport implements Transport {
|
|
|
269
357
|
sql: string;
|
|
270
358
|
params?: Params;
|
|
271
359
|
}>): Promise<TransactionResponse>;
|
|
360
|
+
batch(sql: string, paramsBatch: Params[], writeConcern?: WriteConcern): Promise<BatchResponse>;
|
|
361
|
+
load(sql: string, paramsBatch: Params[], durability?: BulkLoadDurability, checkpoint?: boolean): Promise<LoadResponse>;
|
|
272
362
|
subscribe(_table: string, _filter: Record<string, unknown> | undefined, _callback: (event: ChangeEvent) => void): Promise<RemoteSubscription>;
|
|
273
363
|
close(): void;
|
|
274
364
|
private post;
|
|
@@ -295,11 +385,13 @@ declare class WebSocketTransport implements Transport {
|
|
|
295
385
|
});
|
|
296
386
|
query(sql: string, params?: Params): Promise<QueryResponse>;
|
|
297
387
|
execute(sql: string, params?: Params): Promise<ExecuteResponse>;
|
|
298
|
-
transaction(
|
|
388
|
+
transaction(statements: Array<{
|
|
299
389
|
sql: string;
|
|
300
390
|
params?: Params;
|
|
301
391
|
}>): Promise<TransactionResponse>;
|
|
302
|
-
|
|
392
|
+
batch(sql: string, paramsBatch: Params[], writeConcern?: WriteConcern): Promise<BatchResponse>;
|
|
393
|
+
load(sql: string, paramsBatch: Params[], durability?: BulkLoadDurability, checkpoint?: boolean): Promise<LoadResponse>;
|
|
394
|
+
subscribe(table: string, filter: Record<string, unknown> | undefined, callback: (event: ChangeEvent) => void, options?: SubscribeOptions): Promise<RemoteSubscription>;
|
|
303
395
|
close(): void;
|
|
304
396
|
private nextId;
|
|
305
397
|
private ensureConnected;
|
|
@@ -313,4 +405,4 @@ declare class WebSocketTransport implements Transport {
|
|
|
313
405
|
private cancelReconnect;
|
|
314
406
|
}
|
|
315
407
|
|
|
316
|
-
export { HttpTransport, RemoteDatabase, RemoteError, type RemoteSubscription, type RemoteSubscriptionBuilder, RemoteSubscriptionBuilderImpl, SirannonClient, type TopologyAwareClientOptions, type Transport, WebSocketTransport };
|
|
408
|
+
export { HttpTransport, type LoadAllOptions, RemoteDatabase, RemoteError, type RemoteSubscription, type RemoteSubscriptionBuilder, RemoteSubscriptionBuilderImpl, SirannonClient, type TopologyAwareClientOptions, type Transport, WebSocketTransport };
|