@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
|
@@ -0,0 +1,505 @@
|
|
|
1
|
+
import { C as ChangeTracker } from './change-tracker-DqCdeEyx.js';
|
|
2
|
+
import { I as SQLiteConnection, N as NodeHealth } from './types-Dc8oWlxj.js';
|
|
3
|
+
import { S as SyncTableManifest, R as ReplicationBatch, C as ConflictResolver } from './types-DqODKeOq.js';
|
|
4
|
+
import { C as ClusterCoordinator, k as CoordinatorCompatibilityMetadata, e as ReplicationGroupState } from './types-guEKSzMr.js';
|
|
5
|
+
import { W as WriteConcern } from './query-types-5B02ixH0.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Describes a connected peer, as the transport records it.
|
|
9
|
+
*
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
interface NodeInfo {
|
|
13
|
+
/** Identifies the peer. */
|
|
14
|
+
id: string;
|
|
15
|
+
/** Identifies the peer's replication group. */
|
|
16
|
+
groupId?: string;
|
|
17
|
+
/** Records whether the peer is the primary or a replica. */
|
|
18
|
+
role: 'primary' | 'replica';
|
|
19
|
+
/** Holds the primary term that the peer reports. */
|
|
20
|
+
primaryTerm?: bigint;
|
|
21
|
+
/** Holds the replication protocol version that the peer uses. */
|
|
22
|
+
protocolVersion?: string;
|
|
23
|
+
/** Holds the time, in milliseconds since the Unix epoch, at which the peer connected. */
|
|
24
|
+
joinedAt: number;
|
|
25
|
+
/** Holds the time, in milliseconds since the Unix epoch, of the last message from the peer. The bundled transports set it only when the peer connects. */
|
|
26
|
+
lastSeenAt: number;
|
|
27
|
+
/** Holds the highest change-log position that the peer acknowledges. The bundled transports set it to `0n` only when the peer connects, while {@link PeerState.lastAckedSeq} follows each acknowledgement. */
|
|
28
|
+
lastAckedSeq: bigint;
|
|
29
|
+
/** Holds any other data that the transport attaches about the peer. */
|
|
30
|
+
metadata?: Record<string, unknown>;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Confirms that a node applied one batch.
|
|
34
|
+
*
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
interface ReplicationAck {
|
|
38
|
+
/** Identifies the batch that the node acknowledges. */
|
|
39
|
+
batchId: string;
|
|
40
|
+
/** Holds the highest change-log position that the sender applied. */
|
|
41
|
+
ackedSeq: bigint;
|
|
42
|
+
/** Identifies the node that sends the acknowledgement. */
|
|
43
|
+
nodeId: string;
|
|
44
|
+
/** Identifies the sender's replication group. */
|
|
45
|
+
groupId?: string;
|
|
46
|
+
/** Holds the primary term that the sender reports as current. */
|
|
47
|
+
primaryTerm?: bigint;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Describes a write that a replica sends to the primary, because the replica cannot accept writes itself.
|
|
51
|
+
*
|
|
52
|
+
* @public
|
|
53
|
+
*/
|
|
54
|
+
interface ForwardedTransaction {
|
|
55
|
+
/** Lists the statements to execute, in order, each with its own parameters. */
|
|
56
|
+
statements: Array<{
|
|
57
|
+
sql: string;
|
|
58
|
+
params?: Record<string, unknown> | unknown[];
|
|
59
|
+
}>;
|
|
60
|
+
/** Identifies this forwarded request. */
|
|
61
|
+
requestId: string;
|
|
62
|
+
/** Identifies the forwarding replica's replication group. */
|
|
63
|
+
groupId?: string;
|
|
64
|
+
/** Holds the primary term that the replica reports as current. */
|
|
65
|
+
primaryTerm?: bigint;
|
|
66
|
+
/** The write concern that the caller states, which the primary waits for before it replies; without one, the primary applies its own default. */
|
|
67
|
+
writeConcern?: WriteConcern;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Describes the result that the primary returns for a forwarded write.
|
|
71
|
+
*
|
|
72
|
+
* @public
|
|
73
|
+
*/
|
|
74
|
+
interface ForwardedTransactionResult {
|
|
75
|
+
/** Holds one result per statement, in the order that the primary executed them. */
|
|
76
|
+
results: Array<{
|
|
77
|
+
changes: number;
|
|
78
|
+
lastInsertRowId: number | string;
|
|
79
|
+
}>;
|
|
80
|
+
/** Holds the request ID that the primary generates for this execution, which differs from the ID in the forwarded request. */
|
|
81
|
+
requestId: string;
|
|
82
|
+
/** Identifies the primary's replication group. */
|
|
83
|
+
groupId?: string;
|
|
84
|
+
/** Holds the term under which the primary executed the write. */
|
|
85
|
+
primaryTerm?: bigint;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Describes one batch that this node sent and that its peer has yet to acknowledge.
|
|
89
|
+
*
|
|
90
|
+
* @public
|
|
91
|
+
*/
|
|
92
|
+
interface InFlightBatch {
|
|
93
|
+
/** Identifies the batch. */
|
|
94
|
+
batchId: string;
|
|
95
|
+
/** Holds the change-log position of the batch's first change. */
|
|
96
|
+
fromSeq: bigint;
|
|
97
|
+
/** Holds the change-log position of the batch's last change. */
|
|
98
|
+
toSeq: bigint;
|
|
99
|
+
/** Holds the time, in milliseconds since the Unix epoch, at which this node sent the batch. */
|
|
100
|
+
sentAt: number;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Describes one peer's replication progress, as this node tracks it.
|
|
104
|
+
*
|
|
105
|
+
* @public
|
|
106
|
+
*/
|
|
107
|
+
interface PeerState {
|
|
108
|
+
/** Identifies the peer. */
|
|
109
|
+
nodeId: string;
|
|
110
|
+
/** Holds the highest change-log position among the peer's acknowledgements. */
|
|
111
|
+
lastAckedSeq: bigint;
|
|
112
|
+
/** Holds the change-log position up to which this node sends batches to the peer. A timeout or a failed send moves it back. */
|
|
113
|
+
lastSentSeq: bigint;
|
|
114
|
+
/** Holds the highest hybrid logical clock stamp in any batch that this node has applied from the peer, and an empty string until the first such batch. */
|
|
115
|
+
lastReceivedHlc: string;
|
|
116
|
+
/** Is true while the transport has an open connection to the peer. */
|
|
117
|
+
connected: boolean;
|
|
118
|
+
/** Counts the batches that this node sent to the peer and that await acknowledgement. */
|
|
119
|
+
pendingBatches: number;
|
|
120
|
+
/** Lists the batches that this node sent to the peer and that the peer has yet to acknowledge. */
|
|
121
|
+
inFlightBatches: InFlightBatch[];
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Names how far a joining node is through first sync.
|
|
126
|
+
*
|
|
127
|
+
* @public
|
|
128
|
+
*/
|
|
129
|
+
type SyncPhase = 'pending' | 'syncing' | 'catching-up' | 'ready';
|
|
130
|
+
/**
|
|
131
|
+
* Describes a joining node's progress through first sync.
|
|
132
|
+
*
|
|
133
|
+
* @public
|
|
134
|
+
*/
|
|
135
|
+
interface SyncState {
|
|
136
|
+
/** Names how far the node is through first sync. */
|
|
137
|
+
phase: SyncPhase;
|
|
138
|
+
/** Identifies the peer that streams the copy, or is null when no sync is in progress. */
|
|
139
|
+
sourcePeerId: string | null;
|
|
140
|
+
/** Holds the change-log position at which the source took the copy. */
|
|
141
|
+
snapshotSeq: bigint | null;
|
|
142
|
+
/** Lists the tables that the node already holds in full. */
|
|
143
|
+
completedTables: string[];
|
|
144
|
+
/** Counts the tables that the copy covers. */
|
|
145
|
+
totalTables: number;
|
|
146
|
+
/** Holds the time, in milliseconds since the Unix epoch, at which the sync started. */
|
|
147
|
+
startedAt: number | null;
|
|
148
|
+
/** Holds the reason that the last sync request failed, or null when no failure is recorded. */
|
|
149
|
+
error: string | null;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Asks a peer to stream a full copy of the database.
|
|
153
|
+
*
|
|
154
|
+
* @public
|
|
155
|
+
*/
|
|
156
|
+
interface SyncRequest {
|
|
157
|
+
/** Identifies this sync, and every message of the sync repeats it. */
|
|
158
|
+
requestId: string;
|
|
159
|
+
/** Identifies the node that asks for the copy. */
|
|
160
|
+
joinerNodeId: string;
|
|
161
|
+
/** Lists the tables that the joiner already holds in full, so that the source skips them when the sync resumes. */
|
|
162
|
+
completedTables: string[];
|
|
163
|
+
/** Is true when the joiner can verify the stream with chained batch digests. */
|
|
164
|
+
supportsStreamVerification?: boolean;
|
|
165
|
+
/** Identifies the joiner's replication group. */
|
|
166
|
+
groupId?: string;
|
|
167
|
+
/** Holds the primary term that the joiner reports as current. */
|
|
168
|
+
primaryTerm?: bigint;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Holds one page of first-sync table data.
|
|
172
|
+
*
|
|
173
|
+
* @public
|
|
174
|
+
*/
|
|
175
|
+
interface SyncBatch {
|
|
176
|
+
/** Identifies the sync that this page is part of. */
|
|
177
|
+
requestId: string;
|
|
178
|
+
/** Names the table that the rows come from. */
|
|
179
|
+
table: string;
|
|
180
|
+
/** Holds the position of this page in the table's stream, counting from zero. */
|
|
181
|
+
batchIndex: number;
|
|
182
|
+
/** Holds the rows. */
|
|
183
|
+
rows: Record<string, unknown>[];
|
|
184
|
+
/** Holds the schema statements, which the source sends in a `__schema__` page before any table, so that the joiner can create the tables. */
|
|
185
|
+
schema?: string[];
|
|
186
|
+
/** Holds the checksum of the rows, which the joiner verifies before it writes them. */
|
|
187
|
+
checksum: string;
|
|
188
|
+
/** Is true on the last page of a table. */
|
|
189
|
+
isLastBatchForTable: boolean;
|
|
190
|
+
/** Counts the tables that the whole copy covers. */
|
|
191
|
+
totalTables?: number;
|
|
192
|
+
/** Identifies the source's replication group. */
|
|
193
|
+
groupId?: string;
|
|
194
|
+
/** Holds the source's primary term. */
|
|
195
|
+
primaryTerm?: bigint;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Tells a joining node that first sync is complete, and gives it the manifests that it checks the copy against.
|
|
199
|
+
*
|
|
200
|
+
* @public
|
|
201
|
+
*/
|
|
202
|
+
interface SyncComplete {
|
|
203
|
+
/** Identifies the sync that finished. */
|
|
204
|
+
requestId: string;
|
|
205
|
+
/** Holds the change-log position at which the source took the copy, which the joiner resumes replication from. */
|
|
206
|
+
snapshotSeq: bigint;
|
|
207
|
+
/** Holds one manifest per table, so that the joiner can check the rows that it received. */
|
|
208
|
+
manifests: SyncTableManifest[];
|
|
209
|
+
/** Identifies the source's replication group. */
|
|
210
|
+
groupId?: string;
|
|
211
|
+
/** Holds the source's primary term. */
|
|
212
|
+
primaryTerm?: bigint;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Tells the source whether a joining node stored one first-sync page, and gives the reason for a failure.
|
|
216
|
+
*
|
|
217
|
+
* @public
|
|
218
|
+
*/
|
|
219
|
+
interface SyncAck {
|
|
220
|
+
/** Identifies the sync that this acknowledgement is part of. */
|
|
221
|
+
requestId: string;
|
|
222
|
+
/** Identifies the joining node. */
|
|
223
|
+
joinerNodeId: string;
|
|
224
|
+
/** Names the table that the page came from. */
|
|
225
|
+
table: string;
|
|
226
|
+
/** Holds the position of the page in that table's stream. */
|
|
227
|
+
batchIndex: number;
|
|
228
|
+
/** Is true when the joiner stored the page. */
|
|
229
|
+
success: boolean;
|
|
230
|
+
/** Holds the reason that the joiner could not store the page. */
|
|
231
|
+
error?: string;
|
|
232
|
+
/** Identifies the joiner's replication group. */
|
|
233
|
+
groupId?: string;
|
|
234
|
+
/** Holds the primary term that the joiner reports as current. */
|
|
235
|
+
primaryTerm?: bigint;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Names a node's role: 'primary' accepts writes, and 'replica' serves reads.
|
|
240
|
+
*
|
|
241
|
+
* @public
|
|
242
|
+
*/
|
|
243
|
+
type TopologyRole = 'primary' | 'replica';
|
|
244
|
+
/**
|
|
245
|
+
* Sets the rules for which peers exchange changes with this node, and whether this node writes.
|
|
246
|
+
*
|
|
247
|
+
* @public
|
|
248
|
+
*/
|
|
249
|
+
interface Topology {
|
|
250
|
+
/** Records whether this node is the primary or a replica. */
|
|
251
|
+
role: TopologyRole;
|
|
252
|
+
/** Reports whether this node accepts writes. */
|
|
253
|
+
canWrite(): boolean;
|
|
254
|
+
/** Reports whether this node sends its changes to a given peer. */
|
|
255
|
+
shouldReplicateTo(peerId: string, peerRole: TopologyRole): boolean;
|
|
256
|
+
/** Reports whether this node applies the changes that a given peer sends. */
|
|
257
|
+
shouldAcceptFrom(peerId: string, peerRole: TopologyRole): boolean;
|
|
258
|
+
/** Reports whether an incoming change can conflict with a local write, so that the engine has to resolve it. */
|
|
259
|
+
requiresConflictResolution(): boolean;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Sets what the transport announces about this node when it connects, and the endpoints that it dials.
|
|
263
|
+
*
|
|
264
|
+
* @public
|
|
265
|
+
*/
|
|
266
|
+
interface TransportConfig {
|
|
267
|
+
/** Lists the addresses of the peers that this node dials. */
|
|
268
|
+
endpoints?: string[];
|
|
269
|
+
/** Sets the role that this node announces. The replication engine fills it in when it starts. */
|
|
270
|
+
localRole?: TopologyRole;
|
|
271
|
+
/** Sets the replication group that this node announces. */
|
|
272
|
+
groupId?: string;
|
|
273
|
+
/** Sets the primary term that this node announces. */
|
|
274
|
+
primaryTerm?: bigint;
|
|
275
|
+
/** Sets the replication protocol version that this node announces. */
|
|
276
|
+
protocolVersion?: string;
|
|
277
|
+
/** Holds any other data for the transport to announce about this node. The bundled transports ignore it. */
|
|
278
|
+
metadata?: Record<string, unknown>;
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Sends change batches, acknowledgements, forwarded writes, and first-sync
|
|
282
|
+
* messages between nodes. Implement this interface to replicate over a
|
|
283
|
+
* protocol other than the bundled gRPC and in-memory transports.
|
|
284
|
+
*
|
|
285
|
+
* @public
|
|
286
|
+
*/
|
|
287
|
+
interface ReplicationTransport {
|
|
288
|
+
/** Connects to the configured peers and announces this node. */
|
|
289
|
+
connect(localNodeId: string, config: TransportConfig): Promise<void>;
|
|
290
|
+
/** Closes every peer connection. */
|
|
291
|
+
disconnect(): Promise<void>;
|
|
292
|
+
/** Sends one batch of changes to one peer. */
|
|
293
|
+
send(peerId: string, batch: ReplicationBatch): Promise<void>;
|
|
294
|
+
/** Sends one batch of changes to every connected peer. */
|
|
295
|
+
broadcast(batch: ReplicationBatch): Promise<void>;
|
|
296
|
+
/** Confirms to a peer that this node applied one of its batches. */
|
|
297
|
+
sendAck(peerId: string, ack: ReplicationAck): Promise<void>;
|
|
298
|
+
/** Sends a write to the primary and waits for its result. */
|
|
299
|
+
forward(peerId: string, request: ForwardedTransaction): Promise<ForwardedTransactionResult>;
|
|
300
|
+
/** Asks a peer to stream a full copy of the database. */
|
|
301
|
+
requestSync(peerId: string, request: SyncRequest): Promise<void>;
|
|
302
|
+
/** Sends one page of first-sync table data. */
|
|
303
|
+
sendSyncBatch(peerId: string, batch: SyncBatch): Promise<void>;
|
|
304
|
+
/** Tells a joining node that first sync is complete, and sends the manifests that the node checks its copy against. */
|
|
305
|
+
sendSyncComplete(peerId: string, complete: SyncComplete): Promise<void>;
|
|
306
|
+
/** Tells the source whether this joining node stored one first-sync page. */
|
|
307
|
+
sendSyncAck(peerId: string, ack: SyncAck): Promise<void>;
|
|
308
|
+
/** Registers the handler that applies incoming change batches. */
|
|
309
|
+
onBatchReceived(handler: (batch: ReplicationBatch, fromPeerId: string) => Promise<void>): void;
|
|
310
|
+
/** Registers the handler that records incoming acknowledgements. */
|
|
311
|
+
onAckReceived(handler: (ack: ReplicationAck, fromPeerId: string) => void): void;
|
|
312
|
+
/** Registers the handler that executes a write that a replica forwards. */
|
|
313
|
+
onForwardReceived(handler: (request: ForwardedTransaction, fromPeerId: string) => Promise<ForwardedTransactionResult>): void;
|
|
314
|
+
/** Registers the handler that serves a first-sync request. */
|
|
315
|
+
onSyncRequested(handler: (request: SyncRequest, fromPeerId: string) => Promise<void>): void;
|
|
316
|
+
/** Registers the handler that stores an incoming first-sync page. */
|
|
317
|
+
onSyncBatchReceived(handler: (batch: SyncBatch, fromPeerId: string) => Promise<void>): void;
|
|
318
|
+
/** Registers the handler that finishes first sync and verifies the manifests. */
|
|
319
|
+
onSyncCompleteReceived(handler: (complete: SyncComplete, fromPeerId: string) => Promise<void>): void;
|
|
320
|
+
/** Registers the handler that records first-sync page acknowledgements. */
|
|
321
|
+
onSyncAckReceived(handler: (ack: SyncAck, fromPeerId: string) => void): void;
|
|
322
|
+
/** Registers the handler that the transport calls when a peer connects. */
|
|
323
|
+
onPeerConnected(handler: (peer: NodeInfo) => void): void;
|
|
324
|
+
/** Registers the handler that the transport calls when a peer disconnects. */
|
|
325
|
+
onPeerDisconnected(handler: (peerId: string) => void): void;
|
|
326
|
+
/** Returns every connected peer, keyed by node ID. */
|
|
327
|
+
peers(): ReadonlyMap<string, NodeInfo>;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Configures this node's part in the group's controller loop and the lease that makes a node the controller.
|
|
331
|
+
*
|
|
332
|
+
* @public
|
|
333
|
+
*/
|
|
334
|
+
interface CoordinatorControllerConfig {
|
|
335
|
+
/** Is true when this node competes for the controller lease, which it does by default. */
|
|
336
|
+
enabled?: boolean;
|
|
337
|
+
/** Sets the ID that this node holds the lease under. Defaults to the node ID. */
|
|
338
|
+
holderId?: string;
|
|
339
|
+
/** Sets how many milliseconds the lease lasts before the holder has to renew it. */
|
|
340
|
+
leaseTtlMs?: number;
|
|
341
|
+
/** Sets how many milliseconds pass between controller loop ticks. */
|
|
342
|
+
tickIntervalMs?: number;
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Configures coordinator-backed failover: the coordinator that stores group state, the nodes that vote, and how this
|
|
346
|
+
* node registers.
|
|
347
|
+
*
|
|
348
|
+
* @public
|
|
349
|
+
*/
|
|
350
|
+
interface CoordinatorModeConfig {
|
|
351
|
+
/** Identifies the cluster that contains this group. */
|
|
352
|
+
clusterId: string;
|
|
353
|
+
/** Identifies the replication group. */
|
|
354
|
+
groupId: string;
|
|
355
|
+
/** Sets the address that clients use to reach this node, which the coordinator stores with the node's session. */
|
|
356
|
+
endpoint?: string;
|
|
357
|
+
/** Lists the nodes that count towards the majority, which the engine uses to create the group when the coordinator has no state for it. Automatic failover requires at least three. */
|
|
358
|
+
votingDataBearingNodeIds?: string[];
|
|
359
|
+
/** Holds the coordinator that stores primary authority, node sessions, group state, and the in-sync set. */
|
|
360
|
+
coordinator: ClusterCoordinator;
|
|
361
|
+
/** Sets how many milliseconds this node's session lasts before the node has to renew it. */
|
|
362
|
+
sessionTtlMs?: number;
|
|
363
|
+
/** Turns this node's controller loop on or off, or configures it. The loop is on by default. */
|
|
364
|
+
controller?: boolean | CoordinatorControllerConfig;
|
|
365
|
+
/** Sets the versions that this node publishes, which the engine also records as the group's requirement when it creates the group. */
|
|
366
|
+
compatibility?: CoordinatorCompatibilityMetadata;
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Configures how one node replicates: its identity, topology, transport,
|
|
370
|
+
* batching, first sync, and coordinator-backed failover.
|
|
371
|
+
*
|
|
372
|
+
* @public
|
|
373
|
+
*/
|
|
374
|
+
interface ReplicationConfig {
|
|
375
|
+
/** Identifies this node, and defaults to a random ID. Coordinator mode requires one, so keep it the same across restarts. */
|
|
376
|
+
nodeId?: string;
|
|
377
|
+
/** Sets which peers exchange changes with this node, and whether this node writes. */
|
|
378
|
+
topology: Topology;
|
|
379
|
+
/** Sends batches, acknowledgements, forwarded writes, and first-sync messages between nodes. */
|
|
380
|
+
transport: ReplicationTransport;
|
|
381
|
+
/** Sets what the transport announces about this node, and the endpoints that it dials. */
|
|
382
|
+
transportConfig?: TransportConfig;
|
|
383
|
+
/** Makes a node that cannot accept writes forward `execute` and `executeBatch` calls to the primary. */
|
|
384
|
+
writeForwarding?: boolean;
|
|
385
|
+
/** Maps table names to the resolvers that replace the default for those tables. */
|
|
386
|
+
conflictResolvers?: Record<string, ConflictResolver>;
|
|
387
|
+
/** Sets the resolver for every table that has no resolver of its own. Defaults to last-writer-wins. */
|
|
388
|
+
defaultConflictResolver?: ConflictResolver;
|
|
389
|
+
/** Sets the most changes that one outgoing batch holds. */
|
|
390
|
+
batchSize?: number;
|
|
391
|
+
/** Sets how many milliseconds the sender loop waits between passes. */
|
|
392
|
+
batchIntervalMs?: number;
|
|
393
|
+
/** Sets how many unacknowledged batches one peer can have before this node pauses sending to it. */
|
|
394
|
+
maxPendingBatches?: number;
|
|
395
|
+
/** Reserved, and the engine ignores it. */
|
|
396
|
+
snapshotThreshold?: number;
|
|
397
|
+
/** Sets the largest difference, in milliseconds, between this node's clock and the newest timestamp in an incoming batch. This node rejects a batch that exceeds it. */
|
|
398
|
+
maxClockDriftMs?: number;
|
|
399
|
+
/** Sets the most changes that this node accepts in one incoming batch. This node rejects a larger batch. */
|
|
400
|
+
maxBatchChanges?: number;
|
|
401
|
+
/** Sets how many milliseconds this node waits for a batch acknowledgement before it resends the batch. */
|
|
402
|
+
ackTimeoutMs?: number;
|
|
403
|
+
/** Receives each forwarded statement on the primary before the primary executes it. Throw to refuse the whole forwarded write. */
|
|
404
|
+
onBeforeForwardedQuery?: (sql: string, params?: unknown[] | Record<string, unknown>) => void;
|
|
405
|
+
/** Sets how far a peer can fall behind before this node calls `onLagExceeded`. */
|
|
406
|
+
flowControl?: {
|
|
407
|
+
maxLagSeconds?: number;
|
|
408
|
+
onLagExceeded?: (peerId: string, lagMs: number) => void;
|
|
409
|
+
};
|
|
410
|
+
/** Makes a replica copy the full database from a source peer before it serves reads. Defaults to true. */
|
|
411
|
+
initialSync?: boolean;
|
|
412
|
+
/** Sets how many rows the source sends in each first-sync page. */
|
|
413
|
+
syncBatchSize?: number;
|
|
414
|
+
/** Sets how many first syncs this node serves at once. */
|
|
415
|
+
maxConcurrentSyncs?: number;
|
|
416
|
+
/** Sets how many milliseconds this node waits for the joiner to acknowledge each first-sync page before it aborts the sync. */
|
|
417
|
+
maxSyncDurationMs?: number;
|
|
418
|
+
/** Sets how many change-log positions a joining node can trail its source by when the node marks itself ready. */
|
|
419
|
+
maxSyncLagBeforeReady?: number;
|
|
420
|
+
/** Sets how many milliseconds the source waits for the acknowledgement of one first-sync page. */
|
|
421
|
+
syncAckTimeoutMs?: number;
|
|
422
|
+
/** Sets how many milliseconds a joining node spends catching up before it marks itself ready anyway. */
|
|
423
|
+
catchUpDeadlineMs?: number;
|
|
424
|
+
/** Sets the change-log position to start from, for a node that you seed by copying the database file. The engine uses it only when `initialSync` is false. */
|
|
425
|
+
resumeFromSeq?: bigint;
|
|
426
|
+
/** Opens the read-only connection that this node streams first-sync data from, so that writes continue while the node serves a joiner. */
|
|
427
|
+
snapshotConnectionFactory?: () => Promise<SQLiteConnection>;
|
|
428
|
+
/** Records the local changes that this node replicates. */
|
|
429
|
+
changeTracker?: ChangeTracker;
|
|
430
|
+
/** Turns on coordinator-backed failover and names the coordinator that stores the group state. */
|
|
431
|
+
coordinator?: CoordinatorModeConfig;
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Reports one node's role, peers, progress, and health.
|
|
435
|
+
*
|
|
436
|
+
* @public
|
|
437
|
+
*/
|
|
438
|
+
interface ReplicationStatus {
|
|
439
|
+
/** Identifies this node. */
|
|
440
|
+
nodeId: string;
|
|
441
|
+
/** Records whether this node is the primary or a replica. */
|
|
442
|
+
role: TopologyRole;
|
|
443
|
+
/** Describes each peer's progress, as this node tracks it. */
|
|
444
|
+
peers: PeerState[];
|
|
445
|
+
/** Holds this node's local change-log position as of the sender loop's last pass. */
|
|
446
|
+
localSeq: bigint;
|
|
447
|
+
/** Is true between the engine's `start` and `stop` calls. */
|
|
448
|
+
replicating: boolean;
|
|
449
|
+
/** Reports what this node can do at the moment, and the reason. */
|
|
450
|
+
health: NodeHealth;
|
|
451
|
+
/** Describes this node's progress through first sync. */
|
|
452
|
+
syncState?: SyncState;
|
|
453
|
+
/** Holds the group state that this node last read from the coordinator. */
|
|
454
|
+
coordinator?: CoordinatorRuntimeStatus;
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* Holds the group state that one node last read from the cluster coordinator.
|
|
458
|
+
*
|
|
459
|
+
* @public
|
|
460
|
+
*/
|
|
461
|
+
interface CoordinatorRuntimeStatus {
|
|
462
|
+
/** Identifies the cluster. */
|
|
463
|
+
clusterId: string;
|
|
464
|
+
/** Identifies the replication group. */
|
|
465
|
+
groupId: string;
|
|
466
|
+
/** Identifies the group's current primary. */
|
|
467
|
+
currentPrimary: ReplicationGroupState['currentPrimary'];
|
|
468
|
+
/** Holds the current primary's term. */
|
|
469
|
+
primaryTerm: bigint;
|
|
470
|
+
/** Lists the nodes that are in sync with the primary. */
|
|
471
|
+
inSyncNodeIds: string[];
|
|
472
|
+
/** Lists the draining nodes, which are leaving service. */
|
|
473
|
+
drainingNodeIds: string[];
|
|
474
|
+
/** Lists the repairing nodes, which are rebuilding their copy of the data. */
|
|
475
|
+
repairingNodeIds: string[];
|
|
476
|
+
/** Lists the faulted nodes, which stay out of service until an `updateNodeMaintenance` call clears the flag. */
|
|
477
|
+
faultedNodeIds: string[];
|
|
478
|
+
/** Lists the nodes that count towards the majority. */
|
|
479
|
+
votingDataBearingNodeIds: string[];
|
|
480
|
+
/** Lists the nodes that hold a live session with the coordinator. The field is present only while this node is connected to the coordinator and the coordinator supports session watches. */
|
|
481
|
+
liveNodeIds?: string[];
|
|
482
|
+
/** Is true when the group state names this node as the current primary. */
|
|
483
|
+
authority: boolean;
|
|
484
|
+
/** Is true when this node heard from the coordinator within the last session TTL. */
|
|
485
|
+
connected: boolean;
|
|
486
|
+
/** Names the state of this node's controller loop: 'disabled', 'standby' while it waits for the lease, 'active' while it holds the lease, or 'lost' after a failed renewal or a controller failure. */
|
|
487
|
+
controllerState: 'disabled' | 'standby' | 'active' | 'lost';
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* Describes a replication failure, which the engine emits as its `replication-error` event.
|
|
491
|
+
*
|
|
492
|
+
* @public
|
|
493
|
+
*/
|
|
494
|
+
interface ReplicationErrorEvent {
|
|
495
|
+
/** Holds the error. */
|
|
496
|
+
error: Error;
|
|
497
|
+
/** Names the operation that failed. */
|
|
498
|
+
operation: string;
|
|
499
|
+
/** Identifies the peer that the operation involved, if any. */
|
|
500
|
+
peerId?: string;
|
|
501
|
+
/** Is true when the engine keeps working after this failure. */
|
|
502
|
+
recoverable: boolean;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
export type { CoordinatorRuntimeStatus as C, ForwardedTransaction as F, InFlightBatch as I, NodeInfo as N, PeerState as P, ReplicationAck as R, SyncRequest as S, TransportConfig as T, ForwardedTransactionResult as a, SyncBatch as b, SyncComplete as c, SyncAck as d, ReplicationTransport as e, TopologyRole as f, ReplicationStatus as g, SyncPhase as h, ReplicationConfig as i, SyncState as j, ReplicationErrorEvent as k, Topology as l };
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/** Describes a live query's state, which is pending until the first read returns, ready with the current rows, or an error after a failure.
|
|
2
|
+
* @public
|
|
3
|
+
*/
|
|
4
|
+
type LiveQueryState<T> = {
|
|
5
|
+
/** `'pending'` while the first read is in flight, `'ready'` once the rows are available, or `'error'` after a failure. */
|
|
6
|
+
status: 'pending';
|
|
7
|
+
} | {
|
|
8
|
+
/** Marks the state that has rows. */
|
|
9
|
+
status: 'ready';
|
|
10
|
+
/** The current rows of the query, in its result order. */
|
|
11
|
+
rows: readonly T[];
|
|
12
|
+
/** `true` while Sirannon re-reads the query, in which case `rows` is the previous result until the re-read finishes. */
|
|
13
|
+
revalidating: boolean;
|
|
14
|
+
} | {
|
|
15
|
+
/** Marks the state after a failure. */
|
|
16
|
+
status: 'error';
|
|
17
|
+
/** The error that the read or its change subscription threw. */
|
|
18
|
+
error: Error;
|
|
19
|
+
};
|
|
20
|
+
/** Describes one edit to a live query's result set, as a position and the row at that position.
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
type ResultOp<T> = {
|
|
24
|
+
/** `'insert'` for an added row, `'update'` for a row that changed in place, or `'delete'` for a removed row. */
|
|
25
|
+
op: 'insert';
|
|
26
|
+
/** The zero-based position of the inserted row in the result set. */
|
|
27
|
+
index: number;
|
|
28
|
+
/** The row at that position after the edit. */
|
|
29
|
+
row: T;
|
|
30
|
+
} | {
|
|
31
|
+
/** Marks an edit to a row that changed in place. */
|
|
32
|
+
op: 'update';
|
|
33
|
+
/** The zero-based position of the row that changed. */
|
|
34
|
+
index: number;
|
|
35
|
+
/** The row after the change. */
|
|
36
|
+
row: T;
|
|
37
|
+
} | {
|
|
38
|
+
/** Marks the removal of a row. */
|
|
39
|
+
op: 'delete';
|
|
40
|
+
/** The zero-based position of the removed row before the edit. */
|
|
41
|
+
index: number;
|
|
42
|
+
};
|
|
43
|
+
/** Describes an update that a live query sends to its listeners, for a replaced result set, edits to apply, a re-read in progress, or a failure.
|
|
44
|
+
* @public
|
|
45
|
+
*/
|
|
46
|
+
type LiveUpdate<T> = {
|
|
47
|
+
/** `'rows'` for a replaced result set, `'ops'` for edits to apply, `'revalidating'` while Sirannon re-reads the query, or `'error'` after a failure. */
|
|
48
|
+
kind: 'rows';
|
|
49
|
+
} | {
|
|
50
|
+
/** Marks an update with edits to apply. */
|
|
51
|
+
kind: 'ops';
|
|
52
|
+
/** The edits, in the order in which to apply them to reach the new result set. */
|
|
53
|
+
ops: readonly ResultOp<T>[];
|
|
54
|
+
} | {
|
|
55
|
+
/** Marks the start of a re-read. */
|
|
56
|
+
kind: 'revalidating';
|
|
57
|
+
} | {
|
|
58
|
+
/** Marks a failure, whose error {@link LiveQuery.getState} returns. */
|
|
59
|
+
kind: 'error';
|
|
60
|
+
};
|
|
61
|
+
/** A registered read whose rows Sirannon updates as the underlying tables change.
|
|
62
|
+
* @public
|
|
63
|
+
*/
|
|
64
|
+
interface LiveQuery<T = Record<string, unknown>> {
|
|
65
|
+
/** Returns the query's current state, with the rows when the state is ready. */
|
|
66
|
+
getState(): LiveQueryState<T>;
|
|
67
|
+
/** Registers a listener for each update, and returns a function that removes it. */
|
|
68
|
+
subscribe(listener: (update: LiveUpdate<T>) => void): () => void;
|
|
69
|
+
/** Closes the query and releases its change subscription. */
|
|
70
|
+
close(): Promise<void>;
|
|
71
|
+
}
|
|
72
|
+
/** Settings for one live query.
|
|
73
|
+
* @public
|
|
74
|
+
*/
|
|
75
|
+
interface LiveQueryOptions {
|
|
76
|
+
/** The upper bound in milliseconds of a random delay before each re-read, so that many queries affected by one change re-read at different moments. */
|
|
77
|
+
rereadJitterMs?: number;
|
|
78
|
+
/** The largest number of changes in one transaction that Sirannon applies to the result one by one. For a larger transaction, Sirannon re-reads the whole query. */
|
|
79
|
+
maxTransactionChanges?: number;
|
|
80
|
+
/**
|
|
81
|
+
* Receives the error from any listener of this query that throws or returns a rejected promise.
|
|
82
|
+
* Sirannon calls each listener without awaiting it, so the other listeners still receive the
|
|
83
|
+
* update. Sirannon discards any error that `onError` itself throws.
|
|
84
|
+
*/
|
|
85
|
+
onError?: (error: Error) => void;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export type { LiveQueryOptions as L, ResultOp as R, LiveQuery as a, LiveQueryState as b, LiveUpdate as c };
|