@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.
- package/README.md +79 -56
- package/dist/backup/index.d.ts +44 -45
- package/dist/backup/index.mjs +7 -7
- package/dist/backup-scheduler/index.d.ts +42 -41
- package/dist/backup-scheduler/index.mjs +4 -4
- package/dist/baseline-Co3iIsN_.d.ts +19 -0
- package/dist/change-tracker-DqCdeEyx.d.ts +128 -0
- package/dist/{chunk-VOSJBZ6Q.mjs → chunk-2ES3DT4A.mjs} +71 -33
- package/dist/{chunk-6CMCO7S4.mjs → chunk-2O3PP4CF.mjs} +1 -1
- package/dist/{chunk-E7Q7HE46.mjs → chunk-3BZLZ47R.mjs} +26 -26
- package/dist/chunk-4KASJKKK.mjs +2501 -0
- package/dist/{chunk-MYNI2WFS.mjs → chunk-52XW3Z76.mjs} +40 -8
- package/dist/chunk-55YRLSM2.mjs +57 -0
- package/dist/{chunk-KDAHYFW7.mjs → chunk-6AOJCNRU.mjs} +5 -5
- package/dist/{chunk-KXTYR2OQ.mjs → chunk-A3PHCO6W.mjs} +39 -111
- package/dist/chunk-ADNWEHGZ.mjs +299 -0
- package/dist/{chunk-2QLXDHAP.mjs → chunk-BLMRNSUG.mjs} +11 -2
- package/dist/chunk-BVMZJOVM.mjs +5 -0
- package/dist/{chunk-IWGIYDMZ.mjs → chunk-BZWDPF4G.mjs} +1 -1
- package/dist/{chunk-YVF2ZJTE.mjs → chunk-CZL4D3BM.mjs} +1 -1
- package/dist/{chunk-7SC2TZAS.mjs → chunk-DX4WGJL7.mjs} +2 -2
- package/dist/{chunk-45MKELYA.mjs → chunk-ESTZZPT5.mjs} +132 -13
- package/dist/{chunk-QP5L5DFJ.mjs → chunk-FJPR2CJX.mjs} +3 -3
- package/dist/chunk-HR7K3GZW.mjs +36 -0
- package/dist/{chunk-LXCGPZPA.mjs → chunk-IEKIYO4V.mjs} +1 -1
- package/dist/{chunk-TUD5CJ76.mjs → chunk-KB4OLJAD.mjs} +26 -19
- package/dist/{chunk-PBRXXISQ.mjs → chunk-KINDFBQP.mjs} +3 -2
- package/dist/{chunk-E6IMX7RS.mjs → chunk-KJLNYOOL.mjs} +2 -2
- package/dist/{chunk-BTTFW4Z4.mjs → chunk-KU32OT4H.mjs} +2 -10
- package/dist/{chunk-JQWGHSEH.mjs → chunk-NVSQ2T5Q.mjs} +71 -70
- package/dist/{chunk-W4EUTJNT.mjs → chunk-NZGSDALX.mjs} +94 -96
- package/dist/{chunk-U445A3C4.mjs → chunk-QGVRRKB2.mjs} +1 -1
- package/dist/{chunk-GYCEJNU4.mjs → chunk-R7GBXNTO.mjs} +1 -1
- package/dist/{chunk-7C36BCSN.mjs → chunk-VDN6FHU4.mjs} +1 -1
- package/dist/{chunk-6IYS4WLH.mjs → chunk-VO3ZWA2G.mjs} +142 -115
- package/dist/chunk-WOMADPM4.mjs +12 -0
- package/dist/{chunk-OUSWVNWT.mjs → chunk-YCMB6GR4.mjs} +1 -1
- package/dist/{chunk-YNTDOFTN.mjs → chunk-YW7IKQ7T.mjs} +1 -1
- package/dist/{chunk-M2BEAH5I.mjs → chunk-ZN4HI5FK.mjs} +126 -72
- package/dist/{chunk-SBL6GN43.mjs → chunk-ZYWI45EN.mjs} +1 -1
- package/dist/client/index.d.ts +135 -137
- package/dist/client/index.mjs +177 -82
- package/dist/client/topology.d.ts +31 -31
- package/dist/client/topology.mjs +42 -23
- package/dist/client-base-BxTocU1x.d.ts +398 -0
- package/dist/client-streams-YKANXMWO.mjs +112 -0
- package/dist/codegen/cli.mjs +4 -4
- package/dist/codegen/index.d.ts +36 -29
- package/dist/codegen/index.mjs +4 -4
- package/dist/core/index.d.ts +130 -115
- package/dist/core/index.mjs +387 -297
- package/dist/core/writer-worker.mjs +3 -3
- package/dist/database-CGDsXW1K.d.ts +959 -0
- package/dist/database-backup-DcLhxoa1.d.ts +143 -0
- package/dist/driver/better-sqlite3.d.ts +11 -10
- package/dist/driver/better-sqlite3.mjs +11 -11
- package/dist/driver/bun.d.ts +9 -8
- package/dist/driver/expo.d.ts +6 -7
- package/dist/driver/node.d.ts +11 -10
- package/dist/driver/node.mjs +13 -11
- package/dist/driver/wa-sqlite.d.ts +6 -6
- package/dist/errors-CJUkQ-KL.d.ts +199 -0
- package/dist/file-migrations/index.d.ts +20 -18
- package/dist/file-migrations/index.mjs +3 -3
- package/dist/forward-rpc-VRWFZXHN.mjs +44 -0
- package/dist/operation-registry-CGhNT-Sn.d.ts +96 -0
- package/dist/primary-wins-CHNOYuN7.d.ts +81 -0
- package/dist/protocol-DFpNNsIT.d.ts +153 -0
- package/dist/query-types-5B02ixH0.d.ts +129 -0
- package/dist/react/index.d.ts +22 -22
- package/dist/replication/coordinator/etcd.d.ts +37 -31
- package/dist/replication/coordinator/etcd.mjs +296 -131
- package/dist/replication/index.d.ts +201 -161
- package/dist/replication/index.mjs +630 -529
- package/dist/restore-options-CH8mE-Tb.d.ts +84 -0
- package/dist/server/index.d.ts +201 -191
- package/dist/server/index.mjs +736 -619
- package/dist/server-options-aYtCkefX.d.ts +317 -0
- package/dist/server-streams-24XL4T43.mjs +254 -0
- package/dist/sirannon-J3EgPVD7.d.ts +179 -0
- package/dist/transport/grpc.d.ts +37 -24
- package/dist/transport/grpc.mjs +83 -3199
- package/dist/transport/memory.d.ts +25 -26
- package/dist/transport/memory.mjs +18 -9
- package/dist/types-BrAiDGOb.d.ts +505 -0
- package/dist/types-CEJG0eFS.d.ts +88 -0
- package/dist/types-Dc8oWlxj.d.ts +1580 -0
- package/dist/types-DqODKeOq.d.ts +123 -0
- package/dist/types-guEKSzMr.d.ts +367 -0
- package/package.json +7 -7
- package/dist/baseline-D93hcIEE.d.ts +0 -17
- package/dist/change-tracker-CjRFuZdB.d.ts +0 -144
- package/dist/client-base-Cmd9EVme.d.ts +0 -397
- package/dist/database-BLQvqjsw.d.ts +0 -917
- package/dist/database-backup-B7oszQ2n.d.ts +0 -141
- package/dist/errors-Dei4GdBb.d.ts +0 -196
- package/dist/operation-registry-oiPuSYI6.d.ts +0 -94
- package/dist/primary-wins-B0np8JS3.d.ts +0 -85
- package/dist/protocol-HI-nY8DD.d.ts +0 -152
- package/dist/query-types-p1liOP-b.d.ts +0 -127
- package/dist/restore-options-CksYsH1l.d.ts +0 -83
- package/dist/server-options-Bj5iJnjx.d.ts +0 -292
- package/dist/sirannon-BPxC5tC2.d.ts +0 -178
- package/dist/types-B0EhgDbr.d.ts +0 -340
- package/dist/types-CbjfRwrK.d.ts +0 -499
- package/dist/types-CjhxcjhA.d.ts +0 -123
- package/dist/types-DPSmjU54.d.ts +0 -1518
- package/dist/types-DTO4CYhW.d.ts +0 -88
package/dist/client/index.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
export { F as FieldMergeResolver, L as LWWResolver, P as PrimaryWinsResolver } from '../primary-wins-
|
|
2
|
-
import { C as ConflictResolver, R as ReplicationBatch } from '../types-
|
|
3
|
-
export { a as ConflictContext, b as ConflictResolution } from '../types-
|
|
4
|
-
import { C as ClientOptions, B as BulkLoadDurability } from '../server-options-
|
|
5
|
-
import { D as DatabaseClient, T as Transport, L as LiveHandlers, R as RemoteSubscription, a as RemoteSubscriptionBuilder, S as SubscribeOptions, b as RegistryDigestSource } from '../client-base-
|
|
6
|
-
export { c as LoadAllOptions, d as RemoteDatabase, e as RemoteError, f as SQL_REFUSED_MESSAGE, g as ServerCapabilities, h as ServerCapabilityCheck } from '../client-base-
|
|
7
|
-
import { a as LiveQuery, b as LiveQueryState, c as LiveUpdate } from '../types-
|
|
8
|
-
import { l as DeviceSyncPort, D as Database } from '../database-
|
|
9
|
-
import { C as ChangeEvent, P as Params, R as ReadConcern, W as WriteConcern } from '../query-types-
|
|
10
|
-
import { Q as QueryResponse, E as ExecuteResponse, T as TransactionResponse, B as BatchResponse, L as LoadResponse, A as AckResponse } from '../protocol-
|
|
11
|
-
import '../operation-registry-
|
|
12
|
-
import '../types-
|
|
13
|
-
import '../database-backup-
|
|
14
|
-
import '../change-tracker-
|
|
1
|
+
export { F as FieldMergeResolver, L as LWWResolver, P as PrimaryWinsResolver } from '../primary-wins-CHNOYuN7.js';
|
|
2
|
+
import { C as ConflictResolver, R as ReplicationBatch } from '../types-DqODKeOq.js';
|
|
3
|
+
export { a as ConflictContext, b as ConflictResolution } from '../types-DqODKeOq.js';
|
|
4
|
+
import { C as ClientOptions, B as BulkLoadDurability } from '../server-options-aYtCkefX.js';
|
|
5
|
+
import { D as DatabaseClient, T as Transport, L as LiveHandlers, R as RemoteSubscription, a as RemoteSubscriptionBuilder, S as SubscribeOptions, b as RegistryDigestSource } from '../client-base-BxTocU1x.js';
|
|
6
|
+
export { c as LoadAllOptions, d as RemoteDatabase, e as RemoteError, f as SQL_REFUSED_MESSAGE, g as ServerCapabilities, h as ServerCapabilityCheck } from '../client-base-BxTocU1x.js';
|
|
7
|
+
import { a as LiveQuery, b as LiveQueryState, c as LiveUpdate } from '../types-CEJG0eFS.js';
|
|
8
|
+
import { l as DeviceSyncPort, D as Database } from '../database-CGDsXW1K.js';
|
|
9
|
+
import { C as ChangeEvent, P as Params, R as ReadConcern, W as WriteConcern } from '../query-types-5B02ixH0.js';
|
|
10
|
+
import { Q as QueryResponse, E as ExecuteResponse, T as TransactionResponse, B as BatchResponse, L as LoadResponse, A as AckResponse } from '../protocol-DFpNNsIT.js';
|
|
11
|
+
import '../operation-registry-CGhNT-Sn.js';
|
|
12
|
+
import '../types-Dc8oWlxj.js';
|
|
13
|
+
import '../database-backup-DcLhxoa1.js';
|
|
14
|
+
import '../change-tracker-DqCdeEyx.js';
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
|
-
* Connects to one sirannon-db server and
|
|
17
|
+
* Connects to one sirannon-db server and returns a {@link RemoteDatabase} for each database on it.
|
|
18
18
|
*
|
|
19
19
|
* @public
|
|
20
20
|
*/
|
|
@@ -22,14 +22,14 @@ declare class SirannonClient extends DatabaseClient {
|
|
|
22
22
|
private readonly baseUrl;
|
|
23
23
|
constructor(url: string, options?: ClientOptions);
|
|
24
24
|
/**
|
|
25
|
-
* Builds the transport
|
|
25
|
+
* Builds the transport that sends one database's requests.
|
|
26
26
|
*
|
|
27
27
|
* @param databaseId - Identifier of the database.
|
|
28
28
|
* @returns A transport bound to that database.
|
|
29
29
|
*/
|
|
30
30
|
protected createTransport(databaseId: string): Transport;
|
|
31
31
|
/**
|
|
32
|
-
* Returns the address
|
|
32
|
+
* Returns the address that this client sends requests to.
|
|
33
33
|
*
|
|
34
34
|
* @returns The server's base address.
|
|
35
35
|
*/
|
|
@@ -37,7 +37,7 @@ declare class SirannonClient extends DatabaseClient {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
|
-
* A live query
|
|
40
|
+
* A live query on a remote server, which keeps its rows current as rows change in the tables that the query selects from.
|
|
41
41
|
*
|
|
42
42
|
* @public
|
|
43
43
|
*/
|
|
@@ -51,18 +51,18 @@ declare class RemoteLiveQuery<T> implements LiveQuery<T> {
|
|
|
51
51
|
/** @internal */
|
|
52
52
|
static open<T>(subscribe: (handlers: LiveHandlers) => Promise<RemoteSubscription>, onError?: (error: Error) => void): Promise<RemoteLiveQuery<T>>;
|
|
53
53
|
/**
|
|
54
|
-
* Returns the
|
|
54
|
+
* Returns the query's current state, which is its status with either its rows or its error.
|
|
55
55
|
*/
|
|
56
56
|
getState(): LiveQueryState<T>;
|
|
57
57
|
/**
|
|
58
|
-
* Calls
|
|
58
|
+
* Calls the listener with each update, and returns a function that removes it.
|
|
59
59
|
*
|
|
60
60
|
* @param listener - Receives each update.
|
|
61
61
|
* @returns A function that removes the listener.
|
|
62
62
|
*/
|
|
63
63
|
subscribe(listener: (update: LiveUpdate<T>) => void): () => void;
|
|
64
64
|
/**
|
|
65
|
-
* Ends the query and
|
|
65
|
+
* Ends the query and unsubscribes it from the server.
|
|
66
66
|
*/
|
|
67
67
|
close(): Promise<void>;
|
|
68
68
|
private handlers;
|
|
@@ -74,62 +74,62 @@ declare class RemoteLiveQuery<T> implements LiveQuery<T> {
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
/**
|
|
77
|
-
*
|
|
77
|
+
* The progress of a snapshot download, for the current table and across every table.
|
|
78
78
|
*
|
|
79
79
|
* @public
|
|
80
80
|
*/
|
|
81
81
|
interface SnapshotProgress {
|
|
82
|
-
/**
|
|
82
|
+
/** The table that `downloadDatabaseSnapshot` is copying now. */
|
|
83
83
|
table: string;
|
|
84
|
-
/**
|
|
84
|
+
/** The number of that table's rows in the local database so far. */
|
|
85
85
|
tableLoadedRows: number;
|
|
86
|
-
/**
|
|
86
|
+
/** The total number of rows in that table, from the server's manifest. */
|
|
87
87
|
tableTotalRows: number;
|
|
88
|
-
/**
|
|
88
|
+
/** The number of rows in the local database so far, across every table. */
|
|
89
89
|
loadedRows: number;
|
|
90
|
-
/**
|
|
90
|
+
/** The total number of rows in the snapshot. */
|
|
91
91
|
totalRows: number;
|
|
92
92
|
}
|
|
93
93
|
/**
|
|
94
|
-
*
|
|
94
|
+
* The server and database that a snapshot comes from, and the settings for reading it.
|
|
95
95
|
*
|
|
96
96
|
* @public
|
|
97
97
|
*/
|
|
98
98
|
interface SnapshotDownloadOptions {
|
|
99
|
-
/**
|
|
99
|
+
/** The address of the server that serves the snapshot. */
|
|
100
100
|
url: string;
|
|
101
|
-
/**
|
|
101
|
+
/** The identifier of the database to copy. */
|
|
102
102
|
databaseId: string;
|
|
103
|
-
/** Headers
|
|
103
|
+
/** Headers that `downloadDatabaseSnapshot` adds to each snapshot request. */
|
|
104
104
|
headers?: Record<string, string>;
|
|
105
|
-
/**
|
|
105
|
+
/** The number of rows to request per page. Defaults to 500. */
|
|
106
106
|
pageSize?: number;
|
|
107
|
-
/**
|
|
107
|
+
/** The time limit, in milliseconds, for each request. */
|
|
108
108
|
requestTimeoutMs?: number;
|
|
109
|
-
/** Called
|
|
109
|
+
/** Called after `downloadDatabaseSnapshot` loads each page that contains rows. */
|
|
110
110
|
onProgress?: (progress: SnapshotProgress) => void;
|
|
111
111
|
}
|
|
112
112
|
/**
|
|
113
|
-
*
|
|
113
|
+
* The result of one snapshot download.
|
|
114
114
|
*
|
|
115
115
|
* @public
|
|
116
116
|
*/
|
|
117
117
|
interface SnapshotDownloadResult {
|
|
118
|
-
/**
|
|
118
|
+
/** The change-log position from which the device resumes its subscription. */
|
|
119
119
|
startSeq: bigint;
|
|
120
|
-
/**
|
|
120
|
+
/** The epoch that identifies the sequence space of that position. */
|
|
121
121
|
epoch: string;
|
|
122
|
-
/**
|
|
122
|
+
/** The tables in the snapshot. */
|
|
123
123
|
tables: string[];
|
|
124
|
-
/**
|
|
124
|
+
/** The number of rows that `downloadDatabaseSnapshot` wrote. */
|
|
125
125
|
loadedRows: number;
|
|
126
126
|
}
|
|
127
127
|
/**
|
|
128
|
-
* Copies a database from a server into a local
|
|
128
|
+
* Copies a database from a server into a local database, and replaces every local table that the snapshot contains.
|
|
129
129
|
*
|
|
130
|
-
* @param port - The local database the snapshot
|
|
131
|
-
* @param options -
|
|
132
|
-
* @returns The change-log position and
|
|
130
|
+
* @param port - The local database to write the snapshot into.
|
|
131
|
+
* @param options - The server and database that the snapshot comes from, and the settings for reading it.
|
|
132
|
+
* @returns The change-log position and epoch to resume from, the tables that this function copied, and the number of rows that it wrote.
|
|
133
133
|
*
|
|
134
134
|
* @public
|
|
135
135
|
*/
|
|
@@ -137,9 +137,8 @@ declare function downloadDatabaseSnapshot(port: DeviceSyncPort, options: Snapsho
|
|
|
137
137
|
|
|
138
138
|
/**
|
|
139
139
|
* Builds a remote CDC subscription with optional row-level filters.
|
|
140
|
-
*
|
|
141
|
-
* a promise
|
|
142
|
-
* requires a server round-trip.
|
|
140
|
+
* It has the same methods as the core `SubscriptionBuilder`, but `subscribe()`
|
|
141
|
+
* returns a promise, because the server has to confirm the subscription first.
|
|
143
142
|
*
|
|
144
143
|
* @internal
|
|
145
144
|
*/
|
|
@@ -153,83 +152,83 @@ declare class RemoteSubscriptionBuilderImpl implements RemoteSubscriptionBuilder
|
|
|
153
152
|
}
|
|
154
153
|
|
|
155
154
|
/**
|
|
156
|
-
*
|
|
155
|
+
* Settings that control how a device keeps its local database in step with a server.
|
|
157
156
|
*
|
|
158
157
|
* @public
|
|
159
158
|
*/
|
|
160
159
|
interface SyncControllerOptions {
|
|
161
|
-
/**
|
|
160
|
+
/** The address of the server that this device syncs with. */
|
|
162
161
|
url: string;
|
|
163
|
-
/**
|
|
162
|
+
/** The identifier of the database on that server. */
|
|
164
163
|
databaseId: string;
|
|
165
|
-
/**
|
|
164
|
+
/** The tables that this device syncs. */
|
|
166
165
|
tables: readonly string[];
|
|
167
|
-
/** Headers
|
|
166
|
+
/** Headers that the controller adds to every HTTP request, and to the pull subscription's WebSocket upgrade in a runtime whose WebSocket constructor accepts handshake headers. */
|
|
168
167
|
headers?: Record<string, string>;
|
|
169
|
-
/** Subprotocols
|
|
168
|
+
/** Subprotocols that the controller offers on the pull subscription's WebSocket upgrade, which is how a browser device sends a credential. The controller offers `sirannon.v1` ahead of them. */
|
|
170
169
|
webSocketProtocols?: string | string[];
|
|
171
|
-
/**
|
|
170
|
+
/** The number of changes that the controller reads from the outbox for one push. */
|
|
172
171
|
batchSize?: number;
|
|
173
172
|
/** Milliseconds between pushes of locally recorded changes. */
|
|
174
173
|
pushIntervalMs?: number;
|
|
175
174
|
/** Milliseconds between acknowledgements of pulled changes. */
|
|
176
175
|
ackIntervalMs?: number;
|
|
177
|
-
/**
|
|
176
|
+
/** The longest delay, in milliseconds, between retries of a failed push. */
|
|
178
177
|
maxPushRetryDelayMs?: number;
|
|
179
|
-
/**
|
|
178
|
+
/** The time, in milliseconds, that the controller allows for a single request. */
|
|
180
179
|
requestTimeout?: number;
|
|
181
|
-
/**
|
|
180
|
+
/** Whether the controller downloads a fresh snapshot automatically when it marks the device for a resync. Defaults to true. */
|
|
182
181
|
autoResync?: boolean;
|
|
183
182
|
/** Milliseconds before the first retry of a failed snapshot download. */
|
|
184
183
|
snapshotRetryDelayMs?: number;
|
|
185
|
-
/**
|
|
184
|
+
/** The longest delay, in milliseconds, between snapshot retries. */
|
|
186
185
|
maxSnapshotRetryDelayMs?: number;
|
|
187
|
-
/**
|
|
186
|
+
/** The number of rows that the controller requests per snapshot page. */
|
|
188
187
|
snapshotPageSize?: number;
|
|
189
|
-
/**
|
|
188
|
+
/** The number of unacknowledged pulled changes above which the device acknowledges at once, ahead of `ackIntervalMs`. */
|
|
190
189
|
immediateAckAfterChanges?: number;
|
|
191
|
-
/**
|
|
190
|
+
/** The conflict resolver that the controller applies when a pulled change conflicts with a local change, or a function that returns one for each table. */
|
|
192
191
|
resolver?: ConflictResolver | ((table: string) => ConflictResolver);
|
|
193
|
-
/** Called
|
|
192
|
+
/** Called with each change that this device pulls. */
|
|
194
193
|
onChange?: (event: ChangeEvent) => void;
|
|
195
|
-
/** Called with this device's status when the controller changes state, pushes a batch, applies a pulled batch,
|
|
194
|
+
/** Called with this device's status when the controller changes state, pushes a batch, applies a pulled batch, marks the device for a resync, or records or clears an error. */
|
|
196
195
|
onStatusChange?: (status: SyncStatus) => void;
|
|
197
|
-
/** Called when the
|
|
196
|
+
/** Called when the controller marks the device for a fresh snapshot download. */
|
|
198
197
|
onResyncRequired?: () => void;
|
|
199
|
-
/** Called
|
|
198
|
+
/** Called after the controller loads each snapshot page that contains rows. */
|
|
200
199
|
onSnapshotProgress?: (progress: SnapshotProgress) => void;
|
|
201
|
-
/** Called
|
|
200
|
+
/** Called with the outcome when a snapshot download succeeds or fails. */
|
|
202
201
|
onSnapshotComplete?: (outcome: SnapshotOutcome) => void;
|
|
203
202
|
}
|
|
204
203
|
/**
|
|
205
|
-
*
|
|
204
|
+
* The result of a snapshot download, and whether the local database is usable afterwards.
|
|
206
205
|
*
|
|
207
206
|
* @public
|
|
208
207
|
*/
|
|
209
208
|
type SnapshotOutcome = {
|
|
210
|
-
/** True
|
|
209
|
+
/** True when the download finishes and its rows are in place. */
|
|
211
210
|
ok: true;
|
|
212
|
-
/** Null
|
|
211
|
+
/** Null when the download finishes. */
|
|
213
212
|
error: null;
|
|
214
|
-
/** True, because
|
|
213
|
+
/** True, because the local database is ready to read after a download finishes. */
|
|
215
214
|
databaseUsable: true;
|
|
216
|
-
/** False, because
|
|
215
|
+
/** False, because the controller schedules no retry after a download finishes. */
|
|
217
216
|
retrying: false;
|
|
218
217
|
} | {
|
|
219
|
-
/** False
|
|
218
|
+
/** False when the download fails. */
|
|
220
219
|
ok: false;
|
|
221
|
-
/** The code and message of
|
|
220
|
+
/** The code and message of the error that stopped the download. */
|
|
222
221
|
error: {
|
|
223
222
|
code: string;
|
|
224
223
|
message: string;
|
|
225
224
|
};
|
|
226
|
-
/** Whether the local database still
|
|
225
|
+
/** Whether the local database still accepts reads and writes after the failure. */
|
|
227
226
|
databaseUsable: boolean;
|
|
228
|
-
/** True
|
|
227
|
+
/** True when the controller has another attempt scheduled. */
|
|
229
228
|
retrying: boolean;
|
|
230
229
|
};
|
|
231
230
|
/**
|
|
232
|
-
*
|
|
231
|
+
* The current state of a sync controller.
|
|
233
232
|
*
|
|
234
233
|
* @public
|
|
235
234
|
*/
|
|
@@ -240,36 +239,36 @@ type SyncState = 'stopped' | 'starting' | 'running' | 'paused' | 'snapshotting';
|
|
|
240
239
|
* @public
|
|
241
240
|
*/
|
|
242
241
|
interface SnapshotOptions {
|
|
243
|
-
/**
|
|
242
|
+
/** The number of rows that the controller requests per page. */
|
|
244
243
|
pageSize?: number;
|
|
245
|
-
/** Called
|
|
244
|
+
/** Called after the controller loads each page that contains rows. */
|
|
246
245
|
onProgress?: (progress: SnapshotProgress) => void;
|
|
247
246
|
}
|
|
248
247
|
/**
|
|
249
|
-
*
|
|
248
|
+
* The sync status of a device against its server.
|
|
250
249
|
*
|
|
251
250
|
* @public
|
|
252
251
|
*/
|
|
253
252
|
interface SyncStatus {
|
|
254
|
-
/**
|
|
253
|
+
/** The controller's current state. */
|
|
255
254
|
state: SyncState;
|
|
256
|
-
/**
|
|
255
|
+
/** The identifier that this device uses with the server, or null before the controller starts. */
|
|
257
256
|
deviceId: string | null;
|
|
258
|
-
/**
|
|
257
|
+
/** The capabilities that the server announces, or null before the controller fetches them. */
|
|
259
258
|
serverCapabilities: string[] | null;
|
|
260
|
-
/**
|
|
259
|
+
/** The schema version of the local database. */
|
|
261
260
|
schemaVersion: number | null;
|
|
262
|
-
/**
|
|
261
|
+
/** The number of local changes that the controller has not yet pushed. */
|
|
263
262
|
pendingPushCount: number;
|
|
264
|
-
/**
|
|
263
|
+
/** The highest local change-log position that the server acknowledges. */
|
|
265
264
|
lastPushedSeq: bigint;
|
|
266
|
-
/**
|
|
265
|
+
/** The server change-log position up to which the local database is current, or null before the device first subscribes. */
|
|
267
266
|
lastPulledSeq: bigint | null;
|
|
268
|
-
/**
|
|
267
|
+
/** True when the pending push count is 0. */
|
|
269
268
|
pushCaughtUp: boolean;
|
|
270
|
-
/** Whether
|
|
269
|
+
/** Whether this device must download a fresh snapshot before it can pull changes again. */
|
|
271
270
|
resyncRequired: boolean;
|
|
272
|
-
/** The most recent failure, or null when the
|
|
271
|
+
/** The most recent failure, or null when there is none or the controller clears it after a later success. */
|
|
273
272
|
lastError: {
|
|
274
273
|
code: string;
|
|
275
274
|
message: string;
|
|
@@ -277,7 +276,7 @@ interface SyncStatus {
|
|
|
277
276
|
}
|
|
278
277
|
|
|
279
278
|
/**
|
|
280
|
-
* Keeps one device's local database in step with a server
|
|
279
|
+
* Keeps one device's local database in step with a server by pushing local changes, pulling the server's changes, and downloading a fresh snapshot when the server requires a resync.
|
|
281
280
|
*
|
|
282
281
|
* @public
|
|
283
282
|
*/
|
|
@@ -285,19 +284,16 @@ declare class SyncController {
|
|
|
285
284
|
private readonly db;
|
|
286
285
|
private readonly options;
|
|
287
286
|
private readonly baseUrl;
|
|
288
|
-
private readonly pushIntervalMs;
|
|
289
|
-
private readonly maxPushRetryDelayMs;
|
|
290
287
|
private readonly pull;
|
|
291
288
|
private readonly push;
|
|
292
289
|
private readonly resync;
|
|
290
|
+
private readonly reconnect;
|
|
293
291
|
private readonly statusChanges;
|
|
294
292
|
private port;
|
|
295
293
|
private deviceId;
|
|
296
294
|
private capabilities;
|
|
297
295
|
private schemaVersion;
|
|
298
296
|
private syncState;
|
|
299
|
-
private pullRetryTimer;
|
|
300
|
-
private consecutivePullFailures;
|
|
301
297
|
private pendingPushCount;
|
|
302
298
|
private lastError;
|
|
303
299
|
constructor(db: Database, options: SyncControllerOptions);
|
|
@@ -306,10 +302,17 @@ declare class SyncController {
|
|
|
306
302
|
private setError;
|
|
307
303
|
/**
|
|
308
304
|
* Connects to the server and starts pushing and pulling changes.
|
|
305
|
+
*
|
|
306
|
+
* When the server is unreachable, the promise still resolves, `status()` reports `running` with the failure in
|
|
307
|
+
* `lastError`, and the controller retries the connection with growing waits. It makes no attempt while the device
|
|
308
|
+
* reports no network, and it retries at once when the network returns.
|
|
309
|
+
*
|
|
310
|
+
* @throws A `RemoteError` when the server refuses device sync, such as `DEVICE_SYNC_NOT_ACCEPTED`, `UNAUTHORIZED`, or
|
|
311
|
+
* `FORBIDDEN`.
|
|
309
312
|
*/
|
|
310
313
|
start(): Promise<void>;
|
|
311
314
|
/**
|
|
312
|
-
*
|
|
315
|
+
* Pauses pushing and pulling and closes the pull connection until you call {@link SyncController.resume}.
|
|
313
316
|
*/
|
|
314
317
|
pause(): void;
|
|
315
318
|
/**
|
|
@@ -321,7 +324,7 @@ declare class SyncController {
|
|
|
321
324
|
*/
|
|
322
325
|
stop(): Promise<void>;
|
|
323
326
|
/**
|
|
324
|
-
*
|
|
327
|
+
* Returns this device's sync status, with the pending push count read fresh from the outbox.
|
|
325
328
|
*
|
|
326
329
|
* @returns The device's state, cursors, pending push count, and last failure.
|
|
327
330
|
*/
|
|
@@ -329,7 +332,7 @@ declare class SyncController {
|
|
|
329
332
|
private captureStatus;
|
|
330
333
|
private refreshOutboxCount;
|
|
331
334
|
/**
|
|
332
|
-
* Pushes local changes now
|
|
335
|
+
* Pushes local changes now, ahead of the next push interval.
|
|
333
336
|
*/
|
|
334
337
|
triggerPush(): void;
|
|
335
338
|
private verifyCapabilities;
|
|
@@ -342,22 +345,15 @@ declare class SyncController {
|
|
|
342
345
|
* @param options - Page size and the progress callback for this download.
|
|
343
346
|
*/
|
|
344
347
|
downloadSnapshot(options?: SnapshotOptions): Promise<void>;
|
|
345
|
-
/**
|
|
346
|
-
* Answers whether the local database serves reads and writes again. A failure
|
|
347
|
-
* before the wipe begins leaves it intact, while one after it leaves every
|
|
348
|
-
* statement refused with `SNAPSHOT_IN_PROGRESS` until a later copy succeeds,
|
|
349
|
-
* so the application learns which of the two it is rather than assuming.
|
|
350
|
-
*/
|
|
351
|
-
private snapshotGateOpen;
|
|
352
348
|
private recordError;
|
|
353
349
|
private handleApplyFailure;
|
|
354
350
|
private reopenPull;
|
|
355
351
|
/**
|
|
356
|
-
* Opens the pull subscription,
|
|
357
|
-
* it because this device is behind. A device
|
|
358
|
-
*
|
|
359
|
-
* server has migrated
|
|
360
|
-
* subscription
|
|
352
|
+
* Opens the pull subscription, and reconciles migrations when the server refuses
|
|
353
|
+
* it with `MIGRATION_REQUIRED` because this device's schema is behind. A device
|
|
354
|
+
* that only reads never pushes, so the refused subscription is the only signal
|
|
355
|
+
* that the server has migrated. Without this step, the controller would retry the
|
|
356
|
+
* same refused subscription indefinitely and the device would receive no changes.
|
|
361
357
|
*/
|
|
362
358
|
private openPull;
|
|
363
359
|
private teardownStream;
|
|
@@ -395,23 +391,23 @@ interface ChangesResponse {
|
|
|
395
391
|
}
|
|
396
392
|
|
|
397
393
|
/**
|
|
398
|
-
* Encodes a device-sync batch into the shape the changes route accepts.
|
|
394
|
+
* Encodes a device-sync batch into the shape that the changes route accepts.
|
|
399
395
|
*
|
|
400
396
|
* @internal
|
|
401
397
|
*/
|
|
402
398
|
declare function encodeSyncBatch(batch: ReplicationBatch): ChangesRequest['batch'];
|
|
403
399
|
/**
|
|
404
|
-
* Sends a device-sync batch to the server and returns
|
|
400
|
+
* Sends a device-sync batch to the server and returns how many changes the server applied, skipped, and counted as conflicts.
|
|
405
401
|
*
|
|
406
402
|
* @internal
|
|
407
403
|
*/
|
|
408
404
|
declare function pushSyncBatch(baseUrl: string, databaseId: string, batch: ReplicationBatch, headers?: Record<string, string>, timeoutMs?: number, schemaVersion?: number): Promise<ChangesResponse>;
|
|
409
405
|
|
|
410
406
|
/**
|
|
411
|
-
*
|
|
412
|
-
* server's
|
|
413
|
-
* and
|
|
414
|
-
*
|
|
407
|
+
* Sends queries, writes, transactions, batches, bulk loads, and registered
|
|
408
|
+
* operations to a sirannon-db server's HTTP routes with `fetch`. Change
|
|
409
|
+
* subscriptions and live queries need a WebSocket connection, so use
|
|
410
|
+
* {@link WebSocketTransport} for them.
|
|
415
411
|
*
|
|
416
412
|
* @public
|
|
417
413
|
*/
|
|
@@ -426,37 +422,36 @@ declare class HttpTransport implements Transport {
|
|
|
426
422
|
query(sql: string, params?: Params, readConcern?: ReadConcern): Promise<QueryResponse>;
|
|
427
423
|
/** Sends one write. */
|
|
428
424
|
execute(sql: string, params?: Params): Promise<ExecuteResponse>;
|
|
429
|
-
/** Sends several statements the server
|
|
425
|
+
/** Sends several statements that the server executes in one transaction. */
|
|
430
426
|
transaction(statements: Array<{
|
|
431
427
|
sql: string;
|
|
432
428
|
params?: Params;
|
|
433
429
|
}>): Promise<TransactionResponse>;
|
|
434
|
-
/** Sends one statement
|
|
430
|
+
/** Sends one statement with many parameter sets, which the server executes in one transaction. */
|
|
435
431
|
batch(sql: string, paramsBatch: Params[], writeConcern?: WriteConcern): Promise<BatchResponse>;
|
|
436
|
-
/** Sends a bulk load, which the server
|
|
432
|
+
/** Sends a bulk load, which the server executes at relaxed durability. */
|
|
437
433
|
load(sql: string, paramsBatch: Params[], durability?: BulkLoadDurability, checkpoint?: boolean): Promise<LoadResponse>;
|
|
438
|
-
/**
|
|
434
|
+
/** Executes a registered read by name and returns its rows. */
|
|
439
435
|
queryNamed(name: string, args?: Record<string, unknown>, readConcern?: ReadConcern): Promise<QueryResponse>;
|
|
440
|
-
/**
|
|
436
|
+
/** Executes a registered write by name. */
|
|
441
437
|
executeNamed(name: string, args?: Record<string, unknown>, writeConcern?: WriteConcern): Promise<TransactionResponse>;
|
|
442
|
-
/**
|
|
438
|
+
/** Throws a `RemoteError` with code `TRANSPORT_ERROR`, because live queries need the WebSocket transport. */
|
|
443
439
|
liveSubscribe(): Promise<RemoteSubscription>;
|
|
444
|
-
/**
|
|
440
|
+
/** Throws a `RemoteError` with code `TRANSPORT_ERROR`, because change subscriptions need the WebSocket transport. */
|
|
445
441
|
subscribe(_table: string, _filter: Record<string, unknown> | undefined, _callback: (event: ChangeEvent) => void): Promise<RemoteSubscription>;
|
|
446
|
-
/** Closes the transport
|
|
442
|
+
/** Closes the transport, so every later request throws a `RemoteError` with code `TRANSPORT_ERROR`. */
|
|
447
443
|
close(): void;
|
|
448
444
|
private post;
|
|
449
445
|
}
|
|
450
446
|
|
|
451
447
|
/**
|
|
452
|
-
*
|
|
453
|
-
*
|
|
454
|
-
*
|
|
455
|
-
* connection.
|
|
448
|
+
* Sends queries, writes, transactions, batches, bulk loads, and change
|
|
449
|
+
* subscriptions to sirannon-db over one WebSocket connection to
|
|
450
|
+
* `ws(s)://host:port/db/{id}`.
|
|
456
451
|
*
|
|
457
|
-
*
|
|
458
|
-
*
|
|
459
|
-
*
|
|
452
|
+
* The transport opens the connection on first use. When `autoReconnect` is on
|
|
453
|
+
* and a subscription or live query is open, it reconnects after a disconnect
|
|
454
|
+
* and subscribes again; otherwise it reconnects on the next request.
|
|
460
455
|
*
|
|
461
456
|
* @public
|
|
462
457
|
*/
|
|
@@ -478,6 +473,8 @@ declare class WebSocketTransport implements Transport {
|
|
|
478
473
|
private closed;
|
|
479
474
|
private connectPromise;
|
|
480
475
|
private reconnectTimer;
|
|
476
|
+
private subscriptionsRestored;
|
|
477
|
+
private restorePromise;
|
|
481
478
|
constructor(url: string, options?: {
|
|
482
479
|
autoReconnect?: boolean;
|
|
483
480
|
reconnectInterval?: number;
|
|
@@ -489,33 +486,34 @@ declare class WebSocketTransport implements Transport {
|
|
|
489
486
|
query(sql: string, params?: Params, readConcern?: ReadConcern): Promise<QueryResponse>;
|
|
490
487
|
/** Sends one write. */
|
|
491
488
|
execute(sql: string, params?: Params): Promise<ExecuteResponse>;
|
|
492
|
-
/** Sends several statements the server
|
|
489
|
+
/** Sends several statements that the server executes in one transaction. */
|
|
493
490
|
transaction(statements: Array<{
|
|
494
491
|
sql: string;
|
|
495
492
|
params?: Params;
|
|
496
493
|
}>): Promise<TransactionResponse>;
|
|
497
|
-
/** Sends one statement
|
|
494
|
+
/** Sends one statement with many parameter sets, which the server executes in one transaction. */
|
|
498
495
|
batch(sql: string, paramsBatch: Params[], writeConcern?: WriteConcern): Promise<BatchResponse>;
|
|
499
|
-
/** Sends a bulk load, which the server
|
|
496
|
+
/** Sends a bulk load, which the server executes at relaxed durability. */
|
|
500
497
|
load(sql: string, paramsBatch: Params[], durability?: BulkLoadDurability, checkpoint?: boolean): Promise<LoadResponse>;
|
|
501
|
-
/**
|
|
498
|
+
/** Executes a registered read by name and returns its rows. */
|
|
502
499
|
queryNamed(name: string, args?: Record<string, unknown>, readConcern?: ReadConcern): Promise<QueryResponse>;
|
|
503
|
-
/**
|
|
500
|
+
/** Executes a registered write by name. */
|
|
504
501
|
executeNamed(name: string, args?: Record<string, unknown>, writeConcern?: WriteConcern): Promise<TransactionResponse>;
|
|
505
|
-
/** Opens a live query on a registered read and
|
|
502
|
+
/** Opens a live query on a registered read and passes its updates to the handlers. */
|
|
506
503
|
liveSubscribe(name: string, args: Record<string, unknown> | undefined, handlers: LiveHandlers, registryDigest?: RegistryDigestSource): Promise<RemoteSubscription>;
|
|
507
|
-
/** Opens a change subscription on a
|
|
504
|
+
/** Opens a change subscription on a table. */
|
|
508
505
|
subscribe(table: string, filter: Record<string, unknown> | undefined, callback: (event: ChangeEvent) => void, options?: SubscribeOptions): Promise<RemoteSubscription>;
|
|
509
506
|
private sendUnsubscribe;
|
|
510
507
|
/** @internal */
|
|
511
508
|
ack(deviceId: string, seq: bigint): Promise<AckResponse>;
|
|
512
|
-
/** Closes the transport and every subscription
|
|
509
|
+
/** Closes the transport and ends every subscription on it. */
|
|
513
510
|
close(): void;
|
|
514
511
|
private nextId;
|
|
515
512
|
private ensureConnected;
|
|
516
513
|
private connect;
|
|
517
514
|
private handleDisconnect;
|
|
518
515
|
private scheduleReconnect;
|
|
516
|
+
private restoreSubscriptions;
|
|
519
517
|
private resubscribeAll;
|
|
520
518
|
private request;
|
|
521
519
|
private cancelReconnect;
|