@adonisjs/http-server 8.0.0-next.9 → 8.1.0

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 (50) hide show
  1. package/build/chunk-B2GA45YG.js +35 -0
  2. package/build/define_config-t7GL92UR.js +5470 -0
  3. package/build/factories/http_context.d.ts +10 -4
  4. package/build/factories/main.d.ts +2 -2
  5. package/build/factories/main.js +328 -345
  6. package/build/factories/request.d.ts +4 -4
  7. package/build/factories/response.d.ts +4 -4
  8. package/build/factories/router.d.ts +1 -1
  9. package/build/factories/server_factory.d.ts +1 -1
  10. package/build/factories/url_builder_factory.d.ts +3 -3
  11. package/build/helpers-XD4_pfkD.js +108 -0
  12. package/build/helpers-aa47NQc6.js +1426 -0
  13. package/build/index.d.ts +2 -2
  14. package/build/index.js +330 -373
  15. package/build/src/client/helpers.d.ts +37 -0
  16. package/build/src/client/types.d.ts +194 -0
  17. package/build/src/client/url_builder.d.ts +15 -0
  18. package/build/src/client/url_builder.js +131 -0
  19. package/build/src/cookies/client.d.ts +28 -5
  20. package/build/src/cookies/drivers/encrypted.d.ts +1 -1
  21. package/build/src/cookies/drivers/signed.d.ts +1 -1
  22. package/build/src/cookies/parser.d.ts +1 -1
  23. package/build/src/cookies/serializer.d.ts +2 -2
  24. package/build/src/debug.d.ts +14 -1
  25. package/build/src/define_config.d.ts +19 -1
  26. package/build/src/define_middleware.d.ts +19 -3
  27. package/build/src/errors.d.ts +60 -5
  28. package/build/src/exception_handler.d.ts +28 -8
  29. package/build/src/helpers.d.ts +5 -17
  30. package/build/src/helpers.js +4 -24
  31. package/build/src/http_context/main.d.ts +67 -17
  32. package/build/src/qs.d.ts +17 -3
  33. package/build/src/redirect.d.ts +22 -3
  34. package/build/src/request.d.ts +12 -5
  35. package/build/src/response.d.ts +5 -5
  36. package/build/src/response_status.d.ts +14 -0
  37. package/build/src/router/main.d.ts +6 -2
  38. package/build/src/router/route.d.ts +130 -32
  39. package/build/src/router/signed_url_builder.d.ts +1 -1
  40. package/build/src/server/main.d.ts +6 -6
  41. package/build/src/types/main.js +2 -0
  42. package/build/src/types/request.d.ts +2 -1
  43. package/build/src/types/response.d.ts +6 -1
  44. package/build/src/types/route.d.ts +3 -27
  45. package/build/src/types/url_builder.d.ts +2 -140
  46. package/build/src/utils.d.ts +71 -6
  47. package/package.json +57 -48
  48. package/build/chunk-CVZAIRWJ.js +0 -1222
  49. package/build/chunk-JD6QW4NQ.js +0 -4428
  50. package/build/src/router/url_builder.d.ts +0 -9
@@ -1,356 +1,339 @@
1
- import {
2
- HttpContext,
3
- Qs,
4
- Request,
5
- Response,
6
- Router,
7
- Server,
8
- defineConfig
9
- } from "../chunk-JD6QW4NQ.js";
10
- import "../chunk-CVZAIRWJ.js";
11
-
12
- // factories/router.ts
1
+ import "../chunk-B2GA45YG.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-t7GL92UR.js";
3
+ import { s as parseRoute } from "../helpers-aa47NQc6.js";
4
+ import { t as createURL } from "../helpers-XD4_pfkD.js";
5
+ import { Container } from "@adonisjs/fold";
6
+ import { Socket } from "node:net";
7
+ import proxyAddr from "proxy-addr";
8
+ import { safeStringify } from "@poppinss/utils/json";
13
9
  import { AppFactory } from "@adonisjs/application/factories";
