@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.
Files changed (75) hide show
  1. package/dist/backup-scheduler/index.d.ts +15 -1
  2. package/dist/backup-scheduler/index.mjs +2 -2
  3. package/dist/baseline-D93hcIEE.d.ts +17 -0
  4. package/dist/{change-tracker-DKRVUC3l.d.ts → change-tracker-DDmXB754.d.ts} +56 -8
  5. package/dist/{chunk-5NOIGN5Y.mjs → chunk-2QLXDHAP.mjs} +1 -1
  6. package/dist/{chunk-LNY2VVHE.mjs → chunk-7C36BCSN.mjs} +1 -1
  7. package/dist/{chunk-NVQS53NT.mjs → chunk-7FQRQH5Z.mjs} +53 -64
  8. package/dist/{chunk-D7LAYTKN.mjs → chunk-7R4ER4FB.mjs} +1 -1
  9. package/dist/{chunk-FHWTZFI4.mjs → chunk-BQFQ65OL.mjs} +1 -1
  10. package/dist/{chunk-O7SLN3GI.mjs → chunk-BTTFW4Z4.mjs} +1 -1
  11. package/dist/{chunk-H6PIVVDN.mjs → chunk-CCZK6LCB.mjs} +38 -25
  12. package/dist/{chunk-JZGINXTN.mjs → chunk-HCCGEIZ2.mjs} +2 -2
  13. package/dist/{chunk-67M7KAH6.mjs → chunk-IWGIYDMZ.mjs} +1 -1
  14. package/dist/{chunk-LFZ37BSX.mjs → chunk-OUSWVNWT.mjs} +1 -1
  15. package/dist/{chunk-HR5CWTLC.mjs → chunk-P2VJYRVY.mjs} +60 -7
  16. package/dist/{chunk-UC3SCMIN.mjs → chunk-PBRXXISQ.mjs} +3 -0
  17. package/dist/{chunk-JU64Y7HM.mjs → chunk-SBL6GN43.mjs} +1 -1
  18. package/dist/{chunk-EBJXPQQO.mjs → chunk-UPKKSUPA.mjs} +2 -2
  19. package/dist/{chunk-TJF5GZSV.mjs → chunk-VOSJBZ6Q.mjs} +1 -1
  20. package/dist/{chunk-PIKHN33N.mjs → chunk-VOYGMAU7.mjs} +9 -1
  21. package/dist/{chunk-H237TXZW.mjs → chunk-WJ67DTD6.mjs} +48 -6
  22. package/dist/{chunk-OQVZBEBY.mjs → chunk-XF2HH5E6.mjs} +4 -61
  23. package/dist/client/index.d.ts +211 -12
  24. package/dist/client/index.mjs +155 -67
  25. package/dist/client/topology.d.ts +55 -7
  26. package/dist/client/topology.mjs +20 -1
  27. package/dist/{client-base-CLWmH5Ln.d.ts → client-base-CmZO0v3m.d.ts} +133 -24
  28. package/dist/codegen/cli.mjs +3 -3
  29. package/dist/codegen/index.d.ts +92 -2
  30. package/dist/codegen/index.mjs +3 -3
  31. package/dist/core/index.d.ts +177 -15
  32. package/dist/core/index.mjs +2481 -2226
  33. package/dist/core/writer-worker.mjs +3 -3
  34. package/dist/database-B5Qv1-cU.d.ts +380 -0
  35. package/dist/driver/better-sqlite3.d.ts +18 -1
  36. package/dist/driver/better-sqlite3.mjs +5 -5
  37. package/dist/driver/bun.d.ts +28 -0
  38. package/dist/driver/expo.d.ts +17 -0
  39. package/dist/driver/node.d.ts +18 -1
  40. package/dist/driver/node.mjs +5 -5
  41. package/dist/driver/wa-sqlite.d.ts +18 -1
  42. package/dist/{errors-Bw5MdNCu.d.ts → errors-Dei4GdBb.d.ts} +80 -7
  43. package/dist/file-migrations/index.d.ts +54 -2
  44. package/dist/file-migrations/index.mjs +3 -3
  45. package/dist/{operation-registry-9DcvxcE5.d.ts → operation-registry-hlbhqu7q.d.ts} +50 -1
  46. package/dist/{primary-wins-DPAm2AKG.d.ts → primary-wins-B0np8JS3.d.ts} +25 -1
  47. package/dist/protocol-rqANt-9Q.d.ts +152 -0
  48. package/dist/query-types-DL3LtPvY.d.ts +95 -0
  49. package/dist/react/index.d.ts +58 -3
  50. package/dist/replication/coordinator/etcd.d.ts +63 -3
  51. package/dist/replication/coordinator/etcd.mjs +82 -46
  52. package/dist/replication/index.d.ts +329 -95
  53. package/dist/replication/index.mjs +256 -141
  54. package/dist/server/index.d.ts +230 -12
  55. package/dist/server/index.mjs +63 -50
  56. package/dist/{server-options-1JHu8pid.d.ts → server-options-Dab_Jvd_.d.ts} +96 -12
  57. package/dist/sirannon-CMhiJa5Y.d.ts +111 -0
  58. package/dist/transport/grpc.d.ts +93 -9
  59. package/dist/transport/grpc.mjs +63 -20
  60. package/dist/transport/memory.d.ts +50 -20
  61. package/dist/transport/memory.mjs +25 -0
  62. package/dist/{types-CL6piSnD.d.ts → types-BCejqzNA.d.ts} +20 -0
  63. package/dist/types-CMBcFPhb.d.ts +336 -0
  64. package/dist/types-CjhxcjhA.d.ts +123 -0
  65. package/dist/types-DyrCiWuc.d.ts +499 -0
  66. package/dist/types-rVZKnKN-.d.ts +591 -0
  67. package/package.json +7 -1
  68. package/dist/baseline-Br77Fnhb.d.ts +0 -6
  69. package/dist/database-BY0L5Q2n.d.ts +0 -172
  70. package/dist/protocol-6KrSq2Hy.d.ts +0 -66
  71. package/dist/sirannon-DaQSyhbJ.d.ts +0 -36
  72. package/dist/types-B7gmEsZW.d.ts +0 -221
  73. package/dist/types-BsVabqSI.d.ts +0 -139
  74. package/dist/types-C_D8IhpO.d.ts +0 -60
  75. package/dist/types-zhnRXrsb.d.ts +0 -384
