Where type, when has a field a value of Where[]?

default discord avatar
Teun
last month
6
Where

type is defined as



type Where = {
    [key: string]: WhereField | Where[];
    or?: Where[];
    and?: Where[];
}


What does it mean if a key has a value of Where[]?



e.g.



{
  "hero": [{
    "type" : { "equals": "basic"}
  }] 
}


is that the same as



{
  "hero.type": { "equals": "basic"}
 
}


Or does it mean something else? And if so, what?

  • discord user avatar
    Jarrod
    Payload Team
    last month

    You need to use the dot notation version

  • default discord avatar
    Teun
    last month

    Yes, I know. But I'm trying to create a type safe query builder for my payload-rbac library, so I'm trying to understand the type definition. the type definition specifies that I can use

    { [key: string}: Where[] }

    .What does this mean?



    If this is just to satisfy the type system to support the

    or

    and

    and

    property, then I can ignore it. But if it has some meaning, than I can't.

  • discord user avatar
    Jarrod
    Payload Team
    last month

    Got it. Yes it is just for and/or

  • default discord avatar
    Teun
    last month

    This is what I've got so far:



    import { WhereField } from 'payload/types';
    
    type ValueOf<T extends object> = T[keyof T];
    type AllKeys<T> = T extends object ? (keyof T & string) | ValueOf<{ [K in keyof T & string]: `${K}.${AllKeys<T[K]>}` }> : never;
    
    export type Where<T extends object = any> = Record<AllKeys<T>, WhereField> & {
      or?: Where<T>[];
      and?: Where<T>[];
    };


    But that doesn't take the

    [key: string]: Where[]

    into account.



    Thanks

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.