import type { ExtendedResolveParams } from '../index' ; export interface BeforeQueryHelperOpts { useLean ? : boolean ; } export async function beforeQueryHelper ( resolveParams ) { if ( ! resolveParams . query || typeof resolveParams . query . exec !== 'function' ) { throw new Error ( 'beforeQueryHelper: expected resolveParams.query to be instance of Query' ) ; } if ( ! resolveParams . beforeQuery ) { return resolveParams . query . exec ( ) ; } const result = await resolveParams . beforeQuery ( resolveParams . query , resolveParams ) ; if ( result !== undefined ) { if ( typeof result ?. exec === 'function' ) { return result . exec ( ) ; } else { return result ; } } else { return resolveParams . query . exec ( ) ; } } export async function beforeQueryHelperLean ( resolveParams ) { if ( ! resolveParams . query || typeof resolveParams . query . lean !== 'function' ) { throw new Error ( 'beforeQueryHelper: expected resolveParams.query to be instance of Query' ) ; } if ( ! resolveParams . beforeQuery ) { return resolveParams . query . lean ( ) ; } const result = await resolveParams . beforeQuery ( resolveParams . query , resolveParams ) ; if ( result !== undefined ) { if ( typeof result ?. lean === 'function' ) { return result . lean ( ) ; } else { return result ; } } else { return resolveParams . query . lean ( ) ; } }