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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "apibara",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0-beta.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/core/index.mjs",
|
|
6
6
|
"exports": {
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
"types": "./dist/core/index.d.ts",
|
|
21
21
|
"import": "./dist/core/index.mjs"
|
|
22
22
|
},
|
|
23
|
-
"./
|
|
24
|
-
"types": "./dist/
|
|
25
|
-
"import": "./dist/
|
|
23
|
+
"./rolldown": {
|
|
24
|
+
"types": "./dist/rolldown/index.d.ts",
|
|
25
|
+
"import": "./dist/rolldown/index.mjs"
|
|
26
26
|
},
|
|
27
27
|
"./types": {
|
|
28
28
|
"types": "./dist/types/index.d.ts",
|
|
@@ -32,13 +32,25 @@
|
|
|
32
32
|
"types": "./dist/hooks/index.d.ts",
|
|
33
33
|
"import": "./dist/hooks/index.mjs"
|
|
34
34
|
},
|
|
35
|
-
"./
|
|
36
|
-
"
|
|
37
|
-
"
|
|
35
|
+
"./runtime": {
|
|
36
|
+
"types": "./dist/runtime/index.d.ts",
|
|
37
|
+
"import": "./dist/runtime/index.mjs"
|
|
38
38
|
},
|
|
39
|
-
"./
|
|
40
|
-
"
|
|
41
|
-
"
|
|
39
|
+
"./create": {
|
|
40
|
+
"types": "./dist/create/index.d.ts",
|
|
41
|
+
"import": "./dist/create/index.mjs"
|
|
42
|
+
},
|
|
43
|
+
"./runtime/meta": {
|
|
44
|
+
"types": "./runtime-meta.d.ts",
|
|
45
|
+
"import": "./runtime-meta.mjs"
|
|
46
|
+
},
|
|
47
|
+
"./runtime/*": {
|
|
48
|
+
"types": "./dist/runtime/*.d.ts",
|
|
49
|
+
"import": "./dist/runtime/*.mjs"
|
|
50
|
+
},
|
|
51
|
+
"./dist/runtime/*": {
|
|
52
|
+
"types": "./dist/runtime/*.d.ts",
|
|
53
|
+
"import": "./dist/runtime/*.mjs"
|
|
42
54
|
}
|
|
43
55
|
},
|
|
44
56
|
"bin": {
|
|
@@ -47,6 +59,8 @@
|
|
|
47
59
|
"files": [
|
|
48
60
|
"dist",
|
|
49
61
|
"src",
|
|
62
|
+
"runtime-meta.d.ts",
|
|
63
|
+
"runtime-meta.mjs",
|
|
50
64
|
"README.md"
|
|
51
65
|
],
|
|
52
66
|
"scripts": {
|
|
@@ -55,15 +69,19 @@
|
|
|
55
69
|
"typecheck": "tsc --noEmit",
|
|
56
70
|
"lint:fix": "pnpm lint --write",
|
|
57
71
|
"format": "biome format . --write",
|
|
58
|
-
"playground": "JITI_ESM_RESOLVE=1 NODE_OPTIONS=\"--enable-source-maps\" jiti ./src/cli/index.ts",
|
|
72
|
+
"playground": "JITI_ESM_RESOLVE=1 CONSOLA_LEVEL=debug NODE_OPTIONS=\"--enable-source-maps\" jiti ./src/cli/index.ts",
|
|
59
73
|
"playground:prepare": "pnpm playground prepare --dir playground",
|
|
60
74
|
"playground:dev": "pnpm playground dev --dir playground",
|
|
61
75
|
"playground:build": "pnpm playground build --dir playground",
|
|
62
|
-
"playground:start": "
|
|
76
|
+
"playground:start": "pnpm playground start --dir playground --indexer starknet",
|
|
77
|
+
"playground:init": "pnpm playground init playground",
|
|
78
|
+
"playground:add": "pnpm playground add --dir playground"
|
|
63
79
|
},
|
|
64
80
|
"devDependencies": {
|
|
81
|
+
"@apibara/starknet": "2.1.0-beta.10",
|
|
65
82
|
"@types/fs-extra": "^11.0.4",
|
|
66
83
|
"@types/node": "^20.14.0",
|
|
84
|
+
"@types/prompts": "^2.4.9",
|
|
67
85
|
"jiti": "^1.21.0",
|
|
68
86
|
"starknet": "^6.11.0",
|
|
69
87
|
"unbuild": "^2.0.0",
|
|
@@ -71,27 +89,27 @@
|
|
|
71
89
|
"vitest": "^1.6.0"
|
|
72
90
|
},
|
|
73
91
|
"dependencies": {
|
|
74
|
-
"@apibara/
|
|
75
|
-
"@apibara/
|
|
76
|
-
"@
|
|
77
|
-
"@apibara/starknet": "2.0.0-beta.9",
|
|
78
|
-
"@rollup/plugin-commonjs": "^26.0.1",
|
|
79
|
-
"@rollup/plugin-json": "^6.1.0",
|
|
80
|
-
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
81
|
-
"@rollup/plugin-typescript": "^11.1.6",
|
|
92
|
+
"@apibara/indexer": "2.1.0-beta.10",
|
|
93
|
+
"@apibara/protocol": "2.1.0-beta.10",
|
|
94
|
+
"@rollup/plugin-virtual": "^3.0.2",
|
|
82
95
|
"c12": "^1.11.1",
|
|
83
96
|
"chokidar": "^3.6.0",
|
|
84
97
|
"citty": "^0.1.6",
|
|
85
98
|
"consola": "^3.2.3",
|
|
86
99
|
"defu": "^6.1.4",
|
|
87
|
-
"esbuild": "^0.23.0",
|
|
88
100
|
"fs-extra": "^11.2.0",
|
|
89
101
|
"hookable": "^5.5.3",
|
|
90
102
|
"klona": "^2.0.6",
|
|
103
|
+
"magic-string": "^0.30.12",
|
|
104
|
+
"ohash": "^1.1.4",
|
|
91
105
|
"pathe": "^1.1.2",
|
|
92
106
|
"perfect-debounce": "^1.0.0",
|
|
107
|
+
"picocolors": "^1.1.1",
|
|
93
108
|
"pkg-types": "^1.1.3",
|
|
94
|
-
"
|
|
109
|
+
"prettier": "^3.5.2",
|
|
110
|
+
"prompts": "^2.4.2",
|
|
111
|
+
"rolldown": "1.0.0-beta.3",
|
|
112
|
+
"ts-morph": "^25.0.1",
|
|
95
113
|
"tslib": "^2.6.3",
|
|
96
114
|
"untyped": "^1.4.2"
|
|
97
115
|
}
|
package/runtime-meta.mjs
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { addIndexer } from "apibara/create";
|
|
2
|
+
import { defineCommand } from "citty";
|
|
3
|
+
|
|
4
|
+
export default defineCommand({
|
|
5
|
+
meta: {
|
|
6
|
+
name: "add",
|
|
7
|
+
description:
|
|
8
|
+
"apibara add helps you add a new indexer to your project with sensible defaults.",
|
|
9
|
+
},
|
|
10
|
+
args: {
|
|
11
|
+
indexerId: {
|
|
12
|
+
type: "positional",
|
|
13
|
+
description: "Indexer ID - must be in kebab-case",
|
|
14
|
+
required: false,
|
|
15
|
+
},
|
|
16
|
+
chain: {
|
|
17
|
+
type: "string",
|
|
18
|
+
description: "Blockchain - ethereum, beaconchain, starknet",
|
|
19
|
+
},
|
|
20
|
+
network: {
|
|
21
|
+
type: "string",
|
|
22
|
+
description: "Network - mainnet, sepolia, other",
|
|
23
|
+
},
|
|
24
|
+
storage: {
|
|
25
|
+
type: "string",
|
|
26
|
+
description: "Storage - postgres, none",
|
|
27
|
+
},
|
|
28
|
+
dnaUrl: {
|
|
29
|
+
type: "string",
|
|
30
|
+
description: "DNA URL - https://custom-dna-url.apibara.org",
|
|
31
|
+
},
|
|
32
|
+
dir: {
|
|
33
|
+
type: "string",
|
|
34
|
+
description:
|
|
35
|
+
"Root directory - apibara project root where apibara.config is located | default: current working directory",
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
async run({ args }) {
|
|
39
|
+
const { indexerId, chain, network, storage, dnaUrl, dir } = args;
|
|
40
|
+
|
|
41
|
+
await addIndexer({
|
|
42
|
+
argIndexerId: indexerId,
|
|
43
|
+
argChain: chain,
|
|
44
|
+
argNetwork: network,
|
|
45
|
+
argStorage: storage,
|
|
46
|
+
argDnaUrl: dnaUrl,
|
|
47
|
+
argRootDir: dir,
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { build, createApibara, prepare, writeTypes } from "apibara/core";
|
|
2
|
+
import { runtimeDir } from "apibara/runtime/meta";
|
|
2
3
|
import { defineCommand } from "citty";
|
|
3
|
-
import
|
|
4
|
-
import { resolve } from "pathe";
|
|
4
|
+
import { join, resolve } from "pathe";
|
|
5
5
|
import { commonArgs } from "../common";
|
|
6
6
|
|
|
7
7
|
export default defineCommand({
|
|
@@ -13,11 +13,13 @@ export default defineCommand({
|
|
|
13
13
|
...commonArgs,
|
|
14
14
|
},
|
|
15
15
|
async run({ args }) {
|
|
16
|
-
consola.start("Building");
|
|
17
16
|
const rootDir = resolve((args.dir || args._dir || ".") as string);
|
|
18
17
|
const apibara = await createApibara({
|
|
19
18
|
rootDir,
|
|
20
19
|
});
|
|
20
|
+
|
|
21
|
+
apibara.options.entry = join(runtimeDir, "start.mjs");
|
|
22
|
+
|
|
21
23
|
await prepare(apibara);
|
|
22
24
|
await writeTypes(apibara);
|
|
23
25
|
await build(apibara);
|
package/src/cli/commands/dev.ts
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import { type ChildProcess, spawn } from "node:child_process";
|
|
2
2
|
import { build, createApibara, prepare, writeTypes } from "apibara/core";
|
|
3
|
+
import { runtimeDir } from "apibara/runtime/meta";
|
|
3
4
|
import type { Apibara } from "apibara/types";
|
|
4
5
|
import { defineCommand } from "citty";
|
|
5
|
-
import
|
|
6
|
-
import { resolve } from "pathe";
|
|
6
|
+
import { colors } from "consola/utils";
|
|
7
|
+
import { join, resolve } from "pathe";
|
|
7
8
|
import { commonArgs } from "../common";
|
|
8
9
|
|
|
9
10
|
// Hot module reloading key regex
|
|
10
11
|
// for only runtimeConfig.* keys
|
|
11
12
|
const hmrKeyRe = /^runtimeConfig\./;
|
|
12
13
|
|
|
13
|
-
let childProcess: ChildProcess | undefined;
|
|
14
|
-
|
|
15
14
|
export default defineCommand({
|
|
16
15
|
meta: {
|
|
17
16
|
name: "dev",
|
|
@@ -27,24 +26,33 @@ export default defineCommand({
|
|
|
27
26
|
type: "string",
|
|
28
27
|
description: "Preset to use",
|
|
29
28
|
},
|
|
30
|
-
|
|
31
|
-
type: "
|
|
32
|
-
|
|
29
|
+
alwaysReindex: {
|
|
30
|
+
type: "boolean",
|
|
31
|
+
default: false,
|
|
32
|
+
description:
|
|
33
|
+
"Reindex the indexers from the starting block on every restart (default: false)",
|
|
33
34
|
},
|
|
34
35
|
},
|
|
35
36
|
async run({ args }) {
|
|
36
|
-
consola.start("Starting dev server");
|
|
37
37
|
const rootDir = resolve((args.dir || args._dir || ".") as string);
|
|
38
|
+
|
|
39
|
+
if (args.alwaysReindex) {
|
|
40
|
+
process.env.APIBARA_ALWAYS_REINDEX = "true";
|
|
41
|
+
}
|
|
42
|
+
|
|
38
43
|
let apibara: Apibara;
|
|
44
|
+
let childProcess: ChildProcess | undefined;
|
|
39
45
|
|
|
40
46
|
const reload = async () => {
|
|
41
47
|
if (apibara) {
|
|
42
|
-
|
|
48
|
+
apibara.logger.info("Restarting dev server");
|
|
43
49
|
if ("unwatch" in apibara.options._c12) {
|
|
44
50
|
await apibara.options._c12.unwatch();
|
|
45
51
|
}
|
|
52
|
+
|
|
46
53
|
await apibara.close();
|
|
47
54
|
}
|
|
55
|
+
|
|
48
56
|
apibara = await createApibara(
|
|
49
57
|
{
|
|
50
58
|
rootDir,
|
|
@@ -59,10 +67,11 @@ export default defineCommand({
|
|
|
59
67
|
return; // No changes
|
|
60
68
|
}
|
|
61
69
|
|
|
62
|
-
|
|
63
|
-
`
|
|
70
|
+
apibara.logger.info(
|
|
71
|
+
`Config updated:
|
|
64
72
|
${diff.map((entry) => ` ${entry.toString()}`).join("\n")}`,
|
|
65
73
|
);
|
|
74
|
+
|
|
66
75
|
await (diff.every((e) => hmrKeyRe.test(e.key))
|
|
67
76
|
? apibara.updateConfig(newConfig.config || {}) // Hot reload
|
|
68
77
|
: reload()); // Full reload
|
|
@@ -71,26 +80,37 @@ export default defineCommand({
|
|
|
71
80
|
},
|
|
72
81
|
true,
|
|
73
82
|
);
|
|
83
|
+
|
|
74
84
|
apibara.hooks.hookOnce("restart", reload);
|
|
75
85
|
|
|
86
|
+
apibara.options.entry = join(runtimeDir, "dev.mjs");
|
|
87
|
+
|
|
76
88
|
await prepare(apibara);
|
|
77
89
|
await writeTypes(apibara);
|
|
78
90
|
await build(apibara);
|
|
79
91
|
|
|
80
|
-
apibara.hooks.hook("dev:
|
|
92
|
+
apibara.hooks.hook("dev:restart", async () => {
|
|
81
93
|
if (childProcess) {
|
|
82
|
-
|
|
83
|
-
childProcess
|
|
94
|
+
apibara.logger.info("Change detected, stopping indexers to restart");
|
|
95
|
+
await killProcess(childProcess);
|
|
96
|
+
childProcess = undefined;
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
apibara.hooks.hook("dev:reload", async () => {
|
|
101
|
+
if (childProcess) {
|
|
102
|
+
apibara.logger.info("Restarting indexers");
|
|
103
|
+
await killProcess(childProcess);
|
|
104
|
+
childProcess = undefined;
|
|
84
105
|
} else {
|
|
85
|
-
|
|
86
|
-
consola.success("Starting indexers");
|
|
106
|
+
apibara.logger.info("Starting indexers");
|
|
87
107
|
}
|
|
88
108
|
|
|
89
109
|
const childArgs = [
|
|
90
|
-
resolve(apibara.options.outputDir || "./.apibara/build", "
|
|
110
|
+
resolve(apibara.options.outputDir || "./.apibara/build", "dev.mjs"),
|
|
111
|
+
"start",
|
|
91
112
|
...(args.indexers ? ["--indexers", args.indexers] : []),
|
|
92
113
|
...(args.preset ? ["--preset", args.preset] : []),
|
|
93
|
-
...(args.sink ? ["--sink", args.sink] : []),
|
|
94
114
|
];
|
|
95
115
|
|
|
96
116
|
childProcess = spawn("node", childArgs, {
|
|
@@ -99,7 +119,9 @@ export default defineCommand({
|
|
|
99
119
|
|
|
100
120
|
childProcess.on("close", (code) => {
|
|
101
121
|
if (code !== null) {
|
|
102
|
-
|
|
122
|
+
apibara.logger.log(
|
|
123
|
+
`Indexers process exited with code ${colors.red(code)}`,
|
|
124
|
+
);
|
|
103
125
|
}
|
|
104
126
|
});
|
|
105
127
|
});
|
|
@@ -108,3 +130,12 @@ export default defineCommand({
|
|
|
108
130
|
await reload();
|
|
109
131
|
},
|
|
110
132
|
});
|
|
133
|
+
|
|
134
|
+
async function killProcess(childProcess: ChildProcess | undefined) {
|
|
135
|
+
if (childProcess) {
|
|
136
|
+
await new Promise((resolve) => {
|
|
137
|
+
childProcess.once("exit", resolve);
|
|
138
|
+
childProcess.kill();
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { initializeProject } from "apibara/create";
|
|
2
|
+
import { defineCommand } from "citty";
|
|
3
|
+
|
|
4
|
+
export default defineCommand({
|
|
5
|
+
meta: {
|
|
6
|
+
name: "init",
|
|
7
|
+
description: "Initialize a new Apibara project",
|
|
8
|
+
},
|
|
9
|
+
args: {
|
|
10
|
+
dir: {
|
|
11
|
+
type: "positional",
|
|
12
|
+
description: "Target path to initialize the project",
|
|
13
|
+
required: true,
|
|
14
|
+
},
|
|
15
|
+
language: {
|
|
16
|
+
type: "string",
|
|
17
|
+
description: "Language to use: typescript, ts or javascript, js",
|
|
18
|
+
default: "ts",
|
|
19
|
+
alias: "l",
|
|
20
|
+
},
|
|
21
|
+
noIndexer: {
|
|
22
|
+
type: "boolean",
|
|
23
|
+
description: "Do not create an indexer after initialization",
|
|
24
|
+
default: false,
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
async run({ args }) {
|
|
28
|
+
const { dir: targetDir, noIndexer, language } = args;
|
|
29
|
+
|
|
30
|
+
await initializeProject({
|
|
31
|
+
argTargetDir: targetDir,
|
|
32
|
+
argLanguage: language,
|
|
33
|
+
argNoCreateIndexer: noIndexer,
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
});
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { createApibara, writeTypes } from "apibara/core";
|
|
2
2
|
import {} from "apibara/types";
|
|
3
3
|
import { defineCommand } from "citty";
|
|
4
|
-
import consola from "consola";
|
|
5
4
|
import { resolve } from "pathe";
|
|
6
5
|
import { commonArgs } from "../common";
|
|
7
6
|
|
|
@@ -14,7 +13,6 @@ export default defineCommand({
|
|
|
14
13
|
...commonArgs,
|
|
15
14
|
},
|
|
16
15
|
async run({ args }) {
|
|
17
|
-
consola.start("Preparing Types");
|
|
18
16
|
const rootDir = resolve((args.dir || ".") as string);
|
|
19
17
|
const apibara = await createApibara({ rootDir });
|
|
20
18
|
await writeTypes(apibara);
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { createApibara } from "apibara/core";
|
|
3
|
+
import { defineCommand } from "citty";
|
|
4
|
+
import fse from "fs-extra";
|
|
5
|
+
import { resolve } from "pathe";
|
|
6
|
+
import { commonArgs } from "../common";
|
|
7
|
+
|
|
8
|
+
export default defineCommand({
|
|
9
|
+
meta: {
|
|
10
|
+
name: "start",
|
|
11
|
+
description: "Start one indexer",
|
|
12
|
+
},
|
|
13
|
+
args: {
|
|
14
|
+
...commonArgs,
|
|
15
|
+
indexer: {
|
|
16
|
+
type: "string",
|
|
17
|
+
description: "The indexer to start",
|
|
18
|
+
required: true,
|
|
19
|
+
},
|
|
20
|
+
preset: {
|
|
21
|
+
type: "string",
|
|
22
|
+
description: "The preset to use",
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
async run({ args }) {
|
|
26
|
+
const { indexer, preset } = args;
|
|
27
|
+
const rootDir = resolve((args.dir || args._dir || ".") as string);
|
|
28
|
+
|
|
29
|
+
const apibara = await createApibara({
|
|
30
|
+
rootDir,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
apibara.logger.start(
|
|
34
|
+
`Starting indexer ${indexer}${preset ? ` with preset ${preset}` : ""}`,
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
const outputDir = apibara.options.outputDir || "./.apibara/build";
|
|
38
|
+
const entry = resolve(outputDir, "start.mjs");
|
|
39
|
+
|
|
40
|
+
if (!fse.existsSync(entry)) {
|
|
41
|
+
apibara.logger.error(
|
|
42
|
+
`Output directory ${outputDir} does not exist. Try building the indexer with "apibara build" first.`,
|
|
43
|
+
);
|
|
44
|
+
return process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
await apibara.close();
|
|
48
|
+
|
|
49
|
+
const childArgs = [
|
|
50
|
+
entry,
|
|
51
|
+
"start",
|
|
52
|
+
"--indexer",
|
|
53
|
+
indexer,
|
|
54
|
+
...(preset ? ["--preset", preset] : []),
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
spawn("node", childArgs, {
|
|
58
|
+
stdio: "inherit",
|
|
59
|
+
});
|
|
60
|
+
},
|
|
61
|
+
});
|
package/src/cli/index.ts
CHANGED
|
@@ -9,7 +9,10 @@ export const mainCli = defineCommand({
|
|
|
9
9
|
subCommands: {
|
|
10
10
|
dev: () => import("./commands/dev").then((r) => r.default),
|
|
11
11
|
build: () => import("./commands/build").then((r) => r.default),
|
|
12
|
+
start: () => import("./commands/start").then((r) => r.default),
|
|
12
13
|
prepare: () => import("./commands/prepare").then((r) => r.default),
|
|
14
|
+
init: () => import("./commands/init").then((r) => r.default),
|
|
15
|
+
add: () => import("./commands/add").then((r) => r.default),
|
|
13
16
|
},
|
|
14
17
|
});
|
|
15
18
|
|
package/src/config/index.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { ApibaraConfig, DeepPartial } from "apibara/types";
|
|
2
2
|
|
|
3
3
|
export function defineConfig<
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
T extends Record<
|
|
5
|
+
string,
|
|
6
|
+
DeepPartial<Pick<ApibaraConfig<T, R>, "runtimeConfig">>
|
|
7
|
+
> = Record<string, never>,
|
|
8
|
+
R extends Record<string, unknown> = Record<string, never>,
|
|
8
9
|
>(config: ApibaraConfig<T, R>): ApibaraConfig<T, R> {
|
|
9
10
|
return config;
|
|
10
11
|
}
|
package/src/core/apibara.ts
CHANGED
|
@@ -8,18 +8,18 @@ import consola from "consola";
|
|
|
8
8
|
import { createHooks } from "hookable";
|
|
9
9
|
import { loadOptions } from "./config/loader";
|
|
10
10
|
import { updateApibaraConfig } from "./config/update";
|
|
11
|
+
import { scanIndexers } from "./scan";
|
|
11
12
|
|
|
12
13
|
export async function createApibara(
|
|
13
14
|
config: ApibaraConfig = {},
|
|
14
15
|
opts: LoadConfigOptions = {},
|
|
15
16
|
dev = false,
|
|
16
17
|
): Promise<Apibara> {
|
|
17
|
-
// load options
|
|
18
18
|
const options = await loadOptions(config, opts, dev);
|
|
19
19
|
|
|
20
|
-
// create apibara context
|
|
21
20
|
const apibara: Apibara = {
|
|
22
21
|
options,
|
|
22
|
+
indexers: [],
|
|
23
23
|
hooks: createHooks(),
|
|
24
24
|
close: () => apibara.hooks.callHook("close"),
|
|
25
25
|
logger: consola.withTag("apibara"),
|
|
@@ -30,5 +30,7 @@ export async function createApibara(
|
|
|
30
30
|
|
|
31
31
|
apibara.hooks.addHooks(apibara.options.hooks);
|
|
32
32
|
|
|
33
|
+
await scanIndexers(apibara);
|
|
34
|
+
|
|
33
35
|
return apibara;
|
|
34
36
|
}
|
package/src/core/build/build.ts
CHANGED
|
@@ -1,12 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getRolldownConfig } from "apibara/rolldown";
|
|
2
2
|
import type { Apibara } from "apibara/types";
|
|
3
|
+
import { colors } from "consola/utils";
|
|
3
4
|
import { watchDev } from "./dev";
|
|
4
5
|
import { buildProduction } from "./prod";
|
|
5
6
|
|
|
6
7
|
export async function build(apibara: Apibara) {
|
|
7
|
-
const
|
|
8
|
-
|
|
8
|
+
const rolldownConfig = getRolldownConfig(apibara);
|
|
9
|
+
|
|
10
|
+
await apibara.hooks.callHook("rolldown:before", apibara, rolldownConfig);
|
|
11
|
+
|
|
12
|
+
if (apibara.options.rollupConfig) {
|
|
13
|
+
apibara.logger.error(
|
|
14
|
+
`\n${colors.cyan("apibara.config:")} rollupConfig is deprecated. Use rolldownConfig instead`,
|
|
15
|
+
);
|
|
16
|
+
process.exit(1);
|
|
17
|
+
}
|
|
18
|
+
|
|
9
19
|
return apibara.options.dev
|
|
10
|
-
? await watchDev(apibara,
|
|
11
|
-
: await buildProduction(apibara,
|
|
20
|
+
? await watchDev(apibara, rolldownConfig)
|
|
21
|
+
: await buildProduction(apibara, rolldownConfig);
|
|
12
22
|
}
|
package/src/core/build/dev.ts
CHANGED
|
@@ -1,58 +1,67 @@
|
|
|
1
|
-
import type { Apibara
|
|
1
|
+
import type { Apibara } from "apibara/types";
|
|
2
2
|
import { watch } from "chokidar";
|
|
3
3
|
import defu from "defu";
|
|
4
4
|
import { join } from "pathe";
|
|
5
5
|
import { debounce } from "perfect-debounce";
|
|
6
|
-
import * as
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
export async function watchDev(apibara: Apibara, rollupConfig: RollupConfig) {
|
|
10
|
-
let rollupWatcher: rollup.RollupWatcher;
|
|
6
|
+
import * as rolldown from "rolldown";
|
|
7
|
+
import { formatRolldownError } from "./error";
|
|
11
8
|
|
|
9
|
+
export async function watchDev(
|
|
10
|
+
apibara: Apibara,
|
|
11
|
+
rolldownConfig: rolldown.RolldownOptions,
|
|
12
|
+
) {
|
|
13
|
+
let rolldownWatcher: rolldown.RolldownWatcher;
|
|
12
14
|
async function load() {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
apibara.logger.start("Setting up a dev server");
|
|
16
|
+
if (rolldownWatcher) {
|
|
17
|
+
await rolldownWatcher.close();
|
|
15
18
|
}
|
|
16
|
-
|
|
19
|
+
rolldownWatcher = startRolldownWatcher(apibara, rolldownConfig);
|
|
17
20
|
}
|
|
18
|
-
const reload = debounce(load);
|
|
21
|
+
const reload = debounce(async () => await load());
|
|
19
22
|
|
|
20
|
-
const watchPatterns =
|
|
23
|
+
const watchPatterns = getWatchPatterns(apibara);
|
|
21
24
|
|
|
22
25
|
const watchReloadEvents = new Set(["add", "addDir", "unlink", "unlinkDir"]);
|
|
23
26
|
const reloadWatcher = watch(watchPatterns, { ignoreInitial: true }).on(
|
|
24
27
|
"all",
|
|
25
|
-
(event) => {
|
|
28
|
+
async (event) => {
|
|
26
29
|
if (watchReloadEvents.has(event)) {
|
|
27
|
-
reload();
|
|
30
|
+
await reload();
|
|
28
31
|
}
|
|
29
32
|
},
|
|
30
33
|
);
|
|
31
34
|
|
|
32
35
|
apibara.hooks.hook("close", () => {
|
|
33
|
-
|
|
36
|
+
rolldownWatcher.close();
|
|
34
37
|
reloadWatcher.close();
|
|
35
38
|
});
|
|
36
39
|
|
|
37
|
-
apibara.hooks.hook("
|
|
40
|
+
apibara.hooks.hook("rolldown:reload", async () => await reload());
|
|
38
41
|
|
|
39
42
|
await load();
|
|
40
43
|
}
|
|
41
44
|
|
|
42
|
-
function
|
|
43
|
-
|
|
44
|
-
|
|
45
|
+
function startRolldownWatcher(
|
|
46
|
+
apibara: Apibara,
|
|
47
|
+
rolldownConfig: rolldown.RolldownOptions,
|
|
48
|
+
) {
|
|
49
|
+
const ignorePatterns = getIgnorePatterns(apibara);
|
|
50
|
+
const watcher = rolldown.watch(
|
|
51
|
+
defu(rolldownConfig, {
|
|
45
52
|
watch: {
|
|
46
|
-
|
|
53
|
+
exclude: ignorePatterns,
|
|
54
|
+
...((apibara.options.watchOptions ?? {}) as rolldown.WatchOptions),
|
|
47
55
|
},
|
|
48
56
|
}),
|
|
49
57
|
);
|
|
50
58
|
let start: number;
|
|
51
59
|
|
|
52
|
-
watcher.on("event", (event) => {
|
|
60
|
+
watcher.on("event", async (event) => {
|
|
53
61
|
switch (event.code) {
|
|
54
62
|
// The watcher is (re)starting
|
|
55
63
|
case "START": {
|
|
64
|
+
await apibara.hooks.callHook("dev:restart");
|
|
56
65
|
return;
|
|
57
66
|
}
|
|
58
67
|
|
|
@@ -69,15 +78,28 @@ function startRollupWatcher(apibara: Apibara, rollupConfig: RollupConfig) {
|
|
|
69
78
|
"Indexers built",
|
|
70
79
|
start ? `in ${Date.now() - start} ms` : "",
|
|
71
80
|
);
|
|
72
|
-
apibara.hooks.callHook("dev:reload");
|
|
81
|
+
await apibara.hooks.callHook("dev:reload");
|
|
73
82
|
return;
|
|
74
83
|
}
|
|
75
84
|
|
|
76
85
|
// Encountered an error while bundling
|
|
77
86
|
case "ERROR": {
|
|
78
|
-
apibara.logger.error(
|
|
87
|
+
apibara.logger.error(formatRolldownError(event.error));
|
|
79
88
|
}
|
|
80
89
|
}
|
|
81
90
|
});
|
|
82
91
|
return watcher;
|
|
83
92
|
}
|
|
93
|
+
|
|
94
|
+
const getWatchPatterns = (apibara: Apibara) => [
|
|
95
|
+
join(apibara.options.rootDir, "indexers"),
|
|
96
|
+
];
|
|
97
|
+
|
|
98
|
+
const getIgnorePatterns = (apibara: Apibara) => [
|
|
99
|
+
"**/.apibara/**",
|
|
100
|
+
"**/.git/**",
|
|
101
|
+
"**/.DS_Store",
|
|
102
|
+
"**/node_modules/**",
|
|
103
|
+
"**/dist/**",
|
|
104
|
+
"**/.turbo/**",
|
|
105
|
+
];
|