@mswjs/interceptors 0.41.9 → 0.42.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +274 -228
- package/lib/browser/{bufferUtils-BiiO6HZv.mjs → buffer-utils-DJj7YzLG.js} +3 -3
- package/lib/browser/buffer-utils-DJj7YzLG.js.map +1 -0
- package/lib/browser/create-request-id-Bk5YX1AM.js +720 -0
- package/lib/browser/create-request-id-Bk5YX1AM.js.map +1 -0
- package/lib/browser/{getRawRequest-B1BqgWG6.mjs → fetch-utils-CUOrwEQf.js} +123 -52
- package/lib/browser/fetch-utils-CUOrwEQf.js.map +1 -0
- package/lib/browser/handle-request-CqVvBhcw.js +167 -0
- package/lib/browser/handle-request-CqVvBhcw.js.map +1 -0
- package/lib/{node/hasConfigurableGlobal-BiTmog1u.mjs → browser/has-configurable-global-Cew-dYqk.js} +5 -7
- package/lib/browser/has-configurable-global-Cew-dYqk.js.map +1 -0
- package/lib/browser/http-CB9rQ7i_.d.ts +105 -0
- package/lib/browser/{index.d.cts → index.d.ts} +33 -38
- package/lib/browser/index.js +130 -0
- package/lib/browser/index.js.map +1 -0
- package/lib/browser/interceptor-dtJZ_9QT.d.ts +50 -0
- package/lib/browser/interceptors/WebSocket/index.d.ts +2 -0
- package/lib/browser/interceptors/WebSocket/{index.mjs → index.js} +39 -30
- package/lib/browser/interceptors/WebSocket/index.js.map +1 -0
- package/lib/browser/interceptors/XMLHttpRequest/web.d.ts +11 -0
- package/lib/browser/interceptors/XMLHttpRequest/web.js +2 -0
- package/lib/browser/interceptors/fetch/web.d.ts +14 -0
- package/lib/browser/interceptors/fetch/web.js +2 -0
- package/lib/browser/presets/browser.d.ts +11 -0
- package/lib/browser/presets/browser.js +12 -0
- package/lib/browser/presets/browser.js.map +1 -0
- package/lib/browser/{resolveWebSocketUrl-C83-x9iE.mjs → resolve-web-socket-url-CSvNPLGi.js} +3 -3
- package/lib/browser/resolve-web-socket-url-CSvNPLGi.js.map +1 -0
- package/lib/browser/{XMLHttpRequest-DrZAf3w6.mjs → web-BcKSQghf.js} +327 -255
- package/lib/browser/web-BcKSQghf.js.map +1 -0
- package/lib/browser/web-CdcYFjgm.js +248 -0
- package/lib/browser/web-CdcYFjgm.js.map +1 -0
- package/lib/browser/{interceptors/WebSocket/index.d.cts → websocket-CC0nB0md.d.ts} +41 -33
- package/lib/node/batch-interceptor-ByEZVih3.js +119 -0
- package/lib/node/batch-interceptor-ByEZVih3.js.map +1 -0
- package/lib/node/batch-interceptor-CPjFK2td.d.ts +28 -0
- package/lib/node/buffer-utils-BvPY1Tc-.js +187 -0
- package/lib/node/buffer-utils-BvPY1Tc-.js.map +1 -0
- package/lib/node/fetch-utils-Dw1PsmtX.js +568 -0
- package/lib/node/fetch-utils-Dw1PsmtX.js.map +1 -0
- package/lib/node/has-configurable-global-CJCh_g1I.js +22 -0
- package/lib/node/has-configurable-global-CJCh_g1I.js.map +1 -0
- package/lib/node/http-CB9rQ7i_.d.ts +105 -0
- package/lib/{browser/interceptors/WebSocket/index.d.mts → node/index.d.ts} +120 -60
- package/lib/node/{index.mjs → index.js} +8 -11
- package/lib/node/index.js.map +1 -0
- package/lib/node/interceptor-dtJZ_9QT.d.ts +50 -0
- package/lib/node/interceptors/ClientRequest/index.d.ts +14 -0
- package/lib/node/interceptors/ClientRequest/index.js +67 -0
- package/lib/node/interceptors/ClientRequest/index.js.map +1 -0
- package/lib/node/interceptors/XMLHttpRequest/node.d.ts +12 -0
- package/lib/node/interceptors/XMLHttpRequest/node.js +74 -0
- package/lib/node/interceptors/XMLHttpRequest/node.js.map +1 -0
- package/lib/node/interceptors/fetch/node.d.ts +18 -0
- package/lib/node/interceptors/fetch/node.js +83 -0
- package/lib/node/interceptors/fetch/node.js.map +1 -0
- package/lib/node/interceptors/http/index.d.ts +14 -0
- package/lib/node/interceptors/http/index.js +32 -0
- package/lib/node/interceptors/http/index.js.map +1 -0
- package/lib/node/interceptors/net/index.d.ts +203 -0
- package/lib/node/interceptors/net/index.js +2 -0
- package/lib/node/llhttp/constants.cjs +485 -0
- package/lib/node/llhttp/constants.d.cts +957 -0
- package/lib/node/llhttp/llhttp.wasm +0 -0
- package/lib/node/net-DtMnyEeg.js +1388 -0
- package/lib/node/net-DtMnyEeg.js.map +1 -0
- package/lib/node/presets/node.d.ts +12 -0
- package/lib/node/presets/node.js +17 -0
- package/lib/node/presets/node.js.map +1 -0
- package/lib/node/{RemoteHttpInterceptor.d.cts → remote-http-interceptor.d.ts} +12 -11
- package/lib/node/{RemoteHttpInterceptor.mjs → remote-http-interceptor.js} +38 -33
- package/lib/node/remote-http-interceptor.js.map +1 -0
- package/lib/node/source-lP0yyEtA.js +1990 -0
- package/lib/node/source-lP0yyEtA.js.map +1 -0
- package/package.json +79 -118
- package/src/batch-interceptor.test.ts +475 -0
- package/src/batch-interceptor.ts +244 -0
- package/src/{createRequestId.test.ts → create-request-id.test.ts} +1 -2
- package/src/disposable.ts +13 -0
- package/src/events/http.ts +92 -0
- package/src/events/websocket.ts +47 -0
- package/src/glossary.ts +1 -27
- package/src/index.ts +18 -10
- package/src/interceptor.test.ts +279 -0
- package/src/interceptor.ts +139 -0
- package/src/interceptors/ClientRequest/index.test.ts +21 -39
- package/src/interceptors/ClientRequest/index.ts +64 -179
- package/src/interceptors/ClientRequest/utils/{recordRawHeaders.test.ts → record-raw-headers.test.ts} +1 -2
- package/src/interceptors/ClientRequest/utils/{recordRawHeaders.ts → record-raw-headers.ts} +29 -2
- package/src/interceptors/WebSocket/index.ts +33 -50
- package/src/interceptors/WebSocket/utils/{bindEvent.test.ts → bind-event.test.ts} +1 -2
- package/src/interceptors/WebSocket/utils/events.test.ts +0 -1
- package/src/interceptors/WebSocket/{WebSocketClassTransport.ts → web-socket-class-transport.ts} +3 -3
- package/src/interceptors/WebSocket/{WebSocketClientConnection.ts → web-socket-client-connection.ts} +4 -4
- package/src/interceptors/WebSocket/{WebSocketOverride.ts → web-socket-override.ts} +6 -7
- package/src/interceptors/WebSocket/{WebSocketServerConnection.ts → web-socket-server-connection.ts} +4 -4
- package/src/interceptors/WebSocket/{WebSocketTransport.ts → web-socket-transport.ts} +1 -1
- package/src/interceptors/XMLHttpRequest/node.ts +104 -0
- package/src/interceptors/XMLHttpRequest/polyfills/{ProgressEventPolyfill.ts → progress-event-polyfill.ts} +1 -1
- package/src/interceptors/XMLHttpRequest/utils/{concateArrayBuffer.test.ts → concat-array-buffer.test.ts} +1 -2
- package/src/interceptors/XMLHttpRequest/utils/{concatArrayBuffer.ts → concat-array-buffer.ts} +1 -1
- package/src/interceptors/XMLHttpRequest/utils/{createEvent.test.ts → create-event.test.ts} +3 -4
- package/src/interceptors/XMLHttpRequest/utils/{createEvent.ts → create-event.ts} +2 -2
- package/src/interceptors/XMLHttpRequest/utils/{createResponse.ts → create-response.ts} +1 -1
- package/src/interceptors/XMLHttpRequest/utils/{getBodyByteLength.test.ts → get-body-byte-length.test.ts} +1 -2
- package/src/interceptors/XMLHttpRequest/web.ts +34 -0
- package/src/interceptors/XMLHttpRequest/{XMLHttpRequestController.ts → xml-http-request-controller.ts} +363 -204
- package/src/interceptors/XMLHttpRequest/{XMLHttpRequestProxy.ts → xml-http-request-proxy.ts} +28 -25
- package/src/interceptors/fetch/node.ts +103 -0
- package/src/interceptors/fetch/utils/{followRedirect.ts → follow-redirect.ts} +1 -1
- package/src/interceptors/fetch/web.ts +217 -0
- package/src/interceptors/http/forward-events.test.ts +86 -0
- package/src/interceptors/http/forward-events.ts +139 -0
- package/src/interceptors/http/http-parser/index.ts +310 -0
- package/src/interceptors/http/http-parser/llhttp/constants.cjs +485 -0
- package/src/interceptors/http/http-parser/llhttp/constants.d.cts +957 -0
- package/src/interceptors/http/http-parser/llhttp/llhttp.wasm +0 -0
- package/src/interceptors/http/http-parser.ts +138 -0
- package/src/interceptors/http/index.ts +34 -0
- package/src/interceptors/http/source.ts +688 -0
- package/src/interceptors/net/index.ts +368 -0
- package/src/interceptors/net/socket-controller.ts +1476 -0
- package/src/interceptors/net/utils/address-info.ts +54 -0
- package/src/interceptors/net/utils/connection-options-to-url.ts +56 -0
- package/src/interceptors/net/utils/flush-writes.ts +57 -0
- package/src/interceptors/net/utils/get-tls-connect-options.ts +23 -0
- package/src/interceptors/net/utils/normalize-net-connect-args.test.ts +233 -0
- package/src/interceptors/net/utils/normalize-net-connect-args.ts +121 -0
- package/src/interceptors/net/utils/normalize-tls-connect-args.ts +50 -0
- package/src/presets/browser.ts +4 -4
- package/src/presets/node.ts +4 -4
- package/src/{RemoteHttpInterceptor.ts → remote-http-interceptor.ts} +55 -42
- package/src/request-context.ts +40 -0
- package/src/{RequestController.test.ts → request-controller.test.ts} +37 -3
- package/src/{RequestController.ts → request-controller.ts} +33 -11
- package/src/utils/{bufferUtils.test.ts → buffer-utils.test.ts} +1 -2
- package/src/utils/buffer-utils.ts +37 -0
- package/src/utils/{cloneObject.test.ts → clone-object.test.ts} +1 -2
- package/src/utils/{cloneObject.ts → clone-object.ts} +8 -8
- package/src/utils/{createProxy.test.ts → create-proxy.test.ts} +6 -4
- package/src/utils/{createProxy.ts → create-proxy.ts} +1 -1
- package/src/utils/{fetchUtils.test.ts → fetch-utils.test.ts} +1 -1
- package/src/utils/{fetchUtils.ts → fetch-utils.ts} +28 -3
- package/src/utils/{findPropertySource.test.ts → find-property-source.test.ts} +1 -2
- package/src/utils/{getCleanUrl.test.ts → get-clean-url.test.ts} +1 -2
- package/src/utils/{getUrlByRequestOptions.test.ts → get-url-by-request-options.test.ts} +4 -8
- package/src/utils/{getUrlByRequestOptions.ts → get-url-by-request-options.ts} +16 -16
- package/src/utils/{getValueBySymbol.test.ts → get-value-by-symbol.test.ts} +1 -2
- package/src/utils/{handleRequest.ts → handle-request.ts} +61 -41
- package/src/utils/{hasConfigurableGlobal.test.ts → has-configurable-global.test.ts} +1 -2
- package/src/utils/{hasConfigurableGlobal.ts → has-configurable-global.ts} +2 -4
- package/src/utils/{isObject.test.ts → is-object.test.ts} +1 -2
- package/src/utils/logger.test.ts +154 -0
- package/src/utils/logger.ts +154 -0
- package/src/utils/{parseJson.test.ts → parse-json.test.ts} +1 -2
- package/src/utils/{patchesRegistry.test.ts → patches-registry.test.ts} +1 -1
- package/src/utils/{patchesRegistry.ts → patches-registry.ts} +1 -1
- package/src/utils/{responseUtils.ts → response-utils.ts} +25 -2
- package/ClientRequest/package.json +0 -11
- package/RemoteHttpInterceptor/package.json +0 -11
- package/WebSocket/package.json +0 -12
- package/XMLHttpRequest/package.json +0 -12
- package/fetch/package.json +0 -12
- package/lib/browser/Interceptor-Deczogc8.d.cts +0 -65
- package/lib/browser/Interceptor-gqKgs-aF.d.mts +0 -65
- package/lib/browser/XMLHttpRequest-DrZAf3w6.mjs.map +0 -1
- package/lib/browser/XMLHttpRequest-gXuzzX1g.cjs +0 -751
- package/lib/browser/XMLHttpRequest-gXuzzX1g.cjs.map +0 -1
- package/lib/browser/bufferUtils-BiiO6HZv.mjs.map +0 -1
- package/lib/browser/bufferUtils-Uc0eRItL.cjs +0 -38
- package/lib/browser/bufferUtils-Uc0eRItL.cjs.map +0 -1
- package/lib/browser/createRequestId-DOf8Ktjs.cjs +0 -205
- package/lib/browser/createRequestId-DOf8Ktjs.cjs.map +0 -1
- package/lib/browser/createRequestId-DYCsFHOi.mjs +0 -170
- package/lib/browser/createRequestId-DYCsFHOi.mjs.map +0 -1
- package/lib/browser/fetch-5IMPqr9e.mjs +0 -236
- package/lib/browser/fetch-5IMPqr9e.mjs.map +0 -1
- package/lib/browser/fetch-Bt9rMY9c.cjs +0 -241
- package/lib/browser/fetch-Bt9rMY9c.cjs.map +0 -1
- package/lib/browser/getRawRequest-B1BqgWG6.mjs.map +0 -1
- package/lib/browser/getRawRequest-DdfaiPVH.cjs +0 -376
- package/lib/browser/getRawRequest-DdfaiPVH.cjs.map +0 -1
- package/lib/browser/glossary-1lhZx6Aw.d.cts +0 -69
- package/lib/browser/glossary-nkHWcwvY.d.mts +0 -69
- package/lib/browser/handleRequest-CJim54xG.cjs +0 -191
- package/lib/browser/handleRequest-CJim54xG.cjs.map +0 -1
- package/lib/browser/handleRequest-CPPgsG7s.mjs +0 -180
- package/lib/browser/handleRequest-CPPgsG7s.mjs.map +0 -1
- package/lib/browser/hasConfigurableGlobal-C8zq1MCg.mjs +0 -109
- package/lib/browser/hasConfigurableGlobal-C8zq1MCg.mjs.map +0 -1
- package/lib/browser/hasConfigurableGlobal-CS7adEvV.cjs +0 -126
- package/lib/browser/hasConfigurableGlobal-CS7adEvV.cjs.map +0 -1
- package/lib/browser/index.cjs +0 -70
- package/lib/browser/index.cjs.map +0 -1
- package/lib/browser/index.d.mts +0 -125
- package/lib/browser/index.mjs +0 -56
- package/lib/browser/index.mjs.map +0 -1
- package/lib/browser/interceptors/WebSocket/index.cjs +0 -618
- package/lib/browser/interceptors/WebSocket/index.cjs.map +0 -1
- package/lib/browser/interceptors/WebSocket/index.mjs.map +0 -1
- package/lib/browser/interceptors/XMLHttpRequest/index.cjs +0 -8
- package/lib/browser/interceptors/XMLHttpRequest/index.d.cts +0 -15
- package/lib/browser/interceptors/XMLHttpRequest/index.d.mts +0 -15
- package/lib/browser/interceptors/XMLHttpRequest/index.mjs +0 -8
- package/lib/browser/interceptors/fetch/index.cjs +0 -7
- package/lib/browser/interceptors/fetch/index.d.cts +0 -13
- package/lib/browser/interceptors/fetch/index.d.mts +0 -13
- package/lib/browser/interceptors/fetch/index.mjs +0 -7
- package/lib/browser/presets/browser.cjs +0 -18
- package/lib/browser/presets/browser.cjs.map +0 -1
- package/lib/browser/presets/browser.d.cts +0 -12
- package/lib/browser/presets/browser.d.mts +0 -14
- package/lib/browser/presets/browser.mjs +0 -18
- package/lib/browser/presets/browser.mjs.map +0 -1
- package/lib/browser/resolveWebSocketUrl-6K6EgqsA.cjs +0 -31
- package/lib/browser/resolveWebSocketUrl-6K6EgqsA.cjs.map +0 -1
- package/lib/browser/resolveWebSocketUrl-C83-x9iE.mjs.map +0 -1
- package/lib/node/BatchInterceptor-BGhH8z1z.cjs +0 -49
- package/lib/node/BatchInterceptor-BGhH8z1z.cjs.map +0 -1
- package/lib/node/BatchInterceptor-C4-RX5rg.mjs +0 -44
- package/lib/node/BatchInterceptor-C4-RX5rg.mjs.map +0 -1
- package/lib/node/BatchInterceptor-KKF8Q47I.d.cts +0 -26
- package/lib/node/BatchInterceptor-rSr-NH_H.d.mts +0 -26
- package/lib/node/ClientRequest-2loAH7xM.cjs +0 -1058
- package/lib/node/ClientRequest-2loAH7xM.cjs.map +0 -1
- package/lib/node/ClientRequest-DGhBX21V.mjs +0 -1049
- package/lib/node/ClientRequest-DGhBX21V.mjs.map +0 -1
- package/lib/node/Interceptor-BsZ21ue0.d.cts +0 -132
- package/lib/node/Interceptor-soD-WpQO.d.mts +0 -132
- package/lib/node/RemoteHttpInterceptor.cjs +0 -155
- package/lib/node/RemoteHttpInterceptor.cjs.map +0 -1
- package/lib/node/RemoteHttpInterceptor.d.mts +0 -39
- package/lib/node/RemoteHttpInterceptor.mjs.map +0 -1
- package/lib/node/XMLHttpRequest-BtDNZipW.cjs +0 -752
- package/lib/node/XMLHttpRequest-BtDNZipW.cjs.map +0 -1
- package/lib/node/XMLHttpRequest-Dw6Wm-UU.mjs +0 -746
- package/lib/node/XMLHttpRequest-Dw6Wm-UU.mjs.map +0 -1
- package/lib/node/bufferUtils-DxPxwff_.mjs +0 -20
- package/lib/node/bufferUtils-DxPxwff_.mjs.map +0 -1
- package/lib/node/bufferUtils-S5_-2eN4.cjs +0 -38
- package/lib/node/bufferUtils-S5_-2eN4.cjs.map +0 -1
- package/lib/node/chunk-CbDLau6x.cjs +0 -34
- package/lib/node/fetch-CaC3rGEu.mjs +0 -252
- package/lib/node/fetch-CaC3rGEu.mjs.map +0 -1
- package/lib/node/fetch-D2ClLNN-.cjs +0 -259
- package/lib/node/fetch-D2ClLNN-.cjs.map +0 -1
- package/lib/node/fetchUtils-BKJ1XmiO.mjs +0 -480
- package/lib/node/fetchUtils-BKJ1XmiO.mjs.map +0 -1
- package/lib/node/fetchUtils-umV5xXBy.cjs +0 -546
- package/lib/node/fetchUtils-umV5xXBy.cjs.map +0 -1
- package/lib/node/getRawRequest-B6znU6il.cjs +0 -36
- package/lib/node/getRawRequest-B6znU6il.cjs.map +0 -1
- package/lib/node/getRawRequest-C2-1urzA.mjs +0 -24
- package/lib/node/getRawRequest-C2-1urzA.mjs.map +0 -1
- package/lib/node/handleRequest-C-cKYjIh.cjs +0 -222
- package/lib/node/handleRequest-C-cKYjIh.cjs.map +0 -1
- package/lib/node/handleRequest-FIQv5pwH.mjs +0 -192
- package/lib/node/handleRequest-FIQv5pwH.mjs.map +0 -1
- package/lib/node/hasConfigurableGlobal-BiTmog1u.mjs.map +0 -1
- package/lib/node/hasConfigurableGlobal-MjY06_Ok.cjs +0 -108
- package/lib/node/hasConfigurableGlobal-MjY06_Ok.cjs.map +0 -1
- package/lib/node/index-BJ5E5aW-.d.cts +0 -113
- package/lib/node/index-DfoF45ih.d.mts +0 -113
- package/lib/node/index.cjs +0 -53
- package/lib/node/index.cjs.map +0 -1
- package/lib/node/index.d.cts +0 -104
- package/lib/node/index.d.mts +0 -104
- package/lib/node/index.mjs.map +0 -1
- package/lib/node/interceptors/ClientRequest/index.cjs +0 -6
- package/lib/node/interceptors/ClientRequest/index.d.cts +0 -2
- package/lib/node/interceptors/ClientRequest/index.d.mts +0 -3
- package/lib/node/interceptors/ClientRequest/index.mjs +0 -6
- package/lib/node/interceptors/XMLHttpRequest/index.cjs +0 -7
- package/lib/node/interceptors/XMLHttpRequest/index.d.cts +0 -14
- package/lib/node/interceptors/XMLHttpRequest/index.d.mts +0 -14
- package/lib/node/interceptors/XMLHttpRequest/index.mjs +0 -7
- package/lib/node/interceptors/fetch/index.cjs +0 -6
- package/lib/node/interceptors/fetch/index.d.cts +0 -12
- package/lib/node/interceptors/fetch/index.d.mts +0 -12
- package/lib/node/interceptors/fetch/index.mjs +0 -6
- package/lib/node/node-DIKcnzhK.cjs +0 -39
- package/lib/node/node-DIKcnzhK.cjs.map +0 -1
- package/lib/node/node-lsdNwZEW.mjs +0 -27
- package/lib/node/node-lsdNwZEW.mjs.map +0 -1
- package/lib/node/presets/node.cjs +0 -23
- package/lib/node/presets/node.cjs.map +0 -1
- package/lib/node/presets/node.d.cts +0 -13
- package/lib/node/presets/node.d.mts +0 -15
- package/lib/node/presets/node.mjs +0 -23
- package/lib/node/presets/node.mjs.map +0 -1
- package/lib/node/utils/node/index.cjs +0 -4
- package/lib/node/utils/node/index.d.cts +0 -16
- package/lib/node/utils/node/index.d.mts +0 -16
- package/lib/node/utils/node/index.mjs +0 -3
- package/presets/browser/package.json +0 -5
- package/presets/node/package.json +0 -11
- package/src/BatchInterceptor.test.ts +0 -255
- package/src/BatchInterceptor.ts +0 -96
- package/src/Interceptor.test.ts +0 -205
- package/src/Interceptor.ts +0 -249
- package/src/getRawRequest.ts +0 -21
- package/src/interceptors/ClientRequest/MockHttpSocket.ts +0 -724
- package/src/interceptors/ClientRequest/agents.ts +0 -110
- package/src/interceptors/ClientRequest/utils/getIncomingMessageBody.test.ts +0 -54
- package/src/interceptors/ClientRequest/utils/getIncomingMessageBody.ts +0 -45
- package/src/interceptors/ClientRequest/utils/normalizeClientRequestArgs.test.ts +0 -427
- package/src/interceptors/ClientRequest/utils/normalizeClientRequestArgs.ts +0 -268
- package/src/interceptors/ClientRequest/utils/parserUtils.ts +0 -48
- package/src/interceptors/Socket/MockSocket.test.ts +0 -264
- package/src/interceptors/Socket/MockSocket.ts +0 -58
- package/src/interceptors/Socket/utils/baseUrlFromConnectionOptions.ts +0 -26
- package/src/interceptors/Socket/utils/normalizeSocketWriteArgs.test.ts +0 -52
- package/src/interceptors/Socket/utils/normalizeSocketWriteArgs.ts +0 -33
- package/src/interceptors/XMLHttpRequest/index.ts +0 -40
- package/src/interceptors/fetch/index.ts +0 -203
- package/src/utils/bufferUtils.ts +0 -22
- package/src/utils/canParseUrl.ts +0 -13
- package/src/utils/emitAsync.ts +0 -25
- package/src/utils/nextTick.ts +0 -11
- package/src/utils/node/index.ts +0 -39
- /package/src/{createRequestId.ts → create-request-id.ts} +0 -0
- /package/src/{InterceptorError.ts → interceptor-error.ts} +0 -0
- /package/src/interceptors/WebSocket/utils/{bindEvent.ts → bind-event.ts} +0 -0
- /package/src/interceptors/XMLHttpRequest/polyfills/{EventPolyfill.ts → event-polyfill.ts} +0 -0
- /package/src/interceptors/XMLHttpRequest/utils/{getBodyByteLength.ts → get-body-byte-length.ts} +0 -0
- /package/src/interceptors/XMLHttpRequest/utils/{isDomParserSupportedType.ts → is-dom-parser-supported-type.ts} +0 -0
- /package/src/interceptors/fetch/utils/{createNetworkError.ts → create-network-error.ts} +0 -0
- /package/src/utils/{findPropertySource.ts → find-property-source.ts} +0 -0
- /package/src/utils/{getCleanUrl.ts → get-clean-url.ts} +0 -0
- /package/src/utils/{getValueBySymbol.ts → get-value-by-symbol.ts} +0 -0
- /package/src/utils/{isNodeLikeError.ts → is-node-like-error.ts} +0 -0
- /package/src/utils/{isObject.ts → is-object.ts} +0 -0
- /package/src/utils/{isPropertyAccessible.ts → is-property-accessible.ts} +0 -0
- /package/src/utils/{parseJson.ts → parse-json.ts} +0 -0
- /package/src/utils/{resolveWebSocketUrl.ts → resolve-web-socket-url.ts} +0 -0
|
@@ -1,376 +0,0 @@
|
|
|
1
|
-
let _open_draft_deferred_promise = require("@open-draft/deferred-promise");
|
|
2
|
-
let outvariant = require("outvariant");
|
|
3
|
-
|
|
4
|
-
//#region src/InterceptorError.ts
|
|
5
|
-
var InterceptorError = class InterceptorError extends Error {
|
|
6
|
-
constructor(message) {
|
|
7
|
-
super(message);
|
|
8
|
-
this.name = "InterceptorError";
|
|
9
|
-
Object.setPrototypeOf(this, InterceptorError.prototype);
|
|
10
|
-
}
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
//#endregion
|
|
14
|
-
//#region src/RequestController.ts
|
|
15
|
-
var RequestController = class RequestController {
|
|
16
|
-
static {
|
|
17
|
-
this.PENDING = 0;
|
|
18
|
-
}
|
|
19
|
-
static {
|
|
20
|
-
this.PASSTHROUGH = 1;
|
|
21
|
-
}
|
|
22
|
-
static {
|
|
23
|
-
this.RESPONSE = 2;
|
|
24
|
-
}
|
|
25
|
-
static {
|
|
26
|
-
this.ERROR = 3;
|
|
27
|
-
}
|
|
28
|
-
constructor(request, source) {
|
|
29
|
-
this.request = request;
|
|
30
|
-
this.source = source;
|
|
31
|
-
this.readyState = RequestController.PENDING;
|
|
32
|
-
this.handled = new _open_draft_deferred_promise.DeferredPromise();
|
|
33
|
-
}
|
|
34
|
-
get #handled() {
|
|
35
|
-
return this.handled;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Perform this request as-is.
|
|
39
|
-
*/
|
|
40
|
-
async passthrough() {
|
|
41
|
-
outvariant.invariant.as(InterceptorError, this.readyState === RequestController.PENDING, "Failed to passthrough the \"%s %s\" request: the request has already been handled", this.request.method, this.request.url);
|
|
42
|
-
this.readyState = RequestController.PASSTHROUGH;
|
|
43
|
-
await this.source.passthrough();
|
|
44
|
-
this.#handled.resolve();
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Respond to this request with the given `Response` instance.
|
|
48
|
-
*
|
|
49
|
-
* @example
|
|
50
|
-
* controller.respondWith(new Response())
|
|
51
|
-
* controller.respondWith(Response.json({ id }))
|
|
52
|
-
* controller.respondWith(Response.error())
|
|
53
|
-
*/
|
|
54
|
-
respondWith(response) {
|
|
55
|
-
outvariant.invariant.as(InterceptorError, this.readyState === RequestController.PENDING, "Failed to respond to the \"%s %s\" request with \"%d %s\": the request has already been handled (%d)", this.request.method, this.request.url, response.status, response.statusText || "OK", this.readyState);
|
|
56
|
-
this.readyState = RequestController.RESPONSE;
|
|
57
|
-
this.#handled.resolve();
|
|
58
|
-
/**
|
|
59
|
-
* @note Although `source.respondWith()` is potentially asynchronous,
|
|
60
|
-
* do NOT await it for backward-compatibility. Awaiting it will short-circuit
|
|
61
|
-
* the request listener invocation as soon as a listener responds to a request.
|
|
62
|
-
* Ideally, that's what we want, but that's not what we promise the user.
|
|
63
|
-
*/
|
|
64
|
-
this.source.respondWith(response);
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Error this request with the given reason.
|
|
68
|
-
*
|
|
69
|
-
* @example
|
|
70
|
-
* controller.errorWith()
|
|
71
|
-
* controller.errorWith(new Error('Oops!'))
|
|
72
|
-
* controller.errorWith({ message: 'Oops!'})
|
|
73
|
-
*/
|
|
74
|
-
errorWith(reason) {
|
|
75
|
-
outvariant.invariant.as(InterceptorError, this.readyState === RequestController.PENDING, "Failed to error the \"%s %s\" request with \"%s\": the request has already been handled (%d)", this.request.method, this.request.url, reason?.toString(), this.readyState);
|
|
76
|
-
this.readyState = RequestController.ERROR;
|
|
77
|
-
this.source.errorWith(reason);
|
|
78
|
-
this.#handled.resolve();
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
//#endregion
|
|
83
|
-
//#region src/utils/canParseUrl.ts
|
|
84
|
-
/**
|
|
85
|
-
* Returns a boolean indicating whether the given URL string
|
|
86
|
-
* can be parsed into a `URL` instance.
|
|
87
|
-
* A substitute for `URL.canParse()` for Node.js 18.
|
|
88
|
-
*/
|
|
89
|
-
function canParseUrl(url) {
|
|
90
|
-
try {
|
|
91
|
-
new URL(url);
|
|
92
|
-
return true;
|
|
93
|
-
} catch (_error) {
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
//#endregion
|
|
99
|
-
//#region src/utils/getValueBySymbol.ts
|
|
100
|
-
/**
|
|
101
|
-
* Returns the value behind the symbol with the given name.
|
|
102
|
-
*/
|
|
103
|
-
function getValueBySymbol(symbolName, source) {
|
|
104
|
-
const symbol = Object.getOwnPropertySymbols(source).find((symbol$1) => {
|
|
105
|
-
return symbol$1.description === symbolName;
|
|
106
|
-
});
|
|
107
|
-
if (symbol) return Reflect.get(source, symbol);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
//#endregion
|
|
111
|
-
//#region src/utils/fetchUtils.ts
|
|
112
|
-
var FetchRequest = class FetchRequest extends Request {
|
|
113
|
-
static #resolveProperty(input, init = {}, key) {
|
|
114
|
-
return init[key] ?? (input instanceof Request ? input[key] : void 0);
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Check if the given request method is configurable.
|
|
118
|
-
* @see https://fetch.spec.whatwg.org/#methods
|
|
119
|
-
*/
|
|
120
|
-
static isConfigurableMethod(method) {
|
|
121
|
-
return method !== "CONNECT" && method !== "TRACE" && method !== "TRACK";
|
|
122
|
-
}
|
|
123
|
-
static isMethodWithBody(method) {
|
|
124
|
-
return method !== "HEAD" && method !== "GET" && FetchRequest.isConfigurableMethod(method);
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Check if the given request `mode` is configurable.
|
|
128
|
-
* @see https://fetch.spec.whatwg.org/#concept-request-mode
|
|
129
|
-
*/
|
|
130
|
-
static isConfigurableMode(mode) {
|
|
131
|
-
return mode !== "navigate" && mode !== "websocket" && mode !== "webtransport";
|
|
132
|
-
}
|
|
133
|
-
constructor(input, init) {
|
|
134
|
-
const method = FetchRequest.#resolveProperty(input, init, "method") || "GET";
|
|
135
|
-
const safeMethod = FetchRequest.isConfigurableMethod(method) ? method : "GET";
|
|
136
|
-
const hasExplicitBody = init != null && "body" in init;
|
|
137
|
-
/**
|
|
138
|
-
* Only include `body` in the super init when it needs to be overridden.
|
|
139
|
-
* When `input` is a Request and no explicit body is in `init`, let the
|
|
140
|
-
* Request constructor handle body transfer naturally so it properly
|
|
141
|
-
* marks the original request's body as consumed (bodyUsed = true).
|
|
142
|
-
*/
|
|
143
|
-
const bodyInit = !FetchRequest.isMethodWithBody(method) ? { body: void 0 } : hasExplicitBody ? { body: init.body } : {};
|
|
144
|
-
const mode = FetchRequest.#resolveProperty(input, init, "mode") ?? void 0;
|
|
145
|
-
const safeMode = FetchRequest.isConfigurableMode(mode) ? mode : void 0;
|
|
146
|
-
super(input, {
|
|
147
|
-
...init || {},
|
|
148
|
-
method: safeMethod,
|
|
149
|
-
mode: safeMode,
|
|
150
|
-
duplex: init?.duplex ?? (FetchRequest.isMethodWithBody(method) ? "half" : void 0),
|
|
151
|
-
...bodyInit
|
|
152
|
-
});
|
|
153
|
-
if (method !== safeMethod) this.#setInternalProperty("method", method);
|
|
154
|
-
if (method === "CONNECT") {
|
|
155
|
-
const url = new URL(input instanceof Request ? input.url : input);
|
|
156
|
-
let authority;
|
|
157
|
-
/**
|
|
158
|
-
* @note Node.js has a bug parsing raw CONNECT requests URLs like
|
|
159
|
-
* "http://127.0.0.1:1337/localhost:80". It would treat "localhost:" as a protocol.
|
|
160
|
-
*/
|
|
161
|
-
if (url.protocol === "localhost:") authority = url.href;
|
|
162
|
-
else authority = url.pathname.replace(/^\/+/, "");
|
|
163
|
-
/**
|
|
164
|
-
* @note Define "url" as a getter because Undici uses their own
|
|
165
|
-
* logic to resolve the "request.url" property. Simply reassigning
|
|
166
|
-
* its value doesn't do anything. This is a destructive action
|
|
167
|
-
* but it's safe because "CONNECT" requests are forbidden per fetch.
|
|
168
|
-
*/
|
|
169
|
-
Object.defineProperty(this, "url", {
|
|
170
|
-
get: () => authority,
|
|
171
|
-
enumerable: true,
|
|
172
|
-
configurable: true
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
if (mode != null && mode !== safeMode) this.#setInternalProperty("mode", mode);
|
|
176
|
-
}
|
|
177
|
-
#setInternalProperty(key, value) {
|
|
178
|
-
const internalState = getValueBySymbol("state", this);
|
|
179
|
-
if (internalState) Reflect.set(internalState, key, value);
|
|
180
|
-
else Object.defineProperty(this, key, {
|
|
181
|
-
value,
|
|
182
|
-
enumerable: true,
|
|
183
|
-
configurable: true,
|
|
184
|
-
writable: false
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
const kStatus = Symbol("kStatus");
|
|
189
|
-
const kUrl = Symbol("kUrl");
|
|
190
|
-
var FetchResponse = class FetchResponse extends Response {
|
|
191
|
-
static {
|
|
192
|
-
this.STATUS_CODES_WITHOUT_BODY = [
|
|
193
|
-
101,
|
|
194
|
-
103,
|
|
195
|
-
204,
|
|
196
|
-
205,
|
|
197
|
-
304
|
|
198
|
-
];
|
|
199
|
-
}
|
|
200
|
-
static {
|
|
201
|
-
this.STATUS_CODES_WITH_REDIRECT = [
|
|
202
|
-
301,
|
|
203
|
-
302,
|
|
204
|
-
303,
|
|
205
|
-
307,
|
|
206
|
-
308
|
|
207
|
-
];
|
|
208
|
-
}
|
|
209
|
-
static isConfigurableStatusCode(status) {
|
|
210
|
-
return status >= 200 && status <= 599;
|
|
211
|
-
}
|
|
212
|
-
static isRedirectResponse(status) {
|
|
213
|
-
return FetchResponse.STATUS_CODES_WITH_REDIRECT.includes(status);
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* Returns a boolean indicating whether the given response status
|
|
217
|
-
* code represents a response that can have a body.
|
|
218
|
-
*/
|
|
219
|
-
static isResponseWithBody(status) {
|
|
220
|
-
return !FetchResponse.STATUS_CODES_WITHOUT_BODY.includes(status);
|
|
221
|
-
}
|
|
222
|
-
static setStatus(status, response) {
|
|
223
|
-
/**
|
|
224
|
-
* @note Undici keeps an internal "Symbol(state)" that holds
|
|
225
|
-
* the actual value of response status. Update that in Node.js.
|
|
226
|
-
*/
|
|
227
|
-
const internalState = getValueBySymbol("state", response);
|
|
228
|
-
if (internalState) internalState.status = status;
|
|
229
|
-
else Object.defineProperty(response, "status", {
|
|
230
|
-
value: status,
|
|
231
|
-
enumerable: true,
|
|
232
|
-
configurable: true,
|
|
233
|
-
writable: false
|
|
234
|
-
});
|
|
235
|
-
Object.defineProperty(response, kStatus, {
|
|
236
|
-
value: status,
|
|
237
|
-
enumerable: false
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
static setUrl(url, response) {
|
|
241
|
-
if (!url || url === "about:" || !canParseUrl(url)) return;
|
|
242
|
-
const state = getValueBySymbol("state", response);
|
|
243
|
-
if (state) state.urlList.push(new URL(url));
|
|
244
|
-
else Object.defineProperty(response, "url", {
|
|
245
|
-
value: url,
|
|
246
|
-
enumerable: true,
|
|
247
|
-
configurable: true,
|
|
248
|
-
writable: false
|
|
249
|
-
});
|
|
250
|
-
Object.defineProperty(response, kUrl, {
|
|
251
|
-
value: url,
|
|
252
|
-
enumerable: false
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
/**
|
|
256
|
-
* Parses the given raw HTTP headers into a Fetch API `Headers` instance.
|
|
257
|
-
*/
|
|
258
|
-
static parseRawHeaders(rawHeaders) {
|
|
259
|
-
const headers = new Headers();
|
|
260
|
-
for (let line = 0; line < rawHeaders.length; line += 2) headers.append(rawHeaders[line], rawHeaders[line + 1]);
|
|
261
|
-
return headers;
|
|
262
|
-
}
|
|
263
|
-
/**
|
|
264
|
-
* Safely clones the given `Response`.
|
|
265
|
-
* Coerces response clone exceptions into 500 mocked responses.
|
|
266
|
-
* Handy in the environments that introduce arbitrary response
|
|
267
|
-
* cloning restrictions, like "101 Switching Protocols" cloning
|
|
268
|
-
* in "miniflare".
|
|
269
|
-
*/
|
|
270
|
-
static clone(response) {
|
|
271
|
-
try {
|
|
272
|
-
return response.clone();
|
|
273
|
-
} catch (error) {
|
|
274
|
-
return Response.json(error instanceof Error ? {
|
|
275
|
-
name: error.name,
|
|
276
|
-
message: error.message,
|
|
277
|
-
stack: error.stack
|
|
278
|
-
} : {}, {
|
|
279
|
-
status: 500,
|
|
280
|
-
statusText: "Unclonable Response"
|
|
281
|
-
});
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
constructor(body, init = {}) {
|
|
285
|
-
const status = init.status ?? 200;
|
|
286
|
-
const safeStatus = FetchResponse.isConfigurableStatusCode(status) ? status : 200;
|
|
287
|
-
const finalBody = FetchResponse.isResponseWithBody(status) ? body : null;
|
|
288
|
-
super(finalBody, {
|
|
289
|
-
status: safeStatus,
|
|
290
|
-
statusText: init.statusText,
|
|
291
|
-
headers: init.headers
|
|
292
|
-
});
|
|
293
|
-
/**
|
|
294
|
-
* Since Node.js v24, Undici stores the Response state in an inaccessible field "#state".
|
|
295
|
-
* Forward the modified status/URL to the cloned response manually.
|
|
296
|
-
* @see https://github.com/nodejs/undici/blob/f734c87280e626c75f59aad55b65eb6a89cef392/lib/web/fetch/response.js#L242
|
|
297
|
-
*/
|
|
298
|
-
if (status !== safeStatus) FetchResponse.setStatus(status, this);
|
|
299
|
-
FetchResponse.setUrl(init.url, this);
|
|
300
|
-
}
|
|
301
|
-
clone() {
|
|
302
|
-
const clonedResponse = super.clone();
|
|
303
|
-
const customStatus = Reflect.get(this, kStatus);
|
|
304
|
-
if (customStatus) FetchResponse.setStatus(customStatus, clonedResponse);
|
|
305
|
-
const customUrl = Reflect.get(this, kUrl);
|
|
306
|
-
if (customUrl) FetchResponse.setUrl(customUrl, clonedResponse);
|
|
307
|
-
return clonedResponse;
|
|
308
|
-
}
|
|
309
|
-
};
|
|
310
|
-
|
|
311
|
-
//#endregion
|
|
312
|
-
//#region src/getRawRequest.ts
|
|
313
|
-
const kRawRequest = Symbol("kRawRequest");
|
|
314
|
-
/**
|
|
315
|
-
* Returns a raw request instance associated with this request.
|
|
316
|
-
*
|
|
317
|
-
* @example
|
|
318
|
-
* interceptor.on('request', ({ request }) => {
|
|
319
|
-
* const rawRequest = getRawRequest(request)
|
|
320
|
-
*
|
|
321
|
-
* if (rawRequest instanceof http.ClientRequest) {
|
|
322
|
-
* console.log(rawRequest.rawHeaders)
|
|
323
|
-
* }
|
|
324
|
-
* })
|
|
325
|
-
*/
|
|
326
|
-
function getRawRequest(request) {
|
|
327
|
-
return Reflect.get(request, kRawRequest);
|
|
328
|
-
}
|
|
329
|
-
function setRawRequest(request, rawRequest) {
|
|
330
|
-
Reflect.set(request, kRawRequest, rawRequest);
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
//#endregion
|
|
334
|
-
Object.defineProperty(exports, 'FetchRequest', {
|
|
335
|
-
enumerable: true,
|
|
336
|
-
get: function () {
|
|
337
|
-
return FetchRequest;
|
|
338
|
-
}
|
|
339
|
-
});
|
|
340
|
-
Object.defineProperty(exports, 'FetchResponse', {
|
|
341
|
-
enumerable: true,
|
|
342
|
-
get: function () {
|
|
343
|
-
return FetchResponse;
|
|
344
|
-
}
|
|
345
|
-
});
|
|
346
|
-
Object.defineProperty(exports, 'InterceptorError', {
|
|
347
|
-
enumerable: true,
|
|
348
|
-
get: function () {
|
|
349
|
-
return InterceptorError;
|
|
350
|
-
}
|
|
351
|
-
});
|
|
352
|
-
Object.defineProperty(exports, 'RequestController', {
|
|
353
|
-
enumerable: true,
|
|
354
|
-
get: function () {
|
|
355
|
-
return RequestController;
|
|
356
|
-
}
|
|
357
|
-
});
|
|
358
|
-
Object.defineProperty(exports, 'canParseUrl', {
|
|
359
|
-
enumerable: true,
|
|
360
|
-
get: function () {
|
|
361
|
-
return canParseUrl;
|
|
362
|
-
}
|
|
363
|
-
});
|
|
364
|
-
Object.defineProperty(exports, 'getRawRequest', {
|
|
365
|
-
enumerable: true,
|
|
366
|
-
get: function () {
|
|
367
|
-
return getRawRequest;
|
|
368
|
-
}
|
|
369
|
-
});
|
|
370
|
-
Object.defineProperty(exports, 'setRawRequest', {
|
|
371
|
-
enumerable: true,
|
|
372
|
-
get: function () {
|
|
373
|
-
return setRawRequest;
|
|
374
|
-
}
|
|
375
|
-
});
|
|
376
|
-
//# sourceMappingURL=getRawRequest-DdfaiPVH.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getRawRequest-DdfaiPVH.cjs","names":["request: Request","source: RequestControllerSource","DeferredPromise","#handled","symbol","#resolveProperty","bodyInit: { body?: BodyInit | null }","#setInternalProperty","authority: string"],"sources":["../../src/InterceptorError.ts","../../src/RequestController.ts","../../src/utils/canParseUrl.ts","../../src/utils/getValueBySymbol.ts","../../src/utils/fetchUtils.ts","../../src/getRawRequest.ts"],"sourcesContent":["export class InterceptorError extends Error {\n constructor(message?: string) {\n super(message)\n this.name = 'InterceptorError'\n Object.setPrototypeOf(this, InterceptorError.prototype)\n }\n}\n","import { DeferredPromise } from '@open-draft/deferred-promise'\nimport { invariant } from 'outvariant'\nimport { InterceptorError } from './InterceptorError'\n\nexport interface RequestControllerSource {\n passthrough(): void\n respondWith(response: Response): void\n errorWith(reason?: unknown): void\n}\n\nexport class RequestController {\n static PENDING = 0 as const\n static PASSTHROUGH = 1 as const\n static RESPONSE = 2 as const\n static ERROR = 3 as const\n\n public readyState: number\n\n /**\n * A Promise that resolves when this controller handles a request.\n * See `controller.readyState` for more information on the handling result.\n */\n public handled: Promise<void>\n\n constructor(\n protected readonly request: Request,\n protected readonly source: RequestControllerSource\n ) {\n this.readyState = RequestController.PENDING\n this.handled = new DeferredPromise<void>()\n }\n\n get #handled() {\n return this.handled as DeferredPromise<void>\n }\n\n /**\n * Perform this request as-is.\n */\n public async passthrough(): Promise<void> {\n invariant.as(\n InterceptorError,\n this.readyState === RequestController.PENDING,\n 'Failed to passthrough the \"%s %s\" request: the request has already been handled',\n this.request.method,\n this.request.url\n )\n\n this.readyState = RequestController.PASSTHROUGH\n await this.source.passthrough()\n this.#handled.resolve()\n }\n\n /**\n * Respond to this request with the given `Response` instance.\n *\n * @example\n * controller.respondWith(new Response())\n * controller.respondWith(Response.json({ id }))\n * controller.respondWith(Response.error())\n */\n public respondWith(response: Response): void {\n invariant.as(\n InterceptorError,\n this.readyState === RequestController.PENDING,\n 'Failed to respond to the \"%s %s\" request with \"%d %s\": the request has already been handled (%d)',\n this.request.method,\n this.request.url,\n response.status,\n response.statusText || 'OK',\n this.readyState\n )\n\n this.readyState = RequestController.RESPONSE\n this.#handled.resolve()\n\n /**\n * @note Although `source.respondWith()` is potentially asynchronous,\n * do NOT await it for backward-compatibility. Awaiting it will short-circuit\n * the request listener invocation as soon as a listener responds to a request.\n * Ideally, that's what we want, but that's not what we promise the user.\n */\n this.source.respondWith(response)\n }\n\n /**\n * Error this request with the given reason.\n *\n * @example\n * controller.errorWith()\n * controller.errorWith(new Error('Oops!'))\n * controller.errorWith({ message: 'Oops!'})\n */\n public errorWith(reason?: unknown): void {\n invariant.as(\n InterceptorError,\n this.readyState === RequestController.PENDING,\n 'Failed to error the \"%s %s\" request with \"%s\": the request has already been handled (%d)',\n this.request.method,\n this.request.url,\n reason?.toString(),\n this.readyState\n )\n\n this.readyState = RequestController.ERROR\n this.source.errorWith(reason)\n this.#handled.resolve()\n }\n}\n","/**\n * Returns a boolean indicating whether the given URL string\n * can be parsed into a `URL` instance.\n * A substitute for `URL.canParse()` for Node.js 18.\n */\nexport function canParseUrl(url: string): boolean {\n try {\n new URL(url)\n return true\n } catch (_error) {\n return false\n }\n}\n","/**\n * Returns the value behind the symbol with the given name.\n */\nexport function getValueBySymbol<T>(\n symbolName: string,\n source: object\n): T | undefined {\n const ownSymbols = Object.getOwnPropertySymbols(source)\n\n const symbol = ownSymbols.find((symbol) => {\n return symbol.description === symbolName\n })\n\n if (symbol) {\n return Reflect.get(source, symbol)\n }\n\n return\n}\n","import { canParseUrl } from './canParseUrl'\nimport { getValueBySymbol } from './getValueBySymbol'\n\ninterface UndiciRequestState extends RequestInit {}\n\ninterface FetchRequestInit extends Omit<RequestInit, 'mode'> {\n mode?: RequestMode | 'websocket' | 'webtransport'\n duplex?: 'half' | 'full'\n}\n\nexport class FetchRequest extends Request {\n static #resolveProperty<T extends keyof FetchRequestInit & keyof Request>(\n input: RequestInfo | URL,\n init: FetchRequestInit = {},\n key: T\n ): FetchRequestInit[T] {\n return init[key] ?? (input instanceof Request ? input[key] : undefined)\n }\n\n /**\n * Check if the given request method is configurable.\n * @see https://fetch.spec.whatwg.org/#methods\n */\n static isConfigurableMethod(method: string): boolean {\n return method !== 'CONNECT' && method !== 'TRACE' && method !== 'TRACK'\n }\n\n static isMethodWithBody(method: string): boolean {\n return (\n method !== 'HEAD' &&\n method !== 'GET' &&\n FetchRequest.isConfigurableMethod(method)\n )\n }\n\n /**\n * Check if the given request `mode` is configurable.\n * @see https://fetch.spec.whatwg.org/#concept-request-mode\n */\n static isConfigurableMode(mode: string): boolean {\n return (\n mode !== 'navigate' && mode !== 'websocket' && mode !== 'webtransport'\n )\n }\n\n constructor(input: URL | RequestInfo, init?: FetchRequestInit) {\n const method = FetchRequest.#resolveProperty(input, init, 'method') || 'GET'\n const safeMethod = FetchRequest.isConfigurableMethod(method)\n ? method\n : 'GET'\n\n const hasExplicitBody = init != null && 'body' in init\n\n /**\n * Only include `body` in the super init when it needs to be overridden.\n * When `input` is a Request and no explicit body is in `init`, let the\n * Request constructor handle body transfer naturally so it properly\n * marks the original request's body as consumed (bodyUsed = true).\n */\n const bodyInit: { body?: BodyInit | null } = !FetchRequest.isMethodWithBody(\n method\n )\n ? { body: undefined }\n : hasExplicitBody\n ? { body: init.body }\n : {}\n\n const mode =\n (FetchRequest.#resolveProperty(input, init, 'mode') as RequestMode) ??\n undefined\n const safeMode = FetchRequest.isConfigurableMode(mode) ? mode : undefined\n\n super(input, {\n ...(init || {}),\n method: safeMethod,\n mode: safeMode,\n // @ts-expect-error Untyped Node.js property.\n duplex:\n init?.duplex ??\n (FetchRequest.isMethodWithBody(method) ? 'half' : undefined),\n ...bodyInit,\n })\n\n if (method !== safeMethod) {\n this.#setInternalProperty('method', method)\n }\n\n if (method === 'CONNECT') {\n const url = new URL(input instanceof Request ? input.url : input)\n\n let authority: string\n\n /**\n * @note Node.js has a bug parsing raw CONNECT requests URLs like\n * \"http://127.0.0.1:1337/localhost:80\". It would treat \"localhost:\" as a protocol.\n */\n if (url.protocol === 'localhost:') {\n authority = url.href\n } else {\n authority = url.pathname.replace(/^\\/+/, '')\n }\n\n /**\n * @note Define \"url\" as a getter because Undici uses their own\n * logic to resolve the \"request.url\" property. Simply reassigning\n * its value doesn't do anything. This is a destructive action\n * but it's safe because \"CONNECT\" requests are forbidden per fetch.\n */\n Object.defineProperty(this, 'url', {\n get: () => authority,\n enumerable: true,\n configurable: true,\n })\n }\n\n if (mode != null && mode !== safeMode) {\n this.#setInternalProperty('mode', mode)\n }\n }\n\n #setInternalProperty<T extends keyof Request>(\n key: T,\n value: Request[T]\n ): void {\n const internalState = getValueBySymbol<UndiciRequestState>('state', this)\n\n if (internalState) {\n Reflect.set(internalState, key, value)\n } else {\n Object.defineProperty(this, key, {\n value,\n enumerable: true,\n configurable: true,\n writable: false,\n })\n }\n }\n}\n\nexport interface FetchResponseInit extends ResponseInit {\n url?: string\n}\n\ninterface UndiciResponseState {\n aborted: boolean\n rangeRequested: boolean\n timingAllowPassed: boolean\n requestIncludesCredentials: boolean\n type: ResponseType\n status: number\n statusText: string\n timingInfo: unknown\n cacheState: unknown\n headersList: Record<symbol, Map<string, unknown>>\n urlList: Array<URL>\n body?: {\n stream: ReadableStream\n source: unknown\n length: number\n }\n}\n\nconst kStatus = Symbol('kStatus')\nconst kUrl = Symbol('kUrl')\n\nexport class FetchResponse extends Response {\n /**\n * Response status codes for responses that cannot have body.\n * @see https://fetch.spec.whatwg.org/#statuses\n */\n static readonly STATUS_CODES_WITHOUT_BODY = [101, 103, 204, 205, 304]\n\n static readonly STATUS_CODES_WITH_REDIRECT = [301, 302, 303, 307, 308]\n\n static isConfigurableStatusCode(status: number): boolean {\n return status >= 200 && status <= 599\n }\n\n static isRedirectResponse(status: number): boolean {\n return FetchResponse.STATUS_CODES_WITH_REDIRECT.includes(status)\n }\n\n /**\n * Returns a boolean indicating whether the given response status\n * code represents a response that can have a body.\n */\n static isResponseWithBody(status: number): boolean {\n return !FetchResponse.STATUS_CODES_WITHOUT_BODY.includes(status)\n }\n\n static setStatus(status: number, response: Response): void {\n /**\n * @note Undici keeps an internal \"Symbol(state)\" that holds\n * the actual value of response status. Update that in Node.js.\n */\n const internalState = getValueBySymbol<UndiciResponseState>(\n 'state',\n response\n )\n\n if (internalState) {\n internalState.status = status\n } else {\n Object.defineProperty(response, 'status', {\n value: status,\n enumerable: true,\n configurable: true,\n writable: false,\n })\n }\n\n Object.defineProperty(response, kStatus, {\n value: status,\n enumerable: false,\n })\n }\n\n static setUrl(url: string | undefined, response: Response): void {\n if (!url || url === 'about:' || !canParseUrl(url)) {\n return\n }\n\n const state = getValueBySymbol<UndiciResponseState>('state', response)\n\n if (state) {\n // In Undici, push the URL to the internal list of URLs.\n // This will respect the `response.url` getter logic correctly.\n state.urlList.push(new URL(url))\n } else {\n // In other libraries, redefine the `url` property directly.\n Object.defineProperty(response, 'url', {\n value: url,\n enumerable: true,\n configurable: true,\n writable: false,\n })\n }\n\n Object.defineProperty(response, kUrl, {\n value: url,\n enumerable: false,\n })\n }\n\n /**\n * Parses the given raw HTTP headers into a Fetch API `Headers` instance.\n */\n static parseRawHeaders(rawHeaders: Array<string>): Headers {\n const headers = new Headers()\n\n for (let line = 0; line < rawHeaders.length; line += 2) {\n headers.append(rawHeaders[line], rawHeaders[line + 1])\n }\n\n return headers\n }\n\n /**\n * Safely clones the given `Response`.\n * Coerces response clone exceptions into 500 mocked responses.\n * Handy in the environments that introduce arbitrary response\n * cloning restrictions, like \"101 Switching Protocols\" cloning\n * in \"miniflare\".\n */\n static clone(response: Response): Response {\n try {\n const clone = response.clone()\n return clone\n } catch (error) {\n return Response.json(\n error instanceof Error\n ? {\n name: error.name,\n message: error.message,\n stack: error.stack,\n }\n : {},\n {\n status: 500,\n statusText: 'Unclonable Response',\n }\n )\n }\n }\n\n constructor(body?: BodyInit | null, init: FetchResponseInit = {}) {\n const status = init.status ?? 200\n const safeStatus = FetchResponse.isConfigurableStatusCode(status)\n ? status\n : 200\n const finalBody = FetchResponse.isResponseWithBody(status) ? body : null\n\n super(finalBody, {\n status: safeStatus,\n statusText: init.statusText,\n headers: init.headers,\n })\n\n /**\n * Since Node.js v24, Undici stores the Response state in an inaccessible field \"#state\".\n * Forward the modified status/URL to the cloned response manually.\n * @see https://github.com/nodejs/undici/blob/f734c87280e626c75f59aad55b65eb6a89cef392/lib/web/fetch/response.js#L242\n */\n if (status !== safeStatus) {\n FetchResponse.setStatus(status, this)\n }\n\n FetchResponse.setUrl(init.url, this)\n }\n\n public clone() {\n const clonedResponse = super.clone()\n\n const customStatus = Reflect.get(this, kStatus) as number | undefined\n\n if (customStatus) {\n FetchResponse.setStatus(customStatus, clonedResponse)\n }\n\n const customUrl = Reflect.get(this, kUrl) as string | undefined\n\n if (customUrl) {\n FetchResponse.setUrl(customUrl, clonedResponse)\n }\n\n return clonedResponse\n }\n}\n","const kRawRequest = Symbol('kRawRequest')\n\n/**\n * Returns a raw request instance associated with this request.\n *\n * @example\n * interceptor.on('request', ({ request }) => {\n * const rawRequest = getRawRequest(request)\n *\n * if (rawRequest instanceof http.ClientRequest) {\n * console.log(rawRequest.rawHeaders)\n * }\n * })\n */\nexport function getRawRequest(request: Request): unknown | undefined {\n return Reflect.get(request, kRawRequest)\n}\n\nexport function setRawRequest(request: Request, rawRequest: unknown): void {\n Reflect.set(request, kRawRequest, rawRequest)\n}\n"],"mappings":";;;;AAAA,IAAa,mBAAb,MAAa,yBAAyB,MAAM;CAC1C,YAAY,SAAkB;AAC5B,QAAM,QAAQ;AACd,OAAK,OAAO;AACZ,SAAO,eAAe,MAAM,iBAAiB,UAAU;;;;;;ACM3D,IAAa,oBAAb,MAAa,kBAAkB;;iBACZ;;;qBACI;;;kBACH;;;eACH;;CAUf,YACE,AAAmBA,SACnB,AAAmBC,QACnB;EAFmB;EACA;AAEnB,OAAK,aAAa,kBAAkB;AACpC,OAAK,UAAU,IAAIC,8CAAuB;;CAG5C,KAAIC,UAAW;AACb,SAAO,KAAK;;;;;CAMd,MAAa,cAA6B;AACxC,uBAAU,GACR,kBACA,KAAK,eAAe,kBAAkB,SACtC,qFACA,KAAK,QAAQ,QACb,KAAK,QAAQ,IACd;AAED,OAAK,aAAa,kBAAkB;AACpC,QAAM,KAAK,OAAO,aAAa;AAC/B,QAAKA,QAAS,SAAS;;;;;;;;;;CAWzB,AAAO,YAAY,UAA0B;AAC3C,uBAAU,GACR,kBACA,KAAK,eAAe,kBAAkB,SACtC,wGACA,KAAK,QAAQ,QACb,KAAK,QAAQ,KACb,SAAS,QACT,SAAS,cAAc,MACvB,KAAK,WACN;AAED,OAAK,aAAa,kBAAkB;AACpC,QAAKA,QAAS,SAAS;;;;;;;AAQvB,OAAK,OAAO,YAAY,SAAS;;;;;;;;;;CAWnC,AAAO,UAAU,QAAwB;AACvC,uBAAU,GACR,kBACA,KAAK,eAAe,kBAAkB,SACtC,gGACA,KAAK,QAAQ,QACb,KAAK,QAAQ,KACb,QAAQ,UAAU,EAClB,KAAK,WACN;AAED,OAAK,aAAa,kBAAkB;AACpC,OAAK,OAAO,UAAU,OAAO;AAC7B,QAAKA,QAAS,SAAS;;;;;;;;;;;ACrG3B,SAAgB,YAAY,KAAsB;AAChD,KAAI;AACF,MAAI,IAAI,IAAI;AACZ,SAAO;UACA,QAAQ;AACf,SAAO;;;;;;;;;ACPX,SAAgB,iBACd,YACA,QACe;CAGf,MAAM,SAFa,OAAO,sBAAsB,OAAO,CAE7B,MAAM,aAAW;AACzC,SAAOC,SAAO,gBAAgB;GAC9B;AAEF,KAAI,OACF,QAAO,QAAQ,IAAI,QAAQ,OAAO;;;;;ACJtC,IAAa,eAAb,MAAa,qBAAqB,QAAQ;CACxC,QAAOC,gBACL,OACA,OAAyB,EAAE,EAC3B,KACqB;AACrB,SAAO,KAAK,SAAS,iBAAiB,UAAU,MAAM,OAAO;;;;;;CAO/D,OAAO,qBAAqB,QAAyB;AACnD,SAAO,WAAW,aAAa,WAAW,WAAW,WAAW;;CAGlE,OAAO,iBAAiB,QAAyB;AAC/C,SACE,WAAW,UACX,WAAW,SACX,aAAa,qBAAqB,OAAO;;;;;;CAQ7C,OAAO,mBAAmB,MAAuB;AAC/C,SACE,SAAS,cAAc,SAAS,eAAe,SAAS;;CAI5D,YAAY,OAA0B,MAAyB;EAC7D,MAAM,SAAS,cAAaA,gBAAiB,OAAO,MAAM,SAAS,IAAI;EACvE,MAAM,aAAa,aAAa,qBAAqB,OAAO,GACxD,SACA;EAEJ,MAAM,kBAAkB,QAAQ,QAAQ,UAAU;;;;;;;EAQlD,MAAMC,WAAuC,CAAC,aAAa,iBACzD,OACD,GACG,EAAE,MAAM,QAAW,GACnB,kBACE,EAAE,MAAM,KAAK,MAAM,GACnB,EAAE;EAER,MAAM,OACH,cAAaD,gBAAiB,OAAO,MAAM,OAAO,IACnD;EACF,MAAM,WAAW,aAAa,mBAAmB,KAAK,GAAG,OAAO;AAEhE,QAAM,OAAO;GACX,GAAI,QAAQ,EAAE;GACd,QAAQ;GACR,MAAM;GAEN,QACE,MAAM,WACL,aAAa,iBAAiB,OAAO,GAAG,SAAS;GACpD,GAAG;GACJ,CAAC;AAEF,MAAI,WAAW,WACb,OAAKE,oBAAqB,UAAU,OAAO;AAG7C,MAAI,WAAW,WAAW;GACxB,MAAM,MAAM,IAAI,IAAI,iBAAiB,UAAU,MAAM,MAAM,MAAM;GAEjE,IAAIC;;;;;AAMJ,OAAI,IAAI,aAAa,aACnB,aAAY,IAAI;OAEhB,aAAY,IAAI,SAAS,QAAQ,QAAQ,GAAG;;;;;;;AAS9C,UAAO,eAAe,MAAM,OAAO;IACjC,WAAW;IACX,YAAY;IACZ,cAAc;IACf,CAAC;;AAGJ,MAAI,QAAQ,QAAQ,SAAS,SAC3B,OAAKD,oBAAqB,QAAQ,KAAK;;CAI3C,qBACE,KACA,OACM;EACN,MAAM,gBAAgB,iBAAqC,SAAS,KAAK;AAEzE,MAAI,cACF,SAAQ,IAAI,eAAe,KAAK,MAAM;MAEtC,QAAO,eAAe,MAAM,KAAK;GAC/B;GACA,YAAY;GACZ,cAAc;GACd,UAAU;GACX,CAAC;;;AA4BR,MAAM,UAAU,OAAO,UAAU;AACjC,MAAM,OAAO,OAAO,OAAO;AAE3B,IAAa,gBAAb,MAAa,sBAAsB,SAAS;;mCAKE;GAAC;GAAK;GAAK;GAAK;GAAK;GAAI;;;oCAExB;GAAC;GAAK;GAAK;GAAK;GAAK;GAAI;;CAEtE,OAAO,yBAAyB,QAAyB;AACvD,SAAO,UAAU,OAAO,UAAU;;CAGpC,OAAO,mBAAmB,QAAyB;AACjD,SAAO,cAAc,2BAA2B,SAAS,OAAO;;;;;;CAOlE,OAAO,mBAAmB,QAAyB;AACjD,SAAO,CAAC,cAAc,0BAA0B,SAAS,OAAO;;CAGlE,OAAO,UAAU,QAAgB,UAA0B;;;;;EAKzD,MAAM,gBAAgB,iBACpB,SACA,SACD;AAED,MAAI,cACF,eAAc,SAAS;MAEvB,QAAO,eAAe,UAAU,UAAU;GACxC,OAAO;GACP,YAAY;GACZ,cAAc;GACd,UAAU;GACX,CAAC;AAGJ,SAAO,eAAe,UAAU,SAAS;GACvC,OAAO;GACP,YAAY;GACb,CAAC;;CAGJ,OAAO,OAAO,KAAyB,UAA0B;AAC/D,MAAI,CAAC,OAAO,QAAQ,YAAY,CAAC,YAAY,IAAI,CAC/C;EAGF,MAAM,QAAQ,iBAAsC,SAAS,SAAS;AAEtE,MAAI,MAGF,OAAM,QAAQ,KAAK,IAAI,IAAI,IAAI,CAAC;MAGhC,QAAO,eAAe,UAAU,OAAO;GACrC,OAAO;GACP,YAAY;GACZ,cAAc;GACd,UAAU;GACX,CAAC;AAGJ,SAAO,eAAe,UAAU,MAAM;GACpC,OAAO;GACP,YAAY;GACb,CAAC;;;;;CAMJ,OAAO,gBAAgB,YAAoC;EACzD,MAAM,UAAU,IAAI,SAAS;AAE7B,OAAK,IAAI,OAAO,GAAG,OAAO,WAAW,QAAQ,QAAQ,EACnD,SAAQ,OAAO,WAAW,OAAO,WAAW,OAAO,GAAG;AAGxD,SAAO;;;;;;;;;CAUT,OAAO,MAAM,UAA8B;AACzC,MAAI;AAEF,UADc,SAAS,OAAO;WAEvB,OAAO;AACd,UAAO,SAAS,KACd,iBAAiB,QACb;IACE,MAAM,MAAM;IACZ,SAAS,MAAM;IACf,OAAO,MAAM;IACd,GACD,EAAE,EACN;IACE,QAAQ;IACR,YAAY;IACb,CACF;;;CAIL,YAAY,MAAwB,OAA0B,EAAE,EAAE;EAChE,MAAM,SAAS,KAAK,UAAU;EAC9B,MAAM,aAAa,cAAc,yBAAyB,OAAO,GAC7D,SACA;EACJ,MAAM,YAAY,cAAc,mBAAmB,OAAO,GAAG,OAAO;AAEpE,QAAM,WAAW;GACf,QAAQ;GACR,YAAY,KAAK;GACjB,SAAS,KAAK;GACf,CAAC;;;;;;AAOF,MAAI,WAAW,WACb,eAAc,UAAU,QAAQ,KAAK;AAGvC,gBAAc,OAAO,KAAK,KAAK,KAAK;;CAGtC,AAAO,QAAQ;EACb,MAAM,iBAAiB,MAAM,OAAO;EAEpC,MAAM,eAAe,QAAQ,IAAI,MAAM,QAAQ;AAE/C,MAAI,aACF,eAAc,UAAU,cAAc,eAAe;EAGvD,MAAM,YAAY,QAAQ,IAAI,MAAM,KAAK;AAEzC,MAAI,UACF,eAAc,OAAO,WAAW,eAAe;AAGjD,SAAO;;;;;;ACrUX,MAAM,cAAc,OAAO,cAAc;;;;;;;;;;;;;AAczC,SAAgB,cAAc,SAAuC;AACnE,QAAO,QAAQ,IAAI,SAAS,YAAY;;AAG1C,SAAgB,cAAc,SAAkB,YAA2B;AACzE,SAAQ,IAAI,SAAS,aAAa,WAAW"}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
//#region src/RequestController.d.ts
|
|
2
|
-
interface RequestControllerSource {
|
|
3
|
-
passthrough(): void;
|
|
4
|
-
respondWith(response: Response): void;
|
|
5
|
-
errorWith(reason?: unknown): void;
|
|
6
|
-
}
|
|
7
|
-
declare class RequestController {
|
|
8
|
-
#private;
|
|
9
|
-
protected readonly request: Request;
|
|
10
|
-
protected readonly source: RequestControllerSource;
|
|
11
|
-
static PENDING: 0;
|
|
12
|
-
static PASSTHROUGH: 1;
|
|
13
|
-
static RESPONSE: 2;
|
|
14
|
-
static ERROR: 3;
|
|
15
|
-
readyState: number;
|
|
16
|
-
/**
|
|
17
|
-
* A Promise that resolves when this controller handles a request.
|
|
18
|
-
* See `controller.readyState` for more information on the handling result.
|
|
19
|
-
*/
|
|
20
|
-
handled: Promise<void>;
|
|
21
|
-
constructor(request: Request, source: RequestControllerSource);
|
|
22
|
-
/**
|
|
23
|
-
* Perform this request as-is.
|
|
24
|
-
*/
|
|
25
|
-
passthrough(): Promise<void>;
|
|
26
|
-
/**
|
|
27
|
-
* Respond to this request with the given `Response` instance.
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* controller.respondWith(new Response())
|
|
31
|
-
* controller.respondWith(Response.json({ id }))
|
|
32
|
-
* controller.respondWith(Response.error())
|
|
33
|
-
*/
|
|
34
|
-
respondWith(response: Response): void;
|
|
35
|
-
/**
|
|
36
|
-
* Error this request with the given reason.
|
|
37
|
-
*
|
|
38
|
-
* @example
|
|
39
|
-
* controller.errorWith()
|
|
40
|
-
* controller.errorWith(new Error('Oops!'))
|
|
41
|
-
* controller.errorWith({ message: 'Oops!'})
|
|
42
|
-
*/
|
|
43
|
-
errorWith(reason?: unknown): void;
|
|
44
|
-
}
|
|
45
|
-
//#endregion
|
|
46
|
-
//#region src/glossary.d.ts
|
|
47
|
-
type RequestCredentials = 'omit' | 'include' | 'same-origin';
|
|
48
|
-
type HttpRequestEventMap = {
|
|
49
|
-
request: [args: {
|
|
50
|
-
request: Request;
|
|
51
|
-
requestId: string;
|
|
52
|
-
controller: RequestController;
|
|
53
|
-
}];
|
|
54
|
-
response: [args: {
|
|
55
|
-
response: Response;
|
|
56
|
-
isMockedResponse: boolean;
|
|
57
|
-
request: Request;
|
|
58
|
-
requestId: string;
|
|
59
|
-
}];
|
|
60
|
-
unhandledException: [args: {
|
|
61
|
-
error: unknown;
|
|
62
|
-
request: Request;
|
|
63
|
-
requestId: string;
|
|
64
|
-
controller: RequestController;
|
|
65
|
-
}];
|
|
66
|
-
};
|
|
67
|
-
//#endregion
|
|
68
|
-
export { RequestControllerSource as i, RequestCredentials as n, RequestController as r, HttpRequestEventMap as t };
|
|
69
|
-
//# sourceMappingURL=glossary-1lhZx6Aw.d.cts.map
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
//#region src/RequestController.d.ts
|
|
2
|
-
interface RequestControllerSource {
|
|
3
|
-
passthrough(): void;
|
|
4
|
-
respondWith(response: Response): void;
|
|
5
|
-
errorWith(reason?: unknown): void;
|
|
6
|
-
}
|
|
7
|
-
declare class RequestController {
|
|
8
|
-
#private;
|
|
9
|
-
protected readonly request: Request;
|
|
10
|
-
protected readonly source: RequestControllerSource;
|
|
11
|
-
static PENDING: 0;
|
|
12
|
-
static PASSTHROUGH: 1;
|
|
13
|
-
static RESPONSE: 2;
|
|
14
|
-
static ERROR: 3;
|
|
15
|
-
readyState: number;
|
|
16
|
-
/**
|
|
17
|
-
* A Promise that resolves when this controller handles a request.
|
|
18
|
-
* See `controller.readyState` for more information on the handling result.
|
|
19
|
-
*/
|
|
20
|
-
handled: Promise<void>;
|
|
21
|
-
constructor(request: Request, source: RequestControllerSource);
|
|
22
|
-
/**
|
|
23
|
-
* Perform this request as-is.
|
|
24
|
-
*/
|
|
25
|
-
passthrough(): Promise<void>;
|
|
26
|
-
/**
|
|
27
|
-
* Respond to this request with the given `Response` instance.
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* controller.respondWith(new Response())
|
|
31
|
-
* controller.respondWith(Response.json({ id }))
|
|
32
|
-
* controller.respondWith(Response.error())
|
|
33
|
-
*/
|
|
34
|
-
respondWith(response: Response): void;
|
|
35
|
-
/**
|
|
36
|
-
* Error this request with the given reason.
|
|
37
|
-
*
|
|
38
|
-
* @example
|
|
39
|
-
* controller.errorWith()
|
|
40
|
-
* controller.errorWith(new Error('Oops!'))
|
|
41
|
-
* controller.errorWith({ message: 'Oops!'})
|
|
42
|
-
*/
|
|
43
|
-
errorWith(reason?: unknown): void;
|
|
44
|
-
}
|
|
45
|
-
//#endregion
|
|
46
|
-
//#region src/glossary.d.ts
|
|
47
|
-
type RequestCredentials = 'omit' | 'include' | 'same-origin';
|
|
48
|
-
type HttpRequestEventMap = {
|
|
49
|
-
request: [args: {
|
|
50
|
-
request: Request;
|
|
51
|
-
requestId: string;
|
|
52
|
-
controller: RequestController;
|
|
53
|
-
}];
|
|
54
|
-
response: [args: {
|
|
55
|
-
response: Response;
|
|
56
|
-
isMockedResponse: boolean;
|
|
57
|
-
request: Request;
|
|
58
|
-
requestId: string;
|
|
59
|
-
}];
|
|
60
|
-
unhandledException: [args: {
|
|
61
|
-
error: unknown;
|
|
62
|
-
request: Request;
|
|
63
|
-
requestId: string;
|
|
64
|
-
controller: RequestController;
|
|
65
|
-
}];
|
|
66
|
-
};
|
|
67
|
-
//#endregion
|
|
68
|
-
export { RequestControllerSource as i, RequestCredentials as n, RequestController as r, HttpRequestEventMap as t };
|
|
69
|
-
//# sourceMappingURL=glossary-nkHWcwvY.d.mts.map
|