import type { HookContext, NextFunction } from '@feathersjs/feathers' import { checkContext } from '../../utils/index.js' /** * Disables pagination when `query.$limit` is `-1` or `'-1'`. * Removes the `$limit` from the query and sets `params.paginate = false`. * Must be used as a `before` or `around` hook on the `find` method. * * @example * ```ts * import { disablePagination } from 'feathers-utils/hooks' * * app.service('users').hooks({ * before: { find: [disablePagination()] } * }) * // Then call: app.service('users').find({ query: { $limit: -1 } }) * ``` * * @see https://utils.feathersjs.com/hooks/disable-pagination.html */ export const disablePagination = () => { function hook(context: H): void function hook(context: H, next: NextFunction): Promise function hook(context: H, next?: NextFunction): void | Promise { checkContext(context, { type: ['before', 'around'], method: ['find'], label: 'disablePagination', }) const $limit = context.params?.query?.$limit if ($limit === '-1' || $limit === -1) { context.params.paginate = false delete context.params.query.$limit } if (next) return next() return } return hook }