@adonisjs/http-server 8.0.0-next.8 → 8.0.0

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.
Files changed (49) hide show
  1. package/build/define_config-D-kQXU0e.js +2438 -0
  2. package/build/factories/http_context.d.ts +10 -4
  3. package/build/factories/main.d.ts +2 -2
  4. package/build/factories/main.js +170 -345
  5. package/build/factories/request.d.ts +4 -4
  6. package/build/factories/response.d.ts +4 -4
  7. package/build/factories/router.d.ts +1 -1
  8. package/build/factories/server_factory.d.ts +1 -1
  9. package/build/factories/url_builder_factory.d.ts +3 -3
  10. package/build/helpers-C_2HouOe.js +52 -0
  11. package/build/index.d.ts +3 -2
  12. package/build/index.js +155 -370
  13. package/build/src/client/helpers.d.ts +37 -0
  14. package/build/src/client/types.d.ts +194 -0
  15. package/build/src/client/url_builder.d.ts +15 -0
  16. package/build/src/client/url_builder.js +115 -0
  17. package/build/src/cookies/client.d.ts +28 -5
  18. package/build/src/cookies/drivers/encrypted.d.ts +1 -1
  19. package/build/src/cookies/drivers/signed.d.ts +1 -1
  20. package/build/src/cookies/parser.d.ts +1 -1
  21. package/build/src/cookies/serializer.d.ts +2 -2
  22. package/build/src/debug.d.ts +14 -1
  23. package/build/src/define_config.d.ts +19 -1
  24. package/build/src/define_middleware.d.ts +19 -3
  25. package/build/src/errors.d.ts +60 -5
  26. package/build/src/exception_handler.d.ts +28 -8
  27. package/build/src/helpers.d.ts +23 -16
  28. package/build/src/helpers.js +76 -22
  29. package/build/src/http_context/main.d.ts +67 -17
  30. package/build/src/qs.d.ts +17 -3
  31. package/build/src/redirect.d.ts +22 -3
  32. package/build/src/request.d.ts +12 -5
  33. package/build/src/response.d.ts +5 -5
  34. package/build/src/response_status.d.ts +14 -0
  35. package/build/src/router/main.d.ts +6 -2
  36. package/build/src/router/route.d.ts +130 -32
  37. package/build/src/router/signed_url_builder.d.ts +1 -1
  38. package/build/src/server/main.d.ts +6 -6
  39. package/build/src/types/main.js +1 -0
  40. package/build/src/types/response.d.ts +6 -1
  41. package/build/src/types/route.d.ts +3 -27
  42. package/build/src/types/url_builder.d.ts +2 -140
  43. package/build/src/utils.d.ts +71 -6
  44. package/build/types-AUwURgIL.js +1 -0
  45. package/build/utils-BjSHKI3s.js +618 -0
  46. package/package.json +56 -47
  47. package/build/chunk-NQNHMINZ.js +0 -135
  48. package/build/chunk-W6WKITGF.js +0 -5486
  49. package/build/src/router/url_builder.d.ts +0 -9
