# BlockstoreStore

[**@twine-protocol/twine-blockstore-store v0.0.3**](https://docs.twine.world/twine-js/twine-protocol/twine-blockstore-store/index) • **Docs**

***

[twine-js](https://docs.twine.world/twine-js/index) / [@twine-protocol/twine-blockstore-store](https://docs.twine.world/twine-js/twine-protocol/twine-blockstore-store/index) / BlockstoreStore

## Class: BlockstoreStore

Storage wrapper for storing Twine objects inside datastore and a blockstore

### Implements

* `Store`

### Constructors

#### new BlockstoreStore()

> **new BlockstoreStore**(`datastore`, `blockstore`): [`BlockstoreStore`](https://docs.twine.world/twine-js/twine-protocol/twine-blockstore-store/classes/blockstorestore)

Create a new BlockstoreStore

**Parameters**

| Parameter    | Type                                                                                                            | Description           |
| ------------ | --------------------------------------------------------------------------------------------------------------- | --------------------- |
| `datastore`  | `Datastore`<`object`, `object`, `object`, `object`, `object`, `object`, `object`, `object`, `object`, `object`> | The datastore to use  |
| `blockstore` | `Blockstore`<`object`, `object`, `object`, `object`, `object`, `object`, `object`, `object`>                    | The blockstore to use |

**Returns**

[`BlockstoreStore`](https://docs.twine.world/twine-js/twine-protocol/twine-blockstore-store/classes/blockstorestore)

**Defined in**

[index.ts:25](https://github.com/twine-protocol/twine-js/blob/3800995f9c83f4f5711bcf3062ea754a1e4448ce/packages/twine-blockstore-store/src/index.ts#L25)

### Methods

#### \_cidOf()

> **\_cidOf**(`chain`, `index`): `Promise`<`null` | [`CID`](https://docs.twine.world/twine-js/twine-protocol/twine-core/classes/cid)<`unknown`, `number`, `number`, `Version`>>

Get cid of pulse with specified index

**Parameters**

| Parameter | Type      | Description   |
| --------- | --------- | ------------- |
| `chain`   | `IntoCid` | The chain CID |
| `index`   | `number`  | The index     |

**Returns**

`Promise`<`null` | [`CID`](https://docs.twine.world/twine-js/twine-protocol/twine-core/classes/cid)<`unknown`, `number`, `number`, `Version`>>

The CID of the pulse, or null if not found

**Defined in**

[index.ts:88](https://github.com/twine-protocol/twine-js/blob/3800995f9c83f4f5711bcf3062ea754a1e4448ce/packages/twine-blockstore-store/src/index.ts#L88)

***

#### reIndex()

> **reIndex**(`latestCid`): `Promise`<`void`>

Reindex a chain

**Parameters**

| Parameter   | Type      | Description                 |
| ----------- | --------- | --------------------------- |
| `latestCid` | `IntoCid` | The CID of the latest pulse |

**Returns**

`Promise`<`void`>

**Defined in**

[index.ts:107](https://github.com/twine-protocol/twine-js/blob/3800995f9c83f4f5711bcf3062ea754a1e4448ce/packages/twine-blockstore-store/src/index.ts#L107)

***

#### fetchIndex()

> **fetchIndex**(`chain`, `index`): `Promise`<`null` | `Chain` | `Pulse`>

fetch by index

**Parameters**

| Parameter | Type      | Description   |
| --------- | --------- | ------------- |
| `chain`   | `IntoCid` | The chain CID |
| `index`   | `number`  | The index     |

**Returns**

`Promise`<`null` | `Chain` | `Pulse`>

**Defined in**

[index.ts:137](https://github.com/twine-protocol/twine-js/blob/3800995f9c83f4f5711bcf3062ea754a1e4448ce/packages/twine-blockstore-store/src/index.ts#L137)

***

#### save()

> **save**(`twine`): `Promise`<`void`>

Save a twine to storage

**Parameters**

| Parameter | Type                  | Description       |
| --------- | --------------------- | ----------------- |
| `twine`   | `Twine`<`TwineValue`> | The twine to save |

**Returns**

`Promise`<`void`>

**Implementation of**

`Store.save`

**Defined in**

[index.ts:145](https://github.com/twine-protocol/twine-js/blob/3800995f9c83f4f5711bcf3062ea754a1e4448ce/packages/twine-blockstore-store/src/index.ts#L145)

***

#### saveMany()

> **saveMany**(`twines`): `Promise`<`void`>

Save many twines to storage

**Parameters**

| Parameter | Type                                 | Description        |
| --------- | ------------------------------------ | ------------------ |
| `twines`  | `AnyIterable`<`Twine`<`TwineValue`>> | The twines to save |

**Returns**

`Promise`<`void`>

**Implementation of**

`Store.saveMany`

**Defined in**

[index.ts:164](https://github.com/twine-protocol/twine-js/blob/3800995f9c83f4f5711bcf3062ea754a1e4448ce/packages/twine-blockstore-store/src/index.ts#L164)

***

#### delete()

> **delete**(`cid`): `Promise`<`void`>

Delete a twine from storage

**Parameters**

| Parameter | Type      | Description                    |
| --------- | --------- | ------------------------------ |
| `cid`     | `IntoCid` | The CID of the twine to delete |

**Returns**

`Promise`<`void`>

**Implementation of**

`Store.delete`

**Defined in**

[index.ts:170](https://github.com/twine-protocol/twine-js/blob/3800995f9c83f4f5711bcf3062ea754a1e4448ce/packages/twine-blockstore-store/src/index.ts#L170)

***

#### fetch()

> **fetch**(`cid`): `Promise`<`null` | `Chain` | `Pulse`>

Fetch a twine by it's CID

**Parameters**

| Parameter | Type      |
| --------- | --------- |
| `cid`     | `IntoCid` |

**Returns**

`Promise`<`null` | `Chain` | `Pulse`>

**Implementation of**

`Store.fetch`

**Defined in**

[index.ts:204](https://github.com/twine-protocol/twine-js/blob/3800995f9c83f4f5711bcf3062ea754a1e4448ce/packages/twine-blockstore-store/src/index.ts#L204)

***

#### chains()

> **chains**(): `AsyncIterable`<`Chain`, `any`, `any`>

Get the chains that are known to the resolver

**Returns**

`AsyncIterable`<`Chain`, `any`, `any`>

An sync/async iterable of chains

**Example**

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

**Implementation of**

`Store.chains`

**Defined in**

[index.ts:221](https://github.com/twine-protocol/twine-js/blob/3800995f9c83f4f5711bcf3062ea754a1e4448ce/packages/twine-blockstore-store/src/index.ts#L221)

***

#### pulses()

> **pulses**(`chain`, `start`?, `options`?): `AsyncIterable`<`Pulse`, `any`, `any`>

Get the pulses of a chain

**Parameters**

| Parameter  | Type                  | Description                                          |
| ---------- | --------------------- | ---------------------------------------------------- |
| `chain`    | `IntoCid`             | The chain CID or chain itself to get the pulses from |
| `start`?   | `number` \| `IntoCid` | The index or CID of the pulse to start from          |
| `options`? | `ResolveOptions`      | Options for the resolution                           |

**Returns**

`AsyncIterable`<`Pulse`, `any`, `any`>

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)
}
```

**Implementation of**

`Store.pulses`

**Defined in**

[index.ts:231](https://github.com/twine-protocol/twine-js/blob/3800995f9c83f4f5711bcf3062ea754a1e4448ce/packages/twine-blockstore-store/src/index.ts#L231)

***

#### has()

> **has**(`cid`): `Promise`<`boolean`>

Check if a Twine is present in the blockstore

**Parameters**

| Parameter | Type      |
| --------- | --------- |
| `cid`     | `IntoCid` |

**Returns**

`Promise`<`boolean`>

**Implementation of**

`Store.has`

**Defined in**

[index.ts:256](https://github.com/twine-protocol/twine-js/blob/3800995f9c83f4f5711bcf3062ea754a1e4448ce/packages/twine-blockstore-store/src/index.ts#L256)

***

#### resolveIndex()

> **resolveIndex**(`chain`, `index`, `options`?): `Promise`<`PulseResolution`>

Resolve a pulse by index

**Parameters**

| Parameter  | Type             | Description                                             |
| ---------- | ---------------- | ------------------------------------------------------- |
| `chain`    | `IntoCid`        | The chain CID or chain itself to resolve the pulse from |
| `index`    | `number`         | The index of the pulse to resolve                       |
| `options`? | `ResolveOptions` | Options for the resolution                              |

**Returns**

`Promise`<`PulseResolution`>

A pulse resolution

**Example**

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

**Implementation of**

`Store.resolveIndex`

**Defined in**

[index.ts:267](https://github.com/twine-protocol/twine-js/blob/3800995f9c83f4f5711bcf3062ea754a1e4448ce/packages/twine-blockstore-store/src/index.ts#L267)

***

#### resolve()

**resolve(query, options)**

> **resolve**(`query`, `options`?): `Promise`<`PulseResolution`>

Resolves a twine query

**Parameters**

| Parameter  | Type                    |
| ---------- | ----------------------- |
| `query`    | `IntoResolvePulseQuery` |
| `options`? | `ResolveOptions`        |

**Returns**

`Promise`<`PulseResolution`>

**Implementation of**

`Store.resolve`

**Defined in**

[index.ts:276](https://github.com/twine-protocol/twine-js/blob/3800995f9c83f4f5711bcf3062ea754a1e4448ce/packages/twine-blockstore-store/src/index.ts#L276)

**resolve(query, options)**

> **resolve**(`query`, `options`?): `Promise`<`ChainResolution`>

Resolve a pulse (with its chain) from a query

**Parameters**

| Parameter  | Type                    |
| ---------- | ----------------------- |
| `query`    | `IntoResolveChainQuery` |
| `options`? | `ResolveOptions`        |

**Returns**

`Promise`<`ChainResolution`>

**Implementation of**

`Store.resolve`

**Defined in**

[index.ts:277](https://github.com/twine-protocol/twine-js/blob/3800995f9c83f4f5711bcf3062ea754a1e4448ce/packages/twine-blockstore-store/src/index.ts#L277)

***

#### resolveLatest()

> **resolveLatest**(`chain`): `Promise`<`PulseResolution`>

Resolves the latest pulse for specified chain

**Parameters**

| Parameter | Type      |
| --------- | --------- |
| `chain`   | `IntoCid` |

**Returns**

`Promise`<`PulseResolution`>

**Implementation of**

`Store.resolveLatest`

**Defined in**

[index.ts:288](https://github.com/twine-protocol/twine-js/blob/3800995f9c83f4f5711bcf3062ea754a1e4448ce/packages/twine-blockstore-store/src/index.ts#L288)
