@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,20 +1,20 @@
1
- export { F as FieldMergeResolver, L as LWWResolver, P as PrimaryWinsResolver } from '../primary-wins-B0np8JS3.js';
2
- import { C as ConflictResolver, R as ReplicationBatch } from '../types-CjhxcjhA.js';
3
- export { a as ConflictContext, b as ConflictResolution } from '../types-CjhxcjhA.js';
4
- import { C as ClientOptions, B as BulkLoadDurability } from '../server-options-Bj5iJnjx.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-Cmd9EVme.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-Cmd9EVme.js';
7
- import { a as LiveQuery, b as LiveQueryState, c as LiveUpdate } from '../types-DTO4CYhW.js';
8
- import { l as DeviceSyncPort, D as Database } from '../database-BLQvqjsw.js';
9
- import { C as ChangeEvent, P as Params, R as ReadConcern, W as WriteConcern } from '../query-types-p1liOP-b.js';
10
- import { Q as QueryResponse, E as ExecuteResponse, T as TransactionResponse, B as BatchResponse, L as LoadResponse, A as AckResponse } from '../protocol-HI-nY8DD.js';
11
- import '../operation-registry-oiPuSYI6.js';
12
- import '../types-DPSmjU54.js';
13
- import '../database-backup-B7oszQ2n.js';
14
- import '../change-tracker-CjRFuZdB.js';
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 hands out a {@link RemoteDatabase} per database.
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 a database's requests travel over.
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 requests are sent to.
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 running against a remote server, which keeps its rows current as the tables behind it change.
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 rows the query holds right now.
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 back on each update and returns a function that stops the listener.
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 releases its subscription.
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
- * How far a snapshot download has progressed, for the table in flight and overall.
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
- /** Table the download is reading right now. */
82
+ /** The table that `downloadDatabaseSnapshot` is copying now. */
83
83
  table: string;
84
- /** Rows loaded from that table so far. */
84
+ /** The number of that table's rows in the local database so far. */
85
85
  tableLoadedRows: number;
86
- /** Rows that table holds in total. */
86
+ /** The total number of rows in that table, from the server's manifest. */
87
87
  tableTotalRows: number;
88
- /** Rows loaded across every table so far. */
88
+ /** The number of rows in the local database so far, across every table. */
89
89
  loadedRows: number;
90
- /** Rows the whole snapshot holds. */
90
+ /** The total number of rows in the snapshot. */
91
91
  totalRows: number;
92
92
  }
93
93
  /**
94
- * Where a snapshot comes from and how it is read.
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
- /** Address of the server serving the snapshot. */
99
+ /** The address of the server that serves the snapshot. */
100
100
  url: string;
101
- /** Identifier of the database to copy. */
101
+ /** The identifier of the database to copy. */
102
102
  databaseId: string;
103
- /** Headers attached to each snapshot request. */
103
+ /** Headers that `downloadDatabaseSnapshot` adds to each snapshot request. */
104
104
  headers?: Record<string, string>;
105
- /** Rows requested per page. Default: 500. */
105
+ /** The number of rows to request per page. Defaults to 500. */
106
106
  pageSize?: number;
107
- /** Milliseconds a single page request may take. */
107
+ /** The time limit, in milliseconds, for each request. */
108
108
  requestTimeoutMs?: number;
109
- /** Called as each page arrives. */
109
+ /** Called after `downloadDatabaseSnapshot` loads each page that contains rows. */
110
110
  onProgress?: (progress: SnapshotProgress) => void;
111
111
  }
112
112
  /**
113
- * What one snapshot download produced.
113
+ * The result of one snapshot download.
114
114
  *
115
115
  * @public
116
116
  */
