MemoryStore

@twine-protocol/twine-core v0.1.0 • Docs


twine-js / @twine-protocol/twine-core / MemoryStore

Class: MemoryStore

A store that keeps twines in memory

This store is the base for the TwineCache.

Extended by

Implements

Constructors

new MemoryStore()

new MemoryStore(maxSize): MemoryStore

Create a new memory store

Parameters

Parameter
Type
Default value
Description

maxSize

number

0

The maximum number of twines to keep in memory (default infinite)

Returns

MemoryStore

Defined in

packages/twine-core/src/store/memory-store.ts:60

Properties

Property
Modifier
Type
Description
Defined in

chainStore

protected

Map<string, Chain>

Chains are stored in a map with the CID as the key

chainStorageMeta

protected

Map<string, ChainStorageMeta>

Chain storage metadata

pulseStore

protected

CacheMap<string, Pulse>

Pulses are stored in a map with the CID as the key

maxSize

protected

number

The maximum number of twines to keep in memory

Methods

setMaxSize()

setMaxSize(maxSize): void

Set the maximum number of twines to keep in memory

If the store is already larger than the new max size, the oldest twines will be removed.

Parameters

Parameter
Type

maxSize

number

Returns

void

Defined in

packages/twine-core/src/store/memory-store.ts:70


fetch()

fetch(cid): null | Chain | Pulse

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

The CID of the twine to fetch

Returns

null | Chain | Pulse

Implementation of

Store.fetch

Defined in

packages/twine-core/src/store/memory-store.ts:81


has()

has(cid): boolean

Check if a cid can be resolved

Parameters

Parameter
Type
Description

cid

The CID to check

Returns

boolean

True if the CID can be resolved, false otherwise

Implementation of

Store.has

Defined in

packages/twine-core/src/store/memory-store.ts:97


delete()

delete(cid): void

Delete a twine from storage

Parameters

Parameter
Type
Description

cid

The CID of the twine to delete

Returns

void

Implementation of

Store.delete

Defined in

packages/twine-core/src/store/memory-store.ts:105


save()

save(twine): void

Save a twine to storage

Parameters

Parameter
Type
Description

twine

Twine<any>

The twine to save

Returns

void

Implementation of

Store.save

Defined in

packages/twine-core/src/store/memory-store.ts:147


saveMany()

Save many twines to storage

saveMany(twines)

saveMany(twines): Promise<void>

Save many twines to storage

Parameters

Parameter
Type
Description

twines

AsyncIterable<Twine<TwineValue>, any, any>

The twines to save

Returns

Promise<void>

Implementation of

Store.saveMany

Defined in

packages/twine-core/src/store/memory-store.ts:159

saveMany(twines)

saveMany(twines): void

Save many twines to storage

Parameters

Parameter
Type

twines

Iterable<Twine<TwineValue>, any, any>

Returns

void

Implementation of

Store.saveMany

Defined in

packages/twine-core/src/store/memory-store.ts:160


chains()

chains(): MapIterator<Chain>

Get an iterator of all the chains in the store

Returns

MapIterator<Chain>

Implementation of

Store.chains

Defined in

packages/twine-core/src/store/memory-store.ts:181


pulses()

pulses(chainCid, start?, options?): AsyncGenerator<Pulse, any, any>

Get an async iterator of all the pulses in a chain

Parameters

Parameter
Type

chainCid

start?

number | IntoCid

Returns

AsyncGenerator<Pulse, any, any>

Implementation of

Store.pulses

Defined in

packages/twine-core/src/store/memory-store.ts:188


resolve()

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.

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

The query to resolve

options?

Options for the resolution

Returns

Promise<ChainResolution>

A chain or pulse resolution

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

packages/twine-core/src/store/memory-store.ts:215

resolve(query, options)

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

Resolve a pulse (with its chain) from a query

Parameters

Parameter
Type

Returns

Promise<PulseResolution>

A chain or pulse resolution

Implementation of

Store.resolve

Defined in

packages/twine-core/src/store/memory-store.ts:216


resolveLatest()

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

Resolve the latest pulse of a chain

Parameters

Parameter
Type
Description

chainCid

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

options?

Options for the resolution

Returns

Promise<PulseResolution>

A pulse resolution

Implementation of

Store.resolveLatest

Defined in

packages/twine-core/src/store/memory-store.ts:230


resolveIndex()

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

Resolve a pulse by index

Parameters

Parameter
Type
Description

chain

The chain CID or chain itself to resolve the pulse from

index

number

The index of the pulse to resolve

options?

Options for the resolution

Returns

Promise<PulseResolution>

A pulse resolution

Implementation of

Store.resolveIndex

Defined in

packages/twine-core/src/store/memory-store.ts:246

Last updated