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
chore(core): integrate note_set
Elian Doranad3be73e1b81
diff --git a/apps/server/src/services/search/note_set.ts b/apps/server/src/services/search/note_set.tsindex bab76afa5e..10ecb41346 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<string>;-- 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.tsindex 8c8099cd44..dd4092fb50 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.tsindex 5c10216df7..e6940a14f6 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.tsnew file mode 100644index 0000000000..c621017786--- /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<string>;++ 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;