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