import type { AxiosError } from 'axios'; import type { QueryApiOptions } from '../query.api'; import { QueryApi } from '../query.api'; /** * Factory for creating a QueryApi instance. * Accepts either a plain options object or a function. * * Use a **function** when options depend on observables (queryKey, enabled, etc.) — * MobX tracks observables accessed during the function call and triggers refetch on change. * A plain object is evaluated once at class field initialization and does not react to changes. * * @example Plain object (options don't depend on observables) * ```typescript * techs = query({ * queryKey: ['scheduling', 'techs'], * queryFn: async () => (await this.api?.getTechs())?.data ?? [], * }); * ``` * * @example Function (options depend on observables — reactive) * ```typescript * jobs = query(() => ({ * queryKey: ['scheduling', 'jobs', this.filters], * queryFn: async () => (await this.api?.getJobs(this.filters))?.data ?? [], * enabled: this.selectedJobId > 0, * })); * ``` */ export function query( options: QueryApiOptions | (() => QueryApiOptions) ): QueryApi { const optionsFn = typeof options === 'function' ? options : () => options; return new QueryApi(optionsFn); }