apibara 2.1.0-beta.20 → 2.1.0-beta.22
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 +4 -1
- package/dist/chunks/build.mjs +4 -2
- package/dist/chunks/dev.mjs +16 -6
- package/dist/chunks/init.mjs +11 -7
- package/dist/chunks/prepare.mjs +4 -2
- package/dist/chunks/start.mjs +4 -3
- package/dist/create/index.mjs +6 -20
- package/dist/runtime/dev.mjs +5 -1
- package/dist/runtime/internal/app.d.ts +4 -1
- package/dist/runtime/internal/app.mjs +4 -1
- package/dist/runtime/start.mjs +5 -1
- package/dist/shared/apibara.63c9a277.mjs +29 -0
- package/dist/shared/apibara.730bb1e4.mjs +17 -0
- package/package.json +4 -4
- package/src/cli/commands/add.ts +4 -1
- package/src/cli/commands/build.ts +5 -2
- package/src/cli/commands/dev.ts +24 -6
- package/src/cli/commands/init.ts +12 -7
- package/src/cli/commands/prepare.ts +4 -2
- package/src/cli/commands/start.ts +4 -3
- package/src/cli/common.ts +33 -1
- package/src/create/constants.ts +1 -1
- package/src/create/templates.ts +3 -8
- package/src/runtime/dev.ts +7 -1
- package/src/runtime/internal/app.ts +4 -1
- package/src/runtime/start.ts +7 -1
- package/dist/shared/apibara.1b515d04.mjs +0 -8
package/dist/chunks/add.mjs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { addIndexer } from 'apibara/create';
|
|
2
2
|
import { defineCommand } from 'citty';
|
|
3
|
+
import { a as checkForUnknownArgs } from '../shared/apibara.63c9a277.mjs';
|
|
4
|
+
import 'consola';
|
|
3
5
|
|
|
4
6
|
const add = defineCommand({
|
|
5
7
|
meta: {
|
|
@@ -33,7 +35,8 @@ const add = defineCommand({
|
|
|
33
35
|
description: "Root directory - apibara project root where apibara.config is located | default: current working directory"
|
|
34
36
|
}
|
|
35
37
|
},
|
|
36
|
-
async run({ args }) {
|
|
38
|
+
async run({ args, cmd }) {
|
|
39
|
+
await checkForUnknownArgs(args, cmd);
|
|
37
40
|
const { indexerId, chain, network, storage, dnaUrl, dir } = args;
|
|
38
41
|
await addIndexer({
|
|
39
42
|
argIndexerId: indexerId,
|
package/dist/chunks/build.mjs
CHANGED
|
@@ -2,7 +2,8 @@ import { createApibara, prepare, writeTypes, build as build$1 } from 'apibara/co
|
|
|
2
2
|
import { runtimeDir } from 'apibara/runtime/meta';
|
|
3
3
|
import { defineCommand } from 'citty';
|
|
4
4
|
import { resolve, join } from 'pathe';
|
|
5
|
-
import { c as commonArgs } from '../shared/apibara.
|
|
5
|
+
import { c as commonArgs, a as checkForUnknownArgs } from '../shared/apibara.63c9a277.mjs';
|
|
6
|
+
import 'consola';
|
|
6
7
|
|
|
7
8
|
const build = defineCommand({
|
|
8
9
|
meta: {
|
|
@@ -12,7 +13,8 @@ const build = defineCommand({
|
|
|
12
13
|
args: {
|
|
13
14
|
...commonArgs
|
|
14
15
|
},
|
|
15
|
-
async run({ args }) {
|
|
16
|
+
async run({ args, cmd }) {
|
|
17
|
+
await checkForUnknownArgs(args, cmd);
|
|
16
18
|
const rootDir = resolve(args.dir || args._dir || ".");
|
|
17
19
|
const apibara = await createApibara({
|
|
18
20
|
rootDir
|
package/dist/chunks/dev.mjs
CHANGED
|
@@ -4,7 +4,10 @@ import { runtimeDir } from 'apibara/runtime/meta';
|
|
|
4
4
|
import { defineCommand } from 'citty';
|
|
5
5
|
import { colors } from 'consola/utils';
|
|
6
6
|
import { resolve, join } from 'pathe';
|
|
7
|
-
import {
|
|
7
|
+
import { b as blueBright, g as gray } from '../shared/apibara.730bb1e4.mjs';
|
|
8
|
+
import { c as commonArgs, a as checkForUnknownArgs } from '../shared/apibara.63c9a277.mjs';
|
|
9
|
+
import 'picocolors';
|
|
10
|
+
import 'consola';
|
|
8
11
|
|
|
9
12
|
const hmrKeyRe = /^runtimeConfig\./;
|
|
10
13
|
const dev = defineCommand({
|
|
@@ -22,17 +25,21 @@ const dev = defineCommand({
|
|
|
22
25
|
type: "string",
|
|
23
26
|
description: "Preset to use"
|
|
24
27
|
},
|
|
25
|
-
|
|
28
|
+
"always-reindex": {
|
|
26
29
|
type: "boolean",
|
|
27
30
|
default: false,
|
|
28
|
-
description: "Reindex the indexers from the starting block on every restart
|
|
31
|
+
description: "Reindex the indexers from the starting block on every restart | default: `false`"
|
|
29
32
|
}
|
|
30
33
|
},
|
|
31
|
-
async run({ args }) {
|
|
34
|
+
async run({ args, data, cmd, rawArgs }) {
|
|
35
|
+
await checkForUnknownArgs(args, cmd);
|
|
32
36
|
const rootDir = resolve(args.dir || args._dir || ".");
|
|
33
|
-
if (args
|
|
37
|
+
if (args["always-reindex"]) {
|
|
34
38
|
process.env.APIBARA_ALWAYS_REINDEX = "true";
|
|
35
39
|
}
|
|
40
|
+
const selectedIndexers = new Set(
|
|
41
|
+
args.indexers?.split(",").map((i) => i.trim()).sort() ?? []
|
|
42
|
+
);
|
|
36
43
|
let apibara;
|
|
37
44
|
let childProcess;
|
|
38
45
|
const reload = async () => {
|
|
@@ -85,6 +92,10 @@ const dev = defineCommand({
|
|
|
85
92
|
childProcess = void 0;
|
|
86
93
|
} else {
|
|
87
94
|
apibara.logger.info("Starting indexers");
|
|
95
|
+
const indexersText = apibara.indexers.map(
|
|
96
|
+
(i) => selectedIndexers.has(i.name) || selectedIndexers.size === 0 ? blueBright(i.name) : gray(i.name)
|
|
97
|
+
).join(", ");
|
|
98
|
+
apibara.logger.info("Indexers:", indexersText);
|
|
88
99
|
}
|
|
89
100
|
const childArgs = [
|
|
90
101
|
resolve(apibara.options.outputDir || "./.apibara/build", "dev.mjs"),
|
|
@@ -100,7 +111,6 @@ const dev = defineCommand({
|
|
|
100
111
|
apibara.logger.log(
|
|
101
112
|
`Indexers process exited${code !== null ? ` with code ${colors.red(code)}` : ""}`
|
|
102
113
|
);
|
|
103
|
-
process.exit(code ?? 0);
|
|
104
114
|
});
|
|
105
115
|
});
|
|
106
116
|
};
|
package/dist/chunks/init.mjs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { initializeProject } from 'apibara/create';
|
|
2
2
|
import { defineCommand } from 'citty';
|
|
3
|
+
import { a as checkForUnknownArgs } from '../shared/apibara.63c9a277.mjs';
|
|
4
|
+
import 'consola';
|
|
3
5
|
|
|
4
6
|
const init = defineCommand({
|
|
5
7
|
meta: {
|
|
@@ -14,22 +16,24 @@ const init = defineCommand({
|
|
|
14
16
|
},
|
|
15
17
|
language: {
|
|
16
18
|
type: "string",
|
|
17
|
-
description: "Language to use: typescript, ts or javascript, js",
|
|
19
|
+
description: "Language to use: typescript, ts or javascript, js | default: `ts`",
|
|
18
20
|
default: "ts",
|
|
19
21
|
alias: "l"
|
|
20
22
|
},
|
|
21
|
-
|
|
23
|
+
"create-indexer": {
|
|
22
24
|
type: "boolean",
|
|
23
|
-
|
|
24
|
-
default:
|
|
25
|
+
name: "create-indexer",
|
|
26
|
+
default: true,
|
|
27
|
+
description: "TODO"
|
|
25
28
|
}
|
|
26
29
|
},
|
|
27
|
-
async run({ args }) {
|
|
28
|
-
|
|
30
|
+
async run({ args, cmd }) {
|
|
31
|
+
await checkForUnknownArgs(args, cmd);
|
|
32
|
+
const { dir: targetDir, "create-indexer": createIndexer, language } = args;
|
|
29
33
|
await initializeProject({
|
|
30
34
|
argTargetDir: targetDir,
|
|
31
35
|
argLanguage: language,
|
|
32
|
-
argNoCreateIndexer:
|
|
36
|
+
argNoCreateIndexer: !createIndexer
|
|
33
37
|
});
|
|
34
38
|
}
|
|
35
39
|
});
|
package/dist/chunks/prepare.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { createApibara, writeTypes } from 'apibara/core';
|
|
2
2
|
import { defineCommand } from 'citty';
|
|
3
3
|
import { resolve } from 'pathe';
|
|
4
|
-
import { c as commonArgs } from '../shared/apibara.
|
|
4
|
+
import { c as commonArgs, a as checkForUnknownArgs } from '../shared/apibara.63c9a277.mjs';
|
|
5
|
+
import 'consola';
|
|
5
6
|
|
|
6
7
|
const prepare = defineCommand({
|
|
7
8
|
meta: {
|
|
@@ -11,7 +12,8 @@ const prepare = defineCommand({
|
|
|
11
12
|
args: {
|
|
12
13
|
...commonArgs
|
|
13
14
|
},
|
|
14
|
-
async run({ args }) {
|
|
15
|
+
async run({ args, cmd }) {
|
|
16
|
+
await checkForUnknownArgs(args, cmd);
|
|
15
17
|
const rootDir = resolve(args.dir || ".");
|
|
16
18
|
const apibara = await createApibara({ rootDir });
|
|
17
19
|
await writeTypes(apibara);
|
package/dist/chunks/start.mjs
CHANGED
|
@@ -4,7 +4,8 @@ import { defineCommand } from 'citty';
|
|
|
4
4
|
import { colors } from 'consola/utils';
|
|
5
5
|
import fse from 'fs-extra';
|
|
6
6
|
import { resolve } from 'pathe';
|
|
7
|
-
import { c as commonArgs } from '../shared/apibara.
|
|
7
|
+
import { c as commonArgs, a as checkForUnknownArgs } from '../shared/apibara.63c9a277.mjs';
|
|
8
|
+
import 'consola';
|
|
8
9
|
|
|
9
10
|
const start = defineCommand({
|
|
10
11
|
meta: {
|
|
@@ -23,9 +24,10 @@ const start = defineCommand({
|
|
|
23
24
|
description: "The preset to use"
|
|
24
25
|
}
|
|
25
26
|
},
|
|
26
|
-
async run({ args }) {
|
|
27
|
+
async run({ args, cmd }) {
|
|
27
28
|
const { indexer, preset } = args;
|
|
28
29
|
const rootDir = resolve(args.dir || args._dir || ".");
|
|
30
|
+
await checkForUnknownArgs(args, cmd);
|
|
29
31
|
const apibara = await createApibara({
|
|
30
32
|
rootDir,
|
|
31
33
|
preset
|
|
@@ -57,7 +59,6 @@ const start = defineCommand({
|
|
|
57
59
|
apibara.logger.log(
|
|
58
60
|
`Indexers process exited${code !== null ? ` with code ${colors.red(code)}` : ""}`
|
|
59
61
|
);
|
|
60
|
-
process.exit(code ?? 0);
|
|
61
62
|
});
|
|
62
63
|
}
|
|
63
64
|
});
|
package/dist/create/index.mjs
CHANGED
|
@@ -1,24 +1,11 @@
|
|
|
1
1
|
import path, { basename } from 'node:path';
|
|
2
2
|
import consola$1, { consola } from 'consola';
|
|
3
3
|
import prompts from 'prompts';
|
|
4
|
-
import
|
|
4
|
+
import { a as blue, y as yellow, c as green, r as red, d as cyan, m as magenta, e as reset } from '../shared/apibara.730bb1e4.mjs';
|
|
5
5
|
import fs from 'node:fs';
|
|
6
6
|
import { Project, SyntaxKind } from 'ts-morph';
|
|
7
7
|
import * as prettier from 'prettier';
|
|
8
|
-
|
|
9
|
-
const {
|
|
10
|
-
blue,
|
|
11
|
-
blueBright,
|
|
12
|
-
cyan,
|
|
13
|
-
gray,
|
|
14
|
-
green,
|
|
15
|
-
greenBright,
|
|
16
|
-
magenta,
|
|
17
|
-
red,
|
|
18
|
-
redBright,
|
|
19
|
-
reset,
|
|
20
|
-
yellow
|
|
21
|
-
} = colors;
|
|
8
|
+
import 'picocolors';
|
|
22
9
|
|
|
23
10
|
const chains = [
|
|
24
11
|
{
|
|
@@ -70,7 +57,7 @@ const packageVersions = {
|
|
|
70
57
|
"@apibara/plugin-sqlite": "next",
|
|
71
58
|
// Postgres Dependencies
|
|
72
59
|
"@electric-sql/pglite": "^0.2.17",
|
|
73
|
-
"drizzle-orm": "^0.
|
|
60
|
+
"drizzle-orm": "^0.40.1",
|
|
74
61
|
pg: "^8.13.1",
|
|
75
62
|
"@types/pg": "^8.11.10",
|
|
76
63
|
"drizzle-kit": "^0.29.0",
|
|
@@ -449,10 +436,9 @@ ${storage === "postgres" ? `import * as schema from "../lib/schema";` : ""}
|
|
|
449
436
|
|
|
450
437
|
export default function (runtimeConfig${language === "typescript" ? ": ApibaraRuntimeConfig" : ""}) {
|
|
451
438
|
const indexerId = "${indexerId}";
|
|
452
|
-
const { startingBlock, streamUrl
|
|
439
|
+
const { startingBlock, streamUrl } = runtimeConfig[indexerId];
|
|
453
440
|
${storage === "postgres" ? `const db = drizzle({
|
|
454
441
|
schema,
|
|
455
|
-
connectionString: postgresConnectionString,
|
|
456
442
|
});` : ""}
|
|
457
443
|
|
|
458
444
|
return defineIndexer(${chain === "ethereum" ? "EvmStream" : chain === "beaconchain" ? "BeaconChainStream" : chain === "starknet" ? "StarknetStream" : ""})({
|
|
@@ -546,8 +532,8 @@ async function updateApibaraConfigFile({
|
|
|
546
532
|
);
|
|
547
533
|
const runtimeConfigString = `{
|
|
548
534
|
startingBlock: 0,
|
|
549
|
-
streamUrl: "${dnaUrl ?? getDnaUrl(chain, network)}"
|
|
550
|
-
|
|
535
|
+
streamUrl: "${dnaUrl ?? getDnaUrl(chain, network)}"
|
|
536
|
+
}`;
|
|
551
537
|
const project = new Project();
|
|
552
538
|
const sourceFile = project.addSourceFileAtPath(pathToConfig);
|
|
553
539
|
const defineConfigCall = sourceFile.getFirstDescendantByKind(
|
package/dist/runtime/dev.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { runWithReconnect } from "@apibara/indexer";
|
|
2
2
|
import { defineCommand, runMain } from "citty";
|
|
3
|
+
import { blueBright } from "picocolors";
|
|
3
4
|
import {
|
|
4
5
|
availableIndexers,
|
|
5
6
|
createAuthenticatedClient,
|
|
@@ -35,7 +36,7 @@ const startCommand = defineCommand({
|
|
|
35
36
|
}
|
|
36
37
|
await Promise.all(
|
|
37
38
|
selectedIndexers.map(async (indexer) => {
|
|
38
|
-
const indexerInstance = createIndexer(indexer, preset);
|
|
39
|
+
const { indexer: indexerInstance, logger } = createIndexer(indexer, preset) ?? {};
|
|
39
40
|
if (!indexerInstance) {
|
|
40
41
|
return;
|
|
41
42
|
}
|
|
@@ -43,6 +44,9 @@ const startCommand = defineCommand({
|
|
|
43
44
|
indexerInstance.streamConfig,
|
|
44
45
|
indexerInstance.options.streamUrl
|
|
45
46
|
);
|
|
47
|
+
if (logger) {
|
|
48
|
+
logger.info(`Indexer ${blueBright(indexer)} started`);
|
|
49
|
+
}
|
|
46
50
|
await runWithReconnect(client, indexerInstance);
|
|
47
51
|
})
|
|
48
52
|
);
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { type CreateClientOptions, type StreamConfig } from "@apibara/protocol";
|
|
2
2
|
export declare const availableIndexers: any;
|
|
3
|
-
export declare function createIndexer(indexerName: string, preset?: string):
|
|
3
|
+
export declare function createIndexer(indexerName: string, preset?: string): {
|
|
4
|
+
indexer: import("@apibara/indexer").Indexer<unknown, unknown>;
|
|
5
|
+
logger: any;
|
|
6
|
+
} | undefined;
|
|
4
7
|
export declare function createAuthenticatedClient(config: StreamConfig<unknown, unknown>, streamUrl: string, options?: CreateClientOptions): import("@apibara/protocol").GrpcClient<unknown, unknown>;
|
|
@@ -62,7 +62,10 @@ export function createIndexer(indexerName, preset) {
|
|
|
62
62
|
inMemoryPersistence(),
|
|
63
63
|
...definition.plugins ?? []
|
|
64
64
|
];
|
|
65
|
-
return
|
|
65
|
+
return {
|
|
66
|
+
indexer: _createIndexer(definition),
|
|
67
|
+
logger: consola.create({ reporters: [reporter] })
|
|
68
|
+
};
|
|
66
69
|
}
|
|
67
70
|
export function createAuthenticatedClient(config2, streamUrl, options) {
|
|
68
71
|
const dnaToken = process.env.DNA_TOKEN;
|
package/dist/runtime/start.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { runWithReconnect } from "@apibara/indexer";
|
|
2
2
|
import { defineCommand, runMain } from "citty";
|
|
3
3
|
import consola from "consola";
|
|
4
|
+
import { blueBright } from "picocolors";
|
|
4
5
|
import { register } from "#apibara-internal-virtual/instrumentation";
|
|
5
6
|
import { createAuthenticatedClient, createIndexer } from "./internal/app.mjs";
|
|
6
7
|
const startCommand = defineCommand({
|
|
@@ -21,7 +22,7 @@ const startCommand = defineCommand({
|
|
|
21
22
|
},
|
|
22
23
|
async run({ args }) {
|
|
23
24
|
const { indexer, preset } = args;
|
|
24
|
-
const indexerInstance = createIndexer(indexer, preset);
|
|
25
|
+
const { indexer: indexerInstance, logger } = createIndexer(indexer, preset) ?? {};
|
|
25
26
|
if (!indexerInstance) {
|
|
26
27
|
consola.error(`Specified indexer "${indexer}" but it was not defined`);
|
|
27
28
|
process.exit(1);
|
|
@@ -35,6 +36,9 @@ const startCommand = defineCommand({
|
|
|
35
36
|
await register();
|
|
36
37
|
consola.success("Registered from instrumentation");
|
|
37
38
|
}
|
|
39
|
+
if (logger) {
|
|
40
|
+
logger.info(`Indexer ${blueBright(indexer)} started`);
|
|
41
|
+
}
|
|
38
42
|
await runWithReconnect(client, indexerInstance);
|
|
39
43
|
}
|
|
40
44
|
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { renderUsage } from 'citty';
|
|
2
|
+
import consola from 'consola';
|
|
3
|
+
|
|
4
|
+
const commonArgs = {
|
|
5
|
+
dir: {
|
|
6
|
+
type: "string",
|
|
7
|
+
description: "project root directory"
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
const checkForUnknownArgs = async (args, cmd) => {
|
|
11
|
+
const definedArgs = [];
|
|
12
|
+
if (cmd.args) {
|
|
13
|
+
for (const [argName, argDef] of Object.entries(cmd.args)) {
|
|
14
|
+
definedArgs.push(argName);
|
|
15
|
+
if (argDef.alias) {
|
|
16
|
+
definedArgs.push(argDef.alias);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const providedArgs = Object.keys(args).filter((arg) => arg !== "_");
|
|
21
|
+
const wrongArgs = providedArgs.filter((arg) => !definedArgs.includes(arg));
|
|
22
|
+
if (wrongArgs.length > 0) {
|
|
23
|
+
consola.error(`Unknown arguments: ${wrongArgs.join(", ")}`);
|
|
24
|
+
consola.info(await renderUsage(cmd));
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export { checkForUnknownArgs as a, commonArgs as c };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import colors from 'picocolors';
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
blue,
|
|
5
|
+
blueBright,
|
|
6
|
+
cyan,
|
|
7
|
+
gray,
|
|
8
|
+
green,
|
|
9
|
+
greenBright,
|
|
10
|
+
magenta,
|
|
11
|
+
red,
|
|
12
|
+
redBright,
|
|
13
|
+
reset,
|
|
14
|
+
yellow
|
|
15
|
+
} = colors;
|
|
16
|
+
|
|
17
|
+
export { blue as a, blueBright as b, green as c, cyan as d, reset as e, gray as g, magenta as m, red as r, yellow as y };
|
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.22",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/core/index.mjs",
|
|
6
6
|
"exports": {
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
"playground:add": "pnpm playground add --dir playground"
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
|
81
|
-
"@apibara/starknet": "2.1.0-beta.
|
|
81
|
+
"@apibara/starknet": "2.1.0-beta.22",
|
|
82
82
|
"@types/fs-extra": "^11.0.4",
|
|
83
83
|
"@types/node": "^20.14.0",
|
|
84
84
|
"@types/prompts": "^2.4.9",
|
|
@@ -89,8 +89,8 @@
|
|
|
89
89
|
"vitest": "^1.6.0"
|
|
90
90
|
},
|
|
91
91
|
"dependencies": {
|
|
92
|
-
"@apibara/indexer": "2.1.0-beta.
|
|
93
|
-
"@apibara/protocol": "2.1.0-beta.
|
|
92
|
+
"@apibara/indexer": "2.1.0-beta.22",
|
|
93
|
+
"@apibara/protocol": "2.1.0-beta.22",
|
|
94
94
|
"@rollup/plugin-replace": "^6.0.2",
|
|
95
95
|
"@rollup/plugin-virtual": "^3.0.2",
|
|
96
96
|
"c12": "^1.11.1",
|
package/src/cli/commands/add.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { addIndexer } from "apibara/create";
|
|
2
2
|
import { defineCommand } from "citty";
|
|
3
|
+
import { checkForUnknownArgs } from "../common";
|
|
3
4
|
|
|
4
5
|
export default defineCommand({
|
|
5
6
|
meta: {
|
|
@@ -35,7 +36,9 @@ export default defineCommand({
|
|
|
35
36
|
"Root directory - apibara project root where apibara.config is located | default: current working directory",
|
|
36
37
|
},
|
|
37
38
|
},
|
|
38
|
-
async run({ args }) {
|
|
39
|
+
async run({ args, cmd }) {
|
|
40
|
+
await checkForUnknownArgs(args, cmd);
|
|
41
|
+
|
|
39
42
|
const { indexerId, chain, network, storage, dnaUrl, dir } = args;
|
|
40
43
|
|
|
41
44
|
await addIndexer({
|
|
@@ -2,7 +2,7 @@ import { build, createApibara, prepare, writeTypes } from "apibara/core";
|
|
|
2
2
|
import { runtimeDir } from "apibara/runtime/meta";
|
|
3
3
|
import { defineCommand } from "citty";
|
|
4
4
|
import { join, resolve } from "pathe";
|
|
5
|
-
import { commonArgs } from "../common";
|
|
5
|
+
import { checkForUnknownArgs, commonArgs } from "../common";
|
|
6
6
|
|
|
7
7
|
export default defineCommand({
|
|
8
8
|
meta: {
|
|
@@ -12,8 +12,11 @@ export default defineCommand({
|
|
|
12
12
|
args: {
|
|
13
13
|
...commonArgs,
|
|
14
14
|
},
|
|
15
|
-
async run({ args }) {
|
|
15
|
+
async run({ args, cmd }) {
|
|
16
|
+
await checkForUnknownArgs(args, cmd);
|
|
17
|
+
|
|
16
18
|
const rootDir = resolve((args.dir || args._dir || ".") as string);
|
|
19
|
+
|
|
17
20
|
const apibara = await createApibara({
|
|
18
21
|
rootDir,
|
|
19
22
|
});
|
package/src/cli/commands/dev.ts
CHANGED
|
@@ -5,7 +5,8 @@ import type { Apibara } from "apibara/types";
|
|
|
5
5
|
import { defineCommand } from "citty";
|
|
6
6
|
import { colors } from "consola/utils";
|
|
7
7
|
import { join, resolve } from "pathe";
|
|
8
|
-
import {
|
|
8
|
+
import { blueBright, gray } from "../../create/colors";
|
|
9
|
+
import { checkForUnknownArgs, commonArgs } from "../common";
|
|
9
10
|
|
|
10
11
|
// Hot module reloading key regex
|
|
11
12
|
// for only runtimeConfig.* keys
|
|
@@ -26,20 +27,29 @@ export default defineCommand({
|
|
|
26
27
|
type: "string",
|
|
27
28
|
description: "Preset to use",
|
|
28
29
|
},
|
|
29
|
-
|
|
30
|
+
"always-reindex": {
|
|
30
31
|
type: "boolean",
|
|
31
32
|
default: false,
|
|
32
33
|
description:
|
|
33
|
-
"Reindex the indexers from the starting block on every restart
|
|
34
|
+
"Reindex the indexers from the starting block on every restart | default: `false`",
|
|
34
35
|
},
|
|
35
36
|
},
|
|
36
|
-
async run({ args }) {
|
|
37
|
+
async run({ args, data, cmd, rawArgs }) {
|
|
38
|
+
await checkForUnknownArgs(args, cmd);
|
|
39
|
+
|
|
37
40
|
const rootDir = resolve((args.dir || args._dir || ".") as string);
|
|
38
41
|
|
|
39
|
-
if (args
|
|
42
|
+
if (args["always-reindex"]) {
|
|
40
43
|
process.env.APIBARA_ALWAYS_REINDEX = "true";
|
|
41
44
|
}
|
|
42
45
|
|
|
46
|
+
const selectedIndexers = new Set(
|
|
47
|
+
args.indexers
|
|
48
|
+
?.split(",")
|
|
49
|
+
.map((i) => i.trim())
|
|
50
|
+
.sort() ?? [],
|
|
51
|
+
);
|
|
52
|
+
|
|
43
53
|
let apibara: Apibara;
|
|
44
54
|
let childProcess: ChildProcess | undefined;
|
|
45
55
|
|
|
@@ -105,6 +115,15 @@ export default defineCommand({
|
|
|
105
115
|
childProcess = undefined;
|
|
106
116
|
} else {
|
|
107
117
|
apibara.logger.info("Starting indexers");
|
|
118
|
+
|
|
119
|
+
const indexersText = apibara.indexers
|
|
120
|
+
.map((i) =>
|
|
121
|
+
selectedIndexers.has(i.name) || selectedIndexers.size === 0
|
|
122
|
+
? blueBright(i.name)
|
|
123
|
+
: gray(i.name),
|
|
124
|
+
)
|
|
125
|
+
.join(", ");
|
|
126
|
+
apibara.logger.info("Indexers:", indexersText);
|
|
108
127
|
}
|
|
109
128
|
|
|
110
129
|
const childArgs = [
|
|
@@ -125,7 +144,6 @@ export default defineCommand({
|
|
|
125
144
|
code !== null ? ` with code ${colors.red(code)}` : ""
|
|
126
145
|
}`,
|
|
127
146
|
);
|
|
128
|
-
process.exit(code ?? 0);
|
|
129
147
|
});
|
|
130
148
|
});
|
|
131
149
|
};
|
package/src/cli/commands/init.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { initializeProject } from "apibara/create";
|
|
2
2
|
import { defineCommand } from "citty";
|
|
3
|
+
import { checkForUnknownArgs } from "../common";
|
|
3
4
|
|
|
4
5
|
export default defineCommand({
|
|
5
6
|
meta: {
|
|
@@ -14,23 +15,27 @@ export default defineCommand({
|
|
|
14
15
|
},
|
|
15
16
|
language: {
|
|
16
17
|
type: "string",
|
|
17
|
-
description:
|
|
18
|
+
description:
|
|
19
|
+
"Language to use: typescript, ts or javascript, js | default: `ts`",
|
|
18
20
|
default: "ts",
|
|
19
21
|
alias: "l",
|
|
20
22
|
},
|
|
21
|
-
|
|
23
|
+
"create-indexer": {
|
|
22
24
|
type: "boolean",
|
|
23
|
-
|
|
24
|
-
default:
|
|
25
|
+
name: "create-indexer",
|
|
26
|
+
default: true,
|
|
27
|
+
description: "TODO",
|
|
25
28
|
},
|
|
26
29
|
},
|
|
27
|
-
async run({ args }) {
|
|
28
|
-
|
|
30
|
+
async run({ args, cmd }) {
|
|
31
|
+
await checkForUnknownArgs(args, cmd);
|
|
32
|
+
|
|
33
|
+
const { dir: targetDir, "create-indexer": createIndexer, language } = args;
|
|
29
34
|
|
|
30
35
|
await initializeProject({
|
|
31
36
|
argTargetDir: targetDir,
|
|
32
37
|
argLanguage: language,
|
|
33
|
-
argNoCreateIndexer:
|
|
38
|
+
argNoCreateIndexer: !createIndexer,
|
|
34
39
|
});
|
|
35
40
|
},
|
|
36
41
|
});
|
|
@@ -2,7 +2,7 @@ import { createApibara, writeTypes } from "apibara/core";
|
|
|
2
2
|
import {} from "apibara/types";
|
|
3
3
|
import { defineCommand } from "citty";
|
|
4
4
|
import { resolve } from "pathe";
|
|
5
|
-
import { commonArgs } from "../common";
|
|
5
|
+
import { checkForUnknownArgs, commonArgs } from "../common";
|
|
6
6
|
|
|
7
7
|
export default defineCommand({
|
|
8
8
|
meta: {
|
|
@@ -12,7 +12,9 @@ export default defineCommand({
|
|
|
12
12
|
args: {
|
|
13
13
|
...commonArgs,
|
|
14
14
|
},
|
|
15
|
-
async run({ args }) {
|
|
15
|
+
async run({ args, cmd }) {
|
|
16
|
+
await checkForUnknownArgs(args, cmd);
|
|
17
|
+
|
|
16
18
|
const rootDir = resolve((args.dir || ".") as string);
|
|
17
19
|
const apibara = await createApibara({ rootDir });
|
|
18
20
|
await writeTypes(apibara);
|
|
@@ -4,7 +4,7 @@ import { defineCommand } from "citty";
|
|
|
4
4
|
import { colors } from "consola/utils";
|
|
5
5
|
import fse from "fs-extra";
|
|
6
6
|
import { resolve } from "pathe";
|
|
7
|
-
import { commonArgs } from "../common";
|
|
7
|
+
import { checkForUnknownArgs, commonArgs } from "../common";
|
|
8
8
|
|
|
9
9
|
export default defineCommand({
|
|
10
10
|
meta: {
|
|
@@ -23,10 +23,12 @@ export default defineCommand({
|
|
|
23
23
|
description: "The preset to use",
|
|
24
24
|
},
|
|
25
25
|
},
|
|
26
|
-
async run({ args }) {
|
|
26
|
+
async run({ args, cmd }) {
|
|
27
27
|
const { indexer, preset } = args;
|
|
28
28
|
const rootDir = resolve((args.dir || args._dir || ".") as string);
|
|
29
29
|
|
|
30
|
+
await checkForUnknownArgs(args, cmd);
|
|
31
|
+
|
|
30
32
|
const apibara = await createApibara({
|
|
31
33
|
rootDir,
|
|
32
34
|
preset,
|
|
@@ -67,7 +69,6 @@ export default defineCommand({
|
|
|
67
69
|
code !== null ? ` with code ${colors.red(code)}` : ""
|
|
68
70
|
}`,
|
|
69
71
|
);
|
|
70
|
-
process.exit(code ?? 0);
|
|
71
72
|
});
|
|
72
73
|
},
|
|
73
74
|
});
|
package/src/cli/common.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
type ArgsDef,
|
|
3
|
+
type CommandDef,
|
|
4
|
+
type ParsedArgs,
|
|
5
|
+
renderUsage,
|
|
6
|
+
} from "citty";
|
|
7
|
+
import consola from "consola";
|
|
2
8
|
|
|
3
9
|
export const commonArgs = <ArgsDef>{
|
|
4
10
|
dir: {
|
|
@@ -6,3 +12,29 @@ export const commonArgs = <ArgsDef>{
|
|
|
6
12
|
description: "project root directory",
|
|
7
13
|
},
|
|
8
14
|
};
|
|
15
|
+
|
|
16
|
+
export const checkForUnknownArgs = async <T extends ArgsDef = ArgsDef>(
|
|
17
|
+
args: ParsedArgs<T>,
|
|
18
|
+
cmd: CommandDef<T>,
|
|
19
|
+
) => {
|
|
20
|
+
// Create a list of defined args including both the main arg names and their aliases
|
|
21
|
+
const definedArgs: string[] = [];
|
|
22
|
+
if (cmd.args) {
|
|
23
|
+
for (const [argName, argDef] of Object.entries(cmd.args)) {
|
|
24
|
+
definedArgs.push(argName);
|
|
25
|
+
// Add alias to definedArgs if it exists
|
|
26
|
+
if (argDef.alias) {
|
|
27
|
+
definedArgs.push(argDef.alias);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const providedArgs = Object.keys(args).filter((arg) => arg !== "_");
|
|
33
|
+
const wrongArgs = providedArgs.filter((arg) => !definedArgs.includes(arg));
|
|
34
|
+
|
|
35
|
+
if (wrongArgs.length > 0) {
|
|
36
|
+
consola.error(`Unknown arguments: ${wrongArgs.join(", ")}`);
|
|
37
|
+
consola.info(await renderUsage(cmd));
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
};
|
package/src/create/constants.ts
CHANGED
|
@@ -79,7 +79,7 @@ export const packageVersions = {
|
|
|
79
79
|
"@apibara/plugin-sqlite": "next",
|
|
80
80
|
// Postgres Dependencies
|
|
81
81
|
"@electric-sql/pglite": "^0.2.17",
|
|
82
|
-
"drizzle-orm": "^0.
|
|
82
|
+
"drizzle-orm": "^0.40.1",
|
|
83
83
|
pg: "^8.13.1",
|
|
84
84
|
"@types/pg": "^8.11.10",
|
|
85
85
|
"drizzle-kit": "^0.29.0",
|
package/src/create/templates.ts
CHANGED
|
@@ -89,12 +89,11 @@ ${storage === "postgres" ? `import * as schema from "../lib/schema";` : ""}
|
|
|
89
89
|
|
|
90
90
|
export default function (runtimeConfig${language === "typescript" ? ": ApibaraRuntimeConfig" : ""}) {
|
|
91
91
|
const indexerId = "${indexerId}";
|
|
92
|
-
const { startingBlock, streamUrl
|
|
92
|
+
const { startingBlock, streamUrl } = runtimeConfig[indexerId];
|
|
93
93
|
${
|
|
94
94
|
storage === "postgres"
|
|
95
95
|
? `const db = drizzle({
|
|
96
96
|
schema,
|
|
97
|
-
connectionString: postgresConnectionString,
|
|
98
97
|
});`
|
|
99
98
|
: ""
|
|
100
99
|
}
|
|
@@ -225,12 +224,8 @@ export async function updateApibaraConfigFile({
|
|
|
225
224
|
|
|
226
225
|
const runtimeConfigString = `{
|
|
227
226
|
startingBlock: 0,
|
|
228
|
-
streamUrl: "${dnaUrl ?? getDnaUrl(chain, network)}"
|
|
229
|
-
|
|
230
|
-
? `,
|
|
231
|
-
postgresConnectionString: process.env["POSTGRES_CONNECTION_STRING"] ?? "memory://${indexerId}"`
|
|
232
|
-
: ""
|
|
233
|
-
}}`;
|
|
227
|
+
streamUrl: "${dnaUrl ?? getDnaUrl(chain, network)}"
|
|
228
|
+
}`;
|
|
234
229
|
|
|
235
230
|
const project = new Project();
|
|
236
231
|
const sourceFile = project.addSourceFileAtPath(pathToConfig);
|
package/src/runtime/dev.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { runWithReconnect } from "@apibara/indexer";
|
|
2
2
|
import { defineCommand, runMain } from "citty";
|
|
3
|
+
import { blueBright } from "picocolors";
|
|
3
4
|
import {
|
|
4
5
|
availableIndexers,
|
|
5
6
|
createAuthenticatedClient,
|
|
@@ -39,7 +40,8 @@ const startCommand = defineCommand({
|
|
|
39
40
|
|
|
40
41
|
await Promise.all(
|
|
41
42
|
selectedIndexers.map(async (indexer) => {
|
|
42
|
-
const
|
|
43
|
+
const { indexer: indexerInstance, logger } =
|
|
44
|
+
createIndexer(indexer, preset) ?? {};
|
|
43
45
|
if (!indexerInstance) {
|
|
44
46
|
return;
|
|
45
47
|
}
|
|
@@ -49,6 +51,10 @@ const startCommand = defineCommand({
|
|
|
49
51
|
indexerInstance.options.streamUrl,
|
|
50
52
|
);
|
|
51
53
|
|
|
54
|
+
if (logger) {
|
|
55
|
+
logger.info(`Indexer ${blueBright(indexer)} started`);
|
|
56
|
+
}
|
|
57
|
+
|
|
52
58
|
await runWithReconnect(client, indexerInstance);
|
|
53
59
|
}),
|
|
54
60
|
);
|
|
@@ -88,7 +88,10 @@ export function createIndexer(indexerName: string, preset?: string) {
|
|
|
88
88
|
...(definition.plugins ?? []),
|
|
89
89
|
];
|
|
90
90
|
|
|
91
|
-
return
|
|
91
|
+
return {
|
|
92
|
+
indexer: _createIndexer(definition),
|
|
93
|
+
logger: consola.create({ reporters: [reporter] }),
|
|
94
|
+
};
|
|
92
95
|
}
|
|
93
96
|
|
|
94
97
|
export function createAuthenticatedClient(
|
package/src/runtime/start.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { runWithReconnect } from "@apibara/indexer";
|
|
2
2
|
import { defineCommand, runMain } from "citty";
|
|
3
3
|
import consola from "consola";
|
|
4
|
+
import { blueBright } from "picocolors";
|
|
4
5
|
import { register } from "#apibara-internal-virtual/instrumentation";
|
|
5
6
|
import { createAuthenticatedClient, createIndexer } from "./internal/app";
|
|
6
7
|
|
|
@@ -23,7 +24,8 @@ const startCommand = defineCommand({
|
|
|
23
24
|
async run({ args }) {
|
|
24
25
|
const { indexer, preset } = args;
|
|
25
26
|
|
|
26
|
-
const
|
|
27
|
+
const { indexer: indexerInstance, logger } =
|
|
28
|
+
createIndexer(indexer, preset) ?? {};
|
|
27
29
|
if (!indexerInstance) {
|
|
28
30
|
consola.error(`Specified indexer "${indexer}" but it was not defined`);
|
|
29
31
|
process.exit(1);
|
|
@@ -40,6 +42,10 @@ const startCommand = defineCommand({
|
|
|
40
42
|
consola.success("Registered from instrumentation");
|
|
41
43
|
}
|
|
42
44
|
|
|
45
|
+
if (logger) {
|
|
46
|
+
logger.info(`Indexer ${blueBright(indexer)} started`);
|
|
47
|
+
}
|
|
48
|
+
|
|
43
49
|
await runWithReconnect(client, indexerInstance);
|
|
44
50
|
},
|
|
45
51
|
});
|