apibara 2.1.0-beta.28 → 2.1.0-beta.29

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.
@@ -0,0 +1,50 @@
1
+ import { spawn } from 'node:child_process';
2
+ import { join } from 'node:path';
3
+ import { createApibara, prepare, writeTypes, build } from 'apibara/core';
4
+ import { runtimeDir } from 'apibara/runtime/meta';
5
+ import { defineCommand } from 'citty';
6
+ import consola from 'consola';
7
+ import { resolve } from 'pathe';
8
+ import { c as commonArgs, a as checkForUnknownArgs } from '../shared/apibara.63c9a277.mjs';
9
+
10
+ const writeProjectInfo = defineCommand({
11
+ meta: {
12
+ name: "write-project-info",
13
+ description: "Write json-encoded information about the project."
14
+ },
15
+ args: {
16
+ ...commonArgs
17
+ },
18
+ async run({ args, cmd }) {
19
+ await checkForUnknownArgs(args, cmd);
20
+ consola.start("Generating `project-info.json`");
21
+ const rootDir = resolve(args.dir || ".");
22
+ const apibara = await createApibara({ rootDir, disableLogs: true });
23
+ apibara.options.entry = join(runtimeDir, "project-info.mjs");
24
+ await prepare(apibara);
25
+ await writeTypes(apibara);
26
+ await build(apibara);
27
+ const childArgs = [
28
+ resolve(
29
+ apibara.options.outputDir || "./.apibara/build",
30
+ "project-info.mjs"
31
+ ),
32
+ "start",
33
+ "--build-dir",
34
+ apibara.options.buildDir
35
+ ];
36
+ const child = spawn("node", childArgs, {
37
+ stdio: "inherit"
38
+ });
39
+ child.on("close", (code) => {
40
+ if (code === 0) {
41
+ consola.success("Project info written to `.apibara/project-info.json`");
42
+ }
43
+ });
44
+ child.on("error", (error) => {
45
+ consola.error(`Failed to write project info: ${error.message}`, error);
46
+ });
47
+ }
48
+ });
49
+
50
+ export { writeProjectInfo as default };
@@ -13,7 +13,8 @@ const mainCli = defineCommand({
13
13
  start: () => import('../chunks/start.mjs').then((r) => r.default),
14
14
  prepare: () => import('../chunks/prepare.mjs').then((r) => r.default),
15
15
  init: () => import('../chunks/init.mjs').then((r) => r.default),
16
- add: () => import('../chunks/add.mjs').then((r) => r.default)
16
+ add: () => import('../chunks/add.mjs').then((r) => r.default),
17
+ "write-project-info": () => import('../chunks/write-project-info.mjs').then((r) => r.default)
17
18
  }
18
19
  });
19
20
  runMain(mainCli);
@@ -227,9 +227,11 @@ const getIgnorePatterns = (apibara) => [
227
227
  ];
228
228
 
