Repository navigation
feat: add Firestore CategoryStore with name reservations - #33
Merged
Merged
Conversation
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.
Summary
Adds a Firestore implementation of
CategoryStore. It passes the same 18 contract tests as the in-memory store, run against the Firestore emulator.Category names are unique per user, ignoring case (ADR 0001). Firestore has no unique constraints, so each name has a reservation document in
categoryNames. Its ID is the normalised name (name:<trimmed, lower-cased name>) and it holds{ categoryId }. Because "Work" and "work" map to the same document ID, only one of them can be reserved.How each method works
createcreatethe category and its reservationALREADY_EXISTS, which becomesname-taken. This also covers two concurrent creates of the same name.get/listlistsorts in code withlocaleCompare("en", { sensitivity: "base" }), because Firestore'sorderByis case-sensitive.deleterenamename-takenandnot-foundare returned before any write. A rename that only changes capitalisation keeps the same reservation and only updates the name.Other details:
name, since the ID is the document ID./) are treated as not found rather than throwing.not-found,name-taken) are returned as result values. Anything unexpected is rethrown.Refactor
isValidDocumentIdandisNotFoundErrormoved from the task store to a sharedlib/firestore.ts, together with the newisAlreadyExistsError. The task store now imports them, and its behaviour is unchanged.Testing
firestore-category-store.test.tsruns the shared contract suite against the emulator. It's skipped whenFIRESTORE_EMULATOR_HOSTisn't set, as with the task store.category-test-<uuid>-), so tests don't share data.Not in this PR
categoryIdon tasks (later Phase 3 steps).categoryIdon tasks.