Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const parseValue = value => {
if (typeof value === 'string') return safeJsonParse(value)
return null
}
' WHERE id = ?', [id], function (tx, result) {
if (result.rows.length) {
var metadata = safeJsonParse(result.rows.item(0).json);
fetchedDocs.set(id, metadata);
}
checkDone();
});
});
tx.executeSql(sql, [docId], function (tx, result) {
if (!result.rows.length) {
callback(createError(MISSING_DOC));
} else {
var data = safeJsonParse(result.rows.item(0).metadata);
callback(null, data.rev_tree);
}
});
});
function decodeMetadata(storedObject) {
if (!storedObject) {
return null;
}
var metadata = safeJsonParse(storedObject.data);
metadata.winningRev = storedObject.winningRev;
metadata.deleted = storedObject.deletedOrLocal === '1';
metadata.seq = storedObject.seq;
return metadata;
}
tx.executeSql(sql, sqlArgs, function (a, results) {
if (!results.rows.length) {
var missingErr = createError(MISSING_DOC, 'missing');
return finish(missingErr);
}
var item = results.rows.item(0);
metadata = safeJsonParse(item.metadata);
if (item.deleted && !opts.rev) {
var deletedErr = createError(MISSING_DOC, 'deleted');
return finish(deletedErr);
}
doc = unstringifyDoc(item.data, metadata.id, item.rev);
finish();
});
};
tx.executeSql(sql, sqlArgs, function (tx, result) {
function reportChange(change) {
return function () {
opts.onChange(change);
};
}
for (var i = 0, l = result.rows.length; i < l; i++) {
var item = result.rows.item(i);
var metadata = safeJsonParse(item.metadata);
lastSeq = item.maxSeq;
var doc = unstringifyDoc(item.winningDoc, metadata.id,
item.winningRev);
var change = opts.processChange(doc, metadata, opts);
change.seq = item.maxSeq;
var filtered = filter(change);
if (typeof filtered === 'object') {
return opts.complete(filtered);
}
if (filtered) {
numResults++;
if (opts.return_docs) {
results.push(change);
tx.executeSql(sql, sqlArgs, function (tx, result) {
for (var i = 0, l = result.rows.length; i < l; i++) {
var item = result.rows.item(i);
var metadata = safeJsonParse(item.metadata);
var id = metadata.id;
var data = unstringifyDoc(item.data, id, item.rev);
var winningRev = data._rev;
var doc = {
id: id,
key: id,
value: {rev: winningRev}
};
if (opts.include_docs) {
doc.doc = data;
doc.doc._rev = winningRev;
if (opts.conflicts) {
var conflicts = collectConflicts(metadata);
if (conflicts.length) {
doc.doc._conflicts = conflicts;
}
tx.executeSql(sql, [docId], function (tx, result) {
var metadata = safeJsonParse(result.rows.item(0).metadata);
traverseRevTree(metadata.rev_tree, function (isLeaf, pos,
revHash, ctx, opts) {
var rev = pos + '-' + revHash;
if (revs.indexOf(rev) !== -1) {
opts.status = 'missing';
}
});
var sql = 'UPDATE ' + DOC_STORE + ' SET json = ? WHERE id = ?';
tx.executeSql(sql, [safeJsonStringify(metadata), docId]);
});