@midwayjs/core 3.13.6 → 3.14.0

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.
@@ -15,6 +15,7 @@ export declare abstract class LoggerFactory<Logger extends ILogger, LoggerOption
15
15
  abstract createContextLogger(ctx: any, appLogger: ILogger, contextOptions?: any): ILogger;
16
16
  }
17
17
  export declare class DefaultConsoleLoggerFactory implements LoggerFactory<ILogger, any> {
18
+ private instance;
18
19
  createLogger(name: string, options: any): ILogger;
19
20
  getLogger(loggerName: string): ILogger;
20
21
  close(loggerName?: string): void;
@@ -28,5 +29,7 @@ export declare class DefaultConsoleLoggerFactory implements LoggerFactory<ILogge
28
29
  };
29
30
  };
30
31
  createContextLogger(ctx: any, appLogger: ILogger): ILogger;
32
+ getClients(): Map<string, ILogger>;
33
+ getClientKeys(): string[];
31
34
  }
32
35
  //# sourceMappingURL=loggerFactory.d.ts.map
@@ -5,11 +5,15 @@ class LoggerFactory {
5
5
  }
6
6
  exports.LoggerFactory = LoggerFactory;
7
7
  class DefaultConsoleLoggerFactory {
8
+ constructor() {
9
+ this.instance = new Map();
10
+ }
8
11
  createLogger(name, options) {
12
+ this.instance.set(name, console);
9
13
  return console;
10
14
  }
11
15
  getLogger(loggerName) {
12
- return console;
16
+ return this.instance.get(loggerName);
13
17
  }
14
18
  close(loggerName) { }
15
19
  removeLogger(loggerName) { }
@@ -27,6 +31,12 @@ class DefaultConsoleLoggerFactory {
27
31
  createContextLogger(ctx, appLogger) {
28
32
  return appLogger;
29
33
  }
34
+ getClients() {
35
+ return this.instance;
36
+ }
37
+ getClientKeys() {
38
+ return Array.from(this.instance.keys());
39
+ }
30
40
  }
31
41
  exports.DefaultConsoleLoggerFactory = DefaultConsoleLoggerFactory;
32
42
  //# sourceMappingURL=loggerFactory.js.map
@@ -1,9 +1,15 @@
1
1
  import { IServiceFactory } from '../interface';
2
+ export declare const DEFAULT_PRIORITY: {
3
+ L1: string;
4
+ L2: string;
5
+ L3: string;
6
+ };
2
7
  /**
3
8
  * 多客户端工厂实现
4
9
  */
5
10
  export declare abstract class ServiceFactory<T> implements IServiceFactory<T> {
6
11
  protected clients: Map<string, T>;
12
+ protected priority: any;
7
13
  protected options: {};
8
14
  protected initClients(options?: any): Promise<void>;
9
15
  get<U = T>(id?: string): U;
@@ -14,5 +20,11 @@ export declare abstract class ServiceFactory<T> implements IServiceFactory<T> {
14
20
  protected destroyClient(client: T): Promise<void>;
15
21
  stop(): Promise<void>;
16
22
  getDefaultClientName(): string;
23
+ getClients(): Map<string, T>;
24
+ getClientKeys(): string[];
25
+ getClientPriority(clientName: string): any;
26
+ isHighPriority(clientName: string): boolean;
27
+ isMediumPriority(clientName: string): boolean;
28
+ isLowPriority(clientName: string): boolean;
17
29
  }
18
30
  //# sourceMappingURL=serviceFactory.d.ts.map
@@ -1,7 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ServiceFactory = void 0;
3
+ exports.ServiceFactory = exports.DEFAULT_PRIORITY = void 0;
4
4
  const extend_1 = require("../util/extend");
5
+ exports.DEFAULT_PRIORITY = {
6
+ L1: 'High',
7
+ L2: 'Medium',
8
+ L3: 'Low',
9
+ };
5
10
  /**
6
11
  * 多客户端工厂实现
7
12
  */
@@ -24,6 +29,12 @@ class ServiceFactory {
24
29
  await this.createInstance(options.clients[id], id);
25
30
  }
26
31
  }
32
+ // set priority
33
+ this.priority = options.priority || {
34
+ ...Array.from(this.clients.keys()).map(name => ({
35
+ [name]: exports.DEFAULT_PRIORITY.L2,
36
+ })),
37
+ };
27
38
  }
