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
|
@@ -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.32",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/core/index.mjs",
|
|
6
6
|
"exports": {
|
|
@@ -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": {
|
|
@@ -78,7 +98,7 @@
|
|
|
78
98
|
"playground:add": "pnpm playground add --dir playground"
|
|
79
99
|
},
|
|
80
100
|
"devDependencies": {
|
|
81
|
-
"@apibara/starknet": "2.1.0-beta.
|
|
101
|
+
"@apibara/starknet": "2.1.0-beta.32",
|
|
82
102
|
"@types/fs-extra": "^11.0.4",
|
|
83
103
|
"@types/node": "^20.14.0",
|
|
84
104
|
"@types/prompts": "^2.4.9",
|
|
@@ -89,8 +109,8 @@
|
|
|
89
109
|
"vitest": "^1.6.0"
|
|
90
110
|
},
|
|
91
111
|
"dependencies": {
|
|
92
|
-
"@apibara/indexer": "2.1.0-beta.
|
|
93
|
-
"@apibara/protocol": "2.1.0-beta.
|
|
112
|
+
"@apibara/indexer": "2.1.0-beta.32",
|
|
113
|
+
"@apibara/protocol": "2.1.0-beta.32",
|
|
94
114
|
"@rollup/plugin-replace": "^6.0.2",
|
|
95
115
|
"@rollup/plugin-virtual": "^3.0.2",
|
|
96
116
|
"c12": "^1.11.1",
|
package/src/cli/commands/add.ts
CHANGED
|
@@ -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 { checkForUnknownArgs, commonArgs } from "../common";
|
|
6
6
|
|
|
7
7
|
export default defineCommand({
|
|
8
8
|
meta: {
|
package/src/cli/commands/dev.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
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";
|
|
@@ -6,11 +7,10 @@ import { defineCommand } from "citty";
|
|
|
6
7
|
import { colors } from "consola/utils";
|
|
7
8
|
import { join, resolve } from "pathe";
|
|
8
9
|
import { blueBright, gray } from "../../create/colors";
|
|
9
|
-
import { checkForUnknownArgs, commonArgs } from "../common";
|
|
10
10
|
|
|
11
11
|
// Hot module reloading key regex
|
|
12
|
-
// for only runtimeConfig.* keys
|
|
13
|
-
const hmrKeyRe = /^runtimeConfig
|
|
12
|
+
// for only runtimeConfig.*, presets.* keys & preset key
|
|
13
|
+
const hmrKeyRe = /^(runtimeConfig\.|presets\.|preset$)/;
|
|
14
14
|
|
|
15
15
|
export default defineCommand({
|
|
16
16
|
meta: {
|
|
@@ -79,12 +79,12 @@ export default defineCommand({
|
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
apibara.logger.info(
|
|
82
|
-
`Config updated:
|
|
83
|
-
${diff.map((entry) => ` ${entry.toString()}`).join("\n")}`,
|
|
82
|
+
`Config updated: \n${diff.map((entry) => ` ${entry.toString()}`).join("\n")}`,
|
|
84
83
|
);
|
|
85
84
|
|
|
86
85
|
await (diff.every((e) => hmrKeyRe.test(e.key))
|
|
87
|
-
? 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
|
|
88
88
|
: reload()); // Full reload
|
|
89
89
|
},
|
|
90
90
|
},
|
|
@@ -92,7 +92,9 @@ export default defineCommand({
|
|
|
92
92
|
true,
|
|
93
93
|
);
|
|
94
94
|
|
|
95
|
-
apibara.hooks.hookOnce("restart",
|
|
95
|
+
apibara.hooks.hookOnce("restart", async () => {
|
|
96
|
+
await reload();
|
|
97
|
+
});
|
|
96
98
|
|
|
97
99
|
apibara.options.entry = join(runtimeDir, "dev.mjs");
|
|
98
100
|
|
|
@@ -110,9 +112,9 @@ export default defineCommand({
|
|
|
110
112
|
|
|
111
113
|
apibara.hooks.hook("dev:reload", async () => {
|
|
112
114
|
if (childProcess) {
|
|
113
|
-
apibara.logger.info("Restarting indexers");
|
|
114
115
|
await killProcess(childProcess);
|
|
115
116
|
childProcess = undefined;
|
|
117
|
+
apibara.logger.info("Restarting indexers");
|
|
116
118
|
} else {
|
|
117
119
|
apibara.logger.info("Starting indexers");
|
|
118
120
|
|
|
@@ -130,7 +132,6 @@ export default defineCommand({
|
|
|
130
132
|
resolve(apibara.options.outputDir || "./.apibara/build", "dev.mjs"),
|
|
131
133
|
"start",
|
|
132
134
|
...(args.indexers ? ["--indexers", args.indexers] : []),
|
|
133
|
-
...(args.preset ? ["--preset", args.preset] : []),
|
|
134
135
|
];
|
|
135
136
|
|
|
136
137
|
childProcess = spawn("node", childArgs, {
|
|
@@ -140,7 +141,7 @@ export default defineCommand({
|
|
|
140
141
|
childProcess.on("close", (code, signal) => {
|
|
141
142
|
childProcess = undefined;
|
|
142
143
|
console.log();
|
|
143
|
-
apibara.logger.
|
|
144
|
+
apibara.logger.info(
|
|
144
145
|
`Indexers process exited${
|
|
145
146
|
code !== null ? ` with code ${colors.red(code)}` : ""
|
|
146
147
|
}`,
|
package/src/cli/commands/init.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
+
import { checkForUnknownArgs, commonArgs } from "apibara/common";
|
|
1
2
|
import { createApibara, writeTypes } from "apibara/core";
|
|
2
|
-
import {} from "apibara/types";
|
|
3
3
|
import { defineCommand } from "citty";
|
|
4
4
|
import { resolve } from "pathe";
|
|
5
|
-
import { checkForUnknownArgs, commonArgs } from "../common";
|
|
6
5
|
|
|
7
6
|
export default defineCommand({
|
|
8
7
|
meta: {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
|
+
import { checkForUnknownArgs, commonArgs } from "apibara/common";
|
|
2
3
|
import { createApibara } from "apibara/core";
|
|
3
4
|
import { defineCommand } from "citty";
|
|
4
5
|
import { colors } from "consola/utils";
|
|
5
6
|
import fse from "fs-extra";
|
|
6
7
|
import { resolve } from "pathe";
|
|
7
|
-
import { checkForUnknownArgs, commonArgs } from "../common";
|
|
8
8
|
|
|
9
9
|
export default defineCommand({
|
|
10
10
|
meta: {
|
|
@@ -55,6 +55,8 @@ export default defineCommand({
|
|
|
55
55
|
"start",
|
|
56
56
|
"--indexer",
|
|
57
57
|
indexer,
|
|
58
|
+
// important: this is required to run the indexer with apibara cli to load runtime values correctly
|
|
59
|
+
"--no-standalone",
|
|
58
60
|
...(preset ? ["--preset", preset] : []),
|
|
59
61
|
];
|
|
60
62
|
|
|
@@ -64,7 +66,7 @@ export default defineCommand({
|
|
|
64
66
|
|
|
65
67
|
childProcess.on("close", (code, signal) => {
|
|
66
68
|
console.log();
|
|
67
|
-
apibara.logger.
|
|
69
|
+
apibara.logger.info(
|
|
68
70
|
`Indexers process exited${
|
|
69
71
|
code !== null ? ` with code ${colors.red(code)}` : ""
|
|
70
72
|
}`,
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
+
import { checkForUnknownArgs, commonArgs } from "apibara/common";
|
|
3
4
|
import { build, createApibara, prepare, writeTypes } from "apibara/core";
|
|
4
5
|
import { runtimeDir } from "apibara/runtime/meta";
|
|
5
6
|
import { defineCommand } from "citty";
|
|
6
7
|
import consola from "consola";
|
|
7
8
|
import { resolve } from "pathe";
|
|
8
|
-
import { checkForUnknownArgs, commonArgs } from "../common";
|
|
9
9
|
|
|
10
10
|
export default defineCommand({
|
|
11
11
|
meta: {
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export const ENV_INTERNAL_APIBARA_RUNTIME = "_APIBARA_RUNTIME";
|
|
2
|
+
export const ENV_INTERNAL_APIBARA_PRESET = "_APIBARA_PRESET";
|
|
3
|
+
export const ENV_INTERNAL_APIBARA_PRESETS = "_APIBARA_PRESETS";
|
|
4
|
+
export const ENV_INTERNAL_APIBARA_PROCESSED_RUNTIME =
|
|
5
|
+
"_APIBARA_PROCESSED_RUNTIME";
|
|
6
|
+
export const USER_ENV_APIBARA_RUNTIME_CONFIG = "APIBARA_RUNTIME_CONFIG";
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import defu from "defu";
|
|
2
|
+
import {
|
|
3
|
+
ENV_INTERNAL_APIBARA_PRESET,
|
|
4
|
+
ENV_INTERNAL_APIBARA_PRESETS,
|
|
5
|
+
ENV_INTERNAL_APIBARA_PROCESSED_RUNTIME,
|
|
6
|
+
ENV_INTERNAL_APIBARA_RUNTIME,
|
|
7
|
+
USER_ENV_APIBARA_RUNTIME_CONFIG,
|
|
8
|
+
} from "./constants";
|
|
9
|
+
|
|
10
|
+
export function getRuntimeDataFromEnv() {
|
|
11
|
+
const processedRuntimeConfig: Record<string, unknown> = JSON.parse(
|
|
12
|
+
process.env[ENV_INTERNAL_APIBARA_PROCESSED_RUNTIME] ?? "{}",
|
|
13
|
+
);
|
|
14
|
+
const preset: string | undefined = process.env[ENV_INTERNAL_APIBARA_PRESET];
|
|
15
|
+
const presets: Record<string, unknown> | undefined = JSON.parse(
|
|
16
|
+
process.env[ENV_INTERNAL_APIBARA_PRESETS] ?? "{}",
|
|
17
|
+
);
|
|
18
|
+
const runtimeConfig: Record<string, unknown> | undefined = JSON.parse(
|
|
19
|
+
process.env[ENV_INTERNAL_APIBARA_RUNTIME] ?? "{}",
|
|
20
|
+
);
|
|
21
|
+
const userEnvRuntimeConfig: Record<string, unknown> | undefined = JSON.parse(
|
|
22
|
+
process.env[USER_ENV_APIBARA_RUNTIME_CONFIG] ?? "{}",
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
userEnvRuntimeConfig,
|
|
27
|
+
processedRuntimeConfig,
|
|
28
|
+
preset,
|
|
29
|
+
presets,
|
|
30
|
+
runtimeConfig,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Get the merged runtime config from the user env overrided runtime config, presets and defaults.
|
|
36
|
+
* Priority (Highest to lowest):
|
|
37
|
+
* 1. User env overrided runtime config
|
|
38
|
+
* 2. Preset
|
|
39
|
+
* 3. Defaults
|
|
40
|
+
*/
|
|
41
|
+
export function getProcessedRuntimeConfig({
|
|
42
|
+
preset,
|
|
43
|
+
presets,
|
|
44
|
+
runtimeConfig,
|
|
45
|
+
userEnvRuntimeConfig,
|
|
46
|
+
}: {
|
|
47
|
+
preset?: string;
|
|
48
|
+
presets?: Record<string, unknown>;
|
|
49
|
+
runtimeConfig?: Record<string, unknown>;
|
|
50
|
+
userEnvRuntimeConfig?: Record<string, unknown>;
|
|
51
|
+
}) {
|
|
52
|
+
let _runtimeConfig: Record<string, unknown> = { ...runtimeConfig };
|
|
53
|
+
|
|
54
|
+
if (preset) {
|
|
55
|
+
if (presets === undefined) {
|
|
56
|
+
throw new Error(
|
|
57
|
+
`Specified preset "${preset}" but no presets were defined`,
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (presets[preset] === undefined) {
|
|
62
|
+
throw new Error(`Specified preset "${preset}" but it was not defined`);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const presetValue = presets[preset] as {
|
|
66
|
+
runtimeConfig: Record<string, unknown>;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
// Preset applied
|
|
70
|
+
_runtimeConfig = defu(presetValue.runtimeConfig, _runtimeConfig);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (userEnvRuntimeConfig) {
|
|
74
|
+
try {
|
|
75
|
+
// Environment runtime config applied
|
|
76
|
+
_runtimeConfig = defu(userEnvRuntimeConfig, _runtimeConfig);
|
|
77
|
+
} catch (error) {
|
|
78
|
+
throw new Error(
|
|
79
|
+
"Failed to parse runtime config from process.env.APIBARA_RUNTIME_CONFIG. Please ensure it is a valid JSON string.",
|
|
80
|
+
{ cause: error },
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return _runtimeConfig;
|
|
86
|
+
}
|
package/src/core/apibara.ts
CHANGED
|
@@ -28,8 +28,8 @@ export async function createApibara(
|
|
|
28
28
|
hooks: createHooks(),
|
|
29
29
|
close: () => apibara.hooks.callHook("close"),
|
|
30
30
|
logger: consola.withTag("apibara"),
|
|
31
|
-
async updateConfig(
|
|
32
|
-
updateApibaraConfig(apibara,
|
|
31
|
+
async updateConfig(newConfig: ApibaraDynamicConfig) {
|
|
32
|
+
updateApibaraConfig(apibara, newConfig);
|
|
33
33
|
},
|
|
34
34
|
};
|
|
35
35
|
|
package/src/core/build/dev.ts
CHANGED
|
@@ -7,8 +7,10 @@ import { loadConfig, watchConfig } from "c12";
|
|
|
7
7
|
import { klona } from "klona/full";
|
|
8
8
|
import { ApibaraDefaults } from "./defaults";
|
|
9
9
|
import { resolvePathOptions } from "./resolvers/paths.resolver";
|
|
10
|
+
import { runtimeConfigResolver } from "./resolvers/runtime.resolver";
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
// runtimeConfigResolver handles assigning runtime values to env
|
|
13
|
+
const configResolvers = [resolvePathOptions, runtimeConfigResolver] as const;
|
|
12
14
|
|
|
13
15
|
export async function loadOptions(
|
|
14
16
|
configOverrides: ApibaraConfig = {},
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ENV_INTERNAL_APIBARA_PRESET,
|
|
3
|
+
ENV_INTERNAL_APIBARA_PRESETS,
|
|
4
|
+
ENV_INTERNAL_APIBARA_PROCESSED_RUNTIME,
|
|
5
|
+
ENV_INTERNAL_APIBARA_RUNTIME,
|
|
6
|
+
USER_ENV_APIBARA_RUNTIME_CONFIG,
|
|
7
|
+
getProcessedRuntimeConfig,
|
|
8
|
+
} from "apibara/common";
|
|
9
|
+
import type { ApibaraOptions } from "apibara/types";
|
|
10
|
+
|
|
11
|
+
export function runtimeConfigResolver(options: Partial<ApibaraOptions>) {
|
|
12
|
+
try {
|
|
13
|
+
const { runtimeConfig, preset, presets } = options;
|
|
14
|
+
|
|
15
|
+
if (runtimeConfig) {
|
|
16
|
+
process.env[ENV_INTERNAL_APIBARA_RUNTIME] = JSON.stringify(runtimeConfig);
|
|
17
|
+
}
|
|
18
|
+
if (preset) {
|
|
19
|
+
process.env[ENV_INTERNAL_APIBARA_PRESET] = preset;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (presets) {
|
|
23
|
+
process.env[ENV_INTERNAL_APIBARA_PRESETS] = JSON.stringify(presets);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const userEnvRuntimeConfig = JSON.parse(
|
|
27
|
+
process.env[USER_ENV_APIBARA_RUNTIME_CONFIG] ?? "{}",
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
// This is final processed runtime config that will be used by the indexer and useRuntimeConfig hook
|
|
31
|
+
process.env[ENV_INTERNAL_APIBARA_PROCESSED_RUNTIME] = JSON.stringify(
|
|
32
|
+
getProcessedRuntimeConfig({
|
|
33
|
+
preset,
|
|
34
|
+
presets,
|
|
35
|
+
runtimeConfig,
|
|
36
|
+
userEnvRuntimeConfig,
|
|
37
|
+
}),
|
|
38
|
+
);
|
|
39
|
+
} catch (error) {
|
|
40
|
+
throw new Error("Failed to process & set runtime environment variables", {
|
|
41
|
+
cause: error,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import type { Apibara, ApibaraDynamicConfig } from "apibara/types";
|
|
2
|
+
import { runtimeConfigResolver } from "./resolvers/runtime.resolver";
|
|
2
3
|
|
|
3
4
|
export async function updateApibaraConfig(
|
|
4
5
|
apibara: Apibara,
|
|
5
|
-
|
|
6
|
+
newConfig: ApibaraDynamicConfig,
|
|
6
7
|
) {
|
|
7
|
-
|
|
8
|
+
// applies new config values to env again during hot reload
|
|
9
|
+
runtimeConfigResolver(newConfig);
|
|
8
10
|
apibara.logger.success("Apibara config hot reloaded!");
|
|
11
|
+
// we simply stop indexers and restart them with updated runtime values
|
|
12
|
+
await apibara.hooks.callHook("dev:reload");
|
|
9
13
|
}
|
package/src/create/constants.ts
CHANGED
package/src/create/templates.ts
CHANGED
|
@@ -22,7 +22,6 @@ export function generatePackageJson(isTypeScript: boolean) {
|
|
|
22
22
|
...(isTypeScript && { typecheck: "tsc --noEmit" }),
|
|
23
23
|
},
|
|
24
24
|
dependencies: {
|
|
25
|
-
"@apibara/indexer": packageVersions["@apibara/indexer"],
|
|
26
25
|
"@apibara/protocol": packageVersions["@apibara/protocol"],
|
|
27
26
|
apibara: packageVersions.apibara,
|
|
28
27
|
},
|
|
@@ -70,8 +69,8 @@ export function generateIndexer({
|
|
|
70
69
|
chain,
|
|
71
70
|
language,
|
|
72
71
|
}: IndexerOptions) {
|
|
73
|
-
return `import { defineIndexer } from "
|
|
74
|
-
import { useLogger } from "
|
|
72
|
+
return `import { defineIndexer } from "apibara/indexer";
|
|
73
|
+
import { useLogger } from "apibara/plugins";
|
|
75
74
|
${storage === "postgres" ? `import { drizzleStorage } from "@apibara/plugin-drizzle";` : ""}
|
|
76
75
|
${storage === "postgres" ? `import { drizzle } from "@apibara/plugin-drizzle";` : ""}
|
|
77
76
|
${
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { ENV_INTERNAL_APIBARA_PROCESSED_RUNTIME } from "apibara/common";
|
|
1
2
|
import type { ApibaraRuntimeConfig } from "apibara/types";
|
|
2
3
|
|
|
3
4
|
export function useRuntimeConfig(): ApibaraRuntimeConfig {
|
|
4
|
-
return JSON.parse(
|
|
5
|
+
return JSON.parse(
|
|
6
|
+
process.env[ENV_INTERNAL_APIBARA_PROCESSED_RUNTIME] || "{}",
|
|
7
|
+
);
|
|
5
8
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@apibara/indexer";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@apibara/indexer/plugins";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@apibara/indexer/testing";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@apibara/indexer/vcr";
|
package/src/rolldown/config.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import { builtinModules } from "node:module";
|
|
3
|
-
import replace from "@rollup/plugin-replace";
|
|
4
3
|
import type { Apibara } from "apibara/types";
|
|
5
4
|
import defu from "defu";
|
|
6
5
|
import { join } from "pathe";
|
|
@@ -9,9 +8,9 @@ import type {
|
|
|
9
8
|
RolldownOptions,
|
|
10
9
|
RolldownPluginOption,
|
|
11
10
|
} from "rolldown";
|
|
12
|
-
import { appConfig } from "./plugins/config";
|
|
13
11
|
import { indexers } from "./plugins/indexers";
|
|
14
12
|
import { instrumentation } from "./plugins/instrumentation";
|
|
13
|
+
import { staticConfig } from "./plugins/static-config";
|
|
15
14
|
|
|
16
15
|
const runtimeDependencies = [
|
|
17
16
|
"better-sqlite3",
|
|
@@ -79,33 +78,8 @@ export function getRolldownConfig(apibara: Apibara): RolldownOptions {
|
|
|
79
78
|
},
|
|
80
79
|
);
|
|
81
80
|
|
|
82
|
-
rolldownConfig.plugins?.push(
|
|
83
|
-
replace({
|
|
84
|
-
preventAssignment: true,
|
|
85
|
-
values: {
|
|
86
|
-
"process.env.APIBARA_CONFIG": getSerializedRuntimeConfig(apibara),
|
|
87
|
-
},
|
|
88
|
-
}) as RolldownPluginOption,
|
|
89
|
-
);
|
|
90
|
-
|
|
81
|
+
rolldownConfig.plugins?.push(staticConfig(apibara));
|
|
91
82
|
rolldownConfig.plugins?.push(instrumentation(apibara));
|
|
92
83
|
rolldownConfig.plugins?.push(indexers(apibara));
|
|
93
|
-
rolldownConfig.plugins?.push(appConfig(apibara));
|
|
94
|
-
|
|
95
84
|
return rolldownConfig;
|
|
96
85
|
}
|
|
97
|
-
|
|
98
|
-
function getSerializedRuntimeConfig(apibara: Apibara) {
|
|
99
|
-
try {
|
|
100
|
-
return JSON.stringify({
|
|
101
|
-
runtimeConfig: apibara.options.runtimeConfig,
|
|
102
|
-
preset: apibara.options.preset,
|
|
103
|
-
presets: apibara.options.presets,
|
|
104
|
-
});
|
|
105
|
-
} catch (error) {
|
|
106
|
-
throw new Error(
|
|
107
|
-
"Failed to serialize runtime config. Please ensure all values in your runtime configuration are JSON serializable.",
|
|
108
|
-
{ cause: error },
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
@@ -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,4 +1,5 @@
|
|
|
1
1
|
import { runWithReconnect } from "@apibara/indexer";
|
|
2
|
+
import { getRuntimeDataFromEnv } from "apibara/common";
|
|
2
3
|
import { defineCommand, runMain } from "citty";
|
|
3
4
|
import { blueBright } from "picocolors";
|
|
4
5
|
import {
|
|
@@ -17,13 +18,11 @@ const startCommand = defineCommand({
|
|
|
17
18
|
type: "string",
|
|
18
19
|
description: "Which indexers to run",
|
|
19
20
|
},
|
|
20
|
-
preset: {
|
|
21
|
-
type: "string",
|
|
22
|
-
description: "Preset to use",
|
|
23
|
-
},
|
|
24
21
|
},
|
|
25
22
|
async run({ args }) {
|
|
26
|
-
const { indexers: indexersArgs
|
|
23
|
+
const { indexers: indexersArgs } = args;
|
|
24
|
+
|
|
25
|
+
const { processedRuntimeConfig, preset } = getRuntimeDataFromEnv();
|
|
27
26
|
|
|
28
27
|
let selectedIndexers = availableIndexers;
|
|
29
28
|
if (indexersArgs) {
|
|
@@ -41,7 +40,11 @@ const startCommand = defineCommand({
|
|
|
41
40
|
await Promise.all(
|
|
42
41
|
selectedIndexers.map(async (indexer) => {
|
|
43
42
|
const { indexer: indexerInstance, logger } =
|
|
44
|
-
createIndexer(
|
|
43
|
+
createIndexer({
|
|
44
|
+
indexerName: indexer,
|
|
45
|
+
processedRuntimeConfig,
|
|
46
|
+
preset,
|
|
47
|
+
}) ?? {};
|
|
45
48
|
if (!indexerInstance) {
|
|
46
49
|
return;
|
|
47
50
|
}
|
|
@@ -49,6 +52,7 @@ const startCommand = defineCommand({
|
|
|
49
52
|
const client = createAuthenticatedClient(
|
|
50
53
|
indexerInstance.streamConfig,
|
|
51
54
|
indexerInstance.options.streamUrl,
|
|
55
|
+
indexerInstance.options.clientOptions,
|
|
52
56
|
);
|
|
53
57
|
|
|
54
58
|
if (logger) {
|
|
@@ -15,25 +15,27 @@ import {
|
|
|
15
15
|
createClient,
|
|
16
16
|
} from "@apibara/protocol";
|
|
17
17
|
import consola from "consola";
|
|
18
|
-
import { config } from "#apibara-internal-virtual/config";
|
|
19
18
|
import { indexers } from "#apibara-internal-virtual/indexers";
|
|
20
19
|
import { logger as instrumentationLogger } from "#apibara-internal-virtual/instrumentation";
|
|
21
|
-
import { getProcessedRuntimeConfig } from "./helper";
|
|
22
20
|
import { createLogger } from "./logger";
|
|
23
21
|
|
|
24
22
|
export const availableIndexers = indexers.map((i) => i.name);
|
|
25
23
|
|
|
26
|
-
export function createIndexer(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
24
|
+
export function createIndexer({
|
|
25
|
+
indexerName,
|
|
26
|
+
processedRuntimeConfig,
|
|
27
|
+
preset,
|
|
28
|
+
}: {
|
|
29
|
+
indexerName: string;
|
|
30
|
+
/**
|
|
31
|
+
* Final processed runtime config to be used by the indexer
|
|
32
|
+
*/
|
|
33
|
+
processedRuntimeConfig: Record<string, unknown>;
|
|
34
|
+
/**
|
|
35
|
+
* Preset name which was used to generate the runtime config
|
|
36
|
+
*/
|
|
37
|
+
preset?: string;
|
|
38
|
+
}) {
|
|
37
39
|
const indexerDefinition = indexers.find((i) => i.name === indexerName);
|
|
38
40
|
|
|
39
41
|
if (indexerDefinition === undefined) {
|
|
@@ -52,7 +54,7 @@ export function createIndexer(indexerName: string, preset?: string) {
|
|
|
52
54
|
|
|
53
55
|
const definition =
|
|
54
56
|
typeof indexerModule === "function"
|
|
55
|
-
? indexerModule(
|
|
57
|
+
? indexerModule(processedRuntimeConfig)
|
|
56
58
|
: indexerModule;
|
|
57
59
|
|
|
58
60
|
let reporter: ConsolaReporter = createLogger({
|
|
@@ -109,10 +111,13 @@ export function createAuthenticatedClient(
|
|
|
109
111
|
return createClient(config, streamUrl, {
|
|
110
112
|
...options,
|
|
111
113
|
defaultCallOptions: {
|
|
114
|
+
...(options?.defaultCallOptions ?? {}),
|
|
112
115
|
"*": {
|
|
113
116
|
metadata: Metadata({
|
|
114
117
|
Authorization: `Bearer ${dnaToken}`,
|
|
115
118
|
}),
|
|
119
|
+
// metadata cant be overrided with spread as its a class so we override it fully if user provided it.
|
|
120
|
+
...(options?.defaultCallOptions?.["*"] ?? {}),
|
|
116
121
|
},
|
|
117
122
|
},
|
|
118
123
|
});
|