apibara 2.0.0-beta.9 → 2.1.0-beta.10

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 (90) hide show
  1. package/dist/chunks/add.mjs +49 -0
  2. package/dist/chunks/build.mjs +3 -3
  3. package/dist/chunks/dev.mjs +41 -19
  4. package/dist/chunks/init.mjs +37 -0
  5. package/dist/chunks/prepare.mjs +0 -2
  6. package/dist/chunks/start.mjs +56 -0
  7. package/dist/cli/index.mjs +5 -1
  8. package/dist/config/index.d.mts +1 -1
  9. package/dist/config/index.d.ts +1 -1
  10. package/dist/core/index.mjs +127 -134
  11. package/dist/create/index.d.mts +18 -0
  12. package/dist/create/index.d.ts +18 -0
  13. package/dist/create/index.mjs +1025 -0
  14. package/dist/rolldown/index.d.mts +7 -0
  15. package/dist/rolldown/index.d.ts +7 -0
  16. package/dist/rolldown/index.mjs +90 -0
  17. package/dist/runtime/dev.d.ts +3 -0
  18. package/dist/runtime/dev.mjs +58 -0
  19. package/dist/runtime/index.d.ts +2 -0
  20. package/dist/runtime/index.mjs +2 -0
  21. package/dist/runtime/internal/app.d.ts +2 -0
  22. package/dist/runtime/internal/app.mjs +64 -0
  23. package/dist/runtime/internal/logger.d.ts +14 -0
  24. package/dist/runtime/internal/logger.mjs +45 -0
  25. package/dist/runtime/start.d.ts +3 -0
  26. package/dist/runtime/start.mjs +46 -0
  27. package/dist/types/index.d.mts +35 -29
  28. package/dist/types/index.d.ts +35 -29
  29. package/package.json +40 -22
  30. package/runtime-meta.d.ts +2 -0
  31. package/runtime-meta.mjs +7 -0
  32. package/src/cli/commands/add.ts +50 -0
  33. package/src/cli/commands/build.ts +5 -3
  34. package/src/cli/commands/dev.ts +50 -19
  35. package/src/cli/commands/init.ts +36 -0
  36. package/src/cli/commands/prepare.ts +0 -2
  37. package/src/cli/commands/start.ts +61 -0
  38. package/src/cli/index.ts +3 -0
  39. package/src/config/index.ts +5 -4
  40. package/src/core/apibara.ts +4 -2
  41. package/src/core/build/build.ts +15 -5
  42. package/src/core/build/dev.ts +44 -22
  43. package/src/core/build/error.ts +9 -15
  44. package/src/core/build/prepare.ts +5 -2
  45. package/src/core/build/prod.ts +24 -15
  46. package/src/core/build/types.ts +12 -95
  47. package/src/core/config/defaults.ts +4 -4
  48. package/src/core/config/loader.ts +1 -0
  49. package/src/core/config/resolvers/runtime-config.resolver.ts +1 -1
  50. package/src/core/config/update.ts +3 -4
  51. package/src/core/path.ts +11 -0
  52. package/src/core/scan.ts +40 -0
  53. package/src/create/add.ts +239 -0
  54. package/src/create/colors.ts +15 -0
  55. package/src/create/constants.ts +97 -0
  56. package/src/create/index.ts +2 -0
  57. package/src/create/init.ts +178 -0
  58. package/src/create/templates.ts +501 -0
  59. package/src/create/types.ts +34 -0
  60. package/src/create/utils.ts +422 -0
  61. package/src/rolldown/config.ts +83 -0
  62. package/src/rolldown/index.ts +2 -0
  63. package/src/rolldown/plugins/config.ts +13 -0
  64. package/src/rolldown/plugins/indexers.ts +17 -0
  65. package/src/runtime/dev.ts +67 -0
  66. package/src/runtime/index.ts +2 -0
  67. package/src/runtime/internal/app.ts +86 -0
  68. package/src/runtime/internal/logger.ts +70 -0
  69. package/src/runtime/start.ts +53 -0
  70. package/src/types/apibara.ts +8 -0
  71. package/src/types/config.ts +37 -31
  72. package/src/types/hooks.ts +8 -4
  73. package/src/types/index.ts +1 -1
  74. package/src/types/rolldown.ts +5 -0
  75. package/src/types/virtual/config.d.ts +3 -0
  76. package/src/types/virtual/indexers.d.ts +13 -0
  77. package/dist/internal/citty/index.d.mts +0 -1
  78. package/dist/internal/citty/index.d.ts +0 -1
  79. package/dist/internal/citty/index.mjs +0 -1
  80. package/dist/internal/consola/index.d.mts +0 -2
  81. package/dist/internal/consola/index.d.ts +0 -2
  82. package/dist/internal/consola/index.mjs +0 -1
  83. package/dist/rollup/index.d.mts +0 -5
  84. package/dist/rollup/index.d.ts +0 -5
  85. package/dist/rollup/index.mjs +0 -187
  86. package/src/internal/citty/index.ts +0 -1
  87. package/src/internal/consola/index.ts +0 -1
  88. package/src/rollup/config.ts +0 -209
  89. package/src/rollup/index.ts +0 -1
  90. package/src/types/rollup.ts +0 -8
