@wocker/core 1.0.5 → 1.0.6

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 (73) hide show
  1. package/lib/decorators/Command.d.ts +1 -0
  2. package/lib/decorators/Command.js +10 -0
  3. package/lib/decorators/Completion.d.ts +1 -0
  4. package/lib/decorators/Completion.js +15 -0
  5. package/lib/decorators/Controller.d.ts +5 -0
  6. package/lib/decorators/Controller.js +14 -0
  7. package/lib/decorators/Inject.d.ts +1 -1
  8. package/lib/decorators/Inject.js +10 -2
  9. package/lib/decorators/Injectable.d.ts +1 -4
  10. package/lib/decorators/Injectable.js +7 -12
  11. package/lib/decorators/Module.d.ts +15 -0
  12. package/lib/decorators/Module.js +16 -0
  13. package/lib/decorators/Option.d.ts +4 -0
  14. package/lib/decorators/Option.js +21 -0
  15. package/lib/decorators/Param.d.ts +1 -0
  16. package/lib/decorators/Param.js +8 -0
  17. package/lib/decorators/index.d.ts +7 -0
  18. package/lib/decorators/index.js +23 -0
  19. package/lib/env.d.ts +18 -0
  20. package/lib/env.js +22 -0
  21. package/lib/index.d.ts +5 -18
  22. package/lib/index.js +8 -19
  23. package/lib/makes/Container.d.ts +8 -0
  24. package/lib/makes/Container.js +25 -0
  25. package/lib/makes/FSManager.js +4 -4
  26. package/lib/makes/Factory.d.ts +17 -0
  27. package/lib/makes/Factory.js +201 -0
  28. package/lib/makes/InstanceWrapper.d.ts +10 -0
  29. package/lib/makes/InstanceWrapper.js +41 -0
  30. package/lib/makes/Logger.d.ts +3 -4
  31. package/lib/makes/Logger.js +7 -8
  32. package/lib/makes/Module.d.ts +17 -0
  33. package/lib/makes/Module.js +63 -0
  34. package/lib/makes/Plugin.d.ts +1 -3
  35. package/lib/makes/Plugin.js +2 -3
  36. package/lib/{models → makes}/Preset.d.ts +4 -4
  37. package/lib/{models → makes}/Project.d.ts +7 -9
  38. package/lib/{models → makes}/Project.js +35 -26
  39. package/lib/makes/Scanner.d.ts +4 -0
  40. package/lib/makes/Scanner.js +9 -0
  41. package/lib/makes/index.d.ts +9 -0
  42. package/lib/makes/index.js +25 -0
  43. package/lib/services/AppConfigService.d.ts +1 -1
  44. package/lib/services/AppConfigService.js +12 -2
  45. package/lib/services/AppEventsService.d.ts +2 -2
  46. package/lib/services/AppEventsService.js +12 -2
  47. package/lib/services/DockerService.d.ts +13 -1
  48. package/lib/services/DockerService.js +12 -2
  49. package/lib/services/LogService.d.ts +1 -2
  50. package/lib/services/LogService.js +12 -2
  51. package/lib/services/PluginConfigService.d.ts +5 -0
  52. package/lib/services/PluginConfigService.js +64 -0
  53. package/lib/services/PresetService.d.ts +6 -7
  54. package/lib/services/ProjectService.d.ts +3 -3
  55. package/lib/services/ProjectService.js +14 -4
  56. package/lib/services/index.d.ts +7 -0
  57. package/lib/services/index.js +23 -0
  58. package/lib/types/Abstract.d.ts +3 -0
  59. package/lib/types/Abstract.js +2 -0
  60. package/lib/types/InjectionToken.d.ts +3 -0
  61. package/lib/types/InjectionToken.js +2 -0
  62. package/lib/types/PickProperties.d.ts +3 -0
  63. package/lib/types/PickProperties.js +2 -0
  64. package/lib/types/Provider.d.ts +12 -0
  65. package/lib/types/Provider.js +2 -0
  66. package/lib/types/Type.d.ts +3 -0
  67. package/lib/types/Type.js +2 -0
  68. package/lib/types/index.d.ts +3 -0
  69. package/lib/types/index.js +19 -0
  70. package/package.json +3 -3
  71. package/lib/makes/Controller.d.ts +0 -5
  72. package/lib/makes/Controller.js +0 -9
  73. /package/lib/{models → makes}/Preset.js +0 -0
