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
docs(scripting): render the Backend API as a User Guide page
Elian Dorana1b332fd77d5
diff --git a/CLAUDE.md b/CLAUDE.mdindex 7d03ceeb22..2f1a0bc934 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -233,9 +233,9 @@ Use `note.getOwnedAttribute()` for direct, `note.getAttribute()` for inherited.## Documentation-- Script API reference — Generated by `apps/build-docs` (TypeDoc) into the gitignored `site/script-api/{backend,frontend}` and published to [docs.triliumnotes.org](https://docs.triliumnotes.org/). Not committed; never hand-edit — it's regenerated from the script API type definitions+- Script API reference — Generated by `apps/build-docs` (TypeDoc) into the gitignored `site/script-api/frontend` and published to [docs.triliumnotes.org](https://docs.triliumnotes.org/). Not committed; never hand-edit — it's regenerated from the script API type definitions- `docs/User Guide/` — Markdown pages plus `!!!meta.json`; the in-app help artifacts `apps/server/src/assets/help/help_meta.json` and `help_content.json` are **generated from it and never hand-edited**. Edit the Markdown by hand or in the editor (`pnpm edit-docs:edit-docs`), then run `pnpm edit-docs:sync-docs` so both artifacts follow. A page's shape (a new page, an image, a rename, a move) is meta work — the **`writing-documentation` skill**'s `docs.mjs` does it (`new`, `image`, `rename`, `move`, `delete`) and audits the trees (`check`); load the skill before touching `docs/`-- Generated User Guide pages — the ETAPI, internal API and Electron API references are rendered by `apps/edit-docs` (`openapi_markdown.ts`, `typedoc_markdown.ts`) from the sources listed under `openApiPages` / `typeDocPages` in `edit-docs-config.yaml`, on every `sync-docs` and `edit-docs` run. Never hand-edit them: change the OpenAPI document or the TypeScript comments, then `sync-docs`+- Generated User Guide pages — the ETAPI, internal API, Electron API and backend script API references are rendered by `apps/edit-docs` (`openapi_markdown.ts`, `typedoc_markdown.ts`) from the sources listed under `openApiPages` / `typeDocPages` in `edit-docs-config.yaml`, on every `sync-docs` and `edit-docs` run. Never hand-edit them: change the OpenAPI document or the TypeScript comments, then `sync-docs`- `docs/Developer Guide/` and `docs/Release Notes/` — Safe for direct Markdown editing (also normalized by `sync-docs`)### In-app help (the `_help` subtree)diff --git a/apps/build-docs/src/backend_script_entrypoint.ts b/apps/build-docs/src/backend_script_entrypoint.tsdeleted file mode 100644index 7b00ed752b..0000000000--- a/apps/build-docs/src/backend_script_entrypoint.ts+++ /dev/null@@ -1,38 +0,0 @@-/**- * The backend script API is accessible to code notes with the "JS (backend)" language.- *- * The entire API is exposed as a single global: {@link api}- *- * @module Backend Script API- */--/**- * This file creates the entrypoint for TypeDoc that simulates the context from within a- * script note on the server side.- *- * Make sure to keep in line with backend's `script_context.ts`.- */--export type {- AbstractBeccaEntity,- BAttachment,- BAttribute,- BBranch,- BEtapiToken,- BNote,- BOption,- BRecentNote,- BRevision-} from "@triliumnext/core";--import { BNote, BackendScriptApi, type BackendScriptApiInterface as Api } from "@triliumnext/core";--export type { Api };--const fakeNote = new BNote();--/**- * The `api` global variable allows access to the backend script API,- * which is documented in {@link Api}.- */-export const api: Api = new BackendScriptApi(fakeNote, {});diff --git a/apps/build-docs/src/script-api.ts b/apps/build-docs/src/script-api.tsindex 2c62477474..a9d587475f 100644--- a/apps/build-docs/src/script-api.ts+++ b/apps/build-docs/src/script-api.ts@@ -7,10 +7,8 @@ export default function buildScriptApi({ baseDir, gitRootDir }: BuildContext) {// Generate typesexecSync(`pnpm typecheck`, { stdio: "inherit", cwd: gitRootDir });- for (const config of [ "backend", "frontend" ]) {- const outDir = join(baseDir, "script-api", config);- execSync(`pnpm typedoc --options typedoc.${config}.json --html "${outDir}"`, {- stdio: "inherit"- });- }+ const outDir = join(baseDir, "script-api", "frontend");+ execSync(`pnpm typedoc --options typedoc.frontend.json --html "${outDir}"`, {+ stdio: "inherit"+ });}diff --git a/apps/build-docs/typedoc.backend.json b/apps/build-docs/typedoc.backend.jsondeleted file mode 100644index a7f91c42e4..0000000000--- a/apps/build-docs/typedoc.backend.json+++ /dev/null@@ -1,11 +0,0 @@-{- "$schema": "https://typedoc.org/schema.json",- "name": "Trilium Backend API",- "entryPoints": [- "src/backend_script_entrypoint.ts"- ],- "tsconfig": "tsconfig.app.json",- "plugin": [- "typedoc-plugin-missing-exports"- ]-}diff --git a/apps/server/src/assets/help/help_content.json b/apps/server/src/assets/help/help_content.jsonindex 51397001ae..43c92cc8c5 100644--- a/apps/server/src/assets/help/help_content.json+++ b/apps/server/src/assets/help/help_content.json@@ -270,11 +270,12 @@"_help_RSssb9S3xgSr": "<figure class=\"image image_resized\" style=\"width:54.58%;\"><img style=\"aspect-ratio:896/712;\" src=\"{{helpAssets}}/User%20Guide/Scripting/Frontend%20Basics/Preact/Built-in%20components_image.png\" width=\"896\" height=\"712\"><figcaption>A partial screenshot from the Widget showcase example (see below).</figcaption></figure><p>Trilium comes with its own set of Preact components, some of which are also available to <a class=\"reference-link\" href=\"#root/_help_MgibgPcfeuGz\">Custom Widgets</a> and <a class=\"reference-link\" href=\"#root/_help_HcABDtFCkbFN\">Render Note</a>.</p><p>To use these components, simply import them from <code>trilium:preact</code>:</p><pre><code class=\"language-text-jsx\">import { ActionButton, Button, LinkButton } from \"trilium:preact\";</code></pre><p>and then use them:</p><pre><code class=\"language-text-jsx\">export default function MyRenderNote() {\n const onClick = () => showMessage(\"A button was pressed\");\n \n return (\n <>\n <h2>Buttons</h2>\n <div style={{ display: \"flex\", gap: \"1em\", alignItems: \"center\" }}>\n <ActionButton icon=\"bx bx-rocket\" text=\"Action button\" onClick={onClick} />\n <Button icon=\"bx bx-rocket\" text=\"Simple button\" onClick={onClick} />\n <LinkButton text=\"Link button\" onClick={onClick} /> \n </div>\n </>\n )\n}</code></pre><h2>Widget showcase</h2><aside class=\"admonition tip\"><p>Starting with v0.101.0, the widget showcase is also available in the <a class=\"reference-link\" href=\"#root/_help_6tZeKvSHEUiB\">Demo Notes</a>.</p></aside><p>This is a <a class=\"reference-link\" href=\"#root/_help_HcABDtFCkbFN\">Render Note</a> example with JSX that shows most of the built-in components that are accessible to custom widgets and JSX render notes.</p><p>To use it, simply:</p><ol><li>Create a render note.</li><li>Create a child code note of JSX type with the content of this file: <a class=\"reference-link\" href=\"#root/_help_i9B4IW7b6V6z\">Widget showcase</a></li><li>Set the <code>~renderNote</code> relation of the parent note to the child note.</li><li>Refresh the render note to see the results.</li></ol>","_help_i9B4IW7b6V6z": "import {\n ActionButton, Button, LinkButton,\n Admonition, Collapsible,\n FormCheckbox, FormDropdownList, FormFileUploadButton, FormGroup, FormRadioGroup, FormTextArea,\n FormTextBox, FormToggle, Slider, RawHtml, LoadingSpinner, Icon,\n ColorPicker,\n Dropdown, FormListItem, FormDropdownDivider, FormDropdownSubmenu,\n NoteAutocomplete, NoteLink, Modal,\n Table,\n CKEditor,\n useEffect, useState\n} from \"trilium:preact\";\nimport { showMessage } from \"trilium:api\";\n\nexport default function() {\n const [ time, setTime ] = useState();\n const lorem = \"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam accumsan eu odio non gravida. Pellentesque ornare, arcu condimentum molestie dignissim, nibh turpis ultrices elit, eget elementum nunc erat at erat. Maecenas vehicula consectetur elit, nec fermentum elit venenatis eu.\";\n useEffect(() => {\n const interval = setInterval(() => setTime(new Date().toLocaleString()), 1000);\n return () => clearInterval(interval);\n }, []);\n\n return (\n <div style={{ padding: 20, display: \"flex\", flexDirection: \"column\", gap: \"1em\" }}>\n <h1>Widget showcase</h1>\n\n <Buttons />\n <Admonition type=\"note\">\n <strong>Admonition</strong><br />\n {lorem}\n </Admonition>\n\n <Collapsible title=\"Collapsible\" initiallyExpanded>\n {lorem}\n </Collapsible>\n\n <FormElements />\n <NoteElements />\n <ModalSample />\n <DropdownSample />\n <CollectionViews />\n </div>\n );\n}\n\nfunction Buttons() {\n const onClick = () => showMessage(\"A button was pressed\");\n\n return (\n <>\n <h2>Buttons</h2>\n <div style={{ display: \"flex\", gap: \"1em\", alignItems: \"center\" }}>\n <ActionButton icon=\"bx bx-rocket\" text=\"Action button\" onClick={onClick} />\n <Button icon=\"bx bx-rocket\" text=\"Simple button\" onClick={onClick} />\n <LinkButton text=\"Link button\" onClick={onClick} />\n </div>\n </>\n )\n}\n\nfunction FormElements() {\n const [ checkboxChecked, setCheckboxChecked ] = useState(false);\n const [ dropdownValue, setDropdownValue ] = useState(\"key-1\");\n const [ radioGroupValue, setRadioGroupValue ] = useState(\"key-1\");\n const [ sliderValue, setSliderValue ] = useState(50);\n const [ color, setColor ] = useState(\"#43a047\");\n\n return (\n <>\n <h2>Form elements</h2>\n <div style={{ display: \"grid\", gridTemplateColumns: \"1fr 1fr 1fr\", gap: \"1em\" }}>\n <FormGroup name=\"checkbox\" label=\"Checkbox\">\n <FormCheckbox label=\"Checkbox\" currentValue={checkboxChecked} onChange={setCheckboxChecked} />\n </FormGroup>\n <FormGroup name=\"toggle\" label=\"Toggle\">\n <FormToggle switchOnName=\"Off\" switchOffName=\"On\" currentValue={checkboxChecked} onChange={setCheckboxChecked} />\n </FormGroup>\n <FormGroup name=\"dropdown\" label=\"Dropdown\">\n <FormDropdownList\n values={[\n { key: \"key-1\", name: \"First item\" },\n { key: \"key-2\", name: \"Second item\" },\n { key: \"key-3\", name: \"Third item\" },\n ]}\n currentValue={dropdownValue} onChange={setDropdownValue}\n keyProperty=\"key\" titleProperty=\"name\"\n />\n </FormGroup>\n <FormGroup name=\"radio-group\" label=\"Radio group\">\n <FormRadioGroup\n values={[\n { value: \"key-1\", label: \"First item\" },\n { value: \"key-2\", label: \"Second item\" },\n { value: \"key-3\", label: \"Third item\" },\n ]}\n currentValue={radioGroupValue} onChange={setRadioGroupValue}\n />\n </FormGroup>\n <FormGroup name=\"text-box\" label=\"Text box\">\n <FormTextBox\n placeholder=\"Type something...\"\n currentValue=\"\" onChange={(newValue) => {}}\n />\n </FormGroup>\n <FormGroup name=\"text-area\" label=\"Text area\">\n <FormTextArea\n placeholder=\"Type something bigger...\"\n currentValue=\"\" onChange={(newValue) => {}}\n />\n </FormGroup>\n <FormGroup name=\"color-picker\" label=\"Color picker\">\n <ColorPicker currentValue={color} onChange={setColor} />\n </FormGroup>\n <FormGroup name=\"slider\" label=\"Slider\">\n <Slider\n min={1} max={100}\n value={sliderValue} onChange={setSliderValue}\n />\n </FormGroup>\n <FormGroup name=\"file-upload\" label=\"File upload\">\n <FormFileUploadButton\n text=\"Upload\"\n onChange={(files) => {\n const file = files?.[0];\n if (!file) return;\n showMessage(`Got file \"${file.name}\" of size ${file.size} B and type ${file.type}.`);\n }}\n />\n </FormGroup>\n <FormGroup name=\"icon\" label=\"Icon\">\n <Icon icon=\"bx bx-smile\" />\n </FormGroup>\n <FormGroup name=\"loading-spinner\" label=\"Loading spinner\">\n <LoadingSpinner />\n </FormGroup>\n <FormGroup name=\"raw-html\" label=\"Raw HTML\">\n <RawHtml html=\"<strong>Hi</strong> <em>there</em>\" />\n </FormGroup>\n </div>\n </>\n )\n}\n\nfunction NoteElements() {\n const [ noteId, setNoteId ] = useState(\"\");\n\n return (\n <div>\n <h2>Note elements</h2>\n\n <FormGroup name=\"note-autocomplete\" label=\"Note autocomplete\">\n <NoteAutocomplete\n placeholder=\"Select a note\"\n noteId={noteId} noteIdChanged={setNoteId}\n />\n </FormGroup>\n\n <FormGroup name=\"note-link\" label=\"Note link\">\n {noteId\n ? <NoteLink notePath={noteId} showNoteIcon />\n : <span>Select a note first</span>}\n </FormGroup>\n </div>\n );\n}\n\nfunction ModalSample() {\n const [ shown, setShown ] = useState(false);\n\n return (\n <>\n <h2>Modal</h2>\n <Button text=\"Open modal\" onClick={() => setShown(true)} />\n <Modal title=\"Modal title\" size=\"md\" show={shown} onHidden={() => setShown(false)}>\n Modal goes here.\n </Modal>\n </>\n )\n}\n\nfunction DropdownSample() {\n return (\n <>\n <h2>Dropdown menu</h2>\n <Dropdown text=\"Dropdown\" hideToggleArrow>\n <FormListItem icon=\"bx bx-cut\">Cut</FormListItem>\n <FormListItem icon=\"bx bx-copy\">Copy</FormListItem>\n <FormListItem icon=\"bx bx-paste\">Paste</FormListItem>\n <FormDropdownDivider />\n <FormDropdownSubmenu title=\"Submenu\">\n <FormListItem>More items</FormListItem>\n </FormDropdownSubmenu>\n </Dropdown>\n </>\n )\n}\n\nfunction CollectionViews() {\n return (\n <>\n <h2>Collection views</h2>\n <p>\n A generic <code>Table</code> (Tabulator) is available. A <code>Calendar</code>\n {\" \"}(FullCalendar) component is also exposed, but it requires you to pass a\n {\" \"}<code>plugins</code> array to render a view, so it is not demonstrated here.\n </p>\n <Table\n layout=\"fitColumns\"\n columns={[\n { title: \"Name\", field: \"name\" },\n { title: \"Progress\", field: \"progress\" }\n ]}\n data={[\n { id: 1, name: \"First task\", progress: \"80%\" },\n { id: 2, name: \"Second task\", progress: \"20%\" }\n ]}\n />\n </>\n )\n}\n","_help_irkwjdNtjcxR": "<p>Front-end scripts can be run automatically on certain triggering conditions.</p><p>To do so, set the <code>run</code> <a href=\"#root/_help_HI6GBBIduIgv\">label</a> to either:</p><ul><li><code>frontendStartup</code> - when Trilium frontend starts up (or is refreshed), but not on mobile.</li><li><code>mobileStartup</code> - when Trilium frontend starts up (or is refreshed), on mobile.</li></ul><aside class=\"admonition note\"><p>One script can be triggered on multiple events, this can be done by adding multiple <code>run</code> labels. Separating multiple values by commas <strong>is not</strong> supported.</p></aside><p>Backend scripts have more powerful triggering conditions, for example they can run automatically on a hourly or daily basis, but also on events such as when a note is created or an attribute is modified. See the server-side <a class=\"reference-link\" href=\"#root/_help_GPERMystNGTB\">Events</a> for more information.</p><h2>Safe mode</h2><p>While <a href=\"#root/_help_64ZTlUPgEPtW\">safe mode</a> is active, scripts with events won't trigger.</p>",- "_help_SPirpZypehBG": "<p>Unlike <a href=\"#root/_help_yIhgI5H7A2Sm\">front-end scripts</a> which run on the client / browser-side, back-end scripts run directly on the Node.js environment of the Trilium server.</p><p>Back-end scripts can be used both on a <a class=\"reference-link\" href=\"#root/_help_WOcw2SLH6tbX\">Server Installation</a> (where it will run on the device the server is running on), or on the <a class=\"reference-link\" href=\"#root/_help_poXkQfguuA0U\">Desktop Installation</a> (where it will run on the PC).</p><aside class=\"admonition important\"><p>Starting with v0.104.0, backend scripts are disabled by default to reduce the attack surface. See <a class=\"reference-link\" href=\"#root/_help_fiHicjpHjIRJ\">Security</a> for more information.</p></aside><h2>Advantages of backend scripts</h2><p>The benefit of backend scripts is that they can be pretty powerful, for example to have access to the underlying system, for example it can read files or execute processes.</p><p>However, the main benefit of backend scripts is that they have easier access to the notes since the information about them is already loaded in memory. Whereas on the client, notes have to be manually loaded first.</p><h2>Creating a backend script</h2><p>Create a new <a class=\"reference-link\" href=\"#root/_help_6f9hih2hXXZk\">Code</a> note and select the language <em>JavaScript (Trilium backend)</em>, or choose <em>Insert child note</em> → <em>Code</em> → <em>Backend script</em> in the <a class=\"reference-link\" href=\"#root/_help_YtSN43OrfzaA\">Note tree contextual menu</a>, which does both in one step.</p><h2>Running backend scripts</h2><p>Backend scripts can be either run manually (via the Execute button on the script page), or they can be triggered on certain events.</p><p>When a script run manually or from a launcher throws an error, Trilium shows a <em>Scripting error</em> notification with the error message and a link to the note that failed. If the error comes from a child note the script requires, the link points to that child note. Changes the script made to notes before the error are rolled back.</p><p>In addition, scripts can be run automatically when the server starts up, on a fixed time interval or when a certain event occurs (such as an attribute being modified). For more information, see the dedicated <a class=\"reference-link\" href=\"#root/_help_GPERMystNGTB\">Events</a> page.</p><h2>Script API</h2><p>Trilium exposes a set of APIs that can be directly consumed by scripts, under the <code>api</code> object. For a reference of this API, see <a class=\"reference-link\" href=\"{{helpAssets}}/User%20Guide/Scripting/Script%20API/Backend%20API.dat\">Backend API</a>.</p>",+ "_help_SPirpZypehBG": "<p>Unlike <a href=\"#root/_help_yIhgI5H7A2Sm\">front-end scripts</a> which run on the client / browser-side, back-end scripts run directly on the Node.js environment of the Trilium server.</p><p>Back-end scripts can be used both on a <a class=\"reference-link\" href=\"#root/_help_WOcw2SLH6tbX\">Server Installation</a> (where it will run on the device the server is running on), or on the <a class=\"reference-link\" href=\"#root/_help_poXkQfguuA0U\">Desktop Installation</a> (where it will run on the PC).</p><aside class=\"admonition important\"><p>Starting with v0.104.0, backend scripts are disabled by default to reduce the attack surface. See <a class=\"reference-link\" href=\"#root/_help_fiHicjpHjIRJ\">Security</a> for more information.</p></aside><h2>Advantages of backend scripts</h2><p>The benefit of backend scripts is that they can be pretty powerful, for example to have access to the underlying system, for example it can read files or execute processes.</p><p>However, the main benefit of backend scripts is that they have easier access to the notes since the information about them is already loaded in memory. Whereas on the client, notes have to be manually loaded first.</p><h2>Creating a backend script</h2><p>Create a new <a class=\"reference-link\" href=\"#root/_help_6f9hih2hXXZk\">Code</a> note and select the language <em>JavaScript (Trilium backend)</em>, or choose <em>Insert child note</em> → <em>Code</em> → <em>Backend script</em> in the <a class=\"reference-link\" href=\"#root/_help_YtSN43OrfzaA\">Note tree contextual menu</a>, which does both in one step.</p><h2>Running backend scripts</h2><p>Backend scripts can be either run manually (via the Execute button on the script page), or they can be triggered on certain events.</p><p>When a script run manually or from a launcher throws an error, Trilium shows a <em>Scripting error</em> notification with the error message and a link to the note that failed. If the error comes from a child note the script requires, the link points to that child note. Changes the script made to notes before the error are rolled back.</p><p>In addition, scripts can be run automatically when the server starts up, on a fixed time interval or when a certain event occurs (such as an attribute being modified). For more information, see the dedicated <a class=\"reference-link\" href=\"#root/_help_GPERMystNGTB\">Events</a> page.</p><h2>Script API</h2><p>Trilium exposes a set of APIs that can be directly consumed by scripts, under the <code>api</code> object. For a reference of this API, see <a class=\"reference-link\" href=\"#root/_help_MEtfsqa5VwNi\">Backend API</a>.</p>","_help_fZ2IGYFXjkEy": "<p>Older versions of Trilium Notes allowed the use of Common.js module imports inside backend scripts, such as:</p><pre><code class=\"language-text-x-trilium-auto\">const isBetween = require('dayjs/plugin/isBetween')\napi.dayjs.extend(isBetween)</code></pre><p>For newer versions, Node.js imports are <strong>not officially supported anymore</strong>, since we've added a bundler which makes it more difficult to reuse dependencies.</p><p>Theoretically it's still possible to use imports by manually setting up a <code>node_modules</code> in the server directory via <code>npm</code> or <code>pnpm</code>.</p>","_help_GPERMystNGTB": "<p><a href=\"#root/_help_CdNpE2pqjmI6\">Script</a> notes can be triggered by events. Note that these are backend events and thus relation need to point to the \"JavaScript (Trilium backend)\" code note.</p><h2>Global events</h2><p>Global events are attached to the script note via label. Simply create a <code>run</code> label with some of these values and script note will be executed once the event occurs.</p><figure class=\"table\"><table><thead><tr><th>Label</th><th>Description</th></tr></thead><tbody><tr><td><code>run</code></td><td><p>Defines on which events script should run. Possible values are:</p><ul><li><code>backendStartup</code> - when Trilium backend starts up</li><li><code>hourly</code> - run once an hour. You can use additional label <code>runAtHour</code> to specify at which hour, on the back-end.</li><li><code>daily</code> - run once a day, on the back-end</li></ul></td></tr><tr><td><code>runOnInstance</code></td><td>Specifies that the script should only run on a particular <a class=\"reference-link\" href=\"#root/_help_c5xB8m4g2IY6\">Trilium instance</a>.</td></tr><tr><td><code>runAtHour</code></td><td>On which hour should this run. Should be used together with <code>#run=hourly</code>. Can be defined multiple times for more runs during the day.</td></tr></tbody></table></figure><p>Frontend scripts also have similar <a class=\"reference-link\" href=\"#root/_help_irkwjdNtjcxR\">Events</a>, such as when the application starts.</p><aside class=\"admonition note\"><p>One script can be triggered on multiple events, this can be done by adding multiple <code>run</code> labels. Separating multiple values by commas <strong>is not</strong> supported.</p></aside><h2>Entity events</h2><p>Other events are bound to some entity, these are defined as <a href=\"#root/_help_zEY4DaJG4YT5\">relations</a> - meaning that script is triggered only if note has this script attached to it through relations (or it can inherit it).</p><figure class=\"table\"><table><thead><tr><th>Relation</th><th>Trigger condition</th><th>Origin entity (see below)</th></tr></thead><tbody><tr><td><code>runOnNoteCreation</code></td><td>executes when note is created on backend. Use this relation if you want to run the script for all notes created under a specific subtree. In that case, create it on the subtree root note and make it inheritable. A new note created within the subtree (any depth) will trigger the script.</td><td>The <code>BNote</code> that got created.</td></tr><tr><td><code>runOnChildNoteCreation</code></td><td>executes when new note is created under the note where this relation is defined</td><td>The <code>BNote</code> of the child that got created.</td></tr><tr><td><code>runOnNoteTitleChange</code></td><td>executes when note title is changed (includes note creation as well)</td><td>The <code>BNote</code> of the note whose title got changed.</td></tr><tr><td><code>runOnNoteContentChange</code></td><td>executes when note content is changed (includes note creation as well).</td><td>The <code>BNote</code> of the note whose content got changed.</td></tr><tr><td><code>runOnNoteChange</code></td><td>executes when note is changed (includes note creation as well). Does not include content changes</td><td>The <code>BNote</code> of the note that got changed.</td></tr><tr><td><code>runOnNoteDeletion</code></td><td>executes when note is being deleted</td><td>The <code>BNote</code> of the note that got (soft) deleted.</td></tr><tr><td><code>runOnBranchCreation</code></td><td>executes when a branch is created. Branch is a link between parent note and child note and is created e.g. when cloning or moving note.</td><td>The <code>BBranch</code> that got created.</td></tr><tr><td><code>runOnBranchChange</code></td><td>executes when a branch is updated. (since v0.62)</td><td>The <code>BBranch</code> that got changed.</td></tr><tr><td><code>runOnBranchDeletion</code></td><td>executes when a branch is deleted. Branch is a link between parent note and child note and is deleted e.g. when moving note (old branch/link is deleted).</td><td>The <code>BBranch</code> that got (soft) deleted.</td></tr><tr><td><code>runOnAttributeCreation</code></td><td>executes when new attribute is created for the note which defines this relation</td><td>The <code>BAttribute</code> that got created.</td></tr><tr><td><code>runOnAttributeChange</code></td><td>executes when the attribute is changed of a note which defines this relation. This is triggered also when the attribute is deleted</td><td>The <code>BAttribute</code> that got changed.</td></tr></tbody></table></figure><h2>Origin entity</h2><p>When a script is run by an event such as the ones described above, <code>api.originEntity</code> will get populated with the note, branch or attribute that triggered the change.</p><p>For example, here's a script with <code>~runOnAttributeChange</code> which automatically changes the color of a note based on the value of the <code>mycategory</code> label:</p><pre><code class=\"language-text-javascript\">const attr = api.originEntity;\nif (attr.name !== \"mycategory\") return;\nconst note = api.getNote(attr.noteId);\nif (attr.value === \"Health\") {\n note.setLabel(\"color\", \"green\");\n} else {\n note.removeLabel(\"color\");\n}</code></pre><h2>Safe mode</h2><p>While <a href=\"#root/_help_64ZTlUPgEPtW\">safe mode</a> is active, scripts with events won't trigger.</p>","_help_hA834UaHhSNn": "<p>For both <a class=\"reference-link\" href=\"#root/_help_HcABDtFCkbFN\">Render Note</a> and more complicated scripts, it's generally useful to split the code into multiple <a class=\"reference-link\" href=\"#root/_help_6f9hih2hXXZk\">Code</a> notes.</p><p>When a script is run, the sub-children of the script being run (or the <a class=\"reference-link\" href=\"#root/_help_HcABDtFCkbFN\">Render Note</a>) are checked for children. If the children are Code notes of the corresponding type (front-end or backend) as the code being run, they will be evaluated as well.</p><p>The collection of a script and its child notes is called a <em>bundle</em>. A child note inside a bundle is called a <em>module</em>.</p><p>As a basic example of dependencies, consider the following note structure:</p><ul><li><p><em>Script with dependency</em></p><pre><code class=\"language-text-javascript\">api.log(MyMath.sum(2, 2));</code></pre><ul><li><p><em>MyMath</em></p><pre><code class=\"language-text-javascript\">module.exports = {\n sum(a, b) {\n return a + b;\n }\n};</code></pre></li></ul></li></ul><p>When <em>Script with dependency</em> is run, it will detect <em>MyMath</em> as a submodule and provide the result of its <code>module.exports</code> object into a global object with the same name as the note.</p><aside class=\"admonition note\"><p>If the note contains spaces or special characters, they will be stripped. For example <code>My Nice Note!</code> becomes <code>MyNiceNote</code>.</p></aside><h2>Alternative syntax</h2><p>Instead of providing an object to <code>module.exports</code>, it's also possible to add fields individually:</p><pre><code class=\"language-text-javascript\">module.exports.sum = (a, b) => a + b;\nmodule.exports.subtract = (a, b) => a - b;</code></pre><h2>Ignoring a code script from a bundle</h2><p>To ignore a script from being included in a bundle (e.g. if it's unrelated to the parent script note), apply the <code>#disableInclusion</code> label.</p><h2>Sharing a module across multiple bundles</h2><p>Modules can be reused across multiple scripts by simply cloning the shared module between two modules (see <a class=\"reference-link\" href=\"#root/_help_IakOLONlIfGI\">Cloning Notes</a>).</p><p>Optionally, a separate note can be used to contain all the different reusable modules for an easy way to discover them.</p>",- "_help_GLks18SNjxmC": "<p>For <a href=\"#root/_help_CdNpE2pqjmI6\">script code notes</a>, Trilium offers an API that gives them access to various features of the application.</p><p>There are two APIs:</p><ul><li>One for the front-end scripts: <a class=\"reference-link\" href=\"#root/_help_Q2z6av6JZVWm\">Frontend API</a></li><li>One for the back-end scripts: <a class=\"reference-link\" href=\"{{helpAssets}}/User%20Guide/Scripting/Script%20API/Backend%20API.dat\">Backend API</a></li></ul><p>In both cases, the API resides in a global variable, <code>api</code>, that can be used anywhere in the script.</p><p>For example, to display a message to the user the following front-end script can be used:</p><pre><code class=\"language-text-x-trilium-auto\">api.showMessage(\"Hello world.\");</code></pre><aside class=\"admonition note\"><p><strong>Note</strong><br>The Script API is currently experimental and may undergo changes in future updates.</p></aside>",+ "_help_GLks18SNjxmC": "<p>For <a href=\"#root/_help_CdNpE2pqjmI6\">script code notes</a>, Trilium offers an API that gives them access to various features of the application.</p><p>There are two APIs:</p><ul><li>One for the front-end scripts: <a class=\"reference-link\" href=\"#root/_help_Q2z6av6JZVWm\">Frontend API</a></li><li>One for the back-end scripts: <a class=\"reference-link\" href=\"#root/_help_MEtfsqa5VwNi\">Backend API</a></li></ul><p>In both cases, the API resides in a global variable, <code>api</code>, that can be used anywhere in the script.</p><p>For example, to display a message to the user the following front-end script can be used:</p><pre><code class=\"language-text-x-trilium-auto\">api.showMessage(\"Hello world.\");</code></pre><aside class=\"admonition note\"><p><strong>Note</strong><br>The Script API is currently experimental and may undergo changes in future updates.</p></aside>",+ "_help_MEtfsqa5VwNi": "<h2><code>BackendApi</code></h2><p>The <code>api</code> global available inside <strong>backend</strong> script notes (<code>application/javascript;env=backend</code>). Runs server-side: no DOM, no jQuery.</p><figure class=\"table\"><table><thead><tr><th>Member</th><th>Description</th></tr></thead><tbody><tr><td><code>startNote</code><br><em>optional</em></td><td><p><code>ScriptBNote | null</code><br>Note where the script execution started — the entry point of the current script bundle (in C terms, the file containing <code>main()</code>). When a script is spread across multiple code notes (descendant code notes loaded as modules via <code>require()</code>), every note in the bundle shares the same <code>startNote</code>, while <code>currentNote</code> differs per note. Messages from <code>api.log()</code> are grouped under this note. When a frontend script calls <code>api.runOnBackend()</code>, the frontend's <code>startNote</code> is preserved here; since that note may not be resolvable on the backend, this can be null.</p></td></tr><tr><td><code>currentNote</code></td><td><p><code>ScriptBNote</code><br>Note containing the source code that is currently executing (in C terms, <code>__FILE__</code>). Equal to <code>startNote</code> unless execution has moved into a descendant module note loaded via <code>require()</code>. Don't confuse this with the concept of the active note in the UI.</p></td></tr><tr><td><code>originEntity</code><br><em>optional</em></td><td><p><code>unknown</code><br>Entity whose event triggered this execution; <code>undefined</code> when the run was not event-driven (e.g. started manually via \"Execute script\" or <code>note.executeScript()</code>). What it holds depends on the trigger: - <code>~runOnNoteCreation</code>, <code>~runOnNoteChange</code>, <code>~runOnNoteTitleChange</code>, <code>~runOnNoteContentChange</code> — the affected note; - <code>~runOnChildNoteCreation</code> — the newly created child note; - <code>~runOnAttributeCreation</code>, <code>~runOnAttributeChange</code> — the attribute; - <code>~runOnBranchCreation</code>, <code>~runOnBranchChange</code>, <code>~runOnBranchDeletion</code> — the branch; - scheduled scripts (<code>#run=backendStartup</code> / <code>#run=hourly</code> / <code>#run=daily</code>) — the script note itself; - search scripts (<code>~searchScript</code>) — the search note.</p></td></tr><tr><td><code>req</code></td><td><p><code>ScriptRequest</code><br>Express request object. Available only inside custom request handlers — a note with the <code>#customRequestHandler</code> label, invoked via a <code>/custom/...</code> URL. The editor surfaces this member only for such notes (where the request always supplies it), so it is non-optional rather than forcing a null-check.</p></td></tr><tr><td><code>res</code></td><td><p><code>ScriptResponse</code><br>Express response object — write the HTTP response here, e.g. <code>api.res.status(200).json({ ok: true })</code>. Available only inside custom request handlers (where it is always supplied), so it is non-optional.</p></td></tr><tr><td><code>pathParams</code></td><td><p><code>string[]</code><br>The capture groups from the <code>#customRequestHandler</code> regex that matched this request's URL, in order. Available only inside custom request handlers.</p></td></tr><tr><td><code>dayjs</code></td><td><p><code>ScriptDayjs</code><br>day.js library for date manipulation. See <code>https://day.js.org</code> for documentation</p></td></tr><tr><td><code>xml2js</code></td><td><p><code>unknown</code><br>xml2js library for XML parsing. See <code>https://github.com/Leonidas-from-XIV/node-xml2js</code> for documentation</p></td></tr><tr><td><code>htmlParser</code></td><td><p><code>unknown</code><br>node-html-parser library for HTML parsing. See <code>https://github.com/taoqf/node-fast-html-parser</code> for documentation.</p></td></tr><tr><td><code>getInstanceName</code></td><td><pre><code class=\"language-application-typescript\">getInstanceName(): string | null</code></pre><p>Instance name identifies particular Trilium instance. It can be useful for scripts if some action needs to happen on only one specific instance.</p></td></tr><tr><td><code>getNote</code></td><td><pre><code class=\"language-application-typescript\">getNote(noteId: string): ScriptBNote | null</code></pre><p>Returns a note by its ID, or null.</p></td></tr><tr><td><code>getBranch</code></td><td><pre><code class=\"language-application-typescript\">getBranch(branchId: string): ScriptBBranch | null</code></pre><p>Returns a branch by its ID, or null.</p></td></tr><tr><td><code>getAttribute</code></td><td><pre><code class=\"language-application-typescript\">getAttribute(attributeId: string): ScriptAttribute | null</code></pre><p>Returns an attribute by its ID, or null.</p></td></tr><tr><td><code>getAttachment</code></td><td><pre><code class=\"language-application-typescript\">getAttachment(attachmentId: string): unknown</code></pre><p>Returns an attachment by its ID, or null.</p></td></tr><tr><td><code>getRevision</code></td><td><pre><code class=\"language-application-typescript\">getRevision(revisionId: string): unknown</code></pre><p>Returns a revision by its ID, or null.</p></td></tr><tr><td><code>getEtapiToken</code></td><td><pre><code class=\"language-application-typescript\">getEtapiToken(etapiTokenId: string): unknown</code></pre><p>Returns an ETAPI token by its ID, or null.</p></td></tr><tr><td><code>getEtapiTokens</code></td><td><pre><code class=\"language-application-typescript\">getEtapiTokens(): unknown[]</code></pre><p>Returns all ETAPI tokens.</p></td></tr><tr><td><code>getOption</code></td><td><pre><code class=\"language-application-typescript\">getOption(optionName: string): unknown</code></pre><p>Returns an option by name, or null.</p></td></tr><tr><td><code>getOptions</code></td><td><pre><code class=\"language-application-typescript\">getOptions(): unknown[]</code></pre><p>Returns all options.</p></td></tr><tr><td><code>searchForNotes</code></td><td><pre><code class=\"language-application-typescript\">searchForNotes(query: string, searchParams?: Record<string, unknown>): ScriptBNote[]</code></pre><p>This is a powerful search method - you can search by attributes and their values, e.g.: \"#dateModified =* MONTH AND #log\". See <code>https://triliumnext.github.io/Docs/Wiki/search.html</code> for full documentation for all options</p></td></tr><tr><td><code>searchForNote</code></td><td><pre><code class=\"language-application-typescript\">searchForNote(query: string, searchParams?: Record<string, unknown>): ScriptBNote | null</code></pre><p>This is a powerful search method - you can search by attributes and their values, e.g.: \"#dateModified =* MONTH AND #log\". See <code>https://triliumnext.github.io/Docs/Wiki/search.html</code> for full documentation for all options</p></td></tr><tr><td><code>getNotesWithLabel</code></td><td><pre><code class=\"language-application-typescript\">getNotesWithLabel(name: string, value?: string): ScriptBNote[]</code></pre><p>Retrieves notes with given label name & value</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>name</code></td><td><code>string</code><br>attribute name</td></tr><tr><td><code>value</code><br><em>optional</em></td><td><code>string</code><br>attribute value</td></tr></tbody></table></figure></td></tr><tr><td><code>getNoteWithLabel</code></td><td><pre><code class=\"language-application-typescript\">getNoteWithLabel(name: string, value?: string): ScriptBNote | null</code></pre><p>Retrieves first note with given label name & value</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>name</code></td><td><code>string</code><br>attribute name</td></tr><tr><td><code>value</code><br><em>optional</em></td><td><code>string</code><br>attribute value</td></tr></tbody></table></figure></td></tr><tr><td><code>ensureNoteIsPresentInParent</code></td><td><pre><code class=\"language-application-typescript\">ensureNoteIsPresentInParent(noteId: string, parentNoteId: string, prefix?: string): { branch: ScriptBBranch | null }</code></pre><p>If there's no branch between note and parent note, create one. Otherwise, do nothing. Returns the new or existing branch.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>noteId</code></td><td><code>string</code></td></tr><tr><td><code>parentNoteId</code></td><td><code>string</code></td></tr><tr><td><code>prefix</code><br><em>optional</em></td><td><code>string</code><br>if branch is created between note and parent note, set this prefix</td></tr></tbody></table></figure></td></tr><tr><td><code>ensureNoteIsAbsentFromParent</code></td><td><pre><code class=\"language-application-typescript\">ensureNoteIsAbsentFromParent(noteId: string, parentNoteId: string): void</code></pre><p>If there's a branch between note and parent note, remove it. Otherwise, do nothing.</p></td></tr><tr><td><code>toggleNoteInParent</code></td><td><pre><code class=\"language-application-typescript\">toggleNoteInParent(present: boolean, noteId: string, parentNoteId: string, prefix?: string): void</code></pre><p>Based on the value, either create or remove branch between note and parent note.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>present</code></td><td><code>boolean</code><br>true if we want the branch to exist, false if we want it gone</td></tr><tr><td><code>noteId</code></td><td><code>string</code></td></tr><tr><td><code>parentNoteId</code></td><td><code>string</code></td></tr><tr><td><code>prefix</code><br><em>optional</em></td><td><code>string</code><br>if branch is created between note and parent note, set this prefix</td></tr></tbody></table></figure></td></tr><tr><td><code>createTextNote</code></td><td><pre><code class=\"language-application-typescript\">createTextNote(parentNoteId: string, title: string, content: string): ScriptNoteAndBranch</code></pre><p>Create text note. See also createNewNote() for more options.</p></td></tr><tr><td><code>createDataNote</code></td><td><pre><code class=\"language-application-typescript\">createDataNote(parentNoteId: string, title: string, content: object): ScriptNoteAndBranch</code></pre><p>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.</p></td></tr><tr><td><code>createNewNote</code></td><td><pre><code class=\"language-application-typescript\">createNewNote(params: { parentNoteId: string; title: string; content: string | Uint8Array<ArrayBufferLike>; type: string; mime?: string; [key: string]: unknown }): ScriptNoteAndBranch</code></pre><p><strong>Returns</strong> <code>ScriptNoteAndBranch</code>: object contains newly created entities note and branch</p></td></tr><tr><td><code>logMessages</code></td><td><p><code>Record<string, string[]></code><br>Per-note log message buffers shown in the UI log pane.</p></td></tr><tr><td><code>logSpacedUpdates</code></td><td><p><code>Record<string, unknown></code><br>Per-note spaced-update handlers for the log pane.</p></td></tr><tr><td><code>log</code></td><td><pre><code class=\"language-application-typescript\">log(...args: unknown[]): void</code></pre><p>Log given message to trilium logs and log pane in UI. Accepts multiple arguments which are joined with spaces, similar to <code>console.log</code>.</p></td></tr><tr><td><code>getRootCalendarNote</code></td><td><pre><code class=\"language-application-typescript\">getRootCalendarNote(): ScriptBNote | null</code></pre><p>Returns root note of the calendar.</p></td></tr><tr><td><code>getDayNote</code></td><td><pre><code class=\"language-application-typescript\">getDayNote(date: string, rootNote?: ScriptBNote): ScriptBNote | null</code></pre><p>Returns day note for given date. If such note doesn't exist, it is created.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>date</code></td><td><code>string</code><br>in YYYY-MM-DD format</td></tr><tr><td><code>rootNote</code><br><em>optional</em></td><td><code>ScriptBNote</code><br>specify calendar root note, normally leave empty to use the default calendar</td></tr></tbody></table></figure></td></tr><tr><td><code>getTodayNote</code></td><td><pre><code class=\"language-application-typescript\">getTodayNote(rootNote?: ScriptBNote): ScriptBNote | null</code></pre><p>Returns today's day note. If such note doesn't exist, it is created.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>rootNote</code><br><em>optional</em></td><td><code>ScriptBNote</code><br>specify calendar root note, normally leave empty to use the default calendar</td></tr></tbody></table></figure></td></tr><tr><td><code>getWeekFirstDayNote</code></td><td><pre><code class=\"language-application-typescript\">getWeekFirstDayNote(date: string, rootNote?: ScriptBNote): ScriptBNote | null</code></pre><p>Returns note for the first date of the week of the given date.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>date</code></td><td><code>string</code><br>in YYYY-MM-DD format</td></tr><tr><td><code>rootNote</code><br><em>optional</em></td><td><code>ScriptBNote</code><br>specify calendar root note, normally leave empty to use the default calendar</td></tr></tbody></table></figure></td></tr><tr><td><code>getWeekNote</code></td><td><pre><code class=\"language-application-typescript\">getWeekNote(date: string, rootNote?: ScriptBNote): ScriptBNote | null</code></pre><p>Returns week note for given date. If such a note doesn't exist, it is created.</p><p>If the calendar does not support week notes, this method will return `null`.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>date</code></td><td><code>string</code><br>in YYYY-MM-DD format</td></tr><tr><td><code>rootNote</code><br><em>optional</em></td><td><code>ScriptBNote</code><br>specify calendar root note, normally leave empty to use the default calendar</td></tr></tbody></table></figure><p><strong>Returns</strong> <code>ScriptBNote | null</code>: an existing or newly created week note, or <code>null</code> if the calendar does not support week notes.</p></td></tr><tr><td><code>getMonthNote</code></td><td><pre><code class=\"language-application-typescript\">getMonthNote(date: string, rootNote?: ScriptBNote): ScriptBNote | null</code></pre><p>Returns month note for given date. If such a note doesn't exist, it is created.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>date</code></td><td><code>string</code><br>in YYYY-MM format</td></tr><tr><td><code>rootNote</code><br><em>optional</em></td><td><code>ScriptBNote</code><br>specify calendar root note, normally leave empty to use the default calendar</td></tr></tbody></table></figure></td></tr><tr><td><code>getQuarterNote</code></td><td><pre><code class=\"language-application-typescript\">getQuarterNote(date: string, rootNote?: ScriptBNote): ScriptBNote | null</code></pre><p>Returns quarter note for given date. If such a note doesn't exist, it is created.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>date</code></td><td><code>string</code><br>in YYYY-MM format</td></tr><tr><td><code>rootNote</code><br><em>optional</em></td><td><code>ScriptBNote</code><br>specify calendar root note, normally leave empty to use the default calendar</td></tr></tbody></table></figure></td></tr><tr><td><code>getYearNote</code></td><td><pre><code class=\"language-application-typescript\">getYearNote(year: string, rootNote?: ScriptBNote): ScriptBNote | null</code></pre><p>Returns year note for given year. If such a note doesn't exist, it is created.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>year</code></td><td><code>string</code><br>in YYYY format</td></tr><tr><td><code>rootNote</code><br><em>optional</em></td><td><code>ScriptBNote</code><br>specify calendar root note, normally leave empty to use the default calendar</td></tr></tbody></table></figure></td></tr><tr><td><code>sortNotes</code></td><td><pre><code class=\"language-application-typescript\">sortNotes(parentNoteId: string, sortConfig: { sortBy?: string; reverse?: boolean; foldersFirst?: boolean }): void</code></pre><p>Sort child notes of a given note. <code>sortBy</code> takes the <code>#sorted</code> grammar — comma-separated levels of <code>title</code>, <code>dateCreated</code>, <code>dateModified</code> or a label name, each optionally followed by <code>asc</code> or <code>desc</code> (<code>priority desc, dueDate</code>); <code>reverse</code> is the direction of the levels without their own, of the folders grouping and of ties.</p></td></tr><tr><td><code>setNoteToParent</code></td><td><pre><code class=\"language-application-typescript\">setNoteToParent(noteId: string, prefix: string, parentNoteId: string | null): void</code></pre><p>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).</p><p>This method looks similar to toggleNoteInParent() but differs because we're looking up branch by prefix.</p><aside class=\"admonition warning\"><p>Deprecated. this method is pretty confusing and serves specialized purpose only</p></aside></td></tr><tr><td><code>transactional</code></td><td><pre><code class=\"language-application-typescript\">transactional(func: () => T): T</code></pre><p>This functions wraps code which is supposed to be running in transaction. If transaction already exists, then we'll use that transaction.</p><p><strong>Returns</strong> <code>T</code>: result of func callback</p></td></tr><tr><td><code>randomString</code></td><td><pre><code class=\"language-application-typescript\">randomString(length: number): string</code></pre><p>Return randomly generated string of given length. This random string generation is NOT cryptographically secure.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>length</code></td><td><code>number</code><br>of the string</td></tr></tbody></table></figure><p><strong>Returns</strong> <code>string</code>: random string</p></td></tr><tr><td><code>escapeHtml</code></td><td><pre><code class=\"language-application-typescript\">escapeHtml(str: string): string</code></pre><p><strong>Returns</strong> <code>string</code>: escaped string</p></td></tr><tr><td><code>unescapeHtml</code></td><td><pre><code class=\"language-application-typescript\">unescapeHtml(str: string): string</code></pre><p><strong>Returns</strong> <code>string</code>: unescaped string</p></td></tr><tr><td><code>htmlToMarkdown</code></td><td><pre><code class=\"language-application-typescript\">htmlToMarkdown(html: string): string</code></pre><p>Converts the given HTML string to Markdown.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>html</code></td><td><code>string</code><br>HTML content to convert</td></tr></tbody></table></figure><p><strong>Returns</strong> <code>string</code>: Markdown representation of the input HTML</p></td></tr><tr><td><code>markdownToHtml</code></td><td><pre><code class=\"language-application-typescript\">markdownToHtml(markdown: string): string</code></pre><p>Converts the given Markdown string to HTML.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>markdown</code></td><td><code>string</code><br>Markdown content to convert</td></tr></tbody></table></figure><p><strong>Returns</strong> <code>string</code>: HTML representation of the input Markdown</p></td></tr><tr><td><code>sql</code></td><td><p><code>unknown</code><br>sql</p></td></tr><tr><td><code>getAppInfo</code></td><td><pre><code class=\"language-application-typescript\">getAppInfo(): unknown</code></pre><p>Application info (version, build date, etc.).</p></td></tr><tr><td><code>createOrUpdateLauncher</code></td><td><pre><code class=\"language-application-typescript\">createOrUpdateLauncher(opts: { id: string; type: \"note\" | \"script\" | \"customWidget\"; title: string; isVisible: boolean; icon: string; keyboardShortcut: string; targetNoteId?: string; scriptNoteId?: string; widgetNoteId?: string }): { note: ScriptBNote }</code></pre><p>Creates a new launcher to the launchbar. If the launcher (id) already exists, it will be updated.</p></td></tr><tr><td><code>exportSubtreeToZipFile</code></td><td><pre><code class=\"language-application-typescript\">exportSubtreeToZipFile(noteId: string, format: \"markdown\" | \"html\", zipFilePath: string): Promise<void></code></pre><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>noteId</code></td><td><code>string</code></td></tr><tr><td><code>format</code></td><td><code>\"markdown\" | \"html\"</code><br>either 'html' or 'markdown'</td></tr><tr><td><code>zipFilePath</code></td><td><code>string</code></td></tr></tbody></table></figure></td></tr><tr><td><code>runOnFrontend</code></td><td><pre><code class=\"language-application-typescript\">runOnFrontend(script: string | () => void, params?: unknown[]): void</code></pre><p>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.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>script</code></td><td><code>string | () => void</code><br>script to be executed on the frontend</td></tr><tr><td><code>params</code><br><em>optional</em></td><td><code>unknown[]</code><br>list of parameters to the anonymous function to be sent to frontend</td></tr></tbody></table></figure><p><strong>Returns</strong> <code>void</code>: no return value is provided.</p></td></tr><tr><td><code>runOutsideOfSync</code></td><td><pre><code class=\"language-application-typescript\">runOutsideOfSync(callback: () => void): Promise<void></code></pre><p>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.</p><p>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(...)</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>callback</code></td><td><code>() => void</code><br>function to be executed while sync process is not running</td></tr></tbody></table></figure><p><strong>Returns</strong> <code>Promise<void></code>: resolves once the callback is finished (callback is awaited)</p></td></tr><tr><td><code>backupNow</code></td><td><pre><code class=\"language-application-typescript\">backupNow(backupName: string): Promise<string></code></pre><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>backupName</code></td><td><code>string</code><br>If the backupName is e.g. \"now\", then the backup will be written to \"backup-now.db\" file</td></tr></tbody></table></figure><p><strong>Returns</strong> <code>Promise<string></code>: resolves once the backup is finished</p></td></tr><tr><td><code>duplicateSubtree</code></td><td><pre><code class=\"language-application-typescript\">duplicateSubtree(origNoteId: string, newParentNoteId: string): ScriptNoteAndBranch</code></pre><p>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.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>origNoteId</code></td><td><code>string</code><br>the noteId for the original note to be duplicated</td></tr><tr><td><code>newParentNoteId</code></td><td><code>string</code><br>the noteId for the parent note where the duplication is to be placed.</td></tr></tbody></table></figure><p><strong>Returns</strong> <code>ScriptNoteAndBranch</code>: the note and the branch of the newly created note.</p></td></tr></tbody></table></figure><h2><code>ScriptBNote</code></h2><p>A note as seen by backend scripts (subset of trilium-core's <code>BNote</code>).</p><figure class=\"table\"><table><thead><tr><th>Member</th><th>Description</th></tr></thead><tbody><tr><td><code>noteId</code></td><td><p><code>string</code></p></td></tr><tr><td><code>title</code></td><td><p><code>string</code></p></td></tr><tr><td><code>type</code></td><td><p><code>string</code></p></td></tr><tr><td><code>mime</code></td><td><p><code>string</code></p></td></tr><tr><td><code>isProtected</code></td><td><p><code>boolean</code></p></td></tr><tr><td><code>isArchived</code></td><td><p><code>boolean</code></p></td></tr><tr><td><code>isDeleted</code></td><td><p><code>boolean</code></p></td></tr><tr><td><code>shareId</code></td><td><p><code>string</code><br>Share root ID this note is published under, if any.</p></td></tr><tr><td><code>blobId</code></td><td><p><code>string</code></p></td></tr><tr><td><code>dateCreated</code></td><td><p><code>string</code></p></td></tr><tr><td><code>dateModified</code></td><td><p><code>string</code></p></td></tr><tr><td><code>utcDateCreated</code></td><td><p><code>string</code></p></td></tr><tr><td><code>utcDateModified</code></td><td><p><code>string</code></p></td></tr><tr><td><code>getContent</code></td><td><pre><code class=\"language-application-typescript\">getContent(): string | Uint8Array<ArrayBufferLike></code></pre></td></tr><tr><td><code>setContent</code></td><td><pre><code class=\"language-application-typescript\">setContent(content: string | Uint8Array<ArrayBufferLike>, opts?: { forceFrontendReload?: boolean }): void</code></pre></td></tr><tr><td><code>getJsonContent</code></td><td><pre><code class=\"language-application-typescript\">getJsonContent(): T | null</code></pre></td></tr><tr><td><code>getJsonContentSafely</code></td><td><pre><code class=\"language-application-typescript\">getJsonContentSafely(): unknown</code></pre></td></tr><tr><td><code>setJsonContent</code></td><td><pre><code class=\"language-application-typescript\">setJsonContent(content: unknown): void</code></pre></td></tr><tr><td><code>hasStringContent</code></td><td><pre><code class=\"language-application-typescript\">hasStringContent(): boolean</code></pre></td></tr><tr><td><code>getFileName</code></td><td><pre><code class=\"language-application-typescript\">getFileName(): string</code></pre></td></tr><tr><td><code>getFlatText</code></td><td><pre><code class=\"language-application-typescript\">getFlatText(): string</code></pre></td></tr><tr><td><code>getPojo</code></td><td><pre><code class=\"language-application-typescript\">getPojo(): Record<string, unknown></code></pre><p>Plain serialisable representation of the note (the real return type is <code>NotePojo</code>).</p></td></tr><tr><td><code>getTitleOrProtected</code></td><td><pre><code class=\"language-application-typescript\">getTitleOrProtected(): string</code></pre></td></tr><tr><td><code>getIcon</code></td><td><pre><code class=\"language-application-typescript\">getIcon(): string</code></pre></td></tr><tr><td><code>parents</code></td><td><p><code>ScriptBNote[]</code></p></td></tr><tr><td><code>children</code></td><td><p><code>ScriptBNote[]</code></p></td></tr><tr><td><code>parentBranches</code></td><td><p><code>ScriptBBranch[]</code></p></td></tr><tr><td><code>parentCount</code></td><td><p><code>number</code></p></td></tr><tr><td><code>childrenCount</code></td><td><p><code>number</code></p></td></tr><tr><td><code>getParentNotes</code></td><td><pre><code class=\"language-application-typescript\">getParentNotes(): ScriptBNote[]</code></pre></td></tr><tr><td><code>getChildNotes</code></td><td><pre><code class=\"language-application-typescript\">getChildNotes(): ScriptBNote[]</code></pre></td></tr><tr><td><code>getVisibleChildNotes</code></td><td><pre><code class=\"language-application-typescript\">getVisibleChildNotes(): ScriptBNote[]</code></pre></td></tr><tr><td><code>getParentBranches</code></td><td><pre><code class=\"language-application-typescript\">getParentBranches(): ScriptBBranch[]</code></pre></td></tr><tr><td><code>getChildBranches</code></td><td><pre><code class=\"language-application-typescript\">getChildBranches(): ScriptBBranch[]</code></pre></td></tr><tr><td><code>getVisibleChildBranches</code></td><td><pre><code class=\"language-application-typescript\">getVisibleChildBranches(): ScriptBBranch[]</code></pre></td></tr><tr><td><code>getStrongParentBranches</code></td><td><pre><code class=\"language-application-typescript\">getStrongParentBranches(): ScriptBBranch[]</code></pre></td></tr><tr><td><code>getFilteredChildBranches</code></td><td><pre><code class=\"language-application-typescript\">getFilteredChildBranches(): ScriptBBranch[]</code></pre></td></tr><tr><td><code>getBranches</code></td><td><pre><code class=\"language-application-typescript\">getBranches(): ScriptBBranch[]</code></pre></td></tr><tr><td><code>hasChildren</code></td><td><pre><code class=\"language-application-typescript\">hasChildren(): boolean</code></pre></td></tr><tr><td><code>hasVisibleChildren</code></td><td><pre><code class=\"language-application-typescript\">hasVisibleChildren(): boolean</code></pre></td></tr><tr><td><code>getAncestors</code></td><td><pre><code class=\"language-application-typescript\">getAncestors(): ScriptBNote[]</code></pre></td></tr><tr><td><code>getAncestorNoteIds</code></td><td><pre><code class=\"language-application-typescript\">getAncestorNoteIds(): string[]</code></pre></td></tr><tr><td><code>getDescendantNoteIds</code></td><td><pre><code class=\"language-application-typescript\">getDescendantNoteIds(): string[]</code></pre></td></tr><tr><td><code>getDistanceToAncestor</code></td><td><pre><code class=\"language-application-typescript\">getDistanceToAncestor(ancestorNoteId: string): number</code></pre></td></tr><tr><td><code>hasAncestor</code></td><td><pre><code class=\"language-application-typescript\">hasAncestor(ancestorNoteId: string): boolean</code></pre></td></tr><tr><td><code>isDescendantOfNote</code></td><td><pre><code class=\"language-application-typescript\">isDescendantOfNote(ancestorNoteId: string): boolean</code></pre></td></tr><tr><td><code>isRoot</code></td><td><pre><code class=\"language-application-typescript\">isRoot(): boolean</code></pre></td></tr><tr><td><code>getSubtree</code></td><td><pre><code class=\"language-application-typescript\">getSubtree(opts?: ScriptSubtreeOpts): { notes: ScriptBNote[]; relationships: ScriptSubtreeRelationship[] }</code></pre></td></tr><tr><td><code>getSubtreeNoteIds</code></td><td><pre><code class=\"language-application-typescript\">getSubtreeNoteIds(opts?: ScriptSubtreeOpts): string[]</code></pre></td></tr><tr><td><code>getSubtreeNotesIncludingTemplated</code></td><td><pre><code class=\"language-application-typescript\">getSubtreeNotesIncludingTemplated(): ScriptBNote[]</code></pre></td></tr><tr><td><code>getInheritingNotes</code></td><td><pre><code class=\"language-application-typescript\">getInheritingNotes(): ScriptBNote[]</code></pre></td></tr><tr><td><code>getAllNotePaths</code></td><td><pre><code class=\"language-application-typescript\">getAllNotePaths(): string[][]</code></pre></td></tr><tr><td><code>getBestNotePath</code></td><td><pre><code class=\"language-application-typescript\">getBestNotePath(hoistedNoteId?: string): string[]</code></pre></td></tr><tr><td><code>getBestNotePathString</code></td><td><pre><code class=\"language-application-typescript\">getBestNotePathString(hoistedNoteId?: string): string</code></pre></td></tr><tr><td><code>getSortedNotePathRecords</code></td><td><pre><code class=\"language-application-typescript\">getSortedNotePathRecords(hoistedNoteId?: string): ScriptNotePathRecord[]</code></pre></td></tr><tr><td><code>areAllNotePathsArchived</code></td><td><pre><code class=\"language-application-typescript\">areAllNotePathsArchived(): boolean</code></pre></td></tr><tr><td><code>ownedAttributes</code></td><td><p><code>ScriptAttribute[]</code></p></td></tr><tr><td><code>targetRelations</code></td><td><p><code>ScriptAttribute[]</code></p></td></tr><tr><td><code>attributeCount</code></td><td><p><code>number</code></p></td></tr><tr><td><code>ownedAttributeCount</code></td><td><p><code>number</code></p></td></tr><tr><td><code>labelCount</code></td><td><p><code>number</code></p></td></tr><tr><td><code>ownedLabelCount</code></td><td><p><code>number</code></p></td></tr><tr><td><code>relationCount</code></td><td><p><code>number</code></p></td></tr><tr><td><code>relationCountIncludingLinks</code></td><td><p><code>number</code></p></td></tr><tr><td><code>ownedRelationCount</code></td><td><p><code>number</code></p></td></tr><tr><td><code>ownedRelationCountIncludingLinks</code></td><td><p><code>number</code></p></td></tr><tr><td><code>targetRelationCount</code></td><td><p><code>number</code></p></td></tr><tr><td><code>targetRelationCountIncludingLinks</code></td><td><p><code>number</code></p></td></tr><tr><td><code>getAttributes</code></td><td><pre><code class=\"language-application-typescript\">getAttributes(type?: string, name?: string): ScriptAttribute[]</code></pre></td></tr><tr><td><code>getOwnedAttributes</code></td><td><pre><code class=\"language-application-typescript\">getOwnedAttributes(type?: string, name?: string): ScriptAttribute[]</code></pre></td></tr><tr><td><code>getAttribute</code></td><td><pre><code class=\"language-application-typescript\">getAttribute(type: string, name: string): ScriptAttribute | null</code></pre></td></tr><tr><td><code>getOwnedAttribute</code></td><td><pre><code class=\"language-application-typescript\">getOwnedAttribute(type: string, name: string, value?: string | null): ScriptAttribute | null</code></pre></td></tr><tr><td><code>getAttributeValue</code></td><td><pre><code class=\"language-application-typescript\">getAttributeValue(type: string, name: string): string | null</code></pre></td></tr><tr><td><code>getOwnedAttributeValue</code></td><td><pre><code class=\"language-application-typescript\">getOwnedAttributeValue(type: string, name: string): string | null</code></pre></td></tr><tr><td><code>getAttributeById</code></td><td><pre><code class=\"language-application-typescript\">getAttributeById(attributeId: string): ScriptAttribute | undefined</code></pre></td></tr><tr><td><code>getAttributeCaseInsensitive</code></td><td><pre><code class=\"language-application-typescript\">getAttributeCaseInsensitive(type: string, name: string, value?: string | null): ScriptAttribute | undefined</code></pre></td></tr><tr><td><code>hasAttribute</code></td><td><pre><code class=\"language-application-typescript\">hasAttribute(type: string, name: string): boolean</code></pre></td></tr><tr><td><code>hasOwnedAttribute</code></td><td><pre><code class=\"language-application-typescript\">hasOwnedAttribute(type: string, name: string, value?: string): boolean</code></pre></td></tr><tr><td><code>getLabelDefinitions</code></td><td><pre><code class=\"language-application-typescript\">getLabelDefinitions(): ScriptAttribute[]</code></pre></td></tr><tr><td><code>getRelationDefinitions</code></td><td><pre><code class=\"language-application-typescript\">getRelationDefinitions(): ScriptAttribute[]</code></pre></td></tr><tr><td><code>getTargetRelations</code></td><td><pre><code class=\"language-application-typescript\">getTargetRelations(): ScriptAttribute[]</code></pre></td></tr><tr><td><code>getLabel</code></td><td><pre><code class=\"language-application-typescript\">getLabel(name: string): ScriptAttribute | null</code></pre></td></tr><tr><td><code>getOwnedLabel</code></td><td><pre><code class=\"language-application-typescript\">getOwnedLabel(name: string): ScriptAttribute | null</code></pre></td></tr><tr><td><code>getLabels</code></td><td><pre><code class=\"language-application-typescript\">getLabels(name?: string): ScriptAttribute[]</code></pre></td></tr><tr><td><code>getOwnedLabels</code></td><td><pre><code class=\"language-application-typescript\">getOwnedLabels(name: string): ScriptAttribute[]</code></pre></td></tr><tr><td><code>getLabelValue</code></td><td><pre><code class=\"language-application-typescript\">getLabelValue(name: string): string | null</code></pre></td></tr><tr><td><code>getOwnedLabelValue</code></td><td><pre><code class=\"language-application-typescript\">getOwnedLabelValue(name: string): string | null</code></pre></td></tr><tr><td><code>getLabelValues</code></td><td><pre><code class=\"language-application-typescript\">getLabelValues(name: string): string[]</code></pre></td></tr><tr><td><code>getOwnedLabelValues</code></td><td><pre><code class=\"language-application-typescript\">getOwnedLabelValues(name: string): string[]</code></pre></td></tr><tr><td><code>hasLabel</code></td><td><pre><code class=\"language-application-typescript\">hasLabel(name: string): boolean</code></pre></td></tr><tr><td><code>hasOwnedLabel</code></td><td><pre><code class=\"language-application-typescript\">hasOwnedLabel(name: string, value?: string): boolean</code></pre></td></tr><tr><td><code>isLabelTruthy</code></td><td><pre><code class=\"language-application-typescript\">isLabelTruthy(name: string): boolean</code></pre></td></tr><tr><td><code>hasInheritableArchivedLabel</code></td><td><pre><code class=\"language-application-typescript\">hasInheritableArchivedLabel(): boolean</code></pre></td></tr><tr><td><code>getRelation</code></td><td><pre><code class=\"language-application-typescript\">getRelation(name: string): ScriptAttribute | null</code></pre></td></tr><tr><td><code>getOwnedRelation</code></td><td><pre><code class=\"language-application-typescript\">getOwnedRelation(name: string): ScriptAttribute | null</code></pre></td></tr><tr><td><code>getRelations</code></td><td><pre><code class=\"language-application-typescript\">getRelations(name?: string): ScriptAttribute[]</code></pre></td></tr><tr><td><code>getOwnedRelations</code></td><td><pre><code class=\"language-application-typescript\">getOwnedRelations(name?: string | null): ScriptAttribute[]</code></pre></td></tr><tr><td><code>getRelationValue</code></td><td><pre><code class=\"language-application-typescript\">getRelationValue(name: string): string | null</code></pre></td></tr><tr><td><code>getOwnedRelationValue</code></td><td><pre><code class=\"language-application-typescript\">getOwnedRelationValue(name: string): string | null</code></pre></td></tr><tr><td><code>getRelationTarget</code></td><td><pre><code class=\"language-application-typescript\">getRelationTarget(name: string): ScriptBNote | null</code></pre></td></tr><tr><td><code>hasRelation</code></td><td><pre><code class=\"language-application-typescript\">hasRelation(name: string, value?: string): boolean</code></pre></td></tr><tr><td><code>hasOwnedRelation</code></td><td><pre><code class=\"language-application-typescript\">hasOwnedRelation(name: string, value?: string): boolean</code></pre></td></tr><tr><td><code>addLabel</code></td><td><pre><code class=\"language-application-typescript\">addLabel(name: string, value?: string, isInheritable?: boolean): ScriptAttribute</code></pre></td></tr><tr><td><code>addRelation</code></td><td><pre><code class=\"language-application-typescript\">addRelation(name: string, targetNoteId: string, isInheritable?: boolean): ScriptAttribute</code></pre></td></tr><tr><td><code>addAttribute</code></td><td><pre><code class=\"language-application-typescript\">addAttribute(type: string, name: string, value?: string, isInheritable?: boolean): ScriptAttribute</code></pre></td></tr><tr><td><code>setLabel</code></td><td><pre><code class=\"language-application-typescript\">setLabel(name: string, value?: string): void</code></pre></td></tr><tr><td><code>setRelation</code></td><td><pre><code class=\"language-application-typescript\">setRelation(name: string, value?: string): void</code></pre></td></tr><tr><td><code>setAttribute</code></td><td><pre><code class=\"language-application-typescript\">setAttribute(type: string, name: string, value?: string): void</code></pre></td></tr><tr><td><code>setAttributeValueById</code></td><td><pre><code class=\"language-application-typescript\">setAttributeValueById(attributeId: string, value?: string): void</code></pre></td></tr><tr><td><code>toggleLabel</code></td><td><pre><code class=\"language-application-typescript\">toggleLabel(enabled: boolean, name: string, value?: string): void</code></pre></td></tr><tr><td><code>toggleRelation</code></td><td><pre><code class=\"language-application-typescript\">toggleRelation(enabled: boolean, name: string, value?: string): void</code></pre></td></tr><tr><td><code>toggleAttribute</code></td><td><pre><code class=\"language-application-typescript\">toggleAttribute(type: string, enabled: boolean, name: string, value?: string): void</code></pre></td></tr><tr><td><code>removeLabel</code></td><td><pre><code class=\"language-application-typescript\">removeLabel(name: string, value?: string): void</code></pre></td></tr><tr><td><code>removeRelation</code></td><td><pre><code class=\"language-application-typescript\">removeRelation(name: string, value?: string): void</code></pre></td></tr><tr><td><code>removeAttribute</code></td><td><pre><code class=\"language-application-typescript\">removeAttribute(type: string, name: string, value?: string): void</code></pre></td></tr><tr><td><code>isInherited</code></td><td><pre><code class=\"language-application-typescript\">isInherited(): boolean</code></pre></td></tr><tr><td><code>revisionCount</code></td><td><p><code>number | null</code></p></td></tr><tr><td><code>getRevisions</code></td><td><pre><code class=\"language-application-typescript\">getRevisions(): ScriptBRevision[]</code></pre></td></tr><tr><td><code>saveRevision</code></td><td><pre><code class=\"language-application-typescript\">saveRevision(opts?: { description?: string; source?: string }): ScriptBRevision</code></pre></td></tr><tr><td><code>getAttachments</code></td><td><pre><code class=\"language-application-typescript\">getAttachments(): ScriptAttachment[]</code></pre></td></tr><tr><td><code>getAttachmentById</code></td><td><pre><code class=\"language-application-typescript\">getAttachmentById(attachmentId: string): ScriptAttachment</code></pre></td></tr><tr><td><code>getAttachmentByTitle</code></td><td><pre><code class=\"language-application-typescript\">getAttachmentByTitle(title: string): ScriptAttachment | undefined</code></pre></td></tr><tr><td><code>getAttachmentsByRole</code></td><td><pre><code class=\"language-application-typescript\">getAttachmentsByRole(role: string): ScriptAttachment[]</code></pre></td></tr><tr><td><code>saveAttachment</code></td><td><pre><code class=\"language-application-typescript\">saveAttachment(attachment: ScriptSaveAttachmentInput, matchBy?: \"title\" | \"attachmentId\"): ScriptAttachment</code></pre></td></tr><tr><td><code>convertToParentAttachment</code></td><td><pre><code class=\"language-application-typescript\">convertToParentAttachment(opts?: Record<string, unknown>): ScriptAttachment | null</code></pre></td></tr><tr><td><code>isEligibleForConversionToAttachment</code></td><td><pre><code class=\"language-application-typescript\">isEligibleForConversionToAttachment(opts?: Record<string, unknown>): boolean</code></pre></td></tr><tr><td><code>contentSize</code></td><td><p><code>number | null</code></p></td></tr><tr><td><code>contentAndAttachmentsSize</code></td><td><p><code>number | null</code></p></td></tr><tr><td><code>contentAndAttachmentsAndRevisionsSize</code></td><td><p><code>number | null</code></p></td></tr><tr><td><code>cloneTo</code></td><td><pre><code class=\"language-application-typescript\">cloneTo(parentNoteId: string): ScriptCloneResponse</code></pre></td></tr><tr><td><code>deleteNote</code></td><td><pre><code class=\"language-application-typescript\">deleteNote(deleteId?: string | null): void</code></pre></td></tr><tr><td><code>sortParents</code></td><td><pre><code class=\"language-application-typescript\">sortParents(): void</code></pre></td></tr><tr><td><code>sortChildren</code></td><td><pre><code class=\"language-application-typescript\">sortChildren(): void</code></pre></td></tr><tr><td><code>searchNotesInSubtree</code></td><td><pre><code class=\"language-application-typescript\">searchNotesInSubtree(searchString: string): ScriptBNote[]</code></pre></td></tr><tr><td><code>searchNoteInSubtree</code></td><td><pre><code class=\"language-application-typescript\">searchNoteInSubtree(searchString: string): ScriptBNote | null</code></pre></td></tr><tr><td><code>getSearchResultNotes</code></td><td><pre><code class=\"language-application-typescript\">getSearchResultNotes(): ScriptBNote[]</code></pre></td></tr><tr><td><code>isFolder</code></td><td><pre><code class=\"language-application-typescript\">isFolder(): boolean</code></pre></td></tr><tr><td><code>isContentAvailable</code></td><td><pre><code class=\"language-application-typescript\">isContentAvailable(): boolean</code></pre></td></tr><tr><td><code>isStringNote</code></td><td><pre><code class=\"language-application-typescript\">isStringNote(): boolean</code></pre></td></tr><tr><td><code>isHtml</code></td><td><pre><code class=\"language-application-typescript\">isHtml(): boolean</code></pre></td></tr><tr><td><code>isImage</code></td><td><pre><code class=\"language-application-typescript\">isImage(): boolean</code></pre></td></tr><tr><td><code>isJavaScript</code></td><td><pre><code class=\"language-application-typescript\">isJavaScript(): boolean</code></pre></td></tr><tr><td><code>isJsx</code></td><td><pre><code class=\"language-application-typescript\">isJsx(): boolean</code></pre></td></tr><tr><td><code>isJson</code></td><td><pre><code class=\"language-application-typescript\">isJson(): boolean</code></pre></td></tr><tr><td><code>isMarkdown</code></td><td><pre><code class=\"language-application-typescript\">isMarkdown(): boolean</code></pre></td></tr><tr><td><code>isOptions</code></td><td><pre><code class=\"language-application-typescript\">isOptions(): boolean</code></pre></td></tr><tr><td><code>isLaunchBarConfig</code></td><td><pre><code class=\"language-application-typescript\">isLaunchBarConfig(): boolean</code></pre></td></tr><tr><td><code>isHiddenCompletely</code></td><td><pre><code class=\"language-application-typescript\">isHiddenCompletely(): boolean</code></pre></td></tr><tr><td><code>isInHiddenSubtree</code></td><td><pre><code class=\"language-application-typescript\">isInHiddenSubtree(): boolean</code></pre></td></tr><tr><td><code>getScriptEnv</code></td><td><pre><code class=\"language-application-typescript\">getScriptEnv(): \"frontend\" | \"backend\" | null</code></pre></td></tr><tr><td><code>executeScript</code></td><td><pre><code class=\"language-application-typescript\">executeScript(): unknown</code></pre></td></tr></tbody></table></figure><h2><code>ScriptRequest</code></h2><p>Minimal Express <code>Request</code> surface available to <strong>custom request handlers</strong> (a subset of Express's <code>Request</code> — re-declared here to keep this module self-contained). Only the commonly used members are typed; the real object is a full Express request.</p><figure class=\"table\"><table><thead><tr><th>Member</th><th>Description</th></tr></thead><tbody><tr><td><code>params</code></td><td><p><code>Record<string, string></code><br>Route/path parameters.</p></td></tr><tr><td><code>query</code></td><td><p><code>Record<string, unknown></code><br>Parsed query-string parameters.</p></td></tr><tr><td><code>body</code></td><td><p><code>unknown</code><br>Parsed request body (requires a matching body parser).</p></td></tr><tr><td><code>headers</code></td><td><p><code>Record<string, string | string[] | undefined></code><br>Request headers (lower-cased names).</p></td></tr><tr><td><code>method</code></td><td><p><code>string</code><br>HTTP method, e.g. \"GET\", \"POST\".</p></td></tr><tr><td><code>url</code></td><td><p><code>string</code><br>Request URL (path + query string).</p></td></tr><tr><td><code>get</code></td><td><pre><code class=\"language-application-typescript\">get(headerName: string): string | undefined</code></pre><p>Returns the value of the given (case-insensitive) header.</p></td></tr></tbody></table></figure><h2><code>ScriptResponse</code></h2><p>Minimal Express <code>Response</code> surface available to <strong>custom request handlers</strong> (a subset of Express's <code>Response</code>). Write the HTTP response through this object, e.g. <code>api.res.status(200).json({ ok: true })</code>.</p><figure class=\"table\"><table><thead><tr><th>Member</th><th>Description</th></tr></thead><tbody><tr><td><code>status</code></td><td><pre><code class=\"language-application-typescript\">status(code: number): ScriptResponse</code></pre><p>Sets the HTTP status code (chainable).</p></td></tr><tr><td><code>send</code></td><td><pre><code class=\"language-application-typescript\">send(body?: unknown): ScriptResponse</code></pre><p>Sends the response body (string, Buffer, object, …) and ends the response.</p></td></tr><tr><td><code>json</code></td><td><pre><code class=\"language-application-typescript\">json(body: unknown): ScriptResponse</code></pre><p>Sends a JSON response and ends the response.</p></td></tr><tr><td><code>setHeader</code></td><td><pre><code class=\"language-application-typescript\">setHeader(name: string, value: string | string[]): ScriptResponse</code></pre><p>Sets a response header (chainable).</p></td></tr><tr><td><code>set</code></td><td><pre><code class=\"language-application-typescript\">set(field: string, value?: string): ScriptResponse</code></pre><p>Sets a response header (Express alias of <code>setHeader</code>, chainable).</p></td></tr><tr><td><code>redirect</code></td><td><pre><code class=\"language-application-typescript\">redirect(url: string): void</code></pre><p>Redirects to the given URL.</p></td></tr><tr><td><code>end</code></td><td><pre><code class=\"language-application-typescript\">end(): void</code></pre><p>Ends the response without further data.</p></td></tr></tbody></table></figure><h2><code>ScriptBBranch</code></h2><p>A branch (note→parent placement) as seen by backend scripts (subset of <code>BBranch</code>).</p><figure class=\"table\"><table><thead><tr><th>Member</th><th>Description</th></tr></thead><tbody><tr><td><code>branchId</code></td><td><p><code>string</code></p></td></tr><tr><td><code>noteId</code></td><td><p><code>string</code></p></td></tr><tr><td><code>parentNoteId</code></td><td><p><code>string</code></p></td></tr><tr><td><code>prefix</code></td><td><p><code>string | null</code></p></td></tr><tr><td><code>notePosition</code></td><td><p><code>number</code></p></td></tr><tr><td><code>isExpanded</code></td><td><p><code>boolean</code></p></td></tr><tr><td><code>getNote</code></td><td><pre><code class=\"language-application-typescript\">getNote(): ScriptBNote</code></pre></td></tr><tr><td><code>getParentNote</code></td><td><pre><code class=\"language-application-typescript\">getParentNote(): ScriptBNote | null</code></pre></td></tr></tbody></table></figure><h2><code>ScriptBRevision</code></h2><p>A note revision as seen by backend scripts (subset of trilium-core's <code>BRevision</code>).</p><figure class=\"table\"><table><thead><tr><th>Member</th><th>Description</th></tr></thead><tbody><tr><td><code>revisionId</code><br><em>optional</em></td><td><p><code>string</code></p></td></tr><tr><td><code>noteId</code></td><td><p><code>string</code></p></td></tr><tr><td><code>type</code></td><td><p><code>string</code></p></td></tr><tr><td><code>mime</code></td><td><p><code>string</code></p></td></tr><tr><td><code>title</code></td><td><p><code>string</code></p></td></tr><tr><td><code>dateLastEdited</code><br><em>optional</em></td><td><p><code>string</code></p></td></tr><tr><td><code>utcDateLastEdited</code><br><em>optional</em></td><td><p><code>string</code></p></td></tr><tr><td><code>contentLength</code><br><em>optional</em></td><td><p><code>number</code></p></td></tr><tr><td><code>getContent</code></td><td><pre><code class=\"language-application-typescript\">getContent(): string | Uint8Array<ArrayBufferLike></code></pre></td></tr><tr><td><code>getJsonContent</code></td><td><pre><code class=\"language-application-typescript\">getJsonContent(): unknown</code></pre></td></tr></tbody></table></figure><h2><code>ScriptDayjsInstance</code></h2><p>A date as day.js wraps it (subset).</p><figure class=\"table\"><table><thead><tr><th>Member</th><th>Description</th></tr></thead><tbody><tr><td><code>format</code></td><td><pre><code class=\"language-application-typescript\">format(template?: string): string</code></pre></td></tr><tr><td><code>add</code></td><td><pre><code class=\"language-application-typescript\">add(value: number, unit: string): ScriptDayjsInstance</code></pre></td></tr><tr><td><code>subtract</code></td><td><pre><code class=\"language-application-typescript\">subtract(value: number, unit: string): ScriptDayjsInstance</code></pre></td></tr><tr><td><code>toDate</code></td><td><pre><code class=\"language-application-typescript\">toDate(): Date</code></pre></td></tr></tbody></table></figure><h2>Types</h2><h3><code>ScriptDayjs</code></h3><p>Minimal day.js surface (the real API exposes the full day.js factory).</p><pre><code class=\"language-application-typescript\">type ScriptDayjs = (date?: string | number | Date) => ScriptDayjsInstance</code></pre><h3><code>ScriptAttribute</code></h3><figure class=\"table\"><table><thead><tr><th>Property</th><th>Description</th></tr></thead><tbody><tr><td><code>attributeId</code></td><td><code>string</code></td></tr><tr><td><code>type</code></td><td><code>\"label\" | \"relation\"</code></td></tr><tr><td><code>name</code></td><td><code>string</code></td></tr><tr><td><code>value</code></td><td><code>string</code></td></tr><tr><td><code>isInheritable</code></td><td><code>boolean</code></td></tr><tr><td><code>isOwned</code></td><td><code>boolean</code></td></tr></tbody></table></figure><h3><code>ScriptNoteAndBranch</code></h3><p>Result of the backend note-creation helpers.</p><figure class=\"table\"><table><thead><tr><th>Property</th><th>Description</th></tr></thead><tbody><tr><td><code>note</code></td><td><code>ScriptBNote</code></td></tr><tr><td><code>branch</code></td><td><code>ScriptBBranch</code></td></tr></tbody></table></figure><h3><code>ScriptSubtreeOpts</code></h3><p>Options accepted by the subtree traversal helpers on <code>ScriptBNote</code>.</p><figure class=\"table\"><table><thead><tr><th>Property</th><th>Description</th></tr></thead><tbody><tr><td><code>includeArchived</code> <br><em>optional</em></td><td><code>boolean</code></td></tr><tr><td><code>includeHidden</code> <br><em>optional</em></td><td><code>boolean</code></td></tr><tr><td><code>resolveSearch</code> <br><em>optional</em></td><td><code>boolean</code></td></tr></tbody></table></figure><h3><code>ScriptSubtreeRelationship</code></h3><p>A single parent→child link in a subtree (<code>ScriptBNote.getSubtree</code>).</p><figure class=\"table\"><table><thead><tr><th>Property</th><th>Description</th></tr></thead><tbody><tr><td><code>parentNoteId</code></td><td><code>string</code></td></tr><tr><td><code>childNoteId</code></td><td><code>string</code></td></tr></tbody></table></figure><h3><code>ScriptNotePathRecord</code></h3><p>One resolved tree path to a note (subset of the client's <code>NotePathRecord</code>).</p><figure class=\"table\"><table><thead><tr><th>Property</th><th>Description</th></tr></thead><tbody><tr><td><code>isArchived</code></td><td><code>boolean</code></td></tr><tr><td><code>isInHoistedSubTree</code></td><td><code>boolean</code></td></tr><tr><td><code>isSearch</code> <br><em>optional</em></td><td><code>boolean</code></td></tr><tr><td><code>notePath</code></td><td><code>string[]</code></td></tr><tr><td><code>isHidden</code></td><td><code>boolean</code></td></tr></tbody></table></figure><h3><code>ScriptAttachment</code></h3><p>An attachment as seen by frontend scripts (subset of the client's <code>FAttachment</code>).</p><figure class=\"table\"><table><thead><tr><th>Property</th><th>Description</th></tr></thead><tbody><tr><td><code>attachmentId</code></td><td><code>string</code></td></tr><tr><td><code>ownerId</code></td><td><code>string</code></td></tr><tr><td><code>role</code></td><td><code>string</code></td></tr><tr><td><code>mime</code></td><td><code>string</code></td></tr><tr><td><code>title</code></td><td><code>string</code></td></tr><tr><td><code>utcDateModified</code></td><td><code>string</code></td></tr><tr><td><code>contentLength</code></td><td><code>number</code></td></tr></tbody></table></figure><h3><code>ScriptSaveAttachmentInput</code></h3><p>Input accepted by <code>ScriptBNote.saveAttachment</code>.</p><figure class=\"table\"><table><thead><tr><th>Property</th><th>Description</th></tr></thead><tbody><tr><td><code>attachmentId</code> <br><em>optional</em></td><td><code>string</code></td></tr><tr><td><code>role</code></td><td><code>string</code></td></tr><tr><td><code>mime</code></td><td><code>string</code></td></tr><tr><td><code>title</code></td><td><code>string</code></td></tr><tr><td><code>content</code> <br><em>optional</em></td><td><code>string | Uint8Array<ArrayBufferLike></code></td></tr><tr><td><code>position</code> <br><em>optional</em></td><td><code>number</code></td></tr></tbody></table></figure><h3><code>ScriptCloneResponse</code></h3><p>Result of a clone operation (<code>ScriptBNote.cloneTo</code>); mirrors <code>CloneResponse</code>.</p><figure class=\"table\"><table><thead><tr><th>Property</th><th>Description</th></tr></thead><tbody><tr><td><code>success</code></td><td><code>boolean</code></td></tr><tr><td><code>message</code> <br><em>optional</em></td><td><code>string</code></td></tr><tr><td><code>branchId</code> <br><em>optional</em></td><td><code>string</code></td></tr><tr><td><code>notePath</code> <br><em>optional</em></td><td><code>string</code></td></tr></tbody></table></figure>","_help_GFXVHyblVN3d": "<p>The Electron API is the bridge between Trilium's interface and Electron's main process, exposed as the global <code>window.electronApi</code> in the desktop application.</p><p>It is not part of the <code>api</code> global of script notes, but frontend scripts running in the desktop application can call it directly. It is <code>undefined</code> in the browser and in the standalone build, so guard calls with <code>if (window.electronApi)</code>.</p><h2><code>ElectronApi</code></h2><p>The complete surface exposed to the renderer as <code>window.electronApi</code> via <code>contextBridge</code>. The renderer must access Electron-only functionality through this object — direct <code>require(\"electron\")</code> and <code>@electron/remote</code> are unavailable because <code>nodeIntegration</code> is disabled and <code>contextIsolation</code> is enabled.</p><p>The runtime value lives in <code>apps/desktop/src/preload.ts</code>; this interface is the contract both the preload script (<code>satisfies ElectronApi</code>) and the client (<code>window.electronApi</code>) share.</p><figure class=\"table\"><table><thead><tr><th>Property</th><th>Description</th></tr></thead><tbody><tr><td><code>window</code></td><td><code>ElectronWindowApi</code> <br>Window chrome, zoom, theme, lifecycle, and main → renderer events.</td></tr><tr><td><code>clipboard</code></td><td><code>ElectronClipboardApi</code> <br>System clipboard access beyond what the standard Web Clipboard API offers.</td></tr><tr><td><code>shell</code></td><td><code>ElectronShellApi</code> <br>Shell integration — opening URLs, files, and downloads with OS handlers.</td></tr><tr><td><code>contextMenu</code></td><td><code>ElectronContextMenuApi</code> <br>Native context-menu plumbing for right-click events on web contents.</td></tr><tr><td><code>spellcheck</code></td><td><code>ElectronSpellcheckApi</code> <br>Chromium spell checker controls (dictionary, language list).</td></tr><tr><td><code>systemIntegration</code></td><td><code>ElectronSystemIntegrationApi</code> <br>OS integration — system tray and autostart / launch-on-login.</td></tr><tr><td><code>printing</code></td><td><code>ElectronPrintingApi</code> <br>Printing and PDF export pipeline.</td></tr><tr><td><code>navigation</code></td><td><code>ElectronNavigationApi</code> <br>Read/write access to Chromium's back/forward navigation history.</td></tr><tr><td><code>ws</code></td><td><code>ElectronWsApi</code> <br>In-process bridge that replaces the renderer↔server WebSocket.</td></tr><tr><td><code>security</code></td><td><code>ElectronSecurityApi</code> <br>Security settings (backend scripting, SQL console) stored outside the DB.</td></tr><tr><td><code>backupPassphrase</code></td><td><code>ElectronBackupPassphraseApi</code> <br>Write-only access to the backup passphrase, kept in the OS keyring.</td></tr><tr><td><code>onenote</code></td><td><code>ElectronOneNoteApi</code> <br>OneNote importer sign-in via a loopback OAuth redirect (desktop only).</td></tr><tr><td><code>nativeExport</code></td><td><code>ElectronNativeExportApi</code> <br>Desktop-native subtree export that streams a <code>.zip</code> straight to a file.</td></tr><tr><td><code>nativeImport</code></td><td><code>ElectronNativeImportApi</code> <br>Desktop-native large-<code>.zip</code> import that reads the user's file in place via a capability token.</td></tr><tr><td><code>dialog</code></td><td><code>ElectronDialogApi</code> <br>Native OS pickers that hand the renderer a location the user chose themselves.</td></tr><tr><td><code>restore</code></td><td><code>ElectronRestoreApi</code> <br>Choosing a backup to restore during setup, read where it lies rather than uploaded.</td></tr><tr><td><code>transcription</code></td><td><code>ElectronTranscriptionApi</code> <br>Meeting transcription: starting and stopping a recording, and following its state.</td></tr></tbody></table></figure><h2><code>ElectronWindowApi</code></h2><p>Window-level controls: zoom, theme, title bar, full screen, lifecycle, and a handful of main → renderer event subscriptions.</p><figure class=\"table\"><table><thead><tr><th>Member</th><th>Description</th></tr></thead><tbody><tr><td><code>setZoomFactor</code></td><td><pre><code class=\"language-application-typescript\">setZoomFactor(factor: number): void</code></pre><p>Sets the page zoom factor for the current window.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>factor</code></td><td><code>number</code><br><code>1.0</code> is 100%; e.g. <code>1.2</code> zooms to 120%.</td></tr></tbody></table></figure></td></tr><tr><td><code>getZoomFactor</code></td><td><pre><code class=\"language-application-typescript\">getZoomFactor(): number</code></pre><p>Returns the current page zoom factor (<code>1.0</code> = 100%).</p></td></tr><tr><td><code>setNativeThemeSource</code></td><td><pre><code class=\"language-application-typescript\">setNativeThemeSource(source: \"system\" | \"light\" | \"dark\"): void</code></pre><p>Overrides the operating system's reported color scheme for this app.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>source</code></td><td><code>\"system\" | \"light\" | \"dark\"</code><br>The color scheme to report, or <code>\"system\"</code> to follow the OS setting.</td></tr></tbody></table></figure></td></tr><tr><td><code>setTitleBarOverlay</code></td><td><pre><code class=\"language-application-typescript\">setTitleBarOverlay(options: { color: string; symbolColor: string; height?: number }): void</code></pre><p>Customizes the Windows and Linux native title bar overlay (the area containing the minimize / maximize / close buttons). <code>height</code> also controls their vertical placement, since the buttons are centered within the overlay. It is given in device-independent pixels, which the page zoom does not scale — see <code>setWindowButtonPosition</code>.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>options</code></td><td><code>{ color: string; symbolColor: string; height?: number }</code><br>The overlay's background color, the color of the button symbols, and the overlay's height.</td></tr></tbody></table></figure></td></tr><tr><td><code>setWindowButtonPosition</code></td><td><pre><code class=\"language-application-typescript\">setWindowButtonPosition(position: { x: number; y: number }): void</code></pre><p>Repositions the macOS traffic-light window buttons. Coordinates are relative to the window's top-left corner and given in device-independent pixels: the buttons are drawn by the system rather than by the page, so unlike the surrounding chrome they are unaffected by the page zoom factor and callers have to scale the offsets themselves.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>position</code></td><td><code>{ x: number; y: number }</code><br>The offset of the buttons from the window's top-left corner.</td></tr></tbody></table></figure></td></tr><tr><td><code>onEnterFullScreen</code></td><td><pre><code class=\"language-application-typescript\">onEnterFullScreen(callback: () => void): void</code></pre><p>Registers a callback fired whenever the window enters full-screen mode.</p></td></tr><tr><td><code>onLeaveFullScreen</code></td><td><pre><code class=\"language-application-typescript\">onLeaveFullScreen(callback: () => void): void</code></pre><p>Registers a callback fired whenever the window leaves full-screen mode.</p></td></tr><tr><td><code>isFullScreen</code></td><td><pre><code class=\"language-application-typescript\">isFullScreen(): boolean</code></pre><p>Synchronously returns whether the window is currently in full-screen mode.</p></td></tr><tr><td><code>setFullScreen</code></td><td><pre><code class=\"language-application-typescript\">setFullScreen(enabled: boolean): void</code></pre><p>Enters or leaves full-screen mode.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>enabled</code></td><td><code>boolean</code><br><code>true</code> to enter full-screen mode, <code>false</code> to leave it.</td></tr></tbody></table></figure></td></tr><tr><td><code>minimizeWindow</code></td><td><pre><code class=\"language-application-typescript\">minimizeWindow(): void</code></pre><p>Minimizes the current window to the taskbar / dock.</p></td></tr><tr><td><code>maximizeWindow</code></td><td><pre><code class=\"language-application-typescript\">maximizeWindow(): void</code></pre><p>Maximizes the current window to fill the available screen area.</p></td></tr><tr><td><code>unmaximizeWindow</code></td><td><pre><code class=\"language-application-typescript\">unmaximizeWindow(): void</code></pre><p>Restores the window from a maximized state to its previous size.</p></td></tr><tr><td><code>isMaximized</code></td><td><pre><code class=\"language-application-typescript\">isMaximized(): boolean</code></pre><p>Synchronously returns whether the window is currently maximized.</p></td></tr><tr><td><code>closeWindow</code></td><td><pre><code class=\"language-application-typescript\">closeWindow(): void</code></pre><p>Closes the current window.</p></td></tr><tr><td><code>isAlwaysOnTop</code></td><td><pre><code class=\"language-application-typescript\">isAlwaysOnTop(): boolean</code></pre><p>Synchronously returns whether the window is pinned above all others.</p></td></tr><tr><td><code>setAlwaysOnTop</code></td><td><pre><code class=\"language-application-typescript\">setAlwaysOnTop(enabled: boolean): void</code></pre><p>Pins the window above all others, or unpins it.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>enabled</code></td><td><code>boolean</code><br><code>true</code> to pin the window, <code>false</code> to unpin it.</td></tr></tbody></table></figure></td></tr><tr><td><code>toggleDevTools</code></td><td><pre><code class=\"language-application-typescript\">toggleDevTools(): void</code></pre><p>Opens or closes Chromium DevTools for the current window.</p></td></tr><tr><td><code>isDevToolsDocked</code></td><td><pre><code class=\"language-application-typescript\">isDevToolsDocked(): boolean</code></pre><p>Synchronously returns whether DevTools is currently open and docked into this window (as opposed to detached into a separate window).</p></td></tr><tr><td><code>setBackgroundMaterial</code></td><td><pre><code class=\"language-application-typescript\">setBackgroundMaterial(material: string): void</code></pre><p>Sets the Windows 11 backdrop material applied behind the window contents. No-op on other platforms.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>material</code></td><td><code>string</code><br>The material, such as <code>\"mica\"</code>, <code>\"acrylic\"</code>, <code>\"tabbed\"</code> or <code>\"none\"</code>.</td></tr></tbody></table></figure></td></tr><tr><td><code>setVibrancy</code></td><td><pre><code class=\"language-application-typescript\">setVibrancy(vibrancy: string): void</code></pre><p>Sets the macOS vibrancy effect applied behind the window contents. No-op on other platforms.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>vibrancy</code></td><td><code>string</code><br>The effect, such as <code>\"sidebar\"</code>, <code>\"under-window\"</code> or <code>\"fullscreen-ui\"</code>.</td></tr></tbody></table></figure></td></tr><tr><td><code>reloadAllWindows</code></td><td><pre><code class=\"language-application-typescript\">reloadAllWindows(): void</code></pre><p>Triggers a hard reload of every open Trilium window.</p></td></tr><tr><td><code>restartApp</code></td><td><pre><code class=\"language-application-typescript\">restartApp(): void</code></pre><p>Quits the app and immediately relaunches it.</p></td></tr><tr><td><code>toggleAllWindows</code></td><td><pre><code class=\"language-application-typescript\">toggleAllWindows(): void</code></pre><p>Shows all hidden windows or hides all visible ones — used by the \"show/hide app\" global shortcut and tray menu entry.</p></td></tr><tr><td><code>clearCache</code></td><td><pre><code class=\"language-application-typescript\">clearCache(): Promise<void></code></pre><p>Clears the underlying Chromium HTTP cache. Resolves once the cache is empty.</p></td></tr><tr><td><code>showWindow</code></td><td><pre><code class=\"language-application-typescript\">showWindow(): void</code></pre><p>Brings the main window to the foreground, restoring it if minimized.</p></td></tr><tr><td><code>reportStartupMetric</code></td><td><pre><code class=\"language-application-typescript\">reportStartupMetric(metric: \"client-full-render\"): void</code></pre><p>Reports a renderer startup milestone to the main process, which records it relative to OS process creation alongside the main-process startup metrics. Only the first report of each metric is recorded; later reports (e.g. after a window reload or from extra windows) are ignored.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>metric</code></td><td><code>\"client-full-render\"</code><br>The milestone the renderer reached.</td></tr></tbody></table></figure></td></tr><tr><td><code>onGlobalShortcut</code></td><td><pre><code class=\"language-application-typescript\">onGlobalShortcut(callback: (actionName: string) => void): void</code></pre><p>Subscribes to globally registered keyboard shortcuts.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>callback</code></td><td><code>(actionName: string) => void</code><br>Receives the name of the action the shortcut triggers, not the keystroke.</td></tr></tbody></table></figure></td></tr><tr><td><code>onOpenInSameTab</code></td><td><pre><code class=\"language-application-typescript\">onOpenInSameTab(callback: (noteId: string) => void): void</code></pre><p>Subscribes to \"open note in active tab\" requests originating from outside the renderer (e.g. tray menu, deep links).</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>callback</code></td><td><code>(noteId: string) => void</code><br>Receives the ID of the note to open.</td></tr></tbody></table></figure></td></tr><tr><td><code>onDevToolsDockChanged</code></td><td><pre><code class=\"language-application-typescript\">onDevToolsDockChanged(callback: (docked: boolean) => void): void</code></pre><p>Subscribes to changes of the DevTools docking state. While DevTools is docked, Chromium disables the native window material (Mica / vibrancy).</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>callback</code></td><td><code>(docked: boolean) => void</code><br>Receives <code>true</code> while DevTools is attached to this window, and <code>false</code> when it is closed or in a separate window.</td></tr></tbody></table></figure></td></tr></tbody></table></figure><h2><code>ElectronClipboardApi</code></h2><p>Renderer access to the system clipboard for cases the standard Web API can't cover.</p><figure class=\"table\"><table><thead><tr><th>Member</th><th>Description</th></tr></thead><tbody><tr><td><code>copyImageToClipboard</code></td><td><pre><code class=\"language-application-typescript\">copyImageToClipboard(buffer: Uint8Array): void</code></pre><p>Writes a raw image (PNG-encoded bytes) to the system clipboard so it can be pasted into other applications as an image rather than as a file.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>buffer</code></td><td><code>Uint8Array</code><br>The PNG-encoded image.</td></tr></tbody></table></figure></td></tr><tr><td><code>readText</code></td><td><pre><code class=\"language-application-typescript\">readText(): Promise<string></code></pre><p>Reads plain text from the system clipboard via the main-process <code>electron.clipboard</code>. Used instead of <code>navigator.clipboard.readText()</code> so the renderer's deny-by-default permission policy does not have to grant the sensitive <code>clipboard-read</code> permission to the whole session.</p></td></tr><tr><td><code>readHTML</code></td><td><pre><code class=\"language-application-typescript\">readHTML(): Promise<string></code></pre><p>Reads the HTML flavor of the system clipboard, the same way as <code>readText</code>. Empty when the clipboard has no HTML.</p></td></tr></tbody></table></figure><h2><code>ElectronShellApi</code></h2><p>Wrappers around Electron's <code>shell</code> module for interacting with the OS (default browser, default file handler, downloads, etc.).</p><p>Every method here is validated in the main process before dispatch — see <code>apps/server/src/services/shell_validators.ts</code>. The renderer is treated as untrusted: invalid input throws on the main side rather than being silently passed through to <code>electron.shell</code> / <code>WebContents</code>.</p><figure class=\"table\"><table><thead><tr><th>Member</th><th>Description</th></tr></thead><tbody><tr><td><code>openExternal</code></td><td><pre><code class=\"language-application-typescript\">openExternal(url: string): void</code></pre><p>Opens a URL in the user's default external browser via <code>electron.shell.openExternal</code>.</p><p><strong>Security:</strong> the scheme is matched against the allowlist in <code>SHELL_OPEN_EXTERNAL_PROTOCOLS</code> (commons). Blocked schemes include <code>file:</code>, <code>data:</code>, <code>smb:</code>, <code>ldap:</code>, <code>ldaps:</code>, <code>jar:</code>, and <code>view-source:</code> — they cover Follina-class RCE primitives (<code>ms-msdt:</code>, <code>search-ms:</code>), NTLM credential theft, and Java loader vectors. URLs that fail to parse are rejected outright.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>url</code></td><td><code>string</code><br>The URL to open.</td></tr></tbody></table></figure></td></tr><tr><td><code>openPath</code></td><td><pre><code class=\"language-application-typescript\">openPath(path: string): Promise<string></code></pre><p>Opens a local path with its default OS handler.</p><p><strong>Security:</strong> the path is canonicalized and must resolve to either the Trilium data directory (or a descendant) or the Trilium tmp directory (or a descendant). Anything else — absolute paths elsewhere on disk, traversal attempts, UNC paths that don't normalize under those roots — is rejected. Null bytes, empty strings, and non-existent files are also rejected.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>path</code></td><td><code>string</code><br>A file in the Trilium data or tmp directory.</td></tr></tbody></table></figure><p><strong>Returns</strong> <code>Promise<string></code>: An empty string on success, or an error message on failure.</p></td></tr><tr><td><code>showItemInFolder</code></td><td><pre><code class=\"language-application-typescript\">showItemInFolder(path: string): void</code></pre><p>Shows a local file in the OS file manager, with the file itself selected, via <code>electron.shell.showItemInFolder</code>. For pointing at a file the user is not meant to open — the database, whose reader is Trilium itself.</p><p><strong>Security:</strong> the same sandbox as <code>openPath</code>, with the database file added as a root of its own, since <code>TRILIUM_DOCUMENT_PATH</code> may put it outside the data directory. Revealing is the milder act of the two, the file being selected rather than launched, but a path the renderer names is still a path the renderer must not be free to choose.</p><p>Nothing is reported back: the OS is asked to bring a window forward, and whether it did is not something Electron answers.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>path</code></td><td><code>string</code><br>A file in the Trilium data or tmp directory, or the database file.</td></tr></tbody></table></figure></td></tr><tr><td><code>openFileUrl</code></td><td><pre><code class=\"language-application-typescript\">openFileUrl(fileUrl: string): Promise<string></code></pre><p>Opens a <code>file://</code> URL with its default OS handler. Exists as a separate channel from <code>openExternal</code> because neither Electron API opens every target correctly on Windows: <code>shell.openExternal</code> mishandles Unicode characters in <code>file:</code> URLs, while <code>shell.openPath</code> opens a directory with the Explorer-specific <code>explore</code> verb, bypassing the user's file manager. The main process picks between them per target.</p><p><strong>Security:</strong> the URL must use the <code>file:</code> scheme and must have an empty hostname. UNC paths (<code>file://attacker.example/share/x</code>) are explicitly blocked because Windows would otherwise resolve them to <code>\\\\attacker.example\\share\\x</code> and leak the user's NTLM hash via SMB authentication. Drive-letter-as-host malformations like <code>file://C:/path</code> are normalized to <code>file:///C:/path</code> before parsing.</p><p>Note: unlike <code>openPath</code>, the resolved path is NOT confined to the Trilium data / tmp directories — this channel handles user-clicked <code>file://</code> links inside note content, which routinely reference arbitrary locations on disk (<code>file:///C:/Users/me/Documents/contract.pdf</code> and similar). Equivalent to a browser following a <code>file:</code> link the user clicked. Treat clicks on attacker-influenced note content accordingly.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>fileUrl</code></td><td><code>string</code><br>A <code>file:</code> URL with an empty hostname.</td></tr></tbody></table></figure><p><strong>Returns</strong> <code>Promise<string></code>: An empty string on success, or an error message on failure.</p></td></tr><tr><td><code>downloadURL</code></td><td><pre><code class=\"language-application-typescript\">downloadURL(url: string): void</code></pre><p>Triggers a Chromium download for the given URL — the file is saved through the normal \"Save As\" flow instead of being opened in the renderer.</p><p><strong>Security:</strong> locked to the renderer's own origin. The scheme, hostname, and port must all match the running app's origin (<code>http://localhost:PORT</code> for the dev server, or the custom <code>trilium-app://app/</code> protocol for packaged Electron). Cross-origin downloads, hostless URLs (<code>data:</code>, <code>blob:</code>, <code>about:</code>, plain <code>file:///</code>), and unparseable URLs are rejected. This stops a compromised renderer from pre-positioning a remote payload in the user's Downloads folder under a familiar name.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>url</code></td><td><code>string</code><br>A URL on the app's own origin.</td></tr></tbody></table></figure></td></tr><tr><td><code>openCustom</code></td><td><pre><code class=\"language-application-typescript\">openCustom(filePath: string): void</code></pre><p>Opens a file with a Trilium-specific custom handler (configured via the \"Open With\" option), falling back to the OS default if none is set.</p><p><strong>Security:</strong> the path must resolve to a strict descendant of Trilium's tmp directory and the file must exist on disk. The legitimate caller always passes a path that was just written by <code>saveToTmpDir</code>; anything else (the data dir itself, paths elsewhere on disk, null bytes, empty strings) is rejected.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>filePath</code></td><td><code>string</code><br>A file in Trilium's tmp directory, as written by <code>saveToTmpDir</code>.</td></tr></tbody></table></figure></td></tr></tbody></table></figure><h2><code>ElectronContextMenuApi</code></h2><p>Bridge for the native context menu shown over web contents.</p><figure class=\"table\"><table><thead><tr><th>Member</th><th>Description</th></tr></thead><tbody><tr><td><code>onContextMenu</code></td><td><pre><code class=\"language-application-typescript\">onContextMenu(callback: (params: ElectronContextMenuParams) => void): void</code></pre><p>Subscribes to right-click events forwarded from the main process.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>callback</code></td><td><code>(params: ElectronContextMenuParams) => void</code><br>Receives where the user clicked and what is under the cursor.</td></tr></tbody></table></figure></td></tr><tr><td><code>webContentsAction</code></td><td><pre><code class=\"language-application-typescript\">webContentsAction(action: \"cut\" | \"copy\" | \"paste\" | \"pasteAndMatchStyle\" | \"insertText\", text?: string): void</code></pre><p>Executes a clipboard / text-input action on the focused web contents.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>action</code></td><td><code>\"cut\" | \"copy\" | \"paste\" | \"pasteAndMatchStyle\" | \"insertText\"</code><br>The action to execute.</td></tr><tr><td><code>text</code><br><em>optional</em></td><td><code>string</code><br>The text to insert. <code>\"insertText\"</code> requires it; the other actions ignore it.</td></tr></tbody></table></figure></td></tr></tbody></table></figure><h2><code>ElectronSpellcheckApi</code></h2><p>Renderer-side access to Chromium's built-in spell checker.</p><figure class=\"table\"><table><thead><tr><th>Member</th><th>Description</th></tr></thead><tbody><tr><td><code>addWordToDictionary</code></td><td><pre><code class=\"language-application-typescript\">addWordToDictionary(word: string): void</code></pre><p>Adds a word to the user's personal dictionary so it is no longer flagged.</p></td></tr><tr><td><code>getAvailableSpellCheckerLanguages</code></td><td><pre><code class=\"language-application-typescript\">getAvailableSpellCheckerLanguages(): string[]</code></pre><p>Returns the BCP-47 language tags Chromium can spell-check on this platform.</p></td></tr><tr><td><code>setSpellCheckerLanguages</code></td><td><pre><code class=\"language-application-typescript\">setSpellCheckerLanguages(languageCodes: string[]): void</code></pre><p>Applies the spell-check language list to every open window's session immediately, without an application restart. No-op on macOS, where the OS spell checker auto-detects the language.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>languageCodes</code></td><td><code>string[]</code><br>Language tags returned by <code>getAvailableSpellCheckerLanguages</code>.</td></tr></tbody></table></figure></td></tr><tr><td><code>setSpellCheckerEnabled</code></td><td><pre><code class=\"language-application-typescript\">setSpellCheckerEnabled(enabled: boolean): void</code></pre><p>Enables or disables the built-in spell checker on every open window's session immediately, without an application restart.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>enabled</code></td><td><code>boolean</code><br><code>true</code> to enable the spell checker, <code>false</code> to disable it.</td></tr></tbody></table></figure></td></tr></tbody></table></figure><h2><code>ElectronSystemIntegrationApi</code></h2><p>OS integration controls — system tray and autostart / launch-on-login.</p><figure class=\"table\"><table><thead><tr><th>Member</th><th>Description</th></tr></thead><tbody><tr><td><code>reloadTray</code></td><td><pre><code class=\"language-application-typescript\">reloadTray(): void</code></pre><p>Rebuilds the tray icon and menu — call after changing tray-related settings.</p></td></tr><tr><td><code>reapplyLaunchOnStartup</code></td><td><pre><code class=\"language-application-typescript\">reapplyLaunchOnStartup(): void</code></pre><p>Re-applies the OS autostart entry after the <code>launchOnStartup</code> / <code>hideOnAutoStart</code> options change.</p></td></tr></tbody></table></figure><h2><code>ElectronPrintingApi</code></h2><p>Printing and PDF export flow. Trilium drives Electron's printing pipeline through a small state machine that the main process owns, with progress and results pushed back to the renderer via IPC events.</p><figure class=\"table\"><table><thead><tr><th>Member</th><th>Description</th></tr></thead><tbody><tr><td><code>sendPrintProgress</code></td><td><pre><code class=\"language-application-typescript\">sendPrintProgress(progress: number): void</code></pre><p>Reports rendering progress from the renderer to the main process.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>progress</code></td><td><code>number</code><br>The percentage rendered, from 0 to 100.</td></tr></tbody></table></figure></td></tr><tr><td><code>onPrintProgress</code></td><td><pre><code class=\"language-application-typescript\">onPrintProgress(callback: (data: { progress: number; action: string }) => void): void</code></pre><p>Subscribes to progress updates emitted by the main process during a print or PDF export run.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>callback</code></td><td><code>(data: { progress: number; action: string }) => void</code><br>Receives the percentage done and the current stage, such as <code>\"rendering\"</code>.</td></tr></tbody></table></figure></td></tr><tr><td><code>onPrintDone</code></td><td><pre><code class=\"language-application-typescript\">onPrintDone(callback: (printReport: unknown, liveJobId?: number) => void): void</code></pre><p>Subscribes to the \"print finished\" event, fired once the OS print job is dispatched.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>callback</code></td><td><code>(printReport: unknown, liveJobId?: number) => void</code><br>Receives the main process's report on the job, or an error with a <code>message</code>, and, for a job that printed the app window itself, the ID of the live print the job ended.</td></tr></tbody></table></figure></td></tr><tr><td><code>removePrintListeners</code></td><td><pre><code class=\"language-application-typescript\">removePrintListeners(): void</code></pre><p>Removes all listeners registered via <code>onPrintProgress</code> and <code>onPrintDone</code>.</p></td></tr><tr><td><code>getPrinters</code></td><td><pre><code class=\"language-application-typescript\">getPrinters(): Promise<unknown[]></code></pre><p>Returns the list of printers known to the OS.</p></td></tr><tr><td><code>exportAsPdfPreview</code></td><td><pre><code class=\"language-application-typescript\">exportAsPdfPreview(opts: Record<string, unknown>): void</code></pre><p>Asks the main process to render the current note as a PDF and return the resulting bytes for the in-app preview. Result is delivered via <code>onExportAsPdfPreviewResult</code>.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>opts</code></td><td><code>Record<string, unknown></code><br>The note path, the page size, orientation, scale, margins and page ranges, and a <code>requestId</code> the result echoes back.</td></tr></tbody></table></figure></td></tr><tr><td><code>onExportAsPdfPreviewResult</code></td><td><pre><code class=\"language-application-typescript\">onExportAsPdfPreviewResult(callback: (result: { buffer?: Uint8Array<ArrayBufferLike>; error?: string; requestId?: number }) => void): void</code></pre><p>Subscribes to the result of an <code>exportAsPdfPreview</code> call.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>callback</code></td><td><code>(result: { buffer?: Uint8Array<ArrayBufferLike>; error?: string; requestId?: number }) => void</code><br>Receives the PDF bytes or an error message, and the <code>requestId</code> of the call the result answers.</td></tr></tbody></table></figure></td></tr><tr><td><code>removeExportAsPdfPreviewResultListener</code></td><td><pre><code class=\"language-application-typescript\">removeExportAsPdfPreviewResultListener(): void</code></pre><p>Removes the listener registered via <code>onExportAsPdfPreviewResult</code>.</p></td></tr><tr><td><code>savePdf</code></td><td><pre><code class=\"language-application-typescript\">savePdf(data: { title: string; buffer: Uint8Array }): void</code></pre><p>Persists a previously generated PDF buffer to disk via the native save dialog.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>data</code></td><td><code>{ title: string; buffer: Uint8Array }</code><br>The PDF bytes, and the title to suggest as the file name.</td></tr></tbody></table></figure></td></tr><tr><td><code>printFromPreview</code></td><td><pre><code class=\"language-application-typescript\">printFromPreview(opts: Record<string, unknown>): void</code></pre><p>Sends the previewed PDF to the OS print dialog with the given options.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>opts</code></td><td><code>Record<string, unknown></code><br>The options of <code>exportAsPdfPreview</code>, plus <code>silent</code> to print without the dialog and <code>deviceName</code> to choose the printer.</td></tr></tbody></table></figure></td></tr></tbody></table></figure><h2><code>ElectronNavigationApi</code></h2><p>Accessors for the underlying Chromium navigation history of the current web contents (back/forward stack), exposed so the renderer can mirror it in custom UI such as the breadcrumb / tab back button.</p><figure class=\"table\"><table><thead><tr><th>Member</th><th>Description</th></tr></thead><tbody><tr><td><code>clearNavigationHistory</code></td><td><pre><code class=\"language-application-typescript\">clearNavigationHistory(): void</code></pre><p>Clears the entire back/forward navigation history.</p></td></tr><tr><td><code>navigationCanGoBack</code></td><td><pre><code class=\"language-application-typescript\">navigationCanGoBack(): boolean</code></pre><p>Synchronously returns whether a back navigation is possible.</p></td></tr><tr><td><code>navigationCanGoForward</code></td><td><pre><code class=\"language-application-typescript\">navigationCanGoForward(): boolean</code></pre><p>Synchronously returns whether a forward navigation is possible.</p></td></tr><tr><td><code>navigationGetAllEntries</code></td><td><pre><code class=\"language-application-typescript\">navigationGetAllEntries(): { url: string; title: string }[]</code></pre><p>Returns every entry in the navigation history, oldest first.</p></td></tr><tr><td><code>navigationGetActiveIndex</code></td><td><pre><code class=\"language-application-typescript\">navigationGetActiveIndex(): number</code></pre><p>Returns the index of the currently active entry inside <code>navigationGetAllEntries</code>.</p></td></tr><tr><td><code>navigationLength</code></td><td><pre><code class=\"language-application-typescript\">navigationLength(): number</code></pre><p>Returns the total number of entries in the navigation history.</p></td></tr><tr><td><code>navigationGoToIndex</code></td><td><pre><code class=\"language-application-typescript\">navigationGoToIndex(index: number): void</code></pre><p>Navigates to the entry at the given index in the history stack.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>index</code></td><td><code>number</code><br>An index into <code>navigationGetAllEntries</code>.</td></tr></tbody></table></figure></td></tr><tr><td><code>onDidNavigate</code></td><td><pre><code class=\"language-application-typescript\">onDidNavigate(callback: () => void): void</code></pre><p>Subscribes to top-level navigation events (URL changes that load a new document).</p></td></tr><tr><td><code>onDidNavigateInPage</code></td><td><pre><code class=\"language-application-typescript\">onDidNavigateInPage(callback: () => void): void</code></pre><p>Subscribes to in-page navigation events (hash changes, <code>history.pushState</code>).</p></td></tr><tr><td><code>removeDidNavigateListeners</code></td><td><pre><code class=\"language-application-typescript\">removeDidNavigateListeners(): void</code></pre><p>Removes all listeners registered via <code>onDidNavigate</code> and <code>onDidNavigateInPage</code>.</p></td></tr></tbody></table></figure><h2><code>ElectronWsApi</code></h2><p>In-process replacement for the renderer↔server WebSocket. Backed by Chromium IPC instead of a TCP socket — no port is bound and no auth check is needed because the channel is only reachable from the renderer the BrowserWindow owns. Wire format is whatever the server's <code>MessagingProvider</code> accepts (currently <code>WebSocketMessage</code> / log-error / log-info / ping).</p><figure class=\"table\"><table><thead><tr><th>Member</th><th>Description</th></tr></thead><tbody><tr><td><code>send</code></td><td><pre><code class=\"language-application-typescript\">send(message: unknown): void</code></pre><p>Sends a message from the renderer to the main-process messaging hub.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>message</code></td><td><code>unknown</code><br>A message the server's <code>MessagingProvider</code> accepts.</td></tr></tbody></table></figure></td></tr><tr><td><code>onMessage</code></td><td><pre><code class=\"language-application-typescript\">onMessage(callback: (message: unknown) => void): () => void</code></pre><p>Subscribes to messages pushed from the main process.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>callback</code></td><td><code>(message: unknown) => void</code><br>Receives each message.</td></tr></tbody></table></figure><p><strong>Returns</strong> <code>() => void</code>: An unsubscribe function. Call it when the listener is no longer needed (e.g. when a BrowserWindow is unloaded) to avoid leaking handlers.</p></td></tr></tbody></table></figure><h2><code>ElectronSecurityApi</code></h2><p>Security settings that live outside the database (in <code>data_dir/security.json</code>) to prevent malicious scripts from modifying them. Changes require a native OS confirmation dialog and an app restart to take effect.</p><figure class=\"table\"><table><thead><tr><th>Member</th><th>Description</th></tr></thead><tbody><tr><td><code>setLanAccessEnabled</code></td><td><pre><code class=\"language-application-typescript\">setLanAccessEnabled(enabled: boolean): Promise<boolean></code></pre><p>Requests enabling/disabling LAN access. When enabled, the desktop binds its TCP listener to all interfaces (instead of loopback) so other devices can reach it — e.g. to sync from another device. Same confirmation + restart flow as above.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>enabled</code></td><td><code>boolean</code><br><code>true</code> to listen on all interfaces, <code>false</code> to listen on loopback only.</td></tr></tbody></table></figure><p><strong>Returns</strong> <code>Promise<boolean></code>: <code>true</code> once the user agreed and the change was written.</p></td></tr><tr><td><code>setBackendScriptingEnabled</code></td><td><pre><code class=\"language-application-typescript\">setBackendScriptingEnabled(enabled: boolean): Promise<boolean></code></pre><p>Requests backend script execution be turned on or off.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>enabled</code></td><td><code>boolean</code><br><code>true</code> to allow backend scripts to run, <code>false</code> to block them.</td></tr></tbody></table></figure></td></tr><tr><td><code>setSqlConsoleEnabled</code></td><td><pre><code class=\"language-application-typescript\">setSqlConsoleEnabled(enabled: boolean): Promise<boolean></code></pre><p>Requests the SQL console be turned on or off.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>enabled</code></td><td><code>boolean</code><br><code>true</code> to enable the SQL console, <code>false</code> to disable it.</td></tr></tbody></table></figure></td></tr></tbody></table></figure><h2><code>ElectronBackupPassphraseApi</code></h2><p>The backup passphrase, kept encrypted by the OS keyring in a file outside the database (the database is what ends up inside the backup, so a passphrase stored there would ride along inside the very container it protects).</p><p>Deliberately write-only: there is no way to read the passphrase back, so a frontend script cannot exfiltrate it. Only the main process ever sees the plaintext again, when it writes a backup.</p><p>Both changes are also gated on a native OS confirmation, which a script can request but cannot answer. Without that, a script could quietly swap in a passphrase of its own and every later backup would be encrypted to it.</p><figure class=\"table\"><table><thead><tr><th>Member</th><th>Description</th></tr></thead><tbody><tr><td><code>getStatus</code></td><td><pre><code class=\"language-application-typescript\">getStatus(): Promise<BackupPassphraseStatus></code></pre><p>Whether a passphrase can be stored on this system, and whether one already is.</p></td></tr><tr><td><code>set</code></td><td><pre><code class=\"language-application-typescript\">set(passphrase: string): Promise<BackupPassphraseChange></code></pre><p>Stores a passphrase, replacing any existing one, once the user has confirmed it.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>passphrase</code></td><td><code>string</code><br>The passphrase to encrypt later backups with.</td></tr></tbody></table></figure></td></tr><tr><td><code>clear</code></td><td><pre><code class=\"language-application-typescript\">clear(): Promise<BackupPassphraseChange></code></pre><p>Forgets the stored passphrase. Existing backups keep the passphrase they were written with.</p></td></tr></tbody></table></figure><h2><code>ElectronOneNoteApi</code></h2><p>Desktop-only OneNote importer sign-in, driven from the main process via a loopback OAuth redirect.</p><figure class=\"table\"><table><thead><tr><th>Member</th><th>Description</th></tr></thead><tbody><tr><td><code>login</code></td><td><pre><code class=\"language-application-typescript\">login(): Promise<OneNoteLoginResult></code></pre><p>Runs the Microsoft delegated-Graph OAuth flow: opens the system browser, captures the redirect on a throwaway loopback server, exchanges the code, and stores the token process-side. Resolves once the desktop session is connected (or with <code>connected: false</code> on failure/timeout).</p></td></tr></tbody></table></figure><h2><code>ElectronNativeExportApi</code></h2><p>Desktop-native subtree export that streams a <code>.zip</code> straight to a file.</p><figure class=\"table\"><table><thead><tr><th>Member</th><th>Description</th></tr></thead><tbody><tr><td><code>exportSubtreeToFile</code></td><td><pre><code class=\"language-application-typescript\">exportSubtreeToFile(opts: { branchId: string; format: string; title: string; taskId: string }): Promise<NativeExportResult></code></pre><p>Prompts a native \"save as\" dialog, then streams a subtree (branch) export to the chosen path on disk. This bypasses the in-memory download path, so memory stays bounded regardless of archive size. Progress/success/error are reported over the WebSocket via <code>taskId</code>. Resolves once the dialog is dismissed (<code>cancelled</code>) or the export finishes (<code>saved</code> / <code>error</code>).</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>opts</code></td><td><code>{ branchId: string; format: string; title: string; taskId: string }</code><br>The branch to export, the export format (<code>\"html\"</code>, <code>\"markdown\"</code> or <code>\"share\"</code>), the title to suggest as the file name, and the ID of the task that reports progress.</td></tr></tbody></table></figure></td></tr></tbody></table></figure><h2><code>ElectronNativeImportApi</code></h2><p>Desktop-native import that reads the user's file <strong>in place</strong> (bounded memory, no temp copy) — the whole point being multi-GB <code>.zip</code> archives, though any importable file is accepted. The renderer never handles a filesystem path: <code>pickFiles</code> runs the OS dialog in the main process and returns opaque capability tokens, which <code>importFromToken</code> redeems. A script can't forge a token or pass a path, so it can never read an arbitrary file.</p><figure class=\"table\"><table><thead><tr><th>Member</th><th>Description</th></tr></thead><tbody><tr><td><code>pickFiles</code></td><td><pre><code class=\"language-application-typescript\">pickFiles(): Promise<NativeImportPickResult></code></pre><p>Prompts a native \"open file\" dialog (multi-select, any type) and returns single-use tokens for the chosen files.</p></td></tr><tr><td><code>grantDroppedFiles</code></td><td><pre><code class=\"language-application-typescript\">grantDroppedFiles(files: File[]): Promise<NativeImportPickResult></code></pre><p>Resolves files the user dropped onto a drop zone to capability tokens, so a drag-and-drop import takes the same in-place (streamed) path as the dialog. The <code>File</code> is the unforgeable capability: the path is obtained via <code>webUtils.getPathForFile</code>, which yields a real path only for a genuinely user-supplied file and an empty string for anything a script constructed — so a script can't smuggle in an arbitrary path. Returns <code>cancelled</code> when no dropped file resolved (e.g. dragged from a browser, not the OS), so the caller falls back to the normal upload route.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>files</code></td><td><code>File[]</code><br>The files of the drop event.</td></tr></tbody></table></figure></td></tr><tr><td><code>importFromToken</code></td><td><pre><code class=\"language-application-typescript\">importFromToken(opts: { token: string; parentNoteId: string; taskId: string; options: NativeImportOptions; last: boolean; format?: string }): Promise<NativeImportResult></code></pre><p>Imports the file behind a token, with progress/success/error reported over the WebSocket like the HTTP import path.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>opts</code></td><td><code>{ token: string; parentNoteId: string; taskId: string; options: NativeImportOptions; last: boolean; format?: string }</code><br>The <code>token</code> to redeem, the <code>parentNoteId</code> to import under, the <code>taskId</code> that reports progress, and the import <code>options</code>. When importing several files in one batch, set <code>last</code> only on the final call so the success toast fires once, after everything is in. <code>format</code> routes the file to a specific importer (e.g. <code>\"obsidian\"</code>), mirroring the HTTP route's format tag.</td></tr></tbody></table></figure></td></tr></tbody></table></figure><h2><code>ElectronDialogApi</code></h2><p>Native OS pickers that hand the renderer a location the user chose themselves.</p><figure class=\"table\"><table><thead><tr><th>Member</th><th>Description</th></tr></thead><tbody><tr><td><code>pickDirectory</code></td><td><pre><code class=\"language-application-typescript\">pickDirectory(opts?: { defaultPath?: string }): Promise<NativeDirectoryPickResult></code></pre><p>Prompts a native \"select folder\" dialog. The renderer cannot supply the answer: a script can at most pop the dialog, which the user still has to accept before any path comes back.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>opts</code><br><em>optional</em></td><td><code>{ defaultPath?: string }</code><br>The directory the dialog starts in, as <code>defaultPath</code>.</td></tr></tbody></table></figure></td></tr><tr><td><code>confirmStartOver</code></td><td><pre><code class=\"language-application-typescript\">confirmStartOver(): Promise<boolean></code></pre><p>Prompts a native message box before the application restarts into the setup screen, where the user may replace or erase their knowledge base.</p><p>An OS dialog rather than one of the application's own, for the reason the security toggles use one: a note script can reach every dialog the app draws for itself, and this one guards the path to losing everything. It is never suppressible, so there is no \"don't ask again\" here.</p></td></tr></tbody></table></figure><h2><code>ElectronRestoreApi</code></h2><p>Choosing a backup to restore from the desktop, where the file is already on the same disk as the database it is going to replace and has no business being uploaded to reach it.</p><p>Only usable during setup: what it puts forward is restored by the ordinary <code>POST /api/setup/restore/start</code>, which refuses once the application is initialized.</p><figure class=\"table\"><table><thead><tr><th>Member</th><th>Description</th></tr></thead><tbody><tr><td><code>pickBackup</code></td><td><pre><code class=\"language-application-typescript\">pickBackup(): Promise<NativeBackupPickResult></code></pre><p>Prompts a native \"open file\" dialog for a <code>.db</code> or <code>.tnbackup</code> backup and, if one is chosen, makes it the backup waiting to be restored.</p></td></tr></tbody></table></figure><h2><code>ElectronTranscriptionApi</code></h2><p>Meeting transcription, recorded and transcribed on this computer by the main process. The renderer only starts and stops it; the audio never passes through the renderer.</p><figure class=\"table\"><table><thead><tr><th>Member</th><th>Description</th></tr></thead><tbody><tr><td><code>isSupported</code></td><td><pre><code class=\"language-application-typescript\">isSupported(): Promise<boolean></code></pre><p>Whether this build can transcribe on this computer: <code>false</code> when it carries no speech recognition engine for the platform and processor it runs on.</p></td></tr><tr><td><code>start</code></td><td><pre><code class=\"language-application-typescript\">start(noteId: string): Promise<string></code></pre><p>Starts recording the microphone and the system audio for a meeting note.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>noteId</code></td><td><code>string</code><br>The meeting note the transcript belongs to.</td></tr></tbody></table></figure><p><strong>Returns</strong> <code>Promise<string></code>: An empty string once recording runs, or an error message when it cannot start.</p></td></tr><tr><td><code>stop</code></td><td><pre><code class=\"language-application-typescript\">stop(): Promise<void></code></pre><p>Stops the recording, once the speech already captured has been transcribed.</p></td></tr><tr><td><code>getState</code></td><td><pre><code class=\"language-application-typescript\">getState(): Promise<TranscriptionState></code></pre></td></tr><tr><td><code>renameSpeaker</code></td><td><pre><code class=\"language-application-typescript\">renameSpeaker(attachmentId: string, key: string, name: string): Promise<boolean></code></pre><p>Names a speaker of a transcript attachment, if a running recording writes that transcript. The recording applies it, so no utterance it writes meanwhile is lost.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>attachmentId</code></td><td><code>string</code><br>The transcript attachment.</td></tr><tr><td><code>key</code></td><td><code>string</code><br>The speaker: <code>microphone</code> for the local speaker, <code>system:<n></code> for an identified speaker of the system audio.</td></tr><tr><td><code>name</code></td><td><code>string</code><br>The name to give, or a blank string to restore the default name.</td></tr></tbody></table></figure><p><strong>Returns</strong> <code>Promise<boolean></code>: <code>false</code> when no recording writes <code>attachmentId</code>; it can then be saved whole.</p></td></tr><tr><td><code>getRecordingsDirectory</code></td><td><pre><code class=\"language-application-typescript\">getRecordingsDirectory(): Promise<string></code></pre><p>Returns the directory that keeps the audio and the transcript as produced of each recording while <code>transcriptionKeepRecordings</code> is on, creating it if needed.</p></td></tr><tr><td><code>onStateChanged</code></td><td><pre><code class=\"language-application-typescript\">onStateChanged(callback: (state: TranscriptionState) => void): () => void</code></pre><p>Subscribes to changes of the transcription state, made from any window.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>callback</code></td><td><code>(state: TranscriptionState) => void</code><br>Receives the new state.</td></tr></tbody></table></figure><p><strong>Returns</strong> <code>() => void</code>: A function that removes the listener.</p></td></tr><tr><td><code>onLevel</code></td><td><pre><code class=\"language-application-typescript\">onLevel(callback: (source: TranscriptSource, level: number) => void): () => void</code></pre><p>Subscribes to the audio level of the running recording, about four times a second per source.</p><figure class=\"table\"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>callback</code></td><td><code>(source: TranscriptSource, level: number) => void</code><br>Receives the source and the RMS, from 0 to 1, of each chunk it delivers.</td></tr></tbody></table></figure><p><strong>Returns</strong> <code>() => void</code>: A function that stops the calls.</p></td></tr></tbody></table></figure><h2>Types</h2><h3><code>ElectronContextMenuParams</code></h3><p>Parameters delivered by the main process to the renderer when the user opens the system context menu (right-click) somewhere inside a web view.</p><p>Mirrors the subset of fields from Electron's <code>Electron.ContextMenuParams</code> that the renderer actually consumes when building its custom context menu.</p><figure class=\"table\"><table><thead><tr><th>Property</th><th>Description</th></tr></thead><tbody><tr><td><code>x</code></td><td><code>number</code> <br>Horizontal position of the click, in CSS pixels, relative to the web view.</td></tr><tr><td><code>y</code></td><td><code>number</code> <br>Vertical position of the click, in CSS pixels, relative to the web view.</td></tr><tr><td><code>linkURL</code></td><td><code>string</code> <br>URL of the link the user clicked on, or an empty string if not on a link.</td></tr><tr><td><code>linkText</code></td><td><code>string</code> <br>Visible text of the link the user clicked on, or an empty string.</td></tr><tr><td><code>mediaType</code></td><td><code>string</code> <br>Media kind under the cursor (e.g. <code>\"none\"</code>, <code>\"image\"</code>, <code>\"video\"</code>, <code>\"audio\"</code>).</td></tr><tr><td><code>isEditable</code></td><td><code>boolean</code> <br>Whether the element under the cursor is editable (input, textarea, contenteditable).</td></tr><tr><td><code>selectionText</code></td><td><code>string</code> <br>Currently selected text, or an empty string if nothing is selected.</td></tr><tr><td><code>misspelledWord</code></td><td><code>string</code> <br>The misspelled word under the cursor, or an empty string if none.</td></tr><tr><td><code>dictionarySuggestions</code></td><td><code>string[]</code> <br>Spell-check suggestions for <code>misspelledWord</code>, in order of relevance.</td></tr><tr><td><code>editFlags</code></td><td><code>{ canCut: boolean; canCopy: boolean; canPaste: boolean }</code> <br>Hints about which clipboard operations are currently available.</td></tr></tbody></table></figure><h3><code>BackupPassphraseStatus</code></h3><p>What the Options UI needs to know about the stored backup passphrase.</p><figure class=\"table\"><table><thead><tr><th>Property</th><th>Description</th></tr></thead><tbody><tr><td><code>available</code></td><td><code>boolean</code> <br>Whether the OS offers a keyring to keep the passphrase in. Without one it cannot be stored safely, and since unattended backups cannot ask for it, encryption is unavailable altogether.</td></tr><tr><td><code>set</code></td><td><code>boolean</code> <br>Whether a passphrase is currently stored.</td></tr></tbody></table></figure><h3><code>BackupPassphraseChange</code></h3><p>What became of a request to change the stored backup passphrase.</p><figure class=\"table\"><table><thead><tr><th>Value</th><th>Description</th></tr></thead><tbody><tr><td><code>\"applied\"</code></td><td>The change was confirmed and carried out.</td></tr><tr><td><code>\"cancelled\"</code></td><td>The user declined the OS confirmation, so nothing changed.</td></tr><tr><td><code>\"unavailable\"</code></td><td>There is no keyring on this system to keep a passphrase in.</td></tr></tbody></table></figure><h3><code>OneNoteLoginResult</code></h3><p>Outcome of a <code>ElectronOneNoteApi.login</code> attempt.</p><figure class=\"table\"><table><thead><tr><th>Property</th><th>Description</th></tr></thead><tbody><tr><td><code>connected</code></td><td><code>boolean</code> <br>True if sign-in completed and a Microsoft Graph token was stored.</td></tr><tr><td><code>account</code> <br><em>optional</em></td><td><code>{ name: string; email: string }</code> <br>The connected Microsoft account, present when <code>connected</code> is true.</td></tr><tr><td><code>error</code> <br><em>optional</em></td><td><code>string</code> <br>A human-readable failure reason when <code>connected</code> is false (absent on user cancellation).</td></tr></tbody></table></figure><h3><code>NativeExportResult</code></h3><p>Outcome of a <code>ElectronNativeExportApi.exportSubtreeToFile</code> request.</p><figure class=\"table\"><table><thead><tr><th>Property</th><th>Description</th></tr></thead><tbody><tr><td><code>status</code></td><td><code>\"cancelled\" | \"saved\" | \"error\"</code></td></tr><tr><td><code>filePath</code> <br><em>optional</em></td><td><code>string</code> <br>Absolute path the archive was written to (when <code>status === \"saved\"</code>).</td></tr><tr><td><code>message</code> <br><em>optional</em></td><td><code>string</code> <br>Failure detail (when <code>status === \"error\"</code>).</td></tr></tbody></table></figure><h3><code>NativeImportPickResult</code></h3><p>Outcome of <code>ElectronNativeImportApi.pickFiles</code>: capability tokens, never paths.</p><figure class=\"table\"><table><thead><tr><th>Property</th><th>Description</th></tr></thead><tbody><tr><td><code>status</code></td><td><code>\"cancelled\" | \"selected\"</code></td></tr><tr><td><code>files</code> <br><em>optional</em></td><td><code>NativeImportPickedFile[]</code> <br>The user-chosen files (when <code>status === \"selected\"</code>); one or more, since the dialog allows multi-select.</td></tr></tbody></table></figure><h3><code>NativeImportOptions</code></h3><p>Import flags forwarded to the native importer (mirrors the HTTP route's options; no path).</p><figure class=\"table\"><table><thead><tr><th>Property</th><th>Description</th></tr></thead><tbody><tr><td><code>safeImport</code></td><td><code>boolean</code></td></tr><tr><td><code>shrinkImages</code></td><td><code>boolean</code></td></tr><tr><td><code>textImportedAsText</code></td><td><code>boolean</code></td></tr><tr><td><code>codeImportedAsCode</code></td><td><code>boolean</code></td></tr><tr><td><code>spreadsheetImportedAsSpreadsheet</code></td><td><code>boolean</code></td></tr><tr><td><code>explodeArchives</code></td><td><code>boolean</code></td></tr><tr><td><code>replaceUnderscoresWithSpaces</code></td><td><code>boolean</code></td></tr></tbody></table></figure><h3><code>NativeImportResult</code></h3><p>Outcome of <code>ElectronNativeImportApi.importFromToken</code>.</p><figure class=\"table\"><table><thead><tr><th>Property</th><th>Description</th></tr></thead><tbody><tr><td><code>status</code></td><td><code>\"error\" | \"imported\"</code></td></tr><tr><td><code>importedNoteId</code> <br><em>optional</em></td><td><code>string</code> <br>Root note of the import (when <code>status === \"imported\"</code>).</td></tr><tr><td><code>message</code> <br><em>optional</em></td><td><code>string</code> <br>Failure detail (when <code>status === \"error\"</code>).</td></tr></tbody></table></figure><h3><code>NativeDirectoryPickResult</code></h3><p>Outcome of <code>ElectronDialogApi.pickDirectory</code>.</p><figure class=\"table\"><table><thead><tr><th>Property</th><th>Description</th></tr></thead><tbody><tr><td><code>status</code></td><td><code>\"cancelled\" | \"selected\"</code></td></tr><tr><td><code>path</code> <br><em>optional</em></td><td><code>string</code> <br>Absolute path of the chosen directory (when <code>status === \"selected\"</code>).</td></tr></tbody></table></figure><h3><code>NativeBackupPickResult</code></h3><p>Outcome of <code>ElectronRestoreApi.pickBackup</code>: what the chosen backup is, never where it is.</p><p>The file itself stays with the main process, which holds it as the one waiting to be restored, so the renderer is given only what the screen has to show and decide with.</p><figure class=\"table\"><table><thead><tr><th>Property</th><th>Description</th></tr></thead><tbody><tr><td><code>status</code></td><td><code>\"cancelled\" | \"error\" | \"selected\"</code></td></tr><tr><td><code>fileName</code> <br><em>optional</em></td><td><code>string</code> <br>Display name of the chosen backup (when <code>status === \"selected\"</code>).</td></tr><tr><td><code>encrypted</code> <br><em>optional</em></td><td><code>boolean</code> <br>Whether a passphrase has to be asked for before it can be restored.</td></tr><tr><td><code>message</code> <br><em>optional</em></td><td><code>string</code> <br>Failure detail (when <code>status === \"error\"</code>), e.g. setup already being busy.</td></tr></tbody></table></figure><h3><code>TranscriptionState</code></h3><p>What <code>ElectronTranscriptionApi</code> reports to every window.</p><figure class=\"table\"><table><thead><tr><th>Property</th><th>Description</th></tr></thead><tbody><tr><td><code>status</code></td><td><code>\"idle\" | \"starting\" | \"recording\" | \"stopping\"</code> <br>Phase of the meeting transcription; at most one recording runs at a time.</td></tr><tr><td><code>noteId</code></td><td><code>string | null</code> <br>The meeting note the recording belongs to, or <code>null</code> when idle.</td></tr><tr><td><code>pendingSources</code></td><td><code>TranscriptSource[]</code> <br>The sources heard speaking, or whose speech is still being transcribed.</td></tr><tr><td><code>sourceIssues</code> <br><em>optional</em></td><td><code>Partial<Record<TranscriptSource, \"not_captured\" | \"no_audio\" | \"silent\">></code> <br>While recording, the sources whose audio is not being transcribed, and why; absent when every source delivers sound. <br>Why a source's audio is not being transcribed: its capture did not start (<code>not_captured</code>), it has delivered no audio for 10 s (<code>no_audio</code>), as when its capture hangs, or it has delivered only digital silence for a while (<code>silent</code>), as from a muted device.</td></tr><tr><td><code>startedAt</code> <br><em>optional</em></td><td><code>number</code> <br>When the recording started, in milliseconds since the epoch: set once it records, kept while it stops, absent otherwise.</td></tr><tr><td><code>error</code> <br><em>optional</em></td><td><code>string</code> <br>A problem to tell the user about, sent once with the state it concerns: the recording ended without being stopped, or its transcript cannot be saved. <code>getState()</code> never returns it.</td></tr></tbody></table></figure><h3><code>TranscriptSource</code></h3><p>Where an utterance was heard: the local speaker's microphone, or everyone else on the system output.</p><pre><code class=\"language-application-typescript\">type TranscriptSource = \"microphone\" | \"system\"</code></pre><h3><code>NativeImportPickedFile</code></h3><p>A single user-chosen file: a capability token (redeemed to import it) and its display name — never a path.</p><figure class=\"table\"><table><thead><tr><th>Property</th><th>Description</th></tr></thead><tbody><tr><td><code>token</code></td><td><code>string</code> <br>Single-use, short-lived grant for the chosen file.</td></tr><tr><td><code>fileName</code></td><td><code>string</code> <br>Display name of the chosen file.</td></tr></tbody></table></figure>","_help_ApVHZ8JY5ofC": "<p>Day.js is a date manipulation library that's used by Trilium, but it's also shared with both front-end and back-end scripts. For more information about the library itself, consult the <a href=\"https://day.js.org/en/\">official documentation</a>.</p><h2>How to use</h2><p>The <code>dayjs</code> method is provided directly in the <code>api</code> global:</p><pre><code class=\"language-text-javascript\">const date = api.dayjs();\napi.log(date.format(\"YYYY-MM-DD\"));</code></pre><h2>Plugins</h2><p>Day.js uses a modular, plugin-based architecture. Generally these plugins must be imported, but this process doesn't work inside Trilium scripts due to the use of a bundler.</p><p>Since v0.100.0, the same set of plugins is available for both front-end and back-end scripts.</p><p>The following Day.js plugins are directly integrated into Trilium:</p><ul><li><a href=\"https://day.js.org/docs/en/plugin/advanced-format\">AdvancedFormat</a></li><li><a href=\"https://day.js.org/docs/en/plugin/duration\">Duration</a>, since v0.100.0.</li><li><a href=\"https://day.js.org/docs/en/plugin/is-between\">IsBetween</a></li><li><a href=\"https://day.js.org/docs/en/plugin/iso-week\">IsoWeek</a></li><li><a href=\"https://day.js.org/docs/en/plugin/is-same-or-after\">IsSameOrAfter</a></li><li><a href=\"https://day.js.org/docs/en/plugin/is-same-or-before\">IsSameOrBefore</a></li><li><a href=\"https://day.js.org/docs/en/plugin/quarter-of-year\">QuarterOfYear</a></li><li><a href=\"https://day.js.org/docs/en/plugin/utc\">UTC</a></li></ul><aside class=\"admonition note\"><p>If another Day.js plugin might be needed for scripting purposes, feel free to open a feature request for it. Depending on the size of the plugin and the potential use of it inside the Trilium code base, it has a chance of being integrated.</p></aside>","_help_vElnKeDNPSVl": "<p>Both front-end and back-end notes can log messages for debugging.</p><h2>UI logging via <code>api.log</code></h2><figure class=\"image image-style-align-center image_resized\" style=\"width:57.74%;\"><img style=\"aspect-ratio:749/545;\" src=\"{{helpAssets}}/User%20Guide/Scripting/Logging_image.png\" width=\"749\" height=\"545\"></figure><p>The API log feature integrates with the script editor and it displays all the messages logged via <code>api.log</code>. This works for both back-end and front-end scripts.</p><p>The API log panel will appear at the bottom of a note (including in <a class=\"reference-link\" href=\"#root/_help_ZjLYv08Rp3qC\">Quick edit</a>) after executing a script that uses <code>api.log</code>. It can be dismissed temporarily by pressing the close button in the top-right of the panel.</p><p>Apart from strings, an object can be passed as well in which case it will be pretty-formatted if possible (e.g. recursive objects are not supported).</p><h2>Console logging</h2><p>For logs that are not directly visible to the user, the standard <code>console.log</code> can be used as well.</p><ul><li>For front-end scripts, the log will be shown in the Developer Tools (also known as Inspect).</li><li>For back-end scripts, the log will be shown in the server output while running but <strong>will not</strong> be visible in the <a class=\"reference-link\" href=\"#root/_help_bnyigUA2UK7s\">Backend (server) logs</a>.</li></ul>",diff --git a/apps/server/src/assets/help/help_meta.json b/apps/server/src/assets/help/help_meta.jsonindex 10a1420327..49b91f1265 100644--- a/apps/server/src/assets/help/help_meta.json+++ b/apps/server/src/assets/help/help_meta.json@@ -349,7 +349,7 @@{"id":"_help_Q2z6av6JZVWm","title":"Frontend API","type":"webView","attributes":[{"type":"label","name":"webViewSrc","value":"https://docs.triliumnotes.org/script-api/frontend"},{"type":"label","name":"docUrl","value":"https://docs.triliumnotes.org/user-guide/scripts/script-api/frontend-api"},{"type":"label","name":"iconClass","value":"bx bx-folder"}],"children":[{"id":"_help_habiZ3HU8Kw8","title":"FNote","type":"webView","attributes":[{"type":"label","name":"webViewSrc","value":"https://docs.triliumnotes.org/script-api/frontend/interfaces/FNote.html"},{"type":"label","name":"docUrl","value":"https://docs.triliumnotes.org/user-guide/scripts/script-api/frontend-api/fnote"},{"type":"label","name":"iconClass","value":"bx bx-file"}]}]},- {"id":"_help_MEtfsqa5VwNi","title":"Backend API","type":"webView","attributes":[{"type":"label","name":"webViewSrc","value":"https://docs.triliumnotes.org/script-api/backend"},{"type":"label","name":"docUrl","value":"https://docs.triliumnotes.org/user-guide/scripts/script-api/backend-api"},{"type":"label","name":"iconClass","value":"bx bx-file"}]},+ {"id":"_help_MEtfsqa5VwNi","title":"Backend API","type":"text","attributes":[{"type":"label","name":"fullContentWidth","value":""},{"type":"label","name":"docUrl","value":"https://docs.triliumnotes.org/user-guide/scripts/script-api/backend-api"},{"type":"label","name":"iconClass","value":"bx bx-server"}]},{"id":"_help_GFXVHyblVN3d","title":"Electron API","type":"text","attributes":[{"type":"label","name":"fullContentWidth","value":""},{"type":"label","name":"docUrl","value":"https://docs.triliumnotes.org/user-guide/scripts/script-api/electron-api"},{"type":"label","name":"iconClass","value":"bx bx-window-alt"}]},{"id":"_help_ApVHZ8JY5ofC","title":"Day.js","type":"text","attributes":[{"type":"label","name":"docUrl","value":"https://docs.triliumnotes.org/user-guide/scripts/script-api/day.js"},{"type":"label","name":"iconClass","value":"bx bx-calendar"}]}]},diff --git a/docs/Developer Guide/Developer Guide/Documentation.md b/docs/Developer Guide/Developer Guide/Documentation.mdindex 175ad47686..5fc4f6a14c 100644--- a/docs/Developer Guide/Developer Guide/Documentation.md+++ b/docs/Developer Guide/Developer Guide/Documentation.md@@ -66,26 +66,26 @@ The documentation is built via `apps/build-docs`:2. The User Guide and the Developer Guide are built.1. The documentation from the repo is archived and imported into an in-memory instance.2. The documentation is exported using the shared theme.-3. The frontend and backend script APIs are generated via `typedoc`.+3. The frontend script API is generated via `typedoc`.The `deploy-docs` workflow triggers the documentation build and uploads it to CloudFlare Pages.## Generated pages-The REST API references (ETAPI and the internal API) and the Electron API reference are User Guide pages whose Markdown is generated from their sources, so they appear both in the in-app help and on the website. `edit-docs-config.yaml` lists them for each documentation tree:+The REST API references (ETAPI and the internal API), the Electron API reference and the backend script API reference are User Guide pages whose Markdown is generated from their sources, so they appear both in the in-app help and on the website. `edit-docs-config.yaml` lists them for each documentation tree:* `openApiPages` renders an OpenAPI document (`apps/server/src/assets/etapi.openapi.yaml`, `apps/server/internal.openapi.yaml`), through `apps/edit-docs/src/openapi_markdown.ts`.-* `typeDocPages` renders the exports of a TypeScript module, as TypeDoc reads them, through `apps/edit-docs/src/typedoc_markdown.ts`. The Electron API page documents `packages/commons/src/lib/electron_api_interface.ts`, starting from `ElectronApi`; its introduction is the module's `@packageDocumentation` comment.+* `typeDocPages` renders the exports of a TypeScript module, as TypeDoc reads them, through `apps/edit-docs/src/typedoc_markdown.ts`. The Electron API page documents `packages/commons/src/lib/electron_api_interface.ts`, starting from `ElectronApi`; its introduction is the module's `@packageDocumentation` comment. The Backend API page documents `packages/commons/src/lib/script_api.ts`, the curated types that script notes' autocomplete also uses, starting from `BackendApi`. A page with a `root` shows only what the root reaches, so one module can hold the types of several pages.Both `pnpm edit-docs:sync-docs` and `pnpm edit-docs:edit-docs` regenerate these pages before importing the documentation, so any edit made to them directly is overwritten. To change one, edit its source (the OpenAPI document, or the comments of the TypeScript module), then run `pnpm edit-docs:sync-docs` and commit the regenerated page along with the help files.## Updating the Script API-As mentioned previously, the Script API is not manually editable since it is auto-generated using TypeDoc.+As mentioned previously, the frontend Script API is not manually editable since it is auto-generated using TypeDoc.-The frontend and backend Script API references are regenerated automatically as part of `pnpm docs:build` — their output goes into the gitignored `site/script-api/{backend,frontend}` directory and is published by the `deploy-docs` workflow, so there is nothing to commit. To preview changes locally, run `pnpm docs:build` and inspect the output under `site/`.+The frontend Script API reference is regenerated automatically as part of `pnpm docs:build` — its output goes into the gitignored `site/script-api/frontend` directory and is published by the `deploy-docs` workflow, so there is nothing to commit. To preview changes locally, run `pnpm docs:build` and inspect the output under `site/`.-Note that in order to simulate the environment a script would have, some fake source files (in the sense that they are only used for documentation) are being used as entrypoints for the documentation. Look for `backend_script_entrypoint` and `frontend_script_entrypoint` in `apps/build-docs/src`.+Note that in order to simulate the environment a script would have, a fake source file (in the sense that it is only used for documentation) is used as the entrypoint for the documentation. Look for `frontend_script_entrypoint` in `apps/build-docs/src`.## Building locallydiff --git a/docs/User Guide/!!!meta.json b/docs/User Guide/!!!meta.jsonindex 9b08447fef..47ab4ab2d6 100644--- a/docs/User Guide/!!!meta.json+++ b/docs/User Guide/!!!meta.json@@ -11989,25 +11989,33 @@"notePosition": 20,"prefix": null,"isExpanded": false,- "type": "webView",- "mime": "",+ "type": "text",+ "mime": "text/html","attributes": [{"type": "label",- "name": "webViewSrc",- "value": "/script-api/backend",+ "name": "shareAlias",+ "value": "backend-api","isInheritable": false,"position": 10},{"type": "label",- "name": "shareAlias",- "value": "backend-api",+ "name": "iconClass",+ "value": "bx bx-server","isInheritable": false,"position": 20+ },+ {+ "type": "label",+ "name": "fullContentWidth",+ "value": "",+ "isInheritable": false,+ "position": 30}],- "dataFileName": "Backend API.dat",+ "format": "markdown",+ "dataFileName": "Backend API.md","attachments": []},{diff --git a/docs/User Guide/User Guide.md b/docs/User Guide/User Guide.mdindex 04ad0c3c0a..b8459ddec7 100644--- a/docs/User Guide/User Guide.md+++ b/docs/User Guide/User Guide.md@@ -15,7 +15,7 @@ Trilium is an open-source solution for note-taking and organizing a personal kno* <a class="reference-link" href="User%20Guide/Installation%20%26%20Setup/Desktop%20Installation.md">Desktop Installation</a>* <a class="reference-link" href="User%20Guide/Installation%20%26%20Setup/Server%20Installation.md">Server Installation</a>-* <a class="reference-link" href="User%20Guide/Scripting/Script%20API/Frontend%20API">Frontend API</a> or <a class="reference-link" href="User%20Guide/Scripting/Script%20API/Backend%20API.dat">Backend API</a>+* <a class="reference-link" href="User%20Guide/Scripting/Script%20API/Frontend%20API">Frontend API</a> or <a class="reference-link" href="User%20Guide/Scripting/Script%20API/Backend%20API.md">Backend API</a>* [ETAPI reference](User%20Guide/Advanced%20Usage/ETAPI%20\(REST%20API\)/API%20Reference.md)## External linksdiff --git a/docs/User Guide/User Guide/Scripting/Backend scripts.md b/docs/User Guide/User Guide/Scripting/Backend scripts.mdindex c14c4ccf45..f4f37a2370 100644--- a/docs/User Guide/User Guide/Scripting/Backend scripts.md+++ b/docs/User Guide/User Guide/Scripting/Backend scripts.md@@ -26,4 +26,4 @@ In addition, scripts can be run automatically when the server starts up, on a fi## Script API-Trilium exposes a set of APIs that can be directly consumed by scripts, under the `api` object. For a reference of this API, see <a class="reference-link" href="Script%20API/Backend%20API.dat">Backend API</a>.\ No newline at end of file+Trilium exposes a set of APIs that can be directly consumed by scripts, under the `api` object. For a reference of this API, see <a class="reference-link" href="Script%20API/Backend%20API.md">Backend API</a>.\ No newline at end of filediff --git a/docs/User Guide/User Guide/Scripting/Script API.md b/docs/User Guide/User Guide/Scripting/Script API.mdindex cb470e28ef..bc61095dcd 100644--- a/docs/User Guide/User Guide/Scripting/Script API.md+++ b/docs/User Guide/User Guide/Scripting/Script API.md@@ -4,7 +4,7 @@ For [script code notes](../Scripting.md), Trilium offers an API that gives themThere are two APIs:* One for the front-end scripts: <a class="reference-link" href="Script%20API/Frontend%20API">Frontend API</a>-* One for the back-end scripts: <a class="reference-link" href="Script%20API/Backend%20API.dat">Backend API</a>+* One for the back-end scripts: <a class="reference-link" href="Script%20API/Backend%20API.md">Backend API</a>In both cases, the API resides in a global variable, `api`, that can be used anywhere in the script.diff --git a/docs/User Guide/User Guide/Scripting/Script API/Backend API.dat b/docs/User Guide/User Guide/Scripting/Script API/Backend API.datdeleted file mode 100644index e69de29bb2..0000000000diff --git a/docs/User Guide/User Guide/Scripting/Script API/Backend API.md b/docs/User Guide/User Guide/Scripting/Script API/Backend API.mdnew file mode 100644index 0000000000..256d0f2c19--- /dev/null+++ b/docs/User Guide/User Guide/Scripting/Script API/Backend API.md@@ -0,0 +1,1176 @@+# Backend API+## `BackendApi`++The `api` global available inside **backend** script notes (`application/javascript;env=backend`). Runs server-side: no DOM, no jQuery.++<table>+ <thead>+ <tr>+ <th>Member</th>+ <th>Description</th>+ </tr>+ </thead>+ <tbody>+ <tr>+ <td><code>startNote</code><br><em>optional</em></td>+ <td><p><code>ScriptBNote | null</code><br>Note where the script execution started — the entry point of the current script bundle (in C terms, the file containing <code>main()</code>). When a script is spread across multiple code notes (descendant code notes loaded as modules via <code>require()</code>), every note in the bundle shares the same <code>startNote</code>, while <code>currentNote</code> differs per note. Messages from <code>api.log()</code> are grouped under this note. When a frontend script calls <code>api.runOnBackend()</code>, the frontend's <code>startNote</code> is preserved here; since that note may not be resolvable on the backend, this can be null.</p></td>+ </tr>+ <tr>+ <td><code>currentNote</code></td>+ <td><p><code>ScriptBNote</code><br>Note containing the source code that is currently executing (in C terms, <code>__FILE__</code>). Equal to <code>startNote</code> unless execution has moved into a descendant module note loaded via <code>require()</code>. Don't confuse this with the concept of the active note in the UI.</p></td>+ </tr>+ <tr>+ <td><code>originEntity</code><br><em>optional</em></td>+ <td><p><code>unknown</code><br>Entity whose event triggered this execution; <code>undefined</code> when the run was not event-driven (e.g. started manually via "Execute script" or <code>note.executeScript()</code>). What it holds depends on the trigger: - <code>~runOnNoteCreation</code>, <code>~runOnNoteChange</code>, <code>~runOnNoteTitleChange</code>, <code>~runOnNoteContentChange</code> — the affected note; - <code>~runOnChildNoteCreation</code> — the newly created child note; - <code>~runOnAttributeCreation</code>, <code>~runOnAttributeChange</code> — the attribute; - <code>~runOnBranchCreation</code>, <code>~runOnBranchChange</code>, <code>~runOnBranchDeletion</code> — the branch; - scheduled scripts (<code>#run=backendStartup</code> / <code>#run=hourly</code> / <code>#run=daily</code>) — the script note itself; - search scripts (<code>~searchScript</code>) — the search note.</p></td>+ </tr>+ <tr>+ <td><code>req</code></td>+ <td><p><code>ScriptRequest</code><br>Express request object. Available only inside custom request handlers — a note with the <code>#customRequestHandler</code> label, invoked via a <code>/custom/...</code> URL. The editor surfaces this member only for such notes (where the request always supplies it), so it is non-optional rather than forcing a null-check.</p></td>+ </tr>+ <tr>+ <td><code>res</code></td>+ <td><p><code>ScriptResponse</code><br>Express response object — write the HTTP response here, e.g. <code>api.res.status(200).json({ ok: true })</code>. Available only inside custom request handlers (where it is always supplied), so it is non-optional.</p></td>+ </tr>+ <tr>+ <td><code>pathParams</code></td>+ <td><p><code>string[]</code><br>The capture groups from the <code>#customRequestHandler</code> regex that matched this request's URL, in order. Available only inside custom request handlers.</p></td>+ </tr>+ <tr>+ <td><code>dayjs</code></td>+ <td><p><code>ScriptDayjs</code><br>day.js library for date manipulation. See <code>https://day.js.org</code> for documentation</p></td>+ </tr>+ <tr>+ <td><code>xml2js</code></td>+ <td><p><code>unknown</code><br>xml2js library for XML parsing. See <code>https://github.com/Leonidas-from-XIV/node-xml2js</code> for documentation</p></td>+ </tr>+ <tr>+ <td><code>htmlParser</code></td>+ <td><p><code>unknown</code><br>node-html-parser library for HTML parsing. See <code>https://github.com/taoqf/node-fast-html-parser</code> for documentation.</p></td>+ </tr>+ <tr>+ <td><code>getInstanceName</code></td>+ <td><pre><code class="language-application-typescript">getInstanceName(): string | null</code></pre><p>Instance name identifies particular Trilium instance. It can be useful for scripts if some action needs to happen on only one specific instance.</p></td>+ </tr>+ <tr>+ <td><code>getNote</code></td>+ <td><pre><code class="language-application-typescript">getNote(noteId: string): ScriptBNote | null</code></pre><p>Returns a note by its ID, or null.</p></td>+ </tr>+ <tr>+ <td><code>getBranch</code></td>+ <td><pre><code class="language-application-typescript">getBranch(branchId: string): ScriptBBranch | null</code></pre><p>Returns a branch by its ID, or null.</p></td>+ </tr>+ <tr>+ <td><code>getAttribute</code></td>+ <td><pre><code class="language-application-typescript">getAttribute(attributeId: string): ScriptAttribute | null</code></pre><p>Returns an attribute by its ID, or null.</p></td>+ </tr>+ <tr>+ <td><code>getAttachment</code></td>+ <td><pre><code class="language-application-typescript">getAttachment(attachmentId: string): unknown</code></pre><p>Returns an attachment by its ID, or null.</p></td>+ </tr>+ <tr>+ <td><code>getRevision</code></td>+ <td><pre><code class="language-application-typescript">getRevision(revisionId: string): unknown</code></pre><p>Returns a revision by its ID, or null.</p></td>+ </tr>+ <tr>+ <td><code>getEtapiToken</code></td>+ <td><pre><code class="language-application-typescript">getEtapiToken(etapiTokenId: string): unknown</code></pre><p>Returns an ETAPI token by its ID, or null.</p></td>+ </tr>+ <tr>+ <td><code>getEtapiTokens</code></td>+ <td><pre><code class="language-application-typescript">getEtapiTokens(): unknown[]</code></pre><p>Returns all ETAPI tokens.</p></td>+ </tr>+ <tr>+ <td><code>getOption</code></td>+ <td><pre><code class="language-application-typescript">getOption(optionName: string): unknown</code></pre><p>Returns an option by name, or null.</p></td>+ </tr>+ <tr>+ <td><code>getOptions</code></td>+ <td><pre><code class="language-application-typescript">getOptions(): unknown[]</code></pre><p>Returns all options.</p></td>+ </tr>+ <tr>+ <td><code>searchForNotes</code></td>+ <td><pre><code class="language-application-typescript">searchForNotes(query: string, searchParams?: Record<string, unknown>): ScriptBNote[]</code></pre><p>This is a powerful search method - you can search by attributes and their values, e.g.: "#dateModified =* MONTH AND #log". See <code>https://triliumnext.github.io/Docs/Wiki/search.html</code> for full documentation for all options</p></td>+ </tr>+ <tr>+ <td><code>searchForNote</code></td>+ <td><pre><code class="language-application-typescript">searchForNote(query: string, searchParams?: Record<string, unknown>): ScriptBNote | null</code></pre><p>This is a powerful search method - you can search by attributes and their values, e.g.: "#dateModified =* MONTH AND #log". See <code>https://triliumnext.github.io/Docs/Wiki/search.html</code> for full documentation for all options</p></td>+ </tr>+ <tr>+ <td><code>getNotesWithLabel</code></td>+ <td><pre><code class="language-application-typescript">getNotesWithLabel(name: string, value?: string): ScriptBNote[]</code></pre><p>Retrieves notes with given label name & value</p><figure class="table"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>name</code></td><td><code>string</code><br>attribute name</td></tr><tr><td><code>value</code><br><em>optional</em></td><td><code>string</code><br>attribute value</td></tr></tbody></table></figure></td>+ </tr>+ <tr>+ <td><code>getNoteWithLabel</code></td>+ <td><pre><code class="language-application-typescript">getNoteWithLabel(name: string, value?: string): ScriptBNote | null</code></pre><p>Retrieves first note with given label name & value</p><figure class="table"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>name</code></td><td><code>string</code><br>attribute name</td></tr><tr><td><code>value</code><br><em>optional</em></td><td><code>string</code><br>attribute value</td></tr></tbody></table></figure></td>+ </tr>+ <tr>+ <td><code>ensureNoteIsPresentInParent</code></td>+ <td><pre><code class="language-application-typescript">ensureNoteIsPresentInParent(noteId: string, parentNoteId: string, prefix?: string): { branch: ScriptBBranch | null }</code></pre><p>If there's no branch between note and parent note, create one. Otherwise, do nothing. Returns the new or existing branch.</p><figure class="table"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>noteId</code></td><td><code>string</code></td></tr><tr><td><code>parentNoteId</code></td><td><code>string</code></td></tr><tr><td><code>prefix</code><br><em>optional</em></td><td><code>string</code><br>if branch is created between note and parent note, set this prefix</td></tr></tbody></table></figure></td>+ </tr>+ <tr>+ <td><code>ensureNoteIsAbsentFromParent</code></td>+ <td><pre><code class="language-application-typescript">ensureNoteIsAbsentFromParent(noteId: string, parentNoteId: string): void</code></pre><p>If there's a branch between note and parent note, remove it. Otherwise, do nothing.</p></td>+ </tr>+ <tr>+ <td><code>toggleNoteInParent</code></td>+ <td><pre><code class="language-application-typescript">toggleNoteInParent(present: boolean, noteId: string, parentNoteId: string, prefix?: string): void</code></pre><p>Based on the value, either create or remove branch between note and parent note.</p><figure class="table"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>present</code></td><td><code>boolean</code><br>true if we want the branch to exist, false if we want it gone</td></tr><tr><td><code>noteId</code></td><td><code>string</code></td></tr><tr><td><code>parentNoteId</code></td><td><code>string</code></td></tr><tr><td><code>prefix</code><br><em>optional</em></td><td><code>string</code><br>if branch is created between note and parent note, set this prefix</td></tr></tbody></table></figure></td>+ </tr>+ <tr>+ <td><code>createTextNote</code></td>+ <td><pre><code class="language-application-typescript">createTextNote(parentNoteId: string, title: string, content: string): ScriptNoteAndBranch</code></pre><p>Create text note. See also createNewNote() for more options.</p></td>+ </tr>+ <tr>+ <td><code>createDataNote</code></td>+ <td><pre><code class="language-application-typescript">createDataNote(parentNoteId: string, title: string, content: object): ScriptNoteAndBranch</code></pre><p>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.</p></td>+ </tr>+ <tr>+ <td><code>createNewNote</code></td>+ <td><pre><code class="language-application-typescript">createNewNote(params: { parentNoteId: string; title: string; content: string | Uint8Array<ArrayBufferLike>; type: string; mime?: string; [key: string]: unknown }): ScriptNoteAndBranch</code></pre><p><strong>Returns</strong> <code>ScriptNoteAndBranch</code>: object contains newly created entities note and branch</p></td>+ </tr>+ <tr>+ <td><code>logMessages</code></td>+ <td><p><code>Record<string, string[]></code><br>Per-note log message buffers shown in the UI log pane.</p></td>+ </tr>+ <tr>+ <td><code>logSpacedUpdates</code></td>+ <td><p><code>Record<string, unknown></code><br>Per-note spaced-update handlers for the log pane.</p></td>+ </tr>+ <tr>+ <td><code>log</code></td>+ <td><pre><code class="language-application-typescript">log(...args: unknown[]): void</code></pre><p>Log given message to trilium logs and log pane in UI. Accepts multiple arguments which are joined with spaces, similar to <code>console.log</code>.</p></td>+ </tr>+ <tr>+ <td><code>getRootCalendarNote</code></td>+ <td><pre><code class="language-application-typescript">getRootCalendarNote(): ScriptBNote | null</code></pre><p>Returns root note of the calendar.</p></td>+ </tr>+ <tr>+ <td><code>getDayNote</code></td>+ <td><pre><code class="language-application-typescript">getDayNote(date: string, rootNote?: ScriptBNote): ScriptBNote | null</code></pre><p>Returns day note for given date. If such note doesn't exist, it is created.</p><figure class="table"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>date</code></td><td><code>string</code><br>in YYYY-MM-DD format</td></tr><tr><td><code>rootNote</code><br><em>optional</em></td><td><code>ScriptBNote</code><br>specify calendar root note, normally leave empty to use the default calendar</td></tr></tbody></table></figure></td>+ </tr>+ <tr>+ <td><code>getTodayNote</code></td>+ <td><pre><code class="language-application-typescript">getTodayNote(rootNote?: ScriptBNote): ScriptBNote | null</code></pre><p>Returns today's day note. If such note doesn't exist, it is created.</p><figure class="table"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>rootNote</code><br><em>optional</em></td><td><code>ScriptBNote</code><br>specify calendar root note, normally leave empty to use the default calendar</td></tr></tbody></table></figure></td>+ </tr>+ <tr>+ <td><code>getWeekFirstDayNote</code></td>+ <td><pre><code class="language-application-typescript">getWeekFirstDayNote(date: string, rootNote?: ScriptBNote): ScriptBNote | null</code></pre><p>Returns note for the first date of the week of the given date.</p><figure class="table"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>date</code></td><td><code>string</code><br>in YYYY-MM-DD format</td></tr><tr><td><code>rootNote</code><br><em>optional</em></td><td><code>ScriptBNote</code><br>specify calendar root note, normally leave empty to use the default calendar</td></tr></tbody></table></figure></td>+ </tr>+ <tr>+ <td><code>getWeekNote</code></td>+ <td><pre><code class="language-application-typescript">getWeekNote(date: string, rootNote?: ScriptBNote): ScriptBNote | null</code></pre><p>Returns week note for given date. If such a note doesn't exist, it is created.</p><p>If the calendar does not support week notes, this method will return `null`.</p><figure class="table"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>date</code></td><td><code>string</code><br>in YYYY-MM-DD format</td></tr><tr><td><code>rootNote</code><br><em>optional</em></td><td><code>ScriptBNote</code><br>specify calendar root note, normally leave empty to use the default calendar</td></tr></tbody></table></figure><p><strong>Returns</strong> <code>ScriptBNote | null</code>: an existing or newly created week note, or <code>null</code> if the calendar does not support week notes.</p></td>+ </tr>+ <tr>+ <td><code>getMonthNote</code></td>+ <td><pre><code class="language-application-typescript">getMonthNote(date: string, rootNote?: ScriptBNote): ScriptBNote | null</code></pre><p>Returns month note for given date. If such a note doesn't exist, it is created.</p><figure class="table"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>date</code></td><td><code>string</code><br>in YYYY-MM format</td></tr><tr><td><code>rootNote</code><br><em>optional</em></td><td><code>ScriptBNote</code><br>specify calendar root note, normally leave empty to use the default calendar</td></tr></tbody></table></figure></td>+ </tr>+ <tr>+ <td><code>getQuarterNote</code></td>+ <td><pre><code class="language-application-typescript">getQuarterNote(date: string, rootNote?: ScriptBNote): ScriptBNote | null</code></pre><p>Returns quarter note for given date. If such a note doesn't exist, it is created.</p><figure class="table"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>date</code></td><td><code>string</code><br>in YYYY-MM format</td></tr><tr><td><code>rootNote</code><br><em>optional</em></td><td><code>ScriptBNote</code><br>specify calendar root note, normally leave empty to use the default calendar</td></tr></tbody></table></figure></td>+ </tr>+ <tr>+ <td><code>getYearNote</code></td>+ <td><pre><code class="language-application-typescript">getYearNote(year: string, rootNote?: ScriptBNote): ScriptBNote | null</code></pre><p>Returns year note for given year. If such a note doesn't exist, it is created.</p><figure class="table"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>year</code></td><td><code>string</code><br>in YYYY format</td></tr><tr><td><code>rootNote</code><br><em>optional</em></td><td><code>ScriptBNote</code><br>specify calendar root note, normally leave empty to use the default calendar</td></tr></tbody></table></figure></td>+ </tr>+ <tr>+ <td><code>sortNotes</code></td>+ <td><pre><code class="language-application-typescript">sortNotes(parentNoteId: string, sortConfig: { sortBy?: string; reverse?: boolean; foldersFirst?: boolean }): void</code></pre><p>Sort child notes of a given note. <code>sortBy</code> takes the <code>#sorted</code> grammar — comma-separated levels of <code>title</code>, <code>dateCreated</code>, <code>dateModified</code> or a label name, each optionally followed by <code>asc</code> or <code>desc</code> (<code>priority desc, dueDate</code>); <code>reverse</code> is the direction of the levels without their own, of the folders grouping and of ties.</p></td>+ </tr>+ <tr>+ <td><code>setNoteToParent</code></td>+ <td><pre><code class="language-application-typescript">setNoteToParent(noteId: string, prefix: string, parentNoteId: string | null): void</code></pre><p>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).</p><p>This method looks similar to toggleNoteInParent() but differs because we're looking up branch by prefix.</p><aside class="admonition warning"><p>Deprecated. this method is pretty confusing and serves specialized purpose only</p></aside></td>+ </tr>+ <tr>+ <td><code>transactional</code></td>+ <td><pre><code class="language-application-typescript">transactional(func: () => T): T</code></pre><p>This functions wraps code which is supposed to be running in transaction. If transaction already exists, then we'll use that transaction.</p><p><strong>Returns</strong> <code>T</code>: result of func callback</p></td>+ </tr>+ <tr>+ <td><code>randomString</code></td>+ <td><pre><code class="language-application-typescript">randomString(length: number): string</code></pre><p>Return randomly generated string of given length. This random string generation is NOT cryptographically secure.</p><figure class="table"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>length</code></td><td><code>number</code><br>of the string</td></tr></tbody></table></figure><p><strong>Returns</strong> <code>string</code>: random string</p></td>+ </tr>+ <tr>+ <td><code>escapeHtml</code></td>+ <td><pre><code class="language-application-typescript">escapeHtml(str: string): string</code></pre><p><strong>Returns</strong> <code>string</code>: escaped string</p></td>+ </tr>+ <tr>+ <td><code>unescapeHtml</code></td>+ <td><pre><code class="language-application-typescript">unescapeHtml(str: string): string</code></pre><p><strong>Returns</strong> <code>string</code>: unescaped string</p></td>+ </tr>+ <tr>+ <td><code>htmlToMarkdown</code></td>+ <td><pre><code class="language-application-typescript">htmlToMarkdown(html: string): string</code></pre><p>Converts the given HTML string to Markdown.</p><figure class="table"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>html</code></td><td><code>string</code><br>HTML content to convert</td></tr></tbody></table></figure><p><strong>Returns</strong> <code>string</code>: Markdown representation of the input HTML</p></td>+ </tr>+ <tr>+ <td><code>markdownToHtml</code></td>+ <td><pre><code class="language-application-typescript">markdownToHtml(markdown: string): string</code></pre><p>Converts the given Markdown string to HTML.</p><figure class="table"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>markdown</code></td><td><code>string</code><br>Markdown content to convert</td></tr></tbody></table></figure><p><strong>Returns</strong> <code>string</code>: HTML representation of the input Markdown</p></td>+ </tr>+ <tr>+ <td><code>sql</code></td>+ <td><p><code>unknown</code><br>sql</p></td>+ </tr>+ <tr>+ <td><code>getAppInfo</code></td>+ <td><pre><code class="language-application-typescript">getAppInfo(): unknown</code></pre><p>Application info (version, build date, etc.).</p></td>+ </tr>+ <tr>+ <td><code>createOrUpdateLauncher</code></td>+ <td><pre><code class="language-application-typescript">createOrUpdateLauncher(opts: { id: string; type: "note" | "script" | "customWidget"; title: string; isVisible: boolean; icon: string; keyboardShortcut: string; targetNoteId?: string; scriptNoteId?: string; widgetNoteId?: string }): { note: ScriptBNote }</code></pre><p>Creates a new launcher to the launchbar. If the launcher (id) already exists, it will be updated.</p></td>+ </tr>+ <tr>+ <td><code>exportSubtreeToZipFile</code></td>+ <td><pre><code class="language-application-typescript">exportSubtreeToZipFile(noteId: string, format: "markdown" | "html", zipFilePath: string): Promise<void></code></pre><figure class="table"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>noteId</code></td><td><code>string</code></td></tr><tr><td><code>format</code></td><td><code>"markdown" | "html"</code><br>either 'html' or 'markdown'</td></tr><tr><td><code>zipFilePath</code></td><td><code>string</code></td></tr></tbody></table></figure></td>+ </tr>+ <tr>+ <td><code>runOnFrontend</code></td>+ <td><pre><code class="language-application-typescript">runOnFrontend(script: string | () => void, params?: unknown[]): void</code></pre><p>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.</p><figure class="table"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>script</code></td><td><code>string | () => void</code><br>script to be executed on the frontend</td></tr><tr><td><code>params</code><br><em>optional</em></td><td><code>unknown[]</code><br>list of parameters to the anonymous function to be sent to frontend</td></tr></tbody></table></figure><p><strong>Returns</strong> <code>void</code>: no return value is provided.</p></td>+ </tr>+ <tr>+ <td><code>runOutsideOfSync</code></td>+ <td><pre><code class="language-application-typescript">runOutsideOfSync(callback: () => void): Promise<void></code></pre><p>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.</p><p>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(...)</p><figure class="table"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>callback</code></td><td><code>() => void</code><br>function to be executed while sync process is not running</td></tr></tbody></table></figure><p><strong>Returns</strong> <code>Promise<void></code>: resolves once the callback is finished (callback is awaited)</p></td>+ </tr>+ <tr>+ <td><code>backupNow</code></td>+ <td><pre><code class="language-application-typescript">backupNow(backupName: string): Promise<string></code></pre><figure class="table"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>backupName</code></td><td><code>string</code><br>If the backupName is e.g. "now", then the backup will be written to "backup-now.db" file</td></tr></tbody></table></figure><p><strong>Returns</strong> <code>Promise<string></code>: resolves once the backup is finished</p></td>+ </tr>+ <tr>+ <td><code>duplicateSubtree</code></td>+ <td><pre><code class="language-application-typescript">duplicateSubtree(origNoteId: string, newParentNoteId: string): ScriptNoteAndBranch</code></pre><p>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.</p><figure class="table"><table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>origNoteId</code></td><td><code>string</code><br>the noteId for the original note to be duplicated</td></tr><tr><td><code>newParentNoteId</code></td><td><code>string</code><br>the noteId for the parent note where the duplication is to be placed.</td></tr></tbody></table></figure><p><strong>Returns</strong> <code>ScriptNoteAndBranch</code>: the note and the branch of the newly created note.</p></td>+ </tr>+ </tbody>+</table>++## `ScriptBNote`++A note as seen by backend scripts (subset of trilium-core's `BNote`).++<table>+ <thead>+ <tr>+ <th>Member</th>+ <th>Description</th>+ </tr>+ </thead>+ <tbody>+ <tr>+ <td><code>noteId</code></td>+ <td><p><code>string</code></p></td>+ </tr>+ <tr>+ <td><code>title</code></td>+ <td><p><code>string</code></p></td>+ </tr>+ <tr>+ <td><code>type</code></td>+ <td><p><code>string</code></p></td>+ </tr>+ <tr>+ <td><code>mime</code></td>+ <td><p><code>string</code></p></td>+ </tr>+ <tr>+ <td><code>isProtected</code></td>+ <td><p><code>boolean</code></p></td>+ </tr>+ <tr>+ <td><code>isArchived</code></td>+ <td><p><code>boolean</code></p></td>+ </tr>+ <tr>+ <td><code>isDeleted</code></td>+ <td><p><code>boolean</code></p></td>+ </tr>+ <tr>+ <td><code>shareId</code></td>+ <td><p><code>string</code><br>Share root ID this note is published under, if any.</p></td>+ </tr>+ <tr>+ <td><code>blobId</code></td>+ <td><p><code>string</code></p></td>+ </tr>+ <tr>+ <td><code>dateCreated</code></td>+ <td><p><code>string</code></p></td>+ </tr>+ <tr>+ <td><code>dateModified</code></td>+ <td><p><code>string</code></p></td>+ </tr>+ <tr>+ <td><code>utcDateCreated</code></td>+ <td><p><code>string</code></p></td>+ </tr>+ <tr>+ <td><code>utcDateModified</code></td>+ <td><p><code>string</code></p></td>+ </tr>+ <tr>+ <td><code>getContent</code></td>+ <td><pre><code class="language-application-typescript">getContent(): string | Uint8Array<ArrayBufferLike></code></pre></td>+ </tr>+ <tr>+ <td><code>setContent</code></td>+ <td><pre><code class="language-application-typescript">setContent(content: string | Uint8Array<ArrayBufferLike>, opts?: { forceFrontendReload?: boolean }): void</code></pre></td>+ </tr>+ <tr>+ <td><code>getJsonContent</code></td>+ <td><pre><code class="language-application-typescript">getJsonContent(): T | null</code></pre></td>+ </tr>+ <tr>+ <td><code>getJsonContentSafely</code></td>+ <td><pre><code class="language-application-typescript">getJsonContentSafely(): unknown</code></pre></td>+ </tr>+ <tr>+ <td><code>setJsonContent</code></td>+ <td><pre><code class="language-application-typescript">setJsonContent(content: unknown): void</code></pre></td>+ </tr>+ <tr>+ <td><code>hasStringContent</code></td>+ <td><pre><code class="language-application-typescript">hasStringContent(): boolean</code></pre></td>+ </tr>+ <tr>+ <td><code>getFileName</code></td>+ <td><pre><code class="language-application-typescript">getFileName(): string</code></pre></td>+ </tr>+ <tr>+ <td><code>getFlatText</code></td>+ <td><pre><code class="language-application-typescript">getFlatText(): string</code></pre></td>+ </tr>+ <tr>+ <td><code>getPojo</code></td>+ <td><pre><code class="language-application-typescript">getPojo(): Record<string, unknown></code></pre><p>Plain serialisable representation of the note (the real return type is <code>NotePojo</code>).</p></td>+ </tr>+ <tr>+ <td><code>getTitleOrProtected</code></td>+ <td><pre><code class="language-application-typescript">getTitleOrProtected(): string</code></pre></td>+ </tr>+ <tr>+ <td><code>getIcon</code></td>+ <td><pre><code class="language-application-typescript">getIcon(): string</code></pre></td>+ </tr>+ <tr>+ <td><code>parents</code></td>+ <td><p><code>ScriptBNote[]</code></p></td>+ </tr>+ <tr>+ <td><code>children</code></td>+ <td><p><code>ScriptBNote[]</code></p></td>+ </tr>+ <tr>+ <td><code>parentBranches</code></td>+ <td><p><code>ScriptBBranch[]</code></p></td>+ </tr>+ <tr>+ <td><code>parentCount</code></td>+ <td><p><code>number</code></p></td>+ </tr>+ <tr>+ <td><code>childrenCount</code></td>+ <td><p><code>number</code></p></td>+ </tr>+ <tr>+ <td><code>getParentNotes</code></td>+ <td><pre><code class="language-application-typescript">getParentNotes(): ScriptBNote[]</code></pre></td>+ </tr>+ <tr>+ <td><code>getChildNotes</code></td>+ <td><pre><code class="language-application-typescript">getChildNotes(): ScriptBNote[]</code></pre></td>+ </tr>+ <tr>+ <td><code>getVisibleChildNotes</code></td>+ <td><pre><code class="language-application-typescript">getVisibleChildNotes(): ScriptBNote[]</code></pre></td>+ </tr>+ <tr>+ <td><code>getParentBranches</code></td>+ <td><pre><code class="language-application-typescript">getParentBranches(): ScriptBBranch[]</code></pre></td>+ </tr>+ <tr>+ <td><code>getChildBranches</code></td>+ <td><pre><code class="language-application-typescript">getChildBranches(): ScriptBBranch[]</code></pre></td>+ </tr>+ <tr>+ <td><code>getVisibleChildBranches</code></td>+ <td><pre><code class="language-application-typescript">getVisibleChildBranches(): ScriptBBranch[]</code></pre></td>+ </tr>+ <tr>+ <td><code>getStrongParentBranches</code></td>+ <td><pre><code class="language-application-typescript">getStrongParentBranches(): ScriptBBranch[]</code></pre></td>+ </tr>+ <tr>+ <td><code>getFilteredChildBranches</code></td>+ <td><pre><code class="language-application-typescript">getFilteredChildBranches(): ScriptBBranch[]</code></pre></td>+ </tr>+ <tr>+ <td><code>getBranches</code></td>+ <td><pre><code class="language-application-typescript">getBranches(): ScriptBBranch[]</code></pre></td>+ </tr>+ <tr>+ <td><code>hasChildren</code></td>+ <td><pre><code class="language-application-typescript">hasChildren(): boolean</code></pre></td>+ </tr>+ <tr>+ <td><code>hasVisibleChildren</code></td>+ <td><pre><code class="language-application-typescript">hasVisibleChildren(): boolean</code></pre></td>+ </tr>+ <tr>+ <td><code>getAncestors</code></td>+ <td><pre><code class="language-application-typescript">getAncestors(): ScriptBNote[]</code></pre></td>+ </tr>+ <tr>+ <td><code>getAncestorNoteIds</code></td>+ <td><pre><code class="language-application-typescript">getAncestorNoteIds(): string[]</code></pre></td>+ </tr>+ <tr>+ <td><code>getDescendantNoteIds</code></td>+ <td><pre><code class="language-application-typescript">getDescendantNoteIds(): string[]</code></pre></td>+ </tr>+ <tr>+ <td><code>getDistanceToAncestor</code></td>+ <td><pre><code class="language-application-typescript">getDistanceToAncestor(ancestorNoteId: string): number</code></pre></td>+ </tr>+ <tr>+ <td><code>hasAncestor</code></td>+ <td><pre><code class="language-application-typescript">hasAncestor(ancestorNoteId: string): boolean</code></pre></td>+ </tr>+ <tr>+ <td><code>isDescendantOfNote</code></td>+ <td><pre><code class="language-application-typescript">isDescendantOfNote(ancestorNoteId: string): boolean</code></pre></td>+ </tr>+ <tr>+ <td><code>isRoot</code></td>+ <td><pre><code class="language-application-typescript">isRoot(): boolean</code></pre></td>+ </tr>+ <tr>+ <td><code>getSubtree</code></td>+ <td><pre><code class="language-application-typescript">getSubtree(opts?: ScriptSubtreeOpts): { notes: ScriptBNote[]; relationships: ScriptSubtreeRelationship[] }</code></pre></td>+ </tr>+ <tr>+ <td><code>getSubtreeNoteIds</code></td>+ <td><pre><code class="language-application-typescript">getSubtreeNoteIds(opts?: ScriptSubtreeOpts): string[]</code></pre></td>+ </tr>+ <tr>+ <td><code>getSubtreeNotesIncludingTemplated</code></td>+ <td><pre><code class="language-application-typescript">getSubtreeNotesIncludingTemplated(): ScriptBNote[]</code></pre></td>+ </tr>+ <tr>+ <td><code>getInheritingNotes</code></td>+ <td><pre><code class="language-application-typescript">getInheritingNotes(): ScriptBNote[]</code></pre></td>+ </tr>+ <tr>+ <td><code>getAllNotePaths</code></td>+ <td><pre><code class="language-application-typescript">getAllNotePaths(): string[][]</code></pre></td>+ </tr>+ <tr>+ <td><code>getBestNotePath</code></td>+ <td><pre><code class="language-application-typescript">getBestNotePath(hoistedNoteId?: string): string[]</code></pre></td>+ </tr>+ <tr>+ <td><code>getBestNotePathString</code></td>+ <td><pre><code class="language-application-typescript">getBestNotePathString(hoistedNoteId?: string): string</code></pre></td>+ </tr>+ <tr>+ <td><code>getSortedNotePathRecords</code></td>+ <td><pre><code class="language-application-typescript">getSortedNotePathRecords(hoistedNoteId?: string): ScriptNotePathRecord[]</code></pre></td>+ </tr>+ <tr>+ <td><code>areAllNotePathsArchived</code></td>+ <td><pre><code class="language-application-typescript">areAllNotePathsArchived(): boolean</code></pre></td>+ </tr>+ <tr>+ <td><code>ownedAttributes</code></td>+ <td><p><code>ScriptAttribute[]</code></p></td>+ </tr>+ <tr>+ <td><code>targetRelations</code></td>+ <td><p><code>ScriptAttribute[]</code></p></td>+ </tr>+ <tr>+ <td><code>attributeCount</code></td>+ <td><p><code>number</code></p></td>+ </tr>+ <tr>+ <td><code>ownedAttributeCount</code></td>+ <td><p><code>number</code></p></td>+ </tr>+ <tr>+ <td><code>labelCount</code></td>+ <td><p><code>number</code></p></td>+ </tr>+ <tr>+ <td><code>ownedLabelCount</code></td>+ <td><p><code>number</code></p></td>+ </tr>+ <tr>+ <td><code>relationCount</code></td>+ <td><p><code>number</code></p></td>+ </tr>+ <tr>+ <td><code>relationCountIncludingLinks</code></td>+ <td><p><code>number</code></p></td>+ </tr>+ <tr>+ <td><code>ownedRelationCount</code></td>+ <td><p><code>number</code></p></td>+ </tr>+ <tr>+ <td><code>ownedRelationCountIncludingLinks</code></td>+ <td><p><code>number</code></p></td>+ </tr>+ <tr>+ <td><code>targetRelationCount</code></td>+ <td><p><code>number</code></p></td>+ </tr>+ <tr>+ <td><code>targetRelationCountIncludingLinks</code></td>+ <td><p><code>number</code></p></td>+ </tr>+ <tr>+ <td><code>getAttributes</code></td>+ <td><pre><code class="language-application-typescript">getAttributes(type?: string, name?: string): ScriptAttribute[]</code></pre></td>+ </tr>+ <tr>+ <td><code>getOwnedAttributes</code></td>+ <td><pre><code class="language-application-typescript">getOwnedAttributes(type?: string, name?: string): ScriptAttribute[]</code></pre></td>+ </tr>+ <tr>+ <td><code>getAttribute</code></td>+ <td><pre><code class="language-application-typescript">getAttribute(type: string, name: string): ScriptAttribute | null</code></pre></td>+ </tr>+ <tr>+ <td><code>getOwnedAttribute</code></td>+ <td><pre><code class="language-application-typescript">getOwnedAttribute(type: string, name: string, value?: string | null): ScriptAttribute | null</code></pre></td>+ </tr>+ <tr>+ <td><code>getAttributeValue</code></td>+ <td><pre><code class="language-application-typescript">getAttributeValue(type: string, name: string): string | null</code></pre></td>+ </tr>+ <tr>+ <td><code>getOwnedAttributeValue</code></td>+ <td><pre><code class="language-application-typescript">getOwnedAttributeValue(type: string, name: string): string | null</code></pre></td>+ </tr>+ <tr>+ <td><code>getAttributeById</code></td>+ <td><pre><code class="language-application-typescript">getAttributeById(attributeId: string): ScriptAttribute | undefined</code></pre></td>+ </tr>+ <tr>+ <td><code>getAttributeCaseInsensitive</code></td>+ <td><pre><code class="language-application-typescript">getAttributeCaseInsensitive(type: string, name: string, value?: string | null): ScriptAttribute | undefined</code></pre></td>+ </tr>+ <tr>+ <td><code>hasAttribute</code></td>+ <td><pre><code class="language-application-typescript">hasAttribute(type: string, name: string): boolean</code></pre></td>+ </tr>+ <tr>+ <td><code>hasOwnedAttribute</code></td>+ <td><pre><code class="language-application-typescript">hasOwnedAttribute(type: string, name: string, value?: string): boolean</code></pre></td>+ </tr>+ <tr>+ <td><code>getLabelDefinitions</code></td>+ <td><pre><code class="language-application-typescript">getLabelDefinitions(): ScriptAttribute[]</code></pre></td>+ </tr>+ <tr>+ <td><code>getRelationDefinitions</code></td>+ <td><pre><code class="language-application-typescript">getRelationDefinitions(): ScriptAttribute[]</code></pre></td>+ </tr>+ <tr>+ <td><code>getTargetRelations</code></td>+ <td><pre><code class="language-application-typescript">getTargetRelations(): ScriptAttribute[]</code></pre></td>+ </tr>+ <tr>+ <td><code>getLabel</code></td>+ <td><pre><code class="language-application-typescript">getLabel(name: string): ScriptAttribute | null</code></pre></td>+ </tr>+ <tr>+ <td><code>getOwnedLabel</code></td>+ <td><pre><code class="language-application-typescript">getOwnedLabel(name: string): ScriptAttribute | null</code></pre></td>+ </tr>+ <tr>+ <td><code>getLabels</code></td>+ <td><pre><code class="language-application-typescript">getLabels(name?: string): ScriptAttribute[]</code></pre></td>+ </tr>+ <tr>+ <td><code>getOwnedLabels</code></td>+ <td><pre><code class="language-application-typescript">getOwnedLabels(name: string): ScriptAttribute[]</code></pre></td>+ </tr>+ <tr>+ <td><code>getLabelValue</code></td>+ <td><pre><code class="language-application-typescript">getLabelValue(name: string): string | null</code></pre></td>+ </tr>+ <tr>+ <td><code>getOwnedLabelValue</code></td>+ <td><pre><code class="language-application-typescript">getOwnedLabelValue(name: string): string | null</code></pre></td>+ </tr>+ <tr>+ <td><code>getLabelValues</code></td>+ <td><pre><code class="language-application-typescript">getLabelValues(name: string): string[]</code></pre></td>+ </tr>+ <tr>+ <td><code>getOwnedLabelValues</code></td>+ <td><pre><code class="language-application-typescript">getOwnedLabelValues(name: string): string[]</code></pre></td>+ </tr>+ <tr>+ <td><code>hasLabel</code></td>+ <td><pre><code class="language-application-typescript">hasLabel(name: string): boolean</code></pre></td>+ </tr>+ <tr>+ <td><code>hasOwnedLabel</code></td>+ <td><pre><code class="language-application-typescript">hasOwnedLabel(name: string, value?: string): boolean</code></pre></td>+ </tr>+ <tr>+ <td><code>isLabelTruthy</code></td>+ <td><pre><code class="language-application-typescript">isLabelTruthy(name: string): boolean</code></pre></td>+ </tr>+ <tr>+ <td><code>hasInheritableArchivedLabel</code></td>+ <td><pre><code class="language-application-typescript">hasInheritableArchivedLabel(): boolean</code></pre></td>+ </tr>+ <tr>+ <td><code>getRelation</code></td>+ <td><pre><code class="language-application-typescript">getRelation(name: string): ScriptAttribute | null</code></pre></td>+ </tr>+ <tr>+ <td><code>getOwnedRelation</code></td>+ <td><pre><code class="language-application-typescript">getOwnedRelation(name: string): ScriptAttribute | null</code></pre></td>+ </tr>+ <tr>+ <td><code>getRelations</code></td>+ <td><pre><code class="language-application-typescript">getRelations(name?: string): ScriptAttribute[]</code></pre></td>+ </tr>+ <tr>+ <td><code>getOwnedRelations</code></td>+ <td><pre><code class="language-application-typescript">getOwnedRelations(name?: string | null): ScriptAttribute[]</code></pre></td>+ </tr>+ <tr>+ <td><code>getRelationValue</code></td>+ <td><pre><code class="language-application-typescript">getRelationValue(name: string): string | null</code></pre></td>+ </tr>+ <tr>+ <td><code>getOwnedRelationValue</code></td>+ <td><pre><code class="language-application-typescript">getOwnedRelationValue(name: string): string | null</code></pre></td>+ </tr>+ <tr>+ <td><code>getRelationTarget</code></td>+ <td><pre><code class="language-application-typescript">getRelationTarget(name: string): ScriptBNote | null</code></pre></td>+ </tr>+ <tr>+ <td><code>hasRelation</code></td>+ <td><pre><code class="language-application-typescript">hasRelation(name: string, value?: string): boolean</code></pre></td>+ </tr>+ <tr>+ <td><code>hasOwnedRelation</code></td>+ <td><pre><code class="language-application-typescript">hasOwnedRelation(name: string, value?: string): boolean</code></pre></td>+ </tr>+ <tr>+ <td><code>addLabel</code></td>+ <td><pre><code class="language-application-typescript">addLabel(name: string, value?: string, isInheritable?: boolean): ScriptAttribute</code></pre></td>+ </tr>+ <tr>+ <td><code>addRelation</code></td>+ <td><pre><code class="language-application-typescript">addRelation(name: string, targetNoteId: string, isInheritable?: boolean): ScriptAttribute</code></pre></td>+ </tr>+ <tr>+ <td><code>addAttribute</code></td>+ <td><pre><code class="language-application-typescript">addAttribute(type: string, name: string, value?: string, isInheritable?: boolean): ScriptAttribute</code></pre></td>+ </tr>+ <tr>+ <td><code>setLabel</code></td>+ <td><pre><code class="language-application-typescript">setLabel(name: string, value?: string): void</code></pre></td>+ </tr>+ <tr>+ <td><code>setRelation</code></td>+ <td><pre><code class="language-application-typescript">setRelation(name: string, value?: string): void</code></pre></td>+ </tr>+ <tr>+ <td><code>setAttribute</code></td>+ <td><pre><code class="language-application-typescript">setAttribute(type: string, name: string, value?: string): void</code></pre></td>+ </tr>+ <tr>+ <td><code>setAttributeValueById</code></td>+ <td><pre><code class="language-application-typescript">setAttributeValueById(attributeId: string, value?: string): void</code></pre></td>+ </tr>+ <tr>+ <td><code>toggleLabel</code></td>+ <td><pre><code class="language-application-typescript">toggleLabel(enabled: boolean, name: string, value?: string): void</code></pre></td>+ </tr>+ <tr>+ <td><code>toggleRelation</code></td>+ <td><pre><code class="language-application-typescript">toggleRelation(enabled: boolean, name: string, value?: string): void</code></pre></td>+ </tr>+ <tr>+ <td><code>toggleAttribute</code></td>+ <td><pre><code class="language-application-typescript">toggleAttribute(type: string, enabled: boolean, name: string, value?: string): void</code></pre></td>+ </tr>+ <tr>+ <td><code>removeLabel</code></td>+ <td><pre><code class="language-application-typescript">removeLabel(name: string, value?: string): void</code></pre></td>+ </tr>+ <tr>+ <td><code>removeRelation</code></td>+ <td><pre><code class="language-application-typescript">removeRelation(name: string, value?: string): void</code></pre></td>+ </tr>+ <tr>+ <td><code>removeAttribute</code></td>+ <td><pre><code class="language-application-typescript">removeAttribute(type: string, name: string, value?: string): void</code></pre></td>+ </tr>+ <tr>+ <td><code>isInherited</code></td>+ <td><pre><code class="language-application-typescript">isInherited(): boolean</code></pre></td>+ </tr>+ <tr>+ <td><code>revisionCount</code></td>+ <td><p><code>number | null</code></p></td>+ </tr>+ <tr>+ <td><code>getRevisions</code></td>+ <td><pre><code class="language-application-typescript">getRevisions(): ScriptBRevision[]</code></pre></td>+ </tr>+ <tr>+ <td><code>saveRevision</code></td>+ <td><pre><code class="language-application-typescript">saveRevision(opts?: { description?: string; source?: string }): ScriptBRevision</code></pre></td>+ </tr>+ <tr>+ <td><code>getAttachments</code></td>+ <td><pre><code class="language-application-typescript">getAttachments(): ScriptAttachment[]</code></pre></td>+ </tr>+ <tr>+ <td><code>getAttachmentById</code></td>+ <td><pre><code class="language-application-typescript">getAttachmentById(attachmentId: string): ScriptAttachment</code></pre></td>+ </tr>+ <tr>+ <td><code>getAttachmentByTitle</code></td>+ <td><pre><code class="language-application-typescript">getAttachmentByTitle(title: string): ScriptAttachment | undefined</code></pre></td>+ </tr>+ <tr>+ <td><code>getAttachmentsByRole</code></td>+ <td><pre><code class="language-application-typescript">getAttachmentsByRole(role: string): ScriptAttachment[]</code></pre></td>+ </tr>+ <tr>+ <td><code>saveAttachment</code></td>+ <td><pre><code class="language-application-typescript">saveAttachment(attachment: ScriptSaveAttachmentInput, matchBy?: "title" | "attachmentId"): ScriptAttachment</code></pre></td>+ </tr>+ <tr>+ <td><code>convertToParentAttachment</code></td>+ <td><pre><code class="language-application-typescript">convertToParentAttachment(opts?: Record<string, unknown>): ScriptAttachment | null</code></pre></td>+ </tr>+ <tr>+ <td><code>isEligibleForConversionToAttachment</code></td>+ <td><pre><code class="language-application-typescript">isEligibleForConversionToAttachment(opts?: Record<string, unknown>): boolean</code></pre></td>+ </tr>+ <tr>+ <td><code>contentSize</code></td>+ <td><p><code>number | null</code></p></td>+ </tr>+ <tr>+ <td><code>contentAndAttachmentsSize</code></td>+ <td><p><code>number | null</code></p></td>+ </tr>+ <tr>+ <td><code>contentAndAttachmentsAndRevisionsSize</code></td>+ <td><p><code>number | null</code></p></td>+ </tr>+ <tr>+ <td><code>cloneTo</code></td>+ <td><pre><code class="language-application-typescript">cloneTo(parentNoteId: string): ScriptCloneResponse</code></pre></td>+ </tr>+ <tr>+ <td><code>deleteNote</code></td>+ <td><pre><code class="language-application-typescript">deleteNote(deleteId?: string | null): void</code></pre></td>+ </tr>+ <tr>+ <td><code>sortParents</code></td>+ <td><pre><code class="language-application-typescript">sortParents(): void</code></pre></td>+ </tr>+ <tr>+ <td><code>sortChildren</code></td>+ <td><pre><code class="language-application-typescript">sortChildren(): void</code></pre></td>+ </tr>+ <tr>+ <td><code>searchNotesInSubtree</code></td>+ <td><pre><code class="language-application-typescript">searchNotesInSubtree(searchString: string): ScriptBNote[]</code></pre></td>+ </tr>+ <tr>+ <td><code>searchNoteInSubtree</code></td>+ <td><pre><code class="language-application-typescript">searchNoteInSubtree(searchString: string): ScriptBNote | null</code></pre></td>+ </tr>+ <tr>+ <td><code>getSearchResultNotes</code></td>+ <td><pre><code class="language-application-typescript">getSearchResultNotes(): ScriptBNote[]</code></pre></td>+ </tr>+ <tr>+ <td><code>isFolder</code></td>+ <td><pre><code class="language-application-typescript">isFolder(): boolean</code></pre></td>+ </tr>+ <tr>+ <td><code>isContentAvailable</code></td>+ <td><pre><code class="language-application-typescript">isContentAvailable(): boolean</code></pre></td>+ </tr>+ <tr>+ <td><code>isStringNote</code></td>+ <td><pre><code class="language-application-typescript">isStringNote(): boolean</code></pre></td>+ </tr>+ <tr>+ <td><code>isHtml</code></td>+ <td><pre><code class="language-application-typescript">isHtml(): boolean</code></pre></td>+ </tr>+ <tr>+ <td><code>isImage</code></td>+ <td><pre><code class="language-application-typescript">isImage(): boolean</code></pre></td>+ </tr>+ <tr>+ <td><code>isJavaScript</code></td>+ <td><pre><code class="language-application-typescript">isJavaScript(): boolean</code></pre></td>+ </tr>+ <tr>+ <td><code>isJsx</code></td>+ <td><pre><code class="language-application-typescript">isJsx(): boolean</code></pre></td>+ </tr>+ <tr>+ <td><code>isJson</code></td>+ <td><pre><code class="language-application-typescript">isJson(): boolean</code></pre></td>+ </tr>+ <tr>+ <td><code>isMarkdown</code></td>+ <td><pre><code class="language-application-typescript">isMarkdown(): boolean</code></pre></td>+ </tr>+ <tr>+ <td><code>isOptions</code></td>+ <td><pre><code class="language-application-typescript">isOptions(): boolean</code></pre></td>+ </tr>+ <tr>+ <td><code>isLaunchBarConfig</code></td>+ <td><pre><code class="language-application-typescript">isLaunchBarConfig(): boolean</code></pre></td>+ </tr>+ <tr>+ <td><code>isHiddenCompletely</code></td>+ <td><pre><code class="language-application-typescript">isHiddenCompletely(): boolean</code></pre></td>+ </tr>+ <tr>+ <td><code>isInHiddenSubtree</code></td>+ <td><pre><code class="language-application-typescript">isInHiddenSubtree(): boolean</code></pre></td>+ </tr>+ <tr>+ <td><code>getScriptEnv</code></td>+ <td><pre><code class="language-application-typescript">getScriptEnv(): "frontend" | "backend" | null</code></pre></td>+ </tr>+ <tr>+ <td><code>executeScript</code></td>+ <td><pre><code class="language-application-typescript">executeScript(): unknown</code></pre></td>+ </tr>+ </tbody>+</table>++## `ScriptRequest`++Minimal Express `Request` surface available to **custom request handlers** (a subset of Express's `Request` — re-declared here to keep this module self-contained). Only the commonly used members are typed; the real object is a full Express request.++<table>+ <thead>+ <tr>+ <th>Member</th>+ <th>Description</th>+ </tr>+ </thead>+ <tbody>+ <tr>+ <td><code>params</code></td>+ <td><p><code>Record<string, string></code><br>Route/path parameters.</p></td>+ </tr>+ <tr>+ <td><code>query</code></td>+ <td><p><code>Record<string, unknown></code><br>Parsed query-string parameters.</p></td>+ </tr>+ <tr>+ <td><code>body</code></td>+ <td><p><code>unknown</code><br>Parsed request body (requires a matching body parser).</p></td>+ </tr>+ <tr>+ <td><code>headers</code></td>+ <td><p><code>Record<string, string | string[] | undefined></code><br>Request headers (lower-cased names).</p></td>+ </tr>+ <tr>+ <td><code>method</code></td>+ <td><p><code>string</code><br>HTTP method, e.g. "GET", "POST".</p></td>+ </tr>+ <tr>+ <td><code>url</code></td>+ <td><p><code>string</code><br>Request URL (path + query string).</p></td>+ </tr>+ <tr>+ <td><code>get</code></td>+ <td><pre><code class="language-application-typescript">get(headerName: string): string | undefined</code></pre><p>Returns the value of the given (case-insensitive) header.</p></td>+ </tr>+ </tbody>+</table>++## `ScriptResponse`++Minimal Express `Response` surface available to **custom request handlers** (a subset of Express's `Response`). Write the HTTP response through this object, e.g. `api.res.status(200).json({ ok: true })`.++<table>+ <thead>+ <tr>+ <th>Member</th>+ <th>Description</th>+ </tr>+ </thead>+ <tbody>+ <tr>+ <td><code>status</code></td>+ <td><pre><code class="language-application-typescript">status(code: number): ScriptResponse</code></pre><p>Sets the HTTP status code (chainable).</p></td>+ </tr>+ <tr>+ <td><code>send</code></td>+ <td><pre><code class="language-application-typescript">send(body?: unknown): ScriptResponse</code></pre><p>Sends the response body (string, Buffer, object, …) and ends the response.</p></td>+ </tr>+ <tr>+ <td><code>json</code></td>+ <td><pre><code class="language-application-typescript">json(body: unknown): ScriptResponse</code></pre><p>Sends a JSON response and ends the response.</p></td>+ </tr>+ <tr>+ <td><code>setHeader</code></td>+ <td><pre><code class="language-application-typescript">setHeader(name: string, value: string | string[]): ScriptResponse</code></pre><p>Sets a response header (chainable).</p></td>+ </tr>+ <tr>+ <td><code>set</code></td>+ <td><pre><code class="language-application-typescript">set(field: string, value?: string): ScriptResponse</code></pre><p>Sets a response header (Express alias of <code>setHeader</code>, chainable).</p></td>+ </tr>+ <tr>+ <td><code>redirect</code></td>+ <td><pre><code class="language-application-typescript">redirect(url: string): void</code></pre><p>Redirects to the given URL.</p></td>+ </tr>+ <tr>+ <td><code>end</code></td>+ <td><pre><code class="language-application-typescript">end(): void</code></pre><p>Ends the response without further data.</p></td>+ </tr>+ </tbody>+</table>++## `ScriptBBranch`++A branch (note→parent placement) as seen by backend scripts (subset of `BBranch`).++<table>+ <thead>+ <tr>+ <th>Member</th>+ <th>Description</th>+ </tr>+ </thead>+ <tbody>+ <tr>+ <td><code>branchId</code></td>+ <td><p><code>string</code></p></td>+ </tr>+ <tr>+ <td><code>noteId</code></td>+ <td><p><code>string</code></p></td>+ </tr>+ <tr>+ <td><code>parentNoteId</code></td>+ <td><p><code>string</code></p></td>+ </tr>+ <tr>+ <td><code>prefix</code></td>+ <td><p><code>string | null</code></p></td>+ </tr>+ <tr>+ <td><code>notePosition</code></td>+ <td><p><code>number</code></p></td>+ </tr>+ <tr>+ <td><code>isExpanded</code></td>+ <td><p><code>boolean</code></p></td>+ </tr>+ <tr>+ <td><code>getNote</code></td>+ <td><pre><code class="language-application-typescript">getNote(): ScriptBNote</code></pre></td>+ </tr>+ <tr>+ <td><code>getParentNote</code></td>+ <td><pre><code class="language-application-typescript">getParentNote(): ScriptBNote | null</code></pre></td>+ </tr>+ </tbody>+</table>++## `ScriptBRevision`++A note revision as seen by backend scripts (subset of trilium-core's `BRevision`).++<table>+ <thead>+ <tr>+ <th>Member</th>+ <th>Description</th>+ </tr>+ </thead>+ <tbody>+ <tr>+ <td><code>revisionId</code><br><em>optional</em></td>+ <td><p><code>string</code></p></td>+ </tr>+ <tr>+ <td><code>noteId</code></td>+ <td><p><code>string</code></p></td>+ </tr>+ <tr>+ <td><code>type</code></td>+ <td><p><code>string</code></p></td>+ </tr>+ <tr>+ <td><code>mime</code></td>+ <td><p><code>string</code></p></td>+ </tr>+ <tr>+ <td><code>title</code></td>+ <td><p><code>string</code></p></td>+ </tr>+ <tr>+ <td><code>dateLastEdited</code><br><em>optional</em></td>+ <td><p><code>string</code></p></td>+ </tr>+ <tr>+ <td><code>utcDateLastEdited</code><br><em>optional</em></td>+ <td><p><code>string</code></p></td>+ </tr>+ <tr>+ <td><code>contentLength</code><br><em>optional</em></td>+ <td><p><code>number</code></p></td>+ </tr>+ <tr>+ <td><code>getContent</code></td>+ <td><pre><code class="language-application-typescript">getContent(): string | Uint8Array<ArrayBufferLike></code></pre></td>+ </tr>+ <tr>+ <td><code>getJsonContent</code></td>+ <td><pre><code class="language-application-typescript">getJsonContent(): unknown</code></pre></td>+ </tr>+ </tbody>+</table>++## `ScriptDayjsInstance`++A date as day.js wraps it (subset).++<table>+ <thead>+ <tr>+ <th>Member</th>+ <th>Description</th>+ </tr>+ </thead>+ <tbody>+ <tr>+ <td><code>format</code></td>+ <td><pre><code class="language-application-typescript">format(template?: string): string</code></pre></td>+ </tr>+ <tr>+ <td><code>add</code></td>+ <td><pre><code class="language-application-typescript">add(value: number, unit: string): ScriptDayjsInstance</code></pre></td>+ </tr>+ <tr>+ <td><code>subtract</code></td>+ <td><pre><code class="language-application-typescript">subtract(value: number, unit: string): ScriptDayjsInstance</code></pre></td>+ </tr>+ <tr>+ <td><code>toDate</code></td>+ <td><pre><code class="language-application-typescript">toDate(): Date</code></pre></td>+ </tr>+ </tbody>+</table>++## Types++### `ScriptDayjs`++Minimal day.js surface (the real API exposes the full day.js factory).++```typescript+type ScriptDayjs = (date?: string | number | Date) => ScriptDayjsInstance+```++### `ScriptAttribute`++| Property | Description |+| --- | --- |+| `attributeId` | `string` |+| `type` | `"label" \| "relation"` |+| `name` | `string` |+| `value` | `string` |+| `isInheritable` | `boolean` |+| `isOwned` | `boolean` |++### `ScriptNoteAndBranch`++Result of the backend note-creation helpers.++| Property | Description |+| --- | --- |+| `note` | `ScriptBNote` |+| `branch` | `ScriptBBranch` |++### `ScriptSubtreeOpts`++Options accepted by the subtree traversal helpers on `ScriptBNote`.++| Property | Description |+| --- | --- |+| `includeArchived` <br>_optional_ | `boolean` |+| `includeHidden` <br>_optional_ | `boolean` |+| `resolveSearch` <br>_optional_ | `boolean` |++### `ScriptSubtreeRelationship`++A single parent→child link in a subtree (`ScriptBNote.getSubtree`).++| Property | Description |+| --- | --- |+| `parentNoteId` | `string` |+| `childNoteId` | `string` |++### `ScriptNotePathRecord`++One resolved tree path to a note (subset of the client's `NotePathRecord`).++| Property | Description |+| --- | --- |+| `isArchived` | `boolean` |+| `isInHoistedSubTree` | `boolean` |+| `isSearch` <br>_optional_ | `boolean` |+| `notePath` | `string[]` |+| `isHidden` | `boolean` |++### `ScriptAttachment`++An attachment as seen by frontend scripts (subset of the client's `FAttachment`).++| Property | Description |+| --- | --- |+| `attachmentId` | `string` |+| `ownerId` | `string` |+| `role` | `string` |+| `mime` | `string` |+| `title` | `string` |+| `utcDateModified` | `string` |+| `contentLength` | `number` |++### `ScriptSaveAttachmentInput`++Input accepted by `ScriptBNote.saveAttachment`.++| Property | Description |+| --- | --- |+| `attachmentId` <br>_optional_ | `string` |+| `role` | `string` |+| `mime` | `string` |+| `title` | `string` |+| `content` <br>_optional_ | `string \| Uint8Array<ArrayBufferLike>` |+| `position` <br>_optional_ | `number` |++### `ScriptCloneResponse`++Result of a clone operation (`ScriptBNote.cloneTo`); mirrors `CloneResponse`.++| Property | Description |+| --- | --- |+| `success` | `boolean` |+| `message` <br>_optional_ | `string` |+| `branchId` <br>_optional_ | `string` |+| `notePath` <br>_optional_ | `string` |\ No newline at end of filediff --git a/edit-docs-config.yaml b/edit-docs-config.yamlindex a49b7d9be6..327dd547ae 100644--- a/edit-docs-config.yaml+++ b/edit-docs-config.yaml@@ -19,6 +19,10 @@ noteMappings:entryPoint: "packages/commons/src/lib/electron_api_interface.ts"tsconfig: "packages/commons/tsconfig.lib.json"root: "ElectronApi"+ - noteId: "MEtfsqa5VwNi" # Scripting › Script API › Backend API+ entryPoint: "packages/commons/src/lib/script_api.ts"+ tsconfig: "packages/commons/tsconfig.lib.json"+ root: "BackendApi"- rootNoteId: "jdjRLhLV3TtI"path: "docs/Developer Guide"diff --git a/packages/commons/src/lib/script_api.ts b/packages/commons/src/lib/script_api.tsindex 7c6d4f6311..d8119dbe0b 100644--- a/packages/commons/src/lib/script_api.ts+++ b/packages/commons/src/lib/script_api.ts@@ -250,12 +250,15 @@ export interface ScriptNoteContext {}/** Minimal day.js surface (the real API exposes the full day.js factory). */-export type ScriptDayjs = (date?: string | number | Date) => {+export type ScriptDayjs = (date?: string | number | Date) => ScriptDayjsInstance;++/** A date as day.js wraps it (subset). */+export interface ScriptDayjsInstance {format(template?: string): string;- add(value: number, unit: string): ReturnType<ScriptDayjs>;- subtract(value: number, unit: string): ReturnType<ScriptDayjs>;+ add(value: number, unit: string): ScriptDayjsInstance;+ subtract(value: number, unit: string): ScriptDayjsInstance;toDate(): Date;-};+}type Func = ((...args: unknown[]) => unknown) | string;