mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-04-17 19:08:06 +00:00
21 lines
731 B
TypeScript
21 lines
731 B
TypeScript
import { createDecorator, Provide } from '@alilc/lowcode-shared';
|
|
import { Registry } from '../extension';
|
|
import { ICommandRegistry, Extension } from './commandRegistry';
|
|
|
|
export interface ICommandService {
|
|
executeCommand<T = any>(commandId: string, ...args: any[]): Promise<T | undefined>;
|
|
}
|
|
|
|
export const ICommandService = createDecorator<ICommandService>('commandService');
|
|
|
|
@Provide(ICommandService)
|
|
export class CommandService implements ICommandService {
|
|
executeCommand<T = any>(id: string, ...args: any[]): Promise<T | undefined> {
|
|
const command = Registry.as<ICommandRegistry>(Extension.command).getCommand(id);
|
|
|
|
if (!command) {
|
|
return Promise.reject(new Error(`command '${id}' not found`));
|
|
}
|
|
}
|
|
}
|