@apibara/indexer 2.0.0-beta.18 → 2.0.0-beta.20

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 (68) hide show
  1. package/dist/index.cjs +11 -9
  2. package/dist/index.d.cts +2 -2
  3. package/dist/index.d.mts +2 -2
  4. package/dist/index.d.ts +2 -2
  5. package/dist/index.mjs +5 -3
  6. package/dist/plugins/index.d.cts +2 -2
  7. package/dist/plugins/index.d.mts +2 -2
  8. package/dist/plugins/index.d.ts +2 -2
  9. package/dist/plugins/kv.cjs +6 -5
  10. package/dist/plugins/kv.d.cts +2 -2
  11. package/dist/plugins/kv.d.mts +2 -2
  12. package/dist/plugins/kv.d.ts +2 -2
  13. package/dist/plugins/kv.mjs +2 -1
  14. package/dist/plugins/logger.cjs +31 -0
  15. package/dist/plugins/logger.d.cts +13 -0
  16. package/dist/plugins/logger.d.mts +13 -0
  17. package/dist/plugins/logger.d.ts +13 -0
  18. package/dist/plugins/logger.mjs +28 -0
  19. package/dist/plugins/persistence.cjs +2 -1
  20. package/dist/plugins/persistence.d.cts +2 -2
  21. package/dist/plugins/persistence.d.mts +2 -2
  22. package/dist/plugins/persistence.d.ts +2 -2
  23. package/dist/plugins/persistence.mjs +2 -1
  24. package/dist/shared/{indexer.f055283f.cjs → indexer.077335f3.cjs} +0 -4
  25. package/dist/shared/{indexer.fd803d5b.cjs → indexer.20be838a.cjs} +5 -0
  26. package/dist/shared/{indexer.1895909f.d.cts → indexer.47b4546b.d.cts} +2 -0
  27. package/dist/shared/{indexer.1895909f.d.mts → indexer.47b4546b.d.mts} +2 -0
  28. package/dist/shared/{indexer.1895909f.d.ts → indexer.47b4546b.d.ts} +2 -0
  29. package/dist/shared/{indexer.7ac83e6b.mjs → indexer.54bc74ac.mjs} +5 -0
  30. package/dist/shared/{indexer.0d847427.d.ts → indexer.5a040ab3.d.ts} +1 -1
  31. package/dist/shared/{indexer.1082134b.d.cts → indexer.6f70ff10.d.mts} +1 -1
  32. package/dist/shared/indexer.943adee7.cjs +7 -0
  33. package/dist/shared/{indexer.136b6ca6.mjs → indexer.a55ad619.mjs} +1 -4
  34. package/dist/shared/indexer.e2bc22c0.mjs +5 -0
  35. package/dist/shared/{indexer.108e1a0b.d.mts → indexer.f97f8e70.d.cts} +1 -1
  36. package/dist/sinks/csv.cjs +4 -3
  37. package/dist/sinks/csv.d.cts +2 -1
  38. package/dist/sinks/csv.d.mts +2 -1
  39. package/dist/sinks/csv.d.ts +2 -1
  40. package/dist/sinks/csv.mjs +4 -3
  41. package/dist/sinks/drizzle/index.cjs +14 -3
  42. package/dist/sinks/drizzle/index.d.cts +2 -1
  43. package/dist/sinks/drizzle/index.d.mts +2 -1
  44. package/dist/sinks/drizzle/index.d.ts +2 -1
  45. package/dist/sinks/drizzle/index.mjs +14 -3
  46. package/dist/sinks/sqlite.cjs +9 -3
  47. package/dist/sinks/sqlite.d.cts +2 -1
  48. package/dist/sinks/sqlite.d.mts +2 -1
  49. package/dist/sinks/sqlite.d.ts +2 -1
  50. package/dist/sinks/sqlite.mjs +9 -3
  51. package/dist/testing/index.cjs +3 -2
  52. package/dist/testing/index.d.cts +2 -2
  53. package/dist/testing/index.d.mts +2 -2
  54. package/dist/testing/index.d.ts +2 -2
  55. package/dist/testing/index.mjs +3 -2
  56. package/dist/vcr/index.cjs +3 -2
  57. package/dist/vcr/index.d.cts +2 -2
  58. package/dist/vcr/index.d.mts +2 -2
  59. package/dist/vcr/index.d.ts +2 -2
  60. package/dist/vcr/index.mjs +3 -2
  61. package/package.json +8 -2
  62. package/src/indexer.ts +3 -0
  63. package/src/internal/testing.ts +5 -2
  64. package/src/plugins/logger.ts +30 -0
  65. package/src/sink.ts +7 -0
  66. package/src/sinks/csv.ts +6 -4
  67. package/src/sinks/drizzle/drizzle.ts +17 -4
  68. package/src/sinks/sqlite.ts +11 -4
