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
maxSize
number
0
The maximum number of twines to keep in memory (default infinite)
Returns
Defined in
packages/twine-core/src/store/memory-store.ts:60
Properties
pulseStore
protected
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
maxSize
number
Returns
void
Defined in
packages/twine-core/src/store/memory-store.ts:70
fetch()
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
Returns
Implementation of
Defined in
packages/twine-core/src/store/memory-store.ts:81
has()
has(
cid
):boolean
Check if a cid can be resolved
Parameters
Returns
boolean
True if the CID can be resolved, false otherwise
Implementation of
Defined in
packages/twine-core/src/store/memory-store.ts:97
delete()
delete(
cid
):void
Delete a twine from storage
Parameters
Returns
void
Implementation of
Defined in
packages/twine-core/src/store/memory-store.ts:105
save()
save(
twine
):void
Save a twine to storage
Parameters
Returns
void
Implementation of
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
Returns
Promise
<void
>
Implementation of
Defined in
packages/twine-core/src/store/memory-store.ts:159
saveMany(twines)
saveMany(
twines
):void
Save many twines to storage
Parameters
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
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
Returns
AsyncGenerator
<Pulse
, any
, any
>
Implementation of
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
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
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
options
?
Returns
Promise
<PulseResolution
>
A chain or pulse resolution
Implementation of
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
Returns
Promise
<PulseResolution
>
A pulse resolution
Implementation of
Defined in
packages/twine-core/src/store/memory-store.ts:230
resolveIndex()
resolveIndex(
chain
,index
,options
?):Promise
<PulseResolution
>
Resolve a pulse by index
Parameters
index
number
The index of the pulse to resolve
Returns
Promise
<PulseResolution
>
A pulse resolution
Implementation of
Defined in
Last updated