apibara 2.1.0-beta.4 → 2.1.0-beta.40
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 +168 -139
- 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 +140 -0
- package/dist/rolldown/index.mjs.map +1 -0
- package/dist/runtime/dev.mjs +19 -9
- 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 +59 -7
- 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 +33 -16
- 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 +8 -5
- package/src/create/templates.ts +144 -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 +85 -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 +21 -8
- package/src/runtime/internal/app.ts +42 -29
- package/src/runtime/project-info.ts +90 -0
- package/src/runtime/start.ts +68 -6
- 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
package/dist/runtime/start.mjs
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
import { runWithReconnect } from "@apibara/indexer";
|
|
2
|
-
import {
|
|
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 from "consola";
|
|
10
|
+
import { blueBright } from "picocolors";
|
|
11
|
+
import { register } from "#apibara-internal-virtual/instrumentation";
|
|
12
|
+
import {
|
|
13
|
+
preset as originalPreset,
|
|
14
|
+
presets,
|
|
15
|
+
runtimeConfig,
|
|
16
|
+
userEnvRuntimeConfig
|
|
17
|
+
} from "#apibara-internal-virtual/static-config";
|
|
4
18
|
import { createIndexer } from "./internal/app.mjs";
|
|
5
19
|
const startCommand = defineCommand({
|
|
6
20
|
meta: {
|
|
@@ -15,16 +29,54 @@ const startCommand = defineCommand({
|
|
|
15
29
|
},
|
|
16
30
|
preset: {
|
|
17
31
|
type: "string",
|
|
18
|
-
description: "Preset
|
|
32
|
+
description: "Preset name"
|
|
33
|
+
},
|
|
34
|
+
standalone: {
|
|
35
|
+
type: "boolean",
|
|
36
|
+
default: true,
|
|
37
|
+
description: "--standalone: can run the indexer just with node and without apibara cli \n --no-standalone: must run the indexer with apibara cli"
|
|
19
38
|
}
|
|
20
39
|
},
|
|
21
|
-
async run({ args }) {
|
|
22
|
-
const { indexer, preset } = args;
|
|
23
|
-
|
|
24
|
-
|
|
40
|
+
async run({ args, cmd }) {
|
|
41
|
+
const { indexer, preset: argPreset, standalone } = args;
|
|
42
|
+
await checkForUnknownArgs(args, cmd);
|
|
43
|
+
let preset;
|
|
44
|
+
let processedRuntimeConfig;
|
|
45
|
+
if (standalone) {
|
|
46
|
+
preset = argPreset ?? originalPreset;
|
|
47
|
+
processedRuntimeConfig = getProcessedRuntimeConfig({
|
|
48
|
+
preset,
|
|
49
|
+
presets,
|
|
50
|
+
runtimeConfig,
|
|
51
|
+
userEnvRuntimeConfig
|
|
52
|
+
});
|
|
53
|
+
} else {
|
|
54
|
+
const envResult = getRuntimeDataFromEnv();
|
|
55
|
+
preset = envResult.preset;
|
|
56
|
+
processedRuntimeConfig = envResult.processedRuntimeConfig;
|
|
57
|
+
}
|
|
58
|
+
const { indexer: indexerInstance, logger } = createIndexer({
|
|
59
|
+
indexerName: indexer,
|
|
60
|
+
processedRuntimeConfig,
|
|
61
|
+
preset
|
|
62
|
+
}) ?? {};
|
|
63
|
+
if (!indexerInstance) {
|
|
64
|
+
consola.error(`Specified indexer "${indexer}" but it was not defined`);
|
|
65
|
+
process.exit(1);
|
|
66
|
+
}
|
|
67
|
+
const client = createAuthenticatedClient(
|
|
25
68
|
indexerInstance.streamConfig,
|
|
26
|
-
indexerInstance.options.streamUrl
|
|
69
|
+
indexerInstance.options.streamUrl,
|
|
70
|
+
indexerInstance.options.clientOptions
|
|
27
71
|
);
|
|
72
|
+
if (register) {
|
|
73
|
+
consola.start("Registering from instrumentation");
|
|
74
|
+
await register();
|
|
75
|
+
consola.success("Registered from instrumentation");
|
|
76
|
+
}
|
|
77
|
+
if (logger) {
|
|
78
|
+
logger.info(`Indexer ${blueBright(indexer)} started`);
|
|
79
|
+
}
|
|
28
80
|
await runWithReconnect(client, indexerInstance);
|
|
29
81
|
}
|
|
30
82
|
});
|
|
@@ -0,0 +1,18 @@
|
|
|
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 };
|
|
18
|
+
//# sourceMappingURL=apibara.730bb1e4.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apibara.730bb1e4.mjs","sources":["../../src/create/colors.ts"],"sourcesContent":["import colors from \"picocolors\";\n\nexport const {\n blue,\n blueBright,\n cyan,\n gray,\n green,\n greenBright,\n magenta,\n red,\n redBright,\n reset,\n yellow,\n} = colors;\n"],"names":[],"mappings":";;AAEa,MAAA;AAAA,EACX,IAAA;AAAA,EACA,UAAA;AAAA,EACA,IAAA;AAAA,EACA,IAAA;AAAA,EACA,KAAA;AAAA,EACA,WAAA;AAAA,EACA,OAAA;AAAA,EACA,GAAA;AAAA,EACA,SAAA;AAAA,EACA,KAAA;AAAA,EACA,MAAA;AACF,CAAI,GAAA;;;;"}
|
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,9 +32,8 @@ 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
|
-
type ApibaraDynamicConfig = Pick<ApibaraConfig, "runtimeConfig">;
|
|
36
|
+
type ApibaraDynamicConfig = Pick<ApibaraConfig, "runtimeConfig" | "preset" | "presets">;
|
|
42
37
|
/**
|
|
43
38
|
* Config loader options
|
|
44
39
|
*/
|
|
@@ -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,9 +32,8 @@ 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
|
-
type ApibaraDynamicConfig = Pick<ApibaraConfig, "runtimeConfig">;
|
|
36
|
+
type ApibaraDynamicConfig = Pick<ApibaraConfig, "runtimeConfig" | "preset" | "presets">;
|
|
42
37
|
/**
|
|
43
38
|
* Config loader options
|
|
44
39
|
*/
|
|
@@ -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.mjs
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
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.40",
|
|
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",
|
|
@@ -32,6 +32,10 @@
|
|
|
32
32
|
"types": "./dist/hooks/index.d.ts",
|
|
33
33
|
"import": "./dist/hooks/index.mjs"
|
|
34
34
|
},
|
|
35
|
+
"./common": {
|
|
36
|
+
"types": "./dist/common/index.d.ts",
|
|
37
|
+
"import": "./dist/common/index.mjs"
|
|
38
|
+
},
|
|
35
39
|
"./runtime": {
|
|
36
40
|
"types": "./dist/runtime/index.d.ts",
|
|
37
41
|
"import": "./dist/runtime/index.mjs"
|
|
@@ -51,6 +55,22 @@
|
|
|
51
55
|
"./dist/runtime/*": {
|
|
52
56
|
"types": "./dist/runtime/*.d.ts",
|
|
53
57
|
"import": "./dist/runtime/*.mjs"
|
|
58
|
+
},
|
|
59
|
+
"./indexer": {
|
|
60
|
+
"types": "./dist/indexer/index.d.ts",
|
|
61
|
+
"import": "./dist/indexer/index.mjs"
|
|
62
|
+
},
|
|
63
|
+
"./plugins": {
|
|
64
|
+
"types": "./dist/indexer/plugins.d.ts",
|
|
65
|
+
"import": "./dist/indexer/plugins.mjs"
|
|
66
|
+
},
|
|
67
|
+
"./testing": {
|
|
68
|
+
"types": "./dist/indexer/testing.d.ts",
|
|
69
|
+
"import": "./dist/indexer/testing.mjs"
|
|
70
|
+
},
|
|
71
|
+
"./vcr": {
|
|
72
|
+
"types": "./dist/indexer/vcr.d.ts",
|
|
73
|
+
"import": "./dist/indexer/vcr.mjs"
|
|
54
74
|
}
|
|
55
75
|
},
|
|
56
76
|
"bin": {
|
|
@@ -73,10 +93,12 @@
|
|
|
73
93
|
"playground:prepare": "pnpm playground prepare --dir playground",
|
|
74
94
|
"playground:dev": "pnpm playground dev --dir playground",
|
|
75
95
|
"playground:build": "pnpm playground build --dir playground",
|
|
76
|
-
"playground:start": "pnpm playground start --dir playground --indexer starknet"
|
|
96
|
+
"playground:start": "pnpm playground start --dir playground --indexer starknet",
|
|
97
|
+
"playground:init": "pnpm playground init playground",
|
|
98
|
+
"playground:add": "pnpm playground add --dir playground"
|
|
77
99
|
},
|
|
78
100
|
"devDependencies": {
|
|
79
|
-
"@apibara/starknet": "2.1.0-beta.
|
|
101
|
+
"@apibara/starknet": "2.1.0-beta.40",
|
|
80
102
|
"@types/fs-extra": "^11.0.4",
|
|
81
103
|
"@types/node": "^20.14.0",
|
|
82
104
|
"@types/prompts": "^2.4.9",
|
|
@@ -87,19 +109,15 @@
|
|
|
87
109
|
"vitest": "^1.6.0"
|
|
88
110
|
},
|
|
89
111
|
"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",
|
|
112
|
+
"@apibara/indexer": "2.1.0-beta.40",
|
|
113
|
+
"@apibara/protocol": "2.1.0-beta.40",
|
|
114
|
+
"@rollup/plugin-replace": "^6.0.2",
|
|
96
115
|
"@rollup/plugin-virtual": "^3.0.2",
|
|
97
116
|
"c12": "^1.11.1",
|
|
98
117
|
"chokidar": "^3.6.0",
|
|
99
118
|
"citty": "^0.1.6",
|
|
100
|
-
"consola": "^3.2
|
|
119
|
+
"consola": "^3.4.2",
|
|
101
120
|
"defu": "^6.1.4",
|
|
102
|
-
"esbuild": "^0.23.0",
|
|
103
121
|
"fs-extra": "^11.2.0",
|
|
104
122
|
"hookable": "^5.5.3",
|
|
105
123
|
"klona": "^2.0.6",
|
|
@@ -111,8 +129,7 @@
|
|
|
111
129
|
"pkg-types": "^1.1.3",
|
|
112
130
|
"prettier": "^3.5.2",
|
|
113
131
|
"prompts": "^2.4.2",
|
|
114
|
-
"
|
|
115
|
-
"rollup-plugin-esbuild": "^6.1.1",
|
|
132
|
+
"rolldown": "1.0.0-beta.3",
|
|
116
133
|
"ts-morph": "^25.0.1",
|
|
117
134
|
"tslib": "^2.6.3",
|
|
118
135
|
"untyped": "^1.4.2"
|
package/src/cli/commands/add.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { checkForUnknownArgs } from "apibara/common";
|
|
1
2
|
import { addIndexer } from "apibara/create";
|
|
2
3
|
import { defineCommand } from "citty";
|
|
3
4
|
|
|
@@ -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
|
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { checkForUnknownArgs, commonArgs } from "apibara/common";
|
|
1
2
|
import { build, createApibara, prepare, writeTypes } from "apibara/core";
|
|
2
3
|
import { runtimeDir } from "apibara/runtime/meta";
|
|
3
4
|
import { defineCommand } from "citty";
|
|
4
5
|
import { join, resolve } from "pathe";
|
|
5
|
-
import { 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
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { type ChildProcess, spawn } from "node:child_process";
|
|
2
|
+
import { checkForUnknownArgs, commonArgs } from "apibara/common";
|
|
2
3
|
import { build, createApibara, prepare, writeTypes } from "apibara/core";
|
|
3
4
|
import { runtimeDir } from "apibara/runtime/meta";
|
|
4
5
|
import type { Apibara } from "apibara/types";
|
|
5
6
|
import { defineCommand } from "citty";
|
|
6
7
|
import { colors } from "consola/utils";
|
|
7
8
|
import { join, resolve } from "pathe";
|
|
8
|
-
import {
|
|
9
|
+
import { blueBright, gray } from "../../create/colors";
|
|
9
10
|
|
|
10
11
|
// Hot module reloading key regex
|
|
11
|
-
// for only runtimeConfig.* keys
|
|
12
|
-
const hmrKeyRe = /^runtimeConfig
|
|
12
|
+
// for only runtimeConfig.*, presets.* keys & preset key
|
|
13
|
+
const hmrKeyRe = /^(runtimeConfig\.|presets\.|preset$)/;
|
|
13
14
|
|
|
14
15
|
export default defineCommand({
|
|
15
16
|
meta: {
|
|
@@ -26,10 +27,29 @@ export default defineCommand({
|
|
|
26
27
|
type: "string",
|
|
27
28
|
description: "Preset to use",
|
|
28
29
|
},
|
|
30
|
+
"always-reindex": {
|
|
31
|
+
type: "boolean",
|
|
32
|
+
default: false,
|
|
33
|
+
description:
|
|
34
|
+
"Reindex the indexers from the starting block on every restart | default: `false`",
|
|
35
|
+
},
|
|
29
36
|
},
|
|
30
|
-
async run({ args }) {
|
|
37
|
+
async run({ args, data, cmd, rawArgs }) {
|
|
38
|
+
await checkForUnknownArgs(args, cmd);
|
|
39
|
+
|
|
31
40
|
const rootDir = resolve((args.dir || args._dir || ".") as string);
|
|
32
41
|
|
|
42
|
+
if (args["always-reindex"]) {
|
|
43
|
+
process.env.APIBARA_ALWAYS_REINDEX = "true";
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const selectedIndexers = new Set(
|
|
47
|
+
args.indexers
|
|
48
|
+
?.split(",")
|
|
49
|
+
.map((i) => i.trim())
|
|
50
|
+
.sort() ?? [],
|
|
51
|
+
);
|
|
52
|
+
|
|
33
53
|
let apibara: Apibara;
|
|
34
54
|
let childProcess: ChildProcess | undefined;
|
|
35
55
|
|
|
@@ -46,6 +66,7 @@ export default defineCommand({
|
|
|
46
66
|
apibara = await createApibara(
|
|
47
67
|
{
|
|
48
68
|
rootDir,
|
|
69
|
+
preset: args.preset,
|
|
49
70
|
},
|
|
50
71
|
{
|
|
51
72
|
watch: true,
|
|
@@ -58,12 +79,12 @@ export default defineCommand({
|
|
|
58
79
|
}
|
|
59
80
|
|
|
60
81
|
apibara.logger.info(
|
|
61
|
-
`Config updated:
|
|
62
|
-
${diff.map((entry) => ` ${entry.toString()}`).join("\n")}`,
|
|
82
|
+
`Config updated: \n${diff.map((entry) => ` ${entry.toString()}`).join("\n")}`,
|
|
63
83
|
);
|
|
64
84
|
|
|
65
85
|
await (diff.every((e) => hmrKeyRe.test(e.key))
|
|
66
|
-
? apibara
|
|
86
|
+
? // in hot reload we only update the runtime values & restart indexers,no build step, apibara instance remains the same
|
|
87
|
+
apibara.updateConfig(newConfig.config || {}) // Hot reload
|
|
67
88
|
: reload()); // Full reload
|
|
68
89
|
},
|
|
69
90
|
},
|
|
@@ -71,7 +92,9 @@ export default defineCommand({
|
|
|
71
92
|
true,
|
|
72
93
|
);
|
|
73
94
|
|
|
74
|
-
apibara.hooks.hookOnce("restart",
|
|
95
|
+
apibara.hooks.hookOnce("restart", async () => {
|
|
96
|
+
await reload();
|
|
97
|
+
});
|
|
75
98
|
|
|
76
99
|
apibara.options.entry = join(runtimeDir, "dev.mjs");
|
|
77
100
|
|
|
@@ -79,38 +102,50 @@ export default defineCommand({
|
|
|
79
102
|
await writeTypes(apibara);
|
|
80
103
|
await build(apibara);
|
|
81
104
|
|
|
82
|
-
apibara.hooks.hook("dev:restart", () => {
|
|
105
|
+
apibara.hooks.hook("dev:restart", async () => {
|
|
83
106
|
if (childProcess) {
|
|
84
107
|
apibara.logger.info("Change detected, stopping indexers to restart");
|
|
85
|
-
childProcess
|
|
108
|
+
await killProcess(childProcess);
|
|
86
109
|
childProcess = undefined;
|
|
87
110
|
}
|
|
88
111
|
});
|
|
89
112
|
|
|
90
|
-
apibara.hooks.hook("dev:reload", () => {
|
|
113
|
+
apibara.hooks.hook("dev:reload", async () => {
|
|
91
114
|
if (childProcess) {
|
|
92
|
-
childProcess
|
|
115
|
+
await killProcess(childProcess);
|
|
116
|
+
childProcess = undefined;
|
|
117
|
+
apibara.logger.info("Restarting indexers");
|
|
93
118
|
} else {
|
|
94
|
-
apibara.logger.
|
|
119
|
+
apibara.logger.info("Starting indexers");
|
|
120
|
+
|
|
121
|
+
const indexersText = apibara.indexers
|
|
122
|
+
.map((i) =>
|
|
123
|
+
selectedIndexers.has(i.name) || selectedIndexers.size === 0
|
|
124
|
+
? blueBright(i.name)
|
|
125
|
+
: gray(i.name),
|
|
126
|
+
)
|
|
127
|
+
.join(", ");
|
|
128
|
+
apibara.logger.info("Indexers:", indexersText);
|
|
95
129
|
}
|
|
96
130
|
|
|
97
131
|
const childArgs = [
|
|
98
132
|
resolve(apibara.options.outputDir || "./.apibara/build", "dev.mjs"),
|
|
99
133
|
"start",
|
|
100
134
|
...(args.indexers ? ["--indexers", args.indexers] : []),
|
|
101
|
-
...(args.preset ? ["--preset", args.preset] : []),
|
|
102
135
|
];
|
|
103
136
|
|
|
104
137
|
childProcess = spawn("node", childArgs, {
|
|
105
138
|
stdio: "inherit",
|
|
106
139
|
});
|
|
107
140
|
|
|
108
|
-
childProcess.on("close", (code) => {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
141
|
+
childProcess.on("close", (code, signal) => {
|
|
142
|
+
childProcess = undefined;
|
|
143
|
+
console.log();
|
|
144
|
+
apibara.logger.info(
|
|
145
|
+
`Indexers process exited${
|
|
146
|
+
code !== null ? ` with code ${colors.red(code)}` : ""
|
|
147
|
+
}`,
|
|
148
|
+
);
|
|
114
149
|
});
|
|
115
150
|
});
|
|
116
151
|
};
|
|
@@ -118,3 +153,12 @@ export default defineCommand({
|
|
|
118
153
|
await reload();
|
|
119
154
|
},
|
|
120
155
|
});
|
|
156
|
+
|
|
157
|
+
async function killProcess(childProcess: ChildProcess | undefined) {
|
|
158
|
+
if (childProcess) {
|
|
159
|
+
await new Promise((resolve) => {
|
|
160
|
+
childProcess.once("exit", resolve);
|
|
161
|
+
childProcess.kill();
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}
|
package/src/cli/commands/init.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { checkForUnknownArgs } from "apibara/common";
|
|
1
2
|
import { initializeProject } from "apibara/create";
|
|
2
3
|
import { defineCommand } from "citty";
|
|
3
4
|
|
|
@@ -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
|
});
|