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