@adonisjs/http-server 8.0.0-next.1 → 8.0.0-next.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.
|
@@ -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,41 @@ 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
|
-
|
|
955
|
-
|
|
956
|
-
|
|
958
|
+
handler: {
|
|
959
|
+
method,
|
|
960
|
+
reference: handler,
|
|
961
|
+
importExpression: moduleRefId,
|
|
962
|
+
...moduleImporter(() => this.#app.import(moduleRefId), method).toHandleMethod(),
|
|
963
|
+
name: handler
|
|
964
|
+
},
|
|
965
|
+
routeName: `${new StringBuilder(moduleRefId.split("/").pop()).removeSuffix("controller").snakeCase()}.${string2.snakeCase(method)}`
|
|
957
966
|
};
|
|
958
967
|
}
|
|
959
968
|
if (Array.isArray(handler)) {
|
|
960
|
-
|
|
969
|
+
const controller = handler[0];
|
|
970
|
+
const method = handler[1] ?? "handle";
|
|
971
|
+
if (is.class(controller)) {
|
|
961
972
|
return {
|
|
962
|
-
|
|
963
|
-
|
|
973
|
+
handler: {
|
|
974
|
+
method,
|
|
975
|
+
reference: handler,
|
|
976
|
+
importExpression: null,
|
|
977
|
+
...moduleCaller(controller, method).toHandleMethod()
|
|
978
|
+
},
|
|
979
|
+
routeName: `${new StringBuilder(controller.name).removeSuffix("controller").snakeCase()}.${string2.snakeCase(method)}`
|
|
964
980
|
};
|
|
965
981
|
}
|
|
966
982
|
return {
|
|
967
|
-
|
|
968
|
-
|
|
983
|
+
handler: {
|
|
984
|
+
method,
|
|
985
|
+
reference: handler,
|
|
986
|
+
importExpression: String(controller),
|
|
987
|
+
...moduleImporter(controller, method).toHandleMethod()
|
|
988
|
+
},
|
|
989
|
+
routeName: `${new StringBuilder(controller.name).removeSuffix("controller").snakeCase()}.${string2.snakeCase(method)}`
|
|
969
990
|
};
|
|
970
991
|
}
|
|
971
|
-
return handler;
|
|
992
|
+
return { handler };
|
|
972
993
|
}
|
|
973
994
|
/**
|
|
974
995
|
* Returns an object of param matchers by merging global and local
|
|
@@ -4134,7 +4155,7 @@ var Router = class {
|
|
|
4134
4155
|
const routeNames = routeNamesByDomain.get(route.domain);
|
|
4135
4156
|
if (route.name && routeNames.has(route.name)) {
|
|
4136
4157
|
throw new RuntimeException5(
|
|
4137
|
-
`
|
|
4158
|
+
`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
4159
|
);
|
|
4139
4160
|
}
|
|
4140
4161
|
if (route.name) {
|
|
@@ -4151,33 +4172,19 @@ var Router = class {
|
|
|
4151
4172
|
this.#openedGroups = [];
|
|
4152
4173
|
this.#commited = true;
|
|
4153
4174
|
}
|
|
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
4175
|
/**
|
|
4168
4176
|
* Finds a route by its identifier. The identifier can be the
|
|
4169
4177
|
* route name, controller.method name or the route pattern
|
|
4170
4178
|
* itself.
|
|
4171
4179
|
*
|
|
4172
|
-
* When "
|
|
4173
|
-
*
|
|
4174
|
-
* method. The default lookupStrategy is "name" and "pattern".
|
|
4180
|
+
* When "disableLegacyLookup" is set, the lookup will be performed
|
|
4181
|
+
* only using the route name
|
|
4175
4182
|
*/
|
|
4176
|
-
find(routeIdentifier, domain, method,
|
|
4183
|
+
find(routeIdentifier, domain, method, disableLegacyLookup) {
|
|
4177
4184
|
if (!domain) {
|
|
4178
4185
|
let route = null;
|
|
4179
4186
|
for (const routeDomain of Object.keys(this.routes)) {
|
|
4180
|
-
route = this.find(routeIdentifier, routeDomain, method,
|
|
4187
|
+
route = this.find(routeIdentifier, routeDomain, method, disableLegacyLookup);
|
|
4181
4188
|
if (route) {
|
|
4182
4189
|
break;
|
|
4183
4190
|
}
|
|
@@ -4188,9 +4195,9 @@ var Router = class {
|
|
|
4188
4195
|
if (!routes) {
|
|
4189
4196
|
return null;
|
|
4190
4197
|
}
|
|
4191
|
-
const lookupByName =
|
|
4192
|
-
const lookupByPattern = !
|
|
4193
|
-
const lookupByController = !
|
|
4198
|
+
const lookupByName = true;
|
|
4199
|
+
const lookupByPattern = !disableLegacyLookup;
|
|
4200
|
+
const lookupByController = !disableLegacyLookup;
|
|
4194
4201
|
return routes.find((route) => {
|
|
4195
4202
|
if (method && !route.methods.includes(method)) {
|
|
4196
4203
|
return false;
|
|
@@ -4211,12 +4218,11 @@ var Router = class {
|
|
|
4211
4218
|
*
|
|
4212
4219
|
* An error is raised when unable to find the route.
|
|
4213
4220
|
*
|
|
4214
|
-
* When "
|
|
4215
|
-
*
|
|
4216
|
-
* method. The default lookupStrategy is "name" and "pattern".
|
|
4221
|
+
* When "disableLegacyLookup" is set, the lookup will be performed
|
|
4222
|
+
* only using the route name
|
|
4217
4223
|
*/
|
|
4218
|
-
findOrFail(routeIdentifier, domain, method,
|
|
4219
|
-
const route = this.find(routeIdentifier, domain, method,
|
|
4224
|
+
findOrFail(routeIdentifier, domain, method, disableLegacyLookup) {
|
|
4225
|
+
const route = this.find(routeIdentifier, domain, method, disableLegacyLookup);
|
|
4220
4226
|
if (!route) {
|
|
4221
4227
|
throw new Error(`Cannot lookup route "${routeIdentifier}"`);
|
|
4222
4228
|
}
|
|
@@ -4270,21 +4276,11 @@ var Router = class {
|
|
|
4270
4276
|
routesList["ALL"] = routesList["ALL"] ?? {};
|
|
4271
4277
|
routesList[method] = routesList[method] ?? {};
|
|
4272
4278
|
const identifiers = [];
|
|
4273
|
-
if (
|
|
4274
|
-
if (!routesList[method][route.pattern]) {
|
|
4275
|
-
identifiers.push(route.pattern);
|
|
4276
|
-
}
|
|
4277
|
-
}
|
|
4278
|
-
if (this.lookupStrategies.includes("name") && route.name) {
|
|
4279
|
+
if (route.name) {
|
|
4279
4280
|
identifiers.push(
|
|
4280
4281
|
domain && routesList[method][route.name] ? `${domain}@${route.name}` : route.name
|
|
4281
4282
|
);
|
|
4282
4283
|
}
|
|
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
4284
|
identifiers.forEach((identifier) => {
|
|
4289
4285
|
routesList["ALL"][identifier] = {
|
|
4290
4286
|
params,
|
|
@@ -4871,7 +4867,7 @@ var Server = class {
|
|
|
4871
4867
|
|
|
4872
4868
|
// src/define_config.ts
|
|
4873
4869
|
import proxyAddr from "proxy-addr";
|
|
4874
|
-
import
|
|
4870
|
+
import string3 from "@poppinss/utils/string";
|
|
4875
4871
|
import lodash2 from "@poppinss/utils/lodash";
|
|
4876
4872
|
function defineConfig(config) {
|
|
4877
4873
|
const { trustProxy: trustProxy2, ...rest } = config;
|
|
@@ -4911,7 +4907,7 @@ function defineConfig(config) {
|
|
|
4911
4907
|
};
|
|
4912
4908
|
const normalizedConfig = lodash2.merge({}, defaults, rest);
|
|
4913
4909
|
if (normalizedConfig.cookie.maxAge) {
|
|
4914
|
-
normalizedConfig.cookie.maxAge =
|
|
4910
|
+
normalizedConfig.cookie.maxAge = string3.seconds.parse(normalizedConfig.cookie.maxAge);
|
|
4915
4911
|
}
|
|
4916
4912
|
if (typeof trustProxy2 === "boolean") {
|
|
4917
4913
|
const tpValue = trustProxy2;
|
package/build/factories/main.js
CHANGED
package/build/index.js
CHANGED
|
@@ -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 "
|
|
161
|
-
*
|
|
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,
|
|
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 "
|
|
173
|
-
*
|
|
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,
|
|
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
|
|
@@ -35,6 +35,9 @@ export type RouteFn = (ctx: HttpContext) => any;
|
|
|
35
35
|
* Route handler persisted with the route store
|
|
36
36
|
*/
|
|
37
37
|
export type StoreRouteHandler = RouteFn | {
|
|
38
|
+
name?: string;
|
|
39
|
+
method: string;
|
|
40
|
+
importExpression: string | null;
|
|
38
41
|
reference: string | [LazyImport<Constructor<any>> | Constructor<any>, any?];
|
|
39
42
|
handle: (resolver: ContainerResolver<any>, ...args: [ctx: HttpContext, ...injections: any[]]) => any;
|
|
40
43
|
};
|
|
@@ -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<
|
|
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.
|
|
3
|
+
"version": "8.0.0-next.3",
|
|
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.
|
|
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.
|
|
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",
|