23 lines
655 B
TypeScript
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())]
|
|
}
|