@delali/sirannon-db 0.3.4-next.62 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/README.md +79 -56
  2. package/dist/backup/index.d.ts +44 -45
  3. package/dist/backup/index.mjs +7 -7
  4. package/dist/backup-scheduler/index.d.ts +42 -41
  5. package/dist/backup-scheduler/index.mjs +4 -4
  6. package/dist/baseline-Co3iIsN_.d.ts +19 -0
  7. package/dist/change-tracker-DqCdeEyx.d.ts +128 -0
  8. package/dist/{chunk-VOSJBZ6Q.mjs → chunk-2ES3DT4A.mjs} +71 -33
  9. package/dist/{chunk-6CMCO7S4.mjs → chunk-2O3PP4CF.mjs} +1 -1
  10. package/dist/{chunk-E7Q7HE46.mjs → chunk-3BZLZ47R.mjs} +26 -26
  11. package/dist/chunk-4KASJKKK.mjs +2501 -0
  12. package/dist/{chunk-MYNI2WFS.mjs → chunk-52XW3Z76.mjs} +40 -8
  13. package/dist/chunk-55YRLSM2.mjs +57 -0
  14. package/dist/{chunk-KDAHYFW7.mjs → chunk-6AOJCNRU.mjs} +5 -5
  15. package/dist/{chunk-KXTYR2OQ.mjs → chunk-A3PHCO6W.mjs} +39 -111
  16. package/dist/chunk-ADNWEHGZ.mjs +299 -0
  17. package/dist/{chunk-2QLXDHAP.mjs → chunk-BLMRNSUG.mjs} +11 -2
  18. package/dist/chunk-BVMZJOVM.mjs +5 -0
  19. package/dist/{chunk-IWGIYDMZ.mjs → chunk-BZWDPF4G.mjs} +1 -1
  20. package/dist/{chunk-YVF2ZJTE.mjs → chunk-CZL4D3BM.mjs} +1 -1
  21. package/dist/{chunk-7SC2TZAS.mjs → chunk-DX4WGJL7.mjs} +2 -2
  22. package/dist/{chunk-45MKELYA.mjs → chunk-ESTZZPT5.mjs} +132 -13
  23. package/dist/{chunk-QP5L5DFJ.mjs → chunk-FJPR2CJX.mjs} +3 -3
  24. package/dist/chunk-HR7K3GZW.mjs +36 -0
  25. package/dist/{chunk-LXCGPZPA.mjs → chunk-IEKIYO4V.mjs} +1 -1
  26. package/dist/{chunk-TUD5CJ76.mjs → chunk-KB4OLJAD.mjs} +26 -19
  27. package/dist/{chunk-PBRXXISQ.mjs → chunk-KINDFBQP.mjs} +3 -2
  28. package/dist/{chunk-E6IMX7RS.mjs → chunk-KJLNYOOL.mjs} +2 -2
  29. package/dist/{chunk-BTTFW4Z4.mjs → chunk-KU32OT4H.mjs} +2 -10
  30. package/dist/{chunk-JQWGHSEH.mjs → chunk-NVSQ2T5Q.mjs} +71 -70
  31. package/dist/{chunk-W4EUTJNT.mjs → chunk-NZGSDALX.mjs} +94 -96
  32. package/dist/{chunk-U445A3C4.mjs → chunk-QGVRRKB2.mjs} +1 -1
  33. package/dist/{chunk-GYCEJNU4.mjs → chunk-R7GBXNTO.mjs} +1 -1
  34. package/dist/{chunk-7C36BCSN.mjs → chunk-VDN6FHU4.mjs} +1 -1
  35. package/dist/{chunk-6IYS4WLH.mjs → chunk-VO3ZWA2G.mjs} +142 -115
  36. package/dist/chunk-WOMADPM4.mjs +12 -0
  37. package/dist/{chunk-OUSWVNWT.mjs → chunk-YCMB6GR4.mjs} +1 -1
  38. package/dist/{chunk-YNTDOFTN.mjs → chunk-YW7IKQ7T.mjs} +1 -1
  39. package/dist/{chunk-M2BEAH5I.mjs → chunk-ZN4HI5FK.mjs} +126 -72
  40. package/dist/{chunk-SBL6GN43.mjs → chunk-ZYWI45EN.mjs} +1 -1
  41. package/dist/client/index.d.ts +135 -137
  42. package/dist/client/index.mjs +177 -82
  43. package/dist/client/topology.d.ts +31 -31
  44. package/dist/client/topology.mjs +42 -23
  45. package/dist/client-base-BxTocU1x.d.ts +398 -0
  46. package/dist/client-streams-YKANXMWO.mjs +112 -0
  47. package/dist/codegen/cli.mjs +4 -4
  48. package/dist/codegen/index.d.ts +36 -29
  49. package/dist/codegen/index.mjs +4 -4
  50. package/dist/core/index.d.ts +130 -115
  51. package/dist/core/index.mjs +387 -297
  52. package/dist/core/writer-worker.mjs +3 -3
  53. package/dist/database-CGDsXW1K.d.ts +959 -0
  54. package/dist/database-backup-DcLhxoa1.d.ts +143 -0
  55. package/dist/driver/better-sqlite3.d.ts +11 -10
  56. package/dist/driver/better-sqlite3.mjs +11 -11
  57. package/dist/driver/bun.d.ts +9 -8
  58. package/dist/driver/expo.d.ts +6 -7
  59. package/dist/driver/node.d.ts +11 -10
  60. package/dist/driver/node.mjs +13 -11
  61. package/dist/driver/wa-sqlite.d.ts +6 -6
  62. package/dist/errors-CJUkQ-KL.d.ts +199 -0
  63. package/dist/file-migrations/index.d.ts +20 -18
  64. package/dist/file-migrations/index.mjs +3 -3
  65. package/dist/forward-rpc-VRWFZXHN.mjs +44 -0
  66. package/dist/operation-registry-CGhNT-Sn.d.ts +96 -0
  67. package/dist/primary-wins-CHNOYuN7.d.ts +81 -0
  68. package/dist/protocol-DFpNNsIT.d.ts +153 -0
  69. package/dist/query-types-5B02ixH0.d.ts +129 -0
  70. package/dist/react/index.d.ts +22 -22
  71. package/dist/replication/coordinator/etcd.d.ts +37 -31
  72. package/dist/replication/coordinator/etcd.mjs +296 -131
  73. package/dist/replication/index.d.ts +201 -161
  74. package/dist/replication/index.mjs +630 -529
  75. package/dist/restore-options-CH8mE-Tb.d.ts +84 -0
  76. package/dist/server/index.d.ts +201 -191
  77. package/dist/server/index.mjs +736 -619
  78. package/dist/server-options-aYtCkefX.d.ts +317 -0
  79. package/dist/server-streams-24XL4T43.mjs +254 -0
  80. package/dist/sirannon-J3EgPVD7.d.ts +179 -0
  81. package/dist/transport/grpc.d.ts +37 -24
  82. package/dist/transport/grpc.mjs +83 -3199
  83. package/dist/transport/memory.d.ts +25 -26
  84. package/dist/transport/memory.mjs +18 -9
  85. package/dist/types-BrAiDGOb.d.ts +505 -0
  86. package/dist/types-CEJG0eFS.d.ts +88 -0
  87. package/dist/types-Dc8oWlxj.d.ts +1580 -0
  88. package/dist/types-DqODKeOq.d.ts +123 -0
  89. package/dist/types-guEKSzMr.d.ts +367 -0
  90. package/package.json +7 -7
  91. package/dist/baseline-D93hcIEE.d.ts +0 -17
  92. package/dist/change-tracker-CjRFuZdB.d.ts +0 -144
  93. package/dist/client-base-Cmd9EVme.d.ts +0 -397
  94. package/dist/database-BLQvqjsw.d.ts +0 -917
  95. package/dist/database-backup-B7oszQ2n.d.ts +0 -141
  96. package/dist/errors-Dei4GdBb.d.ts +0 -196
  97. package/dist/operation-registry-oiPuSYI6.d.ts +0 -94
  98. package/dist/primary-wins-B0np8JS3.d.ts +0 -85
  99. package/dist/protocol-HI-nY8DD.d.ts +0 -152
  100. package/dist/query-types-p1liOP-b.d.ts +0 -127
  101. package/dist/restore-options-CksYsH1l.d.ts +0 -83
  102. package/dist/server-options-Bj5iJnjx.d.ts +0 -292
  103. package/dist/sirannon-BPxC5tC2.d.ts +0 -178
  104. package/dist/types-B0EhgDbr.d.ts +0 -340
  105. package/dist/types-CbjfRwrK.d.ts +0 -499
  106. package/dist/types-CjhxcjhA.d.ts +0 -123
  107. package/dist/types-DPSmjU54.d.ts +0 -1518
  108. package/dist/types-DTO4CYhW.d.ts +0 -88
@@ -1,3185 +1,66 @@
1
- import { TransportError } from '../chunk-BTTFW4Z4.mjs';
2
- import '../chunk-2QLXDHAP.mjs';
3
- import '../chunk-PBRXXISQ.mjs';
4
- import { BinaryWriter, BinaryReader } from '@bufbuild/protobuf/wire';
5
- import { makeGenericClientConstructor, Server, Metadata, status, ServerCredentials, credentials } from '@grpc/grpc-js';
6
- import { readFileSync } from 'fs';
7
- import { HealthImplementation } from 'grpc-health-check';
1
+ import { SERVICE_NAME, DEFAULT_FORWARD_DEADLINE_MS } from '../chunk-BVMZJOVM.mjs';
2
+ import { stopEndpointDialling } from '../chunk-55YRLSM2.mjs';
3
+ import { peerIdForServerStream, replicateWriteStream, syncWriteStream } from '../chunk-HR7K3GZW.mjs';
4
+ import { toBatchPayload, toAckPayload, toSyncRequestPayload, toSyncBatchPayload, toSyncCompletePayload, toSyncAckPayload } from '../chunk-ADNWEHGZ.mjs';
5
+ export { fromColumnValue, toColumnValue } from '../chunk-ADNWEHGZ.mjs';
6
+ import { TransportError } from '../chunk-KU32OT4H.mjs';
7
+ import { optionalDependencyError } from '../chunk-WOMADPM4.mjs';
8
+ import '../chunk-BLMRNSUG.mjs';
9
+ import '../chunk-KINDFBQP.mjs';
8
10
 
