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
package/src/core/build/types.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import fsp from "node:fs/promises";
|
|
2
2
|
import type { Apibara } from "apibara/types";
|
|
3
|
-
import
|
|
4
|
-
import defu from "defu";
|
|
5
|
-
import { dirname, isAbsolute, join, relative, resolve } from "pathe";
|
|
6
|
-
import type { TSConfig } from "pkg-types";
|
|
3
|
+
import { dirname, join, resolve } from "pathe";
|
|
7
4
|
import { type JSValue, generateTypes, resolveSchema } from "untyped";
|
|
5
|
+
import { prettyPath } from "../path";
|
|
8
6
|
|
|
9
7
|
export async function writeTypes(apibara: Apibara) {
|
|
10
8
|
const typesDir = resolve(apibara.options.buildDir, "types");
|
|
@@ -31,12 +29,7 @@ declare module "apibara/types" {`,
|
|
|
31
29
|
: "",
|
|
32
30
|
"}",
|
|
33
31
|
// Makes this a module for augmentation purposes
|
|
34
|
-
"export type {}",
|
|
35
|
-
];
|
|
36
|
-
|
|
37
|
-
const declarations = [
|
|
38
|
-
// local apibara augmentations
|
|
39
|
-
'/// <reference path="./apibara-config.d.ts" />',
|
|
32
|
+
"export type {};",
|
|
40
33
|
];
|
|
41
34
|
|
|
42
35
|
const buildFiles: { path: string; contents: string }[] = [];
|
|
@@ -46,83 +39,6 @@ declare module "apibara/types" {`,
|
|
|
46
39
|
contents: config.join("\n"),
|
|
47
40
|
});
|
|
48
41
|
|
|
49
|
-
buildFiles.push({
|
|
50
|
-
path: join(typesDir, "apibara.d.ts"),
|
|
51
|
-
contents: declarations.join("\n"),
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
if (apibara.options.typescript.generateTsConfig) {
|
|
55
|
-
const tsConfigPath = resolve(
|
|
56
|
-
apibara.options.buildDir,
|
|
57
|
-
apibara.options.typescript.tsconfigPath,
|
|
58
|
-
);
|
|
59
|
-
const tsconfigDir = dirname(tsConfigPath);
|
|
60
|
-
const tsConfig: TSConfig = defu(apibara.options.typescript.tsConfig, {
|
|
61
|
-
compilerOptions: {
|
|
62
|
-
forceConsistentCasingInFileNames: true,
|
|
63
|
-
strict: apibara.options.typescript.strict,
|
|
64
|
-
noEmit: true,
|
|
65
|
-
target: "ESNext",
|
|
66
|
-
module: "ESNext",
|
|
67
|
-
moduleResolution: "Bundler",
|
|
68
|
-
allowJs: true,
|
|
69
|
-
resolveJsonModule: true,
|
|
70
|
-
jsx: "preserve",
|
|
71
|
-
allowSyntheticDefaultImports: true,
|
|
72
|
-
jsxFactory: "h",
|
|
73
|
-
jsxFragmentFactory: "Fragment",
|
|
74
|
-
},
|
|
75
|
-
include: [
|
|
76
|
-
relativeWithDot(tsconfigDir, join(typesDir, "apibara.d.ts")).replace(
|
|
77
|
-
/^(?=[^.])/,
|
|
78
|
-
"./",
|
|
79
|
-
),
|
|
80
|
-
],
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
for (const alias in tsConfig.compilerOptions!.paths) {
|
|
84
|
-
const paths = tsConfig.compilerOptions!.paths[alias];
|
|
85
|
-
tsConfig.compilerOptions!.paths[alias] = await Promise.all(
|
|
86
|
-
paths.map(async (path: string) => {
|
|
87
|
-
if (!isAbsolute(path)) {
|
|
88
|
-
return path;
|
|
89
|
-
}
|
|
90
|
-
const stats = await fsp
|
|
91
|
-
.stat(path)
|
|
92
|
-
.catch(() => null /* file does not exist */);
|
|
93
|
-
return relativeWithDot(
|
|
94
|
-
tsconfigDir,
|
|
95
|
-
stats?.isFile()
|
|
96
|
-
? path.replace(/(?<=\w)\.\w+$/g, "") /* remove extension */
|
|
97
|
-
: path,
|
|
98
|
-
);
|
|
99
|
-
}),
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
tsConfig.include = [
|
|
104
|
-
...new Set(
|
|
105
|
-
tsConfig.include!.map((p) =>
|
|
106
|
-
isAbsolute(p) ? relativeWithDot(tsconfigDir, p) : p,
|
|
107
|
-
),
|
|
108
|
-
),
|
|
109
|
-
];
|
|
110
|
-
if (tsConfig.exclude) {
|
|
111
|
-
tsConfig.exclude = [
|
|
112
|
-
...new Set(
|
|
113
|
-
tsConfig.exclude!.map((p) =>
|
|
114
|
-
isAbsolute(p) ? relativeWithDot(tsconfigDir, p) : p,
|
|
115
|
-
),
|
|
116
|
-
),
|
|
117
|
-
];
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
buildFiles.push({
|
|
121
|
-
path: tsConfigPath,
|
|
122
|
-
contents: JSON.stringify(tsConfig, null, 2),
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
|
|
126
42
|
await Promise.all(
|
|
127
43
|
buildFiles.map(async (file) => {
|
|
128
44
|
const _file = resolve(apibara.options.buildDir, file.path);
|
|
@@ -131,12 +47,5 @@ declare module "apibara/types" {`,
|
|
|
131
47
|
}),
|
|
132
48
|
);
|
|
133
49
|
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
const RELATIVE_RE = /^\.{1,2}\//;
|
|
138
|
-
|
|
139
|
-
export function relativeWithDot(from: string, to: string) {
|
|
140
|
-
const rel = relative(from, to);
|
|
141
|
-
return RELATIVE_RE.test(rel) ? rel : `./${rel}`;
|
|
50
|
+
apibara.logger.success(`Types written to ${prettyPath(typesDir)}`);
|
|
142
51
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
// import { defaultSink } from "@apibara/indexer";
|
|
2
1
|
import type { ApibaraConfig } from "apibara/types";
|
|
3
2
|
|
|
4
3
|
export const ApibaraDefaults: ApibaraConfig = {
|
|
5
4
|
rootDir: ".",
|
|
5
|
+
indexersDir: "indexers",
|
|
6
6
|
|
|
7
7
|
runtimeConfig: {},
|
|
8
8
|
hooks: {},
|
|
@@ -11,10 +11,7 @@ export const ApibaraDefaults: ApibaraConfig = {
|
|
|
11
11
|
|
|
12
12
|
typescript: {
|
|
13
13
|
strict: false,
|
|
14
|
-
generateTsConfig: true,
|
|
15
14
|
generateRuntimeConfigTypes: true,
|
|
16
|
-
tsconfigPath: "types/tsconfig.json",
|
|
17
15
|
internalPaths: false,
|
|
18
|
-
tsConfig: {},
|
|
19
16
|
},
|
|
20
17
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ApibaraOptions } from "apibara/types";
|
|
2
2
|
|
|
3
3
|
export async function resolveRuntimeConfigOptions(options: ApibaraOptions) {
|
|
4
|
-
options.runtimeConfig = { ...options.runtimeConfig
|
|
4
|
+
options.runtimeConfig = { ...options.runtimeConfig };
|
|
5
5
|
process.env.APIBARA_RUNTIME_CONFIG = JSON.stringify(options.runtimeConfig);
|
|
6
6
|
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import type { Apibara, ApibaraDynamicConfig } from "apibara/types";
|
|
2
|
-
import consola from "consola";
|
|
3
2
|
|
|
4
3
|
export async function updateApibaraConfig(
|
|
5
4
|
apibara: Apibara,
|
|
6
|
-
|
|
5
|
+
_config: ApibaraDynamicConfig,
|
|
7
6
|
) {
|
|
8
7
|
await apibara.hooks.callHook("rollup:reload");
|
|
9
|
-
|
|
8
|
+
apibara.logger.success("Apibara config hot reloaded!");
|
|
10
9
|
}
|
package/src/core/path.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { colors } from "consola/utils";
|
|
2
|
+
import { relative } from "pathe";
|
|
3
|
+
|
|
4
|
+
/** Return a (possibly highlighted) path relative to the current working directory.
|
|
5
|
+
*
|
|
6
|
+
* From nitrojs/nitro.
|
|
7
|
+
*/
|
|
8
|
+
export function prettyPath(path: string, highlight = true) {
|
|
9
|
+
const rel = relative(process.cwd(), path);
|
|
10
|
+
return highlight ? colors.cyan(rel) : rel;
|
|
11
|
+
}
|
package/src/core/scan.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Apibara } from "apibara/types";
|
|
2
|
+
import fse from "fs-extra";
|
|
3
|
+
import { basename, join } from "pathe";
|
|
4
|
+
|
|
5
|
+
const INDEXER_EXTENSIONS = [".indexer.ts", ".indexer.js"];
|
|
6
|
+
|
|
7
|
+
export async function scanIndexers(apibara: Apibara) {
|
|
8
|
+
apibara.logger.debug("Scanning indexers");
|
|
9
|
+
|
|
10
|
+
const indexersDir = join(
|
|
11
|
+
apibara.options.rootDir,
|
|
12
|
+
apibara.options.indexersDir,
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
if (!fse.existsSync(indexersDir)) {
|
|
16
|
+
throw new Error(`Indexers directory not found: ${indexersDir}`);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
apibara.indexers = [];
|
|
20
|
+
|
|
21
|
+
for (const file of fse.readdirSync(indexersDir)) {
|
|
22
|
+
const indexerName = indexerNameFromFile(file);
|
|
23
|
+
if (indexerName) {
|
|
24
|
+
apibara.indexers.push({
|
|
25
|
+
name: indexerName,
|
|
26
|
+
indexer: join(indexersDir, file),
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
apibara.logger.debug(`Found ${apibara.indexers.length} indexers`);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function indexerNameFromFile(file: string) {
|
|
35
|
+
for (const extension of INDEXER_EXTENSIONS) {
|
|
36
|
+
if (file.endsWith(extension)) {
|
|
37
|
+
return basename(file, extension);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import consola from "consola";
|
|
3
|
+
import prompts from "prompts";
|
|
4
|
+
import { cyan, red, reset } from "./colors";
|
|
5
|
+
import {
|
|
6
|
+
type ChainDataType,
|
|
7
|
+
type NetworkDataType,
|
|
8
|
+
type StorageDataType,
|
|
9
|
+
chains,
|
|
10
|
+
storages,
|
|
11
|
+
} from "./constants";
|
|
12
|
+
import { initializeProject } from "./init";
|
|
13
|
+
import {
|
|
14
|
+
createIndexerFile,
|
|
15
|
+
createStorageRelatedFiles,
|
|
16
|
+
updateApibaraConfigFile,
|
|
17
|
+
updatePackageJson,
|
|
18
|
+
} from "./templates";
|
|
19
|
+
import type { Chain, IndexerOptions, Network, Storage } from "./types";
|
|
20
|
+
import {
|
|
21
|
+
cancelOperation,
|
|
22
|
+
checkFileExists,
|
|
23
|
+
convertKebabToCamelCase,
|
|
24
|
+
getApibaraConfigLanguage,
|
|
25
|
+
getPackageManager,
|
|
26
|
+
hasApibaraConfig,
|
|
27
|
+
validateChain,
|
|
28
|
+
validateDnaUrl,
|
|
29
|
+
validateIndexerId,
|
|
30
|
+
validateNetwork,
|
|
31
|
+
validateStorage,
|
|
32
|
+
} from "./utils";
|
|
33
|
+
|
|
34
|
+
type Options = {
|
|
35
|
+
argIndexerId?: string;
|
|
36
|
+
argChain?: string;
|
|
37
|
+
argNetwork?: string;
|
|
38
|
+
argStorage?: string;
|
|
39
|
+
argDnaUrl?: string;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export async function addIndexer({
|
|
43
|
+
argIndexerId,
|
|
44
|
+
argChain,
|
|
45
|
+
argNetwork,
|
|
46
|
+
argStorage,
|
|
47
|
+
argDnaUrl,
|
|
48
|
+
}: Options) {
|
|
49
|
+
const configExists = hasApibaraConfig(process.cwd());
|
|
50
|
+
|
|
51
|
+
if (!configExists) {
|
|
52
|
+
consola.error("No apibara.config found in the current directory.");
|
|
53
|
+
|
|
54
|
+
const prompt_initialize = await prompts({
|
|
55
|
+
type: "confirm",
|
|
56
|
+
name: "prompt_initialize",
|
|
57
|
+
message: reset(
|
|
58
|
+
"Do you want to initialize a apibara project here before adding an indexer?",
|
|
59
|
+
),
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
if (prompt_initialize.prompt_initialize) {
|
|
63
|
+
await initializeProject({
|
|
64
|
+
argTargetDir: process.cwd(),
|
|
65
|
+
argNoCreateIndexer: true,
|
|
66
|
+
});
|
|
67
|
+
} else {
|
|
68
|
+
consola.info(
|
|
69
|
+
`Initialize a project with ${cyan("apibara init")} before adding an indexer`,
|
|
70
|
+
);
|
|
71
|
+
throw new Error(
|
|
72
|
+
red("✖") + " Operation cancelled: No apibara.config found",
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const language = getApibaraConfigLanguage(process.cwd());
|
|
78
|
+
|
|
79
|
+
validateIndexerId(argIndexerId, true);
|
|
80
|
+
validateChain(argChain, true);
|
|
81
|
+
validateNetwork(argChain, argNetwork, true);
|
|
82
|
+
validateStorage(argStorage, true);
|
|
83
|
+
validateDnaUrl(argDnaUrl, true);
|
|
84
|
+
|
|
85
|
+
const result = await prompts(
|
|
86
|
+
[
|
|
87
|
+
{
|
|
88
|
+
type: argIndexerId ? null : "text",
|
|
89
|
+
name: "prompt_indexerId",
|
|
90
|
+
message: reset("Indexer ID:"),
|
|
91
|
+
initial: argIndexerId ?? "my-indexer",
|
|
92
|
+
validate: (id) =>
|
|
93
|
+
validateIndexerId(id)
|
|
94
|
+
? checkFileExists(
|
|
95
|
+
path.join(
|
|
96
|
+
process.cwd(),
|
|
97
|
+
"indexers",
|
|
98
|
+
`${id}.indexer.${language === "typescript" ? "ts" : "js"}`,
|
|
99
|
+
),
|
|
100
|
+
).then(({ exists }) =>
|
|
101
|
+
exists
|
|
102
|
+
? `Indexer ${cyan(`${id}.indexer.${language === "typescript" ? "ts" : "js"}`)} already exists`
|
|
103
|
+
: true,
|
|
104
|
+
)
|
|
105
|
+
: "Invalid indexer ID, it cannot be empty and must be in kebab-case format",
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
type: argChain ? null : "select",
|
|
109
|
+
name: "prompt_chain",
|
|
110
|
+
message: reset("Select a chain:"),
|
|
111
|
+
choices: chains.map((chain) => ({
|
|
112
|
+
title: chain.color(chain.display),
|
|
113
|
+
value: chain,
|
|
114
|
+
})),
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
type: argNetwork ? null : "select",
|
|
118
|
+
name: "prompt_network",
|
|
119
|
+
message: reset("Select a network:"),
|
|
120
|
+
choices: (chain: ChainDataType | undefined) => [
|
|
121
|
+
...(
|
|
122
|
+
chain?.networks ??
|
|
123
|
+
chains.find((c) => c.name === argChain)?.networks ??
|
|
124
|
+
[]
|
|
125
|
+
).map((network) => ({
|
|
126
|
+
title: network.color(network.display),
|
|
127
|
+
value: network,
|
|
128
|
+
})),
|
|
129
|
+
{
|
|
130
|
+
title: cyan("Other"),
|
|
131
|
+
value: {
|
|
132
|
+
color: cyan,
|
|
133
|
+
display: "Other",
|
|
134
|
+
name: "other",
|
|
135
|
+
} as NetworkDataType,
|
|
136
|
+
},
|
|
137
|
+
],
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
type: (network: NetworkDataType | undefined) => {
|
|
141
|
+
if (network || argNetwork) {
|
|
142
|
+
return network?.name === "other" || argNetwork === "other"
|
|
143
|
+
? "text"
|
|
144
|
+
: null;
|
|
145
|
+
}
|
|
146
|
+
return null;
|
|
147
|
+
},
|
|
148
|
+
name: "prompt_dnaUrl",
|
|
149
|
+
message: reset("Enter a DNA URL:"),
|
|
150
|
+
validate: (url) => validateDnaUrl(url) || "Provide a valid DNA Url",
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
type: argStorage ? null : "select",
|
|
154
|
+
name: "prompt_storage",
|
|
155
|
+
message: reset("Select a storage:"),
|
|
156
|
+
choices: storages.map((storage) => ({
|
|
157
|
+
title: storage.color(storage.display),
|
|
158
|
+
value: storage,
|
|
159
|
+
})),
|
|
160
|
+
},
|
|
161
|
+
],
|
|
162
|
+
{
|
|
163
|
+
onCancel: () => {
|
|
164
|
+
cancelOperation();
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
);
|
|
168
|
+
|
|
169
|
+
const {
|
|
170
|
+
prompt_indexerId,
|
|
171
|
+
prompt_chain,
|
|
172
|
+
prompt_network,
|
|
173
|
+
prompt_storage,
|
|
174
|
+
prompt_dnaUrl,
|
|
175
|
+
} = result as {
|
|
176
|
+
prompt_indexerId: string | undefined;
|
|
177
|
+
prompt_chain: ChainDataType | undefined;
|
|
178
|
+
prompt_network: NetworkDataType | undefined;
|
|
179
|
+
prompt_storage: StorageDataType | undefined;
|
|
180
|
+
prompt_dnaUrl: string | undefined;
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
if (!argIndexerId && !prompt_indexerId) {
|
|
184
|
+
throw new Error(red("✖") + " Indexer ID is required");
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (!argChain && !prompt_chain) {
|
|
188
|
+
throw new Error(red("✖") + " Chain is required");
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (!argNetwork && !prompt_network) {
|
|
192
|
+
throw new Error(red("✖") + " Network is required");
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const indexerFileId = argIndexerId! ?? prompt_indexerId!;
|
|
196
|
+
|
|
197
|
+
const pkgManager = getPackageManager();
|
|
198
|
+
|
|
199
|
+
const options: IndexerOptions = {
|
|
200
|
+
cwd: process.cwd(),
|
|
201
|
+
indexerFileId,
|
|
202
|
+
indexerId: convertKebabToCamelCase(indexerFileId),
|
|
203
|
+
chain: (argChain as Chain) ?? prompt_chain?.name!,
|
|
204
|
+
network: (argNetwork as Network) ?? prompt_network?.name!,
|
|
205
|
+
storage: (argStorage as Storage) ?? prompt_storage?.name!,
|
|
206
|
+
dnaUrl: argDnaUrl ?? prompt_dnaUrl,
|
|
207
|
+
language,
|
|
208
|
+
packageManager: pkgManager.name,
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
await updateApibaraConfigFile(options);
|
|
212
|
+
|
|
213
|
+
consola.success(
|
|
214
|
+
`Updated ${cyan("apibara.config." + (language === "typescript" ? "ts" : "js"))}`,
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
await updatePackageJson(options);
|
|
218
|
+
|
|
219
|
+
consola.success(`Updated ${cyan("package.json")}`);
|
|
220
|
+
|
|
221
|
+
await createIndexerFile(options);
|
|
222
|
+
|
|
223
|
+
consola.success(
|
|
224
|
+
`Created ${cyan(`${indexerFileId}.indexer.${language === "typescript" ? "ts" : "js"}`)}`,
|
|
225
|
+
);
|
|
226
|
+
|
|
227
|
+
await createStorageRelatedFiles(options);
|
|
228
|
+
|
|
229
|
+
console.log();
|
|
230
|
+
|
|
231
|
+
consola.info(
|
|
232
|
+
`Before running the indexer, run ${cyan(`${options.packageManager} run install`)}${
|
|
233
|
+
language === "typescript"
|
|
234
|
+
? " & " + cyan(`${options.packageManager} run prepare`)
|
|
235
|
+
: ""
|
|
236
|
+
}`,
|
|
237
|
+
);
|
|
238
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { blue, green, red, yellow } from "./colors";
|
|
2
|
+
import type { Chain, ColorFunc, Network } from "./types";
|
|
3
|
+
|
|
4
|
+
export type ChainDataType = {
|
|
5
|
+
name: Chain;
|
|
6
|
+
display: string;
|
|
7
|
+
color: ColorFunc;
|
|
8
|
+
networks: NetworkDataType[];
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type NetworkDataType = {
|
|
12
|
+
name: Network;
|
|
13
|
+
display: string;
|
|
14
|
+
color: ColorFunc;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type LanguageDataType = {
|
|
18
|
+
name: "typescript" | "javascript";
|
|
19
|
+
display: string;
|
|
20
|
+
color: ColorFunc;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type StorageDataType = {
|
|
24
|
+
name: "postgres" | "none";
|
|
25
|
+
display: string;
|
|
26
|
+
color: ColorFunc;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const chains: ChainDataType[] = [
|
|
30
|
+
{
|
|
31
|
+
name: "starknet",
|
|
32
|
+
display: "Starknet",
|
|
33
|
+
color: blue,
|
|
34
|
+
networks: [
|
|
35
|
+
{ name: "mainnet", display: "Mainnet", color: blue },
|
|
36
|
+
{ name: "sepolia", display: "Sepolia", color: yellow },
|
|
37
|
+
],
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: "ethereum",
|
|
41
|
+
display: "Ethereum",
|
|
42
|
+
color: green,
|
|
43
|
+
networks: [
|
|
44
|
+
{ name: "mainnet", display: "Mainnet", color: blue },
|
|
45
|
+
{ name: "sepolia", display: "Sepolia", color: yellow },
|
|
46
|
+
],
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: "beaconchain",
|
|
50
|
+
display: "Beacon Chain",
|
|
51
|
+
color: yellow,
|
|
52
|
+
networks: [{ name: "mainnet", display: "Mainnet", color: yellow }],
|
|
53
|
+
},
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
export const networks: NetworkDataType[] = [
|
|
57
|
+
{ name: "mainnet", display: "Mainnet", color: blue },
|
|
58
|
+
{ name: "sepolia", display: "Sepolia", color: green },
|
|
59
|
+
{ name: "other", display: "Other", color: red },
|
|
60
|
+
];
|
|
61
|
+
|
|
62
|
+
export const storages: StorageDataType[] = [
|
|
63
|
+
{ name: "postgres", display: "Postgres", color: green },
|
|
64
|
+
{ name: "none", display: "None", color: red },
|
|
65
|
+
];
|
|
66
|
+
|
|
67
|
+
export const packageVersions = {
|
|
68
|
+
// Required Dependencies
|
|
69
|
+
apibara: "^2.1.0-beta.2",
|
|
70
|
+
"@apibara/indexer": "^2.1.0-beta.2",
|
|
71
|
+
"@apibara/protocol": "^2.1.0-beta.2",
|
|
72
|
+
// Chain Dependencies
|
|
73
|
+
"@apibara/evm": "^2.1.0-beta.2",
|
|
74
|
+
"@apibara/beaconchain": "^2.1.0-beta.2",
|
|
75
|
+
"@apibara/starknet": "^2.1.0-beta.2",
|
|
76
|
+
// Storage Dependencies
|
|
77
|
+
"@apibara/plugin-drizzle": "^2.1.0-beta.2",
|
|
78
|
+
"@apibara/plugin-mongo": "^2.1.0-beta.2",
|
|
79
|
+
"@apibara/plugin-sqlite": "^2.1.0-beta.2",
|
|
80
|
+
// Postgres Dependencies
|
|
81
|
+
"@electric-sql/pglite": "^0.2.17",
|
|
82
|
+
"drizzle-orm": "^0.37.0",
|
|
83
|
+
pg: "^8.13.1",
|
|
84
|
+
"@types/pg": "^8.11.10",
|
|
85
|
+
"drizzle-kit": "^0.29.0",
|
|
86
|
+
// Typescript Dependencies
|
|
87
|
+
typescript: "^5.6.2",
|
|
88
|
+
"@rollup/plugin-typescript": "^11.1.6",
|
|
89
|
+
"@types/node": "^20.5.2",
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export const dnaUrls = {
|
|
93
|
+
ethereum: "https://ethereum.preview.apibara.org",
|
|
94
|
+
ethereumSepolia: "https://ethereum-sepolia.preview.apibara.org",
|
|
95
|
+
beaconchain: "https://beaconchain.preview.apibara.org",
|
|
96
|
+
starknet: "https://starknet.preview.apibara.org",
|
|
97
|
+
starknetSepolia: "https://starknet-sepolia.preview.apibara.org",
|
|
98
|
+
};
|