@eggjs/koa 3.1.2-beta.2 → 3.1.2-beta.20
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/Readme.md +1 -1
- package/dist/application.d.ts +1 -1
- package/dist/application.js +10 -3
- package/dist/request.js +2 -1
- package/dist/response.js +1 -1
- package/package.json +14 -10
package/Readme.md
CHANGED
package/dist/application.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ declare class Application extends Emitter {
|
|
|
32
32
|
maxIpsCount: number;
|
|
33
33
|
protected _keys?: string[];
|
|
34
34
|
middleware: MiddlewareFunc<Context>[];
|
|
35
|
-
ctxStorage: AsyncLocalStorage<Context
|
|
35
|
+
ctxStorage: AsyncLocalStorage<Context> | null;
|
|
36
36
|
silent: boolean;
|
|
37
37
|
ContextClass: ProtoImplClass<Context>;
|
|
38
38
|
context: AnyProto;
|
package/dist/application.js
CHANGED
|
@@ -5,6 +5,7 @@ import Emitter from "node:events";
|
|
|
5
5
|
import http from "node:http";
|
|
6
6
|
import Stream from "node:stream";
|
|
7
7
|
import util, { debuglog } from "node:util";
|
|
8
|
+
import v8 from "node:v8";
|
|
8
9
|
import { getAsyncLocalStorage } from "gals";
|
|
9
10
|
import { HttpError } from "http-errors";
|
|
10
11
|
import { isGeneratorFunction } from "is-type-of";
|
|
@@ -60,7 +61,12 @@ var Application = class extends Emitter {
|
|
|
60
61
|
this._env = options.env || process.env.NODE_ENV || "development";
|
|
61
62
|
if (options.keys) this._keys = options.keys;
|
|
62
63
|
this.middleware = [];
|
|
63
|
-
|
|
64
|
+
if (v8.startupSnapshot?.isBuildingSnapshot?.()) {
|
|
65
|
+
this.ctxStorage = null;
|
|
66
|
+
v8.startupSnapshot.addDeserializeCallback((app) => {
|
|
67
|
+
app.ctxStorage = getAsyncLocalStorage();
|
|
68
|
+
}, this);
|
|
69
|
+
} else this.ctxStorage = getAsyncLocalStorage();
|
|
64
70
|
this.silent = false;
|
|
65
71
|
this.ContextClass = class ApplicationContext extends Context {};
|
|
66
72
|
this.context = this.ContextClass.prototype;
|
|
@@ -134,9 +140,10 @@ var Application = class extends Emitter {
|
|
|
134
140
|
if (!this.listenerCount("error")) this.on("error", this.onerror.bind(this));
|
|
135
141
|
const handleRequest = (req, res) => {
|
|
136
142
|
const ctx = this.createContext(req, res);
|
|
137
|
-
return this.ctxStorage.run(ctx, async () => {
|
|
143
|
+
if (this.ctxStorage) return this.ctxStorage.run(ctx, async () => {
|
|
138
144
|
return await this.handleRequest(ctx, fn);
|
|
139
145
|
});
|
|
146
|
+
return this.handleRequest(ctx, fn);
|
|
140
147
|
};
|
|
141
148
|
return handleRequest;
|
|
142
149
|
}
|
|
@@ -144,7 +151,7 @@ var Application = class extends Emitter {
|
|
|
144
151
|
* return current context from async local storage
|
|
145
152
|
*/
|
|
146
153
|
get currentContext() {
|
|
147
|
-
return this.ctxStorage
|
|
154
|
+
return this.ctxStorage?.getStore();
|
|
148
155
|
}
|
|
149
156
|
/**
|
|
150
157
|
* Handle request in callback.
|
package/dist/request.js
CHANGED
|
@@ -254,7 +254,8 @@ var Request = class {
|
|
|
254
254
|
get length() {
|
|
255
255
|
const len = this.get("Content-Length");
|
|
256
256
|
if (len === "") return;
|
|
257
|
-
|
|
257
|
+
const parsed = Number.parseInt(len, 10);
|
|
258
|
+
return Number.isNaN(parsed) ? void 0 : parsed;
|
|
258
259
|
}
|
|
259
260
|
/**
|
|
260
261
|
* Return the protocol string "http" or "https"
|
package/dist/response.js
CHANGED
|
@@ -134,7 +134,7 @@ var Response = class {
|
|
|
134
134
|
* When Content-Length is not defined it will return `undefined`.
|
|
135
135
|
*/
|
|
136
136
|
get length() {
|
|
137
|
-
if (this.has("Content-Length")) return Number.parseInt(this.get("Content-Length")) || 0;
|
|
137
|
+
if (this.has("Content-Length")) return Number.parseInt(this.get("Content-Length"), 10) || 0;
|
|
138
138
|
const body = this.body;
|
|
139
139
|
if (!body || body instanceof Stream) return;
|
|
140
140
|
if (typeof body === "string") return Buffer.byteLength(body);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eggjs/koa",
|
|
3
|
-
"version": "3.1.2-beta.
|
|
3
|
+
"version": "3.1.2-beta.20",
|
|
4
4
|
"description": "Koa web app framework for https://eggjs.org",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"app",
|
|
@@ -30,9 +30,17 @@
|
|
|
30
30
|
"./package.json": "./package.json"
|
|
31
31
|
},
|
|
32
32
|
"publishConfig": {
|
|
33
|
-
"access": "public"
|
|
33
|
+
"access": "public",
|
|
34
|
+
"exports": {
|
|
35
|
+
".": "./dist/index.js",
|
|
36
|
+
"./package.json": "./package.json"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"typecheck": "tsgo --noEmit"
|
|
34
41
|
},
|
|
35
42
|
"dependencies": {
|
|
43
|
+
"@eggjs/cookies": "4.0.2-beta.20",
|
|
36
44
|
"@types/content-disposition": "^0.5.8",
|
|
37
45
|
"accepts": "^1.3.8",
|
|
38
46
|
"cache-content-type": "^2.0.0",
|
|
@@ -50,10 +58,10 @@
|
|
|
50
58
|
"parseurl": "^1.3.3",
|
|
51
59
|
"statuses": "^2.0.1",
|
|
52
60
|
"type-is": "^2.0.0",
|
|
53
|
-
"vary": "^1.1.2"
|
|
54
|
-
"@eggjs/cookies": "4.0.2-beta.2"
|
|
61
|
+
"vary": "^1.1.2"
|
|
55
62
|
},
|
|
56
63
|
"devDependencies": {
|
|
64
|
+
"@eggjs/supertest": "9.0.2-beta.20",
|
|
57
65
|
"@types/accepts": "^1.3.7",
|
|
58
66
|
"@types/content-type": "^1.1.8",
|
|
59
67
|
"@types/destroy": "^1.0.3",
|
|
@@ -68,13 +76,9 @@
|
|
|
68
76
|
"@types/type-is": "^1.6.6",
|
|
69
77
|
"@types/vary": "^1.1.3",
|
|
70
78
|
"mm": "^4.0.2",
|
|
71
|
-
"typescript": "^5.9.3"
|
|
72
|
-
"@eggjs/supertest": "9.0.2-beta.2"
|
|
79
|
+
"typescript": "^5.9.3"
|
|
73
80
|
},
|
|
74
81
|
"engines": {
|
|
75
82
|
"node": ">=22.18.0"
|
|
76
|
-
},
|
|
77
|
-
"scripts": {
|
|
78
|
-
"typecheck": "tsgo --noEmit"
|
|
79
83
|
}
|
|
80
|
-
}
|
|
84
|
+
}
|