@apibara/indexer 2.0.0-beta.9 → 2.1.0-beta.2
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/index.cjs +271 -39
- package/dist/index.d.cts +1 -16
- package/dist/index.d.mts +1 -16
- package/dist/index.d.ts +1 -16
- package/dist/index.mjs +262 -25
- package/dist/internal/index.cjs +10 -0
- package/dist/internal/index.d.cts +3 -0
- package/dist/internal/index.d.mts +3 -0
- package/dist/internal/index.d.ts +3 -0
- package/dist/internal/index.mjs +8 -0
- package/dist/internal/plugins.cjs +38 -0
- package/dist/internal/plugins.d.cts +13 -0
- package/dist/internal/plugins.d.mts +13 -0
- package/dist/internal/plugins.d.ts +13 -0
- package/dist/internal/plugins.mjs +34 -0
- package/dist/internal/testing.cjs +118 -0
- package/dist/internal/testing.d.cts +42 -0
- package/dist/internal/testing.d.mts +42 -0
- package/dist/internal/testing.d.ts +42 -0
- package/dist/internal/testing.mjs +113 -0
- package/dist/plugins/index.cjs +39 -3
- package/dist/plugins/index.d.cts +16 -2
- package/dist/plugins/index.d.mts +16 -2
- package/dist/plugins/index.d.ts +16 -2
- package/dist/plugins/index.mjs +36 -3
- package/dist/shared/indexer.077335f3.cjs +15 -0
- package/dist/shared/indexer.2416906c.cjs +29 -0
- package/dist/shared/indexer.601ceab0.cjs +7 -0
- package/dist/shared/indexer.9b21ddd2.mjs +5 -0
- package/dist/shared/indexer.a55ad619.mjs +12 -0
- package/dist/shared/indexer.fedcd831.d.cts +100 -0
- package/dist/shared/indexer.fedcd831.d.mts +100 -0
- package/dist/shared/indexer.fedcd831.d.ts +100 -0
- package/dist/shared/indexer.ff25c953.mjs +26 -0
- package/dist/testing/index.cjs +52 -50
- package/dist/testing/index.d.cts +8 -36
- package/dist/testing/index.d.mts +8 -36
- package/dist/testing/index.d.ts +8 -36
- package/dist/testing/index.mjs +47 -47
- package/dist/vcr/index.cjs +84 -17
- package/dist/vcr/index.d.cts +16 -7
- package/dist/vcr/index.d.mts +16 -7
- package/dist/vcr/index.d.ts +16 -7
- package/dist/vcr/index.mjs +75 -11
- package/package.json +22 -42
- package/src/compose.test.ts +76 -0
- package/src/compose.ts +71 -0
- package/src/context.ts +14 -8
- package/src/index.ts +0 -5
- package/src/indexer.test.ts +125 -186
- package/src/indexer.ts +278 -151
- package/src/internal/index.ts +6 -0
- package/src/internal/plugins.ts +1 -0
- package/src/internal/testing.ts +148 -0
- package/src/plugins/config.ts +4 -4
- package/src/plugins/context.ts +40 -0
- package/src/plugins/index.ts +8 -1
- package/src/plugins/logger.ts +30 -0
- package/src/plugins/persistence.ts +24 -187
- package/src/testing/index.ts +58 -3
- package/src/vcr/record.ts +5 -3
- package/src/vcr/replay.ts +8 -18
- package/dist/plugins/kv.cjs +0 -131
- package/dist/plugins/kv.d.cts +0 -32
- package/dist/plugins/kv.d.mts +0 -32
- package/dist/plugins/kv.d.ts +0 -32
- package/dist/plugins/kv.mjs +0 -124
- package/dist/plugins/persistence.cjs +0 -182
- package/dist/plugins/persistence.d.cts +0 -50
- package/dist/plugins/persistence.d.mts +0 -50
- package/dist/plugins/persistence.d.ts +0 -50
- package/dist/plugins/persistence.mjs +0 -179
- package/dist/shared/indexer.2c23c9cd.mjs +0 -35
- package/dist/shared/indexer.318d3617.cjs +0 -47
- package/dist/shared/indexer.36530330.mjs +0 -249
- package/dist/shared/indexer.500fd281.d.cts +0 -23
- package/dist/shared/indexer.541d43eb.cjs +0 -266
- package/dist/shared/indexer.93d6b2eb.mjs +0 -17
- package/dist/shared/indexer.a8b7ab1f.cjs +0 -25
- package/dist/shared/indexer.b9c8f0d8.d.cts +0 -19
- package/dist/shared/indexer.b9c8f0d8.d.mts +0 -19
- package/dist/shared/indexer.b9c8f0d8.d.ts +0 -19
- package/dist/shared/indexer.c7ed6b83.d.cts +0 -82
- package/dist/shared/indexer.e1856641.d.mts +0 -23
- package/dist/shared/indexer.e4f2430f.d.ts +0 -23
- package/dist/shared/indexer.e8bd138d.d.mts +0 -82
- package/dist/shared/indexer.f761abcd.d.ts +0 -82
- package/dist/sinks/csv.cjs +0 -85
- package/dist/sinks/csv.d.cts +0 -66
- package/dist/sinks/csv.d.mts +0 -66
- package/dist/sinks/csv.d.ts +0 -66
- package/dist/sinks/csv.mjs +0 -78
- package/dist/sinks/drizzle/index.cjs +0 -212
- package/dist/sinks/drizzle/index.d.cts +0 -153
- package/dist/sinks/drizzle/index.d.mts +0 -153
- package/dist/sinks/drizzle/index.d.ts +0 -153
- package/dist/sinks/drizzle/index.mjs +0 -198
- package/dist/sinks/sqlite.cjs +0 -90
- package/dist/sinks/sqlite.d.cts +0 -71
- package/dist/sinks/sqlite.d.mts +0 -71
- package/dist/sinks/sqlite.d.ts +0 -71
- package/dist/sinks/sqlite.mjs +0 -87
- package/src/hooks/index.ts +0 -2
- package/src/hooks/useKVStore.ts +0 -12
- package/src/hooks/useSink.ts +0 -13
- package/src/plugins/kv.test.ts +0 -120
- package/src/plugins/kv.ts +0 -132
- package/src/plugins/persistence.test.ts +0 -151
- package/src/sink.ts +0 -36
- package/src/sinks/csv.test.ts +0 -65
- package/src/sinks/csv.ts +0 -159
- package/src/sinks/drizzle/Int8Range.ts +0 -52
- package/src/sinks/drizzle/delete.ts +0 -42
- package/src/sinks/drizzle/drizzle.test.ts +0 -239
- package/src/sinks/drizzle/drizzle.ts +0 -115
- package/src/sinks/drizzle/index.ts +0 -6
- package/src/sinks/drizzle/insert.ts +0 -42
- package/src/sinks/drizzle/select.ts +0 -44
- package/src/sinks/drizzle/transaction.ts +0 -49
- package/src/sinks/drizzle/update.ts +0 -47
- package/src/sinks/drizzle/utils.ts +0 -99
- package/src/sinks/sqlite.test.ts +0 -99
- package/src/sinks/sqlite.ts +0 -170
- package/src/testing/helper.ts +0 -13
- package/src/testing/indexer.ts +0 -35
- package/src/testing/setup.ts +0 -59
- package/src/testing/vcr.ts +0 -54
package/src/context.ts
CHANGED
|
@@ -1,19 +1,25 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
import type { Cursor, DataFinality } from "@apibara/protocol";
|
|
2
3
|
import { getContext } from "unctx";
|
|
3
|
-
import type { Sink } from "./sink";
|
|
4
4
|
|
|
5
5
|
// biome-ignore lint/suspicious/noExplicitAny: context type
|
|
6
|
-
export interface IndexerContext
|
|
7
|
-
sink?: Sink<TTxnParams>;
|
|
8
|
-
sinkTransaction?: TTxnParams;
|
|
9
|
-
}
|
|
6
|
+
export interface IndexerContext extends Record<string, any> {}
|
|
10
7
|
|
|
11
8
|
export const indexerAsyncContext = getContext<IndexerContext>("indexer", {
|
|
12
9
|
asyncContext: true,
|
|
13
10
|
AsyncLocalStorage,
|
|
14
11
|
});
|
|
15
12
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
export function useIndexerContext() {
|
|
14
|
+
return indexerAsyncContext.use() as IndexerContext;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface MessageMetadataContext extends IndexerContext {
|
|
18
|
+
cursor?: Cursor;
|
|
19
|
+
endCursor?: Cursor;
|
|
20
|
+
finality?: DataFinality;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function useMessageMetadataContext(): MessageMetadataContext {
|
|
24
|
+
return useIndexerContext() as MessageMetadataContext;
|
|
19
25
|
}
|
package/src/index.ts
CHANGED
package/src/indexer.test.ts
CHANGED
|
@@ -1,15 +1,37 @@
|
|
|
1
|
+
import type { Cursor, DataFinality } from "@apibara/protocol";
|
|
1
2
|
import {
|
|
2
3
|
type MockBlock,
|
|
3
4
|
MockClient,
|
|
4
5
|
type MockFilter,
|
|
5
6
|
} from "@apibara/protocol/testing";
|
|
6
|
-
import Database from "better-sqlite3";
|
|
7
7
|
import { describe, expect, it } from "vitest";
|
|
8
|
-
import {
|
|
8
|
+
import { type IndexerContext, useMessageMetadataContext } from "./context";
|
|
9
9
|
import { run } from "./indexer";
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
import {
|
|
11
|
+
generateMockMessages,
|
|
12
|
+
getMockIndexer,
|
|
13
|
+
mockSink,
|
|
14
|
+
useMockSink,
|
|
15
|
+
} from "./internal/testing";
|
|
16
|
+
|
|
17
|
+
async function transform<TData>({
|
|
18
|
+
block: { data },
|
|
19
|
+
}: {
|
|
20
|
+
block: { data?: TData };
|
|
21
|
+
cursor?: Cursor;
|
|
22
|
+
endCursor?: Cursor;
|
|
23
|
+
finality?: DataFinality;
|
|
24
|
+
context: IndexerContext;
|
|
25
|
+
}) {
|
|
26
|
+
const { cursor, endCursor, finality } = useMessageMetadataContext();
|
|
27
|
+
const { output } = useMockSink();
|
|
28
|
+
output.push({
|
|
29
|
+
data,
|
|
30
|
+
cursor: cursor?.orderKey,
|
|
31
|
+
endCursor: endCursor?.orderKey,
|
|
32
|
+
finality,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
13
35
|
|
|
14
36
|
describe("Run Test", () => {
|
|
15
37
|
it("should stream messages", async () => {
|
|
@@ -17,121 +39,78 @@ describe("Run Test", () => {
|
|
|
17
39
|
return generateMockMessages();
|
|
18
40
|
});
|
|
19
41
|
|
|
20
|
-
const
|
|
42
|
+
const output: unknown[] = [];
|
|
21
43
|
|
|
22
44
|
const indexer = getMockIndexer({
|
|
23
|
-
sink,
|
|
24
45
|
override: {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
writer.insert([{ data }]);
|
|
28
|
-
},
|
|
46
|
+
plugins: [mockSink({ output })],
|
|
47
|
+
transform,
|
|
29
48
|
},
|
|
30
49
|
});
|
|
31
50
|
|
|
32
51
|
await run(client, indexer);
|
|
33
52
|
|
|
34
|
-
expect(
|
|
53
|
+
expect(output).toMatchInlineSnapshot(`
|
|
35
54
|
[
|
|
36
55
|
{
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
],
|
|
42
|
-
"endCursor": {
|
|
43
|
-
"orderKey": 5000000n,
|
|
44
|
-
},
|
|
56
|
+
"cursor": 4999999n,
|
|
57
|
+
"data": "5000000",
|
|
58
|
+
"endCursor": 5000000n,
|
|
59
|
+
"finality": "accepted",
|
|
45
60
|
},
|
|
46
61
|
{
|
|
47
|
-
"
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
],
|
|
52
|
-
"endCursor": {
|
|
53
|
-
"orderKey": 5000001n,
|
|
54
|
-
},
|
|
62
|
+
"cursor": 5000000n,
|
|
63
|
+
"data": "5000001",
|
|
64
|
+
"endCursor": 5000001n,
|
|
65
|
+
"finality": "accepted",
|
|
55
66
|
},
|
|
56
67
|
{
|
|
57
|
-
"
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
],
|
|
62
|
-
"endCursor": {
|
|
63
|
-
"orderKey": 5000002n,
|
|
64
|
-
},
|
|
68
|
+
"cursor": 5000001n,
|
|
69
|
+
"data": "5000002",
|
|
70
|
+
"endCursor": 5000002n,
|
|
71
|
+
"finality": "accepted",
|
|
65
72
|
},
|
|
66
73
|
{
|
|
67
|
-
"
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
],
|
|
72
|
-
"endCursor": {
|
|
73
|
-
"orderKey": 5000003n,
|
|
74
|
-
},
|
|
74
|
+
"cursor": 5000002n,
|
|
75
|
+
"data": "5000003",
|
|
76
|
+
"endCursor": 5000003n,
|
|
77
|
+
"finality": "accepted",
|
|
75
78
|
},
|
|
76
79
|
{
|
|
77
|
-
"
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
],
|
|
82
|
-
"endCursor": {
|
|
83
|
-
"orderKey": 5000004n,
|
|
84
|
-
},
|
|
80
|
+
"cursor": 5000003n,
|
|
81
|
+
"data": "5000004",
|
|
82
|
+
"endCursor": 5000004n,
|
|
83
|
+
"finality": "accepted",
|
|
85
84
|
},
|
|
86
85
|
{
|
|
87
|
-
"
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
],
|
|
92
|
-
"endCursor": {
|
|
93
|
-
"orderKey": 5000005n,
|
|
94
|
-
},
|
|
86
|
+
"cursor": 5000004n,
|
|
87
|
+
"data": "5000005",
|
|
88
|
+
"endCursor": 5000005n,
|
|
89
|
+
"finality": "accepted",
|
|
95
90
|
},
|
|
96
91
|
{
|
|
97
|
-
"
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
],
|
|
102
|
-
"endCursor": {
|
|
103
|
-
"orderKey": 5000006n,
|
|
104
|
-
},
|
|
92
|
+
"cursor": 5000005n,
|
|
93
|
+
"data": "5000006",
|
|
94
|
+
"endCursor": 5000006n,
|
|
95
|
+
"finality": "accepted",
|
|
105
96
|
},
|
|
106
97
|
{
|
|
107
|
-
"
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
],
|
|
112
|
-
"endCursor": {
|
|
113
|
-
"orderKey": 5000007n,
|
|
114
|
-
},
|
|
98
|
+
"cursor": 5000006n,
|
|
99
|
+
"data": "5000007",
|
|
100
|
+
"endCursor": 5000007n,
|
|
101
|
+
"finality": "accepted",
|
|
115
102
|
},
|
|
116
103
|
{
|
|
117
|
-
"
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
],
|
|
122
|
-
"endCursor": {
|
|
123
|
-
"orderKey": 5000008n,
|
|
124
|
-
},
|
|
104
|
+
"cursor": 5000007n,
|
|
105
|
+
"data": "5000008",
|
|
106
|
+
"endCursor": 5000008n,
|
|
107
|
+
"finality": "accepted",
|
|
125
108
|
},
|
|
126
109
|
{
|
|
127
|
-
"
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
],
|
|
132
|
-
"endCursor": {
|
|
133
|
-
"orderKey": 5000009n,
|
|
134
|
-
},
|
|
110
|
+
"cursor": 5000008n,
|
|
111
|
+
"data": "5000009",
|
|
112
|
+
"endCursor": 5000009n,
|
|
113
|
+
"finality": "accepted",
|
|
135
114
|
},
|
|
136
115
|
]
|
|
137
116
|
`);
|
|
@@ -152,6 +131,7 @@ describe("Run Test", () => {
|
|
|
152
131
|
cursor: { orderKey: 100n },
|
|
153
132
|
endCursor: { orderKey: 101n },
|
|
154
133
|
data: [null, null],
|
|
134
|
+
production: "backfill",
|
|
155
135
|
},
|
|
156
136
|
},
|
|
157
137
|
{
|
|
@@ -161,6 +141,7 @@ describe("Run Test", () => {
|
|
|
161
141
|
cursor: { orderKey: 101n },
|
|
162
142
|
endCursor: { orderKey: 102n },
|
|
163
143
|
data: [null, null],
|
|
144
|
+
production: "backfill",
|
|
164
145
|
},
|
|
165
146
|
},
|
|
166
147
|
{
|
|
@@ -170,6 +151,7 @@ describe("Run Test", () => {
|
|
|
170
151
|
cursor: { orderKey: 102n },
|
|
171
152
|
endCursor: { orderKey: 103n },
|
|
172
153
|
data: [{ data: "B" }, null],
|
|
154
|
+
production: "backfill",
|
|
173
155
|
},
|
|
174
156
|
},
|
|
175
157
|
];
|
|
@@ -186,6 +168,7 @@ describe("Run Test", () => {
|
|
|
186
168
|
cursor: { orderKey: 102n },
|
|
187
169
|
endCursor: { orderKey: 103n },
|
|
188
170
|
data: [{ data: "B" }, { data: "103B" }],
|
|
171
|
+
production: "backfill",
|
|
189
172
|
},
|
|
190
173
|
},
|
|
191
174
|
{
|
|
@@ -195,6 +178,7 @@ describe("Run Test", () => {
|
|
|
195
178
|
cursor: { orderKey: 103n },
|
|
196
179
|
endCursor: { orderKey: 104n },
|
|
197
180
|
data: [null, { data: "104B" }],
|
|
181
|
+
production: "backfill",
|
|
198
182
|
},
|
|
199
183
|
},
|
|
200
184
|
{
|
|
@@ -204,6 +188,7 @@ describe("Run Test", () => {
|
|
|
204
188
|
cursor: { orderKey: 104n },
|
|
205
189
|
endCursor: { orderKey: 105n },
|
|
206
190
|
data: [null, { data: "105B" }],
|
|
191
|
+
production: "backfill",
|
|
207
192
|
},
|
|
208
193
|
},
|
|
209
194
|
{
|
|
@@ -213,6 +198,7 @@ describe("Run Test", () => {
|
|
|
213
198
|
cursor: { orderKey: 105n },
|
|
214
199
|
endCursor: { orderKey: 106n },
|
|
215
200
|
data: [{ data: "C" }, { data: "106B" }],
|
|
201
|
+
production: "backfill",
|
|
216
202
|
},
|
|
217
203
|
},
|
|
218
204
|
];
|
|
@@ -229,6 +215,7 @@ describe("Run Test", () => {
|
|
|
229
215
|
cursor: { orderKey: 105n },
|
|
230
216
|
endCursor: { orderKey: 106n },
|
|
231
217
|
data: [{ data: "C" }, { data: "106BC" }],
|
|
218
|
+
production: "backfill",
|
|
232
219
|
},
|
|
233
220
|
},
|
|
234
221
|
{
|
|
@@ -238,6 +225,7 @@ describe("Run Test", () => {
|
|
|
238
225
|
cursor: { orderKey: 106n },
|
|
239
226
|
endCursor: { orderKey: 107n },
|
|
240
227
|
data: [null, { data: "107BC" }],
|
|
228
|
+
production: "backfill",
|
|
241
229
|
},
|
|
242
230
|
},
|
|
243
231
|
{
|
|
@@ -247,6 +235,7 @@ describe("Run Test", () => {
|
|
|
247
235
|
cursor: { orderKey: 107n },
|
|
248
236
|
endCursor: { orderKey: 108n },
|
|
249
237
|
data: [null, { data: "108BC" }],
|
|
238
|
+
production: "backfill",
|
|
250
239
|
},
|
|
251
240
|
},
|
|
252
241
|
];
|
|
@@ -255,19 +244,12 @@ describe("Run Test", () => {
|
|
|
255
244
|
return [];
|
|
256
245
|
});
|
|
257
246
|
|
|
258
|
-
const
|
|
247
|
+
const output: unknown[] = [];
|
|
248
|
+
const metadata: Record<string, unknown> = {};
|
|
259
249
|
|
|
260
|
-
const sink = vcr();
|
|
261
|
-
|
|
262
|
-
// create mock indexer with persistence plugin
|
|
263
250
|
const indexer = getMockIndexer({
|
|
264
|
-
plugins: [
|
|
265
|
-
sqlitePersistence({
|
|
266
|
-
database: db,
|
|
267
|
-
}),
|
|
268
|
-
],
|
|
269
|
-
sink,
|
|
270
251
|
override: {
|
|
252
|
+
plugins: [mockSink({ output, metadata })],
|
|
271
253
|
startingCursor: { orderKey: 100n },
|
|
272
254
|
factory: async ({ block }) => {
|
|
273
255
|
if (block.data === "B") {
|
|
@@ -280,88 +262,55 @@ describe("Run Test", () => {
|
|
|
280
262
|
|
|
281
263
|
return {};
|
|
282
264
|
},
|
|
283
|
-
transform
|
|
284
|
-
const { writer } = useSink({ context });
|
|
285
|
-
writer.insert([{ data }]);
|
|
286
|
-
},
|
|
265
|
+
transform,
|
|
287
266
|
},
|
|
288
267
|
});
|
|
289
268
|
|
|
290
269
|
await run(client, indexer);
|
|
291
270
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
const latest = store.get();
|
|
271
|
+
expect((metadata.lastCursor as Cursor).orderKey).toEqual(108n);
|
|
272
|
+
expect((metadata.lastFilter as { filter: unknown }).filter).toEqual("BC");
|
|
295
273
|
|
|
296
|
-
expect(
|
|
297
|
-
expect(latest.filter?.filter).toEqual("BC");
|
|
298
|
-
|
|
299
|
-
expect(sink.result).toMatchInlineSnapshot(`
|
|
274
|
+
expect(output).toMatchInlineSnapshot(`
|
|
300
275
|
[
|
|
301
276
|
{
|
|
302
|
-
"
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
],
|
|
307
|
-
"endCursor": {
|
|
308
|
-
"orderKey": 103n,
|
|
309
|
-
},
|
|
277
|
+
"cursor": 102n,
|
|
278
|
+
"data": "103B",
|
|
279
|
+
"endCursor": 103n,
|
|
280
|
+
"finality": "accepted",
|
|
310
281
|
},
|
|
311
282
|
{
|
|
312
|
-
"
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
],
|
|
317
|
-
"endCursor": {
|
|
318
|
-
"orderKey": 104n,
|
|
319
|
-
},
|
|
283
|
+
"cursor": 103n,
|
|
284
|
+
"data": "104B",
|
|
285
|
+
"endCursor": 104n,
|
|
286
|
+
"finality": "accepted",
|
|
320
287
|
},
|
|
321
288
|
{
|
|
322
|
-
"
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
],
|
|
327
|
-
"endCursor": {
|
|
328
|
-
"orderKey": 105n,
|
|
329
|
-
},
|
|
289
|
+
"cursor": 104n,
|
|
290
|
+
"data": "105B",
|
|
291
|
+
"endCursor": 105n,
|
|
292
|
+
"finality": "accepted",
|
|
330
293
|
},
|
|
331
294
|
{
|
|
332
|
-
"
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
],
|
|
337
|
-
"endCursor": {
|
|
338
|
-
"orderKey": 106n,
|
|
339
|
-
},
|
|
295
|
+
"cursor": 105n,
|
|
296
|
+
"data": "106BC",
|
|
297
|
+
"endCursor": 106n,
|
|
298
|
+
"finality": "accepted",
|
|
340
299
|
},
|
|
341
300
|
{
|
|
342
|
-
"
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
],
|
|
347
|
-
"endCursor": {
|
|
348
|
-
"orderKey": 107n,
|
|
349
|
-
},
|
|
301
|
+
"cursor": 106n,
|
|
302
|
+
"data": "107BC",
|
|
303
|
+
"endCursor": 107n,
|
|
304
|
+
"finality": "accepted",
|
|
350
305
|
},
|
|
351
306
|
{
|
|
352
|
-
"
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
],
|
|
357
|
-
"endCursor": {
|
|
358
|
-
"orderKey": 108n,
|
|
359
|
-
},
|
|
307
|
+
"cursor": 107n,
|
|
308
|
+
"data": "108BC",
|
|
309
|
+
"endCursor": 108n,
|
|
310
|
+
"finality": "accepted",
|
|
360
311
|
},
|
|
361
312
|
]
|
|
362
313
|
`);
|
|
363
|
-
|
|
364
|
-
db.close();
|
|
365
314
|
});
|
|
366
315
|
|
|
367
316
|
it("factory mode: last cursor should persist when error is thrown in indexer", async () => {
|
|
@@ -379,6 +328,7 @@ describe("Run Test", () => {
|
|
|
379
328
|
cursor: { orderKey: 100n },
|
|
380
329
|
endCursor: { orderKey: 101n },
|
|
381
330
|
data: [null, null],
|
|
331
|
+
production: "backfill",
|
|
382
332
|
},
|
|
383
333
|
},
|
|
384
334
|
{
|
|
@@ -388,6 +338,7 @@ describe("Run Test", () => {
|
|
|
388
338
|
cursor: { orderKey: 101n },
|
|
389
339
|
endCursor: { orderKey: 102n },
|
|
390
340
|
data: [null, null],
|
|
341
|
+
production: "backfill",
|
|
391
342
|
},
|
|
392
343
|
},
|
|
393
344
|
{
|
|
@@ -397,6 +348,7 @@ describe("Run Test", () => {
|
|
|
397
348
|
cursor: { orderKey: 102n },
|
|
398
349
|
endCursor: { orderKey: 103n },
|
|
399
350
|
data: [{ data: "B" }, null],
|
|
351
|
+
production: "backfill",
|
|
400
352
|
},
|
|
401
353
|
},
|
|
402
354
|
Error("this error should not occurr!"),
|
|
@@ -415,6 +367,7 @@ describe("Run Test", () => {
|
|
|
415
367
|
cursor: { orderKey: 103n },
|
|
416
368
|
endCursor: { orderKey: 104n },
|
|
417
369
|
data: [null, { data: "104B" }],
|
|
370
|
+
production: "backfill",
|
|
418
371
|
},
|
|
419
372
|
},
|
|
420
373
|
{
|
|
@@ -424,6 +377,7 @@ describe("Run Test", () => {
|
|
|
424
377
|
cursor: { orderKey: 104n },
|
|
425
378
|
endCursor: { orderKey: 105n },
|
|
426
379
|
data: [null, { data: "105B" }],
|
|
380
|
+
production: "backfill",
|
|
427
381
|
},
|
|
428
382
|
},
|
|
429
383
|
{
|
|
@@ -433,6 +387,7 @@ describe("Run Test", () => {
|
|
|
433
387
|
cursor: { orderKey: 105n },
|
|
434
388
|
endCursor: { orderKey: 106n },
|
|
435
389
|
data: [{ data: "C" }, { data: "106B" }],
|
|
390
|
+
production: "backfill",
|
|
436
391
|
},
|
|
437
392
|
},
|
|
438
393
|
];
|
|
@@ -441,19 +396,12 @@ describe("Run Test", () => {
|
|
|
441
396
|
return [];
|
|
442
397
|
});
|
|
443
398
|
|
|
444
|
-
const
|
|
399
|
+
const output: unknown[] = [];
|
|
400
|
+
const metadata: Record<string, unknown> = {};
|
|
445
401
|
|
|
446
|
-
const sink = vcr();
|
|
447
|
-
|
|
448
|
-
// create mock indexer with persistence plugin
|
|
449
402
|
const indexer = getMockIndexer({
|
|
450
|
-
plugins: [
|
|
451
|
-
sqlitePersistence({
|
|
452
|
-
database: db,
|
|
453
|
-
}),
|
|
454
|
-
],
|
|
455
|
-
sink,
|
|
456
403
|
override: {
|
|
404
|
+
plugins: [mockSink({ output, metadata })],
|
|
457
405
|
startingCursor: { orderKey: 100n },
|
|
458
406
|
factory: async ({ block }) => {
|
|
459
407
|
if (block.data === "B") {
|
|
@@ -466,10 +414,7 @@ describe("Run Test", () => {
|
|
|
466
414
|
|
|
467
415
|
return {};
|
|
468
416
|
},
|
|
469
|
-
transform
|
|
470
|
-
const { writer } = useSink({ context });
|
|
471
|
-
writer.insert([{ data }]);
|
|
472
|
-
},
|
|
417
|
+
transform,
|
|
473
418
|
},
|
|
474
419
|
});
|
|
475
420
|
|
|
@@ -477,15 +422,9 @@ describe("Run Test", () => {
|
|
|
477
422
|
"this error should occurr!",
|
|
478
423
|
);
|
|
479
424
|
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
const latest = store.get();
|
|
483
|
-
|
|
484
|
-
expect(latest.cursor?.orderKey).toEqual(103n);
|
|
485
|
-
expect(latest.filter?.filter).toEqual("B");
|
|
486
|
-
|
|
487
|
-
expect(sink.result).toMatchInlineSnapshot("[]");
|
|
425
|
+
expect((metadata.lastCursor as Cursor).orderKey).toEqual(103n);
|
|
426
|
+
expect((metadata.lastFilter as { filter: unknown }).filter).toEqual("B");
|
|
488
427
|
|
|
489
|
-
|
|
428
|
+
expect(output).toMatchInlineSnapshot("[]");
|
|
490
429
|
});
|
|
491
430
|
});
|