@ -4,6 +4,9 @@ import ws from "../services/ws.js";
import froca from "../services/froca.js" ;
import protectedSessionHolder from "../services/protected_session_holder.js" ;
import cssClassManager from "../services/css_class_manager.js" ;
import { Froca } from '../services/froca-interface.js' ;
import FAttachment from './fattachment.js' ;
import FAttribute , { AttributeType } from './fattribute.js' ;
const LABEL = 'label' ;
const RELATION = 'relation' ;
@ -30,76 +33,91 @@ const NOTE_TYPE_ICONS = {
* There are many different Note types , some of which are entirely opaque to the
* end user . Those types should be used only for checking against , they are
* not for direct use .
* @typedef { "file" | "image" | "search" | "noteMap" | "launcher" | "doc" | "contentWidget" | "text" | "relationMap" | "render" | "canvas" | "mermaid" | "book" | "webView" | "code" } NoteType
* /
type NoteType = "file" | "image" | "search" | "noteMap" | "launcher" | "doc" | "contentWidget" | "text" | "relationMap" | "render" | "canvas" | "mermaid" | "book" | "webView" | "code" ;
interface NotePathRecord {
isArchived : boolean ;
isInHoistedSubTree : boolean ;
isSearch : boolean ;
notePath : string [ ] ;
isHidden : boolean ;
}
/ * *
* @typedef { Object } NotePathRecord
* @property { boolean } isArchived
* @property { boolean } isInHoistedSubTree
* @property { boolean } isSearch
* @property { Array < string > } notePath
* @property { boolean } isHidden
* /
export interface FNoteRow {
noteId : string ;
title : string ;
isProtected : boolean ;
type : NoteType ;
mime : string ;
blobId : string ;
}
export interface NoteMetaData {
dateCreated : string ;
utcDateCreated : string ;
dateModified : string ;
utcDateModified : string ;
}
/ * *
* Note is the main node and concept in Trilium .
* /
class FNote {
private froca : Froca ;
noteId ! : string ;
title ! : string ;
isProtected ! : boolean ;
type ! : NoteType ;
/ * *
* @param { Froca } froca
* @param { Object . < string , Object > } row
* content - type , e . g . "application/json"
* /
constructor ( froca , row ) {
/** @type {Froca} */
this . froca = froca ;
mime ! : string ;
// the main use case to keep this is to detect content change which should trigger refresh
blobId ! : string ;
/** @type {string[]} */
this . attributes = [ ] ;
attributes : string [ ] ;
targetRelations : string [ ] ;
parents : string [ ] ;
children : string [ ] ;
/** @type {string[]} */
this . targetRelations = [ ] ;
parentToBranch : Record < string , string > ;
childToBranch : Record < string , string > ;
attachments : FAttachment [ ] | null ;
// Managed by Froca.
searchResultsLoaded? : boolean ;
highlightedTokens? : unknown ;
/** @type {string[]} */
constructor ( froca : Froca , row : FNoteRow ) {
this . froca = froca ;
this . attributes = [ ] ;
this . targetRelations = [ ] ;
this . parents = [ ] ;
/** @type {string[]} */
this . children = [ ] ;
/** @type {Object.<string, string>} */
this . parentToBranch = { } ;
/** @type {Object.<string, string>} */
this . childToBranch = { } ;
/** @type {FAttachment[]|null} */
this . attachments = null ; // lazy loaded
this . update ( row ) ;
}
update ( row ) {
/** @type {string} */
update ( row : FNoteRow ) {
this . noteId = row . noteId ;
/** @type {string} */
this . title = row . title ;
/** @type {boolean} */
this . isProtected = ! ! row . isProtected ;
/ * *
* See { @see NoteType } for info on values .
* @type { NoteType }
* /
this . type = row . type ;
/ * *
* content - type , e . g . "application/json"
* @type { string }
* /
this . mime = row . mime ;
// the main use case to keep this is to detect content change which should trigger refresh
this . blobId = row . blobId ;
}
addParent ( parentNoteId , branchId , sort = true ) {
addParent ( parentNoteId : string , branchId : string , sort = true ) {
if ( parentNoteId === 'none' ) {
return ;
}
@ -115,7 +133,7 @@ class FNote {
}
}
addChild ( childNoteId , branchId , sort = true ) {
addChild ( childNoteId : string , branchId : string , sort = true ) {
if ( ! ( childNoteId in this . childToBranch ) ) {
this . children . push ( childNoteId ) ;
}
@ -128,16 +146,18 @@ class FNote {
}
sortChildren() {
const branchIdPos = { } ;
const branchIdPos : Record < string , number > = { } ;
for ( const branchId of Object . values ( this . childToBranch ) ) {
branchIdPos [ branchId ] = this . froca . getBranch ( branchId ) . notePosition ;
const notePosition = this . froca . getBranch ( branchId ) ? . notePosition ;
if ( notePosition ) {
branchIdPos [ branchId ] = notePosition ;
}
}
this . children . sort ( ( a , b ) = > branchIdPos [ this . childToBranch [ a ] ] - branchIdPos [ this . childToBranch [ b ] ] ) ;
}
/** @returns {boolean} */
isJson() {
return this . mime === "application/json" ;
}
@ -151,34 +171,32 @@ class FNote {
async getJsonContent() {
const content = await this . getContent ( ) ;
if ( typeof content !== "string" ) {
console . log ( ` Unknown note content for ' ${ this . noteId } '. ` ) ;
return null ;
}
try {
return JSON . parse ( content ) ;
}
catch ( e ) {
catch ( e : any ) {
console . log ( ` Cannot parse content of note ' ${ this . noteId } ': ` , e . message ) ;
return null ;
}
}
/ * *
* @returns { string [ ] }
* /
getParentBranchIds() {
return Object . values ( this . parentToBranch ) ;
}
/ * *
* @returns { string [ ] }
* @deprecated use getParentBranchIds ( ) instead
* /
getBranchIds() {
return this . getParentBranchIds ( ) ;
}
/ * *
* @returns { FBranch [ ] }
* /
getParentBranches() {
const branchIds = Object . values ( this . parentToBranch ) ;
@ -186,19 +204,16 @@ class FNote {
}
/ * *
* @returns { FBranch [ ] }
* @deprecated use getParentBranches ( ) instead
* /
getBranches() {
return this . getParentBranches ( ) ;
}
/** @returns {boolean} */
hasChildren() {
return this . children . length > 0 ;
}
/** @returns {FBranch[]} */
getChildBranches() {
// don't use Object.values() to guarantee order
const branchIds = this . children . map ( childNoteId = > this . childToBranch [ childNoteId ] ) ;
@ -206,12 +221,10 @@ class FNote {
return this . froca . getBranches ( branchIds ) ;
}
/** @returns {string[]} */
getParentNoteIds() {
return this . parents ;
}
/** @returns {FNote[]} */
getParentNotes() {
return this . froca . getNotesFromCache ( this . parents ) ;
}
@ -240,17 +253,14 @@ class FNote {
return this . hasAttribute ( 'label' , 'archived' ) ;
}
/** @returns {string[]} */
getChildNoteIds() {
return this . children ;
}
/** @returns {Promise<FNote[]>} */
async getChildNotes() {
return await this . froca . getNotes ( this . children ) ;
}
/** @returns {Promise<FAttachment[]>} */
async getAttachments() {
if ( ! this . attachments ) {
this . attachments = await this . froca . getAttachmentsForNote ( this . noteId ) ;
@ -259,14 +269,12 @@ class FNote {
return this . attachments ;
}
/** @returns {Promise<FAttachment[]>} */
async getAttachmentsByRole ( role ) {
async getAttachmentsByRole ( role : string ) {
return ( await this . getAttachments ( ) )
. filter ( attachment = > attachment . role === role ) ;
}
/** @returns {Promise<FAttachment>} */
async getAttachmentById ( attachmentId ) {
async getAttachmentById ( attachmentId : string ) {
const attachments = await this . getAttachments ( ) ;
return attachments . find ( att = > att . attachmentId === attachmentId ) ;
@ -296,11 +304,11 @@ class FNote {
}
/ * *
* @param {string } [type ] - ( optional ) attribute type to filter
* @param {string } [name ] - ( optional ) attribute name to filter
* @returns { FAttribute [ ] } all note ' s attributes , including inherited ones
* @param [type ] - attribute type to filter
* @param [name ] - attribute name to filter
* @returns all note ' s attributes , including inherited ones
* /
getOwnedAttributes ( type , name ) {
getOwnedAttributes ( type ? : AttributeType , name ?: string ) {
const attrs = this . attributes
. map ( attributeId = > this . froca . attributes [ attributeId ] )
. filter ( Boolean ) ; // filter out nulls;
@ -309,20 +317,18 @@ class FNote {
}
/ * *
* @param {string } [type ] - ( optional ) attribute type to filter
* @param {string } [name ] - ( optional ) attribute name to filter
* @returns { FAttribute [ ] } all note ' s attributes , including inherited ones
* @param [type ] - attribute type to filter
* @param [name ] - attribute name to filter
* @returns all note ' s attributes , including inherited ones
* /
getAttributes ( type , name ) {
getAttributes ( type ? : AttributeType , name ?: string ) {
return this . __filterAttrs ( this . __getCachedAttributes ( [ ] ) , type , name ) ;
}
/ * *
* @param { string [ ] } path
* @return { FAttribute [ ] }
* @private
* /
__getCachedAttributes ( path ) {
__getCachedAttributes ( path : string [ ] ) : FAttribute [ ] {
// notes/clones cannot form tree cycles, it is possible to create attribute inheritance cycle via templates
// when template instance is a parent of template itself
if ( path . includes ( this . noteId ) ) {
@ -377,9 +383,9 @@ class FNote {
/ * *
* Gives all possible note paths leading to this note . Paths containing search note are ignored ( could form cycles )
*
* @returns { string [ ] [ ] } - array of notePaths ( each represented by array of noteIds constituting the particular note path )
* @returns array of notePaths ( each represented by array of noteIds constituting the particular note path )
* /
getAllNotePaths () {
getAllNotePaths ( ): string [ ] [ ] {
if ( this . noteId === 'root' ) {
return [ [ 'root' ] ] ;
}
@ -397,10 +403,6 @@ class FNote {
return notePaths ;
}
/ * *
* @param { string } [ hoistedNoteId = 'root' ]
* @return { Array < NotePathRecord > }
* /
getSortedNotePathRecords ( hoistedNoteId = 'root' ) {
const isHoistedRoot = hoistedNoteId === 'root' ;
@ -476,14 +478,10 @@ class FNote {
return true ;
}
/ * *
* @param { FAttribute [ ] } attributes
* @param { AttributeType } type
* @param { string } name
* @return { FAttribute [ ] }
/ * *
* @private
* /
__filterAttrs ( attributes , type , name ) {
__filterAttrs ( attributes : FAttribute [ ] , type ? : AttributeType , name? : string ) : FAttribute [ ] {
this . __validateTypeName ( type , name ) ;
if ( ! type && ! name ) {
@ -495,15 +493,17 @@ class FNote {
} else if ( name ) {
return attributes . filter ( attr = > attr . name === name ) ;
}
return [ ] ;
}
__getInheritableAttributes ( path ) {
__getInheritableAttributes ( path : string [ ] ) {
const attrs = this . __getCachedAttributes ( path ) ;
return attrs . filter ( attr = > attr . isInheritable ) ;
}
__validateTypeName ( type , name ) {
__validateTypeName ( type ? : string , name ?: string ) {
if ( type && type !== 'label' && type !== 'relation' ) {
throw new Error ( ` Unrecognized attribute type ' ${ type } '. Only 'label' and 'relation' are possible values. ` ) ;
}
@ -517,18 +517,18 @@ class FNote {
}
/ * *
* @param {string } [name ] - label name to filter
* @returns { FAttribute [ ] } all note ' s labels ( attributes with type label ) , including inherited ones
* @param [name ] - label name to filter
* @returns all note ' s labels ( attributes with type label ) , including inherited ones
* /
getOwnedLabels ( name ) {
getOwnedLabels ( name : string ) {
return this . getOwnedAttributes ( LABEL , name ) ;
}
/ * *
* @param {string } [name ] - label name to filter
* @returns { FAttribute [ ] } all note ' s labels ( attributes with type label ) , including inherited ones
* @param [name ] - label name to filter
* @returns all note ' s labels ( attributes with type label ) , including inherited ones
* /
getLabels ( name ) {
getLabels ( name : string ) {
return this . getAttributes ( LABEL , name ) ;
}
@ -536,7 +536,7 @@ class FNote {
const iconClassLabels = this . getLabels ( 'iconClass' ) ;
const workspaceIconClass = this . getWorkspaceIconClass ( ) ;
if ( iconClassLabels . length > 0 ) {
if ( iconClassLabels && iconClassLabels . length > 0 ) {
return iconClassLabels [ 0 ] . value ;
}
else if ( workspaceIconClass ) {
@ -579,7 +579,7 @@ class FNote {
if ( ! childBranches ) {
ws . logError ( ` No children for ' ${ this . noteId } '. This shouldn't happen. ` ) ;
return ;
return [ ] ;
}
// we're not checking hideArchivedNotes since that would mean we need to lazy load the child notes
@ -591,102 +591,104 @@ class FNote {
}
/ * *
* @param {string } [name ] - relation name to filter
* @returns { FAttribute [ ] } all note ' s relations ( attributes with type relation ) , including inherited ones
* @param [name ] - relation name to filter
* @returns all note ' s relations ( attributes with type relation ) , including inherited ones
* /
getOwnedRelations ( name ) {
getOwnedRelations ( name : string ) {
return this . getOwnedAttributes ( RELATION , name ) ;
}
/ * *
* @param {string } [name ] - relation name to filter
* @returns { FAttribute [ ] } all note ' s relations ( attributes with type relation ) , including inherited ones
* @param [name ] - relation name to filter
* @returns all note ' s relations ( attributes with type relation ) , including inherited ones
* /
getRelations ( name ) {
getRelations ( name : string ) {
return this . getAttributes ( RELATION , name ) ;
}
/ * *
* @param { AttributeType } type - attribute type ( label , relation , etc . )
* @param { string } name - attribute name
* @returns { boolean } true if note has an attribute with given type and name ( including inherited )
* @param type - attribute type ( label , relation , etc . )
* @param name - attribute name
* @returns true if note has an attribute with given type and name ( including inherited )
* /
hasAttribute ( type , name ) {
hasAttribute ( type : AttributeType , name : string ) {
const attributes = this . getAttributes ( ) ;
return attributes . some ( attr = > attr . name === name && attr . type === type ) ;
}
/ * *
* @param { AttributeType } type - attribute type ( label , relation , etc . )
* @param { string } name - attribute name
* @returns { boolean } true if note has an attribute with given type and name ( including inherited )
* @param type - attribute type ( label , relation , etc . )
* @param name - attribute name
* @returns true if note has an attribute with given type and name ( including inherited )
* /
hasOwnedAttribute ( type , name ) {
hasOwnedAttribute ( type : AttributeType , name : string ) {
return ! ! this . getOwnedAttribute ( type , name ) ;
}
/ * *
* @param { AttributeType } type - attribute type ( label , relation , etc . )
* @param { string } name - attribute name
* @returns { FAttribute } attribute of the given type and name . If there are more such attributes , first is returned . Returns null if there ' s no such attribute belonging to this note .
* @param type - attribute type ( label , relation , etc . )
* @param name - attribute name
* @returns attribute of the given type and name . If there are more such attributes , first is returned . Returns null if there ' s no such attribute belonging to this note .
* /
getOwnedAttribute ( type , name ) {
getOwnedAttribute ( type : AttributeType , name : string ) {
const attributes = this . getOwnedAttributes ( ) ;
return attributes . find ( attr = > attr . name === name && attr . type === type ) ;
}
/ * *
* @param { AttributeType } type - attribute type ( label , relation , etc . )
* @param { string } name - attribute name
* @returns { FAttribute } attribute of the given type and name . If there are more such attributes , first is returned . Returns null if there ' s no such attribute belonging to this note .
* @param type - attribute type ( label , relation , etc . )
* @param name - attribute name
* @returns attribute of the given type and name . If there are more such attributes , first is returned . Returns null if there ' s no such attribute belonging to this note .
* /
getAttribute ( type , name ) {
getAttribute ( type : AttributeType , name : string ) {
const attributes = this . getAttributes ( ) ;
return attributes . find ( attr = > attr . name === name && attr . type === type ) ;
}
/ * *
* @param { AttributeType } type - attribute type ( label , relation , etc . )
* @param { string } name - attribute name
* @returns { string } attribute value of the given type and name or null if no such attribute exists .
* @param type - attribute type ( label , relation , etc . )
* @param name - attribute name
* @returns attribute value of the given type and name or null if no such attribute exists .
* /
getOwnedAttributeValue ( type , name ) {
getOwnedAttributeValue ( type : AttributeType , name : string ) {
const attr = this . getOwnedAttribute ( type , name ) ;
return attr ? attr.value : null ;
}
/ * *
* @param { AttributeType } type - attribute type ( label , relation , etc . )
* @param { string } name - attribute name
* @returns { string } attribute value of the given type and name or null if no such attribute exists .
* @param type - attribute type ( label , relation , etc . )
* @param name - attribute name
* @returns attribute value of the given type and name or null if no such attribute exists .
* /
getAttributeValue ( type , name ) {
getAttributeValue ( type : AttributeType , name : string ) {
const attr = this . getAttribute ( type , name ) ;
return attr ? attr.value : null ;
}
/ * *
* @param { string } name - label name
* @returns { boolean } true if label exists ( excluding inherited )
* @param name - label name
* @returns true if label exists ( excluding inherited )
* /
hasOwnedLabel ( name ) { return this . hasOwnedAttribute ( LABEL , name ) ; }
hasOwnedLabel ( name : string ) {
return this . hasOwnedAttribute ( LABEL , name ) ;
}
/ * *
* @param { string } name - label name
* @returns { boolean } true if label exists ( including inherited )
* @param name - label name
* @returns true if label exists ( including inherited )
* /
hasLabel ( name ) { return this . hasAttribute ( LABEL , name ) ; }
hasLabel ( name : string ) { return this . hasAttribute ( LABEL , name ) ; }
/ * *
* @param { string } name - label name
* @returns { boolean } true if label exists ( including inherited ) and does not have "false" value .
* @param name - label name
* @returns true if label exists ( including inherited ) and does not have "false" value .
* /
isLabelTruthy ( name ) {
isLabelTruthy ( name : string ) {
const label = this . getLabel ( name ) ;
if ( ! label ) {
@ -697,80 +699,79 @@ class FNote {
}
/ * *
* @param { string } name - relation name
* @returns { boolean } true if relation exists ( excluding inherited )
* @param name - relation name
* @returns true if relation exists ( excluding inherited )
* /
hasOwnedRelation ( name ) { return this . hasOwnedAttribute ( RELATION , name ) ; }
hasOwnedRelation ( name : string ) { return this . hasOwnedAttribute ( RELATION , name ) ; }
/ * *
* @param { string } name - relation name
* @returns { boolean } true if relation exists ( including inherited )
* @param name - relation name
* @returns true if relation exists ( including inherited )
* /
hasRelation ( name ) { return this . hasAttribute ( RELATION , name ) ; }
hasRelation ( name : string ) { return this . hasAttribute ( RELATION , name ) ; }
/ * *
* @param { string } name - label name
* @returns { FAttribute } label if it exists , null otherwise
* @param name - label name
* @returns label if it exists , null otherwise
* /
getOwnedLabel ( name ) { return this . getOwnedAttribute ( LABEL , name ) ; }
getOwnedLabel ( name : string ) { return this . getOwnedAttribute ( LABEL , name ) ; }
/ * *
* @param { string } name - label name
* @returns { FAttribute } label if it exists , null otherwise
* @param name - label name
* @returns label if it exists , null otherwise
* /
getLabel ( name ) { return this . getAttribute ( LABEL , name ) ; }
getLabel ( name : string ) { return this . getAttribute ( LABEL , name ) ; }
/ * *
* @param { string } name - relation name
* @returns { FAttribute } relation if it exists , null otherwise
* @param name - relation name
* @returns relation if it exists , null otherwise
* /
getOwnedRelation ( name ) { return this . getOwnedAttribute ( RELATION , name ) ; }
getOwnedRelation ( name : string ) { return this . getOwnedAttribute ( RELATION , name ) ; }
/ * *
* @param { string } name - relation name
* @returns { FAttribute } relation if it exists , null otherwise
* @param name - relation name
* @returns relation if it exists , null otherwise
* /
getRelation ( name ) { return this . getAttribute ( RELATION , name ) ; }
getRelation ( name : string ) { return this . getAttribute ( RELATION , name ) ; }
/ * *
* @param { string } name - label name
* @returns { string } label value if label exists , null otherwise
* @param name - label name
* @returns label value if label exists , null otherwise
* /
getOwnedLabelValue ( name ) { return this . getOwnedAttributeValue ( LABEL , name ) ; }
getOwnedLabelValue ( name : string ) { return this . getOwnedAttributeValue ( LABEL , name ) ; }
/ * *
* @param { string } name - label name
* @returns { string } label value if label exists , null otherwise
* @param name - label name
* @returns label value if label exists , null otherwise
* /
getLabelValue ( name ) { return this . getAttributeValue ( LABEL , name ) ; }
getLabelValue ( name : string ) { return this . getAttributeValue ( LABEL , name ) ; }
/ * *
* @param { string } name - relation name
* @returns { string } relation value if relation exists , null otherwise
* @param name - relation name
* @returns relation value if relation exists , null otherwise
* /
getOwnedRelationValue ( name ) { return this . getOwnedAttributeValue ( RELATION , name ) ; }
getOwnedRelationValue ( name : string ) { return this . getOwnedAttributeValue ( RELATION , name ) ; }
/ * *
* @param { string } name - relation name
* @returns { string } relation value if relation exists , null otherwise
* @param name - relation name
* @returns relation value if relation exists , null otherwise
* /
getRelationValue ( name ) { return this . getAttributeValue ( RELATION , name ) ; }
getRelationValue ( name : string ) { return this . getAttributeValue ( RELATION , name ) ; }
/ * *
* @param { string } name
* @returns { Promise < FNote > | null } target note of the relation or null ( if target is empty or note was not found )
* @param name
* @returns target note of the relation or null ( if target is empty or note was not found )
* /
async getRelationTarget ( name ) {
async getRelationTarget ( name : string ) {
const targets = await this . getRelationTargets ( name ) ;
return targets . length > 0 ? targets [ 0 ] : null ;
}
/ * *
* @param { string } [ name ] - relation name to filter
* @returns { Promise < FNote [ ] > }
* @param [ name ] - relation name to filter
* /
async getRelationTargets ( name ) {
async getRelationTargets ( name : string ) {
const relations = this . getRelations ( name ) ;
const targets = [ ] ;
@ -781,9 +782,6 @@ class FNote {
return targets ;
}
/ * *
* @returns { FNote [ ] }
* /
getNotesToInheritAttributesFrom() {
const relations = [
. . . this . getRelations ( 'template' ) ,
@ -819,7 +817,7 @@ class FNote {
return promotedAttrs ;
}
hasAncestor ( ancestorNoteId , followTemplates = false , visitedNoteIds = null ) {
hasAncestor ( ancestorNoteId : string , followTemplates = false , visitedNoteIds : Set < string > | null = null ) {
if ( this . noteId === ancestorNoteId ) {
return true ;
}
@ -861,8 +859,6 @@ class FNote {
/ * *
* Get relations which target this note
*
* @returns { FAttribute [ ] }
* /
getTargetRelations() {
return this . targetRelations
@ -871,8 +867,6 @@ class FNote {
/ * *
* Get relations which target this note
*
* @returns { Promise < FNote [ ] > }
* /
async getTargetRelationSourceNotes() {
const targetRelations = this . getTargetRelations ( ) ;
@ -882,13 +876,11 @@ class FNote {
/ * *
* @deprecated use getBlob ( ) instead
* @return { Promise < FBlob > }
* /
async getNoteComplement() {
return this . getBlob ( ) ;
}
/** @return {Promise<FBlob>} */
async getBlob() {
return await this . froca . getBlob ( 'notes' , this . noteId ) ;
}
@ -897,8 +889,8 @@ class FNote {
return ` Note(noteId= ${ this . noteId } , title= ${ this . title } ) ` ;
}
get dto () {
const dto = Object . assign ( { } , this ) ;
get dto ( ): Omit < FNote , " froca " > {
const dto = Object . assign ( { } , this ) as any ;
delete dto . froca ;
return dto ;
@ -919,7 +911,7 @@ class FNote {
return labels . length > 0 ? labels [ 0 ] . value : "" ;
}
/** @returns {boolean} true if this note is JavaScript (code or file) */
/** @returns true if this note is JavaScript (code or file) */
isJavaScript() {
return ( this . type === "code" || this . type === "file" || this . type === 'launcher' )
&& ( this . mime . startsWith ( "application/javascript" )
@ -927,12 +919,12 @@ class FNote {
|| this . mime === "text/javascript" ) ;
}
/** @returns {boolean} true if this note is HTML */
/** @returns true if this note is HTML */
isHtml() {
return ( this . type === "code" || this . type === "file" || this . type === "render" ) && this . mime === "text/html" ;
}
/** @returns {string|null} JS script environment - either "frontend" or "backend" */
/** @returns JS script environment - either "frontend" or "backend" */
getScriptEnv() {
if ( this . isHtml ( ) || ( this . isJavaScript ( ) && this . mime . endsWith ( 'env=frontend' ) ) ) {
return "frontend" ;
@ -959,11 +951,9 @@ class FNote {
if ( env === "frontend" ) {
const bundleService = ( await import ( "../services/bundle.js" ) ) . default ;
return await bundleService . getAndExecuteBundle ( this . noteId ) ;
}
else if ( env === "backend" ) {
const resp = await server . post ( ` script/run/ ${ this . noteId } ` ) ;
}
else {
} else if ( env === "backend" ) {
await server . post ( ` script/run/ ${ this . noteId } ` ) ;
} else {
throw new Error ( ` Unrecognized env type ${ env } for note ${ this . noteId } ` ) ;
}
}
@ -1002,11 +992,9 @@ class FNote {
/ * *
* Provides note ' s date metadata .
*
* @returns { Promise < { dateCreated : string , utcDateCreated : string , dateModified : string , utcDateModified : string } > }
* /
async getMetadata() {
return await server . get (` notes/ ${ this . noteId } /metadata ` ) ;
return await server . get <NoteMetaData > (` notes/ ${ this . noteId } /metadata ` ) ;
}
}