> For the complete documentation index, see [llms.txt](https://docs.twine.world/twine-js/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.twine.world/twine-js/twine-protocol/twine-core/interfaces/store.md).

# Store

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

***

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

## Interface: Store

A store that can fetch and save twines

### Extends

* [`Resolver`](/twine-js/twine-protocol/twine-core/interfaces/resolver.md)

### Methods

#### fetch()

> **fetch**(`cid`): [`Awaitable`](/twine-js/twine-protocol/twine-core/type-aliases/awaitable.md)<`null` | [`Twine`](/twine-js/twine-protocol/twine-core/classes/twine.md)<[`TwineValue`](/twine-js/twine-protocol/twine-core/type-aliases/twinevalue.md)>>

Fetch a twine from storage, returning null if it is not found

it is NOT expected that the twine signature is checked, that is for the [Resolver](/twine-js/twine-protocol/twine-core/interfaces/resolver.md) to do.

**Parameters**

| Parameter | Type                                                                     | Description                   |
| --------- | ------------------------------------------------------------------------ | ----------------------------- |
| `cid`     | [`IntoCid`](/twine-js/twine-protocol/twine-core/type-aliases/intocid.md) | The CID of the twine to fetch |

**Returns**

[`Awaitable`](/twine-js/twine-protocol/twine-core/type-aliases/awaitable.md)<`null` | [`Twine`](/twine-js/twine-protocol/twine-core/classes/twine.md)<[`TwineValue`](/twine-js/twine-protocol/twine-core/type-aliases/twinevalue.md)>>

**Defined in**

[packages/twine-core/src/store/types.ts:22](https://github.com/twine-protocol/twine-js/blob/3800995f9c83f4f5711bcf3062ea754a1e4448ce/packages/twine-core/src/store/types.ts#L22)

***

#### save()

> **save**(`twine`): [`Awaitable`](/twine-js/twine-protocol/twine-core/type-aliases/awaitable.md)<`void`>

Save a twine to storage

**Parameters**

| Parameter | Type                                                                                                                                            | Description       |
| --------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | ----------------- |
| `twine`   | [`Twine`](/twine-js/twine-protocol/twine-core/classes/twine.md)<[`TwineValue`](/twine-js/twine-protocol/twine-core/type-aliases/twinevalue.md)> | The twine to save |

**Returns**

[`Awaitable`](/twine-js/twine-protocol/twine-core/type-aliases/awaitable.md)<`void`>

**Defined in**

[packages/twine-core/src/store/types.ts:28](https://github.com/twine-protocol/twine-js/blob/3800995f9c83f4f5711bcf3062ea754a1e4448ce/packages/twine-core/src/store/types.ts#L28)

***

#### saveMany()

> **saveMany**(`twines`): [`Awaitable`](/twine-js/twine-protocol/twine-core/type-aliases/awaitable.md)<`void`>

Save many twines to storage

**Parameters**

| Parameter | Type                                                                                                                                                                                                                              | Description        |
| --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ |
| `twines`  | [`AnyIterable`](/twine-js/twine-protocol/twine-core/type-aliases/anyiterable.md)<[`Twine`](/twine-js/twine-protocol/twine-core/classes/twine.md)<[`TwineValue`](/twine-js/twine-protocol/twine-core/type-aliases/twinevalue.md)>> | The twines to save |

**Returns**

[`Awaitable`](/twine-js/twine-protocol/twine-core/type-aliases/awaitable.md)<`void`>

**Defined in**

[packages/twine-core/src/store/types.ts:34](https://github.com/twine-protocol/twine-js/blob/3800995f9c83f4f5711bcf3062ea754a1e4448ce/packages/twine-core/src/store/types.ts#L34)

***

#### delete()

> **delete**(`cid`): [`Awaitable`](/twine-js/twine-protocol/twine-core/type-aliases/awaitable.md)<`void`>

Delete a twine from storage

**Parameters**

| Parameter | Type                                                                     | Description                    |
| --------- | ------------------------------------------------------------------------ | ------------------------------ |
| `cid`     | [`IntoCid`](/twine-js/twine-protocol/twine-core/type-aliases/intocid.md) | The CID of the twine to delete |

**Returns**

[`Awaitable`](/twine-js/twine-protocol/twine-core/type-aliases/awaitable.md)<`void`>

**Defined in**

[packages/twine-core/src/store/types.ts:40](https://github.com/twine-protocol/twine-js/blob/3800995f9c83f4f5711bcf3062ea754a1e4448ce/packages/twine-core/src/store/types.ts#L40)

***

#### resolve()

**resolve(query, options)**

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

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`](/twine-js/twine-protocol/twine-core/type-aliases/intoresolvechainquery.md) | The query to resolve       |
| `options`? | [`ResolveOptions`](/twine-js/twine-protocol/twine-core/type-aliases/resolveoptions.md)               | Options for the resolution |

**Returns**

`Promise`<[`ChainResolution`](/twine-js/twine-protocol/twine-core/type-aliases/chainresolution.md)>

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`](/twine-js/twine-protocol/twine-core/interfaces/resolver.md).[`resolve`](/twine-js/twine-protocol/twine-core/interfaces/resolver.md#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`](/twine-js/twine-protocol/twine-core/type-aliases/pulseresolution.md)>

Resolve a pulse (with its chain) from a query

**Parameters**

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

**Returns**

`Promise`<[`PulseResolution`](/twine-js/twine-protocol/twine-core/type-aliases/pulseresolution.md)>

**Inherited from**

[`Resolver`](/twine-js/twine-protocol/twine-core/interfaces/resolver.md).[`resolve`](/twine-js/twine-protocol/twine-core/interfaces/resolver.md#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`](/twine-js/twine-protocol/twine-core/type-aliases/pulseresolution.md)>

Resolve the latest pulse of a chain

**Parameters**

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

**Returns**

`Promise`<[`PulseResolution`](/twine-js/twine-protocol/twine-core/type-aliases/pulseresolution.md)>

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`](/twine-js/twine-protocol/twine-core/interfaces/resolver.md).[`resolveLatest`](/twine-js/twine-protocol/twine-core/interfaces/resolver.md#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`](/twine-js/twine-protocol/twine-core/type-aliases/pulseresolution.md)>

Resolve a pulse by index

**Parameters**

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

**Returns**

`Promise`<[`PulseResolution`](/twine-js/twine-protocol/twine-core/type-aliases/pulseresolution.md)>

A pulse resolution

**Example**

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

**Inherited from**

[`Resolver`](/twine-js/twine-protocol/twine-core/interfaces/resolver.md).[`resolveIndex`](/twine-js/twine-protocol/twine-core/interfaces/resolver.md#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`](/twine-js/twine-protocol/twine-core/type-aliases/awaitable.md)<`boolean`>

Check if a cid can be resolved

**Parameters**

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

**Returns**

[`Awaitable`](/twine-js/twine-protocol/twine-core/type-aliases/awaitable.md)<`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`](/twine-js/twine-protocol/twine-core/interfaces/resolver.md).[`has`](/twine-js/twine-protocol/twine-core/interfaces/resolver.md#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`](/twine-js/twine-protocol/twine-core/type-aliases/pulse.md), `any`, `any`> | `Generator`<[`Pulse`](/twine-js/twine-protocol/twine-core/type-aliases/pulse.md), `any`, `any`> | [`AnyIterable`](/twine-js/twine-protocol/twine-core/type-aliases/anyiterable.md)<[`Pulse`](/twine-js/twine-protocol/twine-core/type-aliases/pulse.md)>

Get the pulses of a chain

**Parameters**

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

**Returns**

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

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`](/twine-js/twine-protocol/twine-core/interfaces/resolver.md).[`pulses`](/twine-js/twine-protocol/twine-core/interfaces/resolver.md#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`](/twine-js/twine-protocol/twine-core/type-aliases/chain.md), `any`, `any`> | `Generator`<[`Chain`](/twine-js/twine-protocol/twine-core/type-aliases/chain.md), `any`, `any`> | [`AnyIterable`](/twine-js/twine-protocol/twine-core/type-aliases/anyiterable.md)<[`Chain`](/twine-js/twine-protocol/twine-core/type-aliases/chain.md)>

Get the chains that are known to the resolver

**Returns**

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

An sync/async iterable of chains

**Example**

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

**Inherited from**

[`Resolver`](/twine-js/twine-protocol/twine-core/interfaces/resolver.md).[`chains`](/twine-js/twine-protocol/twine-core/interfaces/resolver.md#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)
