import { Store } from '@servicetitan/react-ioc'; import { QueryApi } from '../query.api'; import { MutationApi } from '../mutation.api'; import { QueryClientStore } from '../query-client.store'; /** @internal Per-instance state managed by the decorator. */ export interface QueryStoreState { managedApis: (QueryApi | MutationApi)[]; runtimeQueries: Map>; runtimeMutations: Map>; } /** @internal Interface for accessing decorator-managed properties from standalone helpers. */ export interface ComposableStore { queryClientStore?: QueryClientStore; queryStoreState?: QueryStoreState; } /** * Class decorator that provides automatic QueryApi/MutationApi lifecycle management. * This is the recommended approach for new stores. * * **What it handles automatically:** * - Injects QueryClientStore (no `@inject(QueryClientStore)` needed) * - Applies `@injectable()` automatically — no need to add it separately. * If migrating and you want to keep `@injectable()`, place it **below** `@queryStore` in source: * ``` * @queryStore * @injectable() * class MyStore extends Store { ... } * ``` * Placing `@injectable()` above `@queryStore` will throw. * - Auto-discovers `QueryApi`, `MutationApi`, `RuntimeQueries`, `RuntimeMutations`, * and `RefreshOnMountDef` class properties and wires their lifecycle * - Chains consumer `initialize()` and `dispose()` methods * - Safe with deep inheritance — prevents double setup/dispose * * **Declarative helpers** (class fields, auto-discovered): * - `query()` / `mutation()` — static queries and mutations * - `setupRuntimeQueries()` / `setupRuntimeMutations()` — containers for queries/mutations * created after initialization (e.g., in response to user actions) * - `refreshOnMount()` — invalidate queries on store initialization * * @example Basic store with queries, mutations, and refresh * ```typescript * @queryStore * class JobsStore extends Store { * @inject(JobsApi) private api?: JobsApi; * * jobs = query(() => ({ * queryKey: ['scheduling', 'jobs'], * queryFn: async () => (await this.api?.getJobs())?.data ?? [], * })); * * deleteJob = mutation(() => ({ * mutationFn: async (arg) => await this.api?.deleteJob(arg.id), * invalidatedQueries: [['scheduling', 'jobs']], * })); * * // Ensure fresh data from external store caches when this store mounts * refresh = refreshOnMount(['business-units', 'list']); * } * ``` * * @example Runtime queries and mutations (created after initialization) * ```typescript * @queryStore * class DetailsStore extends Store { * @inject(DetailsApi) private api?: DetailsApi; * private queries = setupRuntimeQueries(); * private mutations = setupRuntimeMutations(); * * loadDetails(id: number) { * return this.queries.add
(() => ({ * queryKey: ['details', id], * queryFn: () => this.api?.getDetails(id), * }), ['details', id]); * } * * setupDelete(id: number) { * return this.mutations.add(() => ({ * mutationFn: (args) => this.api?.delete(id, args), * }), ['delete', id]); * } * } * ``` */ export declare function queryStore Store>(Base: T): T; //# sourceMappingURL=decorator.d.ts.map