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