9
- // src/transport/grpc/codec.ts
10
- function toColumnValue(value) {
11
- if (value === null || value === void 0) {
12
- return { nullValue: true };
13
- }
14
- if (typeof value === "string") {
15
- return { stringValue: value };
16
- }
17
- if (typeof value === "bigint") {
18
- return { intValue: value };
19
- }
20
- if (typeof value === "number") {
21
- if (Number.isInteger(value)) {
22
- return { intValue: BigInt(value) };
23
- }
24
- return { floatValue: value };
25
- }
26
- if (typeof value === "boolean") {
27
- return { boolValue: value };
28
- }
29
- if (value instanceof Uint8Array || Buffer.isBuffer(value)) {
30
- return { blobValue: Buffer.from(value) };
31
- }
32
- throw new TypeError(
33
- `Unsupported value type for ColumnValue conversion: ${typeof value} (${Object.prototype.toString.call(value)})`
34
- );
35
- }
36
- function fromColumnValue(cv) {
37
- if (cv.nullValue !== void 0) return null;
38
- if (cv.stringValue !== void 0) return cv.stringValue;
39
- if (cv.intValue !== void 0) return cv.intValue;
40
- if (cv.floatValue !== void 0) return cv.floatValue;
41
- if (cv.blobValue !== void 0) return cv.blobValue;
42
- if (cv.boolValue !== void 0) return cv.boolValue;
43
- return null;
44
- }
45
- function toRowData(record) {
46
- if (record === null || record === void 0) return void 0;
47
- const fields = {};
48
- for (const [key, value] of Object.entries(record)) {
49
- fields[key] = toColumnValue(value);
50
- }
51
- return { fields };
52
- }
53
- function fromRowData(rowData) {
54
- if (rowData === void 0) return null;
55
- const result = {};
56
- for (const [key, cv] of Object.entries(rowData.fields)) {
57
- result[key] = fromColumnValue(cv);
58
- }
59
- return result;
60
- }
61
- function toProtoChange(change) {
62
- return {
63
- table: change.table,
64
- operation: change.operation,
65
- rowId: change.rowId,
66
- primaryKey: toRowData(change.primaryKey),
67
- hlc: change.hlc,
68
- txId: change.txId,
69
- nodeId: change.nodeId,
70
- newData: toRowData(change.newData),
71
- oldData: toRowData(change.oldData),
72
- ddlStatement: change.ddlStatement ?? ""
73
- };
74
- }
75
- function fromProtoChange(proto) {
76
- return {
77
- table: proto.table,
78
- operation: proto.operation,
79
- rowId: proto.rowId,
80
- primaryKey: fromRowData(proto.primaryKey) ?? {},
81
- hlc: proto.hlc,
82
- txId: proto.txId,
83
- nodeId: proto.nodeId,
84
- newData: fromRowData(proto.newData),
85
- oldData: fromRowData(proto.oldData),
86
- ddlStatement: proto.ddlStatement || void 0
87
- };
88
- }
89
- function toBatchPayload(batch) {
90
- return {
91
- sourceNodeId: batch.sourceNodeId,
92
- batchId: batch.batchId,
93
- fromSeq: batch.fromSeq,
94
- toSeq: batch.toSeq,
95
- hlcRange: { min: batch.hlcRange.min, max: batch.hlcRange.max },
96
- changes: batch.changes.map(toProtoChange),
97
- checksum: batch.checksum,
98
- groupId: batch.groupId ?? "",
99
- primaryTerm: batch.primaryTerm ?? 0n
100
- };
101
- }
102
- function fromBatchPayload(payload) {
103
- return {
104
- sourceNodeId: payload.sourceNodeId,
105
- batchId: payload.batchId,
106
- fromSeq: payload.fromSeq,
107
- toSeq: payload.toSeq,
108
- hlcRange: {
109
- min: payload.hlcRange?.min ?? "",
110
- max: payload.hlcRange?.max ?? ""
111
- },
112
- changes: payload.changes.map(fromProtoChange),
113
- checksum: payload.checksum,
114
- groupId: payload.groupId || void 0,
115
- primaryTerm: payload.primaryTerm === 0n ? void 0 : payload.primaryTerm
116
- };
117
- }
118
- function toAckPayload(ack) {
119
- return {
120
- batchId: ack.batchId,
121
- ackedSeq: ack.ackedSeq,
122
- nodeId: ack.nodeId,
123
- groupId: ack.groupId ?? "",
124
- primaryTerm: ack.primaryTerm ?? 0n
125
- };
126
- }
127
- function fromAckPayload(payload) {
128
- return {
129
- batchId: payload.batchId,
130
- ackedSeq: payload.ackedSeq,
131
- nodeId: payload.nodeId,
132
- groupId: payload.groupId || void 0,
133
- primaryTerm: payload.primaryTerm === 0n ? void 0 : payload.primaryTerm
134
- };
135
- }
136
- function toSyncRequestPayload(req) {
137
- return {
138
- requestId: req.requestId,
139
- joinerNodeId: req.joinerNodeId,
140
- completedTables: req.completedTables,
141
- groupId: req.groupId ?? "",
142
- primaryTerm: req.primaryTerm ?? 0n,
143
- supportsStreamVerification: req.supportsStreamVerification === true
144
- };
145
- }
146
- function fromSyncRequestPayload(p) {
147
- return {
148
- requestId: p.requestId,
149
- joinerNodeId: p.joinerNodeId,
150
- completedTables: p.completedTables,
151
- supportsStreamVerification: p.supportsStreamVerification === true ? true : void 0,
152
- groupId: p.groupId || void 0,
153
- primaryTerm: p.primaryTerm === 0n ? void 0 : p.primaryTerm
154
- };
155
- }
156
- function toSyncBatchPayload(batch) {
157
- return {
158
- requestId: batch.requestId,
159
- table: batch.table,
160
- batchIndex: batch.batchIndex,
161
- rows: batch.rows.map((row) => toRowData(row) ?? { fields: {} }),
162
- schema: batch.schema ?? [],
163
- checksum: batch.checksum,
164
- isLastBatchForTable: batch.isLastBatchForTable,
165
- groupId: batch.groupId ?? "",
166
- primaryTerm: batch.primaryTerm ?? 0n,
167
- totalTables: batch.totalTables ?? 0
168
- };
169
- }
170
- function fromSyncBatchPayload(p) {
171
- return {
172
- requestId: p.requestId,
173
- table: p.table,
174
- batchIndex: p.batchIndex,
175
- rows: p.rows.map((r) => fromRowData(r) ?? {}),
176
- schema: p.schema.length > 0 ? p.schema : void 0,
177
- checksum: p.checksum,
178
- isLastBatchForTable: p.isLastBatchForTable,
179
- groupId: p.groupId || void 0,
180
- primaryTerm: p.primaryTerm === 0n ? void 0 : p.primaryTerm,
181
- totalTables: p.totalTables === 0 ? void 0 : p.totalTables
182
- };
183
- }
184
- function toSyncCompletePayload(complete) {
185
- return {
186
- requestId: complete.requestId,
187
- snapshotSeq: complete.snapshotSeq,
188
- manifests: complete.manifests.map((m) => ({
189
- table: m.table,
190
- rowCount: m.rowCount,
191
- pkHash: m.pkHash ?? "",
192
- batchDigest: m.batchDigest ?? ""
193
- })),
194
- groupId: complete.groupId ?? "",
195
- primaryTerm: complete.primaryTerm ?? 0n
196
- };
197
- }
198
- function fromSyncCompletePayload(p) {
199
- return {
200
- requestId: p.requestId,
201
- snapshotSeq: p.snapshotSeq,
202
- manifests: p.manifests.map(
203
- (m) => ({
204
- table: m.table,
205
- rowCount: m.rowCount,
206
- pkHash: m.pkHash || void 0,
207
- batchDigest: m.batchDigest || void 0
208
- })
209
- ),
210
- groupId: p.groupId || void 0,
211
- primaryTerm: p.primaryTerm === 0n ? void 0 : p.primaryTerm
212
- };
213
- }
214
- function toSyncAckPayload(ack) {
215
- return {
216
- requestId: ack.requestId,
217
- joinerNodeId: ack.joinerNodeId,
218
- table: ack.table,
219
- batchIndex: ack.batchIndex,
220
- success: ack.success,
221
- error: ack.error ?? "",
222
- groupId: ack.groupId ?? "",
223
- primaryTerm: ack.primaryTerm ?? 0n
224
- };
225
- }
226
- function fromSyncAckPayload(p) {
227
- return {
228
- requestId: p.requestId,
229
- joinerNodeId: p.joinerNodeId,
230
- table: p.table,
231
- batchIndex: p.batchIndex,
232
- success: p.success,
233
- error: p.error || void 0,
234
- groupId: p.groupId || void 0,
235
- primaryTerm: p.primaryTerm === 0n ? void 0 : p.primaryTerm
236
- };
237
- }
238
- function toForwardRequest(req) {
239
- const statements = req.statements.map((s) => {
240
- const namedParams = {};
241
- const positionalParams = [];
242
- if (s.params !== void 0 && s.params !== null) {
243
- if (Array.isArray(s.params)) {
244
- for (const v of s.params) {
245
- positionalParams.push(toColumnValue(v));
246
- }
247
- } else {
248
- for (const [k, v] of Object.entries(s.params)) {
249
- namedParams[k] = toColumnValue(v);
250
- }
251
- }
252
- }
253
- return { sql: s.sql, namedParams, positionalParams };
254
- });
255
- return { requestId: req.requestId, statements, groupId: req.groupId ?? "", primaryTerm: req.primaryTerm ?? 0n };
256
- }
257
- function fromForwardRequest(proto) {
258
- const statements = proto.statements.map((s) => {
259
- const hasNamed = Object.keys(s.namedParams).length > 0;
260
- const hasPositional = s.positionalParams.length > 0;
261
- let params;
262
- if (hasNamed) {
263
- const named = {};
264
- for (const [k, cv] of Object.entries(s.namedParams)) {
265
- named[k] = fromColumnValue(cv);
266
- }
267
- params = named;
268
- } else if (hasPositional) {
269
- params = s.positionalParams.map(fromColumnValue);
270
- }
271
- return { sql: s.sql, params };
272
- });
273
- return {
274
- requestId: proto.requestId,
275
- statements,
276
- groupId: proto.groupId || void 0,
277
- primaryTerm: proto.primaryTerm === 0n ? void 0 : proto.primaryTerm
278
- };
279
- }
280
-
281
- // src/transport/grpc/client-reconnect.ts
282
- var RECONNECT_MIN_DELAY_MS = 250;
283
- var RECONNECT_MAX_DELAY_MS = 5e3;
284
- var stateByTransport = /* @__PURE__ */ new WeakMap();
285
- function stateFor(transport) {
286
- const existing = stateByTransport.get(transport);
287
- if (existing) return existing;
288
- const created = { timers: /* @__PURE__ */ new Map(), delays: /* @__PURE__ */ new Map(), dialled: /* @__PURE__ */ new Map() };
289
- stateByTransport.set(transport, created);
290
- return created;
291
- }
292
- function claimEndpoint(transport, endpoint) {
293
- const state = stateFor(transport);
294
- if (state.dialled.has(endpoint)) return false;
295
- state.dialled.set(endpoint, () => void 0);
296
- return true;
297
- }
298
- function registerEndpointAbort(transport, endpoint, abort) {
299
- const state = stateFor(transport);
300
- if (!state.dialled.has(endpoint)) return;
301
- state.dialled.set(endpoint, abort);
302
- }
303
- function releaseEndpoint(transport, endpoint) {
304
- stateFor(transport).dialled.delete(endpoint);
305
- }
306
- function noteEndpointReachable(transport, endpoint) {
307
- stateFor(transport).delays.delete(endpoint);
308
- }
309
- function scheduleEndpointRedial(transport, endpoint, redial) {
310
- if (!transport.connected) return;
311
- const state = stateFor(transport);
312
- if (state.timers.has(endpoint)) return;
313
- const delayMs = state.delays.get(endpoint) ?? RECONNECT_MIN_DELAY_MS;
314
- state.delays.set(endpoint, Math.min(delayMs * 2, RECONNECT_MAX_DELAY_MS));
315
- const timer = setTimeout(() => {
316
- state.timers.delete(endpoint);
317
- if (!transport.connected) return;
318
- redial();
319
- }, delayMs);
320
- timer.unref?.();
321
- state.timers.set(endpoint, timer);
322
- }
323
- function stopEndpointDialling(transport) {
324
- const state = stateByTransport.get(transport);
325
- if (!state) return;
326
- for (const timer of state.timers.values()) {
327
- clearTimeout(timer);
328
- }
329
- state.timers.clear();
330
- state.delays.clear();
331
- const aborts = [...state.dialled.values()];
332
- state.dialled.clear();
333
- for (const abort of aborts) {
334
- abort();
335
- }
336
- }
337
- function createBaseColumnValue() {
338
- return {
339
- nullValue: void 0,
340
- stringValue: void 0,
341
- intValue: void 0,
342
- floatValue: void 0,
343
- blobValue: void 0,
344
- boolValue: void 0
345
- };
346
- }
347
- var ColumnValue = {
348
- encode(message, writer = new BinaryWriter()) {
349
- if (message.nullValue !== void 0) {
350
- writer.uint32(8).bool(message.nullValue);
351
- }
352
- if (message.stringValue !== void 0) {
353
- writer.uint32(18).string(message.stringValue);
354
- }
355
- if (message.intValue !== void 0) {
356
- if (BigInt.asIntN(64, message.intValue) !== message.intValue) {
357
- throw new globalThis.Error("value provided for field message.intValue of type int64 too large");
358
- }
359
- writer.uint32(24).int64(message.intValue);
360
- }
361
- if (message.floatValue !== void 0) {
362
- writer.uint32(33).double(message.floatValue);
363
- }
364
- if (message.blobValue !== void 0) {
365
- writer.uint32(42).bytes(message.blobValue);
366
- }
367
- if (message.boolValue !== void 0) {
368
- writer.uint32(48).bool(message.boolValue);
369
- }
370
- return writer;
371
- },
372
- decode(input, length) {
373
- const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
374
- const end = length === void 0 ? reader.len : reader.pos + length;
375
- const message = createBaseColumnValue();
376
- while (reader.pos < end) {
377
- const tag = reader.uint32();
378
- switch (tag >>> 3) {
379
- case 1: {
380
- if (tag !== 8) {
381
- break;
382
- }
383
- message.nullValue = reader.bool();
384
- continue;
385
- }
386
- case 2: {
387
- if (tag !== 18) {
388
- break;
389
- }
390
- message.stringValue = reader.string();
391
- continue;
392
- }
393
- case 3: {
394
- if (tag !== 24) {
395
- break;
396
- }
397
- message.intValue = reader.int64();
398
- continue;
399
- }
400
- case 4: {
401
- if (tag !== 33) {
402
- break;
403
- }
404
- message.floatValue = reader.double();
405
- continue;
406
- }
407
- case 5: {
408
- if (tag !== 42) {
409
- break;
410
- }
411
- message.blobValue = Buffer.from(reader.bytes());
412
- continue;
413
- }
414
- case 6: {
415
- if (tag !== 48) {
416
- break;
417
- }
418
- message.boolValue = reader.bool();
419
- continue;
420
- }
421
- }
422
- if ((tag & 7) === 4 || tag === 0) {
423
- break;
424
- }
425
- reader.skip(tag & 7);
426
- }
427
- return message;
428
- },
429
- fromJSON(object) {
430
- return {
431
- nullValue: isSet(object.nullValue) ? globalThis.Boolean(object.nullValue) : isSet(object.null_value) ? globalThis.Boolean(object.null_value) : void 0,
432
- stringValue: isSet(object.stringValue) ? globalThis.String(object.stringValue) : isSet(object.string_value) ? globalThis.String(object.string_value) : void 0,
433
- intValue: isSet(object.intValue) ? BigInt(object.intValue) : isSet(object.int_value) ? BigInt(object.int_value) : void 0,
434
- floatValue: isSet(object.floatValue) ? globalThis.Number(object.floatValue) : isSet(object.float_value) ? globalThis.Number(object.float_value) : void 0,
435
- blobValue: isSet(object.blobValue) ? Buffer.from(bytesFromBase64(object.blobValue)) : isSet(object.blob_value) ? Buffer.from(bytesFromBase64(object.blob_value)) : void 0,
436
- boolValue: isSet(object.boolValue) ? globalThis.Boolean(object.boolValue) : isSet(object.bool_value) ? globalThis.Boolean(object.bool_value) : void 0
437
- };
438
- },
439
- toJSON(message) {
440
- const obj = {};
441
- if (message.nullValue !== void 0) {
442
- obj.nullValue = message.nullValue;
443
- }
444
- if (message.stringValue !== void 0) {
445
- obj.stringValue = message.stringValue;
446
- }
447
- if (message.intValue !== void 0) {
448
- obj.intValue = message.intValue.toString();
449
- }
450
- if (message.floatValue !== void 0) {
451
- obj.floatValue = message.floatValue;
452
- }
453
- if (message.blobValue !== void 0) {
454
- obj.blobValue = base64FromBytes(message.blobValue);
455
- }
456
- if (message.boolValue !== void 0) {
457
- obj.boolValue = message.boolValue;
458
- }
459
- return obj;
460
- },
461
- create(base) {
462
- return ColumnValue.fromPartial(base ?? {});
463
- },
464
- fromPartial(object) {
465
- const message = createBaseColumnValue();
466
- message.nullValue = object.nullValue ?? void 0;
467
- message.stringValue = object.stringValue ?? void 0;
468
- message.intValue = object.intValue ?? void 0;
469
- message.floatValue = object.floatValue ?? void 0;
470
- message.blobValue = object.blobValue ?? void 0;
471
- message.boolValue = object.boolValue ?? void 0;
472
- return message;
473
- }
474
- };
475
- function createBaseRowData() {
476
- return { fields: {} };
477
- }
478
- var RowData = {
479
- encode(message, writer = new BinaryWriter()) {
480
- globalThis.Object.entries(message.fields).forEach(([key, value]) => {
481
- RowData_FieldsEntry.encode({ key, value }, writer.uint32(10).fork()).join();
482
- });
483
- return writer;
484
- },
485
- decode(input, length) {
486
- const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
487
- const end = length === void 0 ? reader.len : reader.pos + length;
488
- const message = createBaseRowData();
489
- while (reader.pos < end) {
490
- const tag = reader.uint32();
491
- switch (tag >>> 3) {
492
- case 1: {
493
- if (tag !== 10) {
494
- break;
495
- }
496
- const entry1 = RowData_FieldsEntry.decode(reader, reader.uint32());
497
- if (entry1.value !== void 0) {
498
- message.fields[entry1.key] = entry1.value;
499
- }
500
- continue;
501
- }
502
- }
503
- if ((tag & 7) === 4 || tag === 0) {
504
- break;
505
- }
506
- reader.skip(tag & 7);
507
- }
508
- return message;
509
- },
510
- fromJSON(object) {
511
- return {
512
- fields: isObject(object.fields) ? globalThis.Object.entries(object.fields).reduce(
513
- (acc, [key, value]) => {
514
- acc[key] = ColumnValue.fromJSON(value);
515
- return acc;
516
- },
517
- {}
518
- ) : {}
519
- };
520
- },
521
- toJSON(message) {
522
- const obj = {};
523
- if (message.fields) {
524
- const entries = globalThis.Object.entries(message.fields);
525
- if (entries.length > 0) {
526
- obj.fields = {};
527
- entries.forEach(([k, v]) => {
528
- obj.fields[k] = ColumnValue.toJSON(v);
529
- });
530
- }
531
- }
532
- return obj;
533
- },
534
- create(base) {
535
- return RowData.fromPartial(base ?? {});
536
- },
537
- fromPartial(object) {
538
- const message = createBaseRowData();
539
- message.fields = globalThis.Object.entries(object.fields ?? {}).reduce(
540
- (acc, [key, value]) => {
541
- if (value !== void 0) {
542
- acc[key] = ColumnValue.fromPartial(value);
543
- }
544
- return acc;
545
- },
546
- {}
547
- );
548
- return message;
549
- }
550
- };
551
- function createBaseRowData_FieldsEntry() {
552
- return { key: "", value: void 0 };
553
- }
554
- var RowData_FieldsEntry = {
555
- encode(message, writer = new BinaryWriter()) {
556
- if (message.key !== "") {
557
- writer.uint32(10).string(message.key);
558
- }
559
- if (message.value !== void 0) {
560
- ColumnValue.encode(message.value, writer.uint32(18).fork()).join();
561
- }
562
- return writer;
563
- },
564
- decode(input, length) {
565
- const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
566
- const end = length === void 0 ? reader.len : reader.pos + length;
567
- const message = createBaseRowData_FieldsEntry();
568
- while (reader.pos < end) {
569
- const tag = reader.uint32();
570
- switch (tag >>> 3) {
571
- case 1: {
572
- if (tag !== 10) {
573
- break;
574
- }
575
- message.key = reader.string();
576
- continue;
577
- }
578
- case 2: {
579
- if (tag !== 18) {
580
- break;
581
- }
582
- message.value = ColumnValue.decode(reader, reader.uint32());
583
- continue;
584
- }
585
- }
586
- if ((tag & 7) === 4 || tag === 0) {
587
- break;
588
- }
589
- reader.skip(tag & 7);
590
- }
591
- return message;
592
- },
593
- fromJSON(object) {
594
- return {
595
- key: isSet(object.key) ? globalThis.String(object.key) : "",
596
- value: isSet(object.value) ? ColumnValue.fromJSON(object.value) : void 0
597
- };
598
- },
599
- toJSON(message) {
600
- const obj = {};
601
- if (message.key !== "") {
602
- obj.key = message.key;
603
- }
604
- if (message.value !== void 0) {
605
- obj.value = ColumnValue.toJSON(message.value);
606
- }
607
- return obj;
608
- },
609
- create(base) {
610
- return RowData_FieldsEntry.fromPartial(base ?? {});
611
- },
612
- fromPartial(object) {
613
- const message = createBaseRowData_FieldsEntry();
614
- message.key = object.key ?? "";
615
- message.value = object.value !== void 0 && object.value !== null ? ColumnValue.fromPartial(object.value) : void 0;
616
- return message;
617
- }
618
- };
619
- function createBaseHlcRange() {
620
- return { min: "", max: "" };
621
- }
622
- var HlcRange = {
623
- encode(message, writer = new BinaryWriter()) {
624
- if (message.min !== "") {
625
- writer.uint32(10).string(message.min);
626
- }
627
- if (message.max !== "") {
628
- writer.uint32(18).string(message.max);
629
- }
630
- return writer;
631
- },
632
- decode(input, length) {
633
- const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
634
- const end = length === void 0 ? reader.len : reader.pos + length;
635
- const message = createBaseHlcRange();
636
- while (reader.pos < end) {
637
- const tag = reader.uint32();
638
- switch (tag >>> 3) {
639
- case 1: {
640
- if (tag !== 10) {
641
- break;
642
- }
643
- message.min = reader.string();
644
- continue;
645
- }
646
- case 2: {
647
- if (tag !== 18) {
648
- break;
649
- }
650
- message.max = reader.string();
651
- continue;
652
- }
653
- }
654
- if ((tag & 7) === 4 || tag === 0) {
655
- break;
656
- }
657
- reader.skip(tag & 7);
658
- }
659
- return message;
660
- },
661
- fromJSON(object) {
662
- return {
663
- min: isSet(object.min) ? globalThis.String(object.min) : "",
664
- max: isSet(object.max) ? globalThis.String(object.max) : ""
665
- };
666
- },
667
- toJSON(message) {
668
- const obj = {};
669
- if (message.min !== "") {
670
- obj.min = message.min;
671
- }
672
- if (message.max !== "") {
673
- obj.max = message.max;
674
- }
675
- return obj;
676
- },
677
- create(base) {
678
- return HlcRange.fromPartial(base ?? {});
679
- },
680
- fromPartial(object) {
681
- const message = createBaseHlcRange();
682
- message.min = object.min ?? "";
683
- message.max = object.max ?? "";
684
- return message;
685
- }
686
- };
687
- function createBaseReplicationChange() {
688
- return {
689
- table: "",
690
- operation: "",
691
- rowId: "",
692
- primaryKey: void 0,
693
- hlc: "",
694
- txId: "",
695
- nodeId: "",
696
- newData: void 0,
697
- oldData: void 0,
698
- ddlStatement: ""
699
- };
700
- }
701
- var ReplicationChange = {
702
- encode(message, writer = new BinaryWriter()) {
703
- if (message.table !== "") {
704
- writer.uint32(10).string(message.table);
705
- }
706
- if (message.operation !== "") {
707
- writer.uint32(18).string(message.operation);
708
- }
709
- if (message.rowId !== "") {
710
- writer.uint32(26).string(message.rowId);
711
- }
712
- if (message.primaryKey !== void 0) {
713
- RowData.encode(message.primaryKey, writer.uint32(34).fork()).join();
714
- }
715
- if (message.hlc !== "") {
716
- writer.uint32(42).string(message.hlc);
717
- }
718
- if (message.txId !== "") {
719
- writer.uint32(50).string(message.txId);
720
- }
721
- if (message.nodeId !== "") {
722
- writer.uint32(58).string(message.nodeId);
723
- }
724
- if (message.newData !== void 0) {
725
- RowData.encode(message.newData, writer.uint32(66).fork()).join();
726
- }
727
- if (message.oldData !== void 0) {
728
- RowData.encode(message.oldData, writer.uint32(74).fork()).join();
729
- }
730
- if (message.ddlStatement !== "") {
731
- writer.uint32(82).string(message.ddlStatement);
732
- }
733
- return writer;
734
- },
735
- decode(input, length) {
736
- const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
737
- const end = length === void 0 ? reader.len : reader.pos + length;
738
- const message = createBaseReplicationChange();
739
- while (reader.pos < end) {
740
- const tag = reader.uint32();
741
- switch (tag >>> 3) {
742
- case 1: {
743
- if (tag !== 10) {
744
- break;
745
- }
746
- message.table = reader.string();
747
- continue;
748
- }
749
- case 2: {
750
- if (tag !== 18) {
751
- break;
752
- }
753
- message.operation = reader.string();
754
- continue;
755
- }
756
- case 3: {
757
- if (tag !== 26) {
758
- break;
759
- }
760
- message.rowId = reader.string();
761
- continue;
762
- }
763
- case 4: {
764
- if (tag !== 34) {
765
- break;
766
- }
767
- message.primaryKey = RowData.decode(reader, reader.uint32());
768
- continue;
769
- }
770
- case 5: {
771
- if (tag !== 42) {
772
- break;
773
- }
774
- message.hlc = reader.string();
775
- continue;
776
- }
777
- case 6: {
778
- if (tag !== 50) {
779
- break;
780
- }
781
- message.txId = reader.string();
782
- continue;
783
- }
784
- case 7: {
785
- if (tag !== 58) {
786
- break;
787
- }
788
- message.nodeId = reader.string();
789
- continue;
790
- }
791
- case 8: {
792
- if (tag !== 66) {
793
- break;
794
- }
795
- message.newData = RowData.decode(reader, reader.uint32());
796
- continue;
797
- }
798
- case 9: {
799
- if (tag !== 74) {
800
- break;
801
- }
802
- message.oldData = RowData.decode(reader, reader.uint32());
803
- continue;
804
- }
805
- case 10: {
806
- if (tag !== 82) {
807
- break;
808
- }
809
- message.ddlStatement = reader.string();
810
- continue;
811
- }
812
- }
813
- if ((tag & 7) === 4 || tag === 0) {
814
- break;
815
- }
816
- reader.skip(tag & 7);
817
- }
818
- return message;
819
- },
820
- fromJSON(object) {
821
- return {
822
- table: isSet(object.table) ? globalThis.String(object.table) : "",
823
- operation: isSet(object.operation) ? globalThis.String(object.operation) : "",
824
- rowId: isSet(object.rowId) ? globalThis.String(object.rowId) : isSet(object.row_id) ? globalThis.String(object.row_id) : "",
825
- primaryKey: isSet(object.primaryKey) ? RowData.fromJSON(object.primaryKey) : isSet(object.primary_key) ? RowData.fromJSON(object.primary_key) : void 0,
826
- hlc: isSet(object.hlc) ? globalThis.String(object.hlc) : "",
827
- txId: isSet(object.txId) ? globalThis.String(object.txId) : isSet(object.tx_id) ? globalThis.String(object.tx_id) : "",
828
- nodeId: isSet(object.nodeId) ? globalThis.String(object.nodeId) : isSet(object.node_id) ? globalThis.String(object.node_id) : "",
829
- newData: isSet(object.newData) ? RowData.fromJSON(object.newData) : isSet(object.new_data) ? RowData.fromJSON(object.new_data) : void 0,
830
- oldData: isSet(object.oldData) ? RowData.fromJSON(object.oldData) : isSet(object.old_data) ? RowData.fromJSON(object.old_data) : void 0,
831
- ddlStatement: isSet(object.ddlStatement) ? globalThis.String(object.ddlStatement) : isSet(object.ddl_statement) ? globalThis.String(object.ddl_statement) : ""
832
- };
833
- },
834
- toJSON(message) {
835
- const obj = {};
836
- if (message.table !== "") {
837
- obj.table = message.table;
838
- }
839
- if (message.operation !== "") {
840
- obj.operation = message.operation;
841
- }
842
- if (message.rowId !== "") {
843
- obj.rowId = message.rowId;
844
- }
845
- if (message.primaryKey !== void 0) {
846
- obj.primaryKey = RowData.toJSON(message.primaryKey);
847
- }
848
- if (message.hlc !== "") {
849
- obj.hlc = message.hlc;
850
- }
851
- if (message.txId !== "") {
852
- obj.txId = message.txId;
853
- }
854
- if (message.nodeId !== "") {
855
- obj.nodeId = message.nodeId;
856
- }
857
- if (message.newData !== void 0) {
858
- obj.newData = RowData.toJSON(message.newData);
859
- }
860
- if (message.oldData !== void 0) {
861
- obj.oldData = RowData.toJSON(message.oldData);
862
- }
863
- if (message.ddlStatement !== "") {
864
- obj.ddlStatement = message.ddlStatement;
865
- }
866
- return obj;
867
- },
868
- create(base) {
869
- return ReplicationChange.fromPartial(base ?? {});
870
- },
871
- fromPartial(object) {
872
- const message = createBaseReplicationChange();
873
- message.table = object.table ?? "";
874
- message.operation = object.operation ?? "";
875
- message.rowId = object.rowId ?? "";
876
- message.primaryKey = object.primaryKey !== void 0 && object.primaryKey !== null ? RowData.fromPartial(object.primaryKey) : void 0;
877
- message.hlc = object.hlc ?? "";
878
- message.txId = object.txId ?? "";
879
- message.nodeId = object.nodeId ?? "";
880
- message.newData = object.newData !== void 0 && object.newData !== null ? RowData.fromPartial(object.newData) : void 0;
881
- message.oldData = object.oldData !== void 0 && object.oldData !== null ? RowData.fromPartial(object.oldData) : void 0;
882
- message.ddlStatement = object.ddlStatement ?? "";
883
- return message;
884
- }
885
- };
886
- function createBaseBatchPayload() {
887
- return {
888
- sourceNodeId: "",
889
- batchId: "",
890
- fromSeq: 0n,
891
- toSeq: 0n,
892
- hlcRange: void 0,
893
- changes: [],
894
- checksum: "",
895
- groupId: "",
896
- primaryTerm: 0n
897
- };
898
- }
899
- var BatchPayload = {
900
- encode(message, writer = new BinaryWriter()) {
901
- if (message.sourceNodeId !== "") {
902
- writer.uint32(10).string(message.sourceNodeId);
903
- }
904
- if (message.batchId !== "") {
905
- writer.uint32(18).string(message.batchId);
906
- }
907
- if (message.fromSeq !== 0n) {
908
- if (BigInt.asIntN(64, message.fromSeq) !== message.fromSeq) {
909
- throw new globalThis.Error("value provided for field message.fromSeq of type int64 too large");
910
- }
911
- writer.uint32(24).int64(message.fromSeq);
912
- }
913
- if (message.toSeq !== 0n) {
914
- if (BigInt.asIntN(64, message.toSeq) !== message.toSeq) {
915
- throw new globalThis.Error("value provided for field message.toSeq of type int64 too large");
916
- }
917
- writer.uint32(32).int64(message.toSeq);
918
- }
919
- if (message.hlcRange !== void 0) {
920
- HlcRange.encode(message.hlcRange, writer.uint32(42).fork()).join();
921
- }
922
- for (const v of message.changes) {
923
- ReplicationChange.encode(v, writer.uint32(50).fork()).join();
924
- }
925
- if (message.checksum !== "") {
926
- writer.uint32(58).string(message.checksum);
927
- }
928
- if (message.groupId !== "") {
929
- writer.uint32(66).string(message.groupId);
930
- }
931
- if (message.primaryTerm !== 0n) {
932
- if (BigInt.asIntN(64, message.primaryTerm) !== message.primaryTerm) {
933
- throw new globalThis.Error("value provided for field message.primaryTerm of type int64 too large");
934
- }
935
- writer.uint32(72).int64(message.primaryTerm);
936
- }
937
- return writer;
938
- },
939
- decode(input, length) {
940
- const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
941
- const end = length === void 0 ? reader.len : reader.pos + length;
942
- const message = createBaseBatchPayload();
943
- while (reader.pos < end) {
944
- const tag = reader.uint32();
945
- switch (tag >>> 3) {
946
- case 1: {
947
- if (tag !== 10) {
948
- break;
949
- }
950
- message.sourceNodeId = reader.string();
951
- continue;
952
- }
953
- case 2: {
954
- if (tag !== 18) {
955
- break;
956
- }
957
- message.batchId = reader.string();
958
- continue;
959
- }
960
- case 3: {
961
- if (tag !== 24) {
962
- break;
963
- }
964
- message.fromSeq = reader.int64();
965
- continue;
966
- }
967
- case 4: {
968
- if (tag !== 32) {
969
- break;
970
- }
971
- message.toSeq = reader.int64();
972
- continue;
973
- }
974
- case 5: {
975
- if (tag !== 42) {
976
- break;
977
- }
978
- message.hlcRange = HlcRange.decode(reader, reader.uint32());
979
- continue;
980
- }
981
- case 6: {
982
- if (tag !== 50) {
983
- break;
984
- }
985
- message.changes.push(ReplicationChange.decode(reader, reader.uint32()));
986
- continue;
987
- }
988
- case 7: {
989
- if (tag !== 58) {
990
- break;
991
- }
992
- message.checksum = reader.string();
993
- continue;
994
- }
995
- case 8: {
996
- if (tag !== 66) {
997
- break;
998
- }
999
- message.groupId = reader.string();
1000
- continue;
1001
- }
1002
- case 9: {
1003
- if (tag !== 72) {
1004
- break;
1005
- }
1006
- message.primaryTerm = reader.int64();
1007
- continue;
1008
- }
1009
- }
1010
- if ((tag & 7) === 4 || tag === 0) {
1011
- break;
1012
- }
1013
- reader.skip(tag & 7);
1014
- }
1015
- return message;
1016
- },
1017
- fromJSON(object) {
1018
- return {
1019
- sourceNodeId: isSet(object.sourceNodeId) ? globalThis.String(object.sourceNodeId) : isSet(object.source_node_id) ? globalThis.String(object.source_node_id) : "",
1020
- batchId: isSet(object.batchId) ? globalThis.String(object.batchId) : isSet(object.batch_id) ? globalThis.String(object.batch_id) : "",
1021
- fromSeq: isSet(object.fromSeq) ? BigInt(object.fromSeq) : isSet(object.from_seq) ? BigInt(object.from_seq) : 0n,
1022
- toSeq: isSet(object.toSeq) ? BigInt(object.toSeq) : isSet(object.to_seq) ? BigInt(object.to_seq) : 0n,
1023
- hlcRange: isSet(object.hlcRange) ? HlcRange.fromJSON(object.hlcRange) : isSet(object.hlc_range) ? HlcRange.fromJSON(object.hlc_range) : void 0,
1024
- changes: globalThis.Array.isArray(object?.changes) ? object.changes.map((e) => ReplicationChange.fromJSON(e)) : [],
1025
- checksum: isSet(object.checksum) ? globalThis.String(object.checksum) : "",
1026
- groupId: isSet(object.groupId) ? globalThis.String(object.groupId) : isSet(object.group_id) ? globalThis.String(object.group_id) : "",
1027
- primaryTerm: isSet(object.primaryTerm) ? BigInt(object.primaryTerm) : isSet(object.primary_term) ? BigInt(object.primary_term) : 0n
1028
- };
1029
- },
1030
- toJSON(message) {
1031
- const obj = {};
1032
- if (message.sourceNodeId !== "") {
1033
- obj.sourceNodeId = message.sourceNodeId;
1034
- }
1035
- if (message.batchId !== "") {
1036
- obj.batchId = message.batchId;
1037
- }
1038
- if (message.fromSeq !== 0n) {
1039
- obj.fromSeq = message.fromSeq.toString();
1040
- }
1041
- if (message.toSeq !== 0n) {
1042
- obj.toSeq = message.toSeq.toString();
1043
- }
1044
- if (message.hlcRange !== void 0) {
1045
- obj.hlcRange = HlcRange.toJSON(message.hlcRange);
1046
- }
1047
- if (message.changes?.length) {
1048
- obj.changes = message.changes.map((e) => ReplicationChange.toJSON(e));
1049
- }
1050
- if (message.checksum !== "") {
1051
- obj.checksum = message.checksum;
1052
- }
1053
- if (message.groupId !== "") {
1054
- obj.groupId = message.groupId;
1055
- }
1056
- if (message.primaryTerm !== 0n) {
1057
- obj.primaryTerm = message.primaryTerm.toString();
1058
- }
1059
- return obj;
1060
- },
1061
- create(base) {
1062
- return BatchPayload.fromPartial(base ?? {});
1063
- },
1064
- fromPartial(object) {
1065
- const message = createBaseBatchPayload();
1066
- message.sourceNodeId = object.sourceNodeId ?? "";
1067
- message.batchId = object.batchId ?? "";
1068
- message.fromSeq = object.fromSeq ?? 0n;
1069
- message.toSeq = object.toSeq ?? 0n;
1070
- message.hlcRange = object.hlcRange !== void 0 && object.hlcRange !== null ? HlcRange.fromPartial(object.hlcRange) : void 0;
1071
- message.changes = object.changes?.map((e) => ReplicationChange.fromPartial(e)) || [];
1072
- message.checksum = object.checksum ?? "";
1073
- message.groupId = object.groupId ?? "";
1074
- message.primaryTerm = object.primaryTerm ?? 0n;
1075
- return message;
1076
- }
1077
- };
1078
- function createBaseAckPayload() {
1079
- return { batchId: "", ackedSeq: 0n, nodeId: "", groupId: "", primaryTerm: 0n };
1080
- }
1081
- var AckPayload = {
1082
- encode(message, writer = new BinaryWriter()) {
1083
- if (message.batchId !== "") {
1084
- writer.uint32(10).string(message.batchId);
1085
- }
1086
- if (message.ackedSeq !== 0n) {
1087
- if (BigInt.asIntN(64, message.ackedSeq) !== message.ackedSeq) {
1088
- throw new globalThis.Error("value provided for field message.ackedSeq of type int64 too large");
1089
- }
1090
- writer.uint32(16).int64(message.ackedSeq);
1091
- }
1092
- if (message.nodeId !== "") {
1093
- writer.uint32(26).string(message.nodeId);
1094
- }
1095
- if (message.groupId !== "") {
1096
- writer.uint32(34).string(message.groupId);
1097
- }
1098
- if (message.primaryTerm !== 0n) {
1099
- if (BigInt.asIntN(64, message.primaryTerm) !== message.primaryTerm) {
1100
- throw new globalThis.Error("value provided for field message.primaryTerm of type int64 too large");
1101
- }
1102
- writer.uint32(40).int64(message.primaryTerm);
1103
- }
1104
- return writer;
1105
- },
1106
- decode(input, length) {
1107
- const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
1108
- const end = length === void 0 ? reader.len : reader.pos + length;
1109
- const message = createBaseAckPayload();
1110
- while (reader.pos < end) {
1111
- const tag = reader.uint32();
1112
- switch (tag >>> 3) {
1113
- case 1: {
1114
- if (tag !== 10) {
1115
- break;
1116
- }
1117
- message.batchId = reader.string();
1118
- continue;
1119
- }
1120
- case 2: {
1121
- if (tag !== 16) {
1122
- break;
1123
- }
1124
- message.ackedSeq = reader.int64();
1125
- continue;
1126
- }
1127
- case 3: {
1128
- if (tag !== 26) {
1129
- break;
1130
- }
1131
- message.nodeId = reader.string();
1132
- continue;
1133
- }
1134
- case 4: {
1135
- if (tag !== 34) {
1136
- break;
1137
- }
1138
- message.groupId = reader.string();
1139
- continue;
1140
- }
1141
- case 5: {
1142
- if (tag !== 40) {
1143
- break;
1144
- }
1145
- message.primaryTerm = reader.int64();
1146
- continue;
1147
- }
1148
- }
1149
- if ((tag & 7) === 4 || tag === 0) {
1150
- break;
1151
- }
1152
- reader.skip(tag & 7);
1153
- }
1154
- return message;
1155
- },
1156
- fromJSON(object) {
1157
- return {
1158
- batchId: isSet(object.batchId) ? globalThis.String(object.batchId) : isSet(object.batch_id) ? globalThis.String(object.batch_id) : "",
1159
- ackedSeq: isSet(object.ackedSeq) ? BigInt(object.ackedSeq) : isSet(object.acked_seq) ? BigInt(object.acked_seq) : 0n,
1160
- nodeId: isSet(object.nodeId) ? globalThis.String(object.nodeId) : isSet(object.node_id) ? globalThis.String(object.node_id) : "",
1161
- groupId: isSet(object.groupId) ? globalThis.String(object.groupId) : isSet(object.group_id) ? globalThis.String(object.group_id) : "",
1162
- primaryTerm: isSet(object.primaryTerm) ? BigInt(object.primaryTerm) : isSet(object.primary_term) ? BigInt(object.primary_term) : 0n
1163
- };
1164
- },
1165
- toJSON(message) {
1166
- const obj = {};
1167
- if (message.batchId !== "") {
1168
- obj.batchId = message.batchId;
1169
- }
1170
- if (message.ackedSeq !== 0n) {
1171
- obj.ackedSeq = message.ackedSeq.toString();
1172
- }
1173
- if (message.nodeId !== "") {
1174
- obj.nodeId = message.nodeId;
1175
- }
1176
- if (message.groupId !== "") {
1177
- obj.groupId = message.groupId;
1178
- }
1179
- if (message.primaryTerm !== 0n) {
1180
- obj.primaryTerm = message.primaryTerm.toString();
1181
- }
1182
- return obj;
1183
- },
1184
- create(base) {
1185
- return AckPayload.fromPartial(base ?? {});
1186
- },
1187
- fromPartial(object) {
1188
- const message = createBaseAckPayload();
1189
- message.batchId = object.batchId ?? "";
1190
- message.ackedSeq = object.ackedSeq ?? 0n;
1191
- message.nodeId = object.nodeId ?? "";
1192
- message.groupId = object.groupId ?? "";
1193
- message.primaryTerm = object.primaryTerm ?? 0n;
1194
- return message;
1195
- }
1196
- };
1197
- function createBaseHello() {
1198
- return { nodeId: "", role: "", groupId: "", primaryTerm: 0n, protocolVersion: "" };
1199
- }
1200
- var Hello = {
1201
- encode(message, writer = new BinaryWriter()) {
1202
- if (message.nodeId !== "") {
1203
- writer.uint32(10).string(message.nodeId);
1204
- }
1205
- if (message.role !== "") {
1206
- writer.uint32(18).string(message.role);
1207
- }
1208
- if (message.groupId !== "") {
1209
- writer.uint32(26).string(message.groupId);
1210
- }
1211
- if (message.primaryTerm !== 0n) {
1212
- if (BigInt.asIntN(64, message.primaryTerm) !== message.primaryTerm) {
1213
- throw new globalThis.Error("value provided for field message.primaryTerm of type int64 too large");
1214
- }
1215
- writer.uint32(32).int64(message.primaryTerm);
1216
- }
1217
- if (message.protocolVersion !== "") {
1218
- writer.uint32(42).string(message.protocolVersion);
1219
- }
1220
- return writer;
1221
- },
1222
- decode(input, length) {
1223
- const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
1224
- const end = length === void 0 ? reader.len : reader.pos + length;
1225
- const message = createBaseHello();
1226
- while (reader.pos < end) {
1227
- const tag = reader.uint32();
1228
- switch (tag >>> 3) {
1229
- case 1: {
1230
- if (tag !== 10) {
1231
- break;
1232
- }
1233
- message.nodeId = reader.string();
1234
- continue;
1235
- }
1236
- case 2: {
1237
- if (tag !== 18) {
1238
- break;
1239
- }
1240
- message.role = reader.string();
1241
- continue;
1242
- }
1243
- case 3: {
1244
- if (tag !== 26) {
1245
- break;
1246
- }
1247
- message.groupId = reader.string();
1248
- continue;
1249
- }
1250
- case 4: {
1251
- if (tag !== 32) {
1252
- break;
1253
- }
1254
- message.primaryTerm = reader.int64();
1255
- continue;
1256
- }
1257
- case 5: {
1258
- if (tag !== 42) {
1259
- break;
1260
- }
1261
- message.protocolVersion = reader.string();
1262
- continue;
1263
- }
1264
- }
1265
- if ((tag & 7) === 4 || tag === 0) {
1266
- break;
1267
- }
1268
- reader.skip(tag & 7);
1269
- }
1270
- return message;
1271
- },
1272
- fromJSON(object) {
1273
- return {
1274
- nodeId: isSet(object.nodeId) ? globalThis.String(object.nodeId) : isSet(object.node_id) ? globalThis.String(object.node_id) : "",
1275
- role: isSet(object.role) ? globalThis.String(object.role) : "",
1276
- groupId: isSet(object.groupId) ? globalThis.String(object.groupId) : isSet(object.group_id) ? globalThis.String(object.group_id) : "",
1277
- primaryTerm: isSet(object.primaryTerm) ? BigInt(object.primaryTerm) : isSet(object.primary_term) ? BigInt(object.primary_term) : 0n,
1278
- protocolVersion: isSet(object.protocolVersion) ? globalThis.String(object.protocolVersion) : isSet(object.protocol_version) ? globalThis.String(object.protocol_version) : ""
1279
- };
1280
- },
1281
- toJSON(message) {
1282
- const obj = {};
1283
- if (message.nodeId !== "") {
1284
- obj.nodeId = message.nodeId;
1285
- }
1286
- if (message.role !== "") {
1287
- obj.role = message.role;
1288
- }
1289
- if (message.groupId !== "") {
1290
- obj.groupId = message.groupId;
1291
- }
1292
- if (message.primaryTerm !== 0n) {
1293
- obj.primaryTerm = message.primaryTerm.toString();
1294
- }
1295
- if (message.protocolVersion !== "") {
1296
- obj.protocolVersion = message.protocolVersion;
1297
- }
1298
- return obj;
1299
- },
1300
- create(base) {
1301
- return Hello.fromPartial(base ?? {});
1302
- },
1303
- fromPartial(object) {
1304
- const message = createBaseHello();
1305
- message.nodeId = object.nodeId ?? "";
1306
- message.role = object.role ?? "";
1307
- message.groupId = object.groupId ?? "";
1308
- message.primaryTerm = object.primaryTerm ?? 0n;
1309
- message.protocolVersion = object.protocolVersion ?? "";
1310
- return message;
1311
- }
1312
- };
1313
- function createBaseReplicationMessage() {
1314
- return { hello: void 0, batch: void 0, ack: void 0 };
1315
- }
1316
- var ReplicationMessage = {
1317
- encode(message, writer = new BinaryWriter()) {
1318
- if (message.hello !== void 0) {
1319
- Hello.encode(message.hello, writer.uint32(10).fork()).join();
1320
- }
1321
- if (message.batch !== void 0) {
1322
- BatchPayload.encode(message.batch, writer.uint32(18).fork()).join();
1323
- }
1324
- if (message.ack !== void 0) {
1325
- AckPayload.encode(message.ack, writer.uint32(26).fork()).join();
1326
- }
1327
- return writer;
1328
- },
1329
- decode(input, length) {
1330
- const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
1331
- const end = length === void 0 ? reader.len : reader.pos + length;
1332
- const message = createBaseReplicationMessage();
1333
- while (reader.pos < end) {
1334
- const tag = reader.uint32();
1335
- switch (tag >>> 3) {
1336
- case 1: {
1337
- if (tag !== 10) {
1338
- break;
1339
- }
1340
- message.hello = Hello.decode(reader, reader.uint32());
1341
- continue;
1342
- }
1343
- case 2: {
1344
- if (tag !== 18) {
1345
- break;
1346
- }
1347
- message.batch = BatchPayload.decode(reader, reader.uint32());
1348
- continue;
1349
- }
1350
- case 3: {
1351
- if (tag !== 26) {
1352
- break;
1353
- }
1354
- message.ack = AckPayload.decode(reader, reader.uint32());
1355
- continue;
1356
- }
1357
- }
1358
- if ((tag & 7) === 4 || tag === 0) {
1359
- break;
1360
- }
1361
- reader.skip(tag & 7);
1362
- }
1363
- return message;
1364
- },
1365
- fromJSON(object) {
1366
- return {
1367
- hello: isSet(object.hello) ? Hello.fromJSON(object.hello) : void 0,
1368
- batch: isSet(object.batch) ? BatchPayload.fromJSON(object.batch) : void 0,
1369
- ack: isSet(object.ack) ? AckPayload.fromJSON(object.ack) : void 0
1370
- };
1371
- },
1372
- toJSON(message) {
1373
- const obj = {};
1374
- if (message.hello !== void 0) {
1375
- obj.hello = Hello.toJSON(message.hello);
1376
- }
1377
- if (message.batch !== void 0) {
1378
- obj.batch = BatchPayload.toJSON(message.batch);
1379
- }
1380
- if (message.ack !== void 0) {
1381
- obj.ack = AckPayload.toJSON(message.ack);
1382
- }
1383
- return obj;
1384
- },
1385
- create(base) {
1386
- return ReplicationMessage.fromPartial(base ?? {});
1387
- },
1388
- fromPartial(object) {
1389
- const message = createBaseReplicationMessage();
1390
- message.hello = object.hello !== void 0 && object.hello !== null ? Hello.fromPartial(object.hello) : void 0;
1391
- message.batch = object.batch !== void 0 && object.batch !== null ? BatchPayload.fromPartial(object.batch) : void 0;
1392
- message.ack = object.ack !== void 0 && object.ack !== null ? AckPayload.fromPartial(object.ack) : void 0;
1393
- return message;
1394
- }
1395
- };
1396
- function createBaseSyncRequestPayload() {
1397
- return {
1398
- requestId: "",
1399
- joinerNodeId: "",
1400
- completedTables: [],
1401
- groupId: "",
1402
- primaryTerm: 0n,
1403
- supportsStreamVerification: false
1404
- };
1405
- }
1406
- var SyncRequestPayload = {
1407
- encode(message, writer = new BinaryWriter()) {
1408
- if (message.requestId !== "") {
1409
- writer.uint32(10).string(message.requestId);
1410
- }
1411
- if (message.joinerNodeId !== "") {
1412
- writer.uint32(18).string(message.joinerNodeId);
1413
- }
1414
- for (const v of message.completedTables) {
1415
- writer.uint32(26).string(v);
1416
- }
1417
- if (message.groupId !== "") {
1418
- writer.uint32(34).string(message.groupId);
1419
- }
1420
- if (message.primaryTerm !== 0n) {
1421
- if (BigInt.asIntN(64, message.primaryTerm) !== message.primaryTerm) {
1422
- throw new globalThis.Error("value provided for field message.primaryTerm of type int64 too large");
1423
- }
1424
- writer.uint32(40).int64(message.primaryTerm);
1425
- }
1426
- if (message.supportsStreamVerification !== false) {
1427
- writer.uint32(48).bool(message.supportsStreamVerification);
1428
- }
1429
- return writer;
1430
- },
1431
- decode(input, length) {
1432
- const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
1433
- const end = length === void 0 ? reader.len : reader.pos + length;
1434
- const message = createBaseSyncRequestPayload();
1435
- while (reader.pos < end) {
1436
- const tag = reader.uint32();
1437
- switch (tag >>> 3) {
1438
- case 1: {
1439
- if (tag !== 10) {
1440
- break;
1441
- }
1442
- message.requestId = reader.string();
1443
- continue;
1444
- }
1445
- case 2: {
1446
- if (tag !== 18) {
1447
- break;
1448
- }
1449
- message.joinerNodeId = reader.string();
1450
- continue;
1451
- }
1452
- case 3: {
1453
- if (tag !== 26) {
1454
- break;
1455
- }
1456
- message.completedTables.push(reader.string());
1457
- continue;
1458
- }
1459
- case 4: {
1460
- if (tag !== 34) {
1461
- break;
1462
- }
1463
- message.groupId = reader.string();
1464
- continue;
1465
- }
1466
- case 5: {
1467
- if (tag !== 40) {
1468
- break;
1469
- }
1470
- message.primaryTerm = reader.int64();
1471
- continue;
1472
- }
1473
- case 6: {
1474
- if (tag !== 48) {
1475
- break;
1476
- }
1477
- message.supportsStreamVerification = reader.bool();
1478
- continue;
1479
- }
1480
- }
1481
- if ((tag & 7) === 4 || tag === 0) {
1482
- break;
1483
- }
1484
- reader.skip(tag & 7);
1485
- }
1486
- return message;
1487
- },
1488
- fromJSON(object) {
1489
- return {
1490
- requestId: isSet(object.requestId) ? globalThis.String(object.requestId) : isSet(object.request_id) ? globalThis.String(object.request_id) : "",
1491
- joinerNodeId: isSet(object.joinerNodeId) ? globalThis.String(object.joinerNodeId) : isSet(object.joiner_node_id) ? globalThis.String(object.joiner_node_id) : "",
1492
- completedTables: globalThis.Array.isArray(object?.completedTables) ? object.completedTables.map((e) => globalThis.String(e)) : globalThis.Array.isArray(object?.completed_tables) ? object.completed_tables.map((e) => globalThis.String(e)) : [],
1493
- groupId: isSet(object.groupId) ? globalThis.String(object.groupId) : isSet(object.group_id) ? globalThis.String(object.group_id) : "",
1494
- primaryTerm: isSet(object.primaryTerm) ? BigInt(object.primaryTerm) : isSet(object.primary_term) ? BigInt(object.primary_term) : 0n,
1495
- supportsStreamVerification: isSet(object.supportsStreamVerification) ? globalThis.Boolean(object.supportsStreamVerification) : isSet(object.supports_stream_verification) ? globalThis.Boolean(object.supports_stream_verification) : false
1496
- };
1497
- },
1498
- toJSON(message) {
1499
- const obj = {};
1500
- if (message.requestId !== "") {
1501
- obj.requestId = message.requestId;
1502
- }
1503
- if (message.joinerNodeId !== "") {
1504
- obj.joinerNodeId = message.joinerNodeId;
1505
- }
1506
- if (message.completedTables?.length) {
1507
- obj.completedTables = message.completedTables;
1508
- }
1509
- if (message.groupId !== "") {
1510
- obj.groupId = message.groupId;
1511
- }
1512
- if (message.primaryTerm !== 0n) {
1513
- obj.primaryTerm = message.primaryTerm.toString();
1514
- }
1515
- if (message.supportsStreamVerification !== false) {
1516
- obj.supportsStreamVerification = message.supportsStreamVerification;
1517
- }
1518
- return obj;
1519
- },
1520
- create(base) {
1521
- return SyncRequestPayload.fromPartial(base ?? {});
1522
- },
1523
- fromPartial(object) {
1524
- const message = createBaseSyncRequestPayload();
1525
- message.requestId = object.requestId ?? "";
1526
- message.joinerNodeId = object.joinerNodeId ?? "";
1527
- message.completedTables = object.completedTables?.map((e) => e) || [];
1528
- message.groupId = object.groupId ?? "";
1529
- message.primaryTerm = object.primaryTerm ?? 0n;
1530
- message.supportsStreamVerification = object.supportsStreamVerification ?? false;
1531
- return message;
1532
- }
1533
- };
1534
- function createBaseSyncBatchPayload() {
1535
- return {
1536
- requestId: "",
1537
- table: "",
1538
- batchIndex: 0,
1539
- rows: [],
1540
- schema: [],
1541
- checksum: "",
1542
- isLastBatchForTable: false,
1543
- groupId: "",
1544
- primaryTerm: 0n,
1545
- totalTables: 0
1546
- };
1547
- }
1548
- var SyncBatchPayload = {
1549
- encode(message, writer = new BinaryWriter()) {
1550
- if (message.requestId !== "") {
1551
- writer.uint32(10).string(message.requestId);
1552
- }
1553
- if (message.table !== "") {
1554
- writer.uint32(18).string(message.table);
1555
- }
1556
- if (message.batchIndex !== 0) {
1557
- writer.uint32(24).int32(message.batchIndex);
1558
- }
1559
- for (const v of message.rows) {
1560
- RowData.encode(v, writer.uint32(34).fork()).join();
1561
- }
1562
- for (const v of message.schema) {
1563
- writer.uint32(42).string(v);
1564
- }
1565
- if (message.checksum !== "") {
1566
- writer.uint32(50).string(message.checksum);
1567
- }
1568
- if (message.isLastBatchForTable !== false) {
1569
- writer.uint32(56).bool(message.isLastBatchForTable);
1570
- }
1571
- if (message.groupId !== "") {
1572
- writer.uint32(66).string(message.groupId);
1573
- }
1574
- if (message.primaryTerm !== 0n) {
1575
- if (BigInt.asIntN(64, message.primaryTerm) !== message.primaryTerm) {
1576
- throw new globalThis.Error("value provided for field message.primaryTerm of type int64 too large");
1577
- }
1578
- writer.uint32(72).int64(message.primaryTerm);
1579
- }
1580
- if (message.totalTables !== 0) {
1581
- writer.uint32(80).int32(message.totalTables);
1582
- }
1583
- return writer;
1584
- },
1585
- decode(input, length) {
1586
- const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
1587
- const end = length === void 0 ? reader.len : reader.pos + length;
1588
- const message = createBaseSyncBatchPayload();
1589
- while (reader.pos < end) {
1590
- const tag = reader.uint32();
1591
- switch (tag >>> 3) {
1592
- case 1: {
1593
- if (tag !== 10) {
1594
- break;
1595
- }
1596
- message.requestId = reader.string();
1597
- continue;
1598
- }
1599
- case 2: {
1600
- if (tag !== 18) {
1601
- break;
1602
- }
1603
- message.table = reader.string();
1604
- continue;
1605
- }
1606
- case 3: {
1607
- if (tag !== 24) {
1608
- break;
1609
- }
1610
- message.batchIndex = reader.int32();
1611
- continue;
1612
- }
1613
- case 4: {
1614
- if (tag !== 34) {
1615
- break;
1616
- }
1617
- message.rows.push(RowData.decode(reader, reader.uint32()));
1618
- continue;
1619
- }
1620
- case 5: {
1621
- if (tag !== 42) {
1622
- break;
1623
- }
1624
- message.schema.push(reader.string());
1625
- continue;
1626
- }
1627
- case 6: {
1628
- if (tag !== 50) {
1629
- break;
1630
- }
1631
- message.checksum = reader.string();
1632
- continue;
1633
- }
1634
- case 7: {
1635
- if (tag !== 56) {
1636
- break;
1637
- }
1638
- message.isLastBatchForTable = reader.bool();
1639
- continue;
1640
- }
1641
- case 8: {
1642
- if (tag !== 66) {
1643
- break;
1644
- }
1645
- message.groupId = reader.string();
1646
- continue;
1647
- }
1648
- case 9: {
1649
- if (tag !== 72) {
1650
- break;
1651
- }
1652
- message.primaryTerm = reader.int64();
1653
- continue;
1654
- }
1655
- case 10: {
1656
- if (tag !== 80) {
1657
- break;
1658
- }
1659
- message.totalTables = reader.int32();
1660
- continue;
1661
- }
1662
- }
1663
- if ((tag & 7) === 4 || tag === 0) {
1664
- break;
1665
- }
1666
- reader.skip(tag & 7);
1667
- }
1668
- return message;
1669
- },
1670
- fromJSON(object) {
1671
- return {
1672
- requestId: isSet(object.requestId) ? globalThis.String(object.requestId) : isSet(object.request_id) ? globalThis.String(object.request_id) : "",
1673
- table: isSet(object.table) ? globalThis.String(object.table) : "",
1674
- batchIndex: isSet(object.batchIndex) ? globalThis.Number(object.batchIndex) : isSet(object.batch_index) ? globalThis.Number(object.batch_index) : 0,
1675
- rows: globalThis.Array.isArray(object?.rows) ? object.rows.map((e) => RowData.fromJSON(e)) : [],
1676
- schema: globalThis.Array.isArray(object?.schema) ? object.schema.map((e) => globalThis.String(e)) : [],
1677
- checksum: isSet(object.checksum) ? globalThis.String(object.checksum) : "",
1678
- isLastBatchForTable: isSet(object.isLastBatchForTable) ? globalThis.Boolean(object.isLastBatchForTable) : isSet(object.is_last_batch_for_table) ? globalThis.Boolean(object.is_last_batch_for_table) : false,
1679
- groupId: isSet(object.groupId) ? globalThis.String(object.groupId) : isSet(object.group_id) ? globalThis.String(object.group_id) : "",
1680
- primaryTerm: isSet(object.primaryTerm) ? BigInt(object.primaryTerm) : isSet(object.primary_term) ? BigInt(object.primary_term) : 0n,
1681
- totalTables: isSet(object.totalTables) ? globalThis.Number(object.totalTables) : isSet(object.total_tables) ? globalThis.Number(object.total_tables) : 0
1682
- };
1683
- },
1684
- toJSON(message) {
1685
- const obj = {};
1686
- if (message.requestId !== "") {
1687
- obj.requestId = message.requestId;
1688
- }
1689
- if (message.table !== "") {
1690
- obj.table = message.table;
1691
- }
1692
- if (message.batchIndex !== 0) {
1693
- obj.batchIndex = Math.round(message.batchIndex);
1694
- }
1695
- if (message.rows?.length) {
1696
- obj.rows = message.rows.map((e) => RowData.toJSON(e));
1697
- }
1698
- if (message.schema?.length) {
1699
- obj.schema = message.schema;
1700
- }
1701
- if (message.checksum !== "") {
1702
- obj.checksum = message.checksum;
1703
- }
1704
- if (message.isLastBatchForTable !== false) {
1705
- obj.isLastBatchForTable = message.isLastBatchForTable;
1706
- }
1707
- if (message.groupId !== "") {
1708
- obj.groupId = message.groupId;
1709
- }
1710
- if (message.primaryTerm !== 0n) {
1711
- obj.primaryTerm = message.primaryTerm.toString();
1712
- }
1713
- if (message.totalTables !== 0) {
1714
- obj.totalTables = Math.round(message.totalTables);
1715
- }
1716
- return obj;
1717
- },
1718
- create(base) {
1719
- return SyncBatchPayload.fromPartial(base ?? {});
1720
- },
1721
- fromPartial(object) {
1722
- const message = createBaseSyncBatchPayload();
1723
- message.requestId = object.requestId ?? "";
1724
- message.table = object.table ?? "";
1725
- message.batchIndex = object.batchIndex ?? 0;
1726
- message.rows = object.rows?.map((e) => RowData.fromPartial(e)) || [];
1727
- message.schema = object.schema?.map((e) => e) || [];
1728
- message.checksum = object.checksum ?? "";
1729
- message.isLastBatchForTable = object.isLastBatchForTable ?? false;
1730
- message.groupId = object.groupId ?? "";
1731
- message.primaryTerm = object.primaryTerm ?? 0n;
1732
- message.totalTables = object.totalTables ?? 0;
1733
- return message;
1734
- }
1735
- };
1736
- function createBaseSyncCompletePayload() {
1737
- return { requestId: "", snapshotSeq: 0n, manifests: [], groupId: "", primaryTerm: 0n };
1738
- }
1739
- var SyncCompletePayload = {
1740
- encode(message, writer = new BinaryWriter()) {
1741
- if (message.requestId !== "") {
1742
- writer.uint32(10).string(message.requestId);
1743
- }
1744
- if (message.snapshotSeq !== 0n) {
1745
- if (BigInt.asIntN(64, message.snapshotSeq) !== message.snapshotSeq) {
1746
- throw new globalThis.Error("value provided for field message.snapshotSeq of type int64 too large");
1747
- }
1748
- writer.uint32(16).int64(message.snapshotSeq);
1749
- }
1750
- for (const v of message.manifests) {
1751
- SyncTableManifest.encode(v, writer.uint32(26).fork()).join();
1752
- }
1753
- if (message.groupId !== "") {
1754
- writer.uint32(34).string(message.groupId);
1755
- }
1756
- if (message.primaryTerm !== 0n) {
1757
- if (BigInt.asIntN(64, message.primaryTerm) !== message.primaryTerm) {
1758
- throw new globalThis.Error("value provided for field message.primaryTerm of type int64 too large");
1759
- }
1760
- writer.uint32(40).int64(message.primaryTerm);
1761
- }
1762
- return writer;
1763
- },
1764
- decode(input, length) {
1765
- const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
1766
- const end = length === void 0 ? reader.len : reader.pos + length;
1767
- const message = createBaseSyncCompletePayload();
1768
- while (reader.pos < end) {
1769
- const tag = reader.uint32();
1770
- switch (tag >>> 3) {
1771
- case 1: {
1772
- if (tag !== 10) {
1773
- break;
1774
- }
1775
- message.requestId = reader.string();
1776
- continue;
1777
- }
1778
- case 2: {
1779
- if (tag !== 16) {
1780
- break;
1781
- }
1782
- message.snapshotSeq = reader.int64();
1783
- continue;
1784
- }
1785
- case 3: {
1786
- if (tag !== 26) {
1787
- break;
1788
- }
1789
- message.manifests.push(SyncTableManifest.decode(reader, reader.uint32()));
1790
- continue;
1791
- }
1792
- case 4: {
1793
- if (tag !== 34) {
1794
- break;
1795
- }
1796
- message.groupId = reader.string();
1797
- continue;
1798
- }
1799
- case 5: {
1800
- if (tag !== 40) {
1801
- break;
1802
- }
1803
- message.primaryTerm = reader.int64();
1804
- continue;
1805
- }
1806
- }
1807
- if ((tag & 7) === 4 || tag === 0) {
1808
- break;
1809
- }
1810
- reader.skip(tag & 7);
1811
- }
1812
- return message;
1813
- },
1814
- fromJSON(object) {
1815
- return {
1816
- requestId: isSet(object.requestId) ? globalThis.String(object.requestId) : isSet(object.request_id) ? globalThis.String(object.request_id) : "",
1817
- snapshotSeq: isSet(object.snapshotSeq) ? BigInt(object.snapshotSeq) : isSet(object.snapshot_seq) ? BigInt(object.snapshot_seq) : 0n,
1818
- manifests: globalThis.Array.isArray(object?.manifests) ? object.manifests.map((e) => SyncTableManifest.fromJSON(e)) : [],
1819
- groupId: isSet(object.groupId) ? globalThis.String(object.groupId) : isSet(object.group_id) ? globalThis.String(object.group_id) : "",
1820
- primaryTerm: isSet(object.primaryTerm) ? BigInt(object.primaryTerm) : isSet(object.primary_term) ? BigInt(object.primary_term) : 0n
1821
- };
1822
- },
1823
- toJSON(message) {
1824
- const obj = {};
1825
- if (message.requestId !== "") {
1826
- obj.requestId = message.requestId;
1827
- }
1828
- if (message.snapshotSeq !== 0n) {
1829
- obj.snapshotSeq = message.snapshotSeq.toString();
1830
- }
1831
- if (message.manifests?.length) {
1832
- obj.manifests = message.manifests.map((e) => SyncTableManifest.toJSON(e));
1833
- }
1834
- if (message.groupId !== "") {
1835
- obj.groupId = message.groupId;
1836
- }
1837
- if (message.primaryTerm !== 0n) {
1838
- obj.primaryTerm = message.primaryTerm.toString();
1839
- }
1840
- return obj;
1841
- },
1842
- create(base) {
1843
- return SyncCompletePayload.fromPartial(base ?? {});
1844
- },
1845
- fromPartial(object) {
1846
- const message = createBaseSyncCompletePayload();
1847
- message.requestId = object.requestId ?? "";
1848
- message.snapshotSeq = object.snapshotSeq ?? 0n;
1849
- message.manifests = object.manifests?.map((e) => SyncTableManifest.fromPartial(e)) || [];
1850
- message.groupId = object.groupId ?? "";
1851
- message.primaryTerm = object.primaryTerm ?? 0n;
1852
- return message;
1853
- }
1854
- };
1855
- function createBaseSyncTableManifest() {
1856
- return { table: "", rowCount: 0, pkHash: "", batchDigest: "" };
1857
- }
1858
- var SyncTableManifest = {
1859
- encode(message, writer = new BinaryWriter()) {
1860
- if (message.table !== "") {
1861
- writer.uint32(10).string(message.table);
1862
- }
1863
- if (message.rowCount !== 0) {
1864
- writer.uint32(16).int32(message.rowCount);
1865
- }
1866
- if (message.pkHash !== "") {
1867
- writer.uint32(26).string(message.pkHash);
1868
- }
1869
- if (message.batchDigest !== "") {
1870
- writer.uint32(34).string(message.batchDigest);
1871
- }
1872
- return writer;
1873
- },
1874
- decode(input, length) {
1875
- const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
1876
- const end = length === void 0 ? reader.len : reader.pos + length;
1877
- const message = createBaseSyncTableManifest();
1878
- while (reader.pos < end) {
1879
- const tag = reader.uint32();
1880
- switch (tag >>> 3) {
1881
- case 1: {
1882
- if (tag !== 10) {
1883
- break;
1884
- }
1885
- message.table = reader.string();
1886
- continue;
1887
- }
1888
- case 2: {
1889
- if (tag !== 16) {
1890
- break;
1891
- }
1892
- message.rowCount = reader.int32();
1893
- continue;
1894
- }
1895
- case 3: {
1896
- if (tag !== 26) {
1897
- break;
1898
- }
1899
- message.pkHash = reader.string();
1900
- continue;
1901
- }
1902
- case 4: {
1903
- if (tag !== 34) {
1904
- break;
1905
- }
1906
- message.batchDigest = reader.string();
1907
- continue;
1908
- }
1909
- }
1910
- if ((tag & 7) === 4 || tag === 0) {
1911
- break;
1912
- }
1913
- reader.skip(tag & 7);
1914
- }
1915
- return message;
1916
- },
1917
- fromJSON(object) {
1918
- return {
1919
- table: isSet(object.table) ? globalThis.String(object.table) : "",
1920
- rowCount: isSet(object.rowCount) ? globalThis.Number(object.rowCount) : isSet(object.row_count) ? globalThis.Number(object.row_count) : 0,
1921
- pkHash: isSet(object.pkHash) ? globalThis.String(object.pkHash) : isSet(object.pk_hash) ? globalThis.String(object.pk_hash) : "",
1922
- batchDigest: isSet(object.batchDigest) ? globalThis.String(object.batchDigest) : isSet(object.batch_digest) ? globalThis.String(object.batch_digest) : ""
1923
- };
1924
- },
1925
- toJSON(message) {
1926
- const obj = {};
1927
- if (message.table !== "") {
1928
- obj.table = message.table;
1929
- }
1930
- if (message.rowCount !== 0) {
1931
- obj.rowCount = Math.round(message.rowCount);
1932
- }
1933
- if (message.pkHash !== "") {
1934
- obj.pkHash = message.pkHash;
1935
- }
1936
- if (message.batchDigest !== "") {
1937
- obj.batchDigest = message.batchDigest;
1938
- }
1939
- return obj;
1940
- },
1941
- create(base) {
1942
- return SyncTableManifest.fromPartial(base ?? {});
1943
- },
1944
- fromPartial(object) {
1945
- const message = createBaseSyncTableManifest();
1946
- message.table = object.table ?? "";
1947
- message.rowCount = object.rowCount ?? 0;
1948
- message.pkHash = object.pkHash ?? "";
1949
- message.batchDigest = object.batchDigest ?? "";
1950
- return message;
1951
- }
1952
- };
1953
- function createBaseSyncAckPayload() {
1954
- return {
1955
- requestId: "",
1956
- joinerNodeId: "",
1957
- table: "",
1958
- batchIndex: 0,
1959
- success: false,
1960
- error: "",
1961
- groupId: "",
1962
- primaryTerm: 0n
1963
- };
1964
- }
1965
- var SyncAckPayload = {
1966
- encode(message, writer = new BinaryWriter()) {
1967
- if (message.requestId !== "") {
1968
- writer.uint32(10).string(message.requestId);
1969
- }
1970
- if (message.joinerNodeId !== "") {
1971
- writer.uint32(18).string(message.joinerNodeId);
1972
- }
1973
- if (message.table !== "") {
1974
- writer.uint32(26).string(message.table);
1975
- }
1976
- if (message.batchIndex !== 0) {
1977
- writer.uint32(32).int32(message.batchIndex);
1978
- }
1979
- if (message.success !== false) {
1980
- writer.uint32(40).bool(message.success);
1981
- }
1982
- if (message.error !== "") {
1983
- writer.uint32(50).string(message.error);
1984
- }
1985
- if (message.groupId !== "") {
1986
- writer.uint32(58).string(message.groupId);
1987
- }
1988
- if (message.primaryTerm !== 0n) {
1989
- if (BigInt.asIntN(64, message.primaryTerm) !== message.primaryTerm) {
1990
- throw new globalThis.Error("value provided for field message.primaryTerm of type int64 too large");
1991
- }
1992
- writer.uint32(64).int64(message.primaryTerm);
1993
- }
1994
- return writer;
1995
- },
1996
- decode(input, length) {
1997
- const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
1998
- const end = length === void 0 ? reader.len : reader.pos + length;
1999
- const message = createBaseSyncAckPayload();
2000
- while (reader.pos < end) {
2001
- const tag = reader.uint32();
2002
- switch (tag >>> 3) {
2003
- case 1: {
2004
- if (tag !== 10) {
2005
- break;
2006
- }
2007
- message.requestId = reader.string();
2008
- continue;
2009
- }
2010
- case 2: {
2011
- if (tag !== 18) {
2012
- break;
2013
- }
2014
- message.joinerNodeId = reader.string();
2015
- continue;
2016
- }
2017
- case 3: {
2018
- if (tag !== 26) {
2019
- break;
2020
- }
2021
- message.table = reader.string();
2022
- continue;
2023
- }
2024
- case 4: {
2025
- if (tag !== 32) {
2026
- break;
2027
- }
2028
- message.batchIndex = reader.int32();
2029
- continue;
2030
- }
2031
- case 5: {
2032
- if (tag !== 40) {
2033
- break;
2034
- }
2035
- message.success = reader.bool();
2036
- continue;
2037
- }
2038
- case 6: {
2039
- if (tag !== 50) {
2040
- break;
2041
- }
2042
- message.error = reader.string();
2043
- continue;
2044
- }
2045
- case 7: {
2046
- if (tag !== 58) {
2047
- break;
2048
- }
2049
- message.groupId = reader.string();
2050
- continue;
2051
- }
2052
- case 8: {
2053
- if (tag !== 64) {
2054
- break;
2055
- }
2056
- message.primaryTerm = reader.int64();
2057
- continue;
2058
- }
2059
- }
2060
- if ((tag & 7) === 4 || tag === 0) {
2061
- break;
2062
- }
2063
- reader.skip(tag & 7);
2064
- }
2065
- return message;
2066
- },
2067
- fromJSON(object) {
2068
- return {
2069
- requestId: isSet(object.requestId) ? globalThis.String(object.requestId) : isSet(object.request_id) ? globalThis.String(object.request_id) : "",
2070
- joinerNodeId: isSet(object.joinerNodeId) ? globalThis.String(object.joinerNodeId) : isSet(object.joiner_node_id) ? globalThis.String(object.joiner_node_id) : "",
2071
- table: isSet(object.table) ? globalThis.String(object.table) : "",
2072
- batchIndex: isSet(object.batchIndex) ? globalThis.Number(object.batchIndex) : isSet(object.batch_index) ? globalThis.Number(object.batch_index) : 0,
2073
- success: isSet(object.success) ? globalThis.Boolean(object.success) : false,
2074
- error: isSet(object.error) ? globalThis.String(object.error) : "",
2075
- groupId: isSet(object.groupId) ? globalThis.String(object.groupId) : isSet(object.group_id) ? globalThis.String(object.group_id) : "",
2076
- primaryTerm: isSet(object.primaryTerm) ? BigInt(object.primaryTerm) : isSet(object.primary_term) ? BigInt(object.primary_term) : 0n
2077
- };
2078
- },
2079
- toJSON(message) {
2080
- const obj = {};
2081
- if (message.requestId !== "") {
2082
- obj.requestId = message.requestId;
2083
- }
2084
- if (message.joinerNodeId !== "") {
2085
- obj.joinerNodeId = message.joinerNodeId;
2086
- }
2087
- if (message.table !== "") {
2088
- obj.table = message.table;
2089
- }
2090
- if (message.batchIndex !== 0) {
2091
- obj.batchIndex = Math.round(message.batchIndex);
2092
- }
2093
- if (message.success !== false) {
2094
- obj.success = message.success;
2095
- }
2096
- if (message.error !== "") {
2097
- obj.error = message.error;
2098
- }
2099
- if (message.groupId !== "") {
2100
- obj.groupId = message.groupId;
2101
- }
2102
- if (message.primaryTerm !== 0n) {
2103
- obj.primaryTerm = message.primaryTerm.toString();
2104
- }
2105
- return obj;
2106
- },
2107
- create(base) {
2108
- return SyncAckPayload.fromPartial(base ?? {});
2109
- },
2110
- fromPartial(object) {
2111
- const message = createBaseSyncAckPayload();
2112
- message.requestId = object.requestId ?? "";
2113
- message.joinerNodeId = object.joinerNodeId ?? "";
2114
- message.table = object.table ?? "";
2115
- message.batchIndex = object.batchIndex ?? 0;
2116
- message.success = object.success ?? false;
2117
- message.error = object.error ?? "";
2118
- message.groupId = object.groupId ?? "";
2119
- message.primaryTerm = object.primaryTerm ?? 0n;
2120
- return message;
2121
- }
2122
- };
2123
- function createBaseSyncMessage() {
11
+ // src/transport/grpc/loader.ts
12
+ var GRPC_INSTALL_COMMAND = "pnpm add -E @grpc/grpc-js @bufbuild/protobuf grpc-health-check";
13
+ function grpcDependency(packageName) {
2124
14
  return {
2125
- hello: void 0,
2126
- syncRequest: void 0,
2127
- syncBatch: void 0,
2128
- syncComplete: void 0,
2129
- syncAck: void 0
2130
- };
2131
- }
2132
- var SyncMessage = {
2133
- encode(message, writer = new BinaryWriter()) {
2134
- if (message.hello !== void 0) {
2135
- Hello.encode(message.hello, writer.uint32(10).fork()).join();
2136
- }
2137
- if (message.syncRequest !== void 0) {
2138
- SyncRequestPayload.encode(message.syncRequest, writer.uint32(18).fork()).join();
2139
- }
2140
- if (message.syncBatch !== void 0) {
2141
- SyncBatchPayload.encode(message.syncBatch, writer.uint32(26).fork()).join();
2142
- }
2143
- if (message.syncComplete !== void 0) {
2144
- SyncCompletePayload.encode(message.syncComplete, writer.uint32(34).fork()).join();
2145
- }
2146
- if (message.syncAck !== void 0) {
2147
- SyncAckPayload.encode(message.syncAck, writer.uint32(42).fork()).join();
2148
- }
2149
- return writer;
2150
- },
2151
- decode(input, length) {
2152
- const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
2153
- const end = length === void 0 ? reader.len : reader.pos + length;
2154
- const message = createBaseSyncMessage();
2155
- while (reader.pos < end) {
2156
- const tag = reader.uint32();
2157
- switch (tag >>> 3) {
2158
- case 1: {
2159
- if (tag !== 10) {
2160
- break;
2161
- }
2162
- message.hello = Hello.decode(reader, reader.uint32());
2163
- continue;
2164
- }
2165
- case 2: {
2166
- if (tag !== 18) {
2167
- break;
2168
- }
2169
- message.syncRequest = SyncRequestPayload.decode(reader, reader.uint32());
2170
- continue;
2171
- }
2172
- case 3: {
2173
- if (tag !== 26) {
2174
- break;
2175
- }
2176
- message.syncBatch = SyncBatchPayload.decode(reader, reader.uint32());
2177
- continue;
2178
- }
2179
- case 4: {
2180
- if (tag !== 34) {
2181
- break;
2182
- }
2183
- message.syncComplete = SyncCompletePayload.decode(reader, reader.uint32());
2184
- continue;
2185
- }
2186
- case 5: {
2187
- if (tag !== 42) {
2188
- break;
2189
- }
2190
- message.syncAck = SyncAckPayload.decode(reader, reader.uint32());
2191
- continue;
2192
- }
2193
- }
2194
- if ((tag & 7) === 4 || tag === 0) {
2195
- break;
2196
- }
2197
- reader.skip(tag & 7);
2198
- }
2199
- return message;
2200
- },
2201
- fromJSON(object) {
2202
- return {
2203
- hello: isSet(object.hello) ? Hello.fromJSON(object.hello) : void 0,
2204
- syncRequest: isSet(object.syncRequest) ? SyncRequestPayload.fromJSON(object.syncRequest) : isSet(object.sync_request) ? SyncRequestPayload.fromJSON(object.sync_request) : void 0,
2205
- syncBatch: isSet(object.syncBatch) ? SyncBatchPayload.fromJSON(object.syncBatch) : isSet(object.sync_batch) ? SyncBatchPayload.fromJSON(object.sync_batch) : void 0,
2206
- syncComplete: isSet(object.syncComplete) ? SyncCompletePayload.fromJSON(object.syncComplete) : isSet(object.sync_complete) ? SyncCompletePayload.fromJSON(object.sync_complete) : void 0,
2207
- syncAck: isSet(object.syncAck) ? SyncAckPayload.fromJSON(object.syncAck) : isSet(object.sync_ack) ? SyncAckPayload.fromJSON(object.sync_ack) : void 0
2208
- };
2209
- },
2210
- toJSON(message) {
2211
- const obj = {};
2212
- if (message.hello !== void 0) {
2213
- obj.hello = Hello.toJSON(message.hello);
2214
- }
2215
- if (message.syncRequest !== void 0) {
2216
- obj.syncRequest = SyncRequestPayload.toJSON(message.syncRequest);
2217
- }
2218
- if (message.syncBatch !== void 0) {
2219
- obj.syncBatch = SyncBatchPayload.toJSON(message.syncBatch);
2220
- }
2221
- if (message.syncComplete !== void 0) {
2222
- obj.syncComplete = SyncCompletePayload.toJSON(message.syncComplete);
2223
- }
2224
- if (message.syncAck !== void 0) {
2225
- obj.syncAck = SyncAckPayload.toJSON(message.syncAck);
2226
- }
2227
- return obj;
2228
- },
2229
- create(base) {
2230
- return SyncMessage.fromPartial(base ?? {});
2231
- },
2232
- fromPartial(object) {
2233
- const message = createBaseSyncMessage();
2234
- message.hello = object.hello !== void 0 && object.hello !== null ? Hello.fromPartial(object.hello) : void 0;
2235
- message.syncRequest = object.syncRequest !== void 0 && object.syncRequest !== null ? SyncRequestPayload.fromPartial(object.syncRequest) : void 0;
2236
- message.syncBatch = object.syncBatch !== void 0 && object.syncBatch !== null ? SyncBatchPayload.fromPartial(object.syncBatch) : void 0;
2237
- message.syncComplete = object.syncComplete !== void 0 && object.syncComplete !== null ? SyncCompletePayload.fromPartial(object.syncComplete) : void 0;
2238
- message.syncAck = object.syncAck !== void 0 && object.syncAck !== null ? SyncAckPayload.fromPartial(object.syncAck) : void 0;
2239
- return message;
2240
- }
2241
- };
2242
- function createBaseStatement() {
2243
- return { sql: "", namedParams: {}, positionalParams: [] };
2244
- }
2245
- var Statement = {
2246
- encode(message, writer = new BinaryWriter()) {
2247
- if (message.sql !== "") {
2248
- writer.uint32(10).string(message.sql);
2249
- }
2250
- globalThis.Object.entries(message.namedParams).forEach(([key, value]) => {
2251
- Statement_NamedParamsEntry.encode({ key, value }, writer.uint32(18).fork()).join();
2252
- });
2253
- for (const v of message.positionalParams) {
2254
- ColumnValue.encode(v, writer.uint32(26).fork()).join();
2255
- }
2256
- return writer;
2257
- },
2258
- decode(input, length) {
2259
- const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
2260
- const end = length === void 0 ? reader.len : reader.pos + length;
2261
- const message = createBaseStatement();
2262
- while (reader.pos < end) {
2263
- const tag = reader.uint32();
2264
- switch (tag >>> 3) {
2265
- case 1: {
2266
- if (tag !== 10) {
2267
- break;
2268
- }
2269
- message.sql = reader.string();
2270
- continue;
2271
- }
2272
- case 2: {
2273
- if (tag !== 18) {
2274
- break;
2275
- }
2276
- const entry2 = Statement_NamedParamsEntry.decode(reader, reader.uint32());
2277
- if (entry2.value !== void 0) {
2278
- message.namedParams[entry2.key] = entry2.value;
2279
- }
2280
- continue;
2281
- }
2282
- case 3: {
2283
- if (tag !== 26) {
2284
- break;
2285
- }
2286
- message.positionalParams.push(ColumnValue.decode(reader, reader.uint32()));
2287
- continue;
2288
- }
2289
- }
2290
- if ((tag & 7) === 4 || tag === 0) {
2291
- break;
2292
- }
2293
- reader.skip(tag & 7);
2294
- }
2295
- return message;
2296
- },
2297
- fromJSON(object) {
2298
- return {
2299
- sql: isSet(object.sql) ? globalThis.String(object.sql) : "",
2300
- namedParams: isObject(object.namedParams) ? globalThis.Object.entries(object.namedParams).reduce(
2301
- (acc, [key, value]) => {
2302
- acc[key] = ColumnValue.fromJSON(value);
2303
- return acc;
2304
- },
2305
- {}
2306
- ) : isObject(object.named_params) ? globalThis.Object.entries(object.named_params).reduce(
2307
- (acc, [key, value]) => {
2308
- acc[key] = ColumnValue.fromJSON(value);
2309
- return acc;
2310
- },
2311
- {}
2312
- ) : {},
2313
- positionalParams: globalThis.Array.isArray(object?.positionalParams) ? object.positionalParams.map((e) => ColumnValue.fromJSON(e)) : globalThis.Array.isArray(object?.positional_params) ? object.positional_params.map((e) => ColumnValue.fromJSON(e)) : []
2314
- };
2315
- },
2316
- toJSON(message) {
2317
- const obj = {};
2318
- if (message.sql !== "") {
2319
- obj.sql = message.sql;
2320
- }
2321
- if (message.namedParams) {
2322
- const entries = globalThis.Object.entries(message.namedParams);
2323
- if (entries.length > 0) {
2324
- obj.namedParams = {};
2325
- entries.forEach(([k, v]) => {
2326
- obj.namedParams[k] = ColumnValue.toJSON(v);
2327
- });
2328
- }
2329
- }
2330
- if (message.positionalParams?.length) {
2331
- obj.positionalParams = message.positionalParams.map((e) => ColumnValue.toJSON(e));
2332
- }
2333
- return obj;
2334
- },
2335
- create(base) {
2336
- return Statement.fromPartial(base ?? {});
2337
- },
2338
- fromPartial(object) {
2339
- const message = createBaseStatement();
2340
- message.sql = object.sql ?? "";
2341
- message.namedParams = globalThis.Object.entries(object.namedParams ?? {}).reduce(
2342
- (acc, [key, value]) => {
2343
- if (value !== void 0) {
2344
- acc[key] = ColumnValue.fromPartial(value);
2345
- }
2346
- return acc;
2347
- },
2348
- {}
2349
- );
2350
- message.positionalParams = object.positionalParams?.map((e) => ColumnValue.fromPartial(e)) || [];
2351
- return message;
2352
- }
2353
- };
2354
- function createBaseStatement_NamedParamsEntry() {
2355
- return { key: "", value: void 0 };
2356
- }
2357
- var Statement_NamedParamsEntry = {
2358
- encode(message, writer = new BinaryWriter()) {
2359
- if (message.key !== "") {
2360
- writer.uint32(10).string(message.key);
2361
- }
2362
- if (message.value !== void 0) {
2363
- ColumnValue.encode(message.value, writer.uint32(18).fork()).join();
2364
- }
2365
- return writer;
2366
- },
2367
- decode(input, length) {
2368
- const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
2369
- const end = length === void 0 ? reader.len : reader.pos + length;
2370
- const message = createBaseStatement_NamedParamsEntry();
2371
- while (reader.pos < end) {
2372
- const tag = reader.uint32();
2373
- switch (tag >>> 3) {
2374
- case 1: {
2375
- if (tag !== 10) {
2376
- break;
2377
- }
2378
- message.key = reader.string();
2379
- continue;
2380
- }
2381
- case 2: {
2382
- if (tag !== 18) {
2383
- break;
2384
- }
2385
- message.value = ColumnValue.decode(reader, reader.uint32());
2386
- continue;
2387
- }
2388
- }
2389
- if ((tag & 7) === 4 || tag === 0) {
2390
- break;
2391
- }
2392
- reader.skip(tag & 7);
2393
- }
2394
- return message;
2395
- },
2396
- fromJSON(object) {
2397
- return {
2398
- key: isSet(object.key) ? globalThis.String(object.key) : "",
2399
- value: isSet(object.value) ? ColumnValue.fromJSON(object.value) : void 0
2400
- };
2401
- },
2402
- toJSON(message) {
2403
- const obj = {};
2404
- if (message.key !== "") {
2405
- obj.key = message.key;
2406
- }
2407
- if (message.value !== void 0) {
2408
- obj.value = ColumnValue.toJSON(message.value);
2409
- }
2410
- return obj;
2411
- },
2412
- create(base) {
2413
- return Statement_NamedParamsEntry.fromPartial(base ?? {});
2414
- },
2415
- fromPartial(object) {
2416
- const message = createBaseStatement_NamedParamsEntry();
2417
- message.key = object.key ?? "";
2418
- message.value = object.value !== void 0 && object.value !== null ? ColumnValue.fromPartial(object.value) : void 0;
2419
- return message;
2420
- }
2421
- };
2422
- function createBaseForwardRequest() {
2423
- return { requestId: "", statements: [], groupId: "", primaryTerm: 0n };
2424
- }
2425
- var ForwardRequest = {
2426
- encode(message, writer = new BinaryWriter()) {
2427
- if (message.requestId !== "") {
2428
- writer.uint32(10).string(message.requestId);
2429
- }
2430
- for (const v of message.statements) {
2431
- Statement.encode(v, writer.uint32(18).fork()).join();
2432
- }
2433
- if (message.groupId !== "") {
2434
- writer.uint32(26).string(message.groupId);
2435
- }
2436
- if (message.primaryTerm !== 0n) {
2437
- if (BigInt.asIntN(64, message.primaryTerm) !== message.primaryTerm) {
2438
- throw new globalThis.Error("value provided for field message.primaryTerm of type int64 too large");
2439
- }
2440
- writer.uint32(32).int64(message.primaryTerm);
2441
- }
2442
- return writer;
2443
- },
2444
- decode(input, length) {
2445
- const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
2446
- const end = length === void 0 ? reader.len : reader.pos + length;
2447
- const message = createBaseForwardRequest();
2448
- while (reader.pos < end) {
2449
- const tag = reader.uint32();
2450
- switch (tag >>> 3) {
2451
- case 1: {
2452
- if (tag !== 10) {
2453
- break;
2454
- }
2455
- message.requestId = reader.string();
2456
- continue;
2457
- }
2458
- case 2: {
2459
- if (tag !== 18) {
2460
- break;
2461
- }
2462
- message.statements.push(Statement.decode(reader, reader.uint32()));
2463
- continue;
2464
- }
2465
- case 3: {
2466
- if (tag !== 26) {
2467
- break;
2468
- }
2469
- message.groupId = reader.string();
2470
- continue;
2471
- }
2472
- case 4: {
2473
- if (tag !== 32) {
2474
- break;
2475
- }
2476
- message.primaryTerm = reader.int64();
2477
- continue;
2478
- }
2479
- }
2480
- if ((tag & 7) === 4 || tag === 0) {
2481
- break;
2482
- }
2483
- reader.skip(tag & 7);
2484
- }
2485
- return message;
2486
- },
2487
- fromJSON(object) {
2488
- return {
2489
- requestId: isSet(object.requestId) ? globalThis.String(object.requestId) : isSet(object.request_id) ? globalThis.String(object.request_id) : "",
2490
- statements: globalThis.Array.isArray(object?.statements) ? object.statements.map((e) => Statement.fromJSON(e)) : [],
2491
- groupId: isSet(object.groupId) ? globalThis.String(object.groupId) : isSet(object.group_id) ? globalThis.String(object.group_id) : "",
2492
- primaryTerm: isSet(object.primaryTerm) ? BigInt(object.primaryTerm) : isSet(object.primary_term) ? BigInt(object.primary_term) : 0n
2493
- };
2494
- },
2495
- toJSON(message) {
2496
- const obj = {};
2497
- if (message.requestId !== "") {
2498
- obj.requestId = message.requestId;
2499
- }
2500
- if (message.statements?.length) {
2501
- obj.statements = message.statements.map((e) => Statement.toJSON(e));
2502
- }
2503
- if (message.groupId !== "") {
2504
- obj.groupId = message.groupId;
2505
- }
2506
- if (message.primaryTerm !== 0n) {
2507
- obj.primaryTerm = message.primaryTerm.toString();
2508
- }
2509
- return obj;
2510
- },
2511
- create(base) {
2512
- return ForwardRequest.fromPartial(base ?? {});
2513
- },
2514
- fromPartial(object) {
2515
- const message = createBaseForwardRequest();
2516
- message.requestId = object.requestId ?? "";
2517
- message.statements = object.statements?.map((e) => Statement.fromPartial(e)) || [];
2518
- message.groupId = object.groupId ?? "";
2519
- message.primaryTerm = object.primaryTerm ?? 0n;
2520
- return message;
2521
- }
2522
- };
2523
- function createBaseStatementResult() {
2524
- return { changes: 0, lastInsertRowId: 0n };
2525
- }
2526
- var StatementResult = {
2527
- encode(message, writer = new BinaryWriter()) {
2528
- if (message.changes !== 0) {
2529
- writer.uint32(8).int32(message.changes);
2530
- }
2531
- if (message.lastInsertRowId !== 0n) {
2532
- if (BigInt.asIntN(64, message.lastInsertRowId) !== message.lastInsertRowId) {
2533
- throw new globalThis.Error("value provided for field message.lastInsertRowId of type int64 too large");
2534
- }
2535
- writer.uint32(16).int64(message.lastInsertRowId);
2536
- }
2537
- return writer;
2538
- },
2539
- decode(input, length) {
2540
- const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
2541
- const end = length === void 0 ? reader.len : reader.pos + length;
2542
- const message = createBaseStatementResult();
2543
- while (reader.pos < end) {
2544
- const tag = reader.uint32();
2545
- switch (tag >>> 3) {
2546
- case 1: {
2547
- if (tag !== 8) {
2548
- break;
2549
- }
2550
- message.changes = reader.int32();
2551
- continue;
2552
- }
2553
- case 2: {
2554
- if (tag !== 16) {
2555
- break;
2556
- }
2557
- message.lastInsertRowId = reader.int64();
2558
- continue;
2559
- }
2560
- }
2561
- if ((tag & 7) === 4 || tag === 0) {
2562
- break;
2563
- }
2564
- reader.skip(tag & 7);
2565
- }
2566
- return message;
2567
- },
2568
- fromJSON(object) {
2569
- return {
2570
- changes: isSet(object.changes) ? globalThis.Number(object.changes) : 0,
2571
- lastInsertRowId: isSet(object.lastInsertRowId) ? BigInt(object.lastInsertRowId) : isSet(object.last_insert_row_id) ? BigInt(object.last_insert_row_id) : 0n
2572
- };
2573
- },
2574
- toJSON(message) {
2575
- const obj = {};
2576
- if (message.changes !== 0) {
2577
- obj.changes = Math.round(message.changes);
2578
- }
2579
- if (message.lastInsertRowId !== 0n) {
2580
- obj.lastInsertRowId = message.lastInsertRowId.toString();
2581
- }
2582
- return obj;
2583
- },
2584
- create(base) {
2585
- return StatementResult.fromPartial(base ?? {});
2586
- },
2587
- fromPartial(object) {
2588
- const message = createBaseStatementResult();
2589
- message.changes = object.changes ?? 0;
2590
- message.lastInsertRowId = object.lastInsertRowId ?? 0n;
2591
- return message;
2592
- }
2593
- };
2594
- function createBaseForwardResponse() {
2595
- return { requestId: "", results: [], error: "", groupId: "", primaryTerm: 0n };
2596
- }
2597
- var ForwardResponse = {
2598
- encode(message, writer = new BinaryWriter()) {
2599
- if (message.requestId !== "") {
2600
- writer.uint32(10).string(message.requestId);
2601
- }
2602
- for (const v of message.results) {
2603
- StatementResult.encode(v, writer.uint32(18).fork()).join();
2604
- }
2605
- if (message.error !== "") {
2606
- writer.uint32(26).string(message.error);
2607
- }
2608
- if (message.groupId !== "") {
2609
- writer.uint32(34).string(message.groupId);
2610
- }
2611
- if (message.primaryTerm !== 0n) {
2612
- if (BigInt.asIntN(64, message.primaryTerm) !== message.primaryTerm) {
2613
- throw new globalThis.Error("value provided for field message.primaryTerm of type int64 too large");
2614
- }
2615
- writer.uint32(40).int64(message.primaryTerm);
2616
- }
2617
- return writer;
2618
- },
2619
- decode(input, length) {
2620
- const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
2621
- const end = length === void 0 ? reader.len : reader.pos + length;
2622
- const message = createBaseForwardResponse();
2623
- while (reader.pos < end) {
2624
- const tag = reader.uint32();
2625
- switch (tag >>> 3) {
2626
- case 1: {
2627
- if (tag !== 10) {
2628
- break;
2629
- }
2630
- message.requestId = reader.string();
2631
- continue;
2632
- }
2633
- case 2: {
2634
- if (tag !== 18) {
2635
- break;
2636
- }
2637
- message.results.push(StatementResult.decode(reader, reader.uint32()));
2638
- continue;
2639
- }
2640
- case 3: {
2641
- if (tag !== 26) {
2642
- break;
2643
- }
2644
- message.error = reader.string();
2645
- continue;
2646
- }
2647
- case 4: {
2648
- if (tag !== 34) {
2649
- break;
2650
- }
2651
- message.groupId = reader.string();
2652
- continue;
2653
- }
2654
- case 5: {
2655
- if (tag !== 40) {
2656
- break;
2657
- }
2658
- message.primaryTerm = reader.int64();
2659
- continue;
2660
- }
2661
- }
2662
- if ((tag & 7) === 4 || tag === 0) {
2663
- break;
2664
- }
2665
- reader.skip(tag & 7);
2666
- }
2667
- return message;
2668
- },
2669
- fromJSON(object) {
2670
- return {
2671
- requestId: isSet(object.requestId) ? globalThis.String(object.requestId) : isSet(object.request_id) ? globalThis.String(object.request_id) : "",
2672
- results: globalThis.Array.isArray(object?.results) ? object.results.map((e) => StatementResult.fromJSON(e)) : [],
2673
- error: isSet(object.error) ? globalThis.String(object.error) : "",
2674
- groupId: isSet(object.groupId) ? globalThis.String(object.groupId) : isSet(object.group_id) ? globalThis.String(object.group_id) : "",
2675
- primaryTerm: isSet(object.primaryTerm) ? BigInt(object.primaryTerm) : isSet(object.primary_term) ? BigInt(object.primary_term) : 0n
2676
- };
2677
- },
2678
- toJSON(message) {
2679
- const obj = {};
2680
- if (message.requestId !== "") {
2681
- obj.requestId = message.requestId;
2682
- }
2683
- if (message.results?.length) {
2684
- obj.results = message.results.map((e) => StatementResult.toJSON(e));
2685
- }
2686
- if (message.error !== "") {
2687
- obj.error = message.error;
2688
- }
2689
- if (message.groupId !== "") {
2690
- obj.groupId = message.groupId;
2691
- }
2692
- if (message.primaryTerm !== 0n) {
2693
- obj.primaryTerm = message.primaryTerm.toString();
2694
- }
2695
- return obj;
2696
- },
2697
- create(base) {
2698
- return ForwardResponse.fromPartial(base ?? {});
2699
- },
2700
- fromPartial(object) {
2701
- const message = createBaseForwardResponse();
2702
- message.requestId = object.requestId ?? "";
2703
- message.results = object.results?.map((e) => StatementResult.fromPartial(e)) || [];
2704
- message.error = object.error ?? "";
2705
- message.groupId = object.groupId ?? "";
2706
- message.primaryTerm = object.primaryTerm ?? 0n;
2707
- return message;
2708
- }
2709
- };
2710
- var ReplicationService = {
2711
- replicate: {
2712
- path: "/sirannon.replication.v1.Replication/Replicate",
2713
- requestStream: true,
2714
- responseStream: true,
2715
- requestSerialize: (value) => Buffer.from(ReplicationMessage.encode(value).finish()),
2716
- requestDeserialize: (value) => ReplicationMessage.decode(value),
2717
- responseSerialize: (value) => Buffer.from(ReplicationMessage.encode(value).finish()),
2718
- responseDeserialize: (value) => ReplicationMessage.decode(value)
2719
- },
2720
- sync: {
2721
- path: "/sirannon.replication.v1.Replication/Sync",
2722
- requestStream: true,
2723
- responseStream: true,
2724
- requestSerialize: (value) => Buffer.from(SyncMessage.encode(value).finish()),
2725
- requestDeserialize: (value) => SyncMessage.decode(value),
2726
- responseSerialize: (value) => Buffer.from(SyncMessage.encode(value).finish()),
2727
- responseDeserialize: (value) => SyncMessage.decode(value)
2728
- },
2729
- forward: {
2730
- path: "/sirannon.replication.v1.Replication/Forward",
2731
- requestStream: false,
2732
- responseStream: false,
2733
- requestSerialize: (value) => Buffer.from(ForwardRequest.encode(value).finish()),
2734
- requestDeserialize: (value) => ForwardRequest.decode(value),
2735
- responseSerialize: (value) => Buffer.from(ForwardResponse.encode(value).finish()),
2736
- responseDeserialize: (value) => ForwardResponse.decode(value)
2737
- }
2738
- };
2739
- var ReplicationClient = makeGenericClientConstructor(
2740
- ReplicationService,
2741
- "sirannon.replication.v1.Replication"
2742
- );
2743
- function bytesFromBase64(b64) {
2744
- return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
2745
- }
2746
- function base64FromBytes(arr) {
2747
- return globalThis.Buffer.from(arr).toString("base64");
2748
- }
2749
- function isObject(value) {
2750
- return typeof value === "object" && value !== null;
2751
- }
2752
- function isSet(value) {
2753
- return value !== null && value !== void 0;
2754
- }
2755
- function buildServerCreds(options) {
2756
- if (options.insecure) {
2757
- return ServerCredentials.createInsecure();
2758
- }
2759
- if (!options.tlsCert || !options.tlsKey) {
2760
- throw new TransportError("TLS certificate and key paths are required when insecure mode is disabled");
2761
- }
2762
- const cert = readFileSync(options.tlsCert);
2763
- const key = readFileSync(options.tlsKey);
2764
- const ca = options.tlsCaCert ? readFileSync(options.tlsCaCert) : null;
2765
- return ServerCredentials.createSsl(ca, [{ private_key: key, cert_chain: cert }], ca !== null);
2766
- }
2767
- function buildChannelCreds(options) {
2768
- if (options.insecure) {
2769
- return credentials.createInsecure();
2770
- }
2771
- if (!options.tlsCert || !options.tlsKey) {
2772
- throw new TransportError("TLS certificate and key paths are required when insecure mode is disabled");
2773
- }
2774
- const cert = readFileSync(options.tlsCert);
2775
- const key = readFileSync(options.tlsKey);
2776
- const ca = options.tlsCaCert ? readFileSync(options.tlsCaCert) : null;
2777
- return credentials.createSsl(ca, key, cert);
2778
- }
2779
-
2780
- // src/transport/grpc/peer-streams.ts
2781
- function replicateWriteStream(serverPeerStreams, clientPeerStreams, peerId) {
2782
- return serverPeerStreams.get(peerId)?.replicateStream ?? clientPeerStreams.get(peerId)?.replicateStream ?? null;
2783
- }
2784
- function syncWriteStream(serverPeerStreams, clientPeerStreams, peerId) {
2785
- return serverPeerStreams.get(peerId)?.syncStream ?? clientPeerStreams.get(peerId)?.syncStream ?? null;
2786
- }
2787
- function peerIdForServerStream(serverPeerStreams, entry) {
2788
- for (const [peerId, candidate] of serverPeerStreams) {
2789
- if (candidate === entry) return peerId;
2790
- }
2791
- return null;
2792
- }
2793
- function registerPeer(connectedPeers, peerConnectedHandler, nodeId, role, metadata = {}) {
2794
- if (connectedPeers.has(nodeId)) return;
2795
- const peerInfo = {
2796
- id: nodeId,
2797
- groupId: metadata.groupId,
2798
- role,
2799
- primaryTerm: metadata.primaryTerm,
2800
- protocolVersion: metadata.protocolVersion,
2801
- joinedAt: Date.now(),
2802
- lastSeenAt: Date.now(),
2803
- lastAckedSeq: 0n
15
+ packageName,
16
+ neededBy: "The gRPC replication transport",
17
+ installCommand: GRPC_INSTALL_COMMAND,
18
+ code: "TRANSPORT_DEPENDENCY_MISSING"
2804
19
  };
2805
- connectedPeers.set(nodeId, peerInfo);
2806
- peerConnectedHandler?.(peerInfo);
2807
- }
2808
- function removePeer(connectedPeers, serverPeerStreams, peerDisconnectedHandler, nodeId) {
2809
- if (!connectedPeers.has(nodeId)) return;
2810
- connectedPeers.delete(nodeId);
2811
- serverPeerStreams.delete(nodeId);
2812
- peerDisconnectedHandler?.(nodeId);
2813
20
  }
2814
-
2815
- // src/transport/grpc/client-streams.ts
2816
- function cancelQuietly(stream) {
21
+ async function requirePackage(packageName, load) {
2817
22
  try {
2818
- stream.cancel();
2819
- } catch {
2820
- }
2821
- }
2822
- function connectToEndpoint(t, endpoint) {
2823
- if (!t.connected) return;
2824
- if (!claimEndpoint(t, endpoint)) return;
2825
- const channelCreds = buildChannelCreds(t.options);
2826
- const clientOpts = {};
2827
- const client = new ReplicationClient(endpoint, channelCreds, clientOpts);
2828
- const replicateStream = client.replicate();
2829
- const syncStream = client.sync();
2830
- const entry = {
2831
- client,
2832
- replicateStream,
2833
- syncStream
2834
- };
2835
- let replicatePeerId = null;
2836
- let syncPeerId = null;
2837
- let closed = false;
2838
- const teardown = () => {
2839
- if (closed) return;
2840
- closed = true;
2841
- releaseEndpoint(t, endpoint);
2842
- const peerId = replicatePeerId ?? syncPeerId;
2843
- if (peerId !== null && t.clientPeerStreams.get(peerId) === entry) {
2844
- t.clientPeerStreams.delete(peerId);
2845
- removePeer(t.connectedPeers, t.serverPeerStreams, t.peerDisconnectedHandler, peerId);
2846
- }
2847
- entry.replicateStream = null;
2848
- entry.syncStream = null;
2849
- cancelQuietly(replicateStream);
2850
- cancelQuietly(syncStream);
2851
- client.close();
2852
- scheduleEndpointRedial(t, endpoint, () => {
2853
- connectToEndpoint(t, endpoint);
2854
- });
2855
- };
2856
- registerEndpointAbort(t, endpoint, teardown);
2857
- const hello = {
2858
- nodeId: t.localNodeId,
2859
- role: t.localRole,
2860
- groupId: t.localGroupId ?? "",
2861
- primaryTerm: t.localPrimaryTerm ?? 0n,
2862
- protocolVersion: t.localProtocolVersion ?? ""
23
+ await load();
24
+ } catch (err) {
25
+ throw optionalDependencyError(grpcDependency(packageName), err);
26
+ }
27
+ }
28
+ async function loadGrpcRuntime() {
29
+ await requirePackage("@grpc/grpc-js", () => import('@grpc/grpc-js'));
30
+ await requirePackage("@bufbuild/protobuf", () => import('@bufbuild/protobuf/wire'));
31
+ await requirePackage("grpc-health-check", () => import('grpc-health-check'));
32
+ const [serverStreams, clientStreams, forwardRpc] = await Promise.all([
33
+ import('../server-streams-24XL4T43.mjs'),
34
+ import('../client-streams-YKANXMWO.mjs'),
35
+ import('../forward-rpc-VRWFZXHN.mjs')
36
+ ]);
37
+ return {
38
+ startServer: serverStreams.startServer,
39
+ connectToEndpoint: clientStreams.connectToEndpoint,
40
+ forwardOverRpc: forwardRpc.forwardOverRpc
2863
41
  };
2864
- replicateStream.write({ hello });
2865
- syncStream.write({ hello });
2866
- replicateStream.on("data", (msg) => {
2867
- if (replicatePeerId === null) {
2868
- if (!msg.hello) {
2869
- teardown();
2870
- return;
2871
- }
2872
- replicatePeerId = msg.hello.nodeId;
2873
- const peerRole = msg.hello.role;
2874
- t.clientPeerStreams.set(replicatePeerId, entry);
2875
- noteEndpointReachable(t, endpoint);
2876
- registerPeer(t.connectedPeers, t.peerConnectedHandler, replicatePeerId, peerRole, {
2877
- groupId: msg.hello.groupId || void 0,
2878
- primaryTerm: msg.hello.primaryTerm === 0n ? void 0 : msg.hello.primaryTerm,
2879
- protocolVersion: msg.hello.protocolVersion || void 0
2880
- });
2881
- return;
2882
- }
2883
- if (msg.batch) {
2884
- t.batchHandler?.(fromBatchPayload(msg.batch), replicatePeerId).catch(() => {
2885
- });
2886
- } else if (msg.ack) {
2887
- t.ackHandler?.(fromAckPayload(msg.ack), replicatePeerId);
2888
- }
2889
- });
2890
- replicateStream.on("end", teardown);
2891
- replicateStream.on("error", teardown);
2892
- syncStream.on("data", (msg) => {
2893
- if (syncPeerId === null) {
2894
- if (!msg.hello) {
2895
- teardown();
2896
- return;
2897
- }
2898
- syncPeerId = msg.hello.nodeId;
2899
- return;
2900
- }
2901
- if (msg.syncRequest) {
2902
- t.syncRequestHandler?.(fromSyncRequestPayload(msg.syncRequest), syncPeerId).catch(() => {
2903
- });
2904
- } else if (msg.syncBatch) {
2905
- t.syncBatchHandler?.(fromSyncBatchPayload(msg.syncBatch), syncPeerId).catch(() => {
2906
- });
2907
- } else if (msg.syncComplete) {
2908
- t.syncCompleteHandler?.(fromSyncCompletePayload(msg.syncComplete), syncPeerId).catch(() => {
2909
- });
2910
- } else if (msg.syncAck) {
2911
- t.syncAckHandler?.(fromSyncAckPayload(msg.syncAck), syncPeerId);
2912
- }
2913
- });
2914
- syncStream.on("end", teardown);
2915
- syncStream.on("error", teardown);
2916
- }
2917
- function forwardOverRpc(entry, request, deadlineMs) {
2918
- const protoRequest = toForwardRequest(request);
2919
- const deadline = new Date(Date.now() + deadlineMs);
2920
- return new Promise((resolve, reject) => {
2921
- entry.client.forward(
2922
- protoRequest,
2923
- new Metadata(),
2924
- { deadline },
2925
- (err, response) => {
2926
- if (err) {
2927
- reject(new TransportError(`Forward RPC failed: ${err.message}`));
2928
- return;
2929
- }
2930
- if (!response) {
2931
- reject(new TransportError("Forward RPC returned empty response"));
2932
- return;
2933
- }
2934
- if (response.error) {
2935
- reject(new TransportError(`Forward RPC error: ${response.error}`));
2936
- return;
2937
- }
2938
- resolve({
2939
- requestId: response.requestId,
2940
- results: response.results.map((r) => ({
2941
- changes: r.changes,
2942
- lastInsertRowId: Number(r.lastInsertRowId)
2943
- })),
2944
- groupId: response.groupId || void 0,
2945
- primaryTerm: response.primaryTerm === 0n ? void 0 : response.primaryTerm
2946
- });
2947
- }
2948
- );
2949
- });
2950
42
  }
2951
43
 
2952
- // src/transport/grpc/options.ts
2953
- var DEFAULT_FORWARD_DEADLINE_MS = 3e4;
2954
- var SERVICE_NAME = "sirannon.replication.v1.Replication";
2955
- async function startServer(t) {
2956
- const server = new Server();
2957
- t.server = server;
2958
- const healthImpl = new HealthImplementation({
2959
- [SERVICE_NAME]: "SERVING",
2960
- "": "SERVING"
2961
- });
2962
- healthImpl.addToServer(server);
2963
- t.healthImpl = healthImpl;
2964
- server.addService(ReplicationService, {
2965
- replicate: (call) => {
2966
- handleServerReplicateStream(t, call);
2967
- },
2968
- sync: (call) => {
2969
- handleServerSyncStream(t, call);
2970
- },
2971
- forward: (call, callback) => {
2972
- handleForwardCall(t, call, callback);
2973
- }
2974
- });
2975
- const host = t.options.host ?? "0.0.0.0";
2976
- const port = t.options.port ?? 0;
2977
- const bindAddress = `${host}:${port}`;
2978
- const serverCreds = buildServerCreds(t.options);
2979
- await new Promise((resolve, reject) => {
2980
- server.bindAsync(bindAddress, serverCreds, (err, assignedPort) => {
2981
- if (err) {
2982
- reject(new TransportError(`Failed to bind gRPC server: ${err.message}`));
2983
- return;
2984
- }
2985
- t.boundPort = assignedPort;
44
+ // src/transport/grpc/server-shutdown.ts
45
+ var GRACEFUL_SHUTDOWN_DEADLINE_MS = 2e3;
46
+ function shutdownGrpcServer(server, deadlineMs = GRACEFUL_SHUTDOWN_DEADLINE_MS) {
47
+ return new Promise((resolve) => {
48
+ let settled = false;
49
+ const finish = () => {
50
+ if (settled) return;
51
+ settled = true;
52
+ clearTimeout(deadline);
2986
53
  resolve();
2987
- });
2988
- });
2989
- }
2990
- function handleServerReplicateStream(t, call) {
2991
- let peerId = null;
2992
- let helloSent = false;
2993
- call.on("data", (msg) => {
2994
- if (peerId === null) {
2995
- if (!msg.hello) {
2996
- call.destroy(new Error("First message must be Hello"));
2997
- return;
2998
- }
2999
- if (!t.validateTlsIdentity(call, msg.hello.nodeId)) {
3000
- call.destroy(new Error(`TLS certificate CN does not match claimed nodeId '${msg.hello.nodeId}'`));
3001
- return;
3002
- }
3003
- peerId = msg.hello.nodeId;
3004
- const peerRole = msg.hello.role;
3005
- const existing = t.serverPeerStreams.get(peerId);
3006
- if (existing?.replicateStream) {
3007
- existing.replicateStream.end();
3008
- }
3009
- const ps = t.serverPeerStreams.get(peerId) ?? {
3010
- replicateStream: null,
3011
- syncStream: null
3012
- };
3013
- ps.replicateStream = call;
3014
- t.serverPeerStreams.set(peerId, ps);
3015
- if (!helloSent) {
3016
- call.write({
3017
- hello: {
3018
- nodeId: t.localNodeId,
3019
- role: t.localRole,
3020
- groupId: t.localGroupId ?? "",
3021
- primaryTerm: t.localPrimaryTerm ?? 0n,
3022
- protocolVersion: t.localProtocolVersion ?? ""
3023
- }
3024
- });
3025
- helloSent = true;
3026
- }
3027
- registerPeer(t.connectedPeers, t.peerConnectedHandler, peerId, peerRole, {
3028
- groupId: msg.hello.groupId || void 0,
3029
- primaryTerm: msg.hello.primaryTerm === 0n ? void 0 : msg.hello.primaryTerm,
3030
- protocolVersion: msg.hello.protocolVersion || void 0
3031
- });
3032
- return;
3033
- }
3034
- if (msg.batch) {
3035
- const batch = fromBatchPayload(msg.batch);
3036
- t.batchHandler?.(batch, peerId).catch(() => {
3037
- });
3038
- } else if (msg.ack) {
3039
- const ack = fromAckPayload(msg.ack);
3040
- t.ackHandler?.(ack, peerId);
3041
- }
3042
- });
3043
- call.on("end", () => {
3044
- call.end();
3045
- if (peerId) {
3046
- const ps = t.serverPeerStreams.get(peerId);
3047
- if (ps?.replicateStream === call) {
3048
- ps.replicateStream = null;
3049
- }
3050
- if (!ps?.syncStream) {
3051
- removePeer(t.connectedPeers, t.serverPeerStreams, t.peerDisconnectedHandler, peerId);
3052
- }
3053
- }
3054
- });
3055
- call.on("error", () => {
3056
- if (peerId) {
3057
- const ps = t.serverPeerStreams.get(peerId);
3058
- if (ps?.replicateStream === call) {
3059
- ps.replicateStream = null;
3060
- }
3061
- if (!ps?.syncStream) {
3062
- removePeer(t.connectedPeers, t.serverPeerStreams, t.peerDisconnectedHandler, peerId);
3063
- }
3064
- }
3065
- });
3066
- }
3067
- function handleServerSyncStream(t, call) {
3068
- let peerId = null;
3069
- let helloSent = false;
3070
- call.on("data", (msg) => {
3071
- if (peerId === null) {
3072
- if (!msg.hello) {
3073
- call.destroy(new Error("First message must be Hello"));
3074
- return;
3075
- }
3076
- if (!t.validateTlsIdentity(call, msg.hello.nodeId)) {
3077
- call.destroy(new Error(`TLS certificate CN does not match claimed nodeId '${msg.hello.nodeId}'`));
3078
- return;
3079
- }
3080
- peerId = msg.hello.nodeId;
3081
- const peerRole = msg.hello.role;
3082
- const existing = t.serverPeerStreams.get(peerId);
3083
- if (existing?.syncStream) {
3084
- existing.syncStream.end();
3085
- }
3086
- const ps = t.serverPeerStreams.get(peerId) ?? {
3087
- replicateStream: null,
3088
- syncStream: null
3089
- };
3090
- ps.syncStream = call;
3091
- t.serverPeerStreams.set(peerId, ps);
3092
- if (!helloSent) {
3093
- call.write({
3094
- hello: {
3095
- nodeId: t.localNodeId,
3096
- role: t.localRole,
3097
- groupId: t.localGroupId ?? "",
3098
- primaryTerm: t.localPrimaryTerm ?? 0n,
3099
- protocolVersion: t.localProtocolVersion ?? ""
3100
- }
3101
- });
3102
- helloSent = true;
3103
- }
3104
- registerPeer(t.connectedPeers, t.peerConnectedHandler, peerId, peerRole, {
3105
- groupId: msg.hello.groupId || void 0,
3106
- primaryTerm: msg.hello.primaryTerm === 0n ? void 0 : msg.hello.primaryTerm,
3107
- protocolVersion: msg.hello.protocolVersion || void 0
3108
- });
3109
- return;
3110
- }
3111
- if (msg.syncRequest) {
3112
- t.syncRequestHandler?.(fromSyncRequestPayload(msg.syncRequest), peerId).catch(() => {
3113
- });
3114
- } else if (msg.syncBatch) {
3115
- t.syncBatchHandler?.(fromSyncBatchPayload(msg.syncBatch), peerId).catch(() => {
3116
- });
3117
- } else if (msg.syncComplete) {
3118
- t.syncCompleteHandler?.(fromSyncCompletePayload(msg.syncComplete), peerId).catch(() => {
3119
- });
3120
- } else if (msg.syncAck) {
3121
- t.syncAckHandler?.(fromSyncAckPayload(msg.syncAck), peerId);
3122
- }
3123
- });
3124
- call.on("end", () => {
3125
- call.end();
3126
- if (peerId) {
3127
- const ps = t.serverPeerStreams.get(peerId);
3128
- if (ps?.syncStream === call) {
3129
- ps.syncStream = null;
3130
- }
3131
- if (!ps?.replicateStream) {
3132
- removePeer(t.connectedPeers, t.serverPeerStreams, t.peerDisconnectedHandler, peerId);
3133
- }
3134
- }
3135
- });
3136
- call.on("error", () => {
3137
- if (peerId) {
3138
- const ps = t.serverPeerStreams.get(peerId);
3139
- if (ps?.syncStream === call) {
3140
- ps.syncStream = null;
3141
- }
3142
- if (!ps?.replicateStream) {
3143
- removePeer(t.connectedPeers, t.serverPeerStreams, t.peerDisconnectedHandler, peerId);
54
+ };
55
+ const deadline = setTimeout(() => {
56
+ server.forceShutdown();
57
+ finish();
58
+ }, deadlineMs);
59
+ server.tryShutdown((err) => {
60
+ if (err) {
61
+ server.forceShutdown();
3144
62
  }
3145
- }
3146
- });
3147
- }
3148
- function handleForwardCall(t, call, callback) {
3149
- if (!t.forwardHandler) {
3150
- callback({
3151
- code: status.UNIMPLEMENTED,
3152
- message: "Forward handler not registered"
3153
- });
3154
- return;
3155
- }
3156
- const peerId = t.resolveForwardPeerId(call);
3157
- if (!peerId) {
3158
- callback({
3159
- code: status.UNAUTHENTICATED,
3160
- message: "Forward request from unidentified peer"
3161
- });
3162
- return;
3163
- }
3164
- const appReq = fromForwardRequest(call.request);
3165
- t.forwardHandler(appReq, peerId).then((result) => {
3166
- callback(null, {
3167
- requestId: result.requestId,
3168
- results: result.results.map((r) => ({
3169
- changes: r.changes,
3170
- lastInsertRowId: BigInt(typeof r.lastInsertRowId === "string" ? r.lastInsertRowId : r.lastInsertRowId)
3171
- })),
3172
- error: "",
3173
- groupId: result.groupId ?? "",
3174
- primaryTerm: result.primaryTerm ?? 0n
3175
- });
3176
- }).catch((err) => {
3177
- callback(null, {
3178
- requestId: call.request.requestId,
3179
- results: [],
3180
- error: err.message,
3181
- groupId: call.request.groupId ?? "",
3182
- primaryTerm: call.request.primaryTerm ?? 0n
63
+ finish();
3183
64
  });
3184
65
  });
3185
66
  }
@@ -3252,21 +133,32 @@ var GrpcReplicationTransport = class {
3252
133
  syncCompleteHandler = null;
3253
134
  /** @internal */
3254
135
  syncAckHandler = null;
136
+ runtime = null;
3255
137
  constructor(options = {}) {
3256
138
  this.options = options;
3257
139
  }
3258
- /** Returns the port the gRPC server bound to, which is the resolved port when you asked for 0. */
140
+ /**
141
+ * Returns the port that the gRPC server listens on, including the port that the operating system picks when `port`
142
+ * is 0, and 0 while no server is listening.
143
+ */
3259
144
  getPort() {
3260
145
  return this.boundPort;
3261
146
  }
3262
- /** Connects to the configured peers and announces this node. */
147
+ /**
148
+ * Loads the gRPC packages, starts the gRPC server when this node is the primary or has a group ID, and dials every
149
+ * configured endpoint.
150
+ *
151
+ * @throws A `SirannonError` with code `TRANSPORT_DEPENDENCY_MISSING` when this process cannot load `@grpc/grpc-js`, `@bufbuild/protobuf`, or `grpc-health-check`.
152
+ */
3263
153
  async connect(localNodeId, config) {
154
+ const runtime = await loadGrpcRuntime();
3264
155
  if (this.connected) {
3265
156
  throw new TransportError("Transport is already connected");
3266
157
  }
3267
158
  if (!localNodeId || typeof localNodeId !== "string") {
3268
159
  throw new TransportError("localNodeId must be a non-empty string");
3269
160
  }
161
+ this.runtime = runtime;
3270
162
  this.localNodeId = localNodeId;
3271
163
  this.localRole = config.localRole ?? "replica";
3272
164
  this.localGroupId = config.groupId;
@@ -3274,15 +166,15 @@ var GrpcReplicationTransport = class {
3274
166
  this.localProtocolVersion = config.protocolVersion;
3275
167
  this.connected = true;
3276
168
  if (this.localRole === "primary" || config.groupId) {
3277
- await startServer(this);
169
+ await runtime.startServer(this);
3278
170
  }
3279
171
  if (config.endpoints && config.endpoints.length > 0) {
3280
172
  for (const endpoint of config.endpoints) {
3281
- connectToEndpoint(this, endpoint);
173
+ runtime.connectToEndpoint(this, endpoint);
3282
174
  }
3283
175
  }
3284
176
  }
3285
- /** Closes every peer connection. */
177
+ /** Closes every peer connection and shuts down the gRPC server. */
3286
178
  async disconnect() {
3287
179
  if (!this.connected) return;
3288
180
  this.connected = false;
@@ -3307,19 +199,7 @@ var GrpcReplicationTransport = class {
3307
199
  this.healthImpl.setStatus(SERVICE_NAME, "NOT_SERVING");
3308
200
  }
3309
201
  if (this.server) {
3310
- await new Promise((resolve) => {
3311
- const srv = this.server;
3312
- if (!srv) {
3313
- resolve();
3314
- return;
3315
- }
3316
- srv.tryShutdown((err) => {
3317
- if (err) {
3318
- srv.forceShutdown();
3319
- }
3320
- resolve();
3321
- });
3322
- });
202
+ await shutdownGrpcServer(this.server);
3323
203
  this.server = null;
3324
204
  }
3325
205
  }
@@ -3360,10 +240,14 @@ var GrpcReplicationTransport = class {
3360
240
  async forward(peerId, request) {
3361
241
  this.ensureConnected();
3362
242
  const clientEntry = this.clientPeerStreams.get(peerId);
3363
- if (!clientEntry) {
243
+ if (!clientEntry || !this.runtime) {
3364
244
  throw new TransportError(`Peer '${peerId}' is not connected`);
3365
245
  }
3366
- return forwardOverRpc(clientEntry, request, this.options.forwardDeadlineMs ?? DEFAULT_FORWARD_DEADLINE_MS);
246
+ return this.runtime.forwardOverRpc(
247
+ clientEntry,
248
+ request,
249
+ this.options.forwardDeadlineMs ?? DEFAULT_FORWARD_DEADLINE_MS
250
+ );
3367
251
  }
3368
252
  /** Asks a peer to stream a full copy of the database. */
3369
253
  async requestSync(peerId, request) {
@@ -3385,7 +269,7 @@ var GrpcReplicationTransport = class {
3385
269
  const msg = { syncBatch: toSyncBatchPayload(batch) };
3386
270
  await writeWithBackpressure(stream, msg);
3387
271
  }
3388
- /** Tells a joining node that first sync has finished, and sends the manifests to verify it. */
272
+ /** Tells a joining node that first sync is complete, and sends the manifests that the node checks its copy against. */
3389
273
  async sendSyncComplete(peerId, complete) {
3390
274
  this.ensureConnected();
3391
275
  const stream = this.getSyncWriteStream(peerId);
@@ -3395,7 +279,7 @@ var GrpcReplicationTransport = class {
3395
279
  const msg = { syncComplete: toSyncCompletePayload(complete) };
3396
280
  await writeWithBackpressure(stream, msg);
3397
281
  }
3398
- /** Confirms to the source that a joining node stored one first-sync page. */
282
+ /** Tells the source whether this joining node stored one first-sync page. */
3399
283
  async sendSyncAck(peerId, ack) {
3400
284
  this.ensureConnected();
3401
285
  const stream = this.getSyncWriteStream(peerId);
@@ -3413,7 +297,7 @@ var GrpcReplicationTransport = class {
3413
297
  onAckReceived(handler) {
3414
298
  this.ackHandler = handler;
3415
299
  }
3416
- /** Registers the handler that runs a write a replica forwarded. */
300
+ /** Registers the handler that executes a write that a replica forwards. */
3417
301
  onForwardReceived(handler) {
3418
302
  this.forwardHandler = handler;
3419
303
  }
@@ -3433,15 +317,15 @@ var GrpcReplicationTransport = class {
3433
317
  onSyncAckReceived(handler) {
3434
318
  this.syncAckHandler = handler;
3435
319
  }
3436
- /** Registers the handler that runs when a peer connects. */
320
+ /** Registers the handler that the transport calls when a peer connects. */
3437
321
  onPeerConnected(handler) {
3438
322
  this.peerConnectedHandler = handler;
3439
323
  }
3440
- /** Registers the handler that runs when a peer disconnects. */
324
+ /** Registers the handler that the transport calls when a peer disconnects. */
3441
325
  onPeerDisconnected(handler) {
3442
326
  this.peerDisconnectedHandler = handler;
3443
327
  }
3444
- /** Returns every connected peer, keyed by identifier. */
328
+ /** Returns every connected peer, keyed by node ID. */
3445
329
  peers() {
3446
330
  return this.connectedPeers;
3447
331
  }
@@ -3493,4 +377,4 @@ var GrpcReplicationTransport = class {
3493
377
  }
3494
378
  };
3495
379
 
3496
- export { GrpcReplicationTransport, fromColumnValue, toColumnValue };
380
+ export { GrpcReplicationTransport };