@adonisjs/http-server 8.0.0-next.1 → 8.0.0-next.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.
@@ -876,6 +876,8 @@ function safeDecodeURI(path, useSemicolonDelimiter) {
876
876
  }
877
877
 
878
878
  // src/router/route.ts
879
+ import StringBuilder from "@poppinss/utils/string_builder";
880
+ import string2 from "@poppinss/utils/string";
879
881
  var Route = class extends Macroable4 {
880
882
  /**
881
883
  * Route pattern
@@ -938,8 +940,10 @@ var Route = class extends Macroable4 {
938
940
  this.#routerMiddleware = routerMiddleware;
939
941
  this.#pattern = options.pattern;
940
942
  this.#methods = options.methods;
941
- this.#handler = this.#resolveRouteHandle(options.handler);
942
943
  this.#globalMatchers = options.globalMatchers;
944
+ const { handler, routeName } = this.#resolveRouteHandle(options.handler);
945
+ this.#handler = handler;
946
+ this.#name = routeName;
943
947
  }
944
948
  /**
945
949
  * Resolves the route handler string expression to a
@@ -951,24 +955,35 @@ var Route = class extends Macroable4 {
951
955
  const method = parts.length === 1 ? "handle" : parts.pop();
952
956
  const moduleRefId = parts.join(".");
953
957
  return {
954
- reference: handler,
955
- ...moduleImporter(() => this.#app.import(moduleRefId), method).toHandleMethod(),
956
- name: handler
958
+ handler: {
959
+ reference: handler,
960
+ ...moduleImporter(() => this.#app.import(moduleRefId), method).toHandleMethod(),
961
+ name: handler
962
+ },
963
+ routeName: `${new StringBuilder(moduleRefId.split("/").pop()).removeSuffix("controller").snakeCase()}.${string2.snakeCase(method)}`
957
964
  };
958
965
  }
959
966
  if (Array.isArray(handler)) {
960
- if (is.class(handler[0])) {
967
+ const controller = handler[0];
968
+ const method = handler[1] ?? "handle";
969
+ if (is.class(controller)) {
961
970
  return {
962
- reference: handler,
963
- ...moduleCaller(handler[0], handler[1] || "handle").toHandleMethod()
971
+ handler: {
972
+ reference: handler,
973
+ ...moduleCaller(controller, method).toHandleMethod()
974
+ },
975
+ routeName: `${new StringBuilder(controller.name).removeSuffix("controller").snakeCase()}.${string2.snakeCase(method)}`
964
976
  };
965
977
  }
966
978
  return {
967
- reference: handler,
968
- ...moduleImporter(handler[0], handler[1] || "handle").toHandleMethod()
979
+ handler: {
980
+ reference: handler,
981
+ ...moduleImporter(controller, method).toHandleMethod()
982
+ },
983
+ routeName: `${new StringBuilder(controller.name).removeSuffix("controller").snakeCase()}.${string2.snakeCase(method)}`
969
984
  };
970
985
  }
971
- return handler;
986
+ return { handler };
972
987
  }
973
988
  /**
974
989
  * Returns an object of param matchers by merging global and local
@@ -4134,7 +4149,7 @@ var Router = class {
4134
4149
  const routeNames = routeNamesByDomain.get(route.domain);
4135
4150
  if (route.name && routeNames.has(route.name)) {
4136
4151
  throw new RuntimeException5(
4137
- `Route with duplicate name found. A route with name "${route.name}" already exists`
4152
+ `A route with name "${route.name}" already exists. It may happen when two routes use the same controller, so make sure to give explicit names to these routes`
4138
4153
  );
4139
4154
  }
4140
4155
  if (route.name) {
@@ -4151,33 +4166,19 @@ var Router = class {
4151
4166
  this.#openedGroups = [];
4152
4167
  this.#commited = true;
4153
4168
  }
4154
- /**
4155
- * The lookup strategies to follow when generating URL builder
4156
- * types and client
4157
- */
4158
- lookupStrategies = ["name", "pattern"];
4159
- /**
4160
- * Define the lookup strategies to follow when generating URL builder
4161
- * types and client.
4162
- */
4163
- updateLookupStrategies(strategies) {
4164
- this.lookupStrategies = strategies;
4165
- return this;
4166
- }
4167
4169
  /**
4168
4170
  * Finds a route by its identifier. The identifier can be the
4169
4171
  * route name, controller.method name or the route pattern
4170
4172
  * itself.
4171
4173
  *
4172
- * When "followLookupStrategy" is enabled, the lookup will be performed
4173
- * on the basis of the lookup strategy enabled via the "lookupStrategies"
4174
- * method. The default lookupStrategy is "name" and "pattern".
4174
+ * When "disableLegacyLookup" is set, the lookup will be performed
4175
+ * only using the route name
4175
4176
  */
4176
- find(routeIdentifier, domain, method, followLookupStrategy) {
4177
+ find(routeIdentifier, domain, method, disableLegacyLookup) {
4177
4178
  if (!domain) {
4178
4179
  let route = null;
4179
4180
  for (const routeDomain of Object.keys(this.routes)) {
4180
- route = this.find(routeIdentifier, routeDomain, method, followLookupStrategy);
4181
+ route = this.find(routeIdentifier, routeDomain, method, disableLegacyLookup);
4181
4182
  if (route) {
4182
4183
  break;
4183
4184
  }
@@ -4188,9 +4189,9 @@ var Router = class {
4188
4189
  if (!routes) {
4189
4190
  return null;
4190
4191
  }
4191
- const lookupByName = !followLookupStrategy || this.lookupStrategies.includes("name");
4192
- const lookupByPattern = !followLookupStrategy || this.lookupStrategies.includes("pattern");
4193
- const lookupByController = !followLookupStrategy || this.lookupStrategies.includes("controller");
4192
+ const lookupByName = true;
4193
+ const lookupByPattern = !disableLegacyLookup;
4194
+ const lookupByController = !disableLegacyLookup;
4194
4195
  return routes.find((route) => {
4195
4196
  if (method && !route.methods.includes(method)) {
4196
4197
  return false;
@@ -4211,12 +4212,11 @@ var Router = class {
4211
4212
  *
4212
4213
  * An error is raised when unable to find the route.
4213
4214
  *
4214
- * When "followLookupStrategy" is enabled, the lookup will be performed
4215
- * on the basis of the lookup strategy enabled via the "lookupStrategies"
4216
- * method. The default lookupStrategy is "name" and "pattern".
4215
+ * When "disableLegacyLookup" is set, the lookup will be performed
4216
+ * only using the route name
4217
4217
  */
4218
- findOrFail(routeIdentifier, domain, method, followLookupStrategy) {
4219
- const route = this.find(routeIdentifier, domain, method, followLookupStrategy);
4218
+ findOrFail(routeIdentifier, domain, method, disableLegacyLookup) {
4219
+ const route = this.find(routeIdentifier, domain, method, disableLegacyLookup);
4220
4220
  if (!route) {
4221
4221
  throw new Error(`Cannot lookup route "${routeIdentifier}"`);
4222
4222
  }
@@ -4270,21 +4270,11 @@ var Router = class {
4270
4270
  routesList["ALL"] = routesList["ALL"] ?? {};
4271
4271
  routesList[method] = routesList[method] ?? {};
4272
4272
  const identifiers = [];
4273
- if (this.lookupStrategies.includes("pattern")) {
4274
- if (!routesList[method][route.pattern]) {
4275
- identifiers.push(route.pattern);
4276
- }
4277
- }
4278
- if (this.lookupStrategies.includes("name") && route.name) {
4273
+ if (route.name) {
4279
4274
  identifiers.push(
4280
4275
  domain && routesList[method][route.name] ? `${domain}@${route.name}` : route.name
4281
4276
  );
4282
4277
  }
4283
- if (this.lookupStrategies.includes("controller") && "reference" in route.handler && typeof route.handler.reference === "string") {
4284
- identifiers.push(
4285
- domain && routesList[method][route.handler.reference] ? `${domain}@${route.handler.reference}` : route.handler.reference
4286
- );
4287
- }
4288
4278
  identifiers.forEach((identifier) => {
4289
4279
  routesList["ALL"][identifier] = {
4290
4280
  params,
@@ -4871,7 +4861,7 @@ var Server = class {
4871
4861
 
4872
4862
  // src/define_config.ts
4873
4863
  import proxyAddr from "proxy-addr";
4874
- import string2 from "@poppinss/utils/string";
4864
+ import string3 from "@poppinss/utils/string";
4875
4865
  import lodash2 from "@poppinss/utils/lodash";
4876
4866
  function defineConfig(config) {
4877
4867
  const { trustProxy: trustProxy2, ...rest } = config;
@@ -4911,7 +4901,7 @@ function defineConfig(config) {
4911
4901
  };
4912
4902
  const normalizedConfig = lodash2.merge({}, defaults, rest);
4913
4903
  if (normalizedConfig.cookie.maxAge) {
4914
- normalizedConfig.cookie.maxAge = string2.seconds.parse(normalizedConfig.cookie.maxAge);
4904
+ normalizedConfig.cookie.maxAge = string3.seconds.parse(normalizedConfig.cookie.maxAge);
4915
4905
  }
4916
4906
  if (typeof trustProxy2 === "boolean") {
4917
4907
  const tpValue = trustProxy2;
@@ -6,7 +6,7 @@ import {
6
6
  Router,
7
7
  Server,
8
8
  defineConfig
9
- } from "../chunk-HMYAZG76.js";
9
+ } from "../chunk-Z5EN426L.js";
10
10
  import "../chunk-ASX56VAK.js";
11
11
 
12
12
  // factories/router.ts
package/build/index.js CHANGED
@@ -20,7 +20,7 @@ import {
20
20
  errors_exports,
21
21
  parseRange,
22
22
  tracing_channels_exports
23
- } from "./chunk-HMYAZG76.js";
23
+ } from "./chunk-Z5EN426L.js";
24
24
  import "./chunk-ASX56VAK.js";
25
25
 
26
26
  // src/exception_handler.ts
@@ -142,26 +142,15 @@ export declare class Router {
142
142
  * commit method is called.
143
143
  */
144
144
  commit(): void;
145
- /**
146
- * The lookup strategies to follow when generating URL builder
147
- * types and client
148
- */
149
- lookupStrategies: ('name' | 'pattern' | 'controller')[];
150
- /**
151
- * Define the lookup strategies to follow when generating URL builder
152
- * types and client.
153
- */
154
- updateLookupStrategies(strategies: ('name' | 'pattern' | 'controller')[]): this;
155
145
  /**
156
146
  * Finds a route by its identifier. The identifier can be the
157
147
  * route name, controller.method name or the route pattern
158
148
  * itself.
159
149
  *
160
- * When "followLookupStrategy" is enabled, the lookup will be performed
161
- * on the basis of the lookup strategy enabled via the "lookupStrategies"
162
- * method. The default lookupStrategy is "name" and "pattern".
150
+ * When "disableLegacyLookup" is set, the lookup will be performed
151
+ * only using the route name
163
152
  */
164
- find(routeIdentifier: string, domain?: string, method?: string, followLookupStrategy?: boolean): RouteJSON | null;
153
+ find(routeIdentifier: string, domain?: string, method?: string, disableLegacyLookup?: boolean): RouteJSON | null;
165
154
  /**
166
155
  * Finds a route by its identifier. The identifier can be the
167
156
  * route name, controller.method name or the route pattern
@@ -169,11 +158,10 @@ export declare class Router {
169
158
  *
170
159
  * An error is raised when unable to find the route.
171
160
  *
172
- * When "followLookupStrategy" is enabled, the lookup will be performed
173
- * on the basis of the lookup strategy enabled via the "lookupStrategies"
174
- * method. The default lookupStrategy is "name" and "pattern".
161
+ * When "disableLegacyLookup" is set, the lookup will be performed
162
+ * only using the route name
175
163
  */
176
- findOrFail(routeIdentifier: string, domain?: string, method?: string, followLookupStrategy?: boolean): RouteJSON;
164
+ findOrFail(routeIdentifier: string, domain?: string, method?: string, disableLegacyLookup?: boolean): RouteJSON;
177
165
  /**
178
166
  * Check if a route exists. The identifier can be the
179
167
  * route name, controller.method name or the route pattern
@@ -19,7 +19,7 @@ export type SignedURLOptions = URLOptions & {
19
19
  /**
20
20
  * Returns params for a route identifier
21
21
  */
22
- export type RouteBuilderArguments<Routes, Method extends keyof Routes, Identifier extends keyof Routes[Method], Options extends any = URLOptions> = Routes extends LookupList ? Prettify<undefined extends Routes[Method][Identifier]['params'] ? [identifier: Identifier, params?: undefined, options?: Options] : [undefined] extends [Routes[Method][Identifier]['params']] ? [
22
+ export type RouteBuilderArguments<Routes, Method extends keyof Routes, Identifier extends keyof Routes[Method], Options extends any = URLOptions> = Routes extends LookupList ? Prettify<Routes[Method][Identifier]['params'] extends undefined ? [identifier: Identifier, params?: undefined, options?: Options] : [undefined] extends [Routes[Method][Identifier]['params']] ? [
23
23
  identifier: Identifier,
24
24
  params?: Routes[Method][Identifier]['params'] | Routes[Method][Identifier]['paramsTuple'],
25
25
  options?: Options
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adonisjs/http-server",
3
- "version": "8.0.0-next.1",
3
+ "version": "8.0.0-next.2",
4
4
  "description": "AdonisJS HTTP server with support packed with Routing and Cookies",
5
5
  "main": "build/index.js",
6
6
  "type": "module",
@@ -65,7 +65,7 @@
65
65
  "@types/fresh": "^0.5.3",
66
66
  "@types/fs-extra": "^11.0.4",
67
67
  "@types/mime-types": "^3.0.1",
68
- "@types/node": "^24.2.1",
68
+ "@types/node": "^24.3.0",
69
69
  "@types/on-finished": "^2.3.5",
70
70
  "@types/pem": "^1.14.4",
71
71
  "@types/proxy-addr": "^2.0.3",
@@ -77,7 +77,7 @@
77
77
  "autocannon": "^8.0.0",
78
78
  "c8": "^10.1.3",
79
79
  "cross-env": "^10.0.0",
80
- "eslint": "^9.33.0",
80
+ "eslint": "^9.34.0",
81
81
  "fastify": "^5.5.0",
82
82
  "fs-extra": "^11.3.1",
83
83
  "get-port": "^7.1.0",