Repository navigation
Read smart folders, tags and note links - #3
Merged
Merged
Conversation
Add Store.smartFolders(), tags(for:), tags(), links(from:), and backlinks(to:). They read the database rows of smart folders and of tag and note-link inline attachments, without decoding note contents.
This was referenced Nov 17, 2026
…ments Tag and link reads returned an empty result from an expired snapshot when the database had no inline attachments or the caller passed no notes. They now throw connectionClosed, as the other reads do. Without the column that marks locked notes, they throw unsupportedSchema instead of reading every note as unlocked.
backlinks(to:) read every note link in the library and filtered them in Swift. A LIKE condition on the link's token now selects the rows that can name the target, and the parsed identifier still decides.
The reads follow database rows, which can remain after a tag or link leaves the text. The link reads cover inline note links only. The smart folder query format is an example from another project that hasn't been checked.
Folder, Account, and Note have no public initializer, because only reads create them. The same holds for SmartFolder and TagSummary, so callers can no longer create one with an empty query or a negative count.
Validate compares tags(for:) and links(from:) with the tags and note links decoded from each note, compares the tag inventory with the per-note read, and checks backlinks(to:) for a sample of link targets. It prints the number of smart folders and the shapes of their queries, with values replaced by JSON types. With --smart-folders, it also prints each smart folder's name and stored query.
Packages that use TopoText build these values in their own tests, as they can with Note.Tag and Note.Link.
A run of Validate against a real database on macOS 27.0.1 found one smart folder with one tag rule. Record its query in place of the caution that the reported form was unchecked.
A run against a real database on macOS 27.0.1 found an inline note link whose token gave no note identifier. Validate now prints the form of each link token and of the columns in the link rows, with each identifier replaced by its length and kind.
On macOS 27.0.1, Validate found no remaining row soon after a tag was deleted from a note. State the limit as a condition, and drop a promise about the count that a public initializer can't keep.
A real database on macOS 27.0.1 holds an inline note link whose token has a host, one query item, and the note's identifier, where the parser expected applenotes:note/<identifier>. The parser now also reads applenotes://showNote?identifier=<identifier>, and backlinks select rows by the identifier alone. This also gives Note.Attachment.linkedNoteID a value for such links.
mattt
marked this pull request as ready for review
November 20, 2026 13:01
mattt
added a commit
to oliverames/iMCP
that referenced
this pull request
Nov 20, 2026
mattt/TopoText#3 is merged and released as 0.3.0, so the package reference moves from the fork's branch to that release.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds reads for smart folders, native tags and note-to-note links, working from database rows rather than decoding each note:
Store.smartFolders()Store.tags(for:)Store.tags(includingRecentlyDeleted:), a tag inventory with countsStore.links(from:)Store.backlinks(to:)Snapshotgets the same five. Locked and recently deleted notes are skipped.The 179 tests pass, including 9 new ones, but everything ran on fixtures. Two things come from reading other projects rather than from observation: that inline-attachment rows can linger after a tag or link is deleted, and the stored smart-folder query format. So the per-note counts can run high.
NoteStore.mdsays so. It's a draft until I've checked it against a real NoteStore.