import type { InjectableWithTypedThis, InjectMap, Resolvable, ResolvableArray } from "@akala/core"; import type { ICommandProcessor } from './processor.js'; import type { Command } from '../metadata/command.js' import type { Configurations } from '../metadata/configurations.js' type Injectable = InjectableWithTypedThis & { '$inject'?: string[] } export interface CommandWithProcessorAffinity extends Command { processor: ICommandProcessor; } export class SelfDefinedCommand implements Command { constructor(public readonly handler: Injectable, T, TArgs>, name?: string, inject?: ResolvableArray | InjectMap) { this.name = name || handler.name; if (typeof inject == 'undefined') inject = handler['$inject']; if (typeof inject == 'undefined' && handler.length) { inject = []; for (let i = 0; i < handler.length; i++) { inject.push('params.' + i); } } this.inject = inject || []; } public get inject(): Resolvable[] | InjectMap { return this.config[''].inject; } public set inject(value: InjectMap | Resolvable[] | undefined) { this.config[''].inject = value; } public name: string; public config: Configurations = { '': {} }; } // export class MapCommand extends Command // { // constructor(public container: Container, commandToTrigger: string, name: string, inject?: string[]) // { // super(function (...args) // { // container.dispatch(commandToTrigger, { params: args }); // }, name, inject); // } // }