94eb298c17
來源=Arcrun `batch/step3456-20260801`(eefbed9)=step3 最前緣(已含 step4+step6+
t158-t162)合入 step5。**先合流再打包**(bundle 是 worker 粒度,三步同一顆 cypher,
分開建會讓 stage 只拿到一步——08-01 那個坑)。
cypher 產物指紋(步驟5 新增,實查):
ON_BRANCH 13/ON_TRUE 9/ON_FALSE 11/branch_hint 4
body_template 8/response_map 8/binding_name 4
步驟3/4/6 迴歸指紋(不得歸零,實查全在):
trySubstitution 3/input_schema 6/not_found 5/suggestion 2/success_rate 4/bundle_version 1
mcp 教材世代更新:「引擎不支援條件分支」字串歸 0,換成三型分支寫法+branch_hint 指路。
保留未動(本建置腳本不產這兩顆):tier1/code、tier2/ui、daemon 段(仍 v0.15.0,
這批不含新小幫手,leo 不必重下載)。core 條目維持 24。
順手清掉既存污染:上一版 staging 的 tier1/*/index.js 內含建置機器的絕對路徑
(`/Users/youlinhsieh/...`,19 檔命中)=前次以 symlink node_modules 打包的殘留;
本次改為實體複製 node_modules 後重建,路徑回正常相對形式,命中歸 0。
⚠️ 僅 `tier1/code/index.js` 仍有(該檔本腳本不重建、本次未動),留給產它的那條線處理。
3522 lines
103 KiB
JavaScript
3522 lines
103 KiB
JavaScript
var __defProp = Object.defineProperty;
|
||
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
||
|
||
// node_modules/.pnpm/unenv@2.0.0-rc.24/node_modules/unenv/dist/runtime/_internal/utils.mjs
|
||
// @__NO_SIDE_EFFECTS__
|
||
function createNotImplementedError(name) {
|
||
return new Error(`[unenv] ${name} is not implemented yet!`);
|
||
}
|
||
__name(createNotImplementedError, "createNotImplementedError");
|
||
// @__NO_SIDE_EFFECTS__
|
||
function notImplemented(name) {
|
||
const fn = /* @__PURE__ */ __name(() => {
|
||
throw /* @__PURE__ */ createNotImplementedError(name);
|
||
}, "fn");
|
||
return Object.assign(fn, { __unenv__: true });
|
||
}
|
||
__name(notImplemented, "notImplemented");
|
||
// @__NO_SIDE_EFFECTS__
|
||
function notImplementedClass(name) {
|
||
return class {
|
||
__unenv__ = true;
|
||
constructor() {
|
||
throw new Error(`[unenv] ${name} is not implemented yet!`);
|
||
}
|
||
};
|
||
}
|
||
__name(notImplementedClass, "notImplementedClass");
|
||
|
||
// node_modules/.pnpm/unenv@2.0.0-rc.24/node_modules/unenv/dist/runtime/node/internal/perf_hooks/performance.mjs
|
||
var _timeOrigin = globalThis.performance?.timeOrigin ?? Date.now();
|
||
var _performanceNow = globalThis.performance?.now ? globalThis.performance.now.bind(globalThis.performance) : () => Date.now() - _timeOrigin;
|
||
var nodeTiming = {
|
||
name: "node",
|
||
entryType: "node",
|
||
startTime: 0,
|
||
duration: 0,
|
||
nodeStart: 0,
|
||
v8Start: 0,
|
||
bootstrapComplete: 0,
|
||
environment: 0,
|
||
loopStart: 0,
|
||
loopExit: 0,
|
||
idleTime: 0,
|
||
uvMetricsInfo: {
|
||
loopCount: 0,
|
||
events: 0,
|
||
eventsWaiting: 0
|
||
},
|
||
detail: void 0,
|
||
toJSON() {
|
||
return this;
|
||
}
|
||
};
|
||
var PerformanceEntry = class {
|
||
static {
|
||
__name(this, "PerformanceEntry");
|
||
}
|
||
__unenv__ = true;
|
||
detail;
|
||
entryType = "event";
|
||
name;
|
||
startTime;
|
||
constructor(name, options) {
|
||
this.name = name;
|
||
this.startTime = options?.startTime || _performanceNow();
|
||
this.detail = options?.detail;
|
||
}
|
||
get duration() {
|
||
return _performanceNow() - this.startTime;
|
||
}
|
||
toJSON() {
|
||
return {
|
||
name: this.name,
|
||
entryType: this.entryType,
|
||
startTime: this.startTime,
|
||
duration: this.duration,
|
||
detail: this.detail
|
||
};
|
||
}
|
||
};
|
||
var PerformanceMark = class PerformanceMark2 extends PerformanceEntry {
|
||
static {
|
||
__name(this, "PerformanceMark");
|
||
}
|
||
entryType = "mark";
|
||
constructor() {
|
||
super(...arguments);
|
||
}
|
||
get duration() {
|
||
return 0;
|
||
}
|
||
};
|
||
var PerformanceMeasure = class extends PerformanceEntry {
|
||
static {
|
||
__name(this, "PerformanceMeasure");
|
||
}
|
||
entryType = "measure";
|
||
};
|
||
var PerformanceResourceTiming = class extends PerformanceEntry {
|
||
static {
|
||
__name(this, "PerformanceResourceTiming");
|
||
}
|
||
entryType = "resource";
|
||
serverTiming = [];
|
||
connectEnd = 0;
|
||
connectStart = 0;
|
||
decodedBodySize = 0;
|
||
domainLookupEnd = 0;
|
||
domainLookupStart = 0;
|
||
encodedBodySize = 0;
|
||
fetchStart = 0;
|
||
initiatorType = "";
|
||
name = "";
|
||
nextHopProtocol = "";
|
||
redirectEnd = 0;
|
||
redirectStart = 0;
|
||
requestStart = 0;
|
||
responseEnd = 0;
|
||
responseStart = 0;
|
||
secureConnectionStart = 0;
|
||
startTime = 0;
|
||
transferSize = 0;
|
||
workerStart = 0;
|
||
responseStatus = 0;
|
||
};
|
||
var PerformanceObserverEntryList = class {
|
||
static {
|
||
__name(this, "PerformanceObserverEntryList");
|
||
}
|
||
__unenv__ = true;
|
||
getEntries() {
|
||
return [];
|
||
}
|
||
getEntriesByName(_name, _type) {
|
||
return [];
|
||
}
|
||
getEntriesByType(type) {
|
||
return [];
|
||
}
|
||
};
|
||
var Performance = class {
|
||
static {
|
||
__name(this, "Performance");
|
||
}
|
||
__unenv__ = true;
|
||
timeOrigin = _timeOrigin;
|
||
eventCounts = /* @__PURE__ */ new Map();
|
||
_entries = [];
|
||
_resourceTimingBufferSize = 0;
|
||
navigation = void 0;
|
||
timing = void 0;
|
||
timerify(_fn, _options) {
|
||
throw createNotImplementedError("Performance.timerify");
|
||
}
|
||
get nodeTiming() {
|
||
return nodeTiming;
|
||
}
|
||
eventLoopUtilization() {
|
||
return {};
|
||
}
|
||
markResourceTiming() {
|
||
return new PerformanceResourceTiming("");
|
||
}
|
||
onresourcetimingbufferfull = null;
|
||
now() {
|
||
if (this.timeOrigin === _timeOrigin) {
|
||
return _performanceNow();
|
||
}
|
||
return Date.now() - this.timeOrigin;
|
||
}
|
||
clearMarks(markName) {
|
||
this._entries = markName ? this._entries.filter((e) => e.name !== markName) : this._entries.filter((e) => e.entryType !== "mark");
|
||
}
|
||
clearMeasures(measureName) {
|
||
this._entries = measureName ? this._entries.filter((e) => e.name !== measureName) : this._entries.filter((e) => e.entryType !== "measure");
|
||
}
|
||
clearResourceTimings() {
|
||
this._entries = this._entries.filter((e) => e.entryType !== "resource" || e.entryType !== "navigation");
|
||
}
|
||
getEntries() {
|
||
return this._entries;
|
||
}
|
||
getEntriesByName(name, type) {
|
||
return this._entries.filter((e) => e.name === name && (!type || e.entryType === type));
|
||
}
|
||
getEntriesByType(type) {
|
||
return this._entries.filter((e) => e.entryType === type);
|
||
}
|
||
mark(name, options) {
|
||
const entry = new PerformanceMark(name, options);
|
||
this._entries.push(entry);
|
||
return entry;
|
||
}
|
||
measure(measureName, startOrMeasureOptions, endMark) {
|
||
let start;
|
||
let end;
|
||
if (typeof startOrMeasureOptions === "string") {
|
||
start = this.getEntriesByName(startOrMeasureOptions, "mark")[0]?.startTime;
|
||
end = this.getEntriesByName(endMark, "mark")[0]?.startTime;
|
||
} else {
|
||
start = Number.parseFloat(startOrMeasureOptions?.start) || this.now();
|
||
end = Number.parseFloat(startOrMeasureOptions?.end) || this.now();
|
||
}
|
||
const entry = new PerformanceMeasure(measureName, {
|
||
startTime: start,
|
||
detail: {
|
||
start,
|
||
end
|
||
}
|
||
});
|
||
this._entries.push(entry);
|
||
return entry;
|
||
}
|
||
setResourceTimingBufferSize(maxSize) {
|
||
this._resourceTimingBufferSize = maxSize;
|
||
}
|
||
addEventListener(type, listener, options) {
|
||
throw createNotImplementedError("Performance.addEventListener");
|
||
}
|
||
removeEventListener(type, listener, options) {
|
||
throw createNotImplementedError("Performance.removeEventListener");
|
||
}
|
||
dispatchEvent(event) {
|
||
throw createNotImplementedError("Performance.dispatchEvent");
|
||
}
|
||
toJSON() {
|
||
return this;
|
||
}
|
||
};
|
||
var PerformanceObserver = class {
|
||
static {
|
||
__name(this, "PerformanceObserver");
|
||
}
|
||
__unenv__ = true;
|
||
static supportedEntryTypes = [];
|
||
_callback = null;
|
||
constructor(callback) {
|
||
this._callback = callback;
|
||
}
|
||
takeRecords() {
|
||
return [];
|
||
}
|
||
disconnect() {
|
||
throw createNotImplementedError("PerformanceObserver.disconnect");
|
||
}
|
||
observe(options) {
|
||
throw createNotImplementedError("PerformanceObserver.observe");
|
||
}
|
||
bind(fn) {
|
||
return fn;
|
||
}
|
||
runInAsyncScope(fn, thisArg, ...args) {
|
||
return fn.call(thisArg, ...args);
|
||
}
|
||
asyncId() {
|
||
return 0;
|
||
}
|
||
triggerAsyncId() {
|
||
return 0;
|
||
}
|
||
emitDestroy() {
|
||
return this;
|
||
}
|
||
};
|
||
var performance = globalThis.performance && "addEventListener" in globalThis.performance ? globalThis.performance : new Performance();
|
||
|
||
// node_modules/.pnpm/@cloudflare+unenv-preset@2.16.0_unenv@2.0.0-rc.24_workerd@1.20260415.1/node_modules/@cloudflare/unenv-preset/dist/runtime/polyfill/performance.mjs
|
||
if (!("__unenv__" in performance)) {
|
||
const proto = Performance.prototype;
|
||
for (const key of Object.getOwnPropertyNames(proto)) {
|
||
if (key !== "constructor" && !(key in performance)) {
|
||
const desc = Object.getOwnPropertyDescriptor(proto, key);
|
||
if (desc) {
|
||
Object.defineProperty(performance, key, desc);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
globalThis.performance = performance;
|
||
globalThis.Performance = Performance;
|
||
globalThis.PerformanceEntry = PerformanceEntry;
|
||
globalThis.PerformanceMark = PerformanceMark;
|
||
globalThis.PerformanceMeasure = PerformanceMeasure;
|
||
globalThis.PerformanceObserver = PerformanceObserver;
|
||
globalThis.PerformanceObserverEntryList = PerformanceObserverEntryList;
|
||
globalThis.PerformanceResourceTiming = PerformanceResourceTiming;
|
||
|
||
// node_modules/.pnpm/unenv@2.0.0-rc.24/node_modules/unenv/dist/runtime/node/console.mjs
|
||
import { Writable } from "node:stream";
|
||
|
||
// node_modules/.pnpm/unenv@2.0.0-rc.24/node_modules/unenv/dist/runtime/mock/noop.mjs
|
||
var noop_default = Object.assign(() => {
|
||
}, { __unenv__: true });
|
||
|
||
// node_modules/.pnpm/unenv@2.0.0-rc.24/node_modules/unenv/dist/runtime/node/console.mjs
|
||
var _console = globalThis.console;
|
||
var _ignoreErrors = true;
|
||
var _stderr = new Writable();
|
||
var _stdout = new Writable();
|
||
var log = _console?.log ?? noop_default;
|
||
var info = _console?.info ?? log;
|
||
var trace = _console?.trace ?? info;
|
||
var debug = _console?.debug ?? log;
|
||
var table = _console?.table ?? log;
|
||
var error = _console?.error ?? log;
|
||
var warn = _console?.warn ?? error;
|
||
var createTask = _console?.createTask ?? /* @__PURE__ */ notImplemented("console.createTask");
|
||
var clear = _console?.clear ?? noop_default;
|
||
var count = _console?.count ?? noop_default;
|
||
var countReset = _console?.countReset ?? noop_default;
|
||
var dir = _console?.dir ?? noop_default;
|
||
var dirxml = _console?.dirxml ?? noop_default;
|
||
var group = _console?.group ?? noop_default;
|
||
var groupEnd = _console?.groupEnd ?? noop_default;
|
||
var groupCollapsed = _console?.groupCollapsed ?? noop_default;
|
||
var profile = _console?.profile ?? noop_default;
|
||
var profileEnd = _console?.profileEnd ?? noop_default;
|
||
var time = _console?.time ?? noop_default;
|
||
var timeEnd = _console?.timeEnd ?? noop_default;
|
||
var timeLog = _console?.timeLog ?? noop_default;
|
||
var timeStamp = _console?.timeStamp ?? noop_default;
|
||
var Console = _console?.Console ?? /* @__PURE__ */ notImplementedClass("console.Console");
|
||
var _times = /* @__PURE__ */ new Map();
|
||
var _stdoutErrorHandler = noop_default;
|
||
var _stderrErrorHandler = noop_default;
|
||
|
||
// node_modules/.pnpm/@cloudflare+unenv-preset@2.16.0_unenv@2.0.0-rc.24_workerd@1.20260415.1/node_modules/@cloudflare/unenv-preset/dist/runtime/node/console.mjs
|
||
var workerdConsole = globalThis["console"];
|
||
var {
|
||
assert,
|
||
clear: clear2,
|
||
// @ts-expect-error undocumented public API
|
||
context,
|
||
count: count2,
|
||
countReset: countReset2,
|
||
// @ts-expect-error undocumented public API
|
||
createTask: createTask2,
|
||
debug: debug2,
|
||
dir: dir2,
|
||
dirxml: dirxml2,
|
||
error: error2,
|
||
group: group2,
|
||
groupCollapsed: groupCollapsed2,
|
||
groupEnd: groupEnd2,
|
||
info: info2,
|
||
log: log2,
|
||
profile: profile2,
|
||
profileEnd: profileEnd2,
|
||
table: table2,
|
||
time: time2,
|
||
timeEnd: timeEnd2,
|
||
timeLog: timeLog2,
|
||
timeStamp: timeStamp2,
|
||
trace: trace2,
|
||
warn: warn2
|
||
} = workerdConsole;
|
||
Object.assign(workerdConsole, {
|
||
Console,
|
||
_ignoreErrors,
|
||
_stderr,
|
||
_stderrErrorHandler,
|
||
_stdout,
|
||
_stdoutErrorHandler,
|
||
_times
|
||
});
|
||
var console_default = workerdConsole;
|
||
|
||
// node_modules/.pnpm/wrangler@4.83.0_@cloudflare+workers-types@4.20260420.1/node_modules/wrangler/_virtual_unenv_global_polyfill-@cloudflare-unenv-preset-node-console
|
||
globalThis.console = console_default;
|
||
|
||
// node_modules/.pnpm/unenv@2.0.0-rc.24/node_modules/unenv/dist/runtime/node/internal/process/hrtime.mjs
|
||
var hrtime = /* @__PURE__ */ Object.assign(/* @__PURE__ */ __name(function hrtime2(startTime) {
|
||
const now = Date.now();
|
||
const seconds = Math.trunc(now / 1e3);
|
||
const nanos = now % 1e3 * 1e6;
|
||
if (startTime) {
|
||
let diffSeconds = seconds - startTime[0];
|
||
let diffNanos = nanos - startTime[0];
|
||
if (diffNanos < 0) {
|
||
diffSeconds = diffSeconds - 1;
|
||
diffNanos = 1e9 + diffNanos;
|
||
}
|
||
return [diffSeconds, diffNanos];
|
||
}
|
||
return [seconds, nanos];
|
||
}, "hrtime"), { bigint: /* @__PURE__ */ __name(function bigint() {
|
||
return BigInt(Date.now() * 1e6);
|
||
}, "bigint") });
|
||
|
||
// node_modules/.pnpm/unenv@2.0.0-rc.24/node_modules/unenv/dist/runtime/node/internal/process/process.mjs
|
||
import { EventEmitter } from "node:events";
|
||
|
||
// node_modules/.pnpm/unenv@2.0.0-rc.24/node_modules/unenv/dist/runtime/node/internal/tty/read-stream.mjs
|
||
var ReadStream = class {
|
||
static {
|
||
__name(this, "ReadStream");
|
||
}
|
||
fd;
|
||
isRaw = false;
|
||
isTTY = false;
|
||
constructor(fd) {
|
||
this.fd = fd;
|
||
}
|
||
setRawMode(mode) {
|
||
this.isRaw = mode;
|
||
return this;
|
||
}
|
||
};
|
||
|
||
// node_modules/.pnpm/unenv@2.0.0-rc.24/node_modules/unenv/dist/runtime/node/internal/tty/write-stream.mjs
|
||
var WriteStream = class {
|
||
static {
|
||
__name(this, "WriteStream");
|
||
}
|
||
fd;
|
||
columns = 80;
|
||
rows = 24;
|
||
isTTY = false;
|
||
constructor(fd) {
|
||
this.fd = fd;
|
||
}
|
||
clearLine(dir3, callback) {
|
||
callback && callback();
|
||
return false;
|
||
}
|
||
clearScreenDown(callback) {
|
||
callback && callback();
|
||
return false;
|
||
}
|
||
cursorTo(x, y, callback) {
|
||
callback && typeof callback === "function" && callback();
|
||
return false;
|
||
}
|
||
moveCursor(dx, dy, callback) {
|
||
callback && callback();
|
||
return false;
|
||
}
|
||
getColorDepth(env2) {
|
||
return 1;
|
||
}
|
||
hasColors(count3, env2) {
|
||
return false;
|
||
}
|
||
getWindowSize() {
|
||
return [this.columns, this.rows];
|
||
}
|
||
write(str, encoding, cb) {
|
||
if (str instanceof Uint8Array) {
|
||
str = new TextDecoder().decode(str);
|
||
}
|
||
try {
|
||
console.log(str);
|
||
} catch {
|
||
}
|
||
cb && typeof cb === "function" && cb();
|
||
return false;
|
||
}
|
||
};
|
||
|
||
// node_modules/.pnpm/unenv@2.0.0-rc.24/node_modules/unenv/dist/runtime/node/internal/process/node-version.mjs
|
||
var NODE_VERSION = "22.14.0";
|
||
|
||
// node_modules/.pnpm/unenv@2.0.0-rc.24/node_modules/unenv/dist/runtime/node/internal/process/process.mjs
|
||
var Process = class _Process extends EventEmitter {
|
||
static {
|
||
__name(this, "Process");
|
||
}
|
||
env;
|
||
hrtime;
|
||
nextTick;
|
||
constructor(impl) {
|
||
super();
|
||
this.env = impl.env;
|
||
this.hrtime = impl.hrtime;
|
||
this.nextTick = impl.nextTick;
|
||
for (const prop of [...Object.getOwnPropertyNames(_Process.prototype), ...Object.getOwnPropertyNames(EventEmitter.prototype)]) {
|
||
const value = this[prop];
|
||
if (typeof value === "function") {
|
||
this[prop] = value.bind(this);
|
||
}
|
||
}
|
||
}
|
||
// --- event emitter ---
|
||
emitWarning(warning, type, code) {
|
||
console.warn(`${code ? `[${code}] ` : ""}${type ? `${type}: ` : ""}${warning}`);
|
||
}
|
||
emit(...args) {
|
||
return super.emit(...args);
|
||
}
|
||
listeners(eventName) {
|
||
return super.listeners(eventName);
|
||
}
|
||
// --- stdio (lazy initializers) ---
|
||
#stdin;
|
||
#stdout;
|
||
#stderr;
|
||
get stdin() {
|
||
return this.#stdin ??= new ReadStream(0);
|
||
}
|
||
get stdout() {
|
||
return this.#stdout ??= new WriteStream(1);
|
||
}
|
||
get stderr() {
|
||
return this.#stderr ??= new WriteStream(2);
|
||
}
|
||
// --- cwd ---
|
||
#cwd = "/";
|
||
chdir(cwd2) {
|
||
this.#cwd = cwd2;
|
||
}
|
||
cwd() {
|
||
return this.#cwd;
|
||
}
|
||
// --- dummy props and getters ---
|
||
arch = "";
|
||
platform = "";
|
||
argv = [];
|
||
argv0 = "";
|
||
execArgv = [];
|
||
execPath = "";
|
||
title = "";
|
||
pid = 200;
|
||
ppid = 100;
|
||
get version() {
|
||
return `v${NODE_VERSION}`;
|
||
}
|
||
get versions() {
|
||
return { node: NODE_VERSION };
|
||
}
|
||
get allowedNodeEnvironmentFlags() {
|
||
return /* @__PURE__ */ new Set();
|
||
}
|
||
get sourceMapsEnabled() {
|
||
return false;
|
||
}
|
||
get debugPort() {
|
||
return 0;
|
||
}
|
||
get throwDeprecation() {
|
||
return false;
|
||
}
|
||
get traceDeprecation() {
|
||
return false;
|
||
}
|
||
get features() {
|
||
return {};
|
||
}
|
||
get release() {
|
||
return {};
|
||
}
|
||
get connected() {
|
||
return false;
|
||
}
|
||
get config() {
|
||
return {};
|
||
}
|
||
get moduleLoadList() {
|
||
return [];
|
||
}
|
||
constrainedMemory() {
|
||
return 0;
|
||
}
|
||
availableMemory() {
|
||
return 0;
|
||
}
|
||
uptime() {
|
||
return 0;
|
||
}
|
||
resourceUsage() {
|
||
return {};
|
||
}
|
||
// --- noop methods ---
|
||
ref() {
|
||
}
|
||
unref() {
|
||
}
|
||
// --- unimplemented methods ---
|
||
umask() {
|
||
throw createNotImplementedError("process.umask");
|
||
}
|
||
getBuiltinModule() {
|
||
return void 0;
|
||
}
|
||
getActiveResourcesInfo() {
|
||
throw createNotImplementedError("process.getActiveResourcesInfo");
|
||
}
|
||
exit() {
|
||
throw createNotImplementedError("process.exit");
|
||
}
|
||
reallyExit() {
|
||
throw createNotImplementedError("process.reallyExit");
|
||
}
|
||
kill() {
|
||
throw createNotImplementedError("process.kill");
|
||
}
|
||
abort() {
|
||
throw createNotImplementedError("process.abort");
|
||
}
|
||
dlopen() {
|
||
throw createNotImplementedError("process.dlopen");
|
||
}
|
||
setSourceMapsEnabled() {
|
||
throw createNotImplementedError("process.setSourceMapsEnabled");
|
||
}
|
||
loadEnvFile() {
|
||
throw createNotImplementedError("process.loadEnvFile");
|
||
}
|
||
disconnect() {
|
||
throw createNotImplementedError("process.disconnect");
|
||
}
|
||
cpuUsage() {
|
||
throw createNotImplementedError("process.cpuUsage");
|
||
}
|
||
setUncaughtExceptionCaptureCallback() {
|
||
throw createNotImplementedError("process.setUncaughtExceptionCaptureCallback");
|
||
}
|
||
hasUncaughtExceptionCaptureCallback() {
|
||
throw createNotImplementedError("process.hasUncaughtExceptionCaptureCallback");
|
||
}
|
||
initgroups() {
|
||
throw createNotImplementedError("process.initgroups");
|
||
}
|
||
openStdin() {
|
||
throw createNotImplementedError("process.openStdin");
|
||
}
|
||
assert() {
|
||
throw createNotImplementedError("process.assert");
|
||
}
|
||
binding() {
|
||
throw createNotImplementedError("process.binding");
|
||
}
|
||
// --- attached interfaces ---
|
||
permission = { has: /* @__PURE__ */ notImplemented("process.permission.has") };
|
||
report = {
|
||
directory: "",
|
||
filename: "",
|
||
signal: "SIGUSR2",
|
||
compact: false,
|
||
reportOnFatalError: false,
|
||
reportOnSignal: false,
|
||
reportOnUncaughtException: false,
|
||
getReport: /* @__PURE__ */ notImplemented("process.report.getReport"),
|
||
writeReport: /* @__PURE__ */ notImplemented("process.report.writeReport")
|
||
};
|
||
finalization = {
|
||
register: /* @__PURE__ */ notImplemented("process.finalization.register"),
|
||
unregister: /* @__PURE__ */ notImplemented("process.finalization.unregister"),
|
||
registerBeforeExit: /* @__PURE__ */ notImplemented("process.finalization.registerBeforeExit")
|
||
};
|
||
memoryUsage = Object.assign(() => ({
|
||
arrayBuffers: 0,
|
||
rss: 0,
|
||
external: 0,
|
||
heapTotal: 0,
|
||
heapUsed: 0
|
||
}), { rss: /* @__PURE__ */ __name(() => 0, "rss") });
|
||
// --- undefined props ---
|
||
mainModule = void 0;
|
||
domain = void 0;
|
||
// optional
|
||
send = void 0;
|
||
exitCode = void 0;
|
||
channel = void 0;
|
||
getegid = void 0;
|
||
geteuid = void 0;
|
||
getgid = void 0;
|
||
getgroups = void 0;
|
||
getuid = void 0;
|
||
setegid = void 0;
|
||
seteuid = void 0;
|
||
setgid = void 0;
|
||
setgroups = void 0;
|
||
setuid = void 0;
|
||
// internals
|
||
_events = void 0;
|
||
_eventsCount = void 0;
|
||
_exiting = void 0;
|
||
_maxListeners = void 0;
|
||
_debugEnd = void 0;
|
||
_debugProcess = void 0;
|
||
_fatalException = void 0;
|
||
_getActiveHandles = void 0;
|
||
_getActiveRequests = void 0;
|
||
_kill = void 0;
|
||
_preload_modules = void 0;
|
||
_rawDebug = void 0;
|
||
_startProfilerIdleNotifier = void 0;
|
||
_stopProfilerIdleNotifier = void 0;
|
||
_tickCallback = void 0;
|
||
_disconnect = void 0;
|
||
_handleQueue = void 0;
|
||
_pendingMessage = void 0;
|
||
_channel = void 0;
|
||
_send = void 0;
|
||
_linkedBinding = void 0;
|
||
};
|
||
|
||
// node_modules/.pnpm/@cloudflare+unenv-preset@2.16.0_unenv@2.0.0-rc.24_workerd@1.20260415.1/node_modules/@cloudflare/unenv-preset/dist/runtime/node/process.mjs
|
||
var globalProcess = globalThis["process"];
|
||
var getBuiltinModule = globalProcess.getBuiltinModule;
|
||
var workerdProcess = getBuiltinModule("node:process");
|
||
var unenvProcess = new Process({
|
||
env: globalProcess.env,
|
||
hrtime,
|
||
// `nextTick` is available from workerd process v1
|
||
nextTick: workerdProcess.nextTick
|
||
});
|
||
var { exit, features, platform } = workerdProcess;
|
||
var {
|
||
_channel,
|
||
_debugEnd,
|
||
_debugProcess,
|
||
_disconnect,
|
||
_events,
|
||
_eventsCount,
|
||
_exiting,
|
||
_fatalException,
|
||
_getActiveHandles,
|
||
_getActiveRequests,
|
||
_handleQueue,
|
||
_kill,
|
||
_linkedBinding,
|
||
_maxListeners,
|
||
_pendingMessage,
|
||
_preload_modules,
|
||
_rawDebug,
|
||
_send,
|
||
_startProfilerIdleNotifier,
|
||
_stopProfilerIdleNotifier,
|
||
_tickCallback,
|
||
abort,
|
||
addListener,
|
||
allowedNodeEnvironmentFlags,
|
||
arch,
|
||
argv,
|
||
argv0,
|
||
assert: assert2,
|
||
availableMemory,
|
||
binding,
|
||
channel,
|
||
chdir,
|
||
config,
|
||
connected,
|
||
constrainedMemory,
|
||
cpuUsage,
|
||
cwd,
|
||
debugPort,
|
||
disconnect,
|
||
dlopen,
|
||
domain,
|
||
emit,
|
||
emitWarning,
|
||
env,
|
||
eventNames,
|
||
execArgv,
|
||
execPath,
|
||
exitCode,
|
||
finalization,
|
||
getActiveResourcesInfo,
|
||
getegid,
|
||
geteuid,
|
||
getgid,
|
||
getgroups,
|
||
getMaxListeners,
|
||
getuid,
|
||
hasUncaughtExceptionCaptureCallback,
|
||
hrtime: hrtime3,
|
||
initgroups,
|
||
kill,
|
||
listenerCount,
|
||
listeners,
|
||
loadEnvFile,
|
||
mainModule,
|
||
memoryUsage,
|
||
moduleLoadList,
|
||
nextTick,
|
||
off,
|
||
on,
|
||
once,
|
||
openStdin,
|
||
permission,
|
||
pid,
|
||
ppid,
|
||
prependListener,
|
||
prependOnceListener,
|
||
rawListeners,
|
||
reallyExit,
|
||
ref,
|
||
release,
|
||
removeAllListeners,
|
||
removeListener,
|
||
report,
|
||
resourceUsage,
|
||
send,
|
||
setegid,
|
||
seteuid,
|
||
setgid,
|
||
setgroups,
|
||
setMaxListeners,
|
||
setSourceMapsEnabled,
|
||
setuid,
|
||
setUncaughtExceptionCaptureCallback,
|
||
sourceMapsEnabled,
|
||
stderr,
|
||
stdin,
|
||
stdout,
|
||
throwDeprecation,
|
||
title,
|
||
traceDeprecation,
|
||
umask,
|
||
unref,
|
||
uptime,
|
||
version,
|
||
versions
|
||
} = unenvProcess;
|
||
var _process = {
|
||
abort,
|
||
addListener,
|
||
allowedNodeEnvironmentFlags,
|
||
hasUncaughtExceptionCaptureCallback,
|
||
setUncaughtExceptionCaptureCallback,
|
||
loadEnvFile,
|
||
sourceMapsEnabled,
|
||
arch,
|
||
argv,
|
||
argv0,
|
||
chdir,
|
||
config,
|
||
connected,
|
||
constrainedMemory,
|
||
availableMemory,
|
||
cpuUsage,
|
||
cwd,
|
||
debugPort,
|
||
dlopen,
|
||
disconnect,
|
||
emit,
|
||
emitWarning,
|
||
env,
|
||
eventNames,
|
||
execArgv,
|
||
execPath,
|
||
exit,
|
||
finalization,
|
||
features,
|
||
getBuiltinModule,
|
||
getActiveResourcesInfo,
|
||
getMaxListeners,
|
||
hrtime: hrtime3,
|
||
kill,
|
||
listeners,
|
||
listenerCount,
|
||
memoryUsage,
|
||
nextTick,
|
||
on,
|
||
off,
|
||
once,
|
||
pid,
|
||
platform,
|
||
ppid,
|
||
prependListener,
|
||
prependOnceListener,
|
||
rawListeners,
|
||
release,
|
||
removeAllListeners,
|
||
removeListener,
|
||
report,
|
||
resourceUsage,
|
||
setMaxListeners,
|
||
setSourceMapsEnabled,
|
||
stderr,
|
||
stdin,
|
||
stdout,
|
||
title,
|
||
throwDeprecation,
|
||
traceDeprecation,
|
||
umask,
|
||
uptime,
|
||
version,
|
||
versions,
|
||
// @ts-expect-error old API
|
||
domain,
|
||
initgroups,
|
||
moduleLoadList,
|
||
reallyExit,
|
||
openStdin,
|
||
assert: assert2,
|
||
binding,
|
||
send,
|
||
exitCode,
|
||
channel,
|
||
getegid,
|
||
geteuid,
|
||
getgid,
|
||
getgroups,
|
||
getuid,
|
||
setegid,
|
||
seteuid,
|
||
setgid,
|
||
setgroups,
|
||
setuid,
|
||
permission,
|
||
mainModule,
|
||
_events,
|
||
_eventsCount,
|
||
_exiting,
|
||
_maxListeners,
|
||
_debugEnd,
|
||
_debugProcess,
|
||
_fatalException,
|
||
_getActiveHandles,
|
||
_getActiveRequests,
|
||
_kill,
|
||
_preload_modules,
|
||
_rawDebug,
|
||
_startProfilerIdleNotifier,
|
||
_stopProfilerIdleNotifier,
|
||
_tickCallback,
|
||
_disconnect,
|
||
_handleQueue,
|
||
_pendingMessage,
|
||
_channel,
|
||
_send,
|
||
_linkedBinding
|
||
};
|
||
var process_default = _process;
|
||
|
||
// node_modules/.pnpm/wrangler@4.83.0_@cloudflare+workers-types@4.20260420.1/node_modules/wrangler/_virtual_unenv_global_polyfill-@cloudflare-unenv-preset-node-process
|
||
globalThis.process = process_default;
|
||
|
||
// src/index.ts
|
||
import componentWasm from "./cfef89ca6e0f809fe5774d8e3db5e48222abb7f6-component.wasm";
|
||
|
||
// node_modules/.pnpm/hono@4.12.14/node_modules/hono/dist/compose.js
|
||
var compose = /* @__PURE__ */ __name((middleware, onError, onNotFound) => {
|
||
return (context2, next) => {
|
||
let index = -1;
|
||
return dispatch(0);
|
||
async function dispatch(i) {
|
||
if (i <= index) {
|
||
throw new Error("next() called multiple times");
|
||
}
|
||
index = i;
|
||
let res;
|
||
let isError = false;
|
||
let handler;
|
||
if (middleware[i]) {
|
||
handler = middleware[i][0][0];
|
||
context2.req.routeIndex = i;
|
||
} else {
|
||
handler = i === middleware.length && next || void 0;
|
||
}
|
||
if (handler) {
|
||
try {
|
||
res = await handler(context2, () => dispatch(i + 1));
|
||
} catch (err) {
|
||
if (err instanceof Error && onError) {
|
||
context2.error = err;
|
||
res = await onError(err, context2);
|
||
isError = true;
|
||
} else {
|
||
throw err;
|
||
}
|
||
}
|
||
} else {
|
||
if (context2.finalized === false && onNotFound) {
|
||
res = await onNotFound(context2);
|
||
}
|
||
}
|
||
if (res && (context2.finalized === false || isError)) {
|
||
context2.res = res;
|
||
}
|
||
return context2;
|
||
}
|
||
__name(dispatch, "dispatch");
|
||
};
|
||
}, "compose");
|
||
|
||
// node_modules/.pnpm/hono@4.12.14/node_modules/hono/dist/request/constants.js
|
||
var GET_MATCH_RESULT = /* @__PURE__ */ Symbol();
|
||
|
||
// node_modules/.pnpm/hono@4.12.14/node_modules/hono/dist/utils/body.js
|
||
var parseBody = /* @__PURE__ */ __name(async (request, options = /* @__PURE__ */ Object.create(null)) => {
|
||
const { all = false, dot = false } = options;
|
||
const headers = request instanceof HonoRequest ? request.raw.headers : request.headers;
|
||
const contentType = headers.get("Content-Type");
|
||
if (contentType?.startsWith("multipart/form-data") || contentType?.startsWith("application/x-www-form-urlencoded")) {
|
||
return parseFormData(request, { all, dot });
|
||
}
|
||
return {};
|
||
}, "parseBody");
|
||
async function parseFormData(request, options) {
|
||
const formData = await request.formData();
|
||
if (formData) {
|
||
return convertFormDataToBodyData(formData, options);
|
||
}
|
||
return {};
|
||
}
|
||
__name(parseFormData, "parseFormData");
|
||
function convertFormDataToBodyData(formData, options) {
|
||
const form = /* @__PURE__ */ Object.create(null);
|
||
formData.forEach((value, key) => {
|
||
const shouldParseAllValues = options.all || key.endsWith("[]");
|
||
if (!shouldParseAllValues) {
|
||
form[key] = value;
|
||
} else {
|
||
handleParsingAllValues(form, key, value);
|
||
}
|
||
});
|
||
if (options.dot) {
|
||
Object.entries(form).forEach(([key, value]) => {
|
||
const shouldParseDotValues = key.includes(".");
|
||
if (shouldParseDotValues) {
|
||
handleParsingNestedValues(form, key, value);
|
||
delete form[key];
|
||
}
|
||
});
|
||
}
|
||
return form;
|
||
}
|
||
__name(convertFormDataToBodyData, "convertFormDataToBodyData");
|
||
var handleParsingAllValues = /* @__PURE__ */ __name((form, key, value) => {
|
||
if (form[key] !== void 0) {
|
||
if (Array.isArray(form[key])) {
|
||
;
|
||
form[key].push(value);
|
||
} else {
|
||
form[key] = [form[key], value];
|
||
}
|
||
} else {
|
||
if (!key.endsWith("[]")) {
|
||
form[key] = value;
|
||
} else {
|
||
form[key] = [value];
|
||
}
|
||
}
|
||
}, "handleParsingAllValues");
|
||
var handleParsingNestedValues = /* @__PURE__ */ __name((form, key, value) => {
|
||
if (/(?:^|\.)__proto__\./.test(key)) {
|
||
return;
|
||
}
|
||
let nestedForm = form;
|
||
const keys = key.split(".");
|
||
keys.forEach((key2, index) => {
|
||
if (index === keys.length - 1) {
|
||
nestedForm[key2] = value;
|
||
} else {
|
||
if (!nestedForm[key2] || typeof nestedForm[key2] !== "object" || Array.isArray(nestedForm[key2]) || nestedForm[key2] instanceof File) {
|
||
nestedForm[key2] = /* @__PURE__ */ Object.create(null);
|
||
}
|
||
nestedForm = nestedForm[key2];
|
||
}
|
||
});
|
||
}, "handleParsingNestedValues");
|
||
|
||
// node_modules/.pnpm/hono@4.12.14/node_modules/hono/dist/utils/url.js
|
||
var splitPath = /* @__PURE__ */ __name((path) => {
|
||
const paths = path.split("/");
|
||
if (paths[0] === "") {
|
||
paths.shift();
|
||
}
|
||
return paths;
|
||
}, "splitPath");
|
||
var splitRoutingPath = /* @__PURE__ */ __name((routePath) => {
|
||
const { groups, path } = extractGroupsFromPath(routePath);
|
||
const paths = splitPath(path);
|
||
return replaceGroupMarks(paths, groups);
|
||
}, "splitRoutingPath");
|
||
var extractGroupsFromPath = /* @__PURE__ */ __name((path) => {
|
||
const groups = [];
|
||
path = path.replace(/\{[^}]+\}/g, (match2, index) => {
|
||
const mark = `@${index}`;
|
||
groups.push([mark, match2]);
|
||
return mark;
|
||
});
|
||
return { groups, path };
|
||
}, "extractGroupsFromPath");
|
||
var replaceGroupMarks = /* @__PURE__ */ __name((paths, groups) => {
|
||
for (let i = groups.length - 1; i >= 0; i--) {
|
||
const [mark] = groups[i];
|
||
for (let j = paths.length - 1; j >= 0; j--) {
|
||
if (paths[j].includes(mark)) {
|
||
paths[j] = paths[j].replace(mark, groups[i][1]);
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
return paths;
|
||
}, "replaceGroupMarks");
|
||
var patternCache = {};
|
||
var getPattern = /* @__PURE__ */ __name((label, next) => {
|
||
if (label === "*") {
|
||
return "*";
|
||
}
|
||
const match2 = label.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
|
||
if (match2) {
|
||
const cacheKey = `${label}#${next}`;
|
||
if (!patternCache[cacheKey]) {
|
||
if (match2[2]) {
|
||
patternCache[cacheKey] = next && next[0] !== ":" && next[0] !== "*" ? [cacheKey, match2[1], new RegExp(`^${match2[2]}(?=/${next})`)] : [label, match2[1], new RegExp(`^${match2[2]}$`)];
|
||
} else {
|
||
patternCache[cacheKey] = [label, match2[1], true];
|
||
}
|
||
}
|
||
return patternCache[cacheKey];
|
||
}
|
||
return null;
|
||
}, "getPattern");
|
||
var tryDecode = /* @__PURE__ */ __name((str, decoder) => {
|
||
try {
|
||
return decoder(str);
|
||
} catch {
|
||
return str.replace(/(?:%[0-9A-Fa-f]{2})+/g, (match2) => {
|
||
try {
|
||
return decoder(match2);
|
||
} catch {
|
||
return match2;
|
||
}
|
||
});
|
||
}
|
||
}, "tryDecode");
|
||
var tryDecodeURI = /* @__PURE__ */ __name((str) => tryDecode(str, decodeURI), "tryDecodeURI");
|
||
var getPath = /* @__PURE__ */ __name((request) => {
|
||
const url = request.url;
|
||
const start = url.indexOf("/", url.indexOf(":") + 4);
|
||
let i = start;
|
||
for (; i < url.length; i++) {
|
||
const charCode = url.charCodeAt(i);
|
||
if (charCode === 37) {
|
||
const queryIndex = url.indexOf("?", i);
|
||
const hashIndex = url.indexOf("#", i);
|
||
const end = queryIndex === -1 ? hashIndex === -1 ? void 0 : hashIndex : hashIndex === -1 ? queryIndex : Math.min(queryIndex, hashIndex);
|
||
const path = url.slice(start, end);
|
||
return tryDecodeURI(path.includes("%25") ? path.replace(/%25/g, "%2525") : path);
|
||
} else if (charCode === 63 || charCode === 35) {
|
||
break;
|
||
}
|
||
}
|
||
return url.slice(start, i);
|
||
}, "getPath");
|
||
var getPathNoStrict = /* @__PURE__ */ __name((request) => {
|
||
const result = getPath(request);
|
||
return result.length > 1 && result.at(-1) === "/" ? result.slice(0, -1) : result;
|
||
}, "getPathNoStrict");
|
||
var mergePath = /* @__PURE__ */ __name((base, sub, ...rest) => {
|
||
if (rest.length) {
|
||
sub = mergePath(sub, ...rest);
|
||
}
|
||
return `${base?.[0] === "/" ? "" : "/"}${base}${sub === "/" ? "" : `${base?.at(-1) === "/" ? "" : "/"}${sub?.[0] === "/" ? sub.slice(1) : sub}`}`;
|
||
}, "mergePath");
|
||
var checkOptionalParameter = /* @__PURE__ */ __name((path) => {
|
||
if (path.charCodeAt(path.length - 1) !== 63 || !path.includes(":")) {
|
||
return null;
|
||
}
|
||
const segments = path.split("/");
|
||
const results = [];
|
||
let basePath = "";
|
||
segments.forEach((segment) => {
|
||
if (segment !== "" && !/\:/.test(segment)) {
|
||
basePath += "/" + segment;
|
||
} else if (/\:/.test(segment)) {
|
||
if (/\?/.test(segment)) {
|
||
if (results.length === 0 && basePath === "") {
|
||
results.push("/");
|
||
} else {
|
||
results.push(basePath);
|
||
}
|
||
const optionalSegment = segment.replace("?", "");
|
||
basePath += "/" + optionalSegment;
|
||
results.push(basePath);
|
||
} else {
|
||
basePath += "/" + segment;
|
||
}
|
||
}
|
||
});
|
||
return results.filter((v, i, a) => a.indexOf(v) === i);
|
||
}, "checkOptionalParameter");
|
||
var _decodeURI = /* @__PURE__ */ __name((value) => {
|
||
if (!/[%+]/.test(value)) {
|
||
return value;
|
||
}
|
||
if (value.indexOf("+") !== -1) {
|
||
value = value.replace(/\+/g, " ");
|
||
}
|
||
return value.indexOf("%") !== -1 ? tryDecode(value, decodeURIComponent_) : value;
|
||
}, "_decodeURI");
|
||
var _getQueryParam = /* @__PURE__ */ __name((url, key, multiple) => {
|
||
let encoded;
|
||
if (!multiple && key && !/[%+]/.test(key)) {
|
||
let keyIndex2 = url.indexOf("?", 8);
|
||
if (keyIndex2 === -1) {
|
||
return void 0;
|
||
}
|
||
if (!url.startsWith(key, keyIndex2 + 1)) {
|
||
keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1);
|
||
}
|
||
while (keyIndex2 !== -1) {
|
||
const trailingKeyCode = url.charCodeAt(keyIndex2 + key.length + 1);
|
||
if (trailingKeyCode === 61) {
|
||
const valueIndex = keyIndex2 + key.length + 2;
|
||
const endIndex = url.indexOf("&", valueIndex);
|
||
return _decodeURI(url.slice(valueIndex, endIndex === -1 ? void 0 : endIndex));
|
||
} else if (trailingKeyCode == 38 || isNaN(trailingKeyCode)) {
|
||
return "";
|
||
}
|
||
keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1);
|
||
}
|
||
encoded = /[%+]/.test(url);
|
||
if (!encoded) {
|
||
return void 0;
|
||
}
|
||
}
|
||
const results = {};
|
||
encoded ??= /[%+]/.test(url);
|
||
let keyIndex = url.indexOf("?", 8);
|
||
while (keyIndex !== -1) {
|
||
const nextKeyIndex = url.indexOf("&", keyIndex + 1);
|
||
let valueIndex = url.indexOf("=", keyIndex);
|
||
if (valueIndex > nextKeyIndex && nextKeyIndex !== -1) {
|
||
valueIndex = -1;
|
||
}
|
||
let name = url.slice(
|
||
keyIndex + 1,
|
||
valueIndex === -1 ? nextKeyIndex === -1 ? void 0 : nextKeyIndex : valueIndex
|
||
);
|
||
if (encoded) {
|
||
name = _decodeURI(name);
|
||
}
|
||
keyIndex = nextKeyIndex;
|
||
if (name === "") {
|
||
continue;
|
||
}
|
||
let value;
|
||
if (valueIndex === -1) {
|
||
value = "";
|
||
} else {
|
||
value = url.slice(valueIndex + 1, nextKeyIndex === -1 ? void 0 : nextKeyIndex);
|
||
if (encoded) {
|
||
value = _decodeURI(value);
|
||
}
|
||
}
|
||
if (multiple) {
|
||
if (!(results[name] && Array.isArray(results[name]))) {
|
||
results[name] = [];
|
||
}
|
||
;
|
||
results[name].push(value);
|
||
} else {
|
||
results[name] ??= value;
|
||
}
|
||
}
|
||
return key ? results[key] : results;
|
||
}, "_getQueryParam");
|
||
var getQueryParam = _getQueryParam;
|
||
var getQueryParams = /* @__PURE__ */ __name((url, key) => {
|
||
return _getQueryParam(url, key, true);
|
||
}, "getQueryParams");
|
||
var decodeURIComponent_ = decodeURIComponent;
|
||
|
||
// node_modules/.pnpm/hono@4.12.14/node_modules/hono/dist/request.js
|
||
var tryDecodeURIComponent = /* @__PURE__ */ __name((str) => tryDecode(str, decodeURIComponent_), "tryDecodeURIComponent");
|
||
var HonoRequest = class {
|
||
static {
|
||
__name(this, "HonoRequest");
|
||
}
|
||
/**
|
||
* `.raw` can get the raw Request object.
|
||
*
|
||
* @see {@link https://hono.dev/docs/api/request#raw}
|
||
*
|
||
* @example
|
||
* ```ts
|
||
* // For Cloudflare Workers
|
||
* app.post('/', async (c) => {
|
||
* const metadata = c.req.raw.cf?.hostMetadata?
|
||
* ...
|
||
* })
|
||
* ```
|
||
*/
|
||
raw;
|
||
#validatedData;
|
||
// Short name of validatedData
|
||
#matchResult;
|
||
routeIndex = 0;
|
||
/**
|
||
* `.path` can get the pathname of the request.
|
||
*
|
||
* @see {@link https://hono.dev/docs/api/request#path}
|
||
*
|
||
* @example
|
||
* ```ts
|
||
* app.get('/about/me', (c) => {
|
||
* const pathname = c.req.path // `/about/me`
|
||
* })
|
||
* ```
|
||
*/
|
||
path;
|
||
bodyCache = {};
|
||
constructor(request, path = "/", matchResult = [[]]) {
|
||
this.raw = request;
|
||
this.path = path;
|
||
this.#matchResult = matchResult;
|
||
this.#validatedData = {};
|
||
}
|
||
param(key) {
|
||
return key ? this.#getDecodedParam(key) : this.#getAllDecodedParams();
|
||
}
|
||
#getDecodedParam(key) {
|
||
const paramKey = this.#matchResult[0][this.routeIndex][1][key];
|
||
const param = this.#getParamValue(paramKey);
|
||
return param && /\%/.test(param) ? tryDecodeURIComponent(param) : param;
|
||
}
|
||
#getAllDecodedParams() {
|
||
const decoded = {};
|
||
const keys = Object.keys(this.#matchResult[0][this.routeIndex][1]);
|
||
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;
|
||
}
|
||
}
|
||
return decoded;
|
||
}
|
||
#getParamValue(paramKey) {
|
||
return this.#matchResult[1] ? this.#matchResult[1][paramKey] : paramKey;
|
||
}
|
||
query(key) {
|
||
return getQueryParam(this.url, key);
|
||
}
|
||
queries(key) {
|
||
return getQueryParams(this.url, key);
|
||
}
|
||
header(name) {
|
||
if (name) {
|
||
return this.raw.headers.get(name) ?? void 0;
|
||
}
|
||
const headerData = {};
|
||
this.raw.headers.forEach((value, key) => {
|
||
headerData[key] = value;
|
||
});
|
||
return headerData;
|
||
}
|
||
async parseBody(options) {
|
||
return parseBody(this, options);
|
||
}
|
||
#cachedBody = /* @__PURE__ */ __name((key) => {
|
||
const { bodyCache, raw: raw2 } = this;
|
||
const cachedBody = bodyCache[key];
|
||
if (cachedBody) {
|
||
return cachedBody;
|
||
}
|
||
const anyCachedKey = Object.keys(bodyCache)[0];
|
||
if (anyCachedKey) {
|
||
return bodyCache[anyCachedKey].then((body) => {
|
||
if (anyCachedKey === "json") {
|
||
body = JSON.stringify(body);
|
||
}
|
||
return new Response(body)[key]();
|
||
});
|
||
}
|
||
return bodyCache[key] = raw2[key]();
|
||
}, "#cachedBody");
|
||
/**
|
||
* `.json()` can parse Request body of type `application/json`
|
||
*
|
||
* @see {@link https://hono.dev/docs/api/request#json}
|
||
*
|
||
* @example
|
||
* ```ts
|
||
* app.post('/entry', async (c) => {
|
||
* const body = await c.req.json()
|
||
* })
|
||
* ```
|
||
*/
|
||
json() {
|
||
return this.#cachedBody("text").then((text) => JSON.parse(text));
|
||
}
|
||
/**
|
||
* `.text()` can parse Request body of type `text/plain`
|
||
*
|
||
* @see {@link https://hono.dev/docs/api/request#text}
|
||
*
|
||
* @example
|
||
* ```ts
|
||
* app.post('/entry', async (c) => {
|
||
* const body = await c.req.text()
|
||
* })
|
||
* ```
|
||
*/
|
||
text() {
|
||
return this.#cachedBody("text");
|
||
}
|
||
/**
|
||
* `.arrayBuffer()` parse Request body as an `ArrayBuffer`
|
||
*
|
||
* @see {@link https://hono.dev/docs/api/request#arraybuffer}
|
||
*
|
||
* @example
|
||
* ```ts
|
||
* app.post('/entry', async (c) => {
|
||
* const body = await c.req.arrayBuffer()
|
||
* })
|
||
* ```
|
||
*/
|
||
arrayBuffer() {
|
||
return this.#cachedBody("arrayBuffer");
|
||
}
|
||
/**
|
||
* Parses the request body as a `Blob`.
|
||
* @example
|
||
* ```ts
|
||
* app.post('/entry', async (c) => {
|
||
* const body = await c.req.blob();
|
||
* });
|
||
* ```
|
||
* @see https://hono.dev/docs/api/request#blob
|
||
*/
|
||
blob() {
|
||
return this.#cachedBody("blob");
|
||
}
|
||
/**
|
||
* Parses the request body as `FormData`.
|
||
* @example
|
||
* ```ts
|
||
* app.post('/entry', async (c) => {
|
||
* const body = await c.req.formData();
|
||
* });
|
||
* ```
|
||
* @see https://hono.dev/docs/api/request#formdata
|
||
*/
|
||
formData() {
|
||
return this.#cachedBody("formData");
|
||
}
|
||
/**
|
||
* Adds validated data to the request.
|
||
*
|
||
* @param target - The target of the validation.
|
||
* @param data - The validated data to add.
|
||
*/
|
||
addValidatedData(target, data) {
|
||
this.#validatedData[target] = data;
|
||
}
|
||
valid(target) {
|
||
return this.#validatedData[target];
|
||
}
|
||
/**
|
||
* `.url()` can get the request url strings.
|
||
*
|
||
* @see {@link https://hono.dev/docs/api/request#url}
|
||
*
|
||
* @example
|
||
* ```ts
|
||
* app.get('/about/me', (c) => {
|
||
* const url = c.req.url // `http://localhost:8787/about/me`
|
||
* ...
|
||
* })
|
||
* ```
|
||
*/
|
||
get url() {
|
||
return this.raw.url;
|
||
}
|
||
/**
|
||
* `.method()` can get the method name of the request.
|
||
*
|
||
* @see {@link https://hono.dev/docs/api/request#method}
|
||
*
|
||
* @example
|
||
* ```ts
|
||
* app.get('/about/me', (c) => {
|
||
* const method = c.req.method // `GET`
|
||
* })
|
||
* ```
|
||
*/
|
||
get method() {
|
||
return this.raw.method;
|
||
}
|
||
get [GET_MATCH_RESULT]() {
|
||
return this.#matchResult;
|
||
}
|
||
/**
|
||
* `.matchedRoutes()` can return a matched route in the handler
|
||
*
|
||
* @deprecated
|
||
*
|
||
* Use matchedRoutes helper defined in "hono/route" instead.
|
||
*
|
||
* @see {@link https://hono.dev/docs/api/request#matchedroutes}
|
||
*
|
||
* @example
|
||
* ```ts
|
||
* app.use('*', async function logger(c, next) {
|
||
* await next()
|
||
* c.req.matchedRoutes.forEach(({ handler, method, path }, i) => {
|
||
* const name = handler.name || (handler.length < 2 ? '[handler]' : '[middleware]')
|
||
* console.log(
|
||
* method,
|
||
* ' ',
|
||
* path,
|
||
* ' '.repeat(Math.max(10 - path.length, 0)),
|
||
* name,
|
||
* i === c.req.routeIndex ? '<- respond from here' : ''
|
||
* )
|
||
* })
|
||
* })
|
||
* ```
|
||
*/
|
||
get matchedRoutes() {
|
||
return this.#matchResult[0].map(([[, route]]) => route);
|
||
}
|
||
/**
|
||
* `routePath()` can retrieve the path registered within the handler
|
||
*
|
||
* @deprecated
|
||
*
|
||
* Use routePath helper defined in "hono/route" instead.
|
||
*
|
||
* @see {@link https://hono.dev/docs/api/request#routepath}
|
||
*
|
||
* @example
|
||
* ```ts
|
||
* app.get('/posts/:id', (c) => {
|
||
* return c.json({ path: c.req.routePath })
|
||
* })
|
||
* ```
|
||
*/
|
||
get routePath() {
|
||
return this.#matchResult[0].map(([[, route]]) => route)[this.routeIndex].path;
|
||
}
|
||
};
|
||
|
||
// node_modules/.pnpm/hono@4.12.14/node_modules/hono/dist/utils/html.js
|
||
var HtmlEscapedCallbackPhase = {
|
||
Stringify: 1,
|
||
BeforeStream: 2,
|
||
Stream: 3
|
||
};
|
||
var raw = /* @__PURE__ */ __name((value, callbacks) => {
|
||
const escapedString = new String(value);
|
||
escapedString.isEscaped = true;
|
||
escapedString.callbacks = callbacks;
|
||
return escapedString;
|
||
}, "raw");
|
||
var resolveCallback = /* @__PURE__ */ __name(async (str, phase, preserveCallbacks, context2, buffer) => {
|
||
if (typeof str === "object" && !(str instanceof String)) {
|
||
if (!(str instanceof Promise)) {
|
||
str = str.toString();
|
||
}
|
||
if (str instanceof Promise) {
|
||
str = await str;
|
||
}
|
||
}
|
||
const callbacks = str.callbacks;
|
||
if (!callbacks?.length) {
|
||
return Promise.resolve(str);
|
||
}
|
||
if (buffer) {
|
||
buffer[0] += str;
|
||
} else {
|
||
buffer = [str];
|
||
}
|
||
const resStr = Promise.all(callbacks.map((c) => c({ phase, buffer, context: context2 }))).then(
|
||
(res) => Promise.all(
|
||
res.filter(Boolean).map((str2) => resolveCallback(str2, phase, false, context2, buffer))
|
||
).then(() => buffer[0])
|
||
);
|
||
if (preserveCallbacks) {
|
||
return raw(await resStr, callbacks);
|
||
} else {
|
||
return resStr;
|
||
}
|
||
}, "resolveCallback");
|
||
|
||
// node_modules/.pnpm/hono@4.12.14/node_modules/hono/dist/context.js
|
||
var TEXT_PLAIN = "text/plain; charset=UTF-8";
|
||
var setDefaultContentType = /* @__PURE__ */ __name((contentType, headers) => {
|
||
return {
|
||
"Content-Type": contentType,
|
||
...headers
|
||
};
|
||
}, "setDefaultContentType");
|
||
var createResponseInstance = /* @__PURE__ */ __name((body, init) => new Response(body, init), "createResponseInstance");
|
||
var Context = class {
|
||
static {
|
||
__name(this, "Context");
|
||
}
|
||
#rawRequest;
|
||
#req;
|
||
/**
|
||
* `.env` can get bindings (environment variables, secrets, KV namespaces, D1 database, R2 bucket etc.) in Cloudflare Workers.
|
||
*
|
||
* @see {@link https://hono.dev/docs/api/context#env}
|
||
*
|
||
* @example
|
||
* ```ts
|
||
* // Environment object for Cloudflare Workers
|
||
* app.get('*', async c => {
|
||
* const counter = c.env.COUNTER
|
||
* })
|
||
* ```
|
||
*/
|
||
env = {};
|
||
#var;
|
||
finalized = false;
|
||
/**
|
||
* `.error` can get the error object from the middleware if the Handler throws an error.
|
||
*
|
||
* @see {@link https://hono.dev/docs/api/context#error}
|
||
*
|
||
* @example
|
||
* ```ts
|
||
* app.use('*', async (c, next) => {
|
||
* await next()
|
||
* if (c.error) {
|
||
* // do something...
|
||
* }
|
||
* })
|
||
* ```
|
||
*/
|
||
error;
|
||
#status;
|
||
#executionCtx;
|
||
#res;
|
||
#layout;
|
||
#renderer;
|
||
#notFoundHandler;
|
||
#preparedHeaders;
|
||
#matchResult;
|
||
#path;
|
||
/**
|
||
* Creates an instance of the Context class.
|
||
*
|
||
* @param req - The Request object.
|
||
* @param options - Optional configuration options for the context.
|
||
*/
|
||
constructor(req, options) {
|
||
this.#rawRequest = req;
|
||
if (options) {
|
||
this.#executionCtx = options.executionCtx;
|
||
this.env = options.env;
|
||
this.#notFoundHandler = options.notFoundHandler;
|
||
this.#path = options.path;
|
||
this.#matchResult = options.matchResult;
|
||
}
|
||
}
|
||
/**
|
||
* `.req` is the instance of {@link HonoRequest}.
|
||
*/
|
||
get req() {
|
||
this.#req ??= new HonoRequest(this.#rawRequest, this.#path, this.#matchResult);
|
||
return this.#req;
|
||
}
|
||
/**
|
||
* @see {@link https://hono.dev/docs/api/context#event}
|
||
* The FetchEvent associated with the current request.
|
||
*
|
||
* @throws Will throw an error if the context does not have a FetchEvent.
|
||
*/
|
||
get event() {
|
||
if (this.#executionCtx && "respondWith" in this.#executionCtx) {
|
||
return this.#executionCtx;
|
||
} else {
|
||
throw Error("This context has no FetchEvent");
|
||
}
|
||
}
|
||
/**
|
||
* @see {@link https://hono.dev/docs/api/context#executionctx}
|
||
* The ExecutionContext associated with the current request.
|
||
*
|
||
* @throws Will throw an error if the context does not have an ExecutionContext.
|
||
*/
|
||
get executionCtx() {
|
||
if (this.#executionCtx) {
|
||
return this.#executionCtx;
|
||
} else {
|
||
throw Error("This context has no ExecutionContext");
|
||
}
|
||
}
|
||
/**
|
||
* @see {@link https://hono.dev/docs/api/context#res}
|
||
* The Response object for the current request.
|
||
*/
|
||
get res() {
|
||
return this.#res ||= createResponseInstance(null, {
|
||
headers: this.#preparedHeaders ??= new Headers()
|
||
});
|
||
}
|
||
/**
|
||
* Sets the Response object for the current request.
|
||
*
|
||
* @param _res - The Response object to set.
|
||
*/
|
||
set res(_res) {
|
||
if (this.#res && _res) {
|
||
_res = createResponseInstance(_res.body, _res);
|
||
for (const [k, v] of this.#res.headers.entries()) {
|
||
if (k === "content-type") {
|
||
continue;
|
||
}
|
||
if (k === "set-cookie") {
|
||
const cookies = this.#res.headers.getSetCookie();
|
||
_res.headers.delete("set-cookie");
|
||
for (const cookie of cookies) {
|
||
_res.headers.append("set-cookie", cookie);
|
||
}
|
||
} else {
|
||
_res.headers.set(k, v);
|
||
}
|
||
}
|
||
}
|
||
this.#res = _res;
|
||
this.finalized = true;
|
||
}
|
||
/**
|
||
* `.render()` can create a response within a layout.
|
||
*
|
||
* @see {@link https://hono.dev/docs/api/context#render-setrenderer}
|
||
*
|
||
* @example
|
||
* ```ts
|
||
* app.get('/', (c) => {
|
||
* return c.render('Hello!')
|
||
* })
|
||
* ```
|
||
*/
|
||
render = /* @__PURE__ */ __name((...args) => {
|
||
this.#renderer ??= (content) => this.html(content);
|
||
return this.#renderer(...args);
|
||
}, "render");
|
||
/**
|
||
* Sets the layout for the response.
|
||
*
|
||
* @param layout - The layout to set.
|
||
* @returns The layout function.
|
||
*/
|
||
setLayout = /* @__PURE__ */ __name((layout) => this.#layout = layout, "setLayout");
|
||
/**
|
||
* Gets the current layout for the response.
|
||
*
|
||
* @returns The current layout function.
|
||
*/
|
||
getLayout = /* @__PURE__ */ __name(() => this.#layout, "getLayout");
|
||
/**
|
||
* `.setRenderer()` can set the layout in the custom middleware.
|
||
*
|
||
* @see {@link https://hono.dev/docs/api/context#render-setrenderer}
|
||
*
|
||
* @example
|
||
* ```tsx
|
||
* app.use('*', async (c, next) => {
|
||
* c.setRenderer((content) => {
|
||
* return c.html(
|
||
* <html>
|
||
* <body>
|
||
* <p>{content}</p>
|
||
* </body>
|
||
* </html>
|
||
* )
|
||
* })
|
||
* await next()
|
||
* })
|
||
* ```
|
||
*/
|
||
setRenderer = /* @__PURE__ */ __name((renderer) => {
|
||
this.#renderer = renderer;
|
||
}, "setRenderer");
|
||
/**
|
||
* `.header()` can set headers.
|
||
*
|
||
* @see {@link https://hono.dev/docs/api/context#header}
|
||
*
|
||
* @example
|
||
* ```ts
|
||
* app.get('/welcome', (c) => {
|
||
* // Set headers
|
||
* c.header('X-Message', 'Hello!')
|
||
* c.header('Content-Type', 'text/plain')
|
||
*
|
||
* return c.body('Thank you for coming')
|
||
* })
|
||
* ```
|
||
*/
|
||
header = /* @__PURE__ */ __name((name, value, options) => {
|
||
if (this.finalized) {
|
||
this.#res = createResponseInstance(this.#res.body, this.#res);
|
||
}
|
||
const headers = this.#res ? this.#res.headers : this.#preparedHeaders ??= new Headers();
|
||
if (value === void 0) {
|
||
headers.delete(name);
|
||
} else if (options?.append) {
|
||
headers.append(name, value);
|
||
} else {
|
||
headers.set(name, value);
|
||
}
|
||
}, "header");
|
||
status = /* @__PURE__ */ __name((status) => {
|
||
this.#status = status;
|
||
}, "status");
|
||
/**
|
||
* `.set()` can set the value specified by the key.
|
||
*
|
||
* @see {@link https://hono.dev/docs/api/context#set-get}
|
||
*
|
||
* @example
|
||
* ```ts
|
||
* app.use('*', async (c, next) => {
|
||
* c.set('message', 'Hono is hot!!')
|
||
* await next()
|
||
* })
|
||
* ```
|
||
*/
|
||
set = /* @__PURE__ */ __name((key, value) => {
|
||
this.#var ??= /* @__PURE__ */ new Map();
|
||
this.#var.set(key, value);
|
||
}, "set");
|
||
/**
|
||
* `.get()` can use the value specified by the key.
|
||
*
|
||
* @see {@link https://hono.dev/docs/api/context#set-get}
|
||
*
|
||
* @example
|
||
* ```ts
|
||
* app.get('/', (c) => {
|
||
* const message = c.get('message')
|
||
* return c.text(`The message is "${message}"`)
|
||
* })
|
||
* ```
|
||
*/
|
||
get = /* @__PURE__ */ __name((key) => {
|
||
return this.#var ? this.#var.get(key) : void 0;
|
||
}, "get");
|
||
/**
|
||
* `.var` can access the value of a variable.
|
||
*
|
||
* @see {@link https://hono.dev/docs/api/context#var}
|
||
*
|
||
* @example
|
||
* ```ts
|
||
* const result = c.var.client.oneMethod()
|
||
* ```
|
||
*/
|
||
// c.var.propName is a read-only
|
||
get var() {
|
||
if (!this.#var) {
|
||
return {};
|
||
}
|
||
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") {
|
||
responseHeaders.append(key, value);
|
||
} else {
|
||
responseHeaders.set(key, value);
|
||
}
|
||
}
|
||
}
|
||
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);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
const status = typeof arg === "number" ? arg : arg?.status ?? this.#status;
|
||
return createResponseInstance(data, { status, headers: responseHeaders });
|
||
}
|
||
newResponse = /* @__PURE__ */ __name((...args) => this.#newResponse(...args), "newResponse");
|
||
/**
|
||
* `.body()` can return the HTTP response.
|
||
* You can set headers with `.header()` and set HTTP status code with `.status`.
|
||
* This can also be set in `.text()`, `.json()` and so on.
|
||
*
|
||
* @see {@link https://hono.dev/docs/api/context#body}
|
||
*
|
||
* @example
|
||
* ```ts
|
||
* app.get('/welcome', (c) => {
|
||
* // Set headers
|
||
* c.header('X-Message', 'Hello!')
|
||
* c.header('Content-Type', 'text/plain')
|
||
* // Set HTTP status code
|
||
* c.status(201)
|
||
*
|
||
* // Return the response body
|
||
* return c.body('Thank you for coming')
|
||
* })
|
||
* ```
|
||
*/
|
||
body = /* @__PURE__ */ __name((data, arg, headers) => this.#newResponse(data, arg, headers), "body");
|
||
/**
|
||
* `.text()` can render text as `Content-Type:text/plain`.
|
||
*
|
||
* @see {@link https://hono.dev/docs/api/context#text}
|
||
*
|
||
* @example
|
||
* ```ts
|
||
* app.get('/say', (c) => {
|
||
* return c.text('Hello!')
|
||
* })
|
||
* ```
|
||
*/
|
||
text = /* @__PURE__ */ __name((text, arg, headers) => {
|
||
return !this.#preparedHeaders && !this.#status && !arg && !headers && !this.finalized ? new Response(text) : this.#newResponse(
|
||
text,
|
||
arg,
|
||
setDefaultContentType(TEXT_PLAIN, headers)
|
||
);
|
||
}, "text");
|
||
/**
|
||
* `.json()` can render JSON as `Content-Type:application/json`.
|
||
*
|
||
* @see {@link https://hono.dev/docs/api/context#json}
|
||
*
|
||
* @example
|
||
* ```ts
|
||
* app.get('/api', (c) => {
|
||
* return c.json({ message: 'Hello!' })
|
||
* })
|
||
* ```
|
||
*/
|
||
json = /* @__PURE__ */ __name((object, arg, headers) => {
|
||
return this.#newResponse(
|
||
JSON.stringify(object),
|
||
arg,
|
||
setDefaultContentType("application/json", headers)
|
||
);
|
||
}, "json");
|
||
html = /* @__PURE__ */ __name((html, arg, headers) => {
|
||
const res = /* @__PURE__ */ __name((html2) => this.#newResponse(html2, arg, setDefaultContentType("text/html; charset=UTF-8", headers)), "res");
|
||
return typeof html === "object" ? resolveCallback(html, HtmlEscapedCallbackPhase.Stringify, false, {}).then(res) : res(html);
|
||
}, "html");
|
||
/**
|
||
* `.redirect()` can Redirect, default status code is 302.
|
||
*
|
||
* @see {@link https://hono.dev/docs/api/context#redirect}
|
||
*
|
||
* @example
|
||
* ```ts
|
||
* app.get('/redirect', (c) => {
|
||
* return c.redirect('/')
|
||
* })
|
||
* app.get('/redirect-permanently', (c) => {
|
||
* return c.redirect('/', 301)
|
||
* })
|
||
* ```
|
||
*/
|
||
redirect = /* @__PURE__ */ __name((location, status) => {
|
||
const locationString = String(location);
|
||
this.header(
|
||
"Location",
|
||
// Multibyes should be encoded
|
||
// eslint-disable-next-line no-control-regex
|
||
!/[^\x00-\xFF]/.test(locationString) ? locationString : encodeURI(locationString)
|
||
);
|
||
return this.newResponse(null, status ?? 302);
|
||
}, "redirect");
|
||
/**
|
||
* `.notFound()` can return the Not Found Response.
|
||
*
|
||
* @see {@link https://hono.dev/docs/api/context#notfound}
|
||
*
|
||
* @example
|
||
* ```ts
|
||
* app.get('/notfound', (c) => {
|
||
* return c.notFound()
|
||
* })
|
||
* ```
|
||
*/
|
||
notFound = /* @__PURE__ */ __name(() => {
|
||
this.#notFoundHandler ??= () => createResponseInstance();
|
||
return this.#notFoundHandler(this);
|
||
}, "notFound");
|
||
};
|
||
|
||
// node_modules/.pnpm/hono@4.12.14/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 MESSAGE_MATCHER_IS_ALREADY_BUILT = "Can not add a route since the matcher is already built.";
|
||
var UnsupportedPathError = class extends Error {
|
||
static {
|
||
__name(this, "UnsupportedPathError");
|
||
}
|
||
};
|
||
|
||
// node_modules/.pnpm/hono@4.12.14/node_modules/hono/dist/utils/constants.js
|
||
var COMPOSED_HANDLER = "__COMPOSED_HANDLER";
|
||
|
||
// node_modules/.pnpm/hono@4.12.14/node_modules/hono/dist/hono-base.js
|
||
var notFoundHandler = /* @__PURE__ */ __name((c) => {
|
||
return c.text("404 Not Found", 404);
|
||
}, "notFoundHandler");
|
||
var errorHandler = /* @__PURE__ */ __name((err, c) => {
|
||
if ("getResponse" in err) {
|
||
const res = err.getResponse();
|
||
return c.newResponse(res.body, res);
|
||
}
|
||
console.error(err);
|
||
return c.text("Internal Server Error", 500);
|
||
}, "errorHandler");
|
||
var Hono = class _Hono {
|
||
static {
|
||
__name(this, "_Hono");
|
||
}
|
||
get;
|
||
post;
|
||
put;
|
||
delete;
|
||
options;
|
||
patch;
|
||
all;
|
||
on;
|
||
use;
|
||
/*
|
||
This class is like an abstract class and does not have a router.
|
||
To use it, inherit the class and implement router in the constructor.
|
||
*/
|
||
router;
|
||
getPath;
|
||
// Cannot use `#` because it requires visibility at JavaScript runtime.
|
||
_basePath = "/";
|
||
#path = "/";
|
||
routes = [];
|
||
constructor(options = {}) {
|
||
const allMethods = [...METHODS, METHOD_NAME_ALL_LOWERCASE];
|
||
allMethods.forEach((method) => {
|
||
this[method] = (args1, ...args) => {
|
||
if (typeof args1 === "string") {
|
||
this.#path = args1;
|
||
} else {
|
||
this.#addRoute(method, this.#path, args1);
|
||
}
|
||
args.forEach((handler) => {
|
||
this.#addRoute(method, this.#path, handler);
|
||
});
|
||
return this;
|
||
};
|
||
});
|
||
this.on = (method, path, ...handlers) => {
|
||
for (const p of [path].flat()) {
|
||
this.#path = p;
|
||
for (const m of [method].flat()) {
|
||
handlers.map((handler) => {
|
||
this.#addRoute(m.toUpperCase(), this.#path, handler);
|
||
});
|
||
}
|
||
}
|
||
return this;
|
||
};
|
||
this.use = (arg1, ...handlers) => {
|
||
if (typeof arg1 === "string") {
|
||
this.#path = arg1;
|
||
} else {
|
||
this.#path = "*";
|
||
handlers.unshift(arg1);
|
||
}
|
||
handlers.forEach((handler) => {
|
||
this.#addRoute(METHOD_NAME_ALL, this.#path, handler);
|
||
});
|
||
return this;
|
||
};
|
||
const { strict, ...optionsWithoutStrict } = options;
|
||
Object.assign(this, optionsWithoutStrict);
|
||
this.getPath = strict ?? true ? options.getPath ?? getPath : getPathNoStrict;
|
||
}
|
||
#clone() {
|
||
const clone = new _Hono({
|
||
router: this.router,
|
||
getPath: this.getPath
|
||
});
|
||
clone.errorHandler = this.errorHandler;
|
||
clone.#notFoundHandler = this.#notFoundHandler;
|
||
clone.routes = this.routes;
|
||
return clone;
|
||
}
|
||
#notFoundHandler = notFoundHandler;
|
||
// Cannot use `#` because it requires visibility at JavaScript runtime.
|
||
errorHandler = errorHandler;
|
||
/**
|
||
* `.route()` allows grouping other Hono instance in routes.
|
||
*
|
||
* @see {@link https://hono.dev/docs/api/routing#grouping}
|
||
*
|
||
* @param {string} path - base Path
|
||
* @param {Hono} app - other Hono instance
|
||
* @returns {Hono} routed Hono instance
|
||
*
|
||
* @example
|
||
* ```ts
|
||
* const app = new Hono()
|
||
* const app2 = new Hono()
|
||
*
|
||
* app2.get("/user", (c) => c.text("user"))
|
||
* app.route("/api", app2) // GET /api/user
|
||
* ```
|
||
*/
|
||
route(path, app2) {
|
||
const subApp = this.basePath(path);
|
||
app2.routes.map((r) => {
|
||
let handler;
|
||
if (app2.errorHandler === errorHandler) {
|
||
handler = r.handler;
|
||
} else {
|
||
handler = /* @__PURE__ */ __name(async (c, next) => (await compose([], app2.errorHandler)(c, () => r.handler(c, next))).res, "handler");
|
||
handler[COMPOSED_HANDLER] = r.handler;
|
||
}
|
||
subApp.#addRoute(r.method, r.path, handler);
|
||
});
|
||
return this;
|
||
}
|
||
/**
|
||
* `.basePath()` allows base paths to be specified.
|
||
*
|
||
* @see {@link https://hono.dev/docs/api/routing#base-path}
|
||
*
|
||
* @param {string} path - base Path
|
||
* @returns {Hono} changed Hono instance
|
||
*
|
||
* @example
|
||
* ```ts
|
||
* const api = new Hono().basePath('/api')
|
||
* ```
|
||
*/
|
||
basePath(path) {
|
||
const subApp = this.#clone();
|
||
subApp._basePath = mergePath(this._basePath, path);
|
||
return subApp;
|
||
}
|
||
/**
|
||
* `.onError()` handles an error and returns a customized Response.
|
||
*
|
||
* @see {@link https://hono.dev/docs/api/hono#error-handling}
|
||
*
|
||
* @param {ErrorHandler} handler - request Handler for error
|
||
* @returns {Hono} changed Hono instance
|
||
*
|
||
* @example
|
||
* ```ts
|
||
* app.onError((err, c) => {
|
||
* console.error(`${err}`)
|
||
* return c.text('Custom Error Message', 500)
|
||
* })
|
||
* ```
|
||
*/
|
||
onError = /* @__PURE__ */ __name((handler) => {
|
||
this.errorHandler = handler;
|
||
return this;
|
||
}, "onError");
|
||
/**
|
||
* `.notFound()` allows you to customize a Not Found Response.
|
||
*
|
||
* @see {@link https://hono.dev/docs/api/hono#not-found}
|
||
*
|
||
* @param {NotFoundHandler} handler - request handler for not-found
|
||
* @returns {Hono} changed Hono instance
|
||
*
|
||
* @example
|
||
* ```ts
|
||
* app.notFound((c) => {
|
||
* return c.text('Custom 404 Message', 404)
|
||
* })
|
||
* ```
|
||
*/
|
||
notFound = /* @__PURE__ */ __name((handler) => {
|
||
this.#notFoundHandler = handler;
|
||
return this;
|
||
}, "notFound");
|
||
/**
|
||
* `.mount()` allows you to mount applications built with other frameworks into your Hono application.
|
||
*
|
||
* @see {@link https://hono.dev/docs/api/hono#mount}
|
||
*
|
||
* @param {string} path - base Path
|
||
* @param {Function} applicationHandler - other Request Handler
|
||
* @param {MountOptions} [options] - options of `.mount()`
|
||
* @returns {Hono} mounted Hono instance
|
||
*
|
||
* @example
|
||
* ```ts
|
||
* import { Router as IttyRouter } from 'itty-router'
|
||
* import { Hono } from 'hono'
|
||
* // Create itty-router application
|
||
* const ittyRouter = IttyRouter()
|
||
* // GET /itty-router/hello
|
||
* ittyRouter.get('/hello', () => new Response('Hello from itty-router'))
|
||
*
|
||
* const app = new Hono()
|
||
* app.mount('/itty-router', ittyRouter.handle)
|
||
* ```
|
||
*
|
||
* @example
|
||
* ```ts
|
||
* const app = new Hono()
|
||
* // Send the request to another application without modification.
|
||
* app.mount('/app', anotherApp, {
|
||
* replaceRequest: (req) => req,
|
||
* })
|
||
* ```
|
||
*/
|
||
mount(path, applicationHandler, options) {
|
||
let replaceRequest;
|
||
let optionHandler;
|
||
if (options) {
|
||
if (typeof options === "function") {
|
||
optionHandler = options;
|
||
} else {
|
||
optionHandler = options.optionHandler;
|
||
if (options.replaceRequest === false) {
|
||
replaceRequest = /* @__PURE__ */ __name((request) => request, "replaceRequest");
|
||
} else {
|
||
replaceRequest = options.replaceRequest;
|
||
}
|
||
}
|
||
}
|
||
const getOptions = optionHandler ? (c) => {
|
||
const options2 = optionHandler(c);
|
||
return Array.isArray(options2) ? options2 : [options2];
|
||
} : (c) => {
|
||
let executionContext = void 0;
|
||
try {
|
||
executionContext = c.executionCtx;
|
||
} catch {
|
||
}
|
||
return [c.env, executionContext];
|
||
};
|
||
replaceRequest ||= (() => {
|
||
const mergedPath = mergePath(this._basePath, path);
|
||
const pathPrefixLength = mergedPath === "/" ? 0 : mergedPath.length;
|
||
return (request) => {
|
||
const url = new URL(request.url);
|
||
url.pathname = url.pathname.slice(pathPrefixLength) || "/";
|
||
return new Request(url, request);
|
||
};
|
||
})();
|
||
const handler = /* @__PURE__ */ __name(async (c, next) => {
|
||
const res = await applicationHandler(replaceRequest(c.req.raw), ...getOptions(c));
|
||
if (res) {
|
||
return res;
|
||
}
|
||
await next();
|
||
}, "handler");
|
||
this.#addRoute(METHOD_NAME_ALL, mergePath(path, "*"), handler);
|
||
return this;
|
||
}
|
||
#addRoute(method, path, handler) {
|
||
method = method.toUpperCase();
|
||
path = mergePath(this._basePath, path);
|
||
const r = { basePath: this._basePath, path, method, handler };
|
||
this.router.add(method, path, [handler, r]);
|
||
this.routes.push(r);
|
||
}
|
||
#handleError(err, c) {
|
||
if (err instanceof Error) {
|
||
return this.errorHandler(err, c);
|
||
}
|
||
throw err;
|
||
}
|
||
#dispatch(request, executionCtx, env2, method) {
|
||
if (method === "HEAD") {
|
||
return (async () => new Response(null, await this.#dispatch(request, executionCtx, env2, "GET")))();
|
||
}
|
||
const path = this.getPath(request, { env: env2 });
|
||
const matchResult = this.router.match(method, path);
|
||
const c = new Context(request, {
|
||
path,
|
||
matchResult,
|
||
env: env2,
|
||
executionCtx,
|
||
notFoundHandler: this.#notFoundHandler
|
||
});
|
||
if (matchResult[0].length === 1) {
|
||
let res;
|
||
try {
|
||
res = matchResult[0][0][0][0](c, async () => {
|
||
c.res = await this.#notFoundHandler(c);
|
||
});
|
||
} catch (err) {
|
||
return this.#handleError(err, c);
|
||
}
|
||
return res instanceof Promise ? res.then(
|
||
(resolved) => resolved || (c.finalized ? c.res : this.#notFoundHandler(c))
|
||
).catch((err) => this.#handleError(err, c)) : res ?? this.#notFoundHandler(c);
|
||
}
|
||
const composed = compose(matchResult[0], this.errorHandler, this.#notFoundHandler);
|
||
return (async () => {
|
||
try {
|
||
const context2 = await composed(c);
|
||
if (!context2.finalized) {
|
||
throw new Error(
|
||
"Context is not finalized. Did you forget to return a Response object or `await next()`?"
|
||
);
|
||
}
|
||
return context2.res;
|
||
} catch (err) {
|
||
return this.#handleError(err, c);
|
||
}
|
||
})();
|
||
}
|
||
/**
|
||
* `.fetch()` will be entry point of your app.
|
||
*
|
||
* @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
|
||
* @returns {Response | Promise<Response>} response of request
|
||
*
|
||
*/
|
||
fetch = /* @__PURE__ */ __name((request, ...rest) => {
|
||
return this.#dispatch(request, rest[1], rest[0], request.method);
|
||
}, "fetch");
|
||
/**
|
||
* `.request()` is a useful method for testing.
|
||
* You can pass a URL or pathname to send a GET request.
|
||
* app will return a Response object.
|
||
* ```ts
|
||
* test('GET /hello is ok', async () => {
|
||
* const res = await app.request('/hello')
|
||
* expect(res.status).toBe(200)
|
||
* })
|
||
* ```
|
||
* @see https://hono.dev/docs/api/hono#request
|
||
*/
|
||
request = /* @__PURE__ */ __name((input, requestInit, Env, executionCtx) => {
|
||
if (input instanceof Request) {
|
||
return this.fetch(requestInit ? new Request(input, requestInit) : input, Env, executionCtx);
|
||
}
|
||
input = input.toString();
|
||
return this.fetch(
|
||
new Request(
|
||
/^https?:\/\//.test(input) ? input : `http://localhost${mergePath("/", input)}`,
|
||
requestInit
|
||
),
|
||
Env,
|
||
executionCtx
|
||
);
|
||
}, "request");
|
||
/**
|
||
* `.fire()` automatically adds a global fetch event listener.
|
||
* This can be useful for environments that adhere to the Service Worker API, such as non-ES module Cloudflare Workers.
|
||
* @deprecated
|
||
* Use `fire` from `hono/service-worker` instead.
|
||
* ```ts
|
||
* import { Hono } from 'hono'
|
||
* import { fire } from 'hono/service-worker'
|
||
*
|
||
* const app = new Hono()
|
||
* // ...
|
||
* fire(app)
|
||
* ```
|
||
* @see https://hono.dev/docs/api/hono#fire
|
||
* @see https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API
|
||
* @see https://developers.cloudflare.com/workers/reference/migrate-to-module-workers/
|
||
*/
|
||
fire = /* @__PURE__ */ __name(() => {
|
||
addEventListener("fetch", (event) => {
|
||
event.respondWith(this.#dispatch(event.request, event, void 0, event.request.method));
|
||
});
|
||
}, "fire");
|
||
};
|
||
|
||
// node_modules/.pnpm/hono@4.12.14/node_modules/hono/dist/router/reg-exp-router/matcher.js
|
||
var emptyParam = [];
|
||
function match(method, path) {
|
||
const matchers = this.buildAllMatchers();
|
||
const match2 = /* @__PURE__ */ __name(((method2, path2) => {
|
||
const matcher = matchers[method2] || matchers[METHOD_NAME_ALL];
|
||
const staticMatch = matcher[2][path2];
|
||
if (staticMatch) {
|
||
return staticMatch;
|
||
}
|
||
const match3 = path2.match(matcher[0]);
|
||
if (!match3) {
|
||
return [[], emptyParam];
|
||
}
|
||
const index = match3.indexOf("", 1);
|
||
return [matcher[1][index], match3];
|
||
}), "match2");
|
||
this.match = match2;
|
||
return match2(method, path);
|
||
}
|
||
__name(match, "match");
|
||
|
||
// node_modules/.pnpm/hono@4.12.14/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 = "(?:|/.*)";
|
||
var PATH_ERROR = /* @__PURE__ */ Symbol();
|
||
var regExpMetaChars = new Set(".\\+*[^]$()");
|
||
function compareKey(a, b) {
|
||
if (a.length === 1) {
|
||
return b.length === 1 ? a < b ? -1 : 1 : -1;
|
||
}
|
||
if (b.length === 1) {
|
||
return 1;
|
||
}
|
||
if (a === ONLY_WILDCARD_REG_EXP_STR || a === TAIL_WILDCARD_REG_EXP_STR) {
|
||
return 1;
|
||
} else if (b === ONLY_WILDCARD_REG_EXP_STR || b === TAIL_WILDCARD_REG_EXP_STR) {
|
||
return -1;
|
||
}
|
||
if (a === LABEL_REG_EXP_STR) {
|
||
return 1;
|
||
} else if (b === LABEL_REG_EXP_STR) {
|
||
return -1;
|
||
}
|
||
return a.length === b.length ? a < b ? -1 : 1 : b.length - a.length;
|
||
}
|
||
__name(compareKey, "compareKey");
|
||
var Node = class _Node {
|
||
static {
|
||
__name(this, "_Node");
|
||
}
|
||
#index;
|
||
#varIndex;
|
||
#children = /* @__PURE__ */ Object.create(null);
|
||
insert(tokens, index, paramMap, context2, 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;
|
||
}
|
||
regexpStr = regexpStr.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:");
|
||
if (/\((?!\?:)/.test(regexpStr)) {
|
||
throw PATH_ERROR;
|
||
}
|
||
}
|
||
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 = context2.varIndex++;
|
||
}
|
||
}
|
||
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.insert(restTokens, index, paramMap, context2, pathErrorCheckOnly);
|
||
}
|
||
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") {
|
||
strList.unshift(`#${this.#index}`);
|
||
}
|
||
if (strList.length === 0) {
|
||
return "";
|
||
}
|
||
if (strList.length === 1) {
|
||
return strList[0];
|
||
}
|
||
return "(?:" + strList.join("|") + ")";
|
||
}
|
||
};
|
||
|
||
// node_modules/.pnpm/hono@4.12.14/node_modules/hono/dist/router/reg-exp-router/trie.js
|
||
var Trie = class {
|
||
static {
|
||
__name(this, "Trie");
|
||
}
|
||
#context = { varIndex: 0 };
|
||
#root = new Node();
|
||
insert(path, index, pathErrorCheckOnly) {
|
||
const paramAssoc = [];
|
||
const groups = [];
|
||
for (let i = 0; ; ) {
|
||
let replaced = false;
|
||
path = path.replace(/\{[^}]+\}/g, (m) => {
|
||
const mark = `@\\${i}`;
|
||
groups[i] = [mark, m];
|
||
i++;
|
||
replaced = true;
|
||
return mark;
|
||
});
|
||
if (!replaced) {
|
||
break;
|
||
}
|
||
}
|
||
const tokens = path.match(/(?::[^\/]+)|(?:\/\*$)|./g) || [];
|
||
for (let i = groups.length - 1; i >= 0; i--) {
|
||
const [mark] = groups[i];
|
||
for (let j = tokens.length - 1; j >= 0; j--) {
|
||
if (tokens[j].indexOf(mark) !== -1) {
|
||
tokens[j] = tokens[j].replace(mark, groups[i][1]);
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
this.#root.insert(tokens, index, paramAssoc, this.#context, pathErrorCheckOnly);
|
||
return paramAssoc;
|
||
}
|
||
buildRegExp() {
|
||
let regexp = this.#root.buildRegExpStr();
|
||
if (regexp === "") {
|
||
return [/^$/, [], []];
|
||
}
|
||
let captureIndex = 0;
|
||
const indexReplacementMap = [];
|
||
const paramReplacementMap = [];
|
||
regexp = regexp.replace(/#(\d+)|@(\d+)|\.\*\$/g, (_, handlerIndex, paramIndex) => {
|
||
if (handlerIndex !== void 0) {
|
||
indexReplacementMap[++captureIndex] = Number(handlerIndex);
|
||
return "$()";
|
||
}
|
||
if (paramIndex !== void 0) {
|
||
paramReplacementMap[Number(paramIndex)] = ++captureIndex;
|
||
return "";
|
||
}
|
||
return "";
|
||
});
|
||
return [new RegExp(`^${regexp}`), indexReplacementMap, paramReplacementMap];
|
||
}
|
||
};
|
||
|
||
// node_modules/.pnpm/hono@4.12.14/node_modules/hono/dist/router/reg-exp-router/router.js
|
||
var nullMatcher = [/^$/, [], /* @__PURE__ */ Object.create(null)];
|
||
var wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
|
||
function buildWildcardRegExp(path) {
|
||
return wildcardRegExpCache[path] ??= new RegExp(
|
||
path === "*" ? "" : `^${path.replace(
|
||
/\/\*$|([.\\+*[^\]$()])/g,
|
||
(_, metaChar) => metaChar ? `\\${metaChar}` : "(?:|/.*)"
|
||
)}$`
|
||
);
|
||
}
|
||
__name(buildWildcardRegExp, "buildWildcardRegExp");
|
||
function clearWildcardRegExpCache() {
|
||
wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
|
||
}
|
||
__name(clearWildcardRegExpCache, "clearWildcardRegExpCache");
|
||
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];
|
||
}
|
||
__name(buildMatcherFromPreprocessedRoutes, "buildMatcherFromPreprocessedRoutes");
|
||
function findMiddleware(middleware, path) {
|
||
if (!middleware) {
|
||
return void 0;
|
||
}
|
||
for (const k of Object.keys(middleware).sort((a, b) => b.length - a.length)) {
|
||
if (buildWildcardRegExp(k).test(path)) {
|
||
return [...middleware[k]];
|
||
}
|
||
}
|
||
return void 0;
|
||
}
|
||
__name(findMiddleware, "findMiddleware");
|
||
var RegExpRouter = class {
|
||
static {
|
||
__name(this, "RegExpRouter");
|
||
}
|
||
name = "RegExpRouter";
|
||
#middleware;
|
||
#routes;
|
||
constructor() {
|
||
this.#middleware = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
|
||
this.#routes = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
|
||
}
|
||
add(method, path, handler) {
|
||
const middleware = this.#middleware;
|
||
const routes = this.#routes;
|
||
if (!middleware || !routes) {
|
||
throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
|
||
}
|
||
if (!middleware[method]) {
|
||
;
|
||
[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]];
|
||
});
|
||
});
|
||
}
|
||
if (path === "/*") {
|
||
path = "*";
|
||
}
|
||
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) {
|
||
Object.keys(middleware[m]).forEach((p) => {
|
||
re.test(p) && middleware[m][p].push([handler, paramCount]);
|
||
});
|
||
}
|
||
});
|
||
Object.keys(routes).forEach((m) => {
|
||
if (method === METHOD_NAME_ALL || method === m) {
|
||
Object.keys(routes[m]).forEach(
|
||
(p) => re.test(p) && routes[m][p].push([handler, paramCount])
|
||
);
|
||
}
|
||
});
|
||
return;
|
||
}
|
||
const paths = checkOptionalParameter(path) || [path];
|
||
for (let i = 0, len = paths.length; i < len; i++) {
|
||
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) || []
|
||
];
|
||
routes[m][path2].push([handler, paramCount - len + i + 1]);
|
||
}
|
||
});
|
||
}
|
||
}
|
||
match = match;
|
||
buildAllMatchers() {
|
||
const matchers = /* @__PURE__ */ Object.create(null);
|
||
Object.keys(this.#routes).concat(Object.keys(this.#middleware)).forEach((method) => {
|
||
matchers[method] ||= this.#buildMatcher(method);
|
||
});
|
||
this.#middleware = this.#routes = 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]])
|
||
);
|
||
}
|
||
});
|
||
if (!hasOwnRoute) {
|
||
return null;
|
||
} else {
|
||
return buildMatcherFromPreprocessedRoutes(routes);
|
||
}
|
||
}
|
||
};
|
||
|
||
// node_modules/.pnpm/hono@4.12.14/node_modules/hono/dist/router/smart-router/router.js
|
||
var SmartRouter = class {
|
||
static {
|
||
__name(this, "SmartRouter");
|
||
}
|
||
name = "SmartRouter";
|
||
#routers = [];
|
||
#routes = [];
|
||
constructor(init) {
|
||
this.#routers = init.routers;
|
||
}
|
||
add(method, path, handler) {
|
||
if (!this.#routes) {
|
||
throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
|
||
}
|
||
this.#routes.push([method, path, handler]);
|
||
}
|
||
match(method, path) {
|
||
if (!this.#routes) {
|
||
throw new Error("Fatal error");
|
||
}
|
||
const routers = this.#routers;
|
||
const routes = this.#routes;
|
||
const len = routers.length;
|
||
let i = 0;
|
||
let res;
|
||
for (; i < len; i++) {
|
||
const router = routers[i];
|
||
try {
|
||
for (let i2 = 0, len2 = routes.length; i2 < len2; i2++) {
|
||
router.add(...routes[i2]);
|
||
}
|
||
res = router.match(method, path);
|
||
} catch (e) {
|
||
if (e instanceof UnsupportedPathError) {
|
||
continue;
|
||
}
|
||
throw e;
|
||
}
|
||
this.match = router.match.bind(router);
|
||
this.#routers = [router];
|
||
this.#routes = void 0;
|
||
break;
|
||
}
|
||
if (i === len) {
|
||
throw new Error("Fatal error");
|
||
}
|
||
this.name = `SmartRouter + ${this.activeRouter.name}`;
|
||
return res;
|
||
}
|
||
get activeRouter() {
|
||
if (this.#routes || this.#routers.length !== 1) {
|
||
throw new Error("No active router has been determined yet.");
|
||
}
|
||
return this.#routers[0];
|
||
}
|
||
};
|
||
|
||
// node_modules/.pnpm/hono@4.12.14/node_modules/hono/dist/router/trie-router/node.js
|
||
var emptyParams = /* @__PURE__ */ Object.create(null);
|
||
var hasChildren = /* @__PURE__ */ __name((children) => {
|
||
for (const _ in children) {
|
||
return true;
|
||
}
|
||
return false;
|
||
}, "hasChildren");
|
||
var Node2 = class _Node2 {
|
||
static {
|
||
__name(this, "_Node");
|
||
}
|
||
#methods;
|
||
#children;
|
||
#patterns;
|
||
#order = 0;
|
||
#params = emptyParams;
|
||
constructor(method, handler, children) {
|
||
this.#children = children || /* @__PURE__ */ Object.create(null);
|
||
this.#methods = [];
|
||
if (method && handler) {
|
||
const m = /* @__PURE__ */ Object.create(null);
|
||
m[method] = { handler, possibleKeys: [], score: 0 };
|
||
this.#methods = [m];
|
||
}
|
||
this.#patterns = [];
|
||
}
|
||
insert(method, path, handler) {
|
||
this.#order = ++this.#order;
|
||
let curNode = this;
|
||
const parts = splitRoutingPath(path);
|
||
const possibleKeys = [];
|
||
for (let i = 0, len = parts.length; i < len; i++) {
|
||
const p = parts[i];
|
||
const nextP = parts[i + 1];
|
||
const pattern = getPattern(p, nextP);
|
||
const key = Array.isArray(pattern) ? pattern[0] : p;
|
||
if (key in curNode.#children) {
|
||
curNode = curNode.#children[key];
|
||
if (pattern) {
|
||
possibleKeys.push(pattern[1]);
|
||
}
|
||
continue;
|
||
}
|
||
curNode.#children[key] = new _Node2();
|
||
if (pattern) {
|
||
curNode.#patterns.push(pattern);
|
||
possibleKeys.push(pattern[1]);
|
||
}
|
||
curNode = curNode.#children[key];
|
||
}
|
||
curNode.#methods.push({
|
||
[method]: {
|
||
handler,
|
||
possibleKeys: possibleKeys.filter((v, i, a) => a.indexOf(v) === i),
|
||
score: this.#order
|
||
}
|
||
});
|
||
return curNode;
|
||
}
|
||
#pushHandlerSets(handlerSets, node, method, nodeParams, params) {
|
||
for (let i = 0, len = node.#methods.length; i < len; i++) {
|
||
const m = node.#methods[i];
|
||
const handlerSet = m[method] || m[METHOD_NAME_ALL];
|
||
const processedSet = {};
|
||
if (handlerSet !== void 0) {
|
||
handlerSet.params = /* @__PURE__ */ Object.create(null);
|
||
handlerSets.push(handlerSet);
|
||
if (nodeParams !== emptyParams || params && params !== emptyParams) {
|
||
for (let i2 = 0, len2 = handlerSet.possibleKeys.length; i2 < len2; i2++) {
|
||
const key = handlerSet.possibleKeys[i2];
|
||
const processed = processedSet[handlerSet.score];
|
||
handlerSet.params[key] = params?.[key] && !processed ? params[key] : nodeParams[key] ?? params?.[key];
|
||
processedSet[handlerSet.score] = true;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
search(method, path) {
|
||
const handlerSets = [];
|
||
this.#params = emptyParams;
|
||
const curNode = this;
|
||
let curNodes = [curNode];
|
||
const parts = splitPath(path);
|
||
const curNodesQueue = [];
|
||
const len = parts.length;
|
||
let partOffsets = null;
|
||
for (let i = 0; i < len; i++) {
|
||
const part = parts[i];
|
||
const isLast = i === len - 1;
|
||
const tempNodes = [];
|
||
for (let j = 0, len2 = curNodes.length; j < len2; j++) {
|
||
const node = curNodes[j];
|
||
const nextNode = node.#children[part];
|
||
if (nextNode) {
|
||
nextNode.#params = node.#params;
|
||
if (isLast) {
|
||
if (nextNode.#children["*"]) {
|
||
this.#pushHandlerSets(handlerSets, nextNode.#children["*"], method, node.#params);
|
||
}
|
||
this.#pushHandlerSets(handlerSets, nextNode, method, node.#params);
|
||
} else {
|
||
tempNodes.push(nextNode);
|
||
}
|
||
}
|
||
for (let k = 0, len3 = node.#patterns.length; k < len3; k++) {
|
||
const pattern = node.#patterns[k];
|
||
const params = node.#params === emptyParams ? {} : { ...node.#params };
|
||
if (pattern === "*") {
|
||
const astNode = node.#children["*"];
|
||
if (astNode) {
|
||
this.#pushHandlerSets(handlerSets, astNode, method, node.#params);
|
||
astNode.#params = params;
|
||
tempNodes.push(astNode);
|
||
}
|
||
continue;
|
||
}
|
||
const [key, name, matcher] = pattern;
|
||
if (!part && !(matcher instanceof RegExp)) {
|
||
continue;
|
||
}
|
||
const child = node.#children[key];
|
||
if (matcher instanceof RegExp) {
|
||
if (partOffsets === null) {
|
||
partOffsets = new Array(len);
|
||
let offset = path[0] === "/" ? 1 : 0;
|
||
for (let p = 0; p < len; p++) {
|
||
partOffsets[p] = offset;
|
||
offset += parts[p].length + 1;
|
||
}
|
||
}
|
||
const restPathString = path.substring(partOffsets[i]);
|
||
const m = matcher.exec(restPathString);
|
||
if (m) {
|
||
params[name] = m[0];
|
||
this.#pushHandlerSets(handlerSets, child, method, node.#params, params);
|
||
if (hasChildren(child.#children)) {
|
||
child.#params = params;
|
||
const componentCount = m[0].match(/\//)?.length ?? 0;
|
||
const targetCurNodes = curNodesQueue[componentCount] ||= [];
|
||
targetCurNodes.push(child);
|
||
}
|
||
continue;
|
||
}
|
||
}
|
||
if (matcher === true || matcher.test(part)) {
|
||
params[name] = part;
|
||
if (isLast) {
|
||
this.#pushHandlerSets(handlerSets, child, method, params, node.#params);
|
||
if (child.#children["*"]) {
|
||
this.#pushHandlerSets(
|
||
handlerSets,
|
||
child.#children["*"],
|
||
method,
|
||
params,
|
||
node.#params
|
||
);
|
||
}
|
||
} else {
|
||
child.#params = params;
|
||
tempNodes.push(child);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
const shifted = curNodesQueue.shift();
|
||
curNodes = shifted ? tempNodes.concat(shifted) : tempNodes;
|
||
}
|
||
if (handlerSets.length > 1) {
|
||
handlerSets.sort((a, b) => {
|
||
return a.score - b.score;
|
||
});
|
||
}
|
||
return [handlerSets.map(({ handler, params }) => [handler, params])];
|
||
}
|
||
};
|
||
|
||
// node_modules/.pnpm/hono@4.12.14/node_modules/hono/dist/router/trie-router/router.js
|
||
var TrieRouter = class {
|
||
static {
|
||
__name(this, "TrieRouter");
|
||
}
|
||
name = "TrieRouter";
|
||
#node;
|
||
constructor() {
|
||
this.#node = new Node2();
|
||
}
|
||
add(method, path, handler) {
|
||
const results = checkOptionalParameter(path);
|
||
if (results) {
|
||
for (let i = 0, len = results.length; i < len; i++) {
|
||
this.#node.insert(method, results[i], handler);
|
||
}
|
||
return;
|
||
}
|
||
this.#node.insert(method, path, handler);
|
||
}
|
||
match(method, path) {
|
||
return this.#node.search(method, path);
|
||
}
|
||
};
|
||
|
||
// node_modules/.pnpm/hono@4.12.14/node_modules/hono/dist/hono.js
|
||
var Hono2 = class extends Hono {
|
||
static {
|
||
__name(this, "Hono");
|
||
}
|
||
/**
|
||
* Creates an instance of the Hono class.
|
||
*
|
||
* @param options - Optional configuration options for the Hono instance.
|
||
*/
|
||
constructor(options = {}) {
|
||
super(options);
|
||
this.router = options.router ?? new SmartRouter({
|
||
routers: [new RegExpRouter(), new TrieRouter()]
|
||
});
|
||
}
|
||
};
|
||
|
||
// node_modules/.pnpm/hono@4.12.14/node_modules/hono/dist/middleware/cors/index.js
|
||
var cors = /* @__PURE__ */ __name((options) => {
|
||
const defaults = {
|
||
origin: "*",
|
||
allowMethods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH"],
|
||
allowHeaders: [],
|
||
exposeHeaders: []
|
||
};
|
||
const opts = {
|
||
...defaults,
|
||
...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;
|
||
}
|
||
} else if (typeof optsOrigin === "function") {
|
||
return optsOrigin;
|
||
} else {
|
||
return (origin) => optsOrigin.includes(origin) ? origin : null;
|
||
}
|
||
})(opts.origin);
|
||
const findAllowMethods = ((optsAllowMethods) => {
|
||
if (typeof optsAllowMethods === "function") {
|
||
return optsAllowMethods;
|
||
} else if (Array.isArray(optsAllowMethods)) {
|
||
return () => optsAllowMethods;
|
||
} else {
|
||
return () => [];
|
||
}
|
||
})(opts.allowMethods);
|
||
return /* @__PURE__ */ __name(async function cors2(c, next) {
|
||
function set(key, value) {
|
||
c.res.headers.set(key, value);
|
||
}
|
||
__name(set, "set");
|
||
const allowOrigin = await findAllowOrigin(c.req.header("origin") || "", c);
|
||
if (allowOrigin) {
|
||
set("Access-Control-Allow-Origin", allowOrigin);
|
||
}
|
||
if (opts.credentials) {
|
||
set("Access-Control-Allow-Credentials", "true");
|
||
}
|
||
if (opts.exposeHeaders?.length) {
|
||
set("Access-Control-Expose-Headers", opts.exposeHeaders.join(","));
|
||
}
|
||
if (c.req.method === "OPTIONS") {
|
||
if (opts.origin !== "*" || opts.credentials) {
|
||
set("Vary", "Origin");
|
||
}
|
||
if (opts.maxAge != null) {
|
||
set("Access-Control-Max-Age", opts.maxAge.toString());
|
||
}
|
||
const allowMethods = await findAllowMethods(c.req.header("origin") || "", c);
|
||
if (allowMethods.length) {
|
||
set("Access-Control-Allow-Methods", allowMethods.join(","));
|
||
}
|
||
let headers = opts.allowHeaders;
|
||
if (!headers?.length) {
|
||
const requestHeaders = c.req.header("Access-Control-Request-Headers");
|
||
if (requestHeaders) {
|
||
headers = requestHeaders.split(/\s*,\s*/);
|
||
}
|
||
}
|
||
if (headers?.length) {
|
||
set("Access-Control-Allow-Headers", headers.join(","));
|
||
c.res.headers.append("Vary", "Access-Control-Request-Headers");
|
||
}
|
||
c.res.headers.delete("Content-Length");
|
||
c.res.headers.delete("Content-Type");
|
||
return new Response(null, {
|
||
headers: c.res.headers,
|
||
status: 204,
|
||
statusText: "No Content"
|
||
});
|
||
}
|
||
await next();
|
||
if (opts.origin !== "*" || opts.credentials) {
|
||
c.header("Vary", "Origin", { append: true });
|
||
}
|
||
}, "cors2");
|
||
}, "cors");
|
||
|
||
// ../../cypher-executor/src/lib/wasi-shim.ts
|
||
var WASI_ESUCCESS = 0;
|
||
var WASI_ENOSYS = 76;
|
||
var FD_STDIN = 0;
|
||
var FD_STDOUT = 1;
|
||
var FD_STDERR = 2;
|
||
function createWasiShim(stdinData, hostFunctions) {
|
||
const stdinBytes = new TextEncoder().encode(stdinData);
|
||
let stdinOffset = 0;
|
||
const stdoutChunks = [];
|
||
const stderrChunks = [];
|
||
let memory = null;
|
||
function getMemoryView() {
|
||
if (!memory) throw new Error("WASI memory not set \u2014 call setMemory() after instantiate");
|
||
return new DataView(memory.buffer);
|
||
}
|
||
__name(getMemoryView, "getMemoryView");
|
||
function writeOut(buf, outPtr, outLenPtr, data) {
|
||
try {
|
||
new Uint8Array(buf, outPtr, data.length).set(data);
|
||
new DataView(buf).setUint32(outLenPtr, data.length, true);
|
||
return 0;
|
||
} catch {
|
||
return 1;
|
||
}
|
||
}
|
||
__name(writeOut, "writeOut");
|
||
function fd_write(fd, iovs, iovs_len, nwritten_ptr) {
|
||
if (fd !== FD_STDOUT && fd !== FD_STDERR) return WASI_ENOSYS;
|
||
const view = getMemoryView();
|
||
const buf = memory.buffer;
|
||
let totalWritten = 0;
|
||
for (let i = 0; i < iovs_len; i++) {
|
||
const iov_base = view.getUint32(iovs + i * 8, true);
|
||
const iov_len = view.getUint32(iovs + i * 8 + 4, true);
|
||
if (iov_len === 0) continue;
|
||
const chunk = new Uint8Array(buf, iov_base, iov_len);
|
||
const copy = new Uint8Array(iov_len);
|
||
copy.set(chunk);
|
||
if (fd === FD_STDOUT) stdoutChunks.push(copy);
|
||
else stderrChunks.push(copy);
|
||
totalWritten += iov_len;
|
||
}
|
||
view.setUint32(nwritten_ptr, totalWritten, true);
|
||
return WASI_ESUCCESS;
|
||
}
|
||
__name(fd_write, "fd_write");
|
||
function fd_read(fd, iovs, iovs_len, nread_ptr) {
|
||
if (fd !== FD_STDIN) return WASI_ENOSYS;
|
||
const view = getMemoryView();
|
||
const buf = memory.buffer;
|
||
let totalRead = 0;
|
||
for (let i = 0; i < iovs_len; i++) {
|
||
const iov_base = view.getUint32(iovs + i * 8, true);
|
||
const iov_len = view.getUint32(iovs + i * 8 + 4, true);
|
||
if (iov_len === 0) continue;
|
||
const remaining = stdinBytes.length - stdinOffset;
|
||
if (remaining <= 0) break;
|
||
const toCopy = Math.min(iov_len, remaining);
|
||
const dest = new Uint8Array(buf, iov_base, toCopy);
|
||
dest.set(stdinBytes.subarray(stdinOffset, stdinOffset + toCopy));
|
||
stdinOffset += toCopy;
|
||
totalRead += toCopy;
|
||
}
|
||
view.setUint32(nread_ptr, totalRead, true);
|
||
return WASI_ESUCCESS;
|
||
}
|
||
__name(fd_read, "fd_read");
|
||
function proc_exit(code) {
|
||
throw new Error(`wasm exit: ${code}`);
|
||
}
|
||
__name(proc_exit, "proc_exit");
|
||
function random_get(buf_ptr, buf_len) {
|
||
const view = new Uint8Array(memory.buffer, buf_ptr, buf_len);
|
||
crypto.getRandomValues(view);
|
||
return WASI_ESUCCESS;
|
||
}
|
||
__name(random_get, "random_get");
|
||
let asyncifyDataPtr = 0;
|
||
const ASYNCIFY_BUF_SIZE = 1024 * 1024;
|
||
let asyncifyPendingPromise = null;
|
||
let asyncifyResult = 0;
|
||
let asyncifyExports = null;
|
||
function jspiSuspending(fn) {
|
||
const SuspendingCtor = WebAssembly["Suspending"];
|
||
return SuspendingCtor ? new SuspendingCtor(fn) : fn;
|
||
}
|
||
__name(jspiSuspending, "jspiSuspending");
|
||
function asyncifyWrap(fn) {
|
||
return (...args) => {
|
||
if (!memory) return 1;
|
||
const ax = asyncifyExports;
|
||
if (!ax) return 0;
|
||
const state = ax.get_state();
|
||
if (state === 2) {
|
||
return asyncifyResult;
|
||
}
|
||
if (state === 1) {
|
||
return 0;
|
||
}
|
||
asyncifyPendingPromise = fn(...args);
|
||
ax.start_unwind(asyncifyDataPtr);
|
||
return 0;
|
||
};
|
||
}
|
||
__name(asyncifyWrap, "asyncifyWrap");
|
||
function hostWrap(fn) {
|
||
const SuspendingCtor = WebAssembly["Suspending"];
|
||
if (SuspendingCtor) {
|
||
return new SuspendingCtor(fn);
|
||
}
|
||
return asyncifyWrap(fn);
|
||
}
|
||
__name(hostWrap, "hostWrap");
|
||
const shim = {
|
||
imports: {
|
||
wasi_snapshot_preview1: {
|
||
fd_write,
|
||
fd_read,
|
||
proc_exit,
|
||
random_get,
|
||
// 其餘 syscall 回傳 ENOSYS(不允許網路/檔案系統操作)
|
||
fd_seek: /* @__PURE__ */ __name(() => WASI_ENOSYS, "fd_seek"),
|
||
fd_close: /* @__PURE__ */ __name(() => WASI_ESUCCESS, "fd_close"),
|
||
fd_fdstat_get: /* @__PURE__ */ __name(() => WASI_ENOSYS, "fd_fdstat_get"),
|
||
fd_prestat_get: /* @__PURE__ */ __name(() => WASI_ENOSYS, "fd_prestat_get"),
|
||
fd_prestat_dir_name: /* @__PURE__ */ __name(() => WASI_ENOSYS, "fd_prestat_dir_name"),
|
||
environ_get: /* @__PURE__ */ __name(() => WASI_ESUCCESS, "environ_get"),
|
||
environ_sizes_get: /* @__PURE__ */ __name((count_ptr, size_ptr) => {
|
||
if (memory) {
|
||
const view = getMemoryView();
|
||
view.setUint32(count_ptr, 0, true);
|
||
view.setUint32(size_ptr, 0, true);
|
||
}
|
||
return WASI_ESUCCESS;
|
||
}, "environ_sizes_get"),
|
||
args_get: /* @__PURE__ */ __name(() => WASI_ESUCCESS, "args_get"),
|
||
args_sizes_get: /* @__PURE__ */ __name((argc_ptr, argv_buf_size_ptr) => {
|
||
if (memory) {
|
||
const view = getMemoryView();
|
||
view.setUint32(argc_ptr, 0, true);
|
||
view.setUint32(argv_buf_size_ptr, 0, true);
|
||
}
|
||
return WASI_ESUCCESS;
|
||
}, "args_sizes_get"),
|
||
clock_time_get: /* @__PURE__ */ __name((id, precision, time_ptr) => {
|
||
if (memory) {
|
||
const view = getMemoryView();
|
||
const now = BigInt(Date.now()) * 1000000n;
|
||
view.setBigUint64(time_ptr, now, true);
|
||
}
|
||
return WASI_ESUCCESS;
|
||
}, "clock_time_get"),
|
||
clock_res_get: /* @__PURE__ */ __name(() => WASI_ENOSYS, "clock_res_get"),
|
||
poll_oneoff: /* @__PURE__ */ __name(() => WASI_ENOSYS, "poll_oneoff"),
|
||
sched_yield: /* @__PURE__ */ __name(() => WASI_ESUCCESS, "sched_yield"),
|
||
proc_raise: /* @__PURE__ */ __name(() => WASI_ENOSYS, "proc_raise"),
|
||
sock_accept: /* @__PURE__ */ __name(() => WASI_ENOSYS, "sock_accept"),
|
||
sock_recv: /* @__PURE__ */ __name(() => WASI_ENOSYS, "sock_recv"),
|
||
sock_send: /* @__PURE__ */ __name(() => WASI_ENOSYS, "sock_send"),
|
||
sock_shutdown: /* @__PURE__ */ __name(() => WASI_ENOSYS, "sock_shutdown"),
|
||
path_open: /* @__PURE__ */ __name(() => WASI_ENOSYS, "path_open"),
|
||
path_create_directory: /* @__PURE__ */ __name(() => WASI_ENOSYS, "path_create_directory"),
|
||
path_remove_directory: /* @__PURE__ */ __name(() => WASI_ENOSYS, "path_remove_directory"),
|
||
path_rename: /* @__PURE__ */ __name(() => WASI_ENOSYS, "path_rename"),
|
||
path_unlink_file: /* @__PURE__ */ __name(() => WASI_ENOSYS, "path_unlink_file"),
|
||
path_filestat_get: /* @__PURE__ */ __name(() => WASI_ENOSYS, "path_filestat_get"),
|
||
path_readlink: /* @__PURE__ */ __name(() => WASI_ENOSYS, "path_readlink"),
|
||
path_symlink: /* @__PURE__ */ __name(() => WASI_ENOSYS, "path_symlink"),
|
||
path_link: /* @__PURE__ */ __name(() => WASI_ENOSYS, "path_link")
|
||
},
|
||
// u6u host functions:讓 .wasm 零件透過 host function 呼叫外部服務
|
||
// .wasm 零件用 //go:wasmimport u6u <name> 宣告
|
||
// 所有 async host function 透過 asyncifyWrap 包裝,實作 asyncify 協議
|
||
u6u: {
|
||
http_request: hostFunctions?.http_request ? hostWrap(async (urlPtr, urlLen, methodPtr, methodLen, headersPtr, headersLen, bodyPtr, bodyLen, outPtr, outLenPtr) => {
|
||
if (!memory) return 1;
|
||
const snapBuf = memory.buffer;
|
||
const dec = new TextDecoder();
|
||
const url = dec.decode(new Uint8Array(snapBuf, urlPtr, urlLen));
|
||
const method = dec.decode(new Uint8Array(snapBuf, methodPtr, methodLen));
|
||
const headers = dec.decode(new Uint8Array(snapBuf, headersPtr, headersLen));
|
||
const body = dec.decode(new Uint8Array(snapBuf, bodyPtr, bodyLen));
|
||
try {
|
||
const result = await hostFunctions.http_request(url, method, headers, body);
|
||
return writeOut(memory.buffer, outPtr, outLenPtr, new TextEncoder().encode(result));
|
||
} catch {
|
||
return 1;
|
||
}
|
||
}) : () => 1,
|
||
// kv_get(keyPtr, keyLen, outPtr, outLenPtr) → 0 成功;1 錯誤;2 找不到 key
|
||
kv_get: hostFunctions?.kv_get ? hostWrap(async (keyPtr, keyLen, outPtr, outLenPtr) => {
|
||
if (!memory) {
|
||
console.error("[kv_get] memory null");
|
||
return 1;
|
||
}
|
||
const key = new TextDecoder().decode(new Uint8Array(memory.buffer, keyPtr, keyLen));
|
||
console.error(`[kv_get] key="${key}" keyPtr=${keyPtr} keyLen=${keyLen} outPtr=${outPtr} outLenPtr=${outLenPtr}`);
|
||
try {
|
||
const result = await hostFunctions.kv_get(key);
|
||
console.error(`[kv_get] result=${result === null ? "null" : result.slice(0, 80)}`);
|
||
if (result === null) return 2;
|
||
const encoded = new TextEncoder().encode(result);
|
||
const status = writeOut(memory.buffer, outPtr, outLenPtr, encoded);
|
||
console.error(`[kv_get] writeOut status=${status} encodedLen=${encoded.length} memBufLen=${memory.buffer.byteLength}`);
|
||
return status;
|
||
} catch (e) {
|
||
console.error(`[kv_get] error: ${e}`);
|
||
return 1;
|
||
}
|
||
}) : () => 1,
|
||
// secret_get(refPtr, refLen, outPtr, outLenPtr) → 0 成功;1 錯誤;2 找不到 ref
|
||
// 與 kv_get 同款 pointer/memory-write 機制;差別只在 host 端實作來源(env[ref] 而非 KV.get)。
|
||
secret_get: hostFunctions?.secret_get ? hostWrap(async (refPtr, refLen, outPtr, outLenPtr) => {
|
||
if (!memory) return 1;
|
||
const ref2 = new TextDecoder().decode(new Uint8Array(memory.buffer, refPtr, refLen));
|
||
try {
|
||
const result = await hostFunctions.secret_get(ref2);
|
||
if (result === null) return 2;
|
||
const encoded = new TextEncoder().encode(result);
|
||
return writeOut(memory.buffer, outPtr, outLenPtr, encoded);
|
||
} catch {
|
||
return 1;
|
||
}
|
||
}) : () => 1,
|
||
// kv_put(keyPtr, keyLen, valPtr, valLen, ttlSeconds) → 0 成功;1 錯誤
|
||
kv_put: hostFunctions?.kv_put ? hostWrap(async (keyPtr, keyLen, valPtr, valLen, ttlSeconds) => {
|
||
if (!memory) return 1;
|
||
const dec = new TextDecoder();
|
||
const key = dec.decode(new Uint8Array(memory.buffer, keyPtr, keyLen));
|
||
const value = dec.decode(new Uint8Array(memory.buffer, valPtr, valLen));
|
||
try {
|
||
await hostFunctions.kv_put(key, value, ttlSeconds);
|
||
return 0;
|
||
} catch {
|
||
return 1;
|
||
}
|
||
}) : () => 1,
|
||
// crypto_decrypt — 已停用,永遠回 1(失敗)。
|
||
//
|
||
// ⚠️ 不能整條移除:現役 auth_static_key / auth_service_account / auth_oauth2 的
|
||
// .wasm 仍宣告 `//go:wasmimport u6u crypto_decrypt`,import 缺項會讓 WASM
|
||
// **instantiate 直接失敗**(不是呼叫才失敗)→ 所有認證零件全掛。故保留成 stub,
|
||
// 讓連結成立。待三個零件的 Go 原始碼移除該 wasmimport 並重編 wasm 後,才可刪掉這條。
|
||
crypto_decrypt: /* @__PURE__ */ __name(() => 1, "crypto_decrypt"),
|
||
// crypto_sign_rs256(dataPtr, dataLen, pkcs8Ptr, pkcs8Len, outPtr, outLenPtr) → 0 成功
|
||
crypto_sign_rs256: hostFunctions?.crypto_sign_rs256 ? hostWrap(async (dataPtr, dataLen, pkcs8Ptr, pkcs8Len, outPtr, outLenPtr) => {
|
||
if (!memory) return 1;
|
||
const data = new Uint8Array(new Uint8Array(memory.buffer, dataPtr, dataLen));
|
||
const pkcs8 = new Uint8Array(new Uint8Array(memory.buffer, pkcs8Ptr, pkcs8Len));
|
||
try {
|
||
const sig = await hostFunctions.crypto_sign_rs256(data, pkcs8);
|
||
return writeOut(memory.buffer, outPtr, outLenPtr, sig);
|
||
} catch {
|
||
return 1;
|
||
}
|
||
}) : () => 1
|
||
}
|
||
},
|
||
setMemory(mem) {
|
||
memory = mem;
|
||
},
|
||
async run(instance) {
|
||
const exp = instance.exports;
|
||
const startFn = exp._start ?? exp.main;
|
||
if (typeof startFn !== "function") throw new Error("WASM missing _start or main export");
|
||
const promisingFn = WebAssembly["promising"];
|
||
if (promisingFn) {
|
||
try {
|
||
await promisingFn(startFn)();
|
||
} catch (e) {
|
||
if (!(e instanceof Error && e.message === "wasm exit: 0")) throw e;
|
||
}
|
||
return;
|
||
}
|
||
const asyncifyGetState = exp.asyncify_get_state;
|
||
const asyncifyStartUnwind = exp.asyncify_start_unwind;
|
||
const asyncifyStopUnwind = exp.asyncify_stop_unwind;
|
||
const asyncifyStartRewind = exp.asyncify_start_rewind;
|
||
const asyncifyStopRewind = exp.asyncify_stop_rewind;
|
||
if (asyncifyGetState && asyncifyStartUnwind && asyncifyStopUnwind && asyncifyStartRewind && asyncifyStopRewind) {
|
||
asyncifyExports = {
|
||
get_state: asyncifyGetState,
|
||
start_unwind: asyncifyStartUnwind,
|
||
stop_unwind: asyncifyStopUnwind,
|
||
start_rewind: asyncifyStartRewind,
|
||
stop_rewind: asyncifyStopRewind
|
||
};
|
||
const mallocFn = exp.malloc;
|
||
if (mallocFn && memory) {
|
||
const totalSize = ASYNCIFY_BUF_SIZE;
|
||
asyncifyDataPtr = mallocFn(totalSize);
|
||
const view = new DataView(memory.buffer);
|
||
view.setInt32(asyncifyDataPtr, asyncifyDataPtr + 8, true);
|
||
view.setInt32(asyncifyDataPtr + 4, asyncifyDataPtr + totalSize, true);
|
||
} else if (memory) {
|
||
const memBytes = memory.buffer.byteLength;
|
||
asyncifyDataPtr = memBytes - ASYNCIFY_BUF_SIZE;
|
||
if (asyncifyDataPtr > 8) {
|
||
const view = new DataView(memory.buffer);
|
||
view.setInt32(asyncifyDataPtr, asyncifyDataPtr + 8, true);
|
||
view.setInt32(asyncifyDataPtr + 4, asyncifyDataPtr + ASYNCIFY_BUF_SIZE, true);
|
||
}
|
||
}
|
||
}
|
||
if (!asyncifyExports) {
|
||
try {
|
||
startFn();
|
||
} catch (e) {
|
||
if (!(e instanceof Error && e.message === "wasm exit: 0")) throw e;
|
||
}
|
||
return;
|
||
}
|
||
let rewinding = false;
|
||
while (true) {
|
||
asyncifyPendingPromise = null;
|
||
try {
|
||
if (rewinding) {
|
||
asyncifyExports.start_rewind(asyncifyDataPtr);
|
||
startFn();
|
||
asyncifyExports.stop_rewind();
|
||
} else {
|
||
startFn();
|
||
}
|
||
} catch (e) {
|
||
if (e instanceof Error && e.message === "wasm exit: 0") break;
|
||
throw e;
|
||
}
|
||
if (asyncifyPendingPromise !== null) {
|
||
asyncifyExports.stop_unwind();
|
||
asyncifyResult = await asyncifyPendingPromise;
|
||
asyncifyPendingPromise = null;
|
||
rewinding = true;
|
||
continue;
|
||
}
|
||
break;
|
||
}
|
||
},
|
||
getStdout() {
|
||
if (stdoutChunks.length === 0) return "";
|
||
const total = stdoutChunks.reduce((n, c) => n + c.length, 0);
|
||
const merged = new Uint8Array(total);
|
||
let offset = 0;
|
||
for (const chunk of stdoutChunks) {
|
||
merged.set(chunk, offset);
|
||
offset += chunk.length;
|
||
}
|
||
return new TextDecoder().decode(merged);
|
||
},
|
||
getStderr() {
|
||
if (stderrChunks.length === 0) return "";
|
||
const total = stderrChunks.reduce((n, c) => n + c.length, 0);
|
||
const merged = new Uint8Array(total);
|
||
let offset = 0;
|
||
for (const chunk of stderrChunks) {
|
||
merged.set(chunk, offset);
|
||
offset += chunk.length;
|
||
}
|
||
return new TextDecoder().decode(merged);
|
||
}
|
||
};
|
||
return shim;
|
||
}
|
||
__name(createWasiShim, "createWasiShim");
|
||
|
||
// src/index.ts
|
||
var app = new Hono2();
|
||
app.use("*", cors());
|
||
app.get("/", (c) => c.json({ ok: true, component: "cron" }));
|
||
app.post("/", async (c) => {
|
||
let input;
|
||
try {
|
||
input = await c.req.json();
|
||
} catch {
|
||
return c.json({ success: false, error: "request body must be JSON" }, 400);
|
||
}
|
||
try {
|
||
const result = await runWasm(input);
|
||
return c.json(result);
|
||
} catch (e) {
|
||
return c.json(
|
||
{ success: false, error: e instanceof Error ? e.message : String(e) },
|
||
500
|
||
);
|
||
}
|
||
});
|
||
var index_default = app;
|
||
async function runWasm(input) {
|
||
const shim = createWasiShim(JSON.stringify(input));
|
||
const instance = await WebAssembly.instantiate(
|
||
componentWasm,
|
||
shim.imports
|
||
);
|
||
shim.setMemory(instance.exports.memory);
|
||
await shim.run(instance);
|
||
const stdout2 = shim.getStdout().trim();
|
||
if (!stdout2) throw new Error("WASM component produced no output");
|
||
return JSON.parse(stdout2);
|
||
}
|
||
__name(runWasm, "runWasm");
|
||
export {
|
||
index_default as default
|
||
};
|
||
//# sourceMappingURL=index.js.map
|