Skip to main content
The Deno 2 Release Candidate is here
Learn more
Module

x/willow/mod.deno.ts>Store

Exploring Willow in the most efficient and sound programming language
Go to Latest
class Store
extends EventTarget
Re-export
import { Store } from "https://deno.land/x/willow@0.2.1/mod.deno.ts";

A local set of a particular namespace's authorised entries to be written to, read from, and synced with other Stores. Applies the concepts of the Willow Data Model to the set of entries stored inside.

Keeps all data in memory unless persisted entry / payload drivers are specified.

https://willowprotocol.org/specs/data-model/index.html#store

Type Parameters

NamespaceId
SubspaceId
PayloadDigest
AuthorisationOpts
AuthorisationToken
Prefingerprint
Fingerprint

Methods

private
insertEntry(unnamed 0: { path: Path; subspace: SubspaceId; timestamp: bigint; hash: PayloadDigest; length: bigint; authToken: AuthorisationToken; }): Promise<Entry<NamespaceId, SubspaceId, PayloadDigest>[]>

Retrieve a AuthorisationToken for a given entry, if held in storage.

getPayload(entry: Entry<NamespaceId, SubspaceId, PayloadDigest>): Promise<Payload | undefined>

Retrieve a Payload for a given entry, if held in storage.

Attempt to store an authorised entry in the Store.

An entry will not be ingested if it is unauthorised; if a newer entry with the same path and subspace are present; or if a newer entry with a path that is a prefix of the given entry exists. See the Willow Data Model's Concepts for more information.

Additionally, if the entry's path is a prefix of already-held older entries, those entries will be removed from the Store. See prefix pruning for more information.

ingestPayload(
entryDetails: { path: Path; timestamp: bigint; subspace: SubspaceId; },
payload: AsyncIterable<Uint8Array>,
offset?,
): Promise<IngestPayloadEvent>

Attempt to store the corresponding payload for one of the store's entries.

A payload will not be ingested if the given entry is not stored in the store; if the hash of the payload does not match the entry's; or if it is already held.

prunableEntries(unnamed 0: { path: Path; subspace: SubspaceId; timestamp: bigint; }): Promise<{ entry: Entry<NamespaceId, SubspaceId, PayloadDigest>; authTokenHash: PayloadDigest; }[]>

Return an array of Entry which would be pruned by a given Entry were it to be ingested. Can be used to prevent potentially undesirable destructive operations.

query(
areaOfInterest: AreaOfInterest<SubspaceId>,
order: QueryOrder,
reverse?,
): AsyncIterable<[Entry<NamespaceId, SubspaceId, PayloadDigest>, Payload | undefined, AuthorisationToken]>

Retrieve an asynchronous iterator of entry-payload-authorisation triples from the store for a given AreaOfInterest.

queryRange(range: Range3d<SubspaceId>, order: "newest" | "oldest"): AsyncIterable<[Entry<NamespaceId, SubspaceId, PayloadDigest>, Payload | undefined, AuthorisationToken]>

Retrieve an asynchronous iterator of entry-payload-authorisation triples from the store for a given Range.

Always returns entries in chronological order.

set(input: EntryInput<SubspaceId>, authorisation: AuthorisationOpts)

Create a new authorised entry for a given payload, and store both in the store. An entry will not be ingested if it is unauthorised; if a newer entry with the same path and subspace are present; or if a newer entry with a path that is a prefix of the given entry exists. See the Willow Data Model's Concepts for more information.

Additionally, if the new entry's path is a prefix of already-held older entries, those entries will be removed from the Store. See prefix pruning for more information.

splitRange(range: Range3d<SubspaceId>, knownSize: number): Promise<[Range3d<SubspaceId>, Range3d<SubspaceId>]>
summarise(range: Range3d<SubspaceId>): Promise<{ fingerprint: Prefingerprint; size: number; }>

Summarise a given Range into a PreFingerprint mapping to the set of entries included by that range.

This is mostly used during sync for 3d range-based set reconciliation.