@wocker/core 1.0.17-dev.0 → 1.0.17-dev.2

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.
@@ -0,0 +1,2 @@
1
+ import "reflect-metadata";
2
+ export declare const Global: () => ClassDecorator;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Global = void 0;
4
+ require("reflect-metadata");
5
+ const env_1 = require("../env");
6
+ const Global = () => {
7
+ return (target) => {
8
+ Reflect.defineMetadata(env_1.IS_GLOBAL_METADATA, true, target);
9
+ };
10
+ };
11
+ exports.Global = Global;
@@ -2,6 +2,7 @@ export * from "./Command";
2
2
  export * from "./Completion";
3
3
  export * from "./Controller";
4
4
  export * from "./Description";
5
+ export * from "./Global";
5
6
  export * from "./Inject";
6
7
  export * from "./Injectable";
7
8
  export * from "./Module";
@@ -18,6 +18,7 @@ __exportStar(require("./Command"), exports);
18
18
  __exportStar(require("./Completion"), exports);
19
19
  __exportStar(require("./Controller"), exports);
20
20
  __exportStar(require("./Description"), exports);
21
+ __exportStar(require("./Global"), exports);
21
22
  __exportStar(require("./Inject"), exports);
22
23
  __exportStar(require("./Injectable"), exports);
23
24
  __exportStar(require("./Module"), exports);
package/lib/env.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export declare const IS_GLOBAL_METADATA = "IS_GLOBAL";
1
2
  export declare const IS_MODULE_METADATA = "isModule";
2
3
  export declare const INJECTABLE_WATERMARK = "__injectable__";
3
4
  export declare const ARGS_META = "__ARGS__";
package/lib/env.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MODULE_METADATA = exports.PLUGIN_NAME_METADATA = exports.PLUGIN_DIR_KEY = exports.INJECT_TOKEN_METADATA = exports.SELF_DECLARED_DEPS_METADATA = exports.PARAMTYPES_METADATA = exports.OPTION_META = exports.ARGS_METADATA = exports.COMPLETION_METADATA = exports.COMMAND_DESCRIPTION_METADATA = exports.COMMAND_METADATA = exports.ARGS_META = exports.INJECTABLE_WATERMARK = exports.IS_MODULE_METADATA = void 0;
3
+ exports.MODULE_METADATA = exports.PLUGIN_NAME_METADATA = exports.PLUGIN_DIR_KEY = exports.INJECT_TOKEN_METADATA = exports.SELF_DECLARED_DEPS_METADATA = exports.PARAMTYPES_METADATA = exports.OPTION_META = exports.ARGS_METADATA = exports.COMPLETION_METADATA = exports.COMMAND_DESCRIPTION_METADATA = exports.COMMAND_METADATA = exports.ARGS_META = exports.INJECTABLE_WATERMARK = exports.IS_MODULE_METADATA = exports.IS_GLOBAL_METADATA = void 0;
4
+ exports.IS_GLOBAL_METADATA = "IS_GLOBAL";
4
5
  exports.IS_MODULE_METADATA = "isModule";
5
6
  exports.INJECTABLE_WATERMARK = "__injectable__";
6
7
  exports.ARGS_META = "__ARGS__";
@@ -1,5 +1,5 @@
1
- import { Type } from "../types/Type";
2
1
  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,7 +1,12 @@
1
+ import { InstanceWrapper } from "./InstanceWrapper";
1
2
  import { Module } from "./Module";
3
+ import { InjectionToken } from "../types/InjectionToken";
4
+ import { Type } from "../types/Type";
2
5
  export declare class Container {
3
- modules: Map<any, Module>;
4
- hasModule(type: any): boolean;
5
- getModule(type: any): Module | undefined;
6
- addModule(type: any, module: Module): void;
6
+ readonly modules: Map<Type, Module>;
7
+ readonly providers: Map<InjectionToken, InstanceWrapper>;
8
+ constructor();
9
+ addModule<TInput = any>(type: Type<TInput>, module: Module): void;
10
+ hasModule<TInput = any>(type: Type<TInput>): boolean;
11
+ getModule<TInput = any>(type: Type<TInput>): Module<TInput>;
7
12
  }
