apibara 2.1.0-beta.1 → 2.1.0-beta.11
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 +12 -7
- package/dist/chunks/dev.mjs +25 -6
- package/dist/chunks/init.mjs +3 -7
- package/dist/chunks/start.mjs +2 -1
- package/dist/core/index.mjs +85 -42
- package/dist/create/index.d.mts +2 -1
- package/dist/create/index.d.ts +2 -1
- package/dist/create/index.mjs +185 -121
- package/dist/hooks/index.mjs +3 -1
- package/dist/rolldown/index.d.mts +7 -0
- package/dist/rolldown/index.d.ts +7 -0
- package/dist/rolldown/index.mjs +126 -0
- package/dist/runtime/dev.mjs +3 -0
- package/dist/runtime/internal/app.d.ts +1 -1
- package/dist/runtime/internal/app.mjs +12 -11
- package/dist/runtime/start.mjs +5 -0
- package/dist/shared/apibara.af330c7d.mjs +15 -0
- package/dist/types/index.d.mts +18 -15
- package/dist/types/index.d.ts +18 -15
- package/package.json +13 -15
- package/src/cli/commands/add.ts +12 -6
- package/src/cli/commands/dev.ts +27 -5
- package/src/cli/commands/init.ts +3 -7
- package/src/cli/commands/start.ts +1 -0
- package/src/core/build/build.ts +13 -5
- package/src/core/build/dev.ts +44 -23
- package/src/core/build/error.ts +9 -14
- package/src/core/build/prod.ts +15 -10
- package/src/core/build/types.ts +8 -0
- package/src/core/config/defaults.ts +3 -0
- package/src/core/config/resolvers/runtime-config.resolver.ts +21 -2
- package/src/core/config/update.ts +1 -1
- package/src/create/add.ts +26 -12
- package/src/create/constants.ts +9 -10
- package/src/create/init.ts +28 -14
- package/src/create/templates.ts +154 -118
- package/src/create/utils.ts +10 -0
- package/src/hooks/useRuntimeConfig.ts +2 -1
- package/src/rolldown/config.ts +108 -0
- package/src/rolldown/index.ts +2 -0
- package/src/rolldown/plugins/config.ts +25 -0
- package/src/{rollup → rolldown}/plugins/indexers.ts +3 -3
- package/src/runtime/dev.ts +3 -0
- package/src/runtime/internal/app.ts +30 -13
- package/src/runtime/start.ts +5 -0
- package/src/types/config.ts +12 -7
- package/src/types/hooks.ts +8 -5
- package/src/types/index.ts +1 -1
- package/src/types/rolldown.ts +5 -0
- package/src/types/virtual/config.d.ts +4 -1
- package/src/types/virtual/indexers.d.ts +4 -1
- package/src/utils/helper.ts +15 -0
- package/dist/rollup/index.d.mts +0 -6
- package/dist/rollup/index.d.ts +0 -6
- package/dist/rollup/index.mjs +0 -150
- package/src/rollup/config.ts +0 -87
- package/src/rollup/index.ts +0 -2
- package/src/rollup/plugins/config.ts +0 -12
- package/src/rollup/plugins/esm-shim.ts +0 -69
- package/src/types/rollup.ts +0 -8
package/src/core/build/prod.ts
CHANGED
|
@@ -1,31 +1,36 @@
|
|
|
1
|
-
import type { Apibara
|
|
1
|
+
import type { Apibara } from "apibara/types";
|
|
2
2
|
import { colors } from "consola/utils";
|
|
3
|
-
import
|
|
3
|
+
import * as rolldown from "rolldown";
|
|
4
4
|
|
|
5
5
|
export async function buildProduction(
|
|
6
6
|
apibara: Apibara,
|
|
7
|
-
|
|
7
|
+
rolldownConfig: rolldown.RolldownOptions,
|
|
8
8
|
) {
|
|
9
9
|
apibara.logger.start(
|
|
10
10
|
`Building ${colors.cyan(apibara.indexers.length)} indexers`,
|
|
11
11
|
);
|
|
12
12
|
|
|
13
|
+
const startTime = Date.now();
|
|
14
|
+
|
|
13
15
|
try {
|
|
14
|
-
const bundle = await
|
|
16
|
+
const bundle = await rolldown.rolldown(rolldownConfig);
|
|
15
17
|
|
|
16
|
-
if (Array.isArray(
|
|
17
|
-
for (const outputOptions of
|
|
18
|
+
if (Array.isArray(rolldownConfig.output)) {
|
|
19
|
+
for (const outputOptions of rolldownConfig.output) {
|
|
18
20
|
await bundle.write(outputOptions);
|
|
19
21
|
}
|
|
20
|
-
} else if (
|
|
21
|
-
await bundle.write(
|
|
22
|
+
} else if (rolldownConfig.output) {
|
|
23
|
+
await bundle.write(rolldownConfig.output as rolldown.OutputOptions);
|
|
22
24
|
} else {
|
|
23
|
-
throw new Error("No output options specified in
|
|
25
|
+
throw new Error("No output options specified in Rolldown config");
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
await bundle.close();
|
|
27
29
|
|
|
28
|
-
|
|
30
|
+
const endTime = Date.now();
|
|
31
|
+
const duration = endTime - startTime;
|
|
32
|
+
|
|
33
|
+
apibara.logger.success(`Build succeeded in ${duration}ms`);
|
|
29
34
|
apibara.logger.info(
|
|
30
35
|
`You can start the indexers with ${colors.cyan("apibara start")}`,
|
|
31
36
|
);
|
package/src/core/build/types.ts
CHANGED
|
@@ -5,6 +5,14 @@ import { type JSValue, generateTypes, resolveSchema } from "untyped";
|
|
|
5
5
|
import { prettyPath } from "../path";
|
|
6
6
|
|
|
7
7
|
export async function writeTypes(apibara: Apibara) {
|
|
8
|
+
// Check if the config file has a TypeScript extension so we assume it's a TypeScript project
|
|
9
|
+
const isTypeScript = apibara.options._c12.configFile?.endsWith(".ts");
|
|
10
|
+
|
|
11
|
+
if (!isTypeScript) {
|
|
12
|
+
// If it's not a TypeScript project, we don't need to generate the types
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
8
16
|
const typesDir = resolve(apibara.options.buildDir, "types");
|
|
9
17
|
|
|
10
18
|
const config = [
|
|
@@ -1,6 +1,25 @@
|
|
|
1
1
|
import type { ApibaraOptions } from "apibara/types";
|
|
2
|
+
import { serialize } from "../../../utils/helper";
|
|
2
3
|
|
|
3
4
|
export async function resolveRuntimeConfigOptions(options: ApibaraOptions) {
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
const { preset, presets } = options;
|
|
6
|
+
let runtimeConfig: Record<string, unknown> = { ...options.runtimeConfig };
|
|
7
|
+
|
|
8
|
+
if (preset) {
|
|
9
|
+
if (presets === undefined) {
|
|
10
|
+
throw new Error(
|
|
11
|
+
`Specified preset "${preset}" but no presets were defined`,
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (presets[preset] === undefined) {
|
|
16
|
+
throw new Error(`Specified preset "${preset}" but it was not defined`);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const presetValue = presets[preset] as {
|
|
20
|
+
runtimeConfig: Record<string, unknown>;
|
|
21
|
+
};
|
|
22
|
+
runtimeConfig = { ...runtimeConfig, ...presetValue.runtimeConfig };
|
|
23
|
+
}
|
|
24
|
+
process.env.APIBARA_RUNTIME_CONFIG = serialize(runtimeConfig);
|
|
6
25
|
}
|
package/src/create/add.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import path from "node:path";
|
|
1
2
|
import consola from "consola";
|
|
2
3
|
import prompts from "prompts";
|
|
3
4
|
import { cyan, red, reset } from "./colors";
|
|
@@ -18,6 +19,7 @@ import {
|
|
|
18
19
|
import type { Chain, IndexerOptions, Network, Storage } from "./types";
|
|
19
20
|
import {
|
|
20
21
|
cancelOperation,
|
|
22
|
+
checkFileExists,
|
|
21
23
|
convertKebabToCamelCase,
|
|
22
24
|
getApibaraConfigLanguage,
|
|
23
25
|
getPackageManager,
|
|
@@ -35,6 +37,7 @@ type Options = {
|
|
|
35
37
|
argNetwork?: string;
|
|
36
38
|
argStorage?: string;
|
|
37
39
|
argDnaUrl?: string;
|
|
40
|
+
argRootDir?: string;
|
|
38
41
|
};
|
|
39
42
|
|
|
40
43
|
export async function addIndexer({
|
|
@@ -43,8 +46,10 @@ export async function addIndexer({
|
|
|
43
46
|
argNetwork,
|
|
44
47
|
argStorage,
|
|
45
48
|
argDnaUrl,
|
|
49
|
+
argRootDir,
|
|
46
50
|
}: Options) {
|
|
47
|
-
const
|
|
51
|
+
const cwd = path.join(process.cwd(), argRootDir ?? ".");
|
|
52
|
+
const configExists = hasApibaraConfig(cwd);
|
|
48
53
|
|
|
49
54
|
if (!configExists) {
|
|
50
55
|
consola.error("No apibara.config found in the current directory.");
|
|
@@ -72,7 +77,7 @@ export async function addIndexer({
|
|
|
72
77
|
}
|
|
73
78
|
}
|
|
74
79
|
|
|
75
|
-
const language = getApibaraConfigLanguage(
|
|
80
|
+
const language = getApibaraConfigLanguage(cwd);
|
|
76
81
|
|
|
77
82
|
validateIndexerId(argIndexerId, true);
|
|
78
83
|
validateChain(argChain, true);
|
|
@@ -88,8 +93,19 @@ export async function addIndexer({
|
|
|
88
93
|
message: reset("Indexer ID:"),
|
|
89
94
|
initial: argIndexerId ?? "my-indexer",
|
|
90
95
|
validate: (id) =>
|
|
91
|
-
validateIndexerId(id)
|
|
92
|
-
|
|
96
|
+
validateIndexerId(id)
|
|
97
|
+
? checkFileExists(
|
|
98
|
+
path.join(
|
|
99
|
+
cwd,
|
|
100
|
+
"indexers",
|
|
101
|
+
`${id}.indexer.${language === "typescript" ? "ts" : "js"}`,
|
|
102
|
+
),
|
|
103
|
+
).then(({ exists }) =>
|
|
104
|
+
exists
|
|
105
|
+
? `Indexer ${cyan(`${id}.indexer.${language === "typescript" ? "ts" : "js"}`)} already exists`
|
|
106
|
+
: true,
|
|
107
|
+
)
|
|
108
|
+
: "Invalid indexer ID, it cannot be empty and must be in kebab-case format",
|
|
93
109
|
},
|
|
94
110
|
{
|
|
95
111
|
type: argChain ? null : "select",
|
|
@@ -184,7 +200,7 @@ export async function addIndexer({
|
|
|
184
200
|
const pkgManager = getPackageManager();
|
|
185
201
|
|
|
186
202
|
const options: IndexerOptions = {
|
|
187
|
-
cwd:
|
|
203
|
+
cwd: cwd,
|
|
188
204
|
indexerFileId,
|
|
189
205
|
indexerId: convertKebabToCamelCase(indexerFileId),
|
|
190
206
|
chain: (argChain as Chain) ?? prompt_chain?.name!,
|
|
@@ -195,13 +211,13 @@ export async function addIndexer({
|
|
|
195
211
|
packageManager: pkgManager.name,
|
|
196
212
|
};
|
|
197
213
|
|
|
198
|
-
updateApibaraConfigFile(options);
|
|
214
|
+
await updateApibaraConfigFile(options);
|
|
199
215
|
|
|
200
216
|
consola.success(
|
|
201
217
|
`Updated ${cyan("apibara.config." + (language === "typescript" ? "ts" : "js"))}`,
|
|
202
218
|
);
|
|
203
219
|
|
|
204
|
-
updatePackageJson(options);
|
|
220
|
+
await updatePackageJson(options);
|
|
205
221
|
|
|
206
222
|
consola.success(`Updated ${cyan("package.json")}`);
|
|
207
223
|
|
|
@@ -215,11 +231,9 @@ export async function addIndexer({
|
|
|
215
231
|
|
|
216
232
|
console.log();
|
|
217
233
|
|
|
234
|
+
const baseCommand = `${options.packageManager} install`;
|
|
235
|
+
const tsCommand = `${baseCommand} && ${options.packageManager} run prepare`;
|
|
218
236
|
consola.info(
|
|
219
|
-
`Before running the indexer, run ${cyan(
|
|
220
|
-
language === "typescript"
|
|
221
|
-
? " & " + cyan(`${options.packageManager} run prepare`)
|
|
222
|
-
: ""
|
|
223
|
-
}`,
|
|
237
|
+
`Before running the indexer, run ${cyan(language === "typescript" ? tsCommand : baseCommand)}`,
|
|
224
238
|
);
|
|
225
239
|
}
|
package/src/create/constants.ts
CHANGED
|
@@ -66,17 +66,17 @@ export const storages: StorageDataType[] = [
|
|
|
66
66
|
|
|
67
67
|
export const packageVersions = {
|
|
68
68
|
// Required Dependencies
|
|
69
|
-
apibara: "
|
|
70
|
-
"@apibara/indexer": "
|
|
71
|
-
"@apibara/protocol": "
|
|
69
|
+
apibara: "next",
|
|
70
|
+
"@apibara/indexer": "next",
|
|
71
|
+
"@apibara/protocol": "next",
|
|
72
72
|
// Chain Dependencies
|
|
73
|
-
"@apibara/evm": "
|
|
74
|
-
"@apibara/beaconchain": "
|
|
75
|
-
"@apibara/starknet": "
|
|
73
|
+
"@apibara/evm": "next",
|
|
74
|
+
"@apibara/beaconchain": "next",
|
|
75
|
+
"@apibara/starknet": "next",
|
|
76
76
|
// Storage Dependencies
|
|
77
|
-
"@apibara/plugin-drizzle": "
|
|
78
|
-
"@apibara/plugin-mongo": "
|
|
79
|
-
"@apibara/plugin-sqlite": "
|
|
77
|
+
"@apibara/plugin-drizzle": "next",
|
|
78
|
+
"@apibara/plugin-mongo": "next",
|
|
79
|
+
"@apibara/plugin-sqlite": "next",
|
|
80
80
|
// Postgres Dependencies
|
|
81
81
|
"@electric-sql/pglite": "^0.2.17",
|
|
82
82
|
"drizzle-orm": "^0.37.0",
|
|
@@ -85,7 +85,6 @@ export const packageVersions = {
|
|
|
85
85
|
"drizzle-kit": "^0.29.0",
|
|
86
86
|
// Typescript Dependencies
|
|
87
87
|
typescript: "^5.6.2",
|
|
88
|
-
"@rollup/plugin-typescript": "^11.1.6",
|
|
89
88
|
"@types/node": "^20.5.2",
|
|
90
89
|
};
|
|
91
90
|
|
package/src/create/init.ts
CHANGED
|
@@ -5,6 +5,7 @@ import prompts from "prompts";
|
|
|
5
5
|
import { addIndexer } from "./add";
|
|
6
6
|
import { cyan, green } from "./colors";
|
|
7
7
|
import {
|
|
8
|
+
createGitIgnoreFile,
|
|
8
9
|
generateApibaraConfig,
|
|
9
10
|
generatePackageJson,
|
|
10
11
|
generateTsConfig,
|
|
@@ -13,6 +14,7 @@ import type { Language } from "./types";
|
|
|
13
14
|
import {
|
|
14
15
|
cancelOperation,
|
|
15
16
|
emptyDir,
|
|
17
|
+
formatFile,
|
|
16
18
|
getLanguageFromAlias,
|
|
17
19
|
getPackageManager,
|
|
18
20
|
isEmpty,
|
|
@@ -121,30 +123,42 @@ export async function initializeProject({
|
|
|
121
123
|
consola.info(`Initializing project in ${argTargetDir}\n\n`);
|
|
122
124
|
|
|
123
125
|
// Generate package.json
|
|
126
|
+
const packageJsonPath = path.join(root, "package.json");
|
|
124
127
|
const packageJson = generatePackageJson(isTs);
|
|
125
128
|
fs.writeFileSync(
|
|
126
|
-
|
|
129
|
+
packageJsonPath,
|
|
127
130
|
JSON.stringify(packageJson, null, 2) + "\n",
|
|
128
131
|
);
|
|
129
|
-
|
|
132
|
+
await formatFile(packageJsonPath);
|
|
133
|
+
consola.success("Created", cyan("package.json"));
|
|
130
134
|
|
|
131
135
|
// Generate tsconfig.json if TypeScript
|
|
132
136
|
if (isTs) {
|
|
137
|
+
const tsConfigPath = path.join(root, "tsconfig.json");
|
|
133
138
|
const tsConfig = generateTsConfig();
|
|
134
|
-
fs.writeFileSync(
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
);
|
|
138
|
-
consola.success("Created ", cyan("tsconfig.json"));
|
|
139
|
+
fs.writeFileSync(tsConfigPath, JSON.stringify(tsConfig, null, 2) + "\n");
|
|
140
|
+
await formatFile(tsConfigPath);
|
|
141
|
+
consola.success("Created", cyan("tsconfig.json"));
|
|
139
142
|
}
|
|
140
143
|
|
|
144
|
+
const apibaraConfigPath = path.join(root, `apibara.config.${configExt}`);
|
|
141
145
|
// Generate apibara.config
|
|
142
146
|
const apibaraConfig = generateApibaraConfig(isTs);
|
|
143
|
-
fs.writeFileSync(
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
147
|
+
fs.writeFileSync(apibaraConfigPath, apibaraConfig);
|
|
148
|
+
await formatFile(apibaraConfigPath);
|
|
149
|
+
consola.success("Created", cyan(`apibara.config.${configExt}`));
|
|
150
|
+
|
|
151
|
+
// Create "indexers" directory if not exists
|
|
152
|
+
const indexersDir = path.join(root, "indexers");
|
|
153
|
+
if (!fs.existsSync(indexersDir)) {
|
|
154
|
+
fs.mkdirSync(indexersDir, { recursive: true });
|
|
155
|
+
consola.success(`Created ${cyan("indexers")} directory`);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
await createGitIgnoreFile(root);
|
|
159
|
+
|
|
160
|
+
console.log("\n");
|
|
161
|
+
|
|
148
162
|
consola.ready(green("Project initialized successfully"));
|
|
149
163
|
|
|
150
164
|
console.log();
|
|
@@ -152,12 +166,12 @@ export async function initializeProject({
|
|
|
152
166
|
if (!argNoCreateIndexer) {
|
|
153
167
|
consola.info("Let's create an indexer\n");
|
|
154
168
|
|
|
155
|
-
await addIndexer({});
|
|
169
|
+
await addIndexer({ argRootDir: argTargetDir });
|
|
156
170
|
} else {
|
|
157
171
|
const pkgManager = getPackageManager();
|
|
158
172
|
consola.info(
|
|
159
173
|
"Run ",
|
|
160
|
-
green(`${pkgManager.name}
|
|
174
|
+
green(`${pkgManager.name} install`),
|
|
161
175
|
" to install all dependencies",
|
|
162
176
|
);
|
|
163
177
|
}
|