apibara 2.1.0-beta.27 → 2.1.0-beta.29
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/write-project-info.mjs +50 -0
- package/dist/cli/index.mjs +2 -1
- package/dist/core/index.mjs +20 -11
- package/dist/rolldown/index.mjs +2 -1
- package/dist/runtime/project-info.d.ts +3 -0
- package/dist/runtime/project-info.mjs +53 -0
- package/dist/types/index.d.mts +1 -0
- package/dist/types/index.d.ts +1 -0
- package/package.json +4 -4
- package/src/cli/commands/write-project-info.ts +56 -0
- package/src/cli/index.ts +2 -0
- package/src/core/apibara.ts +5 -0
- package/src/core/build/prepare.ts +5 -3
- package/src/core/build/prod.ts +11 -7
- package/src/core/build/types.ts +3 -1
- package/src/rolldown/config.ts +2 -1
- package/src/runtime/project-info.ts +72 -0
- package/src/types/config.ts +1 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { createApibara, prepare, writeTypes, build } from 'apibara/core';
|
|
4
|
+
import { runtimeDir } from 'apibara/runtime/meta';
|
|
5
|
+
import { defineCommand } from 'citty';
|
|
6
|
+
import consola from 'consola';
|
|
7
|
+
import { resolve } from 'pathe';
|
|
8
|
+
import { c as commonArgs, a as checkForUnknownArgs } from '../shared/apibara.63c9a277.mjs';
|
|
9
|
+
|
|
10
|
+
const writeProjectInfo = defineCommand({
|
|
11
|
+
meta: {
|
|
12
|
+
name: "write-project-info",
|
|
13
|
+
description: "Write json-encoded information about the project."
|
|
14
|
+
},
|
|
15
|
+
args: {
|
|
16
|
+
...commonArgs
|
|
17
|
+
},
|
|
18
|
+
async run({ args, cmd }) {
|
|
19
|
+
await checkForUnknownArgs(args, cmd);
|
|
20
|
+
consola.start("Generating `project-info.json`");
|
|
21
|
+
const rootDir = resolve(args.dir || ".");
|
|
22
|
+
const apibara = await createApibara({ rootDir, disableLogs: true });
|
|
23
|
+
apibara.options.entry = join(runtimeDir, "project-info.mjs");
|
|
24
|
+
await prepare(apibara);
|
|
25
|
+
await writeTypes(apibara);
|
|
26
|
+
await build(apibara);
|
|
27
|
+
const childArgs = [
|
|
28
|
+
resolve(
|
|
29
|
+
apibara.options.outputDir || "./.apibara/build",
|
|
30
|
+
"project-info.mjs"
|
|
31
|
+
),
|
|
32
|
+
"start",
|
|
33
|
+
"--build-dir",
|
|
34
|
+
apibara.options.buildDir
|
|
35
|
+
];
|
|
36
|
+
const child = spawn("node", childArgs, {
|
|
37
|
+
stdio: "inherit"
|
|
38
|
+
});
|
|
39
|
+
child.on("close", (code) => {
|
|
40
|
+
if (code === 0) {
|
|
41
|
+
consola.success("Project info written to `.apibara/project-info.json`");
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
child.on("error", (error) => {
|
|
45
|
+
consola.error(`Failed to write project info: ${error.message}`, error);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
export { writeProjectInfo as default };
|
package/dist/cli/index.mjs
CHANGED
|
@@ -13,7 +13,8 @@ const mainCli = defineCommand({
|
|
|
13
13
|
start: () => import('../chunks/start.mjs').then((r) => r.default),
|
|
14
14
|
prepare: () => import('../chunks/prepare.mjs').then((r) => r.default),
|
|
15
15
|
init: () => import('../chunks/init.mjs').then((r) => r.default),
|
|
16
|
-
add: () => import('../chunks/add.mjs').then((r) => r.default)
|
|
16
|
+
add: () => import('../chunks/add.mjs').then((r) => r.default),
|
|
17
|
+
"write-project-info": () => import('../chunks/write-project-info.mjs').then((r) => r.default)
|
|
17
18
|
}
|
|
18
19
|
});
|
|
19
20
|
runMain(mainCli);
|
package/dist/core/index.mjs
CHANGED
|
@@ -112,6 +112,7 @@ function indexerNameFromFile(file) {
|
|
|
112
112
|
|
|
113
113
|
async function createApibara(config = {}, opts = {}, dev = false) {
|
|
114
114
|
const options = await loadOptions(config, opts, dev);
|
|
115
|
+
process.env.NODE_OPTIONS = process.env.NODE_OPTIONS ? `${process.env.NODE_OPTIONS} --enable-source-maps` : "--enable-source-maps";
|
|
115
116
|
const apibara = {
|
|
116
117
|
options,
|
|
117
118
|
indexers: [],
|
|
@@ -226,9 +227,11 @@ const getIgnorePatterns = (apibara) => [
|
|
|
226
227
|
];
|
|
227
228
|
|
|
228
229
|
async function buildProduction(apibara, rolldownConfig) {
|
|
229
|
-
apibara.
|
|
230
|
-
|
|
231
|
-
|
|
230
|
+
if (!apibara.options.disableLogs) {
|
|
231
|
+
apibara.logger.start(
|
|
232
|
+
`Building ${colors.cyan(apibara.indexers.length)} indexers`
|
|
233
|
+
);
|
|
234
|
+
}
|
|
232
235
|
const startTime = Date.now();
|
|
233
236
|
try {
|
|
234
237
|
const bundle = await rolldown.rolldown(rolldownConfig);
|
|
@@ -244,10 +247,12 @@ async function buildProduction(apibara, rolldownConfig) {
|
|
|
244
247
|
await bundle.close();
|
|
245
248
|
const endTime = Date.now();
|
|
246
249
|
const duration = endTime - startTime;
|
|
247
|
-
apibara.
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
250
|
+
if (!apibara.options.disableLogs) {
|
|
251
|
+
apibara.logger.success(`Build succeeded in ${duration}ms`);
|
|
252
|
+
apibara.logger.info(
|
|
253
|
+
`You can start the indexers with ${colors.cyan("apibara start")}`
|
|
254
|
+
);
|
|
255
|
+
}
|
|
251
256
|
} catch (error) {
|
|
252
257
|
apibara.logger.error("Build failed", error);
|
|
253
258
|
throw error;
|
|
@@ -275,9 +280,11 @@ function prettyPath(path, highlight = true) {
|
|
|
275
280
|
async function prepare(apibara) {
|
|
276
281
|
await prepareDir(apibara.options.buildDir);
|
|
277
282
|
await prepareDir(apibara.options.outputDir);
|
|
278
|
-
apibara.
|
|
279
|
-
|
|
280
|
-
|
|
283
|
+
if (!apibara.options.disableLogs) {
|
|
284
|
+
apibara.logger.success(
|
|
285
|
+
`Output directory ${prettyPath(apibara.options.outputDir)} cleaned`
|
|
286
|
+
);
|
|
287
|
+
}
|
|
281
288
|
}
|
|
282
289
|
async function prepareDir(dir) {
|
|
283
290
|
await fsp.mkdir(dir, { recursive: true });
|
|
@@ -324,7 +331,9 @@ declare module "apibara/types" {`,
|
|
|
324
331
|
await fsp.writeFile(_file, file.contents);
|
|
325
332
|
})
|
|
326
333
|
);
|
|
327
|
-
apibara.
|
|
334
|
+
if (!apibara.options.disableLogs) {
|
|
335
|
+
apibara.logger.success(`Types written to ${prettyPath(typesDir)}`);
|
|
336
|
+
}
|
|
328
337
|
}
|
|
329
338
|
|
|
330
339
|
export { build, createApibara, prepare, writeTypes };
|
package/dist/rolldown/index.mjs
CHANGED
|
@@ -80,7 +80,8 @@ const runtimeDependencies = [
|
|
|
80
80
|
// https://socket.io/docs/v4/server-installation/#additional-packages
|
|
81
81
|
"utf-8-validate",
|
|
82
82
|
"bufferutil",
|
|
83
|
-
|
|
83
|
+
// was giving unresolved import warnings from `node-fetch` library.
|
|
84
|
+
"encoding"
|
|
84
85
|
];
|
|
85
86
|
function getRolldownConfig(apibara) {
|
|
86
87
|
const extensions = [
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { writeFileSync } from "node:fs";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { defineCommand, runMain } from "citty";
|
|
4
|
+
import { config } from "#apibara-internal-virtual/config";
|
|
5
|
+
import { availableIndexers, createIndexer } from "./internal/app.mjs";
|
|
6
|
+
const startCommand = defineCommand({
|
|
7
|
+
meta: {
|
|
8
|
+
name: "write-project-info",
|
|
9
|
+
description: "Write json-encoded information about the project."
|
|
10
|
+
},
|
|
11
|
+
args: {
|
|
12
|
+
"build-dir": {
|
|
13
|
+
type: "string",
|
|
14
|
+
description: "project build directory"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
async run({ args }) {
|
|
18
|
+
const projectInfo = {
|
|
19
|
+
indexers: {}
|
|
20
|
+
};
|
|
21
|
+
for (const preset of Object.keys(config.presets ?? {})) {
|
|
22
|
+
for (const indexer of availableIndexers) {
|
|
23
|
+
const { indexer: indexerInstance } = createIndexer(indexer, preset) ?? {};
|
|
24
|
+
if (!indexerInstance) {
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
projectInfo.indexers[indexer] = {
|
|
28
|
+
...projectInfo.indexers[indexer] ?? {},
|
|
29
|
+
[preset]: {
|
|
30
|
+
type: indexerInstance.streamConfig.name,
|
|
31
|
+
isFactory: indexerInstance.options.factory !== void 0
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const projectInfoPath = resolve(
|
|
37
|
+
args["build-dir"] ?? ".apibara",
|
|
38
|
+
"project-info.json"
|
|
39
|
+
);
|
|
40
|
+
writeFileSync(projectInfoPath, JSON.stringify(projectInfo, null, 2));
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
export const mainCli = defineCommand({
|
|
44
|
+
meta: {
|
|
45
|
+
name: "write-project-info-runner",
|
|
46
|
+
description: "Write json-encoded information about the project."
|
|
47
|
+
},
|
|
48
|
+
subCommands: {
|
|
49
|
+
start: () => startCommand
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
runMain(mainCli);
|
|
53
|
+
export default {};
|
package/dist/types/index.d.mts
CHANGED
|
@@ -52,6 +52,7 @@ interface ApibaraOptions<T extends Record<string, DeepPartial<Pick<ApibaraConfig
|
|
|
52
52
|
buildDir: string;
|
|
53
53
|
outputDir: string;
|
|
54
54
|
indexersDir: string;
|
|
55
|
+
disableLogs?: boolean;
|
|
55
56
|
dev: boolean;
|
|
56
57
|
watchOptions: WatchOptions["watch"];
|
|
57
58
|
hooks: NestedHooks<ApibaraHooks>;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -52,6 +52,7 @@ interface ApibaraOptions<T extends Record<string, DeepPartial<Pick<ApibaraConfig
|
|
|
52
52
|
buildDir: string;
|
|
53
53
|
outputDir: string;
|
|
54
54
|
indexersDir: string;
|
|
55
|
+
disableLogs?: boolean;
|
|
55
56
|
dev: boolean;
|
|
56
57
|
watchOptions: WatchOptions["watch"];
|
|
57
58
|
hooks: NestedHooks<ApibaraHooks>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "apibara",
|
|
3
|
-
"version": "2.1.0-beta.
|
|
3
|
+
"version": "2.1.0-beta.29",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/core/index.mjs",
|
|
6
6
|
"exports": {
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
"playground:add": "pnpm playground add --dir playground"
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
|
81
|
-
"@apibara/starknet": "2.1.0-beta.
|
|
81
|
+
"@apibara/starknet": "2.1.0-beta.29",
|
|
82
82
|
"@types/fs-extra": "^11.0.4",
|
|
83
83
|
"@types/node": "^20.14.0",
|
|
84
84
|
"@types/prompts": "^2.4.9",
|
|
@@ -89,8 +89,8 @@
|
|
|
89
89
|
"vitest": "^1.6.0"
|
|
90
90
|
},
|
|
91
91
|
"dependencies": {
|
|
92
|
-
"@apibara/indexer": "2.1.0-beta.
|
|
93
|
-
"@apibara/protocol": "2.1.0-beta.
|
|
92
|
+
"@apibara/indexer": "2.1.0-beta.29",
|
|
93
|
+
"@apibara/protocol": "2.1.0-beta.29",
|
|
94
94
|
"@rollup/plugin-replace": "^6.0.2",
|
|
95
95
|
"@rollup/plugin-virtual": "^3.0.2",
|
|
96
96
|
"c12": "^1.11.1",
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { build, createApibara, prepare, writeTypes } from "apibara/core";
|
|
4
|
+
import { runtimeDir } from "apibara/runtime/meta";
|
|
5
|
+
import { defineCommand } from "citty";
|
|
6
|
+
import consola from "consola";
|
|
7
|
+
import { resolve } from "pathe";
|
|
8
|
+
import { checkForUnknownArgs, commonArgs } from "../common";
|
|
9
|
+
|
|
10
|
+
export default defineCommand({
|
|
11
|
+
meta: {
|
|
12
|
+
name: "write-project-info",
|
|
13
|
+
description: "Write json-encoded information about the project.",
|
|
14
|
+
},
|
|
15
|
+
args: {
|
|
16
|
+
...commonArgs,
|
|
17
|
+
},
|
|
18
|
+
async run({ args, cmd }) {
|
|
19
|
+
await checkForUnknownArgs(args, cmd);
|
|
20
|
+
|
|
21
|
+
consola.start("Generating `project-info.json`");
|
|
22
|
+
|
|
23
|
+
const rootDir = resolve((args.dir || ".") as string);
|
|
24
|
+
const apibara = await createApibara({ rootDir, disableLogs: true });
|
|
25
|
+
|
|
26
|
+
apibara.options.entry = join(runtimeDir, "project-info.mjs");
|
|
27
|
+
|
|
28
|
+
await prepare(apibara);
|
|
29
|
+
await writeTypes(apibara);
|
|
30
|
+
await build(apibara);
|
|
31
|
+
|
|
32
|
+
const childArgs = [
|
|
33
|
+
resolve(
|
|
34
|
+
apibara.options.outputDir || "./.apibara/build",
|
|
35
|
+
"project-info.mjs",
|
|
36
|
+
),
|
|
37
|
+
"start",
|
|
38
|
+
"--build-dir",
|
|
39
|
+
apibara.options.buildDir,
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
const child = spawn("node", childArgs, {
|
|
43
|
+
stdio: "inherit",
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
child.on("close", (code) => {
|
|
47
|
+
if (code === 0) {
|
|
48
|
+
consola.success("Project info written to `.apibara/project-info.json`");
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
child.on("error", (error) => {
|
|
53
|
+
consola.error(`Failed to write project info: ${error.message}`, error);
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
});
|
package/src/cli/index.ts
CHANGED
|
@@ -13,6 +13,8 @@ export const mainCli = defineCommand({
|
|
|
13
13
|
prepare: () => import("./commands/prepare").then((r) => r.default),
|
|
14
14
|
init: () => import("./commands/init").then((r) => r.default),
|
|
15
15
|
add: () => import("./commands/add").then((r) => r.default),
|
|
16
|
+
"write-project-info": () =>
|
|
17
|
+
import("./commands/write-project-info").then((r) => r.default),
|
|
16
18
|
},
|
|
17
19
|
});
|
|
18
20
|
|
package/src/core/apibara.ts
CHANGED
|
@@ -17,6 +17,11 @@ export async function createApibara(
|
|
|
17
17
|
): Promise<Apibara> {
|
|
18
18
|
const options = await loadOptions(config, opts, dev);
|
|
19
19
|
|
|
20
|
+
// Enable source map support in Node
|
|
21
|
+
process.env.NODE_OPTIONS = process.env.NODE_OPTIONS
|
|
22
|
+
? `${process.env.NODE_OPTIONS} --enable-source-maps`
|
|
23
|
+
: "--enable-source-maps";
|
|
24
|
+
|
|
20
25
|
const apibara: Apibara = {
|
|
21
26
|
options,
|
|
22
27
|
indexers: [],
|
|
@@ -7,9 +7,11 @@ export async function prepare(apibara: Apibara) {
|
|
|
7
7
|
await prepareDir(apibara.options.buildDir);
|
|
8
8
|
await prepareDir(apibara.options.outputDir);
|
|
9
9
|
|
|
10
|
-
apibara.
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
if (!apibara.options.disableLogs) {
|
|
11
|
+
apibara.logger.success(
|
|
12
|
+
`Output directory ${prettyPath(apibara.options.outputDir)} cleaned`,
|
|
13
|
+
);
|
|
14
|
+
}
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
async function prepareDir(dir: string) {
|
package/src/core/build/prod.ts
CHANGED
|
@@ -6,9 +6,11 @@ export async function buildProduction(
|
|
|
6
6
|
apibara: Apibara,
|
|
7
7
|
rolldownConfig: rolldown.RolldownOptions,
|
|
8
8
|
) {
|
|
9
|
-
apibara.
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
if (!apibara.options.disableLogs) {
|
|
10
|
+
apibara.logger.start(
|
|
11
|
+
`Building ${colors.cyan(apibara.indexers.length)} indexers`,
|
|
12
|
+
);
|
|
13
|
+
}
|
|
12
14
|
|
|
13
15
|
const startTime = Date.now();
|
|
14
16
|
|
|
@@ -30,10 +32,12 @@ export async function buildProduction(
|
|
|
30
32
|
const endTime = Date.now();
|
|
31
33
|
const duration = endTime - startTime;
|
|
32
34
|
|
|
33
|
-
apibara.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
if (!apibara.options.disableLogs) {
|
|
36
|
+
apibara.logger.success(`Build succeeded in ${duration}ms`);
|
|
37
|
+
apibara.logger.info(
|
|
38
|
+
`You can start the indexers with ${colors.cyan("apibara start")}`,
|
|
39
|
+
);
|
|
40
|
+
}
|
|
37
41
|
} catch (error) {
|
|
38
42
|
apibara.logger.error("Build failed", error);
|
|
39
43
|
throw error;
|
package/src/core/build/types.ts
CHANGED
package/src/rolldown/config.ts
CHANGED
|
@@ -20,7 +20,8 @@ const runtimeDependencies = [
|
|
|
20
20
|
// https://socket.io/docs/v4/server-installation/#additional-packages
|
|
21
21
|
"utf-8-validate",
|
|
22
22
|
"bufferutil",
|
|
23
|
-
|
|
23
|
+
// was giving unresolved import warnings from `node-fetch` library.
|
|
24
|
+
"encoding",
|
|
24
25
|
];
|
|
25
26
|
|
|
26
27
|
export function getRolldownConfig(apibara: Apibara): RolldownOptions {
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { writeFileSync } from "node:fs";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { defineCommand, runMain } from "citty";
|
|
4
|
+
import { config } from "#apibara-internal-virtual/config";
|
|
5
|
+
import { availableIndexers, createIndexer } from "./internal/app";
|
|
6
|
+
|
|
7
|
+
type ProjectInfo = {
|
|
8
|
+
indexers: {
|
|
9
|
+
[indexerName: string]: {
|
|
10
|
+
[presetName: string]: {
|
|
11
|
+
type: string;
|
|
12
|
+
isFactory: boolean;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const startCommand = defineCommand({
|
|
19
|
+
meta: {
|
|
20
|
+
name: "write-project-info",
|
|
21
|
+
description: "Write json-encoded information about the project.",
|
|
22
|
+
},
|
|
23
|
+
args: {
|
|
24
|
+
"build-dir": {
|
|
25
|
+
type: "string",
|
|
26
|
+
description: "project build directory",
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
async run({ args }) {
|
|
30
|
+
const projectInfo: ProjectInfo = {
|
|
31
|
+
indexers: {},
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
for (const preset of Object.keys(config.presets ?? {})) {
|
|
35
|
+
for (const indexer of availableIndexers) {
|
|
36
|
+
const { indexer: indexerInstance } =
|
|
37
|
+
createIndexer(indexer, preset) ?? {};
|
|
38
|
+
if (!indexerInstance) {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
projectInfo.indexers[indexer] = {
|
|
42
|
+
...(projectInfo.indexers[indexer] ?? {}),
|
|
43
|
+
[preset]: {
|
|
44
|
+
type: indexerInstance.streamConfig.name,
|
|
45
|
+
isFactory: indexerInstance.options.factory !== undefined,
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const projectInfoPath = resolve(
|
|
52
|
+
args["build-dir"] ?? ".apibara",
|
|
53
|
+
"project-info.json",
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
writeFileSync(projectInfoPath, JSON.stringify(projectInfo, null, 2));
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
export const mainCli = defineCommand({
|
|
61
|
+
meta: {
|
|
62
|
+
name: "write-project-info-runner",
|
|
63
|
+
description: "Write json-encoded information about the project.",
|
|
64
|
+
},
|
|
65
|
+
subCommands: {
|
|
66
|
+
start: () => startCommand,
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
runMain(mainCli);
|
|
71
|
+
|
|
72
|
+
export default {};
|