@@ -0,0 +1,52 @@
1
+ function findRoute(domainsRoutes, routeIdentifier, domain, method, disableLegacyLookup) {
2
+ if (!domain) {
3
+ let route = null;
4
+ for (const routeDomain of Object.keys(domainsRoutes)) {
5
+ route = findRoute(domainsRoutes, routeIdentifier, routeDomain, method, disableLegacyLookup);
6
+ if (route) break;
7
+ }
8
+ return route;
9
+ }
10
+ const routes = domainsRoutes[domain];
11
+ if (!routes) return null;
12
+ const lookupByPattern = !disableLegacyLookup;
13
+ const lookupByController = !disableLegacyLookup;
14
+ return routes.find((route) => {
15
+ if (method && !route.methods.includes(method)) return false;
16
+ if (route.name === routeIdentifier || lookupByPattern && route.pattern === routeIdentifier) return true;
17
+ if (lookupByController && route.handler && typeof route.handler === "object") return "reference" in route.handler && route.handler.reference === routeIdentifier;
18
+ return false;
19
+ }) || null;
20
+ }
21
+ function createURL(pattern, tokens, searchParamsStringifier, params, options) {
22
+ const uriSegments = [];
23
+ const paramsArray = Array.isArray(params) ? params : null;
24
+ const paramsObject = !Array.isArray(params) ? params ?? {} : {};
25
+ let paramsIndex = 0;
26
+ for (const token of tokens) {
27
+ if (token.type === 0) {
28
+ uriSegments.push(token.val === "/" ? "" : `${token.val}${token.end}`);
29
+ continue;
30
+ }
31
+ if (token.type === 2) {
32
+ const values = paramsArray ? paramsArray.slice(paramsIndex) : paramsObject["*"];
33
+ if (!Array.isArray(values) || !values.length) throw new Error(`Cannot make URL for "${pattern}". Invalid value provided for the wildcard param`);
34
+ uriSegments.push(`${values.join("/")}${token.end}`);
35
+ break;
36
+ }
37
+ const paramName = token.val;
38
+ const value = paramsArray ? paramsArray[paramsIndex] : paramsObject[paramName];
39
+ const isDefined = value !== void 0 && value !== null;
40
+ if (token.type === 1 && !isDefined) throw new Error(`Cannot make URL for "${pattern}". Missing value for the "${paramName}" param`);
41
+ if (isDefined) uriSegments.push(`${value}${token.end}`);
42
+ paramsIndex++;
43
+ }
44
+ let URI = `/${uriSegments.join("/")}`;
45
+ if (options?.prefixUrl) URI = `${options?.prefixUrl.replace(/\/$/, "")}${URI}`;
46
+ if (options?.qs) {
47
+ const queryString = searchParamsStringifier(options?.qs);
48
+ URI = queryString ? `${URI}?${queryString}` : URI;
49
+ }
50
+ return URI;
51
+ }
52
+ export { findRoute as n, createURL as t };
package/build/index.d.ts CHANGED
@@ -1,10 +1,11 @@
1
+ export { Qs } from './src/qs.ts';
1
2
  export * as errors from './src/errors.ts';
2
- export { Request } from './src/request.ts';
3
- export { Response } from './src/response.ts';
4
3
  export { Redirect } from './src/redirect.ts';
5
4
  export { Server } from './src/server/main.ts';
6
5
  export { Router } from './src/router/main.ts';
7
6
  export { Route } from './src/router/route.ts';
7
+ export { HttpRequest } from './src/request.ts';
8
+ export { HttpResponse } from './src/response.ts';
8
9
  export { BriskRoute } from './src/router/brisk.ts';
9
10
  export { RouteGroup } from './src/router/group.ts';
10
11
  export { defineConfig } from './src/define_config.ts';
package/build/index.js CHANGED
@@ -1,373 +1,158 @@
1
- import {
2
- BriskRoute,
3
- CookieClient,
4
- CookieParser,
5
- CookieSerializer,
6
- E_CANNOT_LOOKUP_ROUTE,
7
- E_HTTP_EXCEPTION,
8
- E_HTTP_REQUEST_ABORTED,
9
- E_ROUTE_NOT_FOUND,
10
- HttpContext,
11
- Redirect,
12
- Request,
13
- Response,
14
- ResponseStatus,
15
- Route,
16
- RouteGroup,
17
- RouteResource,
18
- Router,
19
- Server,
20
- canWriteResponseBody,
21
- defineConfig,
22
- errors_exports,
23
- parseRange,
24
- tracing_channels_exports
25
- } from "./chunk-W6WKITGF.js";
26
- import "./chunk-NQNHMINZ.js";
27
-
28
- // src/exception_handler.ts
29
- import is from "@sindresorhus/is";
1
+ import { a as RouteGroup, c as Route, m as canWriteResponseBody, o as RouteResource, p as tracing_channels_exports, s as BriskRoute, t as parseRange } from "./utils-BjSHKI3s.js";
2
+ import { _ as Qs, a as CookieSerializer, c as HttpRequest, d as Redirect, f as E_CANNOT_LOOKUP_ROUTE, g as errors_exports, h as E_ROUTE_NOT_FOUND, i as HttpResponse, l as CookieParser, m as E_HTTP_REQUEST_ABORTED, n as Server, o as ResponseStatus, p as E_HTTP_EXCEPTION, r as HttpContext, s as Router, t as defineConfig, u as CookieClient } from "./define_config-D-kQXU0e.js";
3
+ import "./helpers-C_2HouOe.js";
4
+ import "./types-AUwURgIL.js";
30
5
  import Macroable from "@poppinss/macroable";
