@apibara/protocol 0.3.0 → 0.4.0-next.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 (143) hide show
  1. package/dist/client.d.ts +116 -25
  2. package/dist/client.js +159 -35
  3. package/dist/client.js.map +1 -1
  4. package/dist/cursor.d.ts +22 -0
  5. package/dist/cursor.js +43 -0
  6. package/dist/cursor.js.map +1 -0
  7. package/dist/index.d.ts +3 -3
  8. package/dist/index.js +3 -16
  9. package/dist/index.js.map +1 -1
  10. package/dist/proto/apibara/node/v1alpha2/Cursor.d.ts +10 -0
  11. package/dist/proto/apibara/node/{v1alpha1/Node.js → v1alpha2/Cursor.js} +2 -2
  12. package/dist/proto/apibara/node/v1alpha2/Cursor.js.map +1 -0
  13. package/dist/proto/apibara/node/v1alpha2/Data.d.ts +15 -0
  14. package/dist/proto/apibara/node/{v1alpha1 → v1alpha2}/Data.js +1 -1
  15. package/dist/proto/apibara/node/v1alpha2/Data.js.map +1 -0
  16. package/dist/proto/apibara/node/v1alpha2/DataFinality.d.ts +6 -0
  17. package/dist/proto/apibara/node/v1alpha2/DataFinality.js +12 -0
  18. package/dist/proto/apibara/node/v1alpha2/DataFinality.js.map +1 -0
  19. package/dist/proto/apibara/node/{v1alpha1 → v1alpha2}/Heartbeat.d.ts +0 -0
  20. package/dist/proto/apibara/node/v1alpha2/Heartbeat.js +4 -0
  21. package/dist/proto/apibara/node/v1alpha2/Heartbeat.js.map +1 -0
  22. package/dist/proto/apibara/node/v1alpha2/Invalidate.d.ts +7 -0
  23. package/dist/proto/apibara/node/v1alpha2/Invalidate.js +4 -0
  24. package/dist/proto/apibara/node/v1alpha2/Invalidate.js.map +1 -0
  25. package/dist/proto/apibara/node/v1alpha2/Stream.d.ts +16 -0
  26. package/dist/proto/{google/protobuf/Any.js → apibara/node/v1alpha2/Stream.js} +2 -2
  27. package/dist/proto/apibara/node/v1alpha2/Stream.js.map +1 -0
  28. package/dist/proto/apibara/node/v1alpha2/StreamDataRequest.d.ts +24 -0
  29. package/dist/proto/apibara/node/v1alpha2/StreamDataRequest.js +4 -0
  30. package/dist/proto/apibara/node/v1alpha2/StreamDataRequest.js.map +1 -0
  31. package/dist/proto/apibara/node/v1alpha2/StreamDataResponse.d.ts +18 -0
  32. package/dist/proto/apibara/node/v1alpha2/StreamDataResponse.js +4 -0
  33. package/dist/proto/apibara/node/v1alpha2/StreamDataResponse.js.map +1 -0
  34. package/dist/proto/index.d.ts +1 -11
  35. package/dist/proto/index.js +13 -13
  36. package/dist/proto/index.js.map +1 -1
  37. package/dist/proto/stream.d.ts +25 -0
  38. package/dist/proto/{node.js → stream.js} +1 -1
  39. package/dist/proto/stream.js.map +1 -0
  40. package/dist/proto/stream.proto +76 -0
  41. package/dist/proto/testing.d.ts +5 -0
  42. package/dist/proto/testing.js +22 -0
  43. package/dist/proto/testing.js.map +1 -0
  44. package/dist/proto/v1alpha2.d.ts +11 -0
  45. package/dist/proto/v1alpha2.js +12 -0
  46. package/dist/proto/v1alpha2.js.map +1 -0
  47. package/dist/request.d.ts +36 -0
  48. package/dist/request.js +57 -0
  49. package/dist/request.js.map +1 -0
  50. package/dist/request.test.d.ts +1 -0
  51. package/dist/request.test.js +29 -0
  52. package/dist/request.test.js.map +1 -0
  53. package/package.json +7 -4
  54. package/src/client.ts +259 -44
  55. package/src/cursor.ts +39 -0
  56. package/src/index.ts +3 -3
  57. package/src/proto/apibara/node/v1alpha2/Cursor.ts +13 -0
  58. package/src/proto/apibara/node/v1alpha2/Data.ts +18 -0
  59. package/src/proto/apibara/node/v1alpha2/DataFinality.ts +8 -0
  60. package/src/proto/apibara/node/{v1alpha1 → v1alpha2}/Heartbeat.ts +1 -1
  61. package/src/proto/apibara/node/v1alpha2/Invalidate.ts +11 -0
  62. package/src/proto/apibara/node/v1alpha2/Stream.ts +23 -0
  63. package/src/proto/apibara/node/v1alpha2/StreamDataRequest.ts +27 -0
  64. package/src/proto/apibara/node/v1alpha2/StreamDataResponse.ts +22 -0
  65. package/src/proto/index.ts +1 -11
  66. package/src/proto/stream.proto +76 -0
  67. package/src/proto/stream.ts +26 -0
  68. package/src/proto/testing.ts +11 -0
  69. package/src/proto/v1alpha2.ts +19 -0
  70. package/src/request.test.ts +31 -0
  71. package/src/request.ts +64 -0
  72. package/dist/buffer.d.ts +0 -12
  73. package/dist/buffer.js +0 -22
  74. package/dist/buffer.js.map +0 -1
  75. package/dist/proto/apibara/node/v1alpha1/ConnectRequest.d.ts +0 -7
  76. package/dist/proto/apibara/node/v1alpha1/ConnectRequest.js +0 -4
  77. package/dist/proto/apibara/node/v1alpha1/ConnectRequest.js.map +0 -1
  78. package/dist/proto/apibara/node/v1alpha1/ConnectResponse.d.ts +0 -12
  79. package/dist/proto/apibara/node/v1alpha1/ConnectResponse.js +0 -4
  80. package/dist/proto/apibara/node/v1alpha1/ConnectResponse.js.map +0 -1
  81. package/dist/proto/apibara/node/v1alpha1/Data.d.ts +0 -10
  82. package/dist/proto/apibara/node/v1alpha1/Data.js.map +0 -1
  83. package/dist/proto/apibara/node/v1alpha1/Heartbeat.js +0 -4
  84. package/dist/proto/apibara/node/v1alpha1/Heartbeat.js.map +0 -1
  85. package/dist/proto/apibara/node/v1alpha1/InputSyncingStatus.d.ts +0 -9
  86. package/dist/proto/apibara/node/v1alpha1/InputSyncingStatus.js +0 -4
  87. package/dist/proto/apibara/node/v1alpha1/InputSyncingStatus.js.map +0 -1
  88. package/dist/proto/apibara/node/v1alpha1/Invalidate.d.ts +0 -7
  89. package/dist/proto/apibara/node/v1alpha1/Invalidate.js +0 -4
  90. package/dist/proto/apibara/node/v1alpha1/Invalidate.js.map +0 -1
  91. package/dist/proto/apibara/node/v1alpha1/Node.d.ts +0 -28
  92. package/dist/proto/apibara/node/v1alpha1/Node.js.map +0 -1
  93. package/dist/proto/apibara/node/v1alpha1/NotStartedStatus.d.ts +0 -4
  94. package/dist/proto/apibara/node/v1alpha1/NotStartedStatus.js +0 -4
  95. package/dist/proto/apibara/node/v1alpha1/NotStartedStatus.js.map +0 -1
  96. package/dist/proto/apibara/node/v1alpha1/StatusRequest.d.ts +0 -4
  97. package/dist/proto/apibara/node/v1alpha1/StatusRequest.js +0 -4
  98. package/dist/proto/apibara/node/v1alpha1/StatusRequest.js.map +0 -1
  99. package/dist/proto/apibara/node/v1alpha1/StatusResponse.d.ts +0 -15
  100. package/dist/proto/apibara/node/v1alpha1/StatusResponse.js +0 -4
  101. package/dist/proto/apibara/node/v1alpha1/StatusResponse.js.map +0 -1
  102. package/dist/proto/apibara/node/v1alpha1/StreamMessagesRequest.d.ts +0 -9
  103. package/dist/proto/apibara/node/v1alpha1/StreamMessagesRequest.js +0 -4
  104. package/dist/proto/apibara/node/v1alpha1/StreamMessagesRequest.js.map +0 -1
  105. package/dist/proto/apibara/node/v1alpha1/StreamMessagesResponse.d.ts +0 -17
  106. package/dist/proto/apibara/node/v1alpha1/StreamMessagesResponse.js +0 -4
  107. package/dist/proto/apibara/node/v1alpha1/StreamMessagesResponse.js.map +0 -1
  108. package/dist/proto/apibara/node/v1alpha1/SyncedStatus.d.ts +0 -7
  109. package/dist/proto/apibara/node/v1alpha1/SyncedStatus.js +0 -4
  110. package/dist/proto/apibara/node/v1alpha1/SyncedStatus.js.map +0 -1
  111. package/dist/proto/apibara/node/v1alpha1/SyncingStatus.d.ts +0 -10
  112. package/dist/proto/apibara/node/v1alpha1/SyncingStatus.js +0 -4
  113. package/dist/proto/apibara/node/v1alpha1/SyncingStatus.js.map +0 -1
  114. package/dist/proto/google/protobuf/Any.d.ts +0 -10
  115. package/dist/proto/google/protobuf/Any.js.map +0 -1
  116. package/dist/proto/node.d.ts +0 -36
  117. package/dist/proto/node.js.map +0 -1
  118. package/dist/proto/node.proto +0 -99
  119. package/dist/stream.d.ts +0 -32
  120. package/dist/stream.js +0 -95
  121. package/dist/stream.js.map +0 -1
  122. package/dist/stream.test.d.ts +0 -0
  123. package/dist/stream.test.js +0 -19
  124. package/dist/stream.test.js.map +0 -1
  125. package/src/buffer.ts +0 -17
  126. package/src/proto/apibara/node/v1alpha1/ConnectRequest.ts +0 -11
  127. package/src/proto/apibara/node/v1alpha1/ConnectResponse.ts +0 -16
  128. package/src/proto/apibara/node/v1alpha1/Data.ts +0 -14
  129. package/src/proto/apibara/node/v1alpha1/InputSyncingStatus.ts +0 -13
  130. package/src/proto/apibara/node/v1alpha1/Invalidate.ts +0 -11
  131. package/src/proto/apibara/node/v1alpha1/Node.ts +0 -37
  132. package/src/proto/apibara/node/v1alpha1/NotStartedStatus.ts +0 -8
  133. package/src/proto/apibara/node/v1alpha1/StatusRequest.ts +0 -8
  134. package/src/proto/apibara/node/v1alpha1/StatusResponse.ts +0 -19
  135. package/src/proto/apibara/node/v1alpha1/StreamMessagesRequest.ts +0 -13
  136. package/src/proto/apibara/node/v1alpha1/StreamMessagesResponse.ts +0 -21
  137. package/src/proto/apibara/node/v1alpha1/SyncedStatus.ts +0 -11
  138. package/src/proto/apibara/node/v1alpha1/SyncingStatus.ts +0 -14
  139. package/src/proto/google/protobuf/Any.ts +0 -13
  140. package/src/proto/node.proto +0 -99
  141. package/src/proto/node.ts +0 -37
  142. package/src/stream.test.ts +0 -9
  143. package/src/stream.ts +0 -127
