[API reference](https://evolu.dev/docs/api-reference) › [@evolu/common](https://evolu.dev/docs/api-reference/common) › [local‑first/Relay](https://evolu.dev/docs/api-reference/common/local-first/Relay) › RelayStorage

Defined in: [packages/common/src/local-first/Relay.ts:212](https://github.com/evoluhq/evolu/blob/1ef91d4e21b74fa0c122e48558188dc42676c429/packages/common/src/local-first/Relay.ts#L212)

The storage a relay syncs with. Unlike a client's [Storage](https://evolu.dev/docs/api-reference/common/local-first/Storage/interfaces/Storage), it checks
the [OwnerWriteKey](https://evolu.dev/docs/api-reference/common/local-first/Owner/variables/OwnerWriteKey) of every write.

## Extends

- [`Omit`](https://www.typescriptlang.org/docs/handbook/utility-types.html#omittype-keys)\<[`Storage`](https://evolu.dev/docs/api-reference/common/local-first/Storage/interfaces/Storage), `"writeMessages"`\>

## Extended by

- [`RelaySqliteStorage`](https://evolu.dev/docs/api-reference/common/local-first/Relay/interfaces/RelaySqliteStorage)

## Properties

<a id="findlowerbound"></a>

### findLowerBound

```ts
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](https://github.com/evoluhq/evolu/blob/1ef91d4e21b74fa0c122e48558188dc42676c429/packages/common/src/local-first/Storage.ts#L190)

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](https://evolu.dev/docs/api-reference/common/local-first/Storage/variables/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`](https://evolu.dev/docs/api-reference/common/local-first/Storage/interfaces/Storage).[`findLowerBound`](https://evolu.dev/docs/api-reference/common/local-first/Storage/interfaces/Storage#findlowerbound)

---

<a id="fingerprint"></a>

### fingerprint

```ts
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](https://github.com/evoluhq/evolu/blob/1ef91d4e21b74fa0c122e48558188dc42676c429/packages/common/src/local-first/Storage.ts#L155)

Returns the [Fingerprint](https://evolu.dev/docs/api-reference/common/local-first/Storage/type-aliases/Fingerprint) of the owner's timestamps from index `begin`
up to, but not including, `end`, where `begin` is at most `end`.

#### Inherited from

[`Storage`](https://evolu.dev/docs/api-reference/common/local-first/Storage/interfaces/Storage).[`fingerprint`](https://evolu.dev/docs/api-reference/common/local-first/Storage/interfaces/Storage#fingerprint)

---

<a id="fingerprintranges"></a>

### fingerprintRanges

```ts
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](https://github.com/evoluhq/evolu/blob/1ef91d4e21b74fa0c122e48558188dc42676c429/packages/common/src/local-first/Storage.ts#L174)

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`](https://evolu.dev/docs/api-reference/common/local-first/Storage/interfaces/Storage).[`fingerprintRanges`](https://evolu.dev/docs/api-reference/common/local-first/Storage/interfaces/Storage#fingerprintranges)

---

<a id="getsize"></a>

### getSize

```ts
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](https://github.com/evoluhq/evolu/blob/1ef91d4e21b74fa0c122e48558188dc42676c429/packages/common/src/local-first/Storage.ts#L149)

Returns the number of the owner's timestamps.

#### Inherited from

[`Storage`](https://evolu.dev/docs/api-reference/common/local-first/Storage/interfaces/Storage).[`getSize`](https://evolu.dev/docs/api-reference/common/local-first/Storage/interfaces/Storage#getsize)

---

<a id="iterate"></a>

### iterate

```ts
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](https://github.com/evoluhq/evolu/blob/1ef91d4e21b74fa0c122e48558188dc42676c429/packages/common/src/local-first/Storage.ts#L204)

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](https://evolu.dev/docs/api-reference/common/Sqlite/interfaces/Sqlite#iterate) requires.

#### Inherited from

[`Storage`](https://evolu.dev/docs/api-reference/common/local-first/Storage/interfaces/Storage).[`iterate`](https://evolu.dev/docs/api-reference/common/local-first/Storage/interfaces/Storage#iterate)

---

<a id="readdbchange"></a>

### readDbChange

```ts
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](https://github.com/evoluhq/evolu/blob/1ef91d4e21b74fa0c122e48558188dc42676c429/packages/common/src/local-first/Storage.ts#L234)

Read encrypted [DbChange](https://evolu.dev/docs/api-reference/common/local-first/Storage/variables/DbChange)s from storage.

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

#### Inherited from

[`Storage`](https://evolu.dev/docs/api-reference/common/local-first/Storage/interfaces/Storage).[`readDbChange`](https://evolu.dev/docs/api-reference/common/local-first/Storage/interfaces/Storage#readdbchange)

---

<a id="validatewritekey"></a>

### validateWriteKey

```ts
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](https://github.com/evoluhq/evolu/blob/1ef91d4e21b74fa0c122e48558188dc42676c429/packages/common/src/local-first/Relay.ts#L218)

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](https://evolu.dev/docs/api-reference/common/local-first/Protocol/interfaces/ProtocolWriteError).

---

<a id="writemessages"></a>

### writeMessages

```ts
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](https://github.com/evoluhq/evolu/blob/1ef91d4e21b74fa0c122e48558188dc42676c429/packages/common/src/local-first/Relay.ts#L234)

Writes the messages of a writer with `writeKey`, like
[Storage.writeMessages](https://evolu.dev/docs/api-reference/common/local-first/Storage/interfaces/Storage#writemessages). A relay doesn't call
[RelayStorage.validateWriteKey](https://evolu.dev/docs/api-reference/common/local-first/Relay/interfaces/RelayStorage#validatewritekey) before it, so it checks the key
itself, under the owner's lock.

Returns [StorageWriteKeyError](https://evolu.dev/docs/api-reference/common/local-first/Relay/interfaces/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.