Skip to content

Read smart folders, tags and note links - #3

Merged
mattt merged 12 commits into
mattt:mainfrom
oliverames:feat/smart-folders-tags-links
Nov 20, 2026
Merged

mattt merged 12 commits into
mattt:mainfrom
oliverames:feat/smart-folders-tags-links

Conversation

@oliverames

Copy link
Copy Markdown
Contributor

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 counts
  • Store.links(from:)
  • Store.backlinks(to:)

Snapshot gets 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.md says so. It's a draft until I've checked it against a real NoteStore.

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.
mattt added 11 commits November 20, 2026 04:22
…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
mattt marked this pull request as ready for review November 20, 2026 13:01
@mattt
mattt merged commit 7b04863 into mattt:main Nov 20, 2026
4 checks passed
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants