import { z } from 'zod'; import type { Flavored } from './types.js'; import type { Logger } from './log.js'; import type { Result } from './result.js'; export interface FetchValueOptions { /** * The `request.headers` take precedence over the headers computed from other options. */ request?: RequestInit; params?: TParams; parse?: (v: any) => TValue; token?: string | null; cache?: FetchValueCache | null; return_early_from_cache?: boolean; log?: Logger; fetch?: typeof globalThis.fetch; } /** * Specializes `fetch` with some slightly different behavior and additional features: * * - throws on ratelimit errors to mitigate unintentional abuse * - optional `parse` function called on the return value * - optional cache (different from the browser cache, * the caller can serialize it so e.g. dev setups can avoid hitting the network) * - optional simplified API for authorization and data types * (you can still provide headers directly) * * Unlike `fetch`, this throws on ratelimits (status code 429) * to halt whatever is happening in its tracks to avoid accidental abuse, * but returns a `Result` in all other cases. * Handling ratelimit headers with more sophistication gets tricky because behavior * differs across services. * (e.g. Mastodon returns an ISO string for `x-ratelimit-reset`, * but GitHub returns `Date.now()/1000`, * and other services may do whatever, or even use a different header) * * It's also stateless to avoid the complexity and bugs, * so we don't try to track `x-ratelimit-remaining` per domain. * * If the `value` is cached, only the cached safe subset of the `headers` are returned. * (currently just `etag` and `last-modified`) * Otherwise the full `res.headers` are included. * @mutates options.cache - calls `cache.set()` to store fetched results if cache is provided */ export declare const fetch_value: (url: string | URL, options?: FetchValueOptions) => Promise>; export declare const FetchValueCacheKey: z.ZodString; export type FetchValueCacheKey = Flavored, 'FetchValueCacheKey'>; export declare const FetchValueCacheItem: z.ZodObject<{ key: z.ZodString; url: z.ZodString; params: z.ZodAny; value: z.ZodAny; etag: z.ZodNullable; last_modified: z.ZodNullable; }, z.core.$strip>; export type FetchValueCacheItem = z.infer; export declare const FetchValueCache: z.ZodMap; last_modified: z.ZodNullable; }, z.core.$strip>>; export type FetchValueCache = z.infer; export declare const to_fetch_value_cache_key: (url: string, params: any, method: string) => FetchValueCacheKey; /** * Converts `FetchValueCache` to a JSON string. */ export declare const serialize_cache: (cache: FetchValueCache) => string; /** * Converts a serialized cache string to a `FetchValueCache`. */ export declare const deserialize_cache: (serialized: string) => FetchValueCache; //# sourceMappingURL=fetch.d.ts.map