@webiny/tasks 0.0.0-unstable.06b2ede40f

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 (171) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +10 -0
  3. package/context.d.ts +2 -0
  4. package/context.js +33 -0
  5. package/context.js.map +1 -0
  6. package/crud/crud.tasks.d.ts +2 -0
  7. package/crud/crud.tasks.js +273 -0
  8. package/crud/crud.tasks.js.map +1 -0
  9. package/crud/definition.tasks.d.ts +2 -0
  10. package/crud/definition.tasks.js +29 -0
  11. package/crud/definition.tasks.js.map +1 -0
  12. package/crud/model.d.ts +5 -0
  13. package/crud/model.js +216 -0
  14. package/crud/model.js.map +1 -0
  15. package/crud/service.tasks.d.ts +2 -0
  16. package/crud/service.tasks.js +171 -0
  17. package/crud/service.tasks.js.map +1 -0
  18. package/crud/where.d.ts +1 -0
  19. package/crud/where.js +33 -0
  20. package/crud/where.js.map +1 -0
  21. package/graphql/checkPermissions.d.ts +7 -0
  22. package/graphql/checkPermissions.js +46 -0
  23. package/graphql/checkPermissions.js.map +1 -0
  24. package/graphql/index.d.ts +2 -0
  25. package/graphql/index.js +351 -0
  26. package/graphql/index.js.map +1 -0
  27. package/graphql/utils.d.ts +9 -0
  28. package/graphql/utils.js +28 -0
  29. package/graphql/utils.js.map +1 -0
  30. package/handler/index.d.ts +6 -0
  31. package/handler/index.js +69 -0
  32. package/handler/index.js.map +1 -0
  33. package/handler/register.d.ts +1 -0
  34. package/handler/register.js +25 -0
  35. package/handler/register.js.map +1 -0
  36. package/handler/types.d.ts +25 -0
  37. package/handler/types.js +7 -0
  38. package/handler/types.js.map +1 -0
  39. package/index.d.ts +6 -0
  40. package/index.js +62 -0
  41. package/index.js.map +1 -0
  42. package/package.json +50 -0
  43. package/plugins/TaskServicePlugin.d.ts +20 -0
  44. package/plugins/TaskServicePlugin.js +17 -0
  45. package/plugins/TaskServicePlugin.js.map +1 -0
  46. package/plugins/index.d.ts +1 -0
  47. package/plugins/index.js +18 -0
  48. package/plugins/index.js.map +1 -0
  49. package/response/DatabaseResponse.d.ts +12 -0
  50. package/response/DatabaseResponse.js +152 -0
  51. package/response/DatabaseResponse.js.map +1 -0
  52. package/response/Response.d.ts +13 -0
  53. package/response/Response.js +120 -0
  54. package/response/Response.js.map +1 -0
  55. package/response/ResponseAbortedResult.d.ts +10 -0
  56. package/response/ResponseAbortedResult.js +19 -0
  57. package/response/ResponseAbortedResult.js.map +1 -0
  58. package/response/ResponseContinueResult.d.ts +18 -0
  59. package/response/ResponseContinueResult.js +26 -0
  60. package/response/ResponseContinueResult.js.map +1 -0
  61. package/response/ResponseDoneResult.d.ts +13 -0
  62. package/response/ResponseDoneResult.js +21 -0
  63. package/response/ResponseDoneResult.js.map +1 -0
  64. package/response/ResponseErrorResult.d.ts +11 -0
  65. package/response/ResponseErrorResult.js +20 -0
  66. package/response/ResponseErrorResult.js.map +1 -0
  67. package/response/TaskResponse.d.ts +11 -0
  68. package/response/TaskResponse.js +80 -0
  69. package/response/TaskResponse.js.map +1 -0
  70. package/response/abstractions/Response.d.ts +25 -0
  71. package/response/abstractions/Response.js +7 -0
  72. package/response/abstractions/Response.js.map +1 -0
  73. package/response/abstractions/ResponseAbortedResult.d.ts +5 -0
  74. package/response/abstractions/ResponseAbortedResult.js +7 -0
  75. package/response/abstractions/ResponseAbortedResult.js.map +1 -0
  76. package/response/abstractions/ResponseBaseResult.d.ts +8 -0
  77. package/response/abstractions/ResponseBaseResult.js +7 -0
  78. package/response/abstractions/ResponseBaseResult.js.map +1 -0
  79. package/response/abstractions/ResponseContinueResult.d.ts +21 -0
  80. package/response/abstractions/ResponseContinueResult.js +7 -0
  81. package/response/abstractions/ResponseContinueResult.js.map +1 -0
  82. package/response/abstractions/ResponseDoneResult.d.ts +14 -0
  83. package/response/abstractions/ResponseDoneResult.js +7 -0
  84. package/response/abstractions/ResponseDoneResult.js.map +1 -0
  85. package/response/abstractions/ResponseErrorResult.d.ts +19 -0
  86. package/response/abstractions/ResponseErrorResult.js +7 -0
  87. package/response/abstractions/ResponseErrorResult.js.map +1 -0
  88. package/response/abstractions/TaskResponse.d.ts +38 -0
  89. package/response/abstractions/TaskResponse.js +7 -0
  90. package/response/abstractions/TaskResponse.js.map +1 -0
  91. package/response/abstractions/index.d.ts +7 -0
  92. package/response/abstractions/index.js +84 -0
  93. package/response/abstractions/index.js.map +1 -0
  94. package/response/index.d.ts +7 -0
  95. package/response/index.js +84 -0
  96. package/response/index.js.map +1 -0
  97. package/runner/TaskControl.d.ts +14 -0
  98. package/runner/TaskControl.js +222 -0
  99. package/runner/TaskControl.js.map +1 -0
  100. package/runner/TaskEventValidation.d.ts +5 -0
  101. package/runner/TaskEventValidation.js +30 -0
  102. package/runner/TaskEventValidation.js.map +1 -0
  103. package/runner/TaskManager.d.ts +14 -0
  104. package/runner/TaskManager.js +139 -0
  105. package/runner/TaskManager.js.map +1 -0
  106. package/runner/TaskManagerStore.d.ts +40 -0
  107. package/runner/TaskManagerStore.js +167 -0
  108. package/runner/TaskManagerStore.js.map +1 -0
  109. package/runner/TaskRunner.d.ts +26 -0
  110. package/runner/TaskRunner.js +97 -0
  111. package/runner/TaskRunner.js.map +1 -0
  112. package/runner/abstractions/TaskControl.d.ts +10 -0
  113. package/runner/abstractions/TaskControl.js +7 -0
  114. package/runner/abstractions/TaskControl.js.map +1 -0
  115. package/runner/abstractions/TaskEventValidation.d.ts +5 -0
  116. package/runner/abstractions/TaskEventValidation.js +7 -0
  117. package/runner/abstractions/TaskEventValidation.js.map +1 -0
  118. package/runner/abstractions/TaskManager.d.ts +5 -0
  119. package/runner/abstractions/TaskManager.js +7 -0
  120. package/runner/abstractions/TaskManager.js.map +1 -0
  121. package/runner/abstractions/TaskManagerStore.d.ts +92 -0
  122. package/runner/abstractions/TaskManagerStore.js +7 -0
  123. package/runner/abstractions/TaskManagerStore.js.map +1 -0
  124. package/runner/abstractions/TaskRunner.d.ts +13 -0
  125. package/runner/abstractions/TaskRunner.js +7 -0
  126. package/runner/abstractions/TaskRunner.js.map +1 -0
  127. package/runner/abstractions/index.d.ts +5 -0
  128. package/runner/abstractions/index.js +62 -0
  129. package/runner/abstractions/index.js.map +1 -0
  130. package/runner/index.d.ts +1 -0
  131. package/runner/index.js +18 -0
  132. package/runner/index.js.map +1 -0
  133. package/service/EventBridgeEventTransportPlugin.d.ts +17 -0
  134. package/service/EventBridgeEventTransportPlugin.js +60 -0
  135. package/service/EventBridgeEventTransportPlugin.js.map +1 -0
  136. package/service/StepFunctionServicePlugin.d.ts +26 -0
  137. package/service/StepFunctionServicePlugin.js +88 -0
  138. package/service/StepFunctionServicePlugin.js.map +1 -0
  139. package/service/createService.d.ts +6 -0
  140. package/service/createService.js +30 -0
  141. package/service/createService.js.map +1 -0
  142. package/service/index.d.ts +4 -0
  143. package/service/index.js +31 -0
  144. package/service/index.js.map +1 -0
  145. package/task/index.d.ts +2 -0
  146. package/task/index.js +29 -0
  147. package/task/index.js.map +1 -0
  148. package/task/input.d.ts +15 -0
  149. package/task/input.js +21 -0
  150. package/task/input.js.map +1 -0
  151. package/task/plugin.d.ts +36 -0
  152. package/task/plugin.js +106 -0
  153. package/task/plugin.js.map +1 -0
  154. package/tasks/testingRunTask.d.ts +1 -0
  155. package/tasks/testingRunTask.js +21 -0
  156. package/tasks/testingRunTask.js.map +1 -0
  157. package/types.d.ts +340 -0
  158. package/types.js +69 -0
  159. package/types.js.map +1 -0
  160. package/utils/ObjectUpdater.d.ts +8 -0
  161. package/utils/ObjectUpdater.js +46 -0
  162. package/utils/ObjectUpdater.js.map +1 -0
  163. package/utils/getErrorProperties.d.ts +2 -0
  164. package/utils/getErrorProperties.js +15 -0
  165. package/utils/getErrorProperties.js.map +1 -0
  166. package/utils/getObjectProperties.d.ts +8 -0
  167. package/utils/getObjectProperties.js +25 -0
  168. package/utils/getObjectProperties.js.map +1 -0
  169. package/utils/index.d.ts +3 -0
  170. package/utils/index.js +40 -0
  171. package/utils/index.js.map +1 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Webiny
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,10 @@
1
+ # @webiny/tasks
2
+ [![](https://img.shields.io/npm/dw/@webiny/tasks.svg)](https://www.npmjs.com/package/@webiny/tasks)
3
+ [![](https://img.shields.io/npm/v/@webiny/tasks.svg)](https://www.npmjs.com/package/@webiny/tasks)
4
+ [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
5
+ [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
6
+
7
+ ## Install
8
+ ```
9
+ yarn add @webiny/tasks
10
+ ```
package/context.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import type { Plugin } from "@webiny/plugins";
2
+ export declare const createBackgroundTaskContext: () => Plugin[];
package/context.js ADDED
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createBackgroundTaskContext = void 0;
7
+ var _api = require("@webiny/api");
8
+ var _model = require("./crud/model");
9
+ var _definition = require("./crud/definition.tasks");
10
+ var _service = require("./crud/service.tasks");
11
+ var _crud = require("./crud/crud.tasks");
12
+ var _testingRunTask = require("./tasks/testingRunTask");
13
+ var _service2 = require("./service");
14
+ const createTasksCrud = () => {
15
+ const plugin = new _api.ContextPlugin(async context => {
16
+ context.tasks = {
17
+ ...(0, _definition.createDefinitionCrud)(context),
18
+ ...(0, _crud.createTaskCrud)(context),
19
+ ...(0, _service.createServiceCrud)(context)
20
+ };
21
+ });
22
+ plugin.name = "tasks.context";
23
+ return plugin;
24
+ };
25
+ const createTasksContext = () => {
26
+ return [...(0, _service2.createServicePlugins)(), ...(0, _model.createTaskModel)(), createTasksCrud()];
27
+ };
28
+ const createBackgroundTaskContext = () => {
29
+ return [(0, _testingRunTask.createTestingRunTask)(), ...createTasksContext()];
30
+ };
31
+ exports.createBackgroundTaskContext = createBackgroundTaskContext;
32
+
33
+ //# sourceMappingURL=context.js.map
package/context.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_api","require","_model","_definition","_service","_crud","_testingRunTask","_service2","createTasksCrud","plugin","ContextPlugin","context","tasks","createDefinitionCrud","createTaskCrud","createServiceCrud","name","createTasksContext","createServicePlugins","createTaskModel","createBackgroundTaskContext","createTestingRunTask","exports"],"sources":["context.ts"],"sourcesContent":["import type { Plugin } from \"@webiny/plugins\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport type { Context } from \"~/types\";\nimport { createTaskModel } from \"./crud/model\";\nimport { createDefinitionCrud } from \"./crud/definition.tasks\";\nimport { createServiceCrud } from \"~/crud/service.tasks\";\nimport { createTaskCrud } from \"./crud/crud.tasks\";\nimport { createTestingRunTask } from \"~/tasks/testingRunTask\";\nimport { createServicePlugins } from \"~/service\";\n\nconst createTasksCrud = () => {\n const plugin = new ContextPlugin<Context>(async context => {\n context.tasks = {\n ...createDefinitionCrud(context),\n ...createTaskCrud(context),\n ...createServiceCrud(context)\n };\n });\n\n plugin.name = \"tasks.context\";\n\n return plugin;\n};\n\nconst createTasksContext = (): Plugin[] => {\n return [...createServicePlugins(), ...createTaskModel(), createTasksCrud()];\n};\n\nexport const createBackgroundTaskContext = (): Plugin[] => {\n return [createTestingRunTask(), ...createTasksContext()];\n};\n"],"mappings":";;;;;;AACA,IAAAA,IAAA,GAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AACA,IAAAI,KAAA,GAAAJ,OAAA;AACA,IAAAK,eAAA,GAAAL,OAAA;AACA,IAAAM,SAAA,GAAAN,OAAA;AAEA,MAAMO,eAAe,GAAGA,CAAA,KAAM;EAC1B,MAAMC,MAAM,GAAG,IAAIC,kBAAa,CAAU,MAAMC,OAAO,IAAI;IACvDA,OAAO,CAACC,KAAK,GAAG;MACZ,GAAG,IAAAC,gCAAoB,EAACF,OAAO,CAAC;MAChC,GAAG,IAAAG,oBAAc,EAACH,OAAO,CAAC;MAC1B,GAAG,IAAAI,0BAAiB,EAACJ,OAAO;IAChC,CAAC;EACL,CAAC,CAAC;EAEFF,MAAM,CAACO,IAAI,GAAG,eAAe;EAE7B,OAAOP,MAAM;AACjB,CAAC;AAED,MAAMQ,kBAAkB,GAAGA,CAAA,KAAgB;EACvC,OAAO,CAAC,GAAG,IAAAC,8BAAoB,EAAC,CAAC,EAAE,GAAG,IAAAC,sBAAe,EAAC,CAAC,EAAEX,eAAe,CAAC,CAAC,CAAC;AAC/E,CAAC;AAEM,MAAMY,2BAA2B,GAAGA,CAAA,KAAgB;EACvD,OAAO,CAAC,IAAAC,oCAAoB,EAAC,CAAC,EAAE,GAAGJ,kBAAkB,CAAC,CAAC,CAAC;AAC5D,CAAC;AAACK,OAAA,CAAAF,2BAAA,GAAAA,2BAAA","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ import type { Context, ITasksContextCrudObject } from "../types";
2
+ export declare const createTaskCrud: (context: Context) => ITasksContextCrudObject;
@@ -0,0 +1,273 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.createTaskCrud = void 0;
8
+ var _error = _interopRequireDefault(require("@webiny/error"));
9
+ var _types = require("../types");
10
+ var _model = require("./model");
11
+ var _handlerGraphql = require("@webiny/handler-graphql");
12
+ var _pubsub = require("@webiny/pubsub");
13
+ var _where = require("./where");
14
+ var _utils = require("@webiny/utils");
15
+ var _zod = _interopRequireDefault(require("zod"));
16
+ const createRevisionId = id => {
17
+ const {
18
+ id: entryId
19
+ } = (0, _utils.parseIdentifier)(id);
20
+ return `${entryId}#0001`;
21
+ };
22
+ const convertToTask = entry => {
23
+ return {
24
+ id: entry.entryId,
25
+ createdOn: entry.createdOn,
26
+ savedOn: entry.savedOn,
27
+ createdBy: entry.createdBy,
28
+ name: entry.values.name,
29
+ definitionId: entry.values.definitionId,
30
+ input: entry.values.input,
31
+ output: entry.values.output,
32
+ taskStatus: entry.values.taskStatus,
33
+ executionName: entry.values.executionName || "",
34
+ eventResponse: entry.values.eventResponse,
35
+ startedOn: entry.values.startedOn,
36
+ finishedOn: entry.values.finishedOn,
37
+ iterations: entry.values.iterations,
38
+ parentId: entry.values.parentId
39
+ };
40
+ };
41
+ const convertToLog = entry => {
42
+ return {
43
+ id: entry.entryId,
44
+ createdOn: entry.createdOn,
45
+ createdBy: entry.createdBy,
46
+ executionName: entry.values.executionName,
47
+ task: entry.values.task,
48
+ iteration: entry.values.iteration,
49
+ items: entry.values.items || []
50
+ };
51
+ };
52
+ const getZodSchema = schema => {
53
+ if (!schema) {
54
+ return _zod.default.object({}).passthrough();
55
+ } else if (schema instanceof _zod.default.ZodObject) {
56
+ return schema.passthrough();
57
+ } else if (schema instanceof _zod.default.Schema) {
58
+ return schema;
59
+ }
60
+ return _zod.default.object(schema).passthrough();
61
+ };
62
+ const validateTaskInput = async params => {
63
+ const {
64
+ definition,
65
+ data,
66
+ context
67
+ } = params;
68
+ if (!definition.createInputValidation) {
69
+ return;
70
+ }
71
+ const schema = definition.createInputValidation({
72
+ context,
73
+ validator: _zod.default
74
+ });
75
+ /**
76
+ * If the schema is not an object, we need to wrap it with the `object` function.
77
+ */
78
+ const validate = getZodSchema(schema);
79
+ const result = await validate.safeParseAsync(data.input);
80
+ if (result.success) {
81
+ return;
82
+ }
83
+ throw (0, _utils.createZodError)(result.error);
84
+ };
85
+ const createTaskCrud = context => {
86
+ const onTaskBeforeCreate = (0, _pubsub.createTopic)("tasks.onBeforeCreate");
87
+ const onTaskAfterCreate = (0, _pubsub.createTopic)("tasks.onAfterCreate");
88
+ const onTaskBeforeUpdate = (0, _pubsub.createTopic)("tasks.onBeforeUpdate");
89
+ const onTaskAfterUpdate = (0, _pubsub.createTopic)("tasks.onAfterUpdate");
90
+ const onTaskBeforeDelete = (0, _pubsub.createTopic)("tasks.onBeforeDelete");
91
+ const onTaskAfterDelete = (0, _pubsub.createTopic)("tasks.onAfterDelete");
92
+ const getTaskModel = async () => {
93
+ return await context.security.withoutAuthorization(async () => {
94
+ const model = await context.cms.getModel(_model.WEBINY_TASK_MODEL_ID);
95
+ if (model) {
96
+ return model;
97
+ }
98
+ throw new _error.default(`There is no model "${_model.WEBINY_TASK_MODEL_ID}".`);
99
+ });
100
+ };
101
+ const getLogModel = async () => {
102
+ return await context.security.withoutAuthorization(async () => {
103
+ const model = await context.cms.getModel(_model.WEBINY_TASK_LOG_MODEL_ID);
104
+ if (model) {
105
+ return model;
106
+ }
107
+ throw new _error.default(`There is no model "${_model.WEBINY_TASK_LOG_MODEL_ID}".`);
108
+ });
109
+ };
110
+ const getTask = async id => {
111
+ let entry;
112
+ try {
113
+ entry = await context.security.withoutAuthorization(async () => {
114
+ const model = await getTaskModel();
115
+ return await context.cms.getEntryById(model, createRevisionId(id));
116
+ });
117
+ } catch (ex) {
118
+ if (ex instanceof _handlerGraphql.NotFoundError) {
119
+ return null;
120
+ }
121
+ throw ex;
122
+ }
123
+ if (!entry) {
124
+ return null;
125
+ }
126
+ return convertToTask(entry);
127
+ };
128
+ const listTasks = async params => {
129
+ const [items, meta] = await context.security.withoutAuthorization(async () => {
130
+ const model = await getTaskModel();
131
+ return await context.cms.listLatestEntries(model, {
132
+ ...params,
133
+ where: (0, _where.remapWhere)(params?.where)
134
+ });
135
+ });
136
+ return {
137
+ items: items.map(item => convertToTask(item)),
138
+ meta
139
+ };
140
+ };
141
+ const createTask = async data => {
142
+ const definition = context.tasks.getDefinition(data.definitionId);
143
+ if (!definition) {
144
+ throw new _error.default(`There is no task definition.`, "TASK_DEFINITION_ERROR", {
145
+ id: data.definitionId
146
+ });
147
+ }
148
+ await validateTaskInput({
149
+ context,
150
+ definition,
151
+ data
152
+ });
153
+ const entry = await context.security.withoutAuthorization(async () => {
154
+ const model = await getTaskModel();
155
+ return await context.cms.createEntry(model, {
156
+ ...data,
157
+ iterations: 0,
158
+ taskStatus: _types.TaskDataStatus.PENDING
159
+ });
160
+ });
161
+ return convertToTask(entry);
162
+ };
163
+ const updateTask = async (id, data) => {
164
+ const entry = await context.security.withoutAuthorization(async () => {
165
+ const model = await getTaskModel();
166
+ return await context.cms.updateEntry(model, createRevisionId(id), {
167
+ ...data,
168
+ savedOn: new Date().toISOString()
169
+ });
170
+ });
171
+ return convertToTask(entry);
172
+ };
173
+ const deleteTask = async id => {
174
+ return context.security.withoutAuthorization(async () => {
175
+ const model = await getTaskModel();
176
+ await context.cms.deleteEntry(model, createRevisionId(id));
177
+ return true;
178
+ });
179
+ };
180
+ const createLog = async (task, data) => {
181
+ const entry = await context.security.withoutAuthorization(async () => {
182
+ const model = await getLogModel();
183
+ return await context.cms.createEntry(model, {
184
+ ...data,
185
+ task: task.id
186
+ });
187
+ });
188
+ return convertToLog(entry);
189
+ };
190
+ const updateLog = async (id, data) => {
191
+ const entry = await context.security.withoutAuthorization(async () => {
192
+ const model = await getLogModel();
193
+ return await context.cms.updateEntry(model, createRevisionId(id), data);
194
+ });
195
+ return convertToLog(entry);
196
+ };
197
+ const deleteLog = async id => {
198
+ return context.security.withoutAuthorization(async () => {
199
+ const model = await getLogModel();
200
+ await context.cms.deleteEntry(model, id);
201
+ return true;
202
+ });
203
+ };
204
+ const getLog = async id => {
205
+ try {
206
+ const entry = await context.security.withoutAuthorization(async () => {
207
+ const model = await getLogModel();
208
+ return await context.cms.getEntryById(model, id);
209
+ });
210
+ return convertToLog(entry);
211
+ } catch (ex) {
212
+ if (ex instanceof _handlerGraphql.NotFoundError) {
213
+ return null;
214
+ }
215
+ throw ex;
216
+ }
217
+ };
218
+ const getLatestLog = async taskId => {
219
+ const entry = await context.security.withoutAuthorization(async () => {
220
+ const model = await getLogModel();
221
+ const [items] = await context.cms.listLatestEntries(model, {
222
+ where: {
223
+ task: taskId
224
+ },
225
+ sort: ["createdOn_DESC"],
226
+ limit: 1
227
+ });
228
+ const [item] = items;
229
+ if (!item) {
230
+ throw new _handlerGraphql.NotFoundError(`No existing latest log found for task "${taskId}".`);
231
+ }
232
+ return item;
233
+ });
234
+ return convertToLog(entry);
235
+ };
236
+ const listLogs = async params => {
237
+ const [items, meta] = await context.security.withoutAuthorization(async () => {
238
+ const model = await getLogModel();
239
+ return await context.cms.listLatestEntries(model, {
240
+ ...params,
241
+ where: (0, _where.remapWhere)(params.where)
242
+ });
243
+ });
244
+ return {
245
+ items: items.map(item => convertToLog(item)),
246
+ meta
247
+ };
248
+ };
249
+ return {
250
+ onTaskBeforeCreate,
251
+ onTaskAfterCreate,
252
+ onTaskBeforeUpdate,
253
+ onTaskAfterUpdate,
254
+ onTaskBeforeDelete,
255
+ onTaskAfterDelete,
256
+ getTask,
257
+ listTasks,
258
+ createTask,
259
+ updateTask,
260
+ deleteTask,
261
+ createLog,
262
+ updateLog,
263
+ deleteLog,
264
+ getLog,
265
+ listLogs,
266
+ getLatestLog,
267
+ getTaskModel,
268
+ getLogModel
269
+ };
270
+ };
271
+ exports.createTaskCrud = createTaskCrud;
272
+
273
+ //# sourceMappingURL=crud.tasks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_error","_interopRequireDefault","require","_types","_model","_handlerGraphql","_pubsub","_where","_utils","_zod","createRevisionId","id","entryId","parseIdentifier","convertToTask","entry","createdOn","savedOn","createdBy","name","values","definitionId","input","output","taskStatus","executionName","eventResponse","startedOn","finishedOn","iterations","parentId","convertToLog","task","iteration","items","getZodSchema","schema","zod","object","passthrough","ZodObject","Schema","validateTaskInput","params","definition","data","context","createInputValidation","validator","validate","result","safeParseAsync","success","createZodError","error","createTaskCrud","onTaskBeforeCreate","createTopic","onTaskAfterCreate","onTaskBeforeUpdate","onTaskAfterUpdate","onTaskBeforeDelete","onTaskAfterDelete","getTaskModel","security","withoutAuthorization","model","cms","getModel","WEBINY_TASK_MODEL_ID","WebinyError","getLogModel","WEBINY_TASK_LOG_MODEL_ID","getTask","getEntryById","ex","NotFoundError","listTasks","meta","listLatestEntries","where","remapWhere","map","item","createTask","tasks","getDefinition","createEntry","TaskDataStatus","PENDING","updateTask","updateEntry","Date","toISOString","deleteTask","deleteEntry","createLog","updateLog","deleteLog","getLog","getLatestLog","taskId","sort","limit","listLogs","exports"],"sources":["crud.tasks.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type {\n Context,\n IListTaskLogParams,\n IListTaskParams,\n ITask,\n ITaskCreateData,\n ITaskDataInput,\n ITaskDefinition,\n ITaskLog,\n ITaskLogCreateInput,\n ITaskLogUpdateInput,\n ITaskResponseDoneResultOutput,\n ITasksContextCrudObject,\n ITaskUpdateData,\n OnTaskAfterCreateTopicParams,\n OnTaskAfterDeleteTopicParams,\n OnTaskAfterUpdateTopicParams,\n OnTaskBeforeCreateTopicParams,\n OnTaskBeforeDeleteTopicParams,\n OnTaskBeforeUpdateTopicParams\n} from \"~/types\";\nimport { TaskDataStatus } from \"~/types\";\nimport { WEBINY_TASK_LOG_MODEL_ID, WEBINY_TASK_MODEL_ID } from \"./model\";\nimport type { CmsEntry, CmsModel } from \"@webiny/api-headless-cms/types\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport { createTopic } from \"@webiny/pubsub\";\nimport { remapWhere } from \"./where\";\nimport { createZodError, parseIdentifier } from \"@webiny/utils\";\nimport zod from \"zod\";\nimport type { GenericRecord } from \"@webiny/api/types\";\n\nconst createRevisionId = (id: string) => {\n const { id: entryId } = parseIdentifier(id);\n return `${entryId}#0001`;\n};\n\nconst convertToTask = <\n T = any,\n O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput\n>(\n entry: CmsEntry<ITask<T, O>>\n): ITask<T, O> => {\n return {\n id: entry.entryId,\n createdOn: entry.createdOn,\n savedOn: entry.savedOn,\n createdBy: entry.createdBy,\n name: entry.values.name,\n definitionId: entry.values.definitionId,\n input: entry.values.input,\n output: entry.values.output,\n taskStatus: entry.values.taskStatus,\n executionName: entry.values.executionName || \"\",\n eventResponse: entry.values.eventResponse,\n startedOn: entry.values.startedOn,\n finishedOn: entry.values.finishedOn,\n iterations: entry.values.iterations,\n parentId: entry.values.parentId\n };\n};\n\nconst convertToLog = (entry: CmsEntry<ITaskLog>): ITaskLog => {\n return {\n id: entry.entryId,\n createdOn: entry.createdOn,\n createdBy: entry.createdBy,\n executionName: entry.values.executionName,\n task: entry.values.task,\n iteration: entry.values.iteration,\n items: entry.values.items || []\n };\n};\n\ninterface IValidateParams {\n definition: Pick<ITaskDefinition, \"createInputValidation\">;\n data: Pick<ITaskCreateData, \"input\">;\n context: Context;\n}\n\nconst getZodSchema = (schema: GenericRecord<string, zod.Schema> | zod.Schema) => {\n if (!schema) {\n return zod.object({}).passthrough();\n } else if (schema instanceof zod.ZodObject) {\n return schema.passthrough();\n } else if (schema instanceof zod.Schema) {\n return schema;\n }\n return zod.object(schema).passthrough();\n};\n\nconst validateTaskInput = async (params: IValidateParams) => {\n const { definition, data, context } = params;\n if (!definition.createInputValidation) {\n return;\n }\n const schema = definition.createInputValidation({\n context,\n validator: zod\n });\n /**\n * If the schema is not an object, we need to wrap it with the `object` function.\n */\n const validate = getZodSchema(schema);\n\n const result = await validate.safeParseAsync(data.input);\n if (result.success) {\n return;\n }\n throw createZodError(result.error);\n};\n\nexport const createTaskCrud = (context: Context): ITasksContextCrudObject => {\n const onTaskBeforeCreate = createTopic<OnTaskBeforeCreateTopicParams>(\"tasks.onBeforeCreate\");\n const onTaskAfterCreate = createTopic<OnTaskAfterCreateTopicParams>(\"tasks.onAfterCreate\");\n const onTaskBeforeUpdate = createTopic<OnTaskBeforeUpdateTopicParams>(\"tasks.onBeforeUpdate\");\n const onTaskAfterUpdate = createTopic<OnTaskAfterUpdateTopicParams>(\"tasks.onAfterUpdate\");\n const onTaskBeforeDelete = createTopic<OnTaskBeforeDeleteTopicParams>(\"tasks.onBeforeDelete\");\n const onTaskAfterDelete = createTopic<OnTaskAfterDeleteTopicParams>(\"tasks.onAfterDelete\");\n\n const getTaskModel = async (): Promise<CmsModel> => {\n return await context.security.withoutAuthorization(async () => {\n const model = await context.cms.getModel(WEBINY_TASK_MODEL_ID);\n if (model) {\n return model;\n }\n throw new WebinyError(`There is no model \"${WEBINY_TASK_MODEL_ID}\".`);\n });\n };\n\n const getLogModel = async (): Promise<CmsModel> => {\n return await context.security.withoutAuthorization(async () => {\n const model = await context.cms.getModel(WEBINY_TASK_LOG_MODEL_ID);\n if (model) {\n return model;\n }\n throw new WebinyError(`There is no model \"${WEBINY_TASK_LOG_MODEL_ID}\".`);\n });\n };\n\n const getTask = async <\n T = any,\n O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput\n >(\n id: string\n ) => {\n let entry: CmsEntry;\n try {\n entry = await context.security.withoutAuthorization(async () => {\n const model = await getTaskModel();\n return await context.cms.getEntryById(model, createRevisionId(id));\n });\n } catch (ex) {\n if (ex instanceof NotFoundError) {\n return null;\n }\n throw ex;\n }\n\n if (!entry) {\n return null;\n }\n\n return convertToTask(entry as unknown as CmsEntry<ITask<T, O>>);\n };\n\n const listTasks = async <\n T = any,\n O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput\n >(\n params?: IListTaskParams\n ) => {\n const [items, meta] = await context.security.withoutAuthorization(async () => {\n const model = await getTaskModel();\n return await context.cms.listLatestEntries<ITask<T, O>>(model, {\n ...params,\n where: remapWhere(params?.where)\n });\n });\n\n return {\n items: items.map(item => convertToTask<T, O>(item)),\n meta\n };\n };\n\n const createTask = async (data: ITaskCreateData) => {\n const definition = context.tasks.getDefinition(data.definitionId);\n if (!definition) {\n throw new WebinyError(`There is no task definition.`, \"TASK_DEFINITION_ERROR\", {\n id: data.definitionId\n });\n }\n\n await validateTaskInput({\n context,\n definition,\n data\n });\n\n const entry = await context.security.withoutAuthorization(async () => {\n const model = await getTaskModel();\n return await context.cms.createEntry(model, {\n ...data,\n iterations: 0,\n taskStatus: TaskDataStatus.PENDING\n });\n });\n\n return convertToTask(entry as unknown as CmsEntry<ITask>);\n };\n\n const updateTask = async <\n T = ITaskDataInput,\n O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput\n >(\n id: string,\n data: ITaskUpdateData<T, O>\n ) => {\n const entry = await context.security.withoutAuthorization(async () => {\n const model = await getTaskModel();\n return await context.cms.updateEntry(model, createRevisionId(id), {\n ...data,\n savedOn: new Date().toISOString()\n });\n });\n return convertToTask<T, O>(entry as unknown as CmsEntry<ITask<T, O>>);\n };\n\n const deleteTask = async (id: string) => {\n return context.security.withoutAuthorization(async () => {\n const model = await getTaskModel();\n await context.cms.deleteEntry(model, createRevisionId(id));\n return true;\n });\n };\n\n const createLog = async (task: Pick<ITask, \"id\">, data: ITaskLogCreateInput) => {\n const entry = await context.security.withoutAuthorization(async () => {\n const model = await getLogModel();\n\n return await context.cms.createEntry(model, {\n ...data,\n task: task.id\n });\n });\n\n return convertToLog(entry as unknown as CmsEntry<ITaskLog>);\n };\n\n const updateLog = async (id: string, data: ITaskLogUpdateInput) => {\n const entry = await context.security.withoutAuthorization(async () => {\n const model = await getLogModel();\n\n return await context.cms.updateEntry(model, createRevisionId(id), data);\n });\n return convertToLog(entry as unknown as CmsEntry<ITaskLog>);\n };\n\n const deleteLog = async (id: string) => {\n return context.security.withoutAuthorization(async () => {\n const model = await getLogModel();\n await context.cms.deleteEntry(model, id);\n return true;\n });\n };\n\n const getLog = async (id: string): Promise<ITaskLog | null> => {\n try {\n const entry = await context.security.withoutAuthorization(async () => {\n const model = await getLogModel();\n return await context.cms.getEntryById(model, id);\n });\n\n return convertToLog(entry as unknown as CmsEntry<ITaskLog>);\n } catch (ex) {\n if (ex instanceof NotFoundError) {\n return null;\n }\n throw ex;\n }\n };\n\n const getLatestLog = async (taskId: string): Promise<ITaskLog> => {\n const entry = await context.security.withoutAuthorization(async () => {\n const model = await getLogModel();\n const [items] = await context.cms.listLatestEntries<ITaskLog>(model, {\n where: {\n task: taskId\n },\n sort: [\"createdOn_DESC\"],\n limit: 1\n });\n const [item] = items;\n if (!item) {\n throw new NotFoundError(`No existing latest log found for task \"${taskId}\".`);\n }\n return item;\n });\n\n return convertToLog(entry as unknown as CmsEntry<ITaskLog>);\n };\n\n const listLogs = async (params: IListTaskLogParams) => {\n const [items, meta] = await context.security.withoutAuthorization(async () => {\n const model = await getLogModel();\n return await context.cms.listLatestEntries<ITaskLog>(model, {\n ...params,\n where: remapWhere(params.where)\n });\n });\n\n return {\n items: items.map(item => convertToLog(item)),\n meta\n };\n };\n\n return {\n onTaskBeforeCreate,\n onTaskAfterCreate,\n onTaskBeforeUpdate,\n onTaskAfterUpdate,\n onTaskBeforeDelete,\n onTaskAfterDelete,\n getTask,\n listTasks,\n createTask,\n updateTask,\n deleteTask,\n createLog,\n updateLog,\n deleteLog,\n getLog,\n listLogs,\n getLatestLog,\n getTaskModel,\n getLogModel\n };\n};\n"],"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AAK,EAAE4C,IAAI,CAAC,GAAG,MAAMhC,OAAO,CAACkB,QAAQ,CAACC,oBAAoB,CAAC,YAAY;MAC1E,MAAMC,KAAK,GAAG,MAAMK,WAAW,CAAC,CAAC;MACjC,OAAO,MAAMzB,OAAO,CAACqB,GAAG,CAACY,iBAAiB,CAAWb,KAAK,EAAE;QACxD,GAAGvB,MAAM;QACTqC,KAAK,EAAE,IAAAC,iBAAU,EAACtC,MAAM,CAACqC,KAAK;MAClC,CAAC,CAAC;IACN,CAAC,CAAC;IAEF,OAAO;MACH9C,KAAK,EAAEA,KAAK,CAACgD,GAAG,CAACC,IAAI,IAAIpD,YAAY,CAACoD,IAAI,CAAC,CAAC;MAC5CL;IACJ,CAAC;EACL,CAAC;EAED,OAAO;IACHtB,kBAAkB;IAClBE,iBAAiB;IACjBC,kBAAkB;IAClBC,iBAAiB;IACjBC,kBAAkB;IAClBC,iBAAiB;IACjBW,OAAO;IACPI,SAAS;IACTO,UAAU;IACVM,UAAU;IACVI,UAAU;IACVE,SAAS;IACTC,SAAS;IACTC,SAAS;IACTC,MAAM;IACNK,QAAQ;IACRJ,YAAY;IACZrC,YAAY;IACZQ;EACJ,CAAC;AACL,CAAC;AAACkC,OAAA,CAAAlD,cAAA,GAAAA,cAAA","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ import type { Context, ITasksContextDefinitionObject } from "../types";
2
+ export declare const createDefinitionCrud: (context: Context) => ITasksContextDefinitionObject;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createDefinitionCrud = void 0;
7
+ var _task = require("../task");
8
+ const getTaskDefinitionPlugins = context => {
9
+ return context.plugins.byType(_task.TaskDefinitionPlugin.type);
10
+ };
11
+ const createDefinitionCrud = context => {
12
+ return {
13
+ getDefinition: id => {
14
+ const plugins = getTaskDefinitionPlugins(context);
15
+ for (const plugin of plugins) {
16
+ if (plugin.getTask().id === id) {
17
+ return plugin.getTask();
18
+ }
19
+ }
20
+ return null;
21
+ },
22
+ listDefinitions: () => {
23
+ return getTaskDefinitionPlugins(context).map(plugin => plugin.getTask());
24
+ }
25
+ };
26
+ };
27
+ exports.createDefinitionCrud = createDefinitionCrud;
28
+
29
+ //# sourceMappingURL=definition.tasks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_task","require","getTaskDefinitionPlugins","context","plugins","byType","TaskDefinitionPlugin","type","createDefinitionCrud","getDefinition","id","plugin","getTask","listDefinitions","map","exports"],"sources":["definition.tasks.ts"],"sourcesContent":["import type { Context, ITasksContextDefinitionObject } from \"~/types\";\nimport { TaskDefinitionPlugin } from \"~/task\";\n\nconst getTaskDefinitionPlugins = (context: Context) => {\n return context.plugins.byType<TaskDefinitionPlugin>(TaskDefinitionPlugin.type);\n};\n\nexport const createDefinitionCrud = (context: Context): ITasksContextDefinitionObject => {\n return {\n getDefinition: (id: string) => {\n const plugins = getTaskDefinitionPlugins(context);\n\n for (const plugin of plugins) {\n if (plugin.getTask().id === id) {\n return plugin.getTask();\n }\n }\n return null;\n },\n listDefinitions: () => {\n return getTaskDefinitionPlugins(context).map(plugin => plugin.getTask());\n }\n };\n};\n"],"mappings":";;;;;;AACA,IAAAA,KAAA,GAAAC,OAAA;AAEA,MAAMC,wBAAwB,GAAIC,OAAgB,IAAK;EACnD,OAAOA,OAAO,CAACC,OAAO,CAACC,MAAM,CAAuBC,0BAAoB,CAACC,IAAI,CAAC;AAClF,CAAC;AAEM,MAAMC,oBAAoB,GAAIL,OAAgB,IAAoC;EACrF,OAAO;IACHM,aAAa,EAAGC,EAAU,IAAK;MAC3B,MAAMN,OAAO,GAAGF,wBAAwB,CAACC,OAAO,CAAC;MAEjD,KAAK,MAAMQ,MAAM,IAAIP,OAAO,EAAE;QAC1B,IAAIO,MAAM,CAACC,OAAO,CAAC,CAAC,CAACF,EAAE,KAAKA,EAAE,EAAE;UAC5B,OAAOC,MAAM,CAACC,OAAO,CAAC,CAAC;QAC3B;MACJ;MACA,OAAO,IAAI;IACf,CAAC;IACDC,eAAe,EAAEA,CAAA,KAAM;MACnB,OAAOX,wBAAwB,CAACC,OAAO,CAAC,CAACW,GAAG,CAACH,MAAM,IAAIA,MAAM,CAACC,OAAO,CAAC,CAAC,CAAC;IAC5E;EACJ,CAAC;AACL,CAAC;AAACG,OAAA,CAAAP,oBAAA,GAAAA,oBAAA","ignoreList":[]}
@@ -0,0 +1,5 @@
1
+ export declare const WEBINY_TASK_MODEL_ID = "webinyTask";
2
+ export declare const WEBINY_TASK_LOG_MODEL_ID = "webinyTaskLog";
3
+ export declare const taskModel: import("@webiny/api-headless-cms").CmsModelPluginModel;
4
+ export declare const taskLogModel: import("@webiny/api-headless-cms").CmsModelPluginModel;
5
+ export declare const createTaskModel: () => import("@webiny/api-headless-cms").CmsModelPlugin[];
package/crud/model.js ADDED
@@ -0,0 +1,216 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.taskModel = exports.taskLogModel = exports.createTaskModel = exports.WEBINY_TASK_MODEL_ID = exports.WEBINY_TASK_LOG_MODEL_ID = void 0;
7
+ var _apiHeadlessCms = require("@webiny/api-headless-cms");
8
+ var _types = require("../types");
9
+ const WEBINY_TASK_MODEL_ID = exports.WEBINY_TASK_MODEL_ID = "webinyTask";
10
+ const WEBINY_TASK_LOG_MODEL_ID = exports.WEBINY_TASK_LOG_MODEL_ID = "webinyTaskLog";
11
+ const taskLogModelPlugin = (0, _apiHeadlessCms.createCmsModel)((0, _apiHeadlessCms.createPrivateModel)({
12
+ name: "Webiny Task Log",
13
+ modelId: WEBINY_TASK_LOG_MODEL_ID,
14
+ fields: [{
15
+ id: "executionName",
16
+ fieldId: "executionName",
17
+ storageId: "text@executionName",
18
+ type: "text",
19
+ label: "Execution Name"
20
+ }, {
21
+ id: "task",
22
+ fieldId: "task",
23
+ storageId: "text@task",
24
+ type: "text",
25
+ label: "Task",
26
+ validation: [{
27
+ name: "required",
28
+ message: "Task is required."
29
+ }]
30
+ }, {
31
+ id: "iteration",
32
+ fieldId: "iteration",
33
+ storageId: "number@iteration",
34
+ type: "number",
35
+ label: "Iteration",
36
+ validation: [{
37
+ name: "required",
38
+ message: "Iteration is required."
39
+ }]
40
+ }, {
41
+ id: "items",
42
+ fieldId: "items",
43
+ storageId: "object@items",
44
+ type: "object",
45
+ label: "Items",
46
+ multipleValues: true,
47
+ validation: [{
48
+ name: "required",
49
+ message: "Items is required."
50
+ }],
51
+ settings: {
52
+ fields: [{
53
+ id: "message",
54
+ fieldId: "message",
55
+ storageId: "text@message",
56
+ type: "text",
57
+ label: "Message",
58
+ validation: [{
59
+ name: "required",
60
+ message: "Message is required."
61
+ }]
62
+ }, {
63
+ id: "createdOn",
64
+ fieldId: "createdOn",
65
+ storageId: "datetime@createdOn",
66
+ type: "datetime",
67
+ label: "Created On",
68
+ validation: [{
69
+ name: "required",
70
+ message: "Created On is required."
71
+ }]
72
+ }, {
73
+ id: "type",
74
+ fieldId: "type",
75
+ storageId: "text@type",
76
+ type: "text",
77
+ label: "Type",
78
+ predefinedValues: {
79
+ enabled: true,
80
+ values: [{
81
+ value: _types.TaskLogItemType.INFO,
82
+ label: "Info"
83
+ }, {
84
+ value: _types.TaskLogItemType.ERROR,
85
+ label: "Error"
86
+ }]
87
+ },
88
+ validation: [{
89
+ name: "required",
90
+ message: "Type is required."
91
+ }]
92
+ }, {
93
+ id: "data",
94
+ fieldId: "data",
95
+ storageId: "object@data",
96
+ type: "json",
97
+ label: "Data"
98
+ }, {
99
+ id: "error",
100
+ fieldId: "error",
101
+ storageId: "object@error",
102
+ type: "json",
103
+ label: "Error"
104
+ }]
105
+ }
106
+ }]
107
+ }));
108
+ const taskModelPlugin = (0, _apiHeadlessCms.createCmsModel)((0, _apiHeadlessCms.createPrivateModel)({
109
+ name: "Webiny Task",
110
+ modelId: WEBINY_TASK_MODEL_ID,
111
+ fields: [{
112
+ id: "name",
113
+ fieldId: "name",
114
+ storageId: "text@name",
115
+ type: "text",
116
+ label: "Name",
117
+ validation: [{
118
+ name: "required",
119
+ message: "Name is required."
120
+ }]
121
+ }, {
122
+ id: "definitionId",
123
+ fieldId: "definitionId",
124
+ storageId: "text@definitionId",
125
+ type: "text",
126
+ label: "Definition ID",
127
+ validation: [{
128
+ name: "required",
129
+ message: "Definition ID is required."
130
+ }]
131
+ }, {
132
+ id: "parentId",
133
+ fieldId: "parentId",
134
+ storageId: "text@parentId",
135
+ type: "text",
136
+ label: "Parent ID"
137
+ }, {
138
+ id: "executionName",
139
+ fieldId: "executionName",
140
+ storageId: "text@executionName",
141
+ type: "text",
142
+ label: "Execution Name"
143
+ }, {
144
+ id: "iterations",
145
+ fieldId: "iterations",
146
+ storageId: "number@iterations",
147
+ type: "number",
148
+ label: "Iterations"
149
+ }, {
150
+ id: "input",
151
+ fieldId: "input",
152
+ storageId: "object@input",
153
+ type: "json",
154
+ label: "Input"
155
+ }, {
156
+ id: "output",
157
+ fieldId: "output",
158
+ storageId: "object@output",
159
+ type: "json",
160
+ label: "Output"
161
+ }, {
162
+ id: "taskStatus",
163
+ fieldId: "taskStatus",
164
+ storageId: "text@taskStatus",
165
+ type: "text",
166
+ label: "Status",
167
+ predefinedValues: {
168
+ enabled: true,
169
+ values: [{
170
+ value: _types.TaskDataStatus.PENDING,
171
+ label: "Pending"
172
+ }, {
173
+ value: _types.TaskDataStatus.RUNNING,
174
+ label: "Running"
175
+ }, {
176
+ value: _types.TaskDataStatus.FAILED,
177
+ label: "Failed"
178
+ }, {
179
+ value: _types.TaskDataStatus.SUCCESS,
180
+ label: "Success"
181
+ }, {
182
+ value: _types.TaskDataStatus.ABORTED,
183
+ label: "Aborted"
184
+ }]
185
+ },
186
+ settings: {
187
+ defaultValue: _types.TaskDataStatus.PENDING
188
+ }
189
+ }, {
190
+ id: "startedOn",
191
+ fieldId: "startedOn",
192
+ storageId: "datetime@startedOn",
193
+ type: "datetime",
194
+ label: "Started On"
195
+ }, {
196
+ id: "finishedOn",
197
+ fieldId: "finishedOn",
198
+ storageId: "datetime@finishedOn",
199
+ type: "datetime",
200
+ label: "Finished On"
201
+ }, {
202
+ id: "eventResponse",
203
+ fieldId: "eventResponse",
204
+ storageId: "object@eventResponse",
205
+ type: "json",
206
+ label: "Event Response"
207
+ }]
208
+ }));
209
+ const taskModel = exports.taskModel = taskModelPlugin.contentModel;
210
+ const taskLogModel = exports.taskLogModel = taskLogModelPlugin.contentModel;
211
+ const createTaskModel = () => {
212
+ return [taskModelPlugin, taskLogModelPlugin];
213
+ };
214
+ exports.createTaskModel = createTaskModel;
215
+
216
+ //# sourceMappingURL=model.js.map