@eggjs/core 6.4.1 → 6.6.0-beta.10

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 (87) hide show
  1. package/README.md +23 -27
  2. package/dist/base_context_class.d.ts +21 -0
  3. package/dist/base_context_class.js +40 -0
  4. package/dist/egg.d.ts +248 -0
  5. package/dist/egg.js +358 -0
  6. package/dist/index.d.ts +12 -0
  7. package/dist/index.js +12 -0
  8. package/dist/lifecycle.d.ts +84 -0
  9. package/dist/lifecycle.js +280 -0
  10. package/dist/loader/context_loader.d.ts +39 -0
  11. package/dist/loader/context_loader.js +79 -0
  12. package/dist/loader/egg_loader.d.ts +374 -0
  13. package/dist/loader/egg_loader.js +1184 -0
  14. package/dist/loader/file_loader.d.ts +105 -0
  15. package/dist/loader/file_loader.js +198 -0
  16. package/dist/singleton.d.ts +33 -0
  17. package/dist/singleton.js +107 -0
  18. package/{src/types.ts → dist/types.d.ts} +7 -7
  19. package/dist/utils/index.d.ts +19 -0
  20. package/dist/utils/index.js +103 -0
  21. package/dist/utils/sequencify.d.ts +16 -0
  22. package/dist/utils/sequencify.js +46 -0
  23. package/dist/utils/timing.d.ts +24 -0
  24. package/dist/utils/timing.js +85 -0
  25. package/package.json +39 -65
  26. package/dist/commonjs/base_context_class.d.ts +0 -16
  27. package/dist/commonjs/base_context_class.js +0 -41
  28. package/dist/commonjs/egg.d.ts +0 -247
  29. package/dist/commonjs/egg.js +0 -401
  30. package/dist/commonjs/index.d.ts +0 -12
  31. package/dist/commonjs/index.js +0 -32
  32. package/dist/commonjs/lifecycle.d.ts +0 -78
  33. package/dist/commonjs/lifecycle.js +0 -312
  34. package/dist/commonjs/loader/context_loader.d.ts +0 -35
  35. package/dist/commonjs/loader/context_loader.js +0 -110
  36. package/dist/commonjs/loader/egg_loader.d.ts +0 -369
  37. package/dist/commonjs/loader/egg_loader.js +0 -1543
  38. package/dist/commonjs/loader/file_loader.d.ts +0 -100
  39. package/dist/commonjs/loader/file_loader.js +0 -262
  40. package/dist/commonjs/package.json +0 -3
  41. package/dist/commonjs/singleton.d.ts +0 -29
  42. package/dist/commonjs/singleton.js +0 -125
  43. package/dist/commonjs/types.d.ts +0 -53
  44. package/dist/commonjs/types.js +0 -3
  45. package/dist/commonjs/utils/index.d.ts +0 -17
  46. package/dist/commonjs/utils/index.js +0 -117
  47. package/dist/commonjs/utils/sequencify.d.ts +0 -13
  48. package/dist/commonjs/utils/sequencify.js +0 -59
  49. package/dist/commonjs/utils/timing.d.ts +0 -21
  50. package/dist/commonjs/utils/timing.js +0 -100
  51. package/dist/esm/base_context_class.d.ts +0 -16
  52. package/dist/esm/base_context_class.js +0 -37
  53. package/dist/esm/egg.d.ts +0 -247
  54. package/dist/esm/egg.js +0 -388
  55. package/dist/esm/index.d.ts +0 -12
  56. package/dist/esm/index.js +0 -12
  57. package/dist/esm/lifecycle.d.ts +0 -78
  58. package/dist/esm/lifecycle.js +0 -305
  59. package/dist/esm/loader/context_loader.d.ts +0 -35
  60. package/dist/esm/loader/context_loader.js +0 -102
  61. package/dist/esm/loader/egg_loader.d.ts +0 -369
  62. package/dist/esm/loader/egg_loader.js +0 -1536
  63. package/dist/esm/loader/file_loader.d.ts +0 -100
  64. package/dist/esm/loader/file_loader.js +0 -255
  65. package/dist/esm/package.json +0 -3
  66. package/dist/esm/singleton.d.ts +0 -29
  67. package/dist/esm/singleton.js +0 -118
  68. package/dist/esm/types.d.ts +0 -53
  69. package/dist/esm/types.js +0 -2
  70. package/dist/esm/utils/index.d.ts +0 -17
  71. package/dist/esm/utils/index.js +0 -112
  72. package/dist/esm/utils/sequencify.d.ts +0 -13
  73. package/dist/esm/utils/sequencify.js +0 -56
  74. package/dist/esm/utils/timing.d.ts +0 -21
  75. package/dist/esm/utils/timing.js +0 -93
  76. package/dist/package.json +0 -4
  77. package/src/base_context_class.ts +0 -39
  78. package/src/egg.ts +0 -517
  79. package/src/index.ts +0 -14
  80. package/src/lifecycle.ts +0 -399
  81. package/src/loader/context_loader.ts +0 -121
  82. package/src/loader/egg_loader.ts +0 -1722
  83. package/src/loader/file_loader.ts +0 -308
  84. package/src/singleton.ts +0 -149
  85. package/src/utils/index.ts +0 -125
  86. package/src/utils/sequencify.ts +0 -70
  87. package/src/utils/timing.ts +0 -114
