@wocker/core 1.0.25-beta.1 → 1.0.26-beta.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.
Files changed (67) hide show
  1. package/README.md +1 -1
  2. package/lib/core/ApplicationContext.d.ts +1 -1
  3. package/lib/core/AsyncStorage.d.ts +10 -2
  4. package/lib/core/AsyncStorage.js +9 -1
  5. package/lib/core/Container.d.ts +3 -2
  6. package/lib/core/Container.js +8 -0
  7. package/lib/core/InstanceWrapper.d.ts +1 -2
  8. package/lib/core/InstanceWrapper.js +4 -4
  9. package/lib/core/ModuleWrapper.d.ts +10 -6
  10. package/lib/core/ModuleWrapper.js +21 -2
  11. package/lib/core/Route.d.ts +1 -3
  12. package/lib/core/Route.js +6 -8
  13. package/lib/core/Scanner.d.ts +10 -7
  14. package/lib/core/Scanner.js +71 -39
  15. package/lib/decorators/Description.js +13 -0
  16. package/lib/decorators/Module.d.ts +1 -8
  17. package/lib/decorators/Option.js +19 -6
  18. package/lib/decorators/Optional.d.ts +1 -0
  19. package/lib/decorators/Optional.js +22 -0
  20. package/lib/decorators/Param.js +15 -2
  21. package/lib/decorators/Plugin.d.ts +2 -7
  22. package/lib/decorators/Plugin.js +3 -1
  23. package/lib/decorators/index.d.ts +1 -5
  24. package/lib/decorators/index.js +1 -0
  25. package/lib/env.d.ts +2 -1
  26. package/lib/env.js +3 -2
  27. package/lib/index.d.ts +1 -0
  28. package/lib/index.js +1 -0
  29. package/lib/makes/AppConfig.d.ts +1 -6
  30. package/lib/makes/AppConfig.js +1 -10
  31. package/lib/makes/index.d.ts +0 -1
  32. package/lib/makes/index.js +0 -1
  33. package/lib/modules/index.d.ts +1 -0
  34. package/lib/modules/index.js +17 -0
  35. package/lib/modules/project/index.d.ts +4 -0
  36. package/lib/modules/project/index.js +25 -0
  37. package/lib/{makes → modules/project/makes}/Project.d.ts +27 -25
  38. package/lib/modules/project/makes/Project.js +281 -0
  39. package/lib/modules/project/repositories/ProjectRepository.d.ts +11 -0
  40. package/lib/modules/project/repositories/ProjectRepository.js +16 -0
  41. package/lib/{services → modules/project/services}/ProjectService.d.ts +3 -7
  42. package/lib/{services → modules/project/services}/ProjectService.js +1 -1
  43. package/lib/modules/project/types/ProjectType.d.ts +5 -0
  44. package/lib/modules/project/types/ProjectType.js +7 -0
  45. package/lib/modules/project/types/ProjectV1.d.ts +23 -0
  46. package/lib/modules/project/types/ProjectV1.js +2 -0
  47. package/lib/modules/project/types/ServiceProperties.d.ts +9 -0
  48. package/lib/modules/project/types/ServiceProperties.js +2 -0
  49. package/lib/modules/project/types/index.d.ts +3 -0
  50. package/lib/modules/project/types/index.js +19 -0
  51. package/lib/services/AppConfigService.d.ts +4 -2
  52. package/lib/services/AppConfigService.js +18 -11
  53. package/lib/services/AppService.d.ts +1 -1
  54. package/lib/services/AppService.js +2 -2
  55. package/lib/services/index.d.ts +0 -1
  56. package/lib/services/index.js +0 -1
  57. package/lib/types/ArgMeta.d.ts +1 -0
  58. package/lib/types/DynamicModule.d.ts +9 -0
  59. package/lib/types/DynamicModule.js +2 -0
  60. package/lib/types/ModuleMetadata.d.ts +11 -0
  61. package/lib/types/ModuleMetadata.js +3 -0
  62. package/lib/types/PluginMetadata.d.ts +5 -0
  63. package/lib/types/PluginMetadata.js +3 -0
  64. package/lib/types/index.d.ts +14 -0
  65. package/lib/types/index.js +4 -0
  66. package/package.json +7 -9
  67. package/lib/makes/Project.js +0 -200
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  [![npm version](https://img.shields.io/npm/v/@wocker/core.svg)](https://www.npmjs.com/package/@wocker/core)
6
6
  [![Publish](https://github.com/kearisp/wocker-core/actions/workflows/publish-latest.yml/badge.svg?event=release)](https://github.com/kearisp/wocker-core/actions/workflows/publish-latest.yml)
7
- [![License](https://img.shields.io/npm/l/@wocker/core)](https://github.com/kearisp/wocker-core/blob/main/LICENSE)
7
+ [![License](https://img.shields.io/npm/l/@wocker/core)](https://github.com/kearisp/wocker-core/blob/master/LICENSE)
8
8
 
9
9
  [![npm total downloads](https://img.shields.io/npm/dt/@wocker/core.svg)](https://www.npmjs.com/package/@wocker/core)
10
10
  [![bundle size](https://img.shields.io/bundlephobia/minzip/@wocker/core)](https://bundlephobia.com/package/@wocker/core)
@@ -1,5 +1,5 @@
1
+ import { Type } from "../types";
1
2
  import { Container } from "./Container";
2
- import { Type } from "../types/Type";
3
3
  export declare class ApplicationContext {
4
4
  protected readonly module: any;
5
5
  protected readonly container: Container;
@@ -1,3 +1,11 @@
1
- import { AsyncLocalStorage } from "node:async_hooks";
2
1
  import type { Container } from "./Container";
3
- export declare const AsyncStorage: AsyncLocalStorage<Container>;
2
+ export declare const AsyncStorage: {
3
+ getContainer(): Container;
4
+ disable(): void;
5
+ getStore(): Container | undefined;
6
+ readonly name: string;
7
+ run<R>(store: Container, callback: () => R): R;
8
+ run<R, TArgs extends any[]>(store: Container, callback: (...args: TArgs) => R, ...args: TArgs): R;
9
+ exit<R, TArgs extends any[]>(callback: (...args: TArgs) => R, ...args: TArgs): R;
10
+ enterWith(store: Container): void;
11
+ };
@@ -2,4 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AsyncStorage = void 0;
4
4
  const node_async_hooks_1 = require("node:async_hooks");
5
- exports.AsyncStorage = new node_async_hooks_1.AsyncLocalStorage();
5
+ exports.AsyncStorage = new class extends node_async_hooks_1.AsyncLocalStorage {
6
+ getContainer() {
7
+ const container = exports.AsyncStorage.getStore();
8
+ if (!container) {
9
+ throw new Error("Couldn't find container");
10
+ }
11
+ return container;
12
+ }
13
+ }();
@@ -1,9 +1,9 @@
1
1
  import { InstanceWrapper } from "./InstanceWrapper";
2
2
  import { ModuleWrapper } from "./ModuleWrapper";
3
- import { InjectionToken, ProviderType } from "../types";
4
- import { Type } from "../types/Type";
3
+ import { Type, InjectionToken, ProviderType } from "../types";
5
4
  export declare class Container {
6
5
  readonly modules: Map<Type, ModuleWrapper>;
6
+ readonly moduleExportIndex: Map<InjectionToken, Set<ModuleWrapper>>;
7
7
  readonly globalProviders: Map<InjectionToken, InstanceWrapper>;
8
8
  constructor();
9
9
  addModule<TInput = any>(type: Type<TInput>, module: ModuleWrapper): void;
@@ -11,5 +11,6 @@ export declare class Container {
11
11
  getModule<TInput = any>(type: Type<TInput>): ModuleWrapper<TInput>;
12
12
  addProvider(type: InjectionToken, wrapper: InstanceWrapper): void;
13
13
  getProvider(type: InjectionToken): InstanceWrapper | undefined;
14
+ get<TInput = any, TReturn = TInput>(type: InjectionToken<TInput>): TReturn;
14
15
  replace(type: InjectionToken, provider: ProviderType): void;
15
16
  }
@@ -8,6 +8,7 @@ const env_1 = require("../env");
8
8
  class Container {
9
9
  constructor() {
10
10
  this.modules = new Map();
11
+ this.moduleExportIndex = new Map();
11
12
  this.globalProviders = new Map();
12
13
  const cliWrapper = new InstanceWrapper_1.InstanceWrapper(new ModuleWrapper_1.ModuleWrapper(this, null), cli_1.Cli);
13
14
  this.globalProviders.set(cli_1.Cli, cliWrapper);
@@ -37,6 +38,13 @@ class Container {
37
38
  : type;
38
39
  return this.globalProviders.get(token);
39
40
  }
41
+ get(type) {
42
+ const wrapper = this.getProvider(type);
43
+ if (!wrapper) {
44
+ throw new Error("Couldn't find provider wrapper");
45
+ }
46
+ return wrapper.instance;
47
+ }
40
48
  replace(type, provider) {
41
49
  const token = typeof type !== "string"
42
50
  ? Reflect.getMetadata(env_1.INJECT_TOKEN_METADATA, type) || type
@@ -1,6 +1,5 @@
1
1
  import { ModuleWrapper } from "./ModuleWrapper";
2
- import { ProviderType, InjectionToken } from "../types";
3
- import { Type } from "../types/Type";
2
+ import { Type, ProviderType, InjectionToken } from "../types";
4
3
  export declare class InstanceWrapper<TInput = any> {
5
4
  protected readonly module: ModuleWrapper;
6
5
  protected readonly provider: ProviderType<TInput>;
@@ -37,15 +37,15 @@ class InstanceWrapper {
37
37
  if (!this._type) {
38
38
  throw new Error("Type not defined");
39
39
  }
40
- const types = Reflect.getMetadata(env_1.PARAMTYPES_METADATA, this._type) || [];
41
- const selfTypes = Reflect.getMetadata(env_1.SELF_DECLARED_DEPS_METADATA, this._type) || [];
40
+ const types = Reflect.getMetadata(env_1.PARAMTYPES_METADATA, this._type) || [], selfTypes = Reflect.getMetadata(env_1.SELF_DECLARED_DEPS_METADATA, this._type) || [], argsMeta = Reflect.getMetadata(env_1.ARGS_METADATA, this._type) || [];
42
41
  if (selfTypes.length > 0) {
43
42
  selfTypes.forEach(({ index, token }) => {
44
43
  types[index] = token;
45
44
  });
46
45
  }
47
- const params = types.map((type) => {
48
- return this.module.get(type);
46
+ const params = types.map((type, index) => {
47
+ const optional = (argsMeta[index] || {}).optional || false;
48
+ return this.module.get(type, optional);
49
49
  });
50
50
  this._instance = new this._type(...params);
51
51
  }
@@ -1,20 +1,24 @@
1
- import { InjectionToken, ProviderType } from "../types";
2
- import { Type } from "../types/Type";
1
+ import { InjectionToken, ModuleMetadata, ProviderType, Type } from "../types";
3
2
  import { Container } from "./Container";
4
3
  import { InstanceWrapper } from "./InstanceWrapper";
5
4
  import { ControllerWrapper } from "./ControllerWrapper";
6
5
  export declare class ModuleWrapper<TInput = any> {
7
6
  readonly container: Container;
8
7
  readonly type: TInput;
9
- imports: Map<any, InstanceWrapper>;
8
+ global: boolean;
9
+ imports: Set<ModuleWrapper>;
10
10
  controllers: Map<any, ControllerWrapper>;
11
11
  providers: Map<any, InstanceWrapper>;
12
12
  exports: Set<any>;
13
+ factory?: (...args: any[]) => ModuleMetadata | Promise<ModuleMetadata>;
14
+ factoryInject?: any[];
13
15
  constructor(container: Container, type: TInput);
14
- get<TInput = any, TResult = TInput>(type: Type<TInput> | Function | string | symbol): TResult;
16
+ get<TInput = any, TResult = TInput>(type: InjectionToken<TInput>): TResult;
17
+ get<TInput = any, TResult = TInput, O extends boolean = boolean>(type: InjectionToken<TInput>, optional: O): O extends true ? TResult | undefined : TResult;
15
18
  getWrapper(type: InjectionToken): InstanceWrapper | undefined;
16
19
  addProvider(provider: ProviderType): void;
17
- addController(type: any): void;
18
- addExport(type: any): void;
20
+ addController(type: Type): void;
21
+ addImport(module: ModuleWrapper): void;
22
+ addExport(type: InjectionToken | Type): void;
19
23
  replace(token: InjectionToken, provider: ProviderType): void;
20
24
  }
@@ -8,14 +8,18 @@ class ModuleWrapper {
8
8
  constructor(container, type) {
9
9
  this.container = container;
10
10
  this.type = type;
11
- this.imports = new Map();
11
+ this.global = false;
12
+ this.imports = new Set();
12
13
  this.controllers = new Map();
13
14
  this.providers = new Map();
14
15
  this.exports = new Set();
15
16
  }
16
- get(type) {
17
+ get(type, optional) {
17
18
  const wrapper = this.getWrapper(type);
18
19
  if (!wrapper) {
20
+ if (optional) {
21
+ return undefined;
22
+ }
19
23
  if (typeof type === "function") {
20
24
  throw new Error(`Provider "${type.prototype.constructor.name}" not found`);
21
25
  }
@@ -32,6 +36,15 @@ class ModuleWrapper {
32
36
  : type;
33
37
  const wrapper = this.providers.get(token);
34
38
  if (!wrapper) {
39
+ for (const im of this.imports) {
40
+ if (!im.exports.has(token)) {
41
+ continue;
42
+ }
43
+ const wrapper = im.getWrapper(token);
44
+ if (wrapper) {
45
+ return wrapper;
46
+ }
47
+ }
35
48
  return this.container.globalProviders.get(token);
36
49
  }
37
50
  return wrapper;
@@ -44,11 +57,17 @@ class ModuleWrapper {
44
57
  const controllerWrapper = new ControllerWrapper_1.ControllerWrapper(this, type);
45
58
  this.controllers.set(type, controllerWrapper);
46
59
  }
60
+ addImport(module) {
61
+ this.imports.add(module);
62
+ }
47
63
  addExport(type) {
48
64
  const token = typeof type !== "string"
49
65
  ? Reflect.getMetadata(env_1.INJECT_TOKEN_METADATA, type) || type
50
66
  : type;
51
67
  this.exports.add(token);
68
+ const indexes = this.container.moduleExportIndex.get(token) || new Set();
69
+ indexes.add(this);
70
+ this.container.moduleExportIndex.set(token, indexes);
52
71
  }
53
72
  replace(token, provider) {
54
73
  const wrapper = this.getWrapper(token);
@@ -1,5 +1,4 @@
1
- import { ArgMeta } from "../types/ArgMeta";
2
- import { Type } from "../types/Type";
1
+ import { Type } from "../types";
3
2
  export declare class Route {
4
3
  readonly type: Type;
5
4
  readonly method: string;
@@ -9,7 +8,6 @@ export declare class Route {
9
8
  name: string;
10
9
  params: any;
11
10
  }[];
12
- argsMeta: ArgMeta[];
13
11
  designTypes: any[];
14
12
  commandNames: string[];
15
13
  completions: {
package/lib/core/Route.js CHANGED
@@ -7,7 +7,6 @@ class Route {
7
7
  this.type = type;
8
8
  this.method = method;
9
9
  this.args = [];
10
- this.argsMeta = [];
11
10
  this.designTypes = [];
12
11
  this.commandNames = [];
13
12
  this.completions = [];
@@ -18,17 +17,16 @@ class Route {
18
17
  this.description = Reflect.getMetadata(env_1.DESCRIPTION_METADATA, descriptor.value) || "";
19
18
  this.commandNames = Reflect.getMetadata(env_1.COMMAND_METADATA, descriptor.value) || [];
20
19
  this.completions = Reflect.getMetadata(env_1.COMPLETION_METADATA, descriptor.value) || [];
21
- const argsMeta = Reflect.getMetadata(env_1.ARGS_METADATA, this.type, this.method) || [], argsAliases = Reflect.getMetadata(env_1.ALIAS_METADATA, this.type, this.method) || {}, argsDescription = Reflect.getMetadata(env_1.DESCRIPTION_METADATA, this.type, method) || {}, designTypes = Reflect.getMetadata(env_1.PARAMTYPES_METADATA, this.type.prototype, this.method) || [];
22
- this.argsMeta = argsMeta;
23
- this.designTypes = designTypes;
24
- for (let i = 0; i < argsMeta.length; i++) {
25
- const argMeta = argsMeta[i];
20
+ this.designTypes = Reflect.getMetadata(env_1.PARAMTYPES_METADATA, this.type.prototype, this.method) || [];
21
+ const argsMetadata = Reflect.getMetadata(env_1.ARGS_METADATA, this.type, this.method) || [], argsAliases = Reflect.getMetadata(env_1.ALIAS_METADATA, this.type, this.method) || {};
22
+ for (const index in argsMetadata) {
23
+ const argMeta = argsMetadata[index];
26
24
  if (argMeta.type === "param") {
27
25
  this.args[argMeta.index] = {
28
26
  type: argMeta.type,
29
27
  name: argMeta.name,
30
28
  params: {
31
- description: argsDescription[argMeta.index] || ""
29
+ description: argMeta.description,
32
30
  }
33
31
  };
34
32
  }
@@ -37,7 +35,7 @@ class Route {
37
35
  this.args[argMeta.index] = {
38
36
  type: argMeta.type,
39
37
  name: argMeta.name,
40
- params: Object.assign(Object.assign({}, argMeta.params), { type: this.getArgType(argMeta.index) || type, alias: argsAliases[argMeta.index] || alias, description: argsDescription[argMeta.index] || description })
38
+ params: Object.assign(Object.assign({}, argMeta.params), { type: this.getArgType(argMeta.index) || type, alias: argsAliases[argMeta.index] || alias, description: argMeta.description || description })
41
39
  };
42
40
  }
43
41
  }
@@ -1,18 +1,21 @@
1
1
  import "reflect-metadata";
2
2
  import { Cli } from "@kearisp/cli";
3
+ import { Type, DynamicModule, ProviderType } from "../types";
3
4
  import { Container } from "./Container";
4
5
  import { ControllerWrapper } from "./ControllerWrapper";
5
6
  import { ModuleWrapper } from "./ModuleWrapper";
6
7
  export declare class Scanner {
7
8
  readonly container: Container;
8
- constructor();
9
- scan(moduleType: any): Promise<void>;
10
- protected scanModule(moduleType: any): ModuleWrapper;
11
- protected scanControllers(module: ModuleWrapper): void;
12
- protected scanProviders(module: ModuleWrapper): void;
13
- protected scanImports(module: ModuleWrapper): void;
14
- protected scanExports(module: ModuleWrapper): void;
9
+ constructor(container?: Container);
10
+ scan(moduleDefinition: Type | DynamicModule): Promise<void>;
11
+ protected getMetadata(moduleDefinition: Type | DynamicModule): DynamicModule;
12
+ protected scanModule(moduleDefinition: Type | DynamicModule): ModuleWrapper;
13
+ protected scanControllers(module: ModuleWrapper, controllers: Type[]): void;
14
+ protected scanProviders(module: ModuleWrapper, providers: ProviderType[]): void;
15
+ protected scanImports(module: ModuleWrapper, imports: any[]): void;
16
+ protected scanExports(module: ModuleWrapper, exports: any[]): void;
15
17
  protected scanRoutes(): void;
16
18
  protected scanControllerRoutes(cli: Cli, wrapper: ControllerWrapper): void;
17
19
  protected scanDynamicModules(): Promise<void>;
20
+ isDynamicModule(moduleDefinition: Type | DynamicModule): moduleDefinition is DynamicModule;
18
21
  }
@@ -16,61 +16,93 @@ const Container_1 = require("./Container");
16
16
  const ModuleWrapper_1 = require("./ModuleWrapper");
17
17
  const env_1 = require("../env");
18
18
  class Scanner {
19
- constructor() {
20
- this.container = new Container_1.Container();
19
+ constructor(container) {
20
+ this.container = container || new Container_1.Container();
21
21
  }
22
- scan(moduleType) {
22
+ scan(moduleDefinition) {
23
23
  return __awaiter(this, void 0, void 0, function* () {
24
- this.scanModule(moduleType);
24
+ this.scanModule(moduleDefinition);
25
25
  yield this.scanDynamicModules();
26
26
  this.scanRoutes();
27
27
  });
28
28
  }
29
- scanModule(moduleType) {
29
+ getMetadata(moduleDefinition) {
30
+ if (this.isDynamicModule(moduleDefinition)) {
31
+ const module = moduleDefinition.module;
32
+ return {
33
+ module: moduleDefinition.module,
34
+ global: moduleDefinition.global || Reflect.getMetadata(env_1.IS_GLOBAL_METADATA, module),
35
+ inject: moduleDefinition.inject,
36
+ useFactory: moduleDefinition.useFactory,
37
+ imports: [
38
+ ...Reflect.getMetadata(env_1.MODULE_METADATA.IMPORTS, module) || [],
39
+ ...moduleDefinition.imports || []
40
+ ],
41
+ controllers: [
42
+ ...Reflect.getMetadata(env_1.MODULE_METADATA.CONTROLLERS, module) || [],
43
+ ...moduleDefinition.controllers || []
44
+ ],
45
+ providers: [
46
+ ...Reflect.getMetadata(env_1.MODULE_METADATA.PROVIDERS, module) || [],
47
+ ...moduleDefinition.providers || []
48
+ ],
49
+ exports: [
50
+ ...Reflect.getMetadata(env_1.MODULE_METADATA.EXPORTS, module) || [],
51
+ ...moduleDefinition.exports || []
52
+ ]
53
+ };
54
+ }
55
+ return {
56
+ module: moduleDefinition,
57
+ global: Reflect.getMetadata(env_1.IS_GLOBAL_METADATA, moduleDefinition) || false,
58
+ imports: Reflect.getMetadata(env_1.MODULE_METADATA.IMPORTS, moduleDefinition) || [],
59
+ controllers: Reflect.getMetadata(env_1.MODULE_METADATA.CONTROLLERS, moduleDefinition) || [],
60
+ providers: Reflect.getMetadata(env_1.MODULE_METADATA.PROVIDERS, moduleDefinition) || [],
61
+ exports: Reflect.getMetadata(env_1.MODULE_METADATA.EXPORTS, moduleDefinition) || []
62
+ };
63
+ }
64
+ scanModule(moduleDefinition) {
65
+ const { module: moduleType, global = false, inject, useFactory, imports = [], controllers = [], providers = [], exports = [] } = this.getMetadata(moduleDefinition);
30
66
  let module = this.container.hasModule(moduleType)
31
67
  ? this.container.getModule(moduleType)
32
68
  : null;
33
69
  if (!module) {
34
70
  module = new ModuleWrapper_1.ModuleWrapper(this.container, moduleType);
71
+ module.global = global;
72
+ if (useFactory) {
73
+ module.factory = useFactory;
74
+ module.factoryInject = inject;
75
+ }
35
76
  this.container.addModule(moduleType, module);
36
- this.scanImports(module);
37
- this.scanControllers(module);
38
- this.scanProviders(module);
39
- this.scanExports(module);
77
+ this.scanImports(module, imports);
78
+ this.scanControllers(module, controllers);
79
+ this.scanProviders(module, providers);
80
+ this.scanExports(module, exports);
40
81
  }
41
82
  return module;
42
83
  }
43
- scanControllers(module) {
44
- const controllers = Reflect.getMetadata(env_1.MODULE_METADATA.CONTROLLERS, module.type) || [];
84
+ scanControllers(module, controllers) {
85
+ // const controllers = Reflect.getMetadata(MODULE_METADATA.CONTROLLERS, module.type) || [];
45
86
  controllers.forEach((controller) => {
46
87
  module.addController(controller);
47
88
  });
48
89
  }
49
- scanProviders(module) {
50
- const providers = Reflect.getMetadata(env_1.MODULE_METADATA.PROVIDERS, module.type) || [];
90
+ scanProviders(module, providers) {
91
+ // const providers: ProviderType[] = Reflect.getMetadata(MODULE_METADATA.PROVIDERS, module.type) || [];
51
92
  providers.forEach((provider) => {
52
93
  module.addProvider(provider);
53
94
  });
54
95
  }
55
- scanImports(module) {
56
- const imports = Reflect.getMetadata(env_1.MODULE_METADATA.IMPORTS, module.type) || [];
96
+ scanImports(module, imports) {
57
97
  imports.forEach((importType) => {
58
98
  const subModule = this.scanModule(importType);
59
- subModule.exports.forEach((type) => {
60
- const provider = subModule.providers.get(type);
61
- if (!provider) {
62
- return;
63
- }
64
- module.providers.set(type, provider);
65
- });
99
+ module.addImport(subModule);
66
100
  });
67
101
  }
68
- scanExports(module) {
69
- const exports = Reflect.getMetadata(env_1.MODULE_METADATA.EXPORTS, module.type) || [];
70
- const isGlobal = Reflect.getMetadata(env_1.IS_GLOBAL_METADATA, module.type) || false;
102
+ scanExports(module, exports) {
71
103
  exports.forEach((type) => {
72
104
  module.addExport(type);
73
- if (isGlobal) {
105
+ if (module.global) {
74
106
  const wrapper = module.getWrapper(type);
75
107
  if (wrapper) {
76
108
  this.container.addProvider(type, wrapper);
@@ -123,25 +155,25 @@ class Scanner {
123
155
  scanDynamicModules() {
124
156
  return __awaiter(this, void 0, void 0, function* () {
125
157
  const promises = ([...this.container.modules.keys()]).map((type) => __awaiter(this, void 0, void 0, function* () {
126
- if (!type.prototype.load) {
158
+ const wrapper = this.container.modules.get(type);
159
+ if (!wrapper) {
127
160
  return;
128
161
  }
129
- const parentModule = this.container.modules.get(type);
130
- const { [env_1.MODULE_METADATA.IMPORTS]: imports = [] } = yield type.prototype.load(this.container);
131
- for (const subModuleType of imports) {
132
- const module = this.scanModule(subModuleType);
133
- module.exports.forEach((type) => {
134
- const provider = module.getWrapper(type);
135
- if (!provider) {
136
- return;
137
- }
138
- // @ts-ignore
139
- parentModule.providers.set(type, provider);
140
- });
162
+ if (wrapper.factory) {
163
+ const { imports = [], controllers = [], providers = [], exports = [] } = yield wrapper.factory(...(wrapper.factoryInject || []).map((token) => {
164
+ return wrapper.get(token);
165
+ }));
166
+ this.scanImports(wrapper, imports);
167
+ this.scanControllers(wrapper, controllers);
168
+ this.scanProviders(wrapper, providers);
169
+ this.scanExports(wrapper, exports);
141
170
  }
142
171
  }));
143
172
  yield Promise.all(promises);
144
173
  });
145
174
  }
175
+ isDynamicModule(moduleDefinition) {
176
+ return moduleDefinition && !!moduleDefinition.module;
177
+ }
146
178
  }
147
179
  exports.Scanner = Scanner;
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
2
13
  Object.defineProperty(exports, "__esModule", { value: true });
3
14
  exports.Description = void 0;
4
15
  require("reflect-metadata");
@@ -24,6 +35,8 @@ const Description = (description) => {
24
35
  return;
25
36
  }
26
37
  // Parameter
38
+ const _a = Reflect.getMetadata(env_1.ARGS_METADATA, target.constructor, propertyKey) || {}, _b = descriptorOrIndex, options = _a[_b], rest = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]);
39
+ Reflect.defineMetadata(env_1.ARGS_METADATA, Object.assign(Object.assign({}, rest), { [descriptorOrIndex]: Object.assign(Object.assign({}, options || {}), { description }) }), target.constructor, propertyKey);
27
40
  Reflect.defineMetadata(env_1.DESCRIPTION_METADATA, Object.assign(Object.assign({}, Reflect.getMetadata(env_1.DESCRIPTION_METADATA, target.constructor, propertyKey) || {}), { [descriptorOrIndex]: description }), target.constructor, propertyKey);
28
41
  };
29
42
  };
@@ -1,9 +1,2 @@
1
- import { MODULE_METADATA } from "../env";
2
- import { ProviderType } from "../types/ProviderType";
3
- export type ModuleMetadata = {
4
- [MODULE_METADATA.CONTROLLERS]?: any[];
5
- [MODULE_METADATA.PROVIDERS]?: ProviderType[];
6
- [MODULE_METADATA.IMPORTS]?: any[];
7
- [MODULE_METADATA.EXPORTS]?: any[];
8
- };
1
+ import { ModuleMetadata } from "../types";
9
2
  export declare const Module: (config: ModuleMetadata) => ClassDecorator;
@@ -1,22 +1,35 @@
1
1
  "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
2
13
  Object.defineProperty(exports, "__esModule", { value: true });
3
14
  exports.Option = void 0;
4
15
  require("reflect-metadata");
5
16
  const env_1 = require("../env");
6
17
  const Option = (name, aliasOrParams) => {
7
- return (target, key, index) => {
8
- if (!key) {
18
+ return (target, propertyKey, parameterIndex) => {
19
+ if (!propertyKey) {
9
20
  return;
10
21
  }
11
- Reflect.defineMetadata(env_1.ARGS_METADATA, [
22
+ const _a = Reflect.getMetadata(env_1.ARGS_METADATA, target.constructor, propertyKey) || {}, _b = parameterIndex, options = _a[_b], rest = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]);
23
+ Reflect.defineMetadata(env_1.ARGS_METADATA, Object.assign(Object.assign({}, rest), { [parameterIndex]: Object.assign(Object.assign({}, options || {}), { type: "option", name, params: typeof aliasOrParams === "string" ? { alias: aliasOrParams } : aliasOrParams, index: parameterIndex }) }), target.constructor, propertyKey);
24
+ Reflect.defineMetadata(env_1.ARGS_METADATA_OLD, [
12
25
  {
13
26
  type: "option",
14
27
  name,
15
28
  params: typeof aliasOrParams === "string" ? { alias: aliasOrParams } : aliasOrParams,
16
- index
29
+ index: parameterIndex
17
30
  },
18
- ...Reflect.getMetadata(env_1.ARGS_METADATA, target.constructor, key) || []
19
- ], target.constructor, key);
31
+ ...Reflect.getMetadata(env_1.ARGS_METADATA_OLD, target.constructor, propertyKey) || []
32
+ ], target.constructor, propertyKey);
20
33
  };
21
34
  };
22
35
  exports.Option = Option;
@@ -0,0 +1 @@
1
+ export declare const Optional: () => ParameterDecorator;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Optional = void 0;
4
+ const env_1 = require("../env");
5
+ const Optional = () => {
6
+ return (target, propertyKey, parameterIndex) => {
7
+ const metadata = propertyKey
8
+ ? Reflect.getMetadata(env_1.ARGS_METADATA, target.constructor, propertyKey) || {}
9
+ : Reflect.getMetadata(env_1.ARGS_METADATA, target) || {};
10
+ if (!metadata[parameterIndex]) {
11
+ metadata[parameterIndex] = {};
12
+ }
13
+ metadata[parameterIndex] = Object.assign(Object.assign({}, metadata[parameterIndex]), { optional: true });
14
+ if (propertyKey) {
15
+ Reflect.defineMetadata(env_1.ARGS_METADATA, metadata, target.constructor, propertyKey);
16
+ }
17
+ else {
18
+ Reflect.defineMetadata(env_1.ARGS_METADATA, metadata, target);
19
+ }
20
+ };
21
+ };
22
+ exports.Optional = Optional;
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
2
13
  Object.defineProperty(exports, "__esModule", { value: true });
3
14
  exports.Param = void 0;
4
15
  const env_1 = require("../env");
@@ -7,8 +18,10 @@ const Param = (name) => {
7
18
  if (!propertyKey) {
8
19
  return;
9
20
  }
10
- Reflect.defineMetadata(env_1.ARGS_METADATA, [
11
- ...Reflect.getMetadata(env_1.ARGS_METADATA, target.constructor, propertyKey) || [],
21
+ const _a = Reflect.getMetadata(env_1.ARGS_METADATA, target.constructor, propertyKey) || {}, _b = parameterIndex, options = _a[_b], rest = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]);
22
+ Reflect.defineMetadata(env_1.ARGS_METADATA, Object.assign(Object.assign({}, rest), { [parameterIndex]: Object.assign(Object.assign({}, options || {}), { type: "param", name, index: parameterIndex }) }), target.constructor, propertyKey);
23
+ Reflect.defineMetadata(env_1.ARGS_METADATA_OLD, [
24
+ ...Reflect.getMetadata(env_1.ARGS_METADATA_OLD, target.constructor, propertyKey) || [],
12
25
  {
13
26
  type: "param",
14
27
  name,
@@ -1,7 +1,2 @@
1
- import { ModuleMetadata } from "./Module";
2
- import { PLUGIN_NAME_METADATA } from "../env";
3
- type PluginConfig = ModuleMetadata & {
4
- [PLUGIN_NAME_METADATA]: string;
5
- };
6
- export declare const Plugin: (config: PluginConfig) => ClassDecorator;
7
- export {};
1
+ import { PluginMetadata } from "../types";
2
+ export declare const Plugin: (config: PluginMetadata) => ClassDecorator;
@@ -12,13 +12,15 @@ var __rest = (this && this.__rest) || function (s, e) {
12
12
  };
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
14
  exports.Plugin = void 0;
15
+ const Global_1 = require("./Global");
15
16
  const Module_1 = require("./Module");
16
17
  const env_1 = require("../env");
17
18
  const Plugin = (config) => {
18
- const { name } = config, rest = __rest(config, ["name"]);
19
+ const _a = config, _b = env_1.PLUGIN_NAME_METADATA, name = _a[_b], rest = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]);
19
20
  return (target) => {
20
21
  Reflect.defineMetadata("isPlugin", true, target);
21
22
  Reflect.defineMetadata(env_1.PLUGIN_NAME_METADATA, name, target);
23
+ (0, Global_1.Global)()(target);
22
24
  (0, Module_1.Module)(rest)(target);
23
25
  };
24
26
  };
@@ -7,10 +7,6 @@ export * from "./Inject";
7
7
  export * from "./Injectable";
8
8
  export * from "./Module";
9
9
  export * from "./Option";
10
+ export * from "./Optional";
10
11
  export * from "./Param";
11
12
  export * from "./Plugin";
12
- export type {
13
- /**
14
- * @deprecated
15
- */
16
- ModuleMetadata as ModuleConfig } from "./Module";
@@ -23,5 +23,6 @@ __exportStar(require("./Inject"), exports);
23
23
  __exportStar(require("./Injectable"), exports);
24
24
  __exportStar(require("./Module"), exports);
25
25
  __exportStar(require("./Option"), exports);
26
+ __exportStar(require("./Optional"), exports);
26
27
  __exportStar(require("./Param"), exports);
27
28
  __exportStar(require("./Plugin"), exports);