@apibara/indexer 2.0.0-beta.4 → 2.0.0-beta.41

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 (87) hide show
  1. package/dist/index.cjs +278 -0
  2. package/dist/index.d.cts +3 -0
  3. package/dist/index.d.mts +3 -0
  4. package/dist/index.d.ts +3 -0
  5. package/dist/index.mjs +267 -0
  6. package/dist/internal/index.cjs +10 -0
  7. package/dist/internal/index.d.cts +3 -0
  8. package/dist/internal/index.d.mts +3 -0
  9. package/dist/internal/index.d.ts +3 -0
  10. package/dist/internal/index.mjs +8 -0
  11. package/dist/internal/plugins.cjs +38 -0
  12. package/dist/internal/plugins.d.cts +13 -0
  13. package/dist/internal/plugins.d.mts +13 -0
  14. package/dist/internal/plugins.d.ts +13 -0
  15. package/dist/internal/plugins.mjs +34 -0
  16. package/dist/internal/testing.cjs +118 -0
  17. package/dist/internal/testing.d.cts +42 -0
  18. package/dist/internal/testing.d.mts +42 -0
  19. package/dist/internal/testing.d.ts +42 -0
  20. package/dist/internal/testing.mjs +113 -0
  21. package/dist/plugins/index.cjs +43 -0
  22. package/dist/plugins/index.d.cts +18 -0
  23. package/dist/plugins/index.d.mts +18 -0
  24. package/dist/plugins/index.d.ts +18 -0
  25. package/dist/plugins/index.mjs +38 -0
  26. package/dist/shared/indexer.077335f3.cjs +15 -0
  27. package/dist/shared/indexer.2416906c.cjs +29 -0
  28. package/dist/shared/indexer.601ceab0.cjs +7 -0
  29. package/dist/shared/indexer.9b21ddd2.mjs +5 -0
  30. package/dist/shared/indexer.a55ad619.mjs +12 -0
  31. package/dist/shared/indexer.fedcd831.d.cts +100 -0
  32. package/dist/shared/indexer.fedcd831.d.mts +100 -0
  33. package/dist/shared/indexer.fedcd831.d.ts +100 -0
  34. package/dist/shared/indexer.ff25c953.mjs +26 -0
  35. package/dist/testing/index.cjs +66 -0
  36. package/dist/testing/index.d.cts +12 -0
  37. package/dist/testing/index.d.mts +12 -0
  38. package/dist/testing/index.d.ts +12 -0
  39. package/dist/testing/index.mjs +60 -0
  40. package/dist/vcr/index.cjs +92 -0
  41. package/dist/vcr/index.d.cts +27 -0
  42. package/dist/vcr/index.d.mts +27 -0
  43. package/dist/vcr/index.d.ts +27 -0
  44. package/dist/vcr/index.mjs +78 -0
  45. package/package.json +43 -41
  46. package/src/compose.test.ts +76 -0
  47. package/src/compose.ts +71 -0
  48. package/src/context.ts +14 -8
  49. package/src/index.ts +0 -5
  50. package/src/indexer.test.ts +125 -186
  51. package/src/indexer.ts +274 -151
  52. package/src/internal/index.ts +6 -0
  53. package/src/internal/plugins.ts +1 -0
  54. package/src/internal/testing.ts +148 -0
  55. package/src/plugins/config.ts +4 -4
  56. package/src/plugins/context.ts +40 -0
  57. package/src/plugins/index.ts +8 -1
  58. package/src/plugins/logger.ts +30 -0
  59. package/src/plugins/persistence.ts +24 -187
  60. package/src/testing/index.ts +58 -3
  61. package/src/vcr/record.ts +6 -4
  62. package/src/vcr/replay.ts +8 -18
  63. package/src/hooks/index.ts +0 -2
  64. package/src/hooks/useKVStore.ts +0 -12
  65. package/src/hooks/useSink.ts +0 -13
  66. package/src/plugins/kv.test.ts +0 -120
  67. package/src/plugins/kv.ts +0 -132
  68. package/src/plugins/persistence.test.ts +0 -151
  69. package/src/sink.ts +0 -36
  70. package/src/sinks/csv.test.ts +0 -65
  71. package/src/sinks/csv.ts +0 -159
  72. package/src/sinks/drizzle/Int8Range.ts +0 -52
  73. package/src/sinks/drizzle/delete.ts +0 -42
  74. package/src/sinks/drizzle/drizzle.test.ts +0 -239
  75. package/src/sinks/drizzle/drizzle.ts +0 -115
  76. package/src/sinks/drizzle/index.ts +0 -6
  77. package/src/sinks/drizzle/insert.ts +0 -39
  78. package/src/sinks/drizzle/select.ts +0 -44
  79. package/src/sinks/drizzle/transaction.ts +0 -49
  80. package/src/sinks/drizzle/update.ts +0 -47
  81. package/src/sinks/drizzle/utils.ts +0 -36
  82. package/src/sinks/sqlite.test.ts +0 -99
  83. package/src/sinks/sqlite.ts +0 -170
  84. package/src/testing/helper.ts +0 -13
  85. package/src/testing/indexer.ts +0 -35
  86. package/src/testing/setup.ts +0 -59
  87. package/src/testing/vcr.ts +0 -54
