olodb
OT concurrent JSON database client and server over WebSockets.
Server: getting started in 5 steps
1. Installation
npm install olodb
Requirements:
- a
MongoDB
instance running on port 27017
2. Create the server
const olodb = ;const server = ;
3. Define the authentication function
server { // ...}
Based on the credentials object, this method should return a user id or null.
A null
user id will be intended as the user with minimum permissions.
By default it returns null
.
4. Define the users permissions
server { // ...}
For each combination of parameters userId
, collection
and docName
, it should return one of the following:
olojs.roles.OWNER
to grant write permissions to the user on the entire documentolojs.rights.WRITER
to grant write permissions to the user only on thedata
root keyolojs.rights.READER
to grant read-only permission to the userolojs.rights.NONE
to deny access
By default it returns always olojs.roles.OWNER
.
5. Start listening to incoming connections
server;
httpServer is a nodejs http.Server
Client: getting started in 5 steps
1. Installation
In NodeJS:
npm install olodb
In the browser:
jspm install olodb=github:onlabsorg/olodb
2. Connect to the remote store
const olodb = ;const store = "wss:/hostname";await store
The credentials
object is defined by the server-side server.auth
function.
3. Fetch a document
var doc = await store;await doc;
4. Read/Edit the document content
// retrieve and change the document root dictionaryvar root = doc;rootvalue = a:1 b:2 c:'x''y''z' d=u:10 v:20 w:30 s:"abcdef"; // retrieve and edit a primitive itemvar item = root;itemvalue // -> 1itemtype === "numb" // true // retrieve and edit a Dict itemvar dict = root;dictvalue // -> {u:10, v:20, w:30}dicttype === "dict"; // truedict; // change value of item d/vdict; // remove the key 'v' from the dictionary // retrieve and edit a List itemvar list = root;listvalue // -> ['x','y','z']listtype === "list"; // truelistsize === 3; // truelist; // change the value of item c/1list // c is now equal to ['x', 'xy', 'yy', z]list; // c is now equal to ['x', 'xy', z] // retrieve and edit a Text itemvar text = root;textvalue // -> "abcdef"textsize === 6 // truetext; // s is now equal to "axxxbcdef";text; // s is now equal to "abcdef" // retrieve deep itemsvar u = doc;var u = doc;var u = doc;
5. Subscribe to changes
var subscription = doc;// ...subscription;
Every time the document item d
changes, the callback gets called with
an olojs Change
object as parameter.
6. Close
await doc;await store;
Dcumentation
olodb
is an implementation of the olojs Store.
You can refer to the olojs documentation for detailed store API.
Related projects
You may also be interested in the following projects:
- olojs: A library defining the Store interface that
olodb
implements. - ShareDB: A database frontend for concurrent editing systems on which olodb is based
- olowc: Collection of web-components acting as web interface to the remote data structures provided by olojs.
- olopy: A Python implementation of olojs.
- olowa: A web application leveraging olojs, olowc and [olodb][] to create a concurrent data browser and editor for the web.
License
MIT - Copyright (c) 2017 Marcello Del Buono m.delbuono@onlabs.org