@apibara/indexer 2.1.0-beta.5 → 2.1.0-beta.51
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 +134 -41
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +8 -1
- package/dist/index.d.mts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.mjs +125 -34
- package/dist/index.mjs.map +1 -0
- package/dist/internal/index.cjs +1 -0
- package/dist/internal/index.cjs.map +1 -0
- package/dist/internal/index.mjs +1 -0
- package/dist/internal/index.mjs.map +1 -0
- package/dist/internal/plugins.cjs +5 -5
- package/dist/internal/plugins.cjs.map +1 -0
- 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 +3 -3
- package/dist/internal/plugins.mjs.map +1 -0
- package/dist/internal/testing.cjs +35 -14
- package/dist/internal/testing.cjs.map +1 -0
- package/dist/internal/testing.d.cts +16 -12
- package/dist/internal/testing.d.mts +16 -12
- package/dist/internal/testing.d.ts +16 -12
- package/dist/internal/testing.mjs +33 -12
- package/dist/internal/testing.mjs.map +1 -0
- package/dist/plugins/index.cjs +4 -4
- package/dist/plugins/index.cjs.map +1 -0
- 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 +4 -4
- package/dist/plugins/index.mjs.map +1 -0
- package/dist/shared/{indexer.2416906c.cjs → indexer.03c9f151.cjs} +8 -5
- package/dist/shared/indexer.03c9f151.cjs.map +1 -0
- package/dist/shared/{indexer.ff25c953.mjs → indexer.2673dcb1.mjs} +7 -4
- package/dist/shared/indexer.2673dcb1.mjs.map +1 -0
- package/dist/shared/{indexer.077335f3.cjs → indexer.479ae593.cjs} +6 -0
- package/dist/shared/indexer.479ae593.cjs.map +1 -0
- package/dist/shared/{indexer.fedcd831.d.cts → indexer.4ef52548.d.cts} +40 -23
- package/dist/shared/{indexer.fedcd831.d.mts → indexer.4ef52548.d.mts} +40 -23
- package/dist/shared/{indexer.fedcd831.d.ts → indexer.4ef52548.d.ts} +40 -23
- package/dist/shared/{indexer.a55ad619.mjs → indexer.75773ef1.mjs} +6 -1
- package/dist/shared/indexer.75773ef1.mjs.map +1 -0
- package/dist/testing/index.cjs +19 -10
- package/dist/testing/index.cjs.map +1 -0
- package/dist/testing/index.d.cts +11 -7
- package/dist/testing/index.d.mts +11 -7
- package/dist/testing/index.d.ts +11 -7
- package/dist/testing/index.mjs +20 -11
- package/dist/testing/index.mjs.map +1 -0
- package/dist/vcr/index.cjs +3 -1
- package/dist/vcr/index.cjs.map +1 -0
- 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 +3 -1
- package/dist/vcr/index.mjs.map +1 -0
- package/package.json +3 -3
- package/src/index.ts +1 -0
- package/src/indexer.ts +151 -50
- package/src/internal/testing.ts +67 -23
- package/src/otel.ts +29 -2
- package/src/plugins/context.ts +1 -1
- package/src/plugins/logger.ts +11 -2
- package/src/testing/index.ts +30 -6
- package/src/utils/index.ts +21 -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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { StreamDataRequest, StreamDataOptions, Cursor, StreamDataResponse, Invalidate, Finalize,
|
|
1
|
+
import { StreamDataRequest, StreamDataOptions, Cursor, StreamDataResponse, Invalidate, Finalize, SystemMessage, DataFinality, DataProduction, CreateClientOptions, StreamConfig, Client } from '@apibara/protocol';
|
|
2
2
|
import { NestedHooks, Hookable } from 'hookable';
|
|
3
3
|
|
|
4
4
|
interface IndexerContext extends Record<string, any> {
|
|
@@ -13,36 +13,51 @@ declare function defineIndexerPlugin<TFilter, TBlock>(def: IndexerPlugin<TFilter
|
|
|
13
13
|
|
|
14
14
|
type UseMiddlewareFunction = (fn: MiddlewareFunction<IndexerContext>) => void;
|
|
15
15
|
interface IndexerHooks<TFilter, TBlock> {
|
|
16
|
-
"
|
|
17
|
-
|
|
16
|
+
"plugins:init": ({ abortSignal }: {
|
|
17
|
+
abortSignal?: AbortSignal;
|
|
18
|
+
}) => void;
|
|
19
|
+
"run:before": ({ abortSignal }: {
|
|
20
|
+
abortSignal?: AbortSignal;
|
|
21
|
+
}) => void;
|
|
22
|
+
"run:after": ({ abortSignal }: {
|
|
23
|
+
abortSignal?: AbortSignal;
|
|
24
|
+
}) => void;
|
|
18
25
|
"connect:before": ({ request, options, }: {
|
|
19
26
|
request: StreamDataRequest<TFilter>;
|
|
20
27
|
options: StreamDataOptions;
|
|
28
|
+
abortSignal?: AbortSignal;
|
|
21
29
|
}) => void;
|
|
22
30
|
"connect:after": ({ request, }: {
|
|
23
31
|
request: StreamDataRequest<TFilter>;
|
|
32
|
+
abortSignal?: AbortSignal;
|
|
24
33
|
}) => void;
|
|
25
|
-
"connect:factory": ({ request, endCursor, }: {
|
|
34
|
+
"connect:factory": ({ request, endCursor, abortSignal, }: {
|
|
26
35
|
request: StreamDataRequest<TFilter>;
|
|
27
36
|
endCursor?: Cursor;
|
|
37
|
+
abortSignal?: AbortSignal;
|
|
28
38
|
}) => void;
|
|
29
|
-
"handler:middleware": ({ use }: {
|
|
39
|
+
"handler:middleware": ({ use, abortSignal, }: {
|
|
30
40
|
use: UseMiddlewareFunction;
|
|
41
|
+
abortSignal?: AbortSignal;
|
|
31
42
|
}) => void;
|
|
32
|
-
message: ({ message }: {
|
|
43
|
+
message: ({ message, abortSignal, }: {
|
|
33
44
|
message: StreamDataResponse<TBlock>;
|
|
45
|
+
abortSignal?: AbortSignal;
|
|
34
46
|
}) => void;
|
|
35
|
-
"message:invalidate": ({ message }: {
|
|
47
|
+
"message:invalidate": ({ message, abortSignal, }: {
|
|
36
48
|
message: Invalidate;
|
|
49
|
+
abortSignal?: AbortSignal;
|
|
37
50
|
}) => void;
|
|
38
|
-
"message:finalize": ({ message }: {
|
|
51
|
+
"message:finalize": ({ message, abortSignal, }: {
|
|
39
52
|
message: Finalize;
|
|
53
|
+
abortSignal?: AbortSignal;
|
|
40
54
|
}) => void;
|
|
41
|
-
"message:heartbeat": ({
|
|
42
|
-
|
|
55
|
+
"message:heartbeat": ({ abortSignal }: {
|
|
56
|
+
abortSignal?: AbortSignal;
|
|
43
57
|
}) => void;
|
|
44
|
-
"message:systemMessage": ({ message }: {
|
|
58
|
+
"message:systemMessage": ({ message, abortSignal, }: {
|
|
45
59
|
message: SystemMessage;
|
|
60
|
+
abortSignal?: AbortSignal;
|
|
46
61
|
}) => void;
|
|
47
62
|
}
|
|
48
63
|
type IndexerStartingCursor = {
|
|
@@ -55,23 +70,24 @@ type IndexerStartingCursor = {
|
|
|
55
70
|
startingCursor?: never;
|
|
56
71
|
startingBlock?: never;
|
|
57
72
|
};
|
|
73
|
+
type HandlerArgs<TBlock> = {
|
|
74
|
+
block: TBlock;
|
|
75
|
+
cursor?: Cursor | undefined;
|
|
76
|
+
endCursor?: Cursor | undefined;
|
|
77
|
+
finality: DataFinality;
|
|
78
|
+
production: DataProduction;
|
|
79
|
+
context: IndexerContext;
|
|
80
|
+
abortSignal?: AbortSignal;
|
|
81
|
+
};
|
|
58
82
|
type IndexerConfig<TFilter, TBlock> = {
|
|
59
83
|
streamUrl: string;
|
|
60
84
|
filter: TFilter;
|
|
61
85
|
finality?: DataFinality;
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
context: IndexerContext;
|
|
65
|
-
}) => Promise<{
|
|
86
|
+
clientOptions?: CreateClientOptions;
|
|
87
|
+
factory?: (args: HandlerArgs<TBlock>) => Promise<{
|
|
66
88
|
filter?: TFilter;
|
|
67
89
|
}>;
|
|
68
|
-
transform: (args:
|
|
69
|
-
block: TBlock;
|
|
70
|
-
cursor?: Cursor | undefined;
|
|
71
|
-
endCursor?: Cursor | undefined;
|
|
72
|
-
finality: DataFinality;
|
|
73
|
-
context: IndexerContext;
|
|
74
|
-
}) => Promise<void>;
|
|
90
|
+
transform: (args: HandlerArgs<TBlock>) => Promise<void>;
|
|
75
91
|
hooks?: NestedHooks<IndexerHooks<TFilter, TBlock>>;
|
|
76
92
|
plugins?: ReadonlyArray<IndexerPlugin<TFilter, TBlock>>;
|
|
77
93
|
debug?: boolean;
|
|
@@ -94,7 +110,8 @@ interface ReconnectOptions {
|
|
|
94
110
|
declare function runWithReconnect<TFilter, TBlock>(client: Client<TFilter, TBlock>, indexer: Indexer<TFilter, TBlock>, options?: ReconnectOptions): Promise<void>;
|
|
95
111
|
interface RunOptions {
|
|
96
112
|
onConnect?: () => void | Promise<void>;
|
|
113
|
+
abortSignal?: AbortSignal;
|
|
97
114
|
}
|
|
98
115
|
declare function run<TFilter, TBlock>(client: Client<TFilter, TBlock>, indexer: Indexer<TFilter, TBlock>, runOptions?: RunOptions): Promise<void>;
|
|
99
116
|
|
|
100
|
-
export { type
|
|
117
|
+
export { type HandlerArgs as H, type IndexerHooks as I, type ReconnectOptions as R, type UseMiddlewareFunction as U, type IndexerStartingCursor as a, type IndexerConfig as b, type IndexerWithStreamConfig as c, defineIndexer as d, type Indexer as e, createIndexer as f, type RunOptions as g, run as h, type IndexerPlugin as i, defineIndexerPlugin as j, runWithReconnect as r, useIndexerContext as u };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { StreamDataRequest, StreamDataOptions, Cursor, StreamDataResponse, Invalidate, Finalize,
|
|
1
|
+
import { StreamDataRequest, StreamDataOptions, Cursor, StreamDataResponse, Invalidate, Finalize, SystemMessage, DataFinality, DataProduction, CreateClientOptions, StreamConfig, Client } from '@apibara/protocol';
|
|
2
2
|
import { NestedHooks, Hookable } from 'hookable';
|
|
3
3
|
|
|
4
4
|
interface IndexerContext extends Record<string, any> {
|
|
@@ -13,36 +13,51 @@ declare function defineIndexerPlugin<TFilter, TBlock>(def: IndexerPlugin<TFilter
|
|
|
13
13
|
|
|
14
14
|
type UseMiddlewareFunction = (fn: MiddlewareFunction<IndexerContext>) => void;
|
|
15
15
|
interface IndexerHooks<TFilter, TBlock> {
|
|
16
|
-
"
|
|
17
|
-
|
|
16
|
+
"plugins:init": ({ abortSignal }: {
|
|
17
|
+
abortSignal?: AbortSignal;
|
|
18
|
+
}) => void;
|
|
19
|
+
"run:before": ({ abortSignal }: {
|
|
20
|
+
abortSignal?: AbortSignal;
|
|
21
|
+
}) => void;
|
|
22
|
+
"run:after": ({ abortSignal }: {
|
|
23
|
+
abortSignal?: AbortSignal;
|
|
24
|
+
}) => void;
|
|
18
25
|
"connect:before": ({ request, options, }: {
|
|
19
26
|
request: StreamDataRequest<TFilter>;
|
|
20
27
|
options: StreamDataOptions;
|
|
28
|
+
abortSignal?: AbortSignal;
|
|
21
29
|
}) => void;
|
|
22
30
|
"connect:after": ({ request, }: {
|
|
23
31
|
request: StreamDataRequest<TFilter>;
|
|
32
|
+
abortSignal?: AbortSignal;
|
|
24
33
|
}) => void;
|
|
25
|
-
"connect:factory": ({ request, endCursor, }: {
|
|
34
|
+
"connect:factory": ({ request, endCursor, abortSignal, }: {
|
|
26
35
|
request: StreamDataRequest<TFilter>;
|
|
27
36
|
endCursor?: Cursor;
|
|
37
|
+
abortSignal?: AbortSignal;
|
|
28
38
|
}) => void;
|
|
29
|
-
"handler:middleware": ({ use }: {
|
|
39
|
+
"handler:middleware": ({ use, abortSignal, }: {
|
|
30
40
|
use: UseMiddlewareFunction;
|
|
41
|
+
abortSignal?: AbortSignal;
|
|
31
42
|
}) => void;
|
|
32
|
-
message: ({ message }: {
|
|
43
|
+
message: ({ message, abortSignal, }: {
|
|
33
44
|
message: StreamDataResponse<TBlock>;
|
|
45
|
+
abortSignal?: AbortSignal;
|
|
34
46
|
}) => void;
|
|
35
|
-
"message:invalidate": ({ message }: {
|
|
47
|
+
"message:invalidate": ({ message, abortSignal, }: {
|
|
36
48
|
message: Invalidate;
|
|
49
|
+
abortSignal?: AbortSignal;
|
|
37
50
|
}) => void;
|
|
38
|
-
"message:finalize": ({ message }: {
|
|
51
|
+
"message:finalize": ({ message, abortSignal, }: {
|
|
39
52
|
message: Finalize;
|
|
53
|
+
abortSignal?: AbortSignal;
|
|
40
54
|
}) => void;
|
|
41
|
-
"message:heartbeat": ({
|
|
42
|
-
|
|
55
|
+
"message:heartbeat": ({ abortSignal }: {
|
|
56
|
+
abortSignal?: AbortSignal;
|
|
43
57
|
}) => void;
|
|
44
|
-
"message:systemMessage": ({ message }: {
|
|
58
|
+
"message:systemMessage": ({ message, abortSignal, }: {
|
|
45
59
|
message: SystemMessage;
|
|
60
|
+
abortSignal?: AbortSignal;
|
|
46
61
|
}) => void;
|
|
47
62
|
}
|
|
48
63
|
type IndexerStartingCursor = {
|
|
@@ -55,23 +70,24 @@ type IndexerStartingCursor = {
|
|
|
55
70
|
startingCursor?: never;
|
|
56
71
|
startingBlock?: never;
|
|
57
72
|
};
|
|
73
|
+
type HandlerArgs<TBlock> = {
|
|
74
|
+
block: TBlock;
|
|
75
|
+
cursor?: Cursor | undefined;
|
|
76
|
+
endCursor?: Cursor | undefined;
|
|
77
|
+
finality: DataFinality;
|
|
78
|
+
production: DataProduction;
|
|
79
|
+
context: IndexerContext;
|
|
80
|
+
abortSignal?: AbortSignal;
|
|
81
|
+
};
|
|
58
82
|
type IndexerConfig<TFilter, TBlock> = {
|
|
59
83
|
streamUrl: string;
|
|
60
84
|
filter: TFilter;
|
|
61
85
|
finality?: DataFinality;
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
context: IndexerContext;
|
|
65
|
-
}) => Promise<{
|
|
86
|
+
clientOptions?: CreateClientOptions;
|
|
87
|
+
factory?: (args: HandlerArgs<TBlock>) => Promise<{
|
|
66
88
|
filter?: TFilter;
|
|
67
89
|
}>;
|
|
68
|
-
transform: (args:
|
|
69
|
-
block: TBlock;
|
|
70
|
-
cursor?: Cursor | undefined;
|
|
71
|
-
endCursor?: Cursor | undefined;
|
|
72
|
-
finality: DataFinality;
|
|
73
|
-
context: IndexerContext;
|
|
74
|
-
}) => Promise<void>;
|
|
90
|
+
transform: (args: HandlerArgs<TBlock>) => Promise<void>;
|
|
75
91
|
hooks?: NestedHooks<IndexerHooks<TFilter, TBlock>>;
|
|
76
92
|
plugins?: ReadonlyArray<IndexerPlugin<TFilter, TBlock>>;
|
|
77
93
|
debug?: boolean;
|
|
@@ -94,7 +110,8 @@ interface ReconnectOptions {
|
|
|
94
110
|
declare function runWithReconnect<TFilter, TBlock>(client: Client<TFilter, TBlock>, indexer: Indexer<TFilter, TBlock>, options?: ReconnectOptions): Promise<void>;
|
|
95
111
|
interface RunOptions {
|
|
96
112
|
onConnect?: () => void | Promise<void>;
|
|
113
|
+
abortSignal?: AbortSignal;
|
|
97
114
|
}
|
|
98
115
|
declare function run<TFilter, TBlock>(client: Client<TFilter, TBlock>, indexer: Indexer<TFilter, TBlock>, runOptions?: RunOptions): Promise<void>;
|
|
99
116
|
|
|
100
|
-
export { type
|
|
117
|
+
export { type HandlerArgs as H, type IndexerHooks as I, type ReconnectOptions as R, type UseMiddlewareFunction as U, type IndexerStartingCursor as a, type IndexerConfig as b, type IndexerWithStreamConfig as c, defineIndexer as d, type Indexer as e, createIndexer as f, type RunOptions as g, run as h, type IndexerPlugin as i, defineIndexerPlugin as j, runWithReconnect as r, useIndexerContext as u };
|
|
@@ -9,4 +9,9 @@ function useIndexerContext() {
|
|
|
9
9
|
return indexerAsyncContext.use();
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
function defineIndexerPlugin(def) {
|
|
13
|
+
return def;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { defineIndexerPlugin as d, indexerAsyncContext as i, useIndexerContext as u };
|
|
17
|
+
//# sourceMappingURL=indexer.75773ef1.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indexer.75773ef1.mjs","sources":["../../src/context.ts","../../src/plugins/config.ts"],"sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\nimport type { Cursor, DataFinality } from \"@apibara/protocol\";\nimport { getContext } from \"unctx\";\n\n// biome-ignore lint/suspicious/noExplicitAny: context type\nexport interface IndexerContext extends Record<string, any> {}\n\nexport const indexerAsyncContext = getContext<IndexerContext>(\"indexer\", {\n asyncContext: true,\n AsyncLocalStorage,\n});\n\nexport function useIndexerContext() {\n return indexerAsyncContext.use() as IndexerContext;\n}\n\nexport interface MessageMetadataContext extends IndexerContext {\n cursor?: Cursor;\n endCursor?: Cursor;\n finality?: DataFinality;\n}\n\nexport function useMessageMetadataContext(): MessageMetadataContext {\n return useIndexerContext() as MessageMetadataContext;\n}\n","import type { Indexer } from \"../indexer\";\n\nexport type IndexerPlugin<TFilter, TBlock> = (\n indexer: Indexer<TFilter, TBlock>,\n) => void;\n\nexport function defineIndexerPlugin<TFilter, TBlock>(\n def: IndexerPlugin<TFilter, TBlock>,\n) {\n return def;\n}\n"],"names":[],"mappings":";;;AAOa,MAAA,mBAAA,GAAsB,WAA2B,SAAW,EAAA;AAAA,EACvE,YAAc,EAAA,IAAA;AAAA,EACd,iBAAA;AACF,CAAC,EAAA;AAEM,SAAS,iBAAoB,GAAA;AAClC,EAAA,OAAO,oBAAoB,GAAI,EAAA,CAAA;AACjC;;ACRO,SAAS,oBACd,GACA,EAAA;AACA,EAAO,OAAA,GAAA,CAAA;AACT;;;;"}
|
package/dist/testing/index.cjs
CHANGED
|
@@ -2,18 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
const protocol = require('@apibara/protocol');
|
|
4
4
|
const ci = require('ci-info');
|
|
5
|
+
const hookable = require('hookable');
|
|
6
|
+
const config = require('../shared/indexer.479ae593.cjs');
|
|
5
7
|
const index = require('../index.cjs');
|
|
6
8
|
const internal_plugins = require('../internal/plugins.cjs');
|
|
7
|
-
const logger = require('../shared/indexer.
|
|
9
|
+
const logger = require('../shared/indexer.03c9f151.cjs');
|
|
8
10
|
const vcr_index = require('../vcr/index.cjs');
|
|
9
|
-
require('consola');
|
|
10
|
-
require('hookable');
|
|
11
|
-
require('node:assert');
|
|
12
|
-
require('../shared/indexer.077335f3.cjs');
|
|
13
11
|
require('node:async_hooks');
|
|
14
12
|
require('unctx');
|
|
13
|
+
require('consola');
|
|
14
|
+
require('node:assert');
|
|
15
15
|
require('@opentelemetry/api');
|
|
16
|
-
require('../shared/indexer.601ceab0.cjs');
|
|
17
16
|
require('node:fs/promises');
|
|
18
17
|
require('node:path');
|
|
19
18
|
require('node:fs');
|
|
@@ -24,18 +23,23 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
|
|
|
24
23
|
const ci__default = /*#__PURE__*/_interopDefaultCompat(ci);
|
|
25
24
|
|
|
26
25
|
function createVcr() {
|
|
26
|
+
let result;
|
|
27
27
|
return {
|
|
28
|
-
async run(cassetteName, indexerConfig,
|
|
28
|
+
async run(cassetteName, indexerConfig, config$1) {
|
|
29
29
|
const vcrConfig = {
|
|
30
30
|
cassetteDir: "cassettes"
|
|
31
31
|
};
|
|
32
|
+
indexerConfig.hooks = hookable.mergeHooks(
|
|
33
|
+
indexerConfig.hooks ?? {},
|
|
34
|
+
config$1.hooks ?? {}
|
|
35
|
+
);
|
|
32
36
|
const cassetteOptions = {
|
|
33
37
|
name: cassetteName,
|
|
34
38
|
startingCursor: {
|
|
35
|
-
orderKey: range.fromBlock
|
|
39
|
+
orderKey: config$1.range.fromBlock
|
|
36
40
|
},
|
|
37
41
|
endingCursor: {
|
|
38
|
-
orderKey: range.toBlock
|
|
42
|
+
orderKey: config$1.range.toBlock
|
|
39
43
|
}
|
|
40
44
|
};
|
|
41
45
|
indexerConfig.plugins = [
|
|
@@ -47,11 +51,14 @@ function createVcr() {
|
|
|
47
51
|
...indexerConfig.plugins ?? []
|
|
48
52
|
];
|
|
49
53
|
const indexer = index.createIndexer(indexerConfig);
|
|
54
|
+
indexer.hooks.hook("run:after", () => {
|
|
55
|
+
result = config.useIndexerContext();
|
|
56
|
+
});
|
|
50
57
|
if (!vcr_index.isCassetteAvailable(vcrConfig, cassetteName)) {
|
|
51
58
|
if (ci__default.isCI) {
|
|
52
59
|
throw new Error("Cannot record cassette in CI");
|
|
53
60
|
}
|
|
54
|
-
const client = protocol.
|
|
61
|
+
const client = protocol.createAuthenticatedClient(
|
|
55
62
|
indexer.streamConfig,
|
|
56
63
|
indexer.options.streamUrl
|
|
57
64
|
);
|
|
@@ -59,8 +66,10 @@ function createVcr() {
|
|
|
59
66
|
} else {
|
|
60
67
|
await vcr_index.replay(vcrConfig, indexer, cassetteName);
|
|
61
68
|
}
|
|
69
|
+
return result;
|
|
62
70
|
}
|
|
63
71
|
};
|
|
64
72
|
}
|
|
65
73
|
|
|
66
74
|
exports.createVcr = createVcr;
|
|
75
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/testing/index.ts"],"sourcesContent":["import { createAuthenticatedClient } from \"@apibara/protocol\";\nimport ci from \"ci-info\";\nimport { type NestedHooks, mergeHooks } from \"hookable\";\nimport { useIndexerContext } from \"../context\";\nimport {\n type IndexerHooks,\n type IndexerWithStreamConfig,\n createIndexer,\n} from \"../indexer\";\nimport { type InternalContext, internalContext } from \"../plugins/context\";\nimport { logger } from \"../plugins/logger\";\nimport type { CassetteOptions, VcrConfig } from \"../vcr/config\";\nimport { isCassetteAvailable } from \"../vcr/helper\";\nimport { record } from \"../vcr/record\";\nimport { replay } from \"../vcr/replay\";\n\nexport type VcrResult = Record<string, unknown>;\n\nexport function createVcr() {\n let result: VcrResult;\n\n return {\n async run<TFilter, TBlock>(\n cassetteName: string,\n indexerConfig: IndexerWithStreamConfig<TFilter, TBlock>,\n config: {\n range: { fromBlock: bigint; toBlock: bigint };\n hooks?: NestedHooks<IndexerHooks<TFilter, TBlock>>;\n },\n ) {\n const vcrConfig: VcrConfig = {\n cassetteDir: \"cassettes\",\n };\n\n indexerConfig.hooks = mergeHooks(\n indexerConfig.hooks ?? {},\n config.hooks ?? {},\n );\n\n const cassetteOptions: CassetteOptions = {\n name: cassetteName,\n startingCursor: {\n orderKey: config.range.fromBlock,\n },\n endingCursor: {\n orderKey: config.range.toBlock,\n },\n };\n\n indexerConfig.plugins = [\n internalContext({\n indexerName: cassetteName,\n availableIndexers: [cassetteName],\n } as InternalContext),\n logger(),\n ...(indexerConfig.plugins ?? []),\n ];\n\n const indexer = createIndexer(indexerConfig);\n\n indexer.hooks.hook(\"run:after\", () => {\n result = useIndexerContext();\n });\n\n if (!isCassetteAvailable(vcrConfig, cassetteName)) {\n if (ci.isCI) {\n throw new Error(\"Cannot record cassette in CI\");\n }\n\n const client = createAuthenticatedClient(\n indexer.streamConfig,\n indexer.options.streamUrl,\n );\n await record(vcrConfig, client, indexer, cassetteOptions);\n } else {\n await replay(vcrConfig, indexer, cassetteName);\n }\n\n return result;\n },\n };\n}\n"],"names":["config","mergeHooks","internalContext","logger","createIndexer","useIndexerContext","isCassetteAvailable","ci","createAuthenticatedClient","record","replay"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAkBO,SAAS,SAAY,GAAA;AAC1B,EAAI,IAAA,MAAA,CAAA;AAEJ,EAAO,OAAA;AAAA,IACL,MAAM,GAAA,CACJ,YACA,EAAA,aAAA,EACAA,QAIA,EAAA;AACA,MAAA,MAAM,SAAuB,GAAA;AAAA,QAC3B,WAAa,EAAA,WAAA;AAAA,OACf,CAAA;AAEA,MAAA,aAAA,CAAc,KAAQ,GAAAC,mBAAA;AAAA,QACpB,aAAA,CAAc,SAAS,EAAC;AAAA,QACxBD,QAAA,CAAO,SAAS,EAAC;AAAA,OACnB,CAAA;AAEA,MAAA,MAAM,eAAmC,GAAA;AAAA,QACvC,IAAM,EAAA,YAAA;AAAA,QACN,cAAgB,EAAA;AAAA,UACd,QAAA,EAAUA,SAAO,KAAM,CAAA,SAAA;AAAA,SACzB;AAAA,QACA,YAAc,EAAA;AAAA,UACZ,QAAA,EAAUA,SAAO,KAAM,CAAA,OAAA;AAAA,SACzB;AAAA,OACF,CAAA;AAEA,MAAA,aAAA,CAAc,OAAU,GAAA;AAAA,QACtBE,gCAAgB,CAAA;AAAA,UACd,WAAa,EAAA,YAAA;AAAA,UACb,iBAAA,EAAmB,CAAC,YAAY,CAAA;AAAA,SACd,CAAA;AAAA,QACpBC,aAAO,EAAA;AAAA,QACP,GAAI,aAAc,CAAA,OAAA,IAAW,EAAC;AAAA,OAChC,CAAA;AAEA,MAAM,MAAA,OAAA,GAAUC,oBAAc,aAAa,CAAA,CAAA;AAE3C,MAAQ,OAAA,CAAA,KAAA,CAAM,IAAK,CAAA,WAAA,EAAa,MAAM;AACpC,QAAA,MAAA,GAASC,wBAAkB,EAAA,CAAA;AAAA,OAC5B,CAAA,CAAA;AAED,MAAA,IAAI,CAACC,6BAAA,CAAoB,SAAW,EAAA,YAAY,CAAG,EAAA;AACjD,QAAA,IAAIC,YAAG,IAAM,EAAA;AACX,UAAM,MAAA,IAAI,MAAM,8BAA8B,CAAA,CAAA;AAAA,SAChD;AAEA,QAAA,MAAM,MAAS,GAAAC,kCAAA;AAAA,UACb,OAAQ,CAAA,YAAA;AAAA,UACR,QAAQ,OAAQ,CAAA,SAAA;AAAA,SAClB,CAAA;AACA,QAAA,MAAMC,gBAAO,CAAA,SAAA,EAAW,MAAQ,EAAA,OAAA,EAAS,eAAe,CAAA,CAAA;AAAA,OACnD,MAAA;AACL,QAAM,MAAAC,gBAAA,CAAO,SAAW,EAAA,OAAA,EAAS,YAAY,CAAA,CAAA;AAAA,OAC/C;AAEA,MAAO,OAAA,MAAA,CAAA;AAAA,KACT;AAAA,GACF,CAAA;AACF;;;;"}
|
package/dist/testing/index.d.cts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { NestedHooks } from 'hookable';
|
|
2
|
+
import { c as IndexerWithStreamConfig, I as IndexerHooks } from '../shared/indexer.4ef52548.cjs';
|
|
2
3
|
import '@apibara/protocol';
|
|
3
|
-
import 'hookable';
|
|
4
4
|
|
|
5
|
+
type VcrResult = Record<string, unknown>;
|
|
5
6
|
declare function createVcr(): {
|
|
6
|
-
run<TFilter, TBlock>(cassetteName: string, indexerConfig: IndexerWithStreamConfig<TFilter, TBlock>,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
run<TFilter, TBlock>(cassetteName: string, indexerConfig: IndexerWithStreamConfig<TFilter, TBlock>, config: {
|
|
8
|
+
range: {
|
|
9
|
+
fromBlock: bigint;
|
|
10
|
+
toBlock: bigint;
|
|
11
|
+
};
|
|
12
|
+
hooks?: NestedHooks<IndexerHooks<TFilter, TBlock>>;
|
|
13
|
+
}): Promise<VcrResult>;
|
|
10
14
|
};
|
|
11
15
|
|
|
12
|
-
export { createVcr };
|
|
16
|
+
export { type VcrResult, createVcr };
|
package/dist/testing/index.d.mts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { NestedHooks } from 'hookable';
|
|
2
|
+
import { c as IndexerWithStreamConfig, I as IndexerHooks } from '../shared/indexer.4ef52548.mjs';
|
|
2
3
|
import '@apibara/protocol';
|
|
3
|
-
import 'hookable';
|
|
4
4
|
|
|
5
|
+
type VcrResult = Record<string, unknown>;
|
|
5
6
|
declare function createVcr(): {
|
|
6
|
-
run<TFilter, TBlock>(cassetteName: string, indexerConfig: IndexerWithStreamConfig<TFilter, TBlock>,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
run<TFilter, TBlock>(cassetteName: string, indexerConfig: IndexerWithStreamConfig<TFilter, TBlock>, config: {
|
|
8
|
+
range: {
|
|
9
|
+
fromBlock: bigint;
|
|
10
|
+
toBlock: bigint;
|
|
11
|
+
};
|
|
12
|
+
hooks?: NestedHooks<IndexerHooks<TFilter, TBlock>>;
|
|
13
|
+
}): Promise<VcrResult>;
|
|
10
14
|
};
|
|
11
15
|
|
|
12
|
-
export { createVcr };
|
|
16
|
+
export { type VcrResult, createVcr };
|
package/dist/testing/index.d.ts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { NestedHooks } from 'hookable';
|
|
2
|
+
import { c as IndexerWithStreamConfig, I as IndexerHooks } from '../shared/indexer.4ef52548.js';
|
|
2
3
|
import '@apibara/protocol';
|
|
3
|
-
import 'hookable';
|
|
4
4
|
|
|
5
|
+
type VcrResult = Record<string, unknown>;
|
|
5
6
|
declare function createVcr(): {
|
|
6
|
-
run<TFilter, TBlock>(cassetteName: string, indexerConfig: IndexerWithStreamConfig<TFilter, TBlock>,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
run<TFilter, TBlock>(cassetteName: string, indexerConfig: IndexerWithStreamConfig<TFilter, TBlock>, config: {
|
|
8
|
+
range: {
|
|
9
|
+
fromBlock: bigint;
|
|
10
|
+
toBlock: bigint;
|
|
11
|
+
};
|
|
12
|
+
hooks?: NestedHooks<IndexerHooks<TFilter, TBlock>>;
|
|
13
|
+
}): Promise<VcrResult>;
|
|
10
14
|
};
|
|
11
15
|
|
|
12
|
-
export { createVcr };
|
|
16
|
+
export { type VcrResult, createVcr };
|
package/dist/testing/index.mjs
CHANGED
|
@@ -1,35 +1,39 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createAuthenticatedClient } from '@apibara/protocol';
|
|
2
2
|
import ci from 'ci-info';
|
|
3
|
+
import { mergeHooks } from 'hookable';
|
|
4
|
+
import { u as useIndexerContext } from '../shared/indexer.75773ef1.mjs';
|
|
3
5
|
import { createIndexer } from '../index.mjs';
|
|
4
6
|
import { internalContext } from '../internal/plugins.mjs';
|
|
5
|
-
import { l as logger } from '../shared/indexer.
|
|
7
|
+
import { l as logger } from '../shared/indexer.2673dcb1.mjs';
|
|
6
8
|
import { isCassetteAvailable, record, replay } from '../vcr/index.mjs';
|
|
7
|
-
import 'consola';
|
|
8
|
-
import 'hookable';
|
|
9
|
-
import 'node:assert';
|
|
10
|
-
import '../shared/indexer.a55ad619.mjs';
|
|
11
9
|
import 'node:async_hooks';
|
|
12
10
|
import 'unctx';
|
|
11
|
+
import 'consola';
|
|
12
|
+
import 'node:assert';
|
|
13
13
|
import '@opentelemetry/api';
|
|
14
|
-
import '../shared/indexer.9b21ddd2.mjs';
|
|
15
14
|
import 'node:fs/promises';
|
|
16
15
|
import 'node:path';
|
|
17
16
|
import 'node:fs';
|
|
18
17
|
import '@apibara/protocol/testing';
|
|
19
18
|
|
|
20
19
|
function createVcr() {
|
|
20
|
+
let result;
|
|
21
21
|
return {
|
|
22
|
-
async run(cassetteName, indexerConfig,
|
|
22
|
+
async run(cassetteName, indexerConfig, config) {
|
|
23
23
|
const vcrConfig = {
|
|
24
24
|
cassetteDir: "cassettes"
|
|
25
25
|
};
|
|
26
|
+
indexerConfig.hooks = mergeHooks(
|
|
27
|
+
indexerConfig.hooks ?? {},
|
|
28
|
+
config.hooks ?? {}
|
|
29
|
+
);
|
|
26
30
|
const cassetteOptions = {
|
|
27
31
|
name: cassetteName,
|
|
28
32
|
startingCursor: {
|
|
29
|
-
orderKey: range.fromBlock
|
|
33
|
+
orderKey: config.range.fromBlock
|
|
30
34
|
},
|
|
31
35
|
endingCursor: {
|
|
32
|
-
orderKey: range.toBlock
|
|
36
|
+
orderKey: config.range.toBlock
|
|
33
37
|
}
|
|
34
38
|
};
|
|
35
39
|
indexerConfig.plugins = [
|
|
@@ -41,11 +45,14 @@ function createVcr() {
|
|
|
41
45
|
...indexerConfig.plugins ?? []
|
|
42
46
|
];
|
|
43
47
|
const indexer = createIndexer(indexerConfig);
|
|
48
|
+
indexer.hooks.hook("run:after", () => {
|
|
49
|
+
result = useIndexerContext();
|
|
50
|
+
});
|
|
44
51
|
if (!isCassetteAvailable(vcrConfig, cassetteName)) {
|
|
45
52
|
if (ci.isCI) {
|
|
46
53
|
throw new Error("Cannot record cassette in CI");
|
|
47
54
|
}
|
|
48
|
-
const client =
|
|
55
|
+
const client = createAuthenticatedClient(
|
|
49
56
|
indexer.streamConfig,
|
|
50
57
|
indexer.options.streamUrl
|
|
51
58
|
);
|
|
@@ -53,8 +60,10 @@ function createVcr() {
|
|
|
53
60
|
} else {
|
|
54
61
|
await replay(vcrConfig, indexer, cassetteName);
|
|
55
62
|
}
|
|
63
|
+
return result;
|
|
56
64
|
}
|
|
57
65
|
};
|
|
58
66
|
}
|
|
59
67
|
|
|
60
68
|
export { createVcr };
|
|
69
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../src/testing/index.ts"],"sourcesContent":["import { createAuthenticatedClient } from \"@apibara/protocol\";\nimport ci from \"ci-info\";\nimport { type NestedHooks, mergeHooks } from \"hookable\";\nimport { useIndexerContext } from \"../context\";\nimport {\n type IndexerHooks,\n type IndexerWithStreamConfig,\n createIndexer,\n} from \"../indexer\";\nimport { type InternalContext, internalContext } from \"../plugins/context\";\nimport { logger } from \"../plugins/logger\";\nimport type { CassetteOptions, VcrConfig } from \"../vcr/config\";\nimport { isCassetteAvailable } from \"../vcr/helper\";\nimport { record } from \"../vcr/record\";\nimport { replay } from \"../vcr/replay\";\n\nexport type VcrResult = Record<string, unknown>;\n\nexport function createVcr() {\n let result: VcrResult;\n\n return {\n async run<TFilter, TBlock>(\n cassetteName: string,\n indexerConfig: IndexerWithStreamConfig<TFilter, TBlock>,\n config: {\n range: { fromBlock: bigint; toBlock: bigint };\n hooks?: NestedHooks<IndexerHooks<TFilter, TBlock>>;\n },\n ) {\n const vcrConfig: VcrConfig = {\n cassetteDir: \"cassettes\",\n };\n\n indexerConfig.hooks = mergeHooks(\n indexerConfig.hooks ?? {},\n config.hooks ?? {},\n );\n\n const cassetteOptions: CassetteOptions = {\n name: cassetteName,\n startingCursor: {\n orderKey: config.range.fromBlock,\n },\n endingCursor: {\n orderKey: config.range.toBlock,\n },\n };\n\n indexerConfig.plugins = [\n internalContext({\n indexerName: cassetteName,\n availableIndexers: [cassetteName],\n } as InternalContext),\n logger(),\n ...(indexerConfig.plugins ?? []),\n ];\n\n const indexer = createIndexer(indexerConfig);\n\n indexer.hooks.hook(\"run:after\", () => {\n result = useIndexerContext();\n });\n\n if (!isCassetteAvailable(vcrConfig, cassetteName)) {\n if (ci.isCI) {\n throw new Error(\"Cannot record cassette in CI\");\n }\n\n const client = createAuthenticatedClient(\n indexer.streamConfig,\n indexer.options.streamUrl,\n );\n await record(vcrConfig, client, indexer, cassetteOptions);\n } else {\n await replay(vcrConfig, indexer, cassetteName);\n }\n\n return result;\n },\n };\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAkBO,SAAS,SAAY,GAAA;AAC1B,EAAI,IAAA,MAAA,CAAA;AAEJ,EAAO,OAAA;AAAA,IACL,MAAM,GAAA,CACJ,YACA,EAAA,aAAA,EACA,MAIA,EAAA;AACA,MAAA,MAAM,SAAuB,GAAA;AAAA,QAC3B,WAAa,EAAA,WAAA;AAAA,OACf,CAAA;AAEA,MAAA,aAAA,CAAc,KAAQ,GAAA,UAAA;AAAA,QACpB,aAAA,CAAc,SAAS,EAAC;AAAA,QACxB,MAAA,CAAO,SAAS,EAAC;AAAA,OACnB,CAAA;AAEA,MAAA,MAAM,eAAmC,GAAA;AAAA,QACvC,IAAM,EAAA,YAAA;AAAA,QACN,cAAgB,EAAA;AAAA,UACd,QAAA,EAAU,OAAO,KAAM,CAAA,SAAA;AAAA,SACzB;AAAA,QACA,YAAc,EAAA;AAAA,UACZ,QAAA,EAAU,OAAO,KAAM,CAAA,OAAA;AAAA,SACzB;AAAA,OACF,CAAA;AAEA,MAAA,aAAA,CAAc,OAAU,GAAA;AAAA,QACtB,eAAgB,CAAA;AAAA,UACd,WAAa,EAAA,YAAA;AAAA,UACb,iBAAA,EAAmB,CAAC,YAAY,CAAA;AAAA,SACd,CAAA;AAAA,QACpB,MAAO,EAAA;AAAA,QACP,GAAI,aAAc,CAAA,OAAA,IAAW,EAAC;AAAA,OAChC,CAAA;AAEA,MAAM,MAAA,OAAA,GAAU,cAAc,aAAa,CAAA,CAAA;AAE3C,MAAQ,OAAA,CAAA,KAAA,CAAM,IAAK,CAAA,WAAA,EAAa,MAAM;AACpC,QAAA,MAAA,GAAS,iBAAkB,EAAA,CAAA;AAAA,OAC5B,CAAA,CAAA;AAED,MAAA,IAAI,CAAC,mBAAA,CAAoB,SAAW,EAAA,YAAY,CAAG,EAAA;AACjD,QAAA,IAAI,GAAG,IAAM,EAAA;AACX,UAAM,MAAA,IAAI,MAAM,8BAA8B,CAAA,CAAA;AAAA,SAChD;AAEA,QAAA,MAAM,MAAS,GAAA,yBAAA;AAAA,UACb,OAAQ,CAAA,YAAA;AAAA,UACR,QAAQ,OAAQ,CAAA,SAAA;AAAA,SAClB,CAAA;AACA,QAAA,MAAM,MAAO,CAAA,SAAA,EAAW,MAAQ,EAAA,OAAA,EAAS,eAAe,CAAA,CAAA;AAAA,OACnD,MAAA;AACL,QAAM,MAAA,MAAA,CAAO,SAAW,EAAA,OAAA,EAAS,YAAY,CAAA,CAAA;AAAA,OAC/C;AAEA,MAAO,OAAA,MAAA,CAAA;AAAA,KACT;AAAA,GACF,CAAA;AACF;;;;"}
|
package/dist/vcr/index.cjs
CHANGED
|
@@ -9,10 +9,11 @@ const testing = require('@apibara/protocol/testing');
|
|
|
9
9
|
require('@apibara/protocol');
|
|
10
10
|
require('consola');
|
|
11
11
|
require('hookable');
|
|
12
|
-
require('../shared/indexer.
|
|
12
|
+
require('../shared/indexer.479ae593.cjs');
|
|
13
13
|
require('node:async_hooks');
|
|
14
14
|
require('unctx');
|
|
15
15
|
require('@opentelemetry/api');
|
|
16
|
+
require('../internal/plugins.cjs');
|
|
16
17
|
|
|
17
18
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
18
19
|
|
|
@@ -90,3 +91,4 @@ exports.loadCassette = loadCassette;
|
|
|
90
91
|
exports.record = record;
|
|
91
92
|
exports.replay = replay;
|
|
92
93
|
exports.serialize = serialize;
|
|
94
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/vcr/helper.ts","../../src/vcr/record.ts","../../src/vcr/replay.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { VcrConfig } from \"./config\";\n\nexport function deserialize(str: string) {\n return JSON.parse(str, (_, value) =>\n typeof value === \"string\" && value.match(/^\\d+n$/)\n ? BigInt(value.slice(0, -1))\n : value,\n );\n}\n\nexport function serialize(obj: Record<string, unknown>): string {\n return JSON.stringify(\n obj,\n (_, value) => (typeof value === \"bigint\" ? `${value.toString()}n` : value),\n \"\\t\",\n );\n}\n\nexport function isCassetteAvailable(\n vcrConfig: VcrConfig,\n cassetteName: string,\n): boolean {\n const filePath = path.join(vcrConfig.cassetteDir, `${cassetteName}.json`);\n return fs.existsSync(filePath);\n}\n","import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type { Client, StreamDataResponse } from \"@apibara/protocol\";\nimport { type Indexer, run } from \"../indexer\";\nimport type { CassetteOptions, VcrConfig } from \"./config\";\nimport { serialize } from \"./helper\";\n\nexport type CassetteDataType<TFilter, TBlock> = {\n filter: TFilter;\n messages: StreamDataResponse<TBlock>[];\n};\n\nexport async function record<TFilter, TBlock, TTxnParams>(\n vcrConfig: VcrConfig,\n client: Client<TFilter, TBlock>,\n indexer: Indexer<TFilter, TBlock>,\n cassetteOptions: CassetteOptions,\n) {\n const messages: StreamDataResponse<TBlock>[] = [];\n\n indexer.hooks.addHooks({\n \"connect:before\"({ options, request }) {\n request.startingCursor = cassetteOptions.startingCursor;\n options.endingCursor = cassetteOptions.endingCursor;\n },\n message({ message }) {\n messages.push(message);\n },\n async \"run:after\"() {\n const output: CassetteDataType<TFilter, TBlock> = {\n filter: indexer.options.filter,\n messages: messages,\n };\n\n await fs.mkdir(vcrConfig.cassetteDir, { recursive: true });\n\n const filePath = path.join(\n vcrConfig.cassetteDir,\n `${cassetteOptions.name}.json`,\n );\n\n await fs.writeFile(filePath, serialize(output), { flag: \"w\" });\n },\n });\n\n await run(client, indexer);\n}\n","import assert from \"node:assert\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { Client } from \"@apibara/protocol\";\nimport { MockClient } from \"@apibara/protocol/testing\";\nimport { type Indexer, run } from \"../indexer\";\nimport { type CassetteDataType, deserialize } from \"../vcr\";\nimport type { VcrConfig } from \"./config\";\n\nexport async function replay<TFilter, TBlock, TTxnParams>(\n vcrConfig: VcrConfig,\n indexer: Indexer<TFilter, TBlock>,\n cassetteName: string,\n) {\n const client = loadCassette<TFilter, TBlock>(vcrConfig, cassetteName);\n await run(client, indexer);\n}\n\nexport function loadCassette<TFilter, TBlock>(\n vcrConfig: VcrConfig,\n cassetteName: string,\n): Client<TFilter, TBlock> {\n const filePath = path.join(vcrConfig.cassetteDir, `${cassetteName}.json`);\n\n const data = fs.readFileSync(filePath, \"utf8\");\n const cassetteData: CassetteDataType<TFilter, TBlock> = deserialize(data);\n\n const { filter, messages } = cassetteData;\n\n return new MockClient<TFilter, TBlock>((request, options) => {\n // Notice that the request filter is an array of filters,\n // so we need to wrap the indexer filter in an array.\n assert.deepStrictEqual(\n request.filter,\n [filter],\n \"Indexer and cassette filter mismatch. Hint: delete the cassette and run again.\",\n );\n\n return messages;\n });\n}\n"],"names":["path","fs","run","MockClient","assert"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAIO,SAAS,YAAY,GAAa,EAAA;AACvC,EAAA,OAAO,IAAK,CAAA,KAAA;AAAA,IAAM,GAAA;AAAA,IAAK,CAAC,CAAG,EAAA,KAAA,KACzB,OAAO,KAAA,KAAU,YAAY,KAAM,CAAA,KAAA,CAAM,QAAQ,CAAA,GAC7C,OAAO,KAAM,CAAA,KAAA,CAAM,CAAG,EAAA,CAAA,CAAE,CAAC,CACzB,GAAA,KAAA;AAAA,GACN,CAAA;AACF,CAAA;AAEO,S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
CHANGED
|
@@ -7,10 +7,11 @@ import { MockClient } from '@apibara/protocol/testing';
|
|
|
7
7
|
import '@apibara/protocol';
|
|
8
8
|
import 'consola';
|
|
9
9
|
import 'hookable';
|
|
10
|
-
import '../shared/indexer.
|
|
10
|
+
import '../shared/indexer.75773ef1.mjs';
|
|
11
11
|
import 'node:async_hooks';
|
|
12
12
|
import 'unctx';
|
|
13
13
|
import '@opentelemetry/api';
|
|
14
|
+
import '../internal/plugins.mjs';
|
|
14
15
|
|
|
15
16
|
function deserialize(str) {
|
|
16
17
|
return JSON.parse(
|
|
@@ -76,3 +77,4 @@ function loadCassette(vcrConfig, cassetteName) {
|
|
|
76
77
|
}
|
|
77
78
|
|
|
78
79
|
export { deserialize, isCassetteAvailable, loadCassette, record, replay, serialize };
|
|
80
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../src/vcr/helper.ts","../../src/vcr/record.ts","../../src/vcr/replay.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { VcrConfig } from \"./config\";\n\nexport function deserialize(str: string) {\n return JSON.parse(str, (_, value) =>\n typeof value === \"string\" && value.match(/^\\d+n$/)\n ? BigInt(value.slice(0, -1))\n : value,\n );\n}\n\nexport function serialize(obj: Record<string, unknown>): string {\n return JSON.stringify(\n obj,\n (_, value) => (typeof value === \"bigint\" ? `${value.toString()}n` : value),\n \"\\t\",\n );\n}\n\nexport function isCassetteAvailable(\n vcrConfig: VcrConfig,\n cassetteName: string,\n): boolean {\n const filePath = path.join(vcrConfig.cassetteDir, `${cassetteName}.json`);\n return fs.existsSync(filePath);\n}\n","import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type { Client, StreamDataResponse } from \"@apibara/protocol\";\nimport { type Indexer, run } from \"../indexer\";\nimport type { CassetteOptions, VcrConfig } from \"./config\";\nimport { serialize } from \"./helper\";\n\nexport type CassetteDataType<TFilter, TBlock> = {\n filter: TFilter;\n messages: StreamDataResponse<TBlock>[];\n};\n\nexport async function record<TFilter, TBlock, TTxnParams>(\n vcrConfig: VcrConfig,\n client: Client<TFilter, TBlock>,\n indexer: Indexer<TFilter, TBlock>,\n cassetteOptions: CassetteOptions,\n) {\n const messages: StreamDataResponse<TBlock>[] = [];\n\n indexer.hooks.addHooks({\n \"connect:before\"({ options, request }) {\n request.startingCursor = cassetteOptions.startingCursor;\n options.endingCursor = cassetteOptions.endingCursor;\n },\n message({ message }) {\n messages.push(message);\n },\n async \"run:after\"() {\n const output: CassetteDataType<TFilter, TBlock> = {\n filter: indexer.options.filter,\n messages: messages,\n };\n\n await fs.mkdir(vcrConfig.cassetteDir, { recursive: true });\n\n const filePath = path.join(\n vcrConfig.cassetteDir,\n `${cassetteOptions.name}.json`,\n );\n\n await fs.writeFile(filePath, serialize(output), { flag: \"w\" });\n },\n });\n\n await run(client, indexer);\n}\n","import assert from \"node:assert\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { Client } from \"@apibara/protocol\";\nimport { MockClient } from \"@apibara/protocol/testing\";\nimport { type Indexer, run } from \"../indexer\";\nimport { type CassetteDataType, deserialize } from \"../vcr\";\nimport type { VcrConfig } from \"./config\";\n\nexport async function replay<TFilter, TBlock, TTxnParams>(\n vcrConfig: VcrConfig,\n indexer: Indexer<TFilter, TBlock>,\n cassetteName: string,\n) {\n const client = loadCassette<TFilter, TBlock>(vcrConfig, cassetteName);\n await run(client, indexer);\n}\n\nexport function loadCassette<TFilter, TBlock>(\n vcrConfig: VcrConfig,\n cassetteName: string,\n): Client<TFilter, TBlock> {\n const filePath = path.join(vcrConfig.cassetteDir, `${cassetteName}.json`);\n\n const data = fs.readFileSync(filePath, \"utf8\");\n const cassetteData: CassetteDataType<TFilter, TBlock> = deserialize(data);\n\n const { filter, messages } = cassetteData;\n\n return new MockClient<TFilter, TBlock>((request, options) => {\n // Notice that the request filter is an array of filters,\n // so we need to wrap the indexer filter in an array.\n assert.deepStrictEqual(\n request.filter,\n [filter],\n \"Indexer and cassette filter mismatch. Hint: delete the cassette and run again.\",\n );\n\n return messages;\n });\n}\n"],"names":["fs"],"mappings":";;;;;;;;;;;;;;;AAIO,SAAS,YAAY,GAAa,EAAA;AACvC,EAAA,OAAO,IAAK,CAAA,KAAA;AAAA,IAAM,GAAA;AAAA,IAAK,CAAC,CAAG,EAAA,KAAA,KACzB,OAAO,KAAA,KAAU,YAAY,KAAM,CAAA,KAAA,CAAM,QAAQ,CAAA,GAC7C,OAAO,KAAM,CAAA,KAAA,CAAM,CAAG,EAAA,CAAA,CAAE,CAAC,CACzB,GAAA,KAAA;AAAA,GACN,CAAA;AACF,CAAA;AAEO,SAAS,UAAU,GAAsC,EAAA;AAC9D,EAAA,OAAO,IAAK,CAAA,SAAA;AAAA,IACV,GAAA;AAAA,IACA,CAAC,CAAG,EAAA,KAAA,KAAW,OAAO,KAAA,KAAU,WAAW,CAAG,EAAA,KAAA,CAAM,QAAS,EAAC,CAAM,CAAA,CAAA,GAAA,KAAA;AAAA,IACpE,GAAA;AAAA,GACF,CAAA;AACF,CAAA;AAEgB,SAAA,mBAAA,CACd,WACA,YACS,EAAA;AACT,EAAA,MAAM,WAAW,IAAK,CAAA,IAAA,CAAK,UAAU,WAAa,EAAA,CAAA,EAAG,YAAY,CAAO,KAAA,CAAA,CAAA,CAAA;AACxE,EAAO,OAAA,EAAA,CAAG,WAAW,QAAQ,CAAA,CAAA;AAC/B;;ACdA,eAAsB,MACpB,CAAA,SAAA,EACA,MACA,EAAA,OAAA,EACA,eACA,EAAA;AACA,EAAA,MAAM,WAAyC,EAAC,CAAA;AAEhD,EAAA,OAAA,CAAQ,MAAM,QAAS,CAAA;AAAA,IACrB,gBAAiB,CAAA,EAAE,OAAS,EAAA,OAAA,EAAW,EAAA;AACrC,MAAA,OAAA,CAAQ,iBAAiB,eAAgB,CAAA,cAAA,CAAA;AACzC,MAAA,OAAA,CAAQ,eAAe,eAAgB,CAAA,YAAA,CAAA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M,MAAA,EAAE,MAAQ,EAAA,QAAA,EAAa,GAAA,YAAA,CAAA;AAE7B,EAAA,OAAO,IAAI,UAAA,CAA4B,CAAC,OAAA,EAAS,OAAY,KAAA;AAG3D,IAAO,MAAA,CAAA,eAAA;AAAA,MACL,OAAQ,CAAA,MAAA;AAAA,MACR,CAAC,MAAM,CAAA;AAAA,MACP,gFAAA;AAAA,KACF,CAAA;AAEA,IAAO,OAAA,QAAA,CAAA;AAAA,GACR,CAAA,CAAA;AACH;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apibara/indexer",
|
|
3
|
-
"version": "2.1.0-beta.
|
|
3
|
+
"version": "2.1.0-beta.51",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -70,10 +70,10 @@
|
|
|
70
70
|
"vitest": "^1.6.0"
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"@apibara/protocol": "2.1.0-beta.
|
|
73
|
+
"@apibara/protocol": "2.1.0-beta.51",
|
|
74
74
|
"@opentelemetry/api": "^1.9.0",
|
|
75
75
|
"ci-info": "^4.1.0",
|
|
76
|
-
"consola": "^3.2
|
|
76
|
+
"consola": "^3.4.2",
|
|
77
77
|
"hookable": "^5.5.3",
|
|
78
78
|
"klona": "^2.0.6",
|
|
79
79
|
"nice-grpc": "^2.1.8",
|
package/src/index.ts
CHANGED