UNPKG

chaite

Version:

core for chatgpt-plugin and karin-plugin-chatgpt

1,738 lines (1,724 loc) 198 kB
import { i as __require, t as __commonJS } from "../../rolldown-runtime-DVriDoez.mjs"; import { o as require_safe_buffer } from "../@google/genai/index.mjs-BrdPnzXZ.mjs"; import { a as require_unpipe, c as require_http_errors, d as require_content_type, f as require_depd, i as require_on_finished, l as require_statuses, n as require_lib, o as require_destroy, r as require_type_is, s as require_src, t as require_body_parser, u as require_setprototypeof } from "../body-parser/index.mjs-Bj6nfRGh.mjs"; import { t as require_accepts } from "../accepts/index.mjs-CtXuJELB.mjs"; import { i as require_ms } from "../@anthropic-ai/sdk/index.mjs-sKjldQtK.mjs"; import { n as require_encodeurl, t as require_encodeurl$1 } from "../encodeurl/index.mjs-BI1DQR59.mjs"; import { t as require_escape_html } from "../escape-html/index.mjs-CH24eAfR.mjs"; import { t as require_array_flatten } from "../array-flatten/index.mjs-CQr55PjM.mjs"; import { t as require_content_disposition } from "../content-disposition/index.mjs-d-2yLiD4.mjs"; import { t as require_etag } from "../etag/index.mjs-wzo82OOp.mjs"; import { t as require_cookie_signature } from "../cookie-signature/index.mjs-BMcPfKwp.mjs"; import { t as require_cookie } from "../cookie/index.mjs-HM-UN05t.mjs"; import { n as require_vary } from "../cors/index.mjs-DqcZUs8E.mjs"; //#region node_modules/.pnpm/merge-descriptors@1.0.3/node_modules/merge-descriptors/index.js /*! * merge-descriptors * Copyright(c) 2014 Jonathan Ong * Copyright(c) 2015 Douglas Christopher Wilson * MIT Licensed */ var require_merge_descriptors = /* @__PURE__ */ __commonJS({ "node_modules/.pnpm/merge-descriptors@1.0.3/node_modules/merge-descriptors/index.js": ((exports, module) => { /** * Module exports. * @public */ module.exports = merge$3; /** * Module variables. * @private */ var hasOwnProperty$2 = Object.prototype.hasOwnProperty; /** * Merge the property descriptors of `src` into `dest` * * @param {object} dest Object to add descriptors to * @param {object} src Object to clone descriptors from * @param {boolean} [redefine=true] Redefine `dest` properties with `src` properties * @returns {object} Reference to dest * @public */ function merge$3(dest, src, redefine) { if (!dest) throw new TypeError("argument dest is required"); if (!src) throw new TypeError("argument src is required"); if (redefine === void 0) redefine = true; Object.getOwnPropertyNames(src).forEach(function forEachOwnPropertyName(name) { if (!redefine && hasOwnProperty$2.call(dest, name)) return; var descriptor = Object.getOwnPropertyDescriptor(src, name); Object.defineProperty(dest, name, descriptor); }); return dest; } }) }); //#endregion //#region node_modules/.pnpm/parseurl@1.3.3/node_modules/parseurl/index.js /*! * parseurl * Copyright(c) 2014 Jonathan Ong * Copyright(c) 2014-2017 Douglas Christopher Wilson * MIT Licensed */ var require_parseurl = /* @__PURE__ */ __commonJS({ "node_modules/.pnpm/parseurl@1.3.3/node_modules/parseurl/index.js": ((exports, module) => { /** * Module dependencies. * @private */ var url$1 = __require("url"); var parse$2 = url$1.parse; var Url = url$1.Url; /** * Module exports. * @public */ module.exports = parseurl; module.exports.original = originalurl; /** * Parse the `req` url with memoization. * * @param {ServerRequest} req * @return {Object} * @public */ function parseurl(req$2) { var url$2 = req$2.url; if (url$2 === void 0) return; var parsed = req$2._parsedUrl; if (fresh$3(url$2, parsed)) return parsed; parsed = fastparse(url$2); parsed._raw = url$2; return req$2._parsedUrl = parsed; } /** * Parse the `req` original url with fallback and memoization. * * @param {ServerRequest} req * @return {Object} * @public */ function originalurl(req$2) { var url$2 = req$2.originalUrl; if (typeof url$2 !== "string") return parseurl(req$2); var parsed = req$2._parsedOriginalUrl; if (fresh$3(url$2, parsed)) return parsed; parsed = fastparse(url$2); parsed._raw = url$2; return req$2._parsedOriginalUrl = parsed; } /** * Parse the `str` url with fast-path short-cut. * * @param {string} str * @return {Object} * @private */ function fastparse(str) { if (typeof str !== "string" || str.charCodeAt(0) !== 47) return parse$2(str); var pathname = str; var query$1 = 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$1 = str.substring(i + 1); search = str.substring(i); } break; case 9: case 10: case 12: case 13: case 32: case 35: case 160: case 65279: return parse$2(str); } var url$2 = Url !== void 0 ? new Url() : {}; url$2.path = str; url$2.href = str; url$2.pathname = pathname; if (search !== null) { url$2.query = query$1; url$2.search = search; } return url$2; } /** * Determine if parsed is still fresh for url. * * @param {string} url * @param {object} parsedUrl * @return {boolean} * @private */ function fresh$3(url$2, parsedUrl) { return typeof parsedUrl === "object" && parsedUrl !== null && (Url === void 0 || parsedUrl instanceof Url) && parsedUrl._raw === url$2; } }) }); //#endregion //#region node_modules/.pnpm/finalhandler@1.3.1/node_modules/finalhandler/index.js /*! * finalhandler * Copyright(c) 2014-2022 Douglas Christopher Wilson * MIT Licensed */ var require_finalhandler = /* @__PURE__ */ __commonJS({ "node_modules/.pnpm/finalhandler@1.3.1/node_modules/finalhandler/index.js": ((exports, module) => { /** * Module dependencies. * @private */ var debug$6 = require_src()("finalhandler"); var encodeUrl$3 = require_encodeurl(); var escapeHtml$3 = require_escape_html(); var onFinished$2 = require_on_finished(); var parseUrl$3 = require_parseurl(); var statuses$2 = require_statuses(); var unpipe = require_unpipe(); /** * Module variables. * @private */ var DOUBLE_SPACE_REGEXP = /\x20{2}/g; var NEWLINE_REGEXP = /\n/g; /* istanbul ignore next */ var defer = typeof setImmediate === "function" ? setImmediate : function(fn) { process.nextTick(fn.bind.apply(fn, arguments)); }; var isFinished = onFinished$2.isFinished; /** * Create a minimal HTML document. * * @param {string} message * @private */ function createHtmlDocument$2(message) { return "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\">\n<title>Error</title>\n</head>\n<body>\n<pre>" + escapeHtml$3(message).replace(NEWLINE_REGEXP, "<br>").replace(DOUBLE_SPACE_REGEXP, " &nbsp;") + "</pre>\n</body>\n</html>\n"; } /** * Module exports. * @public */ module.exports = finalhandler$1; /** * Create a function to handle the final response. * * @param {Request} req * @param {Response} res * @param {Object} [options] * @return {Function} * @public */ function finalhandler$1(req$2, res$2, 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$1(res$2)) { debug$6("cannot 404 after headers sent"); return; } if (err) { status = getErrorStatusCode(err); if (status === void 0) status = getResponseStatusCode(res$2); else headers = getErrorHeaders(err); msg = getErrorMessage(err, status, env); } else { status = 404; msg = "Cannot " + req$2.method + " " + encodeUrl$3(getResourceName(req$2)); } debug$6("default %s", status); if (err && onerror) defer(onerror, err, req$2, res$2); if (headersSent$1(res$2)) { debug$6("cannot %d after headers sent", status); if (req$2.socket) req$2.socket.destroy(); return; } send$3(req$2, res$2, status, headers, msg); }; } /** * Get headers from Error object. * * @param {Error} err * @return {object} * @private */ function getErrorHeaders(err) { if (!err.headers || typeof err.headers !== "object") return; var headers = 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; } /** * Get message from Error object, fallback to status message. * * @param {Error} err * @param {number} status * @param {string} env * @return {string} * @private */ 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$2.message[status]; } /** * Get status code from Error object. * * @param {Error} err * @return {number} * @private */ 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; } /** * Get resource name for the request. * * This is typically just the original pathname of the request * but will fallback to "resource" is that cannot be determined. * * @param {IncomingMessage} req * @return {string} * @private */ function getResourceName(req$2) { try { return parseUrl$3.original(req$2).pathname; } catch (e) { return "resource"; } } /** * Get status code from response. * * @param {OutgoingMessage} res * @return {number} * @private */ function getResponseStatusCode(res$2) { var status = res$2.statusCode; if (typeof status !== "number" || status < 400 || status > 599) status = 500; return status; } /** * Determine if the response headers have been sent. * * @param {object} res * @returns {boolean} * @private */ function headersSent$1(res$2) { return typeof res$2.headersSent !== "boolean" ? Boolean(res$2._header) : res$2.headersSent; } /** * Send response. * * @param {IncomingMessage} req * @param {OutgoingMessage} res * @param {number} status * @param {object} headers * @param {string} message * @private */ function send$3(req$2, res$2, status, headers, message) { function write() { var body = createHtmlDocument$2(message); res$2.statusCode = status; if (req$2.httpVersionMajor < 2) res$2.statusMessage = statuses$2.message[status]; res$2.removeHeader("Content-Encoding"); res$2.removeHeader("Content-Language"); res$2.removeHeader("Content-Range"); setHeaders$1(res$2, headers); res$2.setHeader("Content-Security-Policy", "default-src 'none'"); res$2.setHeader("X-Content-Type-Options", "nosniff"); res$2.setHeader("Content-Type", "text/html; charset=utf-8"); res$2.setHeader("Content-Length", Buffer.byteLength(body, "utf8")); if (req$2.method === "HEAD") { res$2.end(); return; } res$2.end(body, "utf8"); } if (isFinished(req$2)) { write(); return; } unpipe(req$2); onFinished$2(req$2, write); req$2.resume(); } /** * Set response headers from an object. * * @param {OutgoingMessage} res * @param {object} headers * @private */ function setHeaders$1(res$2, headers) { if (!headers) return; var keys = Object.keys(headers); for (var i = 0; i < keys.length; i++) { var key = keys[i]; res$2.setHeader(key, headers[key]); } } }) }); //#endregion //#region node_modules/.pnpm/path-to-regexp@0.1.12/node_modules/path-to-regexp/index.js var require_path_to_regexp = /* @__PURE__ */ __commonJS({ "node_modules/.pnpm/path-to-regexp@0.1.12/node_modules/path-to-regexp/index.js": ((exports, module) => { /** * Expose `pathToRegexp`. */ module.exports = pathToRegexp; /** * Match matching groups in a regular expression. */ var MATCHING_GROUP_REGEXP = /\\.|\((?:\?<(.*?)>)?(?!\?)/g; /** * Normalize the given path string, * returning a regular expression. * * An empty array should be passed, * which will contain the placeholder * key names. For example "/user/:id" will * then contain ["id"]. * * @param {String|RegExp|Array} path * @param {Array} keys * @param {Object} options * @return {RegExp} * @api private */ function pathToRegexp(path$3, keys, options) { options = options || {}; keys = keys || []; var strict = options.strict; var end = options.end !== false; var flags = options.sensitive ? "" : "i"; var lookahead = options.lookahead !== false; var extraOffset = 0; var keysOffset = keys.length; var i = 0; var name = 0; var pos = 0; var backtrack = ""; var m; if (path$3 instanceof RegExp) { while (m = MATCHING_GROUP_REGEXP.exec(path$3.source)) { if (m[0][0] === "\\") continue; keys.push({ name: m[1] || name++, optional: false, offset: m.index }); } return path$3; } if (Array.isArray(path$3)) { path$3 = path$3.map(function(value) { return pathToRegexp(value, keys, options).source; }); return new RegExp(path$3.join("|"), flags); } if (typeof path$3 !== "string") throw new TypeError("path must be a string, array of strings, or regular expression"); path$3 = path$3.replace(/\\.|(\/)?(\.)?:(\w+)(\(.*?\))?(\*)?(\?)?|[.*]|\/\(/g, function(match, slash, format, key, capture, star, optional, offset) { if (match[0] === "\\") { backtrack += match; pos += 2; return match; } if (match === ".") { backtrack += "\\."; extraOffset += 1; pos += 1; return "\\."; } if (slash || format) backtrack = ""; else backtrack += path$3.slice(pos, offset); pos = offset + match.length; if (match === "*") { extraOffset += 3; return "(.*)"; } if (match === "/(") { backtrack += "/"; extraOffset += 2; return "/(?:"; } slash = slash || ""; format = format ? "\\." : ""; optional = optional || ""; capture = capture ? capture.replace(/\\.|\*/, function(m$1) { return m$1 === "*" ? "(.*)" : m$1; }) : backtrack ? "((?:(?!/|" + backtrack + ").)+?)" : "([^/" + format + "]+?)"; keys.push({ name: key, optional: !!optional, offset: offset + extraOffset }); var result = "(?:" + format + slash + capture + (star ? "((?:[/" + format + "].+?)?)" : "") + ")" + optional; extraOffset += result.length - match.length; return result; }); while (m = MATCHING_GROUP_REGEXP.exec(path$3)) { if (m[0][0] === "\\") continue; if (keysOffset + i === keys.length || keys[keysOffset + i].offset > m.index) keys.splice(keysOffset + i, 0, { name: name++, optional: false, offset: m.index }); i++; } path$3 += strict ? "" : path$3[path$3.length - 1] === "/" ? "?" : "/?"; if (end) path$3 += "$"; else if (path$3[path$3.length - 1] !== "/") path$3 += lookahead ? "(?=/|$)" : "(?:/|$)"; return new RegExp("^" + path$3, flags); } }) }); //#endregion //#region node_modules/.pnpm/express@4.21.2/node_modules/express/lib/router/layer.js /*! * express * Copyright(c) 2009-2013 TJ Holowaychuk * Copyright(c) 2013 Roman Shtylman * Copyright(c) 2014-2015 Douglas Christopher Wilson * MIT Licensed */ var require_layer = /* @__PURE__ */ __commonJS({ "node_modules/.pnpm/express@4.21.2/node_modules/express/lib/router/layer.js": ((exports, module) => { /** * Module dependencies. * @private */ var pathRegexp = require_path_to_regexp(); var debug$5 = require_src()("express:router:layer"); /** * Module variables. * @private */ var hasOwnProperty$1 = Object.prototype.hasOwnProperty; /** * Module exports. * @public */ module.exports = Layer$2; function Layer$2(path$3, options, fn) { if (!(this instanceof Layer$2)) return new Layer$2(path$3, options, fn); debug$5("new %o", path$3); var opts = options || {}; this.handle = fn; this.name = fn.name || "<anonymous>"; this.params = void 0; this.path = void 0; this.regexp = pathRegexp(path$3, this.keys = [], opts); this.regexp.fast_star = path$3 === "*"; this.regexp.fast_slash = path$3 === "/" && opts.end === false; } /** * Handle the error for the layer. * * @param {Error} error * @param {Request} req * @param {Response} res * @param {function} next * @api private */ Layer$2.prototype.handle_error = function handle_error(error, req$2, res$2, next) { var fn = this.handle; if (fn.length !== 4) return next(error); try { fn(error, req$2, res$2, next); } catch (err) { next(err); } }; /** * Handle the request for the layer. * * @param {Request} req * @param {Response} res * @param {function} next * @api private */ Layer$2.prototype.handle_request = function handle(req$2, res$2, next) { var fn = this.handle; if (fn.length > 3) return next(); try { fn(req$2, res$2, next); } catch (err) { next(err); } }; /** * Check if this route matches `path`, if so * populate `.params`. * * @param {String} path * @return {Boolean} * @api private */ Layer$2.prototype.match = function match(path$3) { var match$1; if (path$3 != null) { if (this.regexp.fast_slash) { this.params = {}; this.path = ""; return true; } if (this.regexp.fast_star) { this.params = { "0": decode_param(path$3) }; this.path = path$3; return true; } match$1 = this.regexp.exec(path$3); } if (!match$1) { this.params = void 0; this.path = void 0; return false; } this.params = {}; this.path = match$1[0]; var keys = this.keys; var params = this.params; for (var i = 1; i < match$1.length; i++) { var prop = keys[i - 1].name; var val = decode_param(match$1[i]); if (val !== void 0 || !hasOwnProperty$1.call(params, prop)) params[prop] = val; } return true; }; /** * Decode param value. * * @param {string} val * @return {string} * @private */ function decode_param(val) { if (typeof val !== "string" || val.length === 0) return val; try { return decodeURIComponent(val); } catch (err) { if (err instanceof URIError) { err.message = "Failed to decode param '" + val + "'"; err.status = err.statusCode = 400; } throw err; } } }) }); //#endregion //#region node_modules/.pnpm/methods@1.1.2/node_modules/methods/index.js /*! * methods * Copyright(c) 2013-2014 TJ Holowaychuk * Copyright(c) 2015-2016 Douglas Christopher Wilson * MIT Licensed */ var require_methods = /* @__PURE__ */ __commonJS({ "node_modules/.pnpm/methods@1.1.2/node_modules/methods/index.js": ((exports, module) => { /** * Module dependencies. * @private */ var http$3 = __require("http"); /** * Module exports. * @public */ module.exports = getCurrentNodeMethods() || getBasicNodeMethods(); /** * Get the current Node.js methods. * @private */ function getCurrentNodeMethods() { return http$3.METHODS && http$3.METHODS.map(function lowerCaseMethod(method) { return method.toLowerCase(); }); } /** * Get the "basic" Node.js methods, a snapshot from Node.js 0.10. * @private */ function getBasicNodeMethods() { return [ "get", "post", "put", "head", "delete", "options", "trace", "copy", "lock", "mkcol", "move", "purge", "propfind", "proppatch", "unlock", "report", "mkactivity", "checkout", "merge", "m-search", "notify", "subscribe", "unsubscribe", "patch", "search", "connect" ]; } }) }); //#endregion //#region node_modules/.pnpm/express@4.21.2/node_modules/express/lib/router/route.js /*! * express * Copyright(c) 2009-2013 TJ Holowaychuk * Copyright(c) 2013 Roman Shtylman * Copyright(c) 2014-2015 Douglas Christopher Wilson * MIT Licensed */ var require_route = /* @__PURE__ */ __commonJS({ "node_modules/.pnpm/express@4.21.2/node_modules/express/lib/router/route.js": ((exports, module) => { /** * Module dependencies. * @private */ var debug$4 = require_src()("express:router:route"); var flatten$3 = require_array_flatten(); var Layer$1 = require_layer(); var methods$2 = require_methods(); /** * Module variables. * @private */ var slice$2 = Array.prototype.slice; var toString$1 = Object.prototype.toString; /** * Module exports. * @public */ module.exports = Route$2; /** * Initialize `Route` with the given `path`, * * @param {String} path * @public */ function Route$2(path$3) { this.path = path$3; this.stack = []; debug$4("new %o", path$3); this.methods = {}; } /** * Determine if the route handles a given method. * @private */ Route$2.prototype._handles_method = function _handles_method(method) { if (this.methods._all) return true; var name = typeof method === "string" ? method.toLowerCase() : method; if (name === "head" && !this.methods["head"]) name = "get"; return Boolean(this.methods[name]); }; /** * @return {Array} supported HTTP methods * @private */ Route$2.prototype._options = function _options() { var methods$3 = Object.keys(this.methods); if (this.methods.get && !this.methods.head) methods$3.push("head"); for (var i = 0; i < methods$3.length; i++) methods$3[i] = methods$3[i].toUpperCase(); return methods$3; }; /** * dispatch req, res into this route * @private */ Route$2.prototype.dispatch = function dispatch(req$2, res$2, done) { var idx = 0; var stack = this.stack; var sync = 0; if (stack.length === 0) return done(); var method = typeof req$2.method === "string" ? req$2.method.toLowerCase() : req$2.method; if (method === "head" && !this.methods["head"]) method = "get"; req$2.route = this; next(); function next(err) { if (err && err === "route") return done(); if (err && err === "router") return done(err); if (++sync > 100) return setImmediate(next, err); var layer = stack[idx++]; if (!layer) return done(err); if (layer.method && layer.method !== method) next(err); else if (err) layer.handle_error(err, req$2, res$2, next); else layer.handle_request(req$2, res$2, next); sync = 0; } }; /** * Add a handler for all HTTP verbs to this route. * * Behaves just like middleware and can respond or call `next` * to continue processing. * * You can use multiple `.all` call to add multiple handlers. * * function check_something(req, res, next){ * next(); * }; * * function validate_user(req, res, next){ * next(); * }; * * route * .all(validate_user) * .all(check_something) * .get(function(req, res, next){ * res.send('hello world'); * }); * * @param {function} handler * @return {Route} for chaining * @api public */ Route$2.prototype.all = function all() { var handles = flatten$3(slice$2.call(arguments)); for (var i = 0; i < handles.length; i++) { var handle = handles[i]; if (typeof handle !== "function") { var msg = "Route.all() requires a callback function but got a " + toString$1.call(handle); throw new TypeError(msg); } var layer = Layer$1("/", {}, handle); layer.method = void 0; this.methods._all = true; this.stack.push(layer); } return this; }; methods$2.forEach(function(method) { Route$2.prototype[method] = function() { var handles = flatten$3(slice$2.call(arguments)); for (var i = 0; i < handles.length; i++) { var handle = handles[i]; if (typeof handle !== "function") { var type = toString$1.call(handle); var msg = "Route." + method + "() requires a callback function but got a " + type; throw new Error(msg); } debug$4("%s %o", method, this.path); var layer = Layer$1("/", {}, handle); layer.method = method; this.methods[method] = true; this.stack.push(layer); } return this; }; }); }) }); //#endregion //#region node_modules/.pnpm/utils-merge@1.0.1/node_modules/utils-merge/index.js var require_utils_merge = /* @__PURE__ */ __commonJS({ "node_modules/.pnpm/utils-merge@1.0.1/node_modules/utils-merge/index.js": ((exports, module) => { /** * Merge object b with object a. * * var a = { foo: 'bar' } * , b = { bar: 'baz' }; * * merge(a, b); * // => { foo: 'bar', bar: 'baz' } * * @param {Object} a * @param {Object} b * @return {Object} * @api public */ exports = module.exports = function(a, b) { if (a && b) for (var key in b) a[key] = b[key]; return a; }; }) }); //#endregion //#region node_modules/.pnpm/express@4.21.2/node_modules/express/lib/router/index.js /*! * express * Copyright(c) 2009-2013 TJ Holowaychuk * Copyright(c) 2013 Roman Shtylman * Copyright(c) 2014-2015 Douglas Christopher Wilson * MIT Licensed */ var require_router = /* @__PURE__ */ __commonJS({ "node_modules/.pnpm/express@4.21.2/node_modules/express/lib/router/index.js": ((exports, module) => { /** * Module dependencies. * @private */ var Route$1 = require_route(); var Layer = require_layer(); var methods$1 = require_methods(); var mixin$1 = require_utils_merge(); var debug$3 = require_src()("express:router"); var deprecate$5 = require_depd()("express"); var flatten$2 = require_array_flatten(); var parseUrl$2 = require_parseurl(); var setPrototypeOf$2 = require_setprototypeof(); /** * Module variables. * @private */ var objectRegExp = /^\[object (\S+)\]$/; var slice$1 = Array.prototype.slice; var toString = Object.prototype.toString; /** * Initialize a new `Router` with the given `options`. * * @param {Object} [options] * @return {Router} which is a callable function * @public */ var proto$1 = module.exports = function(options) { var opts = options || {}; function router(req$2, res$2, next) { router.handle(req$2, res$2, next); } setPrototypeOf$2(router, proto$1); router.params = {}; router._params = []; router.caseSensitive = opts.caseSensitive; router.mergeParams = opts.mergeParams; router.strict = opts.strict; router.stack = []; return router; }; /** * Map the given param placeholder `name`(s) to the given callback. * * Parameter mapping is used to provide pre-conditions to routes * which use normalized placeholders. For example a _:user_id_ parameter * could automatically load a user's information from the database without * any additional code, * * The callback uses the same signature as middleware, the only difference * being that the value of the placeholder is passed, in this case the _id_ * of the user. Once the `next()` function is invoked, just like middleware * it will continue on to execute the route, or subsequent parameter functions. * * Just like in middleware, you must either respond to the request or call next * to avoid stalling the request. * * app.param('user_id', function(req, res, next, id){ * User.find(id, function(err, user){ * if (err) { * return next(err); * } else if (!user) { * return next(new Error('failed to load user')); * } * req.user = user; * next(); * }); * }); * * @param {String} name * @param {Function} fn * @return {app} for chaining * @public */ proto$1.param = function param(name, fn) { if (typeof name === "function") { deprecate$5("router.param(fn): Refactor to use path params"); this._params.push(name); return; } var params = this._params; var len = params.length; var ret; if (name[0] === ":") { deprecate$5("router.param(" + JSON.stringify(name) + ", fn): Use router.param(" + JSON.stringify(name.slice(1)) + ", fn) instead"); name = name.slice(1); } for (var i = 0; i < len; ++i) if (ret = params[i](name, fn)) fn = ret; if ("function" !== typeof fn) throw new Error("invalid param() call for " + name + ", got " + fn); (this.params[name] = this.params[name] || []).push(fn); return this; }; /** * Dispatch a req, res into the router. * @private */ proto$1.handle = function handle(req$2, res$2, out) { var self = this; debug$3("dispatching %s %s", req$2.method, req$2.url); var idx = 0; var protohost = getProtohost(req$2.url) || ""; var removed = ""; var slashAdded = false; var sync = 0; var paramcalled = {}; var options = []; var stack = self.stack; var parentParams = req$2.params; var parentUrl = req$2.baseUrl || ""; var done = restore(out, req$2, "baseUrl", "next", "params"); req$2.next = next; if (req$2.method === "OPTIONS") done = wrap(done, function(old, err) { if (err || options.length === 0) return old(err); sendOptionsResponse(res$2, options, old); }); req$2.baseUrl = parentUrl; req$2.originalUrl = req$2.originalUrl || req$2.url; next(); function next(err) { var layerError = err === "route" ? null : err; if (slashAdded) { req$2.url = req$2.url.slice(1); slashAdded = false; } if (removed.length !== 0) { req$2.baseUrl = parentUrl; req$2.url = protohost + removed + req$2.url.slice(protohost.length); removed = ""; } if (layerError === "router") { setImmediate(done, null); return; } if (idx >= stack.length) { setImmediate(done, layerError); return; } if (++sync > 100) return setImmediate(next, err); var path$3 = getPathname(req$2); if (path$3 == null) return done(layerError); var layer; var match; var route; while (match !== true && idx < stack.length) { layer = stack[idx++]; match = matchLayer(layer, path$3); route = layer.route; if (typeof match !== "boolean") layerError = layerError || match; if (match !== true) continue; if (!route) continue; if (layerError) { match = false; continue; } var method = req$2.method; var has_method = route._handles_method(method); if (!has_method && method === "OPTIONS") appendMethods(options, route._options()); if (!has_method && method !== "HEAD") match = false; } if (match !== true) return done(layerError); if (route) req$2.route = route; req$2.params = self.mergeParams ? mergeParams(layer.params, parentParams) : layer.params; var layerPath = layer.path; self.process_params(layer, paramcalled, req$2, res$2, function(err$1) { if (err$1) next(layerError || err$1); else if (route) layer.handle_request(req$2, res$2, next); else trim_prefix(layer, layerError, layerPath, path$3); sync = 0; }); } function trim_prefix(layer, layerError, layerPath, path$3) { if (layerPath.length !== 0) { if (layerPath !== path$3.slice(0, layerPath.length)) { next(layerError); return; } var c = path$3[layerPath.length]; if (c && c !== "/" && c !== ".") return next(layerError); debug$3("trim prefix (%s) from url %s", layerPath, req$2.url); removed = layerPath; req$2.url = protohost + req$2.url.slice(protohost.length + removed.length); if (!protohost && req$2.url[0] !== "/") { req$2.url = "/" + req$2.url; slashAdded = true; } req$2.baseUrl = parentUrl + (removed[removed.length - 1] === "/" ? removed.substring(0, removed.length - 1) : removed); } debug$3("%s %s : %s", layer.name, layerPath, req$2.originalUrl); if (layerError) layer.handle_error(layerError, req$2, res$2, next); else layer.handle_request(req$2, res$2, next); } }; /** * Process any parameters for the layer. * @private */ proto$1.process_params = function process_params(layer, called, req$2, res$2, done) { var params = this.params; var keys = layer.keys; if (!keys || keys.length === 0) return done(); var i = 0; var name; var paramIndex = 0; var key; var paramVal; var paramCallbacks; var paramCalled; function param(err) { if (err) return done(err); if (i >= keys.length) return done(); paramIndex = 0; key = keys[i++]; name = key.name; paramVal = req$2.params[name]; paramCallbacks = params[name]; paramCalled = called[name]; if (paramVal === void 0 || !paramCallbacks) return param(); if (paramCalled && (paramCalled.match === paramVal || paramCalled.error && paramCalled.error !== "route")) { req$2.params[name] = paramCalled.value; return param(paramCalled.error); } called[name] = paramCalled = { error: null, match: paramVal, value: paramVal }; paramCallback(); } function paramCallback(err) { var fn = paramCallbacks[paramIndex++]; paramCalled.value = req$2.params[key.name]; if (err) { paramCalled.error = err; param(err); return; } if (!fn) return param(); try { fn(req$2, res$2, paramCallback, paramVal, key.name); } catch (e) { paramCallback(e); } } param(); }; /** * Use the given middleware function, with optional path, defaulting to "/". * * Use (like `.all`) will run for any http METHOD, but it will not add * handlers for those methods so OPTIONS requests will not consider `.use` * functions even if they could respond. * * The other difference is that _route_ path is stripped and not visible * to the handler function. The main effect of this feature is that mounted * handlers can operate without any code changes regardless of the "prefix" * pathname. * * @public */ proto$1.use = function use(fn) { var offset = 0; var path$3 = "/"; if (typeof fn !== "function") { var arg = fn; while (Array.isArray(arg) && arg.length !== 0) arg = arg[0]; if (typeof arg !== "function") { offset = 1; path$3 = fn; } } var callbacks = flatten$2(slice$1.call(arguments, offset)); if (callbacks.length === 0) throw new TypeError("Router.use() requires a middleware function"); for (var i = 0; i < callbacks.length; i++) { var fn = callbacks[i]; if (typeof fn !== "function") throw new TypeError("Router.use() requires a middleware function but got a " + gettype(fn)); debug$3("use %o %s", path$3, fn.name || "<anonymous>"); var layer = new Layer(path$3, { sensitive: this.caseSensitive, strict: false, end: false }, fn); layer.route = void 0; this.stack.push(layer); } return this; }; /** * Create a new Route for the given path. * * Each route contains a separate middleware stack and VERB handlers. * * See the Route api documentation for details on adding handlers * and middleware to routes. * * @param {String} path * @return {Route} * @public */ proto$1.route = function route(path$3) { var route$1 = new Route$1(path$3); var layer = new Layer(path$3, { sensitive: this.caseSensitive, strict: this.strict, end: true }, route$1.dispatch.bind(route$1)); layer.route = route$1; this.stack.push(layer); return route$1; }; methods$1.concat("all").forEach(function(method) { proto$1[method] = function(path$3) { var route = this.route(path$3); route[method].apply(route, slice$1.call(arguments, 1)); return this; }; }); function appendMethods(list, addition) { for (var i = 0; i < addition.length; i++) { var method = addition[i]; if (list.indexOf(method) === -1) list.push(method); } } function getPathname(req$2) { try { return parseUrl$2(req$2).pathname; } catch (err) { return; } } function getProtohost(url$2) { if (typeof url$2 !== "string" || url$2.length === 0 || url$2[0] === "/") return; var searchIndex = url$2.indexOf("?"); var pathLength = searchIndex !== -1 ? searchIndex : url$2.length; var fqdnIndex = url$2.slice(0, pathLength).indexOf("://"); return fqdnIndex !== -1 ? url$2.substring(0, url$2.indexOf("/", 3 + fqdnIndex)) : void 0; } function gettype(obj) { var type = typeof obj; if (type !== "object") return type; return toString.call(obj).replace(objectRegExp, "$1"); } /** * Match path to a layer. * * @param {Layer} layer * @param {string} path * @private */ function matchLayer(layer, path$3) { try { return layer.match(path$3); } catch (err) { return err; } } function mergeParams(params, parent) { if (typeof parent !== "object" || !parent) return params; var obj = mixin$1({}, parent); if (!(0 in params) || !(0 in parent)) return mixin$1(obj, params); var i = 0; var o = 0; while (i in params) i++; while (o in parent) o++; for (i--; i >= 0; i--) { params[i + o] = params[i]; if (i < o) delete params[i]; } return mixin$1(obj, params); } function restore(fn, obj) { var props = new Array(arguments.length - 2); var vals = new Array(arguments.length - 2); for (var i = 0; i < props.length; i++) { props[i] = arguments[i + 2]; vals[i] = obj[props[i]]; } return function() { for (var i$1 = 0; i$1 < props.length; i$1++) obj[props[i$1]] = vals[i$1]; return fn.apply(this, arguments); }; } function sendOptionsResponse(res$2, options, next) { try { var body = options.join(","); res$2.set("Allow", body); res$2.send(body); } catch (err) { next(err); } } function wrap(old, fn) { return function proxy() { var args = new Array(arguments.length + 1); args[0] = old; for (var i = 0, len = arguments.length; i < len; i++) args[i + 1] = arguments[i]; fn.apply(this, args); }; } }) }); //#endregion //#region node_modules/.pnpm/express@4.21.2/node_modules/express/lib/middleware/init.js /*! * express * Copyright(c) 2009-2013 TJ Holowaychuk * Copyright(c) 2013 Roman Shtylman * Copyright(c) 2014-2015 Douglas Christopher Wilson * MIT Licensed */ var require_init = /* @__PURE__ */ __commonJS({ "node_modules/.pnpm/express@4.21.2/node_modules/express/lib/middleware/init.js": ((exports) => { /** * Module dependencies. * @private */ var setPrototypeOf$1 = require_setprototypeof(); /** * Initialization middleware, exposing the * request and response to each other, as well * as defaulting the X-Powered-By header field. * * @param {Function} app * @return {Function} * @api private */ exports.init = function(app$1) { return function expressInit(req$2, res$2, next) { if (app$1.enabled("x-powered-by")) res$2.setHeader("X-Powered-By", "Express"); req$2.res = res$2; res$2.req = req$2; req$2.next = next; setPrototypeOf$1(req$2, app$1.request); setPrototypeOf$1(res$2, app$1.response); res$2.locals = res$2.locals || Object.create(null); next(); }; }; }) }); //#endregion //#region node_modules/.pnpm/express@4.21.2/node_modules/express/lib/middleware/query.js /*! * express * Copyright(c) 2009-2013 TJ Holowaychuk * Copyright(c) 2013 Roman Shtylman * Copyright(c) 2014-2015 Douglas Christopher Wilson * MIT Licensed */ var require_query = /* @__PURE__ */ __commonJS({ "node_modules/.pnpm/express@4.21.2/node_modules/express/lib/middleware/query.js": ((exports, module) => { /** * Module dependencies. */ var merge$2 = require_utils_merge(); var parseUrl$1 = require_parseurl(); var qs$1 = require_lib(); /** * @param {Object} options * @return {Function} * @api public */ module.exports = function query$1(options) { var opts = merge$2({}, options); var queryparse = qs$1.parse; if (typeof options === "function") { queryparse = options; opts = void 0; } if (opts !== void 0 && opts.allowPrototypes === void 0) opts.allowPrototypes = true; return function query$2(req$2, res$2, next) { if (!req$2.query) { var val = parseUrl$1(req$2).query; req$2.query = queryparse(val, opts); } next(); }; }; }) }); //#endregion //#region node_modules/.pnpm/express@4.21.2/node_modules/express/lib/view.js /*! * express * Copyright(c) 2009-2013 TJ Holowaychuk * Copyright(c) 2013 Roman Shtylman * Copyright(c) 2014-2015 Douglas Christopher Wilson * MIT Licensed */ var require_view = /* @__PURE__ */ __commonJS({ "node_modules/.pnpm/express@4.21.2/node_modules/express/lib/view.js": ((exports, module) => { /** * Module dependencies. * @private */ var debug$2 = require_src()("express:view"); var path$2 = __require("path"); var fs$2 = __require("fs"); /** * Module variables. * @private */ var dirname = path$2.dirname; var basename = path$2.basename; var extname$2 = path$2.extname; var join$1 = path$2.join; var resolve$4 = path$2.resolve; /** * Module exports. * @public */ module.exports = View$1; /** * Initialize a new `View` with the given `name`. * * Options: * * - `defaultEngine` the default template engine name * - `engines` template engine require() cache * - `root` root path for view lookup * * @param {string} name * @param {object} options * @public */ function View$1(name, options) { var opts = options || {}; this.defaultEngine = opts.defaultEngine; this.ext = extname$2(name); this.name = name; this.root = opts.root; if (!this.ext && !this.defaultEngine) throw new Error("No default engine was specified and no extension was provided."); var fileName = name; if (!this.ext) { this.ext = this.defaultEngine[0] !== "." ? "." + this.defaultEngine : this.defaultEngine; fileName += this.ext; } if (!opts.engines[this.ext]) { var mod = this.ext.slice(1); debug$2("require \"%s\"", mod); var fn = __require(mod).__express; if (typeof fn !== "function") throw new Error("Module \"" + mod + "\" does not provide a view engine."); opts.engines[this.ext] = fn; } this.engine = opts.engines[this.ext]; this.path = this.lookup(fileName); } /** * Lookup view by the given `name` * * @param {string} name * @private */ View$1.prototype.lookup = function lookup(name) { var path$3; var roots = [].concat(this.root); debug$2("lookup \"%s\"", name); for (var i = 0; i < roots.length && !path$3; i++) { var root = roots[i]; var loc = resolve$4(root, name); var dir = dirname(loc); var file = basename(loc); path$3 = this.resolve(dir, file); } return path$3; }; /** * Render with the given options. * * @param {object} options * @param {function} callback * @private */ View$1.prototype.render = function render(options, callback) { debug$2("render \"%s\"", this.path); this.engine(this.path, options, callback); }; /** * Resolve the file within the given directory. * * @param {string} dir * @param {string} file * @private */ View$1.prototype.resolve = function resolve$5(dir, file) { var ext = this.ext; var path$3 = join$1(dir, file); var stat = tryStat(path$3); if (stat && stat.isFile()) return path$3; path$3 = join$1(dir, basename(file, ext), "index" + ext); stat = tryStat(path$3); if (stat && stat.isFile()) return path$3; }; /** * Return a stat, maybe. * * @param {string} path * @return {fs.Stats} * @private */ function tryStat(path$3) { debug$2("stat \"%s\"", path$3); try { return fs$2.statSync(path$3); } catch (e) { return; } } }) }); //#endregion //#region node_modules/.pnpm/fresh@0.5.2/node_modules/fresh/index.js /*! * fresh * Copyright(c) 2012 TJ Holowaychuk * Copyright(c) 2016-2017 Douglas Christopher Wilson * MIT Licensed */ var require_fresh = /* @__PURE__ */ __commonJS({ "node_modules/.pnpm/fresh@0.5.2/node_modules/fresh/index.js": ((exports, module) => { /** * RegExp to check for no-cache token in Cache-Control. * @private */ var CACHE_CONTROL_NO_CACHE_REGEXP = /(?:^|,)\s*?no-cache\s*?(?:,|$)/; /** * Module exports. * @public */ module.exports = fresh$2; /** * Check freshness of the response using request and response headers. * * @param {Object} reqHeaders * @param {Object} resHeaders * @return {Boolean} * @public */ function fresh$2(reqHeaders, resHeaders) { var modifiedSince = reqHeaders["if-modified-since"]; var noneMatch = reqHeaders["if-none-match"]; if (!modifiedSince && !noneMatch) return false; var cacheControl = reqHeaders["cache-control"]; if (cacheControl && CACHE_CONTROL_NO_CACHE_REGEXP.test(cacheControl)) return false; if (noneMatch && noneMatch !== "*") { var etag$2 = resHeaders["etag"]; if (!etag$2) return false; var etagStale = true; var matches = parseTokenList$1(noneMatch); for (var i = 0; i < matches.length; i++) { var match = matches[i]; if (match === etag$2 || match === "W/" + etag$2 || "W/" + match === etag$2) { etagStale = false; break; } } if (etagStale) return false; } if (modifiedSince) { var lastModified = resHeaders["last-modified"]; if (!lastModified || !(parseHttpDate$1(lastModified) <= parseHttpDate$1(modifiedSince))) return false; } return true; } /** * Parse an HTTP Date into a number. * * @param {string} date * @private */ function parseHttpDate$1(date) { var timestamp = date && Date.parse(date); // istanbul ignore next: guard against date.js Date.parse patching return typeof timestamp === "number" ? timestamp : NaN; } /** * Parse a HTTP token list. * * @param {string} str * @private */ function parseTokenList$1(str) { var end = 0; var list = []; var start = 0; for (var i = 0, len = str.length; i < len; i++) switch (str.charCodeAt(i)) { case 32: if (start === end) start = end = i + 1; break; case 44: list.push(str.substring(start, end)); start = end = i + 1; break; default: end = i + 1; break; } list.push(str.substring(start, end)); return list; } }) }); //#endregion //#region node_modules/.pnpm/mime@1.6.0/node_modules/mime/types.json var require_types = /* @__PURE__ */ __commonJS({ "node_modules/.pnpm/mime@1.6.0/node_modules/mime/types.json": ((exports, module) => { module.exports = { "application/andrew-inset": ["ez"], "application/applixware": ["aw"], "application/atom+xml": ["atom"], "application/atomcat+xml": ["atomcat"], "application/atomsvc+xml": ["atomsvc"], "application/bdoc": ["bdoc"], "application/ccxml+xml": ["ccxml"], "application/cdmi-capability": ["cdmia"], "application/cdmi-container": ["cdmic"], "application/cdmi-domain": ["cdmid"], "application/cdmi-object": ["cdmio"], "application/cdmi-queue": ["cdmiq"], "application/cu-seeme": ["cu"], "application/dash+xml": ["mpd"], "application/davmount+xml": ["davmount"], "application/docbook+xml": ["dbk"], "application/dssc+der": ["dssc"], "application/dssc+xml": ["xdssc"], "application/ecmascript": ["ecma"], "application/emma+xml": ["emma"], "application/epub+zip": ["epub"], "application/exi": ["exi"], "application/font-tdpfr": ["pfr"], "application/font-woff": [], "application/font-woff2": [], "application/geo+json": ["geojson"], "application/gml+xml": ["gml"], "application/gpx+xml": ["gpx"], "application/gxf": ["gxf"], "application/gzip": ["gz"], "application/hyperstudio": ["stk"], "application/inkml+xml": ["ink", "inkml"], "application/ipfix": ["ipfix"], "application/java-archive": [ "jar", "war", "ear" ], "application/java-serialized-object": ["ser"], "application/java-vm": ["class"], "application/javascript": ["js", "mjs"], "application/json": ["json", "map"], "application/json5": ["json5"], "application/jsonml+json": ["jsonml"], "application/ld+json": ["jsonld"], "application/lost+xml": ["lostxml"], "application/mac-binhex40": ["hqx"], "application/mac-compactpro": ["cpt"], "application/mads+xml": ["mads"], "application/manifest+json": ["webmanifest"], "application/marc": ["mrc"], "application/marcxml+xml": ["mrcx"], "application/mathematica": [ "ma", "nb", "mb" ], "application/mathml+xml": ["mathml"], "application/mbox": ["mbox"], "application/mediaservercontrol+xml": ["mscml"], "application/metalink+xml": ["metalink"], "application/metalink4+xml": ["meta4"], "application/mets+xml": ["mets"], "application/mods+xml": ["mods"], "application/mp21": ["m21", "mp21"], "application/mp4": ["mp4s", "m4p"], "application/msword": ["doc", "dot"], "application/mxf": ["mxf"], "application/octet-stream": [ "bin", "dms", "lrf", "mar", "so", "dist", "distz", "pkg", "bpk", "dump", "elc", "deploy", "exe", "dll", "deb", "dmg", "iso", "img", "msi", "msp", "msm", "buffer" ], "application/oda": ["oda"], "application/oebps-package+xml": ["opf"], "application/ogg": ["ogx"], "application/omdoc+xml": ["omdoc"], "application/onenote": [ "onetoc", "onetoc2", "onetmp", "onepkg" ], "application/oxps": ["oxps"], "application/patch-ops-error+xml": ["xer"], "application/pdf": ["pdf"], "application/pgp-encrypted": ["pgp"], "application/pgp-signature": ["asc", "sig"], "application/pics-rules": ["prf"], "application/pkcs10": ["p10"], "application/pkcs7-mime": ["p7m", "p7c"], "application/pkcs7-signature": ["p7s"], "application/pkcs8": ["p8"], "application/pkix-attr-cert": ["ac"], "application/pkix-cert": ["cer"], "application/pkix-crl": ["crl"], "application/pkix-pkipath": ["pkipath"], "application/pkixcmp": ["pki"], "application/pls+xml": ["pls"], "application/postscript": [ "ai", "eps", "ps" ], "application/prs.cww": ["cww"], "application/pskc+xml": ["pskcxml"], "application/raml+yaml": ["raml"], "application/rdf+xml": ["rdf"], "application/reginfo+xml": ["rif"], "application/relax-ng-compact-syntax": ["rnc"], "application/resource-lists+xml": ["rl"], "application/resource-lists-diff+xml": ["rld"], "application/rls-services+xml": ["rs"], "application/rpki-ghostbusters": ["gbr"], "application/rpki-manifest": ["mft"], "application/rpki-roa": ["roa"], "application/rsd+xml": ["rsd"], "application/rss+xml": ["rss"], "application/rtf": ["rtf"], "application/sbml+xml": ["sbml"], "application/scvp-cv-request": ["scq"], "application/scvp-cv-response": ["scs"], "application/scvp-vp-request": ["spq"], "application/scvp-vp-response": ["spp"], "application/sdp": ["sdp"], "application/set-payment-initiation": ["setpay"], "application/set-registration-initiation": ["setreg"], "application/shf+xml": ["shf"], "application/smil+xml": ["smi", "smil"], "application/sparql-query": ["rq"], "application/sparql-results+xml": ["srx"], "application/srgs": ["gram"], "application/srgs+xml": ["grxml"], "application/sru+xml": ["sru"], "application/ssdl+xml": ["ssdl"], "application/ssml+xml": ["ssml"], "application/tei+xml": ["tei", "teicorpus"], "application/thraud+xml": ["tfi"], "application/timestamped-data": ["tsd"], "application/vnd.3gpp.pic-bw-large": ["plb"], "application/vnd.3gpp.pic-bw-small": ["psb"], "application/vnd.3gpp.pic-bw-var": ["pvb"], "application/vnd.3gpp2.tcap": ["tcap"], "application/vnd.3m.p