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 ChunkFindOptions
= {
params?: P & { paginate?: PaginateOption }
}
/**
* Use `for await` to iterate over chunks (pages) of results from a `find` method.
*
* This function is useful for processing large datasets in batches without loading everything into memory at once.
* It uses pagination to fetch results in chunks, yielding each page's data array.
*
* @example
* ```ts
* import { chunkFind } from 'feathers-utils/utils'
*
* const app = feathers()
*
* // Assuming 'users' service has many records
* for await (const users of chunkFind(app, 'users', {
* params: { query: { active: true }, // Custom query parameters
* } })) {
* console.log(users) // Process each chunk of user records
* }
* ```
*
* @see https://utils.feathersjs.com/utils/chunk-find.html
*/
export async function* chunkFind<
Services,
Path extends KeyOf ,
): AsyncGenerator