apibara 2.1.0-beta.21 → 2.1.0-beta.23

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.
@@ -4,7 +4,9 @@ import { runtimeDir } from 'apibara/runtime/meta';
4
4
  import { defineCommand } from 'citty';
5
5
  import { colors } from 'consola/utils';
6
6
  import { resolve, join } from 'pathe';
7
+ import { b as blueBright, g as gray } from '../shared/apibara.730bb1e4.mjs';
7
8
  import { c as commonArgs, a as checkForUnknownArgs } from '../shared/apibara.63c9a277.mjs';
9
+ import 'picocolors';
8
10
  import 'consola';
9
11
 
10
12
  const hmrKeyRe = /^runtimeConfig\./;
@@ -35,6 +37,9 @@ const dev = defineCommand({
35
37
  if (args["always-reindex"]) {
36
38
  process.env.APIBARA_ALWAYS_REINDEX = "true";
37
39
  }
40
+ const selectedIndexers = new Set(
41
+ args.indexers?.split(",").map((i) => i.trim()).sort() ?? []
42
+ );
38
43
  let apibara;
39
44
  let childProcess;
40
45
  const reload = async () => {
@@ -87,6 +92,10 @@ const dev = defineCommand({
87
92
  childProcess = void 0;
88
93
  } else {
89
94
  apibara.logger.info("Starting indexers");
95
+ const indexersText = apibara.indexers.map(
96
+ (i) => selectedIndexers.has(i.name) || selectedIndexers.size === 0 ? blueBright(i.name) : gray(i.name)
97
+ ).join(", ");
98
+ apibara.logger.info("Indexers:", indexersText);
90
99
  }
91
100
  const childArgs = [
92
101
  resolve(apibara.options.outputDir || "./.apibara/build", "dev.mjs"),
@@ -1,24 +1,11 @@
1
1
  import path, { basename } from 'node:path';
2
2
  import consola$1, { consola } from 'consola';
3
3
  import prompts from 'prompts';
4
- import colors from 'picocolors';
4
+ import { a as blue, y as yellow, c as green, r as red, d as cyan, m as magenta, e as reset } from '../shared/apibara.730bb1e4.mjs';
5
5
  import fs from 'node:fs';
6
6
  import { Project, SyntaxKind } from 'ts-morph';
7
7
  import * as prettier from 'prettier';
8
-
9
- const {
10
- blue,
11
- blueBright,
12
- cyan,
13
- gray,
14
- green,
15
- greenBright,
16
- magenta,
17
- red,
18
- redBright,
19
- reset,
20
- yellow
21
- } = colors;
8
+ import 'picocolors';
22
9
 
23
10
  const chains = [
24
11
  {
@@ -449,10 +436,9 @@ ${storage === "postgres" ? `import * as schema from "../lib/schema";` : ""}
449
436
 
450
437
  export default function (runtimeConfig${language === "typescript" ? ": ApibaraRuntimeConfig" : ""}) {
451
438
  const indexerId = "${indexerId}";
452
- const { startingBlock, streamUrl${storage === "postgres" ? ", postgresConnectionString" : ""} } = runtimeConfig[indexerId];
439
+ const { startingBlock, streamUrl } = runtimeConfig[indexerId];
453
440
  ${storage === "postgres" ? `const db = drizzle({
454
441
  schema,
455
- connectionString: postgresConnectionString,
456
442
  });` : ""}
457
443
 
458
444
  return defineIndexer(${chain === "ethereum" ? "EvmStream" : chain === "beaconchain" ? "BeaconChainStream" : chain === "starknet" ? "StarknetStream" : ""})({
@@ -546,8 +532,8 @@ async function updateApibaraConfigFile({
546
532
  );
547
533
  const runtimeConfigString = `{
548
534
  startingBlock: 0,
549
- streamUrl: "${dnaUrl ?? getDnaUrl(chain, network)}"${storage === "postgres" ? `,
550
- postgresConnectionString: process.env["POSTGRES_CONNECTION_STRING"] ?? "memory://${indexerId}"` : ""}}`;
535
+ streamUrl: "${dnaUrl ?? getDnaUrl(chain, network)}"
536
+ }`;
551
537
  const project = new Project();
552
538
  const sourceFile = project.addSourceFileAtPath(pathToConfig);
553
539
  const defineConfigCall = sourceFile.getFirstDescendantByKind(
@@ -1,5 +1,6 @@
1
1
  import { runWithReconnect } from "@apibara/indexer";
2
2
  import { defineCommand, runMain } from "citty";
3
+ import { blueBright } from "picocolors";
3
4
  import {
4
5
  availableIndexers,
5
6
  createAuthenticatedClient,
@@ -35,7 +36,7 @@ const startCommand = defineCommand({
35
36
  }
36
37
  await Promise.all(
37
38
  selectedIndexers.map(async (indexer) => {
38
- const indexerInstance = createIndexer(indexer, preset);
39
+ const { indexer: indexerInstance, logger } = createIndexer(indexer, preset) ?? {};
39
40
  if (!indexerInstance) {
40
41
  return;
41
42
  }
@@ -43,6 +44,9 @@ const startCommand = defineCommand({
43
44
  indexerInstance.streamConfig,
44
45
  indexerInstance.options.streamUrl
45
46
  );
47
+ if (logger) {
48
+ logger.info(`Indexer ${blueBright(indexer)} started`);
49
+ }
46
50
  await runWithReconnect(client, indexerInstance);
47
51
  })
48
52
  );
@@ -1,4 +1,7 @@
1
1
  import { type CreateClientOptions, type StreamConfig } from "@apibara/protocol";
2
2
  export declare const availableIndexers: any;
3
- export declare function createIndexer(indexerName: string, preset?: string): import("@apibara/indexer").Indexer<unknown, unknown> | undefined;
3
+ export declare function createIndexer(indexerName: string, preset?: string): {
4
+ indexer: import("@apibara/indexer").Indexer<unknown, unknown>;
5
+ logger: any;
6
+ } | undefined;
4
7
  export declare function createAuthenticatedClient(config: StreamConfig<unknown, unknown>, streamUrl: string, options?: CreateClientOptions): import("@apibara/protocol").GrpcClient<unknown, unknown>;
@@ -62,7 +62,10 @@ export function createIndexer(indexerName, preset) {
62
62
  inMemoryPersistence(),
63
63
  ...definition.plugins ?? []
64
64
  ];
65
- return _createIndexer(definition);
65
+ return {
66
+ indexer: _createIndexer(definition),
67
+ logger: consola.create({ reporters: [reporter] })
68
+ };
66
69
  }
67
70
  export function createAuthenticatedClient(config2, streamUrl, options) {
68
71
  const dnaToken = process.env.DNA_TOKEN;
@@ -1,6 +1,7 @@
1
1
  import { runWithReconnect } from "@apibara/indexer";
2
2
  import { defineCommand, runMain } from "citty";
3
3
  import consola from "consola";
4
+ import { blueBright } from "picocolors";
4
5
  import { register } from "#apibara-internal-virtual/instrumentation";
5
6
  import { createAuthenticatedClient, createIndexer } from "./internal/app.mjs";
6
7
  const startCommand = defineCommand({
@@ -21,7 +22,7 @@ const startCommand = defineCommand({
21
22
  },
22
23
  async run({ args }) {
23
24
  const { indexer, preset } = args;
24
- const indexerInstance = createIndexer(indexer, preset);
25
+ const { indexer: indexerInstance, logger } = createIndexer(indexer, preset) ?? {};
25
26
  if (!indexerInstance) {
26
27
  consola.error(`Specified indexer "${indexer}" but it was not defined`);
27
28
  process.exit(1);
@@ -35,6 +36,9 @@ const startCommand = defineCommand({
35
36
  await register();
36
37
  consola.success("Registered from instrumentation");
37
38
  }
39
+ if (logger) {
40
+ logger.info(`Indexer ${blueBright(indexer)} started`);
41
+ }
38
42
  await runWithReconnect(client, indexerInstance);
39
43
  }
40
44
  });
@@ -0,0 +1,17 @@
1
+ import colors from 'picocolors';
2
+
3
+ const {
4
+ blue,
5
+ blueBright,
6
+ cyan,
7
+ gray,
8
+ green,
9
+ greenBright,
10
+ magenta,
11
+ red,
12
+ redBright,
13
+ reset,
14
+ yellow
15
+ } = colors;
16
+
17
+ export { blue as a, blueBright as b, green as c, cyan as d, reset as e, gray as g, magenta as m, red as r, yellow as y };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apibara",
3
- "version": "2.1.0-beta.21",
3
+ "version": "2.1.0-beta.23",
4
4
  "type": "module",
5
5
  "main": "./dist/core/index.mjs",
6
6
  "exports": {
@@ -78,7 +78,7 @@
78
78
  "playground:add": "pnpm playground add --dir playground"
79
79
  },
80
80
  "devDependencies": {
81
- "@apibara/starknet": "2.1.0-beta.21",
81
+ "@apibara/starknet": "2.1.0-beta.23",
82
82
  "@types/fs-extra": "^11.0.4",
83
83
  "@types/node": "^20.14.0",
84
84
  "@types/prompts": "^2.4.9",
@@ -89,8 +89,8 @@
89
89
  "vitest": "^1.6.0"
90
90
  },
91
91
  "dependencies": {
92
- "@apibara/indexer": "2.1.0-beta.21",
93
- "@apibara/protocol": "2.1.0-beta.21",
92
+ "@apibara/indexer": "2.1.0-beta.23",
93
+ "@apibara/protocol": "2.1.0-beta.23",
94
94
  "@rollup/plugin-replace": "^6.0.2",
95
95
  "@rollup/plugin-virtual": "^3.0.2",
96
96
  "c12": "^1.11.1",
@@ -5,6 +5,7 @@ import type { Apibara } from "apibara/types";
5
5
  import { defineCommand } from "citty";
6
6
  import { colors } from "consola/utils";
7
7
  import { join, resolve } from "pathe";
8
+ import { blueBright, gray } from "../../create/colors";
8
9
  import { checkForUnknownArgs, commonArgs } from "../common";
9
10
 
10
11
  // Hot module reloading key regex
@@ -42,6 +43,13 @@ export default defineCommand({
42
43
  process.env.APIBARA_ALWAYS_REINDEX = "true";
43
44
  }
44
45
 
46
+ const selectedIndexers = new Set(
47
+ args.indexers
48
+ ?.split(",")
49
+ .map((i) => i.trim())
50
+ .sort() ?? [],
51
+ );
52
+
45
53
  let apibara: Apibara;
46
54
  let childProcess: ChildProcess | undefined;
47
55
 
@@ -107,6 +115,15 @@ export default defineCommand({
107
115
  childProcess = undefined;
108
116
  } else {
109
117
  apibara.logger.info("Starting indexers");
118
+
119
+ const indexersText = apibara.indexers
120
+ .map((i) =>
121
+ selectedIndexers.has(i.name) || selectedIndexers.size === 0
122
+ ? blueBright(i.name)
123
+ : gray(i.name),
124
+ )
125
+ .join(", ");
126
+ apibara.logger.info("Indexers:", indexersText);
110
127
  }
111
128
 
112
129
  const childArgs = [
@@ -89,12 +89,11 @@ ${storage === "postgres" ? `import * as schema from "../lib/schema";` : ""}
89
89
 
90
90
  export default function (runtimeConfig${language === "typescript" ? ": ApibaraRuntimeConfig" : ""}) {
91
91
  const indexerId = "${indexerId}";
92
- const { startingBlock, streamUrl${storage === "postgres" ? ", postgresConnectionString" : ""} } = runtimeConfig[indexerId];
92
+ const { startingBlock, streamUrl } = runtimeConfig[indexerId];
93
93
  ${
94
94
  storage === "postgres"
95
95
  ? `const db = drizzle({
96
96
  schema,
97
- connectionString: postgresConnectionString,
98
97
  });`
99
98
  : ""
100
99
  }
@@ -225,12 +224,8 @@ export async function updateApibaraConfigFile({
225
224
 
226
225
  const runtimeConfigString = `{
227
226
  startingBlock: 0,
228
- streamUrl: "${dnaUrl ?? getDnaUrl(chain, network)}"${
229
- storage === "postgres"
230
- ? `,
231
- postgresConnectionString: process.env["POSTGRES_CONNECTION_STRING"] ?? "memory://${indexerId}"`
232
- : ""
233
- }}`;
227
+ streamUrl: "${dnaUrl ?? getDnaUrl(chain, network)}"
228
+ }`;
234
229
 
235
230
  const project = new Project();
236
231
  const sourceFile = project.addSourceFileAtPath(pathToConfig);
@@ -1,5 +1,6 @@
1
1
  import { runWithReconnect } from "@apibara/indexer";
2
2
  import { defineCommand, runMain } from "citty";
3
+ import { blueBright } from "picocolors";
3
4
  import {
4
5
  availableIndexers,
5
6
  createAuthenticatedClient,
@@ -39,7 +40,8 @@ const startCommand = defineCommand({
39
40
 
40
41
  await Promise.all(
41
42
  selectedIndexers.map(async (indexer) => {
42
- const indexerInstance = createIndexer(indexer, preset);
43
+ const { indexer: indexerInstance, logger } =
44
+ createIndexer(indexer, preset) ?? {};
43
45
  if (!indexerInstance) {
44
46
  return;
45
47
  }
@@ -49,6 +51,10 @@ const startCommand = defineCommand({
49
51
  indexerInstance.options.streamUrl,
50
52
  );
51
53
 
54
+ if (logger) {
55
+ logger.info(`Indexer ${blueBright(indexer)} started`);
56
+ }
57
+
52
58
  await runWithReconnect(client, indexerInstance);
53
59
  }),
54
60
  );
@@ -88,7 +88,10 @@ export function createIndexer(indexerName: string, preset?: string) {
88
88
  ...(definition.plugins ?? []),
89
89
  ];
90
90
 
91
- return _createIndexer(definition);
91
+ return {
92
+ indexer: _createIndexer(definition),
93
+ logger: consola.create({ reporters: [reporter] }),
94
+ };
92
95
  }
93
96
 
94
97
  export function createAuthenticatedClient(
@@ -1,6 +1,7 @@
1
1
  import { runWithReconnect } from "@apibara/indexer";
2
2
  import { defineCommand, runMain } from "citty";
3
3
  import consola from "consola";
4
+ import { blueBright } from "picocolors";
4
5
  import { register } from "#apibara-internal-virtual/instrumentation";
5
6
  import { createAuthenticatedClient, createIndexer } from "./internal/app";
6
7
 
@@ -23,7 +24,8 @@ const startCommand = defineCommand({
23
24
  async run({ args }) {
24
25
  const { indexer, preset } = args;
25
26
 
26
- const indexerInstance = createIndexer(indexer, preset);
27
+ const { indexer: indexerInstance, logger } =
28
+ createIndexer(indexer, preset) ?? {};
27
29
  if (!indexerInstance) {
28
30
  consola.error(`Specified indexer "${indexer}" but it was not defined`);
29
31
  process.exit(1);
@@ -40,6 +42,10 @@ const startCommand = defineCommand({
40
42
  consola.success("Registered from instrumentation");
41
43
  }
42
44
 
45
+ if (logger) {
46
+ logger.info(`Indexer ${blueBright(indexer)} started`);
47
+ }
48
+
43
49
  await runWithReconnect(client, indexerInstance);
44
50
  },
45
51
  });