@midwayjs/core 4.0.0-alpha.1 → 4.0.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 (133) hide show
  1. package/README.md +1 -1
  2. package/dist/baseFramework.d.ts +13 -10
  3. package/dist/baseFramework.js +30 -15
  4. package/dist/common/applicationManager.js +6 -4
  5. package/dist/common/asyncContextManager.js +23 -0
  6. package/dist/common/dataListener.d.ts +5 -3
  7. package/dist/common/dataListener.js +11 -3
  8. package/dist/common/dataSourceManager.d.ts +18 -9
  9. package/dist/common/dataSourceManager.js +129 -77
  10. package/dist/common/fileDetector.js +2 -4
  11. package/dist/common/filterManager.js +6 -8
  12. package/dist/common/loggerFactory.js +1 -3
  13. package/dist/common/middlewareManager.js +2 -2
  14. package/dist/common/performanceManager.d.ts +0 -1
  15. package/dist/common/performanceManager.js +21 -20
  16. package/dist/common/priorityManager.js +2 -4
  17. package/dist/common/serviceDiscovery/healthCheck.d.ts +66 -0
  18. package/dist/common/serviceDiscovery/healthCheck.js +215 -0
  19. package/dist/common/serviceDiscovery/loadBalancer.d.ts +21 -0
  20. package/dist/common/serviceDiscovery/loadBalancer.js +49 -0
  21. package/dist/common/serviceDiscovery/serviceDiscovery.d.ts +59 -0
  22. package/dist/common/serviceDiscovery/serviceDiscovery.js +107 -0
  23. package/dist/common/serviceFactory.d.ts +5 -2
  24. package/dist/common/serviceFactory.js +47 -12
  25. package/dist/common/typedResourceManager.js +3 -2
  26. package/dist/common/webGenerator.js +2 -0
  27. package/dist/config/config.default.js +4 -1
  28. package/dist/context/componentLoader.js +3 -2
  29. package/dist/context/container.d.ts +4 -4
  30. package/dist/context/container.js +15 -10
  31. package/dist/context/definitionRegistry.d.ts +2 -0
  32. package/dist/context/definitionRegistry.js +11 -16
  33. package/dist/context/dynamicContainer.d.ts +17 -0
  34. package/dist/context/dynamicContainer.js +203 -0
  35. package/dist/context/managedResolverFactory.d.ts +1 -2
  36. package/dist/context/managedResolverFactory.js +16 -8
  37. package/dist/context/providerWrapper.js +1 -2
  38. package/dist/context/requestContainer.d.ts +1 -0
  39. package/dist/context/requestContainer.js +8 -2
  40. package/dist/decorator/common/aspect.js +1 -2
  41. package/dist/decorator/common/autoload.js +1 -2
  42. package/dist/decorator/common/configuration.js +1 -2
  43. package/dist/decorator/common/filter.js +2 -3
  44. package/dist/decorator/common/framework.js +8 -9
  45. package/dist/decorator/common/guard.js +2 -3
  46. package/dist/decorator/common/inject.js +4 -5
  47. package/dist/decorator/common/middleware.js +1 -2
  48. package/dist/decorator/common/mock.js +1 -2
  49. package/dist/decorator/common/objectDef.js +2 -3
  50. package/dist/decorator/common/pipe.js +1 -2
  51. package/dist/decorator/common/provide.js +1 -2
  52. package/dist/decorator/common/scope.js +2 -3
  53. package/dist/decorator/decoratorManager.js +4 -4
  54. package/dist/decorator/faas/serverlessTrigger.js +2 -3
  55. package/dist/decorator/metadataManager.d.ts +14 -6
  56. package/dist/decorator/metadataManager.js +49 -63
  57. package/dist/decorator/microservice/consumer.js +1 -2
  58. package/dist/decorator/microservice/kafkaListener.js +1 -2
  59. package/dist/decorator/microservice/provider.js +4 -4
  60. package/dist/decorator/microservice/rabbitmqListener.js +1 -2
  61. package/dist/decorator/task/queue.js +1 -2
  62. package/dist/decorator/task/schedule.js +1 -2
  63. package/dist/decorator/task/task.js +1 -2
  64. package/dist/decorator/task/taskLocal.js +1 -2
  65. package/dist/decorator/web/controller.d.ts +6 -0
  66. package/dist/decorator/web/controller.js +1 -2
  67. package/dist/decorator/web/response.js +5 -6
  68. package/dist/decorator/ws/webSocketController.js +1 -2
  69. package/dist/decorator/ws/webSocketEvent.js +6 -6
  70. package/dist/definitions/functionDefinition.js +21 -12
  71. package/dist/definitions/objectCreator.js +5 -2
  72. package/dist/definitions/objectDefinition.js +19 -17
  73. package/dist/error/base.js +5 -2
  74. package/dist/error/framework.d.ts +1 -1
  75. package/dist/error/framework.js +4 -2
  76. package/dist/error/http.d.ts +7 -0
  77. package/dist/error/http.js +11 -1
  78. package/dist/functional/configuration.d.ts +6 -6
  79. package/dist/functional/configuration.js +11 -10
  80. package/dist/functional/hooks.d.ts +3 -1
  81. package/dist/functional/hooks.js +18 -9
  82. package/dist/index.d.ts +5 -1
  83. package/dist/index.js +8 -2
  84. package/dist/interface.d.ts +179 -21
  85. package/dist/interface.js +15 -1
  86. package/dist/legacy/decorator.js +31 -32
  87. package/dist/response/base.d.ts +3 -5
  88. package/dist/response/base.js +22 -21
  89. package/dist/response/http.d.ts +4 -7
  90. package/dist/response/http.js +12 -12
  91. package/dist/response/sse.d.ts +0 -1
  92. package/dist/response/sse.js +4 -1
  93. package/dist/response/stream.d.ts +0 -1
  94. package/dist/response/stream.js +3 -1
  95. package/dist/service/aspectService.js +1 -0
  96. package/dist/service/configService.d.ts +1 -1
  97. package/dist/service/configService.js +16 -14
  98. package/dist/service/decoratorService.js +6 -4
  99. package/dist/service/environmentService.js +2 -3
  100. package/dist/service/frameworkService.js +9 -1
  101. package/dist/service/healthService.d.ts +2 -0
  102. package/dist/service/healthService.js +20 -8
  103. package/dist/service/informationService.d.ts +3 -0
  104. package/dist/service/informationService.js +13 -0
  105. package/dist/service/lifeCycleService.d.ts +13 -7
  106. package/dist/service/lifeCycleService.js +55 -33
  107. package/dist/service/loggerService.js +6 -2
  108. package/dist/service/middlewareService.js +1 -0
  109. package/dist/service/mockService.js +17 -15
  110. package/dist/service/slsFunctionService.js +1 -0
  111. package/dist/service/webRouterService.d.ts +25 -1
  112. package/dist/service/webRouterService.js +20 -3
  113. package/dist/setup.js +12 -6
  114. package/dist/util/camelCase.js +2 -3
  115. package/dist/util/contextUtil.d.ts +3 -3
  116. package/dist/util/extend.js +1 -2
  117. package/dist/util/flatted.js +2 -3
  118. package/dist/util/fs.js +2 -2
  119. package/dist/util/httpclient.d.ts +0 -4
  120. package/dist/util/httpclient.js +3 -2
  121. package/dist/util/index.d.ts +3 -18
  122. package/dist/util/index.js +49 -103
  123. package/dist/util/network.d.ts +10 -0
  124. package/dist/util/network.js +40 -0
  125. package/dist/util/pathFileUtil.d.ts +1 -2
  126. package/dist/util/pathFileUtil.js +7 -7
  127. package/dist/util/retry.js +2 -3
  128. package/dist/util/timeout.d.ts +56 -0
  129. package/dist/util/timeout.js +143 -0
  130. package/dist/util/types.d.ts +7 -7
  131. package/dist/util/types.js +17 -17
  132. package/dist/util/uuid.js +1 -2
  133. package/package.json +5 -5
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RabbitMQListener = void 0;
3
+ exports.RabbitMQListener = RabbitMQListener;
4
4
  const __1 = require("../");
