From ad3be73e1b81dafd4a4ab508a85c3e3a7a243a6f Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Tue, 6 Jan 2026 13:45:53 +0200 Subject: [PATCH] chore(core): integrate note_set --- apps/server/src/services/search/note_set.ts | 67 +------------------ .../trilium-core/src/becca/becca-interface.ts | 2 +- packages/trilium-core/src/index.ts | 2 + .../src/services/search/note_set.ts | 65 ++++++++++++++++++ 4 files changed, 69 insertions(+), 67 deletions(-) create mode 100644 packages/trilium-core/src/services/search/note_set.ts diff --git a/apps/server/src/services/search/note_set.ts b/apps/server/src/services/search/note_set.ts index bab76afa5..10ecb4134 100644 --- a/apps/server/src/services/search/note_set.ts +++ b/apps/server/src/services/search/note_set.ts @@ -1,67 +1,2 @@ -"use strict"; - -import type BNote from "../../becca/entities/bnote.js"; - -class NoteSet { - private noteIdSet: Set; - - notes: BNote[]; - sorted: boolean; - - constructor(notes: BNote[] = []) { - this.notes = notes; - this.noteIdSet = new Set(notes.map((note) => note.noteId)); - this.sorted = false; - } - - add(note: BNote) { - if (!this.hasNote(note)) { - this.notes.push(note); - this.noteIdSet.add(note.noteId); - } - } - - addAll(notes: BNote[]) { - for (const note of notes) { - this.add(note); - } - } - - hasNote(note: BNote) { - return this.hasNoteId(note.noteId); - } - - hasNoteId(noteId: string) { - return this.noteIdSet.has(noteId); - } - - mergeIn(anotherNoteSet: NoteSet) { - this.addAll(anotherNoteSet.notes); - } - - minus(anotherNoteSet: NoteSet) { - const newNoteSet = new NoteSet(); - - for (const note of this.notes) { - if (!anotherNoteSet.hasNoteId(note.noteId)) { - newNoteSet.add(note); - } - } - - return newNoteSet; - } - - intersection(anotherNoteSet: NoteSet) { - const newNoteSet = new NoteSet(); - - for (const note of this.notes) { - if (anotherNoteSet.hasNote(note)) { - newNoteSet.add(note); - } - } - - return newNoteSet; - } -} - +import { NoteSet } from "@triliumnext/core"; export default NoteSet; diff --git a/packages/trilium-core/src/becca/becca-interface.ts b/packages/trilium-core/src/becca/becca-interface.ts index 8c8099cd4..dd4092fb5 100644 --- a/packages/trilium-core/src/becca/becca-interface.ts +++ b/packages/trilium-core/src/becca/becca-interface.ts @@ -1,4 +1,3 @@ -import NoteSet from "../services/search/note_set.js"; import { NotFoundError } from "../errors.js"; import type BOption from "./entities/boption.js"; import type BNote from "./entities/bnote.js"; @@ -12,6 +11,7 @@ import BBlob from "./entities/bblob.js"; import BRecentNote from "./entities/brecent_note.js"; import type AbstractBeccaEntity from "./entities/abstract_becca_entity.js"; import { getSql } from "src/services/sql/index.js"; +import NoteSet from "src/services/search/note_set.js"; /** * Becca is a backend cache of all notes, branches, and attributes. diff --git a/packages/trilium-core/src/index.ts b/packages/trilium-core/src/index.ts index 5c10216df..e6940a14f 100644 --- a/packages/trilium-core/src/index.ts +++ b/packages/trilium-core/src/index.ts @@ -43,6 +43,8 @@ export { default as AbstractBeccaEntity } from "./becca/entities/abstract_becca_ export { default as Becca } from "./becca/becca-interface"; export type { NotePojo } from "./becca/becca-interface"; +export { default as NoteSet } from "./services/search/note_set"; + export function initializeCore({ dbConfig, executionContext, crypto }: { dbConfig: SqlServiceParams, executionContext: ExecutionContext, diff --git a/packages/trilium-core/src/services/search/note_set.ts b/packages/trilium-core/src/services/search/note_set.ts new file mode 100644 index 000000000..c62101778 --- /dev/null +++ b/packages/trilium-core/src/services/search/note_set.ts @@ -0,0 +1,65 @@ +import type BNote from "../../becca/entities/bnote.js"; + +class NoteSet { + private noteIdSet: Set; + + notes: BNote[]; + sorted: boolean; + + constructor(notes: BNote[] = []) { + this.notes = notes; + this.noteIdSet = new Set(notes.map((note) => note.noteId)); + this.sorted = false; + } + + add(note: BNote) { + if (!this.hasNote(note)) { + this.notes.push(note); + this.noteIdSet.add(note.noteId); + } + } + + addAll(notes: BNote[]) { + for (const note of notes) { + this.add(note); + } + } + + hasNote(note: BNote) { + return this.hasNoteId(note.noteId); + } + + hasNoteId(noteId: string) { + return this.noteIdSet.has(noteId); + } + + mergeIn(anotherNoteSet: NoteSet) { + this.addAll(anotherNoteSet.notes); + } + + minus(anotherNoteSet: NoteSet) { + const newNoteSet = new NoteSet(); + + for (const note of this.notes) { + if (!anotherNoteSet.hasNoteId(note.noteId)) { + newNoteSet.add(note); + } + } + + return newNoteSet; + } + + intersection(anotherNoteSet: NoteSet) { + const newNoteSet = new NoteSet(); + + for (const note of this.notes) { + if (anotherNoteSet.hasNote(note)) { + newNoteSet.add(note); + } + } + + return newNoteSet; + } +} + +export default NoteSet;