fulmine.js 5.19.2 → 5.19.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.
- package/package.json +2 -1
- package/src/adopt.js +20 -26
- package/src/application.js +46 -45
- package/src/cli.js +28 -34
- package/src/cluster.js +16 -25
- package/src/compression.js +39 -51
- package/src/declarative.js +586 -538
- package/src/hot-settings.js +80 -0
- package/src/index.js +11 -17
- package/src/lazy-readable.js +129 -0
- package/src/lazy-writable.js +97 -0
- package/src/middlewares.js +61 -77
- package/src/nest.js +19 -34
- package/src/node-shim.js +11 -13
- package/src/optimizer.js +598 -0
- package/src/parse-query.js +3 -3
- package/src/request-utils.js +306 -0
- package/src/request.js +101 -513
- package/src/response-utils.js +88 -0
- package/src/response.js +100 -443
- package/src/route.js +4 -5
- package/src/router-utils.js +950 -0
- package/src/router.js +126 -2148
- package/src/server-shape.js +26 -41
- package/src/server-timing.js +16 -29
- package/src/socket.js +208 -0
- package/src/testing.js +39 -42
- package/src/usage.js +16 -21
- package/src/utils.js +49 -59
- package/src/verify.js +18 -28
- package/src/view.js +5 -7
- package/src/walk.js +580 -0
- package/src/websocket.js +19 -20
- package/src/work.js +21 -27
package/src/work.js
CHANGED
|
@@ -16,27 +16,21 @@ limitations under the License.
|
|
|
16
16
|
|
|
17
17
|
// What one request actually made this framework do, read from state it already keeps.
|
|
18
18
|
//
|
|
19
|
-
// Most of
|
|
20
|
-
//
|
|
21
|
-
//
|
|
22
|
-
//
|
|
23
|
-
// puts the folded object back on every request, and the answer stays correct, so nothing fails.
|
|
19
|
+
// Most of the speed here is work that does not happen: no Readable, no Writable, no folded headers
|
|
20
|
+
// object, no parsed query, no socket stand-in. One careless middleware brings it back, and the
|
|
21
|
+
// answer stays correct, so nothing fails. Every field below is already kept for other reasons, so
|
|
22
|
+
// asking costs a load and nothing is counted or wrapped for the sake of being asked.
|
|
24
23
|
//
|
|
25
|
-
//
|
|
26
|
-
//
|
|
27
|
-
// is the whole design rule here: a probe that charges the requests nobody is probing would be
|
|
28
|
-
// paid for by everyone, forever, to be read once.
|
|
24
|
+
// Not here: whether the constructor copied the headers out of uWS. That is about the chain and
|
|
25
|
+
// `routeReport().skipHeaders` reports it already.
|
|
29
26
|
//
|
|
30
|
-
//
|
|
31
|
-
// a decision about the chain rather than about the request, `routeReport().skipHeaders` reports it
|
|
32
|
-
// already, and the one case where the two differ, a granted route whose request declares a body,
|
|
33
|
-
// would cost a flag written on every request to be read on almost none.
|
|
34
|
-
//
|
|
35
|
-
// The two readers are `express.testing.expectLazy`, which fails a build that lost one of these,
|
|
36
|
-
// and `express.serverTiming()`, which writes them into the header for a browser to show.
|
|
27
|
+
// Read by `express.testing.expectLazy` and by `express.serverTiming()`.
|
|
37
28
|
|
|
38
29
|
"use strict";
|
|
39
30
|
|
|
31
|
+
/** @typedef {import("./request.js")} Request */
|
|
32
|
+
/** @typedef {import("./response.js")} Response */
|
|
33
|
+
|
|
40
34
|
/**
|
|
41
35
|
* @typedef {object} Work
|
|
42
36
|
* @property {boolean} native whether µWS matched this route itself
|
|
@@ -50,29 +44,30 @@ limitations under the License.
|
|
|
50
44
|
*/
|
|
51
45
|
|
|
52
46
|
/**
|
|
53
|
-
* What this request did
|
|
54
|
-
* reader that wants the whole picture asks at the end of it.
|
|
47
|
+
* What this request did so far. The answer changes while the chain runs, so ask at the end of it.
|
|
55
48
|
*
|
|
56
|
-
* @param {
|
|
57
|
-
* @param {
|
|
49
|
+
* @param {Request} req
|
|
50
|
+
* @param {Response} res the response, since half of this is about the response
|
|
58
51
|
* @returns {Work}
|
|
59
52
|
*/
|
|
60
53
|
function work(req, res) {
|
|
61
54
|
const native = req.route?._native;
|
|
55
|
+
// cast for the three the classes do not declare: `body` is deliberately not a field of
|
|
56
|
+
// Request, and the two stream states are node's own, written when a lazy stream is built
|
|
57
|
+
const loose = /** @type {any} */ (req);
|
|
62
58
|
return {
|
|
63
59
|
native: Boolean(native),
|
|
64
60
|
declarative: Boolean(native?.declarative),
|
|
65
61
|
headers: req._headersBuilt,
|
|
66
62
|
query: req._queryParsed,
|
|
67
|
-
body:
|
|
68
|
-
requestStream:
|
|
69
|
-
responseStream: res._writableState !== undefined,
|
|
63
|
+
body: loose.body !== undefined,
|
|
64
|
+
requestStream: loose._readableState !== undefined,
|
|
65
|
+
responseStream: /** @type {any} */ (res)._writableState !== undefined,
|
|
70
66
|
socket: req._socketBuilt || res._socketBuilt
|
|
71
67
|
};
|
|
72
68
|
}
|
|
73
69
|
|
|
74
|
-
// The order
|
|
75
|
-
// header and a failure message read the same way.
|
|
70
|
+
// The order both readers list them in, cheapest first, so a header and a failure message agree.
|
|
76
71
|
const NAMES = [
|
|
77
72
|
["headers", "headers"],
|
|
78
73
|
["query", "query"],
|
|
@@ -83,8 +78,7 @@ const NAMES = [
|
|
|
83
78
|
];
|
|
84
79
|
|
|
85
80
|
/**
|
|
86
|
-
* The names of everything that did happen, for a message or a header. Empty
|
|
87
|
-
* did none of it, which is the one this framework is built to serve.
|
|
81
|
+
* The names of everything that did happen, for a message or a header. Empty is the good case.
|
|
88
82
|
*
|
|
89
83
|
* @param {Work} done
|
|
90
84
|
* @returns {string[]}
|