14
- import { EncryptionFactory } from "@adonisjs/encryption/factories";
15
-
16
- // factories/qs_parser_factory.ts
10
+ import { EncryptionFactory } from "@boringnode/encryption/factories";
11
+ import { randomUUID } from "node:crypto";
12
+ import { IncomingMessage, ServerResponse } from "node:http";
13
+ import { Logger } from "@adonisjs/logger";
14
+ import { Emitter } from "@adonisjs/events";
15
+ 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
+ */
17
21
  var QsParserFactory = class {
18
- /**
19
- * Default configuration options for the QS parser
20
- */
21
- #options = {
22
- parse: {
23
- depth: 5,
24
- parameterLimit: 1e3,
25
- allowSparse: false,
26
- arrayLimit: 20,
27
- comma: true
28
- },
29
- stringify: {
30
- encode: true,
31
- encodeValuesOnly: false,
32
- arrayFormat: "indices",
33
- skipNulls: false
34
- }
35
- };
36
- /**
37
- * Merge QS parser factory options
38
- * @param options - Partial options to merge with existing configuration
39
- */
40
- merge(options) {
41
- Object.assign(this.#options.parse, options.parse);
42
- Object.assign(this.#options.stringify, options.stringify);
43
- return this;
44
- }
45
- /**
46
- * Create instance of the QS parser class
47
- */
48
- create() {
49
- return new Qs(this.#options);
50
- }
22
+ /**
23
+ * Default configuration options for the QS parser
24
+ */
25
+ #options = {
26
+ parse: {
27
+ depth: 5,
28
+ parameterLimit: 1e3,
29
+ allowSparse: false,
30
+ arrayLimit: 20,
31
+ comma: true
32
+ },
33
+ stringify: {
34
+ encode: true,
35
+ encodeValuesOnly: false,
36
+ arrayFormat: "indices",
37
+ skipNulls: false
38
+ }
39
+ };
40
+ /**
41
+ * Merge QS parser factory options
42
+ * @param options - Partial options to merge with existing configuration
43
+ */
44
+ merge(options) {
45
+ Object.assign(this.#options.parse, options.parse);
46
+ Object.assign(this.#options.stringify, options.stringify);
47
+ return this;
48
+ }
49
+ /**
50
+ * Create instance of the QS parser class
51
+ */
52
+ create() {
53
+ return new Qs(this.#options);
54
+ }
51
55
  };
52
-
53
- // factories/router.ts
56
+ //#endregion
57
+ //#region factories/router.ts
58
+ /**
59
+ * Router factory is used to generate router class instances for
60
+ * testing
61
+ */
54
62
  var RouterFactory = class {
55
- /**
56
- * Factory parameters for creating router instances
57
- */
58
- #parameters = {};
59
- /**
60
- * Returns an instance of the application class
61
- */
62
- #getApp() {
63
- return this.#parameters.app || new AppFactory().create(new URL("./app/", import.meta.url));
64
- }
65
- /**
66
- * Returns an instance of the encryptor to encrypt
67
- * signed URLs
68
- */
69
- #createEncryption() {
70
- return this.#parameters.encryption || new EncryptionFactory().create();
71
- }
72
- /**
73
- * Merge factory params
74
- * @param params - Partial factory parameters to merge
75
- */
76
- merge(params) {
77
- Object.assign(this.#parameters, params);
78
- return this;
79
- }
80
- /**
81
- * Create router instance
82
- */
83
- create() {
84
- return new Router(this.#getApp(), this.#createEncryption(), new QsParserFactory().create());
85
- }
63
+ /**
64
+ * Factory parameters for creating router instances
65
+ */
66
+ #parameters = {};
67
+ /**
68
+ * Returns an instance of the application class
69
+ */
70
+ #getApp() {
71
+ return this.#parameters.app || new AppFactory().create(new URL("./app/", import.meta.url));
72
+ }
73
+ /**
74
+ * Returns an instance of the encryptor to encrypt
75
+ * signed URLs
76
+ */
77
+ #createEncryption() {
78
+ return this.#parameters.encryption || new EncryptionFactory().create();
79
+ }
80
+ /**
81
+ * Merge factory params
82
+ * @param params - Partial factory parameters to merge
83
+ */
84
+ merge(params) {
85
+ Object.assign(this.#parameters, params);
86
+ return this;
87
+ }
88
+ /**
89
+ * Create router instance
90
+ */
91
+ create() {
92
+ return new Router(this.#getApp(), this.#createEncryption(), new QsParserFactory().create());
93
+ }
86
94
  };
87
-
88
- // factories/request.ts
89
- import { Socket } from "net";
90
- import proxyAddr from "proxy-addr";
91
- import { randomUUID } from "crypto";
92
- import { IncomingMessage, ServerResponse } from "http";
93
- import { EncryptionFactory as EncryptionFactory2 } from "@adonisjs/encryption/factories";
94
- var RequestFactory = class {
95
- /**
96
- * Factory parameters for creating request instances
97
- */
98
- #parameters = {};
99
- /**
100
- * Returns the config for the request class
101
- */
102
- #getConfig() {
103
- return {
104
- allowMethodSpoofing: false,
105
- trustProxy: proxyAddr.compile("loopback"),
106
- subdomainOffset: 2,
107
- generateRequestId: false,
108
- createRequestId() {
109
- return randomUUID();
110
- },
111
- ...this.#parameters.config
112
- };
113
- }
114
- /**
115
- * Returns the HTTP req object
116
- */
117
- #createRequest() {
118
- const req = this.#parameters.req || new IncomingMessage(new Socket());
119
- if (this.#parameters.url) {
120
- req.url = this.#parameters.url;
121
- }
122
- if (this.#parameters.method) {
123
- req.method = this.#parameters.method;
124
- }
125
- return req;
126
- }
127
- /**
128
- * Returns the HTTP res object
129
- * @param req - The incoming message request object
130
- */
131
- #createResponse(req) {
132
- return this.#parameters.res || new ServerResponse(req);
133
- }
134
- /**
135
- * Returns an instance of the encryptor to encrypt
136
- * signed URLs
137
- */
138
- #createEncryption() {
139
- return this.#parameters.encryption || new EncryptionFactory2().create();
140
- }
141
- /**
142
- * Merge factory params
143
- * @param params - Partial factory parameters to merge
144
- */
145
- merge(params) {
146
- Object.assign(this.#parameters, params);
147
- return this;
148
- }
149
- /**
150
- * Create request
151
- */
152
- create() {
153
- const req = this.#createRequest();
154
- return new Request(
155
- req,
156
- this.#createResponse(req),
157
- this.#createEncryption(),
158
- this.#getConfig(),
159
- new QsParserFactory().create()
160
- );
161
- }
95
+ //#endregion
96
+ //#region factories/request.ts
97
+ /**
98
+ * Request factory is used to generate request class instances for
99
+ * testing
100
+ */
101
+ var HttpRequestFactory = class {
102
+ /**
103
+ * Factory parameters for creating request instances
104
+ */
105
+ #parameters = {};
106
+ /**
107
+ * Returns the config for the request class
108
+ */
109
+ #getConfig() {
110
+ return {
111
+ allowMethodSpoofing: false,
112
+ trustProxy: proxyAddr.compile("loopback"),
113
+ subdomainOffset: 2,
114
+ generateRequestId: false,
115
+ createRequestId() {
116
+ return randomUUID();
117
+ },
118
+ ...this.#parameters.config
119
+ };
120
+ }
121
+ /**
122
+ * Returns the HTTP req object
123
+ */
124
+ #createRequest() {
125
+ const req = this.#parameters.req || new IncomingMessage(new Socket());
126
+ if (this.#parameters.url) req.url = this.#parameters.url;
127
+ if (this.#parameters.method) req.method = this.#parameters.method;
128
+ return req;
129
+ }
130
+ /**
131
+ * Returns the HTTP res object
132
+ * @param req - The incoming message request object
133
+ */
134
+ #createResponse(req) {
135
+ return this.#parameters.res || new ServerResponse(req);
136
+ }
137
+ /**
138
+ * Returns an instance of the encryptor to encrypt
139
+ * signed URLs
140
+ */
141
+ #createEncryption() {
142
+ return this.#parameters.encryption || new EncryptionFactory().create();
143
+ }
144
+ /**
145
+ * Merge factory params
146
+ * @param params - Partial factory parameters to merge
147
+ */
148
+ merge(params) {
149
+ Object.assign(this.#parameters, params);
150
+ return this;
151
+ }
152
+ /**
153
+ * Create request
154
+ */
155
+ create() {
156
+ const req = this.#createRequest();
157
+ return new HttpRequest(req, this.#createResponse(req), this.#createEncryption(), this.#getConfig(), new QsParserFactory().create());
158
+ }
162
159
  };
163
-
164
- // factories/response.ts
165
- import { Socket as Socket2 } from "net";
166
- import { IncomingMessage as IncomingMessage2, ServerResponse as ServerResponse2 } from "http";
167
- import { EncryptionFactory as EncryptionFactory3 } from "@adonisjs/encryption/factories";
168
- var ResponseFactory = class {
169
- /**
170
- * Factory parameters for creating response instances
171
- */
172
- #parameters = {};
173
- /**
174
- * Returns the config for the request class
175
- */
176
- #getConfig() {
177
- return {
178
- etag: false,
179
- jsonpCallbackName: "callback",
180
- cookie: {
181
- maxAge: 90,
182
- path: "/",
183
- httpOnly: true,
184
- sameSite: false,
185
- secure: false
186
- },
187
- ...this.#parameters.config
188
- };
189
- }
190
- /**
191
- * Returns the HTTP req object
192
- */
193
- #createRequest() {
194
- return this.#parameters.req || new IncomingMessage2(new Socket2());
195
- }
196
- /**
197
- * Returns an instance of the router
198
- */
199
- #createRouter() {
200
- return this.#parameters.router || new RouterFactory().create();
201
- }
202
- /**
203
- * Returns the HTTP res object
204
- * @param req - The incoming message request object
205
- */
206
- #createResponse(req) {
207
- return this.#parameters.res || new ServerResponse2(req);
208
- }
209
- /**
210
- * Returns an instance of the encryptor to encrypt
211
- * signed URLs
212
- */
213
- #createEncryption() {
214
- return this.#parameters.encryption || new EncryptionFactory3().create();
215
- }
216
- /**
217
- * Merge factory params
218
- * @param params - Partial factory parameters to merge
219
- */
220
- merge(params) {
221
- Object.assign(this.#parameters, params);
222
- return this;
223
- }
224
- /**
225
- * Create response class instance
226
- */
227
- create() {
228
- const req = this.#createRequest();
229
- return new Response(
230
- req,
231
- this.#createResponse(req),
232
- this.#createEncryption(),
233
- this.#getConfig(),
234
- this.#createRouter(),
235
- new QsParserFactory().create()
236
- );
237
- }
160
+ //#endregion
161
+ //#region factories/response.ts
162
+ /**
163
+ * Response factory is used to generate response class instances for
164
+ * testing
165
+ */
166
+ var HttpResponseFactory = class {
167
+ /**
168
+ * Factory parameters for creating response instances
169
+ */
170
+ #parameters = {};
171
+ /**
172
+ * Returns the config for the request class
173
+ */
174
+ #getConfig() {
175
+ return {
176
+ etag: false,
177
+ serializeJSON: safeStringify,
178
+ jsonpCallbackName: "callback",
179
+ cookie: {
180
+ maxAge: 90,
181
+ path: "/",
182
+ httpOnly: true,
183
+ sameSite: false,
184
+ secure: false
185
+ },
186
+ ...this.#parameters.config
187
+ };
188
+ }
189
+ /**
190
+ * Returns the HTTP req object
191
+ */
192
+ #createRequest() {
193
+ return this.#parameters.req || new IncomingMessage(new Socket());
194
+ }
195
+ /**
196
+ * Returns an instance of the router
197
+ */
198
+ #createRouter() {
199
+ return this.#parameters.router || new RouterFactory().create();
200
+ }
201
+ /**
202
+ * Returns the HTTP res object
203
+ * @param req - The incoming message request object
204
+ */
205
+ #createResponse(req) {
206
+ return this.#parameters.res || new ServerResponse(req);
207
+ }
208
+ /**
209
+ * Returns an instance of the encryptor to encrypt
210
+ * signed URLs
211
+ */
212
+ #createEncryption() {
213
+ return this.#parameters.encryption || new EncryptionFactory().create();
214
+ }
215
+ /**
216
+ * Merge factory params
217
+ * @param params - Partial factory parameters to merge
218
+ */
219
+ merge(params) {
220
+ Object.assign(this.#parameters, params);
221
+ return this;
222
+ }
223
+ /**
224
+ * Create response class instance
225
+ */
226
+ create() {
227
+ const req = this.#createRequest();
228
+ return new HttpResponse(req, this.#createResponse(req), this.#createEncryption(), this.#getConfig(), this.#createRouter(), new QsParserFactory().create());
229
+ }
238
230
  };
239
-
240
- // factories/server_factory.ts
241
- import { Logger } from "@adonisjs/logger";
242
- import { Emitter } from "@adonisjs/events";
243
- import { AppFactory as AppFactory2 } from "@adonisjs/application/factories";
244
- import { EncryptionFactory as EncryptionFactory4 } from "@adonisjs/encryption/factories";
231
+ //#endregion
232
+ //#region factories/server_factory.ts
233
+ /**
234
+ * Server factory is used to generate server class instances for
235
+ * testing
236
+ */
245
237
  var ServerFactory = class {
246
- /**
247
- * Factory parameters for creating server instances
248
- */
249
- #parameters = {};
250
- /**
251
- * Returns the emitter instance
252
- */
253
- #getEmitter() {
254
- return this.#parameters.emitter || new Emitter(this.#getApp());
255
- }
256
- /**
257
- * Returns the logger instance
258
- */
259
- #getLogger() {
260
- return this.#parameters.logger || new Logger({ enabled: false });
261
- }
262
- /**
263
- * Returns the config for the server class
264
- */
265
- #getConfig() {
266
- return defineConfig(this.#parameters.config || {});
267
- }
268
- /**
269
- * Returns an instance of the application class
270
- */
271
- #getApp() {
272
- return this.#parameters.app || new AppFactory2().create(new URL("./app/", import.meta.url));
273
- }
274
- /**
275
- * Returns an instance of the encryptor to encrypt
276
- * signed URLs
277
- */
278
- #createEncryption() {
279
- return this.#parameters.encryption || new EncryptionFactory4().create();
280
- }
281
- /**
282
- * Merge factory params
283
- * @param params - Partial factory parameters to merge
284
- */
285
- merge(params) {
286
- Object.assign(this.#parameters, params);
287
- return this;
288
- }
289
- /**
290
- * Create server instance
291
- */
292
- create() {
293
- return new Server(
294
- this.#getApp(),
295
- this.#createEncryption(),
296
- this.#getEmitter(),
297
- this.#getLogger(),
298
- this.#getConfig()
299
- );
300
- }
238
+ /**
239
+ * Factory parameters for creating server instances
240
+ */
241
+ #parameters = {};
242
+ /**
243
+ * Returns the emitter instance
244
+ */
245
+ #getEmitter() {
246
+ return this.#parameters.emitter || new Emitter(this.#getApp());
247
+ }
248
+ /**
249
+ * Returns the logger instance
250
+ */
251
+ #getLogger() {
252
+ return this.#parameters.logger || new Logger({ enabled: false });
253
+ }
254
+ /**
255
+ * Returns the config for the server class
256
+ */
257
+ #getConfig() {
258
+ return defineConfig(this.#parameters.config || {});
259
+ }
260
+ /**
261
+ * Returns an instance of the application class
262
+ */
263
+ #getApp() {
264
+ return this.#parameters.app || new AppFactory().create(new URL("./app/", import.meta.url));
265
+ }
266
+ /**
267
+ * Returns an instance of the encryptor to encrypt
268
+ * signed URLs
269
+ */
270
+ #createEncryption() {
271
+ return this.#parameters.encryption || new EncryptionFactory().create();
272
+ }
273
+ /**
274
+ * Merge factory params
275
+ * @param params - Partial factory parameters to merge
276
+ */
277
+ merge(params) {
278
+ Object.assign(this.#parameters, params);
279
+ return this;
280
+ }
281
+ /**
282
+ * Create server instance
283
+ */
284
+ create() {
285
+ return new Server(this.#getApp(), this.#createEncryption(), this.#getEmitter(), this.#getLogger(), this.#getConfig());
286
+ }
301
287
  };
302
-
303
- // factories/http_context.ts
304
- import { Container } from "@adonisjs/fold";
305
- import { LoggerFactory } from "@adonisjs/logger/factories";
288
+ //#endregion
289
+ //#region factories/http_context.ts
290
+ /**
291
+ * HttpContext factory is used to generate Http context class instances for
292
+ * testing
293
+ */
306
294
  var HttpContextFactory = class {
307
- /**
308
- * Factory parameters for creating HTTP context instances
309
- */
310
- #parameters = {};
311
- /**
312
- * Returns the request class instance
313
- */
314
- #createRequest() {
315
- return this.#parameters.request || new RequestFactory().create();
316
- }
317
- /**
318
- * Returns the response class instance
319
- */
320
- #createResponse() {
321
- return this.#parameters.response || new ResponseFactory().create();
322
- }
323
- /**
324
- * Returns an instance of the logger class
325
- */
326
- #createLogger() {
327
- return this.#parameters.logger || new LoggerFactory().create();
328
- }
329
- /**
330
- * Merge factory params
331
- * @param params - Partial factory parameters to merge
332
- */
333
- merge(params) {
334
- Object.assign(this.#parameters, params);
335
- return this;
336
- }
337
- /**
338
- * Create HTTP context instance
339
- */
340
- create() {
341
- return new HttpContext(
342
- this.#createRequest(),
343
- this.#createResponse(),
344
- this.#createLogger(),
345
- new Container().createResolver()
346
- );
347
- }
348
- };
349
- export {
350
- HttpContextFactory,
351
- QsParserFactory,
352
- RequestFactory,
353
- ResponseFactory,
354
- RouterFactory,
355
- ServerFactory
295
+ /**
296
+ * Factory parameters for creating HTTP context instances
297
+ */
298
+ #parameters = {};
299
+ /**
300
+ * Returns the request class instance
301
+ */
302
+ #createRequest() {
303
+ if (this.#parameters.request) return this.#parameters.request;
304
+ let { url, method, route } = this.#parameters;
305
+ if (route) url = createURL(route.pattern, parseRoute(route.pattern), new QsParserFactory().create().stringify, route.params);
306
+ return new HttpRequestFactory().merge({
307
+ url,
308
+ method
309
+ }).create();
310
+ }
311
+ /**
312
+ * Returns the response class instance
313
+ */
314
+ #createResponse() {
315
+ return this.#parameters.response || new HttpResponseFactory().create();
316
+ }
317
+ /**
318
+ * Returns an instance of the logger class
319
+ */
320
+ #createLogger() {
321
+ return this.#parameters.logger || new LoggerFactory().create();
322
+ }
323
+ /**
324
+ * Merge factory params
325
+ * @param params - Partial factory parameters to merge
326
+ */
327
+ merge(params) {
328
+ Object.assign(this.#parameters, params);
329
+ return this;
330
+ }
331
+ /**
332
+ * Create HTTP context instance
333
+ */
334
+ create() {
335
+ return new HttpContext(this.#createRequest(), this.#createResponse(), this.#createLogger(), new Container().createResolver());
336
+ }
356
337
  };
338
+ //#endregion
339
+ export { HttpContextFactory, QsParserFactory, HttpRequestFactory as RequestFactory, HttpResponseFactory as ResponseFactory, RouterFactory, ServerFactory };