apibara 2.0.0-beta.4 → 2.0.0-beta.40

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/chunks/build.mjs +28 -0
  2. package/dist/chunks/dev.mjs +100 -0
  3. package/dist/chunks/prepare.mjs +21 -0
  4. package/dist/chunks/start.mjs +56 -0
  5. package/dist/cli/index.d.mts +5 -0
  6. package/dist/cli/index.d.ts +5 -0
  7. package/dist/cli/index.mjs +19 -0
  8. package/dist/config/index.d.mts +5 -0
  9. package/dist/config/index.d.ts +5 -0
  10. package/dist/config/index.mjs +5 -0
  11. package/dist/core/index.d.mts +11 -0
  12. package/dist/core/index.d.ts +11 -0
  13. package/dist/core/index.mjs +310 -0
  14. package/dist/hooks/index.d.mts +5 -0
  15. package/dist/hooks/index.d.ts +5 -0
  16. package/dist/hooks/index.mjs +5 -0
  17. package/dist/rollup/index.d.mts +5 -0
  18. package/dist/rollup/index.d.ts +5 -0
  19. package/dist/rollup/index.mjs +150 -0
  20. package/dist/runtime/dev.d.ts +3 -0
  21. package/dist/runtime/dev.mjs +55 -0
  22. package/dist/runtime/index.d.ts +2 -0
  23. package/dist/runtime/index.mjs +2 -0
  24. package/dist/runtime/internal/app.d.ts +2 -0
  25. package/dist/runtime/internal/app.mjs +56 -0
  26. package/dist/runtime/internal/logger.d.ts +14 -0
  27. package/dist/runtime/internal/logger.mjs +45 -0
  28. package/dist/runtime/start.d.ts +3 -0
  29. package/dist/runtime/start.mjs +41 -0
  30. package/dist/shared/apibara.1b515d04.mjs +8 -0
  31. package/dist/types/index.d.mts +90 -0
  32. package/dist/types/index.d.ts +90 -0
  33. package/dist/types/index.mjs +1 -0
  34. package/package.json +28 -8
  35. package/runtime-meta.d.ts +2 -0
  36. package/runtime-meta.mjs +7 -0
  37. package/src/cli/commands/build.ts +5 -3
  38. package/src/cli/commands/dev.ts +29 -19
  39. package/src/cli/commands/prepare.ts +0 -2
  40. package/src/cli/commands/start.ts +61 -0
  41. package/src/cli/index.ts +1 -0
  42. package/src/config/index.ts +5 -4
  43. package/src/core/apibara.ts +4 -2
  44. package/src/core/build/build.ts +2 -0
  45. package/src/core/build/dev.ts +1 -0
  46. package/src/core/build/prepare.ts +5 -2
  47. package/src/core/build/prod.ts +10 -6
  48. package/src/core/build/types.ts +4 -95
  49. package/src/core/config/defaults.ts +1 -4
  50. package/src/core/config/loader.ts +1 -0
  51. package/src/core/config/resolvers/runtime-config.resolver.ts +1 -1
  52. package/src/core/config/update.ts +2 -3
  53. package/src/core/path.ts +11 -0
  54. package/src/core/scan.ts +40 -0
  55. package/src/rollup/config.ts +67 -188
  56. package/src/rollup/plugins/config.ts +12 -0
  57. package/src/rollup/plugins/esm-shim.ts +69 -0
  58. package/src/rollup/plugins/indexers.ts +17 -0
  59. package/src/runtime/dev.ts +64 -0
  60. package/src/runtime/index.ts +2 -0
  61. package/src/runtime/internal/app.ts +78 -0
  62. package/src/runtime/internal/logger.ts +70 -0
  63. package/src/runtime/start.ts +48 -0
  64. package/src/types/apibara.ts +8 -0
  65. package/src/types/config.ts +28 -27
  66. package/src/types/hooks.ts +1 -0
  67. package/src/types/virtual/config.d.ts +3 -0
  68. package/src/types/virtual/indexers.d.ts +10 -0
@@ -1,7 +1,7 @@
1
1
  import { build, createApibara, prepare, writeTypes } from "apibara/core";
2
+ import { runtimeDir } from "apibara/runtime/meta";
2
3
  import { defineCommand } from "citty";
3
- import consola from "consola";
4
- import { resolve } from "pathe";
4
+ import { join, resolve } from "pathe";
5
5
  import { commonArgs } from "../common";
6
6
 
