@apibara/indexer 2.0.0-beta.6 → 2.0.0-beta.7

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 (56) hide show
  1. package/dist/index.cjs +17 -19
  2. package/dist/index.d.cts +9 -38
  3. package/dist/index.d.mts +9 -38
  4. package/dist/index.d.ts +9 -38
  5. package/dist/index.mjs +7 -9
  6. package/dist/plugins/index.cjs +7 -0
  7. package/dist/plugins/index.d.cts +4 -0
  8. package/dist/plugins/index.d.mts +4 -0
  9. package/dist/plugins/index.d.ts +4 -0
  10. package/dist/plugins/index.mjs +5 -0
  11. package/dist/plugins/kv.cjs +131 -0
  12. package/dist/plugins/kv.d.cts +32 -0
  13. package/dist/plugins/kv.d.mts +32 -0
  14. package/dist/plugins/kv.d.ts +32 -0
  15. package/dist/plugins/kv.mjs +124 -0
  16. package/dist/plugins/persistence.cjs +182 -0
  17. package/dist/plugins/persistence.d.cts +50 -0
  18. package/dist/plugins/persistence.d.mts +50 -0
  19. package/dist/plugins/persistence.d.ts +50 -0
  20. package/dist/plugins/persistence.mjs +179 -0
  21. package/dist/shared/indexer.2c23c9cd.mjs +35 -0
  22. package/dist/shared/indexer.318d3617.cjs +47 -0
  23. package/dist/shared/{indexer.28bd9576.mjs → indexer.36530330.mjs} +9 -39
  24. package/dist/shared/indexer.500fd281.d.cts +23 -0
  25. package/dist/shared/{indexer.99ec3128.cjs → indexer.541d43eb.cjs} +16 -50
  26. package/dist/shared/{indexer.d227f25c.d.cts → indexer.b9c8f0d8.d.cts} +1 -1
  27. package/dist/shared/{indexer.d227f25c.d.mts → indexer.b9c8f0d8.d.mts} +1 -1
  28. package/dist/shared/{indexer.d227f25c.d.ts → indexer.b9c8f0d8.d.ts} +1 -1
  29. package/dist/shared/{indexer.26fbe988.d.ts → indexer.c7ed6b83.d.cts} +2 -20
  30. package/dist/shared/indexer.e1856641.d.mts +23 -0
  31. package/dist/shared/indexer.e4f2430f.d.ts +23 -0
  32. package/dist/shared/{indexer.ff960804.d.cts → indexer.e8bd138d.d.mts} +2 -20
  33. package/dist/shared/{indexer.9aa22867.d.mts → indexer.f761abcd.d.ts} +2 -20
  34. package/dist/sinks/csv.d.cts +1 -1
  35. package/dist/sinks/csv.d.mts +1 -1
  36. package/dist/sinks/csv.d.ts +1 -1
  37. package/dist/sinks/drizzle/index.cjs +210 -0
  38. package/dist/sinks/drizzle/index.d.cts +111 -0
  39. package/dist/sinks/drizzle/index.d.mts +111 -0
  40. package/dist/sinks/drizzle/index.d.ts +111 -0
  41. package/dist/sinks/drizzle/index.mjs +196 -0
  42. package/dist/sinks/sqlite.d.cts +1 -1
  43. package/dist/sinks/sqlite.d.mts +1 -1
  44. package/dist/sinks/sqlite.d.ts +1 -1
  45. package/dist/testing/index.cjs +16 -15
  46. package/dist/testing/index.d.cts +3 -2
  47. package/dist/testing/index.d.mts +3 -2
  48. package/dist/testing/index.d.ts +3 -2
  49. package/dist/testing/index.mjs +11 -10
  50. package/dist/vcr/index.cjs +25 -0
  51. package/dist/vcr/index.d.cts +18 -0
  52. package/dist/vcr/index.d.mts +18 -0
  53. package/dist/vcr/index.d.ts +18 -0
  54. package/dist/vcr/index.mjs +14 -0
  55. package/package.json +33 -11
  56. package/src/vcr/record.ts +1 -1
