Files
notesnook/packages/core/api/sync/prepare.js

44 lines
1.1 KiB
JavaScript
Raw Normal View History

2020-04-09 16:36:57 +05:00
import Database from "../index";
2020-04-09 16:46:03 +05:00
var tfun = require("transfun/transfun.js").tfun;
if (!tfun) {
tfun = global.tfun;
}
2020-04-09 16:36:57 +05:00
class Prepare {
/**
*
* @param {Database} db
*/
constructor(db) {
this._db = db;
}
async get(lastSyncedTimestamp) {
this._lastSyncedTimestamp = lastSyncedTimestamp;
return {
notes: this._prepareForServer(this._db.notes.raw),
notebooks: this._prepareForServer(this._db.notebooks.raw),
delta: this._prepareForServer(await this._db.delta.all()),
text: this._prepareForServer(await this._db.text.all()),
tags: this._prepareForServer(this._db.tags.raw),
colors: this._prepareForServer(this._db.colors.raw),
trash: this._prepareForServer(this._db.trash.raw),
};
}
_prepareForServer(array) {
return tfun
.filter((item) => item.dateEdited > this._lastSyncedTimestamp)
.map((item) => {
// in case of resolved delta, we do not want to send this key to the server
if (item.resolved) delete item.resolved;
return {
id: item.id,
data: JSON.stringify(item),
};
})(array);
2020-04-09 16:36:57 +05:00
}
}
export default Prepare;