@apibara/protocol 2.1.0-beta.5 → 2.1.0-beta.50

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 (65) hide show
  1. package/dist/codec.cjs +242 -0
  2. package/dist/codec.cjs.map +1 -0
  3. package/dist/codec.d.cts +81 -0
  4. package/dist/codec.d.mts +81 -0
  5. package/dist/codec.d.ts +81 -0
  6. package/dist/codec.mjs +224 -0
  7. package/dist/codec.mjs.map +1 -0
  8. package/dist/index.cjs +45 -30
  9. package/dist/index.cjs.map +1 -0
  10. package/dist/index.d.cts +5 -5
  11. package/dist/index.d.mts +5 -5
  12. package/dist/index.d.ts +5 -5
  13. package/dist/index.mjs +41 -22
  14. package/dist/index.mjs.map +1 -0
  15. package/dist/rpc/index.cjs +12 -0
  16. package/dist/rpc/index.cjs.map +1 -0
  17. package/dist/rpc/index.d.cts +6 -0
  18. package/dist/rpc/index.d.mts +6 -0
  19. package/dist/rpc/index.d.ts +6 -0
  20. package/dist/rpc/index.mjs +3 -0
  21. package/dist/rpc/index.mjs.map +1 -0
  22. package/dist/shared/{protocol.4b1cfe2c.d.cts → protocol.0e734e33.d.cts} +400 -247
  23. package/dist/shared/{protocol.4b1cfe2c.d.mts → protocol.21e66b9e.d.mts} +400 -247
  24. package/dist/shared/{protocol.e39e40d6.cjs → protocol.53f81a1e.cjs} +177 -177
  25. package/dist/shared/protocol.53f81a1e.cjs.map +1 -0
  26. package/dist/shared/protocol.54f17699.cjs +536 -0
  27. package/dist/shared/protocol.54f17699.cjs.map +1 -0
  28. package/dist/shared/{protocol.991ff9ad.mjs → protocol.68fdd897.mjs} +176 -171
  29. package/dist/shared/protocol.68fdd897.mjs.map +1 -0
  30. package/dist/shared/protocol.6ab8d6dd.d.mts +104 -0
  31. package/dist/shared/protocol.7aa4aab6.d.cts +104 -0
  32. package/dist/shared/protocol.8407f25e.d.ts +104 -0
  33. package/dist/shared/{protocol.4b1cfe2c.d.ts → protocol.8fb09325.d.ts} +400 -247
  34. package/dist/shared/protocol.bde61588.mjs +530 -0
  35. package/dist/shared/protocol.bde61588.mjs.map +1 -0
  36. package/dist/testing/index.cjs +26 -38
  37. package/dist/testing/index.cjs.map +1 -0
  38. package/dist/testing/index.d.cts +107 -54
  39. package/dist/testing/index.d.mts +107 -54
  40. package/dist/testing/index.d.ts +107 -54
  41. package/dist/testing/index.mjs +26 -38
  42. package/dist/testing/index.mjs.map +1 -0
  43. package/package.json +14 -3
  44. package/src/client.ts +39 -14
  45. package/src/codec.ts +662 -0
  46. package/src/common.ts +70 -53
  47. package/src/config.ts +4 -4
  48. package/src/index.ts +2 -0
  49. package/src/proto/google/protobuf/duration.ts +8 -6
  50. package/src/proto/stream.ts +38 -24
  51. package/src/rpc/chain-tracker.ts +327 -0
  52. package/src/rpc/client.ts +51 -0
  53. package/src/rpc/config.ts +88 -0
  54. package/src/rpc/data-stream.ts +366 -0
  55. package/src/rpc/helpers.ts +9 -0
  56. package/src/rpc/index.ts +13 -0
  57. package/src/status.ts +9 -16
  58. package/src/stream.ts +145 -144
  59. package/src/testing/mock.ts +36 -38
  60. package/src/common.test.ts +0 -67
  61. package/src/status.test.ts +0 -51
  62. package/src/stream.test-d.ts +0 -33
  63. package/src/stream.test.ts +0 -254
  64. package/src/testing/client.test.ts +0 -97
  65. package/src/testing/mock.test.ts +0 -35
