@adonisjs/http-server 8.0.0-next.11 → 8.0.0-next.13

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.
@@ -0,0 +1,660 @@
1
+ import { t as createURL } from "./helpers-C_2HouOe.js";
2
+ import "node:module";
3
+ import { InvalidArgumentsException, RuntimeException } from "@poppinss/utils/exception";
4
+ import { debuglog } from "node:util";
5
+ import { serialize } from "cookie-es";
6
+ import matchit from "@poppinss/matchit";
7
+ import string from "@poppinss/utils/string";
8
+ import { moduleCaller, moduleImporter, parseBindingReference } from "@adonisjs/fold";
9
+ import Cache from "tmp-cache";
10
+ import Macroable from "@poppinss/macroable";
11
+ import is from "@sindresorhus/is";
12
+ import Middleware from "@poppinss/middleware";
13
+ import diagnostics_channel from "node:diagnostics_channel";
14
+ import StringBuilder from "@poppinss/utils/string_builder";
15
+ import encodeUrl from "encodeurl";
16
+ import mime from "mime-types";
17
+ var __defProp = Object.defineProperty;
18
+ var __export = (all, symbols) => {
19
+ let target = {};
20
+ for (var name in all) __defProp(target, name, {
21
+ get: all[name],
22
+ enumerable: true
23
+ });
24
+ if (symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
25
+ return target;
26
+ };
27
+ var debug_default = debuglog("adonisjs:http");
28
+ function canWriteResponseBody(value, ctx) {
29
+ return value !== void 0 && !ctx.response.hasLazyBody && value !== ctx.response;
30
+ }
31
+ function useReturnValue(ctx) {
32
+ return function(value) {
33
+ if (canWriteResponseBody(value, ctx)) ctx.response.send(value);
34
+ };
35
+ }
36
+ var tracing_channels_exports = /* @__PURE__ */ __export({
37
+ httpExceptionHandler: () => httpExceptionHandler,
38
+ httpMiddleware: () => httpMiddleware,
39
+ httpRequest: () => httpRequest,
40
+ httpResponseSerializer: () => httpResponseSerializer,
41
+ httpRouteHandler: () => httpRouteHandler
42
+ });
43
+ const httpRequest = diagnostics_channel.tracingChannel("adonisjs.http.request");
44
+ const httpMiddleware = diagnostics_channel.tracingChannel("adonisjs.http.middleware");
45
+ const httpExceptionHandler = diagnostics_channel.tracingChannel("adonisjs.http.exception.handler");
46
+ const httpRouteHandler = diagnostics_channel.tracingChannel("adonisjs.http.route.handler");
47
+ const httpResponseSerializer = diagnostics_channel.tracingChannel("adonisjs.http.response.serializer");
48
+ function execute(route, resolver, ctx, errorResponder) {
49
+ return route.middleware.runner().errorHandler((error) => errorResponder(error, ctx)).finalHandler(() => {
50
+ if (typeof route.handler === "function") return httpRouteHandler.tracePromise(($ctx) => Promise.resolve(route.handler($ctx)), httpRouteHandler.hasSubscribers ? { route } : void 0, void 0, ctx).then(useReturnValue(ctx));
51
+ return httpRouteHandler.tracePromise(route.handler.handle, httpRouteHandler.hasSubscribers ? { route } : void 0, void 0, resolver, ctx).then(useReturnValue(ctx));
52
+ }).run(async (middleware, next) => {
53
+ if (typeof middleware === "function") return httpMiddleware.tracePromise(middleware, httpMiddleware.hasSubscribers ? { middleware } : void 0, void 0, ctx, next);
54
+ return httpMiddleware.tracePromise(middleware.handle, httpMiddleware.hasSubscribers ? { middleware } : void 0, void 0, resolver, ctx, next, middleware.args);
55
+ });
56
+ }
57
+ var Route = class extends Macroable {
58
+ #pattern;
59
+ #methods;
60
+ #name;
61
+ #isDeleted = false;
62
+ #handler;
63
+ #globalMatchers;
64
+ #app;
65
+ #routerMiddleware;
66
+ #routeDomain = "root";
67
+ #matchers = {};
68
+ #prefixes = [];
69
+ #middleware = [];
70
+ constructor(app, routerMiddleware, options) {
71
+ super();
72
+ this.#app = app;
73
+ this.#routerMiddleware = routerMiddleware;
74
+ this.#pattern = options.pattern;
75
+ this.#methods = options.methods;
76
+ this.#globalMatchers = options.globalMatchers;
77
+ const { handler, routeName } = this.#resolveRouteHandle(options.handler);
78
+ this.#handler = handler;
79
+ this.#name = routeName;
80
+ }
81
+ #resolveRouteHandle(handler) {
82
+ if (typeof handler === "string") {
83
+ const parts = handler.split(".");
84
+ const method = parts.length === 1 ? "handle" : parts.pop();
85
+ const moduleRefId = parts.join(".");
86
+ return {
87
+ handler: {
88
+ method,
89
+ reference: handler,
90
+ importExpression: moduleRefId,
91
+ ...moduleImporter(() => this.#app.import(moduleRefId), method).toHandleMethod(),
92
+ name: handler
93
+ },
94
+ routeName: `${new StringBuilder(moduleRefId.split("/").pop()).removeSuffix("controller").snakeCase()}.${string.snakeCase(method)}`
95
+ };
96
+ }
97
+ if (Array.isArray(handler)) {
98
+ const controller = handler[0];
99
+ const method = handler[1] ?? "handle";
100
+ if (is.class(controller)) return {
101
+ handler: {
102
+ method,
103
+ reference: handler,
104
+ importExpression: null,
105
+ ...moduleCaller(controller, method).toHandleMethod()
106
+ },
107
+ routeName: `${new StringBuilder(controller.name).removeSuffix("controller").snakeCase()}.${string.snakeCase(method)}`
108
+ };
109
+ return {
110
+ handler: {
111
+ method,
112
+ reference: handler,
113
+ importExpression: String(controller),
114
+ ...moduleImporter(controller, method).toHandleMethod()
115
+ },
116
+ routeName: controller.name ? `${new StringBuilder(controller.name).removeSuffix("controller").snakeCase()}.${string.snakeCase(method)}` : void 0
117
+ };
118
+ }
119
+ return { handler };
120
+ }
121
+ #getMatchers() {
122
+ return {
123
+ ...this.#globalMatchers,
124
+ ...this.#matchers
125
+ };
126
+ }
127
+ #computePattern() {
128
+ const pattern = dropSlash(this.#pattern);
129
+ const prefix = this.#prefixes.slice().reverse().map((one) => dropSlash(one)).join("");
130
+ return prefix ? `${prefix}${pattern === "/" ? "" : pattern}` : pattern;
131
+ }
132
+ where(param, matcher) {
133
+ if (this.#matchers[param]) return this;
134
+ if (typeof matcher === "string") this.#matchers[param] = { match: new RegExp(matcher) };
135
+ else if (is.regExp(matcher)) this.#matchers[param] = { match: matcher };
136
+ else this.#matchers[param] = matcher;
137
+ return this;
138
+ }
139
+ prefix(prefix) {
140
+ this.#prefixes.push(prefix);
141
+ return this;
142
+ }
143
+ domain(domain, overwrite = false) {
144
+ if (this.#routeDomain === "root" || overwrite) this.#routeDomain = domain;
145
+ return this;
146
+ }
147
+ use(middleware) {
148
+ this.#middleware.push(Array.isArray(middleware) ? middleware : [middleware]);
149
+ return this;
150
+ }
151
+ middleware(middleware) {
152
+ return this.use(middleware);
153
+ }
154
+ as(name, prepend = false) {
155
+ if (prepend) {
156
+ if (!this.#name) throw new RuntimeException(`Routes inside a group must have names before calling "router.group.as"`);
157
+ this.#name = `${name}.${this.#name}`;
158
+ return this;
159
+ }
160
+ this.#name = name;
161
+ return this;
162
+ }
163
+ isDeleted() {
164
+ return this.#isDeleted;
165
+ }
166
+ markAsDeleted() {
167
+ this.#isDeleted = true;
168
+ }
169
+ getName() {
170
+ return this.#name;
171
+ }
172
+ getPattern() {
173
+ return this.#pattern;
174
+ }
175
+ setPattern(pattern) {
176
+ this.#pattern = pattern;
177
+ return this;
178
+ }
179
+ getMiddleware() {
180
+ return this.#middleware;
181
+ }
182
+ #getMiddlewareForStore() {
183
+ const middleware = new Middleware();
184
+ this.#routerMiddleware.forEach((one) => {
185
+ debug_default("adding global middleware to route %s, %O", this.#pattern, one);
186
+ middleware.add(one);
187
+ });
188
+ this.#middleware.flat().forEach((one) => {
189
+ debug_default("adding named middleware to route %s, %O", this.#pattern, one);
190
+ middleware.add(one);
191
+ });
192
+ middleware.freeze();
193
+ return middleware;
194
+ }
195
+ toJSON() {
196
+ const pattern = this.#computePattern();
197
+ const matchers = this.#getMatchers();
198
+ return {
199
+ domain: this.#routeDomain,
200
+ pattern,
201
+ matchers,
202
+ tokens: parseRoute(pattern, matchers),
203
+ meta: {},
204
+ name: this.#name,
205
+ handler: this.#handler,
206
+ methods: this.#methods,
207
+ middleware: this.#getMiddlewareForStore(),
208
+ execute
209
+ };
210
+ }
211
+ };
212
+ var BriskRoute = class extends Macroable {
213
+ #pattern;
214
+ #globalMatchers;
215
+ #app;
216
+ #routerMiddleware;
217
+ route = null;
218
+ constructor(app, routerMiddleware, options) {
219
+ super();
220
+ this.#app = app;
221
+ this.#routerMiddleware = routerMiddleware;
222
+ this.#pattern = options.pattern;
223
+ this.#globalMatchers = options.globalMatchers;
224
+ }
225
+ setHandler(handler) {
226
+ this.route = new Route(this.#app, this.#routerMiddleware, {
227
+ pattern: this.#pattern,
228
+ globalMatchers: this.#globalMatchers,
229
+ methods: ["GET", "HEAD"],
230
+ handler
231
+ });
232
+ return this.route;
233
+ }
234
+ redirect(...args) {
235
+ const [identifier, params, options] = args;
236
+ function redirectsToRoute(ctx) {
237
+ const redirector = ctx.response.redirect();
238
+ if (options?.status) redirector.status(options.status);
239
+ return redirector.toRoute(identifier, params || ctx.params, options);
240
+ }
241
+ Object.defineProperty(redirectsToRoute, "listArgs", {
242
+ value: identifier,
243
+ writable: false
244
+ });
245
+ return this.setHandler(redirectsToRoute);
246
+ }
247
+ redirectToPath(url, options) {
248
+ function redirectsToPath(ctx) {
249
+ const redirector = ctx.response.redirect();
250
+ if (options?.status) redirector.status(options.status);
251
+ return redirector.toPath(url);
252
+ }
253
+ Object.defineProperty(redirectsToPath, "listArgs", {
254
+ value: url,
255
+ writable: false
256
+ });
257
+ return this.setHandler(redirectsToPath);
258
+ }
259
+ };
260
+ var RouteResource = class extends Macroable {
261
+ #resource;
262
+ #controller;
263
+ #shallow = false;
264
+ #globalMatchers;
265
+ #app;
266
+ #routerMiddleware;
267
+ #params = {};
268
+ #routesBaseName;
269
+ routes = [];
270
+ constructor(app, routerMiddleware, options) {
271
+ super();
272
+ this.#validateResourceName(options.resource);
273
+ this.#app = app;
274
+ this.#shallow = options.shallow;
275
+ this.#routerMiddleware = routerMiddleware;
276
+ this.#controller = options.controller;
277
+ this.#globalMatchers = options.globalMatchers;
278
+ this.#resource = this.#normalizeResourceName(options.resource);
279
+ this.#routesBaseName = this.#getRoutesBaseName();
280
+ this.#buildRoutes();
281
+ }
282
+ #normalizeResourceName(resource) {
283
+ return resource.replace(/^\//, "").replace(/\/$/, "");
284
+ }
285
+ #validateResourceName(resource) {
286
+ if (!resource || resource === "/") throw new RuntimeException(`Invalid resource name "${resource}"`);
287
+ }
288
+ #getRoutesBaseName() {
289
+ return this.#resource.split(".").map((token) => string.snakeCase(token)).join(".");
290
+ }
291
+ #createRoute(pattern, methods, action) {
292
+ const route = new Route(this.#app, this.#routerMiddleware, {
293
+ pattern,
294
+ methods,
295
+ handler: typeof this.#controller === "string" ? `${this.#controller}.${action}` : [this.#controller, action],
296
+ globalMatchers: this.#globalMatchers
297
+ });
298
+ route.as(`${this.#routesBaseName}.${action}`);
299
+ this.routes.push(route);
300
+ }
301
+ #getResourceId(resource) {
302
+ return `${string.snakeCase(string.singular(resource))}_id`;
303
+ }
304
+ #buildRoutes() {
305
+ const resources = this.#resource.split(".");
306
+ const mainResource = resources.pop();
307
+ this.#params[mainResource] = ":id";
308
+ const baseURI = `${resources.map((resource) => {
309
+ const paramName = `:${this.#getResourceId(resource)}`;
310
+ this.#params[resource] = paramName;
311
+ return `${resource}/${paramName}`;
312
+ }).join("/")}/${mainResource}`;
313
+ this.#createRoute(baseURI, ["GET", "HEAD"], "index");
314
+ this.#createRoute(`${baseURI}/create`, ["GET", "HEAD"], "create");
315
+ this.#createRoute(baseURI, ["POST"], "store");
316
+ this.#createRoute(`${this.#shallow ? mainResource : baseURI}/:id`, ["GET", "HEAD"], "show");
317
+ this.#createRoute(`${this.#shallow ? mainResource : baseURI}/:id/edit`, ["GET", "HEAD"], "edit");
318
+ this.#createRoute(`${this.#shallow ? mainResource : baseURI}/:id`, ["PUT", "PATCH"], "update");
319
+ this.#createRoute(`${this.#shallow ? mainResource : baseURI}/:id`, ["DELETE"], "destroy");
320
+ }
321
+ #filter(names, inverse) {
322
+ const actions = Array.isArray(names) ? names : [names];
323
+ return this.routes.filter((route) => {
324
+ const match = actions.find((name) => route.getName().endsWith(name));
325
+ return inverse ? !match : match;
326
+ });
327
+ }
328
+ only(names) {
329
+ this.#filter(names, true).forEach((route) => route.markAsDeleted());
330
+ return this;
331
+ }
332
+ except(names) {
333
+ this.#filter(names, false).forEach((route) => route.markAsDeleted());
334
+ return this;
335
+ }
336
+ apiOnly() {
337
+ return this.except(["create", "edit"]);
338
+ }
339
+ where(key, matcher) {
340
+ this.routes.forEach((route) => {
341
+ route.where(key, matcher);
342
+ });
343
+ return this;
344
+ }
345
+ tap(actions, callback) {
346
+ if (typeof actions === "function") {
347
+ this.routes.forEach((route) => {
348
+ if (!route.isDeleted()) actions(route);
349
+ });
350
+ return this;
351
+ }
352
+ this.#filter(actions, false).forEach((route) => {
353
+ if (!route.isDeleted()) callback(route);
354
+ });
355
+ return this;
356
+ }
357
+ params(resources) {
358
+ Object.keys(resources).forEach((resource) => {
359
+ const param = resources[resource];
360
+ const existingParam = this.#params[resource];
361
+ this.#params[resource] = `:${param}`;
362
+ this.routes.forEach((route) => {
363
+ route.setPattern(route.getPattern().replace(`${resource}/${existingParam}`, `${resource}/:${param}`));
364
+ });
365
+ });
366
+ return this;
367
+ }
368
+ use(actions, middleware) {
369
+ if (actions === "*") this.tap((route) => route.use(middleware));
370
+ else this.tap(actions, (route) => route.use(middleware));
371
+ return this;
372
+ }
373
+ middleware(actions, middleware) {
374
+ return this.use(actions, middleware);
375
+ }
376
+ as(name, normalizeName = true) {
377
+ name = normalizeName ? string.snakeCase(name) : name;
378
+ this.routes.forEach((route) => {
379
+ route.as(route.getName().replace(this.#routesBaseName, name), false);
380
+ });
381
+ this.#routesBaseName = name;
382
+ return this;
383
+ }
384
+ };
385
+ var RouteGroup = class RouteGroup extends Macroable {
386
+ #middleware = [];
387
+ constructor(routes) {
388
+ super();
389
+ this.routes = routes;
390
+ }
391
+ #shareMiddlewareStackWithRoutes(route) {
392
+ if (route instanceof RouteGroup) {
393
+ route.routes.forEach((child) => this.#shareMiddlewareStackWithRoutes(child));
394
+ return;
395
+ }
396
+ if (route instanceof RouteResource) {
397
+ route.routes.forEach((child) => child.getMiddleware().unshift(this.#middleware));
398
+ return;
399
+ }
400
+ if (route instanceof BriskRoute) {
401
+ route.route.getMiddleware().unshift(this.#middleware);
402
+ return;
403
+ }
404
+ route.getMiddleware().unshift(this.#middleware);
405
+ }
406
+ #updateRouteName(route, name) {
407
+ if (route instanceof RouteGroup) {
408
+ route.routes.forEach((child) => this.#updateRouteName(child, name));
409
+ return;
410
+ }
411
+ if (route instanceof RouteResource) {
412
+ route.routes.forEach((child) => child.as(name, true));
413
+ return;
414
+ }
415
+ if (route instanceof BriskRoute) {
416
+ route.route.as(name, true);
417
+ return;
418
+ }
419
+ route.as(name, true);
420
+ }
421
+ #setRoutePrefix(route, prefix) {
422
+ if (route instanceof RouteGroup) {
423
+ route.routes.forEach((child) => this.#setRoutePrefix(child, prefix));
424
+ return;
425
+ }
426
+ if (route instanceof RouteResource) {
427
+ route.routes.forEach((child) => child.prefix(prefix));
428
+ return;
429
+ }
430
+ if (route instanceof BriskRoute) {
431
+ route.route.prefix(prefix);
432
+ return;
433
+ }
434
+ route.prefix(prefix);
435
+ }
436
+ #updateRouteDomain(route, domain) {
437
+ if (route instanceof RouteGroup) {
438
+ route.routes.forEach((child) => this.#updateRouteDomain(child, domain));
439
+ return;
440
+ }
441
+ if (route instanceof RouteResource) {
442
+ route.routes.forEach((child) => child.domain(domain));
443
+ return;
444
+ }
445
+ if (route instanceof BriskRoute) {
446
+ route.route.domain(domain, false);
447
+ return;
448
+ }
449
+ route.domain(domain, false);
450
+ }
451
+ #updateRouteMatchers(route, param, matcher) {
452
+ if (route instanceof RouteGroup) {
453
+ route.routes.forEach((child) => this.#updateRouteMatchers(child, param, matcher));
454
+ return;
455
+ }
456
+ if (route instanceof RouteResource) {
457
+ route.routes.forEach((child) => child.where(param, matcher));
458
+ return;
459
+ }
460
+ if (route instanceof BriskRoute) {
461
+ route.route.where(param, matcher);
462
+ return;
463
+ }
464
+ route.where(param, matcher);
465
+ }
466
+ where(param, matcher) {
467
+ this.routes.forEach((route) => this.#updateRouteMatchers(route, param, matcher));
468
+ return this;
469
+ }
470
+ prefix(prefix) {
471
+ this.routes.forEach((route) => this.#setRoutePrefix(route, prefix));
472
+ return this;
473
+ }
474
+ domain(domain) {
475
+ this.routes.forEach((route) => this.#updateRouteDomain(route, domain));
476
+ return this;
477
+ }
478
+ as(name) {
479
+ this.routes.forEach((route) => this.#updateRouteName(route, name));
480
+ return this;
481
+ }
482
+ use(middleware) {
483
+ if (!this.#middleware.length) this.routes.forEach((route) => this.#shareMiddlewareStackWithRoutes(route));
484
+ if (Array.isArray(middleware)) for (let one of middleware) this.#middleware.push(one);
485
+ else this.#middleware.push(middleware);
486
+ return this;
487
+ }
488
+ middleware(middleware) {
489
+ return this.use(middleware);
490
+ }
491
+ };
492
+ const proxyCache = new Cache({ max: 200 });
493
+ function dropSlash(input) {
494
+ if (input === "/") return "/";
495
+ return `/${input.replace(/^\//, "").replace(/\/$/, "")}`;
496
+ }
497
+ function toRoutesJSON(routes) {
498
+ return routes.reduce((list, route) => {
499
+ if (route instanceof RouteGroup) {
500
+ list = list.concat(toRoutesJSON(route.routes));
501
+ return list;
502
+ }
503
+ if (route instanceof RouteResource) {
504
+ list = list.concat(toRoutesJSON(route.routes));
505
+ return list;
506
+ }
507
+ if (route instanceof BriskRoute) {
508
+ if (route.route && !route.route.isDeleted()) list.push(route.route.toJSON());
509
+ return list;
510
+ }
511
+ if (!route.isDeleted()) list.push(route.toJSON());
512
+ return list;
513
+ }, []);
514
+ }
515
+ function trustProxy(remoteAddress, proxyFn) {
516
+ if (proxyCache.has(remoteAddress)) return proxyCache.get(remoteAddress);
517
+ const result = proxyFn(remoteAddress, 0);
518
+ proxyCache.set(remoteAddress, result);
519
+ return result;
520
+ }
521
+ function parseRange(range, value) {
522
+ const parts = range.split("..");
523
+ const min = Number(parts[0]);
524
+ const max = Number(parts[1]);
525
+ if (parts.length === 1 && !Number.isNaN(min)) return { [min]: value };
526
+ if (Number.isNaN(min) || Number.isNaN(max)) return {};
527
+ if (min === max) return { [min]: value };
528
+ if (max < min) throw new InvalidArgumentsException(`Invalid range "${range}"`);
529
+ return [...Array(max - min + 1).keys()].reduce((result, step) => {
530
+ result[min + step] = value;
531
+ return result;
532
+ }, {});
533
+ }
534
+ function decodeComponentChar(highCharCode, lowCharCode) {
535
+ if (highCharCode === 50) {
536
+ if (lowCharCode === 53) return "%";
537
+ if (lowCharCode === 51) return "#";
538
+ if (lowCharCode === 52) return "$";
539
+ if (lowCharCode === 54) return "&";
540
+ if (lowCharCode === 66) return "+";
541
+ if (lowCharCode === 98) return "+";
542
+ if (lowCharCode === 67) return ",";
543
+ if (lowCharCode === 99) return ",";
544
+ if (lowCharCode === 70) return "/";
545
+ if (lowCharCode === 102) return "/";
546
+ return null;
547
+ }
548
+ if (highCharCode === 51) {
549
+ if (lowCharCode === 65) return ":";
550
+ if (lowCharCode === 97) return ":";
551
+ if (lowCharCode === 66) return ";";
552
+ if (lowCharCode === 98) return ";";
553
+ if (lowCharCode === 68) return "=";
554
+ if (lowCharCode === 100) return "=";
555
+ if (lowCharCode === 70) return "?";
556
+ if (lowCharCode === 102) return "?";
557
+ return null;
558
+ }
559
+ if (highCharCode === 52 && lowCharCode === 48) return "@";
560
+ return null;
561
+ }
562
+ function safeDecodeURI(path, useSemicolonDelimiter) {
563
+ let shouldDecode = false;
564
+ let shouldDecodeParam = false;
565
+ let querystring = "";
566
+ for (let i = 1; i < path.length; i++) {
567
+ const charCode = path.charCodeAt(i);
568
+ if (charCode === 37) {
569
+ const highCharCode = path.charCodeAt(i + 1);
570
+ const lowCharCode = path.charCodeAt(i + 2);
571
+ if (decodeComponentChar(highCharCode, lowCharCode) === null) shouldDecode = true;
572
+ else {
573
+ shouldDecodeParam = true;
574
+ if (highCharCode === 50 && lowCharCode === 53) {
575
+ shouldDecode = true;
576
+ path = path.slice(0, i + 1) + "25" + path.slice(i + 1);
577
+ i += 2;
578
+ }
579
+ i += 2;
580
+ }
581
+ } else if (charCode === 63 || charCode === 35 || charCode === 59 && useSemicolonDelimiter) {
582
+ querystring = path.slice(i + 1);
583
+ path = path.slice(0, i);
584
+ break;
585
+ }
586
+ }
587
+ return {
588
+ pathname: shouldDecode ? decodeURI(path) : path,
589
+ query: querystring,
590
+ shouldDecodeParam
591
+ };
592
+ }
593
+ function parseRoute(pattern, matchers) {
594
+ return matchit.parse(pattern, matchers);
595
+ }
596
+ function createSignedURL(identifier, tokens, searchParamsStringifier, encryption, params, options) {
597
+ const signature = encryption.verifier.sign(createURL(identifier, tokens, searchParamsStringifier, params, {
598
+ ...options,
599
+ prefixUrl: void 0
600
+ }), options?.expiresIn, options?.purpose);
601
+ return createURL(identifier, tokens, searchParamsStringifier, params, {
602
+ ...options,
603
+ qs: {
604
+ ...options?.qs,
605
+ signature
606
+ }
607
+ });
608
+ }
609
+ function matchRoute(url, patterns) {
610
+ const tokensBucket = patterns.map((pattern) => parseRoute(pattern));
611
+ const match = matchit.match(url, tokensBucket);
612
+ if (!match.length) return null;
613
+ return matchit.exec(url, match);
614
+ }
615
+ function serializeCookie(key, value, options) {
616
+ let expires;
617
+ let maxAge;
618
+ if (options) {
619
+ expires = typeof options.expires === "function" ? options.expires() : options.expires;
620
+ maxAge = options.maxAge ? string.seconds.parse(options.maxAge) : void 0;
621
+ }
622
+ return serialize(key, value, {
623
+ ...options,
624
+ maxAge,
625
+ expires
626
+ });
627
+ }
628
+ async function middlewareInfo(middleware) {
629
+ if (typeof middleware === "function") return {
630
+ type: "closure",
631
+ name: middleware.name || "closure"
632
+ };
633
+ if ("args" in middleware) return {
634
+ type: "named",
635
+ name: middleware.name,
636
+ args: middleware.args,
637
+ ...await parseBindingReference([middleware.reference])
638
+ };
639
+ return {
640
+ type: "global",
641
+ name: middleware.name,
642
+ ...await parseBindingReference([middleware.reference])
643
+ };
644
+ }
645
+ async function routeInfo(route) {
646
+ return "reference" in route.handler ? {
647
+ type: "controller",
648
+ ...await parseBindingReference(route.handler.reference)
649
+ } : {
650
+ type: "closure",
651
+ name: route.handler.name || "closure",
652
+ args: "listArgs" in route.handler ? String(route.handler.listArgs) : void 0
653
+ };
654
+ }
655
+ function appendQueryString(uri, queryString, qsParser) {
656
+ const { query, pathname } = safeDecodeURI(uri, false);
657
+ const mergedQueryString = qsParser.stringify(Object.assign(qsParser.parse(query), queryString));
658
+ return mergedQueryString ? `${pathname}?${mergedQueryString}` : pathname;
659
+ }
660
+ export { canWriteResponseBody as C, tracing_channels_exports as S, __export as T, Route as _, middlewareInfo as a, httpRequest as b, routeInfo as c, safeDecodeURI as d, toRoutesJSON as f, BriskRoute as g, RouteResource as h, matchRoute as i, serializeCookie as l, RouteGroup as m, createSignedURL as n, mime as o, trustProxy as p, encodeUrl as r, parseRoute as s, appendQueryString as t, parseRange as u, httpExceptionHandler as v, debug_default as w, httpResponseSerializer as x, httpMiddleware as y };
package/build/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  export { Qs } from './src/qs.ts';
2
2
  export * as errors from './src/errors.ts';
3
- export { Request } from './src/request.ts';
4
- export { Response } from './src/response.ts';
5
3
  export { Redirect } from './src/redirect.ts';
6
4
  export { Server } from './src/server/main.ts';
7
5
  export { Router } from './src/router/main.ts';
8
6
  export { Route } from './src/router/route.ts';
7
+ export { HttpRequest } from './src/request.ts';
8
+ export { HttpResponse } from './src/response.ts';
9
9
  export { BriskRoute } from './src/router/brisk.ts';
10
10
  export { RouteGroup } from './src/router/group.ts';
11
11
  export { defineConfig } from './src/define_config.ts';