백엔드 스크립트 API

연결된 공식 문서의 한국어 사본입니다. 함수 이름과 코드 문법은 원문을 유지했습니다. 외부 문서는 운영 버전과 다를 수 있으므로 지원 여부를 확인하세요. 공식 원문 보기

인터페이스 Api

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, 값?: string): BNote[];
    getNoteWithLabel(name: string, 값?: 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;
}
목차

속성

__private: { becca: default }

이 객체에는 다음 특성을 가진 고급 기능 객체가 들어 있습니다. "사용자가 영향을 판단해야 함" 및 "하위 호환성 보장 없음" 고급 사용 사례를 위한 객체입니다.

형식 선언

  • becca: default

    백엔드의 메모리 내 객체 그래프에 접근합니다. 참고: Becca

HTTP 요청을 위한 Axios 라이브러리입니다. 참고: https://axios-http.com 라이브러리 사용 안내

대신 브라우저와 호환되는 기본 fetch()를 사용하세요.

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;
}

HTML 분석과 처리를 위한 cheerio 라이브러리입니다. 참고: https://cheerio.js.org 라이브러리 사용 안내

currentNote: BNote

현재 스크립트가 실행 중인 노트입니다. 코드가 여러 노트로 나뉘어 있으면 처음 실행을 시작한 노트는 다음과 같습니다: "startNote"함수 호출을 통해 다른 노트인 currentNote로 실행 위치가 바뀔 수 있습니다. C 언어에서는 다음 개념과 비슷합니다: FILE 현재 화면에서 활성화된 노트와 혼동하지 마세요.

dayjs: __module

날짜 처리를 위한 day.js 라이브러리입니다. 참고: https://day.js.org 라이브러리 사용 안내

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

이 실행을 시작하게 한 이벤트의 엔터티

sql: any

sql

startNote?: null | BNote

스크립트 실행이 시작된 노트입니다. C 언어로 비유하면 현재 프로세스의 main() 함수가 들어 있는 파일에 해당합니다.

XML 분석을 위한 xml2js 라이브러리입니다. 참고: https://github.com/Leonidas-from-XIV/node-xml2js 라이브러리 사용 안내