5
5
  const legacy_1 = require("../../legacy");
6
6
  function RabbitMQListener(queueName, options = {}) {
@@ -10,5 +10,4 @@ function RabbitMQListener(queueName, options = {}) {
10
10
  (0, legacy_1.attachPropertyDataToClass)(__1.MS_CONSUMER_KEY, options, target, propertyKey);
11
11
  };
12
12
  }
13
- exports.RabbitMQListener = RabbitMQListener;
14
13
  //# sourceMappingURL=rabbitmqListener.js.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Queue = void 0;
3
+ exports.Queue = Queue;
4
4
  const __1 = require("../");
5
5
  const constant_1 = require("../constant");
6
6
  const metadataManager_1 = require("../metadataManager");
@@ -14,5 +14,4 @@ function Queue(options) {
14
14
  (0, __1.Provide)()(target);
15
15
  };
16
16
  }
17
- exports.Queue = Queue;
18
17
  //# sourceMappingURL=queue.js.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Schedule = void 0;
3
+ exports.Schedule = Schedule;
4
4
  const __1 = require("../");
5
5
  const interface_1 = require("../../interface");
6
6
  const metadataManager_1 = require("../metadataManager");
@@ -12,5 +12,4 @@ function Schedule(scheduleOpts) {
12
12
  (0, __1.Provide)()(target);
13
13
  };
14
14
  }
15
- exports.Schedule = Schedule;
16
15
  //# sourceMappingURL=schedule.js.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Task = void 0;
3
+ exports.Task = Task;
4
4
  const constant_1 = require("../constant");
5
5
  const decoratorManager_1 = require("../decoratorManager");
6
6
  const metadataManager_1 = require("../metadataManager");
@@ -15,5 +15,4 @@ function Task(options) {
15
15
  }, target);
16
16
  };
17
17
  }
18
- exports.Task = Task;
19
18
  //# sourceMappingURL=task.js.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TaskLocal = void 0;
3
+ exports.TaskLocal = TaskLocal;
4
4
  const constant_1 = require("../constant");
5
5
  const decoratorManager_1 = require("../decoratorManager");
6
6
  const metadataManager_1 = require("../metadataManager");
@@ -14,5 +14,4 @@ function TaskLocal(options) {
14
14
  }, target);
15
15
  };
16
16
  }
17
- exports.TaskLocal = TaskLocal;
18
17
  //# sourceMappingURL=taskLocal.js.map
@@ -8,6 +8,9 @@ export interface ControllerOption {
8
8
  description?: string;
9
9
  tagName?: string;
10
10
  ignoreGlobalPrefix?: boolean;
11
+ version?: string | string[];
12
+ versionType?: 'URI' | 'HEADER' | 'MEDIA_TYPE' | 'CUSTOM';
13
+ versionPrefix?: string;
11
14
  };
12
15
  }
