API - Cloud Doc
Cloud docs are named client-side references to data. They support transactions and provide high-level functionality for observing and mutating data on the client, which will by syncronized to the upstream source. Each doc lives in the domain specified by the cloud client.
Usage
Client-side docs are retrieved from the cloud client. For example:
import createCloudClient from "@aven-cloud/cloud/createCloudClient";
const cloud = createCloudClient({ source });
const doc = cloud.get("MyDoc");
From there, data can be saved:
await doc.put({ my: 'data' });
// now the new data will be available with doc.getValue()
Those observing the same doc can see the data as it changes:
doc.observeValue.subscribe({
next: value => {
console.log("value here will be {my: 'data'}");
}
});
Doc Children
Docs can have children which are accessed with a slash in the name, or by calling ".get" on the parent doc:
const parent = cloud.get('MyDoc');
const child = cloud.get('MyDoc/Details');
// which is equivalent to:
const child = parent.get('Details');
Children documents are deleted when the parent is deleted. Permissions applied to the parent affect the child as well. Of course children can be arbitrarily deep.
Properties/methods
isConnected
A behavior subject of a boolean regarding the connectivity of the doc. Will be true if the current doc's value is syncronized to the data source, otherwise false.
observe
A behavior subject of the local doc's state, including the fetch time, most recent put time, and current id.
observeValue
A behavior subject of the doc's value, or undefined until the value is known. This observed value will be the same as `doc.getBlock().getValue()` or `doc.getValue()`
getId
Returns the id string of the current blockĀ of data. Should be undefined if the id is not yet known and null if the id is known to be empty.
getValue()
Syncronously retrieve the current value of the doc, or `undefined` if not loaded.
async fetch()
Command a fetch of the value of the doc from the data source, ensuring the id is up to date (although the value may not be fetched)
async fetchValue()
Will make sure the current ID is fetched and the value of the corresponding block has been fetched. If the id is not known, the value and the ID will be fetched from the data source simultaneously.