Name Last Update
config Loading commit data...
dist Loading commit data...
scripts Loading commit data...
spec Loading commit data...
src Loading commit data...
.gitignore Loading commit data...
README.md Loading commit data...
index.d.ts Loading commit data...
package.json Loading commit data...
plugin.xml Loading commit data...

bsync-client

Allows downloading of files referenced by a http/https URI inside a couchdb/pouchdb record. The plugin works for cordova and electron projects.

Usage

Use it with pouchdb

import {ServiceLocator} from 'bsync-client/dist/browser-build';

ServiceLocator.getConfig().setConfig('itemKey', 'type');
ServiceLocator.getConfig().setConfig('itemValue', 'asset');

let localDb = new PouchDB('local-pouch-db');
let fileReplicator = ServiceLocator.getFileReplicator();

localDb.put({
    _id : "_design/index_type",
    views : {
        type : {
            map : function(doc) {
                if (doc[fileReplicator.itemKey]) { emit(doc[fileReplicator.itemKey]); }
            }.toString()
        }
    }
});  

fileReplicator.once('complete', () => {
    // All file are downloaded
});

db.query('index_type/type',{
    include_docs : true,
    key : fileReplicator.itemValue
}).then((res) => { 
    let docs = { docs : [] };                      
    for (let r of res.rows) {
        docs.docs.push(r.doc);
    }

    fileReplicator.pushChanges(docs);
    fileReplicator.start();
});

In electron projects

Within the main process bsync needs to be integrated an initiated.

import {Bsync} from 'bsync';
Bsync.init(ipcMain, filePath);

Testing (Browser/Node)

npm test

Testing (Cordova)

npm run test:cordova