@apibara/protocol 0.4.9 → 2.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/CHANGELOG.md +103 -0
  2. package/buf.gen.yaml +14 -0
  3. package/build.config.ts +11 -0
  4. package/dist/index.cjs +189 -0
  5. package/dist/index.d.cts +72 -0
  6. package/dist/index.d.mts +72 -0
  7. package/dist/index.d.ts +72 -4
  8. package/dist/index.mjs +153 -0
  9. package/dist/shared/protocol.6b1bdade.cjs +1060 -0
  10. package/dist/shared/protocol.a07a51b5.mjs +1028 -0
  11. package/dist/shared/protocol.e9aed6a3.d.cts +549 -0
  12. package/dist/shared/protocol.e9aed6a3.d.mts +549 -0
  13. package/dist/shared/protocol.e9aed6a3.d.ts +549 -0
  14. package/dist/testing/index.cjs +105 -0
  15. package/dist/testing/index.d.cts +70 -0
  16. package/dist/testing/index.d.mts +70 -0
  17. package/dist/testing/index.d.ts +70 -0
  18. package/dist/testing/index.mjs +97 -0
  19. package/package.json +46 -24
  20. package/proto/common.proto +22 -0
  21. package/proto/stream.proto +83 -0
  22. package/proto/testing.proto +11 -0
  23. package/src/client.ts +113 -333
  24. package/src/common.test.ts +67 -0
  25. package/src/common.ts +65 -0
  26. package/src/config.ts +38 -0
  27. package/src/index.ts +10 -3
  28. package/src/proto/common.ts +279 -0
  29. package/src/proto/index.ts +3 -1
  30. package/src/proto/stream.ts +728 -17
  31. package/src/proto/testing.ts +143 -8
  32. package/src/rate.ts +54 -0
  33. package/src/status.test.ts +51 -0
  34. package/src/status.ts +22 -0
  35. package/src/stream.test-d.ts +33 -0
  36. package/src/stream.test.ts +238 -0
  37. package/src/stream.ts +128 -0
  38. package/src/testing/client.test.ts +71 -0
  39. package/src/testing/client.ts +49 -0
  40. package/src/testing/index.ts +2 -0
  41. package/src/testing/mock.test.ts +35 -0
  42. package/src/testing/mock.ts +71 -0
  43. package/tsconfig.json +12 -0
  44. package/dist/client.d.ts +0 -130
  45. package/dist/client.js +0 -215
  46. package/dist/client.js.map +0 -1
  47. package/dist/cursor.d.ts +0 -35
  48. package/dist/cursor.js +0 -67
  49. package/dist/cursor.js.map +0 -1
  50. package/dist/cursor.test.d.ts +0 -1
  51. package/dist/cursor.test.js +0 -22
  52. package/dist/cursor.test.js.map +0 -1
  53. package/dist/index.js +0 -21
  54. package/dist/index.js.map +0 -1
  55. package/dist/proto/apibara/node/v1alpha2/Cursor.d.ts +0 -10
  56. package/dist/proto/apibara/node/v1alpha2/Cursor.js +0 -4
  57. package/dist/proto/apibara/node/v1alpha2/Cursor.js.map +0 -1
  58. package/dist/proto/apibara/node/v1alpha2/Data.d.ts +0 -15
  59. package/dist/proto/apibara/node/v1alpha2/Data.js +0 -4
  60. package/dist/proto/apibara/node/v1alpha2/Data.js.map +0 -1
  61. package/dist/proto/apibara/node/v1alpha2/DataFinality.d.ts +0 -8
  62. package/dist/proto/apibara/node/v1alpha2/DataFinality.js +0 -11
  63. package/dist/proto/apibara/node/v1alpha2/DataFinality.js.map +0 -1
  64. package/dist/proto/apibara/node/v1alpha2/Heartbeat.d.ts +0 -4
  65. package/dist/proto/apibara/node/v1alpha2/Heartbeat.js +0 -4
  66. package/dist/proto/apibara/node/v1alpha2/Heartbeat.js.map +0 -1
  67. package/dist/proto/apibara/node/v1alpha2/Invalidate.d.ts +0 -7
  68. package/dist/proto/apibara/node/v1alpha2/Invalidate.js +0 -4
  69. package/dist/proto/apibara/node/v1alpha2/Invalidate.js.map +0 -1
  70. package/dist/proto/apibara/node/v1alpha2/Stream.d.ts +0 -16
  71. package/dist/proto/apibara/node/v1alpha2/Stream.js +0 -4
  72. package/dist/proto/apibara/node/v1alpha2/Stream.js.map +0 -1
  73. package/dist/proto/apibara/node/v1alpha2/StreamDataRequest.d.ts +0 -24
  74. package/dist/proto/apibara/node/v1alpha2/StreamDataRequest.js +0 -4
  75. package/dist/proto/apibara/node/v1alpha2/StreamDataRequest.js.map +0 -1
  76. package/dist/proto/apibara/node/v1alpha2/StreamDataResponse.d.ts +0 -18
  77. package/dist/proto/apibara/node/v1alpha2/StreamDataResponse.js +0 -4
  78. package/dist/proto/apibara/node/v1alpha2/StreamDataResponse.js.map +0 -1
  79. package/dist/proto/index.d.ts +0 -1
  80. package/dist/proto/index.js +0 -28
  81. package/dist/proto/index.js.map +0 -1
  82. package/dist/proto/stream.d.ts +0 -25
  83. package/dist/proto/stream.js +0 -3
  84. package/dist/proto/stream.js.map +0 -1
  85. package/dist/proto/stream.proto +0 -76
  86. package/dist/proto/testing.d.ts +0 -5
  87. package/dist/proto/testing.js +0 -24
  88. package/dist/proto/testing.js.map +0 -1
  89. package/dist/proto/v1alpha2.d.ts +0 -11
  90. package/dist/proto/v1alpha2.js +0 -15
  91. package/dist/proto/v1alpha2.js.map +0 -1
  92. package/dist/request.d.ts +0 -36
  93. package/dist/request.js +0 -58
  94. package/dist/request.js.map +0 -1
  95. package/dist/request.test.d.ts +0 -1
  96. package/dist/request.test.js +0 -28
  97. package/dist/request.test.js.map +0 -1
  98. package/src/cursor.test.ts +0 -21
  99. package/src/cursor.ts +0 -67
  100. package/src/proto/apibara/node/v1alpha2/Cursor.ts +0 -13
  101. package/src/proto/apibara/node/v1alpha2/Data.ts +0 -18
  102. package/src/proto/apibara/node/v1alpha2/DataFinality.ts +0 -20
  103. package/src/proto/apibara/node/v1alpha2/Heartbeat.ts +0 -8
  104. package/src/proto/apibara/node/v1alpha2/Invalidate.ts +0 -11
  105. package/src/proto/apibara/node/v1alpha2/Stream.ts +0 -23
  106. package/src/proto/apibara/node/v1alpha2/StreamDataRequest.ts +0 -27
  107. package/src/proto/apibara/node/v1alpha2/StreamDataResponse.ts +0 -22
  108. package/src/proto/stream.proto +0 -76
  109. package/src/proto/v1alpha2.ts +0 -24
  110. package/src/request.test.ts +0 -30
  111. package/src/request.ts +0 -64
