@apibara/indexer 2.0.0-beta.35 → 2.0.0-beta.36

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
@@ -110,10 +110,18 @@ async function run(client, indexer, runOptions = {}) {
110
110
  const middleware = await registerMiddleware(indexer);
111
111
  await indexer.hooks.callHook("run:before");
112
112
  const isFactoryMode = indexer.options.factory !== void 0;
113
+ let startingCursor;
114
+ if (indexer.options.startingCursor) {
115
+ startingCursor = indexer.options.startingCursor;
116
+ } else if (indexer.options.startingBlock !== void 0) {
117
+ startingCursor = {
118
+ orderKey: indexer.options.startingBlock
119
+ };
120
+ }
113
121
  const request = indexer.streamConfig.Request.make({
114
122
  filter: isFactoryMode ? [indexer.options.filter, {}] : [indexer.options.filter],
115
123
  finality: indexer.options.finality,
116
- startingCursor: indexer.options.startingCursor
124
+ startingCursor
117
125
  });
118
126
  const options = {};
119
127
  await indexer.hooks.callHook("connect:before", { request, options });
package/dist/index.d.cts CHANGED
@@ -1,3 +1,3 @@
1
- export { c as Indexer, b as IndexerConfig, e as IndexerHooks, I as IndexerWithStreamConfig, R as ReconnectOptions, h as RunOptions, U as UseMiddlewareFunction, g as createIndexer, f as defineIndexer, i as run, r as runWithReconnect, u as useIndexerContext } from './shared/indexer.8939ecc8.cjs';
1
+ export { c as Indexer, b as IndexerConfig, e as IndexerHooks, f as IndexerStartingCursor, I as IndexerWithStreamConfig, R as ReconnectOptions, i as RunOptions, U as UseMiddlewareFunction, h as createIndexer, g as defineIndexer, j as run, r as runWithReconnect, u as useIndexerContext } from './shared/indexer.0a872656.cjs';
2
2
  import '@apibara/protocol';
3
3
  import 'hookable';
package/dist/index.d.mts CHANGED
@@ -1,3 +1,3 @@
1
- export { c as Indexer, b as IndexerConfig, e as IndexerHooks, I as IndexerWithStreamConfig, R as ReconnectOptions, h as RunOptions, U as UseMiddlewareFunction, g as createIndexer, f as defineIndexer, i as run, r as runWithReconnect, u as useIndexerContext } from './shared/indexer.8939ecc8.mjs';
1
+ export { c as Indexer, b as IndexerConfig, e as IndexerHooks, f as IndexerStartingCursor, I as IndexerWithStreamConfig, R as ReconnectOptions, i as RunOptions, U as UseMiddlewareFunction, h as createIndexer, g as defineIndexer, j as run, r as runWithReconnect, u as useIndexerContext } from './shared/indexer.0a872656.mjs';
2
2
  import '@apibara/protocol';
3
3
  import 'hookable';
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { c as Indexer, b as IndexerConfig, e as IndexerHooks, I as IndexerWithStreamConfig, R as ReconnectOptions, h as RunOptions, U as UseMiddlewareFunction, g as createIndexer, f as defineIndexer, i as run, r as runWithReconnect, u as useIndexerContext } from './shared/indexer.8939ecc8.js';
1
+ export { c as Indexer, b as IndexerConfig, e as IndexerHooks, f as IndexerStartingCursor, I as IndexerWithStreamConfig, R as ReconnectOptions, i as RunOptions, U as UseMiddlewareFunction, h as createIndexer, g as defineIndexer, j as run, r as runWithReconnect, u as useIndexerContext } from './shared/indexer.0a872656.js';
2
2
  import '@apibara/protocol';
3
3
  import 'hookable';
package/dist/index.mjs CHANGED
@@ -103,10 +103,18 @@ async function run(client, indexer, runOptions = {}) {
103
103
  const middleware = await registerMiddleware(indexer);
104
104
  await indexer.hooks.callHook("run:before");
105
105
  const isFactoryMode = indexer.options.factory !== void 0;
106
+ let startingCursor;
107
+ if (indexer.options.startingCursor) {
108
+ startingCursor = indexer.options.startingCursor;
109
+ } else if (indexer.options.startingBlock !== void 0) {
110
+ startingCursor = {
111
+ orderKey: indexer.options.startingBlock
112
+ };
113
+ }
106
114
  const request = indexer.streamConfig.Request.make({
107
115
  filter: isFactoryMode ? [indexer.options.filter, {}] : [indexer.options.filter],
108
116
  finality: indexer.options.finality,
109
- startingCursor: indexer.options.startingCursor
117
+ startingCursor
110
118
  });
111
119
  const options = {};
112
120
  await indexer.hooks.callHook("connect:before", { request, options });
@@ -1,4 +1,4 @@
1
- import { a as IndexerPlugin, b as IndexerConfig, c as Indexer } from '../shared/indexer.8939ecc8.cjs';
1
+ import { a as IndexerPlugin, b as IndexerConfig, c as Indexer } from '../shared/indexer.0a872656.cjs';
2
2
  import { MockStreamResponse, MockFilter, MockBlock } from '@apibara/protocol/testing';
3
3
  import '@apibara/protocol';
4
4
  import 'hookable';
@@ -1,4 +1,4 @@
1
- import { a as IndexerPlugin, b as IndexerConfig, c as Indexer } from '../shared/indexer.8939ecc8.mjs';
1
+ import { a as IndexerPlugin, b as IndexerConfig, c as Indexer } from '../shared/indexer.0a872656.mjs';
2
2
  import { MockStreamResponse, MockFilter, MockBlock } from '@apibara/protocol/testing';
3
3
  import '@apibara/protocol';
4
4
  import 'hookable';
@@ -1,4 +1,4 @@
1
- import { a as IndexerPlugin, b as IndexerConfig, c as Indexer } from '../shared/indexer.8939ecc8.js';
1
+ import { a as IndexerPlugin, b as IndexerConfig, c as Indexer } from '../shared/indexer.0a872656.js';
2
2
  import { MockStreamResponse, MockFilter, MockBlock } from '@apibara/protocol/testing';
3
3
  import '@apibara/protocol';
4
4
  import 'hookable';
@@ -1,5 +1,5 @@
1
- import { a as IndexerPlugin } from '../shared/indexer.8939ecc8.cjs';
2
- export { d as defineIndexerPlugin } from '../shared/indexer.8939ecc8.cjs';
1
+ import { a as IndexerPlugin } from '../shared/indexer.0a872656.cjs';
2
+ export { d as defineIndexerPlugin } from '../shared/indexer.0a872656.cjs';
3
3
  import { ConsolaReporter, ConsolaInstance } from 'consola';
4
4
  export { ConsolaInstance, ConsolaReporter } from 'consola';
5
5
  import '@apibara/protocol';
@@ -1,5 +1,5 @@
1
- import { a as IndexerPlugin } from '../shared/indexer.8939ecc8.mjs';
2
- export { d as defineIndexerPlugin } from '../shared/indexer.8939ecc8.mjs';
1
+ import { a as IndexerPlugin } from '../shared/indexer.0a872656.mjs';
2
+ export { d as defineIndexerPlugin } from '../shared/indexer.0a872656.mjs';
3
3
  import { ConsolaReporter, ConsolaInstance } from 'consola';
4
4
  export { ConsolaInstance, ConsolaReporter } from 'consola';
5
5
  import '@apibara/protocol';
@@ -1,5 +1,5 @@
1
- import { a as IndexerPlugin } from '../shared/indexer.8939ecc8.js';
2
- export { d as defineIndexerPlugin } from '../shared/indexer.8939ecc8.js';
1
+ import { a as IndexerPlugin } from '../shared/indexer.0a872656.js';
2
+ export { d as defineIndexerPlugin } from '../shared/indexer.0a872656.js';
3
3
  import { ConsolaReporter, ConsolaInstance } from 'consola';
4
4
  export { ConsolaInstance, ConsolaReporter } from 'consola';
5
5
  import '@apibara/protocol';
@@ -45,11 +45,20 @@ interface IndexerHooks<TFilter, TBlock> {
45
45
  message: SystemMessage;
46
46
  }) => void;
47
47
  }
