MCPcopy
hub / github.com/apache/pouchdb / generateReplicationId

Function generateReplicationId

lib/index-browser.js:9692–9727  ·  view source on GitHub ↗
(src, target, opts)

Source from the content-addressed store, hash-verified

9690// Generate a unique id particular to this replication.
9691// Not guaranteed to align perfectly with CouchDB's rep ids.
9692function generateReplicationId(src, target, opts) {
9693 var docIds = opts.doc_ids ? opts.doc_ids.sort(collate) : '';
9694 var filterFun = opts.filter ? opts.filter.toString() : '';
9695 var queryParams = '';
9696 var filterViewName = '';
9697 var selector = '';
9698
9699 // possibility for checkpoints to be lost here as behaviour of
9700 // JSON.stringify is not stable (see #6226)
9701 /* istanbul ignore if */
9702 if (opts.selector) {
9703 selector = JSON.stringify(opts.selector);
9704 }
9705
9706 if (opts.filter && opts.query_params) {
9707 queryParams = JSON.stringify(sortObjectPropertiesByKey(opts.query_params));
9708 }
9709
9710 if (opts.filter && opts.filter === '_view') {
9711 filterViewName = opts.view.toString();
9712 }
9713
9714 return Promise.all([src.id(), target.id()]).then(function (res) {
9715 var queryData = res[0] + res[1] + filterFun + filterViewName +
9716 queryParams + docIds + selector;
9717 return new Promise(function (resolve) {
9718 binaryMd5(queryData, resolve);
9719 });
9720 }).then(function (md5sum) {
9721 // can't use straight-up md5 alphabet, because
9722 // the char '/' is interpreted as being for attachments,
9723 // and + is also not url-safe
9724 md5sum = md5sum.replace(/\//g, '.').replace(/\+/g, '_');
9725 return '_local/' + md5sum;
9726 });
9727}
9728
9729function replicate(src, target, opts, returnValue, result) {
9730 var batches = []; // list of batches to be processed

Callers 1

initCheckpointerFunction · 0.70

Calls 3

binaryMd5Function · 0.70
toStringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…