package/dist/stream.js DELETED
@@ -1,95 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StreamMessagesStream = exports.defaultOnRetry = exports.neverRetry = void 0;
4
- const stream_1 = require("stream");
5
- const defaultMaxRetry = 3;
6
- const defaultDelaySeconds = 5;
7
- function neverRetry(_retryCount) {
8
- return {
9
- retry: false,
10
- };
11
- }
12
- exports.neverRetry = neverRetry;
13
- function defaultOnRetry(retryCount) {
14
- return {
15
- retry: retryCount < defaultMaxRetry,
16
- delay: defaultDelaySeconds,
17
- };
18
- }
19
- exports.defaultOnRetry = defaultOnRetry;
20
- class StreamMessagesStream extends stream_1.Readable {
21
- constructor({ args, onRetry, client, }) {
22
- super({ objectMode: true });
23
- this.initialRequest = args;
24
- this.client = client;
25
- this.onRetry = onRetry;
26
- this.retryCount = 0;
27
- }
28
- _construct(callback) {
29
- this.setupSource();
30
- callback();
31
- }
32
- _read(_size) {
33
- if (this.source) {
34
- // resume source data if not flowing
35
- if (!this.source.readableFlowing) {
36
- this.source.resume();
37
- }
38
- }
39
- else {
40
- // create source stream
41
- this.setupSource(this.currentSequence);
42
- }
43
- }
44
- setupSource(startingSequence) {
45
- const request = startingSequence !== undefined
46
- ? Object.assign(Object.assign({}, this.initialRequest), { startingSequence }) : this.initialRequest;
47
- this.source = this.client.streamMessages(request);
48
- this.source.on('data', this.onData.bind(this));
49
- this.source.once('error', this.onError.bind(this));
50
- this.source.once('end', this.onEnd.bind(this));
51
- }
52
- cleanupSource() {
53
- if (!this.source) {
54
- return;
55
- }
56
- this.source.off('data', this.onData.bind(this));
57
- this.source.off('error', this.onData.bind(this));
58
- this.source.off('end', this.onEnd.bind(this));
59
- }
60
- onData(chunk) {
61
- var _a;
62
- // reset retry count
63
- this.retryCount = 0;
64
- if (chunk.data) {
65
- this.currentSequence = +chunk.data.sequence;
66
- }
67
- else if (chunk.invalidate) {
68
- this.currentSequence = +chunk.invalidate;
69
- }
70
- // apply backpressure on stream
71
- if (!this.push(chunk)) {
72
- (_a = this.source) === null || _a === void 0 ? void 0 : _a.pause();
73
- }
74
- }
75
- onError(_err) {
76
- this.cleanupSource();
77
- this.retryCount += 1;
78
- const { retry, delay, startingSequence } = this.onRetry(this.retryCount);
79
- if (retry) {
80
- const intervalDelayMs = (delay !== null && delay !== void 0 ? delay : defaultDelaySeconds) * 1000;
81
- setTimeout(() => {
82
- this.setupSource(startingSequence);
83
- }, intervalDelayMs);
84
- }
85
- }
86
- onEnd() {
87
- // block streams never end
88
- if (this.retryCount > 0) {
89
- return;
90
- }
91
- this.cleanupSource();
92
- }
93
- }
94
- exports.StreamMessagesStream = StreamMessagesStream;
95
- //# sourceMappingURL=stream.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"stream.js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,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;YACrB,MAAA,IAAI,CAAC,MAAM,0CAAE,KAAK,EAAE,CAAA;SACrB;IACH,CAAC;IAED,OAAO,CAAC,IAAS;QACf,IAAI,CAAC,aAAa,EAAE,CAAA;QACpB,IAAI,CAAC,UAAU,IAAI,CAAC,CAAA;QAEpB,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,gBAAgB,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;QACxE,IAAI,KAAK,EAAE;YACT,MAAM,eAAe,GAAG,CAAC,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,mBAAmB,CAAC,GAAG,IAAI,CAAA;YAC7D,UAAU,CAAC,GAAG,EAAE;gBACd,IAAI,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAA;YACpC,CAAC,EAAE,eAAe,CAAC,CAAA;SACpB;IACH,CAAC;IAED,KAAK;QACH,0BAA0B;QAC1B,IAAI,IAAI,CAAC,UAAU,GAAG,CAAC,EAAE;YACvB,OAAM;SACP;QACD,IAAI,CAAC,aAAa,EAAE,CAAA;IACtB,CAAC;CACF;AAlGD,oDAkGC"}
File without changes
@@ -1,19 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- describe('StreamMessagesStream', () => {
12
- it('produces data', () => __awaiter(void 0, void 0, void 0, function* () { }));
13
- describe('on error', () => {
14
- it('produces an error by default', () => { });
15
- it('reconnects', () => { });
16
- it('produces an error after trying to reconnect', () => { });
17
- });
18
- });
19
- //# sourceMappingURL=stream.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"stream.test.js","sourceRoot":"","sources":["../src/stream.test.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,QAAQ,CAAC,sBAAsB,EAAE,GAAG,EAAE;IACpC,EAAE,CAAC,eAAe,EAAE,GAAS,EAAE,kDAAE,CAAC,CAAA,CAAC,CAAA;IAEnC,QAAQ,CAAC,UAAU,EAAE,GAAG,EAAE;QACxB,EAAE,CAAC,8BAA8B,EAAE,GAAG,EAAE,GAAE,CAAC,CAAC,CAAA;QAC5C,EAAE,CAAC,YAAY,EAAE,GAAG,EAAE,GAAE,CAAC,CAAC,CAAA;QAC1B,EAAE,CAAC,6CAA6C,EAAE,GAAG,EAAE,GAAE,CAAC,CAAC,CAAA;IAC7D,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
package/src/buffer.ts DELETED
@@ -1,17 +0,0 @@
1
- /**
2
- * Converts the hex-encoded bytes to a `Buffer`.
3
- * @param hex The hex string
4
- * @param size The buffer size, in bytes
5
- */
6
- export function hexToBuffer(hex: string, size: number): Buffer {
7
- const padSize = size * 2
8
- return Buffer.from(hex.replace('0x', '').padStart(padSize, '0'), 'hex')
9
- }
10
-
11
- /**
12
- * Converts the buffer to its hex representation.
13
- * @param buff the buffer
14
- */
15
- export function bufferToHex(buff: Buffer): string {
16
- return '0x' + buff.toString('hex')
17
- }
@@ -1,11 +0,0 @@
1
- // Original file: src/proto/node.proto
2
-
3
- import type { Long } from '@grpc/proto-loader';
4
-
5
- export interface ConnectRequest {
6
- 'startingSequence'?: (number | string | Long);
7
- }
8
-
9
- export interface ConnectRequest__Output {
10
- 'startingSequence': (string);
11
- }
@@ -1,16 +0,0 @@
1
- // Original file: src/proto/node.proto
2
-
3
- import type { Invalidate as _apibara_node_v1alpha1_Invalidate, Invalidate__Output as _apibara_node_v1alpha1_Invalidate__Output } from '../../../apibara/node/v1alpha1/Invalidate';
4
- import type { Data as _apibara_node_v1alpha1_Data, Data__Output as _apibara_node_v1alpha1_Data__Output } from '../../../apibara/node/v1alpha1/Data';
5
-
6
- export interface ConnectResponse {
7
- 'invalidate'?: (_apibara_node_v1alpha1_Invalidate | null);
8
- 'data'?: (_apibara_node_v1alpha1_Data | null);
9
- 'message'?: "invalidate"|"data";
10
- }
11
-
12
- export interface ConnectResponse__Output {
13
- 'invalidate'?: (_apibara_node_v1alpha1_Invalidate__Output | null);
14
- 'data'?: (_apibara_node_v1alpha1_Data__Output | null);
15
- 'message': "invalidate"|"data";
16
- }
@@ -1,14 +0,0 @@
1
- // Original file: src/proto/node.proto
2
-
3
- import type { Any as _google_protobuf_Any, Any__Output as _google_protobuf_Any__Output } from '../../../google/protobuf/Any';
4
- import type { Long } from '@grpc/proto-loader';
5
-
6
- export interface Data {
7
- 'sequence'?: (number | string | Long);
8
- 'data'?: (_google_protobuf_Any | null);
9
- }
10
-
11
- export interface Data__Output {
12
- 'sequence': (string);
13
- 'data': (_google_protobuf_Any__Output | null);
14
- }
@@ -1,13 +0,0 @@
1
- // Original file: src/proto/node.proto
2
-
3
- import type { Long } from '@grpc/proto-loader';
4
-
5
- export interface InputSyncingStatus {
6
- 'head'?: (number | string | Long);
7
- 'indexed'?: (number | string | Long);
8
- }
9
-
10
- export interface InputSyncingStatus__Output {
11
- 'head': (string);
12
- 'indexed': (string);
13
- }
@@ -1,11 +0,0 @@
1
- // Original file: src/proto/node.proto
2
-
3
- import type { Long } from '@grpc/proto-loader';
4
-
5
- export interface Invalidate {
6
- 'sequence'?: (number | string | Long);
7
- }
8
-
9
- export interface Invalidate__Output {
10
- 'sequence': (string);
11
- }
@@ -1,37 +0,0 @@
1
- // Original file: src/proto/node.proto
2
-
3
- import type * as grpc from '@grpc/grpc-js'
4
- import type { MethodDefinition } from '@grpc/proto-loader'
5
- import type { StatusRequest as _apibara_node_v1alpha1_StatusRequest, StatusRequest__Output as _apibara_node_v1alpha1_StatusRequest__Output } from '../../../apibara/node/v1alpha1/StatusRequest';
6
- import type { StatusResponse as _apibara_node_v1alpha1_StatusResponse, StatusResponse__Output as _apibara_node_v1alpha1_StatusResponse__Output } from '../../../apibara/node/v1alpha1/StatusResponse';
7
- import type { StreamMessagesRequest as _apibara_node_v1alpha1_StreamMessagesRequest, StreamMessagesRequest__Output as _apibara_node_v1alpha1_StreamMessagesRequest__Output } from '../../../apibara/node/v1alpha1/StreamMessagesRequest';
8
- import type { StreamMessagesResponse as _apibara_node_v1alpha1_StreamMessagesResponse, StreamMessagesResponse__Output as _apibara_node_v1alpha1_StreamMessagesResponse__Output } from '../../../apibara/node/v1alpha1/StreamMessagesResponse';
9
-
10
- export interface NodeClient extends grpc.Client {
11
- Status(argument: _apibara_node_v1alpha1_StatusRequest, metadata: grpc.Metadata, options: grpc.CallOptions, callback: grpc.requestCallback<_apibara_node_v1alpha1_StatusResponse__Output>): grpc.ClientUnaryCall;
12
- Status(argument: _apibara_node_v1alpha1_StatusRequest, metadata: grpc.Metadata, callback: grpc.requestCallback<_apibara_node_v1alpha1_StatusResponse__Output>): grpc.ClientUnaryCall;
13
- Status(argument: _apibara_node_v1alpha1_StatusRequest, options: grpc.CallOptions, callback: grpc.requestCallback<_apibara_node_v1alpha1_StatusResponse__Output>): grpc.ClientUnaryCall;
14
- Status(argument: _apibara_node_v1alpha1_StatusRequest, callback: grpc.requestCallback<_apibara_node_v1alpha1_StatusResponse__Output>): grpc.ClientUnaryCall;
15
- status(argument: _apibara_node_v1alpha1_StatusRequest, metadata: grpc.Metadata, options: grpc.CallOptions, callback: grpc.requestCallback<_apibara_node_v1alpha1_StatusResponse__Output>): grpc.ClientUnaryCall;
16
- status(argument: _apibara_node_v1alpha1_StatusRequest, metadata: grpc.Metadata, callback: grpc.requestCallback<_apibara_node_v1alpha1_StatusResponse__Output>): grpc.ClientUnaryCall;
17
- status(argument: _apibara_node_v1alpha1_StatusRequest, options: grpc.CallOptions, callback: grpc.requestCallback<_apibara_node_v1alpha1_StatusResponse__Output>): grpc.ClientUnaryCall;
18
- status(argument: _apibara_node_v1alpha1_StatusRequest, callback: grpc.requestCallback<_apibara_node_v1alpha1_StatusResponse__Output>): grpc.ClientUnaryCall;
19
-
20
- StreamMessages(argument: _apibara_node_v1alpha1_StreamMessagesRequest, metadata: grpc.Metadata, options?: grpc.CallOptions): grpc.ClientReadableStream<_apibara_node_v1alpha1_StreamMessagesResponse__Output>;
21
- StreamMessages(argument: _apibara_node_v1alpha1_StreamMessagesRequest, options?: grpc.CallOptions): grpc.ClientReadableStream<_apibara_node_v1alpha1_StreamMessagesResponse__Output>;
22
- streamMessages(argument: _apibara_node_v1alpha1_StreamMessagesRequest, metadata: grpc.Metadata, options?: grpc.CallOptions): grpc.ClientReadableStream<_apibara_node_v1alpha1_StreamMessagesResponse__Output>;
23
- streamMessages(argument: _apibara_node_v1alpha1_StreamMessagesRequest, options?: grpc.CallOptions): grpc.ClientReadableStream<_apibara_node_v1alpha1_StreamMessagesResponse__Output>;
24
-
25
- }
26
-
27
- export interface NodeHandlers extends grpc.UntypedServiceImplementation {
28
- Status: grpc.handleUnaryCall<_apibara_node_v1alpha1_StatusRequest__Output, _apibara_node_v1alpha1_StatusResponse>;
29
-
30
- StreamMessages: grpc.handleServerStreamingCall<_apibara_node_v1alpha1_StreamMessagesRequest__Output, _apibara_node_v1alpha1_StreamMessagesResponse>;
31
-
32
- }
33
-
34
- export interface NodeDefinition extends grpc.ServiceDefinition {
35
- Status: MethodDefinition<_apibara_node_v1alpha1_StatusRequest, _apibara_node_v1alpha1_StatusResponse, _apibara_node_v1alpha1_StatusRequest__Output, _apibara_node_v1alpha1_StatusResponse__Output>
36
- StreamMessages: MethodDefinition<_apibara_node_v1alpha1_StreamMessagesRequest, _apibara_node_v1alpha1_StreamMessagesResponse, _apibara_node_v1alpha1_StreamMessagesRequest__Output, _apibara_node_v1alpha1_StreamMessagesResponse__Output>
37
- }
@@ -1,8 +0,0 @@
1
- // Original file: src/proto/node.proto
2
-
3
-
4
- export interface NotStartedStatus {
5
- }
6
-
7
- export interface NotStartedStatus__Output {
8
- }
@@ -1,8 +0,0 @@
1
- // Original file: src/proto/node.proto
2
-
3
-
4
- export interface StatusRequest {
5
- }
6
-
7
- export interface StatusRequest__Output {
8
- }
@@ -1,19 +0,0 @@
1
- // Original file: src/proto/node.proto
2
-
3
- import type { SyncingStatus as _apibara_node_v1alpha1_SyncingStatus, SyncingStatus__Output as _apibara_node_v1alpha1_SyncingStatus__Output } from '../../../apibara/node/v1alpha1/SyncingStatus';
4
- import type { SyncedStatus as _apibara_node_v1alpha1_SyncedStatus, SyncedStatus__Output as _apibara_node_v1alpha1_SyncedStatus__Output } from '../../../apibara/node/v1alpha1/SyncedStatus';
5
- import type { NotStartedStatus as _apibara_node_v1alpha1_NotStartedStatus, NotStartedStatus__Output as _apibara_node_v1alpha1_NotStartedStatus__Output } from '../../../apibara/node/v1alpha1/NotStartedStatus';
6
-
7
- export interface StatusResponse {
8
- 'syncing'?: (_apibara_node_v1alpha1_SyncingStatus | null);
9
- 'synced'?: (_apibara_node_v1alpha1_SyncedStatus | null);
10
- 'notStarted'?: (_apibara_node_v1alpha1_NotStartedStatus | null);
11
- 'message'?: "syncing"|"synced"|"notStarted";
12
- }
13
-
14
- export interface StatusResponse__Output {
15
- 'syncing'?: (_apibara_node_v1alpha1_SyncingStatus__Output | null);
16
- 'synced'?: (_apibara_node_v1alpha1_SyncedStatus__Output | null);
17
- 'notStarted'?: (_apibara_node_v1alpha1_NotStartedStatus__Output | null);
18
- 'message': "syncing"|"synced"|"notStarted";
19
- }
@@ -1,13 +0,0 @@
1
- // Original file: src/proto/node.proto
2
-
3
- import type { Long } from '@grpc/proto-loader';
4
-
5
- export interface StreamMessagesRequest {
6
- 'startingSequence'?: (number | string | Long);
7
- 'pendingBlockIntervalSeconds'?: (number);
8
- }
9
-
10
- export interface StreamMessagesRequest__Output {
11
- 'startingSequence': (string);
12
- 'pendingBlockIntervalSeconds': (number);
13
- }
@@ -1,21 +0,0 @@
1
- // Original file: src/proto/node.proto
2
-
3
- import type { Invalidate as _apibara_node_v1alpha1_Invalidate, Invalidate__Output as _apibara_node_v1alpha1_Invalidate__Output } from '../../../apibara/node/v1alpha1/Invalidate';
4
- import type { Data as _apibara_node_v1alpha1_Data, Data__Output as _apibara_node_v1alpha1_Data__Output } from '../../../apibara/node/v1alpha1/Data';
5
- import type { Heartbeat as _apibara_node_v1alpha1_Heartbeat, Heartbeat__Output as _apibara_node_v1alpha1_Heartbeat__Output } from '../../../apibara/node/v1alpha1/Heartbeat';
6
-
7
- export interface StreamMessagesResponse {
8
- 'invalidate'?: (_apibara_node_v1alpha1_Invalidate | null);
9
- 'data'?: (_apibara_node_v1alpha1_Data | null);
10
- 'heartbeat'?: (_apibara_node_v1alpha1_Heartbeat | null);
11
- 'pending'?: (_apibara_node_v1alpha1_Data | null);
12
- 'message'?: "invalidate"|"data"|"heartbeat"|"pending";
13
- }
14
-
15
- export interface StreamMessagesResponse__Output {
16
- 'invalidate'?: (_apibara_node_v1alpha1_Invalidate__Output | null);
17
- 'data'?: (_apibara_node_v1alpha1_Data__Output | null);
18
- 'heartbeat'?: (_apibara_node_v1alpha1_Heartbeat__Output | null);
19
- 'pending'?: (_apibara_node_v1alpha1_Data__Output | null);
20
- 'message': "invalidate"|"data"|"heartbeat"|"pending";
21
- }
@@ -1,11 +0,0 @@
1
- // Original file: src/proto/node.proto
2
-
3
- import type { Long } from '@grpc/proto-loader';
4
-
5
- export interface SyncedStatus {
6
- 'sequence'?: (number | string | Long);
7
- }
8
-
9
- export interface SyncedStatus__Output {
10
- 'sequence': (string);
11
- }
@@ -1,14 +0,0 @@
1
- // Original file: src/proto/node.proto
2
-
3
- import type { InputSyncingStatus as _apibara_node_v1alpha1_InputSyncingStatus, InputSyncingStatus__Output as _apibara_node_v1alpha1_InputSyncingStatus__Output } from '../../../apibara/node/v1alpha1/InputSyncingStatus';
4
- import type { Long } from '@grpc/proto-loader';
5
-
6
- export interface SyncingStatus {
7
- 'sequence'?: (number | string | Long);
8
- 'inputs'?: (_apibara_node_v1alpha1_InputSyncingStatus)[];
9
- }
10
-
11
- export interface SyncingStatus__Output {
12
- 'sequence': (string);
13
- 'inputs': (_apibara_node_v1alpha1_InputSyncingStatus__Output)[];
14
- }
@@ -1,13 +0,0 @@
1
- // Original file: null
2
-
3
- import type { AnyExtension } from '@grpc/proto-loader';
4
-
5
- export type Any = AnyExtension | {
6
- type_url: string;
7
- value: Buffer | Uint8Array | string;
8
- }
9
-
10
- export interface Any__Output {
11
- 'type_url': (string);
12
- 'value': (Buffer);
13
- }
@@ -1,99 +0,0 @@
1
- // # Apibara Node service.
2
- syntax = "proto3";
3
-
4
- package apibara.node.v1alpha1;
5
-
6
- import "google/protobuf/any.proto";
7
-
8
- service Node {
9
- // Get information about the node and its status.
10
- rpc Status(StatusRequest) returns (StatusResponse);
11
-
12
- // Stream messages from the node.
13
- rpc StreamMessages(StreamMessagesRequest) returns (stream StreamMessagesResponse);
14
- }
15
-
16
- // Status request. It's empty.
17
- message StatusRequest {
18
- }
19
-
20
- // Status response. Returns information about the node's stream.
21
- message StatusResponse {
22
- oneof message {
23
- SyncingStatus syncing = 1;
24
- SyncedStatus synced = 2;
25
- NotStartedStatus not_started = 3;
26
- }
27
- }
28
-
29
- // Node is syncing with their sources.
30
- message SyncingStatus {
31
- // The latest sequence number.
32
- uint64 sequence = 1;
33
- // The syncing status of each input.
34
- repeated InputSyncingStatus inputs = 2;
35
- }
36
-
37
- // Syncing status of the node's input.
38
- message InputSyncingStatus {
39
- // Latest sequence number.
40
- uint64 head = 1;
41
- // Latest indexed sequenced number.
42
- uint64 indexed = 2;
43
- }
44
-
45
- // Node is fully synced.
46
- message SyncedStatus {
47
- // The latest sequence number.
48
- uint64 sequence = 1;
49
- }
50
-
51
- // Node didn't start syncing.
52
- message NotStartedStatus {
53
- }
54
-
55
- // Message sent from the client to the node.
56
- message ConnectRequest {
57
- // Start streaming from the provided sequence number.
58
- uint64 starting_sequence = 1;
59
- }
60
-
61
- // Message sent from the node to the client.
62
- message ConnectResponse {
63
- oneof message {
64
- Invalidate invalidate = 1;
65
- Data data = 2;
66
- }
67
- }
68
-
69
- // Message sent from the client to the node.
70
- message StreamMessagesRequest {
71
- // Start streaming from the provided sequence number.
72
- uint64 starting_sequence = 1;
73
- // If greater than 0, send pending blocks at the specified interval.
74
- uint32 pending_block_interval_seconds = 2;
75
- }
76
-
77
- // Message sent from the node to the client.
78
- message StreamMessagesResponse {
79
- oneof message {
80
- Invalidate invalidate = 1;
81
- Data data = 2;
82
- Heartbeat heartbeat = 3;
83
- Data pending = 4;
84
- }
85
- }
86
-
87
- // Invalidate data after (inclusive) the given sequence number.
88
- message Invalidate {
89
- uint64 sequence = 1;
90
- }
91
-
92
- message Data {
93
- uint64 sequence = 1;
94
- google.protobuf.Any data = 2;
95
- }
96
-
97
- // Sent to clients to check if stream is still connected.
98
- message Heartbeat {
99
- }
package/src/proto/node.ts DELETED
@@ -1,37 +0,0 @@
1
- import type * as grpc from '@grpc/grpc-js';
2
- import type { MessageTypeDefinition } from '@grpc/proto-loader';
3
-
4
- import type { NodeClient as _apibara_node_v1alpha1_NodeClient, NodeDefinition as _apibara_node_v1alpha1_NodeDefinition } from './apibara/node/v1alpha1/Node';
5
-
6
- type SubtypeConstructor<Constructor extends new (...args: any) => any, Subtype> = {
7
- new(...args: ConstructorParameters<Constructor>): Subtype;
8
- };
9
-
10
- export interface ProtoGrpcType {
11
- apibara: {
12
- node: {
13
- v1alpha1: {
14
- ConnectRequest: MessageTypeDefinition
15
- ConnectResponse: MessageTypeDefinition
16
- Data: MessageTypeDefinition
17
- Heartbeat: MessageTypeDefinition
18
- InputSyncingStatus: MessageTypeDefinition
19
- Invalidate: MessageTypeDefinition
20
- Node: SubtypeConstructor<typeof grpc.Client, _apibara_node_v1alpha1_NodeClient> & { service: _apibara_node_v1alpha1_NodeDefinition }
21
- NotStartedStatus: MessageTypeDefinition
22
- StatusRequest: MessageTypeDefinition
23
- StatusResponse: MessageTypeDefinition
24
- StreamMessagesRequest: MessageTypeDefinition
25
- StreamMessagesResponse: MessageTypeDefinition
26
- SyncedStatus: MessageTypeDefinition
27
- SyncingStatus: MessageTypeDefinition
28
- }
29
- }
30
- }
31
- google: {
32
- protobuf: {
33
- Any: MessageTypeDefinition
34
- }
35
- }
36
- }
37
-
@@ -1,9 +0,0 @@
1
- describe('StreamMessagesStream', () => {
2
- it('produces data', async () => {})
3
-
4
- describe('on error', () => {
5
- it('produces an error by default', () => {})
6
- it('reconnects', () => {})
7
- it('produces an error after trying to reconnect', () => {})
8
- })
9
- })
package/src/stream.ts DELETED
@@ -1,127 +0,0 @@
1
- import { Readable } from 'stream'
2
- import { ClientReadableStream } from '@grpc/grpc-js'
3
- import { NodeClient as GrpcNodeClient } from './proto/apibara/node/v1alpha1/Node'
4
- import { StreamMessagesResponse__Output } from './proto/apibara/node/v1alpha1/StreamMessagesResponse'
5
- import { StreamMessagesRequest } from './proto/apibara/node/v1alpha1/StreamMessagesRequest'
6
-
7
- const defaultMaxRetry = 3
8
- const defaultDelaySeconds = 5
9
-
10
- export function neverRetry(_retryCount: number): Retry {
11
- return {
12
- retry: false,
13
- }
14
- }
15
-
16
- export function defaultOnRetry(retryCount: number): Retry {
17
- return {
18
- retry: retryCount < defaultMaxRetry,
19
- delay: defaultDelaySeconds,
20
- }
21
- }
22
-
23
- export interface Retry {
24
- retry: boolean
25
- startingSequence?: number
26
- delay?: number
27
- }
28
-
29
- export class StreamMessagesStream extends Readable {
30
- private readonly client: GrpcNodeClient
31
- private readonly initialRequest: StreamMessagesRequest
32
- private readonly onRetry: (retryCount: number) => Retry
33
- private source?: ClientReadableStream<StreamMessagesResponse__Output>
34
- private currentSequence?: number
35
- private retryCount: number
36
-
37
- constructor({
38
- args,
39
- onRetry,
40
- client,
41
- }: {
42
- args: StreamMessagesRequest
43
- onRetry: (retryCount: number) => Retry
44
- client: GrpcNodeClient
45
- }) {
46
- super({ objectMode: true })
47
- this.initialRequest = args
48
- this.client = client
49
- this.onRetry = onRetry
50
- this.retryCount = 0
51
- }
52
-
53
- _construct(callback: (error?: Error | null | undefined) => void): void {
54
- this.setupSource()
55
- callback()
56
- }
57
-
58
- _read(_size: number): void {
59
- if (this.source) {
60
- // resume source data if not flowing
61
- if (!this.source.readableFlowing) {
62
- this.source.resume()
63
- }
64
- } else {
65
- // create source stream
66
- this.setupSource(this.currentSequence)
67
- }
68
- }
69
-
70
- setupSource(startingSequence?: number) {
71
- const request =
72
- startingSequence !== undefined
73
- ? { ...this.initialRequest, startingSequence }
74
- : this.initialRequest
75
- this.source = this.client.streamMessages(request)
76
-
77
- this.source.on('data', this.onData.bind(this))
78
- this.source.once('error', this.onError.bind(this))
79
- this.source.once('end', this.onEnd.bind(this))
80
- }
81
-
82
- cleanupSource() {
83
- if (!this.source) {
84
- return
85
- }
86
-
87
- this.source.off('data', this.onData.bind(this))
88
- this.source.off('error', this.onData.bind(this))
89
- this.source.off('end', this.onEnd.bind(this))
90
- }
91
-
92
- onData(chunk: StreamMessagesResponse__Output) {
93
- // reset retry count
94
- this.retryCount = 0
95
- if (chunk.data) {
96
- this.currentSequence = +chunk.data.sequence
97
- } else if (chunk.invalidate) {
98
- this.currentSequence = +chunk.invalidate
99
- }
100
-
101
- // apply backpressure on stream
102
- if (!this.push(chunk)) {
103
- this.source?.pause()
104
- }
105
- }
106
-
107
- onError(_err: any) {
108
- this.cleanupSource()
109
- this.retryCount += 1
110
-
111
- const { retry, delay, startingSequence } = this.onRetry(this.retryCount)
112
- if (retry) {
113
- const intervalDelayMs = (delay ?? defaultDelaySeconds) * 1000
114
- setTimeout(() => {
115
- this.setupSource(startingSequence)
116
- }, intervalDelayMs)
117
- }
118
- }
119
-
120
- onEnd() {
121
- // block streams never end
122
- if (this.retryCount > 0) {
123
- return
124
- }
125
- this.cleanupSource()
126
- }
127
- }