48
- interface IndexerConfig<TFilter, TBlock> {
48
+ type IndexerStartingCursor = {
49
+ startingCursor?: never;
50
+ startingBlock: bigint;
51
+ } | {
52
+ startingCursor: Cursor;
53
+ startingBlock?: never;
54
+ } | {
55
+ startingCursor?: never;
56
+ startingBlock?: never;
57
+ };
58
+ type IndexerConfig<TFilter, TBlock> = {
49
59
  streamUrl: string;
50
60
  filter: TFilter;
51
61
  finality?: DataFinality;
52
- startingCursor?: Cursor;
53
62
  factory?: ({ block, context, }: {
54
63
  block: TBlock;
55
64
  context: IndexerContext;
@@ -66,10 +75,10 @@ interface IndexerConfig<TFilter, TBlock> {
66
75
  hooks?: NestedHooks<IndexerHooks<TFilter, TBlock>>;
67
76
  plugins?: ReadonlyArray<IndexerPlugin<TFilter, TBlock>>;
68
77
  debug?: boolean;
69
- }
70
- interface IndexerWithStreamConfig<TFilter, TBlock> extends IndexerConfig<TFilter, TBlock> {
78
+ } & IndexerStartingCursor;
79
+ type IndexerWithStreamConfig<TFilter, TBlock> = IndexerConfig<TFilter, TBlock> & {
71
80
  streamConfig: StreamConfig<TFilter, TBlock>;
72
- }
81
+ };
73
82
  declare function defineIndexer<TFilter, TBlock>(streamConfig: StreamConfig<TFilter, TBlock>): (config: IndexerConfig<TFilter, TBlock>) => IndexerWithStreamConfig<TFilter, TBlock>;
74
83
  interface Indexer<TFilter, TBlock> {
75
84
  streamConfig: StreamConfig<TFilter, TBlock>;
@@ -88,4 +97,4 @@ interface RunOptions {
88
97
  }
89
98
  declare function run<TFilter, TBlock>(client: Client<TFilter, TBlock>, indexer: Indexer<TFilter, TBlock>, runOptions?: RunOptions): Promise<void>;
90
99
 
91
- export { type IndexerWithStreamConfig as I, type ReconnectOptions as R, type UseMiddlewareFunction as U, type IndexerPlugin as a, type IndexerConfig as b, type Indexer as c, defineIndexerPlugin as d, type IndexerHooks as e, defineIndexer as f, createIndexer as g, type RunOptions as h, run as i, runWithReconnect as r, useIndexerContext as u };
100
+ export { type IndexerWithStreamConfig as I, type ReconnectOptions as R, type UseMiddlewareFunction as U, type IndexerPlugin as a, type IndexerConfig as b, type Indexer as c, defineIndexerPlugin as d, type IndexerHooks as e, type IndexerStartingCursor as f, defineIndexer as g, createIndexer as h, type RunOptions as i, run as j, runWithReconnect as r, useIndexerContext as u };
@@ -45,11 +45,20 @@ interface IndexerHooks<TFilter, TBlock> {
45
45
  message: SystemMessage;
46
46
  }) => void;
47
47
  }
48
- interface IndexerConfig<TFilter, TBlock> {
48
+ type IndexerStartingCursor = {
49
+ startingCursor?: never;
50
+ startingBlock: bigint;
51
+ } | {
52
+ startingCursor: Cursor;
53
+ startingBlock?: never;
54
+ } | {
55
+ startingCursor?: never;
56
+ startingBlock?: never;
57
+ };
58
+ type IndexerConfig<TFilter, TBlock> = {
49
59
  streamUrl: string;
50
60
  filter: TFilter;
51
61
  finality?: DataFinality;
52
- startingCursor?: Cursor;
53
62
  factory?: ({ block, context, }: {
54
63
  block: TBlock;
55
64
  context: IndexerContext;
@@ -66,10 +75,10 @@ interface IndexerConfig<TFilter, TBlock> {
66
75
  hooks?: NestedHooks<IndexerHooks<TFilter, TBlock>>;
67
76
  plugins?: ReadonlyArray<IndexerPlugin<TFilter, TBlock>>;
68
77
  debug?: boolean;
69
- }
70
- interface IndexerWithStreamConfig<TFilter, TBlock> extends IndexerConfig<TFilter, TBlock> {
78
+ } & IndexerStartingCursor;
79
+ type IndexerWithStreamConfig<TFilter, TBlock> = IndexerConfig<TFilter, TBlock> & {
71
80
  streamConfig: StreamConfig<TFilter, TBlock>;
72
- }
81
+ };
73
82
  declare function defineIndexer<TFilter, TBlock>(streamConfig: StreamConfig<TFilter, TBlock>): (config: IndexerConfig<TFilter, TBlock>) => IndexerWithStreamConfig<TFilter, TBlock>;
74
83
  interface Indexer<TFilter, TBlock> {
75
84
  streamConfig: StreamConfig<TFilter, TBlock>;
@@ -88,4 +97,4 @@ interface RunOptions {
88
97
  }
89
98
  declare function run<TFilter, TBlock>(client: Client<TFilter, TBlock>, indexer: Indexer<TFilter, TBlock>, runOptions?: RunOptions): Promise<void>;
90
99
 
91
- export { type IndexerWithStreamConfig as I, type ReconnectOptions as R, type UseMiddlewareFunction as U, type IndexerPlugin as a, type IndexerConfig as b, type Indexer as c, defineIndexerPlugin as d, type IndexerHooks as e, defineIndexer as f, createIndexer as g, type RunOptions as h, run as i, runWithReconnect as r, useIndexerContext as u };
100
+ export { type IndexerWithStreamConfig as I, type ReconnectOptions as R, type UseMiddlewareFunction as U, type IndexerPlugin as a, type IndexerConfig as b, type Indexer as c, defineIndexerPlugin as d, type IndexerHooks as e, type IndexerStartingCursor as f, defineIndexer as g, createIndexer as h, type RunOptions as i, run as j, runWithReconnect as r, useIndexerContext as u };
@@ -45,11 +45,20 @@ interface IndexerHooks<TFilter, TBlock> {
45
45
  message: SystemMessage;
46
46
  }) => void;
47
47
  }
48
- interface IndexerConfig<TFilter, TBlock> {
48
+ type IndexerStartingCursor = {
49
+ startingCursor?: never;
50
+ startingBlock: bigint;
51
+ } | {
52
+ startingCursor: Cursor;
53
+ startingBlock?: never;
54
+ } | {
55
+ startingCursor?: never;
56
+ startingBlock?: never;
57
+ };
58
+ type IndexerConfig<TFilter, TBlock> = {
49
59
  streamUrl: string;
50
60
  filter: TFilter;
51
61
  finality?: DataFinality;
52
- startingCursor?: Cursor;
53
62
  factory?: ({ block, context, }: {
54
63
  block: TBlock;
55
64
  context: IndexerContext;
@@ -66,10 +75,10 @@ interface IndexerConfig<TFilter, TBlock> {
66
75
  hooks?: NestedHooks<IndexerHooks<TFilter, TBlock>>;
67
76
  plugins?: ReadonlyArray<IndexerPlugin<TFilter, TBlock>>;
68
77
  debug?: boolean;
69
- }
70
- interface IndexerWithStreamConfig<TFilter, TBlock> extends IndexerConfig<TFilter, TBlock> {
78
+ } & IndexerStartingCursor;
79
+ type IndexerWithStreamConfig<TFilter, TBlock> = IndexerConfig<TFilter, TBlock> & {
71
80
  streamConfig: StreamConfig<TFilter, TBlock>;
72
- }
81
+ };
73
82
  declare function defineIndexer<TFilter, TBlock>(streamConfig: StreamConfig<TFilter, TBlock>): (config: IndexerConfig<TFilter, TBlock>) => IndexerWithStreamConfig<TFilter, TBlock>;
74
83
  interface Indexer<TFilter, TBlock> {
75
84
  streamConfig: StreamConfig<TFilter, TBlock>;
@@ -88,4 +97,4 @@ interface RunOptions {
88
97
  }
89
98
  declare function run<TFilter, TBlock>(client: Client<TFilter, TBlock>, indexer: Indexer<TFilter, TBlock>, runOptions?: RunOptions): Promise<void>;
90
99
 
91
- export { type IndexerWithStreamConfig as I, type ReconnectOptions as R, type UseMiddlewareFunction as U, type IndexerPlugin as a, type IndexerConfig as b, type Indexer as c, defineIndexerPlugin as d, type IndexerHooks as e, defineIndexer as f, createIndexer as g, type RunOptions as h, run as i, runWithReconnect as r, useIndexerContext as u };
100
+ export { type IndexerWithStreamConfig as I, type ReconnectOptions as R, type UseMiddlewareFunction as U, type IndexerPlugin as a, type IndexerConfig as b, type Indexer as c, defineIndexerPlugin as d, type IndexerHooks as e, type IndexerStartingCursor as f, defineIndexer as g, createIndexer as h, type RunOptions as i, run as j, runWithReconnect as r, useIndexerContext as u };
@@ -1,4 +1,4 @@
1
- import { I as IndexerWithStreamConfig } from '../shared/indexer.8939ecc8.cjs';
1
+ import { I as IndexerWithStreamConfig } from '../shared/indexer.0a872656.cjs';
2
2
  import '@apibara/protocol';
3
3
  import 'hookable';
4
4
 
@@ -1,4 +1,4 @@
1
- import { I as IndexerWithStreamConfig } from '../shared/indexer.8939ecc8.mjs';
1
+ import { I as IndexerWithStreamConfig } from '../shared/indexer.0a872656.mjs';
2
2
  import '@apibara/protocol';
3
3
  import 'hookable';
4
4
 
@@ -1,4 +1,4 @@
1
- import { I as IndexerWithStreamConfig } from '../shared/indexer.8939ecc8.js';
1
+ import { I as IndexerWithStreamConfig } from '../shared/indexer.0a872656.js';
2
2
  import '@apibara/protocol';
3
3
  import 'hookable';
4
4
 
@@ -1,5 +1,5 @@
1
1
  import { Cursor, StreamDataResponse, Client } from '@apibara/protocol';
2
- import { c as Indexer } from '../shared/indexer.8939ecc8.cjs';
2
+ import { c as Indexer } from '../shared/indexer.0a872656.cjs';
3
3
  import 'hookable';
4
4
 
5
5
  type VcrConfig = {
@@ -1,5 +1,5 @@
1
1
  import { Cursor, StreamDataResponse, Client } from '@apibara/protocol';
2
- import { c as Indexer } from '../shared/indexer.8939ecc8.mjs';
2
+ import { c as Indexer } from '../shared/indexer.0a872656.mjs';
3
3
  import 'hookable';
4
4
 
5
5
  type VcrConfig = {
@@ -1,5 +1,5 @@
1
1
  import { Cursor, StreamDataResponse, Client } from '@apibara/protocol';
2
- import { c as Indexer } from '../shared/indexer.8939ecc8.js';
2
+ import { c as Indexer } from '../shared/indexer.0a872656.js';
3
3
  import 'hookable';
4
4
 
5
5
  type VcrConfig = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apibara/indexer",
3
- "version": "2.0.0-beta.35",
3
+ "version": "2.0.0-beta.36",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",
@@ -58,7 +58,7 @@
58
58
  "vitest": "^1.6.0"
59
59
  },
60
60
  "dependencies": {
61
- "@apibara/protocol": "2.0.0-beta.35",
61
+ "@apibara/protocol": "2.0.0-beta.36",
62
62
  "@opentelemetry/api": "^1.9.0",
63
63
  "ci-info": "^4.1.0",
64
64
  "consola": "^3.2.3",
package/src/indexer.ts CHANGED
@@ -63,11 +63,24 @@ export interface IndexerHooks<TFilter, TBlock> {
63
63
  "message:systemMessage": ({ message }: { message: SystemMessage }) => void;
64
64
  }
65
65
 
66
- export interface IndexerConfig<TFilter, TBlock> {
66
+ export type IndexerStartingCursor =
67
+ | {
68
+ startingCursor?: never;
69
+ startingBlock: bigint;
70
+ }
71
+ | {
72
+ startingCursor: Cursor;
73
+ startingBlock?: never;
74
+ }
75
+ | {
76
+ startingCursor?: never;
77
+ startingBlock?: never;
78
+ };
79
+
80
+ export type IndexerConfig<TFilter, TBlock> = {
67
81
  streamUrl: string;
68
82
  filter: TFilter;
69
83
  finality?: DataFinality;
70
- startingCursor?: Cursor;
71
84
  factory?: ({
72
85
  block,
73
86
  context,
@@ -84,12 +97,14 @@ export interface IndexerConfig<TFilter, TBlock> {
84
97
  hooks?: NestedHooks<IndexerHooks<TFilter, TBlock>>;
85
98
  plugins?: ReadonlyArray<IndexerPlugin<TFilter, TBlock>>;
86
99
  debug?: boolean;
87
- }
100
+ } & IndexerStartingCursor;
88
101
 
89
- export interface IndexerWithStreamConfig<TFilter, TBlock>
90
- extends IndexerConfig<TFilter, TBlock> {
102
+ export type IndexerWithStreamConfig<TFilter, TBlock> = IndexerConfig<
103
+ TFilter,
104
+ TBlock
105
+ > & {
91
106
  streamConfig: StreamConfig<TFilter, TBlock>;
92
- }
107
+ };
93
108
 
94
109
  export function defineIndexer<TFilter, TBlock>(
95
110
  streamConfig: StreamConfig<TFilter, TBlock>,
@@ -203,16 +218,25 @@ export async function run<TFilter, TBlock>(
203
218
 
204
219
  await indexer.hooks.callHook("run:before");
205
220
 
206
- // Check if the it's factory mode or not
207
221
  const isFactoryMode = indexer.options.factory !== undefined;
208
222
 
209
- // if factory mode we add a empty filter
223
+ // Give priority to startingCursor over startingBlock.
224
+ let startingCursor: Cursor | undefined;
225
+ if (indexer.options.startingCursor) {
226
+ startingCursor = indexer.options.startingCursor;
227
+ } else if (indexer.options.startingBlock !== undefined) {
228
+ startingCursor = {
229
+ orderKey: indexer.options.startingBlock,
230
+ };
231
+ }
232
+
233
+ // if factory mode we add a empty filter at the end of the filter array.
210
234
  const request = indexer.streamConfig.Request.make({
211
235
  filter: isFactoryMode
212
236
  ? [indexer.options.filter, {} as TFilter]
213
237
  : [indexer.options.filter],
214
238
  finality: indexer.options.finality,
215
- startingCursor: indexer.options.startingCursor,
239
+ startingCursor,
216
240
  });
217
241
 
218
242
  const options: StreamDataOptions = {};
@@ -225,7 +249,6 @@ export async function run<TFilter, TBlock>(
225
249
  mainFilter = request.filter[1];
226
250
  }
227
251
 
228
- // create stream
229
252
  let stream: AsyncIterator<
230
253
  StreamDataResponse<TBlock>,
231
254
  StreamDataResponse<TBlock>