@apibara/indexer 2.1.0-beta.3 → 2.1.0-beta.30
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 +70 -26
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +60 -16
- package/dist/internal/plugins.cjs +3 -4
- package/dist/internal/plugins.d.cts +1 -1
- package/dist/internal/plugins.d.mts +1 -1
- package/dist/internal/plugins.d.ts +1 -1
- package/dist/internal/plugins.mjs +1 -2
- package/dist/internal/testing.cjs +24 -10
- package/dist/internal/testing.d.cts +5 -3
- package/dist/internal/testing.d.mts +5 -3
- package/dist/internal/testing.d.ts +5 -3
- package/dist/internal/testing.mjs +22 -8
- package/dist/plugins/index.cjs +3 -4
- package/dist/plugins/index.d.cts +2 -2
- package/dist/plugins/index.d.mts +2 -2
- package/dist/plugins/index.d.ts +2 -2
- package/dist/plugins/index.mjs +3 -4
- package/dist/shared/{indexer.077335f3.cjs → indexer.479ae593.cjs} +5 -0
- package/dist/shared/{indexer.a55ad619.mjs → indexer.75773ef1.mjs} +5 -1
- package/dist/shared/{indexer.fedcd831.d.cts → indexer.7668fe34.d.cts} +2 -4
- package/dist/shared/{indexer.fedcd831.d.mts → indexer.7668fe34.d.mts} +2 -4
- package/dist/shared/{indexer.fedcd831.d.ts → indexer.7668fe34.d.ts} +2 -4
- package/dist/shared/{indexer.ff25c953.mjs → indexer.98a921a7.mjs} +1 -2
- package/dist/shared/{indexer.2416906c.cjs → indexer.a09fa402.cjs} +3 -4
- package/dist/testing/index.cjs +9 -5
- package/dist/testing/index.d.cts +4 -3
- package/dist/testing/index.d.mts +4 -3
- package/dist/testing/index.d.ts +4 -3
- package/dist/testing/index.mjs +9 -5
- package/dist/vcr/index.cjs +2 -1
- package/dist/vcr/index.d.cts +1 -1
- package/dist/vcr/index.d.mts +1 -1
- package/dist/vcr/index.d.ts +1 -1
- package/dist/vcr/index.mjs +2 -1
- package/package.json +3 -3
- package/src/indexer.ts +47 -15
- package/src/internal/testing.ts +34 -11
- package/src/otel.ts +29 -2
- package/src/testing/index.ts +11 -0
- package/dist/shared/indexer.601ceab0.cjs +0 -7
- package/dist/shared/indexer.9b21ddd2.mjs +0 -5
- package/src/compose.test.ts +0 -76
- package/src/indexer.test.ts +0 -430
package/dist/index.cjs
CHANGED
|
@@ -4,8 +4,9 @@ const protocol = require('@apibara/protocol');
|
|
|
4
4
|
const consola = require('consola');
|
|
5
5
|
const hookable = require('hookable');
|
|
6
6
|
const assert = require('node:assert');
|
|
7
|
-
const
|
|
7
|
+
const config = require('./shared/indexer.479ae593.cjs');
|
|
8
8
|
const api = require('@opentelemetry/api');
|
|
9
|
+
const internal_plugins = require('./internal/plugins.cjs');
|
|
9
10
|
require('node:async_hooks');
|
|
10
11
|
require('unctx');
|
|
11
12
|
|
|
@@ -43,7 +44,29 @@ function compose(middleware) {
|
|
|
43
44
|
};
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
|
|
47
|
+
function createTracer() {
|
|
48
|
+
return api.trace.getTracer("@apibara/indexer");
|
|
49
|
+
}
|
|
50
|
+
function createIndexerMetrics() {
|
|
51
|
+
const meter = api.metrics.getMeter("@apibara/indexer");
|
|
52
|
+
const currentBlockGauge = meter.createGauge("current_block", {
|
|
53
|
+
description: "Current block number being processed",
|
|
54
|
+
unit: "{block}"
|
|
55
|
+
});
|
|
56
|
+
const processedBlockCounter = meter.createCounter("processed_blocks", {
|
|
57
|
+
description: "Number of blocks processed",
|
|
58
|
+
unit: "{blocks}"
|
|
59
|
+
});
|
|
60
|
+
const reorgCounter = meter.createCounter("reorgs", {
|
|
61
|
+
description: "Number of reorgs (invalidate messages) received",
|
|
62
|
+
unit: "{reorgs}"
|
|
63
|
+
});
|
|
64
|
+
return {
|
|
65
|
+
currentBlockGauge,
|
|
66
|
+
processedBlockCounter,
|
|
67
|
+
reorgCounter
|
|
68
|
+
};
|
|
69
|
+
}
|
|
47
70
|
|
|
48
71
|
function defineIndexer(streamConfig) {
|
|
49
72
|
return (config) => ({
|
|
@@ -85,13 +108,15 @@ async function runWithReconnect(client, indexer, options = {}) {
|
|
|
85
108
|
return;
|
|
86
109
|
} catch (error) {
|
|
87
110
|
retryCount++;
|
|
88
|
-
if (error instanceof protocol.ClientError) {
|
|
111
|
+
if (error instanceof protocol.ClientError || error instanceof protocol.ServerError) {
|
|
112
|
+
const isServerError = error instanceof protocol.ServerError;
|
|
89
113
|
if (error.code === protocol.Status.INTERNAL) {
|
|
90
114
|
if (retryCount < maxRetries) {
|
|
91
115
|
consola__default.error(
|
|
92
|
-
|
|
93
|
-
error.message
|
|
116
|
+
`Internal ${isServerError ? "server" : "client"} error: ${error.message}`
|
|
94
117
|
);
|
|
118
|
+
consola__default.start("Reconnecting...");
|
|
119
|
+
console.log();
|
|
95
120
|
const delay = Math.random() * (retryDelay * 0.2) + retryDelay;
|
|
96
121
|
await new Promise(
|
|
97
122
|
(resolve) => setTimeout(resolve, Math.min(retryCount * delay, maxWait))
|
|
@@ -105,10 +130,13 @@ async function runWithReconnect(client, indexer, options = {}) {
|
|
|
105
130
|
}
|
|
106
131
|
}
|
|
107
132
|
async function run(client, indexer, runOptions = {}) {
|
|
108
|
-
await
|
|
109
|
-
const context
|
|
133
|
+
await config.indexerAsyncContext.callAsync({}, async () => {
|
|
134
|
+
const context = config.useIndexerContext();
|
|
110
135
|
const middleware = await registerMiddleware(indexer);
|
|
136
|
+
const indexerMetrics = createIndexerMetrics();
|
|
137
|
+
const tracer = createTracer();
|
|
111
138
|
await indexer.hooks.callHook("run:before");
|
|
139
|
+
const { indexerName: indexerId } = internal_plugins.useInternalContext();
|
|
112
140
|
const isFactoryMode = indexer.options.factory !== void 0;
|
|
113
141
|
let startingCursor;
|
|
114
142
|
if (indexer.options.startingCursor) {
|
|
@@ -122,11 +150,11 @@ async function run(client, indexer, runOptions = {}) {
|
|
|
122
150
|
};
|
|
123
151
|
}
|
|
124
152
|
}
|
|
125
|
-
const request =
|
|
153
|
+
const request = {
|
|
126
154
|
filter: isFactoryMode ? [indexer.options.filter, {}] : [indexer.options.filter],
|
|
127
155
|
finality: indexer.options.finality,
|
|
128
156
|
startingCursor
|
|
129
|
-
}
|
|
157
|
+
};
|
|
130
158
|
const options = {};
|
|
131
159
|
await indexer.hooks.callHook("connect:before", { request, options });
|
|
132
160
|
let mainFilter;
|
|
@@ -153,30 +181,36 @@ async function run(client, indexer, runOptions = {}) {
|
|
|
153
181
|
await tracer.startActiveSpan("message data", async (span) => {
|
|
154
182
|
const blocks = message.data.data;
|
|
155
183
|
const { cursor, endCursor, finality } = message.data;
|
|
156
|
-
context
|
|
157
|
-
context
|
|
158
|
-
context
|
|
159
|
-
|
|
184
|
+
context.cursor = cursor;
|
|
185
|
+
context.endCursor = endCursor;
|
|
186
|
+
context.finality = finality;
|
|
187
|
+
indexerMetrics.currentBlockGauge.record(
|
|
188
|
+
Number(endCursor?.orderKey),
|
|
189
|
+
{
|
|
190
|
+
indexer_id: indexerId
|
|
191
|
+
}
|
|
192
|
+
);
|
|
193
|
+
await middleware(context, async () => {
|
|
160
194
|
let block;
|
|
161
|
-
if (isFactoryMode) {
|
|
195
|
+
if (isFactoryMode && finality !== "pending") {
|
|
162
196
|
assert__default(indexer.options.factory !== void 0);
|
|
163
197
|
const [factoryBlock, mainBlock] = blocks;
|
|
164
198
|
block = mainBlock;
|
|
165
199
|
if (factoryBlock !== null) {
|
|
166
200
|
const { filter } = await indexer.options.factory({
|
|
167
201
|
block: factoryBlock,
|
|
168
|
-
context
|
|
202
|
+
context
|
|
169
203
|
});
|
|
170
204
|
if (filter) {
|
|
171
205
|
mainFilter = indexer.streamConfig.mergeFilter(
|
|
172
206
|
mainFilter,
|
|
173
207
|
filter
|
|
174
208
|
);
|
|
175
|
-
const request2 =
|
|
209
|
+
const request2 = {
|
|
176
210
|
filter: [indexer.options.filter, mainFilter],
|
|
177
211
|
finality: indexer.options.finality,
|
|
178
212
|
startingCursor: cursor
|
|
179
|
-
}
|
|
213
|
+
};
|
|
180
214
|
await indexer.hooks.callHook("connect:factory", {
|
|
181
215
|
request: request2,
|
|
182
216
|
endCursor
|
|
@@ -198,7 +232,7 @@ async function run(client, indexer, runOptions = {}) {
|
|
|
198
232
|
cursor,
|
|
199
233
|
endCursor,
|
|
200
234
|
finality,
|
|
201
|
-
context
|
|
235
|
+
context
|
|
202
236
|
});
|
|
203
237
|
span2.end();
|
|
204
238
|
});
|
|
@@ -206,28 +240,38 @@ async function run(client, indexer, runOptions = {}) {
|
|
|
206
240
|
});
|
|
207
241
|
span.end();
|
|
208
242
|
});
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
243
|
+
indexerMetrics.processedBlockCounter.add(1, {
|
|
244
|
+
indexer_id: indexerId
|
|
245
|
+
});
|
|
246
|
+
context.cursor = void 0;
|
|
247
|
+
context.endCursor = void 0;
|
|
248
|
+
context.finality = void 0;
|
|
212
249
|
break;
|
|
213
250
|
}
|
|
214
251
|
case "invalidate": {
|
|
215
252
|
await tracer.startActiveSpan("message invalidate", async (span) => {
|
|
216
|
-
|
|
253
|
+
indexerMetrics.reorgCounter.add(1, {
|
|
254
|
+
indexer_id: indexerId
|
|
255
|
+
});
|
|
256
|
+
await indexer.hooks.callHook("message:invalidate", {
|
|
257
|
+
message: message.invalidate
|
|
258
|
+
});
|
|
217
259
|
span.end();
|
|
218
260
|
});
|
|
219
261
|
break;
|
|
220
262
|
}
|
|
221
263
|
case "finalize": {
|
|
222
264
|
await tracer.startActiveSpan("message finalize", async (span) => {
|
|
223
|
-
await indexer.hooks.callHook("message:finalize", {
|
|
265
|
+
await indexer.hooks.callHook("message:finalize", {
|
|
266
|
+
message: message.finalize
|
|
267
|
+
});
|
|
224
268
|
span.end();
|
|
225
269
|
});
|
|
226
270
|
break;
|
|
227
271
|
}
|
|
228
272
|
case "heartbeat": {
|
|
229
273
|
await tracer.startActiveSpan("message heartbeat", async (span) => {
|
|
230
|
-
await indexer.hooks.callHook("message:heartbeat"
|
|
274
|
+
await indexer.hooks.callHook("message:heartbeat");
|
|
231
275
|
span.end();
|
|
232
276
|
});
|
|
233
277
|
break;
|
|
@@ -247,7 +291,7 @@ async function run(client, indexer, runOptions = {}) {
|
|
|
247
291
|
}
|
|
248
292
|
}
|
|
249
293
|
await indexer.hooks.callHook("message:systemMessage", {
|
|
250
|
-
message
|
|
294
|
+
message: message.systemMessage
|
|
251
295
|
});
|
|
252
296
|
span.end();
|
|
253
297
|
}
|
|
@@ -275,7 +319,7 @@ async function registerMiddleware(indexer) {
|
|
|
275
319
|
};
|
|
276
320
|
}
|
|
277
321
|
|
|
278
|
-
exports.useIndexerContext =
|
|
322
|
+
exports.useIndexerContext = config.useIndexerContext;
|
|
279
323
|
exports.createIndexer = createIndexer;
|
|
280
324
|
exports.defineIndexer = defineIndexer;
|
|
281
325
|
exports.run = run;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { a as Indexer, c as IndexerConfig, e as IndexerHooks, f as IndexerStartingCursor, I as IndexerWithStreamConfig, R as ReconnectOptions, i as RunOptions, U as UseMiddlewareFunction, h as createIndexer, g as defineIndexer, j as run, r as runWithReconnect, u as useIndexerContext } from './shared/indexer.
|
|
1
|
+
export { a as Indexer, c as IndexerConfig, e as IndexerHooks, f as IndexerStartingCursor, I as IndexerWithStreamConfig, R as ReconnectOptions, i as RunOptions, U as UseMiddlewareFunction, h as createIndexer, g as defineIndexer, j as run, r as runWithReconnect, u as useIndexerContext } from './shared/indexer.7668fe34.cjs';
|
|
2
2
|
import '@apibara/protocol';
|
|
3
3
|
import 'hookable';
|
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { a as Indexer, c as IndexerConfig, e as IndexerHooks, f as IndexerStartingCursor, I as IndexerWithStreamConfig, R as ReconnectOptions, i as RunOptions, U as UseMiddlewareFunction, h as createIndexer, g as defineIndexer, j as run, r as runWithReconnect, u as useIndexerContext } from './shared/indexer.
|
|
1
|
+
export { a as Indexer, c as IndexerConfig, e as IndexerHooks, f as IndexerStartingCursor, I as IndexerWithStreamConfig, R as ReconnectOptions, i as RunOptions, U as UseMiddlewareFunction, h as createIndexer, g as defineIndexer, j as run, r as runWithReconnect, u as useIndexerContext } from './shared/indexer.7668fe34.mjs';
|
|
2
2
|
import '@apibara/protocol';
|
|
3
3
|
import 'hookable';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { a as Indexer, c as IndexerConfig, e as IndexerHooks, f as IndexerStartingCursor, I as IndexerWithStreamConfig, R as ReconnectOptions, i as RunOptions, U as UseMiddlewareFunction, h as createIndexer, g as defineIndexer, j as run, r as runWithReconnect, u as useIndexerContext } from './shared/indexer.
|
|
1
|
+
export { a as Indexer, c as IndexerConfig, e as IndexerHooks, f as IndexerStartingCursor, I as IndexerWithStreamConfig, R as ReconnectOptions, i as RunOptions, U as UseMiddlewareFunction, h as createIndexer, g as defineIndexer, j as run, r as runWithReconnect, u as useIndexerContext } from './shared/indexer.7668fe34.js';
|
|
2
2
|
import '@apibara/protocol';
|
|
3
3
|
import 'hookable';
|
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { ClientError, Status } from '@apibara/protocol';
|
|
1
|
+
import { ClientError, ServerError, Status } from '@apibara/protocol';
|
|
2
2
|
import consola from 'consola';
|
|
3
3
|
import { createHooks, createDebugger } from 'hookable';
|
|
4
4
|
import assert from 'node:assert';
|
|
5
|
-
import { i as indexerAsyncContext, u as useIndexerContext } from './shared/indexer.
|
|
6
|
-
import { trace } from '@opentelemetry/api';
|
|
5
|
+
import { i as indexerAsyncContext, u as useIndexerContext } from './shared/indexer.75773ef1.mjs';
|
|
6
|
+
import { trace, metrics } from '@opentelemetry/api';
|
|
7
|
+
import { useInternalContext } from './internal/plugins.mjs';
|
|
7
8
|
import 'node:async_hooks';
|
|
8
9
|
import 'unctx';
|
|
9
10
|
|
|
@@ -36,7 +37,29 @@ function compose(middleware) {
|
|
|
36
37
|
};
|
|
37
38
|
}
|
|
38
39
|
|
|
39
|
-
|
|
40
|
+
function createTracer() {
|
|
41
|
+
return trace.getTracer("@apibara/indexer");
|
|
42
|
+
}
|
|
43
|
+
function createIndexerMetrics() {
|
|
44
|
+
const meter = metrics.getMeter("@apibara/indexer");
|
|
45
|
+
const currentBlockGauge = meter.createGauge("current_block", {
|
|
46
|
+
description: "Current block number being processed",
|
|
47
|
+
unit: "{block}"
|
|
48
|
+
});
|
|
49
|
+
const processedBlockCounter = meter.createCounter("processed_blocks", {
|
|
50
|
+
description: "Number of blocks processed",
|
|
51
|
+
unit: "{blocks}"
|
|
52
|
+
});
|
|
53
|
+
const reorgCounter = meter.createCounter("reorgs", {
|
|
54
|
+
description: "Number of reorgs (invalidate messages) received",
|
|
55
|
+
unit: "{reorgs}"
|
|
56
|
+
});
|
|
57
|
+
return {
|
|
58
|
+
currentBlockGauge,
|
|
59
|
+
processedBlockCounter,
|
|
60
|
+
reorgCounter
|
|
61
|
+
};
|
|
62
|
+
}
|
|
40
63
|
|
|
41
64
|
function defineIndexer(streamConfig) {
|
|
42
65
|
return (config) => ({
|
|
@@ -78,13 +101,15 @@ async function runWithReconnect(client, indexer, options = {}) {
|
|
|
78
101
|
return;
|
|
79
102
|
} catch (error) {
|
|
80
103
|
retryCount++;
|
|
81
|
-
if (error instanceof ClientError) {
|
|
104
|
+
if (error instanceof ClientError || error instanceof ServerError) {
|
|
105
|
+
const isServerError = error instanceof ServerError;
|
|
82
106
|
if (error.code === Status.INTERNAL) {
|
|
83
107
|
if (retryCount < maxRetries) {
|
|
84
108
|
consola.error(
|
|
85
|
-
|
|
86
|
-
error.message
|
|
109
|
+
`Internal ${isServerError ? "server" : "client"} error: ${error.message}`
|
|
87
110
|
);
|
|
111
|
+
consola.start("Reconnecting...");
|
|
112
|
+
console.log();
|
|
88
113
|
const delay = Math.random() * (retryDelay * 0.2) + retryDelay;
|
|
89
114
|
await new Promise(
|
|
90
115
|
(resolve) => setTimeout(resolve, Math.min(retryCount * delay, maxWait))
|
|
@@ -101,7 +126,10 @@ async function run(client, indexer, runOptions = {}) {
|
|
|
101
126
|
await indexerAsyncContext.callAsync({}, async () => {
|
|
102
127
|
const context = useIndexerContext();
|
|
103
128
|
const middleware = await registerMiddleware(indexer);
|
|
129
|
+
const indexerMetrics = createIndexerMetrics();
|
|
130
|
+
const tracer = createTracer();
|
|
104
131
|
await indexer.hooks.callHook("run:before");
|
|
132
|
+
const { indexerName: indexerId } = useInternalContext();
|
|
105
133
|
const isFactoryMode = indexer.options.factory !== void 0;
|
|
106
134
|
let startingCursor;
|
|
107
135
|
if (indexer.options.startingCursor) {
|
|
@@ -115,11 +143,11 @@ async function run(client, indexer, runOptions = {}) {
|
|
|
115
143
|
};
|
|
116
144
|
}
|
|
117
145
|
}
|
|
118
|
-
const request =
|
|
146
|
+
const request = {
|
|
119
147
|
filter: isFactoryMode ? [indexer.options.filter, {}] : [indexer.options.filter],
|
|
120
148
|
finality: indexer.options.finality,
|
|
121
149
|
startingCursor
|
|
122
|
-
}
|
|
150
|
+
};
|
|
123
151
|
const options = {};
|
|
124
152
|
await indexer.hooks.callHook("connect:before", { request, options });
|
|
125
153
|
let mainFilter;
|
|
@@ -149,9 +177,15 @@ async function run(client, indexer, runOptions = {}) {
|
|
|
149
177
|
context.cursor = cursor;
|
|
150
178
|
context.endCursor = endCursor;
|
|
151
179
|
context.finality = finality;
|
|
180
|
+
indexerMetrics.currentBlockGauge.record(
|
|
181
|
+
Number(endCursor?.orderKey),
|
|
182
|
+
{
|
|
183
|
+
indexer_id: indexerId
|
|
184
|
+
}
|
|
185
|
+
);
|
|
152
186
|
await middleware(context, async () => {
|
|
153
187
|
let block;
|
|
154
|
-
if (isFactoryMode) {
|
|
188
|
+
if (isFactoryMode && finality !== "pending") {
|
|
155
189
|
assert(indexer.options.factory !== void 0);
|
|
156
190
|
const [factoryBlock, mainBlock] = blocks;
|
|
157
191
|
block = mainBlock;
|
|
@@ -165,11 +199,11 @@ async function run(client, indexer, runOptions = {}) {
|
|
|
165
199
|
mainFilter,
|
|
166
200
|
filter
|
|
167
201
|
);
|
|
168
|
-
const request2 =
|
|
202
|
+
const request2 = {
|
|
169
203
|
filter: [indexer.options.filter, mainFilter],
|
|
170
204
|
finality: indexer.options.finality,
|
|
171
205
|
startingCursor: cursor
|
|
172
|
-
}
|
|
206
|
+
};
|
|
173
207
|
await indexer.hooks.callHook("connect:factory", {
|
|
174
208
|
request: request2,
|
|
175
209
|
endCursor
|
|
@@ -199,6 +233,9 @@ async function run(client, indexer, runOptions = {}) {
|
|
|
199
233
|
});
|
|
200
234
|
span.end();
|
|
201
235
|
});
|
|
236
|
+
indexerMetrics.processedBlockCounter.add(1, {
|
|
237
|
+
indexer_id: indexerId
|
|
238
|
+
});
|
|
202
239
|
context.cursor = void 0;
|
|
203
240
|
context.endCursor = void 0;
|
|
204
241
|
context.finality = void 0;
|
|
@@ -206,21 +243,28 @@ async function run(client, indexer, runOptions = {}) {
|
|
|
206
243
|
}
|
|
207
244
|
case "invalidate": {
|
|
208
245
|
await tracer.startActiveSpan("message invalidate", async (span) => {
|
|
209
|
-
|
|
246
|
+
indexerMetrics.reorgCounter.add(1, {
|
|
247
|
+
indexer_id: indexerId
|
|
248
|
+
});
|
|
249
|
+
await indexer.hooks.callHook("message:invalidate", {
|
|
250
|
+
message: message.invalidate
|
|
251
|
+
});
|
|
210
252
|
span.end();
|
|
211
253
|
});
|
|
212
254
|
break;
|
|
213
255
|
}
|
|
214
256
|
case "finalize": {
|
|
215
257
|
await tracer.startActiveSpan("message finalize", async (span) => {
|
|
216
|
-
await indexer.hooks.callHook("message:finalize", {
|
|
258
|
+
await indexer.hooks.callHook("message:finalize", {
|
|
259
|
+
message: message.finalize
|
|
260
|
+
});
|
|
217
261
|
span.end();
|
|
218
262
|
});
|
|
219
263
|
break;
|
|
220
264
|
}
|
|
221
265
|
case "heartbeat": {
|
|
222
266
|
await tracer.startActiveSpan("message heartbeat", async (span) => {
|
|
223
|
-
await indexer.hooks.callHook("message:heartbeat"
|
|
267
|
+
await indexer.hooks.callHook("message:heartbeat");
|
|
224
268
|
span.end();
|
|
225
269
|
});
|
|
226
270
|
break;
|
|
@@ -240,7 +284,7 @@ async function run(client, indexer, runOptions = {}) {
|
|
|
240
284
|
}
|
|
241
285
|
}
|
|
242
286
|
await indexer.hooks.callHook("message:systemMessage", {
|
|
243
|
-
message
|
|
287
|
+
message: message.systemMessage
|
|
244
288
|
});
|
|
245
289
|
span.end();
|
|
246
290
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const config = require('../shared/indexer.601ceab0.cjs');
|
|
3
|
+
const config = require('../shared/indexer.479ae593.cjs');
|
|
5
4
|
require('node:async_hooks');
|
|
6
5
|
require('unctx');
|
|
7
6
|
|
|
@@ -10,7 +9,7 @@ function internalContext(values) {
|
|
|
10
9
|
return config.defineIndexerPlugin((indexer) => {
|
|
11
10
|
indexer.hooks.hook("run:before", () => {
|
|
12
11
|
try {
|
|
13
|
-
const ctx =
|
|
12
|
+
const ctx = config.useIndexerContext();
|
|
14
13
|
ctx[INTERNAL_CONTEXT_PROPERTY] = {
|
|
15
14
|
...ctx[INTERNAL_CONTEXT_PROPERTY] || {},
|
|
16
15
|
...values
|
|
@@ -24,7 +23,7 @@ function internalContext(values) {
|
|
|
24
23
|
});
|
|
25
24
|
}
|
|
26
25
|
function useInternalContext() {
|
|
27
|
-
const ctx =
|
|
26
|
+
const ctx = config.useIndexerContext();
|
|
28
27
|
if (ctx[INTERNAL_CONTEXT_PROPERTY] === void 0) {
|
|
29
28
|
throw new Error(
|
|
30
29
|
"Internal context is not available, possibly 'internalContext' plugin is missing!"
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { u as useIndexerContext } from '../shared/indexer.
|
|
2
|
-
import { d as defineIndexerPlugin } from '../shared/indexer.9b21ddd2.mjs';
|
|
1
|
+
import { d as defineIndexerPlugin, u as useIndexerContext } from '../shared/indexer.75773ef1.mjs';
|
|
3
2
|
import 'node:async_hooks';
|
|
4
3
|
import 'unctx';
|
|
5
4
|
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
const protocol = require('@apibara/protocol');
|
|
4
4
|
const testing = require('@apibara/protocol/testing');
|
|
5
|
-
const
|
|
5
|
+
const config = require('../shared/indexer.479ae593.cjs');
|
|
6
6
|
const index = require('../index.cjs');
|
|
7
|
-
const
|
|
8
|
-
require('consola');
|
|
7
|
+
const logger = require('../shared/indexer.a09fa402.cjs');
|
|
9
8
|
const internal_plugins = require('./plugins.cjs');
|
|
10
9
|
require('node:async_hooks');
|
|
11
10
|
require('unctx');
|
|
11
|
+
require('consola');
|
|
12
12
|
require('hookable');
|
|
13
13
|
require('node:assert');
|
|
14
14
|
require('@opentelemetry/api');
|
|
@@ -17,22 +17,29 @@ function generateMockMessages(count = 10, options) {
|
|
|
17
17
|
const invalidateAt = options?.invalidate;
|
|
18
18
|
const finalizeAt = options?.finalize;
|
|
19
19
|
const messages = [];
|
|
20
|
+
const baseBlockNumber = options?.baseBlockNumber ?? BigInt(5e6);
|
|
20
21
|
for (let i = 0; i < count; i++) {
|
|
22
|
+
const currentBlockNumber = baseBlockNumber + BigInt(i);
|
|
23
|
+
const uniqueKey = uniqueKeyFromOrderKey(currentBlockNumber);
|
|
21
24
|
if (invalidateAt && i === invalidateAt.invalidateTriggerIndex) {
|
|
25
|
+
const invalidateToBlock = baseBlockNumber + BigInt(invalidateAt.invalidateFromIndex);
|
|
22
26
|
messages.push({
|
|
23
27
|
_tag: "invalidate",
|
|
24
28
|
invalidate: {
|
|
25
29
|
cursor: {
|
|
26
|
-
orderKey:
|
|
30
|
+
orderKey: invalidateToBlock,
|
|
31
|
+
uniqueKey: options?.uniqueKey ? uniqueKeyFromOrderKey(invalidateToBlock) : void 0
|
|
27
32
|
}
|
|
28
33
|
}
|
|
29
34
|
});
|
|
30
35
|
} else if (finalizeAt && i === finalizeAt.finalizeTriggerIndex) {
|
|
36
|
+
const fianlizedToBlock = baseBlockNumber + BigInt(finalizeAt.finalizeToIndex);
|
|
31
37
|
messages.push({
|
|
32
38
|
_tag: "finalize",
|
|
33
39
|
finalize: {
|
|
34
40
|
cursor: {
|
|
35
|
-
orderKey:
|
|
41
|
+
orderKey: fianlizedToBlock,
|
|
42
|
+
uniqueKey: options?.uniqueKey ? uniqueKeyFromOrderKey(fianlizedToBlock) : void 0
|
|
36
43
|
}
|
|
37
44
|
}
|
|
38
45
|
});
|
|
@@ -40,10 +47,13 @@ function generateMockMessages(count = 10, options) {
|
|
|
40
47
|
messages.push({
|
|
41
48
|
_tag: "data",
|
|
42
49
|
data: {
|
|
43
|
-
cursor: { orderKey:
|
|
50
|
+
cursor: { orderKey: currentBlockNumber - 1n },
|
|
44
51
|
finality: "accepted",
|
|
45
|
-
data: [{ data: `${
|
|
46
|
-
endCursor: {
|
|
52
|
+
data: [{ data: `${baseBlockNumber + BigInt(i)}` }],
|
|
53
|
+
endCursor: {
|
|
54
|
+
orderKey: currentBlockNumber,
|
|
55
|
+
uniqueKey: options?.uniqueKey ? uniqueKey : void 0
|
|
56
|
+
},
|
|
47
57
|
production: "backfill"
|
|
48
58
|
}
|
|
49
59
|
});
|
|
@@ -51,6 +61,9 @@ function generateMockMessages(count = 10, options) {
|
|
|
51
61
|
}
|
|
52
62
|
return messages;
|
|
53
63
|
}
|
|
64
|
+
function uniqueKeyFromOrderKey(orderKey) {
|
|
65
|
+
return `0xff00${orderKey.toString()}`;
|
|
66
|
+
}
|
|
54
67
|
function getMockIndexer(params) {
|
|
55
68
|
const { internalContext: contextParams, override } = params ?? {};
|
|
56
69
|
const { plugins, ...rest } = override ?? {};
|
|
@@ -62,6 +75,7 @@ function getMockIndexer(params) {
|
|
|
62
75
|
async transform() {
|
|
63
76
|
},
|
|
64
77
|
plugins: [
|
|
78
|
+
logger.logger(),
|
|
65
79
|
internal_plugins.internalContext(
|
|
66
80
|
contextParams ?? {
|
|
67
81
|
availableIndexers: ["testing"],
|
|
@@ -108,8 +122,8 @@ function mockSink({
|
|
|
108
122
|
});
|
|
109
123
|
}
|
|
110
124
|
function useMockSink() {
|
|
111
|
-
const context
|
|
112
|
-
return { output: context
|
|
125
|
+
const context = config.useIndexerContext();
|
|
126
|
+
return { output: context.output };
|
|
113
127
|
}
|
|
114
128
|
|
|
115
129
|
exports.generateMockMessages = generateMockMessages;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as Indexer, b as IndexerPlugin, c as IndexerConfig } from '../shared/indexer.
|
|
1
|
+
import { a as Indexer, b as IndexerPlugin, c as IndexerConfig } from '../shared/indexer.7668fe34.cjs';
|
|
2
2
|
import { MockStreamResponse, MockFilter, MockBlock } from '@apibara/protocol/testing';
|
|
3
3
|
import { InternalContext } from './plugins.cjs';
|
|
4
4
|
import '@apibara/protocol';
|
|
@@ -13,6 +13,8 @@ type MockMessagesOptions = {
|
|
|
13
13
|
finalizeToIndex: number;
|
|
14
14
|
finalizeTriggerIndex: number;
|
|
15
15
|
};
|
|
16
|
+
uniqueKey?: boolean;
|
|
17
|
+
baseBlockNumber?: bigint;
|
|
16
18
|
};
|
|
17
19
|
declare function generateMockMessages(count?: number, options?: MockMessagesOptions): MockStreamResponse[];
|
|
18
20
|
type MockIndexerParams = {
|
|
@@ -20,9 +22,9 @@ type MockIndexerParams = {
|
|
|
20
22
|
override?: Partial<IndexerConfig<MockFilter, MockBlock>>;
|
|
21
23
|
};
|
|
22
24
|
declare function getMockIndexer(params?: MockIndexerParams): Indexer<{
|
|
23
|
-
|
|
25
|
+
filter?: string | undefined;
|
|
24
26
|
}, {
|
|
25
|
-
|
|
27
|
+
data?: string | undefined;
|
|
26
28
|
}>;
|
|
27
29
|
type MockRet = {
|
|
28
30
|
data: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as Indexer, b as IndexerPlugin, c as IndexerConfig } from '../shared/indexer.
|
|
1
|
+
import { a as Indexer, b as IndexerPlugin, c as IndexerConfig } from '../shared/indexer.7668fe34.mjs';
|
|
2
2
|
import { MockStreamResponse, MockFilter, MockBlock } from '@apibara/protocol/testing';
|
|
3
3
|
import { InternalContext } from './plugins.mjs';
|
|
4
4
|
import '@apibara/protocol';
|
|
@@ -13,6 +13,8 @@ type MockMessagesOptions = {
|
|
|
13
13
|
finalizeToIndex: number;
|
|
14
14
|
finalizeTriggerIndex: number;
|
|
15
15
|
};
|
|
16
|
+
uniqueKey?: boolean;
|
|
17
|
+
baseBlockNumber?: bigint;
|
|
16
18
|
};
|
|
17
19
|
declare function generateMockMessages(count?: number, options?: MockMessagesOptions): MockStreamResponse[];
|
|
18
20
|
type MockIndexerParams = {
|
|
@@ -20,9 +22,9 @@ type MockIndexerParams = {
|
|
|
20
22
|
override?: Partial<IndexerConfig<MockFilter, MockBlock>>;
|
|
21
23
|
};
|
|
22
24
|
declare function getMockIndexer(params?: MockIndexerParams): Indexer<{
|
|
23
|
-
|
|
25
|
+
filter?: string | undefined;
|
|
24
26
|
}, {
|
|
25
|
-
|
|
27
|
+
data?: string | undefined;
|
|
26
28
|
}>;
|
|
27
29
|
type MockRet = {
|
|
28
30
|
data: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as Indexer, b as IndexerPlugin, c as IndexerConfig } from '../shared/indexer.
|
|
1
|
+
import { a as Indexer, b as IndexerPlugin, c as IndexerConfig } from '../shared/indexer.7668fe34.js';
|
|
2
2
|
import { MockStreamResponse, MockFilter, MockBlock } from '@apibara/protocol/testing';
|
|
3
3
|
import { InternalContext } from './plugins.js';
|
|
4
4
|
import '@apibara/protocol';
|
|
@@ -13,6 +13,8 @@ type MockMessagesOptions = {
|
|
|
13
13
|
finalizeToIndex: number;
|
|
14
14
|
finalizeTriggerIndex: number;
|
|
15
15
|
};
|
|
16
|
+
uniqueKey?: boolean;
|
|
17
|
+
baseBlockNumber?: bigint;
|
|
16
18
|
};
|
|
17
19
|
declare function generateMockMessages(count?: number, options?: MockMessagesOptions): MockStreamResponse[];
|
|
18
20
|
type MockIndexerParams = {
|
|
@@ -20,9 +22,9 @@ type MockIndexerParams = {
|
|
|
20
22
|
override?: Partial<IndexerConfig<MockFilter, MockBlock>>;
|
|
21
23
|
};
|
|
22
24
|
declare function getMockIndexer(params?: MockIndexerParams): Indexer<{
|
|
23
|
-
|
|
25
|
+
filter?: string | undefined;
|
|
24
26
|
}, {
|
|
25
|
-
|
|
27
|
+
data?: string | undefined;
|
|
26
28
|
}>;
|
|
27
29
|
type MockRet = {
|
|
28
30
|
data: string;
|