2018-12-22 22:16:32 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								import  server  from  '../services/server.js' ;  
						 
					
						
							
								
									
										
										
										
											2019-08-19 20:12:00 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								import  Attribute  from  './attribute.js' ;  
						 
					
						
							
								
									
										
										
										
											2018-12-22 22:16:32 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								const  LABEL  =  'label' ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								const  LABEL _DEFINITION  =  'label-definition' ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								const  RELATION  =  'relation' ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								const  RELATION _DEFINITION  =  'relation-definition' ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-08-23 12:55:45 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								/ * *  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  This  note ' s  representation  is  used  in  note  tree  and  is  kept  in  TreeCache . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 * / 
							 
						 
					
						
							
								
									
										
										
										
											2018-03-25 12:29:00 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								class  NoteShort  {  
						 
					
						
							
								
									
										
										
										
											2019-10-26 09:51:08 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    / * * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *  @ param  { TreeCache }  treeCache 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *  @ param  { Object . < string ,  Object > }  row 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *  @ param  { Branch [ ] }  branches  -  all  relevant  branches ,  i . e .  where  this  note  is  either  child  or  parent 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    constructor ( treeCache ,  row ,  branches )  { 
							 
						 
					
						
							
								
									
										
										
										
											2018-03-25 12:29:00 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        this . treeCache  =  treeCache ; 
							 
						 
					
						
							
								
									
										
										
										
											2018-08-23 12:55:45 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        /** @param {string} */ 
							 
						 
					
						
							
								
									
										
										
										
											2018-03-25 12:29:00 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        this . noteId  =  row . noteId ; 
							 
						 
					
						
							
								
									
										
										
										
											2018-08-23 12:55:45 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        /** @param {string} */ 
							 
						 
					
						
							
								
									
										
										
										
											2018-03-25 12:29:00 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        this . title  =  row . title ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-11-09 09:36:08 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        /** @param {int} */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        this . contentLength  =  row . contentLength ; 
							 
						 
					
						
							
								
									
										
										
										
											2018-08-23 12:55:45 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        /** @param {boolean} */ 
							 
						 
					
						
							
								
									
										
										
										
											2018-03-25 12:29:00 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        this . isProtected  =  row . isProtected ; 
							 
						 
					
						
							
								
									
										
										
										
											2018-08-23 12:55:45 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        /** @param {string} one of 'text', 'code', 'file' or 'render' */ 
							 
						 
					
						
							
								
									
										
										
										
											2018-03-25 12:29:00 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        this . type  =  row . type ; 
							 
						 
					
						
							
								
									
										
										
										
											2018-08-23 12:55:45 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        /** @param {string} content-type, e.g. "application/json" */ 
							 
						 
					
						
							
								
									
										
										
										
											2018-03-25 12:29:00 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        this . mime  =  row . mime ; 
							 
						 
					
						
							
								
									
										
										
										
											2018-08-23 12:55:45 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        /** @param {boolean} */ 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-26 22:50:46 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        this . isDeleted  =  row . isDeleted ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        /** @param {boolean} */ 
							 
						 
					
						
							
								
									
										
										
										
											2018-06-07 19:26:28 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        this . archived  =  row . archived ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-06 23:36:08 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        /** @param {string} */ 
							 
						 
					
						
							
								
									
										
										
										
											2018-08-13 10:59:31 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        this . cssClass  =  row . cssClass ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-11-16 08:59:27 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        /** @param {string} */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        this . iconClass  =  row . iconClass ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-26 09:51:08 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        /** @type {string[]} */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        this . parents  =  [ ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        /** @type {string[]} */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        this . children  =  [ ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        /** @type {Object.<string, string>} */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        this . parentToBranch  =  { } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        /** @type {Object.<string, string>} */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        this . childToBranch  =  { } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        for  ( const  branch  of  branches )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ( this . noteId  ===  branch . noteId )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                this . parents . push ( branch . parentNoteId ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                this . parentToBranch [ branch . parentNoteId ]  =  branch . branchId ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            else  if  ( this . noteId  ===  branch . parentNoteId )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                this . children . push ( branch . noteId ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                this . childToBranch [ branch . noteId ]  =  branch . branchId ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                throw  new  Error ( ` Unknown branch  ${ branch . branchId }  for note  ${ this . noteId } ` ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    addParent ( parentNoteId ,  branchId )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( ! this . parents . includes ( parentNoteId ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            this . parents . push ( parentNoteId ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        this . parentToBranch [ parentNoteId ]  =  branchId ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    addChild ( childNoteId ,  branchId )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( ! this . children . includes ( childNoteId ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            this . children . push ( childNoteId ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        this . childToBranch [ childNoteId ]  =  branchId ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const  branchIdPos  =  { } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        for  ( const  branchId  of  Object . values ( this . childToBranch ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-26 20:48:56 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            branchIdPos [ branchId ]  =  this . treeCache . getBranch ( branchId ) . notePosition ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-26 09:51:08 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        this . children . sort ( ( a ,  b )  =>  branchIdPos [ this . childToBranch [ a ] ]  <  branchIdPos [ this . childToBranch [ b ] ]  ?  - 1  :  1 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2018-03-25 12:29:00 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-08-23 12:55:45 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    /** @returns {boolean} */ 
							 
						 
					
						
							
								
									
										
										
										
											2018-03-25 23:25:17 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    isJson ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  this . mime  ===  "application/json" ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-09-06 23:36:08 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    async  getContent ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // we're not caching content since these objects are in treeCache and as such pretty long lived
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const  note  =  await  server . get ( "notes/"  +  this . noteId ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  note . content ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    async  getJsonContent ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const  content  =  await  this . getContent ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        try  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  JSON . parse ( content ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        catch  ( e )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            console . log ( ` Cannot parse content of note  ${ this . noteId } :  ` ,  e . message ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  null ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-08-23 15:33:19 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    /** @returns {Promise<Branch[]>} */ 
							 
						 
					
						
							
								
									
										
										
										
											2018-03-25 12:29:00 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    async  getBranches ( )  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-26 09:51:08 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        const  branchIds  =  Object . values ( this . parentToBranch ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2018-03-25 12:29:00 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-04-16 23:13:33 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        return  this . treeCache . getBranches ( branchIds ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2018-03-25 12:29:00 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-08-23 12:55:45 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    /** @returns {boolean} */ 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-16 20:40:18 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    hasChildren ( )  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-26 09:51:08 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        return  this . children . length  >  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-16 20:40:18 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-08-23 15:33:19 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    /** @returns {Promise<Branch[]>} */ 
							 
						 
					
						
							
								
									
										
										
										
											2018-03-25 12:29:00 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    async  getChildBranches ( )  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-27 22:39:38 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        // don't use Object.values() to guarantee order
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const  branchIds  =  this . children . map ( childNoteId  =>  this . childToBranch [ childNoteId ] ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2018-03-25 12:29:00 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-26 09:58:00 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        return  this . treeCache . getBranches ( branchIds ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2018-03-25 12:29:00 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-08-23 15:33:19 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    /** @returns {string[]} */ 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-16 23:34:56 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    getParentNoteIds ( )  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-26 09:51:08 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        return  this . parents ; 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-16 20:40:18 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-08-23 15:33:19 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    /** @returns {Promise<NoteShort[]>} */ 
							 
						 
					
						
							
								
									
										
										
										
											2018-03-25 12:29:00 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    async  getParentNotes ( )  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-26 09:51:08 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        return  await  this . treeCache . getNotes ( this . parents ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-16 23:34:56 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-08-23 15:33:19 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    /** @returns {string[]} */ 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-16 23:34:56 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    getChildNoteIds ( )  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-26 09:51:08 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        return  this . children ; 
							 
						 
					
						
							
								
									
										
										
										
											2018-03-25 12:29:00 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-08-23 15:33:19 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    /** @returns {Promise<NoteShort[]>} */ 
							 
						 
					
						
							
								
									
										
										
										
											2018-03-25 12:29:00 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    async  getChildNotes ( )  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-26 09:51:08 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        return  await  this . treeCache . getNotes ( this . children ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2018-03-25 12:29:00 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-12-22 22:16:32 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    / * * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *  @ param  { string }  [ name ]  -  attribute  name  to  filter 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *  @ returns  { Promise < Attribute [ ] > } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    async  getAttributes ( name )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( ! this . attributeCache )  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-19 20:12:00 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            this . attributeCache  =  ( await  server . get ( 'notes/'  +  this . noteId  +  '/attributes' ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                . map ( attrRow  =>  new  Attribute ( this . treeCache ,  attrRow ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2018-12-22 22:16:32 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( name )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  this . attributeCache . filter ( attr  =>  attr . name  ===  name ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  this . attributeCache ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    / * * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *  @ param  { string }  [ name ]  -  label  name  to  filter 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *  @ returns  { Promise < Attribute [ ] > }  all  note ' s  labels  ( attributes  with  type  label ) ,  including  inherited  ones 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    async  getLabels ( name )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  ( await  this . getAttributes ( name ) ) . filter ( attr  =>  attr . type  ===  LABEL ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    / * * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *  @ param  { string }  [ name ]  -  label  name  to  filter 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *  @ returns  { Promise < Attribute [ ] > }  all  note ' s  label  definitions ,  including  inherited  ones 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    async  getLabelDefinitions ( name )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  ( await  this . getAttributes ( name ) ) . filter ( attr  =>  attr . type  ===  LABEL _DEFINITION ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    / * * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *  @ param  { string }  [ name ]  -  relation  name  to  filter 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *  @ returns  { Promise < Attribute [ ] > }  all  note ' s  relations  ( attributes  with  type  relation ) ,  including  inherited  ones 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    async  getRelations ( name )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  ( await  this . getAttributes ( name ) ) . filter ( attr  =>  attr . type  ===  RELATION ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    / * * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *  @ param  { string }  [ name ]  -  relation  name  to  filter 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *  @ returns  { Promise < Attribute [ ] > }  all  note ' s  relation  definitions  including  inherited  ones 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    async  getRelationDefinitions ( name )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  ( await  this . getAttributes ( name ) ) . filter ( attr  =>  attr . type  ===  RELATION _DEFINITION ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    / * * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *  @ param  { string }  type  -  attribute  type  ( label ,  relation ,  etc . ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *  @ param  { string }  name  -  attribute  name 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *  @ returns  { Promise < boolean > }  true  if  note  has  an  attribute  with  given  type  and  name  ( including  inherited ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    async  hasAttribute ( type ,  name )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  ! ! await  this . getAttribute ( type ,  name ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    / * * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *  @ param  { string }  type  -  attribute  type  ( label ,  relation ,  etc . ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *  @ param  { string }  name  -  attribute  name 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *  @ returns  { Promise < Attribute > }  attribute  of  given  type  and  name .  If  there 's more such attributes, first is  returned. Returns null if there' s  no  such  attribute  belonging  to  this  note . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    async  getAttribute ( type ,  name )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const  attributes  =  await  this . getAttributes ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  attributes . find ( attr  =>  attr . type  ===  type  &&  attr . name  ===  name ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    / * * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *  @ param  { string }  type  -  attribute  type  ( label ,  relation ,  etc . ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *  @ param  { string }  name  -  attribute  name 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *  @ returns  { Promise < string > }  attribute  value  of  given  type  and  name  or  null  if  no  such  attribute  exists . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    async  getAttributeValue ( type ,  name )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const  attr  =  await  this . getAttribute ( type ,  name ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  attr  ?  attr . value  :  null ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    / * * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *  @ param  { string }  name  -  label  name 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *  @ returns  { Promise < boolean > }  true  if  label  exists  ( including  inherited ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    async  hasLabel ( name )  {  return  await  this . hasAttribute ( LABEL ,  name ) ;  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    / * * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *  @ param  { string }  name  -  relation  name 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *  @ returns  { Promise < boolean > }  true  if  relation  exists  ( including  inherited ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    async  hasRelation ( name )  {  return  await  this . hasAttribute ( RELATION ,  name ) ;  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    / * * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *  @ param  { string }  name  -  label  name 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *  @ returns  { Promise < Attribute > }  label  if  it  exists ,  null  otherwise 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    async  getLabel ( name )  {  return  await  this . getAttribute ( LABEL ,  name ) ;  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    / * * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *  @ param  { string }  name  -  relation  name 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *  @ returns  { Promise < Attribute > }  relation  if  it  exists ,  null  otherwise 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    async  getRelation ( name )  {  return  await  this . getAttribute ( RELATION ,  name ) ;  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    / * * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *  @ param  { string }  name  -  label  name 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *  @ returns  { Promise < string > }  label  value  if  label  exists ,  null  otherwise 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    async  getLabelValue ( name )  {  return  await  this . getAttributeValue ( LABEL ,  name ) ;  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    / * * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *  @ param  { string }  name  -  relation  name 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *  @ returns  { Promise < string > }  relation  value  if  relation  exists ,  null  otherwise 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    async  getRelationValue ( name )  {  return  await  this . getAttributeValue ( RELATION ,  name ) ;  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    / * * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *  @ param  { string }  name 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-17 11:28:36 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     *  @ returns  { Promise < NoteShort > | null }  target  note  of  the  relation  or  null  ( if  target  is  empty  or  note  was  not  found ) 
							 
						 
					
						
							
								
									
										
										
										
											2018-12-22 22:16:32 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     * / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    async  getRelationTarget ( name )  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-17 11:28:36 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        const  targets  =  await  this . getRelationTargets ( name ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2018-12-22 22:16:32 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-08-17 11:28:36 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        return  targets . length  >  0  ?  targets [ 0 ]  :  null ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    / * * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *  @ param  { string }  [ name ]  -  relation  name  to  filter 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *  @ returns  { Promise < NoteShort [ ] > } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    async  getRelationTargets ( name )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const  relations  =  await  this . getRelations ( name ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const  targets  =  [ ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        for  ( const  relation  of  relations )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            targets . push ( await  this . treeCache . getNote ( relation . value ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  targets ; 
							 
						 
					
						
							
								
									
										
										
										
											2018-12-22 22:16:32 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    / * * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *  Clear  note ' s  attributes  cache  to  force  fresh  reload  for  next  attribute  request . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *  Cache  is  note  instance  scoped . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    invalidateAttributeCache ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        this . attributeCache  =  null ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-08-19 20:12:00 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    / * * 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-19 20:59:40 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     *  Get  relations  which  target  this  note 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *  @ returns  { Promise < Attribute [ ] > } 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-19 20:12:00 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     * / 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-19 20:59:40 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    async  getTargetRelations ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  ( await  server . get ( 'notes/'  +  this . noteId  +  '/target-relations' ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            . map ( attrRow  =>  new  Attribute ( this . treeCache ,  attrRow ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-19 20:12:00 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-03-25 12:29:00 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    get  toString ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  ` Note(noteId= ${ this . noteId } , title= ${ this . title } ) ` ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-08 08:21:49 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    get  dto ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const  dto  =  Object . assign ( { } ,  this ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        delete  dto . treeCache ; 
							 
						 
					
						
							
								
									
										
										
										
											2018-06-07 19:26:28 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        delete  dto . archived ; 
							 
						 
					
						
							
								
									
										
										
										
											2018-12-22 22:16:32 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        delete  dto . attributeCache ; 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-08 08:21:49 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  dto ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2018-03-25 12:29:00 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								export  default  NoteShort ;