Skip to content

feat(firestore): typed dotted field paths in Query.where/orderBy - #84

Merged
fwal merged 3 commits into
mainfrom
fwal/nested-query-paths
Sep 11, 2026
Merged

feat(firestore): typed dotted field paths in Query.where/orderBy#84
fwal merged 3 commits into
mainfrom
fwal/nested-query-paths

Conversation

@fwal

@fwal fwal commented Sep 10, 2026

Copy link
Copy Markdown
Owner

Fixes #18

Query.where('metaData.type', '==', 'post') now type-checks. FieldKeys<S> / FieldType<S, K> derive from FieldPathRecord<S['Type']>, the type behind Repository.update's UpdateData, so nested maps are addressable with dotted paths and the value is typed as the leaf. Same descent rules (structs, Model.Struct, Schema.Class, Record, suspend, Option; arrays/DateTime/class instances are leaves) and the same MAX_FIELD_PATH_DEPTH.

Type-only: admin/client pass constraint.field straight to the SDK, and the mock already resolves dotted paths.

Exports FieldPathRecord, FieldPaths, FieldPathType from Firestore.

Note (pre-existing, unchanged): under contextual inference (repo.query(Query.where(...))) K widens to the full key union, so the value is checked against the union of all field types rather than the exact leaf. Exact when K is given explicitly.

🤖 Generated with Claude Code

FieldKeys/FieldType now derive from FieldPathRecord (the type behind
Repository.update's UpdateData), so nested map fields are addressable as
'metaData.type' with the leaf's type, following the same descent rules and
MAX_FIELD_PATH_DEPTH. Runtime already accepted dotted paths in the admin,
client and mock backends; this is type-only.

Fixes #18

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@github-actions github-actions Bot added 📖 docs Improvements or additions to documentation 📦 core labels Sep 10, 2026
@greptile-apps

greptile-apps Bot commented Sep 10, 2026

Copy link
Copy Markdown

Greptile Summary

The PR adds typed dotted field paths to Firestore query constraints by sharing the existing update-path type derivation.

  • Exposes FieldPathRecord, FieldPaths, FieldPathType, and FieldPathLeaf.
  • Adds nominal type-only brands to Firestore leaf and sentinel classes so structurally similar map values remain traversable.
  • Expands type-level tests and documentation for nested maps, recursive schemas, schema classes, and leaf values.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
packages/effect-firebase/src/lib/firestore/model/update-path.ts Generalizes dotted-path derivation to class and recursive object types while nominally excluding atomic Firestore values.
packages/effect-firebase/src/lib/firestore/query/query.ts Derives query field names and values from the shared dotted-path record types.
packages/effect-firebase/src/lib/firestore/model/update-path.spec.ts Covers recursive interfaces, Schema.Class fields, atomic leaves, and structurally similar map values.
packages/effect-firebase/src/lib/firestore/query/query.spec.ts Verifies dotted query paths, leaf typing, invalid paths, nested records, options, and class fields.
packages/effect-firebase/src/lib/firestore/schema/geopoint.ts Adds a type-only nominal brand so GeoPoint remains an atomic field-path leaf.
packages/effect-firebase/src/lib/firestore/schema/reference.ts Adds a type-only nominal brand so Reference remains an atomic field-path leaf.
packages/effect-firebase/src/lib/firestore/schema/timestamp.ts Adds a type-only nominal brand so Timestamp remains an atomic field-path leaf.

Reviews (3): Last reviewed commit: "fix(firestore): brand leaf classes so fi..." | Re-trigger Greptile

Comment thread packages/effect-firebase/src/lib/firestore/query/query.ts
…e type level

Replace the implicit-index-signature heuristic with an explicit FieldPathLeaf
union (arrays, functions, DateTime, Timestamp, GeoPoint, Reference, sentinels,
JS builtins); any other object type is a map. Aligns UpdateData/FieldPaths
with resolveFieldPath, which already descended into Class declarations, and
gives recursive interfaces typed paths too.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Comment thread packages/effect-firebase/src/lib/firestore/model/update-path.ts
…minal

GeoPoint, Reference, Timestamp, Increment, ArrayUnion and ArrayRemove get a
type-only unique-symbol member. Without it, any struct sharing their field
shape (e.g. { path: string }) matched the FieldPathLeaf union structurally
and lost its dotted paths.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@fwal
fwal merged commit 16d6f65 into main Sep 11, 2026
6 checks passed
@fwal
fwal deleted the fwal/nested-query-paths branch September 11, 2026 09:28
@fwal fwal added this to the 1.0 milestone Sep 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

📦 core 📖 docs Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nested keys are not inferred on queries

1 participant