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
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { addIndexer } from 'apibara/create';
|
|
2
|
+
import { defineCommand } from 'citty';
|
|
3
|
+
|
|
4
|
+
const add = defineCommand({
|
|
5
|
+
meta: {
|
|
6
|
+
name: "add",
|
|
7
|
+
description: "apibara add helps you add a new indexer to your project with sensible defaults."
|
|
8
|
+
},
|
|
9
|
+
args: {
|
|
10
|
+
indexerId: {
|
|
11
|
+
type: "positional",
|
|
12
|
+
description: "Indexer ID - must be in kebab-case",
|
|
13
|
+
required: false
|
|
14
|
+
},
|
|
15
|
+
chain: {
|
|
16
|
+
type: "string",
|
|
17
|
+
description: "Blockchain - ethereum, beaconchain, starknet"
|
|
18
|
+
},
|
|
19
|
+
network: {
|
|
20
|
+
type: "string",
|
|
21
|
+
description: "Network - mainnet, sepolia, other"
|
|
22
|
+
},
|
|
23
|
+
storage: {
|
|
24
|
+
type: "string",
|
|
25
|
+
description: "Storage - postgres, none"
|
|
26
|
+
},
|
|
27
|
+
dnaUrl: {
|
|
28
|
+
type: "string",
|
|
29
|
+
description: "DNA URL - https://custom-dna-url.apibara.org"
|
|
30
|
+
},
|
|
31
|
+
dir: {
|
|
32
|
+
type: "string",
|
|
33
|
+
description: "Root directory - apibara project root where apibara.config is located | default: current working directory"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
async run({ args }) {
|
|
37
|
+
const { indexerId, chain, network, storage, dnaUrl, dir } = args;
|
|
38
|
+
await addIndexer({
|
|
39
|
+
argIndexerId: indexerId,
|
|
40
|
+
argChain: chain,
|
|
41
|
+
argNetwork: network,
|
|
42
|
+
argStorage: storage,
|
|
43
|
+
argDnaUrl: dnaUrl,
|
|
44
|
+
argRootDir: dir
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
export { add as default };
|
package/dist/chunks/build.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createApibara, prepare, writeTypes, build as build$1 } 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 { resolve, join } from 'pathe';
|
|
5
5
|
import { c as commonArgs } from '../shared/apibara.1b515d04.mjs';
|
|
6
6
|
|
|
7
7
|
const build = defineCommand({
|
|
@@ -13,11 +13,11 @@ const build = defineCommand({
|
|
|
13
13
|
...commonArgs
|
|
14
14
|
},
|
|
15
15
|
async run({ args }) {
|
|
16
|
-
consola__default.start("Building");
|
|
17
16
|
const rootDir = resolve(args.dir || args._dir || ".");
|
|
18
17
|
const apibara = await createApibara({
|
|
19
18
|
rootDir
|
|
20
19
|
});
|
|
20
|
+
apibara.options.entry = join(runtimeDir, "start.mjs");
|
|
21
21
|
await prepare(apibara);
|
|
22
22
|
await writeTypes(apibara);
|
|
23
23
|
await build$1(apibara);
|
package/dist/chunks/dev.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
2
|
import { createApibara, prepare, writeTypes, build } from 'apibara/core';
|
|
3
|
+
import { runtimeDir } from 'apibara/runtime/meta';
|
|
3
4
|
import { defineCommand } from 'citty';
|
|
4
|
-
import
|
|
5
|
-
import { resolve } from 'pathe';
|
|
5
|
+
import { colors } from 'consola/utils';
|
|
6
|
+
import { resolve, join } from 'pathe';
|
|
6
7
|
import { c as commonArgs } from '../shared/apibara.1b515d04.mjs';
|
|
7
8
|
|
|
8
9
|
const hmrKeyRe = /^runtimeConfig\./;
|
|
9
|
-
let childProcess;
|
|
10
10
|
const dev = defineCommand({
|
|
11
11
|
meta: {
|
|
12
12
|
name: "dev",
|
|
@@ -22,18 +22,22 @@ const dev = defineCommand({
|
|
|
22
22
|
type: "string",
|
|
23
23
|
description: "Preset to use"
|
|
24
24
|
},
|
|
25
|
-
|
|
26
|
-
type: "
|
|
27
|
-
|
|
25
|
+
alwaysReindex: {
|
|
26
|
+
type: "boolean",
|
|
27
|
+
default: false,
|
|
28
|
+
description: "Reindex the indexers from the starting block on every restart (default: false)"
|
|
28
29
|
}
|
|
29
30
|
},
|
|
30
31
|
async run({ args }) {
|
|
31
|
-
consola__default.start("Starting dev server");
|
|
32
32
|
const rootDir = resolve(args.dir || args._dir || ".");
|
|
33
|
+
if (args.alwaysReindex) {
|
|
34
|
+
process.env.APIBARA_ALWAYS_REINDEX = "true";
|
|
35
|
+
}
|
|
33
36
|
let apibara;
|
|
37
|
+
let childProcess;
|
|
34
38
|
const reload = async () => {
|
|
35
39
|
if (apibara) {
|
|
36
|
-
|
|
40
|
+
apibara.logger.info("Restarting dev server");
|
|
37
41
|
if ("unwatch" in apibara.options._c12) {
|
|
38
42
|
await apibara.options._c12.unwatch();
|
|
39
43
|
}
|
|
@@ -51,8 +55,8 @@ const dev = defineCommand({
|
|
|
51
55
|
if (diff.length === 0) {
|
|
52
56
|
return;
|
|
53
57
|
}
|
|
54
|
-
|
|
55
|
-
`
|
|
58
|
+
apibara.logger.info(
|
|
59
|
+
`Config updated:
|
|
56
60
|
${diff.map((entry) => ` ${entry.toString()}`).join("\n")}`
|
|
57
61
|
);
|
|
58
62
|
await (diff.every((e) => hmrKeyRe.test(e.key)) ? apibara.updateConfig(newConfig.config || {}) : reload());
|
|
@@ -62,29 +66,39 @@ const dev = defineCommand({
|
|
|
62
66
|
true
|
|
63
67
|
);
|
|
64
68
|
apibara.hooks.hookOnce("restart", reload);
|
|
69
|
+
apibara.options.entry = join(runtimeDir, "dev.mjs");
|
|
65
70
|
await prepare(apibara);
|
|
66
71
|
await writeTypes(apibara);
|
|
67
72
|
await build(apibara);
|
|
68
|
-
apibara.hooks.hook("dev:
|
|
73
|
+
apibara.hooks.hook("dev:restart", async () => {
|
|
74
|
+
if (childProcess) {
|
|
75
|
+
apibara.logger.info("Change detected, stopping indexers to restart");
|
|
76
|
+
await killProcess(childProcess);
|
|
77
|
+
childProcess = void 0;
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
apibara.hooks.hook("dev:reload", async () => {
|
|
69
81
|
if (childProcess) {
|
|
70
|
-
|
|
71
|
-
childProcess
|
|
82
|
+
apibara.logger.info("Restarting indexers");
|
|
83
|
+
await killProcess(childProcess);
|
|
84
|
+
childProcess = void 0;
|
|
72
85
|
} else {
|
|
73
|
-
|
|
74
|
-
consola__default.success("Starting indexers");
|
|
86
|
+
apibara.logger.info("Starting indexers");
|
|
75
87
|
}
|
|
76
88
|
const childArgs = [
|
|
77
|
-
resolve(apibara.options.outputDir || "./.apibara/build", "
|
|
89
|
+
resolve(apibara.options.outputDir || "./.apibara/build", "dev.mjs"),
|
|
90
|
+
"start",
|
|
78
91
|
...args.indexers ? ["--indexers", args.indexers] : [],
|
|
79
|
-
...args.preset ? ["--preset", args.preset] : []
|
|
80
|
-
...args.sink ? ["--sink", args.sink] : []
|
|
92
|
+
...args.preset ? ["--preset", args.preset] : []
|
|
81
93
|
];
|
|
82
94
|
childProcess = spawn("node", childArgs, {
|
|
83
95
|
stdio: "inherit"
|
|
84
96
|
});
|
|
85
97
|
childProcess.on("close", (code) => {
|
|
86
98
|
if (code !== null) {
|
|
87
|
-
|
|
99
|
+
apibara.logger.log(
|
|
100
|
+
`Indexers process exited with code ${colors.red(code)}`
|
|
101
|
+
);
|
|
88
102
|
}
|
|
89
103
|
});
|
|
90
104
|
});
|
|
@@ -92,5 +106,13 @@ const dev = defineCommand({
|
|
|
92
106
|
await reload();
|
|
93
107
|
}
|
|
94
108
|
});
|
|
109
|
+
async function killProcess(childProcess) {
|
|
110
|
+
if (childProcess) {
|
|
111
|
+
await new Promise((resolve2) => {
|
|
112
|
+
childProcess.once("exit", resolve2);
|
|
113
|
+
childProcess.kill();
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}
|
|
95
117
|
|
|
96
118
|
export { dev as default };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { initializeProject } from 'apibara/create';
|
|
2
|
+
import { defineCommand } from 'citty';
|
|
3
|
+
|
|
4
|
+
const init = 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
|
+
await initializeProject({
|
|
30
|
+
argTargetDir: targetDir,
|
|
31
|
+
argLanguage: language,
|
|
32
|
+
argNoCreateIndexer: noIndexer
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
export { init as default };
|
package/dist/chunks/prepare.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { createApibara, writeTypes } from 'apibara/core';
|
|
2
2
|
import { defineCommand } from 'citty';
|
|
3
|
-
import consola__default from 'consola';
|
|
4
3
|
import { resolve } from 'pathe';
|
|
5
4
|
import { c as commonArgs } from '../shared/apibara.1b515d04.mjs';
|
|
6
5
|
|
|
@@ -13,7 +12,6 @@ const prepare = defineCommand({
|
|
|
13
12
|
...commonArgs
|
|
14
13
|
},
|
|
15
14
|
async run({ args }) {
|
|
16
|
-
consola__default.start("Preparing Types");
|
|
17
15
|
const rootDir = resolve(args.dir || ".");
|
|
18
16
|
const apibara = await createApibara({ rootDir });
|
|
19
17
|
await writeTypes(apibara);
|
|
@@ -0,0 +1,56 @@
|
|
|
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 { c as commonArgs } from '../shared/apibara.1b515d04.mjs';
|
|
7
|
+
|
|
8
|
+
const start = 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 || ".");
|
|
28
|
+
const apibara = await createApibara({
|
|
29
|
+
rootDir
|
|
30
|
+
});
|
|
31
|
+
apibara.logger.start(
|
|
32
|
+
`Starting indexer ${indexer}${preset ? ` with preset ${preset}` : ""}`
|
|
33
|
+
);
|
|
34
|
+
const outputDir = apibara.options.outputDir || "./.apibara/build";
|
|
35
|
+
const entry = resolve(outputDir, "start.mjs");
|
|
36
|
+
if (!fse.existsSync(entry)) {
|
|
37
|
+
apibara.logger.error(
|
|
38
|
+
`Output directory ${outputDir} does not exist. Try building the indexer with "apibara build" first.`
|
|
39
|
+
);
|
|
40
|
+
return process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
await apibara.close();
|
|
43
|
+
const childArgs = [
|
|
44
|
+
entry,
|
|
45
|
+
"start",
|
|
46
|
+
"--indexer",
|
|
47
|
+
indexer,
|
|
48
|
+
...preset ? ["--preset", preset] : []
|
|
49
|
+
];
|
|
50
|
+
spawn("node", childArgs, {
|
|
51
|
+
stdio: "inherit"
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
export { start as default };
|
package/dist/cli/index.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
1
2
|
import { defineCommand, runMain } from 'citty';
|
|
2
3
|
|
|
3
4
|
const mainCli = defineCommand({
|
|
@@ -9,7 +10,10 @@ const mainCli = defineCommand({
|
|
|
9
10
|
subCommands: {
|
|
10
11
|
dev: () => import('../chunks/dev.mjs').then((r) => r.default),
|
|
11
12
|
build: () => import('../chunks/build.mjs').then((r) => r.default),
|
|
12
|
-
|
|
13
|
+
start: () => import('../chunks/start.mjs').then((r) => r.default),
|
|
14
|
+
prepare: () => import('../chunks/prepare.mjs').then((r) => r.default),
|
|
15
|
+
init: () => import('../chunks/init.mjs').then((r) => r.default),
|
|
16
|
+
add: () => import('../chunks/add.mjs').then((r) => r.default)
|
|
13
17
|
}
|
|
14
18
|
});
|
|
15
19
|
runMain(mainCli);
|
package/dist/config/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DeepPartial, ApibaraConfig } from 'apibara/types';
|
|
2
2
|
|
|
3
|
-
declare function defineConfig<T extends Record<string, DeepPartial<ApibaraConfig<T, R>>> =
|
|
3
|
+
declare function defineConfig<T extends Record<string, DeepPartial<Pick<ApibaraConfig<T, R>, "runtimeConfig">>> = Record<string, never>, R extends Record<string, unknown> = Record<string, never>>(config: ApibaraConfig<T, R>): ApibaraConfig<T, R>;
|
|
4
4
|
|
|
5
5
|
export { defineConfig };
|
package/dist/config/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DeepPartial, ApibaraConfig } from 'apibara/types';
|
|
2
2
|
|
|
3
|
-
declare function defineConfig<T extends Record<string, DeepPartial<ApibaraConfig<T, R>>> =
|
|
3
|
+
declare function defineConfig<T extends Record<string, DeepPartial<Pick<ApibaraConfig<T, R>, "runtimeConfig">>> = Record<string, never>, R extends Record<string, unknown> = Record<string, never>>(config: ApibaraConfig<T, R>): ApibaraConfig<T, R>;
|
|
4
4
|
|
|
5
5
|
export { defineConfig };
|