apitally
Version:
Simple API monitoring & analytics for REST APIs built with Express, Fastify, NestJS, AdonisJS, Hono, H3, Elysia, Hapi, and Koa.
1 lines • 347 kB
Source Map (JSON)
{"version":3,"sources":["../../node_modules/pino-std-serializers/lib/err-helpers.js","../../node_modules/pino-std-serializers/lib/err-proto.js","../../node_modules/pino-std-serializers/lib/err.js","../../node_modules/pino-std-serializers/lib/err-with-cause.js","../../node_modules/pino-std-serializers/lib/req.js","../../node_modules/pino-std-serializers/lib/res.js","../../node_modules/pino-std-serializers/index.js","../../node_modules/pino/lib/caller.js","../../node_modules/fast-redact/lib/validator.js","../../node_modules/fast-redact/lib/rx.js","../../node_modules/fast-redact/lib/parse.js","../../node_modules/fast-redact/lib/redactor.js","../../node_modules/fast-redact/lib/modifiers.js","../../node_modules/fast-redact/lib/restorer.js","../../node_modules/fast-redact/lib/state.js","../../node_modules/fast-redact/index.js","../../node_modules/pino/lib/symbols.js","../../node_modules/pino/lib/redaction.js","../../node_modules/pino/lib/time.js","../../node_modules/quick-format-unescaped/index.js","../../node_modules/atomic-sleep/index.js","../../node_modules/sonic-boom/index.js","../../node_modules/on-exit-leak-free/index.js","../../node_modules/thread-stream/package.json","../../node_modules/thread-stream/lib/wait.js","../../node_modules/thread-stream/lib/indexes.js","../../node_modules/thread-stream/index.js","../../node_modules/pino/lib/transport.js","../../node_modules/pino/lib/tools.js","../../node_modules/pino/lib/constants.js","../../node_modules/pino/lib/levels.js","../../node_modules/pino/lib/meta.js","../../node_modules/pino/lib/proto.js","../../node_modules/safe-stable-stringify/index.js","../../node_modules/pino/lib/multistream.js","../../node_modules/pino/pino.js","../../src/adonisjs/provider.ts","../../src/common/client.ts","../../src/common/consumerRegistry.ts","../../src/common/logging.ts","../../src/common/paramValidation.ts","../../src/common/requestCounter.ts","../../src/common/requestLogger.ts","../../src/common/sentry.ts","../../src/common/serverErrorCounter.ts","../../src/common/tempGzipFile.ts","../../src/common/validationErrorCounter.ts","../../src/common/packageVersions.ts","../../src/loggers/console.ts","../../src/loggers/hapi.ts","../../src/loggers/utils.ts","../../src/loggers/pino.ts"],"sourcesContent":["'use strict'\n\n// **************************************************************\n// * Code initially copied/adapted from \"pony-cause\" npm module *\n// * Please upstream improvements there *\n// **************************************************************\n\nconst isErrorLike = (err) => {\n return err && typeof err.message === 'string'\n}\n\n/**\n * @param {Error|{ cause?: unknown|(()=>err)}} err\n * @returns {Error|Object|undefined}\n */\nconst getErrorCause = (err) => {\n if (!err) return\n\n /** @type {unknown} */\n // @ts-ignore\n const cause = err.cause\n\n // VError / NError style causes\n if (typeof cause === 'function') {\n // @ts-ignore\n const causeResult = err.cause()\n\n return isErrorLike(causeResult)\n ? causeResult\n : undefined\n } else {\n return isErrorLike(cause)\n ? cause\n : undefined\n }\n}\n\n/**\n * Internal method that keeps a track of which error we have already added, to avoid circular recursion\n *\n * @private\n * @param {Error} err\n * @param {Set<Error>} seen\n * @returns {string}\n */\nconst _stackWithCauses = (err, seen) => {\n if (!isErrorLike(err)) return ''\n\n const stack = err.stack || ''\n\n // Ensure we don't go circular or crazily deep\n if (seen.has(err)) {\n return stack + '\\ncauses have become circular...'\n }\n\n const cause = getErrorCause(err)\n\n if (cause) {\n seen.add(err)\n return (stack + '\\ncaused by: ' + _stackWithCauses(cause, seen))\n } else {\n return stack\n }\n}\n\n/**\n * @param {Error} err\n * @returns {string}\n */\nconst stackWithCauses = (err) => _stackWithCauses(err, new Set())\n\n/**\n * Internal method that keeps a track of which error we have already added, to avoid circular recursion\n *\n * @private\n * @param {Error} err\n * @param {Set<Error>} seen\n * @param {boolean} [skip]\n * @returns {string}\n */\nconst _messageWithCauses = (err, seen, skip) => {\n if (!isErrorLike(err)) return ''\n\n const message = skip ? '' : (err.message || '')\n\n // Ensure we don't go circular or crazily deep\n if (seen.has(err)) {\n return message + ': ...'\n }\n\n const cause = getErrorCause(err)\n\n if (cause) {\n seen.add(err)\n\n // @ts-ignore\n const skipIfVErrorStyleCause = typeof err.cause === 'function'\n\n return (message +\n (skipIfVErrorStyleCause ? '' : ': ') +\n _messageWithCauses(cause, seen, skipIfVErrorStyleCause))\n } else {\n return message\n }\n}\n\n/**\n * @param {Error} err\n * @returns {string}\n */\nconst messageWithCauses = (err) => _messageWithCauses(err, new Set())\n\nmodule.exports = {\n isErrorLike,\n getErrorCause,\n stackWithCauses,\n messageWithCauses\n}\n","'use strict'\n\nconst seen = Symbol('circular-ref-tag')\nconst rawSymbol = Symbol('pino-raw-err-ref')\n\nconst pinoErrProto = Object.create({}, {\n type: {\n enumerable: true,\n writable: true,\n value: undefined\n },\n message: {\n enumerable: true,\n writable: true,\n value: undefined\n },\n stack: {\n enumerable: true,\n writable: true,\n value: undefined\n },\n aggregateErrors: {\n enumerable: true,\n writable: true,\n value: undefined\n },\n raw: {\n enumerable: false,\n get: function () {\n return this[rawSymbol]\n },\n set: function (val) {\n this[rawSymbol] = val\n }\n }\n})\nObject.defineProperty(pinoErrProto, rawSymbol, {\n writable: true,\n value: {}\n})\n\nmodule.exports = {\n pinoErrProto,\n pinoErrorSymbols: {\n seen,\n rawSymbol\n }\n}\n","'use strict'\n\nmodule.exports = errSerializer\n\nconst { messageWithCauses, stackWithCauses, isErrorLike } = require('./err-helpers')\nconst { pinoErrProto, pinoErrorSymbols } = require('./err-proto')\nconst { seen } = pinoErrorSymbols\n\nconst { toString } = Object.prototype\n\nfunction errSerializer (err) {\n if (!isErrorLike(err)) {\n return err\n }\n\n err[seen] = undefined // tag to prevent re-looking at this\n const _err = Object.create(pinoErrProto)\n _err.type = toString.call(err.constructor) === '[object Function]'\n ? err.constructor.name\n : err.name\n _err.message = messageWithCauses(err)\n _err.stack = stackWithCauses(err)\n\n if (Array.isArray(err.errors)) {\n _err.aggregateErrors = err.errors.map(err => errSerializer(err))\n }\n\n for (const key in err) {\n if (_err[key] === undefined) {\n const val = err[key]\n if (isErrorLike(val)) {\n // We append cause messages and stacks to _err, therefore skipping causes here\n if (key !== 'cause' && !Object.prototype.hasOwnProperty.call(val, seen)) {\n _err[key] = errSerializer(val)\n }\n } else {\n _err[key] = val\n }\n }\n }\n\n delete err[seen] // clean up tag in case err is serialized again later\n _err.raw = err\n return _err\n}\n","'use strict'\n\nmodule.exports = errWithCauseSerializer\n\nconst { isErrorLike } = require('./err-helpers')\nconst { pinoErrProto, pinoErrorSymbols } = require('./err-proto')\nconst { seen } = pinoErrorSymbols\n\nconst { toString } = Object.prototype\n\nfunction errWithCauseSerializer (err) {\n if (!isErrorLike(err)) {\n return err\n }\n\n err[seen] = undefined // tag to prevent re-looking at this\n const _err = Object.create(pinoErrProto)\n _err.type = toString.call(err.constructor) === '[object Function]'\n ? err.constructor.name\n : err.name\n _err.message = err.message\n _err.stack = err.stack\n\n if (Array.isArray(err.errors)) {\n _err.aggregateErrors = err.errors.map(err => errWithCauseSerializer(err))\n }\n\n if (isErrorLike(err.cause) && !Object.prototype.hasOwnProperty.call(err.cause, seen)) {\n _err.cause = errWithCauseSerializer(err.cause)\n }\n\n for (const key in err) {\n if (_err[key] === undefined) {\n const val = err[key]\n if (isErrorLike(val)) {\n if (!Object.prototype.hasOwnProperty.call(val, seen)) {\n _err[key] = errWithCauseSerializer(val)\n }\n } else {\n _err[key] = val\n }\n }\n }\n\n delete err[seen] // clean up tag in case err is serialized again later\n _err.raw = err\n return _err\n}\n","'use strict'\n\nmodule.exports = {\n mapHttpRequest,\n reqSerializer\n}\n\nconst rawSymbol = Symbol('pino-raw-req-ref')\nconst pinoReqProto = Object.create({}, {\n id: {\n enumerable: true,\n writable: true,\n value: ''\n },\n method: {\n enumerable: true,\n writable: true,\n value: ''\n },\n url: {\n enumerable: true,\n writable: true,\n value: ''\n },\n query: {\n enumerable: true,\n writable: true,\n value: ''\n },\n params: {\n enumerable: true,\n writable: true,\n value: ''\n },\n headers: {\n enumerable: true,\n writable: true,\n value: {}\n },\n remoteAddress: {\n enumerable: true,\n writable: true,\n value: ''\n },\n remotePort: {\n enumerable: true,\n writable: true,\n value: ''\n },\n raw: {\n enumerable: false,\n get: function () {\n return this[rawSymbol]\n },\n set: function (val) {\n this[rawSymbol] = val\n }\n }\n})\nObject.defineProperty(pinoReqProto, rawSymbol, {\n writable: true,\n value: {}\n})\n\nfunction reqSerializer (req) {\n // req.info is for hapi compat.\n const connection = req.info || req.socket\n const _req = Object.create(pinoReqProto)\n _req.id = (typeof req.id === 'function' ? req.id() : (req.id || (req.info ? req.info.id : undefined)))\n _req.method = req.method\n // req.originalUrl is for expressjs compat.\n if (req.originalUrl) {\n _req.url = req.originalUrl\n } else {\n const path = req.path\n // path for safe hapi compat.\n _req.url = typeof path === 'string' ? path : (req.url ? req.url.path || req.url : undefined)\n }\n\n if (req.query) {\n _req.query = req.query\n }\n\n if (req.params) {\n _req.params = req.params\n }\n\n _req.headers = req.headers\n _req.remoteAddress = connection && connection.remoteAddress\n _req.remotePort = connection && connection.remotePort\n // req.raw is for hapi compat/equivalence\n _req.raw = req.raw || req\n return _req\n}\n\nfunction mapHttpRequest (req) {\n return {\n req: reqSerializer(req)\n }\n}\n","'use strict'\n\nmodule.exports = {\n mapHttpResponse,\n resSerializer\n}\n\nconst rawSymbol = Symbol('pino-raw-res-ref')\nconst pinoResProto = Object.create({}, {\n statusCode: {\n enumerable: true,\n writable: true,\n value: 0\n },\n headers: {\n enumerable: true,\n writable: true,\n value: ''\n },\n raw: {\n enumerable: false,\n get: function () {\n return this[rawSymbol]\n },\n set: function (val) {\n this[rawSymbol] = val\n }\n }\n})\nObject.defineProperty(pinoResProto, rawSymbol, {\n writable: true,\n value: {}\n})\n\nfunction resSerializer (res) {\n const _res = Object.create(pinoResProto)\n _res.statusCode = res.headersSent ? res.statusCode : null\n _res.headers = res.getHeaders ? res.getHeaders() : res._headers\n _res.raw = res\n return _res\n}\n\nfunction mapHttpResponse (res) {\n return {\n res: resSerializer(res)\n }\n}\n","'use strict'\n\nconst errSerializer = require('./lib/err')\nconst errWithCauseSerializer = require('./lib/err-with-cause')\nconst reqSerializers = require('./lib/req')\nconst resSerializers = require('./lib/res')\n\nmodule.exports = {\n err: errSerializer,\n errWithCause: errWithCauseSerializer,\n mapHttpRequest: reqSerializers.mapHttpRequest,\n mapHttpResponse: resSerializers.mapHttpResponse,\n req: reqSerializers.reqSerializer,\n res: resSerializers.resSerializer,\n\n wrapErrorSerializer: function wrapErrorSerializer (customSerializer) {\n if (customSerializer === errSerializer) return customSerializer\n return function wrapErrSerializer (err) {\n return customSerializer(errSerializer(err))\n }\n },\n\n wrapRequestSerializer: function wrapRequestSerializer (customSerializer) {\n if (customSerializer === reqSerializers.reqSerializer) return customSerializer\n return function wrappedReqSerializer (req) {\n return customSerializer(reqSerializers.reqSerializer(req))\n }\n },\n\n wrapResponseSerializer: function wrapResponseSerializer (customSerializer) {\n if (customSerializer === resSerializers.resSerializer) return customSerializer\n return function wrappedResSerializer (res) {\n return customSerializer(resSerializers.resSerializer(res))\n }\n }\n}\n","'use strict'\n\nfunction noOpPrepareStackTrace (_, stack) {\n return stack\n}\n\nmodule.exports = function getCallers () {\n const originalPrepare = Error.prepareStackTrace\n Error.prepareStackTrace = noOpPrepareStackTrace\n const stack = new Error().stack\n Error.prepareStackTrace = originalPrepare\n\n if (!Array.isArray(stack)) {\n return undefined\n }\n\n const entries = stack.slice(2)\n\n const fileNames = []\n\n for (const entry of entries) {\n if (!entry) {\n continue\n }\n\n fileNames.push(entry.getFileName())\n }\n\n return fileNames\n}\n","'use strict'\n\nmodule.exports = validator\n\nfunction validator (opts = {}) {\n const {\n ERR_PATHS_MUST_BE_STRINGS = () => 'fast-redact - Paths must be (non-empty) strings',\n ERR_INVALID_PATH = (s) => `fast-redact – Invalid path (${s})`\n } = opts\n\n return function validate ({ paths }) {\n paths.forEach((s) => {\n if (typeof s !== 'string') {\n throw Error(ERR_PATHS_MUST_BE_STRINGS())\n }\n try {\n if (/〇/.test(s)) throw Error()\n const expr = (s[0] === '[' ? '' : '.') + s.replace(/^\\*/, '〇').replace(/\\.\\*/g, '.〇').replace(/\\[\\*\\]/g, '[〇]')\n if (/\\n|\\r|;/.test(expr)) throw Error()\n if (/\\/\\*/.test(expr)) throw Error()\n /* eslint-disable-next-line */\n Function(`\n 'use strict'\n const o = new Proxy({}, { get: () => o, set: () => { throw Error() } });\n const 〇 = null;\n o${expr}\n if ([o${expr}].length !== 1) throw Error()`)()\n } catch (e) {\n throw Error(ERR_INVALID_PATH(s))\n }\n })\n }\n}\n","'use strict'\n\nmodule.exports = /[^.[\\]]+|\\[((?:.)*?)\\]/g\n\n/*\nRegular expression explanation:\n\nAlt 1: /[^.[\\]]+/ - Match one or more characters that are *not* a dot (.)\n opening square bracket ([) or closing square bracket (])\n\nAlt 2: /\\[((?:.)*?)\\]/ - If the char IS dot or square bracket, then create a capture\n group (which will be capture group $1) that matches anything\n within square brackets. Expansion is lazy so it will\n stop matching as soon as the first closing bracket is met `]`\n (rather than continuing to match until the final closing bracket).\n*/\n","'use strict'\n\nconst rx = require('./rx')\n\nmodule.exports = parse\n\nfunction parse ({ paths }) {\n const wildcards = []\n var wcLen = 0\n const secret = paths.reduce(function (o, strPath, ix) {\n var path = strPath.match(rx).map((p) => p.replace(/'|\"|`/g, ''))\n const leadingBracket = strPath[0] === '['\n path = path.map((p) => {\n if (p[0] === '[') return p.substr(1, p.length - 2)\n else return p\n })\n const star = path.indexOf('*')\n if (star > -1) {\n const before = path.slice(0, star)\n const beforeStr = before.join('.')\n const after = path.slice(star + 1, path.length)\n const nested = after.length > 0\n wcLen++\n wildcards.push({\n before,\n beforeStr,\n after,\n nested\n })\n } else {\n o[strPath] = {\n path: path,\n val: undefined,\n precensored: false,\n circle: '',\n escPath: JSON.stringify(strPath),\n leadingBracket: leadingBracket\n }\n }\n return o\n }, {})\n\n return { wildcards, wcLen, secret }\n}\n","'use strict'\n\nconst rx = require('./rx')\n\nmodule.exports = redactor\n\nfunction redactor ({ secret, serialize, wcLen, strict, isCensorFct, censorFctTakesPath }, state) {\n /* eslint-disable-next-line */\n const redact = Function('o', `\n if (typeof o !== 'object' || o == null) {\n ${strictImpl(strict, serialize)}\n }\n const { censor, secret } = this\n const originalSecret = {}\n const secretKeys = Object.keys(secret)\n for (var i = 0; i < secretKeys.length; i++) {\n originalSecret[secretKeys[i]] = secret[secretKeys[i]]\n }\n\n ${redactTmpl(secret, isCensorFct, censorFctTakesPath)}\n this.compileRestore()\n ${dynamicRedactTmpl(wcLen > 0, isCensorFct, censorFctTakesPath)}\n this.secret = originalSecret\n ${resultTmpl(serialize)}\n `).bind(state)\n\n redact.state = state\n\n if (serialize === false) {\n redact.restore = (o) => state.restore(o)\n }\n\n return redact\n}\n\nfunction redactTmpl (secret, isCensorFct, censorFctTakesPath) {\n return Object.keys(secret).map((path) => {\n const { escPath, leadingBracket, path: arrPath } = secret[path]\n const skip = leadingBracket ? 1 : 0\n const delim = leadingBracket ? '' : '.'\n const hops = []\n var match\n while ((match = rx.exec(path)) !== null) {\n const [ , ix ] = match\n const { index, input } = match\n if (index > skip) hops.push(input.substring(0, index - (ix ? 0 : 1)))\n }\n var existence = hops.map((p) => `o${delim}${p}`).join(' && ')\n if (existence.length === 0) existence += `o${delim}${path} != null`\n else existence += ` && o${delim}${path} != null`\n\n const circularDetection = `\n switch (true) {\n ${hops.reverse().map((p) => `\n case o${delim}${p} === censor:\n secret[${escPath}].circle = ${JSON.stringify(p)}\n break\n `).join('\\n')}\n }\n `\n\n const censorArgs = censorFctTakesPath\n ? `val, ${JSON.stringify(arrPath)}`\n : `val`\n\n return `\n if (${existence}) {\n const val = o${delim}${path}\n if (val === censor) {\n secret[${escPath}].precensored = true\n } else {\n secret[${escPath}].val = val\n o${delim}${path} = ${isCensorFct ? `censor(${censorArgs})` : 'censor'}\n ${circularDetection}\n }\n }\n `\n }).join('\\n')\n}\n\nfunction dynamicRedactTmpl (hasWildcards, isCensorFct, censorFctTakesPath) {\n return hasWildcards === true ? `\n {\n const { wildcards, wcLen, groupRedact, nestedRedact } = this\n for (var i = 0; i < wcLen; i++) {\n const { before, beforeStr, after, nested } = wildcards[i]\n if (nested === true) {\n secret[beforeStr] = secret[beforeStr] || []\n nestedRedact(secret[beforeStr], o, before, after, censor, ${isCensorFct}, ${censorFctTakesPath})\n } else secret[beforeStr] = groupRedact(o, before, censor, ${isCensorFct}, ${censorFctTakesPath})\n }\n }\n ` : ''\n}\n\nfunction resultTmpl (serialize) {\n return serialize === false ? `return o` : `\n var s = this.serialize(o)\n this.restore(o)\n return s\n `\n}\n\nfunction strictImpl (strict, serialize) {\n return strict === true\n ? `throw Error('fast-redact: primitives cannot be redacted')`\n : serialize === false ? `return o` : `return this.serialize(o)`\n}\n","'use strict'\n\nmodule.exports = {\n groupRedact,\n groupRestore,\n nestedRedact,\n nestedRestore\n}\n\nfunction groupRestore ({ keys, values, target }) {\n if (target == null || typeof target === 'string') return\n const length = keys.length\n for (var i = 0; i < length; i++) {\n const k = keys[i]\n target[k] = values[i]\n }\n}\n\nfunction groupRedact (o, path, censor, isCensorFct, censorFctTakesPath) {\n const target = get(o, path)\n if (target == null || typeof target === 'string') return { keys: null, values: null, target, flat: true }\n const keys = Object.keys(target)\n const keysLength = keys.length\n const pathLength = path.length\n const pathWithKey = censorFctTakesPath ? [...path] : undefined\n const values = new Array(keysLength)\n\n for (var i = 0; i < keysLength; i++) {\n const key = keys[i]\n values[i] = target[key]\n\n if (censorFctTakesPath) {\n pathWithKey[pathLength] = key\n target[key] = censor(target[key], pathWithKey)\n } else if (isCensorFct) {\n target[key] = censor(target[key])\n } else {\n target[key] = censor\n }\n }\n return { keys, values, target, flat: true }\n}\n\n/**\n * @param {RestoreInstruction[]} instructions a set of instructions for restoring values to objects\n */\nfunction nestedRestore (instructions) {\n for (let i = 0; i < instructions.length; i++) {\n const { target, path, value } = instructions[i]\n let current = target\n for (let i = path.length - 1; i > 0; i--) {\n current = current[path[i]]\n }\n current[path[0]] = value\n }\n}\n\nfunction nestedRedact (store, o, path, ns, censor, isCensorFct, censorFctTakesPath) {\n const target = get(o, path)\n if (target == null) return\n const keys = Object.keys(target)\n const keysLength = keys.length\n for (var i = 0; i < keysLength; i++) {\n const key = keys[i]\n specialSet(store, target, key, path, ns, censor, isCensorFct, censorFctTakesPath)\n }\n return store\n}\n\nfunction has (obj, prop) {\n return obj !== undefined && obj !== null\n ? ('hasOwn' in Object ? Object.hasOwn(obj, prop) : Object.prototype.hasOwnProperty.call(obj, prop))\n : false\n}\n\nfunction specialSet (store, o, k, path, afterPath, censor, isCensorFct, censorFctTakesPath) {\n const afterPathLen = afterPath.length\n const lastPathIndex = afterPathLen - 1\n const originalKey = k\n var i = -1\n var n\n var nv\n var ov\n var oov = null\n var wc = null\n var kIsWc\n var wcov\n var consecutive = false\n var level = 0\n // need to track depth of the `redactPath` tree\n var depth = 0\n var redactPathCurrent = tree()\n ov = n = o[k]\n if (typeof n !== 'object') return\n while (n != null && ++i < afterPathLen) {\n depth += 1\n k = afterPath[i]\n oov = ov\n if (k !== '*' && !wc && !(typeof n === 'object' && k in n)) {\n break\n }\n if (k === '*') {\n if (wc === '*') {\n consecutive = true\n }\n wc = k\n if (i !== lastPathIndex) {\n continue\n }\n }\n if (wc) {\n const wcKeys = Object.keys(n)\n for (var j = 0; j < wcKeys.length; j++) {\n const wck = wcKeys[j]\n wcov = n[wck]\n kIsWc = k === '*'\n if (consecutive) {\n redactPathCurrent = node(redactPathCurrent, wck, depth)\n level = i\n ov = iterateNthLevel(wcov, level - 1, k, path, afterPath, censor, isCensorFct, censorFctTakesPath, originalKey, n, nv, ov, kIsWc, wck, i, lastPathIndex, redactPathCurrent, store, o[originalKey], depth + 1)\n } else {\n if (kIsWc || (typeof wcov === 'object' && wcov !== null && k in wcov)) {\n if (kIsWc) {\n ov = wcov\n } else {\n ov = wcov[k]\n }\n nv = (i !== lastPathIndex)\n ? ov\n : (isCensorFct\n ? (censorFctTakesPath ? censor(ov, [...path, originalKey, ...afterPath]) : censor(ov))\n : censor)\n if (kIsWc) {\n const rv = restoreInstr(node(redactPathCurrent, wck, depth), ov, o[originalKey])\n store.push(rv)\n n[wck] = nv\n } else {\n if (wcov[k] === nv) {\n // pass\n } else if ((nv === undefined && censor !== undefined) || (has(wcov, k) && nv === ov)) {\n redactPathCurrent = node(redactPathCurrent, wck, depth)\n } else {\n redactPathCurrent = node(redactPathCurrent, wck, depth)\n const rv = restoreInstr(node(redactPathCurrent, k, depth + 1), ov, o[originalKey])\n store.push(rv)\n wcov[k] = nv\n }\n }\n }\n }\n }\n wc = null\n } else {\n ov = n[k]\n redactPathCurrent = node(redactPathCurrent, k, depth)\n nv = (i !== lastPathIndex)\n ? ov\n : (isCensorFct\n ? (censorFctTakesPath ? censor(ov, [...path, originalKey, ...afterPath]) : censor(ov))\n : censor)\n if ((has(n, k) && nv === ov) || (nv === undefined && censor !== undefined)) {\n // pass\n } else {\n const rv = restoreInstr(redactPathCurrent, ov, o[originalKey])\n store.push(rv)\n n[k] = nv\n }\n n = n[k]\n }\n if (typeof n !== 'object') break\n // prevent circular structure, see https://github.com/pinojs/pino/issues/1513\n if (ov === oov || typeof ov === 'undefined') {\n // pass\n }\n }\n}\n\nfunction get (o, p) {\n var i = -1\n var l = p.length\n var n = o\n while (n != null && ++i < l) {\n n = n[p[i]]\n }\n return n\n}\n\nfunction iterateNthLevel (wcov, level, k, path, afterPath, censor, isCensorFct, censorFctTakesPath, originalKey, n, nv, ov, kIsWc, wck, i, lastPathIndex, redactPathCurrent, store, parent, depth) {\n if (level === 0) {\n if (kIsWc || (typeof wcov === 'object' && wcov !== null && k in wcov)) {\n if (kIsWc) {\n ov = wcov\n } else {\n ov = wcov[k]\n }\n nv = (i !== lastPathIndex)\n ? ov\n : (isCensorFct\n ? (censorFctTakesPath ? censor(ov, [...path, originalKey, ...afterPath]) : censor(ov))\n : censor)\n if (kIsWc) {\n const rv = restoreInstr(redactPathCurrent, ov, parent)\n store.push(rv)\n n[wck] = nv\n } else {\n if (wcov[k] === nv) {\n // pass\n } else if ((nv === undefined && censor !== undefined) || (has(wcov, k) && nv === ov)) {\n // pass\n } else {\n const rv = restoreInstr(node(redactPathCurrent, k, depth + 1), ov, parent)\n store.push(rv)\n wcov[k] = nv\n }\n }\n }\n }\n for (const key in wcov) {\n if (typeof wcov[key] === 'object') {\n redactPathCurrent = node(redactPathCurrent, key, depth)\n iterateNthLevel(wcov[key], level - 1, k, path, afterPath, censor, isCensorFct, censorFctTakesPath, originalKey, n, nv, ov, kIsWc, wck, i, lastPathIndex, redactPathCurrent, store, parent, depth + 1)\n }\n }\n}\n\n/**\n * @typedef {object} TreeNode\n * @prop {TreeNode} [parent] reference to the parent of this node in the tree, or `null` if there is no parent\n * @prop {string} key the key that this node represents (key here being part of the path being redacted\n * @prop {TreeNode[]} children the child nodes of this node\n * @prop {number} depth the depth of this node in the tree\n */\n\n/**\n * instantiate a new, empty tree\n * @returns {TreeNode}\n */\nfunction tree () {\n return { parent: null, key: null, children: [], depth: 0 }\n}\n\n/**\n * creates a new node in the tree, attaching it as a child of the provided parent node\n * if the specified depth matches the parent depth, adds the new node as a _sibling_ of the parent instead\n * @param {TreeNode} parent the parent node to add a new node to (if the parent depth matches the provided `depth` value, will instead add as a sibling of this\n * @param {string} key the key that the new node represents (key here being part of the path being redacted)\n * @param {number} depth the depth of the new node in the tree - used to determing whether to add the new node as a child or sibling of the provided `parent` node\n * @returns {TreeNode} a reference to the newly created node in the tree\n */\nfunction node (parent, key, depth) {\n if (parent.depth === depth) {\n return node(parent.parent, key, depth)\n }\n\n var child = {\n parent,\n key,\n depth,\n children: []\n }\n\n parent.children.push(child)\n\n return child\n}\n\n/**\n * @typedef {object} RestoreInstruction\n * @prop {string[]} path a reverse-order path that can be used to find the correct insertion point to restore a `value` for the given `parent` object\n * @prop {*} value the value to restore\n * @prop {object} target the object to restore the `value` in\n */\n\n/**\n * create a restore instruction for the given redactPath node\n * generates a path in reverse order by walking up the redactPath tree\n * @param {TreeNode} node a tree node that should be at the bottom of the redact path (i.e. have no children) - this will be used to walk up the redact path tree to construct the path needed to restore\n * @param {*} value the value to restore\n * @param {object} target a reference to the parent object to apply the restore instruction to\n * @returns {RestoreInstruction} an instruction used to restore a nested value for a specific object\n */\nfunction restoreInstr (node, value, target) {\n let current = node\n const path = []\n do {\n path.push(current.key)\n current = current.parent\n } while (current.parent != null)\n\n return { path, value, target }\n}\n","'use strict'\n\nconst { groupRestore, nestedRestore } = require('./modifiers')\n\nmodule.exports = restorer\n\nfunction restorer () {\n return function compileRestore () {\n if (this.restore) {\n this.restore.state.secret = this.secret\n return\n }\n const { secret, wcLen } = this\n const paths = Object.keys(secret)\n const resetters = resetTmpl(secret, paths)\n const hasWildcards = wcLen > 0\n const state = hasWildcards ? { secret, groupRestore, nestedRestore } : { secret }\n /* eslint-disable-next-line */\n this.restore = Function(\n 'o',\n restoreTmpl(resetters, paths, hasWildcards)\n ).bind(state)\n this.restore.state = state\n }\n}\n\n/**\n * Mutates the original object to be censored by restoring its original values\n * prior to censoring.\n *\n * @param {object} secret Compiled object describing which target fields should\n * be censored and the field states.\n * @param {string[]} paths The list of paths to censor as provided at\n * initialization time.\n *\n * @returns {string} String of JavaScript to be used by `Function()`. The\n * string compiles to the function that does the work in the description.\n */\nfunction resetTmpl (secret, paths) {\n return paths.map((path) => {\n const { circle, escPath, leadingBracket } = secret[path]\n const delim = leadingBracket ? '' : '.'\n const reset = circle\n ? `o.${circle} = secret[${escPath}].val`\n : `o${delim}${path} = secret[${escPath}].val`\n const clear = `secret[${escPath}].val = undefined`\n return `\n if (secret[${escPath}].val !== undefined) {\n try { ${reset} } catch (e) {}\n ${clear}\n }\n `\n }).join('')\n}\n\n/**\n * Creates the body of the restore function\n *\n * Restoration of the redacted object happens\n * backwards, in reverse order of redactions,\n * so that repeated redactions on the same object\n * property can be eventually rolled back to the\n * original value.\n *\n * This way dynamic redactions are restored first,\n * starting from the last one working backwards and\n * followed by the static ones.\n *\n * @returns {string} the body of the restore function\n */\nfunction restoreTmpl (resetters, paths, hasWildcards) {\n const dynamicReset = hasWildcards === true ? `\n const keys = Object.keys(secret)\n const len = keys.length\n for (var i = len - 1; i >= ${paths.length}; i--) {\n const k = keys[i]\n const o = secret[k]\n if (o) {\n if (o.flat === true) this.groupRestore(o)\n else this.nestedRestore(o)\n secret[k] = null\n }\n }\n ` : ''\n\n return `\n const secret = this.secret\n ${dynamicReset}\n ${resetters}\n return o\n `\n}\n","'use strict'\n\nmodule.exports = state\n\nfunction state (o) {\n const {\n secret,\n censor,\n compileRestore,\n serialize,\n groupRedact,\n nestedRedact,\n wildcards,\n wcLen\n } = o\n const builder = [{ secret, censor, compileRestore }]\n if (serialize !== false) builder.push({ serialize })\n if (wcLen > 0) builder.push({ groupRedact, nestedRedact, wildcards, wcLen })\n return Object.assign(...builder)\n}\n","'use strict'\n\nconst validator = require('./lib/validator')\nconst parse = require('./lib/parse')\nconst redactor = require('./lib/redactor')\nconst restorer = require('./lib/restorer')\nconst { groupRedact, nestedRedact } = require('./lib/modifiers')\nconst state = require('./lib/state')\nconst rx = require('./lib/rx')\nconst validate = validator()\nconst noop = (o) => o\nnoop.restore = noop\n\nconst DEFAULT_CENSOR = '[REDACTED]'\nfastRedact.rx = rx\nfastRedact.validator = validator\n\nmodule.exports = fastRedact\n\nfunction fastRedact (opts = {}) {\n const paths = Array.from(new Set(opts.paths || []))\n const serialize = 'serialize' in opts ? (\n opts.serialize === false ? opts.serialize\n : (typeof opts.serialize === 'function' ? opts.serialize : JSON.stringify)\n ) : JSON.stringify\n const remove = opts.remove\n if (remove === true && serialize !== JSON.stringify) {\n throw Error('fast-redact – remove option may only be set when serializer is JSON.stringify')\n }\n const censor = remove === true\n ? undefined\n : 'censor' in opts ? opts.censor : DEFAULT_CENSOR\n\n const isCensorFct = typeof censor === 'function'\n const censorFctTakesPath = isCensorFct && censor.length > 1\n\n if (paths.length === 0) return serialize || noop\n\n validate({ paths, serialize, censor })\n\n const { wildcards, wcLen, secret } = parse({ paths, censor })\n\n const compileRestore = restorer()\n const strict = 'strict' in opts ? opts.strict : true\n\n return redactor({ secret, wcLen, serialize, strict, isCensorFct, censorFctTakesPath }, state({\n secret,\n censor,\n compileRestore,\n serialize,\n groupRedact,\n nestedRedact,\n wildcards,\n wcLen\n }))\n}\n","'use strict'\n\nconst setLevelSym = Symbol('pino.setLevel')\nconst getLevelSym = Symbol('pino.getLevel')\nconst levelValSym = Symbol('pino.levelVal')\nconst levelCompSym = Symbol('pino.levelComp')\nconst useLevelLabelsSym = Symbol('pino.useLevelLabels')\nconst useOnlyCustomLevelsSym = Symbol('pino.useOnlyCustomLevels')\nconst mixinSym = Symbol('pino.mixin')\n\nconst lsCacheSym = Symbol('pino.lsCache')\nconst chindingsSym = Symbol('pino.chindings')\n\nconst asJsonSym = Symbol('pino.asJson')\nconst writeSym = Symbol('pino.write')\nconst redactFmtSym = Symbol('pino.redactFmt')\n\nconst timeSym = Symbol('pino.time')\nconst timeSliceIndexSym = Symbol('pino.timeSliceIndex')\nconst streamSym = Symbol('pino.stream')\nconst stringifySym = Symbol('pino.stringify')\nconst stringifySafeSym = Symbol('pino.stringifySafe')\nconst stringifiersSym = Symbol('pino.stringifiers')\nconst endSym = Symbol('pino.end')\nconst formatOptsSym = Symbol('pino.formatOpts')\nconst messageKeySym = Symbol('pino.messageKey')\nconst errorKeySym = Symbol('pino.errorKey')\nconst nestedKeySym = Symbol('pino.nestedKey')\nconst nestedKeyStrSym = Symbol('pino.nestedKeyStr')\nconst mixinMergeStrategySym = Symbol('pino.mixinMergeStrategy')\nconst msgPrefixSym = Symbol('pino.msgPrefix')\n\nconst wildcardFirstSym = Symbol('pino.wildcardFirst')\n\n// public symbols, no need to use the same pino\n// version for these\nconst serializersSym = Symbol.for('pino.serializers')\nconst formattersSym = Symbol.for('pino.formatters')\nconst hooksSym = Symbol.for('pino.hooks')\nconst needsMetadataGsym = Symbol.for('pino.metadata')\n\nmodule.exports = {\n setLevelSym,\n getLevelSym,\n levelValSym,\n levelCompSym,\n useLevelLabelsSym,\n mixinSym,\n lsCacheSym,\n chindingsSym,\n asJsonSym,\n writeSym,\n serializersSym,\n redactFmtSym,\n timeSym,\n timeSliceIndexSym,\n streamSym,\n stringifySym,\n stringifySafeSym,\n stringifiersSym,\n endSym,\n formatOptsSym,\n messageKeySym,\n errorKeySym,\n nestedKeySym,\n wildcardFirstSym,\n needsMetadataGsym,\n useOnlyCustomLevelsSym,\n formattersSym,\n hooksSym,\n nestedKeyStrSym,\n mixinMergeStrategySym,\n msgPrefixSym\n}\n","'use strict'\n\nconst fastRedact = require('fast-redact')\nconst { redactFmtSym, wildcardFirstSym } = require('./symbols')\nconst { rx, validator } = fastRedact\n\nconst validate = validator({\n ERR_PATHS_MUST_BE_STRINGS: () => 'pino – redacted paths must be strings',\n ERR_INVALID_PATH: (s) => `pino – redact paths array contains an invalid path (${s})`\n})\n\nconst CENSOR = '[Redacted]'\nconst strict = false // TODO should this be configurable?\n\nfunction redaction (opts, serialize) {\n const { paths, censor } = handle(opts)\n\n const shape = paths.reduce((o, str) => {\n rx.lastIndex = 0\n const first = rx.exec(str)\n const next = rx.exec(str)\n\n // ns is the top-level path segment, brackets + quoting removed.\n let ns = first[1] !== undefined\n ? first[1].replace(/^(?:\"|'|`)(.*)(?:\"|'|`)$/, '$1')\n : first[0]\n\n if (ns === '*') {\n ns = wildcardFirstSym\n }\n\n // top level key:\n if (next === null) {\n o[ns] = null\n return o\n }\n\n // path with at least two segments:\n // if ns is already redacted at the top level, ignore lower level redactions\n if (o[ns] === null) {\n return o\n }\n\n const { index } = next\n const nextPath = `${str.substr(index, str.length - 1)}`\n\n o[ns] = o[ns] || []\n\n // shape is a mix of paths beginning with literal values and wildcard\n // paths [ \"a.b.c\", \"*.b.z\" ] should reduce to a shape of\n // { \"a\": [ \"b.c\", \"b.z\" ], *: [ \"b.z\" ] }\n // note: \"b.z\" is in both \"a\" and * arrays because \"a\" matches the wildcard.\n // (* entry has wildcardFirstSym as key)\n if (ns !== wildcardFirstSym && o[ns].length === 0) {\n // first time ns's get all '*' redactions so far\n o[ns].push(...(o[wildcardFirstSym] || []))\n }\n\n if (ns === wildcardFirstSym) {\n // new * path gets added to all previously registered literal ns's.\n Object.keys(o).forEach(function (k) {\n if (o[k]) {\n o[k].push(nextPath)\n }\n })\n }\n\n o[ns].push(nextPath)\n return o\n }, {})\n\n // the redactor assigned to the format symbol key\n // provides top level redaction for instances where\n // an object is interpolated into the msg string\n const result = {\n [redactFmtSym]: fastRedact({ paths, censor, serialize, strict })\n }\n\n const topCensor = (...args) => {\n return typeof censor === 'function' ? serialize(censor(...args)) : serialize(censor)\n }\n\n return [...Object.keys(shape), ...Object.getOwnPropertySymbols(shape)].reduce((o, k) => {\n // top level key:\n if (shape[k] === null) {\n o[k] = (value) => topCensor(value, [k])\n } else {\n const wrappedCensor = typeof censor === 'function'\n ? (value, path) => {\n return censor(value, [k, ...path])\n }\n : censor\n o[k] = fastRedact({\n paths: shape[k],\n censor: wrappedCensor,\n serialize,\n strict\n })\n }\n return o\n }, result)\n}\n\nfunction handle (opts) {\n if (Array.isArray(opts)) {\n opts = { paths: opts, censor: CENSOR }\n validate(opts)\n return opts\n }\n let { paths, censor = CENSOR, remove } = opts\n if (Array.isArray(paths) === false) { throw Error('pino – redact must contain an array of strings') }\n if (remove === true) censor = undefined\n validate({ paths, censor })\n\n return { paths, censor }\n}\n\nmodule.exports = redaction\n","'use strict'\n\nconst nullTime = () => ''\n\nconst epochTime = () => `,\"time\":${Date.now()}`\n\nconst unixTime = () => `,\"time\":${Math.round(Date.now() / 1000.0)}`\n\nconst isoTime = () => `,\"time\":\"${new Date(Date.now()).toISOString()}\"` // using Date.now() for testability\n\nconst NS_PER_MS = 1_000_000n\nconst NS_PER_SEC = 1_000_000_000n\n\nconst startWallTimeNs = BigInt(Date.now()) * NS_PER_MS\nconst startHrTime = process.hrtime.bigint()\n\nconst isoTimeNano = () => {\n const elapsedNs = process.hrtime.bigint() - startHrTime\n const currentTimeNs = startWallTimeNs + elapsedNs\n\n const secondsSinceEpoch = currentTimeNs / NS_PER_SEC\n const nanosWithinSecond = currentTimeNs % NS_PER_SEC\n\n const msSinceEpoch = Number(secondsSinceEpoch * 1000n + nanosWithinSecond / 1_000_000n)\n const date = new Date(msSinceEpoch)\n\n const year = date.getUTCFullYear()\n const month = (date.getUTCMonth() + 1).toString().padStart(2, '0')\n const day = date.getUTCDate().toString().padStart(2, '0')\n const hours = date.getUTCHours().toString().padStart(2, '0')\n const minutes = date.getUTCMinutes().toString().padStart(2, '0')\n const seconds = date.getUTCSeconds().toString().padStart(2, '0')\n\n return `,\"time\":\"${year}-${month}-${day}T${hours}:${minutes}:${seconds}.${nanosWithinSecond\n .toString()\n .padStart(9, '0')}Z\"`\n}\n\nmodule.exports = { nullTime, epochTime, unixTime, isoTime, isoTimeNano }\n","'use strict'\nfunction tryStringify (o) {\n try { return JSON.stringify(o) } catch(e) { return '\"[Circular]\"' }\n}\n\nmodule.exports = format\n\nfunction format(f, args, opts) {\n var ss = (opts && opts.stringify) || tryStringify\n var offset = 1\n if (typeof f === 'object' && f !== null) {\n var len = args.length + offset\n if (len === 1) return f\n var objects = new Array(len)\n objects[0] = ss(f)\n for (var index = 1; index < len; index++) {\n objects[index] = ss(args[index])\n }\n return objects.join(' ')\n }\n if (typeof f !== 'string') {\n return f\n }\n var argLen = args.length\n if (argLen === 0) return f\n var str = ''\n var a = 1 - offset\n var lastPos = -1\n var flen = (f && f.length) || 0\n for (var i = 0; i < flen;) {\n if (f.charCodeAt(i) === 37 && i + 1 < flen) {\n lastPos = lastPos > -1 ? lastPos : 0\n switch (f.charCodeAt(i + 1)) {\n case 100: // 'd'\n case 102: // 'f'\n if (a >= argLen)\n break\n if (args[a] == null) break\n if (lastPos < i)\n str += f.slice(lastPos, i)\n str += Number(args[a])\n lastPos = i + 2\n i++\n break\n case 105: // 'i'\n if (a >= argLen)\n break\n if (args[a] == null) break\n if (lastPos < i)\n str += f.slice(lastPos, i)\n str += Math.floor(Number(args[a]))\n lastPos = i + 2\n i++\n break\n case 79: // 'O'\n case 111: // 'o'\n case 106: // 'j'\n if (a >= argLen)\n break\n if (args[a] === undefined) break\n if (lastPos < i)\n str += f.slice(lastPos, i)\n var type = typeof args[a]\n if (type === 'string') {\n str += '\\'' + args[a] + '\\''\n lastPos = i + 2\n i++\n break\n }\n if (type === 'function') {\n str += args[a].name || '<anonymous>'\n lastPos = i + 2\n i++\n break\n }\n str += ss(args[a])\n lastPos = i + 2\n i++\n break\n case 115: // 's'\n if (a >= argLen)\n break\n if (lastPos < i)\n str += f.slice(lastPos, i)\n str += String(args[a])\n lastPos = i + 2\n i++\n break\n case 37: // '%'\n if (lastPos < i)\n str += f.slice(lastPos, i)\n str += '%'\n lastPos = i + 2\n i++\n a--\n break\n }\n ++a\n }\n ++i\n }\n if (lastPos === -1)\n return f\n else if (lastPos < flen) {\n str += f.slice(lastPos)\n }\n\n return str\n}\n","'use strict'\n\n/* global SharedArrayBuffer, Atomics */\n\nif (typeof SharedArrayBuffer !== 'undefined' && typeof Atomics !== 'undefined') {\n const nil = new Int32Array(new SharedArrayBuffer(4))\n\n function sleep (ms) {\n // also filters out NaN, non-number types, including empty strings, but allows bigints\n const valid = ms > 0 && ms < Infinity \n if (valid === false) {\n if (typeof ms !== 'number' && typeof ms !== 'bigint') {\n throw TypeError('sleep: ms must be a number')\n }\n throw RangeError('sleep: ms must be a number that is greater than 0 but less than Infinity')\n }\n\n Atomics.wait(nil, 0, 0, Number(ms))\n }\n module.exports = sleep\n} else {\n\n function sleep (ms) {\n // also filters out NaN, non-number types, including empty strings, but allows bigints\n const valid = ms > 0 && ms < Infinity \n if (valid === false) {\n if (typeof ms !== 'number' && typeof ms !== 'bigint') {\n throw TypeError('sleep: ms must be a number')\n }\n throw RangeError('sleep: ms must be a number that is greater than 0 but less than Infinity')\n }\n const target = Date.now() + Number(ms)\n while (target > Date.now()){}\n }\n\n module.exports = sleep\n\n}\n","'use strict'\n\nconst fs = require('fs')\nconst EventEmitter = require('events')\nconst inherits = require('util').inherits\nconst path = require('path')\nconst sleep = require('atomic-sleep')\nconst assert = require('assert')\n\nconst BUSY_WRITE_TIMEOUT = 100\nconst kEmptyBuffer = Buffer.allocUnsafe(0)\n\n// 16 KB. Don't write more than docker buffer size.\n// https://github.com/moby/moby/blob/513ec73831269947d38a644c278ce3cac36783b2/daemon/logger/copier.go#L13\nconst MAX_WRITE = 16 * 1024\n\nconst kContentModeBuffer = 'buffer'\nconst kContentModeUtf8 = 'utf8'\n\nconst [major, minor] = (process.versions.node || '0.0').split('.').map(Number)\nconst kCopyBuffer = major >= 22 && minor >= 7\n\nfunction openFile (file, sonic) {\n sonic._opening = true\n sonic._writing = true\n sonic._asyncDrainScheduled = false\n\n // NOTE: 'error' and 'ready' events emitted below only relevant when sonic.sync===false\n // for sync mode, there is no way to add a listener that will receive these\n\n function fileOpened (err, fd) {\n if (err) {\n sonic._reopening = false\n sonic._writing = false\n sonic._opening = false\n\n if (sonic.sync) {\n process.nextTick(() => {\n if (sonic.listenerCount('error') > 0) {\n sonic.emit('error', err)\n }\n })\n } else {\n sonic.emit('error', err)\n }\n return\n }\n\n const reopening = sonic._reopening\n\n sonic.fd = fd\n sonic.file = file\n sonic._reopening = false\n sonic._opening = false\n sonic._writing = false\n\n if (sonic.sync) {\n process.nextTick(() => sonic.emit('ready'))\n } else {\n sonic.emit('ready')\n }\n\n if (sonic.destroyed) {\n return\n }\n\n // start\n if ((!sonic._writing && sonic._len > sonic.minLength) || sonic._flushPending) {\n sonic._actualWrite()\n } else if (reopening) {\n process.nextTick(() => sonic.emit('drain'))\n }\n }\n\n const flags = sonic.append ? 'a' : 'w'\n const mode = sonic.mode\n\n if (sonic.sync) {\n try {\n if (sonic.mkdir) fs.mkdirSync(path.dirname(file), { recursive: true })\n const fd = fs.openSync(file, flags, mode)\n fileOpened(null, fd)\n } catch (err) {\n fileOpened(err)\n throw err\n }\n } else if (sonic.mkdir) {\n fs.mkdir(path.dirname(file), { recursive: true }, (err) => {\n if (err) return fileOpened(err)\n fs.open(file, flags, mode, fileOpened)\n })\n } else {\n fs.open(file, flags, mode, fileOpened)\n }\n}\n\nfunction SonicBoom (opts) {\n if (!(this instanceof SonicBoom)) {\n return new SonicBoom(opts)\n }\n\n let { fd, dest, minLength, maxLength, maxWrite, periodicFlush, sync, append = true, mkdir, retryEAGAIN, fsync, contentMode, mode } = opts || {}\n\n fd = fd || dest\n\n this._len = 0\n this.fd = -1\n this._bufs = []\n this._lens = []\n this._writing = false\n this._ending = false\n this._reopening = false\n this._asyncDrainScheduled = false\n this._flushPending = false\n this._hwm = Math.max(minLength || 0, 16387)\n this.file = null\n this.destroyed = false\n this.minLength = minLength || 0\n this.maxLength = maxLength || 0\n this.maxWrite = maxWrite || MAX_WRITE\n this._periodicFlush = periodicFlush || 0\n this._periodicFlushTimer = undefined\n this.sync = sync || false\n this.writable = true\n this._fsync = fsync || false\n this.append = append || false\n this.mode = mode\n this.retryEAGAIN = retryEAGAIN || (() => true)\n this.mkdir = mkdir || false\n\n let fsWriteSync\n let fsWrite\n if (contentMode === kContentModeBuffer) {\n this._writingBuf = kEmptyBuffer\n this.write = writeBuffer\n this.flush = flushBuffer\n this.flushSync = flushBufferSync\n this._actualWrite = actualWriteBuffer\n fsWriteSync = () => fs.writeSync(this.fd, this._writingBuf)\n fsWrite = () => fs.write(this.fd, this._writingBuf, this.release)\n } else if (contentMode === undefined || contentMode === kContentModeUtf8) {\n this._writingBuf = ''\n this.write = write\n this.flush = flush\n this.flushSync = flushSync\n this._actualWrite = actualWrite\n fsWriteSync = () => fs.writeSync(this.fd, this._writingBuf, 'utf8')\n fsWrite = () => fs.write(this.fd, this._writingBuf, 'utf8', this.release)\n } else {\n throw new Error(`SonicBoom supports \"${kContentModeUtf8}\" and \"${kContentModeBuffer}\", but passed ${contentMode}`)\n }\n\n if (typeof fd === 'number') {\n this.fd = fd\n process.nextTick(() => this.emit('ready'))\n } else if (typeof fd === 'string') {\n openFile(fd, this)\n } else {\n throw new Error('So