feat: Enhance FieldKeys and FieldType to support nested fields in Schema. - #25
feat: Enhance FieldKeys and FieldType to support nested fields in Schema.#25christophe-g wants to merge 2 commits into
Conversation
|
@fwal - thanks. You can close this PR if you plan to include type-fest - I won't be offended ; ). For the time being, I have a couple of @ts-expect-error for queries with nested keys and I am ok with this for a couple of additional days / weeks. Out of curiosity - plans for Effect 4 for this lib? Not asking for an ETA, just to know if it will be there at some stage. Cheers ! |
Not had time to dip my toes in just yet but will start work soon, thinking that an eventual 1.0 will run on Effect 4 🎉 |
|
Close/Reopen to trigger CI - long time, but let's get this merged 😅 |
Greptile SummaryThis PR extends Firestore query field-key and value-type utilities to support nested fields represented with dot notation.
Confidence Score: 4/5The nested field-value mapping should be corrected before merging because it accepts values belonging to sibling fields. The new dotted-path branch ignores the inferred tail and feeds every nested key back into Files Needing Attention: packages/effect-firebase/src/lib/firestore/query/query.ts
|
| Filename | Overview |
|---|---|
| packages/effect-firebase/src/lib/firestore/query/query.ts | Adds nested field-path typing, but nested value resolution discards the requested suffix and returns a union of sibling field types. |
Reviews (1): Last reviewed commit: "chore: revert indent spacing" | Re-trigger Greptile
| ? FieldType<T, K> | ||
| : K extends `${infer Head}.${infer Tail}` | ||
| ? Head extends keyof S | ||
| ? FieldType<S[Head], FieldKeys<S[Head]>> |
There was a problem hiding this comment.
When querying a nested field whose siblings have different types, this branch passes every key below Head instead of the inferred Tail, so FieldType<S, "author.name"> becomes a sibling-type union and accepts invalid query values such as a number for a string field.
| ? FieldType<S[Head], FieldKeys<S[Head]>> | |
| ? FieldType<S[Head], Extract<Tail, FieldKeys<S[Head]>>> |
|
Seems to cause a circular dependency in the examples |
Hmm, I indeed have some exception ( type effectLiteralArray = readonly (string)[]
type DotPrefix<T extends string> = T extends "" ? "" : `.${T}`
type DocumentReference = {
firestore: any
path: string
id: string
parent: any
}
type OptionT = Option.Option<any>
type ExcludedTypesT = Date | ((...args: any[]) => any) | Array<any> | effectLiteralArray |
DocumentReference | Stripe.Invoice | File | FileSchemaT | FirestoreSchema.Reference | OptionT
// typeof Schema.Type
export type NestedKeys<T> = (
T extends ExcludedTypesT ? "" :
// branded primitives (e.g. Effect Schema.brand) extend their primitive
T extends (string | number | bigint | boolean | symbol) ? "" :
T extends object ?
{ [K in Exclude<keyof T, symbol>]: `${K}${DotPrefix<NestedKeys<T[K]>>}` }[Exclude<keyof T, symbol>]
: "") extends infer D ? Extract<D, string> : never
export type NestedValue<T, Key extends string> = Key extends `${infer K}.${infer Rest}` ?
K extends keyof T ? NestedValue<T[K], Rest> : never :
Key extends keyof T ? T[Key] : never |
|
Landing nested fields for updates in #83 if that's of any help 😅 |
|
I took a stab on it in #84, hope you don't mind. |
|
Of course not !
…On Thu, Sep 10, 2026 at 1:32 PM Frederik Wallner ***@***.***> wrote:
*fwal* left a comment (fwal/effect-firebase#25)
<#25 (comment)>
I took a stab on it in #84
<#84>, hope you don't mind.
—
Reply to this email directly, view it on GitHub
<#25?email_source=notifications&email_token=AAI5FNO76YTD5LXJCSCPINT5OKGOTA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKNRRG44TQNRVGUY2M4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2KYZTPN52GK4S7MNWGSY3L#issuecomment-5617986551>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAI5FNI2ZWEVJNTWBDQIHXL5OKGOTAVCNFSNUABGKJSXA33TNF2G64TZHMYTANZSGQ3DGNZYGI5US43TOVSTWNBQGE2TIMRZGIZTNILWAI>
.
Triage notifications, keep track of coding agent tasks and review pull
requests on the go with GitHub Mobile for iOS
<https://github.com/notifications/mobile/ios/AAI5FNKF2NUB5YGPDJIMZY35OKGOTA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKNRRG44TQNRVGUY2M4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2KUZTPN52GK4S7NFXXG>
and Android
<https://github.com/notifications/mobile/android/AAI5FNIUEQHCWW42XDYKZXT5OKGOTA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKNRRG44TQNRVGUY2M4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2K4ZTPN52GK4S7MFXGI4TPNFSA>.
Download it today!
You are receiving this because you authored the thread.Message ID:
***@***.***>
--
<https://preignition.org/>
Christophe Geiser / CTO
We are defined by the lines we choose to cross or to be confined by
Co-Founder of preignition.org / accessiblesurveys.com
|
This should close #18.