@apibara/protocol 2.1.0-beta.4 → 2.1.0-beta.40
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.
- package/dist/codec.cjs +242 -0
- package/dist/codec.cjs.map +1 -0
- package/dist/codec.d.cts +81 -0
- package/dist/codec.d.mts +81 -0
- package/dist/codec.d.ts +81 -0
- package/dist/codec.mjs +224 -0
- package/dist/codec.mjs.map +1 -0
- package/dist/index.cjs +43 -30
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +4 -5
- package/dist/index.d.mts +4 -5
- package/dist/index.d.ts +4 -5
- package/dist/index.mjs +40 -22
- package/dist/index.mjs.map +1 -0
- package/dist/shared/{protocol.4b1cfe2c.d.cts → protocol.0e734e33.d.cts} +400 -247
- package/dist/shared/{protocol.4b1cfe2c.d.mts → protocol.21e66b9e.d.mts} +400 -247
- package/dist/shared/{protocol.e39e40d6.cjs → protocol.53f81a1e.cjs} +177 -177
- package/dist/shared/protocol.53f81a1e.cjs.map +1 -0
- package/dist/shared/{protocol.991ff9ad.mjs → protocol.68fdd897.mjs} +176 -171
- package/dist/shared/protocol.68fdd897.mjs.map +1 -0
- package/dist/shared/{protocol.4b1cfe2c.d.ts → protocol.8fb09325.d.ts} +400 -247
- package/dist/testing/index.cjs +26 -38
- package/dist/testing/index.cjs.map +1 -0
- package/dist/testing/index.d.cts +107 -54
- package/dist/testing/index.d.mts +107 -54
- package/dist/testing/index.d.ts +107 -54
- package/dist/testing/index.mjs +26 -38
- package/dist/testing/index.mjs.map +1 -0
- package/package.json +8 -3
- package/src/client.ts +39 -14
- package/src/codec.ts +662 -0
- package/src/common.ts +70 -53
- package/src/config.ts +4 -4
- package/src/proto/google/protobuf/duration.ts +8 -6
- package/src/proto/stream.ts +38 -24
- package/src/status.ts +9 -16
- package/src/stream.ts +145 -144
- package/src/testing/mock.ts +36 -38
- package/src/common.test.ts +0 -67
- package/src/status.test.ts +0 -51
- package/src/stream.test-d.ts +0 -33
- package/src/stream.test.ts +0 -254
- package/src/testing/client.test.ts +0 -97
- package/src/testing/mock.test.ts +0 -35
package/src/stream.test.ts
DELETED
|
@@ -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
|
-
});
|
package/src/testing/mock.test.ts
DELETED
|
@@ -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
|
-
});
|