6
+ import is from "@sindresorhus/is";
31
7
  var ExceptionHandler = class extends Macroable {
32
- /**
33
- * Cached expanded status pages mapping individual status codes to their renderers
34
- * Computed from the statusPages property when first accessed
35
- */
36
- #expandedStatusPages;
37
- /**
38
- * Controls whether to include debug information in error responses
39
- * When enabled, errors include complete stack traces and detailed debugging info
40
- * Defaults to true in non-production environments
41
- */
42
- debug = process.env.NODE_ENV !== "production";
43
- /**
44
- * Controls whether to render custom status pages for unhandled errors
45
- * When enabled, errors with matching status codes use configured status page renderers
46
- * Defaults to true in production environments
47
- */
48
- renderStatusPages = process.env.NODE_ENV === "production";
49
- /**
50
- * Mapping of HTTP status code ranges to their corresponding page renderers
51
- * Supports ranges like '400-499' or individual codes like '404'
52
- */
53
- statusPages = {};
54
- /**
55
- * Controls whether errors should be reported to logging systems
56
- * When disabled, errors are handled but not logged or reported
57
- */
58
- reportErrors = true;
59
- /**
60
- * Array of exception class constructors to exclude from error reporting
61
- * These exceptions are handled but not logged or reported to external systems
62
- */
63
- ignoreExceptions = [
64
- E_HTTP_EXCEPTION,
65
- E_ROUTE_NOT_FOUND,
66
- E_CANNOT_LOOKUP_ROUTE,
67
- E_HTTP_REQUEST_ABORTED
68
- ];
69
- /**
70
- * Array of HTTP status codes to exclude from error reporting
71
- * Errors with these status codes are handled but not logged
72
- */
73
- ignoreStatuses = [400, 422, 401];
74
- /**
75
- * Array of custom error codes to exclude from error reporting
76
- * Errors with these codes are handled but not logged
77
- */
78
- ignoreCodes = [];
79
- /**
80
- * Expands status page ranges into individual status code mappings
81
- * Creates a cached lookup table for faster status page resolution
82
- * @returns Mapping of status codes to renderers
83
- */
84
- #expandStatusPages() {
85
- if (!this.#expandedStatusPages) {
86
- this.#expandedStatusPages = Object.keys(this.statusPages).reduce(
87
- (result, range) => {
88
- const renderer = this.statusPages[range];
89
- result = Object.assign(result, parseRange(range, renderer));
90
- return result;
91
- },
92
- {}
93
- );
94
- }
95
- return this.#expandedStatusPages;
96
- }
97
- /**
98
- * Normalizes any thrown value into a standardized HttpError object
99
- * Ensures the error has required properties like message and status
100
- * @param error - Any thrown value (Error, string, object, etc.)
101
- * @returns {HttpError} Normalized error object with status and message
102
- */
103
- #toHttpError(error) {
104
- const httpError = is.object(error) ? error : new Error(String(error));
105
- if (!httpError.message) {
106
- httpError.message = "Internal server error";
107
- }
108
- if (!httpError.status) {
109
- httpError.status = 500;
110
- }
111
- return httpError;
112
- }
113
- /**
114
- * Provides additional context information for error reporting
115
- * Includes request ID when available for correlation across logs
116
- * @param ctx - HTTP context containing request information
117
- * @returns Additional context data for error reporting
118
- */
119
- context(ctx) {
120
- const requestId = ctx.request.id();
121
- return requestId ? {
122
- "x-request-id": requestId
123
- } : {};
124
- }
125
- /**
126
- * Determines the appropriate log level based on HTTP status code
127
- * 5xx errors are logged as 'error', 4xx as 'warn', others as 'info'
128
- * @param error - HTTP error object with status code
129
- * @returns {Level} Appropriate logging level for the error
130
- */
131
- getErrorLogLevel(error) {
132
- if (error.status >= 500) {
133
- return "error";
134
- }
135
- if (error.status >= 400) {
136
- return "warn";
137
- }
138
- return "info";
139
- }
140
- /**
141
- * Determines whether debug information should be included in error responses
142
- * Override this method to implement context-specific debug control
143
- * @param _ - HTTP context (unused in base implementation)
144
- * @returns {boolean} True if debugging should be enabled
145
- */
146
- isDebuggingEnabled(_) {
147
- return this.debug;
148
- }
149
- /**
150
- * Determines whether an error should be reported to logging systems
151
- * Checks against ignore lists for exceptions, status codes, and error codes
152
- * @param error - HTTP error to evaluate for reporting
153
- * @returns {boolean} True if the error should be reported
154
- */
155
- shouldReport(error) {
156
- if (this.reportErrors === false) {
157
- return false;
158
- }
159
- if (this.ignoreStatuses.includes(error.status)) {
160
- return false;
161
- }
162
- if (error.code && this.ignoreCodes.includes(error.code)) {
163
- return false;
164
- }
165
- if (this.ignoreExceptions.find((exception) => error instanceof exception)) {
166
- return false;
167
- }
168
- return true;
169
- }
170
- /**
171
- * Renders an error as a JSON response
172
- * In debug mode, includes full stack trace using Youch
173
- * @param error - HTTP error to render
174
- * @param ctx - HTTP context for the request
175
- */
176
- async renderErrorAsJSON(error, ctx) {
177
- if (this.isDebuggingEnabled(ctx)) {
178
- const { Youch } = await import("youch");
179
- const json = await new Youch().toJSON(error);
180
- ctx.response.status(error.status).send(json);
181
- return;
182
- }
183
- ctx.response.status(error.status).send({ message: error.message });
184
- }
185
- /**
186
- * Renders an error as a JSON API compliant response
187
- * Follows JSON API specification for error objects
188
- * @param error - HTTP error to render
189
- * @param ctx - HTTP context for the request
190
- */
191
- async renderErrorAsJSONAPI(error, ctx) {
192
- if (this.isDebuggingEnabled(ctx)) {
193
- const { Youch } = await import("youch");
194
- const json = await new Youch().toJSON(error);
195
- ctx.response.status(error.status).send(json);
196
- return;
197
- }
198
- ctx.response.status(error.status).send({
199
- errors: [
200
- {
201
- title: error.message,
202
- code: error.code,
203
- status: error.status
204
- }
205
- ]
206
- });
207
- }
208
- /**
209
- * Renders an error as an HTML response
210
- * Uses status pages if configured, otherwise shows debug info or simple message
211
- * @param error - HTTP error to render
212
- * @param ctx - HTTP context for the request
213
- */
214
- async renderErrorAsHTML(error, ctx) {
215
- const statusPages = this.#expandStatusPages();
216
- if (this.renderStatusPages && statusPages[error.status]) {
217
- const statusPageResponse = await statusPages[error.status](error, ctx);
218
- if (canWriteResponseBody(statusPageResponse, ctx)) {
219
- return ctx.response.safeStatus(error.status).send(statusPageResponse);
220
- }
221
- return statusPageResponse;
222
- }
223
- if (this.isDebuggingEnabled(ctx)) {
224
- const { Youch } = await import("youch");
225
- const html = await new Youch().toHTML(error, {
226
- request: ctx.request.request,
227
- cspNonce: "nonce" in ctx.response ? ctx.response.nonce : void 0
228
- });
229
- ctx.response.status(error.status).send(html);
230
- return;
231
- }
232
- ctx.response.status(error.status).send(`<p> ${error.message} </p>`);
233
- }
234
- /**
235
- * Renders validation error messages as a JSON response
236
- * Returns errors in a simple format with field-specific messages
237
- * @param error - Validation error containing messages array
238
- * @param ctx - HTTP context for the request
239
- */
240
- async renderValidationErrorAsJSON(error, ctx) {
241
- ctx.response.status(error.status).send({
242
- errors: error.messages
243
- });
244
- }
245
- /**
246
- * Renders validation error messages as JSON API compliant response
247
- * Transforms validation messages to JSON API error object format
248
- * @param error - Validation error containing messages array
249
- * @param ctx - HTTP context for the request
250
- */
251
- async renderValidationErrorAsJSONAPI(error, ctx) {
252
- ctx.response.status(error.status).send({
253
- errors: error.messages.map((message) => {
254
- return {
255
- title: message.message,
256
- code: message.rule,
257
- source: {
258
- pointer: message.field
259
- },
260
- meta: message.meta
261
- };
262
- })
263
- });
264
- }
265
- /**
266
- * Renders validation error messages as an HTML response
267
- * Creates simple HTML list of field errors separated by line breaks
268
- * @param error - Validation error containing messages array
269
- * @param ctx - HTTP context for the request
270
- */
271
- async renderValidationErrorAsHTML(error, ctx) {
272
- ctx.response.status(error.status).type("html").send(
273
- error.messages.map((message) => {
274
- return `${message.field} - ${message.message}`;
275
- }).join("<br />")
276
- );
277
- }
278
- /**
279
- * Renders an error to the appropriate response format based on content negotiation
280
- * Supports HTML, JSON API, and JSON formats based on Accept headers
281
- * @param error - HTTP error to render
282
- * @param ctx - HTTP context for the request
283
- */
284
- renderError(error, ctx) {
285
- switch (ctx.request.accepts(["html", "application/vnd.api+json", "json"])) {
286
- case "application/vnd.api+json":
287
- return this.renderErrorAsJSONAPI(error, ctx);
288
- case "json":
289
- return this.renderErrorAsJSON(error, ctx);
290
- case "html":
291
- default:
292
- return this.renderErrorAsHTML(error, ctx);
293
- }
294
- }
295
- /**
296
- * Renders validation errors to the appropriate response format based on content negotiation
297
- * Supports HTML, JSON API, and JSON formats for validation error messages
298
- * @param error - Validation error to render
299
- * @param ctx - HTTP context for the request
300
- */
301
- renderValidationError(error, ctx) {
302
- switch (ctx.request.accepts(["html", "application/vnd.api+json", "json"])) {
303
- case "application/vnd.api+json":
304
- return this.renderValidationErrorAsJSONAPI(error, ctx);
305
- case "json":
306
- return this.renderValidationErrorAsJSON(error, ctx);
307
- case "html":
308
- default:
309
- return this.renderValidationErrorAsHTML(error, ctx);
310
- }
311
- }
312
- /**
313
- * Reports an error to logging systems if reporting is enabled
314
- * Allows errors to self-report via their own report method if available
315
- * @param error - Any error object to report
316
- * @param ctx - HTTP context for additional reporting context
317
- */
318
- async report(error, ctx) {
319
- const httpError = this.#toHttpError(error);
320
- if (!this.shouldReport(httpError)) {
321
- return;
322
- }
323
- if (typeof httpError.report === "function") {
324
- httpError.report(httpError, ctx);
325
- return;
326
- }
327
- const level = this.getErrorLogLevel(httpError);
328
- ctx.logger.log(
329
- level,
330
- {
331
- ...level === "error" || level === "fatal" ? { err: httpError } : {},
332
- ...this.context(ctx)
333
- },
334
- httpError.message
335
- );
336
- }
337
- /**
338
- * Handles errors during HTTP request processing
339
- * Delegates to error's own handle method if available, otherwise renders response
340
- * @param error - Any error object to handle
341
- * @param ctx - HTTP context for error handling
342
- */
343
- async handle(error, ctx) {
344
- const httpError = this.#toHttpError(error);
345
- if (typeof httpError.handle === "function") {
346
- return httpError.handle(httpError, ctx);
347
- }
348
- if (httpError.code === "E_VALIDATION_ERROR" && "messages" in httpError) {
349
- return this.renderValidationError(httpError, ctx);
350
- }
351
- return this.renderError(httpError, ctx);
352
- }
353
- };
354
- export {
355
- BriskRoute,
356
- CookieClient,
357
- CookieParser,
358
- CookieSerializer,
359
- ExceptionHandler,
360
- HttpContext,
361
- Redirect,
362
- Request,
363
- Response,
364
- ResponseStatus,
365
- Route,
366
- RouteGroup,
367
- RouteResource,
368
- Router,
369
- Server,
370
- defineConfig,
371
- errors_exports as errors,
372
- tracing_channels_exports as tracingChannels
8
+ #expandedStatusPages;
9
+ debug = process.env.NODE_ENV !== "production";
10
+ renderStatusPages = process.env.NODE_ENV === "production";
11
+ statusPages = {};
12
+ reportErrors = true;
13
+ ignoreExceptions = [
14
+ E_HTTP_EXCEPTION,
15
+ E_ROUTE_NOT_FOUND,
16
+ E_CANNOT_LOOKUP_ROUTE,
17
+ E_HTTP_REQUEST_ABORTED
18
+ ];
19
+ ignoreStatuses = [
20
+ 400,
21
+ 422,
22
+ 401
23
+ ];
24
+ ignoreCodes = [];
25
+ #expandStatusPages() {
26
+ if (!this.#expandedStatusPages) this.#expandedStatusPages = Object.keys(this.statusPages).reduce((result, range) => {
27
+ const renderer = this.statusPages[range];
28
+ result = Object.assign(result, parseRange(range, renderer));
29
+ return result;
30
+ }, {});
31
+ return this.#expandedStatusPages;
32
+ }
33
+ toHttpError(error) {
34
+ const httpError = is.object(error) ? error : new Error(String(error));
35
+ if (!httpError.message) httpError.message = "Internal server error";
36
+ if (!httpError.status) httpError.status = 500;
37
+ return httpError;
38
+ }
39
+ context(ctx) {
40
+ const requestId = ctx.request.id();
41
+ return requestId ? { "x-request-id": requestId } : {};
42
+ }
43
+ getErrorLogLevel(error) {
44
+ if (error.status >= 500) return "error";
45
+ if (error.status >= 400) return "warn";
46
+ return "info";
47
+ }
48
+ isDebuggingEnabled(_) {
49
+ return this.debug;
50
+ }
51
+ shouldReport(error) {
52
+ if (this.reportErrors === false) return false;
53
+ if (this.ignoreStatuses.includes(error.status)) return false;
54
+ if (error.code && this.ignoreCodes.includes(error.code)) return false;
55
+ if (this.ignoreExceptions.find((exception) => error instanceof exception)) return false;
56
+ return true;
57
+ }
58
+ async renderErrorAsJSON(error, ctx) {
59
+ if (this.isDebuggingEnabled(ctx)) {
60
+ const { Youch } = await import("youch");
61
+ const json = await new Youch().toJSON(error);
62
+ ctx.response.status(error.status).send(json);
63
+ return;
64
+ }
65
+ ctx.response.status(error.status).send({ message: error.message });
66
+ }
67
+ async renderErrorAsJSONAPI(error, ctx) {
68
+ if (this.isDebuggingEnabled(ctx)) {
69
+ const { Youch } = await import("youch");
70
+ const json = await new Youch().toJSON(error);
71
+ ctx.response.status(error.status).send(json);
72
+ return;
73
+ }
74
+ ctx.response.status(error.status).send({ errors: [{
75
+ title: error.message,
76
+ code: error.code,
77
+ status: error.status
78
+ }] });
79
+ }
80
+ async renderErrorAsHTML(error, ctx) {
81
+ const statusPages = this.#expandStatusPages();
82
+ if (this.renderStatusPages && statusPages[error.status]) {
83
+ const statusPageResponse = await statusPages[error.status](error, ctx);
84
+ if (canWriteResponseBody(statusPageResponse, ctx)) return ctx.response.safeStatus(error.status).send(statusPageResponse);
85
+ return statusPageResponse;
86
+ }
87
+ if (this.isDebuggingEnabled(ctx)) {
88
+ const { Youch } = await import("youch");
89
+ const html = await new Youch().toHTML(error, {
90
+ request: ctx.request.request,
91
+ cspNonce: "nonce" in ctx.response ? ctx.response.nonce : void 0
92
+ });
93
+ ctx.response.status(error.status).send(html);
94
+ return;
95
+ }
96
+ ctx.response.status(error.status).send(`<p> ${error.message} </p>`);
97
+ }
98
+ async renderValidationErrorAsJSON(error, ctx) {
99
+ ctx.response.status(error.status).send({ errors: error.messages });
100
+ }
101
+ async renderValidationErrorAsJSONAPI(error, ctx) {
102
+ ctx.response.status(error.status).send({ errors: error.messages.map((message) => {
103
+ return {
104
+ title: message.message,
105
+ code: message.rule,
106
+ source: { pointer: message.field },
107
+ meta: message.meta
108
+ };
109
+ }) });
110
+ }
111
+ async renderValidationErrorAsHTML(error, ctx) {
112
+ ctx.response.status(error.status).type("html").send(error.messages.map((message) => {
113
+ return `${message.field} - ${message.message}`;
114
+ }).join("<br />"));
115
+ }
116
+ renderError(error, ctx) {
117
+ switch (ctx.request.accepts([
118
+ "html",
119
+ "application/vnd.api+json",
120
+ "json"
121
+ ])) {
122
+ case "application/vnd.api+json": return this.renderErrorAsJSONAPI(error, ctx);
123
+ case "json": return this.renderErrorAsJSON(error, ctx);
124
+ default: return this.renderErrorAsHTML(error, ctx);
125
+ }
126
+ }
127
+ renderValidationError(error, ctx) {
128
+ switch (ctx.request.accepts([
129
+ "html",
130
+ "application/vnd.api+json",
131
+ "json"
132
+ ])) {
133
+ case "application/vnd.api+json": return this.renderValidationErrorAsJSONAPI(error, ctx);
134
+ case "json": return this.renderValidationErrorAsJSON(error, ctx);
135
+ default: return this.renderValidationErrorAsHTML(error, ctx);
136
+ }
137
+ }
138
+ async report(error, ctx) {
139
+ const httpError = this.toHttpError(error);
140
+ if (!this.shouldReport(httpError)) return;
141
+ if (typeof httpError.report === "function") {
142
+ httpError.report(httpError, ctx);
143
+ return;
144
+ }
145
+ const level = this.getErrorLogLevel(httpError);
146
+ ctx.logger.log(level, {
147
+ ...level === "error" || level === "fatal" ? { err: httpError } : {},
148
+ ...this.context(ctx)
149
+ }, httpError.message);
150
+ }
151
+ async handle(error, ctx) {
152
+ const httpError = this.toHttpError(error);
153
+ if (typeof httpError.handle === "function") return httpError.handle(httpError, ctx);
154
+ if (httpError.code === "E_VALIDATION_ERROR" && "messages" in httpError) return this.renderValidationError(httpError, ctx);
155
+ return this.renderError(httpError, ctx);
156
+ }
373
157
  };
