@apibara/indexer 2.1.0-beta.1 → 2.1.0-beta.11

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 CHANGED
@@ -114,9 +114,13 @@ async function run(client, indexer, runOptions = {}) {
114
114
  if (indexer.options.startingCursor) {
115
115
  startingCursor = indexer.options.startingCursor;
116
116
  } else if (indexer.options.startingBlock !== void 0) {
117
- startingCursor = {
118
- orderKey: indexer.options.startingBlock
119
- };
117
+ if (indexer.options.startingBlock === 0n) {
118
+ startingCursor = void 0;
119
+ } else if (indexer.options.startingBlock > 0n) {
120
+ startingCursor = {
121
+ orderKey: indexer.options.startingBlock - 1n
122
+ };
123
+ }
120
124
  }
121
125
  const request = indexer.streamConfig.Request.make({
122
126
  filter: isFactoryMode ? [indexer.options.filter, {}] : [indexer.options.filter],
package/dist/index.mjs CHANGED
@@ -107,9 +107,13 @@ async function run(client, indexer, runOptions = {}) {
107
107
  if (indexer.options.startingCursor) {
108
108
  startingCursor = indexer.options.startingCursor;
109
109
  } else if (indexer.options.startingBlock !== void 0) {
110
- startingCursor = {
111
- orderKey: indexer.options.startingBlock
112
- };
110
+ if (indexer.options.startingBlock === 0n) {
111
+ startingCursor = void 0;
112
+ } else if (indexer.options.startingBlock > 0n) {
113
+ startingCursor = {
114
+ orderKey: indexer.options.startingBlock - 1n
115
+ };
116
+ }
113
117
  }
114
118
  const request = indexer.streamConfig.Request.make({
115
119
  filter: isFactoryMode ? [indexer.options.filter, {}] : [indexer.options.filter],
@@ -5,10 +5,11 @@ const testing = require('@apibara/protocol/testing');
5
5
  const context = require('../shared/indexer.077335f3.cjs');
6
6
  const index = require('../index.cjs');
7
7
  const config = require('../shared/indexer.601ceab0.cjs');
8
- require('consola');
8
+ const logger = require('../shared/indexer.2416906c.cjs');
9
9
  const internal_plugins = require('./plugins.cjs');
10
10
  require('node:async_hooks');
11
11
  require('unctx');
12
+ require('consola');
12
13
  require('hookable');
13
14
  require('node:assert');
14
15
  require('@opentelemetry/api');
@@ -62,6 +63,7 @@ function getMockIndexer(params) {
62
63
  async transform() {
63
64
  },
64
65
  plugins: [
66
+ logger.logger(),
65
67
  internal_plugins.internalContext(
66
68
  contextParams ?? {
67
69
  availableIndexers: ["testing"],
@@ -3,10 +3,11 @@ import { MockStream } from '@apibara/protocol/testing';
3
3
  import { u as useIndexerContext } from '../shared/indexer.a55ad619.mjs';
4
4
  import { createIndexer, defineIndexer } from '../index.mjs';
5
5
  import { d as defineIndexerPlugin } from '../shared/indexer.9b21ddd2.mjs';
6
- import 'consola';
6
+ import { l as logger } from '../shared/indexer.ff25c953.mjs';
7
7
  import { internalContext } from './plugins.mjs';
8
8
  import 'node:async_hooks';
9
9
  import 'unctx';
10
+ import 'consola';
10
11
  import 'hookable';
11
12
  import 'node:assert';
12
13
  import '@opentelemetry/api';
@@ -60,6 +61,7 @@ function getMockIndexer(params) {
60
61
  async transform() {
61
62
  },
62
63
  plugins: [
64
+ logger(),
63
65
  internalContext(
64
66
  contextParams ?? {
65
67
  availableIndexers: ["testing"],
@@ -2,16 +2,16 @@
2
2
 
3
3
  const protocol = require('@apibara/protocol');
4
4
  const ci = require('ci-info');
5
+ const context = require('../shared/indexer.077335f3.cjs');
5
6
  const index = require('../index.cjs');
6
7
  const internal_plugins = require('../internal/plugins.cjs');
7
8
  const logger = require('../shared/indexer.2416906c.cjs');
8
9
  const vcr_index = require('../vcr/index.cjs');
10
+ require('node:async_hooks');
11
+ require('unctx');
9
12
  require('consola');
10
13
  require('hookable');
11
14
  require('node:assert');
12
- require('../shared/indexer.077335f3.cjs');
13
- require('node:async_hooks');
14
- require('unctx');
15
15
  require('@opentelemetry/api');
16
16
  require('../shared/indexer.601ceab0.cjs');
17
17
  require('node:fs/promises');
@@ -24,6 +24,7 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
24
24
  const ci__default = /*#__PURE__*/_interopDefaultCompat(ci);
25
25
 
26
26
  function createVcr() {
27
+ let result;
27
28
  return {
28
29
  async run(cassetteName, indexerConfig, range) {
29
30
  const vcrConfig = {
@@ -47,6 +48,9 @@ function createVcr() {
47
48
  ...indexerConfig.plugins ?? []
48
49
  ];
49
50
  const indexer = index.createIndexer(indexerConfig);
51
+ indexer.hooks.hook("run:after", () => {
52
+ result = context.useIndexerContext();
53
+ });
50
54
  if (!vcr_index.isCassetteAvailable(vcrConfig, cassetteName)) {
51
55
  if (ci__default.isCI) {
52
56
  throw new Error("Cannot record cassette in CI");
@@ -59,6 +63,7 @@ function createVcr() {
59
63
  } else {
60
64
  await vcr_index.replay(vcrConfig, indexer, cassetteName);
61
65
  }
66
+ return result;
62
67
  }
63
68
  };
64
69
  }
@@ -2,11 +2,12 @@ import { I as IndexerWithStreamConfig } from '../shared/indexer.fedcd831.cjs';
2
2
  import '@apibara/protocol';
3
3
  import 'hookable';
4
4
 
5
+ type VcrResult = Record<string, unknown>;
5
6
  declare function createVcr(): {
6
7
  run<TFilter, TBlock>(cassetteName: string, indexerConfig: IndexerWithStreamConfig<TFilter, TBlock>, range: {
7
8
  fromBlock: bigint;
8
9
  toBlock: bigint;
9
- }): Promise<void>;
10
+ }): Promise<VcrResult>;
10
11
  };
11
12
 
12
- export { createVcr };
13
+ export { type VcrResult, createVcr };
@@ -2,11 +2,12 @@ import { I as IndexerWithStreamConfig } from '../shared/indexer.fedcd831.mjs';
2
2
  import '@apibara/protocol';
3
3
  import 'hookable';
4
4
 
5
+ type VcrResult = Record<string, unknown>;
5
6
  declare function createVcr(): {
6
7
  run<TFilter, TBlock>(cassetteName: string, indexerConfig: IndexerWithStreamConfig<TFilter, TBlock>, range: {
7
8
  fromBlock: bigint;
8
9
  toBlock: bigint;
9
- }): Promise<void>;
10
+ }): Promise<VcrResult>;
10
11
  };
11
12
 
12
- export { createVcr };
13
+ export { type VcrResult, createVcr };
@@ -2,11 +2,12 @@ import { I as IndexerWithStreamConfig } from '../shared/indexer.fedcd831.js';
2
2
  import '@apibara/protocol';
3
3
  import 'hookable';
4
4
 
5
+ type VcrResult = Record<string, unknown>;
5
6
  declare function createVcr(): {
6
7
  run<TFilter, TBlock>(cassetteName: string, indexerConfig: IndexerWithStreamConfig<TFilter, TBlock>, range: {
7
8
  fromBlock: bigint;
8
9
  toBlock: bigint;
9
- }): Promise<void>;
10
+ }): Promise<VcrResult>;
10
11
  };
11
12
 
12
- export { createVcr };
13
+ export { type VcrResult, createVcr };
@@ -1,15 +1,15 @@
1
1
  import { createClient } from '@apibara/protocol';
2
2
  import ci from 'ci-info';
3
+ import { u as useIndexerContext } from '../shared/indexer.a55ad619.mjs';
3
4
  import { createIndexer } from '../index.mjs';
4
5
  import { internalContext } from '../internal/plugins.mjs';
5
6
  import { l as logger } from '../shared/indexer.ff25c953.mjs';
6
7
  import { isCassetteAvailable, record, replay } from '../vcr/index.mjs';
8
+ import 'node:async_hooks';
9
+ import 'unctx';
7
10
  import 'consola';
8
11
  import 'hookable';
9
12
  import 'node:assert';
10
- import '../shared/indexer.a55ad619.mjs';
11
- import 'node:async_hooks';
12
- import 'unctx';
13
13
  import '@opentelemetry/api';
14
14
  import '../shared/indexer.9b21ddd2.mjs';
15
15
  import 'node:fs/promises';
@@ -18,6 +18,7 @@ import 'node:fs';
18
18
  import '@apibara/protocol/testing';
19
19
 
20
20
  function createVcr() {
21
+ let result;
21
22
  return {
22
23
  async run(cassetteName, indexerConfig, range) {
23
24
  const vcrConfig = {
@@ -41,6 +42,9 @@ function createVcr() {
41
42
  ...indexerConfig.plugins ?? []
42
43
  ];
43
44
  const indexer = createIndexer(indexerConfig);
45
+ indexer.hooks.hook("run:after", () => {
46
+ result = useIndexerContext();
47
+ });
44
48
  if (!isCassetteAvailable(vcrConfig, cassetteName)) {
45
49
  if (ci.isCI) {
46
50
  throw new Error("Cannot record cassette in CI");
@@ -53,6 +57,7 @@ function createVcr() {
53
57
  } else {
54
58
  await replay(vcrConfig, indexer, cassetteName);
55
59
  }
60
+ return result;
56
61
  }
57
62
  };
58
63
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apibara/indexer",
3
- "version": "2.1.0-beta.1",
3
+ "version": "2.1.0-beta.11",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",
@@ -70,7 +70,7 @@
70
70
  "vitest": "^1.6.0"
71
71
  },
72
72
  "dependencies": {
73
- "@apibara/protocol": "2.1.0-beta.1",
73
+ "@apibara/protocol": "2.1.0-beta.11",
74
74
  "@opentelemetry/api": "^1.9.0",
75
75
  "ci-info": "^4.1.0",
76
76
  "consola": "^3.2.3",
package/src/indexer.ts CHANGED
@@ -225,9 +225,13 @@ export async function run<TFilter, TBlock>(
225
225
  if (indexer.options.startingCursor) {
226
226
  startingCursor = indexer.options.startingCursor;
227
227
  } else if (indexer.options.startingBlock !== undefined) {
228
- startingCursor = {
229
- orderKey: indexer.options.startingBlock,
230
- };
228
+ if (indexer.options.startingBlock === 0n) {
229
+ startingCursor = undefined;
230
+ } else if (indexer.options.startingBlock > 0n) {
231
+ startingCursor = {
232
+ orderKey: indexer.options.startingBlock - 1n,
233
+ };
234
+ }
231
235
  }
232
236
 
233
237
  // if factory mode we add a empty filter at the end of the filter array.
@@ -5,10 +5,9 @@ import {
5
5
  MockStream,
6
6
  type MockStreamResponse,
7
7
  } from "@apibara/protocol/testing";
8
-
9
8
  import { useIndexerContext } from "../context";
10
9
  import { type IndexerConfig, createIndexer, defineIndexer } from "../indexer";
11
- import { defineIndexerPlugin } from "../plugins";
10
+ import { defineIndexerPlugin, logger } from "../plugins";
12
11
  import { type InternalContext, internalContext } from "./plugins";
13
12
 
14
13
  export type MockMessagesOptions = {
@@ -82,6 +81,7 @@ export function getMockIndexer(params?: MockIndexerParams) {
82
81
  filter: {},
83
82
  async transform() {},
84
83
  plugins: [
84
+ logger(),
85
85
  internalContext(
86
86
  contextParams ??
87
87
  ({
@@ -1,5 +1,6 @@
1
1
  import { createClient } from "@apibara/protocol";
2
2
  import ci from "ci-info";
3
+ import { useIndexerContext } from "../context";
3
4
  import { type IndexerWithStreamConfig, createIndexer } from "../indexer";
4
5
  import { type InternalContext, internalContext } from "../plugins/context";
5
6
  import { logger } from "../plugins/logger";
@@ -8,7 +9,11 @@ import { isCassetteAvailable } from "../vcr/helper";
8
9
  import { record } from "../vcr/record";
9
10
  import { replay } from "../vcr/replay";
10
11
 
12
+ export type VcrResult = Record<string, unknown>;
13
+
11
14
  export function createVcr() {
15
+ let result: VcrResult;
16
+
12
17
  return {
13
18
  async run<TFilter, TBlock>(
14
19
  cassetteName: string,
@@ -40,6 +45,10 @@ export function createVcr() {
40
45
 
41
46
  const indexer = createIndexer(indexerConfig);
42
47
 
48
+ indexer.hooks.hook("run:after", () => {
49
+ result = useIndexerContext();
50
+ });
51
+
43
52
  if (!isCassetteAvailable(vcrConfig, cassetteName)) {
44
53
  if (ci.isCI) {
45
54
  throw new Error("Cannot record cassette in CI");
@@ -53,6 +62,8 @@ export function createVcr() {
53
62
  } else {
54
63
  await replay(vcrConfig, indexer, cassetteName);
55
64
  }
65
+
66
+ return result;
56
67
  },
57
68
  };
58
69
  }