Files
notesnook/packages/core/migrations.js

105 lines
2.6 KiB
JavaScript
Raw Normal View History

2021-02-02 12:24:54 +05:00
import { QuillDeltaToHtmlConverter } from "quill-delta-to-html";
export const migrations = {
0: {
note: function (item) {
2020-12-07 12:02:01 +05:00
// note.content -> note.contentId
2020-12-06 11:13:17 +05:00
if (item.content) {
const contentId = item.content.delta;
delete item.content;
item.contentId = contentId;
}
2020-12-07 12:02:01 +05:00
return migrations[2].note(item);
},
delta: function (item) {
item.data = item.data.ops;
item.type = "delta";
item.migrated = true;
2021-02-02 12:24:54 +05:00
return migrations["2"].delta(item);
},
trash: function (item) {
item.itemType = item.type;
item.type = "trash";
if (item.itemType === "note") {
item.contentId = item.content.delta;
delete item.content;
}
item.migrated = true;
return item;
},
},
2: {
note: function (item) {
2020-12-07 12:02:01 +05:00
// note.notebook -> note.notebooks
const notebook = item.notebook;
delete item.notebook;
if (notebook && notebook.id && notebook.topic) {
2020-12-08 11:58:45 +05:00
notebook.topics = [notebook.topic];
2020-12-07 12:02:01 +05:00
delete notebook.topic;
item.notebooks = [notebook];
}
return migrations[3].note(item);
},
2021-02-02 12:24:54 +05:00
delta: (item) => migrations["3"].delta(item),
2020-12-07 12:02:01 +05:00
},
3: {
note: function (item) {
// note.colors -> note.color
if (item.colors && item.colors.length > 0) item.color = item.colors.pop();
delete item.colors;
2020-12-07 13:11:44 +05:00
return migrations[4].note(item);
},
2021-02-02 12:24:54 +05:00
delta: (item) => migrations["4"].delta(item),
2020-12-07 13:11:44 +05:00
},
4: {
note: function (item) {
if (item.notebooks && item.notebooks.every((n) => !n.id)) {
item.notebooks = undefined;
}
return migrations["4.1"].note(item);
},
2021-02-02 12:24:54 +05:00
delta: (item) => migrations["4.1"].delta(item),
},
4.1: {
note: function (item) {
return migrations["4.2"].note(item);
},
2021-02-02 12:24:54 +05:00
delta: (item) => migrations["4.2"].delta(item),
},
4.2: {
note: function (item) {
if (item.notebooks) {
item.notebooks = item.notebooks.map((nb) => {
return { id: nb.id, topics: nb.topics || [nb.topic] };
});
}
item.migrated = true;
return item;
},
2021-02-02 12:24:54 +05:00
delta: (item) => migrations["4.3"].delta(item),
},
4.3: {
2021-02-02 12:24:54 +05:00
delta: function (item) {
const deltaConverter = new QuillDeltaToHtmlConverter(item.data, {
classPrefix: "nn",
inlineStyles: true,
});
item.data = deltaConverter.convert();
item.type = "tiny";
item.migrated = true;
return item;
},
},
5.0: {
note: false,
2020-12-07 13:11:44 +05:00
notebook: false,
tag: false,
trash: false,
2020-12-06 11:13:17 +05:00
delta: false,
settings: false,
},
};