egg 4.1.0-beta.35 → 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 +199 -249
- 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,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
//#region src/lib/error/CookieLimitExceedError.d.ts
|
|
2
|
+
declare class CookieLimitExceedError extends Error {
|
|
3
|
+
key: string;
|
|
4
|
+
cookie: string;
|
|
5
|
+
constructor(key: string, cookie: string);
|
|
5
6
|
}
|
|
7
|
+
//#endregion
|
|
8
|
+
export { CookieLimitExceedError };
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
1
|
+
//#region src/lib/error/CookieLimitExceedError.ts
|
|
2
|
+
var CookieLimitExceedError = class extends Error {
|
|
3
|
+
key;
|
|
4
|
+
cookie;
|
|
5
|
+
constructor(key, cookie) {
|
|
6
|
+
super(`cookie ${key}'s length(${cookie.length}) exceed the limit(4093)`);
|
|
7
|
+
this.name = this.constructor.name;
|
|
8
|
+
this.key = key;
|
|
9
|
+
this.cookie = cookie;
|
|
10
|
+
Error.captureStackTrace(this, this.constructor);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
export { CookieLimitExceedError };
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
//#region src/lib/error/MessageUnhandledRejectionError.d.ts
|
|
2
|
+
declare class MessageUnhandledRejectionError extends Error {
|
|
3
|
+
event: string | symbol;
|
|
4
|
+
args: any[];
|
|
5
|
+
constructor(err: Error, event: string | symbol, ...args: any[]);
|
|
5
6
|
}
|
|
7
|
+
//#endregion
|
|
8
|
+
export { MessageUnhandledRejectionError };
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
1
|
+
//#region src/lib/error/MessageUnhandledRejectionError.ts
|
|
2
|
+
var MessageUnhandledRejectionError = class extends Error {
|
|
3
|
+
event;
|
|
4
|
+
args;
|
|
5
|
+
constructor(err, event, ...args) {
|
|
6
|
+
super(`event: ${String(event)}, error: ${err.message}`, { cause: err });
|
|
7
|
+
this.name = this.constructor.name;
|
|
8
|
+
this.event = event;
|
|
9
|
+
this.args = args;
|
|
10
|
+
Error.captureStackTrace(this, this.constructor);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
export { MessageUnhandledRejectionError };
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { CookieLimitExceedError } from "./CookieLimitExceedError.js";
|
|
2
|
+
import { MessageUnhandledRejectionError } from "./MessageUnhandledRejectionError.js";
|
|
3
|
+
export { CookieLimitExceedError, MessageUnhandledRejectionError };
|
package/dist/lib/error/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { CookieLimitExceedError } from "./CookieLimitExceedError.js";
|
|
2
|
+
import { MessageUnhandledRejectionError } from "./MessageUnhandledRejectionError.js";
|
|
3
|
+
|
|
4
|
+
export { CookieLimitExceedError, MessageUnhandledRejectionError };
|
|
@@ -1,12 +1,17 @@
|
|
|
1
|
-
import { EggApplicationLoader } from
|
|
1
|
+
import { EggApplicationLoader } from "./EggApplicationLoader.js";
|
|
2
|
+
|
|
3
|
+
//#region src/lib/loader/AgentWorkerLoader.d.ts
|
|
4
|
+
|
|
2
5
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
* Agent worker process loader
|
|
7
|
+
* @see https://github.com/eggjs/egg-core/blob/master/src/loader/egg_loader.ts
|
|
8
|
+
*/
|
|
9
|
+
declare class AgentWorkerLoader extends EggApplicationLoader {
|
|
10
|
+
/**
|
|
11
|
+
* loadPlugin first, then loadConfig
|
|
12
|
+
*/
|
|
13
|
+
loadConfig(): Promise<void>;
|
|
14
|
+
load(): Promise<void>;
|
|
12
15
|
}
|
|
16
|
+
//#endregion
|
|
17
|
+
export { AgentWorkerLoader };
|
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
import { EggApplicationLoader } from "./EggApplicationLoader.js";
|
|
2
|
+
|
|
3
|
+
//#region src/lib/loader/AgentWorkerLoader.ts
|
|
2
4
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
5
|
+
* Agent worker process loader
|
|
6
|
+
* @see https://github.com/eggjs/egg-core/blob/master/src/loader/egg_loader.ts
|
|
7
|
+
*/
|
|
8
|
+
var AgentWorkerLoader = class extends EggApplicationLoader {
|
|
9
|
+
/**
|
|
10
|
+
* loadPlugin first, then loadConfig
|
|
11
|
+
*/
|
|
12
|
+
async loadConfig() {
|
|
13
|
+
await this.loadPlugin();
|
|
14
|
+
await super.loadConfig();
|
|
15
|
+
}
|
|
16
|
+
async load() {
|
|
17
|
+
await this.loadAgentExtend();
|
|
18
|
+
await this.loadContextExtend();
|
|
19
|
+
await this.loadCustomAgent();
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
export { AgentWorkerLoader };
|
|
@@ -1,17 +1,22 @@
|
|
|
1
|
-
import { EggApplicationLoader } from
|
|
1
|
+
import { EggApplicationLoader } from "./EggApplicationLoader.js";
|
|
2
|
+
|
|
3
|
+
//#region src/lib/loader/AppWorkerLoader.d.ts
|
|
4
|
+
|
|
2
5
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
6
|
+
* App worker process Loader, will load plugins
|
|
7
|
+
* @see https://github.com/eggjs/egg-core/blob/master/src/loader/egg_loader.ts
|
|
8
|
+
*/
|
|
9
|
+
declare class AppWorkerLoader extends EggApplicationLoader {
|
|
10
|
+
/**
|
|
11
|
+
* loadPlugin first, then loadConfig
|
|
12
|
+
* @since 1.0.0
|
|
13
|
+
*/
|
|
14
|
+
loadConfig(): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Load all directories in convention
|
|
17
|
+
* @since 1.0.0
|
|
18
|
+
*/
|
|
19
|
+
load(): Promise<void>;
|
|
17
20
|
}
|
|
21
|
+
//#endregion
|
|
22
|
+
export { AppWorkerLoader };
|
|
@@ -1,39 +1,37 @@
|
|
|
1
1
|
import { EggApplicationLoader } from "./EggApplicationLoader.js";
|
|
2
|
+
|
|
3
|
+
//#region src/lib/loader/AppWorkerLoader.ts
|
|
2
4
|
/**
|
|
3
|
-
|
|
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
|
-
|
|
36
|
-
await this.loadRouter(); // Depend on controllers
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQXBwV29ya2VyTG9hZGVyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2xpYi9sb2FkZXIvQXBwV29ya2VyTG9hZGVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxvQkFBb0IsRUFBRSxNQUFNLDJCQUEyQixDQUFDO0FBRWpFOzs7R0FHRztBQUNILE1BQU0sT0FBTyxlQUFnQixTQUFRLG9CQUFvQjtJQUN2RDs7O09BR0c7SUFDSCxLQUFLLENBQUMsVUFBVTtRQUNkLE1BQU0sSUFBSSxDQUFDLFVBQVUsRUFBRSxDQUFDO1FBQ3hCLE1BQU0sS0FBSyxDQUFDLFVBQVUsRUFBRSxDQUFDO0lBQzNCLENBQUM7SUFFRDs7O09BR0c7SUFDSCxLQUFLLENBQUMsSUFBSTtRQUNSLHNCQUFzQjtRQUN0QixNQUFNLElBQUksQ0FBQyxxQkFBcUIsRUFBRSxDQUFDO1FBQ25DLE1BQU0sSUFBSSxDQUFDLGlCQUFpQixFQUFFLENBQUM7UUFDL0IsTUFBTSxJQUFJLENBQUMsa0JBQWtCLEVBQUUsQ0FBQztRQUNoQyxNQUFNLElBQUksQ0FBQyxpQkFBaUIsRUFBRSxDQUFDO1FBQy9CLE1BQU0sSUFBSSxDQUFDLGdCQUFnQixFQUFFLENBQUM7UUFFOUIsTUFBTSxJQUFJLENBQUMsZ0JBQWdCLEVBQUUsQ0FBQztRQUU5QixlQUFlO1FBQ2YsTUFBTSxJQUFJLENBQUMsYUFBYSxFQUFFLENBQUM7UUFDM0IsZUFBZTtRQUNmLE1BQU0sSUFBSSxDQUFDLFdBQVcsRUFBRSxDQUFDO1FBQ3pCLHNCQUFzQjtRQUN0QixNQUFNLElBQUksQ0FBQyxjQUFjLEVBQUUsQ0FBQztRQUM1QixNQUFNO1FBQ04sTUFBTSxJQUFJLENBQUMsY0FBYyxFQUFFLENBQUM7UUFDNUIsTUFBTTtRQUNOLE1BQU0sSUFBSSxDQUFDLFVBQVUsRUFBRSxDQUFDLENBQUMsd0JBQXdCO0lBQ25ELENBQUM7Q0FDRiJ9
|
|
5
|
+
* App worker process Loader, will load plugins
|
|
6
|
+
* @see https://github.com/eggjs/egg-core/blob/master/src/loader/egg_loader.ts
|
|
7
|
+
*/
|
|
8
|
+
var AppWorkerLoader = class extends EggApplicationLoader {
|
|
9
|
+
/**
|
|
10
|
+
* loadPlugin first, then loadConfig
|
|
11
|
+
* @since 1.0.0
|
|
12
|
+
*/
|
|
13
|
+
async loadConfig() {
|
|
14
|
+
await this.loadPlugin();
|
|
15
|
+
await super.loadConfig();
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Load all directories in convention
|
|
19
|
+
* @since 1.0.0
|
|
20
|
+
*/
|
|
21
|
+
async load() {
|
|
22
|
+
await this.loadApplicationExtend();
|
|
23
|
+
await this.loadRequestExtend();
|
|
24
|
+
await this.loadResponseExtend();
|
|
25
|
+
await this.loadContextExtend();
|
|
26
|
+
await this.loadHelperExtend();
|
|
27
|
+
await this.loadCustomLoader();
|
|
28
|
+
await this.loadCustomApp();
|
|
29
|
+
await this.loadService();
|
|
30
|
+
await this.loadMiddleware();
|
|
31
|
+
await this.loadController();
|
|
32
|
+
await this.loadRouter();
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
export { AppWorkerLoader };
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import { EggLoader } from
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { EggLoader } from "@eggjs/core";
|
|
2
|
+
|
|
3
|
+
//#region src/lib/loader/EggApplicationLoader.d.ts
|
|
4
|
+
declare abstract class EggApplicationLoader extends EggLoader {
|
|
5
|
+
abstract load(): Promise<void>;
|
|
4
6
|
}
|
|
7
|
+
//#endregion
|
|
8
|
+
export { EggApplicationLoader };
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import { EggLoader } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { EggLoader } from "@eggjs/core";
|
|
2
|
+
|
|
3
|
+
//#region src/lib/loader/EggApplicationLoader.ts
|
|
4
|
+
var EggApplicationLoader = class extends EggLoader {};
|
|
5
|
+
|
|
6
|
+
//#endregion
|
|
7
|
+
export { EggApplicationLoader };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { EggApplicationLoader } from "./EggApplicationLoader.js";
|
|
2
|
+
import { AppWorkerLoader } from "./AppWorkerLoader.js";
|
|
3
|
+
import { AgentWorkerLoader } from "./AgentWorkerLoader.js";
|
|
4
|
+
export { AgentWorkerLoader, AppWorkerLoader, EggApplicationLoader };
|
package/dist/lib/loader/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { EggApplicationLoader } from "./EggApplicationLoader.js";
|
|
2
|
+
import { AppWorkerLoader } from "./AppWorkerLoader.js";
|
|
3
|
+
import { AgentWorkerLoader } from "./AgentWorkerLoader.js";
|
|
4
|
+
|
|
5
|
+
export { AgentWorkerLoader, AppWorkerLoader, EggApplicationLoader };
|
package/dist/lib/start.d.ts
CHANGED
|
@@ -1,24 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import { EggPlugin } from "./types.js";
|
|
2
|
+
import { Agent } from "./agent.js";
|
|
3
|
+
import { Application } from "./application.js";
|
|
4
|
+
|
|
5
|
+
//#region src/lib/start.d.ts
|
|
6
|
+
interface StartEggOptions {
|
|
7
|
+
/** specify framework that can be absolute path or npm package */
|
|
8
|
+
framework?: string;
|
|
9
|
+
/** directory of application, default to `process.cwd()` */
|
|
10
|
+
baseDir?: string;
|
|
11
|
+
/** ignore single process mode warning */
|
|
12
|
+
ignoreWarning?: boolean;
|
|
13
|
+
mode?: "single";
|
|
14
|
+
env?: string;
|
|
15
|
+
plugins?: EggPlugin;
|
|
14
16
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
interface SingleModeApplication extends Application {
|
|
18
|
+
agent: SingleModeAgent;
|
|
17
19
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
interface SingleModeAgent extends Agent {
|
|
21
|
+
app: SingleModeApplication;
|
|
20
22
|
}
|
|
21
23
|
/**
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
* Start egg with single process
|
|
25
|
+
*/
|
|
26
|
+
declare function startEgg(options?: StartEggOptions): Promise<SingleModeApplication>;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { SingleModeAgent, SingleModeApplication, StartEggOptions, startEgg };
|
package/dist/lib/start.js
CHANGED
|
@@ -1,46 +1,36 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { importModule } from '@eggjs/utils';
|
|
3
|
-
import { readJSON } from 'utility';
|
|
4
1
|
import { Agent } from "./agent.js";
|
|
5
2
|
import { Application } from "./application.js";
|
|
6
|
-
import
|
|
3
|
+
import "./types.js";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { importModule } from "@eggjs/utils";
|
|
6
|
+
import { readJSON } from "utility";
|
|
7
|
+
|
|
8
|
+
//#region src/lib/start.ts
|
|
7
9
|
/**
|
|
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
|
-
const agent = new AgentClass({
|
|
33
|
-
...options,
|
|
34
|
-
});
|
|
35
|
-
await agent.ready();
|
|
36
|
-
const application = new ApplicationClass({
|
|
37
|
-
...options,
|
|
38
|
-
});
|
|
39
|
-
application.agent = agent;
|
|
40
|
-
agent.application = application;
|
|
41
|
-
await application.ready();
|
|
42
|
-
// emit egg-ready message in agent and application
|
|
43
|
-
application.messenger.broadcast('egg-ready');
|
|
44
|
-
return application;
|
|
10
|
+
* Start egg with single process
|
|
11
|
+
*/
|
|
12
|
+
async function startEgg(options = {}) {
|
|
13
|
+
options.baseDir = options.baseDir ?? process.cwd();
|
|
14
|
+
options.mode = "single";
|
|
15
|
+
if (!options.framework) try {
|
|
16
|
+
options.framework = (await readJSON(path.join(options.baseDir, "package.json"))).egg.framework;
|
|
17
|
+
} catch {}
|
|
18
|
+
let AgentClass = Agent;
|
|
19
|
+
let ApplicationClass = Application;
|
|
20
|
+
if (options.framework) {
|
|
21
|
+
const framework = await importModule(options.framework, { paths: [options.baseDir] });
|
|
22
|
+
AgentClass = framework.Agent;
|
|
23
|
+
ApplicationClass = framework.Application;
|
|
24
|
+
}
|
|
25
|
+
const agent = new AgentClass({ ...options });
|
|
26
|
+
await agent.ready();
|
|
27
|
+
const application = new ApplicationClass({ ...options });
|
|
28
|
+
application.agent = agent;
|
|
29
|
+
agent.application = application;
|
|
30
|
+
await application.ready();
|
|
31
|
+
application.messenger.broadcast("egg-ready");
|
|
32
|
+
return application;
|
|
45
33
|
}
|
|
46
|
-
|
|
34
|
+
|
|
35
|
+
//#endregion
|
|
36
|
+
export { startEgg };
|