@@ -0,0 +1,182 @@
1
+ 'use strict';
2
+
3
+ const helper = require('../shared/indexer.318d3617.cjs');
4
+ require('node:fs/promises');
5
+ require('node:path');
6
+ require('klona/full');
7
+ require('consola');
8
+ require('hookable');
9
+ require('node:assert');
10
+ require('node:fs');
11
+ require('@apibara/protocol/testing');
12
+ const plugins_index = require('./index.cjs');
13
+ require('node:async_hooks');
14
+ require('unctx');
15
+ require('@opentelemetry/api');
16
+
17
+ var __defProp = Object.defineProperty;
18
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
19
+ var __publicField = (obj, key, value) => {
20
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
21
+ return value;
22
+ };
23
+ function sqlitePersistence({
24
+ database
25
+ }) {
26
+ return plugins_index.defineIndexerPlugin((indexer) => {
27
+ let store;
28
+ indexer.hooks.hook("run:before", () => {
29
+ SqlitePersistence.initialize(database);
30
+ store = new SqlitePersistence(database);
31
+ });
32
+ indexer.hooks.hook("connect:before", ({ request }) => {
33
+ const { cursor, filter } = store.get();
34
+ if (cursor) {
35
+ request.startingCursor = cursor;
36
+ }
37
+ if (filter) {
38
+ request.filter[1] = filter;
39
+ }
40
+ });
41
+ indexer.hooks.hook("transaction:commit", ({ endCursor }) => {
42
+ if (endCursor) {
43
+ store.put({ cursor: endCursor });
44
+ }
45
+ });
46
+ indexer.hooks.hook("connect:factory", ({ request, endCursor }) => {
47
+ if (request.filter[1]) {
48
+ store.put({ cursor: endCursor, filter: request.filter[1] });
49
+ }
50
+ });
51
+ });
52
+ }
53
+ class SqlitePersistence {
54
+ constructor(_db) {
55
+ this._db = _db;
56
+ /** Sqlite Queries Prepare Statements */
57
+ __publicField(this, "_getCheckpointQuery");
58
+ __publicField(this, "_putCheckpointQuery");
59
+ __publicField(this, "_delCheckpointQuery");
60
+ __publicField(this, "_getFilterQuery");
61
+ __publicField(this, "_updateFilterToBlockQuery");
62
+ __publicField(this, "_insertFilterQuery");
63
+ __publicField(this, "_delFilterQuery");
64
+ this._getCheckpointQuery = this._db.prepare(statements.getCheckpoint);
65
+ this._putCheckpointQuery = this._db.prepare(statements.putCheckpoint);
66
+ this._delCheckpointQuery = this._db.prepare(statements.delCheckpoint);
67
+ this._getFilterQuery = this._db.prepare(statements.getFilter);
68
+ this._updateFilterToBlockQuery = this._db.prepare(
69
+ statements.updateFilterToBlock
70
+ );
71
+ this._insertFilterQuery = this._db.prepare(statements.insertFilter);
72
+ this._delFilterQuery = this._db.prepare(statements.delFilter);
73
+ }
74
+ static initialize(db) {
75
+ db.prepare(statements.createCheckpointsTable).run();
76
+ db.prepare(statements.createFiltersTable).run();
77
+ }
78
+ get() {
79
+ const cursor = this._getCheckpoint();
80
+ const filter = this._getFilter();
81
+ return { cursor, filter };
82
+ }
83
+ put({ cursor, filter }) {
84
+ if (cursor) {
85
+ this._putCheckpoint(cursor);
86
+ if (filter) {
87
+ this._putFilter(filter, cursor);
88
+ }
89
+ }
90
+ }
91
+ del() {
92
+ this._delCheckpoint();
93
+ this._delFilter();
94
+ }
95
+ // --- CHECKPOINTS TABLE METHODS ---
96
+ _getCheckpoint() {
97
+ const row = this._getCheckpointQuery.get("default");
98
+ if (!row)
99
+ return void 0;
100
+ return { orderKey: BigInt(row.order_key), uniqueKey: row.unique_key };
101
+ }
102
+ _putCheckpoint(cursor) {
103
+ this._putCheckpointQuery.run(
104
+ "default",
105
+ Number(cursor.orderKey),
106
+ cursor.uniqueKey
107
+ );
108
+ }
109
+ _delCheckpoint() {
110
+ this._delCheckpointQuery.run("default");
111
+ }
112
+ // --- FILTERS TABLE METHODS ---
113
+ _getFilter() {
114
+ const row = this._getFilterQuery.get("default");
115
+ if (!row)
116
+ return void 0;
117
+ return helper.deserialize(row.filter);
118
+ }
119
+ _putFilter(filter, endCursor) {
120
+ this._updateFilterToBlockQuery.run(Number(endCursor.orderKey), "default");
121
+ this._insertFilterQuery.run(
122
+ "default",
123
+ helper.serialize(filter),
124
+ Number(endCursor.orderKey)
125
+ );
126
+ }
127
+ _delFilter() {
128
+ this._delFilterQuery.run("default");
129
+ }
130
+ }
131
+ const statements = {
132
+ beginTxn: "BEGIN TRANSACTION",
133
+ commitTxn: "COMMIT TRANSACTION",
134
+ rollbackTxn: "ROLLBACK TRANSACTION",
135
+ createCheckpointsTable: `
136
+ CREATE TABLE IF NOT EXISTS checkpoints (
137
+ id TEXT NOT NULL PRIMARY KEY,
138
+ order_key INTEGER NOT NULL,
139
+ unique_key TEXT
140
+ );`,
141
+ createFiltersTable: `
142
+ CREATE TABLE IF NOT EXISTS filters (
143
+ id TEXT NOT NULL,
144
+ filter BLOB NOT NULL,
145
+ from_block INTEGER NOT NULL,
146
+ to_block INTEGER,
147
+ PRIMARY KEY (id, from_block)
148
+ );`,
149
+ getCheckpoint: `
150
+ SELECT *
151
+ FROM checkpoints
152
+ WHERE id = ?`,
153
+ putCheckpoint: `
154
+ INSERT INTO checkpoints (id, order_key, unique_key)
155
+ VALUES (?, ?, ?)
156
+ ON CONFLICT(id) DO UPDATE SET
157
+ order_key = excluded.order_key,
158
+ unique_key = excluded.unique_key`,
159
+ delCheckpoint: `
160
+ DELETE FROM checkpoints
161
+ WHERE id = ?`,
162
+ getFilter: `
163
+ SELECT *
164
+ FROM filters
165
+ WHERE id = ? AND to_block IS NULL`,
166
+ updateFilterToBlock: `
167
+ UPDATE filters
168
+ SET to_block = ?
169
+ WHERE id = ? AND to_block IS NULL`,
170
+ insertFilter: `
171
+ INSERT INTO filters (id, filter, from_block)
172
+ VALUES (?, ?, ?)
173
+ ON CONFLICT(id, from_block) DO UPDATE SET
174
+ filter = excluded.filter,
175
+ from_block = excluded.from_block`,
176
+ delFilter: `
177
+ DELETE FROM filters
178
+ WHERE id = ?`
179
+ };
180
+
181
+ exports.SqlitePersistence = SqlitePersistence;
182
+ exports.sqlitePersistence = sqlitePersistence;
@@ -0,0 +1,50 @@
1
+ import { I as IndexerPlugin } from '../shared/indexer.c7ed6b83.cjs';
2
+ import { Cursor } from '@apibara/protocol';
3
+ import { Database } from 'better-sqlite3';
4
+ import 'hookable';
5
+ import '../shared/indexer.b9c8f0d8.cjs';
6
+
7
+ declare function sqlitePersistence<TFilter, TBlock, TTxnParams>({ database, }: {
8
+ database: Database;
9
+ }): IndexerPlugin<TFilter, TBlock, TTxnParams>;
10
+ declare class SqlitePersistence<TFilter> {
11
+ private _db;
12
+ /** Sqlite Queries Prepare Statements */
13
+ private _getCheckpointQuery;
14
+ private _putCheckpointQuery;
15
+ private _delCheckpointQuery;
16
+ private _getFilterQuery;
17
+ private _updateFilterToBlockQuery;
18
+ private _insertFilterQuery;
19
+ private _delFilterQuery;
20
+ constructor(_db: Database);
21
+ static initialize(db: Database): void;
22
+ get(): {
23
+ cursor?: Cursor;
24
+ filter?: TFilter;
25
+ };
26
+ put({ cursor, filter }: {
27
+ cursor?: Cursor;
28
+ filter?: TFilter;
29
+ }): void;
30
+ del(): void;
31
+ private _getCheckpoint;
32
+ private _putCheckpoint;
33
+ private _delCheckpoint;
34
+ private _getFilter;
35
+ private _putFilter;
36
+ private _delFilter;
37
+ }
38
+ type CheckpointRow = {
39
+ id: string;
40
+ order_key: number;
41
+ unique_key?: `0x${string}`;
42
+ };
43
+ type FilterRow = {
44
+ id: string;
45
+ filter: string;
46
+ from_block: number;
47
+ to_block?: number;
48
+ };
49
+
50
+ export { type CheckpointRow, type FilterRow, SqlitePersistence, sqlitePersistence };
@@ -0,0 +1,50 @@
1
+ import { I as IndexerPlugin } from '../shared/indexer.e8bd138d.mjs';
2
+ import { Cursor } from '@apibara/protocol';
3
+ import { Database } from 'better-sqlite3';
4
+ import 'hookable';
5
+ import '../shared/indexer.b9c8f0d8.mjs';
6
+
7
+ declare function sqlitePersistence<TFilter, TBlock, TTxnParams>({ database, }: {
8
+ database: Database;
9
+ }): IndexerPlugin<TFilter, TBlock, TTxnParams>;
10
+ declare class SqlitePersistence<TFilter> {
11
+ private _db;
12
+ /** Sqlite Queries Prepare Statements */
13
+ private _getCheckpointQuery;
14
+ private _putCheckpointQuery;
15
+ private _delCheckpointQuery;
16
+ private _getFilterQuery;
17
+ private _updateFilterToBlockQuery;
18
+ private _insertFilterQuery;
19
+ private _delFilterQuery;
20
+ constructor(_db: Database);
21
+ static initialize(db: Database): void;
22
+ get(): {
23
+ cursor?: Cursor;
24
+ filter?: TFilter;
25
+ };
26
+ put({ cursor, filter }: {
27
+ cursor?: Cursor;
28
+ filter?: TFilter;
29
+ }): void;
30
+ del(): void;
31
+ private _getCheckpoint;
32
+ private _putCheckpoint;
33
+ private _delCheckpoint;
34
+ private _getFilter;
35
+ private _putFilter;
36
+ private _delFilter;
37
+ }
38
+ type CheckpointRow = {
39
+ id: string;
40
+ order_key: number;
41
+ unique_key?: `0x${string}`;
42
+ };
43
+ type FilterRow = {
44
+ id: string;
45
+ filter: string;
46
+ from_block: number;
47
+ to_block?: number;
48
+ };
49
+
50
+ export { type CheckpointRow, type FilterRow, SqlitePersistence, sqlitePersistence };
@@ -0,0 +1,50 @@
1
+ import { I as IndexerPlugin } from '../shared/indexer.f761abcd.js';
2
+ import { Cursor } from '@apibara/protocol';
3
+ import { Database } from 'better-sqlite3';
4
+ import 'hookable';
5
+ import '../shared/indexer.b9c8f0d8.js';
6
+
7
+ declare function sqlitePersistence<TFilter, TBlock, TTxnParams>({ database, }: {
8
+ database: Database;
9
+ }): IndexerPlugin<TFilter, TBlock, TTxnParams>;
10
+ declare class SqlitePersistence<TFilter> {
11
+ private _db;
12
+ /** Sqlite Queries Prepare Statements */
13
+ private _getCheckpointQuery;
14
+ private _putCheckpointQuery;
15
+ private _delCheckpointQuery;
16
+ private _getFilterQuery;
17
+ private _updateFilterToBlockQuery;
18
+ private _insertFilterQuery;
19
+ private _delFilterQuery;
20
+ constructor(_db: Database);
21
+ static initialize(db: Database): void;
22
+ get(): {
23
+ cursor?: Cursor;
24
+ filter?: TFilter;
25
+ };
26
+ put({ cursor, filter }: {
27
+ cursor?: Cursor;
28
+ filter?: TFilter;
29
+ }): void;
30
+ del(): void;
31
+ private _getCheckpoint;
32
+ private _putCheckpoint;
33
+ private _delCheckpoint;
34
+ private _getFilter;
35
+ private _putFilter;
36
+ private _delFilter;
37
+ }
38
+ type CheckpointRow = {
39
+ id: string;
40
+ order_key: number;
41
+ unique_key?: `0x${string}`;
42
+ };
43
+ type FilterRow = {
44
+ id: string;
45
+ filter: string;
46
+ from_block: number;
47
+ to_block?: number;
48
+ };
49
+
50
+ export { type CheckpointRow, type FilterRow, SqlitePersistence, sqlitePersistence };
@@ -0,0 +1,179 @@
1
+ import { d as deserialize, s as serialize } from '../shared/indexer.2c23c9cd.mjs';
2
+ import 'node:fs/promises';
3
+ import 'node:path';
4
+ import 'klona/full';
5
+ import 'consola';
6
+ import 'hookable';
7
+ import 'node:assert';
8
+ import 'node:fs';
9
+ import '@apibara/protocol/testing';
10
+ import { defineIndexerPlugin } from './index.mjs';
11
+ import 'node:async_hooks';
12
+ import 'unctx';
13
+ import '@opentelemetry/api';
14
+
15
+ var __defProp = Object.defineProperty;
16
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
17
+ var __publicField = (obj, key, value) => {
18
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
19
+ return value;
20
+ };
21
+ function sqlitePersistence({
22
+ database
23
+ }) {
24
+ return defineIndexerPlugin((indexer) => {
25
+ let store;
26
+ indexer.hooks.hook("run:before", () => {
27
+ SqlitePersistence.initialize(database);
28
+ store = new SqlitePersistence(database);
29
+ });
30
+ indexer.hooks.hook("connect:before", ({ request }) => {
31
+ const { cursor, filter } = store.get();
32
+ if (cursor) {
33
+ request.startingCursor = cursor;
34
+ }
35
+ if (filter) {
36
+ request.filter[1] = filter;
37
+ }
38
+ });
39
+ indexer.hooks.hook("transaction:commit", ({ endCursor }) => {
40
+ if (endCursor) {
41
+ store.put({ cursor: endCursor });
42
+ }
43
+ });
44
+ indexer.hooks.hook("connect:factory", ({ request, endCursor }) => {
45
+ if (request.filter[1]) {
46
+ store.put({ cursor: endCursor, filter: request.filter[1] });
47
+ }
48
+ });
49
+ });
50
+ }
51
+ class SqlitePersistence {
52
+ constructor(_db) {
53
+ this._db = _db;
54
+ /** Sqlite Queries Prepare Statements */
55
+ __publicField(this, "_getCheckpointQuery");
56
+ __publicField(this, "_putCheckpointQuery");
57
+ __publicField(this, "_delCheckpointQuery");
58
+ __publicField(this, "_getFilterQuery");
59
+ __publicField(this, "_updateFilterToBlockQuery");
60
+ __publicField(this, "_insertFilterQuery");
61
+ __publicField(this, "_delFilterQuery");
62
+ this._getCheckpointQuery = this._db.prepare(statements.getCheckpoint);
63
+ this._putCheckpointQuery = this._db.prepare(statements.putCheckpoint);
64
+ this._delCheckpointQuery = this._db.prepare(statements.delCheckpoint);
65
+ this._getFilterQuery = this._db.prepare(statements.getFilter);
66
+ this._updateFilterToBlockQuery = this._db.prepare(
67
+ statements.updateFilterToBlock
68
+ );
69
+ this._insertFilterQuery = this._db.prepare(statements.insertFilter);
70
+ this._delFilterQuery = this._db.prepare(statements.delFilter);
71
+ }
72
+ static initialize(db) {
73
+ db.prepare(statements.createCheckpointsTable).run();
74
+ db.prepare(statements.createFiltersTable).run();
75
+ }
76
+ get() {
77
+ const cursor = this._getCheckpoint();
78
+ const filter = this._getFilter();
79
+ return { cursor, filter };
80
+ }
81
+ put({ cursor, filter }) {
82
+ if (cursor) {
83
+ this._putCheckpoint(cursor);
84
+ if (filter) {
85
+ this._putFilter(filter, cursor);
86
+ }
87
+ }
88
+ }
89
+ del() {
90
+ this._delCheckpoint();
91
+ this._delFilter();
92
+ }
93
+ // --- CHECKPOINTS TABLE METHODS ---
94
+ _getCheckpoint() {
95
+ const row = this._getCheckpointQuery.get("default");
96
+ if (!row)
97
+ return void 0;
98
+ return { orderKey: BigInt(row.order_key), uniqueKey: row.unique_key };
99
+ }
100
+ _putCheckpoint(cursor) {
101
+ this._putCheckpointQuery.run(
102
+ "default",
103
+ Number(cursor.orderKey),
104
+ cursor.uniqueKey
105
+ );
106
+ }
107
+ _delCheckpoint() {
108
+ this._delCheckpointQuery.run("default");
109
+ }
110
+ // --- FILTERS TABLE METHODS ---
111
+ _getFilter() {
112
+ const row = this._getFilterQuery.get("default");
113
+ if (!row)
114
+ return void 0;
115
+ return deserialize(row.filter);
116
+ }
117
+ _putFilter(filter, endCursor) {
118
+ this._updateFilterToBlockQuery.run(Number(endCursor.orderKey), "default");
119
+ this._insertFilterQuery.run(
120
+ "default",
121
+ serialize(filter),
122
+ Number(endCursor.orderKey)
123
+ );
124
+ }
125
+ _delFilter() {
126
+ this._delFilterQuery.run("default");
127
+ }
128
+ }
129
+ const statements = {
130
+ beginTxn: "BEGIN TRANSACTION",
131
+ commitTxn: "COMMIT TRANSACTION",
132
+ rollbackTxn: "ROLLBACK TRANSACTION",
133
+ createCheckpointsTable: `
134
+ CREATE TABLE IF NOT EXISTS checkpoints (
135
+ id TEXT NOT NULL PRIMARY KEY,
136
+ order_key INTEGER NOT NULL,
137
+ unique_key TEXT
138
+ );`,
139
+ createFiltersTable: `
140
+ CREATE TABLE IF NOT EXISTS filters (
141
+ id TEXT NOT NULL,
142
+ filter BLOB NOT NULL,
143
+ from_block INTEGER NOT NULL,
144
+ to_block INTEGER,
145
+ PRIMARY KEY (id, from_block)
146
+ );`,
147
+ getCheckpoint: `
148
+ SELECT *
149
+ FROM checkpoints
150
+ WHERE id = ?`,
151
+ putCheckpoint: `
152
+ INSERT INTO checkpoints (id, order_key, unique_key)
153
+ VALUES (?, ?, ?)
154
+ ON CONFLICT(id) DO UPDATE SET
155
+ order_key = excluded.order_key,
156
+ unique_key = excluded.unique_key`,
157
+ delCheckpoint: `
158
+ DELETE FROM checkpoints
159
+ WHERE id = ?`,
160
+ getFilter: `
161
+ SELECT *
162
+ FROM filters
163
+ WHERE id = ? AND to_block IS NULL`,
164
+ updateFilterToBlock: `
165
+ UPDATE filters
166
+ SET to_block = ?
167
+ WHERE id = ? AND to_block IS NULL`,
168
+ insertFilter: `
169
+ INSERT INTO filters (id, filter, from_block)
170
+ VALUES (?, ?, ?)
171
+ ON CONFLICT(id, from_block) DO UPDATE SET
172
+ filter = excluded.filter,
173
+ from_block = excluded.from_block`,
174
+ delFilter: `
175
+ DELETE FROM filters
176
+ WHERE id = ?`
177
+ };
178
+
179
+ export { SqlitePersistence, sqlitePersistence };
@@ -0,0 +1,35 @@
1
+ import { AsyncLocalStorage } from 'node:async_hooks';
2
+ import { getContext } from 'unctx';
3
+ import { trace } from '@opentelemetry/api';
4
+ import fs from 'node:fs';
5
+ import path from 'node:path';
6
+
7
+ const indexerAsyncContext = getContext("indexer", {
8
+ asyncContext: true,
9
+ AsyncLocalStorage
10
+ });
11
+ function useIndexerContext() {
12
+ return indexerAsyncContext.use();
13
+ }
14
+
15
+ const tracer = trace.getTracer("@apibara/indexer");
16
+
17
+ function deserialize(str) {
18
+ return JSON.parse(
19
+ str,
20
+ (_, value) => typeof value === "string" && value.match(/^\d+n$/) ? BigInt(value.slice(0, -1)) : value
21
+ );
22
+ }
23
+ function serialize(obj) {
24
+ return JSON.stringify(
25
+ obj,
26
+ (_, value) => typeof value === "bigint" ? `${value.toString()}n` : value,
27
+ " "
28
+ );
29
+ }
30
+ function isCassetteAvailable(vcrConfig, cassetteName) {
31
+ const filePath = path.join(vcrConfig.cassetteDir, `${cassetteName}.json`);
32
+ return fs.existsSync(filePath);
33
+ }
34
+
35
+ export { indexerAsyncContext as a, deserialize as d, isCassetteAvailable as i, serialize as s, tracer as t, useIndexerContext as u };
@@ -0,0 +1,47 @@
1
+ 'use strict';
2
+
3
+ const node_async_hooks = require('node:async_hooks');
4
+ const unctx = require('unctx');
5
+ const api = require('@opentelemetry/api');
6
+ const fs = require('node:fs');
7
+ const path = require('node:path');
8
+
9
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
10
+
11
+ const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
12
+ const path__default = /*#__PURE__*/_interopDefaultCompat(path);
13
+
14
+ const indexerAsyncContext = unctx.getContext("indexer", {
15
+ asyncContext: true,
16
+ AsyncLocalStorage: node_async_hooks.AsyncLocalStorage
17
+ });
18
+ function useIndexerContext() {
19
+ return indexerAsyncContext.use();
20
+ }
21
+
22
+ const tracer = api.trace.getTracer("@apibara/indexer");
23
+
24
+ function deserialize(str) {
25
+ return JSON.parse(
26
+ str,
27
+ (_, value) => typeof value === "string" && value.match(/^\d+n$/) ? BigInt(value.slice(0, -1)) : value
28
+ );
29
+ }
30
+ function serialize(obj) {
31
+ return JSON.stringify(
32
+ obj,
33
+ (_, value) => typeof value === "bigint" ? `${value.toString()}n` : value,
34
+ " "
35
+ );
36
+ }
37
+ function isCassetteAvailable(vcrConfig, cassetteName) {
38
+ const filePath = path__default.join(vcrConfig.cassetteDir, `${cassetteName}.json`);
39
+ return fs__default.existsSync(filePath);
40
+ }
41
+
42
+ exports.deserialize = deserialize;
43
+ exports.indexerAsyncContext = indexerAsyncContext;
44
+ exports.isCassetteAvailable = isCassetteAvailable;
45
+ exports.serialize = serialize;
46
+ exports.tracer = tracer;
47
+ exports.useIndexerContext = useIndexerContext;
@@ -1,25 +1,13 @@
1
- import fs$1 from 'node:fs/promises';
1
+ import { a as indexerAsyncContext, u as useIndexerContext, t as tracer, s as serialize, d as deserialize } from './indexer.2c23c9cd.mjs';
2
+ import fs from 'node:fs/promises';
2
3
  import path from 'node:path';
