@eggjs/koa 3.1.2-beta.7 → 3.1.2-beta.9
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/dist/application.d.ts +1 -1
- package/dist/application.js +10 -3
- package/package.json +3 -3
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/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.9",
|
|
4
4
|
"description": "Koa web app framework for https://eggjs.org",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"app",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"statuses": "^2.0.1",
|
|
52
52
|
"type-is": "^2.0.0",
|
|
53
53
|
"vary": "^1.1.2",
|
|
54
|
-
"@eggjs/cookies": "4.0.2-beta.
|
|
54
|
+
"@eggjs/cookies": "4.0.2-beta.9"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@types/accepts": "^1.3.7",
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"@types/vary": "^1.1.3",
|
|
70
70
|
"mm": "^4.0.2",
|
|
71
71
|
"typescript": "^5.9.3",
|
|
72
|
-
"@eggjs/supertest": "9.0.2-beta.
|
|
72
|
+
"@eggjs/supertest": "9.0.2-beta.9"
|
|
73
73
|
},
|
|
74
74
|
"engines": {
|
|
75
75
|
"node": ">=22.18.0"
|