Skip to content

Commit

Permalink
Merge pull request #79 from garbados/fix/preserve-rev
Browse files Browse the repository at this point in the history
fix: preserve ignored fields on read
  • Loading branch information
garbados authored Aug 10, 2021
2 parents 9e682b5 + 873bfb4 commit 5555f3c
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 706 deletions.
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ module.exports = {
}
const encrypted = {}
for (const key of this._ignore) {
encrypted[key] = doc[key]
// attach ignored fields to encrypted doc
if (key in doc) encrypted[key] = doc[key]
}
encrypted.payload = await this._crypt.encrypt(JSON.stringify(doc))
return encrypted
Expand All @@ -71,6 +72,10 @@ module.exports = {
if (!this._crypt) { return doc }
const decryptedString = await this._crypt.decrypt(doc.payload)
const decrypted = JSON.parse(decryptedString)
for (const key of this._ignore) {
// patch decrypted doc with ignored fields
if (key in doc) decrypted[key] = doc[key]
}
return decrypted
}
})
Expand Down
Loading

0 comments on commit 5555f3c

Please sign in to comment.