apibara 2.0.0-beta.9 → 2.1.0-beta.10
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 +49 -0
- package/dist/chunks/build.mjs +3 -3
- package/dist/chunks/dev.mjs +41 -19
- package/dist/chunks/init.mjs +37 -0
- package/dist/chunks/prepare.mjs +0 -2
- package/dist/chunks/start.mjs +56 -0
- package/dist/cli/index.mjs +5 -1
- package/dist/config/index.d.mts +1 -1
- package/dist/config/index.d.ts +1 -1
- package/dist/core/index.mjs +127 -134
- package/dist/create/index.d.mts +18 -0
- package/dist/create/index.d.ts +18 -0
- package/dist/create/index.mjs +1025 -0
- package/dist/rolldown/index.d.mts +7 -0
- package/dist/rolldown/index.d.ts +7 -0
- package/dist/rolldown/index.mjs +90 -0
- package/dist/runtime/dev.d.ts +3 -0
- package/dist/runtime/dev.mjs +58 -0
- package/dist/runtime/index.d.ts +2 -0
- package/dist/runtime/index.mjs +2 -0
- package/dist/runtime/internal/app.d.ts +2 -0
- package/dist/runtime/internal/app.mjs +64 -0
- package/dist/runtime/internal/logger.d.ts +14 -0
- package/dist/runtime/internal/logger.mjs +45 -0
- package/dist/runtime/start.d.ts +3 -0
- package/dist/runtime/start.mjs +46 -0
- package/dist/types/index.d.mts +35 -29
- package/dist/types/index.d.ts +35 -29
- package/package.json +40 -22
- package/runtime-meta.d.ts +2 -0
- package/runtime-meta.mjs +7 -0
- package/src/cli/commands/add.ts +50 -0
- package/src/cli/commands/build.ts +5 -3
- package/src/cli/commands/dev.ts +50 -19
- package/src/cli/commands/init.ts +36 -0
- package/src/cli/commands/prepare.ts +0 -2
- package/src/cli/commands/start.ts +61 -0
- package/src/cli/index.ts +3 -0
- package/src/config/index.ts +5 -4
- package/src/core/apibara.ts +4 -2
- package/src/core/build/build.ts +15 -5
- package/src/core/build/dev.ts +44 -22
- package/src/core/build/error.ts +9 -15
- package/src/core/build/prepare.ts +5 -2
- package/src/core/build/prod.ts +24 -15
- package/src/core/build/types.ts +12 -95
- package/src/core/config/defaults.ts +4 -4
- package/src/core/config/loader.ts +1 -0
- package/src/core/config/resolvers/runtime-config.resolver.ts +1 -1
- package/src/core/config/update.ts +3 -4
- package/src/core/path.ts +11 -0
- package/src/core/scan.ts +40 -0
- package/src/create/add.ts +239 -0
- package/src/create/colors.ts +15 -0
- package/src/create/constants.ts +97 -0
- package/src/create/index.ts +2 -0
- package/src/create/init.ts +178 -0
- package/src/create/templates.ts +501 -0
- package/src/create/types.ts +34 -0
- package/src/create/utils.ts +422 -0
- package/src/rolldown/config.ts +83 -0
- package/src/rolldown/index.ts +2 -0
- package/src/rolldown/plugins/config.ts +13 -0
- package/src/rolldown/plugins/indexers.ts +17 -0
- package/src/runtime/dev.ts +67 -0
- package/src/runtime/index.ts +2 -0
- package/src/runtime/internal/app.ts +86 -0
- package/src/runtime/internal/logger.ts +70 -0
- package/src/runtime/start.ts +53 -0
- package/src/types/apibara.ts +8 -0
- package/src/types/config.ts +37 -31
- package/src/types/hooks.ts +8 -4
- package/src/types/index.ts +1 -1
- package/src/types/rolldown.ts +5 -0
- package/src/types/virtual/config.d.ts +3 -0
- package/src/types/virtual/indexers.d.ts +13 -0
- package/dist/internal/citty/index.d.mts +0 -1
- package/dist/internal/citty/index.d.ts +0 -1
- package/dist/internal/citty/index.mjs +0 -1
- package/dist/internal/consola/index.d.mts +0 -2
- package/dist/internal/consola/index.d.ts +0 -2
- package/dist/internal/consola/index.mjs +0 -1
- package/dist/rollup/index.d.mts +0 -5
- package/dist/rollup/index.d.ts +0 -5
- package/dist/rollup/index.mjs +0 -187
- package/src/internal/citty/index.ts +0 -1
- package/src/internal/consola/index.ts +0 -1
- package/src/rollup/config.ts +0 -209
- package/src/rollup/index.ts +0 -1
- package/src/types/rollup.ts +0 -8
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { builtinModules } from 'node:module';
|
|
3
|
+
import defu from 'defu';
|
|
4
|
+
import { join } from 'pathe';
|
|
5
|
+
import virtual from '@rollup/plugin-virtual';
|
|
6
|
+
import { hash } from 'ohash';
|
|
7
|
+
|
|
8
|
+
function appConfig(apibara) {
|
|
9
|
+
return virtual({
|
|
10
|
+
"#apibara-internal-virtual/config": `
|
|
11
|
+
import * as projectConfig from '${apibara.options._c12.configFile}';
|
|
12
|
+
|
|
13
|
+
export const config = projectConfig.default;
|
|
14
|
+
`
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function indexers(apibara) {
|
|
19
|
+
const indexers2 = [...new Set(apibara.indexers)];
|
|
20
|
+
return virtual({
|
|
21
|
+
"#apibara-internal-virtual/indexers": `
|
|
22
|
+
${indexers2.map((i) => `import * as _${hash(i)} from '${i.indexer}';`).join("\n")}
|
|
23
|
+
|
|
24
|
+
export const indexers = [
|
|
25
|
+
${indexers2.map((i) => `{ name: "${i.name}", indexer: _${hash(i)} }`).join(",\n")}
|
|
26
|
+
];
|
|
27
|
+
`
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const runtimeDependencies = [
|
|
32
|
+
"better-sqlite3",
|
|
33
|
+
"@electric-sql/pglite",
|
|
34
|
+
"pg",
|
|
35
|
+
// https://socket.io/docs/v4/server-installation/#additional-packages
|
|
36
|
+
"utf-8-validate",
|
|
37
|
+
"bufferutil",
|
|
38
|
+
"node-fetch"
|
|
39
|
+
];
|
|
40
|
+
function getRolldownConfig(apibara) {
|
|
41
|
+
const extensions = [
|
|
42
|
+
".ts",
|
|
43
|
+
".mjs",
|
|
44
|
+
".js",
|
|
45
|
+
".json",
|
|
46
|
+
".node",
|
|
47
|
+
".tsx",
|
|
48
|
+
".jsx"
|
|
49
|
+
];
|
|
50
|
+
const tsConfigExists = existsSync(
|
|
51
|
+
join(apibara.options.rootDir, "tsconfig.json")
|
|
52
|
+
);
|
|
53
|
+
const rolldownConfig = defu(
|
|
54
|
+
// biome-ignore lint/suspicious/noExplicitAny: apibara.options.rolldownConfig is typed
|
|
55
|
+
apibara.options.rolldownConfig,
|
|
56
|
+
{
|
|
57
|
+
platform: "node",
|
|
58
|
+
input: apibara.options.entry,
|
|
59
|
+
output: {
|
|
60
|
+
dir: join(apibara.options.outputDir || "./.apibara/build"),
|
|
61
|
+
format: "esm",
|
|
62
|
+
entryFileNames: "[name].mjs",
|
|
63
|
+
chunkFileNames: "chunks/[name]-[hash].mjs",
|
|
64
|
+
sourcemap: true
|
|
65
|
+
},
|
|
66
|
+
plugins: [],
|
|
67
|
+
onwarn(warning, rolldownWarn) {
|
|
68
|
+
if (!["CIRCULAR_DEPENDENCY", "EVAL", "THIS_IS_UNDEFINED"].includes(
|
|
69
|
+
warning.code || ""
|
|
70
|
+
) && !warning.message.includes("Unsupported source map comment") && !warning.message.includes("@__PURE__") && !warning.message.includes("/*#__PURE__*/")) {
|
|
71
|
+
rolldownWarn(warning);
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
resolve: {
|
|
75
|
+
extensions,
|
|
76
|
+
preferBuiltins: !!apibara.options.node,
|
|
77
|
+
mainFields: ["main"],
|
|
78
|
+
exportConditions: apibara.options.exportConditions,
|
|
79
|
+
tsconfigFilename: tsConfigExists ? "tsconfig.json" : void 0
|
|
80
|
+
},
|
|
81
|
+
treeshake: true,
|
|
82
|
+
external: [...builtinModules, ...runtimeDependencies]
|
|
83
|
+
}
|
|
84
|
+
);
|
|
85
|
+
rolldownConfig.plugins?.push(indexers(apibara));
|
|
86
|
+
rolldownConfig.plugins?.push(appConfig(apibara));
|
|
87
|
+
return rolldownConfig;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export { getRolldownConfig };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { runWithReconnect } from "@apibara/indexer";
|
|
2
|
+
import { createClient } from "@apibara/protocol";
|
|
3
|
+
import { defineCommand, runMain } from "citty";
|
|
4
|
+
import { availableIndexers, createIndexer } from "./internal/app.mjs";
|
|
5
|
+
const startCommand = defineCommand({
|
|
6
|
+
meta: {
|
|
7
|
+
name: "start",
|
|
8
|
+
description: "Start the indexer"
|
|
9
|
+
},
|
|
10
|
+
args: {
|
|
11
|
+
indexers: {
|
|
12
|
+
type: "string",
|
|
13
|
+
description: "Which indexers to run"
|
|
14
|
+
},
|
|
15
|
+
preset: {
|
|
16
|
+
type: "string",
|
|
17
|
+
description: "Preset to use"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
async run({ args }) {
|
|
21
|
+
const { indexers: indexersArgs, preset } = args;
|
|
22
|
+
let selectedIndexers = availableIndexers;
|
|
23
|
+
if (indexersArgs) {
|
|
24
|
+
selectedIndexers = indexersArgs.split(",");
|
|
25
|
+
}
|
|
26
|
+
for (const indexer of selectedIndexers) {
|
|
27
|
+
if (!availableIndexers.includes(indexer)) {
|
|
28
|
+
throw new Error(
|
|
29
|
+
`Specified indexer "${indexer}" but it was not defined`
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
await Promise.all(
|
|
34
|
+
selectedIndexers.map(async (indexer) => {
|
|
35
|
+
const indexerInstance = createIndexer(indexer, preset);
|
|
36
|
+
if (!indexerInstance) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const client = createClient(
|
|
40
|
+
indexerInstance.streamConfig,
|
|
41
|
+
indexerInstance.options.streamUrl
|
|
42
|
+
);
|
|
43
|
+
await runWithReconnect(client, indexerInstance);
|
|
44
|
+
})
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
export const mainCli = defineCommand({
|
|
49
|
+
meta: {
|
|
50
|
+
name: "indexer-dev-runner",
|
|
51
|
+
description: "Run indexer in dev mode"
|
|
52
|
+
},
|
|
53
|
+
subCommands: {
|
|
54
|
+
start: () => startCommand
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
runMain(mainCli);
|
|
58
|
+
export default {};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { createIndexer as _createIndexer } from "@apibara/indexer";
|
|
2
|
+
import {
|
|
3
|
+
internalContext
|
|
4
|
+
} from "@apibara/indexer/internal/plugins";
|
|
5
|
+
import {
|
|
6
|
+
inMemoryPersistence,
|
|
7
|
+
logger
|
|
8
|
+
} from "@apibara/indexer/plugins";
|
|
9
|
+
import consola from "consola";
|
|
10
|
+
import { config } from "#apibara-internal-virtual/config";
|
|
11
|
+
import { indexers } from "#apibara-internal-virtual/indexers";
|
|
12
|
+
import { createLogger } from "./logger.mjs";
|
|
13
|
+
export const availableIndexers = indexers.map((i) => i.name);
|
|
14
|
+
export function createIndexer(indexerName, preset) {
|
|
15
|
+
let runtimeConfig = { ...config.runtimeConfig };
|
|
16
|
+
if (preset) {
|
|
17
|
+
if (config.presets === void 0) {
|
|
18
|
+
throw new Error(
|
|
19
|
+
`Specified preset "${preset}" but no presets were defined`
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
if (config.presets[preset] === void 0) {
|
|
23
|
+
throw new Error(`Specified preset "${preset}" but it was not defined`);
|
|
24
|
+
}
|
|
25
|
+
const presetValue = config.presets[preset];
|
|
26
|
+
runtimeConfig = { ...runtimeConfig, ...presetValue.runtimeConfig };
|
|
27
|
+
}
|
|
28
|
+
const indexerDefinition = indexers.find((i) => i.name === indexerName);
|
|
29
|
+
if (indexerDefinition === void 0) {
|
|
30
|
+
throw new Error(
|
|
31
|
+
`Specified indexer "${indexerName}" but it was not defined`
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
const indexerModule = indexerDefinition.indexer?.default;
|
|
35
|
+
if (indexerModule === void 0) {
|
|
36
|
+
consola.warn(
|
|
37
|
+
`Specified indexer "${indexerName}" but it does not export a default. Ignoring.`
|
|
38
|
+
);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const definition = typeof indexerModule === "function" ? indexerModule(runtimeConfig) : indexerModule;
|
|
42
|
+
let reporter = createLogger({
|
|
43
|
+
indexer: indexerName,
|
|
44
|
+
preset,
|
|
45
|
+
indexers: availableIndexers
|
|
46
|
+
});
|
|
47
|
+
if (config.logger) {
|
|
48
|
+
reporter = config.logger({
|
|
49
|
+
indexer: indexerName,
|
|
50
|
+
preset,
|
|
51
|
+
indexers: availableIndexers
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
definition.plugins = [
|
|
55
|
+
internalContext({
|
|
56
|
+
indexerName,
|
|
57
|
+
availableIndexers
|
|
58
|
+
}),
|
|
59
|
+
logger({ logger: reporter }),
|
|
60
|
+
inMemoryPersistence(),
|
|
61
|
+
...definition.plugins ?? []
|
|
62
|
+
];
|
|
63
|
+
return _createIndexer(definition);
|
|
64
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ConsolaOptions, ConsolaReporter, LogObject } from "consola";
|
|
2
|
+
declare class DefaultReporter implements ConsolaReporter {
|
|
3
|
+
private tag;
|
|
4
|
+
constructor(indexer: string, indexers: string[], preset?: string);
|
|
5
|
+
log(logObj: LogObject, ctx: {
|
|
6
|
+
options: ConsolaOptions;
|
|
7
|
+
}): void;
|
|
8
|
+
}
|
|
9
|
+
export declare function createLogger({ indexer, indexers, preset, }: {
|
|
10
|
+
indexer: string;
|
|
11
|
+
indexers: string[];
|
|
12
|
+
preset?: string;
|
|
13
|
+
}): DefaultReporter;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { colors, getColor } from "consola/utils";
|
|
2
|
+
import { murmurHash } from "ohash";
|
|
3
|
+
const INDEXER_COLOR_MAP = [
|
|
4
|
+
colors.red,
|
|
5
|
+
colors.green,
|
|
6
|
+
colors.yellow,
|
|
7
|
+
colors.blue,
|
|
8
|
+
colors.magenta,
|
|
9
|
+
colors.cyan
|
|
10
|
+
];
|
|
11
|
+
const TYPE_COLOR_MAP = {
|
|
12
|
+
info: "cyan",
|
|
13
|
+
fail: "red",
|
|
14
|
+
success: "green",
|
|
15
|
+
ready: "green",
|
|
16
|
+
start: "magenta"
|
|
17
|
+
};
|
|
18
|
+
const LEVEL_COLOR_MAP = {
|
|
19
|
+
0: "red",
|
|
20
|
+
1: "yellow"
|
|
21
|
+
};
|
|
22
|
+
const MAX_INDEXER_NAME_LENGTH = 20;
|
|
23
|
+
class DefaultReporter {
|
|
24
|
+
tag;
|
|
25
|
+
constructor(indexer, indexers, preset) {
|
|
26
|
+
const color = INDEXER_COLOR_MAP[murmurHash(indexer) % INDEXER_COLOR_MAP.length];
|
|
27
|
+
const presetLength = preset ? preset.length : 0;
|
|
28
|
+
const longestIndexerName = Math.max(...indexers.map((i) => i.length), indexer.length) + presetLength;
|
|
29
|
+
const paddedIndexer = `${indexer}${preset ? `:${preset} ` : ""}`.padEnd(longestIndexerName, " ").slice(0, Math.min(longestIndexerName, MAX_INDEXER_NAME_LENGTH));
|
|
30
|
+
this.tag = color(`${paddedIndexer} |`);
|
|
31
|
+
}
|
|
32
|
+
log(logObj, ctx) {
|
|
33
|
+
const { args } = logObj;
|
|
34
|
+
const typeColor = TYPE_COLOR_MAP[logObj.type] || LEVEL_COLOR_MAP[logObj.level] || "gray";
|
|
35
|
+
const type = getColor(typeColor, "white")(logObj.type);
|
|
36
|
+
console.log(`${this.tag} ${type}`, ...args);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export function createLogger({
|
|
40
|
+
indexer,
|
|
41
|
+
indexers,
|
|
42
|
+
preset
|
|
43
|
+
}) {
|
|
44
|
+
return new DefaultReporter(indexer, indexers, preset);
|
|
45
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { runWithReconnect } from "@apibara/indexer";
|
|
2
|
+
import { createClient } from "@apibara/protocol";
|
|
3
|
+
import { defineCommand, runMain } from "citty";
|
|
4
|
+
import consola from "consola";
|
|
5
|
+
import { createIndexer } from "./internal/app.mjs";
|
|
6
|
+
const startCommand = defineCommand({
|
|
7
|
+
meta: {
|
|
8
|
+
name: "start",
|
|
9
|
+
description: "Start the indexer"
|
|
10
|
+
},
|
|
11
|
+
args: {
|
|
12
|
+
indexer: {
|
|
13
|
+
type: "string",
|
|
14
|
+
description: "Indexer name",
|
|
15
|
+
required: true
|
|
16
|
+
},
|
|
17
|
+
preset: {
|
|
18
|
+
type: "string",
|
|
19
|
+
description: "Preset to use"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
async run({ args }) {
|
|
23
|
+
const { indexer, preset } = args;
|
|
24
|
+
const indexerInstance = createIndexer(indexer, preset);
|
|
25
|
+
if (!indexerInstance) {
|
|
26
|
+
consola.error(`Specified indexer "${indexer}" but it was not defined`);
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
const client = createClient(
|
|
30
|
+
indexerInstance.streamConfig,
|
|
31
|
+
indexerInstance.options.streamUrl
|
|
32
|
+
);
|
|
33
|
+
await runWithReconnect(client, indexerInstance);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
export const mainCli = defineCommand({
|
|
37
|
+
meta: {
|
|
38
|
+
name: "indexer-runner",
|
|
39
|
+
description: "Run an indexer"
|
|
40
|
+
},
|
|
41
|
+
subCommands: {
|
|
42
|
+
start: () => startCommand
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
runMain(mainCli);
|
|
46
|
+
export default {};
|
package/dist/types/index.d.mts
CHANGED
|
@@ -1,39 +1,36 @@
|
|
|
1
1
|
import { ConsolaInstance } from 'consola';
|
|
2
2
|
import { NestedHooks, Hookable } from 'hookable';
|
|
3
|
-
import {
|
|
3
|
+
import { ConsolaReporter } from '@apibara/indexer/plugins';
|
|
4
4
|
import { C12InputConfig, WatchConfigOptions, ResolvedConfig, ConfigWatcher } from 'c12';
|
|
5
|
-
import { WatchOptions } from '
|
|
6
|
-
import { TSConfig } from 'pkg-types';
|
|
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:
|
|
21
|
-
"
|
|
14
|
+
"dev:restart": () => Promise<void>;
|
|
15
|
+
"dev:reload": () => Promise<void>;
|
|
16
|
+
"rolldown:reload": () => Promise<void>;
|
|
22
17
|
restart: () => void;
|
|
23
18
|
close: () => void;
|
|
24
19
|
}
|
|
25
20
|
|
|
21
|
+
type LoggerFactory = ({ indexer, preset, }: {
|
|
22
|
+
indexer: string;
|
|
23
|
+
indexers: string[];
|
|
24
|
+
preset?: string;
|
|
25
|
+
}) => ConsolaReporter;
|
|
26
26
|
/**
|
|
27
27
|
* Apibara Config type (apibara.config)
|
|
28
28
|
*/
|
|
29
|
-
interface ApibaraConfig<T extends Record<string, DeepPartial<ApibaraConfig<T, R>>> =
|
|
30
|
-
sink?: {
|
|
31
|
-
default: () => Sink;
|
|
32
|
-
[key: string]: () => Sink;
|
|
33
|
-
};
|
|
29
|
+
interface ApibaraConfig<T extends Record<string, DeepPartial<Pick<ApibaraConfig<T, R>, "runtimeConfig">>> = Record<string, never>, R extends Record<string, unknown> = Record<string, never>> extends Partial<Omit<ApibaraOptions<T, R>, "preset" | "presets" | "dev">>, C12InputConfig<ApibaraConfig<T, R>> {
|
|
34
30
|
runtimeConfig?: R;
|
|
35
31
|
presets?: T;
|
|
36
32
|
preset?: keyof T;
|
|
33
|
+
logger?: LoggerFactory;
|
|
37
34
|
}
|
|
38
35
|
type ApibaraDynamicConfig = Pick<ApibaraConfig, "runtimeConfig">;
|
|
39
36
|
/**
|
|
@@ -43,13 +40,9 @@ interface LoadConfigOptions {
|
|
|
43
40
|
watch?: boolean;
|
|
44
41
|
c12?: WatchConfigOptions;
|
|
45
42
|
}
|
|
46
|
-
interface ApibaraOptions<T extends Record<string, DeepPartial<ApibaraConfig<T, R>>> =
|
|
43
|
+
interface ApibaraOptions<T extends Record<string, DeepPartial<Pick<ApibaraConfig<T, R>, "runtimeConfig">>> = Record<string, never>, R extends Record<string, unknown> = Record<string, never>> {
|
|
47
44
|
_config: ApibaraConfig<T, R>;
|
|
48
45
|
_c12: ResolvedConfig<ApibaraConfig<T, R>> | ConfigWatcher<ApibaraConfig<T, R>>;
|
|
49
|
-
sink: {
|
|
50
|
-
default: () => Sink;
|
|
51
|
-
[key: string]: () => Sink;
|
|
52
|
-
};
|
|
53
46
|
presets?: T;
|
|
54
47
|
preset?: keyof T;
|
|
55
48
|
debug: boolean;
|
|
@@ -57,31 +50,44 @@ interface ApibaraOptions<T extends Record<string, DeepPartial<ApibaraConfig<T, R
|
|
|
57
50
|
rootDir: string;
|
|
58
51
|
buildDir: string;
|
|
59
52
|
outputDir: string;
|
|
53
|
+
indexersDir: string;
|
|
60
54
|
dev: boolean;
|
|
61
|
-
watchOptions: WatchOptions;
|
|
55
|
+
watchOptions: WatchOptions["watch"];
|
|
62
56
|
hooks: NestedHooks<ApibaraHooks>;
|
|
63
|
-
|
|
57
|
+
logger?: LoggerFactory;
|
|
58
|
+
rolldownConfig?: Partial<RolldownOptions>;
|
|
59
|
+
/**
|
|
60
|
+
* @deprecated Use rolldownConfig instead. This option will be removed in future releases.
|
|
61
|
+
*/
|
|
62
|
+
rollupConfig?: unknown;
|
|
63
|
+
sourceMap?: boolean;
|
|
64
64
|
entry: string;
|
|
65
|
-
|
|
65
|
+
node: boolean;
|
|
66
|
+
exportConditions?: string[];
|
|
66
67
|
typescript: {
|
|
67
68
|
strict?: boolean;
|
|
68
69
|
internalPaths?: boolean;
|
|
69
70
|
generateRuntimeConfigTypes?: boolean;
|
|
70
|
-
generateTsConfig?: boolean;
|
|
71
|
-
/** the path of the generated `tsconfig.json`, relative to buildDir */
|
|
72
|
-
tsconfigPath: string;
|
|
73
|
-
tsConfig?: Partial<TSConfig>;
|
|
74
71
|
};
|
|
75
72
|
}
|
|
76
73
|
|
|
74
|
+
type IndexerDefinition = {
|
|
75
|
+
name: string;
|
|
76
|
+
indexer: string;
|
|
77
|
+
};
|
|
77
78
|
interface Apibara {
|
|
78
79
|
options: ApibaraOptions;
|
|
79
80
|
hooks: Hookable<ApibaraHooks>;
|
|
81
|
+
indexers: IndexerDefinition[];
|
|
80
82
|
logger: ConsolaInstance;
|
|
81
83
|
close: () => Promise<void>;
|
|
82
84
|
updateConfig: (config: ApibaraDynamicConfig) => void | Promise<void>;
|
|
83
85
|
}
|
|
84
86
|
|
|
87
|
+
type RolldownConfig = InputOptions & {
|
|
88
|
+
output: OutputOptions;
|
|
89
|
+
};
|
|
90
|
+
|
|
85
91
|
type ApibaraRuntimeConfig = Record<string, unknown>;
|
|
86
92
|
|
|
87
|
-
export type { Apibara, ApibaraConfig, ApibaraDynamicConfig, ApibaraHooks, ApibaraOptions, ApibaraRuntimeConfig, DeepPartial, LoadConfigOptions,
|
|
93
|
+
export type { Apibara, ApibaraConfig, ApibaraDynamicConfig, ApibaraHooks, ApibaraOptions, ApibaraRuntimeConfig, DeepPartial, IndexerDefinition, LoadConfigOptions, LoggerFactory, RolldownConfig };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,39 +1,36 @@
|
|
|
1
1
|
import { ConsolaInstance } from 'consola';
|
|
2
2
|
import { NestedHooks, Hookable } from 'hookable';
|
|
3
|
-
import {
|
|
3
|
+
import { ConsolaReporter } from '@apibara/indexer/plugins';
|
|
4
4
|
import { C12InputConfig, WatchConfigOptions, ResolvedConfig, ConfigWatcher } from 'c12';
|
|
5
|
-
import { WatchOptions } from '
|
|
6
|
-
import { TSConfig } from 'pkg-types';
|
|
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:
|
|
21
|
-
"
|
|
14
|
+
"dev:restart": () => Promise<void>;
|
|
15
|
+
"dev:reload": () => Promise<void>;
|
|
16
|
+
"rolldown:reload": () => Promise<void>;
|
|
22
17
|
restart: () => void;
|
|
23
18
|
close: () => void;
|
|
24
19
|
}
|
|
25
20
|
|
|
21
|
+
type LoggerFactory = ({ indexer, preset, }: {
|
|
22
|
+
indexer: string;
|
|
23
|
+
indexers: string[];
|
|
24
|
+
preset?: string;
|
|
25
|
+
}) => ConsolaReporter;
|
|
26
26
|
/**
|
|
27
27
|
* Apibara Config type (apibara.config)
|
|
28
28
|
*/
|
|
29
|
-
interface ApibaraConfig<T extends Record<string, DeepPartial<ApibaraConfig<T, R>>> =
|
|
30
|
-
sink?: {
|
|
31
|
-
default: () => Sink;
|
|
32
|
-
[key: string]: () => Sink;
|
|
33
|
-
};
|
|
29
|
+
interface ApibaraConfig<T extends Record<string, DeepPartial<Pick<ApibaraConfig<T, R>, "runtimeConfig">>> = Record<string, never>, R extends Record<string, unknown> = Record<string, never>> extends Partial<Omit<ApibaraOptions<T, R>, "preset" | "presets" | "dev">>, C12InputConfig<ApibaraConfig<T, R>> {
|
|
34
30
|
runtimeConfig?: R;
|
|
35
31
|
presets?: T;
|
|
36
32
|
preset?: keyof T;
|
|
33
|
+
logger?: LoggerFactory;
|
|
37
34
|
}
|
|
38
35
|
type ApibaraDynamicConfig = Pick<ApibaraConfig, "runtimeConfig">;
|
|
39
36
|
/**
|
|
@@ -43,13 +40,9 @@ interface LoadConfigOptions {
|
|
|
43
40
|
watch?: boolean;
|
|
44
41
|
c12?: WatchConfigOptions;
|
|
45
42
|
}
|
|
46
|
-
interface ApibaraOptions<T extends Record<string, DeepPartial<ApibaraConfig<T, R>>> =
|
|
43
|
+
interface ApibaraOptions<T extends Record<string, DeepPartial<Pick<ApibaraConfig<T, R>, "runtimeConfig">>> = Record<string, never>, R extends Record<string, unknown> = Record<string, never>> {
|
|
47
44
|
_config: ApibaraConfig<T, R>;
|
|
48
45
|
_c12: ResolvedConfig<ApibaraConfig<T, R>> | ConfigWatcher<ApibaraConfig<T, R>>;
|
|
49
|
-
sink: {
|
|
50
|
-
default: () => Sink;
|
|
51
|
-
[key: string]: () => Sink;
|
|
52
|
-
};
|
|
53
46
|
presets?: T;
|
|
54
47
|
preset?: keyof T;
|
|
55
48
|
debug: boolean;
|
|
@@ -57,31 +50,44 @@ interface ApibaraOptions<T extends Record<string, DeepPartial<ApibaraConfig<T, R
|
|
|
57
50
|
rootDir: string;
|
|
58
51
|
buildDir: string;
|
|
59
52
|
outputDir: string;
|
|
53
|
+
indexersDir: string;
|
|
60
54
|
dev: boolean;
|
|
61
|
-
watchOptions: WatchOptions;
|
|
55
|
+
watchOptions: WatchOptions["watch"];
|
|
62
56
|
hooks: NestedHooks<ApibaraHooks>;
|
|
63
|
-
|
|
57
|
+
logger?: LoggerFactory;
|
|
58
|
+
rolldownConfig?: Partial<RolldownOptions>;
|
|
59
|
+
/**
|
|
60
|
+
* @deprecated Use rolldownConfig instead. This option will be removed in future releases.
|
|
61
|
+
*/
|
|
62
|
+
rollupConfig?: unknown;
|
|
63
|
+
sourceMap?: boolean;
|
|
64
64
|
entry: string;
|
|
65
|
-
|
|
65
|
+
node: boolean;
|
|
66
|
+
exportConditions?: string[];
|
|
66
67
|
typescript: {
|
|
67
68
|
strict?: boolean;
|
|
68
69
|
internalPaths?: boolean;
|
|
69
70
|
generateRuntimeConfigTypes?: boolean;
|
|
70
|
-
generateTsConfig?: boolean;
|
|
71
|
-
/** the path of the generated `tsconfig.json`, relative to buildDir */
|
|
72
|
-
tsconfigPath: string;
|
|
73
|
-
tsConfig?: Partial<TSConfig>;
|
|
74
71
|
};
|
|
75
72
|
}
|
|
76
73
|
|
|
74
|
+
type IndexerDefinition = {
|
|
75
|
+
name: string;
|
|
76
|
+
indexer: string;
|
|
77
|
+
};
|
|
77
78
|
interface Apibara {
|
|
78
79
|
options: ApibaraOptions;
|
|
79
80
|
hooks: Hookable<ApibaraHooks>;
|
|
81
|
+
indexers: IndexerDefinition[];
|
|
80
82
|
logger: ConsolaInstance;
|
|
81
83
|
close: () => Promise<void>;
|
|
82
84
|
updateConfig: (config: ApibaraDynamicConfig) => void | Promise<void>;
|
|
83
85
|
}
|
|
84
86
|
|
|
87
|
+
type RolldownConfig = InputOptions & {
|
|
88
|
+
output: OutputOptions;
|
|
89
|
+
};
|
|
90
|
+
|
|
85
91
|
type ApibaraRuntimeConfig = Record<string, unknown>;
|
|
86
92
|
|
|
87
|
-
export type { Apibara, ApibaraConfig, ApibaraDynamicConfig, ApibaraHooks, ApibaraOptions, ApibaraRuntimeConfig, DeepPartial, LoadConfigOptions,
|
|
93
|
+
export type { Apibara, ApibaraConfig, ApibaraDynamicConfig, ApibaraHooks, ApibaraOptions, ApibaraRuntimeConfig, DeepPartial, IndexerDefinition, LoadConfigOptions, LoggerFactory, RolldownConfig };
|