@webiny/background-tasks 0.0.0-unstable.a4f3e4ea8b → 0.0.0-unstable.eb81deee7e

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 (189) hide show
  1. package/admin/BackgroundTaskRoutes.js +16 -3
  2. package/admin/BackgroundTaskRoutes.js.map +1 -1
  3. package/admin/features/listLogs/ListLogsGateway.js +1 -1
  4. package/admin/features/listLogs/ListLogsGateway.js.map +1 -1
  5. package/admin/features/permissions/feature.d.ts +1 -1
  6. package/admin/presentation/BackgroundTaskSettings/BackgroundTaskSettingsPresenter.js +2 -2
  7. package/admin/presentation/BackgroundTaskSettings/BackgroundTaskSettingsPresenter.js.map +1 -1
  8. package/admin/presentation/TaskDetail/TaskDetailPresenter.js +1 -1
  9. package/admin/presentation/TaskDetail/TaskDetailPresenter.js.map +1 -1
  10. package/admin/presentation/TaskExecutions/TaskExecutionsDataSource.js +1 -1
  11. package/admin/presentation/TaskExecutions/TaskExecutionsDataSource.js.map +1 -1
  12. package/api/{features/GetTaskDefinition/feature.d.ts → BackgroundTasksFeature.d.ts} +1 -1
  13. package/api/BackgroundTasksFeature.js +61 -0
  14. package/api/BackgroundTasksFeature.js.map +1 -0
  15. package/api/TasksCrud.d.ts +10 -0
  16. package/api/TasksCrud.js +5 -0
  17. package/api/TasksCrud.js.map +1 -0
  18. package/api/abstractions/Timer.d.ts +1 -0
  19. package/api/abstractions/Timer.js +0 -0
  20. package/api/abstractions/index.d.ts +1 -0
  21. package/api/abstractions/index.js +1 -0
  22. package/api/crud/TaskLogPrivateModel.js +2 -1
  23. package/api/crud/TaskLogPrivateModel.js.map +1 -1
  24. package/api/crud/TaskPrivateModel.js +2 -1
  25. package/api/crud/TaskPrivateModel.js.map +1 -1
  26. package/api/crud/cleanupTaskSubtree.d.ts +2 -2
  27. package/api/crud/cleanupTaskSubtree.js +8 -7
  28. package/api/crud/cleanupTaskSubtree.js.map +1 -1
  29. package/api/crud/crud.tasks.d.ts +3 -2
  30. package/api/crud/crud.tasks.js +46 -44
  31. package/api/crud/crud.tasks.js.map +1 -1
  32. package/api/crud/definition.tasks.d.ts +3 -2
  33. package/api/crud/definition.tasks.js +4 -4
  34. package/api/crud/definition.tasks.js.map +1 -1
  35. package/api/crud/service.tasks.d.ts +3 -2
  36. package/api/crud/service.tasks.js +25 -21
  37. package/api/crud/service.tasks.js.map +1 -1
  38. package/api/decorators/{SelfCleaningTaskDecorator.d.ts → SelfCleaningTaskHandlerDecorator.d.ts} +21 -18
  39. package/api/decorators/SelfCleaningTaskHandlerDecorator.js +69 -0
  40. package/api/decorators/SelfCleaningTaskHandlerDecorator.js.map +1 -0
  41. package/api/decorators/TaskDefinitionDefaultsDecorator.d.ts +27 -0
  42. package/api/decorators/TaskDefinitionDefaultsDecorator.js +47 -0
  43. package/api/decorators/TaskDefinitionDefaultsDecorator.js.map +1 -0
  44. package/api/domain/TaskService.d.ts +12 -0
  45. package/api/domain/TaskService.js +5 -0
  46. package/api/domain/TaskService.js.map +1 -0
  47. package/api/features/AbortTask/AbortTaskUseCase.d.ts +2 -3
  48. package/api/features/AbortTask/AbortTaskUseCase.js +3 -3
  49. package/api/features/AbortTask/AbortTaskUseCase.js.map +1 -1
  50. package/api/features/AbortTask/feature.d.ts +1 -2
  51. package/api/features/AbortTask/feature.js +3 -2
  52. package/api/features/AbortTask/feature.js.map +1 -1
  53. package/api/features/CleanupTaskSubtree/CleanupTaskSubtreeUseCase.d.ts +3 -3
  54. package/api/features/CleanupTaskSubtree/CleanupTaskSubtreeUseCase.js +3 -3
  55. package/api/features/CleanupTaskSubtree/CleanupTaskSubtreeUseCase.js.map +1 -1
  56. package/api/features/GetBackgroundTaskSettings/GetBackgroundTaskSettingsRepository.js +7 -4
  57. package/api/features/GetBackgroundTaskSettings/GetBackgroundTaskSettingsRepository.js.map +1 -1
  58. package/api/features/GetRunnableTaskDefinition/GetRunnableTaskDefinitionUseCase.d.ts +13 -0
  59. package/api/features/GetRunnableTaskDefinition/GetRunnableTaskDefinitionUseCase.js +51 -0
  60. package/api/features/GetRunnableTaskDefinition/GetRunnableTaskDefinitionUseCase.js.map +1 -0
  61. package/api/features/{GetTaskDefinition → GetRunnableTaskDefinition}/abstractions.d.ts +6 -6
  62. package/api/features/GetRunnableTaskDefinition/abstractions.js +5 -0
  63. package/api/features/GetRunnableTaskDefinition/abstractions.js.map +1 -0
  64. package/api/features/GetRunnableTaskDefinition/feature.d.ts +4 -0
  65. package/api/features/GetRunnableTaskDefinition/feature.js +11 -0
  66. package/api/features/GetRunnableTaskDefinition/feature.js.map +1 -0
  67. package/api/features/GetRunnableTaskDefinition/index.d.ts +2 -0
  68. package/api/features/GetRunnableTaskDefinition/index.js +2 -0
  69. package/api/features/GetTask/GetTaskUseCase.d.ts +3 -3
  70. package/api/features/GetTask/GetTaskUseCase.js +3 -3
  71. package/api/features/GetTask/GetTaskUseCase.js.map +1 -1
  72. package/api/features/GetTask/feature.d.ts +1 -2
  73. package/api/features/GetTask/feature.js +3 -2
  74. package/api/features/GetTask/feature.js.map +1 -1
  75. package/api/features/ListTasks/ListTasksUseCase.d.ts +4 -3
  76. package/api/features/ListTasks/ListTasksUseCase.js +3 -3
  77. package/api/features/ListTasks/ListTasksUseCase.js.map +1 -1
  78. package/api/features/ListTasks/feature.d.ts +1 -2
  79. package/api/features/ListTasks/feature.js +3 -2
  80. package/api/features/ListTasks/feature.js.map +1 -1
  81. package/api/features/TaskExecutionContext/TaskExecutionContext.d.ts +3 -3
  82. package/api/features/TaskExecutionContext/TaskExecutionContext.js.map +1 -1
  83. package/api/features/TaskExecutionContext/abstractions.d.ts +3 -3
  84. package/api/features/TaskExecutionContext/abstractions.js.map +1 -1
  85. package/api/features/TaskHandlerResolver/TaskHandlerResolver.d.ts +12 -0
  86. package/api/features/TaskHandlerResolver/TaskHandlerResolver.js +19 -0
  87. package/api/features/TaskHandlerResolver/TaskHandlerResolver.js.map +1 -0
  88. package/api/features/TaskHandlerResolver/abstractions.d.ts +17 -0
  89. package/api/features/TaskHandlerResolver/abstractions.js +5 -0
  90. package/api/features/TaskHandlerResolver/abstractions.js.map +1 -0
  91. package/api/features/TaskHandlerResolver/feature.d.ts +9 -0
  92. package/api/features/TaskHandlerResolver/feature.js +11 -0
  93. package/api/features/TaskHandlerResolver/feature.js.map +1 -0
  94. package/api/features/TaskHandlerResolver/index.d.ts +2 -0
  95. package/api/features/TaskHandlerResolver/index.js +2 -0
  96. package/api/features/TriggerTask/TriggerTaskUseCase.d.ts +2 -3
  97. package/api/features/TriggerTask/TriggerTaskUseCase.js +3 -3
  98. package/api/features/TriggerTask/TriggerTaskUseCase.js.map +1 -1
  99. package/api/features/TriggerTask/feature.d.ts +1 -2
  100. package/api/features/TriggerTask/feature.js +3 -2
  101. package/api/features/TriggerTask/feature.js.map +1 -1
  102. package/api/features/UpdateBackgroundTaskSettings/UpdateBackgroundTaskSettingsRepository.js +6 -3
  103. package/api/features/UpdateBackgroundTaskSettings/UpdateBackgroundTaskSettingsRepository.js.map +1 -1
  104. package/api/graphql/BackgroundTasksGraphQLSchema.d.ts +27 -0
  105. package/api/graphql/BackgroundTasksGraphQLSchema.js +441 -0
  106. package/api/graphql/BackgroundTasksGraphQLSchema.js.map +1 -0
  107. package/api/graphql/checkPermissions.js +2 -1
  108. package/api/graphql/checkPermissions.js.map +1 -1
  109. package/api/graphql/utils.d.ts +1 -1
  110. package/api/graphql/utils.js +1 -1
  111. package/api/graphql/utils.js.map +1 -1
  112. package/api/handler/types.d.ts +0 -2
  113. package/api/index.d.ts +10 -3
  114. package/api/index.js +9 -3
  115. package/api/response/DatabaseResponse.js +1 -1
  116. package/api/response/DatabaseResponse.js.map +1 -1
  117. package/api/runner/TaskControl.d.ts +25 -1
  118. package/api/runner/TaskControl.js +30 -17
  119. package/api/runner/TaskControl.js.map +1 -1
  120. package/api/runner/TaskManager.d.ts +12 -1
  121. package/api/runner/TaskManager.js +8 -6
  122. package/api/runner/TaskManager.js.map +1 -1
  123. package/api/runner/TaskManagerStore.d.ts +10 -2
  124. package/api/runner/TaskManagerStore.js +5 -3
  125. package/api/runner/TaskManagerStore.js.map +1 -1
  126. package/api/runner/TaskRunner.d.ts +3 -3
  127. package/api/runner/TaskRunner.js +25 -4
  128. package/api/runner/TaskRunner.js.map +1 -1
  129. package/api/runner/abstractions/TaskRunner.d.ts +2 -2
  130. package/api/service/createService.d.ts +3 -3
  131. package/api/service/createService.js +5 -10
  132. package/api/service/createService.js.map +1 -1
  133. package/api/service/index.d.ts +1 -4
  134. package/api/service/index.js +1 -12
  135. package/api/tasks/testingRunTask.d.ts +10 -2
  136. package/api/tasks/testingRunTask.js +10 -3
  137. package/api/tasks/testingRunTask.js.map +1 -1
  138. package/api/types.d.ts +2 -2
  139. package/api/types.js.map +1 -1
  140. package/package.json +25 -23
  141. package/testing/index.d.ts +3 -0
  142. package/testing/index.js +2 -0
  143. package/testing/mockTaskTriggerTransportPlugin.d.ts +2 -0
  144. package/testing/mockTaskTriggerTransportPlugin.js +18 -0
  145. package/testing/mockTaskTriggerTransportPlugin.js.map +1 -0
  146. package/testing/runner.d.ts +19 -0
  147. package/testing/runner.js +44 -0
  148. package/testing/runner.js.map +1 -0
  149. package/api/context.d.ts +0 -2
  150. package/api/context.js +0 -66
  151. package/api/context.js.map +0 -1
  152. package/api/decorators/RunnableTaskDecorator.d.ts +0 -32
  153. package/api/decorators/RunnableTaskDecorator.js +0 -69
  154. package/api/decorators/RunnableTaskDecorator.js.map +0 -1
  155. package/api/decorators/SelfCleaningTaskDecorator.js +0 -84
  156. package/api/decorators/SelfCleaningTaskDecorator.js.map +0 -1
  157. package/api/features/GetTaskDefinition/GetTaskDefinitionUseCase.d.ts +0 -12
  158. package/api/features/GetTaskDefinition/GetTaskDefinitionUseCase.js +0 -27
  159. package/api/features/GetTaskDefinition/GetTaskDefinitionUseCase.js.map +0 -1
  160. package/api/features/GetTaskDefinition/abstractions.js +0 -5
  161. package/api/features/GetTaskDefinition/abstractions.js.map +0 -1
  162. package/api/features/GetTaskDefinition/feature.js +0 -11
  163. package/api/features/GetTaskDefinition/feature.js.map +0 -1
  164. package/api/features/GetTaskDefinition/index.d.ts +0 -2
  165. package/api/features/GetTaskDefinition/index.js +0 -2
  166. package/api/graphql/BackgroundTaskSettingsSchema.d.ts +0 -2
  167. package/api/graphql/BackgroundTaskSettingsSchema.js +0 -84
  168. package/api/graphql/BackgroundTaskSettingsSchema.js.map +0 -1
  169. package/api/graphql/index.d.ts +0 -2
  170. package/api/graphql/index.js +0 -301
  171. package/api/graphql/index.js.map +0 -1
  172. package/api/handler/index.d.ts +0 -6
  173. package/api/handler/index.js +0 -55
  174. package/api/handler/index.js.map +0 -1
  175. package/api/handler/register.d.ts +0 -1
  176. package/api/handler/register.js +0 -15
  177. package/api/handler/register.js.map +0 -1
  178. package/api/plugins/TaskServicePlugin.d.ts +0 -19
  179. package/api/plugins/TaskServicePlugin.js +0 -13
  180. package/api/plugins/TaskServicePlugin.js.map +0 -1
  181. package/api/plugins/index.d.ts +0 -1
  182. package/api/plugins/index.js +0 -1
  183. package/api/service/EventBridgeEventTransportPlugin.d.ts +0 -16
  184. package/api/service/EventBridgeEventTransportPlugin.js +0 -52
  185. package/api/service/EventBridgeEventTransportPlugin.js.map +0 -1
  186. package/api/service/StepFunctionServicePlugin.d.ts +0 -25
  187. package/api/service/StepFunctionServicePlugin.js +0 -77
  188. package/api/service/StepFunctionServicePlugin.js.map +0 -1
  189. package/api/service/index.js.map +0 -1
