@apibara/indexer 2.0.0-beta.5 → 2.0.0-beta.6
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 +52 -0
- package/dist/index.d.cts +47 -0
- package/dist/index.d.mts +47 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.mjs +36 -0
- package/dist/shared/indexer.26fbe988.d.ts +100 -0
- package/dist/shared/indexer.28bd9576.mjs +279 -0
- package/dist/shared/indexer.93d6b2eb.mjs +17 -0
- package/dist/shared/indexer.99ec3128.cjs +300 -0
- package/dist/shared/indexer.9aa22867.d.mts +100 -0
- package/dist/shared/indexer.a8b7ab1f.cjs +25 -0
- package/dist/shared/indexer.d227f25c.d.cts +19 -0
- package/dist/shared/indexer.d227f25c.d.mts +19 -0
- package/dist/shared/indexer.d227f25c.d.ts +19 -0
- package/dist/shared/indexer.ff960804.d.cts +100 -0
- package/dist/sinks/csv.cjs +85 -0
- package/dist/sinks/csv.d.cts +66 -0
- package/dist/sinks/csv.d.mts +66 -0
- package/dist/sinks/csv.d.ts +66 -0
- package/dist/sinks/csv.mjs +78 -0
- package/dist/sinks/sqlite.cjs +90 -0
- package/dist/sinks/sqlite.d.cts +71 -0
- package/dist/sinks/sqlite.d.mts +71 -0
- package/dist/sinks/sqlite.d.ts +71 -0
- package/dist/sinks/sqlite.mjs +87 -0
- package/dist/testing/index.cjs +63 -0
- package/dist/testing/index.d.cts +39 -0
- package/dist/testing/index.d.mts +39 -0
- package/dist/testing/index.d.ts +39 -0
- package/dist/testing/index.mjs +59 -0
- package/package.json +2 -2
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const vitest = require('vitest');
|
|
4
|
+
const replay = require('../shared/indexer.99ec3128.cjs');
|
|
5
|
+
require('node:fs/promises');
|
|
6
|
+
require('node:path');
|
|
7
|
+
require('consola');
|
|
8
|
+
require('klona/full');
|
|
9
|
+
require('node:assert');
|
|
10
|
+
require('node:fs');
|
|
11
|
+
require('@apibara/protocol/testing');
|
|
12
|
+
require('hookable');
|
|
13
|
+
require('node:async_hooks');
|
|
14
|
+
require('unctx');
|
|
15
|
+
require('@opentelemetry/api');
|
|
16
|
+
require('../shared/indexer.a8b7ab1f.cjs');
|
|
17
|
+
|
|
18
|
+
const test = vitest.test.extend({
|
|
19
|
+
vcr: {
|
|
20
|
+
withClient
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
async function withClient(cassetteName, range, callback) {
|
|
24
|
+
const vcrConfig = {
|
|
25
|
+
cassetteDir: "cassettes"
|
|
26
|
+
};
|
|
27
|
+
const cassetteOptions = {
|
|
28
|
+
name: cassetteName,
|
|
29
|
+
startingCursor: {
|
|
30
|
+
orderKey: range.fromBlock
|
|
31
|
+
},
|
|
32
|
+
endingCursor: {
|
|
33
|
+
orderKey: range.toBlock
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
const context = {
|
|
37
|
+
async run(indexer) {
|
|
38
|
+
const client = replay.loadCassette(vcrConfig, cassetteName);
|
|
39
|
+
if (!replay.isCassetteAvailable(vcrConfig, cassetteName)) {
|
|
40
|
+
await replay.record(vcrConfig, client, indexer, cassetteOptions);
|
|
41
|
+
}
|
|
42
|
+
return await replay.replay(vcrConfig, indexer, cassetteName);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
await callback(context);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function generateMockMessages(count = 10) {
|
|
49
|
+
return [...Array(count)].map((_, i) => ({
|
|
50
|
+
_tag: "data",
|
|
51
|
+
data: {
|
|
52
|
+
cursor: { orderKey: BigInt(5e6 - 1) },
|
|
53
|
+
finality: "accepted",
|
|
54
|
+
data: [{ data: `${5e6 + i}` }],
|
|
55
|
+
endCursor: { orderKey: BigInt(5e6 + i) }
|
|
56
|
+
}
|
|
57
|
+
}));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
exports.VcrSink = replay.VcrSink;
|
|
61
|
+
exports.vcr = replay.vcr;
|
|
62
|
+
exports.generateMockMessages = generateMockMessages;
|
|
63
|
+
exports.test = test;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as vitest from 'vitest';
|
|
2
|
+
import { I as Indexer, j as VcrReplayResult } from '../shared/indexer.ff960804.cjs';
|
|
3
|
+
import { Cursor } from '@apibara/protocol';
|
|
4
|
+
import { b as Sink, S as SinkData, a as SinkCursorParams } from '../shared/indexer.d227f25c.cjs';
|
|
5
|
+
import { MockStreamResponse } from '@apibara/protocol/testing';
|
|
6
|
+
import 'hookable';
|
|
7
|
+
|
|
8
|
+
declare const test: vitest.TestAPI<{
|
|
9
|
+
vcr: {
|
|
10
|
+
withClient: typeof withClient;
|
|
11
|
+
};
|
|
12
|
+
}>;
|
|
13
|
+
type WithClientContext<TFilter, TBlock, TTxnParams> = {
|
|
14
|
+
run: (indexerArgs: Indexer<TFilter, TBlock, TTxnParams>) => Promise<VcrReplayResult>;
|
|
15
|
+
};
|
|
16
|
+
declare function withClient<TFilter, TBlock, TTxnParams>(cassetteName: string, range: {
|
|
17
|
+
fromBlock: bigint;
|
|
18
|
+
toBlock: bigint;
|
|
19
|
+
}, callback: (context: WithClientContext<TFilter, TBlock, TTxnParams>) => Promise<void>): Promise<void>;
|
|
20
|
+
|
|
21
|
+
type TxnParams = {
|
|
22
|
+
writer: {
|
|
23
|
+
insert: (data: SinkData[]) => void;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
declare class VcrSink extends Sink {
|
|
27
|
+
result: VcrReplayResult["outputs"];
|
|
28
|
+
write({ data, endCursor }: {
|
|
29
|
+
data: SinkData[];
|
|
30
|
+
endCursor?: Cursor;
|
|
31
|
+
}): void;
|
|
32
|
+
transaction({ cursor, endCursor, finality }: SinkCursorParams, cb: (params: TxnParams) => Promise<void>): Promise<void>;
|
|
33
|
+
invalidate(cursor?: Cursor): Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
declare function vcr(): VcrSink;
|
|
36
|
+
|
|
37
|
+
declare function generateMockMessages(count?: number): MockStreamResponse[];
|
|
38
|
+
|
|
39
|
+
export { VcrSink, generateMockMessages, test, vcr };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as vitest from 'vitest';
|
|
2
|
+
import { I as Indexer, j as VcrReplayResult } from '../shared/indexer.9aa22867.mjs';
|
|
3
|
+
import { Cursor } from '@apibara/protocol';
|
|
4
|
+
import { b as Sink, S as SinkData, a as SinkCursorParams } from '../shared/indexer.d227f25c.mjs';
|
|
5
|
+
import { MockStreamResponse } from '@apibara/protocol/testing';
|
|
6
|
+
import 'hookable';
|
|
7
|
+
|
|
8
|
+
declare const test: vitest.TestAPI<{
|
|
9
|
+
vcr: {
|
|
10
|
+
withClient: typeof withClient;
|
|
11
|
+
};
|
|
12
|
+
}>;
|
|
13
|
+
type WithClientContext<TFilter, TBlock, TTxnParams> = {
|
|
14
|
+
run: (indexerArgs: Indexer<TFilter, TBlock, TTxnParams>) => Promise<VcrReplayResult>;
|
|
15
|
+
};
|
|
16
|
+
declare function withClient<TFilter, TBlock, TTxnParams>(cassetteName: string, range: {
|
|
17
|
+
fromBlock: bigint;
|
|
18
|
+
toBlock: bigint;
|
|
19
|
+
}, callback: (context: WithClientContext<TFilter, TBlock, TTxnParams>) => Promise<void>): Promise<void>;
|
|
20
|
+
|
|
21
|
+
type TxnParams = {
|
|
22
|
+
writer: {
|
|
23
|
+
insert: (data: SinkData[]) => void;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
declare class VcrSink extends Sink {
|
|
27
|
+
result: VcrReplayResult["outputs"];
|
|
28
|
+
write({ data, endCursor }: {
|
|
29
|
+
data: SinkData[];
|
|
30
|
+
endCursor?: Cursor;
|
|
31
|
+
}): void;
|
|
32
|
+
transaction({ cursor, endCursor, finality }: SinkCursorParams, cb: (params: TxnParams) => Promise<void>): Promise<void>;
|
|
33
|
+
invalidate(cursor?: Cursor): Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
declare function vcr(): VcrSink;
|
|
36
|
+
|
|
37
|
+
declare function generateMockMessages(count?: number): MockStreamResponse[];
|
|
38
|
+
|
|
39
|
+
export { VcrSink, generateMockMessages, test, vcr };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as vitest from 'vitest';
|
|
2
|
+
import { I as Indexer, j as VcrReplayResult } from '../shared/indexer.26fbe988.js';
|
|
3
|
+
import { Cursor } from '@apibara/protocol';
|
|
4
|
+
import { b as Sink, S as SinkData, a as SinkCursorParams } from '../shared/indexer.d227f25c.js';
|
|
5
|
+
import { MockStreamResponse } from '@apibara/protocol/testing';
|
|
6
|
+
import 'hookable';
|
|
7
|
+
|
|
8
|
+
declare const test: vitest.TestAPI<{
|
|
9
|
+
vcr: {
|
|
10
|
+
withClient: typeof withClient;
|
|
11
|
+
};
|
|
12
|
+
}>;
|
|
13
|
+
type WithClientContext<TFilter, TBlock, TTxnParams> = {
|
|
14
|
+
run: (indexerArgs: Indexer<TFilter, TBlock, TTxnParams>) => Promise<VcrReplayResult>;
|
|
15
|
+
};
|
|
16
|
+
declare function withClient<TFilter, TBlock, TTxnParams>(cassetteName: string, range: {
|
|
17
|
+
fromBlock: bigint;
|
|
18
|
+
toBlock: bigint;
|
|
19
|
+
}, callback: (context: WithClientContext<TFilter, TBlock, TTxnParams>) => Promise<void>): Promise<void>;
|
|
20
|
+
|
|
21
|
+
type TxnParams = {
|
|
22
|
+
writer: {
|
|
23
|
+
insert: (data: SinkData[]) => void;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
declare class VcrSink extends Sink {
|
|
27
|
+
result: VcrReplayResult["outputs"];
|
|
28
|
+
write({ data, endCursor }: {
|
|
29
|
+
data: SinkData[];
|
|
30
|
+
endCursor?: Cursor;
|
|
31
|
+
}): void;
|
|
32
|
+
transaction({ cursor, endCursor, finality }: SinkCursorParams, cb: (params: TxnParams) => Promise<void>): Promise<void>;
|
|
33
|
+
invalidate(cursor?: Cursor): Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
declare function vcr(): VcrSink;
|
|
36
|
+
|
|
37
|
+
declare function generateMockMessages(count?: number): MockStreamResponse[];
|
|
38
|
+
|
|
39
|
+
export { VcrSink, generateMockMessages, test, vcr };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { test as test$1 } from 'vitest';
|
|
2
|
+
import { l as loadCassette, i as isCassetteAvailable, b as record, e as replay } from '../shared/indexer.28bd9576.mjs';
|
|
3
|
+
export { V as VcrSink, v as vcr } from '../shared/indexer.28bd9576.mjs';
|
|
4
|
+
import 'node:fs/promises';
|
|
5
|
+
import 'node:path';
|
|
6
|
+
import 'consola';
|
|
7
|
+
import 'klona/full';
|
|
8
|
+
import 'node:assert';
|
|
9
|
+
import 'node:fs';
|
|
10
|
+
import '@apibara/protocol/testing';
|
|
11
|
+
import 'hookable';
|
|
12
|
+
import 'node:async_hooks';
|
|
13
|
+
import 'unctx';
|
|
14
|
+
import '@opentelemetry/api';
|
|
15
|
+
import '../shared/indexer.93d6b2eb.mjs';
|
|
16
|
+
|
|
17
|
+
const test = test$1.extend({
|
|
18
|
+
vcr: {
|
|
19
|
+
withClient
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
async function withClient(cassetteName, range, callback) {
|
|
23
|
+
const vcrConfig = {
|
|
24
|
+
cassetteDir: "cassettes"
|
|
25
|
+
};
|
|
26
|
+
const cassetteOptions = {
|
|
27
|
+
name: cassetteName,
|
|
28
|
+
startingCursor: {
|
|
29
|
+
orderKey: range.fromBlock
|
|
30
|
+
},
|
|
31
|
+
endingCursor: {
|
|
32
|
+
orderKey: range.toBlock
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const context = {
|
|
36
|
+
async run(indexer) {
|
|
37
|
+
const client = loadCassette(vcrConfig, cassetteName);
|
|
38
|
+
if (!isCassetteAvailable(vcrConfig, cassetteName)) {
|
|
39
|
+
await record(vcrConfig, client, indexer, cassetteOptions);
|
|
40
|
+
}
|
|
41
|
+
return await replay(vcrConfig, indexer, cassetteName);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
await callback(context);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function generateMockMessages(count = 10) {
|
|
48
|
+
return [...Array(count)].map((_, i) => ({
|
|
49
|
+
_tag: "data",
|
|
50
|
+
data: {
|
|
51
|
+
cursor: { orderKey: BigInt(5e6 - 1) },
|
|
52
|
+
finality: "accepted",
|
|
53
|
+
data: [{ data: `${5e6 + i}` }],
|
|
54
|
+
endCursor: { orderKey: BigInt(5e6 + i) }
|
|
55
|
+
}
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export { generateMockMessages, test };
|
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.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"source": "./src/index.ts",
|
|
6
6
|
"main": "./dist/index.mjs",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"vitest": "^1.6.0"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@apibara/protocol": "2.0.0-beta.
|
|
62
|
+
"@apibara/protocol": "2.0.0-beta.6",
|
|
63
63
|
"@opentelemetry/api": "^1.9.0",
|
|
64
64
|
"consola": "^3.2.3",
|
|
65
65
|
"hookable": "^5.5.3",
|