3
- import consola from 'consola';
4
4
  import { klona } from 'klona/full';
5
- import assert from 'node:assert';
6
- import fs from 'node:fs';
7
- import { MockClient } from '@apibara/protocol/testing';
5
+ import consola from 'consola';
8
6
  import { createHooks, createDebugger } from 'hookable';
9
- import { AsyncLocalStorage } from 'node:async_hooks';
10
- import { getContext } from 'unctx';
11
- import { trace } from '@opentelemetry/api';
7
+ import assert from 'node:assert';
12
8
  import { d as defaultSink, S as Sink } from './indexer.93d6b2eb.mjs';
13
-
14
- const indexerAsyncContext = getContext("indexer", {
15
- asyncContext: true,
16
- AsyncLocalStorage
17
- });
18
- function useIndexerContext() {
19
- return indexerAsyncContext.use();
20
- }
21
-
22
- const tracer = trace.getTracer("@apibara/indexer");
9
+ import fs$1 from 'node:fs';
10
+ import { MockClient } from '@apibara/protocol/testing';
23
11
 
24
12
  function defineIndexer(streamConfig) {
25
13
  return (config) => ({
@@ -170,24 +158,6 @@ async function run(client, indexer) {
170
158
  });
171
159
  }
172
160
 
173
- function deserialize(str) {
174
- return JSON.parse(
175
- str,
176
- (_, value) => typeof value === "string" && value.match(/^\d+n$/) ? BigInt(value.slice(0, -1)) : value
177
- );
178
- }
179
- function serialize(obj) {
180
- return JSON.stringify(
181
- obj,
182
- (_, value) => typeof value === "bigint" ? `${value.toString()}n` : value,
183
- " "
184
- );
185
- }
186
- function isCassetteAvailable(vcrConfig, cassetteName) {
187
- const filePath = path.join(vcrConfig.cassetteDir, `${cassetteName}.json`);
188
- return fs.existsSync(filePath);
189
- }
190
-
191
161
  async function record(vcrConfig, client, indexerArg, cassetteOptions) {
192
162
  const indexer = klona(indexerArg);
193
163
  const messages = [];
@@ -208,7 +178,7 @@ async function record(vcrConfig, client, indexerArg, cassetteOptions) {
208
178
  vcrConfig.cassetteDir,
209
179
  `${cassetteOptions.name}.json`
210
180
  );
211
- await fs$1.writeFile(filePath, serialize(output), { flag: "w" });
181
+ await fs.writeFile(filePath, serialize(output), { flag: "w" });
212
182
  }
213
183
  });
