Generic service that lazily resolves resources by key, supporting async and sync values.
// Source: https://github.com/moeru-ai/airi | License: MIT | Copyright 2024-PRESENT Neko Ayaka // Provided via justclaw.it.com; keep this notice with the code. /** * Resolves one resource value lazily on demand. * * Use when: * - A resource should be computed or fetched only when requested * * Expects: * - The resolver returns the same logical resource shape each time * * Returns: * - The resolved resource value, synchronously or asynchronously */ export type ResourceResolver<T> = () => Promise<T> | T /** * Stores resources either as eager values or lazy resolver functions. * * Lookup order is: * 1. resolver registered with `setResolver` * 2. value registered with `setValue` * 3. optional fallback passed to `get` * * Example: * ```ts * const service = new ResourceServ ... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key