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.
Files changed (101) hide show
  1. package/dist/agent.d.ts +7 -3
  2. package/dist/agent.js +10 -6
  3. package/dist/ajv.d.ts +1 -1
  4. package/dist/ajv.js +3 -2
  5. package/dist/aop.d.ts +1 -1
  6. package/dist/aop.js +3 -2
  7. package/dist/app/extend/context.d.ts +181 -178
  8. package/dist/app/extend/context.js +244 -259
  9. package/dist/app/extend/helper.d.ts +40 -35
  10. package/dist/app/extend/helper.js +45 -41
  11. package/dist/app/extend/request.d.ts +135 -131
  12. package/dist/app/extend/request.js +219 -258
  13. package/dist/app/extend/response.d.ts +28 -24
  14. package/dist/app/extend/response.js +36 -34
  15. package/dist/app/middleware/body_parser.d.ts +2 -2
  16. package/dist/app/middleware/body_parser.js +7 -3
  17. package/dist/app/middleware/meta.d.ts +8 -8
  18. package/dist/app/middleware/meta.js +15 -18
  19. package/dist/app/middleware/notfound.d.ts +8 -5
  20. package/dist/app/middleware/notfound.js +25 -28
  21. package/dist/app/middleware/override_method.d.ts +2 -2
  22. package/dist/app/middleware/override_method.js +7 -3
  23. package/dist/app/middleware/site_file.d.ts +11 -7
  24. package/dist/app/middleware/site_file.js +37 -52
  25. package/dist/config/config.default.d.ts +11 -6
  26. package/dist/config/config.default.js +258 -375
  27. package/dist/config/config.local.d.ts +6 -3
  28. package/dist/config/config.local.js +7 -8
  29. package/dist/config/config.unittest.d.ts +6 -3
  30. package/dist/config/config.unittest.js +10 -8
  31. package/dist/config/plugin.d.ts +6 -2
  32. package/dist/config/plugin.js +67 -131
  33. package/dist/dal.d.ts +1 -1
  34. package/dist/dal.js +3 -2
  35. package/dist/errors.d.ts +1 -1
  36. package/dist/errors.js +3 -2
  37. package/dist/helper.d.ts +1 -1
  38. package/dist/helper.js +3 -2
  39. package/dist/index.d.ts +24 -106
  40. package/dist/index.js +23 -89
  41. package/dist/lib/agent.d.ts +21 -15
  42. package/dist/lib/agent.js +53 -45
  43. package/dist/lib/application.d.ts +60 -54
  44. package/dist/lib/application.js +199 -249
  45. package/dist/lib/core/base_context_class.d.ts +23 -17
  46. package/dist/lib/core/base_context_class.js +17 -15
  47. package/dist/lib/core/base_context_logger.d.ts +39 -35
  48. package/dist/lib/core/base_context_logger.js +58 -60
  49. package/dist/lib/core/base_hook_class.d.ts +18 -11
  50. package/dist/lib/core/base_hook_class.js +26 -22
  51. package/dist/lib/core/context_httpclient.d.ts +21 -16
  52. package/dist/lib/core/context_httpclient.js +29 -26
  53. package/dist/lib/core/httpclient.d.ts +14 -12
  54. package/dist/lib/core/httpclient.js +34 -37
  55. package/dist/lib/core/logger.d.ts +7 -3
  56. package/dist/lib/core/logger.js +30 -36
  57. package/dist/lib/core/messenger/IMessenger.d.ts +53 -49
  58. package/dist/lib/core/messenger/IMessenger.js +1 -2
  59. package/dist/lib/core/messenger/base.d.ts +11 -7
  60. package/dist/lib/core/messenger/base.js +30 -29
  61. package/dist/lib/core/messenger/index.d.ts +10 -6
  62. package/dist/lib/core/messenger/index.js +11 -8
  63. package/dist/lib/core/messenger/ipc.d.ts +62 -57
  64. package/dist/lib/core/messenger/ipc.js +126 -138
  65. package/dist/lib/core/messenger/local.d.ts +63 -58
  66. package/dist/lib/core/messenger/local.js +126 -131
  67. package/dist/lib/core/utils.d.ts +5 -2
  68. package/dist/lib/core/utils.js +44 -66
  69. package/dist/lib/define.d.ts +72 -67
  70. package/dist/lib/define.js +54 -53
  71. package/dist/lib/egg.d.ts +283 -281
  72. package/dist/lib/egg.js +512 -573
  73. package/dist/lib/error/CookieLimitExceedError.d.ts +7 -4
  74. package/dist/lib/error/CookieLimitExceedError.js +15 -12
  75. package/dist/lib/error/MessageUnhandledRejectionError.d.ts +7 -4
  76. package/dist/lib/error/MessageUnhandledRejectionError.js +15 -12
  77. package/dist/lib/error/index.d.ts +3 -2
  78. package/dist/lib/error/index.js +4 -3
  79. package/dist/lib/loader/AgentWorkerLoader.d.ts +15 -10
  80. package/dist/lib/loader/AgentWorkerLoader.js +22 -18
  81. package/dist/lib/loader/AppWorkerLoader.d.ts +20 -15
  82. package/dist/lib/loader/AppWorkerLoader.js +35 -37
  83. package/dist/lib/loader/EggApplicationLoader.d.ts +7 -3
  84. package/dist/lib/loader/EggApplicationLoader.js +7 -4
  85. package/dist/lib/loader/index.d.ts +4 -3
  86. package/dist/lib/loader/index.js +5 -4
  87. package/dist/lib/start.d.ts +24 -20
  88. package/dist/lib/start.js +32 -42
  89. package/dist/lib/types.d.ts +288 -286
  90. package/dist/lib/types.js +2 -2
  91. package/dist/lib/types.plugin.d.ts +21 -21
  92. package/dist/lib/types.plugin.js +23 -24
  93. package/dist/orm.d.ts +1 -1
  94. package/dist/orm.js +3 -2
  95. package/dist/schedule.d.ts +2 -2
  96. package/dist/schedule.js +5 -5
  97. package/dist/transaction.d.ts +1 -1
  98. package/dist/transaction.js +3 -2
  99. package/dist/urllib.d.ts +1 -1
  100. package/dist/urllib.js +3 -2
  101. package/package.json +60 -64
