@wocker/core
Advanced tools
Comparing version 1.0.17-dev.0 to 1.0.17-dev.1
@@ -5,2 +5,3 @@ export * from "./Command"; | ||
export * from "./Description"; | ||
export * from "./Global"; | ||
export * from "./Inject"; | ||
@@ -7,0 +8,0 @@ export * from "./Injectable"; |
@@ -21,2 +21,3 @@ "use strict"; | ||
__exportStar(require("./Description"), exports); | ||
__exportStar(require("./Global"), exports); | ||
__exportStar(require("./Inject"), exports); | ||
@@ -23,0 +24,0 @@ __exportStar(require("./Injectable"), exports); |
@@ -0,1 +1,2 @@ | ||
export declare const IS_GLOBAL_METADATA = "IS_GLOBAL"; | ||
export declare const IS_MODULE_METADATA = "isModule"; | ||
@@ -2,0 +3,0 @@ export declare const INJECTABLE_WATERMARK = "__injectable__"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
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; | ||
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; | ||
exports.IS_GLOBAL_METADATA = "IS_GLOBAL"; | ||
exports.IS_MODULE_METADATA = "isModule"; | ||
@@ -5,0 +6,0 @@ exports.INJECTABLE_WATERMARK = "__injectable__"; |
@@ -0,3 +1,3 @@ | ||
import { Container } from "./Container"; | ||
import { Type } from "../types/Type"; | ||
import { Container } from "./Container"; | ||
export declare class ApplicationContext { | ||
@@ -4,0 +4,0 @@ protected readonly module: any; |
@@ -0,7 +1,12 @@ | ||
import { InstanceWrapper } from "./InstanceWrapper"; | ||
import { Module } from "./Module"; | ||
import { InjectionToken } from "../types/InjectionToken"; | ||
import { Type } from "../types/Type"; | ||
export declare class Container { | ||
modules: Map<any, Module>; | ||
hasModule(type: any): boolean; | ||
getModule(type: any): Module | undefined; | ||
addModule(type: any, module: Module): void; | ||
readonly modules: Map<Type, Module>; | ||
readonly providers: Map<InjectionToken, InstanceWrapper>; | ||
constructor(); | ||
addModule<TInput = any>(type: Type<TInput>, module: Module): void; | ||
hasModule<TInput = any>(type: Type<TInput>): boolean; | ||
getModule<TInput = any>(type: Type<TInput>): Module<TInput>; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Container = void 0; | ||
const cli_1 = require("@kearisp/cli"); | ||
const InstanceWrapper_1 = require("./InstanceWrapper"); | ||
const Module_1 = require("./Module"); | ||
class Container { | ||
constructor() { | ||
this.modules = new Map(); | ||
// public addController(moduleType: any, type: any): void { | ||
// const module = this.getModule(moduleType); | ||
// | ||
// if(!module) { | ||
// return; | ||
// } | ||
// | ||
// module.addController(type); | ||
// } | ||
this.providers = new Map(); | ||
const cliWrapper = new InstanceWrapper_1.InstanceWrapper(new Module_1.Module(this, null), cli_1.Cli); | ||
this.providers.set(cli_1.Cli, cliWrapper); | ||
} | ||
addModule(type, module) { | ||
this.modules.set(type, module); | ||
} | ||
hasModule(type) { | ||
@@ -21,8 +21,9 @@ return this.modules.has(type); | ||
getModule(type) { | ||
return this.modules.get(type); | ||
const module = this.modules.get(type); | ||
if (!module) { | ||
throw new Error("Module not found"); | ||
} | ||
return module; | ||
} | ||
addModule(type, module) { | ||
this.modules.set(type, module); | ||
} | ||
} | ||
exports.Container = Container; |
import { ApplicationContext } from "./ApplicationContext"; | ||
import { Container } from "./Container"; | ||
import { Module } from "./Module"; | ||
export declare class Factory { | ||
private readonly cli; | ||
private readonly container; | ||
private routes; | ||
private constructor(); | ||
scan(moduleType: any): Promise<void>; | ||
scanModules(moduleType: any, parent?: Module): Promise<Module | undefined>; | ||
scanDependencies(): Promise<void>; | ||
scanModuleDependencies(module: Module): Promise<void>; | ||
scanDynamicModules(): Promise<void>; | ||
scanRoutes(): Promise<void>; | ||
init(): Promise<void>; | ||
run(args: string[]): Promise<string>; | ||
getContainer(): Container; | ||
static create(module: any): Promise<ApplicationContext>; | ||
} |
@@ -13,192 +13,10 @@ "use strict"; | ||
exports.Factory = void 0; | ||
const cli_1 = require("@kearisp/cli"); | ||
const ApplicationContext_1 = require("./ApplicationContext"); | ||
const Container_1 = require("./Container"); | ||
const Module_1 = require("./Module"); | ||
const env_1 = require("../env"); | ||
const Scanner_1 = require("./Scanner"); | ||
class Factory { | ||
constructor() { | ||
this.routes = []; | ||
this.container = new Container_1.Container(); | ||
this.cli = new cli_1.Cli(); | ||
} | ||
scan(moduleType) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (this.container.modules.has(moduleType)) { | ||
return; | ||
} | ||
yield this.scanModules(moduleType); | ||
yield this.scanDependencies(); | ||
yield this.scanDynamicModules(); | ||
yield this.scanRoutes(); | ||
yield this.init(); | ||
}); | ||
} | ||
scanModules(moduleType, parent) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (this.container.hasModule(moduleType)) { | ||
return; | ||
} | ||
const module = new Module_1.Module(moduleType, parent); | ||
this.container.addModule(moduleType, module); | ||
const modules = Reflect.getMetadata(env_1.MODULE_METADATA.IMPORTS, moduleType) || []; | ||
for (const subModuleType of modules) { | ||
yield this.scanModules(subModuleType, module); | ||
} | ||
// const exports = Reflect.getMetadata(MODULE_METADATA.EXPORTS, moduleType) || []; | ||
return module; | ||
}); | ||
} | ||
scanDependencies() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
for (const [, module] of this.container.modules) { | ||
yield this.scanModuleDependencies(module); | ||
} | ||
}); | ||
} | ||
scanModuleDependencies(module) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const providers = Reflect.getMetadata(env_1.MODULE_METADATA.PROVIDERS, module.type) || []; | ||
// Logger.info(module.type.name, providers); | ||
module.addProvider(cli_1.Cli, this.cli); | ||
providers.forEach((providerType) => { | ||
// Logger.info(" ->", (providerType as any).name); | ||
module.addProvider(providerType); | ||
}); | ||
const controllers = Reflect.getMetadata(env_1.MODULE_METADATA.CONTROLLERS, module.type) || []; | ||
controllers.forEach((controller) => { | ||
module.addController(controller); | ||
}); | ||
}); | ||
} | ||
scanDynamicModules() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
for (const [moduleType, module] of this.container.modules) { | ||
if (moduleType.prototype.load) { | ||
const { imports } = yield moduleType.prototype.load(this.container); | ||
for (const type of imports) { | ||
const isModule = Reflect.getMetadata(env_1.IS_MODULE_METADATA, type); | ||
if (!isModule) { | ||
continue; | ||
} | ||
const subModule = yield this.scanModules(type, module); | ||
if (subModule) { | ||
yield this.scanModuleDependencies(subModule); | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
scanRoutes() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
for (const [, module] of this.container.modules) { | ||
for (const [type, controller] of module.controllers) { | ||
const controllerCommands = []; | ||
const controllerCompletions = []; | ||
for (const name of Object.getOwnPropertyNames(type.prototype)) { | ||
const descriptor = Object.getOwnPropertyDescriptor(type.prototype, name); | ||
if (!descriptor) { | ||
continue; | ||
} | ||
const commandName = Reflect.getMetadata(env_1.COMMAND_METADATA, descriptor.value); | ||
const completions = (Reflect.getMetadata(env_1.COMPLETION_METADATA, descriptor.value) || []) | ||
.map((completion) => { | ||
return Object.assign(Object.assign({}, completion), { method: name }); | ||
}); | ||
if (completions.length > 0) { | ||
controllerCompletions.push(...completions); | ||
} | ||
if (commandName) { | ||
controllerCommands.push({ | ||
command: commandName, | ||
controller, | ||
method: name, | ||
argsMeta: Reflect.getMetadata(env_1.ARGS_METADATA, type, name) || [] | ||
}); | ||
const argsMeta = Reflect.getMetadata(env_1.ARGS_METADATA, type, name) || []; | ||
const command = this.cli.command(commandName); | ||
command.help({ | ||
description: "Des" | ||
}); | ||
for (const argMeta of argsMeta) { | ||
if (argMeta.type === "option") { | ||
command.option(argMeta.name, argMeta.params); | ||
} | ||
} | ||
// command.action((options, ...params) => { | ||
// const args: any[] = []; | ||
// | ||
// argsMeta.forEach((argMeta: any) => { | ||
// if(argMeta.type === "option") { | ||
// args[argMeta.index] = options[argMeta.name]; | ||
// } | ||
// }); | ||
// | ||
// return controller.instance[name](...args, ...params); | ||
// }); | ||
} | ||
} | ||
for (const controllerCommand of controllerCommands) { | ||
const { command: commandName, method, argsMeta } = controllerCommand; | ||
this.cli.command(commandName) | ||
.action((input) => { | ||
const args = []; | ||
const params = Object.values(input.arguments()); | ||
argsMeta.forEach((argMeta) => { | ||
if (argMeta.type === "param") { | ||
args[argMeta.index] = input.argument(argMeta.name); | ||
} | ||
else if (argMeta.type === "option") { | ||
args[argMeta.index] = input.option(argMeta.name); | ||
} | ||
}); | ||
return controller.instance[method](...args, ...params); | ||
}); | ||
} | ||
for (const controllerCompletion of controllerCompletions) { | ||
const { name, command: commandName, method } = controllerCompletion; | ||
if (!commandName) { | ||
for (const route of controllerCommands) { | ||
const { command } = route; | ||
this.cli.command(command).completion(name, () => { | ||
return controller.instance[method](); | ||
}); | ||
} | ||
} | ||
else { | ||
this.cli.command(commandName).completion(name, () => { | ||
return controller.instance[method](); | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
init() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
for (const [, module] of this.container.modules) { | ||
module.providers.forEach((provider) => { | ||
provider.instance; | ||
}); | ||
module.controllers.forEach((controller) => { | ||
controller.instance; | ||
}); | ||
} | ||
}); | ||
} | ||
run(args) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.cli.run(args); | ||
}); | ||
} | ||
getContainer() { | ||
return this.container; | ||
} | ||
static create(module) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const factory = new this(); | ||
yield factory.scan(module); | ||
return new ApplicationContext_1.ApplicationContext(module, factory.getContainer()); | ||
const scanner = new Scanner_1.Scanner(); | ||
yield scanner.scan(module); | ||
return new ApplicationContext_1.ApplicationContext(module, scanner.container); | ||
}); | ||
@@ -205,0 +23,0 @@ } |
import "reflect-metadata"; | ||
import { Module } from "./Module"; | ||
export declare class InstanceWrapper { | ||
import { Provider } from "../types/Provider"; | ||
import { Type } from "../types/Type"; | ||
import { InjectionToken } from "../types/InjectionToken"; | ||
export declare class InstanceWrapper<TInput = any> { | ||
private readonly module; | ||
private readonly provider; | ||
private _instance?; | ||
constructor(module: Module, provider: any, _instance?: any); | ||
get instance(): any; | ||
set instance(instance: any); | ||
protected _instance?: TInput | undefined; | ||
readonly token: InjectionToken<TInput>; | ||
readonly type?: Type<TInput>; | ||
constructor(module: Module, provider: Provider<TInput>, _instance?: TInput | undefined); | ||
get instance(): TInput | undefined; | ||
} |
@@ -11,9 +11,19 @@ "use strict"; | ||
this._instance = _instance; | ||
if ("provide" in this.provider && "useValue" in this.provider) { | ||
this.token = this.provider.provide; | ||
this._instance = this.provider.useValue; | ||
return; | ||
} | ||
if ("provide" in this.provider && "useClass" in this.provider) { | ||
this.token = this.provider.provide; | ||
this.type = this.provider.useClass; | ||
return; | ||
} | ||
this.token = Reflect.getMetadata(env_1.INJECT_TOKEN_METADATA, this.provider) || this.provider; | ||
this.type = this.provider; | ||
} | ||
get instance() { | ||
if (!this._instance) { | ||
const types = [ | ||
...Reflect.getMetadata(env_1.PARAMTYPES_METADATA, this.provider) || [] | ||
]; | ||
const selfTypes = Reflect.getMetadata(env_1.SELF_DECLARED_DEPS_METADATA, this.provider) || []; | ||
if (!this._instance && this.type) { | ||
const types = Reflect.getMetadata(env_1.PARAMTYPES_METADATA, this.type) || []; | ||
const selfTypes = Reflect.getMetadata(env_1.SELF_DECLARED_DEPS_METADATA, this.type) || []; | ||
if (selfTypes.length > 0) { | ||
@@ -25,16 +35,9 @@ selfTypes.forEach(({ index, token }) => { | ||
const params = types.map((type) => { | ||
const wrapper = this.module.getWrapper(type); | ||
if (!wrapper) { | ||
return undefined; | ||
} | ||
return wrapper.instance; | ||
return this.module.get(type); | ||
}); | ||
this._instance = new this.provider(...params); | ||
this._instance = new this.type(...params); | ||
} | ||
return this._instance; | ||
} | ||
set instance(instance) { | ||
this._instance = instance; | ||
} | ||
} | ||
exports.InstanceWrapper = InstanceWrapper; |
@@ -10,11 +10,23 @@ "use strict"; | ||
static log(...data) { | ||
if (!loggerService) { | ||
return; | ||
} | ||
loggerService.log(...data); | ||
} | ||
static info(...data) { | ||
if (!loggerService) { | ||
return; | ||
} | ||
loggerService.info(...data); | ||
} | ||
static warn(...data) { | ||
if (!loggerService) { | ||
return; | ||
} | ||
loggerService.warn(...data); | ||
} | ||
static error(...data) { | ||
if (!loggerService) { | ||
return; | ||
} | ||
loggerService.error(...data); | ||
@@ -21,0 +33,0 @@ } |
import { Provider } from "../types/Provider"; | ||
import { Type } from "../types/Type"; | ||
import { Container } from "./Container"; | ||
import { InstanceWrapper } from "./InstanceWrapper"; | ||
export declare class Module { | ||
type: any; | ||
export declare class Module<TInput = any> { | ||
readonly container: Container; | ||
type: TInput; | ||
parent?: Module | undefined; | ||
imports: Set<any>; | ||
imports: Map<any, InstanceWrapper>; | ||
controllers: Map<any, InstanceWrapper>; | ||
providers: Map<any, InstanceWrapper>; | ||
exports: Map<any, any>; | ||
constructor(type: any, parent?: Module | undefined); | ||
get<T = any>(type: any): T; | ||
exports: Set<any>; | ||
constructor(container: Container, type: TInput, parent?: Module | undefined); | ||
get<TInput = any, TResult = TInput>(type: Type<TInput> | Function | string | symbol): TResult; | ||
getWrapper(type: any): InstanceWrapper | undefined; | ||
addImport(module: any): void; | ||
addProvider(provider: Provider, instance?: any): void; | ||
getProvider(): void; | ||
addInjection(): void; | ||
addController(type: any): void; | ||
addExport(type: any): void; | ||
} |
@@ -7,9 +7,10 @@ "use strict"; | ||
class Module { | ||
constructor(type, parent) { | ||
constructor(container, type, parent) { | ||
this.container = container; | ||
this.type = type; | ||
this.parent = parent; | ||
this.imports = new Set(); | ||
this.imports = new Map(); | ||
this.controllers = new Map(); | ||
this.providers = new Map(); | ||
this.exports = new Map(); | ||
this.exports = new Set(); | ||
} | ||
@@ -31,22 +32,17 @@ get(type) { | ||
} | ||
if (!wrapper) { | ||
return this.container.providers.get(type); | ||
} | ||
return wrapper; | ||
} | ||
addImport(module) { | ||
this.imports.add(module); | ||
// this.imports.add(module); | ||
} | ||
addProvider(provider, instance) { | ||
if ("provide" in provider && "useValue" in provider) { | ||
const wrapper = new InstanceWrapper_1.InstanceWrapper(this, provider.provide, provider.useValue); | ||
this.providers.set(provider.provide, wrapper); | ||
return; | ||
} | ||
if ("provide" in provider && "useClass" in provider) { | ||
const wrapper = new InstanceWrapper_1.InstanceWrapper(this, provider.useClass); | ||
this.providers.set(provider.provide, wrapper); | ||
return; | ||
} | ||
const token = Reflect.getMetadata("INJECT_TOKEN", provider) || provider; | ||
const wrapper = new InstanceWrapper_1.InstanceWrapper(this, provider, instance); | ||
this.providers.set(token, wrapper); | ||
this.providers.set(wrapper.token, wrapper); | ||
} | ||
getProvider() { | ||
// | ||
} | ||
addInjection() { | ||
@@ -69,3 +65,6 @@ // | ||
} | ||
addExport(type) { | ||
this.exports.add(type); | ||
} | ||
} | ||
exports.Module = Module; |
@@ -0,4 +1,15 @@ | ||
import "reflect-metadata"; | ||
import { Container } from "./Container"; | ||
import { Module } from "./Module"; | ||
export declare class Scanner { | ||
readonly container: Container; | ||
constructor(); | ||
scan(module: any): void; | ||
scan(moduleType: any): Promise<void>; | ||
protected scanModule(moduleType: any): Module; | ||
protected scanControllers(module: Module): void; | ||
protected scanProviders(module: Module): void; | ||
protected scanImports(module: Module): void; | ||
protected scanExports(module: Module): void; | ||
protected scanRoutes(): void; | ||
protected scanDynamicModules(): Promise<void>; | ||
} |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Scanner = void 0; | ||
require("reflect-metadata"); | ||
const cli_1 = require("@kearisp/cli"); | ||
const Container_1 = require("./Container"); | ||
const Module_1 = require("./Module"); | ||
const Logger_1 = require("./Logger"); | ||
const env_1 = require("../env"); | ||
class Scanner { | ||
constructor() { } | ||
scan(module) { | ||
constructor() { | ||
this.container = new Container_1.Container(); | ||
} | ||
scan(moduleType) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.scanModule(moduleType); | ||
yield this.scanDynamicModules(); | ||
this.scanRoutes(); | ||
}); | ||
} | ||
scanModule(moduleType) { | ||
let module = this.container.hasModule(moduleType) | ||
? this.container.getModule(moduleType) | ||
: null; | ||
if (!module) { | ||
module = new Module_1.Module(this.container, moduleType); | ||
this.container.addModule(moduleType, module); | ||
this.scanImports(module); | ||
this.scanControllers(module); | ||
this.scanProviders(module); | ||
this.scanExports(module); | ||
} | ||
return module; | ||
} | ||
scanControllers(module) { | ||
const controllers = Reflect.getMetadata(env_1.MODULE_METADATA.CONTROLLERS, module.type) || []; | ||
controllers.forEach((controller) => { | ||
module.addController(controller); | ||
}); | ||
} | ||
scanProviders(module) { | ||
const providers = Reflect.getMetadata(env_1.MODULE_METADATA.PROVIDERS, module.type) || []; | ||
providers.forEach((provider) => { | ||
module.addProvider(provider); | ||
}); | ||
} | ||
scanImports(module) { | ||
const imports = Reflect.getMetadata(env_1.MODULE_METADATA.IMPORTS, module.type) || []; | ||
imports.forEach((importType) => { | ||
const subModule = this.scanModule(importType); | ||
subModule.exports.forEach((type) => { | ||
const provider = subModule.providers.get(type); | ||
if (!provider) { | ||
return; | ||
} | ||
module.providers.set(type, provider); | ||
}); | ||
}); | ||
} | ||
scanExports(module) { | ||
const exports = Reflect.getMetadata(env_1.MODULE_METADATA.EXPORTS, module.type) || []; | ||
const isGlobal = Reflect.getMetadata(env_1.IS_GLOBAL_METADATA, module.type) || false; | ||
exports.forEach((type) => { | ||
module.addExport(type); | ||
if (isGlobal) { | ||
const wrapper = module.getWrapper(type); | ||
if (wrapper) { | ||
this.container.providers.set(type, wrapper); | ||
} | ||
} | ||
}); | ||
} | ||
scanRoutes() { | ||
const cliWrapper = this.container.providers.get(cli_1.Cli); | ||
if (!cliWrapper) { | ||
return; | ||
} | ||
const cli = cliWrapper.instance; | ||
// Logger.unmute(); | ||
Logger_1.Logger.info(">_<"); | ||
for (const [, module] of this.container.modules) { | ||
for (const [type, controller] of module.controllers) { | ||
const controllerCommands = []; | ||
const controllerCompletions = []; | ||
for (const name of Object.getOwnPropertyNames(type.prototype)) { | ||
const descriptor = Object.getOwnPropertyDescriptor(type.prototype, name); | ||
if (!descriptor) { | ||
continue; | ||
} | ||
const commandName = Reflect.getMetadata(env_1.COMMAND_METADATA, descriptor.value); | ||
const completions = (Reflect.getMetadata(env_1.COMPLETION_METADATA, descriptor.value) || []) | ||
.map((completion) => { | ||
return Object.assign(Object.assign({}, completion), { method: name }); | ||
}); | ||
if (completions.length > 0) { | ||
controllerCompletions.push(...completions); | ||
} | ||
if (commandName) { | ||
controllerCommands.push({ | ||
command: commandName, | ||
controller, | ||
method: name, | ||
argsMeta: Reflect.getMetadata(env_1.ARGS_METADATA, type, name) || [] | ||
}); | ||
const argsMeta = Reflect.getMetadata(env_1.ARGS_METADATA, type, name) || []; | ||
const command = cli.command(commandName); | ||
command.help({ | ||
description: "Des" | ||
}); | ||
for (const argMeta of argsMeta) { | ||
if (argMeta.type === "option") { | ||
command.option(argMeta.name, argMeta.params); | ||
} | ||
} | ||
// command.action((options, ...params) => { | ||
// const args: any[] = []; | ||
// | ||
// argsMeta.forEach((argMeta: any) => { | ||
// if(argMeta.type === "option") { | ||
// args[argMeta.index] = options[argMeta.name]; | ||
// } | ||
// }); | ||
// | ||
// return controller.instance[name](...args, ...params); | ||
// }); | ||
} | ||
} | ||
for (const controllerCommand of controllerCommands) { | ||
const { command: commandName, method, argsMeta } = controllerCommand; | ||
cli.command(commandName) | ||
.action((input) => { | ||
const args = []; | ||
const params = Object.values(input.arguments()); | ||
argsMeta.forEach((argMeta) => { | ||
if (argMeta.type === "param") { | ||
args[argMeta.index] = input.argument(argMeta.name); | ||
} | ||
else if (argMeta.type === "option") { | ||
args[argMeta.index] = input.option(argMeta.name); | ||
} | ||
}); | ||
return controller.instance[method](...args, ...params); | ||
}); | ||
} | ||
for (const controllerCompletion of controllerCompletions) { | ||
const { name, command: commandName, method } = controllerCompletion; | ||
if (!commandName) { | ||
for (const route of controllerCommands) { | ||
const { command } = route; | ||
cli.command(command).completion(name, () => { | ||
return controller.instance[method](); | ||
}); | ||
} | ||
} | ||
else { | ||
cli.command(commandName).completion(name, () => { | ||
return controller.instance[method](); | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
scanDynamicModules() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const promises = ([...this.container.modules.keys()]).map((type) => __awaiter(this, void 0, void 0, function* () { | ||
if (!type.prototype.load) { | ||
return; | ||
} | ||
const parentModule = this.container.modules.get(type); | ||
const { [env_1.MODULE_METADATA.IMPORTS]: imports = [] } = yield type.prototype.load(this.container); | ||
for (const subModuleType of imports) { | ||
const module = this.scanModule(subModuleType); | ||
module.exports.forEach((type) => { | ||
const provider = module.getWrapper(type); | ||
if (!provider) { | ||
// console.log(type, ">_<", provider); | ||
} | ||
// @ts-ignore | ||
parentModule.providers.set(type, provider); | ||
}); | ||
} | ||
})); | ||
yield Promise.all(promises); | ||
}); | ||
} | ||
} | ||
exports.Scanner = Scanner; |
@@ -1,7 +0,6 @@ | ||
type EventHandle = (...args: any[]) => Promise<void> | void; | ||
export type AppEventHandle = (...args: any[]) => Promise<void> | void; | ||
export declare abstract class AppEventsService { | ||
abstract on(event: string, handle: EventHandle): void; | ||
abstract off(event: string, handle: EventHandle): void; | ||
abstract on(event: string, handle: AppEventHandle): void; | ||
abstract off(event: string, handle: AppEventHandle): void; | ||
abstract emit(event: string, ...args: any[]): Promise<void>; | ||
} | ||
export { EventHandle as AppEventHandle }; |
{ | ||
"name": "@wocker/core", | ||
"version": "1.0.17-dev.0", | ||
"version": "1.0.17-dev.1", | ||
"author": "Kris Papercut <krispcut@gmail.com>", | ||
@@ -28,3 +28,3 @@ "description": "Core of the Wocker", | ||
"dependencies": { | ||
"@kearisp/cli": "^2.0.4", | ||
"@kearisp/cli": "^2.0.5", | ||
"fs": "^0.0.1-security", | ||
@@ -31,0 +31,0 @@ "path": "^0.12.7", |
99283
101
2509
Updated@kearisp/cli@^2.0.5