117
117
  interface SnapshotDownloadResult {
118
- /** Change-log position the device resumes its subscription from. */
118
+ /** The change-log position from which the device resumes its subscription. */
119
119
  startSeq: bigint;
120
- /** Sequence space that position belongs to. */
120
+ /** The epoch that identifies the sequence space of that position. */
121
121
  epoch: string;
122
- /** Tables the snapshot carried. */
122
+ /** The tables in the snapshot. */
123
123
  tables: string[];
124
- /** Rows the download wrote. */
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 one, replacing what the local database holds.
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 is written into.
131
- * @param options - Where the snapshot comes from and how it is read.
132
- * @returns The change-log position and sequence space to resume from, the tables copied, and the rows written.
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
- * Mirrors the core `SubscriptionBuilder` interface but returns
141
- * a promise from `subscribe()` since confirming the subscription
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
- * How a device keeps its local database in step with a server.
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
- /** Address of the server this device syncs with. */
160
+ /** The address of the server that this device syncs with. */
162
161
  url: string;
163
- /** Identifier of the database on that server. */
162
+ /** The identifier of the database on that server. */
164
163
  databaseId: string;
165
- /** Tables this device syncs. */
164
+ /** The tables that this device syncs. */
166
165
  tables: readonly string[];
167
- /** Headers attached to every HTTP request, and to the pull subscription's WebSocket upgrade in a runtime whose WebSocket carries a handshake header. */
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 offered on the pull subscription's WebSocket upgrade, which is how a browser device carries a credential. The controller offers `sirannon.v1` ahead of them. */
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
- /** Changes sent in one push. */
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
- /** Longest delay, in milliseconds, between retries of a failed push. */
176
+ /** The longest delay, in milliseconds, between retries of a failed push. */
178
177
  maxPushRetryDelayMs?: number;
179
- /** Milliseconds a single request may take. */
178
+ /** The time, in milliseconds, that the controller allows for a single request. */
180
179
  requestTimeout?: number;
181
- /** Downloads a fresh snapshot on its own when the server says the cursor is too old. Default: true. */
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
- /** Longest delay, in milliseconds, between snapshot retries. */
184
+ /** The longest delay, in milliseconds, between snapshot retries. */
186
185
  maxSnapshotRetryDelayMs?: number;
187
- /** Rows requested per snapshot page. */
186
+ /** The number of rows that the controller requests per snapshot page. */
188
187
  snapshotPageSize?: number;
189
- /** Changes after which the device acknowledges at once instead of waiting for the interval. */
188
+ /** The number of unacknowledged pulled changes above which the device acknowledges at once, ahead of `ackIntervalMs`. */
190
189
  immediateAckAfterChanges?: number;
191
- /** Resolves which version of a row wins when a pulled change meets a local one. */
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 for each change this device pulls. */
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, needs a resync, or records or clears an error. */
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 server says the device must download a fresh snapshot. */
196
+ /** Called when the controller marks the device for a fresh snapshot download. */
198
197
  onResyncRequired?: () => void;
199
- /** Called as each snapshot page arrives. */
198
+ /** Called after the controller loads each snapshot page that contains rows. */
200
199
  onSnapshotProgress?: (progress: SnapshotProgress) => void;
201
- /** Called once a snapshot download settles, whether it succeeded or failed. */
200
+ /** Called with the outcome when a snapshot download succeeds or fails. */
202
201
  onSnapshotComplete?: (outcome: SnapshotOutcome) => void;
203
202
  }
204
203
  /**
205
- * How a snapshot download settled, and whether the local database is usable afterwards.
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 where the download finished and its rows are in place. */
209
+ /** True when the download finishes and its rows are in place. */
211
210
  ok: true;
212
- /** Null on a download that finished. */
211
+ /** Null when the download finishes. */
213
212
  error: null;
214
- /** True, because a finished download leaves the local database ready to read. */
213
+ /** True, because the local database is ready to read after a download finishes. */
215
214
  databaseUsable: true;
216
- /** False, because a finished download needs no further attempt. */
215
+ /** False, because the controller schedules no retry after a download finishes. */
217
216
  retrying: false;
218
217
  } | {
219
- /** False where the download failed. */
218
+ /** False when the download fails. */
220
219
  ok: false;
221
- /** The code and message of what stopped the download. */
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 answers reads after the failure. */
225
+ /** Whether the local database still accepts reads and writes after the failure. */
227
226
  databaseUsable: boolean;
228
- /** True while the controller is making another attempt. */
227
+ /** True when the controller has another attempt scheduled. */
229
228
  retrying: boolean;
230
229
  };
