mirror of
https://github.com/zadam/trilium.git
synced 2026-01-18 12:34:24 +01:00
chore(core): integrate note_set
This commit is contained in:
parent
64b212b93e
commit
ad3be73e1b
@ -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;
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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,
|
||||
|
||||
65
packages/trilium-core/src/services/search/note_set.ts
Normal file
65
packages/trilium-core/src/services/search/note_set.ts
Normal 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;
|
||||
Loading…
x
Reference in New Issue
Block a user