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