@midwayjs/core 3.20.4 → 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 (151) hide show
  1. package/dist/baseFramework.d.ts +14 -39
  2. package/dist/baseFramework.js +19 -59
  3. package/dist/common/applicationManager.d.ts +6 -6
  4. package/dist/common/applicationManager.js +18 -35
  5. package/dist/common/asyncContextManager.d.ts +15 -0
  6. package/dist/common/asyncContextManager.js +51 -2
  7. package/dist/common/dataListener.d.ts +5 -3
  8. package/dist/common/dataListener.js +13 -4
  9. package/dist/common/dataSourceManager.d.ts +18 -9
  10. package/dist/common/dataSourceManager.js +121 -72
  11. package/dist/common/fileDetector.d.ts +9 -9
  12. package/dist/common/fileDetector.js +30 -28
  13. package/dist/common/filterManager.js +5 -4
  14. package/dist/common/guardManager.js +3 -2
  15. package/dist/common/middlewareManager.js +4 -3
  16. package/dist/common/performanceManager.js +1 -1
  17. package/dist/common/priorityManager.js +2 -2
  18. package/dist/common/serviceDiscovery/healthCheck.d.ts +66 -0
  19. package/dist/common/serviceDiscovery/healthCheck.js +207 -0
  20. package/dist/common/serviceDiscovery/loadBalancer.d.ts +21 -0
  21. package/dist/common/serviceDiscovery/loadBalancer.js +51 -0
  22. package/dist/common/serviceDiscovery/serviceDiscovery.d.ts +59 -0
  23. package/dist/common/serviceDiscovery/serviceDiscovery.js +104 -0
  24. package/dist/common/serviceFactory.d.ts +5 -2
  25. package/dist/common/serviceFactory.js +44 -9
  26. package/dist/common/webGenerator.js +4 -6
  27. package/dist/config/config.default.js +4 -1
  28. package/dist/constants.d.ts +2 -32
  29. package/dist/constants.js +3 -33
  30. package/dist/context/componentLoader.d.ts +20 -0
  31. package/dist/context/componentLoader.js +193 -0
  32. package/dist/context/container.d.ts +18 -32
  33. package/dist/context/container.js +74 -308
  34. package/dist/context/definitionRegistry.d.ts +5 -0
  35. package/dist/context/definitionRegistry.js +17 -26
  36. package/dist/context/dynamicContainer.d.ts +17 -0
  37. package/dist/context/dynamicContainer.js +202 -0
  38. package/dist/context/managedResolverFactory.d.ts +15 -41
  39. package/dist/context/managedResolverFactory.js +271 -349
  40. package/dist/context/requestContainer.d.ts +23 -12
  41. package/dist/context/requestContainer.js +46 -51
  42. package/dist/decorator/common/aspect.js +4 -4
  43. package/dist/decorator/common/autoload.js +1 -1
  44. package/dist/decorator/common/configuration.d.ts +1 -24
  45. package/dist/decorator/common/configuration.js +6 -1
  46. package/dist/decorator/common/filter.js +6 -6
  47. package/dist/decorator/common/framework.d.ts +46 -3
  48. package/dist/decorator/common/framework.js +43 -9
  49. package/dist/decorator/common/guard.js +4 -9
  50. package/dist/decorator/common/inject.d.ts +4 -2
  51. package/dist/decorator/common/inject.js +87 -4
  52. package/dist/decorator/common/mock.js +1 -1
  53. package/dist/decorator/common/objectDef.d.ts +0 -5
  54. package/dist/decorator/common/objectDef.js +8 -20
  55. package/dist/decorator/common/provide.d.ts +1 -1
  56. package/dist/decorator/common/provide.js +1 -1
  57. package/dist/decorator/common/scope.d.ts +6 -0
  58. package/dist/decorator/common/scope.js +21 -0
  59. package/dist/decorator/constant.d.ts +14 -17
  60. package/dist/decorator/constant.js +23 -35
  61. package/dist/decorator/decoratorManager.d.ts +21 -294
  62. package/dist/decorator/decoratorManager.js +127 -694
  63. package/dist/decorator/faas/serverlessTrigger.js +5 -5
  64. package/dist/decorator/index.d.ts +2 -3
  65. package/dist/decorator/index.js +6 -4
  66. package/dist/decorator/metadataManager.d.ts +131 -0
  67. package/dist/decorator/metadataManager.js +465 -0
  68. package/dist/decorator/microservice/consumer.js +3 -2
  69. package/dist/decorator/microservice/kafkaListener.js +2 -1
  70. package/dist/decorator/microservice/provider.js +6 -5
  71. package/dist/decorator/microservice/rabbitmqListener.js +2 -1
  72. package/dist/decorator/task/queue.js +3 -2
  73. package/dist/decorator/task/schedule.js +3 -2
  74. package/dist/decorator/task/task.js +4 -3
  75. package/dist/decorator/task/taskLocal.js +4 -3
  76. package/dist/decorator/web/controller.js +3 -2
  77. package/dist/decorator/web/paramMapping.js +2 -2
  78. package/dist/decorator/web/requestMapping.js +5 -5
  79. package/dist/decorator/web/response.js +6 -5
  80. package/dist/decorator/ws/webSocketController.js +3 -2
  81. package/dist/decorator/ws/webSocketEvent.js +7 -6
  82. package/dist/definitions/functionDefinition.d.ts +3 -3
  83. package/dist/definitions/functionDefinition.js +12 -11
  84. package/dist/definitions/objectCreator.d.ts +5 -11
  85. package/dist/definitions/objectCreator.js +6 -28
  86. package/dist/definitions/objectDefinition.d.ts +2 -3
  87. package/dist/definitions/objectDefinition.js +1 -3
  88. package/dist/error/base.js +2 -2
  89. package/dist/error/framework.d.ts +2 -9
  90. package/dist/error/framework.js +13 -27
  91. package/dist/error/http.js +1 -1
  92. package/dist/functional/configuration.d.ts +14 -15
  93. package/dist/functional/configuration.js +37 -47
  94. package/dist/functional/hooks.d.ts +12 -0
  95. package/dist/functional/hooks.js +78 -0
  96. package/dist/functional/index.d.ts +3 -0
  97. package/dist/functional/index.js +22 -0
  98. package/dist/index.d.ts +8 -4
  99. package/dist/index.js +10 -7
  100. package/dist/interface.d.ts +261 -137
  101. package/dist/interface.js +23 -33
  102. package/dist/legacy/constants.d.ts +29 -0
  103. package/dist/legacy/constants.js +33 -0
  104. package/dist/legacy/decorator.d.ts +255 -0
  105. package/dist/legacy/decorator.js +468 -0
  106. package/dist/legacy/index.d.ts +3 -0
  107. package/dist/legacy/index.js +19 -0
  108. package/dist/legacy/types.d.ts +2 -0
  109. package/dist/legacy/types.js +3 -0
  110. package/dist/service/aspectService.js +11 -12
  111. package/dist/service/configService.d.ts +1 -1
  112. package/dist/service/configService.js +5 -4
  113. package/dist/service/decoratorService.d.ts +3 -3
  114. package/dist/service/decoratorService.js +14 -10
  115. package/dist/service/environmentService.js +2 -2
  116. package/dist/service/frameworkService.d.ts +5 -4
  117. package/dist/service/frameworkService.js +30 -28
  118. package/dist/service/healthService.d.ts +2 -0
  119. package/dist/service/healthService.js +19 -8
  120. package/dist/service/informationService.d.ts +3 -0
  121. package/dist/service/informationService.js +13 -4
  122. package/dist/service/lifeCycleService.d.ts +13 -7
  123. package/dist/service/lifeCycleService.js +54 -48
  124. package/dist/service/loggerService.js +3 -4
  125. package/dist/service/middlewareService.js +7 -8
  126. package/dist/service/mockService.js +9 -15
  127. package/dist/service/slsFunctionService.d.ts +1 -14
  128. package/dist/service/slsFunctionService.js +33 -81
  129. package/dist/service/webRouterService.js +11 -11
  130. package/dist/setup.d.ts +5 -5
  131. package/dist/setup.js +83 -94
  132. package/dist/util/contextUtil.d.ts +2 -2
  133. package/dist/util/httpclient.d.ts +2 -2
  134. package/dist/util/index.d.ts +16 -17
  135. package/dist/util/index.js +153 -78
  136. package/dist/util/network.d.ts +10 -0
  137. package/dist/util/network.js +40 -0
  138. package/dist/util/pathFileUtil.d.ts +15 -2
  139. package/dist/util/pathFileUtil.js +27 -6
  140. package/dist/util/timeout.d.ts +57 -0
  141. package/dist/util/timeout.js +144 -0
  142. package/dist/util/webRouterParam.js +2 -2
  143. package/package.json +24 -6
  144. package/dist/decorator/common/pipeline.d.ts +0 -3
  145. package/dist/decorator/common/pipeline.js +0 -12
  146. package/dist/decorator/rpc/hsf.d.ts +0 -13
  147. package/dist/decorator/rpc/hsf.js +0 -20
  148. package/dist/definitions/properties.d.ts +0 -7
  149. package/dist/definitions/properties.js +0 -19
  150. package/dist/service/pipelineService.d.ts +0 -168
  151. package/dist/service/pipelineService.js +0 -254
