Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(codemirror/autocomplete): improve script API descriptions
Elian Dorand83989b0f37f
diff --git a/packages/commons/src/lib/script_api.ts b/packages/commons/src/lib/script_api.tsindex 44b6d795aa..01e417d3aa 100644--- a/packages/commons/src/lib/script_api.ts+++ b/packages/commons/src/lib/script_api.ts@@ -82,15 +82,31 @@ type Func = ((...args: unknown[]) => unknown) | string;* (`application/javascript;env=frontend`).*/export interface FrontendApi {- /** Container of all the rendered script content (jQuery element). */+ /**+ * Container of all the rendered script content+ * */$container: unknown;- /** Note where the script started executing (the event entrypoint). */+ /**+ * Note where the script started executing, i.e., the (event) entrypoint of the current script execution.+ */startNote: ScriptFNote;- /** Note where the script is currently executing. */+ /**+ * Note where the script is currently executing, i.e. the note where the currently executing source code is written.+ */currentNote: ScriptFNote;- /** Entity whose event triggered this execution (a note, or null). */+ /**+ * Entity whose event triggered this execution.+ *+ * <p>+ * For front-end scripts, generally there's no origin entity specified since the scripts are run by the user or automatically by the UI (widgets).+ * If there is an origin entity specified, then it's going to be a note entity.+ */originEntity: unknown | null;- /** day.js library for date manipulation. See https://day.js.org */+ /**+ * day.js library for date manipulation.+ * See {@link https://day.js.org} for documentation+ * @see https://day.js.org+ */dayjs: ScriptDayjs;/** Base class for right-panel widgets. */@@ -100,114 +116,311 @@ export interface FrontendApi {/** Base class for basic widgets. */BasicWidget: unknown;- /** Activates a note in the tree and in the note detail. */+ /**+ * Activates note in the tree and in the note detail.+ *+ * @param notePath (or noteId)+ */activateNote(notePath: string): Promise<void>;- /** Activates a newly created note, ensuring the frontend has fully synced first. */+ /**+ * Activates newly created note. Compared to this.activateNote() also makes sure that frontend has been fully synced.+ *+ * @param notePath (or noteId)+ */activateNewNote(notePath: string): Promise<void>;- /** Opens a note in a new tab. */+ /**+ * Open a note in a new tab.+ *+ * @method+ * @param notePath (or noteId)+ * @param activate - set to true to activate the new tab, false to stay on the current tab+ */openTabWithNote(notePath: string, activate: boolean): Promise<void>;- /** Opens a note in a new split. */+ /**+ * Open a note in a new split.+ *+ * @param notePath (or noteId)+ * @param activate - set to true to activate the new split, false to stay on the current split+ */openSplitWithNote(notePath: string, activate: boolean): Promise<void>;- /** Executes the given (synchronous) function on the backend. */+ /**+ * Executes given anonymous function on the backend.+ * Internally this serializes the anonymous function into string and sends it to backend via AJAX.+ * Please make sure that the supplied function is synchronous. Only sync functions will work correctly+ * with transaction management. If you really know what you're doing, you can call api.runAsyncOnBackendWithManualTransactionHandling()+ *+ * @method+ * @param func - (synchronous) function to be executed on the backend+ * @param params - list of parameters to the anonymous function to be sent to backend+ * @returns return value of the executed function on the backend+ */runOnBackend(func: Func, params?: unknown[]): Promise<unknown>;- /** Executes the given async function on the backend with manual transaction handling. */+ /**+ * Executes given anonymous function on the backend.+ * Internally this serializes the anonymous function into string and sends it to backend via AJAX.+ * This function is meant for advanced needs where an async function is necessary.+ * In this case, the automatic request-scoped transaction management is not applied,+ * and you need to manually define transaction via api.transactional().+ *+ * If you have a synchronous function, please use api.runOnBackend().+ *+ * @method+ * @param func - (synchronous) function to be executed on the backend+ * @param params - list of parameters to the anonymous function to be sent to backend+ * @returns return value of the executed function on the backend+ */runAsyncOnBackendWithManualTransactionHandling(func: Func, params?: unknown[]): Promise<unknown>;- /** Powerful attribute/value search, e.g. "#dateModified =* MONTH AND #log". */+ /**+ * This is a powerful search method - you can search by attributes and their values, e.g.:+ * "#dateModified =* MONTH AND #log". See full documentation for all options at: https://triliumnext.github.io/Docs/Wiki/search.html+ */searchForNotes(searchString: string): Promise<ScriptFNote[]>;- /** Returns the first note matching the search, or null. */+ /**+ * This is a powerful search method - you can search by attributes and their values, e.g.:+ * "#dateModified =* MONTH AND #log". See full documentation for all options at: https://triliumnext.github.io/Docs/Wiki/search.html+ */searchForNote(searchString: string): Promise<ScriptFNote | null>;- /** Returns a note by its ID (loading it into the cache if needed), or null. */+ /**+ * Returns note by given noteId. If note is missing from the cache, it's loaded.+ */getNote(noteId: string): Promise<ScriptFNote | null>;- /** Returns multiple notes by their IDs (bulk-fills the cache). */+ /**+ * Returns list of notes. If note is missing from the cache, it's loaded.+ *+ * This is often used to bulk-fill the cache with notes which would have to be picked one by one+ * otherwise (by e.g. createLink())+ *+ * @param [silentNotFoundError] - don't report error if the note is not found+ */getNotes(noteIds: string[], silentNotFoundError?: boolean): Promise<ScriptFNote[]>;- /** Refreshes the given notes in the frontend cache from the backend. */+ /**+ * Update frontend tree (note) cache from the backend.+ */reloadNotes(noteIds: string[]): Promise<void>;- /** The name identifying this particular Trilium instance, or null. */+ /**+ * Instance name identifies particular Trilium instance. It can be useful for scripts+ * if some action needs to happen on only one specific instance.+ */getInstanceName(): string | null;- /** Adds plain text at the active editor's cursor. */+ /**+ * Adds given text to the editor cursor+ *+ * @param text - this must be clear text, HTML is not supported.+ */addTextToActiveContextEditor(text: string): void;- /** The active note loaded into the center pane. */+ /**+ * @returns active note (loaded into center pane)+ */getActiveContextNote(): ScriptFNote;- /** The currently active/focused split in the current tab. */+ /**+ * Obtains the currently active/focused split in the current tab.+ *+ * Note that this method does not return the note context of the "Quick edit" panel, it will return the note context behind it.+ */getActiveContext(): ScriptNoteContext;- /** The main (left-most) context of the current tab. */+ /**+ * Obtains the main context of the current tab. This is the left-most split.+ *+ * Note that this method does not return the note context of the "Quick edit" panel, it will return the note context behind it.+ */getActiveMainContext(): ScriptNoteContext;- /** All note contexts (splits) across all tabs. */+ /**+ * @returns returns all note contexts (splits) in all tabs+ */getNoteContexts(): ScriptNoteContext[];- /** All main contexts (one per tab). */+ /**+ * @returns returns all main contexts representing tabs+ */getMainNoteContexts(): ScriptNoteContext[];- /** The CKEditor instance of the active text note, if any. */+ /**+ * See https://ckeditor.com/docs/ckeditor5/latest/api/module_core_editor_editor-Editor.html for documentation on the returned instance.+ *+ * @returns {Promise<BalloonEditor>} instance of CKEditor+ */getActiveContextTextEditor(): Promise<unknown>;- /** The CodeMirror instance of the active code note, if any. */+ /**+ * See https://codemirror.net/doc/manual.html#api+ *+ * @method+ * @returns instance of CodeMirror+ */getActiveContextCodeEditor(): Promise<unknown>;- /** The widget handling the active note detail. */+ /**+ * Get access to the widget handling note detail. Methods like `getWidgetType()` and `getTypeWidget()` to get to the+ * implementation of actual widget type.+ */getActiveNoteDetailWidget(): Promise<unknown>;- /** The note path of the active note, or null. */+ /**+ * @returns returns a note path of active note or null if there isn't active note+ */getActiveContextNotePath(): string | null;- /** The component owning the given DOM element (nearest parent in the DOM tree). */+ /**+ * Returns component which owns the given DOM element (the nearest parent component in DOM tree)+ *+ * @method+ * @param el DOM element+ */getComponentByEl(el: HTMLElement): unknown;- /** Shows an info toast message to the user. */+ /**+ * Show an info toast message to the user.+ */showMessage(message: string, delay?: number): void;- /** Shows an error toast message to the user. */+ /**+ * Show an error toast message to the user.+ */showError(message: string, delay?: number): void;- /** Shows an info dialog to the user. */+ /**+ * Show an info dialog to the user.+ */showInfoDialog(message: string): Promise<void>;- /** Shows a confirm dialog; resolves true if the user confirmed. */+ /**+ * Show confirm dialog to the user.+ * @returns promise resolving to true if the user confirmed+ */showConfirmDialog(message: string): Promise<boolean>;- /** Shows a prompt dialog; resolves to the user's answer. */+ /**+ * Show prompt dialog to the user.+ *+ * @returns promise resolving to the answer provided by the user+ */showPromptDialog(props: { title?: string; message?: string; defaultValue?: string }): Promise<string | null>;- /** Creates a note link (jQuery element) for the given note path. */+ /**+ * Create a note link (jQuery object) for given note.+ *+ * @param {string} notePath (or noteId)+ * @param {object} [params]+ * @param {boolean} [params.showTooltip] - enable/disable tooltip on the link+ * @param {boolean} [params.showNotePath] - show also whole note's path as part of the link+ * @param {boolean} [params.showNoteIcon] - show also note icon before the title+ * @param {string} [params.title] - custom link tile with note's title as default+ * @param {string} [params.title=] - custom link tile with note's title as default+ * @returns {jQuery} - jQuery element with the link (wrapped in <span>)+ */createLink(notePath: string, params?: Record<string, unknown>): unknown;- /** @deprecated use createLink() instead */+ /** @deprecated - use api.createLink() instead */createNoteLink(notePath: string, params?: Record<string, unknown>): unknown;- /** Triggers a Trilium command (low-level). */+ /**+ * Trigger command. This is a very low-level API which should be avoided if possible.+ */triggerCommand(name: string, data?: Record<string, unknown>): Promise<unknown>;- /** Triggers a Trilium event (low-level). */+ /**+ * Trigger event. This is a very low-level API which should be avoided if possible.+ */triggerEvent(name: string, data?: Record<string, unknown>): Promise<unknown>;- /** Sets up a tooltip on the given jQuery element. */+ /**+ * @param {object} $el - jquery object on which to set up the tooltip+ */setupElementTooltip(el: unknown): void;- /** Protects/unprotects a note. */+ /**+ * @param {boolean} protect - true to protect note, false to unprotect+ */protectNote(noteId: string, protect: boolean): Promise<void>;- /** Protects/unprotects a whole subtree. */+ /**+ * @param noteId+ * @param protect - true to protect subtree, false to unprotect+ */protectSubTree(noteId: string, protect: boolean): Promise<void>;- /** Returns (creating if needed) the date-note for today. */+ /**+ * Returns date-note for today. If it doesn't exist, it is automatically created.+ */getTodayNote(): Promise<ScriptFNote>;- /** Returns (creating if needed) the day-note for the given "YYYY-MM-DD" date. */+ /**+ * Returns day note for a given date. If it doesn't exist, it is automatically created.+ *+ * @param date - e.g. "2019-04-29"+ */getDayNote(date: string): Promise<ScriptFNote>;- /** Returns (creating if needed) the week's first day-note for the given date. */+ /**+ * Returns day note for the first date of the week of the given date. If it doesn't exist, it is automatically created.+ *+ * @param date - e.g. "2019-04-29"+ */getWeekFirstDayNote(date: string): Promise<ScriptFNote>;- /** Returns (creating if needed) the week-note for the given "YYYY-MM-DD" date. */+ /**+ * Returns week note for given date. If such a note doesn't exist, it is automatically created.+ *+ * @param date in YYYY-MM-DD format+ * @param rootNote - specify calendar root note, normally leave empty to use the default calendar+ */getWeekNote(date: string): Promise<ScriptFNote>;- /** Returns (creating if needed) the month-note for the given "YYYY-MM" month. */+ /**+ * Returns month-note. If it doesn't exist, it is automatically created.+ *+ * @param month - e.g. "2019-04"+ */getMonthNote(month: string): Promise<ScriptFNote>;- /** Returns (creating if needed) the quarter-note for the given date. */+ /**+ * Returns quarter note for given date. If such a note doesn't exist, it is automatically created.+ *+ * @param date in YYYY-MM format+ * @param rootNote - specify calendar root note, normally leave empty to use the default calendar+ */getQuarterNote(date: string): Promise<ScriptFNote>;- /** Returns (creating if needed) the year-note for the given "YYYY" year. */+ /**+ * Returns year-note. If it doesn't exist, it is automatically created.+ *+ * @method+ * @param {string} year - e.g. "2019"+ * @returns {Promise<FNote>}+ */getYearNote(year: string): Promise<ScriptFNote>;- /** Hoists a note in the current tab ('root' effectively unhoists). */+ /**+ * Hoist note in the current tab. See https://triliumnext.github.io/Docs/Wiki/note-hoisting.html+ *+ * @param {string} noteId - set hoisted note. 'root' will effectively unhoist+ */setHoistedNoteId(noteId: string): void;- /** Binds a global keyboard shortcut (e.g. "ctrl+shift+a") to a handler. */+ /**+ * @param keyboardShortcut - e.g. "ctrl+shift+a"+ * @param [namespace] specify namespace of the handler for the cases where call for bind may be repeated.+ * If a handler with this ID exists, it's replaced by the new handler.+ */bindGlobalShortcut(keyboardShortcut: string, handler: () => void, namespace?: string): void;- /** Resolves once all backend → frontend synchronization is finished. */+ /**+ * Trilium runs in a backend and frontend process, when something is changed on the backend from a script,+ * frontend will get asynchronously synchronized.+ *+ * This method returns a promise which resolves once all the backend -> frontend synchronization is finished.+ * Typical use case is when a new note has been created, we should wait until it is synced into frontend and only then activate it.+ */waitUntilSynced(): Promise<unknown>;- /** Refreshes all open notes that include the given note. */+ /**+ * This will refresh all currently opened notes which have included note specified in the parameter+ *+ * @param includedNoteId - noteId of the included note+ */refreshIncludedNote(includedNoteId: string): void;- /** Returns a random (non-cryptographic) alphanumeric string of the given length. */+ /**+ * Return randomly generated string of given length. This random string generation is NOT cryptographically secure.+ *+ * @method+ * @param length of the string+ * @returns random string+ */randomString(length: number): string;- /** Formats a size in bytes into a human-readable string. */+ /**+ * @param size in bytes+ * @return formatted string+ */formatSize(size: number): string;- /** @deprecated use formatSize() */+ /**+ * @param size in bytes+ * @return formatted string+ * @deprecated - use api.formatSize()+ */formatNoteSize(size: number): string;- /** Formats a date as "YYYY-MM-DD". */+ /**+ * @returns date in YYYY-MM-DD format+ */formatDateISO(date: Date): string;/** Parses a date string into a Date. */parseDate(str: string): Date;@@ -216,7 +429,10 @@ export interface FrontendApi {logMessages: Record<string, string[]>;/** Per-note spaced-update handlers for the log pane. */logSpacedUpdates: Record<string, unknown>;- /** Logs a message to the UI log pane (joins arguments like console.log). */+ /**+ * Log given message to the log pane in UI.+ * Accepts multiple arguments which are joined with spaces, similar to `console.log`.+ */log(...args: unknown[]): void;/** The Preact API surface (components, hooks) for render scripts. */@@ -283,23 +499,46 @@ export interface ScriptNoteAndBranch {* (`application/javascript;env=backend`). Runs server-side: no DOM, no jQuery.*/export interface BackendApi {- /** Note where the script started executing (the entrypoint). */+ /**+ * Note where the script started executing (entrypoint).+ * As an analogy, in C this would be the file which contains the main() function of the current process.+ */startNote?: ScriptBNote | null;- /** Note where the script is currently executing. */+ /**+ * Note where the script is currently executing. This comes into play when your script is spread in multiple code+ * notes, the script starts in "startNote", but then through function calls may jump into another note (currentNote).+ * A similar concept in C would be __FILE__+ * Don't mix this up with the concept of active note.+ */currentNote: ScriptBNote;- /** Entity whose event triggered this execution. */+ /**+ * Entity whose event triggered this execution+ */originEntity?: unknown | null;- /** day.js library for date manipulation. */+ /**+ * day.js library for date manipulation. See {@link https://day.js.org} for documentation+ */dayjs: ScriptDayjs;- /** xml2js library for XML parsing. */+ /**+ * xml2js library for XML parsing. See {@link https://github.com/Leonidas-from-XIV/node-xml2js} for documentation+ */xml2js: unknown;- /** @deprecated use htmlParser instead */+ /**+ * cheerio library for HTML parsing and manipulation. See {@link https://cheerio.js.org} for documentation+ * @deprecated cheerio will be removed in a future version. Use api.htmlParser (node-html-parser) instead.+ */cheerio: unknown;- /** node-html-parser for HTML parsing. */+ /**+ * node-html-parser library for HTML parsing. See {@link https://github.com/piotr-nicol/node-html-parser} for documentation.+ * This is the recommended replacement for cheerio.+ */htmlParser: unknown;- /** The name identifying this particular Trilium instance, or null. */+ /**+ * Instance name identifies particular Trilium instance. It can be useful for scripts+ * if some action needs to happen on only one specific instance.+ */getInstanceName(): string | null;/** Returns a note by its ID, or null. */@@ -321,27 +560,61 @@ export interface BackendApi {/** Returns all options. */getOptions(): unknown[];- /** Powerful attribute/value search, e.g. "#dateModified =* MONTH AND #log". */+ /**+ * This is a powerful search method - you can search by attributes and their values, e.g.:+ * "#dateModified =* MONTH AND #log". See {@link https://triliumnext.github.io/Docs/Wiki/search.html} for full documentation for all options+ */searchForNotes(query: string, searchParams?: Record<string, unknown>): ScriptBNote[];- /** Returns the first note matching the search, or null. */+ /**+ * This is a powerful search method - you can search by attributes and their values, e.g.:+ * "#dateModified =* MONTH AND #log". See {@link https://triliumnext.github.io/Docs/Wiki/search.html} for full documentation for all options+ */searchForNote(query: string, searchParams?: Record<string, unknown>): ScriptBNote | null;- /** Returns all notes carrying the given label. */+ /**+ * Retrieves notes with given label name & value+ *+ * @param name - attribute name+ * @param value - attribute value+ */getNotesWithLabel(name: string, value?: string): ScriptBNote[];- /** Returns the first note carrying the given label, or null. */+ /**+ * Retrieves first note with given label name & value+ *+ * @param name - attribute name+ * @param value - attribute value+ */getNoteWithLabel(name: string, value?: string): ScriptBNote | null;- /** Ensures a branch exists between note and parent (creating it if needed). */+ /**+ * If there's no branch between note and parent note, create one. Otherwise, do nothing. Returns the new or existing branch.+ *+ * @param prefix - if branch is created between note and parent note, set this prefix+ */ensureNoteIsPresentInParent(noteId: string, parentNoteId: string, prefix?: string): { branch: ScriptBBranch | null };- /** Ensures no branch exists between note and parent (removing it if present). */+ /**+ * If there's a branch between note and parent note, remove it. Otherwise, do nothing.+ */ensureNoteIsAbsentFromParent(noteId: string, parentNoteId: string): void;- /** Creates or removes the branch between note and parent based on `present`. */+ /**+ * Based on the value, either create or remove branch between note and parent note.+ *+ * @param present - true if we want the branch to exist, false if we want it gone+ * @param prefix - if branch is created between note and parent note, set this prefix+ */toggleNoteInParent(present: boolean, noteId: string, parentNoteId: string, prefix?: string): void;- /** Creates a text note under the given parent. */+ /**+ * Create text note. See also createNewNote() for more options.+ */createTextNote(parentNoteId: string, title: string, content: string): ScriptNoteAndBranch;- /** Creates a data (JSON) note under the given parent. */+ /**+ * Create data note - data in this context means object serializable to JSON. Created note will be of type 'code' and+ * JSON MIME type. See also createNewNote() for more options.+ */createDataNote(parentNoteId: string, title: string, content: object): ScriptNoteAndBranch;- /** Creates a new note with full control over its parameters. */+ /**+ * @returns object contains newly created entities note and branch+ */createNewNote(params: {parentNoteId: string;title: string;@@ -355,45 +628,120 @@ export interface BackendApi {logMessages: Record<string, string[]>;/** Per-note spaced-update handlers for the log pane. */logSpacedUpdates: Record<string, unknown>;- /** Logs a message to the Trilium log and the UI log pane. */+ /**+ * Log given message to trilium logs and log pane in UI.+ * Accepts multiple arguments which are joined with spaces, similar to `console.log`.+ */log(...args: unknown[]): void;- /** Returns the root note of the calendar. */+ /**+ * Returns root note of the calendar.+ */getRootCalendarNote(): ScriptBNote | null;- /** Returns (creating if needed) the day-note for the given "YYYY-MM-DD" date. */+ /**+ * Returns day note for given date. If such note doesn't exist, it is created.+ *+ * @method+ * @param date in YYYY-MM-DD format+ * @param rootNote - specify calendar root note, normally leave empty to use the default calendar+ */getDayNote(date: string, rootNote?: ScriptBNote): ScriptBNote | null;- /** Returns (creating if needed) today's day-note. */+ /**+ * Returns today's day note. If such note doesn't exist, it is created.+ *+ * @param rootNote specify calendar root note, normally leave empty to use the default calendar+ */getTodayNote(rootNote?: ScriptBNote): ScriptBNote | null;- /** Returns (creating if needed) the week's first day-note for the given date. */+ /**+ * Returns note for the first date of the week of the given date.+ *+ * @param date in YYYY-MM-DD format+ * @param rootNote - specify calendar root note, normally leave empty to use the default calendar+ */getWeekFirstDayNote(date: string, rootNote?: ScriptBNote): ScriptBNote | null;- /** Returns (creating if needed) the week-note for the given date, or null if unsupported. */+ /**+ * Returns week note for given date. If such a note doesn't exist, it is created.+ *+ * <p>+ * If the calendar does not support week notes, this method will return `null`.+ *+ * @param date in YYYY-MM-DD format+ * @param rootNote - specify calendar root note, normally leave empty to use the default calendar+ * @return an existing or newly created week note, or `null` if the calendar does not support week notes.+ */getWeekNote(date: string, rootNote?: ScriptBNote): ScriptBNote | null;- /** Returns (creating if needed) the month-note for the given "YYYY-MM" month. */+ /**+ * Returns month note for given date. If such a note doesn't exist, it is created.+ *+ * @param date in YYYY-MM format+ * @param rootNote - specify calendar root note, normally leave empty to use the default calendar+ */getMonthNote(date: string, rootNote?: ScriptBNote): ScriptBNote | null;- /** Returns (creating if needed) the quarter-note for the given date. */+ /**+ * Returns quarter note for given date. If such a note doesn't exist, it is created.+ *+ * @param date in YYYY-MM format+ * @param rootNote - specify calendar root note, normally leave empty to use the default calendar+ */getQuarterNote(date: string, rootNote?: ScriptBNote): ScriptBNote | null;- /** Returns (creating if needed) the year-note for the given "YYYY" year. */+ /**+ * Returns year note for given year. If such a note doesn't exist, it is created.+ *+ * @param year in YYYY format+ * @param rootNote - specify calendar root note, normally leave empty to use the default calendar+ */getYearNote(year: string, rootNote?: ScriptBNote): ScriptBNote | null;- /** Sorts the child notes of the given note. */+ /**+ * Sort child notes of a given note.+ */sortNotes(parentNoteId: string, sortConfig: { sortBy?: string; reverse?: boolean; foldersFirst?: boolean }): void;- /** Sets or removes a note's branch under a parent, looked up by prefix. */+ /**+ * This method finds note by its noteId and prefix and either sets it to the given parentNoteId+ * or removes the branch (if parentNoteId is not given).+ *+ * This method looks similar to toggleNoteInParent() but differs because we're looking up branch by prefix.+ *+ * @deprecated this method is pretty confusing and serves specialized purpose only+ */setNoteToParent(noteId: string, prefix: string, parentNoteId: string | null): void;- /** Runs the given function inside a transaction (reusing an existing one if present). */+ /**+ * This functions wraps code which is supposed to be running in transaction. If transaction already+ * exists, then we'll use that transaction.+ *+ * @param func+ * @returns result of func callback+ */transactional<T>(func: () => T): T;- /** Returns a random (non-cryptographic) alphanumeric string of the given length. */+ /**+ * Return randomly generated string of given length. This random string generation is NOT cryptographically secure.+ *+ * @param length of the string+ * @returns random string+ */randomString(length: number): string;- /** Escapes the given HTML string. */+ /**+ * @param to escape+ * @returns escaped string+ */escapeHtml(str: string): string;- /** Unescapes the given HTML string. */+ /**+ * @param string to unescape+ * @returns unescaped string+ */unescapeHtml(str: string): string;- /** Low-level SQL access. */+ /**+ * sql+ * @type {module:sql}+ */sql: unknown;/** Application info (version, build date, etc.). */getAppInfo(): unknown;- /** Creates or updates a launchbar launcher. */+ /**+ * Creates a new launcher to the launchbar. If the launcher (id) already exists, it will be updated.+ */createOrUpdateLauncher(opts: {id: string;type: "note" | "script" | "customWidget";@@ -405,14 +753,46 @@ export interface BackendApi {scriptNoteId?: string;widgetNoteId?: string;}): { note: ScriptBNote };- /** Exports a subtree to a zip file in the given format. */+ /**+ * @param format - either 'html' or 'markdown'+ */exportSubtreeToZipFile(noteId: string, format: "markdown" | "html", zipFilePath: string): Promise<void>;- /** Executes the given function on all connected frontend instances. */+ /**+ * Executes given anonymous function on the frontend(s).+ * Internally, this serializes the anonymous function into string and sends it to frontend(s) via WebSocket.+ * Note that there can be multiple connected frontend instances (e.g. in different tabs). In such case, all+ * instances execute the given function.+ *+ * @param script - script to be executed on the frontend+ * @param params - list of parameters to the anonymous function to be sent to frontend+ * @returns no return value is provided.+ */runOnFrontend(script: (() => void) | string, params?: unknown[]): void;- /** Runs the callback while no sync process is running. */+ /**+ * Sync process can make data intermittently inconsistent. Scripts which require strong data consistency+ * can use this function to wait for a possible sync process to finish and prevent new sync process from starting+ * while it is running.+ *+ * Because this is an async process, the inner callback doesn't have automatic transaction handling, so in case+ * you need to make some DB changes, you need to surround your call with api.transactional(...)+ *+ * @param callback - function to be executed while sync process is not running+ * @returns resolves once the callback is finished (callback is awaited)+ */runOutsideOfSync(callback: () => void): Promise<void>;- /** Triggers a backup immediately, returning the backup file path. */+ /**+ * @param backupName - If the backupName is e.g. "now", then the backup will be written to "backup-now.db" file+ * @returns resolves once the backup is finished+ */backupNow(backupName: string): Promise<string>;- /** Duplicates a subtree under a new parent. */+ /**+ * Enables the complete duplication of the specified original note and all its children into the specified parent note.+ * The new note will be named the same as the original, with (Dup) added to the end of it.+ *+ * @param origNoteId - the noteId for the original note to be duplicated+ * @param newParentNoteId - the noteId for the parent note where the duplication is to be placed.+ *+ * @returns the note and the branch of the newly created note.+ */duplicateSubtree(origNoteId: string, newParentNoteId: string): ScriptNoteAndBranch;}