@midwayjs/core 3.0.0-alpha.9 → 3.0.0-beta.4

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 (109) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/dist/baseFramework.d.ts +55 -22
  3. package/dist/baseFramework.js +151 -232
  4. package/dist/{util → common}/fileDetector.d.ts +0 -0
  5. package/dist/{util → common}/fileDetector.js +16 -10
  6. package/dist/common/filterManager.d.ts +19 -0
  7. package/dist/common/filterManager.js +85 -0
  8. package/dist/common/middlewareManager.d.ts +11 -0
  9. package/dist/common/middlewareManager.js +48 -0
  10. package/dist/common/serviceFactory.d.ts +15 -0
  11. package/dist/{util → common}/serviceFactory.js +16 -6
  12. package/dist/{util → common}/triggerCollector.d.ts +0 -0
  13. package/dist/{util → common}/triggerCollector.js +0 -0
  14. package/dist/common/webGenerator.d.ts +27 -0
  15. package/dist/common/webGenerator.js +125 -0
  16. package/dist/{util → common}/webRouterCollector.d.ts +21 -2
  17. package/dist/{util → common}/webRouterCollector.js +115 -138
  18. package/dist/config/config.default.d.ts +7 -0
  19. package/dist/config/config.default.js +28 -0
  20. package/dist/context/container.d.ts +73 -43
  21. package/dist/context/container.js +277 -270
  22. package/dist/context/definitionRegistry.d.ts +26 -0
  23. package/dist/context/definitionRegistry.js +124 -0
  24. package/dist/context/managedResolverFactory.d.ts +15 -32
  25. package/dist/context/managedResolverFactory.js +88 -317
  26. package/dist/context/providerWrapper.d.ts +2 -3
  27. package/dist/context/requestContainer.d.ts +0 -2
  28. package/dist/context/requestContainer.js +9 -26
  29. package/dist/definitions/functionDefinition.d.ts +3 -4
  30. package/dist/definitions/functionDefinition.js +0 -6
  31. package/dist/definitions/objectCreator.js +6 -6
  32. package/dist/definitions/objectDefinition.d.ts +4 -6
  33. package/dist/definitions/objectDefinition.js +0 -8
  34. package/dist/definitions/properties.d.ts +2 -15
  35. package/dist/definitions/properties.js +3 -72
  36. package/dist/error/base.d.ts +13 -0
  37. package/dist/error/base.js +19 -0
  38. package/dist/error/code.d.ts +59 -0
  39. package/dist/error/code.js +64 -0
  40. package/dist/error/framework.d.ts +21 -0
  41. package/dist/error/framework.js +52 -0
  42. package/dist/error/http.d.ts +58 -0
  43. package/dist/error/http.js +82 -0
  44. package/dist/error/index.d.ts +4 -0
  45. package/dist/error/index.js +16 -0
  46. package/dist/functional/configuration.d.ts +4 -2
  47. package/dist/functional/configuration.js +12 -2
  48. package/dist/index.d.ts +23 -10
  49. package/dist/index.js +33 -33
  50. package/dist/interface.d.ts +263 -184
  51. package/dist/interface.js +9 -1
  52. package/dist/service/aspectService.d.ts +11 -14
  53. package/dist/service/aspectService.js +116 -172
  54. package/dist/service/configService.d.ts +10 -8
  55. package/dist/service/configService.js +61 -38
  56. package/dist/service/decoratorService.d.ts +23 -0
  57. package/dist/service/decoratorService.js +149 -0
  58. package/dist/service/environmentService.js +15 -4
  59. package/dist/service/frameworkService.d.ts +25 -0
  60. package/dist/service/frameworkService.js +171 -0
  61. package/dist/service/informationService.d.ts +4 -7
  62. package/dist/service/informationService.js +41 -10
  63. package/dist/service/lifeCycleService.d.ts +14 -0
  64. package/dist/service/lifeCycleService.js +130 -0
  65. package/dist/service/loggerService.d.ts +27 -0
  66. package/dist/service/loggerService.js +132 -0
  67. package/dist/service/middlewareService.d.ts +11 -0
  68. package/dist/service/middlewareService.js +119 -0
  69. package/dist/{features/pipeline.d.ts → service/pipelineService.d.ts} +56 -46
  70. package/dist/{features/pipeline.js → service/pipelineService.js} +54 -19
  71. package/dist/setup.d.ts +4 -0
  72. package/dist/setup.js +113 -0
  73. package/dist/util/contextUtil.d.ts +1 -1
  74. package/dist/util/contextUtil.js +2 -2
  75. package/dist/util/index.d.ts +55 -0
  76. package/dist/util/index.js +137 -7
  77. package/dist/util/pathFileUtil.js +2 -2
  78. package/dist/util/pathToRegexp.d.ts +17 -0
  79. package/dist/util/pathToRegexp.js +280 -0
  80. package/dist/util/webRouterParam.d.ts +2 -2
  81. package/dist/util/webRouterParam.js +19 -20
  82. package/package.json +8 -13
  83. package/dist/common/lodashWrap.d.ts +0 -9
  84. package/dist/common/lodashWrap.js +0 -18
  85. package/dist/common/notFoundError.d.ts +0 -8
  86. package/dist/common/notFoundError.js +0 -20
  87. package/dist/common/reflectTool.d.ts +0 -15
  88. package/dist/common/reflectTool.js +0 -83
  89. package/dist/context/applicationContext.d.ts +0 -81
  90. package/dist/context/applicationContext.js +0 -263
  91. package/dist/context/managed.d.ts +0 -45
  92. package/dist/context/managed.js +0 -69
  93. package/dist/context/resolverHandler.d.ts +0 -34
  94. package/dist/context/resolverHandler.js +0 -88
  95. package/dist/definitions/messageSource.d.ts +0 -13
  96. package/dist/definitions/messageSource.js +0 -74
  97. package/dist/definitions/resource.d.ts +0 -27
  98. package/dist/definitions/resource.js +0 -116
  99. package/dist/features/index.d.ts +0 -2
  100. package/dist/features/index.js +0 -3
  101. package/dist/logger.d.ts +0 -4
  102. package/dist/logger.js +0 -20
  103. package/dist/util/containerUtil.d.ts +0 -11
  104. package/dist/util/containerUtil.js +0 -26
  105. package/dist/util/emptyFramework.d.ts +0 -62
  106. package/dist/util/emptyFramework.js +0 -72
  107. package/dist/util/serviceFactory.d.ts +0 -13
  108. package/dist/util/staticConfig.d.ts +0 -10
  109. package/dist/util/staticConfig.js +0 -67
