@apibara/indexer 2.0.0-beta.36 → 2.0.0-beta.38
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.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- 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 +36 -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 +32 -0
- package/dist/internal/testing.cjs +15 -7
- package/dist/internal/testing.d.cts +6 -4
- package/dist/internal/testing.d.mts +6 -4
- package/dist/internal/testing.d.ts +6 -4
- package/dist/internal/testing.mjs +15 -7
- 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/shared/{indexer.0a872656.d.cts → indexer.fedcd831.d.cts} +1 -1
- package/dist/shared/{indexer.0a872656.d.mts → indexer.fedcd831.d.mts} +1 -1
- package/dist/shared/{indexer.0a872656.d.ts → indexer.fedcd831.d.ts} +1 -1
- package/dist/testing/index.d.cts +1 -1
- package/dist/testing/index.d.mts +1 -1
- package/dist/testing/index.d.ts +1 -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/package.json +14 -2
- package/src/indexer.test.ts +2 -2
- package/src/internal/index.ts +6 -0
- package/src/internal/plugins.ts +1 -0
- package/src/internal/testing.ts +22 -10
- package/src/plugins/context.ts +37 -0
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export {
|
|
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
2
|
import '@apibara/protocol';
|
|
3
3
|
import 'hookable';
|
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export {
|
|
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
2
|
import '@apibara/protocol';
|
|
3
3
|
import 'hookable';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export {
|
|
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
2
|
import '@apibara/protocol';
|
|
3
3
|
import 'hookable';
|
|
@@ -0,0 +1,36 @@
|
|
|
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]) {
|
|
29
|
+
throw new Error("Internal context is not available");
|
|
30
|
+
}
|
|
31
|
+
return ctx[INTERNAL_CONTEXT_PROPERTY];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
exports.INTERNAL_CONTEXT_PROPERTY = INTERNAL_CONTEXT_PROPERTY;
|
|
35
|
+
exports.internalContext = internalContext;
|
|
36
|
+
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 };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { u as useIndexerContext } from '../shared/indexer.a55ad619.mjs';
|
|
2
|
+
import { d as defineIndexerPlugin } from '../shared/indexer.9b21ddd2.mjs';
|
|
3
|
+
import 'node:async_hooks';
|
|
4
|
+
import 'unctx';
|
|
5
|
+
|
|
6
|
+
const INTERNAL_CONTEXT_PROPERTY = "_internal";
|
|
7
|
+
function internalContext(values) {
|
|
8
|
+
return defineIndexerPlugin((indexer) => {
|
|
9
|
+
indexer.hooks.hook("run:before", () => {
|
|
10
|
+
try {
|
|
11
|
+
const ctx = useIndexerContext();
|
|
12
|
+
ctx[INTERNAL_CONTEXT_PROPERTY] = {
|
|
13
|
+
...ctx[INTERNAL_CONTEXT_PROPERTY] || {},
|
|
14
|
+
...values
|
|
15
|
+
};
|
|
16
|
+
} catch (error) {
|
|
17
|
+
throw new Error("Failed to set internal context", {
|
|
18
|
+
cause: error
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
function useInternalContext() {
|
|
25
|
+
const ctx = useIndexerContext();
|
|
26
|
+
if (!ctx[INTERNAL_CONTEXT_PROPERTY]) {
|
|
27
|
+
throw new Error("Internal context is not available");
|
|
28
|
+
}
|
|
29
|
+
return ctx[INTERNAL_CONTEXT_PROPERTY];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { INTERNAL_CONTEXT_PROPERTY, internalContext, useInternalContext };
|
|
@@ -6,6 +6,7 @@ const context = require('../shared/indexer.077335f3.cjs');
|
|
|
6
6
|
const index = require('../index.cjs');
|
|
7
7
|
const config = require('../shared/indexer.601ceab0.cjs');
|
|
8
8
|
require('consola');
|
|
9
|
+
const internal_plugins = require('./plugins.cjs');
|
|
9
10
|
require('node:async_hooks');
|
|
10
11
|
require('unctx');
|
|
11
12
|
require('hookable');
|
|
@@ -50,19 +51,26 @@ function generateMockMessages(count = 10, options) {
|
|
|
50
51
|
}
|
|
51
52
|
return messages;
|
|
52
53
|
}
|
|
53
|
-
function getMockIndexer({
|
|
54
|
-
|
|
55
|
-
override
|
|
56
|
-
} = {}) {
|
|
54
|
+
function getMockIndexer(params) {
|
|
55
|
+
const { internalContext: contextParams, override } = params ?? {};
|
|
56
|
+
const { plugins, ...rest } = override ?? {};
|
|
57
57
|
return index.createIndexer(
|
|
58
58
|
index.defineIndexer(testing.MockStream)({
|
|
59
59
|
streamUrl: "https://sepolia.ethereum.a5a.ch",
|
|
60
60
|
finality: "accepted",
|
|
61
61
|
filter: {},
|
|
62
|
-
async transform(
|
|
62
|
+
async transform() {
|
|
63
63
|
},
|
|
64
|
-
plugins
|
|
65
|
-
|
|
64
|
+
plugins: [
|
|
65
|
+
internal_plugins.internalContext(
|
|
66
|
+
contextParams ?? {
|
|
67
|
+
availableIndexers: ["testing"],
|
|
68
|
+
indexerName: "testing"
|
|
69
|
+
}
|
|
70
|
+
),
|
|
71
|
+
...plugins ?? []
|
|
72
|
+
],
|
|
73
|
+
...rest ?? {}
|
|
66
74
|
})
|
|
67
75
|
);
|
|
68
76
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as Indexer, b as IndexerPlugin, c as IndexerConfig } from '../shared/indexer.fedcd831.cjs';
|
|
2
2
|
import { MockStreamResponse, MockFilter, MockBlock } from '@apibara/protocol/testing';
|
|
3
|
+
import { InternalContext } from './plugins.cjs';
|
|
3
4
|
import '@apibara/protocol';
|
|
4
5
|
import 'hookable';
|
|
5
6
|
|
|
@@ -14,10 +15,11 @@ type MockMessagesOptions = {
|
|
|
14
15
|
};
|
|
15
16
|
};
|
|
16
17
|
declare function generateMockMessages(count?: number, options?: MockMessagesOptions): MockStreamResponse[];
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
type MockIndexerParams = {
|
|
19
|
+
internalContext?: InternalContext;
|
|
19
20
|
override?: Partial<IndexerConfig<MockFilter, MockBlock>>;
|
|
20
|
-
}
|
|
21
|
+
};
|
|
22
|
+
declare function getMockIndexer(params?: MockIndexerParams): Indexer<{
|
|
21
23
|
readonly filter?: string | undefined;
|
|
22
24
|
}, {
|
|
23
25
|
readonly data?: string | undefined;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as Indexer, b as IndexerPlugin, c as IndexerConfig } from '../shared/indexer.fedcd831.mjs';
|
|
2
2
|
import { MockStreamResponse, MockFilter, MockBlock } from '@apibara/protocol/testing';
|
|
3
|
+
import { InternalContext } from './plugins.mjs';
|
|
3
4
|
import '@apibara/protocol';
|
|
4
5
|
import 'hookable';
|
|
5
6
|
|
|
@@ -14,10 +15,11 @@ type MockMessagesOptions = {
|
|
|
14
15
|
};
|
|
15
16
|
};
|
|
16
17
|
declare function generateMockMessages(count?: number, options?: MockMessagesOptions): MockStreamResponse[];
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
type MockIndexerParams = {
|
|
19
|
+
internalContext?: InternalContext;
|
|
19
20
|
override?: Partial<IndexerConfig<MockFilter, MockBlock>>;
|
|
20
|
-
}
|
|
21
|
+
};
|
|
22
|
+
declare function getMockIndexer(params?: MockIndexerParams): Indexer<{
|
|
21
23
|
readonly filter?: string | undefined;
|
|
22
24
|
}, {
|
|
23
25
|
readonly data?: string | undefined;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as Indexer, b as IndexerPlugin, c as IndexerConfig } from '../shared/indexer.fedcd831.js';
|
|
2
2
|
import { MockStreamResponse, MockFilter, MockBlock } from '@apibara/protocol/testing';
|
|
3
|
+
import { InternalContext } from './plugins.js';
|
|
3
4
|
import '@apibara/protocol';
|
|
4
5
|
import 'hookable';
|
|
5
6
|
|
|
@@ -14,10 +15,11 @@ type MockMessagesOptions = {
|
|
|
14
15
|
};
|
|
15
16
|
};
|
|
16
17
|
declare function generateMockMessages(count?: number, options?: MockMessagesOptions): MockStreamResponse[];
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
type MockIndexerParams = {
|
|
19
|
+
internalContext?: InternalContext;
|
|
19
20
|
override?: Partial<IndexerConfig<MockFilter, MockBlock>>;
|
|
20
|
-
}
|
|
21
|
+
};
|
|
22
|
+
declare function getMockIndexer(params?: MockIndexerParams): Indexer<{
|
|
21
23
|
readonly filter?: string | undefined;
|
|
22
24
|
}, {
|
|
23
25
|
readonly data?: string | undefined;
|
|
@@ -4,6 +4,7 @@ import { u as useIndexerContext } from '../shared/indexer.a55ad619.mjs';
|
|
|
4
4
|
import { createIndexer, defineIndexer } from '../index.mjs';
|
|
5
5
|
import { d as defineIndexerPlugin } from '../shared/indexer.9b21ddd2.mjs';
|
|
6
6
|
import 'consola';
|
|
7
|
+
import { internalContext } from './plugins.mjs';
|
|
7
8
|
import 'node:async_hooks';
|
|
8
9
|
import 'unctx';
|
|
9
10
|
import 'hookable';
|
|
@@ -48,19 +49,26 @@ function generateMockMessages(count = 10, options) {
|
|
|
48
49
|
}
|
|
49
50
|
return messages;
|
|
50
51
|
}
|
|
51
|
-
function getMockIndexer({
|
|
52
|
-
|
|
53
|
-
override
|
|
54
|
-
} = {}) {
|
|
52
|
+
function getMockIndexer(params) {
|
|
53
|
+
const { internalContext: contextParams, override } = params ?? {};
|
|
54
|
+
const { plugins, ...rest } = override ?? {};
|
|
55
55
|
return createIndexer(
|
|
56
56
|
defineIndexer(MockStream)({
|
|
57
57
|
streamUrl: "https://sepolia.ethereum.a5a.ch",
|
|
58
58
|
finality: "accepted",
|
|
59
59
|
filter: {},
|
|
60
|
-
async transform(
|
|
60
|
+
async transform() {
|
|
61
61
|
},
|
|
62
|
-
plugins
|
|
63
|
-
|
|
62
|
+
plugins: [
|
|
63
|
+
internalContext(
|
|
64
|
+
contextParams ?? {
|
|
65
|
+
availableIndexers: ["testing"],
|
|
66
|
+
indexerName: "testing"
|
|
67
|
+
}
|
|
68
|
+
),
|
|
69
|
+
...plugins ?? []
|
|
70
|
+
],
|
|
71
|
+
...rest ?? {}
|
|
64
72
|
})
|
|
65
73
|
);
|
|
66
74
|
}
|
package/dist/plugins/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { d as defineIndexerPlugin } from '../shared/indexer.
|
|
1
|
+
import { b as IndexerPlugin } from '../shared/indexer.fedcd831.cjs';
|
|
2
|
+
export { d as defineIndexerPlugin } from '../shared/indexer.fedcd831.cjs';
|
|
3
3
|
import { ConsolaReporter, ConsolaInstance } from 'consola';
|
|
4
4
|
export { ConsolaInstance, ConsolaReporter } from 'consola';
|
|
5
5
|
import '@apibara/protocol';
|
package/dist/plugins/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { d as defineIndexerPlugin } from '../shared/indexer.
|
|
1
|
+
import { b as IndexerPlugin } from '../shared/indexer.fedcd831.mjs';
|
|
2
|
+
export { d as defineIndexerPlugin } from '../shared/indexer.fedcd831.mjs';
|
|
3
3
|
import { ConsolaReporter, ConsolaInstance } from 'consola';
|
|
4
4
|
export { ConsolaInstance, ConsolaReporter } from 'consola';
|
|
5
5
|
import '@apibara/protocol';
|
package/dist/plugins/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { d as defineIndexerPlugin } from '../shared/indexer.
|
|
1
|
+
import { b as IndexerPlugin } from '../shared/indexer.fedcd831.js';
|
|
2
|
+
export { d as defineIndexerPlugin } from '../shared/indexer.fedcd831.js';
|
|
3
3
|
import { ConsolaReporter, ConsolaInstance } from 'consola';
|
|
4
4
|
export { ConsolaInstance, ConsolaReporter } from 'consola';
|
|
5
5
|
import '@apibara/protocol';
|
|
@@ -97,4 +97,4 @@ interface RunOptions {
|
|
|
97
97
|
}
|
|
98
98
|
declare function run<TFilter, TBlock>(client: Client<TFilter, TBlock>, indexer: Indexer<TFilter, TBlock>, runOptions?: RunOptions): Promise<void>;
|
|
99
99
|
|
|
100
|
-
export { type IndexerWithStreamConfig as I, type ReconnectOptions as R, type UseMiddlewareFunction as U, type
|
|
100
|
+
export { type IndexerWithStreamConfig as I, type ReconnectOptions as R, type UseMiddlewareFunction as U, type Indexer as a, type IndexerPlugin as b, type IndexerConfig as c, defineIndexerPlugin as d, type IndexerHooks as e, type IndexerStartingCursor as f, defineIndexer as g, createIndexer as h, type RunOptions as i, run as j, runWithReconnect as r, useIndexerContext as u };
|
|
@@ -97,4 +97,4 @@ interface RunOptions {
|
|
|
97
97
|
}
|
|
98
98
|
declare function run<TFilter, TBlock>(client: Client<TFilter, TBlock>, indexer: Indexer<TFilter, TBlock>, runOptions?: RunOptions): Promise<void>;
|
|
99
99
|
|
|
100
|
-
export { type IndexerWithStreamConfig as I, type ReconnectOptions as R, type UseMiddlewareFunction as U, type
|
|
100
|
+
export { type IndexerWithStreamConfig as I, type ReconnectOptions as R, type UseMiddlewareFunction as U, type Indexer as a, type IndexerPlugin as b, type IndexerConfig as c, defineIndexerPlugin as d, type IndexerHooks as e, type IndexerStartingCursor as f, defineIndexer as g, createIndexer as h, type RunOptions as i, run as j, runWithReconnect as r, useIndexerContext as u };
|
|
@@ -97,4 +97,4 @@ interface RunOptions {
|
|
|
97
97
|
}
|
|
98
98
|
declare function run<TFilter, TBlock>(client: Client<TFilter, TBlock>, indexer: Indexer<TFilter, TBlock>, runOptions?: RunOptions): Promise<void>;
|
|
99
99
|
|
|
100
|
-
export { type IndexerWithStreamConfig as I, type ReconnectOptions as R, type UseMiddlewareFunction as U, type
|
|
100
|
+
export { type IndexerWithStreamConfig as I, type ReconnectOptions as R, type UseMiddlewareFunction as U, type Indexer as a, type IndexerPlugin as b, type IndexerConfig as c, defineIndexerPlugin as d, type IndexerHooks as e, type IndexerStartingCursor as f, defineIndexer as g, createIndexer as h, type RunOptions as i, run as j, runWithReconnect as r, useIndexerContext as u };
|
package/dist/testing/index.d.cts
CHANGED
package/dist/testing/index.d.mts
CHANGED
package/dist/testing/index.d.ts
CHANGED
package/dist/vcr/index.d.cts
CHANGED
package/dist/vcr/index.d.mts
CHANGED
package/dist/vcr/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apibara/indexer",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.38",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -35,10 +35,22 @@
|
|
|
35
35
|
"default": "./dist/plugins/index.mjs"
|
|
36
36
|
},
|
|
37
37
|
"./internal": {
|
|
38
|
+
"types": "./dist/internal/index.d.ts",
|
|
39
|
+
"import": "./dist/internal/index.mjs",
|
|
40
|
+
"require": "./dist/internal/index.cjs",
|
|
41
|
+
"default": "./dist/internal/index.mjs"
|
|
42
|
+
},
|
|
43
|
+
"./internal/testing": {
|
|
38
44
|
"types": "./dist/internal/testing.d.ts",
|
|
39
45
|
"import": "./dist/internal/testing.mjs",
|
|
40
46
|
"require": "./dist/internal/testing.cjs",
|
|
41
47
|
"default": "./dist/internal/testing.mjs"
|
|
48
|
+
},
|
|
49
|
+
"./internal/plugins": {
|
|
50
|
+
"types": "./dist/internal/plugins.d.ts",
|
|
51
|
+
"import": "./dist/internal/plugins.mjs",
|
|
52
|
+
"require": "./dist/internal/plugins.cjs",
|
|
53
|
+
"default": "./dist/internal/plugins.mjs"
|
|
42
54
|
}
|
|
43
55
|
},
|
|
44
56
|
"scripts": {
|
|
@@ -58,7 +70,7 @@
|
|
|
58
70
|
"vitest": "^1.6.0"
|
|
59
71
|
},
|
|
60
72
|
"dependencies": {
|
|
61
|
-
"@apibara/protocol": "2.0.0-beta.
|
|
73
|
+
"@apibara/protocol": "2.0.0-beta.38",
|
|
62
74
|
"@opentelemetry/api": "^1.9.0",
|
|
63
75
|
"ci-info": "^4.1.0",
|
|
64
76
|
"consola": "^3.2.3",
|
package/src/indexer.test.ts
CHANGED
|
@@ -248,8 +248,8 @@ describe("Run Test", () => {
|
|
|
248
248
|
const metadata: Record<string, unknown> = {};
|
|
249
249
|
|
|
250
250
|
const indexer = getMockIndexer({
|
|
251
|
-
plugins: [mockSink({ output, metadata })],
|
|
252
251
|
override: {
|
|
252
|
+
plugins: [mockSink({ output, metadata })],
|
|
253
253
|
startingCursor: { orderKey: 100n },
|
|
254
254
|
factory: async ({ block }) => {
|
|
255
255
|
if (block.data === "B") {
|
|
@@ -400,8 +400,8 @@ describe("Run Test", () => {
|
|
|
400
400
|
const metadata: Record<string, unknown> = {};
|
|
401
401
|
|
|
402
402
|
const indexer = getMockIndexer({
|
|
403
|
-
plugins: [mockSink({ output, metadata })],
|
|
404
403
|
override: {
|
|
404
|
+
plugins: [mockSink({ output, metadata })],
|
|
405
405
|
startingCursor: { orderKey: 100n },
|
|
406
406
|
factory: async ({ block }) => {
|
|
407
407
|
if (block.data === "B") {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../plugins/context";
|
package/src/internal/testing.ts
CHANGED
|
@@ -8,7 +8,8 @@ import {
|
|
|
8
8
|
|
|
9
9
|
import { useIndexerContext } from "../context";
|
|
10
10
|
import { type IndexerConfig, createIndexer, defineIndexer } from "../indexer";
|
|
11
|
-
import {
|
|
11
|
+
import { defineIndexerPlugin } from "../plugins";
|
|
12
|
+
import { type InternalContext, internalContext } from "./plugins";
|
|
12
13
|
|
|
13
14
|
export type MockMessagesOptions = {
|
|
14
15
|
invalidate?: {
|
|
@@ -65,21 +66,32 @@ export function generateMockMessages(
|
|
|
65
66
|
return messages;
|
|
66
67
|
}
|
|
67
68
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
override,
|
|
71
|
-
}: {
|
|
72
|
-
plugins?: ReadonlyArray<IndexerPlugin<MockFilter, MockBlock>>;
|
|
69
|
+
type MockIndexerParams = {
|
|
70
|
+
internalContext?: InternalContext;
|
|
73
71
|
override?: Partial<IndexerConfig<MockFilter, MockBlock>>;
|
|
74
|
-
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export function getMockIndexer(params?: MockIndexerParams) {
|
|
75
|
+
const { internalContext: contextParams, override } = params ?? {};
|
|
76
|
+
const { plugins, ...rest } = override ?? {};
|
|
77
|
+
|
|
75
78
|
return createIndexer(
|
|
76
79
|
defineIndexer(MockStream)({
|
|
77
80
|
streamUrl: "https://sepolia.ethereum.a5a.ch",
|
|
78
81
|
finality: "accepted",
|
|
79
82
|
filter: {},
|
|
80
|
-
async transform(
|
|
81
|
-
plugins
|
|
82
|
-
|
|
83
|
+
async transform() {},
|
|
84
|
+
plugins: [
|
|
85
|
+
internalContext(
|
|
86
|
+
contextParams ??
|
|
87
|
+
({
|
|
88
|
+
availableIndexers: ["testing"],
|
|
89
|
+
indexerName: "testing",
|
|
90
|
+
} as InternalContext),
|
|
91
|
+
),
|
|
92
|
+
...(plugins ?? []),
|
|
93
|
+
],
|
|
94
|
+
...(rest ?? {}),
|
|
83
95
|
}),
|
|
84
96
|
);
|
|
85
97
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { useIndexerContext } from "../context";
|
|
2
|
+
import { defineIndexerPlugin } from "./config";
|
|
3
|
+
|
|
4
|
+
export const INTERNAL_CONTEXT_PROPERTY = "_internal";
|
|
5
|
+
|
|
6
|
+
export function internalContext<TFilter, TBlock, TTxnParams>(
|
|
7
|
+
values: Record<string, unknown>,
|
|
8
|
+
) {
|
|
9
|
+
return defineIndexerPlugin<TFilter, TBlock>((indexer) => {
|
|
10
|
+
indexer.hooks.hook("run:before", () => {
|
|
11
|
+
try {
|
|
12
|
+
const ctx = useIndexerContext();
|
|
13
|
+
ctx[INTERNAL_CONTEXT_PROPERTY] = {
|
|
14
|
+
...(ctx[INTERNAL_CONTEXT_PROPERTY] || {}),
|
|
15
|
+
...values,
|
|
16
|
+
};
|
|
17
|
+
} catch (error) {
|
|
18
|
+
throw new Error("Failed to set internal context", {
|
|
19
|
+
cause: error,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type InternalContext = {
|
|
27
|
+
indexerName: string;
|
|
28
|
+
availableIndexers: string[];
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export function useInternalContext(): InternalContext {
|
|
32
|
+
const ctx = useIndexerContext();
|
|
33
|
+
if (!ctx[INTERNAL_CONTEXT_PROPERTY]) {
|
|
34
|
+
throw new Error("Internal context is not available");
|
|
35
|
+
}
|
|
36
|
+
return ctx[INTERNAL_CONTEXT_PROPERTY];
|
|
37
|
+
}
|