@webiny/background-tasks 6.6.0-alpha.0 → 6.6.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/admin/BackgroundTaskRoutes.js +16 -3
- package/admin/BackgroundTaskRoutes.js.map +1 -1
- package/admin/presentation/TaskDetail/components/TaskDetailDrawer.js +6 -0
- package/admin/presentation/TaskDetail/components/TaskDetailDrawer.js.map +1 -1
- package/admin/presentation/TaskExecutions/components/TaskExecutionsView.js +44 -24
- package/admin/presentation/TaskExecutions/components/TaskExecutionsView.js.map +1 -1
- package/api/BackgroundTasksFeature.js +44 -24
- package/api/BackgroundTasksFeature.js.map +1 -1
- package/api/crud/TaskLogPrivateModel.js +2 -1
- package/api/crud/TaskLogPrivateModel.js.map +1 -1
- package/api/crud/TaskPrivateModel.js +2 -1
- package/api/crud/TaskPrivateModel.js.map +1 -1
- package/api/decorators/{SelfCleaningTaskDecorator.d.ts → SelfCleaningTaskHandlerDecorator.d.ts} +21 -18
- package/api/decorators/SelfCleaningTaskHandlerDecorator.js +69 -0
- package/api/decorators/SelfCleaningTaskHandlerDecorator.js.map +1 -0
- package/api/decorators/TaskDefinitionDefaultsDecorator.d.ts +27 -0
- package/api/decorators/TaskDefinitionDefaultsDecorator.js +47 -0
- package/api/decorators/TaskDefinitionDefaultsDecorator.js.map +1 -0
- package/api/domain/errors.d.ts +4 -0
- package/api/domain/errors.js +10 -2
- package/api/domain/errors.js.map +1 -1
- package/api/domain/task/TaskLogModelProvider.d.ts +12 -0
- package/api/domain/task/TaskLogModelProvider.js +23 -0
- package/api/domain/task/TaskLogModelProvider.js.map +1 -0
- package/api/domain/task/TaskLogsRepository.d.ts +34 -0
- package/api/domain/task/TaskLogsRepository.js +146 -0
- package/api/domain/task/TaskLogsRepository.js.map +1 -0
- package/api/domain/task/TaskModelProvider.d.ts +12 -0
- package/api/domain/task/TaskModelProvider.js +23 -0
- package/api/domain/task/TaskModelProvider.js.map +1 -0
- package/api/domain/task/TasksRepository.d.ts +37 -0
- package/api/domain/task/TasksRepository.js +126 -0
- package/api/domain/task/TasksRepository.js.map +1 -0
- package/api/domain/task/abstractions.d.ts +50 -0
- package/api/domain/task/abstractions.js +8 -0
- package/api/domain/task/abstractions.js.map +1 -0
- package/api/domain/task/createRevisionId.d.ts +1 -0
- package/api/domain/task/createRevisionId.js +8 -0
- package/api/domain/task/createRevisionId.js.map +1 -0
- package/api/domain/task/entryToTask.d.ts +3 -0
- package/api/domain/task/entryToTask.js +20 -0
- package/api/domain/task/entryToTask.js.map +1 -0
- package/api/domain/task/entryToTaskLog.d.ts +3 -0
- package/api/domain/task/entryToTaskLog.js +12 -0
- package/api/domain/task/entryToTaskLog.js.map +1 -0
- package/api/features/CleanupTaskSubtree/CleanupTaskSubtreeUseCase.d.ts +25 -5
- package/api/features/CleanupTaskSubtree/CleanupTaskSubtreeUseCase.js +111 -5
- package/api/features/CleanupTaskSubtree/CleanupTaskSubtreeUseCase.js.map +1 -1
- package/api/features/CleanupTaskSubtree/feature.d.ts +4 -0
- package/api/features/CleanupTaskSubtree/feature.js +11 -0
- package/api/features/CleanupTaskSubtree/feature.js.map +1 -0
- package/api/features/CleanupTaskSubtree/index.d.ts +1 -1
- package/api/features/CleanupTaskSubtree/index.js +1 -1
- package/api/features/CreateTask/CreateTaskUseCase.d.ts +17 -0
- package/api/features/CreateTask/CreateTaskUseCase.js +56 -0
- package/api/features/CreateTask/CreateTaskUseCase.js.map +1 -0
- package/api/features/CreateTask/abstractions.d.ts +21 -0
- package/api/features/CreateTask/abstractions.js +5 -0
- package/api/features/CreateTask/abstractions.js.map +1 -0
- package/api/features/{GetTaskDefinition → CreateTask}/feature.d.ts +1 -1
- package/api/features/CreateTask/feature.js +11 -0
- package/api/features/CreateTask/feature.js.map +1 -0
- package/api/features/CreateTask/index.d.ts +2 -0
- package/api/features/CreateTask/index.js +2 -0
- package/api/features/CreateTaskLog/CreateTaskLogUseCase.d.ts +13 -0
- package/api/features/CreateTaskLog/CreateTaskLogUseCase.js +19 -0
- package/api/features/CreateTaskLog/CreateTaskLogUseCase.js.map +1 -0
- package/api/features/CreateTaskLog/abstractions.d.ts +16 -0
- package/api/features/CreateTaskLog/abstractions.js +5 -0
- package/api/features/CreateTaskLog/abstractions.js.map +1 -0
- package/api/features/CreateTaskLog/feature.d.ts +4 -0
- package/api/features/CreateTaskLog/feature.js +11 -0
- package/api/features/CreateTaskLog/feature.js.map +1 -0
- package/api/features/CreateTaskLog/index.d.ts +2 -0
- package/api/features/CreateTaskLog/index.js +2 -0
- package/api/features/DeleteTask/DeleteTaskUseCase.d.ts +14 -0
- package/api/features/DeleteTask/DeleteTaskUseCase.js +34 -0
- package/api/features/DeleteTask/DeleteTaskUseCase.js.map +1 -0
- package/api/features/DeleteTask/abstractions.d.ts +17 -0
- package/api/features/DeleteTask/abstractions.js +5 -0
- package/api/features/DeleteTask/abstractions.js.map +1 -0
- package/api/features/DeleteTask/feature.d.ts +4 -0
- package/api/features/DeleteTask/feature.js +11 -0
- package/api/features/DeleteTask/feature.js.map +1 -0
- package/api/features/DeleteTask/index.d.ts +2 -0
- package/api/features/DeleteTask/index.js +2 -0
- package/api/features/DeleteTaskLog/DeleteTaskLogUseCase.d.ts +11 -0
- package/api/features/DeleteTaskLog/DeleteTaskLogUseCase.js +19 -0
- package/api/features/DeleteTaskLog/DeleteTaskLogUseCase.js.map +1 -0
- package/api/features/DeleteTaskLog/abstractions.d.ts +14 -0
- package/api/features/DeleteTaskLog/abstractions.js +5 -0
- package/api/features/DeleteTaskLog/abstractions.js.map +1 -0
- package/api/features/DeleteTaskLog/feature.d.ts +4 -0
- package/api/features/DeleteTaskLog/feature.js +11 -0
- package/api/features/DeleteTaskLog/feature.js.map +1 -0
- package/api/features/DeleteTaskLog/index.d.ts +2 -0
- package/api/features/DeleteTaskLog/index.js +2 -0
- package/api/features/GetLatestTaskLog/GetLatestTaskLogUseCase.d.ts +11 -0
- package/api/features/GetLatestTaskLog/GetLatestTaskLogUseCase.js +19 -0
- package/api/features/GetLatestTaskLog/GetLatestTaskLogUseCase.js.map +1 -0
- package/api/features/GetLatestTaskLog/abstractions.d.ts +15 -0
- package/api/features/GetLatestTaskLog/abstractions.js +5 -0
- package/api/features/GetLatestTaskLog/abstractions.js.map +1 -0
- package/api/features/GetLatestTaskLog/feature.d.ts +4 -0
- package/api/features/GetLatestTaskLog/feature.js +11 -0
- package/api/features/GetLatestTaskLog/feature.js.map +1 -0
- package/api/features/GetLatestTaskLog/index.d.ts +2 -0
- package/api/features/GetLatestTaskLog/index.js +2 -0
- package/api/features/GetRunnableTaskDefinition/GetRunnableTaskDefinitionUseCase.d.ts +13 -0
- package/api/features/GetRunnableTaskDefinition/GetRunnableTaskDefinitionUseCase.js +51 -0
- package/api/features/GetRunnableTaskDefinition/GetRunnableTaskDefinitionUseCase.js.map +1 -0
- package/api/features/{GetTaskDefinition → GetRunnableTaskDefinition}/abstractions.d.ts +6 -6
- package/api/features/GetRunnableTaskDefinition/abstractions.js +5 -0
- package/api/features/GetRunnableTaskDefinition/abstractions.js.map +1 -0
- package/api/features/GetRunnableTaskDefinition/feature.d.ts +4 -0
- package/api/features/GetRunnableTaskDefinition/feature.js +11 -0
- package/api/features/GetRunnableTaskDefinition/feature.js.map +1 -0
- package/api/features/GetRunnableTaskDefinition/index.d.ts +2 -0
- package/api/features/GetRunnableTaskDefinition/index.js +2 -0
- package/api/features/GetTask/GetTaskUseCase.d.ts +9 -5
- package/api/features/GetTask/GetTaskUseCase.js +12 -4
- package/api/features/GetTask/GetTaskUseCase.js.map +1 -1
- package/api/features/GetTask/abstractions.d.ts +9 -2
- package/api/features/GetTask/abstractions.js.map +1 -1
- package/api/features/GetTask/feature.js +2 -4
- package/api/features/GetTask/feature.js.map +1 -1
- package/api/features/ListTaskLogs/ListTaskLogsUseCase.d.ts +12 -0
- package/api/features/ListTaskLogs/ListTaskLogsUseCase.js +19 -0
- package/api/features/ListTaskLogs/ListTaskLogsUseCase.js.map +1 -0
- package/api/features/ListTaskLogs/abstractions.d.ts +15 -0
- package/api/features/ListTaskLogs/abstractions.js +5 -0
- package/api/features/ListTaskLogs/abstractions.js.map +1 -0
- package/api/features/ListTaskLogs/feature.d.ts +4 -0
- package/api/features/ListTaskLogs/feature.js +11 -0
- package/api/features/ListTaskLogs/feature.js.map +1 -0
- package/api/features/ListTaskLogs/index.d.ts +2 -0
- package/api/features/ListTaskLogs/index.js +2 -0
- package/api/features/ListTasks/ListTasksUseCase.d.ts +9 -6
- package/api/features/ListTasks/ListTasksUseCase.js +12 -4
- package/api/features/ListTasks/ListTasksUseCase.js.map +1 -1
- package/api/features/ListTasks/abstractions.d.ts +9 -3
- package/api/features/ListTasks/abstractions.js.map +1 -1
- package/api/features/ListTasks/feature.js +2 -4
- package/api/features/ListTasks/feature.js.map +1 -1
- package/api/features/ListVisibleTaskDefinitions/ListVisibleTaskDefinitionsUseCase.d.ts +11 -0
- package/api/features/ListVisibleTaskDefinitions/ListVisibleTaskDefinitionsUseCase.js +19 -0
- package/api/features/ListVisibleTaskDefinitions/ListVisibleTaskDefinitionsUseCase.js.map +1 -0
- package/api/features/ListVisibleTaskDefinitions/abstractions.d.ts +9 -0
- package/api/features/ListVisibleTaskDefinitions/abstractions.js +5 -0
- package/api/features/ListVisibleTaskDefinitions/abstractions.js.map +1 -0
- package/api/features/ListVisibleTaskDefinitions/feature.d.ts +4 -0
- package/api/features/ListVisibleTaskDefinitions/feature.js +11 -0
- package/api/features/ListVisibleTaskDefinitions/feature.js.map +1 -0
- package/api/features/ListVisibleTaskDefinitions/index.d.ts +2 -0
- package/api/features/ListVisibleTaskDefinitions/index.js +2 -0
- package/api/features/TaskHandlerResolver/TaskHandlerResolver.d.ts +12 -0
- package/api/features/TaskHandlerResolver/TaskHandlerResolver.js +19 -0
- package/api/features/TaskHandlerResolver/TaskHandlerResolver.js.map +1 -0
- package/api/features/TaskHandlerResolver/abstractions.d.ts +17 -0
- package/api/features/TaskHandlerResolver/abstractions.js +5 -0
- package/api/features/TaskHandlerResolver/abstractions.js.map +1 -0
- package/api/features/TaskHandlerResolver/feature.d.ts +9 -0
- package/api/features/TaskHandlerResolver/feature.js +11 -0
- package/api/features/TaskHandlerResolver/feature.js.map +1 -0
- package/api/features/TaskHandlerResolver/index.d.ts +2 -0
- package/api/features/TaskHandlerResolver/index.js +2 -0
- package/api/features/TaskService/BackgroundTaskService.d.ts +42 -0
- package/api/features/TaskService/BackgroundTaskService.js +191 -0
- package/api/features/TaskService/BackgroundTaskService.js.map +1 -0
- package/api/features/TaskService/feature.d.ts +4 -0
- package/api/features/TaskService/feature.js +11 -0
- package/api/features/TaskService/feature.js.map +1 -0
- package/api/features/TaskService/index.d.ts +1 -0
- package/api/features/TaskService/index.js +1 -0
- package/api/features/TriggerVisibleTask/TriggerVisibleTaskUseCase.d.ts +15 -0
- package/api/features/TriggerVisibleTask/TriggerVisibleTaskUseCase.js +26 -0
- package/api/features/TriggerVisibleTask/TriggerVisibleTaskUseCase.js.map +1 -0
- package/api/features/TriggerVisibleTask/abstractions.d.ts +17 -0
- package/api/features/TriggerVisibleTask/abstractions.js +5 -0
- package/api/features/TriggerVisibleTask/abstractions.js.map +1 -0
- package/api/features/TriggerVisibleTask/feature.d.ts +4 -0
- package/api/features/TriggerVisibleTask/feature.js +11 -0
- package/api/features/TriggerVisibleTask/feature.js.map +1 -0
- package/api/features/TriggerVisibleTask/index.d.ts +2 -0
- package/api/features/TriggerVisibleTask/index.js +2 -0
- package/api/features/UpdateBackgroundTaskSettings/UpdateBackgroundTaskSettingsRepository.js +3 -1
- package/api/features/UpdateBackgroundTaskSettings/UpdateBackgroundTaskSettingsRepository.js.map +1 -1
- package/api/features/UpdateTask/UpdateTaskUseCase.d.ts +17 -0
- package/api/features/UpdateTask/UpdateTaskUseCase.js +36 -0
- package/api/features/UpdateTask/UpdateTaskUseCase.js.map +1 -0
- package/api/features/UpdateTask/abstractions.d.ts +22 -0
- package/api/features/UpdateTask/abstractions.js +5 -0
- package/api/features/UpdateTask/abstractions.js.map +1 -0
- package/api/features/UpdateTask/feature.d.ts +4 -0
- package/api/features/UpdateTask/feature.js +11 -0
- package/api/features/UpdateTask/feature.js.map +1 -0
- package/api/features/UpdateTask/index.d.ts +2 -0
- package/api/features/UpdateTask/index.js +2 -0
- package/api/features/UpdateTaskLog/UpdateTaskLogUseCase.d.ts +12 -0
- package/api/features/UpdateTaskLog/UpdateTaskLogUseCase.js +19 -0
- package/api/features/UpdateTaskLog/UpdateTaskLogUseCase.js.map +1 -0
- package/api/features/UpdateTaskLog/abstractions.d.ts +16 -0
- package/api/features/UpdateTaskLog/abstractions.js +5 -0
- package/api/features/UpdateTaskLog/abstractions.js.map +1 -0
- package/api/features/UpdateTaskLog/feature.d.ts +4 -0
- package/api/features/UpdateTaskLog/feature.js +11 -0
- package/api/features/UpdateTaskLog/feature.js.map +1 -0
- package/api/features/UpdateTaskLog/index.d.ts +2 -0
- package/api/features/UpdateTaskLog/index.js +2 -0
- package/api/graphql/BackgroundTasksGraphQLSchema.d.ts +29 -0
- package/api/graphql/BackgroundTasksGraphQLSchema.js +462 -0
- package/api/graphql/BackgroundTasksGraphQLSchema.js.map +1 -0
- package/api/index.d.ts +11 -2
- package/api/index.js +11 -2
- package/api/runner/TaskControl.d.ts +35 -1
- package/api/runner/TaskControl.js +52 -42
- package/api/runner/TaskControl.js.map +1 -1
- package/api/runner/TaskManager.d.ts +12 -1
- package/api/runner/TaskManager.js +11 -10
- package/api/runner/TaskManager.js.map +1 -1
- package/api/runner/TaskManagerStore.d.ts +16 -0
- package/api/runner/TaskManagerStore.js +23 -7
- package/api/runner/TaskManagerStore.js.map +1 -1
- package/api/runner/TaskRunner.js +35 -4
- package/api/runner/TaskRunner.js.map +1 -1
- package/api/tasks/testingRunTask.d.ts +10 -2
- package/api/tasks/testingRunTask.js +10 -3
- package/api/tasks/testingRunTask.js.map +1 -1
- package/api/types.d.ts +1 -48
- package/api/types.js.map +1 -1
- package/package.json +28 -32
- package/testing/index.d.ts +3 -0
- package/testing/index.js +2 -0
- package/testing/mockTaskTriggerTransportPlugin.d.ts +2 -0
- package/testing/mockTaskTriggerTransportPlugin.js +18 -0
- package/testing/mockTaskTriggerTransportPlugin.js.map +1 -0
- package/testing/runner.d.ts +19 -0
- package/testing/runner.js +44 -0
- package/testing/runner.js.map +1 -0
- package/api/TasksCrud.d.ts +0 -10
- package/api/TasksCrud.js +0 -5
- package/api/TasksCrud.js.map +0 -1
- package/api/crud/cleanupTaskSubtree.d.ts +0 -8
- package/api/crud/cleanupTaskSubtree.js +0 -63
- package/api/crud/cleanupTaskSubtree.js.map +0 -1
- package/api/crud/crud.tasks.d.ts +0 -3
- package/api/crud/crud.tasks.js +0 -318
- package/api/crud/crud.tasks.js.map +0 -1
- package/api/crud/definition.tasks.d.ts +0 -3
- package/api/crud/definition.tasks.js +0 -17
- package/api/crud/definition.tasks.js.map +0 -1
- package/api/crud/service.tasks.d.ts +0 -3
- package/api/crud/service.tasks.js +0 -132
- package/api/crud/service.tasks.js.map +0 -1
- package/api/decorators/RunnableTaskDecorator.d.ts +0 -32
- package/api/decorators/RunnableTaskDecorator.js +0 -69
- package/api/decorators/RunnableTaskDecorator.js.map +0 -1
- package/api/decorators/SelfCleaningTaskDecorator.js +0 -84
- package/api/decorators/SelfCleaningTaskDecorator.js.map +0 -1
- package/api/features/GetTaskDefinition/GetTaskDefinitionUseCase.d.ts +0 -12
- package/api/features/GetTaskDefinition/GetTaskDefinitionUseCase.js +0 -27
- package/api/features/GetTaskDefinition/GetTaskDefinitionUseCase.js.map +0 -1
- package/api/features/GetTaskDefinition/abstractions.js +0 -5
- package/api/features/GetTaskDefinition/abstractions.js.map +0 -1
- package/api/features/GetTaskDefinition/feature.js +0 -11
- package/api/features/GetTaskDefinition/feature.js.map +0 -1
- package/api/features/GetTaskDefinition/index.d.ts +0 -2
- package/api/features/GetTaskDefinition/index.js +0 -2
- package/api/graphql/BackgroundTasksContextualSchema.d.ts +0 -21
- package/api/graphql/BackgroundTasksContextualSchema.js +0 -369
- package/api/graphql/BackgroundTasksContextualSchema.js.map +0 -1
- package/api/service/createService.d.ts +0 -6
- package/api/service/createService.js +0 -11
- package/api/service/createService.js.map +0 -1
- package/api/service/index.d.ts +0 -1
- package/api/service/index.js +0 -1
|
@@ -1,11 +1,117 @@
|
|
|
1
|
+
import { Logger } from "@webiny/api-core/features/logger/index.js";
|
|
2
|
+
import { CleanupTaskSubtreeUseCase } from "./abstractions.js";
|
|
3
|
+
import { TaskLogsRepository, TasksRepository } from "../../domain/task/abstractions.js";
|
|
4
|
+
import { DeleteTaskUseCase } from "../DeleteTask/index.js";
|
|
5
|
+
const PAGE_SIZE = 100;
|
|
1
6
|
class CleanupTaskSubtreeUseCaseImpl {
|
|
2
|
-
constructor(
|
|
3
|
-
this.
|
|
7
|
+
constructor(tasks, logs, deleteTask, logger){
|
|
8
|
+
this.tasks = tasks;
|
|
9
|
+
this.logs = logs;
|
|
10
|
+
this.deleteTask = deleteTask;
|
|
11
|
+
this.logger = logger;
|
|
4
12
|
}
|
|
5
|
-
async execute(
|
|
6
|
-
|
|
13
|
+
async execute(rootId) {
|
|
14
|
+
let ordered;
|
|
15
|
+
try {
|
|
16
|
+
ordered = await this.collectSubtree(rootId);
|
|
17
|
+
} catch (error) {
|
|
18
|
+
this.logger.warn({
|
|
19
|
+
error
|
|
20
|
+
}, `cleanupTaskSubtree: failed to collect the subtree of task "${rootId}", skipping.`);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
for (const task of ordered){
|
|
24
|
+
await this.deleteTaskLogs(task);
|
|
25
|
+
const result = await this.deleteTask.execute(task.id);
|
|
26
|
+
if (result.isFail()) this.logger.warn({
|
|
27
|
+
error: result.error
|
|
28
|
+
}, `cleanupTaskSubtree: failed to delete task "${task.id}".`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
async collectSubtree(rootId) {
|
|
32
|
+
const root = await this.tasks.get(rootId);
|
|
33
|
+
if (root.isFail()) return [];
|
|
34
|
+
const order = [
|
|
35
|
+
root.value
|
|
36
|
+
];
|
|
37
|
+
const seen = new Set([
|
|
38
|
+
root.value.id
|
|
39
|
+
]);
|
|
40
|
+
let i = 0;
|
|
41
|
+
while(i < order.length){
|
|
42
|
+
const current = order[i++];
|
|
43
|
+
for (const child of (await this.listChildren(current.id)))if (!seen.has(child.id)) {
|
|
44
|
+
seen.add(child.id);
|
|
45
|
+
order.push(child);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return order.reverse();
|
|
49
|
+
}
|
|
50
|
+
async listChildren(parentId) {
|
|
51
|
+
const children = [];
|
|
52
|
+
let after = null;
|
|
53
|
+
do {
|
|
54
|
+
const params = {
|
|
55
|
+
where: {
|
|
56
|
+
parentId
|
|
57
|
+
},
|
|
58
|
+
limit: PAGE_SIZE,
|
|
59
|
+
after
|
|
60
|
+
};
|
|
61
|
+
const result = await this.tasks.list(params);
|
|
62
|
+
if (result.isFail()) throw result.error;
|
|
63
|
+
const { items, meta } = result.value;
|
|
64
|
+
children.push(...items);
|
|
65
|
+
after = meta.hasMoreItems ? meta.cursor : null;
|
|
66
|
+
}while (after)
|
|
67
|
+
return children;
|
|
68
|
+
}
|
|
69
|
+
async listLogs(taskId) {
|
|
70
|
+
const logs = [];
|
|
71
|
+
let after = null;
|
|
72
|
+
do {
|
|
73
|
+
const params = {
|
|
74
|
+
where: {
|
|
75
|
+
task: taskId
|
|
76
|
+
},
|
|
77
|
+
limit: PAGE_SIZE,
|
|
78
|
+
after
|
|
79
|
+
};
|
|
80
|
+
const result = await this.logs.list(params);
|
|
81
|
+
if (result.isFail()) throw result.error;
|
|
82
|
+
const { items, meta } = result.value;
|
|
83
|
+
logs.push(...items);
|
|
84
|
+
after = meta.hasMoreItems ? meta.cursor : null;
|
|
85
|
+
}while (after)
|
|
86
|
+
return logs;
|
|
87
|
+
}
|
|
88
|
+
async deleteTaskLogs(task) {
|
|
89
|
+
let logs;
|
|
90
|
+
try {
|
|
91
|
+
logs = await this.listLogs(task.id);
|
|
92
|
+
} catch (error) {
|
|
93
|
+
this.logger.warn({
|
|
94
|
+
error
|
|
95
|
+
}, `cleanupTaskSubtree: failed to list logs for task "${task.id}".`);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
for (const log of logs){
|
|
99
|
+
const result = await this.logs.delete(log.id);
|
|
100
|
+
if (result.isFail()) this.logger.warn({
|
|
101
|
+
error: result.error
|
|
102
|
+
}, `cleanupTaskSubtree: failed to delete log "${log.id}" for task "${task.id}".`);
|
|
103
|
+
}
|
|
7
104
|
}
|
|
8
105
|
}
|
|
9
|
-
|
|
106
|
+
const CleanupTaskSubtreeUseCase_CleanupTaskSubtreeUseCase = CleanupTaskSubtreeUseCase.createImplementation({
|
|
107
|
+
implementation: CleanupTaskSubtreeUseCaseImpl,
|
|
108
|
+
dependencies: [
|
|
109
|
+
TasksRepository,
|
|
110
|
+
TaskLogsRepository,
|
|
111
|
+
DeleteTaskUseCase,
|
|
112
|
+
Logger
|
|
113
|
+
]
|
|
114
|
+
});
|
|
115
|
+
export { CleanupTaskSubtreeUseCase_CleanupTaskSubtreeUseCase as CleanupTaskSubtreeUseCase };
|
|
10
116
|
|
|
11
117
|
//# sourceMappingURL=CleanupTaskSubtreeUseCase.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api/features/CleanupTaskSubtree/CleanupTaskSubtreeUseCase.js","sources":["../../../../src/api/features/CleanupTaskSubtree/CleanupTaskSubtreeUseCase.ts"],"sourcesContent":["import { CleanupTaskSubtreeUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport type {
|
|
1
|
+
{"version":3,"file":"api/features/CleanupTaskSubtree/CleanupTaskSubtreeUseCase.js","sources":["../../../../src/api/features/CleanupTaskSubtree/CleanupTaskSubtreeUseCase.ts"],"sourcesContent":["import { Logger } from \"@webiny/api-core/features/logger/index.js\";\nimport { CleanupTaskSubtreeUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { TaskLogsRepository, TasksRepository } from \"~/api/domain/task/abstractions.js\";\nimport { DeleteTaskUseCase } from \"~/api/features/DeleteTask/index.js\";\nimport type { ITask } from \"~/api/types.js\";\nimport type { ITaskLog } from \"~/api/types.js\";\nimport type { IListTaskParams } from \"~/api/types.js\";\nimport type { IListTaskLogParams } from \"~/api/types.js\";\n\nconst PAGE_SIZE = 100;\n\n/**\n * Deletes the task identified by `rootId`, all its descendants, and their logs. The logs are listed\n * by task id whatever the owning definition says (`databaseLogs`, or no registered definition): a\n * self-cleaning task writes none of its own, but an abort still writes one log row, and cleanup\n * removes whatever exists. Bottom-up and best-effort: a record that fails to delete is logged and\n * skipped, and the use case never throws.\n */\nclass CleanupTaskSubtreeUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(\n private readonly tasks: TasksRepository.Interface,\n private readonly logs: TaskLogsRepository.Interface,\n private readonly deleteTask: DeleteTaskUseCase.Interface,\n private readonly logger: Logger.Interface\n ) {}\n\n public async execute(rootId: string): Promise<void> {\n let ordered: ITask[];\n try {\n ordered = await this.collectSubtree(rootId);\n } catch (error) {\n // Without the full subtree, deleting anything could orphan the tasks we didn't find.\n this.logger.warn(\n { error },\n `cleanupTaskSubtree: failed to collect the subtree of task \"${rootId}\", skipping.`\n );\n return;\n }\n for (const task of ordered) {\n await this.deleteTaskLogs(task);\n const result = await this.deleteTask.execute(task.id);\n if (result.isFail()) {\n this.logger.warn(\n { error: result.error },\n `cleanupTaskSubtree: failed to delete task \"${task.id}\".`\n );\n }\n }\n }\n\n // Breadth-first from the root, then reversed, so children are deleted before their parents.\n private async collectSubtree(rootId: string): Promise<ITask[]> {\n const root = await this.tasks.get(rootId);\n if (root.isFail()) {\n return [];\n }\n const order: ITask[] = [root.value];\n const seen = new Set<string>([root.value.id]);\n let i = 0;\n while (i < order.length) {\n const current = order[i++];\n for (const child of await this.listChildren(current.id)) {\n if (seen.has(child.id)) {\n continue;\n }\n seen.add(child.id);\n order.push(child);\n }\n }\n return order.reverse();\n }\n\n // Every page, not just the first: a parent can have more children than one page holds.\n private async listChildren(parentId: string): Promise<ITask[]> {\n const children: ITask[] = [];\n let after: string | null = null;\n do {\n const params: IListTaskParams = { where: { parentId }, limit: PAGE_SIZE, after };\n const result = await this.tasks.list(params);\n if (result.isFail()) {\n throw result.error;\n }\n const { items, meta } = result.value;\n children.push(...items);\n after = meta.hasMoreItems ? meta.cursor : null;\n } while (after);\n return children;\n }\n\n // All pages are read before anything is deleted, so deleting doesn't shift what a cursor sees.\n private async listLogs(taskId: string): Promise<ITaskLog[]> {\n const logs: ITaskLog[] = [];\n let after: string | null = null;\n do {\n const params: IListTaskLogParams = { where: { task: taskId }, limit: PAGE_SIZE, after };\n const result = await this.logs.list(params);\n if (result.isFail()) {\n throw result.error;\n }\n const { items, meta } = result.value;\n logs.push(...items);\n after = meta.hasMoreItems ? meta.cursor : null;\n } while (after);\n return logs;\n }\n\n private async deleteTaskLogs(task: ITask): Promise<void> {\n let logs: ITaskLog[];\n try {\n logs = await this.listLogs(task.id);\n } catch (error) {\n this.logger.warn(\n { error },\n `cleanupTaskSubtree: failed to list logs for task \"${task.id}\".`\n );\n return;\n }\n for (const log of logs) {\n const result = await this.logs.delete(log.id);\n if (result.isFail()) {\n this.logger.warn(\n { error: result.error },\n `cleanupTaskSubtree: failed to delete log \"${log.id}\" for task \"${task.id}\".`\n );\n }\n }\n }\n}\n\nexport const CleanupTaskSubtreeUseCase = UseCaseAbstraction.createImplementation({\n implementation: CleanupTaskSubtreeUseCaseImpl,\n dependencies: [TasksRepository, TaskLogsRepository, DeleteTaskUseCase, Logger]\n});\n"],"names":["PAGE_SIZE","CleanupTaskSubtreeUseCaseImpl","tasks","logs","deleteTask","logger","rootId","ordered","error","task","result","root","order","seen","Set","i","current","child","parentId","children","after","params","items","meta","taskId","log","CleanupTaskSubtreeUseCase","UseCaseAbstraction","TasksRepository","TaskLogsRepository","DeleteTaskUseCase","Logger"],"mappings":"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"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { CleanupTaskSubtreeUseCase } from "./CleanupTaskSubtreeUseCase.js";
|
|
3
|
+
const CleanupTaskSubtreeFeature = createFeature({
|
|
4
|
+
name: "CleanupTaskSubtree",
|
|
5
|
+
register (container) {
|
|
6
|
+
container.register(CleanupTaskSubtreeUseCase);
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
export { CleanupTaskSubtreeFeature };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api/features/CleanupTaskSubtree/feature.js","sources":["../../../../src/api/features/CleanupTaskSubtree/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { CleanupTaskSubtreeUseCase } from \"./CleanupTaskSubtreeUseCase.js\";\n\nexport const CleanupTaskSubtreeFeature = createFeature({\n name: \"CleanupTaskSubtree\",\n register(container) {\n container.register(CleanupTaskSubtreeUseCase);\n }\n});\n"],"names":["CleanupTaskSubtreeFeature","createFeature","container","CleanupTaskSubtreeUseCase"],"mappings":";;AAGO,MAAMA,4BAA4BC,cAAc;IACnD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { CleanupTaskSubtreeUseCase } from "./abstractions.js";
|
|
2
|
-
export {
|
|
2
|
+
export { CleanupTaskSubtreeFeature } from "./feature.js";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { CleanupTaskSubtreeUseCase } from "./abstractions.js";
|
|
2
|
-
export {
|
|
2
|
+
export { CleanupTaskSubtreeFeature } from "./feature.js";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import { EventPublisher } from "@webiny/api-core/features/eventPublisher/index.js";
|
|
3
|
+
import type { TaskService } from "@webiny/api-core/features/task/TaskService/index.js";
|
|
4
|
+
import { CreateTaskUseCase as UseCaseAbstraction } from "./abstractions.js";
|
|
5
|
+
import { GetRunnableTaskDefinitionUseCase } from "../../../api/features/GetRunnableTaskDefinition/index.js";
|
|
6
|
+
import { TasksRepository } from "../../../api/domain/task/abstractions.js";
|
|
7
|
+
declare class CreateTaskUseCaseImpl implements UseCaseAbstraction.Interface {
|
|
8
|
+
private readonly getDefinition;
|
|
9
|
+
private readonly eventPublisher;
|
|
10
|
+
private readonly repository;
|
|
11
|
+
constructor(getDefinition: GetRunnableTaskDefinitionUseCase.Interface, eventPublisher: EventPublisher.Interface, repository: TasksRepository.Interface);
|
|
12
|
+
execute<I extends TaskService.TaskInput = TaskService.TaskInput>(data: UseCaseAbstraction.Params<I>): Promise<Result<TaskService.Task<I>, UseCaseAbstraction.Error>>;
|
|
13
|
+
}
|
|
14
|
+
export declare const CreateTaskUseCase: typeof CreateTaskUseCaseImpl & {
|
|
15
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").ICreateTaskUseCase>;
|
|
16
|
+
};
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import zod from "zod";
|
|
2
|
+
import { Result } from "@webiny/feature/api";
|
|
3
|
+
import { EventPublisher } from "@webiny/api-core/features/eventPublisher/index.js";
|
|
4
|
+
import { CreateTaskUseCase } from "./abstractions.js";
|
|
5
|
+
import { GetRunnableTaskDefinitionUseCase } from "../GetRunnableTaskDefinition/index.js";
|
|
6
|
+
import { TasksRepository } from "../../domain/task/abstractions.js";
|
|
7
|
+
import { TaskInputValidationError } from "../../domain/errors.js";
|
|
8
|
+
import { TaskAfterCreateEvent, TaskBeforeCreateEvent } from "../../events/index.js";
|
|
9
|
+
const toZodSchema = (schema)=>{
|
|
10
|
+
if (!schema) return zod.looseObject({});
|
|
11
|
+
else if (schema instanceof zod.ZodObject) return schema.loose();
|
|
12
|
+
else if (schema instanceof zod.ZodType) return schema;
|
|
13
|
+
return zod.looseObject(schema);
|
|
14
|
+
};
|
|
15
|
+
const validateInput = async (definition, input)=>{
|
|
16
|
+
if (!definition.createInputValidation) return null;
|
|
17
|
+
const schema = toZodSchema(definition.createInputValidation({
|
|
18
|
+
validator: zod
|
|
19
|
+
}));
|
|
20
|
+
const result = await schema.safeParseAsync(input);
|
|
21
|
+
return result.success ? null : result.error;
|
|
22
|
+
};
|
|
23
|
+
class CreateTaskUseCaseImpl {
|
|
24
|
+
constructor(getDefinition, eventPublisher, repository){
|
|
25
|
+
this.getDefinition = getDefinition;
|
|
26
|
+
this.eventPublisher = eventPublisher;
|
|
27
|
+
this.repository = repository;
|
|
28
|
+
}
|
|
29
|
+
async execute(data) {
|
|
30
|
+
const definition = this.getDefinition.execute(data.definitionId);
|
|
31
|
+
if (definition.isFail()) return Result.fail(definition.error);
|
|
32
|
+
const invalid = await validateInput(definition.value, data.input);
|
|
33
|
+
if (invalid) return Result.fail(new TaskInputValidationError(invalid));
|
|
34
|
+
await this.eventPublisher.publish(new TaskBeforeCreateEvent({
|
|
35
|
+
input: data
|
|
36
|
+
}));
|
|
37
|
+
const result = await this.repository.create(data);
|
|
38
|
+
if (result.isFail()) return Result.fail(result.error);
|
|
39
|
+
await this.eventPublisher.publish(new TaskAfterCreateEvent({
|
|
40
|
+
input: data,
|
|
41
|
+
task: result.value
|
|
42
|
+
}));
|
|
43
|
+
return Result.ok(result.value);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const CreateTaskUseCase_CreateTaskUseCase = CreateTaskUseCase.createImplementation({
|
|
47
|
+
implementation: CreateTaskUseCaseImpl,
|
|
48
|
+
dependencies: [
|
|
49
|
+
GetRunnableTaskDefinitionUseCase,
|
|
50
|
+
EventPublisher,
|
|
51
|
+
TasksRepository
|
|
52
|
+
]
|
|
53
|
+
});
|
|
54
|
+
export { CreateTaskUseCase_CreateTaskUseCase as CreateTaskUseCase };
|
|
55
|
+
|
|
56
|
+
//# sourceMappingURL=CreateTaskUseCase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api/features/CreateTask/CreateTaskUseCase.js","sources":["../../../../src/api/features/CreateTask/CreateTaskUseCase.ts"],"sourcesContent":["import zod from \"zod\";\nimport { Result } from \"@webiny/feature/api\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\nimport { EventPublisher } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport type { TaskDefinition } from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\nimport type { TaskService } from \"@webiny/api-core/features/task/TaskService/index.js\";\nimport { CreateTaskUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { GetRunnableTaskDefinitionUseCase } from \"~/api/features/GetRunnableTaskDefinition/index.js\";\nimport { TasksRepository } from \"~/api/domain/task/abstractions.js\";\nimport { TaskInputValidationError } from \"~/api/domain/errors.js\";\nimport { TaskAfterCreateEvent, TaskBeforeCreateEvent } from \"~/api/events/index.js\";\n\ntype InputSchema = GenericRecord<string, zod.ZodTypeAny> | zod.ZodTypeAny;\n\nconst toZodSchema = (schema: InputSchema) => {\n if (!schema) {\n return zod.looseObject({});\n } else if (schema instanceof zod.ZodObject) {\n return schema.loose();\n } else if (schema instanceof zod.ZodType) {\n return schema;\n }\n return zod.looseObject(schema);\n};\n\nconst validateInput = async (\n definition: Pick<TaskDefinition.Runnable, \"createInputValidation\">,\n input: unknown\n): Promise<zod.ZodError | null> => {\n if (!definition.createInputValidation) {\n return null;\n }\n const schema = toZodSchema(definition.createInputValidation({ validator: zod }));\n const result = await schema.safeParseAsync(input);\n return result.success ? null : result.error;\n};\n\nclass CreateTaskUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private readonly getDefinition: GetRunnableTaskDefinitionUseCase.Interface,\n private readonly eventPublisher: EventPublisher.Interface,\n private readonly repository: TasksRepository.Interface\n ) {}\n\n async execute<I extends TaskService.TaskInput = TaskService.TaskInput>(\n data: UseCaseAbstraction.Params<I>\n ): Promise<Result<TaskService.Task<I>, UseCaseAbstraction.Error>> {\n const definition = this.getDefinition.execute(data.definitionId);\n if (definition.isFail()) {\n return Result.fail(definition.error);\n }\n\n const invalid = await validateInput(definition.value, data.input);\n if (invalid) {\n return Result.fail(new TaskInputValidationError(invalid));\n }\n\n await this.eventPublisher.publish(new TaskBeforeCreateEvent({ input: data }));\n\n const result = await this.repository.create<I>(data);\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n await this.eventPublisher.publish(\n new TaskAfterCreateEvent({ input: data, task: result.value })\n );\n\n return Result.ok(result.value);\n }\n}\n\nexport const CreateTaskUseCase = UseCaseAbstraction.createImplementation({\n implementation: CreateTaskUseCaseImpl,\n dependencies: [GetRunnableTaskDefinitionUseCase, EventPublisher, TasksRepository]\n});\n"],"names":["toZodSchema","schema","zod","validateInput","definition","input","result","CreateTaskUseCaseImpl","getDefinition","eventPublisher","repository","data","Result","invalid","TaskInputValidationError","TaskBeforeCreateEvent","TaskAfterCreateEvent","CreateTaskUseCase","UseCaseAbstraction","GetRunnableTaskDefinitionUseCase","EventPublisher","TasksRepository"],"mappings":";;;;;;;;AAcA,MAAMA,cAAc,CAACC;IACjB,IAAI,CAACA,QACD,OAAOC,IAAI,WAAW,CAAC,CAAC;SACrB,IAAID,kBAAkBC,IAAI,SAAS,EACtC,OAAOD,OAAO,KAAK;SAChB,IAAIA,kBAAkBC,IAAI,OAAO,EACpC,OAAOD;IAEX,OAAOC,IAAI,WAAW,CAACD;AAC3B;AAEA,MAAME,gBAAgB,OAClBC,YACAC;IAEA,IAAI,CAACD,WAAW,qBAAqB,EACjC,OAAO;IAEX,MAAMH,SAASD,YAAYI,WAAW,qBAAqB,CAAC;QAAE,WAAWF;IAAI;IAC7E,MAAMI,SAAS,MAAML,OAAO,cAAc,CAACI;IAC3C,OAAOC,OAAO,OAAO,GAAG,OAAOA,OAAO,KAAK;AAC/C;AAEA,MAAMC;IACF,YACqBC,aAAyD,EACzDC,cAAwC,EACxCC,UAAqC,CACxD;aAHmBF,aAAa,GAAbA;aACAC,cAAc,GAAdA;aACAC,UAAU,GAAVA;IAClB;IAEH,MAAM,QACFC,IAAkC,EAC4B;QAC9D,MAAMP,aAAa,IAAI,CAAC,aAAa,CAAC,OAAO,CAACO,KAAK,YAAY;QAC/D,IAAIP,WAAW,MAAM,IACjB,OAAOQ,OAAO,IAAI,CAACR,WAAW,KAAK;QAGvC,MAAMS,UAAU,MAAMV,cAAcC,WAAW,KAAK,EAAEO,KAAK,KAAK;QAChE,IAAIE,SACA,OAAOD,OAAO,IAAI,CAAC,IAAIE,yBAAyBD;QAGpD,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAIE,sBAAsB;YAAE,OAAOJ;QAAK;QAE1E,MAAML,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAAIK;QAC/C,IAAIL,OAAO,MAAM,IACb,OAAOM,OAAO,IAAI,CAACN,OAAO,KAAK;QAGnC,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIU,qBAAqB;YAAE,OAAOL;YAAM,MAAML,OAAO,KAAK;QAAC;QAG/D,OAAOM,OAAO,EAAE,CAACN,OAAO,KAAK;IACjC;AACJ;AAEO,MAAMW,sCAAoBC,kBAAAA,oBAAuC,CAAC;IACrE,gBAAgBX;IAChB,cAAc;QAACY;QAAkCC;QAAgBC;KAAgB;AACrF"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type Result } from "@webiny/feature/api";
|
|
2
|
+
import type { TaskService } from "@webiny/api-core/features/task/TaskService/index.js";
|
|
3
|
+
import type { ITaskCreateData } from "../../../api/types.js";
|
|
4
|
+
import type { BackgroundTaskPersistenceError, TaskDefinitionNotFoundError, TaskInputValidationError } from "../../../api/domain/errors.js";
|
|
5
|
+
export interface ICreateTaskUseCase {
|
|
6
|
+
execute<I extends TaskService.TaskInput = TaskService.TaskInput>(data: ITaskCreateData<I>): Promise<Result<TaskService.Task<I>, UseCaseError>>;
|
|
7
|
+
}
|
|
8
|
+
export interface ICreateTaskUseCaseErrors {
|
|
9
|
+
definitionNotFound: TaskDefinitionNotFoundError;
|
|
10
|
+
validation: TaskInputValidationError;
|
|
11
|
+
persistence: BackgroundTaskPersistenceError;
|
|
12
|
+
}
|
|
13
|
+
type UseCaseError = ICreateTaskUseCaseErrors[keyof ICreateTaskUseCaseErrors];
|
|
14
|
+
/** Store a new task in the pending state. Doesn't send it for execution; see TriggerTaskUseCase. */
|
|
15
|
+
export declare const CreateTaskUseCase: import("@webiny/di").Abstraction<ICreateTaskUseCase>;
|
|
16
|
+
export declare namespace CreateTaskUseCase {
|
|
17
|
+
type Interface = ICreateTaskUseCase;
|
|
18
|
+
type Params<I extends TaskService.TaskInput = TaskService.TaskInput> = ITaskCreateData<I>;
|
|
19
|
+
type Error = UseCaseError;
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api/features/CreateTask/abstractions.js","sources":["../../../../src/api/features/CreateTask/abstractions.ts"],"sourcesContent":["import { createAbstraction, type Result } from \"@webiny/feature/api\";\nimport type { TaskService } from \"@webiny/api-core/features/task/TaskService/index.js\";\nimport type { ITaskCreateData } from \"~/api/types.js\";\nimport type {\n BackgroundTaskPersistenceError,\n TaskDefinitionNotFoundError,\n TaskInputValidationError\n} from \"~/api/domain/errors.js\";\n\nexport interface ICreateTaskUseCase {\n execute<I extends TaskService.TaskInput = TaskService.TaskInput>(\n data: ITaskCreateData<I>\n ): Promise<Result<TaskService.Task<I>, UseCaseError>>;\n}\n\nexport interface ICreateTaskUseCaseErrors {\n definitionNotFound: TaskDefinitionNotFoundError;\n validation: TaskInputValidationError;\n persistence: BackgroundTaskPersistenceError;\n}\n\ntype UseCaseError = ICreateTaskUseCaseErrors[keyof ICreateTaskUseCaseErrors];\n\n/** Store a new task in the pending state. Doesn't send it for execution; see TriggerTaskUseCase. */\nexport const CreateTaskUseCase = createAbstraction<ICreateTaskUseCase>(\"Tasks/CreateTaskUseCase\");\n\nexport namespace CreateTaskUseCase {\n export type Interface = ICreateTaskUseCase;\n export type Params<I extends TaskService.TaskInput = TaskService.TaskInput> =\n ITaskCreateData<I>;\n export type Error = UseCaseError;\n}\n"],"names":["CreateTaskUseCase","createAbstraction"],"mappings":";AAwBO,MAAMA,oBAAoBC,kBAAsC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { CreateTaskUseCase } from "./CreateTaskUseCase.js";
|
|
3
|
+
const CreateTaskFeature = createFeature({
|
|
4
|
+
name: "CreateTask",
|
|
5
|
+
register (container) {
|
|
6
|
+
container.register(CreateTaskUseCase);
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
export { CreateTaskFeature };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api/features/CreateTask/feature.js","sources":["../../../../src/api/features/CreateTask/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { CreateTaskUseCase } from \"./CreateTaskUseCase.js\";\n\nexport const CreateTaskFeature = createFeature({\n name: \"CreateTask\",\n register(container) {\n container.register(CreateTaskUseCase);\n }\n});\n"],"names":["CreateTaskFeature","createFeature","container","CreateTaskUseCase"],"mappings":";;AAGO,MAAMA,oBAAoBC,cAAc;IAC3C,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { CreateTaskLogUseCase as UseCaseAbstraction } from "./abstractions.js";
|
|
2
|
+
import { TaskLogsRepository } from "../../../api/domain/task/abstractions.js";
|
|
3
|
+
import type { TaskService } from "@webiny/api-core/features/task/TaskService/index.js";
|
|
4
|
+
import type { ITaskLogCreateInput } from "../../../api/types.js";
|
|
5
|
+
declare class CreateTaskLogUseCaseImpl implements UseCaseAbstraction.Interface {
|
|
6
|
+
private readonly repository;
|
|
7
|
+
constructor(repository: TaskLogsRepository.Interface);
|
|
8
|
+
execute(task: Pick<TaskService.Task, "id">, data: ITaskLogCreateInput): Promise<import("@webiny/feature/api/Result.js").Result<import("~/api/types.js").ITaskLog, import("../../domain/errors.js").BackgroundTaskPersistenceError>>;
|
|
9
|
+
}
|
|
10
|
+
export declare const CreateTaskLogUseCase: typeof CreateTaskLogUseCaseImpl & {
|
|
11
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").ICreateTaskLogUseCase>;
|
|
12
|
+
};
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { CreateTaskLogUseCase } from "./abstractions.js";
|
|
2
|
+
import { TaskLogsRepository } from "../../domain/task/abstractions.js";
|
|
3
|
+
class CreateTaskLogUseCaseImpl {
|
|
4
|
+
constructor(repository){
|
|
5
|
+
this.repository = repository;
|
|
6
|
+
}
|
|
7
|
+
execute(task, data) {
|
|
8
|
+
return this.repository.create(task, data);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
const CreateTaskLogUseCase_CreateTaskLogUseCase = CreateTaskLogUseCase.createImplementation({
|
|
12
|
+
implementation: CreateTaskLogUseCaseImpl,
|
|
13
|
+
dependencies: [
|
|
14
|
+
TaskLogsRepository
|
|
15
|
+
]
|
|
16
|
+
});
|
|
17
|
+
export { CreateTaskLogUseCase_CreateTaskLogUseCase as CreateTaskLogUseCase };
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=CreateTaskLogUseCase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api/features/CreateTaskLog/CreateTaskLogUseCase.js","sources":["../../../../src/api/features/CreateTaskLog/CreateTaskLogUseCase.ts"],"sourcesContent":["import { CreateTaskLogUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { TaskLogsRepository } from \"~/api/domain/task/abstractions.js\";\nimport type { TaskService } from \"@webiny/api-core/features/task/TaskService/index.js\";\nimport type { ITaskLogCreateInput } from \"~/api/types.js\";\n\nclass CreateTaskLogUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(private readonly repository: TaskLogsRepository.Interface) {}\n\n execute(task: Pick<TaskService.Task, \"id\">, data: ITaskLogCreateInput) {\n return this.repository.create(task, data);\n }\n}\n\nexport const CreateTaskLogUseCase = UseCaseAbstraction.createImplementation({\n implementation: CreateTaskLogUseCaseImpl,\n dependencies: [TaskLogsRepository]\n});\n"],"names":["CreateTaskLogUseCaseImpl","repository","task","data","CreateTaskLogUseCase","UseCaseAbstraction","TaskLogsRepository"],"mappings":";;AAKA,MAAMA;IACF,YAA6BC,UAAwC,CAAE;aAA1CA,UAAU,GAAVA;IAA2C;IAExE,QAAQC,IAAkC,EAAEC,IAAyB,EAAE;QACnE,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAACD,MAAMC;IACxC;AACJ;AAEO,MAAMC,4CAAuBC,qBAAAA,oBAAuC,CAAC;IACxE,gBAAgBL;IAChB,cAAc;QAACM;KAAmB;AACtC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Result } from "@webiny/feature/api";
|
|
2
|
+
import type { TaskService } from "@webiny/api-core/features/task/TaskService/index.js";
|
|
3
|
+
import type { ITaskLog } from "../../../api/types.js";
|
|
4
|
+
import type { ITaskLogCreateInput } from "../../../api/types.js";
|
|
5
|
+
import type { BackgroundTaskPersistenceError } from "../../../api/domain/errors.js";
|
|
6
|
+
type UseCaseError = BackgroundTaskPersistenceError;
|
|
7
|
+
export interface ICreateTaskLogUseCase {
|
|
8
|
+
execute(task: Pick<TaskService.Task, "id">, data: ITaskLogCreateInput): Promise<Result<ITaskLog, UseCaseError>>;
|
|
9
|
+
}
|
|
10
|
+
/** Create a new log for a task run. */
|
|
11
|
+
export declare const CreateTaskLogUseCase: import("@webiny/di").Abstraction<ICreateTaskLogUseCase>;
|
|
12
|
+
export declare namespace CreateTaskLogUseCase {
|
|
13
|
+
type Interface = ICreateTaskLogUseCase;
|
|
14
|
+
type Error = UseCaseError;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api/features/CreateTaskLog/abstractions.js","sources":["../../../../src/api/features/CreateTaskLog/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { Result } from \"@webiny/feature/api\";\nimport type { TaskService } from \"@webiny/api-core/features/task/TaskService/index.js\";\nimport type { ITaskLog } from \"~/api/types.js\";\nimport type { ITaskLogCreateInput } from \"~/api/types.js\";\nimport type { BackgroundTaskPersistenceError } from \"~/api/domain/errors.js\";\n\ntype UseCaseError = BackgroundTaskPersistenceError;\n\nexport interface ICreateTaskLogUseCase {\n execute(\n task: Pick<TaskService.Task, \"id\">,\n data: ITaskLogCreateInput\n ): Promise<Result<ITaskLog, UseCaseError>>;\n}\n\n/** Create a new log for a task run. */\nexport const CreateTaskLogUseCase = createAbstraction<ICreateTaskLogUseCase>(\n \"Tasks/CreateTaskLogUseCase\"\n);\n\nexport namespace CreateTaskLogUseCase {\n export type Interface = ICreateTaskLogUseCase;\n export type Error = UseCaseError;\n}\n"],"names":["CreateTaskLogUseCase","createAbstraction"],"mappings":";AAiBO,MAAMA,uBAAuBC,kBAChC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { CreateTaskLogUseCase } from "./CreateTaskLogUseCase.js";
|
|
3
|
+
const CreateTaskLogFeature = createFeature({
|
|
4
|
+
name: "CreateTaskLog",
|
|
5
|
+
register (container) {
|
|
6
|
+
container.register(CreateTaskLogUseCase);
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
export { CreateTaskLogFeature };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api/features/CreateTaskLog/feature.js","sources":["../../../../src/api/features/CreateTaskLog/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { CreateTaskLogUseCase } from \"./CreateTaskLogUseCase.js\";\n\nexport const CreateTaskLogFeature = createFeature({\n name: \"CreateTaskLog\",\n register(container) {\n container.register(CreateTaskLogUseCase);\n }\n});\n"],"names":["CreateTaskLogFeature","createFeature","container","CreateTaskLogUseCase"],"mappings":";;AAGO,MAAMA,uBAAuBC,cAAc;IAC9C,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import { EventPublisher } from "@webiny/api-core/features/eventPublisher/index.js";
|
|
3
|
+
import { DeleteTaskUseCase as UseCaseAbstraction } from "./abstractions.js";
|
|
4
|
+
import { TasksRepository } from "../../../api/domain/task/abstractions.js";
|
|
5
|
+
declare class DeleteTaskUseCaseImpl implements UseCaseAbstraction.Interface {
|
|
6
|
+
private readonly eventPublisher;
|
|
7
|
+
private readonly repository;
|
|
8
|
+
constructor(eventPublisher: EventPublisher.Interface, repository: TasksRepository.Interface);
|
|
9
|
+
execute(id: string): Promise<Result<void, UseCaseAbstraction.Error>>;
|
|
10
|
+
}
|
|
11
|
+
export declare const DeleteTaskUseCase: typeof DeleteTaskUseCaseImpl & {
|
|
12
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IDeleteTaskUseCase>;
|
|
13
|
+
};
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import { EventPublisher } from "@webiny/api-core/features/eventPublisher/index.js";
|
|
3
|
+
import { DeleteTaskUseCase } from "./abstractions.js";
|
|
4
|
+
import { TasksRepository } from "../../domain/task/abstractions.js";
|
|
5
|
+
import { TaskAfterDeleteEvent, TaskBeforeDeleteEvent } from "../../events/index.js";
|
|
6
|
+
class DeleteTaskUseCaseImpl {
|
|
7
|
+
constructor(eventPublisher, repository){
|
|
8
|
+
this.eventPublisher = eventPublisher;
|
|
9
|
+
this.repository = repository;
|
|
10
|
+
}
|
|
11
|
+
async execute(id) {
|
|
12
|
+
const task = await this.repository.get(id);
|
|
13
|
+
if (task.isFail()) return Result.fail(task.error);
|
|
14
|
+
await this.eventPublisher.publish(new TaskBeforeDeleteEvent({
|
|
15
|
+
task: task.value
|
|
16
|
+
}));
|
|
17
|
+
const result = await this.repository.delete(id);
|
|
18
|
+
if (result.isFail()) return Result.fail(result.error);
|
|
19
|
+
await this.eventPublisher.publish(new TaskAfterDeleteEvent({
|
|
20
|
+
task: task.value
|
|
21
|
+
}));
|
|
22
|
+
return Result.ok();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const DeleteTaskUseCase_DeleteTaskUseCase = DeleteTaskUseCase.createImplementation({
|
|
26
|
+
implementation: DeleteTaskUseCaseImpl,
|
|
27
|
+
dependencies: [
|
|
28
|
+
EventPublisher,
|
|
29
|
+
TasksRepository
|
|
30
|
+
]
|
|
31
|
+
});
|
|
32
|
+
export { DeleteTaskUseCase_DeleteTaskUseCase as DeleteTaskUseCase };
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=DeleteTaskUseCase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api/features/DeleteTask/DeleteTaskUseCase.js","sources":["../../../../src/api/features/DeleteTask/DeleteTaskUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { EventPublisher } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport { DeleteTaskUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { TasksRepository } from \"~/api/domain/task/abstractions.js\";\nimport { TaskAfterDeleteEvent, TaskBeforeDeleteEvent } from \"~/api/events/index.js\";\n\nclass DeleteTaskUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private readonly eventPublisher: EventPublisher.Interface,\n private readonly repository: TasksRepository.Interface\n ) {}\n\n async execute(id: string): Promise<Result<void, UseCaseAbstraction.Error>> {\n const task = await this.repository.get(id);\n if (task.isFail()) {\n return Result.fail(task.error);\n }\n\n await this.eventPublisher.publish(new TaskBeforeDeleteEvent({ task: task.value }));\n\n const result = await this.repository.delete(id);\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n await this.eventPublisher.publish(new TaskAfterDeleteEvent({ task: task.value }));\n\n return Result.ok();\n }\n}\n\nexport const DeleteTaskUseCase = UseCaseAbstraction.createImplementation({\n implementation: DeleteTaskUseCaseImpl,\n dependencies: [EventPublisher, TasksRepository]\n});\n"],"names":["DeleteTaskUseCaseImpl","eventPublisher","repository","id","task","Result","TaskBeforeDeleteEvent","result","TaskAfterDeleteEvent","DeleteTaskUseCase","UseCaseAbstraction","EventPublisher","TasksRepository"],"mappings":";;;;;AAMA,MAAMA;IACF,YACqBC,cAAwC,EACxCC,UAAqC,CACxD;aAFmBD,cAAc,GAAdA;aACAC,UAAU,GAAVA;IAClB;IAEH,MAAM,QAAQC,EAAU,EAAmD;QACvE,MAAMC,OAAO,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,CAACD;QACvC,IAAIC,KAAK,MAAM,IACX,OAAOC,OAAO,IAAI,CAACD,KAAK,KAAK;QAGjC,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAIE,sBAAsB;YAAE,MAAMF,KAAK,KAAK;QAAC;QAE/E,MAAMG,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAACJ;QAC5C,IAAII,OAAO,MAAM,IACb,OAAOF,OAAO,IAAI,CAACE,OAAO,KAAK;QAGnC,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAIC,qBAAqB;YAAE,MAAMJ,KAAK,KAAK;QAAC;QAE9E,OAAOC,OAAO,EAAE;IACpB;AACJ;AAEO,MAAMI,sCAAoBC,kBAAAA,oBAAuC,CAAC;IACrE,gBAAgBV;IAChB,cAAc;QAACW;QAAgBC;KAAgB;AACnD"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type Result } from "@webiny/feature/api";
|
|
2
|
+
import type { BackgroundTaskPersistenceError, TaskNotFoundError } from "../../../api/domain/errors.js";
|
|
3
|
+
export interface IDeleteTaskUseCase {
|
|
4
|
+
execute(id: string): Promise<Result<void, UseCaseError>>;
|
|
5
|
+
}
|
|
6
|
+
export interface IDeleteTaskUseCaseErrors {
|
|
7
|
+
notFound: TaskNotFoundError;
|
|
8
|
+
persistence: BackgroundTaskPersistenceError;
|
|
9
|
+
}
|
|
10
|
+
type UseCaseError = IDeleteTaskUseCaseErrors[keyof IDeleteTaskUseCaseErrors];
|
|
11
|
+
/** Delete a single stored task. Its logs and child tasks stay; see CleanupTaskSubtreeUseCase. */
|
|
12
|
+
export declare const DeleteTaskUseCase: import("@webiny/di").Abstraction<IDeleteTaskUseCase>;
|
|
13
|
+
export declare namespace DeleteTaskUseCase {
|
|
14
|
+
type Interface = IDeleteTaskUseCase;
|
|
15
|
+
type Error = UseCaseError;
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api/features/DeleteTask/abstractions.js","sources":["../../../../src/api/features/DeleteTask/abstractions.ts"],"sourcesContent":["import { createAbstraction, type Result } from \"@webiny/feature/api\";\nimport type { BackgroundTaskPersistenceError, TaskNotFoundError } from \"~/api/domain/errors.js\";\n\nexport interface IDeleteTaskUseCase {\n execute(id: string): Promise<Result<void, UseCaseError>>;\n}\n\nexport interface IDeleteTaskUseCaseErrors {\n notFound: TaskNotFoundError;\n persistence: BackgroundTaskPersistenceError;\n}\n\ntype UseCaseError = IDeleteTaskUseCaseErrors[keyof IDeleteTaskUseCaseErrors];\n\n/** Delete a single stored task. Its logs and child tasks stay; see CleanupTaskSubtreeUseCase. */\nexport const DeleteTaskUseCase = createAbstraction<IDeleteTaskUseCase>(\"Tasks/DeleteTaskUseCase\");\n\nexport namespace DeleteTaskUseCase {\n export type Interface = IDeleteTaskUseCase;\n export type Error = UseCaseError;\n}\n"],"names":["DeleteTaskUseCase","createAbstraction"],"mappings":";AAeO,MAAMA,oBAAoBC,kBAAsC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { DeleteTaskUseCase } from "./DeleteTaskUseCase.js";
|
|
3
|
+
const DeleteTaskFeature = createFeature({
|
|
4
|
+
name: "DeleteTask",
|
|
5
|
+
register (container) {
|
|
6
|
+
container.register(DeleteTaskUseCase);
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
export { DeleteTaskFeature };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api/features/DeleteTask/feature.js","sources":["../../../../src/api/features/DeleteTask/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { DeleteTaskUseCase } from \"./DeleteTaskUseCase.js\";\n\nexport const DeleteTaskFeature = createFeature({\n name: \"DeleteTask\",\n register(container) {\n container.register(DeleteTaskUseCase);\n }\n});\n"],"names":["DeleteTaskFeature","createFeature","container","DeleteTaskUseCase"],"mappings":";;AAGO,MAAMA,oBAAoBC,cAAc;IAC3C,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DeleteTaskLogUseCase as UseCaseAbstraction } from "./abstractions.js";
|
|
2
|
+
import { TaskLogsRepository } from "../../../api/domain/task/abstractions.js";
|
|
3
|
+
declare class DeleteTaskLogUseCaseImpl implements UseCaseAbstraction.Interface {
|
|
4
|
+
private readonly repository;
|
|
5
|
+
constructor(repository: TaskLogsRepository.Interface);
|
|
6
|
+
execute(id: string): Promise<import("@webiny/feature/api/Result.js").Result<void, import("../../domain/errors.js").BackgroundTaskPersistenceError | import("../../domain/errors.js").TaskLogNotFoundError>>;
|
|
7
|
+
}
|
|
8
|
+
export declare const DeleteTaskLogUseCase: typeof DeleteTaskLogUseCaseImpl & {
|
|
9
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IDeleteTaskLogUseCase>;
|
|
10
|
+
};
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { DeleteTaskLogUseCase } from "./abstractions.js";
|
|
2
|
+
import { TaskLogsRepository } from "../../domain/task/abstractions.js";
|
|
3
|
+
class DeleteTaskLogUseCaseImpl {
|
|
4
|
+
constructor(repository){
|
|
5
|
+
this.repository = repository;
|
|
6
|
+
}
|
|
7
|
+
execute(id) {
|
|
8
|
+
return this.repository.delete(id);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
const DeleteTaskLogUseCase_DeleteTaskLogUseCase = DeleteTaskLogUseCase.createImplementation({
|
|
12
|
+
implementation: DeleteTaskLogUseCaseImpl,
|
|
13
|
+
dependencies: [
|
|
14
|
+
TaskLogsRepository
|
|
15
|
+
]
|
|
16
|
+
});
|
|
17
|
+
export { DeleteTaskLogUseCase_DeleteTaskLogUseCase as DeleteTaskLogUseCase };
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=DeleteTaskLogUseCase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api/features/DeleteTaskLog/DeleteTaskLogUseCase.js","sources":["../../../../src/api/features/DeleteTaskLog/DeleteTaskLogUseCase.ts"],"sourcesContent":["import { DeleteTaskLogUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { TaskLogsRepository } from \"~/api/domain/task/abstractions.js\";\n\nclass DeleteTaskLogUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(private readonly repository: TaskLogsRepository.Interface) {}\n\n execute(id: string) {\n return this.repository.delete(id);\n }\n}\n\nexport const DeleteTaskLogUseCase = UseCaseAbstraction.createImplementation({\n implementation: DeleteTaskLogUseCaseImpl,\n dependencies: [TaskLogsRepository]\n});\n"],"names":["DeleteTaskLogUseCaseImpl","repository","id","DeleteTaskLogUseCase","UseCaseAbstraction","TaskLogsRepository"],"mappings":";;AAGA,MAAMA;IACF,YAA6BC,UAAwC,CAAE;aAA1CA,UAAU,GAAVA;IAA2C;IAExE,QAAQC,EAAU,EAAE;QAChB,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAACA;IAClC;AACJ;AAEO,MAAMC,4CAAuBC,qBAAAA,oBAAuC,CAAC;IACxE,gBAAgBJ;IAChB,cAAc;QAACK;KAAmB;AACtC"}
|