Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function encodeMetadata(metadata, winningRev, deleted) {
return {
data: safeJsonStringify(metadata),
winningRev: winningRev,
deletedOrLocal: deleted ? '1' : '0',
seq: metadata.seq, // highest seq for this doc
id: metadata.id
};
}
const stringifyValue = value => {
if (value === null) return ''
if (value === undefined) return ''
return safeJsonStringify(value)
}
if (revsToCompact.length) {
compactRevs(revsToCompact, id, tx);
}
docInfo.metadata.seq = seq;
var rev = docInfo.metadata.rev;
delete docInfo.metadata.rev;
var sql = isUpdate ?
'UPDATE ' + DOC_STORE +
' SET json=?, max_seq=?, winningseq=' +
'(SELECT seq FROM ' + BY_SEQ_STORE +
' WHERE doc_id=' + DOC_STORE + '.id AND rev=?) WHERE id=?'
: 'INSERT INTO ' + DOC_STORE +
' (id, winningseq, max_seq, json) VALUES (?,?,?,?);';
var metadataStr = safeJsonStringify(docInfo.metadata);
var params = isUpdate ?
[metadataStr, seq, winningRev, id] :
[id, seq, seq, metadataStr];
tx.executeSql(sql, params, function () {
results[resultsIdx] = {
ok: true,
id: docInfo.metadata.id,
rev: rev
};
fetchedDocs.set(id, docInfo.metadata);
callback();
});
}
}
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]);
});