@adonisjs/http-server 7.0.0-0 → 7.0.0-2

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 (62) hide show
  1. package/build/{chunk-XX72ATFY.js → chunk-Z63E3STR.js} +66 -18
  2. package/build/chunk-Z63E3STR.js.map +1 -0
  3. package/build/factories/http_context.d.ts +25 -0
  4. package/build/factories/http_server.d.ts +8 -0
  5. package/build/factories/main.d.ts +6 -149
  6. package/build/factories/main.js +2 -1
  7. package/build/factories/main.js.map +1 -0
  8. package/build/factories/qs_parser_factory.d.ts +20 -0
  9. package/build/factories/request.d.ts +29 -0
  10. package/build/factories/response.d.ts +29 -0
  11. package/build/factories/router.d.ts +23 -0
  12. package/build/factories/server_factory.d.ts +29 -0
  13. package/build/index.d.ts +14 -272
  14. package/build/index.js +2 -1
  15. package/build/index.js.map +1 -0
  16. package/build/src/cookies/client.d.ts +37 -0
  17. package/build/src/cookies/drivers/encrypted.d.ts +16 -0
  18. package/build/src/cookies/drivers/plain.d.ts +15 -0
  19. package/build/src/cookies/drivers/signed.d.ts +16 -0
  20. package/build/src/cookies/parser.d.ts +37 -0
  21. package/build/src/cookies/serializer.d.ts +33 -0
  22. package/build/src/debug.d.ts +3 -0
  23. package/build/src/define_config.d.ts +9 -0
  24. package/build/src/define_middleware.d.ts +11 -0
  25. package/build/src/exception_handler.d.ts +113 -0
  26. package/build/src/exceptions.d.ts +84 -0
  27. package/build/src/helpers.d.ts +23 -0
  28. package/build/src/http_context/local_storage.d.ts +12 -0
  29. package/build/src/http_context/main.d.ts +58 -0
  30. package/build/src/qs.d.ts +11 -0
  31. package/build/src/redirect.d.ts +42 -0
  32. package/build/src/request.d.ts +565 -0
  33. package/build/src/response.d.ts +620 -0
  34. package/build/src/router/brisk.d.ts +42 -0
  35. package/build/src/router/executor.d.ts +9 -0
  36. package/build/src/router/factories/use_return_value.d.ts +6 -0
  37. package/build/src/router/group.d.ts +65 -0
  38. package/build/src/router/lookup_store/main.d.ts +47 -0
  39. package/build/src/router/lookup_store/route_finder.d.ts +25 -0
  40. package/build/src/router/lookup_store/url_builder.d.ts +52 -0
  41. package/build/src/router/main.d.ts +128 -0
  42. package/build/src/router/matchers.d.ts +27 -0
  43. package/build/src/router/parser.d.ts +5 -0
  44. package/build/src/router/resource.d.ts +66 -0
  45. package/build/src/router/route.d.ts +92 -0
  46. package/build/src/router/store.d.ts +66 -0
  47. package/build/src/server/factories/final_handler.d.ts +10 -0
  48. package/build/src/server/factories/middleware_handler.d.ts +8 -0
  49. package/build/src/server/factories/write_response.d.ts +6 -0
  50. package/build/{main-29eaaee4.d.ts → src/server/main.d.ts} +18 -13
  51. package/build/src/types/base.d.ts +19 -0
  52. package/build/src/types/main.d.ts +7 -14
  53. package/build/src/types/main.js +1 -0
  54. package/build/src/types/main.js.map +1 -0
  55. package/build/src/types/middleware.d.ts +35 -0
  56. package/build/src/types/qs.d.ts +68 -0
  57. package/build/src/types/request.d.ts +39 -0
  58. package/build/src/types/response.d.ts +45 -0
  59. package/build/src/types/route.d.ts +166 -0
  60. package/build/src/types/server.d.ts +72 -0
  61. package/package.json +52 -48
  62. package/build/main-e5b46c83.d.ts +0 -2210
@@ -279,10 +279,18 @@ var RouteResource = class extends Macroable2 {
279
279
  }
280
280
  tap(actions, callback) {
281
281
  if (typeof actions === "function") {
282
- this.routes.forEach((route) => actions(route));
282
+ this.routes.forEach((route) => {
283
+ if (!route.isDeleted()) {
284
+ actions(route);
285
+ }
286
+ });
283
287
  return this;
284
288
  }
285
- this.#filter(actions, false).forEach((route) => callback(route));
289
+ this.#filter(actions, false).forEach((route) => {
290
+ if (!route.isDeleted()) {
291
+ callback(route);
292
+ }
293
+ });
286
294
  return this;
287
295
  }
288
296
  /**
@@ -301,6 +309,27 @@ var RouteResource = class extends Macroable2 {
301
309
  });
302
310
  return this;
303
311
  }
312
+ /**
313
+ * Define one or more middleware on the routes created by
314
+ * the resource.
315
+ *
316
+ * Calling this method multiple times will append middleware
317
+ * to existing list.
318
+ */
319
+ use(actions, middleware) {
320
+ if (actions === "*") {
321
+ this.tap((route) => route.use(middleware));
322
+ } else {
323
+ this.tap(actions, (route) => route.use(middleware));
324
+ }
325
+ return this;
326
+ }
327
+ /**
328
+ * @alias use
329
+ */
330
+ middleware(actions, middleware) {
331
+ return this.use(actions, middleware);
332
+ }
304
333
  /**
305
334
  * Prepend name to all the routes
306
335
  */