28
39
  get(id = 'default') {
29
40
  return this.clients.get(id);
@@ -51,6 +62,24 @@ class ServiceFactory {
51
62
  getDefaultClientName() {
52
63
  return this.options['defaultClientName'];
53
64
  }
65
+ getClients() {
66
+ return this.clients;
67
+ }
68
+ getClientKeys() {
69
+ return Array.from(this.clients.keys());
70
+ }
71
+ getClientPriority(clientName) {
72
+ return this.priority[clientName] || exports.DEFAULT_PRIORITY.L2;
73
+ }
74
+ isHighPriority(clientName) {
75
+ return this.getClientPriority(clientName) === exports.DEFAULT_PRIORITY.L1;
76
+ }
77
+ isMediumPriority(clientName) {
78
+ return this.getClientPriority(clientName) === exports.DEFAULT_PRIORITY.L2;
79
+ }
80
+ isLowPriority(clientName) {
81
+ return this.getClientPriority(clientName) === exports.DEFAULT_PRIORITY.L3;
82
+ }
54
83
  }
55
84
  exports.ServiceFactory = ServiceFactory;
56
85
  //# sourceMappingURL=serviceFactory.js.map
@@ -22,6 +22,7 @@ export declare const FrameworkErrorEnum: {
22
22
  readonly INVOKE_METHOD_FORBIDDEN: "MIDWAY_10018";
23
23
  readonly CODE_INVOKE_TIMEOUT: "MIDWAY_10019";
24
24
  readonly MAIN_FRAMEWORK_MISSING: "MIDWAY_10020";
25
+ readonly INVALID_CONFIG_PROPERTY: "MIDWAY_10021";
25
26
  };
26
27
  export declare class MidwayCommonError extends MidwayError {
27
28
  constructor(message: string);
@@ -86,4 +87,7 @@ export declare class MidwayCodeInvokeTimeoutError extends MidwayError {
86
87
  export declare class MidwayMainFrameworkMissingError extends MidwayError {
87
88
  constructor();
88
89
  }
90
+ export declare class MidwayInvalidConfigPropertyError extends MidwayError {
91
+ constructor(propertyName: string, allowTypes?: string[]);
92
+ }
89
93
  //# sourceMappingURL=framework.d.ts.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MidwayMainFrameworkMissingError = exports.MidwayCodeInvokeTimeoutError = exports.MidwayInvokeForbiddenError = exports.MidwayRetryExceededMaxTimesError = exports.MidwayDuplicateControllerOptionsError = exports.MidwayDuplicateClassNameError = exports.MidwayInconsistentVersionError = exports.MidwayUtilHttpClientTimeoutError = exports.MidwayMissingImportComponentError = exports.MidwaySingletonInjectRequestError = exports.MidwayUseWrongMethodError = exports.MidwayDuplicateRouteError = exports.MidwayResolverMissingError = exports.MidwayInvalidConfigError = exports.MidwayConfigMissingError = exports.MidwayFeatureNotImplementedError = exports.MidwayFeatureNoLongerSupportedError = exports.MidwayDefinitionNotFoundError = exports.MidwayParameterError = exports.MidwayCommonError = exports.FrameworkErrorEnum = void 0;
3
+ exports.MidwayInvalidConfigPropertyError = exports.MidwayMainFrameworkMissingError = exports.MidwayCodeInvokeTimeoutError = exports.MidwayInvokeForbiddenError = exports.MidwayRetryExceededMaxTimesError = exports.MidwayDuplicateControllerOptionsError = exports.MidwayDuplicateClassNameError = exports.MidwayInconsistentVersionError = exports.MidwayUtilHttpClientTimeoutError = exports.MidwayMissingImportComponentError = exports.MidwaySingletonInjectRequestError = exports.MidwayUseWrongMethodError = exports.MidwayDuplicateRouteError = exports.MidwayResolverMissingError = exports.MidwayInvalidConfigError = exports.MidwayConfigMissingError = exports.MidwayFeatureNotImplementedError = exports.MidwayFeatureNoLongerSupportedError = exports.MidwayDefinitionNotFoundError = exports.MidwayParameterError = exports.MidwayCommonError = exports.FrameworkErrorEnum = void 0;
4
4
  const base_1 = require("./base");
5
5
  exports.FrameworkErrorEnum = (0, base_1.registerErrorCode)('midway', {
6
6
  UNKNOWN: 10000,
@@ -24,6 +24,7 @@ exports.FrameworkErrorEnum = (0, base_1.registerErrorCode)('midway', {
24
24
  INVOKE_METHOD_FORBIDDEN: 10018,
25
25
  CODE_INVOKE_TIMEOUT: 10019,
26
26
  MAIN_FRAMEWORK_MISSING: 10020,
27
+ INVALID_CONFIG_PROPERTY: 10021,
27
28
  });
28
29
  class MidwayCommonError extends base_1.MidwayError {
29
30
  constructor(message) {
@@ -166,4 +167,12 @@ class MidwayMainFrameworkMissingError extends base_1.MidwayError {
166
167
  }
167
168
  }
168
169
  exports.MidwayMainFrameworkMissingError = MidwayMainFrameworkMissingError;
170
+ class MidwayInvalidConfigPropertyError extends base_1.MidwayError {
171
+ constructor(propertyName, allowTypes) {
172
+ super(`Invalid config property "${propertyName}", ${allowTypes
173
+ ? `only ${allowTypes.join(',')} can be set`
174
+ : 'please check your configuration'}.`, exports.FrameworkErrorEnum.INVALID_CONFIG_PROPERTY);
175
+ }
176
+ }
177
+ exports.MidwayInvalidConfigPropertyError = MidwayInvalidConfigPropertyError;
169
178
  //# sourceMappingURL=framework.js.map
@@ -399,6 +399,7 @@ export interface MidwayCoreDefaultConfig {
399
399
  healthCheckTimeout?: number;
400
400
  };
401
401
  }
402
+ export type ClientPriorityValue = 'High' | 'Medium' | 'Low';
402
403
  export type ServiceFactoryConfigOption<OPTIONS> = {
403
404
  default?: PowerPartial<OPTIONS>;
404
405
  client?: PowerPartial<OPTIONS>;
@@ -406,6 +407,9 @@ export type ServiceFactoryConfigOption<OPTIONS> = {
406
407
  [key: string]: PowerPartial<OPTIONS>;
407
408
  };
408
409
  defaultClientName?: string;
410
+ clientPriority?: {
411
+ [key: string]: ClientPriorityValue;
412
+ };
409
413
  };
410
414
  export type CreateDataSourceInstanceOptions = {
411
415
  /**
@@ -939,6 +943,12 @@ export interface IServiceFactory<Client> {
939
943
  getName(): string;
940
944
  stop(): Promise<void>;
941
945
  getDefaultClientName(): string;
946
+ getClients(): Map<string, Client>;
947
+ getClientKeys(): string[];
948
+ getClientPriority(clientName: string): ClientPriorityValue;
949
+ isHighPriority(clientName: string): boolean;
950
+ isMediumPriority(clientName: string): boolean;
951
+ isLowPriority(clientName: string): boolean;
942
952
  }
943
953
  export interface ISimulation {
944
954
  setup?(): Promise<void>;
@@ -17,5 +17,7 @@ export declare class MidwayLoggerService extends ServiceFactory<ILogger> {
17
17
  getLogger(name: string): any;
18
18
  getCurrentLoggerFactory(): LoggerFactory<any, any>;
19
19
  createContextLogger(ctx: IMidwayContext, appLogger: ILogger, contextOptions?: any): ILogger;
20
+ getClients(): Map<string, ILogger>;
21
+ getClientKeys(): string[];
20
22
  }
21
23
  //# sourceMappingURL=loggerService.d.ts.map
@@ -86,6 +86,12 @@ let MidwayLoggerService = class MidwayLoggerService extends serviceFactory_1.Ser
86
86
  createContextLogger(ctx, appLogger, contextOptions) {
87
87
  return this.loggerFactory.createContextLogger(ctx, appLogger, contextOptions);
88
88
  }
89
+ getClients() {
90
+ return this.clients;
91
+ }
92
+ getClientKeys() {
93
+ return Array.from(this.clients.keys());
94
+ }
89
95
  };
90
96
  __decorate([
91
97
  (0, decorator_1.Inject)(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/core",
3
- "version": "3.13.6",
3
+ "version": "3.14.0",
4
4
  "description": "midway core",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -32,7 +32,7 @@
32
32
  "@midwayjs/glob": "^1.0.2",
33
33
  "class-transformer": "0.5.1",
34
34
  "picomatch": "2.3.1",
35
- "reflect-metadata": "0.1.13"
35
+ "reflect-metadata": "0.2.1"
36
36
  },
37
37
  "author": "Harry Chen <czy88840616@gmail.com>",
38
38
  "repository": {
@@ -42,5 +42,5 @@
42
42
  "engines": {
43
43
  "node": ">=12"
44
44
  },
45
- "gitHead": "684bb9ff9e66bf0d4e2e13559fac562dd9205bc4"
45
+ "gitHead": "67e3a3596ffdb65a413064d30c68f1f7965af282"
46
46
  }