apibara 2.1.0-beta.3 → 2.1.0-beta.30
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/build.mjs +4 -2
- package/dist/chunks/dev.mjs +44 -14
- package/dist/chunks/init.mjs +11 -7
- package/dist/chunks/prepare.mjs +4 -2
- package/dist/chunks/start.mjs +14 -4
- package/dist/chunks/write-project-info.mjs +50 -0
- package/dist/cli/index.mjs +2 -1
- package/dist/core/index.mjs +98 -68
- package/dist/create/index.d.mts +2 -1
- package/dist/create/index.d.ts +2 -1
- package/dist/create/index.mjs +142 -112
- package/dist/hooks/index.mjs +1 -1
- package/dist/rolldown/index.d.mts +7 -0
- package/dist/rolldown/index.d.ts +7 -0
- package/dist/rolldown/index.mjs +159 -0
- package/dist/runtime/dev.mjs +14 -4
- package/dist/runtime/internal/app.d.ts +6 -1
- package/dist/runtime/internal/app.mjs +50 -19
- package/dist/runtime/internal/helper.d.ts +12 -0
- package/dist/runtime/internal/helper.mjs +33 -0
- package/dist/runtime/project-info.d.ts +3 -0
- package/dist/runtime/project-info.mjs +53 -0
- package/dist/runtime/start.mjs +18 -4
- package/dist/shared/apibara.63c9a277.mjs +29 -0
- package/dist/shared/apibara.730bb1e4.mjs +17 -0
- package/dist/types/index.d.mts +23 -19
- package/dist/types/index.d.ts +23 -19
- package/package.json +13 -16
- package/src/cli/commands/add.ts +16 -7
- package/src/cli/commands/build.ts +5 -2
- package/src/cli/commands/dev.ts +56 -13
- package/src/cli/commands/init.ts +12 -7
- package/src/cli/commands/prepare.ts +4 -2
- package/src/cli/commands/start.ts +16 -3
- package/src/cli/commands/write-project-info.ts +56 -0
- package/src/cli/common.ts +33 -1
- package/src/cli/index.ts +2 -0
- package/src/core/apibara.ts +5 -0
- package/src/core/build/build.ts +13 -5
- package/src/core/build/dev.ts +44 -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 +13 -7
- package/src/core/config/resolvers/preset.resolver.ts +3 -0
- package/src/core/config/update.ts +1 -1
- package/src/create/add.ts +10 -9
- package/src/create/constants.ts +10 -11
- package/src/create/init.ts +8 -5
- package/src/create/templates.ts +130 -102
- package/src/hooks/useRuntimeConfig.ts +1 -1
- package/src/rolldown/config.ts +111 -0
- package/src/rolldown/index.ts +2 -0
- package/src/rolldown/plugins/config.ts +17 -0
- package/src/{rollup → rolldown}/plugins/indexers.ts +3 -3
- package/src/rolldown/plugins/instrumentation.ts +68 -0
- package/src/runtime/dev.ts +16 -4
- package/src/runtime/internal/app.ts +66 -25
- package/src/runtime/internal/helper.ts +55 -0
- package/src/runtime/project-info.ts +72 -0
- package/src/runtime/start.ts +21 -4
- package/src/types/config.ts +23 -12
- 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/config.d.ts +4 -1
- package/src/types/virtual/indexers.d.ts +4 -1
- package/src/types/virtual/instrumentation.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/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
|
@@ -6,51 +6,82 @@ import {
|
|
|
6
6
|
inMemoryPersistence,
|
|
7
7
|
logger
|
|
8
8
|
} from "@apibara/indexer/plugins";
|
|
9
|
+
import {
|
|
10
|
+
Metadata,
|
|
11
|
+
createClient
|
|
12
|
+
} from "@apibara/protocol";
|
|
13
|
+
import consola from "consola";
|
|
9
14
|
import { config } from "#apibara-internal-virtual/config";
|
|
10
15
|
import { indexers } from "#apibara-internal-virtual/indexers";
|
|
16
|
+
import { logger as instrumentationLogger } from "#apibara-internal-virtual/instrumentation";
|
|
17
|
+
import { getProcessedRuntimeConfig } from "./helper.mjs";
|
|
11
18
|
import { createLogger } from "./logger.mjs";
|
|
12
19
|
export const availableIndexers = indexers.map((i) => i.name);
|
|
13
20
|
export function createIndexer(indexerName, preset) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
if (config.presets[preset] === void 0) {
|
|
22
|
-
throw new Error(`Specified preset "${preset}" but it was not defined`);
|
|
23
|
-
}
|
|
24
|
-
const presetValue = config.presets[preset];
|
|
25
|
-
runtimeConfig = { ...runtimeConfig, ...presetValue.runtimeConfig };
|
|
26
|
-
}
|
|
21
|
+
const runtimeConfig = getProcessedRuntimeConfig({
|
|
22
|
+
preset,
|
|
23
|
+
presets: config.presets,
|
|
24
|
+
runtimeConfig: config.runtimeConfig
|
|
25
|
+
});
|
|
26
|
+
process.env.APIBARA_RUNTIME_CONFIG_HOOK_DATA = JSON.stringify(runtimeConfig);
|
|
27
27
|
const indexerDefinition = indexers.find((i) => i.name === indexerName);
|
|
28
28
|
if (indexerDefinition === void 0) {
|
|
29
29
|
throw new Error(
|
|
30
30
|
`Specified indexer "${indexerName}" but it was not defined`
|
|
31
31
|
);
|
|
32
32
|
}
|
|
33
|
-
const
|
|
33
|
+
const indexerModule = indexerDefinition.indexer?.default;
|
|
34
|
+
if (indexerModule === void 0) {
|
|
35
|
+
consola.warn(
|
|
36
|
+
`Specified indexer "${indexerName}" but it does not export a default. Ignoring.`
|
|
37
|
+
);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const definition = typeof indexerModule === "function" ? indexerModule(runtimeConfig) : indexerModule;
|
|
34
41
|
let reporter = createLogger({
|
|
35
42
|
indexer: indexerName,
|
|
36
43
|
preset,
|
|
37
44
|
indexers: availableIndexers
|
|
38
45
|
});
|
|
39
|
-
if (
|
|
40
|
-
|
|
46
|
+
if (instrumentationLogger) {
|
|
47
|
+
const _reporter = instrumentationLogger({
|
|
41
48
|
indexer: indexerName,
|
|
42
49
|
preset,
|
|
43
50
|
indexers: availableIndexers
|
|
44
51
|
});
|
|
52
|
+
if (_reporter && "log" in _reporter) {
|
|
53
|
+
reporter = _reporter;
|
|
54
|
+
}
|
|
45
55
|
}
|
|
46
56
|
definition.plugins = [
|
|
47
57
|
internalContext({
|
|
48
58
|
indexerName,
|
|
49
59
|
availableIndexers
|
|
50
60
|
}),
|
|
61
|
+
logger({ logger: reporter }),
|
|
51
62
|
inMemoryPersistence(),
|
|
52
|
-
...definition.plugins ?? []
|
|
53
|
-
logger({ logger: reporter })
|
|
63
|
+
...definition.plugins ?? []
|
|
54
64
|
];
|
|
55
|
-
return
|
|
65
|
+
return {
|
|
66
|
+
indexer: _createIndexer(definition),
|
|
67
|
+
logger: consola.create({ reporters: [reporter] })
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
export function createAuthenticatedClient(config2, streamUrl, options) {
|
|
71
|
+
const dnaToken = process.env.DNA_TOKEN;
|
|
72
|
+
if (!dnaToken) {
|
|
73
|
+
consola.warn(
|
|
74
|
+
"DNA_TOKEN environment variable is not set. Trying to connect without authentication."
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
return createClient(config2, streamUrl, {
|
|
78
|
+
...options,
|
|
79
|
+
defaultCallOptions: {
|
|
80
|
+
"*": {
|
|
81
|
+
metadata: Metadata({
|
|
82
|
+
Authorization: `Bearer ${dnaToken}`
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
});
|
|
56
87
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the merged runtime config from the process.env.APIBARA_RUNTIME_CONFIG, presets and defaults.
|
|
3
|
+
* Priority (Highest to lowest):
|
|
4
|
+
* 1. process.env.APIBARA_RUNTIME_CONFIG
|
|
5
|
+
* 2. Preset
|
|
6
|
+
* 3. Defaults
|
|
7
|
+
*/
|
|
8
|
+
export declare function getProcessedRuntimeConfig({ preset, presets, runtimeConfig, }: {
|
|
9
|
+
preset?: string;
|
|
10
|
+
presets?: Record<string, unknown>;
|
|
11
|
+
runtimeConfig?: Record<string, unknown>;
|
|
12
|
+
}): Record<string, unknown>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import defu from "defu";
|
|
2
|
+
export function getProcessedRuntimeConfig({
|
|
3
|
+
preset,
|
|
4
|
+
presets,
|
|
5
|
+
runtimeConfig
|
|
6
|
+
}) {
|
|
7
|
+
let _runtimeConfig = { ...runtimeConfig };
|
|
8
|
+
const envRuntimeConfig = process.env.APIBARA_RUNTIME_CONFIG;
|
|
9
|
+
if (preset) {
|
|
10
|
+
if (presets === void 0) {
|
|
11
|
+
throw new Error(
|
|
12
|
+
`Specified preset "${preset}" but no presets were defined`
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
if (presets[preset] === void 0) {
|
|
16
|
+
throw new Error(`Specified preset "${preset}" but it was not defined`);
|
|
17
|
+
}
|
|
18
|
+
const presetValue = presets[preset];
|
|
19
|
+
_runtimeConfig = defu(presetValue.runtimeConfig, _runtimeConfig);
|
|
20
|
+
}
|
|
21
|
+
if (envRuntimeConfig) {
|
|
22
|
+
try {
|
|
23
|
+
const envRuntimeConfigValue = JSON.parse(envRuntimeConfig);
|
|
24
|
+
_runtimeConfig = defu(envRuntimeConfigValue, _runtimeConfig);
|
|
25
|
+
} catch (error) {
|
|
26
|
+
throw new Error(
|
|
27
|
+
"Failed to parse runtime config from process.env.APIBARA_RUNTIME_CONFIG. Please ensure it is a valid JSON string.",
|
|
28
|
+
{ cause: error }
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return _runtimeConfig;
|
|
33
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { writeFileSync } from "node:fs";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { defineCommand, runMain } from "citty";
|
|
4
|
+
import { config } from "#apibara-internal-virtual/config";
|
|
5
|
+
import { availableIndexers, createIndexer } from "./internal/app.mjs";
|
|
6
|
+
const startCommand = defineCommand({
|
|
7
|
+
meta: {
|
|
8
|
+
name: "write-project-info",
|
|
9
|
+
description: "Write json-encoded information about the project."
|
|
10
|
+
},
|
|
11
|
+
args: {
|
|
12
|
+
"build-dir": {
|
|
13
|
+
type: "string",
|
|
14
|
+
description: "project build directory"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
async run({ args }) {
|
|
18
|
+
const projectInfo = {
|
|
19
|
+
indexers: {}
|
|
20
|
+
};
|
|
21
|
+
for (const preset of Object.keys(config.presets ?? {})) {
|
|
22
|
+
for (const indexer of availableIndexers) {
|
|
23
|
+
const { indexer: indexerInstance } = createIndexer(indexer, preset) ?? {};
|
|
24
|
+
if (!indexerInstance) {
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
projectInfo.indexers[indexer] = {
|
|
28
|
+
...projectInfo.indexers[indexer] ?? {},
|
|
29
|
+
[preset]: {
|
|
30
|
+
type: indexerInstance.streamConfig.name,
|
|
31
|
+
isFactory: indexerInstance.options.factory !== void 0
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const projectInfoPath = resolve(
|
|
37
|
+
args["build-dir"] ?? ".apibara",
|
|
38
|
+
"project-info.json"
|
|
39
|
+
);
|
|
40
|
+
writeFileSync(projectInfoPath, JSON.stringify(projectInfo, null, 2));
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
export const mainCli = defineCommand({
|
|
44
|
+
meta: {
|
|
45
|
+
name: "write-project-info-runner",
|
|
46
|
+
description: "Write json-encoded information about the project."
|
|
47
|
+
},
|
|
48
|
+
subCommands: {
|
|
49
|
+
start: () => startCommand
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
runMain(mainCli);
|
|
53
|
+
export default {};
|
package/dist/runtime/start.mjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { runWithReconnect } from "@apibara/indexer";
|
|
2
|
-
import { createClient } from "@apibara/protocol";
|
|
3
2
|
import { defineCommand, runMain } from "citty";
|
|
4
|
-
import
|
|
3
|
+
import consola from "consola";
|
|
4
|
+
import { blueBright } from "picocolors";
|
|
5
|
+
import { register } from "#apibara-internal-virtual/instrumentation";
|
|
6
|
+
import { createAuthenticatedClient, createIndexer } from "./internal/app.mjs";
|
|
5
7
|
const startCommand = defineCommand({
|
|
6
8
|
meta: {
|
|
7
9
|
name: "start",
|
|
@@ -20,11 +22,23 @@ const startCommand = defineCommand({
|
|
|
20
22
|
},
|
|
21
23
|
async run({ args }) {
|
|
22
24
|
const { indexer, preset } = args;
|
|
23
|
-
const indexerInstance = createIndexer(indexer, preset);
|
|
24
|
-
|
|
25
|
+
const { indexer: indexerInstance, logger } = createIndexer(indexer, preset) ?? {};
|
|
26
|
+
if (!indexerInstance) {
|
|
27
|
+
consola.error(`Specified indexer "${indexer}" but it was not defined`);
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
30
|
+
const client = createAuthenticatedClient(
|
|
25
31
|
indexerInstance.streamConfig,
|
|
26
32
|
indexerInstance.options.streamUrl
|
|
27
33
|
);
|
|
34
|
+
if (register) {
|
|
35
|
+
consola.start("Registering from instrumentation");
|
|
36
|
+
await register();
|
|
37
|
+
consola.success("Registered from instrumentation");
|
|
38
|
+
}
|
|
39
|
+
if (logger) {
|
|
40
|
+
logger.info(`Indexer ${blueBright(indexer)} started`);
|
|
41
|
+
}
|
|
28
42
|
await runWithReconnect(client, indexerInstance);
|
|
29
43
|
}
|
|
30
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/dist/types/index.d.mts
CHANGED
|
@@ -1,34 +1,30 @@
|
|
|
1
1
|
import { ConsolaInstance } from 'consola';
|
|
2
2
|
import { NestedHooks, Hookable } from 'hookable';
|
|
3
3
|
import { ConsolaReporter } from '@apibara/indexer/plugins';
|
|
4
|
-
import { RollupCommonJSOptions } from '@rollup/plugin-commonjs';
|
|
5
4
|
import { C12InputConfig, WatchConfigOptions, ResolvedConfig, ConfigWatcher } from 'c12';
|
|
6
|
-
import { WatchOptions } from '
|
|
7
|
-
import { InputOptions, OutputOptions } from 'rollup';
|
|
5
|
+
import { RolldownOptions, WatchOptions, InputOptions, OutputOptions } from 'rolldown';
|
|
8
6
|
|
|
9
7
|
type DeepPartial<T> = T extends Record<string, any> ? {
|
|
10
8
|
[P in keyof T]?: DeepPartial<T[P]> | T[P];
|
|
11
9
|
} : T;
|
|
12
10
|
|
|
13
|
-
type RollupConfig = InputOptions & {
|
|
14
|
-
output: OutputOptions;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
11
|
interface ApibaraHooks {
|
|
18
|
-
"
|
|
12
|
+
"rolldown:before": (apibara: Apibara, rolldownConfig: RolldownOptions) => void;
|
|
19
13
|
compiled: (apibara: Apibara) => void;
|
|
20
|
-
"dev:restart": () => void
|
|
21
|
-
"dev:reload": () => void
|
|
22
|
-
"
|
|
14
|
+
"dev:restart": () => Promise<void>;
|
|
15
|
+
"dev:reload": () => Promise<void>;
|
|
16
|
+
"rolldown:reload": () => Promise<void>;
|
|
23
17
|
restart: () => void;
|
|
24
18
|
close: () => void;
|
|
25
19
|
}
|
|
26
20
|
|
|
27
|
-
type
|
|
21
|
+
type RegisterFn = () => Promise<void>;
|
|
22
|
+
type LoggerFactoryFn = ({ indexer, indexers, preset, }: LoggerFactoryArgs) => ConsolaReporter;
|
|
23
|
+
type LoggerFactoryArgs = {
|
|
28
24
|
indexer: string;
|
|
29
25
|
indexers: string[];
|
|
30
26
|
preset?: string;
|
|
31
|
-
}
|
|
27
|
+
};
|
|
32
28
|
/**
|
|
33
29
|
* Apibara Config type (apibara.config)
|
|
34
30
|
*/
|
|
@@ -36,7 +32,6 @@ interface ApibaraConfig<T extends Record<string, DeepPartial<Pick<ApibaraConfig<
|
|
|
36
32
|
runtimeConfig?: R;
|
|
37
33
|
presets?: T;
|
|
38
34
|
preset?: keyof T;
|
|
39
|
-
logger?: LoggerFactory;
|
|
40
35
|
}
|
|
41
36
|
type ApibaraDynamicConfig = Pick<ApibaraConfig, "runtimeConfig">;
|
|
42
37
|
/**
|
|
@@ -57,14 +52,19 @@ interface ApibaraOptions<T extends Record<string, DeepPartial<Pick<ApibaraConfig
|
|
|
57
52
|
buildDir: string;
|
|
58
53
|
outputDir: string;
|
|
59
54
|
indexersDir: string;
|
|
55
|
+
disableLogs?: boolean;
|
|
60
56
|
dev: boolean;
|
|
61
|
-
watchOptions: WatchOptions;
|
|
57
|
+
watchOptions: WatchOptions["watch"];
|
|
62
58
|
hooks: NestedHooks<ApibaraHooks>;
|
|
63
|
-
|
|
64
|
-
|
|
59
|
+
rolldownConfig?: Partial<RolldownOptions>;
|
|
60
|
+
/**
|
|
61
|
+
* @deprecated Use rolldownConfig instead. This option will be removed in future releases.
|
|
62
|
+
*/
|
|
63
|
+
rollupConfig?: unknown;
|
|
65
64
|
sourceMap?: boolean;
|
|
66
65
|
entry: string;
|
|
67
|
-
|
|
66
|
+
node: boolean;
|
|
67
|
+
exportConditions?: string[];
|
|
68
68
|
typescript: {
|
|
69
69
|
strict?: boolean;
|
|
70
70
|
internalPaths?: boolean;
|
|
@@ -85,6 +85,10 @@ interface Apibara {
|
|
|
85
85
|
updateConfig: (config: ApibaraDynamicConfig) => void | Promise<void>;
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
+
type RolldownConfig = InputOptions & {
|
|
89
|
+
output: OutputOptions;
|
|
90
|
+
};
|
|
91
|
+
|
|
88
92
|
type ApibaraRuntimeConfig = Record<string, unknown>;
|
|
89
93
|
|
|
90
|
-
export type { Apibara, ApibaraConfig, ApibaraDynamicConfig, ApibaraHooks, ApibaraOptions, ApibaraRuntimeConfig, DeepPartial, IndexerDefinition, LoadConfigOptions,
|
|
94
|
+
export type { Apibara, ApibaraConfig, ApibaraDynamicConfig, ApibaraHooks, ApibaraOptions, ApibaraRuntimeConfig, DeepPartial, IndexerDefinition, LoadConfigOptions, LoggerFactoryArgs, LoggerFactoryFn, RegisterFn, RolldownConfig };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,34 +1,30 @@
|
|
|
1
1
|
import { ConsolaInstance } from 'consola';
|
|
2
2
|
import { NestedHooks, Hookable } from 'hookable';
|
|
3
3
|
import { ConsolaReporter } from '@apibara/indexer/plugins';
|
|
4
|
-
import { RollupCommonJSOptions } from '@rollup/plugin-commonjs';
|
|
5
4
|
import { C12InputConfig, WatchConfigOptions, ResolvedConfig, ConfigWatcher } from 'c12';
|
|
6
|
-
import { WatchOptions } from '
|
|
7
|
-
import { InputOptions, OutputOptions } from 'rollup';
|
|
5
|
+
import { RolldownOptions, WatchOptions, InputOptions, OutputOptions } from 'rolldown';
|
|
8
6
|
|
|
9
7
|
type DeepPartial<T> = T extends Record<string, any> ? {
|
|
10
8
|
[P in keyof T]?: DeepPartial<T[P]> | T[P];
|
|
11
9
|
} : T;
|
|
12
10
|
|
|
13
|
-
type RollupConfig = InputOptions & {
|
|
14
|
-
output: OutputOptions;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
11
|
interface ApibaraHooks {
|
|
18
|
-
"
|
|
12
|
+
"rolldown:before": (apibara: Apibara, rolldownConfig: RolldownOptions) => void;
|
|
19
13
|
compiled: (apibara: Apibara) => void;
|
|
20
|
-
"dev:restart": () => void
|
|
21
|
-
"dev:reload": () => void
|
|
22
|
-
"
|
|
14
|
+
"dev:restart": () => Promise<void>;
|
|
15
|
+
"dev:reload": () => Promise<void>;
|
|
16
|
+
"rolldown:reload": () => Promise<void>;
|
|
23
17
|
restart: () => void;
|
|
24
18
|
close: () => void;
|
|
25
19
|
}
|
|
26
20
|
|
|
27
|
-
type
|
|
21
|
+
type RegisterFn = () => Promise<void>;
|
|
22
|
+
type LoggerFactoryFn = ({ indexer, indexers, preset, }: LoggerFactoryArgs) => ConsolaReporter;
|
|
23
|
+
type LoggerFactoryArgs = {
|
|
28
24
|
indexer: string;
|
|
29
25
|
indexers: string[];
|
|
30
26
|
preset?: string;
|
|
31
|
-
}
|
|
27
|
+
};
|
|
32
28
|
/**
|
|
33
29
|
* Apibara Config type (apibara.config)
|
|
34
30
|
*/
|
|
@@ -36,7 +32,6 @@ interface ApibaraConfig<T extends Record<string, DeepPartial<Pick<ApibaraConfig<
|
|
|
36
32
|
runtimeConfig?: R;
|
|
37
33
|
presets?: T;
|
|
38
34
|
preset?: keyof T;
|
|
39
|
-
logger?: LoggerFactory;
|
|
40
35
|
}
|
|
41
36
|
type ApibaraDynamicConfig = Pick<ApibaraConfig, "runtimeConfig">;
|
|
42
37
|
/**
|
|
@@ -57,14 +52,19 @@ interface ApibaraOptions<T extends Record<string, DeepPartial<Pick<ApibaraConfig
|
|
|
57
52
|
buildDir: string;
|
|
58
53
|
outputDir: string;
|
|
59
54
|
indexersDir: string;
|
|
55
|
+
disableLogs?: boolean;
|
|
60
56
|
dev: boolean;
|
|
61
|
-
watchOptions: WatchOptions;
|
|
57
|
+
watchOptions: WatchOptions["watch"];
|
|
62
58
|
hooks: NestedHooks<ApibaraHooks>;
|
|
63
|
-
|
|
64
|
-
|
|
59
|
+
rolldownConfig?: Partial<RolldownOptions>;
|
|
60
|
+
/**
|
|
61
|
+
* @deprecated Use rolldownConfig instead. This option will be removed in future releases.
|
|
62
|
+
*/
|
|
63
|
+
rollupConfig?: unknown;
|
|
65
64
|
sourceMap?: boolean;
|
|
66
65
|
entry: string;
|
|
67
|
-
|
|
66
|
+
node: boolean;
|
|
67
|
+
exportConditions?: string[];
|
|
68
68
|
typescript: {
|
|
69
69
|
strict?: boolean;
|
|
70
70
|
internalPaths?: boolean;
|
|
@@ -85,6 +85,10 @@ interface Apibara {
|
|
|
85
85
|
updateConfig: (config: ApibaraDynamicConfig) => void | Promise<void>;
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
+
type RolldownConfig = InputOptions & {
|
|
89
|
+
output: OutputOptions;
|
|
90
|
+
};
|
|
91
|
+
|
|
88
92
|
type ApibaraRuntimeConfig = Record<string, unknown>;
|
|
89
93
|
|
|
90
|
-
export type { Apibara, ApibaraConfig, ApibaraDynamicConfig, ApibaraHooks, ApibaraOptions, ApibaraRuntimeConfig, DeepPartial, IndexerDefinition, LoadConfigOptions,
|
|
94
|
+
export type { Apibara, ApibaraConfig, ApibaraDynamicConfig, ApibaraHooks, ApibaraOptions, ApibaraRuntimeConfig, DeepPartial, IndexerDefinition, LoadConfigOptions, LoggerFactoryArgs, LoggerFactoryFn, RegisterFn, RolldownConfig };
|
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.30",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/core/index.mjs",
|
|
6
6
|
"exports": {
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
"types": "./dist/core/index.d.ts",
|
|
21
21
|
"import": "./dist/core/index.mjs"
|
|
22
22
|
},
|
|
23
|
-
"./
|
|
24
|
-
"types": "./dist/
|
|
25
|
-
"import": "./dist/
|
|
23
|
+
"./rolldown": {
|
|
24
|
+
"types": "./dist/rolldown/index.d.ts",
|
|
25
|
+
"import": "./dist/rolldown/index.mjs"
|
|
26
26
|
},
|
|
27
27
|
"./types": {
|
|
28
28
|
"types": "./dist/types/index.d.ts",
|
|
@@ -73,10 +73,12 @@
|
|
|
73
73
|
"playground:prepare": "pnpm playground prepare --dir playground",
|
|
74
74
|
"playground:dev": "pnpm playground dev --dir playground",
|
|
75
75
|
"playground:build": "pnpm playground build --dir playground",
|
|
76
|
-
"playground:start": "pnpm playground start --dir playground --indexer starknet"
|
|
76
|
+
"playground:start": "pnpm playground start --dir playground --indexer starknet",
|
|
77
|
+
"playground:init": "pnpm playground init playground",
|
|
78
|
+
"playground:add": "pnpm playground add --dir playground"
|
|
77
79
|
},
|
|
78
80
|
"devDependencies": {
|
|
79
|
-
"@apibara/starknet": "2.1.0-beta.
|
|
81
|
+
"@apibara/starknet": "2.1.0-beta.30",
|
|
80
82
|
"@types/fs-extra": "^11.0.4",
|
|
81
83
|
"@types/node": "^20.14.0",
|
|
82
84
|
"@types/prompts": "^2.4.9",
|
|
@@ -87,19 +89,15 @@
|
|
|
87
89
|
"vitest": "^1.6.0"
|
|
88
90
|
},
|
|
89
91
|
"dependencies": {
|
|
90
|
-
"@apibara/indexer": "2.1.0-beta.
|
|
91
|
-
"@apibara/protocol": "2.1.0-beta.
|
|
92
|
-
"@rollup/plugin-
|
|
93
|
-
"@rollup/plugin-json": "^6.1.0",
|
|
94
|
-
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
95
|
-
"@rollup/plugin-typescript": "^11.1.6",
|
|
92
|
+
"@apibara/indexer": "2.1.0-beta.30",
|
|
93
|
+
"@apibara/protocol": "2.1.0-beta.30",
|
|
94
|
+
"@rollup/plugin-replace": "^6.0.2",
|
|
96
95
|
"@rollup/plugin-virtual": "^3.0.2",
|
|
97
96
|
"c12": "^1.11.1",
|
|
98
97
|
"chokidar": "^3.6.0",
|
|
99
98
|
"citty": "^0.1.6",
|
|
100
|
-
"consola": "^3.2
|
|
99
|
+
"consola": "^3.4.2",
|
|
101
100
|
"defu": "^6.1.4",
|
|
102
|
-
"esbuild": "^0.23.0",
|
|
103
101
|
"fs-extra": "^11.2.0",
|
|
104
102
|
"hookable": "^5.5.3",
|
|
105
103
|
"klona": "^2.0.6",
|
|
@@ -111,8 +109,7 @@
|
|
|
111
109
|
"pkg-types": "^1.1.3",
|
|
112
110
|
"prettier": "^3.5.2",
|
|
113
111
|
"prompts": "^2.4.2",
|
|
114
|
-
"
|
|
115
|
-
"rollup-plugin-esbuild": "^6.1.1",
|
|
112
|
+
"rolldown": "1.0.0-beta.3",
|
|
116
113
|
"ts-morph": "^25.0.1",
|
|
117
114
|
"tslib": "^2.6.3",
|
|
118
115
|
"untyped": "^1.4.2"
|
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: {
|
|
@@ -10,28 +11,35 @@ export default defineCommand({
|
|
|
10
11
|
args: {
|
|
11
12
|
indexerId: {
|
|
12
13
|
type: "positional",
|
|
13
|
-
description: "Indexer ID",
|
|
14
|
+
description: "Indexer ID - must be in kebab-case",
|
|
14
15
|
required: false,
|
|
15
16
|
},
|
|
16
17
|
chain: {
|
|
17
18
|
type: "string",
|
|
18
|
-
description: "
|
|
19
|
+
description: "Blockchain - ethereum, beaconchain, starknet",
|
|
19
20
|
},
|
|
20
21
|
network: {
|
|
21
22
|
type: "string",
|
|
22
|
-
description: "Network",
|
|
23
|
+
description: "Network - mainnet, sepolia, other",
|
|
23
24
|
},
|
|
24
25
|
storage: {
|
|
25
26
|
type: "string",
|
|
26
|
-
description: "Storage",
|
|
27
|
+
description: "Storage - postgres, none",
|
|
27
28
|
},
|
|
28
29
|
dnaUrl: {
|
|
29
30
|
type: "string",
|
|
30
|
-
description: "DNA URL",
|
|
31
|
+
description: "DNA URL - https://custom-dna-url.apibara.org",
|
|
32
|
+
},
|
|
33
|
+
dir: {
|
|
34
|
+
type: "string",
|
|
35
|
+
description:
|
|
36
|
+
"Root directory - apibara project root where apibara.config is located | default: current working directory",
|
|
31
37
|
},
|
|
32
38
|
},
|
|
33
|
-
async run({ args }) {
|
|
34
|
-
|
|
39
|
+
async run({ args, cmd }) {
|
|
40
|
+
await checkForUnknownArgs(args, cmd);
|
|
41
|
+
|
|
42
|
+
const { indexerId, chain, network, storage, dnaUrl, dir } = args;
|
|
35
43
|
|
|
36
44
|
await addIndexer({
|
|
37
45
|
argIndexerId: indexerId,
|
|
@@ -39,6 +47,7 @@ export default defineCommand({
|
|
|
39
47
|
argNetwork: network,
|
|
40
48
|
argStorage: storage,
|
|
41
49
|
argDnaUrl: dnaUrl,
|
|
50
|
+
argRootDir: dir,
|
|
42
51
|
});
|
|
43
52
|
},
|
|
44
53
|
});
|
|
@@ -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
|
});
|