apibara 2.1.0-beta.31 → 2.1.0-beta.33

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 (40) hide show
  1. package/dist/chunks/add.mjs +1 -2
  2. package/dist/chunks/add.mjs.map +1 -1
  3. package/dist/chunks/build.mjs +1 -2
  4. package/dist/chunks/build.mjs.map +1 -1
  5. package/dist/chunks/dev.mjs +1 -2
  6. package/dist/chunks/dev.mjs.map +1 -1
  7. package/dist/chunks/init.mjs +1 -2
  8. package/dist/chunks/init.mjs.map +1 -1
  9. package/dist/chunks/prepare.mjs +1 -2
  10. package/dist/chunks/prepare.mjs.map +1 -1
  11. package/dist/chunks/start.mjs +10 -3
  12. package/dist/chunks/start.mjs.map +1 -1
  13. package/dist/chunks/write-project-info.mjs +1 -1
  14. package/dist/chunks/write-project-info.mjs.map +1 -1
  15. package/dist/common/index.d.mts +6 -1
  16. package/dist/common/index.d.ts +6 -1
  17. package/dist/common/index.mjs +28 -1
  18. package/dist/common/index.mjs.map +1 -1
  19. package/dist/create/index.mjs +2 -3
  20. package/dist/create/index.mjs.map +1 -1
  21. package/dist/rolldown/index.mjs +18 -0
  22. package/dist/rolldown/index.mjs.map +1 -1
  23. package/dist/runtime/start.mjs +38 -4
  24. package/package.json +4 -4
  25. package/src/cli/commands/add.ts +1 -1
  26. package/src/cli/commands/build.ts +1 -1
  27. package/src/cli/commands/dev.ts +1 -1
  28. package/src/cli/commands/init.ts +1 -1
  29. package/src/cli/commands/prepare.ts +1 -2
  30. package/src/cli/commands/start.ts +10 -2
  31. package/src/cli/commands/write-project-info.ts +1 -1
  32. package/src/common/index.ts +1 -0
  33. package/src/create/templates.ts +2 -3
  34. package/src/rolldown/config.ts +2 -1
  35. package/src/rolldown/plugins/static-config.ts +21 -0
  36. package/src/runtime/start.ts +44 -4
  37. package/src/types/virtual/static-config.d.ts +4 -0
  38. package/dist/shared/apibara.63c9a277.mjs +0 -30
  39. package/dist/shared/apibara.63c9a277.mjs.map +0 -1
  40. /package/src/{cli/common.ts → common/cli.ts} +0 -0
@@ -1,10 +1,10 @@
1
1
  import { spawn } from "node:child_process";
2
+ import { checkForUnknownArgs, commonArgs } from "apibara/common";
2
3
  import { createApibara } from "apibara/core";
3
4
  import { defineCommand } from "citty";
4
5
  import { colors } from "consola/utils";
5
6
  import fse from "fs-extra";
6
7
  import { resolve } from "pathe";
7
- import { checkForUnknownArgs, commonArgs } from "../common";
8
8
 
