UNPKG

msw

Version:

Seamless REST/GraphQL API mocking library for browser and Node.js.

1 lines 1.18 kB
{"version":3,"sources":["../../src/core/getResponse.ts"],"sourcesContent":["import { createRequestId } from '@mswjs/interceptors'\nimport type { RequestHandler } from './handlers/RequestHandler'\nimport {\n executeHandlers,\n type ResponseResolutionContext,\n} from './utils/executeHandlers'\n\n/**\n * Finds a response for the given request instance\n * in the array of request handlers.\n * @param handlers The array of request handlers.\n * @param request The `Request` instance.\n * @param resolutionContext Request resolution options.\n * @returns {Response} A mocked response, if any.\n */\nexport const getResponse = async (\n handlers: Array<RequestHandler>,\n request: Request,\n resolutionContext?: ResponseResolutionContext,\n): Promise<Response | undefined> => {\n const result = await executeHandlers({\n request,\n requestId: createRequestId(),\n handlers,\n resolutionContext,\n })\n\n return result?.response\n}\n"],"mappings":"AAAA,SAAS,uBAAuB;AAEhC;AAAA,EACE;AAAA,OAEK;AAUA,MAAM,cAAc,OACzB,UACA,SACA,sBACkC;AAClC,QAAM,SAAS,MAAM,gBAAgB;AAAA,IACnC;AAAA,IACA,WAAW,gBAAgB;AAAA,IAC3B;AAAA,IACA;AAAA,EACF,CAAC;AAED,SAAO,QAAQ;AACjB;","names":[]}