@@ -1,254 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
-
3
- import { Schema } from "@effect/schema";
4
-
5
- import {
6
- Heartbeat,
7
- Invalidate,
8
- StreamDataRequest,
9
- StreamDataResponse,
10
- SystemMessage,
11
- } from "./stream";
12
-
13
- const InnerData = Schema.Struct({
14
- value: Schema.String,
15
- });
16
-
17
- const TestData = Schema.transform(
18
- Schema.Uint8ArrayFromSelf,
19
- Schema.NullOr(InnerData),
20
- {
21
- decode(bytes) {
22
- const value = new TextDecoder().decode(bytes);
23
- return { value };
24
- },
25
- encode(value) {
26
- if (value === null) {
27
- return new Uint8Array();
28
- }
29
- return new TextEncoder().encode(value.value);
30
- },
31
- },
32
- );
33
-
34
- const TestStreamDataRequest = StreamDataRequest(TestData);
35
-
36
- const encodeTestRequest = Schema.encodeSync(TestStreamDataRequest);
37
- const decodeTestRequest = Schema.decodeSync(TestStreamDataRequest);
38
-
39
- const TestStreamDataResponse = StreamDataResponse(TestData);
40
-
41
- type TestStreamDataResponse = typeof TestStreamDataResponse.Type;
42
-
43
- const encodeTestResponse = Schema.encodeSync(TestStreamDataResponse);
44
- const decodeTestResponse = Schema.decodeSync(TestStreamDataResponse);
45
-
46
- describe("StreamDataRequest", () => {
47
- it("encodes and decodes", () => {
48
- const request = TestStreamDataRequest.make({
49
- finality: "accepted",
50
- startingCursor: {
51
- orderKey: 5_000_000n,
52
- },
53
- filter: [{ value: "hello" }, { value: "world" }],
54
- });
55
-
56
- const proto = encodeTestRequest(request);
57
- expect(proto).toMatchInlineSnapshot(`
58
- {
59
- "filter": [
60
- Uint8Array [
61
- 104,
62
- 101,
63
- 108,
64
- 108,
65
- 111,
66
- ],
67
- Uint8Array [
68
- 119,
69
- 111,
70
- 114,
71
- 108,
72
- 100,
73
- ],
74
- ],
75
- "finality": 2,
76
- "startingCursor": {
77
- "orderKey": 5000000n,
78
- "uniqueKey": Uint8Array [],
79
- },
80
- }
81
- `);
82
- const back = decodeTestRequest(proto);
83
- expect(request).toEqual(back);
84
- });
85
- });
86
-
87
- describe("StreamDataResponse", () => {
88
- const encode = encodeTestResponse;
89
- const decode = decodeTestResponse;
90
-
91
- describe(".data", () => {
92
- it("encodes and decodes", () => {
93
- const message: TestStreamDataResponse = {
94
- _tag: "data",
95
- data: {
96
- finality: "accepted",
97
- data: [{ value: "hello" }, { value: "world" }],
98
- production: "backfill",
99
- endCursor: {
100
- orderKey: 5_000_000n,
101
- uniqueKey: "0x1234567890",
102
- },
103
- },
104
- } as const;
105
-
106
- const proto = encode(message);
107
- expect(proto).toMatchInlineSnapshot(`
108
- {
109
- "$case": "data",
110
- "data": {
111
- "data": [
112
- Uint8Array [
113
- 104,
114
- 101,
115
- 108,
116
- 108,
117
- 111,
118
- ],
119
- Uint8Array [
120
- 119,
121
- 111,
122
- 114,
123
- 108,
124
- 100,
125
- ],
126
- ],
127
- "endCursor": {
128
- "orderKey": 5000000n,
129
- "uniqueKey": Uint8Array [
130
- 18,
131
- 52,
132
- 86,
133
- 120,
134
- 144,
135
- ],
136
- },
137
- "finality": 2,
138
- "production": 1,
139
- },
140
- }
141
- `);
142
- const back = decode(proto);
143
- expect(back).toEqual(message);
144
- });
145
- });
146
-
147
- describe(".invalidate", () => {
148
- it("encodes and decodes", () => {
149
- const invalidate = Invalidate.make({
150
- _tag: "invalidate",
151
- invalidate: {
152
- cursor: {
153
- orderKey: 5_000_000n,
154
- uniqueKey: "0x1234567890",
155
- },
156
- },
157
- });
158
-
159
- const proto = encode(invalidate);
160
- expect(proto).toMatchInlineSnapshot(`
161
- {
162
- "$case": "invalidate",
163
- "invalidate": {
164
- "cursor": {
165
- "orderKey": 5000000n,
166
- "uniqueKey": Uint8Array [
167
- 18,
168
- 52,
169
- 86,
170
- 120,
171
- 144,
172
- ],
173
- },
174
- },
175
- }
176
- `);
177
- const back = decode(proto);
178
- expect(back).toEqual(invalidate);
179
- });
180
- });
181
-
182
- describe(".heartbeat", () => {
183
- it("encodes and decodes", () => {
184
- const heartbeat = Heartbeat.make({
185
- _tag: "heartbeat",
186
- });
187
-
188
- const proto = encode(heartbeat);
189
- expect(proto).toMatchInlineSnapshot(`
190
- {
191
- "$case": "heartbeat",
192
- }
193
- `);
194
- const back = decode(proto);
195
- expect(back).toEqual(heartbeat);
196
- });
197
- });
198
-
199
- describe(".systemMessage", () => {
200
- it("encodes and decodes stdout", () => {
201
- const message = SystemMessage.make({
202
- _tag: "systemMessage",
203
- systemMessage: {
204
- output: {
205
- _tag: "stdout",
206
- stdout: "hello",
207
- },
208
- },
209
- });
210
-
211
- const proto = encode(message);
212
- expect(proto).toMatchInlineSnapshot(`
213
- {
214
- "$case": "systemMessage",
215
- "systemMessage": {
216
- "output": {
217
- "$case": "stdout",
218
- "stdout": "hello",
219
- },
220
- },
221
- }
222
- `);
223
- const back = decode(proto);
224
- expect(back).toEqual(message);
225
- });
226
-
227
- it("encodes and decodes stderr", () => {
228
- const message = SystemMessage.make({
229
- _tag: "systemMessage",
230
- systemMessage: {
231
- output: {
232
- _tag: "stderr",
233
- stderr: "hello",
234
- },
235
- },
236
- });
237
-
238
- const proto = encode(message);
239
- expect(proto).toMatchInlineSnapshot(`
240
- {
241
- "$case": "systemMessage",
242
- "systemMessage": {
243
- "output": {
244
- "$case": "stderr",
245
- "stderr": "hello",
246
- },
247
- },
248
- }
249
- `);
250
- const back = decode(proto);
251
- expect(back).toEqual(message);
252
- });
253
- });
254
- });
@@ -1,97 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import type { MockBlock } from "../proto/testing";
3
- import { MockClient } from "./client";
4
- import type { MockFilter } from "./mock";
5
-
6
- describe("MockClient", () => {
7
- it("returns a stream of messages", async () => {
8
- const client = new MockClient<MockFilter, MockBlock>(() => {
9
- return [
10
- {
11
- _tag: "data",
12
- data: {
13
- finality: "finalized",
14
- data: [{ data: "hello" }],
15
- production: "backfill",
16
- endCursor: {
17
- orderKey: 5_000_000n,
18
- uniqueKey: "0x1234567890",
19
- },
20
- },
21
- },
22
- ];
23
- });
24
-
25
- const output = [];
26
- for await (const m of client.streamData({ filter: [] })) {
27
- output.push(m);
28
- }
29
-
30
- expect(output).toMatchInlineSnapshot(`
31
- [
32
- {
33
- "_tag": "data",
34
- "data": {
35
- "data": [
36
- {
37
- "data": "hello",
38
- },
39
- ],
40
- "endCursor": {
41
- "orderKey": 5000000n,
42
- "uniqueKey": "0x1234567890",
43
- },
44
- "finality": "finalized",
45
- "production": "backfill",
46
- },
47
- },
48
- ]
49
- `);
50
- });
51
-
52
- it("supports factory messages", async () => {
53
- const client = new MockClient<MockFilter, MockBlock>(() => {
54
- return [
55
- {
56
- _tag: "data",
57
- data: {
58
- finality: "finalized",
59
- data: [{ data: "hello" }, null],
60
- production: "backfill",
61
- endCursor: {
62
- orderKey: 5_000_000n,
63
- uniqueKey: "0x1234567890",
64
- },
65
- },
66
- },
67
- ];
68
- });
69
-
70
- const output = [];
71
- for await (const m of client.streamData({ filter: [] })) {
72
- output.push(m);
73
- }
74
-
75
- expect(output).toMatchInlineSnapshot(`
76
- [
77
- {
78
- "_tag": "data",
79
- "data": {
80
- "data": [
81
- {
82
- "data": "hello",
83
- },
84
- null,
85
- ],
86
- "endCursor": {
87
- "orderKey": 5000000n,
88
- "uniqueKey": "0x1234567890",
89
- },
90
- "finality": "finalized",
91
- "production": "backfill",
92
- },
93
- },
94
- ]
95
- `);
96
- });
97
- });
@@ -1,35 +0,0 @@
1
- import { Schema } from "@effect/schema";
2
- import { describe, expect, it } from "vitest";
3
-
4
- import { type MockBlock, MockBlockFromBytes, MockStream } from "./mock";
5
-
6
- describe("MockBlock", () => {
7
- const encode = Schema.encodeSync(MockBlockFromBytes);
8
- const decode = Schema.decodeSync(MockBlockFromBytes);
9
-
10
- it("can be encoded and decoded", () => {
11
- const block = { data: "hello" } satisfies MockBlock;
12
-
13
- const proto = encode(block);
14
- const back = decode(proto);
15
-
16
- expect(back).toEqual(block);
17
- });
18
-
19
- it("encodes null as empty data", () => {
20
- const proto = encode(null);
21
- expect(proto).toEqual(new Uint8Array());
22
- });
23
-
24
- it("decodes empty data as null", () => {
25
- const block = decode(new Uint8Array());
26
- expect(block).toBe(null);
27
- });
28
- });
29
-
30
- describe("MockStream", () => {
31
- it("allow filters to be merged", () => {
32
- const f = MockStream.mergeFilter({ filter: "hello" }, { filter: "world" });
33
- expect(f).toEqual({ filter: "helloworld" });
34
- });
35
- });