@webiny/background-tasks 6.6.0-alpha.1 → 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.
Files changed (245) hide show
  1. package/api/BackgroundTasksFeature.js +42 -24
  2. package/api/BackgroundTasksFeature.js.map +1 -1
  3. package/api/crud/TaskLogPrivateModel.js +2 -1
  4. package/api/crud/TaskLogPrivateModel.js.map +1 -1
  5. package/api/crud/TaskPrivateModel.js +2 -1
  6. package/api/crud/TaskPrivateModel.js.map +1 -1
  7. package/api/decorators/SelfCleaningTaskHandlerDecorator.d.ts +33 -0
  8. package/api/decorators/{SelfCleaningTaskDecorator.js → SelfCleaningTaskHandlerDecorator.js} +15 -39
  9. package/api/decorators/SelfCleaningTaskHandlerDecorator.js.map +1 -0
  10. package/api/decorators/TaskDefinitionDefaultsDecorator.d.ts +27 -0
  11. package/api/decorators/{RunnableTaskDecorator.js → TaskDefinitionDefaultsDecorator.js} +11 -32
  12. package/api/decorators/TaskDefinitionDefaultsDecorator.js.map +1 -0
  13. package/api/domain/errors.d.ts +4 -10
  14. package/api/domain/errors.js +10 -12
  15. package/api/domain/errors.js.map +1 -1
  16. package/api/domain/task/TaskLogModelProvider.d.ts +12 -0
  17. package/api/domain/task/TaskLogModelProvider.js +23 -0
  18. package/api/domain/task/TaskLogModelProvider.js.map +1 -0
  19. package/api/domain/task/TaskLogsRepository.d.ts +34 -0
  20. package/api/domain/task/TaskLogsRepository.js +146 -0
  21. package/api/domain/task/TaskLogsRepository.js.map +1 -0
  22. package/api/domain/task/TaskModelProvider.d.ts +12 -0
  23. package/api/domain/task/TaskModelProvider.js +23 -0
  24. package/api/domain/task/TaskModelProvider.js.map +1 -0
  25. package/api/domain/task/TasksRepository.d.ts +37 -0
  26. package/api/domain/task/TasksRepository.js +126 -0
  27. package/api/domain/task/TasksRepository.js.map +1 -0
  28. package/api/domain/task/abstractions.d.ts +50 -0
  29. package/api/domain/task/abstractions.js +8 -0
  30. package/api/domain/task/abstractions.js.map +1 -0
  31. package/api/domain/task/createRevisionId.d.ts +1 -0
  32. package/api/domain/task/createRevisionId.js +8 -0
  33. package/api/domain/task/createRevisionId.js.map +1 -0
  34. package/api/domain/task/entryToTask.d.ts +3 -0
  35. package/api/domain/task/entryToTask.js +20 -0
  36. package/api/domain/task/entryToTask.js.map +1 -0
  37. package/api/domain/task/entryToTaskLog.d.ts +3 -0
  38. package/api/domain/task/entryToTaskLog.js +12 -0
  39. package/api/domain/task/entryToTaskLog.js.map +1 -0
  40. package/api/features/CleanupTaskSubtree/CleanupTaskSubtreeUseCase.d.ts +25 -5
  41. package/api/features/CleanupTaskSubtree/CleanupTaskSubtreeUseCase.js +111 -5
  42. package/api/features/CleanupTaskSubtree/CleanupTaskSubtreeUseCase.js.map +1 -1
  43. package/api/features/CleanupTaskSubtree/feature.d.ts +4 -0
  44. package/api/features/CleanupTaskSubtree/feature.js +11 -0
  45. package/api/features/CleanupTaskSubtree/feature.js.map +1 -0
  46. package/api/features/CleanupTaskSubtree/index.d.ts +1 -1
  47. package/api/features/CleanupTaskSubtree/index.js +1 -1
  48. package/api/features/CreateTask/CreateTaskUseCase.d.ts +17 -0
  49. package/api/features/CreateTask/CreateTaskUseCase.js +56 -0
  50. package/api/features/CreateTask/CreateTaskUseCase.js.map +1 -0
  51. package/api/features/CreateTask/abstractions.d.ts +21 -0
  52. package/api/features/CreateTask/abstractions.js +5 -0
  53. package/api/features/CreateTask/abstractions.js.map +1 -0
  54. package/api/features/{GetTaskDefinition → CreateTask}/feature.d.ts +1 -1
  55. package/api/features/CreateTask/feature.js +11 -0
  56. package/api/features/CreateTask/feature.js.map +1 -0
  57. package/api/features/CreateTask/index.d.ts +2 -0
  58. package/api/features/CreateTask/index.js +2 -0
  59. package/api/features/CreateTaskLog/CreateTaskLogUseCase.d.ts +13 -0
  60. package/api/features/CreateTaskLog/CreateTaskLogUseCase.js +19 -0
  61. package/api/features/CreateTaskLog/CreateTaskLogUseCase.js.map +1 -0
  62. package/api/features/CreateTaskLog/abstractions.d.ts +16 -0
  63. package/api/features/CreateTaskLog/abstractions.js +5 -0
  64. package/api/features/CreateTaskLog/abstractions.js.map +1 -0
  65. package/api/features/CreateTaskLog/feature.d.ts +4 -0
  66. package/api/features/CreateTaskLog/feature.js +11 -0
  67. package/api/features/CreateTaskLog/feature.js.map +1 -0
  68. package/api/features/CreateTaskLog/index.d.ts +2 -0
  69. package/api/features/CreateTaskLog/index.js +2 -0
  70. package/api/features/DeleteTask/DeleteTaskUseCase.d.ts +14 -0
  71. package/api/features/DeleteTask/DeleteTaskUseCase.js +34 -0
  72. package/api/features/DeleteTask/DeleteTaskUseCase.js.map +1 -0
  73. package/api/features/DeleteTask/abstractions.d.ts +17 -0
  74. package/api/features/DeleteTask/abstractions.js +5 -0
  75. package/api/features/DeleteTask/abstractions.js.map +1 -0
  76. package/api/features/DeleteTask/feature.d.ts +4 -0
  77. package/api/features/DeleteTask/feature.js +11 -0
  78. package/api/features/DeleteTask/feature.js.map +1 -0
  79. package/api/features/DeleteTask/index.d.ts +2 -0
  80. package/api/features/DeleteTask/index.js +2 -0
  81. package/api/features/DeleteTaskLog/DeleteTaskLogUseCase.d.ts +11 -0
  82. package/api/features/DeleteTaskLog/DeleteTaskLogUseCase.js +19 -0
  83. package/api/features/DeleteTaskLog/DeleteTaskLogUseCase.js.map +1 -0
  84. package/api/features/DeleteTaskLog/abstractions.d.ts +14 -0
  85. package/api/features/DeleteTaskLog/abstractions.js +5 -0
  86. package/api/features/DeleteTaskLog/abstractions.js.map +1 -0
  87. package/api/features/DeleteTaskLog/feature.d.ts +4 -0
  88. package/api/features/DeleteTaskLog/feature.js +11 -0
  89. package/api/features/DeleteTaskLog/feature.js.map +1 -0
  90. package/api/features/DeleteTaskLog/index.d.ts +2 -0
  91. package/api/features/DeleteTaskLog/index.js +2 -0
  92. package/api/features/GetLatestTaskLog/GetLatestTaskLogUseCase.d.ts +11 -0
  93. package/api/features/GetLatestTaskLog/GetLatestTaskLogUseCase.js +19 -0
  94. package/api/features/GetLatestTaskLog/GetLatestTaskLogUseCase.js.map +1 -0
  95. package/api/features/GetLatestTaskLog/abstractions.d.ts +15 -0
  96. package/api/features/GetLatestTaskLog/abstractions.js +5 -0
  97. package/api/features/GetLatestTaskLog/abstractions.js.map +1 -0
  98. package/api/features/GetLatestTaskLog/feature.d.ts +4 -0
  99. package/api/features/GetLatestTaskLog/feature.js +11 -0
  100. package/api/features/GetLatestTaskLog/feature.js.map +1 -0
  101. package/api/features/GetLatestTaskLog/index.d.ts +2 -0
  102. package/api/features/GetLatestTaskLog/index.js +2 -0
  103. package/api/features/{GetTaskDefinition/GetTaskDefinitionUseCase.d.ts → GetRunnableTaskDefinition/GetRunnableTaskDefinitionUseCase.d.ts} +5 -7
  104. package/api/features/GetRunnableTaskDefinition/GetRunnableTaskDefinitionUseCase.js +51 -0
  105. package/api/features/GetRunnableTaskDefinition/GetRunnableTaskDefinitionUseCase.js.map +1 -0
  106. package/api/features/{GetTaskDefinition → GetRunnableTaskDefinition}/abstractions.d.ts +7 -8
  107. package/api/features/GetRunnableTaskDefinition/abstractions.js +5 -0
  108. package/api/features/GetRunnableTaskDefinition/abstractions.js.map +1 -0
  109. package/api/features/GetRunnableTaskDefinition/feature.d.ts +4 -0
  110. package/api/features/GetRunnableTaskDefinition/feature.js +11 -0
  111. package/api/features/GetRunnableTaskDefinition/feature.js.map +1 -0
  112. package/api/features/GetRunnableTaskDefinition/index.d.ts +2 -0
  113. package/api/features/GetRunnableTaskDefinition/index.js +2 -0
  114. package/api/features/GetTask/GetTaskUseCase.d.ts +9 -5
  115. package/api/features/GetTask/GetTaskUseCase.js +12 -4
  116. package/api/features/GetTask/GetTaskUseCase.js.map +1 -1
  117. package/api/features/GetTask/abstractions.d.ts +9 -2
  118. package/api/features/GetTask/abstractions.js.map +1 -1
  119. package/api/features/GetTask/feature.js +2 -4
  120. package/api/features/GetTask/feature.js.map +1 -1
  121. package/api/features/ListTaskLogs/ListTaskLogsUseCase.d.ts +12 -0
  122. package/api/features/ListTaskLogs/ListTaskLogsUseCase.js +19 -0
  123. package/api/features/ListTaskLogs/ListTaskLogsUseCase.js.map +1 -0
  124. package/api/features/ListTaskLogs/abstractions.d.ts +15 -0
  125. package/api/features/ListTaskLogs/abstractions.js +5 -0
  126. package/api/features/ListTaskLogs/abstractions.js.map +1 -0
  127. package/api/features/ListTaskLogs/feature.d.ts +4 -0
  128. package/api/features/ListTaskLogs/feature.js +11 -0
  129. package/api/features/ListTaskLogs/feature.js.map +1 -0
  130. package/api/features/ListTaskLogs/index.d.ts +2 -0
  131. package/api/features/ListTaskLogs/index.js +2 -0
  132. package/api/features/ListTasks/ListTasksUseCase.d.ts +9 -6
  133. package/api/features/ListTasks/ListTasksUseCase.js +12 -4
  134. package/api/features/ListTasks/ListTasksUseCase.js.map +1 -1
  135. package/api/features/ListTasks/abstractions.d.ts +9 -3
  136. package/api/features/ListTasks/abstractions.js.map +1 -1
  137. package/api/features/ListTasks/feature.js +2 -4
  138. package/api/features/ListTasks/feature.js.map +1 -1
  139. package/api/features/ListVisibleTaskDefinitions/ListVisibleTaskDefinitionsUseCase.d.ts +11 -0
  140. package/api/features/ListVisibleTaskDefinitions/ListVisibleTaskDefinitionsUseCase.js +19 -0
  141. package/api/features/ListVisibleTaskDefinitions/ListVisibleTaskDefinitionsUseCase.js.map +1 -0
  142. package/api/features/ListVisibleTaskDefinitions/abstractions.d.ts +9 -0
  143. package/api/features/ListVisibleTaskDefinitions/abstractions.js +5 -0
  144. package/api/features/ListVisibleTaskDefinitions/abstractions.js.map +1 -0
  145. package/api/features/ListVisibleTaskDefinitions/feature.d.ts +4 -0
  146. package/api/features/ListVisibleTaskDefinitions/feature.js +11 -0
  147. package/api/features/ListVisibleTaskDefinitions/feature.js.map +1 -0
  148. package/api/features/ListVisibleTaskDefinitions/index.d.ts +2 -0
  149. package/api/features/ListVisibleTaskDefinitions/index.js +2 -0
  150. package/api/features/TaskService/BackgroundTaskService.d.ts +42 -0
  151. package/api/features/TaskService/BackgroundTaskService.js +191 -0
  152. package/api/features/TaskService/BackgroundTaskService.js.map +1 -0
  153. package/api/features/TaskService/feature.d.ts +4 -0
  154. package/api/features/TaskService/feature.js +11 -0
  155. package/api/features/TaskService/feature.js.map +1 -0
  156. package/api/features/TaskService/index.d.ts +1 -0
  157. package/api/features/TaskService/index.js +1 -0
  158. package/api/features/TriggerVisibleTask/TriggerVisibleTaskUseCase.d.ts +15 -0
  159. package/api/features/TriggerVisibleTask/TriggerVisibleTaskUseCase.js +26 -0
  160. package/api/features/TriggerVisibleTask/TriggerVisibleTaskUseCase.js.map +1 -0
  161. package/api/features/TriggerVisibleTask/abstractions.d.ts +17 -0
  162. package/api/features/TriggerVisibleTask/abstractions.js +5 -0
  163. package/api/features/TriggerVisibleTask/abstractions.js.map +1 -0
  164. package/api/features/TriggerVisibleTask/feature.d.ts +4 -0
  165. package/api/features/TriggerVisibleTask/feature.js +11 -0
  166. package/api/features/TriggerVisibleTask/feature.js.map +1 -0
  167. package/api/features/TriggerVisibleTask/index.d.ts +2 -0
  168. package/api/features/TriggerVisibleTask/index.js +2 -0
  169. package/api/features/UpdateBackgroundTaskSettings/UpdateBackgroundTaskSettingsRepository.js +3 -1
  170. package/api/features/UpdateBackgroundTaskSettings/UpdateBackgroundTaskSettingsRepository.js.map +1 -1
  171. package/api/features/UpdateTask/UpdateTaskUseCase.d.ts +17 -0
  172. package/api/features/UpdateTask/UpdateTaskUseCase.js +36 -0
  173. package/api/features/UpdateTask/UpdateTaskUseCase.js.map +1 -0
  174. package/api/features/UpdateTask/abstractions.d.ts +22 -0
  175. package/api/features/UpdateTask/abstractions.js +5 -0
  176. package/api/features/UpdateTask/abstractions.js.map +1 -0
  177. package/api/features/UpdateTask/feature.d.ts +4 -0
  178. package/api/features/UpdateTask/feature.js +11 -0
  179. package/api/features/UpdateTask/feature.js.map +1 -0
  180. package/api/features/UpdateTask/index.d.ts +2 -0
  181. package/api/features/UpdateTask/index.js +2 -0
  182. package/api/features/UpdateTaskLog/UpdateTaskLogUseCase.d.ts +12 -0
  183. package/api/features/UpdateTaskLog/UpdateTaskLogUseCase.js +19 -0
  184. package/api/features/UpdateTaskLog/UpdateTaskLogUseCase.js.map +1 -0
  185. package/api/features/UpdateTaskLog/abstractions.d.ts +16 -0
  186. package/api/features/UpdateTaskLog/abstractions.js +5 -0
  187. package/api/features/UpdateTaskLog/abstractions.js.map +1 -0
  188. package/api/features/UpdateTaskLog/feature.d.ts +4 -0
  189. package/api/features/UpdateTaskLog/feature.js +11 -0
  190. package/api/features/UpdateTaskLog/feature.js.map +1 -0
  191. package/api/features/UpdateTaskLog/index.d.ts +2 -0
  192. package/api/features/UpdateTaskLog/index.js +2 -0
  193. package/api/graphql/BackgroundTasksGraphQLSchema.d.ts +29 -0
  194. package/api/graphql/BackgroundTasksGraphQLSchema.js +462 -0
  195. package/api/graphql/BackgroundTasksGraphQLSchema.js.map +1 -0
  196. package/api/index.d.ts +11 -2
  197. package/api/index.js +11 -2
  198. package/api/runner/TaskControl.d.ts +14 -4
  199. package/api/runner/TaskControl.js +29 -29
  200. package/api/runner/TaskControl.js.map +1 -1
  201. package/api/runner/TaskManager.js +3 -3
  202. package/api/runner/TaskManager.js.map +1 -1
  203. package/api/runner/TaskManagerStore.d.ts +14 -5
  204. package/api/runner/TaskManagerStore.js +23 -7
  205. package/api/runner/TaskManagerStore.js.map +1 -1
  206. package/api/runner/TaskRunner.js +14 -4
  207. package/api/runner/TaskRunner.js.map +1 -1
  208. package/api/types.d.ts +1 -48
  209. package/api/types.js.map +1 -1
  210. package/package.json +28 -30
  211. package/api/TasksCrud.d.ts +0 -10
  212. package/api/TasksCrud.js +0 -5
  213. package/api/TasksCrud.js.map +0 -1
  214. package/api/crud/cleanupTaskSubtree.d.ts +0 -8
  215. package/api/crud/cleanupTaskSubtree.js +0 -63
  216. package/api/crud/cleanupTaskSubtree.js.map +0 -1
  217. package/api/crud/crud.tasks.d.ts +0 -3
  218. package/api/crud/crud.tasks.js +0 -318
  219. package/api/crud/crud.tasks.js.map +0 -1
  220. package/api/crud/definition.tasks.d.ts +0 -3
  221. package/api/crud/definition.tasks.js +0 -17
  222. package/api/crud/definition.tasks.js.map +0 -1
  223. package/api/crud/service.tasks.d.ts +0 -3
  224. package/api/crud/service.tasks.js +0 -134
  225. package/api/crud/service.tasks.js.map +0 -1
  226. package/api/decorators/RunnableTaskDecorator.d.ts +0 -33
  227. package/api/decorators/RunnableTaskDecorator.js.map +0 -1
  228. package/api/decorators/SelfCleaningTaskDecorator.d.ts +0 -33
  229. package/api/decorators/SelfCleaningTaskDecorator.js.map +0 -1
  230. package/api/features/GetTaskDefinition/GetTaskDefinitionUseCase.js +0 -88
  231. package/api/features/GetTaskDefinition/GetTaskDefinitionUseCase.js.map +0 -1
  232. package/api/features/GetTaskDefinition/abstractions.js +0 -5
  233. package/api/features/GetTaskDefinition/abstractions.js.map +0 -1
  234. package/api/features/GetTaskDefinition/feature.js +0 -11
  235. package/api/features/GetTaskDefinition/feature.js.map +0 -1
  236. package/api/features/GetTaskDefinition/index.d.ts +0 -2
  237. package/api/features/GetTaskDefinition/index.js +0 -2
  238. package/api/graphql/BackgroundTasksContextualSchema.d.ts +0 -21
  239. package/api/graphql/BackgroundTasksContextualSchema.js +0 -369
  240. package/api/graphql/BackgroundTasksContextualSchema.js.map +0 -1
  241. package/api/service/createService.d.ts +0 -6
  242. package/api/service/createService.js +0 -11
  243. package/api/service/createService.js.map +0 -1
  244. package/api/service/index.d.ts +0 -1
  245. package/api/service/index.js +0 -1
