@jcyamacho/agent-memory 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -0
- package/dist/index.js +3577 -23
- package/package.json +3 -1
package/dist/index.js
CHANGED
|
@@ -12464,15 +12464,29 @@ class StdioServerTransport {
|
|
|
12464
12464
|
}
|
|
12465
12465
|
}
|
|
12466
12466
|
// package.json
|
|
12467
|
-
var version2 = "0.0.
|
|
12467
|
+
var version2 = "0.0.7";
|
|
12468
12468
|
|
|
12469
12469
|
// src/config.ts
|
|
12470
12470
|
import { homedir } from "node:os";
|
|
12471
12471
|
import { join } from "node:path";
|
|
12472
|
+
import { parseArgs } from "node:util";
|
|
12472
12473
|
var AGENT_MEMORY_DB_PATH_ENV = "AGENT_MEMORY_DB_PATH";
|
|
12473
|
-
var
|
|
12474
|
-
|
|
12475
|
-
}
|
|
12474
|
+
var DEFAULT_UI_PORT = 6580;
|
|
12475
|
+
var resolveConfig = (environment = process.env, argv = process.argv.slice(2)) => {
|
|
12476
|
+
const { values } = parseArgs({
|
|
12477
|
+
args: argv,
|
|
12478
|
+
options: {
|
|
12479
|
+
ui: { type: "boolean", default: false },
|
|
12480
|
+
port: { type: "string", default: String(DEFAULT_UI_PORT) }
|
|
12481
|
+
},
|
|
12482
|
+
strict: false
|
|
12483
|
+
});
|
|
12484
|
+
return {
|
|
12485
|
+
databasePath: environment[AGENT_MEMORY_DB_PATH_ENV] || join(homedir(), ".config", "agent-memory", "memory.db"),
|
|
12486
|
+
uiMode: Boolean(values.ui),
|
|
12487
|
+
uiPort: Number(values.port) || DEFAULT_UI_PORT
|
|
12488
|
+
};
|
|
12489
|
+
};
|
|
12476
12490
|
|
|
12477
12491
|
// node_modules/zod/v3/helpers/util.js
|
|
12478
12492
|
var util;
|
|
@@ -19901,6 +19915,13 @@ class ValidationError extends MemoryError {
|
|
|
19901
19915
|
}
|
|
19902
19916
|
}
|
|
19903
19917
|
|
|
19918
|
+
class NotFoundError extends MemoryError {
|
|
19919
|
+
constructor(message) {
|
|
19920
|
+
super("NOT_FOUND", message);
|
|
19921
|
+
this.name = "NotFoundError";
|
|
19922
|
+
}
|
|
19923
|
+
}
|
|
19924
|
+
|
|
19904
19925
|
class PersistenceError extends MemoryError {
|
|
19905
19926
|
constructor(message, options) {
|
|
19906
19927
|
super("PERSISTENCE_ERROR", message, options);
|
|
@@ -20192,6 +20213,10 @@ var initializeMemoryDatabase = (database) => {
|
|
|
20192
20213
|
class SqliteMemoryRepository {
|
|
20193
20214
|
database;
|
|
20194
20215
|
insertStatement;
|
|
20216
|
+
findByIdStatement;
|
|
20217
|
+
updateStatement;
|
|
20218
|
+
deleteStatement;
|
|
20219
|
+
listWorkspacesStatement;
|
|
20195
20220
|
constructor(database) {
|
|
20196
20221
|
this.database = database;
|
|
20197
20222
|
this.insertStatement = database.prepare(`
|
|
@@ -20209,6 +20234,10 @@ class SqliteMemoryRepository {
|
|
|
20209
20234
|
?
|
|
20210
20235
|
)
|
|
20211
20236
|
`);
|
|
20237
|
+
this.findByIdStatement = database.prepare("SELECT id, content, workspace, created_at, updated_at FROM memories WHERE id = ?");
|
|
20238
|
+
this.updateStatement = database.prepare("UPDATE memories SET content = ?, updated_at = ? WHERE id = ?");
|
|
20239
|
+
this.deleteStatement = database.prepare("DELETE FROM memories WHERE id = ?");
|
|
20240
|
+
this.listWorkspacesStatement = database.prepare("SELECT DISTINCT workspace FROM memories WHERE workspace IS NOT NULL ORDER BY workspace");
|
|
20212
20241
|
}
|
|
20213
20242
|
async save(memory) {
|
|
20214
20243
|
try {
|
|
@@ -20248,12 +20277,8 @@ class SqliteMemoryRepository {
|
|
|
20248
20277
|
const rows = statement.all(...params);
|
|
20249
20278
|
const maxScore = Math.max(...rows.map((row) => row.score), 0);
|
|
20250
20279
|
return rows.map((row) => ({
|
|
20251
|
-
|
|
20252
|
-
|
|
20253
|
-
score: toNormalizedScore(maxScore > 0 ? row.score / maxScore : 0),
|
|
20254
|
-
workspace: row.workspace ?? undefined,
|
|
20255
|
-
createdAt: new Date(row.created_at),
|
|
20256
|
-
updatedAt: new Date(row.updated_at)
|
|
20280
|
+
...toMemoryRecord(row),
|
|
20281
|
+
score: toNormalizedScore(maxScore > 0 ? row.score / maxScore : 0)
|
|
20257
20282
|
}));
|
|
20258
20283
|
} catch (error2) {
|
|
20259
20284
|
throw new PersistenceError("Failed to search memories.", {
|
|
@@ -20261,7 +20286,87 @@ class SqliteMemoryRepository {
|
|
|
20261
20286
|
});
|
|
20262
20287
|
}
|
|
20263
20288
|
}
|
|
20289
|
+
async findById(id) {
|
|
20290
|
+
try {
|
|
20291
|
+
const rows = this.findByIdStatement.all(id);
|
|
20292
|
+
const row = rows[0];
|
|
20293
|
+
return row ? toMemoryRecord(row) : undefined;
|
|
20294
|
+
} catch (error2) {
|
|
20295
|
+
throw new PersistenceError("Failed to find memory.", { cause: error2 });
|
|
20296
|
+
}
|
|
20297
|
+
}
|
|
20298
|
+
async findAll(options) {
|
|
20299
|
+
try {
|
|
20300
|
+
const whereClauses = [];
|
|
20301
|
+
const params = [];
|
|
20302
|
+
if (options.workspace) {
|
|
20303
|
+
whereClauses.push("workspace = ?");
|
|
20304
|
+
params.push(options.workspace);
|
|
20305
|
+
} else if (options.workspaceIsNull) {
|
|
20306
|
+
whereClauses.push("workspace IS NULL");
|
|
20307
|
+
}
|
|
20308
|
+
const whereClause = whereClauses.length > 0 ? `WHERE ${whereClauses.join(" AND ")}` : "";
|
|
20309
|
+
const limit = options.limit + 1;
|
|
20310
|
+
params.push(limit, options.offset);
|
|
20311
|
+
const statement = this.database.prepare(`
|
|
20312
|
+
SELECT id, content, workspace, created_at, updated_at
|
|
20313
|
+
FROM memories
|
|
20314
|
+
${whereClause}
|
|
20315
|
+
ORDER BY created_at DESC
|
|
20316
|
+
LIMIT ? OFFSET ?
|
|
20317
|
+
`);
|
|
20318
|
+
const rows = statement.all(...params);
|
|
20319
|
+
const hasMore = rows.length > options.limit;
|
|
20320
|
+
const items = (hasMore ? rows.slice(0, options.limit) : rows).map(toMemoryRecord);
|
|
20321
|
+
return { items, hasMore };
|
|
20322
|
+
} catch (error2) {
|
|
20323
|
+
throw new PersistenceError("Failed to list memories.", { cause: error2 });
|
|
20324
|
+
}
|
|
20325
|
+
}
|
|
20326
|
+
async update(id, content) {
|
|
20327
|
+
let result;
|
|
20328
|
+
try {
|
|
20329
|
+
const now = Date.now();
|
|
20330
|
+
result = this.updateStatement.run(content, now, id);
|
|
20331
|
+
} catch (error2) {
|
|
20332
|
+
throw new PersistenceError("Failed to update memory.", { cause: error2 });
|
|
20333
|
+
}
|
|
20334
|
+
if (result.changes === 0) {
|
|
20335
|
+
throw new NotFoundError(`Memory not found: ${id}`);
|
|
20336
|
+
}
|
|
20337
|
+
const memory = await this.findById(id);
|
|
20338
|
+
if (!memory) {
|
|
20339
|
+
throw new NotFoundError(`Memory not found after update: ${id}`);
|
|
20340
|
+
}
|
|
20341
|
+
return memory;
|
|
20342
|
+
}
|
|
20343
|
+
async delete(id) {
|
|
20344
|
+
let result;
|
|
20345
|
+
try {
|
|
20346
|
+
result = this.deleteStatement.run(id);
|
|
20347
|
+
} catch (error2) {
|
|
20348
|
+
throw new PersistenceError("Failed to delete memory.", { cause: error2 });
|
|
20349
|
+
}
|
|
20350
|
+
if (result.changes === 0) {
|
|
20351
|
+
throw new NotFoundError(`Memory not found: ${id}`);
|
|
20352
|
+
}
|
|
20353
|
+
}
|
|
20354
|
+
async listWorkspaces() {
|
|
20355
|
+
try {
|
|
20356
|
+
const rows = this.listWorkspacesStatement.all();
|
|
20357
|
+
return rows.map((row) => row.workspace);
|
|
20358
|
+
} catch (error2) {
|
|
20359
|
+
throw new PersistenceError("Failed to list workspaces.", { cause: error2 });
|
|
20360
|
+
}
|
|
20361
|
+
}
|
|
20264
20362
|
}
|
|
20363
|
+
var toMemoryRecord = (row) => ({
|
|
20364
|
+
id: row.id,
|
|
20365
|
+
content: row.content,
|
|
20366
|
+
workspace: row.workspace ?? undefined,
|
|
20367
|
+
createdAt: new Date(row.created_at),
|
|
20368
|
+
updatedAt: new Date(row.updated_at)
|
|
20369
|
+
});
|
|
20265
20370
|
var toFtsQuery = (terms) => terms.map(toFtsTerm).join(" OR ");
|
|
20266
20371
|
var toFtsTerm = (term) => {
|
|
20267
20372
|
const escaped = term.replaceAll('"', '""');
|
|
@@ -20271,17 +20376,3466 @@ var toFtsTerm = (term) => {
|
|
|
20271
20376
|
return `"${escaped}"*`;
|
|
20272
20377
|
};
|
|
20273
20378
|
|
|
20274
|
-
// src/
|
|
20275
|
-
|
|
20276
|
-
|
|
20277
|
-
|
|
20278
|
-
|
|
20279
|
-
|
|
20280
|
-
|
|
20281
|
-
|
|
20282
|
-
|
|
20283
|
-
|
|
20284
|
-
|
|
20285
|
-
|
|
20286
|
-
|
|
20379
|
+
// src/ui/server.tsx
|
|
20380
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
20381
|
+
|
|
20382
|
+
// node_modules/@hono/node-server/dist/index.mjs
|
|
20383
|
+
import { createServer as createServerHTTP } from "http";
|
|
20384
|
+
import { Http2ServerRequest as Http2ServerRequest2 } from "http2";
|
|
20385
|
+
import { Http2ServerRequest } from "http2";
|
|
20386
|
+
import { Readable } from "stream";
|
|
20387
|
+
import crypto from "crypto";
|
|
20388
|
+
var RequestError = class extends Error {
|
|
20389
|
+
constructor(message, options) {
|
|
20390
|
+
super(message, options);
|
|
20391
|
+
this.name = "RequestError";
|
|
20392
|
+
}
|
|
20393
|
+
};
|
|
20394
|
+
var toRequestError = (e) => {
|
|
20395
|
+
if (e instanceof RequestError) {
|
|
20396
|
+
return e;
|
|
20397
|
+
}
|
|
20398
|
+
return new RequestError(e.message, { cause: e });
|
|
20399
|
+
};
|
|
20400
|
+
var GlobalRequest = global.Request;
|
|
20401
|
+
var Request2 = class extends GlobalRequest {
|
|
20402
|
+
constructor(input, options) {
|
|
20403
|
+
if (typeof input === "object" && getRequestCache in input) {
|
|
20404
|
+
input = input[getRequestCache]();
|
|
20405
|
+
}
|
|
20406
|
+
if (typeof options?.body?.getReader !== "undefined") {
|
|
20407
|
+
options.duplex ??= "half";
|
|
20408
|
+
}
|
|
20409
|
+
super(input, options);
|
|
20410
|
+
}
|
|
20411
|
+
};
|
|
20412
|
+
var newHeadersFromIncoming = (incoming) => {
|
|
20413
|
+
const headerRecord = [];
|
|
20414
|
+
const rawHeaders = incoming.rawHeaders;
|
|
20415
|
+
for (let i = 0;i < rawHeaders.length; i += 2) {
|
|
20416
|
+
const { [i]: key, [i + 1]: value } = rawHeaders;
|
|
20417
|
+
if (key.charCodeAt(0) !== 58) {
|
|
20418
|
+
headerRecord.push([key, value]);
|
|
20419
|
+
}
|
|
20420
|
+
}
|
|
20421
|
+
return new Headers(headerRecord);
|
|
20422
|
+
};
|
|
20423
|
+
var wrapBodyStream = Symbol("wrapBodyStream");
|
|
20424
|
+
var newRequestFromIncoming = (method, url, headers, incoming, abortController) => {
|
|
20425
|
+
const init = {
|
|
20426
|
+
method,
|
|
20427
|
+
headers,
|
|
20428
|
+
signal: abortController.signal
|
|
20429
|
+
};
|
|
20430
|
+
if (method === "TRACE") {
|
|
20431
|
+
init.method = "GET";
|
|
20432
|
+
const req = new Request2(url, init);
|
|
20433
|
+
Object.defineProperty(req, "method", {
|
|
20434
|
+
get() {
|
|
20435
|
+
return "TRACE";
|
|
20436
|
+
}
|
|
20437
|
+
});
|
|
20438
|
+
return req;
|
|
20439
|
+
}
|
|
20440
|
+
if (!(method === "GET" || method === "HEAD")) {
|
|
20441
|
+
if ("rawBody" in incoming && incoming.rawBody instanceof Buffer) {
|
|
20442
|
+
init.body = new ReadableStream({
|
|
20443
|
+
start(controller) {
|
|
20444
|
+
controller.enqueue(incoming.rawBody);
|
|
20445
|
+
controller.close();
|
|
20446
|
+
}
|
|
20447
|
+
});
|
|
20448
|
+
} else if (incoming[wrapBodyStream]) {
|
|
20449
|
+
let reader;
|
|
20450
|
+
init.body = new ReadableStream({
|
|
20451
|
+
async pull(controller) {
|
|
20452
|
+
try {
|
|
20453
|
+
reader ||= Readable.toWeb(incoming).getReader();
|
|
20454
|
+
const { done, value } = await reader.read();
|
|
20455
|
+
if (done) {
|
|
20456
|
+
controller.close();
|
|
20457
|
+
} else {
|
|
20458
|
+
controller.enqueue(value);
|
|
20459
|
+
}
|
|
20460
|
+
} catch (error2) {
|
|
20461
|
+
controller.error(error2);
|
|
20462
|
+
}
|
|
20463
|
+
}
|
|
20464
|
+
});
|
|
20465
|
+
} else {
|
|
20466
|
+
init.body = Readable.toWeb(incoming);
|
|
20467
|
+
}
|
|
20468
|
+
}
|
|
20469
|
+
return new Request2(url, init);
|
|
20470
|
+
};
|
|
20471
|
+
var getRequestCache = Symbol("getRequestCache");
|
|
20472
|
+
var requestCache = Symbol("requestCache");
|
|
20473
|
+
var incomingKey = Symbol("incomingKey");
|
|
20474
|
+
var urlKey = Symbol("urlKey");
|
|
20475
|
+
var headersKey = Symbol("headersKey");
|
|
20476
|
+
var abortControllerKey = Symbol("abortControllerKey");
|
|
20477
|
+
var getAbortController = Symbol("getAbortController");
|
|
20478
|
+
var requestPrototype = {
|
|
20479
|
+
get method() {
|
|
20480
|
+
return this[incomingKey].method || "GET";
|
|
20481
|
+
},
|
|
20482
|
+
get url() {
|
|
20483
|
+
return this[urlKey];
|
|
20484
|
+
},
|
|
20485
|
+
get headers() {
|
|
20486
|
+
return this[headersKey] ||= newHeadersFromIncoming(this[incomingKey]);
|
|
20487
|
+
},
|
|
20488
|
+
[getAbortController]() {
|
|
20489
|
+
this[getRequestCache]();
|
|
20490
|
+
return this[abortControllerKey];
|
|
20491
|
+
},
|
|
20492
|
+
[getRequestCache]() {
|
|
20493
|
+
this[abortControllerKey] ||= new AbortController;
|
|
20494
|
+
return this[requestCache] ||= newRequestFromIncoming(this.method, this[urlKey], this.headers, this[incomingKey], this[abortControllerKey]);
|
|
20495
|
+
}
|
|
20496
|
+
};
|
|
20497
|
+
[
|
|
20498
|
+
"body",
|
|
20499
|
+
"bodyUsed",
|
|
20500
|
+
"cache",
|
|
20501
|
+
"credentials",
|
|
20502
|
+
"destination",
|
|
20503
|
+
"integrity",
|
|
20504
|
+
"mode",
|
|
20505
|
+
"redirect",
|
|
20506
|
+
"referrer",
|
|
20507
|
+
"referrerPolicy",
|
|
20508
|
+
"signal",
|
|
20509
|
+
"keepalive"
|
|
20510
|
+
].forEach((k) => {
|
|
20511
|
+
Object.defineProperty(requestPrototype, k, {
|
|
20512
|
+
get() {
|
|
20513
|
+
return this[getRequestCache]()[k];
|
|
20514
|
+
}
|
|
20515
|
+
});
|
|
20516
|
+
});
|
|
20517
|
+
["arrayBuffer", "blob", "clone", "formData", "json", "text"].forEach((k) => {
|
|
20518
|
+
Object.defineProperty(requestPrototype, k, {
|
|
20519
|
+
value: function() {
|
|
20520
|
+
return this[getRequestCache]()[k]();
|
|
20521
|
+
}
|
|
20522
|
+
});
|
|
20523
|
+
});
|
|
20524
|
+
Object.setPrototypeOf(requestPrototype, Request2.prototype);
|
|
20525
|
+
var newRequest = (incoming, defaultHostname) => {
|
|
20526
|
+
const req = Object.create(requestPrototype);
|
|
20527
|
+
req[incomingKey] = incoming;
|
|
20528
|
+
const incomingUrl = incoming.url || "";
|
|
20529
|
+
if (incomingUrl[0] !== "/" && (incomingUrl.startsWith("http://") || incomingUrl.startsWith("https://"))) {
|
|
20530
|
+
if (incoming instanceof Http2ServerRequest) {
|
|
20531
|
+
throw new RequestError("Absolute URL for :path is not allowed in HTTP/2");
|
|
20532
|
+
}
|
|
20533
|
+
try {
|
|
20534
|
+
const url2 = new URL(incomingUrl);
|
|
20535
|
+
req[urlKey] = url2.href;
|
|
20536
|
+
} catch (e) {
|
|
20537
|
+
throw new RequestError("Invalid absolute URL", { cause: e });
|
|
20538
|
+
}
|
|
20539
|
+
return req;
|
|
20540
|
+
}
|
|
20541
|
+
const host = (incoming instanceof Http2ServerRequest ? incoming.authority : incoming.headers.host) || defaultHostname;
|
|
20542
|
+
if (!host) {
|
|
20543
|
+
throw new RequestError("Missing host header");
|
|
20544
|
+
}
|
|
20545
|
+
let scheme;
|
|
20546
|
+
if (incoming instanceof Http2ServerRequest) {
|
|
20547
|
+
scheme = incoming.scheme;
|
|
20548
|
+
if (!(scheme === "http" || scheme === "https")) {
|
|
20549
|
+
throw new RequestError("Unsupported scheme");
|
|
20550
|
+
}
|
|
20551
|
+
} else {
|
|
20552
|
+
scheme = incoming.socket && incoming.socket.encrypted ? "https" : "http";
|
|
20553
|
+
}
|
|
20554
|
+
const url = new URL(`${scheme}://${host}${incomingUrl}`);
|
|
20555
|
+
if (url.hostname.length !== host.length && url.hostname !== host.replace(/:\d+$/, "")) {
|
|
20556
|
+
throw new RequestError("Invalid host header");
|
|
20557
|
+
}
|
|
20558
|
+
req[urlKey] = url.href;
|
|
20559
|
+
return req;
|
|
20560
|
+
};
|
|
20561
|
+
var responseCache = Symbol("responseCache");
|
|
20562
|
+
var getResponseCache = Symbol("getResponseCache");
|
|
20563
|
+
var cacheKey = Symbol("cache");
|
|
20564
|
+
var GlobalResponse = global.Response;
|
|
20565
|
+
var Response2 = class _Response {
|
|
20566
|
+
#body;
|
|
20567
|
+
#init;
|
|
20568
|
+
[getResponseCache]() {
|
|
20569
|
+
delete this[cacheKey];
|
|
20570
|
+
return this[responseCache] ||= new GlobalResponse(this.#body, this.#init);
|
|
20571
|
+
}
|
|
20572
|
+
constructor(body, init) {
|
|
20573
|
+
let headers;
|
|
20574
|
+
this.#body = body;
|
|
20575
|
+
if (init instanceof _Response) {
|
|
20576
|
+
const cachedGlobalResponse = init[responseCache];
|
|
20577
|
+
if (cachedGlobalResponse) {
|
|
20578
|
+
this.#init = cachedGlobalResponse;
|
|
20579
|
+
this[getResponseCache]();
|
|
20580
|
+
return;
|
|
20581
|
+
} else {
|
|
20582
|
+
this.#init = init.#init;
|
|
20583
|
+
headers = new Headers(init.#init.headers);
|
|
20584
|
+
}
|
|
20585
|
+
} else {
|
|
20586
|
+
this.#init = init;
|
|
20587
|
+
}
|
|
20588
|
+
if (typeof body === "string" || typeof body?.getReader !== "undefined" || body instanceof Blob || body instanceof Uint8Array) {
|
|
20589
|
+
this[cacheKey] = [init?.status || 200, body, headers || init?.headers];
|
|
20590
|
+
}
|
|
20591
|
+
}
|
|
20592
|
+
get headers() {
|
|
20593
|
+
const cache = this[cacheKey];
|
|
20594
|
+
if (cache) {
|
|
20595
|
+
if (!(cache[2] instanceof Headers)) {
|
|
20596
|
+
cache[2] = new Headers(cache[2] || { "content-type": "text/plain; charset=UTF-8" });
|
|
20597
|
+
}
|
|
20598
|
+
return cache[2];
|
|
20599
|
+
}
|
|
20600
|
+
return this[getResponseCache]().headers;
|
|
20601
|
+
}
|
|
20602
|
+
get status() {
|
|
20603
|
+
return this[cacheKey]?.[0] ?? this[getResponseCache]().status;
|
|
20604
|
+
}
|
|
20605
|
+
get ok() {
|
|
20606
|
+
const status = this.status;
|
|
20607
|
+
return status >= 200 && status < 300;
|
|
20608
|
+
}
|
|
20609
|
+
};
|
|
20610
|
+
["body", "bodyUsed", "redirected", "statusText", "trailers", "type", "url"].forEach((k) => {
|
|
20611
|
+
Object.defineProperty(Response2.prototype, k, {
|
|
20612
|
+
get() {
|
|
20613
|
+
return this[getResponseCache]()[k];
|
|
20614
|
+
}
|
|
20615
|
+
});
|
|
20616
|
+
});
|
|
20617
|
+
["arrayBuffer", "blob", "clone", "formData", "json", "text"].forEach((k) => {
|
|
20618
|
+
Object.defineProperty(Response2.prototype, k, {
|
|
20619
|
+
value: function() {
|
|
20620
|
+
return this[getResponseCache]()[k]();
|
|
20621
|
+
}
|
|
20622
|
+
});
|
|
20623
|
+
});
|
|
20624
|
+
Object.setPrototypeOf(Response2, GlobalResponse);
|
|
20625
|
+
Object.setPrototypeOf(Response2.prototype, GlobalResponse.prototype);
|
|
20626
|
+
async function readWithoutBlocking(readPromise) {
|
|
20627
|
+
return Promise.race([readPromise, Promise.resolve().then(() => Promise.resolve(undefined))]);
|
|
20628
|
+
}
|
|
20629
|
+
function writeFromReadableStreamDefaultReader(reader, writable, currentReadPromise) {
|
|
20630
|
+
const cancel = (error2) => {
|
|
20631
|
+
reader.cancel(error2).catch(() => {});
|
|
20632
|
+
};
|
|
20633
|
+
writable.on("close", cancel);
|
|
20634
|
+
writable.on("error", cancel);
|
|
20635
|
+
(currentReadPromise ?? reader.read()).then(flow, handleStreamError);
|
|
20636
|
+
return reader.closed.finally(() => {
|
|
20637
|
+
writable.off("close", cancel);
|
|
20638
|
+
writable.off("error", cancel);
|
|
20639
|
+
});
|
|
20640
|
+
function handleStreamError(error2) {
|
|
20641
|
+
if (error2) {
|
|
20642
|
+
writable.destroy(error2);
|
|
20643
|
+
}
|
|
20644
|
+
}
|
|
20645
|
+
function onDrain() {
|
|
20646
|
+
reader.read().then(flow, handleStreamError);
|
|
20647
|
+
}
|
|
20648
|
+
function flow({ done, value }) {
|
|
20649
|
+
try {
|
|
20650
|
+
if (done) {
|
|
20651
|
+
writable.end();
|
|
20652
|
+
} else if (!writable.write(value)) {
|
|
20653
|
+
writable.once("drain", onDrain);
|
|
20654
|
+
} else {
|
|
20655
|
+
return reader.read().then(flow, handleStreamError);
|
|
20656
|
+
}
|
|
20657
|
+
} catch (e) {
|
|
20658
|
+
handleStreamError(e);
|
|
20659
|
+
}
|
|
20660
|
+
}
|
|
20661
|
+
}
|
|
20662
|
+
function writeFromReadableStream(stream, writable) {
|
|
20663
|
+
if (stream.locked) {
|
|
20664
|
+
throw new TypeError("ReadableStream is locked.");
|
|
20665
|
+
} else if (writable.destroyed) {
|
|
20666
|
+
return;
|
|
20667
|
+
}
|
|
20668
|
+
return writeFromReadableStreamDefaultReader(stream.getReader(), writable);
|
|
20669
|
+
}
|
|
20670
|
+
var buildOutgoingHttpHeaders = (headers) => {
|
|
20671
|
+
const res = {};
|
|
20672
|
+
if (!(headers instanceof Headers)) {
|
|
20673
|
+
headers = new Headers(headers ?? undefined);
|
|
20674
|
+
}
|
|
20675
|
+
const cookies = [];
|
|
20676
|
+
for (const [k, v] of headers) {
|
|
20677
|
+
if (k === "set-cookie") {
|
|
20678
|
+
cookies.push(v);
|
|
20679
|
+
} else {
|
|
20680
|
+
res[k] = v;
|
|
20681
|
+
}
|
|
20682
|
+
}
|
|
20683
|
+
if (cookies.length > 0) {
|
|
20684
|
+
res["set-cookie"] = cookies;
|
|
20685
|
+
}
|
|
20686
|
+
res["content-type"] ??= "text/plain; charset=UTF-8";
|
|
20687
|
+
return res;
|
|
20688
|
+
};
|
|
20689
|
+
var X_ALREADY_SENT = "x-hono-already-sent";
|
|
20690
|
+
if (typeof global.crypto === "undefined") {
|
|
20691
|
+
global.crypto = crypto;
|
|
20692
|
+
}
|
|
20693
|
+
var outgoingEnded = Symbol("outgoingEnded");
|
|
20694
|
+
var handleRequestError = () => new Response(null, {
|
|
20695
|
+
status: 400
|
|
20696
|
+
});
|
|
20697
|
+
var handleFetchError = (e) => new Response(null, {
|
|
20698
|
+
status: e instanceof Error && (e.name === "TimeoutError" || e.constructor.name === "TimeoutError") ? 504 : 500
|
|
20699
|
+
});
|
|
20700
|
+
var handleResponseError = (e, outgoing) => {
|
|
20701
|
+
const err = e instanceof Error ? e : new Error("unknown error", { cause: e });
|
|
20702
|
+
if (err.code === "ERR_STREAM_PREMATURE_CLOSE") {
|
|
20703
|
+
console.info("The user aborted a request.");
|
|
20704
|
+
} else {
|
|
20705
|
+
console.error(e);
|
|
20706
|
+
if (!outgoing.headersSent) {
|
|
20707
|
+
outgoing.writeHead(500, { "Content-Type": "text/plain" });
|
|
20708
|
+
}
|
|
20709
|
+
outgoing.end(`Error: ${err.message}`);
|
|
20710
|
+
outgoing.destroy(err);
|
|
20711
|
+
}
|
|
20712
|
+
};
|
|
20713
|
+
var flushHeaders = (outgoing) => {
|
|
20714
|
+
if ("flushHeaders" in outgoing && outgoing.writable) {
|
|
20715
|
+
outgoing.flushHeaders();
|
|
20716
|
+
}
|
|
20717
|
+
};
|
|
20718
|
+
var responseViaCache = async (res, outgoing) => {
|
|
20719
|
+
let [status, body, header] = res[cacheKey];
|
|
20720
|
+
let hasContentLength = false;
|
|
20721
|
+
if (!header) {
|
|
20722
|
+
header = { "content-type": "text/plain; charset=UTF-8" };
|
|
20723
|
+
} else if (header instanceof Headers) {
|
|
20724
|
+
hasContentLength = header.has("content-length");
|
|
20725
|
+
header = buildOutgoingHttpHeaders(header);
|
|
20726
|
+
} else if (Array.isArray(header)) {
|
|
20727
|
+
const headerObj = new Headers(header);
|
|
20728
|
+
hasContentLength = headerObj.has("content-length");
|
|
20729
|
+
header = buildOutgoingHttpHeaders(headerObj);
|
|
20730
|
+
} else {
|
|
20731
|
+
for (const key in header) {
|
|
20732
|
+
if (key.length === 14 && key.toLowerCase() === "content-length") {
|
|
20733
|
+
hasContentLength = true;
|
|
20734
|
+
break;
|
|
20735
|
+
}
|
|
20736
|
+
}
|
|
20737
|
+
}
|
|
20738
|
+
if (!hasContentLength) {
|
|
20739
|
+
if (typeof body === "string") {
|
|
20740
|
+
header["Content-Length"] = Buffer.byteLength(body);
|
|
20741
|
+
} else if (body instanceof Uint8Array) {
|
|
20742
|
+
header["Content-Length"] = body.byteLength;
|
|
20743
|
+
} else if (body instanceof Blob) {
|
|
20744
|
+
header["Content-Length"] = body.size;
|
|
20745
|
+
}
|
|
20746
|
+
}
|
|
20747
|
+
outgoing.writeHead(status, header);
|
|
20748
|
+
if (typeof body === "string" || body instanceof Uint8Array) {
|
|
20749
|
+
outgoing.end(body);
|
|
20750
|
+
} else if (body instanceof Blob) {
|
|
20751
|
+
outgoing.end(new Uint8Array(await body.arrayBuffer()));
|
|
20752
|
+
} else {
|
|
20753
|
+
flushHeaders(outgoing);
|
|
20754
|
+
await writeFromReadableStream(body, outgoing)?.catch((e) => handleResponseError(e, outgoing));
|
|
20755
|
+
}
|
|
20756
|
+
outgoing[outgoingEnded]?.();
|
|
20757
|
+
};
|
|
20758
|
+
var isPromise = (res) => typeof res.then === "function";
|
|
20759
|
+
var responseViaResponseObject = async (res, outgoing, options = {}) => {
|
|
20760
|
+
if (isPromise(res)) {
|
|
20761
|
+
if (options.errorHandler) {
|
|
20762
|
+
try {
|
|
20763
|
+
res = await res;
|
|
20764
|
+
} catch (err) {
|
|
20765
|
+
const errRes = await options.errorHandler(err);
|
|
20766
|
+
if (!errRes) {
|
|
20767
|
+
return;
|
|
20768
|
+
}
|
|
20769
|
+
res = errRes;
|
|
20770
|
+
}
|
|
20771
|
+
} else {
|
|
20772
|
+
res = await res.catch(handleFetchError);
|
|
20773
|
+
}
|
|
20774
|
+
}
|
|
20775
|
+
if (cacheKey in res) {
|
|
20776
|
+
return responseViaCache(res, outgoing);
|
|
20777
|
+
}
|
|
20778
|
+
const resHeaderRecord = buildOutgoingHttpHeaders(res.headers);
|
|
20779
|
+
if (res.body) {
|
|
20780
|
+
const reader = res.body.getReader();
|
|
20781
|
+
const values = [];
|
|
20782
|
+
let done = false;
|
|
20783
|
+
let currentReadPromise = undefined;
|
|
20784
|
+
if (resHeaderRecord["transfer-encoding"] !== "chunked") {
|
|
20785
|
+
let maxReadCount = 2;
|
|
20786
|
+
for (let i = 0;i < maxReadCount; i++) {
|
|
20787
|
+
currentReadPromise ||= reader.read();
|
|
20788
|
+
const chunk = await readWithoutBlocking(currentReadPromise).catch((e) => {
|
|
20789
|
+
console.error(e);
|
|
20790
|
+
done = true;
|
|
20791
|
+
});
|
|
20792
|
+
if (!chunk) {
|
|
20793
|
+
if (i === 1) {
|
|
20794
|
+
await new Promise((resolve) => setTimeout(resolve));
|
|
20795
|
+
maxReadCount = 3;
|
|
20796
|
+
continue;
|
|
20797
|
+
}
|
|
20798
|
+
break;
|
|
20799
|
+
}
|
|
20800
|
+
currentReadPromise = undefined;
|
|
20801
|
+
if (chunk.value) {
|
|
20802
|
+
values.push(chunk.value);
|
|
20803
|
+
}
|
|
20804
|
+
if (chunk.done) {
|
|
20805
|
+
done = true;
|
|
20806
|
+
break;
|
|
20807
|
+
}
|
|
20808
|
+
}
|
|
20809
|
+
if (done && !("content-length" in resHeaderRecord)) {
|
|
20810
|
+
resHeaderRecord["content-length"] = values.reduce((acc, value) => acc + value.length, 0);
|
|
20811
|
+
}
|
|
20812
|
+
}
|
|
20813
|
+
outgoing.writeHead(res.status, resHeaderRecord);
|
|
20814
|
+
values.forEach((value) => {
|
|
20815
|
+
outgoing.write(value);
|
|
20816
|
+
});
|
|
20817
|
+
if (done) {
|
|
20818
|
+
outgoing.end();
|
|
20819
|
+
} else {
|
|
20820
|
+
if (values.length === 0) {
|
|
20821
|
+
flushHeaders(outgoing);
|
|
20822
|
+
}
|
|
20823
|
+
await writeFromReadableStreamDefaultReader(reader, outgoing, currentReadPromise);
|
|
20824
|
+
}
|
|
20825
|
+
} else if (resHeaderRecord[X_ALREADY_SENT]) {} else {
|
|
20826
|
+
outgoing.writeHead(res.status, resHeaderRecord);
|
|
20827
|
+
outgoing.end();
|
|
20828
|
+
}
|
|
20829
|
+
outgoing[outgoingEnded]?.();
|
|
20830
|
+
};
|
|
20831
|
+
var getRequestListener = (fetchCallback, options = {}) => {
|
|
20832
|
+
const autoCleanupIncoming = options.autoCleanupIncoming ?? true;
|
|
20833
|
+
if (options.overrideGlobalObjects !== false && global.Request !== Request2) {
|
|
20834
|
+
Object.defineProperty(global, "Request", {
|
|
20835
|
+
value: Request2
|
|
20836
|
+
});
|
|
20837
|
+
Object.defineProperty(global, "Response", {
|
|
20838
|
+
value: Response2
|
|
20839
|
+
});
|
|
20840
|
+
}
|
|
20841
|
+
return async (incoming, outgoing) => {
|
|
20842
|
+
let res, req;
|
|
20843
|
+
try {
|
|
20844
|
+
req = newRequest(incoming, options.hostname);
|
|
20845
|
+
let incomingEnded = !autoCleanupIncoming || incoming.method === "GET" || incoming.method === "HEAD";
|
|
20846
|
+
if (!incomingEnded) {
|
|
20847
|
+
incoming[wrapBodyStream] = true;
|
|
20848
|
+
incoming.on("end", () => {
|
|
20849
|
+
incomingEnded = true;
|
|
20850
|
+
});
|
|
20851
|
+
if (incoming instanceof Http2ServerRequest2) {
|
|
20852
|
+
outgoing[outgoingEnded] = () => {
|
|
20853
|
+
if (!incomingEnded) {
|
|
20854
|
+
setTimeout(() => {
|
|
20855
|
+
if (!incomingEnded) {
|
|
20856
|
+
setTimeout(() => {
|
|
20857
|
+
incoming.destroy();
|
|
20858
|
+
outgoing.destroy();
|
|
20859
|
+
});
|
|
20860
|
+
}
|
|
20861
|
+
});
|
|
20862
|
+
}
|
|
20863
|
+
};
|
|
20864
|
+
}
|
|
20865
|
+
}
|
|
20866
|
+
outgoing.on("close", () => {
|
|
20867
|
+
const abortController = req[abortControllerKey];
|
|
20868
|
+
if (abortController) {
|
|
20869
|
+
if (incoming.errored) {
|
|
20870
|
+
req[abortControllerKey].abort(incoming.errored.toString());
|
|
20871
|
+
} else if (!outgoing.writableFinished) {
|
|
20872
|
+
req[abortControllerKey].abort("Client connection prematurely closed.");
|
|
20873
|
+
}
|
|
20874
|
+
}
|
|
20875
|
+
if (!incomingEnded) {
|
|
20876
|
+
setTimeout(() => {
|
|
20877
|
+
if (!incomingEnded) {
|
|
20878
|
+
setTimeout(() => {
|
|
20879
|
+
incoming.destroy();
|
|
20880
|
+
});
|
|
20881
|
+
}
|
|
20882
|
+
});
|
|
20883
|
+
}
|
|
20884
|
+
});
|
|
20885
|
+
res = fetchCallback(req, { incoming, outgoing });
|
|
20886
|
+
if (cacheKey in res) {
|
|
20887
|
+
return responseViaCache(res, outgoing);
|
|
20888
|
+
}
|
|
20889
|
+
} catch (e) {
|
|
20890
|
+
if (!res) {
|
|
20891
|
+
if (options.errorHandler) {
|
|
20892
|
+
res = await options.errorHandler(req ? e : toRequestError(e));
|
|
20893
|
+
if (!res) {
|
|
20894
|
+
return;
|
|
20895
|
+
}
|
|
20896
|
+
} else if (!req) {
|
|
20897
|
+
res = handleRequestError();
|
|
20898
|
+
} else {
|
|
20899
|
+
res = handleFetchError(e);
|
|
20900
|
+
}
|
|
20901
|
+
} else {
|
|
20902
|
+
return handleResponseError(e, outgoing);
|
|
20903
|
+
}
|
|
20904
|
+
}
|
|
20905
|
+
try {
|
|
20906
|
+
return await responseViaResponseObject(res, outgoing, options);
|
|
20907
|
+
} catch (e) {
|
|
20908
|
+
return handleResponseError(e, outgoing);
|
|
20909
|
+
}
|
|
20910
|
+
};
|
|
20911
|
+
};
|
|
20912
|
+
var createAdaptorServer = (options) => {
|
|
20913
|
+
const fetchCallback = options.fetch;
|
|
20914
|
+
const requestListener = getRequestListener(fetchCallback, {
|
|
20915
|
+
hostname: options.hostname,
|
|
20916
|
+
overrideGlobalObjects: options.overrideGlobalObjects,
|
|
20917
|
+
autoCleanupIncoming: options.autoCleanupIncoming
|
|
20918
|
+
});
|
|
20919
|
+
const createServer = options.createServer || createServerHTTP;
|
|
20920
|
+
const server = createServer(options.serverOptions || {}, requestListener);
|
|
20921
|
+
return server;
|
|
20922
|
+
};
|
|
20923
|
+
var serve = (options, listeningListener) => {
|
|
20924
|
+
const server = createAdaptorServer(options);
|
|
20925
|
+
server.listen(options?.port ?? 3000, options.hostname, () => {
|
|
20926
|
+
const serverInfo = server.address();
|
|
20927
|
+
listeningListener && listeningListener(serverInfo);
|
|
20928
|
+
});
|
|
20929
|
+
return server;
|
|
20930
|
+
};
|
|
20931
|
+
|
|
20932
|
+
// node_modules/hono/dist/compose.js
|
|
20933
|
+
var compose = (middleware, onError, onNotFound) => {
|
|
20934
|
+
return (context, next) => {
|
|
20935
|
+
let index = -1;
|
|
20936
|
+
return dispatch(0);
|
|
20937
|
+
async function dispatch(i) {
|
|
20938
|
+
if (i <= index) {
|
|
20939
|
+
throw new Error("next() called multiple times");
|
|
20940
|
+
}
|
|
20941
|
+
index = i;
|
|
20942
|
+
let res;
|
|
20943
|
+
let isError = false;
|
|
20944
|
+
let handler;
|
|
20945
|
+
if (middleware[i]) {
|
|
20946
|
+
handler = middleware[i][0][0];
|
|
20947
|
+
context.req.routeIndex = i;
|
|
20948
|
+
} else {
|
|
20949
|
+
handler = i === middleware.length && next || undefined;
|
|
20950
|
+
}
|
|
20951
|
+
if (handler) {
|
|
20952
|
+
try {
|
|
20953
|
+
res = await handler(context, () => dispatch(i + 1));
|
|
20954
|
+
} catch (err) {
|
|
20955
|
+
if (err instanceof Error && onError) {
|
|
20956
|
+
context.error = err;
|
|
20957
|
+
res = await onError(err, context);
|
|
20958
|
+
isError = true;
|
|
20959
|
+
} else {
|
|
20960
|
+
throw err;
|
|
20961
|
+
}
|
|
20962
|
+
}
|
|
20963
|
+
} else {
|
|
20964
|
+
if (context.finalized === false && onNotFound) {
|
|
20965
|
+
res = await onNotFound(context);
|
|
20966
|
+
}
|
|
20967
|
+
}
|
|
20968
|
+
if (res && (context.finalized === false || isError)) {
|
|
20969
|
+
context.res = res;
|
|
20970
|
+
}
|
|
20971
|
+
return context;
|
|
20972
|
+
}
|
|
20973
|
+
};
|
|
20974
|
+
};
|
|
20975
|
+
|
|
20976
|
+
// node_modules/hono/dist/request/constants.js
|
|
20977
|
+
var GET_MATCH_RESULT = /* @__PURE__ */ Symbol();
|
|
20978
|
+
|
|
20979
|
+
// node_modules/hono/dist/utils/body.js
|
|
20980
|
+
var parseBody = async (request, options = /* @__PURE__ */ Object.create(null)) => {
|
|
20981
|
+
const { all = false, dot = false } = options;
|
|
20982
|
+
const headers = request instanceof HonoRequest ? request.raw.headers : request.headers;
|
|
20983
|
+
const contentType = headers.get("Content-Type");
|
|
20984
|
+
if (contentType?.startsWith("multipart/form-data") || contentType?.startsWith("application/x-www-form-urlencoded")) {
|
|
20985
|
+
return parseFormData(request, { all, dot });
|
|
20986
|
+
}
|
|
20987
|
+
return {};
|
|
20988
|
+
};
|
|
20989
|
+
async function parseFormData(request, options) {
|
|
20990
|
+
const formData = await request.formData();
|
|
20991
|
+
if (formData) {
|
|
20992
|
+
return convertFormDataToBodyData(formData, options);
|
|
20993
|
+
}
|
|
20994
|
+
return {};
|
|
20995
|
+
}
|
|
20996
|
+
function convertFormDataToBodyData(formData, options) {
|
|
20997
|
+
const form = /* @__PURE__ */ Object.create(null);
|
|
20998
|
+
formData.forEach((value, key) => {
|
|
20999
|
+
const shouldParseAllValues = options.all || key.endsWith("[]");
|
|
21000
|
+
if (!shouldParseAllValues) {
|
|
21001
|
+
form[key] = value;
|
|
21002
|
+
} else {
|
|
21003
|
+
handleParsingAllValues(form, key, value);
|
|
21004
|
+
}
|
|
21005
|
+
});
|
|
21006
|
+
if (options.dot) {
|
|
21007
|
+
Object.entries(form).forEach(([key, value]) => {
|
|
21008
|
+
const shouldParseDotValues = key.includes(".");
|
|
21009
|
+
if (shouldParseDotValues) {
|
|
21010
|
+
handleParsingNestedValues(form, key, value);
|
|
21011
|
+
delete form[key];
|
|
21012
|
+
}
|
|
21013
|
+
});
|
|
21014
|
+
}
|
|
21015
|
+
return form;
|
|
21016
|
+
}
|
|
21017
|
+
var handleParsingAllValues = (form, key, value) => {
|
|
21018
|
+
if (form[key] !== undefined) {
|
|
21019
|
+
if (Array.isArray(form[key])) {
|
|
21020
|
+
form[key].push(value);
|
|
21021
|
+
} else {
|
|
21022
|
+
form[key] = [form[key], value];
|
|
21023
|
+
}
|
|
21024
|
+
} else {
|
|
21025
|
+
if (!key.endsWith("[]")) {
|
|
21026
|
+
form[key] = value;
|
|
21027
|
+
} else {
|
|
21028
|
+
form[key] = [value];
|
|
21029
|
+
}
|
|
21030
|
+
}
|
|
21031
|
+
};
|
|
21032
|
+
var handleParsingNestedValues = (form, key, value) => {
|
|
21033
|
+
if (/(?:^|\.)__proto__\./.test(key)) {
|
|
21034
|
+
return;
|
|
21035
|
+
}
|
|
21036
|
+
let nestedForm = form;
|
|
21037
|
+
const keys = key.split(".");
|
|
21038
|
+
keys.forEach((key2, index) => {
|
|
21039
|
+
if (index === keys.length - 1) {
|
|
21040
|
+
nestedForm[key2] = value;
|
|
21041
|
+
} else {
|
|
21042
|
+
if (!nestedForm[key2] || typeof nestedForm[key2] !== "object" || Array.isArray(nestedForm[key2]) || nestedForm[key2] instanceof File) {
|
|
21043
|
+
nestedForm[key2] = /* @__PURE__ */ Object.create(null);
|
|
21044
|
+
}
|
|
21045
|
+
nestedForm = nestedForm[key2];
|
|
21046
|
+
}
|
|
21047
|
+
});
|
|
21048
|
+
};
|
|
21049
|
+
|
|
21050
|
+
// node_modules/hono/dist/utils/url.js
|
|
21051
|
+
var splitPath = (path) => {
|
|
21052
|
+
const paths = path.split("/");
|
|
21053
|
+
if (paths[0] === "") {
|
|
21054
|
+
paths.shift();
|
|
21055
|
+
}
|
|
21056
|
+
return paths;
|
|
21057
|
+
};
|
|
21058
|
+
var splitRoutingPath = (routePath) => {
|
|
21059
|
+
const { groups, path } = extractGroupsFromPath(routePath);
|
|
21060
|
+
const paths = splitPath(path);
|
|
21061
|
+
return replaceGroupMarks(paths, groups);
|
|
21062
|
+
};
|
|
21063
|
+
var extractGroupsFromPath = (path) => {
|
|
21064
|
+
const groups = [];
|
|
21065
|
+
path = path.replace(/\{[^}]+\}/g, (match, index) => {
|
|
21066
|
+
const mark = `@${index}`;
|
|
21067
|
+
groups.push([mark, match]);
|
|
21068
|
+
return mark;
|
|
21069
|
+
});
|
|
21070
|
+
return { groups, path };
|
|
21071
|
+
};
|
|
21072
|
+
var replaceGroupMarks = (paths, groups) => {
|
|
21073
|
+
for (let i = groups.length - 1;i >= 0; i--) {
|
|
21074
|
+
const [mark] = groups[i];
|
|
21075
|
+
for (let j = paths.length - 1;j >= 0; j--) {
|
|
21076
|
+
if (paths[j].includes(mark)) {
|
|
21077
|
+
paths[j] = paths[j].replace(mark, groups[i][1]);
|
|
21078
|
+
break;
|
|
21079
|
+
}
|
|
21080
|
+
}
|
|
21081
|
+
}
|
|
21082
|
+
return paths;
|
|
21083
|
+
};
|
|
21084
|
+
var patternCache = {};
|
|
21085
|
+
var getPattern = (label, next) => {
|
|
21086
|
+
if (label === "*") {
|
|
21087
|
+
return "*";
|
|
21088
|
+
}
|
|
21089
|
+
const match = label.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
|
|
21090
|
+
if (match) {
|
|
21091
|
+
const cacheKey2 = `${label}#${next}`;
|
|
21092
|
+
if (!patternCache[cacheKey2]) {
|
|
21093
|
+
if (match[2]) {
|
|
21094
|
+
patternCache[cacheKey2] = next && next[0] !== ":" && next[0] !== "*" ? [cacheKey2, match[1], new RegExp(`^${match[2]}(?=/${next})`)] : [label, match[1], new RegExp(`^${match[2]}$`)];
|
|
21095
|
+
} else {
|
|
21096
|
+
patternCache[cacheKey2] = [label, match[1], true];
|
|
21097
|
+
}
|
|
21098
|
+
}
|
|
21099
|
+
return patternCache[cacheKey2];
|
|
21100
|
+
}
|
|
21101
|
+
return null;
|
|
21102
|
+
};
|
|
21103
|
+
var tryDecode = (str, decoder) => {
|
|
21104
|
+
try {
|
|
21105
|
+
return decoder(str);
|
|
21106
|
+
} catch {
|
|
21107
|
+
return str.replace(/(?:%[0-9A-Fa-f]{2})+/g, (match) => {
|
|
21108
|
+
try {
|
|
21109
|
+
return decoder(match);
|
|
21110
|
+
} catch {
|
|
21111
|
+
return match;
|
|
21112
|
+
}
|
|
21113
|
+
});
|
|
21114
|
+
}
|
|
21115
|
+
};
|
|
21116
|
+
var tryDecodeURI = (str) => tryDecode(str, decodeURI);
|
|
21117
|
+
var getPath = (request) => {
|
|
21118
|
+
const url = request.url;
|
|
21119
|
+
const start = url.indexOf("/", url.indexOf(":") + 4);
|
|
21120
|
+
let i = start;
|
|
21121
|
+
for (;i < url.length; i++) {
|
|
21122
|
+
const charCode = url.charCodeAt(i);
|
|
21123
|
+
if (charCode === 37) {
|
|
21124
|
+
const queryIndex = url.indexOf("?", i);
|
|
21125
|
+
const hashIndex = url.indexOf("#", i);
|
|
21126
|
+
const end = queryIndex === -1 ? hashIndex === -1 ? undefined : hashIndex : hashIndex === -1 ? queryIndex : Math.min(queryIndex, hashIndex);
|
|
21127
|
+
const path = url.slice(start, end);
|
|
21128
|
+
return tryDecodeURI(path.includes("%25") ? path.replace(/%25/g, "%2525") : path);
|
|
21129
|
+
} else if (charCode === 63 || charCode === 35) {
|
|
21130
|
+
break;
|
|
21131
|
+
}
|
|
21132
|
+
}
|
|
21133
|
+
return url.slice(start, i);
|
|
21134
|
+
};
|
|
21135
|
+
var getPathNoStrict = (request) => {
|
|
21136
|
+
const result = getPath(request);
|
|
21137
|
+
return result.length > 1 && result.at(-1) === "/" ? result.slice(0, -1) : result;
|
|
21138
|
+
};
|
|
21139
|
+
var mergePath = (base, sub, ...rest) => {
|
|
21140
|
+
if (rest.length) {
|
|
21141
|
+
sub = mergePath(sub, ...rest);
|
|
21142
|
+
}
|
|
21143
|
+
return `${base?.[0] === "/" ? "" : "/"}${base}${sub === "/" ? "" : `${base?.at(-1) === "/" ? "" : "/"}${sub?.[0] === "/" ? sub.slice(1) : sub}`}`;
|
|
21144
|
+
};
|
|
21145
|
+
var checkOptionalParameter = (path) => {
|
|
21146
|
+
if (path.charCodeAt(path.length - 1) !== 63 || !path.includes(":")) {
|
|
21147
|
+
return null;
|
|
21148
|
+
}
|
|
21149
|
+
const segments = path.split("/");
|
|
21150
|
+
const results = [];
|
|
21151
|
+
let basePath = "";
|
|
21152
|
+
segments.forEach((segment) => {
|
|
21153
|
+
if (segment !== "" && !/\:/.test(segment)) {
|
|
21154
|
+
basePath += "/" + segment;
|
|
21155
|
+
} else if (/\:/.test(segment)) {
|
|
21156
|
+
if (/\?/.test(segment)) {
|
|
21157
|
+
if (results.length === 0 && basePath === "") {
|
|
21158
|
+
results.push("/");
|
|
21159
|
+
} else {
|
|
21160
|
+
results.push(basePath);
|
|
21161
|
+
}
|
|
21162
|
+
const optionalSegment = segment.replace("?", "");
|
|
21163
|
+
basePath += "/" + optionalSegment;
|
|
21164
|
+
results.push(basePath);
|
|
21165
|
+
} else {
|
|
21166
|
+
basePath += "/" + segment;
|
|
21167
|
+
}
|
|
21168
|
+
}
|
|
21169
|
+
});
|
|
21170
|
+
return results.filter((v, i, a) => a.indexOf(v) === i);
|
|
21171
|
+
};
|
|
21172
|
+
var _decodeURI = (value) => {
|
|
21173
|
+
if (!/[%+]/.test(value)) {
|
|
21174
|
+
return value;
|
|
21175
|
+
}
|
|
21176
|
+
if (value.indexOf("+") !== -1) {
|
|
21177
|
+
value = value.replace(/\+/g, " ");
|
|
21178
|
+
}
|
|
21179
|
+
return value.indexOf("%") !== -1 ? tryDecode(value, decodeURIComponent_) : value;
|
|
21180
|
+
};
|
|
21181
|
+
var _getQueryParam = (url, key, multiple) => {
|
|
21182
|
+
let encoded;
|
|
21183
|
+
if (!multiple && key && !/[%+]/.test(key)) {
|
|
21184
|
+
let keyIndex2 = url.indexOf("?", 8);
|
|
21185
|
+
if (keyIndex2 === -1) {
|
|
21186
|
+
return;
|
|
21187
|
+
}
|
|
21188
|
+
if (!url.startsWith(key, keyIndex2 + 1)) {
|
|
21189
|
+
keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1);
|
|
21190
|
+
}
|
|
21191
|
+
while (keyIndex2 !== -1) {
|
|
21192
|
+
const trailingKeyCode = url.charCodeAt(keyIndex2 + key.length + 1);
|
|
21193
|
+
if (trailingKeyCode === 61) {
|
|
21194
|
+
const valueIndex = keyIndex2 + key.length + 2;
|
|
21195
|
+
const endIndex = url.indexOf("&", valueIndex);
|
|
21196
|
+
return _decodeURI(url.slice(valueIndex, endIndex === -1 ? undefined : endIndex));
|
|
21197
|
+
} else if (trailingKeyCode == 38 || isNaN(trailingKeyCode)) {
|
|
21198
|
+
return "";
|
|
21199
|
+
}
|
|
21200
|
+
keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1);
|
|
21201
|
+
}
|
|
21202
|
+
encoded = /[%+]/.test(url);
|
|
21203
|
+
if (!encoded) {
|
|
21204
|
+
return;
|
|
21205
|
+
}
|
|
21206
|
+
}
|
|
21207
|
+
const results = {};
|
|
21208
|
+
encoded ??= /[%+]/.test(url);
|
|
21209
|
+
let keyIndex = url.indexOf("?", 8);
|
|
21210
|
+
while (keyIndex !== -1) {
|
|
21211
|
+
const nextKeyIndex = url.indexOf("&", keyIndex + 1);
|
|
21212
|
+
let valueIndex = url.indexOf("=", keyIndex);
|
|
21213
|
+
if (valueIndex > nextKeyIndex && nextKeyIndex !== -1) {
|
|
21214
|
+
valueIndex = -1;
|
|
21215
|
+
}
|
|
21216
|
+
let name = url.slice(keyIndex + 1, valueIndex === -1 ? nextKeyIndex === -1 ? undefined : nextKeyIndex : valueIndex);
|
|
21217
|
+
if (encoded) {
|
|
21218
|
+
name = _decodeURI(name);
|
|
21219
|
+
}
|
|
21220
|
+
keyIndex = nextKeyIndex;
|
|
21221
|
+
if (name === "") {
|
|
21222
|
+
continue;
|
|
21223
|
+
}
|
|
21224
|
+
let value;
|
|
21225
|
+
if (valueIndex === -1) {
|
|
21226
|
+
value = "";
|
|
21227
|
+
} else {
|
|
21228
|
+
value = url.slice(valueIndex + 1, nextKeyIndex === -1 ? undefined : nextKeyIndex);
|
|
21229
|
+
if (encoded) {
|
|
21230
|
+
value = _decodeURI(value);
|
|
21231
|
+
}
|
|
21232
|
+
}
|
|
21233
|
+
if (multiple) {
|
|
21234
|
+
if (!(results[name] && Array.isArray(results[name]))) {
|
|
21235
|
+
results[name] = [];
|
|
21236
|
+
}
|
|
21237
|
+
results[name].push(value);
|
|
21238
|
+
} else {
|
|
21239
|
+
results[name] ??= value;
|
|
21240
|
+
}
|
|
21241
|
+
}
|
|
21242
|
+
return key ? results[key] : results;
|
|
21243
|
+
};
|
|
21244
|
+
var getQueryParam = _getQueryParam;
|
|
21245
|
+
var getQueryParams = (url, key) => {
|
|
21246
|
+
return _getQueryParam(url, key, true);
|
|
21247
|
+
};
|
|
21248
|
+
var decodeURIComponent_ = decodeURIComponent;
|
|
21249
|
+
|
|
21250
|
+
// node_modules/hono/dist/request.js
|
|
21251
|
+
var tryDecodeURIComponent = (str) => tryDecode(str, decodeURIComponent_);
|
|
21252
|
+
var HonoRequest = class {
|
|
21253
|
+
raw;
|
|
21254
|
+
#validatedData;
|
|
21255
|
+
#matchResult;
|
|
21256
|
+
routeIndex = 0;
|
|
21257
|
+
path;
|
|
21258
|
+
bodyCache = {};
|
|
21259
|
+
constructor(request, path = "/", matchResult = [[]]) {
|
|
21260
|
+
this.raw = request;
|
|
21261
|
+
this.path = path;
|
|
21262
|
+
this.#matchResult = matchResult;
|
|
21263
|
+
this.#validatedData = {};
|
|
21264
|
+
}
|
|
21265
|
+
param(key) {
|
|
21266
|
+
return key ? this.#getDecodedParam(key) : this.#getAllDecodedParams();
|
|
21267
|
+
}
|
|
21268
|
+
#getDecodedParam(key) {
|
|
21269
|
+
const paramKey = this.#matchResult[0][this.routeIndex][1][key];
|
|
21270
|
+
const param = this.#getParamValue(paramKey);
|
|
21271
|
+
return param && /\%/.test(param) ? tryDecodeURIComponent(param) : param;
|
|
21272
|
+
}
|
|
21273
|
+
#getAllDecodedParams() {
|
|
21274
|
+
const decoded = {};
|
|
21275
|
+
const keys = Object.keys(this.#matchResult[0][this.routeIndex][1]);
|
|
21276
|
+
for (const key of keys) {
|
|
21277
|
+
const value = this.#getParamValue(this.#matchResult[0][this.routeIndex][1][key]);
|
|
21278
|
+
if (value !== undefined) {
|
|
21279
|
+
decoded[key] = /\%/.test(value) ? tryDecodeURIComponent(value) : value;
|
|
21280
|
+
}
|
|
21281
|
+
}
|
|
21282
|
+
return decoded;
|
|
21283
|
+
}
|
|
21284
|
+
#getParamValue(paramKey) {
|
|
21285
|
+
return this.#matchResult[1] ? this.#matchResult[1][paramKey] : paramKey;
|
|
21286
|
+
}
|
|
21287
|
+
query(key) {
|
|
21288
|
+
return getQueryParam(this.url, key);
|
|
21289
|
+
}
|
|
21290
|
+
queries(key) {
|
|
21291
|
+
return getQueryParams(this.url, key);
|
|
21292
|
+
}
|
|
21293
|
+
header(name) {
|
|
21294
|
+
if (name) {
|
|
21295
|
+
return this.raw.headers.get(name) ?? undefined;
|
|
21296
|
+
}
|
|
21297
|
+
const headerData = {};
|
|
21298
|
+
this.raw.headers.forEach((value, key) => {
|
|
21299
|
+
headerData[key] = value;
|
|
21300
|
+
});
|
|
21301
|
+
return headerData;
|
|
21302
|
+
}
|
|
21303
|
+
async parseBody(options) {
|
|
21304
|
+
return this.bodyCache.parsedBody ??= await parseBody(this, options);
|
|
21305
|
+
}
|
|
21306
|
+
#cachedBody = (key) => {
|
|
21307
|
+
const { bodyCache, raw } = this;
|
|
21308
|
+
const cachedBody = bodyCache[key];
|
|
21309
|
+
if (cachedBody) {
|
|
21310
|
+
return cachedBody;
|
|
21311
|
+
}
|
|
21312
|
+
const anyCachedKey = Object.keys(bodyCache)[0];
|
|
21313
|
+
if (anyCachedKey) {
|
|
21314
|
+
return bodyCache[anyCachedKey].then((body) => {
|
|
21315
|
+
if (anyCachedKey === "json") {
|
|
21316
|
+
body = JSON.stringify(body);
|
|
21317
|
+
}
|
|
21318
|
+
return new Response(body)[key]();
|
|
21319
|
+
});
|
|
21320
|
+
}
|
|
21321
|
+
return bodyCache[key] = raw[key]();
|
|
21322
|
+
};
|
|
21323
|
+
json() {
|
|
21324
|
+
return this.#cachedBody("text").then((text) => JSON.parse(text));
|
|
21325
|
+
}
|
|
21326
|
+
text() {
|
|
21327
|
+
return this.#cachedBody("text");
|
|
21328
|
+
}
|
|
21329
|
+
arrayBuffer() {
|
|
21330
|
+
return this.#cachedBody("arrayBuffer");
|
|
21331
|
+
}
|
|
21332
|
+
blob() {
|
|
21333
|
+
return this.#cachedBody("blob");
|
|
21334
|
+
}
|
|
21335
|
+
formData() {
|
|
21336
|
+
return this.#cachedBody("formData");
|
|
21337
|
+
}
|
|
21338
|
+
addValidatedData(target, data) {
|
|
21339
|
+
this.#validatedData[target] = data;
|
|
21340
|
+
}
|
|
21341
|
+
valid(target) {
|
|
21342
|
+
return this.#validatedData[target];
|
|
21343
|
+
}
|
|
21344
|
+
get url() {
|
|
21345
|
+
return this.raw.url;
|
|
21346
|
+
}
|
|
21347
|
+
get method() {
|
|
21348
|
+
return this.raw.method;
|
|
21349
|
+
}
|
|
21350
|
+
get [GET_MATCH_RESULT]() {
|
|
21351
|
+
return this.#matchResult;
|
|
21352
|
+
}
|
|
21353
|
+
get matchedRoutes() {
|
|
21354
|
+
return this.#matchResult[0].map(([[, route]]) => route);
|
|
21355
|
+
}
|
|
21356
|
+
get routePath() {
|
|
21357
|
+
return this.#matchResult[0].map(([[, route]]) => route)[this.routeIndex].path;
|
|
21358
|
+
}
|
|
21359
|
+
};
|
|
21360
|
+
|
|
21361
|
+
// node_modules/hono/dist/utils/html.js
|
|
21362
|
+
var HtmlEscapedCallbackPhase = {
|
|
21363
|
+
Stringify: 1,
|
|
21364
|
+
BeforeStream: 2,
|
|
21365
|
+
Stream: 3
|
|
21366
|
+
};
|
|
21367
|
+
var raw = (value, callbacks) => {
|
|
21368
|
+
const escapedString = new String(value);
|
|
21369
|
+
escapedString.isEscaped = true;
|
|
21370
|
+
escapedString.callbacks = callbacks;
|
|
21371
|
+
return escapedString;
|
|
21372
|
+
};
|
|
21373
|
+
var escapeRe = /[&<>'"]/;
|
|
21374
|
+
var stringBufferToString = async (buffer, callbacks) => {
|
|
21375
|
+
let str = "";
|
|
21376
|
+
callbacks ||= [];
|
|
21377
|
+
const resolvedBuffer = await Promise.all(buffer);
|
|
21378
|
+
for (let i = resolvedBuffer.length - 1;; i--) {
|
|
21379
|
+
str += resolvedBuffer[i];
|
|
21380
|
+
i--;
|
|
21381
|
+
if (i < 0) {
|
|
21382
|
+
break;
|
|
21383
|
+
}
|
|
21384
|
+
let r = resolvedBuffer[i];
|
|
21385
|
+
if (typeof r === "object") {
|
|
21386
|
+
callbacks.push(...r.callbacks || []);
|
|
21387
|
+
}
|
|
21388
|
+
const isEscaped = r.isEscaped;
|
|
21389
|
+
r = await (typeof r === "object" ? r.toString() : r);
|
|
21390
|
+
if (typeof r === "object") {
|
|
21391
|
+
callbacks.push(...r.callbacks || []);
|
|
21392
|
+
}
|
|
21393
|
+
if (r.isEscaped ?? isEscaped) {
|
|
21394
|
+
str += r;
|
|
21395
|
+
} else {
|
|
21396
|
+
const buf = [str];
|
|
21397
|
+
escapeToBuffer(r, buf);
|
|
21398
|
+
str = buf[0];
|
|
21399
|
+
}
|
|
21400
|
+
}
|
|
21401
|
+
return raw(str, callbacks);
|
|
21402
|
+
};
|
|
21403
|
+
var escapeToBuffer = (str, buffer) => {
|
|
21404
|
+
const match = str.search(escapeRe);
|
|
21405
|
+
if (match === -1) {
|
|
21406
|
+
buffer[0] += str;
|
|
21407
|
+
return;
|
|
21408
|
+
}
|
|
21409
|
+
let escape2;
|
|
21410
|
+
let index;
|
|
21411
|
+
let lastIndex = 0;
|
|
21412
|
+
for (index = match;index < str.length; index++) {
|
|
21413
|
+
switch (str.charCodeAt(index)) {
|
|
21414
|
+
case 34:
|
|
21415
|
+
escape2 = """;
|
|
21416
|
+
break;
|
|
21417
|
+
case 39:
|
|
21418
|
+
escape2 = "'";
|
|
21419
|
+
break;
|
|
21420
|
+
case 38:
|
|
21421
|
+
escape2 = "&";
|
|
21422
|
+
break;
|
|
21423
|
+
case 60:
|
|
21424
|
+
escape2 = "<";
|
|
21425
|
+
break;
|
|
21426
|
+
case 62:
|
|
21427
|
+
escape2 = ">";
|
|
21428
|
+
break;
|
|
21429
|
+
default:
|
|
21430
|
+
continue;
|
|
21431
|
+
}
|
|
21432
|
+
buffer[0] += str.substring(lastIndex, index) + escape2;
|
|
21433
|
+
lastIndex = index + 1;
|
|
21434
|
+
}
|
|
21435
|
+
buffer[0] += str.substring(lastIndex, index);
|
|
21436
|
+
};
|
|
21437
|
+
var resolveCallbackSync = (str) => {
|
|
21438
|
+
const callbacks = str.callbacks;
|
|
21439
|
+
if (!callbacks?.length) {
|
|
21440
|
+
return str;
|
|
21441
|
+
}
|
|
21442
|
+
const buffer = [str];
|
|
21443
|
+
const context = {};
|
|
21444
|
+
callbacks.forEach((c) => c({ phase: HtmlEscapedCallbackPhase.Stringify, buffer, context }));
|
|
21445
|
+
return buffer[0];
|
|
21446
|
+
};
|
|
21447
|
+
var resolveCallback = async (str, phase, preserveCallbacks, context, buffer) => {
|
|
21448
|
+
if (typeof str === "object" && !(str instanceof String)) {
|
|
21449
|
+
if (!(str instanceof Promise)) {
|
|
21450
|
+
str = str.toString();
|
|
21451
|
+
}
|
|
21452
|
+
if (str instanceof Promise) {
|
|
21453
|
+
str = await str;
|
|
21454
|
+
}
|
|
21455
|
+
}
|
|
21456
|
+
const callbacks = str.callbacks;
|
|
21457
|
+
if (!callbacks?.length) {
|
|
21458
|
+
return Promise.resolve(str);
|
|
21459
|
+
}
|
|
21460
|
+
if (buffer) {
|
|
21461
|
+
buffer[0] += str;
|
|
21462
|
+
} else {
|
|
21463
|
+
buffer = [str];
|
|
21464
|
+
}
|
|
21465
|
+
const resStr = Promise.all(callbacks.map((c) => c({ phase, buffer, context }))).then((res) => Promise.all(res.filter(Boolean).map((str2) => resolveCallback(str2, phase, false, context, buffer))).then(() => buffer[0]));
|
|
21466
|
+
if (preserveCallbacks) {
|
|
21467
|
+
return raw(await resStr, callbacks);
|
|
21468
|
+
} else {
|
|
21469
|
+
return resStr;
|
|
21470
|
+
}
|
|
21471
|
+
};
|
|
21472
|
+
|
|
21473
|
+
// node_modules/hono/dist/context.js
|
|
21474
|
+
var TEXT_PLAIN = "text/plain; charset=UTF-8";
|
|
21475
|
+
var setDefaultContentType = (contentType, headers) => {
|
|
21476
|
+
return {
|
|
21477
|
+
"Content-Type": contentType,
|
|
21478
|
+
...headers
|
|
21479
|
+
};
|
|
21480
|
+
};
|
|
21481
|
+
var createResponseInstance = (body, init) => new Response(body, init);
|
|
21482
|
+
var Context = class {
|
|
21483
|
+
#rawRequest;
|
|
21484
|
+
#req;
|
|
21485
|
+
env = {};
|
|
21486
|
+
#var;
|
|
21487
|
+
finalized = false;
|
|
21488
|
+
error;
|
|
21489
|
+
#status;
|
|
21490
|
+
#executionCtx;
|
|
21491
|
+
#res;
|
|
21492
|
+
#layout;
|
|
21493
|
+
#renderer;
|
|
21494
|
+
#notFoundHandler;
|
|
21495
|
+
#preparedHeaders;
|
|
21496
|
+
#matchResult;
|
|
21497
|
+
#path;
|
|
21498
|
+
constructor(req, options) {
|
|
21499
|
+
this.#rawRequest = req;
|
|
21500
|
+
if (options) {
|
|
21501
|
+
this.#executionCtx = options.executionCtx;
|
|
21502
|
+
this.env = options.env;
|
|
21503
|
+
this.#notFoundHandler = options.notFoundHandler;
|
|
21504
|
+
this.#path = options.path;
|
|
21505
|
+
this.#matchResult = options.matchResult;
|
|
21506
|
+
}
|
|
21507
|
+
}
|
|
21508
|
+
get req() {
|
|
21509
|
+
this.#req ??= new HonoRequest(this.#rawRequest, this.#path, this.#matchResult);
|
|
21510
|
+
return this.#req;
|
|
21511
|
+
}
|
|
21512
|
+
get event() {
|
|
21513
|
+
if (this.#executionCtx && "respondWith" in this.#executionCtx) {
|
|
21514
|
+
return this.#executionCtx;
|
|
21515
|
+
} else {
|
|
21516
|
+
throw Error("This context has no FetchEvent");
|
|
21517
|
+
}
|
|
21518
|
+
}
|
|
21519
|
+
get executionCtx() {
|
|
21520
|
+
if (this.#executionCtx) {
|
|
21521
|
+
return this.#executionCtx;
|
|
21522
|
+
} else {
|
|
21523
|
+
throw Error("This context has no ExecutionContext");
|
|
21524
|
+
}
|
|
21525
|
+
}
|
|
21526
|
+
get res() {
|
|
21527
|
+
return this.#res ||= createResponseInstance(null, {
|
|
21528
|
+
headers: this.#preparedHeaders ??= new Headers
|
|
21529
|
+
});
|
|
21530
|
+
}
|
|
21531
|
+
set res(_res) {
|
|
21532
|
+
if (this.#res && _res) {
|
|
21533
|
+
_res = createResponseInstance(_res.body, _res);
|
|
21534
|
+
for (const [k, v] of this.#res.headers.entries()) {
|
|
21535
|
+
if (k === "content-type") {
|
|
21536
|
+
continue;
|
|
21537
|
+
}
|
|
21538
|
+
if (k === "set-cookie") {
|
|
21539
|
+
const cookies = this.#res.headers.getSetCookie();
|
|
21540
|
+
_res.headers.delete("set-cookie");
|
|
21541
|
+
for (const cookie of cookies) {
|
|
21542
|
+
_res.headers.append("set-cookie", cookie);
|
|
21543
|
+
}
|
|
21544
|
+
} else {
|
|
21545
|
+
_res.headers.set(k, v);
|
|
21546
|
+
}
|
|
21547
|
+
}
|
|
21548
|
+
}
|
|
21549
|
+
this.#res = _res;
|
|
21550
|
+
this.finalized = true;
|
|
21551
|
+
}
|
|
21552
|
+
render = (...args) => {
|
|
21553
|
+
this.#renderer ??= (content) => this.html(content);
|
|
21554
|
+
return this.#renderer(...args);
|
|
21555
|
+
};
|
|
21556
|
+
setLayout = (layout) => this.#layout = layout;
|
|
21557
|
+
getLayout = () => this.#layout;
|
|
21558
|
+
setRenderer = (renderer) => {
|
|
21559
|
+
this.#renderer = renderer;
|
|
21560
|
+
};
|
|
21561
|
+
header = (name, value, options) => {
|
|
21562
|
+
if (this.finalized) {
|
|
21563
|
+
this.#res = createResponseInstance(this.#res.body, this.#res);
|
|
21564
|
+
}
|
|
21565
|
+
const headers = this.#res ? this.#res.headers : this.#preparedHeaders ??= new Headers;
|
|
21566
|
+
if (value === undefined) {
|
|
21567
|
+
headers.delete(name);
|
|
21568
|
+
} else if (options?.append) {
|
|
21569
|
+
headers.append(name, value);
|
|
21570
|
+
} else {
|
|
21571
|
+
headers.set(name, value);
|
|
21572
|
+
}
|
|
21573
|
+
};
|
|
21574
|
+
status = (status) => {
|
|
21575
|
+
this.#status = status;
|
|
21576
|
+
};
|
|
21577
|
+
set = (key, value) => {
|
|
21578
|
+
this.#var ??= /* @__PURE__ */ new Map;
|
|
21579
|
+
this.#var.set(key, value);
|
|
21580
|
+
};
|
|
21581
|
+
get = (key) => {
|
|
21582
|
+
return this.#var ? this.#var.get(key) : undefined;
|
|
21583
|
+
};
|
|
21584
|
+
get var() {
|
|
21585
|
+
if (!this.#var) {
|
|
21586
|
+
return {};
|
|
21587
|
+
}
|
|
21588
|
+
return Object.fromEntries(this.#var);
|
|
21589
|
+
}
|
|
21590
|
+
#newResponse(data, arg, headers) {
|
|
21591
|
+
const responseHeaders = this.#res ? new Headers(this.#res.headers) : this.#preparedHeaders ?? new Headers;
|
|
21592
|
+
if (typeof arg === "object" && "headers" in arg) {
|
|
21593
|
+
const argHeaders = arg.headers instanceof Headers ? arg.headers : new Headers(arg.headers);
|
|
21594
|
+
for (const [key, value] of argHeaders) {
|
|
21595
|
+
if (key.toLowerCase() === "set-cookie") {
|
|
21596
|
+
responseHeaders.append(key, value);
|
|
21597
|
+
} else {
|
|
21598
|
+
responseHeaders.set(key, value);
|
|
21599
|
+
}
|
|
21600
|
+
}
|
|
21601
|
+
}
|
|
21602
|
+
if (headers) {
|
|
21603
|
+
for (const [k, v] of Object.entries(headers)) {
|
|
21604
|
+
if (typeof v === "string") {
|
|
21605
|
+
responseHeaders.set(k, v);
|
|
21606
|
+
} else {
|
|
21607
|
+
responseHeaders.delete(k);
|
|
21608
|
+
for (const v2 of v) {
|
|
21609
|
+
responseHeaders.append(k, v2);
|
|
21610
|
+
}
|
|
21611
|
+
}
|
|
21612
|
+
}
|
|
21613
|
+
}
|
|
21614
|
+
const status = typeof arg === "number" ? arg : arg?.status ?? this.#status;
|
|
21615
|
+
return createResponseInstance(data, { status, headers: responseHeaders });
|
|
21616
|
+
}
|
|
21617
|
+
newResponse = (...args) => this.#newResponse(...args);
|
|
21618
|
+
body = (data, arg, headers) => this.#newResponse(data, arg, headers);
|
|
21619
|
+
text = (text, arg, headers) => {
|
|
21620
|
+
return !this.#preparedHeaders && !this.#status && !arg && !headers && !this.finalized ? new Response(text) : this.#newResponse(text, arg, setDefaultContentType(TEXT_PLAIN, headers));
|
|
21621
|
+
};
|
|
21622
|
+
json = (object4, arg, headers) => {
|
|
21623
|
+
return this.#newResponse(JSON.stringify(object4), arg, setDefaultContentType("application/json", headers));
|
|
21624
|
+
};
|
|
21625
|
+
html = (html, arg, headers) => {
|
|
21626
|
+
const res = (html2) => this.#newResponse(html2, arg, setDefaultContentType("text/html; charset=UTF-8", headers));
|
|
21627
|
+
return typeof html === "object" ? resolveCallback(html, HtmlEscapedCallbackPhase.Stringify, false, {}).then(res) : res(html);
|
|
21628
|
+
};
|
|
21629
|
+
redirect = (location, status) => {
|
|
21630
|
+
const locationString = String(location);
|
|
21631
|
+
this.header("Location", !/[^\x00-\xFF]/.test(locationString) ? locationString : encodeURI(locationString));
|
|
21632
|
+
return this.newResponse(null, status ?? 302);
|
|
21633
|
+
};
|
|
21634
|
+
notFound = () => {
|
|
21635
|
+
this.#notFoundHandler ??= () => createResponseInstance();
|
|
21636
|
+
return this.#notFoundHandler(this);
|
|
21637
|
+
};
|
|
21638
|
+
};
|
|
21639
|
+
|
|
21640
|
+
// node_modules/hono/dist/router.js
|
|
21641
|
+
var METHOD_NAME_ALL = "ALL";
|
|
21642
|
+
var METHOD_NAME_ALL_LOWERCASE = "all";
|
|
21643
|
+
var METHODS = ["get", "post", "put", "delete", "options", "patch"];
|
|
21644
|
+
var MESSAGE_MATCHER_IS_ALREADY_BUILT = "Can not add a route since the matcher is already built.";
|
|
21645
|
+
var UnsupportedPathError = class extends Error {
|
|
21646
|
+
};
|
|
21647
|
+
|
|
21648
|
+
// node_modules/hono/dist/utils/constants.js
|
|
21649
|
+
var COMPOSED_HANDLER = "__COMPOSED_HANDLER";
|
|
21650
|
+
|
|
21651
|
+
// node_modules/hono/dist/hono-base.js
|
|
21652
|
+
var notFoundHandler = (c) => {
|
|
21653
|
+
return c.text("404 Not Found", 404);
|
|
21654
|
+
};
|
|
21655
|
+
var errorHandler = (err, c) => {
|
|
21656
|
+
if ("getResponse" in err) {
|
|
21657
|
+
const res = err.getResponse();
|
|
21658
|
+
return c.newResponse(res.body, res);
|
|
21659
|
+
}
|
|
21660
|
+
console.error(err);
|
|
21661
|
+
return c.text("Internal Server Error", 500);
|
|
21662
|
+
};
|
|
21663
|
+
var Hono = class _Hono {
|
|
21664
|
+
get;
|
|
21665
|
+
post;
|
|
21666
|
+
put;
|
|
21667
|
+
delete;
|
|
21668
|
+
options;
|
|
21669
|
+
patch;
|
|
21670
|
+
all;
|
|
21671
|
+
on;
|
|
21672
|
+
use;
|
|
21673
|
+
router;
|
|
21674
|
+
getPath;
|
|
21675
|
+
_basePath = "/";
|
|
21676
|
+
#path = "/";
|
|
21677
|
+
routes = [];
|
|
21678
|
+
constructor(options = {}) {
|
|
21679
|
+
const allMethods = [...METHODS, METHOD_NAME_ALL_LOWERCASE];
|
|
21680
|
+
allMethods.forEach((method) => {
|
|
21681
|
+
this[method] = (args1, ...args) => {
|
|
21682
|
+
if (typeof args1 === "string") {
|
|
21683
|
+
this.#path = args1;
|
|
21684
|
+
} else {
|
|
21685
|
+
this.#addRoute(method, this.#path, args1);
|
|
21686
|
+
}
|
|
21687
|
+
args.forEach((handler) => {
|
|
21688
|
+
this.#addRoute(method, this.#path, handler);
|
|
21689
|
+
});
|
|
21690
|
+
return this;
|
|
21691
|
+
};
|
|
21692
|
+
});
|
|
21693
|
+
this.on = (method, path, ...handlers) => {
|
|
21694
|
+
for (const p of [path].flat()) {
|
|
21695
|
+
this.#path = p;
|
|
21696
|
+
for (const m of [method].flat()) {
|
|
21697
|
+
handlers.map((handler) => {
|
|
21698
|
+
this.#addRoute(m.toUpperCase(), this.#path, handler);
|
|
21699
|
+
});
|
|
21700
|
+
}
|
|
21701
|
+
}
|
|
21702
|
+
return this;
|
|
21703
|
+
};
|
|
21704
|
+
this.use = (arg1, ...handlers) => {
|
|
21705
|
+
if (typeof arg1 === "string") {
|
|
21706
|
+
this.#path = arg1;
|
|
21707
|
+
} else {
|
|
21708
|
+
this.#path = "*";
|
|
21709
|
+
handlers.unshift(arg1);
|
|
21710
|
+
}
|
|
21711
|
+
handlers.forEach((handler) => {
|
|
21712
|
+
this.#addRoute(METHOD_NAME_ALL, this.#path, handler);
|
|
21713
|
+
});
|
|
21714
|
+
return this;
|
|
21715
|
+
};
|
|
21716
|
+
const { strict, ...optionsWithoutStrict } = options;
|
|
21717
|
+
Object.assign(this, optionsWithoutStrict);
|
|
21718
|
+
this.getPath = strict ?? true ? options.getPath ?? getPath : getPathNoStrict;
|
|
21719
|
+
}
|
|
21720
|
+
#clone() {
|
|
21721
|
+
const clone2 = new _Hono({
|
|
21722
|
+
router: this.router,
|
|
21723
|
+
getPath: this.getPath
|
|
21724
|
+
});
|
|
21725
|
+
clone2.errorHandler = this.errorHandler;
|
|
21726
|
+
clone2.#notFoundHandler = this.#notFoundHandler;
|
|
21727
|
+
clone2.routes = this.routes;
|
|
21728
|
+
return clone2;
|
|
21729
|
+
}
|
|
21730
|
+
#notFoundHandler = notFoundHandler;
|
|
21731
|
+
errorHandler = errorHandler;
|
|
21732
|
+
route(path, app) {
|
|
21733
|
+
const subApp = this.basePath(path);
|
|
21734
|
+
app.routes.map((r) => {
|
|
21735
|
+
let handler;
|
|
21736
|
+
if (app.errorHandler === errorHandler) {
|
|
21737
|
+
handler = r.handler;
|
|
21738
|
+
} else {
|
|
21739
|
+
handler = async (c, next) => (await compose([], app.errorHandler)(c, () => r.handler(c, next))).res;
|
|
21740
|
+
handler[COMPOSED_HANDLER] = r.handler;
|
|
21741
|
+
}
|
|
21742
|
+
subApp.#addRoute(r.method, r.path, handler);
|
|
21743
|
+
});
|
|
21744
|
+
return this;
|
|
21745
|
+
}
|
|
21746
|
+
basePath(path) {
|
|
21747
|
+
const subApp = this.#clone();
|
|
21748
|
+
subApp._basePath = mergePath(this._basePath, path);
|
|
21749
|
+
return subApp;
|
|
21750
|
+
}
|
|
21751
|
+
onError = (handler) => {
|
|
21752
|
+
this.errorHandler = handler;
|
|
21753
|
+
return this;
|
|
21754
|
+
};
|
|
21755
|
+
notFound = (handler) => {
|
|
21756
|
+
this.#notFoundHandler = handler;
|
|
21757
|
+
return this;
|
|
21758
|
+
};
|
|
21759
|
+
mount(path, applicationHandler, options) {
|
|
21760
|
+
let replaceRequest;
|
|
21761
|
+
let optionHandler;
|
|
21762
|
+
if (options) {
|
|
21763
|
+
if (typeof options === "function") {
|
|
21764
|
+
optionHandler = options;
|
|
21765
|
+
} else {
|
|
21766
|
+
optionHandler = options.optionHandler;
|
|
21767
|
+
if (options.replaceRequest === false) {
|
|
21768
|
+
replaceRequest = (request) => request;
|
|
21769
|
+
} else {
|
|
21770
|
+
replaceRequest = options.replaceRequest;
|
|
21771
|
+
}
|
|
21772
|
+
}
|
|
21773
|
+
}
|
|
21774
|
+
const getOptions = optionHandler ? (c) => {
|
|
21775
|
+
const options2 = optionHandler(c);
|
|
21776
|
+
return Array.isArray(options2) ? options2 : [options2];
|
|
21777
|
+
} : (c) => {
|
|
21778
|
+
let executionContext = undefined;
|
|
21779
|
+
try {
|
|
21780
|
+
executionContext = c.executionCtx;
|
|
21781
|
+
} catch {}
|
|
21782
|
+
return [c.env, executionContext];
|
|
21783
|
+
};
|
|
21784
|
+
replaceRequest ||= (() => {
|
|
21785
|
+
const mergedPath = mergePath(this._basePath, path);
|
|
21786
|
+
const pathPrefixLength = mergedPath === "/" ? 0 : mergedPath.length;
|
|
21787
|
+
return (request) => {
|
|
21788
|
+
const url = new URL(request.url);
|
|
21789
|
+
url.pathname = url.pathname.slice(pathPrefixLength) || "/";
|
|
21790
|
+
return new Request(url, request);
|
|
21791
|
+
};
|
|
21792
|
+
})();
|
|
21793
|
+
const handler = async (c, next) => {
|
|
21794
|
+
const res = await applicationHandler(replaceRequest(c.req.raw), ...getOptions(c));
|
|
21795
|
+
if (res) {
|
|
21796
|
+
return res;
|
|
21797
|
+
}
|
|
21798
|
+
await next();
|
|
21799
|
+
};
|
|
21800
|
+
this.#addRoute(METHOD_NAME_ALL, mergePath(path, "*"), handler);
|
|
21801
|
+
return this;
|
|
21802
|
+
}
|
|
21803
|
+
#addRoute(method, path, handler) {
|
|
21804
|
+
method = method.toUpperCase();
|
|
21805
|
+
path = mergePath(this._basePath, path);
|
|
21806
|
+
const r = { basePath: this._basePath, path, method, handler };
|
|
21807
|
+
this.router.add(method, path, [handler, r]);
|
|
21808
|
+
this.routes.push(r);
|
|
21809
|
+
}
|
|
21810
|
+
#handleError(err, c) {
|
|
21811
|
+
if (err instanceof Error) {
|
|
21812
|
+
return this.errorHandler(err, c);
|
|
21813
|
+
}
|
|
21814
|
+
throw err;
|
|
21815
|
+
}
|
|
21816
|
+
#dispatch(request, executionCtx, env, method) {
|
|
21817
|
+
if (method === "HEAD") {
|
|
21818
|
+
return (async () => new Response(null, await this.#dispatch(request, executionCtx, env, "GET")))();
|
|
21819
|
+
}
|
|
21820
|
+
const path = this.getPath(request, { env });
|
|
21821
|
+
const matchResult = this.router.match(method, path);
|
|
21822
|
+
const c = new Context(request, {
|
|
21823
|
+
path,
|
|
21824
|
+
matchResult,
|
|
21825
|
+
env,
|
|
21826
|
+
executionCtx,
|
|
21827
|
+
notFoundHandler: this.#notFoundHandler
|
|
21828
|
+
});
|
|
21829
|
+
if (matchResult[0].length === 1) {
|
|
21830
|
+
let res;
|
|
21831
|
+
try {
|
|
21832
|
+
res = matchResult[0][0][0][0](c, async () => {
|
|
21833
|
+
c.res = await this.#notFoundHandler(c);
|
|
21834
|
+
});
|
|
21835
|
+
} catch (err) {
|
|
21836
|
+
return this.#handleError(err, c);
|
|
21837
|
+
}
|
|
21838
|
+
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);
|
|
21839
|
+
}
|
|
21840
|
+
const composed = compose(matchResult[0], this.errorHandler, this.#notFoundHandler);
|
|
21841
|
+
return (async () => {
|
|
21842
|
+
try {
|
|
21843
|
+
const context = await composed(c);
|
|
21844
|
+
if (!context.finalized) {
|
|
21845
|
+
throw new Error("Context is not finalized. Did you forget to return a Response object or `await next()`?");
|
|
21846
|
+
}
|
|
21847
|
+
return context.res;
|
|
21848
|
+
} catch (err) {
|
|
21849
|
+
return this.#handleError(err, c);
|
|
21850
|
+
}
|
|
21851
|
+
})();
|
|
21852
|
+
}
|
|
21853
|
+
fetch = (request, ...rest) => {
|
|
21854
|
+
return this.#dispatch(request, rest[1], rest[0], request.method);
|
|
21855
|
+
};
|
|
21856
|
+
request = (input, requestInit, Env, executionCtx) => {
|
|
21857
|
+
if (input instanceof Request) {
|
|
21858
|
+
return this.fetch(requestInit ? new Request(input, requestInit) : input, Env, executionCtx);
|
|
21859
|
+
}
|
|
21860
|
+
input = input.toString();
|
|
21861
|
+
return this.fetch(new Request(/^https?:\/\//.test(input) ? input : `http://localhost${mergePath("/", input)}`, requestInit), Env, executionCtx);
|
|
21862
|
+
};
|
|
21863
|
+
fire = () => {
|
|
21864
|
+
addEventListener("fetch", (event) => {
|
|
21865
|
+
event.respondWith(this.#dispatch(event.request, event, undefined, event.request.method));
|
|
21866
|
+
});
|
|
21867
|
+
};
|
|
21868
|
+
};
|
|
21869
|
+
|
|
21870
|
+
// node_modules/hono/dist/router/reg-exp-router/matcher.js
|
|
21871
|
+
var emptyParam = [];
|
|
21872
|
+
function match(method, path) {
|
|
21873
|
+
const matchers = this.buildAllMatchers();
|
|
21874
|
+
const match2 = (method2, path2) => {
|
|
21875
|
+
const matcher = matchers[method2] || matchers[METHOD_NAME_ALL];
|
|
21876
|
+
const staticMatch = matcher[2][path2];
|
|
21877
|
+
if (staticMatch) {
|
|
21878
|
+
return staticMatch;
|
|
21879
|
+
}
|
|
21880
|
+
const match3 = path2.match(matcher[0]);
|
|
21881
|
+
if (!match3) {
|
|
21882
|
+
return [[], emptyParam];
|
|
21883
|
+
}
|
|
21884
|
+
const index = match3.indexOf("", 1);
|
|
21885
|
+
return [matcher[1][index], match3];
|
|
21886
|
+
};
|
|
21887
|
+
this.match = match2;
|
|
21888
|
+
return match2(method, path);
|
|
21889
|
+
}
|
|
21890
|
+
|
|
21891
|
+
// node_modules/hono/dist/router/reg-exp-router/node.js
|
|
21892
|
+
var LABEL_REG_EXP_STR = "[^/]+";
|
|
21893
|
+
var ONLY_WILDCARD_REG_EXP_STR = ".*";
|
|
21894
|
+
var TAIL_WILDCARD_REG_EXP_STR = "(?:|/.*)";
|
|
21895
|
+
var PATH_ERROR = /* @__PURE__ */ Symbol();
|
|
21896
|
+
var regExpMetaChars = new Set(".\\+*[^]$()");
|
|
21897
|
+
function compareKey(a, b) {
|
|
21898
|
+
if (a.length === 1) {
|
|
21899
|
+
return b.length === 1 ? a < b ? -1 : 1 : -1;
|
|
21900
|
+
}
|
|
21901
|
+
if (b.length === 1) {
|
|
21902
|
+
return 1;
|
|
21903
|
+
}
|
|
21904
|
+
if (a === ONLY_WILDCARD_REG_EXP_STR || a === TAIL_WILDCARD_REG_EXP_STR) {
|
|
21905
|
+
return 1;
|
|
21906
|
+
} else if (b === ONLY_WILDCARD_REG_EXP_STR || b === TAIL_WILDCARD_REG_EXP_STR) {
|
|
21907
|
+
return -1;
|
|
21908
|
+
}
|
|
21909
|
+
if (a === LABEL_REG_EXP_STR) {
|
|
21910
|
+
return 1;
|
|
21911
|
+
} else if (b === LABEL_REG_EXP_STR) {
|
|
21912
|
+
return -1;
|
|
21913
|
+
}
|
|
21914
|
+
return a.length === b.length ? a < b ? -1 : 1 : b.length - a.length;
|
|
21915
|
+
}
|
|
21916
|
+
var Node = class _Node {
|
|
21917
|
+
#index;
|
|
21918
|
+
#varIndex;
|
|
21919
|
+
#children = /* @__PURE__ */ Object.create(null);
|
|
21920
|
+
insert(tokens, index, paramMap, context, pathErrorCheckOnly) {
|
|
21921
|
+
if (tokens.length === 0) {
|
|
21922
|
+
if (this.#index !== undefined) {
|
|
21923
|
+
throw PATH_ERROR;
|
|
21924
|
+
}
|
|
21925
|
+
if (pathErrorCheckOnly) {
|
|
21926
|
+
return;
|
|
21927
|
+
}
|
|
21928
|
+
this.#index = index;
|
|
21929
|
+
return;
|
|
21930
|
+
}
|
|
21931
|
+
const [token, ...restTokens] = tokens;
|
|
21932
|
+
const pattern = token === "*" ? restTokens.length === 0 ? ["", "", ONLY_WILDCARD_REG_EXP_STR] : ["", "", LABEL_REG_EXP_STR] : token === "/*" ? ["", "", TAIL_WILDCARD_REG_EXP_STR] : token.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
|
|
21933
|
+
let node;
|
|
21934
|
+
if (pattern) {
|
|
21935
|
+
const name = pattern[1];
|
|
21936
|
+
let regexpStr = pattern[2] || LABEL_REG_EXP_STR;
|
|
21937
|
+
if (name && pattern[2]) {
|
|
21938
|
+
if (regexpStr === ".*") {
|
|
21939
|
+
throw PATH_ERROR;
|
|
21940
|
+
}
|
|
21941
|
+
regexpStr = regexpStr.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:");
|
|
21942
|
+
if (/\((?!\?:)/.test(regexpStr)) {
|
|
21943
|
+
throw PATH_ERROR;
|
|
21944
|
+
}
|
|
21945
|
+
}
|
|
21946
|
+
node = this.#children[regexpStr];
|
|
21947
|
+
if (!node) {
|
|
21948
|
+
if (Object.keys(this.#children).some((k) => k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR)) {
|
|
21949
|
+
throw PATH_ERROR;
|
|
21950
|
+
}
|
|
21951
|
+
if (pathErrorCheckOnly) {
|
|
21952
|
+
return;
|
|
21953
|
+
}
|
|
21954
|
+
node = this.#children[regexpStr] = new _Node;
|
|
21955
|
+
if (name !== "") {
|
|
21956
|
+
node.#varIndex = context.varIndex++;
|
|
21957
|
+
}
|
|
21958
|
+
}
|
|
21959
|
+
if (!pathErrorCheckOnly && name !== "") {
|
|
21960
|
+
paramMap.push([name, node.#varIndex]);
|
|
21961
|
+
}
|
|
21962
|
+
} else {
|
|
21963
|
+
node = this.#children[token];
|
|
21964
|
+
if (!node) {
|
|
21965
|
+
if (Object.keys(this.#children).some((k) => k.length > 1 && k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR)) {
|
|
21966
|
+
throw PATH_ERROR;
|
|
21967
|
+
}
|
|
21968
|
+
if (pathErrorCheckOnly) {
|
|
21969
|
+
return;
|
|
21970
|
+
}
|
|
21971
|
+
node = this.#children[token] = new _Node;
|
|
21972
|
+
}
|
|
21973
|
+
}
|
|
21974
|
+
node.insert(restTokens, index, paramMap, context, pathErrorCheckOnly);
|
|
21975
|
+
}
|
|
21976
|
+
buildRegExpStr() {
|
|
21977
|
+
const childKeys = Object.keys(this.#children).sort(compareKey);
|
|
21978
|
+
const strList = childKeys.map((k) => {
|
|
21979
|
+
const c = this.#children[k];
|
|
21980
|
+
return (typeof c.#varIndex === "number" ? `(${k})@${c.#varIndex}` : regExpMetaChars.has(k) ? `\\${k}` : k) + c.buildRegExpStr();
|
|
21981
|
+
});
|
|
21982
|
+
if (typeof this.#index === "number") {
|
|
21983
|
+
strList.unshift(`#${this.#index}`);
|
|
21984
|
+
}
|
|
21985
|
+
if (strList.length === 0) {
|
|
21986
|
+
return "";
|
|
21987
|
+
}
|
|
21988
|
+
if (strList.length === 1) {
|
|
21989
|
+
return strList[0];
|
|
21990
|
+
}
|
|
21991
|
+
return "(?:" + strList.join("|") + ")";
|
|
21992
|
+
}
|
|
21993
|
+
};
|
|
21994
|
+
|
|
21995
|
+
// node_modules/hono/dist/router/reg-exp-router/trie.js
|
|
21996
|
+
var Trie = class {
|
|
21997
|
+
#context = { varIndex: 0 };
|
|
21998
|
+
#root = new Node;
|
|
21999
|
+
insert(path, index, pathErrorCheckOnly) {
|
|
22000
|
+
const paramAssoc = [];
|
|
22001
|
+
const groups = [];
|
|
22002
|
+
for (let i = 0;; ) {
|
|
22003
|
+
let replaced = false;
|
|
22004
|
+
path = path.replace(/\{[^}]+\}/g, (m) => {
|
|
22005
|
+
const mark = `@\\${i}`;
|
|
22006
|
+
groups[i] = [mark, m];
|
|
22007
|
+
i++;
|
|
22008
|
+
replaced = true;
|
|
22009
|
+
return mark;
|
|
22010
|
+
});
|
|
22011
|
+
if (!replaced) {
|
|
22012
|
+
break;
|
|
22013
|
+
}
|
|
22014
|
+
}
|
|
22015
|
+
const tokens = path.match(/(?::[^\/]+)|(?:\/\*$)|./g) || [];
|
|
22016
|
+
for (let i = groups.length - 1;i >= 0; i--) {
|
|
22017
|
+
const [mark] = groups[i];
|
|
22018
|
+
for (let j = tokens.length - 1;j >= 0; j--) {
|
|
22019
|
+
if (tokens[j].indexOf(mark) !== -1) {
|
|
22020
|
+
tokens[j] = tokens[j].replace(mark, groups[i][1]);
|
|
22021
|
+
break;
|
|
22022
|
+
}
|
|
22023
|
+
}
|
|
22024
|
+
}
|
|
22025
|
+
this.#root.insert(tokens, index, paramAssoc, this.#context, pathErrorCheckOnly);
|
|
22026
|
+
return paramAssoc;
|
|
22027
|
+
}
|
|
22028
|
+
buildRegExp() {
|
|
22029
|
+
let regexp = this.#root.buildRegExpStr();
|
|
22030
|
+
if (regexp === "") {
|
|
22031
|
+
return [/^$/, [], []];
|
|
22032
|
+
}
|
|
22033
|
+
let captureIndex = 0;
|
|
22034
|
+
const indexReplacementMap = [];
|
|
22035
|
+
const paramReplacementMap = [];
|
|
22036
|
+
regexp = regexp.replace(/#(\d+)|@(\d+)|\.\*\$/g, (_, handlerIndex, paramIndex) => {
|
|
22037
|
+
if (handlerIndex !== undefined) {
|
|
22038
|
+
indexReplacementMap[++captureIndex] = Number(handlerIndex);
|
|
22039
|
+
return "$()";
|
|
22040
|
+
}
|
|
22041
|
+
if (paramIndex !== undefined) {
|
|
22042
|
+
paramReplacementMap[Number(paramIndex)] = ++captureIndex;
|
|
22043
|
+
return "";
|
|
22044
|
+
}
|
|
22045
|
+
return "";
|
|
22046
|
+
});
|
|
22047
|
+
return [new RegExp(`^${regexp}`), indexReplacementMap, paramReplacementMap];
|
|
22048
|
+
}
|
|
22049
|
+
};
|
|
22050
|
+
|
|
22051
|
+
// node_modules/hono/dist/router/reg-exp-router/router.js
|
|
22052
|
+
var nullMatcher = [/^$/, [], /* @__PURE__ */ Object.create(null)];
|
|
22053
|
+
var wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
|
|
22054
|
+
function buildWildcardRegExp(path) {
|
|
22055
|
+
return wildcardRegExpCache[path] ??= new RegExp(path === "*" ? "" : `^${path.replace(/\/\*$|([.\\+*[^\]$()])/g, (_, metaChar) => metaChar ? `\\${metaChar}` : "(?:|/.*)")}$`);
|
|
22056
|
+
}
|
|
22057
|
+
function clearWildcardRegExpCache() {
|
|
22058
|
+
wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
|
|
22059
|
+
}
|
|
22060
|
+
function buildMatcherFromPreprocessedRoutes(routes) {
|
|
22061
|
+
const trie = new Trie;
|
|
22062
|
+
const handlerData = [];
|
|
22063
|
+
if (routes.length === 0) {
|
|
22064
|
+
return nullMatcher;
|
|
22065
|
+
}
|
|
22066
|
+
const routesWithStaticPathFlag = routes.map((route) => [!/\*|\/:/.test(route[0]), ...route]).sort(([isStaticA, pathA], [isStaticB, pathB]) => isStaticA ? 1 : isStaticB ? -1 : pathA.length - pathB.length);
|
|
22067
|
+
const staticMap = /* @__PURE__ */ Object.create(null);
|
|
22068
|
+
for (let i = 0, j = -1, len = routesWithStaticPathFlag.length;i < len; i++) {
|
|
22069
|
+
const [pathErrorCheckOnly, path, handlers] = routesWithStaticPathFlag[i];
|
|
22070
|
+
if (pathErrorCheckOnly) {
|
|
22071
|
+
staticMap[path] = [handlers.map(([h]) => [h, /* @__PURE__ */ Object.create(null)]), emptyParam];
|
|
22072
|
+
} else {
|
|
22073
|
+
j++;
|
|
22074
|
+
}
|
|
22075
|
+
let paramAssoc;
|
|
22076
|
+
try {
|
|
22077
|
+
paramAssoc = trie.insert(path, j, pathErrorCheckOnly);
|
|
22078
|
+
} catch (e) {
|
|
22079
|
+
throw e === PATH_ERROR ? new UnsupportedPathError(path) : e;
|
|
22080
|
+
}
|
|
22081
|
+
if (pathErrorCheckOnly) {
|
|
22082
|
+
continue;
|
|
22083
|
+
}
|
|
22084
|
+
handlerData[j] = handlers.map(([h, paramCount]) => {
|
|
22085
|
+
const paramIndexMap = /* @__PURE__ */ Object.create(null);
|
|
22086
|
+
paramCount -= 1;
|
|
22087
|
+
for (;paramCount >= 0; paramCount--) {
|
|
22088
|
+
const [key, value] = paramAssoc[paramCount];
|
|
22089
|
+
paramIndexMap[key] = value;
|
|
22090
|
+
}
|
|
22091
|
+
return [h, paramIndexMap];
|
|
22092
|
+
});
|
|
22093
|
+
}
|
|
22094
|
+
const [regexp, indexReplacementMap, paramReplacementMap] = trie.buildRegExp();
|
|
22095
|
+
for (let i = 0, len = handlerData.length;i < len; i++) {
|
|
22096
|
+
for (let j = 0, len2 = handlerData[i].length;j < len2; j++) {
|
|
22097
|
+
const map2 = handlerData[i][j]?.[1];
|
|
22098
|
+
if (!map2) {
|
|
22099
|
+
continue;
|
|
22100
|
+
}
|
|
22101
|
+
const keys = Object.keys(map2);
|
|
22102
|
+
for (let k = 0, len3 = keys.length;k < len3; k++) {
|
|
22103
|
+
map2[keys[k]] = paramReplacementMap[map2[keys[k]]];
|
|
22104
|
+
}
|
|
22105
|
+
}
|
|
22106
|
+
}
|
|
22107
|
+
const handlerMap = [];
|
|
22108
|
+
for (const i in indexReplacementMap) {
|
|
22109
|
+
handlerMap[i] = handlerData[indexReplacementMap[i]];
|
|
22110
|
+
}
|
|
22111
|
+
return [regexp, handlerMap, staticMap];
|
|
22112
|
+
}
|
|
22113
|
+
function findMiddleware(middleware, path) {
|
|
22114
|
+
if (!middleware) {
|
|
22115
|
+
return;
|
|
22116
|
+
}
|
|
22117
|
+
for (const k of Object.keys(middleware).sort((a, b) => b.length - a.length)) {
|
|
22118
|
+
if (buildWildcardRegExp(k).test(path)) {
|
|
22119
|
+
return [...middleware[k]];
|
|
22120
|
+
}
|
|
22121
|
+
}
|
|
22122
|
+
return;
|
|
22123
|
+
}
|
|
22124
|
+
var RegExpRouter = class {
|
|
22125
|
+
name = "RegExpRouter";
|
|
22126
|
+
#middleware;
|
|
22127
|
+
#routes;
|
|
22128
|
+
constructor() {
|
|
22129
|
+
this.#middleware = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
|
|
22130
|
+
this.#routes = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
|
|
22131
|
+
}
|
|
22132
|
+
add(method, path, handler) {
|
|
22133
|
+
const middleware = this.#middleware;
|
|
22134
|
+
const routes = this.#routes;
|
|
22135
|
+
if (!middleware || !routes) {
|
|
22136
|
+
throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
|
|
22137
|
+
}
|
|
22138
|
+
if (!middleware[method]) {
|
|
22139
|
+
[middleware, routes].forEach((handlerMap) => {
|
|
22140
|
+
handlerMap[method] = /* @__PURE__ */ Object.create(null);
|
|
22141
|
+
Object.keys(handlerMap[METHOD_NAME_ALL]).forEach((p) => {
|
|
22142
|
+
handlerMap[method][p] = [...handlerMap[METHOD_NAME_ALL][p]];
|
|
22143
|
+
});
|
|
22144
|
+
});
|
|
22145
|
+
}
|
|
22146
|
+
if (path === "/*") {
|
|
22147
|
+
path = "*";
|
|
22148
|
+
}
|
|
22149
|
+
const paramCount = (path.match(/\/:/g) || []).length;
|
|
22150
|
+
if (/\*$/.test(path)) {
|
|
22151
|
+
const re = buildWildcardRegExp(path);
|
|
22152
|
+
if (method === METHOD_NAME_ALL) {
|
|
22153
|
+
Object.keys(middleware).forEach((m) => {
|
|
22154
|
+
middleware[m][path] ||= findMiddleware(middleware[m], path) || findMiddleware(middleware[METHOD_NAME_ALL], path) || [];
|
|
22155
|
+
});
|
|
22156
|
+
} else {
|
|
22157
|
+
middleware[method][path] ||= findMiddleware(middleware[method], path) || findMiddleware(middleware[METHOD_NAME_ALL], path) || [];
|
|
22158
|
+
}
|
|
22159
|
+
Object.keys(middleware).forEach((m) => {
|
|
22160
|
+
if (method === METHOD_NAME_ALL || method === m) {
|
|
22161
|
+
Object.keys(middleware[m]).forEach((p) => {
|
|
22162
|
+
re.test(p) && middleware[m][p].push([handler, paramCount]);
|
|
22163
|
+
});
|
|
22164
|
+
}
|
|
22165
|
+
});
|
|
22166
|
+
Object.keys(routes).forEach((m) => {
|
|
22167
|
+
if (method === METHOD_NAME_ALL || method === m) {
|
|
22168
|
+
Object.keys(routes[m]).forEach((p) => re.test(p) && routes[m][p].push([handler, paramCount]));
|
|
22169
|
+
}
|
|
22170
|
+
});
|
|
22171
|
+
return;
|
|
22172
|
+
}
|
|
22173
|
+
const paths = checkOptionalParameter(path) || [path];
|
|
22174
|
+
for (let i = 0, len = paths.length;i < len; i++) {
|
|
22175
|
+
const path2 = paths[i];
|
|
22176
|
+
Object.keys(routes).forEach((m) => {
|
|
22177
|
+
if (method === METHOD_NAME_ALL || method === m) {
|
|
22178
|
+
routes[m][path2] ||= [
|
|
22179
|
+
...findMiddleware(middleware[m], path2) || findMiddleware(middleware[METHOD_NAME_ALL], path2) || []
|
|
22180
|
+
];
|
|
22181
|
+
routes[m][path2].push([handler, paramCount - len + i + 1]);
|
|
22182
|
+
}
|
|
22183
|
+
});
|
|
22184
|
+
}
|
|
22185
|
+
}
|
|
22186
|
+
match = match;
|
|
22187
|
+
buildAllMatchers() {
|
|
22188
|
+
const matchers = /* @__PURE__ */ Object.create(null);
|
|
22189
|
+
Object.keys(this.#routes).concat(Object.keys(this.#middleware)).forEach((method) => {
|
|
22190
|
+
matchers[method] ||= this.#buildMatcher(method);
|
|
22191
|
+
});
|
|
22192
|
+
this.#middleware = this.#routes = undefined;
|
|
22193
|
+
clearWildcardRegExpCache();
|
|
22194
|
+
return matchers;
|
|
22195
|
+
}
|
|
22196
|
+
#buildMatcher(method) {
|
|
22197
|
+
const routes = [];
|
|
22198
|
+
let hasOwnRoute = method === METHOD_NAME_ALL;
|
|
22199
|
+
[this.#middleware, this.#routes].forEach((r) => {
|
|
22200
|
+
const ownRoute = r[method] ? Object.keys(r[method]).map((path) => [path, r[method][path]]) : [];
|
|
22201
|
+
if (ownRoute.length !== 0) {
|
|
22202
|
+
hasOwnRoute ||= true;
|
|
22203
|
+
routes.push(...ownRoute);
|
|
22204
|
+
} else if (method !== METHOD_NAME_ALL) {
|
|
22205
|
+
routes.push(...Object.keys(r[METHOD_NAME_ALL]).map((path) => [path, r[METHOD_NAME_ALL][path]]));
|
|
22206
|
+
}
|
|
22207
|
+
});
|
|
22208
|
+
if (!hasOwnRoute) {
|
|
22209
|
+
return null;
|
|
22210
|
+
} else {
|
|
22211
|
+
return buildMatcherFromPreprocessedRoutes(routes);
|
|
22212
|
+
}
|
|
22213
|
+
}
|
|
22214
|
+
};
|
|
22215
|
+
|
|
22216
|
+
// node_modules/hono/dist/router/reg-exp-router/prepared-router.js
|
|
22217
|
+
var PreparedRegExpRouter = class {
|
|
22218
|
+
name = "PreparedRegExpRouter";
|
|
22219
|
+
#matchers;
|
|
22220
|
+
#relocateMap;
|
|
22221
|
+
constructor(matchers, relocateMap) {
|
|
22222
|
+
this.#matchers = matchers;
|
|
22223
|
+
this.#relocateMap = relocateMap;
|
|
22224
|
+
}
|
|
22225
|
+
#addWildcard(method, handlerData) {
|
|
22226
|
+
const matcher = this.#matchers[method];
|
|
22227
|
+
matcher[1].forEach((list) => list && list.push(handlerData));
|
|
22228
|
+
Object.values(matcher[2]).forEach((list) => list[0].push(handlerData));
|
|
22229
|
+
}
|
|
22230
|
+
#addPath(method, path, handler, indexes, map2) {
|
|
22231
|
+
const matcher = this.#matchers[method];
|
|
22232
|
+
if (!map2) {
|
|
22233
|
+
matcher[2][path][0].push([handler, {}]);
|
|
22234
|
+
} else {
|
|
22235
|
+
indexes.forEach((index) => {
|
|
22236
|
+
if (typeof index === "number") {
|
|
22237
|
+
matcher[1][index].push([handler, map2]);
|
|
22238
|
+
} else {
|
|
22239
|
+
matcher[2][index || path][0].push([handler, map2]);
|
|
22240
|
+
}
|
|
22241
|
+
});
|
|
22242
|
+
}
|
|
22243
|
+
}
|
|
22244
|
+
add(method, path, handler) {
|
|
22245
|
+
if (!this.#matchers[method]) {
|
|
22246
|
+
const all = this.#matchers[METHOD_NAME_ALL];
|
|
22247
|
+
const staticMap = {};
|
|
22248
|
+
for (const key in all[2]) {
|
|
22249
|
+
staticMap[key] = [all[2][key][0].slice(), emptyParam];
|
|
22250
|
+
}
|
|
22251
|
+
this.#matchers[method] = [
|
|
22252
|
+
all[0],
|
|
22253
|
+
all[1].map((list) => Array.isArray(list) ? list.slice() : 0),
|
|
22254
|
+
staticMap
|
|
22255
|
+
];
|
|
22256
|
+
}
|
|
22257
|
+
if (path === "/*" || path === "*") {
|
|
22258
|
+
const handlerData = [handler, {}];
|
|
22259
|
+
if (method === METHOD_NAME_ALL) {
|
|
22260
|
+
for (const m in this.#matchers) {
|
|
22261
|
+
this.#addWildcard(m, handlerData);
|
|
22262
|
+
}
|
|
22263
|
+
} else {
|
|
22264
|
+
this.#addWildcard(method, handlerData);
|
|
22265
|
+
}
|
|
22266
|
+
return;
|
|
22267
|
+
}
|
|
22268
|
+
const data = this.#relocateMap[path];
|
|
22269
|
+
if (!data) {
|
|
22270
|
+
throw new Error(`Path ${path} is not registered`);
|
|
22271
|
+
}
|
|
22272
|
+
for (const [indexes, map2] of data) {
|
|
22273
|
+
if (method === METHOD_NAME_ALL) {
|
|
22274
|
+
for (const m in this.#matchers) {
|
|
22275
|
+
this.#addPath(m, path, handler, indexes, map2);
|
|
22276
|
+
}
|
|
22277
|
+
} else {
|
|
22278
|
+
this.#addPath(method, path, handler, indexes, map2);
|
|
22279
|
+
}
|
|
22280
|
+
}
|
|
22281
|
+
}
|
|
22282
|
+
buildAllMatchers() {
|
|
22283
|
+
return this.#matchers;
|
|
22284
|
+
}
|
|
22285
|
+
match = match;
|
|
22286
|
+
};
|
|
22287
|
+
|
|
22288
|
+
// node_modules/hono/dist/router/smart-router/router.js
|
|
22289
|
+
var SmartRouter = class {
|
|
22290
|
+
name = "SmartRouter";
|
|
22291
|
+
#routers = [];
|
|
22292
|
+
#routes = [];
|
|
22293
|
+
constructor(init) {
|
|
22294
|
+
this.#routers = init.routers;
|
|
22295
|
+
}
|
|
22296
|
+
add(method, path, handler) {
|
|
22297
|
+
if (!this.#routes) {
|
|
22298
|
+
throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
|
|
22299
|
+
}
|
|
22300
|
+
this.#routes.push([method, path, handler]);
|
|
22301
|
+
}
|
|
22302
|
+
match(method, path) {
|
|
22303
|
+
if (!this.#routes) {
|
|
22304
|
+
throw new Error("Fatal error");
|
|
22305
|
+
}
|
|
22306
|
+
const routers = this.#routers;
|
|
22307
|
+
const routes = this.#routes;
|
|
22308
|
+
const len = routers.length;
|
|
22309
|
+
let i = 0;
|
|
22310
|
+
let res;
|
|
22311
|
+
for (;i < len; i++) {
|
|
22312
|
+
const router = routers[i];
|
|
22313
|
+
try {
|
|
22314
|
+
for (let i2 = 0, len2 = routes.length;i2 < len2; i2++) {
|
|
22315
|
+
router.add(...routes[i2]);
|
|
22316
|
+
}
|
|
22317
|
+
res = router.match(method, path);
|
|
22318
|
+
} catch (e) {
|
|
22319
|
+
if (e instanceof UnsupportedPathError) {
|
|
22320
|
+
continue;
|
|
22321
|
+
}
|
|
22322
|
+
throw e;
|
|
22323
|
+
}
|
|
22324
|
+
this.match = router.match.bind(router);
|
|
22325
|
+
this.#routers = [router];
|
|
22326
|
+
this.#routes = undefined;
|
|
22327
|
+
break;
|
|
22328
|
+
}
|
|
22329
|
+
if (i === len) {
|
|
22330
|
+
throw new Error("Fatal error");
|
|
22331
|
+
}
|
|
22332
|
+
this.name = `SmartRouter + ${this.activeRouter.name}`;
|
|
22333
|
+
return res;
|
|
22334
|
+
}
|
|
22335
|
+
get activeRouter() {
|
|
22336
|
+
if (this.#routes || this.#routers.length !== 1) {
|
|
22337
|
+
throw new Error("No active router has been determined yet.");
|
|
22338
|
+
}
|
|
22339
|
+
return this.#routers[0];
|
|
22340
|
+
}
|
|
22341
|
+
};
|
|
22342
|
+
|
|
22343
|
+
// node_modules/hono/dist/router/trie-router/node.js
|
|
22344
|
+
var emptyParams = /* @__PURE__ */ Object.create(null);
|
|
22345
|
+
var hasChildren = (children) => {
|
|
22346
|
+
for (const _ in children) {
|
|
22347
|
+
return true;
|
|
22348
|
+
}
|
|
22349
|
+
return false;
|
|
22350
|
+
};
|
|
22351
|
+
var Node2 = class _Node2 {
|
|
22352
|
+
#methods;
|
|
22353
|
+
#children;
|
|
22354
|
+
#patterns;
|
|
22355
|
+
#order = 0;
|
|
22356
|
+
#params = emptyParams;
|
|
22357
|
+
constructor(method, handler, children) {
|
|
22358
|
+
this.#children = children || /* @__PURE__ */ Object.create(null);
|
|
22359
|
+
this.#methods = [];
|
|
22360
|
+
if (method && handler) {
|
|
22361
|
+
const m = /* @__PURE__ */ Object.create(null);
|
|
22362
|
+
m[method] = { handler, possibleKeys: [], score: 0 };
|
|
22363
|
+
this.#methods = [m];
|
|
22364
|
+
}
|
|
22365
|
+
this.#patterns = [];
|
|
22366
|
+
}
|
|
22367
|
+
insert(method, path, handler) {
|
|
22368
|
+
this.#order = ++this.#order;
|
|
22369
|
+
let curNode = this;
|
|
22370
|
+
const parts = splitRoutingPath(path);
|
|
22371
|
+
const possibleKeys = [];
|
|
22372
|
+
for (let i = 0, len = parts.length;i < len; i++) {
|
|
22373
|
+
const p = parts[i];
|
|
22374
|
+
const nextP = parts[i + 1];
|
|
22375
|
+
const pattern = getPattern(p, nextP);
|
|
22376
|
+
const key = Array.isArray(pattern) ? pattern[0] : p;
|
|
22377
|
+
if (key in curNode.#children) {
|
|
22378
|
+
curNode = curNode.#children[key];
|
|
22379
|
+
if (pattern) {
|
|
22380
|
+
possibleKeys.push(pattern[1]);
|
|
22381
|
+
}
|
|
22382
|
+
continue;
|
|
22383
|
+
}
|
|
22384
|
+
curNode.#children[key] = new _Node2;
|
|
22385
|
+
if (pattern) {
|
|
22386
|
+
curNode.#patterns.push(pattern);
|
|
22387
|
+
possibleKeys.push(pattern[1]);
|
|
22388
|
+
}
|
|
22389
|
+
curNode = curNode.#children[key];
|
|
22390
|
+
}
|
|
22391
|
+
curNode.#methods.push({
|
|
22392
|
+
[method]: {
|
|
22393
|
+
handler,
|
|
22394
|
+
possibleKeys: possibleKeys.filter((v, i, a) => a.indexOf(v) === i),
|
|
22395
|
+
score: this.#order
|
|
22396
|
+
}
|
|
22397
|
+
});
|
|
22398
|
+
return curNode;
|
|
22399
|
+
}
|
|
22400
|
+
#pushHandlerSets(handlerSets, node, method, nodeParams, params) {
|
|
22401
|
+
for (let i = 0, len = node.#methods.length;i < len; i++) {
|
|
22402
|
+
const m = node.#methods[i];
|
|
22403
|
+
const handlerSet = m[method] || m[METHOD_NAME_ALL];
|
|
22404
|
+
const processedSet = {};
|
|
22405
|
+
if (handlerSet !== undefined) {
|
|
22406
|
+
handlerSet.params = /* @__PURE__ */ Object.create(null);
|
|
22407
|
+
handlerSets.push(handlerSet);
|
|
22408
|
+
if (nodeParams !== emptyParams || params && params !== emptyParams) {
|
|
22409
|
+
for (let i2 = 0, len2 = handlerSet.possibleKeys.length;i2 < len2; i2++) {
|
|
22410
|
+
const key = handlerSet.possibleKeys[i2];
|
|
22411
|
+
const processed = processedSet[handlerSet.score];
|
|
22412
|
+
handlerSet.params[key] = params?.[key] && !processed ? params[key] : nodeParams[key] ?? params?.[key];
|
|
22413
|
+
processedSet[handlerSet.score] = true;
|
|
22414
|
+
}
|
|
22415
|
+
}
|
|
22416
|
+
}
|
|
22417
|
+
}
|
|
22418
|
+
}
|
|
22419
|
+
search(method, path) {
|
|
22420
|
+
const handlerSets = [];
|
|
22421
|
+
this.#params = emptyParams;
|
|
22422
|
+
const curNode = this;
|
|
22423
|
+
let curNodes = [curNode];
|
|
22424
|
+
const parts = splitPath(path);
|
|
22425
|
+
const curNodesQueue = [];
|
|
22426
|
+
const len = parts.length;
|
|
22427
|
+
let partOffsets = null;
|
|
22428
|
+
for (let i = 0;i < len; i++) {
|
|
22429
|
+
const part = parts[i];
|
|
22430
|
+
const isLast = i === len - 1;
|
|
22431
|
+
const tempNodes = [];
|
|
22432
|
+
for (let j = 0, len2 = curNodes.length;j < len2; j++) {
|
|
22433
|
+
const node = curNodes[j];
|
|
22434
|
+
const nextNode = node.#children[part];
|
|
22435
|
+
if (nextNode) {
|
|
22436
|
+
nextNode.#params = node.#params;
|
|
22437
|
+
if (isLast) {
|
|
22438
|
+
if (nextNode.#children["*"]) {
|
|
22439
|
+
this.#pushHandlerSets(handlerSets, nextNode.#children["*"], method, node.#params);
|
|
22440
|
+
}
|
|
22441
|
+
this.#pushHandlerSets(handlerSets, nextNode, method, node.#params);
|
|
22442
|
+
} else {
|
|
22443
|
+
tempNodes.push(nextNode);
|
|
22444
|
+
}
|
|
22445
|
+
}
|
|
22446
|
+
for (let k = 0, len3 = node.#patterns.length;k < len3; k++) {
|
|
22447
|
+
const pattern = node.#patterns[k];
|
|
22448
|
+
const params = node.#params === emptyParams ? {} : { ...node.#params };
|
|
22449
|
+
if (pattern === "*") {
|
|
22450
|
+
const astNode = node.#children["*"];
|
|
22451
|
+
if (astNode) {
|
|
22452
|
+
this.#pushHandlerSets(handlerSets, astNode, method, node.#params);
|
|
22453
|
+
astNode.#params = params;
|
|
22454
|
+
tempNodes.push(astNode);
|
|
22455
|
+
}
|
|
22456
|
+
continue;
|
|
22457
|
+
}
|
|
22458
|
+
const [key, name, matcher] = pattern;
|
|
22459
|
+
if (!part && !(matcher instanceof RegExp)) {
|
|
22460
|
+
continue;
|
|
22461
|
+
}
|
|
22462
|
+
const child = node.#children[key];
|
|
22463
|
+
if (matcher instanceof RegExp) {
|
|
22464
|
+
if (partOffsets === null) {
|
|
22465
|
+
partOffsets = new Array(len);
|
|
22466
|
+
let offset = path[0] === "/" ? 1 : 0;
|
|
22467
|
+
for (let p = 0;p < len; p++) {
|
|
22468
|
+
partOffsets[p] = offset;
|
|
22469
|
+
offset += parts[p].length + 1;
|
|
22470
|
+
}
|
|
22471
|
+
}
|
|
22472
|
+
const restPathString = path.substring(partOffsets[i]);
|
|
22473
|
+
const m = matcher.exec(restPathString);
|
|
22474
|
+
if (m) {
|
|
22475
|
+
params[name] = m[0];
|
|
22476
|
+
this.#pushHandlerSets(handlerSets, child, method, node.#params, params);
|
|
22477
|
+
if (hasChildren(child.#children)) {
|
|
22478
|
+
child.#params = params;
|
|
22479
|
+
const componentCount = m[0].match(/\//)?.length ?? 0;
|
|
22480
|
+
const targetCurNodes = curNodesQueue[componentCount] ||= [];
|
|
22481
|
+
targetCurNodes.push(child);
|
|
22482
|
+
}
|
|
22483
|
+
continue;
|
|
22484
|
+
}
|
|
22485
|
+
}
|
|
22486
|
+
if (matcher === true || matcher.test(part)) {
|
|
22487
|
+
params[name] = part;
|
|
22488
|
+
if (isLast) {
|
|
22489
|
+
this.#pushHandlerSets(handlerSets, child, method, params, node.#params);
|
|
22490
|
+
if (child.#children["*"]) {
|
|
22491
|
+
this.#pushHandlerSets(handlerSets, child.#children["*"], method, params, node.#params);
|
|
22492
|
+
}
|
|
22493
|
+
} else {
|
|
22494
|
+
child.#params = params;
|
|
22495
|
+
tempNodes.push(child);
|
|
22496
|
+
}
|
|
22497
|
+
}
|
|
22498
|
+
}
|
|
22499
|
+
}
|
|
22500
|
+
const shifted = curNodesQueue.shift();
|
|
22501
|
+
curNodes = shifted ? tempNodes.concat(shifted) : tempNodes;
|
|
22502
|
+
}
|
|
22503
|
+
if (handlerSets.length > 1) {
|
|
22504
|
+
handlerSets.sort((a, b) => {
|
|
22505
|
+
return a.score - b.score;
|
|
22506
|
+
});
|
|
22507
|
+
}
|
|
22508
|
+
return [handlerSets.map(({ handler, params }) => [handler, params])];
|
|
22509
|
+
}
|
|
22510
|
+
};
|
|
22511
|
+
|
|
22512
|
+
// node_modules/hono/dist/router/trie-router/router.js
|
|
22513
|
+
var TrieRouter = class {
|
|
22514
|
+
name = "TrieRouter";
|
|
22515
|
+
#node;
|
|
22516
|
+
constructor() {
|
|
22517
|
+
this.#node = new Node2;
|
|
22518
|
+
}
|
|
22519
|
+
add(method, path, handler) {
|
|
22520
|
+
const results = checkOptionalParameter(path);
|
|
22521
|
+
if (results) {
|
|
22522
|
+
for (let i = 0, len = results.length;i < len; i++) {
|
|
22523
|
+
this.#node.insert(method, results[i], handler);
|
|
22524
|
+
}
|
|
22525
|
+
return;
|
|
22526
|
+
}
|
|
22527
|
+
this.#node.insert(method, path, handler);
|
|
22528
|
+
}
|
|
22529
|
+
match(method, path) {
|
|
22530
|
+
return this.#node.search(method, path);
|
|
22531
|
+
}
|
|
22532
|
+
};
|
|
22533
|
+
|
|
22534
|
+
// node_modules/hono/dist/hono.js
|
|
22535
|
+
var Hono2 = class extends Hono {
|
|
22536
|
+
constructor(options = {}) {
|
|
22537
|
+
super(options);
|
|
22538
|
+
this.router = options.router ?? new SmartRouter({
|
|
22539
|
+
routers: [new RegExpRouter, new TrieRouter]
|
|
22540
|
+
});
|
|
22541
|
+
}
|
|
22542
|
+
};
|
|
22543
|
+
|
|
22544
|
+
// src/ui/styles.css
|
|
22545
|
+
var styles_default = `*,
|
|
22546
|
+
*::before,
|
|
22547
|
+
*::after {
|
|
22548
|
+
box-sizing: border-box;
|
|
22549
|
+
margin: 0;
|
|
22550
|
+
padding: 0;
|
|
22551
|
+
}
|
|
22552
|
+
|
|
22553
|
+
:root {
|
|
22554
|
+
--bg: #fafafa;
|
|
22555
|
+
--surface: #fff;
|
|
22556
|
+
--border: #e0e0e0;
|
|
22557
|
+
--text: #1a1a1a;
|
|
22558
|
+
--text-muted: #666;
|
|
22559
|
+
--primary: #2563eb;
|
|
22560
|
+
--danger: #dc2626;
|
|
22561
|
+
--sidebar-w: 220px;
|
|
22562
|
+
--radius: 6px;
|
|
22563
|
+
--gap: 16px;
|
|
22564
|
+
}
|
|
22565
|
+
|
|
22566
|
+
@media (prefers-color-scheme: dark) {
|
|
22567
|
+
:root {
|
|
22568
|
+
--bg: #111;
|
|
22569
|
+
--surface: #1a1a1a;
|
|
22570
|
+
--border: #333;
|
|
22571
|
+
--text: #e5e5e5;
|
|
22572
|
+
--text-muted: #999;
|
|
22573
|
+
--primary: #60a5fa;
|
|
22574
|
+
--danger: #f87171;
|
|
22575
|
+
}
|
|
22576
|
+
}
|
|
22577
|
+
|
|
22578
|
+
body {
|
|
22579
|
+
font-family: system-ui, -apple-system, sans-serif;
|
|
22580
|
+
background: var(--bg);
|
|
22581
|
+
color: var(--text);
|
|
22582
|
+
line-height: 1.5;
|
|
22583
|
+
}
|
|
22584
|
+
|
|
22585
|
+
.layout {
|
|
22586
|
+
display: flex;
|
|
22587
|
+
min-height: 100vh;
|
|
22588
|
+
}
|
|
22589
|
+
|
|
22590
|
+
.sidebar {
|
|
22591
|
+
width: var(--sidebar-w);
|
|
22592
|
+
flex-shrink: 0;
|
|
22593
|
+
border-right: 1px solid var(--border);
|
|
22594
|
+
background: var(--surface);
|
|
22595
|
+
padding: var(--gap) 0;
|
|
22596
|
+
overflow-y: auto;
|
|
22597
|
+
}
|
|
22598
|
+
|
|
22599
|
+
@media (min-width: 1200px) {
|
|
22600
|
+
:root {
|
|
22601
|
+
--sidebar-w: 280px;
|
|
22602
|
+
}
|
|
22603
|
+
}
|
|
22604
|
+
|
|
22605
|
+
@media (min-width: 1600px) {
|
|
22606
|
+
:root {
|
|
22607
|
+
--sidebar-w: 340px;
|
|
22608
|
+
}
|
|
22609
|
+
}
|
|
22610
|
+
|
|
22611
|
+
.sidebar h2 {
|
|
22612
|
+
font-size: 0.75rem;
|
|
22613
|
+
text-transform: uppercase;
|
|
22614
|
+
color: var(--text-muted);
|
|
22615
|
+
padding: 0 var(--gap);
|
|
22616
|
+
margin-bottom: 8px;
|
|
22617
|
+
letter-spacing: 0.05em;
|
|
22618
|
+
}
|
|
22619
|
+
|
|
22620
|
+
.sidebar-item {
|
|
22621
|
+
display: block;
|
|
22622
|
+
width: 100%;
|
|
22623
|
+
padding: 6px var(--gap);
|
|
22624
|
+
font-size: 0.8125rem;
|
|
22625
|
+
color: var(--text);
|
|
22626
|
+
text-decoration: none;
|
|
22627
|
+
}
|
|
22628
|
+
|
|
22629
|
+
.sidebar-item.ws-item {
|
|
22630
|
+
direction: rtl;
|
|
22631
|
+
white-space: nowrap;
|
|
22632
|
+
overflow: hidden;
|
|
22633
|
+
text-overflow: ellipsis;
|
|
22634
|
+
text-align: left;
|
|
22635
|
+
}
|
|
22636
|
+
|
|
22637
|
+
.sidebar-item.ws-item span {
|
|
22638
|
+
unicode-bidi: plaintext;
|
|
22639
|
+
}
|
|
22640
|
+
.sidebar-item:hover {
|
|
22641
|
+
background: var(--bg);
|
|
22642
|
+
}
|
|
22643
|
+
.sidebar-item.active {
|
|
22644
|
+
background: var(--primary);
|
|
22645
|
+
color: #fff;
|
|
22646
|
+
}
|
|
22647
|
+
.sidebar-item.all-item {
|
|
22648
|
+
font-weight: 500;
|
|
22649
|
+
}
|
|
22650
|
+
.sidebar-item.no-ws-item {
|
|
22651
|
+
font-style: italic;
|
|
22652
|
+
color: var(--text-muted);
|
|
22653
|
+
}
|
|
22654
|
+
.sidebar-item.no-ws-item.active {
|
|
22655
|
+
color: #fff;
|
|
22656
|
+
}
|
|
22657
|
+
|
|
22658
|
+
.main {
|
|
22659
|
+
flex: 1;
|
|
22660
|
+
min-width: 0;
|
|
22661
|
+
padding: var(--gap);
|
|
22662
|
+
}
|
|
22663
|
+
|
|
22664
|
+
header {
|
|
22665
|
+
display: flex;
|
|
22666
|
+
align-items: center;
|
|
22667
|
+
justify-content: space-between;
|
|
22668
|
+
margin-bottom: var(--gap);
|
|
22669
|
+
}
|
|
22670
|
+
|
|
22671
|
+
h1 {
|
|
22672
|
+
font-size: 1.25rem;
|
|
22673
|
+
font-weight: 600;
|
|
22674
|
+
}
|
|
22675
|
+
|
|
22676
|
+
a.btn,
|
|
22677
|
+
button {
|
|
22678
|
+
cursor: pointer;
|
|
22679
|
+
border: 1px solid var(--border);
|
|
22680
|
+
border-radius: var(--radius);
|
|
22681
|
+
padding: 6px 12px;
|
|
22682
|
+
background: var(--surface);
|
|
22683
|
+
color: var(--text);
|
|
22684
|
+
font-size: 0.875rem;
|
|
22685
|
+
text-decoration: none;
|
|
22686
|
+
display: inline-block;
|
|
22687
|
+
}
|
|
22688
|
+
|
|
22689
|
+
a.btn:hover,
|
|
22690
|
+
button:hover {
|
|
22691
|
+
border-color: var(--primary);
|
|
22692
|
+
}
|
|
22693
|
+
.primary {
|
|
22694
|
+
background: var(--primary);
|
|
22695
|
+
color: #fff;
|
|
22696
|
+
border-color: var(--primary);
|
|
22697
|
+
}
|
|
22698
|
+
.danger {
|
|
22699
|
+
color: var(--danger);
|
|
22700
|
+
}
|
|
22701
|
+
.danger:hover {
|
|
22702
|
+
background: var(--danger);
|
|
22703
|
+
color: #fff;
|
|
22704
|
+
border-color: var(--danger);
|
|
22705
|
+
}
|
|
22706
|
+
|
|
22707
|
+
.card {
|
|
22708
|
+
border: 1px solid var(--border);
|
|
22709
|
+
border-radius: var(--radius);
|
|
22710
|
+
padding: var(--gap);
|
|
22711
|
+
margin-bottom: 12px;
|
|
22712
|
+
background: var(--surface);
|
|
22713
|
+
}
|
|
22714
|
+
|
|
22715
|
+
.card-header {
|
|
22716
|
+
display: flex;
|
|
22717
|
+
justify-content: space-between;
|
|
22718
|
+
align-items: flex-start;
|
|
22719
|
+
margin-bottom: 8px;
|
|
22720
|
+
}
|
|
22721
|
+
|
|
22722
|
+
.card-meta {
|
|
22723
|
+
font-size: 0.75rem;
|
|
22724
|
+
color: var(--text-muted);
|
|
22725
|
+
}
|
|
22726
|
+
|
|
22727
|
+
.badge {
|
|
22728
|
+
display: inline-block;
|
|
22729
|
+
background: var(--bg);
|
|
22730
|
+
border: 1px solid var(--border);
|
|
22731
|
+
border-radius: 3px;
|
|
22732
|
+
padding: 1px 6px;
|
|
22733
|
+
font-size: 0.75rem;
|
|
22734
|
+
color: var(--text-muted);
|
|
22735
|
+
}
|
|
22736
|
+
|
|
22737
|
+
.card-content {
|
|
22738
|
+
white-space: pre-wrap;
|
|
22739
|
+
word-break: break-word;
|
|
22740
|
+
font-size: 0.875rem;
|
|
22741
|
+
}
|
|
22742
|
+
.card-actions {
|
|
22743
|
+
display: flex;
|
|
22744
|
+
gap: 6px;
|
|
22745
|
+
margin-top: 10px;
|
|
22746
|
+
}
|
|
22747
|
+
.card-actions form {
|
|
22748
|
+
display: inline;
|
|
22749
|
+
}
|
|
22750
|
+
|
|
22751
|
+
textarea {
|
|
22752
|
+
width: 100%;
|
|
22753
|
+
min-height: 80px;
|
|
22754
|
+
border: 1px solid var(--border);
|
|
22755
|
+
border-radius: var(--radius);
|
|
22756
|
+
padding: 8px;
|
|
22757
|
+
background: var(--surface);
|
|
22758
|
+
color: var(--text);
|
|
22759
|
+
font-family: inherit;
|
|
22760
|
+
font-size: 0.875rem;
|
|
22761
|
+
resize: vertical;
|
|
22762
|
+
}
|
|
22763
|
+
|
|
22764
|
+
.form-card {
|
|
22765
|
+
border: 1px solid var(--border);
|
|
22766
|
+
border-radius: var(--radius);
|
|
22767
|
+
padding: var(--gap);
|
|
22768
|
+
margin-bottom: var(--gap);
|
|
22769
|
+
background: var(--surface);
|
|
22770
|
+
}
|
|
22771
|
+
|
|
22772
|
+
.field {
|
|
22773
|
+
margin-bottom: 10px;
|
|
22774
|
+
}
|
|
22775
|
+
.field label {
|
|
22776
|
+
display: block;
|
|
22777
|
+
font-size: 0.75rem;
|
|
22778
|
+
color: var(--text-muted);
|
|
22779
|
+
margin-bottom: 4px;
|
|
22780
|
+
}
|
|
22781
|
+
|
|
22782
|
+
.field input {
|
|
22783
|
+
width: 100%;
|
|
22784
|
+
border: 1px solid var(--border);
|
|
22785
|
+
border-radius: var(--radius);
|
|
22786
|
+
padding: 6px 10px;
|
|
22787
|
+
background: var(--surface);
|
|
22788
|
+
color: var(--text);
|
|
22789
|
+
font-size: 0.875rem;
|
|
22790
|
+
}
|
|
22791
|
+
|
|
22792
|
+
.form-actions {
|
|
22793
|
+
display: flex;
|
|
22794
|
+
gap: 6px;
|
|
22795
|
+
}
|
|
22796
|
+
.load-more {
|
|
22797
|
+
display: block;
|
|
22798
|
+
width: 100%;
|
|
22799
|
+
text-align: center;
|
|
22800
|
+
padding: 10px;
|
|
22801
|
+
margin-top: 8px;
|
|
22802
|
+
text-decoration: none;
|
|
22803
|
+
}
|
|
22804
|
+
.empty {
|
|
22805
|
+
text-align: center;
|
|
22806
|
+
color: var(--text-muted);
|
|
22807
|
+
padding: 40px 0;
|
|
22808
|
+
}
|
|
22809
|
+
|
|
22810
|
+
.ws-group-header {
|
|
22811
|
+
font-size: 0.75rem;
|
|
22812
|
+
color: var(--text-muted);
|
|
22813
|
+
margin: var(--gap) 0 8px;
|
|
22814
|
+
padding-bottom: 4px;
|
|
22815
|
+
border-bottom: 1px solid var(--border);
|
|
22816
|
+
}
|
|
22817
|
+
|
|
22818
|
+
.pagination {
|
|
22819
|
+
display: flex;
|
|
22820
|
+
justify-content: space-between;
|
|
22821
|
+
align-items: center;
|
|
22822
|
+
margin-top: var(--gap);
|
|
22823
|
+
padding-top: var(--gap);
|
|
22824
|
+
border-top: 1px solid var(--border);
|
|
22825
|
+
}
|
|
22826
|
+
|
|
22827
|
+
.page-info {
|
|
22828
|
+
font-size: 0.8125rem;
|
|
22829
|
+
color: var(--text-muted);
|
|
22830
|
+
}
|
|
22831
|
+
|
|
22832
|
+
@media (max-width: 640px) {
|
|
22833
|
+
.layout {
|
|
22834
|
+
flex-direction: column;
|
|
22835
|
+
}
|
|
22836
|
+
|
|
22837
|
+
.sidebar {
|
|
22838
|
+
width: 100%;
|
|
22839
|
+
border-right: none;
|
|
22840
|
+
border-bottom: 1px solid var(--border);
|
|
22841
|
+
padding: 12px 0;
|
|
22842
|
+
overflow-x: auto;
|
|
22843
|
+
overflow-y: hidden;
|
|
22844
|
+
white-space: nowrap;
|
|
22845
|
+
display: flex;
|
|
22846
|
+
flex-wrap: wrap;
|
|
22847
|
+
gap: 4px;
|
|
22848
|
+
}
|
|
22849
|
+
|
|
22850
|
+
.sidebar h2 {
|
|
22851
|
+
width: 100%;
|
|
22852
|
+
margin-bottom: 4px;
|
|
22853
|
+
}
|
|
22854
|
+
|
|
22855
|
+
.sidebar-item {
|
|
22856
|
+
width: auto;
|
|
22857
|
+
display: inline-block;
|
|
22858
|
+
padding: 4px 10px;
|
|
22859
|
+
border-radius: var(--radius);
|
|
22860
|
+
border: 1px solid var(--border);
|
|
22861
|
+
direction: ltr;
|
|
22862
|
+
}
|
|
22863
|
+
}
|
|
22864
|
+
`;
|
|
22865
|
+
|
|
22866
|
+
// src/ui/constants.ts
|
|
22867
|
+
var NO_WORKSPACE_FILTER = "__none__";
|
|
22868
|
+
|
|
22869
|
+
// node_modules/hono/dist/jsx/constants.js
|
|
22870
|
+
var DOM_RENDERER = /* @__PURE__ */ Symbol("RENDERER");
|
|
22871
|
+
var DOM_ERROR_HANDLER = /* @__PURE__ */ Symbol("ERROR_HANDLER");
|
|
22872
|
+
var DOM_INTERNAL_TAG = /* @__PURE__ */ Symbol("INTERNAL");
|
|
22873
|
+
var PERMALINK = /* @__PURE__ */ Symbol("PERMALINK");
|
|
22874
|
+
|
|
22875
|
+
// node_modules/hono/dist/jsx/dom/utils.js
|
|
22876
|
+
var setInternalTagFlag = (fn) => {
|
|
22877
|
+
fn[DOM_INTERNAL_TAG] = true;
|
|
22878
|
+
return fn;
|
|
22879
|
+
};
|
|
22880
|
+
|
|
22881
|
+
// node_modules/hono/dist/jsx/dom/context.js
|
|
22882
|
+
var createContextProviderFunction = (values) => ({ value, children }) => {
|
|
22883
|
+
if (!children) {
|
|
22884
|
+
return;
|
|
22885
|
+
}
|
|
22886
|
+
const props = {
|
|
22887
|
+
children: [
|
|
22888
|
+
{
|
|
22889
|
+
tag: setInternalTagFlag(() => {
|
|
22890
|
+
values.push(value);
|
|
22891
|
+
}),
|
|
22892
|
+
props: {}
|
|
22893
|
+
}
|
|
22894
|
+
]
|
|
22895
|
+
};
|
|
22896
|
+
if (Array.isArray(children)) {
|
|
22897
|
+
props.children.push(...children.flat());
|
|
22898
|
+
} else {
|
|
22899
|
+
props.children.push(children);
|
|
22900
|
+
}
|
|
22901
|
+
props.children.push({
|
|
22902
|
+
tag: setInternalTagFlag(() => {
|
|
22903
|
+
values.pop();
|
|
22904
|
+
}),
|
|
22905
|
+
props: {}
|
|
22906
|
+
});
|
|
22907
|
+
const res = { tag: "", props, type: "" };
|
|
22908
|
+
res[DOM_ERROR_HANDLER] = (err) => {
|
|
22909
|
+
values.pop();
|
|
22910
|
+
throw err;
|
|
22911
|
+
};
|
|
22912
|
+
return res;
|
|
22913
|
+
};
|
|
22914
|
+
|
|
22915
|
+
// node_modules/hono/dist/jsx/context.js
|
|
22916
|
+
var globalContexts = [];
|
|
22917
|
+
var createContext = (defaultValue) => {
|
|
22918
|
+
const values = [defaultValue];
|
|
22919
|
+
const context = (props) => {
|
|
22920
|
+
values.push(props.value);
|
|
22921
|
+
let string4;
|
|
22922
|
+
try {
|
|
22923
|
+
string4 = props.children ? (Array.isArray(props.children) ? new JSXFragmentNode("", {}, props.children) : props.children).toString() : "";
|
|
22924
|
+
} catch (e) {
|
|
22925
|
+
values.pop();
|
|
22926
|
+
throw e;
|
|
22927
|
+
}
|
|
22928
|
+
if (string4 instanceof Promise) {
|
|
22929
|
+
return string4.finally(() => values.pop()).then((resString) => raw(resString, resString.callbacks));
|
|
22930
|
+
} else {
|
|
22931
|
+
values.pop();
|
|
22932
|
+
return raw(string4);
|
|
22933
|
+
}
|
|
22934
|
+
};
|
|
22935
|
+
context.values = values;
|
|
22936
|
+
context.Provider = context;
|
|
22937
|
+
context[DOM_RENDERER] = createContextProviderFunction(values);
|
|
22938
|
+
globalContexts.push(context);
|
|
22939
|
+
return context;
|
|
22940
|
+
};
|
|
22941
|
+
var useContext = (context) => {
|
|
22942
|
+
return context.values.at(-1);
|
|
22943
|
+
};
|
|
22944
|
+
|
|
22945
|
+
// node_modules/hono/dist/jsx/intrinsic-element/common.js
|
|
22946
|
+
var deDupeKeyMap = {
|
|
22947
|
+
title: [],
|
|
22948
|
+
script: ["src"],
|
|
22949
|
+
style: ["data-href"],
|
|
22950
|
+
link: ["href"],
|
|
22951
|
+
meta: ["name", "httpEquiv", "charset", "itemProp"]
|
|
22952
|
+
};
|
|
22953
|
+
var domRenderers = {};
|
|
22954
|
+
var dataPrecedenceAttr = "data-precedence";
|
|
22955
|
+
var isStylesheetLinkWithPrecedence = (props) => props.rel === "stylesheet" && ("precedence" in props);
|
|
22956
|
+
var shouldDeDupeByKey = (tagName, supportSort) => {
|
|
22957
|
+
if (tagName === "link") {
|
|
22958
|
+
return supportSort;
|
|
22959
|
+
}
|
|
22960
|
+
return deDupeKeyMap[tagName].length > 0;
|
|
22961
|
+
};
|
|
22962
|
+
|
|
22963
|
+
// node_modules/hono/dist/jsx/intrinsic-element/components.js
|
|
22964
|
+
var exports_components = {};
|
|
22965
|
+
__export(exports_components, {
|
|
22966
|
+
title: () => title,
|
|
22967
|
+
style: () => style,
|
|
22968
|
+
script: () => script,
|
|
22969
|
+
meta: () => meta2,
|
|
22970
|
+
link: () => link,
|
|
22971
|
+
input: () => input,
|
|
22972
|
+
form: () => form,
|
|
22973
|
+
button: () => button
|
|
22974
|
+
});
|
|
22975
|
+
|
|
22976
|
+
// node_modules/hono/dist/jsx/children.js
|
|
22977
|
+
var toArray = (children) => Array.isArray(children) ? children : [children];
|
|
22978
|
+
|
|
22979
|
+
// node_modules/hono/dist/jsx/intrinsic-element/components.js
|
|
22980
|
+
var metaTagMap = /* @__PURE__ */ new WeakMap;
|
|
22981
|
+
var insertIntoHead = (tagName, tag, props, precedence) => ({ buffer, context }) => {
|
|
22982
|
+
if (!buffer) {
|
|
22983
|
+
return;
|
|
22984
|
+
}
|
|
22985
|
+
const map2 = metaTagMap.get(context) || {};
|
|
22986
|
+
metaTagMap.set(context, map2);
|
|
22987
|
+
const tags = map2[tagName] ||= [];
|
|
22988
|
+
let duped = false;
|
|
22989
|
+
const deDupeKeys = deDupeKeyMap[tagName];
|
|
22990
|
+
const deDupeByKey = shouldDeDupeByKey(tagName, precedence !== undefined);
|
|
22991
|
+
if (deDupeByKey) {
|
|
22992
|
+
LOOP:
|
|
22993
|
+
for (const [, tagProps] of tags) {
|
|
22994
|
+
if (tagName === "link" && !(tagProps.rel === "stylesheet" && tagProps[dataPrecedenceAttr] !== undefined)) {
|
|
22995
|
+
continue;
|
|
22996
|
+
}
|
|
22997
|
+
for (const key of deDupeKeys) {
|
|
22998
|
+
if ((tagProps?.[key] ?? null) === props?.[key]) {
|
|
22999
|
+
duped = true;
|
|
23000
|
+
break LOOP;
|
|
23001
|
+
}
|
|
23002
|
+
}
|
|
23003
|
+
}
|
|
23004
|
+
}
|
|
23005
|
+
if (duped) {
|
|
23006
|
+
buffer[0] = buffer[0].replaceAll(tag, "");
|
|
23007
|
+
} else if (deDupeByKey || tagName === "link") {
|
|
23008
|
+
tags.push([tag, props, precedence]);
|
|
23009
|
+
} else {
|
|
23010
|
+
tags.unshift([tag, props, precedence]);
|
|
23011
|
+
}
|
|
23012
|
+
if (buffer[0].indexOf("</head>") !== -1) {
|
|
23013
|
+
let insertTags;
|
|
23014
|
+
if (tagName === "link" || precedence !== undefined) {
|
|
23015
|
+
const precedences = [];
|
|
23016
|
+
insertTags = tags.map(([tag2, , tagPrecedence], index) => {
|
|
23017
|
+
if (tagPrecedence === undefined) {
|
|
23018
|
+
return [tag2, Number.MAX_SAFE_INTEGER, index];
|
|
23019
|
+
}
|
|
23020
|
+
let order = precedences.indexOf(tagPrecedence);
|
|
23021
|
+
if (order === -1) {
|
|
23022
|
+
precedences.push(tagPrecedence);
|
|
23023
|
+
order = precedences.length - 1;
|
|
23024
|
+
}
|
|
23025
|
+
return [tag2, order, index];
|
|
23026
|
+
}).sort((a, b) => a[1] - b[1] || a[2] - b[2]).map(([tag2]) => tag2);
|
|
23027
|
+
} else {
|
|
23028
|
+
insertTags = tags.map(([tag2]) => tag2);
|
|
23029
|
+
}
|
|
23030
|
+
insertTags.forEach((tag2) => {
|
|
23031
|
+
buffer[0] = buffer[0].replaceAll(tag2, "");
|
|
23032
|
+
});
|
|
23033
|
+
buffer[0] = buffer[0].replace(/(?=<\/head>)/, insertTags.join(""));
|
|
23034
|
+
}
|
|
23035
|
+
};
|
|
23036
|
+
var returnWithoutSpecialBehavior = (tag, children, props) => raw(new JSXNode(tag, props, toArray(children ?? [])).toString());
|
|
23037
|
+
var documentMetadataTag = (tag, children, props, sort) => {
|
|
23038
|
+
if ("itemProp" in props) {
|
|
23039
|
+
return returnWithoutSpecialBehavior(tag, children, props);
|
|
23040
|
+
}
|
|
23041
|
+
let { precedence, blocking, ...restProps } = props;
|
|
23042
|
+
precedence = sort ? precedence ?? "" : undefined;
|
|
23043
|
+
if (sort) {
|
|
23044
|
+
restProps[dataPrecedenceAttr] = precedence;
|
|
23045
|
+
}
|
|
23046
|
+
const string4 = new JSXNode(tag, restProps, toArray(children || [])).toString();
|
|
23047
|
+
if (string4 instanceof Promise) {
|
|
23048
|
+
return string4.then((resString) => raw(string4, [
|
|
23049
|
+
...resString.callbacks || [],
|
|
23050
|
+
insertIntoHead(tag, resString, restProps, precedence)
|
|
23051
|
+
]));
|
|
23052
|
+
} else {
|
|
23053
|
+
return raw(string4, [insertIntoHead(tag, string4, restProps, precedence)]);
|
|
23054
|
+
}
|
|
23055
|
+
};
|
|
23056
|
+
var title = ({ children, ...props }) => {
|
|
23057
|
+
const nameSpaceContext = getNameSpaceContext();
|
|
23058
|
+
if (nameSpaceContext) {
|
|
23059
|
+
const context = useContext(nameSpaceContext);
|
|
23060
|
+
if (context === "svg" || context === "head") {
|
|
23061
|
+
return new JSXNode("title", props, toArray(children ?? []));
|
|
23062
|
+
}
|
|
23063
|
+
}
|
|
23064
|
+
return documentMetadataTag("title", children, props, false);
|
|
23065
|
+
};
|
|
23066
|
+
var script = ({
|
|
23067
|
+
children,
|
|
23068
|
+
...props
|
|
23069
|
+
}) => {
|
|
23070
|
+
const nameSpaceContext = getNameSpaceContext();
|
|
23071
|
+
if (["src", "async"].some((k) => !props[k]) || nameSpaceContext && useContext(nameSpaceContext) === "head") {
|
|
23072
|
+
return returnWithoutSpecialBehavior("script", children, props);
|
|
23073
|
+
}
|
|
23074
|
+
return documentMetadataTag("script", children, props, false);
|
|
23075
|
+
};
|
|
23076
|
+
var style = ({
|
|
23077
|
+
children,
|
|
23078
|
+
...props
|
|
23079
|
+
}) => {
|
|
23080
|
+
if (!["href", "precedence"].every((k) => (k in props))) {
|
|
23081
|
+
return returnWithoutSpecialBehavior("style", children, props);
|
|
23082
|
+
}
|
|
23083
|
+
props["data-href"] = props.href;
|
|
23084
|
+
delete props.href;
|
|
23085
|
+
return documentMetadataTag("style", children, props, true);
|
|
23086
|
+
};
|
|
23087
|
+
var link = ({ children, ...props }) => {
|
|
23088
|
+
if (["onLoad", "onError"].some((k) => (k in props)) || props.rel === "stylesheet" && (!("precedence" in props) || ("disabled" in props))) {
|
|
23089
|
+
return returnWithoutSpecialBehavior("link", children, props);
|
|
23090
|
+
}
|
|
23091
|
+
return documentMetadataTag("link", children, props, isStylesheetLinkWithPrecedence(props));
|
|
23092
|
+
};
|
|
23093
|
+
var meta2 = ({ children, ...props }) => {
|
|
23094
|
+
const nameSpaceContext = getNameSpaceContext();
|
|
23095
|
+
if (nameSpaceContext && useContext(nameSpaceContext) === "head") {
|
|
23096
|
+
return returnWithoutSpecialBehavior("meta", children, props);
|
|
23097
|
+
}
|
|
23098
|
+
return documentMetadataTag("meta", children, props, false);
|
|
23099
|
+
};
|
|
23100
|
+
var newJSXNode = (tag, { children, ...props }) => new JSXNode(tag, props, toArray(children ?? []));
|
|
23101
|
+
var form = (props) => {
|
|
23102
|
+
if (typeof props.action === "function") {
|
|
23103
|
+
props.action = PERMALINK in props.action ? props.action[PERMALINK] : undefined;
|
|
23104
|
+
}
|
|
23105
|
+
return newJSXNode("form", props);
|
|
23106
|
+
};
|
|
23107
|
+
var formActionableElement = (tag, props) => {
|
|
23108
|
+
if (typeof props.formAction === "function") {
|
|
23109
|
+
props.formAction = PERMALINK in props.formAction ? props.formAction[PERMALINK] : undefined;
|
|
23110
|
+
}
|
|
23111
|
+
return newJSXNode(tag, props);
|
|
23112
|
+
};
|
|
23113
|
+
var input = (props) => formActionableElement("input", props);
|
|
23114
|
+
var button = (props) => formActionableElement("button", props);
|
|
23115
|
+
|
|
23116
|
+
// node_modules/hono/dist/jsx/utils.js
|
|
23117
|
+
var normalizeElementKeyMap = /* @__PURE__ */ new Map([
|
|
23118
|
+
["className", "class"],
|
|
23119
|
+
["htmlFor", "for"],
|
|
23120
|
+
["crossOrigin", "crossorigin"],
|
|
23121
|
+
["httpEquiv", "http-equiv"],
|
|
23122
|
+
["itemProp", "itemprop"],
|
|
23123
|
+
["fetchPriority", "fetchpriority"],
|
|
23124
|
+
["noModule", "nomodule"],
|
|
23125
|
+
["formAction", "formaction"]
|
|
23126
|
+
]);
|
|
23127
|
+
var normalizeIntrinsicElementKey = (key) => normalizeElementKeyMap.get(key) || key;
|
|
23128
|
+
var styleObjectForEach = (style2, fn) => {
|
|
23129
|
+
for (const [k, v] of Object.entries(style2)) {
|
|
23130
|
+
const key = k[0] === "-" || !/[A-Z]/.test(k) ? k : k.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`);
|
|
23131
|
+
fn(key, v == null ? null : typeof v === "number" ? !key.match(/^(?:a|border-im|column(?:-c|s)|flex(?:$|-[^b])|grid-(?:ar|[^a])|font-w|li|or|sca|st|ta|wido|z)|ty$/) ? `${v}px` : `${v}` : v);
|
|
23132
|
+
}
|
|
23133
|
+
};
|
|
23134
|
+
|
|
23135
|
+
// node_modules/hono/dist/jsx/base.js
|
|
23136
|
+
var nameSpaceContext = undefined;
|
|
23137
|
+
var getNameSpaceContext = () => nameSpaceContext;
|
|
23138
|
+
var toSVGAttributeName = (key) => /[A-Z]/.test(key) && key.match(/^(?:al|basel|clip(?:Path|Rule)$|co|do|fill|fl|fo|gl|let|lig|i|marker[EMS]|o|pai|pointe|sh|st[or]|text[^L]|tr|u|ve|w)/) ? key.replace(/([A-Z])/g, "-$1").toLowerCase() : key;
|
|
23139
|
+
var emptyTags = [
|
|
23140
|
+
"area",
|
|
23141
|
+
"base",
|
|
23142
|
+
"br",
|
|
23143
|
+
"col",
|
|
23144
|
+
"embed",
|
|
23145
|
+
"hr",
|
|
23146
|
+
"img",
|
|
23147
|
+
"input",
|
|
23148
|
+
"keygen",
|
|
23149
|
+
"link",
|
|
23150
|
+
"meta",
|
|
23151
|
+
"param",
|
|
23152
|
+
"source",
|
|
23153
|
+
"track",
|
|
23154
|
+
"wbr"
|
|
23155
|
+
];
|
|
23156
|
+
var booleanAttributes = [
|
|
23157
|
+
"allowfullscreen",
|
|
23158
|
+
"async",
|
|
23159
|
+
"autofocus",
|
|
23160
|
+
"autoplay",
|
|
23161
|
+
"checked",
|
|
23162
|
+
"controls",
|
|
23163
|
+
"default",
|
|
23164
|
+
"defer",
|
|
23165
|
+
"disabled",
|
|
23166
|
+
"download",
|
|
23167
|
+
"formnovalidate",
|
|
23168
|
+
"hidden",
|
|
23169
|
+
"inert",
|
|
23170
|
+
"ismap",
|
|
23171
|
+
"itemscope",
|
|
23172
|
+
"loop",
|
|
23173
|
+
"multiple",
|
|
23174
|
+
"muted",
|
|
23175
|
+
"nomodule",
|
|
23176
|
+
"novalidate",
|
|
23177
|
+
"open",
|
|
23178
|
+
"playsinline",
|
|
23179
|
+
"readonly",
|
|
23180
|
+
"required",
|
|
23181
|
+
"reversed",
|
|
23182
|
+
"selected"
|
|
23183
|
+
];
|
|
23184
|
+
var childrenToStringToBuffer = (children, buffer) => {
|
|
23185
|
+
for (let i = 0, len = children.length;i < len; i++) {
|
|
23186
|
+
const child = children[i];
|
|
23187
|
+
if (typeof child === "string") {
|
|
23188
|
+
escapeToBuffer(child, buffer);
|
|
23189
|
+
} else if (typeof child === "boolean" || child === null || child === undefined) {
|
|
23190
|
+
continue;
|
|
23191
|
+
} else if (child instanceof JSXNode) {
|
|
23192
|
+
child.toStringToBuffer(buffer);
|
|
23193
|
+
} else if (typeof child === "number" || child.isEscaped) {
|
|
23194
|
+
buffer[0] += child;
|
|
23195
|
+
} else if (child instanceof Promise) {
|
|
23196
|
+
buffer.unshift("", child);
|
|
23197
|
+
} else {
|
|
23198
|
+
childrenToStringToBuffer(child, buffer);
|
|
23199
|
+
}
|
|
23200
|
+
}
|
|
23201
|
+
};
|
|
23202
|
+
var JSXNode = class {
|
|
23203
|
+
tag;
|
|
23204
|
+
props;
|
|
23205
|
+
key;
|
|
23206
|
+
children;
|
|
23207
|
+
isEscaped = true;
|
|
23208
|
+
localContexts;
|
|
23209
|
+
constructor(tag, props, children) {
|
|
23210
|
+
this.tag = tag;
|
|
23211
|
+
this.props = props;
|
|
23212
|
+
this.children = children;
|
|
23213
|
+
}
|
|
23214
|
+
get type() {
|
|
23215
|
+
return this.tag;
|
|
23216
|
+
}
|
|
23217
|
+
get ref() {
|
|
23218
|
+
return this.props.ref || null;
|
|
23219
|
+
}
|
|
23220
|
+
toString() {
|
|
23221
|
+
const buffer = [""];
|
|
23222
|
+
this.localContexts?.forEach(([context, value]) => {
|
|
23223
|
+
context.values.push(value);
|
|
23224
|
+
});
|
|
23225
|
+
try {
|
|
23226
|
+
this.toStringToBuffer(buffer);
|
|
23227
|
+
} finally {
|
|
23228
|
+
this.localContexts?.forEach(([context]) => {
|
|
23229
|
+
context.values.pop();
|
|
23230
|
+
});
|
|
23231
|
+
}
|
|
23232
|
+
return buffer.length === 1 ? "callbacks" in buffer ? resolveCallbackSync(raw(buffer[0], buffer.callbacks)).toString() : buffer[0] : stringBufferToString(buffer, buffer.callbacks);
|
|
23233
|
+
}
|
|
23234
|
+
toStringToBuffer(buffer) {
|
|
23235
|
+
const tag = this.tag;
|
|
23236
|
+
const props = this.props;
|
|
23237
|
+
let { children } = this;
|
|
23238
|
+
buffer[0] += `<${tag}`;
|
|
23239
|
+
const normalizeKey = nameSpaceContext && useContext(nameSpaceContext) === "svg" ? (key) => toSVGAttributeName(normalizeIntrinsicElementKey(key)) : (key) => normalizeIntrinsicElementKey(key);
|
|
23240
|
+
for (let [key, v] of Object.entries(props)) {
|
|
23241
|
+
key = normalizeKey(key);
|
|
23242
|
+
if (key === "children") {} else if (key === "style" && typeof v === "object") {
|
|
23243
|
+
let styleStr = "";
|
|
23244
|
+
styleObjectForEach(v, (property, value) => {
|
|
23245
|
+
if (value != null) {
|
|
23246
|
+
styleStr += `${styleStr ? ";" : ""}${property}:${value}`;
|
|
23247
|
+
}
|
|
23248
|
+
});
|
|
23249
|
+
buffer[0] += ' style="';
|
|
23250
|
+
escapeToBuffer(styleStr, buffer);
|
|
23251
|
+
buffer[0] += '"';
|
|
23252
|
+
} else if (typeof v === "string") {
|
|
23253
|
+
buffer[0] += ` ${key}="`;
|
|
23254
|
+
escapeToBuffer(v, buffer);
|
|
23255
|
+
buffer[0] += '"';
|
|
23256
|
+
} else if (v === null || v === undefined) {} else if (typeof v === "number" || v.isEscaped) {
|
|
23257
|
+
buffer[0] += ` ${key}="${v}"`;
|
|
23258
|
+
} else if (typeof v === "boolean" && booleanAttributes.includes(key)) {
|
|
23259
|
+
if (v) {
|
|
23260
|
+
buffer[0] += ` ${key}=""`;
|
|
23261
|
+
}
|
|
23262
|
+
} else if (key === "dangerouslySetInnerHTML") {
|
|
23263
|
+
if (children.length > 0) {
|
|
23264
|
+
throw new Error("Can only set one of `children` or `props.dangerouslySetInnerHTML`.");
|
|
23265
|
+
}
|
|
23266
|
+
children = [raw(v.__html)];
|
|
23267
|
+
} else if (v instanceof Promise) {
|
|
23268
|
+
buffer[0] += ` ${key}="`;
|
|
23269
|
+
buffer.unshift('"', v);
|
|
23270
|
+
} else if (typeof v === "function") {
|
|
23271
|
+
if (!key.startsWith("on") && key !== "ref") {
|
|
23272
|
+
throw new Error(`Invalid prop '${key}' of type 'function' supplied to '${tag}'.`);
|
|
23273
|
+
}
|
|
23274
|
+
} else {
|
|
23275
|
+
buffer[0] += ` ${key}="`;
|
|
23276
|
+
escapeToBuffer(v.toString(), buffer);
|
|
23277
|
+
buffer[0] += '"';
|
|
23278
|
+
}
|
|
23279
|
+
}
|
|
23280
|
+
if (emptyTags.includes(tag) && children.length === 0) {
|
|
23281
|
+
buffer[0] += "/>";
|
|
23282
|
+
return;
|
|
23283
|
+
}
|
|
23284
|
+
buffer[0] += ">";
|
|
23285
|
+
childrenToStringToBuffer(children, buffer);
|
|
23286
|
+
buffer[0] += `</${tag}>`;
|
|
23287
|
+
}
|
|
23288
|
+
};
|
|
23289
|
+
var JSXFunctionNode = class extends JSXNode {
|
|
23290
|
+
toStringToBuffer(buffer) {
|
|
23291
|
+
const { children } = this;
|
|
23292
|
+
const props = { ...this.props };
|
|
23293
|
+
if (children.length) {
|
|
23294
|
+
props.children = children.length === 1 ? children[0] : children;
|
|
23295
|
+
}
|
|
23296
|
+
const res = this.tag.call(null, props);
|
|
23297
|
+
if (typeof res === "boolean" || res == null) {
|
|
23298
|
+
return;
|
|
23299
|
+
} else if (res instanceof Promise) {
|
|
23300
|
+
if (globalContexts.length === 0) {
|
|
23301
|
+
buffer.unshift("", res);
|
|
23302
|
+
} else {
|
|
23303
|
+
const currentContexts = globalContexts.map((c) => [c, c.values.at(-1)]);
|
|
23304
|
+
buffer.unshift("", res.then((childRes) => {
|
|
23305
|
+
if (childRes instanceof JSXNode) {
|
|
23306
|
+
childRes.localContexts = currentContexts;
|
|
23307
|
+
}
|
|
23308
|
+
return childRes;
|
|
23309
|
+
}));
|
|
23310
|
+
}
|
|
23311
|
+
} else if (res instanceof JSXNode) {
|
|
23312
|
+
res.toStringToBuffer(buffer);
|
|
23313
|
+
} else if (typeof res === "number" || res.isEscaped) {
|
|
23314
|
+
buffer[0] += res;
|
|
23315
|
+
if (res.callbacks) {
|
|
23316
|
+
buffer.callbacks ||= [];
|
|
23317
|
+
buffer.callbacks.push(...res.callbacks);
|
|
23318
|
+
}
|
|
23319
|
+
} else {
|
|
23320
|
+
escapeToBuffer(res, buffer);
|
|
23321
|
+
}
|
|
23322
|
+
}
|
|
23323
|
+
};
|
|
23324
|
+
var JSXFragmentNode = class extends JSXNode {
|
|
23325
|
+
toStringToBuffer(buffer) {
|
|
23326
|
+
childrenToStringToBuffer(this.children, buffer);
|
|
23327
|
+
}
|
|
23328
|
+
};
|
|
23329
|
+
var initDomRenderer = false;
|
|
23330
|
+
var jsxFn = (tag, props, children) => {
|
|
23331
|
+
if (!initDomRenderer) {
|
|
23332
|
+
for (const k in domRenderers) {
|
|
23333
|
+
exports_components[k][DOM_RENDERER] = domRenderers[k];
|
|
23334
|
+
}
|
|
23335
|
+
initDomRenderer = true;
|
|
23336
|
+
}
|
|
23337
|
+
if (typeof tag === "function") {
|
|
23338
|
+
return new JSXFunctionNode(tag, props, children);
|
|
23339
|
+
} else if (exports_components[tag]) {
|
|
23340
|
+
return new JSXFunctionNode(exports_components[tag], props, children);
|
|
23341
|
+
} else if (tag === "svg" || tag === "head") {
|
|
23342
|
+
nameSpaceContext ||= createContext("");
|
|
23343
|
+
return new JSXNode(tag, props, [
|
|
23344
|
+
new JSXFunctionNode(nameSpaceContext, {
|
|
23345
|
+
value: tag
|
|
23346
|
+
}, children)
|
|
23347
|
+
]);
|
|
23348
|
+
} else {
|
|
23349
|
+
return new JSXNode(tag, props, children);
|
|
23350
|
+
}
|
|
23351
|
+
};
|
|
23352
|
+
var Fragment = ({
|
|
23353
|
+
children
|
|
23354
|
+
}) => {
|
|
23355
|
+
return new JSXFragmentNode("", {
|
|
23356
|
+
children
|
|
23357
|
+
}, Array.isArray(children) ? children : children ? [children] : []);
|
|
23358
|
+
};
|
|
23359
|
+
|
|
23360
|
+
// node_modules/hono/dist/jsx/jsx-dev-runtime.js
|
|
23361
|
+
function jsxDEV(tag, props, key) {
|
|
23362
|
+
let node;
|
|
23363
|
+
if (!props || !("children" in props)) {
|
|
23364
|
+
node = jsxFn(tag, props, []);
|
|
23365
|
+
} else {
|
|
23366
|
+
const children = props.children;
|
|
23367
|
+
node = Array.isArray(children) ? jsxFn(tag, props, children) : jsxFn(tag, props, [children]);
|
|
23368
|
+
}
|
|
23369
|
+
node.key = key;
|
|
23370
|
+
return node;
|
|
23371
|
+
}
|
|
23372
|
+
|
|
23373
|
+
// src/ui/components/create-form.tsx
|
|
23374
|
+
var CreateForm = ({ workspace }) => /* @__PURE__ */ jsxDEV("div", {
|
|
23375
|
+
class: "form-card",
|
|
23376
|
+
children: /* @__PURE__ */ jsxDEV("form", {
|
|
23377
|
+
method: "post",
|
|
23378
|
+
action: "/memories",
|
|
23379
|
+
children: [
|
|
23380
|
+
/* @__PURE__ */ jsxDEV("div", {
|
|
23381
|
+
class: "field",
|
|
23382
|
+
children: [
|
|
23383
|
+
/* @__PURE__ */ jsxDEV("label", {
|
|
23384
|
+
for: "new-content",
|
|
23385
|
+
children: "Content"
|
|
23386
|
+
}, undefined, false, undefined, this),
|
|
23387
|
+
/* @__PURE__ */ jsxDEV("textarea", {
|
|
23388
|
+
id: "new-content",
|
|
23389
|
+
name: "content",
|
|
23390
|
+
placeholder: "Fact, preference, decision...",
|
|
23391
|
+
required: true
|
|
23392
|
+
}, undefined, false, undefined, this)
|
|
23393
|
+
]
|
|
23394
|
+
}, undefined, true, undefined, this),
|
|
23395
|
+
/* @__PURE__ */ jsxDEV("div", {
|
|
23396
|
+
class: "field",
|
|
23397
|
+
children: [
|
|
23398
|
+
/* @__PURE__ */ jsxDEV("label", {
|
|
23399
|
+
for: "new-workspace",
|
|
23400
|
+
children: "Workspace (optional)"
|
|
23401
|
+
}, undefined, false, undefined, this),
|
|
23402
|
+
/* @__PURE__ */ jsxDEV("input", {
|
|
23403
|
+
id: "new-workspace",
|
|
23404
|
+
name: "workspace",
|
|
23405
|
+
type: "text",
|
|
23406
|
+
placeholder: "/path/to/project",
|
|
23407
|
+
value: workspace && workspace !== NO_WORKSPACE_FILTER ? workspace : ""
|
|
23408
|
+
}, undefined, false, undefined, this)
|
|
23409
|
+
]
|
|
23410
|
+
}, undefined, true, undefined, this),
|
|
23411
|
+
/* @__PURE__ */ jsxDEV("div", {
|
|
23412
|
+
class: "form-actions",
|
|
23413
|
+
children: /* @__PURE__ */ jsxDEV("button", {
|
|
23414
|
+
type: "submit",
|
|
23415
|
+
class: "primary",
|
|
23416
|
+
children: "Save"
|
|
23417
|
+
}, undefined, false, undefined, this)
|
|
23418
|
+
}, undefined, false, undefined, this)
|
|
23419
|
+
]
|
|
23420
|
+
}, undefined, true, undefined, this)
|
|
23421
|
+
}, undefined, false, undefined, this);
|
|
23422
|
+
|
|
23423
|
+
// src/ui/components/memory-card.tsx
|
|
23424
|
+
var MemoryCard = ({ memory, editing, showWorkspace, returnUrl }) => /* @__PURE__ */ jsxDEV("div", {
|
|
23425
|
+
class: "card",
|
|
23426
|
+
children: [
|
|
23427
|
+
/* @__PURE__ */ jsxDEV("div", {
|
|
23428
|
+
class: "card-header",
|
|
23429
|
+
children: /* @__PURE__ */ jsxDEV("div", {
|
|
23430
|
+
class: "card-meta",
|
|
23431
|
+
children: [
|
|
23432
|
+
showWorkspace && memory.workspace && /* @__PURE__ */ jsxDEV(Fragment, {
|
|
23433
|
+
children: [
|
|
23434
|
+
/* @__PURE__ */ jsxDEV("span", {
|
|
23435
|
+
class: "badge",
|
|
23436
|
+
children: memory.workspace
|
|
23437
|
+
}, undefined, false, undefined, this),
|
|
23438
|
+
" "
|
|
23439
|
+
]
|
|
23440
|
+
}, undefined, true, undefined, this),
|
|
23441
|
+
memory.updatedAt.toLocaleString()
|
|
23442
|
+
]
|
|
23443
|
+
}, undefined, true, undefined, this)
|
|
23444
|
+
}, undefined, false, undefined, this),
|
|
23445
|
+
editing ? /* @__PURE__ */ jsxDEV("form", {
|
|
23446
|
+
method: "post",
|
|
23447
|
+
action: `/memories/${encodeURIComponent(memory.id)}/update`,
|
|
23448
|
+
children: [
|
|
23449
|
+
/* @__PURE__ */ jsxDEV("input", {
|
|
23450
|
+
type: "hidden",
|
|
23451
|
+
name: "returnUrl",
|
|
23452
|
+
value: returnUrl
|
|
23453
|
+
}, undefined, false, undefined, this),
|
|
23454
|
+
/* @__PURE__ */ jsxDEV("textarea", {
|
|
23455
|
+
name: "content",
|
|
23456
|
+
required: true,
|
|
23457
|
+
children: memory.content
|
|
23458
|
+
}, undefined, false, undefined, this),
|
|
23459
|
+
/* @__PURE__ */ jsxDEV("div", {
|
|
23460
|
+
class: "card-actions",
|
|
23461
|
+
children: [
|
|
23462
|
+
/* @__PURE__ */ jsxDEV("button", {
|
|
23463
|
+
type: "submit",
|
|
23464
|
+
class: "primary",
|
|
23465
|
+
children: "Save"
|
|
23466
|
+
}, undefined, false, undefined, this),
|
|
23467
|
+
/* @__PURE__ */ jsxDEV("a", {
|
|
23468
|
+
href: returnUrl,
|
|
23469
|
+
class: "btn",
|
|
23470
|
+
children: "Cancel"
|
|
23471
|
+
}, undefined, false, undefined, this)
|
|
23472
|
+
]
|
|
23473
|
+
}, undefined, true, undefined, this)
|
|
23474
|
+
]
|
|
23475
|
+
}, undefined, true, undefined, this) : /* @__PURE__ */ jsxDEV(Fragment, {
|
|
23476
|
+
children: [
|
|
23477
|
+
/* @__PURE__ */ jsxDEV("div", {
|
|
23478
|
+
class: "card-content",
|
|
23479
|
+
children: memory.content
|
|
23480
|
+
}, undefined, false, undefined, this),
|
|
23481
|
+
/* @__PURE__ */ jsxDEV("div", {
|
|
23482
|
+
class: "card-actions",
|
|
23483
|
+
children: [
|
|
23484
|
+
/* @__PURE__ */ jsxDEV("a", {
|
|
23485
|
+
href: `${returnUrl}${returnUrl.includes("?") ? "&" : "?"}edit=${encodeURIComponent(memory.id)}`,
|
|
23486
|
+
class: "btn",
|
|
23487
|
+
children: "Edit"
|
|
23488
|
+
}, undefined, false, undefined, this),
|
|
23489
|
+
/* @__PURE__ */ jsxDEV("form", {
|
|
23490
|
+
method: "post",
|
|
23491
|
+
action: `/memories/${encodeURIComponent(memory.id)}/delete`,
|
|
23492
|
+
onsubmit: "return confirm('Delete this memory?')",
|
|
23493
|
+
children: [
|
|
23494
|
+
/* @__PURE__ */ jsxDEV("input", {
|
|
23495
|
+
type: "hidden",
|
|
23496
|
+
name: "returnUrl",
|
|
23497
|
+
value: returnUrl
|
|
23498
|
+
}, undefined, false, undefined, this),
|
|
23499
|
+
/* @__PURE__ */ jsxDEV("button", {
|
|
23500
|
+
type: "submit",
|
|
23501
|
+
class: "danger",
|
|
23502
|
+
children: "Delete"
|
|
23503
|
+
}, undefined, false, undefined, this)
|
|
23504
|
+
]
|
|
23505
|
+
}, undefined, true, undefined, this)
|
|
23506
|
+
]
|
|
23507
|
+
}, undefined, true, undefined, this)
|
|
23508
|
+
]
|
|
23509
|
+
}, undefined, true, undefined, this)
|
|
23510
|
+
]
|
|
23511
|
+
}, undefined, true, undefined, this);
|
|
23512
|
+
|
|
23513
|
+
// src/ui/components/sidebar.tsx
|
|
23514
|
+
var Sidebar = ({ workspaces, selected }) => /* @__PURE__ */ jsxDEV("nav", {
|
|
23515
|
+
class: "sidebar",
|
|
23516
|
+
children: [
|
|
23517
|
+
/* @__PURE__ */ jsxDEV("h2", {
|
|
23518
|
+
children: "Workspaces"
|
|
23519
|
+
}, undefined, false, undefined, this),
|
|
23520
|
+
/* @__PURE__ */ jsxDEV("a", {
|
|
23521
|
+
href: "/",
|
|
23522
|
+
class: `sidebar-item all-item${selected === null ? " active" : ""}`,
|
|
23523
|
+
children: "All"
|
|
23524
|
+
}, undefined, false, undefined, this),
|
|
23525
|
+
/* @__PURE__ */ jsxDEV("a", {
|
|
23526
|
+
href: `/?workspace=${NO_WORKSPACE_FILTER}`,
|
|
23527
|
+
class: `sidebar-item no-ws-item${selected === NO_WORKSPACE_FILTER ? " active" : ""}`,
|
|
23528
|
+
children: "No workspace"
|
|
23529
|
+
}, undefined, false, undefined, this),
|
|
23530
|
+
workspaces.map((ws) => /* @__PURE__ */ jsxDEV("a", {
|
|
23531
|
+
href: `/?workspace=${encodeURIComponent(ws)}`,
|
|
23532
|
+
class: `sidebar-item ws-item${selected === ws ? " active" : ""}`,
|
|
23533
|
+
title: ws,
|
|
23534
|
+
children: /* @__PURE__ */ jsxDEV("span", {
|
|
23535
|
+
children: ws.replace(/\/$/, "")
|
|
23536
|
+
}, undefined, false, undefined, this)
|
|
23537
|
+
}, undefined, false, undefined, this))
|
|
23538
|
+
]
|
|
23539
|
+
}, undefined, true, undefined, this);
|
|
23540
|
+
|
|
23541
|
+
// src/ui/components/page.tsx
|
|
23542
|
+
var buildUrl = (base, overrides) => {
|
|
23543
|
+
const url = new URL(base, "http://localhost");
|
|
23544
|
+
for (const [key, value] of Object.entries(overrides)) {
|
|
23545
|
+
url.searchParams.set(key, value);
|
|
23546
|
+
}
|
|
23547
|
+
return `${url.pathname}${url.search}`;
|
|
23548
|
+
};
|
|
23549
|
+
var Page = ({
|
|
23550
|
+
memories,
|
|
23551
|
+
workspaces,
|
|
23552
|
+
selectedWorkspace,
|
|
23553
|
+
editingId,
|
|
23554
|
+
currentPage,
|
|
23555
|
+
hasMore,
|
|
23556
|
+
showCreate
|
|
23557
|
+
}) => {
|
|
23558
|
+
const params = new URLSearchParams;
|
|
23559
|
+
if (selectedWorkspace)
|
|
23560
|
+
params.set("workspace", selectedWorkspace);
|
|
23561
|
+
if (currentPage > 1)
|
|
23562
|
+
params.set("page", String(currentPage));
|
|
23563
|
+
const baseUrl = params.size > 0 ? `/?${params.toString()}` : "/";
|
|
23564
|
+
const showGroupHeaders = selectedWorkspace === null && new Set(memories.map((m) => m.workspace ?? null)).size > 1;
|
|
23565
|
+
const grouped = [];
|
|
23566
|
+
for (const m of memories) {
|
|
23567
|
+
const key = m.workspace ?? "(no workspace)";
|
|
23568
|
+
const last = grouped[grouped.length - 1];
|
|
23569
|
+
if (last && last.key === key) {
|
|
23570
|
+
last.items.push(m);
|
|
23571
|
+
} else {
|
|
23572
|
+
grouped.push({ key, items: [m] });
|
|
23573
|
+
}
|
|
23574
|
+
}
|
|
23575
|
+
const hasPrev = currentPage > 1;
|
|
23576
|
+
return /* @__PURE__ */ jsxDEV("html", {
|
|
23577
|
+
lang: "en",
|
|
23578
|
+
children: [
|
|
23579
|
+
/* @__PURE__ */ jsxDEV("head", {
|
|
23580
|
+
children: [
|
|
23581
|
+
/* @__PURE__ */ jsxDEV("meta", {
|
|
23582
|
+
charset: "utf-8"
|
|
23583
|
+
}, undefined, false, undefined, this),
|
|
23584
|
+
/* @__PURE__ */ jsxDEV("meta", {
|
|
23585
|
+
name: "viewport",
|
|
23586
|
+
content: "width=device-width, initial-scale=1"
|
|
23587
|
+
}, undefined, false, undefined, this),
|
|
23588
|
+
/* @__PURE__ */ jsxDEV("title", {
|
|
23589
|
+
children: "agent-memory"
|
|
23590
|
+
}, undefined, false, undefined, this),
|
|
23591
|
+
/* @__PURE__ */ jsxDEV("style", {
|
|
23592
|
+
children: styles_default
|
|
23593
|
+
}, undefined, false, undefined, this)
|
|
23594
|
+
]
|
|
23595
|
+
}, undefined, true, undefined, this),
|
|
23596
|
+
/* @__PURE__ */ jsxDEV("body", {
|
|
23597
|
+
children: /* @__PURE__ */ jsxDEV("div", {
|
|
23598
|
+
class: "layout",
|
|
23599
|
+
children: [
|
|
23600
|
+
/* @__PURE__ */ jsxDEV(Sidebar, {
|
|
23601
|
+
workspaces,
|
|
23602
|
+
selected: selectedWorkspace
|
|
23603
|
+
}, undefined, false, undefined, this),
|
|
23604
|
+
/* @__PURE__ */ jsxDEV("div", {
|
|
23605
|
+
class: "main",
|
|
23606
|
+
children: [
|
|
23607
|
+
/* @__PURE__ */ jsxDEV("header", {
|
|
23608
|
+
children: [
|
|
23609
|
+
/* @__PURE__ */ jsxDEV("h1", {
|
|
23610
|
+
children: "agent-memory"
|
|
23611
|
+
}, undefined, false, undefined, this),
|
|
23612
|
+
showCreate ? /* @__PURE__ */ jsxDEV("a", {
|
|
23613
|
+
href: baseUrl,
|
|
23614
|
+
class: "btn",
|
|
23615
|
+
children: "Cancel"
|
|
23616
|
+
}, undefined, false, undefined, this) : /* @__PURE__ */ jsxDEV("a", {
|
|
23617
|
+
href: buildUrl(baseUrl, { create: "1" }),
|
|
23618
|
+
class: "btn primary",
|
|
23619
|
+
children: "New Memory"
|
|
23620
|
+
}, undefined, false, undefined, this)
|
|
23621
|
+
]
|
|
23622
|
+
}, undefined, true, undefined, this),
|
|
23623
|
+
showCreate && /* @__PURE__ */ jsxDEV(CreateForm, {
|
|
23624
|
+
workspace: selectedWorkspace
|
|
23625
|
+
}, undefined, false, undefined, this),
|
|
23626
|
+
memories.length === 0 && !hasPrev ? /* @__PURE__ */ jsxDEV("div", {
|
|
23627
|
+
class: "empty",
|
|
23628
|
+
children: "No memories found."
|
|
23629
|
+
}, undefined, false, undefined, this) : /* @__PURE__ */ jsxDEV(Fragment, {
|
|
23630
|
+
children: [
|
|
23631
|
+
grouped.map(({ key, items }) => /* @__PURE__ */ jsxDEV(Fragment, {
|
|
23632
|
+
children: [
|
|
23633
|
+
showGroupHeaders && /* @__PURE__ */ jsxDEV("div", {
|
|
23634
|
+
class: "ws-group-header",
|
|
23635
|
+
children: key
|
|
23636
|
+
}, undefined, false, undefined, this),
|
|
23637
|
+
items.map((m) => /* @__PURE__ */ jsxDEV(MemoryCard, {
|
|
23638
|
+
memory: m,
|
|
23639
|
+
editing: editingId === m.id,
|
|
23640
|
+
showWorkspace: selectedWorkspace === null,
|
|
23641
|
+
returnUrl: baseUrl
|
|
23642
|
+
}, undefined, false, undefined, this))
|
|
23643
|
+
]
|
|
23644
|
+
}, undefined, true, undefined, this)),
|
|
23645
|
+
(hasPrev || hasMore) && /* @__PURE__ */ jsxDEV("div", {
|
|
23646
|
+
class: "pagination",
|
|
23647
|
+
children: [
|
|
23648
|
+
hasPrev ? /* @__PURE__ */ jsxDEV("a", {
|
|
23649
|
+
href: buildUrl(baseUrl, { page: String(currentPage - 1) }),
|
|
23650
|
+
class: "btn",
|
|
23651
|
+
children: "Previous"
|
|
23652
|
+
}, undefined, false, undefined, this) : /* @__PURE__ */ jsxDEV("span", {}, undefined, false, undefined, this),
|
|
23653
|
+
/* @__PURE__ */ jsxDEV("span", {
|
|
23654
|
+
class: "page-info",
|
|
23655
|
+
children: [
|
|
23656
|
+
"Page ",
|
|
23657
|
+
currentPage
|
|
23658
|
+
]
|
|
23659
|
+
}, undefined, true, undefined, this),
|
|
23660
|
+
hasMore ? /* @__PURE__ */ jsxDEV("a", {
|
|
23661
|
+
href: buildUrl(baseUrl, { page: String(currentPage + 1) }),
|
|
23662
|
+
class: "btn",
|
|
23663
|
+
children: "Next"
|
|
23664
|
+
}, undefined, false, undefined, this) : /* @__PURE__ */ jsxDEV("span", {}, undefined, false, undefined, this)
|
|
23665
|
+
]
|
|
23666
|
+
}, undefined, true, undefined, this)
|
|
23667
|
+
]
|
|
23668
|
+
}, undefined, true, undefined, this)
|
|
23669
|
+
]
|
|
23670
|
+
}, undefined, true, undefined, this)
|
|
23671
|
+
]
|
|
23672
|
+
}, undefined, true, undefined, this)
|
|
23673
|
+
}, undefined, false, undefined, this)
|
|
23674
|
+
]
|
|
23675
|
+
}, undefined, true, undefined, this);
|
|
23676
|
+
};
|
|
23677
|
+
|
|
23678
|
+
// src/ui/server.tsx
|
|
23679
|
+
var DEFAULT_LIST_LIMIT = 15;
|
|
23680
|
+
var MAX_LIST_LIMIT = 100;
|
|
23681
|
+
var startWebServer = (repository, options) => {
|
|
23682
|
+
const app = new Hono2;
|
|
23683
|
+
app.get("/", async (c) => {
|
|
23684
|
+
const workspace = c.req.query("workspace") ?? null;
|
|
23685
|
+
const pageNum = Math.max(Number(c.req.query("page")) || 1, 1);
|
|
23686
|
+
const editingId = c.req.query("edit") ?? null;
|
|
23687
|
+
const showCreate = c.req.query("create") === "1";
|
|
23688
|
+
const isNoWorkspace = workspace === NO_WORKSPACE_FILTER;
|
|
23689
|
+
const wsFilter = workspace && !isNoWorkspace ? workspace : undefined;
|
|
23690
|
+
const page = await repository.findAll({
|
|
23691
|
+
workspace: wsFilter,
|
|
23692
|
+
workspaceIsNull: isNoWorkspace,
|
|
23693
|
+
offset: (pageNum - 1) * DEFAULT_LIST_LIMIT,
|
|
23694
|
+
limit: DEFAULT_LIST_LIMIT
|
|
23695
|
+
});
|
|
23696
|
+
const workspaces = await repository.listWorkspaces();
|
|
23697
|
+
return c.html(/* @__PURE__ */ jsxDEV(Page, {
|
|
23698
|
+
memories: page.items,
|
|
23699
|
+
workspaces,
|
|
23700
|
+
selectedWorkspace: workspace,
|
|
23701
|
+
editingId,
|
|
23702
|
+
currentPage: pageNum,
|
|
23703
|
+
hasMore: page.hasMore,
|
|
23704
|
+
showCreate
|
|
23705
|
+
}, undefined, false, undefined, this));
|
|
23706
|
+
});
|
|
23707
|
+
app.post("/memories", async (c) => {
|
|
23708
|
+
const form2 = await c.req.parseBody();
|
|
23709
|
+
const content = typeof form2.content === "string" ? form2.content.trim() : "";
|
|
23710
|
+
const workspace = typeof form2.workspace === "string" ? form2.workspace.trim() || undefined : undefined;
|
|
23711
|
+
if (content) {
|
|
23712
|
+
const now = new Date;
|
|
23713
|
+
await repository.save({ id: randomUUID2(), content, workspace, createdAt: now, updatedAt: now });
|
|
23714
|
+
}
|
|
23715
|
+
const wsParam = workspace ? `/?workspace=${encodeURIComponent(workspace)}` : "/";
|
|
23716
|
+
return c.redirect(wsParam);
|
|
23717
|
+
});
|
|
23718
|
+
app.post("/memories/:id/update", async (c) => {
|
|
23719
|
+
const form2 = await c.req.parseBody();
|
|
23720
|
+
const content = typeof form2.content === "string" ? form2.content.trim() : "";
|
|
23721
|
+
const returnUrl = safeReturnUrl(form2.returnUrl);
|
|
23722
|
+
if (content) {
|
|
23723
|
+
try {
|
|
23724
|
+
await repository.update(c.req.param("id"), content);
|
|
23725
|
+
} catch (error2) {
|
|
23726
|
+
if (!(error2 instanceof NotFoundError))
|
|
23727
|
+
throw error2;
|
|
23728
|
+
}
|
|
23729
|
+
}
|
|
23730
|
+
return c.redirect(returnUrl);
|
|
23731
|
+
});
|
|
23732
|
+
app.post("/memories/:id/delete", async (c) => {
|
|
23733
|
+
const form2 = await c.req.parseBody();
|
|
23734
|
+
const returnUrl = safeReturnUrl(form2.returnUrl);
|
|
23735
|
+
try {
|
|
23736
|
+
await repository.delete(c.req.param("id"));
|
|
23737
|
+
} catch (error2) {
|
|
23738
|
+
if (!(error2 instanceof NotFoundError))
|
|
23739
|
+
throw error2;
|
|
23740
|
+
}
|
|
23741
|
+
return c.redirect(returnUrl);
|
|
23742
|
+
});
|
|
23743
|
+
app.get("/api/workspaces", async (c) => {
|
|
23744
|
+
const workspaces = await repository.listWorkspaces();
|
|
23745
|
+
return c.json({ workspaces });
|
|
23746
|
+
});
|
|
23747
|
+
app.get("/api/memories", async (c) => {
|
|
23748
|
+
const workspace = c.req.query("workspace");
|
|
23749
|
+
const limitParam = c.req.query("limit");
|
|
23750
|
+
const limit = Math.min(Math.max(Number(limitParam) || DEFAULT_LIST_LIMIT, 1), MAX_LIST_LIMIT);
|
|
23751
|
+
const offset = Math.max(Number(c.req.query("offset")) || 0, 0);
|
|
23752
|
+
const page = await repository.findAll({ workspace, offset, limit });
|
|
23753
|
+
return c.json({ items: page.items.map(toMemoryJson), hasMore: page.hasMore });
|
|
23754
|
+
});
|
|
23755
|
+
app.get("/api/memories/:id", async (c) => {
|
|
23756
|
+
const memory = await repository.findById(c.req.param("id"));
|
|
23757
|
+
if (!memory)
|
|
23758
|
+
return c.json({ error: "Memory not found." }, 404);
|
|
23759
|
+
return c.json(toMemoryJson(memory));
|
|
23760
|
+
});
|
|
23761
|
+
app.post("/api/memories", async (c) => {
|
|
23762
|
+
const body = await c.req.json().catch(() => null);
|
|
23763
|
+
if (!body)
|
|
23764
|
+
return c.json({ error: "Invalid JSON." }, 400);
|
|
23765
|
+
const content = typeof body.content === "string" ? body.content.trim() : "";
|
|
23766
|
+
if (!content)
|
|
23767
|
+
return c.json({ error: "Content is required." }, 400);
|
|
23768
|
+
const workspace = typeof body.workspace === "string" ? body.workspace.trim() || undefined : undefined;
|
|
23769
|
+
const now = new Date;
|
|
23770
|
+
const memory = await repository.save({ id: randomUUID2(), content, workspace, createdAt: now, updatedAt: now });
|
|
23771
|
+
return c.json(toMemoryJson(memory), 201);
|
|
23772
|
+
});
|
|
23773
|
+
app.patch("/api/memories/:id", async (c) => {
|
|
23774
|
+
const body = await c.req.json().catch(() => null);
|
|
23775
|
+
if (!body)
|
|
23776
|
+
return c.json({ error: "Invalid JSON." }, 400);
|
|
23777
|
+
const content = typeof body.content === "string" ? body.content.trim() : "";
|
|
23778
|
+
if (!content)
|
|
23779
|
+
return c.json({ error: "Content is required." }, 400);
|
|
23780
|
+
try {
|
|
23781
|
+
const updated = await repository.update(c.req.param("id"), content);
|
|
23782
|
+
return c.json(toMemoryJson(updated));
|
|
23783
|
+
} catch (error2) {
|
|
23784
|
+
if (error2 instanceof NotFoundError)
|
|
23785
|
+
return c.json({ error: "Memory not found." }, 404);
|
|
23786
|
+
throw error2;
|
|
23787
|
+
}
|
|
23788
|
+
});
|
|
23789
|
+
app.delete("/api/memories/:id", async (c) => {
|
|
23790
|
+
try {
|
|
23791
|
+
await repository.delete(c.req.param("id"));
|
|
23792
|
+
return c.body(null, 204);
|
|
23793
|
+
} catch (error2) {
|
|
23794
|
+
if (error2 instanceof NotFoundError)
|
|
23795
|
+
return c.json({ error: "Memory not found." }, 404);
|
|
23796
|
+
throw error2;
|
|
23797
|
+
}
|
|
23798
|
+
});
|
|
23799
|
+
return serve({ fetch: app.fetch, port: options.port });
|
|
23800
|
+
};
|
|
23801
|
+
var safeReturnUrl = (value) => {
|
|
23802
|
+
if (typeof value === "string" && value.startsWith("/"))
|
|
23803
|
+
return value;
|
|
23804
|
+
return "/";
|
|
23805
|
+
};
|
|
23806
|
+
var toMemoryJson = (memory) => ({
|
|
23807
|
+
id: memory.id,
|
|
23808
|
+
content: memory.content,
|
|
23809
|
+
workspace: memory.workspace ?? null,
|
|
23810
|
+
created_at: memory.createdAt.toISOString(),
|
|
23811
|
+
updated_at: memory.updatedAt.toISOString()
|
|
23812
|
+
});
|
|
23813
|
+
|
|
23814
|
+
// src/index.ts
|
|
23815
|
+
var config2 = resolveConfig();
|
|
23816
|
+
var database = openMemoryDatabase(config2.databasePath);
|
|
23817
|
+
var repository = new SqliteMemoryRepository(database);
|
|
23818
|
+
if (config2.uiMode) {
|
|
23819
|
+
const server = startWebServer(repository, { port: config2.uiPort });
|
|
23820
|
+
const addr = server.address();
|
|
23821
|
+
const port = typeof addr === "object" && addr ? addr.port : config2.uiPort;
|
|
23822
|
+
console.log(`agent-memory UI running at http://localhost:${port}`);
|
|
23823
|
+
const shutdown = () => {
|
|
23824
|
+
server.close();
|
|
23825
|
+
database.close();
|
|
23826
|
+
process.exit(0);
|
|
23827
|
+
};
|
|
23828
|
+
process.on("SIGINT", shutdown);
|
|
23829
|
+
process.on("SIGTERM", shutdown);
|
|
23830
|
+
} else {
|
|
23831
|
+
const memoryService = new MemoryService(repository);
|
|
23832
|
+
const server = createMcpServer(memoryService, version2);
|
|
23833
|
+
const transport = new StdioServerTransport;
|
|
23834
|
+
try {
|
|
23835
|
+
await server.connect(transport);
|
|
23836
|
+
} catch (error2) {
|
|
23837
|
+
console.error(error2 instanceof Error ? error2.message : "Failed to start agent-memory.");
|
|
23838
|
+
database.close();
|
|
23839
|
+
process.exit(1);
|
|
23840
|
+
}
|
|
20287
23841
|
}
|