Repository URL to install this package:
|
Version:
7.1.2 ▾
|
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const exotic_1 = require("exotic");
const fromHeadersToSerialized_1 = require("./fromHeadersToSerialized");
const SERIALIZABLE_PROPERTIES_LIST = Object.freeze([
'cache',
'method',
'mode',
'referrer',
]);
/**
* @see https://github.com/bitinn/node-fetch/tree/master/src
* @see https://github.com/apollographql/apollo-server/blob/master/packages/apollo-server-env/src/index.ts
* @see https://github.com/apollographql/apollo-server/blob/master/packages/apollo-server-env/src/index.d.ts
* @see https://github.com/apollographql/apollo-server/blob/master/packages/apollo-server-core/src/nodeHttpToRequest.ts
*/
function fromRequestToSerialized(response) {
const temp = {};
const clean = {};
Object.getOwnPropertySymbols(response).forEach(symbol => {
// String(symbol) !== 'Symbol(Body internals)'
if (!response[symbol].body) {
temp[String(symbol)] = response[symbol];
}
});
const bodyInternals = temp['Symbol(Body internals)'] || exotic_1.EMPTY_OBJ;
const requestInternals = temp['Symbol(Request internals)'] || exotic_1.EMPTY_OBJ;
const merged = Object.assign({}, bodyInternals, requestInternals, response);
// clean.redirect = requestInternals.redirect
clean.body = bodyInternals.body;
clean.method = requestInternals.method;
clean.headers = fromHeadersToSerialized_1.fromHeadersToSerialized(requestInternals.headers);
clean.url = requestInternals.parsedURL.href;
SERIALIZABLE_PROPERTIES_LIST.forEach(key => {
if (merged[key] !== undefined) {
clean[key] = merged[key];
}
});
return clean;
}
exports.fromRequestToSerialized = fromRequestToSerialized;
//# sourceMappingURL=fromRequestToSerialized.js.map