@eggjs/core 7.0.0-beta.18 → 7.0.0-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/dist/index.d.ts +977 -12
- package/dist/index.js +2423 -10
- package/package.json +9 -9
- package/dist/base_context_class.d.ts +0 -21
- package/dist/base_context_class.js +0 -40
- package/dist/egg.d.ts +0 -248
- package/dist/egg.js +0 -358
- package/dist/lifecycle.d.ts +0 -84
- package/dist/lifecycle.js +0 -280
- package/dist/loader/context_loader.d.ts +0 -39
- package/dist/loader/context_loader.js +0 -79
- package/dist/loader/egg_loader.d.ts +0 -374
- package/dist/loader/egg_loader.js +0 -1184
- package/dist/loader/file_loader.d.ts +0 -105
- package/dist/loader/file_loader.js +0 -198
- package/dist/singleton.d.ts +0 -33
- package/dist/singleton.js +0 -107
- package/dist/types.d.ts +0 -56
- package/dist/utils/index.d.ts +0 -19
- package/dist/utils/index.js +0 -103
- package/dist/utils/sequencify.d.ts +0 -16
- package/dist/utils/sequencify.js +0 -46
- package/dist/utils/timing.d.ts +0 -24
- package/dist/utils/timing.js +0 -85
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,977 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { Application as KoaApplication, Context as KoaContext, MiddlewareFunc as KoaMiddlewareFunc, Next, Request as KoaRequest, Response as KoaResponse } from "@eggjs/koa";
|
|
2
|
+
import * as egg_logger0 from "egg-logger";
|
|
3
|
+
import { EggConsoleLogger, Logger } from "egg-logger";
|
|
4
|
+
import { EggRouter as Router, RegisterOptions, ResourcesController } from "@eggjs/router";
|
|
5
|
+
import { EventEmitter } from "node:events";
|
|
6
|
+
import { ReadyFunctionArg } from "get-ready";
|
|
7
|
+
import { Ready as Ready$1 } from "ready-callback";
|
|
8
|
+
|
|
9
|
+
//#region src/utils/index.d.ts
|
|
10
|
+
type Fun = (...args: unknown[]) => unknown;
|
|
11
|
+
declare function getCalleeFromStack(withLine?: boolean, stackIndex?: number): string;
|
|
12
|
+
declare const _default: {
|
|
13
|
+
deprecated(message: string): void;
|
|
14
|
+
extensions: any;
|
|
15
|
+
extensionNames: string[];
|
|
16
|
+
existsPath(filepath: string): Promise<boolean>;
|
|
17
|
+
loadFile(filepath: string): Promise<any>;
|
|
18
|
+
resolvePath(filepath: string, options?: {
|
|
19
|
+
paths?: string[];
|
|
20
|
+
}): string;
|
|
21
|
+
methods: string[];
|
|
22
|
+
callFn(fn: Fun, args?: unknown[], ctx?: unknown): Promise<unknown>;
|
|
23
|
+
getCalleeFromStack: typeof getCalleeFromStack;
|
|
24
|
+
getResolvedFilename(filepath: string, baseDir: string): string;
|
|
25
|
+
};
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/types.d.ts
|
|
28
|
+
interface EggAppInfo {
|
|
29
|
+
/** package.json */
|
|
30
|
+
pkg: Record<string, any>;
|
|
31
|
+
/** the application name from package.json */
|
|
32
|
+
name: string;
|
|
33
|
+
/** current directory of application */
|
|
34
|
+
baseDir: string;
|
|
35
|
+
/** equals to serverEnv */
|
|
36
|
+
env: string;
|
|
37
|
+
/** equals to serverScope */
|
|
38
|
+
scope: string;
|
|
39
|
+
/** home directory of the OS */
|
|
40
|
+
HOME: string;
|
|
41
|
+
/** baseDir when local and unittest, HOME when other environment */
|
|
42
|
+
root: string;
|
|
43
|
+
}
|
|
44
|
+
interface EggPluginInfo {
|
|
45
|
+
/** the plugin name, it can be used in `dep` */
|
|
46
|
+
name: string;
|
|
47
|
+
/** the package name of plugin */
|
|
48
|
+
package?: string;
|
|
49
|
+
version?: string;
|
|
50
|
+
/** whether enabled */
|
|
51
|
+
enable: boolean;
|
|
52
|
+
implicitEnable?: boolean;
|
|
53
|
+
/** the directory of the plugin package */
|
|
54
|
+
path?: string;
|
|
55
|
+
/** the dependent plugins, you can use the plugin name */
|
|
56
|
+
dependencies: string[];
|
|
57
|
+
/** the optional dependent plugins. */
|
|
58
|
+
optionalDependencies: string[];
|
|
59
|
+
dependents?: string[];
|
|
60
|
+
/** specify the serverEnv that only enable the plugin in it */
|
|
61
|
+
env: string[];
|
|
62
|
+
/** the file plugin config in. */
|
|
63
|
+
from: string;
|
|
64
|
+
}
|
|
65
|
+
interface CustomLoaderConfigItem {
|
|
66
|
+
/** the directory of the custom loader */
|
|
67
|
+
directory: string;
|
|
68
|
+
/** the inject object, it can be app or ctx */
|
|
69
|
+
inject: string;
|
|
70
|
+
/** whether load unit files */
|
|
71
|
+
loadunit?: boolean;
|
|
72
|
+
}
|
|
73
|
+
interface EggAppConfig extends Record<string, any> {
|
|
74
|
+
coreMiddleware: string[];
|
|
75
|
+
middleware: string[];
|
|
76
|
+
customLoader?: Record<string, CustomLoaderConfigItem>;
|
|
77
|
+
controller?: {
|
|
78
|
+
supportParams?: boolean;
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
//#endregion
|
|
82
|
+
//#region src/base_context_class.d.ts
|
|
83
|
+
/**
|
|
84
|
+
* BaseContextClass is a base class that can be extended,
|
|
85
|
+
* it's instantiated in context level,
|
|
86
|
+
* {@link Helper}, {@link Service} is extending it.
|
|
87
|
+
*/
|
|
88
|
+
declare class BaseContextClass {
|
|
89
|
+
ctx: Context;
|
|
90
|
+
app: EggCore;
|
|
91
|
+
config: Record<string, any>;
|
|
92
|
+
service: BaseContextClass;
|
|
93
|
+
/**
|
|
94
|
+
* @since 1.0.0
|
|
95
|
+
*/
|
|
96
|
+
constructor(ctx: Context);
|
|
97
|
+
}
|
|
98
|
+
//#endregion
|
|
99
|
+
//#region src/utils/timing.d.ts
|
|
100
|
+
interface TimingItem {
|
|
101
|
+
name: string;
|
|
102
|
+
start: number;
|
|
103
|
+
end?: number;
|
|
104
|
+
duration?: number;
|
|
105
|
+
pid: number;
|
|
106
|
+
index: number;
|
|
107
|
+
}
|
|
108
|
+
declare class Timing {
|
|
109
|
+
#private;
|
|
110
|
+
constructor();
|
|
111
|
+
init(): void;
|
|
112
|
+
start(name?: string, start?: number): TimingItem | undefined;
|
|
113
|
+
end(name?: string): TimingItem | undefined;
|
|
114
|
+
enable(): void;
|
|
115
|
+
disable(): void;
|
|
116
|
+
clear(): void;
|
|
117
|
+
toJSON(): TimingItem[];
|
|
118
|
+
itemToString(timelineEnd: number, item: TimingItem, times: number): string;
|
|
119
|
+
toString(prefix?: string, width?: number): string;
|
|
120
|
+
}
|
|
121
|
+
//#endregion
|
|
122
|
+
//#region src/lifecycle.d.ts
|
|
123
|
+
interface ILifecycleBoot {
|
|
124
|
+
fullPath?: string;
|
|
125
|
+
/**
|
|
126
|
+
* Ready to call configDidLoad,
|
|
127
|
+
* Config, plugin files are referred,
|
|
128
|
+
* this is the last chance to modify the config.
|
|
129
|
+
*/
|
|
130
|
+
configWillLoad?(): void;
|
|
131
|
+
/**
|
|
132
|
+
* Config, plugin files have loaded
|
|
133
|
+
*/
|
|
134
|
+
configDidLoad?(): void;
|
|
135
|
+
/**
|
|
136
|
+
* All files have loaded, start plugin here
|
|
137
|
+
*/
|
|
138
|
+
didLoad?(): Promise<void>;
|
|
139
|
+
/**
|
|
140
|
+
* All plugins have started, can do some thing before app ready
|
|
141
|
+
*/
|
|
142
|
+
willReady?(): Promise<void>;
|
|
143
|
+
/**
|
|
144
|
+
* Worker is ready, can do some things,
|
|
145
|
+
* don't need to block the app boot
|
|
146
|
+
*/
|
|
147
|
+
didReady?(err?: Error): Promise<void>;
|
|
148
|
+
/**
|
|
149
|
+
* Server is listening
|
|
150
|
+
*/
|
|
151
|
+
serverDidReady?(): Promise<void>;
|
|
152
|
+
/**
|
|
153
|
+
* Do some thing before app close
|
|
154
|
+
*/
|
|
155
|
+
beforeClose?(): Promise<void>;
|
|
156
|
+
}
|
|
157
|
+
type BootImplClass<T = ILifecycleBoot> = new (...args: any[]) => T;
|
|
158
|
+
interface LifecycleOptions {
|
|
159
|
+
baseDir: string;
|
|
160
|
+
app: EggCore;
|
|
161
|
+
logger: EggConsoleLogger;
|
|
162
|
+
}
|
|
163
|
+
type FunWithFullPath = Fun & {
|
|
164
|
+
fullPath?: string;
|
|
165
|
+
};
|
|
166
|
+
declare class Lifecycle extends EventEmitter {
|
|
167
|
+
#private;
|
|
168
|
+
loadReady: Ready$1;
|
|
169
|
+
bootReady: Ready$1;
|
|
170
|
+
options: LifecycleOptions;
|
|
171
|
+
readyTimeout: number;
|
|
172
|
+
constructor(options: Partial<LifecycleOptions>);
|
|
173
|
+
ready(): Promise<void>;
|
|
174
|
+
ready(flagOrFunction: ReadyFunctionArg): void;
|
|
175
|
+
get app(): EggCore;
|
|
176
|
+
get logger(): EggConsoleLogger<egg_logger0.LoggerOptions>;
|
|
177
|
+
get timing(): Timing;
|
|
178
|
+
legacyReadyCallback(name: string, opt?: object): (...args: unknown[]) => void;
|
|
179
|
+
addBootHook(bootHootOrBootClass: BootImplClass | ILifecycleBoot): void;
|
|
180
|
+
addFunctionAsBootHook<T = EggCore>(hook: (app: T) => void, fullPath?: string): void;
|
|
181
|
+
/**
|
|
182
|
+
* init boots and trigger config did config
|
|
183
|
+
*/
|
|
184
|
+
init(): void;
|
|
185
|
+
registerBeforeStart(scope: Fun, name: string): void;
|
|
186
|
+
registerBeforeClose(fn: FunWithFullPath, fullPath?: string): void;
|
|
187
|
+
close(): Promise<void>;
|
|
188
|
+
triggerConfigWillLoad(): void;
|
|
189
|
+
triggerConfigDidLoad(): void;
|
|
190
|
+
triggerDidLoad(): void;
|
|
191
|
+
triggerWillReady(): void;
|
|
192
|
+
triggerDidReady(err?: Error): Promise<void>;
|
|
193
|
+
triggerServerDidReady(): Promise<void>;
|
|
194
|
+
}
|
|
195
|
+
//#endregion
|
|
196
|
+
//#region src/loader/file_loader.d.ts
|
|
197
|
+
declare const FULLPATH: unique symbol;
|
|
198
|
+
declare const EXPORTS: unique symbol;
|
|
199
|
+
declare const CaseStyle: {
|
|
200
|
+
readonly camel: "camel";
|
|
201
|
+
readonly lower: "lower";
|
|
202
|
+
readonly upper: "upper";
|
|
203
|
+
};
|
|
204
|
+
type CaseStyle = (typeof CaseStyle)[keyof typeof CaseStyle];
|
|
205
|
+
type CaseStyleFunction = (filepath: string) => string[];
|
|
206
|
+
type FileLoaderInitializer = (exports: unknown, options: {
|
|
207
|
+
path: string;
|
|
208
|
+
pathName: string;
|
|
209
|
+
}) => unknown;
|
|
210
|
+
type FileLoaderFilter = (exports: unknown) => boolean;
|
|
211
|
+
interface FileLoaderOptions {
|
|
212
|
+
/** directories to be loaded */
|
|
213
|
+
directory: string | string[];
|
|
214
|
+
/** attach the target object from loaded files */
|
|
215
|
+
target: Record<string, any>;
|
|
216
|
+
/** match the files when load, support glob, default to all js files */
|
|
217
|
+
match?: string | string[];
|
|
218
|
+
/** ignore the files when load, support glob */
|
|
219
|
+
ignore?: string | string[];
|
|
220
|
+
/** custom file exports, receive two parameters, first is the inject object(if not js file, will be content buffer), second is an `options` object that contain `path` */
|
|
221
|
+
initializer?: FileLoaderInitializer;
|
|
222
|
+
/** determine whether invoke when exports is function */
|
|
223
|
+
call?: boolean;
|
|
224
|
+
/** determine whether override the property when get the same name */
|
|
225
|
+
override?: boolean;
|
|
226
|
+
/** an object that be the argument when invoke the function */
|
|
227
|
+
inject?: Record<string, any>;
|
|
228
|
+
/** a function that filter the exports which can be loaded */
|
|
229
|
+
filter?: FileLoaderFilter;
|
|
230
|
+
/** set property's case when converting a filepath to property list. */
|
|
231
|
+
caseStyle?: CaseStyle | CaseStyleFunction;
|
|
232
|
+
lowercaseFirst?: boolean;
|
|
233
|
+
}
|
|
234
|
+
interface FileLoaderParseItem {
|
|
235
|
+
fullpath: string;
|
|
236
|
+
properties: string[];
|
|
237
|
+
exports: object | Fun;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Load files from directory to target object.
|
|
241
|
+
* @since 1.0.0
|
|
242
|
+
*/
|
|
243
|
+
declare class FileLoader {
|
|
244
|
+
static get FULLPATH(): symbol;
|
|
245
|
+
static get EXPORTS(): symbol;
|
|
246
|
+
readonly options: FileLoaderOptions & Required<Pick<FileLoaderOptions, 'caseStyle'>>;
|
|
247
|
+
/**
|
|
248
|
+
* @class
|
|
249
|
+
* @param {Object} options - options
|
|
250
|
+
* @param {String|Array} options.directory - directories to be loaded
|
|
251
|
+
* @param {Object} options.target - attach the target object from loaded files
|
|
252
|
+
* @param {String} options.match - match the files when load, support glob, default to all js files
|
|
253
|
+
* @param {String} options.ignore - ignore the files when load, support glob
|
|
254
|
+
* @param {Function} options.initializer - custom file exports, receive two parameters, first is the inject object(if not js file, will be content buffer), second is an `options` object that contain `path`
|
|
255
|
+
* @param {Boolean} options.call - determine whether invoke when exports is function
|
|
256
|
+
* @param {Boolean} options.override - determine whether override the property when get the same name
|
|
257
|
+
* @param {Object} options.inject - an object that be the argument when invoke the function
|
|
258
|
+
* @param {Function} options.filter - a function that filter the exports which can be loaded
|
|
259
|
+
* @param {String|Function} options.caseStyle - set property's case when converting a filepath to property list.
|
|
260
|
+
*/
|
|
261
|
+
constructor(options: FileLoaderOptions);
|
|
262
|
+
/**
|
|
263
|
+
* attach items to target object. Mapping the directory to properties.
|
|
264
|
+
* `app/controller/group/repository.js` => `target.group.repository`
|
|
265
|
+
* @returns {Object} target
|
|
266
|
+
* @since 1.0.0
|
|
267
|
+
*/
|
|
268
|
+
load(): Promise<object>;
|
|
269
|
+
/**
|
|
270
|
+
* Parse files from given directories, then return an items list, each item contains properties and exports.
|
|
271
|
+
*
|
|
272
|
+
* For example, parse `app/controller/group/repository.js`
|
|
273
|
+
*
|
|
274
|
+
* ```
|
|
275
|
+
* module.exports = app => {
|
|
276
|
+
* return class RepositoryController extends app.Controller {};
|
|
277
|
+
* }
|
|
278
|
+
* ```
|
|
279
|
+
*
|
|
280
|
+
* It returns a item
|
|
281
|
+
*
|
|
282
|
+
* ```
|
|
283
|
+
* {
|
|
284
|
+
* properties: [ 'group', 'repository' ],
|
|
285
|
+
* exports: app => { ... },
|
|
286
|
+
* }
|
|
287
|
+
* ```
|
|
288
|
+
*
|
|
289
|
+
* `Properties` is an array that contains the directory of a filepath.
|
|
290
|
+
*
|
|
291
|
+
* `Exports` depends on type, if exports is a function, it will be called. if initializer is specified, it will be called with exports for customizing.
|
|
292
|
+
* @returns {Array} items
|
|
293
|
+
* @since 1.0.0
|
|
294
|
+
*/
|
|
295
|
+
protected parse(): Promise<FileLoaderParseItem[]>;
|
|
296
|
+
}
|
|
297
|
+
//#endregion
|
|
298
|
+
//#region src/loader/context_loader.d.ts
|
|
299
|
+
interface ClassLoaderOptions {
|
|
300
|
+
ctx: Context;
|
|
301
|
+
properties: any;
|
|
302
|
+
}
|
|
303
|
+
declare class ClassLoader {
|
|
304
|
+
#private;
|
|
305
|
+
readonly _cache: Map<any, any>;
|
|
306
|
+
_ctx: Context;
|
|
307
|
+
constructor(options: ClassLoaderOptions);
|
|
308
|
+
}
|
|
309
|
+
interface ContextLoaderOptions extends Omit<FileLoaderOptions, 'target'> {
|
|
310
|
+
/** required inject */
|
|
311
|
+
inject: Record<string, any>;
|
|
312
|
+
/** property name defined to target */
|
|
313
|
+
property: string | symbol;
|
|
314
|
+
/** determine the field name of inject object. */
|
|
315
|
+
fieldClass?: string;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Same as {@link FileLoader}, but it will attach file to `inject[fieldClass]`.
|
|
319
|
+
* The exports will be lazy loaded, such as `ctx.group.repository`.
|
|
320
|
+
* @augments FileLoader
|
|
321
|
+
* @since 1.0.0
|
|
322
|
+
*/
|
|
323
|
+
declare class ContextLoader extends FileLoader {
|
|
324
|
+
#private;
|
|
325
|
+
/**
|
|
326
|
+
* @class
|
|
327
|
+
* @param {Object} options - options same as {@link FileLoader}
|
|
328
|
+
* @param {String} options.fieldClass - determine the field name of inject object.
|
|
329
|
+
*/
|
|
330
|
+
constructor(options: ContextLoaderOptions);
|
|
331
|
+
}
|
|
332
|
+
//#endregion
|
|
333
|
+
//#region src/loader/egg_loader.d.ts
|
|
334
|
+
interface EggLoaderOptions {
|
|
335
|
+
/** server env */
|
|
336
|
+
env: string;
|
|
337
|
+
/** Application instance */
|
|
338
|
+
app: EggCore;
|
|
339
|
+
EggCoreClass?: typeof EggCore;
|
|
340
|
+
/** the directory of application */
|
|
341
|
+
baseDir: string;
|
|
342
|
+
/** egg logger */
|
|
343
|
+
logger: Logger;
|
|
344
|
+
/** server scope */
|
|
345
|
+
serverScope?: string;
|
|
346
|
+
/** custom plugins */
|
|
347
|
+
plugins?: Record<string, EggPluginInfo>;
|
|
348
|
+
}
|
|
349
|
+
type EggDirInfoType = 'app' | 'plugin' | 'framework';
|
|
350
|
+
interface EggDirInfo {
|
|
351
|
+
path: string;
|
|
352
|
+
type: EggDirInfoType;
|
|
353
|
+
}
|
|
354
|
+
declare class EggLoader {
|
|
355
|
+
#private;
|
|
356
|
+
readonly options: EggLoaderOptions;
|
|
357
|
+
readonly timing: Timing;
|
|
358
|
+
readonly pkg: Record<string, any>;
|
|
359
|
+
readonly eggPaths: string[];
|
|
360
|
+
readonly serverEnv: string;
|
|
361
|
+
readonly serverScope: string;
|
|
362
|
+
readonly appInfo: EggAppInfo;
|
|
363
|
+
dirs?: EggDirInfo[];
|
|
364
|
+
/**
|
|
365
|
+
* @class
|
|
366
|
+
* @param {Object} options - options
|
|
367
|
+
* @param {String} options.baseDir - the directory of application
|
|
368
|
+
* @param {EggCore} options.app - Application instance
|
|
369
|
+
* @param {Logger} options.logger - logger
|
|
370
|
+
* @param {Object} [options.plugins] - custom plugins
|
|
371
|
+
* @since 1.0.0
|
|
372
|
+
*/
|
|
373
|
+
constructor(options: EggLoaderOptions);
|
|
374
|
+
get app(): EggCore;
|
|
375
|
+
get lifecycle(): Lifecycle;
|
|
376
|
+
get logger(): Logger<egg_logger0.EggLoggerOptions>;
|
|
377
|
+
/**
|
|
378
|
+
* Get {@link AppInfo#env}
|
|
379
|
+
* @returns {String} env
|
|
380
|
+
* @see AppInfo#env
|
|
381
|
+
* @private
|
|
382
|
+
* @since 1.0.0
|
|
383
|
+
*/
|
|
384
|
+
protected getServerEnv(): string;
|
|
385
|
+
/**
|
|
386
|
+
* Get {@link AppInfo#scope}
|
|
387
|
+
* @returns {String} serverScope
|
|
388
|
+
* @private
|
|
389
|
+
*/
|
|
390
|
+
protected getServerScope(): string;
|
|
391
|
+
/**
|
|
392
|
+
* Get {@link AppInfo#name}
|
|
393
|
+
* @returns {String} appname
|
|
394
|
+
* @private
|
|
395
|
+
* @since 1.0.0
|
|
396
|
+
*/
|
|
397
|
+
getAppname(): string;
|
|
398
|
+
/**
|
|
399
|
+
* Get home directory
|
|
400
|
+
* @returns {String} home directory
|
|
401
|
+
* @since 3.4.0
|
|
402
|
+
*/
|
|
403
|
+
getHomedir(): string;
|
|
404
|
+
/**
|
|
405
|
+
* Get app info
|
|
406
|
+
* @returns {AppInfo} appInfo
|
|
407
|
+
* @since 1.0.0
|
|
408
|
+
*/
|
|
409
|
+
protected getAppInfo(): EggAppInfo;
|
|
410
|
+
/**
|
|
411
|
+
* Get {@link EggLoader#eggPaths}
|
|
412
|
+
* @returns {Array} framework directories
|
|
413
|
+
* @see {@link EggLoader#eggPaths}
|
|
414
|
+
* @private
|
|
415
|
+
* @since 1.0.0
|
|
416
|
+
*/
|
|
417
|
+
protected getEggPaths(): string[];
|
|
418
|
+
/** start Plugin loader */
|
|
419
|
+
lookupDirs: Set<string>;
|
|
420
|
+
eggPlugins: Record<string, EggPluginInfo>;
|
|
421
|
+
appPlugins: Record<string, EggPluginInfo>;
|
|
422
|
+
customPlugins: Record<string, EggPluginInfo>;
|
|
423
|
+
allPlugins: Record<string, EggPluginInfo>;
|
|
424
|
+
orderPlugins: EggPluginInfo[];
|
|
425
|
+
/** enable plugins */
|
|
426
|
+
plugins: Record<string, EggPluginInfo>;
|
|
427
|
+
/**
|
|
428
|
+
* Load config/plugin.js from {EggLoader#loadUnits}
|
|
429
|
+
*
|
|
430
|
+
* plugin.js is written below
|
|
431
|
+
*
|
|
432
|
+
* ```js
|
|
433
|
+
* {
|
|
434
|
+
* 'xxx-client': {
|
|
435
|
+
* enable: true,
|
|
436
|
+
* package: 'xxx-client',
|
|
437
|
+
* dep: [],
|
|
438
|
+
* env: [],
|
|
439
|
+
* },
|
|
440
|
+
* // short hand
|
|
441
|
+
* 'rds': false,
|
|
442
|
+
* 'depd': {
|
|
443
|
+
* enable: true,
|
|
444
|
+
* path: 'path/to/depd'
|
|
445
|
+
* }
|
|
446
|
+
* }
|
|
447
|
+
* ```
|
|
448
|
+
*
|
|
449
|
+
* If the plugin has path, Loader will find the module from it.
|
|
450
|
+
*
|
|
451
|
+
* Otherwise Loader will lookup follow the order by packageName
|
|
452
|
+
*
|
|
453
|
+
* 1. $APP_BASE/node_modules/${package}
|
|
454
|
+
* 2. $EGG_BASE/node_modules/${package}
|
|
455
|
+
*
|
|
456
|
+
* You can call `loader.plugins` that retrieve enabled plugins.
|
|
457
|
+
*
|
|
458
|
+
* ```js
|
|
459
|
+
* loader.plugins['xxx-client'] = {
|
|
460
|
+
* name: 'xxx-client', // the plugin name, it can be used in `dep`
|
|
461
|
+
* package: 'xxx-client', // the package name of plugin
|
|
462
|
+
* enable: true, // whether enabled
|
|
463
|
+
* path: 'path/to/xxx-client', // the directory of the plugin package
|
|
464
|
+
* dep: [], // the dependent plugins, you can use the plugin name
|
|
465
|
+
* env: [ 'local', 'unittest' ], // specify the serverEnv that only enable the plugin in it
|
|
466
|
+
* }
|
|
467
|
+
* ```
|
|
468
|
+
*
|
|
469
|
+
* `loader.allPlugins` can be used when retrieve all plugins.
|
|
470
|
+
* @function EggLoader#loadPlugin
|
|
471
|
+
* @since 1.0.0
|
|
472
|
+
*/
|
|
473
|
+
loadPlugin(): Promise<void>;
|
|
474
|
+
protected loadAppPlugins(): Promise<Record<string, EggPluginInfo>>;
|
|
475
|
+
protected loadEggPlugins(): Promise<Record<string, EggPluginInfo>>;
|
|
476
|
+
protected loadCustomPlugins(): Record<string, EggPluginInfo>;
|
|
477
|
+
protected readPluginConfigs(configPaths: string[] | string): Promise<Record<string, EggPluginInfo>>;
|
|
478
|
+
protected getOrderPlugins(allPlugins: Record<string, EggPluginInfo>, enabledPluginNames: string[], appPlugins: Record<string, EggPluginInfo>): EggPluginInfo[];
|
|
479
|
+
protected getLookupDirs(): Set<string>;
|
|
480
|
+
protected getPluginPath(plugin: EggPluginInfo): string;
|
|
481
|
+
/** end Plugin loader */
|
|
482
|
+
/** start Config loader */
|
|
483
|
+
configMeta: Record<string, any>;
|
|
484
|
+
config: EggAppConfig;
|
|
485
|
+
/**
|
|
486
|
+
* Load config/config.js
|
|
487
|
+
*
|
|
488
|
+
* Will merge config.default.js 和 config.${env}.js
|
|
489
|
+
*
|
|
490
|
+
* @function EggLoader#loadConfig
|
|
491
|
+
* @since 1.0.0
|
|
492
|
+
*/
|
|
493
|
+
loadConfig(): Promise<void>;
|
|
494
|
+
/** end Config loader */
|
|
495
|
+
/** start Extend loader */
|
|
496
|
+
/**
|
|
497
|
+
* mixin Agent.prototype
|
|
498
|
+
* @function EggLoader#loadAgentExtend
|
|
499
|
+
* @since 1.0.0
|
|
500
|
+
*/
|
|
501
|
+
loadAgentExtend(): Promise<void>;
|
|
502
|
+
/**
|
|
503
|
+
* mixin Application.prototype
|
|
504
|
+
* @function EggLoader#loadApplicationExtend
|
|
505
|
+
* @since 1.0.0
|
|
506
|
+
*/
|
|
507
|
+
loadApplicationExtend(): Promise<void>;
|
|
508
|
+
/**
|
|
509
|
+
* mixin Request.prototype
|
|
510
|
+
* @function EggLoader#loadRequestExtend
|
|
511
|
+
* @since 1.0.0
|
|
512
|
+
*/
|
|
513
|
+
loadRequestExtend(): Promise<void>;
|
|
514
|
+
/**
|
|
515
|
+
* mixin Response.prototype
|
|
516
|
+
* @function EggLoader#loadResponseExtend
|
|
517
|
+
* @since 1.0.0
|
|
518
|
+
*/
|
|
519
|
+
loadResponseExtend(): Promise<void>;
|
|
520
|
+
/**
|
|
521
|
+
* mixin Context.prototype
|
|
522
|
+
* @function EggLoader#loadContextExtend
|
|
523
|
+
* @since 1.0.0
|
|
524
|
+
*/
|
|
525
|
+
loadContextExtend(): Promise<void>;
|
|
526
|
+
/**
|
|
527
|
+
* mixin app.Helper.prototype
|
|
528
|
+
* @function EggLoader#loadHelperExtend
|
|
529
|
+
* @since 1.0.0
|
|
530
|
+
*/
|
|
531
|
+
loadHelperExtend(): Promise<void>;
|
|
532
|
+
/**
|
|
533
|
+
* Find all extend file paths by name
|
|
534
|
+
* can be override in top level framework to support load `app/extends/{name}.js`
|
|
535
|
+
*
|
|
536
|
+
* @param {String} name - filename which may be `app/extend/{name}.js`
|
|
537
|
+
* @returns {Array} filepaths extend file paths
|
|
538
|
+
* @private
|
|
539
|
+
*/
|
|
540
|
+
protected getExtendFilePaths(name: string): string[];
|
|
541
|
+
/**
|
|
542
|
+
* Loader app/extend/xx.js to `prototype`,
|
|
543
|
+
* @function loadExtend
|
|
544
|
+
* @param {String} name - filename which may be `app/extend/{name}.js`
|
|
545
|
+
* @param {Object} proto - prototype that mixed
|
|
546
|
+
* @since 1.0.0
|
|
547
|
+
*/
|
|
548
|
+
loadExtend(name: string, proto: object): Promise<void>;
|
|
549
|
+
/** end Extend loader */
|
|
550
|
+
/** start Custom loader */
|
|
551
|
+
/**
|
|
552
|
+
* load app.js
|
|
553
|
+
*
|
|
554
|
+
* @example
|
|
555
|
+
* - old:
|
|
556
|
+
*
|
|
557
|
+
* ```js
|
|
558
|
+
* module.exports = function(app) {
|
|
559
|
+
* doSomething();
|
|
560
|
+
* }
|
|
561
|
+
* ```
|
|
562
|
+
*
|
|
563
|
+
* - new:
|
|
564
|
+
*
|
|
565
|
+
* ```js
|
|
566
|
+
* module.exports = class Boot {
|
|
567
|
+
* constructor(app) {
|
|
568
|
+
* this.app = app;
|
|
569
|
+
* }
|
|
570
|
+
* configDidLoad() {
|
|
571
|
+
* doSomething();
|
|
572
|
+
* }
|
|
573
|
+
* }
|
|
574
|
+
* @since 1.0.0
|
|
575
|
+
*/
|
|
576
|
+
loadCustomApp(): Promise<void>;
|
|
577
|
+
/**
|
|
578
|
+
* Load agent.js, same as {@link EggLoader#loadCustomApp}
|
|
579
|
+
*/
|
|
580
|
+
loadCustomAgent(): Promise<void>;
|
|
581
|
+
loadBootHook(): void;
|
|
582
|
+
/** end Custom loader */
|
|
583
|
+
/** start Service loader */
|
|
584
|
+
/**
|
|
585
|
+
* Load app/service
|
|
586
|
+
* @function EggLoader#loadService
|
|
587
|
+
* @param {Object} options - LoaderOptions
|
|
588
|
+
* @since 1.0.0
|
|
589
|
+
*/
|
|
590
|
+
loadService(options?: Partial<ContextLoaderOptions>): Promise<void>;
|
|
591
|
+
/** end Service loader */
|
|
592
|
+
/** start Middleware loader */
|
|
593
|
+
/**
|
|
594
|
+
* Load app/middleware
|
|
595
|
+
*
|
|
596
|
+
* app.config.xx is the options of the middleware xx that has same name as config
|
|
597
|
+
*
|
|
598
|
+
* @function EggLoader#loadMiddleware
|
|
599
|
+
* @param {Object} opt - LoaderOptions
|
|
600
|
+
* @example
|
|
601
|
+
* ```js
|
|
602
|
+
* // app/middleware/status.js
|
|
603
|
+
* module.exports = function(options, app) {
|
|
604
|
+
* // options == app.config.status
|
|
605
|
+
* return async next => {
|
|
606
|
+
* await next();
|
|
607
|
+
* }
|
|
608
|
+
* }
|
|
609
|
+
* ```
|
|
610
|
+
* @since 1.0.0
|
|
611
|
+
*/
|
|
612
|
+
loadMiddleware(opt?: Partial<FileLoaderOptions>): Promise<void>;
|
|
613
|
+
/** end Middleware loader */
|
|
614
|
+
/** start Controller loader */
|
|
615
|
+
/**
|
|
616
|
+
* Load app/controller
|
|
617
|
+
* @param {Object} opt - LoaderOptions
|
|
618
|
+
* @since 1.0.0
|
|
619
|
+
*/
|
|
620
|
+
loadController(opt?: Partial<FileLoaderOptions>): Promise<void>;
|
|
621
|
+
/** end Controller loader */
|
|
622
|
+
/** start Router loader */
|
|
623
|
+
/**
|
|
624
|
+
* Load app/router.js
|
|
625
|
+
* @function EggLoader#loadRouter
|
|
626
|
+
* @since 1.0.0
|
|
627
|
+
*/
|
|
628
|
+
loadRouter(): Promise<void>;
|
|
629
|
+
/** end Router loader */
|
|
630
|
+
/** start CustomLoader loader */
|
|
631
|
+
loadCustomLoader(): Promise<void>;
|
|
632
|
+
/** end CustomLoader loader */
|
|
633
|
+
/**
|
|
634
|
+
* Load single file, will invoke when export is function
|
|
635
|
+
*
|
|
636
|
+
* @param {String} filepath - fullpath
|
|
637
|
+
* @param {Array} inject - pass rest arguments into the function when invoke
|
|
638
|
+
* @returns {Object} exports
|
|
639
|
+
* @example
|
|
640
|
+
* ```js
|
|
641
|
+
* app.loader.loadFile(path.join(app.options.baseDir, 'config/router.js'));
|
|
642
|
+
* ```
|
|
643
|
+
* @since 1.0.0
|
|
644
|
+
*/
|
|
645
|
+
loadFile(filepath: string, ...inject: unknown[]): Promise<any>;
|
|
646
|
+
/**
|
|
647
|
+
* @param {String} filepath - fullpath
|
|
648
|
+
* @private
|
|
649
|
+
*/
|
|
650
|
+
requireFile(filepath: string): Promise<any>;
|
|
651
|
+
/**
|
|
652
|
+
* Get all loadUnit
|
|
653
|
+
*
|
|
654
|
+
* loadUnit is a directory that can be loaded by EggLoader, it has the same structure.
|
|
655
|
+
* loadUnit has a path and a type(app, framework, plugin).
|
|
656
|
+
*
|
|
657
|
+
* The order of the loadUnits:
|
|
658
|
+
*
|
|
659
|
+
* 1. plugin
|
|
660
|
+
* 2. framework
|
|
661
|
+
* 3. app
|
|
662
|
+
*
|
|
663
|
+
* @returns {Array} loadUnits
|
|
664
|
+
* @since 1.0.0
|
|
665
|
+
*/
|
|
666
|
+
getLoadUnits(): EggDirInfo[];
|
|
667
|
+
/**
|
|
668
|
+
* Load files using {@link FileLoader}, inject to {@link Application}
|
|
669
|
+
* @param {String|Array} directory - see {@link FileLoader}
|
|
670
|
+
* @param {String} property - see {@link FileLoader}, e.g.: 'controller', 'middlewares'
|
|
671
|
+
* @param {Object} options - see {@link FileLoader}
|
|
672
|
+
* @since 1.0.0
|
|
673
|
+
*/
|
|
674
|
+
loadToApp(directory: string | string[], property: string | symbol, options?: Omit<FileLoaderOptions, 'inject' | 'target'>): Promise<void>;
|
|
675
|
+
/**
|
|
676
|
+
* Load files using {@link ContextLoader}
|
|
677
|
+
* @param {String|Array} directory - see {@link ContextLoader}
|
|
678
|
+
* @param {String} property - see {@link ContextLoader}
|
|
679
|
+
* @param {Object} options - see {@link ContextLoader}
|
|
680
|
+
* @since 1.0.0
|
|
681
|
+
*/
|
|
682
|
+
loadToContext(directory: string | string[], property: string | symbol, options?: Omit<ContextLoaderOptions, 'inject' | 'property'>): Promise<void>;
|
|
683
|
+
/**
|
|
684
|
+
* @member {FileLoader} EggLoader#FileLoader
|
|
685
|
+
* @since 1.0.0
|
|
686
|
+
*/
|
|
687
|
+
get FileLoader(): typeof FileLoader;
|
|
688
|
+
/**
|
|
689
|
+
* @member {ContextLoader} EggLoader#ContextLoader
|
|
690
|
+
* @since 1.0.0
|
|
691
|
+
*/
|
|
692
|
+
get ContextLoader(): typeof ContextLoader;
|
|
693
|
+
getTypeFiles(filename: string): string[];
|
|
694
|
+
resolveModule(filepath: string): string | undefined;
|
|
695
|
+
}
|
|
696
|
+
//#endregion
|
|
697
|
+
//#region src/singleton.d.ts
|
|
698
|
+
type SingletonCreateMethod = (config: Record<string, any>, app: EggCore, clientName: string) => unknown | Promise<unknown>;
|
|
699
|
+
interface SingletonOptions {
|
|
700
|
+
name: string;
|
|
701
|
+
app: EggCore;
|
|
702
|
+
create: SingletonCreateMethod;
|
|
703
|
+
}
|
|
704
|
+
declare class Singleton<T = any> {
|
|
705
|
+
#private;
|
|
706
|
+
readonly clients: Map<string, T>;
|
|
707
|
+
readonly app: EggCore;
|
|
708
|
+
readonly create: SingletonCreateMethod;
|
|
709
|
+
readonly name: string;
|
|
710
|
+
readonly options: Record<string, any>;
|
|
711
|
+
constructor(options: SingletonOptions);
|
|
712
|
+
init(): void | Promise<void>;
|
|
713
|
+
initSync(): void;
|
|
714
|
+
initAsync(): Promise<void>;
|
|
715
|
+
/**
|
|
716
|
+
* @deprecated please use `getSingletonInstance(id)` instead
|
|
717
|
+
*/
|
|
718
|
+
get(id: string): T;
|
|
719
|
+
/**
|
|
720
|
+
* Get singleton instance by id
|
|
721
|
+
*/
|
|
722
|
+
getSingletonInstance(id: string): T;
|
|
723
|
+
createInstance(config: Record<string, any>, clientName: string): T;
|
|
724
|
+
createInstanceAsync(config: Record<string, any>, clientName: string): Promise<T>;
|
|
725
|
+
}
|
|
726
|
+
//#endregion
|
|
727
|
+
//#region src/egg.d.ts
|
|
728
|
+
declare const EGG_LOADER: unique symbol;
|
|
729
|
+
interface EggCoreOptions {
|
|
730
|
+
baseDir: string;
|
|
731
|
+
type: 'application' | 'agent';
|
|
732
|
+
plugins?: any;
|
|
733
|
+
serverScope?: string;
|
|
734
|
+
env?: string;
|
|
735
|
+
}
|
|
736
|
+
type EggCoreInitOptions = Partial<EggCoreOptions>;
|
|
737
|
+
declare class Request extends KoaRequest {
|
|
738
|
+
app: EggCore;
|
|
739
|
+
response: Response;
|
|
740
|
+
}
|
|
741
|
+
declare class Response extends KoaResponse {
|
|
742
|
+
app: EggCore;
|
|
743
|
+
request: Request;
|
|
744
|
+
}
|
|
745
|
+
declare class Context extends KoaContext {
|
|
746
|
+
app: EggCore;
|
|
747
|
+
request: Request;
|
|
748
|
+
response: Response;
|
|
749
|
+
service: BaseContextClass;
|
|
750
|
+
/**
|
|
751
|
+
* Returns map of URL parameters for given `path` and `paramNames`.
|
|
752
|
+
* @example
|
|
753
|
+
* ##### ctx.params.id {string}
|
|
754
|
+
*
|
|
755
|
+
* `GET /api/users/1` => `'1'`
|
|
756
|
+
*
|
|
757
|
+
* ##### ctx.params.per_page {string}
|
|
758
|
+
*
|
|
759
|
+
* The number of every page, `GET /api/users?per_page=20` => `20`
|
|
760
|
+
*/
|
|
761
|
+
params?: Record<string, string>;
|
|
762
|
+
/**
|
|
763
|
+
* Returns array of router regexp url path captures.
|
|
764
|
+
*/
|
|
765
|
+
captures?: string[];
|
|
766
|
+
/**
|
|
767
|
+
* Returns the name of the matched router.
|
|
768
|
+
*/
|
|
769
|
+
routerName?: string;
|
|
770
|
+
/**
|
|
771
|
+
* Returns the path of the matched router.
|
|
772
|
+
*/
|
|
773
|
+
routerPath?: string | RegExp;
|
|
774
|
+
}
|
|
775
|
+
type MiddlewareFunc<T extends KoaContext = Context> = KoaMiddlewareFunc<T>;
|
|
776
|
+
declare class EggCore extends KoaApplication {
|
|
777
|
+
#private;
|
|
778
|
+
options: EggCoreOptions;
|
|
779
|
+
timing: Timing;
|
|
780
|
+
console: EggConsoleLogger;
|
|
781
|
+
BaseContextClass: typeof BaseContextClass;
|
|
782
|
+
Controller: typeof BaseContextClass;
|
|
783
|
+
Service: typeof BaseContextClass;
|
|
784
|
+
Helper?: typeof BaseContextClass;
|
|
785
|
+
lifecycle: Lifecycle;
|
|
786
|
+
loader: EggLoader;
|
|
787
|
+
/** auto inject on loadService() */
|
|
788
|
+
readonly serviceClasses: Record<string, any>;
|
|
789
|
+
/** auto inject on loadController() */
|
|
790
|
+
readonly controller: Record<string, any>;
|
|
791
|
+
/** auto inject on loadMiddleware() */
|
|
792
|
+
readonly middlewares: Record<string, (opt: unknown, app: EggCore) => MiddlewareFunc>;
|
|
793
|
+
/**
|
|
794
|
+
* @class
|
|
795
|
+
* @param {Object} options - options
|
|
796
|
+
* @param {String} [options.baseDir] - the directory of application
|
|
797
|
+
* @param {String} [options.type] - whether it's running in app worker or agent worker
|
|
798
|
+
* @param {Object} [options.plugins] - custom plugins
|
|
799
|
+
* @since 1.0.0
|
|
800
|
+
*/
|
|
801
|
+
constructor(options?: EggCoreInitOptions);
|
|
802
|
+
get logger(): Logger;
|
|
803
|
+
get coreLogger(): Logger;
|
|
804
|
+
/**
|
|
805
|
+
* create a singleton instance
|
|
806
|
+
* @param {String} name - unique name for singleton
|
|
807
|
+
* @param {Function|AsyncFunction} create - method will be invoked when singleton instance create
|
|
808
|
+
*/
|
|
809
|
+
addSingleton(name: string, create: SingletonCreateMethod): void;
|
|
810
|
+
/**
|
|
811
|
+
* override koa's app.use, support generator function
|
|
812
|
+
* @since 1.0.0
|
|
813
|
+
*/
|
|
814
|
+
use<T extends KoaContext = Context>(fn: MiddlewareFunc<T>): this;
|
|
815
|
+
/**
|
|
816
|
+
* Whether `application` or `agent`
|
|
817
|
+
* @member {String}
|
|
818
|
+
* @since 1.0.0
|
|
819
|
+
*/
|
|
820
|
+
get type(): "application" | "agent";
|
|
821
|
+
/**
|
|
822
|
+
* The current directory of application
|
|
823
|
+
* @member {String}
|
|
824
|
+
* @see {@link AppInfo#baseDir}
|
|
825
|
+
* @since 1.0.0
|
|
826
|
+
*/
|
|
827
|
+
get baseDir(): string;
|
|
828
|
+
/**
|
|
829
|
+
* Alias to {@link https://npmjs.com/package/depd}
|
|
830
|
+
* @member {Function}
|
|
831
|
+
* @since 1.0.0
|
|
832
|
+
*/
|
|
833
|
+
get deprecate(): (message: string) => void;
|
|
834
|
+
/**
|
|
835
|
+
* The name of application
|
|
836
|
+
* @member {String}
|
|
837
|
+
* @see {@link AppInfo#name}
|
|
838
|
+
* @since 1.0.0
|
|
839
|
+
*/
|
|
840
|
+
get name(): any;
|
|
841
|
+
/**
|
|
842
|
+
* Retrieve enabled plugins
|
|
843
|
+
* @member {Object}
|
|
844
|
+
* @since 1.0.0
|
|
845
|
+
*/
|
|
846
|
+
get plugins(): Record<string, EggPluginInfo>;
|
|
847
|
+
/**
|
|
848
|
+
* The configuration of application
|
|
849
|
+
* @member {Config}
|
|
850
|
+
* @since 1.0.0
|
|
851
|
+
*/
|
|
852
|
+
get config(): EggAppConfig;
|
|
853
|
+
/**
|
|
854
|
+
* Execute scope after loaded and before app start.
|
|
855
|
+
*
|
|
856
|
+
* Notice:
|
|
857
|
+
* This method is now NOT recommended and regarded as a deprecated one,
|
|
858
|
+
* For plugin development, we should use `didLoad` instead.
|
|
859
|
+
* For application development, we should use `willReady` instead.
|
|
860
|
+
*
|
|
861
|
+
* @see https://eggjs.org/en/advanced/loader.html#beforestart
|
|
862
|
+
*
|
|
863
|
+
* @param {Function} scope function will execute before app start
|
|
864
|
+
* @param {string} [name] scope name, default is empty string
|
|
865
|
+
*/
|
|
866
|
+
beforeStart(scope: Fun, name?: string): void;
|
|
867
|
+
/**
|
|
868
|
+
* register an callback function that will be invoked when application is ready.
|
|
869
|
+
* @see https://github.com/node-modules/get-ready
|
|
870
|
+
* @since 1.0.0
|
|
871
|
+
* @example
|
|
872
|
+
* const app = new Application(...);
|
|
873
|
+
* app.ready(err => {
|
|
874
|
+
* if (err) throw err;
|
|
875
|
+
* console.log('done');
|
|
876
|
+
* });
|
|
877
|
+
*/
|
|
878
|
+
ready(): Promise<void>;
|
|
879
|
+
ready(flagOrFunction: ReadyFunctionArg): void;
|
|
880
|
+
/**
|
|
881
|
+
* If a client starts asynchronously, you can register `readyCallback`,
|
|
882
|
+
* then the application will wait for the callback to ready
|
|
883
|
+
*
|
|
884
|
+
* It will log when the callback is not invoked after 10s
|
|
885
|
+
*
|
|
886
|
+
* Recommend to use {@link EggCore#beforeStart}
|
|
887
|
+
* @since 1.0.0
|
|
888
|
+
*
|
|
889
|
+
* @param {String} name - readyCallback task name
|
|
890
|
+
* @param {object} opts -
|
|
891
|
+
* - {Number} [timeout=10000] - emit `ready_timeout` when it doesn't finish but reach the timeout
|
|
892
|
+
* - {Boolean} [isWeakDep=false] - whether it's a weak dependency
|
|
893
|
+
* @returns {Function} - a callback
|
|
894
|
+
* @example
|
|
895
|
+
* const done = app.readyCallback('mysql');
|
|
896
|
+
* mysql.ready(done);
|
|
897
|
+
*/
|
|
898
|
+
readyCallback(name: string, opts: object): (...args: unknown[]) => void;
|
|
899
|
+
/**
|
|
900
|
+
* Register a function that will be called when app close.
|
|
901
|
+
*
|
|
902
|
+
* Notice:
|
|
903
|
+
* This method is now NOT recommended directly used,
|
|
904
|
+
* Developers SHOULDN'T use app.beforeClose directly now,
|
|
905
|
+
* but in the form of class to implement beforeClose instead.
|
|
906
|
+
*
|
|
907
|
+
* @see https://eggjs.org/en/advanced/loader.html#beforeclose
|
|
908
|
+
*
|
|
909
|
+
* @param {Function} fn - the function that can be generator function or async function.
|
|
910
|
+
*/
|
|
911
|
+
beforeClose(fn: Fun, name?: string): void;
|
|
912
|
+
/**
|
|
913
|
+
* Close all, it will close
|
|
914
|
+
* - callbacks registered by beforeClose
|
|
915
|
+
* - emit `close` event
|
|
916
|
+
* - remove add listeners
|
|
917
|
+
*
|
|
918
|
+
* If error is thrown when it's closing, the promise will reject.
|
|
919
|
+
* It will also reject after following call.
|
|
920
|
+
* @returns {Promise} promise
|
|
921
|
+
* @since 1.0.0
|
|
922
|
+
*/
|
|
923
|
+
close(): Promise<void>;
|
|
924
|
+
/**
|
|
925
|
+
* get router
|
|
926
|
+
* @member {Router} EggCore#router
|
|
927
|
+
* @since 1.0.0
|
|
928
|
+
*/
|
|
929
|
+
get router(): Router;
|
|
930
|
+
/**
|
|
931
|
+
* Alias to {@link Router#url}
|
|
932
|
+
* @param {String} name - Router name
|
|
933
|
+
* @param {Object} params - more parameters
|
|
934
|
+
* @returns {String} url
|
|
935
|
+
*/
|
|
936
|
+
url(name: string, params?: Parameters<Router['url']>[1]): string;
|
|
937
|
+
head(path: string | RegExp | (string | RegExp)[], ...middlewares: (MiddlewareFunc | string)[]): EggCore;
|
|
938
|
+
head(name: string, path: string | RegExp | (string | RegExp)[], ...middlewares: (MiddlewareFunc | string)[]): EggCore;
|
|
939
|
+
get(path: string | RegExp | (string | RegExp)[], ...middlewares: (MiddlewareFunc | string)[]): EggCore;
|
|
940
|
+
get(name: string, path: string | RegExp | (string | RegExp)[], ...middlewares: (MiddlewareFunc | string)[]): EggCore;
|
|
941
|
+
put(path: string | RegExp | (string | RegExp)[], ...middlewares: (MiddlewareFunc | string)[]): EggCore;
|
|
942
|
+
put(name: string, path: string | RegExp | (string | RegExp)[], ...middlewares: (MiddlewareFunc | string)[]): EggCore;
|
|
943
|
+
patch(path: string | RegExp | (string | RegExp)[], ...middlewares: (MiddlewareFunc | string)[]): EggCore;
|
|
944
|
+
patch(name: string, path: string | RegExp | (string | RegExp)[], ...middlewares: (MiddlewareFunc | string)[]): EggCore;
|
|
945
|
+
post(path: string | RegExp | (string | RegExp)[], ...middlewares: (MiddlewareFunc | string)[]): EggCore;
|
|
946
|
+
post(name: string, path: string | RegExp | (string | RegExp)[], ...middlewares: (MiddlewareFunc | string)[]): EggCore;
|
|
947
|
+
delete(path: string | RegExp | (string | RegExp)[], ...middlewares: (MiddlewareFunc | string)[]): EggCore;
|
|
948
|
+
delete(name: string, path: string | RegExp | (string | RegExp)[], ...middlewares: (MiddlewareFunc | string)[]): EggCore;
|
|
949
|
+
del(path: string | RegExp | (string | RegExp)[], ...middlewares: (MiddlewareFunc | string)[]): EggCore;
|
|
950
|
+
del(name: string, path: string | RegExp | (string | RegExp)[], ...middlewares: (MiddlewareFunc | string)[]): EggCore;
|
|
951
|
+
all(path: string | RegExp | (string | RegExp)[], ...middlewares: (MiddlewareFunc | string)[]): EggCore;
|
|
952
|
+
all(name: string, path: string | RegExp | (string | RegExp)[], ...middlewares: (MiddlewareFunc | string)[]): EggCore;
|
|
953
|
+
resources(prefix: string, controller: string | ResourcesController): EggCore;
|
|
954
|
+
resources(prefix: string, middleware: MiddlewareFunc, controller: string | ResourcesController): EggCore;
|
|
955
|
+
resources(name: string, prefix: string, controller: string | ResourcesController): EggCore;
|
|
956
|
+
resources(name: string, prefix: string, middleware: MiddlewareFunc, controller: string | ResourcesController): EggCore;
|
|
957
|
+
redirect(source: string, destination: string, status?: number): this;
|
|
958
|
+
register(path: string | RegExp | (string | RegExp)[], methods: string[], middleware: MiddlewareFunc | MiddlewareFunc[], opts?: RegisterOptions): this;
|
|
959
|
+
get [EGG_LOADER](): typeof EggLoader;
|
|
960
|
+
}
|
|
961
|
+
//#endregion
|
|
962
|
+
//#region src/utils/sequencify.d.ts
|
|
963
|
+
interface SequencifyResult {
|
|
964
|
+
sequence: string[];
|
|
965
|
+
requires: Record<string, true>;
|
|
966
|
+
}
|
|
967
|
+
interface SequencifyTask {
|
|
968
|
+
dependencies: string[];
|
|
969
|
+
optionalDependencies: string[];
|
|
970
|
+
}
|
|
971
|
+
declare function sequencify(tasks: Record<string, SequencifyTask>, names: string[]): {
|
|
972
|
+
sequence: string[];
|
|
973
|
+
missingTasks: string[];
|
|
974
|
+
recursiveDependencies: string[];
|
|
975
|
+
};
|
|
976
|
+
//#endregion
|
|
977
|
+
export { BaseContextClass, BootImplClass, CaseStyle, CaseStyleFunction, ClassLoader, ClassLoaderOptions, Context, ContextLoader, ContextLoaderOptions, CustomLoaderConfigItem, EGG_LOADER, EXPORTS, EggAppConfig, EggAppInfo, EggCore, EggCoreInitOptions, EggCoreOptions, EggDirInfo, EggDirInfoType, EggLoader, EggLoaderOptions, EggPluginInfo, FULLPATH, FileLoader, FileLoaderFilter, FileLoaderInitializer, FileLoaderOptions, FileLoaderParseItem, FunWithFullPath, ILifecycleBoot, KoaApplication, KoaContext, type KoaMiddlewareFunc, KoaRequest, KoaResponse, Lifecycle, LifecycleOptions, MiddlewareFunc, type Next, Request, Response, Router, SequencifyResult, SequencifyTask, Singleton, SingletonCreateMethod, SingletonOptions, Timing, TimingItem, sequencify, _default as utils };
|