MCPcopy Index your code
hub / github.com/apache/pouchdb / changes

Function changes

lib/index-browser.js:5673–5863  ·  view source on GitHub ↗
(opts, api, dbName, idb)

Source from the content-addressed store, hash-verified

5671}
5672
5673function changes(opts, api, dbName, idb) {
5674 opts = clone(opts);
5675
5676 if (opts.continuous) {
5677 var id = dbName + ':' + uuid$1();
5678 changesHandler.addListener(dbName, id, api, opts);
5679 changesHandler.notify(dbName);
5680 return {
5681 cancel: function () {
5682 changesHandler.removeListener(dbName, id);
5683 }
5684 };
5685 }
5686
5687 var docIds = opts.doc_ids && new Set(opts.doc_ids);
5688
5689 opts.since = opts.since || 0;
5690 var lastSeq = opts.since;
5691
5692 var limit = 'limit' in opts ? opts.limit : -1;
5693 if (limit === 0) {
5694 limit = 1; // per CouchDB _changes spec
5695 }
5696
5697 var results = [];
5698 var numResults = 0;
5699 var filter = filterChange(opts);
5700 var docIdsToMetadata = new Map();
5701
5702 var txn;
5703 var bySeqStore;
5704 var docStore;
5705 var docIdRevIndex;
5706
5707 function onBatch(batchKeys, batchValues, cursor) {
5708 if (!cursor || !batchKeys.length) { // done
5709 return;
5710 }
5711
5712 var winningDocs = new Array(batchKeys.length);
5713 var metadatas = new Array(batchKeys.length);
5714
5715 function processMetadataAndWinningDoc(metadata, winningDoc) {
5716 var change = opts.processChange(winningDoc, metadata, opts);
5717 lastSeq = change.seq = metadata.seq;
5718
5719 var filtered = filter(change);
5720 if (typeof filtered === 'object') { // anything but true/false indicates error
5721 return Promise.reject(filtered);
5722 }
5723
5724 if (!filtered) {
5725 return Promise.resolve();
5726 }
5727 numResults++;
5728 if (opts.return_docs) {
5729 results.push(change);
5730 }

Callers 1

initFunction · 0.70

Calls 8

cloneFunction · 0.70
filterChangeFunction · 0.70
openTransactionSafelyFunction · 0.70
idbErrorFunction · 0.70
runBatchedCursorFunction · 0.70
addListenerMethod · 0.45
notifyMethod · 0.45
removeListenerMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…