@@ -1,27 +1,28 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Container = void 0;
4
+ const cli_1 = require("@kearisp/cli");
5
+ const InstanceWrapper_1 = require("./InstanceWrapper");
6
+ const Module_1 = require("./Module");
4
7
  class Container {
5
8
  constructor() {
6
9
  this.modules = new Map();
7
- // public addController(moduleType: any, type: any): void {
8
- // const module = this.getModule(moduleType);
9
- //
10
- // if(!module) {
11
- // return;
12
- // }
13
- //
14
- // module.addController(type);
15
- // }
10
+ this.providers = new Map();
11
+ const cliWrapper = new InstanceWrapper_1.InstanceWrapper(new Module_1.Module(this, null), cli_1.Cli);
12
+ this.providers.set(cli_1.Cli, cliWrapper);
13
+ }
14
+ addModule(type, module) {
15
+ this.modules.set(type, module);
16
16
  }
17
17
  hasModule(type) {
18
18
  return this.modules.has(type);
19
19
  }
20
20
  getModule(type) {
21
- return this.modules.get(type);
22
- }
23
- addModule(type, module) {
24
- this.modules.set(type, module);
21
+ const module = this.modules.get(type);
22
+ if (!module) {
23
+ throw new Error("Module not found");
24
+ }
25
+ return module;
25
26
  }
26
27
  }
27
28
  exports.Container = Container;
@@ -1,19 +1,4 @@
1
1
  import { ApplicationContext } from "./ApplicationContext";
2
- import { Container } from "./Container";
3
- import { Module } from "./Module";
4
2
  export declare class Factory {
5
- private readonly cli;
6
- private readonly container;
7
- private routes;
8
- private constructor();
9
- scan(moduleType: any): Promise<void>;
10
- scanModules(moduleType: any, parent?: Module): Promise<Module | undefined>;
11
- scanDependencies(): Promise<void>;
12
- scanModuleDependencies(module: Module): Promise<void>;
13
- scanDynamicModules(): Promise<void>;
14
- scanRoutes(): Promise<void>;
15
- init(): Promise<void>;
16
- run(args: string[]): Promise<string>;
17
- getContainer(): Container;
18
3
  static create(module: any): Promise<ApplicationContext>;
19
4
  }
@@ -10,196 +10,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.Factory = void 0;
13
- const cli_1 = require("@kearisp/cli");
14
13
  const ApplicationContext_1 = require("./ApplicationContext");
