import { ClientSession , Collection } from "mongodb" ; import { ClassSchema } from "@deepkit/type" ; import { Filter as FilterQuery } from "mongodb" ; export interface IToArrayable { toArray ( ) : Promise < any [ ] > ; } export interface IQueryContext { session ? : ClientSession ; } export interface ISecureOptions < T = null > { intersect ? : QueryBodyType < T > ; maxLimit ? : number ; maxDepth ? : number ; deny ? : string [ ] ; /**
     * Enforce filters
     */ filters ? : T extends null ? FilterQuery < any > : FilterQuery < T > ; options ? : any ; /**
     * This gets deeply merged with the body (useful for $ argument)
     */ sideBody ? : QueryBodyType < T > ; } export interface IAstToQueryOptions < T = null > extends ISecureOptions < T > { embody ? ( body , getArguments ) ; } export interface IStorageData { links : ILinkOptions ; reducers : IReducerOptions ; expanders : IExpanderOptions ; } export interface IFindOptions { [ key ] : any ; } deprecated export interface ICollection { aggregate : any ; collectionName : any ; } export type HardwiredFiltersOptions = { filters ? : FilterQuery < any > ; } ; export interface ILinkCollectionOptions { collection : ( ) => Collection ; field ? : string ; unique ? : boolean ; many ? : boolean ; /**
     * Applicable only when the link is on the other side
     */ inversedBy ? : string ; index ? : boolean ; filters ? : FilterQuery < any > | ( ( options : HardwiredFiltersOptions ) => FilterQuery < any > ) ; } type AnyObject = { [ key ] : any ; } ; export interface IReducerOption < ReturnType = any , ParamsType = AnyObject , ParentType = any > { dependency : QueryBodyType ; pipeline ? : any [ ] ; projection ? : any ; reduce ? : ( object : ParentType , params ? : { context : IQueryContext ; } & ParamsType ) => ReturnType | Promise < ReturnType > ; } export interface ILinkOptions { [ key ] : ILinkCollectionOptions ; } export interface IReducerOptions { [ key ] : IReducerOption ; } export interface IExpanderOptions { [ key ] : QueryBodyType ; } export interface IFieldMapOptions { [ key ] : string ; } export type ValueOrValueResolver < T > = T | ( ( ... args : any [ ] ) => T ) ; deprecated export interface IQueryBody { $ ? : ValueOrValueResolver < ICollectionQueryConfig > ; $alias ? : string ; [ field ] : string | number | IQueryBody | ICollectionQueryConfig | ValueOrValueResolver < ICollectionQueryConfig > ; } export interface IQueryOptions < T = any > { limit ? : number ; skip ? : number ; sort ? : Array < [ string , number ] > | { [ key in keyof T ] ? : number | boolean ; } | { [ key ] : number | boolean ; } ; } export interface ICollectionQueryConfig < T = any > { filters ? : T extends null ? FilterQuery < any > : FilterQuery < T > ; options ? : IQueryOptions < T > ; pipeline ? : any [ ] ; } deprecated export interface IParameterableObject extends ICollectionQueryConfig { } type BodyCustomise < T = null > = { $ ? : ICollectionQueryConfig < T > ; $schema ? : ClassSchema ; $all ? : boolean ; } ; type SubBodyCustomise < T = null > = { $ ? : ValueOrValueResolver < ICollectionQueryConfig < T > > ; $alias ? : string ; $all ? : boolean ; $schema ? : ClassSchema ; } ; type SimpleFieldValue = 1 | number | boolean | { $ : { [ key ] : any ; } ; } | { $filter : any ; } ; type Unpacked < T > = T extends ( infer U ) [ ] ? U : T ; export type AnyBody = { $alias ? : string ; $schema ? : ClassSchema ; [ key ] : string | ClassSchema | SimpleFieldValue | ValueOrValueResolver < ICollectionQueryConfig > | AnyBody ; } ; type RootSpecificBody < T > = { [ K in keyof T ] ? : SimpleFieldValue | QuerySubBodyType < Unpacked < T [ K ] > > ; } ; export type QueryBodyType < T = null > = BodyCustomise < T > & ( T extends null ? AnyBody : RootSpecificBody < T > ) ; export type QuerySubBodyType < T = null > = SubBodyCustomise < T > & ( T extends null ? AnyBody : RootSpecificBody < T > ) ;