231
230
  /**
232
- * What a sync controller is doing right now.
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
- /** Rows requested per page. */
242
+ /** The number of rows that the controller requests per page. */
244
243
  pageSize?: number;
245
- /** Called as each page arrives. */
244
+ /** Called after the controller loads each page that contains rows. */
246
245
  onProgress?: (progress: SnapshotProgress) => void;
247
246
  }
248
247
  /**
249
- * Where a device stands against its server.
248
+ * The sync status of a device against its server.
250
249
  *
251
250
  * @public
252
251
  */
253
252
  interface SyncStatus {
254
- /** What the controller is doing right now. */
253
+ /** The controller's current state. */
255
254
  state: SyncState;
256
- /** Identifier this device is known by on the server. */
255
+ /** The identifier that this device uses with the server, or null before the controller starts. */
257
256
  deviceId: string | null;
258
- /** Capabilities the server announced, or null before the device has asked. */
257
+ /** The capabilities that the server announces, or null before the controller fetches them. */
259
258
  serverCapabilities: string[] | null;
260
- /** Schema version the local database is at. */
259
+ /** The schema version of the local database. */
261
260
  schemaVersion: number | null;
262
- /** Local changes waiting to be pushed. */
261
+ /** The number of local changes that the controller has not yet pushed. */
263
262
  pendingPushCount: number;
264
- /** Highest local change-log position the server has accepted. */
263
+ /** The highest local change-log position that the server acknowledges. */
265
264
  lastPushedSeq: bigint;
266
- /** Highest server change-log position this device has applied. */
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
- /** Whether every local change has reached the server. */
267
+ /** True when the pending push count is 0. */
269
268
  pushCaughtUp: boolean;
270
- /** Whether the server has told this device to download a fresh snapshot. */
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 last try succeeded. */
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: it pushes local changes, pulls the server's, and downloads a fresh snapshot when the device falls too far behind.
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
- * Holds pushing and pulling without disconnecting.
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
- * Reports where this device stands against the server.
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 instead of waiting for the next interval.
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, reconciling migrations when the server refuses
357
- * it because this device is behind. A device that only reads never pushes, so
358
- * the subscribe refusal is the sole point at which it can learn that the
359
- * server has migrated; without this it would retry the same refused
360
- * subscription forever and silently receive nothing.
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 what the server applied.
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
- * HTTP transport for sirannon-db. Sends requests via `fetch` to the
412
- * server's REST endpoints. Supports query, execute, transaction, batch,
413
- * and load operations. Real-time subscriptions are not available over
414
- * HTTP; use {@link WebSocketTransport} for CDC subscriptions.
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 runs in one transaction. */
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 over many parameter sets, which the server runs in one transaction. */
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 runs at relaxed durability. */
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
- /** Runs a registered read by name and returns its rows. */
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
- /** Runs a registered write by name. */
436
+ /** Executes a registered write by name. */
441
437
  executeNamed(name: string, args?: Record<string, unknown>, writeConcern?: WriteConcern): Promise<TransactionResponse>;
442
- /** Opens a live query on a registered read and delivers its updates to the handlers. */
438
+ /** Throws a `RemoteError` with code `TRANSPORT_ERROR`, because live queries need the WebSocket transport. */
443
439
  liveSubscribe(): Promise<RemoteSubscription>;
444
- /** Opens a change subscription on a watched table. */
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 and every subscription running on it. */
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
- * WebSocket transport for sirannon-db. Connects to
453
- * `ws(s)://host:port/db/{id}` and supports query, execute, transaction,
454
- * batch, load, and real-time CDC subscriptions over a single persistent
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
- * Connections are established lazily on first use and will
458
- * auto-reconnect (with subscription restoration) when
459
- * `autoReconnect` is enabled.
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 runs in one transaction. */
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 over many parameter sets, which the server runs in one transaction. */
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 runs at relaxed durability. */
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
- /** Runs a registered read by name and returns its rows. */
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
- /** Runs a registered write by name. */
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 delivers its updates to the handlers. */
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 watched table. */
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 running on it. */
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;