@midwayjs/core 4.0.0-alpha.1 → 4.0.0-beta.1

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 (59) hide show
  1. package/README.md +1 -1
  2. package/dist/baseFramework.d.ts +7 -4
  3. package/dist/baseFramework.js +12 -10
  4. package/dist/common/applicationManager.js +5 -1
  5. package/dist/common/dataListener.d.ts +5 -3
  6. package/dist/common/dataListener.js +12 -3
  7. package/dist/common/dataSourceManager.d.ts +18 -9
  8. package/dist/common/dataSourceManager.js +121 -71
  9. package/dist/common/serviceDiscovery/healthCheck.d.ts +66 -0
  10. package/dist/common/serviceDiscovery/healthCheck.js +207 -0
  11. package/dist/common/serviceDiscovery/loadBalancer.d.ts +21 -0
  12. package/dist/common/serviceDiscovery/loadBalancer.js +51 -0
  13. package/dist/common/serviceDiscovery/serviceDiscovery.d.ts +59 -0
  14. package/dist/common/serviceDiscovery/serviceDiscovery.js +104 -0
  15. package/dist/common/serviceFactory.d.ts +5 -2
  16. package/dist/common/serviceFactory.js +43 -8
  17. package/dist/config/config.default.js +3 -0
  18. package/dist/context/container.d.ts +4 -3
  19. package/dist/context/container.js +6 -2
  20. package/dist/context/definitionRegistry.d.ts +2 -0
  21. package/dist/context/definitionRegistry.js +9 -11
  22. package/dist/context/dynamicContainer.d.ts +17 -0
  23. package/dist/context/dynamicContainer.js +202 -0
  24. package/dist/context/managedResolverFactory.d.ts +1 -2
  25. package/dist/context/managedResolverFactory.js +14 -7
  26. package/dist/context/requestContainer.d.ts +1 -0
  27. package/dist/context/requestContainer.js +3 -0
  28. package/dist/decorator/metadataManager.d.ts +6 -2
  29. package/dist/definitions/objectCreator.js +3 -1
  30. package/dist/error/framework.d.ts +1 -1
  31. package/dist/error/framework.js +4 -2
  32. package/dist/error/http.d.ts +7 -0
  33. package/dist/error/http.js +11 -1
  34. package/dist/functional/configuration.d.ts +6 -6
  35. package/dist/functional/configuration.js +10 -10
  36. package/dist/functional/hooks.d.ts +3 -1
  37. package/dist/functional/hooks.js +11 -1
  38. package/dist/index.d.ts +5 -1
  39. package/dist/index.js +8 -2
  40. package/dist/interface.d.ts +180 -20
  41. package/dist/interface.js +15 -1
  42. package/dist/service/configService.d.ts +1 -1
  43. package/dist/service/configService.js +3 -2
  44. package/dist/service/healthService.d.ts +2 -0
  45. package/dist/service/healthService.js +15 -4
  46. package/dist/service/informationService.d.ts +3 -0
  47. package/dist/service/informationService.js +10 -0
  48. package/dist/service/lifeCycleService.d.ts +13 -7
  49. package/dist/service/lifeCycleService.js +49 -32
  50. package/dist/setup.js +8 -1
  51. package/dist/util/index.d.ts +2 -17
  52. package/dist/util/index.js +8 -67
  53. package/dist/util/network.d.ts +10 -0
  54. package/dist/util/network.js +40 -0
  55. package/dist/util/pathFileUtil.d.ts +1 -1
  56. package/dist/util/pathFileUtil.js +2 -2
  57. package/dist/util/timeout.d.ts +57 -0
  58. package/dist/util/timeout.js +144 -0
  59. package/package.json +3 -3
