# CombinedResolver

[**@twine-protocol/twine-core v0.1.0**](../index) • **Docs**

***

[twine-js](../../../index) / [@twine-protocol/twine-core](../index) / CombinedResolver

## Interface: CombinedResolver

A resolver that combines multiple resolvers

### Extends

* [`Resolver`](resolver)

### Properties

| Property       | Type                                    | Description                                  | Defined in                                                                                                                                                                                 |
| -------------- | --------------------------------------- | -------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `add`          | (`r`: [`Resolver`](resolver)) => `void` | Add a resolver to the combined resolver      | [packages/twine-core/src/resolver/combine.ts:51](https://github.com/twine-protocol/twine-js/blob/3800995f9c83f4f5711bcf3062ea754a1e4448ce/packages/twine-core/src/resolver/combine.ts#L51) |
| `remove`       | (`r`: [`Resolver`](resolver)) => `void` | Remove a resolver from the combined resolver | [packages/twine-core/src/resolver/combine.ts:57](https://github.com/twine-protocol/twine-js/blob/3800995f9c83f4f5711bcf3062ea754a1e4448ce/packages/twine-core/src/resolver/combine.ts#L57) |
| `setCacheSize` | (`count`: `number`) => `void`           | Set the maximum number of items to cache     | [packages/twine-core/src/resolver/combine.ts:63](https://github.com/twine-protocol/twine-js/blob/3800995f9c83f4f5711bcf3062ea754a1e4448ce/packages/twine-core/src/resolver/combine.ts#L63) |

### Methods

#### close()

> **close**(): [`Awaitable`](../type-aliases/awaitable)<`void`>

Close the resolver (if cleanup is needed in sub-resolvers)

**Returns**

[`Awaitable`](../type-aliases/awaitable)<`void`>

**Defined in**

[packages/twine-core/src/resolver/combine.ts:67](https://github.com/twine-protocol/twine-js/blob/3800995f9c83f4f5711bcf3062ea754a1e4448ce/packages/twine-core/src/resolver/combine.ts#L67)

***

#### resolve()

**resolve(query, options)**

> **resolve**(`query`, `options`?): `Promise`<[`ChainResolution`](../type-aliases/chainresolution)>

Resolve a chain from a query

This is the main way to get a pulse or chain from somewhere and have it automatically verified.

If the input is already a successful resolution, it will be returned as is.

If the input is a chain or pulse, it will be resolved as a chain or pulse resolution.

**Parameters**

| Parameter  | Type                                                             | Description                |
| ---------- | ---------------------------------------------------------------- | -------------------------- |
| `query`    | [`IntoResolveChainQuery`](../type-aliases/intoresolvechainquery) | The query to resolve       |
| `options`? | [`ResolveOptions`](../type-aliases/resolveoptions)               | Options for the resolution |

**Returns**

`Promise`<[`ChainResolution`](../type-aliases/chainresolution)>

A chain or pulse resolution

**Examples**

```js
const { chain } = await resolver.resolve({ chain: 'bafybeib3...' })
if (chain) {
  console.log('chain', chain)
} else {
  console.log('no chain')
}
```

```js
const { chain, pulse } = await resolver.resolve({
  chain: 'bafybeib3...',
  pulse: 'bafybeib3...'
})

if (pulse) {
  console.log('pulse', pulse)
} else {
  console.log('no pulse')
}
```

**Inherited from**

[`Resolver`](resolver).[`resolve`](../resolver#resolve)

**Defined in**

[packages/twine-core/src/resolver/types.ts:233](https://github.com/twine-protocol/twine-js/blob/3800995f9c83f4f5711bcf3062ea754a1e4448ce/packages/twine-core/src/resolver/types.ts#L233)

**resolve(query, options)**

> **resolve**(`query`, `options`?): `Promise`<[`PulseResolution`](../type-aliases/pulseresolution)>

Resolve a pulse (with its chain) from a query

**Parameters**

| Parameter  | Type                                                             |
| ---------- | ---------------------------------------------------------------- |
| `query`    | [`IntoResolvePulseQuery`](../type-aliases/intoresolvepulsequery) |
| `options`? | [`ResolveOptions`](../type-aliases/resolveoptions)               |

**Returns**

`Promise`<[`PulseResolution`](../type-aliases/pulseresolution)>

**Inherited from**

[`Resolver`](resolver).[`resolve`](../resolver#resolve)

**Defined in**

[packages/twine-core/src/resolver/types.ts:237](https://github.com/twine-protocol/twine-js/blob/3800995f9c83f4f5711bcf3062ea754a1e4448ce/packages/twine-core/src/resolver/types.ts#L237)

***

#### resolveLatest()

> **resolveLatest**(`chain`, `options`?): `Promise`<[`PulseResolution`](../type-aliases/pulseresolution)>

Resolve the latest pulse of a chain

**Parameters**

| Parameter  | Type                                               | Description                                                    |
| ---------- | -------------------------------------------------- | -------------------------------------------------------------- |
| `chain`    | [`IntoCid`](../type-aliases/intocid)               | The chain CID or chain itself to resolve the latest pulse from |
| `options`? | [`ResolveOptions`](../type-aliases/resolveoptions) | Options for the resolution                                     |

**Returns**

`Promise`<[`PulseResolution`](../type-aliases/pulseresolution)>

A pulse resolution

**Examples**

```js
const resolution = await resolver.resolveLatest('bafybeib3...')
if (resolution.pulse) {
  console.log('pulse', resolution.pulse)
}
```

```js
const { chain } = await resolver.resolve({ chain: 'bafybeib3...' })
const resolution = await resolver.resolveLatest(chain)
```

**Inherited from**

[`Resolver`](resolver).[`resolveLatest`](../resolver#resolvelatest)

**Defined in**

[packages/twine-core/src/resolver/types.ts:260](https://github.com/twine-protocol/twine-js/blob/3800995f9c83f4f5711bcf3062ea754a1e4448ce/packages/twine-core/src/resolver/types.ts#L260)

***

#### resolveIndex()

> **resolveIndex**(`chain`, `index`, `options`?): `Promise`<[`PulseResolution`](../type-aliases/pulseresolution)>

Resolve a pulse by index

**Parameters**

| Parameter  | Type                                               | Description                                             |
| ---------- | -------------------------------------------------- | ------------------------------------------------------- |
| `chain`    | [`IntoCid`](../type-aliases/intocid)               | The chain CID or chain itself to resolve the pulse from |
| `index`    | `number`                                           | The index of the pulse to resolve                       |
| `options`? | [`ResolveOptions`](../type-aliases/resolveoptions) | Options for the resolution                              |

**Returns**

`Promise`<[`PulseResolution`](../type-aliases/pulseresolution)>

A pulse resolution

**Example**

```js
const resolution = await resolver.resolveIndex('bafybeib3...', 42)
if (resolution.pulse) {
  console.log('pulse', resolution.pulse)
}
```

**Inherited from**

[`Resolver`](resolver).[`resolveIndex`](../resolver#resolveindex)

**Defined in**

[packages/twine-core/src/resolver/types.ts:278](https://github.com/twine-protocol/twine-js/blob/3800995f9c83f4f5711bcf3062ea754a1e4448ce/packages/twine-core/src/resolver/types.ts#L278)

***

#### has()

> **has**(`cid`): [`Awaitable`](../type-aliases/awaitable)<`boolean`>

Check if a cid can be resolved

**Parameters**

| Parameter | Type                                 | Description      |
| --------- | ------------------------------------ | ---------------- |
| `cid`     | [`IntoCid`](../type-aliases/intocid) | The CID to check |

**Returns**

[`Awaitable`](../type-aliases/awaitable)<`boolean`>

True if the CID can be resolved, false otherwise

**Example**

```js
const exists = await resolver.has('bafybeib3...')
if (exists) {
  console.log('chain exists')
} else {
  console.log('chain does not exist')
}
```

**Inherited from**

[`Resolver`](resolver).[`has`](../resolver#has)

**Defined in**

[packages/twine-core/src/resolver/types.ts:295](https://github.com/twine-protocol/twine-js/blob/3800995f9c83f4f5711bcf3062ea754a1e4448ce/packages/twine-core/src/resolver/types.ts#L295)

***

#### pulses()

> **pulses**(`chain`, `start`?, `options`?): `AsyncGenerator`<[`Pulse`](../type-aliases/pulse), `any`, `any`> | `Generator`<[`Pulse`](../type-aliases/pulse), `any`, `any`> | [`AnyIterable`](../type-aliases/anyiterable)<[`Pulse`](../type-aliases/pulse)>

Get the pulses of a chain

**Parameters**

| Parameter  | Type                                               | Description                                          |
| ---------- | -------------------------------------------------- | ---------------------------------------------------- |
| `chain`    | [`IntoCid`](../type-aliases/intocid)               | The chain CID or chain itself to get the pulses from |
| `start`?   | `number` \| [`IntoCid`](../type-aliases/intocid)   | The index or CID of the pulse to start from          |
| `options`? | [`ResolveOptions`](../type-aliases/resolveoptions) | Options for the resolution                           |

**Returns**

`AsyncGenerator`<[`Pulse`](../type-aliases/pulse), `any`, `any`> | `Generator`<[`Pulse`](../type-aliases/pulse), `any`, `any`> | [`AnyIterable`](../type-aliases/anyiterable)<[`Pulse`](../type-aliases/pulse)>

An sync/async iterable of pulses

**Example**

```js
// loop through pulses and print indices
for await (const pulse of resolver.pulses('bafybeib3...')) {
  console.log('pulse', pulse.value.content.index)
}
```

**Inherited from**

[`Resolver`](resolver).[`pulses`](../resolver#pulses)

**Defined in**

[packages/twine-core/src/resolver/types.ts:313](https://github.com/twine-protocol/twine-js/blob/3800995f9c83f4f5711bcf3062ea754a1e4448ce/packages/twine-core/src/resolver/types.ts#L313)

***

#### chains()

> **chains**(): `AsyncGenerator`<[`Chain`](../type-aliases/chain), `any`, `any`> | `Generator`<[`Chain`](../type-aliases/chain), `any`, `any`> | [`AnyIterable`](../type-aliases/anyiterable)<[`Chain`](../type-aliases/chain)>

Get the chains that are known to the resolver

**Returns**

`AsyncGenerator`<[`Chain`](../type-aliases/chain), `any`, `any`> | `Generator`<[`Chain`](../type-aliases/chain), `any`, `any`> | [`AnyIterable`](../type-aliases/anyiterable)<[`Chain`](../type-aliases/chain)>

An sync/async iterable of chains

**Example**

```js
const chains = await collect(resolver.chains())
```

**Inherited from**

[`Resolver`](resolver).[`chains`](../resolver#chains)

**Defined in**

[packages/twine-core/src/resolver/types.ts:324](https://github.com/twine-protocol/twine-js/blob/3800995f9c83f4f5711bcf3062ea754a1e4448ce/packages/twine-core/src/resolver/types.ts#L324)
