- Install and run Argos (on port 80) with test data.
npm install hypertopic
const hypertopic = require('hypertopic');
let db = hypertopic([
"http:https://localhost",
"https://steatite.utt.fr"
]);
const _log = (x) => console.log(JSON.stringify(x, null, 2));
const _error = (x) => console.error(x.message);
- on a user
db.getView('/user/vitraux')
.then(_log);
- on an item
db.getView('/item/Vitraux - Bénel/85bb03f5e4930f3b9d1ef9afbfa92421b8e2e23b')
.then(_log);
- on a corpus (with all its items)
db.getView('/corpus/Vitraux - Bénel')
.then(_log);
- on a viewpoint
db.getView('/viewpoint/a76306e4f17ed4f79e7e481eb9a1bd06')
.then(_log);
- on several of them
db.getView(['/corpus/Vitraux - Bénel','/corpus/Vitraux - Recensement'])
.then(_log);
- on all corpora and viewpoints of a user
db.getView('/user/vitraux')
.then(x => [
...x.vitraux.viewpoint.map(y => `/viewpoint/${y.id}`),
...x.vitraux.corpus.map(y => `/corpus/${y.id}`)
])
.then(db.getView)
.then(_log);
- Create an object (with an automatic ID)
db.auth('alice', 'whiterabbit')
.post({item_name:'Bond', item_corpus:'TEST'})
.then(_log)
.catch(_error);
- Create an object with a given ID
db.auth('alice', 'whiterabbit')
.post({_id:'007', item_name:'Bond', item_corpus:'TEST'})
.then(_log)
.catch(_error);
- Update an object
db.auth('alice', 'whiterabbit')
.get({_id:'007'})
.then(x => Object.assign(x, {item_name:'James Bond'}))
.then(db.post)
.then(_log)
.catch(_error);
- Delete an object with update conflict detection
db.auth('alice', 'whiterabbit')
.delete({_id:'007', _rev:'1-xxxxxxxxx'})
.then(_log)
.catch(_error);
- Delete an object with no conflict detection (to be used with caution!)
db.auth('alice', 'whiterabbit')
.get({_id:'007'})
.then(db.delete)
.then(_log)
.catch(_error);
- Item attributes
db.auth('alice', 'whiterabbit')
.item({_id:'007', item_corpus:'agents'})
.setAttributes({item_name:'James Bond', weapon:'Walther PPK'})
.then(_log)
.catch(_error);
db.auth('alice', 'whiterabbit')
.item({_id:'007', item_corpus:'agents'})
.unsetAttribute('weapon')
.then(_log)
.catch(_error);
- Item topics
db.auth('alice', 'whiterabbit')
.item({_id:'007', item_corpus:'agents'})
.setTopic('topic-octopussy', 'viewpoint-missions')
.then(_log)
.catch(_error);
db.auth('alice', 'whiterabbit')
.item({_id:'007', item_corpus:'agents'})
.unsetTopic('topic-octopussy')
.then(_log)
.catch(_error);
- Item resources
db.auth('alice', 'whiterabbit')
.item({_id:'007', item_corpus:'agents'})
.setResource('hello.txt', 'text/plain', 'My name is Bond, James Bond.')
.then(_log)
.catch(_error);
db.auth('alice', 'whiterabbit')
.item({_id:'007', item_corpus:'agents'})
.unsetResource('hello.txt')
.then(_log)
.catch(_error);
- Item links
db.auth('alice', 'whiterabbit')
.item({_id:'007', item_corpus:'agents'})
.setLink('has for superior', 'executives', 'M')
.then(_log)
.catch(_error);
db.auth('alice', 'whiterabbit')
.item({_id:'007', item_corpus:'agents'})
.unsetLink('has for superior', 'executives', 'M')
.then(_log)
.catch(_error);