@delali/sirannon-db 0.2.0 → 0.2.1
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/dist/backup-scheduler/index.d.ts +15 -1
- package/dist/backup-scheduler/index.mjs +2 -2
- package/dist/baseline-D93hcIEE.d.ts +17 -0
- package/dist/{change-tracker-DKRVUC3l.d.ts → change-tracker-DDmXB754.d.ts} +56 -8
- package/dist/{chunk-5NOIGN5Y.mjs → chunk-2QLXDHAP.mjs} +1 -1
- package/dist/{chunk-LNY2VVHE.mjs → chunk-7C36BCSN.mjs} +1 -1
- package/dist/{chunk-NVQS53NT.mjs → chunk-7FQRQH5Z.mjs} +53 -64
- package/dist/{chunk-D7LAYTKN.mjs → chunk-7R4ER4FB.mjs} +1 -1
- package/dist/{chunk-FHWTZFI4.mjs → chunk-BQFQ65OL.mjs} +1 -1
- package/dist/{chunk-O7SLN3GI.mjs → chunk-BTTFW4Z4.mjs} +1 -1
- package/dist/{chunk-H6PIVVDN.mjs → chunk-CCZK6LCB.mjs} +38 -25
- package/dist/{chunk-JZGINXTN.mjs → chunk-HCCGEIZ2.mjs} +2 -2
- package/dist/{chunk-67M7KAH6.mjs → chunk-IWGIYDMZ.mjs} +1 -1
- package/dist/{chunk-LFZ37BSX.mjs → chunk-OUSWVNWT.mjs} +1 -1
- package/dist/{chunk-HR5CWTLC.mjs → chunk-P2VJYRVY.mjs} +60 -7
- package/dist/{chunk-UC3SCMIN.mjs → chunk-PBRXXISQ.mjs} +3 -0
- package/dist/{chunk-JU64Y7HM.mjs → chunk-SBL6GN43.mjs} +1 -1
- package/dist/{chunk-EBJXPQQO.mjs → chunk-UPKKSUPA.mjs} +2 -2
- package/dist/{chunk-TJF5GZSV.mjs → chunk-VOSJBZ6Q.mjs} +1 -1
- package/dist/{chunk-PIKHN33N.mjs → chunk-VOYGMAU7.mjs} +9 -1
- package/dist/{chunk-H237TXZW.mjs → chunk-WJ67DTD6.mjs} +48 -6
- package/dist/{chunk-OQVZBEBY.mjs → chunk-XF2HH5E6.mjs} +4 -61
- package/dist/client/index.d.ts +211 -12
- package/dist/client/index.mjs +155 -67
- package/dist/client/topology.d.ts +55 -7
- package/dist/client/topology.mjs +20 -1
- package/dist/{client-base-CLWmH5Ln.d.ts → client-base-CmZO0v3m.d.ts} +133 -24
- package/dist/codegen/cli.mjs +3 -3
- package/dist/codegen/index.d.ts +92 -2
- package/dist/codegen/index.mjs +3 -3
- package/dist/core/index.d.ts +177 -15
- package/dist/core/index.mjs +2481 -2226
- package/dist/core/writer-worker.mjs +3 -3
- package/dist/database-B5Qv1-cU.d.ts +380 -0
- package/dist/driver/better-sqlite3.d.ts +18 -1
- package/dist/driver/better-sqlite3.mjs +5 -5
- package/dist/driver/bun.d.ts +28 -0
- package/dist/driver/expo.d.ts +17 -0
- package/dist/driver/node.d.ts +18 -1
- package/dist/driver/node.mjs +5 -5
- package/dist/driver/wa-sqlite.d.ts +18 -1
- package/dist/{errors-Bw5MdNCu.d.ts → errors-Dei4GdBb.d.ts} +80 -7
- package/dist/file-migrations/index.d.ts +54 -2
- package/dist/file-migrations/index.mjs +3 -3
- package/dist/{operation-registry-9DcvxcE5.d.ts → operation-registry-hlbhqu7q.d.ts} +50 -1
- package/dist/{primary-wins-DPAm2AKG.d.ts → primary-wins-B0np8JS3.d.ts} +25 -1
- package/dist/protocol-rqANt-9Q.d.ts +152 -0
- package/dist/query-types-DL3LtPvY.d.ts +95 -0
- package/dist/react/index.d.ts +58 -3
- package/dist/replication/coordinator/etcd.d.ts +63 -3
- package/dist/replication/coordinator/etcd.mjs +82 -46
- package/dist/replication/index.d.ts +329 -95
- package/dist/replication/index.mjs +256 -141
- package/dist/server/index.d.ts +230 -12
- package/dist/server/index.mjs +63 -50
- package/dist/{server-options-1JHu8pid.d.ts → server-options-Dab_Jvd_.d.ts} +96 -12
- package/dist/sirannon-CMhiJa5Y.d.ts +111 -0
- package/dist/transport/grpc.d.ts +93 -9
- package/dist/transport/grpc.mjs +63 -20
- package/dist/transport/memory.d.ts +50 -20
- package/dist/transport/memory.mjs +25 -0
- package/dist/{types-CL6piSnD.d.ts → types-BCejqzNA.d.ts} +20 -0
- package/dist/types-CMBcFPhb.d.ts +336 -0
- package/dist/types-CjhxcjhA.d.ts +123 -0
- package/dist/types-DyrCiWuc.d.ts +499 -0
- package/dist/types-rVZKnKN-.d.ts +591 -0
- package/package.json +7 -1
- package/dist/baseline-Br77Fnhb.d.ts +0 -6
- package/dist/database-BY0L5Q2n.d.ts +0 -172
- package/dist/protocol-6KrSq2Hy.d.ts +0 -66
- package/dist/sirannon-DaQSyhbJ.d.ts +0 -36
- package/dist/types-B7gmEsZW.d.ts +0 -221
- package/dist/types-BsVabqSI.d.ts +0 -139
- package/dist/types-C_D8IhpO.d.ts +0 -60
- package/dist/types-zhnRXrsb.d.ts +0 -384
|
@@ -0,0 +1,499 @@
|
|
|
1
|
+
import { C as ChangeTracker } from './change-tracker-DDmXB754.js';
|
|
2
|
+
import { e as SQLiteConnection, N as NodeHealth } from './types-rVZKnKN-.js';
|
|
3
|
+
import { S as SyncTableManifest, R as ReplicationBatch, C as ConflictResolver } from './types-CjhxcjhA.js';
|
|
4
|
+
import { C as ClusterCoordinator, j as CoordinatorCompatibilityMetadata, c as ReplicationGroupState } from './types-CMBcFPhb.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* What one node records about a peer it is connected to.
|
|
8
|
+
*
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
interface NodeInfo {
|
|
12
|
+
/** Identifier of the peer. */
|
|
13
|
+
id: string;
|
|
14
|
+
/** Replication group the peer belongs to. */
|
|
15
|
+
groupId?: string;
|
|
16
|
+
/** Whether the peer accepts writes or serves reads. */
|
|
17
|
+
role: 'primary' | 'replica';
|
|
18
|
+
/** Primary term the peer holds. */
|
|
19
|
+
primaryTerm?: bigint;
|
|
20
|
+
/** Replication protocol version the peer speaks. */
|
|
21
|
+
protocolVersion?: string;
|
|
22
|
+
/** Milliseconds since the Unix epoch, taken when the peer connected. */
|
|
23
|
+
joinedAt: number;
|
|
24
|
+
/** Milliseconds since the Unix epoch, taken at the last message from the peer. */
|
|
25
|
+
lastSeenAt: number;
|
|
26
|
+
/** Highest change-log position the peer has acknowledged. */
|
|
27
|
+
lastAckedSeq: bigint;
|
|
28
|
+
/** Anything else the transport attached about the peer. */
|
|
29
|
+
metadata?: Record<string, unknown>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Confirms that a node applied one batch.
|
|
33
|
+
*
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
36
|
+
interface ReplicationAck {
|
|
37
|
+
/** Identifier of the batch being acknowledged. */
|
|
38
|
+
batchId: string;
|
|
39
|
+
/** Highest change-log position the sender has now applied. */
|
|
40
|
+
ackedSeq: bigint;
|
|
41
|
+
/** Identifier of the node sending the acknowledgement. */
|
|
42
|
+
nodeId: string;
|
|
43
|
+
/** Replication group the sender belongs to. */
|
|
44
|
+
groupId?: string;
|
|
45
|
+
/** Primary term the sender reports as current. */
|
|
46
|
+
primaryTerm?: bigint;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* A write a replica sends to the primary, because it accepts no writes itself.
|
|
50
|
+
*
|
|
51
|
+
* @public
|
|
52
|
+
*/
|
|
53
|
+
interface ForwardedTransaction {
|
|
54
|
+
/** The statements to run, in order, each with its own parameters. */
|
|
55
|
+
statements: Array<{
|
|
56
|
+
sql: string;
|
|
57
|
+
params?: Record<string, unknown> | unknown[];
|
|
58
|
+
}>;
|
|
59
|
+
/** Identifier the result echoes, so the replica matches it to the request. */
|
|
60
|
+
requestId: string;
|
|
61
|
+
/** Replication group the forwarding replica belongs to. */
|
|
62
|
+
groupId?: string;
|
|
63
|
+
/** Primary term the replica reports as current. */
|
|
64
|
+
primaryTerm?: bigint;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* What the primary reports back for a write a replica forwarded to it.
|
|
68
|
+
*
|
|
69
|
+
* @public
|
|
70
|
+
*/
|
|
71
|
+
interface ForwardedTransactionResult {
|
|
72
|
+
/** One result per statement, in the order the primary ran them. */
|
|
73
|
+
results: Array<{
|
|
74
|
+
changes: number;
|
|
75
|
+
lastInsertRowId: number | string;
|
|
76
|
+
}>;
|
|
77
|
+
/** Identifier the request carried. */
|
|
78
|
+
requestId: string;
|
|
79
|
+
/** Replication group the primary belongs to. */
|
|
80
|
+
groupId?: string;
|
|
81
|
+
/** Primary term the primary held when it ran the write. */
|
|
82
|
+
primaryTerm?: bigint;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* One batch a node has sent and is still waiting to see acknowledged.
|
|
86
|
+
*
|
|
87
|
+
* @public
|
|
88
|
+
*/
|
|
89
|
+
interface InFlightBatch {
|
|
90
|
+
/** Identifier of the batch. */
|
|
91
|
+
batchId: string;
|
|
92
|
+
/** Change-log position of its first change. */
|
|
93
|
+
fromSeq: bigint;
|
|
94
|
+
/** Change-log position of its last change. */
|
|
95
|
+
toSeq: bigint;
|
|
96
|
+
/** Milliseconds since the Unix epoch, taken when the batch was sent. */
|
|
97
|
+
sentAt: number;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Where one peer stands from this node's point of view.
|
|
101
|
+
*
|
|
102
|
+
* @public
|
|
103
|
+
*/
|
|
104
|
+
interface PeerState {
|
|
105
|
+
/** Identifier of the peer. */
|
|
106
|
+
nodeId: string;
|
|
107
|
+
/** Highest change-log position the peer has acknowledged. */
|
|
108
|
+
lastAckedSeq: bigint;
|
|
109
|
+
/** Highest change-log position this node has sent it. */
|
|
110
|
+
lastSentSeq: bigint;
|
|
111
|
+
/** Most recent hybrid logical clock stamp received from the peer. */
|
|
112
|
+
lastReceivedHlc: string;
|
|
113
|
+
/** Whether the transport holds an open connection to the peer. */
|
|
114
|
+
connected: boolean;
|
|
115
|
+
/** Batches waiting to be sent to the peer. */
|
|
116
|
+
pendingBatches: number;
|
|
117
|
+
/** Batches sent to the peer and not yet acknowledged. */
|
|
118
|
+
inFlightBatches: InFlightBatch[];
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* How far a joining node has got through first sync.
|
|
123
|
+
*
|
|
124
|
+
* @public
|
|
125
|
+
*/
|
|
126
|
+
type SyncPhase = 'pending' | 'syncing' | 'catching-up' | 'ready';
|
|
127
|
+
/**
|
|
128
|
+
* Where a joining node stands in first sync.
|
|
129
|
+
*
|
|
130
|
+
* @public
|
|
131
|
+
*/
|
|
132
|
+
interface SyncState {
|
|
133
|
+
/** How far the node has got. */
|
|
134
|
+
phase: SyncPhase;
|
|
135
|
+
/** Peer streaming the copy, or null when no sync is running. */
|
|
136
|
+
sourcePeerId: string | null;
|
|
137
|
+
/** Change-log position the copy was taken at. */
|
|
138
|
+
snapshotSeq: bigint | null;
|
|
139
|
+
/** Tables already copied in full. */
|
|
140
|
+
completedTables: string[];
|
|
141
|
+
/** Tables the copy covers. */
|
|
142
|
+
totalTables: number;
|
|
143
|
+
/** Milliseconds since the Unix epoch, taken when the sync started. */
|
|
144
|
+
startedAt: number | null;
|
|
145
|
+
/** Why the sync failed, or null while it is going well. */
|
|
146
|
+
error: string | null;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Asks a peer to stream a full copy of the database.
|
|
150
|
+
*
|
|
151
|
+
* @public
|
|
152
|
+
*/
|
|
153
|
+
interface SyncRequest {
|
|
154
|
+
/** Identifier every message of this sync carries. */
|
|
155
|
+
requestId: string;
|
|
156
|
+
/** Identifier of the node asking for the copy. */
|
|
157
|
+
joinerNodeId: string;
|
|
158
|
+
/** Tables the joiner already holds in full, so a resumed sync skips them. */
|
|
159
|
+
completedTables: string[];
|
|
160
|
+
/** Whether the joiner verifies the stream with chained batch digests. */
|
|
161
|
+
supportsStreamVerification?: boolean;
|
|
162
|
+
/** Replication group the joiner belongs to. */
|
|
163
|
+
groupId?: string;
|
|
164
|
+
/** Primary term the joiner reports as current. */
|
|
165
|
+
primaryTerm?: bigint;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* One page of first-sync table data.
|
|
169
|
+
*
|
|
170
|
+
* @public
|
|
171
|
+
*/
|
|
172
|
+
interface SyncBatch {
|
|
173
|
+
/** Identifier of the sync this page belongs to. */
|
|
174
|
+
requestId: string;
|
|
175
|
+
/** Table these rows come from. */
|
|
176
|
+
table: string;
|
|
177
|
+
/** Position of this page in the table's stream, counting from zero. */
|
|
178
|
+
batchIndex: number;
|
|
179
|
+
/** The rows themselves. */
|
|
180
|
+
rows: Record<string, unknown>[];
|
|
181
|
+
/** Schema statements, sent with the first page so the joiner can build the tables. */
|
|
182
|
+
schema?: string[];
|
|
183
|
+
/** Checksum of the rows, which the joiner verifies before it writes them. */
|
|
184
|
+
checksum: string;
|
|
185
|
+
/** Set on the last page of a table. */
|
|
186
|
+
isLastBatchForTable: boolean;
|
|
187
|
+
/** Tables the whole copy covers. */
|
|
188
|
+
totalTables?: number;
|
|
189
|
+
/** Replication group the source belongs to. */
|
|
190
|
+
groupId?: string;
|
|
191
|
+
/** Primary term the source held. */
|
|
192
|
+
primaryTerm?: bigint;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Tells a joining node that first sync has finished, and carries what it needs to verify the copy.
|
|
196
|
+
*
|
|
197
|
+
* @public
|
|
198
|
+
*/
|
|
199
|
+
interface SyncComplete {
|
|
200
|
+
/** Identifier of the sync that finished. */
|
|
201
|
+
requestId: string;
|
|
202
|
+
/** Change-log position the copy was taken at, which the joiner resumes from. */
|
|
203
|
+
snapshotSeq: bigint;
|
|
204
|
+
/** One manifest per table, so the joiner can check what it received. */
|
|
205
|
+
manifests: SyncTableManifest[];
|
|
206
|
+
/** Replication group the source belongs to. */
|
|
207
|
+
groupId?: string;
|
|
208
|
+
/** Primary term the source held. */
|
|
209
|
+
primaryTerm?: bigint;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Confirms to the source that a joining node stored one first-sync page, or says why it could not.
|
|
213
|
+
*
|
|
214
|
+
* @public
|
|
215
|
+
*/
|
|
216
|
+
interface SyncAck {
|
|
217
|
+
/** Identifier of the sync this acknowledgement belongs to. */
|
|
218
|
+
requestId: string;
|
|
219
|
+
/** Identifier of the node that received the page. */
|
|
220
|
+
joinerNodeId: string;
|
|
221
|
+
/** Table the page came from. */
|
|
222
|
+
table: string;
|
|
223
|
+
/** Position of the page in that table's stream. */
|
|
224
|
+
batchIndex: number;
|
|
225
|
+
/** Whether the joiner stored the page. */
|
|
226
|
+
success: boolean;
|
|
227
|
+
/** Why the joiner could not store it. */
|
|
228
|
+
error?: string;
|
|
229
|
+
/** Replication group the joiner belongs to. */
|
|
230
|
+
groupId?: string;
|
|
231
|
+
/** Primary term the joiner reports as current. */
|
|
232
|
+
primaryTerm?: bigint;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Whether a node accepts writes or serves reads.
|
|
237
|
+
*
|
|
238
|
+
* @public
|
|
239
|
+
*/
|
|
240
|
+
type TopologyRole = 'primary' | 'replica';
|
|
241
|
+
/**
|
|
242
|
+
* Which nodes a change flows between, and whether this node writes.
|
|
243
|
+
*
|
|
244
|
+
* @public
|
|
245
|
+
*/
|
|
246
|
+
interface Topology {
|
|
247
|
+
/** Whether this node accepts writes or serves reads. */
|
|
248
|
+
role: TopologyRole;
|
|
249
|
+
/** Reports whether this node accepts writes right now. */
|
|
250
|
+
canWrite(): boolean;
|
|
251
|
+
/** Reports whether this node sends its changes to a given peer. */
|
|
252
|
+
shouldReplicateTo(peerId: string, peerRole: TopologyRole): boolean;
|
|
253
|
+
/** Reports whether this node applies changes arriving from a given peer. */
|
|
254
|
+
shouldAcceptFrom(peerId: string, peerRole: TopologyRole): boolean;
|
|
255
|
+
/** Reports whether incoming changes can meet a local row and need a resolver. */
|
|
256
|
+
requiresConflictResolution(): boolean;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* What a transport announces about this node when it connects, and where it dials.
|
|
260
|
+
*
|
|
261
|
+
* @public
|
|
262
|
+
*/
|
|
263
|
+
interface TransportConfig {
|
|
264
|
+
/** Addresses of the peers this node dials. */
|
|
265
|
+
endpoints?: string[];
|
|
266
|
+
/** Role this node announces. A replication engine fills it in on start. */
|
|
267
|
+
localRole?: TopologyRole;
|
|
268
|
+
/** Replication group this node announces. */
|
|
269
|
+
groupId?: string;
|
|
270
|
+
/** Primary term this node announces. */
|
|
271
|
+
primaryTerm?: bigint;
|
|
272
|
+
/** Replication protocol version this node announces. */
|
|
273
|
+
protocolVersion?: string;
|
|
274
|
+
/** Anything else the transport should announce about this node. */
|
|
275
|
+
metadata?: Record<string, unknown>;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Carries change batches, acknowledgements, forwarded writes, and first sync
|
|
279
|
+
* between nodes. Build your own to replicate over something the package does
|
|
280
|
+
* not already speak.
|
|
281
|
+
*
|
|
282
|
+
* @public
|
|
283
|
+
*/
|
|
284
|
+
interface ReplicationTransport {
|
|
285
|
+
/** Connects to the configured peers and announces this node. */
|
|
286
|
+
connect(localNodeId: string, config: TransportConfig): Promise<void>;
|
|
287
|
+
/** Closes every peer connection. */
|
|
288
|
+
disconnect(): Promise<void>;
|
|
289
|
+
/** Sends one batch of changes to one peer. */
|
|
290
|
+
send(peerId: string, batch: ReplicationBatch): Promise<void>;
|
|
291
|
+
/** Sends one batch of changes to every connected peer. */
|
|
292
|
+
broadcast(batch: ReplicationBatch): Promise<void>;
|
|
293
|
+
/** Confirms to a peer that this node applied one of its batches. */
|
|
294
|
+
sendAck(peerId: string, ack: ReplicationAck): Promise<void>;
|
|
295
|
+
/** Sends a write to the primary and waits for its result. */
|
|
296
|
+
forward(peerId: string, request: ForwardedTransaction): Promise<ForwardedTransactionResult>;
|
|
297
|
+
/** Asks a peer to stream a full copy of the database. */
|
|
298
|
+
requestSync(peerId: string, request: SyncRequest): Promise<void>;
|
|
299
|
+
/** Sends one page of first-sync table data. */
|
|
300
|
+
sendSyncBatch(peerId: string, batch: SyncBatch): Promise<void>;
|
|
301
|
+
/** Tells a joining node that first sync has finished, and sends the manifests to verify it. */
|
|
302
|
+
sendSyncComplete(peerId: string, complete: SyncComplete): Promise<void>;
|
|
303
|
+
/** Confirms to the source that a joining node stored one first-sync page. */
|
|
304
|
+
sendSyncAck(peerId: string, ack: SyncAck): Promise<void>;
|
|
305
|
+
/** Registers the handler that applies incoming change batches. */
|
|
306
|
+
onBatchReceived(handler: (batch: ReplicationBatch, fromPeerId: string) => Promise<void>): void;
|
|
307
|
+
/** Registers the handler that records incoming acknowledgements. */
|
|
308
|
+
onAckReceived(handler: (ack: ReplicationAck, fromPeerId: string) => void): void;
|
|
309
|
+
/** Registers the handler that runs a write a replica forwarded. */
|
|
310
|
+
onForwardReceived(handler: (request: ForwardedTransaction, fromPeerId: string) => Promise<ForwardedTransactionResult>): void;
|
|
311
|
+
/** Registers the handler that serves a first-sync request. */
|
|
312
|
+
onSyncRequested(handler: (request: SyncRequest, fromPeerId: string) => Promise<void>): void;
|
|
313
|
+
/** Registers the handler that stores an incoming first-sync page. */
|
|
314
|
+
onSyncBatchReceived(handler: (batch: SyncBatch, fromPeerId: string) => Promise<void>): void;
|
|
315
|
+
/** Registers the handler that finishes first sync and verifies the manifests. */
|
|
316
|
+
onSyncCompleteReceived(handler: (complete: SyncComplete, fromPeerId: string) => Promise<void>): void;
|
|
317
|
+
/** Registers the handler that records first-sync page acknowledgements. */
|
|
318
|
+
onSyncAckReceived(handler: (ack: SyncAck, fromPeerId: string) => void): void;
|
|
319
|
+
/** Registers the handler that runs when a peer connects. */
|
|
320
|
+
onPeerConnected(handler: (peer: NodeInfo) => void): void;
|
|
321
|
+
/** Registers the handler that runs when a peer disconnects. */
|
|
322
|
+
onPeerDisconnected(handler: (peerId: string) => void): void;
|
|
323
|
+
/** Returns every connected peer, keyed by identifier. */
|
|
324
|
+
peers(): ReadonlyMap<string, NodeInfo>;
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Whether this node runs the group's controller loop, and how it holds the lease that grants it.
|
|
328
|
+
*
|
|
329
|
+
* @public
|
|
330
|
+
*/
|
|
331
|
+
interface CoordinatorControllerConfig {
|
|
332
|
+
/** Whether this node stands for the controller lease. */
|
|
333
|
+
enabled?: boolean;
|
|
334
|
+
/** Identifier this node claims the lease under. Defaults to the node identifier. */
|
|
335
|
+
holderId?: string;
|
|
336
|
+
/** Milliseconds the lease lasts before it must be renewed. */
|
|
337
|
+
leaseTtlMs?: number;
|
|
338
|
+
/** Milliseconds between controller passes. */
|
|
339
|
+
tickIntervalMs?: number;
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Coordinator-backed failover: where group state is stored, which nodes vote, and how this node registers.
|
|
343
|
+
*
|
|
344
|
+
* @public
|
|
345
|
+
*/
|
|
346
|
+
interface CoordinatorModeConfig {
|
|
347
|
+
/** Identifier of the cluster this group belongs to. */
|
|
348
|
+
clusterId: string;
|
|
349
|
+
/** Identifier of the replication group. */
|
|
350
|
+
groupId: string;
|
|
351
|
+
/** Address clients reach this node at, which the group publishes to readers. */
|
|
352
|
+
endpoint?: string;
|
|
353
|
+
/** Identifiers of the nodes that count towards majority. Automatic failover needs at least three. */
|
|
354
|
+
votingDataBearingNodeIds?: string[];
|
|
355
|
+
/** Where primary authority, node sessions, group state, and the in-sync set are stored. */
|
|
356
|
+
coordinator: ClusterCoordinator;
|
|
357
|
+
/** Milliseconds this node's session lasts before it must be renewed. */
|
|
358
|
+
sessionTtlMs?: number;
|
|
359
|
+
/** Whether this node runs the group's controller loop. */
|
|
360
|
+
controller?: boolean | CoordinatorControllerConfig;
|
|
361
|
+
/** Package and specification versions this node publishes, so the group refuses an incompatible peer. */
|
|
362
|
+
compatibility?: CoordinatorCompatibilityMetadata;
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* How one node replicates: its identity, topology, transport, batching, first
|
|
366
|
+
* sync, and coordinator-backed failover.
|
|
367
|
+
*
|
|
368
|
+
* @public
|
|
369
|
+
*/
|
|
370
|
+
interface ReplicationConfig {
|
|
371
|
+
/** Identifier of this node. Coordinator mode requires a stable, persisted value. */
|
|
372
|
+
nodeId?: string;
|
|
373
|
+
/** Which nodes a change flows between, and whether this node writes. */
|
|
374
|
+
topology: Topology;
|
|
375
|
+
/** Carries batches, acknowledgements, forwarded writes, and first sync between nodes. */
|
|
376
|
+
transport: ReplicationTransport;
|
|
377
|
+
/** What the transport announces about this node, and where it dials. */
|
|
378
|
+
transportConfig?: TransportConfig;
|
|
379
|
+
/** Sends a write this node cannot serve to the primary instead of refusing it. */
|
|
380
|
+
writeForwarding?: boolean;
|
|
381
|
+
/** Resolvers to use for named tables, which override the default. */
|
|
382
|
+
conflictResolvers?: Record<string, ConflictResolver>;
|
|
383
|
+
/** Resolver for every table without one of its own. Default: last-writer-wins. */
|
|
384
|
+
defaultConflictResolver?: ConflictResolver;
|
|
385
|
+
/** Changes sent in one batch. */
|
|
386
|
+
batchSize?: number;
|
|
387
|
+
/** Milliseconds between batches. */
|
|
388
|
+
batchIntervalMs?: number;
|
|
389
|
+
/** Batches allowed in flight to one peer before this node stops sending. */
|
|
390
|
+
maxPendingBatches?: number;
|
|
391
|
+
/** Change-log distance beyond which a joining node takes a full copy instead of catching up. */
|
|
392
|
+
snapshotThreshold?: number;
|
|
393
|
+
/** Clock difference, in milliseconds, beyond which this node reports a peer's stamps as suspect. */
|
|
394
|
+
maxClockDriftMs?: number;
|
|
395
|
+
/** Changes allowed in one batch, whatever the byte size. */
|
|
396
|
+
maxBatchChanges?: number;
|
|
397
|
+
/** Milliseconds this node waits for a batch acknowledgement before it retries. */
|
|
398
|
+
ackTimeoutMs?: number;
|
|
399
|
+
/** Runs on the primary before it executes a write a replica forwarded. Throw to refuse it. */
|
|
400
|
+
onBeforeForwardedQuery?: (sql: string, params?: unknown[] | Record<string, unknown>) => void;
|
|
401
|
+
/** How far a peer may fall behind before this node reports it. */
|
|
402
|
+
flowControl?: {
|
|
403
|
+
maxLagSeconds?: number;
|
|
404
|
+
onLagExceeded?: (peerId: string, lagMs: number) => void;
|
|
405
|
+
};
|
|
406
|
+
/** Pulls a full copy of the database before serving reads. Default: true. */
|
|
407
|
+
initialSync?: boolean;
|
|
408
|
+
/** Rows sent per first-sync page. */
|
|
409
|
+
syncBatchSize?: number;
|
|
410
|
+
/** First syncs this node serves at once. */
|
|
411
|
+
maxConcurrentSyncs?: number;
|
|
412
|
+
/** Milliseconds a first sync may run before this node abandons it. */
|
|
413
|
+
maxSyncDurationMs?: number;
|
|
414
|
+
/** Change-log distance a joining node may still be behind by and be declared ready. */
|
|
415
|
+
maxSyncLagBeforeReady?: number;
|
|
416
|
+
/** Milliseconds the source waits for a first-sync page acknowledgement. */
|
|
417
|
+
syncAckTimeoutMs?: number;
|
|
418
|
+
/** Milliseconds a joining node may spend catching up before it gives up. */
|
|
419
|
+
catchUpDeadlineMs?: number;
|
|
420
|
+
/** Change-log position to start from, for a node seeded by copying the database file. */
|
|
421
|
+
resumeFromSeq?: bigint;
|
|
422
|
+
/** Opens the read-only connection this node streams first-sync data from, so serving a joiner never blocks writes. */
|
|
423
|
+
snapshotConnectionFactory?: () => Promise<SQLiteConnection>;
|
|
424
|
+
/** Records the local changes this node replicates. */
|
|
425
|
+
changeTracker?: ChangeTracker;
|
|
426
|
+
/** Turns on coordinator-backed failover and names where group state is stored. */
|
|
427
|
+
coordinator?: CoordinatorModeConfig;
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* Where one node stands: its role, its peers, its progress, and its health.
|
|
431
|
+
*
|
|
432
|
+
* @public
|
|
433
|
+
*/
|
|
434
|
+
interface ReplicationStatus {
|
|
435
|
+
/** Identifier of this node. */
|
|
436
|
+
nodeId: string;
|
|
437
|
+
/** Whether this node accepts writes or serves reads. */
|
|
438
|
+
role: TopologyRole;
|
|
439
|
+
/** Where each peer stands from this node's point of view. */
|
|
440
|
+
peers: PeerState[];
|
|
441
|
+
/** Highest change-log position this node has sent. */
|
|
442
|
+
localSeq: bigint;
|
|
443
|
+
/** Whether the engine is running. */
|
|
444
|
+
replicating: boolean;
|
|
445
|
+
/** What this node can do right now, and the condition behind it. */
|
|
446
|
+
health: NodeHealth;
|
|
447
|
+
/** Where this node stands in first sync. */
|
|
448
|
+
syncState?: SyncState;
|
|
449
|
+
/** Group state as this node last read it from the coordinator. */
|
|
450
|
+
coordinator?: CoordinatorRuntimeStatus;
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* Group state as one node last read it from the cluster coordinator.
|
|
454
|
+
*
|
|
455
|
+
* @public
|
|
456
|
+
*/
|
|
457
|
+
interface CoordinatorRuntimeStatus {
|
|
458
|
+
/** Identifier of the cluster. */
|
|
459
|
+
clusterId: string;
|
|
460
|
+
/** Identifier of the replication group. */
|
|
461
|
+
groupId: string;
|
|
462
|
+
/** The primary the group currently names. */
|
|
463
|
+
currentPrimary: ReplicationGroupState['currentPrimary'];
|
|
464
|
+
/** Term that primary holds. */
|
|
465
|
+
primaryTerm: bigint;
|
|
466
|
+
/** Nodes the group counts as in sync. */
|
|
467
|
+
inSyncNodeIds: string[];
|
|
468
|
+
/** Nodes being taken out of service. */
|
|
469
|
+
drainingNodeIds: string[];
|
|
470
|
+
/** Nodes being rebuilt. */
|
|
471
|
+
repairingNodeIds: string[];
|
|
472
|
+
/** Nodes the group has quarantined. */
|
|
473
|
+
faultedNodeIds: string[];
|
|
474
|
+
/** Nodes that count towards majority. */
|
|
475
|
+
votingDataBearingNodeIds: string[];
|
|
476
|
+
/** Whether this node holds write authority for the current term. */
|
|
477
|
+
authority: boolean;
|
|
478
|
+
/** Whether this node reaches the coordinator. */
|
|
479
|
+
connected: boolean;
|
|
480
|
+
/** Whether this node runs the group's controller loop. */
|
|
481
|
+
controllerState: 'disabled' | 'standby' | 'active' | 'lost';
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* A replication failure, delivered to listeners of the engine's `replication-error` event.
|
|
485
|
+
*
|
|
486
|
+
* @public
|
|
487
|
+
*/
|
|
488
|
+
interface ReplicationErrorEvent {
|
|
489
|
+
/** The failure itself. */
|
|
490
|
+
error: Error;
|
|
491
|
+
/** What the engine was doing when it failed. */
|
|
492
|
+
operation: string;
|
|
493
|
+
/** Peer the operation involved, when it involved one. */
|
|
494
|
+
peerId?: string;
|
|
495
|
+
/** Whether the engine carries on after this failure. */
|
|
496
|
+
recoverable: boolean;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
export type { 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, SyncPhase as g, ReplicationConfig as h, SyncState as i, ReplicationStatus as j, ReplicationErrorEvent as k, Topology as l };
|