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.
- package/dist/chunks/add.mjs +49 -0
- package/dist/chunks/build.mjs +3 -3
- package/dist/chunks/dev.mjs +41 -19
- package/dist/chunks/init.mjs +37 -0
- package/dist/chunks/prepare.mjs +0 -2
- package/dist/chunks/start.mjs +56 -0
- package/dist/cli/index.mjs +5 -1
- package/dist/config/index.d.mts +1 -1
- package/dist/config/index.d.ts +1 -1
- package/dist/core/index.mjs +127 -134
- package/dist/create/index.d.mts +18 -0
- package/dist/create/index.d.ts +18 -0
- package/dist/create/index.mjs +1025 -0
- package/dist/rolldown/index.d.mts +7 -0
- package/dist/rolldown/index.d.ts +7 -0
- package/dist/rolldown/index.mjs +90 -0
- package/dist/runtime/dev.d.ts +3 -0
- package/dist/runtime/dev.mjs +58 -0
- package/dist/runtime/index.d.ts +2 -0
- package/dist/runtime/index.mjs +2 -0
- package/dist/runtime/internal/app.d.ts +2 -0
- package/dist/runtime/internal/app.mjs +64 -0
- package/dist/runtime/internal/logger.d.ts +14 -0
- package/dist/runtime/internal/logger.mjs +45 -0
- package/dist/runtime/start.d.ts +3 -0
- package/dist/runtime/start.mjs +46 -0
- package/dist/types/index.d.mts +35 -29
- package/dist/types/index.d.ts +35 -29
- package/package.json +40 -22
- package/runtime-meta.d.ts +2 -0
- package/runtime-meta.mjs +7 -0
- package/src/cli/commands/add.ts +50 -0
- package/src/cli/commands/build.ts +5 -3
- package/src/cli/commands/dev.ts +50 -19
- package/src/cli/commands/init.ts +36 -0
- package/src/cli/commands/prepare.ts +0 -2
- package/src/cli/commands/start.ts +61 -0
- package/src/cli/index.ts +3 -0
- package/src/config/index.ts +5 -4
- package/src/core/apibara.ts +4 -2
- package/src/core/build/build.ts +15 -5
- package/src/core/build/dev.ts +44 -22
- package/src/core/build/error.ts +9 -15
- package/src/core/build/prepare.ts +5 -2
- package/src/core/build/prod.ts +24 -15
- package/src/core/build/types.ts +12 -95
- package/src/core/config/defaults.ts +4 -4
- package/src/core/config/loader.ts +1 -0
- package/src/core/config/resolvers/runtime-config.resolver.ts +1 -1
- package/src/core/config/update.ts +3 -4
- package/src/core/path.ts +11 -0
- package/src/core/scan.ts +40 -0
- package/src/create/add.ts +239 -0
- package/src/create/colors.ts +15 -0
- package/src/create/constants.ts +97 -0
- package/src/create/index.ts +2 -0
- package/src/create/init.ts +178 -0
- package/src/create/templates.ts +501 -0
- package/src/create/types.ts +34 -0
- package/src/create/utils.ts +422 -0
- package/src/rolldown/config.ts +83 -0
- package/src/rolldown/index.ts +2 -0
- package/src/rolldown/plugins/config.ts +13 -0
- package/src/rolldown/plugins/indexers.ts +17 -0
- package/src/runtime/dev.ts +67 -0
- package/src/runtime/index.ts +2 -0
- package/src/runtime/internal/app.ts +86 -0
- package/src/runtime/internal/logger.ts +70 -0
- package/src/runtime/start.ts +53 -0
- package/src/types/apibara.ts +8 -0
- package/src/types/config.ts +37 -31
- package/src/types/hooks.ts +8 -4
- package/src/types/index.ts +1 -1
- package/src/types/rolldown.ts +5 -0
- package/src/types/virtual/config.d.ts +3 -0
- package/src/types/virtual/indexers.d.ts +13 -0
- package/dist/internal/citty/index.d.mts +0 -1
- package/dist/internal/citty/index.d.ts +0 -1
- package/dist/internal/citty/index.mjs +0 -1
- package/dist/internal/consola/index.d.mts +0 -2
- package/dist/internal/consola/index.d.ts +0 -2
- package/dist/internal/consola/index.mjs +0 -1
- package/dist/rollup/index.d.mts +0 -5
- package/dist/rollup/index.d.ts +0 -5
- package/dist/rollup/index.mjs +0 -187
- package/src/internal/citty/index.ts +0 -1
- package/src/internal/consola/index.ts +0 -1
- package/src/rollup/config.ts +0 -209
- package/src/rollup/index.ts +0 -1
- package/src/types/rollup.ts +0 -8
package/src/rollup/config.ts
DELETED
|
@@ -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
|
-
};
|
package/src/rollup/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./config";
|