package/README.md CHANGED
@@ -9,4 +9,4 @@ Document: [https://midwayjs.org](https://midwayjs.org)
9
9
 
10
10
  ## License
11
11
 
12
- [MIT]((http://github.com/midwayjs/midway/blob/master/LICENSE))
12
+ [MIT]((https://github.com/midwayjs/midway/blob/master/LICENSE))
@@ -14,10 +14,8 @@ export declare abstract class BaseFramework<APP extends IMidwayApplication<CTX>,
14
14
  app: APP;
15
15
  configurationOptions: OPT;
16
16
  protected logger: ILogger;
17
- protected appLogger: ILogger;
17
+ protected frameworkLoggerName: string;
18
18
  protected defaultContext: {};
19
- protected contextLoggerApplyLogger: string;
20
- protected contextLoggerFormat: any;
21
19
  protected middlewareManager: ContextMiddlewareManager<CTX, ResOrNext, Next>;
22
20
  protected filterManager: FilterManager<CTX, ResOrNext, Next>;
23
21
  protected guardManager: GuardManager<CTX>;
@@ -32,7 +30,7 @@ export declare abstract class BaseFramework<APP extends IMidwayApplication<CTX>,
32
30
  middlewareService: MidwayMiddlewareService<CTX, ResOrNext, Next>;
33
31
  mockService: MidwayMockService;
34
32
  constructor(applicationContext: IMidwayGlobalContainer);
35
- init(): Promise<this>;
33
+ protected init(): Promise<this>;
36
34
  abstract configure(options?: OPT): OPT;
37
35
  abstract applicationInitialize(options: IMidwayBootstrapOptions): void | Promise<void>;
38
36
  abstract run(): Promise<void>;
@@ -64,5 +62,10 @@ export declare abstract class BaseFramework<APP extends IMidwayApplication<CTX>,
64
62
  protected createGuardManager(): GuardManager<CTX>;
65
63
  setNamespace(namespace: string): void;
66
64
  getNamespace(): string;
65
+ /**
66
+ * Set the default framework logger name
67
+ * @since 4.0.0
68
+ */
69
+ setFrameworkLoggerName(loggerName: string): void;
67
70
  }
68
71
  //# sourceMappingURL=baseFramework.d.ts.map
@@ -29,6 +29,7 @@ const debug = util.debuglog('midway:debug');
29
29
  class BaseFramework {
30
30
  constructor(applicationContext) {
31
31
  this.applicationContext = applicationContext;
32
+ this.frameworkLoggerName = 'appLogger';
32
33
  this.defaultContext = {};
33
34
  this.middlewareManager = this.createMiddlewareManager();
34
35
  this.filterManager = this.createFilterManager();
@@ -37,11 +38,7 @@ class BaseFramework {
37
38
  }
38
39
  async init() {
39
40
  this.configurationOptions = this.configure() ?? {};
40
- this.contextLoggerApplyLogger =
41
- this.configurationOptions.contextLoggerApplyLogger ?? 'appLogger';
42
- this.contextLoggerFormat = this.configurationOptions.contextLoggerFormat;
43
41
  this.logger = this.loggerService.getLogger('coreLogger');
44
- this.appLogger = this.loggerService.getLogger('appLogger');
45
42
  return this;
46
43
  }
47
44
  isEnable() {
@@ -74,7 +71,7 @@ class BaseFramework {
74
71
  return this.app;
75
72
  }
76
73
  createContextLogger(ctx, name) {
77
- if (name && name !== 'appLogger') {
74
+ if (name && name !== this.frameworkLoggerName) {
78
75
  const appLogger = this.getLogger(name);
79
76
  let ctxLoggerCache = ctx.getAttr(constants_1.REQUEST_CTX_LOGGER_CACHE_KEY);
80
77
  if (!ctxLoggerCache) {
@@ -91,14 +88,12 @@ class BaseFramework {
91
88
  return ctxLogger;
92
89
  }
93
90
  else {
94
- const appLogger = this.getLogger(name ?? this.contextLoggerApplyLogger);
95
91
  // avoid maximum call stack size exceeded
96
92
  if (ctx['_logger']) {
97
93
  return ctx['_logger'];
98
94
  }
99
- ctx['_logger'] = this.loggerService.createContextLogger(ctx, appLogger, {
100
- contextFormat: this.contextLoggerFormat,
101
- });
95
+ const appLogger = this.getLogger(name);
96
+ ctx['_logger'] = this.loggerService.createContextLogger(ctx, appLogger);
102
97
  return ctx['_logger'];
103
98
  }
104
99
  }
@@ -258,7 +253,7 @@ class BaseFramework {
258
253
  return this.composeMiddleware;
259
254
  }
260
255
  getLogger(name) {
261
- return this.loggerService.getLogger(name) ?? this.appLogger;
256
+ return this.loggerService.getLogger(name ?? this.frameworkLoggerName);
262
257
  }
263
258
  getCoreLogger() {
264
259
  return this.logger;
@@ -302,6 +297,13 @@ class BaseFramework {
302
297
  getNamespace() {
303
298
  return this.namespace;
304
299
  }
300
+ /**
301
+ * Set the default framework logger name
302
+ * @since 4.0.0
303
+ */
304
+ setFrameworkLoggerName(loggerName) {
305
+ this.frameworkLoggerName = loggerName;
306
+ }
305
307
  }
306
308
  exports.BaseFramework = BaseFramework;
307
309
  __decorate([
@@ -33,8 +33,12 @@ let MidwayApplicationManager = class MidwayApplicationManager {
33
33
  }
34
34
  getApplications(frameworkNameOrNamespace) {
35
35
  if (!frameworkNameOrNamespace) {
36
- return Array.from(this.globalFrameworkMap.values()).map(framework => {
36
+ return Array.from(this.globalFrameworkMap.values())
37
+ .map(framework => {
37
38
  return framework.getApplication();
39
+ })
40
+ .filter(app => {
41
+ return !!app;
38
42
  });
39
43
  }
40
44
  else {
@@ -1,10 +1,12 @@
1
- export declare abstract class DataListener<T> {
2
- private innerData;
1
+ export declare abstract class DataListener<T, U = T> {
2
+ protected innerData: T;
3
+ private isReady;
3
4
  protected init(): Promise<void>;
4
5
  abstract initData(): T | Promise<T>;
5
6
  abstract onData(callback: (data: T) => void): any;
6
7
  protected setData(data: T): void;
7
- getData(): T;
8
+ getData(): U;
9
+ protected transformData(data: T): U;
8
10
  stop(): Promise<void>;
9
11
  protected destroyListener(): Promise<void>;
10
12
  }
@@ -12,15 +12,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.DataListener = void 0;
13
13
  const decorator_1 = require("../decorator");
14
14
  class DataListener {
15
+ constructor() {
16
+ this.isReady = false;
17
+ }
15
18
  async init() {
16
- this.innerData = await this.initData();
17
- await this.onData(this.setData.bind(this));
19
+ if (!this.isReady) {
20
+ this.innerData = await this.initData();
21
+ await this.onData(this.setData.bind(this));
22
+ this.isReady = true;
23
+ }
18
24
  }
19
25
  setData(data) {
20
26
  this.innerData = data;
21
27
  }
22
28
  getData() {
23
- return this.innerData;
29
+ return this.transformData(this.innerData);
30
+ }
31
+ transformData(data) {
32
+ return data;
24
33
  }
25
34
  async stop() {
26
35
  await this.destroyListener();
@@ -1,18 +1,20 @@
1
- import { ModuleLoadType, DataSourceManagerConfigOption } from '../interface';
1
+ import { ModuleLoadType, DataSourceManagerConfigOption, IDataSourceManager, BaseDataSourceManagerConfigOption } from '../interface';
2
2
  import { MidwayEnvironmentService } from '../service/environmentService';
3
3
  import { MidwayPriorityManager } from './priorityManager';
4
- export declare abstract class DataSourceManager<T, ConnectionOpts extends Record<string, any> = Record<string, any>> {
4
+ export declare abstract class DataSourceManager<T, ConnectionOpts extends BaseDataSourceManagerConfigOption<Record<string, any>, ENTITY_CONFIG_KEY> = BaseDataSourceManagerConfigOption<Record<string, any>, 'entities'>, ENTITY_CONFIG_KEY extends string = 'entities'> implements IDataSourceManager<T, ConnectionOpts> {
5
5
  protected dataSource: Map<string, T>;
6
- protected options: DataSourceManagerConfigOption<ConnectionOpts>;
6
+ protected options: DataSourceManagerConfigOption<ConnectionOpts, ENTITY_CONFIG_KEY>;
7
7
  protected modelMapping: WeakMap<object, any>;
8
8
  private innerDefaultDataSourceName;
9
9
  protected dataSourcePriority: Record<string, string>;
10
- protected appDir: string;
10
+ private creatingDataSources;
11
+ protected baseDir: string;
11
12
  protected environmentService: MidwayEnvironmentService;
12
13
  protected priorityManager: MidwayPriorityManager;
13
- protected initDataSource(dataSourceConfig: DataSourceManagerConfigOption<ConnectionOpts>, baseDirOrOptions: {
14
- baseDir: string;
14
+ protected initDataSource(dataSourceConfig: DataSourceManagerConfigOption<ConnectionOpts, ENTITY_CONFIG_KEY>, baseDirOrOptions: {
15
+ baseDir?: string;
15
16
  entitiesConfigKey?: string;
17
+ concurrent?: boolean;
16
18
  } | string): Promise<void>;
17
19
  /**
18
20
  * get a data source instance
@@ -31,8 +33,15 @@ export declare abstract class DataSourceManager<T, ConnectionOpts extends Record
31
33
  * @param dataSourceName
32
34
  */
33
35
  isConnected(dataSourceName: string): Promise<boolean>;
34
- createInstance(config: any, clientName: any, options?: {
36
+ createInstance(config: ConnectionOpts): Promise<T | void>;
37
+ createInstance(config: ConnectionOpts, clientName: string, options?: {
38
+ /**
39
+ * @deprecated
40
+ */
35
41
  validateConnection?: boolean;
42
+ /**
43
+ * @deprecated
44
+ */
36
45
  cacheInstance?: boolean | undefined;
37
46
  }): Promise<T | void>;
38
47
  /**
@@ -53,7 +62,7 @@ export declare abstract class DataSourceManager<T, ConnectionOpts extends Record
53
62
  isHighPriority(name: string): boolean;
54
63
  isMediumPriority(name: string): boolean;
55
64
  isLowPriority(name: string): boolean;
65
+ static formatGlobString(globString: string): string[];
66
+ static globModels(globString: string, baseDir: string, loadMode?: ModuleLoadType): Promise<any[]>;
56
67
  }
57
- export declare function formatGlobString(globString: string): string[];
58
- export declare function globModels(globString: string, appDir: string, loadMode?: ModuleLoadType): Promise<any[]>;
59
68
  //# sourceMappingURL=dataSourceManager.d.ts.map
@@ -9,7 +9,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.globModels = exports.formatGlobString = exports.DataSourceManager = void 0;
12
+ exports.DataSourceManager = void 0;
13
13
  /**
14
14
  * 数据源管理器实现
15
15
  */
@@ -31,6 +31,8 @@ class DataSourceManager {
31
31
  this.options = {};
32
32
  this.modelMapping = new WeakMap();
33
33
  this.dataSourcePriority = {};
34
+ // for multi client with initialization
35
+ this.creatingDataSources = new Map();
34
36
  }
35
37
  async initDataSource(dataSourceConfig, baseDirOrOptions) {
36
38
  this.options = dataSourceConfig;
@@ -41,18 +43,18 @@ class DataSourceManager {
41
43
  baseDirOrOptions = {
42
44
  baseDir: baseDirOrOptions,
43
45
  entitiesConfigKey: 'entities',
46
+ concurrent: false,
44
47
  };
45
48
  }
46
- for (const dataSourceName in dataSourceConfig.dataSource) {
47
- const dataSourceOptions = dataSourceConfig.dataSource[dataSourceName];
48
- const userEntities = dataSourceOptions[baseDirOrOptions.entitiesConfigKey];
49
+ const { baseDir = this.baseDir, entitiesConfigKey = 'entities', concurrent, } = baseDirOrOptions;
50
+ const processDataSource = async (dataSourceName, dataSourceOptions) => {
51
+ const userEntities = dataSourceOptions[entitiesConfigKey];
49
52
  if (userEntities) {
50
53
  const entities = new Set();
51
- // loop entities and glob files to model
52
- for (const entity of userEntities) {
54
+ const processEntity = async (entity) => {
53
55
  if (typeof entity === 'string') {
54
56
  // string will be glob file
55
- const models = await globModels(entity, baseDirOrOptions.baseDir, this.environmentService?.getModuleLoadType());
57
+ const models = await DataSourceManager.globModels(entity, baseDir, this.environmentService?.getModuleLoadType());
56
58
  for (const model of models) {
57
59
  entities.add(model);
58
60
  this.modelMapping.set(model, dataSourceName);
@@ -63,17 +65,33 @@ class DataSourceManager {
63
65
  entities.add(entity);
64
66
  this.modelMapping.set(entity, dataSourceName);
65
67
  }
68
+ };
69
+ if (concurrent) {
70
+ await Promise.all(userEntities.map(processEntity));
66
71
  }
67
- dataSourceOptions[baseDirOrOptions.entitiesConfigKey] =
68
- Array.from(entities);
69
- debug(`[core]: DataManager load ${dataSourceOptions[baseDirOrOptions.entitiesConfigKey].length} models from ${dataSourceName}.`);
72
+ else {
73
+ for (const entity of userEntities) {
74
+ await processEntity(entity);
75
+ }
76
+ }
77
+ dataSourceOptions[entitiesConfigKey] = Array.from(entities);
78
+ debug(`[core]: DataManager load ${dataSourceOptions[entitiesConfigKey].length} models from ${dataSourceName}.`);
70
79
  }
71
80
  // create data source
72
81
  const opts = {
73
- cacheInstance: dataSourceConfig.cacheInstance, // will default true
82
+ cacheInstance: dataSourceConfig.cacheInstance,
74
83
  validateConnection: dataSourceConfig.validateConnection,
75
84
  };
76
- await this.createInstance(dataSourceOptions, dataSourceName, opts);
85
+ return this.createInstance(dataSourceOptions, dataSourceName, opts);
86
+ };
87
+ const entries = Object.entries(dataSourceConfig.dataSource);
88
+ if (concurrent) {
89
+ await Promise.all(entries.map(([name, options]) => processDataSource(name, options)));
90
+ }
91
+ else {
92
+ for (const [name, options] of entries) {
93
+ await processDataSource(name, options);
94
+ }
77
95
  }
78
96
  }
79
97
  /**
@@ -105,26 +123,59 @@ class DataSourceManager {
105
123
  return inst ? this.checkConnected(inst) : false;
106
124
  }
107
125
  async createInstance(config, clientName, options) {
108
- const cache = options && typeof options.cacheInstance === 'boolean'
109
- ? options.cacheInstance
110
- : true;
111
- const validateConnection = (options && options.validateConnection) || false;
112
- // options.clients[id] will be merged with options.default
113
- const configNow = (0, extend_1.extend)(true, {}, this.options['default'], config);
114
- const client = await this.createDataSource(configNow, clientName);
115
- if (cache && clientName && client) {
116
- this.dataSource.set(clientName, client);
126
+ if (clientName && typeof clientName !== 'string') {
127
+ options = clientName;
128
+ clientName = undefined;
129
+ }
130
+ if (clientName && options && options.cacheInstance === false) {
131
+ // 后面就用传不传 clientName 来判断是否缓存
132
+ clientName = undefined;
117
133
  }
118
- if (validateConnection) {
119
- if (!client) {
120
- throw new error_1.MidwayCommonError(`[DataSourceManager] ${clientName} initialization failed.`);
134
+ if (clientName) {
135
+ if (this.dataSource.has(clientName)) {
136
+ return this.dataSource.get(clientName);
137
+ }
138
+ if (this.creatingDataSources.has(clientName)) {
139
+ return this.creatingDataSources.get(clientName);
121
140
  }
122
- const connected = await this.checkConnected(client);
123
- if (!connected) {
124
- throw new error_1.MidwayCommonError(`[DataSourceManager] ${clientName} is not connected.`);
141
+ }
142
+ const validateConnection = config.validateConnection ??
143
+ (options && options.validateConnection) ??
144
+ false;
145
+ // options.clients[id] will be merged with options.default
146
+ const configNow = (0, extend_1.extend)(true, {}, this.options['default'], config);
147
+ const clientCreatingPromise = this.createDataSource(configNow, clientName);
148
+ if (clientCreatingPromise && types_1.Types.isPromise(clientCreatingPromise)) {
149
+ if (clientName) {
150
+ this.creatingDataSources.set(clientName, clientCreatingPromise);
125
151
  }
152
+ return clientCreatingPromise
153
+ .then(async (client) => {
154
+ if (clientName) {
155
+ this.dataSource.set(clientName, client);
156
+ }
157
+ if (validateConnection) {
158
+ if (!client) {
159
+ throw new error_1.MidwayCommonError(`[DataSourceManager] ${clientName} initialization failed.`);
160
+ }
161
+ const connected = await this.checkConnected(client);
162
+ if (!connected) {
163
+ throw new error_1.MidwayCommonError(`[DataSourceManager] ${clientName} is not connected.`);
164
+ }
165
+ }
166
+ return client;
167
+ })
168
+ .finally(() => {
169
+ if (clientName) {
170
+ this.creatingDataSources.delete(clientName);
171
+ }
172
+ });
126
173
  }
127
- return client;
174
+ // 处理同步返回的情况
175
+ if (clientName) {
176
+ this.dataSource.set(clientName, clientCreatingPromise);
177
+ }
178
+ return clientCreatingPromise;
128
179
  }
129
180
  /**
130
181
  * get data source name by model or repository
@@ -171,12 +222,53 @@ class DataSourceManager {
171
222
  isLowPriority(name) {
172
223
  return this.priorityManager.isLowPriority(this.dataSourcePriority[name]);
173
224
  }
225
+ static formatGlobString(globString) {
226
+ let pattern;
227
+ if (!/^\*/.test(globString)) {
228
+ globString = '/' + globString;
229
+ }
230
+ const parsePattern = (0, path_1.parse)(globString);
231
+ if (parsePattern.base &&
232
+ (/\*/.test(parsePattern.base) || parsePattern.ext)) {
233
+ pattern = [globString];
234
+ }
235
+ else {
236
+ pattern = [...constants_1.DEFAULT_PATTERN.map(p => (0, path_1.join)(globString, p))];
237
+ }
238
+ return pattern;
239
+ }
240
+ static async globModels(globString, baseDir, loadMode) {
241
+ const pattern = this.formatGlobString(globString);
242
+ const models = [];
243
+ // string will be glob file
244
+ const files = (0, glob_1.run)(pattern, {
245
+ cwd: baseDir,
246
+ ignore: constants_1.IGNORE_PATTERN,
247
+ });
248
+ for (const file of files) {
249
+ const exports = await (0, util_2.loadModule)(file, {
250
+ loadMode,
251
+ });
252
+ if (types_1.Types.isClass(exports)) {
253
+ models.push(exports);
254
+ }
255
+ else {
256
+ for (const m in exports) {
257
+ const module = exports[m];
258
+ if (types_1.Types.isClass(module)) {
259
+ models.push(module);
260
+ }
261
+ }
262
+ }
263
+ }
264
+ return models;
265
+ }
174
266
  }
175
267
  exports.DataSourceManager = DataSourceManager;
176
268
  __decorate([
177
269
  (0, decorator_1.Inject)(),
178
270
  __metadata("design:type", String)
179
- ], DataSourceManager.prototype, "appDir", void 0);
271
+ ], DataSourceManager.prototype, "baseDir", void 0);
180
272
  __decorate([
181
273
  (0, decorator_1.Inject)(),
182
274
  __metadata("design:type", environmentService_1.MidwayEnvironmentService)
@@ -185,46 +277,4 @@ __decorate([
185
277
  (0, decorator_1.Inject)(),
186
278
  __metadata("design:type", priorityManager_1.MidwayPriorityManager)
187
279
  ], DataSourceManager.prototype, "priorityManager", void 0);
188
- function formatGlobString(globString) {
189
- let pattern;
190
- if (!/^\*/.test(globString)) {
191
- globString = '/' + globString;
192
- }
193
- const parsePattern = (0, path_1.parse)(globString);
194
- if (parsePattern.base && (/\*/.test(parsePattern.base) || parsePattern.ext)) {
195
- pattern = [globString];
196
- }
197
- else {
198
- pattern = [...constants_1.DEFAULT_PATTERN.map(p => (0, path_1.join)(globString, p))];
199
- }
200
- return pattern;
201
- }
202
- exports.formatGlobString = formatGlobString;
203
- async function globModels(globString, appDir, loadMode) {
204
- const pattern = formatGlobString(globString);
205
- const models = [];
206
- // string will be glob file
207
- const files = (0, glob_1.run)(pattern, {
208
- cwd: appDir,
209
- ignore: constants_1.IGNORE_PATTERN,
210
- });
211
- for (const file of files) {
212
- const exports = await (0, util_2.loadModule)(file, {
213
- loadMode,
214
- });
215
- if (types_1.Types.isClass(exports)) {
216
- models.push(exports);
217
- }
218
- else {
219
- for (const m in exports) {
220
- const module = exports[m];
221
- if (types_1.Types.isClass(module)) {
222
- models.push(module);
223
- }
224
- }
225
- }
226
- }
227
- return models;
228
- }
229
- exports.globModels = globModels;
230
280
  //# sourceMappingURL=dataSourceManager.js.map
@@ -0,0 +1,66 @@
1
+ import { HTTPServiceDiscoveryHealthCheckOptions, IServiceDiscoveryHealthCheck, ServiceDiscoveryHealthCheckOptions, ServiceDiscoveryHealthCheckResult, ServiceDiscoveryHealthCheckType, TCPServiceDiscoveryHealthCheckOptions, TTLServiceDiscoveryHealthCheckOptions } from '../../interface';
2
+ /**
3
+ * 抽象健康检查类
4
+ */
5
+ export declare abstract class AbstractHealthCheck<ServiceInstance> implements IServiceDiscoveryHealthCheck<ServiceInstance> {
6
+ protected options: ServiceDiscoveryHealthCheckOptions;
7
+ protected lastCheckTime: number;
8
+ protected lastCheckResult: ServiceDiscoveryHealthCheckResult | null;
9
+ constructor(options: ServiceDiscoveryHealthCheckOptions);
10
+ /**
11
+ * 执行健康检查
12
+ * @param instance 服务实例
13
+ */
14
+ abstract check(instance: ServiceInstance): Promise<ServiceDiscoveryHealthCheckResult>;
15
+ /**
16
+ * 是否需要检查
17
+ * 根据检查间隔判断是否需要执行新的检查
18
+ */
19
+ shouldCheck(): boolean;
20
+ /**
21
+ * 获取最后一次检查结果
22
+ */
23
+ getLastCheckResult(): ServiceDiscoveryHealthCheckResult | null;
24
+ /**
25
+ * 更新检查结果
26
+ */
27
+ protected updateCheckResult(result: ServiceDiscoveryHealthCheckResult): void;
28
+ }
29
+ /**
30
+ * TTL 健康检查实现
31
+ * 用于 Redis/ETCD 等基于 TTL 的服务发现
32
+ */
33
+ export declare class TTLHealthCheck<ServiceInstance> extends AbstractHealthCheck<ServiceInstance> {
34
+ private ttl;
35
+ constructor(options?: TTLServiceDiscoveryHealthCheckOptions);
36
+ check(instance: ServiceInstance): Promise<ServiceDiscoveryHealthCheckResult>;
37
+ }
38
+ /**
39
+ * HTTP 健康检查实现
40
+ * 用于支持 HTTP 检查的服务发现
41
+ */
42
+ export declare class HTTPHealthCheck<ServiceInstance> extends AbstractHealthCheck<ServiceInstance> {
43
+ private checkUrl;
44
+ private httpClient;
45
+ private httpOptions;
46
+ constructor(options: HTTPServiceDiscoveryHealthCheckOptions);
47
+ check(instance: ServiceInstance): Promise<ServiceDiscoveryHealthCheckResult>;
48
+ }
49
+ /**
50
+ * TCP 健康检查实现
51
+ * 用于支持 TCP 检查的服务发现
52
+ */
53
+ export declare class TCPHealthCheck<ServiceInstance> extends AbstractHealthCheck<ServiceInstance> {
54
+ private host;
55
+ private port;
56
+ private tcpOptions;
57
+ constructor(options: TCPServiceDiscoveryHealthCheckOptions);
58
+ check(instance: ServiceInstance): Promise<ServiceDiscoveryHealthCheckResult>;
59
+ }
60
+ /**
61
+ * 健康检查工厂
62
+ */
63
+ export declare class ServiceDiscoveryHealthCheckFactory {
64
+ static create<ServiceInstance>(type: ServiceDiscoveryHealthCheckType, options: ServiceDiscoveryHealthCheckOptions | IServiceDiscoveryHealthCheck<ServiceInstance>): IServiceDiscoveryHealthCheck<ServiceInstance>;
65
+ }
66
+ //# sourceMappingURL=healthCheck.d.ts.map