158
+ export { BriskRoute, CookieClient, CookieParser, CookieSerializer, ExceptionHandler, HttpContext, HttpRequest, HttpResponse, Qs, Redirect, ResponseStatus, Route, RouteGroup, RouteResource, Router, Server, defineConfig, errors_exports as errors, tracing_channels_exports as tracingChannels };
@@ -0,0 +1,37 @@
1
+ import { type ClientRouteMatchItTokens, type ClientRouteJSON, type URLOptions } from './types.ts';
2
+ /**
3
+ * Finds a route by its identifier across domains.
4
+ *
5
+ * Searches for routes by name, pattern, or controller reference. When no domain
6
+ * is specified, searches across all domains. Supports legacy lookup strategies
7
+ * for backwards compatibility.
8
+ *
9
+ * @param domainsRoutes - Object mapping domain names to route arrays
10
+ * @param routeIdentifier - Route name, pattern, or controller reference to find
11
+ * @param domain - Optional domain to limit search scope
12
+ * @param method - Optional HTTP method to filter routes
13
+ * @param disableLegacyLookup - Whether to disable pattern and controller lookup
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * const route = findRoute(routes, 'users.show', 'api', 'GET')
18
+ * const route2 = findRoute(routes, '/users/:id', undefined, 'GET')
19
+ * ```
20
+ */
21
+ export declare function findRoute<Route extends ClientRouteJSON>(domainsRoutes: {
22
+ [domain: string]: Route[];
23
+ }, routeIdentifier: string, domain?: string, method?: string, disableLegacyLookup?: boolean): null | Route;
24
+ /**
25
+ * Makes URL for a given route pattern using its parsed tokens. The
26
+ * tokens could be generated using the "parseRoute" method.
27
+ *
28
+ * @param pattern - The route pattern
29
+ * @param tokens - Array of parsed route tokens
30
+ * @param searchParamsStringifier - Function to stringify query parameters
31
+ * @param params - Route parameters as array or object
32
+ * @param options - URL options
33
+ * @returns {string} The generated URL
34
+ */
35
+ export declare function createURL(pattern: string, tokens: Pick<ClientRouteMatchItTokens, 'val' | 'type' | 'end'>[], searchParamsStringifier: (qs: Record<string, any>) => string, params?: any[] | {
36
+ [param: string]: any;
37
+ }, options?: URLOptions): string;