UNPKG

next

Version:

The React Framework

95 lines (93 loc) 3.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); 0 && (module.exports = { logStringify: null, preLogSerializationClone: null, safeStringifyWithDepth: null }); function _export(target, all) { for(var name in all)Object.defineProperty(target, name, { enumerable: true, get: all[name] }); } _export(exports, { logStringify: function() { return logStringify; }, preLogSerializationClone: function() { return preLogSerializationClone; }, safeStringifyWithDepth: function() { return safeStringifyWithDepth; } }); const _safestablestringify = require("next/dist/compiled/safe-stable-stringify"); const _terminalloggingconfig = require("./terminal-logging-config"); const _forwardlogsshared = require("../../shared/forward-logs-shared"); const terminalLoggingConfig = (0, _terminalloggingconfig.getTerminalLoggingConfig)(); const PROMISE_MARKER = 'Promise {}'; const UNAVAILABLE_MARKER = '[Unable to view]'; const maximumDepth = typeof terminalLoggingConfig === 'object' && terminalLoggingConfig.depthLimit ? terminalLoggingConfig.depthLimit : 5; const maximumBreadth = typeof terminalLoggingConfig === 'object' && terminalLoggingConfig.edgeLimit ? terminalLoggingConfig.edgeLimit : 100; const safeStringifyWithDepth = (0, _safestablestringify.configure)({ maximumDepth, maximumBreadth }); function preLogSerializationClone(value, seen = new WeakMap()) { if (value === undefined) return _forwardlogsshared.UNDEFINED_MARKER; if (value === null || typeof value !== 'object') return value; if (seen.has(value)) return seen.get(value); try { Object.keys(value); } catch { return UNAVAILABLE_MARKER; } try { if (typeof value.then === 'function') return PROMISE_MARKER; } catch { return UNAVAILABLE_MARKER; } if (Array.isArray(value)) { const out = []; seen.set(value, out); for (const item of value){ try { out.push(preLogSerializationClone(item, seen)); } catch { out.push(UNAVAILABLE_MARKER); } } return out; } const proto = Object.getPrototypeOf(value); if (proto === Object.prototype || proto === null) { const out = {}; seen.set(value, out); for (const key of Object.keys(value)){ try { out[key] = preLogSerializationClone(value[key], seen); } catch { out[key] = UNAVAILABLE_MARKER; } } return out; } return Object.prototype.toString.call(value); } const logStringify = (data)=>{ try { const result = safeStringifyWithDepth(data); return result ?? `"${UNAVAILABLE_MARKER}"`; } catch { return `"${UNAVAILABLE_MARKER}"`; } }; if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') { Object.defineProperty(exports.default, '__esModule', { value: true }); Object.assign(exports.default, exports); module.exports = exports.default; } //# sourceMappingURL=forward-logs-utils.js.map