trilium
    Preparing search index...
    interface Api {
        __private: { becca: default };
        axios: AxiosStatic;
        cheerio: {
            default: CheerioAPI;
            version: string;
            contains(container: Element, contained: Element): boolean;
            html(options?: CheerioParserOptions): string;
            html(
                dom: string | Element | Cheerio,
                options?: CheerioParserOptions,
            ): string;
            load(
                html: string | Buffer<ArrayBufferLike>,
                options?: CheerioParserOptions,
            ): Root;
            load(element: Element | Element[], options?: CheerioParserOptions): Root;
            parseHTML(
                data: string,
                context?: null | Document,
                keepScripts?: boolean,
            ): Document[];
            root(): Cheerio;
            xml(dom?: string | Element | Cheerio): string;
        };
        currentNote: BNote;
        dayjs: __module;
        logMessages: Record<string, string[]>;
        logSpacedUpdates: Record<string, SpacedUpdate>;
        originEntity?: null | AbstractBeccaEntity<any>;
        sql: any;
        startNote?: null | BNote;
        xml2js: node_modules/@types/xml2js;
        backupNow(backupName: string): Promise<string>;
        createDataNote(
            parentNoteId: string,
            title: string,
            content: {},
        ): NoteAndBranch;
        createNewNote(params: NoteParams): NoteAndBranch;
        createNote(
            parentNoteId: string,
            title: string,
            content: string,
            extraOptions: Omit<
                NoteParams,
                "title"
                | "parentNoteId"
                | "content"
                | "type",
            > & { attributes?: AttributeRow[]; json?: boolean },
        ): NoteAndBranch;
        createOrUpdateLauncher(
            opts: {
                icon: string;
                id: string;
                isVisible: boolean;
                keyboardShortcut: string;
                scriptNoteId: string;
                targetNoteId: string;
                title: string;
                type: "script" | "note" | "customWidget";
                widgetNoteId?: string;
            },
        ): { note: BNote };
        createTextNote(
            parentNoteId: string,
            title: string,
            content: string,
        ): NoteAndBranch;
        ensureNoteIsAbsentFromParent(noteId: string, parentNoteId: string): void;
        ensureNoteIsPresentInParent(
            noteId: string,
            parentNoteId: string,
            prefix: string,
        ): { branch: null | BBranch };
        escapeHtml(string: string): string;
        exportSubtreeToZipFile(
            noteId: string,
            format: "html" | "markdown",
            zipFilePath: string,
        ): Promise<void>;
        getAppInfo(): {
            appVersion: string;
            buildDate: string;
            buildRevision: string;
            clipperProtocolVersion: string;
            dataDirectory: string;
            dbVersion: number;
            nodeVersion: string;
            syncVersion: number;
            utcDateTime: string;
        };
        getAttachment(attachmentId: string): null | BAttachment;
        getAttribute(attachmentId: string): null | BAttribute;
        getAttribute(attributeId: string): null | BAttribute;
        getBranch(branchId: string): null | BBranch;
        getDayNote(date: string, rootNote?: BNote): Promise<null | BNote>;
        getEtapiToken(etapiTokenId: string): null | BEtapiToken;
        getEtapiTokens(): BEtapiToken[];
        getInstanceName(): null | string;
        getMonthNote(date: string, rootNote: BNote): Promise<null | BNote>;
        getNote(noteId: string): null | BNote;
        getNotesWithLabel(name: string, value?: string): BNote[];
        getNoteWithLabel(name: string, value?: string): null | BNote;
        getOption(optionName: string): null | BOption;
        getOptions(): BOption[];
        getQuarterNote(date: string, rootNote: BNote): Promise<null | BNote>;
        getRevision(revisionId: string): null | BRevision;
        getRootCalendarNote(): null | BNote;
        getTodayNote(rootNote?: BNote): Promise<null | BNote>;
        getWeekFirstDayNote(date: string, rootNote: BNote): Promise<null | BNote>;
        getWeekNote(date: string, rootNote: BNote): Promise<null | BNote>;
        getYearNote(year: string, rootNote?: BNote): null | BNote;
        log(message: string): void;
        randomString(length: number): string;
        runOnFrontend(script: () => string | void, params: []): void;
        runOutsideOfSync(callback: () => void): Promise<void>;
        searchForNote(query: string, searchParams: SearchParams): null | BNote;
        searchForNotes(query: string, searchParams: SearchParams): BNote[];
        setNoteToParent(
            noteId: string,
            prefix: string,
            parentNoteId: null | string,
        ): void;
        sortNotes(
            parentNoteId: string,
            sortConfig: { foldersFirst?: boolean; reverse?: boolean; sortBy?: string },
        ): void;
        toggleNoteInParent(
            present: true,
            noteId: string,
            parentNoteId: string,
            prefix: string,
        ): void;
        transactional(func: () => void): any;
        unescapeHtml(string: string): string;
    }
    Index

    Properties

    __private: { becca: default }

    This object contains "at your risk" and "no BC guarantees" objects for advanced use cases.

    Type declaration

    • becca: default

      provides access to the backend in-memory object graph, see Becca

    Axios library for HTTP requests. See https://axios-http.com for documentation

    use native (browser compatible) fetch() instead

    cheerio: {
        default: CheerioAPI;
        version: string;
        contains(container: Element, contained: Element): boolean;
        html(options?: CheerioParserOptions): string;
        html(
            dom: string | Element | Cheerio,
            options?: CheerioParserOptions,
        ): string;
        load(
            html: string | Buffer<ArrayBufferLike>,
            options?: CheerioParserOptions,
        ): Root;
        load(element: Element | Element[], options?: CheerioParserOptions): Root;
        parseHTML(
            data: string,
            context?: null | Document,
            keepScripts?: boolean,
        ): Document[];
        root(): Cheerio;
        xml(dom?: string | Element | Cheerio): string;
    }

    cheerio library for HTML parsing and manipulation. See https://cheerio.js.org for documentation

    currentNote: BNote

    Note where the script is currently executing. This comes into play when your script is spread in multiple code notes, the script starts in "startNote", but then through function calls may jump into another note (currentNote). A similar concept in C would be FILE Don't mix this up with the concept of active note.

    dayjs: __module

    day.js library for date manipulation. See https://day.js.org for documentation

    logMessages: Record<string, string[]>
    logSpacedUpdates: Record<string, SpacedUpdate>
    originEntity?: null | AbstractBeccaEntity<any>

    Entity whose event triggered this execution

    sql: any

    sql

    startNote?: null | BNote

    Note where the script started executing (entrypoint). As an analogy, in C this would be the file which contains the main() function of the current process.

    xml2js library for XML parsing. See https://github.com/Leonidas-from-XIV/node-xml2js for documentation

    Methods

    • Parameters

      • backupName: string

        If the backupName is e.g. "now", then the backup will be written to "backup-now.db" file

      Returns Promise<string>

      resolves once the backup is finished

    • 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.

      Parameters

      • parentNoteId: string
      • title: string
      • content: {}

      Returns NoteAndBranch

    • Parameters

      • parentNoteId: string

        create new note under this parent

      • title: string
      • content: string
      • extraOptions: Omit<NoteParams, "title" | "parentNoteId" | "content" | "type"> & {
            attributes?: AttributeRow[];
            json?: boolean;
        }
        • Optionalattributes?: AttributeRow[]
        • Optionaljson?: boolean

          should the note be JSON

      Returns NoteAndBranch

      object contains newly created entities note and branch

      please use createTextNote() with similar API for simpler use cases or createNewNote() for more complex needs

    • Creates a new launcher to the launchbar. If the launcher (id) already exists, it will be updated.

      Parameters

      • opts: {
            icon: string;
            id: string;
            isVisible: boolean;
            keyboardShortcut: string;
            scriptNoteId: string;
            targetNoteId: string;
            title: string;
            type: "script" | "note" | "customWidget";
            widgetNoteId?: string;
        }
        • icon: string

          name of the boxicon to be used (e.g. "bx-time")

        • id: string

          id of the launcher, only alphanumeric at least 6 characters long

        • isVisible: boolean

          if true, will be created in the "Visible launchers", otherwise in "Available launchers"

        • keyboardShortcut: string

          will activate the target note/script upon pressing, e.g. "ctrl+e"

        • scriptNoteId: string

          for type "script"

        • targetNoteId: string

          for type "note"

        • title: string
        • type: "script" | "note" | "customWidget"

          one of

          • "note" - activating the launcher will navigate to the target note (specified in targetNoteId param)
          • "script" - activating the launcher will execute the script (specified in scriptNoteId param)
          • "customWidget" - the launcher will be rendered with a custom widget (specified in widgetNoteId param)
        • OptionalwidgetNoteId?: string

          for type "customWidget"

      Returns { note: BNote }

    • If there's a branch between note and parent note, remove it. Otherwise, do nothing.

      Parameters

      • noteId: string
      • parentNoteId: string

      Returns void

    • If there's no branch between note and parent note, create one. Otherwise, do nothing. Returns the new or existing branch.

      Parameters

      • noteId: string
      • parentNoteId: string
      • prefix: string

        if branch is created between note and parent note, set this prefix

      Returns { branch: null | BBranch }

    • Parameters

      • noteId: string
      • format: "html" | "markdown"

        either 'html' or 'markdown'

      • zipFilePath: string

      Returns Promise<void>

    • Returns {
          appVersion: string;
          buildDate: string;
          buildRevision: string;
          clipperProtocolVersion: string;
          dataDirectory: string;
          dbVersion: number;
          nodeVersion: string;
          syncVersion: number;
          utcDateTime: string;
      }

    • Returns day note for given date. If such note doesn't exist, it is created.

      Parameters

      • date: string

        in YYYY-MM-DD format

      • OptionalrootNote: BNote

        specify calendar root note, normally leave empty to use the default calendar

      Returns Promise<null | BNote>

    • Instance name identifies particular Trilium instance. It can be useful for scripts if some action needs to happen on only one specific instance.

      Returns null | string

    • Returns month note for given date. If such a note doesn't exist, it is created.

      Parameters

      • date: string

        in YYYY-MM format

      • rootNote: BNote

        specify calendar root note, normally leave empty to use the default calendar

      Returns Promise<null | BNote>

    • Retrieves notes with given label name & value

      Parameters

      • name: string

        attribute name

      • Optionalvalue: string

        attribute value

      Returns BNote[]

    • Retrieves first note with given label name & value

      Parameters

      • name: string

        attribute name

      • Optionalvalue: string

        attribute value

      Returns null | BNote

    • Returns quarter note for given date. If such a note doesn't exist, it is created.

      Parameters

      • date: string

        in YYYY-MM format

      • rootNote: BNote

        specify calendar root note, normally leave empty to use the default calendar

      Returns Promise<null | BNote>

    • Returns today's day note. If such note doesn't exist, it is created.

      Parameters

      • OptionalrootNote: BNote

        specify calendar root note, normally leave empty to use the default calendar

      Returns Promise<null | BNote>

    • Returns note for the first date of the week of the given date.

      Parameters

      • date: string

        in YYYY-MM-DD format

      • rootNote: BNote

        specify calendar root note, normally leave empty to use the default calendar

      Returns Promise<null | BNote>

    • Returns week note for given date. If such a note doesn't exist, it is created.

      Parameters

      • date: string

        in YYYY-MM-DD format

      • rootNote: BNote

        specify calendar root note, normally leave empty to use the default calendar

      Returns Promise<null | BNote>

    • Returns year note for given year. If such a note doesn't exist, it is created.

      Parameters

      • year: string

        in YYYY format

      • OptionalrootNote: BNote

        specify calendar root note, normally leave empty to use the default calendar

      Returns null | BNote

    • Return randomly generated string of given length. This random string generation is NOT cryptographically secure.

      Parameters

      • length: number

        of the string

      Returns string

      random string

    • 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.

      Parameters

      • script: () => string | void

        script to be executed on the frontend

      • params: []

        list of parameters to the anonymous function to be sent to frontend

      Returns void

      no return value is provided.

    • Sync process can make data intermittently inconsistent. Scripts which require strong data consistency can use this function to wait for a possible sync process to finish and prevent new sync process from starting while it is running.

      Because this is an async process, the inner callback doesn't have automatic transaction handling, so in case you need to make some DB changes, you need to surround your call with api.transactional(...)

      Parameters

      • callback: () => void

        function to be executed while sync process is not running

      Returns Promise<void>

      resolves once the callback is finished (callback is awaited)

    • This method finds note by its noteId and prefix and either sets it to the given parentNoteId or removes the branch (if parentNoteId is not given).

      This method looks similar to toggleNoteInParent() but differs because we're looking up branch by prefix.

      Parameters

      • noteId: string
      • prefix: string
      • parentNoteId: null | string

      Returns void

      this method is pretty confusing and serves specialized purpose only

    • Sort child notes of a given note.

      Parameters

      • parentNoteId: string
      • sortConfig: { foldersFirst?: boolean; reverse?: boolean; sortBy?: string }

      Returns void

    • Based on the value, either create or remove branch between note and parent note.

      Parameters

      • present: true

        true if we want the branch to exist, false if we want it gone

      • noteId: string
      • parentNoteId: string
      • prefix: string

        if branch is created between note and parent note, set this prefix

      Returns void

    • This functions wraps code which is supposed to be running in transaction. If transaction already exists, then we'll use that transaction.

      Parameters

      • func: () => void

      Returns any

      result of func callback