package/dist/index.cjs CHANGED
@@ -3,8 +3,9 @@
3
3
  const consola = require('consola');
4
4
  const hookable = require('hookable');
5
5
  const assert = require('node:assert');
6
- const otel = require('./shared/indexer.f055283f.cjs');
7
- const sink = require('./shared/indexer.fd803d5b.cjs');
6
+ const context = require('./shared/indexer.077335f3.cjs');
7
+ const otel = require('./shared/indexer.943adee7.cjs');
8
+ const sink = require('./shared/indexer.20be838a.cjs');
8
9
  require('node:async_hooks');
9
10
  require('unctx');
10
11
  require('@opentelemetry/api');
@@ -39,10 +40,10 @@ function createIndexer({
39
40
  return indexer;
40
41
  }
41
42
  async function run(client, indexer) {
42
- await otel.indexerAsyncContext.callAsync({}, async () => {
43
- const context = otel.useIndexerContext();
43
+ await context.indexerAsyncContext.callAsync({}, async () => {
44
+ const context$1 = context.useIndexerContext();
44
45
  const sink$1 = indexer.options.sink ?? sink.defaultSink();
45
- context.sink = sink$1;
46
+ context$1.sink = sink$1;
46
47
  await indexer.hooks.callHook("run:before");
47
48
  const isFactoryMode = indexer.options.factory !== void 0;
48
49
  const request = indexer.streamConfig.Request.make({
@@ -52,6 +53,7 @@ async function run(client, indexer) {
52
53
  });
53
54
  const options = {};
54
55
  await indexer.hooks.callHook("connect:before", { request, options });
56
+ await sink$1.invalidateOnRestart(request.startingCursor);
55
57
  let mainFilter;
56
58
  if (isFactoryMode) {
57
59
  mainFilter = request.filter[1];
@@ -72,7 +74,7 @@ async function run(client, indexer) {
72
74
  await sink$1.transaction(
73
75
  { cursor, endCursor, finality },
74
76
  async (txn) => {
75
- context.sinkTransaction = txn;
77
+ context$1.sinkTransaction = txn;
76
78
  let block;
77
79
  if (isFactoryMode) {
78
80
  assert__default(indexer.options.factory !== void 0);
@@ -81,7 +83,7 @@ async function run(client, indexer) {
81
83
  if (factoryBlock !== null) {
82
84
  const { filter } = await indexer.options.factory({
83
85
  block: factoryBlock,
84
- context
86
+ context: context$1
85
87
  });
86
88
  if (filter) {
87
89
  mainFilter = indexer.streamConfig.mergeFilter(
@@ -120,7 +122,7 @@ async function run(client, indexer) {
120
122
  cursor,
121
123
  endCursor,
122
124
  finality,
123
- context
125
+ context: context$1
124
126
  });
125
127
  await indexer.hooks.callHook("handler:after", {
126
128
  block,
@@ -202,7 +204,7 @@ async function run(client, indexer) {
202
204
  });
203
205
  }
204
206
 
205
- exports.useIndexerContext = otel.useIndexerContext;
207
+ exports.useIndexerContext = context.useIndexerContext;
206
208
  exports.DefaultSink = sink.DefaultSink;
207
209
  exports.Sink = sink.Sink;
208
210
  exports.defaultSink = sink.defaultSink;
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- export { b as Indexer, e as IndexerConfig, c as IndexerHooks, I as IndexerWithStreamConfig, g as createIndexer, f as defineIndexer, r as run } from './shared/indexer.1082134b.cjs';
2
- export { D as DefaultSink, S as Sink, a as SinkCursorParams, b as SinkData, d as defaultSink, u as useIndexerContext, c as useSink } from './shared/indexer.1895909f.cjs';
1
+ export { b as Indexer, e as IndexerConfig, c as IndexerHooks, I as IndexerWithStreamConfig, g as createIndexer, f as defineIndexer, r as run } from './shared/indexer.f97f8e70.cjs';
2
+ export { D as DefaultSink, S as Sink, a as SinkCursorParams, b as SinkData, d as defaultSink, u as useIndexerContext, c as useSink } from './shared/indexer.47b4546b.cjs';
3
3
  import '@apibara/protocol';
4
4
  import 'hookable';
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- export { b as Indexer, e as IndexerConfig, c as IndexerHooks, I as IndexerWithStreamConfig, g as createIndexer, f as defineIndexer, r as run } from './shared/indexer.108e1a0b.mjs';
2
- export { D as DefaultSink, S as Sink, a as SinkCursorParams, b as SinkData, d as defaultSink, u as useIndexerContext, c as useSink } from './shared/indexer.1895909f.mjs';
1
+ export { b as Indexer, e as IndexerConfig, c as IndexerHooks, I as IndexerWithStreamConfig, g as createIndexer, f as defineIndexer, r as run } from './shared/indexer.6f70ff10.mjs';
2
+ export { D as DefaultSink, S as Sink, a as SinkCursorParams, b as SinkData, d as defaultSink, u as useIndexerContext, c as useSink } from './shared/indexer.47b4546b.mjs';
3
3
  import '@apibara/protocol';
4
4
  import 'hookable';
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { b as Indexer, e as IndexerConfig, c as IndexerHooks, I as IndexerWithStreamConfig, g as createIndexer, f as defineIndexer, r as run } from './shared/indexer.0d847427.js';
2
- export { D as DefaultSink, S as Sink, a as SinkCursorParams, b as SinkData, d as defaultSink, u as useIndexerContext, c as useSink } from './shared/indexer.1895909f.js';
1
+ export { b as Indexer, e as IndexerConfig, c as IndexerHooks, I as IndexerWithStreamConfig, g as createIndexer, f as defineIndexer, r as run } from './shared/indexer.5a040ab3.js';
2
+ export { D as DefaultSink, S as Sink, a as SinkCursorParams, b as SinkData, d as defaultSink, u as useIndexerContext, c as useSink } from './shared/indexer.47b4546b.js';
3
3
  import '@apibara/protocol';
4
4
  import 'hookable';
package/dist/index.mjs CHANGED
@@ -1,9 +1,10 @@
1
1
  import consola from 'consola';
2
2
  import { createHooks, createDebugger } from 'hookable';
3
3
  import assert from 'node:assert';
4
- import { i as indexerAsyncContext, u as useIndexerContext, t as tracer } from './shared/indexer.136b6ca6.mjs';
5
- import { d as defaultSink } from './shared/indexer.7ac83e6b.mjs';
6
- export { D as DefaultSink, S as Sink, u as useSink } from './shared/indexer.7ac83e6b.mjs';
4
+ import { i as indexerAsyncContext, u as useIndexerContext } from './shared/indexer.a55ad619.mjs';
5
+ import { t as tracer } from './shared/indexer.e2bc22c0.mjs';
6
+ import { d as defaultSink } from './shared/indexer.54bc74ac.mjs';
7
+ export { D as DefaultSink, S as Sink, u as useSink } from './shared/indexer.54bc74ac.mjs';
7
8
  import 'node:async_hooks';
8
9
  import 'unctx';
9
10
  import '@opentelemetry/api';
@@ -46,6 +47,7 @@ async function run(client, indexer) {
46
47
  });
47
48
  const options = {};
48
49
  await indexer.hooks.callHook("connect:before", { request, options });
50
+ await sink.invalidateOnRestart(request.startingCursor);
49
51
  let mainFilter;
50
52
  if (isFactoryMode) {
51
53
  mainFilter = request.filter[1];
@@ -1,4 +1,4 @@
1
- export { a as IndexerPlugin, d as defineIndexerPlugin } from '../shared/indexer.1082134b.cjs';
1
+ export { a as IndexerPlugin, d as defineIndexerPlugin } from '../shared/indexer.f97f8e70.cjs';
2
2
  import '@apibara/protocol';
3
3
  import 'hookable';
4
- import '../shared/indexer.1895909f.cjs';
4
+ import '../shared/indexer.47b4546b.cjs';
@@ -1,4 +1,4 @@
1
- export { a as IndexerPlugin, d as defineIndexerPlugin } from '../shared/indexer.108e1a0b.mjs';
1
+ export { a as IndexerPlugin, d as defineIndexerPlugin } from '../shared/indexer.6f70ff10.mjs';
2
2
  import '@apibara/protocol';
3
3
  import 'hookable';
4
- import '../shared/indexer.1895909f.mjs';
4
+ import '../shared/indexer.47b4546b.mjs';
@@ -1,4 +1,4 @@
1
- export { a as IndexerPlugin, d as defineIndexerPlugin } from '../shared/indexer.0d847427.js';
1
+ export { a as IndexerPlugin, d as defineIndexerPlugin } from '../shared/indexer.5a040ab3.js';
2
2
  import '@apibara/protocol';
3
3
  import 'hookable';
4
- import '../shared/indexer.1895909f.js';
4
+ import '../shared/indexer.47b4546b.js';
@@ -1,13 +1,14 @@
1
1
  'use strict';
2
2
 
3
3
  const assert = require('node:assert');
4
- const otel = require('../shared/indexer.f055283f.cjs');
4
+ const context = require('../shared/indexer.077335f3.cjs');
5
5
  const helper = require('../shared/indexer.219f58e0.cjs');
6
6
  require('node:fs/promises');
7
7
  require('node:path');
8
8
  require('klona/full');
9
9
  require('consola');
10
10
  require('hookable');
11
+ require('../shared/indexer.943adee7.cjs');
11
12
  require('node:fs');
12
13
  require('@apibara/protocol/testing');
13
14
  const plugins_index = require('./index.cjs');
@@ -33,18 +34,18 @@ function kv({
33
34
  KVStore.initialize(database);
34
35
  });
35
36
  indexer.hooks.hook("handler:before", ({ finality, endCursor }) => {
36
- const ctx = otel.useIndexerContext();
37
+ const ctx = context.useIndexerContext();
37
38
  assert__default(endCursor, new Error("endCursor cannot be undefined"));
38
39
  ctx.kv = new KVStore(database, finality, endCursor);
39
40
  ctx.kv.beginTransaction();
40
41
  });
41
42
  indexer.hooks.hook("handler:after", () => {
42
- const ctx = otel.useIndexerContext();
43
+ const ctx = context.useIndexerContext();
43
44
  ctx.kv.commitTransaction();
44
45
  ctx.kv = null;
45
46
  });
46
47
  indexer.hooks.hook("handler:exception", () => {
47
- const ctx = otel.useIndexerContext();
48
+ const ctx = context.useIndexerContext();
48
49
  ctx.kv.rollbackTransaction();
49
50
  ctx.kv = null;
50
51
  });
@@ -100,7 +101,7 @@ class KVStore {
100
101
  }
101
102
  }
102
103
  function useKVStore() {
103
- const ctx = otel.useIndexerContext();
104
+ const ctx = context.useIndexerContext();
104
105
  if (!ctx?.kv)
105
106
  throw new Error("KV Plugin is not available in context!");
106
107
  return ctx.kv;
@@ -1,8 +1,8 @@
1
- import { a as IndexerPlugin } from '../shared/indexer.1082134b.cjs';
1
+ import { a as IndexerPlugin } from '../shared/indexer.f97f8e70.cjs';
2
2
  import { DataFinality, Cursor } from '@apibara/protocol';
3
3
  import { Database } from 'better-sqlite3';
4
4
  import 'hookable';
5
- import '../shared/indexer.1895909f.cjs';
5
+ import '../shared/indexer.47b4546b.cjs';
6
6
 
7
7
  declare function kv<TFilter, TBlock, TTxnParams>({ database, }: {
8
8
  database: Database;
@@ -1,8 +1,8 @@
1
- import { a as IndexerPlugin } from '../shared/indexer.108e1a0b.mjs';
1
+ import { a as IndexerPlugin } from '../shared/indexer.6f70ff10.mjs';
2
2
  import { DataFinality, Cursor } from '@apibara/protocol';
3
3
  import { Database } from 'better-sqlite3';
4
4
  import 'hookable';
5
- import '../shared/indexer.1895909f.mjs';
5
+ import '../shared/indexer.47b4546b.mjs';
6
6
 
7
7
  declare function kv<TFilter, TBlock, TTxnParams>({ database, }: {
8
8
  database: Database;
@@ -1,8 +1,8 @@
1
- import { a as IndexerPlugin } from '../shared/indexer.0d847427.js';
1
+ import { a as IndexerPlugin } from '../shared/indexer.5a040ab3.js';
2
2
  import { DataFinality, Cursor } from '@apibara/protocol';
3
3
  import { Database } from 'better-sqlite3';
4
4
  import 'hookable';
5
- import '../shared/indexer.1895909f.js';
5
+ import '../shared/indexer.47b4546b.js';
6
6
 
7
7
  declare function kv<TFilter, TBlock, TTxnParams>({ database, }: {
8
8
  database: Database;
@@ -1,11 +1,12 @@
1
1
  import assert from 'node:assert';
2
- import { u as useIndexerContext } from '../shared/indexer.136b6ca6.mjs';
2
+ import { u as useIndexerContext } from '../shared/indexer.a55ad619.mjs';
3
3
  import { d as deserialize, s as serialize } from '../shared/indexer.0c0510df.mjs';
4
4
  import 'node:fs/promises';
5
5
  import 'node:path';
6
6
  import 'klona/full';
7
7
  import 'consola';
8
8
  import 'hookable';
9
+ import '../shared/indexer.e2bc22c0.mjs';
9
10
  import 'node:fs';
10
11
  import '@apibara/protocol/testing';
11
12
  import { defineIndexerPlugin } from './index.mjs';
@@ -0,0 +1,31 @@
1
+ 'use strict';
2
+
3
+ const consola = require('consola');
4
+ const context = require('../shared/indexer.077335f3.cjs');
5
+ const plugins_index = require('./index.cjs');
6
+ require('node:async_hooks');
7
+ require('unctx');
8
+
9
+ function logger({
10
+ logger: logger2
11
+ } = {}) {
12
+ return plugins_index.defineIndexerPlugin((indexer) => {
13
+ indexer.hooks.hook("run:before", () => {
14
+ const ctx = context.useIndexerContext();
15
+ if (logger2) {
16
+ ctx.logger = consola.consola.create({ reporters: [logger2] });
17
+ } else {
18
+ ctx.logger = consola.consola.create({});
19
+ }
20
+ });
21
+ });
22
+ }
23
+ function useLogger() {
24
+ const ctx = context.useIndexerContext();
25
+ if (!ctx?.logger)
26
+ throw new Error("Logger plugin is not available in context");
27
+ return ctx.logger;
28
+ }
29
+
30
+ exports.logger = logger;
31
+ exports.useLogger = useLogger;
@@ -0,0 +1,13 @@
1
+ import { a as IndexerPlugin } from '../shared/indexer.f97f8e70.cjs';
2
+ import { ConsolaReporter, ConsolaInstance } from 'consola';
3
+ export { ConsolaInstance, ConsolaReporter } from 'consola';
4
+ import '@apibara/protocol';
5
+ import 'hookable';
6
+ import '../shared/indexer.47b4546b.cjs';
7
+
8
+ declare function logger<TFilter, TBlock, TTxnParams>({ logger, }?: {
9
+ logger?: ConsolaReporter;
10
+ }): IndexerPlugin<TFilter, TBlock, TTxnParams>;
11
+ declare function useLogger(): ConsolaInstance;
12
+
13
+ export { logger, useLogger };
@@ -0,0 +1,13 @@
1
+ import { a as IndexerPlugin } from '../shared/indexer.6f70ff10.mjs';
2
+ import { ConsolaReporter, ConsolaInstance } from 'consola';
3
+ export { ConsolaInstance, ConsolaReporter } from 'consola';
4
+ import '@apibara/protocol';
5
+ import 'hookable';
6
+ import '../shared/indexer.47b4546b.mjs';
7
+
8
+ declare function logger<TFilter, TBlock, TTxnParams>({ logger, }?: {
9
+ logger?: ConsolaReporter;
10
+ }): IndexerPlugin<TFilter, TBlock, TTxnParams>;
11
+ declare function useLogger(): ConsolaInstance;
12
+
13
+ export { logger, useLogger };
@@ -0,0 +1,13 @@
1
+ import { a as IndexerPlugin } from '../shared/indexer.5a040ab3.js';
2
+ import { ConsolaReporter, ConsolaInstance } from 'consola';
3
+ export { ConsolaInstance, ConsolaReporter } from 'consola';
4
+ import '@apibara/protocol';
5
+ import 'hookable';
6
+ import '../shared/indexer.47b4546b.js';
7
+
8
+ declare function logger<TFilter, TBlock, TTxnParams>({ logger, }?: {
9
+ logger?: ConsolaReporter;
10
+ }): IndexerPlugin<TFilter, TBlock, TTxnParams>;
11
+ declare function useLogger(): ConsolaInstance;
12
+
13
+ export { logger, useLogger };
@@ -0,0 +1,28 @@
1
+ import { consola } from 'consola';
2
+ import { u as useIndexerContext } from '../shared/indexer.a55ad619.mjs';
3
+ import { defineIndexerPlugin } from './index.mjs';
4
+ import 'node:async_hooks';
5
+ import 'unctx';
6
+
7
+ function logger({
8
+ logger: logger2
9
+ } = {}) {
10
+ return defineIndexerPlugin((indexer) => {
11
+ indexer.hooks.hook("run:before", () => {
12
+ const ctx = useIndexerContext();
13
+ if (logger2) {
14
+ ctx.logger = consola.create({ reporters: [logger2] });
15
+ } else {
16
+ ctx.logger = consola.create({});
17
+ }
18
+ });
19
+ });
20
+ }
21
+ function useLogger() {
22
+ const ctx = useIndexerContext();
23
+ if (!ctx?.logger)
24
+ throw new Error("Logger plugin is not available in context");
25
+ return ctx.logger;
26
+ }
27
+
28
+ export { logger, useLogger };
@@ -7,7 +7,8 @@ require('klona/full');
7
7
  require('consola');
8
8
  require('hookable');
9
9
  require('node:assert');
10
- require('../shared/indexer.f055283f.cjs');
10
+ require('../shared/indexer.077335f3.cjs');
11
+ require('../shared/indexer.943adee7.cjs');
11
12
  require('node:fs');
12
13
  require('@apibara/protocol/testing');
13
14
  const plugins_index = require('./index.cjs');
@@ -1,8 +1,8 @@
1
- import { a as IndexerPlugin } from '../shared/indexer.1082134b.cjs';
1
+ import { a as IndexerPlugin } from '../shared/indexer.f97f8e70.cjs';
2
2
  import { Cursor } from '@apibara/protocol';
3
3
  import { Database } from 'better-sqlite3';
4
4
  import 'hookable';
5
- import '../shared/indexer.1895909f.cjs';
5
+ import '../shared/indexer.47b4546b.cjs';
6
6
 
7
7
  declare function sqlitePersistence<TFilter, TBlock, TTxnParams>({ database, }: {
8
8
  database: Database;
@@ -1,8 +1,8 @@
1
- import { a as IndexerPlugin } from '../shared/indexer.108e1a0b.mjs';
1
+ import { a as IndexerPlugin } from '../shared/indexer.6f70ff10.mjs';
2
2
  import { Cursor } from '@apibara/protocol';
3
3
  import { Database } from 'better-sqlite3';
4
4
  import 'hookable';
5
- import '../shared/indexer.1895909f.mjs';
5
+ import '../shared/indexer.47b4546b.mjs';
6
6
 
7
7
  declare function sqlitePersistence<TFilter, TBlock, TTxnParams>({ database, }: {
8
8
  database: Database;
@@ -1,8 +1,8 @@
1
- import { a as IndexerPlugin } from '../shared/indexer.0d847427.js';
1
+ import { a as IndexerPlugin } from '../shared/indexer.5a040ab3.js';
2
2
  import { Cursor } from '@apibara/protocol';
3
3
  import { Database } from 'better-sqlite3';
4
4
  import 'hookable';
5
- import '../shared/indexer.1895909f.js';
5
+ import '../shared/indexer.47b4546b.js';
6
6
 
7
7
  declare function sqlitePersistence<TFilter, TBlock, TTxnParams>({ database, }: {
8
8
  database: Database;
@@ -5,7 +5,8 @@ import 'klona/full';
5
5
  import 'consola';
6
6
  import 'hookable';
7
7
  import 'node:assert';
8
- import '../shared/indexer.136b6ca6.mjs';
8
+ import '../shared/indexer.a55ad619.mjs';
9
+ import '../shared/indexer.e2bc22c0.mjs';
9
10
  import 'node:fs';
10
11
  import '@apibara/protocol/testing';
11
12
  import { defineIndexerPlugin } from './index.mjs';
@@ -2,7 +2,6 @@
2
2
 
3
3
  const node_async_hooks = require('node:async_hooks');
4
4
  const unctx = require('unctx');
5
- const api = require('@opentelemetry/api');
6
5
 
7
6
  const indexerAsyncContext = unctx.getContext("indexer", {
8
7
  asyncContext: true,
@@ -12,8 +11,5 @@ function useIndexerContext() {
12
11
  return indexerAsyncContext.use();
13
12
  }
14
13
 
15
- const tracer = api.trace.getTracer("@apibara/indexer");
16
-
17
14
  exports.indexerAsyncContext = indexerAsyncContext;
18
- exports.tracer = tracer;
19
15
  exports.useIndexerContext = useIndexerContext;
@@ -12,6 +12,11 @@ class DefaultSink extends Sink {
12
12
  async transaction({ cursor, endCursor, finality }, cb) {
13
13
  await cb({});
14
14
  }
15
+ async invalidateOnRestart(cursor) {
16
+ consola__default.info(
17
+ `Invalidating all rows with cursor > ${cursor?.orderKey} on restart`
18
+ );
19
+ }
15
20
  async invalidate(cursor) {
16
21
  consola__default.info(`Invalidating cursor ${cursor?.orderKey}`);
17
22
  }
@@ -8,11 +8,13 @@ type SinkCursorParams = {
8
8
  };
9
9
  declare abstract class Sink<TTxnParams = unknown> {
10
10
  abstract transaction({ cursor, endCursor, finality }: SinkCursorParams, cb: (params: TTxnParams) => Promise<void>): Promise<void>;
11
+ abstract invalidateOnRestart(cursor?: Cursor): Promise<void>;
11
12
  abstract invalidate(cursor?: Cursor): Promise<void>;
12
13
  abstract finalize(cursor?: Cursor): Promise<void>;
13
14
  }
14
15
  declare class DefaultSink extends Sink<unknown> {
15
16
  transaction({ cursor, endCursor, finality }: SinkCursorParams, cb: (params: unknown) => Promise<void>): Promise<void>;
17
+ invalidateOnRestart(cursor?: Cursor): Promise<void>;
16
18
  invalidate(cursor?: Cursor): Promise<void>;
17
19
  finalize(cursor?: Cursor): Promise<void>;
18
20
  }
@@ -8,11 +8,13 @@ type SinkCursorParams = {
8
8
  };
9
9
  declare abstract class Sink<TTxnParams = unknown> {
10
10
  abstract transaction({ cursor, endCursor, finality }: SinkCursorParams, cb: (params: TTxnParams) => Promise<void>): Promise<void>;
11
+ abstract invalidateOnRestart(cursor?: Cursor): Promise<void>;
11
12
  abstract invalidate(cursor?: Cursor): Promise<void>;
12
13
  abstract finalize(cursor?: Cursor): Promise<void>;
13
14
  }
14
15
  declare class DefaultSink extends Sink<unknown> {
15
16
  transaction({ cursor, endCursor, finality }: SinkCursorParams, cb: (params: unknown) => Promise<void>): Promise<void>;
17
+ invalidateOnRestart(cursor?: Cursor): Promise<void>;
16
18
  invalidate(cursor?: Cursor): Promise<void>;
17
19
  finalize(cursor?: Cursor): Promise<void>;
18
20
  }
@@ -8,11 +8,13 @@ type SinkCursorParams = {
8
8
  };
9
9
  declare abstract class Sink<TTxnParams = unknown> {
10
10
  abstract transaction({ cursor, endCursor, finality }: SinkCursorParams, cb: (params: TTxnParams) => Promise<void>): Promise<void>;
11
+ abstract invalidateOnRestart(cursor?: Cursor): Promise<void>;
11
12
  abstract invalidate(cursor?: Cursor): Promise<void>;
12
13
  abstract finalize(cursor?: Cursor): Promise<void>;
13
14
  }
14
15
  declare class DefaultSink extends Sink<unknown> {
15
16
  transaction({ cursor, endCursor, finality }: SinkCursorParams, cb: (params: unknown) => Promise<void>): Promise<void>;
17
+ invalidateOnRestart(cursor?: Cursor): Promise<void>;
16
18
  invalidate(cursor?: Cursor): Promise<void>;
17
19
  finalize(cursor?: Cursor): Promise<void>;
18
20
  }
@@ -6,6 +6,11 @@ class DefaultSink extends Sink {
6
6
  async transaction({ cursor, endCursor, finality }, cb) {
7
7
  await cb({});
8
8
  }
9
+ async invalidateOnRestart(cursor) {
10
+ consola.info(
11
+ `Invalidating all rows with cursor > ${cursor?.orderKey} on restart`
12
+ );
13
+ }
9
14
  async invalidate(cursor) {
10
15
  consola.info(`Invalidating cursor ${cursor?.orderKey}`);
11
16
  }
@@ -1,6 +1,6 @@
1
1
  import { StreamDataRequest, StreamDataOptions, Cursor, DataFinality, StreamDataResponse, Invalidate, Finalize, Heartbeat, SystemMessage, StreamConfig, Client } from '@apibara/protocol';
2
2
  import { NestedHooks, Hookable } from 'hookable';
3
- import { S as Sink, I as IndexerContext } from './indexer.1895909f.js';
3
+ import { S as Sink, I as IndexerContext } from './indexer.47b4546b.js';
4
4
 
5
5
  type IndexerPlugin<TFilter, TBlock, TTxnParams> = (indexer: Indexer<TFilter, TBlock, TTxnParams>) => void;
6
6
  declare function defineIndexerPlugin<TFilter, TBlock, TTxnParams>(def: IndexerPlugin<TFilter, TBlock, TTxnParams>): IndexerPlugin<TFilter, TBlock, TTxnParams>;
@@ -1,6 +1,6 @@
1
1
  import { StreamDataRequest, StreamDataOptions, Cursor, DataFinality, StreamDataResponse, Invalidate, Finalize, Heartbeat, SystemMessage, StreamConfig, Client } from '@apibara/protocol';
2
2
  import { NestedHooks, Hookable } from 'hookable';
3
- import { S as Sink, I as IndexerContext } from './indexer.1895909f.cjs';
3
+ import { S as Sink, I as IndexerContext } from './indexer.47b4546b.mjs';
4
4
 
5
5
  type IndexerPlugin<TFilter, TBlock, TTxnParams> = (indexer: Indexer<TFilter, TBlock, TTxnParams>) => void;
6
6
  declare function defineIndexerPlugin<TFilter, TBlock, TTxnParams>(def: IndexerPlugin<TFilter, TBlock, TTxnParams>): IndexerPlugin<TFilter, TBlock, TTxnParams>;
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ const api = require('@opentelemetry/api');
4
+
5
+ const tracer = api.trace.getTracer("@apibara/indexer");
6
+
7
+ exports.tracer = tracer;
@@ -1,6 +1,5 @@
1
1
  import { AsyncLocalStorage } from 'node:async_hooks';
2
2
  import { getContext } from 'unctx';
3
- import { trace } from '@opentelemetry/api';
4
3
 
5
4
  const indexerAsyncContext = getContext("indexer", {
6
5
  asyncContext: true,
@@ -10,6 +9,4 @@ function useIndexerContext() {
10
9
  return indexerAsyncContext.use();
11
10
  }
12
11
 
13
- const tracer = trace.getTracer("@apibara/indexer");
14
-
15
- export { indexerAsyncContext as i, tracer as t, useIndexerContext as u };
12
+ export { indexerAsyncContext as i, useIndexerContext as u };
@@ -0,0 +1,5 @@
1
+ import { trace } from '@opentelemetry/api';
2
+
3
+ const tracer = trace.getTracer("@apibara/indexer");
4
+
5
+ export { tracer as t };
@@ -1,6 +1,6 @@
1
1
  import { StreamDataRequest, StreamDataOptions, Cursor, DataFinality, StreamDataResponse, Invalidate, Finalize, Heartbeat, SystemMessage, StreamConfig, Client } from '@apibara/protocol';
2
2
  import { NestedHooks, Hookable } from 'hookable';
3
- import { S as Sink, I as IndexerContext } from './indexer.1895909f.mjs';
3
+ import { S as Sink, I as IndexerContext } from './indexer.47b4546b.cjs';
4
4
 
5
5
  type IndexerPlugin<TFilter, TBlock, TTxnParams> = (indexer: Indexer<TFilter, TBlock, TTxnParams>) => void;
6
6
  declare function defineIndexerPlugin<TFilter, TBlock, TTxnParams>(def: IndexerPlugin<TFilter, TBlock, TTxnParams>): IndexerPlugin<TFilter, TBlock, TTxnParams>;
@@ -2,7 +2,7 @@
2
2
 
3
3
  const fs = require('node:fs');
4
4
  const csvStringify = require('csv-stringify');
5
- const sink = require('../shared/indexer.fd803d5b.cjs');
5
+ const sink = require('../shared/indexer.20be838a.cjs');
6
6
  require('consola');
7
7
 
8
8
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
@@ -37,11 +37,12 @@ class CsvSink extends sink.Sink {
37
37
  await cb({ writer });
38
38
  await this.write({ data: context.buffer, endCursor });
39
39
  }
40
+ async invalidateOnRestart(cursor) {
41
+ }
40
42
  async invalidate(cursor) {
41
- throw new Error("Not implemented");
43
+ throw new Error("Reorg for CSV Sink is not implemented");
42
44
  }
43
45
  async finalize(cursor) {
44
- throw new Error("Not implemented");
45
46
  }
46
47
  async insertToCSV(data) {
47
48
  if (data.length === 0)
@@ -1,6 +1,6 @@
1
1
  import { Cursor } from '@apibara/protocol';
2
2
  import { Options, Stringifier } from 'csv-stringify';
3
- import { S as Sink, a as SinkCursorParams, b as SinkData } from '../shared/indexer.1895909f.cjs';
3
+ import { S as Sink, a as SinkCursorParams, b as SinkData } from '../shared/indexer.47b4546b.cjs';
4
4
 
5
5
  type CsvArgs = {
6
6
  /**
@@ -57,6 +57,7 @@ declare class CsvSink extends Sink {
57
57
  constructor(_stringifier: Stringifier, _config: CsvSinkOptions);
58
58
  private write;
59
59
  transaction({ cursor, endCursor, finality }: SinkCursorParams, cb: (params: TxnParams) => Promise<void>): Promise<void>;
60
+ invalidateOnRestart(cursor?: Cursor): Promise<void>;
60
61
  invalidate(cursor?: Cursor): Promise<void>;
61
62
  finalize(cursor?: Cursor): Promise<void>;
62
63
  private insertToCSV;
@@ -1,6 +1,6 @@
1
1
  import { Cursor } from '@apibara/protocol';
2
2
  import { Options, Stringifier } from 'csv-stringify';
3
- import { S as Sink, a as SinkCursorParams, b as SinkData } from '../shared/indexer.1895909f.mjs';
3
+ import { S as Sink, a as SinkCursorParams, b as SinkData } from '../shared/indexer.47b4546b.mjs';
4
4
 
5
5
  type CsvArgs = {
6
6
  /**
@@ -57,6 +57,7 @@ declare class CsvSink extends Sink {
57
57
  constructor(_stringifier: Stringifier, _config: CsvSinkOptions);
58
58
  private write;
59
59
  transaction({ cursor, endCursor, finality }: SinkCursorParams, cb: (params: TxnParams) => Promise<void>): Promise<void>;
60
+ invalidateOnRestart(cursor?: Cursor): Promise<void>;
60
61
  invalidate(cursor?: Cursor): Promise<void>;
61
62
  finalize(cursor?: Cursor): Promise<void>;
62
63
  private insertToCSV;
@@ -1,6 +1,6 @@
1
1
  import { Cursor } from '@apibara/protocol';
2
2
  import { Options, Stringifier } from 'csv-stringify';
3
- import { S as Sink, a as SinkCursorParams, b as SinkData } from '../shared/indexer.1895909f.js';
3
+ import { S as Sink, a as SinkCursorParams, b as SinkData } from '../shared/indexer.47b4546b.js';
4
4
 
5
5
  type CsvArgs = {
6
6
  /**
@@ -57,6 +57,7 @@ declare class CsvSink extends Sink {
57
57
  constructor(_stringifier: Stringifier, _config: CsvSinkOptions);
58
58
  private write;
59
59
  transaction({ cursor, endCursor, finality }: SinkCursorParams, cb: (params: TxnParams) => Promise<void>): Promise<void>;
60
+ invalidateOnRestart(cursor?: Cursor): Promise<void>;
60
61
  invalidate(cursor?: Cursor): Promise<void>;
61
62
  finalize(cursor?: Cursor): Promise<void>;
62
63
  private insertToCSV;