@apibara/indexer 2.1.0-beta.16 → 2.1.0-beta.18

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.
@@ -17,22 +17,29 @@ function generateMockMessages(count = 10, options) {
17
17
  const invalidateAt = options?.invalidate;
18
18
  const finalizeAt = options?.finalize;
19
19
  const messages = [];
20
+ const baseBlockNumber = options?.baseBlockNumber ?? BigInt(5e6);
20
21
  for (let i = 0; i < count; i++) {
22
+ const currentBlockNumber = baseBlockNumber + BigInt(i);
23
+ const uniqueKey = uniqueKeyFromOrderKey(currentBlockNumber);
21
24
  if (invalidateAt && i === invalidateAt.invalidateTriggerIndex) {
25
+ const invalidateToBlock = baseBlockNumber + BigInt(invalidateAt.invalidateFromIndex);
22
26
  messages.push({
23
27
  _tag: "invalidate",
24
28
  invalidate: {
25
29
  cursor: {
26
- orderKey: BigInt(5e6 + invalidateAt.invalidateFromIndex)
30
+ orderKey: invalidateToBlock,
31
+ uniqueKey: options?.uniqueKey ? uniqueKeyFromOrderKey(invalidateToBlock) : void 0
27
32
  }
28
33
  }
29
34
  });
30
35
  } else if (finalizeAt && i === finalizeAt.finalizeTriggerIndex) {
36
+ const fianlizedToBlock = baseBlockNumber + BigInt(finalizeAt.finalizeToIndex);
31
37
  messages.push({
32
38
  _tag: "finalize",
33
39
  finalize: {
34
40
  cursor: {
35
- orderKey: BigInt(5e6 + finalizeAt.finalizeToIndex)
41
+ orderKey: fianlizedToBlock,
42
+ uniqueKey: options?.uniqueKey ? uniqueKeyFromOrderKey(fianlizedToBlock) : void 0
36
43
  }
37
44
  }
38
45
  });
@@ -40,10 +47,13 @@ function generateMockMessages(count = 10, options) {
40
47
  messages.push({
41
48
  _tag: "data",
42
49
  data: {
43
- cursor: { orderKey: BigInt(5e6 + i - 1) },
50
+ cursor: { orderKey: currentBlockNumber - 1n },
44
51
  finality: "accepted",
45
- data: [{ data: `${5e6 + i}` }],
46
- endCursor: { orderKey: BigInt(5e6 + i) },
52
+ data: [{ data: `${baseBlockNumber + BigInt(i)}` }],
53
+ endCursor: {
54
+ orderKey: currentBlockNumber,
55
+ uniqueKey: options?.uniqueKey ? uniqueKey : void 0
56
+ },
47
57
  production: "backfill"
48
58
  }
49
59
  });
@@ -51,6 +61,9 @@ function generateMockMessages(count = 10, options) {
51
61
  }
52
62
  return messages;
53
63
  }
64
+ function uniqueKeyFromOrderKey(orderKey) {
65
+ return `0xff00${orderKey.toString()}`;
66
+ }
54
67
  function getMockIndexer(params) {
55
68
  const { internalContext: contextParams, override } = params ?? {};
56
69
  const { plugins, ...rest } = override ?? {};
@@ -13,6 +13,8 @@ type MockMessagesOptions = {
13
13
  finalizeToIndex: number;
14
14
  finalizeTriggerIndex: number;
15
15
  };
16
+ uniqueKey?: boolean;
17
+ baseBlockNumber?: bigint;
16
18
  };
17
19
  declare function generateMockMessages(count?: number, options?: MockMessagesOptions): MockStreamResponse[];
18
20
  type MockIndexerParams = {
@@ -13,6 +13,8 @@ type MockMessagesOptions = {
13
13
  finalizeToIndex: number;
14
14
  finalizeTriggerIndex: number;
15
15
  };
16
+ uniqueKey?: boolean;
17
+ baseBlockNumber?: bigint;
16
18
  };
17
19
  declare function generateMockMessages(count?: number, options?: MockMessagesOptions): MockStreamResponse[];
18
20
  type MockIndexerParams = {
@@ -13,6 +13,8 @@ type MockMessagesOptions = {
13
13
  finalizeToIndex: number;
14
14
  finalizeTriggerIndex: number;
15
15
  };
16
+ uniqueKey?: boolean;
17
+ baseBlockNumber?: bigint;
16
18
  };
17
19
  declare function generateMockMessages(count?: number, options?: MockMessagesOptions): MockStreamResponse[];
18
20
  type MockIndexerParams = {
@@ -15,22 +15,29 @@ function generateMockMessages(count = 10, options) {
15
15
  const invalidateAt = options?.invalidate;
16
16
  const finalizeAt = options?.finalize;
17
17
  const messages = [];
18
+ const baseBlockNumber = options?.baseBlockNumber ?? BigInt(5e6);
18
19
  for (let i = 0; i < count; i++) {
20
+ const currentBlockNumber = baseBlockNumber + BigInt(i);
21
+ const uniqueKey = uniqueKeyFromOrderKey(currentBlockNumber);
19
22
  if (invalidateAt && i === invalidateAt.invalidateTriggerIndex) {
23
+ const invalidateToBlock = baseBlockNumber + BigInt(invalidateAt.invalidateFromIndex);
20
24
  messages.push({
21
25
  _tag: "invalidate",
22
26
  invalidate: {
23
27
  cursor: {
24
- orderKey: BigInt(5e6 + invalidateAt.invalidateFromIndex)
28
+ orderKey: invalidateToBlock,
29
+ uniqueKey: options?.uniqueKey ? uniqueKeyFromOrderKey(invalidateToBlock) : void 0
25
30
  }
26
31
  }
27
32
  });
28
33
  } else if (finalizeAt && i === finalizeAt.finalizeTriggerIndex) {
34
+ const fianlizedToBlock = baseBlockNumber + BigInt(finalizeAt.finalizeToIndex);
29
35
  messages.push({
30
36
  _tag: "finalize",
31
37
  finalize: {
32
38
  cursor: {
33
- orderKey: BigInt(5e6 + finalizeAt.finalizeToIndex)
39
+ orderKey: fianlizedToBlock,
40
+ uniqueKey: options?.uniqueKey ? uniqueKeyFromOrderKey(fianlizedToBlock) : void 0
34
41
  }
35
42
  }
36
43
  });
@@ -38,10 +45,13 @@ function generateMockMessages(count = 10, options) {
38
45
  messages.push({
39
46
  _tag: "data",
40
47
  data: {
41
- cursor: { orderKey: BigInt(5e6 + i - 1) },
48
+ cursor: { orderKey: currentBlockNumber - 1n },
42
49
  finality: "accepted",
43
- data: [{ data: `${5e6 + i}` }],
44
- endCursor: { orderKey: BigInt(5e6 + i) },
50
+ data: [{ data: `${baseBlockNumber + BigInt(i)}` }],
51
+ endCursor: {
52
+ orderKey: currentBlockNumber,
53
+ uniqueKey: options?.uniqueKey ? uniqueKey : void 0
54
+ },
45
55
  production: "backfill"
46
56
  }
47
57
  });
@@ -49,6 +59,9 @@ function generateMockMessages(count = 10, options) {
49
59
  }
50
60
  return messages;
51
61
  }
62
+ function uniqueKeyFromOrderKey(orderKey) {
63
+ return `0xff00${orderKey.toString()}`;
64
+ }
52
65
  function getMockIndexer(params) {
53
66
  const { internalContext: contextParams, override } = params ?? {};
54
67
  const { plugins, ...rest } = override ?? {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apibara/indexer",
3
- "version": "2.1.0-beta.16",
3
+ "version": "2.1.0-beta.18",
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.16",
73
+ "@apibara/protocol": "2.1.0-beta.18",
74
74
  "@opentelemetry/api": "^1.9.0",
75
75
  "ci-info": "^4.1.0",
76
76
  "consola": "^3.4.2",
@@ -19,6 +19,8 @@ export type MockMessagesOptions = {
19
19
  finalizeToIndex: number;
20
20
  finalizeTriggerIndex: number;
21
21
  };
22
+ uniqueKey?: boolean;
23
+ baseBlockNumber?: bigint;
22
24
  };
23
25
 
24
26
  export function generateMockMessages(
@@ -29,22 +31,36 @@ export function generateMockMessages(
29
31
  const finalizeAt = options?.finalize;
30
32
  const messages: MockStreamResponse[] = [];
31
33
 
34
+ const baseBlockNumber = options?.baseBlockNumber ?? BigInt(5_000_000);
35
+
32
36
  for (let i = 0; i < count; i++) {
37
+ const currentBlockNumber = baseBlockNumber + BigInt(i);
38
+ const uniqueKey = uniqueKeyFromOrderKey(currentBlockNumber);
33
39
  if (invalidateAt && i === invalidateAt.invalidateTriggerIndex) {
40
+ const invalidateToBlock =
41
+ baseBlockNumber + BigInt(invalidateAt.invalidateFromIndex);
34
42
  messages.push({
35
43
  _tag: "invalidate",
36
44
  invalidate: {
37
45
  cursor: {
38
- orderKey: BigInt(5_000_000 + invalidateAt.invalidateFromIndex),
46
+ orderKey: invalidateToBlock,
47
+ uniqueKey: options?.uniqueKey
48
+ ? uniqueKeyFromOrderKey(invalidateToBlock)
49
+ : undefined,
39
50
  },
40
51
  },
41
52
  } as Invalidate);
42
53
  } else if (finalizeAt && i === finalizeAt.finalizeTriggerIndex) {
54
+ const fianlizedToBlock =
55
+ baseBlockNumber + BigInt(finalizeAt.finalizeToIndex);
43
56
  messages.push({
44
57
  _tag: "finalize",
45
58
  finalize: {
46
59
  cursor: {
47
- orderKey: BigInt(5_000_000 + finalizeAt.finalizeToIndex),
60
+ orderKey: fianlizedToBlock,
61
+ uniqueKey: options?.uniqueKey
62
+ ? uniqueKeyFromOrderKey(fianlizedToBlock)
63
+ : undefined,
48
64
  },
49
65
  },
50
66
  } as Finalize);
@@ -52,10 +68,13 @@ export function generateMockMessages(
52
68
  messages.push({
53
69
  _tag: "data",
54
70
  data: {
55
- cursor: { orderKey: BigInt(5_000_000 + i - 1) },
71
+ cursor: { orderKey: currentBlockNumber - 1n },
56
72
  finality: "accepted",
57
- data: [{ data: `${5_000_000 + i}` }],
58
- endCursor: { orderKey: BigInt(5_000_000 + i) },
73
+ data: [{ data: `${baseBlockNumber + BigInt(i)}` }],
74
+ endCursor: {
75
+ orderKey: currentBlockNumber,
76
+ uniqueKey: options?.uniqueKey ? uniqueKey : undefined,
77
+ },
59
78
  production: "backfill",
60
79
  },
61
80
  });
@@ -65,6 +84,10 @@ export function generateMockMessages(
65
84
  return messages;
66
85
  }
67
86
 
87
+ function uniqueKeyFromOrderKey(orderKey: bigint): `0x${string}` {
88
+ return `0xff00${orderKey.toString()}`;
89
+ }
90
+
68
91
  type MockIndexerParams = {
69
92
  internalContext?: InternalContext;
70
93
  override?: Partial<IndexerConfig<MockFilter, MockBlock>>;