refactor(util): let a collection cast its own ids (#821 spike) - #917
Draft
rmdes wants to merge 1 commit into
Draft
refactor(util): let a collection cast its own ids (#821 spike)#917rmdes wants to merge 1 commit into
rmdes wants to merge 1 commit into
Conversation
Answers one question: does `addCollection` hold as a storage seam? `lib/sqlite.js` implements the subset of the MongoDB collection interface Indiekit uses, on `node:sqlite`. `find`, `findOne`, `countDocuments`, `insertOne` and `deleteOne` all port over without touching their callers. `getCursor` did not, because it calls `getObjectId` — it names a MongoDB type inside code that is meant to be storage-neutral. `collection.castId` lets a collection say how to read its own ids; MongoDB collections have no such property, so they keep coercing to an ObjectId exactly as before. Also adds the cursor test that was missing: the existing ones pass `after._id`, a live ObjectId, so `getObjectId` is a no-op there and its removal went undetected by the whole suite. Over HTTP the id is always a string. Not a migration, and not a schema proposal.
paulrobertlloyd
force-pushed
the
main
branch
2 times, most recently
from
August 27, 2026 20:07
67b3847 to
fa1d368
Compare
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.
Draft, as offered in #821 — opened so the branch is easier to read than a
tree link. Not a proposal to merge, and not a schema proposal.
What it shows
util/lib/sqlite.jsimplements the collection interface onnode:sqlite,and upstream's
getCursorruns against it unmodified. The collectioninterface holds:
insertOne,find,findOne,countDocumentsandcursor pagination all work without changes to their callers.
The one seam needed is id casting:
MongoDB collections have no
castId, so they coerce to anObjectIdexactly as before; the SQLite one supplies
Number. No existing callerchanges.
A test gap it uncovered
Deleting the
getObjectIdcalls outright left the wholeutilsuite and145/145 in
endpoint-micropubpassing. The existing cursor tests passafter._id— a liveObjectId— andgetObjectId(anObjectId)is a no-op,so nothing could detect the removal. Over HTTP
?after=is always astring, which is where the coercion does its work. The suite could not
tell working pagination from broken. The missing case is added here.
Not covered
aggregate— the two$toDate/$addFieldscount pipelines. Everythingelse in the spike is exercised by tests.
This does not touch the
_id-in-URLs question, which I still think is theactual decision to make.
Rebased onto
mainso the lint step reflects this branch rather than theendpoint-shareREADME formatting fixed in #910/#914.