@adonisjs/http-server 8.1.0 → 8.1.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.
- package/build/define_config-BRmlbWlB.js +2452 -0
- package/build/factories/main.js +5 -163
- package/build/{helpers-XD4_pfkD.js → helpers-C_2HouOe.js} +0 -56
- package/build/index.js +4 -179
- package/build/src/client/url_builder.js +2 -14
- package/build/src/helpers.js +75 -3
- package/build/src/server/main.d.ts +1 -1
- package/build/src/types/main.js +0 -1
- package/build/src/types/server.d.ts +10 -0
- package/build/types-AUwURgIL.js +1 -0
- package/build/utils-BjSHKI3s.js +618 -0
- package/package.json +2 -2
- package/build/chunk-B2GA45YG.js +0 -35
- package/build/define_config-t7GL92UR.js +0 -5470
- package/build/helpers-aa47NQc6.js +0 -1426
package/build/factories/main.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import "../
|
|
2
|
-
import { _ as Qs, c as HttpRequest, i as HttpResponse, n as Server, r as HttpContext, s as Router, t as defineConfig } from "../define_config-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import "../utils-BjSHKI3s.js";
|
|
2
|
+
import { _ as Qs, c as HttpRequest, i as HttpResponse, n as Server, r as HttpContext, s as Router, t as defineConfig } from "../define_config-BRmlbWlB.js";
|
|
3
|
+
import { t as createURL } from "../helpers-C_2HouOe.js";
|
|
4
|
+
import { parseRoute } from "../src/helpers.js";
|
|
5
|
+
import "../types-AUwURgIL.js";
|
|
5
6
|
import { Container } from "@adonisjs/fold";
|
|
6
7
|
import { Socket } from "node:net";
|
|
7
8
|
import proxyAddr from "proxy-addr";
|
|
@@ -13,15 +14,7 @@ import { IncomingMessage, ServerResponse } from "node:http";
|
|
|
13
14
|
import { Logger } from "@adonisjs/logger";
|
|
14
15
|
import { Emitter } from "@adonisjs/events";
|
|
15
16
|
import { LoggerFactory } from "@adonisjs/logger/factories";
|
|
16
|
-
//#region factories/qs_parser_factory.ts
|
|
17
|
-
/**
|
|
18
|
-
* QS Parser factory is used to generate the query string
|
|
19
|
-
* parser for testing
|
|
20
|
-
*/
|
|
21
17
|
var QsParserFactory = class {
|
|
22
|
-
/**
|
|
23
|
-
* Default configuration options for the QS parser
|
|
24
|
-
*/
|
|
25
18
|
#options = {
|
|
26
19
|
parse: {
|
|
27
20
|
depth: 5,
|
|
@@ -37,75 +30,33 @@ var QsParserFactory = class {
|
|
|
37
30
|
skipNulls: false
|
|
38
31
|
}
|
|
39
32
|
};
|
|
40
|
-
/**
|
|
41
|
-
* Merge QS parser factory options
|
|
42
|
-
* @param options - Partial options to merge with existing configuration
|
|
43
|
-
*/
|
|
44
33
|
merge(options) {
|
|
45
34
|
Object.assign(this.#options.parse, options.parse);
|
|
46
35
|
Object.assign(this.#options.stringify, options.stringify);
|
|
47
36
|
return this;
|
|
48
37
|
}
|
|
49
|
-
/**
|
|
50
|
-
* Create instance of the QS parser class
|
|
51
|
-
*/
|
|
52
38
|
create() {
|
|
53
39
|
return new Qs(this.#options);
|
|
54
40
|
}
|
|
55
41
|
};
|
|
56
|
-
//#endregion
|
|
57
|
-
//#region factories/router.ts
|
|
58
|
-
/**
|
|
59
|
-
* Router factory is used to generate router class instances for
|
|
60
|
-
* testing
|
|
61
|
-
*/
|
|
62
42
|
var RouterFactory = class {
|
|
63
|
-
/**
|
|
64
|
-
* Factory parameters for creating router instances
|
|
65
|
-
*/
|
|
66
43
|
#parameters = {};
|
|
67
|
-
/**
|
|
68
|
-
* Returns an instance of the application class
|
|
69
|
-
*/
|
|
70
44
|
#getApp() {
|
|
71
45
|
return this.#parameters.app || new AppFactory().create(new URL("./app/", import.meta.url));
|
|
72
46
|
}
|
|
73
|
-
/**
|
|
74
|
-
* Returns an instance of the encryptor to encrypt
|
|
75
|
-
* signed URLs
|
|
76
|
-
*/
|
|
77
47
|
#createEncryption() {
|
|
78
48
|
return this.#parameters.encryption || new EncryptionFactory().create();
|
|
79
49
|
}
|
|
80
|
-
/**
|
|
81
|
-
* Merge factory params
|
|
82
|
-
* @param params - Partial factory parameters to merge
|
|
83
|
-
*/
|
|
84
50
|
merge(params) {
|
|
85
51
|
Object.assign(this.#parameters, params);
|
|
86
52
|
return this;
|
|
87
53
|
}
|
|
88
|
-
/**
|
|
89
|
-
* Create router instance
|
|
90
|
-
*/
|
|
91
54
|
create() {
|
|
92
55
|
return new Router(this.#getApp(), this.#createEncryption(), new QsParserFactory().create());
|
|
93
56
|
}
|
|
94
57
|
};
|
|
95
|
-
//#endregion
|
|
96
|
-
//#region factories/request.ts
|
|
97
|
-
/**
|
|
98
|
-
* Request factory is used to generate request class instances for
|
|
99
|
-
* testing
|
|
100
|
-
*/
|
|
101
58
|
var HttpRequestFactory = class {
|
|
102
|
-
/**
|
|
103
|
-
* Factory parameters for creating request instances
|
|
104
|
-
*/
|
|
105
59
|
#parameters = {};
|
|
106
|
-
/**
|
|
107
|
-
* Returns the config for the request class
|
|
108
|
-
*/
|
|
109
60
|
#getConfig() {
|
|
110
61
|
return {
|
|
111
62
|
allowMethodSpoofing: false,
|
|
@@ -118,59 +69,29 @@ var HttpRequestFactory = class {
|
|
|
118
69
|
...this.#parameters.config
|
|
119
70
|
};
|
|
120
71
|
}
|
|
121
|
-
/**
|
|
122
|
-
* Returns the HTTP req object
|
|
123
|
-
*/
|
|
124
72
|
#createRequest() {
|
|
125
73
|
const req = this.#parameters.req || new IncomingMessage(new Socket());
|
|
126
74
|
if (this.#parameters.url) req.url = this.#parameters.url;
|
|
127
75
|
if (this.#parameters.method) req.method = this.#parameters.method;
|
|
128
76
|
return req;
|
|
129
77
|
}
|
|
130
|
-
/**
|
|
131
|
-
* Returns the HTTP res object
|
|
132
|
-
* @param req - The incoming message request object
|
|
133
|
-
*/
|
|
134
78
|
#createResponse(req) {
|
|
135
79
|
return this.#parameters.res || new ServerResponse(req);
|
|
136
80
|
}
|
|
137
|
-
/**
|
|
138
|
-
* Returns an instance of the encryptor to encrypt
|
|
139
|
-
* signed URLs
|
|
140
|
-
*/
|
|
141
81
|
#createEncryption() {
|
|
142
82
|
return this.#parameters.encryption || new EncryptionFactory().create();
|
|
143
83
|
}
|
|
144
|
-
/**
|
|
145
|
-
* Merge factory params
|
|
146
|
-
* @param params - Partial factory parameters to merge
|
|
147
|
-
*/
|
|
148
84
|
merge(params) {
|
|
149
85
|
Object.assign(this.#parameters, params);
|
|
150
86
|
return this;
|
|
151
87
|
}
|
|
152
|
-
/**
|
|
153
|
-
* Create request
|
|
154
|
-
*/
|
|
155
88
|
create() {
|
|
156
89
|
const req = this.#createRequest();
|
|
157
90
|
return new HttpRequest(req, this.#createResponse(req), this.#createEncryption(), this.#getConfig(), new QsParserFactory().create());
|
|
158
91
|
}
|
|
159
92
|
};
|
|
160
|
-
//#endregion
|
|
161
|
-
//#region factories/response.ts
|
|
162
|
-
/**
|
|
163
|
-
* Response factory is used to generate response class instances for
|
|
164
|
-
* testing
|
|
165
|
-
*/
|
|
166
93
|
var HttpResponseFactory = class {
|
|
167
|
-
/**
|
|
168
|
-
* Factory parameters for creating response instances
|
|
169
|
-
*/
|
|
170
94
|
#parameters = {};
|
|
171
|
-
/**
|
|
172
|
-
* Returns the config for the request class
|
|
173
|
-
*/
|
|
174
95
|
#getConfig() {
|
|
175
96
|
return {
|
|
176
97
|
etag: false,
|
|
@@ -186,119 +107,54 @@ var HttpResponseFactory = class {
|
|
|
186
107
|
...this.#parameters.config
|
|
187
108
|
};
|
|
188
109
|
}
|
|
189
|
-
/**
|
|
190
|
-
* Returns the HTTP req object
|
|
191
|
-
*/
|
|
192
110
|
#createRequest() {
|
|
193
111
|
return this.#parameters.req || new IncomingMessage(new Socket());
|
|
194
112
|
}
|
|
195
|
-
/**
|
|
196
|
-
* Returns an instance of the router
|
|
197
|
-
*/
|
|
198
113
|
#createRouter() {
|
|
199
114
|
return this.#parameters.router || new RouterFactory().create();
|
|
200
115
|
}
|
|
201
|
-
/**
|
|
202
|
-
* Returns the HTTP res object
|
|
203
|
-
* @param req - The incoming message request object
|
|
204
|
-
*/
|
|
205
116
|
#createResponse(req) {
|
|
206
117
|
return this.#parameters.res || new ServerResponse(req);
|
|
207
118
|
}
|
|
208
|
-
/**
|
|
209
|
-
* Returns an instance of the encryptor to encrypt
|
|
210
|
-
* signed URLs
|
|
211
|
-
*/
|
|
212
119
|
#createEncryption() {
|
|
213
120
|
return this.#parameters.encryption || new EncryptionFactory().create();
|
|
214
121
|
}
|
|
215
|
-
/**
|
|
216
|
-
* Merge factory params
|
|
217
|
-
* @param params - Partial factory parameters to merge
|
|
218
|
-
*/
|
|
219
122
|
merge(params) {
|
|
220
123
|
Object.assign(this.#parameters, params);
|
|
221
124
|
return this;
|
|
222
125
|
}
|
|
223
|
-
/**
|
|
224
|
-
* Create response class instance
|
|
225
|
-
*/
|
|
226
126
|
create() {
|
|
227
127
|
const req = this.#createRequest();
|
|
228
128
|
return new HttpResponse(req, this.#createResponse(req), this.#createEncryption(), this.#getConfig(), this.#createRouter(), new QsParserFactory().create());
|
|
229
129
|
}
|
|
230
130
|
};
|
|
231
|
-
//#endregion
|
|
232
|
-
//#region factories/server_factory.ts
|
|
233
|
-
/**
|
|
234
|
-
* Server factory is used to generate server class instances for
|
|
235
|
-
* testing
|
|
236
|
-
*/
|
|
237
131
|
var ServerFactory = class {
|
|
238
|
-
/**
|
|
239
|
-
* Factory parameters for creating server instances
|
|
240
|
-
*/
|
|
241
132
|
#parameters = {};
|
|
242
|
-
/**
|
|
243
|
-
* Returns the emitter instance
|
|
244
|
-
*/
|
|
245
133
|
#getEmitter() {
|
|
246
134
|
return this.#parameters.emitter || new Emitter(this.#getApp());
|
|
247
135
|
}
|
|
248
|
-
/**
|
|
249
|
-
* Returns the logger instance
|
|
250
|
-
*/
|
|
251
136
|
#getLogger() {
|
|
252
137
|
return this.#parameters.logger || new Logger({ enabled: false });
|
|
253
138
|
}
|
|
254
|
-
/**
|
|
255
|
-
* Returns the config for the server class
|
|
256
|
-
*/
|
|
257
139
|
#getConfig() {
|
|
258
140
|
return defineConfig(this.#parameters.config || {});
|
|
259
141
|
}
|
|
260
|
-
/**
|
|
261
|
-
* Returns an instance of the application class
|
|
262
|
-
*/
|
|
263
142
|
#getApp() {
|
|
264
143
|
return this.#parameters.app || new AppFactory().create(new URL("./app/", import.meta.url));
|
|
265
144
|
}
|
|
266
|
-
/**
|
|
267
|
-
* Returns an instance of the encryptor to encrypt
|
|
268
|
-
* signed URLs
|
|
269
|
-
*/
|
|
270
145
|
#createEncryption() {
|
|
271
146
|
return this.#parameters.encryption || new EncryptionFactory().create();
|
|
272
147
|
}
|
|
273
|
-
/**
|
|
274
|
-
* Merge factory params
|
|
275
|
-
* @param params - Partial factory parameters to merge
|
|
276
|
-
*/
|
|
277
148
|
merge(params) {
|
|
278
149
|
Object.assign(this.#parameters, params);
|
|
279
150
|
return this;
|
|
280
151
|
}
|
|
281
|
-
/**
|
|
282
|
-
* Create server instance
|
|
283
|
-
*/
|
|
284
152
|
create() {
|
|
285
153
|
return new Server(this.#getApp(), this.#createEncryption(), this.#getEmitter(), this.#getLogger(), this.#getConfig());
|
|
286
154
|
}
|
|
287
155
|
};
|
|
288
|
-
//#endregion
|
|
289
|
-
//#region factories/http_context.ts
|
|
290
|
-
/**
|
|
291
|
-
* HttpContext factory is used to generate Http context class instances for
|
|
292
|
-
* testing
|
|
293
|
-
*/
|
|
294
156
|
var HttpContextFactory = class {
|
|
295
|
-
/**
|
|
296
|
-
* Factory parameters for creating HTTP context instances
|
|
297
|
-
*/
|
|
298
157
|
#parameters = {};
|
|
299
|
-
/**
|
|
300
|
-
* Returns the request class instance
|
|
301
|
-
*/
|
|
302
158
|
#createRequest() {
|
|
303
159
|
if (this.#parameters.request) return this.#parameters.request;
|
|
304
160
|
let { url, method, route } = this.#parameters;
|
|
@@ -308,32 +164,18 @@ var HttpContextFactory = class {
|
|
|
308
164
|
method
|
|
309
165
|
}).create();
|
|
310
166
|
}
|
|
311
|
-
/**
|
|
312
|
-
* Returns the response class instance
|
|
313
|
-
*/
|
|
314
167
|
#createResponse() {
|
|
315
168
|
return this.#parameters.response || new HttpResponseFactory().create();
|
|
316
169
|
}
|
|
317
|
-
/**
|
|
318
|
-
* Returns an instance of the logger class
|
|
319
|
-
*/
|
|
320
170
|
#createLogger() {
|
|
321
171
|
return this.#parameters.logger || new LoggerFactory().create();
|
|
322
172
|
}
|
|
323
|
-
/**
|
|
324
|
-
* Merge factory params
|
|
325
|
-
* @param params - Partial factory parameters to merge
|
|
326
|
-
*/
|
|
327
173
|
merge(params) {
|
|
328
174
|
Object.assign(this.#parameters, params);
|
|
329
175
|
return this;
|
|
330
176
|
}
|
|
331
|
-
/**
|
|
332
|
-
* Create HTTP context instance
|
|
333
|
-
*/
|
|
334
177
|
create() {
|
|
335
178
|
return new HttpContext(this.#createRequest(), this.#createResponse(), this.#createLogger(), new Container().createResolver());
|
|
336
179
|
}
|
|
337
180
|
};
|
|
338
|
-
//#endregion
|
|
339
181
|
export { HttpContextFactory, QsParserFactory, HttpRequestFactory as RequestFactory, HttpResponseFactory as ResponseFactory, RouterFactory, ServerFactory };
|
|
@@ -1,28 +1,4 @@
|
|
|
1
|
-
//#region src/client/helpers.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
1
|
function findRoute(domainsRoutes, routeIdentifier, domain, method, disableLegacyLookup) {
|
|
22
|
-
/**
|
|
23
|
-
* Search for route in all the domains when no domain name is
|
|
24
|
-
* mentioned.
|
|
25
|
-
*/
|
|
26
2
|
if (!domain) {
|
|
27
3
|
let route = null;
|
|
28
4
|
for (const routeDomain of Object.keys(domainsRoutes)) {
|
|
@@ -33,10 +9,6 @@ function findRoute(domainsRoutes, routeIdentifier, domain, method, disableLegacy
|
|
|
33
9
|
}
|
|
34
10
|
const routes = domainsRoutes[domain];
|
|
35
11
|
if (!routes) return null;
|
|
36
|
-
/**
|
|
37
|
-
* Pattern and controller are supported for legacy reasons. However
|
|
38
|
-
* the URL builder only works with names
|
|
39
|
-
*/
|
|
40
12
|
const lookupByPattern = !disableLegacyLookup;
|
|
41
13
|
const lookupByController = !disableLegacyLookup;
|
|
42
14
|
return routes.find((route) => {
|
|
@@ -46,34 +18,16 @@ function findRoute(domainsRoutes, routeIdentifier, domain, method, disableLegacy
|
|
|
46
18
|
return false;
|
|
47
19
|
}) || null;
|
|
48
20
|
}
|
|
49
|
-
/**
|
|
50
|
-
* Makes URL for a given route pattern using its parsed tokens. The
|
|
51
|
-
* tokens could be generated using the "parseRoute" method.
|
|
52
|
-
*
|
|
53
|
-
* @param pattern - The route pattern
|
|
54
|
-
* @param tokens - Array of parsed route tokens
|
|
55
|
-
* @param searchParamsStringifier - Function to stringify query parameters
|
|
56
|
-
* @param params - Route parameters as array or object
|
|
57
|
-
* @param options - URL options
|
|
58
|
-
* @returns {string} The generated URL
|
|
59
|
-
*/
|
|
60
21
|
function createURL(pattern, tokens, searchParamsStringifier, params, options) {
|
|
61
22
|
const uriSegments = [];
|
|
62
23
|
const paramsArray = Array.isArray(params) ? params : null;
|
|
63
24
|
const paramsObject = !Array.isArray(params) ? params ?? {} : {};
|
|
64
25
|
let paramsIndex = 0;
|
|
65
26
|
for (const token of tokens) {
|
|
66
|
-
/**
|
|
67
|
-
* Static param
|
|
68
|
-
*/
|
|
69
27
|
if (token.type === 0) {
|
|
70
28
|
uriSegments.push(token.val === "/" ? "" : `${token.val}${token.end}`);
|
|
71
29
|
continue;
|
|
72
30
|
}
|
|
73
|
-
/**
|
|
74
|
-
* Wildcard param. It will always be the last param, hence we will provide
|
|
75
|
-
* it all the remaining values
|
|
76
|
-
*/
|
|
77
31
|
if (token.type === 2) {
|
|
78
32
|
const values = paramsArray ? paramsArray.slice(paramsIndex) : paramsObject["*"];
|
|
79
33
|
if (!Array.isArray(values) || !values.length) throw new Error(`Cannot make URL for "${pattern}". Invalid value provided for the wildcard param`);
|
|
@@ -83,26 +37,16 @@ function createURL(pattern, tokens, searchParamsStringifier, params, options) {
|
|
|
83
37
|
const paramName = token.val;
|
|
84
38
|
const value = paramsArray ? paramsArray[paramsIndex] : paramsObject[paramName];
|
|
85
39
|
const isDefined = value !== void 0 && value !== null;
|
|
86
|
-
/**
|
|
87
|
-
* Required param
|
|
88
|
-
*/
|
|
89
40
|
if (token.type === 1 && !isDefined) throw new Error(`Cannot make URL for "${pattern}". Missing value for the "${paramName}" param`);
|
|
90
41
|
if (isDefined) uriSegments.push(`${value}${token.end}`);
|
|
91
42
|
paramsIndex++;
|
|
92
43
|
}
|
|
93
44
|
let URI = `/${uriSegments.join("/")}`;
|
|
94
|
-
/**
|
|
95
|
-
* Prefix base URL
|
|
96
|
-
*/
|
|
97
45
|
if (options?.prefixUrl) URI = `${options?.prefixUrl.replace(/\/$/, "")}${URI}`;
|
|
98
|
-
/**
|
|
99
|
-
* Append query string
|
|
100
|
-
*/
|
|
101
46
|
if (options?.qs) {
|
|
102
47
|
const queryString = searchParamsStringifier(options?.qs);
|
|
103
48
|
URI = queryString ? `${URI}?${queryString}` : URI;
|
|
104
49
|
}
|
|
105
50
|
return URI;
|
|
106
51
|
}
|
|
107
|
-
//#endregion
|
|
108
52
|
export { findRoute as n, createURL as t };
|