import { EnsDbPublicConfig, IndexingMetadataContext, IndexingMetadataContextInitialized, Unvalidated } from '@ensnode/ensnode-sdk'; export { IndexingMetadataContext, IndexingMetadataContextInitialized, IndexingMetadataContextStatusCodes, IndexingMetadataContextUninitialized } from '@ensnode/ensnode-sdk'; import { NodePgDatabase } from 'drizzle-orm/node-postgres'; import { a as abstractEnsIndexerSchema } from './index-D36RM4zS.js'; import { e as ensNodeSchema } from './index-BHoa233Z.js'; import 'ponder'; import 'drizzle-orm'; import 'drizzle-orm/pg-core'; import 'enssdk'; /** * Utilities for Drizzle ORM integration with ENSDb. */ /** * PostgreSQL startup `options` string for ENSDb connections. * * Sets `search_path` so unqualified references (notably the `gin_trgm_ops` * opclass from the pg_trgm extension, installed in the `ensnode` schema by * migration 0001) resolve correctly at query and index-creation time. * * Pass via node-postgres `PoolConfig.options` (e.g. Ponder's * `database.poolConfig.options`) or Drizzle's connection config. */ declare const ENSDB_CONNECTION_OPTIONS = "-c search_path=ensnode,public"; /** * Abstract ENSIndexer Schema * * Represents the "abstract" ENSIndexer Schema definition, where tables do not reference * the specific ENSIndexer Schema name. */ type AbstractEnsIndexerSchema = typeof abstractEnsIndexerSchema; /** * ENSNode Schema * * Represents the ENSNode Schema definition for ENSDb. */ type EnsNodeSchema = typeof ensNodeSchema; /** * ENSDb Schema type * * Represents the combined database schema for ENSDb, * including both the "concrete" ENSIndexer Schema and the ENSNode Schema. */ type EnsDbSchema = ConcreteEnsIndexerSchema & EnsNodeSchema; /** * Drizzle client type for ENSDb. * * The `ConcreteEnsIndexerSchema` type parameter allows for typing * the Drizzle client with a "concrete" ENSIndexer Schema definition * where tables reference the specific ENSIndexer Schema name. */ type EnsDbDrizzleClient = NodePgDatabase>; /** * ENSDb Config */ interface EnsDbConfig { /** * PostgreSQL connection string for ENSDb. * * Guaranteed to be a valid PostgreSQL connection string with the format: * `postgresql://username:password@host:port/database` or * `postgres://username:password@host:port/database` */ ensDbUrl: string; /** * The name of the ENSIndexer Schema in the ENSDb instance. * * Guaranteed to be a non-empty string that is * a valid Postgres database schema identifier */ ensIndexerSchemaName: string; } /** * ENSDb Schema Checksum * * Checksum representing the ENSDb Schema definition, which is a combination of * - the ENSIndexer Schema definition, and * - the ENSNode Schema definition. * * This checksum can be used to verify compatibility between * the ENSDb Schema definition expected by any client app connecting to ENSDb * instance and the actual ENSDb Schema definition present in ENSDb SDK. */ declare const ENSDB_SCHEMA_CHECKSUM: string; /** * ENSDb Reader * * Enables read-only querying of an ENSDb instance, including data spanning * the ENSNode Schema and the specified ENSIndexer Schema. * * Note: we use a parameter type `ConcreteEnsIndexerSchema` to represent * the "concrete" ENSIndexer Schema type within the ENSDb Schema and * make sure that the Drizzle client used for querying is typed with * the same "concrete" ENSIndexer Schema type. */ declare class EnsDbReader { /** * Drizzle client for ENSDb. * * Uses the ENSDb Schema from {@link ensDbSchema}. */ protected drizzleClient: EnsDbDrizzleClient; /** * "Concrete" ENSIndexer Schema definition for ENSDb. * * This is the "concrete" ENSIndexer Schema in which tables reference * the ENSIndexer Schema name from {@link ensIndexerSchemaName}. */ protected _concreteEnsIndexerSchema: ConcreteEnsIndexerSchema; /** * The name of the ENSIndexer schema to read from in ENSDb. * * This also identifies which ENSNode metadata records to read from the ENSNode Schema * as the ENSNode Schema is multi-tenant across ENSIndexer instances / ENSIndexer Schemas in an ENSDb. */ protected _ensIndexerSchemaName: string; protected _ensNodeSchema: EnsNodeSchema; /** * @param ensDbUrl The connection string for Drizzle to connect to the ENSDb instance. * @param ensIndexerSchemaName The name of the ENSIndexer schema to read from in ENSDb, used to identify which ENSNode metadata records to read. */ constructor(ensDbUrl: string, ensIndexerSchemaName: string); /** * Getter for the Drizzle client for ENSDb instance * * Useful while working on complex queries for ENSDb. */ get ensDb(): EnsDbDrizzleClient; /** * Getter for the "concrete" ENSIndexer Schema definition used in the Drizzle client * for ENSDb instance. * * Useful while working on complex queries for ENSDb. * * Note: using `ensIndexerSchema` name for this getter to make it read better * in the context of query building. For example: * `this.ensDb.select().from(this.ensIndexerSchema.event)` vs. * `this.ensDb.select().from(this.concreteEnsIndexerSchema.event)`. */ get ensIndexerSchema(): ConcreteEnsIndexerSchema; /** * Getter for the ENSIndexer Schema Name used by this ENSDbReader instance. */ get ensIndexerSchemaName(): string; /** * Getter for the ENSNode Schema definition used in the Drizzle client * for ENSDb instance. * * Useful while working on complex queries for ENSDb. */ get ensNodeSchema(): EnsNodeSchema; /** * Check if the ENSDb instance is healthy by running a simple query * against it. */ isHealthy(): Promise; /** * Check if the ENSDb instance is ready by verifying that * the {@link IndexingMetadataContext} has been initialized for * the ENSIndexer Schema used by this ENSDbReader instance. */ isReady(): Promise; /** * Build ENSDb Public Config */ buildEnsDbPublicConfig(): Promise; /** * Get Indexing Metadata Context * * @returns the initialized record, or a default uninitialized one if no record exists in ENSDb. */ getIndexingMetadataContext(): Promise; /** * Destroy the ENSDbReader instance by closing the ENSDb connection pool. */ destroy(): Promise; /** * Get ENSNode Metadata record * * @returns selected record in ENSDb. * @throws when more than one matching metadata record is found * (should be impossible given the composite PK constraint on * 'ensIndexerSchemaName' and 'key') */ private getEnsNodeMetadata; /** * Get PostgreSQL version for the server hosting the ENSDb instance. * * @throws when the version cannot be retrieved or parsed from the query result. */ private getPostgresVersion; /** * Build ENSDb version info. * * @throws when version info cannot be retrieved or parsed from * the ENSDb instance. */ private buildEnsDbVersionInfo; } /** * ENSDb Writer * * Allows updating an ENSDb instance, including: * - executing database migrations for ENSNode Schema, * - updating ENSNode Metadata records in ENSDb for the given ENSIndexer instance. */ declare class EnsDbWriter extends EnsDbReader { /** * Stable arbitrary lock ID for ENSNode Schema migrations to * prevent concurrent migration execution across multiple ENSIndexer instances. */ private static readonly MIGRATION_LOCK_ID; /** * Execute pending database migrations for ENSNode Schema in ENSDb. * * This function is: * - idempotent and can be safely executed multiple times, * - safe to execute concurrently across multiple ENSIndexer instances, * as it uses a stable arbitrary advisory lock to prevent concurrent * execution of migrations. * * @param migrationsDirPath - The file path to the directory containing * database migration files for ENSNode Schema. * @throws error when migration execution fails. */ migrateEnsNodeSchema(migrationsDirPath: string): Promise; /** * Upsert Indexing Metadata Context Initialized * * @throws when upsert operation failed. */ upsertIndexingMetadataContext(indexingMetadataContext: IndexingMetadataContextInitialized): Promise; /** * Upsert ENSNode metadata * * @throws when upsert operation failed. */ private upsertEnsNodeMetadata; } /** * Keys used to distinguish records in `ensnode_metadata` table in the ENSDb. */ declare const EnsNodeMetadataKeys: { readonly IndexingMetadataContext: "indexing_metadata_context"; }; type EnsNodeMetadataKey = (typeof EnsNodeMetadataKeys)[keyof typeof EnsNodeMetadataKeys]; /** * ENSNode Metadata record for Indexing Metadata Context * * This record is used to store the Indexing Metadata Context in * ENSNode Metadata table for each ENSIndexer instance. */ interface EnsNodeMetadataIndexingMetadataContext { key: typeof EnsNodeMetadataKeys.IndexingMetadataContext; value: IndexingMetadataContextInitialized; } /** * ENSNode Metadata * * Type alias for ENSNode Metadata records, * currently only includes the record for Indexing Metadata Context, * but can be extended in the future to include more types of * ENSNode Metadata records as needed. */ type EnsNodeMetadata = EnsNodeMetadataIndexingMetadataContext; /** * Validate ENSDb config * * @param unvalidatedConfig - Unvalidated ENSDb config * @returns Valid ENSDb config * @throws Error if validation fails, with details about the validation errors */ declare function validateEnsDbConfig(unvalidatedConfig: Unvalidated): EnsDbConfig; export { ENSDB_CONNECTION_OPTIONS, ENSDB_SCHEMA_CHECKSUM, type EnsDbConfig, type EnsDbDrizzleClient, EnsDbReader, EnsDbWriter, type EnsNodeMetadata, type EnsNodeMetadataIndexingMetadataContext, type EnsNodeMetadataKey, EnsNodeMetadataKeys, validateEnsDbConfig };