apibara 2.0.0-beta.9 → 2.1.0-beta.3
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 +44 -0
- package/dist/chunks/build.mjs +3 -3
- package/dist/chunks/dev.mjs +22 -18
- 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 +61 -97
- package/dist/create/index.d.mts +17 -0
- package/dist/create/index.d.ts +17 -0
- package/dist/create/index.mjs +981 -0
- package/dist/rollup/index.d.mts +2 -1
- package/dist/rollup/index.d.ts +2 -1
- package/dist/rollup/index.mjs +130 -167
- package/dist/runtime/dev.d.ts +3 -0
- package/dist/runtime/dev.mjs +55 -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 +56 -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 +41 -0
- package/dist/types/index.d.mts +22 -19
- package/dist/types/index.d.ts +22 -19
- package/package.json +35 -13
- package/runtime-meta.d.ts +2 -0
- package/runtime-meta.mjs +7 -0
- package/src/cli/commands/add.ts +44 -0
- package/src/cli/commands/build.ts +5 -3
- package/src/cli/commands/dev.ts +28 -18
- 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 +2 -0
- package/src/core/build/dev.ts +1 -0
- package/src/core/build/error.ts +0 -1
- package/src/core/build/prepare.ts +5 -2
- package/src/core/build/prod.ts +10 -6
- package/src/core/build/types.ts +4 -95
- package/src/core/config/defaults.ts +1 -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 +2 -3
- package/src/core/path.ts +11 -0
- package/src/core/scan.ts +40 -0
- package/src/create/add.ts +238 -0
- package/src/create/colors.ts +15 -0
- package/src/create/constants.ts +98 -0
- package/src/create/index.ts +2 -0
- package/src/create/init.ts +175 -0
- package/src/create/templates.ts +468 -0
- package/src/create/types.ts +34 -0
- package/src/create/utils.ts +422 -0
- package/src/rollup/config.ts +67 -189
- package/src/rollup/index.ts +1 -0
- package/src/rollup/plugins/config.ts +12 -0
- package/src/rollup/plugins/esm-shim.ts +69 -0
- package/src/rollup/plugins/indexers.ts +17 -0
- package/src/runtime/dev.ts +64 -0
- package/src/runtime/index.ts +2 -0
- package/src/runtime/internal/app.ts +78 -0
- package/src/runtime/internal/logger.ts +70 -0
- package/src/runtime/start.ts +48 -0
- package/src/types/apibara.ts +8 -0
- package/src/types/config.ts +28 -27
- package/src/types/hooks.ts +1 -0
- package/src/types/virtual/config.d.ts +3 -0
- package/src/types/virtual/indexers.d.ts +10 -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/src/internal/citty/index.ts +0 -1
- package/src/internal/consola/index.ts +0 -1
|
@@ -0,0 +1,44 @@
|
|
|
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",
|
|
13
|
+
required: false
|
|
14
|
+
},
|
|
15
|
+
chain: {
|
|
16
|
+
type: "string",
|
|
17
|
+
description: "Chain"
|
|
18
|
+
},
|
|
19
|
+
network: {
|
|
20
|
+
type: "string",
|
|
21
|
+
description: "Network"
|
|
22
|
+
},
|
|
23
|
+
storage: {
|
|
24
|
+
type: "string",
|
|
25
|
+
description: "Storage"
|
|
26
|
+
},
|
|
27
|
+
dnaUrl: {
|
|
28
|
+
type: "string",
|
|
29
|
+
description: "DNA URL"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
async run({ args }) {
|
|
33
|
+
const { indexerId, chain, network, storage, dnaUrl } = args;
|
|
34
|
+
await addIndexer({
|
|
35
|
+
argIndexerId: indexerId,
|
|
36
|
+
argChain: chain,
|
|
37
|
+
argNetwork: network,
|
|
38
|
+
argStorage: storage,
|
|
39
|
+
argDnaUrl: dnaUrl
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
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",
|
|
@@ -21,19 +21,15 @@ const dev = defineCommand({
|
|
|
21
21
|
preset: {
|
|
22
22
|
type: "string",
|
|
23
23
|
description: "Preset to use"
|
|
24
|
-
},
|
|
25
|
-
sink: {
|
|
26
|
-
type: "string",
|
|
27
|
-
description: "Sink to use"
|
|
28
24
|
}
|
|
29
25
|
},
|
|
30
26
|
async run({ args }) {
|
|
31
|
-
consola__default.start("Starting dev server");
|
|
32
27
|
const rootDir = resolve(args.dir || args._dir || ".");
|
|
33
28
|
let apibara;
|
|
29
|
+
let childProcess;
|
|
34
30
|
const reload = async () => {
|
|
35
31
|
if (apibara) {
|
|
36
|
-
|
|
32
|
+
apibara.logger.info("Restarting dev server");
|
|
37
33
|
if ("unwatch" in apibara.options._c12) {
|
|
38
34
|
await apibara.options._c12.unwatch();
|
|
39
35
|
}
|
|
@@ -51,8 +47,8 @@ const dev = defineCommand({
|
|
|
51
47
|
if (diff.length === 0) {
|
|
52
48
|
return;
|
|
53
49
|
}
|
|
54
|
-
|
|
55
|
-
`
|
|
50
|
+
apibara.logger.info(
|
|
51
|
+
`Config updated:
|
|
56
52
|
${diff.map((entry) => ` ${entry.toString()}`).join("\n")}`
|
|
57
53
|
);
|
|
58
54
|
await (diff.every((e) => hmrKeyRe.test(e.key)) ? apibara.updateConfig(newConfig.config || {}) : reload());
|
|
@@ -62,29 +58,37 @@ const dev = defineCommand({
|
|
|
62
58
|
true
|
|
63
59
|
);
|
|
64
60
|
apibara.hooks.hookOnce("restart", reload);
|
|
61
|
+
apibara.options.entry = join(runtimeDir, "dev.mjs");
|
|
65
62
|
await prepare(apibara);
|
|
66
63
|
await writeTypes(apibara);
|
|
67
64
|
await build(apibara);
|
|
65
|
+
apibara.hooks.hook("dev:restart", () => {
|
|
66
|
+
if (childProcess) {
|
|
67
|
+
apibara.logger.info("Change detected, stopping indexers to restart");
|
|
68
|
+
childProcess.kill();
|
|
69
|
+
childProcess = void 0;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
68
72
|
apibara.hooks.hook("dev:reload", () => {
|
|
69
73
|
if (childProcess) {
|
|
70
|
-
consola__default.start("Restarting indexers");
|
|
71
74
|
childProcess.kill();
|
|
72
75
|
} else {
|
|
73
|
-
|
|
74
|
-
consola__default.success("Starting indexers");
|
|
76
|
+
apibara.logger.success("Restarting indexers");
|
|
75
77
|
}
|
|
76
78
|
const childArgs = [
|
|
77
|
-
resolve(apibara.options.outputDir || "./.apibara/build", "
|
|
79
|
+
resolve(apibara.options.outputDir || "./.apibara/build", "dev.mjs"),
|
|
80
|
+
"start",
|
|
78
81
|
...args.indexers ? ["--indexers", args.indexers] : [],
|
|
79
|
-
...args.preset ? ["--preset", args.preset] : []
|
|
80
|
-
...args.sink ? ["--sink", args.sink] : []
|
|
82
|
+
...args.preset ? ["--preset", args.preset] : []
|
|
81
83
|
];
|
|
82
84
|
childProcess = spawn("node", childArgs, {
|
|
83
85
|
stdio: "inherit"
|
|
84
86
|
});
|
|
85
87
|
childProcess.on("close", (code) => {
|
|
86
88
|
if (code !== null) {
|
|
87
|
-
|
|
89
|
+
apibara.logger.log(
|
|
90
|
+
`Indexers process exited with code ${colors.red(code)}`
|
|
91
|
+
);
|
|
88
92
|
}
|
|
89
93
|
});
|
|
90
94
|
});
|
|
@@ -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 };
|
package/dist/core/index.mjs
CHANGED
|
@@ -1,30 +1,29 @@
|
|
|
1
|
-
import
|
|
1
|
+
import consola from 'consola';
|
|
2
2
|
import { createHooks } from 'hookable';
|
|
3
3
|
import { watchConfig, loadConfig } from 'c12';
|
|
4
4
|
import { klona } from 'klona/full';
|
|
5
|
-
import { resolve, isAbsolute, relative,
|
|
5
|
+
import { resolve, join, basename, isAbsolute, relative, dirname } from 'pathe';
|
|
6
6
|
import defu from 'defu';
|
|
7
|
+
import fse from 'fs-extra';
|
|
7
8
|
import { getRollupConfig } from 'apibara/rollup';
|
|
8
9
|
import { watch } from 'chokidar';
|
|
9
10
|
import { debounce } from 'perfect-debounce';
|
|
10
11
|
import * as rollup from 'rollup';
|
|
11
12
|
import { rollup as rollup$1 } from 'rollup';
|
|
13
|
+
import { colors } from 'consola/utils';
|
|
12
14
|
import fsp from 'node:fs/promises';
|
|
13
|
-
import fse from 'fs-extra';
|
|
14
15
|
import { generateTypes, resolveSchema } from 'untyped';
|
|
15
16
|
|
|
16
17
|
const ApibaraDefaults = {
|
|
17
18
|
rootDir: ".",
|
|
19
|
+
indexersDir: "indexers",
|
|
18
20
|
runtimeConfig: {},
|
|
19
21
|
hooks: {},
|
|
20
22
|
buildDir: ".apibara",
|
|
21
23
|
typescript: {
|
|
22
24
|
strict: false,
|
|
23
|
-
generateTsConfig: true,
|
|
24
25
|
generateRuntimeConfigTypes: true,
|
|
25
|
-
|
|
26
|
-
internalPaths: false,
|
|
27
|
-
tsConfig: {}
|
|
26
|
+
internalPaths: false
|
|
28
27
|
}
|
|
29
28
|
};
|
|
30
29
|
|
|
@@ -46,7 +45,7 @@ async function presetResolver(options) {
|
|
|
46
45
|
}
|
|
47
46
|
|
|
48
47
|
async function resolveRuntimeConfigOptions(options) {
|
|
49
|
-
options.runtimeConfig = { ...options.runtimeConfig
|
|
48
|
+
options.runtimeConfig = { ...options.runtimeConfig };
|
|
50
49
|
process.env.APIBARA_RUNTIME_CONFIG = JSON.stringify(options.runtimeConfig);
|
|
51
50
|
}
|
|
52
51
|
|
|
@@ -83,23 +82,55 @@ async function _loadUserConfig(configOverrides = {}, opts = {}, dev = false) {
|
|
|
83
82
|
return options;
|
|
84
83
|
}
|
|
85
84
|
|
|
86
|
-
async function updateApibaraConfig(apibara,
|
|
85
|
+
async function updateApibaraConfig(apibara, _config) {
|
|
87
86
|
await apibara.hooks.callHook("rollup:reload");
|
|
88
|
-
|
|
87
|
+
apibara.logger.success("Apibara config hot reloaded!");
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const INDEXER_EXTENSIONS = [".indexer.ts", ".indexer.js"];
|
|
91
|
+
async function scanIndexers(apibara) {
|
|
92
|
+
apibara.logger.debug("Scanning indexers");
|
|
93
|
+
const indexersDir = join(
|
|
94
|
+
apibara.options.rootDir,
|
|
95
|
+
apibara.options.indexersDir
|
|
96
|
+
);
|
|
97
|
+
if (!fse.existsSync(indexersDir)) {
|
|
98
|
+
throw new Error(`Indexers directory not found: ${indexersDir}`);
|
|
99
|
+
}
|
|
100
|
+
apibara.indexers = [];
|
|
101
|
+
for (const file of fse.readdirSync(indexersDir)) {
|
|
102
|
+
const indexerName = indexerNameFromFile(file);
|
|
103
|
+
if (indexerName) {
|
|
104
|
+
apibara.indexers.push({
|
|
105
|
+
name: indexerName,
|
|
106
|
+
indexer: join(indexersDir, file)
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
apibara.logger.debug(`Found ${apibara.indexers.length} indexers`);
|
|
111
|
+
}
|
|
112
|
+
function indexerNameFromFile(file) {
|
|
113
|
+
for (const extension of INDEXER_EXTENSIONS) {
|
|
114
|
+
if (file.endsWith(extension)) {
|
|
115
|
+
return basename(file, extension);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
89
118
|
}
|
|
90
119
|
|
|
91
120
|
async function createApibara(config = {}, opts = {}, dev = false) {
|
|
92
121
|
const options = await loadOptions(config, opts, dev);
|
|
93
122
|
const apibara = {
|
|
94
123
|
options,
|
|
124
|
+
indexers: [],
|
|
95
125
|
hooks: createHooks(),
|
|
96
126
|
close: () => apibara.hooks.callHook("close"),
|
|
97
|
-
logger:
|
|
127
|
+
logger: consola.withTag("apibara"),
|
|
98
128
|
async updateConfig(config2) {
|
|
99
129
|
updateApibaraConfig(apibara);
|
|
100
130
|
}
|
|
101
131
|
};
|
|
102
132
|
apibara.hooks.addHooks(apibara.options.hooks);
|
|
133
|
+
await scanIndexers(apibara);
|
|
103
134
|
return apibara;
|
|
104
135
|
}
|
|
105
136
|
|
|
@@ -116,7 +147,6 @@ function formatRollupError(_error) {
|
|
|
116
147
|
}
|
|
117
148
|
const text = error.text || error.frame;
|
|
118
149
|
logs.push(
|
|
119
|
-
// biome-ignore lint/style/useTemplate: <explanation>
|
|
120
150
|
`Rollup error while processing \`${path}\`` + text ? "\n\n" + text : ""
|
|
121
151
|
);
|
|
122
152
|
}
|
|
@@ -164,6 +194,7 @@ function startRollupWatcher(apibara, rollupConfig) {
|
|
|
164
194
|
watcher.on("event", (event) => {
|
|
165
195
|
switch (event.code) {
|
|
166
196
|
case "START": {
|
|
197
|
+
apibara.hooks.callHook("dev:restart");
|
|
167
198
|
return;
|
|
168
199
|
}
|
|
169
200
|
case "BUNDLE_START": {
|
|
@@ -188,6 +219,9 @@ function startRollupWatcher(apibara, rollupConfig) {
|
|
|
188
219
|
}
|
|
189
220
|
|
|
190
221
|
async function buildProduction(apibara, rollupConfig) {
|
|
222
|
+
apibara.logger.start(
|
|
223
|
+
`Building ${colors.cyan(apibara.indexers.length)} indexers`
|
|
224
|
+
);
|
|
191
225
|
try {
|
|
192
226
|
const bundle = await rollup$1(rollupConfig);
|
|
193
227
|
if (Array.isArray(rollupConfig.output)) {
|
|
@@ -200,9 +234,12 @@ async function buildProduction(apibara, rollupConfig) {
|
|
|
200
234
|
throw new Error("No output options specified in Rollup config");
|
|
201
235
|
}
|
|
202
236
|
await bundle.close();
|
|
203
|
-
|
|
237
|
+
apibara.logger.success("Build succeeded!");
|
|
238
|
+
apibara.logger.info(
|
|
239
|
+
`You can start the indexers with ${colors.cyan("apibara start")}`
|
|
240
|
+
);
|
|
204
241
|
} catch (error) {
|
|
205
|
-
|
|
242
|
+
apibara.logger.error("Build failed", error);
|
|
206
243
|
throw error;
|
|
207
244
|
}
|
|
208
245
|
}
|
|
@@ -213,10 +250,17 @@ async function build(apibara) {
|
|
|
213
250
|
return apibara.options.dev ? await watchDev(apibara, rollupConfig) : await buildProduction(apibara, rollupConfig);
|
|
214
251
|
}
|
|
215
252
|
|
|
253
|
+
function prettyPath(path, highlight = true) {
|
|
254
|
+
const rel = relative(process.cwd(), path);
|
|
255
|
+
return highlight ? colors.cyan(rel) : rel;
|
|
256
|
+
}
|
|
257
|
+
|
|
216
258
|
async function prepare(apibara) {
|
|
217
259
|
await prepareDir(apibara.options.buildDir);
|
|
218
260
|
await prepareDir(apibara.options.outputDir);
|
|
219
|
-
|
|
261
|
+
apibara.logger.success(
|
|
262
|
+
`Output directory ${prettyPath(apibara.options.outputDir)} cleaned`
|
|
263
|
+
);
|
|
220
264
|
}
|
|
221
265
|
async function prepareDir(dir) {
|
|
222
266
|
await fsp.mkdir(dir, { recursive: true });
|
|
@@ -245,88 +289,13 @@ declare module "apibara/types" {`,
|
|
|
245
289
|
) : "",
|
|
246
290
|
"}",
|
|
247
291
|
// Makes this a module for augmentation purposes
|
|
248
|
-
"export type {}"
|
|
249
|
-
];
|
|
250
|
-
const declarations = [
|
|
251
|
-
// local apibara augmentations
|
|
252
|
-
'/// <reference path="./apibara-config.d.ts" />'
|
|
292
|
+
"export type {};"
|
|
253
293
|
];
|
|
254
294
|
const buildFiles = [];
|
|
255
295
|
buildFiles.push({
|
|
256
296
|
path: join(typesDir, "apibara-config.d.ts"),
|
|
257
297
|
contents: config.join("\n")
|
|
258
298
|
});
|
|
259
|
-
buildFiles.push({
|
|
260
|
-
path: join(typesDir, "apibara.d.ts"),
|
|
261
|
-
contents: declarations.join("\n")
|
|
262
|
-
});
|
|
263
|
-
if (apibara.options.typescript.generateTsConfig) {
|
|
264
|
-
const tsConfigPath = resolve(
|
|
265
|
-
apibara.options.buildDir,
|
|
266
|
-
apibara.options.typescript.tsconfigPath
|
|
267
|
-
);
|
|
268
|
-
const tsconfigDir = dirname(tsConfigPath);
|
|
269
|
-
const tsConfig = defu(apibara.options.typescript.tsConfig, {
|
|
270
|
-
compilerOptions: {
|
|
271
|
-
forceConsistentCasingInFileNames: true,
|
|
272
|
-
strict: apibara.options.typescript.strict,
|
|
273
|
-
noEmit: true,
|
|
274
|
-
target: "ESNext",
|
|
275
|
-
module: "ESNext",
|
|
276
|
-
moduleResolution: "Bundler",
|
|
277
|
-
allowJs: true,
|
|
278
|
-
resolveJsonModule: true,
|
|
279
|
-
jsx: "preserve",
|
|
280
|
-
allowSyntheticDefaultImports: true,
|
|
281
|
-
jsxFactory: "h",
|
|
282
|
-
jsxFragmentFactory: "Fragment"
|
|
283
|
-
},
|
|
284
|
-
include: [
|
|
285
|
-
relativeWithDot(tsconfigDir, join(typesDir, "apibara.d.ts")).replace(
|
|
286
|
-
/^(?=[^.])/,
|
|
287
|
-
"./"
|
|
288
|
-
)
|
|
289
|
-
]
|
|
290
|
-
});
|
|
291
|
-
for (const alias in tsConfig.compilerOptions.paths) {
|
|
292
|
-
const paths = tsConfig.compilerOptions.paths[alias];
|
|
293
|
-
tsConfig.compilerOptions.paths[alias] = await Promise.all(
|
|
294
|
-
paths.map(async (path) => {
|
|
295
|
-
if (!isAbsolute(path)) {
|
|
296
|
-
return path;
|
|
297
|
-
}
|
|
298
|
-
const stats = await fsp.stat(path).catch(
|
|
299
|
-
() => null
|
|
300
|
-
/* file does not exist */
|
|
301
|
-
);
|
|
302
|
-
return relativeWithDot(
|
|
303
|
-
tsconfigDir,
|
|
304
|
-
stats?.isFile() ? path.replace(/(?<=\w)\.\w+$/g, "") : path
|
|
305
|
-
);
|
|
306
|
-
})
|
|
307
|
-
);
|
|
308
|
-
}
|
|
309
|
-
tsConfig.include = [
|
|
310
|
-
...new Set(
|
|
311
|
-
tsConfig.include.map(
|
|
312
|
-
(p) => isAbsolute(p) ? relativeWithDot(tsconfigDir, p) : p
|
|
313
|
-
)
|
|
314
|
-
)
|
|
315
|
-
];
|
|
316
|
-
if (tsConfig.exclude) {
|
|
317
|
-
tsConfig.exclude = [
|
|
318
|
-
...new Set(
|
|
319
|
-
tsConfig.exclude.map(
|
|
320
|
-
(p) => isAbsolute(p) ? relativeWithDot(tsconfigDir, p) : p
|
|
321
|
-
)
|
|
322
|
-
)
|
|
323
|
-
];
|
|
324
|
-
}
|
|
325
|
-
buildFiles.push({
|
|
326
|
-
path: tsConfigPath,
|
|
327
|
-
contents: JSON.stringify(tsConfig, null, 2)
|
|
328
|
-
});
|
|
329
|
-
}
|
|
330
299
|
await Promise.all(
|
|
331
300
|
buildFiles.map(async (file) => {
|
|
332
301
|
const _file = resolve(apibara.options.buildDir, file.path);
|
|
@@ -334,12 +303,7 @@ declare module "apibara/types" {`,
|
|
|
334
303
|
await fsp.writeFile(_file, file.contents);
|
|
335
304
|
})
|
|
336
305
|
);
|
|
337
|
-
|
|
338
|
-
}
|
|
339
|
-
const RELATIVE_RE = /^\.{1,2}\//;
|
|
340
|
-
function relativeWithDot(from, to) {
|
|
341
|
-
const rel = relative(from, to);
|
|
342
|
-
return RELATIVE_RE.test(rel) ? rel : `./${rel}`;
|
|
306
|
+
apibara.logger.success(`Types written to ${prettyPath(typesDir)}`);
|
|
343
307
|
}
|
|
344
308
|
|
|
345
309
|
export { build, createApibara, prepare, writeTypes };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
type Options$1 = {
|
|
2
|
+
argIndexerId?: string;
|
|
3
|
+
argChain?: string;
|
|
4
|
+
argNetwork?: string;
|
|
5
|
+
argStorage?: string;
|
|
6
|
+
argDnaUrl?: string;
|
|
7
|
+
};
|
|
8
|
+
declare function addIndexer({ argIndexerId, argChain, argNetwork, argStorage, argDnaUrl, }: Options$1): Promise<void>;
|
|
9
|
+
|
|
10
|
+
type Options = {
|
|
11
|
+
argTargetDir: string;
|
|
12
|
+
argLanguage?: string;
|
|
13
|
+
argNoCreateIndexer?: boolean;
|
|
14
|
+
};
|
|
15
|
+
declare function initializeProject({ argTargetDir, argLanguage, argNoCreateIndexer, }: Options): Promise<void>;
|
|
16
|
+
|
|
17
|
+
export { addIndexer, initializeProject };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
type Options$1 = {
|
|
2
|
+
argIndexerId?: string;
|
|
3
|
+
argChain?: string;
|
|
4
|
+
argNetwork?: string;
|
|
5
|
+
argStorage?: string;
|
|
6
|
+
argDnaUrl?: string;
|
|
7
|
+
};
|
|
8
|
+
declare function addIndexer({ argIndexerId, argChain, argNetwork, argStorage, argDnaUrl, }: Options$1): Promise<void>;
|
|
9
|
+
|
|
10
|
+
type Options = {
|
|
11
|
+
argTargetDir: string;
|
|
12
|
+
argLanguage?: string;
|
|
13
|
+
argNoCreateIndexer?: boolean;
|
|
14
|
+
};
|
|
15
|
+
declare function initializeProject({ argTargetDir, argLanguage, argNoCreateIndexer, }: Options): Promise<void>;
|
|
16
|
+
|
|
17
|
+
export { addIndexer, initializeProject };
|