9
9
  export default defineCommand({
10
10
  meta: {
@@ -50,7 +50,15 @@ export default defineCommand({
50
50
 
51
51
  await apibara.close();
52
52
 
53
- const childArgs = [entry, "start", "--indexer", indexer];
53
+ const childArgs = [
54
+ entry,
55
+ "start",
56
+ "--indexer",
57
+ indexer,
58
+ // important: this is required to run the indexer with apibara cli to load runtime values correctly
59
+ "--no-standalone",
60
+ ...(preset ? ["--preset", preset] : []),
61
+ ];
54
62
 
55
63
  const childProcess = spawn("node", childArgs, {
56
64
  stdio: "inherit",
@@ -1,11 +1,11 @@
1
1
  import { spawn } from "node:child_process";
2
2
  import { join } from "node:path";
3
+ import { checkForUnknownArgs, commonArgs } from "apibara/common";
3
4
  import { build, createApibara, prepare, writeTypes } from "apibara/core";
4
5
  import { runtimeDir } from "apibara/runtime/meta";
5
6
  import { defineCommand } from "citty";
6
7
  import consola from "consola";
7
8
  import { resolve } from "pathe";
8
- import { checkForUnknownArgs, commonArgs } from "../common";
9
9
 
10
10
  export default defineCommand({
11
11
  meta: {
@@ -1,2 +1,3 @@
1
1
  export * from "./constants";
2
2
  export * from "./helper";
3
+ export * from "./cli";
@@ -87,8 +87,7 @@ ${storage === "postgres" ? `import * as schema from "../lib/schema";` : ""}
87
87
 
88
88
 
89
89
  export default function (runtimeConfig${language === "typescript" ? ": ApibaraRuntimeConfig" : ""}) {
90
- const indexerId = "${indexerId}";
91
- const { startingBlock, streamUrl } = runtimeConfig[indexerId];
90
+ const { startingBlock, streamUrl } = runtimeConfig["${indexerId}"];
92
91
  ${
93
92
  storage === "postgres"
94
93
  ? `const db = drizzle({
@@ -110,7 +109,7 @@ export default function (runtimeConfig${language === "typescript" ? ": ApibaraRu
110
109
  finality: "accepted",
111
110
  startingBlock: BigInt(startingBlock),
112
111
  filter: {
113
- header: "always",
112
+ ${chain === "ethereum" ? "logs: []," : chain === "starknet" ? "events: []," : ""}
114
113
  },
115
114
  plugins: [${storage === "postgres" ? "drizzleStorage({ db, migrate: { migrationsFolder: './drizzle' } })" : ""}],
116
115
  async transform({ endCursor, finality }) {
@@ -10,6 +10,7 @@ import type {
10
10
  } from "rolldown";
11
11
  import { indexers } from "./plugins/indexers";
12
12
  import { instrumentation } from "./plugins/instrumentation";
13
+ import { staticConfig } from "./plugins/static-config";
13
14
 
14
15
  const runtimeDependencies = [
15
16
  "better-sqlite3",
@@ -77,8 +78,8 @@ export function getRolldownConfig(apibara: Apibara): RolldownOptions {
77
78
  },
78
79
  );
79
80
 
81
+ rolldownConfig.plugins?.push(staticConfig(apibara));
80
82
  rolldownConfig.plugins?.push(instrumentation(apibara));
81
83
  rolldownConfig.plugins?.push(indexers(apibara));
82
-
83
84
  return rolldownConfig;
84
85
  }
@@ -0,0 +1,21 @@
1
+ import virtual from "@rollup/plugin-virtual";
2
+ import { USER_ENV_APIBARA_RUNTIME_CONFIG } from "apibara/common";
3
+ import type { Apibara } from "apibara/types";
4
+ import type { RolldownPluginOption } from "rolldown";
5
+
6
+ export function staticConfig(apibara: Apibara) {
7
+ const presetString = apibara.options.preset ?? "";
8
+ const presetsStringified = JSON.stringify(apibara.options.presets ?? {});
9
+ const runtimeConfigStringified = JSON.stringify(
10
+ apibara.options.runtimeConfig ?? {},
11
+ );
12
+
13
+ return virtual({
14
+ "#apibara-internal-virtual/static-config": `
15
+ export const preset = ${presetString ? `"${presetString}"` : "undefined"};
16
+ export const presets = ${presetsStringified};
17
+ export const runtimeConfig = ${runtimeConfigStringified};
18
+ export const userEnvRuntimeConfig = JSON.parse(process.env.${USER_ENV_APIBARA_RUNTIME_CONFIG} ?? "{}");
19
+ `,
20
+ }) as RolldownPluginOption;
21
+ }
@@ -1,9 +1,20 @@
1
1
  import { runWithReconnect } from "@apibara/indexer";
2
- import { getRuntimeDataFromEnv } from "apibara/common";
2
+ import {
3
+ checkForUnknownArgs,
4
+ getProcessedRuntimeConfig,
5
+ getRuntimeDataFromEnv,
6
+ } from "apibara/common";
3
7
  import { defineCommand, runMain } from "citty";
4
8
  import consola from "consola";
5
9
  import { blueBright } from "picocolors";
6
10
  import { register } from "#apibara-internal-virtual/instrumentation";
11
+ // used when running with node .apibara/build/start.mjs as these values are made static during build time (except userEnvRuntimeConfig)
12
+ import {
13
+ preset as originalPreset,
14
+ presets,
15
+ runtimeConfig,
16
+ userEnvRuntimeConfig,
17
+ } from "#apibara-internal-virtual/static-config";
7
18
  import { createAuthenticatedClient, createIndexer } from "./internal/app";
8
19
 
9
20
  const startCommand = defineCommand({
@@ -17,11 +28,39 @@ const startCommand = defineCommand({
17
28
  description: "Indexer name",
18
29
  required: true,
19
30
  },
31
+ preset: {
32
+ type: "string",
33
+ description: "Preset name",
34
+ },
35
+ standalone: {
36
+ type: "boolean",
37
+ default: true,
38
+ description:
39
+ "--standalone: can run the indexer just with node and without apibara cli \n\t\t\t --no-standalone: must run the indexer with apibara cli",
40
+ },
20
41
  },
21
- async run({ args }) {
22
- const { indexer } = args;
42
+ async run({ args, cmd }) {
43
+ const { indexer, preset: argPreset, standalone } = args;
44
+ await checkForUnknownArgs(args, cmd);
23
45
 
24
- const { processedRuntimeConfig, preset } = getRuntimeDataFromEnv();
46
+ let preset: string | undefined;
47
+ let processedRuntimeConfig: Record<string, unknown> | undefined;
48
+
49
+ if (standalone) {
50
+ // when user does node .apibara/build/start.mjs
51
+ preset = argPreset ?? originalPreset;
52
+ processedRuntimeConfig = getProcessedRuntimeConfig({
53
+ preset,
54
+ presets,
55
+ runtimeConfig,
56
+ userEnvRuntimeConfig,
57
+ });
58
+ } else {
59
+ // When user does apibara start
60
+ const envResult = getRuntimeDataFromEnv();
61
+ preset = envResult.preset;
62
+ processedRuntimeConfig = envResult.processedRuntimeConfig;
63
+ }
25
64
 
26
65
  const { indexer: indexerInstance, logger } =
27
66
  createIndexer({
@@ -29,6 +68,7 @@ const startCommand = defineCommand({
29
68
  processedRuntimeConfig,
30
69
  preset,
31
70
  }) ?? {};
71
+
32
72
  if (!indexerInstance) {
33
73
  consola.error(`Specified indexer "${indexer}" but it was not defined`);
34
74
  process.exit(1);
@@ -0,0 +1,4 @@
1
+ export const preset: string | undefined = undefined;
2
+ export const presets: Record<string, unknown> = {};
3
+ export const runtimeConfig: Record<string, unknown> = {};
4
+ export const userEnvRuntimeConfig: Record<string, unknown> = {};
@@ -1,30 +0,0 @@
1
- import { renderUsage } from 'citty';
2
- import consola from 'consola';
3
-
4
- const commonArgs = {
5
- dir: {
6
- type: "string",
7
- description: "project root directory"
8
- }
9
- };
10
- const checkForUnknownArgs = async (args, cmd) => {
11
- const definedArgs = [];
12
- if (cmd.args) {
13
- for (const [argName, argDef] of Object.entries(cmd.args)) {
14
- definedArgs.push(argName);
15
- if (argDef.alias) {
16
- definedArgs.push(argDef.alias);
17
- }
18
- }
19
- }
20
- const providedArgs = Object.keys(args).filter((arg) => arg !== "_");
21
- const wrongArgs = providedArgs.filter((arg) => !definedArgs.includes(arg));
22
- if (wrongArgs.length > 0) {
23
- consola.error(`Unknown arguments: ${wrongArgs.join(", ")}`);
24
- consola.info(await renderUsage(cmd));
25
- process.exit(1);
26
- }
27
- };
28
-
29
- export { checkForUnknownArgs as a, commonArgs as c };
30
- //# sourceMappingURL=apibara.63c9a277.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"apibara.63c9a277.mjs","sources":["../../src/cli/common.ts"],"sourcesContent":["import {\n type ArgsDef,\n type CommandDef,\n type ParsedArgs,\n renderUsage,\n} from \"citty\";\nimport consola from \"consola\";\n\nexport const commonArgs = <ArgsDef>{\n dir: {\n type: \"string\",\n description: \"project root directory\",\n },\n};\n\nexport const checkForUnknownArgs = async <T extends ArgsDef = ArgsDef>(\n args: ParsedArgs<T>,\n cmd: CommandDef<T>,\n) => {\n // Create a list of defined args including both the main arg names and their aliases\n const definedArgs: string[] = [];\n if (cmd.args) {\n for (const [argName, argDef] of Object.entries(cmd.args)) {\n definedArgs.push(argName);\n // Add alias to definedArgs if it exists\n if (argDef.alias) {\n definedArgs.push(argDef.alias);\n }\n }\n }\n\n const providedArgs = Object.keys(args).filter((arg) => arg !== \"_\");\n const wrongArgs = providedArgs.filter((arg) => !definedArgs.includes(arg));\n\n if (wrongArgs.length > 0) {\n consola.error(`Unknown arguments: ${wrongArgs.join(\", \")}`);\n consola.info(await renderUsage(cmd));\n process.exit(1);\n }\n};\n"],"names":[],"mappings":";;;AAQO,MAAM,UAAsB,GAAA;AAAA,EACjC,GAAK,EAAA;AAAA,IACH,IAAM,EAAA,QAAA;AAAA,IACN,WAAa,EAAA,wBAAA;AAAA,GACf;AACF,EAAA;AAEa,MAAA,mBAAA,GAAsB,OACjC,IAAA,EACA,GACG,KAAA;AAEH,EAAA,MAAM,cAAwB,EAAC,CAAA;AAC/B,EAAA,IAAI,IAAI,IAAM,EAAA;AACZ,IAAW,KAAA,MAAA,CAAC,SAAS,MAAM,CAAA,IAAK,OAAO,OAAQ,CAAA,GAAA,CAAI,IAAI,CAAG,EAAA;AACxD,MAAA,WAAA,CAAY,KAAK,OAAO,CAAA,CAAA;AAExB,MAAA,IAAI,OAAO,KAAO,EAAA;AAChB,QAAY,WAAA,CAAA,IAAA,CAAK,OAAO,KAAK,CAAA,CAAA;AAAA,OAC/B;AAAA,KACF;AAAA,GACF;AAEA,EAAM,MAAA,YAAA,GAAe,OAAO,IAAK,CAAA,IAAI,EAAE,MAAO,CAAA,CAAC,GAAQ,KAAA,GAAA,KAAQ,GAAG,CAAA,CAAA;AAClE,EAAM,MAAA,SAAA,GAAY,aAAa,MAAO,CAAA,CAAC,QAAQ,CAAC,WAAA,CAAY,QAAS,CAAA,GAAG,CAAC,CAAA,CAAA;AAEzE,EAAI,IAAA,SAAA,CAAU,SAAS,CAAG,EAAA;AACxB,IAAA,OAAA,CAAQ,MAAM,CAAsB,mBAAA,EAAA,SAAA,CAAU,IAAK,CAAA,IAAI,CAAC,CAAE,CAAA,CAAA,CAAA;AAC1D,IAAA,OAAA,CAAQ,IAAK,CAAA,MAAM,WAAY,CAAA,GAAG,CAAC,CAAA,CAAA;AACnC,IAAA,OAAA,CAAQ,KAAK,CAAC,CAAA,CAAA;AAAA,GAChB;AACF;;;;"}
File without changes