@@ -1,26 +1,737 @@
1
- import type * as grpc from '@grpc/grpc-js';
2
- import type { EnumTypeDefinition, MessageTypeDefinition } from '@grpc/proto-loader';
1
+ // Code generated by protoc-gen-ts_proto. DO NOT EDIT.
2
+ // versions:
3
+ // protoc-gen-ts_proto v1.176.0
4
+ // protoc unknown
5
+ // source: stream.proto
3
6
 
4
- import type { StreamClient as _apibara_node_v1alpha2_StreamClient, StreamDefinition as _apibara_node_v1alpha2_StreamDefinition } from './apibara/node/v1alpha2/Stream';
7
+ /* eslint-disable */
8
+ import { type CallContext, type CallOptions } from "nice-grpc-common";
9
+ import _m0 from "protobufjs/minimal";
10
+ import { Cursor, StatusRequest, StatusResponse } from "./common";
5
11
 
6
- type SubtypeConstructor<Constructor extends new (...args: any) => any, Subtype> = {
7
- new(...args: ConstructorParameters<Constructor>): Subtype;
12
+ export const protobufPackage = "dna.v2.stream";
13
+
14
+ /** Apibara DNA server V2 */
15
+
16
+ /** Data finality. */
17
+ export enum DataFinality {
18
+ UNKNOWN = 0,
19
+ /** PENDING - Data was received, but is not part of the canonical chain yet. */
20
+ PENDING = 1,
21
+ /** ACCEPTED - Data is now part of the canonical chain, but could still be invalidated. */
22
+ ACCEPTED = 2,
23
+ /** FINALIZED - Data is finalized and cannot be invalidated. */
24
+ FINALIZED = 3,
25
+ UNRECOGNIZED = -1,
26
+ }
27
+
28
+ export function dataFinalityFromJSON(object: any): DataFinality {
29
+ switch (object) {
30
+ case 0:
31
+ case "DATA_FINALITY_UNKNOWN":
32
+ return DataFinality.UNKNOWN;
33
+ case 1:
34
+ case "DATA_FINALITY_PENDING":
35
+ return DataFinality.PENDING;
36
+ case 2:
37
+ case "DATA_FINALITY_ACCEPTED":
38
+ return DataFinality.ACCEPTED;
39
+ case 3:
40
+ case "DATA_FINALITY_FINALIZED":
41
+ return DataFinality.FINALIZED;
42
+ case -1:
43
+ case "UNRECOGNIZED":
44
+ default:
45
+ return DataFinality.UNRECOGNIZED;
46
+ }
47
+ }
48
+
49
+ export function dataFinalityToJSON(object: DataFinality): string {
50
+ switch (object) {
51
+ case DataFinality.UNKNOWN:
52
+ return "DATA_FINALITY_UNKNOWN";
53
+ case DataFinality.PENDING:
54
+ return "DATA_FINALITY_PENDING";
55
+ case DataFinality.ACCEPTED:
56
+ return "DATA_FINALITY_ACCEPTED";
57
+ case DataFinality.FINALIZED:
58
+ return "DATA_FINALITY_FINALIZED";
59
+ case DataFinality.UNRECOGNIZED:
60
+ default:
61
+ return "UNRECOGNIZED";
62
+ }
63
+ }
64
+
65
+ /** Request data to be streamed. */
66
+ export interface StreamDataRequest {
67
+ /** Cursor to start streaming from. */
68
+ readonly startingCursor?:
69
+ | Cursor
70
+ | undefined;
71
+ /**
72
+ * Return data with the specified finality.
73
+ * If not specified, defaults to `DATA_FINALITY_ACCEPTED`.
74
+ */
75
+ readonly finality?:
76
+ | DataFinality
77
+ | undefined;
78
+ /** Filters used to generate data. */
79
+ readonly filter: readonly Uint8Array[];
80
+ }
81
+
82
+ /** Contains a piece of streamed data. */
83
+ export interface StreamDataResponse {
84
+ readonly message?:
85
+ | { readonly $case: "data"; readonly data: Data }
86
+ | { readonly $case: "invalidate"; readonly invalidate: Invalidate }
87
+ | { readonly $case: "heartbeat"; readonly heartbeat: Heartbeat }
88
+ | { readonly $case: "systemMessage"; readonly systemMessage: SystemMessage }
89
+ | undefined;
90
+ }
91
+
92
+ /** Invalidate data after the given cursor. */
93
+ export interface Invalidate {
94
+ /** The cursor of the message before the now invalid data. */
95
+ readonly cursor?: Cursor | undefined;
96
+ }
97
+
98
+ /**
99
+ * A single block of data.
100
+ *
101
+ * If the request specified multiple filters, the `data` field will contain the
102
+ * data for each filter in the same order as the filters were specified in the
103
+ * request.
104
+ * If no data is available for a filter, the corresponding data field will be
105
+ * empty.
106
+ */
107
+ export interface Data {
108
+ /** Cursor that generated this block of data. */
109
+ readonly cursor?:
110
+ | Cursor
111
+ | undefined;
112
+ /** Block cursor. Use this cursor to resume the stream. */
113
+ readonly endCursor?:
114
+ | Cursor
115
+ | undefined;
116
+ /** The finality status of the block. */
117
+ readonly finality: DataFinality;
118
+ /** The block data. */
119
+ readonly data: readonly Uint8Array[];
120
+ }
121
+
122
+ /** Sent to clients to check if stream is still connected. */
123
+ export interface Heartbeat {
124
+ }
125
+
126
+ /** Message from the server to the client. */
127
+ export interface SystemMessage {
128
+ readonly output?: { readonly $case: "stdout"; readonly stdout: string } | {
129
+ readonly $case: "stderr";
130
+ readonly stderr: string;
131
+ } | undefined;
132
+ }
133
+
134
+ function createBaseStreamDataRequest(): StreamDataRequest {
135
+ return { startingCursor: undefined, finality: undefined, filter: [] };
136
+ }
137
+
138
+ export const StreamDataRequest = {
139
+ encode(message: StreamDataRequest, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
140
+ if (message.startingCursor !== undefined) {
141
+ Cursor.encode(message.startingCursor, writer.uint32(10).fork()).ldelim();
142
+ }
143
+ if (message.finality !== undefined) {
144
+ writer.uint32(16).int32(message.finality);
145
+ }
146
+ for (const v of message.filter) {
147
+ writer.uint32(26).bytes(v!);
148
+ }
149
+ return writer;
150
+ },
151
+
152
+ decode(input: _m0.Reader | Uint8Array, length?: number): StreamDataRequest {
153
+ const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
154
+ let end = length === undefined ? reader.len : reader.pos + length;
155
+ const message = createBaseStreamDataRequest() as any;
156
+ while (reader.pos < end) {
157
+ const tag = reader.uint32();
158
+ switch (tag >>> 3) {
159
+ case 1:
160
+ if (tag !== 10) {
161
+ break;
162
+ }
163
+
164
+ message.startingCursor = Cursor.decode(reader, reader.uint32());
165
+ continue;
166
+ case 2:
167
+ if (tag !== 16) {
168
+ break;
169
+ }
170
+
171
+ message.finality = reader.int32() as any;
172
+ continue;
173
+ case 3:
174
+ if (tag !== 26) {
175
+ break;
176
+ }
177
+
178
+ message.filter.push(reader.bytes());
179
+ continue;
180
+ }
181
+ if ((tag & 7) === 4 || tag === 0) {
182
+ break;
183
+ }
184
+ reader.skipType(tag & 7);
185
+ }
186
+ return message;
187
+ },
188
+
189
+ fromJSON(object: any): StreamDataRequest {
190
+ return {
191
+ startingCursor: isSet(object.startingCursor) ? Cursor.fromJSON(object.startingCursor) : undefined,
192
+ finality: isSet(object.finality) ? dataFinalityFromJSON(object.finality) : undefined,
193
+ filter: globalThis.Array.isArray(object?.filter) ? object.filter.map((e: any) => bytesFromBase64(e)) : [],
194
+ };
195
+ },
196
+
197
+ toJSON(message: StreamDataRequest): unknown {
198
+ const obj: any = {};
199
+ if (message.startingCursor !== undefined) {
200
+ obj.startingCursor = Cursor.toJSON(message.startingCursor);
201
+ }
202
+ if (message.finality !== undefined) {
203
+ obj.finality = dataFinalityToJSON(message.finality);
204
+ }
205
+ if (message.filter?.length) {
206
+ obj.filter = message.filter.map((e) => base64FromBytes(e));
207
+ }
208
+ return obj;
209
+ },
210
+
211
+ create(base?: DeepPartial<StreamDataRequest>): StreamDataRequest {
212
+ return StreamDataRequest.fromPartial(base ?? {});
213
+ },
214
+ fromPartial(object: DeepPartial<StreamDataRequest>): StreamDataRequest {
215
+ const message = createBaseStreamDataRequest() as any;
216
+ message.startingCursor = (object.startingCursor !== undefined && object.startingCursor !== null)
217
+ ? Cursor.fromPartial(object.startingCursor)
218
+ : undefined;
219
+ message.finality = object.finality ?? undefined;
220
+ message.filter = object.filter?.map((e) => e) || [];
221
+ return message;
222
+ },
8
223
  };
9
224
 
10
- export interface ProtoGrpcType {
11
- apibara: {
12
- node: {
13
- v1alpha2: {
14
- Cursor: MessageTypeDefinition
15
- Data: MessageTypeDefinition
16
- DataFinality: EnumTypeDefinition
17
- Heartbeat: MessageTypeDefinition
18
- Invalidate: MessageTypeDefinition
19
- Stream: SubtypeConstructor<typeof grpc.Client, _apibara_node_v1alpha2_StreamClient> & { service: _apibara_node_v1alpha2_StreamDefinition }
20
- StreamDataRequest: MessageTypeDefinition
21
- StreamDataResponse: MessageTypeDefinition
225
+ function createBaseStreamDataResponse(): StreamDataResponse {
226
+ return { message: undefined };
227
+ }
228
+
229
+ export const StreamDataResponse = {
230
+ encode(message: StreamDataResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
231
+ switch (message.message?.$case) {
232
+ case "data":
233
+ Data.encode(message.message.data, writer.uint32(10).fork()).ldelim();
234
+ break;
235
+ case "invalidate":
236
+ Invalidate.encode(message.message.invalidate, writer.uint32(18).fork()).ldelim();
237
+ break;
238
+ case "heartbeat":
239
+ Heartbeat.encode(message.message.heartbeat, writer.uint32(26).fork()).ldelim();
240
+ break;
241
+ case "systemMessage":
242
+ SystemMessage.encode(message.message.systemMessage, writer.uint32(34).fork()).ldelim();
243
+ break;
244
+ }
245
+ return writer;
246
+ },
247
+
248
+ decode(input: _m0.Reader | Uint8Array, length?: number): StreamDataResponse {
249
+ const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
250
+ let end = length === undefined ? reader.len : reader.pos + length;
251
+ const message = createBaseStreamDataResponse() as any;
252
+ while (reader.pos < end) {
253
+ const tag = reader.uint32();
254
+ switch (tag >>> 3) {
255
+ case 1:
256
+ if (tag !== 10) {
257
+ break;
258
+ }
259
+
260
+ message.message = { $case: "data", data: Data.decode(reader, reader.uint32()) };
261
+ continue;
262
+ case 2:
263
+ if (tag !== 18) {
264
+ break;
265
+ }
266
+
267
+ message.message = { $case: "invalidate", invalidate: Invalidate.decode(reader, reader.uint32()) };
268
+ continue;
269
+ case 3:
270
+ if (tag !== 26) {
271
+ break;
272
+ }
273
+
274
+ message.message = { $case: "heartbeat", heartbeat: Heartbeat.decode(reader, reader.uint32()) };
275
+ continue;
276
+ case 4:
277
+ if (tag !== 34) {
278
+ break;
279
+ }
280
+
281
+ message.message = { $case: "systemMessage", systemMessage: SystemMessage.decode(reader, reader.uint32()) };
282
+ continue;
22
283
  }
284
+ if ((tag & 7) === 4 || tag === 0) {
285
+ break;
286
+ }
287
+ reader.skipType(tag & 7);
288
+ }
289
+ return message;
290
+ },
291
+
292
+ fromJSON(object: any): StreamDataResponse {
293
+ return {
294
+ message: isSet(object.data)
295
+ ? { $case: "data", data: Data.fromJSON(object.data) }
296
+ : isSet(object.invalidate)
297
+ ? { $case: "invalidate", invalidate: Invalidate.fromJSON(object.invalidate) }
298
+ : isSet(object.heartbeat)
299
+ ? { $case: "heartbeat", heartbeat: Heartbeat.fromJSON(object.heartbeat) }
300
+ : isSet(object.systemMessage)
301
+ ? { $case: "systemMessage", systemMessage: SystemMessage.fromJSON(object.systemMessage) }
302
+ : undefined,
303
+ };
304
+ },
305
+
306
+ toJSON(message: StreamDataResponse): unknown {
307
+ const obj: any = {};
308
+ if (message.message?.$case === "data") {
309
+ obj.data = Data.toJSON(message.message.data);
310
+ }
311
+ if (message.message?.$case === "invalidate") {
312
+ obj.invalidate = Invalidate.toJSON(message.message.invalidate);
313
+ }
314
+ if (message.message?.$case === "heartbeat") {
315
+ obj.heartbeat = Heartbeat.toJSON(message.message.heartbeat);
23
316
  }
317
+ if (message.message?.$case === "systemMessage") {
318
+ obj.systemMessage = SystemMessage.toJSON(message.message.systemMessage);
319
+ }
320
+ return obj;
321
+ },
322
+
323
+ create(base?: DeepPartial<StreamDataResponse>): StreamDataResponse {
324
+ return StreamDataResponse.fromPartial(base ?? {});
325
+ },
326
+ fromPartial(object: DeepPartial<StreamDataResponse>): StreamDataResponse {
327
+ const message = createBaseStreamDataResponse() as any;
328
+ if (object.message?.$case === "data" && object.message?.data !== undefined && object.message?.data !== null) {
329
+ message.message = { $case: "data", data: Data.fromPartial(object.message.data) };
330
+ }
331
+ if (
332
+ object.message?.$case === "invalidate" &&
333
+ object.message?.invalidate !== undefined &&
334
+ object.message?.invalidate !== null
335
+ ) {
336
+ message.message = { $case: "invalidate", invalidate: Invalidate.fromPartial(object.message.invalidate) };
337
+ }
338
+ if (
339
+ object.message?.$case === "heartbeat" &&
340
+ object.message?.heartbeat !== undefined &&
341
+ object.message?.heartbeat !== null
342
+ ) {
343
+ message.message = { $case: "heartbeat", heartbeat: Heartbeat.fromPartial(object.message.heartbeat) };
344
+ }
345
+ if (
346
+ object.message?.$case === "systemMessage" &&
347
+ object.message?.systemMessage !== undefined &&
348
+ object.message?.systemMessage !== null
349
+ ) {
350
+ message.message = {
351
+ $case: "systemMessage",
352
+ systemMessage: SystemMessage.fromPartial(object.message.systemMessage),
353
+ };
354
+ }
355
+ return message;
356
+ },
357
+ };
358
+
359
+ function createBaseInvalidate(): Invalidate {
360
+ return { cursor: undefined };
361
+ }
362
+
363
+ export const Invalidate = {
364
+ encode(message: Invalidate, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
365
+ if (message.cursor !== undefined) {
366
+ Cursor.encode(message.cursor, writer.uint32(10).fork()).ldelim();
367
+ }
368
+ return writer;
369
+ },
370
+
371
+ decode(input: _m0.Reader | Uint8Array, length?: number): Invalidate {
372
+ const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
373
+ let end = length === undefined ? reader.len : reader.pos + length;
374
+ const message = createBaseInvalidate() as any;
375
+ while (reader.pos < end) {
376
+ const tag = reader.uint32();
377
+ switch (tag >>> 3) {
378
+ case 1:
379
+ if (tag !== 10) {
380
+ break;
381
+ }
382
+
383
+ message.cursor = Cursor.decode(reader, reader.uint32());
384
+ continue;
385
+ }
386
+ if ((tag & 7) === 4 || tag === 0) {
387
+ break;
388
+ }
389
+ reader.skipType(tag & 7);
390
+ }
391
+ return message;
392
+ },
393
+
394
+ fromJSON(object: any): Invalidate {
395
+ return { cursor: isSet(object.cursor) ? Cursor.fromJSON(object.cursor) : undefined };
396
+ },
397
+
398
+ toJSON(message: Invalidate): unknown {
399
+ const obj: any = {};
400
+ if (message.cursor !== undefined) {
401
+ obj.cursor = Cursor.toJSON(message.cursor);
402
+ }
403
+ return obj;
404
+ },
405
+
406
+ create(base?: DeepPartial<Invalidate>): Invalidate {
407
+ return Invalidate.fromPartial(base ?? {});
408
+ },
409
+ fromPartial(object: DeepPartial<Invalidate>): Invalidate {
410
+ const message = createBaseInvalidate() as any;
411
+ message.cursor = (object.cursor !== undefined && object.cursor !== null)
412
+ ? Cursor.fromPartial(object.cursor)
413
+ : undefined;
414
+ return message;
415
+ },
416
+ };
417
+
418
+ function createBaseData(): Data {
419
+ return { cursor: undefined, endCursor: undefined, finality: 0, data: [] };
420
+ }
421
+
422
+ export const Data = {
423
+ encode(message: Data, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
424
+ if (message.cursor !== undefined) {
425
+ Cursor.encode(message.cursor, writer.uint32(10).fork()).ldelim();
426
+ }
427
+ if (message.endCursor !== undefined) {
428
+ Cursor.encode(message.endCursor, writer.uint32(18).fork()).ldelim();
429
+ }
430
+ if (message.finality !== 0) {
431
+ writer.uint32(24).int32(message.finality);
432
+ }
433
+ for (const v of message.data) {
434
+ writer.uint32(34).bytes(v!);
435
+ }
436
+ return writer;
437
+ },
438
+
439
+ decode(input: _m0.Reader | Uint8Array, length?: number): Data {
440
+ const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
441
+ let end = length === undefined ? reader.len : reader.pos + length;
442
+ const message = createBaseData() as any;
443
+ while (reader.pos < end) {
444
+ const tag = reader.uint32();
445
+ switch (tag >>> 3) {
446
+ case 1:
447
+ if (tag !== 10) {
448
+ break;
449
+ }
450
+
451
+ message.cursor = Cursor.decode(reader, reader.uint32());
452
+ continue;
453
+ case 2:
454
+ if (tag !== 18) {
455
+ break;
456
+ }
457
+
458
+ message.endCursor = Cursor.decode(reader, reader.uint32());
459
+ continue;
460
+ case 3:
461
+ if (tag !== 24) {
462
+ break;
463
+ }
464
+
465
+ message.finality = reader.int32() as any;
466
+ continue;
467
+ case 4:
468
+ if (tag !== 34) {
469
+ break;
470
+ }
471
+
472
+ message.data.push(reader.bytes());
473
+ continue;
474
+ }
475
+ if ((tag & 7) === 4 || tag === 0) {
476
+ break;
477
+ }
478
+ reader.skipType(tag & 7);
479
+ }
480
+ return message;
481
+ },
482
+
483
+ fromJSON(object: any): Data {
484
+ return {
485
+ cursor: isSet(object.cursor) ? Cursor.fromJSON(object.cursor) : undefined,
486
+ endCursor: isSet(object.endCursor) ? Cursor.fromJSON(object.endCursor) : undefined,
487
+ finality: isSet(object.finality) ? dataFinalityFromJSON(object.finality) : 0,
488
+ data: globalThis.Array.isArray(object?.data) ? object.data.map((e: any) => bytesFromBase64(e)) : [],
489
+ };
490
+ },
491
+
492
+ toJSON(message: Data): unknown {
493
+ const obj: any = {};
494
+ if (message.cursor !== undefined) {
495
+ obj.cursor = Cursor.toJSON(message.cursor);
496
+ }
497
+ if (message.endCursor !== undefined) {
498
+ obj.endCursor = Cursor.toJSON(message.endCursor);
499
+ }
500
+ if (message.finality !== 0) {
501
+ obj.finality = dataFinalityToJSON(message.finality);
502
+ }
503
+ if (message.data?.length) {
504
+ obj.data = message.data.map((e) => base64FromBytes(e));
505
+ }
506
+ return obj;
507
+ },
508
+
509
+ create(base?: DeepPartial<Data>): Data {
510
+ return Data.fromPartial(base ?? {});
511
+ },
512
+ fromPartial(object: DeepPartial<Data>): Data {
513
+ const message = createBaseData() as any;
514
+ message.cursor = (object.cursor !== undefined && object.cursor !== null)
515
+ ? Cursor.fromPartial(object.cursor)
516
+ : undefined;
517
+ message.endCursor = (object.endCursor !== undefined && object.endCursor !== null)
518
+ ? Cursor.fromPartial(object.endCursor)
519
+ : undefined;
520
+ message.finality = object.finality ?? 0;
521
+ message.data = object.data?.map((e) => e) || [];
522
+ return message;
523
+ },
524
+ };
525
+
526
+ function createBaseHeartbeat(): Heartbeat {
527
+ return {};
528
+ }
529
+
530
+ export const Heartbeat = {
531
+ encode(_: Heartbeat, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
532
+ return writer;
533
+ },
534
+
535
+ decode(input: _m0.Reader | Uint8Array, length?: number): Heartbeat {
536
+ const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
537
+ let end = length === undefined ? reader.len : reader.pos + length;
538
+ const message = createBaseHeartbeat() as any;
539
+ while (reader.pos < end) {
540
+ const tag = reader.uint32();
541
+ switch (tag >>> 3) {
542
+ }
543
+ if ((tag & 7) === 4 || tag === 0) {
544
+ break;
545
+ }
546
+ reader.skipType(tag & 7);
547
+ }
548
+ return message;
549
+ },
550
+
551
+ fromJSON(_: any): Heartbeat {
552
+ return {};
553
+ },
554
+
555
+ toJSON(_: Heartbeat): unknown {
556
+ const obj: any = {};
557
+ return obj;
558
+ },
559
+
560
+ create(base?: DeepPartial<Heartbeat>): Heartbeat {
561
+ return Heartbeat.fromPartial(base ?? {});
562
+ },
563
+ fromPartial(_: DeepPartial<Heartbeat>): Heartbeat {
564
+ const message = createBaseHeartbeat() as any;
565
+ return message;
566
+ },
567
+ };
568
+
569
+ function createBaseSystemMessage(): SystemMessage {
570
+ return { output: undefined };
571
+ }
572
+
573
+ export const SystemMessage = {
574
+ encode(message: SystemMessage, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
575
+ switch (message.output?.$case) {
576
+ case "stdout":
577
+ writer.uint32(10).string(message.output.stdout);
578
+ break;
579
+ case "stderr":
580
+ writer.uint32(18).string(message.output.stderr);
581
+ break;
582
+ }
583
+ return writer;
584
+ },
585
+
586
+ decode(input: _m0.Reader | Uint8Array, length?: number): SystemMessage {
587
+ const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
588
+ let end = length === undefined ? reader.len : reader.pos + length;
589
+ const message = createBaseSystemMessage() as any;
590
+ while (reader.pos < end) {
591
+ const tag = reader.uint32();
592
+ switch (tag >>> 3) {
593
+ case 1:
594
+ if (tag !== 10) {
595
+ break;
596
+ }
597
+
598
+ message.output = { $case: "stdout", stdout: reader.string() };
599
+ continue;
600
+ case 2:
601
+ if (tag !== 18) {
602
+ break;
603
+ }
604
+
605
+ message.output = { $case: "stderr", stderr: reader.string() };
606
+ continue;
607
+ }
608
+ if ((tag & 7) === 4 || tag === 0) {
609
+ break;
610
+ }
611
+ reader.skipType(tag & 7);
612
+ }
613
+ return message;
614
+ },
615
+
616
+ fromJSON(object: any): SystemMessage {
617
+ return {
618
+ output: isSet(object.stdout)
619
+ ? { $case: "stdout", stdout: globalThis.String(object.stdout) }
620
+ : isSet(object.stderr)
621
+ ? { $case: "stderr", stderr: globalThis.String(object.stderr) }
622
+ : undefined,
623
+ };
624
+ },
625
+
626
+ toJSON(message: SystemMessage): unknown {
627
+ const obj: any = {};
628
+ if (message.output?.$case === "stdout") {
629
+ obj.stdout = message.output.stdout;
630
+ }
631
+ if (message.output?.$case === "stderr") {
632
+ obj.stderr = message.output.stderr;
633
+ }
634
+ return obj;
635
+ },
636
+
637
+ create(base?: DeepPartial<SystemMessage>): SystemMessage {
638
+ return SystemMessage.fromPartial(base ?? {});
639
+ },
640
+ fromPartial(object: DeepPartial<SystemMessage>): SystemMessage {
641
+ const message = createBaseSystemMessage() as any;
642
+ if (object.output?.$case === "stdout" && object.output?.stdout !== undefined && object.output?.stdout !== null) {
643
+ message.output = { $case: "stdout", stdout: object.output.stdout };
644
+ }
645
+ if (object.output?.$case === "stderr" && object.output?.stderr !== undefined && object.output?.stderr !== null) {
646
+ message.output = { $case: "stderr", stderr: object.output.stderr };
647
+ }
648
+ return message;
649
+ },
650
+ };
651
+
652
+ export type DnaStreamDefinition = typeof DnaStreamDefinition;
653
+ export const DnaStreamDefinition = {
654
+ name: "DnaStream",
655
+ fullName: "dna.v2.stream.DnaStream",
656
+ methods: {
657
+ /** Stream data from the server. */
658
+ streamData: {
659
+ name: "StreamData",
660
+ requestType: StreamDataRequest,
661
+ requestStream: false,
662
+ responseType: StreamDataResponse,
663
+ responseStream: true,
664
+ options: {},
665
+ },
666
+ /** Get DNA server status. */
667
+ status: {
668
+ name: "Status",
669
+ requestType: StatusRequest,
670
+ requestStream: false,
671
+ responseType: StatusResponse,
672
+ responseStream: false,
673
+ options: {},
674
+ },
675
+ },
676
+ } as const;
677
+
678
+ export interface DnaStreamServiceImplementation<CallContextExt = {}> {
679
+ /** Stream data from the server. */
680
+ streamData(
681
+ request: StreamDataRequest,
682
+ context: CallContext & CallContextExt,
683
+ ): ServerStreamingMethodResult<DeepPartial<StreamDataResponse>>;
684
+ /** Get DNA server status. */
685
+ status(request: StatusRequest, context: CallContext & CallContextExt): Promise<DeepPartial<StatusResponse>>;
686
+ }
687
+
688
+ export interface DnaStreamClient<CallOptionsExt = {}> {
689
+ /** Stream data from the server. */
690
+ streamData(
691
+ request: DeepPartial<StreamDataRequest>,
692
+ options?: CallOptions & CallOptionsExt,
693
+ ): AsyncIterable<StreamDataResponse>;
694
+ /** Get DNA server status. */
695
+ status(request: DeepPartial<StatusRequest>, options?: CallOptions & CallOptionsExt): Promise<StatusResponse>;
696
+ }
697
+
698
+ function bytesFromBase64(b64: string): Uint8Array {
699
+ if ((globalThis as any).Buffer) {
700
+ return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
701
+ } else {
702
+ const bin = globalThis.atob(b64);
703
+ const arr = new Uint8Array(bin.length);
704
+ for (let i = 0; i < bin.length; ++i) {
705
+ arr[i] = bin.charCodeAt(i);
706
+ }
707
+ return arr;
708
+ }
709
+ }
710
+
711
+ function base64FromBytes(arr: Uint8Array): string {
712
+ if ((globalThis as any).Buffer) {
713
+ return globalThis.Buffer.from(arr).toString("base64");
714
+ } else {
715
+ const bin: string[] = [];
716
+ arr.forEach((byte) => {
717
+ bin.push(globalThis.String.fromCharCode(byte));
718
+ });
719
+ return globalThis.btoa(bin.join(""));
24
720
  }
25
721
  }
26
722
 
723
+ type Builtin = Date | Function | Uint8Array | string | number | boolean | bigint | undefined;
724
+
725
+ export type DeepPartial<T> = T extends Builtin ? T
726
+ : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>>
727
+ : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
728
+ : T extends { readonly $case: string }
729
+ ? { [K in keyof Omit<T, "$case">]?: DeepPartial<T[K]> } & { readonly $case: T["$case"] }
730
+ : T extends {} ? { [K in keyof T]?: DeepPartial<T[K]> }
731
+ : Partial<T>;
732
+
733
+ function isSet(value: any): boolean {
734
+ return value !== null && value !== undefined;
735
+ }
736
+
737
+ export type ServerStreamingMethodResult<Response> = { [Symbol.asyncIterator](): AsyncIterator<Response, void> };