UNPKG

backport

Version:

A CLI tool that automates the process of backporting commits

45 lines 2.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.responseMetaInterceptorExchange = void 0; const wonka_1 = require("wonka"); // A Map to temporarily store headers and status code const temporaryResponseDataStore = new Map(); const responseMetaInterceptorExchange = ({ client, forward, }) => { // Renamed for clarity return (operations$) => { // 1. Modify outgoing operations to use a wrapped fetch const operationsWithWrappedFetch$ = (0, wonka_1.pipe)(operations$, (0, wonka_1.map)((operation) => { const originalFetch = operation.context.fetch || client.fetch || fetch; const newContext = { ...operation.context, fetch: async (input, init) => { const response = await originalFetch(input, init); // Store both headers and status code when the response is received temporaryResponseDataStore.set(operation.key, { headers: response.headers, statusCode: response.status, // Capture status code here }); return response; }, }; return { ...operation, context: newContext }; })); // 2. Forward the modified operations const resultsFromNextExchange$ = forward(operationsWithWrappedFetch$); // 3. Modify incoming results to attach the stored data return (0, wonka_1.pipe)(resultsFromNextExchange$, (0, wonka_1.map)((result) => { const storedData = temporaryResponseDataStore.get(result.operation.key); if (storedData) { temporaryResponseDataStore.delete(result.operation.key); // Clean up return { ...result, responseHeaders: storedData.headers, statusCode: storedData.statusCode, // Attach status code here }; // Use the updated interface } return result; // Cast even if not found, though it should be })); }; }; exports.responseMetaInterceptorExchange = responseMetaInterceptorExchange; //# sourceMappingURL=responseMetaInterceptorExchange.js.map