mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 10:26:08 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			56 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			56 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| "use strict";
 | |
| 
 | |
| class Becca {
 | |
|     constructor() {
 | |
|         this.reset();
 | |
|     }
 | |
| 
 | |
|     reset() {
 | |
|         /** @type {Object.<String, Note>} */
 | |
|         this.notes = [];
 | |
|         /** @type {Object.<String, Branch>} */
 | |
|         this.branches = [];
 | |
|         /** @type {Object.<String, Branch>} */
 | |
|         this.childParentToBranch = {};
 | |
|         /** @type {Object.<String, Attribute>} */
 | |
|         this.attributes = [];
 | |
|         /** @type {Object.<String, Attribute[]>} Points from attribute type-name to list of attributes */
 | |
|         this.attributeIndex = {};
 | |
| 
 | |
|         this.loaded = false;
 | |
|     }
 | |
| 
 | |
|     /** @return {Attribute[]} */
 | |
|     findAttributes(type, name) {
 | |
|         return this.attributeIndex[`${type}-${name.toLowerCase()}`] || [];
 | |
|     }
 | |
| 
 | |
|     /** @return {Attribute[]} */
 | |
|     findAttributesWithPrefix(type, name) {
 | |
|         const resArr = [];
 | |
|         const key = `${type}-${name}`;
 | |
| 
 | |
|         for (const idx in this.attributeIndex) {
 | |
|             if (idx.startsWith(key)) {
 | |
|                 resArr.push(this.attributeIndex[idx]);
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         return resArr.flat();
 | |
|     }
 | |
| 
 | |
|     decryptProtectedNotes() {
 | |
|         for (const note of Object.values(this.notes)) {
 | |
|             note.decrypt();
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     getBranch(childNoteId, parentNoteId) {
 | |
|         return this.childParentToBranch[`${childNoteId}-${parentNoteId}`];
 | |
|     }
 | |
| }
 | |
| 
 | |
| const becca = new Becca();
 | |
| 
 | |
| module.exports = becca;
 |