Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

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

default discord avatar
teun45402 years ago
4
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_not_jared
    2 years ago

    You need to use the dot notation version

  • default discord avatar
    teun45402 years ago

    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_not_jared
    2 years ago

    Got it. Yes it is just for and/or

  • default discord avatar
    teun45402 years ago

    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

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.