import type { IResponseError, ITask, ITaskLogItemData, ITaskUpdateData, TaskDataStatus } from "../../../api/types.js"; import { TaskDefinition } from "@webiny/api-core/features/task/TaskDefinition/index.js"; export type ITaskManagerStoreUpdateTaskValues = T; export interface ITaskManagerStoreUpdateTaskValuesCb { (input: T): T; } export interface ITaskManagerStoreUpdateTaskInputOptions { save: boolean; } export type ITaskManagerStoreUpdateTaskInputParam = ITaskManagerStoreUpdateTaskValuesCb | Partial>; export interface ITaskManagerStoreUpdateTaskParamCb { (task: ITask): ITaskUpdateData; } export type ITaskManagerStoreUpdateTask = ITaskUpdateData; export type ITaskManagerStoreUpdateTaskParams = ITaskManagerStoreUpdateTaskParamCb | Partial>; export interface ITaskManagerStoreInfoLog { message: string; data?: ITaskLogItemData; } export interface ITaskManagerStoreErrorLog { message: string; data?: ITaskLogItemData; error: IResponseError | Error; } export interface ITaskManagerStoreSetOutputOptions { /** * Default is true. */ save?: boolean; } export interface ITaskManagerStoreUpdateTaskOptions { /** * Default is true. */ save?: boolean; } export interface ITaskManagerStoreAddLogOptions { /** * Default is true. */ save?: boolean; } /** * Interface should not be used outside the @webiny/background-tasks package. */ export interface ITaskManagerStorePrivate { getTask: () => ITask; getStatus: () => TaskDataStatus; /** * @throws {Error} If task not found or something goes wrong during the database update. */ updateTask(params: ITaskManagerStoreUpdateTaskParams, options?: ITaskManagerStoreUpdateTaskOptions): Promise; /** * List all child tasks of the current task. * If definitionId is provided, filter by that parameter. */ listChildTasks(definitionId?: string): Promise[]>; /** * Update the task input, which are used to store custom user data. * You can send partial input, and it will be merged with the existing input. * * @throws {Error} If task not found or something goes wrong during the database update. */ updateInput: (params: ITaskManagerStoreUpdateTaskInputParam, options?: ITaskManagerStoreUpdateTaskInputOptions) => Promise; getInput: () => T; /** * Update the task output, which are used to store the output data. * You can send partial output, and it will be merged with the existing output. * * Second parameter is optional options, and it contains a possibility not to store the task immediately. * * @throws {Error} If task not found or something goes wrong during the database update. */ updateOutput: (values: Partial, options?: ITaskManagerStoreSetOutputOptions) => Promise; getOutput: () => O; /** * @throws {Error} If task not found or something goes wrong during the database update. */ addInfoLog: (log: ITaskManagerStoreInfoLog) => Promise; /** * @throws {Error} If task not found or something goes wrong during the database update. * * */ addErrorLog: (log: ITaskManagerStoreErrorLog) => Promise; /** * Should store the task and logs into the database, if any. * If nothing to update, it should skip calling the internal store methods. */ save(): Promise; } export type ITaskManagerStore = Omit, "save">;