import { Tidx } from 'tidx.ts'; import type { Chain } from 'viem'; import type * as Auth from './Auth.js'; import * as Credential from './Credential.js'; import type * as Log from './Log.js'; import * as Viem from './Viem.js'; /** Default Tempo indexer (TIDX) base URLs. */ export declare const url: Record; /** TIDX query client. */ export type Client = Tidx.Tidx; /** Gets a TIDX query client for a Tempo chain id and request context. */ export type GetClient = (chainId?: Viem.ChainId, options?: Pick) => Client; /** Shared, per-chain, or dynamically resolved TIDX URLs. */ export type UrlResolver = Viem.UrlResolver; /** * Resolves the effective TIDX config for a single request. * * Accepts either a static config object or a per-request resolver function that * receives a {@link Viem.resolveRpc.Context} (`chainId` plus the request * `principal`), so callers can route traffic per caller — e.g. send anonymous * (`principal.type === 'public'`) traffic to a separate, no-auth indexer. A * missing `baseUrl` falls back to the built-in public host map ({@link url}); * missing `auth` sends no Authorization header. */ export declare function resolve(tidx: getClient.Tidx | undefined, context: Viem.resolveRpc.Context): resolve.Resolved; export declare namespace resolve { /** Resolved TIDX config for a single request. */ type Resolved = { /** * Resolved TIDX base URL, or `undefined` when neither a configured `tidx` * nor the built-in {@link url} map covers the chain (e.g. an unconfigured * localnet). A `undefined` base URL falls through to the TIDX client default. */ baseUrl: string | undefined; /** Basic auth credentials, or undefined to send no Basic auth. */ basicAuth?: string | undefined; /** Bearer auth credential, or undefined to send no Bearer auth. */ bearerAuth?: string | undefined; /** Headers sent to Zone indexer upstreams. */ zoneHeaders?: Viem.ZoneHeaders | undefined; }; } export declare function getClient(options: getClient.Options): Client; /** * Builds a memoized {@link GetClient} that constructs one TIDX client per * resolved upstream and reuses it. Clients are stateless HTTP transports, so * reusing them avoids per-call construction cost. The cache key is the resolved * output (`baseUrl` + auth + `chainId`), not the principal, so a resolver * `tidx` may branch on any principal field while client cardinality stays * bounded by the number of distinct upstreams — callers that resolve to the same * upstream share a client. */ export declare function createGetClient(options?: createGetClient.Options): GetClient; /** * Escapes a free-form string for safe embedding inside a single-quoted SQL * string literal sent to the indexer. TIDX parses every query with an ANSI * SQL parser before re-rendering it for the engine, and ANSI strings have * exactly one special character inside `'…'`: the quote itself, escaped by * doubling (`''`). Backslash escaping (`\'`) is **rejected** with a parse * error, and a backslash is an ordinary character on both engines (verified * against the deployed indexer on `postgres` and `clickhouse`). * * Most interpolated values (addresses, hashes, ISO timestamps) are already * schema-constrained to charsets that cannot contain a quote; reach for this * whenever a query must interpolate genuinely free-form user input (e.g. the * token `currency` filter). */ export declare function escape(value: string): string; /** * Wraps a TIDX client so `fetch` retries transient errors under **one** * shared budget ({@link transientRetryCount} retries with backoff). * * Two transient failure modes are covered: HTTP-level failures (408/429/5xx) * and the indexer's transient ClickHouse errors, which arrive as **HTTP 200** * with an `{ ok: false, error: 'db error' }` body (a `FetchRequestError` * whose `status` is 200). The raw `tidx.ts` client would retry the HTTP-level * mode itself (5 attempts), which stacked multiplicatively under this wrapper * — one flapping query shape could cost ~25 upstream executions — so the * wrapper disables the client-level retries (`retryCount: 1`) and owns the * whole budget: at most {@link transientRetryCount} + 1 upstream executions. * Deterministic errors (e.g. a malformed query) fall through immediately. */ export declare function withTransientRetry(client: Client): Client; /** Adds request-scoped timing and redacted failure diagnostics to a TIDX client. */ export declare function observe(client: Client, options: observe.Options): Client; export declare namespace observe { /** Request-scoped observability hooks for TIDX calls. */ type Options = { /** Records a failure, or clears one after a later successful query. */ record: (failure: Log.ProviderFailure | undefined) => void; /** Measures the complete TIDX call, including retries. */ time: (fn: () => Promise) => Promise; }; } /** Returns bounded failure metadata for a TIDX request. */ export declare function providerFailure(cause: unknown): Log.ProviderFailure; /** Returns bounded failure metadata when a TIDX response represents a failed query. */ export declare function responseFailure(response: Response): Promise; /** Whether a TIDX response is a deterministic rejection of the caller's query. */ export declare function isQueryRejection(cause: unknown): boolean; /** Whether a failed TIDX request exhausted its query execution deadline. */ export declare function isQueryTimeout(cause: unknown): boolean; /** * True for deterministic indexer failures a retry cannot fix: a * `FetchRequestError` outside {@link isTransientError}'s transient classes, * e.g. an HTTP 422 `db error` for a query shape the planner cannot execute. */ export declare function isDeterministicError(error: unknown): boolean; export declare namespace getClient { /** Options for getting a TIDX query client. */ type Options = { /** Tempo chain id. */ chainId?: Viem.ChainId | undefined; /** Request principal, or `null`/omitted for a trusted non-request caller. */ principal?: Auth.Principal | null | undefined; /** TIDX query client options. */ tidx?: Tidx | undefined; /** Zone chain metadata used for TIDX URL resolution. */ zone?: Chain | undefined; }; /** * TIDX query client options: either a static config, or a per-request * resolver function that receives a {@link Viem.resolveRpc.Context} and returns * the config to use (e.g. routing anonymous callers to a public, no-auth * indexer). */ type Tidx = { /** Shared or per-chain TIDX credentials. Values containing `:` use Basic auth; others use Bearer auth. */ auth?: Credential.ChainCredential | undefined; /** Resolves the TIDX base URL for a Tempo chain id, or a static base URL. */ baseUrl?: UrlResolver | undefined; /** Headers sent to Zone indexer upstreams. */ zoneHeaders?: Viem.ZoneHeaders | undefined; } | ((context: Viem.resolveRpc.Context) => { /** Shared or per-chain TIDX credentials, or undefined for none. */ auth?: Credential.ChainCredential | undefined; /** TIDX base URL to use; falls back to the built-in public host when omitted. */ baseUrl?: string | undefined; /** Headers sent to Zone indexer upstreams. */ zoneHeaders?: Viem.ZoneHeaders | undefined; }); } export declare namespace createGetClient { /** Options for building a memoized TIDX client resolver. */ type Options = { /** Tempo chain id used when a caller omits one. */ defaultChainId?: Viem.ChainId | undefined; /** TIDX query client options applied to every constructed client. */ tidx?: getClient.Tidx | undefined; }; } //# sourceMappingURL=Tidx.d.ts.map