apibara 2.0.0-beta.4 → 2.0.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/build.mjs +28 -0
- package/dist/chunks/dev.mjs +100 -0
- package/dist/chunks/prepare.mjs +21 -0
- package/dist/chunks/start.mjs +56 -0
- package/dist/cli/index.d.mts +5 -0
- package/dist/cli/index.d.ts +5 -0
- package/dist/cli/index.mjs +19 -0
- package/dist/config/index.d.mts +5 -0
- package/dist/config/index.d.ts +5 -0
- package/dist/config/index.mjs +5 -0
- package/dist/core/index.d.mts +11 -0
- package/dist/core/index.d.ts +11 -0
- package/dist/core/index.mjs +310 -0
- package/dist/hooks/index.d.mts +5 -0
- package/dist/hooks/index.d.ts +5 -0
- package/dist/hooks/index.mjs +5 -0
- package/dist/rollup/index.d.mts +5 -0
- package/dist/rollup/index.d.ts +5 -0
- package/dist/rollup/index.mjs +150 -0
- package/dist/runtime/dev.d.ts +3 -0
- package/dist/runtime/dev.mjs +55 -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 +56 -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 +41 -0
- package/dist/shared/apibara.1b515d04.mjs +8 -0
- package/dist/types/index.d.mts +90 -0
- package/dist/types/index.d.ts +90 -0
- package/dist/types/index.mjs +1 -0
- package/package.json +28 -8
- package/runtime-meta.d.ts +2 -0
- package/runtime-meta.mjs +7 -0
- package/src/cli/commands/build.ts +5 -3
- package/src/cli/commands/dev.ts +29 -19
- package/src/cli/commands/prepare.ts +0 -2
- package/src/cli/commands/start.ts +61 -0
- package/src/cli/index.ts +1 -0
- package/src/config/index.ts +5 -4
- package/src/core/apibara.ts +4 -2
- package/src/core/build/build.ts +2 -0
- package/src/core/build/dev.ts +1 -0
- package/src/core/build/prepare.ts +5 -2
- package/src/core/build/prod.ts +10 -6
- package/src/core/build/types.ts +4 -95
- package/src/core/config/defaults.ts +1 -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 +2 -3
- package/src/core/path.ts +11 -0
- package/src/core/scan.ts +40 -0
- package/src/rollup/config.ts +67 -188
- package/src/rollup/plugins/config.ts +12 -0
- package/src/rollup/plugins/esm-shim.ts +69 -0
- package/src/rollup/plugins/indexers.ts +17 -0
- package/src/runtime/dev.ts +64 -0
- package/src/runtime/index.ts +2 -0
- package/src/runtime/internal/app.ts +78 -0
- package/src/runtime/internal/logger.ts +70 -0
- package/src/runtime/start.ts +48 -0
- package/src/types/apibara.ts +8 -0
- package/src/types/config.ts +28 -27
- package/src/types/hooks.ts +1 -0
- package/src/types/virtual/config.d.ts +3 -0
- package/src/types/virtual/indexers.d.ts +10 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { builtinModules } from 'node:module';
|
|
2
|
+
import commonjs from '@rollup/plugin-commonjs';
|
|
3
|
+
import json from '@rollup/plugin-json';
|
|
4
|
+
import { nodeResolve } from '@rollup/plugin-node-resolve';
|
|
5
|
+
import { join } from 'pathe';
|
|
6
|
+
import defu from 'defu';
|
|
7
|
+
import virtual from '@rollup/plugin-virtual';
|
|
8
|
+
import MagicString from 'magic-string';
|
|
9
|
+
import { hash } from 'ohash';
|
|
10
|
+
|
|
11
|
+
function appConfig(apibara) {
|
|
12
|
+
return virtual({
|
|
13
|
+
"#apibara-internal-virtual/config": `
|
|
14
|
+
import * as projectConfig from '${apibara.options._c12.configFile}';
|
|
15
|
+
|
|
16
|
+
export const config = projectConfig.default;
|
|
17
|
+
`
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function esmShim() {
|
|
22
|
+
const ESMShim = `
|
|
23
|
+
// -- Shims --
|
|
24
|
+
import cjsUrl from 'node:url';
|
|
25
|
+
import cjsPath from 'node:path';
|
|
26
|
+
const __filename = cjsUrl.fileURLToPath(import.meta.url);
|
|
27
|
+
const __dirname = cjsPath.dirname(__filename);
|
|
28
|
+
// -- End Shims --
|
|
29
|
+
`;
|
|
30
|
+
const CJSyntaxRegex = /__filename|__dirname/;
|
|
31
|
+
return {
|
|
32
|
+
name: "esm-shim",
|
|
33
|
+
renderChunk(code, _chunk, opts) {
|
|
34
|
+
if (opts.format === "es") {
|
|
35
|
+
if (code.includes(ESMShim) || !CJSyntaxRegex.test(code)) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
let endIndexOfLastImport = -1;
|
|
39
|
+
for (const match of code.matchAll(/^import\s.*';$/gm)) {
|
|
40
|
+
if (match.length === 0 || typeof match.index !== "number") {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
endIndexOfLastImport = match.index + match[0].length;
|
|
44
|
+
}
|
|
45
|
+
const s = new MagicString(code);
|
|
46
|
+
s.appendRight(endIndexOfLastImport, ESMShim);
|
|
47
|
+
const sourceMap = s.generateMap({
|
|
48
|
+
includeContent: true
|
|
49
|
+
});
|
|
50
|
+
let sourcesContent;
|
|
51
|
+
if (Array.isArray(sourceMap.sourcesContent)) {
|
|
52
|
+
sourcesContent = [];
|
|
53
|
+
for (let i = 0; i < sourceMap.sourcesContent.length; i++) {
|
|
54
|
+
const content = sourceMap.sourcesContent[i];
|
|
55
|
+
if (typeof content === "string") {
|
|
56
|
+
sourcesContent.push(content);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
code: s.toString(),
|
|
62
|
+
map: {
|
|
63
|
+
...sourceMap,
|
|
64
|
+
sourcesContent
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function indexers(apibara) {
|
|
74
|
+
const indexers2 = [...new Set(apibara.indexers)];
|
|
75
|
+
return virtual({
|
|
76
|
+
"#apibara-internal-virtual/indexers": `
|
|
77
|
+
${indexers2.map((i) => `import _${hash(i)} from '${i.indexer}';`).join("\n")}
|
|
78
|
+
|
|
79
|
+
export const indexers = [
|
|
80
|
+
${indexers2.map((i) => `{ name: "${i.name}", indexer: _${hash(i)} }`).join(",\n")}
|
|
81
|
+
];
|
|
82
|
+
`
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const runtimeDependencies = ["better-sqlite3", "@electric-sql/pglite"];
|
|
87
|
+
function getRollupConfig(apibara) {
|
|
88
|
+
const extensions = [
|
|
89
|
+
".ts",
|
|
90
|
+
".mjs",
|
|
91
|
+
".js",
|
|
92
|
+
".json",
|
|
93
|
+
".node",
|
|
94
|
+
".tsx",
|
|
95
|
+
".jsx"
|
|
96
|
+
];
|
|
97
|
+
const rollupConfig = defu(
|
|
98
|
+
// biome-ignore lint/suspicious/noExplicitAny: apibara.options.rollupConfig is typed
|
|
99
|
+
apibara.options.rollupConfig,
|
|
100
|
+
{
|
|
101
|
+
input: apibara.options.entry,
|
|
102
|
+
output: {
|
|
103
|
+
dir: join(apibara.options.outputDir || "./.apibara/build"),
|
|
104
|
+
format: "esm",
|
|
105
|
+
exports: "auto",
|
|
106
|
+
entryFileNames: "[name].mjs",
|
|
107
|
+
chunkFileNames: "chunks/[name]-[hash].mjs",
|
|
108
|
+
generatedCode: {
|
|
109
|
+
constBindings: true
|
|
110
|
+
},
|
|
111
|
+
sourcemap: true,
|
|
112
|
+
sourcemapExcludeSources: true,
|
|
113
|
+
sourcemapIgnoreList(relativePath, sourcemapPath) {
|
|
114
|
+
return relativePath.includes("node_modules");
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
plugins: [],
|
|
118
|
+
onwarn(warning, rollupWarn) {
|
|
119
|
+
if (!["CIRCULAR_DEPENDENCY", "EVAL", "THIS_IS_UNDEFINED"].includes(
|
|
120
|
+
warning.code || ""
|
|
121
|
+
) && !warning.message.includes("Unsupported source map comment") && !warning.message.includes("@__PURE__") && !warning.message.includes("/*#__PURE__*/")) {
|
|
122
|
+
rollupWarn(warning);
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
treeshake: true,
|
|
126
|
+
external: [...builtinModules, ...runtimeDependencies]
|
|
127
|
+
}
|
|
128
|
+
);
|
|
129
|
+
rollupConfig.plugins.push(esmShim());
|
|
130
|
+
rollupConfig.plugins.push(json());
|
|
131
|
+
rollupConfig.plugins.push(
|
|
132
|
+
commonjs({
|
|
133
|
+
strictRequires: true,
|
|
134
|
+
requireReturnsDefault: "auto",
|
|
135
|
+
...apibara.options.commonJS
|
|
136
|
+
})
|
|
137
|
+
);
|
|
138
|
+
rollupConfig.plugins.push(
|
|
139
|
+
nodeResolve({
|
|
140
|
+
extensions,
|
|
141
|
+
preferBuiltins: true,
|
|
142
|
+
mainFields: ["main"]
|
|
143
|
+
})
|
|
144
|
+
);
|
|
145
|
+
rollupConfig.plugins.push(indexers(apibara));
|
|
146
|
+
rollupConfig.plugins.push(appConfig(apibara));
|
|
147
|
+
return rollupConfig;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export { getRollupConfig };
|
|
@@ -0,0 +1,55 @@
|
|
|
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
|
+
const client = createClient(
|
|
37
|
+
indexerInstance.streamConfig,
|
|
38
|
+
indexerInstance.options.streamUrl
|
|
39
|
+
);
|
|
40
|
+
await runWithReconnect(client, indexerInstance);
|
|
41
|
+
})
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
export const mainCli = defineCommand({
|
|
46
|
+
meta: {
|
|
47
|
+
name: "indexer-dev-runner",
|
|
48
|
+
description: "Run indexer in dev mode"
|
|
49
|
+
},
|
|
50
|
+
subCommands: {
|
|
51
|
+
start: () => startCommand
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
runMain(mainCli);
|
|
55
|
+
export default {};
|
|
@@ -0,0 +1,56 @@
|
|
|
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 { config } from "#apibara-internal-virtual/config";
|
|
10
|
+
import { indexers } from "#apibara-internal-virtual/indexers";
|
|
11
|
+
import { createLogger } from "./logger.mjs";
|
|
12
|
+
export const availableIndexers = indexers.map((i) => i.name);
|
|
13
|
+
export function createIndexer(indexerName, preset) {
|
|
14
|
+
let runtimeConfig = { ...config.runtimeConfig };
|
|
15
|
+
if (preset) {
|
|
16
|
+
if (config.presets === void 0) {
|
|
17
|
+
throw new Error(
|
|
18
|
+
`Specified preset "${preset}" but no presets were defined`
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
if (config.presets[preset] === void 0) {
|
|
22
|
+
throw new Error(`Specified preset "${preset}" but it was not defined`);
|
|
23
|
+
}
|
|
24
|
+
const presetValue = config.presets[preset];
|
|
25
|
+
runtimeConfig = { ...runtimeConfig, ...presetValue.runtimeConfig };
|
|
26
|
+
}
|
|
27
|
+
const indexerDefinition = indexers.find((i) => i.name === indexerName);
|
|
28
|
+
if (indexerDefinition === void 0) {
|
|
29
|
+
throw new Error(
|
|
30
|
+
`Specified indexer "${indexerName}" but it was not defined`
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
const definition = typeof indexerDefinition.indexer === "function" ? indexerDefinition.indexer(runtimeConfig) : indexerDefinition.indexer;
|
|
34
|
+
let reporter = createLogger({
|
|
35
|
+
indexer: indexerName,
|
|
36
|
+
preset,
|
|
37
|
+
indexers: availableIndexers
|
|
38
|
+
});
|
|
39
|
+
if (config.logger) {
|
|
40
|
+
reporter = config.logger({
|
|
41
|
+
indexer: indexerName,
|
|
42
|
+
preset,
|
|
43
|
+
indexers: availableIndexers
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
definition.plugins = [
|
|
47
|
+
internalContext({
|
|
48
|
+
indexerName,
|
|
49
|
+
availableIndexers
|
|
50
|
+
}),
|
|
51
|
+
inMemoryPersistence(),
|
|
52
|
+
...definition.plugins ?? [],
|
|
53
|
+
logger({ logger: reporter })
|
|
54
|
+
];
|
|
55
|
+
return _createIndexer(definition);
|
|
56
|
+
}
|
|
@@ -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,41 @@
|
|
|
1
|
+
import { runWithReconnect } from "@apibara/indexer";
|
|
2
|
+
import { createClient } from "@apibara/protocol";
|
|
3
|
+
import { defineCommand, runMain } from "citty";
|
|
4
|
+
import { createIndexer } from "./internal/app.mjs";
|
|
5
|
+
const startCommand = defineCommand({
|
|
6
|
+
meta: {
|
|
7
|
+
name: "start",
|
|
8
|
+
description: "Start the indexer"
|
|
9
|
+
},
|
|
10
|
+
args: {
|
|
11
|
+
indexer: {
|
|
12
|
+
type: "string",
|
|
13
|
+
description: "Indexer name",
|
|
14
|
+
required: true
|
|
15
|
+
},
|
|
16
|
+
preset: {
|
|
17
|
+
type: "string",
|
|
18
|
+
description: "Preset to use"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
async run({ args }) {
|
|
22
|
+
const { indexer, preset } = args;
|
|
23
|
+
const indexerInstance = createIndexer(indexer, preset);
|
|
24
|
+
const client = createClient(
|
|
25
|
+
indexerInstance.streamConfig,
|
|
26
|
+
indexerInstance.options.streamUrl
|
|
27
|
+
);
|
|
28
|
+
await runWithReconnect(client, indexerInstance);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
export const mainCli = defineCommand({
|
|
32
|
+
meta: {
|
|
33
|
+
name: "indexer-runner",
|
|
34
|
+
description: "Run an indexer"
|
|
35
|
+
},
|
|
36
|
+
subCommands: {
|
|
37
|
+
start: () => startCommand
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
runMain(mainCli);
|
|
41
|
+
export default {};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { ConsolaInstance } from 'consola';
|
|
2
|
+
import { NestedHooks, Hookable } from 'hookable';
|
|
3
|
+
import { ConsolaReporter } from '@apibara/indexer/plugins';
|
|
4
|
+
import { RollupCommonJSOptions } from '@rollup/plugin-commonjs';
|
|
5
|
+
import { C12InputConfig, WatchConfigOptions, ResolvedConfig, ConfigWatcher } from 'c12';
|
|
6
|
+
import { WatchOptions } from 'chokidar';
|
|
7
|
+
import { InputOptions, OutputOptions } from 'rollup';
|
|
8
|
+
|
|
9
|
+
type DeepPartial<T> = T extends Record<string, any> ? {
|
|
10
|
+
[P in keyof T]?: DeepPartial<T[P]> | T[P];
|
|
11
|
+
} : T;
|
|
12
|
+
|
|
13
|
+
type RollupConfig = InputOptions & {
|
|
14
|
+
output: OutputOptions;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
interface ApibaraHooks {
|
|
18
|
+
"rollup:before": (apibara: Apibara, rollupConfig: RollupConfig) => void;
|
|
19
|
+
compiled: (apibara: Apibara) => void;
|
|
20
|
+
"dev:restart": () => void;
|
|
21
|
+
"dev:reload": () => void;
|
|
22
|
+
"rollup:reload": () => void;
|
|
23
|
+
restart: () => void;
|
|
24
|
+
close: () => void;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
type LoggerFactory = ({ indexer, preset, }: {
|
|
28
|
+
indexer: string;
|
|
29
|
+
indexers: string[];
|
|
30
|
+
preset?: string;
|
|
31
|
+
}) => ConsolaReporter;
|
|
32
|
+
/**
|
|
33
|
+
* Apibara Config type (apibara.config)
|
|
34
|
+
*/
|
|
35
|
+
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>> {
|
|
36
|
+
runtimeConfig?: R;
|
|
37
|
+
presets?: T;
|
|
38
|
+
preset?: keyof T;
|
|
39
|
+
logger?: LoggerFactory;
|
|
40
|
+
}
|
|
41
|
+
type ApibaraDynamicConfig = Pick<ApibaraConfig, "runtimeConfig">;
|
|
42
|
+
/**
|
|
43
|
+
* Config loader options
|
|
44
|
+
*/
|
|
45
|
+
interface LoadConfigOptions {
|
|
46
|
+
watch?: boolean;
|
|
47
|
+
c12?: WatchConfigOptions;
|
|
48
|
+
}
|
|
49
|
+
interface ApibaraOptions<T extends Record<string, DeepPartial<Pick<ApibaraConfig<T, R>, "runtimeConfig">>> = Record<string, never>, R extends Record<string, unknown> = Record<string, never>> {
|
|
50
|
+
_config: ApibaraConfig<T, R>;
|
|
51
|
+
_c12: ResolvedConfig<ApibaraConfig<T, R>> | ConfigWatcher<ApibaraConfig<T, R>>;
|
|
52
|
+
presets?: T;
|
|
53
|
+
preset?: keyof T;
|
|
54
|
+
debug: boolean;
|
|
55
|
+
runtimeConfig: R;
|
|
56
|
+
rootDir: string;
|
|
57
|
+
buildDir: string;
|
|
58
|
+
outputDir: string;
|
|
59
|
+
indexersDir: string;
|
|
60
|
+
dev: boolean;
|
|
61
|
+
watchOptions: WatchOptions;
|
|
62
|
+
hooks: NestedHooks<ApibaraHooks>;
|
|
63
|
+
logger?: LoggerFactory;
|
|
64
|
+
rollupConfig?: Partial<RollupConfig>;
|
|
65
|
+
sourceMap?: boolean;
|
|
66
|
+
entry: string;
|
|
67
|
+
commonJS?: RollupCommonJSOptions;
|
|
68
|
+
typescript: {
|
|
69
|
+
strict?: boolean;
|
|
70
|
+
internalPaths?: boolean;
|
|
71
|
+
generateRuntimeConfigTypes?: boolean;
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
type IndexerDefinition = {
|
|
76
|
+
name: string;
|
|
77
|
+
indexer: string;
|
|
78
|
+
};
|
|
79
|
+
interface Apibara {
|
|
80
|
+
options: ApibaraOptions;
|
|
81
|
+
hooks: Hookable<ApibaraHooks>;
|
|
82
|
+
indexers: IndexerDefinition[];
|
|
83
|
+
logger: ConsolaInstance;
|
|
84
|
+
close: () => Promise<void>;
|
|
85
|
+
updateConfig: (config: ApibaraDynamicConfig) => void | Promise<void>;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
type ApibaraRuntimeConfig = Record<string, unknown>;
|
|
89
|
+
|
|
90
|
+
export type { Apibara, ApibaraConfig, ApibaraDynamicConfig, ApibaraHooks, ApibaraOptions, ApibaraRuntimeConfig, DeepPartial, IndexerDefinition, LoadConfigOptions, LoggerFactory, RollupConfig };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { ConsolaInstance } from 'consola';
|
|
2
|
+
import { NestedHooks, Hookable } from 'hookable';
|
|
3
|
+
import { ConsolaReporter } from '@apibara/indexer/plugins';
|
|
4
|
+
import { RollupCommonJSOptions } from '@rollup/plugin-commonjs';
|
|
5
|
+
import { C12InputConfig, WatchConfigOptions, ResolvedConfig, ConfigWatcher } from 'c12';
|
|
6
|
+
import { WatchOptions } from 'chokidar';
|
|
7
|
+
import { InputOptions, OutputOptions } from 'rollup';
|
|
8
|
+
|
|
9
|
+
type DeepPartial<T> = T extends Record<string, any> ? {
|
|
10
|
+
[P in keyof T]?: DeepPartial<T[P]> | T[P];
|
|
11
|
+
} : T;
|
|
12
|
+
|
|
13
|
+
type RollupConfig = InputOptions & {
|
|
14
|
+
output: OutputOptions;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
interface ApibaraHooks {
|
|
18
|
+
"rollup:before": (apibara: Apibara, rollupConfig: RollupConfig) => void;
|
|
19
|
+
compiled: (apibara: Apibara) => void;
|
|
20
|
+
"dev:restart": () => void;
|
|
21
|
+
"dev:reload": () => void;
|
|
22
|
+
"rollup:reload": () => void;
|
|
23
|
+
restart: () => void;
|
|
24
|
+
close: () => void;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
type LoggerFactory = ({ indexer, preset, }: {
|
|
28
|
+
indexer: string;
|
|
29
|
+
indexers: string[];
|
|
30
|
+
preset?: string;
|
|
31
|
+
}) => ConsolaReporter;
|
|
32
|
+
/**
|
|
33
|
+
* Apibara Config type (apibara.config)
|
|
34
|
+
*/
|
|
35
|
+
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>> {
|
|
36
|
+
runtimeConfig?: R;
|
|
37
|
+
presets?: T;
|
|
38
|
+
preset?: keyof T;
|
|
39
|
+
logger?: LoggerFactory;
|
|
40
|
+
}
|
|
41
|
+
type ApibaraDynamicConfig = Pick<ApibaraConfig, "runtimeConfig">;
|
|
42
|
+
/**
|
|
43
|
+
* Config loader options
|
|
44
|
+
*/
|
|
45
|
+
interface LoadConfigOptions {
|
|
46
|
+
watch?: boolean;
|
|
47
|
+
c12?: WatchConfigOptions;
|
|
48
|
+
}
|
|
49
|
+
interface ApibaraOptions<T extends Record<string, DeepPartial<Pick<ApibaraConfig<T, R>, "runtimeConfig">>> = Record<string, never>, R extends Record<string, unknown> = Record<string, never>> {
|
|
50
|
+
_config: ApibaraConfig<T, R>;
|
|
51
|
+
_c12: ResolvedConfig<ApibaraConfig<T, R>> | ConfigWatcher<ApibaraConfig<T, R>>;
|
|
52
|
+
presets?: T;
|
|
53
|
+
preset?: keyof T;
|
|
54
|
+
debug: boolean;
|
|
55
|
+
runtimeConfig: R;
|
|
56
|
+
rootDir: string;
|
|
57
|
+
buildDir: string;
|
|
58
|
+
outputDir: string;
|
|
59
|
+
indexersDir: string;
|
|
60
|
+
dev: boolean;
|
|
61
|
+
watchOptions: WatchOptions;
|
|
62
|
+
hooks: NestedHooks<ApibaraHooks>;
|
|
63
|
+
logger?: LoggerFactory;
|
|
64
|
+
rollupConfig?: Partial<RollupConfig>;
|
|
65
|
+
sourceMap?: boolean;
|
|
66
|
+
entry: string;
|
|
67
|
+
commonJS?: RollupCommonJSOptions;
|
|
68
|
+
typescript: {
|
|
69
|
+
strict?: boolean;
|
|
70
|
+
internalPaths?: boolean;
|
|
71
|
+
generateRuntimeConfigTypes?: boolean;
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
type IndexerDefinition = {
|
|
76
|
+
name: string;
|
|
77
|
+
indexer: string;
|
|
78
|
+
};
|
|
79
|
+
interface Apibara {
|
|
80
|
+
options: ApibaraOptions;
|
|
81
|
+
hooks: Hookable<ApibaraHooks>;
|
|
82
|
+
indexers: IndexerDefinition[];
|
|
83
|
+
logger: ConsolaInstance;
|
|
84
|
+
close: () => Promise<void>;
|
|
85
|
+
updateConfig: (config: ApibaraDynamicConfig) => void | Promise<void>;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
type ApibaraRuntimeConfig = Record<string, unknown>;
|
|
89
|
+
|
|
90
|
+
export type { Apibara, ApibaraConfig, ApibaraDynamicConfig, ApibaraHooks, ApibaraOptions, ApibaraRuntimeConfig, DeepPartial, IndexerDefinition, LoadConfigOptions, LoggerFactory, RollupConfig };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
package/package.json
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "apibara",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.40",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"source": "./src/core/index.ts",
|
|
6
5
|
"main": "./dist/core/index.mjs",
|
|
7
6
|
"exports": {
|
|
8
7
|
".": {
|
|
@@ -32,6 +31,22 @@
|
|
|
32
31
|
"./hooks": {
|
|
33
32
|
"types": "./dist/hooks/index.d.ts",
|
|
34
33
|
"import": "./dist/hooks/index.mjs"
|
|
34
|
+
},
|
|
35
|
+
"./runtime": {
|
|
36
|
+
"types": "./dist/runtime/index.d.ts",
|
|
37
|
+
"import": "./dist/runtime/index.mjs"
|
|
38
|
+
},
|
|
39
|
+
"./runtime/meta": {
|
|
40
|
+
"types": "./runtime-meta.d.ts",
|
|
41
|
+
"import": "./runtime-meta.mjs"
|
|
42
|
+
},
|
|
43
|
+
"./runtime/*": {
|
|
44
|
+
"types": "./dist/runtime/*.d.ts",
|
|
45
|
+
"import": "./dist/runtime/*.mjs"
|
|
46
|
+
},
|
|
47
|
+
"./dist/runtime/*": {
|
|
48
|
+
"types": "./dist/runtime/*.d.ts",
|
|
49
|
+
"import": "./dist/runtime/*.mjs"
|
|
35
50
|
}
|
|
36
51
|
},
|
|
37
52
|
"bin": {
|
|
@@ -40,6 +55,8 @@
|
|
|
40
55
|
"files": [
|
|
41
56
|
"dist",
|
|
42
57
|
"src",
|
|
58
|
+
"runtime-meta.d.ts",
|
|
59
|
+
"runtime-meta.mjs",
|
|
43
60
|
"README.md"
|
|
44
61
|
],
|
|
45
62
|
"scripts": {
|
|
@@ -48,13 +65,14 @@
|
|
|
48
65
|
"typecheck": "tsc --noEmit",
|
|
49
66
|
"lint:fix": "pnpm lint --write",
|
|
50
67
|
"format": "biome format . --write",
|
|
51
|
-
"playground": "JITI_ESM_RESOLVE=1 NODE_OPTIONS=\"--enable-source-maps\" jiti ./src/cli/index.ts",
|
|
68
|
+
"playground": "JITI_ESM_RESOLVE=1 CONSOLA_LEVEL=debug NODE_OPTIONS=\"--enable-source-maps\" jiti ./src/cli/index.ts",
|
|
52
69
|
"playground:prepare": "pnpm playground prepare --dir playground",
|
|
53
70
|
"playground:dev": "pnpm playground dev --dir playground",
|
|
54
71
|
"playground:build": "pnpm playground build --dir playground",
|
|
55
|
-
"playground:start": "
|
|
72
|
+
"playground:start": "pnpm playground start --dir playground --indexer starknet"
|
|
56
73
|
},
|
|
57
74
|
"devDependencies": {
|
|
75
|
+
"@apibara/starknet": "2.0.0-beta.40",
|
|
58
76
|
"@types/fs-extra": "^11.0.4",
|
|
59
77
|
"@types/node": "^20.14.0",
|
|
60
78
|
"jiti": "^1.21.0",
|
|
@@ -64,14 +82,13 @@
|
|
|
64
82
|
"vitest": "^1.6.0"
|
|
65
83
|
},
|
|
66
84
|
"dependencies": {
|
|
67
|
-
"@apibara/
|
|
68
|
-
"@apibara/
|
|
69
|
-
"@apibara/protocol": "2.0.0-beta.4",
|
|
70
|
-
"@apibara/starknet": "2.0.0-beta.4",
|
|
85
|
+
"@apibara/indexer": "2.0.0-beta.40",
|
|
86
|
+
"@apibara/protocol": "2.0.0-beta.40",
|
|
71
87
|
"@rollup/plugin-commonjs": "^26.0.1",
|
|
72
88
|
"@rollup/plugin-json": "^6.1.0",
|
|
73
89
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
74
90
|
"@rollup/plugin-typescript": "^11.1.6",
|
|
91
|
+
"@rollup/plugin-virtual": "^3.0.2",
|
|
75
92
|
"c12": "^1.11.1",
|
|
76
93
|
"chokidar": "^3.6.0",
|
|
77
94
|
"citty": "^0.1.6",
|
|
@@ -81,10 +98,13 @@
|
|
|
81
98
|
"fs-extra": "^11.2.0",
|
|
82
99
|
"hookable": "^5.5.3",
|
|
83
100
|
"klona": "^2.0.6",
|
|
101
|
+
"magic-string": "^0.30.12",
|
|
102
|
+
"ohash": "^1.1.4",
|
|
84
103
|
"pathe": "^1.1.2",
|
|
85
104
|
"perfect-debounce": "^1.0.0",
|
|
86
105
|
"pkg-types": "^1.1.3",
|
|
87
106
|
"rollup": "^4.18.1",
|
|
107
|
+
"rollup-plugin-esbuild": "^6.1.1",
|
|
88
108
|
"tslib": "^2.6.3",
|
|
89
109
|
"untyped": "^1.4.2"
|
|
90
110
|
}
|