214
184
  await run(client, indexer);
@@ -263,7 +233,7 @@ async function replay(vcrConfig, indexer, cassetteName) {
263
233
  }
264
234
  function loadCassette(vcrConfig, cassetteName) {
265
235
  const filePath = path.join(vcrConfig.cassetteDir, `${cassetteName}.json`);
266
- const data = fs.readFileSync(filePath, "utf8");
236
+ const data = fs$1.readFileSync(filePath, "utf8");
267
237
  const cassetteData = deserialize(data);
268
238
  const { filter, messages } = cassetteData;
269
239
  return new MockClient((request, options) => {
@@ -276,4 +246,4 @@ function loadCassette(vcrConfig, cassetteName) {
276
246
  });
277
247
  }
278
248
 
279
- export { VcrSink as V, deserialize as a, record as b, createIndexer as c, defineIndexer as d, replay as e, isCassetteAvailable as i, loadCassette as l, run as r, serialize as s, useIndexerContext as u, vcr as v };
249
+ export { VcrSink as V, record as a, replay as b, createIndexer as c, defineIndexer as d, loadCassette as l, run as r, vcr as v };
@@ -0,0 +1,23 @@
1
+ import { Cursor, Client } from '@apibara/protocol';
2
+ import { f as Indexer } from './indexer.c7ed6b83.cjs';
3
+ import { b as SinkData } from './indexer.b9c8f0d8.cjs';
4
+
5
+ type VcrConfig = {
6
+ cassetteDir: string;
7
+ };
8
+ type CassetteOptions = {
9
+ name: string;
10
+ startingCursor: Cursor;
11
+ endingCursor: Cursor;
12
+ };
13
+
14
+ declare function replay<TFilter, TBlock, TTxnParams>(vcrConfig: VcrConfig, indexer: Indexer<TFilter, TBlock, TTxnParams>, cassetteName: string): Promise<VcrReplayResult>;
15
+ type VcrReplayResult = {
16
+ outputs: Array<{
17
+ endCursor?: Cursor;
18
+ data: SinkData[];
19
+ }>;
20
+ };
21
+ declare function loadCassette<TFilter, TBlock>(vcrConfig: VcrConfig, cassetteName: string): Client<TFilter, TBlock>;
22
+
23
+ export { type CassetteOptions as C, type VcrConfig as V, type VcrReplayResult as a, loadCassette as l, replay as r };