229
229
  async function buildProduction(apibara, rolldownConfig) {
230
- apibara.logger.start(
231
- `Building ${colors.cyan(apibara.indexers.length)} indexers`
232
- );
230
+ if (!apibara.options.disableLogs) {
231
+ apibara.logger.start(
232
+ `Building ${colors.cyan(apibara.indexers.length)} indexers`
233
+ );
234
+ }
233
235
  const startTime = Date.now();
234
236
  try {
235
237
  const bundle = await rolldown.rolldown(rolldownConfig);
@@ -245,10 +247,12 @@ async function buildProduction(apibara, rolldownConfig) {
245
247
  await bundle.close();
246
248
  const endTime = Date.now();
247
249
  const duration = endTime - startTime;
248
- apibara.logger.success(`Build succeeded in ${duration}ms`);
249
- apibara.logger.info(
250
- `You can start the indexers with ${colors.cyan("apibara start")}`
251
- );
250
+ if (!apibara.options.disableLogs) {
251
+ apibara.logger.success(`Build succeeded in ${duration}ms`);
252
+ apibara.logger.info(
253
+ `You can start the indexers with ${colors.cyan("apibara start")}`
254
+ );
255
+ }
252
256
  } catch (error) {
253
257
  apibara.logger.error("Build failed", error);
254
258
  throw error;
@@ -276,9 +280,11 @@ function prettyPath(path, highlight = true) {
276
280
  async function prepare(apibara) {
277
281
  await prepareDir(apibara.options.buildDir);
278
282
  await prepareDir(apibara.options.outputDir);
279
- apibara.logger.success(
280
- `Output directory ${prettyPath(apibara.options.outputDir)} cleaned`
281
- );
283
+ if (!apibara.options.disableLogs) {
284
+ apibara.logger.success(
285
+ `Output directory ${prettyPath(apibara.options.outputDir)} cleaned`
286
+ );
287
+ }
282
288
  }
283
289
  async function prepareDir(dir) {
284
290
  await fsp.mkdir(dir, { recursive: true });
@@ -325,7 +331,9 @@ declare module "apibara/types" {`,
325
331
  await fsp.writeFile(_file, file.contents);
326
332
  })
327
333
  );
328
- apibara.logger.success(`Types written to ${prettyPath(typesDir)}`);
334
+ if (!apibara.options.disableLogs) {
335
+ apibara.logger.success(`Types written to ${prettyPath(typesDir)}`);
336
+ }
329
337
  }
330
338
 
331
339
  export { build, createApibara, prepare, writeTypes };
@@ -0,0 +1,3 @@
1
+ export declare const mainCli: import("citty").CommandDef<import("citty").ArgsDef>;
2
+ declare const _default: {};
3
+ export default _default;
@@ -0,0 +1,53 @@
1
+ import { writeFileSync } from "node:fs";
2
+ import { resolve } from "node:path";
3
+ import { defineCommand, runMain } from "citty";
4
+ import { config } from "#apibara-internal-virtual/config";
5
+ import { availableIndexers, createIndexer } from "./internal/app.mjs";
6
+ const startCommand = defineCommand({
7
+ meta: {
8
+ name: "write-project-info",
9
+ description: "Write json-encoded information about the project."
10
+ },
11
+ args: {
12
+ "build-dir": {
13
+ type: "string",
14
+ description: "project build directory"
15
+ }
16
+ },
17
+ async run({ args }) {
18
+ const projectInfo = {
19
+ indexers: {}
20
+ };
21
+ for (const preset of Object.keys(config.presets ?? {})) {
22
+ for (const indexer of availableIndexers) {
23
+ const { indexer: indexerInstance } = createIndexer(indexer, preset) ?? {};
24
+ if (!indexerInstance) {
25
+ continue;
26
+ }
27
+ projectInfo.indexers[indexer] = {
28
+ ...projectInfo.indexers[indexer] ?? {},
29
+ [preset]: {
30
+ type: indexerInstance.streamConfig.name,
31
+ isFactory: indexerInstance.options.factory !== void 0
32
+ }
33
+ };
34
+ }
35
+ }
36
+ const projectInfoPath = resolve(
37
+ args["build-dir"] ?? ".apibara",
38
+ "project-info.json"
39
+ );
40
+ writeFileSync(projectInfoPath, JSON.stringify(projectInfo, null, 2));
41
+ }
42
+ });
43
+ export const mainCli = defineCommand({
44
+ meta: {
45
+ name: "write-project-info-runner",
46
+ description: "Write json-encoded information about the project."
47
+ },
48
+ subCommands: {
49
+ start: () => startCommand
50
+ }
51
+ });
52
+ runMain(mainCli);
53
+ export default {};
@@ -52,6 +52,7 @@ interface ApibaraOptions<T extends Record<string, DeepPartial<Pick<ApibaraConfig
52
52
  buildDir: string;
53
53
  outputDir: string;
54
54
  indexersDir: string;
55
+ disableLogs?: boolean;
55
56
  dev: boolean;
56
57
  watchOptions: WatchOptions["watch"];
57
58
  hooks: NestedHooks<ApibaraHooks>;
@@ -52,6 +52,7 @@ interface ApibaraOptions<T extends Record<string, DeepPartial<Pick<ApibaraConfig
52
52
  buildDir: string;
53
53
  outputDir: string;
54
54
  indexersDir: string;
55
+ disableLogs?: boolean;
55
56
  dev: boolean;
56
57
  watchOptions: WatchOptions["watch"];
57
58
  hooks: NestedHooks<ApibaraHooks>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apibara",
3
- "version": "2.1.0-beta.28",
3
+ "version": "2.1.0-beta.29",
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.28",
81
+ "@apibara/starknet": "2.1.0-beta.29",
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.28",
93
- "@apibara/protocol": "2.1.0-beta.28",
92
+ "@apibara/indexer": "2.1.0-beta.29",
93
+ "@apibara/protocol": "2.1.0-beta.29",
94
94
  "@rollup/plugin-replace": "^6.0.2",
95
95
  "@rollup/plugin-virtual": "^3.0.2",
96
96
  "c12": "^1.11.1",
@@ -0,0 +1,56 @@
1
+ import { spawn } from "node:child_process";
2
+ import { join } from "node:path";
3
+ import { build, createApibara, prepare, writeTypes } from "apibara/core";
4
+ import { runtimeDir } from "apibara/runtime/meta";
5
+ import { defineCommand } from "citty";
6
+ import consola from "consola";
7
+ import { resolve } from "pathe";
8
+ import { checkForUnknownArgs, commonArgs } from "../common";
9
+
10
+ export default defineCommand({
11
+ meta: {
12
+ name: "write-project-info",
13
+ description: "Write json-encoded information about the project.",
14
+ },
15
+ args: {
16
+ ...commonArgs,
17
+ },
18
+ async run({ args, cmd }) {
19
+ await checkForUnknownArgs(args, cmd);
20
+
21
+ consola.start("Generating `project-info.json`");
22
+
23
+ const rootDir = resolve((args.dir || ".") as string);
24
+ const apibara = await createApibara({ rootDir, disableLogs: true });
25
+
26
+ apibara.options.entry = join(runtimeDir, "project-info.mjs");
27
+
28
+ await prepare(apibara);
29
+ await writeTypes(apibara);
30
+ await build(apibara);
31
+
32
+ const childArgs = [
33
+ resolve(
34
+ apibara.options.outputDir || "./.apibara/build",
35
+ "project-info.mjs",
36
+ ),
37
+ "start",
38
+ "--build-dir",
39
+ apibara.options.buildDir,
40
+ ];
41
+
42
+ const child = spawn("node", childArgs, {
43
+ stdio: "inherit",
44
+ });
45
+
46
+ child.on("close", (code) => {
47
+ if (code === 0) {
48
+ consola.success("Project info written to `.apibara/project-info.json`");
49
+ }
50
+ });
51
+
52
+ child.on("error", (error) => {
53
+ consola.error(`Failed to write project info: ${error.message}`, error);
54
+ });
55
+ },
56
+ });
package/src/cli/index.ts CHANGED
@@ -13,6 +13,8 @@ export const mainCli = defineCommand({
13
13
  prepare: () => import("./commands/prepare").then((r) => r.default),
14
14
  init: () => import("./commands/init").then((r) => r.default),
15
15
  add: () => import("./commands/add").then((r) => r.default),
16
+ "write-project-info": () =>
17
+ import("./commands/write-project-info").then((r) => r.default),
16
18
  },
17
19
  });
18
20
 
@@ -7,9 +7,11 @@ export async function prepare(apibara: Apibara) {
7
7
  await prepareDir(apibara.options.buildDir);
8
8
  await prepareDir(apibara.options.outputDir);
9
9
 
10
- apibara.logger.success(
11
- `Output directory ${prettyPath(apibara.options.outputDir)} cleaned`,
12
- );
10
+ if (!apibara.options.disableLogs) {
11
+ apibara.logger.success(
12
+ `Output directory ${prettyPath(apibara.options.outputDir)} cleaned`,
13
+ );
14
+ }
13
15
  }
14
16
 
15
17
  async function prepareDir(dir: string) {
@@ -6,9 +6,11 @@ export async function buildProduction(
6
6
  apibara: Apibara,
7
7
  rolldownConfig: rolldown.RolldownOptions,
8
8
  ) {
9
- apibara.logger.start(
10
- `Building ${colors.cyan(apibara.indexers.length)} indexers`,
11
- );
9
+ if (!apibara.options.disableLogs) {
10
+ apibara.logger.start(
11
+ `Building ${colors.cyan(apibara.indexers.length)} indexers`,
12
+ );
13
+ }
12
14
 
13
15
  const startTime = Date.now();
14
16
 
@@ -30,10 +32,12 @@ export async function buildProduction(
30
32
  const endTime = Date.now();
31
33
  const duration = endTime - startTime;
32
34
 
33
- apibara.logger.success(`Build succeeded in ${duration}ms`);
34
- apibara.logger.info(
35
- `You can start the indexers with ${colors.cyan("apibara start")}`,
36
- );
35
+ if (!apibara.options.disableLogs) {
36
+ apibara.logger.success(`Build succeeded in ${duration}ms`);
37
+ apibara.logger.info(
38
+ `You can start the indexers with ${colors.cyan("apibara start")}`,
39
+ );
40
+ }
37
41
  } catch (error) {
38
42
  apibara.logger.error("Build failed", error);
39
43
  throw error;
@@ -55,5 +55,7 @@ declare module "apibara/types" {`,
55
55
  }),
56
56
  );
57
57
 
58
- apibara.logger.success(`Types written to ${prettyPath(typesDir)}`);
58
+ if (!apibara.options.disableLogs) {
59
+ apibara.logger.success(`Types written to ${prettyPath(typesDir)}`);
60
+ }
59
61
  }
@@ -0,0 +1,72 @@
1
+ import { writeFileSync } from "node:fs";
2
+ import { resolve } from "node:path";
3
+ import { defineCommand, runMain } from "citty";
4
+ import { config } from "#apibara-internal-virtual/config";
5
+ import { availableIndexers, createIndexer } from "./internal/app";
6
+
7
+ type ProjectInfo = {
8
+ indexers: {
9
+ [indexerName: string]: {
10
+ [presetName: string]: {
11
+ type: string;
12
+ isFactory: boolean;
13
+ };
14
+ };
15
+ };
16
+ };
17
+
18
+ const startCommand = defineCommand({
19
+ meta: {
20
+ name: "write-project-info",
21
+ description: "Write json-encoded information about the project.",
22
+ },
23
+ args: {
24
+ "build-dir": {
25
+ type: "string",
26
+ description: "project build directory",
27
+ },
28
+ },
29
+ async run({ args }) {
30
+ const projectInfo: ProjectInfo = {
31
+ indexers: {},
32
+ };
33
+
34
+ for (const preset of Object.keys(config.presets ?? {})) {
35
+ for (const indexer of availableIndexers) {
36
+ const { indexer: indexerInstance } =
37
+ createIndexer(indexer, preset) ?? {};
38
+ if (!indexerInstance) {
39
+ continue;
40
+ }
41
+ projectInfo.indexers[indexer] = {
42
+ ...(projectInfo.indexers[indexer] ?? {}),
43
+ [preset]: {
44
+ type: indexerInstance.streamConfig.name,
45
+ isFactory: indexerInstance.options.factory !== undefined,
46
+ },
47
+ };
48
+ }
49
+ }
50
+
51
+ const projectInfoPath = resolve(
52
+ args["build-dir"] ?? ".apibara",
53
+ "project-info.json",
54
+ );
55
+
56
+ writeFileSync(projectInfoPath, JSON.stringify(projectInfo, null, 2));
57
+ },
58
+ });
59
+
60
+ export const mainCli = defineCommand({
61
+ meta: {
62
+ name: "write-project-info-runner",
63
+ description: "Write json-encoded information about the project.",
64
+ },
65
+ subCommands: {
66
+ start: () => startCommand,
67
+ },
68
+ });
69
+
70
+ runMain(mainCli);
71
+
72
+ export default {};
@@ -75,6 +75,7 @@ export interface ApibaraOptions<
75
75
  buildDir: string;
76
76
  outputDir: string;
77
77
  indexersDir: string;
78
+ disableLogs?: boolean;
78
79
 
79
80
  // Dev
80
81
  dev: boolean;