apibara 2.1.0-beta.4 → 2.1.0-beta.6
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/core/index.mjs +5 -3
- package/dist/create/index.mjs +88 -3
- package/dist/rollup/index.mjs +4 -3
- package/dist/runtime/dev.mjs +3 -0
- package/dist/runtime/internal/app.d.ts +1 -1
- package/dist/runtime/internal/app.mjs +9 -1
- package/dist/runtime/start.mjs +5 -0
- package/dist/types/index.d.mts +2 -0
- package/dist/types/index.d.ts +2 -0
- package/package.json +5 -7
- package/src/core/build/error.ts +3 -10
- package/src/core/config/defaults.ts +3 -0
- package/src/create/init.ts +6 -3
- package/src/create/templates.ts +101 -0
- package/src/rollup/config.ts +3 -1
- package/src/rollup/plugins/indexers.ts +1 -1
- package/src/runtime/dev.ts +3 -0
- package/src/runtime/internal/app.ts +12 -3
- package/src/runtime/start.ts +5 -0
- package/src/types/config.ts +2 -0
- package/src/types/virtual/indexers.d.ts +4 -1
package/dist/core/index.mjs
CHANGED
|
@@ -24,7 +24,9 @@ const ApibaraDefaults = {
|
|
|
24
24
|
strict: false,
|
|
25
25
|
generateRuntimeConfigTypes: true,
|
|
26
26
|
internalPaths: false
|
|
27
|
-
}
|
|
27
|
+
},
|
|
28
|
+
node: true,
|
|
29
|
+
exportConditions: ["node"]
|
|
28
30
|
};
|
|
29
31
|
|
|
30
32
|
async function resolvePathOptions(options) {
|
|
@@ -141,11 +143,11 @@ function formatRollupError(_error) {
|
|
|
141
143
|
for (const error of errors) {
|
|
142
144
|
const id = error.path || error.id || _error.id;
|
|
143
145
|
let path = isAbsolute(id) ? relative(process.cwd(), id) : id;
|
|
144
|
-
const location = error.loc
|
|
146
|
+
const location = error.loc;
|
|
145
147
|
if (location) {
|
|
146
148
|
path += `:${location.line}:${location.column}`;
|
|
147
149
|
}
|
|
148
|
-
const text = error.
|
|
150
|
+
const text = error.frame;
|
|
149
151
|
logs.push(
|
|
150
152
|
`Rollup error while processing \`${path}\`` + text ? "\n\n" + text : ""
|
|
151
153
|
);
|
package/dist/create/index.mjs
CHANGED
|
@@ -705,6 +705,90 @@ async function createStorageRelatedFiles(options) {
|
|
|
705
705
|
await createDrizzleStorageFiles(options);
|
|
706
706
|
}
|
|
707
707
|
}
|
|
708
|
+
const gitIgnoreItems = [
|
|
709
|
+
{
|
|
710
|
+
isRecommended: false,
|
|
711
|
+
value: "node_modules"
|
|
712
|
+
},
|
|
713
|
+
{
|
|
714
|
+
isRecommended: false,
|
|
715
|
+
value: "dist"
|
|
716
|
+
},
|
|
717
|
+
{
|
|
718
|
+
isRecommended: true,
|
|
719
|
+
description: "build and dev files of apibara",
|
|
720
|
+
value: ".apibara"
|
|
721
|
+
},
|
|
722
|
+
{
|
|
723
|
+
isRecommended: false,
|
|
724
|
+
value: ".env"
|
|
725
|
+
},
|
|
726
|
+
{
|
|
727
|
+
isRecommended: false,
|
|
728
|
+
description: "for mac users",
|
|
729
|
+
value: ".DS_Store"
|
|
730
|
+
}
|
|
731
|
+
];
|
|
732
|
+
async function createGitIgnoreFile(cwd) {
|
|
733
|
+
const gitIgnorePath = path.join(cwd, ".gitignore");
|
|
734
|
+
if (fs.existsSync(gitIgnorePath)) {
|
|
735
|
+
const result = await prompts([
|
|
736
|
+
{
|
|
737
|
+
type: "select",
|
|
738
|
+
name: "overwrite",
|
|
739
|
+
message: `${cyan(".gitignore")} already exists. Please choose how to proceed:`,
|
|
740
|
+
initial: 0,
|
|
741
|
+
choices: [
|
|
742
|
+
{
|
|
743
|
+
title: "Choose items to append in your .gitignore",
|
|
744
|
+
value: "append"
|
|
745
|
+
},
|
|
746
|
+
{
|
|
747
|
+
title: "Keep original",
|
|
748
|
+
value: "ignore"
|
|
749
|
+
},
|
|
750
|
+
{
|
|
751
|
+
title: "Overwrite",
|
|
752
|
+
value: "overwrite"
|
|
753
|
+
}
|
|
754
|
+
]
|
|
755
|
+
},
|
|
756
|
+
{
|
|
757
|
+
type: (overwrite2) => overwrite2 === "append" ? "multiselect" : null,
|
|
758
|
+
name: "ignoreItems",
|
|
759
|
+
message: "Choose items to append in your .gitignore",
|
|
760
|
+
choices: gitIgnoreItems.map((item) => ({
|
|
761
|
+
title: `${yellow(item.value)}${item.description ? ` - ${item.description}` : ""}${item.isRecommended ? ` ${green("(recommended)")}` : ""}`,
|
|
762
|
+
value: item.value
|
|
763
|
+
}))
|
|
764
|
+
}
|
|
765
|
+
]);
|
|
766
|
+
const { overwrite, ignoreItems } = result;
|
|
767
|
+
if (overwrite === "append" && ignoreItems.length > 0) {
|
|
768
|
+
const gitIgnoreContent = fs.readFileSync(gitIgnorePath, "utf8");
|
|
769
|
+
fs.writeFileSync(
|
|
770
|
+
gitIgnorePath,
|
|
771
|
+
`${gitIgnoreContent}
|
|
772
|
+
${result.ignoreItems.join("\n")}`
|
|
773
|
+
);
|
|
774
|
+
consola.success(`Updated ${cyan(".gitignore")}`);
|
|
775
|
+
return;
|
|
776
|
+
}
|
|
777
|
+
if (overwrite === "overwrite") {
|
|
778
|
+
fs.writeFileSync(
|
|
779
|
+
gitIgnorePath,
|
|
780
|
+
gitIgnoreItems.map((item) => item.value).join("\n")
|
|
781
|
+
);
|
|
782
|
+
consola.success(`Updated ${cyan(".gitignore")}`);
|
|
783
|
+
return;
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
fs.writeFileSync(
|
|
787
|
+
gitIgnorePath,
|
|
788
|
+
gitIgnoreItems.map((item) => item.value).join("\n")
|
|
789
|
+
);
|
|
790
|
+
consola.success(`Created ${cyan(".gitignore")}`);
|
|
791
|
+
}
|
|
708
792
|
|
|
709
793
|
async function initializeProject({
|
|
710
794
|
argTargetDir,
|
|
@@ -789,24 +873,25 @@ async function initializeProject({
|
|
|
789
873
|
JSON.stringify(packageJson, null, 2) + "\n"
|
|
790
874
|
);
|
|
791
875
|
await formatFile(packageJsonPath);
|
|
792
|
-
consola$1.success("Created
|
|
876
|
+
consola$1.success("Created", cyan("package.json"));
|
|
793
877
|
if (isTs) {
|
|
794
878
|
const tsConfigPath = path.join(root, "tsconfig.json");
|
|
795
879
|
const tsConfig = generateTsConfig();
|
|
796
880
|
fs.writeFileSync(tsConfigPath, JSON.stringify(tsConfig, null, 2) + "\n");
|
|
797
881
|
await formatFile(tsConfigPath);
|
|
798
|
-
consola$1.success("Created
|
|
882
|
+
consola$1.success("Created", cyan("tsconfig.json"));
|
|
799
883
|
}
|
|
800
884
|
const apibaraConfigPath = path.join(root, `apibara.config.${configExt}`);
|
|
801
885
|
const apibaraConfig = generateApibaraConfig(isTs);
|
|
802
886
|
fs.writeFileSync(apibaraConfigPath, apibaraConfig);
|
|
803
887
|
await formatFile(apibaraConfigPath);
|
|
804
|
-
consola$1.success("Created
|
|
888
|
+
consola$1.success("Created", cyan(`apibara.config.${configExt}`));
|
|
805
889
|
const indexersDir = path.join(root, "indexers");
|
|
806
890
|
if (!fs.existsSync(indexersDir)) {
|
|
807
891
|
fs.mkdirSync(indexersDir, { recursive: true });
|
|
808
892
|
consola$1.success(`Created ${cyan("indexers")} directory`);
|
|
809
893
|
}
|
|
894
|
+
await createGitIgnoreFile(root);
|
|
810
895
|
console.log("\n");
|
|
811
896
|
consola$1.ready(green("Project initialized successfully"));
|
|
812
897
|
console.log();
|
package/dist/rollup/index.mjs
CHANGED
|
@@ -74,7 +74,7 @@ function indexers(apibara) {
|
|
|
74
74
|
const indexers2 = [...new Set(apibara.indexers)];
|
|
75
75
|
return virtual({
|
|
76
76
|
"#apibara-internal-virtual/indexers": `
|
|
77
|
-
${indexers2.map((i) => `import _${hash(i)} from '${i.indexer}';`).join("\n")}
|
|
77
|
+
${indexers2.map((i) => `import * as _${hash(i)} from '${i.indexer}';`).join("\n")}
|
|
78
78
|
|
|
79
79
|
export const indexers = [
|
|
80
80
|
${indexers2.map((i) => `{ name: "${i.name}", indexer: _${hash(i)} }`).join(",\n")}
|
|
@@ -138,8 +138,9 @@ function getRollupConfig(apibara) {
|
|
|
138
138
|
rollupConfig.plugins.push(
|
|
139
139
|
nodeResolve({
|
|
140
140
|
extensions,
|
|
141
|
-
preferBuiltins:
|
|
142
|
-
mainFields: ["main"]
|
|
141
|
+
preferBuiltins: !!apibara.options.node,
|
|
142
|
+
mainFields: ["main"],
|
|
143
|
+
exportConditions: apibara.options.exportConditions
|
|
143
144
|
})
|
|
144
145
|
);
|
|
145
146
|
rollupConfig.plugins.push(indexers(apibara));
|
package/dist/runtime/dev.mjs
CHANGED
|
@@ -33,6 +33,9 @@ const startCommand = defineCommand({
|
|
|
33
33
|
await Promise.all(
|
|
34
34
|
selectedIndexers.map(async (indexer) => {
|
|
35
35
|
const indexerInstance = createIndexer(indexer, preset);
|
|
36
|
+
if (!indexerInstance) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
36
39
|
const client = createClient(
|
|
37
40
|
indexerInstance.streamConfig,
|
|
38
41
|
indexerInstance.options.streamUrl
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const availableIndexers: any;
|
|
2
|
-
export declare function createIndexer(indexerName: string, preset?: string): import("@apibara/indexer").Indexer<unknown, unknown
|
|
2
|
+
export declare function createIndexer(indexerName: string, preset?: string): import("@apibara/indexer").Indexer<unknown, unknown> | undefined;
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
inMemoryPersistence,
|
|
7
7
|
logger
|
|
8
8
|
} from "@apibara/indexer/plugins";
|
|
9
|
+
import consola from "consola";
|
|
9
10
|
import { config } from "#apibara-internal-virtual/config";
|
|
10
11
|
import { indexers } from "#apibara-internal-virtual/indexers";
|
|
11
12
|
import { createLogger } from "./logger.mjs";
|
|
@@ -30,7 +31,14 @@ export function createIndexer(indexerName, preset) {
|
|
|
30
31
|
`Specified indexer "${indexerName}" but it was not defined`
|
|
31
32
|
);
|
|
32
33
|
}
|
|
33
|
-
const
|
|
34
|
+
const indexerModule = indexerDefinition.indexer?.default;
|
|
35
|
+
if (indexerModule === void 0) {
|
|
36
|
+
consola.warn(
|
|
37
|
+
`Specified indexer "${indexerName}" but it does not export a default. Ignoring.`
|
|
38
|
+
);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const definition = typeof indexerModule === "function" ? indexerModule(runtimeConfig) : indexerModule;
|
|
34
42
|
let reporter = createLogger({
|
|
35
43
|
indexer: indexerName,
|
|
36
44
|
preset,
|
package/dist/runtime/start.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { runWithReconnect } from "@apibara/indexer";
|
|
2
2
|
import { createClient } from "@apibara/protocol";
|
|
3
3
|
import { defineCommand, runMain } from "citty";
|
|
4
|
+
import consola from "consola";
|
|
4
5
|
import { createIndexer } from "./internal/app.mjs";
|
|
5
6
|
const startCommand = defineCommand({
|
|
6
7
|
meta: {
|
|
@@ -21,6 +22,10 @@ const startCommand = defineCommand({
|
|
|
21
22
|
async run({ args }) {
|
|
22
23
|
const { indexer, preset } = args;
|
|
23
24
|
const indexerInstance = createIndexer(indexer, preset);
|
|
25
|
+
if (!indexerInstance) {
|
|
26
|
+
consola.error(`Specified indexer "${indexer}" but it was not defined`);
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
24
29
|
const client = createClient(
|
|
25
30
|
indexerInstance.streamConfig,
|
|
26
31
|
indexerInstance.options.streamUrl
|
package/dist/types/index.d.mts
CHANGED
|
@@ -65,6 +65,8 @@ interface ApibaraOptions<T extends Record<string, DeepPartial<Pick<ApibaraConfig
|
|
|
65
65
|
sourceMap?: boolean;
|
|
66
66
|
entry: string;
|
|
67
67
|
commonJS?: RollupCommonJSOptions;
|
|
68
|
+
node: boolean;
|
|
69
|
+
exportConditions?: string[];
|
|
68
70
|
typescript: {
|
|
69
71
|
strict?: boolean;
|
|
70
72
|
internalPaths?: boolean;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -65,6 +65,8 @@ interface ApibaraOptions<T extends Record<string, DeepPartial<Pick<ApibaraConfig
|
|
|
65
65
|
sourceMap?: boolean;
|
|
66
66
|
entry: string;
|
|
67
67
|
commonJS?: RollupCommonJSOptions;
|
|
68
|
+
node: boolean;
|
|
69
|
+
exportConditions?: string[];
|
|
68
70
|
typescript: {
|
|
69
71
|
strict?: boolean;
|
|
70
72
|
internalPaths?: boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "apibara",
|
|
3
|
-
"version": "2.1.0-beta.
|
|
3
|
+
"version": "2.1.0-beta.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/core/index.mjs",
|
|
6
6
|
"exports": {
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
"playground:start": "pnpm playground start --dir playground --indexer starknet"
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
|
-
"@apibara/starknet": "2.1.0-beta.
|
|
79
|
+
"@apibara/starknet": "2.1.0-beta.6",
|
|
80
80
|
"@types/fs-extra": "^11.0.4",
|
|
81
81
|
"@types/node": "^20.14.0",
|
|
82
82
|
"@types/prompts": "^2.4.9",
|
|
@@ -87,8 +87,8 @@
|
|
|
87
87
|
"vitest": "^1.6.0"
|
|
88
88
|
},
|
|
89
89
|
"dependencies": {
|
|
90
|
-
"@apibara/indexer": "2.1.0-beta.
|
|
91
|
-
"@apibara/protocol": "2.1.0-beta.
|
|
90
|
+
"@apibara/indexer": "2.1.0-beta.6",
|
|
91
|
+
"@apibara/protocol": "2.1.0-beta.6",
|
|
92
92
|
"@rollup/plugin-commonjs": "^26.0.1",
|
|
93
93
|
"@rollup/plugin-json": "^6.1.0",
|
|
94
94
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
@@ -99,7 +99,6 @@
|
|
|
99
99
|
"citty": "^0.1.6",
|
|
100
100
|
"consola": "^3.2.3",
|
|
101
101
|
"defu": "^6.1.4",
|
|
102
|
-
"esbuild": "^0.23.0",
|
|
103
102
|
"fs-extra": "^11.2.0",
|
|
104
103
|
"hookable": "^5.5.3",
|
|
105
104
|
"klona": "^2.0.6",
|
|
@@ -111,8 +110,7 @@
|
|
|
111
110
|
"pkg-types": "^1.1.3",
|
|
112
111
|
"prettier": "^3.5.2",
|
|
113
112
|
"prompts": "^2.4.2",
|
|
114
|
-
"rollup": "^4.
|
|
115
|
-
"rollup-plugin-esbuild": "^6.1.1",
|
|
113
|
+
"rollup": "^4.34.8",
|
|
116
114
|
"ts-morph": "^25.0.1",
|
|
117
115
|
"tslib": "^2.6.3",
|
|
118
116
|
"untyped": "^1.4.2"
|
package/src/core/build/error.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import type esbuild from "esbuild";
|
|
2
1
|
import { isAbsolute, relative } from "pathe";
|
|
3
2
|
import type rollup from "rollup";
|
|
4
3
|
|
|
5
|
-
export function formatRollupError(
|
|
6
|
-
_error: rollup.RollupError | esbuild.OnResolveResult,
|
|
7
|
-
) {
|
|
4
|
+
export function formatRollupError(_error: rollup.RollupError) {
|
|
8
5
|
try {
|
|
9
6
|
const logs: string[] = [_error.toString()];
|
|
10
7
|
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
@@ -12,15 +9,11 @@ export function formatRollupError(
|
|
|
12
9
|
for (const error of errors) {
|
|
13
10
|
const id = error.path || error.id || (_error as rollup.RollupError).id;
|
|
14
11
|
let path = isAbsolute(id) ? relative(process.cwd(), id) : id;
|
|
15
|
-
const location =
|
|
16
|
-
(error as rollup.RollupError).loc ||
|
|
17
|
-
(error as esbuild.PartialMessage).location;
|
|
12
|
+
const location = (error as rollup.RollupError).loc;
|
|
18
13
|
if (location) {
|
|
19
14
|
path += `:${location.line}:${location.column}`;
|
|
20
15
|
}
|
|
21
|
-
const text =
|
|
22
|
-
(error as esbuild.PartialMessage).text ||
|
|
23
|
-
(error as rollup.RollupError).frame;
|
|
16
|
+
const text = (error as rollup.RollupError).frame;
|
|
24
17
|
|
|
25
18
|
logs.push(
|
|
26
19
|
`Rollup error while processing \`${path}\`` + text ? "\n\n" + text : "",
|
package/src/create/init.ts
CHANGED
|
@@ -5,6 +5,7 @@ import prompts from "prompts";
|
|
|
5
5
|
import { addIndexer } from "./add";
|
|
6
6
|
import { cyan, green } from "./colors";
|
|
7
7
|
import {
|
|
8
|
+
createGitIgnoreFile,
|
|
8
9
|
generateApibaraConfig,
|
|
9
10
|
generatePackageJson,
|
|
10
11
|
generateTsConfig,
|
|
@@ -129,7 +130,7 @@ export async function initializeProject({
|
|
|
129
130
|
JSON.stringify(packageJson, null, 2) + "\n",
|
|
130
131
|
);
|
|
131
132
|
await formatFile(packageJsonPath);
|
|
132
|
-
consola.success("Created
|
|
133
|
+
consola.success("Created", cyan("package.json"));
|
|
133
134
|
|
|
134
135
|
// Generate tsconfig.json if TypeScript
|
|
135
136
|
if (isTs) {
|
|
@@ -137,7 +138,7 @@ export async function initializeProject({
|
|
|
137
138
|
const tsConfig = generateTsConfig();
|
|
138
139
|
fs.writeFileSync(tsConfigPath, JSON.stringify(tsConfig, null, 2) + "\n");
|
|
139
140
|
await formatFile(tsConfigPath);
|
|
140
|
-
consola.success("Created
|
|
141
|
+
consola.success("Created", cyan("tsconfig.json"));
|
|
141
142
|
}
|
|
142
143
|
|
|
143
144
|
const apibaraConfigPath = path.join(root, `apibara.config.${configExt}`);
|
|
@@ -145,7 +146,7 @@ export async function initializeProject({
|
|
|
145
146
|
const apibaraConfig = generateApibaraConfig(isTs);
|
|
146
147
|
fs.writeFileSync(apibaraConfigPath, apibaraConfig);
|
|
147
148
|
await formatFile(apibaraConfigPath);
|
|
148
|
-
consola.success("Created
|
|
149
|
+
consola.success("Created", cyan(`apibara.config.${configExt}`));
|
|
149
150
|
|
|
150
151
|
// Create "indexers" directory if not exists
|
|
151
152
|
const indexersDir = path.join(root, "indexers");
|
|
@@ -154,6 +155,8 @@ export async function initializeProject({
|
|
|
154
155
|
consola.success(`Created ${cyan("indexers")} directory`);
|
|
155
156
|
}
|
|
156
157
|
|
|
158
|
+
await createGitIgnoreFile(root);
|
|
159
|
+
|
|
157
160
|
console.log("\n");
|
|
158
161
|
|
|
159
162
|
consola.ready(green("Project initialized successfully"));
|
package/src/create/templates.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { consola } from "consola";
|
|
4
|
+
import prompts from "prompts";
|
|
4
5
|
import { type ObjectLiteralExpression, Project, SyntaxKind } from "ts-morph";
|
|
5
6
|
import { cyan, green, magenta, yellow } from "./colors";
|
|
6
7
|
import { packageVersions } from "./constants";
|
|
@@ -466,3 +467,103 @@ export async function createStorageRelatedFiles(options: IndexerOptions) {
|
|
|
466
467
|
await createDrizzleStorageFiles(options);
|
|
467
468
|
}
|
|
468
469
|
}
|
|
470
|
+
|
|
471
|
+
const gitIgnoreItems: {
|
|
472
|
+
isRecommended: boolean;
|
|
473
|
+
description?: string;
|
|
474
|
+
value: string;
|
|
475
|
+
}[] = [
|
|
476
|
+
{
|
|
477
|
+
isRecommended: false,
|
|
478
|
+
value: "node_modules",
|
|
479
|
+
},
|
|
480
|
+
{
|
|
481
|
+
isRecommended: false,
|
|
482
|
+
value: "dist",
|
|
483
|
+
},
|
|
484
|
+
{
|
|
485
|
+
isRecommended: true,
|
|
486
|
+
description: "build and dev files of apibara",
|
|
487
|
+
value: ".apibara",
|
|
488
|
+
},
|
|
489
|
+
{
|
|
490
|
+
isRecommended: false,
|
|
491
|
+
value: ".env",
|
|
492
|
+
},
|
|
493
|
+
{
|
|
494
|
+
isRecommended: false,
|
|
495
|
+
description: "for mac users",
|
|
496
|
+
value: ".DS_Store",
|
|
497
|
+
},
|
|
498
|
+
];
|
|
499
|
+
|
|
500
|
+
export async function createGitIgnoreFile(cwd: string) {
|
|
501
|
+
const gitIgnorePath = path.join(cwd, ".gitignore");
|
|
502
|
+
|
|
503
|
+
if (fs.existsSync(gitIgnorePath)) {
|
|
504
|
+
const result = await prompts([
|
|
505
|
+
{
|
|
506
|
+
type: "select",
|
|
507
|
+
name: "overwrite",
|
|
508
|
+
message: `${cyan(".gitignore")} already exists. Please choose how to proceed:`,
|
|
509
|
+
initial: 0,
|
|
510
|
+
choices: [
|
|
511
|
+
{
|
|
512
|
+
title: "Choose items to append in your .gitignore",
|
|
513
|
+
value: "append",
|
|
514
|
+
},
|
|
515
|
+
{
|
|
516
|
+
title: "Keep original",
|
|
517
|
+
value: "ignore",
|
|
518
|
+
},
|
|
519
|
+
{
|
|
520
|
+
title: "Overwrite",
|
|
521
|
+
value: "overwrite",
|
|
522
|
+
},
|
|
523
|
+
],
|
|
524
|
+
},
|
|
525
|
+
{
|
|
526
|
+
type: (overwrite: "append" | "ignore" | "overwrite") =>
|
|
527
|
+
overwrite === "append" ? "multiselect" : null,
|
|
528
|
+
name: "ignoreItems",
|
|
529
|
+
message: "Choose items to append in your .gitignore",
|
|
530
|
+
choices: gitIgnoreItems.map((item) => ({
|
|
531
|
+
title: `${yellow(item.value)}${
|
|
532
|
+
item.description ? ` - ${item.description}` : ""
|
|
533
|
+
}${item.isRecommended ? ` ${green("(recommended)")}` : ""}`,
|
|
534
|
+
value: item.value,
|
|
535
|
+
})),
|
|
536
|
+
},
|
|
537
|
+
]);
|
|
538
|
+
|
|
539
|
+
const { overwrite, ignoreItems } = result as {
|
|
540
|
+
overwrite: "append" | "ignore" | "overwrite";
|
|
541
|
+
ignoreItems: string[];
|
|
542
|
+
};
|
|
543
|
+
|
|
544
|
+
if (overwrite === "append" && ignoreItems.length > 0) {
|
|
545
|
+
const gitIgnoreContent = fs.readFileSync(gitIgnorePath, "utf8");
|
|
546
|
+
fs.writeFileSync(
|
|
547
|
+
gitIgnorePath,
|
|
548
|
+
`${gitIgnoreContent}\n${result.ignoreItems.join("\n")}`,
|
|
549
|
+
);
|
|
550
|
+
consola.success(`Updated ${cyan(".gitignore")}`);
|
|
551
|
+
return;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
if (overwrite === "overwrite") {
|
|
555
|
+
fs.writeFileSync(
|
|
556
|
+
gitIgnorePath,
|
|
557
|
+
gitIgnoreItems.map((item) => item.value).join("\n"),
|
|
558
|
+
);
|
|
559
|
+
consola.success(`Updated ${cyan(".gitignore")}`);
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
fs.writeFileSync(
|
|
565
|
+
gitIgnorePath,
|
|
566
|
+
gitIgnoreItems.map((item) => item.value).join("\n"),
|
|
567
|
+
);
|
|
568
|
+
consola.success(`Created ${cyan(".gitignore")}`);
|
|
569
|
+
}
|
package/src/rollup/config.ts
CHANGED
|
@@ -76,10 +76,12 @@ export function getRollupConfig(apibara: Apibara): RollupConfig {
|
|
|
76
76
|
rollupConfig.plugins.push(
|
|
77
77
|
nodeResolve({
|
|
78
78
|
extensions,
|
|
79
|
-
preferBuiltins:
|
|
79
|
+
preferBuiltins: !!apibara.options.node,
|
|
80
80
|
mainFields: ["main"],
|
|
81
|
+
exportConditions: apibara.options.exportConditions,
|
|
81
82
|
}),
|
|
82
83
|
);
|
|
84
|
+
|
|
83
85
|
rollupConfig.plugins.push(indexers(apibara));
|
|
84
86
|
rollupConfig.plugins.push(appConfig(apibara));
|
|
85
87
|
|
|
@@ -7,7 +7,7 @@ export function indexers(apibara: Apibara) {
|
|
|
7
7
|
|
|
8
8
|
return virtual({
|
|
9
9
|
"#apibara-internal-virtual/indexers": `
|
|
10
|
-
${indexers.map((i) => `import _${hash(i)} from '${i.indexer}';`).join("\n")}
|
|
10
|
+
${indexers.map((i) => `import * as _${hash(i)} from '${i.indexer}';`).join("\n")}
|
|
11
11
|
|
|
12
12
|
export const indexers = [
|
|
13
13
|
${indexers.map((i) => `{ name: "${i.name}", indexer: _${hash(i)} }`).join(",\n")}
|
package/src/runtime/dev.ts
CHANGED
|
@@ -37,6 +37,9 @@ const startCommand = defineCommand({
|
|
|
37
37
|
await Promise.all(
|
|
38
38
|
selectedIndexers.map(async (indexer) => {
|
|
39
39
|
const indexerInstance = createIndexer(indexer, preset);
|
|
40
|
+
if (!indexerInstance) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
40
43
|
|
|
41
44
|
const client = createClient(
|
|
42
45
|
indexerInstance.streamConfig,
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
inMemoryPersistence,
|
|
9
9
|
logger,
|
|
10
10
|
} from "@apibara/indexer/plugins";
|
|
11
|
+
import consola from "consola";
|
|
11
12
|
import { config } from "#apibara-internal-virtual/config";
|
|
12
13
|
import { indexers } from "#apibara-internal-virtual/indexers";
|
|
13
14
|
import { createLogger } from "./logger";
|
|
@@ -42,10 +43,18 @@ export function createIndexer(indexerName: string, preset?: string) {
|
|
|
42
43
|
);
|
|
43
44
|
}
|
|
44
45
|
|
|
46
|
+
const indexerModule = indexerDefinition.indexer?.default;
|
|
47
|
+
if (indexerModule === undefined) {
|
|
48
|
+
consola.warn(
|
|
49
|
+
`Specified indexer "${indexerName}" but it does not export a default. Ignoring.`,
|
|
50
|
+
);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
45
54
|
const definition =
|
|
46
|
-
typeof
|
|
47
|
-
?
|
|
48
|
-
:
|
|
55
|
+
typeof indexerModule === "function"
|
|
56
|
+
? indexerModule(runtimeConfig)
|
|
57
|
+
: indexerModule;
|
|
49
58
|
|
|
50
59
|
let reporter: ConsolaReporter = createLogger({
|
|
51
60
|
indexer: indexerName,
|
package/src/runtime/start.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { runWithReconnect } from "@apibara/indexer";
|
|
2
2
|
import { createClient } from "@apibara/protocol";
|
|
3
3
|
import { defineCommand, runMain } from "citty";
|
|
4
|
+
import consola from "consola";
|
|
4
5
|
import { createIndexer } from "./internal/app";
|
|
5
6
|
|
|
6
7
|
const startCommand = defineCommand({
|
|
@@ -23,6 +24,10 @@ const startCommand = defineCommand({
|
|
|
23
24
|
const { indexer, preset } = args;
|
|
24
25
|
|
|
25
26
|
const indexerInstance = createIndexer(indexer, preset);
|
|
27
|
+
if (!indexerInstance) {
|
|
28
|
+
consola.error(`Specified indexer "${indexer}" but it was not defined`);
|
|
29
|
+
process.exit(1);
|
|
30
|
+
}
|
|
26
31
|
|
|
27
32
|
const client = createClient(
|
|
28
33
|
indexerInstance.streamConfig,
|
package/src/types/config.ts
CHANGED
|
@@ -7,4 +7,7 @@ export type IndexerConstructor =
|
|
|
7
7
|
) => IndexerWithStreamConfig<unknown, unknown, unknown>)
|
|
8
8
|
| IndexerWithStreamConfig<unknown, unknown, unknown>;
|
|
9
9
|
|
|
10
|
-
export const indexers: {
|
|
10
|
+
export const indexers: {
|
|
11
|
+
name: string;
|
|
12
|
+
indexer: { default?: IndexerConstructor | undefined };
|
|
13
|
+
}[] = [];
|