forked from namehash/ensnode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathponder.config.ts
More file actions
62 lines (51 loc) · 2.42 KB
/
ponder.config.ts
File metadata and controls
62 lines (51 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import config from "@/config";
import type { ENSIndexerConfig } from "@/config/types";
import { prettyPrintConfig } from "@/lib/lib-config";
import { mergePonderConfigs } from "@/lib/merge-ponder-configs";
import { ALL_PLUGINS, type AllPluginsConfig } from "@/plugins";
////////
// First, generate `MergedPonderConfig` type representing the merged types of each plugin's `config`,
// so ponder's typechecking of the indexing handlers and their event arguments is correct, regardless
// of which plugins are actually active at runtime.
////////
export type MergedPonderConfig = AllPluginsConfig & {
/**
* NOTE: we inject additional values (ones that change the behavior of the indexing logic) into the
* Ponder config in order to alter the ponder-generated build id when these additional options change.
*
* This ensures that running ENSIndexer with different configurations maintains compatibility with
* Ponder's default crash recovery behavior.
*
* https://ponder.sh/docs/api-reference/ponder/database#build-id-and-crash-recovery
**/
indexingBehaviorDependencies: Pick<
ENSIndexerConfig,
"healReverseAddresses" | "indexAdditionalResolverRecords"
>;
};
////////
// Merge the plugins' configs into a single ponder config, including injected dependencies.
////////
// filter all plugins by those activated by the config
const activePlugins = ALL_PLUGINS.filter((plugin) => config.plugins.includes(plugin.pluginName));
// combine each plugins' config into a MergedPonderConfig
const ponderConfig = activePlugins.reduce(
(memo, plugin) => mergePonderConfigs(memo, plugin.createPonderConfig(config)),
{},
) as MergedPonderConfig;
// inject the additional indexing behavior dependencies
ponderConfig.indexingBehaviorDependencies = {
healReverseAddresses: config.healReverseAddresses,
indexAdditionalResolverRecords: config.indexAdditionalResolverRecords,
};
////////
// Activate the active plugins' handlers, which register indexing handlers with Ponder.
////////
// NOTE: we explicitly delay the execution of this function for 1 tick, to avoid a race condition
// within ponder internals related to the schema name and drizzle-orm
setTimeout(() => activePlugins.map((plugin) => plugin.activate()), 0);
////////
// Finally, return the merged config for ponder to use for type inference and runtime behavior.
////////
console.log(`ENSIndexer running with config:\n${prettyPrintConfig(config)}`);
export default ponderConfig;