13
16
  export declare function Controller(prefix?: string, routerOptions?: {
@@ -16,5 +19,8 @@ export declare function Controller(prefix?: string, routerOptions?: {
16
19
  description?: string;
17
20
  tagName?: string;
18
21
  ignoreGlobalPrefix?: boolean;
22
+ version?: string | string[];
23
+ versionType?: 'URI' | 'HEADER' | 'MEDIA_TYPE' | 'CUSTOM';
24
+ versionPrefix?: string;
19
25
  }): ClassDecorator;
20
26
  //# sourceMappingURL=controller.d.ts.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Controller = void 0;
3
+ exports.Controller = Controller;
4
4
  const __1 = require("../");
5
5
  const interface_1 = require("../../interface");
6
6
  const metadataManager_1 = require("../metadataManager");
@@ -16,5 +16,4 @@ function Controller(prefix = '/', routerOptions = { middleware: [], sensitive: t
16
16
  (0, __1.Provide)()(target);
17
17
  };
18
18
  }
19
- exports.Controller = Controller;
20
19
  //# sourceMappingURL=controller.js.map
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createRender = exports.ContentType = exports.SetHeader = exports.HttpCode = exports.Redirect = void 0;
3
+ exports.Redirect = Redirect;
4
+ exports.HttpCode = HttpCode;
5
+ exports.SetHeader = SetHeader;
6
+ exports.ContentType = ContentType;
7
+ exports.createRender = createRender;
4
8
  const __1 = require("../");
5
9
  const metadataManager_1 = require("../metadataManager");
6
10
  function Redirect(url, code = 302) {
@@ -13,7 +17,6 @@ function Redirect(url, code = 302) {
13
17
  return descriptor;
14
18
  };
15
19
  }
16
- exports.Redirect = Redirect;
17
20
  function HttpCode(code) {
18
21
  return (target, key, descriptor) => {
19
22
  metadataManager_1.MetadataManager.attachMetadata(__1.WEB_RESPONSE_KEY, {
@@ -23,7 +26,6 @@ function HttpCode(code) {
23
26
  return descriptor;
24
27
  };
25
28
  }
26
- exports.HttpCode = HttpCode;
27
29
  function SetHeader(headerKey, value) {
28
30
  return (target, key, descriptor) => {
29
31
  let headerObject = {};
@@ -40,7 +42,6 @@ function SetHeader(headerKey, value) {
40
42
  return descriptor;
41
43
  };
42
44
  }
43
- exports.SetHeader = SetHeader;
44
45
  function ContentType(contentType) {
45
46
  return (target, key, descriptor) => {
46
47
  metadataManager_1.MetadataManager.attachMetadata(__1.WEB_RESPONSE_KEY, {
@@ -50,7 +51,6 @@ function ContentType(contentType) {
50
51
  return descriptor;
51
52
  };
52
53
  }
53
- exports.ContentType = ContentType;
54
54
  function createRender(RenderEngine) {
55
55
  return (templateName) => {
56
56
  return (target, key, descriptor) => {
@@ -62,5 +62,4 @@ function createRender(RenderEngine) {
62
62
  };
63
63
  };
64
64
  }
65
- exports.createRender = createRender;
66
65
  //# sourceMappingURL=response.js.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WSController = void 0;
3
+ exports.WSController = WSController;
4
4
  const __1 = require("../");
5
5
  const interface_1 = require("../../interface");
6
6
  const metadataManager_1 = require("../metadataManager");
@@ -18,5 +18,4 @@ function WSController(namespace = '/', routerOptions = {
18
18
  (0, __1.Provide)()(target);
19
19
  };
20
20
  }
21
- exports.WSController = WSController;
22
21
  //# sourceMappingURL=webSocketController.js.map
@@ -1,6 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OnConnection = exports.OnDisConnection = exports.Emit = exports.OnMessage = exports.WSBroadCast = exports.WSEmit = exports.OnWSMessage = exports.OnWSDisConnection = exports.OnWSConnection = exports.WSEventTypeEnum = void 0;
3
+ exports.OnConnection = exports.OnDisConnection = exports.Emit = exports.OnMessage = exports.WSEventTypeEnum = void 0;
4
+ exports.OnWSConnection = OnWSConnection;
5
+ exports.OnWSDisConnection = OnWSDisConnection;
6
+ exports.OnWSMessage = OnWSMessage;
7
+ exports.WSEmit = WSEmit;
8
+ exports.WSBroadCast = WSBroadCast;
4
9
  const __1 = require("../");
5
10
  const metadataManager_1 = require("../metadataManager");
6
11
  var WSEventTypeEnum;
@@ -22,7 +27,6 @@ function OnWSConnection(eventOptions = {}) {
22
27
  }, target.constructor);
23
28
  };
24
29
  }
25
- exports.OnWSConnection = OnWSConnection;
26
30
  function OnWSDisConnection() {
27
31
  return (target, propertyKey, descriptor) => {
28
32
  metadataManager_1.MetadataManager.attachMetadata(__1.WS_EVENT_KEY, {
@@ -32,7 +36,6 @@ function OnWSDisConnection() {
32
36
  }, target.constructor);
33
37
  };
34
38
  }
35
- exports.OnWSDisConnection = OnWSDisConnection;
36
39
  function OnWSMessage(eventName, eventOptions = {}) {
37
40
  return (target, propertyKey, descriptor) => {
38
41
  metadataManager_1.MetadataManager.attachMetadata(__1.WS_EVENT_KEY, {
@@ -44,7 +47,6 @@ function OnWSMessage(eventName, eventOptions = {}) {
44
47
  }, target.constructor);
45
48
  };
46
49
  }
47
- exports.OnWSMessage = OnWSMessage;
48
50
  function WSEmit(messageName, roomName = []) {
49
51
  return (target, propertyKey, descriptor) => {
50
52
  metadataManager_1.MetadataManager.attachMetadata(__1.WS_EVENT_KEY, {
@@ -56,7 +58,6 @@ function WSEmit(messageName, roomName = []) {
56
58
  }, target.constructor);
57
59
  };
58
60
  }
59
- exports.WSEmit = WSEmit;
60
61
  function WSBroadCast(messageName = '', roomName = []) {
61
62
  return (target, propertyKey, descriptor) => {
62
63
  metadataManager_1.MetadataManager.attachMetadata(__1.WS_EVENT_KEY, {
@@ -68,7 +69,6 @@ function WSBroadCast(messageName = '', roomName = []) {
68
69
  }, target.constructor);
69
70
  };
70
71
  }
71
- exports.WSBroadCast = WSBroadCast;
72
72
  /**
73
73
  * @deprecated please use @OnWSMessage
74
74
  */
@@ -4,10 +4,7 @@ exports.FunctionDefinition = void 0;
4
4
  const interface_1 = require("../interface");
5
5
  const objectCreator_1 = require("./objectCreator");
6
6
  class FunctionWrapperCreator extends objectCreator_1.ObjectCreator {
7
- constructor() {
8
- super(...arguments);
9
- this.type = 'function';
10
- }
7
+ type = 'function';
11
8
  doConstruct(Clzz, args) {
12
9
  return Clzz;
13
10
  }
@@ -20,16 +17,28 @@ class FunctionWrapperCreator extends objectCreator_1.ObjectCreator {
20
17
  }
21
18
  class FunctionDefinition {
22
19
  constructor() {
23
- this.constructorArgs = [];
24
- this.namespace = '';
25
- this.asynchronous = true;
26
- this.handlerProps = [];
27
- this.allowDowngrade = false;
28
- // 函数工厂创建的对象默认不需要自动装配
29
- this.innerAutowire = false;
30
- this.innerScope = interface_1.ScopeEnum.Singleton;
31
20
  this.creator = new FunctionWrapperCreator(this);
32
21
  }
22
+ constructMethod;
23
+ constructorArgs = [];
24
+ creator;
25
+ dependsOn;
26
+ destroyMethod;
27
+ export;
28
+ id;
29
+ name;
30
+ initMethod;
31
+ srcPath;
32
+ path;
33
+ properties;
34
+ namespace = '';
35
+ asynchronous = true;
36
+ handlerProps = [];
37
+ createFrom;
38
+ allowDowngrade = false;
39
+ // 函数工厂创建的对象默认不需要自动装配
40
+ innerAutowire = false;
41
+ innerScope = interface_1.ScopeEnum.Singleton;
33
42
  getAttr(key) { }
34
43
  hasAttr(key) {
35
44
  return false;
@@ -4,8 +4,9 @@ exports.ObjectCreator = void 0;
4
4
  const error_1 = require("../error");
5
5
  const types_1 = require("../util/types");
6
6
  class ObjectCreator {
7
+ definition;
8
+ type = 'object';
7
9
  constructor(definition) {
8
- this.type = 'object';
9
10
  this.definition = definition;
10
11
  }
11
12
  /**
@@ -114,7 +115,9 @@ class ObjectCreator {
114
115
  * @returns {void}
115
116
  */
116
117
  async doDestroyAsync(obj) {
117
- if (this.definition.destroyMethod && obj[this.definition.destroyMethod]) {
118
+ if (obj &&
119
+ this.definition.destroyMethod &&
120
+ obj[this.definition.destroyMethod]) {
118
121
  const fn = obj[this.definition.destroyMethod];
119
122
  if (types_1.Types.isAsyncFunction(fn)) {
120
123
  await fn.call(obj);
@@ -4,24 +4,26 @@ exports.ObjectDefinition = void 0;
4
4
  const interface_1 = require("../interface");
5
5
  const objectCreator_1 = require("./objectCreator");
6
6
  class ObjectDefinition {
7
+ _attrs = new Map();
8
+ _asynchronous = false;
9
+ scope = interface_1.ScopeEnum.Singleton;
10
+ creator = null;
11
+ id = null;
12
+ name = null;
13
+ initMethod = null;
14
+ destroyMethod = null;
15
+ constructMethod = null;
16
+ constructorArgs = [];
17
+ srcPath;
18
+ path = null;
19
+ export = null;
20
+ dependsOn = [];
21
+ properties = new Map();
22
+ namespace = '';
23
+ handlerProps = [];
24
+ createFrom;
25
+ allowDowngrade = false;
7
26
  constructor() {
8
- this._attrs = new Map();
9
- this._asynchronous = false;
10
- this.scope = interface_1.ScopeEnum.Singleton;
11
- this.creator = null;
12
- this.id = null;
13
- this.name = null;
14
- this.initMethod = null;
15
- this.destroyMethod = null;
16
- this.constructMethod = null;
17
- this.constructorArgs = [];
18
- this.path = null;
19
- this.export = null;
20
- this.dependsOn = [];
21
- this.properties = new Map();
22
- this.namespace = '';
23
- this.handlerProps = [];
24
- this.allowDowngrade = false;
25
27
  this.creator = new objectCreator_1.ObjectCreator(this);
26
28
  }
27
29
  set asynchronous(asynchronous) {
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MidwayHttpError = exports.MidwayError = exports.registerErrorCode = void 0;
3
+ exports.MidwayHttpError = exports.MidwayError = void 0;
4
+ exports.registerErrorCode = registerErrorCode;
4
5
  const http_1 = require("http");
5
6
  const codeGroup = new Set();
6
7
  /**
@@ -25,8 +26,9 @@ function registerErrorCode(errorGroup, errorCodeMapping) {
25
26
  }
26
27
  return newCodeEnum;
27
28
  }
28
- exports.registerErrorCode = registerErrorCode;
29
29
  class MidwayError extends Error {
30
+ code;
31
+ cause;
30
32
  constructor(message, code, options) {
31
33
  super(message);
32
34
  if (!code || typeof code === 'object') {
@@ -40,6 +42,7 @@ class MidwayError extends Error {
40
42
  }
41
43
  exports.MidwayError = MidwayError;
42
44
  class MidwayHttpError extends MidwayError {
45
+ status;
43
46
  constructor(resOrMessage, status, code, options) {
44
47
  super(resOrMessage
45
48
  ? typeof resOrMessage === 'string'
@@ -76,7 +76,7 @@ export declare class MidwayInvokeForbiddenError extends MidwayError {
76
76
  constructor(methodName: string, module?: any);
77
77
  }
78
78
  export declare class MidwayCodeInvokeTimeoutError extends MidwayError {
79
- constructor(methodName: string, timeout: number);
79
+ constructor(methodName: string, timeout: number, moduleName?: string);
80
80
  }
81
81
  export declare class MidwayMainFrameworkMissingError extends MidwayError {
82
82
  constructor();
@@ -141,8 +141,10 @@ class MidwayInvokeForbiddenError extends base_1.MidwayError {
141
141
  }
142
142
  exports.MidwayInvokeForbiddenError = MidwayInvokeForbiddenError;
143
143
  class MidwayCodeInvokeTimeoutError extends base_1.MidwayError {
144
- constructor(methodName, timeout) {
145
- super(`Invoke "${methodName}" running timeout(${timeout}ms)`, exports.FrameworkErrorEnum.CODE_INVOKE_TIMEOUT);
144
+ constructor(methodName, timeout, moduleName) {
145
+ super(moduleName
146
+ ? `Function "${methodName}" of "${moduleName}" call more than ${timeout}ms`
147
+ : `Function "${methodName}" call more than ${timeout}ms`, exports.FrameworkErrorEnum.CODE_INVOKE_TIMEOUT);
146
148
  }
147
149
  }
148
150
  exports.MidwayCodeInvokeTimeoutError = MidwayCodeInvokeTimeoutError;
@@ -112,6 +112,12 @@ export declare class UnsupportedMediaTypeError extends MidwayHttpError {
112
112
  export declare class UnprocessableEntityError extends MidwayHttpError {
113
113
  constructor(resOrMessage?: ResOrMessage);
114
114
  }
115
+ /**
116
+ * 429 http error, Means that client has sent too many requests in a given amount of time and that's why the server won't accept the request.
117
+ */
118
+ export declare class TooManyRequestsError extends MidwayHttpError {
119
+ constructor(resOrMessage?: ResOrMessage);
120
+ }
115
121
  /**
116
122
  * 500 http error, Is a generic error and users receive this error message when there is no more suitable specific message.
117
123
  */
@@ -154,6 +160,7 @@ export declare const httpError: {
154
160
  PayloadTooLargeError: typeof PayloadTooLargeError;
155
161
  UnsupportedMediaTypeError: typeof UnsupportedMediaTypeError;
156
162
  UnprocessableEntityError: typeof UnprocessableEntityError;
163
+ TooManyRequestsError: typeof TooManyRequestsError;
157
164
  InternalServerErrorError: typeof InternalServerErrorError;
158
165
  NotImplementedError: typeof NotImplementedError;
159
166
  BadGatewayError: typeof BadGatewayError;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.httpError = exports.GatewayTimeoutError = exports.ServiceUnavailableError = exports.BadGatewayError = exports.NotImplementedError = exports.InternalServerErrorError = exports.UnprocessableEntityError = exports.UnsupportedMediaTypeError = exports.PayloadTooLargeError = exports.GoneError = exports.ConflictError = exports.RequestTimeoutError = exports.NotAcceptableError = exports.ForbiddenError = exports.NotFoundError = exports.UnauthorizedError = exports.BadRequestError = exports.HttpStatus = void 0;
3
+ exports.httpError = exports.GatewayTimeoutError = exports.ServiceUnavailableError = exports.BadGatewayError = exports.NotImplementedError = exports.InternalServerErrorError = exports.TooManyRequestsError = exports.UnprocessableEntityError = exports.UnsupportedMediaTypeError = exports.PayloadTooLargeError = exports.GoneError = exports.ConflictError = exports.RequestTimeoutError = exports.NotAcceptableError = exports.ForbiddenError = exports.NotFoundError = exports.UnauthorizedError = exports.BadRequestError = exports.HttpStatus = void 0;
4
4
  const base_1 = require("./base");
5
5
  var HttpStatus;
6
6
  (function (HttpStatus) {
@@ -149,6 +149,15 @@ class UnprocessableEntityError extends base_1.MidwayHttpError {
149
149
  }
150
150
  }
151
151
  exports.UnprocessableEntityError = UnprocessableEntityError;
152
+ /**
153
+ * 429 http error, Means that client has sent too many requests in a given amount of time and that's why the server won't accept the request.
154
+ */
155
+ class TooManyRequestsError extends base_1.MidwayHttpError {
156
+ constructor(resOrMessage) {
157
+ super(resOrMessage, HttpStatus.TOO_MANY_REQUESTS);
158
+ }
159
+ }
160
+ exports.TooManyRequestsError = TooManyRequestsError;
152
161
  /**
153
162
  * 500 http error, Is a generic error and users receive this error message when there is no more suitable specific message.
154
163
  */
@@ -206,6 +215,7 @@ exports.httpError = {
206
215
  PayloadTooLargeError,
207
216
  UnsupportedMediaTypeError,
208
217
  UnprocessableEntityError,
218
+ TooManyRequestsError,
209
219
  InternalServerErrorError,
210
220
  NotImplementedError,
211
221
  BadGatewayError,
@@ -1,12 +1,12 @@
1
- import { ILifeCycle, IMidwayApplication, IMidwayContainer, ObjectBeforeCreatedOptions, ObjectBeforeDestroyOptions, ObjectCreatedOptions, ObjectInitOptions, FunctionalConfigurationOptions } from '../interface';
1
+ import { ILifeCycle, IMidwayApplication, IMidwayContainer, ObjectBeforeCreatedOptions, ObjectBeforeDestroyOptions, ObjectCreatedOptions, ObjectInitOptions, FunctionalConfigurationOptions, LifeCycleInvokeOptions } from '../interface';
2
2
  export declare class FunctionalConfiguration implements ILifeCycle {
3
3
  protected options: FunctionalConfigurationOptions;
4
4
  constructor(options: FunctionalConfigurationOptions);
5
- onConfigLoad(container: IMidwayContainer, mainApp: IMidwayApplication): Promise<any>;
6
- onReady(container: IMidwayContainer, mainApp: IMidwayApplication): Promise<void>;
7
- onServerReady(container: IMidwayContainer, mainApp: IMidwayApplication): Promise<void>;
8
- onHealthCheck(container: IMidwayContainer): Promise<import("../interface").HealthResult>;
9
- onStop(container: IMidwayContainer, mainApp: IMidwayApplication): Promise<void>;
5
+ onConfigLoad(container: IMidwayContainer, mainApp: IMidwayApplication, options: LifeCycleInvokeOptions): Promise<any>;
6
+ onReady(container: IMidwayContainer, mainApp: IMidwayApplication, options: LifeCycleInvokeOptions): Promise<void>;
7
+ onServerReady(container: IMidwayContainer, mainApp: IMidwayApplication, options: LifeCycleInvokeOptions): Promise<void>;
8
+ onHealthCheck(container: IMidwayContainer, mainApp: IMidwayApplication, options: LifeCycleInvokeOptions): Promise<import("../interface").HealthResult>;
9
+ onStop(container: IMidwayContainer, mainApp: IMidwayApplication, options: LifeCycleInvokeOptions): Promise<void>;
10
10
  onBeforeObjectCreated(Clzz: any, options: ObjectBeforeCreatedOptions): void;
11
11
  onObjectCreated<T>(ins: T, options: ObjectCreatedOptions<T>): void;
12
12
  onObjectInit<T>(ins: T, options: ObjectInitOptions): void;
@@ -4,23 +4,24 @@ exports.defineConfiguration = exports.FunctionalConfiguration = void 0;
4
4
  const decorator_1 = require("../decorator");
5
5
  const metadataManager_1 = require("../decorator/metadataManager");
6
6
  class FunctionalConfiguration {
7
+ options;
7
8
  constructor(options) {
8
9
  this.options = options;
9
10
  }
10
- async onConfigLoad(container, mainApp) {
11
- return this.options?.onConfigLoad?.(container, mainApp);
11
+ async onConfigLoad(container, mainApp, options) {
12
+ return this.options?.onConfigLoad?.(container, mainApp, options);
12
13
  }
13
- async onReady(container, mainApp) {
14
- return this.options?.onReady?.(container, mainApp);
14
+ async onReady(container, mainApp, options) {
15
+ return this.options?.onReady?.(container, mainApp, options);
15
16
  }
16
- async onServerReady(container, mainApp) {
17
- return this.options?.onServerReady?.(container, mainApp);
17
+ async onServerReady(container, mainApp, options) {
18
+ return this.options?.onServerReady?.(container, mainApp, options);
18
19
  }
19
- async onHealthCheck(container) {
20
- return this.options?.onHealthCheck?.(container);
20
+ async onHealthCheck(container, mainApp, options) {
21
+ return this.options?.onHealthCheck?.(container, mainApp, options);
21
22
  }
22
- async onStop(container, mainApp) {
23
- return this.options?.onStop?.(container, mainApp);
23
+ async onStop(container, mainApp, options) {
24
+ return this.options?.onStop?.(container, mainApp, options);
24
25
  }
25
26
  // object lifecycle
26
27
  onBeforeObjectCreated(Clzz, options) {
@@ -1,4 +1,4 @@
1
- import { ClassType, ILogger, IMidwayApplication, MidwayConfig } from '../interface';
1
+ import { ClassType, ILogger, IMidwayApplication, IServiceFactory, MidwayConfig, IDataSourceManager } from '../interface';
2
2
  export declare function useContext<T = any>(): T | undefined;
3
3
  export declare function useLogger(loggerName?: string): ILogger;
4
4
  export declare function usePlugin(key: string): any;
@@ -7,4 +7,6 @@ export declare function useInjectSync<T = any>(identifier: ClassType<T> | string
7
7
  export declare function useConfig(key?: string): MidwayConfig;
8
8
  export declare function useApp(appName: string): IMidwayApplication;
9
9
  export declare function useMainApp(): IMidwayApplication;
10
+ export declare function useInjectClient<Client = any>(serviceFactoryClz: new (...args: any[]) => IServiceFactory<Client>, clientName?: string): Promise<Client>;
11
+ export declare function useInjectDataSource<DataSource = any>(dataSourceManagerClz: new (...args: any[]) => IDataSourceManager<DataSource, any>, dataSourceName: string): Promise<DataSource>;
10
12
  //# sourceMappingURL=hooks.d.ts.map
@@ -1,6 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useMainApp = exports.useApp = exports.useConfig = exports.useInjectSync = exports.useInject = exports.usePlugin = exports.useLogger = exports.useContext = void 0;
3
+ exports.useContext = useContext;
4
+ exports.useLogger = useLogger;
5
+ exports.usePlugin = usePlugin;
6
+ exports.useInject = useInject;
7
+ exports.useInjectSync = useInjectSync;
8
+ exports.useConfig = useConfig;
9
+ exports.useApp = useApp;
10
+ exports.useMainApp = useMainApp;
11
+ exports.useInjectClient = useInjectClient;
12
+ exports.useInjectDataSource = useInjectDataSource;
4
13
  const contextUtil_1 = require("../util/contextUtil");
5
14
  const constants_1 = require("../constants");
6
15
  const applicationManager_1 = require("../common/applicationManager");
@@ -11,7 +20,6 @@ function useContext() {
11
20
  .getValue(constants_1.ASYNC_CONTEXT_KEY);
12
21
  return ctx;
13
22
  }
14
- exports.useContext = useContext;
15
23
  function useLogger(loggerName) {
16
24
  const ctx = useContext();
17
25
  if (ctx) {
@@ -24,12 +32,10 @@ function useLogger(loggerName) {
24
32
  return useMainApp().getLogger(loggerName);
25
33
  }
26
34
  }
27
- exports.useLogger = useLogger;
28
35
  function usePlugin(key) {
29
36
  const ctx = useContext();
30
37
  return ctx ? ctx.app[key] || ctx[key] : useMainApp()[key];
31
38
  }
32
- exports.usePlugin = usePlugin;
33
39
  async function useInject(identifier, args) {
34
40
  const ctx = useContext();
35
41
  const requestContext = ctx
@@ -37,7 +43,6 @@ async function useInject(identifier, args) {
37
43
  : useMainApp().getApplicationContext();
38
44
  return requestContext.getAsync(identifier, args);
39
45
  }
40
- exports.useInject = useInject;
41
46
  function useInjectSync(identifier, args) {
42
47
  ``;
43
48
  const ctx = useContext();
@@ -46,23 +51,27 @@ function useInjectSync(identifier, args) {
46
51
  : useMainApp().getApplicationContext();
47
52
  return requestContext.get(identifier, args);
48
53
  }
49
- exports.useInjectSync = useInjectSync;
50
54
  function useConfig(key) {
51
55
  return useMainApp()
52
56
  .getApplicationContext()
53
57
  .get(configService_1.MidwayConfigService)
54
58
  .getConfiguration(key);
55
59
  }
56
- exports.useConfig = useConfig;
57
60
  function useApp(appName) {
58
61
  const applicationManager = useMainApp()
59
62
  .getApplicationContext()
60
63
  .get(applicationManager_1.MidwayApplicationManager);
61
64
  return applicationManager.getApplication(appName);
62
65
  }
63
- exports.useApp = useApp;
64
66
  function useMainApp() {
65
67
  return (0, contextUtil_1.getCurrentMainApp)();
66
68
  }
67
- exports.useMainApp = useMainApp;
69
+ async function useInjectClient(serviceFactoryClz, clientName) {
70
+ const factoryService = await useInject(serviceFactoryClz);
71
+ return factoryService.get(clientName);
72
+ }
73
+ async function useInjectDataSource(dataSourceManagerClz, dataSourceName) {
74
+ const dataSourceManager = await useInject(dataSourceManagerClz);
75
+ return dataSourceManager.getDataSource(dataSourceName);
76
+ }
68
77
  //# sourceMappingURL=hooks.js.map
package/dist/index.d.ts CHANGED
@@ -41,12 +41,16 @@ export * from './util/pathToRegexp';
41
41
  export * from './util/httpclient';
42
42
  export { retryWithAsync, retryWith } from './util/retry';
43
43
  export { Types } from './util/types';
44
- export { PathFileUtil } from './util/pathFileUtil';
44
+ export { PathFileUtils } from './util/pathFileUtil';
45
45
  export { FileUtils } from './util/fs';
46
46
  export { FORMAT } from './util/format';
47
+ export { NetworkUtils } from './util/network';
47
48
  export { ServerResponse, HttpServerResponse } from './response/index';
48
49
  export { TypedResourceManager } from './common/typedResourceManager';
49
50
  export { MidwayPerformanceManager } from './common/performanceManager';
51
+ export { DynamicMidwayContainer } from './context/dynamicContainer';
52
+ export * from './common/serviceDiscovery/serviceDiscovery';
53
+ export * from './common/serviceDiscovery/loadBalancer';
50
54
  export * from './decorator/metadataManager';
51
55
  export * from './legacy';
52
56
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.MidwayPerformanceManager = exports.TypedResourceManager = exports.HttpServerResponse = exports.ServerResponse = exports.FORMAT = exports.FileUtils = exports.PathFileUtil = exports.Types = exports.retryWith = exports.retryWithAsync = exports.extend = exports.Utils = exports.sleep = exports.isTypeScriptEnvironment = exports.wrapAsync = exports.wrapMiddleware = exports.pathMatching = exports.transformRequestObjectByType = exports.deprecatedOutput = exports.delegateTargetAllPrototypeMethod = exports.delegateTargetProperties = exports.delegateTargetMethod = exports.delegateTargetPrototypeMethod = exports.loadModule = exports.safeRequire = exports.safelyGet = exports.ASYNC_ROOT_CONTEXT = exports.MidwayPriorityManager = exports.DEFAULT_PRIORITY = exports.DataSourceManager = exports.MidwayServerlessFunctionService = exports.MidwayWebRouterService = exports.MidwayHealthService = exports.MidwayMockService = exports.MidwayDecoratorService = exports.MidwayMiddlewareService = exports.MidwayLifeCycleService = exports.MidwayAspectService = exports.MidwayFrameworkService = exports.MidwayLoggerService = exports.MidwayInformationService = exports.MidwayEnvironmentService = exports.MidwayConfigService = exports.BaseFramework = exports.MidwayRequestContainer = void 0;
17
+ exports.DynamicMidwayContainer = exports.MidwayPerformanceManager = exports.TypedResourceManager = exports.HttpServerResponse = exports.ServerResponse = exports.NetworkUtils = exports.FORMAT = exports.FileUtils = exports.PathFileUtils = exports.Types = exports.retryWith = exports.retryWithAsync = exports.extend = exports.Utils = exports.sleep = exports.isTypeScriptEnvironment = exports.wrapAsync = exports.wrapMiddleware = exports.pathMatching = exports.transformRequestObjectByType = exports.deprecatedOutput = exports.delegateTargetAllPrototypeMethod = exports.delegateTargetProperties = exports.delegateTargetMethod = exports.delegateTargetPrototypeMethod = exports.loadModule = exports.safeRequire = exports.safelyGet = exports.ASYNC_ROOT_CONTEXT = exports.MidwayPriorityManager = exports.DEFAULT_PRIORITY = exports.DataSourceManager = exports.MidwayServerlessFunctionService = exports.MidwayWebRouterService = exports.MidwayHealthService = exports.MidwayMockService = exports.MidwayDecoratorService = exports.MidwayMiddlewareService = exports.MidwayLifeCycleService = exports.MidwayAspectService = exports.MidwayFrameworkService = exports.MidwayLoggerService = exports.MidwayInformationService = exports.MidwayEnvironmentService = exports.MidwayConfigService = exports.BaseFramework = exports.MidwayRequestContainer = void 0;
18
18
  __exportStar(require("./interface"), exports);
19
19
  __exportStar(require("./context/container"), exports);
20
20
  var requestContainer_1 = require("./context/requestContainer");
@@ -99,11 +99,13 @@ Object.defineProperty(exports, "retryWith", { enumerable: true, get: function ()
99
99
  var types_1 = require("./util/types");
100
100
  Object.defineProperty(exports, "Types", { enumerable: true, get: function () { return types_1.Types; } });
101
101
  var pathFileUtil_1 = require("./util/pathFileUtil");
102
- Object.defineProperty(exports, "PathFileUtil", { enumerable: true, get: function () { return pathFileUtil_1.PathFileUtil; } });
102
+ Object.defineProperty(exports, "PathFileUtils", { enumerable: true, get: function () { return pathFileUtil_1.PathFileUtils; } });
103
103
  var fs_1 = require("./util/fs");
104
104
  Object.defineProperty(exports, "FileUtils", { enumerable: true, get: function () { return fs_1.FileUtils; } });
105
105
  var format_1 = require("./util/format");
106
106
  Object.defineProperty(exports, "FORMAT", { enumerable: true, get: function () { return format_1.FORMAT; } });
107
+ var network_1 = require("./util/network");
108
+ Object.defineProperty(exports, "NetworkUtils", { enumerable: true, get: function () { return network_1.NetworkUtils; } });
107
109
  var index_1 = require("./response/index");
108
110
  Object.defineProperty(exports, "ServerResponse", { enumerable: true, get: function () { return index_1.ServerResponse; } });
109
111
  Object.defineProperty(exports, "HttpServerResponse", { enumerable: true, get: function () { return index_1.HttpServerResponse; } });
@@ -111,6 +113,10 @@ var typedResourceManager_1 = require("./common/typedResourceManager");
111
113
  Object.defineProperty(exports, "TypedResourceManager", { enumerable: true, get: function () { return typedResourceManager_1.TypedResourceManager; } });
112
114
  var performanceManager_1 = require("./common/performanceManager");
113
115
  Object.defineProperty(exports, "MidwayPerformanceManager", { enumerable: true, get: function () { return performanceManager_1.MidwayPerformanceManager; } });
116
+ var dynamicContainer_1 = require("./context/dynamicContainer");
117
+ Object.defineProperty(exports, "DynamicMidwayContainer", { enumerable: true, get: function () { return dynamicContainer_1.DynamicMidwayContainer; } });
118
+ __exportStar(require("./common/serviceDiscovery/serviceDiscovery"), exports);
119
+ __exportStar(require("./common/serviceDiscovery/loadBalancer"), exports);
114
120
  __exportStar(require("./decorator/metadataManager"), exports);
115
121
  __exportStar(require("./legacy"), exports);
116
122
  //# sourceMappingURL=index.js.map