@@ -1,14 +1,25 @@
1
- import { MidwayContainer } from './container';
2
- import { IMidwayContainer } from '../interface';
3
- export declare class MidwayRequestContainer extends MidwayContainer {
4
- private readonly applicationContext;
5
- constructor(ctx: any, applicationContext: IMidwayContainer);
6
- init(): void;
7
- get<T = any>(identifier: any, args?: any): T;
8
- getAsync<T = any>(identifier: any, args?: any): Promise<T>;
9
- ready(): Promise<void>;
10
- getContext(): {
11
- _MAIN_CTX_: boolean;
12
- };
1
+ import { ClassType, IMidwayGlobalContainer, IMidwayRequestContainer, ObjectIdentifier, ScopeEnum } from '../interface';
2
+ import { ObjectDefinitionRegistry } from './definitionRegistry';
3
+ export declare class MidwayRequestContainer implements IMidwayRequestContainer {
4
+ protected readonly ctx: any;
5
+ protected readonly applicationContext: IMidwayGlobalContainer;
6
+ parent: IMidwayGlobalContainer;
7
+ registry: ObjectDefinitionRegistry;
8
+ private attrMap;
9
+ constructor(ctx: any, applicationContext: IMidwayGlobalContainer);
10
+ get<T = any>(identifier: ClassType<T> | string, args?: any): T;
11
+ getAsync<T = any>(identifier: ClassType<T> | string, args?: any): Promise<T>;
12
+ getContext(): any;
13
+ hasDefinition(identifier: ObjectIdentifier): boolean;
14
+ getDefinition(identifier: ObjectIdentifier): import("../interface").IObjectDefinition;
15
+ registerObject(identifier: string, obj: any): void;
16
+ removeObject(identifier: ObjectIdentifier): void;
17
+ hasObject(identifier: ObjectIdentifier): boolean;
18
+ getObject<T>(identifier: ObjectIdentifier): T;
19
+ setAttr(key: string, value: any): void;
20
+ getAttr<T>(key: string): T;
21
+ getIdentifier(identifier: ClassType | string): string;
22
+ getInstanceScope(instance: any): ScopeEnum | undefined;
23
+ hasNamespace(namespace: string): boolean;
13
24
  }
14
25
  //# sourceMappingURL=requestContainer.d.ts.map
@@ -1,16 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MidwayRequestContainer = void 0;
4
- const container_1 = require("./container");
5
- const decorator_1 = require("../decorator");
6
4
  const constants_1 = require("../constants");
7
- class MidwayRequestContainer extends container_1.MidwayContainer {
5
+ const definitionRegistry_1 = require("./definitionRegistry");
6
+ class MidwayRequestContainer {
8
7
  constructor(ctx, applicationContext) {
9
- super(applicationContext);
8
+ this.ctx = ctx;
10
9
  this.applicationContext = applicationContext;
10
+ this.registry = new definitionRegistry_1.ObjectDefinitionRegistry();
11
+ this.attrMap = new Map();
12
+ this.parent = applicationContext;
11
13
  // update legacy relationship
12
14
  this.registry.setIdentifierRelation(this.applicationContext.registry.getIdentifierRelation());
13
- this.ctx = ctx;
14
15
  // register ctx
15
16
  this.registerObject(constants_1.REQUEST_CTX_KEY, ctx);
16
17
  // register res
@@ -19,60 +20,54 @@ class MidwayRequestContainer extends container_1.MidwayContainer {
19
20
  // register contextLogger
20
21
  this.registerObject('logger', ctx.logger);
21
22
  }
22
- }
23
- init() {
24
- // do nothing
23
+ ctx[constants_1.REQUEST_CTX_UNIQUE_KEY] = this;
25
24
  }
26
25
  get(identifier, args) {
27
- if (typeof identifier !== 'string') {
28
- identifier = this.getIdentifier(identifier);
29
- }
30
- if (this.registry.hasObject(identifier)) {
31
- return this.registry.getObject(identifier);
32
- }
33
- const definition = this.applicationContext.registry.getDefinition(identifier);
34
- if (definition) {
35
- if (definition.isRequestScope() ||
36
- definition.id === decorator_1.PIPELINE_IDENTIFIER) {
37
- // create object from applicationContext definition for requestScope
38
- return this.getManagedResolverFactory().create({
39
- definition,
40
- args,
41
- });
42
- }
43
- }
44
- if (this.parent) {
45
- return this.parent.get(identifier, args);
46
- }
26
+ return this.parent
27
+ .getManagedResolverFactory()
28
+ .create(identifier, args, this);
47
29
  }
48
30
  async getAsync(identifier, args) {
49
- if (typeof identifier !== 'string') {
50
- identifier = this.getIdentifier(identifier);
51
- }
52
- if (this.registry.hasObject(identifier)) {
53
- return this.registry.getObject(identifier);
54
- }
55
- const definition = this.applicationContext.registry.getDefinition(identifier);
56
- if (definition) {
57
- if (definition.isRequestScope() ||
58
- definition.id === decorator_1.PIPELINE_IDENTIFIER) {
59
- // create object from applicationContext definition for requestScope
60
- return this.getManagedResolverFactory().createAsync({
61
- definition,
62
- args,
63
- });
64
- }
65
- }
66
- if (this.parent) {
67
- return this.parent.getAsync(identifier, args);
68
- }
69
- }
70
- async ready() {
71
- // ignore other things
31
+ return this.parent
32
+ .getManagedResolverFactory()
33
+ .createAsync(identifier, args, this);
72
34
  }
73
35
  getContext() {
74
36
  return this.ctx;
75
37
  }
38
+ hasDefinition(identifier) {
39
+ return this.parent.hasDefinition(identifier);
40
+ }
41
+ getDefinition(identifier) {
42
+ return this.parent.getDefinition(identifier);
43
+ }
44
+ registerObject(identifier, obj) {
45
+ this.registry.registerObject(identifier, obj);
46
+ }
47
+ removeObject(identifier) {
48
+ this.registry.removeObject(identifier);
49
+ }
50
+ hasObject(identifier) {
51
+ return this.registry.hasObject(identifier);
52
+ }
53
+ getObject(identifier) {
54
+ return this.registry.getObject(identifier);
55
+ }
56
+ setAttr(key, value) {
57
+ this.attrMap.set(key, value);
58
+ }
59
+ getAttr(key) {
60
+ return this.attrMap.get(key);
61
+ }
62
+ getIdentifier(identifier) {
63
+ return this.parent.getIdentifier(identifier);
64
+ }
65
+ getInstanceScope(instance) {
66
+ return this.parent.getInstanceScope(instance);
67
+ }
68
+ hasNamespace(namespace) {
69
+ return this.parent.hasNamespace(namespace);
70
+ }
76
71
  }
77
72
  exports.MidwayRequestContainer = MidwayRequestContainer;
78
73
  //# sourceMappingURL=requestContainer.js.map
@@ -2,20 +2,20 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Aspect = void 0;
4
4
  const __1 = require("../");
5
- const objectDef_1 = require("./objectDef");
6
5
  const interface_1 = require("../../interface");
6
+ const metadataManager_1 = require("../metadataManager");
7
7
  function Aspect(aspectTarget, match, priority) {
8
8
  return function (target) {
9
- (0, __1.saveModule)(__1.ASPECT_KEY, target);
9
+ __1.DecoratorManager.saveModule(__1.ASPECT_KEY, target);
10
10
  const aspectTargets = [].concat(aspectTarget);
11
11
  for (const aspectTarget of aspectTargets) {
12
- (0, __1.attachClassMetadata)(__1.ASPECT_KEY, {
12
+ metadataManager_1.MetadataManager.attachMetadata(__1.ASPECT_KEY, {
13
13
  aspectTarget,
14
14
  match,
15
15
  priority,
16
16
  }, target);
17
17
  }
18
- (0, objectDef_1.Scope)(interface_1.ScopeEnum.Singleton)(target);
18
+ (0, __1.Scope)(interface_1.ScopeEnum.Singleton)(target);
19
19
  (0, __1.Provide)()(target);
20
20
  };
21
21
  }
@@ -5,7 +5,7 @@ const decoratorManager_1 = require("../decoratorManager");
5
5
  const provide_1 = require("./provide");
6
6
  function Autoload() {
7
7
  return function (target) {
8
- (0, decoratorManager_1.savePreloadModule)(target);
8
+ decoratorManager_1.DecoratorManager.savePreStartModule(target);
9
9
  (0, provide_1.Provide)()(target);
10
10
  };
11
11
  }
@@ -1,26 +1,3 @@
1
- import { IFileDetector } from '../../interface';
2
- export interface IComponentInfo {
3
- component: any;
4
- enabledEnvironment?: string[];
5
- }
6
- export interface ResolveFilter {
7
- pattern: string | RegExp;
8
- filter: (module: any, filter: any, bindModule: any) => any;
9
- ignoreRequire?: boolean;
10
- }
11
- export interface InjectionConfigurationOptions {
12
- imports?: Array<string | IComponentInfo | {
13
- Configuration: any;
14
- }>;
15
- importObjects?: Record<string, unknown>;
16
- importConfigs?: Array<{
17
- [environmentName: string]: Record<string, any>;
18
- }> | Record<string, any>;
19
- importConfigFilter?: (config: Record<string, any>) => Record<string, any>;
20
- namespace?: string;
21
- detector?: IFileDetector | false;
22
- detectorOptions?: Record<string, any>;
23
- conflictCheck?: boolean;
24
- }
1
+ import { InjectionConfigurationOptions } from '../../interface';
25
2
  export declare function Configuration(options?: InjectionConfigurationOptions): ClassDecorator;
26
3
  //# sourceMappingURL=configuration.d.ts.map
@@ -2,9 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Configuration = void 0;
4
4
  const __1 = require("../");
5
+ const metadataManager_1 = require("../metadataManager");
6
+ const interface_1 = require("../../interface");
5
7
  function Configuration(options = {}) {
6
8
  return (target) => {
7
- (0, __1.saveClassMetadata)(__1.CONFIGURATION_KEY, options, target);
9
+ options.namespace = options.namespace ?? __1.MAIN_MODULE_KEY;
10
+ metadataManager_1.MetadataManager.defineMetadata(__1.CONFIGURATION_KEY, options, target);
11
+ (0, __1.Scope)(interface_1.ScopeEnum.Singleton)(target);
12
+ (0, __1.Provide)()(target);
8
13
  };
9
14
  }
10
15
  exports.Configuration = Configuration;
@@ -1,29 +1,29 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Match = exports.Catch = void 0;
4
- const decoratorManager_1 = require("../decoratorManager");
5
4
  const constant_1 = require("../constant");
6
- const objectDef_1 = require("./objectDef");
7
5
  const provide_1 = require("./provide");
8
6
  const interface_1 = require("../../interface");
7
+ const metadataManager_1 = require("../metadataManager");
8
+ const scope_1 = require("./scope");
9
9
  function Catch(catchTarget, options = {}) {
10
10
  return function (target) {
11
11
  const catchTargets = catchTarget ? [].concat(catchTarget) : undefined;
12
- (0, decoratorManager_1.saveClassMetadata)(constant_1.CATCH_KEY, {
12
+ metadataManager_1.MetadataManager.defineMetadata(constant_1.CATCH_KEY, {
13
13
  catchTargets,
14
14
  catchOptions: options,
15
15
  }, target);
16
- (0, objectDef_1.Scope)(interface_1.ScopeEnum.Singleton)(target);
16
+ (0, scope_1.Scope)(interface_1.ScopeEnum.Singleton)(target);
17
17
  (0, provide_1.Provide)()(target);
18
18
  };
19
19
  }
20
20
  exports.Catch = Catch;
21
21
  function Match(matchPattern = true) {
22
22
  return function (target) {
23
- (0, decoratorManager_1.saveClassMetadata)(constant_1.MATCH_KEY, {
23
+ metadataManager_1.MetadataManager.defineMetadata(constant_1.MATCH_KEY, {
24
24
  matchPattern,
25
25
  }, target);
26
- (0, objectDef_1.Scope)(interface_1.ScopeEnum.Singleton)(target);
26
+ (0, scope_1.Scope)(interface_1.ScopeEnum.Singleton)(target);
27
27
  (0, provide_1.Provide)()(target);
28
28
  };
29
29
  }
@@ -1,8 +1,51 @@
1
- import { FrameworkType } from '../../interface';
1
+ /**
2
+ * Framework decorator, use to define the framework module
3
+ * @since 2.0.0
4
+ */
2
5
  export declare function Framework(): ClassDecorator;
6
+ /**
7
+ * Plugin decorator, use to get egg plugin instance
8
+ * @since 2.0.0
9
+ */
3
10
  export declare function Plugin(identifier?: string): PropertyDecorator;
4
- export declare function Config(identifier?: string): PropertyDecorator;
5
- export declare function App(typeOrNamespace?: FrameworkType | string): PropertyDecorator;
11
+ /**
12
+ * @deprecated Use @AllConfig() instead
13
+ * @since 2.0.0
14
+ */
15
+ export declare function Config(): PropertyDecorator;
16
+ /**
17
+ * Config decorator, use to get config
18
+ * @since 2.0.0
19
+ */
20
+ export declare function Config(identifier: string): PropertyDecorator;
21
+ /**
22
+ * Config decorator, use to get all config
23
+ * @since 4.0.0
24
+ */
25
+ export declare function AllConfig(): PropertyDecorator;
26
+ /**
27
+ * @deprecated Use @MainApp() instead
28
+ */
29
+ export declare function App(): PropertyDecorator;
30
+ /**
31
+ * App decorator, use to get application instance, default is main application
32
+ * If you want to get the application instance of other framework, you can use the namespace parameter to specify
33
+ * @since 2.0.0
34
+ */
35
+ export declare function App(namespace: string): PropertyDecorator;
36
+ /**
37
+ * Get the main application instance
38
+ * @since 4.0.0
39
+ */
40
+ export declare function MainApp(): PropertyDecorator;
41
+ /**
42
+ * Logger decorator, use to get logger instance
43
+ * @since 2.0.0
44
+ */
6
45
  export declare function Logger(identifier?: string): PropertyDecorator;
46
+ /**
47
+ * ApplicationContext decorator, use to get global IoC container instance
48
+ * @since 3.0.0
49
+ */
7
50
  export declare function ApplicationContext(): PropertyDecorator;
8
51
  //# sourceMappingURL=framework.d.ts.map
@@ -1,42 +1,76 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApplicationContext = exports.Logger = exports.App = exports.Config = exports.Plugin = exports.Framework = void 0;
3
+ exports.ApplicationContext = exports.Logger = exports.MainApp = exports.App = exports.AllConfig = exports.Config = exports.Plugin = exports.Framework = void 0;
4
4
  const __1 = require("../");
5
5
  const interface_1 = require("../../interface");
6
+ /**
7
+ * Framework decorator, use to define the framework module
8
+ * @since 2.0.0
9
+ */
6
10
  function Framework() {
7
11
  return (target) => {
8
- (0, __1.saveModule)(__1.FRAMEWORK_KEY, target);
12
+ __1.DecoratorManager.saveModule(__1.FRAMEWORK_KEY, target);
9
13
  (0, __1.Scope)(interface_1.ScopeEnum.Singleton)(target);
10
14
  (0, __1.Provide)()(target);
11
15
  };
12
16
  }
13
17
  exports.Framework = Framework;
18
+ /**
19
+ * Plugin decorator, use to get egg plugin instance
20
+ * @since 2.0.0
21
+ */
14
22
  function Plugin(identifier) {
15
- return (0, __1.createCustomPropertyDecorator)(__1.PLUGIN_KEY, {
23
+ return __1.DecoratorManager.createCustomPropertyDecorator(__1.PLUGIN_KEY, {
16
24
  identifier,
17
25
  });
18
26
  }
19
27
  exports.Plugin = Plugin;
20
28
  function Config(identifier) {
21
- return (0, __1.createCustomPropertyDecorator)(__1.CONFIG_KEY, {
29
+ return __1.DecoratorManager.createCustomPropertyDecorator(__1.CONFIG_KEY, {
22
30
  identifier,
23
31
  });
24
32
  }
25
33
  exports.Config = Config;
26
- function App(typeOrNamespace) {
27
- return (0, __1.createCustomPropertyDecorator)(__1.APPLICATION_KEY, {
28
- type: typeOrNamespace,
34
+ /**
35
+ * Config decorator, use to get all config
36
+ * @since 4.0.0
37
+ */
38
+ function AllConfig() {
39
+ return __1.DecoratorManager.createCustomPropertyDecorator(__1.CONFIG_KEY, {
40
+ identifier: __1.ALL_VALUE_KEY,
41
+ });
42
+ }
43
+ exports.AllConfig = AllConfig;
44
+ function App(namespace) {
45
+ return __1.DecoratorManager.createCustomPropertyDecorator(__1.APPLICATION_KEY, {
46
+ type: namespace,
29
47
  });
30
48
  }
31
49
  exports.App = App;
50
+ /**
51
+ * Get the main application instance
52
+ * @since 4.0.0
53
+ */
54
+ function MainApp() {
55
+ return __1.DecoratorManager.createCustomPropertyDecorator(__1.MAIN_APPLICATION_KEY, {});
56
+ }
57
+ exports.MainApp = MainApp;
58
+ /**
59
+ * Logger decorator, use to get logger instance
60
+ * @since 2.0.0
61
+ */
32
62
  function Logger(identifier) {
33
- return (0, __1.createCustomPropertyDecorator)(__1.LOGGER_KEY, {
63
+ return __1.DecoratorManager.createCustomPropertyDecorator(__1.LOGGER_KEY, {
34
64
  identifier,
35
65
  });
36
66
  }
37
67
  exports.Logger = Logger;
68
+ /**
69
+ * ApplicationContext decorator, use to get global IoC container instance
70
+ * @since 3.0.0
71
+ */
38
72
  function ApplicationContext() {
39
- return (0, __1.createCustomPropertyDecorator)(__1.APPLICATION_CONTEXT_KEY, {});
73
+ return __1.DecoratorManager.createCustomPropertyDecorator(__1.APPLICATION_CONTEXT_KEY, {});
40
74
  }
41
75
  exports.ApplicationContext = ApplicationContext;
42
76
  //# sourceMappingURL=framework.js.map
@@ -1,29 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Guard = exports.UseGuard = void 0;
4
- const decoratorManager_1 = require("../decoratorManager");
5
4
  const interface_1 = require("../../interface");
6
5
  const constant_1 = require("../constant");
7
6
  const provide_1 = require("./provide");
8
- const objectDef_1 = require("./objectDef");
7
+ const metadataManager_1 = require("../metadataManager");
8
+ const scope_1 = require("./scope");
9
9
  function UseGuard(guardOrArr) {
10
10
  return (target, propertyKey, descriptor) => {
11
11
  if (!Array.isArray(guardOrArr)) {
12
12
  guardOrArr = [guardOrArr];
13
13
  }
14
- if (propertyKey) {
15
- (0, decoratorManager_1.savePropertyMetadata)(constant_1.GUARD_KEY, guardOrArr, target, propertyKey);
16
- }
17
- else {
18
- (0, decoratorManager_1.saveClassMetadata)(constant_1.GUARD_KEY, guardOrArr, target);
19
- }
14
+ metadataManager_1.MetadataManager.defineMetadata(constant_1.GUARD_KEY, guardOrArr, target, propertyKey);
20
15
  };
21
16
  }
22
17
  exports.UseGuard = UseGuard;
23
18
  function Guard() {
24
19
  return target => {
25
20
  (0, provide_1.Provide)()(target);
26
- (0, objectDef_1.Scope)(interface_1.ScopeEnum.Singleton)(target);
21
+ (0, scope_1.Scope)(interface_1.ScopeEnum.Singleton)(target);
27
22
  };
28
23
  }
29
24
  exports.Guard = Guard;
@@ -1,4 +1,6 @@
1
- import { IServiceFactory, ObjectIdentifier } from '../../interface';
2
- export declare function Inject(identifier?: ObjectIdentifier): (target: any, targetKey: string) => void;
1
+ import { IServiceFactory, ObjectIdentifier, ClassType } from '../../interface';
2
+ export declare function saveInjectMetadata(identifier: any, target: any, targetKey: any, isLazyInject?: boolean, parameterIndex?: number): void;
3
+ export declare function Inject(identifier?: ObjectIdentifier): PropertyDecorator & ParameterDecorator;
4
+ export declare function LazyInject(identifier?: ObjectIdentifier | (() => ObjectIdentifier | ClassType)): PropertyDecorator & ParameterDecorator;
3
5
  export declare function InjectClient(serviceFactoryClz: new (...args: any[]) => IServiceFactory<unknown>, clientName?: string): PropertyDecorator;
4
6
  //# sourceMappingURL=inject.d.ts.map
@@ -1,16 +1,99 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InjectClient = exports.Inject = void 0;
3
+ exports.InjectClient = exports.LazyInject = exports.Inject = exports.saveInjectMetadata = void 0;
4
4
  const decoratorManager_1 = require("../decoratorManager");
5
+ const interface_1 = require("../../interface");
5
6
  const constant_1 = require("../constant");
7
+ const types_1 = require("../../util/types");
8
+ const metadataManager_1 = require("../metadataManager");
9
+ const util_1 = require("../../util");
10
+ function getConstructParamNames(target) {
11
+ let paramNames = metadataManager_1.MetadataManager.getOwnMetadata('constructorParamNames', target);
12
+ if (!paramNames) {
13
+ // cache constructor param names
14
+ paramNames = (0, util_1.getParamNames)(target);
15
+ metadataManager_1.MetadataManager.defineMetadata('constructorParamNames', paramNames, target);
16
+ }
17
+ return paramNames;
18
+ }
19
+ function saveInjectMetadata(identifier, target, targetKey, isLazyInject = false, parameterIndex) {
20
+ // 1、use identifier by user
21
+ // let identifier = opts.identifier;
22
+ let injectMode = interface_1.InjectModeEnum.Identifier;
23
+ let id = identifier;
24
+ const isConstructor = parameterIndex !== undefined;
25
+ // 2、use identifier by class uuid
26
+ if (isConstructor) {
27
+ const paramNames = getConstructParamNames(target);
28
+ if (!id) {
29
+ const argsTypes = metadataManager_1.MetadataManager.getMethodParamTypes(target, targetKey);
30
+ const type = metadataManager_1.MetadataManager.transformTypeFromTSDesign(argsTypes[parameterIndex]);
31
+ if (!type.isBaseType &&
32
+ (0, types_1.isClass)(type.originDesign) &&
33
+ decoratorManager_1.DecoratorManager.isProvide(type.originDesign)) {
34
+ id = decoratorManager_1.DecoratorManager.getProviderUUId(type.originDesign);
35
+ injectMode = interface_1.InjectModeEnum.Class;
36
+ }
37
+ if (!id) {
38
+ // 3、use identifier by property name
39
+ id = paramNames[parameterIndex];
40
+ injectMode = interface_1.InjectModeEnum.SelfName;
41
+ }
42
+ }
43
+ metadataManager_1.MetadataManager.attachMetadata(constant_1.CONSTRUCTOR_INJECT_KEY, {
44
+ targetKey,
45
+ id,
46
+ name: paramNames[parameterIndex],
47
+ injectMode,
48
+ isLazyInject,
49
+ parameterIndex,
50
+ }, target, 'default');
51
+ }
52
+ else {
53
+ if (!id) {
54
+ const type = metadataManager_1.MetadataManager.transformTypeFromTSDesign(metadataManager_1.MetadataManager.getPropertyType(target, targetKey));
55
+ if (!type.isBaseType &&
56
+ (0, types_1.isClass)(type.originDesign) &&
57
+ decoratorManager_1.DecoratorManager.isProvide(type.originDesign)) {
58
+ id = decoratorManager_1.DecoratorManager.getProviderUUId(type.originDesign);
59
+ injectMode = interface_1.InjectModeEnum.Class;
60
+ }
61
+ if (!id) {
62
+ // 3、use identifier by property name
63
+ id = targetKey;
64
+ injectMode = interface_1.InjectModeEnum.SelfName;
65
+ }
66
+ }
67
+ metadataManager_1.MetadataManager.defineMetadata(constant_1.PROPERTY_INJECT_KEY, {
68
+ targetKey,
69
+ id,
70
+ name: targetKey,
71
+ isLazyInject,
72
+ injectMode,
73
+ }, target, targetKey);
74
+ }
75
+ }
76
+ exports.saveInjectMetadata = saveInjectMetadata;
6
77
  function Inject(identifier) {
7
- return function (target, targetKey) {
8
- (0, decoratorManager_1.savePropertyInject)({ target, targetKey, identifier });
78
+ return function (target, targetKey, parameterIndex) {
79
+ return saveInjectMetadata(identifier, target, targetKey, false, parameterIndex);
9
80
  };
10
81
  }
11
82
  exports.Inject = Inject;
83
+ function LazyInject(identifier) {
84
+ let id = identifier;
85
+ if (id && typeof id !== 'function') {
86
+ id = (() => {
87
+ return identifier;
88
+ });
89
+ }
90
+ return function (target, targetKey, parameterIndex) {
91
+ return saveInjectMetadata(id, target, targetKey, true, parameterIndex);
92
+ };
93
+ }
94
+ exports.LazyInject = LazyInject;
12
95
  function InjectClient(serviceFactoryClz, clientName) {
13
- return (0, decoratorManager_1.createCustomPropertyDecorator)(constant_1.FACTORY_SERVICE_CLIENT_KEY, {
96
+ return decoratorManager_1.DecoratorManager.createCustomPropertyDecorator(constant_1.FACTORY_SERVICE_CLIENT_KEY, {
14
97
  serviceFactoryClz,
15
98
  clientName,
16
99
  });
@@ -5,7 +5,7 @@ const __1 = require("../");
5
5
  const interface_1 = require("../../interface");
6
6
  function Mock() {
7
7
  return (target) => {
8
- (0, __1.saveModule)(__1.MOCK_KEY, target);
8
+ __1.DecoratorManager.saveModule(__1.MOCK_KEY, target);
9
9
  (0, __1.Scope)(interface_1.ScopeEnum.Singleton)(target);
10
10
  (0, __1.Provide)()(target);
11
11
  };
@@ -1,8 +1,3 @@
1
- import { ScopeEnum } from '../../interface';
2
1
  export declare function Init(): MethodDecorator;
3
2
  export declare function Destroy(): MethodDecorator;
4
- export declare function Scope(scope: ScopeEnum, scopeOptions?: {
5
- allowDowngrade?: boolean;
6
- }): ClassDecorator;
7
- export declare function Singleton(): ClassDecorator;
8
3
  //# sourceMappingURL=objectDef.d.ts.map
@@ -1,34 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Singleton = exports.Scope = exports.Destroy = exports.Init = void 0;
4
- const decoratorManager_1 = require("../decoratorManager");
5
- const provide_1 = require("./provide");
6
- const interface_1 = require("../../interface");
3
+ exports.Destroy = exports.Init = void 0;
4
+ const metadataManager_1 = require("../metadataManager");
5
+ const constant_1 = require("../constant");
7
6
  function Init() {
8
7
  return function (target, propertyKey) {
9
- (0, decoratorManager_1.saveObjectDefinition)(target, { initMethod: propertyKey });
8
+ metadataManager_1.MetadataManager.attachMetadata(constant_1.OBJECT_DEFINITION_KEY, {
9
+ initMethod: propertyKey,
10
+ }, target, propertyKey);
10
11
  };
11
12
  }
12
13
  exports.Init = Init;
13
14
  function Destroy() {
14
15
  return function (target, propertyKey) {
15
- (0, decoratorManager_1.saveObjectDefinition)(target, {
16
+ metadataManager_1.MetadataManager.attachMetadata(constant_1.OBJECT_DEFINITION_KEY, {
16
17
  destroyMethod: propertyKey,
17
- });
18
+ }, target, propertyKey);
18
19
  };
19
20
  }
20
21
  exports.Destroy = Destroy;
21
- function Scope(scope, scopeOptions) {
22
- return function (target) {
23
- (0, decoratorManager_1.saveObjectDefinition)(target, { scope, ...scopeOptions });
24
- };
25
- }
26
- exports.Scope = Scope;
27
- function Singleton() {
28
- return function (target) {
29
- Scope(interface_1.ScopeEnum.Singleton)(target);
30
- (0, provide_1.Provide)()(target);
31
- };
32
- }
33
- exports.Singleton = Singleton;
34
22
  //# sourceMappingURL=objectDef.js.map
@@ -1,3 +1,3 @@
1
1
  import { ObjectIdentifier } from '../../interface';
2
- export declare function Provide(identifier?: ObjectIdentifier): (target: any) => any;
2
+ export declare function Provide(identifier?: ObjectIdentifier): (target: any) => void;
3
3
  //# sourceMappingURL=provide.d.ts.map
@@ -4,7 +4,7 @@ exports.Provide = void 0;
4
4
  const decoratorManager_1 = require("../decoratorManager");
5
5
  function Provide(identifier) {
6
6
  return function (target) {
7
- return (0, decoratorManager_1.saveProviderId)(identifier, target);
7
+ decoratorManager_1.DecoratorManager.saveProviderId(identifier, target);
8
8
  };
9
9
  }
10
10
  exports.Provide = Provide;
@@ -0,0 +1,6 @@
1
+ import { ScopeEnum } from '../../interface';
2
+ export declare function Scope(scope: ScopeEnum, scopeOptions?: {
3
+ allowDowngrade?: boolean;
4
+ }): ClassDecorator;
5
+ export declare function Singleton(): ClassDecorator;
6
+ //# sourceMappingURL=scope.d.ts.map