@@ -0,0 +1 @@
1
+ export declare const Command: (command: string) => MethodDecorator;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Command = void 0;
4
+ const env_1 = require("../env");
5
+ const Command = (command) => {
6
+ return (target, key, descriptor) => {
7
+ Reflect.defineMetadata(env_1.COMMAND_METADATA, command, descriptor.value);
8
+ };
9
+ };
10
+ exports.Command = Command;
@@ -0,0 +1 @@
1
+ export declare const Completion: (name: string, command?: string) => MethodDecorator;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Completion = void 0;
4
+ const Completion = (name, command) => {
5
+ return (target, propertyKey, descriptor) => {
6
+ Reflect.defineMetadata("completion", [
7
+ ...Reflect.getMetadata("completion", descriptor.value) || [],
8
+ {
9
+ name,
10
+ command
11
+ }
12
+ ], descriptor.value);
13
+ };
14
+ };
15
+ exports.Completion = Completion;
@@ -0,0 +1,5 @@
1
+ type Params = {
2
+ command?: string;
3
+ };
4
+ export declare const Controller: (params?: Params) => ClassDecorator;
5
+ export {};
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Controller = void 0;
4
+ const Controller = (params) => {
5
+ const { command } = params || {};
6
+ return (target) => {
7
+ if (!command) {
8
+ return;
9
+ }
10
+ Reflect.defineMetadata("IS_CONTROLLER", true, target);
11
+ // TODO:
12
+ };
13
+ };
14
+ exports.Controller = Controller;
@@ -1 +1 @@
1
- export declare const Inject: () => (target: any) => void;
1
+ export declare const Inject: <T = any>(token?: T) => ParameterDecorator;
@@ -1,8 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Inject = void 0;
4
- const Inject = () => {
5
- return (target) => {
4
+ const env_1 = require("../env");
5
+ const Inject = (token) => {
6
+ return (target, propertyKey, parameterIndex) => {
7
+ Reflect.defineMetadata(env_1.SELF_DECLARED_DEPS_METADATA, [
8
+ ...Reflect.getMetadata(env_1.SELF_DECLARED_DEPS_METADATA, target) || [],
9
+ {
10
+ token: token,
11
+ index: parameterIndex
12
+ }
13
+ ], target);
6
14
  };
7
15
  };
8
16
  exports.Inject = Inject;
@@ -1,4 +1 @@
1
- import { DI } from "../makes/DI";
2
- export declare const Injectable: () => <T extends new (...rest: any[]) => {}>(Target: T) => {
3
- new (di: DI): {};
4
- } & T;
1
+ export declare const Injectable: (token?: string) => ClassDecorator;
@@ -1,18 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Injectable = void 0;
4
- const Injectable = () => {
5
- return (Target) => {
6
- // @ts-ignore
7
- return class extends Target {
8
- constructor(di) {
9
- const types = Reflect.getMetadata("design:paramtypes", Target);
10
- const params = types.map((type) => {
11
- return (di).resolveService(type);
12
- });
13
- super(...params);
14
- }
15
- };
4
+ const env_1 = require("../env");
5
+ const Injectable = (token) => {
6
+ return (target) => {
7
+ Reflect.defineMetadata(env_1.INJECTABLE_WATERMARK, true, target);
8
+ if (token) {
9
+ Reflect.defineMetadata(env_1.INJECT_TOKEN_METADATA, token, target);
10
+ }
16
11
  };
17
12
  };
18
13
  exports.Injectable = Injectable;
@@ -0,0 +1,15 @@
1
+ import { MODULE_METADATA } from "../env";
2
+ import { Provider } from "../types/Provider";
3
+ import { Type } from "../types/Type";
4
+ type Config = {
5
+ [MODULE_METADATA.NAME]?: string;
6
+ [MODULE_METADATA.CONTROLLERS]?: any[];
7
+ [MODULE_METADATA.PROVIDERS]?: Provider[];
8
+ [MODULE_METADATA.IMPORTS]?: any[];
9
+ [MODULE_METADATA.EXPORTS]?: any[];
10
+ };
11
+ export type DynamicModule = {
12
+ providers?: any[];
13
+ };
14
+ export declare const Module: (config: Config) => <T extends Type>(Target: T) => void;
15
+ export {};
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Module = void 0;
4
+ const env_1 = require("../env");
5
+ const Module = (config) => {
6
+ const { [env_1.MODULE_METADATA.NAME]: name, [env_1.MODULE_METADATA.CONTROLLERS]: controllers = [], [env_1.MODULE_METADATA.PROVIDERS]: providers = [], [env_1.MODULE_METADATA.IMPORTS]: imports = [], [env_1.MODULE_METADATA.EXPORTS]: exports = [] } = config;
7
+ return (Target) => {
8
+ Reflect.defineMetadata("isModule", true, Target);
9
+ Reflect.defineMetadata(env_1.MODULE_METADATA.NAME, name, Target);
10
+ Reflect.defineMetadata(env_1.MODULE_METADATA.IMPORTS, imports, Target);
11
+ Reflect.defineMetadata(env_1.MODULE_METADATA.CONTROLLERS, controllers, Target);
12
+ Reflect.defineMetadata(env_1.MODULE_METADATA.PROVIDERS, providers, Target);
13
+ Reflect.defineMetadata(env_1.MODULE_METADATA.EXPORTS, exports, Target);
14
+ };
15
+ };
16
+ exports.Module = Module;
@@ -0,0 +1,4 @@
1
+ import { Option as O } from "@kearisp/cli";
2
+ type Params = Omit<O, "name">;
3
+ export declare const Option: (name: string, params?: Partial<Params>) => ParameterDecorator;
4
+ export {};
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Option = void 0;
4
+ const env_1 = require("../env");
5
+ const Option = (name, params) => {
6
+ return (target, key, index) => {
7
+ if (!key) {
8
+ return;
9
+ }
10
+ Reflect.defineMetadata(env_1.ARGS_METADATA, [
11
+ ...Reflect.getMetadata(env_1.ARGS_METADATA, target.constructor, key) || [],
12
+ {
13
+ type: "option",
14
+ name,
15
+ params,
16
+ index
17
+ }
18
+ ], target.constructor, key);
19
+ };
20
+ };
21
+ exports.Option = Option;
@@ -0,0 +1 @@
1
+ export declare const Param: (name: string) => MethodDecorator;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Param = void 0;
4
+ const Param = (name) => {
5
+ return (target, propertyKey, descriptor) => {
6
+ };
7
+ };
8
+ exports.Param = Param;
@@ -0,0 +1,7 @@
1
+ export * from "./Command";
2
+ export * from "./Completion";
3
+ export * from "./Controller";
4
+ export * from "./Inject";
5
+ export * from "./Injectable";
6
+ export * from "./Module";
7
+ export * from "./Option";
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./Command"), exports);
18
+ __exportStar(require("./Completion"), exports);
19
+ __exportStar(require("./Controller"), exports);
20
+ __exportStar(require("./Inject"), exports);
21
+ __exportStar(require("./Injectable"), exports);
22
+ __exportStar(require("./Module"), exports);
23
+ __exportStar(require("./Option"), exports);
package/lib/env.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ export declare const IS_MODULE = "IS_MODULE";
2
+ export declare const INJECTABLE_WATERMARK = "__injectable__";
3
+ export declare const ARGS_META = "__ARGS__";
4
+ export declare const COMMAND_METADATA = "command";
5
+ export declare const COMPLETION_METADATA = "completion";
6
+ export declare const ARGS_METADATA = "__ARGS__";
7
+ export declare const OPTION_META = "__OPTION_META__";
8
+ export declare const PARAMTYPES_METADATA = "design:paramtypes";
9
+ export declare const SELF_DECLARED_DEPS_METADATA = "self:paramtypes";
10
+ export declare const INJECT_TOKEN_METADATA = "INJECT_TOKEN";
11
+ export declare const PLUGIN_DIR_KEY = "PLUGIN_DIR";
12
+ export declare enum MODULE_METADATA {
13
+ NAME = "name",
14
+ IMPORTS = "imports",
15
+ EXPORTS = "exports",
16
+ CONTROLLERS = "controllers",
17
+ PROVIDERS = "providers"
18
+ }
package/lib/env.js ADDED
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MODULE_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_METADATA = exports.ARGS_META = exports.INJECTABLE_WATERMARK = exports.IS_MODULE = void 0;
4
+ exports.IS_MODULE = "IS_MODULE";
5
+ exports.INJECTABLE_WATERMARK = "__injectable__";
6
+ exports.ARGS_META = "__ARGS__";
7
+ exports.COMMAND_METADATA = "command";
8
+ exports.COMPLETION_METADATA = "completion";
9
+ exports.ARGS_METADATA = "__ARGS__";
10
+ exports.OPTION_META = "__OPTION_META__";
11
+ exports.PARAMTYPES_METADATA = "design:paramtypes";
12
+ exports.SELF_DECLARED_DEPS_METADATA = "self:paramtypes";
13
+ exports.INJECT_TOKEN_METADATA = "INJECT_TOKEN";
14
+ exports.PLUGIN_DIR_KEY = "PLUGIN_DIR";
15
+ var MODULE_METADATA;
16
+ (function (MODULE_METADATA) {
17
+ MODULE_METADATA["NAME"] = "name";
18
+ MODULE_METADATA["IMPORTS"] = "imports";
19
+ MODULE_METADATA["EXPORTS"] = "exports";
20
+ MODULE_METADATA["CONTROLLERS"] = "controllers";
21
+ MODULE_METADATA["PROVIDERS"] = "providers";
22
+ })(MODULE_METADATA || (exports.MODULE_METADATA = MODULE_METADATA = {}));
package/lib/index.d.ts CHANGED
@@ -1,19 +1,6 @@
1
1
  export { Cli } from "@kearisp/cli";
2
- export * from "./decorators/Inject";
3
- export * from "./decorators/Injectable";
4
- export * from "./makes/Controller";
5
- export * from "./makes/DI";
6
- export * from "./makes/FS";
7
- export * from "./makes/FSManager";
8
- export * from "./makes/Logger";
9
- export * from "./makes/Plugin";
10
- export * from "./models/Preset";
11
- export * from "./models/Project";
12
- export * from "./services/AppConfigService";
13
- export * from "./services/AppEventsService";
14
- export * from "./services/DockerService";
15
- export * from "./services/LogService";
16
- export * from "./services/PresetService";
17
- export * from "./services/ProjectService";
18
- export * from "./types/AppConfig";
19
- export * from "./types/EnvConfig";
2
+ export * from "./decorators";
3
+ export * from "./makes";
4
+ export * from "./services";
5
+ export * from "./types";
6
+ export { MODULE_METADATA, PLUGIN_DIR_KEY } from "./env";
package/lib/index.js CHANGED
@@ -14,24 +14,13 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.Cli = void 0;
17
+ exports.PLUGIN_DIR_KEY = exports.MODULE_METADATA = exports.Cli = void 0;
18
18
  var cli_1 = require("@kearisp/cli");
19
19
  Object.defineProperty(exports, "Cli", { enumerable: true, get: function () { return cli_1.Cli; } });
20
- __exportStar(require("./decorators/Inject"), exports);
21
- __exportStar(require("./decorators/Injectable"), exports);
22
- __exportStar(require("./makes/Controller"), exports);
23
- __exportStar(require("./makes/DI"), exports);
24
- __exportStar(require("./makes/FS"), exports);
25
- __exportStar(require("./makes/FSManager"), exports);
26
- __exportStar(require("./makes/Logger"), exports);
27
- __exportStar(require("./makes/Plugin"), exports);
28
- __exportStar(require("./models/Preset"), exports);
29
- __exportStar(require("./models/Project"), exports);
30
- __exportStar(require("./services/AppConfigService"), exports);
31
- __exportStar(require("./services/AppEventsService"), exports);
32
- __exportStar(require("./services/DockerService"), exports);
33
- __exportStar(require("./services/LogService"), exports);
34
- __exportStar(require("./services/PresetService"), exports);
35
- __exportStar(require("./services/ProjectService"), exports);
36
- __exportStar(require("./types/AppConfig"), exports);
37
- __exportStar(require("./types/EnvConfig"), exports);
20
+ __exportStar(require("./decorators"), exports);
21
+ __exportStar(require("./makes"), exports);
22
+ __exportStar(require("./services"), exports);
23
+ __exportStar(require("./types"), exports);
24
+ var env_1 = require("./env");
25
+ Object.defineProperty(exports, "MODULE_METADATA", { enumerable: true, get: function () { return env_1.MODULE_METADATA; } });
26
+ Object.defineProperty(exports, "PLUGIN_DIR_KEY", { enumerable: true, get: function () { return env_1.PLUGIN_DIR_KEY; } });
@@ -0,0 +1,8 @@
1
+ import { Module } from "./Module";
2
+ 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;
7
+ addController(moduleType: any, type: any): void;
8
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Container = void 0;
4
+ class Container {
5
+ constructor() {
6
+ this.modules = new Map();
7
+ }
8
+ hasModule(type) {
9
+ return this.modules.has(type);
10
+ }
11
+ getModule(type) {
12
+ return this.modules.get(type);
13
+ }
14
+ addModule(type, module) {
15
+ this.modules.set(type, module);
16
+ }
17
+ addController(moduleType, type) {
18
+ const module = this.getModule(moduleType);
19
+ if (!module) {
20
+ return;
21
+ }
22
+ module.addController(type);
23
+ }
24
+ }
25
+ exports.Container = Container;
@@ -43,8 +43,8 @@ class FSManager {
43
43
  path(...parts) {
44
44
  return Path.join(this.destination, ...parts);
45
45
  }
46
- mkdir(path, options = {}) {
47
- return __awaiter(this, void 0, void 0, function* () {
46
+ mkdir(path_1) {
47
+ return __awaiter(this, arguments, void 0, function* (path, options = {}) {
48
48
  const fullPath = Path.join(this.destination, path);
49
49
  return new Promise((resolve, reject) => {
50
50
  (0, fs_1.mkdir)(fullPath, options, (err) => {
@@ -120,8 +120,8 @@ class FSManager {
120
120
  });
121
121
  });
122
122
  }
123
- rm(path, options = {}) {
124
- return __awaiter(this, void 0, void 0, function* () {
123
+ rm(path_1) {
124
+ return __awaiter(this, arguments, void 0, function* (path, options = {}) {
125
125
  const filePath = Path.join(this.destination, path);
126
126
  return new Promise((resolve, reject) => {
127
127
  fs_1.default.rm(filePath, options, (err) => {
@@ -0,0 +1,17 @@
1
+ import { Module } from "./Module";
2
+ export declare class Factory {
3
+ private readonly cli;
4
+ private readonly container;
5
+ private routes;
6
+ private constructor();
7
+ scan(moduleType: any): Promise<void>;
8
+ scanModules(moduleType: any, parent?: Module): Promise<Module | undefined>;
9
+ scanDependencies(): Promise<void>;
10
+ scanModuleDependencies(module: Module): Promise<void>;
11
+ scanDynamicModules(): Promise<void>;
12
+ scanRoutes(): Promise<void>;
13
+ log(...args: any[]): void;
14
+ init(): Promise<void>;
15
+ run(args: string[]): Promise<any>;
16
+ static create(module: any): Promise<Factory>;
17
+ }
@@ -0,0 +1,201 @@
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
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Factory = void 0;
13
+ const cli_1 = require("@kearisp/cli");
14
+ const Container_1 = require("./Container");
15
+ const Module_1 = require("./Module");
16
+ const env_1 = require("../env");
17
+ class Factory {
18
+ constructor() {
19
+ this.routes = [];
20
+ this.container = new Container_1.Container();
21
+ this.cli = new cli_1.Cli();
22
+ }
23
+ scan(moduleType) {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ if (this.container.modules.has(moduleType)) {
26
+ return;
27
+ }
28
+ yield this.scanModules(moduleType);
29
+ yield this.scanDependencies();
30
+ yield this.scanDynamicModules();
31
+ yield this.scanRoutes();
32
+ yield this.init();
33
+ });
34
+ }
35
+ scanModules(moduleType, parent) {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ if (this.container.hasModule(moduleType)) {
38
+ return;
39
+ }
40
+ const module = new Module_1.Module(moduleType, parent);
41
+ this.container.addModule(moduleType, module);
42
+ const modules = Reflect.getMetadata(env_1.MODULE_METADATA.IMPORTS, moduleType) || [];
43
+ for (const subModuleType of modules) {
44
+ yield this.scanModules(subModuleType, module);
45
+ }
46
+ // const exports = Reflect.getMetadata(MODULE_METADATA.EXPORTS, moduleType) || [];
47
+ return module;
48
+ });
49
+ }
50
+ scanDependencies() {
51
+ return __awaiter(this, void 0, void 0, function* () {
52
+ for (const [, module] of this.container.modules) {
53
+ yield this.scanModuleDependencies(module);
54
+ }
55
+ });
56
+ }
57
+ scanModuleDependencies(module) {
58
+ return __awaiter(this, void 0, void 0, function* () {
59
+ const providers = Reflect.getMetadata(env_1.MODULE_METADATA.PROVIDERS, module.type) || [];
60
+ module.addProvider(cli_1.Cli, this.cli);
61
+ providers.forEach((providerType) => {
62
+ module.addProvider(providerType);
63
+ });
64
+ const controllers = Reflect.getMetadata(env_1.MODULE_METADATA.CONTROLLERS, module.type) || [];
65
+ controllers.forEach((controller) => {
66
+ module.addController(controller);
67
+ });
68
+ });
69
+ }
70
+ scanDynamicModules() {
71
+ return __awaiter(this, void 0, void 0, function* () {
72
+ for (const [moduleType, module] of this.container.modules) {
73
+ if (moduleType.prototype.load) {
74
+ const { imports } = yield moduleType.prototype.load(this.container);
75
+ for (const type of imports) {
76
+ const isModule = Reflect.getMetadata("isModule", type);
77
+ if (!isModule) {
78
+ continue;
79
+ }
80
+ const subModule = yield this.scanModules(type, module);
81
+ if (subModule) {
82
+ yield this.scanModuleDependencies(subModule);
83
+ }
84
+ }
85
+ }
86
+ }
87
+ });
88
+ }
89
+ scanRoutes() {
90
+ return __awaiter(this, void 0, void 0, function* () {
91
+ for (const [, module] of this.container.modules) {
92
+ for (const [type, controller] of module.controllers) {
93
+ const controllerCommands = [];
94
+ const controllerCompletions = [];
95
+ for (const name of Object.getOwnPropertyNames(type.prototype)) {
96
+ const descriptor = Object.getOwnPropertyDescriptor(type.prototype, name);
97
+ if (!descriptor) {
98
+ continue;
99
+ }
100
+ const commandName = Reflect.getMetadata(env_1.COMMAND_METADATA, descriptor.value);
101
+ const completions = (Reflect.getMetadata(env_1.COMPLETION_METADATA, descriptor.value) || []).map((completion) => {
102
+ return Object.assign(Object.assign({}, completion), { method: name });
103
+ });
104
+ if (completions.length > 0) {
105
+ controllerCompletions.push(...completions);
106
+ }
107
+ if (commandName) {
108
+ controllerCommands.push({
109
+ command: commandName,
110
+ controller,
111
+ method: name,
112
+ argsMeta: Reflect.getMetadata(env_1.ARGS_METADATA, type, name) || []
113
+ });
114
+ const argsMeta = Reflect.getMetadata(env_1.ARGS_METADATA, type, name) || [];
115
+ const command = this.cli.command(commandName);
116
+ for (const argMeta of argsMeta) {
117
+ if (argMeta.type === "option") {
118
+ command.option(argMeta.name, argMeta.params);
119
+ }
120
+ }
121
+ // command.action((options, ...params) => {
122
+ // const args: any[] = [];
123
+ //
124
+ // argsMeta.forEach((argMeta: any) => {
125
+ // if(argMeta.type === "option") {
126
+ // args[argMeta.index] = options[argMeta.name];
127
+ // }
128
+ // });
129
+ //
130
+ // return controller.instance[name](...args, ...params);
131
+ // });
132
+ }
133
+ }
134
+ for (const controllerCommand of controllerCommands) {
135
+ const { command: commandName, method, argsMeta } = controllerCommand;
136
+ this.cli.command(commandName)
137
+ .action((options, ...params) => {
138
+ const args = [];
139
+ argsMeta.forEach((argMeta) => {
140
+ if (argMeta.type === "option") {
141
+ args[argMeta.index] = options[argMeta.name];
142
+ }
143
+ });
144
+ return controller.instance[method](...args, ...params);
145
+ });
146
+ }
147
+ for (const controllerCompletion of controllerCompletions) {
148
+ const { name, command: commandName, method } = controllerCompletion;
149
+ if (!commandName) {
150
+ for (const route of controllerCommands) {
151
+ const { command } = route;
152
+ this.cli.command(command).completion(name, () => {
153
+ return controller.instance[method]();
154
+ });
155
+ }
156
+ }
157
+ else {
158
+ this.cli.command(commandName).completion(name, () => {
159
+ return controller.instance[method]();
160
+ });
161
+ }
162
+ }
163
+ }
164
+ }
165
+ });
166
+ }
167
+ log(...args) {
168
+ for (const [, module] of this.container.modules) {
169
+ module.providers.forEach((provider) => {
170
+ if (provider.instance.info) {
171
+ provider.instance.info(...args);
172
+ }
173
+ });
174
+ }
175
+ }
176
+ init() {
177
+ return __awaiter(this, void 0, void 0, function* () {
178
+ for (const [, module] of this.container.modules) {
179
+ module.providers.forEach((provider) => {
180
+ provider.instance;
181
+ });
182
+ module.controllers.forEach((controller) => {
183
+ controller.instance;
184
+ });
185
+ }
186
+ });
187
+ }
188
+ run(args) {
189
+ return __awaiter(this, void 0, void 0, function* () {
190
+ return this.cli.run(args);
191
+ });
192
+ }
193
+ static create(module) {
194
+ return __awaiter(this, void 0, void 0, function* () {
195
+ const factory = new this();
196
+ yield factory.scan(module);
197
+ return factory;
198
+ });
199
+ }
200
+ }
201
+ exports.Factory = Factory;
@@ -0,0 +1,10 @@
1
+ import { Module } from "./Module";
2
+ export declare class InstanceWrapper {
3
+ private readonly module;
4
+ private readonly token;
5
+ private readonly provider;
6
+ private _instance?;
7
+ constructor(module: Module, token: any, provider: any, _instance?: any);
8
+ get instance(): any;
9
+ set instance(instance: any);
10
+ }