@ubiquity-os/plugin-sdk 3.8.0 → 3.8.1
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 +43 -27
- package/dist/configuration.d.mts +3 -3
- package/dist/configuration.d.ts +3 -3
- package/dist/configuration.js +12 -2632
- package/dist/configuration.mjs +2 -2632
- package/dist/{context-zLHgu52i.d.ts → context-BE4WjJZf.d.ts} +0 -28
- package/dist/{context-Dwl3aRX-.d.mts → context-Ckj1HMjz.d.mts} +0 -28
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +127 -2857
- package/dist/index.mjs +93 -2823
- package/dist/llm.d.mts +2 -2
- package/dist/llm.d.ts +2 -2
- package/dist/llm.js +11 -0
- package/dist/llm.mjs +11 -0
- package/dist/octokit.d.mts +2 -2
- package/dist/octokit.d.ts +2 -2
- package/dist/octokit.js +2 -164
- package/dist/octokit.mjs +1 -163
- package/package.json +11 -1
package/dist/index.mjs
CHANGED
|
@@ -1,343 +1,11 @@
|
|
|
1
1
|
// src/actions.ts
|
|
2
2
|
import * as core from "@actions/core";
|
|
3
3
|
import { Value as Value3 } from "@sinclair/typebox/value";
|
|
4
|
-
|
|
5
|
-
// ../../node_modules/@ubiquity-os/ubiquity-os-logger/dist/index.js
|
|
6
|
-
var COLORS = {
|
|
7
|
-
reset: "\x1B[0m",
|
|
8
|
-
bright: "\x1B[1m",
|
|
9
|
-
dim: "\x1B[2m",
|
|
10
|
-
underscore: "\x1B[4m",
|
|
11
|
-
blink: "\x1B[5m",
|
|
12
|
-
reverse: "\x1B[7m",
|
|
13
|
-
hidden: "\x1B[8m",
|
|
14
|
-
fgBlack: "\x1B[30m",
|
|
15
|
-
fgRed: "\x1B[31m",
|
|
16
|
-
fgGreen: "\x1B[32m",
|
|
17
|
-
fgYellow: "\x1B[33m",
|
|
18
|
-
fgBlue: "\x1B[34m",
|
|
19
|
-
fgMagenta: "\x1B[35m",
|
|
20
|
-
fgCyan: "\x1B[36m",
|
|
21
|
-
fgWhite: "\x1B[37m",
|
|
22
|
-
bgBlack: "\x1B[40m",
|
|
23
|
-
bgRed: "\x1B[41m",
|
|
24
|
-
bgGreen: "\x1B[42m",
|
|
25
|
-
bgYellow: "\x1B[43m",
|
|
26
|
-
bgBlue: "\x1B[44m",
|
|
27
|
-
bgMagenta: "\x1B[45m",
|
|
28
|
-
bgCyan: "\x1B[46m",
|
|
29
|
-
bgWhite: "\x1B[47m"
|
|
30
|
-
};
|
|
31
|
-
var LOG_LEVEL = {
|
|
32
|
-
FATAL: "fatal",
|
|
33
|
-
ERROR: "error",
|
|
34
|
-
WARN: "warn",
|
|
35
|
-
INFO: "info",
|
|
36
|
-
VERBOSE: "verbose",
|
|
37
|
-
DEBUG: "debug"
|
|
38
|
-
};
|
|
39
|
-
var PrettyLogs = class {
|
|
40
|
-
constructor() {
|
|
41
|
-
this.ok = this.ok.bind(this);
|
|
42
|
-
this.info = this.info.bind(this);
|
|
43
|
-
this.error = this.error.bind(this);
|
|
44
|
-
this.fatal = this.fatal.bind(this);
|
|
45
|
-
this.warn = this.warn.bind(this);
|
|
46
|
-
this.debug = this.debug.bind(this);
|
|
47
|
-
this.verbose = this.verbose.bind(this);
|
|
48
|
-
}
|
|
49
|
-
fatal(message, metadata) {
|
|
50
|
-
this._logWithStack(LOG_LEVEL.FATAL, message, metadata);
|
|
51
|
-
}
|
|
52
|
-
error(message, metadata) {
|
|
53
|
-
this._logWithStack(LOG_LEVEL.ERROR, message, metadata);
|
|
54
|
-
}
|
|
55
|
-
warn(message, metadata) {
|
|
56
|
-
this._logWithStack(LOG_LEVEL.WARN, message, metadata);
|
|
57
|
-
}
|
|
58
|
-
ok(message, metadata) {
|
|
59
|
-
this._logWithStack("ok", message, metadata);
|
|
60
|
-
}
|
|
61
|
-
info(message, metadata) {
|
|
62
|
-
this._logWithStack(LOG_LEVEL.INFO, message, metadata);
|
|
63
|
-
}
|
|
64
|
-
debug(message, metadata) {
|
|
65
|
-
this._logWithStack(LOG_LEVEL.DEBUG, message, metadata);
|
|
66
|
-
}
|
|
67
|
-
verbose(message, metadata) {
|
|
68
|
-
this._logWithStack(LOG_LEVEL.VERBOSE, message, metadata);
|
|
69
|
-
}
|
|
70
|
-
_logWithStack(type, message, metaData) {
|
|
71
|
-
this._log(type, message);
|
|
72
|
-
if (typeof metaData === "string") {
|
|
73
|
-
this._log(type, metaData);
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
if (metaData) {
|
|
77
|
-
const metadata = metaData;
|
|
78
|
-
let stack = metadata?.error?.stack || metadata?.stack;
|
|
79
|
-
if (!stack) {
|
|
80
|
-
const stackTrace = new Error().stack?.split("\n");
|
|
81
|
-
if (stackTrace) {
|
|
82
|
-
stackTrace.splice(0, 4);
|
|
83
|
-
stack = stackTrace.filter((line) => line.includes(".ts:")).join("\n");
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
const newMetadata = { ...metadata };
|
|
87
|
-
delete newMetadata.message;
|
|
88
|
-
delete newMetadata.name;
|
|
89
|
-
delete newMetadata.stack;
|
|
90
|
-
if (!this._isEmpty(newMetadata)) {
|
|
91
|
-
this._log(type, newMetadata);
|
|
92
|
-
}
|
|
93
|
-
if (typeof stack == "string") {
|
|
94
|
-
const prettyStack = this._formatStackTrace(stack, 1);
|
|
95
|
-
const colorizedStack = this._colorizeText(prettyStack, COLORS.dim);
|
|
96
|
-
this._log(type, colorizedStack);
|
|
97
|
-
} else if (stack) {
|
|
98
|
-
const prettyStack = this._formatStackTrace(stack.join("\n"), 1);
|
|
99
|
-
const colorizedStack = this._colorizeText(prettyStack, COLORS.dim);
|
|
100
|
-
this._log(type, colorizedStack);
|
|
101
|
-
} else {
|
|
102
|
-
throw new Error("Stack is null");
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
_colorizeText(text, color) {
|
|
107
|
-
if (!color) {
|
|
108
|
-
throw new Error(`Invalid color: ${color}`);
|
|
109
|
-
}
|
|
110
|
-
return color.concat(text).concat(COLORS.reset);
|
|
111
|
-
}
|
|
112
|
-
_formatStackTrace(stack, linesToRemove = 0, prefix = "") {
|
|
113
|
-
const lines = stack.split("\n");
|
|
114
|
-
for (let i = 0; i < linesToRemove; i++) {
|
|
115
|
-
lines.shift();
|
|
116
|
-
}
|
|
117
|
-
return lines.map((line) => `${prefix}${line.replace(/\s*at\s*/, " \u21B3 ")}`).join("\n");
|
|
118
|
-
}
|
|
119
|
-
_isEmpty(obj) {
|
|
120
|
-
return !Reflect.ownKeys(obj).some((key) => typeof obj[String(key)] !== "function");
|
|
121
|
-
}
|
|
122
|
-
_log(type, message) {
|
|
123
|
-
const defaultSymbols = {
|
|
124
|
-
fatal: "\xD7",
|
|
125
|
-
ok: "\u2713",
|
|
126
|
-
warn: "\u26A0",
|
|
127
|
-
error: "\u26A0",
|
|
128
|
-
info: "\u203A",
|
|
129
|
-
debug: "\u203A\u203A",
|
|
130
|
-
verbose: "\u{1F4AC}"
|
|
131
|
-
};
|
|
132
|
-
const symbol = defaultSymbols[type];
|
|
133
|
-
const messageFormatted = typeof message === "string" ? message : JSON.stringify(message, null, 2);
|
|
134
|
-
const lines = messageFormatted.split("\n");
|
|
135
|
-
const logString = lines.map((line, index) => {
|
|
136
|
-
const prefix = index === 0 ? ` ${symbol}` : ` ${" ".repeat(symbol.length)}`;
|
|
137
|
-
return `${prefix} ${line}`;
|
|
138
|
-
}).join("\n");
|
|
139
|
-
const fullLogString = logString;
|
|
140
|
-
const colorMap = {
|
|
141
|
-
fatal: ["error", COLORS.fgRed],
|
|
142
|
-
ok: ["log", COLORS.fgGreen],
|
|
143
|
-
warn: ["warn", COLORS.fgYellow],
|
|
144
|
-
error: ["warn", COLORS.fgYellow],
|
|
145
|
-
info: ["info", COLORS.dim],
|
|
146
|
-
debug: ["debug", COLORS.fgMagenta],
|
|
147
|
-
verbose: ["debug", COLORS.dim]
|
|
148
|
-
};
|
|
149
|
-
const _console = console[colorMap[type][0]];
|
|
150
|
-
if (typeof _console === "function" && fullLogString.length > 12) {
|
|
151
|
-
_console(this._colorizeText(fullLogString, colorMap[type][1]));
|
|
152
|
-
} else if (fullLogString.length <= 12) {
|
|
153
|
-
return;
|
|
154
|
-
} else {
|
|
155
|
-
throw new Error(fullLogString);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
var LogReturn = class {
|
|
160
|
-
logMessage;
|
|
161
|
-
metadata;
|
|
162
|
-
constructor(logMessage, metadata) {
|
|
163
|
-
this.logMessage = logMessage;
|
|
164
|
-
this.metadata = metadata;
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
|
-
var Logs = class _Logs {
|
|
168
|
-
_maxLevel = -1;
|
|
169
|
-
static console;
|
|
170
|
-
_log({ level, consoleLog, logMessage, metadata, type }) {
|
|
171
|
-
if (this._getNumericLevel(level) <= this._maxLevel) {
|
|
172
|
-
consoleLog(logMessage, metadata);
|
|
173
|
-
}
|
|
174
|
-
return new LogReturn(
|
|
175
|
-
{
|
|
176
|
-
raw: logMessage,
|
|
177
|
-
diff: this._diffColorCommentMessage(type, logMessage),
|
|
178
|
-
type,
|
|
179
|
-
level
|
|
180
|
-
},
|
|
181
|
-
metadata
|
|
182
|
-
);
|
|
183
|
-
}
|
|
184
|
-
_addDiagnosticInformation(metadata) {
|
|
185
|
-
if (!metadata) {
|
|
186
|
-
metadata = {};
|
|
187
|
-
} else if (typeof metadata !== "object") {
|
|
188
|
-
metadata = { message: metadata };
|
|
189
|
-
}
|
|
190
|
-
const stackLines = new Error().stack?.split("\n") || [];
|
|
191
|
-
if (stackLines.length > 3) {
|
|
192
|
-
const callerLine = stackLines[3];
|
|
193
|
-
const match2 = callerLine.match(/at (\S+)/);
|
|
194
|
-
if (match2) {
|
|
195
|
-
metadata.caller = match2[1];
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
return metadata;
|
|
199
|
-
}
|
|
200
|
-
ok(log, metadata) {
|
|
201
|
-
metadata = this._addDiagnosticInformation(metadata);
|
|
202
|
-
return this._log({
|
|
203
|
-
level: LOG_LEVEL.INFO,
|
|
204
|
-
consoleLog: _Logs.console.ok,
|
|
205
|
-
logMessage: log,
|
|
206
|
-
metadata,
|
|
207
|
-
type: "ok"
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
info(log, metadata) {
|
|
211
|
-
metadata = this._addDiagnosticInformation(metadata);
|
|
212
|
-
return this._log({
|
|
213
|
-
level: LOG_LEVEL.INFO,
|
|
214
|
-
consoleLog: _Logs.console.info,
|
|
215
|
-
logMessage: log,
|
|
216
|
-
metadata,
|
|
217
|
-
type: "info"
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
warn(log, metadata) {
|
|
221
|
-
metadata = this._addDiagnosticInformation(metadata);
|
|
222
|
-
return this._log({
|
|
223
|
-
level: LOG_LEVEL.WARN,
|
|
224
|
-
consoleLog: _Logs.console.warn,
|
|
225
|
-
logMessage: log,
|
|
226
|
-
metadata,
|
|
227
|
-
type: "warn"
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
error(log, metadata) {
|
|
231
|
-
metadata = this._addDiagnosticInformation(metadata);
|
|
232
|
-
return this._log({
|
|
233
|
-
level: LOG_LEVEL.ERROR,
|
|
234
|
-
consoleLog: _Logs.console.error,
|
|
235
|
-
logMessage: log,
|
|
236
|
-
metadata,
|
|
237
|
-
type: "error"
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
debug(log, metadata) {
|
|
241
|
-
metadata = this._addDiagnosticInformation(metadata);
|
|
242
|
-
return this._log({
|
|
243
|
-
level: LOG_LEVEL.DEBUG,
|
|
244
|
-
consoleLog: _Logs.console.debug,
|
|
245
|
-
logMessage: log,
|
|
246
|
-
metadata,
|
|
247
|
-
type: "debug"
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
|
-
fatal(log, metadata) {
|
|
251
|
-
if (!metadata) {
|
|
252
|
-
metadata = _Logs.convertErrorsIntoObjects(new Error(log));
|
|
253
|
-
const stack = metadata.stack;
|
|
254
|
-
stack.splice(1, 1);
|
|
255
|
-
metadata.stack = stack;
|
|
256
|
-
}
|
|
257
|
-
if (metadata instanceof Error) {
|
|
258
|
-
metadata = _Logs.convertErrorsIntoObjects(metadata);
|
|
259
|
-
const stack = metadata.stack;
|
|
260
|
-
stack.splice(1, 1);
|
|
261
|
-
metadata.stack = stack;
|
|
262
|
-
}
|
|
263
|
-
metadata = this._addDiagnosticInformation(metadata);
|
|
264
|
-
return this._log({
|
|
265
|
-
level: LOG_LEVEL.FATAL,
|
|
266
|
-
consoleLog: _Logs.console.fatal,
|
|
267
|
-
logMessage: log,
|
|
268
|
-
metadata,
|
|
269
|
-
type: "fatal"
|
|
270
|
-
});
|
|
271
|
-
}
|
|
272
|
-
verbose(log, metadata) {
|
|
273
|
-
metadata = this._addDiagnosticInformation(metadata);
|
|
274
|
-
return this._log({
|
|
275
|
-
level: LOG_LEVEL.VERBOSE,
|
|
276
|
-
consoleLog: _Logs.console.verbose,
|
|
277
|
-
logMessage: log,
|
|
278
|
-
metadata,
|
|
279
|
-
type: "verbose"
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
constructor(logLevel) {
|
|
283
|
-
this._maxLevel = this._getNumericLevel(logLevel);
|
|
284
|
-
_Logs.console = new PrettyLogs();
|
|
285
|
-
}
|
|
286
|
-
_diffColorCommentMessage(type, message) {
|
|
287
|
-
const diffPrefix = {
|
|
288
|
-
fatal: "> [!CAUTION]",
|
|
289
|
-
error: "> [!CAUTION]",
|
|
290
|
-
warn: "> [!WARNING]",
|
|
291
|
-
ok: "> [!TIP]",
|
|
292
|
-
info: "> [!NOTE]",
|
|
293
|
-
debug: "> [!IMPORTANT]",
|
|
294
|
-
verbose: "> [!NOTE]"
|
|
295
|
-
};
|
|
296
|
-
const selected = diffPrefix[type];
|
|
297
|
-
if (selected) {
|
|
298
|
-
message = message.trim().split("\n").map((line) => `> ${line}`).join("\n");
|
|
299
|
-
}
|
|
300
|
-
return [selected, message].join("\n");
|
|
301
|
-
}
|
|
302
|
-
_getNumericLevel(level) {
|
|
303
|
-
switch (level) {
|
|
304
|
-
case LOG_LEVEL.FATAL:
|
|
305
|
-
return 0;
|
|
306
|
-
case LOG_LEVEL.ERROR:
|
|
307
|
-
return 1;
|
|
308
|
-
case LOG_LEVEL.WARN:
|
|
309
|
-
return 2;
|
|
310
|
-
case LOG_LEVEL.INFO:
|
|
311
|
-
return 3;
|
|
312
|
-
case LOG_LEVEL.VERBOSE:
|
|
313
|
-
return 4;
|
|
314
|
-
case LOG_LEVEL.DEBUG:
|
|
315
|
-
return 5;
|
|
316
|
-
default:
|
|
317
|
-
return -1;
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
static convertErrorsIntoObjects(obj) {
|
|
321
|
-
if (obj instanceof Error) {
|
|
322
|
-
return {
|
|
323
|
-
message: obj.message,
|
|
324
|
-
name: obj.name,
|
|
325
|
-
stack: obj.stack ? obj.stack.split("\n") : null
|
|
326
|
-
};
|
|
327
|
-
} else if (typeof obj === "object" && obj !== null) {
|
|
328
|
-
const keys = Object.keys(obj);
|
|
329
|
-
keys.forEach((key) => {
|
|
330
|
-
obj[key] = this.convertErrorsIntoObjects(obj[key]);
|
|
331
|
-
});
|
|
332
|
-
}
|
|
333
|
-
return obj;
|
|
334
|
-
}
|
|
335
|
-
};
|
|
336
|
-
|
|
337
|
-
// src/actions.ts
|
|
4
|
+
import { Logs } from "@ubiquity-os/ubiquity-os-logger";
|
|
338
5
|
import { config } from "dotenv";
|
|
339
6
|
|
|
340
7
|
// src/error.ts
|
|
8
|
+
import { LogReturn } from "@ubiquity-os/ubiquity-os-logger";
|
|
341
9
|
function getErrorStatus(err) {
|
|
342
10
|
if (!err || typeof err !== "object") return null;
|
|
343
11
|
const candidate = err;
|
|
@@ -348,9 +16,9 @@ function getErrorStatus(err) {
|
|
|
348
16
|
if (Number.isFinite(parsed)) return parsed;
|
|
349
17
|
}
|
|
350
18
|
if (err instanceof Error) {
|
|
351
|
-
const
|
|
352
|
-
if (
|
|
353
|
-
const parsed = Number.parseInt(
|
|
19
|
+
const match = /LLM API error:\s*(\d{3})/i.exec(err.message);
|
|
20
|
+
if (match) {
|
|
21
|
+
const parsed = Number.parseInt(match[1], 10);
|
|
354
22
|
if (Number.isFinite(parsed)) return parsed;
|
|
355
23
|
}
|
|
356
24
|
}
|
|
@@ -388,56 +56,8 @@ function transformError(context, error) {
|
|
|
388
56
|
return logByStatus(context, String(error), { err: error });
|
|
389
57
|
}
|
|
390
58
|
|
|
391
|
-
//
|
|
392
|
-
|
|
393
|
-
const global = globalThis;
|
|
394
|
-
const globalEnv = global?.process?.env;
|
|
395
|
-
runtime ??= getRuntimeKey();
|
|
396
|
-
const runtimeEnvHandlers = {
|
|
397
|
-
bun: () => globalEnv,
|
|
398
|
-
node: () => globalEnv,
|
|
399
|
-
"edge-light": () => globalEnv,
|
|
400
|
-
deno: () => {
|
|
401
|
-
return Deno.env.toObject();
|
|
402
|
-
},
|
|
403
|
-
workerd: () => c.env,
|
|
404
|
-
// On Fastly Compute, you can use the ConfigStore to manage user-defined data.
|
|
405
|
-
fastly: () => ({}),
|
|
406
|
-
other: () => ({})
|
|
407
|
-
};
|
|
408
|
-
return runtimeEnvHandlers[runtime]();
|
|
409
|
-
};
|
|
410
|
-
var knownUserAgents = {
|
|
411
|
-
deno: "Deno",
|
|
412
|
-
bun: "Bun",
|
|
413
|
-
workerd: "Cloudflare-Workers",
|
|
414
|
-
node: "Node.js"
|
|
415
|
-
};
|
|
416
|
-
var getRuntimeKey = () => {
|
|
417
|
-
const global = globalThis;
|
|
418
|
-
const userAgentSupported = typeof navigator !== "undefined" && typeof navigator.userAgent === "string";
|
|
419
|
-
if (userAgentSupported) {
|
|
420
|
-
for (const [runtimeKey, userAgent] of Object.entries(knownUserAgents)) {
|
|
421
|
-
if (checkUserAgentEquals(userAgent)) {
|
|
422
|
-
return runtimeKey;
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
if (typeof global?.EdgeRuntime === "string") {
|
|
427
|
-
return "edge-light";
|
|
428
|
-
}
|
|
429
|
-
if (global?.fastly !== void 0) {
|
|
430
|
-
return "fastly";
|
|
431
|
-
}
|
|
432
|
-
if (global?.process?.release?.name === "node") {
|
|
433
|
-
return "node";
|
|
434
|
-
}
|
|
435
|
-
return "other";
|
|
436
|
-
};
|
|
437
|
-
var checkUserAgentEquals = (platform) => {
|
|
438
|
-
const userAgent = navigator.userAgent;
|
|
439
|
-
return userAgent.startsWith(platform);
|
|
440
|
-
};
|
|
59
|
+
// src/helpers/runtime-info.ts
|
|
60
|
+
import { getRuntimeKey } from "hono/adapter";
|
|
441
61
|
|
|
442
62
|
// src/helpers/github-context.ts
|
|
443
63
|
import * as github from "@actions/github";
|
|
@@ -458,29 +78,29 @@ function getGithubContext() {
|
|
|
458
78
|
var PluginRuntimeInfo = class _PluginRuntimeInfo {
|
|
459
79
|
static _instance = null;
|
|
460
80
|
_env = {};
|
|
461
|
-
constructor(
|
|
462
|
-
if (
|
|
463
|
-
this._env =
|
|
81
|
+
constructor(env) {
|
|
82
|
+
if (env) {
|
|
83
|
+
this._env = env;
|
|
464
84
|
}
|
|
465
85
|
}
|
|
466
|
-
static getInstance(
|
|
86
|
+
static getInstance(env) {
|
|
467
87
|
if (!_PluginRuntimeInfo._instance) {
|
|
468
88
|
switch (getRuntimeKey()) {
|
|
469
89
|
case "workerd":
|
|
470
|
-
_PluginRuntimeInfo._instance = new CfRuntimeInfo(
|
|
90
|
+
_PluginRuntimeInfo._instance = new CfRuntimeInfo(env);
|
|
471
91
|
break;
|
|
472
92
|
case "deno":
|
|
473
93
|
if (process.env.CI) {
|
|
474
|
-
_PluginRuntimeInfo._instance = new NodeRuntimeInfo(
|
|
94
|
+
_PluginRuntimeInfo._instance = new NodeRuntimeInfo(env);
|
|
475
95
|
} else {
|
|
476
|
-
_PluginRuntimeInfo._instance = new DenoRuntimeInfo(
|
|
96
|
+
_PluginRuntimeInfo._instance = new DenoRuntimeInfo(env);
|
|
477
97
|
}
|
|
478
98
|
break;
|
|
479
99
|
case "node":
|
|
480
|
-
_PluginRuntimeInfo._instance = new NodeRuntimeInfo(
|
|
100
|
+
_PluginRuntimeInfo._instance = new NodeRuntimeInfo(env);
|
|
481
101
|
break;
|
|
482
102
|
default:
|
|
483
|
-
_PluginRuntimeInfo._instance = new NodeRuntimeInfo(
|
|
103
|
+
_PluginRuntimeInfo._instance = new NodeRuntimeInfo(env);
|
|
484
104
|
break;
|
|
485
105
|
}
|
|
486
106
|
}
|
|
@@ -546,6 +166,9 @@ var DenoRuntimeInfo = class extends PluginRuntimeInfo {
|
|
|
546
166
|
}
|
|
547
167
|
};
|
|
548
168
|
|
|
169
|
+
// src/util.ts
|
|
170
|
+
import { LOG_LEVEL } from "@ubiquity-os/ubiquity-os-logger";
|
|
171
|
+
|
|
549
172
|
// src/constants.ts
|
|
550
173
|
var KERNEL_PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
|
|
551
174
|
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAs96DOU+JqM8SyNXOB6u3
|
|
@@ -596,54 +219,6 @@ function getPluginOptions(options) {
|
|
|
596
219
|
}
|
|
597
220
|
|
|
598
221
|
// src/comment.ts
|
|
599
|
-
var COMMAND_RESPONSE_KIND = "command-response";
|
|
600
|
-
var COMMAND_RESPONSE_MARKER = `"commentKind": "${COMMAND_RESPONSE_KIND}"`;
|
|
601
|
-
var COMMAND_RESPONSE_COMMENT_LIMIT = 50;
|
|
602
|
-
var RECENT_COMMENTS_QUERY = `
|
|
603
|
-
query($owner: String!, $repo: String!, $number: Int!, $last: Int!) {
|
|
604
|
-
repository(owner: $owner, name: $repo) {
|
|
605
|
-
issueOrPullRequest(number: $number) {
|
|
606
|
-
__typename
|
|
607
|
-
... on Issue {
|
|
608
|
-
comments(last: $last) {
|
|
609
|
-
nodes {
|
|
610
|
-
id
|
|
611
|
-
body
|
|
612
|
-
isMinimized
|
|
613
|
-
minimizedReason
|
|
614
|
-
author {
|
|
615
|
-
login
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
}
|
|
619
|
-
}
|
|
620
|
-
... on PullRequest {
|
|
621
|
-
comments(last: $last) {
|
|
622
|
-
nodes {
|
|
623
|
-
id
|
|
624
|
-
body
|
|
625
|
-
isMinimized
|
|
626
|
-
minimizedReason
|
|
627
|
-
author {
|
|
628
|
-
login
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
}
|
|
636
|
-
`;
|
|
637
|
-
var MINIMIZE_COMMENT_MUTATION = `
|
|
638
|
-
mutation($id: ID!, $classifier: ReportedContentClassifiers!) {
|
|
639
|
-
minimizeComment(input: { subjectId: $id, classifier: $classifier }) {
|
|
640
|
-
minimizedComment {
|
|
641
|
-
isMinimized
|
|
642
|
-
minimizedReason
|
|
643
|
-
}
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
`;
|
|
647
222
|
function logByStatus2(logger, message, status, metadata) {
|
|
648
223
|
const payload = { ...metadata, ...status ? { status } : {} };
|
|
649
224
|
if (status && status >= 500) return logger.error(message, payload);
|
|
@@ -656,7 +231,6 @@ function logByStatus2(logger, message, status, metadata) {
|
|
|
656
231
|
var CommentHandler = class _CommentHandler {
|
|
657
232
|
static HEADER_NAME = "UbiquityOS";
|
|
658
233
|
_lastCommentId = { reviewCommentId: null, issueCommentId: null };
|
|
659
|
-
_commandResponsePolicyApplied = false;
|
|
660
234
|
async _updateIssueComment(context, params) {
|
|
661
235
|
if (!this._lastCommentId.issueCommentId) {
|
|
662
236
|
throw context.logger.error("issueCommentId is missing");
|
|
@@ -711,11 +285,6 @@ var CommentHandler = class _CommentHandler {
|
|
|
711
285
|
_getCommentId(context) {
|
|
712
286
|
return "pull_request" in context.payload && "comment" in context.payload ? context.payload.comment.id : void 0;
|
|
713
287
|
}
|
|
714
|
-
_getCommentNodeId(context) {
|
|
715
|
-
const payload = context.payload;
|
|
716
|
-
const nodeId = payload.comment?.node_id;
|
|
717
|
-
return typeof nodeId === "string" && nodeId.trim() ? nodeId : null;
|
|
718
|
-
}
|
|
719
288
|
_extractIssueContext(context) {
|
|
720
289
|
if (!("repository" in context.payload) || !context.payload.repository?.owner?.login) {
|
|
721
290
|
return null;
|
|
@@ -729,86 +298,6 @@ var CommentHandler = class _CommentHandler {
|
|
|
729
298
|
repo: context.payload.repository.name
|
|
730
299
|
};
|
|
731
300
|
}
|
|
732
|
-
_extractIssueLocator(context) {
|
|
733
|
-
if (!("issue" in context.payload) && !("pull_request" in context.payload)) {
|
|
734
|
-
return null;
|
|
735
|
-
}
|
|
736
|
-
const issueContext = this._extractIssueContext(context);
|
|
737
|
-
if (!issueContext) return null;
|
|
738
|
-
return {
|
|
739
|
-
owner: issueContext.owner,
|
|
740
|
-
repo: issueContext.repo,
|
|
741
|
-
issueNumber: issueContext.issueNumber
|
|
742
|
-
};
|
|
743
|
-
}
|
|
744
|
-
_shouldApplyCommandResponsePolicy(context) {
|
|
745
|
-
const payload = context;
|
|
746
|
-
return Boolean(payload.command);
|
|
747
|
-
}
|
|
748
|
-
_isCommandResponseComment(body) {
|
|
749
|
-
return typeof body === "string" && body.includes(COMMAND_RESPONSE_MARKER);
|
|
750
|
-
}
|
|
751
|
-
_getGraphqlClient(context) {
|
|
752
|
-
const graphql = context.octokit.graphql;
|
|
753
|
-
return typeof graphql === "function" ? graphql : null;
|
|
754
|
-
}
|
|
755
|
-
async _fetchRecentComments(context, locator, last = COMMAND_RESPONSE_COMMENT_LIMIT) {
|
|
756
|
-
const graphql = this._getGraphqlClient(context);
|
|
757
|
-
if (!graphql) return [];
|
|
758
|
-
try {
|
|
759
|
-
const data = await graphql(RECENT_COMMENTS_QUERY, {
|
|
760
|
-
owner: locator.owner,
|
|
761
|
-
repo: locator.repo,
|
|
762
|
-
number: locator.issueNumber,
|
|
763
|
-
last
|
|
764
|
-
});
|
|
765
|
-
const nodes = data.repository?.issueOrPullRequest?.comments?.nodes ?? [];
|
|
766
|
-
return nodes.filter((node) => Boolean(node));
|
|
767
|
-
} catch (error) {
|
|
768
|
-
context.logger.debug("Failed to fetch recent comments (non-fatal)", { err: error });
|
|
769
|
-
return [];
|
|
770
|
-
}
|
|
771
|
-
}
|
|
772
|
-
_findPreviousCommandResponseComment(comments, currentCommentId) {
|
|
773
|
-
for (let idx = comments.length - 1; idx >= 0; idx -= 1) {
|
|
774
|
-
const comment = comments[idx];
|
|
775
|
-
if (!comment) continue;
|
|
776
|
-
if (currentCommentId && comment.id === currentCommentId) continue;
|
|
777
|
-
if (this._isCommandResponseComment(comment.body)) {
|
|
778
|
-
return comment;
|
|
779
|
-
}
|
|
780
|
-
}
|
|
781
|
-
return null;
|
|
782
|
-
}
|
|
783
|
-
async _minimizeComment(context, commentNodeId, classifier = "RESOLVED") {
|
|
784
|
-
const graphql = this._getGraphqlClient(context);
|
|
785
|
-
if (!graphql) return;
|
|
786
|
-
try {
|
|
787
|
-
await graphql(MINIMIZE_COMMENT_MUTATION, {
|
|
788
|
-
id: commentNodeId,
|
|
789
|
-
classifier
|
|
790
|
-
});
|
|
791
|
-
} catch (error) {
|
|
792
|
-
context.logger.debug("Failed to minimize comment (non-fatal)", { err: error, commentNodeId });
|
|
793
|
-
}
|
|
794
|
-
}
|
|
795
|
-
async _applyCommandResponsePolicy(context) {
|
|
796
|
-
if (this._commandResponsePolicyApplied) return;
|
|
797
|
-
this._commandResponsePolicyApplied = true;
|
|
798
|
-
if (!this._shouldApplyCommandResponsePolicy(context)) return;
|
|
799
|
-
const locator = this._extractIssueLocator(context);
|
|
800
|
-
const commentNodeId = this._getCommentNodeId(context);
|
|
801
|
-
const comments = locator ? await this._fetchRecentComments(context, locator) : [];
|
|
802
|
-
const current = commentNodeId ? comments.find((comment) => comment.id === commentNodeId) : null;
|
|
803
|
-
const currentIsMinimized = current?.isMinimized ?? false;
|
|
804
|
-
if (commentNodeId && !currentIsMinimized) {
|
|
805
|
-
await this._minimizeComment(context, commentNodeId);
|
|
806
|
-
}
|
|
807
|
-
const previous = this._findPreviousCommandResponseComment(comments, commentNodeId);
|
|
808
|
-
if (previous && !previous.isMinimized) {
|
|
809
|
-
await this._minimizeComment(context, previous.id);
|
|
810
|
-
}
|
|
811
|
-
}
|
|
812
301
|
_processMessage(context, message) {
|
|
813
302
|
if (message instanceof Error) {
|
|
814
303
|
const metadata2 = {
|
|
@@ -860,9 +349,7 @@ var CommentHandler = class _CommentHandler {
|
|
|
860
349
|
}
|
|
861
350
|
_createCommentBody(context, message, options) {
|
|
862
351
|
const { metadata, logMessage } = this._processMessage(context, message);
|
|
863
|
-
const
|
|
864
|
-
const metadataWithKind = shouldTagCommandResponse ? { ...metadata, commentKind: options?.commentKind } : metadata;
|
|
865
|
-
const { header, jsonPretty } = this._createMetadataContent(context, metadataWithKind);
|
|
352
|
+
const { header, jsonPretty } = this._createMetadataContent(context, metadata);
|
|
866
353
|
const metadataContent = this._formatMetadataContent(logMessage, header, jsonPretty);
|
|
867
354
|
return `${options?.raw ? logMessage?.raw : logMessage?.diff}
|
|
868
355
|
|
|
@@ -870,17 +357,12 @@ ${metadataContent}
|
|
|
870
357
|
`;
|
|
871
358
|
}
|
|
872
359
|
async postComment(context, message, options = { updateComment: true, raw: false }) {
|
|
873
|
-
await this._applyCommandResponsePolicy(context);
|
|
874
360
|
const issueContext = this._extractIssueContext(context);
|
|
875
361
|
if (!issueContext) {
|
|
876
362
|
context.logger.warn("Cannot post comment: missing issue context in payload");
|
|
877
363
|
return null;
|
|
878
364
|
}
|
|
879
|
-
const
|
|
880
|
-
const body = this._createCommentBody(context, message, {
|
|
881
|
-
...options,
|
|
882
|
-
commentKind: options.commentKind ?? (shouldTagCommandResponse ? COMMAND_RESPONSE_KIND : void 0)
|
|
883
|
-
});
|
|
365
|
+
const body = this._createCommentBody(context, message, options);
|
|
884
366
|
const { issueNumber, commentId, owner, repo } = issueContext;
|
|
885
367
|
const params = { owner, repo, body, issueNumber };
|
|
886
368
|
if (options.updateComment) {
|
|
@@ -927,169 +409,7 @@ function decompressString(compressed) {
|
|
|
927
409
|
|
|
928
410
|
// src/octokit.ts
|
|
929
411
|
import { Octokit } from "@octokit/core";
|
|
930
|
-
|
|
931
|
-
// ../../node_modules/@octokit/plugin-paginate-graphql/dist-bundle/index.js
|
|
932
|
-
var generateMessage = (path, cursorValue) => `The cursor at "${path.join(
|
|
933
|
-
","
|
|
934
|
-
)}" did not change its value "${cursorValue}" after a page transition. Please make sure your that your query is set up correctly.`;
|
|
935
|
-
var MissingCursorChange = class extends Error {
|
|
936
|
-
constructor(pageInfo, cursorValue) {
|
|
937
|
-
super(generateMessage(pageInfo.pathInQuery, cursorValue));
|
|
938
|
-
this.pageInfo = pageInfo;
|
|
939
|
-
this.cursorValue = cursorValue;
|
|
940
|
-
if (Error.captureStackTrace) {
|
|
941
|
-
Error.captureStackTrace(this, this.constructor);
|
|
942
|
-
}
|
|
943
|
-
}
|
|
944
|
-
name = "MissingCursorChangeError";
|
|
945
|
-
};
|
|
946
|
-
var MissingPageInfo = class extends Error {
|
|
947
|
-
constructor(response) {
|
|
948
|
-
super(
|
|
949
|
-
`No pageInfo property found in response. Please make sure to specify the pageInfo in your query. Response-Data: ${JSON.stringify(
|
|
950
|
-
response,
|
|
951
|
-
null,
|
|
952
|
-
2
|
|
953
|
-
)}`
|
|
954
|
-
);
|
|
955
|
-
this.response = response;
|
|
956
|
-
if (Error.captureStackTrace) {
|
|
957
|
-
Error.captureStackTrace(this, this.constructor);
|
|
958
|
-
}
|
|
959
|
-
}
|
|
960
|
-
name = "MissingPageInfo";
|
|
961
|
-
};
|
|
962
|
-
var isObject = (value) => Object.prototype.toString.call(value) === "[object Object]";
|
|
963
|
-
function findPaginatedResourcePath(responseData) {
|
|
964
|
-
const paginatedResourcePath = deepFindPathToProperty(
|
|
965
|
-
responseData,
|
|
966
|
-
"pageInfo"
|
|
967
|
-
);
|
|
968
|
-
if (paginatedResourcePath.length === 0) {
|
|
969
|
-
throw new MissingPageInfo(responseData);
|
|
970
|
-
}
|
|
971
|
-
return paginatedResourcePath;
|
|
972
|
-
}
|
|
973
|
-
var deepFindPathToProperty = (object, searchProp, path = []) => {
|
|
974
|
-
for (const key of Object.keys(object)) {
|
|
975
|
-
const currentPath = [...path, key];
|
|
976
|
-
const currentValue = object[key];
|
|
977
|
-
if (isObject(currentValue)) {
|
|
978
|
-
if (currentValue.hasOwnProperty(searchProp)) {
|
|
979
|
-
return currentPath;
|
|
980
|
-
}
|
|
981
|
-
const result = deepFindPathToProperty(
|
|
982
|
-
currentValue,
|
|
983
|
-
searchProp,
|
|
984
|
-
currentPath
|
|
985
|
-
);
|
|
986
|
-
if (result.length > 0) {
|
|
987
|
-
return result;
|
|
988
|
-
}
|
|
989
|
-
}
|
|
990
|
-
}
|
|
991
|
-
return [];
|
|
992
|
-
};
|
|
993
|
-
var get = (object, path) => {
|
|
994
|
-
return path.reduce((current, nextProperty) => current[nextProperty], object);
|
|
995
|
-
};
|
|
996
|
-
var set = (object, path, mutator) => {
|
|
997
|
-
const lastProperty = path[path.length - 1];
|
|
998
|
-
const parentPath = [...path].slice(0, -1);
|
|
999
|
-
const parent = get(object, parentPath);
|
|
1000
|
-
if (typeof mutator === "function") {
|
|
1001
|
-
parent[lastProperty] = mutator(parent[lastProperty]);
|
|
1002
|
-
} else {
|
|
1003
|
-
parent[lastProperty] = mutator;
|
|
1004
|
-
}
|
|
1005
|
-
};
|
|
1006
|
-
var extractPageInfos = (responseData) => {
|
|
1007
|
-
const pageInfoPath = findPaginatedResourcePath(responseData);
|
|
1008
|
-
return {
|
|
1009
|
-
pathInQuery: pageInfoPath,
|
|
1010
|
-
pageInfo: get(responseData, [...pageInfoPath, "pageInfo"])
|
|
1011
|
-
};
|
|
1012
|
-
};
|
|
1013
|
-
var isForwardSearch = (givenPageInfo) => {
|
|
1014
|
-
return givenPageInfo.hasOwnProperty("hasNextPage");
|
|
1015
|
-
};
|
|
1016
|
-
var getCursorFrom = (pageInfo) => isForwardSearch(pageInfo) ? pageInfo.endCursor : pageInfo.startCursor;
|
|
1017
|
-
var hasAnotherPage = (pageInfo) => isForwardSearch(pageInfo) ? pageInfo.hasNextPage : pageInfo.hasPreviousPage;
|
|
1018
|
-
var createIterator = (octokit) => {
|
|
1019
|
-
return (query, initialParameters = {}) => {
|
|
1020
|
-
let nextPageExists = true;
|
|
1021
|
-
let parameters = { ...initialParameters };
|
|
1022
|
-
return {
|
|
1023
|
-
[Symbol.asyncIterator]: () => ({
|
|
1024
|
-
async next() {
|
|
1025
|
-
if (!nextPageExists) return { done: true, value: {} };
|
|
1026
|
-
const response = await octokit.graphql(
|
|
1027
|
-
query,
|
|
1028
|
-
parameters
|
|
1029
|
-
);
|
|
1030
|
-
const pageInfoContext = extractPageInfos(response);
|
|
1031
|
-
const nextCursorValue = getCursorFrom(pageInfoContext.pageInfo);
|
|
1032
|
-
nextPageExists = hasAnotherPage(pageInfoContext.pageInfo);
|
|
1033
|
-
if (nextPageExists && nextCursorValue === parameters.cursor) {
|
|
1034
|
-
throw new MissingCursorChange(pageInfoContext, nextCursorValue);
|
|
1035
|
-
}
|
|
1036
|
-
parameters = {
|
|
1037
|
-
...parameters,
|
|
1038
|
-
cursor: nextCursorValue
|
|
1039
|
-
};
|
|
1040
|
-
return { done: false, value: response };
|
|
1041
|
-
}
|
|
1042
|
-
})
|
|
1043
|
-
};
|
|
1044
|
-
};
|
|
1045
|
-
};
|
|
1046
|
-
var mergeResponses = (response1, response2) => {
|
|
1047
|
-
if (Object.keys(response1).length === 0) {
|
|
1048
|
-
return Object.assign(response1, response2);
|
|
1049
|
-
}
|
|
1050
|
-
const path = findPaginatedResourcePath(response1);
|
|
1051
|
-
const nodesPath = [...path, "nodes"];
|
|
1052
|
-
const newNodes = get(response2, nodesPath);
|
|
1053
|
-
if (newNodes) {
|
|
1054
|
-
set(response1, nodesPath, (values) => {
|
|
1055
|
-
return [...values, ...newNodes];
|
|
1056
|
-
});
|
|
1057
|
-
}
|
|
1058
|
-
const edgesPath = [...path, "edges"];
|
|
1059
|
-
const newEdges = get(response2, edgesPath);
|
|
1060
|
-
if (newEdges) {
|
|
1061
|
-
set(response1, edgesPath, (values) => {
|
|
1062
|
-
return [...values, ...newEdges];
|
|
1063
|
-
});
|
|
1064
|
-
}
|
|
1065
|
-
const pageInfoPath = [...path, "pageInfo"];
|
|
1066
|
-
set(response1, pageInfoPath, get(response2, pageInfoPath));
|
|
1067
|
-
return response1;
|
|
1068
|
-
};
|
|
1069
|
-
var createPaginate = (octokit) => {
|
|
1070
|
-
const iterator = createIterator(octokit);
|
|
1071
|
-
return async (query, initialParameters = {}) => {
|
|
1072
|
-
let mergedResponse = {};
|
|
1073
|
-
for await (const response of iterator(
|
|
1074
|
-
query,
|
|
1075
|
-
initialParameters
|
|
1076
|
-
)) {
|
|
1077
|
-
mergedResponse = mergeResponses(mergedResponse, response);
|
|
1078
|
-
}
|
|
1079
|
-
return mergedResponse;
|
|
1080
|
-
};
|
|
1081
|
-
};
|
|
1082
|
-
function paginateGraphQL(octokit) {
|
|
1083
|
-
return {
|
|
1084
|
-
graphql: Object.assign(octokit.graphql, {
|
|
1085
|
-
paginate: Object.assign(createPaginate(octokit), {
|
|
1086
|
-
iterator: createIterator(octokit)
|
|
1087
|
-
})
|
|
1088
|
-
})
|
|
1089
|
-
};
|
|
1090
|
-
}
|
|
1091
|
-
|
|
1092
|
-
// src/octokit.ts
|
|
412
|
+
import { paginateGraphQL } from "@octokit/plugin-paginate-graphql";
|
|
1093
413
|
import { paginateRest } from "@octokit/plugin-paginate-rest";
|
|
1094
414
|
import { restEndpointMethods } from "@octokit/plugin-rest-endpoint-methods";
|
|
1095
415
|
import { retry } from "@octokit/plugin-retry";
|
|
@@ -1221,17 +541,17 @@ async function createActionsPlugin(handler, options) {
|
|
|
1221
541
|
} else {
|
|
1222
542
|
config2 = inputs.settings;
|
|
1223
543
|
}
|
|
1224
|
-
let
|
|
544
|
+
let env;
|
|
1225
545
|
if (pluginOptions.envSchema) {
|
|
1226
546
|
try {
|
|
1227
|
-
|
|
547
|
+
env = Value3.Decode(pluginOptions.envSchema, Value3.Default(pluginOptions.envSchema, process.env));
|
|
1228
548
|
} catch (e) {
|
|
1229
549
|
console.dir(...Value3.Errors(pluginOptions.envSchema, process.env), { depth: null });
|
|
1230
550
|
core.setFailed(`Error: Invalid environment provided.`);
|
|
1231
551
|
throw e;
|
|
1232
552
|
}
|
|
1233
553
|
} else {
|
|
1234
|
-
|
|
554
|
+
env = process.env;
|
|
1235
555
|
}
|
|
1236
556
|
const command = getCommand(inputs, pluginOptions);
|
|
1237
557
|
const context = {
|
|
@@ -1242,7 +562,7 @@ async function createActionsPlugin(handler, options) {
|
|
|
1242
562
|
ubiquityKernelToken: inputs.ubiquityKernelToken,
|
|
1243
563
|
octokit: new customOctokit({ auth: inputs.authToken }),
|
|
1244
564
|
config: config2,
|
|
1245
|
-
env
|
|
565
|
+
env,
|
|
1246
566
|
logger: new Logs(pluginOptions.logLevel),
|
|
1247
567
|
commentHandler: new CommentHandler()
|
|
1248
568
|
};
|
|
@@ -1278,12 +598,12 @@ function cleanMarkdown(md, options = {}) {
|
|
|
1278
598
|
const segments = [];
|
|
1279
599
|
let lastIndex = 0;
|
|
1280
600
|
const matches = [...md.matchAll(codeBlockRegex)];
|
|
1281
|
-
for (const
|
|
1282
|
-
if (
|
|
1283
|
-
segments.push(processSegment(md.slice(lastIndex,
|
|
601
|
+
for (const match of matches) {
|
|
602
|
+
if (match.index > lastIndex) {
|
|
603
|
+
segments.push(processSegment(md.slice(lastIndex, match.index), tags, shouldCollapseEmptyLines));
|
|
1284
604
|
}
|
|
1285
|
-
segments.push(
|
|
1286
|
-
lastIndex =
|
|
605
|
+
segments.push(match[0]);
|
|
606
|
+
lastIndex = match.index + match[0].length;
|
|
1287
607
|
}
|
|
1288
608
|
if (lastIndex < md.length) {
|
|
1289
609
|
segments.push(processSegment(md.slice(lastIndex), tags, shouldCollapseEmptyLines));
|
|
@@ -1298,9 +618,9 @@ function processSegment(segment, extraTags, shouldCollapseEmptyLines) {
|
|
|
1298
618
|
return `__INLINE_CODE_${inlineCodes.length - 1}__`;
|
|
1299
619
|
});
|
|
1300
620
|
s = s.replace(/<!--[\s\S]*?-->/g, "");
|
|
1301
|
-
for (const
|
|
1302
|
-
if (!
|
|
1303
|
-
const tag =
|
|
621
|
+
for (const raw of extraTags) {
|
|
622
|
+
if (!raw) continue;
|
|
623
|
+
const tag = raw.toLowerCase().trim().replace(/[^\w:-]/g, "");
|
|
1304
624
|
if (!tag) continue;
|
|
1305
625
|
if (VOID_TAGS.has(tag)) {
|
|
1306
626
|
const voidRe = new RegExp(`<${tag}\\b[^>]*\\/?>`, "gi");
|
|
@@ -1325,2125 +645,64 @@ function processSegment(segment, extraTags, shouldCollapseEmptyLines) {
|
|
|
1325
645
|
|
|
1326
646
|
// src/server.ts
|
|
1327
647
|
import { Value as Value4 } from "@sinclair/typebox/value";
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
}
|
|
1338
|
-
index = i;
|
|
1339
|
-
let res;
|
|
1340
|
-
let isError = false;
|
|
1341
|
-
let handler;
|
|
1342
|
-
if (middleware[i]) {
|
|
1343
|
-
handler = middleware[i][0][0];
|
|
1344
|
-
context.req.routeIndex = i;
|
|
1345
|
-
} else {
|
|
1346
|
-
handler = i === middleware.length && next || void 0;
|
|
1347
|
-
}
|
|
1348
|
-
if (handler) {
|
|
1349
|
-
try {
|
|
1350
|
-
res = await handler(context, () => dispatch(i + 1));
|
|
1351
|
-
} catch (err) {
|
|
1352
|
-
if (err instanceof Error && onError) {
|
|
1353
|
-
context.error = err;
|
|
1354
|
-
res = await onError(err, context);
|
|
1355
|
-
isError = true;
|
|
1356
|
-
} else {
|
|
1357
|
-
throw err;
|
|
1358
|
-
}
|
|
1359
|
-
}
|
|
1360
|
-
} else {
|
|
1361
|
-
if (context.finalized === false && onNotFound) {
|
|
1362
|
-
res = await onNotFound(context);
|
|
1363
|
-
}
|
|
1364
|
-
}
|
|
1365
|
-
if (res && (context.finalized === false || isError)) {
|
|
1366
|
-
context.res = res;
|
|
1367
|
-
}
|
|
1368
|
-
return context;
|
|
1369
|
-
}
|
|
1370
|
-
};
|
|
1371
|
-
};
|
|
1372
|
-
|
|
1373
|
-
// ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/http-exception.js
|
|
1374
|
-
var HTTPException = class extends Error {
|
|
1375
|
-
res;
|
|
1376
|
-
status;
|
|
1377
|
-
/**
|
|
1378
|
-
* Creates an instance of `HTTPException`.
|
|
1379
|
-
* @param status - HTTP status code for the exception. Defaults to 500.
|
|
1380
|
-
* @param options - Additional options for the exception.
|
|
1381
|
-
*/
|
|
1382
|
-
constructor(status = 500, options) {
|
|
1383
|
-
super(options?.message, { cause: options?.cause });
|
|
1384
|
-
this.res = options?.res;
|
|
1385
|
-
this.status = status;
|
|
1386
|
-
}
|
|
1387
|
-
/**
|
|
1388
|
-
* Returns the response object associated with the exception.
|
|
1389
|
-
* If a response object is not provided, a new response is created with the error message and status code.
|
|
1390
|
-
* @returns The response object.
|
|
1391
|
-
*/
|
|
1392
|
-
getResponse() {
|
|
1393
|
-
if (this.res) {
|
|
1394
|
-
const newResponse = new Response(this.res.body, {
|
|
1395
|
-
status: this.status,
|
|
1396
|
-
headers: this.res.headers
|
|
1397
|
-
});
|
|
1398
|
-
return newResponse;
|
|
1399
|
-
}
|
|
1400
|
-
return new Response(this.message, {
|
|
1401
|
-
status: this.status
|
|
1402
|
-
});
|
|
1403
|
-
}
|
|
1404
|
-
};
|
|
1405
|
-
|
|
1406
|
-
// ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/request/constants.js
|
|
1407
|
-
var GET_MATCH_RESULT = /* @__PURE__ */ Symbol();
|
|
1408
|
-
|
|
1409
|
-
// ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/utils/body.js
|
|
1410
|
-
var parseBody = async (request, options = /* @__PURE__ */ Object.create(null)) => {
|
|
1411
|
-
const { all = false, dot = false } = options;
|
|
1412
|
-
const headers = request instanceof HonoRequest ? request.raw.headers : request.headers;
|
|
1413
|
-
const contentType = headers.get("Content-Type");
|
|
1414
|
-
if (contentType?.startsWith("multipart/form-data") || contentType?.startsWith("application/x-www-form-urlencoded")) {
|
|
1415
|
-
return parseFormData(request, { all, dot });
|
|
1416
|
-
}
|
|
1417
|
-
return {};
|
|
1418
|
-
};
|
|
1419
|
-
async function parseFormData(request, options) {
|
|
1420
|
-
const formData = await request.formData();
|
|
1421
|
-
if (formData) {
|
|
1422
|
-
return convertFormDataToBodyData(formData, options);
|
|
648
|
+
import { Logs as Logs2 } from "@ubiquity-os/ubiquity-os-logger";
|
|
649
|
+
import { Hono } from "hono";
|
|
650
|
+
import { env as honoEnv } from "hono/adapter";
|
|
651
|
+
import { HTTPException } from "hono/http-exception";
|
|
652
|
+
async function handleError2(context, pluginOptions, error) {
|
|
653
|
+
console.error(error);
|
|
654
|
+
const loggerError = transformError(context, error);
|
|
655
|
+
if (pluginOptions.postCommentOnError && loggerError) {
|
|
656
|
+
await context.commentHandler.postComment(context, loggerError);
|
|
1423
657
|
}
|
|
1424
|
-
|
|
658
|
+
throw new HTTPException(500, { message: "Unexpected error" });
|
|
1425
659
|
}
|
|
1426
|
-
function
|
|
1427
|
-
const
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
form[key] = value;
|
|
1432
|
-
} else {
|
|
1433
|
-
handleParsingAllValues(form, key, value);
|
|
1434
|
-
}
|
|
660
|
+
function createPlugin(handler, manifest, options) {
|
|
661
|
+
const pluginOptions = getPluginOptions(options);
|
|
662
|
+
const app = new Hono();
|
|
663
|
+
app.get("/manifest.json", (ctx) => {
|
|
664
|
+
return ctx.json(manifest);
|
|
1435
665
|
});
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
if (shouldParseDotValues) {
|
|
1440
|
-
handleParsingNestedValues(form, key, value);
|
|
1441
|
-
delete form[key];
|
|
1442
|
-
}
|
|
1443
|
-
});
|
|
1444
|
-
}
|
|
1445
|
-
return form;
|
|
1446
|
-
}
|
|
1447
|
-
var handleParsingAllValues = (form, key, value) => {
|
|
1448
|
-
if (form[key] !== void 0) {
|
|
1449
|
-
if (Array.isArray(form[key])) {
|
|
1450
|
-
;
|
|
1451
|
-
form[key].push(value);
|
|
1452
|
-
} else {
|
|
1453
|
-
form[key] = [form[key], value];
|
|
1454
|
-
}
|
|
1455
|
-
} else {
|
|
1456
|
-
if (!key.endsWith("[]")) {
|
|
1457
|
-
form[key] = value;
|
|
1458
|
-
} else {
|
|
1459
|
-
form[key] = [value];
|
|
666
|
+
app.post("/", async function appPost(ctx) {
|
|
667
|
+
if (ctx.req.header("content-type") !== "application/json") {
|
|
668
|
+
throw new HTTPException(400, { message: "Content-Type must be application/json" });
|
|
1460
669
|
}
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
keys.forEach((key2, index) => {
|
|
1467
|
-
if (index === keys.length - 1) {
|
|
1468
|
-
nestedForm[key2] = value;
|
|
1469
|
-
} else {
|
|
1470
|
-
if (!nestedForm[key2] || typeof nestedForm[key2] !== "object" || Array.isArray(nestedForm[key2]) || nestedForm[key2] instanceof File) {
|
|
1471
|
-
nestedForm[key2] = /* @__PURE__ */ Object.create(null);
|
|
1472
|
-
}
|
|
1473
|
-
nestedForm = nestedForm[key2];
|
|
670
|
+
const body = await ctx.req.json();
|
|
671
|
+
const inputSchemaErrors = [...Value4.Errors(inputSchema, body)];
|
|
672
|
+
if (inputSchemaErrors.length) {
|
|
673
|
+
console.dir(inputSchemaErrors, { depth: null });
|
|
674
|
+
throw new HTTPException(400, { message: "Invalid body" });
|
|
1474
675
|
}
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
// ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/utils/url.js
|
|
1479
|
-
var splitPath = (path) => {
|
|
1480
|
-
const paths = path.split("/");
|
|
1481
|
-
if (paths[0] === "") {
|
|
1482
|
-
paths.shift();
|
|
1483
|
-
}
|
|
1484
|
-
return paths;
|
|
1485
|
-
};
|
|
1486
|
-
var splitRoutingPath = (routePath) => {
|
|
1487
|
-
const { groups, path } = extractGroupsFromPath(routePath);
|
|
1488
|
-
const paths = splitPath(path);
|
|
1489
|
-
return replaceGroupMarks(paths, groups);
|
|
1490
|
-
};
|
|
1491
|
-
var extractGroupsFromPath = (path) => {
|
|
1492
|
-
const groups = [];
|
|
1493
|
-
path = path.replace(/\{[^}]+\}/g, (match2, index) => {
|
|
1494
|
-
const mark = `@${index}`;
|
|
1495
|
-
groups.push([mark, match2]);
|
|
1496
|
-
return mark;
|
|
1497
|
-
});
|
|
1498
|
-
return { groups, path };
|
|
1499
|
-
};
|
|
1500
|
-
var replaceGroupMarks = (paths, groups) => {
|
|
1501
|
-
for (let i = groups.length - 1; i >= 0; i--) {
|
|
1502
|
-
const [mark] = groups[i];
|
|
1503
|
-
for (let j = paths.length - 1; j >= 0; j--) {
|
|
1504
|
-
if (paths[j].includes(mark)) {
|
|
1505
|
-
paths[j] = paths[j].replace(mark, groups[i][1]);
|
|
1506
|
-
break;
|
|
1507
|
-
}
|
|
676
|
+
const signature = body.signature;
|
|
677
|
+
if (!pluginOptions.bypassSignatureVerification && !await verifySignature(pluginOptions.kernelPublicKey, body, signature)) {
|
|
678
|
+
throw new HTTPException(400, { message: "Invalid signature" });
|
|
1508
679
|
}
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
const match2 = label.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
|
|
1518
|
-
if (match2) {
|
|
1519
|
-
const cacheKey = `${label}#${next}`;
|
|
1520
|
-
if (!patternCache[cacheKey]) {
|
|
1521
|
-
if (match2[2]) {
|
|
1522
|
-
patternCache[cacheKey] = next && next[0] !== ":" && next[0] !== "*" ? [cacheKey, match2[1], new RegExp(`^${match2[2]}(?=/${next})`)] : [label, match2[1], new RegExp(`^${match2[2]}$`)];
|
|
1523
|
-
} else {
|
|
1524
|
-
patternCache[cacheKey] = [label, match2[1], true];
|
|
680
|
+
const inputs = Value4.Decode(inputSchema, body);
|
|
681
|
+
let config2;
|
|
682
|
+
if (pluginOptions.settingsSchema) {
|
|
683
|
+
try {
|
|
684
|
+
config2 = Value4.Decode(pluginOptions.settingsSchema, Value4.Default(pluginOptions.settingsSchema, inputs.settings));
|
|
685
|
+
} catch (e) {
|
|
686
|
+
console.dir(...Value4.Errors(pluginOptions.settingsSchema, inputs.settings), { depth: null });
|
|
687
|
+
throw e;
|
|
1525
688
|
}
|
|
689
|
+
} else {
|
|
690
|
+
config2 = inputs.settings;
|
|
1526
691
|
}
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
};
|
|
1531
|
-
var tryDecode = (str, decoder) => {
|
|
1532
|
-
try {
|
|
1533
|
-
return decoder(str);
|
|
1534
|
-
} catch {
|
|
1535
|
-
return str.replace(/(?:%[0-9A-Fa-f]{2})+/g, (match2) => {
|
|
692
|
+
let env;
|
|
693
|
+
const honoEnvironment = honoEnv(ctx);
|
|
694
|
+
if (pluginOptions.envSchema) {
|
|
1536
695
|
try {
|
|
1537
|
-
|
|
1538
|
-
} catch {
|
|
1539
|
-
|
|
696
|
+
env = Value4.Decode(pluginOptions.envSchema, Value4.Default(pluginOptions.envSchema, honoEnvironment));
|
|
697
|
+
} catch (e) {
|
|
698
|
+
console.dir(...Value4.Errors(pluginOptions.envSchema, honoEnvironment), { depth: null });
|
|
699
|
+
throw e;
|
|
1540
700
|
}
|
|
1541
|
-
}
|
|
1542
|
-
|
|
1543
|
-
};
|
|
1544
|
-
var tryDecodeURI = (str) => tryDecode(str, decodeURI);
|
|
1545
|
-
var getPath = (request) => {
|
|
1546
|
-
const url = request.url;
|
|
1547
|
-
const start = url.indexOf("/", url.indexOf(":") + 4);
|
|
1548
|
-
let i = start;
|
|
1549
|
-
for (; i < url.length; i++) {
|
|
1550
|
-
const charCode = url.charCodeAt(i);
|
|
1551
|
-
if (charCode === 37) {
|
|
1552
|
-
const queryIndex = url.indexOf("?", i);
|
|
1553
|
-
const path = url.slice(start, queryIndex === -1 ? void 0 : queryIndex);
|
|
1554
|
-
return tryDecodeURI(path.includes("%25") ? path.replace(/%25/g, "%2525") : path);
|
|
1555
|
-
} else if (charCode === 63) {
|
|
1556
|
-
break;
|
|
1557
|
-
}
|
|
1558
|
-
}
|
|
1559
|
-
return url.slice(start, i);
|
|
1560
|
-
};
|
|
1561
|
-
var getPathNoStrict = (request) => {
|
|
1562
|
-
const result = getPath(request);
|
|
1563
|
-
return result.length > 1 && result.at(-1) === "/" ? result.slice(0, -1) : result;
|
|
1564
|
-
};
|
|
1565
|
-
var mergePath = (base, sub, ...rest) => {
|
|
1566
|
-
if (rest.length) {
|
|
1567
|
-
sub = mergePath(sub, ...rest);
|
|
1568
|
-
}
|
|
1569
|
-
return `${base?.[0] === "/" ? "" : "/"}${base}${sub === "/" ? "" : `${base?.at(-1) === "/" ? "" : "/"}${sub?.[0] === "/" ? sub.slice(1) : sub}`}`;
|
|
1570
|
-
};
|
|
1571
|
-
var checkOptionalParameter = (path) => {
|
|
1572
|
-
if (path.charCodeAt(path.length - 1) !== 63 || !path.includes(":")) {
|
|
1573
|
-
return null;
|
|
1574
|
-
}
|
|
1575
|
-
const segments = path.split("/");
|
|
1576
|
-
const results = [];
|
|
1577
|
-
let basePath = "";
|
|
1578
|
-
segments.forEach((segment) => {
|
|
1579
|
-
if (segment !== "" && !/\:/.test(segment)) {
|
|
1580
|
-
basePath += "/" + segment;
|
|
1581
|
-
} else if (/\:/.test(segment)) {
|
|
1582
|
-
if (/\?/.test(segment)) {
|
|
1583
|
-
if (results.length === 0 && basePath === "") {
|
|
1584
|
-
results.push("/");
|
|
1585
|
-
} else {
|
|
1586
|
-
results.push(basePath);
|
|
1587
|
-
}
|
|
1588
|
-
const optionalSegment = segment.replace("?", "");
|
|
1589
|
-
basePath += "/" + optionalSegment;
|
|
1590
|
-
results.push(basePath);
|
|
1591
|
-
} else {
|
|
1592
|
-
basePath += "/" + segment;
|
|
1593
|
-
}
|
|
1594
|
-
}
|
|
1595
|
-
});
|
|
1596
|
-
return results.filter((v, i, a) => a.indexOf(v) === i);
|
|
1597
|
-
};
|
|
1598
|
-
var _decodeURI = (value) => {
|
|
1599
|
-
if (!/[%+]/.test(value)) {
|
|
1600
|
-
return value;
|
|
1601
|
-
}
|
|
1602
|
-
if (value.indexOf("+") !== -1) {
|
|
1603
|
-
value = value.replace(/\+/g, " ");
|
|
1604
|
-
}
|
|
1605
|
-
return value.indexOf("%") !== -1 ? tryDecode(value, decodeURIComponent_) : value;
|
|
1606
|
-
};
|
|
1607
|
-
var _getQueryParam = (url, key, multiple) => {
|
|
1608
|
-
let encoded;
|
|
1609
|
-
if (!multiple && key && !/[%+]/.test(key)) {
|
|
1610
|
-
let keyIndex2 = url.indexOf("?", 8);
|
|
1611
|
-
if (keyIndex2 === -1) {
|
|
1612
|
-
return void 0;
|
|
1613
|
-
}
|
|
1614
|
-
if (!url.startsWith(key, keyIndex2 + 1)) {
|
|
1615
|
-
keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1);
|
|
1616
|
-
}
|
|
1617
|
-
while (keyIndex2 !== -1) {
|
|
1618
|
-
const trailingKeyCode = url.charCodeAt(keyIndex2 + key.length + 1);
|
|
1619
|
-
if (trailingKeyCode === 61) {
|
|
1620
|
-
const valueIndex = keyIndex2 + key.length + 2;
|
|
1621
|
-
const endIndex = url.indexOf("&", valueIndex);
|
|
1622
|
-
return _decodeURI(url.slice(valueIndex, endIndex === -1 ? void 0 : endIndex));
|
|
1623
|
-
} else if (trailingKeyCode == 38 || isNaN(trailingKeyCode)) {
|
|
1624
|
-
return "";
|
|
1625
|
-
}
|
|
1626
|
-
keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1);
|
|
1627
|
-
}
|
|
1628
|
-
encoded = /[%+]/.test(url);
|
|
1629
|
-
if (!encoded) {
|
|
1630
|
-
return void 0;
|
|
1631
|
-
}
|
|
1632
|
-
}
|
|
1633
|
-
const results = {};
|
|
1634
|
-
encoded ??= /[%+]/.test(url);
|
|
1635
|
-
let keyIndex = url.indexOf("?", 8);
|
|
1636
|
-
while (keyIndex !== -1) {
|
|
1637
|
-
const nextKeyIndex = url.indexOf("&", keyIndex + 1);
|
|
1638
|
-
let valueIndex = url.indexOf("=", keyIndex);
|
|
1639
|
-
if (valueIndex > nextKeyIndex && nextKeyIndex !== -1) {
|
|
1640
|
-
valueIndex = -1;
|
|
1641
|
-
}
|
|
1642
|
-
let name = url.slice(
|
|
1643
|
-
keyIndex + 1,
|
|
1644
|
-
valueIndex === -1 ? nextKeyIndex === -1 ? void 0 : nextKeyIndex : valueIndex
|
|
1645
|
-
);
|
|
1646
|
-
if (encoded) {
|
|
1647
|
-
name = _decodeURI(name);
|
|
1648
|
-
}
|
|
1649
|
-
keyIndex = nextKeyIndex;
|
|
1650
|
-
if (name === "") {
|
|
1651
|
-
continue;
|
|
1652
|
-
}
|
|
1653
|
-
let value;
|
|
1654
|
-
if (valueIndex === -1) {
|
|
1655
|
-
value = "";
|
|
1656
|
-
} else {
|
|
1657
|
-
value = url.slice(valueIndex + 1, nextKeyIndex === -1 ? void 0 : nextKeyIndex);
|
|
1658
|
-
if (encoded) {
|
|
1659
|
-
value = _decodeURI(value);
|
|
1660
|
-
}
|
|
1661
|
-
}
|
|
1662
|
-
if (multiple) {
|
|
1663
|
-
if (!(results[name] && Array.isArray(results[name]))) {
|
|
1664
|
-
results[name] = [];
|
|
1665
|
-
}
|
|
1666
|
-
;
|
|
1667
|
-
results[name].push(value);
|
|
1668
|
-
} else {
|
|
1669
|
-
results[name] ??= value;
|
|
1670
|
-
}
|
|
1671
|
-
}
|
|
1672
|
-
return key ? results[key] : results;
|
|
1673
|
-
};
|
|
1674
|
-
var getQueryParam = _getQueryParam;
|
|
1675
|
-
var getQueryParams = (url, key) => {
|
|
1676
|
-
return _getQueryParam(url, key, true);
|
|
1677
|
-
};
|
|
1678
|
-
var decodeURIComponent_ = decodeURIComponent;
|
|
1679
|
-
|
|
1680
|
-
// ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/request.js
|
|
1681
|
-
var tryDecodeURIComponent = (str) => tryDecode(str, decodeURIComponent_);
|
|
1682
|
-
var HonoRequest = class {
|
|
1683
|
-
/**
|
|
1684
|
-
* `.raw` can get the raw Request object.
|
|
1685
|
-
*
|
|
1686
|
-
* @see {@link https://hono.dev/docs/api/request#raw}
|
|
1687
|
-
*
|
|
1688
|
-
* @example
|
|
1689
|
-
* ```ts
|
|
1690
|
-
* // For Cloudflare Workers
|
|
1691
|
-
* app.post('/', async (c) => {
|
|
1692
|
-
* const metadata = c.req.raw.cf?.hostMetadata?
|
|
1693
|
-
* ...
|
|
1694
|
-
* })
|
|
1695
|
-
* ```
|
|
1696
|
-
*/
|
|
1697
|
-
raw;
|
|
1698
|
-
#validatedData;
|
|
1699
|
-
// Short name of validatedData
|
|
1700
|
-
#matchResult;
|
|
1701
|
-
routeIndex = 0;
|
|
1702
|
-
/**
|
|
1703
|
-
* `.path` can get the pathname of the request.
|
|
1704
|
-
*
|
|
1705
|
-
* @see {@link https://hono.dev/docs/api/request#path}
|
|
1706
|
-
*
|
|
1707
|
-
* @example
|
|
1708
|
-
* ```ts
|
|
1709
|
-
* app.get('/about/me', (c) => {
|
|
1710
|
-
* const pathname = c.req.path // `/about/me`
|
|
1711
|
-
* })
|
|
1712
|
-
* ```
|
|
1713
|
-
*/
|
|
1714
|
-
path;
|
|
1715
|
-
bodyCache = {};
|
|
1716
|
-
constructor(request, path = "/", matchResult = [[]]) {
|
|
1717
|
-
this.raw = request;
|
|
1718
|
-
this.path = path;
|
|
1719
|
-
this.#matchResult = matchResult;
|
|
1720
|
-
this.#validatedData = {};
|
|
1721
|
-
}
|
|
1722
|
-
param(key) {
|
|
1723
|
-
return key ? this.#getDecodedParam(key) : this.#getAllDecodedParams();
|
|
1724
|
-
}
|
|
1725
|
-
#getDecodedParam(key) {
|
|
1726
|
-
const paramKey = this.#matchResult[0][this.routeIndex][1][key];
|
|
1727
|
-
const param = this.#getParamValue(paramKey);
|
|
1728
|
-
return param && /\%/.test(param) ? tryDecodeURIComponent(param) : param;
|
|
1729
|
-
}
|
|
1730
|
-
#getAllDecodedParams() {
|
|
1731
|
-
const decoded = {};
|
|
1732
|
-
const keys = Object.keys(this.#matchResult[0][this.routeIndex][1]);
|
|
1733
|
-
for (const key of keys) {
|
|
1734
|
-
const value = this.#getParamValue(this.#matchResult[0][this.routeIndex][1][key]);
|
|
1735
|
-
if (value !== void 0) {
|
|
1736
|
-
decoded[key] = /\%/.test(value) ? tryDecodeURIComponent(value) : value;
|
|
1737
|
-
}
|
|
1738
|
-
}
|
|
1739
|
-
return decoded;
|
|
1740
|
-
}
|
|
1741
|
-
#getParamValue(paramKey) {
|
|
1742
|
-
return this.#matchResult[1] ? this.#matchResult[1][paramKey] : paramKey;
|
|
1743
|
-
}
|
|
1744
|
-
query(key) {
|
|
1745
|
-
return getQueryParam(this.url, key);
|
|
1746
|
-
}
|
|
1747
|
-
queries(key) {
|
|
1748
|
-
return getQueryParams(this.url, key);
|
|
1749
|
-
}
|
|
1750
|
-
header(name) {
|
|
1751
|
-
if (name) {
|
|
1752
|
-
return this.raw.headers.get(name) ?? void 0;
|
|
1753
|
-
}
|
|
1754
|
-
const headerData = {};
|
|
1755
|
-
this.raw.headers.forEach((value, key) => {
|
|
1756
|
-
headerData[key] = value;
|
|
1757
|
-
});
|
|
1758
|
-
return headerData;
|
|
1759
|
-
}
|
|
1760
|
-
async parseBody(options) {
|
|
1761
|
-
return this.bodyCache.parsedBody ??= await parseBody(this, options);
|
|
1762
|
-
}
|
|
1763
|
-
#cachedBody = (key) => {
|
|
1764
|
-
const { bodyCache, raw: raw2 } = this;
|
|
1765
|
-
const cachedBody = bodyCache[key];
|
|
1766
|
-
if (cachedBody) {
|
|
1767
|
-
return cachedBody;
|
|
1768
|
-
}
|
|
1769
|
-
const anyCachedKey = Object.keys(bodyCache)[0];
|
|
1770
|
-
if (anyCachedKey) {
|
|
1771
|
-
return bodyCache[anyCachedKey].then((body) => {
|
|
1772
|
-
if (anyCachedKey === "json") {
|
|
1773
|
-
body = JSON.stringify(body);
|
|
1774
|
-
}
|
|
1775
|
-
return new Response(body)[key]();
|
|
1776
|
-
});
|
|
1777
|
-
}
|
|
1778
|
-
return bodyCache[key] = raw2[key]();
|
|
1779
|
-
};
|
|
1780
|
-
/**
|
|
1781
|
-
* `.json()` can parse Request body of type `application/json`
|
|
1782
|
-
*
|
|
1783
|
-
* @see {@link https://hono.dev/docs/api/request#json}
|
|
1784
|
-
*
|
|
1785
|
-
* @example
|
|
1786
|
-
* ```ts
|
|
1787
|
-
* app.post('/entry', async (c) => {
|
|
1788
|
-
* const body = await c.req.json()
|
|
1789
|
-
* })
|
|
1790
|
-
* ```
|
|
1791
|
-
*/
|
|
1792
|
-
json() {
|
|
1793
|
-
return this.#cachedBody("text").then((text) => JSON.parse(text));
|
|
1794
|
-
}
|
|
1795
|
-
/**
|
|
1796
|
-
* `.text()` can parse Request body of type `text/plain`
|
|
1797
|
-
*
|
|
1798
|
-
* @see {@link https://hono.dev/docs/api/request#text}
|
|
1799
|
-
*
|
|
1800
|
-
* @example
|
|
1801
|
-
* ```ts
|
|
1802
|
-
* app.post('/entry', async (c) => {
|
|
1803
|
-
* const body = await c.req.text()
|
|
1804
|
-
* })
|
|
1805
|
-
* ```
|
|
1806
|
-
*/
|
|
1807
|
-
text() {
|
|
1808
|
-
return this.#cachedBody("text");
|
|
1809
|
-
}
|
|
1810
|
-
/**
|
|
1811
|
-
* `.arrayBuffer()` parse Request body as an `ArrayBuffer`
|
|
1812
|
-
*
|
|
1813
|
-
* @see {@link https://hono.dev/docs/api/request#arraybuffer}
|
|
1814
|
-
*
|
|
1815
|
-
* @example
|
|
1816
|
-
* ```ts
|
|
1817
|
-
* app.post('/entry', async (c) => {
|
|
1818
|
-
* const body = await c.req.arrayBuffer()
|
|
1819
|
-
* })
|
|
1820
|
-
* ```
|
|
1821
|
-
*/
|
|
1822
|
-
arrayBuffer() {
|
|
1823
|
-
return this.#cachedBody("arrayBuffer");
|
|
1824
|
-
}
|
|
1825
|
-
/**
|
|
1826
|
-
* Parses the request body as a `Blob`.
|
|
1827
|
-
* @example
|
|
1828
|
-
* ```ts
|
|
1829
|
-
* app.post('/entry', async (c) => {
|
|
1830
|
-
* const body = await c.req.blob();
|
|
1831
|
-
* });
|
|
1832
|
-
* ```
|
|
1833
|
-
* @see https://hono.dev/docs/api/request#blob
|
|
1834
|
-
*/
|
|
1835
|
-
blob() {
|
|
1836
|
-
return this.#cachedBody("blob");
|
|
1837
|
-
}
|
|
1838
|
-
/**
|
|
1839
|
-
* Parses the request body as `FormData`.
|
|
1840
|
-
* @example
|
|
1841
|
-
* ```ts
|
|
1842
|
-
* app.post('/entry', async (c) => {
|
|
1843
|
-
* const body = await c.req.formData();
|
|
1844
|
-
* });
|
|
1845
|
-
* ```
|
|
1846
|
-
* @see https://hono.dev/docs/api/request#formdata
|
|
1847
|
-
*/
|
|
1848
|
-
formData() {
|
|
1849
|
-
return this.#cachedBody("formData");
|
|
1850
|
-
}
|
|
1851
|
-
/**
|
|
1852
|
-
* Adds validated data to the request.
|
|
1853
|
-
*
|
|
1854
|
-
* @param target - The target of the validation.
|
|
1855
|
-
* @param data - The validated data to add.
|
|
1856
|
-
*/
|
|
1857
|
-
addValidatedData(target, data) {
|
|
1858
|
-
this.#validatedData[target] = data;
|
|
1859
|
-
}
|
|
1860
|
-
valid(target) {
|
|
1861
|
-
return this.#validatedData[target];
|
|
1862
|
-
}
|
|
1863
|
-
/**
|
|
1864
|
-
* `.url()` can get the request url strings.
|
|
1865
|
-
*
|
|
1866
|
-
* @see {@link https://hono.dev/docs/api/request#url}
|
|
1867
|
-
*
|
|
1868
|
-
* @example
|
|
1869
|
-
* ```ts
|
|
1870
|
-
* app.get('/about/me', (c) => {
|
|
1871
|
-
* const url = c.req.url // `http://localhost:8787/about/me`
|
|
1872
|
-
* ...
|
|
1873
|
-
* })
|
|
1874
|
-
* ```
|
|
1875
|
-
*/
|
|
1876
|
-
get url() {
|
|
1877
|
-
return this.raw.url;
|
|
1878
|
-
}
|
|
1879
|
-
/**
|
|
1880
|
-
* `.method()` can get the method name of the request.
|
|
1881
|
-
*
|
|
1882
|
-
* @see {@link https://hono.dev/docs/api/request#method}
|
|
1883
|
-
*
|
|
1884
|
-
* @example
|
|
1885
|
-
* ```ts
|
|
1886
|
-
* app.get('/about/me', (c) => {
|
|
1887
|
-
* const method = c.req.method // `GET`
|
|
1888
|
-
* })
|
|
1889
|
-
* ```
|
|
1890
|
-
*/
|
|
1891
|
-
get method() {
|
|
1892
|
-
return this.raw.method;
|
|
1893
|
-
}
|
|
1894
|
-
get [GET_MATCH_RESULT]() {
|
|
1895
|
-
return this.#matchResult;
|
|
1896
|
-
}
|
|
1897
|
-
/**
|
|
1898
|
-
* `.matchedRoutes()` can return a matched route in the handler
|
|
1899
|
-
*
|
|
1900
|
-
* @deprecated
|
|
1901
|
-
*
|
|
1902
|
-
* Use matchedRoutes helper defined in "hono/route" instead.
|
|
1903
|
-
*
|
|
1904
|
-
* @see {@link https://hono.dev/docs/api/request#matchedroutes}
|
|
1905
|
-
*
|
|
1906
|
-
* @example
|
|
1907
|
-
* ```ts
|
|
1908
|
-
* app.use('*', async function logger(c, next) {
|
|
1909
|
-
* await next()
|
|
1910
|
-
* c.req.matchedRoutes.forEach(({ handler, method, path }, i) => {
|
|
1911
|
-
* const name = handler.name || (handler.length < 2 ? '[handler]' : '[middleware]')
|
|
1912
|
-
* console.log(
|
|
1913
|
-
* method,
|
|
1914
|
-
* ' ',
|
|
1915
|
-
* path,
|
|
1916
|
-
* ' '.repeat(Math.max(10 - path.length, 0)),
|
|
1917
|
-
* name,
|
|
1918
|
-
* i === c.req.routeIndex ? '<- respond from here' : ''
|
|
1919
|
-
* )
|
|
1920
|
-
* })
|
|
1921
|
-
* })
|
|
1922
|
-
* ```
|
|
1923
|
-
*/
|
|
1924
|
-
get matchedRoutes() {
|
|
1925
|
-
return this.#matchResult[0].map(([[, route]]) => route);
|
|
1926
|
-
}
|
|
1927
|
-
/**
|
|
1928
|
-
* `routePath()` can retrieve the path registered within the handler
|
|
1929
|
-
*
|
|
1930
|
-
* @deprecated
|
|
1931
|
-
*
|
|
1932
|
-
* Use routePath helper defined in "hono/route" instead.
|
|
1933
|
-
*
|
|
1934
|
-
* @see {@link https://hono.dev/docs/api/request#routepath}
|
|
1935
|
-
*
|
|
1936
|
-
* @example
|
|
1937
|
-
* ```ts
|
|
1938
|
-
* app.get('/posts/:id', (c) => {
|
|
1939
|
-
* return c.json({ path: c.req.routePath })
|
|
1940
|
-
* })
|
|
1941
|
-
* ```
|
|
1942
|
-
*/
|
|
1943
|
-
get routePath() {
|
|
1944
|
-
return this.#matchResult[0].map(([[, route]]) => route)[this.routeIndex].path;
|
|
1945
|
-
}
|
|
1946
|
-
};
|
|
1947
|
-
|
|
1948
|
-
// ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/utils/html.js
|
|
1949
|
-
var HtmlEscapedCallbackPhase = {
|
|
1950
|
-
Stringify: 1,
|
|
1951
|
-
BeforeStream: 2,
|
|
1952
|
-
Stream: 3
|
|
1953
|
-
};
|
|
1954
|
-
var raw = (value, callbacks) => {
|
|
1955
|
-
const escapedString = new String(value);
|
|
1956
|
-
escapedString.isEscaped = true;
|
|
1957
|
-
escapedString.callbacks = callbacks;
|
|
1958
|
-
return escapedString;
|
|
1959
|
-
};
|
|
1960
|
-
var resolveCallback = async (str, phase, preserveCallbacks, context, buffer) => {
|
|
1961
|
-
if (typeof str === "object" && !(str instanceof String)) {
|
|
1962
|
-
if (!(str instanceof Promise)) {
|
|
1963
|
-
str = str.toString();
|
|
1964
|
-
}
|
|
1965
|
-
if (str instanceof Promise) {
|
|
1966
|
-
str = await str;
|
|
1967
|
-
}
|
|
1968
|
-
}
|
|
1969
|
-
const callbacks = str.callbacks;
|
|
1970
|
-
if (!callbacks?.length) {
|
|
1971
|
-
return Promise.resolve(str);
|
|
1972
|
-
}
|
|
1973
|
-
if (buffer) {
|
|
1974
|
-
buffer[0] += str;
|
|
1975
|
-
} else {
|
|
1976
|
-
buffer = [str];
|
|
1977
|
-
}
|
|
1978
|
-
const resStr = Promise.all(callbacks.map((c) => c({ phase, buffer, context }))).then(
|
|
1979
|
-
(res) => Promise.all(
|
|
1980
|
-
res.filter(Boolean).map((str2) => resolveCallback(str2, phase, false, context, buffer))
|
|
1981
|
-
).then(() => buffer[0])
|
|
1982
|
-
);
|
|
1983
|
-
if (preserveCallbacks) {
|
|
1984
|
-
return raw(await resStr, callbacks);
|
|
1985
|
-
} else {
|
|
1986
|
-
return resStr;
|
|
1987
|
-
}
|
|
1988
|
-
};
|
|
1989
|
-
|
|
1990
|
-
// ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/context.js
|
|
1991
|
-
var TEXT_PLAIN = "text/plain; charset=UTF-8";
|
|
1992
|
-
var setDefaultContentType = (contentType, headers) => {
|
|
1993
|
-
return {
|
|
1994
|
-
"Content-Type": contentType,
|
|
1995
|
-
...headers
|
|
1996
|
-
};
|
|
1997
|
-
};
|
|
1998
|
-
var Context = class {
|
|
1999
|
-
#rawRequest;
|
|
2000
|
-
#req;
|
|
2001
|
-
/**
|
|
2002
|
-
* `.env` can get bindings (environment variables, secrets, KV namespaces, D1 database, R2 bucket etc.) in Cloudflare Workers.
|
|
2003
|
-
*
|
|
2004
|
-
* @see {@link https://hono.dev/docs/api/context#env}
|
|
2005
|
-
*
|
|
2006
|
-
* @example
|
|
2007
|
-
* ```ts
|
|
2008
|
-
* // Environment object for Cloudflare Workers
|
|
2009
|
-
* app.get('*', async c => {
|
|
2010
|
-
* const counter = c.env.COUNTER
|
|
2011
|
-
* })
|
|
2012
|
-
* ```
|
|
2013
|
-
*/
|
|
2014
|
-
env = {};
|
|
2015
|
-
#var;
|
|
2016
|
-
finalized = false;
|
|
2017
|
-
/**
|
|
2018
|
-
* `.error` can get the error object from the middleware if the Handler throws an error.
|
|
2019
|
-
*
|
|
2020
|
-
* @see {@link https://hono.dev/docs/api/context#error}
|
|
2021
|
-
*
|
|
2022
|
-
* @example
|
|
2023
|
-
* ```ts
|
|
2024
|
-
* app.use('*', async (c, next) => {
|
|
2025
|
-
* await next()
|
|
2026
|
-
* if (c.error) {
|
|
2027
|
-
* // do something...
|
|
2028
|
-
* }
|
|
2029
|
-
* })
|
|
2030
|
-
* ```
|
|
2031
|
-
*/
|
|
2032
|
-
error;
|
|
2033
|
-
#status;
|
|
2034
|
-
#executionCtx;
|
|
2035
|
-
#res;
|
|
2036
|
-
#layout;
|
|
2037
|
-
#renderer;
|
|
2038
|
-
#notFoundHandler;
|
|
2039
|
-
#preparedHeaders;
|
|
2040
|
-
#matchResult;
|
|
2041
|
-
#path;
|
|
2042
|
-
/**
|
|
2043
|
-
* Creates an instance of the Context class.
|
|
2044
|
-
*
|
|
2045
|
-
* @param req - The Request object.
|
|
2046
|
-
* @param options - Optional configuration options for the context.
|
|
2047
|
-
*/
|
|
2048
|
-
constructor(req, options) {
|
|
2049
|
-
this.#rawRequest = req;
|
|
2050
|
-
if (options) {
|
|
2051
|
-
this.#executionCtx = options.executionCtx;
|
|
2052
|
-
this.env = options.env;
|
|
2053
|
-
this.#notFoundHandler = options.notFoundHandler;
|
|
2054
|
-
this.#path = options.path;
|
|
2055
|
-
this.#matchResult = options.matchResult;
|
|
2056
|
-
}
|
|
2057
|
-
}
|
|
2058
|
-
/**
|
|
2059
|
-
* `.req` is the instance of {@link HonoRequest}.
|
|
2060
|
-
*/
|
|
2061
|
-
get req() {
|
|
2062
|
-
this.#req ??= new HonoRequest(this.#rawRequest, this.#path, this.#matchResult);
|
|
2063
|
-
return this.#req;
|
|
2064
|
-
}
|
|
2065
|
-
/**
|
|
2066
|
-
* @see {@link https://hono.dev/docs/api/context#event}
|
|
2067
|
-
* The FetchEvent associated with the current request.
|
|
2068
|
-
*
|
|
2069
|
-
* @throws Will throw an error if the context does not have a FetchEvent.
|
|
2070
|
-
*/
|
|
2071
|
-
get event() {
|
|
2072
|
-
if (this.#executionCtx && "respondWith" in this.#executionCtx) {
|
|
2073
|
-
return this.#executionCtx;
|
|
2074
|
-
} else {
|
|
2075
|
-
throw Error("This context has no FetchEvent");
|
|
2076
|
-
}
|
|
2077
|
-
}
|
|
2078
|
-
/**
|
|
2079
|
-
* @see {@link https://hono.dev/docs/api/context#executionctx}
|
|
2080
|
-
* The ExecutionContext associated with the current request.
|
|
2081
|
-
*
|
|
2082
|
-
* @throws Will throw an error if the context does not have an ExecutionContext.
|
|
2083
|
-
*/
|
|
2084
|
-
get executionCtx() {
|
|
2085
|
-
if (this.#executionCtx) {
|
|
2086
|
-
return this.#executionCtx;
|
|
2087
|
-
} else {
|
|
2088
|
-
throw Error("This context has no ExecutionContext");
|
|
2089
|
-
}
|
|
2090
|
-
}
|
|
2091
|
-
/**
|
|
2092
|
-
* @see {@link https://hono.dev/docs/api/context#res}
|
|
2093
|
-
* The Response object for the current request.
|
|
2094
|
-
*/
|
|
2095
|
-
get res() {
|
|
2096
|
-
return this.#res ||= new Response(null, {
|
|
2097
|
-
headers: this.#preparedHeaders ??= new Headers()
|
|
2098
|
-
});
|
|
2099
|
-
}
|
|
2100
|
-
/**
|
|
2101
|
-
* Sets the Response object for the current request.
|
|
2102
|
-
*
|
|
2103
|
-
* @param _res - The Response object to set.
|
|
2104
|
-
*/
|
|
2105
|
-
set res(_res) {
|
|
2106
|
-
if (this.#res && _res) {
|
|
2107
|
-
_res = new Response(_res.body, _res);
|
|
2108
|
-
for (const [k, v] of this.#res.headers.entries()) {
|
|
2109
|
-
if (k === "content-type") {
|
|
2110
|
-
continue;
|
|
2111
|
-
}
|
|
2112
|
-
if (k === "set-cookie") {
|
|
2113
|
-
const cookies = this.#res.headers.getSetCookie();
|
|
2114
|
-
_res.headers.delete("set-cookie");
|
|
2115
|
-
for (const cookie of cookies) {
|
|
2116
|
-
_res.headers.append("set-cookie", cookie);
|
|
2117
|
-
}
|
|
2118
|
-
} else {
|
|
2119
|
-
_res.headers.set(k, v);
|
|
2120
|
-
}
|
|
2121
|
-
}
|
|
2122
|
-
}
|
|
2123
|
-
this.#res = _res;
|
|
2124
|
-
this.finalized = true;
|
|
2125
|
-
}
|
|
2126
|
-
/**
|
|
2127
|
-
* `.render()` can create a response within a layout.
|
|
2128
|
-
*
|
|
2129
|
-
* @see {@link https://hono.dev/docs/api/context#render-setrenderer}
|
|
2130
|
-
*
|
|
2131
|
-
* @example
|
|
2132
|
-
* ```ts
|
|
2133
|
-
* app.get('/', (c) => {
|
|
2134
|
-
* return c.render('Hello!')
|
|
2135
|
-
* })
|
|
2136
|
-
* ```
|
|
2137
|
-
*/
|
|
2138
|
-
render = (...args) => {
|
|
2139
|
-
this.#renderer ??= (content) => this.html(content);
|
|
2140
|
-
return this.#renderer(...args);
|
|
2141
|
-
};
|
|
2142
|
-
/**
|
|
2143
|
-
* Sets the layout for the response.
|
|
2144
|
-
*
|
|
2145
|
-
* @param layout - The layout to set.
|
|
2146
|
-
* @returns The layout function.
|
|
2147
|
-
*/
|
|
2148
|
-
setLayout = (layout) => this.#layout = layout;
|
|
2149
|
-
/**
|
|
2150
|
-
* Gets the current layout for the response.
|
|
2151
|
-
*
|
|
2152
|
-
* @returns The current layout function.
|
|
2153
|
-
*/
|
|
2154
|
-
getLayout = () => this.#layout;
|
|
2155
|
-
/**
|
|
2156
|
-
* `.setRenderer()` can set the layout in the custom middleware.
|
|
2157
|
-
*
|
|
2158
|
-
* @see {@link https://hono.dev/docs/api/context#render-setrenderer}
|
|
2159
|
-
*
|
|
2160
|
-
* @example
|
|
2161
|
-
* ```tsx
|
|
2162
|
-
* app.use('*', async (c, next) => {
|
|
2163
|
-
* c.setRenderer((content) => {
|
|
2164
|
-
* return c.html(
|
|
2165
|
-
* <html>
|
|
2166
|
-
* <body>
|
|
2167
|
-
* <p>{content}</p>
|
|
2168
|
-
* </body>
|
|
2169
|
-
* </html>
|
|
2170
|
-
* )
|
|
2171
|
-
* })
|
|
2172
|
-
* await next()
|
|
2173
|
-
* })
|
|
2174
|
-
* ```
|
|
2175
|
-
*/
|
|
2176
|
-
setRenderer = (renderer) => {
|
|
2177
|
-
this.#renderer = renderer;
|
|
2178
|
-
};
|
|
2179
|
-
/**
|
|
2180
|
-
* `.header()` can set headers.
|
|
2181
|
-
*
|
|
2182
|
-
* @see {@link https://hono.dev/docs/api/context#header}
|
|
2183
|
-
*
|
|
2184
|
-
* @example
|
|
2185
|
-
* ```ts
|
|
2186
|
-
* app.get('/welcome', (c) => {
|
|
2187
|
-
* // Set headers
|
|
2188
|
-
* c.header('X-Message', 'Hello!')
|
|
2189
|
-
* c.header('Content-Type', 'text/plain')
|
|
2190
|
-
*
|
|
2191
|
-
* return c.body('Thank you for coming')
|
|
2192
|
-
* })
|
|
2193
|
-
* ```
|
|
2194
|
-
*/
|
|
2195
|
-
header = (name, value, options) => {
|
|
2196
|
-
if (this.finalized) {
|
|
2197
|
-
this.#res = new Response(this.#res.body, this.#res);
|
|
2198
|
-
}
|
|
2199
|
-
const headers = this.#res ? this.#res.headers : this.#preparedHeaders ??= new Headers();
|
|
2200
|
-
if (value === void 0) {
|
|
2201
|
-
headers.delete(name);
|
|
2202
|
-
} else if (options?.append) {
|
|
2203
|
-
headers.append(name, value);
|
|
2204
|
-
} else {
|
|
2205
|
-
headers.set(name, value);
|
|
2206
|
-
}
|
|
2207
|
-
};
|
|
2208
|
-
status = (status) => {
|
|
2209
|
-
this.#status = status;
|
|
2210
|
-
};
|
|
2211
|
-
/**
|
|
2212
|
-
* `.set()` can set the value specified by the key.
|
|
2213
|
-
*
|
|
2214
|
-
* @see {@link https://hono.dev/docs/api/context#set-get}
|
|
2215
|
-
*
|
|
2216
|
-
* @example
|
|
2217
|
-
* ```ts
|
|
2218
|
-
* app.use('*', async (c, next) => {
|
|
2219
|
-
* c.set('message', 'Hono is hot!!')
|
|
2220
|
-
* await next()
|
|
2221
|
-
* })
|
|
2222
|
-
* ```
|
|
2223
|
-
*/
|
|
2224
|
-
set = (key, value) => {
|
|
2225
|
-
this.#var ??= /* @__PURE__ */ new Map();
|
|
2226
|
-
this.#var.set(key, value);
|
|
2227
|
-
};
|
|
2228
|
-
/**
|
|
2229
|
-
* `.get()` can use the value specified by the key.
|
|
2230
|
-
*
|
|
2231
|
-
* @see {@link https://hono.dev/docs/api/context#set-get}
|
|
2232
|
-
*
|
|
2233
|
-
* @example
|
|
2234
|
-
* ```ts
|
|
2235
|
-
* app.get('/', (c) => {
|
|
2236
|
-
* const message = c.get('message')
|
|
2237
|
-
* return c.text(`The message is "${message}"`)
|
|
2238
|
-
* })
|
|
2239
|
-
* ```
|
|
2240
|
-
*/
|
|
2241
|
-
get = (key) => {
|
|
2242
|
-
return this.#var ? this.#var.get(key) : void 0;
|
|
2243
|
-
};
|
|
2244
|
-
/**
|
|
2245
|
-
* `.var` can access the value of a variable.
|
|
2246
|
-
*
|
|
2247
|
-
* @see {@link https://hono.dev/docs/api/context#var}
|
|
2248
|
-
*
|
|
2249
|
-
* @example
|
|
2250
|
-
* ```ts
|
|
2251
|
-
* const result = c.var.client.oneMethod()
|
|
2252
|
-
* ```
|
|
2253
|
-
*/
|
|
2254
|
-
// c.var.propName is a read-only
|
|
2255
|
-
get var() {
|
|
2256
|
-
if (!this.#var) {
|
|
2257
|
-
return {};
|
|
2258
|
-
}
|
|
2259
|
-
return Object.fromEntries(this.#var);
|
|
2260
|
-
}
|
|
2261
|
-
#newResponse(data, arg, headers) {
|
|
2262
|
-
const responseHeaders = this.#res ? new Headers(this.#res.headers) : this.#preparedHeaders ?? new Headers();
|
|
2263
|
-
if (typeof arg === "object" && "headers" in arg) {
|
|
2264
|
-
const argHeaders = arg.headers instanceof Headers ? arg.headers : new Headers(arg.headers);
|
|
2265
|
-
for (const [key, value] of argHeaders) {
|
|
2266
|
-
if (key.toLowerCase() === "set-cookie") {
|
|
2267
|
-
responseHeaders.append(key, value);
|
|
2268
|
-
} else {
|
|
2269
|
-
responseHeaders.set(key, value);
|
|
2270
|
-
}
|
|
2271
|
-
}
|
|
2272
|
-
}
|
|
2273
|
-
if (headers) {
|
|
2274
|
-
for (const [k, v] of Object.entries(headers)) {
|
|
2275
|
-
if (typeof v === "string") {
|
|
2276
|
-
responseHeaders.set(k, v);
|
|
2277
|
-
} else {
|
|
2278
|
-
responseHeaders.delete(k);
|
|
2279
|
-
for (const v2 of v) {
|
|
2280
|
-
responseHeaders.append(k, v2);
|
|
2281
|
-
}
|
|
2282
|
-
}
|
|
2283
|
-
}
|
|
2284
|
-
}
|
|
2285
|
-
const status = typeof arg === "number" ? arg : arg?.status ?? this.#status;
|
|
2286
|
-
return new Response(data, { status, headers: responseHeaders });
|
|
2287
|
-
}
|
|
2288
|
-
newResponse = (...args) => this.#newResponse(...args);
|
|
2289
|
-
/**
|
|
2290
|
-
* `.body()` can return the HTTP response.
|
|
2291
|
-
* You can set headers with `.header()` and set HTTP status code with `.status`.
|
|
2292
|
-
* This can also be set in `.text()`, `.json()` and so on.
|
|
2293
|
-
*
|
|
2294
|
-
* @see {@link https://hono.dev/docs/api/context#body}
|
|
2295
|
-
*
|
|
2296
|
-
* @example
|
|
2297
|
-
* ```ts
|
|
2298
|
-
* app.get('/welcome', (c) => {
|
|
2299
|
-
* // Set headers
|
|
2300
|
-
* c.header('X-Message', 'Hello!')
|
|
2301
|
-
* c.header('Content-Type', 'text/plain')
|
|
2302
|
-
* // Set HTTP status code
|
|
2303
|
-
* c.status(201)
|
|
2304
|
-
*
|
|
2305
|
-
* // Return the response body
|
|
2306
|
-
* return c.body('Thank you for coming')
|
|
2307
|
-
* })
|
|
2308
|
-
* ```
|
|
2309
|
-
*/
|
|
2310
|
-
body = (data, arg, headers) => this.#newResponse(data, arg, headers);
|
|
2311
|
-
/**
|
|
2312
|
-
* `.text()` can render text as `Content-Type:text/plain`.
|
|
2313
|
-
*
|
|
2314
|
-
* @see {@link https://hono.dev/docs/api/context#text}
|
|
2315
|
-
*
|
|
2316
|
-
* @example
|
|
2317
|
-
* ```ts
|
|
2318
|
-
* app.get('/say', (c) => {
|
|
2319
|
-
* return c.text('Hello!')
|
|
2320
|
-
* })
|
|
2321
|
-
* ```
|
|
2322
|
-
*/
|
|
2323
|
-
text = (text, arg, headers) => {
|
|
2324
|
-
return !this.#preparedHeaders && !this.#status && !arg && !headers && !this.finalized ? new Response(text) : this.#newResponse(
|
|
2325
|
-
text,
|
|
2326
|
-
arg,
|
|
2327
|
-
setDefaultContentType(TEXT_PLAIN, headers)
|
|
2328
|
-
);
|
|
2329
|
-
};
|
|
2330
|
-
/**
|
|
2331
|
-
* `.json()` can render JSON as `Content-Type:application/json`.
|
|
2332
|
-
*
|
|
2333
|
-
* @see {@link https://hono.dev/docs/api/context#json}
|
|
2334
|
-
*
|
|
2335
|
-
* @example
|
|
2336
|
-
* ```ts
|
|
2337
|
-
* app.get('/api', (c) => {
|
|
2338
|
-
* return c.json({ message: 'Hello!' })
|
|
2339
|
-
* })
|
|
2340
|
-
* ```
|
|
2341
|
-
*/
|
|
2342
|
-
json = (object, arg, headers) => {
|
|
2343
|
-
return this.#newResponse(
|
|
2344
|
-
JSON.stringify(object),
|
|
2345
|
-
arg,
|
|
2346
|
-
setDefaultContentType("application/json", headers)
|
|
2347
|
-
);
|
|
2348
|
-
};
|
|
2349
|
-
html = (html, arg, headers) => {
|
|
2350
|
-
const res = (html2) => this.#newResponse(html2, arg, setDefaultContentType("text/html; charset=UTF-8", headers));
|
|
2351
|
-
return typeof html === "object" ? resolveCallback(html, HtmlEscapedCallbackPhase.Stringify, false, {}).then(res) : res(html);
|
|
2352
|
-
};
|
|
2353
|
-
/**
|
|
2354
|
-
* `.redirect()` can Redirect, default status code is 302.
|
|
2355
|
-
*
|
|
2356
|
-
* @see {@link https://hono.dev/docs/api/context#redirect}
|
|
2357
|
-
*
|
|
2358
|
-
* @example
|
|
2359
|
-
* ```ts
|
|
2360
|
-
* app.get('/redirect', (c) => {
|
|
2361
|
-
* return c.redirect('/')
|
|
2362
|
-
* })
|
|
2363
|
-
* app.get('/redirect-permanently', (c) => {
|
|
2364
|
-
* return c.redirect('/', 301)
|
|
2365
|
-
* })
|
|
2366
|
-
* ```
|
|
2367
|
-
*/
|
|
2368
|
-
redirect = (location, status) => {
|
|
2369
|
-
const locationString = String(location);
|
|
2370
|
-
this.header(
|
|
2371
|
-
"Location",
|
|
2372
|
-
// Multibyes should be encoded
|
|
2373
|
-
// eslint-disable-next-line no-control-regex
|
|
2374
|
-
!/[^\x00-\xFF]/.test(locationString) ? locationString : encodeURI(locationString)
|
|
2375
|
-
);
|
|
2376
|
-
return this.newResponse(null, status ?? 302);
|
|
2377
|
-
};
|
|
2378
|
-
/**
|
|
2379
|
-
* `.notFound()` can return the Not Found Response.
|
|
2380
|
-
*
|
|
2381
|
-
* @see {@link https://hono.dev/docs/api/context#notfound}
|
|
2382
|
-
*
|
|
2383
|
-
* @example
|
|
2384
|
-
* ```ts
|
|
2385
|
-
* app.get('/notfound', (c) => {
|
|
2386
|
-
* return c.notFound()
|
|
2387
|
-
* })
|
|
2388
|
-
* ```
|
|
2389
|
-
*/
|
|
2390
|
-
notFound = () => {
|
|
2391
|
-
this.#notFoundHandler ??= () => new Response();
|
|
2392
|
-
return this.#notFoundHandler(this);
|
|
2393
|
-
};
|
|
2394
|
-
};
|
|
2395
|
-
|
|
2396
|
-
// ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/router.js
|
|
2397
|
-
var METHOD_NAME_ALL = "ALL";
|
|
2398
|
-
var METHOD_NAME_ALL_LOWERCASE = "all";
|
|
2399
|
-
var METHODS = ["get", "post", "put", "delete", "options", "patch"];
|
|
2400
|
-
var MESSAGE_MATCHER_IS_ALREADY_BUILT = "Can not add a route since the matcher is already built.";
|
|
2401
|
-
var UnsupportedPathError = class extends Error {
|
|
2402
|
-
};
|
|
2403
|
-
|
|
2404
|
-
// ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/utils/constants.js
|
|
2405
|
-
var COMPOSED_HANDLER = "__COMPOSED_HANDLER";
|
|
2406
|
-
|
|
2407
|
-
// ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/hono-base.js
|
|
2408
|
-
var notFoundHandler = (c) => {
|
|
2409
|
-
return c.text("404 Not Found", 404);
|
|
2410
|
-
};
|
|
2411
|
-
var errorHandler = (err, c) => {
|
|
2412
|
-
if ("getResponse" in err) {
|
|
2413
|
-
const res = err.getResponse();
|
|
2414
|
-
return c.newResponse(res.body, res);
|
|
2415
|
-
}
|
|
2416
|
-
console.error(err);
|
|
2417
|
-
return c.text("Internal Server Error", 500);
|
|
2418
|
-
};
|
|
2419
|
-
var Hono = class _Hono {
|
|
2420
|
-
get;
|
|
2421
|
-
post;
|
|
2422
|
-
put;
|
|
2423
|
-
delete;
|
|
2424
|
-
options;
|
|
2425
|
-
patch;
|
|
2426
|
-
all;
|
|
2427
|
-
on;
|
|
2428
|
-
use;
|
|
2429
|
-
/*
|
|
2430
|
-
This class is like an abstract class and does not have a router.
|
|
2431
|
-
To use it, inherit the class and implement router in the constructor.
|
|
2432
|
-
*/
|
|
2433
|
-
router;
|
|
2434
|
-
getPath;
|
|
2435
|
-
// Cannot use `#` because it requires visibility at JavaScript runtime.
|
|
2436
|
-
_basePath = "/";
|
|
2437
|
-
#path = "/";
|
|
2438
|
-
routes = [];
|
|
2439
|
-
constructor(options = {}) {
|
|
2440
|
-
const allMethods = [...METHODS, METHOD_NAME_ALL_LOWERCASE];
|
|
2441
|
-
allMethods.forEach((method) => {
|
|
2442
|
-
this[method] = (args1, ...args) => {
|
|
2443
|
-
if (typeof args1 === "string") {
|
|
2444
|
-
this.#path = args1;
|
|
2445
|
-
} else {
|
|
2446
|
-
this.#addRoute(method, this.#path, args1);
|
|
2447
|
-
}
|
|
2448
|
-
args.forEach((handler) => {
|
|
2449
|
-
this.#addRoute(method, this.#path, handler);
|
|
2450
|
-
});
|
|
2451
|
-
return this;
|
|
2452
|
-
};
|
|
2453
|
-
});
|
|
2454
|
-
this.on = (method, path, ...handlers) => {
|
|
2455
|
-
for (const p of [path].flat()) {
|
|
2456
|
-
this.#path = p;
|
|
2457
|
-
for (const m of [method].flat()) {
|
|
2458
|
-
handlers.map((handler) => {
|
|
2459
|
-
this.#addRoute(m.toUpperCase(), this.#path, handler);
|
|
2460
|
-
});
|
|
2461
|
-
}
|
|
2462
|
-
}
|
|
2463
|
-
return this;
|
|
2464
|
-
};
|
|
2465
|
-
this.use = (arg1, ...handlers) => {
|
|
2466
|
-
if (typeof arg1 === "string") {
|
|
2467
|
-
this.#path = arg1;
|
|
2468
|
-
} else {
|
|
2469
|
-
this.#path = "*";
|
|
2470
|
-
handlers.unshift(arg1);
|
|
2471
|
-
}
|
|
2472
|
-
handlers.forEach((handler) => {
|
|
2473
|
-
this.#addRoute(METHOD_NAME_ALL, this.#path, handler);
|
|
2474
|
-
});
|
|
2475
|
-
return this;
|
|
2476
|
-
};
|
|
2477
|
-
const { strict, ...optionsWithoutStrict } = options;
|
|
2478
|
-
Object.assign(this, optionsWithoutStrict);
|
|
2479
|
-
this.getPath = strict ?? true ? options.getPath ?? getPath : getPathNoStrict;
|
|
2480
|
-
}
|
|
2481
|
-
#clone() {
|
|
2482
|
-
const clone = new _Hono({
|
|
2483
|
-
router: this.router,
|
|
2484
|
-
getPath: this.getPath
|
|
2485
|
-
});
|
|
2486
|
-
clone.errorHandler = this.errorHandler;
|
|
2487
|
-
clone.#notFoundHandler = this.#notFoundHandler;
|
|
2488
|
-
clone.routes = this.routes;
|
|
2489
|
-
return clone;
|
|
2490
|
-
}
|
|
2491
|
-
#notFoundHandler = notFoundHandler;
|
|
2492
|
-
// Cannot use `#` because it requires visibility at JavaScript runtime.
|
|
2493
|
-
errorHandler = errorHandler;
|
|
2494
|
-
/**
|
|
2495
|
-
* `.route()` allows grouping other Hono instance in routes.
|
|
2496
|
-
*
|
|
2497
|
-
* @see {@link https://hono.dev/docs/api/routing#grouping}
|
|
2498
|
-
*
|
|
2499
|
-
* @param {string} path - base Path
|
|
2500
|
-
* @param {Hono} app - other Hono instance
|
|
2501
|
-
* @returns {Hono} routed Hono instance
|
|
2502
|
-
*
|
|
2503
|
-
* @example
|
|
2504
|
-
* ```ts
|
|
2505
|
-
* const app = new Hono()
|
|
2506
|
-
* const app2 = new Hono()
|
|
2507
|
-
*
|
|
2508
|
-
* app2.get("/user", (c) => c.text("user"))
|
|
2509
|
-
* app.route("/api", app2) // GET /api/user
|
|
2510
|
-
* ```
|
|
2511
|
-
*/
|
|
2512
|
-
route(path, app) {
|
|
2513
|
-
const subApp = this.basePath(path);
|
|
2514
|
-
app.routes.map((r) => {
|
|
2515
|
-
let handler;
|
|
2516
|
-
if (app.errorHandler === errorHandler) {
|
|
2517
|
-
handler = r.handler;
|
|
2518
|
-
} else {
|
|
2519
|
-
handler = async (c, next) => (await compose([], app.errorHandler)(c, () => r.handler(c, next))).res;
|
|
2520
|
-
handler[COMPOSED_HANDLER] = r.handler;
|
|
2521
|
-
}
|
|
2522
|
-
subApp.#addRoute(r.method, r.path, handler);
|
|
2523
|
-
});
|
|
2524
|
-
return this;
|
|
2525
|
-
}
|
|
2526
|
-
/**
|
|
2527
|
-
* `.basePath()` allows base paths to be specified.
|
|
2528
|
-
*
|
|
2529
|
-
* @see {@link https://hono.dev/docs/api/routing#base-path}
|
|
2530
|
-
*
|
|
2531
|
-
* @param {string} path - base Path
|
|
2532
|
-
* @returns {Hono} changed Hono instance
|
|
2533
|
-
*
|
|
2534
|
-
* @example
|
|
2535
|
-
* ```ts
|
|
2536
|
-
* const api = new Hono().basePath('/api')
|
|
2537
|
-
* ```
|
|
2538
|
-
*/
|
|
2539
|
-
basePath(path) {
|
|
2540
|
-
const subApp = this.#clone();
|
|
2541
|
-
subApp._basePath = mergePath(this._basePath, path);
|
|
2542
|
-
return subApp;
|
|
2543
|
-
}
|
|
2544
|
-
/**
|
|
2545
|
-
* `.onError()` handles an error and returns a customized Response.
|
|
2546
|
-
*
|
|
2547
|
-
* @see {@link https://hono.dev/docs/api/hono#error-handling}
|
|
2548
|
-
*
|
|
2549
|
-
* @param {ErrorHandler} handler - request Handler for error
|
|
2550
|
-
* @returns {Hono} changed Hono instance
|
|
2551
|
-
*
|
|
2552
|
-
* @example
|
|
2553
|
-
* ```ts
|
|
2554
|
-
* app.onError((err, c) => {
|
|
2555
|
-
* console.error(`${err}`)
|
|
2556
|
-
* return c.text('Custom Error Message', 500)
|
|
2557
|
-
* })
|
|
2558
|
-
* ```
|
|
2559
|
-
*/
|
|
2560
|
-
onError = (handler) => {
|
|
2561
|
-
this.errorHandler = handler;
|
|
2562
|
-
return this;
|
|
2563
|
-
};
|
|
2564
|
-
/**
|
|
2565
|
-
* `.notFound()` allows you to customize a Not Found Response.
|
|
2566
|
-
*
|
|
2567
|
-
* @see {@link https://hono.dev/docs/api/hono#not-found}
|
|
2568
|
-
*
|
|
2569
|
-
* @param {NotFoundHandler} handler - request handler for not-found
|
|
2570
|
-
* @returns {Hono} changed Hono instance
|
|
2571
|
-
*
|
|
2572
|
-
* @example
|
|
2573
|
-
* ```ts
|
|
2574
|
-
* app.notFound((c) => {
|
|
2575
|
-
* return c.text('Custom 404 Message', 404)
|
|
2576
|
-
* })
|
|
2577
|
-
* ```
|
|
2578
|
-
*/
|
|
2579
|
-
notFound = (handler) => {
|
|
2580
|
-
this.#notFoundHandler = handler;
|
|
2581
|
-
return this;
|
|
2582
|
-
};
|
|
2583
|
-
/**
|
|
2584
|
-
* `.mount()` allows you to mount applications built with other frameworks into your Hono application.
|
|
2585
|
-
*
|
|
2586
|
-
* @see {@link https://hono.dev/docs/api/hono#mount}
|
|
2587
|
-
*
|
|
2588
|
-
* @param {string} path - base Path
|
|
2589
|
-
* @param {Function} applicationHandler - other Request Handler
|
|
2590
|
-
* @param {MountOptions} [options] - options of `.mount()`
|
|
2591
|
-
* @returns {Hono} mounted Hono instance
|
|
2592
|
-
*
|
|
2593
|
-
* @example
|
|
2594
|
-
* ```ts
|
|
2595
|
-
* import { Router as IttyRouter } from 'itty-router'
|
|
2596
|
-
* import { Hono } from 'hono'
|
|
2597
|
-
* // Create itty-router application
|
|
2598
|
-
* const ittyRouter = IttyRouter()
|
|
2599
|
-
* // GET /itty-router/hello
|
|
2600
|
-
* ittyRouter.get('/hello', () => new Response('Hello from itty-router'))
|
|
2601
|
-
*
|
|
2602
|
-
* const app = new Hono()
|
|
2603
|
-
* app.mount('/itty-router', ittyRouter.handle)
|
|
2604
|
-
* ```
|
|
2605
|
-
*
|
|
2606
|
-
* @example
|
|
2607
|
-
* ```ts
|
|
2608
|
-
* const app = new Hono()
|
|
2609
|
-
* // Send the request to another application without modification.
|
|
2610
|
-
* app.mount('/app', anotherApp, {
|
|
2611
|
-
* replaceRequest: (req) => req,
|
|
2612
|
-
* })
|
|
2613
|
-
* ```
|
|
2614
|
-
*/
|
|
2615
|
-
mount(path, applicationHandler, options) {
|
|
2616
|
-
let replaceRequest;
|
|
2617
|
-
let optionHandler;
|
|
2618
|
-
if (options) {
|
|
2619
|
-
if (typeof options === "function") {
|
|
2620
|
-
optionHandler = options;
|
|
2621
|
-
} else {
|
|
2622
|
-
optionHandler = options.optionHandler;
|
|
2623
|
-
if (options.replaceRequest === false) {
|
|
2624
|
-
replaceRequest = (request) => request;
|
|
2625
|
-
} else {
|
|
2626
|
-
replaceRequest = options.replaceRequest;
|
|
2627
|
-
}
|
|
2628
|
-
}
|
|
2629
|
-
}
|
|
2630
|
-
const getOptions = optionHandler ? (c) => {
|
|
2631
|
-
const options2 = optionHandler(c);
|
|
2632
|
-
return Array.isArray(options2) ? options2 : [options2];
|
|
2633
|
-
} : (c) => {
|
|
2634
|
-
let executionContext = void 0;
|
|
2635
|
-
try {
|
|
2636
|
-
executionContext = c.executionCtx;
|
|
2637
|
-
} catch {
|
|
2638
|
-
}
|
|
2639
|
-
return [c.env, executionContext];
|
|
2640
|
-
};
|
|
2641
|
-
replaceRequest ||= (() => {
|
|
2642
|
-
const mergedPath = mergePath(this._basePath, path);
|
|
2643
|
-
const pathPrefixLength = mergedPath === "/" ? 0 : mergedPath.length;
|
|
2644
|
-
return (request) => {
|
|
2645
|
-
const url = new URL(request.url);
|
|
2646
|
-
url.pathname = url.pathname.slice(pathPrefixLength) || "/";
|
|
2647
|
-
return new Request(url, request);
|
|
2648
|
-
};
|
|
2649
|
-
})();
|
|
2650
|
-
const handler = async (c, next) => {
|
|
2651
|
-
const res = await applicationHandler(replaceRequest(c.req.raw), ...getOptions(c));
|
|
2652
|
-
if (res) {
|
|
2653
|
-
return res;
|
|
2654
|
-
}
|
|
2655
|
-
await next();
|
|
2656
|
-
};
|
|
2657
|
-
this.#addRoute(METHOD_NAME_ALL, mergePath(path, "*"), handler);
|
|
2658
|
-
return this;
|
|
2659
|
-
}
|
|
2660
|
-
#addRoute(method, path, handler) {
|
|
2661
|
-
method = method.toUpperCase();
|
|
2662
|
-
path = mergePath(this._basePath, path);
|
|
2663
|
-
const r = { basePath: this._basePath, path, method, handler };
|
|
2664
|
-
this.router.add(method, path, [handler, r]);
|
|
2665
|
-
this.routes.push(r);
|
|
2666
|
-
}
|
|
2667
|
-
#handleError(err, c) {
|
|
2668
|
-
if (err instanceof Error) {
|
|
2669
|
-
return this.errorHandler(err, c);
|
|
2670
|
-
}
|
|
2671
|
-
throw err;
|
|
2672
|
-
}
|
|
2673
|
-
#dispatch(request, executionCtx, env2, method) {
|
|
2674
|
-
if (method === "HEAD") {
|
|
2675
|
-
return (async () => new Response(null, await this.#dispatch(request, executionCtx, env2, "GET")))();
|
|
2676
|
-
}
|
|
2677
|
-
const path = this.getPath(request, { env: env2 });
|
|
2678
|
-
const matchResult = this.router.match(method, path);
|
|
2679
|
-
const c = new Context(request, {
|
|
2680
|
-
path,
|
|
2681
|
-
matchResult,
|
|
2682
|
-
env: env2,
|
|
2683
|
-
executionCtx,
|
|
2684
|
-
notFoundHandler: this.#notFoundHandler
|
|
2685
|
-
});
|
|
2686
|
-
if (matchResult[0].length === 1) {
|
|
2687
|
-
let res;
|
|
2688
|
-
try {
|
|
2689
|
-
res = matchResult[0][0][0][0](c, async () => {
|
|
2690
|
-
c.res = await this.#notFoundHandler(c);
|
|
2691
|
-
});
|
|
2692
|
-
} catch (err) {
|
|
2693
|
-
return this.#handleError(err, c);
|
|
2694
|
-
}
|
|
2695
|
-
return res instanceof Promise ? res.then(
|
|
2696
|
-
(resolved) => resolved || (c.finalized ? c.res : this.#notFoundHandler(c))
|
|
2697
|
-
).catch((err) => this.#handleError(err, c)) : res ?? this.#notFoundHandler(c);
|
|
2698
|
-
}
|
|
2699
|
-
const composed = compose(matchResult[0], this.errorHandler, this.#notFoundHandler);
|
|
2700
|
-
return (async () => {
|
|
2701
|
-
try {
|
|
2702
|
-
const context = await composed(c);
|
|
2703
|
-
if (!context.finalized) {
|
|
2704
|
-
throw new Error(
|
|
2705
|
-
"Context is not finalized. Did you forget to return a Response object or `await next()`?"
|
|
2706
|
-
);
|
|
2707
|
-
}
|
|
2708
|
-
return context.res;
|
|
2709
|
-
} catch (err) {
|
|
2710
|
-
return this.#handleError(err, c);
|
|
2711
|
-
}
|
|
2712
|
-
})();
|
|
2713
|
-
}
|
|
2714
|
-
/**
|
|
2715
|
-
* `.fetch()` will be entry point of your app.
|
|
2716
|
-
*
|
|
2717
|
-
* @see {@link https://hono.dev/docs/api/hono#fetch}
|
|
2718
|
-
*
|
|
2719
|
-
* @param {Request} request - request Object of request
|
|
2720
|
-
* @param {Env} Env - env Object
|
|
2721
|
-
* @param {ExecutionContext} - context of execution
|
|
2722
|
-
* @returns {Response | Promise<Response>} response of request
|
|
2723
|
-
*
|
|
2724
|
-
*/
|
|
2725
|
-
fetch = (request, ...rest) => {
|
|
2726
|
-
return this.#dispatch(request, rest[1], rest[0], request.method);
|
|
2727
|
-
};
|
|
2728
|
-
/**
|
|
2729
|
-
* `.request()` is a useful method for testing.
|
|
2730
|
-
* You can pass a URL or pathname to send a GET request.
|
|
2731
|
-
* app will return a Response object.
|
|
2732
|
-
* ```ts
|
|
2733
|
-
* test('GET /hello is ok', async () => {
|
|
2734
|
-
* const res = await app.request('/hello')
|
|
2735
|
-
* expect(res.status).toBe(200)
|
|
2736
|
-
* })
|
|
2737
|
-
* ```
|
|
2738
|
-
* @see https://hono.dev/docs/api/hono#request
|
|
2739
|
-
*/
|
|
2740
|
-
request = (input, requestInit, Env, executionCtx) => {
|
|
2741
|
-
if (input instanceof Request) {
|
|
2742
|
-
return this.fetch(requestInit ? new Request(input, requestInit) : input, Env, executionCtx);
|
|
2743
|
-
}
|
|
2744
|
-
input = input.toString();
|
|
2745
|
-
return this.fetch(
|
|
2746
|
-
new Request(
|
|
2747
|
-
/^https?:\/\//.test(input) ? input : `http://localhost${mergePath("/", input)}`,
|
|
2748
|
-
requestInit
|
|
2749
|
-
),
|
|
2750
|
-
Env,
|
|
2751
|
-
executionCtx
|
|
2752
|
-
);
|
|
2753
|
-
};
|
|
2754
|
-
/**
|
|
2755
|
-
* `.fire()` automatically adds a global fetch event listener.
|
|
2756
|
-
* This can be useful for environments that adhere to the Service Worker API, such as non-ES module Cloudflare Workers.
|
|
2757
|
-
* @deprecated
|
|
2758
|
-
* Use `fire` from `hono/service-worker` instead.
|
|
2759
|
-
* ```ts
|
|
2760
|
-
* import { Hono } from 'hono'
|
|
2761
|
-
* import { fire } from 'hono/service-worker'
|
|
2762
|
-
*
|
|
2763
|
-
* const app = new Hono()
|
|
2764
|
-
* // ...
|
|
2765
|
-
* fire(app)
|
|
2766
|
-
* ```
|
|
2767
|
-
* @see https://hono.dev/docs/api/hono#fire
|
|
2768
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API
|
|
2769
|
-
* @see https://developers.cloudflare.com/workers/reference/migrate-to-module-workers/
|
|
2770
|
-
*/
|
|
2771
|
-
fire = () => {
|
|
2772
|
-
addEventListener("fetch", (event) => {
|
|
2773
|
-
event.respondWith(this.#dispatch(event.request, event, void 0, event.request.method));
|
|
2774
|
-
});
|
|
2775
|
-
};
|
|
2776
|
-
};
|
|
2777
|
-
|
|
2778
|
-
// ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/router/reg-exp-router/matcher.js
|
|
2779
|
-
var emptyParam = [];
|
|
2780
|
-
function match(method, path) {
|
|
2781
|
-
const matchers = this.buildAllMatchers();
|
|
2782
|
-
const match2 = ((method2, path2) => {
|
|
2783
|
-
const matcher = matchers[method2] || matchers[METHOD_NAME_ALL];
|
|
2784
|
-
const staticMatch = matcher[2][path2];
|
|
2785
|
-
if (staticMatch) {
|
|
2786
|
-
return staticMatch;
|
|
2787
|
-
}
|
|
2788
|
-
const match3 = path2.match(matcher[0]);
|
|
2789
|
-
if (!match3) {
|
|
2790
|
-
return [[], emptyParam];
|
|
2791
|
-
}
|
|
2792
|
-
const index = match3.indexOf("", 1);
|
|
2793
|
-
return [matcher[1][index], match3];
|
|
2794
|
-
});
|
|
2795
|
-
this.match = match2;
|
|
2796
|
-
return match2(method, path);
|
|
2797
|
-
}
|
|
2798
|
-
|
|
2799
|
-
// ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/router/reg-exp-router/node.js
|
|
2800
|
-
var LABEL_REG_EXP_STR = "[^/]+";
|
|
2801
|
-
var ONLY_WILDCARD_REG_EXP_STR = ".*";
|
|
2802
|
-
var TAIL_WILDCARD_REG_EXP_STR = "(?:|/.*)";
|
|
2803
|
-
var PATH_ERROR = /* @__PURE__ */ Symbol();
|
|
2804
|
-
var regExpMetaChars = new Set(".\\+*[^]$()");
|
|
2805
|
-
function compareKey(a, b) {
|
|
2806
|
-
if (a.length === 1) {
|
|
2807
|
-
return b.length === 1 ? a < b ? -1 : 1 : -1;
|
|
2808
|
-
}
|
|
2809
|
-
if (b.length === 1) {
|
|
2810
|
-
return 1;
|
|
2811
|
-
}
|
|
2812
|
-
if (a === ONLY_WILDCARD_REG_EXP_STR || a === TAIL_WILDCARD_REG_EXP_STR) {
|
|
2813
|
-
return 1;
|
|
2814
|
-
} else if (b === ONLY_WILDCARD_REG_EXP_STR || b === TAIL_WILDCARD_REG_EXP_STR) {
|
|
2815
|
-
return -1;
|
|
2816
|
-
}
|
|
2817
|
-
if (a === LABEL_REG_EXP_STR) {
|
|
2818
|
-
return 1;
|
|
2819
|
-
} else if (b === LABEL_REG_EXP_STR) {
|
|
2820
|
-
return -1;
|
|
2821
|
-
}
|
|
2822
|
-
return a.length === b.length ? a < b ? -1 : 1 : b.length - a.length;
|
|
2823
|
-
}
|
|
2824
|
-
var Node = class _Node {
|
|
2825
|
-
#index;
|
|
2826
|
-
#varIndex;
|
|
2827
|
-
#children = /* @__PURE__ */ Object.create(null);
|
|
2828
|
-
insert(tokens, index, paramMap, context, pathErrorCheckOnly) {
|
|
2829
|
-
if (tokens.length === 0) {
|
|
2830
|
-
if (this.#index !== void 0) {
|
|
2831
|
-
throw PATH_ERROR;
|
|
2832
|
-
}
|
|
2833
|
-
if (pathErrorCheckOnly) {
|
|
2834
|
-
return;
|
|
2835
|
-
}
|
|
2836
|
-
this.#index = index;
|
|
2837
|
-
return;
|
|
2838
|
-
}
|
|
2839
|
-
const [token, ...restTokens] = tokens;
|
|
2840
|
-
const pattern = token === "*" ? restTokens.length === 0 ? ["", "", ONLY_WILDCARD_REG_EXP_STR] : ["", "", LABEL_REG_EXP_STR] : token === "/*" ? ["", "", TAIL_WILDCARD_REG_EXP_STR] : token.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
|
|
2841
|
-
let node;
|
|
2842
|
-
if (pattern) {
|
|
2843
|
-
const name = pattern[1];
|
|
2844
|
-
let regexpStr = pattern[2] || LABEL_REG_EXP_STR;
|
|
2845
|
-
if (name && pattern[2]) {
|
|
2846
|
-
if (regexpStr === ".*") {
|
|
2847
|
-
throw PATH_ERROR;
|
|
2848
|
-
}
|
|
2849
|
-
regexpStr = regexpStr.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:");
|
|
2850
|
-
if (/\((?!\?:)/.test(regexpStr)) {
|
|
2851
|
-
throw PATH_ERROR;
|
|
2852
|
-
}
|
|
2853
|
-
}
|
|
2854
|
-
node = this.#children[regexpStr];
|
|
2855
|
-
if (!node) {
|
|
2856
|
-
if (Object.keys(this.#children).some(
|
|
2857
|
-
(k) => k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR
|
|
2858
|
-
)) {
|
|
2859
|
-
throw PATH_ERROR;
|
|
2860
|
-
}
|
|
2861
|
-
if (pathErrorCheckOnly) {
|
|
2862
|
-
return;
|
|
2863
|
-
}
|
|
2864
|
-
node = this.#children[regexpStr] = new _Node();
|
|
2865
|
-
if (name !== "") {
|
|
2866
|
-
node.#varIndex = context.varIndex++;
|
|
2867
|
-
}
|
|
2868
|
-
}
|
|
2869
|
-
if (!pathErrorCheckOnly && name !== "") {
|
|
2870
|
-
paramMap.push([name, node.#varIndex]);
|
|
2871
|
-
}
|
|
2872
|
-
} else {
|
|
2873
|
-
node = this.#children[token];
|
|
2874
|
-
if (!node) {
|
|
2875
|
-
if (Object.keys(this.#children).some(
|
|
2876
|
-
(k) => k.length > 1 && k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR
|
|
2877
|
-
)) {
|
|
2878
|
-
throw PATH_ERROR;
|
|
2879
|
-
}
|
|
2880
|
-
if (pathErrorCheckOnly) {
|
|
2881
|
-
return;
|
|
2882
|
-
}
|
|
2883
|
-
node = this.#children[token] = new _Node();
|
|
2884
|
-
}
|
|
2885
|
-
}
|
|
2886
|
-
node.insert(restTokens, index, paramMap, context, pathErrorCheckOnly);
|
|
2887
|
-
}
|
|
2888
|
-
buildRegExpStr() {
|
|
2889
|
-
const childKeys = Object.keys(this.#children).sort(compareKey);
|
|
2890
|
-
const strList = childKeys.map((k) => {
|
|
2891
|
-
const c = this.#children[k];
|
|
2892
|
-
return (typeof c.#varIndex === "number" ? `(${k})@${c.#varIndex}` : regExpMetaChars.has(k) ? `\\${k}` : k) + c.buildRegExpStr();
|
|
2893
|
-
});
|
|
2894
|
-
if (typeof this.#index === "number") {
|
|
2895
|
-
strList.unshift(`#${this.#index}`);
|
|
2896
|
-
}
|
|
2897
|
-
if (strList.length === 0) {
|
|
2898
|
-
return "";
|
|
2899
|
-
}
|
|
2900
|
-
if (strList.length === 1) {
|
|
2901
|
-
return strList[0];
|
|
2902
|
-
}
|
|
2903
|
-
return "(?:" + strList.join("|") + ")";
|
|
2904
|
-
}
|
|
2905
|
-
};
|
|
2906
|
-
|
|
2907
|
-
// ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/router/reg-exp-router/trie.js
|
|
2908
|
-
var Trie = class {
|
|
2909
|
-
#context = { varIndex: 0 };
|
|
2910
|
-
#root = new Node();
|
|
2911
|
-
insert(path, index, pathErrorCheckOnly) {
|
|
2912
|
-
const paramAssoc = [];
|
|
2913
|
-
const groups = [];
|
|
2914
|
-
for (let i = 0; ; ) {
|
|
2915
|
-
let replaced = false;
|
|
2916
|
-
path = path.replace(/\{[^}]+\}/g, (m) => {
|
|
2917
|
-
const mark = `@\\${i}`;
|
|
2918
|
-
groups[i] = [mark, m];
|
|
2919
|
-
i++;
|
|
2920
|
-
replaced = true;
|
|
2921
|
-
return mark;
|
|
2922
|
-
});
|
|
2923
|
-
if (!replaced) {
|
|
2924
|
-
break;
|
|
2925
|
-
}
|
|
2926
|
-
}
|
|
2927
|
-
const tokens = path.match(/(?::[^\/]+)|(?:\/\*$)|./g) || [];
|
|
2928
|
-
for (let i = groups.length - 1; i >= 0; i--) {
|
|
2929
|
-
const [mark] = groups[i];
|
|
2930
|
-
for (let j = tokens.length - 1; j >= 0; j--) {
|
|
2931
|
-
if (tokens[j].indexOf(mark) !== -1) {
|
|
2932
|
-
tokens[j] = tokens[j].replace(mark, groups[i][1]);
|
|
2933
|
-
break;
|
|
2934
|
-
}
|
|
2935
|
-
}
|
|
2936
|
-
}
|
|
2937
|
-
this.#root.insert(tokens, index, paramAssoc, this.#context, pathErrorCheckOnly);
|
|
2938
|
-
return paramAssoc;
|
|
2939
|
-
}
|
|
2940
|
-
buildRegExp() {
|
|
2941
|
-
let regexp = this.#root.buildRegExpStr();
|
|
2942
|
-
if (regexp === "") {
|
|
2943
|
-
return [/^$/, [], []];
|
|
2944
|
-
}
|
|
2945
|
-
let captureIndex = 0;
|
|
2946
|
-
const indexReplacementMap = [];
|
|
2947
|
-
const paramReplacementMap = [];
|
|
2948
|
-
regexp = regexp.replace(/#(\d+)|@(\d+)|\.\*\$/g, (_, handlerIndex, paramIndex) => {
|
|
2949
|
-
if (handlerIndex !== void 0) {
|
|
2950
|
-
indexReplacementMap[++captureIndex] = Number(handlerIndex);
|
|
2951
|
-
return "$()";
|
|
2952
|
-
}
|
|
2953
|
-
if (paramIndex !== void 0) {
|
|
2954
|
-
paramReplacementMap[Number(paramIndex)] = ++captureIndex;
|
|
2955
|
-
return "";
|
|
2956
|
-
}
|
|
2957
|
-
return "";
|
|
2958
|
-
});
|
|
2959
|
-
return [new RegExp(`^${regexp}`), indexReplacementMap, paramReplacementMap];
|
|
2960
|
-
}
|
|
2961
|
-
};
|
|
2962
|
-
|
|
2963
|
-
// ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/router/reg-exp-router/router.js
|
|
2964
|
-
var nullMatcher = [/^$/, [], /* @__PURE__ */ Object.create(null)];
|
|
2965
|
-
var wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
|
|
2966
|
-
function buildWildcardRegExp(path) {
|
|
2967
|
-
return wildcardRegExpCache[path] ??= new RegExp(
|
|
2968
|
-
path === "*" ? "" : `^${path.replace(
|
|
2969
|
-
/\/\*$|([.\\+*[^\]$()])/g,
|
|
2970
|
-
(_, metaChar) => metaChar ? `\\${metaChar}` : "(?:|/.*)"
|
|
2971
|
-
)}$`
|
|
2972
|
-
);
|
|
2973
|
-
}
|
|
2974
|
-
function clearWildcardRegExpCache() {
|
|
2975
|
-
wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
|
|
2976
|
-
}
|
|
2977
|
-
function buildMatcherFromPreprocessedRoutes(routes) {
|
|
2978
|
-
const trie = new Trie();
|
|
2979
|
-
const handlerData = [];
|
|
2980
|
-
if (routes.length === 0) {
|
|
2981
|
-
return nullMatcher;
|
|
2982
|
-
}
|
|
2983
|
-
const routesWithStaticPathFlag = routes.map(
|
|
2984
|
-
(route) => [!/\*|\/:/.test(route[0]), ...route]
|
|
2985
|
-
).sort(
|
|
2986
|
-
([isStaticA, pathA], [isStaticB, pathB]) => isStaticA ? 1 : isStaticB ? -1 : pathA.length - pathB.length
|
|
2987
|
-
);
|
|
2988
|
-
const staticMap = /* @__PURE__ */ Object.create(null);
|
|
2989
|
-
for (let i = 0, j = -1, len = routesWithStaticPathFlag.length; i < len; i++) {
|
|
2990
|
-
const [pathErrorCheckOnly, path, handlers] = routesWithStaticPathFlag[i];
|
|
2991
|
-
if (pathErrorCheckOnly) {
|
|
2992
|
-
staticMap[path] = [handlers.map(([h]) => [h, /* @__PURE__ */ Object.create(null)]), emptyParam];
|
|
2993
|
-
} else {
|
|
2994
|
-
j++;
|
|
2995
|
-
}
|
|
2996
|
-
let paramAssoc;
|
|
2997
|
-
try {
|
|
2998
|
-
paramAssoc = trie.insert(path, j, pathErrorCheckOnly);
|
|
2999
|
-
} catch (e) {
|
|
3000
|
-
throw e === PATH_ERROR ? new UnsupportedPathError(path) : e;
|
|
3001
|
-
}
|
|
3002
|
-
if (pathErrorCheckOnly) {
|
|
3003
|
-
continue;
|
|
3004
|
-
}
|
|
3005
|
-
handlerData[j] = handlers.map(([h, paramCount]) => {
|
|
3006
|
-
const paramIndexMap = /* @__PURE__ */ Object.create(null);
|
|
3007
|
-
paramCount -= 1;
|
|
3008
|
-
for (; paramCount >= 0; paramCount--) {
|
|
3009
|
-
const [key, value] = paramAssoc[paramCount];
|
|
3010
|
-
paramIndexMap[key] = value;
|
|
3011
|
-
}
|
|
3012
|
-
return [h, paramIndexMap];
|
|
3013
|
-
});
|
|
3014
|
-
}
|
|
3015
|
-
const [regexp, indexReplacementMap, paramReplacementMap] = trie.buildRegExp();
|
|
3016
|
-
for (let i = 0, len = handlerData.length; i < len; i++) {
|
|
3017
|
-
for (let j = 0, len2 = handlerData[i].length; j < len2; j++) {
|
|
3018
|
-
const map = handlerData[i][j]?.[1];
|
|
3019
|
-
if (!map) {
|
|
3020
|
-
continue;
|
|
3021
|
-
}
|
|
3022
|
-
const keys = Object.keys(map);
|
|
3023
|
-
for (let k = 0, len3 = keys.length; k < len3; k++) {
|
|
3024
|
-
map[keys[k]] = paramReplacementMap[map[keys[k]]];
|
|
3025
|
-
}
|
|
3026
|
-
}
|
|
3027
|
-
}
|
|
3028
|
-
const handlerMap = [];
|
|
3029
|
-
for (const i in indexReplacementMap) {
|
|
3030
|
-
handlerMap[i] = handlerData[indexReplacementMap[i]];
|
|
3031
|
-
}
|
|
3032
|
-
return [regexp, handlerMap, staticMap];
|
|
3033
|
-
}
|
|
3034
|
-
function findMiddleware(middleware, path) {
|
|
3035
|
-
if (!middleware) {
|
|
3036
|
-
return void 0;
|
|
3037
|
-
}
|
|
3038
|
-
for (const k of Object.keys(middleware).sort((a, b) => b.length - a.length)) {
|
|
3039
|
-
if (buildWildcardRegExp(k).test(path)) {
|
|
3040
|
-
return [...middleware[k]];
|
|
3041
|
-
}
|
|
3042
|
-
}
|
|
3043
|
-
return void 0;
|
|
3044
|
-
}
|
|
3045
|
-
var RegExpRouter = class {
|
|
3046
|
-
name = "RegExpRouter";
|
|
3047
|
-
#middleware;
|
|
3048
|
-
#routes;
|
|
3049
|
-
constructor() {
|
|
3050
|
-
this.#middleware = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
|
|
3051
|
-
this.#routes = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
|
|
3052
|
-
}
|
|
3053
|
-
add(method, path, handler) {
|
|
3054
|
-
const middleware = this.#middleware;
|
|
3055
|
-
const routes = this.#routes;
|
|
3056
|
-
if (!middleware || !routes) {
|
|
3057
|
-
throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
|
|
3058
|
-
}
|
|
3059
|
-
if (!middleware[method]) {
|
|
3060
|
-
;
|
|
3061
|
-
[middleware, routes].forEach((handlerMap) => {
|
|
3062
|
-
handlerMap[method] = /* @__PURE__ */ Object.create(null);
|
|
3063
|
-
Object.keys(handlerMap[METHOD_NAME_ALL]).forEach((p) => {
|
|
3064
|
-
handlerMap[method][p] = [...handlerMap[METHOD_NAME_ALL][p]];
|
|
3065
|
-
});
|
|
3066
|
-
});
|
|
3067
|
-
}
|
|
3068
|
-
if (path === "/*") {
|
|
3069
|
-
path = "*";
|
|
3070
|
-
}
|
|
3071
|
-
const paramCount = (path.match(/\/:/g) || []).length;
|
|
3072
|
-
if (/\*$/.test(path)) {
|
|
3073
|
-
const re = buildWildcardRegExp(path);
|
|
3074
|
-
if (method === METHOD_NAME_ALL) {
|
|
3075
|
-
Object.keys(middleware).forEach((m) => {
|
|
3076
|
-
middleware[m][path] ||= findMiddleware(middleware[m], path) || findMiddleware(middleware[METHOD_NAME_ALL], path) || [];
|
|
3077
|
-
});
|
|
3078
|
-
} else {
|
|
3079
|
-
middleware[method][path] ||= findMiddleware(middleware[method], path) || findMiddleware(middleware[METHOD_NAME_ALL], path) || [];
|
|
3080
|
-
}
|
|
3081
|
-
Object.keys(middleware).forEach((m) => {
|
|
3082
|
-
if (method === METHOD_NAME_ALL || method === m) {
|
|
3083
|
-
Object.keys(middleware[m]).forEach((p) => {
|
|
3084
|
-
re.test(p) && middleware[m][p].push([handler, paramCount]);
|
|
3085
|
-
});
|
|
3086
|
-
}
|
|
3087
|
-
});
|
|
3088
|
-
Object.keys(routes).forEach((m) => {
|
|
3089
|
-
if (method === METHOD_NAME_ALL || method === m) {
|
|
3090
|
-
Object.keys(routes[m]).forEach(
|
|
3091
|
-
(p) => re.test(p) && routes[m][p].push([handler, paramCount])
|
|
3092
|
-
);
|
|
3093
|
-
}
|
|
3094
|
-
});
|
|
3095
|
-
return;
|
|
3096
|
-
}
|
|
3097
|
-
const paths = checkOptionalParameter(path) || [path];
|
|
3098
|
-
for (let i = 0, len = paths.length; i < len; i++) {
|
|
3099
|
-
const path2 = paths[i];
|
|
3100
|
-
Object.keys(routes).forEach((m) => {
|
|
3101
|
-
if (method === METHOD_NAME_ALL || method === m) {
|
|
3102
|
-
routes[m][path2] ||= [
|
|
3103
|
-
...findMiddleware(middleware[m], path2) || findMiddleware(middleware[METHOD_NAME_ALL], path2) || []
|
|
3104
|
-
];
|
|
3105
|
-
routes[m][path2].push([handler, paramCount - len + i + 1]);
|
|
3106
|
-
}
|
|
3107
|
-
});
|
|
3108
|
-
}
|
|
3109
|
-
}
|
|
3110
|
-
match = match;
|
|
3111
|
-
buildAllMatchers() {
|
|
3112
|
-
const matchers = /* @__PURE__ */ Object.create(null);
|
|
3113
|
-
Object.keys(this.#routes).concat(Object.keys(this.#middleware)).forEach((method) => {
|
|
3114
|
-
matchers[method] ||= this.#buildMatcher(method);
|
|
3115
|
-
});
|
|
3116
|
-
this.#middleware = this.#routes = void 0;
|
|
3117
|
-
clearWildcardRegExpCache();
|
|
3118
|
-
return matchers;
|
|
3119
|
-
}
|
|
3120
|
-
#buildMatcher(method) {
|
|
3121
|
-
const routes = [];
|
|
3122
|
-
let hasOwnRoute = method === METHOD_NAME_ALL;
|
|
3123
|
-
[this.#middleware, this.#routes].forEach((r) => {
|
|
3124
|
-
const ownRoute = r[method] ? Object.keys(r[method]).map((path) => [path, r[method][path]]) : [];
|
|
3125
|
-
if (ownRoute.length !== 0) {
|
|
3126
|
-
hasOwnRoute ||= true;
|
|
3127
|
-
routes.push(...ownRoute);
|
|
3128
|
-
} else if (method !== METHOD_NAME_ALL) {
|
|
3129
|
-
routes.push(
|
|
3130
|
-
...Object.keys(r[METHOD_NAME_ALL]).map((path) => [path, r[METHOD_NAME_ALL][path]])
|
|
3131
|
-
);
|
|
3132
|
-
}
|
|
3133
|
-
});
|
|
3134
|
-
if (!hasOwnRoute) {
|
|
3135
|
-
return null;
|
|
3136
|
-
} else {
|
|
3137
|
-
return buildMatcherFromPreprocessedRoutes(routes);
|
|
3138
|
-
}
|
|
3139
|
-
}
|
|
3140
|
-
};
|
|
3141
|
-
|
|
3142
|
-
// ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/router/smart-router/router.js
|
|
3143
|
-
var SmartRouter = class {
|
|
3144
|
-
name = "SmartRouter";
|
|
3145
|
-
#routers = [];
|
|
3146
|
-
#routes = [];
|
|
3147
|
-
constructor(init) {
|
|
3148
|
-
this.#routers = init.routers;
|
|
3149
|
-
}
|
|
3150
|
-
add(method, path, handler) {
|
|
3151
|
-
if (!this.#routes) {
|
|
3152
|
-
throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
|
|
3153
|
-
}
|
|
3154
|
-
this.#routes.push([method, path, handler]);
|
|
3155
|
-
}
|
|
3156
|
-
match(method, path) {
|
|
3157
|
-
if (!this.#routes) {
|
|
3158
|
-
throw new Error("Fatal error");
|
|
3159
|
-
}
|
|
3160
|
-
const routers = this.#routers;
|
|
3161
|
-
const routes = this.#routes;
|
|
3162
|
-
const len = routers.length;
|
|
3163
|
-
let i = 0;
|
|
3164
|
-
let res;
|
|
3165
|
-
for (; i < len; i++) {
|
|
3166
|
-
const router = routers[i];
|
|
3167
|
-
try {
|
|
3168
|
-
for (let i2 = 0, len2 = routes.length; i2 < len2; i2++) {
|
|
3169
|
-
router.add(...routes[i2]);
|
|
3170
|
-
}
|
|
3171
|
-
res = router.match(method, path);
|
|
3172
|
-
} catch (e) {
|
|
3173
|
-
if (e instanceof UnsupportedPathError) {
|
|
3174
|
-
continue;
|
|
3175
|
-
}
|
|
3176
|
-
throw e;
|
|
3177
|
-
}
|
|
3178
|
-
this.match = router.match.bind(router);
|
|
3179
|
-
this.#routers = [router];
|
|
3180
|
-
this.#routes = void 0;
|
|
3181
|
-
break;
|
|
3182
|
-
}
|
|
3183
|
-
if (i === len) {
|
|
3184
|
-
throw new Error("Fatal error");
|
|
3185
|
-
}
|
|
3186
|
-
this.name = `SmartRouter + ${this.activeRouter.name}`;
|
|
3187
|
-
return res;
|
|
3188
|
-
}
|
|
3189
|
-
get activeRouter() {
|
|
3190
|
-
if (this.#routes || this.#routers.length !== 1) {
|
|
3191
|
-
throw new Error("No active router has been determined yet.");
|
|
3192
|
-
}
|
|
3193
|
-
return this.#routers[0];
|
|
3194
|
-
}
|
|
3195
|
-
};
|
|
3196
|
-
|
|
3197
|
-
// ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/router/trie-router/node.js
|
|
3198
|
-
var emptyParams = /* @__PURE__ */ Object.create(null);
|
|
3199
|
-
var Node2 = class _Node2 {
|
|
3200
|
-
#methods;
|
|
3201
|
-
#children;
|
|
3202
|
-
#patterns;
|
|
3203
|
-
#order = 0;
|
|
3204
|
-
#params = emptyParams;
|
|
3205
|
-
constructor(method, handler, children) {
|
|
3206
|
-
this.#children = children || /* @__PURE__ */ Object.create(null);
|
|
3207
|
-
this.#methods = [];
|
|
3208
|
-
if (method && handler) {
|
|
3209
|
-
const m = /* @__PURE__ */ Object.create(null);
|
|
3210
|
-
m[method] = { handler, possibleKeys: [], score: 0 };
|
|
3211
|
-
this.#methods = [m];
|
|
3212
|
-
}
|
|
3213
|
-
this.#patterns = [];
|
|
3214
|
-
}
|
|
3215
|
-
insert(method, path, handler) {
|
|
3216
|
-
this.#order = ++this.#order;
|
|
3217
|
-
let curNode = this;
|
|
3218
|
-
const parts = splitRoutingPath(path);
|
|
3219
|
-
const possibleKeys = [];
|
|
3220
|
-
for (let i = 0, len = parts.length; i < len; i++) {
|
|
3221
|
-
const p = parts[i];
|
|
3222
|
-
const nextP = parts[i + 1];
|
|
3223
|
-
const pattern = getPattern(p, nextP);
|
|
3224
|
-
const key = Array.isArray(pattern) ? pattern[0] : p;
|
|
3225
|
-
if (key in curNode.#children) {
|
|
3226
|
-
curNode = curNode.#children[key];
|
|
3227
|
-
if (pattern) {
|
|
3228
|
-
possibleKeys.push(pattern[1]);
|
|
3229
|
-
}
|
|
3230
|
-
continue;
|
|
3231
|
-
}
|
|
3232
|
-
curNode.#children[key] = new _Node2();
|
|
3233
|
-
if (pattern) {
|
|
3234
|
-
curNode.#patterns.push(pattern);
|
|
3235
|
-
possibleKeys.push(pattern[1]);
|
|
3236
|
-
}
|
|
3237
|
-
curNode = curNode.#children[key];
|
|
3238
|
-
}
|
|
3239
|
-
curNode.#methods.push({
|
|
3240
|
-
[method]: {
|
|
3241
|
-
handler,
|
|
3242
|
-
possibleKeys: possibleKeys.filter((v, i, a) => a.indexOf(v) === i),
|
|
3243
|
-
score: this.#order
|
|
3244
|
-
}
|
|
3245
|
-
});
|
|
3246
|
-
return curNode;
|
|
3247
|
-
}
|
|
3248
|
-
#getHandlerSets(node, method, nodeParams, params) {
|
|
3249
|
-
const handlerSets = [];
|
|
3250
|
-
for (let i = 0, len = node.#methods.length; i < len; i++) {
|
|
3251
|
-
const m = node.#methods[i];
|
|
3252
|
-
const handlerSet = m[method] || m[METHOD_NAME_ALL];
|
|
3253
|
-
const processedSet = {};
|
|
3254
|
-
if (handlerSet !== void 0) {
|
|
3255
|
-
handlerSet.params = /* @__PURE__ */ Object.create(null);
|
|
3256
|
-
handlerSets.push(handlerSet);
|
|
3257
|
-
if (nodeParams !== emptyParams || params && params !== emptyParams) {
|
|
3258
|
-
for (let i2 = 0, len2 = handlerSet.possibleKeys.length; i2 < len2; i2++) {
|
|
3259
|
-
const key = handlerSet.possibleKeys[i2];
|
|
3260
|
-
const processed = processedSet[handlerSet.score];
|
|
3261
|
-
handlerSet.params[key] = params?.[key] && !processed ? params[key] : nodeParams[key] ?? params?.[key];
|
|
3262
|
-
processedSet[handlerSet.score] = true;
|
|
3263
|
-
}
|
|
3264
|
-
}
|
|
3265
|
-
}
|
|
3266
|
-
}
|
|
3267
|
-
return handlerSets;
|
|
3268
|
-
}
|
|
3269
|
-
search(method, path) {
|
|
3270
|
-
const handlerSets = [];
|
|
3271
|
-
this.#params = emptyParams;
|
|
3272
|
-
const curNode = this;
|
|
3273
|
-
let curNodes = [curNode];
|
|
3274
|
-
const parts = splitPath(path);
|
|
3275
|
-
const curNodesQueue = [];
|
|
3276
|
-
for (let i = 0, len = parts.length; i < len; i++) {
|
|
3277
|
-
const part = parts[i];
|
|
3278
|
-
const isLast = i === len - 1;
|
|
3279
|
-
const tempNodes = [];
|
|
3280
|
-
for (let j = 0, len2 = curNodes.length; j < len2; j++) {
|
|
3281
|
-
const node = curNodes[j];
|
|
3282
|
-
const nextNode = node.#children[part];
|
|
3283
|
-
if (nextNode) {
|
|
3284
|
-
nextNode.#params = node.#params;
|
|
3285
|
-
if (isLast) {
|
|
3286
|
-
if (nextNode.#children["*"]) {
|
|
3287
|
-
handlerSets.push(
|
|
3288
|
-
...this.#getHandlerSets(nextNode.#children["*"], method, node.#params)
|
|
3289
|
-
);
|
|
3290
|
-
}
|
|
3291
|
-
handlerSets.push(...this.#getHandlerSets(nextNode, method, node.#params));
|
|
3292
|
-
} else {
|
|
3293
|
-
tempNodes.push(nextNode);
|
|
3294
|
-
}
|
|
3295
|
-
}
|
|
3296
|
-
for (let k = 0, len3 = node.#patterns.length; k < len3; k++) {
|
|
3297
|
-
const pattern = node.#patterns[k];
|
|
3298
|
-
const params = node.#params === emptyParams ? {} : { ...node.#params };
|
|
3299
|
-
if (pattern === "*") {
|
|
3300
|
-
const astNode = node.#children["*"];
|
|
3301
|
-
if (astNode) {
|
|
3302
|
-
handlerSets.push(...this.#getHandlerSets(astNode, method, node.#params));
|
|
3303
|
-
astNode.#params = params;
|
|
3304
|
-
tempNodes.push(astNode);
|
|
3305
|
-
}
|
|
3306
|
-
continue;
|
|
3307
|
-
}
|
|
3308
|
-
const [key, name, matcher] = pattern;
|
|
3309
|
-
if (!part && !(matcher instanceof RegExp)) {
|
|
3310
|
-
continue;
|
|
3311
|
-
}
|
|
3312
|
-
const child = node.#children[key];
|
|
3313
|
-
const restPathString = parts.slice(i).join("/");
|
|
3314
|
-
if (matcher instanceof RegExp) {
|
|
3315
|
-
const m = matcher.exec(restPathString);
|
|
3316
|
-
if (m) {
|
|
3317
|
-
params[name] = m[0];
|
|
3318
|
-
handlerSets.push(...this.#getHandlerSets(child, method, node.#params, params));
|
|
3319
|
-
if (Object.keys(child.#children).length) {
|
|
3320
|
-
child.#params = params;
|
|
3321
|
-
const componentCount = m[0].match(/\//)?.length ?? 0;
|
|
3322
|
-
const targetCurNodes = curNodesQueue[componentCount] ||= [];
|
|
3323
|
-
targetCurNodes.push(child);
|
|
3324
|
-
}
|
|
3325
|
-
continue;
|
|
3326
|
-
}
|
|
3327
|
-
}
|
|
3328
|
-
if (matcher === true || matcher.test(part)) {
|
|
3329
|
-
params[name] = part;
|
|
3330
|
-
if (isLast) {
|
|
3331
|
-
handlerSets.push(...this.#getHandlerSets(child, method, params, node.#params));
|
|
3332
|
-
if (child.#children["*"]) {
|
|
3333
|
-
handlerSets.push(
|
|
3334
|
-
...this.#getHandlerSets(child.#children["*"], method, params, node.#params)
|
|
3335
|
-
);
|
|
3336
|
-
}
|
|
3337
|
-
} else {
|
|
3338
|
-
child.#params = params;
|
|
3339
|
-
tempNodes.push(child);
|
|
3340
|
-
}
|
|
3341
|
-
}
|
|
3342
|
-
}
|
|
3343
|
-
}
|
|
3344
|
-
curNodes = tempNodes.concat(curNodesQueue.shift() ?? []);
|
|
3345
|
-
}
|
|
3346
|
-
if (handlerSets.length > 1) {
|
|
3347
|
-
handlerSets.sort((a, b) => {
|
|
3348
|
-
return a.score - b.score;
|
|
3349
|
-
});
|
|
3350
|
-
}
|
|
3351
|
-
return [handlerSets.map(({ handler, params }) => [handler, params])];
|
|
3352
|
-
}
|
|
3353
|
-
};
|
|
3354
|
-
|
|
3355
|
-
// ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/router/trie-router/router.js
|
|
3356
|
-
var TrieRouter = class {
|
|
3357
|
-
name = "TrieRouter";
|
|
3358
|
-
#node;
|
|
3359
|
-
constructor() {
|
|
3360
|
-
this.#node = new Node2();
|
|
3361
|
-
}
|
|
3362
|
-
add(method, path, handler) {
|
|
3363
|
-
const results = checkOptionalParameter(path);
|
|
3364
|
-
if (results) {
|
|
3365
|
-
for (let i = 0, len = results.length; i < len; i++) {
|
|
3366
|
-
this.#node.insert(method, results[i], handler);
|
|
3367
|
-
}
|
|
3368
|
-
return;
|
|
3369
|
-
}
|
|
3370
|
-
this.#node.insert(method, path, handler);
|
|
3371
|
-
}
|
|
3372
|
-
match(method, path) {
|
|
3373
|
-
return this.#node.search(method, path);
|
|
3374
|
-
}
|
|
3375
|
-
};
|
|
3376
|
-
|
|
3377
|
-
// ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/hono.js
|
|
3378
|
-
var Hono2 = class extends Hono {
|
|
3379
|
-
/**
|
|
3380
|
-
* Creates an instance of the Hono class.
|
|
3381
|
-
*
|
|
3382
|
-
* @param options - Optional configuration options for the Hono instance.
|
|
3383
|
-
*/
|
|
3384
|
-
constructor(options = {}) {
|
|
3385
|
-
super(options);
|
|
3386
|
-
this.router = options.router ?? new SmartRouter({
|
|
3387
|
-
routers: [new RegExpRouter(), new TrieRouter()]
|
|
3388
|
-
});
|
|
3389
|
-
}
|
|
3390
|
-
};
|
|
3391
|
-
|
|
3392
|
-
// src/server.ts
|
|
3393
|
-
async function handleError2(context, pluginOptions, error) {
|
|
3394
|
-
console.error(error);
|
|
3395
|
-
const loggerError = transformError(context, error);
|
|
3396
|
-
if (pluginOptions.postCommentOnError && loggerError) {
|
|
3397
|
-
await context.commentHandler.postComment(context, loggerError);
|
|
3398
|
-
}
|
|
3399
|
-
throw new HTTPException(500, { message: "Unexpected error" });
|
|
3400
|
-
}
|
|
3401
|
-
function createPlugin(handler, manifest, options) {
|
|
3402
|
-
const pluginOptions = getPluginOptions(options);
|
|
3403
|
-
const app = new Hono2();
|
|
3404
|
-
app.get("/manifest.json", (ctx) => {
|
|
3405
|
-
return ctx.json(manifest);
|
|
3406
|
-
});
|
|
3407
|
-
app.post("/", async function appPost(ctx) {
|
|
3408
|
-
if (ctx.req.header("content-type") !== "application/json") {
|
|
3409
|
-
throw new HTTPException(400, { message: "Content-Type must be application/json" });
|
|
3410
|
-
}
|
|
3411
|
-
const body = await ctx.req.json();
|
|
3412
|
-
const inputSchemaErrors = [...Value4.Errors(inputSchema, body)];
|
|
3413
|
-
if (inputSchemaErrors.length) {
|
|
3414
|
-
console.dir(inputSchemaErrors, { depth: null });
|
|
3415
|
-
throw new HTTPException(400, { message: "Invalid body" });
|
|
3416
|
-
}
|
|
3417
|
-
const signature = body.signature;
|
|
3418
|
-
if (!pluginOptions.bypassSignatureVerification && !await verifySignature(pluginOptions.kernelPublicKey, body, signature)) {
|
|
3419
|
-
throw new HTTPException(400, { message: "Invalid signature" });
|
|
3420
|
-
}
|
|
3421
|
-
const inputs = Value4.Decode(inputSchema, body);
|
|
3422
|
-
let config2;
|
|
3423
|
-
if (pluginOptions.settingsSchema) {
|
|
3424
|
-
try {
|
|
3425
|
-
config2 = Value4.Decode(pluginOptions.settingsSchema, Value4.Default(pluginOptions.settingsSchema, inputs.settings));
|
|
3426
|
-
} catch (e) {
|
|
3427
|
-
console.dir(...Value4.Errors(pluginOptions.settingsSchema, inputs.settings), { depth: null });
|
|
3428
|
-
throw e;
|
|
3429
|
-
}
|
|
3430
|
-
} else {
|
|
3431
|
-
config2 = inputs.settings;
|
|
3432
|
-
}
|
|
3433
|
-
let env2;
|
|
3434
|
-
const honoEnvironment = env(ctx);
|
|
3435
|
-
if (pluginOptions.envSchema) {
|
|
3436
|
-
try {
|
|
3437
|
-
env2 = Value4.Decode(pluginOptions.envSchema, Value4.Default(pluginOptions.envSchema, honoEnvironment));
|
|
3438
|
-
} catch (e) {
|
|
3439
|
-
console.dir(...Value4.Errors(pluginOptions.envSchema, honoEnvironment), { depth: null });
|
|
3440
|
-
throw e;
|
|
3441
|
-
}
|
|
3442
|
-
} else {
|
|
3443
|
-
env2 = ctx.env;
|
|
701
|
+
} else {
|
|
702
|
+
env = ctx.env;
|
|
3444
703
|
}
|
|
3445
704
|
const workerName = new URL(inputs.ref).hostname.split(".")[0];
|
|
3446
|
-
PluginRuntimeInfo.getInstance({ ...
|
|
705
|
+
PluginRuntimeInfo.getInstance({ ...env, CLOUDFLARE_WORKER_NAME: workerName });
|
|
3447
706
|
const command = getCommand(inputs, pluginOptions);
|
|
3448
707
|
const context = {
|
|
3449
708
|
eventName: inputs.eventName,
|
|
@@ -3453,8 +712,8 @@ function createPlugin(handler, manifest, options) {
|
|
|
3453
712
|
ubiquityKernelToken: inputs.ubiquityKernelToken,
|
|
3454
713
|
octokit: new customOctokit({ auth: inputs.authToken }),
|
|
3455
714
|
config: config2,
|
|
3456
|
-
env
|
|
3457
|
-
logger: new
|
|
715
|
+
env,
|
|
716
|
+
logger: new Logs2(pluginOptions.logLevel),
|
|
3458
717
|
commentHandler: new CommentHandler()
|
|
3459
718
|
};
|
|
3460
719
|
try {
|
|
@@ -3567,6 +826,10 @@ async function fetchWithRetry(url, options, maxRetries) {
|
|
|
3567
826
|
throw error;
|
|
3568
827
|
} catch (error) {
|
|
3569
828
|
lastError = error;
|
|
829
|
+
const status = typeof error.status === "number" ? error.status : void 0;
|
|
830
|
+
if (typeof status === "number" && status < 500) {
|
|
831
|
+
throw error;
|
|
832
|
+
}
|
|
3570
833
|
if (attempt >= maxRetries) throw error;
|
|
3571
834
|
await sleep(getRetryDelayMs(attempt));
|
|
3572
835
|
attempt += 1;
|
|
@@ -3642,6 +905,13 @@ function parseEventData(data) {
|
|
|
3642
905
|
try {
|
|
3643
906
|
return JSON.parse(data);
|
|
3644
907
|
} catch (error) {
|
|
908
|
+
if (data.includes("\n")) {
|
|
909
|
+
const collapsed = data.replace(/\n/g, EMPTY_STRING);
|
|
910
|
+
try {
|
|
911
|
+
return JSON.parse(collapsed);
|
|
912
|
+
} catch {
|
|
913
|
+
}
|
|
914
|
+
}
|
|
3645
915
|
const message = error instanceof Error ? error.message : String(error);
|
|
3646
916
|
const preview = data.length > 200 ? `${data.slice(0, 200)}...` : data;
|
|
3647
917
|
throw new Error(`LLM stream parse error: ${message}. Data: ${preview}`);
|