| 
									
										
										
										
											2020-05-17 09:48:24 +02:00
										 |  |  | "use strict"; | 
					
						
							| 
									
										
										
										
											2020-05-16 23:12:29 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-16 23:00:08 +02:00
										 |  |  | class Becca { | 
					
						
							| 
									
										
										
										
											2020-05-16 23:12:29 +02:00
										 |  |  |     constructor() { | 
					
						
							| 
									
										
										
										
											2020-05-22 09:38:30 +02:00
										 |  |  |         this.reset(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     reset() { | 
					
						
							| 
									
										
										
										
											2020-05-16 23:12:29 +02:00
										 |  |  |         /** @type {Object.<String, Note>} */ | 
					
						
							| 
									
										
										
										
											2020-05-22 09:38:30 +02:00
										 |  |  |         this.notes = []; | 
					
						
							| 
									
										
										
										
											2020-05-16 23:12:29 +02:00
										 |  |  |         /** @type {Object.<String, Branch>} */ | 
					
						
							| 
									
										
										
										
											2020-05-22 09:38:30 +02:00
										 |  |  |         this.branches = []; | 
					
						
							| 
									
										
										
										
											2020-05-16 23:12:29 +02:00
										 |  |  |         /** @type {Object.<String, Branch>} */ | 
					
						
							|  |  |  |         this.childParentToBranch = {}; | 
					
						
							|  |  |  |         /** @type {Object.<String, Attribute>} */ | 
					
						
							| 
									
										
										
										
											2020-05-22 09:38:30 +02:00
										 |  |  |         this.attributes = []; | 
					
						
							| 
									
										
										
										
											2020-12-12 12:07:15 +01:00
										 |  |  |         /** @type {Object.<String, Attribute[]>} Points from attribute type-name to list of attributes */ | 
					
						
							| 
									
										
										
										
											2020-05-22 09:38:30 +02:00
										 |  |  |         this.attributeIndex = {}; | 
					
						
							| 
									
										
										
										
											2020-05-16 23:12:29 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         this.loaded = false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** @return {Attribute[]} */ | 
					
						
							|  |  |  |     findAttributes(type, name) { | 
					
						
							| 
									
										
										
										
											2020-12-12 12:07:15 +01:00
										 |  |  |         return this.attributeIndex[`${type}-${name.toLowerCase()}`] || []; | 
					
						
							| 
									
										
										
										
											2020-05-16 23:12:29 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-21 12:05:12 +02:00
										 |  |  |     /** @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(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-16 23:12:29 +02:00
										 |  |  |     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
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-16 23:00:08 +02:00
										 |  |  | const becca = new Becca(); | 
					
						
							| 
									
										
										
										
											2020-05-16 23:12:29 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-16 23:00:08 +02:00
										 |  |  | module.exports = becca; |