package/dist/index.cjs ADDED
@@ -0,0 +1,278 @@
1
+ 'use strict';
2
+
3
+ const protocol = require('@apibara/protocol');
4
+ const consola = require('consola');
5
+ const hookable = require('hookable');
6
+ const assert = require('node:assert');
7
+ const context = require('./shared/indexer.077335f3.cjs');
8
+ const api = require('@opentelemetry/api');
9
+ require('node:async_hooks');
10
+ require('unctx');
11
+
12
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
13
+
14
+ const consola__default = /*#__PURE__*/_interopDefaultCompat(consola);
15
+ const assert__default = /*#__PURE__*/_interopDefaultCompat(assert);
16
+
17
+ function compose(middleware) {
18
+ return (context, next) => {
19
+ let index = -1;
20
+ return dispatch(0);
21
+ async function dispatch(i) {
22
+ if (i <= index) {
23
+ throw new Error("next() called multiple times");
24
+ }
25
+ index = i;
26
+ let handler;
27
+ if (i >= middleware.length) {
28
+ if (next) {
29
+ await next();
30
+ }
31
+ return;
32
+ }
33
+ if (middleware[i]) {
34
+ handler = middleware[i];
35
+ } else {
36
+ handler = i === middleware.length ? next : void 0;
37
+ }
38
+ if (!handler) {
39
+ throw new Error("Handler not found");
40
+ }
41
+ await handler(context, () => dispatch(i + 1));
42
+ }
43
+ };
44
+ }
45
+
46
+ const tracer = api.trace.getTracer("@apibara/indexer");
47
+
48
+ function defineIndexer(streamConfig) {
49
+ return (config) => ({
50
+ streamConfig,
51
+ ...config
52
+ });
53
+ }
54
+ function createIndexer({
55
+ streamConfig,
56
+ ...options
57
+ }) {
58
+ const indexer = {
59
+ options,
60
+ streamConfig,
61
+ hooks: hookable.createHooks()
62
+ };
63
+ if (indexer.options.debug) {
64
+ hookable.createDebugger(indexer.hooks, { tag: "indexer" });
65
+ }
66
+ indexer.hooks.addHooks(indexer.options.hooks ?? {});
67
+ for (const plugin of indexer.options.plugins ?? []) {
68
+ plugin(indexer);
69
+ }
70
+ return indexer;
71
+ }
72
+ async function runWithReconnect(client, indexer, options = {}) {
73
+ let retryCount = 0;
74
+ const maxRetries = options.maxRetries ?? 10;
75
+ const retryDelay = options.retryDelay ?? 1e3;
76
+ const maxWait = options.maxWait ?? 3e4;
77
+ const runOptions = {
78
+ onConnect() {
79
+ retryCount = 0;
80
+ }
81
+ };
82
+ while (true) {
83
+ try {
84
+ await run(client, indexer, runOptions);
85
+ return;
86
+ } catch (error) {
87
+ retryCount++;
88
+ if (error instanceof protocol.ClientError) {
89
+ if (error.code === protocol.Status.INTERNAL) {
90
+ if (retryCount < maxRetries) {
91
+ consola__default.error(
92
+ "Internal server error, reconnecting...",
93
+ error.message
94
+ );
95
+ const delay = Math.random() * (retryDelay * 0.2) + retryDelay;
96
+ await new Promise(
97
+ (resolve) => setTimeout(resolve, Math.min(retryCount * delay, maxWait))
98
+ );
99
+ continue;
100
+ }
101
+ }
102
+ }
103
+ throw error;
104
+ }
105
+ }
106
+ }
107
+ async function run(client, indexer, runOptions = {}) {
108
+ await context.indexerAsyncContext.callAsync({}, async () => {
109
+ const context$1 = context.useIndexerContext();
110
+ const middleware = await registerMiddleware(indexer);
111
+ await indexer.hooks.callHook("run:before");
112
+ const isFactoryMode = indexer.options.factory !== void 0;
113
+ let startingCursor;
114
+ if (indexer.options.startingCursor) {
115
+ startingCursor = indexer.options.startingCursor;
116
+ } else if (indexer.options.startingBlock !== void 0) {
117
+ startingCursor = {
118
+ orderKey: indexer.options.startingBlock
119
+ };
120
+ }
121
+ const request = indexer.streamConfig.Request.make({
122
+ filter: isFactoryMode ? [indexer.options.filter, {}] : [indexer.options.filter],
123
+ finality: indexer.options.finality,
124
+ startingCursor
125
+ });
126
+ const options = {};
127
+ await indexer.hooks.callHook("connect:before", { request, options });
128
+ let mainFilter;
129
+ if (isFactoryMode) {
130
+ mainFilter = request.filter[1];
131
+ }
132
+ let stream = client.streamData(request, options)[Symbol.asyncIterator]();
133
+ await indexer.hooks.callHook("connect:after", { request });
134
+ let onConnectCalled = false;
135
+ while (true) {
136
+ const { value: message, done } = await stream.next();
137
+ if (done) {
138
+ break;
139
+ }
140
+ if (!onConnectCalled) {
141
+ onConnectCalled = true;
142
+ if (runOptions.onConnect) {
143
+ await runOptions.onConnect();
144
+ }
145
+ }
146
+ await indexer.hooks.callHook("message", { message });
147
+ switch (message._tag) {
148
+ case "data": {
149
+ await tracer.startActiveSpan("message data", async (span) => {
150
+ const blocks = message.data.data;
151
+ const { cursor, endCursor, finality } = message.data;
152
+ context$1.cursor = cursor;
153
+ context$1.endCursor = endCursor;
154
+ context$1.finality = finality;
155
+ await middleware(context$1, async () => {
156
+ let block;
157
+ if (isFactoryMode) {
158
+ assert__default(indexer.options.factory !== void 0);
159
+ const [factoryBlock, mainBlock] = blocks;
160
+ block = mainBlock;
161
+ if (factoryBlock !== null) {
162
+ const { filter } = await indexer.options.factory({
163
+ block: factoryBlock,
164
+ context: context$1
165
+ });
166
+ if (filter) {
167
+ mainFilter = indexer.streamConfig.mergeFilter(
168
+ mainFilter,
169
+ filter
170
+ );
171
+ const request2 = indexer.streamConfig.Request.make({
172
+ filter: [indexer.options.filter, mainFilter],
173
+ finality: indexer.options.finality,
174
+ startingCursor: cursor
175
+ });
176
+ await indexer.hooks.callHook("connect:factory", {
177
+ request: request2,
178
+ endCursor
179
+ });
180
+ stream = client.streamData(request2, options)[Symbol.asyncIterator]();
181
+ const { value: message2 } = await stream.next();
182
+ assert__default(message2._tag === "data");
183
+ const [_factoryBlock, _block] = message2.data.data;
184
+ block = _block;
185
+ }
186
+ }
187
+ } else {
188
+ block = blocks[0];
189
+ }
190
+ if (block) {
191
+ await tracer.startActiveSpan("handler", async (span2) => {
192
+ await indexer.options.transform({
193
+ block,
194
+ cursor,
195
+ endCursor,
196
+ finality,
197
+ context: context$1
198
+ });
199
+ span2.end();
200
+ });
201
+ }
202
+ });
203
+ span.end();
204
+ });
205
+ context$1.cursor = void 0;
206
+ context$1.endCursor = void 0;
207
+ context$1.finality = void 0;
208
+ break;
209
+ }
210
+ case "invalidate": {
211
+ await tracer.startActiveSpan("message invalidate", async (span) => {
212
+ await indexer.hooks.callHook("message:invalidate", { message });
213
+ span.end();
214
+ });
215
+ break;
216
+ }
217
+ case "finalize": {
218
+ await tracer.startActiveSpan("message finalize", async (span) => {
219
+ await indexer.hooks.callHook("message:finalize", { message });
220
+ span.end();
221
+ });
222
+ break;
223
+ }
224
+ case "heartbeat": {
225
+ await tracer.startActiveSpan("message heartbeat", async (span) => {
226
+ await indexer.hooks.callHook("message:heartbeat", { message });
227
+ span.end();
228
+ });
229
+ break;
230
+ }
231
+ case "systemMessage": {
232
+ await tracer.startActiveSpan(
233
+ "message systemMessage",
234
+ async (span) => {
235
+ switch (message.systemMessage.output?._tag) {
236
+ case "stderr": {
237
+ consola__default.warn(message.systemMessage.output.stderr);
238
+ break;
239
+ }
240
+ case "stdout": {
241
+ consola__default.info(message.systemMessage.output.stdout);
242
+ break;
243
+ }
244
+ }
245
+ await indexer.hooks.callHook("message:systemMessage", {
246
+ message
247
+ });
248
+ span.end();
249
+ }
250
+ );
251
+ break;
252
+ }
253
+ default: {
254
+ consola__default.warn("unexpected message", message);
255
+ throw new Error("not implemented");
256
+ }
257
+ }
258
+ await indexer.hooks.callHook("run:after");
259
+ }
260
+ });
261
+ }
262
+ async function registerMiddleware(indexer) {
263
+ const middleware = [];
264
+ const use = (fn) => {
265
+ middleware.push(fn);
266
+ };
267
+ await indexer.hooks.callHook("handler:middleware", { use });
268
+ const composed = compose(middleware);
269
+ return async function _composedIndexerMiddleware(context, next) {
270
+ await composed(context, next);
271
+ };
272
+ }
273
+
274
+ exports.useIndexerContext = context.useIndexerContext;
275
+ exports.createIndexer = createIndexer;
276
+ exports.defineIndexer = defineIndexer;
277
+ exports.run = run;
278
+ exports.runWithReconnect = runWithReconnect;
@@ -0,0 +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.fedcd831.cjs';
2
+ import '@apibara/protocol';
3
+ import 'hookable';
@@ -0,0 +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.fedcd831.mjs';
2
+ import '@apibara/protocol';
3
+ import 'hookable';
@@ -0,0 +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.fedcd831.js';
2
+ import '@apibara/protocol';
3
+ import 'hookable';
package/dist/index.mjs ADDED
@@ -0,0 +1,267 @@
1
+ import { ClientError, Status } from '@apibara/protocol';
2
+ import consola from 'consola';
3
+ import { createHooks, createDebugger } from 'hookable';
4
+ import assert from 'node:assert';
5
+ import { i as indexerAsyncContext, u as useIndexerContext } from './shared/indexer.a55ad619.mjs';
6
+ import { trace } from '@opentelemetry/api';
7
+ import 'node:async_hooks';
8
+ import 'unctx';
9
+
10
+ function compose(middleware) {
11
+ return (context, next) => {
12
+ let index = -1;
13
+ return dispatch(0);
14
+ async function dispatch(i) {
15
+ if (i <= index) {
16
+ throw new Error("next() called multiple times");
17
+ }
18
+ index = i;
19
+ let handler;
20
+ if (i >= middleware.length) {
21
+ if (next) {
22
+ await next();
23
+ }
24
+ return;
25
+ }
26
+ if (middleware[i]) {
27
+ handler = middleware[i];
28
+ } else {
29
+ handler = i === middleware.length ? next : void 0;
30
+ }
31
+ if (!handler) {
32
+ throw new Error("Handler not found");
33
+ }
34
+ await handler(context, () => dispatch(i + 1));
35
+ }
36
+ };
37
+ }
38
+
39
+ const tracer = trace.getTracer("@apibara/indexer");
40
+
41
+ function defineIndexer(streamConfig) {
42
+ return (config) => ({
43
+ streamConfig,
44
+ ...config
45
+ });
46
+ }
47
+ function createIndexer({
48
+ streamConfig,
49
+ ...options
50
+ }) {
51
+ const indexer = {
52
+ options,
53
+ streamConfig,
54
+ hooks: createHooks()
55
+ };
56
+ if (indexer.options.debug) {
57
+ createDebugger(indexer.hooks, { tag: "indexer" });
58
+ }
59
+ indexer.hooks.addHooks(indexer.options.hooks ?? {});
60
+ for (const plugin of indexer.options.plugins ?? []) {
61
+ plugin(indexer);
62
+ }
63
+ return indexer;
64
+ }
65
+ async function runWithReconnect(client, indexer, options = {}) {
66
+ let retryCount = 0;
67
+ const maxRetries = options.maxRetries ?? 10;
68
+ const retryDelay = options.retryDelay ?? 1e3;
69
+ const maxWait = options.maxWait ?? 3e4;
70
+ const runOptions = {
71
+ onConnect() {
72
+ retryCount = 0;
73
+ }
74
+ };
75
+ while (true) {
76
+ try {
77
+ await run(client, indexer, runOptions);
78
+ return;
79
+ } catch (error) {
80
+ retryCount++;
81
+ if (error instanceof ClientError) {
82
+ if (error.code === Status.INTERNAL) {
83
+ if (retryCount < maxRetries) {
84
+ consola.error(
85
+ "Internal server error, reconnecting...",
86
+ error.message
87
+ );
88
+ const delay = Math.random() * (retryDelay * 0.2) + retryDelay;
89
+ await new Promise(
90
+ (resolve) => setTimeout(resolve, Math.min(retryCount * delay, maxWait))
91
+ );
92
+ continue;
93
+ }
94
+ }
95
+ }
96
+ throw error;
97
+ }
98
+ }
99
+ }
100
+ async function run(client, indexer, runOptions = {}) {
101
+ await indexerAsyncContext.callAsync({}, async () => {
102
+ const context = useIndexerContext();
103
+ const middleware = await registerMiddleware(indexer);
104
+ await indexer.hooks.callHook("run:before");
105
+ const isFactoryMode = indexer.options.factory !== void 0;
106
+ let startingCursor;
107
+ if (indexer.options.startingCursor) {
108
+ startingCursor = indexer.options.startingCursor;
109
+ } else if (indexer.options.startingBlock !== void 0) {
110
+ startingCursor = {
111
+ orderKey: indexer.options.startingBlock
112
+ };
113
+ }
114
+ const request = indexer.streamConfig.Request.make({
115
+ filter: isFactoryMode ? [indexer.options.filter, {}] : [indexer.options.filter],
116
+ finality: indexer.options.finality,
117
+ startingCursor
118
+ });
119
+ const options = {};
120
+ await indexer.hooks.callHook("connect:before", { request, options });
121
+ let mainFilter;
122
+ if (isFactoryMode) {
123
+ mainFilter = request.filter[1];
124
+ }
125
+ let stream = client.streamData(request, options)[Symbol.asyncIterator]();
126
+ await indexer.hooks.callHook("connect:after", { request });
127
+ let onConnectCalled = false;
128
+ while (true) {
129
+ const { value: message, done } = await stream.next();
130
+ if (done) {
131
+ break;
132
+ }
133
+ if (!onConnectCalled) {
134
+ onConnectCalled = true;
135
+ if (runOptions.onConnect) {
136
+ await runOptions.onConnect();
137
+ }
138
+ }
139
+ await indexer.hooks.callHook("message", { message });
140
+ switch (message._tag) {
141
+ case "data": {
142
+ await tracer.startActiveSpan("message data", async (span) => {
143
+ const blocks = message.data.data;
144
+ const { cursor, endCursor, finality } = message.data;
145
+ context.cursor = cursor;
146
+ context.endCursor = endCursor;
147
+ context.finality = finality;
148
+ await middleware(context, async () => {
149
+ let block;
150
+ if (isFactoryMode) {
151
+ assert(indexer.options.factory !== void 0);
152
+ const [factoryBlock, mainBlock] = blocks;
153
+ block = mainBlock;
154
+ if (factoryBlock !== null) {
155
+ const { filter } = await indexer.options.factory({
156
+ block: factoryBlock,
157
+ context
158
+ });
159
+ if (filter) {
160
+ mainFilter = indexer.streamConfig.mergeFilter(
161
+ mainFilter,
162
+ filter
163
+ );
164
+ const request2 = indexer.streamConfig.Request.make({
165
+ filter: [indexer.options.filter, mainFilter],
166
+ finality: indexer.options.finality,
167
+ startingCursor: cursor
168
+ });
169
+ await indexer.hooks.callHook("connect:factory", {
170
+ request: request2,
171
+ endCursor
172
+ });
173
+ stream = client.streamData(request2, options)[Symbol.asyncIterator]();
174
+ const { value: message2 } = await stream.next();
175
+ assert(message2._tag === "data");
176
+ const [_factoryBlock, _block] = message2.data.data;
177
+ block = _block;
178
+ }
179
+ }
180
+ } else {
181
+ block = blocks[0];
182
+ }
183
+ if (block) {
184
+ await tracer.startActiveSpan("handler", async (span2) => {
185
+ await indexer.options.transform({
186
+ block,
187
+ cursor,
188
+ endCursor,
189
+ finality,
190
+ context
191
+ });
192
+ span2.end();
193
+ });
194
+ }
195
+ });
196
+ span.end();
197
+ });
198
+ context.cursor = void 0;
199
+ context.endCursor = void 0;
200
+ context.finality = void 0;
201
+ break;
202
+ }
203
+ case "invalidate": {
204
+ await tracer.startActiveSpan("message invalidate", async (span) => {
205
+ await indexer.hooks.callHook("message:invalidate", { message });
206
+ span.end();
207
+ });
208
+ break;
209
+ }
210
+ case "finalize": {
211
+ await tracer.startActiveSpan("message finalize", async (span) => {
212
+ await indexer.hooks.callHook("message:finalize", { message });
213
+ span.end();
214
+ });
215
+ break;
216
+ }
217
+ case "heartbeat": {
218
+ await tracer.startActiveSpan("message heartbeat", async (span) => {
219
+ await indexer.hooks.callHook("message:heartbeat", { message });
220
+ span.end();
221
+ });
222
+ break;
223
+ }
224
+ case "systemMessage": {
225
+ await tracer.startActiveSpan(
226
+ "message systemMessage",
227
+ async (span) => {
228
+ switch (message.systemMessage.output?._tag) {
229
+ case "stderr": {
230
+ consola.warn(message.systemMessage.output.stderr);
231
+ break;
232
+ }
233
+ case "stdout": {
234
+ consola.info(message.systemMessage.output.stdout);
235
+ break;
236
+ }
237
+ }
238
+ await indexer.hooks.callHook("message:systemMessage", {
239
+ message
240
+ });
241
+ span.end();
242
+ }
243
+ );
244
+ break;
245
+ }
246
+ default: {
247
+ consola.warn("unexpected message", message);
248
+ throw new Error("not implemented");
249
+ }
250
+ }
251
+ await indexer.hooks.callHook("run:after");
252
+ }
253
+ });
254
+ }
255
+ async function registerMiddleware(indexer) {
256
+ const middleware = [];
257
+ const use = (fn) => {
258
+ middleware.push(fn);
259
+ };
260
+ await indexer.hooks.callHook("handler:middleware", { use });
261
+ const composed = compose(middleware);
262
+ return async function _composedIndexerMiddleware(context, next) {
263
+ await composed(context, next);
264
+ };
265
+ }
266
+
267
+ export { createIndexer, defineIndexer, run, runWithReconnect, useIndexerContext };
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+
3
+ function generateIndexerId(fileBasedName, identifier) {
4
+ return `indexer_${fileBasedName}_${identifier || "default"}`.replace(
5
+ /[^a-zA-Z0-9_]/g,
6
+ "_"
7
+ );
8
+ }
9
+
10
+ exports.generateIndexerId = generateIndexerId;
@@ -0,0 +1,3 @@
1
+ declare function generateIndexerId(fileBasedName: string, identifier?: string): string;
2
+
3
+ export { generateIndexerId };
@@ -0,0 +1,3 @@
1
+ declare function generateIndexerId(fileBasedName: string, identifier?: string): string;
2
+
3
+ export { generateIndexerId };
@@ -0,0 +1,3 @@
1
+ declare function generateIndexerId(fileBasedName: string, identifier?: string): string;
2
+
3
+ export { generateIndexerId };
@@ -0,0 +1,8 @@
1
+ function generateIndexerId(fileBasedName, identifier) {
2
+ return `indexer_${fileBasedName}_${identifier || "default"}`.replace(
3
+ /[^a-zA-Z0-9_]/g,
4
+ "_"
5
+ );
6
+ }
7
+
8
+ export { generateIndexerId };
@@ -0,0 +1,38 @@
1
+ 'use strict';
2
+
3
+ const context = require('../shared/indexer.077335f3.cjs');
4
+ const config = require('../shared/indexer.601ceab0.cjs');
5
+ require('node:async_hooks');
6
+ require('unctx');
7
+
8
+ const INTERNAL_CONTEXT_PROPERTY = "_internal";
9
+ function internalContext(values) {
10
+ return config.defineIndexerPlugin((indexer) => {
11
+ indexer.hooks.hook("run:before", () => {
12
+ try {
13
+ const ctx = context.useIndexerContext();
14
+ ctx[INTERNAL_CONTEXT_PROPERTY] = {
15
+ ...ctx[INTERNAL_CONTEXT_PROPERTY] || {},
16
+ ...values
17
+ };
18
+ } catch (error) {
19
+ throw new Error("Failed to set internal context", {
20
+ cause: error
21
+ });
22
+ }
23
+ });
24
+ });
25
+ }
26
+ function useInternalContext() {
27
+ const ctx = context.useIndexerContext();
28
+ if (ctx[INTERNAL_CONTEXT_PROPERTY] === void 0) {
29
+ throw new Error(
30
+ "Internal context is not available, possibly 'internalContext' plugin is missing!"
31
+ );
32
+ }
33
+ return ctx[INTERNAL_CONTEXT_PROPERTY];
34
+ }
35
+
36
+ exports.INTERNAL_CONTEXT_PROPERTY = INTERNAL_CONTEXT_PROPERTY;
37
+ exports.internalContext = internalContext;
38
+ exports.useInternalContext = useInternalContext;
@@ -0,0 +1,13 @@
1
+ import { b as IndexerPlugin } from '../shared/indexer.fedcd831.cjs';
2
+ import '@apibara/protocol';
3
+ import 'hookable';
4
+
5
+ declare const INTERNAL_CONTEXT_PROPERTY = "_internal";
6
+ declare function internalContext<TFilter, TBlock, TTxnParams>(values: Record<string, unknown>): IndexerPlugin<TFilter, TBlock>;
7
+ type InternalContext = {
8
+ indexerName: string;
9
+ availableIndexers: string[];
10
+ };
11
+ declare function useInternalContext(): InternalContext;
12
+
13
+ export { INTERNAL_CONTEXT_PROPERTY, type InternalContext, internalContext, useInternalContext };
@@ -0,0 +1,13 @@
1
+ import { b as IndexerPlugin } from '../shared/indexer.fedcd831.mjs';
2
+ import '@apibara/protocol';
3
+ import 'hookable';
4
+
5
+ declare const INTERNAL_CONTEXT_PROPERTY = "_internal";
6
+ declare function internalContext<TFilter, TBlock, TTxnParams>(values: Record<string, unknown>): IndexerPlugin<TFilter, TBlock>;
7
+ type InternalContext = {
8
+ indexerName: string;
9
+ availableIndexers: string[];
10
+ };
11
+ declare function useInternalContext(): InternalContext;
12
+
13
+ export { INTERNAL_CONTEXT_PROPERTY, type InternalContext, internalContext, useInternalContext };
@@ -0,0 +1,13 @@
1
+ import { b as IndexerPlugin } from '../shared/indexer.fedcd831.js';
2
+ import '@apibara/protocol';
3
+ import 'hookable';
4
+
5
+ declare const INTERNAL_CONTEXT_PROPERTY = "_internal";
6
+ declare function internalContext<TFilter, TBlock, TTxnParams>(values: Record<string, unknown>): IndexerPlugin<TFilter, TBlock>;
7
+ type InternalContext = {
8
+ indexerName: string;
9
+ availableIndexers: string[];
10
+ };
11
+ declare function useInternalContext(): InternalContext;
12
+
13
+ export { INTERNAL_CONTEXT_PROPERTY, type InternalContext, internalContext, useInternalContext };