15
- const Container_1 = require("./Container");
16
- const Module_1 = require("./Module");
17
- const env_1 = require("../env");
14
+ const Scanner_1 = require("./Scanner");
18
15
  class Factory {
19
- constructor() {
20
- this.routes = [];
21
- this.container = new Container_1.Container();
22
- this.cli = new cli_1.Cli();
23
- }
24
- scan(moduleType) {
25
- return __awaiter(this, void 0, void 0, function* () {
26
- if (this.container.modules.has(moduleType)) {
27
- return;
28
- }
29
- yield this.scanModules(moduleType);
30
- yield this.scanDependencies();
31
- yield this.scanDynamicModules();
32
- yield this.scanRoutes();
33
- yield this.init();
34
- });
35
- }
36
- scanModules(moduleType, parent) {
37
- return __awaiter(this, void 0, void 0, function* () {
38
- if (this.container.hasModule(moduleType)) {
39
- return;
40
- }
41
- const module = new Module_1.Module(moduleType, parent);
42
- this.container.addModule(moduleType, module);
43
- const modules = Reflect.getMetadata(env_1.MODULE_METADATA.IMPORTS, moduleType) || [];
44
- for (const subModuleType of modules) {
45
- yield this.scanModules(subModuleType, module);
46
- }
47
- // const exports = Reflect.getMetadata(MODULE_METADATA.EXPORTS, moduleType) || [];
48
- return module;
49
- });
50
- }
51
- scanDependencies() {
52
- return __awaiter(this, void 0, void 0, function* () {
53
- for (const [, module] of this.container.modules) {
54
- yield this.scanModuleDependencies(module);
55
- }
56
- });
57
- }
58
- scanModuleDependencies(module) {
59
- return __awaiter(this, void 0, void 0, function* () {
60
- const providers = Reflect.getMetadata(env_1.MODULE_METADATA.PROVIDERS, module.type) || [];
61
- // Logger.info(module.type.name, providers);
62
- module.addProvider(cli_1.Cli, this.cli);
63
- providers.forEach((providerType) => {
64
- // Logger.info(" ->", (providerType as any).name);
65
- module.addProvider(providerType);
66
- });
67
- const controllers = Reflect.getMetadata(env_1.MODULE_METADATA.CONTROLLERS, module.type) || [];
68
- controllers.forEach((controller) => {
69
- module.addController(controller);
70
- });
71
- });
72
- }
73
- scanDynamicModules() {
74
- return __awaiter(this, void 0, void 0, function* () {
75
- for (const [moduleType, module] of this.container.modules) {
76
- if (moduleType.prototype.load) {
77
- const { imports } = yield moduleType.prototype.load(this.container);
78
- for (const type of imports) {
79
- const isModule = Reflect.getMetadata(env_1.IS_MODULE_METADATA, type);
80
- if (!isModule) {
81
- continue;
82
- }
83
- const subModule = yield this.scanModules(type, module);
84
- if (subModule) {
85
- yield this.scanModuleDependencies(subModule);
86
- }
87
- }
88
- }
89
- }
90
- });
91
- }
92
- scanRoutes() {
93
- return __awaiter(this, void 0, void 0, function* () {
94
- for (const [, module] of this.container.modules) {
95
- for (const [type, controller] of module.controllers) {
96
- const controllerCommands = [];
97
- const controllerCompletions = [];
98
- for (const name of Object.getOwnPropertyNames(type.prototype)) {
99
- const descriptor = Object.getOwnPropertyDescriptor(type.prototype, name);
100
- if (!descriptor) {
101
- continue;
102
- }
103
- const commandName = Reflect.getMetadata(env_1.COMMAND_METADATA, descriptor.value);
104
- const completions = (Reflect.getMetadata(env_1.COMPLETION_METADATA, descriptor.value) || [])
105
- .map((completion) => {
106
- return Object.assign(Object.assign({}, completion), { method: name });
107
- });
108
- if (completions.length > 0) {
109
- controllerCompletions.push(...completions);
110
- }
111
- if (commandName) {
112
- controllerCommands.push({
113
- command: commandName,
114
- controller,
115
- method: name,
116
- argsMeta: Reflect.getMetadata(env_1.ARGS_METADATA, type, name) || []
117
- });
118
- const argsMeta = Reflect.getMetadata(env_1.ARGS_METADATA, type, name) || [];
119
- const command = this.cli.command(commandName);
120
- command.help({
121
- description: "Des"
122
- });
123
- for (const argMeta of argsMeta) {
124
- if (argMeta.type === "option") {
125
- command.option(argMeta.name, argMeta.params);
126
- }
127
- }
128
- // command.action((options, ...params) => {
129
- // const args: any[] = [];
130
- //
131
- // argsMeta.forEach((argMeta: any) => {
132
- // if(argMeta.type === "option") {
133
- // args[argMeta.index] = options[argMeta.name];
134
- // }
135
- // });
136
- //
137
- // return controller.instance[name](...args, ...params);
138
- // });
139
- }
140
- }
141
- for (const controllerCommand of controllerCommands) {
142
- const { command: commandName, method, argsMeta } = controllerCommand;
143
- this.cli.command(commandName)
144
- .action((input) => {
145
- const args = [];
146
- const params = Object.values(input.arguments());
147
- argsMeta.forEach((argMeta) => {
148
- if (argMeta.type === "param") {
149
- args[argMeta.index] = input.argument(argMeta.name);
150
- }
151
- else if (argMeta.type === "option") {
152
- args[argMeta.index] = input.option(argMeta.name);
153
- }
154
- });
155
- return controller.instance[method](...args, ...params);
156
- });
157
- }
158
- for (const controllerCompletion of controllerCompletions) {
159
- const { name, command: commandName, method } = controllerCompletion;
160
- if (!commandName) {
161
- for (const route of controllerCommands) {
162
- const { command } = route;
163
- this.cli.command(command).completion(name, () => {
164
- return controller.instance[method]();
165
- });
166
- }
167
- }
168
- else {
169
- this.cli.command(commandName).completion(name, () => {
170
- return controller.instance[method]();
171
- });
172
- }
173
- }
174
- }
175
- }
176
- });
177
- }
178
- init() {
179
- return __awaiter(this, void 0, void 0, function* () {
180
- for (const [, module] of this.container.modules) {
181
- module.providers.forEach((provider) => {
182
- provider.instance;
183
- });
184
- module.controllers.forEach((controller) => {
185
- controller.instance;
186
- });
187
- }
188
- });
189
- }
190
- run(args) {
191
- return __awaiter(this, void 0, void 0, function* () {
192
- return this.cli.run(args);
193
- });
194
- }
195
- getContainer() {
196
- return this.container;
197
- }
198
16
  static create(module) {
199
17
  return __awaiter(this, void 0, void 0, function* () {
200
- const factory = new this();
201
- yield factory.scan(module);
202
- return new ApplicationContext_1.ApplicationContext(module, factory.getContainer());
18
+ const scanner = new Scanner_1.Scanner();
19
+ yield scanner.scan(module);
20
+ return new ApplicationContext_1.ApplicationContext(module, scanner.container);
203
21
  });
204
22
  }
205
23
  }