@@ -1,6 +1,7 @@
1
- import { a as OperationRegistry } from './operation-registry-9DcvxcE5.js';
2
- import { R as ReplicationBatch, C as ConflictResolver, A as ApplyResult } from './types-C_D8IhpO.js';
3
- import { N as NodeHealth, P as Params, Q as QueryOptions, E as ExecuteResult, T as Transaction, C as ClusterStatusInfo } from './types-zhnRXrsb.js';
1
+ import { a as OperationRegistry } from './operation-registry-hlbhqu7q.js';
2
+ import { R as ReplicationBatch, C as ConflictResolver, A as ApplyResult } from './types-CjhxcjhA.js';
3
+ import { N as NodeHealth, T as Transaction, C as ClusterStatusInfo } from './types-rVZKnKN-.js';
4
+ import { P as Params, Q as QueryOptions, E as ExecuteResult } from './query-types-DL3LtPvY.js';
4
5
 
5
6
  interface AppliedMigrationRow {
6
7
  version: number;
@@ -8,15 +9,32 @@ interface AppliedMigrationRow {
8
9
  checksum: string | null;
9
10
  }
10
11
 
11
- /** Context passed to the authenticate hook. */
12
+ /** Context passed to the authenticate hook.
13
+ * @public
14
+ */
12
15
  interface RequestContext {
16
+ /** Request headers, with every name lower-cased. */
13
17
  headers: Record<string, string>;
18
+ /** HTTP method of the request, or the method of a WebSocket upgrade. */
14
19
  method: string;
20
+ /** Path the request arrived on. */
15
21
  path: string;
22
+ /** Identifier of the database the route addresses. */
16
23
  databaseId?: string;
24
+ /** Address the request came from. */
17
25
  remoteAddress: string;
18
26
  }
27
+ /**
28
+ * Identifies the caller behind a request. Return the identity registered
29
+ * operations then read, and throw a {@link RequestDeniedError} to refuse the
30
+ * request with a status of your own.
31
+ *
32
+ * @public
33
+ */
19
34
  type AuthenticateHook<Identity = unknown> = (ctx: RequestContext) => Identity | undefined | Promise<Identity | undefined>;
35
+ /** Reports whether a caller may read the addresses of every node in the group.
36
+ * @public
37
+ */
20
38
  type ClusterStatusAuthorizer = (ctx: RequestContext) => boolean | Promise<boolean>;
21
39
  /**
22
40
  * Durability level in force while a bulk load runs. SQLite sanctions 'off' for
@@ -24,8 +42,13 @@ type ClusterStatusAuthorizer = (ctx: RequestContext) => boolean | Promise<boolea
24
42
  * gives up corruption safety, so it fits only a load that starts from nothing.
25
43
  * 'normal' keeps WAL-mode corruption safety and suits loads into a database
26
44
  * that already holds data the operator cannot afford to lose.
45
+ *
46
+ * @public
27
47
  */
28
48
  type BulkLoadDurability = 'off' | 'normal';
49
+ /** Settings for one bulk load.
50
+ * @public
51
+ */
29
52
  interface BulkLoadOptions {
30
53
  /** Durability during the load. Default: 'off'. */
31
54
  durability?: BulkLoadDurability;
@@ -39,28 +62,41 @@ interface BulkLoadOptions {
39
62
  checkpoint?: boolean;
40
63
  }
41
64
  /** Aggregate outcome of a bulk load. Summed rather than per-row so a
42
- * million-row load never holds a million result objects in memory. */
65
+ * million-row load never holds a million result objects in memory.
66
+ * @public
67
+ */
43
68
  interface BulkLoadResult {
69
+ /** Number of parameter sets the load applied. */
44
70
  rowsLoaded: number;
71
+ /** Number of rows the load inserted, updated, or deleted. */
45
72
  changes: number;
46
73
  }
74
+ /**
75
+ * What the server runs statements against for one database. A local
76
+ * `Database` satisfies it, and so does a proxy that forwards to another node.
77
+ *
78
+ * @public
79
+ */
47
80
  interface ServerExecutionTarget {
81
+ /** Runs a read and returns the rows. */
48
82
  query<T = Record<string, unknown>>(sql: string, params?: Params, options?: QueryOptions): Promise<T[]>;
49
83
  /**
50
84
  * Optional single-pass read that returns rows already encoded for the wire
51
85
  * (safe-range integers as plain numbers, larger integers and BLOBs as tagged
52
- * envelopes). When present the server uses it instead of {@link query}
86
+ * envelopes). When present the server uses it instead of {@link ServerExecutionTarget.query}
53
87
  * followed by a separate tag-encoding walk. A target that omits it stays
54
- * correct: the server falls back to encoding {@link query} rows itself.
88
+ * correct: the server falls back to encoding {@link ServerExecutionTarget.query} rows itself.
55
89
  */
56
90
  queryForWire?(sql: string, params?: Params, options?: QueryOptions): Promise<unknown[]>;
91
+ /** Runs one write and returns the change count and last inserted row id. */
57
92
  execute(sql: string, params?: Params, options?: QueryOptions): Promise<ExecuteResult>;
93
+ /** Runs a function inside one transaction. */
58
94
  transaction<T>(fn: (tx: Transaction) => Promise<T>, options?: QueryOptions): Promise<T>;
59
95
  /**
60
96
  * Optional entry point for a transaction whose statements are all known
61
97
  * before it starts, which lets concurrent transactions share one commit. A
62
98
  * target that omits it stays correct: the server falls back to
63
- * {@link transaction} and runs the statements one at a time.
99
+ * {@link ServerExecutionTarget.transaction} and runs the statements one at a time.
64
100
  */
65
101
  executeTransaction?(statements: readonly {
66
102
  sql: string;
@@ -72,14 +108,26 @@ interface ServerExecutionTarget {
72
108
  * of silently degrading to per-statement writes.
73
109
  */
74
110
  bulkLoad?(sql: string, paramsBatch: Params[], options?: BulkLoadOptions): Promise<BulkLoadResult>;
111
+ /** Optional device-sync entry point that applies a batch of changes a device pushed. */
75
112
  applyChanges?(batch: ReplicationBatch, resolver?: ConflictResolver | ((table: string) => ConflictResolver)): Promise<ApplyResult>;
113
+ /** Optional listing of the migrations this database has applied. */
76
114
  appliedMigrations?(): Promise<AppliedMigrationRow[]>;
77
115
  }
116
+ /**
117
+ * Finds what the server should run a database's statements against.
118
+ *
119
+ * @public
120
+ */
78
121
  type ServerExecutionTargetResolver = (databaseId: string) => ServerExecutionTarget | null | undefined | Promise<ServerExecutionTarget | null | undefined>;
79
- /** Options for the standalone HTTP + WS server. */
122
+ /** Options for the standalone HTTP + WS server.
123
+ * @public
124
+ */
80
125
  interface ServerOptions<Identity = unknown> {
126
+ /** Address the server binds to. Default: '0.0.0.0'. */
81
127
  host?: string;
128
+ /** Port the server binds to. Default: 3000. */
82
129
  port?: number;
130
+ /** Cross-origin rules the server answers browser requests with. */
83
131
  cors?: boolean | CorsOptions;
84
132
  /**
85
133
  * Maximum HTTP request body and WebSocket message size in bytes. Applied
@@ -107,43 +155,77 @@ interface ServerOptions<Identity = unknown> {
107
155
  * (one hour).
108
156
  */
109
157
  cdcRetentionMs?: number;
158
+ /** How long, in milliseconds, a device's sync cursor is kept after its last contact. */
110
159
  deviceCursorRetentionMs?: number;
160
+ /** Changes a device may leave unacknowledged before the server stops sending more. */
111
161
  maxUnacknowledgedChanges?: number;
162
+ /** Runs before every database route and every WebSocket upgrade, and names the caller. */
112
163
  authenticate?: AuthenticateHook<Identity>;
164
+ /** Statements callers may invoke by name. Without these, only SQL routes serve reads and writes. */
113
165
  operations?: OperationRegistry<Identity>;
166
+ /** Opens the five statement routes and their WebSocket messages. Default: false. */
114
167
  acceptSql?: boolean;
168
+ /** Finds what the server runs a database's statements against. */
115
169
  resolveExecutionTarget?: ServerExecutionTargetResolver;
170
+ /** Supplies the replication figures the readiness endpoint reports. */
116
171
  getReplicationStatus?: () => ReplicationStatusInfo | null;
172
+ /** Supplies what `GET /db/{id}/cluster` reports for one database. */
117
173
  getClusterStatus?: (databaseId: string) => ClusterStatusInfo | null;
174
+ /** Reports whether a caller may read the addresses of every node in the group. */
118
175
  authorizeClusterStatus?: ClusterStatusAuthorizer;
119
176
  }
177
+ /** Replication figures one node reports through its readiness endpoint.
178
+ * @public
179
+ */
120
180
  interface ReplicationStatusInfo {
181
+ /** Whether this node accepts writes or serves reads. */
121
182
  role: string;
183
+ /** Whether this node forwards writes to the primary. */
122
184
  writeForwarding: boolean;
185
+ /** Number of peers the node is connected to. */
123
186
  peers: number;
187
+ /** Highest change-log position this node has recorded locally. */
124
188
  localSeq: bigint;
189
+ /** What the node can do right now, and the condition behind it. */
125
190
  health: NodeHealth;
191
+ /** Identifier of the replication group the node belongs to. */
126
192
  replicationGroupId?: string;
193
+ /** The primary term this node reports as current. */
127
194
  primaryTerm?: bigint;
195
+ /** Identifier of the primary this node reports as current. */
128
196
  currentPrimary?: string;
197
+ /** Whether the node reaches its cluster coordinator, and whether it holds write authority. */
129
198
  coordinator?: {
130
199
  connected: boolean;
131
200
  authority: boolean;
132
201
  };
202
+ /** Whether this node runs the group's controller loop. */
133
203
  controller?: {
134
204
  state: 'disabled' | 'standby' | 'active' | 'lost';
135
205
  };
206
+ /** Identifiers of the replicas the group counts as in sync. */
136
207
  inSyncReplicas?: string[];
208
+ /** Identifiers of the replicas that have fallen behind. */
137
209
  laggingReplicas?: string[];
210
+ /** Where this node stands in first sync. */
138
211
  syncState?: string;
139
212
  }
140
- /** CORS configuration. */
213
+ /** CORS configuration.
214
+ * @public
215
+ */
141
216
  interface CorsOptions {
217
+ /** Origins the server allows. */
142
218
  origin?: string | string[];
219
+ /** Methods the server allows. */
143
220
  methods?: string[];
221
+ /** Request headers the server allows. */
144
222
  headers?: string[];
145
223
  }
146
- /** Options for the mountable WebSocket handler. */
224
+ /**
225
+ * Options for the mountable WebSocket handler.
226
+ *
227
+ * @internal
228
+ */
147
229
  interface WSHandlerOptions<Identity = unknown> {
148
230
  /** Maximum message size in bytes. Default: 1_048_576 (1 MB). */
149
231
  maxPayloadLength?: number;
@@ -155,7 +237,9 @@ interface WSHandlerOptions<Identity = unknown> {
155
237
  operations?: OperationRegistry<Identity>;
156
238
  resolveExecutionTarget?: ServerExecutionTargetResolver;
157
239
  }
158
- /** Options for the client SDK. */
240
+ /** Options for the client SDK.
241
+ * @public
242
+ */
159
243
  interface ClientOptions {
160
244
  /** Transport to use. Default: 'websocket'. */
161
245
  transport?: 'websocket' | 'http';
@@ -0,0 +1,111 @@
1
+ import { D as Database } from './database-B5Qv1-cU.js';
2
+ import { S as SirannonOptions, a as SQLiteDriver, D as DatabaseOptions, M as Migration, B as BeforeQueryHook, A as AfterQueryHook, b as BeforeConnectHook, c as DatabaseOpenHook, d as DatabaseCloseHook } from './types-rVZKnKN-.js';
3
+
4
+ /**
5
+ * A registry of open SQLite databases, keyed by identifier.
6
+ *
7
+ * It opens each database through one driver, applies shared hooks, metrics, and migrations, and closes idle databases when you configure a lifecycle.
8
+ *
9
+ * @public
10
+ */
11
+ declare class Sirannon {
12
+ private readonly dbs;
13
+ private readonly opening;
14
+ private readonly resolving;
15
+ private migrationSet;
16
+ private _shutdown;
17
+ private readonly _driver;
18
+ private readonly hookRegistry;
19
+ private readonly metricsCollector;
20
+ private readonly lifecycleManager;
21
+ /** The driver, hooks, metrics, lifecycle, migrations, and writer-worker default this registry was built with. */
22
+ readonly options: SirannonOptions;
23
+ /**
24
+ * Builds a registry.
25
+ *
26
+ * @param options - Driver, hooks, metrics, lifecycle, migrations, and the writer-worker default.
27
+ */
28
+ constructor(options: SirannonOptions);
29
+ /** @internal */
30
+ get driver(): SQLiteDriver;
31
+ /**
32
+ * Opens a database and registers it under an identifier.
33
+ *
34
+ * @param id - Identifier callers reach this database by.
35
+ * @param path - File path of the SQLite database.
36
+ * @param options - Pool size, journal mode, durability, and change-capture settings.
37
+ * @returns The open database.
38
+ * @throws When the identifier is already registered.
39
+ */
40
+ open(id: string, path: string, options?: DatabaseOptions): Promise<Database>;
41
+ private withRegistryDefaults;
42
+ /**
43
+ * Closes one database and removes it from the registry.
44
+ *
45
+ * @param id - Identifier of the database to close.
46
+ */
47
+ close(id: string): Promise<void>;
48
+ /**
49
+ * Returns an already-open database.
50
+ *
51
+ * @param id - Identifier of the database.
52
+ * @returns The database, or undefined when none is open under that identifier.
53
+ */
54
+ get(id: string): Database | undefined;
55
+ /** @internal */
56
+ resolve(id: string): Promise<Database | undefined>;
57
+ /** @internal */
58
+ registryMigrations(): Promise<Migration[]>;
59
+ private applyRegistryMigrations;
60
+ private loadMigrationSet;
61
+ /**
62
+ * Reports whether a database is open under an identifier.
63
+ *
64
+ * @param id - Identifier to check.
65
+ * @returns True when the registry holds an open database under it.
66
+ */
67
+ has(id: string): boolean;
68
+ /**
69
+ * Returns every database this registry currently holds open.
70
+ *
71
+ * @returns The open databases, keyed by identifier.
72
+ */
73
+ databases(): Map<string, Database>;
74
+ /**
75
+ * Closes every open database and stops the lifecycle timers.
76
+ */
77
+ shutdown(): Promise<void>;
78
+ /**
79
+ * Registers a hook that runs before each statement on every database in this registry. Throw from it to refuse the statement.
80
+ *
81
+ * @param hook - Receives the statement, its parameters, and the concerns it carries.
82
+ */
83
+ onBeforeQuery(hook: BeforeQueryHook): void;
84
+ /**
85
+ * Registers a hook that runs after each statement on every database in this registry.
86
+ *
87
+ * @param hook - Receives the statement and how long it took.
88
+ */
89
+ onAfterQuery(hook: AfterQueryHook): void;
90
+ /**
91
+ * Registers a hook that runs before a database connection opens.
92
+ *
93
+ * @param hook - Receives the database identifier and its file path.
94
+ */
95
+ onBeforeConnect(hook: BeforeConnectHook): void;
96
+ /**
97
+ * Registers a hook that runs once a database is open.
98
+ *
99
+ * @param hook - Receives the database identifier and its file path.
100
+ */
101
+ onDatabaseOpen(hook: DatabaseOpenHook): void;
102
+ /**
103
+ * Registers a hook that runs once a database is closed.
104
+ *
105
+ * @param hook - Receives the database identifier and its file path.
106
+ */
107
+ onDatabaseClose(hook: DatabaseCloseHook): void;
108
+ private ensureRunning;
109
+ }
110
+
111
+ export { Sirannon as S };
@@ -1,11 +1,12 @@
1
1
  import { BinaryWriter, BinaryReader } from '@bufbuild/protobuf/wire';
2
2
  import { Client, ClientDuplexStream, CallOptions, Metadata, ServiceError, ClientUnaryCall, ChannelCredentials, ClientOptions, ServerDuplexStream, Server } from '@grpc/grpc-js';
3
3
  import { HealthImplementation } from 'grpc-health-check';
4
- import { R as ReplicationAck, F as ForwardedTransaction, a as ForwardedTransactionResult, N as NodeInfo, S as SyncRequest, b as SyncBatch, c as SyncComplete, d as SyncAck, e as ReplicationTransport, f as TopologyRole, T as TransportConfig } from '../types-B7gmEsZW.js';
5
- import { R as ReplicationBatch } from '../types-C_D8IhpO.js';
6
- import '../change-tracker-DKRVUC3l.js';
7
- import '../types-zhnRXrsb.js';
8
- import '../types-BsVabqSI.js';
4
+ import { R as ReplicationAck, F as ForwardedTransaction, a as ForwardedTransactionResult, N as NodeInfo, S as SyncRequest, b as SyncBatch, c as SyncComplete, d as SyncAck, e as ReplicationTransport, f as TopologyRole, T as TransportConfig } from '../types-DyrCiWuc.js';
5
+ import { R as ReplicationBatch } from '../types-CjhxcjhA.js';
6
+ import '../change-tracker-DDmXB754.js';
7
+ import '../types-rVZKnKN-.js';
8
+ import '../query-types-DL3LtPvY.js';
9
+ import '../types-CMBcFPhb.js';
9
10
 
10
11
  interface ColumnValue {
11
12
  nullValue?: boolean | undefined;
@@ -223,16 +224,52 @@ interface MessageFns<T> {
223
224
  fromPartial<I extends Exact<DeepPartial<T>, I>>(object: I): T;
224
225
  }
225
226
 
227
+ /**
228
+ * Encodes one SQLite value into the gRPC column representation.
229
+ *
230
+ * @internal
231
+ */
226
232
  declare function toColumnValue(value: unknown): ColumnValue;
233
+ /**
234
+ * Decodes one gRPC column value back into a SQLite value.
235
+ *
236
+ * @internal
237
+ */
227
238
  declare function fromColumnValue(cv: ColumnValue): unknown;
228
239
 
240
+ /**
241
+ * @public
242
+ *
243
+ * Where the gRPC transport listens, and the certificates it presents and trusts.
244
+ */
229
245
  interface GrpcReplicationOptions {
246
+ /**
247
+ * Address the gRPC server binds to. Default: '0.0.0.0'.
248
+ */
230
249
  host?: string;
250
+ /**
251
+ * Port the gRPC server binds to. Pass 0 to take any free port.
252
+ */
231
253
  port?: number;
254
+ /**
255
+ * Path to this node's certificate.
256
+ */
232
257
  tlsCert?: string;
258
+ /**
259
+ * Path to this node's private key.
260
+ */
233
261
  tlsKey?: string;
262
+ /**
263
+ * Path to the authority certificate this node verifies its peers against.
264
+ */
234
265
  tlsCaCert?: string;
266
+ /**
267
+ * Runs without TLS, which suits tests only.
268
+ */
235
269
  insecure?: boolean;
270
+ /**
271
+ * Milliseconds a forwarded write may take before the replica gives up. Default: 30000.
272
+ */
236
273
  forwardDeadlineMs?: number;
237
274
  }
238
275
 
@@ -255,62 +292,109 @@ type SyncBatchHandler = (batch: SyncBatch, fromPeerId: string) => Promise<void>;
255
292
  type SyncCompleteHandler = (complete: SyncComplete, fromPeerId: string) => Promise<void>;
256
293
  type SyncAckHandler = (ack: SyncAck, fromPeerId: string) => void;
257
294
 
295
+ /**
296
+ * @public
297
+ *
298
+ * Replicates between nodes over gRPC with mutual TLS, which is the transport production clusters use.
299
+ */
258
300
  declare class GrpcReplicationTransport implements ReplicationTransport {
301
+ /** @internal */
259
302
  readonly options: GrpcReplicationOptions;
303
+ /** @internal */
260
304
  localNodeId: string;
305
+ /** @internal */
261
306
  localRole: TopologyRole;
307
+ /** @internal */
262
308
  localGroupId: string | undefined;
309
+ /** @internal */
263
310
  localPrimaryTerm: bigint | undefined;
311
+ /** @internal */
264
312
  localProtocolVersion: string | undefined;
313
+ /** @internal */
265
314
  connected: boolean;
315
+ /** @internal */
266
316
  server: Server | null;
317
+ /** @internal */
267
318
  boundPort: number;
319
+ /** @internal */
268
320
  healthImpl: HealthImplementation | null;
321
+ /** @internal */
269
322
  readonly connectedPeers: Map<string, NodeInfo>;
323
+ /** @internal */
270
324
  readonly serverPeerStreams: Map<string, PeerStreamEntry>;
325
+ /** @internal */
271
326
  readonly clientPeerStreams: Map<string, ClientPeerEntry>;
327
+ /** @internal */
272
328
  batchHandler: BatchHandler | null;
329
+ /** @internal */
273
330
  ackHandler: AckHandler | null;
331
+ /** @internal */
274
332
  forwardHandler: ForwardHandler | null;
333
+ /** @internal */
275
334
  peerConnectedHandler: PeerConnectedHandler | null;
335
+ /** @internal */
276
336
  peerDisconnectedHandler: PeerDisconnectedHandler | null;
337
+ /** @internal */
277
338
  syncRequestHandler: SyncRequestHandler | null;
339
+ /** @internal */
278
340
  syncBatchHandler: SyncBatchHandler | null;
341
+ /** @internal */
279
342
  syncCompleteHandler: SyncCompleteHandler | null;
343
+ /** @internal */
280
344
  syncAckHandler: SyncAckHandler | null;
281
345
  constructor(options?: GrpcReplicationOptions);
346
+ /** Returns the port the gRPC server bound to, which is the resolved port when you asked for 0. */
282
347
  getPort(): number;
348
+ /** Connects to the configured peers and announces this node. */
283
349
  connect(localNodeId: string, config: TransportConfig): Promise<void>;
350
+ /** Closes every peer connection. */
284
351
  disconnect(): Promise<void>;
352
+ /** Sends one batch of changes to one peer. */
285
353
  send(peerId: string, batch: ReplicationBatch): Promise<void>;
354
+ /** Sends one batch of changes to every connected peer. */
286
355
  broadcast(batch: ReplicationBatch): Promise<void>;
356
+ /** Confirms to a peer that this node applied one of its batches. */
287
357
  sendAck(peerId: string, ack: ReplicationAck): Promise<void>;
358
+ /** Sends a write to the primary and waits for its result. */
288
359
  forward(peerId: string, request: ForwardedTransaction): Promise<ForwardedTransactionResult>;
360
+ /** Asks a peer to stream a full copy of the database. */
289
361
  requestSync(peerId: string, request: SyncRequest): Promise<void>;
362
+ /** Sends one page of first-sync table data. */
290
363
  sendSyncBatch(peerId: string, batch: SyncBatch): Promise<void>;
364
+ /** Tells a joining node that first sync has finished, and sends the manifests to verify it. */
291
365
  sendSyncComplete(peerId: string, complete: SyncComplete): Promise<void>;
366
+ /** Confirms to the source that a joining node stored one first-sync page. */
292
367
  sendSyncAck(peerId: string, ack: SyncAck): Promise<void>;
368
+ /** Registers the handler that applies incoming change batches. */
293
369
  onBatchReceived(handler: BatchHandler): void;
370
+ /** Registers the handler that records incoming acknowledgements. */
294
371
  onAckReceived(handler: AckHandler): void;
372
+ /** Registers the handler that runs a write a replica forwarded. */
295
373
  onForwardReceived(handler: ForwardHandler): void;
374
+ /** Registers the handler that serves a first-sync request. */
296
375
  onSyncRequested(handler: SyncRequestHandler): void;
376
+ /** Registers the handler that stores an incoming first-sync page. */
297
377
  onSyncBatchReceived(handler: SyncBatchHandler): void;
378
+ /** Registers the handler that finishes first sync and verifies the manifests. */
298
379
  onSyncCompleteReceived(handler: SyncCompleteHandler): void;
380
+ /** Registers the handler that records first-sync page acknowledgements. */
299
381
  onSyncAckReceived(handler: SyncAckHandler): void;
382
+ /** Registers the handler that runs when a peer connects. */
300
383
  onPeerConnected(handler: PeerConnectedHandler): void;
384
+ /** Registers the handler that runs when a peer disconnects. */
301
385
  onPeerDisconnected(handler: PeerDisconnectedHandler): void;
386
+ /** Returns every connected peer, keyed by identifier. */
302
387
  peers(): ReadonlyMap<string, NodeInfo>;
303
- extractTlsCN(call: {
304
- getAuthContext(): unknown;
305
- }): string | null;
388
+ private extractTlsCN;
389
+ /** @internal */
306
390
  validateTlsIdentity(call: {
307
391
  getAuthContext(): unknown;
308
392
  }, claimedNodeId: string): boolean;
393
+ /** @internal */
309
394
  resolveForwardPeerId(call: {
310
395
  getPeer(): string;
311
396
  getAuthContext(): unknown;
312
397
  }): string | null;
313
- private findPeerIdForStream;
314
398
  private ensureConnected;
315
399
  private getReplicateWriteStream;
316
400
  private getSyncWriteStream;