API reference › @evolu/common › local‑first/Relay › RelaySqliteStorage

Defined in: packages/common/src/local-first/Relay.ts:261

A RelayStorage on SQLite.

Extends

Properties

deleteOwner

readonly deleteOwner: (ownerId: Uint8Array<ArrayBufferLike> & Brand<"Length16"> & Brand<"IdBytes"> & Brand<"OwnerIdBytes">) => Task<void, UnknownError>;

Defined in: packages/common/src/local-first/Relay.ts:266

Deletes all data of an owner after the owner's write in progress, holding the lock that RelayStorage.writeMessages holds.


findLowerBound

readonly findLowerBound: (ownerId: Uint8Array<ArrayBufferLike> & Brand<"Length16"> & Brand<"IdBytes"> & Brand<"OwnerIdBytes">, begin: number & Brand<"NonNaN"> & Brand<"Finite"> & Brand<"Int"> & Brand<"NonNegative">, end: number & Brand<"NonNaN"> & Brand<"Finite"> & Brand<"Int"> & Brand<"NonNegative">, upperBound: RangeUpperBound) => number & Brand<"NonNaN"> & Brand<"Finite"> & Brand<"Int"> & Brand<"NonNegative">;

Defined in: packages/common/src/local-first/Storage.ts:190

Returns the index of the owner's first timestamp not below upperBound, counted from the owner's first timestamp, or end when there is none or upperBound is InfiniteUpperBound.

begin must be 0 or the result for an earlier bound not above upperBound, and end the owner's size, so the result lies in [begin, end]. When end is 0 or equals begin, the result is end. Sync meets this because the protocol rejects range upper bounds that decrease.

Inherited from

Storage.findLowerBound


fingerprint

readonly fingerprint: (ownerId: Uint8Array<ArrayBufferLike> & Brand<"Length16"> & Brand<"IdBytes"> & Brand<"OwnerIdBytes">, begin: number & Brand<"NonNaN"> & Brand<"Finite"> & Brand<"Int"> & Brand<"NonNegative">, end: number & Brand<"NonNaN"> & Brand<"Finite"> & Brand<"Int"> & Brand<"NonNegative">) => Fingerprint;

Defined in: packages/common/src/local-first/Storage.ts:155

Returns the Fingerprint of the owner's timestamps from index begin up to, but not including, end, where begin is at most end.

Inherited from

Storage.fingerprint


fingerprintRanges

readonly fingerprintRanges: (ownerId: Uint8Array<ArrayBufferLike> & Brand<"Length16"> & Brand<"IdBytes"> & Brand<"OwnerIdBytes">, buckets: readonly [number & Brand<"NonNaN"> & Brand<"Finite"> & Brand<"Int"> & Brand<"NonNegative">, number & Brand<"NonNaN"> & Brand<"Finite"> & Brand<"Int"> & Brand<"NonNegative">], upperBound?: RangeUpperBound) => readonly FingerprintRange[];

Defined in: packages/common/src/local-first/Storage.ts:174

Computes fingerprints with their upper bounds in one call.

Each bucket is the end index of a range that starts at the previous bucket, or at 0 for the first. There is at least one, they never decrease, and none exceeds the owner's size, which only the last may equal: a range's upper bound is the timestamp at its bucket, and the last range's is upperBound.

This function can be replaced with many fingerprint/findLowerBound calls, but implementations can leverage it for batching and more efficient fingerprint computation.

Inherited from

Storage.fingerprintRanges


getSize

readonly getSize: (ownerId: Uint8Array<ArrayBufferLike> & Brand<"Length16"> & Brand<"IdBytes"> & Brand<"OwnerIdBytes">) => number & Brand<"NonNaN"> & Brand<"Finite"> & Brand<"Int"> & Brand<"NonNegative">;

Defined in: packages/common/src/local-first/Storage.ts:149

Returns the number of the owner's timestamps.

Inherited from

Storage.getSize


iterate

readonly iterate: (ownerId: Uint8Array<ArrayBufferLike> & Brand<"Length16"> & Brand<"IdBytes"> & Brand<"OwnerIdBytes">, begin: number & Brand<"NonNaN"> & Brand<"Finite"> & Brand<"Int"> & Brand<"NonNegative">, end: number & Brand<"NonNaN"> & Brand<"Finite"> & Brand<"Int"> & Brand<"NonNegative">, callback: (timestamp: Uint8Array<ArrayBufferLike> & Brand<"Length16"> & Brand<"TimestampBytes">, index: number & Brand<"NonNaN"> & Brand<"Finite"> & Brand<"Int"> & Brand<"NonNegative">) => boolean) => void;

Defined in: packages/common/src/local-first/Storage.ts:204

Calls callback with the owner's timestamps and their indexes from begin up to, but not including, end, where begin is at most end, until the callback returns false. No timestamp after the one it stops at is read. The callback can read, but must not write, the storage's database, as Sqlite.iterate requires.

Inherited from

Storage.iterate


readDbChange

readonly readDbChange: (ownerId: Uint8Array<ArrayBufferLike> & Brand<"Length16"> & Brand<"IdBytes"> & Brand<"OwnerIdBytes">, timestamp: Uint8Array<ArrayBufferLike> & Brand<"Length16"> & Brand<"TimestampBytes">) => EncryptedDbChange;

Defined in: packages/common/src/local-first/Storage.ts:234

Read encrypted DbChanges from storage.

The returned array must not be modified or reused later, because sync references it until it finishes its answer.

Inherited from

Storage.readDbChange


validateWriteKey

readonly validateWriteKey: (ownerId: Uint8Array<ArrayBufferLike> & Brand<"Length16"> & Brand<"IdBytes"> & Brand<"OwnerIdBytes">, writeKey: Uint8Array<ArrayBufferLike> & Brand<"Entropy"> & Brand<"Length16"> & Brand<"OwnerWriteKey">) => boolean;

Defined in: packages/common/src/local-first/Relay.ts:218

Returns whether writeKey is the owner's write key or the owner has none, without storing it. A relay calls it only for a request without messages, logs a throw, and answers the request with ProtocolWriteError.

Inherited from

RelayStorage.validateWriteKey


writeMessages

readonly writeMessages: (ownerIdBytes: Uint8Array<ArrayBufferLike> & Brand<"Length16"> & Brand<"IdBytes"> & Brand<"OwnerIdBytes">, writeKey: Uint8Array<ArrayBufferLike> & Brand<"Entropy"> & Brand<"Length16"> & Brand<"OwnerWriteKey">, messages: readonly [EncryptedCrdtMessage, EncryptedCrdtMessage]) => Task<void, RelayStorageWriteMessagesError>;

Defined in: packages/common/src/local-first/Relay.ts:234

Writes the messages of a writer with writeKey, like Storage.writeMessages. A relay doesn't call RelayStorage.validateWriteKey before it, so it checks the key itself, under the owner's lock.

Returns StorageWriteKeyError when the owner has another write key. An owner without one stores writeKey in the transaction of its first write that passes the quota check, so a request without messages or a refused write stores none.

Inherited from

RelayStorage.writeMessages