@adonisjs/http-server 7.0.0-1 → 7.0.0-3

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 (65) hide show
  1. package/build/chunk-NC6OWANS.js +4437 -0
  2. package/build/chunk-NC6OWANS.js.map +1 -0
  3. package/build/factories/http_server.d.ts +1 -0
  4. package/build/factories/main.js +332 -14
  5. package/build/factories/main.js.map +1 -0
  6. package/build/index.js +309 -22
  7. package/build/index.js.map +1 -0
  8. package/build/src/define_middleware.d.ts +2 -1
  9. package/build/src/router/lookup_store/main.d.ts +1 -3
  10. package/build/src/router/lookup_store/route_finder.d.ts +5 -1
  11. package/build/src/router/main.d.ts +5 -4
  12. package/build/src/router/resource.d.ts +19 -7
  13. package/build/src/types/main.js +1 -15
  14. package/build/src/types/main.js.map +1 -0
  15. package/build/src/types/middleware.d.ts +3 -1
  16. package/package.json +60 -59
  17. package/build/factories/http_context.js +0 -51
  18. package/build/factories/http_server.js +0 -26
  19. package/build/factories/qs_parser_factory.js +0 -44
  20. package/build/factories/request.js +0 -73
  21. package/build/factories/response.js +0 -77
  22. package/build/factories/router.js +0 -45
  23. package/build/factories/server_factory.js +0 -65
  24. package/build/src/cookies/client.js +0 -84
  25. package/build/src/cookies/drivers/encrypted.js +0 -36
  26. package/build/src/cookies/drivers/plain.js +0 -33
  27. package/build/src/cookies/drivers/signed.js +0 -36
  28. package/build/src/cookies/parser.js +0 -167
  29. package/build/src/cookies/serializer.js +0 -79
  30. package/build/src/debug.js +0 -10
  31. package/build/src/define_config.js +0 -68
  32. package/build/src/define_middleware.js +0 -35
  33. package/build/src/exception_handler.js +0 -306
  34. package/build/src/exceptions.js +0 -38
  35. package/build/src/helpers.js +0 -105
  36. package/build/src/http_context/local_storage.js +0 -39
  37. package/build/src/http_context/main.js +0 -105
  38. package/build/src/qs.js +0 -25
  39. package/build/src/redirect.js +0 -140
  40. package/build/src/request.js +0 -865
  41. package/build/src/response.js +0 -1208
  42. package/build/src/router/brisk.js +0 -85
  43. package/build/src/router/executor.js +0 -30
  44. package/build/src/router/factories/use_return_value.js +0 -22
  45. package/build/src/router/group.js +0 -207
  46. package/build/src/router/lookup_store/main.js +0 -86
  47. package/build/src/router/lookup_store/route_finder.js +0 -49
  48. package/build/src/router/lookup_store/url_builder.js +0 -209
  49. package/build/src/router/main.js +0 -316
  50. package/build/src/router/matchers.js +0 -36
  51. package/build/src/router/parser.js +0 -17
  52. package/build/src/router/resource.js +0 -216
  53. package/build/src/router/route.js +0 -293
  54. package/build/src/router/store.js +0 -195
  55. package/build/src/server/factories/final_handler.js +0 -30
  56. package/build/src/server/factories/middleware_handler.js +0 -16
  57. package/build/src/server/factories/write_response.js +0 -24
  58. package/build/src/server/main.js +0 -292
  59. package/build/src/types/base.js +0 -9
  60. package/build/src/types/middleware.js +0 -9
  61. package/build/src/types/qs.js +0 -9
  62. package/build/src/types/request.js +0 -9
  63. package/build/src/types/response.js +0 -9
  64. package/build/src/types/route.js +0 -9
  65. package/build/src/types/server.js +0 -9