@@ -2,9 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.WebRouterCollector = void 0;
4
4
  const decorator_1 = require("@midwayjs/decorator");
5
- const index_1 = require("./index");
5
+ const util_1 = require("../util");
6
6
  const container_1 = require("../context/container");
7
7
  const fileDetector_1 = require("./fileDetector");
8
+ const util = require("util");
9
+ const debug = util.debuglog('midway:debug');
8
10
  class WebRouterCollector {
9
11
  constructor(baseDir = '', options = {}) {
10
12
  this.isReady = false;
@@ -21,16 +23,27 @@ class WebRouterCollector {
21
23
  }));
22
24
  await container.ready();
23
25
  }
24
- const controllerModules = decorator_1.listModule(decorator_1.CONTROLLER_KEY);
26
+ const controllerModules = (0, decorator_1.listModule)(decorator_1.CONTROLLER_KEY);
25
27
  for (const module of controllerModules) {
26
28
  this.collectRoute(module);
27
29
  }
28
30
  if (this.options.includeFunctionRouter) {
29
- const fnModules = decorator_1.listModule(decorator_1.FUNC_KEY);
31
+ const fnModules = (0, decorator_1.listModule)(decorator_1.FUNC_KEY);
30
32
  for (const module of fnModules) {
31
33
  this.collectFunctionRoute(module);
32
34
  }
33
35
  }
36
+ // filter empty prefix
37
+ this.routesPriority = this.routesPriority.filter(item => {
38
+ const prefixList = this.routes.get(item.prefix);
39
+ if (prefixList.length > 0) {
40
+ return true;
41
+ }
42
+ else {
43
+ this.routes.delete(item.prefix);
44
+ return false;
45
+ }
46
+ });
34
47
  // sort router
