UNPKG

elysia-react-router

Version:

Use React Router v7 or Remix with Elysia with HMR support!

2,115 lines (2,068 loc) 338 kB
import { g as getDefaultExportFromCjs } from './index-DOjPtrHA.js'; import require$$0$2 from 'tty'; import require$$1 from 'util'; import require$$3 from 'fs'; import require$$4 from 'net'; import require$$1$1 from 'events'; import require$$0$3 from 'url'; import require$$3$1 from 'http'; import { Elysia } from 'elysia'; import require$$1$2 from 'path'; import require$$5 from 'querystring'; import require$$0$4 from 'buffer'; import require$$1$3 from 'stream'; import 'fs/promises'; var src = {exports: {}}; var browser = {exports: {}}; var debug = {exports: {}}; var ms; var hasRequiredMs; function requireMs () { if (hasRequiredMs) return ms; hasRequiredMs = 1; var s = 1e3; var m = s * 60; var h = m * 60; var d = h * 24; var y = d * 365.25; ms = function(val, options) { options = options || {}; var type = typeof val; if (type === "string" && val.length > 0) { return parse(val); } else if (type === "number" && isNaN(val) === false) { return options.long ? fmtLong(val) : fmtShort(val); } throw new Error( "val is not a non-empty string or a valid number. val=" + JSON.stringify(val) ); }; function parse(str) { str = String(str); if (str.length > 100) { return; } var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec( str ); if (!match) { return; } var n = parseFloat(match[1]); var type = (match[2] || "ms").toLowerCase(); switch (type) { case "years": case "year": case "yrs": case "yr": case "y": return n * y; case "days": case "day": case "d": return n * d; case "hours": case "hour": case "hrs": case "hr": case "h": return n * h; case "minutes": case "minute": case "mins": case "min": case "m": return n * m; case "seconds": case "second": case "secs": case "sec": case "s": return n * s; case "milliseconds": case "millisecond": case "msecs": case "msec": case "ms": return n; default: return void 0; } } function fmtShort(ms) { if (ms >= d) { return Math.round(ms / d) + "d"; } if (ms >= h) { return Math.round(ms / h) + "h"; } if (ms >= m) { return Math.round(ms / m) + "m"; } if (ms >= s) { return Math.round(ms / s) + "s"; } return ms + "ms"; } function fmtLong(ms) { return plural(ms, d, "day") || plural(ms, h, "hour") || plural(ms, m, "minute") || plural(ms, s, "second") || ms + " ms"; } function plural(ms, n, name) { if (ms < n) { return; } if (ms < n * 1.5) { return Math.floor(ms / n) + " " + name; } return Math.ceil(ms / n) + " " + name + "s"; } return ms; } var hasRequiredDebug; function requireDebug () { if (hasRequiredDebug) return debug.exports; hasRequiredDebug = 1; (function (module, exports) { exports = module.exports = createDebug.debug = createDebug["default"] = createDebug; exports.coerce = coerce; exports.disable = disable; exports.enable = enable; exports.enabled = enabled; exports.humanize = requireMs(); exports.names = []; exports.skips = []; exports.formatters = {}; var prevTime; function selectColor(namespace) { var hash = 0, i; for (i in namespace) { hash = (hash << 5) - hash + namespace.charCodeAt(i); hash |= 0; } return exports.colors[Math.abs(hash) % exports.colors.length]; } function createDebug(namespace) { function debug() { if (!debug.enabled) return; var self = debug; var curr = +/* @__PURE__ */ new Date(); var ms = curr - (prevTime || curr); self.diff = ms; self.prev = prevTime; self.curr = curr; prevTime = curr; var args = new Array(arguments.length); for (var i = 0; i < args.length; i++) { args[i] = arguments[i]; } args[0] = exports.coerce(args[0]); if ("string" !== typeof args[0]) { args.unshift("%O"); } var index = 0; args[0] = args[0].replace(/%([a-zA-Z%])/g, function(match, format) { if (match === "%%") return match; index++; var formatter = exports.formatters[format]; if ("function" === typeof formatter) { var val = args[index]; match = formatter.call(self, val); args.splice(index, 1); index--; } return match; }); exports.formatArgs.call(self, args); var logFn = debug.log || exports.log || console.log.bind(console); logFn.apply(self, args); } debug.namespace = namespace; debug.enabled = exports.enabled(namespace); debug.useColors = exports.useColors(); debug.color = selectColor(namespace); if ("function" === typeof exports.init) { exports.init(debug); } return debug; } function enable(namespaces) { exports.save(namespaces); exports.names = []; exports.skips = []; var split = (typeof namespaces === "string" ? namespaces : "").split(/[\s,]+/); var len = split.length; for (var i = 0; i < len; i++) { if (!split[i]) continue; namespaces = split[i].replace(/\*/g, ".*?"); if (namespaces[0] === "-") { exports.skips.push(new RegExp("^" + namespaces.substr(1) + "$")); } else { exports.names.push(new RegExp("^" + namespaces + "$")); } } } function disable() { exports.enable(""); } function enabled(name) { var i, len; for (i = 0, len = exports.skips.length; i < len; i++) { if (exports.skips[i].test(name)) { return false; } } for (i = 0, len = exports.names.length; i < len; i++) { if (exports.names[i].test(name)) { return true; } } return false; } function coerce(val) { if (val instanceof Error) return val.stack || val.message; return val; } } (debug, debug.exports)); return debug.exports; } var hasRequiredBrowser; function requireBrowser () { if (hasRequiredBrowser) return browser.exports; hasRequiredBrowser = 1; (function (module, exports) { exports = module.exports = requireDebug(); exports.log = log; exports.formatArgs = formatArgs; exports.save = save; exports.load = load; exports.useColors = useColors; exports.storage = "undefined" != typeof chrome && "undefined" != typeof chrome.storage ? chrome.storage.local : localstorage(); exports.colors = [ "lightseagreen", "forestgreen", "goldenrod", "dodgerblue", "darkorchid", "crimson" ]; function useColors() { if (typeof window !== "undefined" && window.process && window.process.type === "renderer") { return true; } return typeof document !== "undefined" && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || // is firebug? http://stackoverflow.com/a/398120/376773 typeof window !== "undefined" && window.console && (window.console.firebug || window.console.exception && window.console.table) || // is firefox >= v31? // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31 || // double check webkit in userAgent just in case we are in a worker typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/); } exports.formatters.j = function(v) { try { return JSON.stringify(v); } catch (err) { return "[UnexpectedJSONParseError]: " + err.message; } }; function formatArgs(args) { var useColors2 = this.useColors; args[0] = (useColors2 ? "%c" : "") + this.namespace + (useColors2 ? " %c" : " ") + args[0] + (useColors2 ? "%c " : " ") + "+" + exports.humanize(this.diff); if (!useColors2) return; var c = "color: " + this.color; args.splice(1, 0, c, "color: inherit"); var index = 0; var lastC = 0; args[0].replace(/%[a-zA-Z%]/g, function(match) { if ("%%" === match) return; index++; if ("%c" === match) { lastC = index; } }); args.splice(lastC, 0, c); } function log() { return "object" === typeof console && console.log && Function.prototype.apply.call(console.log, console, arguments); } function save(namespaces) { try { if (null == namespaces) { exports.storage.removeItem("debug"); } else { exports.storage.debug = namespaces; } } catch (e) { } } function load() { var r; try { r = exports.storage.debug; } catch (e) { } if (!r && typeof process !== "undefined" && "env" in process) { r = process.env.DEBUG; } return r; } exports.enable(load()); function localstorage() { try { return window.localStorage; } catch (e) { } } } (browser, browser.exports)); return browser.exports; } var node = {exports: {}}; var hasRequiredNode; function requireNode () { if (hasRequiredNode) return node.exports; hasRequiredNode = 1; (function (module, exports) { var tty = require$$0$2; var util = require$$1; exports = module.exports = requireDebug(); exports.init = init; exports.log = log; exports.formatArgs = formatArgs; exports.save = save; exports.load = load; exports.useColors = useColors; exports.colors = [6, 2, 3, 4, 5, 1]; exports.inspectOpts = Object.keys(process.env).filter(function(key) { return /^debug_/i.test(key); }).reduce(function(obj, key) { var prop = key.substring(6).toLowerCase().replace(/_([a-z])/g, function(_, k) { return k.toUpperCase(); }); var val = process.env[key]; if (/^(yes|on|true|enabled)$/i.test(val)) val = true; else if (/^(no|off|false|disabled)$/i.test(val)) val = false; else if (val === "null") val = null; else val = Number(val); obj[prop] = val; return obj; }, {}); var fd = parseInt(process.env.DEBUG_FD, 10) || 2; if (1 !== fd && 2 !== fd) { util.deprecate(function() { }, "except for stderr(2) and stdout(1), any other usage of DEBUG_FD is deprecated. Override debug.log if you want to use a different log function (https://git.io/debug_fd)")(); } var stream = 1 === fd ? process.stdout : 2 === fd ? process.stderr : createWritableStdioStream(fd); function useColors() { return "colors" in exports.inspectOpts ? Boolean(exports.inspectOpts.colors) : tty.isatty(fd); } exports.formatters.o = function(v) { this.inspectOpts.colors = this.useColors; return util.inspect(v, this.inspectOpts).split("\n").map(function(str) { return str.trim(); }).join(" "); }; exports.formatters.O = function(v) { this.inspectOpts.colors = this.useColors; return util.inspect(v, this.inspectOpts); }; function formatArgs(args) { var name = this.namespace; var useColors2 = this.useColors; if (useColors2) { var c = this.color; var prefix = " \x1B[3" + c + ";1m" + name + " \x1B[0m"; args[0] = prefix + args[0].split("\n").join("\n" + prefix); args.push("\x1B[3" + c + "m+" + exports.humanize(this.diff) + "\x1B[0m"); } else { args[0] = (/* @__PURE__ */ new Date()).toUTCString() + " " + name + " " + args[0]; } } function log() { return stream.write(util.format.apply(util, arguments) + "\n"); } function save(namespaces) { if (null == namespaces) { delete process.env.DEBUG; } else { process.env.DEBUG = namespaces; } } function load() { return process.env.DEBUG; } function createWritableStdioStream(fd2) { var stream2; var tty_wrap = process.binding("tty_wrap"); switch (tty_wrap.guessHandleType(fd2)) { case "TTY": stream2 = new tty.WriteStream(fd2); stream2._type = "tty"; if (stream2._handle && stream2._handle.unref) { stream2._handle.unref(); } break; case "FILE": var fs = require$$3; stream2 = new fs.SyncWriteStream(fd2, { autoClose: false }); stream2._type = "fs"; break; case "PIPE": case "TCP": var net = require$$4; stream2 = new net.Socket({ fd: fd2, readable: false, writable: true }); stream2.readable = false; stream2.read = null; stream2._type = "pipe"; if (stream2._handle && stream2._handle.unref) { stream2._handle.unref(); } break; default: throw new Error("Implement me. Unknown stream file type!"); } stream2.fd = fd2; stream2._isStdio = true; return stream2; } function init(debug) { debug.inspectOpts = {}; var keys = Object.keys(exports.inspectOpts); for (var i = 0; i < keys.length; i++) { debug.inspectOpts[keys[i]] = exports.inspectOpts[keys[i]]; } } exports.enable(load()); } (node, node.exports)); return node.exports; } var hasRequiredSrc; function requireSrc () { if (hasRequiredSrc) return src.exports; hasRequiredSrc = 1; if (typeof process !== "undefined" && process.type === "renderer") { src.exports = requireBrowser(); } else { src.exports = requireNode(); } return src.exports; } var encodeurl; var hasRequiredEncodeurl; function requireEncodeurl () { if (hasRequiredEncodeurl) return encodeurl; hasRequiredEncodeurl = 1; /*! * encodeurl * Copyright(c) 2016 Douglas Christopher Wilson * MIT Licensed */ encodeurl = encodeUrl; var ENCODE_CHARS_REGEXP = /(?:[^\x21\x25\x26-\x3B\x3D\x3F-\x5B\x5D\x5F\x61-\x7A\x7E]|%(?:[^0-9A-Fa-f]|[0-9A-Fa-f][^0-9A-Fa-f]|$))+/g; var UNMATCHED_SURROGATE_PAIR_REGEXP = /(^|[^\uD800-\uDBFF])[\uDC00-\uDFFF]|[\uD800-\uDBFF]([^\uDC00-\uDFFF]|$)/g; var UNMATCHED_SURROGATE_PAIR_REPLACE = "$1\uFFFD$2"; function encodeUrl(url) { return String(url).replace(UNMATCHED_SURROGATE_PAIR_REGEXP, UNMATCHED_SURROGATE_PAIR_REPLACE).replace(ENCODE_CHARS_REGEXP, encodeURI); } return encodeurl; } var escapeHtml_1; var hasRequiredEscapeHtml; function requireEscapeHtml () { if (hasRequiredEscapeHtml) return escapeHtml_1; hasRequiredEscapeHtml = 1; /*! * escape-html * Copyright(c) 2012-2013 TJ Holowaychuk * Copyright(c) 2015 Andreas Lubbe * Copyright(c) 2015 Tiancheng "Timothy" Gu * MIT Licensed */ var matchHtmlRegExp = /["'&<>]/; escapeHtml_1 = escapeHtml; function escapeHtml(string) { var str = "" + string; var match = matchHtmlRegExp.exec(str); if (!match) { return str; } var escape; var html = ""; var index = 0; var lastIndex = 0; for (index = match.index; index < str.length; index++) { switch (str.charCodeAt(index)) { case 34: escape = "&quot;"; break; case 38: escape = "&amp;"; break; case 39: escape = "&#39;"; break; case 60: escape = "&lt;"; break; case 62: escape = "&gt;"; break; default: continue; } if (lastIndex !== index) { html += str.substring(lastIndex, index); } lastIndex = index + 1; html += escape; } return lastIndex !== index ? html + str.substring(lastIndex, index) : html; } return escapeHtml_1; } var onFinished = {exports: {}}; var eeFirst; var hasRequiredEeFirst; function requireEeFirst () { if (hasRequiredEeFirst) return eeFirst; hasRequiredEeFirst = 1; /*! * ee-first * Copyright(c) 2014 Jonathan Ong * MIT Licensed */ eeFirst = first; function first(stuff, done) { if (!Array.isArray(stuff)) throw new TypeError("arg must be an array of [ee, events...] arrays"); var cleanups = []; for (var i = 0; i < stuff.length; i++) { var arr = stuff[i]; if (!Array.isArray(arr) || arr.length < 2) throw new TypeError("each array member must be [ee, events...]"); var ee = arr[0]; for (var j = 1; j < arr.length; j++) { var event = arr[j]; var fn = listener(event, callback); ee.on(event, fn); cleanups.push({ ee, event, fn }); } } function callback() { cleanup(); done.apply(null, arguments); } function cleanup() { var x; for (var i2 = 0; i2 < cleanups.length; i2++) { x = cleanups[i2]; x.ee.removeListener(x.event, x.fn); } } function thunk(fn2) { done = fn2; } thunk.cancel = cleanup; return thunk; } function listener(event, done) { return function onevent(arg1) { var args = new Array(arguments.length); var ee = this; var err = event === "error" ? arg1 : null; for (var i = 0; i < args.length; i++) { args[i] = arguments[i]; } done(err, ee, event, args); }; } return eeFirst; } var hasRequiredOnFinished; function requireOnFinished () { if (hasRequiredOnFinished) return onFinished.exports; hasRequiredOnFinished = 1; /*! * on-finished * Copyright(c) 2013 Jonathan Ong * Copyright(c) 2014 Douglas Christopher Wilson * MIT Licensed */ onFinished.exports = onFinished$1; onFinished.exports.isFinished = isFinished; var first = requireEeFirst(); var defer = typeof setImmediate === "function" ? setImmediate : function(fn) { process.nextTick(fn.bind.apply(fn, arguments)); }; function onFinished$1(msg, listener) { if (isFinished(msg) !== false) { defer(listener, null, msg); return msg; } attachListener(msg, listener); return msg; } function isFinished(msg) { var socket = msg.socket; if (typeof msg.finished === "boolean") { return Boolean(msg.finished || socket && !socket.writable); } if (typeof msg.complete === "boolean") { return Boolean(msg.upgrade || !socket || !socket.readable || msg.complete && !msg.readable); } return void 0; } function attachFinishedListener(msg, callback) { var eeMsg; var eeSocket; var finished = false; function onFinish(error) { eeMsg.cancel(); eeSocket.cancel(); finished = true; callback(error); } eeMsg = eeSocket = first([[msg, "end", "finish"]], onFinish); function onSocket(socket) { msg.removeListener("socket", onSocket); if (finished) return; if (eeMsg !== eeSocket) return; eeSocket = first([[socket, "error", "close"]], onFinish); } if (msg.socket) { onSocket(msg.socket); return; } msg.on("socket", onSocket); if (msg.socket === void 0) { patchAssignSocket(msg, onSocket); } } function attachListener(msg, listener) { var attached = msg.__onFinished; if (!attached || !attached.queue) { attached = msg.__onFinished = createListener(msg); attachFinishedListener(msg, attached); } attached.queue.push(listener); } function createListener(msg) { function listener(err) { if (msg.__onFinished === listener) msg.__onFinished = null; if (!listener.queue) return; var queue = listener.queue; listener.queue = null; for (var i = 0; i < queue.length; i++) { queue[i](err, msg); } } listener.queue = []; return listener; } function patchAssignSocket(res, callback) { var assignSocket = res.assignSocket; if (typeof assignSocket !== "function") return; res.assignSocket = function _assignSocket(socket) { assignSocket.call(this, socket); callback(socket); }; } return onFinished.exports; } var parseurl = {exports: {}}; var hasRequiredParseurl; function requireParseurl () { if (hasRequiredParseurl) return parseurl.exports; hasRequiredParseurl = 1; /*! * parseurl * Copyright(c) 2014 Jonathan Ong * Copyright(c) 2014-2017 Douglas Christopher Wilson * MIT Licensed */ var url = require$$0$3; var parse = url.parse; var Url = url.Url; parseurl.exports = parseurl$1; parseurl.exports.original = originalurl; function parseurl$1(req) { var url2 = req.url; if (url2 === void 0) { return void 0; } var parsed = req._parsedUrl; if (fresh(url2, parsed)) { return parsed; } parsed = fastparse(url2); parsed._raw = url2; return req._parsedUrl = parsed; } function originalurl(req) { var url2 = req.originalUrl; if (typeof url2 !== "string") { return parseurl$1(req); } var parsed = req._parsedOriginalUrl; if (fresh(url2, parsed)) { return parsed; } parsed = fastparse(url2); parsed._raw = url2; return req._parsedOriginalUrl = parsed; } function fastparse(str) { if (typeof str !== "string" || str.charCodeAt(0) !== 47) { return parse(str); } var pathname = str; var query = null; var search = null; for (var i = 1; i < str.length; i++) { switch (str.charCodeAt(i)) { case 63: if (search === null) { pathname = str.substring(0, i); query = str.substring(i + 1); search = str.substring(i); } break; case 9: /* \t */ case 10: /* \n */ case 12: /* \f */ case 13: /* \r */ case 32: /* */ case 35: /* # */ case 160: case 65279: return parse(str); } } var url2 = Url !== void 0 ? new Url() : {}; url2.path = str; url2.href = str; url2.pathname = pathname; if (search !== null) { url2.query = query; url2.search = search; } return url2; } function fresh(url2, parsedUrl) { return typeof parsedUrl === "object" && parsedUrl !== null && (Url === void 0 || parsedUrl instanceof Url) && parsedUrl._raw === url2; } return parseurl.exports; } var require$$0$1 = { "100": "Continue", "101": "Switching Protocols", "102": "Processing", "103": "Early Hints", "200": "OK", "201": "Created", "202": "Accepted", "203": "Non-Authoritative Information", "204": "No Content", "205": "Reset Content", "206": "Partial Content", "207": "Multi-Status", "208": "Already Reported", "226": "IM Used", "300": "Multiple Choices", "301": "Moved Permanently", "302": "Found", "303": "See Other", "304": "Not Modified", "305": "Use Proxy", "306": "(Unused)", "307": "Temporary Redirect", "308": "Permanent Redirect", "400": "Bad Request", "401": "Unauthorized", "402": "Payment Required", "403": "Forbidden", "404": "Not Found", "405": "Method Not Allowed", "406": "Not Acceptable", "407": "Proxy Authentication Required", "408": "Request Timeout", "409": "Conflict", "410": "Gone", "411": "Length Required", "412": "Precondition Failed", "413": "Payload Too Large", "414": "URI Too Long", "415": "Unsupported Media Type", "416": "Range Not Satisfiable", "417": "Expectation Failed", "418": "I'm a teapot", "421": "Misdirected Request", "422": "Unprocessable Entity", "423": "Locked", "424": "Failed Dependency", "425": "Unordered Collection", "426": "Upgrade Required", "428": "Precondition Required", "429": "Too Many Requests", "431": "Request Header Fields Too Large", "451": "Unavailable For Legal Reasons", "500": "Internal Server Error", "501": "Not Implemented", "502": "Bad Gateway", "503": "Service Unavailable", "504": "Gateway Timeout", "505": "HTTP Version Not Supported", "506": "Variant Also Negotiates", "507": "Insufficient Storage", "508": "Loop Detected", "509": "Bandwidth Limit Exceeded", "510": "Not Extended", "511": "Network Authentication Required" }; var statuses; var hasRequiredStatuses; function requireStatuses () { if (hasRequiredStatuses) return statuses; hasRequiredStatuses = 1; /*! * statuses * Copyright(c) 2014 Jonathan Ong * Copyright(c) 2016 Douglas Christopher Wilson * MIT Licensed */ var codes = require$$0$1; statuses = status; status.STATUS_CODES = codes; status.codes = populateStatusesMap(status, codes); status.redirect = { 300: true, 301: true, 302: true, 303: true, 305: true, 307: true, 308: true }; status.empty = { 204: true, 205: true, 304: true }; status.retry = { 502: true, 503: true, 504: true }; function populateStatusesMap(statuses, codes2) { var arr = []; Object.keys(codes2).forEach(function forEachCode(code) { var message = codes2[code]; var status2 = Number(code); statuses[status2] = message; statuses[message] = status2; statuses[message.toLowerCase()] = status2; arr.push(status2); }); return arr; } function status(code) { if (typeof code === "number") { if (!status[code]) throw new Error("invalid status code: " + code); return code; } if (typeof code !== "string") { throw new TypeError("code must be a number or string"); } var n = parseInt(code, 10); if (!isNaN(n)) { if (!status[n]) throw new Error("invalid status code: " + n); return n; } n = status[code.toLowerCase()]; if (!n) throw new Error('invalid status message: "' + code + '"'); return n; } return statuses; } var unpipe_1; var hasRequiredUnpipe; function requireUnpipe () { if (hasRequiredUnpipe) return unpipe_1; hasRequiredUnpipe = 1; /*! * unpipe * Copyright(c) 2015 Douglas Christopher Wilson * MIT Licensed */ unpipe_1 = unpipe; function hasPipeDataListeners(stream) { var listeners = stream.listeners("data"); for (var i = 0; i < listeners.length; i++) { if (listeners[i].name === "ondata") { return true; } } return false; } function unpipe(stream) { if (!stream) { throw new TypeError("argument stream is required"); } if (typeof stream.unpipe === "function") { stream.unpipe(); return; } if (!hasPipeDataListeners(stream)) { return; } var listener; var listeners = stream.listeners("close"); for (var i = 0; i < listeners.length; i++) { listener = listeners[i]; if (listener.name !== "cleanup" && listener.name !== "onclose") { continue; } listener.call(stream); } } return unpipe_1; } var finalhandler_1; var hasRequiredFinalhandler; function requireFinalhandler () { if (hasRequiredFinalhandler) return finalhandler_1; hasRequiredFinalhandler = 1; /*! * finalhandler * Copyright(c) 2014-2017 Douglas Christopher Wilson * MIT Licensed */ var debug = requireSrc()("finalhandler"); var encodeUrl = requireEncodeurl(); var escapeHtml = requireEscapeHtml(); var onFinished = requireOnFinished(); var parseUrl = requireParseurl(); var statuses = requireStatuses(); var unpipe = requireUnpipe(); var DOUBLE_SPACE_REGEXP = /\x20{2}/g; var NEWLINE_REGEXP = /\n/g; var defer = typeof setImmediate === "function" ? setImmediate : function(fn) { process.nextTick(fn.bind.apply(fn, arguments)); }; var isFinished = onFinished.isFinished; function createHtmlDocument(message) { var body = escapeHtml(message).replace(NEWLINE_REGEXP, "<br>").replace(DOUBLE_SPACE_REGEXP, " &nbsp;"); return '<!DOCTYPE html>\n<html lang="en">\n<head>\n<meta charset="utf-8">\n<title>Error</title>\n</head>\n<body>\n<pre>' + body + "</pre>\n</body>\n</html>\n"; } finalhandler_1 = finalhandler; function finalhandler(req, res, options) { var opts = options || {}; var env = opts.env || process.env.NODE_ENV || "development"; var onerror = opts.onerror; return function(err) { var headers; var msg; var status; if (!err && headersSent(res)) { debug("cannot 404 after headers sent"); return; } if (err) { status = getErrorStatusCode(err); if (status === void 0) { status = getResponseStatusCode(res); } else { headers = getErrorHeaders(err); } msg = getErrorMessage(err, status, env); } else { status = 404; msg = "Cannot " + req.method + " " + encodeUrl(getResourceName(req)); } debug("default %s", status); if (err && onerror) { defer(onerror, err, req, res); } if (headersSent(res)) { debug("cannot %d after headers sent", status); req.socket.destroy(); return; } send(req, res, status, headers, msg); }; } function getErrorHeaders(err) { if (!err.headers || typeof err.headers !== "object") { return void 0; } var headers = /* @__PURE__ */ Object.create(null); var keys = Object.keys(err.headers); for (var i = 0; i < keys.length; i++) { var key = keys[i]; headers[key] = err.headers[key]; } return headers; } function getErrorMessage(err, status, env) { var msg; if (env !== "production") { msg = err.stack; if (!msg && typeof err.toString === "function") { msg = err.toString(); } } return msg || statuses[status]; } function getErrorStatusCode(err) { if (typeof err.status === "number" && err.status >= 400 && err.status < 600) { return err.status; } if (typeof err.statusCode === "number" && err.statusCode >= 400 && err.statusCode < 600) { return err.statusCode; } return void 0; } function getResourceName(req) { try { return parseUrl.original(req).pathname; } catch (e) { return "resource"; } } function getResponseStatusCode(res) { var status = res.statusCode; if (typeof status !== "number" || status < 400 || status > 599) { status = 500; } return status; } function headersSent(res) { return typeof res.headersSent !== "boolean" ? Boolean(res._header) : res.headersSent; } function send(req, res, status, headers, message) { function write() { var body = createHtmlDocument(message); res.statusCode = status; res.statusMessage = statuses[status]; setHeaders(res, headers); res.setHeader("Content-Security-Policy", "default-src 'none'"); res.setHeader("X-Content-Type-Options", "nosniff"); res.setHeader("Content-Type", "text/html; charset=utf-8"); res.setHeader("Content-Length", Buffer.byteLength(body, "utf8")); if (req.method === "HEAD") { res.end(); return; } res.end(body, "utf8"); } if (isFinished(req)) { write(); return; } unpipe(req); onFinished(req, write); req.resume(); } function setHeaders(res, headers) { if (!headers) { return; } var keys = Object.keys(headers); for (var i = 0; i < keys.length; i++) { var key = keys[i]; res.setHeader(key, headers[key]); } } return finalhandler_1; } var utilsMerge = {exports: {}}; var hasRequiredUtilsMerge; function requireUtilsMerge () { if (hasRequiredUtilsMerge) return utilsMerge.exports; hasRequiredUtilsMerge = 1; (function (module, exports) { module.exports = function(a, b) { if (a && b) { for (var key in b) { a[key] = b[key]; } } return a; }; } (utilsMerge)); return utilsMerge.exports; } var connect$1; var hasRequiredConnect; function requireConnect () { if (hasRequiredConnect) return connect$1; hasRequiredConnect = 1; /*! * connect * Copyright(c) 2010 Sencha Inc. * Copyright(c) 2011 TJ Holowaychuk * Copyright(c) 2015 Douglas Christopher Wilson * MIT Licensed */ var debug = requireSrc()("connect:dispatcher"); var EventEmitter = require$$1$1.EventEmitter; var finalhandler = requireFinalhandler(); var http = require$$3$1; var merge = requireUtilsMerge(); var parseUrl = requireParseurl(); connect$1 = createServer; var env = process.env.NODE_ENV || "development"; var proto = {}; var defer = typeof setImmediate === "function" ? setImmediate : function(fn) { process.nextTick(fn.bind.apply(fn, arguments)); }; function createServer() { function app(req, res, next) { app.handle(req, res, next); } merge(app, proto); merge(app, EventEmitter.prototype); app.route = "/"; app.stack = []; return app; } proto.use = function use(route, fn) { var handle2 = fn; var path = route; if (typeof route !== "string") { handle2 = route; path = "/"; } if (typeof handle2.handle === "function") { var server = handle2; server.route = path; handle2 = function(req, res, next) { server.handle(req, res, next); }; } if (handle2 instanceof http.Server) { handle2 = handle2.listeners("request")[0]; } if (path[path.length - 1] === "/") { path = path.slice(0, -1); } debug("use %s %s", path || "/", handle2.name || "anonymous"); this.stack.push({ route: path, handle: handle2 }); return this; }; proto.handle = function handle(req, res, out) { var index = 0; var protohost = getProtohost(req.url) || ""; var removed = ""; var slashAdded = false; var stack = this.stack; var done = out || finalhandler(req, res, { env, onerror: logerror }); req.originalUrl = req.originalUrl || req.url; function next(err) { if (slashAdded) { req.url = req.url.substr(1); slashAdded = false; } if (removed.length !== 0) { req.url = protohost + removed + req.url.substr(protohost.length); removed = ""; } var layer = stack[index++]; if (!layer) { defer(done, err); return; } var path = parseUrl(req).pathname || "/"; var route = layer.route; if (path.toLowerCase().substr(0, route.length) !== route.toLowerCase()) { return next(err); } var c = path.length > route.length && path[route.length]; if (c && c !== "/" && c !== ".") { return next(err); } if (route.length !== 0 && route !== "/") { removed = route; req.url = protohost + req.url.substr(protohost.length + removed.length); if (!protohost && req.url[0] !== "/") { req.url = "/" + req.url; slashAdded = true; } } call(layer.handle, route, err, req, res, next); } next(); }; proto.listen = function listen() { var server = http.createServer(this); return server.listen.apply(server, arguments); }; function call(handle2, route, err, req, res, next) { var arity = handle2.length; var error = err; var hasError = Boolean(err); debug("%s %s : %s", handle2.name || "<anonymous>", route, req.originalUrl); try { if (hasError && arity === 4) { handle2(err, req, res, next); return; } else if (!hasError && arity < 4) { handle2(req, res, next); return; } } catch (e) { error = e; } next(error); } function logerror(err) { if (env !== "test") console.error(err.stack || err.toString()); } function getProtohost(url) { if (url.length === 0 || url[0] === "/") { return void 0; } var fqdnIndex = url.indexOf("://"); return fqdnIndex !== -1 && url.lastIndexOf("?", fqdnIndex) === -1 ? url.substr(0, url.indexOf("/", 3 + fqdnIndex)) : void 0; } return connect$1; } var connectExports = requireConnect(); var Connect = /*@__PURE__*/getDefaultExportFromCjs(connectExports); var httpMock = {}; var mockRequest$1 = {}; var typeIs = {exports: {}}; var mediaTyper = {}; var hasRequiredMediaTyper; function requireMediaTyper () { if (hasRequiredMediaTyper) return mediaTyper; hasRequiredMediaTyper = 1; /*! * media-typer * Copyright(c) 2014 Douglas Christopher Wilson * MIT Licensed */ var paramRegExp = /; *([!#$%&'\*\+\-\.0-9A-Z\^_`a-z\|~]+) *= *("(?:[ !\u0023-\u005b\u005d-\u007e\u0080-\u00ff]|\\[\u0020-\u007e])*"|[!#$%&'\*\+\-\.0-9A-Z\^_`a-z\|~]+) */g; var textRegExp = /^[\u0020-\u007e\u0080-\u00ff]+$/; var tokenRegExp = /^[!#$%&'\*\+\-\.0-9A-Z\^_`a-z\|~]+$/; var qescRegExp = /\\([\u0000-\u007f])/g; var quoteRegExp = /([\\"])/g; var subtypeNameRegExp = /^[A-Za-z0-9][A-Za-z0-9!#$&^_.-]{0,126}$/; var typeNameRegExp = /^[A-Za-z0-9][A-Za-z0-9!#$&^_-]{0,126}$/; var typeRegExp = /^ *([A-Za-z0-9][A-Za-z0-9!#$&^_-]{0,126})\/([A-Za-z0-9][A-Za-z0-9!#$&^_.+-]{0,126}) *$/; mediaTyper.format = format; mediaTyper.parse = parse; function format(obj) { if (!obj || typeof obj !== "object") { throw new TypeError("argument obj is required"); } var parameters = obj.parameters; var subtype = obj.subtype; var suffix = obj.suffix; var type = obj.type; if (!type || !typeNameRegExp.test(type)) { throw new TypeError("invalid type"); } if (!subtype || !subtypeNameRegExp.test(subtype)) { throw new TypeError("invalid subtype"); } var string = type + "/" + subtype; if (suffix) { if (!typeNameRegExp.test(suffix)) { throw new TypeError("invalid suffix"); } string += "+" + suffix; } if (parameters && typeof parameters === "object") { var param; var params = Object.keys(parameters).sort(); for (var i = 0; i < params.length; i++) { param = params[i]; if (!tokenRegExp.test(param)) { throw new TypeError("invalid parameter name"); } string += "; " + param + "=" + qstring(parameters[param]); } } return string; } function parse(string) { if (!string) { throw new TypeError("argument string is required"); } if (typeof string === "object") { string = getcontenttype(string); } if (typeof string !== "string") { throw new TypeError("argument string is required to be a string"); } var index = string.indexOf(";"); var type = index !== -1 ? string.substr(0, index) : string; var key; var match; var obj = splitType(type); var params = {}; var value; paramRegExp.lastIndex = index; while (match = paramRegExp.exec(string)) { if (match.index !== index) { throw new TypeError("invalid parameter format"); } index += match[0].length; key = match[1].toLowerCase(); value = match[2]; if (value[0] === '"') { value = value.substr(1, value.length - 2).replace(qescRegExp, "$1"); } params[key] = value; } if (index !== -1 && index !== string.length) { throw new TypeError("invalid parameter format"); } obj.parameters = params; return obj; } function getcontenttype(obj) { if (typeof obj.getHeader === "function") { return obj.getHeader("content-type"); } if (typeof obj.headers === "object") { return obj.headers && obj.headers["content-type"]; } } function qstring(val) { var str = String(val); if (tokenRegExp.test(str)) { return str; } if (str.length > 0 && !textRegExp.test(str)) { throw new TypeError("invalid parameter value"); } return '"' + str.replace(quoteRegExp, "\\$1") + '"'; } function splitType(string) { var match = typeRegExp.exec(string.toLowerCase()); if (!match) { throw new TypeError("invalid media type"); } var type = match[1]; var subtype = match[2]; var suffix; var index = subtype.lastIndexOf("+"); if (index !== -1) { suffix = subtype.substr(index + 1); subtype = subtype.substr(0, index); } var obj = { type, subtype, suffix }; return obj; } return mediaTyper; } var mimeTypes = {}; var require$$0 = { "application/1d-interleaved-parityfec": { source: "iana" }, "application/3gpdash-qoe-report+xml": { source: "iana", charset: "UTF-8", compressible: true }, "application/3gpp-ims+xml": { source: "iana", compressible: true }, "application/3gpphal+json": { source: "iana", compressible: true }, "application/3gpphalforms+json": { source: "iana", compressible: true }, "application/a2l": { source: "iana" }, "application/ace+cbor": { source: "iana" }, "application/activemessage": { source: "iana" }, "application/activity+json": { source: "iana", compressible: true }, "application/alto-costmap+json": { source: "iana", compressible: true }, "application/alto-costmapfilter+json": { source: "iana", compressible: true }, "application/alto-directory+json": { source: "iana", compressible: true }, "application/alto-endpointcost+json": { source: "iana", compressible: true }, "application/alto-endpointcostparams+json": { source: "iana", compressible: true }, "application/alto-endpointprop+json": { source: "iana", compressible: true }, "application/alto-endpointpropparams+json": { source: "iana", compressible: true }, "application/alto-error+json": { source: "iana", compressible: true }, "application/alto-networkmap+json": { source: "iana", compressible: true }, "application/alto-networkmapfilter+json": { source: "iana", compressible: true }, "application/alto-updatestreamcontrol+json": { source: "iana", compressible: true }, "application/alto-updatestreamparams+json": { source: "iana", compressible: true }, "application/aml": { source: "iana" }, "application/andrew-inset": { source: "iana", extensions: [ "ez" ] }, "application/applefile": { source: "iana" }, "application/applixware": { source: "apache", extensions: [ "aw" ] }, "application/at+jwt": { source: "iana" }, "application/atf": { source: "iana" }, "application/atfx": { source: "iana" }, "application/atom+xml": { source: "iana", compressible: true, extensions: [ "atom" ] }, "application/atomcat+xml": { source: "iana", compressible: true, extensions: [ "atomcat" ] }, "application/atomdeleted+xml": { source: "iana", compressible: true, extensions: [ "atomdeleted" ] }, "application/atomicmail": { source: "iana" }, "application/atomsvc+xml": { source: "iana", compressible: true, extensions: [ "atomsvc" ] }, "application/atsc-dwd+xml": { source: "iana", compressible: true, extensions: [ "dwd" ] }, "application/atsc-dynamic-event-message": { source: "iana" }, "application/atsc-held+xml": { source: "iana", compressible: true, extensions: [ "held" ] }, "application/atsc-rdt+json": { source: "iana", compressible: true }, "application/atsc-rsat+xml": { source: "iana", compressible: true, extensions: [ "rsat" ] }, "application/atxml": { source: "iana" }, "application/auth-policy+xml": { source: "iana", compressible: true }, "application/bacnet-xdd+zip": { source: "iana", compressible: false }, "application/batch-smtp": { source: "iana" }, "application/bdoc": { compressible: false, extensions: [ "bdoc" ] }, "application/beep+xml": { source: "iana", charset: "UTF-8", compressible: true }, "application/calendar+json": { source: "iana", compressible: true }, "application/calendar+xml": { source: "iana", compressible: true, extensions: [ "xcs" ] }, "application/call-completion": { source: "iana" }, "application/cals-1840": { source: "iana" }, "application/captive+json": { source: "iana", compressible: true }, "application/cbor": { source: "iana" }, "application/cbor-seq": { source: "iana" }, "application/cccex": { source: "iana" }, "application/ccmp+xml": { source: "iana", compressible: true }, "application/ccxml+xml": { source: "iana", compressible: true, extensions: [ "ccxml" ] }, "application/cdfx+xml": { source: "iana", compressible: true, extensions: [ "cdfx" ] }, "application/cdmi-capability": { source: "iana", extensions: [ "cdmia" ] }, "application/cdmi-container": { source: "iana", extensions: [ "cdmic" ] }, "application/cdmi-domain": { source: "iana", extensions: [ "cdmid" ] }, "application/cdmi-object": { source: "iana", extensions: [ "cdmio" ] }, "application/cdmi-queue": { source: "iana", extensions: [ "cdmiq" ] }, "application/cdni": { source: "iana" }, "application/cea": { source: "iana" }, "application/cea-2018+xml": { source: "iana", compressible: true }, "application/cellml+xml": { source: "iana", compressible: true }, "application/cfw": { source: "iana" }, "application/city+json": { source: "iana", compressible: true }, "application/clr": { source: "iana" }, "application/clue+xml": { source: "iana", compressible: true }, "application/clue_info+xml": { source: "iana", compressible: true }, "application/cms": { source: "iana" }, "application/cnrp+xml": { source: "iana", compressible: true }, "application/coap-group+json": { source: "iana", compressible: true }, "application/coap-payload": { source: "iana" }, "application/commonground": { source: "iana" }, "application/conference-info+xml": { source: "iana", compressible: true }, "application/cose": { source: "iana" }, "application/cose-key": { source: "iana" }, "application/cose-key-set": { source: "iana" }, "application/cpl+xml": { source: "iana", compressible: true, extensions: [ "cpl" ] }, "application/csrattrs": { source: "iana" }, "application/csta+xml": { source: "iana", compressible: true }, "application/cstadata+xml": { source: "iana", compressible: true }, "application/csvm+json": { source: "iana", compressible: true }, "application/cu-seeme": { source: "apache", extensions: [ "cu" ] }, "application/cwt": { source: "iana" }, "application/cybercash": { source: "iana" }, "application/dart": { compressible: true }, "application/dash+xml": { source: "iana", compressible: true, extensions: [ "mpd" ] }, "application/dash-patch+xml": { source: "iana", compressible: true, extensions: [ "mpp" ] }, "application/dashdelta": { source: "iana" }, "application/davmount+xml": { source: "iana", compressible: true, extensions: [ "davmount" ] }, "application/dca-rft": { source: "iana" }, "application/dcd": { source: "iana" }, "application/dec-dx": { source: "iana" }, "application/dialog-info+xml": { source: "iana", compressible: true }, "application/dicom": { source: "iana" }, "application/dicom+json": { source: "iana", compressible: true }, "application/dicom+xml": { source: "iana", compressible: true }, "application/dii": { source: "iana" }, "application/dit": { source: "iana" }, "application/dns": { source: "iana" }, "application/dns+json": { source: "iana", compressible: true }, "application/dns-message": { source: "iana" }, "application/docbook+xml": { source: "apache", compressible: true, extensions: [ "dbk" ] }, "application/dots+cbor": { source: "iana" }, "application/dskpp+xml": { source: "iana", compressible: true }, "application/dssc+der": { source: "iana", extensions: [ "dssc" ] }, "application/dssc+xml": { source: "iana", compressible: true, extensions: [ "xdssc" ] }, "application/dvcs": { source: "iana" }, "application/ecmascript": { source: "iana", compressible: true, extensions: [ "es", "ecma" ] }, "application/edi-consent": { source: "iana" }, "application/edi-x12": { source: "iana", compressible: false }, "application/edifact": { source: "iana", compressible: false }, "application/efi": { source: "iana" }, "application/elm+json": { source: "iana", charset: "UTF-8", compressible: true }, "application/elm+xml": { source: "iana", compressible: true }, "application/emergencycalldata.cap+xml": { source: "iana", charset: "UTF-8", compressible: true }, "application/emergencycalldata.comment+xml": { source: "iana", compressible: true }, "application/emergencycalldata.control+xml": { source: "iana", compressible: true }, "application/emergencycalldata.deviceinfo+xml": { source: "iana", compressible: true }, "application/emergencycalldata.ecall.msd": { source: "iana" }, "application/emergencycalldata.providerinfo+xml": { source: "iana", compressible: true }, "application/emergencycalldata.serviceinfo+xml": { source: "iana", compressible: true }, "application/emergencycalldata.subscriberinfo+xml": { source: "iana", compressible: true }, "application/emergencycalldata.veds+xml": { source: "iana", compressible: true }, "application/emma+xml": { source: "iana", compressible: true, extensions: [ "emma" ] }, "application/emotionml+xml": { source: "iana", compressible: true, extensions: [ "emotionml" ] }, "application/encaprtp": { source: "iana" }, "application/epp+xml": { source: "iana", compressible: true }, "application/epub+zip": { source: "iana", compressible: false, extensions: [ "epub" ] }, "application/eshop": { source: "iana" }, "application/exi": { source: "iana", extensions: [ "exi" ] }, "application/expect-ct-report+json": { source: "iana", compressible: true }, "application/express": { source: "iana", extensions: [ "exp" ] }, "application/fastinfoset": { source: "iana" }, "application/fastsoap": { source: "iana" }, "application/fdt+xml": { source: "iana", compressible: true, extensions: [ "fdt" ] }, "application/fhir+json": { source: "iana", charset: "UTF-8", compressible: true }, "application/fhir+xml": { source: "iana", charset: "UTF-8", compressible: true }, "application/fido.trusted-apps+json": { compressible: true }, "application/fits": { source: "iana" }, "application/flexfec": { source: "iana" }, "application/font-sfnt": { source: "iana" }, "application/font-tdpfr": { source: "iana", extensions: [ "pfr" ] }, "application/font-woff": { source: "iana", compressible: false }, "application/framework-attributes+xml": { source: "iana", compressible: true }, "application/geo+json": { source: "iana", compressible: true, extensions: [ "geojson" ] }, "application/geo+json-seq": { source: "iana" }, "application/geopackage+sqlite3": { source: "iana" }, "application/geoxacml+xml": { source: "iana", compressible: true }, "application/gltf-buffer": { source: "iana" }, "application/gml+xml": { source: "iana", compressible: true, extensions: [ "gml" ] }, "application/gpx+xml": { source: "apache", compressible: true, extensions: [ "gpx" ] }, "application/gxf": { source: "apache", extensions: [ "gxf" ] }, "application/gzip": { source: "iana", compressible: false, extensions: [ "gz" ] }, "application/h224": { source: "iana" }, "application/held+xml": { source: "iana", compressible: true }, "application/hjson": { extensions: [ "hjson" ] }, "application/http": { source: "iana" }, "applicatio