/** * Builder for creating Promidas repository instances. * * This module provides a fluent builder interface for constructing * {@link ProtopediaInMemoryRepository} instances. * * @module */ import type { ProtoPediaApiClientOptions } from 'protopedia-api-v2-client'; import { ProtopediaApiCustomClient, type ProtopediaApiCustomClientConfig } from './fetcher/index.js'; import type { ProtopediaInMemoryRepository, ProtopediaInMemoryRepositoryConfig, PrototypeAnalysisResult } from './repository/types/index.js'; import { type PrototypeInMemoryStats, type PrototypeInMemoryStoreConfig } from './store/index.js'; export type { PrototypeInMemoryStoreConfig, PrototypeInMemoryStats, ProtopediaApiCustomClient, ProtopediaApiCustomClientConfig, ProtoPediaApiClientOptions, ProtopediaInMemoryRepository, ProtopediaInMemoryRepositoryConfig, PrototypeAnalysisResult, }; /** * A builder class for constructing {@link ProtopediaInMemoryRepository} instances. * * It allows for step-by-step configuration of Store, API Client, and Repository settings * through a fluent interface. * * @remarks * **Logger Configuration:** * Each component (Store, API Client, Repository) receives an independent logger instance. * - If you provide a custom logger, it will be used as-is * - If you don't provide a logger, a new ConsoleLogger is created with the specified logLevel (default: 'info') * - Each component can have different loggers and log levels for maximum flexibility * * @example * ```typescript * // Basic usage with default settings (each component gets independent logger) * const repo = new PromidasRepositoryBuilder().build(); * * // Configure store settings * const repo = new PromidasRepositoryBuilder() * .setStoreConfig({ ttlMs: 60000 }) * .setApiClientConfig({ * protoPediaApiClientOptions: { token: 'my-token' } * }) * .build(); * * // Different log levels for each component * const repo = new PromidasRepositoryBuilder() * .setStoreConfig({ logLevel: 'error' }) * .setApiClientConfig({ logLevel: 'warn' }) * .setRepositoryConfig({ logLevel: 'debug' }) * .build(); * ``` */ export declare class PromidasRepositoryBuilder { #private; /** * Set configuration for the in-memory store. * * Multiple calls will merge configurations (later values override earlier ones). * Configuration is deeply merged to prevent external mutations while preserving * function references (e.g., logger methods). * * @param config - Store configuration (TTL, max size, logger, etc.) */ setStoreConfig(config: PrototypeInMemoryStoreConfig): this; /** * Set configuration for the ProtopediaApiCustomClient wrapper. * Allows configuring the logger used by the client wrapper itself. * * Multiple calls will merge configurations (later values override earlier ones). * Configuration is deeply merged to prevent external mutations while preserving * function references (e.g., logger methods). * * @param config - Wrapper configuration (logger, logLevel) */ setApiClientConfig(config: ProtopediaApiCustomClientConfig): this; /** * Set configuration for the Repository itself. * * Multiple calls will merge configurations (later values override earlier ones). * Configuration is deeply merged to prevent external mutations while preserving * function references (e.g., logger methods). * * @param config - Repository configuration (logger, etc.) */ setRepositoryConfig(config: ProtopediaInMemoryRepositoryConfig): this; /** * Build and return a fully configured ProtopediaInMemoryRepository instance. * * This method creates new instances of dependencies (Store, API Client) * based on the accumulated configuration. * * @remarks * **Logger Creation:** * When no explicit logger is provided in a component's configuration, Builder * creates a new ConsoleLogger instance with the specified logLevel (default: 'info'). * Each component receives an independent logger instance unless you explicitly * share a logger by passing the same logger instance to multiple configs. * * **Configuration Immutability:** * Configurations are deep-merged to prevent external mutations from affecting * the builder's internal state. * * **Failure Logging:** * When construction fails, this method logs the failure via the repository * logger (if `logger.error` is a function) and rethrows the original error. * * @returns A fully configured ProtopediaInMemoryRepository instance * @throws {ConfigurationError} When store configuration is invalid * @throws {DataSizeExceededError} When snapshot data exceeds size limit * @throws {SizeEstimationError} When snapshot size estimation fails * @throws {StoreError} When store initialization fails * @throws {unknown} When API client or repository construction fails * * @example * ```typescript * // Build with default settings (each component gets independent logger with 'info' level) * const repo = new PromidasRepositoryBuilder().build(); * * // Build with different log levels * const repo = new PromidasRepositoryBuilder() * .setStoreConfig({ ttlMs: 60000, logLevel: 'warn' }) * .setRepositoryConfig({ logLevel: 'debug' }) * .build(); * // Result: Store gets ConsoleLogger('warn'), Repository gets ConsoleLogger('debug') * ``` */ build(): ProtopediaInMemoryRepository; /** * Creates a PrototypeInMemoryStore instance with detailed error handling. * * @param config - Store configuration * @param repositoryLogger - Logger instance for error reporting * @returns Initialized store instance * @throws {ConfigurationError} When store configuration is invalid * @throws {DataSizeExceededError} When snapshot data exceeds size limit * @throws {SizeEstimationError} When snapshot size estimation fails * @throws {StoreError} When other store-related errors occur * @throws {unknown} When the store constructor throws an unexpected error * * @remarks * On failure, this method logs via the repository logger (if `logger.error` * is a function) and rethrows the original error. * * @internal This method is private and intended for internal use and testing only */ private buildStore; /** * Creates a ProtopediaApiCustomClient instance with detailed error handling. * * @param config - API client configuration * @param repositoryLogger - Logger instance for error reporting * @returns Initialized API client instance * @throws {unknown} When API client construction fails * * @remarks * On failure, this method logs via the repository logger (if `logger.error` * is a function) and rethrows the original error. * * @internal This method is private and intended for internal use and testing only */ private buildApiClient; } //# sourceMappingURL=builder.d.ts.map