package/build/index.js CHANGED
@@ -1,22 +1,309 @@
1
- /*
2
- * @adonisjs/http-server
3
- *
4
- * (c) AdonisJS
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
- export { Request } from './src/request.js';
10
- export { Response } from './src/response.js';
11
- export { Redirect } from './src/redirect.js';
12
- export { Server } from './src/server/main.js';
13
- export { Router } from './src/router/main.js';
14
- export { Route } from './src/router/route.js';
15
- export * as errors from './src/exceptions.js';
16
- export { BriskRoute } from './src/router/brisk.js';
17
- export { RouteGroup } from './src/router/group.js';
18
- export { defineConfig } from './src/define_config.js';
19
- export { CookieClient } from './src/cookies/client.js';
20
- export { HttpContext } from './src/http_context/main.js';
21
- export { RouteResource } from './src/router/resource.js';
22
- export { ExceptionHandler } from './src/exception_handler.js';
1
+ import {
2
+ BriskRoute,
3
+ CookieClient,
4
+ E_CANNOT_LOOKUP_ROUTE,
5
+ E_HTTP_EXCEPTION,
6
+ E_HTTP_REQUEST_ABORTED,
7
+ E_ROUTE_NOT_FOUND,
8
+ HttpContext,
9
+ Redirect,
10
+ Request,
11
+ Response,
12
+ Route,
13
+ RouteGroup,
14
+ RouteResource,
15
+ Router,
16
+ Server,
17
+ defineConfig,
18
+ exceptions_exports,
19
+ parseRange
20
+ } from "./chunk-NC6OWANS.js";
21
+
22
+ // src/exception_handler.ts
23
+ import is from "@sindresorhus/is";
24
+ import Macroable from "@poppinss/macroable";
25
+ var ExceptionHandler = class extends Macroable {
26
+ /**
27
+ * Computed from the status pages property
28
+ */
29
+ #expandedStatusPages;
30
+ /**
31
+ * Whether or not to render debug info. When set to true, the errors
32
+ * will have the complete error stack.
33
+ */
34
+ debug = process.env.NODE_ENV !== "production";
35
+ /**
36
+ * Whether or not to render status pages. When set to true, the unhandled
37
+ * errors with matching status codes will be rendered using a status
38
+ * page.
39
+ */
40
+ renderStatusPages = process.env.NODE_ENV === "production";
41
+ /**
42
+ * A collection of error status code range and the view to render.
43
+ */
44
+ statusPages = {};
45
+ /**
46
+ * Enable/disable errors reporting
47
+ */
48
+ reportErrors = true;
49
+ /**
50
+ * An array of exception classes to ignore when
51
+ * reporting an error
52
+ */
53
+ ignoreExceptions = [
54
+ E_HTTP_EXCEPTION,
55
+ E_ROUTE_NOT_FOUND,
56
+ E_CANNOT_LOOKUP_ROUTE,
57
+ E_HTTP_REQUEST_ABORTED
58
+ ];
59
+ /**
60
+ * An array of HTTP status codes to ignore when reporting
61
+ * an error
62
+ */
63
+ ignoreStatuses = [400, 422, 401];
64
+ /**
65
+ * An array of error codes to ignore when reporting
66
+ * an error
67
+ */
68
+ ignoreCodes = [];
69
+ /**
70
+ * Expands status pages
71
+ */
72
+ #expandStatusPages() {
73
+ if (!this.#expandedStatusPages) {
74
+ this.#expandedStatusPages = Object.keys(this.statusPages).reduce(
75
+ (result, range) => {
76
+ const renderer = this.statusPages[range];
77
+ result = Object.assign(result, parseRange(range, renderer));
78
+ return result;
79
+ },
80
+ {}
81
+ );
82
+ }
83
+ return this.#expandedStatusPages;
84
+ }
85
+ /**
86
+ * Forcefully tweaking the type of the error object to
87
+ * have known properties.
88
+ */
89
+ #toHttpError(error) {
90
+ const httpError = is.object(error) ? error : new Error(String(error));
91
+ httpError.message = httpError.message || "Internal server error";
92
+ httpError.status = httpError.status || 500;
93
+ return httpError;
94
+ }
95
+ /**
96
+ * Error reporting context
97
+ */
98
+ context(ctx) {
99
+ const requestId = ctx.request.id();
100
+ return requestId ? {
101
+ "x-request-id": requestId
102
+ } : {};
103
+ }
104
+ /**
105
+ * Returns the log level for an error based upon the error
106
+ * status code.
107
+ */
108
+ getErrorLogLevel(error) {
109
+ if (error.status >= 500) {
110
+ return "error";
111
+ }
112
+ if (error.status >= 400) {
113
+ return "warn";
114
+ }
115
+ return "info";
116
+ }
117
+ /**
118
+ * A boolean to control if errors should be rendered with
119
+ * all the available debugging info.
120
+ */
121
+ isDebuggingEnabled(_) {
122
+ return this.debug;
123
+ }
124
+ /**
125
+ * Returns a boolean by checking if an error should be reported.
126
+ */
127
+ shouldReport(error) {
128
+ if (this.reportErrors === false) {
129
+ return false;
130
+ }
131
+ if (this.ignoreStatuses.includes(error.status)) {
132
+ return false;
133
+ }
134
+ if (error.code && this.ignoreCodes.includes(error.code)) {
135
+ return false;
136
+ }
137
+ if (this.ignoreExceptions.find((exception) => error instanceof exception)) {
138
+ return false;
139
+ }
140
+ return true;
141
+ }
142
+ /**
143
+ * Renders an error to JSON response
144
+ */
145
+ async renderErrorAsJSON(error, ctx) {
146
+ if (this.isDebuggingEnabled(ctx)) {
147
+ const { default: Youch } = await import("youch");
148
+ const json = await new Youch(error, ctx.request.request).toJSON();
149
+ ctx.response.status(error.status).send(json.error);
150
+ return;
151
+ }
152
+ ctx.response.status(error.status).send({ message: error.message });
153
+ }
154
+ /**
155
+ * Renders an error to JSON API response
156
+ */
157
+ async renderErrorAsJSONAPI(error, ctx) {
158
+ if (this.isDebuggingEnabled(ctx)) {
159
+ const { default: Youch } = await import("youch");
160
+ const json = await new Youch(error, ctx.request.request).toJSON();
161
+ ctx.response.status(error.status).send(json.error);
162
+ return;
163
+ }
164
+ ctx.response.status(error.status).send({
165
+ errors: [
166
+ {
167
+ title: error.message,
168
+ code: error.code,
169
+ status: error.status
170
+ }
171
+ ]
172
+ });
173
+ }
174
+ /**
175
+ * Renders an error to HTML response
176
+ */
177
+ async renderErrorAsHTML(error, ctx) {
178
+ if (this.isDebuggingEnabled(ctx)) {
179
+ const { default: Youch } = await import("youch");
180
+ const html = await new Youch(error, ctx.request.request).toHTML({
181
+ cspNonce: "nonce" in ctx.response ? ctx.response.nonce : void 0
182
+ });
183
+ ctx.response.status(error.status).send(html);
184
+ return;
185
+ }
186
+ ctx.response.status(error.status).send(`<p> ${error.message} </p>`);
187
+ }
188
+ /**
189
+ * Renders the validation error message to a JSON
190
+ * response
191
+ */
192
+ async renderValidationErrorAsJSON(error, ctx) {
193
+ ctx.response.status(error.status).send({
194
+ errors: error.messages
195
+ });
196
+ }
197
+ /**
198
+ * Renders the validation error message as per JSON API
199
+ * spec
200
+ */
201
+ async renderValidationErrorAsJSONAPI(error, ctx) {
202
+ ctx.response.status(error.status).send({
203
+ errors: error.messages.map((message) => {
204
+ return {
205
+ title: message.message,
206
+ code: message.rule,
207
+ source: {
208
+ pointer: message.field
209
+ },
210
+ meta: message.meta
211
+ };
212
+ })
213
+ });
214
+ }
215
+ /**
216
+ * Renders the validation error as an HTML string
217
+ */
218
+ async renderValidationErrorAsHTML(error, ctx) {
219
+ ctx.response.status(error.status).type("html").send(
220
+ error.messages.map((message) => {
221
+ return `${message.field} - ${message.message}`;
222
+ }).join("<br />")
223
+ );
224
+ }
225
+ /**
226
+ * Renders the error to response
227
+ */
228
+ renderError(error, ctx) {
229
+ switch (ctx.request.accepts(["html", "application/vnd.api+json", "json"])) {
230
+ case "application/vnd.api+json":
231
+ return this.renderErrorAsJSONAPI(error, ctx);
232
+ case "json":
233
+ return this.renderErrorAsJSON(error, ctx);
234
+ case "html":
235
+ default:
236
+ return this.renderErrorAsHTML(error, ctx);
237
+ }
238
+ }
239
+ /**
240
+ * Renders the validation error to response
241
+ */
242
+ renderValidationError(error, ctx) {
243
+ switch (ctx.request.accepts(["html", "application/vnd.api+json", "json"])) {
244
+ case "application/vnd.api+json":
245
+ return this.renderValidationErrorAsJSONAPI(error, ctx);
246
+ case "json":
247
+ return this.renderValidationErrorAsJSON(error, ctx);
248
+ case "html":
249
+ default:
250
+ return this.renderValidationErrorAsHTML(error, ctx);
251
+ }
252
+ }
253
+ /**
254
+ * Reports an error during an HTTP request
255
+ */
256
+ async report(error, ctx) {
257
+ const httpError = this.#toHttpError(error);
258
+ if (!this.shouldReport(httpError)) {
259
+ return;
260
+ }
261
+ if (typeof httpError.report === "function") {
262
+ httpError.report(httpError, ctx);
263
+ return;
264
+ }
265
+ const level = this.getErrorLogLevel(httpError);
266
+ ctx.logger.log(
267
+ level,
268
+ {
269
+ ...level === "error" || level === "fatal" ? { err: httpError } : {},
270
+ ...this.context(ctx)
271
+ },
272
+ httpError.message
273
+ );
274
+ }
275
+ /**
276
+ * Handles the error during the HTTP request.
277
+ */
278
+ async handle(error, ctx) {
279
+ const httpError = this.#toHttpError(error);
280
+ if (typeof httpError.handle === "function") {
281
+ return httpError.handle(httpError, ctx);
282
+ }
283
+ if (httpError.code === "E_VALIDATION_ERROR" && "messages" in httpError) {
284
+ return this.renderValidationError(httpError, ctx);
285
+ }
286
+ const statusPages = this.#expandStatusPages();
287
+ if (this.renderStatusPages && statusPages[httpError.status]) {
288
+ return statusPages[httpError.status](httpError, ctx);
289
+ }
290
+ return this.renderError(httpError, ctx);
291
+ }
292
+ };
293
+ export {
294
+ BriskRoute,
295
+ CookieClient,
296
+ ExceptionHandler,
297
+ HttpContext,
298
+ Redirect,
299
+ Request,
300
+ Response,
301
+ Route,
302
+ RouteGroup,
303
+ RouteResource,
304
+ Router,
305
+ Server,
306
+ defineConfig,
307
+ exceptions_exports as errors
308
+ };
309
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/exception_handler.ts"],"sourcesContent":["/*\n * @adonisjs/http-server\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport is from '@sindresorhus/is'\nimport Macroable from '@poppinss/macroable'\nimport type { Level } from '@adonisjs/logger/types'\n\nimport { parseRange } from './helpers.js'\nimport * as errors from './exceptions.js'\nimport type { HttpContext } from './http_context/main.js'\nimport type { HttpError, StatusPageRange, StatusPageRenderer } from './types/server.js'\n\n/**\n * The base HTTP exception handler one can inherit from to handle\n * HTTP exceptions.\n *\n * The HTTP exception handler has support for\n *\n * - Ability to render exceptions by calling the render method on the exception.\n * - Rendering status pages\n * - Pretty printing errors during development\n * - Transforming errors to JSON or HTML using content negotiation\n * - Reporting errors\n */\nexport class ExceptionHandler extends Macroable {\n /**\n * Computed from the status pages property\n */\n #expandedStatusPages?: Record<number, StatusPageRenderer>\n\n /**\n * Whether or not to render debug info. When set to true, the errors\n * will have the complete error stack.\n */\n protected debug: boolean = process.env.NODE_ENV !== 'production'\n\n /**\n * Whether or not to render status pages. When set to true, the unhandled\n * errors with matching status codes will be rendered using a status\n * page.\n */\n protected renderStatusPages: boolean = process.env.NODE_ENV === 'production'\n\n /**\n * A collection of error status code range and the view to render.\n */\n protected statusPages: Record<StatusPageRange, StatusPageRenderer> = {}\n\n /**\n * Enable/disable errors reporting\n */\n protected reportErrors: boolean = true\n\n /**\n * An array of exception classes to ignore when\n * reporting an error\n */\n protected ignoreExceptions: any[] = [\n errors.E_HTTP_EXCEPTION,\n errors.E_ROUTE_NOT_FOUND,\n errors.E_CANNOT_LOOKUP_ROUTE,\n errors.E_HTTP_REQUEST_ABORTED,\n ]\n\n /**\n * An array of HTTP status codes to ignore when reporting\n * an error\n */\n protected ignoreStatuses: number[] = [400, 422, 401]\n\n /**\n * An array of error codes to ignore when reporting\n * an error\n */\n protected ignoreCodes: string[] = []\n\n /**\n * Expands status pages\n */\n #expandStatusPages() {\n if (!this.#expandedStatusPages) {\n this.#expandedStatusPages = Object.keys(this.statusPages).reduce(\n (result, range) => {\n const renderer = this.statusPages[range as StatusPageRange]\n result = Object.assign(result, parseRange(range, renderer))\n return result\n },\n {} as Record<number, StatusPageRenderer>\n )\n }\n\n return this.#expandedStatusPages\n }\n\n /**\n * Forcefully tweaking the type of the error object to\n * have known properties.\n */\n #toHttpError(error: unknown): HttpError {\n const httpError: any = is.object(error) ? error : new Error(String(error))\n httpError.message = httpError.message || 'Internal server error'\n httpError.status = httpError.status || 500\n return httpError\n }\n\n /**\n * Error reporting context\n */\n protected context(ctx: HttpContext): any {\n const requestId = ctx.request.id()\n return requestId\n ? {\n 'x-request-id': requestId,\n }\n : {}\n }\n\n /**\n * Returns the log level for an error based upon the error\n * status code.\n */\n protected getErrorLogLevel(error: HttpError): Level {\n if (error.status >= 500) {\n return 'error'\n }\n\n if (error.status >= 400) {\n return 'warn'\n }\n\n return 'info'\n }\n\n /**\n * A boolean to control if errors should be rendered with\n * all the available debugging info.\n */\n protected isDebuggingEnabled(_: HttpContext): boolean {\n return this.debug\n }\n\n /**\n * Returns a boolean by checking if an error should be reported.\n */\n protected shouldReport(error: HttpError): boolean {\n if (this.reportErrors === false) {\n return false\n }\n\n if (this.ignoreStatuses.includes(error.status)) {\n return false\n }\n\n if (error.code && this.ignoreCodes.includes(error.code)) {\n return false\n }\n\n if (this.ignoreExceptions.find((exception) => error instanceof exception)) {\n return false\n }\n\n return true\n }\n\n /**\n * Renders an error to JSON response\n */\n async renderErrorAsJSON(error: HttpError, ctx: HttpContext) {\n if (this.isDebuggingEnabled(ctx)) {\n const { default: Youch } = await import('youch')\n const json = await new Youch(error, ctx.request.request).toJSON()\n ctx.response.status(error.status).send(json.error)\n return\n }\n\n ctx.response.status(error.status).send({ message: error.message })\n }\n\n /**\n * Renders an error to JSON API response\n */\n async renderErrorAsJSONAPI(error: HttpError, ctx: HttpContext) {\n if (this.isDebuggingEnabled(ctx)) {\n const { default: Youch } = await import('youch')\n const json = await new Youch(error, ctx.request.request).toJSON()\n ctx.response.status(error.status).send(json.error)\n return\n }\n\n ctx.response.status(error.status).send({\n errors: [\n {\n title: error.message,\n code: error.code,\n status: error.status,\n },\n ],\n })\n }\n\n /**\n * Renders an error to HTML response\n */\n async renderErrorAsHTML(error: HttpError, ctx: HttpContext) {\n if (this.isDebuggingEnabled(ctx)) {\n const { default: Youch } = await import('youch')\n const html = await new Youch(error, ctx.request.request).toHTML({\n cspNonce: 'nonce' in ctx.response ? ctx.response.nonce : undefined,\n })\n ctx.response.status(error.status).send(html)\n return\n }\n\n ctx.response.status(error.status).send(`<p> ${error.message} </p>`)\n }\n\n /**\n * Renders the validation error message to a JSON\n * response\n */\n async renderValidationErrorAsJSON(error: HttpError, ctx: HttpContext) {\n ctx.response.status(error.status).send({\n errors: error.messages,\n })\n }\n\n /**\n * Renders the validation error message as per JSON API\n * spec\n */\n async renderValidationErrorAsJSONAPI(error: HttpError, ctx: HttpContext) {\n ctx.response.status(error.status).send({\n errors: error.messages.map((message: any) => {\n return {\n title: message.message,\n code: message.rule,\n source: {\n pointer: message.field,\n },\n meta: message.meta,\n }\n }),\n })\n }\n\n /**\n * Renders the validation error as an HTML string\n */\n async renderValidationErrorAsHTML(error: HttpError, ctx: HttpContext) {\n ctx.response\n .status(error.status)\n .type('html')\n .send(\n error.messages\n .map((message: any) => {\n return `${message.field} - ${message.message}`\n })\n .join('<br />')\n )\n }\n\n /**\n * Renders the error to response\n */\n renderError(error: HttpError, ctx: HttpContext) {\n switch (ctx.request.accepts(['html', 'application/vnd.api+json', 'json'])) {\n case 'application/vnd.api+json':\n return this.renderErrorAsJSONAPI(error, ctx)\n case 'json':\n return this.renderErrorAsJSON(error, ctx)\n case 'html':\n default:\n return this.renderErrorAsHTML(error, ctx)\n }\n }\n\n /**\n * Renders the validation error to response\n */\n renderValidationError(error: HttpError, ctx: HttpContext) {\n switch (ctx.request.accepts(['html', 'application/vnd.api+json', 'json'])) {\n case 'application/vnd.api+json':\n return this.renderValidationErrorAsJSONAPI(error, ctx)\n case 'json':\n return this.renderValidationErrorAsJSON(error, ctx)\n case 'html':\n default:\n return this.renderValidationErrorAsHTML(error, ctx)\n }\n }\n\n /**\n * Reports an error during an HTTP request\n */\n async report(error: unknown, ctx: HttpContext) {\n const httpError = this.#toHttpError(error)\n if (!this.shouldReport(httpError)) {\n return\n }\n\n if (typeof httpError.report === 'function') {\n httpError.report(httpError, ctx)\n return\n }\n\n /**\n * Log the error using the logger\n */\n const level = this.getErrorLogLevel(httpError)\n ctx.logger.log(\n level,\n {\n ...(level === 'error' || level === 'fatal' ? { err: httpError } : {}),\n ...this.context(ctx),\n },\n httpError.message\n )\n }\n\n /**\n * Handles the error during the HTTP request.\n */\n async handle(error: unknown, ctx: HttpContext) {\n const httpError = this.#toHttpError(error)\n\n /**\n * Self handle exception\n */\n if (typeof httpError.handle === 'function') {\n return httpError.handle(httpError, ctx)\n }\n\n /**\n * Handle validation error using the validation error\n * renderers\n */\n if (httpError.code === 'E_VALIDATION_ERROR' && 'messages' in httpError) {\n return this.renderValidationError(httpError, ctx)\n }\n\n /**\n * Render status page\n */\n const statusPages = this.#expandStatusPages()\n if (this.renderStatusPages && statusPages[httpError.status]) {\n return statusPages[httpError.status](httpError, ctx)\n }\n\n /**\n * Use the format renderers.\n */\n return this.renderError(httpError, ctx)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AASA,OAAO,QAAQ;AACf,OAAO,eAAe;AAoBf,IAAM,mBAAN,cAA+B,UAAU;AAAA;AAAA;AAAA;AAAA,EAI9C;AAAA;AAAA;AAAA;AAAA;AAAA,EAMU,QAAiB,QAAQ,IAAI,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAO1C,oBAA6B,QAAQ,IAAI,aAAa;AAAA;AAAA;AAAA;AAAA,EAKtD,cAA2D,CAAC;AAAA;AAAA;AAAA;AAAA,E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AM,YAAY,KAAK,aAAa,KAAK;AAKzC,QAAI,OAAO,UAAU,WAAW,YAAY;AAC1C,aAAO,UAAU,OAAO,WAAW,GAAG;AAAA,IACxC;AAMA,QAAI,UAAU,SAAS,wBAAwB,cAAc,WAAW;AACtE,aAAO,KAAK,sBAAsB,WAAW,GAAG;AAAA,IAClD;AAKA,UAAM,cAAc,KAAK,mBAAmB;AAC5C,QAAI,KAAK,qBAAqB,YAAY,UAAU,MAAM,GAAG;AAC3D,aAAO,YAAY,UAAU,MAAM,EAAE,WAAW,GAAG;AAAA,IACrD;AAKA,WAAO,KAAK,YAAY,WAAW,GAAG;AAAA,EACxC;AACF;","names":[]}
@@ -8,4 +8,5 @@ import type { GetMiddlewareArgs, MiddlewareAsClass, ParsedGlobalMiddleware } fro
8
8
  export declare function defineNamedMiddleware<NamedMiddleware extends Record<string | number | symbol, LazyImport<MiddlewareAsClass>>>(collection: NamedMiddleware): { [K in keyof NamedMiddleware]: <Args extends GetMiddlewareArgs<UnWrapLazyImport<NamedMiddleware[K]>>>(...args: Args) => {
9
9
  name: K;
10
10
  args: Args[0];
11
- } & ParsedGlobalMiddleware; };
11
+ handle: ParsedGlobalMiddleware['handle'];
12
+ }; };
@@ -43,7 +43,5 @@ export declare class LookupStore {
43
43
  * itself.
44
44
  */
45
45
  has(routeIdentifier: string, domain?: string): boolean;
46
- toJSON(): {
47
- [domain: string]: RouteJSON[];
48
- };
46
+ toJSON(): Record<string, RouteJSON[]>;
49
47
  }
