HttpStore

@twine-protocol/twine-http-store v0.1.0Docs


twine-js / @twine-protocol/twine-http-store / HttpStore

Class: HttpStore

An HTTP client that implements Store

Implements

  • Store

Constructors

new HttpStore()

new HttpStore(baseUrl, fetcherOptions?): HttpStore

Create a new HTTP store

Parameters

Parameter
Type
Description

baseUrl

string

The base URL of the store

fetcherOptions?

FetcherOptions & HttpStoreOptions

Options for the fetcher

Returns

HttpStore

Defined in

index.ts:188

Methods

fetchChain()

fetchChain(chainCid): Promise<null | Chain>

Fetch a chain by CID without validation

Parameters

Parameter
Type

chainCid

IntoCid

Returns

Promise<null | Chain>

Defined in

index.ts:219


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

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

Implementation of

Store.chains

Defined in

index.ts:228


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

// 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:236


fetch()

fetch(cid): Promise<null | Twine<TwineValue>>

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 to do.

Parameters

Parameter
Type
Description

cid

IntoCid

The CID of the twine to fetch

Returns

Promise<null | Twine<TwineValue>>

Implementation of

Store.fetch

Defined in

index.ts:294


has()

has(cid): Promise<boolean>

Check if a cid can be resolved

Parameters

Parameter
Type
Description

cid

IntoCid

The CID to check

Returns

Promise<boolean>

True if the CID can be resolved, false otherwise

Example

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

Implementation of

Store.has

Defined in

index.ts:303


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:309


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

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

Implementation of

Store.resolveIndex

Defined in

index.ts:313


resolve()

resolve(query, options)

resolve(query, options?): Promise<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

The query to resolve

options?

ResolveOptions

Options for the resolution

Returns

Promise<ChainResolution>

A chain or pulse resolution

Examples

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

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

Implementation of

Store.resolve

Defined in

index.ts:327

resolve(query, options)

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

Resolve a pulse (with its chain) from a query

Parameters

Parameter
Type

query

IntoResolvePulseQuery

options?

ResolveOptions

Returns

Promise<PulseResolution>

Implementation of

Store.resolve

Defined in

index.ts:328


resolveLatest()

resolveLatest(chain, options?): Promise<PulseResolution>

Resolve the latest pulse of a chain

Parameters

Parameter
Type
Description

chain

IntoCid

The chain CID or chain itself to resolve the latest pulse from

options?

ResolveOptions

Options for the resolution

Returns

Promise<PulseResolution>

A pulse resolution

Examples

const resolution = await resolver.resolveLatest('bafybeib3...')
if (resolution.pulse) {
  console.log('pulse', resolution.pulse)
}
const { chain } = await resolver.resolve({ chain: 'bafybeib3...' })
const resolution = await resolver.resolveLatest(chain)

Implementation of

Store.resolveLatest

Defined in

index.ts:342


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:353


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:394

Last updated