apibara 2.1.0-beta.5 → 2.1.0-beta.6

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.
@@ -24,7 +24,9 @@ const ApibaraDefaults = {
24
24
  strict: false,
25
25
  generateRuntimeConfigTypes: true,
26
26
  internalPaths: false
27
- }
27
+ },
28
+ node: true,
29
+ exportConditions: ["node"]
28
30
  };
29
31
 
30
32
  async function resolvePathOptions(options) {
@@ -141,11 +143,11 @@ function formatRollupError(_error) {
141
143
  for (const error of errors) {
142
144
  const id = error.path || error.id || _error.id;
143
145
  let path = isAbsolute(id) ? relative(process.cwd(), id) : id;
144
- const location = error.loc || error.location;
146
+ const location = error.loc;
145
147
  if (location) {
146
148
  path += `:${location.line}:${location.column}`;
147
149
  }
148
- const text = error.text || error.frame;
150
+ const text = error.frame;
149
151
  logs.push(
150
152
  `Rollup error while processing \`${path}\`` + text ? "\n\n" + text : ""
151
153
  );
@@ -74,7 +74,7 @@ function indexers(apibara) {
74
74
  const indexers2 = [...new Set(apibara.indexers)];
75
75
  return virtual({
76
76
  "#apibara-internal-virtual/indexers": `
77
- ${indexers2.map((i) => `import _${hash(i)} from '${i.indexer}';`).join("\n")}
77
+ ${indexers2.map((i) => `import * as _${hash(i)} from '${i.indexer}';`).join("\n")}
78
78
 
79
79
  export const indexers = [
80
80
  ${indexers2.map((i) => `{ name: "${i.name}", indexer: _${hash(i)} }`).join(",\n")}
@@ -138,8 +138,9 @@ function getRollupConfig(apibara) {
138
138
  rollupConfig.plugins.push(
139
139
  nodeResolve({
140
140
  extensions,
141
- preferBuiltins: true,
142
- mainFields: ["main"]
141
+ preferBuiltins: !!apibara.options.node,
142
+ mainFields: ["main"],
143
+ exportConditions: apibara.options.exportConditions
143
144
  })
144
145
  );
145
146
  rollupConfig.plugins.push(indexers(apibara));
@@ -33,6 +33,9 @@ const startCommand = defineCommand({
33
33
  await Promise.all(
34
34
  selectedIndexers.map(async (indexer) => {
35
35
  const indexerInstance = createIndexer(indexer, preset);
36
+ if (!indexerInstance) {
37
+ return;
38
+ }
36
39
  const client = createClient(
37
40
  indexerInstance.streamConfig,
38
41
  indexerInstance.options.streamUrl
@@ -1,2 +1,2 @@
1
1
  export declare const availableIndexers: any;
2
- export declare function createIndexer(indexerName: string, preset?: string): import("@apibara/indexer").Indexer<unknown, unknown>;
2
+ export declare function createIndexer(indexerName: string, preset?: string): import("@apibara/indexer").Indexer<unknown, unknown> | undefined;
@@ -6,6 +6,7 @@ import {
6
6
  inMemoryPersistence,
7
7
  logger
8
8
  } from "@apibara/indexer/plugins";
9
+ import consola from "consola";
9
10
  import { config } from "#apibara-internal-virtual/config";
10
11
  import { indexers } from "#apibara-internal-virtual/indexers";
11
12
  import { createLogger } from "./logger.mjs";
@@ -30,7 +31,14 @@ export function createIndexer(indexerName, preset) {
30
31
  `Specified indexer "${indexerName}" but it was not defined`
31
32
  );
32
33
  }
33
- const definition = typeof indexerDefinition.indexer === "function" ? indexerDefinition.indexer(runtimeConfig) : indexerDefinition.indexer;
34
+ const indexerModule = indexerDefinition.indexer?.default;
35
+ if (indexerModule === void 0) {
36
+ consola.warn(
37
+ `Specified indexer "${indexerName}" but it does not export a default. Ignoring.`
38
+ );
39
+ return;
40
+ }
41
+ const definition = typeof indexerModule === "function" ? indexerModule(runtimeConfig) : indexerModule;
34
42
  let reporter = createLogger({
35
43
  indexer: indexerName,
36
44
  preset,
@@ -1,6 +1,7 @@
1
1
  import { runWithReconnect } from "@apibara/indexer";
2
2
  import { createClient } from "@apibara/protocol";
3
3
  import { defineCommand, runMain } from "citty";
4
+ import consola from "consola";
4
5
  import { createIndexer } from "./internal/app.mjs";
5
6
  const startCommand = defineCommand({
6
7
  meta: {
@@ -21,6 +22,10 @@ const startCommand = defineCommand({
21
22
  async run({ args }) {
22
23
  const { indexer, preset } = args;
23
24
  const indexerInstance = createIndexer(indexer, preset);
25
+ if (!indexerInstance) {
26
+ consola.error(`Specified indexer "${indexer}" but it was not defined`);
27
+ process.exit(1);
28
+ }
24
29
  const client = createClient(
25
30
  indexerInstance.streamConfig,
26
31
  indexerInstance.options.streamUrl
@@ -65,6 +65,8 @@ interface ApibaraOptions<T extends Record<string, DeepPartial<Pick<ApibaraConfig
65
65
  sourceMap?: boolean;
66
66
  entry: string;
67
67
  commonJS?: RollupCommonJSOptions;
68
+ node: boolean;
69
+ exportConditions?: string[];
68
70
  typescript: {
69
71
  strict?: boolean;
70
72
  internalPaths?: boolean;
@@ -65,6 +65,8 @@ interface ApibaraOptions<T extends Record<string, DeepPartial<Pick<ApibaraConfig
65
65
  sourceMap?: boolean;
66
66
  entry: string;
67
67
  commonJS?: RollupCommonJSOptions;
68
+ node: boolean;
69
+ exportConditions?: string[];
68
70
  typescript: {
69
71
  strict?: boolean;
70
72
  internalPaths?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apibara",
3
- "version": "2.1.0-beta.5",
3
+ "version": "2.1.0-beta.6",
4
4
  "type": "module",
5
5
  "main": "./dist/core/index.mjs",
6
6
  "exports": {
@@ -76,7 +76,7 @@
76
76
  "playground:start": "pnpm playground start --dir playground --indexer starknet"
77
77
  },
78
78
  "devDependencies": {
79
- "@apibara/starknet": "2.1.0-beta.5",
79
+ "@apibara/starknet": "2.1.0-beta.6",
80
80
  "@types/fs-extra": "^11.0.4",
81
81
  "@types/node": "^20.14.0",
82
82
  "@types/prompts": "^2.4.9",
@@ -87,8 +87,8 @@
87
87
  "vitest": "^1.6.0"
88
88
  },
89
89
  "dependencies": {
90
- "@apibara/indexer": "2.1.0-beta.5",
91
- "@apibara/protocol": "2.1.0-beta.5",
90
+ "@apibara/indexer": "2.1.0-beta.6",
91
+ "@apibara/protocol": "2.1.0-beta.6",
92
92
  "@rollup/plugin-commonjs": "^26.0.1",
93
93
  "@rollup/plugin-json": "^6.1.0",
94
94
  "@rollup/plugin-node-resolve": "^15.2.3",
@@ -99,7 +99,6 @@
99
99
  "citty": "^0.1.6",
100
100
  "consola": "^3.2.3",
101
101
  "defu": "^6.1.4",
102
- "esbuild": "^0.23.0",
103
102
  "fs-extra": "^11.2.0",
104
103
  "hookable": "^5.5.3",
105
104
  "klona": "^2.0.6",
@@ -111,8 +110,7 @@
111
110
  "pkg-types": "^1.1.3",
112
111
  "prettier": "^3.5.2",
113
112
  "prompts": "^2.4.2",
114
- "rollup": "^4.18.1",
115
- "rollup-plugin-esbuild": "^6.1.1",
113
+ "rollup": "^4.34.8",
116
114
  "ts-morph": "^25.0.1",
117
115
  "tslib": "^2.6.3",
118
116
  "untyped": "^1.4.2"
@@ -1,10 +1,7 @@
1
- import type esbuild from "esbuild";
2
1
  import { isAbsolute, relative } from "pathe";
3
2
  import type rollup from "rollup";
4
3
 
5
- export function formatRollupError(
6
- _error: rollup.RollupError | esbuild.OnResolveResult,
7
- ) {
4
+ export function formatRollupError(_error: rollup.RollupError) {
8
5
  try {
9
6
  const logs: string[] = [_error.toString()];
10
7
  // biome-ignore lint/suspicious/noExplicitAny: <explanation>
@@ -12,15 +9,11 @@ export function formatRollupError(
12
9
  for (const error of errors) {
13
10
  const id = error.path || error.id || (_error as rollup.RollupError).id;
14
11
  let path = isAbsolute(id) ? relative(process.cwd(), id) : id;
15
- const location =
16
- (error as rollup.RollupError).loc ||
17
- (error as esbuild.PartialMessage).location;
12
+ const location = (error as rollup.RollupError).loc;
18
13
  if (location) {
19
14
  path += `:${location.line}:${location.column}`;
20
15
  }
21
- const text =
22
- (error as esbuild.PartialMessage).text ||
23
- (error as rollup.RollupError).frame;
16
+ const text = (error as rollup.RollupError).frame;
24
17
 
25
18
  logs.push(
26
19
  `Rollup error while processing \`${path}\`` + text ? "\n\n" + text : "",
@@ -14,4 +14,7 @@ export const ApibaraDefaults: ApibaraConfig = {
14
14
  generateRuntimeConfigTypes: true,
15
15
  internalPaths: false,
16
16
  },
17
+
18
+ node: true,
19
+ exportConditions: ["node"],
17
20
  };
@@ -76,10 +76,12 @@ export function getRollupConfig(apibara: Apibara): RollupConfig {
76
76
  rollupConfig.plugins.push(
77
77
  nodeResolve({
78
78
  extensions,
79
- preferBuiltins: true,
79
+ preferBuiltins: !!apibara.options.node,
80
80
  mainFields: ["main"],
81
+ exportConditions: apibara.options.exportConditions,
81
82
  }),
82
83
  );
84
+
83
85
  rollupConfig.plugins.push(indexers(apibara));
84
86
  rollupConfig.plugins.push(appConfig(apibara));
85
87
 
@@ -7,7 +7,7 @@ export function indexers(apibara: Apibara) {
7
7
 
8
8
  return virtual({
9
9
  "#apibara-internal-virtual/indexers": `
10
- ${indexers.map((i) => `import _${hash(i)} from '${i.indexer}';`).join("\n")}
10
+ ${indexers.map((i) => `import * as _${hash(i)} from '${i.indexer}';`).join("\n")}
11
11
 
12
12
  export const indexers = [
13
13
  ${indexers.map((i) => `{ name: "${i.name}", indexer: _${hash(i)} }`).join(",\n")}
@@ -37,6 +37,9 @@ const startCommand = defineCommand({
37
37
  await Promise.all(
38
38
  selectedIndexers.map(async (indexer) => {
39
39
  const indexerInstance = createIndexer(indexer, preset);
40
+ if (!indexerInstance) {
41
+ return;
42
+ }
40
43
 
41
44
  const client = createClient(
42
45
  indexerInstance.streamConfig,
@@ -8,6 +8,7 @@ import {
8
8
  inMemoryPersistence,
9
9
  logger,
10
10
  } from "@apibara/indexer/plugins";
11
+ import consola from "consola";
11
12
  import { config } from "#apibara-internal-virtual/config";
12
13
  import { indexers } from "#apibara-internal-virtual/indexers";
13
14
  import { createLogger } from "./logger";
@@ -42,10 +43,18 @@ export function createIndexer(indexerName: string, preset?: string) {
42
43
  );
43
44
  }
44
45
 
46
+ const indexerModule = indexerDefinition.indexer?.default;
47
+ if (indexerModule === undefined) {
48
+ consola.warn(
49
+ `Specified indexer "${indexerName}" but it does not export a default. Ignoring.`,
50
+ );
51
+ return;
52
+ }
53
+
45
54
  const definition =
46
- typeof indexerDefinition.indexer === "function"
47
- ? indexerDefinition.indexer(runtimeConfig)
48
- : indexerDefinition.indexer;
55
+ typeof indexerModule === "function"
56
+ ? indexerModule(runtimeConfig)
57
+ : indexerModule;
49
58
 
50
59
  let reporter: ConsolaReporter = createLogger({
51
60
  indexer: indexerName,
@@ -1,6 +1,7 @@
1
1
  import { runWithReconnect } from "@apibara/indexer";
2
2
  import { createClient } from "@apibara/protocol";
3
3
  import { defineCommand, runMain } from "citty";
4
+ import consola from "consola";
4
5
  import { createIndexer } from "./internal/app";
5
6
 
6
7
  const startCommand = defineCommand({
@@ -23,6 +24,10 @@ const startCommand = defineCommand({
23
24
  const { indexer, preset } = args;
24
25
 
25
26
  const indexerInstance = createIndexer(indexer, preset);
27
+ if (!indexerInstance) {
28
+ consola.error(`Specified indexer "${indexer}" but it was not defined`);
29
+ process.exit(1);
30
+ }
26
31
 
27
32
  const client = createClient(
28
33
  indexerInstance.streamConfig,
@@ -84,6 +84,8 @@ export interface ApibaraOptions<
84
84
  sourceMap?: boolean;
85
85
  entry: string;
86
86
  commonJS?: RollupCommonJSOptions;
87
+ node: boolean;
88
+ exportConditions?: string[];
87
89
 
88
90
  // Advanced
89
91
  typescript: {
@@ -7,4 +7,7 @@ export type IndexerConstructor =
7
7
  ) => IndexerWithStreamConfig<unknown, unknown, unknown>)
8
8
  | IndexerWithStreamConfig<unknown, unknown, unknown>;
9
9
 
10
- export const indexers: { name: string; indexer: IndexerConstructor }[] = [];
10
+ export const indexers: {
11
+ name: string;
12
+ indexer: { default?: IndexerConstructor | undefined };
13
+ }[] = [];