From 21307c09ceda5969019ebd768cd5a10f4cbfdb36 Mon Sep 17 00:00:00 2001 From: Pedro Teixeira Date: Sun, 27 May 2018 18:28:15 +0100 Subject: [PATCH 1/2] dream API --- README.md | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/README.md b/README.md index a87f860..350f275 100644 --- a/README.md +++ b/README.md @@ -20,3 +20,78 @@ Distributed Applications and their internal building blocks exposed as reusable ## Examples - [peer-crdt-example](https://github.com/ipfs-shipyard/peer-crdt-example) + +## API + +### PeerStar + +```js +const PeerStar = require('peer-star') +``` + +### Self-Identity + +```js +const identity:Identity = PeerStar.identity([identityStore:IdentityStore]) +const identities:Array = identity.all() +const identity:Identity = identity.get('identity-id') +``` + +### Collaboration + +```js +const app:App = await PeerStar.app('my app id') +const collaboration:Collaboration = await app.collaborate('room name', identity) +``` + +### Document + +```js +collaboration.on('new document', (docName:String, whoDidIt:Peer) => { + console.log('document was created', docName) +}) + +collaboration.on('document removed', (docName:String, byPeer:Peer) => { + console.log('document %s was removed by peer', docName, byPeer) +}) + +collaboration.on('peer wants access', (peer:Peer, docName:String, accessLevelRequested:String) => { + await collaboration.grantAccess(peer, docName, accessLevelRequested) + await collaboration.revokeAccess(peer, docName, 'write') +}) + +// get doc +const doc:Doc = await collaboration.getDocument('document name') + +// request access to doc +const permission:DocPermission = await doc.requestAccess('write') + +// create doc +const doc2 = await collaboration.create('document type') + +doc2.name // has the name of the document + +doc.on('changed', (what:ChangeEvent, who:Peer) => { + // document changed +}) + +doc.on('stable', (lastChange:ChangeEvent) => { + // doc latest change is causally stable +}) + +doc.on('replicated', (peer:Peer) => { + // doc latest changes are replicated to given peer +}) + +doc. // mutate and access doc + +// peers +const peers:Set = doc.peers() + +// history of changes, paginated +const history:Sequence = doc.history([from [, count]]) + +await doc.leave() // leave document + +await collaboration.leave() +``` From 0945bfa83b93391a76f38440807f609e8b4b3329 Mon Sep 17 00:00:00 2001 From: Pedro Teixeira Date: Sun, 27 May 2018 18:36:16 +0100 Subject: [PATCH 2/2] changed a type --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 350f275..bd51c30 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ const PeerStar = require('peer-star') ```js const identity:Identity = PeerStar.identity([identityStore:IdentityStore]) -const identities:Array = identity.all() +const identities:Map = identity.all() const identity:Identity = identity.get('identity-id') ```