> ## Documentation Index
> Fetch the complete documentation index at: https://kweri.uchenna.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# Kweri

> Full API reference for the Kweri class.

## Constructor

```ts theme={null}
new Kweri(options: KweriOptions, timer?: TimerAdapter)
```

## KweriOptions

| Property         | Type                        | Default        | Description                                           |
| ---------------- | --------------------------- | -------------- | ----------------------------------------------------- |
| `baseURL`        | `string`                    | —              | **Required.** Base URL prepended to all request paths |
| `fetcher`        | `Fetcher`                   | global `fetch` | Custom HTTP transport                                 |
| `staleTime`      | `number`                    | `0`            | Milliseconds data is considered fresh                 |
| `cacheTime`      | `number`                    | `300_000`      | Milliseconds to retain stale data with no observers   |
| `maxRetries`     | `number`                    | `0`            | Max automatic retries for retryable errors            |
| `gcInterval`     | `number`                    | `undefined`    | Milliseconds between GC sweeps (disabled if omitted)  |
| `persistence`    | `PersistenceAdapter`        | `undefined`    | Adapter for cross-session cache persistence           |
| `enableDevTools` | `boolean`                   | `false`        | Mount the DevTools overlay (no-op in production)      |
| `devtools`       | `MountKweriDevToolsOptions` | `{}`           | DevTools panel options                                |

## Methods

### query

```ts theme={null}
query<E extends Endpoint>(endpoint: E, params: InferParams<E>): Promise<InferResponse<E>>
```

Executes a query. Returns cached data if fresh; otherwise fetches, caches, and returns.

***

### mutate

```ts theme={null}
mutate<E extends Endpoint, TContext = unknown>(
  endpoint: E,
  params: InferParams<E>,
  options?: MutationOptions<InferParams<E>, InferResponse<E>, TContext>
): Promise<InferResponse<E>>
```

Executes a mutation with lifecycle hooks. See [Mutations](/core/mutations).

***

### getCachedData

```ts theme={null}
getCachedData<E extends Endpoint>(endpoint: E, params: InferParams<E>): InferResponse<E> | undefined
```

Returns cached data without triggering a network request. Returns `undefined` if not cached.

***

### setCachedData

```ts theme={null}
setCachedData<E extends Endpoint>(endpoint: E, params: InferParams<E>, data: InferResponse<E>): void
```

Writes data into the cache directly. Marks entry as `success` with `updatedAt = Date.now()`.

***

### invalidateQuery

```ts theme={null}
invalidateQuery<E extends Endpoint>(endpoint: E, params: InferParams<E>): void
```

Marks a cache entry as stale. The entry remains in cache; a background refetch fires on next access.

***

### invalidateByPath

```ts theme={null}
invalidateByPath(pattern: string | RegExp): void
```

Marks all entries whose serialized cache key contains `pattern` as stale.

***

### invalidateQueryByKey

```ts theme={null}
invalidateQueryByKey(key: string): void
```

Invalidates by raw serialized cache key.

***

### removeQuery

```ts theme={null}
removeQuery<E extends Endpoint>(endpoint: E, params: InferParams<E>): void
```

Deletes a cache entry entirely.

***

### removeQueryByKey

```ts theme={null}
removeQueryByKey(key: string): void
```

Deletes by raw serialized cache key.

***

### subscribe

```ts theme={null}
subscribe<E extends Endpoint>(
  endpoint: E,
  params: InferParams<E>,
  callback: (entry: CacheEntry) => void
): () => void
```

Subscribes to cache changes for a query. Returns an unsubscribe function.

***

### onCacheChange

```ts theme={null}
onCacheChange(callback: (key: string, entry: CacheEntry) => void): () => void
```

Subscribes to all cache changes globally.

***

### isInFlight

```ts theme={null}
isInFlight<E extends Endpoint>(endpoint: E, params: InferParams<E>): boolean
```

Returns `true` if a fetch is currently in progress for this query.

***

### getQueryKey

```ts theme={null}
getQueryKey<E extends Endpoint>(endpoint: E, params: InferParams<E>): string
```

Returns the serialized cache key string (e.g. `GET:/users:{}`).

***

### startGC / stopGC

```ts theme={null}
startGC(intervalMs: number): void
stopGC(): void
```

Start or stop the eviction engine.

***

### getDevToolsSnapshot

```ts theme={null}
getDevToolsSnapshot(): KweriDevToolsSnapshot
```

Returns a snapshot of the current cache, observer counts, and in-flight requests.

***

### destroy

```ts theme={null}
destroy(): void
```

Stops GC, unmounts DevTools, clears all subscriptions.

## Properties

```ts theme={null}
readonly queryClient: QueryClient
readonly apiClient:   ApiClient
```