7
7
  export default defineCommand({
@@ -13,11 +13,13 @@ export default defineCommand({
13
13
  ...commonArgs,
14
14
  },
15
15
  async run({ args }) {
16
- consola.start("Building");
17
16
  const rootDir = resolve((args.dir || args._dir || ".") as string);
18
17
  const apibara = await createApibara({
19
18
  rootDir,
20
19
  });
20
+
21
+ apibara.options.entry = join(runtimeDir, "start.mjs");
22
+
21
23
  await prepare(apibara);
22
24
  await writeTypes(apibara);
23
25
  await build(apibara);
@@ -1,17 +1,16 @@
1
1
  import { type ChildProcess, spawn } from "node:child_process";
2
2
  import { build, createApibara, prepare, writeTypes } from "apibara/core";
3
+ import { runtimeDir } from "apibara/runtime/meta";
3
4
  import type { Apibara } from "apibara/types";
4
5
  import { defineCommand } from "citty";
5
- import consola from "consola";
6
- import { resolve } from "pathe";
6
+ import { colors } from "consola/utils";
7
+ import { join, resolve } from "pathe";
7
8
  import { commonArgs } from "../common";
8
9
 
9
10
  // Hot module reloading key regex
10
11
  // for only runtimeConfig.* keys
11
12
  const hmrKeyRe = /^runtimeConfig\./;
12
13
 
13
- let childProcess: ChildProcess | undefined;
14
-
15
14
  export default defineCommand({
16
15
  meta: {
17
16
  name: "dev",
@@ -27,24 +26,23 @@ export default defineCommand({
27
26
  type: "string",
28
27
  description: "Preset to use",
29
28
  },
30
- sink: {
31
- type: "string",
32
- description: "Sink to use",
33
- },
34
29
  },
35
30
  async run({ args }) {
36
- consola.start("Starting dev server");
37
31
  const rootDir = resolve((args.dir || args._dir || ".") as string);
32
+
38
33
  let apibara: Apibara;
34
+ let childProcess: ChildProcess | undefined;
39
35
 
40
36
  const reload = async () => {
41
37
  if (apibara) {
42
- consola.info("Restarting dev server");
38
+ apibara.logger.info("Restarting dev server");
43
39
  if ("unwatch" in apibara.options._c12) {
44
40
  await apibara.options._c12.unwatch();
45
41
  }
42
+
46
43
  await apibara.close();
47
44
  }
45
+
48
46
  apibara = await createApibara(
49
47
  {
50
48
  rootDir,
@@ -59,10 +57,11 @@ export default defineCommand({
59
57
  return; // No changes
60
58
  }
61
59
 
62
- consola.info(
63
- `Nitro config updated:
60
+ apibara.logger.info(
61
+ `Config updated:
64
62
  ${diff.map((entry) => ` ${entry.toString()}`).join("\n")}`,
65
63
  );
64
+
66
65
  await (diff.every((e) => hmrKeyRe.test(e.key))
67
66
  ? apibara.updateConfig(newConfig.config || {}) // Hot reload
68
67
  : reload()); // Full reload
@@ -71,35 +70,46 @@ export default defineCommand({
71
70
  },
72
71
  true,
73
72
  );
73
+
74
74
  apibara.hooks.hookOnce("restart", reload);
75
75
 
76
+ apibara.options.entry = join(runtimeDir, "dev.mjs");
77
+
76
78
  await prepare(apibara);
77
79
  await writeTypes(apibara);
78
80
  await build(apibara);
79
81
 
82
+ apibara.hooks.hook("dev:restart", () => {
83
+ if (childProcess) {
84
+ apibara.logger.info("Change detected, stopping indexers to restart");
85
+ childProcess.kill();
86
+ childProcess = undefined;
87
+ }
88
+ });
89
+
80
90
  apibara.hooks.hook("dev:reload", () => {
81
91
  if (childProcess) {
82
- consola.start("Restarting indexers");
83
92
  childProcess.kill();
84
93
  } else {
85
- consola.success("Dev server started");
86
- consola.success("Starting indexers");
94
+ apibara.logger.success("Restarting indexers");
87
95
  }
88
96
 
89
97
  const childArgs = [
90
- resolve(apibara.options.outputDir || "./.apibara/build", "main.mjs"),
98
+ resolve(apibara.options.outputDir || "./.apibara/build", "dev.mjs"),
99
+ "start",
91
100
  ...(args.indexers ? ["--indexers", args.indexers] : []),
92
101
  ...(args.preset ? ["--preset", args.preset] : []),
93
- ...(args.sink ? ["--sink", args.sink] : []),
94
102
  ];
95
103
 
96
- childProcess = spawn("jiti", childArgs, {
104
+ childProcess = spawn("node", childArgs, {
97
105
  stdio: "inherit",
98
106
  });
99
107
 
100
108
  childProcess.on("close", (code) => {
101
109
  if (code !== null) {
102
- consola.log(`Indexers process exited with code ${code}`);
110
+ apibara.logger.log(
111
+ `Indexers process exited with code ${colors.red(code)}`,
112
+ );
103
113
  }
104
114
  });
105
115
  });
@@ -1,7 +1,6 @@
1
1
  import { createApibara, writeTypes } from "apibara/core";
2
2
  import {} from "apibara/types";
3
3
  import { defineCommand } from "citty";
4
- import consola from "consola";
5
4
  import { resolve } from "pathe";
6
5
  import { commonArgs } from "../common";
7
6
 
@@ -14,7 +13,6 @@ export default defineCommand({
14
13
  ...commonArgs,
15
14
  },
16
15
  async run({ args }) {
17
- consola.start("Preparing Types");
18
16
  const rootDir = resolve((args.dir || ".") as string);
19
17
  const apibara = await createApibara({ rootDir });
20
18
  await writeTypes(apibara);
@@ -0,0 +1,61 @@
1
+ import { spawn } from "node:child_process";
2
+ import { createApibara } from "apibara/core";
3
+ import { defineCommand } from "citty";
4
+ import fse from "fs-extra";
5
+ import { resolve } from "pathe";
6
+ import { commonArgs } from "../common";
7
+
8
+ export default defineCommand({
9
+ meta: {
10
+ name: "start",
11
+ description: "Start one indexer",
12
+ },
13
+ args: {
14
+ ...commonArgs,
15
+ indexer: {
16
+ type: "string",
17
+ description: "The indexer to start",
18
+ required: true,
19
+ },
20
+ preset: {
21
+ type: "string",
22
+ description: "The preset to use",
23
+ },
24
+ },
25
+ async run({ args }) {
26
+ const { indexer, preset } = args;
27
+ const rootDir = resolve((args.dir || args._dir || ".") as string);
28
+
29
+ const apibara = await createApibara({
30
+ rootDir,
31
+ });
32
+
33
+ apibara.logger.start(
34
+ `Starting indexer ${indexer}${preset ? ` with preset ${preset}` : ""}`,
35
+ );
36
+
37
+ const outputDir = apibara.options.outputDir || "./.apibara/build";
38
+ const entry = resolve(outputDir, "start.mjs");
39
+
40
+ if (!fse.existsSync(entry)) {
41
+ apibara.logger.error(
42
+ `Output directory ${outputDir} does not exist. Try building the indexer with "apibara build" first.`,
43
+ );
44
+ return process.exit(1);
45
+ }
46
+
47
+ await apibara.close();
48
+
49
+ const childArgs = [
50
+ entry,
51
+ "start",
52
+ "--indexer",
53
+ indexer,
54
+ ...(preset ? ["--preset", preset] : []),
55
+ ];
56
+
57
+ spawn("node", childArgs, {
58
+ stdio: "inherit",
59
+ });
60
+ },
61
+ });
package/src/cli/index.ts CHANGED
@@ -9,6 +9,7 @@ export const mainCli = defineCommand({
9
9
  subCommands: {
10
10
  dev: () => import("./commands/dev").then((r) => r.default),
11
11
  build: () => import("./commands/build").then((r) => r.default),
12
+ start: () => import("./commands/start").then((r) => r.default),
12
13
  prepare: () => import("./commands/prepare").then((r) => r.default),
13
14
  },
14
15
  });
@@ -1,10 +1,11 @@
1
1
  import type { ApibaraConfig, DeepPartial } from "apibara/types";
2
2
 
3
3
  export function defineConfig<
4
- // biome-ignore lint/complexity/noBannedTypes: <explanation>
5
- T extends Record<string, DeepPartial<ApibaraConfig<T, R>>> = {},
6
- // biome-ignore lint/complexity/noBannedTypes: <explanation>
7
- R extends Record<string, unknown> = {},
4
+ T extends Record<
5
+ string,
6
+ DeepPartial<Pick<ApibaraConfig<T, R>, "runtimeConfig">>
7
+ > = Record<string, never>,
8
+ R extends Record<string, unknown> = Record<string, never>,
8
9
  >(config: ApibaraConfig<T, R>): ApibaraConfig<T, R> {
9
10
  return config;
10
11
  }
@@ -8,18 +8,18 @@ import consola from "consola";
8
8
  import { createHooks } from "hookable";
9
9
  import { loadOptions } from "./config/loader";
10
10
  import { updateApibaraConfig } from "./config/update";
11
+ import { scanIndexers } from "./scan";
11
12
 
12
13
  export async function createApibara(
13
14
  config: ApibaraConfig = {},
14
15
  opts: LoadConfigOptions = {},
15
16
  dev = false,
16
17
  ): Promise<Apibara> {
17
- // load options
18
18
  const options = await loadOptions(config, opts, dev);
19
19
 
20
- // create apibara context
21
20
  const apibara: Apibara = {
22
21
  options,
22
+ indexers: [],
23
23
  hooks: createHooks(),
24
24
  close: () => apibara.hooks.callHook("close"),
25
25
  logger: consola.withTag("apibara"),
@@ -30,5 +30,7 @@ export async function createApibara(
30
30
 
31
31
  apibara.hooks.addHooks(apibara.options.hooks);
32
32
 
33
+ await scanIndexers(apibara);
34
+
33
35
  return apibara;
34
36
  }
@@ -5,7 +5,9 @@ import { buildProduction } from "./prod";
5
5
 
6
6
  export async function build(apibara: Apibara) {
7
7
  const rollupConfig = getRollupConfig(apibara);
8
+
8
9
  await apibara.hooks.callHook("rollup:before", apibara, rollupConfig);
10
+
9
11
  return apibara.options.dev
10
12
  ? await watchDev(apibara, rollupConfig)
11
13
  : await buildProduction(apibara, rollupConfig);
@@ -53,6 +53,7 @@ function startRollupWatcher(apibara: Apibara, rollupConfig: RollupConfig) {
53
53
  switch (event.code) {
54
54
  // The watcher is (re)starting
55
55
  case "START": {
56
+ apibara.hooks.callHook("dev:restart");
56
57
  return;
57
58
  }
58
59
 
@@ -1,12 +1,15 @@
1
1
  import fsp from "node:fs/promises";
2
2
  import type { Apibara } from "apibara/types";
3
- import consola from "consola";
4
3
  import fse from "fs-extra";
4
+ import { prettyPath } from "../path";
5
5
 
6
6
  export async function prepare(apibara: Apibara) {
7
7
  await prepareDir(apibara.options.buildDir);
8
8
  await prepareDir(apibara.options.outputDir);
9
- consola.success("Output directory cleaned");
9
+
10
+ apibara.logger.success(
11
+ `Output directory ${prettyPath(apibara.options.outputDir)} cleaned`,
12
+ );
10
13
  }
11
14
 
12
15
  async function prepareDir(dir: string) {
@@ -1,16 +1,18 @@
1
1
  import type { Apibara, RollupConfig } from "apibara/types";
2
- import consola from "consola";
2
+ import { colors } from "consola/utils";
3
3
  import { type OutputOptions, rollup } from "rollup";
4
4
 
5
5
  export async function buildProduction(
6
6
  apibara: Apibara,
7
7
  rollupConfig: RollupConfig,
8
8
  ) {
9
+ apibara.logger.start(
10
+ `Building ${colors.cyan(apibara.indexers.length)} indexers`,
11
+ );
12
+
9
13
  try {
10
- // Create a bundle
11
14
  const bundle = await rollup(rollupConfig);
12
15
 
13
- // Generate output
14
16
  if (Array.isArray(rollupConfig.output)) {
15
17
  for (const outputOptions of rollupConfig.output) {
16
18
  await bundle.write(outputOptions);
@@ -21,12 +23,14 @@ export async function buildProduction(
21
23
  throw new Error("No output options specified in Rollup config");
22
24
  }
23
25
 
24
- // Close the bundle
25
26
  await bundle.close();
26
27
 
27
- consola.success("Build completed successfully!");
28
+ apibara.logger.success("Build succeeded!");
29
+ apibara.logger.info(
30
+ `You can start the indexers with ${colors.cyan("apibara start")}`,
31
+ );
28
32
  } catch (error) {
29
- console.error("Build failed:", error);
33
+ apibara.logger.error("Build failed", error);
30
34
  throw error;
31
35
  }
32
36
  }
@@ -1,10 +1,8 @@
1
1
  import fsp from "node:fs/promises";
2
2
  import type { Apibara } from "apibara/types";
3
- import consola from "consola";
4
- import defu from "defu";
5
- import { dirname, isAbsolute, join, relative, resolve } from "pathe";
6
- import type { TSConfig } from "pkg-types";
3
+ import { dirname, join, resolve } from "pathe";
7
4
  import { type JSValue, generateTypes, resolveSchema } from "untyped";
5
+ import { prettyPath } from "../path";
8
6
 
9
7
  export async function writeTypes(apibara: Apibara) {
10
8
  const typesDir = resolve(apibara.options.buildDir, "types");
@@ -31,12 +29,7 @@ declare module "apibara/types" {`,
31
29
  : "",
32
30
  "}",
33
31
  // Makes this a module for augmentation purposes
34
- "export type {}",
35
- ];
36
-
37
- const declarations = [
38
- // local apibara augmentations
39
- '/// <reference path="./apibara-config.d.ts" />',
32
+ "export type {};",
40
33
  ];
41
34
 
42
35
  const buildFiles: { path: string; contents: string }[] = [];
@@ -46,83 +39,6 @@ declare module "apibara/types" {`,
46
39
  contents: config.join("\n"),
47
40
  });
48
41
 
49
- buildFiles.push({
50
- path: join(typesDir, "apibara.d.ts"),
51
- contents: declarations.join("\n"),
52
- });
53
-
54
- if (apibara.options.typescript.generateTsConfig) {
55
- const tsConfigPath = resolve(
56
- apibara.options.buildDir,
57
- apibara.options.typescript.tsconfigPath,
58
- );
59
- const tsconfigDir = dirname(tsConfigPath);
60
- const tsConfig: TSConfig = defu(apibara.options.typescript.tsConfig, {
61
- compilerOptions: {
62
- forceConsistentCasingInFileNames: true,
63
- strict: apibara.options.typescript.strict,
64
- noEmit: true,
65
- target: "ESNext",
66
- module: "ESNext",
67
- moduleResolution: "Bundler",
68
- allowJs: true,
69
- resolveJsonModule: true,
70
- jsx: "preserve",
71
- allowSyntheticDefaultImports: true,
72
- jsxFactory: "h",
73
- jsxFragmentFactory: "Fragment",
74
- },
75
- include: [
76
- relativeWithDot(tsconfigDir, join(typesDir, "apibara.d.ts")).replace(
77
- /^(?=[^.])/,
78
- "./",
79
- ),
80
- ],
81
- });
82
-
83
- for (const alias in tsConfig.compilerOptions!.paths) {
84
- const paths = tsConfig.compilerOptions!.paths[alias];
85
- tsConfig.compilerOptions!.paths[alias] = await Promise.all(
86
- paths.map(async (path: string) => {
87
- if (!isAbsolute(path)) {
88
- return path;
89
- }
90
- const stats = await fsp
91
- .stat(path)
92
- .catch(() => null /* file does not exist */);
93
- return relativeWithDot(
94
- tsconfigDir,
95
- stats?.isFile()
96
- ? path.replace(/(?<=\w)\.\w+$/g, "") /* remove extension */
97
- : path,
98
- );
99
- }),
100
- );
101
- }
102
-
103
- tsConfig.include = [
104
- ...new Set(
105
- tsConfig.include!.map((p) =>
106
- isAbsolute(p) ? relativeWithDot(tsconfigDir, p) : p,
107
- ),
108
- ),
109
- ];
110
- if (tsConfig.exclude) {
111
- tsConfig.exclude = [
112
- ...new Set(
113
- tsConfig.exclude!.map((p) =>
114
- isAbsolute(p) ? relativeWithDot(tsconfigDir, p) : p,
115
- ),
116
- ),
117
- ];
118
- }
119
-
120
- buildFiles.push({
121
- path: tsConfigPath,
122
- contents: JSON.stringify(tsConfig, null, 2),
123
- });
124
- }
125
-
126
42
  await Promise.all(
127
43
  buildFiles.map(async (file) => {
128
44
  const _file = resolve(apibara.options.buildDir, file.path);
@@ -131,12 +47,5 @@ declare module "apibara/types" {`,
131
47
  }),
132
48
  );
133
49
 
134
- consola.success("Types generated");
135
- }
136
-
137
- const RELATIVE_RE = /^\.{1,2}\//;
138
-
139
- export function relativeWithDot(from: string, to: string) {
140
- const rel = relative(from, to);
141
- return RELATIVE_RE.test(rel) ? rel : `./${rel}`;
50
+ apibara.logger.success(`Types written to ${prettyPath(typesDir)}`);
142
51
  }
@@ -1,8 +1,8 @@
1
- // import { defaultSink } from "@apibara/indexer";
2
1
  import type { ApibaraConfig } from "apibara/types";
3
2
 
4
3
  export const ApibaraDefaults: ApibaraConfig = {
5
4
  rootDir: ".",
5
+ indexersDir: "indexers",
6
6
 
7
7
  runtimeConfig: {},
8
8
  hooks: {},
@@ -11,10 +11,7 @@ export const ApibaraDefaults: ApibaraConfig = {
11
11
 
12
12
  typescript: {
13
13
  strict: false,
14
- generateTsConfig: true,
15
14
  generateRuntimeConfigTypes: true,
16
- tsconfigPath: "types/tsconfig.json",
17
15
  internalPaths: false,
18
- tsConfig: {},
19
16
  },
20
17
  };
@@ -53,6 +53,7 @@ async function _loadUserConfig(
53
53
 
54
54
  options._config = configOverrides;
55
55
  options._c12 = loadedConfig;
56
+
56
57
  if (dev) {
57
58
  options.dev = dev;
58
59
  }
@@ -1,6 +1,6 @@
1
1
  import type { ApibaraOptions } from "apibara/types";
2
2
 
3
3
  export async function resolveRuntimeConfigOptions(options: ApibaraOptions) {
4
- options.runtimeConfig = { ...options.runtimeConfig, default: "value" };
4
+ options.runtimeConfig = { ...options.runtimeConfig };
5
5
  process.env.APIBARA_RUNTIME_CONFIG = JSON.stringify(options.runtimeConfig);
6
6
  }
@@ -1,10 +1,9 @@
1
1
  import type { Apibara, ApibaraDynamicConfig } from "apibara/types";
2
- import consola from "consola";
3
2
 
4
3
  export async function updateApibaraConfig(
5
4
  apibara: Apibara,
6
- config: ApibaraDynamicConfig,
5
+ _config: ApibaraDynamicConfig,
7
6
  ) {
8
7
  await apibara.hooks.callHook("rollup:reload");
9
- consola.success("Apibara config hot reloaded!");
8
+ apibara.logger.success("Apibara config hot reloaded!");
10
9
  }
@@ -0,0 +1,11 @@
1
+ import { colors } from "consola/utils";
2
+ import { relative } from "pathe";
3
+
4
+ /** Return a (possibly highlighted) path relative to the current working directory.
5
+ *
6
+ * From nitrojs/nitro.
7
+ */
8
+ export function prettyPath(path: string, highlight = true) {
9
+ const rel = relative(process.cwd(), path);
10
+ return highlight ? colors.cyan(rel) : rel;
11
+ }
@@ -0,0 +1,40 @@
1
+ import type { Apibara } from "apibara/types";
2
+ import fse from "fs-extra";
3
+ import { basename, join } from "pathe";
4
+
5
+ const INDEXER_EXTENSIONS = [".indexer.ts", ".indexer.js"];
6
+
7
+ export async function scanIndexers(apibara: Apibara) {
8
+ apibara.logger.debug("Scanning indexers");
9
+
10
+ const indexersDir = join(
11
+ apibara.options.rootDir,
12
+ apibara.options.indexersDir,
13
+ );
14
+
15
+ if (!fse.existsSync(indexersDir)) {
16
+ throw new Error(`Indexers directory not found: ${indexersDir}`);
17
+ }
18
+
19
+ apibara.indexers = [];
20
+
21
+ for (const file of fse.readdirSync(indexersDir)) {
22
+ const indexerName = indexerNameFromFile(file);
23
+ if (indexerName) {
24
+ apibara.indexers.push({
25
+ name: indexerName,
26
+ indexer: join(indexersDir, file),
27
+ });
28
+ }
29
+ }
30
+
31
+ apibara.logger.debug(`Found ${apibara.indexers.length} indexers`);
32
+ }
33
+
34
+ function indexerNameFromFile(file: string) {
35
+ for (const extension of INDEXER_EXTENSIONS) {
36
+ if (file.endsWith(extension)) {
37
+ return basename(file, extension);
38
+ }
39
+ }
40
+ }