Skip to content

Instantly share code, notes, and snippets.

@raucao
Last active March 26, 2023 10:47
Show Gist options
  • Save raucao/c2d3c4d95fbd9bc138df13010b891a32 to your computer and use it in GitHub Desktop.
Save raucao/c2d3c4d95fbd9bc138df13010b891a32 to your computer and use it in GitHub Desktop.
{
"dependencies": {
"node-fetch": "^2.6.9",
"remotestoragejs": "2.0.0-beta.6"
}
}
console.log('=============================================');
global.fetch = require('node-fetch');
const RemoteStorage = require('remotestoragejs');
const mod = {
async alfa () {
var Bookmarks = { name: 'bookmarks', builder: function(privateClient, publicClient) {
return {
exports: {
addBookmark: function(bookmark) {
return privateClient.storeFile('application/json', bookmark.id, bookmark);
}
}
}
}};
const remoteStorage = new RemoteStorage({
modules: [ Bookmarks ],
logging: true
});
'ready,not-connected,connected,disconnected,error,features-loaded,connecting,authing,wire-busy,wire-done,sync-req-done,sync-done,network-offline,network-online,sync-interval-change'.split(',').forEach(function (e) {
remoteStorage.on(e, function() {
console.log('did emit ' + e);
});
});
remoteStorage.access.claim('bookmarks', 'rw');
remoteStorage.caching.enable('/');
remoteStorage.on('ready', async () => {
await remoteStorage.bookmarks.addBookmark({
id: 'alfa',
url: 'http://unhosted.org',
description: 'Unhosted Adventures',
tags: ['unhosted', 'remotestorage', 'no-backend']
}).then(res => {
console.log('did write', res);
});
const bookmarks = await remoteStorage.scope('/bookmarks/').getAll('');
console.log(bookmarks);
})
}
};
mod.alfa();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment