ship 1.4.32:Arcrun@eebb691

This commit is contained in:
ship
2026-08-10 14:25:55 +00:00
parent 595a7c607e
commit c698ad4e41
8 changed files with 34467 additions and 484 deletions
+269 -223
View File
@@ -1,7 +1,7 @@
// ../../matrix/arcrun/.component-builds/http_request/src/index.ts
// ../arcrun/.component-builds/http_request/src/index.ts
import componentWasm from "./component.wasm";
// ../../matrix/arcrun/.component-builds/http_request/node_modules/.pnpm/hono@4.12.14/node_modules/hono/dist/compose.js
// ../arcrun/.component-builds/http_request/node_modules/hono/dist/compose.js
var compose = (middleware, onError, onNotFound) => {
return (context, next) => {
let index = -1;
@@ -45,21 +45,46 @@ var compose = (middleware, onError, onNotFound) => {
};
};
// ../../matrix/arcrun/.component-builds/http_request/node_modules/.pnpm/hono@4.12.14/node_modules/hono/dist/request/constants.js
// ../arcrun/.component-builds/http_request/node_modules/hono/dist/request/constants.js
var GET_MATCH_RESULT = /* @__PURE__ */ Symbol();
// ../../matrix/arcrun/.component-builds/http_request/node_modules/.pnpm/hono@4.12.14/node_modules/hono/dist/utils/body.js
// ../arcrun/.component-builds/http_request/node_modules/hono/dist/utils/buffer.js
var bufferToFormData = (arrayBuffer, contentType) => {
const response = new Response(arrayBuffer, {
headers: {
// Normalize the media type (case-insensitive) while keeping parameters like the boundary
"Content-Type": contentType.replace(/^[^;]+/, (mediaType) => mediaType.toLowerCase())
}
});
return response.formData();
};
// ../arcrun/.component-builds/http_request/node_modules/hono/dist/utils/body.js
var isRawRequest = (request) => "headers" in request;
var parseBody = async (request, options = /* @__PURE__ */ Object.create(null)) => {
const { all = false, dot = false } = options;
const headers = request instanceof HonoRequest ? request.raw.headers : request.headers;
const headers = isRawRequest(request) ? request.headers : request.raw.headers;
const contentType = headers.get("Content-Type");
if (contentType?.startsWith("multipart/form-data") || contentType?.startsWith("application/x-www-form-urlencoded")) {
const mediaType = contentType?.split(";")[0].trim().toLowerCase();
if (mediaType === "multipart/form-data" || mediaType === "application/x-www-form-urlencoded") {
return parseFormData(request, { all, dot });
}
return {};
};
async function parseFormData(request, options) {
const formData = await request.formData();
if (!isRawRequest(request) && request.bodyCache.formData) {
return convertFormDataToBodyData(
await request.bodyCache.formData,
options
);
}
const headers = isRawRequest(request) ? request.headers : request.raw.headers;
const arrayBuffer = await request.arrayBuffer();
const formDataPromise = bufferToFormData(arrayBuffer, headers.get("Content-Type") || "");
if (!isRawRequest(request)) {
request.bodyCache.formData = formDataPromise;
}
const formData = await formDataPromise;
if (formData) {
return convertFormDataToBodyData(formData, options);
}
@@ -120,7 +145,7 @@ var handleParsingNestedValues = (form, key, value) => {
});
};
// ../../matrix/arcrun/.component-builds/http_request/node_modules/.pnpm/hono@4.12.14/node_modules/hono/dist/utils/url.js
// ../arcrun/.component-builds/http_request/node_modules/hono/dist/utils/url.js
var splitPath = (path) => {
const paths = path.split("/");
if (paths[0] === "") {
@@ -242,18 +267,16 @@ var checkOptionalParameter = (path) => {
});
return results.filter((v, i, a) => a.indexOf(v) === i);
};
var tryDecodeURIComponent = (str) => str.indexOf("%") !== -1 ? tryDecode(str, decodeURIComponent_) : str;
var _decodeURI = (value) => {
if (!/[%+]/.test(value)) {
return value;
}
if (value.indexOf("+") !== -1) {
value = value.replace(/\+/g, " ");
}
return value.indexOf("%") !== -1 ? tryDecode(value, decodeURIComponent_) : value;
return tryDecodeURIComponent(value);
};
var _getQueryParam = (url, key, multiple) => {
let encoded;
if (!multiple && key && !/[%+]/.test(key)) {
if (!multiple && key && key.indexOf("%") === -1 && key.indexOf("+") === -1) {
let keyIndex2 = url.indexOf("?", 8);
if (keyIndex2 === -1) {
return void 0;
@@ -277,7 +300,7 @@ var _getQueryParam = (url, key, multiple) => {
return void 0;
}
}
const results = {};
const results = /* @__PURE__ */ Object.create(null);
encoded ??= /[%+]/.test(url);
let keyIndex = url.indexOf("?", 8);
while (keyIndex !== -1) {
@@ -324,8 +347,7 @@ var getQueryParams = (url, key) => {
};
var decodeURIComponent_ = decodeURIComponent;
// ../../matrix/arcrun/.component-builds/http_request/node_modules/.pnpm/hono@4.12.14/node_modules/hono/dist/request.js
var tryDecodeURIComponent = (str) => tryDecode(str, decodeURIComponent_);
// ../arcrun/.component-builds/http_request/node_modules/hono/dist/request.js
var HonoRequest = class {
/**
* `.raw` can get the raw Request object.
@@ -364,7 +386,6 @@ var HonoRequest = class {
this.raw = request;
this.path = path;
this.#matchResult = matchResult;
this.#validatedData = {};
}
param(key) {
return key ? this.#getDecodedParam(key) : this.#getAllDecodedParams();
@@ -372,7 +393,7 @@ var HonoRequest = class {
#getDecodedParam(key) {
const paramKey = this.#matchResult[0][this.routeIndex][1][key];
const param = this.#getParamValue(paramKey);
return param && /\%/.test(param) ? tryDecodeURIComponent(param) : param;
return param && tryDecodeURIComponent(param);
}
#getAllDecodedParams() {
const decoded = {};
@@ -380,7 +401,7 @@ var HonoRequest = class {
for (const key of keys) {
const value = this.#getParamValue(this.#matchResult[0][this.routeIndex][1][key]);
if (value !== void 0) {
decoded[key] = /\%/.test(value) ? tryDecodeURIComponent(value) : value;
decoded[key] = tryDecodeURIComponent(value);
}
}
return decoded;
@@ -398,7 +419,7 @@ var HonoRequest = class {
if (name) {
return this.raw.headers.get(name) ?? void 0;
}
const headerData = {};
const headerData = /* @__PURE__ */ Object.create(null);
this.raw.headers.forEach((value, key) => {
headerData[key] = value;
});
@@ -413,8 +434,7 @@ var HonoRequest = class {
if (cachedBody) {
return cachedBody;
}
const anyCachedKey = Object.keys(bodyCache)[0];
if (anyCachedKey) {
for (const anyCachedKey in bodyCache) {
return bodyCache[anyCachedKey].then((body) => {
if (anyCachedKey === "json") {
body = JSON.stringify(body);
@@ -469,6 +489,21 @@ var HonoRequest = class {
arrayBuffer() {
return this.#cachedBody("arrayBuffer");
}
/**
* `.bytes()` parses the request body as a `Uint8Array`.
*
* @see {@link https://hono.dev/docs/api/request#bytes}
*
* @example
* ```ts
* app.post('/entry', async (c) => {
* const body = await c.req.bytes()
* })
* ```
*/
bytes() {
return this.#cachedBody("arrayBuffer").then((buffer) => new Uint8Array(buffer));
}
/**
* Parses the request body as a `Blob`.
* @example
@@ -502,10 +537,11 @@ var HonoRequest = class {
* @param data - The validated data to add.
*/
addValidatedData(target, data) {
this.#validatedData[target] = data;
;
(this.#validatedData ??= {})[target] = data;
}
valid(target) {
return this.#validatedData[target];
return this.#validatedData?.[target];
}
/**
* `.url()` can get the request url strings.
@@ -592,7 +628,7 @@ var HonoRequest = class {
}
};
// ../../matrix/arcrun/.component-builds/http_request/node_modules/.pnpm/hono@4.12.14/node_modules/hono/dist/utils/html.js
// ../arcrun/.component-builds/http_request/node_modules/hono/dist/utils/html.js
var HtmlEscapedCallbackPhase = {
Stringify: 1,
BeforeStream: 2,
@@ -634,7 +670,7 @@ var resolveCallback = async (str, phase, preserveCallbacks, context, buffer) =>
}
};
// ../../matrix/arcrun/.component-builds/http_request/node_modules/.pnpm/hono@4.12.14/node_modules/hono/dist/context.js
// ../arcrun/.component-builds/http_request/node_modules/hono/dist/context.js
var TEXT_PLAIN = "text/plain; charset=UTF-8";
var setDefaultContentType = (contentType, headers) => {
return {
@@ -907,11 +943,11 @@ var Context = class {
return Object.fromEntries(this.#var);
}
#newResponse(data, arg, headers) {
const responseHeaders = this.#res ? new Headers(this.#res.headers) : this.#preparedHeaders ?? new Headers();
if (typeof arg === "object" && "headers" in arg) {
const argHeaders = arg.headers instanceof Headers ? arg.headers : new Headers(arg.headers);
for (const [key, value] of argHeaders) {
if (key.toLowerCase() === "set-cookie") {
let responseHeaders = this.#res ? new Headers(this.#res.headers) : this.#preparedHeaders;
if (typeof arg === "object" && arg.headers) {
responseHeaders ??= new Headers();
for (const [key, value] of new Headers(arg.headers)) {
if (key === "set-cookie") {
responseHeaders.append(key, value);
} else {
responseHeaders.set(key, value);
@@ -919,19 +955,34 @@ var Context = class {
}
}
if (headers) {
for (const [k, v] of Object.entries(headers)) {
if (typeof v === "string") {
responseHeaders.set(k, v);
} else {
responseHeaders.delete(k);
for (const v2 of v) {
responseHeaders.append(k, v2);
if (!responseHeaders) {
let count = 0;
for (const k in headers) {
if (++count > 1 || typeof headers[k] !== "string") {
responseHeaders = new Headers();
break;
}
}
}
if (responseHeaders) {
for (const k in headers) {
const v = headers[k];
if (typeof v === "string") {
responseHeaders.set(k, v);
} else {
responseHeaders.delete(k);
for (const v2 of v) {
responseHeaders.append(k, v2);
}
}
}
}
}
const status = typeof arg === "number" ? arg : arg?.status ?? this.#status;
return createResponseInstance(data, { status, headers: responseHeaders });
return createResponseInstance(data, {
status,
headers: responseHeaders ?? headers
});
}
newResponse = (...args) => this.#newResponse(...args);
/**
@@ -1041,18 +1092,18 @@ var Context = class {
};
};
// ../../matrix/arcrun/.component-builds/http_request/node_modules/.pnpm/hono@4.12.14/node_modules/hono/dist/router.js
// ../arcrun/.component-builds/http_request/node_modules/hono/dist/router.js
var METHOD_NAME_ALL = "ALL";
var METHOD_NAME_ALL_LOWERCASE = "all";
var METHODS = ["get", "post", "put", "delete", "options", "patch"];
var METHODS = ["get", "post", "put", "delete", "options", "patch", "query"];
var MESSAGE_MATCHER_IS_ALREADY_BUILT = "Can not add a route since the matcher is already built.";
var UnsupportedPathError = class extends Error {
};
// ../../matrix/arcrun/.component-builds/http_request/node_modules/.pnpm/hono@4.12.14/node_modules/hono/dist/utils/constants.js
// ../arcrun/.component-builds/http_request/node_modules/hono/dist/utils/constants.js
var COMPOSED_HANDLER = "__COMPOSED_HANDLER";
// ../../matrix/arcrun/.component-builds/http_request/node_modules/.pnpm/hono@4.12.14/node_modules/hono/dist/hono-base.js
// ../arcrun/.component-builds/http_request/node_modules/hono/dist/hono-base.js
var notFoundHandler = (c) => {
return c.text("404 Not Found", 404);
};
@@ -1071,6 +1122,7 @@ var Hono = class _Hono {
delete;
options;
patch;
query;
all;
on;
use;
@@ -1167,7 +1219,7 @@ var Hono = class _Hono {
handler = async (c, next) => (await compose([], app2.errorHandler)(c, () => r.handler(c, next))).res;
handler[COMPOSED_HANDLER] = r.handler;
}
subApp.#addRoute(r.method, r.path, handler);
subApp.#addRoute(r.method, r.path, handler, r.basePath);
});
return this;
}
@@ -1291,7 +1343,7 @@ var Hono = class _Hono {
const pathPrefixLength = mergedPath === "/" ? 0 : mergedPath.length;
return (request) => {
const url = new URL(request.url);
url.pathname = url.pathname.slice(pathPrefixLength) || "/";
url.pathname = this.getPath(request).slice(pathPrefixLength) || "/";
return new Request(url, request);
};
})();
@@ -1305,10 +1357,15 @@ var Hono = class _Hono {
this.#addRoute(METHOD_NAME_ALL, mergePath(path, "*"), handler);
return this;
}
#addRoute(method, path, handler) {
#addRoute(method, path, handler, baseRoutePath) {
method = method.toUpperCase();
path = mergePath(this._basePath, path);
const r = { basePath: this._basePath, path, method, handler };
const r = {
basePath: baseRoutePath !== void 0 ? mergePath(this._basePath, baseRoutePath) : this._basePath,
path,
method,
handler
};
this.router.add(method, path, [handler, r]);
this.routes.push(r);
}
@@ -1365,8 +1422,8 @@ var Hono = class _Hono {
* @see {@link https://hono.dev/docs/api/hono#fetch}
*
* @param {Request} request - request Object of request
* @param {Env} Env - env Object
* @param {ExecutionContext} - context of execution
* @param {Env} env - env Object
* @param {ExecutionContext} executionCtx - context of execution
* @returns {Response | Promise<Response>} response of request
*
*/
@@ -1423,7 +1480,7 @@ var Hono = class _Hono {
};
};
// ../../matrix/arcrun/.component-builds/http_request/node_modules/.pnpm/hono@4.12.14/node_modules/hono/dist/router/reg-exp-router/matcher.js
// ../arcrun/.component-builds/http_request/node_modules/hono/dist/router/reg-exp-router/matcher.js
var emptyParam = [];
function match(method, path) {
const matchers = this.buildAllMatchers();
@@ -1444,7 +1501,7 @@ function match(method, path) {
return match2(method, path);
}
// ../../matrix/arcrun/.component-builds/http_request/node_modules/.pnpm/hono@4.12.14/node_modules/hono/dist/router/reg-exp-router/node.js
// ../arcrun/.component-builds/http_request/node_modules/hono/dist/router/reg-exp-router/node.js
var LABEL_REG_EXP_STR = "[^/]+";
var ONLY_WILDCARD_REG_EXP_STR = ".*";
var TAIL_WILDCARD_REG_EXP_STR = "(?:|/.*)";
@@ -1458,7 +1515,7 @@ function compareKey(a, b) {
return 1;
}
if (a === ONLY_WILDCARD_REG_EXP_STR || a === TAIL_WILDCARD_REG_EXP_STR) {
return 1;
return b === TAIL_WILDCARD_REG_EXP_STR ? -1 : 1;
} else if (b === ONLY_WILDCARD_REG_EXP_STR || b === TAIL_WILDCARD_REG_EXP_STR) {
return -1;
}
@@ -1470,76 +1527,75 @@ function compareKey(a, b) {
return a.length === b.length ? a < b ? -1 : 1 : b.length - a.length;
}
var Node = class _Node {
// handler index of a dynamic path, or -1 for a static path terminal
#index;
#varIndex;
#children = /* @__PURE__ */ Object.create(null);
insert(tokens, index, paramMap, context, pathErrorCheckOnly) {
if (tokens.length === 0) {
if (this.#index !== void 0) {
throw PATH_ERROR;
}
if (pathErrorCheckOnly) {
return;
}
this.#index = index;
return;
}
const [token, ...restTokens] = tokens;
const pattern = token === "*" ? restTokens.length === 0 ? ["", "", ONLY_WILDCARD_REG_EXP_STR] : ["", "", LABEL_REG_EXP_STR] : token === "/*" ? ["", "", TAIL_WILDCARD_REG_EXP_STR] : token.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
let node;
if (pattern) {
const name = pattern[1];
let regexpStr = pattern[2] || LABEL_REG_EXP_STR;
if (name && pattern[2]) {
if (regexpStr === ".*") {
throw PATH_ERROR;
insert(tokens, index, paramMap, context, isStatic) {
let node = this;
for (let i = 0, len = tokens.length; i < len; i++) {
const token = tokens[i];
const pattern = token.length === 1 ? token === "*" ? i === len - 1 ? ["", "", ONLY_WILDCARD_REG_EXP_STR] : ["", "", LABEL_REG_EXP_STR] : null : token === "/*" ? ["", "", TAIL_WILDCARD_REG_EXP_STR] : token.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
let nextNode;
if (pattern) {
const name = pattern[1];
let regexpStr = pattern[2] || LABEL_REG_EXP_STR;
if (name && pattern[2]) {
if (regexpStr === ".*") {
throw PATH_ERROR;
}
regexpStr = regexpStr.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:");
if (/\((?!\?:)/.test(regexpStr)) {
throw PATH_ERROR;
}
if (regexpStr.length === 1 && regExpMetaChars.has(regexpStr)) {
throw PATH_ERROR;
}
}
regexpStr = regexpStr.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:");
if (/\((?!\?:)/.test(regexpStr)) {
throw PATH_ERROR;
nextNode = node.#children[regexpStr];
if (!nextNode) {
if (regexpStr !== ONLY_WILDCARD_REG_EXP_STR && regexpStr !== TAIL_WILDCARD_REG_EXP_STR) {
for (const k in node.#children) {
if (
// a single-char pattern coexists with single-char literals as a literal does
(regexpStr.length > 1 || k.length > 1) && k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR
) {
throw PATH_ERROR;
}
}
}
nextNode = node.#children[regexpStr] = new _Node();
}
}
node = this.#children[regexpStr];
if (!node) {
if (Object.keys(this.#children).some(
(k) => k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR
)) {
throw PATH_ERROR;
}
if (pathErrorCheckOnly) {
return;
}
node = this.#children[regexpStr] = new _Node();
if (name !== "") {
node.#varIndex = context.varIndex++;
nextNode.#varIndex ??= context.varIndex++;
paramMap.push([name, nextNode.#varIndex]);
}
} else {
nextNode = node.#children[token];
if (!nextNode) {
for (const k in node.#children) {
if (k.length > 1 && k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR) {
throw PATH_ERROR;
}
}
nextNode = node.#children[token] = new _Node();
}
}
if (!pathErrorCheckOnly && name !== "") {
paramMap.push([name, node.#varIndex]);
}
} else {
node = this.#children[token];
if (!node) {
if (Object.keys(this.#children).some(
(k) => k.length > 1 && k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR
)) {
throw PATH_ERROR;
}
if (pathErrorCheckOnly) {
return;
}
node = this.#children[token] = new _Node();
}
node = nextNode;
}
node.insert(restTokens, index, paramMap, context, pathErrorCheckOnly);
if (node.#index !== void 0) {
throw PATH_ERROR;
}
node.#index = isStatic ? -1 : index;
}
buildRegExpStr() {
const childKeys = Object.keys(this.#children).sort(compareKey);
const strList = childKeys.map((k) => {
const c = this.#children[k];
return (typeof c.#varIndex === "number" ? `(${k})@${c.#varIndex}` : regExpMetaChars.has(k) ? `\\${k}` : k) + c.buildRegExpStr();
});
if (typeof this.#index === "number") {
const childStr = c.buildRegExpStr();
return childStr === "" ? "" : (typeof c.#varIndex === "number" ? `(${k})@${c.#varIndex}` : regExpMetaChars.has(k) ? `\\${k}` : k) + childStr;
}).filter(Boolean);
if (typeof this.#index === "number" && this.#index !== -1) {
strList.unshift(`#${this.#index}`);
}
if (strList.length === 0) {
@@ -1552,16 +1608,24 @@ var Node = class _Node {
}
};
// ../../matrix/arcrun/.component-builds/http_request/node_modules/.pnpm/hono@4.12.14/node_modules/hono/dist/router/reg-exp-router/trie.js
// ../arcrun/.component-builds/http_request/node_modules/hono/dist/router/reg-exp-router/trie.js
var Trie = class {
#context = { varIndex: 0 };
#root = new Node();
insert(path, index, pathErrorCheckOnly) {
#index = 0;
// dynamic path -> [handler index, param assoc]; static paths are not registered
paths = /* @__PURE__ */ Object.create(null);
insert(path, isStatic) {
if (isStatic) {
this.#root.insert(path.split(""), 0, [], this.#context, true);
return;
}
const paramAssoc = [];
const groups = [];
let markedPath = path;
for (let i = 0; ; ) {
let replaced = false;
path = path.replace(/\{[^}]+\}/g, (m) => {
markedPath = markedPath.replace(/\{[^}]+\}/g, (m) => {
const mark = `@\\${i}`;
groups[i] = [mark, m];
i++;
@@ -1572,7 +1636,7 @@ var Trie = class {
break;
}
}
const tokens = path.match(/(?::[^\/]+)|(?:\/\*$)|./g) || [];
const tokens = markedPath.match(/(?::[^\/]+)|(?:\/\*$)|./g) || [];
for (let i = groups.length - 1; i >= 0; i--) {
const [mark] = groups[i];
for (let j = tokens.length - 1; j >= 0; j--) {
@@ -1582,8 +1646,8 @@ var Trie = class {
}
}
}
this.#root.insert(tokens, index, paramAssoc, this.#context, pathErrorCheckOnly);
return paramAssoc;
this.#root.insert(tokens, this.#index, paramAssoc, this.#context, false);
this.paths[path] = [this.#index++, paramAssoc];
}
buildRegExp() {
let regexp = this.#root.buildRegExpStr();
@@ -1608,8 +1672,7 @@ var Trie = class {
}
};
// ../../matrix/arcrun/.component-builds/http_request/node_modules/.pnpm/hono@4.12.14/node_modules/hono/dist/router/reg-exp-router/router.js
var nullMatcher = [/^$/, [], /* @__PURE__ */ Object.create(null)];
// ../arcrun/.component-builds/http_request/node_modules/hono/dist/router/reg-exp-router/router.js
var wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
function buildWildcardRegExp(path) {
return wildcardRegExpCache[path] ??= new RegExp(
@@ -1622,63 +1685,6 @@ function buildWildcardRegExp(path) {
function clearWildcardRegExpCache() {
wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
}
function buildMatcherFromPreprocessedRoutes(routes) {
const trie = new Trie();
const handlerData = [];
if (routes.length === 0) {
return nullMatcher;
}
const routesWithStaticPathFlag = routes.map(
(route) => [!/\*|\/:/.test(route[0]), ...route]
).sort(
([isStaticA, pathA], [isStaticB, pathB]) => isStaticA ? 1 : isStaticB ? -1 : pathA.length - pathB.length
);
const staticMap = /* @__PURE__ */ Object.create(null);
for (let i = 0, j = -1, len = routesWithStaticPathFlag.length; i < len; i++) {
const [pathErrorCheckOnly, path, handlers] = routesWithStaticPathFlag[i];
if (pathErrorCheckOnly) {
staticMap[path] = [handlers.map(([h]) => [h, /* @__PURE__ */ Object.create(null)]), emptyParam];
} else {
j++;
}
let paramAssoc;
try {
paramAssoc = trie.insert(path, j, pathErrorCheckOnly);
} catch (e) {
throw e === PATH_ERROR ? new UnsupportedPathError(path) : e;
}
if (pathErrorCheckOnly) {
continue;
}
handlerData[j] = handlers.map(([h, paramCount]) => {
const paramIndexMap = /* @__PURE__ */ Object.create(null);
paramCount -= 1;
for (; paramCount >= 0; paramCount--) {
const [key, value] = paramAssoc[paramCount];
paramIndexMap[key] = value;
}
return [h, paramIndexMap];
});
}
const [regexp, indexReplacementMap, paramReplacementMap] = trie.buildRegExp();
for (let i = 0, len = handlerData.length; i < len; i++) {
for (let j = 0, len2 = handlerData[i].length; j < len2; j++) {
const map = handlerData[i][j]?.[1];
if (!map) {
continue;
}
const keys = Object.keys(map);
for (let k = 0, len3 = keys.length; k < len3; k++) {
map[keys[k]] = paramReplacementMap[map[keys[k]]];
}
}
}
const handlerMap = [];
for (const i in indexReplacementMap) {
handlerMap[i] = handlerData[indexReplacementMap[i]];
}
return [regexp, handlerMap, staticMap];
}
function findMiddleware(middleware, path) {
if (!middleware) {
return void 0;
@@ -1694,9 +1700,18 @@ var RegExpRouter = class {
name = "RegExpRouter";
#middleware;
#routes;
#tries;
constructor() {
this.#middleware = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
this.#routes = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
this.#tries = { [METHOD_NAME_ALL]: new Trie() };
}
#insertPath(method, path) {
try {
this.#tries[method].insert(path, !/\*|\/:/.test(path));
} catch (e) {
throw e === PATH_ERROR ? new UnsupportedPathError(path) : e;
}
}
add(method, path, handler) {
const middleware = this.#middleware;
@@ -1705,11 +1720,12 @@ var RegExpRouter = class {
throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
}
if (!middleware[method]) {
;
this.#tries[method] = new Trie();
[middleware, routes].forEach((handlerMap) => {
handlerMap[method] = /* @__PURE__ */ Object.create(null);
Object.keys(handlerMap[METHOD_NAME_ALL]).forEach((p) => {
handlerMap[method][p] = [...handlerMap[METHOD_NAME_ALL][p]];
this.#insertPath(method, p);
});
});
}
@@ -1719,13 +1735,12 @@ var RegExpRouter = class {
const paramCount = (path.match(/\/:/g) || []).length;
if (/\*$/.test(path)) {
const re = buildWildcardRegExp(path);
if (method === METHOD_NAME_ALL) {
Object.keys(middleware).forEach((m) => {
middleware[m][path] ||= findMiddleware(middleware[m], path) || findMiddleware(middleware[METHOD_NAME_ALL], path) || [];
});
} else {
middleware[method][path] ||= findMiddleware(middleware[method], path) || findMiddleware(middleware[METHOD_NAME_ALL], path) || [];
}
Object.keys(middleware).forEach((m) => {
if ((method === METHOD_NAME_ALL || method === m) && !middleware[m][path]) {
this.#insertPath(m, path);
middleware[m][path] = findMiddleware(middleware[m], path) || findMiddleware(middleware[METHOD_NAME_ALL], path) || [];
}
});
Object.keys(middleware).forEach((m) => {
if (method === METHOD_NAME_ALL || method === m) {
Object.keys(middleware[m]).forEach((p) => {
@@ -1747,9 +1762,12 @@ var RegExpRouter = class {
const path2 = paths[i];
Object.keys(routes).forEach((m) => {
if (method === METHOD_NAME_ALL || method === m) {
routes[m][path2] ||= [
...findMiddleware(middleware[m], path2) || findMiddleware(middleware[METHOD_NAME_ALL], path2) || []
];
if (!routes[m][path2]) {
this.#insertPath(m, path2);
routes[m][path2] = [
...findMiddleware(middleware[m], path2) || findMiddleware(middleware[METHOD_NAME_ALL], path2) || []
];
}
routes[m][path2].push([handler, paramCount - len + i + 1]);
}
});
@@ -1761,33 +1779,58 @@ var RegExpRouter = class {
Object.keys(this.#routes).concat(Object.keys(this.#middleware)).forEach((method) => {
matchers[method] ||= this.#buildMatcher(method);
});
this.#middleware = this.#routes = void 0;
this.#middleware = this.#routes = this.#tries = void 0;
clearWildcardRegExpCache();
return matchers;
}
#buildMatcher(method) {
const routes = [];
let hasOwnRoute = method === METHOD_NAME_ALL;
[this.#middleware, this.#routes].forEach((r) => {
const ownRoute = r[method] ? Object.keys(r[method]).map((path) => [path, r[method][path]]) : [];
if (ownRoute.length !== 0) {
hasOwnRoute ||= true;
routes.push(...ownRoute);
} else if (method !== METHOD_NAME_ALL) {
routes.push(
...Object.keys(r[METHOD_NAME_ALL]).map((path) => [path, r[METHOD_NAME_ALL][path]])
);
const middleware = this.#middleware[method];
const routes = this.#routes[method];
const trie = this.#tries[method];
const staticMap = /* @__PURE__ */ Object.create(null);
const handlerData = [];
[middleware, routes].forEach((r) => {
for (const path in r) {
const handlers = r[path];
const pathData = trie.paths[path];
if (!pathData) {
staticMap[path] = [handlers.map(([h]) => [h, /* @__PURE__ */ Object.create(null)]), emptyParam];
continue;
}
const paramAssoc = pathData[1];
handlerData[pathData[0]] = handlers.map(([h, paramCount]) => {
const paramIndexMap = /* @__PURE__ */ Object.create(null);
paramCount -= 1;
for (; paramCount >= 0; paramCount--) {
const [key, value] = paramAssoc[paramCount];
paramIndexMap[key] = value;
}
return [h, paramIndexMap];
});
}
});
if (!hasOwnRoute) {
return null;
} else {
return buildMatcherFromPreprocessedRoutes(routes);
const [regexp, indexReplacementMap, paramReplacementMap] = trie.buildRegExp();
for (let i = 0, len = handlerData.length; i < len; i++) {
for (let j = 0, len2 = handlerData[i].length; j < len2; j++) {
const map = handlerData[i][j]?.[1];
if (!map) {
continue;
}
const keys = Object.keys(map);
for (let k = 0, len3 = keys.length; k < len3; k++) {
map[keys[k]] = paramReplacementMap[map[keys[k]]];
}
}
}
const handlerMap = [];
for (const i in indexReplacementMap) {
handlerMap[i] = handlerData[indexReplacementMap[i]];
}
return [regexp, handlerMap, staticMap];
}
};
// ../../matrix/arcrun/.component-builds/http_request/node_modules/.pnpm/hono@4.12.14/node_modules/hono/dist/router/smart-router/router.js
// ../arcrun/.component-builds/http_request/node_modules/hono/dist/router/smart-router/router.js
var SmartRouter = class {
name = "SmartRouter";
#routers = [];
@@ -1842,7 +1885,7 @@ var SmartRouter = class {
}
};
// ../../matrix/arcrun/.component-builds/http_request/node_modules/.pnpm/hono@4.12.14/node_modules/hono/dist/router/trie-router/node.js
// ../arcrun/.component-builds/http_request/node_modules/hono/dist/router/trie-router/node.js
var emptyParams = /* @__PURE__ */ Object.create(null);
var hasChildren = (children) => {
for (const _ in children) {
@@ -1976,9 +2019,18 @@ var Node2 = class _Node2 {
if (m) {
params[name] = m[0];
this.#pushHandlerSets(handlerSets, child, method, node.#params, params);
if (m[0].length === restPathString.length && child.#children["*"]) {
this.#pushHandlerSets(
handlerSets,
child.#children["*"],
method,
node.#params,
params
);
}
if (hasChildren(child.#children)) {
child.#params = params;
const componentCount = m[0].match(/\//)?.length ?? 0;
const componentCount = m[0].match(/\//g)?.length ?? 0;
const targetCurNodes = curNodesQueue[componentCount] ||= [];
targetCurNodes.push(child);
}
@@ -2017,7 +2069,7 @@ var Node2 = class _Node2 {
}
};
// ../../matrix/arcrun/.component-builds/http_request/node_modules/.pnpm/hono@4.12.14/node_modules/hono/dist/router/trie-router/router.js
// ../arcrun/.component-builds/http_request/node_modules/hono/dist/router/trie-router/router.js
var TrieRouter = class {
name = "TrieRouter";
#node;
@@ -2039,7 +2091,7 @@ var TrieRouter = class {
}
};
// ../../matrix/arcrun/.component-builds/http_request/node_modules/.pnpm/hono@4.12.14/node_modules/hono/dist/hono.js
// ../arcrun/.component-builds/http_request/node_modules/hono/dist/hono.js
var Hono2 = class extends Hono {
/**
* Creates an instance of the Hono class.
@@ -2054,24 +2106,18 @@ var Hono2 = class extends Hono {
}
};
// ../../matrix/arcrun/.component-builds/http_request/node_modules/.pnpm/hono@4.12.14/node_modules/hono/dist/middleware/cors/index.js
// ../arcrun/.component-builds/http_request/node_modules/hono/dist/middleware/cors/index.js
var cors = (options) => {
const defaults = {
origin: "*",
allowMethods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH"],
allowHeaders: [],
exposeHeaders: []
};
const opts = {
...defaults,
origin: "*",
allowMethods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH", "QUERY"],
allowHeaders: [],
exposeHeaders: [],
...options
};
const findAllowOrigin = ((optsOrigin) => {
if (typeof optsOrigin === "string") {
if (optsOrigin === "*") {
if (opts.credentials) {
return (origin) => origin || null;
}
return () => optsOrigin;
} else {
return (origin) => optsOrigin === origin ? origin : null;
@@ -2106,7 +2152,7 @@ var cors = (options) => {
set("Access-Control-Expose-Headers", opts.exposeHeaders.join(","));
}
if (c.req.method === "OPTIONS") {
if (opts.origin !== "*" || opts.credentials) {
if (opts.origin !== "*") {
set("Vary", "Origin");
}
if (opts.maxAge != null) {
@@ -2120,7 +2166,7 @@ var cors = (options) => {
if (!headers?.length) {
const requestHeaders = c.req.header("Access-Control-Request-Headers");
if (requestHeaders) {
headers = requestHeaders.split(/\s*,\s*/);
headers = requestHeaders.split(",").map((h) => h.trim());
}
}
if (headers?.length) {
@@ -2136,13 +2182,13 @@ var cors = (options) => {
});
}
await next();
if (opts.origin !== "*" || opts.credentials) {
if (opts.origin !== "*") {
c.header("Vary", "Origin", { append: true });
}
};
};
// ../../matrix/arcrun/cypher-executor/src/lib/wasi-shim.ts
// ../arcrun/cypher-executor/src/lib/wasi-shim.ts
var WASI_ESUCCESS = 0;
var WASI_ENOSYS = 76;
var FD_STDIN = 0;
@@ -2501,7 +2547,7 @@ function createWasiShim(stdinData, hostFunctions) {
return shim;
}
// ../../matrix/arcrun/.component-builds/http_request/src/index.ts
// ../arcrun/.component-builds/http_request/src/index.ts
var app = new Hono2();
app.use("*", cors());
app.get("/", (c) => c.json({ ok: true, component: "http_request" }));
@@ -2522,7 +2568,7 @@ app.post("/", async (c) => {
);
}
});
var index_default = app;
var src_default = app;
async function runWasm(input) {
const hostFunctions = {
http_request: async (url, method, headersJson, body) => {
@@ -2568,5 +2614,5 @@ async function runWasm(input) {
return JSON.parse(stdout);
}
export {
index_default as default
src_default as default
};