@@ -5,7 +5,7 @@ import type { RouteJSON } from '../../types/route.js';
5
5
  */
6
6
  export declare class RouteFinder {
7
7
  #private;
8
- constructor(routes: RouteJSON[]);
8
+ register(route: RouteJSON): void;
9
9
  /**
10
10
  * Find a route by indentifier
11
11
  */
@@ -18,4 +18,8 @@ export declare class RouteFinder {
18
18
  * Find if a route exists
19
19
  */
20
20
  has(routeIdentifier: string): boolean;
21
+ /**
22
+ * Returns an array of registered routes
23
+ */
24
+ toJSON(): RouteJSON[];
21
25
  }
@@ -8,7 +8,7 @@ import { RouteResource } from './resource.js';
8
8
  import { LookupStore } from './lookup_store/main.js';
9
9
  import { RouteMatchers as Matchers } from './matchers.js';
10
10
  import type { Constructor, LazyImport } from '../types/base.js';
11
- import type { MiddlewareAsClass, ParsedGlobalMiddleware } from '../types/middleware.js';
11
+ import type { MiddlewareAsClass } from '../types/middleware.js';
12
12
  import type { RouteFn, MatchedRoute, RouteMatcher, RouteMatchers, MakeUrlOptions, MakeSignedUrlOptions, GetControllerHandlers } from '../types/route.js';
13
13
  /**
14
14
  * Router class exposes a unified API to register new routes, group them or
@@ -57,7 +57,8 @@ export declare class Router extends LookupStore {
57
57
  named<NamedMiddleware extends Record<string, LazyImport<MiddlewareAsClass>>>(collection: NamedMiddleware): { [K in keyof NamedMiddleware]: <Args extends import("../types/middleware.js").GetMiddlewareArgs<import("../types/base.js").UnWrapLazyImport<NamedMiddleware[K]>>>(...args: Args) => {
58
58
  name: K;
59
59
  args: Args[0];
60
- } & ParsedGlobalMiddleware; };
60
+ handle: (resolver: import("@adonisjs/fold").ContainerResolver<any>, ctx: import("../http_context/main.js").HttpContext, next: import("@poppinss/middleware/types").NextFn, params?: any) => any;
61
+ }; };
61
62
  /**
62
63
  * Add route for a given pattern and methods
63
64
  */
@@ -94,11 +95,11 @@ export declare class Router extends LookupStore {
94
95
  /**
95
96
  * Registers a route resource with conventional set of routes
96
97
  */
97
- resource(resource: string, controller: string | LazyImport<Constructor<any>> | Constructor<any>): RouteResource;
98
+ resource(resource: string, controller: string | LazyImport<Constructor<any>> | Constructor<any>): RouteResource<import("../types/route.js").ResourceActionNames>;
98
99
  /**
99
100
  * Register a route resource with shallow nested routes.
100
101
  */
101
- shallowResource(resource: string, controller: string | LazyImport<Constructor<any>> | Constructor<any>): RouteResource;
102
+ shallowResource(resource: string, controller: string | LazyImport<Constructor<any>> | Constructor<any>): RouteResource<import("../types/route.js").ResourceActionNames>;
102
103
  /**
103
104
  * Returns a brisk route instance for a given URL pattern
104
105
  */
@@ -1,13 +1,13 @@
1
1
  import Macroable from '@poppinss/macroable';
2
2
  import type { Application } from '@adonisjs/application';
3
3
  import { Route } from './route.js';
4
- import type { Constructor, LazyImport } from '../types/base.js';
5
- import type { ParsedGlobalMiddleware } from '../types/middleware.js';
4
+ import type { Constructor, LazyImport, OneOrMore } from '../types/base.js';
5
+ import type { MiddlewareFn, ParsedGlobalMiddleware, ParsedNamedMiddleware } from '../types/middleware.js';
6
6
  import type { ResourceActionNames, RouteMatcher, RouteMatchers } from '../types/route.js';
7
7
  /**
8
8
  * Route resource exposes the API to register multiple routes for a resource.
9
9
  */
10
- export declare class RouteResource extends Macroable {
10
+ export declare class RouteResource<ActionNames extends ResourceActionNames = ResourceActionNames> extends Macroable {
11
11
  #private;
12
12
  /**
13
13
  * A collection of routes instances that belongs to this resource
@@ -22,16 +22,16 @@ export declare class RouteResource extends Macroable {
22
22
  /**
23
23
  * Register only given routes and remove others
24
24
  */
25
- only(names: ResourceActionNames[]): this;
25
+ only<Name extends ActionNames>(names: Name[]): RouteResource<Name>;
26
26
  /**
27
27
  * Register all routes, except the one's defined
28
28
  */
29
- except(names: ResourceActionNames[]): this;
29
+ except<Name extends ActionNames>(names: Name[]): RouteResource<Exclude<ActionNames, Name>>;
30
30
  /**
31
31
  * Register api only routes. The `create` and `edit` routes, which
32
32
  * are meant to show forms will not be registered
33
33
  */
34
- apiOnly(): this;
34
+ apiOnly(): RouteResource<Exclude<ActionNames, 'create' | 'edit'>>;
35
35
  /**
36
36
  * Define matcher for params inside the resource
37
37
  */
@@ -40,13 +40,25 @@ export declare class RouteResource extends Macroable {
40
40
  * Tap into multiple routes to configure them by their name
41
41
  */
42
42
  tap(callback: (route: Route) => void): this;
43
- tap(actions: ResourceActionNames | ResourceActionNames[], callback: (route: Route) => void): this;
43
+ tap(actions: ActionNames | ActionNames[], callback: (route: Route) => void): this;
44
44
  /**
45
45
  * Set the param name for a given resource
46
46
  */
47
47
  params(resources: {
48
48
  [resource: string]: string;
49
49
  }): this;
50
+ /**
51
+ * Define one or more middleware on the routes created by
52
+ * the resource.
53
+ *
54
+ * Calling this method multiple times will append middleware
55
+ * to existing list.
56
+ */
57
+ use(actions: ActionNames | ActionNames[] | '*', middleware: OneOrMore<MiddlewareFn | ParsedNamedMiddleware>): this;
58
+ /**
59
+ * @alias use
60
+ */
61
+ middleware(actions: ActionNames | ActionNames[] | '*', middleware: OneOrMore<MiddlewareFn | ParsedNamedMiddleware>): this;
50
62
  /**
51
63
  * Prepend name to all the routes
52
64
  */
@@ -1,15 +1 @@
1
- /*
2
- * @adonisjs/http-server
3
- *
4
- * (c) AdonisJS
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
- export * from './base.js';
10
- export * from './middleware.js';
11
- export * from './qs.js';
12
- export * from './request.js';
13
- export * from './response.js';
14
- export * from './route.js';
15
- export * from './server.js';
1
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -23,13 +23,15 @@ export type MiddlewareFn = (ctx: HttpContext, next: NextFn) => any;
23
23
  * Parsed global middleware
24
24
  */
25
25
  export type ParsedGlobalMiddleware = {
26
+ name?: string;
26
27
  handle: (resolver: ContainerResolver<any>, ...args: [ctx: HttpContext, next: NextFn, params?: any]) => any;
27
28
  };
28
29
  /**
29
30
  * Parsed named middleware
30
31
  */
31
- export type ParsedNamedMiddleware = ParsedGlobalMiddleware & {
32
+ export type ParsedNamedMiddleware = {
32
33
  name: string;
34
+ handle: ParsedGlobalMiddleware['handle'];
33
35
  args: any;
34
36
  };
35
37
  export {};