import { Container } from '@servicetitan/react-ioc'; import { QueryApi } from '../../utils/query.api'; import type { QueryClientConfig } from '@tanstack/query-core'; /** * Waits for a MobX observable condition to become true. * * Uses a MobX reaction that fires immediately and whenever tracked observables change. * Resolves the promise when the condition function returns `true`. * * @param check - Function that returns true when the condition is met * @returns Promise that resolves when the condition becomes true * * @example * ```tsx * // Wait for a store to be initialized * await waitFor(() => store.initialized); * * // Wait for data to be loaded * await waitFor(() => store.data.length > 0); * * // Wait for multiple conditions * await waitFor(() => store.initialized && !store.isLoading); * * // Wait for a specific value * await waitFor(() => store.status === 'success'); * ``` */ export declare const waitFor: (check: () => boolean) => Promise; export interface Type extends Function { new (...args: any[]): T; } export type SymbolToken = symbol & { typeRef?: T; }; export type Token = SymbolToken | Type | Function; type InstanceType = undefined | { useClass?: Type; useValue?: T; }; /** * Options for `ContainerBuilder.initialize()`. */ export interface InitializeOptions { /** Store tokens to skip initialization for entirely. */ ignoreStores?: Token[]; /** Individual `QueryApi` instances to skip waiting for. */ skipQueries?: QueryApi[]; } /** * Test container builder for dependency injection in tests. * * Simplifies setting up stores and their dependencies with automatic query client * configuration and store initialization. Use with `@servicetitan/react-ioc` containers. * * @example * ```tsx * // Basic usage * const { container, initialize } = new ContainerBuilder() * .add(JobsStore) * .add(JobsApi) * .build(); * * await initialize(); * const store = container.get(JobsStore); * expect(store.initialized).toBe(true); * ``` * * @example * ```tsx * // With mocked dependencies * const mockApi = new MockJobsApi(); * const { container, initialize } = new ContainerBuilder() * .add(JobsStore) * .add(JobsApi, { useValue: mockApi }) * .build(); * * await initialize(); * ``` * * @example * ```tsx * // With custom query client config * const builder = new ContainerBuilder(undefined, { * defaultOptions: { * queries: { staleTime: 0, retry: false }, * }, * }); * ``` */ export declare class ContainerBuilder { container: Container; private instances; constructor(container?: Container, options?: QueryClientConfig); /** * Builds the container and binds all added dependencies. * * Call this after adding all classes and values with `add()`. * Returns `this` to allow chaining with `initialize()`. * * @returns The builder instance with `container` and `initialize` available * * @example * ```tsx * const { container, initialize } = new ContainerBuilder() * .add(JobsStore) * .add(JobsApi) * .build(); * ``` */ build: () => this; /** * Runs the `initialize()` lifecycle method on all stores and waits for completion. * * Waits for: * - All store `initialize()` promises to complete * - All `QueryApiStore` instances to reach `initialized: true` * - All queries within stores to reach `initialized: true` * * Queries intended to stay disabled for the duration of a test (e.g. * `enabled: false` literal) must be opted out explicitly via `skipQueries` * or `ignoreStores`; otherwise this method waits for them indefinitely. * * @param options - Array of tokens to skip, or an options object * @returns Promise that resolves when all initialization is complete * * @example * ```tsx * // Initialize all stores * await initialize(); * expect(store.initialized).toBe(true); * ``` * * @example * ```tsx * // Skip specific stores * await initialize([StoreToSkip]); * ``` * * @example * ```tsx * // Skip specific queries * await initialize({ skipQueries: [store.lazyQuery] }); * ``` */ initialize: (options?: Token[] | InitializeOptions) => Promise; /** * Configures the `QueryClientStore` with custom TanStack Query options. * * Called automatically in the constructor with test-friendly defaults. * Only call manually if you need custom configuration. * * @param config - TanStack Query configuration options * @returns The builder instance for chaining * * @example * ```tsx * builder.addQueryClient({ * defaultOptions: { * queries: { * staleTime: Infinity, * retry: false, * }, * }, * }); * ``` */ addQueryClient: (config?: QueryClientConfig) => this; /** * Adds a class or value to the container for dependency injection. * * @param provide - The token (class, symbol, or function) to provide * @param customValue - Optional custom implementation or value * @returns The builder instance for chaining * * @example * ```tsx * // Add a store class * builder.add(JobsStore); * ``` * * @example * ```tsx * // Add with a custom implementation class * builder.add(JobsApi, { useClass: MockJobsApi }); * ``` * * @example * ```tsx * // Add with a concrete value instance * const mockApi = new MockJobsApi(); * builder.add(JobsApi, { useValue: mockApi }); * ``` */ add: (provide: Token, customValue?: InstanceType) => this; } export {}; //# sourceMappingURL=container-builder.d.ts.map