@@ -1,133 +1,128 @@
1
- import { debuglog } from 'node:util';
2
1
  import { BaseMessenger } from "./base.js";
3
- const debug = debuglog('egg/lib/core/messenger/local');
2
+ import { debuglog } from "node:util";
3
+
4
+ //#region src/lib/core/messenger/local.ts
5
+ const debug = debuglog("egg/lib/core/messenger/local");
4
6
  /**
5
- * Communication between app worker and agent worker with EventEmitter
6
- */
7
- export class Messenger extends BaseMessenger {
8
- pid;
9
- constructor(egg) {
10
- super(egg);
11
- this.pid = String(process.pid);
12
- }
13
- /**
14
- * Send message to all agent and app
15
- * @param {String} action - message key
16
- * @param {Object} data - message value
17
- * @return {Messenger} this
18
- */
19
- broadcast(action, data) {
20
- debug('[%s:%s] broadcast %s with %j', this.egg.type, this.pid, action, data);
21
- this.send(action, data, 'both');
22
- return this;
23
- }
24
- /**
25
- * send message to the specified process
26
- * Notice: in single process mode, it only can send to self process,
27
- * and it will send to both agent and app's messengers.
28
- * @param {String} workerId - the workerId of the receiver
29
- * @param {String} action - message key
30
- * @param {Object} data - message value
31
- * @return {Messenger} this
32
- */
33
- sendTo(workerId, action, data) {
34
- debug('[%s:%s] send %s with %j to %s', this.egg.type, this.pid, action, data, workerId);
35
- if (String(workerId) !== this.pid) {
36
- return this;
37
- }
38
- this.send(action, data, 'both');
39
- return this;
40
- }
41
- /**
42
- * send message to one worker by random
43
- * Notice: in single process mode, we only start one agent worker and one app worker
44
- * - if it's running in agent, it will send to one of app workers
45
- * - if it's running in app, it will send to agent
46
- * @param {String} action - message key
47
- * @param {Object} data - message value
48
- * @return {Messenger} this
49
- */
50
- sendRandom(action, data) {
51
- debug('[%s:%s] send %s with %o to opposite', this.egg.type, this.pid, action, data);
52
- this.send(action, data, 'opposite');
53
- return this;
54
- }
55
- /**
56
- * send message to app
57
- * @param {String} action - message key
58
- * @param {Object} data - message value
59
- * @return {Messenger} this
60
- */
61
- sendToApp(action, data) {
62
- debug('[%s:%s] send %s with %o to all app', this.egg.type, this.pid, action, data);
63
- this.send(action, data, 'application');
64
- return this;
65
- }
66
- /**
67
- * send message to agent
68
- * @param {String} action - message key
69
- * @param {Object} data - message value
70
- * @return {Messenger} this
71
- */
72
- sendToAgent(action, data) {
73
- debug('[%s:%s] send %s with %o to all agent', this.egg.type, this.pid, action, data);
74
- this.send(action, data, 'agent');
75
- return this;
76
- }
77
- /**
78
- * @param {String} action - message key
79
- * @param {Object} data - message value
80
- * @param {String} to - let master know how to send message
81
- * @return {Messenger} this
82
- */
83
- send(action, data, to) {
84
- if (to === 'app') {
85
- // alias app to application
86
- to = 'application';
87
- }
88
- // use nextTick to keep it async as IPC messenger
89
- process.nextTick(() => {
90
- const { egg } = this;
91
- let application;
92
- let agent;
93
- let opposite;
94
- if (egg.type === 'application') {
95
- application = egg;
96
- agent = egg.agent;
97
- opposite = agent;
98
- }
99
- else {
100
- agent = egg;
101
- application = egg.application;
102
- opposite = application;
103
- }
104
- if (!to) {
105
- to = egg.type === 'application' ? 'agent' : 'application';
106
- }
107
- debug('[%s:%s] send action:%s with %o to %s', this.egg.type, this.pid, action, data, to);
108
- if (application && application.messenger && (to === 'application' || to === 'both')) {
109
- application.messenger.onMessage({ action, data });
110
- }
111
- if (agent && agent.messenger && (to === 'agent' || to === 'both')) {
112
- agent.messenger.onMessage({ action, data });
113
- }
114
- if (opposite && opposite.messenger && to === 'opposite') {
115
- opposite.messenger.onMessage({ action, data });
116
- }
117
- });
118
- return this;
119
- }
120
- onMessage(message) {
121
- if (typeof message?.action === 'string') {
122
- debug('[%s:%s] got message %s with %j', this.egg.type, this.pid, message.action, message.data);
123
- this.emit(message.action, message.data);
124
- }
125
- else {
126
- debug('[%s:%s] got an invalid message %j', this.egg.type, this.pid, message);
127
- }
128
- }
129
- close() {
130
- this.removeAllListeners();
131
- }
132
- }
133
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibG9jYWwuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9zcmMvbGliL2NvcmUvbWVzc2VuZ2VyL2xvY2FsLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxRQUFRLEVBQUUsTUFBTSxXQUFXLENBQUM7QUFHckMsT0FBTyxFQUFFLGFBQWEsRUFBRSxNQUFNLFdBQVcsQ0FBQztBQUcxQyxNQUFNLEtBQUssR0FBRyxRQUFRLENBQUMsOEJBQThCLENBQUMsQ0FBQztBQUV2RDs7R0FFRztBQUNILE1BQU0sT0FBTyxTQUFVLFNBQVEsYUFBYTtJQUNqQyxHQUFHLENBQVM7SUFFckIsWUFBWSxHQUF1QjtRQUNqQyxLQUFLLENBQUMsR0FBRyxDQUFDLENBQUM7UUFDWCxJQUFJLENBQUMsR0FBRyxHQUFHLE1BQU0sQ0FBQyxPQUFPLENBQUMsR0FBRyxDQUFDLENBQUM7SUFDakMsQ0FBQztJQUVEOzs7Ozt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messenger = class extends BaseMessenger {
10
+ pid;
11
+ constructor(egg) {
12
+ super(egg);
13
+ this.pid = String(process.pid);
14
+ }
15
+ /**
16
+ * Send message to all agent and app
17
+ * @param {String} action - message key
18
+ * @param {Object} data - message value
19
+ * @return {Messenger} this
20
+ */
21
+ broadcast(action, data) {
22
+ debug("[%s:%s] broadcast %s with %j", this.egg.type, this.pid, action, data);
23
+ this.send(action, data, "both");
24
+ return this;
25
+ }
26
+ /**
27
+ * send message to the specified process
28
+ * Notice: in single process mode, it only can send to self process,
29
+ * and it will send to both agent and app's messengers.
30
+ * @param {String} workerId - the workerId of the receiver
31
+ * @param {String} action - message key
32
+ * @param {Object} data - message value
33
+ * @return {Messenger} this
34
+ */
35
+ sendTo(workerId, action, data) {
36
+ debug("[%s:%s] send %s with %j to %s", this.egg.type, this.pid, action, data, workerId);
37
+ if (String(workerId) !== this.pid) return this;
38
+ this.send(action, data, "both");
39
+ return this;
40
+ }
41
+ /**
42
+ * send message to one worker by random
43
+ * Notice: in single process mode, we only start one agent worker and one app worker
44
+ * - if it's running in agent, it will send to one of app workers
45
+ * - if it's running in app, it will send to agent
46
+ * @param {String} action - message key
47
+ * @param {Object} data - message value
48
+ * @return {Messenger} this
49
+ */
50
+ sendRandom(action, data) {
51
+ debug("[%s:%s] send %s with %o to opposite", this.egg.type, this.pid, action, data);
52
+ this.send(action, data, "opposite");
53
+ return this;
54
+ }
55
+ /**
56
+ * send message to app
57
+ * @param {String} action - message key
58
+ * @param {Object} data - message value
59
+ * @return {Messenger} this
60
+ */
61
+ sendToApp(action, data) {
62
+ debug("[%s:%s] send %s with %o to all app", this.egg.type, this.pid, action, data);
63
+ this.send(action, data, "application");
64
+ return this;
65
+ }
66
+ /**
67
+ * send message to agent
68
+ * @param {String} action - message key
69
+ * @param {Object} data - message value
70
+ * @return {Messenger} this
71
+ */
72
+ sendToAgent(action, data) {
73
+ debug("[%s:%s] send %s with %o to all agent", this.egg.type, this.pid, action, data);
74
+ this.send(action, data, "agent");
75
+ return this;
76
+ }
77
+ /**
78
+ * @param {String} action - message key
79
+ * @param {Object} data - message value
80
+ * @param {String} to - let master know how to send message
81
+ * @return {Messenger} this
82
+ */
83
+ send(action, data, to) {
84
+ if (to === "app") to = "application";
85
+ process.nextTick(() => {
86
+ const { egg } = this;
87
+ let application;
88
+ let agent;
89
+ let opposite;
90
+ if (egg.type === "application") {
91
+ application = egg;
92
+ agent = egg.agent;
93
+ opposite = agent;
94
+ } else {
95
+ agent = egg;
96
+ application = egg.application;
97
+ opposite = application;
98
+ }
99
+ if (!to) to = egg.type === "application" ? "agent" : "application";
100
+ debug("[%s:%s] send action:%s with %o to %s", this.egg.type, this.pid, action, data, to);
101
+ if (application && application.messenger && (to === "application" || to === "both")) application.messenger.onMessage({
102
+ action,
103
+ data
104
+ });
105
+ if (agent && agent.messenger && (to === "agent" || to === "both")) agent.messenger.onMessage({
106
+ action,
107
+ data
108
+ });
109
+ if (opposite && opposite.messenger && to === "opposite") opposite.messenger.onMessage({
110
+ action,
111
+ data
112
+ });
113
+ });
114
+ return this;
115
+ }
116
+ onMessage(message) {
117
+ if (typeof message?.action === "string") {
118
+ debug("[%s:%s] got message %s with %j", this.egg.type, this.pid, message.action, message.data);
119
+ this.emit(message.action, message.data);
120
+ } else debug("[%s:%s] got an invalid message %j", this.egg.type, this.pid, message);
121
+ }
122
+ close() {
123
+ this.removeAllListeners();
124
+ }
125
+ };
126
+
127
+ //#endregion
128
+ export { Messenger };
@@ -1,2 +1,5 @@
1
- export declare function convertObject(obj: any, ignore?: string | RegExp | (string | RegExp)[]): any;
2
- export declare function safeParseURL(url: string): URL | null;
1
+ //#region src/lib/core/utils.d.ts
2
+ declare function convertObject(obj: any, ignore?: string | RegExp | (string | RegExp)[]): any;
3
+ declare function safeParseURL(url: string): URL | null;
4
+ //#endregion
5
+ export { convertObject, safeParseURL };
@@ -1,70 +1,48 @@
1
- import util from 'node:util';
2
- import { isSymbol, isRegExp, isPrimitive, isClass, isFunction, isGeneratorFunction, isAsyncFunction } from 'is-type-of';
3
- export function convertObject(obj, ignore = []) {
4
- if (!Array.isArray(ignore)) {
5
- ignore = [ignore];
6
- }
7
- for (const key of Object.keys(obj)) {
8
- obj[key] = convertValue(key, obj[key], ignore);
9
- }
10
- return obj;
1
+ import util from "node:util";
2
+ import { isAsyncFunction, isClass, isFunction, isGeneratorFunction, isPrimitive, isRegExp, isSymbol } from "is-type-of";
3
+
4
+ //#region src/lib/core/utils.ts
5
+ function convertObject(obj, ignore = []) {
6
+ if (!Array.isArray(ignore)) ignore = [ignore];
7
+ for (const key of Object.keys(obj)) obj[key] = convertValue(key, obj[key], ignore);
8
+ return obj;
11
9
  }
12
10
  function convertValue(key, value, ignore) {
13
- if (value === null || value === undefined) {
14
- return value;
15
- }
16
- let hit = false;
17
- for (const matchKey of ignore) {
18
- if (typeof matchKey === 'string' && matchKey === key) {
19
- hit = true;
20
- break;
21
- }
22
- else if (isRegExp(matchKey) && matchKey.test(key)) {
23
- hit = true;
24
- break;
25
- }
26
- }
27
- if (!hit) {
28
- if (isSymbol(value) || isRegExp(value) || value instanceof URL) {
29
- return value.toString();
30
- }
31
- if (isPrimitive(value) || Array.isArray(value)) {
32
- return value;
33
- }
34
- }
35
- // only convert recursively when it's a plain object,
36
- // o = {}
37
- if (Object.getPrototypeOf(value) === Object.prototype) {
38
- return convertObject(value, ignore);
39
- }
40
- // support class
41
- const name = value.name || 'anonymous';
42
- if (isClass(value)) {
43
- return `<Class ${name}>`;
44
- }
45
- // support generator function
46
- if (isFunction(value)) {
47
- if (isGeneratorFunction(value))
48
- return `<GeneratorFunction ${name}>`;
49
- if (isAsyncFunction(value))
50
- return `<AsyncFunction ${name}>`;
51
- return `<Function ${name}>`;
52
- }
53
- const typeName = value.constructor.name;
54
- if (typeName) {
55
- if (Buffer.isBuffer(value) || typeof value === 'string') {
56
- return `<${typeName} len: ${value.length}>`;
57
- }
58
- return `<${typeName}>`;
59
- }
60
- return util.format(value);
11
+ if (value === null || value === void 0) return value;
12
+ let hit = false;
13
+ for (const matchKey of ignore) if (typeof matchKey === "string" && matchKey === key) {
14
+ hit = true;
15
+ break;
16
+ } else if (isRegExp(matchKey) && matchKey.test(key)) {
17
+ hit = true;
18
+ break;
19
+ }
20
+ if (!hit) {
21
+ if (isSymbol(value) || isRegExp(value) || value instanceof URL) return value.toString();
22
+ if (isPrimitive(value) || Array.isArray(value)) return value;
23
+ }
24
+ if (Object.getPrototypeOf(value) === Object.prototype) return convertObject(value, ignore);
25
+ const name = value.name || "anonymous";
26
+ if (isClass(value)) return `<Class ${name}>`;
27
+ if (isFunction(value)) {
28
+ if (isGeneratorFunction(value)) return `<GeneratorFunction ${name}>`;
29
+ if (isAsyncFunction(value)) return `<AsyncFunction ${name}>`;
30
+ return `<Function ${name}>`;
31
+ }
32
+ const typeName = value.constructor.name;
33
+ if (typeName) {
34
+ if (Buffer.isBuffer(value) || typeof value === "string") return `<${typeName} len: ${value.length}>`;
35
+ return `<${typeName}>`;
36
+ }
37
+ return util.format(value);
61
38
  }
62
- export function safeParseURL(url) {
63
- try {
64
- return new URL(url);
65
- }
66
- catch {
67
- return null;
68
- }
39
+ function safeParseURL(url) {
40
+ try {
41
+ return new URL(url);
42
+ } catch {
43
+ return null;
44
+ }
69
45
  }
70
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbHMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvbGliL2NvcmUvdXRpbHMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxJQUFJLE1BQU0sV0FBVyxDQUFDO0FBRTdCLE9BQU8sRUFBRSxRQUFRLEVBQUUsUUFBUSxFQUFFLFdBQVcsRUFBRSxPQUFPLEVBQUUsVUFBVSxFQUFFLG1CQUFtQixFQUFFLGVBQWUsRUFBRSxNQUFNLFlBQVksQ0FBQztBQUV4SCxNQUFNLFVBQVUsYUFBYSxDQU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0FBSyxDQUFDLFdBQVcsQ0FBQyxJQUFJLENBQUM7SUFDeEMsSUFBSSxRQUFRLEVBQUUsQ0FBQztRQUNiLElBQUksTUFBTSxDQUFDLFFBQVEsQ0FBQyxLQUFLLENBQUMsSUFBSSxPQUFPLEtBQUssS0FBSyxRQUFRLEVBQUUsQ0FBQztZQUN4RCxPQUFPLElBQUksUUFBUSxTQUFTLEtBQUssQ0FBQyxNQUFNLEdBQUcsQ0FBQztRQUM5QyxDQUFDO1FBQ0QsT0FBTyxJQUFJLFFBQVEsR0FBRyxDQUFDO0lBQ3pCLENBQUM7SUFFRCxPQUFPLElBQUksQ0FBQyxNQUFNLENBQUMsS0FBSyxDQUFDLENBQUM7QUFDNUIsQ0FBQztBQUVELE1BQU0sVUFBVSxZQUFZLENBQUMsR0FBVztJQUN0QyxJQUFJLENBQUM7UUFDSCxPQUFPLElBQUksR0FBRyxDQUFDLEdBQUcsQ0FBQyxDQUFDO0lBQ3RCLENBQUM7SUFBQyxNQUFNLENBQUM7UUFDUCxPQUFPLElBQUksQ0FBQztJQUNkLENBQUM7QUFDSCxDQUFDIn0=
46
+
47
+ //#endregion
48
+ export { convertObject, safeParseURL };
@@ -1,76 +1,81 @@
1
- import type { PartialDeep } from 'type-fest';
2
- import type { EggAppConfig, EggAppInfo, EggEnvType } from './types.ts';
1
+ import { EggAppConfig, EggAppInfo, EggEnvType } from "./types.js";
2
+ import { PartialDeep } from "type-fest";
3
+
4
+ //#region src/lib/define.d.ts
5
+
3
6
  /**
4
- * Partial EggAppConfig
5
- */
6
- export type PartialEggConfig = PartialDeep<EggAppConfig>;
7
+ * Partial EggAppConfig
8
+ */
9
+ type PartialEggConfig = PartialDeep<EggAppConfig>;
7
10
  /**
8
- * Configuration factory function return type
9
- */
10
- export type EggConfigFactory = (appInfo: EggAppInfo) => PartialEggConfig;
11
+ * Configuration factory function return type
12
+ */
13
+ type EggConfigFactory = (appInfo: EggAppInfo) => PartialEggConfig;
11
14
  /**
12
- * Define configuration with type safety
13
- * @example
14
- * ```ts
15
- * import { defineConfig } from 'egg';
16
- *
17
- * export default defineConfig({
18
- * keys: 'my-keys',
19
- * middleware: []
20
- * });
21
- * ```
22
- */
23
- export declare function defineConfig(config: PartialEggConfig): PartialEggConfig;
15
+ * Define configuration with type safety
16
+ * @example
17
+ * ```ts
18
+ * import { defineConfig } from 'egg';
19
+ *
20
+ * export default defineConfig({
21
+ * keys: 'my-keys',
22
+ * middleware: []
23
+ * });
24
+ * ```
25
+ */
26
+ declare function defineConfig(config: PartialEggConfig): PartialEggConfig;
24
27
  /**
25
- * Define configuration factory function with type safety
26
- * @example
27
- * ```ts
28
- * export default defineConfigFactory((appInfo): PartialEggConfig => ({
29
- * keys: appInfo.name + '_keys',
30
- * middleware: []
31
- * }));
32
- * ```
33
- */
34
- export declare function defineConfigFactory(configFactory: EggConfigFactory): EggConfigFactory;
28
+ * Define configuration factory function with type safety
29
+ * @example
30
+ * ```ts
31
+ * export default defineConfigFactory((appInfo): PartialEggConfig => ({
32
+ * keys: appInfo.name + '_keys',
33
+ * middleware: []
34
+ * }));
35
+ * ```
36
+ */
37
+ declare function defineConfigFactory(configFactory: EggConfigFactory): EggConfigFactory;
35
38
  /**
36
- * Define plugin meta with type safety
37
- */
38
- export interface EggPluginMeta {
39
- /** the plugin name, it can be used in `dep` */
40
- name: string;
41
- /** whether enabled */
42
- enable: boolean;
43
- /** the directory of the plugin package */
44
- path: string;
45
- /** the dependent plugins, you can use the plugin name */
46
- dependencies?: string[];
47
- /** the optional dependent plugins. */
48
- optionalDependencies?: string[];
49
- /** specify the serverEnv that only enable the plugin in it, default to all envs */
50
- env?: EggEnvType[];
39
+ * Define plugin meta with type safety
40
+ */
41
+ interface EggPluginMeta {
42
+ /** the plugin name, it can be used in `dep` */
43
+ name: string;
44
+ /** whether enabled */
45
+ enable: boolean;
46
+ /** the directory of the plugin package */
47
+ path: string;
48
+ /** the dependent plugins, you can use the plugin name */
49
+ dependencies?: string[];
50
+ /** the optional dependent plugins. */
51
+ optionalDependencies?: string[];
52
+ /** specify the serverEnv that only enable the plugin in it, default to all envs */
53
+ env?: EggEnvType[];
51
54
  }
52
55
  /**
53
- * Egg plugin options, user can't provide name, it will be generated by the plugin factory.
54
- */
55
- export type EggPluginOptions = PartialDeep<Omit<EggPluginMeta, 'name'>>;
56
+ * Egg plugin options, user can't provide name, it will be generated by the plugin factory.
57
+ */
58
+ type EggPluginOptions = PartialDeep<Omit<EggPluginMeta, "name">>;
56
59
  /**
57
- * Egg plugin factory type, the return value is a record of plugin name and plugin meta.
58
- */
59
- export type EggPluginFactory = (options?: EggPluginOptions) => Record<string, EggPluginMeta>;
60
+ * Egg plugin factory type, the return value is a record of plugin name and plugin meta.
61
+ */
62
+ type EggPluginFactory = (options?: EggPluginOptions) => Record<string, EggPluginMeta>;
60
63
  /**
61
- * Define plugin factory with type safety
62
- * @example
63
- * ```ts
64
- * import { definePluginFactory } from 'egg';
65
- *
66
- * export default definePluginFactory({
67
- * name: 'my-plugin',
68
- * enable: true,
69
- * path: 'path/to/my-plugin',
70
- * dependencies: ['watcher'],
71
- * optionalDependencies: ['view'],
72
- * env: ['local', 'unittest'],
73
- * });
74
- * ```
75
- */
76
- export declare function definePluginFactory(pluginMeta: EggPluginMeta): EggPluginFactory;
64
+ * Define plugin factory with type safety
65
+ * @example
66
+ * ```ts
67
+ * import { definePluginFactory } from 'egg';
68
+ *
69
+ * export default definePluginFactory({
70
+ * name: 'my-plugin',
71
+ * enable: true,
72
+ * path: 'path/to/my-plugin',
73
+ * dependencies: ['watcher'],
74
+ * optionalDependencies: ['view'],
75
+ * env: ['local', 'unittest'],
76
+ * });
77
+ * ```
78
+ */
79
+ declare function definePluginFactory(pluginMeta: EggPluginMeta): EggPluginFactory;
80
+ //#endregion
81
+ export { EggConfigFactory, EggPluginFactory, EggPluginMeta, EggPluginOptions, PartialEggConfig, defineConfig, defineConfigFactory, definePluginFactory };