@ubiquity-os/plugin-sdk 3.5.5 → 3.6.2
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 +35 -93
- package/dist/configuration.d.mts +2 -2
- package/dist/configuration.d.ts +2 -2
- package/dist/configuration.js +2633 -13
- package/dist/configuration.mjs +2633 -3
- package/dist/{context-DOUnUNNN.d.ts → context-BbEmsEct.d.ts} +2 -0
- package/dist/{context-3Ck9sBZI.d.mts → context-sqbr2o6i.d.mts} +2 -0
- package/dist/index.d.mts +6 -3
- package/dist/index.d.ts +6 -3
- package/dist/index.js +2242 -94
- package/dist/index.mjs +2237 -90
- package/dist/llm.d.mts +23 -0
- package/dist/llm.d.ts +23 -0
- package/dist/llm.js +109 -0
- package/dist/llm.mjs +84 -0
- package/dist/octokit.d.mts +2 -2
- package/dist/octokit.d.ts +2 -2
- package/dist/octokit.js +164 -2
- package/dist/octokit.mjs +163 -1
- package/dist/signature.d.mts +1 -0
- package/dist/signature.d.ts +1 -0
- package/dist/signature.js +1 -0
- package/dist/signature.mjs +1 -0
- package/package.json +51 -40
package/dist/index.mjs
CHANGED
|
@@ -2,38 +2,422 @@
|
|
|
2
2
|
import * as core from "@actions/core";
|
|
3
3
|
import * as github2 from "@actions/github";
|
|
4
4
|
import { Value as Value3 } from "@sinclair/typebox/value";
|
|
5
|
-
|
|
5
|
+
|
|
6
|
+
// ../../node_modules/@ubiquity-os/ubiquity-os-logger/dist/index.js
|
|
7
|
+
var COLORS = {
|
|
8
|
+
reset: "\x1B[0m",
|
|
9
|
+
bright: "\x1B[1m",
|
|
10
|
+
dim: "\x1B[2m",
|
|
11
|
+
underscore: "\x1B[4m",
|
|
12
|
+
blink: "\x1B[5m",
|
|
13
|
+
reverse: "\x1B[7m",
|
|
14
|
+
hidden: "\x1B[8m",
|
|
15
|
+
fgBlack: "\x1B[30m",
|
|
16
|
+
fgRed: "\x1B[31m",
|
|
17
|
+
fgGreen: "\x1B[32m",
|
|
18
|
+
fgYellow: "\x1B[33m",
|
|
19
|
+
fgBlue: "\x1B[34m",
|
|
20
|
+
fgMagenta: "\x1B[35m",
|
|
21
|
+
fgCyan: "\x1B[36m",
|
|
22
|
+
fgWhite: "\x1B[37m",
|
|
23
|
+
bgBlack: "\x1B[40m",
|
|
24
|
+
bgRed: "\x1B[41m",
|
|
25
|
+
bgGreen: "\x1B[42m",
|
|
26
|
+
bgYellow: "\x1B[43m",
|
|
27
|
+
bgBlue: "\x1B[44m",
|
|
28
|
+
bgMagenta: "\x1B[45m",
|
|
29
|
+
bgCyan: "\x1B[46m",
|
|
30
|
+
bgWhite: "\x1B[47m"
|
|
31
|
+
};
|
|
32
|
+
var LOG_LEVEL = {
|
|
33
|
+
FATAL: "fatal",
|
|
34
|
+
ERROR: "error",
|
|
35
|
+
WARN: "warn",
|
|
36
|
+
INFO: "info",
|
|
37
|
+
VERBOSE: "verbose",
|
|
38
|
+
DEBUG: "debug"
|
|
39
|
+
};
|
|
40
|
+
var PrettyLogs = class {
|
|
41
|
+
constructor() {
|
|
42
|
+
this.ok = this.ok.bind(this);
|
|
43
|
+
this.info = this.info.bind(this);
|
|
44
|
+
this.error = this.error.bind(this);
|
|
45
|
+
this.fatal = this.fatal.bind(this);
|
|
46
|
+
this.warn = this.warn.bind(this);
|
|
47
|
+
this.debug = this.debug.bind(this);
|
|
48
|
+
this.verbose = this.verbose.bind(this);
|
|
49
|
+
}
|
|
50
|
+
fatal(message, metadata) {
|
|
51
|
+
this._logWithStack(LOG_LEVEL.FATAL, message, metadata);
|
|
52
|
+
}
|
|
53
|
+
error(message, metadata) {
|
|
54
|
+
this._logWithStack(LOG_LEVEL.ERROR, message, metadata);
|
|
55
|
+
}
|
|
56
|
+
warn(message, metadata) {
|
|
57
|
+
this._logWithStack(LOG_LEVEL.WARN, message, metadata);
|
|
58
|
+
}
|
|
59
|
+
ok(message, metadata) {
|
|
60
|
+
this._logWithStack("ok", message, metadata);
|
|
61
|
+
}
|
|
62
|
+
info(message, metadata) {
|
|
63
|
+
this._logWithStack(LOG_LEVEL.INFO, message, metadata);
|
|
64
|
+
}
|
|
65
|
+
debug(message, metadata) {
|
|
66
|
+
this._logWithStack(LOG_LEVEL.DEBUG, message, metadata);
|
|
67
|
+
}
|
|
68
|
+
verbose(message, metadata) {
|
|
69
|
+
this._logWithStack(LOG_LEVEL.VERBOSE, message, metadata);
|
|
70
|
+
}
|
|
71
|
+
_logWithStack(type, message, metaData) {
|
|
72
|
+
this._log(type, message);
|
|
73
|
+
if (typeof metaData === "string") {
|
|
74
|
+
this._log(type, metaData);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (metaData) {
|
|
78
|
+
const metadata = metaData;
|
|
79
|
+
let stack = metadata?.error?.stack || metadata?.stack;
|
|
80
|
+
if (!stack) {
|
|
81
|
+
const stackTrace = new Error().stack?.split("\n");
|
|
82
|
+
if (stackTrace) {
|
|
83
|
+
stackTrace.splice(0, 4);
|
|
84
|
+
stack = stackTrace.filter((line) => line.includes(".ts:")).join("\n");
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const newMetadata = { ...metadata };
|
|
88
|
+
delete newMetadata.message;
|
|
89
|
+
delete newMetadata.name;
|
|
90
|
+
delete newMetadata.stack;
|
|
91
|
+
if (!this._isEmpty(newMetadata)) {
|
|
92
|
+
this._log(type, newMetadata);
|
|
93
|
+
}
|
|
94
|
+
if (typeof stack == "string") {
|
|
95
|
+
const prettyStack = this._formatStackTrace(stack, 1);
|
|
96
|
+
const colorizedStack = this._colorizeText(prettyStack, COLORS.dim);
|
|
97
|
+
this._log(type, colorizedStack);
|
|
98
|
+
} else if (stack) {
|
|
99
|
+
const prettyStack = this._formatStackTrace(stack.join("\n"), 1);
|
|
100
|
+
const colorizedStack = this._colorizeText(prettyStack, COLORS.dim);
|
|
101
|
+
this._log(type, colorizedStack);
|
|
102
|
+
} else {
|
|
103
|
+
throw new Error("Stack is null");
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
_colorizeText(text, color) {
|
|
108
|
+
if (!color) {
|
|
109
|
+
throw new Error(`Invalid color: ${color}`);
|
|
110
|
+
}
|
|
111
|
+
return color.concat(text).concat(COLORS.reset);
|
|
112
|
+
}
|
|
113
|
+
_formatStackTrace(stack, linesToRemove = 0, prefix = "") {
|
|
114
|
+
const lines = stack.split("\n");
|
|
115
|
+
for (let i = 0; i < linesToRemove; i++) {
|
|
116
|
+
lines.shift();
|
|
117
|
+
}
|
|
118
|
+
return lines.map((line) => `${prefix}${line.replace(/\s*at\s*/, " \u21B3 ")}`).join("\n");
|
|
119
|
+
}
|
|
120
|
+
_isEmpty(obj) {
|
|
121
|
+
return !Reflect.ownKeys(obj).some((key) => typeof obj[String(key)] !== "function");
|
|
122
|
+
}
|
|
123
|
+
_log(type, message) {
|
|
124
|
+
const defaultSymbols = {
|
|
125
|
+
fatal: "\xD7",
|
|
126
|
+
ok: "\u2713",
|
|
127
|
+
warn: "\u26A0",
|
|
128
|
+
error: "\u26A0",
|
|
129
|
+
info: "\u203A",
|
|
130
|
+
debug: "\u203A\u203A",
|
|
131
|
+
verbose: "\u{1F4AC}"
|
|
132
|
+
};
|
|
133
|
+
const symbol = defaultSymbols[type];
|
|
134
|
+
const messageFormatted = typeof message === "string" ? message : JSON.stringify(message, null, 2);
|
|
135
|
+
const lines = messageFormatted.split("\n");
|
|
136
|
+
const logString = lines.map((line, index) => {
|
|
137
|
+
const prefix = index === 0 ? ` ${symbol}` : ` ${" ".repeat(symbol.length)}`;
|
|
138
|
+
return `${prefix} ${line}`;
|
|
139
|
+
}).join("\n");
|
|
140
|
+
const fullLogString = logString;
|
|
141
|
+
const colorMap = {
|
|
142
|
+
fatal: ["error", COLORS.fgRed],
|
|
143
|
+
ok: ["log", COLORS.fgGreen],
|
|
144
|
+
warn: ["warn", COLORS.fgYellow],
|
|
145
|
+
error: ["warn", COLORS.fgYellow],
|
|
146
|
+
info: ["info", COLORS.dim],
|
|
147
|
+
debug: ["debug", COLORS.fgMagenta],
|
|
148
|
+
verbose: ["debug", COLORS.dim]
|
|
149
|
+
};
|
|
150
|
+
const _console = console[colorMap[type][0]];
|
|
151
|
+
if (typeof _console === "function" && fullLogString.length > 12) {
|
|
152
|
+
_console(this._colorizeText(fullLogString, colorMap[type][1]));
|
|
153
|
+
} else if (fullLogString.length <= 12) {
|
|
154
|
+
return;
|
|
155
|
+
} else {
|
|
156
|
+
throw new Error(fullLogString);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
var LogReturn = class {
|
|
161
|
+
logMessage;
|
|
162
|
+
metadata;
|
|
163
|
+
constructor(logMessage, metadata) {
|
|
164
|
+
this.logMessage = logMessage;
|
|
165
|
+
this.metadata = metadata;
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
var Logs = class _Logs {
|
|
169
|
+
_maxLevel = -1;
|
|
170
|
+
static console;
|
|
171
|
+
_log({ level, consoleLog, logMessage, metadata, type }) {
|
|
172
|
+
if (this._getNumericLevel(level) <= this._maxLevel) {
|
|
173
|
+
consoleLog(logMessage, metadata);
|
|
174
|
+
}
|
|
175
|
+
return new LogReturn(
|
|
176
|
+
{
|
|
177
|
+
raw: logMessage,
|
|
178
|
+
diff: this._diffColorCommentMessage(type, logMessage),
|
|
179
|
+
type,
|
|
180
|
+
level
|
|
181
|
+
},
|
|
182
|
+
metadata
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
_addDiagnosticInformation(metadata) {
|
|
186
|
+
if (!metadata) {
|
|
187
|
+
metadata = {};
|
|
188
|
+
} else if (typeof metadata !== "object") {
|
|
189
|
+
metadata = { message: metadata };
|
|
190
|
+
}
|
|
191
|
+
const stackLines = new Error().stack?.split("\n") || [];
|
|
192
|
+
if (stackLines.length > 3) {
|
|
193
|
+
const callerLine = stackLines[3];
|
|
194
|
+
const match = callerLine.match(/at (\S+)/);
|
|
195
|
+
if (match) {
|
|
196
|
+
metadata.caller = match[1];
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return metadata;
|
|
200
|
+
}
|
|
201
|
+
ok(log, metadata) {
|
|
202
|
+
metadata = this._addDiagnosticInformation(metadata);
|
|
203
|
+
return this._log({
|
|
204
|
+
level: LOG_LEVEL.INFO,
|
|
205
|
+
consoleLog: _Logs.console.ok,
|
|
206
|
+
logMessage: log,
|
|
207
|
+
metadata,
|
|
208
|
+
type: "ok"
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
info(log, metadata) {
|
|
212
|
+
metadata = this._addDiagnosticInformation(metadata);
|
|
213
|
+
return this._log({
|
|
214
|
+
level: LOG_LEVEL.INFO,
|
|
215
|
+
consoleLog: _Logs.console.info,
|
|
216
|
+
logMessage: log,
|
|
217
|
+
metadata,
|
|
218
|
+
type: "info"
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
warn(log, metadata) {
|
|
222
|
+
metadata = this._addDiagnosticInformation(metadata);
|
|
223
|
+
return this._log({
|
|
224
|
+
level: LOG_LEVEL.WARN,
|
|
225
|
+
consoleLog: _Logs.console.warn,
|
|
226
|
+
logMessage: log,
|
|
227
|
+
metadata,
|
|
228
|
+
type: "warn"
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
error(log, metadata) {
|
|
232
|
+
metadata = this._addDiagnosticInformation(metadata);
|
|
233
|
+
return this._log({
|
|
234
|
+
level: LOG_LEVEL.ERROR,
|
|
235
|
+
consoleLog: _Logs.console.error,
|
|
236
|
+
logMessage: log,
|
|
237
|
+
metadata,
|
|
238
|
+
type: "error"
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
debug(log, metadata) {
|
|
242
|
+
metadata = this._addDiagnosticInformation(metadata);
|
|
243
|
+
return this._log({
|
|
244
|
+
level: LOG_LEVEL.DEBUG,
|
|
245
|
+
consoleLog: _Logs.console.debug,
|
|
246
|
+
logMessage: log,
|
|
247
|
+
metadata,
|
|
248
|
+
type: "debug"
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
fatal(log, metadata) {
|
|
252
|
+
if (!metadata) {
|
|
253
|
+
metadata = _Logs.convertErrorsIntoObjects(new Error(log));
|
|
254
|
+
const stack = metadata.stack;
|
|
255
|
+
stack.splice(1, 1);
|
|
256
|
+
metadata.stack = stack;
|
|
257
|
+
}
|
|
258
|
+
if (metadata instanceof Error) {
|
|
259
|
+
metadata = _Logs.convertErrorsIntoObjects(metadata);
|
|
260
|
+
const stack = metadata.stack;
|
|
261
|
+
stack.splice(1, 1);
|
|
262
|
+
metadata.stack = stack;
|
|
263
|
+
}
|
|
264
|
+
metadata = this._addDiagnosticInformation(metadata);
|
|
265
|
+
return this._log({
|
|
266
|
+
level: LOG_LEVEL.FATAL,
|
|
267
|
+
consoleLog: _Logs.console.fatal,
|
|
268
|
+
logMessage: log,
|
|
269
|
+
metadata,
|
|
270
|
+
type: "fatal"
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
verbose(log, metadata) {
|
|
274
|
+
metadata = this._addDiagnosticInformation(metadata);
|
|
275
|
+
return this._log({
|
|
276
|
+
level: LOG_LEVEL.VERBOSE,
|
|
277
|
+
consoleLog: _Logs.console.verbose,
|
|
278
|
+
logMessage: log,
|
|
279
|
+
metadata,
|
|
280
|
+
type: "verbose"
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
constructor(logLevel) {
|
|
284
|
+
this._maxLevel = this._getNumericLevel(logLevel);
|
|
285
|
+
_Logs.console = new PrettyLogs();
|
|
286
|
+
}
|
|
287
|
+
_diffColorCommentMessage(type, message) {
|
|
288
|
+
const diffPrefix = {
|
|
289
|
+
fatal: "> [!CAUTION]",
|
|
290
|
+
error: "> [!CAUTION]",
|
|
291
|
+
warn: "> [!WARNING]",
|
|
292
|
+
ok: "> [!TIP]",
|
|
293
|
+
info: "> [!NOTE]",
|
|
294
|
+
debug: "> [!IMPORTANT]",
|
|
295
|
+
verbose: "> [!NOTE]"
|
|
296
|
+
};
|
|
297
|
+
const selected = diffPrefix[type];
|
|
298
|
+
if (selected) {
|
|
299
|
+
message = message.trim().split("\n").map((line) => `> ${line}`).join("\n");
|
|
300
|
+
}
|
|
301
|
+
return [selected, message].join("\n");
|
|
302
|
+
}
|
|
303
|
+
_getNumericLevel(level) {
|
|
304
|
+
switch (level) {
|
|
305
|
+
case LOG_LEVEL.FATAL:
|
|
306
|
+
return 0;
|
|
307
|
+
case LOG_LEVEL.ERROR:
|
|
308
|
+
return 1;
|
|
309
|
+
case LOG_LEVEL.WARN:
|
|
310
|
+
return 2;
|
|
311
|
+
case LOG_LEVEL.INFO:
|
|
312
|
+
return 3;
|
|
313
|
+
case LOG_LEVEL.VERBOSE:
|
|
314
|
+
return 4;
|
|
315
|
+
case LOG_LEVEL.DEBUG:
|
|
316
|
+
return 5;
|
|
317
|
+
default:
|
|
318
|
+
return -1;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
static convertErrorsIntoObjects(obj) {
|
|
322
|
+
if (obj instanceof Error) {
|
|
323
|
+
return {
|
|
324
|
+
message: obj.message,
|
|
325
|
+
name: obj.name,
|
|
326
|
+
stack: obj.stack ? obj.stack.split("\n") : null
|
|
327
|
+
};
|
|
328
|
+
} else if (typeof obj === "object" && obj !== null) {
|
|
329
|
+
const keys = Object.keys(obj);
|
|
330
|
+
keys.forEach((key) => {
|
|
331
|
+
obj[key] = this.convertErrorsIntoObjects(obj[key]);
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
return obj;
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
// src/actions.ts
|
|
6
339
|
import { config } from "dotenv";
|
|
7
340
|
|
|
8
341
|
// src/helpers/runtime-info.ts
|
|
9
342
|
import github from "@actions/github";
|
|
10
|
-
|
|
343
|
+
|
|
344
|
+
// ../../node_modules/hono/dist/helper/adapter/index.js
|
|
345
|
+
var env = (c, runtime) => {
|
|
346
|
+
const global = globalThis;
|
|
347
|
+
const globalEnv = global?.process?.env;
|
|
348
|
+
runtime ??= getRuntimeKey();
|
|
349
|
+
const runtimeEnvHandlers = {
|
|
350
|
+
bun: () => globalEnv,
|
|
351
|
+
node: () => globalEnv,
|
|
352
|
+
"edge-light": () => globalEnv,
|
|
353
|
+
deno: () => {
|
|
354
|
+
return Deno.env.toObject();
|
|
355
|
+
},
|
|
356
|
+
workerd: () => c.env,
|
|
357
|
+
fastly: () => ({}),
|
|
358
|
+
other: () => ({})
|
|
359
|
+
};
|
|
360
|
+
return runtimeEnvHandlers[runtime]();
|
|
361
|
+
};
|
|
362
|
+
var knownUserAgents = {
|
|
363
|
+
deno: "Deno",
|
|
364
|
+
bun: "Bun",
|
|
365
|
+
workerd: "Cloudflare-Workers",
|
|
366
|
+
node: "Node.js"
|
|
367
|
+
};
|
|
368
|
+
var getRuntimeKey = () => {
|
|
369
|
+
const global = globalThis;
|
|
370
|
+
const userAgentSupported = typeof navigator !== "undefined" && typeof navigator.userAgent === "string";
|
|
371
|
+
if (userAgentSupported) {
|
|
372
|
+
for (const [runtimeKey, userAgent] of Object.entries(knownUserAgents)) {
|
|
373
|
+
if (checkUserAgentEquals(userAgent)) {
|
|
374
|
+
return runtimeKey;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
if (typeof global?.EdgeRuntime === "string") {
|
|
379
|
+
return "edge-light";
|
|
380
|
+
}
|
|
381
|
+
if (global?.fastly !== void 0) {
|
|
382
|
+
return "fastly";
|
|
383
|
+
}
|
|
384
|
+
if (global?.process?.release?.name === "node") {
|
|
385
|
+
return "node";
|
|
386
|
+
}
|
|
387
|
+
return "other";
|
|
388
|
+
};
|
|
389
|
+
var checkUserAgentEquals = (platform) => {
|
|
390
|
+
const userAgent = navigator.userAgent;
|
|
391
|
+
return userAgent.startsWith(platform);
|
|
392
|
+
};
|
|
393
|
+
|
|
394
|
+
// src/helpers/runtime-info.ts
|
|
11
395
|
var PluginRuntimeInfo = class _PluginRuntimeInfo {
|
|
12
396
|
static _instance = null;
|
|
13
397
|
_env = {};
|
|
14
|
-
constructor(
|
|
15
|
-
if (
|
|
16
|
-
this._env =
|
|
398
|
+
constructor(env2) {
|
|
399
|
+
if (env2) {
|
|
400
|
+
this._env = env2;
|
|
17
401
|
}
|
|
18
402
|
}
|
|
19
|
-
static getInstance(
|
|
403
|
+
static getInstance(env2) {
|
|
20
404
|
if (!_PluginRuntimeInfo._instance) {
|
|
21
405
|
switch (getRuntimeKey()) {
|
|
22
406
|
case "workerd":
|
|
23
|
-
_PluginRuntimeInfo._instance = new CfRuntimeInfo(
|
|
407
|
+
_PluginRuntimeInfo._instance = new CfRuntimeInfo(env2);
|
|
24
408
|
break;
|
|
25
409
|
case "deno":
|
|
26
410
|
if (process.env.CI) {
|
|
27
|
-
_PluginRuntimeInfo._instance = new NodeRuntimeInfo(
|
|
411
|
+
_PluginRuntimeInfo._instance = new NodeRuntimeInfo(env2);
|
|
28
412
|
} else {
|
|
29
|
-
_PluginRuntimeInfo._instance = new DenoRuntimeInfo(
|
|
413
|
+
_PluginRuntimeInfo._instance = new DenoRuntimeInfo(env2);
|
|
30
414
|
}
|
|
31
415
|
break;
|
|
32
416
|
case "node":
|
|
33
|
-
_PluginRuntimeInfo._instance = new NodeRuntimeInfo(
|
|
417
|
+
_PluginRuntimeInfo._instance = new NodeRuntimeInfo(env2);
|
|
34
418
|
break;
|
|
35
419
|
default:
|
|
36
|
-
_PluginRuntimeInfo._instance = new NodeRuntimeInfo(
|
|
420
|
+
_PluginRuntimeInfo._instance = new NodeRuntimeInfo(env2);
|
|
37
421
|
break;
|
|
38
422
|
}
|
|
39
423
|
}
|
|
@@ -98,9 +482,6 @@ var DenoRuntimeInfo = class extends PluginRuntimeInfo {
|
|
|
98
482
|
}
|
|
99
483
|
};
|
|
100
484
|
|
|
101
|
-
// src/util.ts
|
|
102
|
-
import { LOG_LEVEL } from "@ubiquity-os/ubiquity-os-logger";
|
|
103
|
-
|
|
104
485
|
// src/constants.ts
|
|
105
486
|
var KERNEL_PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
|
|
106
487
|
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAs96DOU+JqM8SyNXOB6u3
|
|
@@ -297,13 +678,12 @@ ${metadataContent}
|
|
|
297
678
|
};
|
|
298
679
|
|
|
299
680
|
// src/error.ts
|
|
300
|
-
import { LogReturn as LogReturn2 } from "@ubiquity-os/ubiquity-os-logger";
|
|
301
681
|
function transformError(context2, error) {
|
|
302
682
|
let loggerError;
|
|
303
683
|
if (error instanceof AggregateError) {
|
|
304
684
|
loggerError = context2.logger.error(
|
|
305
685
|
error.errors.map((err) => {
|
|
306
|
-
if (err instanceof
|
|
686
|
+
if (err instanceof LogReturn) {
|
|
307
687
|
return err.logMessage.raw;
|
|
308
688
|
} else if (err instanceof Error) {
|
|
309
689
|
return err.message;
|
|
@@ -313,7 +693,7 @@ function transformError(context2, error) {
|
|
|
313
693
|
}).join("\n\n"),
|
|
314
694
|
{ error }
|
|
315
695
|
);
|
|
316
|
-
} else if (error instanceof Error || error instanceof
|
|
696
|
+
} else if (error instanceof Error || error instanceof LogReturn) {
|
|
317
697
|
loggerError = error;
|
|
318
698
|
} else {
|
|
319
699
|
loggerError = context2.logger.error(String(error));
|
|
@@ -353,7 +733,169 @@ function decompressString(compressed) {
|
|
|
353
733
|
|
|
354
734
|
// src/octokit.ts
|
|
355
735
|
import { Octokit } from "@octokit/core";
|
|
356
|
-
|
|
736
|
+
|
|
737
|
+
// ../../node_modules/@octokit/plugin-paginate-graphql/dist-bundle/index.js
|
|
738
|
+
var generateMessage = (path, cursorValue) => `The cursor at "${path.join(
|
|
739
|
+
","
|
|
740
|
+
)}" did not change its value "${cursorValue}" after a page transition. Please make sure your that your query is set up correctly.`;
|
|
741
|
+
var MissingCursorChange = class extends Error {
|
|
742
|
+
constructor(pageInfo, cursorValue) {
|
|
743
|
+
super(generateMessage(pageInfo.pathInQuery, cursorValue));
|
|
744
|
+
this.pageInfo = pageInfo;
|
|
745
|
+
this.cursorValue = cursorValue;
|
|
746
|
+
if (Error.captureStackTrace) {
|
|
747
|
+
Error.captureStackTrace(this, this.constructor);
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
name = "MissingCursorChangeError";
|
|
751
|
+
};
|
|
752
|
+
var MissingPageInfo = class extends Error {
|
|
753
|
+
constructor(response) {
|
|
754
|
+
super(
|
|
755
|
+
`No pageInfo property found in response. Please make sure to specify the pageInfo in your query. Response-Data: ${JSON.stringify(
|
|
756
|
+
response,
|
|
757
|
+
null,
|
|
758
|
+
2
|
|
759
|
+
)}`
|
|
760
|
+
);
|
|
761
|
+
this.response = response;
|
|
762
|
+
if (Error.captureStackTrace) {
|
|
763
|
+
Error.captureStackTrace(this, this.constructor);
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
name = "MissingPageInfo";
|
|
767
|
+
};
|
|
768
|
+
var isObject = (value) => Object.prototype.toString.call(value) === "[object Object]";
|
|
769
|
+
function findPaginatedResourcePath(responseData) {
|
|
770
|
+
const paginatedResourcePath = deepFindPathToProperty(
|
|
771
|
+
responseData,
|
|
772
|
+
"pageInfo"
|
|
773
|
+
);
|
|
774
|
+
if (paginatedResourcePath.length === 0) {
|
|
775
|
+
throw new MissingPageInfo(responseData);
|
|
776
|
+
}
|
|
777
|
+
return paginatedResourcePath;
|
|
778
|
+
}
|
|
779
|
+
var deepFindPathToProperty = (object, searchProp, path = []) => {
|
|
780
|
+
for (const key of Object.keys(object)) {
|
|
781
|
+
const currentPath = [...path, key];
|
|
782
|
+
const currentValue = object[key];
|
|
783
|
+
if (isObject(currentValue)) {
|
|
784
|
+
if (currentValue.hasOwnProperty(searchProp)) {
|
|
785
|
+
return currentPath;
|
|
786
|
+
}
|
|
787
|
+
const result = deepFindPathToProperty(
|
|
788
|
+
currentValue,
|
|
789
|
+
searchProp,
|
|
790
|
+
currentPath
|
|
791
|
+
);
|
|
792
|
+
if (result.length > 0) {
|
|
793
|
+
return result;
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
return [];
|
|
798
|
+
};
|
|
799
|
+
var get = (object, path) => {
|
|
800
|
+
return path.reduce((current, nextProperty) => current[nextProperty], object);
|
|
801
|
+
};
|
|
802
|
+
var set = (object, path, mutator) => {
|
|
803
|
+
const lastProperty = path[path.length - 1];
|
|
804
|
+
const parentPath = [...path].slice(0, -1);
|
|
805
|
+
const parent = get(object, parentPath);
|
|
806
|
+
if (typeof mutator === "function") {
|
|
807
|
+
parent[lastProperty] = mutator(parent[lastProperty]);
|
|
808
|
+
} else {
|
|
809
|
+
parent[lastProperty] = mutator;
|
|
810
|
+
}
|
|
811
|
+
};
|
|
812
|
+
var extractPageInfos = (responseData) => {
|
|
813
|
+
const pageInfoPath = findPaginatedResourcePath(responseData);
|
|
814
|
+
return {
|
|
815
|
+
pathInQuery: pageInfoPath,
|
|
816
|
+
pageInfo: get(responseData, [...pageInfoPath, "pageInfo"])
|
|
817
|
+
};
|
|
818
|
+
};
|
|
819
|
+
var isForwardSearch = (givenPageInfo) => {
|
|
820
|
+
return givenPageInfo.hasOwnProperty("hasNextPage");
|
|
821
|
+
};
|
|
822
|
+
var getCursorFrom = (pageInfo) => isForwardSearch(pageInfo) ? pageInfo.endCursor : pageInfo.startCursor;
|
|
823
|
+
var hasAnotherPage = (pageInfo) => isForwardSearch(pageInfo) ? pageInfo.hasNextPage : pageInfo.hasPreviousPage;
|
|
824
|
+
var createIterator = (octokit) => {
|
|
825
|
+
return (query, initialParameters = {}) => {
|
|
826
|
+
let nextPageExists = true;
|
|
827
|
+
let parameters = { ...initialParameters };
|
|
828
|
+
return {
|
|
829
|
+
[Symbol.asyncIterator]: () => ({
|
|
830
|
+
async next() {
|
|
831
|
+
if (!nextPageExists) return { done: true, value: {} };
|
|
832
|
+
const response = await octokit.graphql(
|
|
833
|
+
query,
|
|
834
|
+
parameters
|
|
835
|
+
);
|
|
836
|
+
const pageInfoContext = extractPageInfos(response);
|
|
837
|
+
const nextCursorValue = getCursorFrom(pageInfoContext.pageInfo);
|
|
838
|
+
nextPageExists = hasAnotherPage(pageInfoContext.pageInfo);
|
|
839
|
+
if (nextPageExists && nextCursorValue === parameters.cursor) {
|
|
840
|
+
throw new MissingCursorChange(pageInfoContext, nextCursorValue);
|
|
841
|
+
}
|
|
842
|
+
parameters = {
|
|
843
|
+
...parameters,
|
|
844
|
+
cursor: nextCursorValue
|
|
845
|
+
};
|
|
846
|
+
return { done: false, value: response };
|
|
847
|
+
}
|
|
848
|
+
})
|
|
849
|
+
};
|
|
850
|
+
};
|
|
851
|
+
};
|
|
852
|
+
var mergeResponses = (response1, response2) => {
|
|
853
|
+
if (Object.keys(response1).length === 0) {
|
|
854
|
+
return Object.assign(response1, response2);
|
|
855
|
+
}
|
|
856
|
+
const path = findPaginatedResourcePath(response1);
|
|
857
|
+
const nodesPath = [...path, "nodes"];
|
|
858
|
+
const newNodes = get(response2, nodesPath);
|
|
859
|
+
if (newNodes) {
|
|
860
|
+
set(response1, nodesPath, (values) => {
|
|
861
|
+
return [...values, ...newNodes];
|
|
862
|
+
});
|
|
863
|
+
}
|
|
864
|
+
const edgesPath = [...path, "edges"];
|
|
865
|
+
const newEdges = get(response2, edgesPath);
|
|
866
|
+
if (newEdges) {
|
|
867
|
+
set(response1, edgesPath, (values) => {
|
|
868
|
+
return [...values, ...newEdges];
|
|
869
|
+
});
|
|
870
|
+
}
|
|
871
|
+
const pageInfoPath = [...path, "pageInfo"];
|
|
872
|
+
set(response1, pageInfoPath, get(response2, pageInfoPath));
|
|
873
|
+
return response1;
|
|
874
|
+
};
|
|
875
|
+
var createPaginate = (octokit) => {
|
|
876
|
+
const iterator = createIterator(octokit);
|
|
877
|
+
return async (query, initialParameters = {}) => {
|
|
878
|
+
let mergedResponse = {};
|
|
879
|
+
for await (const response of iterator(
|
|
880
|
+
query,
|
|
881
|
+
initialParameters
|
|
882
|
+
)) {
|
|
883
|
+
mergedResponse = mergeResponses(mergedResponse, response);
|
|
884
|
+
}
|
|
885
|
+
return mergedResponse;
|
|
886
|
+
};
|
|
887
|
+
};
|
|
888
|
+
function paginateGraphQL(octokit) {
|
|
889
|
+
return {
|
|
890
|
+
graphql: Object.assign(octokit.graphql, {
|
|
891
|
+
paginate: Object.assign(createPaginate(octokit), {
|
|
892
|
+
iterator: createIterator(octokit)
|
|
893
|
+
})
|
|
894
|
+
})
|
|
895
|
+
};
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
// src/octokit.ts
|
|
357
899
|
import { paginateRest } from "@octokit/plugin-paginate-rest";
|
|
358
900
|
import { restEndpointMethods } from "@octokit/plugin-rest-endpoint-methods";
|
|
359
901
|
import { retry } from "@octokit/plugin-retry";
|
|
@@ -387,6 +929,7 @@ async function verifySignature(publicKeyPem, inputs, signature) {
|
|
|
387
929
|
eventPayload: inputs.eventPayload,
|
|
388
930
|
settings: inputs.settings,
|
|
389
931
|
authToken: inputs.authToken,
|
|
932
|
+
ubiquityKernelToken: inputs.ubiquityKernelToken,
|
|
390
933
|
ref: inputs.ref,
|
|
391
934
|
command: inputs.command
|
|
392
935
|
};
|
|
@@ -435,6 +978,7 @@ var inputSchema = T2.Object({
|
|
|
435
978
|
eventPayload: jsonType(T2.Record(T2.String(), T2.Any()), true),
|
|
436
979
|
command: jsonType(commandCallSchema),
|
|
437
980
|
authToken: T2.String(),
|
|
981
|
+
ubiquityKernelToken: T2.Optional(T2.String()),
|
|
438
982
|
settings: jsonType(T2.Record(T2.String(), T2.Any())),
|
|
439
983
|
ref: T2.String(),
|
|
440
984
|
signature: T2.String()
|
|
@@ -445,7 +989,7 @@ config();
|
|
|
445
989
|
async function handleError(context2, pluginOptions, error) {
|
|
446
990
|
console.error(error);
|
|
447
991
|
const loggerError = transformError(context2, error);
|
|
448
|
-
if (loggerError instanceof
|
|
992
|
+
if (loggerError instanceof LogReturn) {
|
|
449
993
|
core.setFailed(loggerError.logMessage.diff);
|
|
450
994
|
} else if (loggerError instanceof Error) {
|
|
451
995
|
core.setFailed(loggerError);
|
|
@@ -486,26 +1030,28 @@ async function createActionsPlugin(handler, options) {
|
|
|
486
1030
|
} else {
|
|
487
1031
|
config2 = inputs.settings;
|
|
488
1032
|
}
|
|
489
|
-
let
|
|
1033
|
+
let env2;
|
|
490
1034
|
if (pluginOptions.envSchema) {
|
|
491
1035
|
try {
|
|
492
|
-
|
|
1036
|
+
env2 = Value3.Decode(pluginOptions.envSchema, Value3.Default(pluginOptions.envSchema, process.env));
|
|
493
1037
|
} catch (e) {
|
|
494
1038
|
console.dir(...Value3.Errors(pluginOptions.envSchema, process.env), { depth: null });
|
|
495
1039
|
core.setFailed(`Error: Invalid environment provided.`);
|
|
496
1040
|
throw e;
|
|
497
1041
|
}
|
|
498
1042
|
} else {
|
|
499
|
-
|
|
1043
|
+
env2 = process.env;
|
|
500
1044
|
}
|
|
501
1045
|
const command = getCommand(inputs, pluginOptions);
|
|
502
1046
|
const context2 = {
|
|
503
1047
|
eventName: inputs.eventName,
|
|
504
1048
|
payload: inputs.eventPayload,
|
|
505
1049
|
command,
|
|
1050
|
+
authToken: inputs.authToken,
|
|
1051
|
+
ubiquityKernelToken: inputs.ubiquityKernelToken,
|
|
506
1052
|
octokit: new customOctokit({ auth: inputs.authToken }),
|
|
507
1053
|
config: config2,
|
|
508
|
-
env,
|
|
1054
|
+
env: env2,
|
|
509
1055
|
logger: new Logs(pluginOptions.logLevel),
|
|
510
1056
|
commentHandler: new CommentHandler()
|
|
511
1057
|
};
|
|
@@ -560,9 +1106,9 @@ function processSegment(segment, extraTags, shouldCollapseEmptyLines) {
|
|
|
560
1106
|
return `__INLINE_CODE_${inlineCodes.length - 1}__`;
|
|
561
1107
|
});
|
|
562
1108
|
s = s.replace(/<!--[\s\S]*?-->/g, "");
|
|
563
|
-
for (const
|
|
564
|
-
if (!
|
|
565
|
-
const tag =
|
|
1109
|
+
for (const raw2 of extraTags) {
|
|
1110
|
+
if (!raw2) continue;
|
|
1111
|
+
const tag = raw2.toLowerCase().trim().replace(/[^\w:-]/g, "");
|
|
566
1112
|
if (!tag) continue;
|
|
567
1113
|
if (VOID_TAGS.has(tag)) {
|
|
568
1114
|
const voidRe = new RegExp(`<${tag}\\b[^>]*\\/?>`, "gi");
|
|
@@ -587,86 +1133,1687 @@ function processSegment(segment, extraTags, shouldCollapseEmptyLines) {
|
|
|
587
1133
|
|
|
588
1134
|
// src/server.ts
|
|
589
1135
|
import { Value as Value4 } from "@sinclair/typebox/value";
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
1136
|
+
|
|
1137
|
+
// ../../node_modules/hono/dist/compose.js
|
|
1138
|
+
var compose = (middleware, onError, onNotFound) => {
|
|
1139
|
+
return (context2, next) => {
|
|
1140
|
+
let index = -1;
|
|
1141
|
+
return dispatch(0);
|
|
1142
|
+
async function dispatch(i) {
|
|
1143
|
+
if (i <= index) {
|
|
1144
|
+
throw new Error("next() called multiple times");
|
|
1145
|
+
}
|
|
1146
|
+
index = i;
|
|
1147
|
+
let res;
|
|
1148
|
+
let isError = false;
|
|
1149
|
+
let handler;
|
|
1150
|
+
if (middleware[i]) {
|
|
1151
|
+
handler = middleware[i][0][0];
|
|
1152
|
+
context2.req.routeIndex = i;
|
|
1153
|
+
} else {
|
|
1154
|
+
handler = i === middleware.length && next || void 0;
|
|
1155
|
+
}
|
|
1156
|
+
if (handler) {
|
|
1157
|
+
try {
|
|
1158
|
+
res = await handler(context2, () => dispatch(i + 1));
|
|
1159
|
+
} catch (err) {
|
|
1160
|
+
if (err instanceof Error && onError) {
|
|
1161
|
+
context2.error = err;
|
|
1162
|
+
res = await onError(err, context2);
|
|
1163
|
+
isError = true;
|
|
1164
|
+
} else {
|
|
1165
|
+
throw err;
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
} else {
|
|
1169
|
+
if (context2.finalized === false && onNotFound) {
|
|
1170
|
+
res = await onNotFound(context2);
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
if (res && (context2.finalized === false || isError)) {
|
|
1174
|
+
context2.res = res;
|
|
1175
|
+
}
|
|
1176
|
+
return context2;
|
|
1177
|
+
}
|
|
1178
|
+
};
|
|
1179
|
+
};
|
|
1180
|
+
|
|
1181
|
+
// ../../node_modules/hono/dist/request/constants.js
|
|
1182
|
+
var GET_MATCH_RESULT = Symbol();
|
|
1183
|
+
|
|
1184
|
+
// ../../node_modules/hono/dist/utils/body.js
|
|
1185
|
+
var parseBody = async (request, options = /* @__PURE__ */ Object.create(null)) => {
|
|
1186
|
+
const { all = false, dot = false } = options;
|
|
1187
|
+
const headers = request instanceof HonoRequest ? request.raw.headers : request.headers;
|
|
1188
|
+
const contentType = headers.get("Content-Type");
|
|
1189
|
+
if (contentType?.startsWith("multipart/form-data") || contentType?.startsWith("application/x-www-form-urlencoded")) {
|
|
1190
|
+
return parseFormData(request, { all, dot });
|
|
599
1191
|
}
|
|
600
|
-
|
|
1192
|
+
return {};
|
|
1193
|
+
};
|
|
1194
|
+
async function parseFormData(request, options) {
|
|
1195
|
+
const formData = await request.formData();
|
|
1196
|
+
if (formData) {
|
|
1197
|
+
return convertFormDataToBodyData(formData, options);
|
|
1198
|
+
}
|
|
1199
|
+
return {};
|
|
601
1200
|
}
|
|
602
|
-
function
|
|
603
|
-
const
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
1201
|
+
function convertFormDataToBodyData(formData, options) {
|
|
1202
|
+
const form = /* @__PURE__ */ Object.create(null);
|
|
1203
|
+
formData.forEach((value, key) => {
|
|
1204
|
+
const shouldParseAllValues = options.all || key.endsWith("[]");
|
|
1205
|
+
if (!shouldParseAllValues) {
|
|
1206
|
+
form[key] = value;
|
|
1207
|
+
} else {
|
|
1208
|
+
handleParsingAllValues(form, key, value);
|
|
1209
|
+
}
|
|
607
1210
|
});
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
1211
|
+
if (options.dot) {
|
|
1212
|
+
Object.entries(form).forEach(([key, value]) => {
|
|
1213
|
+
const shouldParseDotValues = key.includes(".");
|
|
1214
|
+
if (shouldParseDotValues) {
|
|
1215
|
+
handleParsingNestedValues(form, key, value);
|
|
1216
|
+
delete form[key];
|
|
1217
|
+
}
|
|
1218
|
+
});
|
|
1219
|
+
}
|
|
1220
|
+
return form;
|
|
1221
|
+
}
|
|
1222
|
+
var handleParsingAllValues = (form, key, value) => {
|
|
1223
|
+
if (form[key] !== void 0) {
|
|
1224
|
+
if (Array.isArray(form[key])) {
|
|
1225
|
+
;
|
|
1226
|
+
form[key].push(value);
|
|
1227
|
+
} else {
|
|
1228
|
+
form[key] = [form[key], value];
|
|
611
1229
|
}
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
1230
|
+
} else {
|
|
1231
|
+
if (!key.endsWith("[]")) {
|
|
1232
|
+
form[key] = value;
|
|
1233
|
+
} else {
|
|
1234
|
+
form[key] = [value];
|
|
617
1235
|
}
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
1236
|
+
}
|
|
1237
|
+
};
|
|
1238
|
+
var handleParsingNestedValues = (form, key, value) => {
|
|
1239
|
+
let nestedForm = form;
|
|
1240
|
+
const keys = key.split(".");
|
|
1241
|
+
keys.forEach((key2, index) => {
|
|
1242
|
+
if (index === keys.length - 1) {
|
|
1243
|
+
nestedForm[key2] = value;
|
|
1244
|
+
} else {
|
|
1245
|
+
if (!nestedForm[key2] || typeof nestedForm[key2] !== "object" || Array.isArray(nestedForm[key2]) || nestedForm[key2] instanceof File) {
|
|
1246
|
+
nestedForm[key2] = /* @__PURE__ */ Object.create(null);
|
|
1247
|
+
}
|
|
1248
|
+
nestedForm = nestedForm[key2];
|
|
621
1249
|
}
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
1250
|
+
});
|
|
1251
|
+
};
|
|
1252
|
+
|
|
1253
|
+
// ../../node_modules/hono/dist/utils/url.js
|
|
1254
|
+
var splitPath = (path) => {
|
|
1255
|
+
const paths = path.split("/");
|
|
1256
|
+
if (paths[0] === "") {
|
|
1257
|
+
paths.shift();
|
|
1258
|
+
}
|
|
1259
|
+
return paths;
|
|
1260
|
+
};
|
|
1261
|
+
var splitRoutingPath = (routePath) => {
|
|
1262
|
+
const { groups, path } = extractGroupsFromPath(routePath);
|
|
1263
|
+
const paths = splitPath(path);
|
|
1264
|
+
return replaceGroupMarks(paths, groups);
|
|
1265
|
+
};
|
|
1266
|
+
var extractGroupsFromPath = (path) => {
|
|
1267
|
+
const groups = [];
|
|
1268
|
+
path = path.replace(/\{[^}]+\}/g, (match, index) => {
|
|
1269
|
+
const mark = `@${index}`;
|
|
1270
|
+
groups.push([mark, match]);
|
|
1271
|
+
return mark;
|
|
1272
|
+
});
|
|
1273
|
+
return { groups, path };
|
|
1274
|
+
};
|
|
1275
|
+
var replaceGroupMarks = (paths, groups) => {
|
|
1276
|
+
for (let i = groups.length - 1; i >= 0; i--) {
|
|
1277
|
+
const [mark] = groups[i];
|
|
1278
|
+
for (let j = paths.length - 1; j >= 0; j--) {
|
|
1279
|
+
if (paths[j].includes(mark)) {
|
|
1280
|
+
paths[j] = paths[j].replace(mark, groups[i][1]);
|
|
1281
|
+
break;
|
|
630
1282
|
}
|
|
631
|
-
} else {
|
|
632
|
-
config2 = inputs.settings;
|
|
633
1283
|
}
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
1284
|
+
}
|
|
1285
|
+
return paths;
|
|
1286
|
+
};
|
|
1287
|
+
var patternCache = {};
|
|
1288
|
+
var getPattern = (label, next) => {
|
|
1289
|
+
if (label === "*") {
|
|
1290
|
+
return "*";
|
|
1291
|
+
}
|
|
1292
|
+
const match = label.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
|
|
1293
|
+
if (match) {
|
|
1294
|
+
const cacheKey = `${label}#${next}`;
|
|
1295
|
+
if (!patternCache[cacheKey]) {
|
|
1296
|
+
if (match[2]) {
|
|
1297
|
+
patternCache[cacheKey] = next && next[0] !== ":" && next[0] !== "*" ? [cacheKey, match[1], new RegExp(`^${match[2]}(?=/${next})`)] : [label, match[1], new RegExp(`^${match[2]}$`)];
|
|
1298
|
+
} else {
|
|
1299
|
+
patternCache[cacheKey] = [label, match[1], true];
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
return patternCache[cacheKey];
|
|
1303
|
+
}
|
|
1304
|
+
return null;
|
|
1305
|
+
};
|
|
1306
|
+
var tryDecode = (str, decoder) => {
|
|
1307
|
+
try {
|
|
1308
|
+
return decoder(str);
|
|
1309
|
+
} catch {
|
|
1310
|
+
return str.replace(/(?:%[0-9A-Fa-f]{2})+/g, (match) => {
|
|
637
1311
|
try {
|
|
638
|
-
|
|
639
|
-
} catch
|
|
640
|
-
|
|
641
|
-
throw e;
|
|
1312
|
+
return decoder(match);
|
|
1313
|
+
} catch {
|
|
1314
|
+
return match;
|
|
642
1315
|
}
|
|
643
|
-
}
|
|
644
|
-
|
|
1316
|
+
});
|
|
1317
|
+
}
|
|
1318
|
+
};
|
|
1319
|
+
var tryDecodeURI = (str) => tryDecode(str, decodeURI);
|
|
1320
|
+
var getPath = (request) => {
|
|
1321
|
+
const url = request.url;
|
|
1322
|
+
const start = url.indexOf(
|
|
1323
|
+
"/",
|
|
1324
|
+
url.charCodeAt(9) === 58 ? 13 : 8
|
|
1325
|
+
);
|
|
1326
|
+
let i = start;
|
|
1327
|
+
for (; i < url.length; i++) {
|
|
1328
|
+
const charCode = url.charCodeAt(i);
|
|
1329
|
+
if (charCode === 37) {
|
|
1330
|
+
const queryIndex = url.indexOf("?", i);
|
|
1331
|
+
const path = url.slice(start, queryIndex === -1 ? void 0 : queryIndex);
|
|
1332
|
+
return tryDecodeURI(path.includes("%25") ? path.replace(/%25/g, "%2525") : path);
|
|
1333
|
+
} else if (charCode === 63) {
|
|
1334
|
+
break;
|
|
645
1335
|
}
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
1336
|
+
}
|
|
1337
|
+
return url.slice(start, i);
|
|
1338
|
+
};
|
|
1339
|
+
var getPathNoStrict = (request) => {
|
|
1340
|
+
const result = getPath(request);
|
|
1341
|
+
return result.length > 1 && result.at(-1) === "/" ? result.slice(0, -1) : result;
|
|
1342
|
+
};
|
|
1343
|
+
var mergePath = (base, sub, ...rest) => {
|
|
1344
|
+
if (rest.length) {
|
|
1345
|
+
sub = mergePath(sub, ...rest);
|
|
1346
|
+
}
|
|
1347
|
+
return `${base?.[0] === "/" ? "" : "/"}${base}${sub === "/" ? "" : `${base?.at(-1) === "/" ? "" : "/"}${sub?.[0] === "/" ? sub.slice(1) : sub}`}`;
|
|
1348
|
+
};
|
|
1349
|
+
var checkOptionalParameter = (path) => {
|
|
1350
|
+
if (path.charCodeAt(path.length - 1) !== 63 || !path.includes(":")) {
|
|
1351
|
+
return null;
|
|
1352
|
+
}
|
|
1353
|
+
const segments = path.split("/");
|
|
1354
|
+
const results = [];
|
|
1355
|
+
let basePath = "";
|
|
1356
|
+
segments.forEach((segment) => {
|
|
1357
|
+
if (segment !== "" && !/\:/.test(segment)) {
|
|
1358
|
+
basePath += "/" + segment;
|
|
1359
|
+
} else if (/\:/.test(segment)) {
|
|
1360
|
+
if (/\?/.test(segment)) {
|
|
1361
|
+
if (results.length === 0 && basePath === "") {
|
|
1362
|
+
results.push("/");
|
|
1363
|
+
} else {
|
|
1364
|
+
results.push(basePath);
|
|
1365
|
+
}
|
|
1366
|
+
const optionalSegment = segment.replace("?", "");
|
|
1367
|
+
basePath += "/" + optionalSegment;
|
|
1368
|
+
results.push(basePath);
|
|
1369
|
+
} else {
|
|
1370
|
+
basePath += "/" + segment;
|
|
1371
|
+
}
|
|
664
1372
|
}
|
|
665
1373
|
});
|
|
666
|
-
return
|
|
1374
|
+
return results.filter((v, i, a) => a.indexOf(v) === i);
|
|
1375
|
+
};
|
|
1376
|
+
var _decodeURI = (value) => {
|
|
1377
|
+
if (!/[%+]/.test(value)) {
|
|
1378
|
+
return value;
|
|
1379
|
+
}
|
|
1380
|
+
if (value.indexOf("+") !== -1) {
|
|
1381
|
+
value = value.replace(/\+/g, " ");
|
|
1382
|
+
}
|
|
1383
|
+
return value.indexOf("%") !== -1 ? tryDecode(value, decodeURIComponent_) : value;
|
|
1384
|
+
};
|
|
1385
|
+
var _getQueryParam = (url, key, multiple) => {
|
|
1386
|
+
let encoded;
|
|
1387
|
+
if (!multiple && key && !/[%+]/.test(key)) {
|
|
1388
|
+
let keyIndex2 = url.indexOf(`?${key}`, 8);
|
|
1389
|
+
if (keyIndex2 === -1) {
|
|
1390
|
+
keyIndex2 = url.indexOf(`&${key}`, 8);
|
|
1391
|
+
}
|
|
1392
|
+
while (keyIndex2 !== -1) {
|
|
1393
|
+
const trailingKeyCode = url.charCodeAt(keyIndex2 + key.length + 1);
|
|
1394
|
+
if (trailingKeyCode === 61) {
|
|
1395
|
+
const valueIndex = keyIndex2 + key.length + 2;
|
|
1396
|
+
const endIndex = url.indexOf("&", valueIndex);
|
|
1397
|
+
return _decodeURI(url.slice(valueIndex, endIndex === -1 ? void 0 : endIndex));
|
|
1398
|
+
} else if (trailingKeyCode == 38 || isNaN(trailingKeyCode)) {
|
|
1399
|
+
return "";
|
|
1400
|
+
}
|
|
1401
|
+
keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1);
|
|
1402
|
+
}
|
|
1403
|
+
encoded = /[%+]/.test(url);
|
|
1404
|
+
if (!encoded) {
|
|
1405
|
+
return void 0;
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
const results = {};
|
|
1409
|
+
encoded ??= /[%+]/.test(url);
|
|
1410
|
+
let keyIndex = url.indexOf("?", 8);
|
|
1411
|
+
while (keyIndex !== -1) {
|
|
1412
|
+
const nextKeyIndex = url.indexOf("&", keyIndex + 1);
|
|
1413
|
+
let valueIndex = url.indexOf("=", keyIndex);
|
|
1414
|
+
if (valueIndex > nextKeyIndex && nextKeyIndex !== -1) {
|
|
1415
|
+
valueIndex = -1;
|
|
1416
|
+
}
|
|
1417
|
+
let name = url.slice(
|
|
1418
|
+
keyIndex + 1,
|
|
1419
|
+
valueIndex === -1 ? nextKeyIndex === -1 ? void 0 : nextKeyIndex : valueIndex
|
|
1420
|
+
);
|
|
1421
|
+
if (encoded) {
|
|
1422
|
+
name = _decodeURI(name);
|
|
1423
|
+
}
|
|
1424
|
+
keyIndex = nextKeyIndex;
|
|
1425
|
+
if (name === "") {
|
|
1426
|
+
continue;
|
|
1427
|
+
}
|
|
1428
|
+
let value;
|
|
1429
|
+
if (valueIndex === -1) {
|
|
1430
|
+
value = "";
|
|
1431
|
+
} else {
|
|
1432
|
+
value = url.slice(valueIndex + 1, nextKeyIndex === -1 ? void 0 : nextKeyIndex);
|
|
1433
|
+
if (encoded) {
|
|
1434
|
+
value = _decodeURI(value);
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
if (multiple) {
|
|
1438
|
+
if (!(results[name] && Array.isArray(results[name]))) {
|
|
1439
|
+
results[name] = [];
|
|
1440
|
+
}
|
|
1441
|
+
;
|
|
1442
|
+
results[name].push(value);
|
|
1443
|
+
} else {
|
|
1444
|
+
results[name] ??= value;
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1447
|
+
return key ? results[key] : results;
|
|
1448
|
+
};
|
|
1449
|
+
var getQueryParam = _getQueryParam;
|
|
1450
|
+
var getQueryParams = (url, key) => {
|
|
1451
|
+
return _getQueryParam(url, key, true);
|
|
1452
|
+
};
|
|
1453
|
+
var decodeURIComponent_ = decodeURIComponent;
|
|
1454
|
+
|
|
1455
|
+
// ../../node_modules/hono/dist/request.js
|
|
1456
|
+
var tryDecodeURIComponent = (str) => tryDecode(str, decodeURIComponent_);
|
|
1457
|
+
var HonoRequest = class {
|
|
1458
|
+
raw;
|
|
1459
|
+
#validatedData;
|
|
1460
|
+
#matchResult;
|
|
1461
|
+
routeIndex = 0;
|
|
1462
|
+
path;
|
|
1463
|
+
bodyCache = {};
|
|
1464
|
+
constructor(request, path = "/", matchResult = [[]]) {
|
|
1465
|
+
this.raw = request;
|
|
1466
|
+
this.path = path;
|
|
1467
|
+
this.#matchResult = matchResult;
|
|
1468
|
+
this.#validatedData = {};
|
|
1469
|
+
}
|
|
1470
|
+
param(key) {
|
|
1471
|
+
return key ? this.#getDecodedParam(key) : this.#getAllDecodedParams();
|
|
1472
|
+
}
|
|
1473
|
+
#getDecodedParam(key) {
|
|
1474
|
+
const paramKey = this.#matchResult[0][this.routeIndex][1][key];
|
|
1475
|
+
const param = this.#getParamValue(paramKey);
|
|
1476
|
+
return param ? /\%/.test(param) ? tryDecodeURIComponent(param) : param : void 0;
|
|
1477
|
+
}
|
|
1478
|
+
#getAllDecodedParams() {
|
|
1479
|
+
const decoded = {};
|
|
1480
|
+
const keys = Object.keys(this.#matchResult[0][this.routeIndex][1]);
|
|
1481
|
+
for (const key of keys) {
|
|
1482
|
+
const value = this.#getParamValue(this.#matchResult[0][this.routeIndex][1][key]);
|
|
1483
|
+
if (value && typeof value === "string") {
|
|
1484
|
+
decoded[key] = /\%/.test(value) ? tryDecodeURIComponent(value) : value;
|
|
1485
|
+
}
|
|
1486
|
+
}
|
|
1487
|
+
return decoded;
|
|
1488
|
+
}
|
|
1489
|
+
#getParamValue(paramKey) {
|
|
1490
|
+
return this.#matchResult[1] ? this.#matchResult[1][paramKey] : paramKey;
|
|
1491
|
+
}
|
|
1492
|
+
query(key) {
|
|
1493
|
+
return getQueryParam(this.url, key);
|
|
1494
|
+
}
|
|
1495
|
+
queries(key) {
|
|
1496
|
+
return getQueryParams(this.url, key);
|
|
1497
|
+
}
|
|
1498
|
+
header(name) {
|
|
1499
|
+
if (name) {
|
|
1500
|
+
return this.raw.headers.get(name) ?? void 0;
|
|
1501
|
+
}
|
|
1502
|
+
const headerData = {};
|
|
1503
|
+
this.raw.headers.forEach((value, key) => {
|
|
1504
|
+
headerData[key] = value;
|
|
1505
|
+
});
|
|
1506
|
+
return headerData;
|
|
1507
|
+
}
|
|
1508
|
+
async parseBody(options) {
|
|
1509
|
+
return this.bodyCache.parsedBody ??= await parseBody(this, options);
|
|
1510
|
+
}
|
|
1511
|
+
#cachedBody = (key) => {
|
|
1512
|
+
const { bodyCache, raw: raw2 } = this;
|
|
1513
|
+
const cachedBody = bodyCache[key];
|
|
1514
|
+
if (cachedBody) {
|
|
1515
|
+
return cachedBody;
|
|
1516
|
+
}
|
|
1517
|
+
const anyCachedKey = Object.keys(bodyCache)[0];
|
|
1518
|
+
if (anyCachedKey) {
|
|
1519
|
+
return bodyCache[anyCachedKey].then((body) => {
|
|
1520
|
+
if (anyCachedKey === "json") {
|
|
1521
|
+
body = JSON.stringify(body);
|
|
1522
|
+
}
|
|
1523
|
+
return new Response(body)[key]();
|
|
1524
|
+
});
|
|
1525
|
+
}
|
|
1526
|
+
return bodyCache[key] = raw2[key]();
|
|
1527
|
+
};
|
|
1528
|
+
json() {
|
|
1529
|
+
return this.#cachedBody("text").then((text) => JSON.parse(text));
|
|
1530
|
+
}
|
|
1531
|
+
text() {
|
|
1532
|
+
return this.#cachedBody("text");
|
|
1533
|
+
}
|
|
1534
|
+
arrayBuffer() {
|
|
1535
|
+
return this.#cachedBody("arrayBuffer");
|
|
1536
|
+
}
|
|
1537
|
+
blob() {
|
|
1538
|
+
return this.#cachedBody("blob");
|
|
1539
|
+
}
|
|
1540
|
+
formData() {
|
|
1541
|
+
return this.#cachedBody("formData");
|
|
1542
|
+
}
|
|
1543
|
+
addValidatedData(target, data) {
|
|
1544
|
+
this.#validatedData[target] = data;
|
|
1545
|
+
}
|
|
1546
|
+
valid(target) {
|
|
1547
|
+
return this.#validatedData[target];
|
|
1548
|
+
}
|
|
1549
|
+
get url() {
|
|
1550
|
+
return this.raw.url;
|
|
1551
|
+
}
|
|
1552
|
+
get method() {
|
|
1553
|
+
return this.raw.method;
|
|
1554
|
+
}
|
|
1555
|
+
get [GET_MATCH_RESULT]() {
|
|
1556
|
+
return this.#matchResult;
|
|
1557
|
+
}
|
|
1558
|
+
get matchedRoutes() {
|
|
1559
|
+
return this.#matchResult[0].map(([[, route]]) => route);
|
|
1560
|
+
}
|
|
1561
|
+
get routePath() {
|
|
1562
|
+
return this.#matchResult[0].map(([[, route]]) => route)[this.routeIndex].path;
|
|
1563
|
+
}
|
|
1564
|
+
};
|
|
1565
|
+
|
|
1566
|
+
// ../../node_modules/hono/dist/utils/html.js
|
|
1567
|
+
var HtmlEscapedCallbackPhase = {
|
|
1568
|
+
Stringify: 1,
|
|
1569
|
+
BeforeStream: 2,
|
|
1570
|
+
Stream: 3
|
|
1571
|
+
};
|
|
1572
|
+
var raw = (value, callbacks) => {
|
|
1573
|
+
const escapedString = new String(value);
|
|
1574
|
+
escapedString.isEscaped = true;
|
|
1575
|
+
escapedString.callbacks = callbacks;
|
|
1576
|
+
return escapedString;
|
|
1577
|
+
};
|
|
1578
|
+
var resolveCallback = async (str, phase, preserveCallbacks, context2, buffer) => {
|
|
1579
|
+
if (typeof str === "object" && !(str instanceof String)) {
|
|
1580
|
+
if (!(str instanceof Promise)) {
|
|
1581
|
+
str = str.toString();
|
|
1582
|
+
}
|
|
1583
|
+
if (str instanceof Promise) {
|
|
1584
|
+
str = await str;
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
const callbacks = str.callbacks;
|
|
1588
|
+
if (!callbacks?.length) {
|
|
1589
|
+
return Promise.resolve(str);
|
|
1590
|
+
}
|
|
1591
|
+
if (buffer) {
|
|
1592
|
+
buffer[0] += str;
|
|
1593
|
+
} else {
|
|
1594
|
+
buffer = [str];
|
|
1595
|
+
}
|
|
1596
|
+
const resStr = Promise.all(callbacks.map((c) => c({ phase, buffer, context: context2 }))).then(
|
|
1597
|
+
(res) => Promise.all(
|
|
1598
|
+
res.filter(Boolean).map((str2) => resolveCallback(str2, phase, false, context2, buffer))
|
|
1599
|
+
).then(() => buffer[0])
|
|
1600
|
+
);
|
|
1601
|
+
if (preserveCallbacks) {
|
|
1602
|
+
return raw(await resStr, callbacks);
|
|
1603
|
+
} else {
|
|
1604
|
+
return resStr;
|
|
1605
|
+
}
|
|
1606
|
+
};
|
|
1607
|
+
|
|
1608
|
+
// ../../node_modules/hono/dist/context.js
|
|
1609
|
+
var TEXT_PLAIN = "text/plain; charset=UTF-8";
|
|
1610
|
+
var setDefaultContentType = (contentType, headers) => {
|
|
1611
|
+
return {
|
|
1612
|
+
"Content-Type": contentType,
|
|
1613
|
+
...headers
|
|
1614
|
+
};
|
|
1615
|
+
};
|
|
1616
|
+
var Context = class {
|
|
1617
|
+
#rawRequest;
|
|
1618
|
+
#req;
|
|
1619
|
+
env = {};
|
|
1620
|
+
#var;
|
|
1621
|
+
finalized = false;
|
|
1622
|
+
error;
|
|
1623
|
+
#status;
|
|
1624
|
+
#executionCtx;
|
|
1625
|
+
#res;
|
|
1626
|
+
#layout;
|
|
1627
|
+
#renderer;
|
|
1628
|
+
#notFoundHandler;
|
|
1629
|
+
#preparedHeaders;
|
|
1630
|
+
#matchResult;
|
|
1631
|
+
#path;
|
|
1632
|
+
constructor(req, options) {
|
|
1633
|
+
this.#rawRequest = req;
|
|
1634
|
+
if (options) {
|
|
1635
|
+
this.#executionCtx = options.executionCtx;
|
|
1636
|
+
this.env = options.env;
|
|
1637
|
+
this.#notFoundHandler = options.notFoundHandler;
|
|
1638
|
+
this.#path = options.path;
|
|
1639
|
+
this.#matchResult = options.matchResult;
|
|
1640
|
+
}
|
|
1641
|
+
}
|
|
1642
|
+
get req() {
|
|
1643
|
+
this.#req ??= new HonoRequest(this.#rawRequest, this.#path, this.#matchResult);
|
|
1644
|
+
return this.#req;
|
|
1645
|
+
}
|
|
1646
|
+
get event() {
|
|
1647
|
+
if (this.#executionCtx && "respondWith" in this.#executionCtx) {
|
|
1648
|
+
return this.#executionCtx;
|
|
1649
|
+
} else {
|
|
1650
|
+
throw Error("This context has no FetchEvent");
|
|
1651
|
+
}
|
|
1652
|
+
}
|
|
1653
|
+
get executionCtx() {
|
|
1654
|
+
if (this.#executionCtx) {
|
|
1655
|
+
return this.#executionCtx;
|
|
1656
|
+
} else {
|
|
1657
|
+
throw Error("This context has no ExecutionContext");
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1660
|
+
get res() {
|
|
1661
|
+
return this.#res ||= new Response(null, {
|
|
1662
|
+
headers: this.#preparedHeaders ??= new Headers()
|
|
1663
|
+
});
|
|
1664
|
+
}
|
|
1665
|
+
set res(_res) {
|
|
1666
|
+
if (this.#res && _res) {
|
|
1667
|
+
_res = new Response(_res.body, _res);
|
|
1668
|
+
for (const [k, v] of this.#res.headers.entries()) {
|
|
1669
|
+
if (k === "content-type") {
|
|
1670
|
+
continue;
|
|
1671
|
+
}
|
|
1672
|
+
if (k === "set-cookie") {
|
|
1673
|
+
const cookies = this.#res.headers.getSetCookie();
|
|
1674
|
+
_res.headers.delete("set-cookie");
|
|
1675
|
+
for (const cookie of cookies) {
|
|
1676
|
+
_res.headers.append("set-cookie", cookie);
|
|
1677
|
+
}
|
|
1678
|
+
} else {
|
|
1679
|
+
_res.headers.set(k, v);
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
}
|
|
1683
|
+
this.#res = _res;
|
|
1684
|
+
this.finalized = true;
|
|
1685
|
+
}
|
|
1686
|
+
render = (...args) => {
|
|
1687
|
+
this.#renderer ??= (content) => this.html(content);
|
|
1688
|
+
return this.#renderer(...args);
|
|
1689
|
+
};
|
|
1690
|
+
setLayout = (layout) => this.#layout = layout;
|
|
1691
|
+
getLayout = () => this.#layout;
|
|
1692
|
+
setRenderer = (renderer) => {
|
|
1693
|
+
this.#renderer = renderer;
|
|
1694
|
+
};
|
|
1695
|
+
header = (name, value, options) => {
|
|
1696
|
+
if (this.finalized) {
|
|
1697
|
+
this.#res = new Response(this.#res.body, this.#res);
|
|
1698
|
+
}
|
|
1699
|
+
const headers = this.#res ? this.#res.headers : this.#preparedHeaders ??= new Headers();
|
|
1700
|
+
if (value === void 0) {
|
|
1701
|
+
headers.delete(name);
|
|
1702
|
+
} else if (options?.append) {
|
|
1703
|
+
headers.append(name, value);
|
|
1704
|
+
} else {
|
|
1705
|
+
headers.set(name, value);
|
|
1706
|
+
}
|
|
1707
|
+
};
|
|
1708
|
+
status = (status) => {
|
|
1709
|
+
this.#status = status;
|
|
1710
|
+
};
|
|
1711
|
+
set = (key, value) => {
|
|
1712
|
+
this.#var ??= /* @__PURE__ */ new Map();
|
|
1713
|
+
this.#var.set(key, value);
|
|
1714
|
+
};
|
|
1715
|
+
get = (key) => {
|
|
1716
|
+
return this.#var ? this.#var.get(key) : void 0;
|
|
1717
|
+
};
|
|
1718
|
+
get var() {
|
|
1719
|
+
if (!this.#var) {
|
|
1720
|
+
return {};
|
|
1721
|
+
}
|
|
1722
|
+
return Object.fromEntries(this.#var);
|
|
1723
|
+
}
|
|
1724
|
+
#newResponse(data, arg, headers) {
|
|
1725
|
+
const responseHeaders = this.#res ? new Headers(this.#res.headers) : this.#preparedHeaders ?? new Headers();
|
|
1726
|
+
if (typeof arg === "object" && "headers" in arg) {
|
|
1727
|
+
const argHeaders = arg.headers instanceof Headers ? arg.headers : new Headers(arg.headers);
|
|
1728
|
+
for (const [key, value] of argHeaders) {
|
|
1729
|
+
if (key.toLowerCase() === "set-cookie") {
|
|
1730
|
+
responseHeaders.append(key, value);
|
|
1731
|
+
} else {
|
|
1732
|
+
responseHeaders.set(key, value);
|
|
1733
|
+
}
|
|
1734
|
+
}
|
|
1735
|
+
}
|
|
1736
|
+
if (headers) {
|
|
1737
|
+
for (const [k, v] of Object.entries(headers)) {
|
|
1738
|
+
if (typeof v === "string") {
|
|
1739
|
+
responseHeaders.set(k, v);
|
|
1740
|
+
} else {
|
|
1741
|
+
responseHeaders.delete(k);
|
|
1742
|
+
for (const v2 of v) {
|
|
1743
|
+
responseHeaders.append(k, v2);
|
|
1744
|
+
}
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1747
|
+
}
|
|
1748
|
+
const status = typeof arg === "number" ? arg : arg?.status ?? this.#status;
|
|
1749
|
+
return new Response(data, { status, headers: responseHeaders });
|
|
1750
|
+
}
|
|
1751
|
+
newResponse = (...args) => this.#newResponse(...args);
|
|
1752
|
+
body = (data, arg, headers) => this.#newResponse(data, arg, headers);
|
|
1753
|
+
text = (text, arg, headers) => {
|
|
1754
|
+
return !this.#preparedHeaders && !this.#status && !arg && !headers && !this.finalized ? new Response(text) : this.#newResponse(
|
|
1755
|
+
text,
|
|
1756
|
+
arg,
|
|
1757
|
+
setDefaultContentType(TEXT_PLAIN, headers)
|
|
1758
|
+
);
|
|
1759
|
+
};
|
|
1760
|
+
json = (object, arg, headers) => {
|
|
1761
|
+
return this.#newResponse(
|
|
1762
|
+
JSON.stringify(object),
|
|
1763
|
+
arg,
|
|
1764
|
+
setDefaultContentType("application/json", headers)
|
|
1765
|
+
);
|
|
1766
|
+
};
|
|
1767
|
+
html = (html, arg, headers) => {
|
|
1768
|
+
const res = (html2) => this.#newResponse(html2, arg, setDefaultContentType("text/html; charset=UTF-8", headers));
|
|
1769
|
+
return typeof html === "object" ? resolveCallback(html, HtmlEscapedCallbackPhase.Stringify, false, {}).then(res) : res(html);
|
|
1770
|
+
};
|
|
1771
|
+
redirect = (location, status) => {
|
|
1772
|
+
const locationString = String(location);
|
|
1773
|
+
this.header(
|
|
1774
|
+
"Location",
|
|
1775
|
+
!/[^\x00-\xFF]/.test(locationString) ? locationString : encodeURI(locationString)
|
|
1776
|
+
);
|
|
1777
|
+
return this.newResponse(null, status ?? 302);
|
|
1778
|
+
};
|
|
1779
|
+
notFound = () => {
|
|
1780
|
+
this.#notFoundHandler ??= () => new Response();
|
|
1781
|
+
return this.#notFoundHandler(this);
|
|
1782
|
+
};
|
|
1783
|
+
};
|
|
1784
|
+
|
|
1785
|
+
// ../../node_modules/hono/dist/router.js
|
|
1786
|
+
var METHOD_NAME_ALL = "ALL";
|
|
1787
|
+
var METHOD_NAME_ALL_LOWERCASE = "all";
|
|
1788
|
+
var METHODS = ["get", "post", "put", "delete", "options", "patch"];
|
|
1789
|
+
var MESSAGE_MATCHER_IS_ALREADY_BUILT = "Can not add a route since the matcher is already built.";
|
|
1790
|
+
var UnsupportedPathError = class extends Error {
|
|
1791
|
+
};
|
|
1792
|
+
|
|
1793
|
+
// ../../node_modules/hono/dist/utils/constants.js
|
|
1794
|
+
var COMPOSED_HANDLER = "__COMPOSED_HANDLER";
|
|
1795
|
+
|
|
1796
|
+
// ../../node_modules/hono/dist/hono-base.js
|
|
1797
|
+
var notFoundHandler = (c) => {
|
|
1798
|
+
return c.text("404 Not Found", 404);
|
|
1799
|
+
};
|
|
1800
|
+
var errorHandler = (err, c) => {
|
|
1801
|
+
if ("getResponse" in err) {
|
|
1802
|
+
const res = err.getResponse();
|
|
1803
|
+
return c.newResponse(res.body, res);
|
|
1804
|
+
}
|
|
1805
|
+
console.error(err);
|
|
1806
|
+
return c.text("Internal Server Error", 500);
|
|
1807
|
+
};
|
|
1808
|
+
var Hono = class {
|
|
1809
|
+
get;
|
|
1810
|
+
post;
|
|
1811
|
+
put;
|
|
1812
|
+
delete;
|
|
1813
|
+
options;
|
|
1814
|
+
patch;
|
|
1815
|
+
all;
|
|
1816
|
+
on;
|
|
1817
|
+
use;
|
|
1818
|
+
router;
|
|
1819
|
+
getPath;
|
|
1820
|
+
_basePath = "/";
|
|
1821
|
+
#path = "/";
|
|
1822
|
+
routes = [];
|
|
1823
|
+
constructor(options = {}) {
|
|
1824
|
+
const allMethods = [...METHODS, METHOD_NAME_ALL_LOWERCASE];
|
|
1825
|
+
allMethods.forEach((method) => {
|
|
1826
|
+
this[method] = (args1, ...args) => {
|
|
1827
|
+
if (typeof args1 === "string") {
|
|
1828
|
+
this.#path = args1;
|
|
1829
|
+
} else {
|
|
1830
|
+
this.#addRoute(method, this.#path, args1);
|
|
1831
|
+
}
|
|
1832
|
+
args.forEach((handler) => {
|
|
1833
|
+
this.#addRoute(method, this.#path, handler);
|
|
1834
|
+
});
|
|
1835
|
+
return this;
|
|
1836
|
+
};
|
|
1837
|
+
});
|
|
1838
|
+
this.on = (method, path, ...handlers) => {
|
|
1839
|
+
for (const p of [path].flat()) {
|
|
1840
|
+
this.#path = p;
|
|
1841
|
+
for (const m of [method].flat()) {
|
|
1842
|
+
handlers.map((handler) => {
|
|
1843
|
+
this.#addRoute(m.toUpperCase(), this.#path, handler);
|
|
1844
|
+
});
|
|
1845
|
+
}
|
|
1846
|
+
}
|
|
1847
|
+
return this;
|
|
1848
|
+
};
|
|
1849
|
+
this.use = (arg1, ...handlers) => {
|
|
1850
|
+
if (typeof arg1 === "string") {
|
|
1851
|
+
this.#path = arg1;
|
|
1852
|
+
} else {
|
|
1853
|
+
this.#path = "*";
|
|
1854
|
+
handlers.unshift(arg1);
|
|
1855
|
+
}
|
|
1856
|
+
handlers.forEach((handler) => {
|
|
1857
|
+
this.#addRoute(METHOD_NAME_ALL, this.#path, handler);
|
|
1858
|
+
});
|
|
1859
|
+
return this;
|
|
1860
|
+
};
|
|
1861
|
+
const { strict, ...optionsWithoutStrict } = options;
|
|
1862
|
+
Object.assign(this, optionsWithoutStrict);
|
|
1863
|
+
this.getPath = strict ?? true ? options.getPath ?? getPath : getPathNoStrict;
|
|
1864
|
+
}
|
|
1865
|
+
#clone() {
|
|
1866
|
+
const clone = new Hono({
|
|
1867
|
+
router: this.router,
|
|
1868
|
+
getPath: this.getPath
|
|
1869
|
+
});
|
|
1870
|
+
clone.errorHandler = this.errorHandler;
|
|
1871
|
+
clone.#notFoundHandler = this.#notFoundHandler;
|
|
1872
|
+
clone.routes = this.routes;
|
|
1873
|
+
return clone;
|
|
1874
|
+
}
|
|
1875
|
+
#notFoundHandler = notFoundHandler;
|
|
1876
|
+
errorHandler = errorHandler;
|
|
1877
|
+
route(path, app) {
|
|
1878
|
+
const subApp = this.basePath(path);
|
|
1879
|
+
app.routes.map((r) => {
|
|
1880
|
+
let handler;
|
|
1881
|
+
if (app.errorHandler === errorHandler) {
|
|
1882
|
+
handler = r.handler;
|
|
1883
|
+
} else {
|
|
1884
|
+
handler = async (c, next) => (await compose([], app.errorHandler)(c, () => r.handler(c, next))).res;
|
|
1885
|
+
handler[COMPOSED_HANDLER] = r.handler;
|
|
1886
|
+
}
|
|
1887
|
+
subApp.#addRoute(r.method, r.path, handler);
|
|
1888
|
+
});
|
|
1889
|
+
return this;
|
|
1890
|
+
}
|
|
1891
|
+
basePath(path) {
|
|
1892
|
+
const subApp = this.#clone();
|
|
1893
|
+
subApp._basePath = mergePath(this._basePath, path);
|
|
1894
|
+
return subApp;
|
|
1895
|
+
}
|
|
1896
|
+
onError = (handler) => {
|
|
1897
|
+
this.errorHandler = handler;
|
|
1898
|
+
return this;
|
|
1899
|
+
};
|
|
1900
|
+
notFound = (handler) => {
|
|
1901
|
+
this.#notFoundHandler = handler;
|
|
1902
|
+
return this;
|
|
1903
|
+
};
|
|
1904
|
+
mount(path, applicationHandler, options) {
|
|
1905
|
+
let replaceRequest;
|
|
1906
|
+
let optionHandler;
|
|
1907
|
+
if (options) {
|
|
1908
|
+
if (typeof options === "function") {
|
|
1909
|
+
optionHandler = options;
|
|
1910
|
+
} else {
|
|
1911
|
+
optionHandler = options.optionHandler;
|
|
1912
|
+
if (options.replaceRequest === false) {
|
|
1913
|
+
replaceRequest = (request) => request;
|
|
1914
|
+
} else {
|
|
1915
|
+
replaceRequest = options.replaceRequest;
|
|
1916
|
+
}
|
|
1917
|
+
}
|
|
1918
|
+
}
|
|
1919
|
+
const getOptions = optionHandler ? (c) => {
|
|
1920
|
+
const options2 = optionHandler(c);
|
|
1921
|
+
return Array.isArray(options2) ? options2 : [options2];
|
|
1922
|
+
} : (c) => {
|
|
1923
|
+
let executionContext = void 0;
|
|
1924
|
+
try {
|
|
1925
|
+
executionContext = c.executionCtx;
|
|
1926
|
+
} catch {
|
|
1927
|
+
}
|
|
1928
|
+
return [c.env, executionContext];
|
|
1929
|
+
};
|
|
1930
|
+
replaceRequest ||= (() => {
|
|
1931
|
+
const mergedPath = mergePath(this._basePath, path);
|
|
1932
|
+
const pathPrefixLength = mergedPath === "/" ? 0 : mergedPath.length;
|
|
1933
|
+
return (request) => {
|
|
1934
|
+
const url = new URL(request.url);
|
|
1935
|
+
url.pathname = url.pathname.slice(pathPrefixLength) || "/";
|
|
1936
|
+
return new Request(url, request);
|
|
1937
|
+
};
|
|
1938
|
+
})();
|
|
1939
|
+
const handler = async (c, next) => {
|
|
1940
|
+
const res = await applicationHandler(replaceRequest(c.req.raw), ...getOptions(c));
|
|
1941
|
+
if (res) {
|
|
1942
|
+
return res;
|
|
1943
|
+
}
|
|
1944
|
+
await next();
|
|
1945
|
+
};
|
|
1946
|
+
this.#addRoute(METHOD_NAME_ALL, mergePath(path, "*"), handler);
|
|
1947
|
+
return this;
|
|
1948
|
+
}
|
|
1949
|
+
#addRoute(method, path, handler) {
|
|
1950
|
+
method = method.toUpperCase();
|
|
1951
|
+
path = mergePath(this._basePath, path);
|
|
1952
|
+
const r = { basePath: this._basePath, path, method, handler };
|
|
1953
|
+
this.router.add(method, path, [handler, r]);
|
|
1954
|
+
this.routes.push(r);
|
|
1955
|
+
}
|
|
1956
|
+
#handleError(err, c) {
|
|
1957
|
+
if (err instanceof Error) {
|
|
1958
|
+
return this.errorHandler(err, c);
|
|
1959
|
+
}
|
|
1960
|
+
throw err;
|
|
1961
|
+
}
|
|
1962
|
+
#dispatch(request, executionCtx, env2, method) {
|
|
1963
|
+
if (method === "HEAD") {
|
|
1964
|
+
return (async () => new Response(null, await this.#dispatch(request, executionCtx, env2, "GET")))();
|
|
1965
|
+
}
|
|
1966
|
+
const path = this.getPath(request, { env: env2 });
|
|
1967
|
+
const matchResult = this.router.match(method, path);
|
|
1968
|
+
const c = new Context(request, {
|
|
1969
|
+
path,
|
|
1970
|
+
matchResult,
|
|
1971
|
+
env: env2,
|
|
1972
|
+
executionCtx,
|
|
1973
|
+
notFoundHandler: this.#notFoundHandler
|
|
1974
|
+
});
|
|
1975
|
+
if (matchResult[0].length === 1) {
|
|
1976
|
+
let res;
|
|
1977
|
+
try {
|
|
1978
|
+
res = matchResult[0][0][0][0](c, async () => {
|
|
1979
|
+
c.res = await this.#notFoundHandler(c);
|
|
1980
|
+
});
|
|
1981
|
+
} catch (err) {
|
|
1982
|
+
return this.#handleError(err, c);
|
|
1983
|
+
}
|
|
1984
|
+
return res instanceof Promise ? res.then(
|
|
1985
|
+
(resolved) => resolved || (c.finalized ? c.res : this.#notFoundHandler(c))
|
|
1986
|
+
).catch((err) => this.#handleError(err, c)) : res ?? this.#notFoundHandler(c);
|
|
1987
|
+
}
|
|
1988
|
+
const composed = compose(matchResult[0], this.errorHandler, this.#notFoundHandler);
|
|
1989
|
+
return (async () => {
|
|
1990
|
+
try {
|
|
1991
|
+
const context2 = await composed(c);
|
|
1992
|
+
if (!context2.finalized) {
|
|
1993
|
+
throw new Error(
|
|
1994
|
+
"Context is not finalized. Did you forget to return a Response object or `await next()`?"
|
|
1995
|
+
);
|
|
1996
|
+
}
|
|
1997
|
+
return context2.res;
|
|
1998
|
+
} catch (err) {
|
|
1999
|
+
return this.#handleError(err, c);
|
|
2000
|
+
}
|
|
2001
|
+
})();
|
|
2002
|
+
}
|
|
2003
|
+
fetch = (request, ...rest) => {
|
|
2004
|
+
return this.#dispatch(request, rest[1], rest[0], request.method);
|
|
2005
|
+
};
|
|
2006
|
+
request = (input, requestInit, Env, executionCtx) => {
|
|
2007
|
+
if (input instanceof Request) {
|
|
2008
|
+
return this.fetch(requestInit ? new Request(input, requestInit) : input, Env, executionCtx);
|
|
2009
|
+
}
|
|
2010
|
+
input = input.toString();
|
|
2011
|
+
return this.fetch(
|
|
2012
|
+
new Request(
|
|
2013
|
+
/^https?:\/\//.test(input) ? input : `http://localhost${mergePath("/", input)}`,
|
|
2014
|
+
requestInit
|
|
2015
|
+
),
|
|
2016
|
+
Env,
|
|
2017
|
+
executionCtx
|
|
2018
|
+
);
|
|
2019
|
+
};
|
|
2020
|
+
fire = () => {
|
|
2021
|
+
addEventListener("fetch", (event) => {
|
|
2022
|
+
event.respondWith(this.#dispatch(event.request, event, void 0, event.request.method));
|
|
2023
|
+
});
|
|
2024
|
+
};
|
|
2025
|
+
};
|
|
2026
|
+
|
|
2027
|
+
// ../../node_modules/hono/dist/router/reg-exp-router/node.js
|
|
2028
|
+
var LABEL_REG_EXP_STR = "[^/]+";
|
|
2029
|
+
var ONLY_WILDCARD_REG_EXP_STR = ".*";
|
|
2030
|
+
var TAIL_WILDCARD_REG_EXP_STR = "(?:|/.*)";
|
|
2031
|
+
var PATH_ERROR = Symbol();
|
|
2032
|
+
var regExpMetaChars = new Set(".\\+*[^]$()");
|
|
2033
|
+
function compareKey(a, b) {
|
|
2034
|
+
if (a.length === 1) {
|
|
2035
|
+
return b.length === 1 ? a < b ? -1 : 1 : -1;
|
|
2036
|
+
}
|
|
2037
|
+
if (b.length === 1) {
|
|
2038
|
+
return 1;
|
|
2039
|
+
}
|
|
2040
|
+
if (a === ONLY_WILDCARD_REG_EXP_STR || a === TAIL_WILDCARD_REG_EXP_STR) {
|
|
2041
|
+
return 1;
|
|
2042
|
+
} else if (b === ONLY_WILDCARD_REG_EXP_STR || b === TAIL_WILDCARD_REG_EXP_STR) {
|
|
2043
|
+
return -1;
|
|
2044
|
+
}
|
|
2045
|
+
if (a === LABEL_REG_EXP_STR) {
|
|
2046
|
+
return 1;
|
|
2047
|
+
} else if (b === LABEL_REG_EXP_STR) {
|
|
2048
|
+
return -1;
|
|
2049
|
+
}
|
|
2050
|
+
return a.length === b.length ? a < b ? -1 : 1 : b.length - a.length;
|
|
2051
|
+
}
|
|
2052
|
+
var Node = class {
|
|
2053
|
+
#index;
|
|
2054
|
+
#varIndex;
|
|
2055
|
+
#children = /* @__PURE__ */ Object.create(null);
|
|
2056
|
+
insert(tokens, index, paramMap, context2, pathErrorCheckOnly) {
|
|
2057
|
+
if (tokens.length === 0) {
|
|
2058
|
+
if (this.#index !== void 0) {
|
|
2059
|
+
throw PATH_ERROR;
|
|
2060
|
+
}
|
|
2061
|
+
if (pathErrorCheckOnly) {
|
|
2062
|
+
return;
|
|
2063
|
+
}
|
|
2064
|
+
this.#index = index;
|
|
2065
|
+
return;
|
|
2066
|
+
}
|
|
2067
|
+
const [token, ...restTokens] = tokens;
|
|
2068
|
+
const pattern = token === "*" ? restTokens.length === 0 ? ["", "", ONLY_WILDCARD_REG_EXP_STR] : ["", "", LABEL_REG_EXP_STR] : token === "/*" ? ["", "", TAIL_WILDCARD_REG_EXP_STR] : token.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
|
|
2069
|
+
let node;
|
|
2070
|
+
if (pattern) {
|
|
2071
|
+
const name = pattern[1];
|
|
2072
|
+
let regexpStr = pattern[2] || LABEL_REG_EXP_STR;
|
|
2073
|
+
if (name && pattern[2]) {
|
|
2074
|
+
if (regexpStr === ".*") {
|
|
2075
|
+
throw PATH_ERROR;
|
|
2076
|
+
}
|
|
2077
|
+
regexpStr = regexpStr.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:");
|
|
2078
|
+
if (/\((?!\?:)/.test(regexpStr)) {
|
|
2079
|
+
throw PATH_ERROR;
|
|
2080
|
+
}
|
|
2081
|
+
}
|
|
2082
|
+
node = this.#children[regexpStr];
|
|
2083
|
+
if (!node) {
|
|
2084
|
+
if (Object.keys(this.#children).some(
|
|
2085
|
+
(k) => k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR
|
|
2086
|
+
)) {
|
|
2087
|
+
throw PATH_ERROR;
|
|
2088
|
+
}
|
|
2089
|
+
if (pathErrorCheckOnly) {
|
|
2090
|
+
return;
|
|
2091
|
+
}
|
|
2092
|
+
node = this.#children[regexpStr] = new Node();
|
|
2093
|
+
if (name !== "") {
|
|
2094
|
+
node.#varIndex = context2.varIndex++;
|
|
2095
|
+
}
|
|
2096
|
+
}
|
|
2097
|
+
if (!pathErrorCheckOnly && name !== "") {
|
|
2098
|
+
paramMap.push([name, node.#varIndex]);
|
|
2099
|
+
}
|
|
2100
|
+
} else {
|
|
2101
|
+
node = this.#children[token];
|
|
2102
|
+
if (!node) {
|
|
2103
|
+
if (Object.keys(this.#children).some(
|
|
2104
|
+
(k) => k.length > 1 && k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR
|
|
2105
|
+
)) {
|
|
2106
|
+
throw PATH_ERROR;
|
|
2107
|
+
}
|
|
2108
|
+
if (pathErrorCheckOnly) {
|
|
2109
|
+
return;
|
|
2110
|
+
}
|
|
2111
|
+
node = this.#children[token] = new Node();
|
|
2112
|
+
}
|
|
2113
|
+
}
|
|
2114
|
+
node.insert(restTokens, index, paramMap, context2, pathErrorCheckOnly);
|
|
2115
|
+
}
|
|
2116
|
+
buildRegExpStr() {
|
|
2117
|
+
const childKeys = Object.keys(this.#children).sort(compareKey);
|
|
2118
|
+
const strList = childKeys.map((k) => {
|
|
2119
|
+
const c = this.#children[k];
|
|
2120
|
+
return (typeof c.#varIndex === "number" ? `(${k})@${c.#varIndex}` : regExpMetaChars.has(k) ? `\\${k}` : k) + c.buildRegExpStr();
|
|
2121
|
+
});
|
|
2122
|
+
if (typeof this.#index === "number") {
|
|
2123
|
+
strList.unshift(`#${this.#index}`);
|
|
2124
|
+
}
|
|
2125
|
+
if (strList.length === 0) {
|
|
2126
|
+
return "";
|
|
2127
|
+
}
|
|
2128
|
+
if (strList.length === 1) {
|
|
2129
|
+
return strList[0];
|
|
2130
|
+
}
|
|
2131
|
+
return "(?:" + strList.join("|") + ")";
|
|
2132
|
+
}
|
|
2133
|
+
};
|
|
2134
|
+
|
|
2135
|
+
// ../../node_modules/hono/dist/router/reg-exp-router/trie.js
|
|
2136
|
+
var Trie = class {
|
|
2137
|
+
#context = { varIndex: 0 };
|
|
2138
|
+
#root = new Node();
|
|
2139
|
+
insert(path, index, pathErrorCheckOnly) {
|
|
2140
|
+
const paramAssoc = [];
|
|
2141
|
+
const groups = [];
|
|
2142
|
+
for (let i = 0; ; ) {
|
|
2143
|
+
let replaced = false;
|
|
2144
|
+
path = path.replace(/\{[^}]+\}/g, (m) => {
|
|
2145
|
+
const mark = `@\\${i}`;
|
|
2146
|
+
groups[i] = [mark, m];
|
|
2147
|
+
i++;
|
|
2148
|
+
replaced = true;
|
|
2149
|
+
return mark;
|
|
2150
|
+
});
|
|
2151
|
+
if (!replaced) {
|
|
2152
|
+
break;
|
|
2153
|
+
}
|
|
2154
|
+
}
|
|
2155
|
+
const tokens = path.match(/(?::[^\/]+)|(?:\/\*$)|./g) || [];
|
|
2156
|
+
for (let i = groups.length - 1; i >= 0; i--) {
|
|
2157
|
+
const [mark] = groups[i];
|
|
2158
|
+
for (let j = tokens.length - 1; j >= 0; j--) {
|
|
2159
|
+
if (tokens[j].indexOf(mark) !== -1) {
|
|
2160
|
+
tokens[j] = tokens[j].replace(mark, groups[i][1]);
|
|
2161
|
+
break;
|
|
2162
|
+
}
|
|
2163
|
+
}
|
|
2164
|
+
}
|
|
2165
|
+
this.#root.insert(tokens, index, paramAssoc, this.#context, pathErrorCheckOnly);
|
|
2166
|
+
return paramAssoc;
|
|
2167
|
+
}
|
|
2168
|
+
buildRegExp() {
|
|
2169
|
+
let regexp = this.#root.buildRegExpStr();
|
|
2170
|
+
if (regexp === "") {
|
|
2171
|
+
return [/^$/, [], []];
|
|
2172
|
+
}
|
|
2173
|
+
let captureIndex = 0;
|
|
2174
|
+
const indexReplacementMap = [];
|
|
2175
|
+
const paramReplacementMap = [];
|
|
2176
|
+
regexp = regexp.replace(/#(\d+)|@(\d+)|\.\*\$/g, (_, handlerIndex, paramIndex) => {
|
|
2177
|
+
if (handlerIndex !== void 0) {
|
|
2178
|
+
indexReplacementMap[++captureIndex] = Number(handlerIndex);
|
|
2179
|
+
return "$()";
|
|
2180
|
+
}
|
|
2181
|
+
if (paramIndex !== void 0) {
|
|
2182
|
+
paramReplacementMap[Number(paramIndex)] = ++captureIndex;
|
|
2183
|
+
return "";
|
|
2184
|
+
}
|
|
2185
|
+
return "";
|
|
2186
|
+
});
|
|
2187
|
+
return [new RegExp(`^${regexp}`), indexReplacementMap, paramReplacementMap];
|
|
2188
|
+
}
|
|
2189
|
+
};
|
|
2190
|
+
|
|
2191
|
+
// ../../node_modules/hono/dist/router/reg-exp-router/router.js
|
|
2192
|
+
var emptyParam = [];
|
|
2193
|
+
var nullMatcher = [/^$/, [], /* @__PURE__ */ Object.create(null)];
|
|
2194
|
+
var wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
|
|
2195
|
+
function buildWildcardRegExp(path) {
|
|
2196
|
+
return wildcardRegExpCache[path] ??= new RegExp(
|
|
2197
|
+
path === "*" ? "" : `^${path.replace(
|
|
2198
|
+
/\/\*$|([.\\+*[^\]$()])/g,
|
|
2199
|
+
(_, metaChar) => metaChar ? `\\${metaChar}` : "(?:|/.*)"
|
|
2200
|
+
)}$`
|
|
2201
|
+
);
|
|
2202
|
+
}
|
|
2203
|
+
function clearWildcardRegExpCache() {
|
|
2204
|
+
wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
|
|
2205
|
+
}
|
|
2206
|
+
function buildMatcherFromPreprocessedRoutes(routes) {
|
|
2207
|
+
const trie = new Trie();
|
|
2208
|
+
const handlerData = [];
|
|
2209
|
+
if (routes.length === 0) {
|
|
2210
|
+
return nullMatcher;
|
|
2211
|
+
}
|
|
2212
|
+
const routesWithStaticPathFlag = routes.map(
|
|
2213
|
+
(route) => [!/\*|\/:/.test(route[0]), ...route]
|
|
2214
|
+
).sort(
|
|
2215
|
+
([isStaticA, pathA], [isStaticB, pathB]) => isStaticA ? 1 : isStaticB ? -1 : pathA.length - pathB.length
|
|
2216
|
+
);
|
|
2217
|
+
const staticMap = /* @__PURE__ */ Object.create(null);
|
|
2218
|
+
for (let i = 0, j = -1, len = routesWithStaticPathFlag.length; i < len; i++) {
|
|
2219
|
+
const [pathErrorCheckOnly, path, handlers] = routesWithStaticPathFlag[i];
|
|
2220
|
+
if (pathErrorCheckOnly) {
|
|
2221
|
+
staticMap[path] = [handlers.map(([h]) => [h, /* @__PURE__ */ Object.create(null)]), emptyParam];
|
|
2222
|
+
} else {
|
|
2223
|
+
j++;
|
|
2224
|
+
}
|
|
2225
|
+
let paramAssoc;
|
|
2226
|
+
try {
|
|
2227
|
+
paramAssoc = trie.insert(path, j, pathErrorCheckOnly);
|
|
2228
|
+
} catch (e) {
|
|
2229
|
+
throw e === PATH_ERROR ? new UnsupportedPathError(path) : e;
|
|
2230
|
+
}
|
|
2231
|
+
if (pathErrorCheckOnly) {
|
|
2232
|
+
continue;
|
|
2233
|
+
}
|
|
2234
|
+
handlerData[j] = handlers.map(([h, paramCount]) => {
|
|
2235
|
+
const paramIndexMap = /* @__PURE__ */ Object.create(null);
|
|
2236
|
+
paramCount -= 1;
|
|
2237
|
+
for (; paramCount >= 0; paramCount--) {
|
|
2238
|
+
const [key, value] = paramAssoc[paramCount];
|
|
2239
|
+
paramIndexMap[key] = value;
|
|
2240
|
+
}
|
|
2241
|
+
return [h, paramIndexMap];
|
|
2242
|
+
});
|
|
2243
|
+
}
|
|
2244
|
+
const [regexp, indexReplacementMap, paramReplacementMap] = trie.buildRegExp();
|
|
2245
|
+
for (let i = 0, len = handlerData.length; i < len; i++) {
|
|
2246
|
+
for (let j = 0, len2 = handlerData[i].length; j < len2; j++) {
|
|
2247
|
+
const map = handlerData[i][j]?.[1];
|
|
2248
|
+
if (!map) {
|
|
2249
|
+
continue;
|
|
2250
|
+
}
|
|
2251
|
+
const keys = Object.keys(map);
|
|
2252
|
+
for (let k = 0, len3 = keys.length; k < len3; k++) {
|
|
2253
|
+
map[keys[k]] = paramReplacementMap[map[keys[k]]];
|
|
2254
|
+
}
|
|
2255
|
+
}
|
|
2256
|
+
}
|
|
2257
|
+
const handlerMap = [];
|
|
2258
|
+
for (const i in indexReplacementMap) {
|
|
2259
|
+
handlerMap[i] = handlerData[indexReplacementMap[i]];
|
|
2260
|
+
}
|
|
2261
|
+
return [regexp, handlerMap, staticMap];
|
|
2262
|
+
}
|
|
2263
|
+
function findMiddleware(middleware, path) {
|
|
2264
|
+
if (!middleware) {
|
|
2265
|
+
return void 0;
|
|
2266
|
+
}
|
|
2267
|
+
for (const k of Object.keys(middleware).sort((a, b) => b.length - a.length)) {
|
|
2268
|
+
if (buildWildcardRegExp(k).test(path)) {
|
|
2269
|
+
return [...middleware[k]];
|
|
2270
|
+
}
|
|
2271
|
+
}
|
|
2272
|
+
return void 0;
|
|
2273
|
+
}
|
|
2274
|
+
var RegExpRouter = class {
|
|
2275
|
+
name = "RegExpRouter";
|
|
2276
|
+
#middleware;
|
|
2277
|
+
#routes;
|
|
2278
|
+
constructor() {
|
|
2279
|
+
this.#middleware = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
|
|
2280
|
+
this.#routes = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
|
|
2281
|
+
}
|
|
2282
|
+
add(method, path, handler) {
|
|
2283
|
+
const middleware = this.#middleware;
|
|
2284
|
+
const routes = this.#routes;
|
|
2285
|
+
if (!middleware || !routes) {
|
|
2286
|
+
throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
|
|
2287
|
+
}
|
|
2288
|
+
if (!middleware[method]) {
|
|
2289
|
+
;
|
|
2290
|
+
[middleware, routes].forEach((handlerMap) => {
|
|
2291
|
+
handlerMap[method] = /* @__PURE__ */ Object.create(null);
|
|
2292
|
+
Object.keys(handlerMap[METHOD_NAME_ALL]).forEach((p) => {
|
|
2293
|
+
handlerMap[method][p] = [...handlerMap[METHOD_NAME_ALL][p]];
|
|
2294
|
+
});
|
|
2295
|
+
});
|
|
2296
|
+
}
|
|
2297
|
+
if (path === "/*") {
|
|
2298
|
+
path = "*";
|
|
2299
|
+
}
|
|
2300
|
+
const paramCount = (path.match(/\/:/g) || []).length;
|
|
2301
|
+
if (/\*$/.test(path)) {
|
|
2302
|
+
const re = buildWildcardRegExp(path);
|
|
2303
|
+
if (method === METHOD_NAME_ALL) {
|
|
2304
|
+
Object.keys(middleware).forEach((m) => {
|
|
2305
|
+
middleware[m][path] ||= findMiddleware(middleware[m], path) || findMiddleware(middleware[METHOD_NAME_ALL], path) || [];
|
|
2306
|
+
});
|
|
2307
|
+
} else {
|
|
2308
|
+
middleware[method][path] ||= findMiddleware(middleware[method], path) || findMiddleware(middleware[METHOD_NAME_ALL], path) || [];
|
|
2309
|
+
}
|
|
2310
|
+
Object.keys(middleware).forEach((m) => {
|
|
2311
|
+
if (method === METHOD_NAME_ALL || method === m) {
|
|
2312
|
+
Object.keys(middleware[m]).forEach((p) => {
|
|
2313
|
+
re.test(p) && middleware[m][p].push([handler, paramCount]);
|
|
2314
|
+
});
|
|
2315
|
+
}
|
|
2316
|
+
});
|
|
2317
|
+
Object.keys(routes).forEach((m) => {
|
|
2318
|
+
if (method === METHOD_NAME_ALL || method === m) {
|
|
2319
|
+
Object.keys(routes[m]).forEach(
|
|
2320
|
+
(p) => re.test(p) && routes[m][p].push([handler, paramCount])
|
|
2321
|
+
);
|
|
2322
|
+
}
|
|
2323
|
+
});
|
|
2324
|
+
return;
|
|
2325
|
+
}
|
|
2326
|
+
const paths = checkOptionalParameter(path) || [path];
|
|
2327
|
+
for (let i = 0, len = paths.length; i < len; i++) {
|
|
2328
|
+
const path2 = paths[i];
|
|
2329
|
+
Object.keys(routes).forEach((m) => {
|
|
2330
|
+
if (method === METHOD_NAME_ALL || method === m) {
|
|
2331
|
+
routes[m][path2] ||= [
|
|
2332
|
+
...findMiddleware(middleware[m], path2) || findMiddleware(middleware[METHOD_NAME_ALL], path2) || []
|
|
2333
|
+
];
|
|
2334
|
+
routes[m][path2].push([handler, paramCount - len + i + 1]);
|
|
2335
|
+
}
|
|
2336
|
+
});
|
|
2337
|
+
}
|
|
2338
|
+
}
|
|
2339
|
+
match(method, path) {
|
|
2340
|
+
clearWildcardRegExpCache();
|
|
2341
|
+
const matchers = this.#buildAllMatchers();
|
|
2342
|
+
this.match = (method2, path2) => {
|
|
2343
|
+
const matcher = matchers[method2] || matchers[METHOD_NAME_ALL];
|
|
2344
|
+
const staticMatch = matcher[2][path2];
|
|
2345
|
+
if (staticMatch) {
|
|
2346
|
+
return staticMatch;
|
|
2347
|
+
}
|
|
2348
|
+
const match = path2.match(matcher[0]);
|
|
2349
|
+
if (!match) {
|
|
2350
|
+
return [[], emptyParam];
|
|
2351
|
+
}
|
|
2352
|
+
const index = match.indexOf("", 1);
|
|
2353
|
+
return [matcher[1][index], match];
|
|
2354
|
+
};
|
|
2355
|
+
return this.match(method, path);
|
|
2356
|
+
}
|
|
2357
|
+
#buildAllMatchers() {
|
|
2358
|
+
const matchers = /* @__PURE__ */ Object.create(null);
|
|
2359
|
+
Object.keys(this.#routes).concat(Object.keys(this.#middleware)).forEach((method) => {
|
|
2360
|
+
matchers[method] ||= this.#buildMatcher(method);
|
|
2361
|
+
});
|
|
2362
|
+
this.#middleware = this.#routes = void 0;
|
|
2363
|
+
return matchers;
|
|
2364
|
+
}
|
|
2365
|
+
#buildMatcher(method) {
|
|
2366
|
+
const routes = [];
|
|
2367
|
+
let hasOwnRoute = method === METHOD_NAME_ALL;
|
|
2368
|
+
[this.#middleware, this.#routes].forEach((r) => {
|
|
2369
|
+
const ownRoute = r[method] ? Object.keys(r[method]).map((path) => [path, r[method][path]]) : [];
|
|
2370
|
+
if (ownRoute.length !== 0) {
|
|
2371
|
+
hasOwnRoute ||= true;
|
|
2372
|
+
routes.push(...ownRoute);
|
|
2373
|
+
} else if (method !== METHOD_NAME_ALL) {
|
|
2374
|
+
routes.push(
|
|
2375
|
+
...Object.keys(r[METHOD_NAME_ALL]).map((path) => [path, r[METHOD_NAME_ALL][path]])
|
|
2376
|
+
);
|
|
2377
|
+
}
|
|
2378
|
+
});
|
|
2379
|
+
if (!hasOwnRoute) {
|
|
2380
|
+
return null;
|
|
2381
|
+
} else {
|
|
2382
|
+
return buildMatcherFromPreprocessedRoutes(routes);
|
|
2383
|
+
}
|
|
2384
|
+
}
|
|
2385
|
+
};
|
|
2386
|
+
|
|
2387
|
+
// ../../node_modules/hono/dist/router/smart-router/router.js
|
|
2388
|
+
var SmartRouter = class {
|
|
2389
|
+
name = "SmartRouter";
|
|
2390
|
+
#routers = [];
|
|
2391
|
+
#routes = [];
|
|
2392
|
+
constructor(init) {
|
|
2393
|
+
this.#routers = init.routers;
|
|
2394
|
+
}
|
|
2395
|
+
add(method, path, handler) {
|
|
2396
|
+
if (!this.#routes) {
|
|
2397
|
+
throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
|
|
2398
|
+
}
|
|
2399
|
+
this.#routes.push([method, path, handler]);
|
|
2400
|
+
}
|
|
2401
|
+
match(method, path) {
|
|
2402
|
+
if (!this.#routes) {
|
|
2403
|
+
throw new Error("Fatal error");
|
|
2404
|
+
}
|
|
2405
|
+
const routers = this.#routers;
|
|
2406
|
+
const routes = this.#routes;
|
|
2407
|
+
const len = routers.length;
|
|
2408
|
+
let i = 0;
|
|
2409
|
+
let res;
|
|
2410
|
+
for (; i < len; i++) {
|
|
2411
|
+
const router = routers[i];
|
|
2412
|
+
try {
|
|
2413
|
+
for (let i2 = 0, len2 = routes.length; i2 < len2; i2++) {
|
|
2414
|
+
router.add(...routes[i2]);
|
|
2415
|
+
}
|
|
2416
|
+
res = router.match(method, path);
|
|
2417
|
+
} catch (e) {
|
|
2418
|
+
if (e instanceof UnsupportedPathError) {
|
|
2419
|
+
continue;
|
|
2420
|
+
}
|
|
2421
|
+
throw e;
|
|
2422
|
+
}
|
|
2423
|
+
this.match = router.match.bind(router);
|
|
2424
|
+
this.#routers = [router];
|
|
2425
|
+
this.#routes = void 0;
|
|
2426
|
+
break;
|
|
2427
|
+
}
|
|
2428
|
+
if (i === len) {
|
|
2429
|
+
throw new Error("Fatal error");
|
|
2430
|
+
}
|
|
2431
|
+
this.name = `SmartRouter + ${this.activeRouter.name}`;
|
|
2432
|
+
return res;
|
|
2433
|
+
}
|
|
2434
|
+
get activeRouter() {
|
|
2435
|
+
if (this.#routes || this.#routers.length !== 1) {
|
|
2436
|
+
throw new Error("No active router has been determined yet.");
|
|
2437
|
+
}
|
|
2438
|
+
return this.#routers[0];
|
|
2439
|
+
}
|
|
2440
|
+
};
|
|
2441
|
+
|
|
2442
|
+
// ../../node_modules/hono/dist/router/trie-router/node.js
|
|
2443
|
+
var emptyParams = /* @__PURE__ */ Object.create(null);
|
|
2444
|
+
var Node2 = class {
|
|
2445
|
+
#methods;
|
|
2446
|
+
#children;
|
|
2447
|
+
#patterns;
|
|
2448
|
+
#order = 0;
|
|
2449
|
+
#params = emptyParams;
|
|
2450
|
+
constructor(method, handler, children) {
|
|
2451
|
+
this.#children = children || /* @__PURE__ */ Object.create(null);
|
|
2452
|
+
this.#methods = [];
|
|
2453
|
+
if (method && handler) {
|
|
2454
|
+
const m = /* @__PURE__ */ Object.create(null);
|
|
2455
|
+
m[method] = { handler, possibleKeys: [], score: 0 };
|
|
2456
|
+
this.#methods = [m];
|
|
2457
|
+
}
|
|
2458
|
+
this.#patterns = [];
|
|
2459
|
+
}
|
|
2460
|
+
insert(method, path, handler) {
|
|
2461
|
+
this.#order = ++this.#order;
|
|
2462
|
+
let curNode = this;
|
|
2463
|
+
const parts = splitRoutingPath(path);
|
|
2464
|
+
const possibleKeys = [];
|
|
2465
|
+
for (let i = 0, len = parts.length; i < len; i++) {
|
|
2466
|
+
const p = parts[i];
|
|
2467
|
+
const nextP = parts[i + 1];
|
|
2468
|
+
const pattern = getPattern(p, nextP);
|
|
2469
|
+
const key = Array.isArray(pattern) ? pattern[0] : p;
|
|
2470
|
+
if (key in curNode.#children) {
|
|
2471
|
+
curNode = curNode.#children[key];
|
|
2472
|
+
if (pattern) {
|
|
2473
|
+
possibleKeys.push(pattern[1]);
|
|
2474
|
+
}
|
|
2475
|
+
continue;
|
|
2476
|
+
}
|
|
2477
|
+
curNode.#children[key] = new Node2();
|
|
2478
|
+
if (pattern) {
|
|
2479
|
+
curNode.#patterns.push(pattern);
|
|
2480
|
+
possibleKeys.push(pattern[1]);
|
|
2481
|
+
}
|
|
2482
|
+
curNode = curNode.#children[key];
|
|
2483
|
+
}
|
|
2484
|
+
curNode.#methods.push({
|
|
2485
|
+
[method]: {
|
|
2486
|
+
handler,
|
|
2487
|
+
possibleKeys: possibleKeys.filter((v, i, a) => a.indexOf(v) === i),
|
|
2488
|
+
score: this.#order
|
|
2489
|
+
}
|
|
2490
|
+
});
|
|
2491
|
+
return curNode;
|
|
2492
|
+
}
|
|
2493
|
+
#getHandlerSets(node, method, nodeParams, params) {
|
|
2494
|
+
const handlerSets = [];
|
|
2495
|
+
for (let i = 0, len = node.#methods.length; i < len; i++) {
|
|
2496
|
+
const m = node.#methods[i];
|
|
2497
|
+
const handlerSet = m[method] || m[METHOD_NAME_ALL];
|
|
2498
|
+
const processedSet = {};
|
|
2499
|
+
if (handlerSet !== void 0) {
|
|
2500
|
+
handlerSet.params = /* @__PURE__ */ Object.create(null);
|
|
2501
|
+
handlerSets.push(handlerSet);
|
|
2502
|
+
if (nodeParams !== emptyParams || params && params !== emptyParams) {
|
|
2503
|
+
for (let i2 = 0, len2 = handlerSet.possibleKeys.length; i2 < len2; i2++) {
|
|
2504
|
+
const key = handlerSet.possibleKeys[i2];
|
|
2505
|
+
const processed = processedSet[handlerSet.score];
|
|
2506
|
+
handlerSet.params[key] = params?.[key] && !processed ? params[key] : nodeParams[key] ?? params?.[key];
|
|
2507
|
+
processedSet[handlerSet.score] = true;
|
|
2508
|
+
}
|
|
2509
|
+
}
|
|
2510
|
+
}
|
|
2511
|
+
}
|
|
2512
|
+
return handlerSets;
|
|
2513
|
+
}
|
|
2514
|
+
search(method, path) {
|
|
2515
|
+
const handlerSets = [];
|
|
2516
|
+
this.#params = emptyParams;
|
|
2517
|
+
const curNode = this;
|
|
2518
|
+
let curNodes = [curNode];
|
|
2519
|
+
const parts = splitPath(path);
|
|
2520
|
+
const curNodesQueue = [];
|
|
2521
|
+
for (let i = 0, len = parts.length; i < len; i++) {
|
|
2522
|
+
const part = parts[i];
|
|
2523
|
+
const isLast = i === len - 1;
|
|
2524
|
+
const tempNodes = [];
|
|
2525
|
+
for (let j = 0, len2 = curNodes.length; j < len2; j++) {
|
|
2526
|
+
const node = curNodes[j];
|
|
2527
|
+
const nextNode = node.#children[part];
|
|
2528
|
+
if (nextNode) {
|
|
2529
|
+
nextNode.#params = node.#params;
|
|
2530
|
+
if (isLast) {
|
|
2531
|
+
if (nextNode.#children["*"]) {
|
|
2532
|
+
handlerSets.push(
|
|
2533
|
+
...this.#getHandlerSets(nextNode.#children["*"], method, node.#params)
|
|
2534
|
+
);
|
|
2535
|
+
}
|
|
2536
|
+
handlerSets.push(...this.#getHandlerSets(nextNode, method, node.#params));
|
|
2537
|
+
} else {
|
|
2538
|
+
tempNodes.push(nextNode);
|
|
2539
|
+
}
|
|
2540
|
+
}
|
|
2541
|
+
for (let k = 0, len3 = node.#patterns.length; k < len3; k++) {
|
|
2542
|
+
const pattern = node.#patterns[k];
|
|
2543
|
+
const params = node.#params === emptyParams ? {} : { ...node.#params };
|
|
2544
|
+
if (pattern === "*") {
|
|
2545
|
+
const astNode = node.#children["*"];
|
|
2546
|
+
if (astNode) {
|
|
2547
|
+
handlerSets.push(...this.#getHandlerSets(astNode, method, node.#params));
|
|
2548
|
+
astNode.#params = params;
|
|
2549
|
+
tempNodes.push(astNode);
|
|
2550
|
+
}
|
|
2551
|
+
continue;
|
|
2552
|
+
}
|
|
2553
|
+
const [key, name, matcher] = pattern;
|
|
2554
|
+
if (!part && !(matcher instanceof RegExp)) {
|
|
2555
|
+
continue;
|
|
2556
|
+
}
|
|
2557
|
+
const child = node.#children[key];
|
|
2558
|
+
const restPathString = parts.slice(i).join("/");
|
|
2559
|
+
if (matcher instanceof RegExp) {
|
|
2560
|
+
const m = matcher.exec(restPathString);
|
|
2561
|
+
if (m) {
|
|
2562
|
+
params[name] = m[0];
|
|
2563
|
+
handlerSets.push(...this.#getHandlerSets(child, method, node.#params, params));
|
|
2564
|
+
if (Object.keys(child.#children).length) {
|
|
2565
|
+
child.#params = params;
|
|
2566
|
+
const componentCount = m[0].match(/\//)?.length ?? 0;
|
|
2567
|
+
const targetCurNodes = curNodesQueue[componentCount] ||= [];
|
|
2568
|
+
targetCurNodes.push(child);
|
|
2569
|
+
}
|
|
2570
|
+
continue;
|
|
2571
|
+
}
|
|
2572
|
+
}
|
|
2573
|
+
if (matcher === true || matcher.test(part)) {
|
|
2574
|
+
params[name] = part;
|
|
2575
|
+
if (isLast) {
|
|
2576
|
+
handlerSets.push(...this.#getHandlerSets(child, method, params, node.#params));
|
|
2577
|
+
if (child.#children["*"]) {
|
|
2578
|
+
handlerSets.push(
|
|
2579
|
+
...this.#getHandlerSets(child.#children["*"], method, params, node.#params)
|
|
2580
|
+
);
|
|
2581
|
+
}
|
|
2582
|
+
} else {
|
|
2583
|
+
child.#params = params;
|
|
2584
|
+
tempNodes.push(child);
|
|
2585
|
+
}
|
|
2586
|
+
}
|
|
2587
|
+
}
|
|
2588
|
+
}
|
|
2589
|
+
curNodes = tempNodes.concat(curNodesQueue.shift() ?? []);
|
|
2590
|
+
}
|
|
2591
|
+
if (handlerSets.length > 1) {
|
|
2592
|
+
handlerSets.sort((a, b) => {
|
|
2593
|
+
return a.score - b.score;
|
|
2594
|
+
});
|
|
2595
|
+
}
|
|
2596
|
+
return [handlerSets.map(({ handler, params }) => [handler, params])];
|
|
2597
|
+
}
|
|
2598
|
+
};
|
|
2599
|
+
|
|
2600
|
+
// ../../node_modules/hono/dist/router/trie-router/router.js
|
|
2601
|
+
var TrieRouter = class {
|
|
2602
|
+
name = "TrieRouter";
|
|
2603
|
+
#node;
|
|
2604
|
+
constructor() {
|
|
2605
|
+
this.#node = new Node2();
|
|
2606
|
+
}
|
|
2607
|
+
add(method, path, handler) {
|
|
2608
|
+
const results = checkOptionalParameter(path);
|
|
2609
|
+
if (results) {
|
|
2610
|
+
for (let i = 0, len = results.length; i < len; i++) {
|
|
2611
|
+
this.#node.insert(method, results[i], handler);
|
|
2612
|
+
}
|
|
2613
|
+
return;
|
|
2614
|
+
}
|
|
2615
|
+
this.#node.insert(method, path, handler);
|
|
2616
|
+
}
|
|
2617
|
+
match(method, path) {
|
|
2618
|
+
return this.#node.search(method, path);
|
|
2619
|
+
}
|
|
2620
|
+
};
|
|
2621
|
+
|
|
2622
|
+
// ../../node_modules/hono/dist/hono.js
|
|
2623
|
+
var Hono2 = class extends Hono {
|
|
2624
|
+
constructor(options = {}) {
|
|
2625
|
+
super(options);
|
|
2626
|
+
this.router = options.router ?? new SmartRouter({
|
|
2627
|
+
routers: [new RegExpRouter(), new TrieRouter()]
|
|
2628
|
+
});
|
|
2629
|
+
}
|
|
2630
|
+
};
|
|
2631
|
+
|
|
2632
|
+
// ../../node_modules/hono/dist/http-exception.js
|
|
2633
|
+
var HTTPException = class extends Error {
|
|
2634
|
+
res;
|
|
2635
|
+
status;
|
|
2636
|
+
constructor(status = 500, options) {
|
|
2637
|
+
super(options?.message, { cause: options?.cause });
|
|
2638
|
+
this.res = options?.res;
|
|
2639
|
+
this.status = status;
|
|
2640
|
+
}
|
|
2641
|
+
getResponse() {
|
|
2642
|
+
if (this.res) {
|
|
2643
|
+
const newResponse = new Response(this.res.body, {
|
|
2644
|
+
status: this.status,
|
|
2645
|
+
headers: this.res.headers
|
|
2646
|
+
});
|
|
2647
|
+
return newResponse;
|
|
2648
|
+
}
|
|
2649
|
+
return new Response(this.message, {
|
|
2650
|
+
status: this.status
|
|
2651
|
+
});
|
|
2652
|
+
}
|
|
2653
|
+
};
|
|
2654
|
+
|
|
2655
|
+
// src/server.ts
|
|
2656
|
+
async function handleError2(context2, pluginOptions, error) {
|
|
2657
|
+
console.error(error);
|
|
2658
|
+
const loggerError = transformError(context2, error);
|
|
2659
|
+
if (pluginOptions.postCommentOnError && loggerError) {
|
|
2660
|
+
await context2.commentHandler.postComment(context2, loggerError);
|
|
2661
|
+
}
|
|
2662
|
+
throw new HTTPException(500, { message: "Unexpected error" });
|
|
2663
|
+
}
|
|
2664
|
+
function createPlugin(handler, manifest, options) {
|
|
2665
|
+
const pluginOptions = getPluginOptions(options);
|
|
2666
|
+
const app = new Hono2();
|
|
2667
|
+
app.get("/manifest.json", (ctx) => {
|
|
2668
|
+
return ctx.json(manifest);
|
|
2669
|
+
});
|
|
2670
|
+
app.post("/", async function appPost(ctx) {
|
|
2671
|
+
if (ctx.req.header("content-type") !== "application/json") {
|
|
2672
|
+
throw new HTTPException(400, { message: "Content-Type must be application/json" });
|
|
2673
|
+
}
|
|
2674
|
+
const body = await ctx.req.json();
|
|
2675
|
+
const inputSchemaErrors = [...Value4.Errors(inputSchema, body)];
|
|
2676
|
+
if (inputSchemaErrors.length) {
|
|
2677
|
+
console.dir(inputSchemaErrors, { depth: null });
|
|
2678
|
+
throw new HTTPException(400, { message: "Invalid body" });
|
|
2679
|
+
}
|
|
2680
|
+
const signature = body.signature;
|
|
2681
|
+
if (!pluginOptions.bypassSignatureVerification && !await verifySignature(pluginOptions.kernelPublicKey, body, signature)) {
|
|
2682
|
+
throw new HTTPException(400, { message: "Invalid signature" });
|
|
2683
|
+
}
|
|
2684
|
+
const inputs = Value4.Decode(inputSchema, body);
|
|
2685
|
+
let config2;
|
|
2686
|
+
if (pluginOptions.settingsSchema) {
|
|
2687
|
+
try {
|
|
2688
|
+
config2 = Value4.Decode(pluginOptions.settingsSchema, Value4.Default(pluginOptions.settingsSchema, inputs.settings));
|
|
2689
|
+
} catch (e) {
|
|
2690
|
+
console.dir(...Value4.Errors(pluginOptions.settingsSchema, inputs.settings), { depth: null });
|
|
2691
|
+
throw e;
|
|
2692
|
+
}
|
|
2693
|
+
} else {
|
|
2694
|
+
config2 = inputs.settings;
|
|
2695
|
+
}
|
|
2696
|
+
let env2;
|
|
2697
|
+
const honoEnvironment = env(ctx);
|
|
2698
|
+
if (pluginOptions.envSchema) {
|
|
2699
|
+
try {
|
|
2700
|
+
env2 = Value4.Decode(pluginOptions.envSchema, Value4.Default(pluginOptions.envSchema, honoEnvironment));
|
|
2701
|
+
} catch (e) {
|
|
2702
|
+
console.dir(...Value4.Errors(pluginOptions.envSchema, honoEnvironment), { depth: null });
|
|
2703
|
+
throw e;
|
|
2704
|
+
}
|
|
2705
|
+
} else {
|
|
2706
|
+
env2 = ctx.env;
|
|
2707
|
+
}
|
|
2708
|
+
const workerName = new URL(inputs.ref).hostname.split(".")[0];
|
|
2709
|
+
PluginRuntimeInfo.getInstance({ ...env2, CLOUDFLARE_WORKER_NAME: workerName });
|
|
2710
|
+
const command = getCommand(inputs, pluginOptions);
|
|
2711
|
+
const context2 = {
|
|
2712
|
+
eventName: inputs.eventName,
|
|
2713
|
+
payload: inputs.eventPayload,
|
|
2714
|
+
command,
|
|
2715
|
+
authToken: inputs.authToken,
|
|
2716
|
+
ubiquityKernelToken: inputs.ubiquityKernelToken,
|
|
2717
|
+
octokit: new customOctokit({ auth: inputs.authToken }),
|
|
2718
|
+
config: config2,
|
|
2719
|
+
env: env2,
|
|
2720
|
+
logger: new Logs(pluginOptions.logLevel),
|
|
2721
|
+
commentHandler: new CommentHandler()
|
|
2722
|
+
};
|
|
2723
|
+
try {
|
|
2724
|
+
const result = await handler(context2);
|
|
2725
|
+
return ctx.json({ stateId: inputs.stateId, output: result ?? {} });
|
|
2726
|
+
} catch (error) {
|
|
2727
|
+
await handleError2(context2, pluginOptions, error);
|
|
2728
|
+
}
|
|
2729
|
+
});
|
|
2730
|
+
return app;
|
|
2731
|
+
}
|
|
2732
|
+
|
|
2733
|
+
// src/llm/index.ts
|
|
2734
|
+
function normalizeBaseUrl(baseUrl) {
|
|
2735
|
+
return baseUrl.trim().replace(/\/+$/, "");
|
|
2736
|
+
}
|
|
2737
|
+
function getEnvString(name) {
|
|
2738
|
+
if (typeof process === "undefined" || !process?.env) return "";
|
|
2739
|
+
return String(process.env[name] ?? "").trim();
|
|
2740
|
+
}
|
|
2741
|
+
function getAiBaseUrl(options) {
|
|
2742
|
+
if (typeof options.baseUrl === "string" && options.baseUrl.trim()) {
|
|
2743
|
+
return normalizeBaseUrl(options.baseUrl);
|
|
2744
|
+
}
|
|
2745
|
+
const envBaseUrl = getEnvString("UBQ_AI_BASE_URL") || getEnvString("UBQ_AI_URL");
|
|
2746
|
+
if (envBaseUrl) return normalizeBaseUrl(envBaseUrl);
|
|
2747
|
+
return "https://ai.ubq.fi";
|
|
2748
|
+
}
|
|
2749
|
+
async function callLlm(options, input) {
|
|
2750
|
+
const authToken = input?.authToken ?? "";
|
|
2751
|
+
const ubiquityKernelToken = input?.ubiquityKernelToken ?? "";
|
|
2752
|
+
const payload = input?.payload;
|
|
2753
|
+
const owner = payload?.repository?.owner?.login ?? "";
|
|
2754
|
+
const repo = payload?.repository?.name ?? "";
|
|
2755
|
+
const installationId = payload?.installation?.id;
|
|
2756
|
+
if (!authToken) throw new Error("Missing authToken in inputs");
|
|
2757
|
+
const requiresKernelToken = authToken.trim().startsWith("gh");
|
|
2758
|
+
if (requiresKernelToken && !ubiquityKernelToken) {
|
|
2759
|
+
throw new Error("Missing ubiquityKernelToken in inputs (kernel attestation is required for GitHub auth)");
|
|
2760
|
+
}
|
|
2761
|
+
const url = `${getAiBaseUrl(options)}/v1/chat/completions`;
|
|
2762
|
+
const { baseUrl: _baseUrl, model, stream, messages, ...rest } = options;
|
|
2763
|
+
const body = JSON.stringify({
|
|
2764
|
+
...rest,
|
|
2765
|
+
...model ? { model } : {},
|
|
2766
|
+
messages,
|
|
2767
|
+
stream: stream ?? false
|
|
2768
|
+
});
|
|
2769
|
+
const headers = {
|
|
2770
|
+
Authorization: `Bearer ${authToken}`,
|
|
2771
|
+
"Content-Type": "application/json"
|
|
2772
|
+
};
|
|
2773
|
+
if (owner) headers["X-GitHub-Owner"] = owner;
|
|
2774
|
+
if (repo) headers["X-GitHub-Repo"] = repo;
|
|
2775
|
+
if (typeof installationId === "number" && Number.isFinite(installationId)) {
|
|
2776
|
+
headers["X-GitHub-Installation-Id"] = String(installationId);
|
|
2777
|
+
}
|
|
2778
|
+
if (ubiquityKernelToken) {
|
|
2779
|
+
headers["X-Ubiquity-Kernel-Token"] = ubiquityKernelToken;
|
|
2780
|
+
}
|
|
2781
|
+
const response = await fetch(url, { method: "POST", headers, body });
|
|
2782
|
+
if (!response.ok) {
|
|
2783
|
+
const err = await response.text();
|
|
2784
|
+
throw new Error(`LLM API error: ${response.status} - ${err}`);
|
|
2785
|
+
}
|
|
2786
|
+
if (options.stream) {
|
|
2787
|
+
return parseSseStream(response.body);
|
|
2788
|
+
}
|
|
2789
|
+
return response.json();
|
|
2790
|
+
}
|
|
2791
|
+
async function* parseSseStream(body) {
|
|
2792
|
+
const reader = body.getReader();
|
|
2793
|
+
const decoder = new TextDecoder();
|
|
2794
|
+
let buffer = "";
|
|
2795
|
+
try {
|
|
2796
|
+
while (true) {
|
|
2797
|
+
const { value, done } = await reader.read();
|
|
2798
|
+
if (done) break;
|
|
2799
|
+
buffer += decoder.decode(value, { stream: true });
|
|
2800
|
+
const events = buffer.split("\n\n");
|
|
2801
|
+
buffer = events.pop() || "";
|
|
2802
|
+
for (const event of events) {
|
|
2803
|
+
if (event.startsWith("data: ")) {
|
|
2804
|
+
const data = event.slice(6);
|
|
2805
|
+
if (data === "[DONE]") return;
|
|
2806
|
+
yield JSON.parse(data);
|
|
2807
|
+
}
|
|
2808
|
+
}
|
|
2809
|
+
}
|
|
2810
|
+
} finally {
|
|
2811
|
+
reader.releaseLock();
|
|
2812
|
+
}
|
|
667
2813
|
}
|
|
668
2814
|
export {
|
|
669
2815
|
CommentHandler,
|
|
2816
|
+
callLlm,
|
|
670
2817
|
cleanMarkdown,
|
|
671
2818
|
createActionsPlugin,
|
|
672
2819
|
createPlugin,
|