fix(firestore): keep non-filter constraints out of Query.and composite - #114
Open
detail-app[bot] wants to merge 3 commits into
Open
detail-app[bot] wants to merge 3 commits into
detail-app[bot] wants to merge 3 commits into
Conversation
|
AGENTS.md requires tests to use `@effect/vitest`, like the admin function specs converted in 10bdc0f. The new admin and client builder specs added by this PR imported from `vitest` directly. `@effect/vitest` re-exports all of `vitest`, so the admin spec is a plain import swap (it has no `vi` usage). The client spec keeps `vi` on `vitest` because it uses `vi.hoisted`/`vi.mock`, which vitest's hoisting transformer only honours when `vi` is imported from `vitest` (or a redistributed specifier) — `@effect/vitest` is a plain re-export, so importing `vi` from it leaves the hoisted calls referencing an uninitialised binding (`Cannot access '__vi_import_1__' before initialization`).
AGENTS.md requires tests to use @effect/vitest, like the builder specs fixed in cf6a3b3. The query-combinator spec in the core package and the query-filter spec in the mock package imported from vitest directly. Neither file uses vi, so this is a plain import swap.
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.
Detail bug report: View on Detail
Closes #94
Bug
Query.and(...)mixes filter (where) and non-filter (orderBy,limit, cursors) constraints in a single call — a pattern shown across its JSDoc, the README, and AGENTS.md. Its flatten-vs-wrap heuristic has two branches: with no nestedAnd/Orit returns the constraints flat (works); when any child is anAnd/Orit wraps all children — includingOrderBy/Limit/LimitToLastand the cursor constraints — into oneAndnode. The Client and Admin query builders route every child of anAnd/Orthrough filter-only conversion and throwCannot use <Tag> inside AND/OR composite filterson the non-filter ones. The crash only surfaces when a nestedor(...)and a non-filter constraint are passed to the sameQuery.and(...)call; the transition from "works" to "crashes" is invisible to the caller.Fix
In
packages/effect-firebase/src/lib/firestore/query/query.ts, whenQuery.anddecides to wrap, it now partitions the children: only filter constraints (Where/And/Or) go into theAndcomposite; non-filter constraints are returned as top-level siblings after the composite, preserving their relative order. The emitted shape[and(filters...), orderBy, limit]is exactly what the Firestore client SDK'svalidateQueryConstraintArrayaccepts (compositeFilterCount=1, fieldFilterCount=0), and what both builders already handle on their non-composite path.Query.oris untouched (it is filter-only by contract). Introduced in8e11e17.Testing
Query.and/Query.orcombinators (core), the client builder, the admin builder, and the mock backend. With the fix reverted, 15 of those tests fail (builder throws, mock returns wrong/unsorted/unlimited results, structural asserts break); with the fix, all 52 pass.addOrderBy/addLimitform (['And','OrderBy','Limit']).validateQueryConstraintArrayconfirms the spread form[where, or, orderBy, limit]is still rejected (the SDK's own restriction, unchanged) while the fix's[and(where, or), orderBy, limit]shape is accepted.Automatic Fixes PRs can be configured here.