@@ -1,10 +1,14 @@
1
1
  import "reflect-metadata";
2
2
  import { Module } from "./Module";
3
- export declare class InstanceWrapper {
3
+ import { Provider } from "../types/Provider";
4
+ import { Type } from "../types/Type";
5
+ import { InjectionToken } from "../types/InjectionToken";
6
+ export declare class InstanceWrapper<TInput = any> {
4
7
  private readonly module;
5
8
  private readonly provider;
6
- private _instance?;
7
- constructor(module: Module, provider: any, _instance?: any);
8
- get instance(): any;
9
- set instance(instance: any);
9
+ protected _instance?: TInput | undefined;
10
+ readonly token: InjectionToken<TInput>;
11
+ readonly type?: Type<TInput>;
12
+ constructor(module: Module, provider: Provider<TInput>, _instance?: TInput | undefined);
13
+ get instance(): TInput | undefined;
10
14
  }
@@ -8,31 +8,34 @@ class InstanceWrapper {
8
8
  this.module = module;
9
9
  this.provider = provider;
10
10
  this._instance = _instance;
11
+ if ("provide" in this.provider && "useValue" in this.provider) {
12
+ this.token = this.provider.provide;
13
+ this._instance = this.provider.useValue;
14
+ return;
15
+ }
16
+ if ("provide" in this.provider && "useClass" in this.provider) {
17
+ this.token = this.provider.provide;
18
+ this.type = this.provider.useClass;
19
+ return;
20
+ }
21
+ this.token = Reflect.getMetadata(env_1.INJECT_TOKEN_METADATA, this.provider) || this.provider;
22
+ this.type = this.provider;
11
23
  }
12
24
  get instance() {
13
- if (!this._instance) {
14
- const types = [
15
- ...Reflect.getMetadata(env_1.PARAMTYPES_METADATA, this.provider) || []
16
- ];
17
- const selfTypes = Reflect.getMetadata(env_1.SELF_DECLARED_DEPS_METADATA, this.provider) || [];
25
+ if (!this._instance && this.type) {
26
+ const types = Reflect.getMetadata(env_1.PARAMTYPES_METADATA, this.type) || [];
27
+ const selfTypes = Reflect.getMetadata(env_1.SELF_DECLARED_DEPS_METADATA, this.type) || [];
18
28
  if (selfTypes.length > 0) {
19
29
  selfTypes.forEach(({ index, token }) => {
20
30
  types[index] = token;
21
31
  });
22
32
  }
23
33
  const params = types.map((type) => {
24
- const wrapper = this.module.getWrapper(type);
25
- if (!wrapper) {
26
- return undefined;
27
- }
28
- return wrapper.instance;
34
+ return this.module.get(type);
29
35
  });
30
- this._instance = new this.provider(...params);
36
+ this._instance = new this.type(...params);
31
37
  }
32
38
  return this._instance;
33
39
  }
34
- set instance(instance) {
35
- this._instance = instance;
36
- }
37
40
  }
38
41
  exports.InstanceWrapper = InstanceWrapper;
@@ -7,15 +7,27 @@ class Logger {
7
7
  loggerService = ls;
8
8
  }
9
9
  static log(...data) {
10
+ if (!loggerService) {
11
+ return;
12
+ }
10
13
  loggerService.log(...data);
11
14
  }
12
15
  static info(...data) {
16
+ if (!loggerService) {
17
+ return;
18
+ }
13
19
  loggerService.info(...data);
14
20
  }
15
21
  static warn(...data) {
22
+ if (!loggerService) {
23
+ return;
24
+ }
16
25
  loggerService.warn(...data);
17
26
  }
18
27
  static error(...data) {
28
+ if (!loggerService) {
29
+ return;
30
+ }
19
31
  loggerService.error(...data);
20
32
  }
21
33
  }