@@ -1,11 +1,19 @@
1
+ import { ListTasksUseCase } from "./abstractions.js";
2
+ import { TasksRepository } from "../../domain/task/abstractions.js";
1
3
  class ListTasksUseCaseImpl {
2
- constructor(tasksCrud){
3
- this.tasksCrud = tasksCrud;
4
+ constructor(repository){
5
+ this.repository = repository;
4
6
  }
5
7
  async execute(params) {
6
- return await this.tasksCrud.listTasks(params);
8
+ return this.repository.list(params);
7
9
  }
8
10
  }
9
- export { ListTasksUseCaseImpl };
11
+ const ListTasksUseCase_ListTasksUseCase = ListTasksUseCase.createImplementation({
12
+ implementation: ListTasksUseCaseImpl,
13
+ dependencies: [
14
+ TasksRepository
15
+ ]
16
+ });
17
+ export { ListTasksUseCase_ListTasksUseCase as ListTasksUseCase };
10
18
 
11
19
  //# sourceMappingURL=ListTasksUseCase.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"api/features/ListTasks/ListTasksUseCase.js","sources":["../../../../src/api/features/ListTasks/ListTasksUseCase.ts"],"sourcesContent":["import { ListTasksUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { TaskDefinition } from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\nimport { TaskService } from \"@webiny/api-core/features/task/TaskService/index.js\";\nimport type { IListTasksResponse } from \"~/api/types.js\";\nimport type { TasksCrud } from \"~/api/TasksCrud.js\";\n\nexport class ListTasksUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(private tasksCrud: TasksCrud.Interface) {}\n\n async execute<\n I extends TaskDefinition.TaskInput = TaskDefinition.TaskInput,\n O extends TaskService.GenericOutput = TaskService.GenericOutput\n >(params?: UseCaseAbstraction.Params): Promise<IListTasksResponse<I, O>> {\n return await this.tasksCrud.listTasks<I, O>(params);\n }\n}\n"],"names":["ListTasksUseCaseImpl","tasksCrud","params"],"mappings":"AAMO,MAAMA;IACT,YAA2BC,SAA8B,CAAE;aAAhCA,SAAS,GAATA;IAAiC;IAE5D,MAAM,QAGJC,MAAkC,EAAqC;QACrE,OAAO,MAAM,IAAI,CAAC,SAAS,CAAC,SAAS,CAAOA;IAChD;AACJ"}
1
+ {"version":3,"file":"api/features/ListTasks/ListTasksUseCase.js","sources":["../../../../src/api/features/ListTasks/ListTasksUseCase.ts"],"sourcesContent":["import { ListTasksUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { TaskDefinition } from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\nimport { TaskService } from \"@webiny/api-core/features/task/TaskService/index.js\";\nimport { TasksRepository } from \"~/api/domain/task/abstractions.js\";\n\nclass ListTasksUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(private readonly repository: TasksRepository.Interface) {}\n\n async execute<\n I extends TaskDefinition.TaskInput = TaskDefinition.TaskInput,\n O extends TaskService.GenericOutput = TaskService.GenericOutput\n >(params?: UseCaseAbstraction.Params): UseCaseAbstraction.Return<I, O> {\n return this.repository.list<I, O>(params);\n }\n}\n\nexport const ListTasksUseCase = UseCaseAbstraction.createImplementation({\n implementation: ListTasksUseCaseImpl,\n dependencies: [TasksRepository]\n});\n"],"names":["ListTasksUseCaseImpl","repository","params","ListTasksUseCase","UseCaseAbstraction","TasksRepository"],"mappings":";;AAKA,MAAMA;IACF,YAAoCC,UAAqC,CAAE;aAAvCA,UAAU,GAAVA;IAAwC;IAE5E,MAAM,QAGJC,MAAkC,EAAmC;QACnE,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAOA;IACtC;AACJ;AAEO,MAAMC,oCAAmBC,iBAAAA,oBAAuC,CAAC;IACpE,gBAAgBJ;IAChB,cAAc;QAACK;KAAgB;AACnC"}
@@ -1,13 +1,19 @@
1
+ import type { Result } from "@webiny/feature/api";
1
2
  import { TaskService } from "@webiny/api-core/features/task/TaskService/index.js";
2
3
  import { TaskDefinition } from "@webiny/api-core/features/task/TaskDefinition/index.js";
3
- import type { IListTasksResponse, IListTaskParams } from "../../../api/types.js";
4
+ import type { IListTasksResponse } from "../../../api/types.js";
5
+ import type { IListTaskParams } from "../../../api/types.js";
6
+ import type { BackgroundTaskPersistenceError } from "../../../api/domain/errors.js";
7
+ type UseCaseError = BackgroundTaskPersistenceError;
4
8
  export interface IListTasksUseCase {
5
- execute<I extends TaskDefinition.TaskInput = TaskDefinition.TaskInput, O extends TaskService.GenericOutput = TaskService.GenericOutput>(params?: ListTasksParams): Promise<IListTasksResponse<I, O>>;
9
+ execute<I extends TaskDefinition.TaskInput = TaskDefinition.TaskInput, O extends TaskService.GenericOutput = TaskService.GenericOutput>(params?: ListTasksParams): Promise<Result<IListTasksResponse<I, O>, UseCaseError>>;
6
10
  }
7
11
  export type ListTasksParams = IListTaskParams;
8
12
  export declare const ListTasksUseCase: import("@webiny/di").Abstraction<IListTasksUseCase>;
9
13
  export declare namespace ListTasksUseCase {
10
14
  type Interface = IListTasksUseCase;
11
15
  type Params = ListTasksParams;
12
- type Return<I extends TaskDefinition.TaskInput = TaskDefinition.TaskInput, O extends TaskService.GenericOutput = TaskService.GenericOutput> = Promise<IListTasksResponse<I, O>>;
16
+ type Error = UseCaseError;
17
+ type Return<I extends TaskDefinition.TaskInput = TaskDefinition.TaskInput, O extends TaskService.GenericOutput = TaskService.GenericOutput> = Promise<Result<IListTasksResponse<I, O>, UseCaseError>>;
13
18
  }
19
+ export {};
@@ -1 +1 @@
1
- {"version":3,"file":"api/features/ListTasks/abstractions.js","sources":["../../../../src/api/features/ListTasks/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { TaskService } from \"@webiny/api-core/features/task/TaskService/index.js\";\nimport { TaskDefinition } from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\nimport type { IListTasksResponse, IListTaskParams } from \"~/api/types.js\";\n\nexport interface IListTasksUseCase {\n execute<\n I extends TaskDefinition.TaskInput = TaskDefinition.TaskInput,\n O extends TaskService.GenericOutput = TaskService.GenericOutput\n >(\n params?: ListTasksParams\n ): Promise<IListTasksResponse<I, O>>;\n}\n\nexport type ListTasksParams = IListTaskParams;\n\nexport const ListTasksUseCase = createAbstraction<IListTasksUseCase>(\"Tasks/ListTasksUseCase\");\n\nexport namespace ListTasksUseCase {\n export type Interface = IListTasksUseCase;\n export type Params = ListTasksParams;\n\n export type Return<\n I extends TaskDefinition.TaskInput = TaskDefinition.TaskInput,\n O extends TaskService.GenericOutput = TaskService.GenericOutput\n > = Promise<IListTasksResponse<I, O>>;\n}\n"],"names":["ListTasksUseCase","createAbstraction"],"mappings":";AAgBO,MAAMA,mBAAmBC,kBAAqC"}
1
+ {"version":3,"file":"api/features/ListTasks/abstractions.js","sources":["../../../../src/api/features/ListTasks/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { Result } from \"@webiny/feature/api\";\nimport { TaskService } from \"@webiny/api-core/features/task/TaskService/index.js\";\nimport { TaskDefinition } from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\nimport type { IListTasksResponse } from \"~/api/types.js\";\nimport type { IListTaskParams } from \"~/api/types.js\";\nimport type { BackgroundTaskPersistenceError } from \"~/api/domain/errors.js\";\n\ntype UseCaseError = BackgroundTaskPersistenceError;\n\nexport interface IListTasksUseCase {\n execute<\n I extends TaskDefinition.TaskInput = TaskDefinition.TaskInput,\n O extends TaskService.GenericOutput = TaskService.GenericOutput\n >(\n params?: ListTasksParams\n ): Promise<Result<IListTasksResponse<I, O>, UseCaseError>>;\n}\n\nexport type ListTasksParams = IListTaskParams;\n\nexport const ListTasksUseCase = createAbstraction<IListTasksUseCase>(\"Tasks/ListTasksUseCase\");\n\nexport namespace ListTasksUseCase {\n export type Interface = IListTasksUseCase;\n export type Params = ListTasksParams;\n export type Error = UseCaseError;\n\n export type Return<\n I extends TaskDefinition.TaskInput = TaskDefinition.TaskInput,\n O extends TaskService.GenericOutput = TaskService.GenericOutput\n > = Promise<Result<IListTasksResponse<I, O>, UseCaseError>>;\n}\n"],"names":["ListTasksUseCase","createAbstraction"],"mappings":";AAqBO,MAAMA,mBAAmBC,kBAAqC"}
@@ -1,11 +1,9 @@
1
1
  import { createFeature } from "@webiny/feature/api";
2
- import { ListTasksUseCaseImpl } from "./ListTasksUseCase.js";
3
- import { ListTasksUseCase } from "./abstractions.js";
4
- import { TasksCrud } from "../../TasksCrud.js";
2
+ import { ListTasksUseCase } from "./ListTasksUseCase.js";
5
3
  const ListTasksFeature = createFeature({
6
4
  name: "ListTasks",
7
5
  register (container) {
8
- container.registerFactory(ListTasksUseCase, ()=>new ListTasksUseCaseImpl(container.resolve(TasksCrud)));
6
+ container.register(ListTasksUseCase);
9
7
  }
10
8
  });
11
9
  export { ListTasksFeature };
@@ -1 +1 @@
1
- {"version":3,"file":"api/features/ListTasks/feature.js","sources":["../../../../src/api/features/ListTasks/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { ListTasksUseCaseImpl } from \"./ListTasksUseCase.js\";\nimport { ListTasksUseCase } from \"./abstractions.js\";\nimport { TasksCrud } from \"~/api/TasksCrud.js\";\n\nexport const ListTasksFeature = createFeature({\n name: \"ListTasks\",\n register(container) {\n container.registerFactory(ListTasksUseCase, () => {\n return new ListTasksUseCaseImpl(container.resolve(TasksCrud));\n });\n }\n});\n"],"names":["ListTasksFeature","createFeature","container","ListTasksUseCase","ListTasksUseCaseImpl","TasksCrud"],"mappings":";;;;AAKO,MAAMA,mBAAmBC,cAAc;IAC1C,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,eAAe,CAACC,kBAAkB,IACjC,IAAIC,qBAAqBF,UAAU,OAAO,CAACG;IAE1D;AACJ"}
1
+ {"version":3,"file":"api/features/ListTasks/feature.js","sources":["../../../../src/api/features/ListTasks/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { ListTasksUseCase } from \"./ListTasksUseCase.js\";\n\nexport const ListTasksFeature = createFeature({\n name: \"ListTasks\",\n register(container) {\n container.register(ListTasksUseCase);\n }\n});\n"],"names":["ListTasksFeature","createFeature","container","ListTasksUseCase"],"mappings":";;AAGO,MAAMA,mBAAmBC,cAAc;IAC1C,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
@@ -0,0 +1,11 @@
1
+ import { ListVisibleTaskDefinitionsUseCase as UseCaseAbstraction } from "./abstractions.js";
2
+ import { ListTaskDefinitionsUseCase } from "../../../api/features/ListTaskDefinitions/abstractions.js";
3
+ declare class ListVisibleTaskDefinitionsUseCaseImpl implements UseCaseAbstraction.Interface {
4
+ private readonly listTaskDefinitions;
5
+ constructor(listTaskDefinitions: ListTaskDefinitionsUseCase.Interface);
6
+ execute(): import("@webiny/api-core/features/task/TaskDefinition/abstractions.js").TaskDefinition.Interface<import("@webiny/api-core/features/task/TaskDefinition/abstractions.js").ITaskInput, import("@webiny/api-core/features/task/TaskDefinition/abstractions.js").ITaskOutput>[];
7
+ }
8
+ export declare const ListVisibleTaskDefinitionsUseCase: typeof ListVisibleTaskDefinitionsUseCaseImpl & {
9
+ __abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IListVisibleTaskDefinitionsUseCase>;
10
+ };
11
+ export {};
@@ -0,0 +1,19 @@
1
+ import { ListVisibleTaskDefinitionsUseCase } from "./abstractions.js";
2
+ import { ListTaskDefinitionsUseCase } from "../ListTaskDefinitions/abstractions.js";
3
+ class ListVisibleTaskDefinitionsUseCaseImpl {
4
+ constructor(listTaskDefinitions){
5
+ this.listTaskDefinitions = listTaskDefinitions;
6
+ }
7
+ execute() {
8
+ return this.listTaskDefinitions.execute().filter((definition)=>!definition.isPrivate);
9
+ }
10
+ }
11
+ const ListVisibleTaskDefinitionsUseCase_ListVisibleTaskDefinitionsUseCase = ListVisibleTaskDefinitionsUseCase.createImplementation({
12
+ implementation: ListVisibleTaskDefinitionsUseCaseImpl,
13
+ dependencies: [
14
+ ListTaskDefinitionsUseCase
15
+ ]
16
+ });
17
+ export { ListVisibleTaskDefinitionsUseCase_ListVisibleTaskDefinitionsUseCase as ListVisibleTaskDefinitionsUseCase };
18
+
19
+ //# sourceMappingURL=ListVisibleTaskDefinitionsUseCase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api/features/ListVisibleTaskDefinitions/ListVisibleTaskDefinitionsUseCase.js","sources":["../../../../src/api/features/ListVisibleTaskDefinitions/ListVisibleTaskDefinitionsUseCase.ts"],"sourcesContent":["import { ListVisibleTaskDefinitionsUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { ListTaskDefinitionsUseCase } from \"~/api/features/ListTaskDefinitions/abstractions.js\";\n\nclass ListVisibleTaskDefinitionsUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(\n private readonly listTaskDefinitions: ListTaskDefinitionsUseCase.Interface\n ) {}\n\n public execute() {\n return this.listTaskDefinitions.execute().filter(definition => !definition.isPrivate);\n }\n}\n\nexport const ListVisibleTaskDefinitionsUseCase = UseCaseAbstraction.createImplementation({\n implementation: ListVisibleTaskDefinitionsUseCaseImpl,\n dependencies: [ListTaskDefinitionsUseCase]\n});\n"],"names":["ListVisibleTaskDefinitionsUseCaseImpl","listTaskDefinitions","definition","ListVisibleTaskDefinitionsUseCase","UseCaseAbstraction","ListTaskDefinitionsUseCase"],"mappings":";;AAGA,MAAMA;IACF,YACqBC,mBAAyD,CAC5E;aADmBA,mBAAmB,GAAnBA;IAClB;IAEI,UAAU;QACb,OAAO,IAAI,CAAC,mBAAmB,CAAC,OAAO,GAAG,MAAM,CAACC,CAAAA,aAAc,CAACA,WAAW,SAAS;IACxF;AACJ;AAEO,MAAMC,sEAAoCC,kCAAAA,oBAAuC,CAAC;IACrF,gBAAgBJ;IAChB,cAAc;QAACK;KAA2B;AAC9C"}
@@ -0,0 +1,9 @@
1
+ import { TaskDefinition } from "@webiny/api-core/features/task/TaskDefinition/index.js";
2
+ export interface IListVisibleTaskDefinitionsUseCase {
3
+ execute(): TaskDefinition.Interface[];
4
+ }
5
+ /** List task definitions for the GraphQL API, without the private ones. */
6
+ export declare const ListVisibleTaskDefinitionsUseCase: import("@webiny/di").Abstraction<IListVisibleTaskDefinitionsUseCase>;
7
+ export declare namespace ListVisibleTaskDefinitionsUseCase {
8
+ type Interface = IListVisibleTaskDefinitionsUseCase;
9
+ }
@@ -0,0 +1,5 @@
1
+ import { createAbstraction } from "@webiny/feature/api";
2
+ const ListVisibleTaskDefinitionsUseCase = createAbstraction("Tasks/ListVisibleTaskDefinitionsUseCase");
3
+ export { ListVisibleTaskDefinitionsUseCase };
4
+
5
+ //# sourceMappingURL=abstractions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api/features/ListVisibleTaskDefinitions/abstractions.js","sources":["../../../../src/api/features/ListVisibleTaskDefinitions/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { TaskDefinition } from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\n\nexport interface IListVisibleTaskDefinitionsUseCase {\n execute(): TaskDefinition.Interface[];\n}\n\n/** List task definitions for the GraphQL API, without the private ones. */\nexport const ListVisibleTaskDefinitionsUseCase =\n createAbstraction<IListVisibleTaskDefinitionsUseCase>(\n \"Tasks/ListVisibleTaskDefinitionsUseCase\"\n );\n\nexport namespace ListVisibleTaskDefinitionsUseCase {\n export type Interface = IListVisibleTaskDefinitionsUseCase;\n}\n"],"names":["ListVisibleTaskDefinitionsUseCase","createAbstraction"],"mappings":";AAQO,MAAMA,oCACTC,kBACI"}
@@ -0,0 +1,4 @@
1
+ export declare const ListVisibleTaskDefinitionsFeature: {
2
+ name: string;
3
+ register(container: import("@webiny/di").Container): void;
4
+ };
@@ -0,0 +1,11 @@
1
+ import { createFeature } from "@webiny/feature/api";
2
+ import { ListVisibleTaskDefinitionsUseCase } from "./ListVisibleTaskDefinitionsUseCase.js";
3
+ const ListVisibleTaskDefinitionsFeature = createFeature({
4
+ name: "ListVisibleTaskDefinitions",
5
+ register (container) {
6
+ container.register(ListVisibleTaskDefinitionsUseCase);
7
+ }
8
+ });
9
+ export { ListVisibleTaskDefinitionsFeature };
10
+
11
+ //# sourceMappingURL=feature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api/features/ListVisibleTaskDefinitions/feature.js","sources":["../../../../src/api/features/ListVisibleTaskDefinitions/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { ListVisibleTaskDefinitionsUseCase } from \"./ListVisibleTaskDefinitionsUseCase.js\";\n\nexport const ListVisibleTaskDefinitionsFeature = createFeature({\n name: \"ListVisibleTaskDefinitions\",\n register(container) {\n container.register(ListVisibleTaskDefinitionsUseCase);\n }\n});\n"],"names":["ListVisibleTaskDefinitionsFeature","createFeature","container","ListVisibleTaskDefinitionsUseCase"],"mappings":";;AAGO,MAAMA,oCAAoCC,cAAc;IAC3D,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
@@ -0,0 +1,2 @@
1
+ export { ListVisibleTaskDefinitionsUseCase } from "./abstractions.js";
2
+ export { ListVisibleTaskDefinitionsFeature } from "./feature.js";
@@ -0,0 +1,2 @@
1
+ export { ListVisibleTaskDefinitionsUseCase } from "./abstractions.js";
2
+ export { ListVisibleTaskDefinitionsFeature } from "./feature.js";
@@ -0,0 +1,42 @@
1
+ import { BaseError, Result } from "@webiny/feature/api";
2
+ import { Logger } from "@webiny/api-core/features/logger/index.js";
3
+ import { TaskService } from "@webiny/api-core/features/task/TaskService/index.js";
4
+ import type { IServiceInfo, ITaskAbortParams, ITaskTriggerParams } from "@webiny/api-core/features/task/TaskService/abstractions.js";
5
+ import { TaskService as TaskTransport } from "../../../api/domain/TaskService.js";
6
+ import { GetTaskUseCase } from "../../../api/features/GetTask/index.js";
7
+ import { CreateTaskLogUseCase } from "../../../api/features/CreateTaskLog/index.js";
8
+ import { GetLatestTaskLogUseCase } from "../../../api/features/GetLatestTaskLog/index.js";
9
+ import { UpdateTaskLogUseCase } from "../../../api/features/UpdateTaskLog/index.js";
10
+ import { CreateTaskUseCase } from "../../../api/features/CreateTask/index.js";
11
+ import { UpdateTaskUseCase } from "../../../api/features/UpdateTask/index.js";
12
+ import { DeleteTaskUseCase } from "../../../api/features/DeleteTask/index.js";
13
+ import { GetRunnableTaskDefinitionUseCase } from "../../../api/features/GetRunnableTaskDefinition/index.js";
14
+ type TaskInput = TaskService.TaskInput;
15
+ type TaskOutput = TaskService.GenericOutput;
16
+ /**
17
+ * The public TaskService: stores a task and hands it to the transport (Step Functions, the worker),
18
+ * aborts a running task, and reads what the transport knows about one.
19
+ */
20
+ declare class BackgroundTaskServiceImpl implements TaskService.Interface {
21
+ private readonly getDefinition;
22
+ private readonly createTask;
23
+ private readonly updateTask;
24
+ private readonly deleteTask;
25
+ private readonly getTask;
26
+ private readonly getLatestTaskLog;
27
+ private readonly createTaskLog;
28
+ private readonly updateTaskLog;
29
+ private readonly transports;
30
+ private readonly logger;
31
+ constructor(getDefinition: GetRunnableTaskDefinitionUseCase.Interface, createTask: CreateTaskUseCase.Interface, updateTask: UpdateTaskUseCase.Interface, deleteTask: DeleteTaskUseCase.Interface, getTask: GetTaskUseCase.Interface, getLatestTaskLog: GetLatestTaskLogUseCase.Interface, createTaskLog: CreateTaskLogUseCase.Interface, updateTaskLog: UpdateTaskLogUseCase.Interface, transports: TaskTransport.Interface[], logger: Logger.Interface);
32
+ trigger<I extends TaskInput = TaskInput, O extends TaskOutput = TaskOutput>(params: ITaskTriggerParams<I>): Promise<Result<TaskService.Task<I, O>, BaseError>>;
33
+ fetchServiceInfo(input: TaskService.Task | string): Promise<Result<IServiceInfo, BaseError>>;
34
+ abort<I extends TaskInput = TaskInput, O extends TaskOutput = TaskOutput>(params: ITaskAbortParams): Promise<Result<TaskService.Task<I, O>, BaseError<any>>>;
35
+ private findTask;
36
+ private getTransport;
37
+ private getOrCreateLog;
38
+ }
39
+ export declare const BackgroundTaskService: typeof BackgroundTaskServiceImpl & {
40
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/task/TaskService/abstractions.js").ITaskService>;
41
+ };
42
+ export {};
@@ -0,0 +1,191 @@
1
+ import error from "@webiny/error";
2
+ import { Result } from "@webiny/feature/api";
3
+ import { Logger } from "@webiny/api-core/features/logger/index.js";
4
+ import { TaskService } from "@webiny/api-core/features/task/TaskService/index.js";
5
+ import { NotFoundError } from "@webiny/api-graphql";
6
+ import { TaskService as TaskService_js_TaskService } from "../../domain/TaskService.js";
7
+ import { GetTaskUseCase } from "../GetTask/index.js";
8
+ import { CreateTaskLogUseCase } from "../CreateTaskLog/index.js";
9
+ import { GetLatestTaskLogUseCase } from "../GetLatestTaskLog/index.js";
10
+ import { UpdateTaskLogUseCase } from "../UpdateTaskLog/index.js";
11
+ import { CreateTaskUseCase } from "../CreateTask/index.js";
12
+ import { UpdateTaskUseCase } from "../UpdateTask/index.js";
13
+ import { DeleteTaskUseCase } from "../DeleteTask/index.js";
14
+ import { GetRunnableTaskDefinitionUseCase } from "../GetRunnableTaskDefinition/index.js";
15
+ import { TaskAbortError, TaskDefinitionNotFoundError, TaskNotFoundError, TaskServiceInfoError } from "../../domain/errors.js";
16
+ import { TaskDataStatus, TaskLogItemType } from "../../types.js";
17
+ const MAX_DELAY_DAYS = 355;
18
+ const MAX_DELAY_SECONDS = 24 * MAX_DELAY_DAYS * 3600;
19
+ const validateDelay = (input, delay)=>{
20
+ if (!delay || delay < 0 || false === Number.isInteger(delay)) return;
21
+ else if (delay < MAX_DELAY_SECONDS) return;
22
+ throw new error(`The maximum delay for a task is ${MAX_DELAY_DAYS} days.`, "MAX_DELAY_ERROR", {
23
+ ...input,
24
+ delay
25
+ });
26
+ };
27
+ class BackgroundTaskServiceImpl {
28
+ constructor(getDefinition, createTask, updateTask, deleteTask, getTask, getLatestTaskLog, createTaskLog, updateTaskLog, transports, logger){
29
+ this.getDefinition = getDefinition;
30
+ this.createTask = createTask;
31
+ this.updateTask = updateTask;
32
+ this.deleteTask = deleteTask;
33
+ this.getTask = getTask;
34
+ this.getLatestTaskLog = getLatestTaskLog;
35
+ this.createTaskLog = createTaskLog;
36
+ this.updateTaskLog = updateTaskLog;
37
+ this.transports = transports;
38
+ this.logger = logger;
39
+ }
40
+ async trigger(params) {
41
+ const transport = this.getTransport();
42
+ const { definition: id, input: inputValues, name, parent, delay = 0 } = params;
43
+ const definitionResult = this.getDefinition.execute(id);
44
+ if (definitionResult.isFail()) throw new error("Task definition was not found!", "TASK_DEFINITION_ERROR", {
45
+ id
46
+ });
47
+ const definition = definitionResult.value;
48
+ const input = {
49
+ name: name || definition.title,
50
+ definitionId: id,
51
+ input: inputValues || {},
52
+ parentId: parent?.id
53
+ };
54
+ if (definition.onBeforeTrigger) await definition.onBeforeTrigger({
55
+ data: input,
56
+ definition
57
+ });
58
+ validateDelay(input, delay);
59
+ const created = await this.createTask.execute(input);
60
+ if (created.isFail()) {
61
+ this.logger.error({
62
+ error: created.error
63
+ }, "Could not create the task.");
64
+ throw created.error;
65
+ }
66
+ const task = created.value;
67
+ let response = null;
68
+ try {
69
+ response = await transport.send(task, delay);
70
+ if (!response) throw new error("Could not trigger the step function!", "TRIGGER_STEP_FUNCTION_ERROR", {
71
+ task
72
+ });
73
+ } catch (ex) {
74
+ this.logger.error({
75
+ error: ex
76
+ }, "Could not trigger the step function.");
77
+ await this.deleteTask.execute(task.id);
78
+ throw ex;
79
+ }
80
+ const updated = await this.updateTask.execute(task.id, {
81
+ eventResponse: response
82
+ });
83
+ if (updated.isFail()) throw updated.error;
84
+ return Result.ok(updated.value);
85
+ }
86
+ async fetchServiceInfo(input) {
87
+ const transport = this.getTransport();
88
+ const task = "object" == typeof input ? input : await this.findTask(input);
89
+ if (task || "string" != typeof input) {
90
+ if (!task) throw new error("Task was not found!", "TASK_FETCH_ERROR", {
91
+ input
92
+ });
93
+ } else throw new NotFoundError(`Task "${input}" was not found!`);
94
+ try {
95
+ const info = await transport.fetch(task);
96
+ if (info) return Result.ok(info);
97
+ return Result.fail(new TaskServiceInfoError());
98
+ } catch (ex) {
99
+ this.logger.error({
100
+ error: ex
101
+ }, "Service fetch error.");
102
+ return Result.fail(new TaskServiceInfoError());
103
+ }
104
+ }
105
+ async abort(params) {
106
+ const taskResult = await this.getTask.execute(params.id);
107
+ if (taskResult.isFail()) return Result.fail(taskResult.error);
108
+ const task = taskResult.value;
109
+ const definitionResult = this.getDefinition.execute(task.definitionId);
110
+ if (definitionResult.isFail()) return Result.fail(new TaskDefinitionNotFoundError(task.definitionId));
111
+ const definition = definitionResult.value;
112
+ if (false === [
113
+ TaskDataStatus.PENDING,
114
+ TaskDataStatus.RUNNING
115
+ ].includes(task.taskStatus)) return Result.fail(new TaskAbortError({
116
+ id: params.id,
117
+ status: task.taskStatus
118
+ }));
119
+ const taskLog = await this.getOrCreateLog(task);
120
+ try {
121
+ const updated = await this.updateTask.execute(task.id, {
122
+ taskStatus: TaskDataStatus.ABORTED
123
+ });
124
+ if (updated.isFail()) throw updated.error;
125
+ const logUpdate = await this.updateTaskLog.execute(taskLog.id, {
126
+ items: taskLog.items.concat([
127
+ {
128
+ message: params.message || "Task aborted.",
129
+ type: TaskLogItemType.INFO,
130
+ createdOn: new Date().toISOString()
131
+ }
132
+ ])
133
+ });
134
+ if (logUpdate.isFail()) throw logUpdate.error;
135
+ if (definition.onAbort) await definition.onAbort({
136
+ task: updated.value,
137
+ definition
138
+ });
139
+ return Result.ok(updated.value);
140
+ } catch (ex) {
141
+ throw new error("Could not abort the task!", "TASK_ABORT_ERROR", {
142
+ id: params.id,
143
+ message: ex.message
144
+ });
145
+ }
146
+ }
147
+ async findTask(id) {
148
+ const result = await this.getTask.execute(id);
149
+ if (result.isOk()) return result.value;
150
+ else if (result.error instanceof TaskNotFoundError) return null;
151
+ throw result.error;
152
+ }
153
+ getTransport() {
154
+ const transport = this.transports[this.transports.length - 1];
155
+ if (!transport) throw new error("Missing TaskService.", "TASK_SERVICE_ERROR");
156
+ return transport;
157
+ }
158
+ async getOrCreateLog(task) {
159
+ const latest = await this.getLatestTaskLog.execute(task.id);
160
+ if (latest.isOk()) return latest.value;
161
+ const created = await this.createTaskLog.execute(task, {
162
+ iteration: 1,
163
+ executionName: task.executionName
164
+ });
165
+ if (created.isFail()) throw created.error;
166
+ return created.value;
167
+ }
168
+ }
169
+ const BackgroundTaskService = TaskService.createImplementation({
170
+ implementation: BackgroundTaskServiceImpl,
171
+ dependencies: [
172
+ GetRunnableTaskDefinitionUseCase,
173
+ CreateTaskUseCase,
174
+ UpdateTaskUseCase,
175
+ DeleteTaskUseCase,
176
+ GetTaskUseCase,
177
+ GetLatestTaskLogUseCase,
178
+ CreateTaskLogUseCase,
179
+ UpdateTaskLogUseCase,
180
+ [
181
+ TaskService_js_TaskService,
182
+ {
183
+ multiple: true
184
+ }
185
+ ],
186
+ Logger
187
+ ]
188
+ });
189
+ export { BackgroundTaskService };
190
+
191
+ //# sourceMappingURL=BackgroundTaskService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api/features/TaskService/BackgroundTaskService.js","sources":["../../../../src/api/features/TaskService/BackgroundTaskService.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { BaseError, Result } from \"@webiny/feature/api\";\nimport { Logger } from \"@webiny/api-core/features/logger/index.js\";\nimport { TaskService } from \"@webiny/api-core/features/task/TaskService/index.js\";\nimport type {\n IServiceInfo,\n ITaskAbortParams,\n ITaskTriggerParams\n} from \"@webiny/api-core/features/task/TaskService/abstractions.js\";\nimport type { TaskDefinition } from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\nimport { NotFoundError } from \"@webiny/api-graphql\";\nimport { TaskService as TaskTransport } from \"~/api/domain/TaskService.js\";\nimport { GetTaskUseCase } from \"~/api/features/GetTask/index.js\";\nimport { CreateTaskLogUseCase } from \"~/api/features/CreateTaskLog/index.js\";\nimport { GetLatestTaskLogUseCase } from \"~/api/features/GetLatestTaskLog/index.js\";\nimport { UpdateTaskLogUseCase } from \"~/api/features/UpdateTaskLog/index.js\";\nimport { CreateTaskUseCase } from \"~/api/features/CreateTask/index.js\";\nimport { UpdateTaskUseCase } from \"~/api/features/UpdateTask/index.js\";\nimport { DeleteTaskUseCase } from \"~/api/features/DeleteTask/index.js\";\nimport { GetRunnableTaskDefinitionUseCase } from \"~/api/features/GetRunnableTaskDefinition/index.js\";\nimport {\n TaskAbortError,\n TaskDefinitionNotFoundError,\n TaskNotFoundError,\n TaskServiceInfoError\n} from \"~/api/domain/errors.js\";\nimport { TaskDataStatus, TaskLogItemType } from \"~/api/types.js\";\nimport type { ITaskLog } from \"~/api/types.js\";\n\ntype TaskInput = TaskService.TaskInput;\ntype TaskOutput = TaskService.GenericOutput;\n\nconst MAX_DELAY_DAYS = 355;\nconst MAX_DELAY_SECONDS = MAX_DELAY_DAYS * 24 * 60 * 60;\n\nconst validateDelay = (input: TaskDefinition.TaskCreateData<any>, delay: number): void => {\n if (!delay || delay < 0 || Number.isInteger(delay) === false) {\n return;\n } else if (delay < MAX_DELAY_SECONDS) {\n return;\n }\n throw new WebinyError(\n `The maximum delay for a task is ${MAX_DELAY_DAYS} days.`,\n \"MAX_DELAY_ERROR\",\n { ...input, delay }\n );\n};\n\n/**\n * The public TaskService: stores a task and hands it to the transport (Step Functions, the worker),\n * aborts a running task, and reads what the transport knows about one.\n */\nclass BackgroundTaskServiceImpl implements TaskService.Interface {\n constructor(\n private readonly getDefinition: GetRunnableTaskDefinitionUseCase.Interface,\n private readonly createTask: CreateTaskUseCase.Interface,\n private readonly updateTask: UpdateTaskUseCase.Interface,\n private readonly deleteTask: DeleteTaskUseCase.Interface,\n private readonly getTask: GetTaskUseCase.Interface,\n private readonly getLatestTaskLog: GetLatestTaskLogUseCase.Interface,\n private readonly createTaskLog: CreateTaskLogUseCase.Interface,\n private readonly updateTaskLog: UpdateTaskLogUseCase.Interface,\n private readonly transports: TaskTransport.Interface[],\n private readonly logger: Logger.Interface\n ) {}\n\n async trigger<I extends TaskInput = TaskInput, O extends TaskOutput = TaskOutput>(\n params: ITaskTriggerParams<I>\n ): Promise<Result<TaskService.Task<I, O>, BaseError>> {\n const transport = this.getTransport();\n const { definition: id, input: inputValues, name, parent, delay = 0 } = params;\n const definitionResult = this.getDefinition.execute(id);\n if (definitionResult.isFail()) {\n throw new WebinyError(`Task definition was not found!`, \"TASK_DEFINITION_ERROR\", {\n id\n });\n }\n const definition = definitionResult.value;\n const input: TaskDefinition.TaskCreateData<I> = {\n name: name || definition.title,\n definitionId: id,\n input: inputValues || ({} as I),\n parentId: parent?.id\n };\n\n if (definition.onBeforeTrigger) {\n await definition.onBeforeTrigger({ data: input, definition });\n }\n validateDelay(input, delay);\n\n const created = await this.createTask.execute<I>(input);\n if (created.isFail()) {\n this.logger.error({ error: created.error }, \"Could not create the task.\");\n throw created.error;\n }\n const task = created.value;\n\n let response: unknown = null;\n try {\n response = await transport.send(task, delay);\n if (!response) {\n throw new WebinyError(\n `Could not trigger the step function!`,\n \"TRIGGER_STEP_FUNCTION_ERROR\",\n { task }\n );\n }\n } catch (ex) {\n this.logger.error({ error: ex }, \"Could not trigger the step function.\");\n // The task can't run, so don't leave it behind as pending.\n await this.deleteTask.execute(task.id);\n throw ex;\n }\n\n const updated = await this.updateTask.execute<I, O>(task.id, {\n eventResponse: response as Record<string, any>\n });\n if (updated.isFail()) {\n throw updated.error;\n }\n\n return Result.ok(updated.value);\n }\n\n async fetchServiceInfo(\n input: TaskService.Task | string\n ): Promise<Result<IServiceInfo, BaseError>> {\n const transport = this.getTransport();\n const task = typeof input === \"object\" ? input : await this.findTask(input);\n if (!task && typeof input === \"string\") {\n throw new NotFoundError(`Task \"${input}\" was not found!`);\n } else if (!task) {\n throw new WebinyError(`Task was not found!`, \"TASK_FETCH_ERROR\", { input });\n }\n\n try {\n const info = (await transport.fetch(task)) as IServiceInfo | null;\n if (info) {\n return Result.ok(info);\n }\n return Result.fail(new TaskServiceInfoError());\n } catch (ex) {\n this.logger.error({ error: ex }, \"Service fetch error.\");\n return Result.fail(new TaskServiceInfoError());\n }\n }\n\n async abort<I extends TaskInput = TaskInput, O extends TaskOutput = TaskOutput>(\n params: ITaskAbortParams\n ): Promise<Result<TaskService.Task<I, O>, BaseError<any>>> {\n const taskResult = await this.getTask.execute<I, O>(params.id);\n if (taskResult.isFail()) {\n return Result.fail(taskResult.error);\n }\n const task = taskResult.value;\n\n const definitionResult = this.getDefinition.execute<I, O>(task.definitionId);\n if (definitionResult.isFail()) {\n return Result.fail(new TaskDefinitionNotFoundError(task.definitionId));\n }\n const definition = definitionResult.value;\n\n // Only a pending or running task can be aborted.\n if ([TaskDataStatus.PENDING, TaskDataStatus.RUNNING].includes(task.taskStatus) === false) {\n return Result.fail(new TaskAbortError({ id: params.id, status: task.taskStatus }));\n }\n\n const taskLog = await this.getOrCreateLog(task);\n try {\n const updated = await this.updateTask.execute<I, O>(task.id, {\n taskStatus: TaskDataStatus.ABORTED\n });\n if (updated.isFail()) {\n throw updated.error;\n }\n const logUpdate = await this.updateTaskLog.execute(taskLog.id, {\n items: taskLog.items.concat([\n {\n message: params.message || \"Task aborted.\",\n type: TaskLogItemType.INFO,\n createdOn: new Date().toISOString()\n }\n ])\n });\n if (logUpdate.isFail()) {\n throw logUpdate.error;\n }\n // TODO: determine when to kick off the onAbort hook\n if (definition.onAbort) {\n await definition.onAbort({ task: updated.value, definition });\n }\n\n return Result.ok(updated.value);\n } catch (ex) {\n throw new WebinyError(`Could not abort the task!`, \"TASK_ABORT_ERROR\", {\n id: params.id,\n message: ex.message\n });\n }\n }\n\n // A missing task is null; any other failure is thrown, so it isn't mistaken for a missing one.\n private async findTask(id: string): Promise<TaskService.Task | null> {\n const result = await this.getTask.execute(id);\n if (result.isOk()) {\n return result.value;\n } else if (result.error instanceof TaskNotFoundError) {\n return null;\n }\n throw result.error;\n }\n\n private getTransport(): TaskTransport.Interface {\n // The last registration wins, so a test or a deployment can swap the transport.\n const transport = this.transports[this.transports.length - 1];\n if (!transport) {\n throw new WebinyError(\"Missing TaskService.\", \"TASK_SERVICE_ERROR\");\n }\n return transport;\n }\n\n private async getOrCreateLog(task: TaskService.Task<any, any>): Promise<ITaskLog> {\n const latest = await this.getLatestTaskLog.execute(task.id);\n if (latest.isOk()) {\n return latest.value;\n }\n const created = await this.createTaskLog.execute(task, {\n iteration: 1,\n executionName: task.executionName\n });\n if (created.isFail()) {\n throw created.error;\n }\n return created.value;\n }\n}\n\nexport const BackgroundTaskService = TaskService.createImplementation({\n implementation: BackgroundTaskServiceImpl,\n dependencies: [\n GetRunnableTaskDefinitionUseCase,\n CreateTaskUseCase,\n UpdateTaskUseCase,\n DeleteTaskUseCase,\n GetTaskUseCase,\n GetLatestTaskLogUseCase,\n CreateTaskLogUseCase,\n UpdateTaskLogUseCase,\n [TaskTransport, { multiple: true }],\n Logger\n ]\n});\n"],"names":["MAX_DELAY_DAYS","MAX_DELAY_SECONDS","validateDelay","input","delay","Number","WebinyError","BackgroundTaskServiceImpl","getDefinition","createTask","updateTask","deleteTask","getTask","getLatestTaskLog","createTaskLog","updateTaskLog","transports","logger","params","transport","id","inputValues","name","parent","definitionResult","definition","created","task","response","ex","updated","Result","NotFoundError","info","TaskServiceInfoError","taskResult","TaskDefinitionNotFoundError","TaskDataStatus","TaskAbortError","taskLog","logUpdate","TaskLogItemType","Date","result","TaskNotFoundError","latest","BackgroundTaskService","TaskService","GetRunnableTaskDefinitionUseCase","CreateTaskUseCase","UpdateTaskUseCase","DeleteTaskUseCase","GetTaskUseCase","GetLatestTaskLogUseCase","CreateTaskLogUseCase","UpdateTaskLogUseCase","TaskTransport","Logger"],"mappings":"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"}
@@ -0,0 +1,4 @@
1
+ export declare const BackgroundTaskServiceFeature: {
2
+ name: string;
3
+ register(container: import("@webiny/di").Container): void;
4
+ };
@@ -0,0 +1,11 @@
1
+ import { createFeature } from "@webiny/feature/api";
2
+ import { BackgroundTaskService } from "./BackgroundTaskService.js";
3
+ const BackgroundTaskServiceFeature = createFeature({
4
+ name: "BackgroundTaskService",
5
+ register (container) {
6
+ container.register(BackgroundTaskService);
7
+ }
8
+ });
9
+ export { BackgroundTaskServiceFeature };
10
+
11
+ //# sourceMappingURL=feature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api/features/TaskService/feature.js","sources":["../../../../src/api/features/TaskService/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { BackgroundTaskService } from \"./BackgroundTaskService.js\";\n\nexport const BackgroundTaskServiceFeature = createFeature({\n name: \"BackgroundTaskService\",\n register(container) {\n container.register(BackgroundTaskService);\n }\n});\n"],"names":["BackgroundTaskServiceFeature","createFeature","container","BackgroundTaskService"],"mappings":";;AAGO,MAAMA,+BAA+BC,cAAc;IACtD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
@@ -0,0 +1 @@
1
+ export { BackgroundTaskServiceFeature } from "./feature.js";
@@ -0,0 +1 @@
1
+ export { BackgroundTaskServiceFeature } from "./feature.js";
@@ -0,0 +1,15 @@
1
+ import { Result } from "@webiny/feature/api";
2
+ import { TriggerVisibleTaskUseCase as UseCaseAbstraction } from "./abstractions.js";
3
+ import { TriggerTaskUseCase } from "../../../api/features/TriggerTask/abstractions.js";
4
+ import { GetRunnableTaskDefinitionUseCase } from "../../../api/features/GetRunnableTaskDefinition/abstractions.js";
5
+ import { TaskDefinitionNotFoundError } from "../../../api/domain/errors.js";
6
+ declare class TriggerVisibleTaskUseCaseImpl implements UseCaseAbstraction.Interface {
7
+ private readonly triggerTask;
8
+ private readonly getRunnableTaskDefinition;
9
+ constructor(triggerTask: TriggerTaskUseCase.Interface, getRunnableTaskDefinition: GetRunnableTaskDefinitionUseCase.Interface);
10
+ execute(params: TriggerTaskUseCase.Params): Promise<Result<import("@webiny/api-core/features/task/TaskService/abstractions.js").TaskService.Task<import("@webiny/api-core/features/task/TaskDefinition/abstractions.js").ITaskInput, import("@webiny/api-core/features/task/TaskService/abstractions.js").IGenericOutput>, TaskDefinitionNotFoundError | import("~/api/domain/errors.js").TaskNotFoundError | import("~/api/domain/errors.js").TaskServiceInfoError>>;
11
+ }
12
+ export declare const TriggerVisibleTaskUseCase: typeof TriggerVisibleTaskUseCaseImpl & {
13
+ __abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").ITriggerVisibleTaskUseCase>;
14
+ };
15
+ export {};
@@ -0,0 +1,26 @@
1
+ import { Result } from "@webiny/feature/api";
2
+ import { TriggerVisibleTaskUseCase } from "./abstractions.js";
3
+ import { TriggerTaskUseCase } from "../TriggerTask/abstractions.js";
4
+ import { GetRunnableTaskDefinitionUseCase } from "../GetRunnableTaskDefinition/abstractions.js";
5
+ import { TaskDefinitionNotFoundError } from "../../domain/errors.js";
6
+ class TriggerVisibleTaskUseCaseImpl {
7
+ constructor(triggerTask, getRunnableTaskDefinition){
8
+ this.triggerTask = triggerTask;
9
+ this.getRunnableTaskDefinition = getRunnableTaskDefinition;
10
+ }
11
+ async execute(params) {
12
+ const definition = this.getRunnableTaskDefinition.execute(params.definition);
13
+ if (definition.isFail() || definition.value.isPrivate) return Result.fail(new TaskDefinitionNotFoundError(params.definition));
14
+ return this.triggerTask.execute(params);
15
+ }
16
+ }
17
+ const TriggerVisibleTaskUseCase_TriggerVisibleTaskUseCase = TriggerVisibleTaskUseCase.createImplementation({
18
+ implementation: TriggerVisibleTaskUseCaseImpl,
19
+ dependencies: [
20
+ TriggerTaskUseCase,
21
+ GetRunnableTaskDefinitionUseCase
22
+ ]
23
+ });
24
+ export { TriggerVisibleTaskUseCase_TriggerVisibleTaskUseCase as TriggerVisibleTaskUseCase };
25
+
26
+ //# sourceMappingURL=TriggerVisibleTaskUseCase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api/features/TriggerVisibleTask/TriggerVisibleTaskUseCase.js","sources":["../../../../src/api/features/TriggerVisibleTask/TriggerVisibleTaskUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { TriggerVisibleTaskUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { TriggerTaskUseCase } from \"~/api/features/TriggerTask/abstractions.js\";\nimport { GetRunnableTaskDefinitionUseCase } from \"~/api/features/GetRunnableTaskDefinition/abstractions.js\";\nimport { TaskDefinitionNotFoundError } from \"~/api/domain/errors.js\";\n\nclass TriggerVisibleTaskUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(\n private readonly triggerTask: TriggerTaskUseCase.Interface,\n private readonly getRunnableTaskDefinition: GetRunnableTaskDefinitionUseCase.Interface\n ) {}\n\n public async execute(params: TriggerTaskUseCase.Params) {\n const definition = this.getRunnableTaskDefinition.execute(params.definition);\n if (definition.isFail() || definition.value.isPrivate) {\n return Result.fail(new TaskDefinitionNotFoundError(params.definition));\n }\n return this.triggerTask.execute(params);\n }\n}\n\nexport const TriggerVisibleTaskUseCase = UseCaseAbstraction.createImplementation({\n implementation: TriggerVisibleTaskUseCaseImpl,\n dependencies: [TriggerTaskUseCase, GetRunnableTaskDefinitionUseCase]\n});\n"],"names":["TriggerVisibleTaskUseCaseImpl","triggerTask","getRunnableTaskDefinition","params","definition","Result","TaskDefinitionNotFoundError","TriggerVisibleTaskUseCase","UseCaseAbstraction","TriggerTaskUseCase","GetRunnableTaskDefinitionUseCase"],"mappings":";;;;;AAMA,MAAMA;IACF,YACqBC,WAAyC,EACzCC,yBAAqE,CACxF;aAFmBD,WAAW,GAAXA;aACAC,yBAAyB,GAAzBA;IAClB;IAEH,MAAa,QAAQC,MAAiC,EAAE;QACpD,MAAMC,aAAa,IAAI,CAAC,yBAAyB,CAAC,OAAO,CAACD,OAAO,UAAU;QAC3E,IAAIC,WAAW,MAAM,MAAMA,WAAW,KAAK,CAAC,SAAS,EACjD,OAAOC,OAAO,IAAI,CAAC,IAAIC,4BAA4BH,OAAO,UAAU;QAExE,OAAO,IAAI,CAAC,WAAW,CAAC,OAAO,CAACA;IACpC;AACJ;AAEO,MAAMI,sDAA4BC,0BAAAA,oBAAuC,CAAC;IAC7E,gBAAgBR;IAChB,cAAc;QAACS;QAAoBC;KAAiC;AACxE"}
@@ -0,0 +1,17 @@
1
+ import type { Result } from "@webiny/feature/api";
2
+ import type { ITask } from "../../../api/types.js";
3
+ import type { TriggerTaskUseCase } from "../../../api/features/TriggerTask/abstractions.js";
4
+ type UseCaseError = TriggerTaskUseCase.Error;
5
+ export interface ITriggerVisibleTaskUseCase {
6
+ execute(params: TriggerTaskUseCase.Params): Promise<Result<ITask, UseCaseError>>;
7
+ }
8
+ /**
9
+ * Trigger a task from the GraphQL API. A private definition is refused exactly like an unknown
10
+ * one, so a caller cannot tell the two apart and cannot start it with input of their choice.
11
+ */
12
+ export declare const TriggerVisibleTaskUseCase: import("@webiny/di").Abstraction<ITriggerVisibleTaskUseCase>;
13
+ export declare namespace TriggerVisibleTaskUseCase {
14
+ type Interface = ITriggerVisibleTaskUseCase;
15
+ type Error = UseCaseError;
16
+ }
17
+ export {};
@@ -0,0 +1,5 @@
1
+ import { createAbstraction } from "@webiny/feature/api";
2
+ const TriggerVisibleTaskUseCase = createAbstraction("Tasks/TriggerVisibleTaskUseCase");
3
+ export { TriggerVisibleTaskUseCase };
4
+
5
+ //# sourceMappingURL=abstractions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api/features/TriggerVisibleTask/abstractions.js","sources":["../../../../src/api/features/TriggerVisibleTask/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { Result } from \"@webiny/feature/api\";\nimport type { ITask } from \"~/api/types.js\";\nimport type { TriggerTaskUseCase } from \"~/api/features/TriggerTask/abstractions.js\";\n\ntype UseCaseError = TriggerTaskUseCase.Error;\n\nexport interface ITriggerVisibleTaskUseCase {\n execute(params: TriggerTaskUseCase.Params): Promise<Result<ITask, UseCaseError>>;\n}\n\n/**\n * Trigger a task from the GraphQL API. A private definition is refused exactly like an unknown\n * one, so a caller cannot tell the two apart and cannot start it with input of their choice.\n */\nexport const TriggerVisibleTaskUseCase = createAbstraction<ITriggerVisibleTaskUseCase>(\n \"Tasks/TriggerVisibleTaskUseCase\"\n);\n\nexport namespace TriggerVisibleTaskUseCase {\n export type Interface = ITriggerVisibleTaskUseCase;\n export type Error = UseCaseError;\n}\n"],"names":["TriggerVisibleTaskUseCase","createAbstraction"],"mappings":";AAeO,MAAMA,4BAA4BC,kBACrC"}
@@ -0,0 +1,4 @@
1
+ export declare const TriggerVisibleTaskFeature: {
2
+ name: string;
3
+ register(container: import("@webiny/di").Container): void;
4
+ };
@@ -0,0 +1,11 @@
1
+ import { createFeature } from "@webiny/feature/api";
2
+ import { TriggerVisibleTaskUseCase } from "./TriggerVisibleTaskUseCase.js";
3
+ const TriggerVisibleTaskFeature = createFeature({
4
+ name: "TriggerVisibleTask",
5
+ register (container) {
6
+ container.register(TriggerVisibleTaskUseCase);
7
+ }
8
+ });
9
+ export { TriggerVisibleTaskFeature };
10
+
11
+ //# sourceMappingURL=feature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api/features/TriggerVisibleTask/feature.js","sources":["../../../../src/api/features/TriggerVisibleTask/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { TriggerVisibleTaskUseCase } from \"./TriggerVisibleTaskUseCase.js\";\n\nexport const TriggerVisibleTaskFeature = createFeature({\n name: \"TriggerVisibleTask\",\n register(container) {\n container.register(TriggerVisibleTaskUseCase);\n }\n});\n"],"names":["TriggerVisibleTaskFeature","createFeature","container","TriggerVisibleTaskUseCase"],"mappings":";;AAGO,MAAMA,4BAA4BC,cAAc;IACnD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
@@ -0,0 +1,2 @@
1
+ export { TriggerVisibleTaskUseCase } from "./abstractions.js";
2
+ export { TriggerVisibleTaskFeature } from "./feature.js";
@@ -0,0 +1,2 @@
1
+ export { TriggerVisibleTaskUseCase } from "./abstractions.js";
2
+ export { TriggerVisibleTaskFeature } from "./feature.js";