35
48
  for (const prefix of this.routes.keys()) {
36
49
  const routerInfo = this.routes.get(prefix);
@@ -38,37 +51,57 @@ class WebRouterCollector {
38
51
  }
39
52
  // sort prefix
40
53
  this.routesPriority = this.routesPriority.sort((routeA, routeB) => {
41
- return routeB.priority - routeA.priority;
54
+ return routeB.prefix.length - routeA.prefix.length;
42
55
  });
43
56
  }
44
57
  collectRoute(module, functionMeta = false) {
45
- const controllerId = decorator_1.getProviderId(module);
46
- const controllerOption = decorator_1.getClassMetadata(decorator_1.CONTROLLER_KEY, module);
47
- // sort for priority
48
- let priority = decorator_1.getClassMetadata(decorator_1.PRIORITY_KEY, module);
58
+ var _a;
59
+ const controllerId = (0, decorator_1.getProviderName)(module);
60
+ debug(`[core:webCollector]: Found Controller ${controllerId}.`);
61
+ const id = (0, decorator_1.getProviderUUId)(module);
62
+ const controllerOption = (0, decorator_1.getClassMetadata)(decorator_1.CONTROLLER_KEY, module);
63
+ let priority;
49
64
  // implement middleware in controller
50
65
  const middleware = controllerOption.routerOptions.middleware;
51
- const prefix = controllerOption.prefix || '/';
52
- if (prefix === '/' && priority === undefined) {
53
- priority = -999;
66
+ const controllerIgnoreGlobalPrefix = !!((_a = controllerOption.routerOptions) === null || _a === void 0 ? void 0 : _a.ignoreGlobalPrefix);
67
+ let prefix = (0, util_1.joinURLPath)(this.options.globalPrefix, controllerOption.prefix || '/');
68
+ const ignorePrefix = controllerOption.prefix || '/';
69
+ // if controller set ignore global prefix, all router will be ignore too.
70
+ if (controllerIgnoreGlobalPrefix) {
71
+ prefix = ignorePrefix;
54
72
  }
73
+ // set prefix
55
74
  if (!this.routes.has(prefix)) {
56
75
  this.routes.set(prefix, []);
57
76
  this.routesPriority.push({
58
77
  prefix,
59
- priority: priority || 0,
78
+ priority: prefix === '/' && priority === undefined ? -999 : 0,
60
79
  middleware,
61
80
  routerOptions: controllerOption.routerOptions,
62
81
  controllerId,
82
+ routerModule: module,
63
83
  });
64
84
  }
65
- const webRouterInfo = decorator_1.getClassMetadata(decorator_1.WEB_ROUTER_KEY, module);
85
+ // set ignorePrefix
86
+ if (!this.routes.has(ignorePrefix)) {
87
+ this.routes.set(ignorePrefix, []);
88
+ this.routesPriority.push({
89
+ prefix: ignorePrefix,
90
+ priority: ignorePrefix === '/' && priority === undefined ? -999 : 0,
91
+ middleware,
92
+ routerOptions: controllerOption.routerOptions,
93
+ controllerId,
94
+ routerModule: module,
95
+ });
96
+ }
97
+ const webRouterInfo = (0, decorator_1.getClassMetadata)(decorator_1.WEB_ROUTER_KEY, module);
66
98
  if (webRouterInfo && typeof webRouterInfo[Symbol.iterator] === 'function') {
67
99
  for (const webRouter of webRouterInfo) {
68
- const routeArgsInfo = decorator_1.getPropertyDataFromClass(decorator_1.WEB_ROUTER_PARAM_KEY, module, webRouter.method) || [];
69
- const routerResponseData = decorator_1.getPropertyMetadata(decorator_1.WEB_RESPONSE_KEY, module, webRouter.method) || [];
100
+ const routeArgsInfo = (0, decorator_1.getPropertyDataFromClass)(decorator_1.WEB_ROUTER_PARAM_KEY, module, webRouter.method) || [];
101
+ const routerResponseData = (0, decorator_1.getPropertyMetadata)(decorator_1.WEB_RESPONSE_KEY, module, webRouter.method) || [];
70
102
  const data = {
71
- prefix,
103
+ id,
104
+ prefix: webRouter.ignoreGlobalPrefix ? ignorePrefix : prefix,
72
105
  routerName: webRouter.routerName || '',
73
106
  url: webRouter.path,
74
107
  requestMethod: webRouter.requestMethod,
@@ -88,22 +121,23 @@ class WebRouterCollector {
88
121
  data.functionName = controllerId + '-' + webRouter.method;
89
122
  data.functionTriggerName = decorator_1.ServerlessTriggerType.HTTP;
90
123
  data.functionTriggerMetadata = {
91
- path: index_1.joinURLPath(prefix, webRouter.path.toString()),
124
+ path: (0, util_1.joinURLPath)(prefix, webRouter.path.toString()),
92
125
  method: webRouter.requestMethod,
93
126
  };
94
127
  data.functionMetadata = {
95
128
  functionName: data.functionName,
96
129
  };
97
130
  }
98
- this.checkDuplicateAndPush(prefix, data);
131
+ this.checkDuplicateAndPush(data.prefix, data);
99
132
  }
100
133
  }
101
134
  }
102
135
  collectFunctionRoute(module, functionMeta = false) {
103
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
104
- // 老的函数路由
105
- const webRouterInfo = decorator_1.getClassMetadata(decorator_1.FUNC_KEY, module);
106
- const controllerId = decorator_1.getProviderId(module);
136
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
137
+ // serverlessTrigger metadata
138
+ const webRouterInfo = (0, decorator_1.getClassMetadata)(decorator_1.FUNC_KEY, module);
139
+ const controllerId = (0, decorator_1.getProviderName)(module);
140
+ const id = (0, decorator_1.getProviderUUId)(module);
107
141
  const prefix = '/';
108
142
  if (!this.routes.has(prefix)) {
109
143
  this.routes.set(prefix, []);
@@ -113,134 +147,74 @@ class WebRouterCollector {
113
147
  middleware: [],
114
148
  routerOptions: {},
115
149
  controllerId,
150
+ routerModule: module,
116
151
  });
117
152
  }
118
153
  for (const webRouter of webRouterInfo) {
119
- if (webRouter['type']) {
120
- // 新的 @ServerlessTrigger 写法
121
- if ((_a = webRouter['metadata']) === null || _a === void 0 ? void 0 : _a['path']) {
122
- const routeArgsInfo = decorator_1.getPropertyDataFromClass(decorator_1.WEB_ROUTER_PARAM_KEY, module, webRouter['methodName']) || [];
123
- const routerResponseData = decorator_1.getPropertyMetadata(decorator_1.WEB_RESPONSE_KEY, module, webRouter['methodName']) || [];
124
- // http/api gateway 函数
125
- const data = {
126
- prefix,
127
- routerName: '',
128
- url: webRouter['metadata']['path'],
129
- requestMethod: (_c = (_b = webRouter['metadata']) === null || _b === void 0 ? void 0 : _b['method']) !== null && _c !== void 0 ? _c : 'get',
130
- method: webRouter['methodName'],
131
- description: '',
132
- summary: '',
133
- handlerName: `${controllerId}.${webRouter['methodName']}`,
134
- funcHandlerName: `${controllerId}.${webRouter['methodName']}`,
135
- controllerId,
136
- middleware: ((_d = webRouter['metadata']) === null || _d === void 0 ? void 0 : _d['middleware']) || [],
137
- controllerMiddleware: [],
138
- requestMetadata: routeArgsInfo,
139
- responseMetadata: routerResponseData,
154
+ // 新的 @ServerlessTrigger 写法
155
+ if ((_a = webRouter['metadata']) === null || _a === void 0 ? void 0 : _a['path']) {
156
+ const routeArgsInfo = (0, decorator_1.getPropertyDataFromClass)(decorator_1.WEB_ROUTER_PARAM_KEY, module, webRouter['methodName']) || [];
157
+ const routerResponseData = (0, decorator_1.getPropertyMetadata)(decorator_1.WEB_RESPONSE_KEY, module, webRouter['methodName']) || [];
158
+ // http/api gateway 函数
159
+ const data = {
160
+ id,
161
+ prefix,
162
+ routerName: '',
163
+ url: webRouter['metadata']['path'],
164
+ requestMethod: (_c = (_b = webRouter['metadata']) === null || _b === void 0 ? void 0 : _b['method']) !== null && _c !== void 0 ? _c : 'get',
165
+ method: webRouter['methodName'],
166
+ description: '',
167
+ summary: '',
168
+ handlerName: `${controllerId}.${webRouter['methodName']}`,
169
+ funcHandlerName: `${controllerId}.${webRouter['methodName']}`,
170
+ controllerId,
171
+ middleware: ((_d = webRouter['metadata']) === null || _d === void 0 ? void 0 : _d['middleware']) || [],
172
+ controllerMiddleware: [],
173
+ requestMetadata: routeArgsInfo,
174
+ responseMetadata: routerResponseData,
175
+ };
176
+ if (functionMeta) {
177
+ const functionMeta = (0, decorator_1.getPropertyMetadata)(decorator_1.SERVERLESS_FUNC_KEY, module, webRouter['methodName']) || {};
178
+ const functionName = (_f = (_e = functionMeta['functionName']) !== null && _e !== void 0 ? _e : webRouter['functionName']) !== null && _f !== void 0 ? _f : createFunctionName(module, webRouter['methodName']);
179
+ data.functionName = functionName;
180
+ data.functionTriggerName = webRouter['type'];
181
+ data.functionTriggerMetadata = webRouter['metadata'];
182
+ data.functionMetadata = {
183
+ functionName,
184
+ ...functionMeta,
140
185
  };
141
- if (functionMeta) {
142
- data.functionName = webRouter['functionName'];
143
- data.functionTriggerName = webRouter['type'];
144
- data.functionTriggerMetadata = webRouter['metadata'];
145
- const functionMeta = decorator_1.getPropertyMetadata(decorator_1.SERVERLESS_FUNC_KEY, module, webRouter['methodName']) || {};
146
- data.functionMetadata = {
147
- functionName: webRouter['functionName'],
148
- ...functionMeta,
149
- };
150
- }
151
- this.checkDuplicateAndPush(prefix, data);
152
- }
153
- else {
154
- if (functionMeta) {
155
- const functionMeta = decorator_1.getPropertyMetadata(decorator_1.SERVERLESS_FUNC_KEY, module, webRouter['methodName']) || {};
156
- // 其他类型的函数
157
- this.checkDuplicateAndPush(prefix, {
158
- prefix,
159
- routerName: '',
160
- url: '',
161
- requestMethod: '',
162
- method: webRouter['methodName'],
163
- description: '',
164
- summary: '',
165
- handlerName: `${controllerId}.${webRouter['methodName']}`,
166
- funcHandlerName: `${controllerId}.${webRouter['methodName']}`,
167
- controllerId,
168
- middleware: [],
169
- controllerMiddleware: [],
170
- requestMetadata: [],
171
- responseMetadata: [],
172
- functionName: webRouter['functionName'],
173
- functionTriggerName: webRouter['type'],
174
- functionTriggerMetadata: webRouter['metadata'],
175
- functionMetadata: {
176
- functionName: webRouter['functionName'],
177
- ...functionMeta,
178
- },
179
- });
180
- }
181
186
  }
187
+ this.checkDuplicateAndPush(prefix, data);
182
188
  }
183
189
  else {
184
- // 老的 @Func 写法
185
- if (webRouter['path'] || webRouter['middleware']) {
186
- const data = {
190
+ if (functionMeta) {
191
+ const functionMeta = (0, decorator_1.getPropertyMetadata)(decorator_1.SERVERLESS_FUNC_KEY, module, webRouter['methodName']) || {};
192
+ const functionName = (_h = (_g = functionMeta['functionName']) !== null && _g !== void 0 ? _g : webRouter['functionName']) !== null && _h !== void 0 ? _h : createFunctionName(module, webRouter['methodName']);
193
+ // 其他类型的函数
194
+ this.checkDuplicateAndPush(prefix, {
195
+ id,
187
196
  prefix,
188
197
  routerName: '',
189
- url: (_e = webRouter['path']) !== null && _e !== void 0 ? _e : '',
190
- requestMethod: (_f = webRouter['method']) !== null && _f !== void 0 ? _f : 'get',
191
- method: (_g = webRouter['key']) !== null && _g !== void 0 ? _g : '',
198
+ url: '',
199
+ requestMethod: '',
200
+ method: webRouter['methodName'],
192
201
  description: '',
193
202
  summary: '',
194
- handlerName: `${controllerId}.${webRouter['key']}`,
195
- funcHandlerName: webRouter['funHandler'] || `${controllerId}.${webRouter['key']}`,
203
+ handlerName: `${controllerId}.${webRouter['methodName']}`,
204
+ funcHandlerName: `${controllerId}.${webRouter['methodName']}`,
196
205
  controllerId,
197
- middleware: webRouter['middleware'] || [],
206
+ middleware: ((_j = webRouter['metadata']) === null || _j === void 0 ? void 0 : _j['middleware']) || [],
198
207
  controllerMiddleware: [],
199
208
  requestMetadata: [],
200
209
  responseMetadata: [],
201
- };
202
- if (functionMeta) {
203
- // get function information
204
- data.functionName = controllerId + '-' + ((_h = webRouter['key']) !== null && _h !== void 0 ? _h : '');
205
- data.functionTriggerName = decorator_1.ServerlessTriggerType.HTTP;
206
- data.functionTriggerMetadata = {
207
- path: (_j = webRouter['path']) !== null && _j !== void 0 ? _j : '/',
208
- method: (_k = webRouter['method']) !== null && _k !== void 0 ? _k : 'get',
209
- };
210
- data.functionMetadata = {
211
- functionName: data.functionName,
212
- };
213
- }
214
- // 老函数的 http
215
- this.checkDuplicateAndPush(prefix, data);
216
- }
217
- else {
218
- if (functionMeta) {
219
- // 非 http
220
- this.checkDuplicateAndPush(prefix, {
221
- prefix,
222
- routerName: '',
223
- url: '',
224
- requestMethod: '',
225
- method: webRouter['key'],
226
- description: '',
227
- summary: '',
228
- handlerName: `${controllerId}.${webRouter['key']}`,
229
- funcHandlerName: webRouter['funHandler'] ||
230
- `${controllerId}.${webRouter['key']}`,
231
- controllerId,
232
- middleware: webRouter['middleware'] || [],
233
- controllerMiddleware: [],
234
- requestMetadata: [],
235
- responseMetadata: [],
236
- functionName: webRouter['functionName'],
237
- functionTriggerName: webRouter['type'],
238
- functionTriggerMetadata: webRouter['metadata'],
239
- functionMetadata: {
240
- functionName: webRouter['functionName'],
241
- },
242
- });
243
- }
210
+ functionName,
211
+ functionTriggerName: webRouter['type'],
212
+ functionTriggerMetadata: webRouter['metadata'],
213
+ functionMetadata: {
214
+ functionName,
215
+ ...functionMeta,
216
+ },
217
+ });
244
218
  }
245
219
  }
246
220
  }
@@ -254,7 +228,7 @@ class WebRouterCollector {
254
228
  return urlMatchList
255
229
  .map(item => {
256
230
  const urlString = item.url.toString();
257
- const weightArr = decorator_1.isRegExp(item.url)
231
+ const weightArr = (0, decorator_1.isRegExp)(item.url)
258
232
  ? urlString.split('/')
259
233
  : urlString.split('/');
260
234
  let weight = 0;
@@ -325,8 +299,8 @@ class WebRouterCollector {
325
299
  this.isReady = true;
326
300
  }
327
301
  let routeArr = [];
328
- for (const routerInfo of this.routes.values()) {
329
- routeArr = routeArr.concat(routerInfo);
302
+ for (const routerPriority of this.routesPriority) {
303
+ routeArr = routeArr.concat(this.routes.get(routerPriority.prefix));
330
304
  }
331
305
  return routeArr;
332
306
  }
@@ -345,4 +319,7 @@ class WebRouterCollector {
345
319
  }
346
320
  }
347
321
  exports.WebRouterCollector = WebRouterCollector;
322
+ function createFunctionName(target, functionName) {
323
+ return (0, decorator_1.getProviderName)(target).replace(/[:#]/g, '-') + '-' + functionName;
324
+ }
348
325
  //# sourceMappingURL=webRouterCollector.js.map
@@ -0,0 +1,7 @@
1
+ import { MidwayAppInfo, ServiceFactoryConfigOption } from '../interface';
2
+ import type { LoggerOptions } from '@midwayjs/logger';
3
+ declare const _default: (appInfo: MidwayAppInfo) => {
4
+ midwayLogger?: ServiceFactoryConfigOption<LoggerOptions>;
5
+ };
6
+ export default _default;
7
+ //# sourceMappingURL=config.default.d.ts.map
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const interface_1 = require("../interface");
4
+ const util_1 = require("../util/");
5
+ const path_1 = require("path");
6
+ exports.default = (appInfo) => {
7
+ var _a;
8
+ const isDevelopment = (0, util_1.isDevelopmentEnvironment)((0, util_1.getCurrentEnvironment)());
9
+ return {
10
+ midwayLogger: {
11
+ default: {
12
+ dir: (0, path_1.join)((_a = process.env[interface_1.MIDWAY_LOGGER_WRITEABLE_DIR]) !== null && _a !== void 0 ? _a : appInfo.root, 'logs', appInfo.name),
13
+ level: isDevelopment ? 'info' : 'warn',
14
+ consoleLevel: isDevelopment ? 'info' : 'warn',
15
+ },
16
+ clients: {
17
+ coreLogger: {
18
+ fileLogName: 'midway-core.log',
19
+ },
20
+ appLogger: {
21
+ fileLogName: 'midway-app.log',
22
+ aliasName: 'logger',
23
+ },
24
+ },
25
+ },
26
+ };
27
+ };
28
+ //# sourceMappingURL=config.default.js.map
@@ -1,54 +1,84 @@
1
- import { ObjectDefinitionOptions, ObjectIdentifier } from '@midwayjs/decorator';
2
- import { BaseApplicationContext } from './applicationContext';
3
- import { IConfigService, IEnvironmentService, IFileDetector, IInformationService, IMidwayContainer, IObjectDefinitionMetadata } from '../interface';
4
- import { ResolverHandler } from './resolverHandler';
5
- declare class ContainerConfiguration {
6
- readonly container: any;
7
- private namespace;
8
- constructor(container: any);
9
- load(module: any): void;
10
- addImportConfigs(importConfigs: string[]): void;
11
- addImports(imports?: any[]): void;
12
- bindConfigurationClass(clzz: any, filePath?: string): void;
13
- private getConfigurationExport;
14
- }
15
- export declare class MidwayContainer extends BaseApplicationContext implements IMidwayContainer {
16
- private debugLogger;
17
- private definitionMetadataList;
18
- protected resolverHandler: ResolverHandler;
1
+ /// <reference types="node" />
2
+ import { ObjectIdentifier, IModuleStore } from '@midwayjs/decorator';
3
+ import { IFileDetector, IIdentifierRelationShip, IMidwayContainer, IObjectDefinition, IObjectDefinitionRegistry, ObjectContext } from '../interface';
4
+ import { ManagedResolverFactory } from './managedResolverFactory';
5
+ import * as EventEmitter from 'events';
6
+ export declare class MidwayContainer implements IMidwayContainer, IModuleStore {
7
+ private _resolverFactory;
8
+ private _registry;
9
+ private _identifierMapping;
10
+ private moduleMap;
11
+ private _objectCreateEventTarget;
12
+ parent: IMidwayContainer;
19
13
  protected ctx: {};
20
- protected configService: IConfigService;
21
- protected environmentService: IEnvironmentService;
22
- protected informationService: IInformationService;
23
- protected aspectService: any;
24
14
  private fileDetector;
25
15
  private attrMap;
16
+ private _namespaceSet;
26
17
  private isLoad;
27
- init(): void;
28
- initService(): void;
18
+ constructor(parent?: IMidwayContainer);
19
+ protected init(): void;
20
+ get objectCreateEventTarget(): EventEmitter;
21
+ get registry(): IObjectDefinitionRegistry;
22
+ set registry(registry: IObjectDefinitionRegistry);
23
+ get managedResolverFactory(): ManagedResolverFactory;
24
+ get identifierMapping(): IIdentifierRelationShip;
25
+ get namespaceSet(): Set<string>;
29
26
  load(module?: any): void;
30
- loadDefinitions(): void;
31
- createConfiguration(): ContainerConfiguration;
32
- bindClass(exports: any, namespace?: string, filePath?: string): void;
33
- bind<T>(target: T, options?: ObjectDefinitionOptions): void;
34
- bind<T>(identifier: ObjectIdentifier, target: T, options?: ObjectDefinitionOptions): void;
35
- protected restoreDefinition(definitionMeta: IObjectDefinitionMetadata): void;
36
- protected restoreDefinitions(definitionMetadataList: any): void;
37
- protected getDefinitionMetaList(): any[];
38
- protected bindModule(module: any, namespace?: string, filePath?: string): void;
39
- getDebugLogger(): (msg: string, ...param: any[]) => void;
27
+ protected loadDefinitions(): void;
28
+ bindClass(exports: any, options?: Partial<IObjectDefinition>): void;
29
+ bind<T>(target: T, options?: Partial<IObjectDefinition>): void;
30
+ bind<T>(identifier: ObjectIdentifier, target: T, options?: Partial<IObjectDefinition>): void;
31
+ protected bindModule(module: any, options: Partial<IObjectDefinition>): void;
40
32
  setFileDetector(fileDetector: IFileDetector): void;
41
33
  createChild(): IMidwayContainer;
42
- registerDataHandler(handlerType: string, handler: (...args: any[]) => any): void;
43
- getConfigService(): IConfigService;
44
- getEnvironmentService(): IEnvironmentService;
45
- getInformationService(): IInformationService;
46
- setInformationService(informationService: any): void;
47
- getAspectService(): any;
48
- getCurrentEnv(): string;
49
- getResolverHandler(): ResolverHandler;
50
34
  setAttr(key: string, value: any): void;
51
35
  getAttr<T>(key: string): T;
36
+ protected getIdentifier(target: any): string;
37
+ protected getManagedResolverFactory(): ManagedResolverFactory;
38
+ stop(): Promise<void>;
39
+ ready(): Promise<void>;
40
+ get<T>(identifier: {
41
+ new (...args: any[]): T;
42
+ }, args?: any[], objectContext?: ObjectContext): T;
43
+ get<T>(identifier: ObjectIdentifier, args?: any[], objectContext?: ObjectContext): T;
44
+ getAsync<T>(identifier: {
45
+ new (...args: any[]): T;
46
+ }, args?: any[], objectContext?: ObjectContext): Promise<T>;
47
+ getAsync<T>(identifier: ObjectIdentifier, args?: any[], objectContext?: ObjectContext): Promise<T>;
48
+ /**
49
+ * proxy registry.registerObject
50
+ * @param {ObjectIdentifier} identifier
51
+ * @param target
52
+ */
53
+ registerObject(identifier: ObjectIdentifier, target: any): void;
54
+ onBeforeBind(fn: (Clzz: any, options: {
55
+ context: IMidwayContainer;
56
+ definition: IObjectDefinition;
57
+ replaceCallback: (newDefinition: IObjectDefinition) => void;
58
+ }) => void): void;
59
+ onBeforeObjectCreated(fn: (Clzz: any, options: {
60
+ context: IMidwayContainer;
61
+ definition: IObjectDefinition;
62
+ constructorArgs: any[];
63
+ }) => void): void;
64
+ onObjectCreated<T>(fn: (ins: T, options: {
65
+ context: IMidwayContainer;
66
+ definition: IObjectDefinition;
67
+ replaceCallback: (ins: T) => void;
68
+ }) => void): void;
69
+ onObjectInit<T>(fn: (ins: T, options: {
70
+ context: IMidwayContainer;
71
+ definition: IObjectDefinition;
72
+ }) => void): void;
73
+ onBeforeObjectDestroy<T>(fn: (ins: T, options: {
74
+ context: IMidwayContainer;
75
+ definition: IObjectDefinition;
76
+ }) => void): void;
77
+ saveModule(key: any, module: any): void;
78
+ listModule(key: string): unknown[];
79
+ transformModule(moduleMap: Map<string, Set<any>>): void;
80
+ hasNamespace(ns: string): boolean;
81
+ hasDefinition(identifier: ObjectIdentifier): boolean;
82
+ hasObject(identifier: ObjectIdentifier): boolean;
52
83
  }
53
- export {};
54
84
  //# sourceMappingURL=container.d.ts.map