@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.
- package/build/chunk-B2GA45YG.js +35 -0
- package/build/define_config-t7GL92UR.js +5470 -0
- package/build/factories/http_context.d.ts +10 -4
- package/build/factories/main.d.ts +2 -2
- package/build/factories/main.js +328 -345
- package/build/factories/request.d.ts +4 -4
- package/build/factories/response.d.ts +4 -4
- package/build/factories/router.d.ts +1 -1
- package/build/factories/server_factory.d.ts +1 -1
- package/build/factories/url_builder_factory.d.ts +3 -3
- package/build/helpers-XD4_pfkD.js +108 -0
- package/build/helpers-aa47NQc6.js +1426 -0
- package/build/index.d.ts +2 -2
- package/build/index.js +330 -373
- package/build/src/client/helpers.d.ts +37 -0
- package/build/src/client/types.d.ts +194 -0
- package/build/src/client/url_builder.d.ts +15 -0
- package/build/src/client/url_builder.js +131 -0
- package/build/src/cookies/client.d.ts +28 -5
- package/build/src/cookies/drivers/encrypted.d.ts +1 -1
- package/build/src/cookies/drivers/signed.d.ts +1 -1
- package/build/src/cookies/parser.d.ts +1 -1
- package/build/src/cookies/serializer.d.ts +2 -2
- package/build/src/debug.d.ts +14 -1
- package/build/src/define_config.d.ts +19 -1
- package/build/src/define_middleware.d.ts +19 -3
- package/build/src/errors.d.ts +60 -5
- package/build/src/exception_handler.d.ts +28 -8
- package/build/src/helpers.d.ts +5 -17
- package/build/src/helpers.js +4 -24
- package/build/src/http_context/main.d.ts +67 -17
- package/build/src/qs.d.ts +17 -3
- package/build/src/redirect.d.ts +22 -3
- package/build/src/request.d.ts +12 -5
- package/build/src/response.d.ts +5 -5
- package/build/src/response_status.d.ts +14 -0
- package/build/src/router/main.d.ts +6 -2
- package/build/src/router/route.d.ts +130 -32
- package/build/src/router/signed_url_builder.d.ts +1 -1
- package/build/src/server/main.d.ts +6 -6
- package/build/src/types/main.js +2 -0
- package/build/src/types/request.d.ts +2 -1
- package/build/src/types/response.d.ts +6 -1
- package/build/src/types/route.d.ts +3 -27
- package/build/src/types/url_builder.d.ts +2 -140
- package/build/src/utils.d.ts +71 -6
- package/package.json +57 -48
- package/build/chunk-CVZAIRWJ.js +0 -1222
- package/build/chunk-JD6QW4NQ.js +0 -4428
- package/build/src/router/url_builder.d.ts +0 -9
package/build/factories/main.js
CHANGED
|
@@ -1,356 +1,339 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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 "@
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
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
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
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
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
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
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
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
|
-
|
|
304
|
-
|
|
305
|
-
|
|
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
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
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 };
|