-
Notifications
You must be signed in to change notification settings - Fork 16
Extend ensdb-sdk with EnsDbConfig data model
#1868
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
2604c0d
Make ENSNode SDK a regular dependency for ENSDb SDK
tk-o b133b42
Update ENSDb SDK dependencies
tk-o cba260e
Extend ENSDb SDK data model
tk-o c55893c
docs(changeset): Added `validateEnsDbConfig` function to support vali…
tk-o ba3989b
Build `EnsDbConfig` for ENSApi
tk-o 4b9ecab
Build `EnsDbConfig` for ENSIndexer
tk-o 3e8161f
Update testing suite
tk-o 7aa8ce4
Apply AI PR feedback
tk-o c807ec9
Merge branch 'main' into feat/1824-enhance-ensdb-sdk
shrugs 7518d89
fix: tidy up schema parsing
shrugs d10db1f
nit: 'values'
shrugs caab8f0
fix: comments
shrugs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@ensnode/ensdb-sdk": minor | ||
| --- | ||
|
|
||
| Added `validateEnsDbConfig` function to support validation for the `EnsDbConfig` data model. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,31 @@ | ||
| import { buildEnsDbConfigFromEnvironment } from "./ensdb-config.schema"; | ||
| import { type EnsDbConfig, validateEnsDbConfig } from "@ensnode/ensdb-sdk"; | ||
| import type { Unvalidated } from "@ensnode/ensnode-sdk"; | ||
|
|
||
| export default buildEnsDbConfigFromEnvironment(process.env); | ||
| import { lazyProxy } from "@/lib/lazy"; | ||
| import logger from "@/lib/logger"; | ||
|
|
||
| /** | ||
| * Build ENSDb config from environment variables for ENSApi app. | ||
| * | ||
| * Exits the process if the configuration is invalid, logging the error details. | ||
| */ | ||
| export function buildEnsDbConfigFromEnvironment(env: NodeJS.ProcessEnv): EnsDbConfig { | ||
| const unvalidatedConfig = { | ||
| ensDbUrl: env.ENSDB_URL, | ||
| ensIndexerSchemaName: env.ENSINDEXER_SCHEMA_NAME, | ||
| } satisfies Unvalidated<EnsDbConfig>; | ||
|
|
||
| try { | ||
| return validateEnsDbConfig(unvalidatedConfig); | ||
| } catch (error) { | ||
| const errorMessage = error instanceof Error ? error.message : String(error); | ||
| logger.error(`Failed to validate ENSDb config from environment: ${errorMessage}`); | ||
| process.exit(1); | ||
| } | ||
| } | ||
|
|
||
| // lazyProxy defers construction until first use so that this module can be | ||
| // imported without env vars being present (e.g. during OpenAPI generation). | ||
| const ensDbConfig = lazyProxy<EnsDbConfig>(() => buildEnsDbConfigFromEnvironment(process.env)); | ||
|
|
||
| export default ensDbConfig; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,9 @@ | ||
| import { parse as parseConnectionString } from "pg-connection-string"; | ||
| import { prettifyError, ZodError, z } from "zod/v4"; | ||
|
|
||
| import { buildBlockNumberRange, PluginName, uniq } from "@ensnode/ensnode-sdk"; | ||
| import { | ||
| buildRpcConfigsFromEnv, | ||
| ENSNamespaceSchema, | ||
| EnsIndexerSchemaNameSchema, | ||
| invariant_isSubgraphCompatibleRequirements, | ||
| invariant_rpcConfigsSpecifiedForRootChain, | ||
| makeFullyPinnedLabelSetSchema, | ||
|
|
@@ -14,6 +12,7 @@ import { | |
| } from "@ensnode/ensnode-sdk/internal"; | ||
|
|
||
| import { DEFAULT_SUBGRAPH_COMPAT } from "@/config/defaults"; | ||
| import ensDbConfig from "@/config/ensdb-config"; | ||
| import type { ENSIndexerEnvironment } from "@/config/environment"; | ||
| import { applyDefaults, EnvironmentDefaults } from "@/config/environment-defaults"; | ||
|
|
||
|
|
@@ -27,24 +26,6 @@ import { | |
| invariant_validContractConfigs, | ||
| } from "./validations"; | ||
|
|
||
| export const EnsDbUrlSchema = z.string().refine( | ||
| (url) => { | ||
| try { | ||
| if (!url.startsWith("postgresql://") && !url.startsWith("postgres://")) { | ||
| return false; | ||
| } | ||
| const config = parseConnectionString(url); | ||
| return !!(config.host && config.port && config.database); | ||
| } catch { | ||
| return false; | ||
| } | ||
| }, | ||
| { | ||
| error: | ||
| "Invalid PostgreSQL connection string for ENSDb. Expected format: postgresql://username:password@host:port/database", | ||
| }, | ||
| ); | ||
|
|
||
| // parses an env string bool with strict requirement of 'true' or 'false' | ||
| const makeEnvStringBoolSchema = (envVarKey: string) => | ||
| z | ||
|
|
@@ -106,8 +87,6 @@ const IsSubgraphCompatibleSchema = | |
|
|
||
| const ENSIndexerConfigSchema = z | ||
| .object({ | ||
| ensDbUrl: EnsDbUrlSchema, | ||
| ensIndexerSchemaName: EnsIndexerSchemaNameSchema, | ||
| rpcConfigs: RpcConfigsSchema, | ||
|
|
||
| namespace: ENSNamespaceSchema, | ||
|
|
@@ -116,6 +95,10 @@ const ENSIndexerConfigSchema = z | |
| globalBlockrange: BlockrangeSchema, | ||
| ensRainbowUrl: EnsRainbowUrlSchema, | ||
| labelSet: LabelSetSchema, | ||
|
|
||
| // include the ENSDbConfig params in the ENSIndexerConfigSchema | ||
| ensDbUrl: z.string(), | ||
| ensIndexerSchemaName: z.string(), | ||
| }) | ||
| /** | ||
| * Derived configuration | ||
|
|
@@ -184,8 +167,6 @@ export function buildConfigFromEnvironment(_env: ENSIndexerEnvironment): EnsInde | |
|
|
||
| // parse/validate with ENSIndexerConfigSchema | ||
| return ENSIndexerConfigSchema.parse({ | ||
| ensDbUrl: env.ENSDB_URL, | ||
| ensIndexerSchemaName: env.ENSINDEXER_SCHEMA_NAME, | ||
| namespace: env.NAMESPACE, | ||
| rpcConfigs, | ||
|
|
||
|
|
@@ -200,6 +181,10 @@ export function buildConfigFromEnvironment(_env: ENSIndexerEnvironment): EnsInde | |
| labelSetId: env.LABEL_SET_ID, | ||
| labelSetVersion: env.LABEL_SET_VERSION, | ||
| }, | ||
|
|
||
| // include the validated ENSDb config values in the parsed EnsIndexerConfig | ||
| ensDbUrl: ensDbConfig.ensDbUrl, | ||
| ensIndexerSchemaName: ensDbConfig.ensIndexerSchemaName, | ||
|
Comment on lines
+185
to
+187
|
||
| }); | ||
| } catch (error) { | ||
| if (error instanceof ZodError) { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { type EnsDbConfig, validateEnsDbConfig } from "@ensnode/ensdb-sdk"; | ||
| import type { Unvalidated } from "@ensnode/ensnode-sdk"; | ||
|
|
||
| /** | ||
| * Build ENSDb config from environment variables for ENSIndexer app. | ||
| * | ||
| * Exits the process if the configuration is invalid, logging the error details. | ||
| */ | ||
| function buildEnsDbConfigFromEnvironment(env: NodeJS.ProcessEnv): EnsDbConfig { | ||
| const unvalidatedConfig = { | ||
| ensDbUrl: env.ENSDB_URL, | ||
| ensIndexerSchemaName: env.ENSINDEXER_SCHEMA_NAME, | ||
| } satisfies Unvalidated<EnsDbConfig>; | ||
|
|
||
| try { | ||
| return validateEnsDbConfig(unvalidatedConfig); | ||
| } catch (error) { | ||
| const errorMessage = error instanceof Error ? error.message : String(error); | ||
| console.error(`Failed to validate ENSDb config from environment: ${errorMessage}`); | ||
| process.exit(1); | ||
| } | ||
| } | ||
tk-o marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| export default buildEnsDbConfigFromEnvironment(process.env); | ||
tk-o marked this conversation as resolved.
Show resolved
Hide resolved
tk-o marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This changeset describes only adding
validateEnsDbConfig, but the PR also introduces theEnsDbConfigdata model and its schema. Consider updating the changeset text to mention the newEnsDbConfigexport as part of the minor release so consumers understand what was added.