@webiny/tasks 0.0.0-unstable.e53eceafb5 → 0.0.0-unstable.e6f0dc8ca7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -9
- package/context.js +50 -21
- package/context.js.map +1 -1
- package/crud/TaskLogPrivateModel.d.ts +9 -0
- package/crud/TaskLogPrivateModel.js +34 -0
- package/crud/TaskLogPrivateModel.js.map +1 -0
- package/crud/TaskPrivateModel.d.ts +9 -0
- package/crud/TaskPrivateModel.js +46 -0
- package/crud/TaskPrivateModel.js.map +1 -0
- package/crud/cleanupTaskSubtree.d.ts +8 -0
- package/crud/cleanupTaskSubtree.js +76 -0
- package/crud/cleanupTaskSubtree.js.map +1 -0
- package/crud/crud.tasks.d.ts +1 -1
- package/crud/crud.tasks.js +213 -105
- package/crud/crud.tasks.js.map +1 -1
- package/crud/definition.tasks.d.ts +1 -1
- package/crud/definition.tasks.js +9 -18
- package/crud/definition.tasks.js.map +1 -1
- package/crud/service.tasks.d.ts +1 -1
- package/crud/service.tasks.js +31 -36
- package/crud/service.tasks.js.map +1 -1
- package/decorators/RunnableTaskDecorator.d.ts +32 -0
- package/decorators/RunnableTaskDecorator.js +85 -0
- package/decorators/RunnableTaskDecorator.js.map +1 -0
- package/decorators/SelfCleaningTaskDecorator.d.ts +30 -0
- package/decorators/SelfCleaningTaskDecorator.js +98 -0
- package/decorators/SelfCleaningTaskDecorator.js.map +1 -0
- package/domain/errors.d.ts +29 -0
- package/domain/errors.js +47 -0
- package/domain/errors.js.map +1 -0
- package/events/TaskAfterCreateEvent.d.ts +6 -0
- package/events/TaskAfterCreateEvent.js +10 -0
- package/events/TaskAfterCreateEvent.js.map +1 -0
- package/events/TaskAfterDeleteEvent.d.ts +6 -0
- package/events/TaskAfterDeleteEvent.js +10 -0
- package/events/TaskAfterDeleteEvent.js.map +1 -0
- package/events/TaskAfterUpdateEvent.d.ts +6 -0
- package/events/TaskAfterUpdateEvent.js +10 -0
- package/events/TaskAfterUpdateEvent.js.map +1 -0
- package/events/TaskBeforeCreateEvent.d.ts +6 -0
- package/events/TaskBeforeCreateEvent.js +10 -0
- package/events/TaskBeforeCreateEvent.js.map +1 -0
- package/events/TaskBeforeDeleteEvent.d.ts +6 -0
- package/events/TaskBeforeDeleteEvent.js +10 -0
- package/events/TaskBeforeDeleteEvent.js.map +1 -0
- package/events/TaskBeforeUpdateEvent.d.ts +6 -0
- package/events/TaskBeforeUpdateEvent.js +10 -0
- package/events/TaskBeforeUpdateEvent.js.map +1 -0
- package/events/abstractions.d.ts +53 -0
- package/events/abstractions.js +39 -0
- package/events/abstractions.js.map +1 -0
- package/events/index.d.ts +7 -0
- package/events/index.js +9 -0
- package/events/index.js.map +1 -0
- package/features/AbortTask/AbortTaskUseCase.d.ts +10 -0
- package/features/AbortTask/AbortTaskUseCase.js +11 -0
- package/features/AbortTask/AbortTaskUseCase.js.map +1 -0
- package/features/AbortTask/abstractions.d.ts +25 -0
- package/features/AbortTask/abstractions.js +4 -0
- package/features/AbortTask/abstractions.js.map +1 -0
- package/features/AbortTask/feature.d.ts +5 -0
- package/features/AbortTask/feature.js +11 -0
- package/features/AbortTask/feature.js.map +1 -0
- package/features/AbortTask/index.d.ts +2 -0
- package/features/AbortTask/index.js +4 -0
- package/features/AbortTask/index.js.map +1 -0
- package/features/CleanupTaskSubtree/CleanupTaskSubtreeUseCase.d.ts +7 -0
- package/features/CleanupTaskSubtree/CleanupTaskSubtreeUseCase.js +10 -0
- package/features/CleanupTaskSubtree/CleanupTaskSubtreeUseCase.js.map +1 -0
- package/features/CleanupTaskSubtree/abstractions.d.ts +7 -0
- package/features/CleanupTaskSubtree/abstractions.js +4 -0
- package/features/CleanupTaskSubtree/abstractions.js.map +1 -0
- package/features/CleanupTaskSubtree/index.d.ts +2 -0
- package/features/CleanupTaskSubtree/index.js +4 -0
- package/features/CleanupTaskSubtree/index.js.map +1 -0
- package/features/GetTask/GetTaskUseCase.d.ts +9 -0
- package/features/GetTask/GetTaskUseCase.js +10 -0
- package/features/GetTask/GetTaskUseCase.js.map +1 -0
- package/features/GetTask/abstractions.d.ts +10 -0
- package/features/GetTask/abstractions.js +4 -0
- package/features/GetTask/abstractions.js.map +1 -0
- package/features/GetTask/feature.d.ts +5 -0
- package/features/GetTask/feature.js +11 -0
- package/features/GetTask/feature.js.map +1 -0
- package/features/GetTask/index.d.ts +2 -0
- package/features/GetTask/index.js +4 -0
- package/features/GetTask/index.js.map +1 -0
- package/features/GetTaskDefinition/GetTaskDefinitionUseCase.d.ts +12 -0
- package/features/GetTaskDefinition/GetTaskDefinitionUseCase.js +25 -0
- package/features/GetTaskDefinition/GetTaskDefinitionUseCase.js.map +1 -0
- package/features/GetTaskDefinition/abstractions.d.ts +17 -0
- package/features/GetTaskDefinition/abstractions.js +4 -0
- package/features/GetTaskDefinition/abstractions.js.map +1 -0
- package/features/GetTaskDefinition/feature.d.ts +4 -0
- package/features/GetTaskDefinition/feature.js +10 -0
- package/features/GetTaskDefinition/feature.js.map +1 -0
- package/features/GetTaskDefinition/index.d.ts +2 -0
- package/features/GetTaskDefinition/index.js +4 -0
- package/features/GetTaskDefinition/index.js.map +1 -0
- package/features/ListTaskDefinitions/ListTaskDefinitionsUseCase.d.ts +11 -0
- package/features/ListTaskDefinitions/ListTaskDefinitionsUseCase.js +18 -0
- package/features/ListTaskDefinitions/ListTaskDefinitionsUseCase.js.map +1 -0
- package/features/ListTaskDefinitions/abstractions.d.ts +9 -0
- package/features/ListTaskDefinitions/abstractions.js +4 -0
- package/features/ListTaskDefinitions/abstractions.js.map +1 -0
- package/features/ListTaskDefinitions/feature.d.ts +4 -0
- package/features/ListTaskDefinitions/feature.js +10 -0
- package/features/ListTaskDefinitions/feature.js.map +1 -0
- package/features/ListTaskDefinitions/index.d.ts +2 -0
- package/features/ListTaskDefinitions/index.js +4 -0
- package/features/ListTaskDefinitions/index.js.map +1 -0
- package/features/ListTasks/ListTasksUseCase.d.ts +9 -0
- package/features/ListTasks/ListTasksUseCase.js +10 -0
- package/features/ListTasks/ListTasksUseCase.js.map +1 -0
- package/features/ListTasks/abstractions.d.ts +13 -0
- package/features/ListTasks/abstractions.js +4 -0
- package/features/ListTasks/abstractions.js.map +1 -0
- package/features/ListTasks/feature.d.ts +5 -0
- package/features/ListTasks/feature.js +11 -0
- package/features/ListTasks/feature.js.map +1 -0
- package/features/ListTasks/index.d.ts +2 -0
- package/features/ListTasks/index.js +4 -0
- package/features/ListTasks/index.js.map +1 -0
- package/features/TaskController/TaskController.d.ts +49 -0
- package/features/TaskController/TaskController.js +71 -0
- package/features/TaskController/TaskController.js.map +1 -0
- package/features/TaskController/augmentation.d.ts +60 -0
- package/features/TaskController/augmentation.js +3 -0
- package/features/TaskController/augmentation.js.map +1 -0
- package/features/TaskController/index.d.ts +2 -0
- package/features/TaskController/index.js +7 -0
- package/features/TaskController/index.js.map +1 -0
- package/features/TaskExecutionContext/TaskExecutionContext.d.ts +24 -0
- package/features/TaskExecutionContext/TaskExecutionContext.js +50 -0
- package/features/TaskExecutionContext/TaskExecutionContext.js.map +1 -0
- package/features/TaskExecutionContext/abstractions.d.ts +26 -0
- package/features/TaskExecutionContext/abstractions.js +13 -0
- package/features/TaskExecutionContext/abstractions.js.map +1 -0
- package/features/TaskExecutionContext/feature.d.ts +4 -0
- package/features/TaskExecutionContext/feature.js +10 -0
- package/features/TaskExecutionContext/feature.js.map +1 -0
- package/features/TaskExecutionContext/index.d.ts +1 -0
- package/features/TaskExecutionContext/index.js +3 -0
- package/features/TaskExecutionContext/index.js.map +1 -0
- package/features/TriggerTask/TriggerTaskUseCase.d.ts +10 -0
- package/features/TriggerTask/TriggerTaskUseCase.js +11 -0
- package/features/TriggerTask/TriggerTaskUseCase.js.map +1 -0
- package/features/TriggerTask/abstractions.d.ts +28 -0
- package/features/TriggerTask/abstractions.js +4 -0
- package/features/TriggerTask/abstractions.js.map +1 -0
- package/features/TriggerTask/feature.d.ts +5 -0
- package/features/TriggerTask/feature.js +11 -0
- package/features/TriggerTask/feature.js.map +1 -0
- package/features/TriggerTask/index.d.ts +2 -0
- package/features/TriggerTask/index.js +4 -0
- package/features/TriggerTask/index.js.map +1 -0
- package/global.d.ts +1 -0
- package/global.js +3 -0
- package/global.js.map +1 -0
- package/graphql/checkPermissions.d.ts +1 -1
- package/graphql/checkPermissions.js +3 -9
- package/graphql/checkPermissions.js.map +1 -1
- package/graphql/index.d.ts +1 -1
- package/graphql/index.js +67 -83
- package/graphql/index.js.map +1 -1
- package/graphql/utils.d.ts +3 -3
- package/graphql/utils.js +8 -17
- package/graphql/utils.js.map +1 -1
- package/handler/index.d.ts +2 -2
- package/handler/index.js +33 -40
- package/handler/index.js.map +1 -1
- package/handler/register.js +5 -7
- package/handler/register.js.map +1 -1
- package/handler/types.d.ts +1 -3
- package/handler/types.js +1 -5
- package/handler/types.js.map +1 -1
- package/index.d.ts +5 -6
- package/index.js +5 -60
- package/index.js.map +1 -1
- package/package.json +27 -28
- package/plugins/TaskServicePlugin.d.ts +1 -2
- package/plugins/TaskServicePlugin.js +2 -9
- package/plugins/TaskServicePlugin.js.map +1 -1
- package/plugins/index.d.ts +1 -1
- package/plugins/index.js +1 -16
- package/plugins/index.js.map +1 -1
- package/response/DatabaseResponse.d.ts +3 -3
- package/response/DatabaseResponse.js +14 -20
- package/response/DatabaseResponse.js.map +1 -1
- package/response/Response.d.ts +4 -3
- package/response/Response.js +20 -31
- package/response/Response.js.map +1 -1
- package/response/ResponseAbortedResult.d.ts +3 -4
- package/response/ResponseAbortedResult.js +3 -11
- package/response/ResponseAbortedResult.js.map +1 -1
- package/response/ResponseContinueResult.d.ts +4 -5
- package/response/ResponseContinueResult.js +3 -11
- package/response/ResponseContinueResult.js.map +1 -1
- package/response/ResponseDoneResult.d.ts +4 -6
- package/response/ResponseDoneResult.js +3 -11
- package/response/ResponseDoneResult.js.map +1 -1
- package/response/ResponseErrorResult.d.ts +3 -4
- package/response/ResponseErrorResult.js +3 -11
- package/response/ResponseErrorResult.js.map +1 -1
- package/response/TaskResponse.d.ts +7 -6
- package/response/TaskResponse.js +5 -12
- package/response/TaskResponse.js.map +1 -1
- package/response/abstractions/Response.d.ts +7 -7
- package/response/abstractions/Response.js +1 -5
- package/response/abstractions/Response.js.map +1 -1
- package/response/abstractions/ResponseAbortedResult.d.ts +3 -3
- package/response/abstractions/ResponseAbortedResult.js +1 -5
- package/response/abstractions/ResponseAbortedResult.js.map +1 -1
- package/response/abstractions/ResponseBaseResult.d.ts +2 -3
- package/response/abstractions/ResponseBaseResult.js +1 -5
- package/response/abstractions/ResponseBaseResult.js.map +1 -1
- package/response/abstractions/ResponseContinueResult.d.ts +4 -4
- package/response/abstractions/ResponseContinueResult.js +1 -5
- package/response/abstractions/ResponseContinueResult.js.map +1 -1
- package/response/abstractions/ResponseDoneResult.d.ts +5 -6
- package/response/abstractions/ResponseDoneResult.js +1 -5
- package/response/abstractions/ResponseDoneResult.js.map +1 -1
- package/response/abstractions/ResponseErrorResult.d.ts +4 -5
- package/response/abstractions/ResponseErrorResult.js +1 -5
- package/response/abstractions/ResponseErrorResult.js.map +1 -1
- package/response/abstractions/TaskResponse.d.ts +8 -30
- package/response/abstractions/TaskResponse.js +1 -5
- package/response/abstractions/TaskResponse.js.map +1 -1
- package/response/abstractions/index.d.ts +7 -7
- package/response/abstractions/index.js +7 -82
- package/response/abstractions/index.js.map +1 -1
- package/response/index.d.ts +7 -7
- package/response/index.js +7 -82
- package/response/index.js.map +1 -1
- package/runner/TaskControl.d.ts +4 -4
- package/runner/TaskControl.js +61 -39
- package/runner/TaskControl.js.map +1 -1
- package/runner/TaskEventValidation.d.ts +2 -2
- package/runner/TaskEventValidation.js +11 -20
- package/runner/TaskEventValidation.js.map +1 -1
- package/runner/TaskManager.d.ts +7 -10
- package/runner/TaskManager.js +19 -39
- package/runner/TaskManager.js.map +1 -1
- package/runner/TaskManagerStore.d.ts +7 -7
- package/runner/TaskManagerStore.js +16 -25
- package/runner/TaskManagerStore.js.map +1 -1
- package/runner/TaskRunner.d.ts +5 -6
- package/runner/TaskRunner.js +9 -31
- package/runner/TaskRunner.js.map +1 -1
- package/runner/abstractions/TaskControl.d.ts +4 -4
- package/runner/abstractions/TaskControl.js +1 -5
- package/runner/abstractions/TaskControl.js.map +1 -1
- package/runner/abstractions/TaskEventValidation.d.ts +1 -1
- package/runner/abstractions/TaskEventValidation.js +1 -5
- package/runner/abstractions/TaskEventValidation.js.map +1 -1
- package/runner/abstractions/TaskManager.d.ts +4 -4
- package/runner/abstractions/TaskManager.js +1 -5
- package/runner/abstractions/TaskManager.js.map +1 -1
- package/runner/abstractions/TaskManagerStore.d.ts +11 -11
- package/runner/abstractions/TaskManagerStore.js +1 -5
- package/runner/abstractions/TaskManagerStore.js.map +1 -1
- package/runner/abstractions/TaskRunner.d.ts +3 -3
- package/runner/abstractions/TaskRunner.js +1 -5
- package/runner/abstractions/TaskRunner.js.map +1 -1
- package/runner/abstractions/index.d.ts +5 -5
- package/runner/abstractions/index.js +5 -60
- package/runner/abstractions/index.js.map +1 -1
- package/runner/index.d.ts +1 -1
- package/runner/index.js +1 -16
- package/runner/index.js.map +1 -1
- package/service/EventBridgeEventTransportPlugin.d.ts +4 -5
- package/service/EventBridgeEventTransportPlugin.js +8 -17
- package/service/EventBridgeEventTransportPlugin.js.map +1 -1
- package/service/StepFunctionServicePlugin.d.ts +4 -5
- package/service/StepFunctionServicePlugin.js +11 -21
- package/service/StepFunctionServicePlugin.js.map +1 -1
- package/service/createService.d.ts +2 -2
- package/service/createService.js +7 -18
- package/service/createService.js.map +1 -1
- package/service/index.d.ts +3 -3
- package/service/index.js +6 -27
- package/service/index.js.map +1 -1
- package/tasks/testingRunTask.d.ts +10 -1
- package/tasks/testingRunTask.js +13 -18
- package/tasks/testingRunTask.js.map +1 -1
- package/types.d.ts +41 -214
- package/types.js +7 -56
- package/types.js.map +1 -1
- package/utils/ObjectUpdater.js +4 -11
- package/utils/ObjectUpdater.js.map +1 -1
- package/utils/getErrorProperties.d.ts +1 -1
- package/utils/getErrorProperties.js +3 -10
- package/utils/getErrorProperties.js.map +1 -1
- package/utils/getObjectProperties.js +1 -8
- package/utils/getObjectProperties.js.map +1 -1
- package/utils/index.d.ts +3 -3
- package/utils/index.js +3 -38
- package/utils/index.js.map +1 -1
- package/utils/normalizeSelfCleanup.d.ts +2 -0
- package/utils/normalizeSelfCleanup.js +15 -0
- package/utils/normalizeSelfCleanup.js.map +1 -0
- package/crud/model.d.ts +0 -5
- package/crud/model.js +0 -216
- package/crud/model.js.map +0 -1
- package/crud/where.d.ts +0 -1
- package/crud/where.js +0 -33
- package/crud/where.js.map +0 -1
- package/task/index.d.ts +0 -2
- package/task/index.js +0 -29
- package/task/index.js.map +0 -1
- package/task/input.d.ts +0 -15
- package/task/input.js +0 -21
- package/task/input.js.map +0 -1
- package/task/plugin.d.ts +0 -36
- package/task/plugin.js +0 -106
- package/task/plugin.js.map +0 -1
|
@@ -1,18 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.TaskManagerStore = void 0;
|
|
8
|
-
var _types = require("../types");
|
|
9
|
-
var _deepEqual = _interopRequireDefault(require("deep-equal"));
|
|
10
|
-
var _getObjectProperties = require("../utils/getObjectProperties");
|
|
11
|
-
var _ObjectUpdater = require("../utils/ObjectUpdater");
|
|
1
|
+
import { TaskLogItemType } from "../types.js";
|
|
12
2
|
/**
|
|
13
3
|
* Package deep-equal does not have types.
|
|
14
4
|
*/
|
|
15
|
-
|
|
5
|
+
import deepEqual from "deep-equal";
|
|
6
|
+
import { getObjectProperties } from "../utils/getObjectProperties.js";
|
|
7
|
+
import { ObjectUpdater } from "../utils/ObjectUpdater.js";
|
|
16
8
|
const getInput = (originalInput, input) => {
|
|
17
9
|
if (typeof input === "function") {
|
|
18
10
|
return input(originalInput);
|
|
@@ -22,14 +14,14 @@ const getInput = (originalInput, input) => {
|
|
|
22
14
|
...input
|
|
23
15
|
};
|
|
24
16
|
};
|
|
25
|
-
class TaskManagerStore {
|
|
26
|
-
taskUpdater = new
|
|
27
|
-
taskLogUpdater = new
|
|
17
|
+
export class TaskManagerStore {
|
|
18
|
+
taskUpdater = new ObjectUpdater();
|
|
19
|
+
taskLogUpdater = new ObjectUpdater();
|
|
28
20
|
constructor(params) {
|
|
29
21
|
this.context = params.context;
|
|
30
22
|
this.task = params.task;
|
|
31
23
|
this.taskLog = params.log;
|
|
32
|
-
this.
|
|
24
|
+
this.databaseLogs = params.databaseLogs === true;
|
|
33
25
|
}
|
|
34
26
|
getStatus() {
|
|
35
27
|
return this.task.taskStatus;
|
|
@@ -57,7 +49,7 @@ class TaskManagerStore {
|
|
|
57
49
|
/**
|
|
58
50
|
* No need to update if nothing changed.
|
|
59
51
|
*/
|
|
60
|
-
if ((
|
|
52
|
+
if (deepEqual(data, this.task)) {
|
|
61
53
|
return;
|
|
62
54
|
}
|
|
63
55
|
this.taskUpdater.update(data);
|
|
@@ -72,7 +64,7 @@ class TaskManagerStore {
|
|
|
72
64
|
/**
|
|
73
65
|
* No need to update if nothing changed.
|
|
74
66
|
*/
|
|
75
|
-
if ((
|
|
67
|
+
if (deepEqual(input, this.task.input)) {
|
|
76
68
|
return;
|
|
77
69
|
}
|
|
78
70
|
this.taskUpdater.update({
|
|
@@ -103,14 +95,14 @@ class TaskManagerStore {
|
|
|
103
95
|
* TODO: Maybe we should wrap it into try/catch and return error if any?
|
|
104
96
|
*/
|
|
105
97
|
async addInfoLog(log, options) {
|
|
106
|
-
if (this.
|
|
98
|
+
if (!this.databaseLogs) {
|
|
107
99
|
return;
|
|
108
100
|
}
|
|
109
101
|
this.taskLogUpdater.update({
|
|
110
102
|
items: [{
|
|
111
103
|
message: log.message,
|
|
112
104
|
data: log.data,
|
|
113
|
-
type:
|
|
105
|
+
type: TaskLogItemType.INFO,
|
|
114
106
|
createdOn: new Date().toISOString()
|
|
115
107
|
}]
|
|
116
108
|
});
|
|
@@ -124,7 +116,7 @@ class TaskManagerStore {
|
|
|
124
116
|
* TODO: Maybe we should wrap it into try/catch and return error if any?
|
|
125
117
|
*/
|
|
126
118
|
async addErrorLog(log, options) {
|
|
127
|
-
if (this.
|
|
119
|
+
if (!this.databaseLogs) {
|
|
128
120
|
return;
|
|
129
121
|
}
|
|
130
122
|
/**
|
|
@@ -137,8 +129,8 @@ class TaskManagerStore {
|
|
|
137
129
|
this.taskLogUpdater.update({
|
|
138
130
|
items: [{
|
|
139
131
|
message: log.message,
|
|
140
|
-
error: log.error instanceof Error ?
|
|
141
|
-
type:
|
|
132
|
+
error: log.error instanceof Error ? getObjectProperties(log.error) : log.error,
|
|
133
|
+
type: TaskLogItemType.ERROR,
|
|
142
134
|
createdOn: new Date().toISOString()
|
|
143
135
|
}]
|
|
144
136
|
});
|
|
@@ -154,7 +146,7 @@ class TaskManagerStore {
|
|
|
154
146
|
if (this.taskUpdater.isDirty()) {
|
|
155
147
|
this.task = await this.context.tasks.updateTask(this.task.id, this.taskUpdater.fetch());
|
|
156
148
|
}
|
|
157
|
-
if (this.
|
|
149
|
+
if (!this.databaseLogs) {
|
|
158
150
|
return;
|
|
159
151
|
}
|
|
160
152
|
if (this.taskLogUpdater.isDirty()) {
|
|
@@ -162,6 +154,5 @@ class TaskManagerStore {
|
|
|
162
154
|
}
|
|
163
155
|
}
|
|
164
156
|
}
|
|
165
|
-
exports.TaskManagerStore = TaskManagerStore;
|
|
166
157
|
|
|
167
158
|
//# sourceMappingURL=TaskManagerStore.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_types","require","_deepEqual","_interopRequireDefault","_getObjectProperties","_ObjectUpdater","getInput","originalInput","input","TaskManagerStore","taskUpdater","ObjectUpdater","taskLogUpdater","constructor","params","context","task","taskLog","log","disableDatabaseLogs","getStatus","taskStatus","getTask","listChildTasks","definitionId","where","parentId","id","result","tasks","listTasks","sort","limit","items","updateTask","param","options","data","deepEqual","update","save","updateInput","updateOutput","values","output","getOutput","addInfoLog","message","type","TaskLogItemType","INFO","createdOn","Date","toISOString","addErrorLog","console","error","Error","getObjectProperties","ERROR","isDirty","fetch","updateLog","exports"],"sources":["TaskManagerStore.ts"],"sourcesContent":["import type {\n IListTaskParamsWhere,\n ITask,\n ITaskDataInput,\n ITaskLog,\n ITaskManagerStoreInfoLog,\n ITaskManagerStorePrivate,\n ITaskManagerStoreSetOutputOptions,\n ITaskManagerStoreUpdateTaskInputOptions,\n ITaskManagerStoreUpdateTaskOptions,\n ITaskResponseDoneResultOutput,\n ITasksContextObject,\n TaskDataStatus\n} from \"~/types\";\nimport { TaskLogItemType } from \"~/types\";\nimport type {\n ITaskManagerStoreAddLogOptions,\n ITaskManagerStoreErrorLog,\n ITaskManagerStoreUpdateTaskInputParam,\n ITaskManagerStoreUpdateTaskParams\n} from \"./abstractions\";\n/**\n * Package deep-equal does not have types.\n */\nimport deepEqual from \"deep-equal\";\nimport { getObjectProperties } from \"~/utils/getObjectProperties\";\nimport { ObjectUpdater } from \"~/utils/ObjectUpdater\";\nimport type { GenericRecord } from \"@webiny/api/types\";\n\nconst getInput = <T extends ITaskDataInput = ITaskDataInput>(\n originalInput: T,\n input: ITaskManagerStoreUpdateTaskInputParam<T>\n): T => {\n if (typeof input === \"function\") {\n return input(originalInput);\n }\n return {\n ...originalInput,\n ...input\n };\n};\n\nexport interface TaskManagerStoreContext {\n tasks: Pick<ITasksContextObject, \"updateTask\" | \"updateLog\" | \"listTasks\">;\n}\n\nexport interface ITaskManagerStoreParams {\n context: TaskManagerStoreContext;\n task: ITask;\n log: ITaskLog;\n disableDatabaseLogs?: boolean;\n}\n\nexport class TaskManagerStore<\n T extends ITaskDataInput = ITaskDataInput,\n O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput\n> implements ITaskManagerStorePrivate<T, O>\n{\n private readonly context: TaskManagerStoreContext;\n private task: ITask<T, O>;\n private taskLog: ITaskLog;\n private readonly disableDatabaseLogs: boolean;\n\n private readonly taskUpdater = new ObjectUpdater<ITask<T, O>>();\n private readonly taskLogUpdater = new ObjectUpdater<ITaskLog>();\n\n public constructor(params: ITaskManagerStoreParams) {\n this.context = params.context;\n this.task = params.task as ITask<T, O>;\n this.taskLog = params.log;\n this.disableDatabaseLogs = !!params.disableDatabaseLogs;\n }\n\n public getStatus(): TaskDataStatus {\n return this.task.taskStatus;\n }\n\n public getTask(): ITask<T, O> {\n return this.task as ITask<T, O>;\n }\n\n public async listChildTasks<\n I = GenericRecord,\n O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput\n >(definitionId?: string): Promise<ITask<I, O>[]> {\n const where: IListTaskParamsWhere = {\n parentId: this.task.id\n };\n if (definitionId) {\n where.definitionId = definitionId;\n }\n const result = await this.context.tasks.listTasks<I, O>({\n where,\n sort: [\"createdOn_ASC\"],\n limit: 1000000\n });\n return result.items;\n }\n\n public async updateTask(\n param: ITaskManagerStoreUpdateTaskParams<T, O>,\n options?: ITaskManagerStoreUpdateTaskOptions\n ): Promise<void> {\n const data = typeof param === \"function\" ? param(this.task) : param;\n\n /**\n * No need to update if nothing changed.\n */\n if (deepEqual(data, this.task)) {\n return;\n }\n\n this.taskUpdater.update(data);\n\n if (options?.save === false) {\n return;\n }\n await this.save();\n }\n\n public async updateInput(\n param: ITaskManagerStoreUpdateTaskInputParam<T>,\n options?: ITaskManagerStoreUpdateTaskInputOptions\n ): Promise<void> {\n const input = getInput<T>(this.task.input, param);\n\n /**\n * No need to update if nothing changed.\n */\n if (deepEqual(input, this.task.input)) {\n return;\n }\n this.taskUpdater.update({\n input: input as T\n });\n if (options?.save === false) {\n return;\n }\n await this.save();\n }\n\n public getInput(): T {\n return this.task.input as T;\n }\n\n public async updateOutput(\n values: Partial<O>,\n options: ITaskManagerStoreSetOutputOptions = {}\n ): Promise<void> {\n this.taskUpdater.update({\n output: values as O\n });\n if (options?.save === false) {\n return;\n }\n await this.save();\n }\n\n public getOutput(): O {\n return this.task.output as O;\n }\n /**\n * Currently the methods throws an error if something goes wrong during the database update.\n * TODO: Maybe we should wrap it into try/catch and return error if any?\n */\n public async addInfoLog(\n log: ITaskManagerStoreInfoLog,\n options?: ITaskManagerStoreAddLogOptions\n ): Promise<void> {\n if (this.disableDatabaseLogs) {\n return;\n }\n this.taskLogUpdater.update({\n items: [\n {\n message: log.message,\n data: log.data,\n type: TaskLogItemType.INFO,\n createdOn: new Date().toISOString()\n }\n ]\n });\n if (options?.save === false) {\n return;\n }\n\n await this.save();\n }\n /**\n * Currently the methods throws an error if something goes wrong during the database update.\n * TODO: Maybe we should wrap it into try/catch and return error if any?\n */\n public async addErrorLog(\n log: ITaskManagerStoreErrorLog,\n options?: ITaskManagerStoreAddLogOptions\n ): Promise<void> {\n if (this.disableDatabaseLogs) {\n return;\n }\n /**\n * Let's log the error to the console as well.\n */\n console.error(log.error);\n /**\n * Then update the log object.\n */\n this.taskLogUpdater.update({\n items: [\n {\n message: log.message,\n error: log.error instanceof Error ? getObjectProperties(log.error) : log.error,\n type: TaskLogItemType.ERROR,\n createdOn: new Date().toISOString()\n }\n ]\n });\n if (options?.save === false) {\n return;\n }\n await this.save();\n }\n\n public async save(): Promise<void> {\n /**\n * Update both task and the log, if anything to update.\n */\n if (this.taskUpdater.isDirty()) {\n this.task = await this.context.tasks.updateTask<T, O>(\n this.task.id,\n this.taskUpdater.fetch()\n );\n }\n if (this.disableDatabaseLogs) {\n return;\n }\n if (this.taskLogUpdater.isDirty()) {\n this.taskLog = await this.context.tasks.updateLog(\n this.taskLog.id,\n this.taskLogUpdater.fetch()\n );\n }\n }\n}\n"],"mappings":";;;;;;;AAcA,IAAAA,MAAA,GAAAC,OAAA;AAUA,IAAAC,UAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,oBAAA,GAAAH,OAAA;AACA,IAAAI,cAAA,GAAAJ,OAAA;AALA;AACA;AACA;;AAMA,MAAMK,QAAQ,GAAGA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AACR;AACA;IACQ,IAAI,IAAI,CAAC9B,WAAW,CAACkD,OAAO,CAAC,CAAC,EAAE;MAC5B,IAAI,CAAC5C,IAAI,GAAG,MAAM,IAAI,CAACD,OAAO,CAACc,KAAK,CAACK,UAAU,CAC3C,IAAI,CAAClB,IAAI,CAACW,EAAE,EACZ,IAAI,CAACjB,WAAW,CAACmD,KAAK,CAAC,CAC3B,CAAC;IACL;IACA,IAAI,IAAI,CAAC1C,mBAAmB,EAAE;MAC1B;IACJ;IACA,IAAI,IAAI,CAACP,cAAc,CAACgD,OAAO,CAAC,CAAC,EAAE;MAC/B,IAAI,CAAC3C,OAAO,GAAG,MAAM,IAAI,CAACF,OAAO,CAACc,KAAK,CAACiC,SAAS,CAC7C,IAAI,CAAC7C,OAAO,CAACU,EAAE,EACf,IAAI,CAACf,cAAc,CAACiD,KAAK,CAAC,CAC9B,CAAC;IACL;EACJ;AACJ;AAACE,OAAA,CAAAtD,gBAAA,GAAAA,gBAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["TaskLogItemType","deepEqual","getObjectProperties","ObjectUpdater","getInput","originalInput","input","TaskManagerStore","taskUpdater","taskLogUpdater","constructor","params","context","task","taskLog","log","databaseLogs","getStatus","taskStatus","getTask","listChildTasks","definitionId","where","parentId","id","result","tasks","listTasks","sort","limit","items","updateTask","param","options","data","update","save","updateInput","updateOutput","values","output","getOutput","addInfoLog","message","type","INFO","createdOn","Date","toISOString","addErrorLog","console","error","Error","ERROR","isDirty","fetch","updateLog"],"sources":["TaskManagerStore.ts"],"sourcesContent":["import type {\n IListTaskParamsWhere,\n ITask,\n ITaskDataInput,\n ITaskLog,\n ITaskManagerStoreInfoLog,\n ITaskManagerStorePrivate,\n ITaskManagerStoreSetOutputOptions,\n ITaskManagerStoreUpdateTaskInputOptions,\n ITaskManagerStoreUpdateTaskOptions,\n ITasksContextObject,\n TaskDataStatus\n} from \"~/types.js\";\nimport { TaskLogItemType } from \"~/types.js\";\nimport type {\n ITaskManagerStoreAddLogOptions,\n ITaskManagerStoreErrorLog,\n ITaskManagerStoreUpdateTaskInputParam,\n ITaskManagerStoreUpdateTaskParams\n} from \"./abstractions/index.js\";\n/**\n * Package deep-equal does not have types.\n */\nimport deepEqual from \"deep-equal\";\nimport { getObjectProperties } from \"~/utils/getObjectProperties.js\";\nimport { ObjectUpdater } from \"~/utils/ObjectUpdater.js\";\nimport { TaskDefinition } from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\n\nconst getInput = <T extends ITaskDataInput = ITaskDataInput>(\n originalInput: T,\n input: ITaskManagerStoreUpdateTaskInputParam<T>\n): T => {\n if (typeof input === \"function\") {\n return input(originalInput);\n }\n return {\n ...originalInput,\n ...input\n };\n};\n\nexport interface TaskManagerStoreContext {\n tasks: Pick<ITasksContextObject, \"updateTask\" | \"updateLog\" | \"listTasks\">;\n}\n\nexport interface ITaskManagerStoreParams {\n context: TaskManagerStoreContext;\n task: ITask;\n log: ITaskLog;\n databaseLogs: boolean;\n}\n\nexport class TaskManagerStore<\n T extends ITaskDataInput = ITaskDataInput,\n O extends TaskDefinition.TaskOutput = TaskDefinition.TaskOutput\n> implements ITaskManagerStorePrivate<T, O> {\n private readonly context: TaskManagerStoreContext;\n private task: ITask<T, O>;\n private taskLog: ITaskLog;\n private readonly databaseLogs: boolean;\n\n private readonly taskUpdater = new ObjectUpdater<ITask<T, O>>();\n private readonly taskLogUpdater = new ObjectUpdater<ITaskLog>();\n\n public constructor(params: ITaskManagerStoreParams) {\n this.context = params.context;\n this.task = params.task as ITask<T, O>;\n this.taskLog = params.log;\n this.databaseLogs = params.databaseLogs === true;\n }\n\n public getStatus(): TaskDataStatus {\n return this.task.taskStatus;\n }\n\n public getTask(): ITask<T, O> {\n return this.task as ITask<T, O>;\n }\n\n public async listChildTasks<\n I extends TaskDefinition.TaskInput = TaskDefinition.TaskInput,\n O extends TaskDefinition.TaskOutput = TaskDefinition.TaskOutput\n >(definitionId?: string): Promise<ITask<I, O>[]> {\n const where: IListTaskParamsWhere = {\n parentId: this.task.id\n };\n if (definitionId) {\n where.definitionId = definitionId;\n }\n const result = await this.context.tasks.listTasks<I, O>({\n where,\n sort: [\"createdOn_ASC\"],\n limit: 1000000\n });\n return result.items;\n }\n\n public async updateTask(\n param: ITaskManagerStoreUpdateTaskParams<T, O>,\n options?: ITaskManagerStoreUpdateTaskOptions\n ): Promise<void> {\n const data = typeof param === \"function\" ? param(this.task) : param;\n\n /**\n * No need to update if nothing changed.\n */\n if (deepEqual(data, this.task)) {\n return;\n }\n\n this.taskUpdater.update(data);\n\n if (options?.save === false) {\n return;\n }\n await this.save();\n }\n\n public async updateInput(\n param: ITaskManagerStoreUpdateTaskInputParam<T>,\n options?: ITaskManagerStoreUpdateTaskInputOptions\n ): Promise<void> {\n const input = getInput<T>(this.task.input, param);\n\n /**\n * No need to update if nothing changed.\n */\n if (deepEqual(input, this.task.input)) {\n return;\n }\n this.taskUpdater.update({\n input: input as T\n });\n if (options?.save === false) {\n return;\n }\n await this.save();\n }\n\n public getInput(): T {\n return this.task.input as T;\n }\n\n public async updateOutput(\n values: Partial<O>,\n options: ITaskManagerStoreSetOutputOptions = {}\n ): Promise<void> {\n this.taskUpdater.update({\n output: values as O\n });\n if (options?.save === false) {\n return;\n }\n await this.save();\n }\n\n public getOutput(): O {\n return this.task.output as O;\n }\n /**\n * Currently the methods throws an error if something goes wrong during the database update.\n * TODO: Maybe we should wrap it into try/catch and return error if any?\n */\n public async addInfoLog(\n log: ITaskManagerStoreInfoLog,\n options?: ITaskManagerStoreAddLogOptions\n ): Promise<void> {\n if (!this.databaseLogs) {\n return;\n }\n this.taskLogUpdater.update({\n items: [\n {\n message: log.message,\n data: log.data,\n type: TaskLogItemType.INFO,\n createdOn: new Date().toISOString()\n }\n ]\n });\n if (options?.save === false) {\n return;\n }\n\n await this.save();\n }\n /**\n * Currently the methods throws an error if something goes wrong during the database update.\n * TODO: Maybe we should wrap it into try/catch and return error if any?\n */\n public async addErrorLog(\n log: ITaskManagerStoreErrorLog,\n options?: ITaskManagerStoreAddLogOptions\n ): Promise<void> {\n if (!this.databaseLogs) {\n return;\n }\n /**\n * Let's log the error to the console as well.\n */\n console.error(log.error);\n /**\n * Then update the log object.\n */\n this.taskLogUpdater.update({\n items: [\n {\n message: log.message,\n error: log.error instanceof Error ? getObjectProperties(log.error) : log.error,\n type: TaskLogItemType.ERROR,\n createdOn: new Date().toISOString()\n }\n ]\n });\n if (options?.save === false) {\n return;\n }\n await this.save();\n }\n\n public async save(): Promise<void> {\n /**\n * Update both task and the log, if anything to update.\n */\n if (this.taskUpdater.isDirty()) {\n this.task = await this.context.tasks.updateTask<T, O>(\n this.task.id,\n this.taskUpdater.fetch()\n );\n }\n if (!this.databaseLogs) {\n return;\n }\n if (this.taskLogUpdater.isDirty()) {\n this.taskLog = await this.context.tasks.updateLog(\n this.taskLog.id,\n this.taskLogUpdater.fetch()\n );\n }\n }\n}\n"],"mappings":"AAaA,SAASA,eAAe;AAOxB;AACA;AACA;AACA,OAAOC,SAAS,MAAM,YAAY;AAClC,SAASC,mBAAmB;AAC5B,SAASC,aAAa;AAGtB,MAAMC,QAAQ,GAAGA,CACbC,aAAgB,EAChBC,KAA+C,KAC3C;EACJ,IAAI,OAAOA,KAAK,KAAK,UAAU,EAAE;IAC7B,OAAOA,KAAK,CAACD,aAAa,CAAC;EAC/B;EACA,OAAO;IACH,GAAGA,aAAa;IAChB,GAAGC;EACP,CAAC;AACL,CAAC;AAaD,OAAO,MAAMC,gBAAgB,CAGe;EAMvBC,WAAW,GAAG,IAAIL,aAAa,CAAc,CAAC;EAC9CM,cAAc,GAAG,IAAIN,aAAa,CAAW,CAAC;EAExDO,WAAWA,CAACC,MAA+B,EAAE;IAChD,IAAI,CAACC,OAAO,GAAGD,MAAM,CAACC,OAAO;IAC7B,IAAI,CAACC,IAAI,GAAGF,MAAM,CAACE,IAAmB;IACtC,IAAI,CAACC,OAAO,GAAGH,MAAM,CAACI,GAAG;IACzB,IAAI,CAACC,YAAY,GAAG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C9B,CAAC;IACL;EACJ;AACJ","ignoreList":[]}
|
package/runner/TaskRunner.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { ITaskRawEvent } from "../handler/types";
|
|
2
|
-
import type { ITaskEventValidation, ITaskRunner } from "./abstractions";
|
|
3
|
-
import type { Context } from "../types";
|
|
4
|
-
import type { IResponseResult } from "../response/abstractions";
|
|
5
|
-
import type { ITimer } from "@webiny/handler-aws/utils";
|
|
1
|
+
import type { ITaskRawEvent } from "../handler/types.js";
|
|
2
|
+
import type { ITaskEventValidation, ITaskRunner } from "./abstractions/index.js";
|
|
3
|
+
import type { Context } from "../types.js";
|
|
4
|
+
import type { IResponseResult } from "../response/abstractions/index.js";
|
|
5
|
+
import type { ITimer } from "@webiny/handler-aws/utils/index.js";
|
|
6
6
|
export declare class TaskRunner<C extends Context = Context> implements ITaskRunner<C> {
|
|
7
7
|
/**
|
|
8
8
|
* When DI is introduced, these will get injected.
|
|
@@ -22,5 +22,4 @@ export declare class TaskRunner<C extends Context = Context> implements ITaskRun
|
|
|
22
22
|
isCloseToTimeout(seconds?: number): boolean;
|
|
23
23
|
run(rawEvent: ITaskRawEvent): Promise<IResponseResult>;
|
|
24
24
|
private getIsCloseToTimeoutMilliseconds;
|
|
25
|
-
private setLocale;
|
|
26
25
|
}
|
package/runner/TaskRunner.js
CHANGED
|
@@ -1,17 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.TaskRunner = void 0;
|
|
7
|
-
var _response = require("../response");
|
|
8
|
-
var _TaskControl = require("./TaskControl");
|
|
9
|
-
var _getErrorProperties = require("../utils/getErrorProperties");
|
|
1
|
+
import { Response, ResponseErrorResult } from "../response/index.js";
|
|
2
|
+
import { TaskControl } from "./TaskControl.js";
|
|
3
|
+
import { getErrorProperties } from "../utils/getErrorProperties.js";
|
|
10
4
|
const transformMinutesIntoMilliseconds = minutes => {
|
|
11
5
|
return minutes * 60000;
|
|
12
6
|
};
|
|
13
7
|
const DEFAULT_TASKS_TIMEOUT_CLOSE_MINUTES = 3;
|
|
14
|
-
class TaskRunner {
|
|
8
|
+
export class TaskRunner {
|
|
15
9
|
/**
|
|
16
10
|
* When DI is introduced, these will get injected.
|
|
17
11
|
*
|
|
@@ -34,7 +28,7 @@ class TaskRunner {
|
|
|
34
28
|
return this.timer.getRemainingMilliseconds() < milliseconds;
|
|
35
29
|
}
|
|
36
30
|
async run(rawEvent) {
|
|
37
|
-
const response = new
|
|
31
|
+
const response = new Response({
|
|
38
32
|
...rawEvent
|
|
39
33
|
});
|
|
40
34
|
let event;
|
|
@@ -42,7 +36,7 @@ class TaskRunner {
|
|
|
42
36
|
event = this.validation.validate(rawEvent);
|
|
43
37
|
} catch (ex) {
|
|
44
38
|
return response.error({
|
|
45
|
-
error:
|
|
39
|
+
error: getErrorProperties(ex)
|
|
46
40
|
});
|
|
47
41
|
}
|
|
48
42
|
response.setEvent(event);
|
|
@@ -55,15 +49,10 @@ class TaskRunner {
|
|
|
55
49
|
wait: rawEvent.delay
|
|
56
50
|
});
|
|
57
51
|
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Here we set the context locale, using the value receive from the event.
|
|
61
|
-
*/
|
|
62
|
-
this.setLocale(event);
|
|
63
|
-
const control = new _TaskControl.TaskControl(this, response, this.context);
|
|
52
|
+
const control = new TaskControl(this, response, this.context);
|
|
64
53
|
try {
|
|
65
54
|
const result = await control.run(event);
|
|
66
|
-
if (result instanceof
|
|
55
|
+
if (result instanceof ResponseErrorResult === false) {
|
|
67
56
|
return result;
|
|
68
57
|
}
|
|
69
58
|
console.error(result);
|
|
@@ -72,7 +61,7 @@ class TaskRunner {
|
|
|
72
61
|
console.error(`Failed to execute task "${event.webinyTaskId}".`);
|
|
73
62
|
console.error(ex);
|
|
74
63
|
return response.error({
|
|
75
|
-
error:
|
|
64
|
+
error: getErrorProperties(ex)
|
|
76
65
|
});
|
|
77
66
|
}
|
|
78
67
|
}
|
|
@@ -81,17 +70,6 @@ class TaskRunner {
|
|
|
81
70
|
const result = value > 0 ? value : DEFAULT_TASKS_TIMEOUT_CLOSE_MINUTES;
|
|
82
71
|
return transformMinutesIntoMilliseconds(result);
|
|
83
72
|
}
|
|
84
|
-
setLocale(event) {
|
|
85
|
-
const {
|
|
86
|
-
locale: localeCode
|
|
87
|
-
} = event;
|
|
88
|
-
const locale = this.context.i18n.getLocale(localeCode);
|
|
89
|
-
if (!locale) {
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
this.context.i18n.setContentLocale(locale);
|
|
93
|
-
}
|
|
94
73
|
}
|
|
95
|
-
exports.TaskRunner = TaskRunner;
|
|
96
74
|
|
|
97
75
|
//# sourceMappingURL=TaskRunner.js.map
|
package/runner/TaskRunner.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["Response","ResponseErrorResult","TaskControl","getErrorProperties","transformMinutesIntoMilliseconds","minutes","DEFAULT_TASKS_TIMEOUT_CLOSE_MINUTES","TaskRunner","constructor","context","timer","validation","isCloseToTimeout","seconds","milliseconds","getIsCloseToTimeoutMilliseconds","getRemainingMilliseconds","run","rawEvent","response","event","validate","ex","error","setEvent","delay","continue","input","wait","control","result","console","webinyTaskId","value","parseInt","process","env"],"sources":["TaskRunner.ts"],"sourcesContent":["import type { ITaskEvent, ITaskRawEvent } from \"~/handler/types.js\";\nimport type { ITaskEventValidation, ITaskRunner } from \"./abstractions/index.js\";\nimport type { Context } from \"~/types.js\";\nimport { Response, ResponseErrorResult } from \"~/response/index.js\";\nimport { TaskControl } from \"./TaskControl.js\";\nimport type { IResponseResult } from \"~/response/abstractions/index.js\";\nimport { getErrorProperties } from \"~/utils/getErrorProperties.js\";\nimport type { ITimer } from \"@webiny/handler-aws/utils/index.js\";\n\nconst transformMinutesIntoMilliseconds = (minutes: number) => {\n return minutes * 60000;\n};\n\nconst DEFAULT_TASKS_TIMEOUT_CLOSE_MINUTES = 3;\n\nexport class TaskRunner<C extends Context = Context> implements ITaskRunner<C> {\n /**\n * When DI is introduced, these will get injected.\n *\n * container.bind<Request>(\"Request\").toConstantValue(request);\n * @inject(\"Request\") public readonly request: Request;\n *\n * Follow the same example for the rest of the properties.\n */\n public readonly context: C;\n public readonly timer: ITimer;\n private readonly validation: ITaskEventValidation;\n\n /**\n * We take all required variables separately because they will get injected via DI - so less refactoring is required in the future.\n */\n public constructor(context: C, timer: ITimer, validation: ITaskEventValidation) {\n this.context = context;\n this.timer = timer;\n this.validation = validation;\n }\n\n public isCloseToTimeout(seconds?: number) {\n const milliseconds = seconds ? seconds * 1000 : this.getIsCloseToTimeoutMilliseconds();\n return this.timer.getRemainingMilliseconds() < milliseconds;\n }\n\n public async run(rawEvent: ITaskRawEvent): Promise<IResponseResult> {\n const response = new Response({\n ...rawEvent\n });\n\n let event: ITaskEvent;\n try {\n event = this.validation.validate(rawEvent);\n } catch (ex) {\n return response.error({\n error: getErrorProperties(ex)\n });\n }\n response.setEvent(event);\n /**\n * If we received a delay when initiating the task, we need to send the continue response immediately.\n */\n if (rawEvent.delay && rawEvent.delay > 0) {\n return response.continue({\n input: {},\n wait: rawEvent.delay\n });\n }\n\n const control = new TaskControl(this, response, this.context);\n\n try {\n const result = await control.run(event);\n if (result instanceof ResponseErrorResult === false) {\n return result;\n }\n console.error(result);\n return result;\n } catch (ex) {\n console.error(`Failed to execute task \"${event.webinyTaskId}\".`);\n console.error(ex);\n return response.error({\n error: getErrorProperties(ex)\n });\n }\n }\n\n private getIsCloseToTimeoutMilliseconds() {\n const value = parseInt(process.env[\"WEBINY_TASKS_TIMEOUT_CLOSE_MINUTES\"] || \"\");\n const result = value > 0 ? value : DEFAULT_TASKS_TIMEOUT_CLOSE_MINUTES;\n return transformMinutesIntoMilliseconds(result);\n }\n}\n"],"mappings":"AAGA,SAASA,QAAQ,EAAEC,mBAAmB;AACtC,SAASC,WAAW;AAEp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C,CAAC;IACN;IAEA,MAAMI,OAAO,GAAG,IAAI3B,WAAW,CAAC,IAAI,EAAEiB,QAAQ,EAAE,IAAI,CAACV,OAAO,CAAC;IAE7D,IAAI;MACA,MAAMqB,MAAM,GAAG,MAAMD,OAAO,CAACZ,GAAG,CAACG,KAAK,CAAC;MACvC,IAAIU,MAAM,YAAY7B,mBAAmB,KAAK,KAAK,EAAE;QACjD,OAAO6B,MAAM;MACjB;MACAC,OAAO,CAACR,KAAK,CAACO,MAAM,CAAC;MACrB,OAAOA,MAAM;IACjB,CAAC,CAAC,OAAOR,EAAE,EAAE;MACTS,OAAO,CAACR,KAAK,CAAC,2BAA2BH,KAAK,CAACY,YAAY,IAAI,CAAC;MAChED,OAAO,CAACR,KAAK,CAACD,EAAE,CAAC;MACjB,OAAOH,QAAQ,CAACI,KAAK,CAAC;QAClBA,KAAK,EAAEpB,kBAAkB,CAACmB,EAAE;MAChC,CAAC,CAAC;IACN;EACJ;EAEQP,+BAA+BA,CAAA,EAAG;IACtC,MAAMkB,KAAK,GAAGC,QAAQ,CAACC,OAAO,CAACC,GAAG,CAAC,oCAAoC,CAAC,IAAI,EAAE,CAAC;IAC/E,MAAMN,MAAM,GAAGG,KAAK,GAAG,CAAC,GAAGA,KAAK,GAAG3B,mCAAmC;IACtE,OAAOF,gCAAgC,CAAC0B,MAAM,CAAC;EACnD;AACJ","ignoreList":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { ITaskRunner } from "
|
|
2
|
-
import type { IResponse, IResponseResult } from "../../response/abstractions";
|
|
3
|
-
import type { Context } from "../../types";
|
|
4
|
-
import type { ITaskEvent } from "../../handler/types";
|
|
1
|
+
import type { ITaskRunner } from "../../runner/abstractions/index.js";
|
|
2
|
+
import type { IResponse, IResponseResult } from "../../response/abstractions/index.js";
|
|
3
|
+
import type { Context } from "../../types.js";
|
|
4
|
+
import type { ITaskEvent } from "../../handler/types.js";
|
|
5
5
|
export interface ITaskControl {
|
|
6
6
|
runner: ITaskRunner;
|
|
7
7
|
response: IResponse;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["TaskControl.ts"],"sourcesContent":["import type { ITaskRunner } from \"~/runner/abstractions\";\nimport type { IResponse, IResponseResult } from \"~/response/abstractions\";\nimport type { Context } from \"~/types\";\nimport type { ITaskEvent } from \"~/handler/types\";\n\nexport interface ITaskControl {\n runner: ITaskRunner;\n response: IResponse;\n context: Context;\n\n run(event: ITaskEvent): Promise<IResponseResult>;\n}\n"],"mappings":"","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":[],"sources":["TaskControl.ts"],"sourcesContent":["import type { ITaskRunner } from \"~/runner/abstractions/index.js\";\nimport type { IResponse, IResponseResult } from \"~/response/abstractions/index.js\";\nimport type { Context } from \"~/types.js\";\nimport type { ITaskEvent } from \"~/handler/types.js\";\n\nexport interface ITaskControl {\n runner: ITaskRunner;\n response: IResponse;\n context: Context;\n\n run(event: ITaskEvent): Promise<IResponseResult>;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ITaskEvent } from "../../handler/types";
|
|
1
|
+
import type { ITaskEvent } from "../../handler/types.js";
|
|
2
2
|
export type ITaskEventValidationResult = ITaskEvent;
|
|
3
3
|
export interface ITaskEventValidation {
|
|
4
4
|
validate: (event: Partial<ITaskEvent>) => ITaskEventValidationResult;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["TaskEventValidation.ts"],"sourcesContent":["import type { ITaskEvent } from \"~/handler/types\";\n\nexport type ITaskEventValidationResult = ITaskEvent;\n\nexport interface ITaskEventValidation {\n validate: (event: Partial<ITaskEvent>) => ITaskEventValidationResult;\n}\n"],"mappings":"","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":[],"sources":["TaskEventValidation.ts"],"sourcesContent":["import type { ITaskEvent } from \"~/handler/types.js\";\n\nexport type ITaskEventValidationResult = ITaskEvent;\n\nexport interface ITaskEventValidation {\n validate: (event: Partial<ITaskEvent>) => ITaskEventValidationResult;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { IResponseResult } from "../../response/abstractions";
|
|
2
|
-
import
|
|
3
|
-
export interface ITaskManager
|
|
4
|
-
run: (definition:
|
|
1
|
+
import type { IResponseResult } from "../../response/abstractions/index.js";
|
|
2
|
+
import { TaskDefinition } from "@webiny/api-core/features/task/TaskDefinition/index.js";
|
|
3
|
+
export interface ITaskManager {
|
|
4
|
+
run: (definition: TaskDefinition.Runnable) => Promise<IResponseResult>;
|
|
5
5
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["TaskManager.ts"],"sourcesContent":["import type { IResponseResult } from \"~/response/abstractions\";\nimport
|
|
1
|
+
{"version":3,"names":[],"sources":["TaskManager.ts"],"sourcesContent":["import type { IResponseResult } from \"~/response/abstractions/index.js\";\nimport { TaskDefinition } from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\n\nexport interface ITaskManager {\n run: (definition: TaskDefinition.Runnable) => Promise<IResponseResult>;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import type { IResponseError, ITask,
|
|
2
|
-
import
|
|
3
|
-
export type ITaskManagerStoreUpdateTaskValues<T =
|
|
4
|
-
export interface ITaskManagerStoreUpdateTaskValuesCb<T =
|
|
1
|
+
import type { IResponseError, ITask, ITaskLogItemData, ITaskUpdateData, TaskDataStatus } from "../../types.js";
|
|
2
|
+
import { TaskDefinition } from "@webiny/api-core/features/task/TaskDefinition/index.js";
|
|
3
|
+
export type ITaskManagerStoreUpdateTaskValues<T extends TaskDefinition.TaskInput = TaskDefinition.TaskInput> = T;
|
|
4
|
+
export interface ITaskManagerStoreUpdateTaskValuesCb<T extends TaskDefinition.TaskInput = TaskDefinition.TaskInput> {
|
|
5
5
|
(input: T): T;
|
|
6
6
|
}
|
|
7
7
|
export interface ITaskManagerStoreUpdateTaskInputOptions {
|
|
8
8
|
save: boolean;
|
|
9
9
|
}
|
|
10
|
-
export type ITaskManagerStoreUpdateTaskInputParam<T =
|
|
11
|
-
export interface ITaskManagerStoreUpdateTaskParamCb<T =
|
|
10
|
+
export type ITaskManagerStoreUpdateTaskInputParam<T extends TaskDefinition.TaskInput = TaskDefinition.TaskInput> = ITaskManagerStoreUpdateTaskValuesCb<T> | Partial<ITaskManagerStoreUpdateTaskValues<T>>;
|
|
11
|
+
export interface ITaskManagerStoreUpdateTaskParamCb<T extends TaskDefinition.TaskInput = TaskDefinition.TaskInput, O extends TaskDefinition.TaskOutput = TaskDefinition.TaskOutput> {
|
|
12
12
|
(task: ITask<T, O>): ITaskUpdateData<T, O>;
|
|
13
13
|
}
|
|
14
|
-
export type ITaskManagerStoreUpdateTask<T =
|
|
15
|
-
export type ITaskManagerStoreUpdateTaskParams<T =
|
|
14
|
+
export type ITaskManagerStoreUpdateTask<T extends TaskDefinition.TaskInput = TaskDefinition.TaskInput, O extends TaskDefinition.TaskOutput = TaskDefinition.TaskOutput> = ITaskUpdateData<T, O>;
|
|
15
|
+
export type ITaskManagerStoreUpdateTaskParams<T extends TaskDefinition.TaskInput = TaskDefinition.TaskInput, O extends TaskDefinition.TaskOutput = TaskDefinition.TaskOutput> = ITaskManagerStoreUpdateTaskParamCb<T, O> | Partial<ITaskManagerStoreUpdateTask<T, O>>;
|
|
16
16
|
export interface ITaskManagerStoreInfoLog {
|
|
17
17
|
message: string;
|
|
18
18
|
data?: ITaskLogItemData;
|
|
@@ -43,7 +43,7 @@ export interface ITaskManagerStoreAddLogOptions {
|
|
|
43
43
|
/**
|
|
44
44
|
* Interface should not be used outside the @webiny/tasks package.
|
|
45
45
|
*/
|
|
46
|
-
export interface ITaskManagerStorePrivate<T =
|
|
46
|
+
export interface ITaskManagerStorePrivate<T extends TaskDefinition.TaskInput = TaskDefinition.TaskInput, O extends TaskDefinition.TaskOutput = TaskDefinition.TaskOutput> {
|
|
47
47
|
getTask: () => ITask<T, O>;
|
|
48
48
|
getStatus: () => TaskDataStatus;
|
|
49
49
|
/**
|
|
@@ -54,7 +54,7 @@ export interface ITaskManagerStorePrivate<T = ITaskDataInput, O extends ITaskRes
|
|
|
54
54
|
* List all child tasks of the current task.
|
|
55
55
|
* If definitionId is provided, filter by that parameter.
|
|
56
56
|
*/
|
|
57
|
-
listChildTasks<T =
|
|
57
|
+
listChildTasks<T extends TaskDefinition.TaskInput = TaskDefinition.TaskInput, O extends TaskDefinition.TaskOutput = TaskDefinition.TaskOutput>(definitionId?: string): Promise<ITask<T, O>[]>;
|
|
58
58
|
/**
|
|
59
59
|
* Update the task input, which are used to store custom user data.
|
|
60
60
|
* You can send partial input, and it will be merged with the existing input.
|
|
@@ -89,4 +89,4 @@ export interface ITaskManagerStorePrivate<T = ITaskDataInput, O extends ITaskRes
|
|
|
89
89
|
*/
|
|
90
90
|
save(): Promise<void>;
|
|
91
91
|
}
|
|
92
|
-
export type ITaskManagerStore<T =
|
|
92
|
+
export type ITaskManagerStore<T extends TaskDefinition.TaskInput = TaskDefinition.TaskInput, O extends TaskDefinition.TaskOutput = TaskDefinition.TaskOutput> = Omit<ITaskManagerStorePrivate<T, O>, "save">;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["TaskManagerStore.ts"],"sourcesContent":["import type {\n IResponseError,\n ITask,\n
|
|
1
|
+
{"version":3,"names":[],"sources":["TaskManagerStore.ts"],"sourcesContent":["import type {\n IResponseError,\n ITask,\n ITaskLogItemData,\n ITaskUpdateData,\n TaskDataStatus\n} from \"~/types.js\";\nimport { TaskDefinition } from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\n\nexport type ITaskManagerStoreUpdateTaskValues<\n T extends TaskDefinition.TaskInput = TaskDefinition.TaskInput\n> = T;\n\nexport interface ITaskManagerStoreUpdateTaskValuesCb<\n T extends TaskDefinition.TaskInput = TaskDefinition.TaskInput\n> {\n (input: T): T;\n}\n\nexport interface ITaskManagerStoreUpdateTaskInputOptions {\n save: boolean;\n}\n\nexport type ITaskManagerStoreUpdateTaskInputParam<\n T extends TaskDefinition.TaskInput = TaskDefinition.TaskInput\n> = ITaskManagerStoreUpdateTaskValuesCb<T> | Partial<ITaskManagerStoreUpdateTaskValues<T>>;\n\nexport interface ITaskManagerStoreUpdateTaskParamCb<\n T extends TaskDefinition.TaskInput = TaskDefinition.TaskInput,\n O extends TaskDefinition.TaskOutput = TaskDefinition.TaskOutput\n> {\n (task: ITask<T, O>): ITaskUpdateData<T, O>;\n}\n\nexport type ITaskManagerStoreUpdateTask<\n T extends TaskDefinition.TaskInput = TaskDefinition.TaskInput,\n O extends TaskDefinition.TaskOutput = TaskDefinition.TaskOutput\n> = ITaskUpdateData<T, O>;\n\nexport type ITaskManagerStoreUpdateTaskParams<\n T extends TaskDefinition.TaskInput = TaskDefinition.TaskInput,\n O extends TaskDefinition.TaskOutput = TaskDefinition.TaskOutput\n> = ITaskManagerStoreUpdateTaskParamCb<T, O> | Partial<ITaskManagerStoreUpdateTask<T, O>>;\n\nexport interface ITaskManagerStoreInfoLog {\n message: string;\n data?: ITaskLogItemData;\n}\n\nexport interface ITaskManagerStoreErrorLog {\n message: string;\n data?: ITaskLogItemData;\n error: IResponseError | Error;\n}\n\nexport interface ITaskManagerStoreSetOutputOptions {\n /**\n * Default is true.\n */\n save?: boolean;\n}\n\nexport interface ITaskManagerStoreUpdateTaskOptions {\n /**\n * Default is true.\n */\n save?: boolean;\n}\n\nexport interface ITaskManagerStoreAddLogOptions {\n /**\n * Default is true.\n */\n save?: boolean;\n}\n\n/**\n * Interface should not be used outside the @webiny/tasks package.\n */\nexport interface ITaskManagerStorePrivate<\n T extends TaskDefinition.TaskInput = TaskDefinition.TaskInput,\n O extends TaskDefinition.TaskOutput = TaskDefinition.TaskOutput\n> {\n getTask: () => ITask<T, O>;\n getStatus: () => TaskDataStatus;\n /**\n * @throws {Error} If task not found or something goes wrong during the database update.\n */\n updateTask(\n params: ITaskManagerStoreUpdateTaskParams<T, O>,\n options?: ITaskManagerStoreUpdateTaskOptions\n ): Promise<void>;\n /**\n * List all child tasks of the current task.\n * If definitionId is provided, filter by that parameter.\n */\n listChildTasks<\n T extends TaskDefinition.TaskInput = TaskDefinition.TaskInput,\n O extends TaskDefinition.TaskOutput = TaskDefinition.TaskOutput\n >(\n definitionId?: string\n ): Promise<ITask<T, O>[]>;\n /**\n * Update the task input, which are used to store custom user data.\n * You can send partial input, and it will be merged with the existing input.\n *\n * @throws {Error} If task not found or something goes wrong during the database update.\n */\n updateInput: (\n params: ITaskManagerStoreUpdateTaskInputParam<T>,\n options?: ITaskManagerStoreUpdateTaskInputOptions\n ) => Promise<void>;\n getInput: () => T;\n /**\n * Update the task output, which are used to store the output data.\n * You can send partial output, and it will be merged with the existing output.\n *\n * Second parameter is optional options, and it contains a possibility not to store the task immediately.\n *\n * @throws {Error} If task not found or something goes wrong during the database update.\n */\n updateOutput: (\n values: Partial<O>,\n options?: ITaskManagerStoreSetOutputOptions\n ) => Promise<void>;\n getOutput: () => O;\n /**\n * @throws {Error} If task not found or something goes wrong during the database update.\n */\n addInfoLog: (log: ITaskManagerStoreInfoLog) => Promise<void>;\n /**\n * @throws {Error} If task not found or something goes wrong during the database update.\n *\n *\n */\n addErrorLog: (log: ITaskManagerStoreErrorLog) => Promise<void>;\n /**\n * Should store the task and logs into the database, if any.\n * If nothing to update, it should skip calling the internal store methods.\n */\n save(): Promise<void>;\n}\n\nexport type ITaskManagerStore<\n T extends TaskDefinition.TaskInput = TaskDefinition.TaskInput,\n O extends TaskDefinition.TaskOutput = TaskDefinition.TaskOutput\n> = Omit<ITaskManagerStorePrivate<T, O>, \"save\">;\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Context } from "../../types";
|
|
2
|
-
import type { ITaskEvent } from "../../handler/types";
|
|
3
|
-
import type { IResponseResult } from "../../response/abstractions";
|
|
1
|
+
import type { Context } from "../../types.js";
|
|
2
|
+
import type { ITaskEvent } from "../../handler/types.js";
|
|
3
|
+
import type { IResponseResult } from "../../response/abstractions/index.js";
|
|
4
4
|
import type { ITimer } from "@webiny/handler-aws";
|
|
5
5
|
export interface IIsCloseToTimeoutCallable {
|
|
6
6
|
(seconds?: number): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["TaskRunner.ts"],"sourcesContent":["import type { Context } from \"~/types\";\nimport type { ITaskEvent } from \"~/handler/types\";\nimport type { IResponseResult } from \"~/response/abstractions\";\nimport type { ITimer } from \"@webiny/handler-aws\";\n\nexport interface IIsCloseToTimeoutCallable {\n (seconds?: number): boolean;\n}\n\nexport interface ITaskRunner<C extends Context = Context> {\n context: C;\n isCloseToTimeout: IIsCloseToTimeoutCallable;\n timer: ITimer;\n run(event: ITaskEvent): Promise<IResponseResult>;\n}\n"],"mappings":"","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":[],"sources":["TaskRunner.ts"],"sourcesContent":["import type { Context } from \"~/types.js\";\nimport type { ITaskEvent } from \"~/handler/types.js\";\nimport type { IResponseResult } from \"~/response/abstractions/index.js\";\nimport type { ITimer } from \"@webiny/handler-aws\";\n\nexport interface IIsCloseToTimeoutCallable {\n (seconds?: number): boolean;\n}\n\nexport interface ITaskRunner<C extends Context = Context> {\n context: C;\n isCloseToTimeout: IIsCloseToTimeoutCallable;\n timer: ITimer;\n run(event: ITaskEvent): Promise<IResponseResult>;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from "./TaskControl";
|
|
2
|
-
export * from "./TaskEventValidation";
|
|
3
|
-
export * from "./TaskManager";
|
|
4
|
-
export * from "./TaskRunner";
|
|
5
|
-
export * from "./TaskManagerStore";
|
|
1
|
+
export * from "./TaskControl.js";
|
|
2
|
+
export * from "./TaskEventValidation.js";
|
|
3
|
+
export * from "./TaskManager.js";
|
|
4
|
+
export * from "./TaskRunner.js";
|
|
5
|
+
export * from "./TaskManagerStore.js";
|
|
@@ -1,62 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var _TaskControl = require("./TaskControl");
|
|
7
|
-
Object.keys(_TaskControl).forEach(function (key) {
|
|
8
|
-
if (key === "default" || key === "__esModule") return;
|
|
9
|
-
if (key in exports && exports[key] === _TaskControl[key]) return;
|
|
10
|
-
Object.defineProperty(exports, key, {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function () {
|
|
13
|
-
return _TaskControl[key];
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
var _TaskEventValidation = require("./TaskEventValidation");
|
|
18
|
-
Object.keys(_TaskEventValidation).forEach(function (key) {
|
|
19
|
-
if (key === "default" || key === "__esModule") return;
|
|
20
|
-
if (key in exports && exports[key] === _TaskEventValidation[key]) return;
|
|
21
|
-
Object.defineProperty(exports, key, {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function () {
|
|
24
|
-
return _TaskEventValidation[key];
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
var _TaskManager = require("./TaskManager");
|
|
29
|
-
Object.keys(_TaskManager).forEach(function (key) {
|
|
30
|
-
if (key === "default" || key === "__esModule") return;
|
|
31
|
-
if (key in exports && exports[key] === _TaskManager[key]) return;
|
|
32
|
-
Object.defineProperty(exports, key, {
|
|
33
|
-
enumerable: true,
|
|
34
|
-
get: function () {
|
|
35
|
-
return _TaskManager[key];
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
var _TaskRunner = require("./TaskRunner");
|
|
40
|
-
Object.keys(_TaskRunner).forEach(function (key) {
|
|
41
|
-
if (key === "default" || key === "__esModule") return;
|
|
42
|
-
if (key in exports && exports[key] === _TaskRunner[key]) return;
|
|
43
|
-
Object.defineProperty(exports, key, {
|
|
44
|
-
enumerable: true,
|
|
45
|
-
get: function () {
|
|
46
|
-
return _TaskRunner[key];
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
var _TaskManagerStore = require("./TaskManagerStore");
|
|
51
|
-
Object.keys(_TaskManagerStore).forEach(function (key) {
|
|
52
|
-
if (key === "default" || key === "__esModule") return;
|
|
53
|
-
if (key in exports && exports[key] === _TaskManagerStore[key]) return;
|
|
54
|
-
Object.defineProperty(exports, key, {
|
|
55
|
-
enumerable: true,
|
|
56
|
-
get: function () {
|
|
57
|
-
return _TaskManagerStore[key];
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
});
|
|
1
|
+
export * from "./TaskControl.js";
|
|
2
|
+
export * from "./TaskEventValidation.js";
|
|
3
|
+
export * from "./TaskManager.js";
|
|
4
|
+
export * from "./TaskRunner.js";
|
|
5
|
+
export * from "./TaskManagerStore.js";
|
|
61
6
|
|
|
62
7
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./TaskControl.js\";\nexport * from \"./TaskEventValidation.js\";\nexport * from \"./TaskManager.js\";\nexport * from \"./TaskRunner.js\";\nexport * from \"./TaskManagerStore.js\";\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA","ignoreList":[]}
|
package/runner/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./TaskRunner";
|
|
1
|
+
export * from "./TaskRunner.js";
|
package/runner/index.js
CHANGED
|
@@ -1,18 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
var _TaskRunner = require("./TaskRunner");
|
|
7
|
-
Object.keys(_TaskRunner).forEach(function (key) {
|
|
8
|
-
if (key === "default" || key === "__esModule") return;
|
|
9
|
-
if (key in exports && exports[key] === _TaskRunner[key]) return;
|
|
10
|
-
Object.defineProperty(exports, key, {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function () {
|
|
13
|
-
return _TaskRunner[key];
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
});
|
|
1
|
+
export * from "./TaskRunner.js";
|
|
17
2
|
|
|
18
3
|
//# sourceMappingURL=index.js.map
|