@@ -3360,7 +3389,7 @@ var UrlBuilder = class {
3360
3389
  const tokens = parseRoutePattern(pattern);
3361
3390
  for (const token of tokens) {
3362
3391
  if (token.type === 0) {
3363
- uriSegments.push(`${token.val}${token.end}`);
3392
+ uriSegments.push(token.val === "/" ? "" : `${token.val}${token.end}`);
3364
3393
  } else if (token.type === 2) {
3365
3394
  const values = paramsArray ? paramsArray.slice(paramsIndex) : paramsObject["*"];
3366
3395
  this.#ensureHasWildCardValues(pattern, values);
@@ -3471,9 +3500,9 @@ var UrlBuilder = class {
3471
3500
 
3472
3501
  // src/router/lookup_store/route_finder.ts
3473
3502
  var RouteFinder = class {
3474
- #routes;
3475
- constructor(routes) {
3476
- this.#routes = routes;
3503
+ #routes = [];
3504
+ register(route) {
3505
+ this.#routes.push(route);
3477
3506
  }
3478
3507
  /**
3479
3508
  * Find a route by indentifier
@@ -3505,12 +3534,18 @@ var RouteFinder = class {
3505
3534
  has(routeIdentifier) {
3506
3535
  return !!this.find(routeIdentifier);
3507
3536
  }
3537
+ /**
3538
+ * Returns an array of registered routes
3539
+ */
3540
+ toJSON() {
3541
+ return this.#routes;
3542
+ }
3508
3543
  };
3509
3544
 
3510
3545
  // src/router/lookup_store/main.ts
3511
3546
  var LookupStore = class {
3512
3547
  /**
3513
- * List of routes grouped by domain
3548
+ * List of route finders grouped by domains
3514
3549
  */
3515
3550
  #routes = {};
3516
3551
  /**
@@ -3529,8 +3564,8 @@ var LookupStore = class {
3529
3564
  * Register route JSON payload
3530
3565
  */
3531
3566
  register(route) {
3532
- this.#routes[route.domain] = this.#routes[route.domain] || [];
3533
- this.#routes[route.domain].push(route);
3567
+ this.#routes[route.domain] = this.#routes[route.domain] || new RouteFinder();
3568
+ this.#routes[route.domain].register(route);
3534
3569
  }
3535
3570
  /**
3536
3571
  * Returns an instance of the URL builder for making
@@ -3544,8 +3579,8 @@ var LookupStore = class {
3544
3579
  * domain.
3545
3580
  */
3546
3581
  builderForDomain(domain) {
3547
- const routes = this.#routes[domain];
3548
- return new UrlBuilder(this.#encryption, new RouteFinder(routes || []), this.#qsParser);
3582
+ const finder = this.#routes[domain];
3583
+ return new UrlBuilder(this.#encryption, finder || new RouteFinder(), this.#qsParser);
3549
3584
  }
3550
3585
  /**
3551
3586
  * Finds a route by its identifier. The identifier can be the
@@ -3553,8 +3588,11 @@ var LookupStore = class {
3553
3588
  * itself.
3554
3589
  */
3555
3590
  find(routeIdentifier, domain) {
3556
- const routes = this.#routes[domain || "root"] || [];
3557
- return new RouteFinder(routes).find(routeIdentifier);
3591
+ const finder = this.#routes[domain || "root"];
3592
+ if (!finder) {
3593
+ return null;
3594
+ }
3595
+ return finder.find(routeIdentifier);
3558
3596
  }
3559
3597
  /**
3560
3598
  * Finds a route by its identifier. The identifier can be the
@@ -3564,8 +3602,11 @@ var LookupStore = class {
3564
3602
  * An error is raised when unable to find the route.
3565
3603
  */
3566
3604
  findOrFail(routeIdentifier, domain) {
3567
- const routes = this.#routes[domain || "root"] || [];
3568
- return new RouteFinder(routes).findOrFail(routeIdentifier);
3605
+ const finder = this.#routes[domain || "root"];
3606
+ if (!finder) {
3607
+ throw new E_CANNOT_LOOKUP_ROUTE([routeIdentifier]);
3608
+ }
3609
+ return finder.findOrFail(routeIdentifier);
3569
3610
  }
3570
3611
  /**
3571
3612
  * Check if a route exists. The identifier can be the
@@ -3573,11 +3614,17 @@ var LookupStore = class {
3573
3614
  * itself.
3574
3615
  */
3575
3616
  has(routeIdentifier, domain) {
3576
- const routes = this.#routes[domain || "root"] || [];
3577
- return new RouteFinder(routes).has(routeIdentifier);
3617
+ const finder = this.#routes[domain || "root"];
3618
+ if (!finder) {
3619
+ return false;
3620
+ }
3621
+ return finder.has(routeIdentifier);
3578
3622
  }
3579
3623
  toJSON() {
3580
- return this.#routes;
3624
+ return Object.keys(this.#routes).reduce((result, domain) => {
3625
+ result[domain] = this.#routes[domain].toJSON();
3626
+ return result;
3627
+ }, {});
3581
3628
  }
3582
3629
  };
3583
3630
 
@@ -4386,3 +4433,4 @@ export {
4386
4433
  Server,
4387
4434
  defineConfig
4388
4435
  };
4436
+ //# sourceMappingURL=chunk-Z63E3STR.js.map