mappersmith
Version:
It is a lightweight rest client for node.js and the browser
1 lines • 1.12 kB
Source Map (JSON)
{"version":3,"sources":["../../../src/middleware/timeout.ts"],"sourcesContent":["import type { Middleware } from './index'\n\nexport type Milliseconds = number\n\n/**\n * Automatically configure your requests with a default timeout\n *\n * Example:\n * In your manifest:\n * {\n * middleware: [ TimeoutMiddleware(500) ]\n * }\n *\n * You can still override the default value:\n * client.User.all({ timeout: 100 })\n */\nexport const TimeoutMiddleware = (timeoutValue: Milliseconds): Middleware =>\n function TimeoutMiddleware() {\n return {\n async prepareRequest(next) {\n const request = await next()\n const timeout = request.timeout()\n return !timeout // Keep the override\n ? request.enhance({ timeout: timeoutValue })\n : request\n },\n }\n }\n\nexport default TimeoutMiddleware\n"],"mappings":";AAgBO,IAAM,oBAAoB,CAAC,iBAChC,SAASA,qBAAoB;AAC3B,SAAO;AAAA,IACL,MAAM,eAAe,MAAM;AACzB,YAAM,UAAU,MAAM,KAAK;AAC3B,YAAM,UAAU,QAAQ,QAAQ;AAChC,aAAO,CAAC,UACJ,QAAQ,QAAQ,EAAE,SAAS,aAAa,CAAC,IACzC;AAAA,IACN;AAAA,EACF;AACF;AAEF,IAAO,kBAAQ;","names":["TimeoutMiddleware"]}