apibara 2.1.0-beta.5 → 2.1.0-beta.50
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 +16 -8
- package/dist/chunks/add.mjs.map +1 -0
- package/dist/chunks/build.mjs +4 -2
- package/dist/chunks/build.mjs.map +1 -0
- package/dist/chunks/dev.mjs +55 -21
- package/dist/chunks/dev.mjs.map +1 -0
- package/dist/chunks/init.mjs +11 -7
- package/dist/chunks/init.mjs.map +1 -0
- package/dist/chunks/prepare.mjs +4 -2
- package/dist/chunks/prepare.mjs.map +1 -0
- package/dist/chunks/start.mjs +16 -4
- package/dist/chunks/start.mjs.map +1 -0
- package/dist/chunks/write-project-info.mjs +51 -0
- package/dist/chunks/write-project-info.mjs.map +1 -0
- package/dist/cli/index.mjs +3 -1
- package/dist/cli/index.mjs.map +1 -0
- package/dist/common/index.d.mts +33 -0
- package/dist/common/index.d.ts +33 -0
- package/dist/common/index.mjs +91 -0
- package/dist/common/index.mjs.map +1 -0
- package/dist/config/index.mjs +1 -0
- package/dist/config/index.mjs.map +1 -0
- package/dist/core/index.mjs +134 -69
- package/dist/core/index.mjs.map +1 -0
- package/dist/create/index.d.mts +2 -1
- package/dist/create/index.d.ts +2 -1
- package/dist/create/index.mjs +80 -136
- package/dist/create/index.mjs.map +1 -0
- package/dist/hooks/index.mjs +6 -1
- package/dist/hooks/index.mjs.map +1 -0
- package/dist/indexer/index.d.ts +1 -0
- package/dist/indexer/index.mjs +1 -0
- package/dist/indexer/plugins.d.ts +1 -0
- package/dist/indexer/plugins.mjs +1 -0
- package/dist/indexer/testing.d.ts +1 -0
- package/dist/indexer/testing.mjs +1 -0
- package/dist/indexer/vcr.d.ts +1 -0
- package/dist/indexer/vcr.mjs +1 -0
- package/dist/rolldown/index.d.mts +7 -0
- package/dist/rolldown/index.d.ts +7 -0
- package/dist/rolldown/index.mjs +141 -0
- package/dist/rolldown/index.mjs.map +1 -0
- package/dist/runtime/dev.mjs +39 -17
- package/dist/runtime/internal/app.d.ts +14 -1
- package/dist/runtime/internal/app.mjs +26 -21
- package/dist/runtime/project-info.d.ts +3 -0
- package/dist/runtime/project-info.mjs +67 -0
- package/dist/runtime/start.mjs +78 -11
- package/dist/shared/apibara.730bb1e4.mjs +18 -0
- package/dist/shared/apibara.730bb1e4.mjs.map +1 -0
- package/dist/types/index.d.mts +24 -20
- package/dist/types/index.d.ts +24 -20
- package/dist/types/index.mjs +1 -0
- package/dist/types/index.mjs.map +1 -0
- package/package.json +34 -17
- package/src/cli/commands/add.ts +16 -7
- package/src/cli/commands/build.ts +5 -2
- package/src/cli/commands/dev.ts +64 -20
- package/src/cli/commands/init.ts +12 -7
- package/src/cli/commands/prepare.ts +4 -3
- package/src/cli/commands/start.ts +18 -3
- package/src/cli/commands/write-project-info.ts +56 -0
- package/src/cli/index.ts +2 -0
- package/src/common/cli.ts +40 -0
- package/src/common/constants.ts +6 -0
- package/src/common/helper.ts +86 -0
- package/src/common/index.ts +3 -0
- package/src/core/apibara.ts +7 -2
- package/src/core/build/build.ts +13 -5
- package/src/core/build/dev.ts +46 -23
- package/src/core/build/error.ts +9 -14
- package/src/core/build/prepare.ts +5 -3
- package/src/core/build/prod.ts +25 -16
- package/src/core/build/types.ts +11 -1
- package/src/core/config/defaults.ts +3 -0
- package/src/core/config/loader.ts +15 -7
- package/src/core/config/resolvers/runtime.resolver.ts +44 -0
- package/src/core/config/update.ts +6 -2
- package/src/core/scan.ts +1 -1
- package/src/create/add.ts +14 -20
- package/src/create/constants.ts +5 -7
- package/src/create/init.ts +2 -2
- package/src/create/templates.ts +43 -116
- package/src/create/types.ts +3 -0
- package/src/create/utils.ts +20 -7
- package/src/hooks/useRuntimeConfig.ts +4 -1
- package/src/indexer/index.ts +1 -0
- package/src/indexer/plugins.ts +1 -0
- package/src/indexer/testing.ts +1 -0
- package/src/indexer/vcr.ts +1 -0
- package/src/rolldown/config.ts +86 -0
- package/src/rolldown/index.ts +2 -0
- package/src/{rollup → rolldown}/plugins/indexers.ts +3 -3
- package/src/rolldown/plugins/instrumentation.ts +68 -0
- package/src/rolldown/plugins/static-config.ts +21 -0
- package/src/runtime/dev.ts +49 -19
- package/src/runtime/internal/app.ts +42 -29
- package/src/runtime/project-info.ts +90 -0
- package/src/runtime/start.ts +91 -11
- package/src/types/config.ts +27 -13
- package/src/types/hooks.ts +8 -5
- package/src/types/index.ts +1 -1
- package/src/types/rolldown.ts +5 -0
- package/src/types/virtual/indexers.d.ts +4 -1
- package/src/types/virtual/instrumentation.d.ts +4 -0
- package/src/types/virtual/static-config.d.ts +4 -0
- package/dist/rollup/index.d.mts +0 -6
- package/dist/rollup/index.d.ts +0 -6
- package/dist/rollup/index.mjs +0 -150
- package/dist/shared/apibara.1b515d04.mjs +0 -8
- package/src/cli/common.ts +0 -8
- package/src/core/config/resolvers/preset.resolver.ts +0 -9
- package/src/core/config/resolvers/runtime-config.resolver.ts +0 -6
- package/src/rollup/config.ts +0 -87
- package/src/rollup/index.ts +0 -2
- package/src/rollup/plugins/config.ts +0 -12
- package/src/rollup/plugins/esm-shim.ts +0 -69
- package/src/types/rollup.ts +0 -8
- package/src/types/virtual/config.d.ts +0 -3
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import virtual from "@rollup/plugin-virtual";
|
|
4
|
+
import type { Apibara } from "apibara/types";
|
|
5
|
+
import type { RolldownPluginOption } from "rolldown";
|
|
6
|
+
|
|
7
|
+
export function instrumentation(apibara: Apibara) {
|
|
8
|
+
const instrumentationPath = join(
|
|
9
|
+
apibara.options._c12.cwd!,
|
|
10
|
+
`instrumentation.${apibara.options._c12.configFile?.endsWith(".ts") ? "ts" : apibara.options._c12.configFile?.endsWith(".mjs") ? "mjs" : "js"}`,
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
if (!existsSync(instrumentationPath)) {
|
|
14
|
+
return virtual({
|
|
15
|
+
"#apibara-internal-virtual/instrumentation": `
|
|
16
|
+
let register = undefined;
|
|
17
|
+
let logger = undefined;
|
|
18
|
+
|
|
19
|
+
export { register, logger };
|
|
20
|
+
`,
|
|
21
|
+
}) as RolldownPluginOption;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* We are importing the instrumentation file inline with "require" instead of "import" at the top of the file to avoid warnings from rolldown
|
|
26
|
+
* when some methods are not defined in the instrumentation file.
|
|
27
|
+
*
|
|
28
|
+
* Example warning:
|
|
29
|
+
*
|
|
30
|
+
* [IMPORT_IS_UNDEFINED] Warning: Import `logger` will always be undefined because there is no matching export in 'instrumentation.ts'
|
|
31
|
+
* ╭─[virtual:#apibara-internal-virtual/instrumentation:11:35]
|
|
32
|
+
* │
|
|
33
|
+
* 11 │ if (instrumentation && typeof instrumentation.logger === "function") {
|
|
34
|
+
* │ ───────────┬──────────
|
|
35
|
+
* │ ╰────────────
|
|
36
|
+
* ────╯
|
|
37
|
+
|
|
38
|
+
* [IMPORT_IS_UNDEFINED] Warning: Import `logger` will always be undefined because there is no matching export in 'instrumentation.ts'
|
|
39
|
+
* ╭─[virtual:#apibara-internal-virtual/instrumentation:12:16]
|
|
40
|
+
* │
|
|
41
|
+
* 12 │ logger = instrumentation.logger;
|
|
42
|
+
* │ ───────────┬──────────
|
|
43
|
+
* │ ╰────────────
|
|
44
|
+
* ────╯
|
|
45
|
+
*/
|
|
46
|
+
return virtual({
|
|
47
|
+
"#apibara-internal-virtual/instrumentation": `
|
|
48
|
+
let register = undefined;
|
|
49
|
+
let logger = undefined;
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
const instrumentation = require('${instrumentationPath}');
|
|
53
|
+
|
|
54
|
+
if (instrumentation?.register && typeof instrumentation.register === "function") {
|
|
55
|
+
register = instrumentation.register;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (instrumentation?.logger && typeof instrumentation.logger === "function") {
|
|
59
|
+
logger = instrumentation.logger;
|
|
60
|
+
}
|
|
61
|
+
} catch {
|
|
62
|
+
// Silently handle any require errors
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export { register, logger };
|
|
66
|
+
`,
|
|
67
|
+
}) as RolldownPluginOption;
|
|
68
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import virtual from "@rollup/plugin-virtual";
|
|
2
|
+
import { USER_ENV_APIBARA_RUNTIME_CONFIG } from "apibara/common";
|
|
3
|
+
import type { Apibara } from "apibara/types";
|
|
4
|
+
import type { RolldownPluginOption } from "rolldown";
|
|
5
|
+
|
|
6
|
+
export function staticConfig(apibara: Apibara) {
|
|
7
|
+
const presetString = apibara.options.preset ?? "";
|
|
8
|
+
const presetsStringified = JSON.stringify(apibara.options.presets ?? {});
|
|
9
|
+
const runtimeConfigStringified = JSON.stringify(
|
|
10
|
+
apibara.options.runtimeConfig ?? {},
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
return virtual({
|
|
14
|
+
"#apibara-internal-virtual/static-config": `
|
|
15
|
+
export const preset = ${presetString ? `"${presetString}"` : "undefined"};
|
|
16
|
+
export const presets = ${presetsStringified};
|
|
17
|
+
export const runtimeConfig = ${runtimeConfigStringified};
|
|
18
|
+
export const userEnvRuntimeConfig = JSON.parse(process.env.${USER_ENV_APIBARA_RUNTIME_CONFIG} ?? "{}");
|
|
19
|
+
`,
|
|
20
|
+
}) as RolldownPluginOption;
|
|
21
|
+
}
|
package/src/runtime/dev.ts
CHANGED
|
@@ -1,8 +1,53 @@
|
|
|
1
|
-
import { runWithReconnect } from "@apibara/indexer";
|
|
2
|
-
import {
|
|
1
|
+
import { ReloadIndexerRequest, runWithReconnect } from "@apibara/indexer";
|
|
2
|
+
import { createAuthenticatedClient } from "@apibara/protocol";
|
|
3
|
+
import { getRuntimeDataFromEnv } from "apibara/common";
|
|
3
4
|
import { defineCommand, runMain } from "citty";
|
|
5
|
+
import type { ConsolaInstance } from "consola";
|
|
6
|
+
import { blueBright } from "picocolors";
|
|
4
7
|
import { availableIndexers, createIndexer } from "./internal/app";
|
|
5
8
|
|
|
9
|
+
async function startIndexer(indexer: string) {
|
|
10
|
+
let _logger: ConsolaInstance | undefined;
|
|
11
|
+
while (true) {
|
|
12
|
+
try {
|
|
13
|
+
const { processedRuntimeConfig, preset } = getRuntimeDataFromEnv();
|
|
14
|
+
|
|
15
|
+
const { indexer: indexerInstance, logger } =
|
|
16
|
+
(await createIndexer({
|
|
17
|
+
indexerName: indexer,
|
|
18
|
+
processedRuntimeConfig,
|
|
19
|
+
preset,
|
|
20
|
+
})) ?? {};
|
|
21
|
+
|
|
22
|
+
_logger = logger;
|
|
23
|
+
|
|
24
|
+
if (!indexerInstance) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const client = createAuthenticatedClient(
|
|
29
|
+
indexerInstance.streamConfig,
|
|
30
|
+
indexerInstance.options.streamUrl,
|
|
31
|
+
indexerInstance.options.clientOptions,
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
if (logger) {
|
|
35
|
+
logger.info(`Indexer ${blueBright(indexer)} started`);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
await runWithReconnect(client, indexerInstance);
|
|
39
|
+
|
|
40
|
+
return;
|
|
41
|
+
} catch (error) {
|
|
42
|
+
if (error instanceof ReloadIndexerRequest) {
|
|
43
|
+
_logger?.info(`Indexer ${blueBright(indexer)} reloaded`);
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
6
51
|
const startCommand = defineCommand({
|
|
7
52
|
meta: {
|
|
8
53
|
name: "start",
|
|
@@ -13,13 +58,9 @@ const startCommand = defineCommand({
|
|
|
13
58
|
type: "string",
|
|
14
59
|
description: "Which indexers to run",
|
|
15
60
|
},
|
|
16
|
-
preset: {
|
|
17
|
-
type: "string",
|
|
18
|
-
description: "Preset to use",
|
|
19
|
-
},
|
|
20
61
|
},
|
|
21
62
|
async run({ args }) {
|
|
22
|
-
const { indexers: indexersArgs
|
|
63
|
+
const { indexers: indexersArgs } = args;
|
|
23
64
|
|
|
24
65
|
let selectedIndexers = availableIndexers;
|
|
25
66
|
if (indexersArgs) {
|
|
@@ -34,18 +75,7 @@ const startCommand = defineCommand({
|
|
|
34
75
|
}
|
|
35
76
|
}
|
|
36
77
|
|
|
37
|
-
await Promise.all(
|
|
38
|
-
selectedIndexers.map(async (indexer) => {
|
|
39
|
-
const indexerInstance = createIndexer(indexer, preset);
|
|
40
|
-
|
|
41
|
-
const client = createClient(
|
|
42
|
-
indexerInstance.streamConfig,
|
|
43
|
-
indexerInstance.options.streamUrl,
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
await runWithReconnect(client, indexerInstance);
|
|
47
|
-
}),
|
|
48
|
-
);
|
|
78
|
+
await Promise.all(selectedIndexers.map((indexer) => startIndexer(indexer)));
|
|
49
79
|
},
|
|
50
80
|
});
|
|
51
81
|
|
|
@@ -8,32 +8,28 @@ import {
|
|
|
8
8
|
inMemoryPersistence,
|
|
9
9
|
logger,
|
|
10
10
|
} from "@apibara/indexer/plugins";
|
|
11
|
-
import
|
|
11
|
+
import consola from "consola";
|
|
12
12
|
import { indexers } from "#apibara-internal-virtual/indexers";
|
|
13
|
+
import { logger as instrumentationLogger } from "#apibara-internal-virtual/instrumentation";
|
|
13
14
|
import { createLogger } from "./logger";
|
|
14
15
|
|
|
15
16
|
export const availableIndexers = indexers.map((i) => i.name);
|
|
16
17
|
|
|
17
|
-
export function createIndexer(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
runtimeConfig: Record<string, unknown>;
|
|
33
|
-
};
|
|
34
|
-
runtimeConfig = { ...runtimeConfig, ...presetValue.runtimeConfig };
|
|
35
|
-
}
|
|
36
|
-
|
|
18
|
+
export async function createIndexer({
|
|
19
|
+
indexerName,
|
|
20
|
+
processedRuntimeConfig,
|
|
21
|
+
preset,
|
|
22
|
+
}: {
|
|
23
|
+
indexerName: string;
|
|
24
|
+
/**
|
|
25
|
+
* Final processed runtime config to be used by the indexer
|
|
26
|
+
*/
|
|
27
|
+
processedRuntimeConfig: Record<string, unknown>;
|
|
28
|
+
/**
|
|
29
|
+
* Preset name which was used to generate the runtime config
|
|
30
|
+
*/
|
|
31
|
+
preset?: string;
|
|
32
|
+
}) {
|
|
37
33
|
const indexerDefinition = indexers.find((i) => i.name === indexerName);
|
|
38
34
|
|
|
39
35
|
if (indexerDefinition === undefined) {
|
|
@@ -42,10 +38,18 @@ export function createIndexer(indexerName: string, preset?: string) {
|
|
|
42
38
|
);
|
|
43
39
|
}
|
|
44
40
|
|
|
41
|
+
const indexerModule = indexerDefinition.indexer?.default;
|
|
42
|
+
if (indexerModule === undefined) {
|
|
43
|
+
consola.warn(
|
|
44
|
+
`Specified indexer "${indexerName}" but it does not export a default. Ignoring.`,
|
|
45
|
+
);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
45
49
|
const definition =
|
|
46
|
-
typeof
|
|
47
|
-
?
|
|
48
|
-
:
|
|
50
|
+
typeof indexerModule === "function"
|
|
51
|
+
? await indexerModule(processedRuntimeConfig)
|
|
52
|
+
: indexerModule;
|
|
49
53
|
|
|
50
54
|
let reporter: ConsolaReporter = createLogger({
|
|
51
55
|
indexer: indexerName,
|
|
@@ -53,26 +57,35 @@ export function createIndexer(indexerName: string, preset?: string) {
|
|
|
53
57
|
indexers: availableIndexers,
|
|
54
58
|
});
|
|
55
59
|
|
|
56
|
-
if
|
|
57
|
-
|
|
60
|
+
// Check if a custom logger is provided through instrumentation
|
|
61
|
+
if (instrumentationLogger) {
|
|
62
|
+
// Create a reporter using the custom logger function
|
|
63
|
+
const _reporter = instrumentationLogger({
|
|
58
64
|
indexer: indexerName,
|
|
59
65
|
preset,
|
|
60
66
|
indexers: availableIndexers,
|
|
61
67
|
});
|
|
68
|
+
|
|
69
|
+
// If the reporter is valid (has a log method), use it instead of the default
|
|
70
|
+
if (_reporter && "log" in _reporter) {
|
|
71
|
+
reporter = _reporter;
|
|
72
|
+
}
|
|
62
73
|
}
|
|
63
74
|
|
|
64
75
|
// Put the in-memory persistence plugin first so that it can be overridden by any user-defined
|
|
65
76
|
// persistence plugin.
|
|
66
|
-
// Put the logger last since we want to override any user-defined logger.
|
|
67
77
|
definition.plugins = [
|
|
68
78
|
internalContext({
|
|
69
79
|
indexerName,
|
|
70
80
|
availableIndexers,
|
|
71
81
|
} as InternalContext),
|
|
82
|
+
logger({ logger: reporter }),
|
|
72
83
|
inMemoryPersistence(),
|
|
73
84
|
...(definition.plugins ?? []),
|
|
74
|
-
logger({ logger: reporter }),
|
|
75
85
|
];
|
|
76
86
|
|
|
77
|
-
return
|
|
87
|
+
return {
|
|
88
|
+
indexer: _createIndexer(definition),
|
|
89
|
+
logger: consola.create({ reporters: [reporter] }),
|
|
90
|
+
};
|
|
78
91
|
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { writeFileSync } from "node:fs";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import {
|
|
4
|
+
getProcessedRuntimeConfig,
|
|
5
|
+
getRuntimeDataFromEnv,
|
|
6
|
+
} from "apibara/common";
|
|
7
|
+
import { defineCommand, runMain } from "citty";
|
|
8
|
+
import { availableIndexers, createIndexer } from "./internal/app";
|
|
9
|
+
|
|
10
|
+
type ProjectInfo = {
|
|
11
|
+
indexers: {
|
|
12
|
+
[indexerName: string]: {
|
|
13
|
+
[presetName: string]: {
|
|
14
|
+
type: string;
|
|
15
|
+
isFactory: boolean;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const startCommand = defineCommand({
|
|
22
|
+
meta: {
|
|
23
|
+
name: "write-project-info",
|
|
24
|
+
description: "Write json-encoded information about the project.",
|
|
25
|
+
},
|
|
26
|
+
args: {
|
|
27
|
+
"build-dir": {
|
|
28
|
+
type: "string",
|
|
29
|
+
description: "project build directory",
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
async run({ args }) {
|
|
33
|
+
const projectInfo: ProjectInfo = {
|
|
34
|
+
indexers: {},
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// get all original runtime data from env
|
|
38
|
+
const { presets, runtimeConfig, userEnvRuntimeConfig } =
|
|
39
|
+
getRuntimeDataFromEnv();
|
|
40
|
+
|
|
41
|
+
for (const preset of Object.keys(presets ?? {})) {
|
|
42
|
+
// process runtime config for each preset
|
|
43
|
+
const processedRuntimeConfig = getProcessedRuntimeConfig({
|
|
44
|
+
preset,
|
|
45
|
+
presets,
|
|
46
|
+
runtimeConfig,
|
|
47
|
+
userEnvRuntimeConfig,
|
|
48
|
+
});
|
|
49
|
+
for (const indexer of availableIndexers) {
|
|
50
|
+
const { indexer: indexerInstance } =
|
|
51
|
+
(await createIndexer({
|
|
52
|
+
indexerName: indexer,
|
|
53
|
+
processedRuntimeConfig,
|
|
54
|
+
preset,
|
|
55
|
+
})) ?? {};
|
|
56
|
+
if (!indexerInstance) {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
projectInfo.indexers[indexer] = {
|
|
60
|
+
...(projectInfo.indexers[indexer] ?? {}),
|
|
61
|
+
[preset]: {
|
|
62
|
+
type: indexerInstance.streamConfig.name,
|
|
63
|
+
isFactory: indexerInstance.options.factory !== undefined,
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const projectInfoPath = resolve(
|
|
70
|
+
args["build-dir"] ?? ".apibara",
|
|
71
|
+
"project-info.json",
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
writeFileSync(projectInfoPath, JSON.stringify(projectInfo, null, 2));
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
export const mainCli = defineCommand({
|
|
79
|
+
meta: {
|
|
80
|
+
name: "write-project-info-runner",
|
|
81
|
+
description: "Write json-encoded information about the project.",
|
|
82
|
+
},
|
|
83
|
+
subCommands: {
|
|
84
|
+
start: () => startCommand,
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
runMain(mainCli);
|
|
89
|
+
|
|
90
|
+
export default {};
|
package/src/runtime/start.ts
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
|
-
import { runWithReconnect } from "@apibara/indexer";
|
|
2
|
-
import {
|
|
1
|
+
import { ReloadIndexerRequest, runWithReconnect } from "@apibara/indexer";
|
|
2
|
+
import { createAuthenticatedClient } from "@apibara/protocol";
|
|
3
|
+
import {
|
|
4
|
+
checkForUnknownArgs,
|
|
5
|
+
getProcessedRuntimeConfig,
|
|
6
|
+
getRuntimeDataFromEnv,
|
|
7
|
+
} from "apibara/common";
|
|
3
8
|
import { defineCommand, runMain } from "citty";
|
|
9
|
+
import consola, { type ConsolaInstance } from "consola";
|
|
10
|
+
import { blueBright } from "picocolors";
|
|
11
|
+
import { register } from "#apibara-internal-virtual/instrumentation";
|
|
12
|
+
// used when running with node .apibara/build/start.mjs as these values are made static during build time (except userEnvRuntimeConfig)
|
|
13
|
+
import {
|
|
14
|
+
preset as originalPreset,
|
|
15
|
+
presets,
|
|
16
|
+
runtimeConfig,
|
|
17
|
+
userEnvRuntimeConfig,
|
|
18
|
+
} from "#apibara-internal-virtual/static-config";
|
|
4
19
|
import { createIndexer } from "./internal/app";
|
|
5
20
|
|
|
6
21
|
const startCommand = defineCommand({
|
|
@@ -16,20 +31,85 @@ const startCommand = defineCommand({
|
|
|
16
31
|
},
|
|
17
32
|
preset: {
|
|
18
33
|
type: "string",
|
|
19
|
-
description: "Preset
|
|
34
|
+
description: "Preset name",
|
|
35
|
+
},
|
|
36
|
+
standalone: {
|
|
37
|
+
type: "boolean",
|
|
38
|
+
default: true,
|
|
39
|
+
description:
|
|
40
|
+
"--standalone: can run the indexer just with node and without apibara cli \n\t\t\t --no-standalone: must run the indexer with apibara cli",
|
|
20
41
|
},
|
|
21
42
|
},
|
|
22
|
-
async run({ args }) {
|
|
23
|
-
const { indexer, preset } = args;
|
|
43
|
+
async run({ args, cmd }) {
|
|
44
|
+
const { indexer, preset: argPreset, standalone } = args;
|
|
45
|
+
await checkForUnknownArgs(args, cmd);
|
|
46
|
+
|
|
47
|
+
let _logger: ConsolaInstance | undefined;
|
|
48
|
+
|
|
49
|
+
while (true) {
|
|
50
|
+
try {
|
|
51
|
+
let preset: string | undefined;
|
|
52
|
+
let processedRuntimeConfig: Record<string, unknown> | undefined;
|
|
53
|
+
|
|
54
|
+
if (standalone) {
|
|
55
|
+
// when user does node .apibara/build/start.mjs
|
|
56
|
+
preset = argPreset ?? originalPreset;
|
|
57
|
+
processedRuntimeConfig = getProcessedRuntimeConfig({
|
|
58
|
+
preset,
|
|
59
|
+
presets,
|
|
60
|
+
runtimeConfig,
|
|
61
|
+
userEnvRuntimeConfig,
|
|
62
|
+
});
|
|
63
|
+
} else {
|
|
64
|
+
// When user does apibara start
|
|
65
|
+
const envResult = getRuntimeDataFromEnv();
|
|
66
|
+
preset = envResult.preset;
|
|
67
|
+
processedRuntimeConfig = envResult.processedRuntimeConfig;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const { indexer: indexerInstance, logger } =
|
|
71
|
+
(await createIndexer({
|
|
72
|
+
indexerName: indexer,
|
|
73
|
+
processedRuntimeConfig,
|
|
74
|
+
preset,
|
|
75
|
+
})) ?? {};
|
|
76
|
+
|
|
77
|
+
_logger = logger;
|
|
78
|
+
|
|
79
|
+
if (!indexerInstance) {
|
|
80
|
+
consola.error(
|
|
81
|
+
`Specified indexer "${indexer}" but it was not defined`,
|
|
82
|
+
);
|
|
83
|
+
process.exit(1);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const client = createAuthenticatedClient(
|
|
87
|
+
indexerInstance.streamConfig,
|
|
88
|
+
indexerInstance.options.streamUrl,
|
|
89
|
+
indexerInstance.options.clientOptions,
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
if (register) {
|
|
93
|
+
consola.start("Registering from instrumentation");
|
|
94
|
+
await register();
|
|
95
|
+
consola.success("Registered from instrumentation");
|
|
96
|
+
}
|
|
24
97
|
|
|
25
|
-
|
|
98
|
+
if (logger) {
|
|
99
|
+
logger.info(`Indexer ${blueBright(indexer)} started`);
|
|
100
|
+
}
|
|
26
101
|
|
|
27
|
-
|
|
28
|
-
indexerInstance.streamConfig,
|
|
29
|
-
indexerInstance.options.streamUrl,
|
|
30
|
-
);
|
|
102
|
+
await runWithReconnect(client, indexerInstance);
|
|
31
103
|
|
|
32
|
-
|
|
104
|
+
return;
|
|
105
|
+
} catch (error) {
|
|
106
|
+
if (error instanceof ReloadIndexerRequest) {
|
|
107
|
+
_logger?.info(`Indexer ${blueBright(indexer)} reloaded`);
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
throw error;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
33
113
|
},
|
|
34
114
|
});
|
|
35
115
|
|
package/src/types/config.ts
CHANGED
|
@@ -1,21 +1,29 @@
|
|
|
1
1
|
import type { ConsolaReporter } from "@apibara/indexer/plugins";
|
|
2
|
-
import type { RollupCommonJSOptions } from "@rollup/plugin-commonjs";
|
|
3
2
|
import type {
|
|
4
3
|
C12InputConfig,
|
|
5
4
|
ConfigWatcher,
|
|
6
5
|
ResolvedConfig,
|
|
7
6
|
WatchConfigOptions,
|
|
8
7
|
} from "c12";
|
|
9
|
-
import type { WatchOptions } from "chokidar";
|
|
10
8
|
import type { NestedHooks } from "hookable";
|
|
9
|
+
import type { WatchOptions } from "rolldown";
|
|
10
|
+
import type { RolldownOptions } from "rolldown";
|
|
11
11
|
import type { DeepPartial } from "./_utils";
|
|
12
12
|
import type { ApibaraHooks } from "./hooks";
|
|
13
|
-
import type { RollupConfig } from "./rollup";
|
|
14
13
|
|
|
15
|
-
export type
|
|
14
|
+
export type RegisterFn = () => Promise<void>;
|
|
15
|
+
|
|
16
|
+
export type LoggerFactoryFn = ({
|
|
16
17
|
indexer,
|
|
18
|
+
indexers,
|
|
17
19
|
preset,
|
|
18
|
-
}:
|
|
20
|
+
}: LoggerFactoryArgs) => ConsolaReporter;
|
|
21
|
+
|
|
22
|
+
export type LoggerFactoryArgs = {
|
|
23
|
+
indexer: string;
|
|
24
|
+
indexers: string[];
|
|
25
|
+
preset?: string;
|
|
26
|
+
};
|
|
19
27
|
|
|
20
28
|
/**
|
|
21
29
|
* Apibara Config type (apibara.config)
|
|
@@ -31,10 +39,12 @@ export interface ApibaraConfig<
|
|
|
31
39
|
runtimeConfig?: R;
|
|
32
40
|
presets?: T;
|
|
33
41
|
preset?: keyof T;
|
|
34
|
-
logger?: LoggerFactory;
|
|
35
42
|
}
|
|
36
43
|
|
|
37
|
-
export type ApibaraDynamicConfig = Pick<
|
|
44
|
+
export type ApibaraDynamicConfig = Pick<
|
|
45
|
+
ApibaraConfig,
|
|
46
|
+
"runtimeConfig" | "preset" | "presets"
|
|
47
|
+
>;
|
|
38
48
|
|
|
39
49
|
/**
|
|
40
50
|
* Config loader options
|
|
@@ -68,22 +78,26 @@ export interface ApibaraOptions<
|
|
|
68
78
|
buildDir: string;
|
|
69
79
|
outputDir: string;
|
|
70
80
|
indexersDir: string;
|
|
81
|
+
disableLogs?: boolean;
|
|
71
82
|
|
|
72
83
|
// Dev
|
|
73
84
|
dev: boolean;
|
|
74
|
-
watchOptions: WatchOptions;
|
|
85
|
+
watchOptions: WatchOptions["watch"];
|
|
75
86
|
|
|
76
87
|
// Hooks
|
|
77
88
|
hooks: NestedHooks<ApibaraHooks>;
|
|
78
89
|
|
|
79
|
-
//
|
|
80
|
-
|
|
90
|
+
// Rolldown
|
|
91
|
+
rolldownConfig?: Partial<RolldownOptions>;
|
|
81
92
|
|
|
82
|
-
|
|
83
|
-
|
|
93
|
+
/**
|
|
94
|
+
* @deprecated Use rolldownConfig instead. This option will be removed in future releases.
|
|
95
|
+
*/
|
|
96
|
+
rollupConfig?: unknown;
|
|
84
97
|
sourceMap?: boolean;
|
|
85
98
|
entry: string;
|
|
86
|
-
|
|
99
|
+
node: boolean;
|
|
100
|
+
exportConditions?: string[];
|
|
87
101
|
|
|
88
102
|
// Advanced
|
|
89
103
|
typescript: {
|
package/src/types/hooks.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
+
import type { RolldownOptions } from "rolldown";
|
|
1
2
|
import type { Apibara } from "./apibara";
|
|
2
|
-
import type { RollupConfig } from "./rollup";
|
|
3
3
|
|
|
4
4
|
export interface ApibaraHooks {
|
|
5
|
-
"
|
|
5
|
+
"rolldown:before": (
|
|
6
|
+
apibara: Apibara,
|
|
7
|
+
rolldownConfig: RolldownOptions,
|
|
8
|
+
) => void;
|
|
6
9
|
compiled: (apibara: Apibara) => void;
|
|
7
|
-
"dev:restart": () => void
|
|
8
|
-
"dev:reload": () => void
|
|
9
|
-
"
|
|
10
|
+
"dev:restart": () => Promise<void>;
|
|
11
|
+
"dev:reload": () => Promise<void>;
|
|
12
|
+
"rolldown:reload": () => Promise<void>;
|
|
10
13
|
restart: () => void;
|
|
11
14
|
close: () => void;
|
|
12
15
|
}
|
package/src/types/index.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
|
+
}[] = [];
|
package/dist/rollup/index.d.mts
DELETED