import type { Application, Params } from '@feathersjs/feathers' import type { KeyOf } from '../../internal.utils.js' import type { InferFindParams, InferFindResultSingle, } from '../../utility-types/infer-service-methods.js' type PaginateOption = { default?: number; max?: number } type IterateFindOptions
= {
params?: P & { paginate?: PaginateOption }
}
/**
* Use `for await` to iterate over the results of a `find` method.
*
* This function is useful for iterating over large datasets without loading everything into memory at once.
* It uses pagination to fetch results in chunks, allowing you to process each item as it is retrieved.
*
* @example
* ```ts
* import { iterateFind } from 'feathers-utils/utils'
*
* const app = feathers()
*
* // Assuming 'users' service has many records
* for await (const user of iterateFind(app, 'users', {
* params: { query: { active: true }, // Custom query parameters
* } })) {
* console.log(user) // Process each user record
* }
* ```
*
* @see https://utils.feathersjs.com/utils/iterate-find.html
*/
export async function* iterateFind<
Services,
Path extends KeyOf ,
): AsyncGenerator