egg 4.1.0-beta.34 → 4.1.0-beta.36
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/agent.d.ts +7 -3
- package/dist/agent.js +10 -6
- package/dist/ajv.d.ts +1 -1
- package/dist/ajv.js +3 -2
- package/dist/aop.d.ts +1 -1
- package/dist/aop.js +3 -2
- package/dist/app/extend/context.d.ts +181 -178
- package/dist/app/extend/context.js +244 -259
- package/dist/app/extend/helper.d.ts +40 -35
- package/dist/app/extend/helper.js +45 -41
- package/dist/app/extend/request.d.ts +135 -131
- package/dist/app/extend/request.js +219 -258
- package/dist/app/extend/response.d.ts +28 -24
- package/dist/app/extend/response.js +36 -34
- package/dist/app/middleware/body_parser.d.ts +2 -2
- package/dist/app/middleware/body_parser.js +7 -3
- package/dist/app/middleware/meta.d.ts +8 -8
- package/dist/app/middleware/meta.js +15 -18
- package/dist/app/middleware/notfound.d.ts +8 -5
- package/dist/app/middleware/notfound.js +25 -28
- package/dist/app/middleware/override_method.d.ts +2 -2
- package/dist/app/middleware/override_method.js +7 -3
- package/dist/app/middleware/site_file.d.ts +11 -7
- package/dist/app/middleware/site_file.js +37 -52
- package/dist/config/config.default.d.ts +11 -6
- package/dist/config/config.default.js +258 -375
- package/dist/config/config.local.d.ts +6 -3
- package/dist/config/config.local.js +7 -8
- package/dist/config/config.unittest.d.ts +6 -3
- package/dist/config/config.unittest.js +10 -8
- package/dist/config/plugin.d.ts +6 -2
- package/dist/config/plugin.js +67 -131
- package/dist/dal.d.ts +1 -1
- package/dist/dal.js +3 -2
- package/dist/errors.d.ts +1 -1
- package/dist/errors.js +3 -2
- package/dist/helper.d.ts +1 -1
- package/dist/helper.js +3 -2
- package/dist/index.d.ts +24 -106
- package/dist/index.js +23 -89
- package/dist/lib/agent.d.ts +21 -15
- package/dist/lib/agent.js +53 -45
- package/dist/lib/application.d.ts +60 -54
- package/dist/lib/application.js +200 -250
- package/dist/lib/core/base_context_class.d.ts +23 -17
- package/dist/lib/core/base_context_class.js +17 -15
- package/dist/lib/core/base_context_logger.d.ts +39 -35
- package/dist/lib/core/base_context_logger.js +58 -60
- package/dist/lib/core/base_hook_class.d.ts +18 -11
- package/dist/lib/core/base_hook_class.js +26 -22
- package/dist/lib/core/context_httpclient.d.ts +21 -16
- package/dist/lib/core/context_httpclient.js +29 -26
- package/dist/lib/core/httpclient.d.ts +14 -12
- package/dist/lib/core/httpclient.js +34 -37
- package/dist/lib/core/logger.d.ts +7 -3
- package/dist/lib/core/logger.js +30 -36
- package/dist/lib/core/messenger/IMessenger.d.ts +53 -49
- package/dist/lib/core/messenger/IMessenger.js +1 -2
- package/dist/lib/core/messenger/base.d.ts +11 -7
- package/dist/lib/core/messenger/base.js +30 -29
- package/dist/lib/core/messenger/index.d.ts +10 -6
- package/dist/lib/core/messenger/index.js +11 -8
- package/dist/lib/core/messenger/ipc.d.ts +62 -57
- package/dist/lib/core/messenger/ipc.js +126 -138
- package/dist/lib/core/messenger/local.d.ts +63 -58
- package/dist/lib/core/messenger/local.js +126 -131
- package/dist/lib/core/utils.d.ts +5 -2
- package/dist/lib/core/utils.js +44 -66
- package/dist/lib/define.d.ts +72 -67
- package/dist/lib/define.js +54 -53
- package/dist/lib/egg.d.ts +283 -281
- package/dist/lib/egg.js +512 -573
- package/dist/lib/error/CookieLimitExceedError.d.ts +7 -4
- package/dist/lib/error/CookieLimitExceedError.js +15 -12
- package/dist/lib/error/MessageUnhandledRejectionError.d.ts +7 -4
- package/dist/lib/error/MessageUnhandledRejectionError.js +15 -12
- package/dist/lib/error/index.d.ts +3 -2
- package/dist/lib/error/index.js +4 -3
- package/dist/lib/loader/AgentWorkerLoader.d.ts +15 -10
- package/dist/lib/loader/AgentWorkerLoader.js +22 -18
- package/dist/lib/loader/AppWorkerLoader.d.ts +20 -15
- package/dist/lib/loader/AppWorkerLoader.js +35 -37
- package/dist/lib/loader/EggApplicationLoader.d.ts +7 -3
- package/dist/lib/loader/EggApplicationLoader.js +7 -4
- package/dist/lib/loader/index.d.ts +4 -3
- package/dist/lib/loader/index.js +5 -4
- package/dist/lib/start.d.ts +24 -20
- package/dist/lib/start.js +32 -42
- package/dist/lib/types.d.ts +288 -286
- package/dist/lib/types.js +2 -2
- package/dist/lib/types.plugin.d.ts +21 -21
- package/dist/lib/types.plugin.js +23 -24
- package/dist/orm.d.ts +1 -1
- package/dist/orm.js +3 -2
- package/dist/schedule.d.ts +2 -2
- package/dist/schedule.js +5 -5
- package/dist/transaction.d.ts +1 -1
- package/dist/transaction.js +3 -2
- package/dist/urllib.d.ts +1 -1
- package/dist/urllib.js +3 -2
- package/package.json +60 -64
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
import bodyparser from
|
|
2
|
-
|
|
3
|
-
//#
|
|
1
|
+
import bodyparser from "koa-bodyparser";
|
|
2
|
+
|
|
3
|
+
//#region src/app/middleware/body_parser.ts
|
|
4
|
+
var body_parser_default = bodyparser;
|
|
5
|
+
|
|
6
|
+
//#endregion
|
|
7
|
+
export { body_parser_default as default };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
logging: boolean;
|
|
1
|
+
import { MiddlewareFunc } from "../../lib/egg.js";
|
|
2
|
+
|
|
3
|
+
//#region src/app/middleware/meta.d.ts
|
|
4
|
+
interface MetaMiddlewareOptions {
|
|
5
|
+
enable: boolean;
|
|
6
|
+
logging: boolean;
|
|
8
7
|
}
|
|
9
8
|
declare const _default: (options: MetaMiddlewareOptions) => MiddlewareFunc;
|
|
10
|
-
|
|
9
|
+
//#endregion
|
|
10
|
+
export { MetaMiddlewareOptions, _default as default };
|
|
@@ -1,20 +1,17 @@
|
|
|
1
|
+
import { performance } from "node:perf_hooks";
|
|
2
|
+
|
|
3
|
+
//#region src/app/middleware/meta.ts
|
|
1
4
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
// total response time header
|
|
12
|
-
if (ctx.performanceStarttime) {
|
|
13
|
-
ctx.set('x-readtime', Math.floor((performance.now() - ctx.performanceStarttime) * 1000) / 1000);
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
ctx.set('x-readtime', Date.now() - ctx.starttime);
|
|
17
|
-
}
|
|
18
|
-
};
|
|
5
|
+
* meta middleware, should be the first middleware
|
|
6
|
+
*/
|
|
7
|
+
var meta_default = (options) => {
|
|
8
|
+
return async function meta(ctx, next) {
|
|
9
|
+
if (options.logging) ctx.coreLogger.info("[meta] request started, host: %s, user-agent: %s", ctx.host, ctx.header["user-agent"]);
|
|
10
|
+
await next();
|
|
11
|
+
if (ctx.performanceStarttime) ctx.set("x-readtime", Math.floor((performance.now() - ctx.performanceStarttime) * 1e3) / 1e3);
|
|
12
|
+
else ctx.set("x-readtime", Date.now() - ctx.starttime);
|
|
13
|
+
};
|
|
19
14
|
};
|
|
20
|
-
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
export { meta_default as default };
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { MiddlewareFunc } from "../../lib/egg.js";
|
|
2
|
+
|
|
3
|
+
//#region src/app/middleware/notfound.d.ts
|
|
4
|
+
interface NotFoundMiddlewareOptions {
|
|
5
|
+
enable: boolean;
|
|
6
|
+
pageUrl: string;
|
|
5
7
|
}
|
|
6
8
|
declare const _default: (options: NotFoundMiddlewareOptions) => MiddlewareFunc;
|
|
7
|
-
|
|
9
|
+
//#endregion
|
|
10
|
+
export { NotFoundMiddlewareOptions, _default as default };
|
|
@@ -1,29 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
ctx.redirect(options.pageUrl);
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
ctx.body = notFoundHtml;
|
|
27
|
-
};
|
|
1
|
+
//#region src/app/middleware/notfound.ts
|
|
2
|
+
var notfound_default = (options) => {
|
|
3
|
+
return async function notfound(ctx, next) {
|
|
4
|
+
await next();
|
|
5
|
+
if (ctx.status !== 404 || ctx.body) return;
|
|
6
|
+
ctx.status = 404;
|
|
7
|
+
if (ctx.acceptJSON) {
|
|
8
|
+
ctx.body = { message: "Not Found" };
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const notFoundHtml = "<h1>404 Not Found</h1>";
|
|
12
|
+
if (options.pageUrl && ctx.path === options.pageUrl) {
|
|
13
|
+
ctx.body = `${notFoundHtml}<p><pre><code>config.notfound.pageUrl(${options.pageUrl})</code></pre> is unimplemented</p>`;
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
if (options.pageUrl) {
|
|
17
|
+
ctx.realStatus = 404;
|
|
18
|
+
ctx.redirect(options.pageUrl);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
ctx.body = notFoundHtml;
|
|
22
|
+
};
|
|
28
23
|
};
|
|
29
|
-
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
export { notfound_default as default };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import override from
|
|
2
|
-
export default
|
|
1
|
+
import override from "koa-override";
|
|
2
|
+
export { override as default };
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
import override from
|
|
2
|
-
|
|
3
|
-
//#
|
|
1
|
+
import override from "koa-override";
|
|
2
|
+
|
|
3
|
+
//#region src/app/middleware/override_method.ts
|
|
4
|
+
var override_method_default = override;
|
|
5
|
+
|
|
6
|
+
//#endregion
|
|
7
|
+
export { override_method_default as default };
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import Context from "../extend/context.js";
|
|
2
|
+
import { MiddlewareFunc } from "../../lib/egg.js";
|
|
3
|
+
|
|
4
|
+
//#region src/app/middleware/site_file.d.ts
|
|
5
|
+
type SiteFileContentFun = (ctx: Context) => Promise<Buffer | string>;
|
|
6
|
+
interface SiteFileMiddlewareOptions {
|
|
7
|
+
enable: boolean;
|
|
8
|
+
cacheControl: string;
|
|
9
|
+
[key: string]: string | Buffer | boolean | SiteFileContentFun | URL;
|
|
7
10
|
}
|
|
8
11
|
declare const _default: (options: SiteFileMiddlewareOptions) => MiddlewareFunc;
|
|
9
|
-
|
|
12
|
+
//#endregion
|
|
13
|
+
export { SiteFileContentFun, SiteFileMiddlewareOptions, _default as default };
|
|
@@ -1,53 +1,38 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import { readFile } from
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
Reflect.set(content, BUFFER_CACHE, buffer);
|
|
36
|
-
}
|
|
37
|
-
ctx.set('cache-control', options.cacheControl);
|
|
38
|
-
ctx.body = content;
|
|
39
|
-
ctx.type = path.extname(ctx.path);
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
// '/robots.txt': Buffer <xx..
|
|
43
|
-
// content is buffer
|
|
44
|
-
if (Buffer.isBuffer(content)) {
|
|
45
|
-
ctx.set('cache-control', options.cacheControl);
|
|
46
|
-
ctx.body = content;
|
|
47
|
-
ctx.type = path.extname(ctx.path);
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
return next();
|
|
51
|
-
};
|
|
1
|
+
import { fileURLToPath } from "node:url";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { readFile } from "node:fs/promises";
|
|
4
|
+
|
|
5
|
+
//#region src/app/middleware/site_file.ts
|
|
6
|
+
const BUFFER_CACHE = Symbol("siteFile URL buffer cache");
|
|
7
|
+
var site_file_default = (options) => {
|
|
8
|
+
return async function siteFile(ctx, next) {
|
|
9
|
+
if (ctx.method !== "HEAD" && ctx.method !== "GET") return next();
|
|
10
|
+
if (ctx.path[0] !== "/") return next();
|
|
11
|
+
let content = options[ctx.path];
|
|
12
|
+
if (!content) return next();
|
|
13
|
+
if (typeof content === "function") content = await content(ctx);
|
|
14
|
+
if (typeof content === "string") return ctx.redirect(content);
|
|
15
|
+
if (content instanceof URL) {
|
|
16
|
+
if (content.protocol !== "file:") return ctx.redirect(content.href);
|
|
17
|
+
let buffer = Reflect.get(content, BUFFER_CACHE);
|
|
18
|
+
if (!buffer) {
|
|
19
|
+
buffer = await readFile(fileURLToPath(content));
|
|
20
|
+
Reflect.set(content, BUFFER_CACHE, buffer);
|
|
21
|
+
}
|
|
22
|
+
ctx.set("cache-control", options.cacheControl);
|
|
23
|
+
ctx.body = content;
|
|
24
|
+
ctx.type = path.extname(ctx.path);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (Buffer.isBuffer(content)) {
|
|
28
|
+
ctx.set("cache-control", options.cacheControl);
|
|
29
|
+
ctx.body = content;
|
|
30
|
+
ctx.type = path.extname(ctx.path);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
return next();
|
|
34
|
+
};
|
|
52
35
|
};
|
|
53
|
-
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
export { site_file_default as default };
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EggConfigFactory } from "../lib/define.js";
|
|
2
|
+
import "../index.js";
|
|
3
|
+
|
|
4
|
+
//#region src/config/config.default.d.ts
|
|
5
|
+
|
|
2
6
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
+
* The configuration of egg application, can be access by `app.config`
|
|
8
|
+
* @class Config
|
|
9
|
+
* @since 1.0.0
|
|
10
|
+
*/
|
|
7
11
|
declare const factory: EggConfigFactory;
|
|
8
|
-
|
|
12
|
+
//#endregion
|
|
13
|
+
export { factory as default };
|