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

# Class: BaseBijectionClient

> Low-level client for directly integrating state management libraries with Bijection.

[browser](/api/modules/browser).BaseBijectionClient

Low-level client for directly integrating state management libraries
with Bijection.

Most developers should use higher level clients, like
the [BijectionHttpClient](/api/classes/browser.BijectionHttpClient) or the React hook based [BijectionReactClient](/api/classes/react.BijectionReactClient).

## Constructors

### constructor

• **new BaseBijectionClient**(`address`, `onTransition`, `options?`)

#### Parameters

| Name | Type | Description |
| :- | :- | :- |
| `address` | `string` | The url of your Bijection deployment, often provided by an environment variable. E.g. `https://small-mouse-123.bijection.cloud`. |
| `onTransition` | (`updatedQueries`: [`QueryToken`](/api/modules/browser#querytoken)\[]) => `void` | A callback receiving an array of query tokens corresponding to query results that have changed -- additional handlers can be added via `addOnTransitionHandler`. |
| `options?` | [`BaseBijectionClientOptions`](/api/interfaces/browser.BaseBijectionClientOptions) | See [BaseBijectionClientOptions](/api/interfaces/browser.BaseBijectionClientOptions) for a full description. |

## Accessors

### url

• `get` **url**(): `string`

Return the address for this client, useful for creating a new client.

Not guaranteed to match the address with which this client was constructed:
it may be canonicalized.

#### Returns

`string`

## Methods

### getMaxObservedTimestamp

▸ **getMaxObservedTimestamp**(): `undefined` | `Long`

#### Returns

`undefined` | `Long`

***

### addOnTransitionHandler

▸ **addOnTransitionHandler**(`fn`): () => `boolean`

Add a handler that will be called on a transition.

Any external side effects (e.g. setting React state) should be handled here.

#### Parameters

| Name | Type |
| :- | :- |
| `fn` | (`transition`: `Transition`) => `void` |

#### Returns

`fn`

▸ (): `boolean`

##### Returns

`boolean`

***

### getCurrentAuthClaims

▸ **getCurrentAuthClaims**(): `undefined` | \{ `token`: `string` ; `decoded`: `Record`\<`string`, `any`>  }

Get the current JWT auth token and decoded claims.

#### Returns

`undefined` | \{ `token`: `string` ; `decoded`: `Record`\<`string`, `any`>  }

***

### setAuth

▸ **setAuth**(`fetchToken`, `onChange`, `onRefreshChange?`): `void`

Set the authentication token to be used for subsequent queries and mutations.
`fetchToken` will be called automatically again if a token expires.
`fetchToken` should return `null` if the token cannot be retrieved, for example
when the user's rights were permanently revoked.

#### Parameters

| Name | Type | Description |
| :- | :- | :- |
| `fetchToken` | [`AuthTokenFetcher`](/api/modules/browser#authtokenfetcher) | an async function returning the JWT-encoded OpenID Connect Identity Token |
| `onChange` | (`isAuthenticated`: `boolean`) => `void` | a callback that will be called when the authentication status changes |
| `onRefreshChange?` | (`isRefreshing`: `boolean`) => `void` | a callback called with `true` when the socket is paused to fetch a replacement token after a server rejection, and `false` when refresh completes |

#### Returns

`void`

***

### hasAuth

▸ **hasAuth**(): `boolean`

#### Returns

`boolean`

***

### clearAuth

▸ **clearAuth**(): `void`

#### Returns

`void`

***

### subscribe

▸ **subscribe**(`name`, `args?`, `options?`): `Object`

Subscribe to a query function.

Whenever this query's result changes, the `onTransition` callback
passed into the constructor will be called.

#### Parameters

| Name | Type | Description |
| :- | :- | :- |
| `name` | `string` | The name of the query. |
| `args?` | `Record`\<`string`, [`Value`](/api/modules/values#value)> | An arguments object for the query. If this is omitted, the arguments will be `{}`. |
| `options?` | [`SubscribeOptions`](/api/interfaces/browser.SubscribeOptions) | A [SubscribeOptions](/api/interfaces/browser.SubscribeOptions) options object for this query. |

#### Returns

`Object`

An object containing a [QueryToken](/api/modules/browser#querytoken) corresponding to this
query and an `unsubscribe` callback.

| Name | Type |
| :- | :- |
| `queryToken` | [`QueryToken`](/api/modules/browser#querytoken) |
| `unsubscribe` | () => `void` |

***

### localQueryResult

▸ **localQueryResult**(`udfPath`, `args?`): `undefined` | [`Value`](/api/modules/values#value)

A query result based only on the current, local state.

The only way this will return a value is if we're already subscribed to the
query or its value has been set optimistically.

#### Parameters

| Name | Type |
| :- | :- |
| `udfPath` | `string` |
| `args?` | `Record`\<`string`, [`Value`](/api/modules/values#value)> |

#### Returns

`undefined` | [`Value`](/api/modules/values#value)

***

### queryJournal

▸ **queryJournal**(`name`, `args?`): `undefined` | [`QueryJournal`](/api/modules/browser#queryjournal)

Retrieve the current [QueryJournal](/api/modules/browser#queryjournal) for this query function.

If we have not yet received a result for this query, this will be `undefined`.

#### Parameters

| Name | Type | Description |
| :- | :- | :- |
| `name` | `string` | The name of the query. |
| `args?` | `Record`\<`string`, [`Value`](/api/modules/values#value)> | The arguments object for this query. |

#### Returns

`undefined` | [`QueryJournal`](/api/modules/browser#queryjournal)

The query's [QueryJournal](/api/modules/browser#queryjournal) or `undefined`.

***

### connectionState

▸ **connectionState**(): [`ConnectionState`](/api/modules/browser#connectionstate)

Get the current [ConnectionState](/api/modules/browser#connectionstate) between the client and the Bijection
backend.

#### Returns

[`ConnectionState`](/api/modules/browser#connectionstate)

The [ConnectionState](/api/modules/browser#connectionstate) with the Bijection backend.

***

### subscribeToConnectionState

▸ **subscribeToConnectionState**(`cb`): () => `void`

Subscribe to the [ConnectionState](/api/modules/browser#connectionstate) between the client and the Bijection
backend, calling a callback each time it changes.

Subscribed callbacks will be called when any part of ConnectionState changes.
ConnectionState may grow in future versions (e.g. to provide a array of
inflight requests) in which case callbacks would be called more frequently.

#### Parameters

| Name | Type |
| :- | :- |
| `cb` | (`connectionState`: [`ConnectionState`](/api/modules/browser#connectionstate)) => `void` |

#### Returns

`fn`

An unsubscribe function to stop listening.

▸ (): `void`

Subscribe to the [ConnectionState](/api/modules/browser#connectionstate) between the client and the Bijection
backend, calling a callback each time it changes.

Subscribed callbacks will be called when any part of ConnectionState changes.
ConnectionState may grow in future versions (e.g. to provide a array of
inflight requests) in which case callbacks would be called more frequently.

##### Returns

`void`

An unsubscribe function to stop listening.

***

### mutation

▸ **mutation**(`name`, `args?`, `options?`): `Promise`\<`any`>

Execute a mutation function.

#### Parameters

| Name | Type | Description |
| :- | :- | :- |
| `name` | `string` | The name of the mutation. |
| `args?` | `Record`\<`string`, [`Value`](/api/modules/values#value)> | An arguments object for the mutation. If this is omitted, the arguments will be `{}`. |
| `options?` | [`MutationOptions`](/api/interfaces/browser.MutationOptions) | A [MutationOptions](/api/interfaces/browser.MutationOptions) options object for this mutation. |

#### Returns

`Promise`\<`any`>

* A promise of the mutation's result.

***

### action

▸ **action**(`name`, `args?`): `Promise`\<`any`>

Execute an action function.

#### Parameters

| Name | Type | Description |
| :- | :- | :- |
| `name` | `string` | The name of the action. |
| `args?` | `Record`\<`string`, [`Value`](/api/modules/values#value)> | An arguments object for the action. If this is omitted, the arguments will be `{}`. |

#### Returns

`Promise`\<`any`>

A promise of the action's result.

***

### close

▸ **close**(): `Promise`\<`void`>

Close any network handles associated with this client and stop all subscriptions.

Call this method when you're done with an [BaseBijectionClient](/api/classes/browser.BaseBijectionClient) to
dispose of its sockets and resources.

#### Returns

`Promise`\<`void`>

A `Promise` fulfilled when the connection has been completely closed.
