gemi 0.4.17 → 0.4.18

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/dist/app/index.js CHANGED
@@ -1,1332 +1,17 @@
1
- import {createRequire} from "node:module";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getProtoOf = Object.getPrototypeOf;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __toESM = (mod, isNodeMode, target) => {
8
- target = mod != null ? __create(__getProtoOf(mod)) : {};
9
- const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
10
- for (let key of __getOwnPropNames(mod))
11
- if (!__hasOwnProp.call(to, key))
12
- __defProp(to, key, {
13
- get: () => mod[key],
14
- enumerable: true
15
- });
16
- return to;
17
- };
18
- var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
19
- var __require = createRequire(import.meta.url);
20
-
21
- // http/Controller.ts
22
- class Controller {
23
- requests = {};
24
- static kind = "controller";
25
- constructor() {
26
- }
27
- }
28
-
29
- class ResourceController extends Controller {
30
- constructor() {
31
- super(...arguments);
32
- }
33
- }
34
- // internal/isConstructor.ts
35
- function isConstructor(value) {
36
- return typeof value === "function" && value.prototype !== undefined;
37
- }
38
-
39
- // http/ApiRouter.ts
40
- var isController = function(candidate) {
41
- return isConstructor(candidate);
42
- };
43
-
44
- class RouteHandler {
45
- method;
46
- handler;
47
- methodName;
48
- middlewares = [];
49
- constructor(method, handler, methodName) {
50
- this.method = method;
51
- this.handler = handler;
52
- this.methodName = methodName;
53
- this.handler = handler;
54
- this.methodName = methodName;
55
- this.method = method;
56
- }
57
- run(req) {
58
- let httpRequest = req;
59
- if (isController(this.handler)) {
60
- const controller = new this.handler;
61
- const handler = controller[this.methodName].bind(controller);
62
- httpRequest = controller.requests[this.methodName] ? new controller.requests[this.methodName](req.rawRequest, req.params) : httpRequest;
63
- return handler(httpRequest);
64
- } else {
65
- return this.handler(req);
66
- }
67
- }
68
- middleware(middlewareList) {
69
- this.middlewares = middlewareList;
70
- return this;
71
- }
72
- }
73
-
74
- class ApiRouter {
75
- routes = {};
76
- middlewares = [];
77
- middleware(_req) {
78
- }
79
- get(handler, methodName) {
80
- return new RouteHandler("GET", handler, methodName);
81
- }
82
- post(handler, methodName) {
83
- return new RouteHandler("POST", handler, methodName);
84
- }
85
- put(handler, methodName) {
86
- return new RouteHandler("PUT", handler, methodName);
87
- }
88
- patch(handler, methodName) {
89
- return new RouteHandler("PATCH", handler, methodName);
90
- }
91
- delete(handler, methodName) {
92
- return new RouteHandler("DELETE", handler, methodName);
93
- }
94
- resource(Controller2) {
95
-
96
- class ResourceRouter extends ApiRouter {
97
- constructor() {
98
- super(...arguments);
99
- }
100
- routes = {
101
- "/": {
102
- list: this.get(Controller2, "list"),
103
- create: this.post(Controller2, "create")
104
- },
105
- "/:id": {
106
- show: this.get(Controller2, "show"),
107
- update: this.put(Controller2, "update"),
108
- delete: this.delete(Controller2, "delete")
109
- }
110
- };
111
- }
112
- return ResourceRouter;
113
- }
114
- }
115
- // http/ViewRouter.ts
116
- class ViewRouter {
117
- routes = {};
118
- middlewares = [];
119
- middleware(req) {
120
- }
121
- layout(viewPath, handler, children) {
122
- function prepare(middlewares = []) {
123
- let _children = children ?? {};
124
- if (handler && handler.constructor === Object) {
125
- _children = handler;
126
- }
127
- return {
128
- exec: async (req) => {
129
- let _handler = () => Promise.resolve({
130
- data: { [viewPath]: {} },
131
- headers: {},
132
- head: {}
133
- });
134
- if (typeof handler === "function") {
135
- _handler = handler;
136
- }
137
- if (Array.isArray(handler)) {
138
- const [controller, methodName] = handler;
139
- const instance = new controller(app);
140
- _handler = instance[methodName].bind(instance);
141
- }
142
- const data = await _handler(req);
143
- return { [viewPath]: data };
144
- },
145
- children: _children,
146
- viewPath,
147
- middlewares,
148
- kind: "layout"
149
- };
150
- }
151
- return {
152
- prepare,
153
- middleware: (middlewares) => ({
154
- prepare: () => prepare(middlewares)
155
- })
156
- };
157
- }
158
- view(viewPath, handler, children) {
159
- function prepare(middlewares = []) {
160
- let _children = children ?? {};
161
- if (handler && handler.constructor === Object) {
162
- _children = handler;
163
- }
164
- return {
165
- exec: async (req) => {
166
- let _handler = () => Promise.resolve({
167
- data: { [viewPath]: {} },
168
- headers: {},
169
- head: {}
170
- });
171
- if (typeof handler === "function") {
172
- _handler = handler;
173
- }
174
- if (Array.isArray(handler)) {
175
- const [controller, methodName] = handler;
176
- const instance = new controller(app);
177
- _handler = instance[methodName].bind(instance);
178
- }
179
- const data = await _handler(req);
180
- return { [viewPath]: data };
181
- },
182
- children: _children,
183
- viewPath,
184
- middlewares,
185
- kind: "view"
186
- };
187
- }
188
- return {
189
- prepare,
190
- middleware: (middlewares) => ({
191
- prepare: () => prepare(middlewares)
192
- })
193
- };
194
- }
195
- }
196
- // http/Error.ts
197
- var GEMI_REQUEST_BREAKER_ERROR = "GEMI_REQUEST_BREAKER_ERROR";
198
-
199
- class RequestBreakerError extends Error {
200
- constructor() {
201
- super(...arguments);
202
- }
203
- kind = GEMI_REQUEST_BREAKER_ERROR;
204
- payload = { api: {}, view: {} };
205
- }
206
-
207
- // http/Router.ts
208
- class AuthenticationError extends RequestBreakerError {
209
- constructor() {
210
- super("Authentication error");
211
- this.name = "AuthenticationError";
212
- }
213
- payload = {
214
- api: {
215
- status: 401,
216
- data: { error: "Authentication error" }
217
- },
218
- view: {
219
- status: 302,
220
- headers: {
221
- "Cache-Control": "private, no-cache, no-store, max-age=0, must-revalidate",
222
- Location: "/auth/sign-in"
223
- }
224
- }
225
- };
226
- }
227
-
228
- class ValidationError extends RequestBreakerError {
229
- errors = {};
230
- constructor(errors) {
231
- super("Validation error");
232
- this.name = "ValidationError";
233
- this.errors = errors;
234
- this.payload = {
235
- api: {
236
- status: 400,
237
- data: {
238
- error: {
239
- kind: "validation_error",
240
- messages: errors
241
- }
242
- },
243
- headers: {
244
- "Content-Type": "application/json"
245
- }
246
- },
247
- view: {
248
- status: 400
249
- }
250
- };
251
- }
252
- }
253
- // http/requestContext.ts
254
- import {AsyncLocalStorage} from "async_hooks";
255
-
256
- // http/Cookie.ts
257
- class Cookie {
258
- name;
259
- value;
260
- options;
261
- constructor(name, value, options = {}) {
262
- this.name = name;
263
- this.value = value;
264
- this.options = options;
265
- }
266
- toString() {
267
- return [
268
- `${this.name}=${this.value}`,
269
- this.options.maxAge ? `Max-Age=${this.options.maxAge}` : "",
270
- this.options.httpOnly ? "HttpOnly" : "",
271
- this.options.secure ? "Secure" : "",
272
- this.options.sameSite ? `SameSite=${this.options.sameSite}` : "SameSite=Strict",
273
- this.options.path ? `Path=${this.options.path}` : "Path=/",
274
- this.options.domain ? `Domain=${this.options.domain}` : "",
275
- this.options.expires ? `Expires=${this.options.expires.toUTCString()}` : "",
276
- this.options.partitioned ? "Partitioned" : ""
277
- ].filter((i) => i !== "").join("; ");
278
- }
279
- }
280
-
281
- // http/requestContext.ts
282
- var requestContext = new AsyncLocalStorage;
283
-
284
- class Store {
285
- cookies = new Set;
286
- user = null;
287
- req = null;
288
- constructor() {
289
- }
290
- setCookie(name, value, options = {}) {
291
- this.cookies.add(new Cookie(name, value, options));
292
- }
293
- setUser(user) {
294
- this.user = user;
295
- }
296
- setRequest(req) {
297
- this.req = req;
298
- }
299
- }
300
-
301
- class RequestContext {
302
- static getStore() {
303
- return requestContext.getStore();
304
- }
305
- static setRequest(req) {
306
- requestContext.getStore().req = req;
307
- }
308
- static async run(fn) {
309
- return requestContext.run(new Store, fn);
310
- }
311
- }
312
-
313
- // http/HttpRequest.ts
314
- var validate = function(ruleName) {
315
- const [rule, param] = ruleName.split(":");
316
- switch (rule) {
317
- case "required":
318
- return (value) => {
319
- return value !== null && value !== undefined && value?.length > 0;
320
- };
321
- case "password":
322
- return (value) => {
323
- const passwordRegex = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z0-9]).{8,}$/;
324
- return passwordRegex.test(value);
325
- };
326
- case "number":
327
- return (value) => {
328
- if (typeof value !== "number")
329
- return false;
330
- return !isNaN(value);
331
- };
332
- case "min":
333
- return (value) => {
334
- return value?.length >= parseInt(param);
335
- };
336
- case "max":
337
- return (value) => {
338
- return value?.length <= parseInt(param);
339
- };
340
- case "email":
341
- return (value) => {
342
- const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
343
- return emailRegex.test(value);
344
- };
345
- default:
346
- return () => true;
347
- }
348
- };
349
-
350
- class Input {
351
- data;
352
- constructor(data) {
353
- this.data = data;
354
- }
355
- get(key) {
356
- return this.data[key];
357
- }
358
- set(key, value) {
359
- this.data[key] = value;
360
- }
361
- has(key) {
362
- return this.data[key] !== undefined;
363
- }
364
- toJSON() {
365
- return this.data;
366
- }
367
- }
368
-
369
- class HttpRequest {
370
- rawRequest;
371
- headers;
372
- cookies;
373
- schema = {};
374
- params;
375
- ctx = RequestContext.getStore();
376
- constructor(req, params) {
377
- this.params = params;
378
- this.rawRequest = req;
379
- this.headers = req.headers;
380
- const cookie = this.rawRequest.headers.get("Cookie");
381
- const cookies = new Map;
382
- if (cookie) {
383
- const cookieArray = cookie.split(";");
384
- for (const c of cookieArray) {
385
- const [key, value] = c.split("=");
386
- cookies.set(key.trim(), value.trim());
387
- }
388
- }
389
- this.cookies = cookies;
390
- }
391
- async parseBody() {
392
- const inputMap = new Input({});
393
- if (this.rawRequest.headers.get("Content-Type") === "application/json") {
394
- const body = await this.rawRequest.json();
395
- for (const [key, value] of Object.entries(body)) {
396
- inputMap.set(key, value);
397
- }
398
- }
399
- if (this.rawRequest.headers.get("Content-Type") === "application/x-www-form-urlencoded") {
400
- const body = await this.rawRequest.formData();
401
- for (const [key, value] of body) {
402
- inputMap.set(key, value);
403
- }
404
- }
405
- if (this.rawRequest.headers.get("Content-Type").startsWith("multipart/form-data")) {
406
- const body = await this.rawRequest.formData();
407
- for (const [key, value] of body) {
408
- if (inputMap.has(key)) {
409
- const currentValue = inputMap.get(key);
410
- if (Array.isArray(currentValue)) {
411
- currentValue.push(value);
412
- inputMap.set(key, currentValue);
413
- } else {
414
- inputMap.set(key, [currentValue, value]);
415
- }
416
- } else {
417
- inputMap.set(key, value);
418
- }
419
- }
420
- }
421
- return inputMap;
422
- }
423
- validateInput(input) {
424
- const errors = {};
425
- for (const [key, rules] of Object.entries(this.schema)) {
426
- for (const [rule, message] of Object.entries(rules)) {
427
- const validator = validate(rule);
428
- if (!validator(input.get(key))) {
429
- if (!errors[key]) {
430
- errors[key] = [];
431
- }
432
- if (rule === "required") {
433
- errors[key] = [String(message)];
434
- break;
435
- } else {
436
- errors[key].push(String(message));
437
- }
438
- }
439
- }
440
- }
441
- if (Object.keys(errors).length > 0) {
442
- throw new ValidationError(errors);
443
- } else {
444
- return input;
445
- }
446
- }
447
- async input() {
448
- return this.validateInput(await this.parseBody());
449
- }
450
- async safeInput() {
451
- const input = await this.parseBody();
452
- try {
453
- this.validateInput(input);
454
- return {
455
- isValid: true,
456
- errors: {},
457
- input
458
- };
459
- } catch (err) {
460
- if (!(err instanceof ValidationError)) {
461
- throw err;
462
- }
463
- return {
464
- isValid: false,
465
- errors: err.errors,
466
- input
467
- };
468
- }
469
- }
470
- async terminate(params) {
471
- throw "not implemented";
472
- }
473
- }
474
- // http/Middleware.ts
475
- class Middleware {
476
- async run(_req) {
477
- return {};
478
- }
479
- }
480
- // http/getCookies.ts
481
- function getCookies(req) {
482
- const cookies = req.headers.get("cookie");
483
- if (!cookies) {
484
- return new Map;
485
- }
486
- const _cookies = new Map;
487
- const cookieStrings = cookies.split(";");
488
- for (const cookieString of cookieStrings) {
489
- const [name, value] = cookieString.split("=");
490
- _cookies.set(name.trim(), value);
491
- }
492
- return _cookies;
493
- }
494
- // http/MiddlewareServiceProvider.ts
495
- class MiddlewareServiceProvider {
496
- aliases = {};
497
- }
498
- // kernel/context.ts
499
- import {AsyncLocalStorage as AsyncLocalStorage2} from "async_hooks";
500
- var kernelContext = new AsyncLocalStorage2;
501
-
502
- // kernel/KernelContext.ts
503
- class KernelContext {
504
- static getStore = () => kernelContext.getStore();
505
- }
506
-
507
- // http/AuthenticationMiddlware.ts
508
- class AuthenticationMiddleware extends Middleware {
509
- constructor() {
510
- super(...arguments);
511
- }
512
- async run(req) {
513
- const requestContextStore = RequestContext.getStore();
514
- const accessToken = requestContextStore.req.cookies.get("access_token");
515
- if (!accessToken) {
516
- throw new AuthenticationError;
517
- }
518
- let user = requestContextStore.user;
519
- if (!user) {
520
- const session = await KernelContext.getStore().authenticationServiceProvider.adapter.findSession({
521
- token: accessToken,
522
- userAgent: requestContextStore.req.headers.get("User-Agent")
523
- });
524
- if (!session) {
525
- throw new AuthenticationError;
526
- }
527
- user = session?.user;
528
- requestContextStore.setUser(user);
529
- }
530
- return {};
531
- }
532
- }
533
- // ../../node_modules/urlpattern-polyfill/dist/urlpattern.js
534
- var Re = function(e, t) {
535
- return (t ? /^[\x00-\xFF]*$/ : /^[\x00-\x7F]*$/).test(e);
536
- };
537
- var v = function(e, t = false) {
538
- let r = [], n = 0;
539
- for (;n < e.length; ) {
540
- let o = e[n], c = function(l) {
541
- if (!t)
542
- throw new TypeError(l);
543
- r.push({ type: "INVALID_CHAR", index: n, value: e[n++] });
544
- };
545
- if (o === "*") {
546
- r.push({ type: "ASTERISK", index: n, value: e[n++] });
547
- continue;
548
- }
549
- if (o === "+" || o === "?") {
550
- r.push({ type: "OTHER_MODIFIER", index: n, value: e[n++] });
551
- continue;
552
- }
553
- if (o === "\\") {
554
- r.push({ type: "ESCAPED_CHAR", index: n++, value: e[n++] });
555
- continue;
556
- }
557
- if (o === "{") {
558
- r.push({ type: "OPEN", index: n, value: e[n++] });
559
- continue;
560
- }
561
- if (o === "}") {
562
- r.push({ type: "CLOSE", index: n, value: e[n++] });
563
- continue;
564
- }
565
- if (o === ":") {
566
- let l = "", s = n + 1;
567
- for (;s < e.length; ) {
568
- let i = e.substr(s, 1);
569
- if (s === n + 1 && be.test(i) || s !== n + 1 && Pe.test(i)) {
570
- l += e[s++];
571
- continue;
572
- }
573
- break;
574
- }
575
- if (!l) {
576
- c(`Missing parameter name at ${n}`);
577
- continue;
578
- }
579
- r.push({ type: "NAME", index: n, value: l }), n = s;
580
- continue;
581
- }
582
- if (o === "(") {
583
- let l = 1, s = "", i = n + 1, a = false;
584
- if (e[i] === "?") {
585
- c(`Pattern cannot start with "?" at ${i}`);
586
- continue;
587
- }
588
- for (;i < e.length; ) {
589
- if (!Re(e[i], false)) {
590
- c(`Invalid character '${e[i]}' at ${i}.`), a = true;
591
- break;
592
- }
593
- if (e[i] === "\\") {
594
- s += e[i++] + e[i++];
595
- continue;
596
- }
597
- if (e[i] === ")") {
598
- if (l--, l === 0) {
599
- i++;
600
- break;
601
- }
602
- } else if (e[i] === "(" && (l++, e[i + 1] !== "?")) {
603
- c(`Capturing groups are not allowed at ${i}`), a = true;
604
- break;
605
- }
606
- s += e[i++];
607
- }
608
- if (a)
609
- continue;
610
- if (l) {
611
- c(`Unbalanced pattern at ${n}`);
612
- continue;
613
- }
614
- if (!s) {
615
- c(`Missing pattern at ${n}`);
616
- continue;
617
- }
618
- r.push({ type: "REGEX", index: n, value: s }), n = i;
619
- continue;
620
- }
621
- r.push({ type: "CHAR", index: n, value: e[n++] });
622
- }
623
- return r.push({ type: "END", index: n, value: "" }), r;
624
- };
625
- var D = function(e, t = {}) {
626
- let r = v(e);
627
- t.delimiter ??= "/#?", t.prefixes ??= "./";
628
- let n = `[^${S(t.delimiter)}]+?`, o = [], c = 0, l = 0, s = "", i = new Set, a = (h) => {
629
- if (l < r.length && r[l].type === h)
630
- return r[l++].value;
631
- }, f = () => a("OTHER_MODIFIER") ?? a("ASTERISK"), d = (h) => {
632
- let u = a(h);
633
- if (u !== undefined)
634
- return u;
635
- let { type: p, index: A } = r[l];
636
- throw new TypeError(`Unexpected ${p} at ${A}, expected ${h}`);
637
- }, T = () => {
638
- let h = "", u;
639
- for (;u = a("CHAR") ?? a("ESCAPED_CHAR"); )
640
- h += u;
641
- return h;
642
- }, Se = (h) => h, L = t.encodePart || Se, I = "", U = (h) => {
643
- I += h;
644
- }, $ = () => {
645
- I.length && (o.push(new R(3, "", "", L(I), "", 3)), I = "");
646
- }, V = (h, u, p, A, Y) => {
647
- let g = 3;
648
- switch (Y) {
649
- case "?":
650
- g = 1;
651
- break;
652
- case "*":
653
- g = 0;
654
- break;
655
- case "+":
656
- g = 2;
657
- break;
658
- }
659
- if (!u && !p && g === 3) {
660
- U(h);
661
- return;
662
- }
663
- if ($(), !u && !p) {
664
- if (!h)
665
- return;
666
- o.push(new R(3, "", "", L(h), "", g));
667
- return;
668
- }
669
- let m;
670
- p ? p === "*" ? m = M : m = p : m = n;
671
- let O = 2;
672
- m === n ? (O = 1, m = "") : m === M && (O = 0, m = "");
673
- let P;
674
- if (u ? P = u : p && (P = c++), i.has(P))
675
- throw new TypeError(`Duplicate name '${P}'.`);
676
- i.add(P), o.push(new R(O, P, L(h), m, L(A), g));
677
- };
678
- for (;l < r.length; ) {
679
- let h = a("CHAR"), u = a("NAME"), p = a("REGEX");
680
- if (!u && !p && (p = a("ASTERISK")), u || p) {
681
- let g = h ?? "";
682
- t.prefixes.indexOf(g) === -1 && (U(g), g = ""), $();
683
- let m = f();
684
- V(g, u, p, "", m);
685
- continue;
686
- }
687
- let A = h ?? a("ESCAPED_CHAR");
688
- if (A) {
689
- U(A);
690
- continue;
691
- }
692
- if (a("OPEN")) {
693
- let g = T(), m = a("NAME"), O = a("REGEX");
694
- !m && !O && (O = a("ASTERISK"));
695
- let P = T();
696
- d("CLOSE");
697
- let xe = f();
698
- V(g, m, O, P, xe);
699
- continue;
700
- }
701
- $(), d("END");
702
- }
703
- return o;
704
- };
705
- var S = function(e) {
706
- return e.replace(/([.+*?^${}()[\]|/\\])/g, "\\$1");
707
- };
708
- var X = function(e) {
709
- return e && e.ignoreCase ? "ui" : "u";
710
- };
711
- var Z = function(e, t, r) {
712
- return F(D(e, r), t, r);
713
- };
714
- var k = function(e) {
715
- switch (e) {
716
- case 0:
717
- return "*";
718
- case 1:
719
- return "?";
720
- case 2:
721
- return "+";
722
- case 3:
723
- return "";
724
- }
725
- };
726
- var F = function(e, t, r = {}) {
727
- r.delimiter ??= "/#?", r.prefixes ??= "./", r.sensitive ??= false, r.strict ??= false, r.end ??= true, r.start ??= true, r.endsWith = "";
728
- let n = r.start ? "^" : "";
729
- for (let s of e) {
730
- if (s.type === 3) {
731
- s.modifier === 3 ? n += S(s.value) : n += `(?:${S(s.value)})${k(s.modifier)}`;
732
- continue;
733
- }
734
- t && t.push(s.name);
735
- let i = `[^${S(r.delimiter)}]+?`, a = s.value;
736
- if (s.type === 1 ? a = i : s.type === 0 && (a = M), !s.prefix.length && !s.suffix.length) {
737
- s.modifier === 3 || s.modifier === 1 ? n += `(${a})${k(s.modifier)}` : n += `((?:${a})${k(s.modifier)})`;
738
- continue;
739
- }
740
- if (s.modifier === 3 || s.modifier === 1) {
741
- n += `(?:${S(s.prefix)}(${a})${S(s.suffix)})`, n += k(s.modifier);
742
- continue;
743
- }
744
- n += `(?:${S(s.prefix)}`, n += `((?:${a})(?:`, n += S(s.suffix), n += S(s.prefix), n += `(?:${a}))*)${S(s.suffix)})`, s.modifier === 0 && (n += "?");
745
- }
746
- let o = `[${S(r.endsWith)}]|\$`, c = `[${S(r.delimiter)}]`;
747
- if (r.end)
748
- return r.strict || (n += `${c}?`), r.endsWith.length ? n += `(?=${o})` : n += "$", new RegExp(n, X(r));
749
- r.strict || (n += `(?:${c}(?=${o}))?`);
750
- let l = false;
751
- if (e.length) {
752
- let s = e[e.length - 1];
753
- s.type === 3 && s.modifier === 3 && (l = r.delimiter.indexOf(s) > -1);
754
- }
755
- return l || (n += `(?=${c}|${o})`), new RegExp(n, X(r));
756
- };
757
- var J = function(e, t) {
758
- return e.length ? e[0] === "/" ? true : !t || e.length < 2 ? false : (e[0] == "\\" || e[0] == "{") && e[1] == "/" : false;
759
- };
760
- var Q = function(e, t) {
761
- return e.startsWith(t) ? e.substring(t.length, e.length) : e;
762
- };
763
- var Ee = function(e, t) {
764
- return e.endsWith(t) ? e.substr(0, e.length - t.length) : e;
765
- };
766
- var W = function(e) {
767
- return !e || e.length < 2 ? false : e[0] === "[" || (e[0] === "\\" || e[0] === "{") && e[1] === "[";
768
- };
769
- var N = function(e) {
770
- if (!e)
771
- return true;
772
- for (let t of ee)
773
- if (e.test(t))
774
- return true;
775
- return false;
776
- };
777
- var te = function(e, t) {
778
- if (e = Q(e, "#"), t || e === "")
779
- return e;
780
- let r = new URL("https://example.com");
781
- return r.hash = e, r.hash ? r.hash.substring(1, r.hash.length) : "";
782
- };
783
- var re = function(e, t) {
784
- if (e = Q(e, "?"), t || e === "")
785
- return e;
786
- let r = new URL("https://example.com");
787
- return r.search = e, r.search ? r.search.substring(1, r.search.length) : "";
788
- };
789
- var ne = function(e, t) {
790
- return t || e === "" ? e : W(e) ? j(e) : z(e);
791
- };
792
- var se = function(e, t) {
793
- if (t || e === "")
794
- return e;
795
- let r = new URL("https://example.com");
796
- return r.password = e, r.password;
797
- };
798
- var ie = function(e, t) {
799
- if (t || e === "")
800
- return e;
801
- let r = new URL("https://example.com");
802
- return r.username = e, r.username;
803
- };
804
- var ae = function(e, t, r) {
805
- if (r || e === "")
806
- return e;
807
- if (t && !ee.includes(t))
808
- return new URL(`${t}:${e}`).pathname;
809
- let n = e[0] == "/";
810
- return e = new URL(n ? e : "/-" + e, "https://example.com").pathname, n || (e = e.substring(2, e.length)), e;
811
- };
812
- var oe = function(e, t, r) {
813
- return _(t) === e && (e = ""), r || e === "" ? e : K(e);
814
- };
815
- var ce = function(e, t) {
816
- return e = Ee(e, ":"), t || e === "" ? e : y(e);
817
- };
818
- var _ = function(e) {
819
- switch (e) {
820
- case "ws":
821
- case "http":
822
- return "80";
823
- case "wws":
824
- case "https":
825
- return "443";
826
- case "ftp":
827
- return "21";
828
- default:
829
- return "";
830
- }
831
- };
832
- var y = function(e) {
833
- if (e === "")
834
- return e;
835
- if (/^[-+.A-Za-z0-9]*$/.test(e))
836
- return e.toLowerCase();
837
- throw new TypeError(`Invalid protocol '${e}'.`);
838
- };
839
- var le = function(e) {
840
- if (e === "")
841
- return e;
842
- let t = new URL("https://example.com");
843
- return t.username = e, t.username;
844
- };
845
- var fe = function(e) {
846
- if (e === "")
847
- return e;
848
- let t = new URL("https://example.com");
849
- return t.password = e, t.password;
850
- };
851
- var z = function(e) {
852
- if (e === "")
853
- return e;
854
- if (/[\t\n\r #%/:<>?@[\]^\\|]/g.test(e))
855
- throw new TypeError(`Invalid hostname '${e}'`);
856
- let t = new URL("https://example.com");
857
- return t.hostname = e, t.hostname;
858
- };
859
- var j = function(e) {
860
- if (e === "")
861
- return e;
862
- if (/[^0-9a-fA-F[\]:]/g.test(e))
863
- throw new TypeError(`Invalid IPv6 hostname '${e}'`);
864
- return e.toLowerCase();
865
- };
866
- var K = function(e) {
867
- if (e === "" || /^[0-9]*$/.test(e) && parseInt(e) <= 65535)
868
- return e;
869
- throw new TypeError(`Invalid port '${e}'.`);
870
- };
871
- var he = function(e) {
872
- if (e === "")
873
- return e;
874
- let t = new URL("https://example.com");
875
- return t.pathname = e[0] !== "/" ? "/-" + e : e, e[0] !== "/" ? t.pathname.substring(2, t.pathname.length) : t.pathname;
876
- };
877
- var ue = function(e) {
878
- return e === "" ? e : new URL(`data:${e}`).pathname;
879
- };
880
- var de = function(e) {
881
- if (e === "")
882
- return e;
883
- let t = new URL("https://example.com");
884
- return t.search = e, t.search.substring(1, t.search.length);
885
- };
886
- var pe = function(e) {
887
- if (e === "")
888
- return e;
889
- let t = new URL("https://example.com");
890
- return t.hash = e, t.hash.substring(1, t.hash.length);
891
- };
892
- var ge = function(e, t) {
893
- if (typeof e != "string")
894
- throw new TypeError("parameter 1 is not of type 'string'.");
895
- let r = new URL(e, t);
896
- return { protocol: r.protocol.substring(0, r.protocol.length - 1), username: r.username, password: r.password, hostname: r.hostname, port: r.port, pathname: r.pathname, search: r.search !== "" ? r.search.substring(1, r.search.length) : undefined, hash: r.hash !== "" ? r.hash.substring(1, r.hash.length) : undefined };
897
- };
898
- var b = function(e, t) {
899
- return t ? C(e) : e;
900
- };
901
- var w = function(e, t, r) {
902
- let n;
903
- if (typeof t.baseURL == "string")
904
- try {
905
- n = new URL(t.baseURL), t.protocol === undefined && (e.protocol = b(n.protocol.substring(0, n.protocol.length - 1), r)), !r && t.protocol === undefined && t.hostname === undefined && t.port === undefined && t.username === undefined && (e.username = b(n.username, r)), !r && t.protocol === undefined && t.hostname === undefined && t.port === undefined && t.username === undefined && t.password === undefined && (e.password = b(n.password, r)), t.protocol === undefined && t.hostname === undefined && (e.hostname = b(n.hostname, r)), t.protocol === undefined && t.hostname === undefined && t.port === undefined && (e.port = b(n.port, r)), t.protocol === undefined && t.hostname === undefined && t.port === undefined && t.pathname === undefined && (e.pathname = b(n.pathname, r)), t.protocol === undefined && t.hostname === undefined && t.port === undefined && t.pathname === undefined && t.search === undefined && (e.search = b(n.search.substring(1, n.search.length), r)), t.protocol === undefined && t.hostname === undefined && t.port === undefined && t.pathname === undefined && t.search === undefined && t.hash === undefined && (e.hash = b(n.hash.substring(1, n.hash.length), r));
906
- } catch {
907
- throw new TypeError(`invalid baseURL '${t.baseURL}'.`);
908
- }
909
- if (typeof t.protocol == "string" && (e.protocol = ce(t.protocol, r)), typeof t.username == "string" && (e.username = ie(t.username, r)), typeof t.password == "string" && (e.password = se(t.password, r)), typeof t.hostname == "string" && (e.hostname = ne(t.hostname, r)), typeof t.port == "string" && (e.port = oe(t.port, e.protocol, r)), typeof t.pathname == "string") {
910
- if (e.pathname = t.pathname, n && !J(e.pathname, r)) {
911
- let o = n.pathname.lastIndexOf("/");
912
- o >= 0 && (e.pathname = b(n.pathname.substring(0, o + 1), r) + e.pathname);
913
- }
914
- e.pathname = ae(e.pathname, e.protocol, r);
915
- }
916
- return typeof t.search == "string" && (e.search = re(t.search, r)), typeof t.hash == "string" && (e.hash = te(t.hash, r)), e;
917
- };
918
- var C = function(e) {
919
- return e.replace(/([+*?:{}()\\])/g, "\\$1");
920
- };
921
- var Oe = function(e) {
922
- return e.replace(/([.+*?^${}()[\]|/\\])/g, "\\$1");
923
- };
924
- var ke = function(e, t) {
925
- t.delimiter ??= "/#?", t.prefixes ??= "./", t.sensitive ??= false, t.strict ??= false, t.end ??= true, t.start ??= true, t.endsWith = "";
926
- let r = ".*", n = `[^${Oe(t.delimiter)}]+?`, o = /[$_\u200C\u200D\p{ID_Continue}]/u, c = "";
927
- for (let l = 0;l < e.length; ++l) {
928
- let s = e[l];
929
- if (s.type === 3) {
930
- if (s.modifier === 3) {
931
- c += C(s.value);
932
- continue;
933
- }
934
- c += `{${C(s.value)}}${k(s.modifier)}`;
935
- continue;
936
- }
937
- let i = s.hasCustomName(), a = !!s.suffix.length || !!s.prefix.length && (s.prefix.length !== 1 || !t.prefixes.includes(s.prefix)), f = l > 0 ? e[l - 1] : null, d = l < e.length - 1 ? e[l + 1] : null;
938
- if (!a && i && s.type === 1 && s.modifier === 3 && d && !d.prefix.length && !d.suffix.length)
939
- if (d.type === 3) {
940
- let T = d.value.length > 0 ? d.value[0] : "";
941
- a = o.test(T);
942
- } else
943
- a = !d.hasCustomName();
944
- if (!a && !s.prefix.length && f && f.type === 3) {
945
- let T = f.value[f.value.length - 1];
946
- a = t.prefixes.includes(T);
947
- }
948
- a && (c += "{"), c += C(s.prefix), i && (c += `:${s.name}`), s.type === 2 ? c += `(${s.value})` : s.type === 1 ? i || (c += `(${n})`) : s.type === 0 && (!i && (!f || f.type === 3 || f.modifier !== 3 || a || s.prefix !== "") ? c += "*" : c += `(${r})`), s.type === 1 && i && s.suffix.length && o.test(s.suffix[0]) && (c += "\\"), c += C(s.suffix), a && (c += "}"), s.modifier !== 3 && (c += k(s.modifier));
949
- }
950
- return c;
951
- };
952
- var R = class {
953
- type = 3;
954
- name = "";
955
- prefix = "";
956
- value = "";
957
- suffix = "";
958
- modifier = 3;
959
- constructor(t, r, n, o, c, l) {
960
- this.type = t, this.name = r, this.prefix = n, this.value = o, this.suffix = c, this.modifier = l;
961
- }
962
- hasCustomName() {
963
- return this.name !== "" && typeof this.name != "number";
964
- }
965
- };
966
- var be = /[$_\p{ID_Start}]/u;
967
- var Pe = /[$_\u200C\u200D\p{ID_Continue}]/u;
968
- var M = ".*";
969
- var x = { delimiter: "", prefixes: "", sensitive: true, strict: true };
970
- var B = { delimiter: ".", prefixes: "", sensitive: true, strict: true };
971
- var q = { delimiter: "/", prefixes: "/", sensitive: true, strict: true };
972
- var ee = ["ftp", "file", "http", "https", "ws", "wss"];
973
- var H = class {
974
- #i;
975
- #n = [];
976
- #t = {};
977
- #e = 0;
978
- #s = 1;
979
- #l = 0;
980
- #o = 0;
981
- #d = 0;
982
- #p = 0;
983
- #g = false;
984
- constructor(t) {
985
- this.#i = t;
986
- }
987
- get result() {
988
- return this.#t;
989
- }
990
- parse() {
991
- for (this.#n = v(this.#i, true);this.#e < this.#n.length; this.#e += this.#s) {
992
- if (this.#s = 1, this.#n[this.#e].type === "END") {
993
- if (this.#o === 0) {
994
- this.#b(), this.#f() ? this.#r(9, 1) : this.#h() ? this.#r(8, 1) : this.#r(7, 0);
995
- continue;
996
- } else if (this.#o === 2) {
997
- this.#u(5);
998
- continue;
999
- }
1000
- this.#r(10, 0);
1001
- break;
1002
- }
1003
- if (this.#d > 0)
1004
- if (this.#A())
1005
- this.#d -= 1;
1006
- else
1007
- continue;
1008
- if (this.#T()) {
1009
- this.#d += 1;
1010
- continue;
1011
- }
1012
- switch (this.#o) {
1013
- case 0:
1014
- this.#P() && this.#u(1);
1015
- break;
1016
- case 1:
1017
- if (this.#P()) {
1018
- this.#C();
1019
- let t = 7, r = 1;
1020
- this.#E() ? (t = 2, r = 3) : this.#g && (t = 2), this.#r(t, r);
1021
- }
1022
- break;
1023
- case 2:
1024
- this.#S() ? this.#u(3) : (this.#x() || this.#h() || this.#f()) && this.#u(5);
1025
- break;
1026
- case 3:
1027
- this.#O() ? this.#r(4, 1) : this.#S() && this.#r(5, 1);
1028
- break;
1029
- case 4:
1030
- this.#S() && this.#r(5, 1);
1031
- break;
1032
- case 5:
1033
- this.#y() ? this.#p += 1 : this.#w() && (this.#p -= 1), this.#k() && !this.#p ? this.#r(6, 1) : this.#x() ? this.#r(7, 0) : this.#h() ? this.#r(8, 1) : this.#f() && this.#r(9, 1);
1034
- break;
1035
- case 6:
1036
- this.#x() ? this.#r(7, 0) : this.#h() ? this.#r(8, 1) : this.#f() && this.#r(9, 1);
1037
- break;
1038
- case 7:
1039
- this.#h() ? this.#r(8, 1) : this.#f() && this.#r(9, 1);
1040
- break;
1041
- case 8:
1042
- this.#f() && this.#r(9, 1);
1043
- break;
1044
- case 9:
1045
- break;
1046
- case 10:
1047
- break;
1048
- }
1049
- }
1050
- this.#t.hostname !== undefined && this.#t.port === undefined && (this.#t.port = "");
1051
- }
1052
- #r(t, r) {
1053
- switch (this.#o) {
1054
- case 0:
1055
- break;
1056
- case 1:
1057
- this.#t.protocol = this.#c();
1058
- break;
1059
- case 2:
1060
- break;
1061
- case 3:
1062
- this.#t.username = this.#c();
1063
- break;
1064
- case 4:
1065
- this.#t.password = this.#c();
1066
- break;
1067
- case 5:
1068
- this.#t.hostname = this.#c();
1069
- break;
1070
- case 6:
1071
- this.#t.port = this.#c();
1072
- break;
1073
- case 7:
1074
- this.#t.pathname = this.#c();
1075
- break;
1076
- case 8:
1077
- this.#t.search = this.#c();
1078
- break;
1079
- case 9:
1080
- this.#t.hash = this.#c();
1081
- break;
1082
- case 10:
1083
- break;
1084
- }
1085
- this.#o !== 0 && t !== 10 && ([1, 2, 3, 4].includes(this.#o) && [6, 7, 8, 9].includes(t) && (this.#t.hostname ??= ""), [1, 2, 3, 4, 5, 6].includes(this.#o) && [8, 9].includes(t) && (this.#t.pathname ??= this.#g ? "/" : ""), [1, 2, 3, 4, 5, 6, 7].includes(this.#o) && t === 9 && (this.#t.search ??= "")), this.#R(t, r);
1086
- }
1087
- #R(t, r) {
1088
- this.#o = t, this.#l = this.#e + r, this.#e += r, this.#s = 0;
1089
- }
1090
- #b() {
1091
- this.#e = this.#l, this.#s = 0;
1092
- }
1093
- #u(t) {
1094
- this.#b(), this.#o = t;
1095
- }
1096
- #m(t) {
1097
- return t < 0 && (t = this.#n.length - t), t < this.#n.length ? this.#n[t] : this.#n[this.#n.length - 1];
1098
- }
1099
- #a(t, r) {
1100
- let n = this.#m(t);
1101
- return n.value === r && (n.type === "CHAR" || n.type === "ESCAPED_CHAR" || n.type === "INVALID_CHAR");
1102
- }
1103
- #P() {
1104
- return this.#a(this.#e, ":");
1105
- }
1106
- #E() {
1107
- return this.#a(this.#e + 1, "/") && this.#a(this.#e + 2, "/");
1108
- }
1109
- #S() {
1110
- return this.#a(this.#e, "@");
1111
- }
1112
- #O() {
1113
- return this.#a(this.#e, ":");
1114
- }
1115
- #k() {
1116
- return this.#a(this.#e, ":");
1117
- }
1118
- #x() {
1119
- return this.#a(this.#e, "/");
1120
- }
1121
- #h() {
1122
- if (this.#a(this.#e, "?"))
1123
- return true;
1124
- if (this.#n[this.#e].value !== "?")
1125
- return false;
1126
- let t = this.#m(this.#e - 1);
1127
- return t.type !== "NAME" && t.type !== "REGEX" && t.type !== "CLOSE" && t.type !== "ASTERISK";
1128
- }
1129
- #f() {
1130
- return this.#a(this.#e, "#");
1131
- }
1132
- #T() {
1133
- return this.#n[this.#e].type == "OPEN";
1134
- }
1135
- #A() {
1136
- return this.#n[this.#e].type == "CLOSE";
1137
- }
1138
- #y() {
1139
- return this.#a(this.#e, "[");
1140
- }
1141
- #w() {
1142
- return this.#a(this.#e, "]");
1143
- }
1144
- #c() {
1145
- let t = this.#n[this.#e], r = this.#m(this.#l).index;
1146
- return this.#i.substring(r, t.index);
1147
- }
1148
- #C() {
1149
- let t = {};
1150
- Object.assign(t, x), t.encodePart = y;
1151
- let r = Z(this.#c(), undefined, t);
1152
- this.#g = N(r);
1153
- }
1154
- };
1155
- var G = ["protocol", "username", "password", "hostname", "port", "pathname", "search", "hash"];
1156
- var E = "*";
1157
- var me = class {
1158
- #i;
1159
- #n = {};
1160
- #t = {};
1161
- #e = {};
1162
- #s = {};
1163
- #l = false;
1164
- constructor(t = {}, r, n) {
1165
- try {
1166
- let o;
1167
- if (typeof r == "string" ? o = r : n = r, typeof t == "string") {
1168
- let i = new H(t);
1169
- if (i.parse(), t = i.result, o === undefined && typeof t.protocol != "string")
1170
- throw new TypeError("A base URL must be provided for a relative constructor string.");
1171
- t.baseURL = o;
1172
- } else {
1173
- if (!t || typeof t != "object")
1174
- throw new TypeError("parameter 1 is not of type 'string' and cannot convert to dictionary.");
1175
- if (o)
1176
- throw new TypeError("parameter 1 is not of type 'string'.");
1177
- }
1178
- typeof n > "u" && (n = { ignoreCase: false });
1179
- let c = { ignoreCase: n.ignoreCase === true }, l = { pathname: E, protocol: E, username: E, password: E, hostname: E, port: E, search: E, hash: E };
1180
- this.#i = w(l, t, true), _(this.#i.protocol) === this.#i.port && (this.#i.port = "");
1181
- let s;
1182
- for (s of G) {
1183
- if (!(s in this.#i))
1184
- continue;
1185
- let i = {}, a = this.#i[s];
1186
- switch (this.#t[s] = [], s) {
1187
- case "protocol":
1188
- Object.assign(i, x), i.encodePart = y;
1189
- break;
1190
- case "username":
1191
- Object.assign(i, x), i.encodePart = le;
1192
- break;
1193
- case "password":
1194
- Object.assign(i, x), i.encodePart = fe;
1195
- break;
1196
- case "hostname":
1197
- Object.assign(i, B), W(a) ? i.encodePart = j : i.encodePart = z;
1198
- break;
1199
- case "port":
1200
- Object.assign(i, x), i.encodePart = K;
1201
- break;
1202
- case "pathname":
1203
- N(this.#n.protocol) ? (Object.assign(i, q, c), i.encodePart = he) : (Object.assign(i, x, c), i.encodePart = ue);
1204
- break;
1205
- case "search":
1206
- Object.assign(i, x, c), i.encodePart = de;
1207
- break;
1208
- case "hash":
1209
- Object.assign(i, x, c), i.encodePart = pe;
1210
- break;
1211
- }
1212
- try {
1213
- this.#s[s] = D(a, i), this.#n[s] = F(this.#s[s], this.#t[s], i), this.#e[s] = ke(this.#s[s], i), this.#l = this.#l || this.#s[s].some((f) => f.type === 2);
1214
- } catch {
1215
- throw new TypeError(`invalid ${s} pattern '${this.#i[s]}'.`);
1216
- }
1217
- }
1218
- } catch (o) {
1219
- throw new TypeError(`Failed to construct 'URLPattern': ${o.message}`);
1220
- }
1221
- }
1222
- test(t = {}, r) {
1223
- let n = { pathname: "", protocol: "", username: "", password: "", hostname: "", port: "", search: "", hash: "" };
1224
- if (typeof t != "string" && r)
1225
- throw new TypeError("parameter 1 is not of type 'string'.");
1226
- if (typeof t > "u")
1227
- return false;
1228
- try {
1229
- typeof t == "object" ? n = w(n, t, false) : n = w(n, ge(t, r), false);
1230
- } catch {
1231
- return false;
1232
- }
1233
- let o;
1234
- for (o of G)
1235
- if (!this.#n[o].exec(n[o]))
1236
- return false;
1237
- return true;
1238
- }
1239
- exec(t = {}, r) {
1240
- let n = { pathname: "", protocol: "", username: "", password: "", hostname: "", port: "", search: "", hash: "" };
1241
- if (typeof t != "string" && r)
1242
- throw new TypeError("parameter 1 is not of type 'string'.");
1243
- if (typeof t > "u")
1244
- return;
1245
- try {
1246
- typeof t == "object" ? n = w(n, t, false) : n = w(n, ge(t, r), false);
1247
- } catch {
1248
- return null;
1249
- }
1250
- let o = {};
1251
- r ? o.inputs = [t, r] : o.inputs = [t];
1252
- let c;
1253
- for (c of G) {
1254
- let l = this.#n[c].exec(n[c]);
1255
- if (!l)
1256
- return null;
1257
- let s = {};
1258
- for (let [i, a] of this.#t[c].entries())
1259
- if (typeof a == "string" || typeof a == "number") {
1260
- let f = l[i + 1];
1261
- s[a] = f;
1262
- }
1263
- o[c] = { input: n[c] ?? "", groups: s };
1264
- }
1265
- return o;
1266
- }
1267
- static compareComponent(t, r, n) {
1268
- let o = (i, a) => {
1269
- for (let f of ["type", "modifier", "prefix", "value", "suffix"]) {
1270
- if (i[f] < a[f])
1271
- return -1;
1272
- if (i[f] === a[f])
1273
- continue;
1274
- return 1;
1275
- }
1276
- return 0;
1277
- }, c = new R(3, "", "", "", "", 3), l = new R(0, "", "", "", "", 3), s = (i, a) => {
1278
- let f = 0;
1279
- for (;f < Math.min(i.length, a.length); ++f) {
1280
- let d = o(i[f], a[f]);
1281
- if (d)
1282
- return d;
1283
- }
1284
- return i.length === a.length ? 0 : o(i[f] ?? c, a[f] ?? c);
1285
- };
1286
- return !r.#e[t] && !n.#e[t] ? 0 : r.#e[t] && !n.#e[t] ? s(r.#s[t], [l]) : !r.#e[t] && n.#e[t] ? s([l], n.#s[t]) : s(r.#s[t], n.#s[t]);
1287
- }
1288
- get protocol() {
1289
- return this.#e.protocol;
1290
- }
1291
- get username() {
1292
- return this.#e.username;
1293
- }
1294
- get password() {
1295
- return this.#e.password;
1296
- }
1297
- get hostname() {
1298
- return this.#e.hostname;
1299
- }
1300
- get port() {
1301
- return this.#e.port;
1302
- }
1303
- get pathname() {
1304
- return this.#e.pathname;
1305
- }
1306
- get search() {
1307
- return this.#e.search;
1308
- }
1309
- get hash() {
1310
- return this.#e.hash;
1311
- }
1312
- get hasRegExpGroups() {
1313
- return this.#l;
1314
- }
1315
- };
1316
-
1317
- // ../../node_modules/urlpattern-polyfill/index.js
1318
- if (!globalThis.URLPattern) {
1319
- globalThis.URLPattern = me;
1320
- }
1321
-
1322
- // server/generateEtag.ts
1323
- function generateETag(lastModified) {
1324
- const lastModifiedStr = lastModified.toString();
1325
- const hasher = new Bun.CryptoHasher("sha1");
1326
- hasher.update(lastModifiedStr);
1327
- const hash = hasher.digest("hex");
1328
- return hash;
1329
- }
1
+ // @bun
2
+ import {
3
+ HttpRequest,
4
+ isConstructor
5
+ } from "../http/index.js";
6
+ import {
7
+ generateETag,
8
+ me
9
+ } from "../chunk-21e105fb2b3d36d7.js";
10
+ import {
11
+ GEMI_REQUEST_BREAKER_ERROR,
12
+ RequestContext
13
+ } from "../chunk-fa40971555060604.js";
14
+ import"../chunk-970e033f764e29fc.js";
1330
15
 
1331
16
  // client/helpers/flattenComponentTree.ts
1332
17
  function flattenComponentTree(componentTree) {
@@ -1340,7 +25,7 @@ function flattenComponentTree(componentTree) {
1340
25
  // app/createComponentTree.ts
1341
26
  function createComponentTree(routes) {
1342
27
  const componentTree = [];
1343
- for (const [_2, routeHandler] of Object.entries(routes)) {
28
+ for (const [_, routeHandler] of Object.entries(routes)) {
1344
29
  if ("prepare" in routeHandler) {
1345
30
  const { viewPath, children } = routeHandler.prepare();
1346
31
  if (Object.entries(children).length > 0) {
@@ -1568,9 +253,9 @@ class App {
1568
253
  if (typeof aliasOrTest === "string") {
1569
254
  const alias = aliasOrTest;
1570
255
  const kernelServices = this.kernel.getServices.call(this.kernel);
1571
- const Middleware3 = kernelServices.middlewareServiceProvider.aliases[alias];
1572
- if (Middleware3) {
1573
- const middleware2 = new Middleware3;
256
+ const Middleware = kernelServices.middlewareServiceProvider.aliases[alias];
257
+ if (Middleware) {
258
+ const middleware2 = new Middleware;
1574
259
  return middleware2.run;
1575
260
  }
1576
261
  } else {