2020-05-17 09:48:24 +02:00
|
|
|
"use strict";
|
2020-05-16 23:12:29 +02:00
|
|
|
|
2020-05-17 09:48:24 +02:00
|
|
|
const Note = require('./entities/note');
|
|
|
|
const Branch = require('./entities/branch');
|
|
|
|
const Attribute = require('./entities/attribute');
|
2020-05-16 23:12:29 +02:00
|
|
|
|
|
|
|
class NoteCache {
|
|
|
|
constructor() {
|
|
|
|
/** @type {Object.<String, Note>} */
|
|
|
|
this.notes = null;
|
|
|
|
/** @type {Object.<String, Branch>} */
|
|
|
|
this.branches = null;
|
|
|
|
/** @type {Object.<String, Branch>} */
|
|
|
|
this.childParentToBranch = {};
|
|
|
|
/** @type {Object.<String, Attribute>} */
|
|
|
|
this.attributes = null;
|
|
|
|
/** @type {Object.<String, Attribute[]>} Points from attribute type-name to list of attributes them */
|
|
|
|
this.attributeIndex = null;
|
|
|
|
|
|
|
|
this.loaded = false;
|
2020-05-20 00:03:33 +02:00
|
|
|
this.loadedResolve = null;
|
|
|
|
this.loadedPromise = new Promise(res => {this.loadedResolve = res;});
|
2020-05-16 23:12:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @return {Attribute[]} */
|
|
|
|
findAttributes(type, name) {
|
|
|
|
return this.attributeIndex[`${type}-${name}`] || [];
|
|
|
|
}
|
|
|
|
|
|
|
|
decryptProtectedNotes() {
|
|
|
|
for (const note of Object.values(this.notes)) {
|
2020-05-17 09:48:24 +02:00
|
|
|
note.decrypt();
|
2020-05-16 23:12:29 +02:00
|
|
|
}
|
|
|
|
}
|
2020-05-17 09:48:24 +02:00
|
|
|
|
|
|
|
getBranch(childNoteId, parentNoteId) {
|
|
|
|
return this.childParentToBranch[`${childNoteId}-${parentNoteId}`];
|
|
|
|
}
|
2020-05-16 23:12:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const noteCache = new NoteCache();
|
|
|
|
|
2020-05-17 09:48:24 +02:00
|
|
|
module.exports = noteCache;
|