메서드

  • 매개변수

    • backupName: string

      예를 들어 backupName에 다음 값을 지정하면: "now"백업은 다음 이름으로 저장됩니다: "backup-now.db" 파일

    반환값 Promise<string>

    백업이 끝나면 완료됩니다.

  • JSON으로 직렬화할 수 있는 객체를 데이터 노트로 만듭니다. 생성되는 노트의 유형은 code이며 MIME 유형은 JSON입니다. 더 많은 옵션은 createNewNote()를 확인하세요.

    매개변수

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

    반환값 NoteAndBranch

  • 매개변수

    • parentNoteId: string

      이 상위 노트 아래에 새 노트 생성

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

        노트에 JSON을 사용할지 여부

    반환값 NoteAndBranch

    새로 생성한 노트와 가지 엔터티가 들어 있는 객체

    간단한 용도에는 비슷한 API인 createTextNote()를 사용하고 복잡한 요구에는 createNewNote()를 사용하세요.

  • 실행 도구 모음에 새 실행 도구를 만듭니다. 같은 ID가 있으면 변경합니다.

    매개변수

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

        사용할 Boxicons 아이콘 이름. 예: "bx-time")

      • id: string

        영문과 숫자로만 구성된 6자리 이상의 실행 도구 ID

      • isVisible: boolean

        true이면 다음 위치에 생성합니다: "표시할 실행 도구"그 외에는 다음 위치에 생성합니다: "사용 가능한 실행 도구"

      • keyboardShortcut: string

        누르면 대상 노트나 스크립트를 활성화할 단축키. 예: "ctrl+e"

      • scriptNoteId: string

        해당 유형: "script"

      • targetNoteId: string

        해당 유형: "note"

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

        다음 중 하나

        • "note" 실행 도구를 누르면 targetNoteId로 지정한 노트로 이동합니다.
        • "script" 실행 도구를 누르면 scriptNoteId로 지정한 스크립트를 실행합니다.
        • "customWidget" widgetNoteId로 지정한 사용자 지정 위젯으로 실행 도구를 표시합니다.
      • OptionalwidgetNoteId?: string

        해당 유형: "customWidget"

    반환값 { note: BNote }

  • 텍스트 노트를 만듭니다. 더 많은 옵션은 createNewNote()를 확인하세요.

    매개변수

    • parentNoteId: string
    • title: string
    • content: string

    반환값 NoteAndBranch

  • 노트와 상위 노트 사이에 가지가 있으면 삭제합니다. 없으면 아무 작업도 하지 않습니다.

    매개변수

    • noteId: string
    • parentNoteId: string

    반환값 void

  • 노트와 상위 노트 사이에 가지가 없으면 만듭니다. 이미 있으면 그대로 둡니다. 새 가지 또는 기존 가지를 반환합니다.

    매개변수

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

      노트와 상위 노트 사이에 가지를 새로 만들 때 지정할 접두사

    반환값 { branch: null | BBranch }

  • 매개변수

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

      html 또는 markdown

    • zipFilePath: string

    반환값 Promise<void>

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

  • 지정한 날짜의 일별 노트를 반환합니다. 없으면 만듭니다.

    매개변수

    • date: string

      YYYY-MM-DD 형식

    • OptionalrootNote: BNote

      달력 루트 노트를 지정합니다. 일반적으로 비워 두어 기본 달력을 사용합니다.

    반환값 Promise<null | BNote>

  • 인스턴스 이름은 개별 Trilium 실행 환경을 구분합니다. 특정 인스턴스에서만 작업을 실행해야 하는 스크립트에 유용합니다.

    반환값 null | string

  • 지정한 날짜의 월별 노트를 반환합니다. 없으면 만듭니다.

    매개변수

    • date: string

      YYYY-MM 형식

    • rootNote: BNote

      달력 루트 노트를 지정합니다. 일반적으로 비워 두어 기본 달력을 사용합니다.

    반환값 Promise<null | BNote>

  • 지정한 라벨 이름을 가진 노트들을 조회합니다. & 값

    매개변수

    • name: string

      속성 이름

    • Optional값: string

      속성값

    반환값 BNote[]

  • 지정한 라벨 이름을 가진 첫 번째 노트를 조회합니다. & 값

    매개변수

    • name: string

      속성 이름

    • Optional값: string

      속성값

    반환값 null | BNote

  • 지정한 날짜의 분기별 노트를 반환합니다. 없으면 만듭니다.

    매개변수

    • date: string

      YYYY-MM 형식

    • rootNote: BNote

      달력 루트 노트를 지정합니다. 일반적으로 비워 두어 기본 달력을 사용합니다.

    반환값 Promise<null | BNote>

  • 오늘의 일별 노트를 반환합니다. 없으면 만듭니다.

    매개변수

    • OptionalrootNote: BNote

      달력 루트 노트를 지정합니다. 일반적으로 비워 두어 기본 달력을 사용합니다.

    반환값 Promise<null | BNote>

  • 지정한 날짜가 속한 주의 첫날에 해당하는 노트를 반환합니다.

    매개변수

    • date: string

      YYYY-MM-DD 형식

    • rootNote: BNote

      달력 루트 노트를 지정합니다. 일반적으로 비워 두어 기본 달력을 사용합니다.

    반환값 Promise<null | BNote>

  • 지정한 날짜의 주별 노트를 반환합니다. 없으면 만듭니다.

    매개변수

    • date: string

      YYYY-MM-DD 형식

    • rootNote: BNote

      달력 루트 노트를 지정합니다. 일반적으로 비워 두어 기본 달력을 사용합니다.

    반환값 Promise<null | BNote>

  • 지정한 연도의 연도별 노트를 반환합니다. 없으면 만듭니다.

    매개변수

    • year: string

      YYYY 형식

    • OptionalrootNote: BNote

      달력 루트 노트를 지정합니다. 일반적으로 비워 두어 기본 달력을 사용합니다.

    반환값 null | BNote

  • 지정한 메시지를 Trilium 로그와 화면의 로그 창에 기록합니다.

    매개변수

    • message: string

    반환값 void

  • 지정한 길이의 임의 문자열을 반환합니다. 암호학적으로 안전한 난수를 만드는 함수가 아닙니다.

    매개변수

    • length: number

      문자열 기준

    반환값 string

    임의 문자열

  • 지정한 익명 함수를 프런트엔드에서 실행합니다. 내부적으로 함수를 문자열로 직렬화한 뒤 WebSocket으로 전송합니다. 서로 다른 탭 등 여러 프런트엔드가 연결돼 있으면 모든 인스턴스에서 실행합니다.

    매개변수

    • script: () => string | void

      프런트엔드에서 실행할 스크립트

    • params: []

      프런트엔드로 보낼 익명 함수의 매개변수 목록

    반환값 void

    반환값이 없습니다.

  • 동기화 중에는 데이터가 일시적으로 일관되지 않을 수 있습니다. 강한 일관성이 필요한 스크립트는 이 함수로 진행 중인 동기화가 끝나기를 기다리고 실행 중 새 동기화가 시작되지 않게 할 수 있습니다.

    비동기 처리이므로 내부 콜백에는 자동 트랜잭션 처리가 적용되지 않습니다. 데이터베이스를 변경하려면 api.transactional(...)로 호출을 감싸야 합니다.

    매개변수

    • callback: () => void

      동기화가 실행되지 않는 동안 실행할 함수

    반환값 Promise<void>

    콜백이 끝날 때까지 기다린 뒤 완료됩니다.

  • noteId와 접두사로 노트를 찾아 지정한 parentNoteId 아래에 배치합니다. parentNoteId를 지정하지 않으면 가지를 삭제합니다.

    toggleNoteInParent()와 비슷하지만 접두사로 가지를 찾는다는 차이가 있습니다.

    매개변수

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

    반환값 void

    동작을 혼동하기 쉬운 메서드이며 특수한 용도에만 사용합니다.

  • 지정한 노트의 하위 노트를 정렬합니다.

    매개변수

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

    반환값 void

  • 값에 따라 노트와 상위 노트 사이의 가지를 만들거나 삭제합니다.

    매개변수

    • present: true

      가지를 유지하려면 true를 사용하고 없애려면 false를 사용합니다.

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

      노트와 상위 노트 사이에 가지를 새로 만들 때 지정할 접두사

    반환값 void

  • 트랜잭션 안에서 실행할 코드를 감쌉니다. 이미 트랜잭션이 있으면 해당 트랜잭션을 사용합니다.

    매개변수

    • func: () => void

    반환값 any

    func 콜백의 결과

  • 매개변수

    • string: string

      이스케이프를 해제할 대상

    반환값 string

    이스케이프를 해제한 문자열