| 26 | import { SessionContent } from "./session-content.js"; |
| 27 | |
| 28 | export class NoteHistory implements ICollection { |
| 29 | name = "notehistory"; |
| 30 | sessionContent; |
| 31 | readonly collection: SQLCollection<"notehistory", HistorySession>; |
| 32 | constructor(private readonly db: Database) { |
| 33 | this.sessionContent = new SessionContent(db); |
| 34 | this.collection = new SQLCollection( |
| 35 | db.sql, |
| 36 | db.transaction, |
| 37 | "notehistory", |
| 38 | db.eventManager, |
| 39 | db.sanitizer |
| 40 | ); |
| 41 | } |
| 42 | |
| 43 | async init() { |
| 44 | await this.collection.init(); |
| 45 | await this.sessionContent.init(); |
| 46 | } |
| 47 | |
| 48 | // async get(noteId: string, order: "asc" | "desc" = "desc") { |
| 49 | // if (!noteId) return []; |
| 50 | |
| 51 | // // const indices = this.collection.indexer.indices; |
| 52 | // // const sessionIds = indices.filter((id) => id.startsWith(noteId)); |
| 53 | // // if (sessionIds.length === 0) return []; |
| 54 | // // const history = await this.getSessions(sessionIds); |
| 55 | |
| 56 | // // return history.sort(function (a, b) { |
| 57 | // // return b.dateModified - a.dateModified; |
| 58 | // // }); |
| 59 | // const history = await this.db |
| 60 | // .sql() |
| 61 | // .selectFrom("notehistory") |
| 62 | // .where("noteId", "==", noteId) |
| 63 | // .orderBy(`dateModified ${order}`) |
| 64 | // .selectAll() |
| 65 | // .execute(); |
| 66 | // return history as HistorySession[]; |
| 67 | // } |
| 68 | get(noteId: string) { |
| 69 | return new FilteredSelector<HistorySession>( |
| 70 | "notehistory", |
| 71 | this.db.sql().selectFrom("notehistory").where("noteId", "==", noteId) |
| 72 | ); |
| 73 | } |
| 74 | |
| 75 | async add( |
| 76 | sessionId: string, |
| 77 | content: Partial<NoteContent<boolean>> & { |
| 78 | noteId: string; |
| 79 | locked?: boolean; |
| 80 | title?: string; |
| 81 | } |
| 82 | ) { |
| 83 | const { noteId, locked } = content; |
| 84 | sessionId = `${noteId}_${sessionId}`; |
| 85 |
nothing calls this directly
no outgoing calls
no test coverage detected