@delali/sirannon-db 0.1.4 → 0.1.5

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.
@@ -0,0 +1,316 @@
1
+ import { BinaryWriter, BinaryReader } from '@bufbuild/protobuf/wire';
2
+ import { Client, ClientDuplexStream, CallOptions, Metadata, ServiceError, ClientUnaryCall, ChannelCredentials, ClientOptions, ServerDuplexStream, Server } from '@grpc/grpc-js';
3
+ import { HealthImplementation } from 'grpc-health-check';
4
+ import { R as ReplicationBatch, a as ReplicationAck, F as ForwardedTransaction, b as ForwardedTransactionResult, N as NodeInfo, S as SyncRequest, c as SyncBatch, d as SyncComplete, e as SyncAck, f as ReplicationTransport, T as TopologyRole, g as TransportConfig } from '../types-B2byqt0B.js';
5
+ import '../change-tracker-CFTQ9TSn.js';
6
+ import '../types-BFSsG77t.js';
7
+ import '../types-D-74JiXb.js';
8
+ import '../types-BEu1I_9_.js';
9
+
10
+ interface ColumnValue {
11
+ nullValue?: boolean | undefined;
12
+ stringValue?: string | undefined;
13
+ intValue?: bigint | undefined;
14
+ floatValue?: number | undefined;
15
+ blobValue?: Buffer | undefined;
16
+ boolValue?: boolean | undefined;
17
+ }
18
+ declare const ColumnValue: MessageFns<ColumnValue>;
19
+ interface RowData {
20
+ fields: {
21
+ [key: string]: ColumnValue;
22
+ };
23
+ }
24
+ declare const RowData: MessageFns<RowData>;
25
+ interface HlcRange {
26
+ min: string;
27
+ max: string;
28
+ }
29
+ declare const HlcRange: MessageFns<HlcRange>;
30
+ interface ReplicationChange {
31
+ table: string;
32
+ operation: string;
33
+ rowId: string;
34
+ primaryKey: RowData | undefined;
35
+ hlc: string;
36
+ txId: string;
37
+ nodeId: string;
38
+ newData: RowData | undefined;
39
+ oldData: RowData | undefined;
40
+ ddlStatement: string;
41
+ }
42
+ declare const ReplicationChange: MessageFns<ReplicationChange>;
43
+ interface BatchPayload {
44
+ sourceNodeId: string;
45
+ batchId: string;
46
+ fromSeq: bigint;
47
+ toSeq: bigint;
48
+ hlcRange: HlcRange | undefined;
49
+ changes: ReplicationChange[];
50
+ checksum: string;
51
+ groupId: string;
52
+ primaryTerm: bigint;
53
+ }
54
+ declare const BatchPayload: MessageFns<BatchPayload>;
55
+ interface AckPayload {
56
+ batchId: string;
57
+ ackedSeq: bigint;
58
+ nodeId: string;
59
+ groupId: string;
60
+ primaryTerm: bigint;
61
+ }
62
+ declare const AckPayload: MessageFns<AckPayload>;
63
+ interface Hello {
64
+ nodeId: string;
65
+ role: string;
66
+ groupId: string;
67
+ primaryTerm: bigint;
68
+ protocolVersion: string;
69
+ }
70
+ declare const Hello: MessageFns<Hello>;
71
+ interface ReplicationMessage {
72
+ hello?: Hello | undefined;
73
+ batch?: BatchPayload | undefined;
74
+ ack?: AckPayload | undefined;
75
+ }
76
+ declare const ReplicationMessage: MessageFns<ReplicationMessage>;
77
+ interface SyncRequestPayload {
78
+ requestId: string;
79
+ joinerNodeId: string;
80
+ completedTables: string[];
81
+ groupId: string;
82
+ primaryTerm: bigint;
83
+ }
84
+ declare const SyncRequestPayload: MessageFns<SyncRequestPayload>;
85
+ interface SyncBatchPayload {
86
+ requestId: string;
87
+ table: string;
88
+ batchIndex: number;
89
+ rows: RowData[];
90
+ schema: string[];
91
+ checksum: string;
92
+ isLastBatchForTable: boolean;
93
+ groupId: string;
94
+ primaryTerm: bigint;
95
+ }
96
+ declare const SyncBatchPayload: MessageFns<SyncBatchPayload>;
97
+ interface SyncCompletePayload {
98
+ requestId: string;
99
+ snapshotSeq: bigint;
100
+ manifests: SyncTableManifest[];
101
+ groupId: string;
102
+ primaryTerm: bigint;
103
+ }
104
+ declare const SyncCompletePayload: MessageFns<SyncCompletePayload>;
105
+ interface SyncTableManifest {
106
+ table: string;
107
+ rowCount: number;
108
+ pkHash: string;
109
+ }
110
+ declare const SyncTableManifest: MessageFns<SyncTableManifest>;
111
+ interface SyncAckPayload {
112
+ requestId: string;
113
+ joinerNodeId: string;
114
+ table: string;
115
+ batchIndex: number;
116
+ success: boolean;
117
+ error: string;
118
+ groupId: string;
119
+ primaryTerm: bigint;
120
+ }
121
+ declare const SyncAckPayload: MessageFns<SyncAckPayload>;
122
+ interface SyncMessage {
123
+ hello?: Hello | undefined;
124
+ syncRequest?: SyncRequestPayload | undefined;
125
+ syncBatch?: SyncBatchPayload | undefined;
126
+ syncComplete?: SyncCompletePayload | undefined;
127
+ syncAck?: SyncAckPayload | undefined;
128
+ }
129
+ declare const SyncMessage: MessageFns<SyncMessage>;
130
+ interface Statement {
131
+ sql: string;
132
+ namedParams: {
133
+ [key: string]: ColumnValue;
134
+ };
135
+ positionalParams: ColumnValue[];
136
+ }
137
+ declare const Statement: MessageFns<Statement>;
138
+ interface ForwardRequest {
139
+ requestId: string;
140
+ statements: Statement[];
141
+ groupId: string;
142
+ primaryTerm: bigint;
143
+ }
144
+ declare const ForwardRequest: MessageFns<ForwardRequest>;
145
+ interface StatementResult {
146
+ changes: number;
147
+ lastInsertRowId: bigint;
148
+ }
149
+ declare const StatementResult: MessageFns<StatementResult>;
150
+ interface ForwardResponse {
151
+ requestId: string;
152
+ results: StatementResult[];
153
+ error: string;
154
+ groupId: string;
155
+ primaryTerm: bigint;
156
+ }
157
+ declare const ForwardResponse: MessageFns<ForwardResponse>;
158
+ type ReplicationService = typeof ReplicationService;
159
+ declare const ReplicationService: {
160
+ readonly replicate: {
161
+ readonly path: "/sirannon.replication.v1.Replication/Replicate";
162
+ readonly requestStream: true;
163
+ readonly responseStream: true;
164
+ readonly requestSerialize: (value: ReplicationMessage) => Buffer;
165
+ readonly requestDeserialize: (value: Buffer) => ReplicationMessage;
166
+ readonly responseSerialize: (value: ReplicationMessage) => Buffer;
167
+ readonly responseDeserialize: (value: Buffer) => ReplicationMessage;
168
+ };
169
+ readonly sync: {
170
+ readonly path: "/sirannon.replication.v1.Replication/Sync";
171
+ readonly requestStream: true;
172
+ readonly responseStream: true;
173
+ readonly requestSerialize: (value: SyncMessage) => Buffer;
174
+ readonly requestDeserialize: (value: Buffer) => SyncMessage;
175
+ readonly responseSerialize: (value: SyncMessage) => Buffer;
176
+ readonly responseDeserialize: (value: Buffer) => SyncMessage;
177
+ };
178
+ readonly forward: {
179
+ readonly path: "/sirannon.replication.v1.Replication/Forward";
180
+ readonly requestStream: false;
181
+ readonly responseStream: false;
182
+ readonly requestSerialize: (value: ForwardRequest) => Buffer;
183
+ readonly requestDeserialize: (value: Buffer) => ForwardRequest;
184
+ readonly responseSerialize: (value: ForwardResponse) => Buffer;
185
+ readonly responseDeserialize: (value: Buffer) => ForwardResponse;
186
+ };
187
+ };
188
+ interface ReplicationClient extends Client {
189
+ replicate(): ClientDuplexStream<ReplicationMessage, ReplicationMessage>;
190
+ replicate(options: Partial<CallOptions>): ClientDuplexStream<ReplicationMessage, ReplicationMessage>;
191
+ replicate(metadata: Metadata, options?: Partial<CallOptions>): ClientDuplexStream<ReplicationMessage, ReplicationMessage>;
192
+ sync(): ClientDuplexStream<SyncMessage, SyncMessage>;
193
+ sync(options: Partial<CallOptions>): ClientDuplexStream<SyncMessage, SyncMessage>;
194
+ sync(metadata: Metadata, options?: Partial<CallOptions>): ClientDuplexStream<SyncMessage, SyncMessage>;
195
+ forward(request: ForwardRequest, callback: (error: ServiceError | null, response: ForwardResponse) => void): ClientUnaryCall;
196
+ forward(request: ForwardRequest, metadata: Metadata, callback: (error: ServiceError | null, response: ForwardResponse) => void): ClientUnaryCall;
197
+ forward(request: ForwardRequest, metadata: Metadata, options: Partial<CallOptions>, callback: (error: ServiceError | null, response: ForwardResponse) => void): ClientUnaryCall;
198
+ }
199
+ declare const ReplicationClient: {
200
+ new (address: string, credentials: ChannelCredentials, options?: Partial<ClientOptions>): ReplicationClient;
201
+ service: typeof ReplicationService;
202
+ serviceName: string;
203
+ };
204
+ type Builtin = Date | Function | Uint8Array | string | number | boolean | bigint | undefined;
205
+ type DeepPartial<T> = T extends Builtin ? T : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {} ? {
206
+ [K in keyof T]?: DeepPartial<T[K]>;
207
+ } : Partial<T>;
208
+ type KeysOfUnion<T> = T extends T ? keyof T : never;
209
+ type Exact<P, I extends P> = P extends Builtin ? P : P & {
210
+ [K in keyof P]: Exact<P[K], I[K]>;
211
+ } & {
212
+ [K in Exclude<keyof I, KeysOfUnion<P>>]: never;
213
+ };
214
+ interface MessageFns<T> {
215
+ encode(message: T, writer?: BinaryWriter): BinaryWriter;
216
+ decode(input: BinaryReader | Uint8Array, length?: number): T;
217
+ fromJSON(object: any): T;
218
+ toJSON(message: T): unknown;
219
+ create<I extends Exact<DeepPartial<T>, I>>(base?: I): T;
220
+ fromPartial<I extends Exact<DeepPartial<T>, I>>(object: I): T;
221
+ }
222
+
223
+ declare function toColumnValue(value: unknown): ColumnValue;
224
+ declare function fromColumnValue(cv: ColumnValue): unknown;
225
+
226
+ interface GrpcReplicationOptions {
227
+ host?: string;
228
+ port?: number;
229
+ tlsCert?: string;
230
+ tlsKey?: string;
231
+ tlsCaCert?: string;
232
+ insecure?: boolean;
233
+ forwardDeadlineMs?: number;
234
+ }
235
+
236
+ interface PeerStreamEntry {
237
+ replicateStream: ServerDuplexStream<ReplicationMessage, ReplicationMessage> | null;
238
+ syncStream: ServerDuplexStream<SyncMessage, SyncMessage> | null;
239
+ }
240
+ interface ClientPeerEntry {
241
+ client: InstanceType<typeof ReplicationClient>;
242
+ replicateStream: ClientDuplexStream<ReplicationMessage, ReplicationMessage> | null;
243
+ syncStream: ClientDuplexStream<SyncMessage, SyncMessage> | null;
244
+ }
245
+ type BatchHandler = (batch: ReplicationBatch, fromPeerId: string) => Promise<void>;
246
+ type AckHandler = (ack: ReplicationAck, fromPeerId: string) => void;
247
+ type ForwardHandler = (request: ForwardedTransaction, fromPeerId: string) => Promise<ForwardedTransactionResult>;
248
+ type PeerConnectedHandler = (peer: NodeInfo) => void;
249
+ type PeerDisconnectedHandler = (peerId: string) => void;
250
+ type SyncRequestHandler = (request: SyncRequest, fromPeerId: string) => Promise<void>;
251
+ type SyncBatchHandler = (batch: SyncBatch, fromPeerId: string) => Promise<void>;
252
+ type SyncCompleteHandler = (complete: SyncComplete, fromPeerId: string) => Promise<void>;
253
+ type SyncAckHandler = (ack: SyncAck, fromPeerId: string) => void;
254
+
255
+ declare class GrpcReplicationTransport implements ReplicationTransport {
256
+ readonly options: GrpcReplicationOptions;
257
+ localNodeId: string;
258
+ localRole: TopologyRole;
259
+ localGroupId: string | undefined;
260
+ localPrimaryTerm: bigint | undefined;
261
+ localProtocolVersion: string | undefined;
262
+ connected: boolean;
263
+ server: Server | null;
264
+ boundPort: number;
265
+ healthImpl: HealthImplementation | null;
266
+ readonly connectedPeers: Map<string, NodeInfo>;
267
+ readonly serverPeerStreams: Map<string, PeerStreamEntry>;
268
+ readonly clientPeerStreams: Map<string, ClientPeerEntry>;
269
+ batchHandler: BatchHandler | null;
270
+ ackHandler: AckHandler | null;
271
+ forwardHandler: ForwardHandler | null;
272
+ peerConnectedHandler: PeerConnectedHandler | null;
273
+ peerDisconnectedHandler: PeerDisconnectedHandler | null;
274
+ syncRequestHandler: SyncRequestHandler | null;
275
+ syncBatchHandler: SyncBatchHandler | null;
276
+ syncCompleteHandler: SyncCompleteHandler | null;
277
+ syncAckHandler: SyncAckHandler | null;
278
+ constructor(options?: GrpcReplicationOptions);
279
+ getPort(): number;
280
+ connect(localNodeId: string, config: TransportConfig): Promise<void>;
281
+ disconnect(): Promise<void>;
282
+ send(peerId: string, batch: ReplicationBatch): Promise<void>;
283
+ broadcast(batch: ReplicationBatch): Promise<void>;
284
+ sendAck(peerId: string, ack: ReplicationAck): Promise<void>;
285
+ forward(peerId: string, request: ForwardedTransaction): Promise<ForwardedTransactionResult>;
286
+ requestSync(peerId: string, request: SyncRequest): Promise<void>;
287
+ sendSyncBatch(peerId: string, batch: SyncBatch): Promise<void>;
288
+ sendSyncComplete(peerId: string, complete: SyncComplete): Promise<void>;
289
+ sendSyncAck(peerId: string, ack: SyncAck): Promise<void>;
290
+ onBatchReceived(handler: BatchHandler): void;
291
+ onAckReceived(handler: AckHandler): void;
292
+ onForwardReceived(handler: ForwardHandler): void;
293
+ onSyncRequested(handler: SyncRequestHandler): void;
294
+ onSyncBatchReceived(handler: SyncBatchHandler): void;
295
+ onSyncCompleteReceived(handler: SyncCompleteHandler): void;
296
+ onSyncAckReceived(handler: SyncAckHandler): void;
297
+ onPeerConnected(handler: PeerConnectedHandler): void;
298
+ onPeerDisconnected(handler: PeerDisconnectedHandler): void;
299
+ peers(): ReadonlyMap<string, NodeInfo>;
300
+ extractTlsCN(call: {
301
+ getAuthContext(): unknown;
302
+ }): string | null;
303
+ validateTlsIdentity(call: {
304
+ getAuthContext(): unknown;
305
+ }, claimedNodeId: string): boolean;
306
+ resolveForwardPeerId(call: {
307
+ getPeer(): string;
308
+ getAuthContext(): unknown;
309
+ }): string | null;
310
+ private findPeerIdForStream;
311
+ private ensureConnected;
312
+ private getReplicateWriteStream;
313
+ private getSyncWriteStream;
314
+ }
315
+
316
+ export { type GrpcReplicationOptions, GrpcReplicationTransport, fromColumnValue, toColumnValue };