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,97 @@
|
|
|
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: "next",
|
|
70
|
+
"@apibara/indexer": "next",
|
|
71
|
+
"@apibara/protocol": "next",
|
|
72
|
+
// Chain Dependencies
|
|
73
|
+
"@apibara/evm": "next",
|
|
74
|
+
"@apibara/beaconchain": "next",
|
|
75
|
+
"@apibara/starknet": "next",
|
|
76
|
+
// Storage Dependencies
|
|
77
|
+
"@apibara/plugin-drizzle": "next",
|
|
78
|
+
"@apibara/plugin-mongo": "next",
|
|
79
|
+
"@apibara/plugin-sqlite": "next",
|
|
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
|
+
"@types/node": "^20.5.2",
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export const dnaUrls = {
|
|
92
|
+
ethereum: "https://ethereum.preview.apibara.org",
|
|
93
|
+
ethereumSepolia: "https://ethereum-sepolia.preview.apibara.org",
|
|
94
|
+
beaconchain: "https://beaconchain.preview.apibara.org",
|
|
95
|
+
starknet: "https://starknet.preview.apibara.org",
|
|
96
|
+
starknetSepolia: "https://starknet-sepolia.preview.apibara.org",
|
|
97
|
+
};
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import consola from "consola";
|
|
4
|
+
import prompts from "prompts";
|
|
5
|
+
import { addIndexer } from "./add";
|
|
6
|
+
import { cyan, green } from "./colors";
|
|
7
|
+
import {
|
|
8
|
+
createGitIgnoreFile,
|
|
9
|
+
generateApibaraConfig,
|
|
10
|
+
generatePackageJson,
|
|
11
|
+
generateTsConfig,
|
|
12
|
+
} from "./templates";
|
|
13
|
+
import type { Language } from "./types";
|
|
14
|
+
import {
|
|
15
|
+
cancelOperation,
|
|
16
|
+
emptyDir,
|
|
17
|
+
formatFile,
|
|
18
|
+
getLanguageFromAlias,
|
|
19
|
+
getPackageManager,
|
|
20
|
+
isEmpty,
|
|
21
|
+
validateLanguage,
|
|
22
|
+
} from "./utils";
|
|
23
|
+
|
|
24
|
+
type Options = {
|
|
25
|
+
argTargetDir: string;
|
|
26
|
+
argLanguage?: string;
|
|
27
|
+
argNoCreateIndexer?: boolean;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export async function initializeProject({
|
|
31
|
+
argTargetDir,
|
|
32
|
+
argLanguage,
|
|
33
|
+
argNoCreateIndexer,
|
|
34
|
+
}: Options) {
|
|
35
|
+
const cwd = process.cwd();
|
|
36
|
+
validateLanguage(argLanguage, true);
|
|
37
|
+
|
|
38
|
+
console.log();
|
|
39
|
+
|
|
40
|
+
const result = await prompts(
|
|
41
|
+
[
|
|
42
|
+
{
|
|
43
|
+
type: () =>
|
|
44
|
+
argTargetDir &&
|
|
45
|
+
(!fs.existsSync(argTargetDir) || isEmpty(argTargetDir))
|
|
46
|
+
? null
|
|
47
|
+
: "select",
|
|
48
|
+
name: "overwrite",
|
|
49
|
+
message: () =>
|
|
50
|
+
(argTargetDir === "."
|
|
51
|
+
? "Current directory"
|
|
52
|
+
: `Target directory "${argTargetDir}"`) +
|
|
53
|
+
" is not empty. Please choose how to proceed:",
|
|
54
|
+
initial: 0,
|
|
55
|
+
choices: [
|
|
56
|
+
{
|
|
57
|
+
title: "Cancel operation",
|
|
58
|
+
value: "no",
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
title: "Remove existing files and continue",
|
|
62
|
+
value: "yes",
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
title: "Ignore files and continue",
|
|
66
|
+
value: "ignore",
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
hint: "\nCurrent Working Directory: " + cwd,
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
type: (_, { overwrite }: { overwrite?: string }) => {
|
|
73
|
+
if (overwrite === "no") {
|
|
74
|
+
cancelOperation();
|
|
75
|
+
}
|
|
76
|
+
return null;
|
|
77
|
+
},
|
|
78
|
+
name: "overwriteChecker",
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
type: argLanguage ? null : "select",
|
|
82
|
+
name: "prompt_language",
|
|
83
|
+
message: "Select a language:",
|
|
84
|
+
choices: [
|
|
85
|
+
{
|
|
86
|
+
title: "Typescript",
|
|
87
|
+
value: "typescript",
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
title: "Javascript",
|
|
91
|
+
value: "javascript",
|
|
92
|
+
},
|
|
93
|
+
],
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
{
|
|
97
|
+
onCancel: () => {
|
|
98
|
+
cancelOperation();
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
const { overwrite, prompt_language } = result as {
|
|
104
|
+
overwrite: "no" | "yes" | "ignore";
|
|
105
|
+
prompt_language: "typescript" | "javascript";
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const root = path.join(cwd, argTargetDir);
|
|
109
|
+
if (overwrite === "yes") {
|
|
110
|
+
emptyDir(root);
|
|
111
|
+
} else if (!fs.existsSync(root)) {
|
|
112
|
+
fs.mkdirSync(root, { recursive: true });
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const lang: Language = argLanguage
|
|
116
|
+
? getLanguageFromAlias(argLanguage)
|
|
117
|
+
: prompt_language;
|
|
118
|
+
|
|
119
|
+
const isTs = lang === "typescript";
|
|
120
|
+
const configExt = isTs ? "ts" : "js";
|
|
121
|
+
|
|
122
|
+
console.log("\n");
|
|
123
|
+
consola.info(`Initializing project in ${argTargetDir}\n\n`);
|
|
124
|
+
|
|
125
|
+
// Generate package.json
|
|
126
|
+
const packageJsonPath = path.join(root, "package.json");
|
|
127
|
+
const packageJson = generatePackageJson(isTs);
|
|
128
|
+
fs.writeFileSync(
|
|
129
|
+
packageJsonPath,
|
|
130
|
+
JSON.stringify(packageJson, null, 2) + "\n",
|
|
131
|
+
);
|
|
132
|
+
await formatFile(packageJsonPath);
|
|
133
|
+
consola.success("Created", cyan("package.json"));
|
|
134
|
+
|
|
135
|
+
// Generate tsconfig.json if TypeScript
|
|
136
|
+
if (isTs) {
|
|
137
|
+
const tsConfigPath = path.join(root, "tsconfig.json");
|
|
138
|
+
const tsConfig = generateTsConfig();
|
|
139
|
+
fs.writeFileSync(tsConfigPath, JSON.stringify(tsConfig, null, 2) + "\n");
|
|
140
|
+
await formatFile(tsConfigPath);
|
|
141
|
+
consola.success("Created", cyan("tsconfig.json"));
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const apibaraConfigPath = path.join(root, `apibara.config.${configExt}`);
|
|
145
|
+
// Generate apibara.config
|
|
146
|
+
const apibaraConfig = generateApibaraConfig(isTs);
|
|
147
|
+
fs.writeFileSync(apibaraConfigPath, apibaraConfig);
|
|
148
|
+
await formatFile(apibaraConfigPath);
|
|
149
|
+
consola.success("Created", cyan(`apibara.config.${configExt}`));
|
|
150
|
+
|
|
151
|
+
// Create "indexers" directory if not exists
|
|
152
|
+
const indexersDir = path.join(root, "indexers");
|
|
153
|
+
if (!fs.existsSync(indexersDir)) {
|
|
154
|
+
fs.mkdirSync(indexersDir, { recursive: true });
|
|
155
|
+
consola.success(`Created ${cyan("indexers")} directory`);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
await createGitIgnoreFile(root);
|
|
159
|
+
|
|
160
|
+
console.log("\n");
|
|
161
|
+
|
|
162
|
+
consola.ready(green("Project initialized successfully"));
|
|
163
|
+
|
|
164
|
+
console.log();
|
|
165
|
+
|
|
166
|
+
if (!argNoCreateIndexer) {
|
|
167
|
+
consola.info("Let's create an indexer\n");
|
|
168
|
+
|
|
169
|
+
await addIndexer({ argRootDir: argTargetDir });
|
|
170
|
+
} else {
|
|
171
|
+
const pkgManager = getPackageManager();
|
|
172
|
+
consola.info(
|
|
173
|
+
"Run ",
|
|
174
|
+
green(`${pkgManager.name} install`),
|
|
175
|
+
" to install all dependencies",
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
}
|