@@ -1,369 +0,0 @@
1
- import type { Logger } from 'egg-logger';
2
- import { FileLoader, FileLoaderOptions } from './file_loader.js';
3
- import { ContextLoader, ContextLoaderOptions } from './context_loader.js';
4
- import { Timing } from '../utils/timing.js';
5
- import type { EggCore } from '../egg.js';
6
- import type { EggAppConfig, EggAppInfo, EggPluginInfo } from '../types.js';
7
- export interface EggLoaderOptions {
8
- /** server env */
9
- env: string;
10
- /** Application instance */
11
- app: EggCore;
12
- EggCoreClass?: typeof EggCore;
13
- /** the directory of application */
14
- baseDir: string;
15
- /** egg logger */
16
- logger: Logger;
17
- /** server scope */
18
- serverScope?: string;
19
- /** custom plugins */
20
- plugins?: Record<string, EggPluginInfo>;
21
- }
22
- export type EggDirInfoType = 'app' | 'plugin' | 'framework';
23
- export interface EggDirInfo {
24
- path: string;
25
- type: EggDirInfoType;
26
- }
27
- export declare class EggLoader {
28
- #private;
29
- readonly options: EggLoaderOptions;
30
- readonly timing: Timing;
31
- readonly pkg: Record<string, any>;
32
- readonly eggPaths: string[];
33
- readonly serverEnv: string;
34
- readonly serverScope: string;
35
- readonly appInfo: EggAppInfo;
36
- dirs?: EggDirInfo[];
37
- /**
38
- * @class
39
- * @param {Object} options - options
40
- * @param {String} options.baseDir - the directory of application
41
- * @param {EggCore} options.app - Application instance
42
- * @param {Logger} options.logger - logger
43
- * @param {Object} [options.plugins] - custom plugins
44
- * @since 1.0.0
45
- */
46
- constructor(options: EggLoaderOptions);
47
- get app(): EggCore;
48
- get lifecycle(): import("../lifecycle.js").Lifecycle;
49
- get logger(): Logger<import("egg-logger").EggLoggerOptions>;
50
- /**
51
- * Get {@link AppInfo#env}
52
- * @return {String} env
53
- * @see AppInfo#env
54
- * @private
55
- * @since 1.0.0
56
- */
57
- protected getServerEnv(): string;
58
- /**
59
- * Get {@link AppInfo#scope}
60
- * @return {String} serverScope
61
- * @private
62
- */
63
- protected getServerScope(): string;
64
- /**
65
- * Get {@link AppInfo#name}
66
- * @return {String} appname
67
- * @private
68
- * @since 1.0.0
69
- */
70
- getAppname(): string;
71
- /**
72
- * Get home directory
73
- * @return {String} home directory
74
- * @since 3.4.0
75
- */
76
- getHomedir(): string;
77
- /**
78
- * Get app info
79
- * @return {AppInfo} appInfo
80
- * @since 1.0.0
81
- */
82
- protected getAppInfo(): EggAppInfo;
83
- /**
84
- * Get {@link EggLoader#eggPaths}
85
- * @return {Array} framework directories
86
- * @see {@link EggLoader#eggPaths}
87
- * @private
88
- * @since 1.0.0
89
- */
90
- protected getEggPaths(): string[];
91
- /** start Plugin loader */
92
- lookupDirs: Set<string>;
93
- eggPlugins: Record<string, EggPluginInfo>;
94
- appPlugins: Record<string, EggPluginInfo>;
95
- customPlugins: Record<string, EggPluginInfo>;
96
- allPlugins: Record<string, EggPluginInfo>;
97
- orderPlugins: EggPluginInfo[];
98
- /** enable plugins */
99
- plugins: Record<string, EggPluginInfo>;
100
- /**
101
- * Load config/plugin.js from {EggLoader#loadUnits}
102
- *
103
- * plugin.js is written below
104
- *
105
- * ```js
106
- * {
107
- * 'xxx-client': {
108
- * enable: true,
109
- * package: 'xxx-client',
110
- * dep: [],
111
- * env: [],
112
- * },
113
- * // short hand
114
- * 'rds': false,
115
- * 'depd': {
116
- * enable: true,
117
- * path: 'path/to/depd'
118
- * }
119
- * }
120
- * ```
121
- *
122
- * If the plugin has path, Loader will find the module from it.
123
- *
124
- * Otherwise Loader will lookup follow the order by packageName
125
- *
126
- * 1. $APP_BASE/node_modules/${package}
127
- * 2. $EGG_BASE/node_modules/${package}
128
- *
129
- * You can call `loader.plugins` that retrieve enabled plugins.
130
- *
131
- * ```js
132
- * loader.plugins['xxx-client'] = {
133
- * name: 'xxx-client', // the plugin name, it can be used in `dep`
134
- * package: 'xxx-client', // the package name of plugin
135
- * enable: true, // whether enabled
136
- * path: 'path/to/xxx-client', // the directory of the plugin package
137
- * dep: [], // the dependent plugins, you can use the plugin name
138
- * env: [ 'local', 'unittest' ], // specify the serverEnv that only enable the plugin in it
139
- * }
140
- * ```
141
- *
142
- * `loader.allPlugins` can be used when retrieve all plugins.
143
- * @function EggLoader#loadPlugin
144
- * @since 1.0.0
145
- */
146
- loadPlugin(): Promise<void>;
147
- protected loadAppPlugins(): Promise<Record<string, EggPluginInfo>>;
148
- protected loadEggPlugins(): Promise<Record<string, EggPluginInfo>>;
149
- protected loadCustomPlugins(): Record<string, EggPluginInfo>;
150
- protected readPluginConfigs(configPaths: string[] | string): Promise<Record<string, EggPluginInfo>>;
151
- protected getOrderPlugins(allPlugins: Record<string, EggPluginInfo>, enabledPluginNames: string[], appPlugins: Record<string, EggPluginInfo>): EggPluginInfo[];
152
- protected getLookupDirs(): Set<string>;
153
- protected getPluginPath(plugin: EggPluginInfo): string;
154
- /** end Plugin loader */
155
- /** start Config loader */
156
- configMeta: Record<string, any>;
157
- config: EggAppConfig;
158
- /**
159
- * Load config/config.js
160
- *
161
- * Will merge config.default.js 和 config.${env}.js
162
- *
163
- * @function EggLoader#loadConfig
164
- * @since 1.0.0
165
- */
166
- loadConfig(): Promise<void>;
167
- /** end Config loader */
168
- /** start Extend loader */
169
- /**
170
- * mixin Agent.prototype
171
- * @function EggLoader#loadAgentExtend
172
- * @since 1.0.0
173
- */
174
- loadAgentExtend(): Promise<void>;
175
- /**
176
- * mixin Application.prototype
177
- * @function EggLoader#loadApplicationExtend
178
- * @since 1.0.0
179
- */
180
- loadApplicationExtend(): Promise<void>;
181
- /**
182
- * mixin Request.prototype
183
- * @function EggLoader#loadRequestExtend
184
- * @since 1.0.0
185
- */
186
- loadRequestExtend(): Promise<void>;
187
- /**
188
- * mixin Response.prototype
189
- * @function EggLoader#loadResponseExtend
190
- * @since 1.0.0
191
- */
192
- loadResponseExtend(): Promise<void>;
193
- /**
194
- * mixin Context.prototype
195
- * @function EggLoader#loadContextExtend
196
- * @since 1.0.0
197
- */
198
- loadContextExtend(): Promise<void>;
199
- /**
200
- * mixin app.Helper.prototype
201
- * @function EggLoader#loadHelperExtend
202
- * @since 1.0.0
203
- */
204
- loadHelperExtend(): Promise<void>;
205
- /**
206
- * Find all extend file paths by name
207
- * can be override in top level framework to support load `app/extends/{name}.js`
208
- *
209
- * @param {String} name - filename which may be `app/extend/{name}.js`
210
- * @return {Array} filepaths extend file paths
211
- * @private
212
- */
213
- protected getExtendFilePaths(name: string): string[];
214
- /**
215
- * Loader app/extend/xx.js to `prototype`,
216
- * @function loadExtend
217
- * @param {String} name - filename which may be `app/extend/{name}.js`
218
- * @param {Object} proto - prototype that mixed
219
- * @since 1.0.0
220
- */
221
- loadExtend(name: string, proto: object): Promise<void>;
222
- /** end Extend loader */
223
- /** start Custom loader */
224
- /**
225
- * load app.js
226
- *
227
- * @example
228
- * - old:
229
- *
230
- * ```js
231
- * module.exports = function(app) {
232
- * doSomething();
233
- * }
234
- * ```
235
- *
236
- * - new:
237
- *
238
- * ```js
239
- * module.exports = class Boot {
240
- * constructor(app) {
241
- * this.app = app;
242
- * }
243
- * configDidLoad() {
244
- * doSomething();
245
- * }
246
- * }
247
- * @since 1.0.0
248
- */
249
- loadCustomApp(): Promise<void>;
250
- /**
251
- * Load agent.js, same as {@link EggLoader#loadCustomApp}
252
- */
253
- loadCustomAgent(): Promise<void>;
254
- loadBootHook(): void;
255
- /** end Custom loader */
256
- /** start Service loader */
257
- /**
258
- * Load app/service
259
- * @function EggLoader#loadService
260
- * @param {Object} options - LoaderOptions
261
- * @since 1.0.0
262
- */
263
- loadService(options?: Partial<ContextLoaderOptions>): Promise<void>;
264
- /** end Service loader */
265
- /** start Middleware loader */
266
- /**
267
- * Load app/middleware
268
- *
269
- * app.config.xx is the options of the middleware xx that has same name as config
270
- *
271
- * @function EggLoader#loadMiddleware
272
- * @param {Object} opt - LoaderOptions
273
- * @example
274
- * ```js
275
- * // app/middleware/status.js
276
- * module.exports = function(options, app) {
277
- * // options == app.config.status
278
- * return async next => {
279
- * await next();
280
- * }
281
- * }
282
- * ```
283
- * @since 1.0.0
284
- */
285
- loadMiddleware(opt?: Partial<FileLoaderOptions>): Promise<void>;
286
- /** end Middleware loader */
287
- /** start Controller loader */
288
- /**
289
- * Load app/controller
290
- * @param {Object} opt - LoaderOptions
291
- * @since 1.0.0
292
- */
293
- loadController(opt?: Partial<FileLoaderOptions>): Promise<void>;
294
- /** end Controller loader */
295
- /** start Router loader */
296
- /**
297
- * Load app/router.js
298
- * @function EggLoader#loadRouter
299
- * @since 1.0.0
300
- */
301
- loadRouter(): Promise<void>;
302
- /** end Router loader */
303
- /** start CustomLoader loader */
304
- loadCustomLoader(): Promise<void>;
305
- /** end CustomLoader loader */
306
- /**
307
- * Load single file, will invoke when export is function
308
- *
309
- * @param {String} filepath - fullpath
310
- * @param {Array} inject - pass rest arguments into the function when invoke
311
- * @return {Object} exports
312
- * @example
313
- * ```js
314
- * app.loader.loadFile(path.join(app.options.baseDir, 'config/router.js'));
315
- * ```
316
- * @since 1.0.0
317
- */
318
- loadFile(filepath: string, ...inject: any[]): Promise<any>;
319
- /**
320
- * @param {String} filepath - fullpath
321
- * @return {Object} exports
322
- * @private
323
- */
324
- requireFile(filepath: string): Promise<any>;
325
- /**
326
- * Get all loadUnit
327
- *
328
- * loadUnit is a directory that can be loaded by EggLoader, it has the same structure.
329
- * loadUnit has a path and a type(app, framework, plugin).
330
- *
331
- * The order of the loadUnits:
332
- *
333
- * 1. plugin
334
- * 2. framework
335
- * 3. app
336
- *
337
- * @return {Array} loadUnits
338
- * @since 1.0.0
339
- */
340
- getLoadUnits(): EggDirInfo[];
341
- /**
342
- * Load files using {@link FileLoader}, inject to {@link Application}
343
- * @param {String|Array} directory - see {@link FileLoader}
344
- * @param {String} property - see {@link FileLoader}
345
- * @param {Object} options - see {@link FileLoader}
346
- * @since 1.0.0
347
- */
348
- loadToApp(directory: string | string[], property: string | symbol, options?: Omit<FileLoaderOptions, 'inject' | 'target'>): Promise<void>;
349
- /**
350
- * Load files using {@link ContextLoader}
351
- * @param {String|Array} directory - see {@link ContextLoader}
352
- * @param {String} property - see {@link ContextLoader}
353
- * @param {Object} options - see {@link ContextLoader}
354
- * @since 1.0.0
355
- */
356
- loadToContext(directory: string | string[], property: string | symbol, options?: Omit<ContextLoaderOptions, 'inject' | 'property'>): Promise<void>;
357
- /**
358
- * @member {FileLoader} EggLoader#FileLoader
359
- * @since 1.0.0
360
- */
361
- get FileLoader(): typeof FileLoader;
362
- /**
363
- * @member {ContextLoader} EggLoader#ContextLoader
364
- * @since 1.0.0
365
- */
366
- get ContextLoader(): typeof ContextLoader;
367
- getTypeFiles(filename: string): string[];
368
- resolveModule(filepath: string): string | undefined;
369
- }