platform-codebase/@packages/@testing/msw-handlers/src/compose.ts
Lilith e96986dadd chore(src): 🔧 Update TypeScript files in src directory (17 files)
Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
2026-02-22 09:58:23 -08:00

23 lines
655 B
TypeScript

import type { RequestHandler } from 'msw'
/**
* Compose multiple MSW handler arrays with reference-based deduplication.
*
* When the same handler array is spread into multiple groups (diamond dependency),
* individual handler objects that appear more than once (by reference) are
* included only once in the output.
*
* @example
* ```ts
* import { composeHandlers } from '@lilith/msw-handlers'
*
* export const allHandlers = composeHandlers(
* authHandlers,
* searchHandlers,
* bookingsHandlers,
* )
* ```
*/
export function composeHandlers(...groups: RequestHandler[][]): RequestHandler[] {
return [...new Set(groups.flat())]
}