@@ -1,17 +1,22 @@
1
1
  import { Provider } from "../types/Provider";
2
+ import { Type } from "../types/Type";
3
+ import { Container } from "./Container";
2
4
  import { InstanceWrapper } from "./InstanceWrapper";
3
- export declare class Module {
4
- type: any;
5
+ export declare class Module<TInput = any> {
6
+ readonly container: Container;
7
+ type: TInput;
5
8
  parent?: Module | undefined;
6
- imports: Set<any>;
9
+ imports: Map<any, InstanceWrapper>;
7
10
  controllers: Map<any, InstanceWrapper>;
8
11
  providers: Map<any, InstanceWrapper>;
9
- exports: Map<any, any>;
10
- constructor(type: any, parent?: Module | undefined);
11
- get<T = any>(type: any): T;
12
+ exports: Set<any>;
13
+ constructor(container: Container, type: TInput, parent?: Module | undefined);
14
+ get<TInput = any, TResult = TInput>(type: Type<TInput> | Function | string | symbol): TResult;
12
15
  getWrapper(type: any): InstanceWrapper | undefined;
13
16
  addImport(module: any): void;
14
17
  addProvider(provider: Provider, instance?: any): void;
18
+ getProvider(): void;
15
19
  addInjection(): void;
16
20
  addController(type: any): void;
21
+ addExport(type: any): void;
17
22
  }
@@ -4,13 +4,14 @@ exports.Module = void 0;
4
4
  const InstanceWrapper_1 = require("./InstanceWrapper");
5
5
  const env_1 = require("../env");
6
6
  class Module {
7
- constructor(type, parent) {
7
+ constructor(container, type, parent) {
8
+ this.container = container;
8
9
  this.type = type;
9
10
  this.parent = parent;
10
- this.imports = new Set();
11
+ this.imports = new Map();
11
12
  this.controllers = new Map();
12
13
  this.providers = new Map();
13
- this.exports = new Map();
14
+ this.exports = new Set();
14
15
  }
15
16
  get(type) {
16
17
  const wrapper = this.getWrapper(type);
@@ -27,25 +28,20 @@ class Module {
27
28
  if (!wrapper && this.parent) {
28
29
  return this.parent.getWrapper(type);
29
30
  }
31
+ if (!wrapper) {
32
+ return this.container.providers.get(type);
33
+ }
30
34
  return wrapper;
31
35
  }
32
36
  addImport(module) {
33
- this.imports.add(module);
37
+ // this.imports.add(module);
34
38
  }
35
39
  addProvider(provider, instance) {
36
- if ("provide" in provider && "useValue" in provider) {
37
- const wrapper = new InstanceWrapper_1.InstanceWrapper(this, provider.provide, provider.useValue);
38
- this.providers.set(provider.provide, wrapper);
39
- return;
40
- }
41
- if ("provide" in provider && "useClass" in provider) {
42
- const wrapper = new InstanceWrapper_1.InstanceWrapper(this, provider.useClass);
43
- this.providers.set(provider.provide, wrapper);
44
- return;
45
- }
46
- const token = Reflect.getMetadata("INJECT_TOKEN", provider) || provider;
47
40
  const wrapper = new InstanceWrapper_1.InstanceWrapper(this, provider, instance);
48
- this.providers.set(token, wrapper);
41
+ this.providers.set(wrapper.token, wrapper);
42
+ }
43
+ getProvider() {
44
+ //
49
45
  }
50
46
  addInjection() {
51
47
  //
@@ -64,5 +60,8 @@ class Module {
64
60
  // console.log(">", name, command);
65
61
  }
66
62
  }
63
+ addExport(type) {
64
+ this.exports.add(type);
65
+ }
67
66
  }
68
67
  exports.Module = Module;
@@ -1,4 +1,15 @@
1
+ import "reflect-metadata";
2
+ import { Container } from "./Container";
3
+ import { Module } from "./Module";
1
4
  export declare class Scanner {
5
+ readonly container: Container;
2
6
  constructor();
3
- scan(module: any): void;
7
+ scan(moduleType: any): Promise<void>;
8
+ protected scanModule(moduleType: any): Module;
9
+ protected scanControllers(module: Module): void;
10
+ protected scanProviders(module: Module): void;
11
+ protected scanImports(module: Module): void;
12
+ protected scanExports(module: Module): void;
13
+ protected scanRoutes(): void;
14
+ protected scanDynamicModules(): Promise<void>;
4
15
  }
@@ -1,9 +1,198 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.Scanner = void 0;
13
+ require("reflect-metadata");
14
+ const cli_1 = require("@kearisp/cli");
15
+ const Container_1 = require("./Container");
16
+ const Module_1 = require("./Module");
17
+ const Logger_1 = require("./Logger");
18
+ const env_1 = require("../env");
4
19
  class Scanner {
5
- constructor() { }
6
- scan(module) {
20
+ constructor() {
21
+ this.container = new Container_1.Container();
22
+ }
23
+ scan(moduleType) {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ this.scanModule(moduleType);
26
+ yield this.scanDynamicModules();
27
+ this.scanRoutes();
28
+ });
29
+ }
30
+ scanModule(moduleType) {
31
+ let module = this.container.hasModule(moduleType)
32
+ ? this.container.getModule(moduleType)
33
+ : null;
34
+ if (!module) {
35
+ module = new Module_1.Module(this.container, moduleType);
36
+ this.container.addModule(moduleType, module);
37
+ this.scanImports(module);
38
+ this.scanControllers(module);
39
+ this.scanProviders(module);
40
+ this.scanExports(module);
41
+ }
42
+ return module;
43
+ }
44
+ scanControllers(module) {
45
+ const controllers = Reflect.getMetadata(env_1.MODULE_METADATA.CONTROLLERS, module.type) || [];
46
+ controllers.forEach((controller) => {
47
+ module.addController(controller);
48
+ });
49
+ }
50
+ scanProviders(module) {
51
+ const providers = Reflect.getMetadata(env_1.MODULE_METADATA.PROVIDERS, module.type) || [];
52
+ providers.forEach((provider) => {
53
+ module.addProvider(provider);
54
+ });
55
+ }
56
+ scanImports(module) {
57
+ const imports = Reflect.getMetadata(env_1.MODULE_METADATA.IMPORTS, module.type) || [];
58
+ imports.forEach((importType) => {
59
+ const subModule = this.scanModule(importType);
60
+ subModule.exports.forEach((type) => {
61
+ const provider = subModule.providers.get(type);
62
+ if (!provider) {
63
+ return;
64
+ }
65
+ module.providers.set(type, provider);
66
+ });
67
+ });
68
+ }
69
+ scanExports(module) {
70
+ const exports = Reflect.getMetadata(env_1.MODULE_METADATA.EXPORTS, module.type) || [];
71
+ const isGlobal = Reflect.getMetadata(env_1.IS_GLOBAL_METADATA, module.type) || false;
72
+ exports.forEach((type) => {
73
+ module.addExport(type);
74
+ if (isGlobal) {
75
+ const wrapper = module.getWrapper(type);
76
+ if (wrapper) {
77
+ this.container.providers.set(type, wrapper);
78
+ }
79
+ }
80
+ });
81
+ }
82
+ scanRoutes() {
83
+ const cliWrapper = this.container.providers.get(cli_1.Cli);
84
+ if (!cliWrapper) {
85
+ return;
86
+ }
87
+ const cli = cliWrapper.instance;
88
+ // Logger.unmute();
89
+ Logger_1.Logger.info(">_<");
90
+ for (const [, module] of this.container.modules) {
91
+ for (const [type, controller] of module.controllers) {
92
+ const controllerCommands = [];
93
+ const controllerCompletions = [];
94
+ for (const name of Object.getOwnPropertyNames(type.prototype)) {
95
+ const descriptor = Object.getOwnPropertyDescriptor(type.prototype, name);
96
+ if (!descriptor) {
97
+ continue;
98
+ }
99
+ const description = Reflect.getMetadata(env_1.COMMAND_DESCRIPTION_METADATA, descriptor.value);
100
+ const commandName = Reflect.getMetadata(env_1.COMMAND_METADATA, descriptor.value);
101
+ const completions = (Reflect.getMetadata(env_1.COMPLETION_METADATA, descriptor.value) || [])
102
+ .map((completion) => {
103
+ return Object.assign(Object.assign({}, completion), { method: name });
104
+ });
105
+ if (completions.length > 0) {
106
+ controllerCompletions.push(...completions);
107
+ }
108
+ if (commandName) {
109
+ controllerCommands.push({
110
+ command: commandName,
111
+ controller,
112
+ method: name,
113
+ argsMeta: Reflect.getMetadata(env_1.ARGS_METADATA, type, name) || []
114
+ });
115
+ const argsMeta = Reflect.getMetadata(env_1.ARGS_METADATA, type, name) || [];
116
+ const command = cli.command(commandName);
117
+ command.help({
118
+ description: description
119
+ });
120
+ for (const argMeta of argsMeta) {
121
+ if (argMeta.type === "option") {
122
+ command.option(argMeta.name, argMeta.params);
123
+ }
124
+ }
125
+ // command.action((options, ...params) => {
126
+ // const args: any[] = [];
127
+ //
128
+ // argsMeta.forEach((argMeta: any) => {
129
+ // if(argMeta.type === "option") {
130
+ // args[argMeta.index] = options[argMeta.name];
131
+ // }
132
+ // });
133
+ //
134
+ // return controller.instance[name](...args, ...params);
135
+ // });
136
+ }
137
+ }
138
+ for (const controllerCommand of controllerCommands) {
139
+ const { command: commandName, method, argsMeta } = controllerCommand;
140
+ cli.command(commandName)
141
+ .action((input) => {
142
+ const args = [];
143
+ const params = Object.values(input.arguments());
144
+ argsMeta.forEach((argMeta) => {
145
+ if (argMeta.type === "param") {
146
+ args[argMeta.index] = input.argument(argMeta.name);
147
+ }
148
+ else if (argMeta.type === "option") {
149
+ args[argMeta.index] = input.option(argMeta.name);
150
+ }
151
+ });
152
+ return controller.instance[method](...args, ...params);
153
+ });
154
+ }
155
+ for (const controllerCompletion of controllerCompletions) {
156
+ const { name, command: commandName, method } = controllerCompletion;
157
+ if (!commandName) {
158
+ for (const route of controllerCommands) {
159
+ const { command } = route;
160
+ cli.command(command).completion(name, () => {
161
+ return controller.instance[method]();
162
+ });
163
+ }
164
+ }
165
+ else {
166
+ cli.command(commandName).completion(name, () => {
167
+ return controller.instance[method]();
168
+ });
169
+ }
170
+ }
171
+ }
172
+ }
173
+ }
174
+ scanDynamicModules() {
175
+ return __awaiter(this, void 0, void 0, function* () {
176
+ const promises = ([...this.container.modules.keys()]).map((type) => __awaiter(this, void 0, void 0, function* () {
177
+ if (!type.prototype.load) {
178
+ return;
179
+ }
180
+ const parentModule = this.container.modules.get(type);
181
+ const { [env_1.MODULE_METADATA.IMPORTS]: imports = [] } = yield type.prototype.load(this.container);
182
+ for (const subModuleType of imports) {
183
+ const module = this.scanModule(subModuleType);
184
+ module.exports.forEach((type) => {
185
+ const provider = module.getWrapper(type);
186
+ if (!provider) {
187
+ // console.log(type, ">_<", provider);
188
+ }
189
+ // @ts-ignore
190
+ parentModule.providers.set(type, provider);
191
+ });
192
+ }
193
+ }));
194
+ yield Promise.all(promises);
195
+ });
7
196
  }
8
197
  }
9
198
  exports.Scanner = Scanner;
@@ -1,7 +1,6 @@
1
- type EventHandle = (...args: any[]) => Promise<void> | void;
1
+ export type AppEventHandle = (...args: any[]) => Promise<void> | void;
2
2
  export declare abstract class AppEventsService {
3
- abstract on(event: string, handle: EventHandle): void;
4
- abstract off(event: string, handle: EventHandle): void;
3
+ abstract on(event: string, handle: AppEventHandle): void;
4
+ abstract off(event: string, handle: AppEventHandle): void;
5
5
  abstract emit(event: string, ...args: any[]): Promise<void>;
6
6
  }
7
- export { EventHandle as AppEventHandle };
@@ -0,0 +1,2 @@
1
+ import { Provider } from "../types/Provider";
2
+ export declare const getProviderToken: (provider: Provider) => void;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getProviderToken = void 0;
4
+ const getProviderToken = (provider) => {
5
+ };
6
+ exports.getProviderToken = getProviderToken;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wocker/core",
3
- "version": "1.0.17-dev.0",
3
+ "version": "1.0.17-dev.2",
4
4
  "author": "Kris Papercut <krispcut@gmail.com>",
5
5
  "description": "Core of the Wocker",
6
6
  "license": "MIT",
@@ -25,7 +25,7 @@
25
25
  "test-watch": "jest --colors --watchAll --coverage"
26
26
  },
27
27
  "dependencies": {
28
- "@kearisp/cli": "^2.0.4",
28
+ "@kearisp/cli": "^2.0.5",
29
29
  "fs": "^0.0.1-security",
30
30
  "path": "^0.12.7",
31
31
  "reflect-metadata": "^0.2.2"