import { Dispatcher } from "./Dispatcher"; import { UseCase } from "./UseCase"; import { UseCaseLike } from "./UseCaseLike"; declare type Arguments any> = F extends (...x: infer A) => any ? A : never; export interface UseCaseExecutor extends Dispatcher { useCase: T; execute

>(...args: P): Promise; executor(executor: (useCase: Pick) => any): Promise; release(): void; onReleaseOnce(handler: () => void): void; } /** * `UseCaseExecutor` is a helper class for executing UseCase. * * You can not create the instance of UseCaseExecutor directory. * You can get the instance by `Context#useCase(useCase)`, * */ export declare class UseCaseExecutorImpl extends Dispatcher implements UseCaseExecutor { /** * A executable useCase */ useCase: T; /** * A parent useCase */ private _parentUseCase; /** * callable release handlers that are called in release() */ private _releaseHandlers; private releaseEvents; /** * @param useCase * @param parent * parent is parent of `useCase` * @param dispatcher * @public * * **internal** documentation */ constructor({ useCase, parent }: { useCase: T; parent: UseCase | null; }); private willNotExecuteUseCase; /** * @param [args] arguments of the UseCase */ private willExecuteUseCase; /** * dispatch did execute each UseCase */ private didExecuteUseCase; /** * dispatch complete each UseCase * @param [value] unwrapped result value of the useCase executed */ private completeUseCase; /** * Call handler when this UseCaseExecutor will be released * @param handler */ onReleaseOnce(handler: () => void): void; /** * **Stability**: Deprecated(Previously: experimental) * * - This feature is subject to change. It may change or be removed in future versions. * - If you inserting in this, please see * * Similar to `execute(arguments)`, but it accept an executor function insteadof `arguments` * `executor(useCase => useCase.execute())` return a Promise object that resolved with undefined. * * This method is type-safe. It is useful for TypeScript. * * ## Example * * ```js * context.useCase(new MyUseCase()) * .executor(useCase => useCase.execute("value")) * .then(() => { * console.log("test"); * }); * ``` * * ## Notes * * ### What is difference between `executor(executor)` and `execute(arguments)`? * * The `execute(arguments)` is a alias of following codes: * * ```js * context.useCase(new MyUseCase()) * .execute("value") * // === * context.useCase(new MyUseCase()) * .executor(useCase => useCase.execute("value")) * ``` * * ### Why executor's result always to be undefined? * * `execute()` return a Promise that will resolve `undefined` by design. * In CQRS, the command always have returned void type. * * - http://cqrs.nu/Faq * * So, `execute()` only return command result that is success or failure. * You should not relay on the result value of the useCase#execute. * * @deprecated Use `execute()` instead of `executor()` * Almin 0.18+ make `execute` type complete. * It will be remove in the future. * * Please apply migration scripts: * https://github.com/almin/almin/issues/356 * */ executor(executor: (useCase: Pick) => any): Promise; /** * Execute UseCase instance. * UseCase is a executable object that has `execute` method. * * This method invoke UseCase's `execute` method and return a promise. * The promise will be resolved when the UseCase is completed finished. * * ### Why executor's result always to be undefined? * * `execute()` return a Promise that will resolve `undefined` by design. * In CQRS, the command always have returned void type. * * - http://cqrs.nu/Faq * * So, `execute()` only return command result that is success or failure. * You should not relay on the result value of the useCase#execute. * * ## Notes * * > Added: Almin 0.17.0+ * * `execute()` support type check in Almin 0.17.0. * However, it has a limitation about argument lengths. * For more details, please see * * > Added: Almin 0.18.0+ * * `execute()` support type check completely. * No more need to use `executor()` for typing. * */ execute

>(...args: P): Promise; /** * release all events handler. * You can call this when no more call event handler * * **internal** */ release(): void; } export {};