chore(core): integrate note_set

This commit is contained in:
Elian Doran 2026-01-06 13:45:53 +02:00
parent 64b212b93e
commit ad3be73e1b
No known key found for this signature in database
4 changed files with 69 additions and 67 deletions

View File

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

View File

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

View File

@ -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,

View File

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