@@ -1,30 +1,33 @@
1
- import { TaskDefinition } from "@webiny/api-core/features/task/TaskDefinition/index.js";
1
+ import { TaskHandler } from "@webiny/api-core/features/task/TaskDefinition/index.js";
2
+ import { Logger } from "@webiny/api-core/features/logger/index.js";
2
3
  import { CleanupTaskSubtreeUseCase } from "../../api/features/CleanupTaskSubtree/index.js";
3
- type LifecycleHook = TaskDefinition.Interface["onDone"];
4
- type HookParams = Parameters<NonNullable<LifecycleHook>>[0];
5
- export declare class SelfCleaningTaskDecoratorImpl implements TaskDefinition.Interface {
4
+ type HookParams = TaskHandler.LifecycleHookParams;
5
+ /**
6
+ * Deletes a finished task, and its descendants, for the events its definition asked for.
7
+ *
8
+ * Registered against `TaskHandler`, so it wraps every task's handler. Which task it is wrapping, and
9
+ * whether that task wants cleaning up, both come from `params.definition` rather than from anything
10
+ * captured at construction: one decorator instance serves whichever handler is resolved.
11
+ *
12
+ * The user's hook runs first and its failure is swallowed, so a task that throws on the way out is
13
+ * still cleaned up. That is what the previous single-object implementation did.
14
+ */
15
+ export declare class SelfCleaningTaskHandlerDecoratorImpl implements TaskHandler.Interface {
6
16
  private readonly cleanupTaskSubtree;
7
- private decoratee;
8
- private readonly events;
9
- constructor(cleanupTaskSubtree: CleanupTaskSubtreeUseCase.Interface, decoratee: TaskDefinition.Interface);
10
- get id(): string;
11
- get title(): string;
12
- get description(): string | undefined;
13
- get isPrivate(): boolean | undefined;
14
- get maxIterations(): number | undefined;
15
- get selfCleanup(): import("@webiny/api-core/features/task/TaskDefinition/abstractions").ISelfCleanup | undefined;
16
- get createInputValidation(): ((params: import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskCreateInputValidationParams) => import("@webiny/api/types").GenericRecord<PropertyKey, import("zod").ZodType<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>> | import("zod").ZodType<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>) | undefined;
17
+ private readonly logger;
18
+ private readonly decoratee;
19
+ constructor(cleanupTaskSubtree: CleanupTaskSubtreeUseCase.Interface, logger: Logger.Interface, decoratee: TaskHandler.Interface);
17
20
  get run(): (params: import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskRunParams<import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskInput, import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskOutput>) => Promise<import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskResult<import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskInput, import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskOutput>>;
18
21
  get onBeforeTrigger(): ((params: import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskBeforeTriggerParams<import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskInput>) => Promise<void>) | undefined;
19
22
  get onMaxIterations(): ((params: import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskLifecycleHook<import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskInput, import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskOutput>) => Promise<void>) | undefined;
20
- get databaseLogs(): boolean | undefined;
23
+ get createInputValidation(): ((params: import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskCreateInputValidationParams) => import("@webiny/api/types").GenericRecord<PropertyKey, import("zod").ZodType<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>> | import("zod").ZodType<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>) | undefined;
21
24
  get onDone(): (params: HookParams) => Promise<void>;
22
25
  get onError(): (params: HookParams) => Promise<void>;
23
26
  get onAbort(): (params: HookParams) => Promise<void>;
24
- private runCleanup;
27
+ private cleanUpIfAsked;
25
28
  private safeCall;
26
29
  }
27
- export declare const SelfCleaningTaskDecorator: typeof SelfCleaningTaskDecoratorImpl & {
28
- __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskDefinition<import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskInput, import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskOutput>>;
30
+ export declare const SelfCleaningTaskHandlerDecorator: typeof SelfCleaningTaskHandlerDecoratorImpl & {
31
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskHandler<import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskInput, import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskOutput>>;
29
32
  };
30
33
  export {};
@@ -0,0 +1,69 @@
1
+ import { TaskHandler } from "@webiny/api-core/features/task/TaskDefinition/index.js";
2
+ import { Logger } from "@webiny/api-core/features/logger/index.js";
3
+ import { normalizeSelfCleanup } from "../utils/normalizeSelfCleanup.js";
4
+ import { CleanupTaskSubtreeUseCase } from "../features/CleanupTaskSubtree/index.js";
5
+ import { getErrorProperties } from "../utils/getErrorProperties.js";
6
+ class SelfCleaningTaskHandlerDecoratorImpl {
7
+ constructor(cleanupTaskSubtree, logger, decoratee){
8
+ this.cleanupTaskSubtree = cleanupTaskSubtree;
9
+ this.logger = logger;
10
+ this.decoratee = decoratee;
11
+ }
12
+ get run() {
13
+ return this.decoratee.run.bind(this.decoratee);
14
+ }
15
+ get onBeforeTrigger() {
16
+ return this.decoratee.onBeforeTrigger?.bind(this.decoratee);
17
+ }
18
+ get onMaxIterations() {
19
+ return this.decoratee.onMaxIterations?.bind(this.decoratee);
20
+ }
21
+ get createInputValidation() {
22
+ return this.decoratee.createInputValidation?.bind(this.decoratee);
23
+ }
24
+ get onDone() {
25
+ return async (params)=>{
26
+ await this.safeCall(this.decoratee.onDone, params, "onDone");
27
+ await this.cleanUpIfAsked(params, "onSuccess");
28
+ };
29
+ }
30
+ get onError() {
31
+ return async (params)=>{
32
+ await this.safeCall(this.decoratee.onError, params, "onError");
33
+ await this.cleanUpIfAsked(params, "onError");
34
+ };
35
+ }
36
+ get onAbort() {
37
+ return async (params)=>{
38
+ await this.safeCall(this.decoratee.onAbort, params, "onAbort");
39
+ await this.cleanUpIfAsked(params, "onAbort");
40
+ };
41
+ }
42
+ async cleanUpIfAsked(params, event) {
43
+ const events = normalizeSelfCleanup(params.definition.selfCleanup);
44
+ if (!events.has(event)) return;
45
+ await this.cleanupTaskSubtree.execute(params.task.id);
46
+ }
47
+ async safeCall(hook, params, name) {
48
+ if (!hook) return;
49
+ try {
50
+ await hook.call(this.decoratee, params);
51
+ } catch (ex) {
52
+ this.logger.error({
53
+ error: getErrorProperties(ex),
54
+ taskId: params.task.id,
55
+ hook: name
56
+ }, "Error executing task lifecycle hook.");
57
+ }
58
+ }
59
+ }
60
+ const SelfCleaningTaskHandlerDecorator = TaskHandler.createDecorator({
61
+ decorator: SelfCleaningTaskHandlerDecoratorImpl,
62
+ dependencies: [
63
+ CleanupTaskSubtreeUseCase,
64
+ Logger
65
+ ]
66
+ });
67
+ export { SelfCleaningTaskHandlerDecorator, SelfCleaningTaskHandlerDecoratorImpl };
68
+
69
+ //# sourceMappingURL=SelfCleaningTaskHandlerDecorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api/decorators/SelfCleaningTaskHandlerDecorator.js","sources":["../../../src/api/decorators/SelfCleaningTaskHandlerDecorator.ts"],"sourcesContent":["import { TaskHandler } from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\nimport { Logger } from \"@webiny/api-core/features/logger/index.js\";\nimport { normalizeSelfCleanup } from \"~/api/utils/normalizeSelfCleanup.js\";\nimport { CleanupTaskSubtreeUseCase } from \"~/api/features/CleanupTaskSubtree/index.js\";\nimport { getErrorProperties } from \"~/api/utils/getErrorProperties.js\";\n\ntype HookParams = TaskHandler.LifecycleHookParams;\n\n/**\n * Deletes a finished task, and its descendants, for the events its definition asked for.\n *\n * Registered against `TaskHandler`, so it wraps every task's handler. Which task it is wrapping, and\n * whether that task wants cleaning up, both come from `params.definition` rather than from anything\n * captured at construction: one decorator instance serves whichever handler is resolved.\n *\n * The user's hook runs first and its failure is swallowed, so a task that throws on the way out is\n * still cleaned up. That is what the previous single-object implementation did.\n */\nexport class SelfCleaningTaskHandlerDecoratorImpl implements TaskHandler.Interface {\n public constructor(\n private readonly cleanupTaskSubtree: CleanupTaskSubtreeUseCase.Interface,\n private readonly logger: Logger.Interface,\n private readonly decoratee: TaskHandler.Interface\n ) {}\n\n get run() {\n return this.decoratee.run.bind(this.decoratee);\n }\n\n get onBeforeTrigger() {\n return this.decoratee.onBeforeTrigger?.bind(this.decoratee);\n }\n\n get onMaxIterations() {\n return this.decoratee.onMaxIterations?.bind(this.decoratee);\n }\n\n get createInputValidation() {\n return this.decoratee.createInputValidation?.bind(this.decoratee);\n }\n\n get onDone() {\n return async (params: HookParams) => {\n await this.safeCall(this.decoratee.onDone, params, \"onDone\");\n await this.cleanUpIfAsked(params, \"onSuccess\");\n };\n }\n\n get onError() {\n return async (params: HookParams) => {\n await this.safeCall(this.decoratee.onError, params, \"onError\");\n await this.cleanUpIfAsked(params, \"onError\");\n };\n }\n\n get onAbort() {\n return async (params: HookParams) => {\n await this.safeCall(this.decoratee.onAbort, params, \"onAbort\");\n await this.cleanUpIfAsked(params, \"onAbort\");\n };\n }\n\n private async cleanUpIfAsked(\n params: HookParams,\n event: \"onSuccess\" | \"onError\" | \"onAbort\"\n ): Promise<void> {\n const events = normalizeSelfCleanup(params.definition.selfCleanup);\n if (!events.has(event)) {\n return;\n }\n\n await this.cleanupTaskSubtree.execute(params.task.id);\n }\n\n private async safeCall(\n hook: TaskHandler.Interface[\"onDone\"],\n params: HookParams,\n name: string\n ): Promise<void> {\n if (!hook) {\n return;\n }\n\n try {\n await hook.call(this.decoratee, params);\n } catch (ex) {\n this.logger.error(\n { error: getErrorProperties(ex), taskId: params.task.id, hook: name },\n \"Error executing task lifecycle hook.\"\n );\n }\n }\n}\n\nexport const SelfCleaningTaskHandlerDecorator = TaskHandler.createDecorator({\n decorator: SelfCleaningTaskHandlerDecoratorImpl,\n dependencies: [CleanupTaskSubtreeUseCase, Logger]\n});\n"],"names":["SelfCleaningTaskHandlerDecoratorImpl","cleanupTaskSubtree","logger","decoratee","params","event","events","normalizeSelfCleanup","hook","name","ex","getErrorProperties","SelfCleaningTaskHandlerDecorator","TaskHandler","CleanupTaskSubtreeUseCase","Logger"],"mappings":";;;;;AAkBO,MAAMA;IACT,YACqBC,kBAAuD,EACvDC,MAAwB,EACxBC,SAAgC,CACnD;aAHmBF,kBAAkB,GAAlBA;aACAC,MAAM,GAANA;aACAC,SAAS,GAATA;IAClB;IAEH,IAAI,MAAM;QACN,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS;IACjD;IAEA,IAAI,kBAAkB;QAClB,OAAO,IAAI,CAAC,SAAS,CAAC,eAAe,EAAE,KAAK,IAAI,CAAC,SAAS;IAC9D;IAEA,IAAI,kBAAkB;QAClB,OAAO,IAAI,CAAC,SAAS,CAAC,eAAe,EAAE,KAAK,IAAI,CAAC,SAAS;IAC9D;IAEA,IAAI,wBAAwB;QACxB,OAAO,IAAI,CAAC,SAAS,CAAC,qBAAqB,EAAE,KAAK,IAAI,CAAC,SAAS;IACpE;IAEA,IAAI,SAAS;QACT,OAAO,OAAOC;YACV,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAEA,QAAQ;YACnD,MAAM,IAAI,CAAC,cAAc,CAACA,QAAQ;QACtC;IACJ;IAEA,IAAI,UAAU;QACV,OAAO,OAAOA;YACV,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,EAAEA,QAAQ;YACpD,MAAM,IAAI,CAAC,cAAc,CAACA,QAAQ;QACtC;IACJ;IAEA,IAAI,UAAU;QACV,OAAO,OAAOA;YACV,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,EAAEA,QAAQ;YACpD,MAAM,IAAI,CAAC,cAAc,CAACA,QAAQ;QACtC;IACJ;IAEA,MAAc,eACVA,MAAkB,EAClBC,KAA0C,EAC7B;QACb,MAAMC,SAASC,qBAAqBH,OAAO,UAAU,CAAC,WAAW;QACjE,IAAI,CAACE,OAAO,GAAG,CAACD,QACZ;QAGJ,MAAM,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAACD,OAAO,IAAI,CAAC,EAAE;IACxD;IAEA,MAAc,SACVI,IAAqC,EACrCJ,MAAkB,EAClBK,IAAY,EACC;QACb,IAAI,CAACD,MACD;QAGJ,IAAI;YACA,MAAMA,KAAK,IAAI,CAAC,IAAI,CAAC,SAAS,EAAEJ;QACpC,EAAE,OAAOM,IAAI;YACT,IAAI,CAAC,MAAM,CAAC,KAAK,CACb;gBAAE,OAAOC,mBAAmBD;gBAAK,QAAQN,OAAO,IAAI,CAAC,EAAE;gBAAE,MAAMK;YAAK,GACpE;QAER;IACJ;AACJ;AAEO,MAAMG,mCAAmCC,YAAY,eAAe,CAAC;IACxE,WAAWb;IACX,cAAc;QAACc;QAA2BC;KAAO;AACrD"}
@@ -0,0 +1,27 @@
1
+ import { TaskDefinition } from "@webiny/api-core/features/task/TaskDefinition/index.js";
2
+ /**
3
+ * Fills in the defaults a definition is allowed to leave out, applies the one rule that overrides
4
+ * what a definition asked for (self-cleanup forces `databaseLogs` off), and rejects an id that is
5
+ * not camelCase.
6
+ *
7
+ * Everything here is metadata. A definition carries no behaviour, so there is nothing to forward:
8
+ * `GetRunnableTaskDefinitionUseCase` takes `run` and the hooks from the handler that `handler` names, after
9
+ * this decorator has run.
10
+ */
11
+ export declare class TaskDefinitionDefaultsDecoratorImpl implements TaskDefinition.Interface {
12
+ private decoratee;
13
+ private readonly cleansUp;
14
+ constructor(decoratee: TaskDefinition.Interface);
15
+ get id(): string;
16
+ get title(): string;
17
+ get description(): string | undefined;
18
+ get handler(): import("@webiny/di").Constructor<import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskHandler<import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskInput, import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskOutput>>;
19
+ get isPrivate(): boolean;
20
+ get databaseLogs(): boolean;
21
+ get maxIterations(): number;
22
+ get selfCleanup(): import("@webiny/api-core/features/task/TaskDefinition/abstractions").ISelfCleanup | undefined;
23
+ private validate;
24
+ }
25
+ export declare const TaskDefinitionDefaultsDecorator: typeof TaskDefinitionDefaultsDecoratorImpl & {
26
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskDefinition<import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskInput, import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskOutput>>;
27
+ };
@@ -0,0 +1,47 @@
1
+ import camelCase from "lodash/camelCase.js";
2
+ import error from "@webiny/error";
3
+ import { TaskDefinition } from "@webiny/api-core/features/task/TaskDefinition/index.js";
4
+ import { normalizeSelfCleanup } from "../utils/normalizeSelfCleanup.js";
5
+ const DEFAULT_MAX_ITERATIONS = 50;
6
+ class TaskDefinitionDefaultsDecoratorImpl {
7
+ constructor(decoratee){
8
+ this.decoratee = decoratee;
9
+ this.validate();
10
+ this.cleansUp = normalizeSelfCleanup(decoratee.selfCleanup).size > 0;
11
+ }
12
+ get id() {
13
+ return this.decoratee.id;
14
+ }
15
+ get title() {
16
+ return this.decoratee.title;
17
+ }
18
+ get description() {
19
+ return this.decoratee.description;
20
+ }
21
+ get handler() {
22
+ return this.decoratee.handler;
23
+ }
24
+ get isPrivate() {
25
+ return this.decoratee.isPrivate || false;
26
+ }
27
+ get databaseLogs() {
28
+ if (this.cleansUp) return false;
29
+ return this.decoratee.databaseLogs || false;
30
+ }
31
+ get maxIterations() {
32
+ return this.decoratee.maxIterations || DEFAULT_MAX_ITERATIONS;
33
+ }
34
+ get selfCleanup() {
35
+ return this.decoratee.selfCleanup;
36
+ }
37
+ validate() {
38
+ if (camelCase(this.decoratee.id) !== this.decoratee.id) throw new error(`Task ID "${this.decoratee.id}" is invalid. It must be in camelCase format, for example: "myCustomTask".`);
39
+ }
40
+ }
41
+ const TaskDefinitionDefaultsDecorator = TaskDefinition.createDecorator({
42
+ decorator: TaskDefinitionDefaultsDecoratorImpl,
43
+ dependencies: []
44
+ });
45
+ export { TaskDefinitionDefaultsDecorator, TaskDefinitionDefaultsDecoratorImpl };
46
+
47
+ //# sourceMappingURL=TaskDefinitionDefaultsDecorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api/decorators/TaskDefinitionDefaultsDecorator.js","sources":["../../../src/api/decorators/TaskDefinitionDefaultsDecorator.ts"],"sourcesContent":["import camelCase from \"lodash/camelCase.js\";\nimport WebinyError from \"@webiny/error\";\nimport { TaskDefinition } from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\nimport { normalizeSelfCleanup } from \"~/api/utils/normalizeSelfCleanup.js\";\n\nconst DEFAULT_MAX_ITERATIONS = 50;\n\n/**\n * Fills in the defaults a definition is allowed to leave out, applies the one rule that overrides\n * what a definition asked for (self-cleanup forces `databaseLogs` off), and rejects an id that is\n * not camelCase.\n *\n * Everything here is metadata. A definition carries no behaviour, so there is nothing to forward:\n * `GetRunnableTaskDefinitionUseCase` takes `run` and the hooks from the handler that `handler` names, after\n * this decorator has run.\n */\nexport class TaskDefinitionDefaultsDecoratorImpl implements TaskDefinition.Interface {\n private readonly cleansUp: boolean;\n\n constructor(private decoratee: TaskDefinition.Interface) {\n this.validate();\n this.cleansUp = normalizeSelfCleanup(decoratee.selfCleanup).size > 0;\n }\n\n get id() {\n return this.decoratee.id;\n }\n\n get title() {\n return this.decoratee.title;\n }\n\n get description() {\n return this.decoratee.description;\n }\n\n get handler() {\n return this.decoratee.handler;\n }\n\n // The three defaults.\n get isPrivate() {\n return this.decoratee.isPrivate || false;\n }\n\n get databaseLogs() {\n // A task that deletes itself on the way out has nowhere to keep logs, so asking for any\n // cleanup event overrides the task's own choice.\n if (this.cleansUp) {\n return false;\n }\n return this.decoratee.databaseLogs || false;\n }\n\n get maxIterations() {\n return this.decoratee.maxIterations || DEFAULT_MAX_ITERATIONS;\n }\n\n get selfCleanup() {\n return this.decoratee.selfCleanup;\n }\n\n private validate(): void {\n if (camelCase(this.decoratee.id) !== this.decoratee.id) {\n throw new WebinyError(\n `Task ID \"${this.decoratee.id}\" is invalid. It must be in camelCase format, for example: \"myCustomTask\".`\n );\n }\n }\n}\n\nexport const TaskDefinitionDefaultsDecorator = TaskDefinition.createDecorator({\n decorator: TaskDefinitionDefaultsDecoratorImpl,\n dependencies: []\n});\n"],"names":["DEFAULT_MAX_ITERATIONS","TaskDefinitionDefaultsDecoratorImpl","decoratee","normalizeSelfCleanup","camelCase","WebinyError","TaskDefinitionDefaultsDecorator","TaskDefinition"],"mappings":";;;;AAKA,MAAMA,yBAAyB;AAWxB,MAAMC;IAGT,YAAoBC,SAAmC,CAAE;aAArCA,SAAS,GAATA;QAChB,IAAI,CAAC,QAAQ;QACb,IAAI,CAAC,QAAQ,GAAGC,qBAAqBD,UAAU,WAAW,EAAE,IAAI,GAAG;IACvE;IAEA,IAAI,KAAK;QACL,OAAO,IAAI,CAAC,SAAS,CAAC,EAAE;IAC5B;IAEA,IAAI,QAAQ;QACR,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK;IAC/B;IAEA,IAAI,cAAc;QACd,OAAO,IAAI,CAAC,SAAS,CAAC,WAAW;IACrC;IAEA,IAAI,UAAU;QACV,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO;IACjC;IAGA,IAAI,YAAY;QACZ,OAAO,IAAI,CAAC,SAAS,CAAC,SAAS,IAAI;IACvC;IAEA,IAAI,eAAe;QAGf,IAAI,IAAI,CAAC,QAAQ,EACb,OAAO;QAEX,OAAO,IAAI,CAAC,SAAS,CAAC,YAAY,IAAI;IAC1C;IAEA,IAAI,gBAAgB;QAChB,OAAO,IAAI,CAAC,SAAS,CAAC,aAAa,IAAIF;IAC3C;IAEA,IAAI,cAAc;QACd,OAAO,IAAI,CAAC,SAAS,CAAC,WAAW;IACrC;IAEQ,WAAiB;QACrB,IAAII,UAAU,IAAI,CAAC,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC,SAAS,CAAC,EAAE,EAClD,MAAM,IAAIC,MACN,CAAC,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,0EAA0E,CAAC;IAGrH;AACJ;AAEO,MAAMC,kCAAkCC,eAAe,eAAe,CAAC;IAC1E,WAAWN;IACX,cAAc,EAAE;AACpB"}
@@ -0,0 +1,12 @@
1
+ import type { ITask } from "../../api/types.js";
2
+ export type ITaskServiceTask = Pick<ITask, "id" | "definitionId">;
3
+ export interface ITaskService {
4
+ send(task: ITaskServiceTask, delay: number): Promise<unknown | null>;
5
+ fetch(task: ITask): Promise<unknown | null>;
6
+ }
7
+ export declare const TaskService: import("@webiny/di").Abstraction<ITaskService>;
8
+ export declare namespace TaskService {
9
+ type Interface = ITaskService;
10
+ type SendTaskParams = ITaskServiceTask;
11
+ type Task = ITask;
12
+ }
@@ -0,0 +1,5 @@
1
+ import { createAbstraction } from "@webiny/feature/api";
2
+ const TaskService = createAbstraction("BackgroundTasks/TaskService");
3
+ export { TaskService };
4
+
5
+ //# sourceMappingURL=TaskService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api/domain/TaskService.js","sources":["../../../src/api/domain/TaskService.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { ITask } from \"~/api/types.js\";\n\nexport type ITaskServiceTask = Pick<ITask, \"id\" | \"definitionId\">;\n\nexport interface ITaskService {\n send(task: ITaskServiceTask, delay: number): Promise<unknown | null>;\n fetch(task: ITask): Promise<unknown | null>;\n}\n\nexport const TaskService = createAbstraction<ITaskService>(\"BackgroundTasks/TaskService\");\n\nexport namespace TaskService {\n export type Interface = ITaskService;\n export type SendTaskParams = ITaskServiceTask;\n export type Task = ITask;\n}\n"],"names":["TaskService","createAbstraction"],"mappings":";AAUO,MAAMA,cAAcC,kBAAgC"}
@@ -2,9 +2,8 @@ import { Result } from "@webiny/feature/api";
2
2
  import { AbortTaskUseCase as UseCaseAbstraction } from "./abstractions.js";
3
3
  import { TaskDefinition } from "@webiny/api-core/features/task/TaskDefinition/index.js";
4
4
  import { TaskService } from "@webiny/api-core/features/task/TaskService/index.js";
5
- import type { Context } from "../../../api/types.js";
6
5
  export declare class AbortTaskUseCaseImpl implements UseCaseAbstraction.Interface {
7
- private context;
8
- constructor(context: Context);
6
+ private taskService;
7
+ constructor(taskService: TaskService.Interface);
9
8
  execute<I extends TaskDefinition.TaskInput = TaskDefinition.TaskInput, O extends TaskService.GenericOutput = TaskService.GenericOutput>(params: UseCaseAbstraction.Params): Promise<Result<TaskService.Task<I, O>, UseCaseAbstraction.Error>>;
10
9
  }
@@ -1,9 +1,9 @@
1
1
  class AbortTaskUseCaseImpl {
2
- constructor(context){
3
- this.context = context;
2
+ constructor(taskService){
3
+ this.taskService = taskService;
4
4
  }
5
5
  async execute(params) {
6
- const result = await this.context.tasks.abort(params);
6
+ const result = await this.taskService.abort(params);
7
7
  return result;
8
8
  }
9
9
  }
@@ -1 +1 @@
1
- {"version":3,"file":"api/features/AbortTask/AbortTaskUseCase.js","sources":["../../../../src/api/features/AbortTask/AbortTaskUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { AbortTaskUseCase 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 { Context } from \"~/api/types.js\";\n\nexport class AbortTaskUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(private context: Context) {}\n\n async execute<\n I extends TaskDefinition.TaskInput = TaskDefinition.TaskInput,\n O extends TaskService.GenericOutput = TaskService.GenericOutput\n >(\n params: UseCaseAbstraction.Params\n ): Promise<Result<TaskService.Task<I, O>, UseCaseAbstraction.Error>> {\n const result = await this.context.tasks.abort<I, O>(params);\n return result as unknown as Promise<\n Result<TaskService.Task<I, O>, UseCaseAbstraction.Error>\n >;\n }\n}\n"],"names":["AbortTaskUseCaseImpl","context","params","result"],"mappings":"AAMO,MAAMA;IACT,YAA2BC,OAAgB,CAAE;aAAlBA,OAAO,GAAPA;IAAmB;IAE9C,MAAM,QAIFC,MAAiC,EACgC;QACjE,MAAMC,SAAS,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAOD;QACpD,OAAOC;IAGX;AACJ"}
1
+ {"version":3,"file":"api/features/AbortTask/AbortTaskUseCase.js","sources":["../../../../src/api/features/AbortTask/AbortTaskUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { AbortTaskUseCase 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\";\nexport class AbortTaskUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(private taskService: TaskService.Interface) {}\n\n async execute<\n I extends TaskDefinition.TaskInput = TaskDefinition.TaskInput,\n O extends TaskService.GenericOutput = TaskService.GenericOutput\n >(\n params: UseCaseAbstraction.Params\n ): Promise<Result<TaskService.Task<I, O>, UseCaseAbstraction.Error>> {\n const result = await this.taskService.abort<I, O>(params);\n return result as unknown as Promise<\n Result<TaskService.Task<I, O>, UseCaseAbstraction.Error>\n >;\n }\n}\n"],"names":["AbortTaskUseCaseImpl","taskService","params","result"],"mappings":"AAIO,MAAMA;IACT,YAA2BC,WAAkC,CAAE;aAApCA,WAAW,GAAXA;IAAqC;IAEhE,MAAM,QAIFC,MAAiC,EACgC;QACjE,MAAMC,SAAS,MAAM,IAAI,CAAC,WAAW,CAAC,KAAK,CAAOD;QAClD,OAAOC;IAGX;AACJ"}
@@ -1,5 +1,4 @@
1
- import type { Context } from "../../../api/types.js";
2
1
  export declare const AbortTaskFeature: {
3
2
  name: string;
4
- register(container: import("@webiny/di").Container, context: Context): void;
3
+ register(container: import("@webiny/di").Container): void;
5
4
  };
@@ -1,10 +1,11 @@
1
1
  import { createFeature } from "@webiny/feature/api";
2
2
  import { AbortTaskUseCaseImpl } from "./AbortTaskUseCase.js";
3
3
  import { AbortTaskUseCase } from "./abstractions.js";
4
+ import { TaskService } from "@webiny/api-core/features/task/TaskService/index.js";
4
5
  const AbortTaskFeature = createFeature({
5
6
  name: "AbortTask",
6
- register (container, context) {
7
- container.registerInstance(AbortTaskUseCase, new AbortTaskUseCaseImpl(context));
7
+ register (container) {
8
+ container.registerFactory(AbortTaskUseCase, ()=>new AbortTaskUseCaseImpl(container.resolve(TaskService)));
8
9
  }
9
10
  });
10
11
  export { AbortTaskFeature };
@@ -1 +1 @@
1
- {"version":3,"file":"api/features/AbortTask/feature.js","sources":["../../../../src/api/features/AbortTask/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { AbortTaskUseCaseImpl } from \"./AbortTaskUseCase.js\";\nimport type { Context } from \"~/api/types.js\";\nimport { AbortTaskUseCase } from \"./abstractions.js\";\n\nexport const AbortTaskFeature = createFeature<Context>({\n name: \"AbortTask\",\n register(container, context) {\n container.registerInstance(AbortTaskUseCase, new AbortTaskUseCaseImpl(context!));\n }\n});\n"],"names":["AbortTaskFeature","createFeature","container","context","AbortTaskUseCase","AbortTaskUseCaseImpl"],"mappings":";;;AAKO,MAAMA,mBAAmBC,cAAuB;IACnD,MAAM;IACN,UAASC,SAAS,EAAEC,OAAO;QACvBD,UAAU,gBAAgB,CAACE,kBAAkB,IAAIC,qBAAqBF;IAC1E;AACJ"}
1
+ {"version":3,"file":"api/features/AbortTask/feature.js","sources":["../../../../src/api/features/AbortTask/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { AbortTaskUseCaseImpl } from \"./AbortTaskUseCase.js\";\nimport { AbortTaskUseCase } from \"./abstractions.js\";\nimport { TaskService } from \"@webiny/api-core/features/task/TaskService/index.js\";\n\nexport const AbortTaskFeature = createFeature({\n name: \"AbortTask\",\n register(container) {\n container.registerFactory(AbortTaskUseCase, () => {\n return new AbortTaskUseCaseImpl(container.resolve(TaskService));\n });\n }\n});\n"],"names":["AbortTaskFeature","createFeature","container","AbortTaskUseCase","AbortTaskUseCaseImpl","TaskService"],"mappings":";;;;AAKO,MAAMA,mBAAmBC,cAAc;IAC1C,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,eAAe,CAACC,kBAAkB,IACjC,IAAIC,qBAAqBF,UAAU,OAAO,CAACG;IAE1D;AACJ"}
@@ -1,7 +1,7 @@
1
1
  import { CleanupTaskSubtreeUseCase as UseCaseAbstraction } from "./abstractions.js";
2
- import type { Context } from "../../../api/types.js";
2
+ import type { TasksCrud } from "../../../api/TasksCrud.js";
3
3
  export declare class CleanupTaskSubtreeUseCaseImpl implements UseCaseAbstraction.Interface {
4
- private readonly context;
5
- constructor(context: Context);
4
+ private readonly tasksCrud;
5
+ constructor(tasksCrud: TasksCrud.Interface);
6
6
  execute(taskId: string): Promise<void>;
7
7
  }
@@ -1,9 +1,9 @@
1
1
  class CleanupTaskSubtreeUseCaseImpl {
2
- constructor(context){
3
- this.context = context;
2
+ constructor(tasksCrud){
3
+ this.tasksCrud = tasksCrud;
4
4
  }
5
5
  async execute(taskId) {
6
- await this.context.tasks.cleanupTaskSubtree(taskId);
6
+ await this.tasksCrud.cleanupTaskSubtree(taskId);
7
7
  }
8
8
  }
9
9
  export { CleanupTaskSubtreeUseCaseImpl };
@@ -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 { Context } from \"~/api/types.js\";\n\nexport class CleanupTaskSubtreeUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(private readonly context: Context) {}\n\n public async execute(taskId: string): Promise<void> {\n await this.context.tasks.cleanupTaskSubtree(taskId);\n }\n}\n"],"names":["CleanupTaskSubtreeUseCaseImpl","context","taskId"],"mappings":"AAGO,MAAMA;IACT,YAAoCC,OAAgB,CAAE;aAAlBA,OAAO,GAAPA;IAAmB;IAEvD,MAAa,QAAQC,MAAc,EAAiB;QAChD,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,kBAAkB,CAACA;IAChD;AACJ"}
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 { TasksCrud } from \"~/api/TasksCrud.js\";\n\nexport class CleanupTaskSubtreeUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(private readonly tasksCrud: TasksCrud.Interface) {}\n\n public async execute(taskId: string): Promise<void> {\n await this.tasksCrud.cleanupTaskSubtree(taskId);\n }\n}\n"],"names":["CleanupTaskSubtreeUseCaseImpl","tasksCrud","taskId"],"mappings":"AAGO,MAAMA;IACT,YAAoCC,SAA8B,CAAE;aAAhCA,SAAS,GAATA;IAAiC;IAErE,MAAa,QAAQC,MAAc,EAAiB;QAChD,MAAM,IAAI,CAAC,SAAS,CAAC,kBAAkB,CAACA;IAC5C;AACJ"}
@@ -14,7 +14,7 @@ class GetBackgroundTaskSettingsRepositoryImpl {
14
14
  this.getLatestRevisionRepository = getLatestRevisionRepository;
15
15
  this.createEntryRepository = createEntryRepository;
16
16
  this.createEntryDataFactory = createEntryDataFactory;
17
- this.defaultRetentionDays = buildParams.get("BackgroundTasks.RetentionDays") ?? BACKGROUND_TASK_DEFAULT_RETENTION_DAYS;
17
+ this.defaultRetentionDays = buildParams.get("BackgroundTasks.RetentionDays") || BACKGROUND_TASK_DEFAULT_RETENTION_DAYS;
18
18
  }
19
19
  async execute() {
20
20
  try {
@@ -26,9 +26,12 @@ class GetBackgroundTaskSettingsRepositoryImpl {
26
26
  const entryResult = await this.getLatestRevisionRepository.execute(model, {
27
27
  id: entryId
28
28
  });
29
- if (entryResult.isOk()) return Result.ok({
30
- retentionDays: entryResult.value.values.retentionDays ?? this.defaultRetentionDays
31
- });
29
+ if (entryResult.isOk()) {
30
+ const retentionDays = null != entryResult.value.values.retentionDays ? entryResult.value.values.retentionDays : this.defaultRetentionDays;
31
+ return Result.ok({
32
+ retentionDays
33
+ });
34
+ }
32
35
  const { entry } = await this.createEntryDataFactory.create(model, {
33
36
  id: singletonId,
34
37
  values: {
@@ -1 +1 @@
1
- {"version":3,"file":"api/features/GetBackgroundTaskSettings/GetBackgroundTaskSettingsRepository.js","sources":["../../../../src/api/features/GetBackgroundTaskSettings/GetBackgroundTaskSettingsRepository.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { createCacheKey } from \"@webiny/utils\";\nimport { GetModelRepository } from \"@webiny/api-headless-cms/features/contentModel/GetModel/index.js\";\nimport { GetLatestRevisionByEntryIdRepository } from \"@webiny/api-headless-cms/features/contentEntry/GetLatestRevisionByEntryId/index.js\";\nimport { CreateEntryRepository } from \"@webiny/api-headless-cms/features/contentEntry/CreateEntry/index.js\";\nimport { CreateEntryDataFactory } from \"@webiny/api-headless-cms/exports/api/cms/entry.js\";\nimport { BuildParams } from \"@webiny/api-core/features/buildParams/index.js\";\nimport { GetBackgroundTaskSettingsRepository as RepositoryAbstraction } from \"./abstractions.js\";\nimport {\n BackgroundTaskModelNotFoundError,\n BackgroundTaskPersistenceError\n} from \"~/api/domain/errors.js\";\nimport {\n BACKGROUND_TASK_SETTINGS_MODEL_ID,\n BACKGROUND_TASK_DEFAULT_RETENTION_DAYS\n} from \"~/api/domain/constants.js\";\nimport type { IBackgroundTaskSettings } from \"~/api/domain/BackgroundTaskSettings.js\";\n\ninterface BackgroundTaskSettingsValues {\n retentionDays?: number;\n}\n\nclass GetBackgroundTaskSettingsRepositoryImpl implements RepositoryAbstraction.Interface {\n private readonly defaultRetentionDays: number;\n\n constructor(\n private readonly getModelRepository: GetModelRepository.Interface,\n private readonly getLatestRevisionRepository: GetLatestRevisionByEntryIdRepository.Interface,\n private readonly createEntryRepository: CreateEntryRepository.Interface,\n private readonly createEntryDataFactory: CreateEntryDataFactory.Interface,\n buildParams: BuildParams.Interface\n ) {\n this.defaultRetentionDays =\n buildParams.get<number>(\"BackgroundTasks.RetentionDays\") ??\n BACKGROUND_TASK_DEFAULT_RETENTION_DAYS;\n }\n\n async execute(): Promise<Result<IBackgroundTaskSettings, RepositoryAbstraction.Error>> {\n try {\n const modelResult = await this.getModelRepository.execute(\n BACKGROUND_TASK_SETTINGS_MODEL_ID\n );\n if (modelResult.isFail()) {\n return Result.fail(\n new BackgroundTaskModelNotFoundError(BACKGROUND_TASK_SETTINGS_MODEL_ID)\n );\n }\n\n const model = modelResult.value;\n const singletonId = createCacheKey(model.modelId);\n const entryId = `${singletonId}#0001`;\n\n const entryResult =\n await this.getLatestRevisionRepository.execute<BackgroundTaskSettingsValues>(\n model,\n { id: entryId }\n );\n\n if (entryResult.isOk()) {\n return Result.ok({\n retentionDays:\n entryResult.value.values.retentionDays ?? this.defaultRetentionDays\n });\n }\n\n /* Entry doesn't exist yet — create it with the build-param default. */\n const { entry } =\n await this.createEntryDataFactory.create<BackgroundTaskSettingsValues>(model, {\n id: singletonId,\n values: {\n retentionDays: this.defaultRetentionDays\n }\n });\n\n const createResult = await this.createEntryRepository.execute(model, entry);\n if (createResult.isFail()) {\n return Result.fail(BackgroundTaskPersistenceError.from(createResult.error));\n }\n\n return Result.ok({ retentionDays: this.defaultRetentionDays });\n } catch (error) {\n return Result.fail(BackgroundTaskPersistenceError.from(error));\n }\n }\n}\n\nexport const GetBackgroundTaskSettingsRepository = RepositoryAbstraction.createImplementation({\n implementation: GetBackgroundTaskSettingsRepositoryImpl,\n dependencies: [\n GetModelRepository,\n GetLatestRevisionByEntryIdRepository,\n CreateEntryRepository,\n CreateEntryDataFactory,\n BuildParams\n ]\n});\n"],"names":["GetBackgroundTaskSettingsRepositoryImpl","getModelRepository","getLatestRevisionRepository","createEntryRepository","createEntryDataFactory","buildParams","BACKGROUND_TASK_DEFAULT_RETENTION_DAYS","modelResult","BACKGROUND_TASK_SETTINGS_MODEL_ID","Result","BackgroundTaskModelNotFoundError","model","singletonId","createCacheKey","entryId","entryResult","entry","createResult","BackgroundTaskPersistenceError","error","GetBackgroundTaskSettingsRepository","RepositoryAbstraction","GetModelRepository","GetLatestRevisionByEntryIdRepository","CreateEntryRepository","CreateEntryDataFactory","BuildParams"],"mappings":";;;;;;;;;;AAsBA,MAAMA;IAGF,YACqBC,kBAAgD,EAChDC,2BAA2E,EAC3EC,qBAAsD,EACtDC,sBAAwD,EACzEC,WAAkC,CACpC;aALmBJ,kBAAkB,GAAlBA;aACAC,2BAA2B,GAA3BA;aACAC,qBAAqB,GAArBA;aACAC,sBAAsB,GAAtBA;QAGjB,IAAI,CAAC,oBAAoB,GACrBC,YAAY,GAAG,CAAS,oCACxBC;IACR;IAEA,MAAM,UAAiF;QACnF,IAAI;YACA,MAAMC,cAAc,MAAM,IAAI,CAAC,kBAAkB,CAAC,OAAO,CACrDC;YAEJ,IAAID,YAAY,MAAM,IAClB,OAAOE,OAAO,IAAI,CACd,IAAIC,iCAAiCF;YAI7C,MAAMG,QAAQJ,YAAY,KAAK;YAC/B,MAAMK,cAAcC,eAAeF,MAAM,OAAO;YAChD,MAAMG,UAAU,GAAGF,YAAY,KAAK,CAAC;YAErC,MAAMG,cACF,MAAM,IAAI,CAAC,2BAA2B,CAAC,OAAO,CAC1CJ,OACA;gBAAE,IAAIG;YAAQ;YAGtB,IAAIC,YAAY,IAAI,IAChB,OAAON,OAAO,EAAE,CAAC;gBACb,eACIM,YAAY,KAAK,CAAC,MAAM,CAAC,aAAa,IAAI,IAAI,CAAC,oBAAoB;YAC3E;YAIJ,MAAM,EAAEC,KAAK,EAAE,GACX,MAAM,IAAI,CAAC,sBAAsB,CAAC,MAAM,CAA+BL,OAAO;gBAC1E,IAAIC;gBACJ,QAAQ;oBACJ,eAAe,IAAI,CAAC,oBAAoB;gBAC5C;YACJ;YAEJ,MAAMK,eAAe,MAAM,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAACN,OAAOK;YACrE,IAAIC,aAAa,MAAM,IACnB,OAAOR,OAAO,IAAI,CAACS,+BAA+B,IAAI,CAACD,aAAa,KAAK;YAG7E,OAAOR,OAAO,EAAE,CAAC;gBAAE,eAAe,IAAI,CAAC,oBAAoB;YAAC;QAChE,EAAE,OAAOU,OAAO;YACZ,OAAOV,OAAO,IAAI,CAACS,+BAA+B,IAAI,CAACC;QAC3D;IACJ;AACJ;AAEO,MAAMC,0EAAsCC,oCAAAA,oBAA0C,CAAC;IAC1F,gBAAgBrB;IAChB,cAAc;QACVsB;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
1
+ {"version":3,"file":"api/features/GetBackgroundTaskSettings/GetBackgroundTaskSettingsRepository.js","sources":["../../../../src/api/features/GetBackgroundTaskSettings/GetBackgroundTaskSettingsRepository.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { createCacheKey } from \"@webiny/utils\";\nimport { GetModelRepository } from \"@webiny/api-headless-cms/features/contentModel/GetModel/index.js\";\nimport { GetLatestRevisionByEntryIdRepository } from \"@webiny/api-headless-cms/features/contentEntry/GetLatestRevisionByEntryId/index.js\";\nimport { CreateEntryRepository } from \"@webiny/api-headless-cms/features/contentEntry/CreateEntry/index.js\";\nimport { CreateEntryDataFactory } from \"@webiny/api-headless-cms/exports/api/cms/entry.js\";\nimport { BuildParams } from \"@webiny/api-core/features/buildParams/index.js\";\nimport { GetBackgroundTaskSettingsRepository as RepositoryAbstraction } from \"./abstractions.js\";\nimport {\n BackgroundTaskModelNotFoundError,\n BackgroundTaskPersistenceError\n} from \"~/api/domain/errors.js\";\nimport {\n BACKGROUND_TASK_SETTINGS_MODEL_ID,\n BACKGROUND_TASK_DEFAULT_RETENTION_DAYS\n} from \"~/api/domain/constants.js\";\nimport type { IBackgroundTaskSettings } from \"~/api/domain/BackgroundTaskSettings.js\";\n\ninterface BackgroundTaskSettingsValues {\n retentionDays?: number;\n}\n\nclass GetBackgroundTaskSettingsRepositoryImpl implements RepositoryAbstraction.Interface {\n private readonly defaultRetentionDays: number;\n\n constructor(\n private readonly getModelRepository: GetModelRepository.Interface,\n private readonly getLatestRevisionRepository: GetLatestRevisionByEntryIdRepository.Interface,\n private readonly createEntryRepository: CreateEntryRepository.Interface,\n private readonly createEntryDataFactory: CreateEntryDataFactory.Interface,\n buildParams: BuildParams.Interface\n ) {\n this.defaultRetentionDays =\n buildParams.get<number>(\"BackgroundTasks.RetentionDays\") ||\n BACKGROUND_TASK_DEFAULT_RETENTION_DAYS;\n }\n\n async execute(): Promise<Result<IBackgroundTaskSettings, RepositoryAbstraction.Error>> {\n try {\n const modelResult = await this.getModelRepository.execute(\n BACKGROUND_TASK_SETTINGS_MODEL_ID\n );\n if (modelResult.isFail()) {\n return Result.fail(\n new BackgroundTaskModelNotFoundError(BACKGROUND_TASK_SETTINGS_MODEL_ID)\n );\n }\n\n const model = modelResult.value;\n const singletonId = createCacheKey(model.modelId);\n const entryId = `${singletonId}#0001`;\n\n const entryResult =\n await this.getLatestRevisionRepository.execute<BackgroundTaskSettingsValues>(\n model,\n { id: entryId }\n );\n\n if (entryResult.isOk()) {\n const retentionDays =\n entryResult.value.values.retentionDays != null\n ? entryResult.value.values.retentionDays\n : this.defaultRetentionDays;\n\n return Result.ok({ retentionDays });\n }\n\n /* Entry doesn't exist yet — create it with the build-param default. */\n const { entry } =\n await this.createEntryDataFactory.create<BackgroundTaskSettingsValues>(model, {\n id: singletonId,\n values: {\n retentionDays: this.defaultRetentionDays\n }\n });\n\n const createResult = await this.createEntryRepository.execute(model, entry);\n if (createResult.isFail()) {\n return Result.fail(BackgroundTaskPersistenceError.from(createResult.error));\n }\n\n return Result.ok({ retentionDays: this.defaultRetentionDays });\n } catch (error) {\n return Result.fail(BackgroundTaskPersistenceError.from(error));\n }\n }\n}\n\nexport const GetBackgroundTaskSettingsRepository = RepositoryAbstraction.createImplementation({\n implementation: GetBackgroundTaskSettingsRepositoryImpl,\n dependencies: [\n GetModelRepository,\n GetLatestRevisionByEntryIdRepository,\n CreateEntryRepository,\n CreateEntryDataFactory,\n BuildParams\n ]\n});\n"],"names":["GetBackgroundTaskSettingsRepositoryImpl","getModelRepository","getLatestRevisionRepository","createEntryRepository","createEntryDataFactory","buildParams","BACKGROUND_TASK_DEFAULT_RETENTION_DAYS","modelResult","BACKGROUND_TASK_SETTINGS_MODEL_ID","Result","BackgroundTaskModelNotFoundError","model","singletonId","createCacheKey","entryId","entryResult","retentionDays","entry","createResult","BackgroundTaskPersistenceError","error","GetBackgroundTaskSettingsRepository","RepositoryAbstraction","GetModelRepository","GetLatestRevisionByEntryIdRepository","CreateEntryRepository","CreateEntryDataFactory","BuildParams"],"mappings":";;;;;;;;;;AAsBA,MAAMA;IAGF,YACqBC,kBAAgD,EAChDC,2BAA2E,EAC3EC,qBAAsD,EACtDC,sBAAwD,EACzEC,WAAkC,CACpC;aALmBJ,kBAAkB,GAAlBA;aACAC,2BAA2B,GAA3BA;aACAC,qBAAqB,GAArBA;aACAC,sBAAsB,GAAtBA;QAGjB,IAAI,CAAC,oBAAoB,GACrBC,YAAY,GAAG,CAAS,oCACxBC;IACR;IAEA,MAAM,UAAiF;QACnF,IAAI;YACA,MAAMC,cAAc,MAAM,IAAI,CAAC,kBAAkB,CAAC,OAAO,CACrDC;YAEJ,IAAID,YAAY,MAAM,IAClB,OAAOE,OAAO,IAAI,CACd,IAAIC,iCAAiCF;YAI7C,MAAMG,QAAQJ,YAAY,KAAK;YAC/B,MAAMK,cAAcC,eAAeF,MAAM,OAAO;YAChD,MAAMG,UAAU,GAAGF,YAAY,KAAK,CAAC;YAErC,MAAMG,cACF,MAAM,IAAI,CAAC,2BAA2B,CAAC,OAAO,CAC1CJ,OACA;gBAAE,IAAIG;YAAQ;YAGtB,IAAIC,YAAY,IAAI,IAAI;gBACpB,MAAMC,gBACFD,AAA0C,QAA1CA,YAAY,KAAK,CAAC,MAAM,CAAC,aAAa,GAChCA,YAAY,KAAK,CAAC,MAAM,CAAC,aAAa,GACtC,IAAI,CAAC,oBAAoB;gBAEnC,OAAON,OAAO,EAAE,CAAC;oBAAEO;gBAAc;YACrC;YAGA,MAAM,EAAEC,KAAK,EAAE,GACX,MAAM,IAAI,CAAC,sBAAsB,CAAC,MAAM,CAA+BN,OAAO;gBAC1E,IAAIC;gBACJ,QAAQ;oBACJ,eAAe,IAAI,CAAC,oBAAoB;gBAC5C;YACJ;YAEJ,MAAMM,eAAe,MAAM,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAACP,OAAOM;YACrE,IAAIC,aAAa,MAAM,IACnB,OAAOT,OAAO,IAAI,CAACU,+BAA+B,IAAI,CAACD,aAAa,KAAK;YAG7E,OAAOT,OAAO,EAAE,CAAC;gBAAE,eAAe,IAAI,CAAC,oBAAoB;YAAC;QAChE,EAAE,OAAOW,OAAO;YACZ,OAAOX,OAAO,IAAI,CAACU,+BAA+B,IAAI,CAACC;QAC3D;IACJ;AACJ;AAEO,MAAMC,0EAAsCC,oCAAAA,oBAA0C,CAAC;IAC1F,gBAAgBtB;IAChB,cAAc;QACVuB;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
@@ -0,0 +1,13 @@
1
+ import { Result } from "@webiny/feature/api";
2
+ import { GetRunnableTaskDefinitionUseCase as UseCaseAbstraction } from "./abstractions.js";
3
+ import { TaskDefinition } from "@webiny/api-core/features/task/TaskDefinition/index.js";
4
+ import { TaskHandlerResolver } from "../../../api/features/TaskHandlerResolver/index.js";
5
+ export declare class GetRunnableTaskDefinitionUseCaseImpl implements UseCaseAbstraction.Interface {
6
+ private definitions;
7
+ private handlerResolver;
8
+ constructor(definitions: TaskDefinition.Interface[], handlerResolver: TaskHandlerResolver.Interface);
9
+ execute<I extends TaskDefinition.TaskInput = TaskDefinition.TaskInput, O extends TaskDefinition.TaskOutput = TaskDefinition.TaskOutput>(id: string): Result<TaskDefinition.Runnable<I, O>, UseCaseAbstraction.Error>;
10
+ }
11
+ export declare const GetRunnableTaskDefinitionUseCase: typeof GetRunnableTaskDefinitionUseCaseImpl & {
12
+ __abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IGetRunnableTaskDefinitionUseCase>;
13
+ };
@@ -0,0 +1,51 @@
1
+ import { Result } from "@webiny/feature/api";
2
+ import { GetRunnableTaskDefinitionUseCase } from "./abstractions.js";
3
+ import { TaskDefinition } from "@webiny/api-core/features/task/TaskDefinition/index.js";
4
+ import { TaskHandlerResolver } from "../TaskHandlerResolver/index.js";
5
+ import { TaskDefinitionNotFoundError } from "../../domain/errors.js";
6
+ class GetRunnableTaskDefinitionUseCaseImpl {
7
+ constructor(definitions, handlerResolver){
8
+ this.definitions = definitions;
9
+ this.handlerResolver = handlerResolver;
10
+ }
11
+ execute(id) {
12
+ for (const definition of this.definitions){
13
+ if (definition.id !== id) continue;
14
+ const handlerClass = definition.handler;
15
+ const handler = this.handlerResolver.resolve(handlerClass);
16
+ const runnable = {
17
+ id: definition.id,
18
+ title: definition.title,
19
+ description: definition.description,
20
+ isPrivate: definition.isPrivate,
21
+ databaseLogs: definition.databaseLogs,
22
+ maxIterations: definition.maxIterations,
23
+ selfCleanup: definition.selfCleanup,
24
+ run: handler.run.bind(handler),
25
+ onBeforeTrigger: handler.onBeforeTrigger?.bind(handler),
26
+ onDone: handler.onDone?.bind(handler),
27
+ onError: handler.onError?.bind(handler),
28
+ onAbort: handler.onAbort?.bind(handler),
29
+ onMaxIterations: handler.onMaxIterations?.bind(handler),
30
+ createInputValidation: handler.createInputValidation?.bind(handler)
31
+ };
32
+ return Result.ok(runnable);
33
+ }
34
+ return Result.fail(new TaskDefinitionNotFoundError(id));
35
+ }
36
+ }
37
+ const GetRunnableTaskDefinitionUseCase_GetRunnableTaskDefinitionUseCase = GetRunnableTaskDefinitionUseCase.createImplementation({
38
+ implementation: GetRunnableTaskDefinitionUseCaseImpl,
39
+ dependencies: [
40
+ [
41
+ TaskDefinition,
42
+ {
43
+ multiple: true
44
+ }
45
+ ],
46
+ TaskHandlerResolver
47
+ ]
48
+ });
49
+ export { GetRunnableTaskDefinitionUseCaseImpl, GetRunnableTaskDefinitionUseCase_GetRunnableTaskDefinitionUseCase as GetRunnableTaskDefinitionUseCase };
50
+
51
+ //# sourceMappingURL=GetRunnableTaskDefinitionUseCase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api/features/GetRunnableTaskDefinition/GetRunnableTaskDefinitionUseCase.js","sources":["../../../../src/api/features/GetRunnableTaskDefinition/GetRunnableTaskDefinitionUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport type { Constructor } from \"@webiny/di\";\nimport { GetRunnableTaskDefinitionUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { TaskDefinition } from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\nimport { TaskHandlerResolver } from \"~/api/features/TaskHandlerResolver/index.js\";\nimport { TaskDefinitionNotFoundError } from \"~/api/domain/errors.js\";\n\nexport class GetRunnableTaskDefinitionUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(\n private definitions: TaskDefinition.Interface[],\n private handlerResolver: TaskHandlerResolver.Interface\n ) {}\n\n public execute<\n I extends TaskDefinition.TaskInput = TaskDefinition.TaskInput,\n O extends TaskDefinition.TaskOutput = TaskDefinition.TaskOutput\n >(id: string): Result<TaskDefinition.Runnable<I, O>, UseCaseAbstraction.Error> {\n for (const definition of this.definitions) {\n if (definition.id !== id) {\n continue;\n }\n\n // Every definition is free to build, so reaching this point cost nothing. The handler is\n // the expensive half and it is built only now, for the one task that was asked for.\n //\n // The registered definition is stored under the abstraction's default generics, so its\n // handler cannot be proven assignable to the caller's narrower <I, O>.\n const handlerClass = definition.handler as Constructor<TaskDefinition.Handler<I, O>>;\n const handler = this.handlerResolver.resolve(handlerClass);\n\n // Present the two halves as the single object the runner and\n // `context.tasks.getDefinition()` expect. Metadata from the definition, behaviour from\n // the handler, bound so `this` inside a hook is still the instance that owns the\n // injected dependencies.\n const runnable: TaskDefinition.Runnable<I, O> = {\n id: definition.id,\n title: definition.title,\n description: definition.description,\n isPrivate: definition.isPrivate as boolean,\n databaseLogs: definition.databaseLogs as boolean,\n maxIterations: definition.maxIterations as number,\n selfCleanup: definition.selfCleanup,\n\n run: handler.run.bind(handler),\n onBeforeTrigger: handler.onBeforeTrigger?.bind(handler),\n onDone: handler.onDone?.bind(handler),\n onError: handler.onError?.bind(handler),\n onAbort: handler.onAbort?.bind(handler),\n onMaxIterations: handler.onMaxIterations?.bind(handler),\n createInputValidation: handler.createInputValidation?.bind(handler)\n };\n\n return Result.ok(runnable);\n }\n\n return Result.fail(new TaskDefinitionNotFoundError(id));\n }\n}\n\nexport const GetRunnableTaskDefinitionUseCase = UseCaseAbstraction.createImplementation({\n implementation: GetRunnableTaskDefinitionUseCaseImpl,\n dependencies: [[TaskDefinition, { multiple: true }], TaskHandlerResolver]\n});\n"],"names":["GetRunnableTaskDefinitionUseCaseImpl","definitions","handlerResolver","id","definition","handlerClass","handler","runnable","Result","TaskDefinitionNotFoundError","GetRunnableTaskDefinitionUseCase","UseCaseAbstraction","TaskDefinition","TaskHandlerResolver"],"mappings":";;;;;AAOO,MAAMA;IACT,YACYC,WAAuC,EACvCC,eAA8C,CACxD;aAFUD,WAAW,GAAXA;aACAC,eAAe,GAAfA;IACT;IAEI,QAGLC,EAAU,EAAmE;QAC3E,KAAK,MAAMC,cAAc,IAAI,CAAC,WAAW,CAAE;YACvC,IAAIA,WAAW,EAAE,KAAKD,IAClB;YAQJ,MAAME,eAAeD,WAAW,OAAO;YACvC,MAAME,UAAU,IAAI,CAAC,eAAe,CAAC,OAAO,CAACD;YAM7C,MAAME,WAA0C;gBAC5C,IAAIH,WAAW,EAAE;gBACjB,OAAOA,WAAW,KAAK;gBACvB,aAAaA,WAAW,WAAW;gBACnC,WAAWA,WAAW,SAAS;gBAC/B,cAAcA,WAAW,YAAY;gBACrC,eAAeA,WAAW,aAAa;gBACvC,aAAaA,WAAW,WAAW;gBAEnC,KAAKE,QAAQ,GAAG,CAAC,IAAI,CAACA;gBACtB,iBAAiBA,QAAQ,eAAe,EAAE,KAAKA;gBAC/C,QAAQA,QAAQ,MAAM,EAAE,KAAKA;gBAC7B,SAASA,QAAQ,OAAO,EAAE,KAAKA;gBAC/B,SAASA,QAAQ,OAAO,EAAE,KAAKA;gBAC/B,iBAAiBA,QAAQ,eAAe,EAAE,KAAKA;gBAC/C,uBAAuBA,QAAQ,qBAAqB,EAAE,KAAKA;YAC/D;YAEA,OAAOE,OAAO,EAAE,CAACD;QACrB;QAEA,OAAOC,OAAO,IAAI,CAAC,IAAIC,4BAA4BN;IACvD;AACJ;AAEO,MAAMO,oEAAmCC,iCAAAA,oBAAuC,CAAC;IACpF,gBAAgBX;IAChB,cAAc;QAAC;YAACY;YAAgB;gBAAE,UAAU;YAAK;SAAE;QAAEC;KAAoB;AAC7E"}
@@ -1,16 +1,16 @@
1
1
  import type { Result } from "@webiny/feature/api";
2
2
  import type { TaskDefinition } from "@webiny/api-core/features/task/TaskDefinition/index.js";
3
3
  import type { TaskDefinitionNotFoundError } from "../../../api/domain/errors.js";
4
- export interface IGetTaskDefinitionUseCase {
4
+ export interface IGetRunnableTaskDefinitionUseCase {
5
5
  execute<I extends TaskDefinition.TaskInput = TaskDefinition.TaskInput, O extends TaskDefinition.TaskOutput = TaskDefinition.TaskOutput>(id: string): Result<TaskDefinition.Runnable<I, O>, UseCaseError>;
6
6
  }
7
- export interface IGetTaskDefinitionUseCaseErrors {
7
+ export interface IGetRunnableTaskDefinitionUseCaseErrors {
8
8
  notFound: TaskDefinitionNotFoundError;
9
9
  }
10
- type UseCaseError = IGetTaskDefinitionUseCaseErrors[keyof IGetTaskDefinitionUseCaseErrors];
11
- export declare const GetTaskDefinitionUseCase: import("@webiny/di").Abstraction<IGetTaskDefinitionUseCase>;
12
- export declare namespace GetTaskDefinitionUseCase {
13
- type Interface = IGetTaskDefinitionUseCase;
10
+ type UseCaseError = IGetRunnableTaskDefinitionUseCaseErrors[keyof IGetRunnableTaskDefinitionUseCaseErrors];
11
+ export declare const GetRunnableTaskDefinitionUseCase: import("@webiny/di").Abstraction<IGetRunnableTaskDefinitionUseCase>;
12
+ export declare namespace GetRunnableTaskDefinitionUseCase {
13
+ type Interface = IGetRunnableTaskDefinitionUseCase;
14
14
  type Error = UseCaseError;
15
15
  type Return<I extends TaskDefinition.TaskInput = TaskDefinition.TaskInput, O extends TaskDefinition.TaskOutput = TaskDefinition.TaskOutput> = Result<TaskDefinition.Runnable<I, O>, UseCaseError>;
16
16
  }
@@ -0,0 +1,5 @@
1
+ import { createAbstraction } from "@webiny/feature/api";
2
+ const GetRunnableTaskDefinitionUseCase = createAbstraction("Tasks/GetRunnableTaskDefinitionUseCase");
3
+ export { GetRunnableTaskDefinitionUseCase };
4
+
5
+ //# sourceMappingURL=abstractions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api/features/GetRunnableTaskDefinition/abstractions.js","sources":["../../../../src/api/features/GetRunnableTaskDefinition/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { Result } from \"@webiny/feature/api\";\nimport type { TaskDefinition } from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\nimport type { TaskDefinitionNotFoundError } from \"~/api/domain/errors.js\";\n\nexport interface IGetRunnableTaskDefinitionUseCase {\n execute<\n I extends TaskDefinition.TaskInput = TaskDefinition.TaskInput,\n O extends TaskDefinition.TaskOutput = TaskDefinition.TaskOutput\n >(\n id: string\n ): Result<TaskDefinition.Runnable<I, O>, UseCaseError>;\n}\n\nexport interface IGetRunnableTaskDefinitionUseCaseErrors {\n notFound: TaskDefinitionNotFoundError;\n}\n\ntype UseCaseError =\n IGetRunnableTaskDefinitionUseCaseErrors[keyof IGetRunnableTaskDefinitionUseCaseErrors];\n\nexport const GetRunnableTaskDefinitionUseCase =\n createAbstraction<IGetRunnableTaskDefinitionUseCase>(\"Tasks/GetRunnableTaskDefinitionUseCase\");\n\nexport namespace GetRunnableTaskDefinitionUseCase {\n export type Interface = IGetRunnableTaskDefinitionUseCase;\n\n export type Error = UseCaseError;\n export type Return<\n I extends TaskDefinition.TaskInput = TaskDefinition.TaskInput,\n O extends TaskDefinition.TaskOutput = TaskDefinition.TaskOutput\n > = Result<TaskDefinition.Runnable<I, O>, UseCaseError>;\n}\n"],"names":["GetRunnableTaskDefinitionUseCase","createAbstraction"],"mappings":";AAqBO,MAAMA,mCACTC,kBAAqD"}
@@ -0,0 +1,4 @@
1
+ export declare const GetRunnableTaskDefinitionFeature: {
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 { GetRunnableTaskDefinitionUseCase } from "./GetRunnableTaskDefinitionUseCase.js";
3
+ const GetRunnableTaskDefinitionFeature = createFeature({
4
+ name: "GetRunnableTaskDefinition",
5
+ register (container) {
6
+ container.register(GetRunnableTaskDefinitionUseCase);
7
+ }
8
+ });
9
+ export { GetRunnableTaskDefinitionFeature };
10
+
11
+ //# sourceMappingURL=feature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api/features/GetRunnableTaskDefinition/feature.js","sources":["../../../../src/api/features/GetRunnableTaskDefinition/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { GetRunnableTaskDefinitionUseCase } from \"./GetRunnableTaskDefinitionUseCase.js\";\n\nexport const GetRunnableTaskDefinitionFeature = createFeature({\n name: \"GetRunnableTaskDefinition\",\n register(container) {\n container.register(GetRunnableTaskDefinitionUseCase);\n }\n});\n"],"names":["GetRunnableTaskDefinitionFeature","createFeature","container","GetRunnableTaskDefinitionUseCase"],"mappings":";;AAGO,MAAMA,mCAAmCC,cAAc;IAC1D,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
@@ -0,0 +1,2 @@
1
+ export { GetRunnableTaskDefinitionUseCase } from "./abstractions.js";
2
+ export { GetRunnableTaskDefinitionFeature } from "./feature.js";
@@ -0,0 +1,2 @@
1
+ export { GetRunnableTaskDefinitionUseCase } from "./abstractions.js";
2
+ export { GetRunnableTaskDefinitionFeature } from "./feature.js";
@@ -1,9 +1,9 @@
1
1
  import { GetTaskUseCase as UseCaseAbstraction } from "./abstractions.js";
2
2
  import { TaskDefinition } from "@webiny/api-core/features/task/TaskDefinition/index.js";
3
3
  import { TaskService } from "@webiny/api-core/features/task/TaskService/index.js";
4
- import type { Context } from "../../../api/types.js";
4
+ import type { TasksCrud } from "../../../api/TasksCrud.js";
5
5
  export declare class GetTaskUseCaseImpl implements UseCaseAbstraction.Interface {
6
- private context;
7
- constructor(context: Context);
6
+ private tasksCrud;
7
+ constructor(tasksCrud: TasksCrud.Interface);
8
8
  execute<I extends TaskDefinition.TaskInput = TaskDefinition.TaskInput, O extends TaskService.GenericOutput = TaskService.GenericOutput>(id: string): Promise<TaskService.Task<I, O> | null>;
9
9
  }
@@ -1,9 +1,9 @@
1
1
  class GetTaskUseCaseImpl {
2
- constructor(context){
3
- this.context = context;
2
+ constructor(tasksCrud){
3
+ this.tasksCrud = tasksCrud;
4
4
  }
5
5
  async execute(id) {
6
- return await this.context.tasks.getTask(id);
6
+ return await this.tasksCrud.getTask(id);
7
7
  }
8
8
  }
9
9
  export { GetTaskUseCaseImpl };