@@ -1,209 +0,0 @@
1
- import { existsSync } from "node:fs";
2
- import { builtinModules } from "node:module";
3
- import commonjs from "@rollup/plugin-commonjs";
4
- import json from "@rollup/plugin-json";
5
- import { nodeResolve } from "@rollup/plugin-node-resolve";
6
- import typescript from "@rollup/plugin-typescript";
7
- import type { Apibara, RollupConfig } from "apibara/types";
8
- import fsExtra from "fs-extra";
9
- import { basename, join } from "pathe";
10
-
11
- export const getRollupConfig = (
12
- apibara: Apibara,
13
- dev = false,
14
- ): RollupConfig => {
15
- const extensions: string[] = [
16
- ".ts",
17
- ".mjs",
18
- ".js",
19
- ".json",
20
- ".node",
21
- ".tsx",
22
- ".jsx",
23
- ];
24
-
25
- const indexerDir = join(apibara.options.rootDir, "indexers");
26
- const configPath = join(apibara.options.rootDir, "./apibara.config.ts");
27
-
28
- // Check if the indexers directory and config file exist
29
- if (!existsSync(indexerDir)) {
30
- throw new Error(`Indexers directory not found: ${indexerDir}`);
31
- }
32
- if (!existsSync(configPath)) {
33
- throw new Error(`Config file not found: ${configPath}`);
34
- }
35
-
36
- // Check if the indexers directory exists and is not empty
37
- let indexerFiles: string[] = [];
38
- try {
39
- indexerFiles = fsExtra
40
- .readdirSync(indexerDir)
41
- .filter((file) => file.endsWith(".indexer.ts"));
42
- if (indexerFiles.length === 0) {
43
- console.warn(`No indexer files found in ${indexerDir}`);
44
- }
45
- } catch (error) {
46
- console.error(`Error reading indexers directory: ${error}`);
47
- }
48
-
49
- const indexerImports = indexerFiles
50
- .map(
51
- (file, index) =>
52
- `import indexer${index} from '${join(indexerDir, file)}';`,
53
- )
54
- .join("\n");
55
-
56
- // Generate main.ts content
57
- const mainContent = `
58
- import { createClient } from "@apibara/protocol";
59
- import { createIndexer, run } from "@apibara/indexer";
60
- import { consola as _consola } from "apibara/internal/consola";
61
- import { defineCommand, runMain } from "apibara/internal/citty";
62
- import config from './${configPath}';
63
-
64
- const consola = _consola.withTag("Apibara | ");
65
-
66
- ${indexerImports}
67
-
68
- const indexers = {
69
- ${indexerFiles
70
- .map(
71
- (file, index) => `'${basename(file, ".indexer.ts")}': indexer${index},`,
72
- )
73
- .join("\n ")}
74
- };
75
-
76
- const command = defineCommand({
77
- meta: {
78
- name: "run-indexers",
79
- description: "Run Apibara indexers",
80
- },
81
- args: {
82
- indexers: {
83
- type: "string",
84
- description: "Comma-separated list of indexers to run",
85
- },
86
- preset: {
87
- type: "string",
88
- description: "Preset to use",
89
- },
90
- sink: {
91
- type: "string",
92
- description: "Sink to use",
93
- },
94
- },
95
- async run({ args }) {
96
- const selectedIndexers = args.indexers ? args.indexers.split(',') : Object.keys(indexers);
97
- const preset = args.preset || config.preset || 'default';
98
- const sinkName = args.sink || 'default';
99
-
100
- // Apply preset
101
- let runtimeConfig = { ...config.runtimeConfig };
102
- if (preset && config.presets && config.presets[preset]) {
103
- runtimeConfig = { ...runtimeConfig, ...config.presets[preset].runtimeConfig };
104
- }
105
-
106
- // Get sink function
107
- const sinkFunction = config.sink?.[sinkName];
108
- if (!sinkFunction) {
109
- throw new Error(\`Sink \${sinkName} not found\`);
110
- }
111
-
112
- await Promise.all(selectedIndexers.map(async (name) => {
113
- if (!indexers[name]) {
114
- console.error(\`Indexer \${name} not found\`);
115
- return;
116
- }
117
-
118
- const indexerConfig = indexers[name]
119
- const indexer = typeof indexerConfig === 'function'
120
- ? await createIndexer(indexerConfig(runtimeConfig))
121
- : createIndexer(indexerConfig);
122
-
123
- const client = createClient(indexer.streamConfig, indexer.options.streamUrl);
124
- const sink = sinkFunction();
125
-
126
- try {
127
- consola.log("Running Indexer: ", name);
128
- await run(client, indexer, sink);
129
- } catch (error) {
130
- consola.error(\`Error in indexer \${name}:\`, error);
131
- }
132
- }));
133
- },
134
- });
135
-
136
- runMain(command);
137
- `;
138
-
139
- return {
140
- input: {
141
- main: "virtual:main.ts",
142
- },
143
- output: {
144
- dir: join(apibara.options.outputDir || "./.apibara/build"),
145
- format: "esm",
146
- exports: "auto",
147
- entryFileNames: "[name].mjs",
148
- chunkFileNames: "chunks/[name]-[hash].mjs",
149
- generatedCode: {
150
- constBindings: true,
151
- },
152
- sourcemap: true,
153
- sourcemapExcludeSources: true,
154
- sourcemapIgnoreList(relativePath, sourcemapPath) {
155
- return relativePath.includes("node_modules");
156
- },
157
- },
158
- plugins: [
159
- {
160
- name: "virtual",
161
- resolveId(id) {
162
- if (id === "virtual:main.ts") {
163
- return id;
164
- }
165
- return null;
166
- },
167
- load(id) {
168
- if (id === "virtual:main.ts") {
169
- return mainContent;
170
- }
171
- return null;
172
- },
173
- },
174
- nodeResolve({
175
- extensions,
176
- preferBuiltins: true,
177
- }),
178
- commonjs(),
179
- json(),
180
- typescript({
181
- tsconfig: join(apibara.options.rootDir, "./tsconfig.json"),
182
- compilerOptions: {
183
- outDir: join(apibara.options.outputDir || "./.apibara/build"),
184
- declarationDir: join(apibara.options.outputDir || "./.apibara/build"),
185
- noEmit: false,
186
- types: ["node"],
187
- },
188
- }),
189
- ],
190
- onwarn(warning, rollupWarn) {
191
- if (
192
- !["CIRCULAR_DEPENDENCY", "EVAL"].includes(warning.code || "") &&
193
- !warning.message.includes("Unsupported source map comment") &&
194
- !warning.message.includes("@__PURE__")
195
- ) {
196
- rollupWarn(warning);
197
- }
198
- },
199
- treeshake: true,
200
- external: [
201
- ...builtinModules,
202
- "@apibara/indexer",
203
- "@apibara/protocol",
204
- "@apibara/evm",
205
- "@apibara/starknet",
206
- "@apibara/beaconchain",
207
- ],
208
- };
209
- };
@@ -1 +0,0 @@
1
- export * from "./config";
@@ -1,8 +0,0 @@
1
- import type {
2
- InputOptions as RollupInputOptions,
3
- OutputOptions as RollupOutputOptions,
4
- } from "rollup";
5
-
6
- export type RollupConfig = RollupInputOptions & {
7
- output: RollupOutputOptions;
8
- };