bridgething
Surfaces ↓

Store

client.store

Requests

you ask, the daemon answers; await the tagged result and check .ok

get(KVGet): Promise<TypedRequestResult<StorageResponse, never>>

push form: onResponse (subscribe instead of awaiting)

Webapp request: read a value out of KV storage by key.

const res = await client.store.get({ key: '...' });
if (res.ok) {
  console.log(res.response.key);
}

put(KVPut): Promise<TypedRequestResult<StorageResponse, never>>

push form: onResponse (subscribe instead of awaiting)

Webapp request: write a value to KV storage under key.

const res = await client.store.put({ key: '...', value: '...' });
if (res.ok) {
  console.log(res.response.key);
}

delete(KVDelete): Promise<TypedRequestResult<StorageResponse, never>>

push form: onResponse (subscribe instead of awaiting)

Webapp request: delete the KV storage entry at key.

const res = await client.store.delete({ key: '...' });
if (res.ok) {
  console.log(res.response.key);
}

Types

shapes referenced above, as the SDK types them

Webapp request: read a value out of KV storage by key.

type KVGet = {
  key: string;
};

Reply to KVGet, KVPut, and KVDelete alike; the request that produced it distinguishes which operation happened.

type StorageResponse = {
  key: string;
  value?: string; // `None` on a `Get` miss or after a `Delete`; `Put` always echoes back `Some` of what it just wrote.
};

Webapp request: write a value to KV storage under key.

type KVPut = {
  key: string;
  value: string;
};

Webapp request: delete the KV storage entry at key.

type KVDelete = {
  key: string;
};