Initializing Stores
Permissions
It's recommended to specify permissions on either Tome or its subclasses. The schema is:
interface Perm {
read: 'our' | 'space' | 'open'
write: 'our' | 'space' | 'open'
admin: 'our' | 'space' | 'open'
}ouris our ship only (src.bowl)spaceis any ship in the current Holium space. If Realm is not installed, this becomesour.openis anyone, including comets.
read / write / admin mean slightly different things based on the store type, so they will be described below.
Tome
TomeTome.init(api?: Urbit, app?: string, options?)
api: The optional Urbit connection to be used for requests. If not set, TomeDB will attempt to use localStorage for storing key-value pairs.app: An optional app name to store under. Defaults to'all'. It's recommended to set this to the name of your application (be wary of collisions, though!)
options
Optional ship, space, agent, permissions, and realm flag for initializing a Tome.
options: {
realm?: boolean = false
ship?: string = api.ship
space?: string = 'our'
agent?: string = 'tome'
permissions?: Perm
}shipcan be specified with or without the~.agentspecifies both the desk and agent name that the JavaScript client will use. This is useful if you want to distribute a copy of TomeDB in the desk alongside your application.If
realmisfalse, Tome will useshipandspaceas specified.If
realmistrue,shipandspacemust be either set together or not at all.If neither are set, Tome will automatically detect and use the current Realm space and corresponding host ship, as well as handle switching application data when a user changes spaces in Realm.
To create a "locked" Tome, specify
shipandspacetogether. A locked Tome will work only in that specific space (think internal DAO tooling).
permissionsis a default permissions level to be used by sub-classes. When creating many store instances with the same permissions, simply specify them once here.
Returns: Promise<Tome>
All storage types must be created from a Tome instance, so do this first.
Key-value
Key-valuedb.keyvalue(options?)
options
Optional bucket, permissions, preload flag, and callbacks for the key-value store.
bucketis the bucket name to store key-value pairs under. If your app needs multiple key-value stores with different permissions, they should be different buckets. Separating buckets can also save on download sizes depending on the application.preloadis whether the client should fetch and cache all key-value pairs in the bucket, and subscribe to live updates. This helps with responsiveness when using an application, since most requests won't go to Urbit.permissionsis the permissions for the key-value store. If not set, defaults to the Tome-level permissions.readcan read any key-value pairs from the bucket.writecan create new key-value pairs or update their own values.admincan create or overwrite any values in the bucket.
onDataChangeis called whenever data in the key-value store changes, and can be used to re-render an application with new data.onReadyChangeis called whenever the store changesreadystate: after initial app configuration, and whenever a user changes between spaces in Realm. Use combined withpreloadset tofalseto know when to show a loading screen, and when to start making requests.If preload is
true, useonLoadChangeinstead to be notified when all data has been loaded and is addressable. This also handles the case of switching between Realm spaces.onWriteChangeandonAdminChangeare called when the current user'swriteandadminpermissions have been detected to change.
Returns: Promise<KeyValueStore>
Initialize or connect to a key-value store. It uses localStorage if the corresponding Tome has no Urbit connection.
Feed + Log
Feed + Logdb.feed(options?) or db.log(options?)
options
Optional bucket, permissions, preload flag, and callbacks for the log or feed store.
permissions is the permissions for the feedlog store. If not set, defaults to the Tome-level permissions.
readcan read any posts and metadata from the bucket.For a
feed,writecan create or update their own posts / links. For alog,writeonly allows creating new posts.admincan create or overwrite any posts / links in the bucket.
Refer to the options under key-value for more information, as the rest are functionally identical.
Returns: Promise<FeedStore> or Promise<LogStore>
Initialize a feed or log store. These must be created from a Tome with a valid Urbit connection.
feed and log are very similar, the only differences are:
writefor a log can't update any values. This makes a log more similar to an "append-only" data structure."Links" (comments, reactions, etc.) currently aren't supported for logs but are for feeds.
Last updated