apibara 2.1.0-beta.30 → 2.1.0-beta.32
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 +2 -2
- package/dist/chunks/add.mjs.map +1 -0
- package/dist/chunks/build.mjs +2 -2
- package/dist/chunks/build.mjs.map +1 -0
- package/dist/chunks/dev.mjs +15 -11
- package/dist/chunks/dev.mjs.map +1 -0
- package/dist/chunks/init.mjs +2 -2
- package/dist/chunks/init.mjs.map +1 -0
- package/dist/chunks/prepare.mjs +2 -2
- package/dist/chunks/prepare.mjs.map +1 -0
- package/dist/chunks/start.mjs +5 -3
- package/dist/chunks/start.mjs.map +1 -0
- package/dist/chunks/write-project-info.mjs +2 -1
- package/dist/chunks/write-project-info.mjs.map +1 -0
- package/dist/cli/index.mjs +1 -0
- 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 +41 -6
- package/dist/core/index.mjs.map +1 -0
- package/dist/create/index.mjs +3 -4
- 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.mjs +19 -38
- package/dist/rolldown/index.mjs.map +1 -0
- package/dist/runtime/dev.mjs +10 -7
- package/dist/runtime/internal/app.d.ts +11 -1
- package/dist/runtime/internal/app.mjs +12 -13
- package/dist/runtime/project-info.mjs +17 -3
- package/dist/runtime/start.mjs +42 -5
- package/dist/shared/apibara.730bb1e4.mjs +1 -0
- package/dist/shared/apibara.730bb1e4.mjs.map +1 -0
- package/dist/types/index.d.mts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.mjs +1 -0
- package/dist/types/index.mjs.map +1 -0
- package/package.json +24 -4
- package/src/cli/commands/add.ts +1 -1
- package/src/cli/commands/build.ts +1 -1
- package/src/cli/commands/dev.ts +11 -10
- package/src/cli/commands/init.ts +1 -1
- package/src/cli/commands/prepare.ts +1 -2
- package/src/cli/commands/start.ts +4 -2
- package/src/cli/commands/write-project-info.ts +1 -1
- 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 +2 -2
- package/src/core/build/dev.ts +2 -0
- package/src/core/config/loader.ts +3 -1
- package/src/core/config/resolvers/runtime.resolver.ts +44 -0
- package/src/core/config/update.ts +6 -2
- package/src/create/constants.ts +0 -1
- package/src/create/templates.ts +2 -3
- 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 +2 -28
- package/src/rolldown/plugins/static-config.ts +21 -0
- package/src/runtime/dev.ts +10 -6
- package/src/runtime/internal/app.ts +19 -14
- package/src/runtime/project-info.ts +21 -3
- package/src/runtime/start.ts +48 -4
- package/src/types/config.ts +4 -1
- package/src/types/virtual/static-config.d.ts +4 -0
- package/dist/runtime/internal/helper.d.ts +0 -12
- package/dist/runtime/internal/helper.mjs +0 -33
- package/dist/shared/apibara.63c9a277.mjs +0 -29
- package/src/core/config/resolvers/preset.resolver.ts +0 -12
- package/src/rolldown/plugins/config.ts +0 -17
- package/src/runtime/internal/helper.ts +0 -55
- package/src/types/virtual/config.d.ts +0 -6
- /package/src/{cli/common.ts → common/cli.ts} +0 -0
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { writeFileSync } from "node:fs";
|
|
2
2
|
import { resolve } from "node:path";
|
|
3
|
+
import {
|
|
4
|
+
getProcessedRuntimeConfig,
|
|
5
|
+
getRuntimeDataFromEnv,
|
|
6
|
+
} from "apibara/common";
|
|
3
7
|
import { defineCommand, runMain } from "citty";
|
|
4
|
-
import { config } from "#apibara-internal-virtual/config";
|
|
5
8
|
import { availableIndexers, createIndexer } from "./internal/app";
|
|
6
9
|
|
|
7
10
|
type ProjectInfo = {
|
|
@@ -31,10 +34,25 @@ const startCommand = defineCommand({
|
|
|
31
34
|
indexers: {},
|
|
32
35
|
};
|
|
33
36
|
|
|
34
|
-
|
|
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
|
+
});
|
|
35
49
|
for (const indexer of availableIndexers) {
|
|
36
50
|
const { indexer: indexerInstance } =
|
|
37
|
-
createIndexer(
|
|
51
|
+
createIndexer({
|
|
52
|
+
indexerName: indexer,
|
|
53
|
+
processedRuntimeConfig,
|
|
54
|
+
preset,
|
|
55
|
+
}) ?? {};
|
|
38
56
|
if (!indexerInstance) {
|
|
39
57
|
continue;
|
|
40
58
|
}
|
package/src/runtime/start.ts
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
import { runWithReconnect } from "@apibara/indexer";
|
|
2
|
+
import {
|
|
3
|
+
checkForUnknownArgs,
|
|
4
|
+
getProcessedRuntimeConfig,
|
|
5
|
+
getRuntimeDataFromEnv,
|
|
6
|
+
} from "apibara/common";
|
|
2
7
|
import { defineCommand, runMain } from "citty";
|
|
3
8
|
import consola from "consola";
|
|
4
9
|
import { blueBright } from "picocolors";
|
|
5
10
|
import { register } from "#apibara-internal-virtual/instrumentation";
|
|
11
|
+
// used when running with node .apibara/build/start.mjs as these values are made static during build time (except userEnvRuntimeConfig)
|
|
12
|
+
import {
|
|
13
|
+
preset as originalPreset,
|
|
14
|
+
presets,
|
|
15
|
+
runtimeConfig,
|
|
16
|
+
userEnvRuntimeConfig,
|
|
17
|
+
} from "#apibara-internal-virtual/static-config";
|
|
6
18
|
import { createAuthenticatedClient, createIndexer } from "./internal/app";
|
|
7
19
|
|
|
8
20
|
const startCommand = defineCommand({
|
|
@@ -18,14 +30,45 @@ const startCommand = defineCommand({
|
|
|
18
30
|
},
|
|
19
31
|
preset: {
|
|
20
32
|
type: "string",
|
|
21
|
-
description: "Preset
|
|
33
|
+
description: "Preset name",
|
|
34
|
+
},
|
|
35
|
+
standalone: {
|
|
36
|
+
type: "boolean",
|
|
37
|
+
default: true,
|
|
38
|
+
description:
|
|
39
|
+
"--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",
|
|
22
40
|
},
|
|
23
41
|
},
|
|
24
|
-
async run({ args }) {
|
|
25
|
-
const { indexer, preset } = args;
|
|
42
|
+
async run({ args, cmd }) {
|
|
43
|
+
const { indexer, preset: argPreset, standalone } = args;
|
|
44
|
+
await checkForUnknownArgs(args, cmd);
|
|
45
|
+
|
|
46
|
+
let preset: string | undefined;
|
|
47
|
+
let processedRuntimeConfig: Record<string, unknown> | undefined;
|
|
48
|
+
|
|
49
|
+
if (standalone) {
|
|
50
|
+
// when user does node .apibara/build/start.mjs
|
|
51
|
+
preset = argPreset ?? originalPreset;
|
|
52
|
+
processedRuntimeConfig = getProcessedRuntimeConfig({
|
|
53
|
+
preset,
|
|
54
|
+
presets,
|
|
55
|
+
runtimeConfig,
|
|
56
|
+
userEnvRuntimeConfig,
|
|
57
|
+
});
|
|
58
|
+
} else {
|
|
59
|
+
// When user does apibara start
|
|
60
|
+
const envResult = getRuntimeDataFromEnv();
|
|
61
|
+
preset = envResult.preset;
|
|
62
|
+
processedRuntimeConfig = envResult.processedRuntimeConfig;
|
|
63
|
+
}
|
|
26
64
|
|
|
27
65
|
const { indexer: indexerInstance, logger } =
|
|
28
|
-
createIndexer(
|
|
66
|
+
createIndexer({
|
|
67
|
+
indexerName: indexer,
|
|
68
|
+
processedRuntimeConfig,
|
|
69
|
+
preset,
|
|
70
|
+
}) ?? {};
|
|
71
|
+
|
|
29
72
|
if (!indexerInstance) {
|
|
30
73
|
consola.error(`Specified indexer "${indexer}" but it was not defined`);
|
|
31
74
|
process.exit(1);
|
|
@@ -34,6 +77,7 @@ const startCommand = defineCommand({
|
|
|
34
77
|
const client = createAuthenticatedClient(
|
|
35
78
|
indexerInstance.streamConfig,
|
|
36
79
|
indexerInstance.options.streamUrl,
|
|
80
|
+
indexerInstance.options.clientOptions,
|
|
37
81
|
);
|
|
38
82
|
|
|
39
83
|
if (register) {
|
package/src/types/config.ts
CHANGED
|
@@ -41,7 +41,10 @@ export interface ApibaraConfig<
|
|
|
41
41
|
preset?: keyof T;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
export type ApibaraDynamicConfig = Pick<
|
|
44
|
+
export type ApibaraDynamicConfig = Pick<
|
|
45
|
+
ApibaraConfig,
|
|
46
|
+
"runtimeConfig" | "preset" | "presets"
|
|
47
|
+
>;
|
|
45
48
|
|
|
46
49
|
/**
|
|
47
50
|
* Config loader options
|
|
@@ -1,12 +0,0 @@
|
|
|
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>;
|
|
@@ -1,33 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
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 };
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { ApibaraOptions } from "apibara/types";
|
|
2
|
-
import defu from "defu";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @note This resolver is not in use currently, as we resolve presets in runtime files.
|
|
6
|
-
*/
|
|
7
|
-
export async function presetResolver(options: ApibaraOptions) {
|
|
8
|
-
if (options.preset && options.presets?.[options.preset]) {
|
|
9
|
-
const new_options = defu(options.presets[options.preset], options);
|
|
10
|
-
Object.assign(options, new_options);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import virtual from "@rollup/plugin-virtual";
|
|
2
|
-
import type { Apibara } from "apibara/types";
|
|
3
|
-
import type { RolldownPluginOption } from "rolldown";
|
|
4
|
-
|
|
5
|
-
export function appConfig(apibara: Apibara) {
|
|
6
|
-
return virtual({
|
|
7
|
-
"#apibara-internal-virtual/config": `
|
|
8
|
-
const serializedConfig = \`process.env.APIBARA_CONFIG\`;
|
|
9
|
-
|
|
10
|
-
if (serializedConfig === undefined || serializedConfig === "") {
|
|
11
|
-
throw new Error("APIBARA_CONFIG is not defined");
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export const config = JSON.parse(serializedConfig);
|
|
15
|
-
`,
|
|
16
|
-
}) as RolldownPluginOption;
|
|
17
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import defu from "defu";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Get the merged runtime config from the process.env.APIBARA_RUNTIME_CONFIG, presets and defaults.
|
|
5
|
-
* Priority (Highest to lowest):
|
|
6
|
-
* 1. process.env.APIBARA_RUNTIME_CONFIG
|
|
7
|
-
* 2. Preset
|
|
8
|
-
* 3. Defaults
|
|
9
|
-
*/
|
|
10
|
-
export function getProcessedRuntimeConfig({
|
|
11
|
-
preset,
|
|
12
|
-
presets,
|
|
13
|
-
runtimeConfig,
|
|
14
|
-
}: {
|
|
15
|
-
preset?: string;
|
|
16
|
-
presets?: Record<string, unknown>;
|
|
17
|
-
runtimeConfig?: Record<string, unknown>;
|
|
18
|
-
}) {
|
|
19
|
-
let _runtimeConfig: Record<string, unknown> = { ...runtimeConfig };
|
|
20
|
-
const envRuntimeConfig = process.env.APIBARA_RUNTIME_CONFIG;
|
|
21
|
-
|
|
22
|
-
if (preset) {
|
|
23
|
-
if (presets === undefined) {
|
|
24
|
-
throw new Error(
|
|
25
|
-
`Specified preset "${preset}" but no presets were defined`,
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (presets[preset] === undefined) {
|
|
30
|
-
throw new Error(`Specified preset "${preset}" but it was not defined`);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const presetValue = presets[preset] as {
|
|
34
|
-
runtimeConfig: Record<string, unknown>;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
// Preset applied
|
|
38
|
-
_runtimeConfig = defu(presetValue.runtimeConfig, _runtimeConfig);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (envRuntimeConfig) {
|
|
42
|
-
try {
|
|
43
|
-
// Environment runtime config applied
|
|
44
|
-
const envRuntimeConfigValue = JSON.parse(envRuntimeConfig);
|
|
45
|
-
_runtimeConfig = defu(envRuntimeConfigValue, _runtimeConfig);
|
|
46
|
-
} catch (error) {
|
|
47
|
-
throw new Error(
|
|
48
|
-
"Failed to parse runtime config from process.env.APIBARA_RUNTIME_CONFIG. Please ensure it is a valid JSON string.",
|
|
49
|
-
{ cause: error },
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return _runtimeConfig;
|
|
55
|
-
}
|
|
File without changes
|