@twin.org/background-task-models 0.0.1-next.9 → 0.0.1

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.
@@ -1,4 +1,7 @@
1
1
  export * from "./factories/backgroundTaskConnectorFactory";
2
2
  export * from "./models/IBackgroundTask";
3
3
  export * from "./models/IBackgroundTaskConnector";
4
+ export * from "./models/IScheduledTaskInfo";
5
+ export * from "./models/IScheduledTaskTime";
6
+ export * from "./models/ITaskSchedulerComponent";
4
7
  export * from "./models/taskStatus";
@@ -1,7 +1,7 @@
1
1
  import type { IError } from "@twin.org/core";
2
2
  import type { TaskStatus } from "./taskStatus";
3
3
  /**
4
- * Interface describing a background task connector.
4
+ * Interface describing a background task.
5
5
  */
6
6
  export interface IBackgroundTask<T = any, U = any> {
7
7
  /**
@@ -0,0 +1,12 @@
1
+ import type { IScheduledTaskTime } from "./IScheduledTaskTime";
2
+ /**
3
+ * Interface describing a scheduled task information.
4
+ */
5
+ export interface IScheduledTaskInfo {
6
+ /**
7
+ * The information for the tasks.
8
+ */
9
+ tasks: {
10
+ [id: string]: IScheduledTaskTime[];
11
+ };
12
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Interface describing a scheduled task time.
3
+ */
4
+ export interface IScheduledTaskTime {
5
+ /**
6
+ * The date/time to start the task, if not provided defaults to first interval from now.
7
+ */
8
+ nextTriggerTime?: number;
9
+ /**
10
+ * The interval in days to repeat the task, if no intervals are set the task will not repeat.
11
+ */
12
+ intervalDays?: number;
13
+ /**
14
+ * The interval in hours to repeat the task, if no intervals are set the task will not repeat.
15
+ */
16
+ intervalHours?: number;
17
+ /**
18
+ * The interval in minutes to repeat the task, if no intervals are set the task will not repeat.
19
+ */
20
+ intervalMinutes?: number;
21
+ }
@@ -0,0 +1,27 @@
1
+ import type { IComponent } from "@twin.org/core";
2
+ import type { IScheduledTaskInfo } from "./IScheduledTaskInfo";
3
+ import type { IScheduledTaskTime } from "./IScheduledTaskTime";
4
+ /**
5
+ * Interface describing a task scheduler.
6
+ */
7
+ export interface ITaskSchedulerComponent extends IComponent {
8
+ /**
9
+ * Add a task to the scheduler.
10
+ * @param taskId The id of the task to add.
11
+ * @param times The times at which the task should be scheduled.
12
+ * @param taskCallback The callback to execute when the task is scheduled.
13
+ * @returns Nothing.
14
+ */
15
+ addTask(taskId: string, times: IScheduledTaskTime[], taskCallback: () => Promise<void>): Promise<void>;
16
+ /**
17
+ * Remove a task from the scheduler.
18
+ * @param taskId The id of the task to remove.
19
+ * @returns Nothing.
20
+ */
21
+ removeTask(taskId: string): Promise<void>;
22
+ /**
23
+ * Get the information about the tasks.
24
+ * @returns The tasks information.
25
+ */
26
+ tasksInfo(): Promise<IScheduledTaskInfo>;
27
+ }
package/docs/changelog.md CHANGED
@@ -1,5 +1,78 @@
1
1
  # @twin.org/background-task-models - Changelog
2
2
 
3
- ## v0.0.1-next.9
3
+ ## 0.0.1 (2025-07-07)
4
+
5
+
6
+ ### Features
7
+
8
+ * release to production ([7ce9896](https://github.com/twinfoundation/background-task/commit/7ce989659e6819f05655c86b1bda2a265af5d281))
9
+
10
+ ## [0.0.1-next.21](https://github.com/twinfoundation/background-task/compare/background-task-models-v0.0.1-next.20...background-task-models-v0.0.1-next.21) (2025-06-23)
11
+
12
+
13
+ ### Miscellaneous Chores
14
+
15
+ * **background-task-models:** Synchronize repo versions
16
+
17
+ ## [0.0.1-next.20](https://github.com/twinfoundation/background-task/compare/background-task-models-v0.0.1-next.19...background-task-models-v0.0.1-next.20) (2025-06-23)
18
+
19
+
20
+ ### Features
21
+
22
+ * add task scheduler ([754d973](https://github.com/twinfoundation/background-task/commit/754d973e7c8483e5e54e887c157661867d5a0375))
23
+ * improve comment ([f2b4ac2](https://github.com/twinfoundation/background-task/commit/f2b4ac22fb8f735d2bf4ce28583cf7c54acdf272))
24
+ * update dependencies ([8e65767](https://github.com/twinfoundation/background-task/commit/8e657679f5e4305dbcb15ac7bcb3ab8a4613a60b))
25
+ * use shared store mechanism ([#6](https://github.com/twinfoundation/background-task/issues/6)) ([27ed203](https://github.com/twinfoundation/background-task/commit/27ed20367d5ace7257bfa7a82b59ad70e5b5d209))
26
+
27
+ ## [0.0.1-next.19](https://github.com/twinfoundation/background-task/compare/background-task-models-v0.0.1-next.18...background-task-models-v0.0.1-next.19) (2025-06-23)
28
+
29
+
30
+ ### Features
31
+
32
+ * add task scheduler ([754d973](https://github.com/twinfoundation/background-task/commit/754d973e7c8483e5e54e887c157661867d5a0375))
33
+
34
+ ## [0.0.1-next.18](https://github.com/twinfoundation/background-task/compare/background-task-models-v0.0.1-next.17...background-task-models-v0.0.1-next.18) (2025-06-19)
35
+
36
+
37
+ ### Miscellaneous Chores
38
+
39
+ * **background-task-models:** Synchronize repo versions
40
+
41
+ ## [0.0.1-next.17](https://github.com/twinfoundation/background-task/compare/background-task-models-v0.0.1-next.16...background-task-models-v0.0.1-next.17) (2025-06-12)
42
+
43
+
44
+ ### Features
45
+
46
+ * update dependencies ([8e65767](https://github.com/twinfoundation/background-task/commit/8e657679f5e4305dbcb15ac7bcb3ab8a4613a60b))
47
+
48
+ ## [0.0.1-next.16](https://github.com/twinfoundation/background-task/compare/background-task-models-v0.0.1-next.15...background-task-models-v0.0.1-next.16) (2025-06-05)
49
+
50
+
51
+ ### Miscellaneous Chores
52
+
53
+ * **background-task-models:** Synchronize repo versions
54
+
55
+ ## [0.0.1-next.15](https://github.com/twinfoundation/background-task/compare/background-task-models-v0.0.1-next.14...background-task-models-v0.0.1-next.15) (2025-04-17)
56
+
57
+
58
+ ### Features
59
+
60
+ * use shared store mechanism ([#6](https://github.com/twinfoundation/background-task/issues/6)) ([27ed203](https://github.com/twinfoundation/background-task/commit/27ed20367d5ace7257bfa7a82b59ad70e5b5d209))
61
+
62
+ ## [0.0.1-next.14](https://github.com/twinfoundation/background-task/compare/background-task-models-v0.0.1-next.13...background-task-models-v0.0.1-next.14) (2025-04-11)
63
+
64
+
65
+ ### Miscellaneous Chores
66
+
67
+ * **background-task-models:** Synchronize repo versions
68
+
69
+ ## [0.0.1-next.13](https://github.com/twinfoundation/background-task/compare/background-task-models-v0.0.1-next.12...background-task-models-v0.0.1-next.13) (2025-03-28)
70
+
71
+
72
+ ### Features
73
+
74
+ * improve comment ([f2b4ac2](https://github.com/twinfoundation/background-task/commit/f2b4ac22fb8f735d2bf4ce28583cf7c54acdf272))
75
+
76
+ ## v0.0.1-next.12
4
77
 
5
78
  - Initial Release
@@ -4,6 +4,9 @@
4
4
 
5
5
  - [IBackgroundTask](interfaces/IBackgroundTask.md)
6
6
  - [IBackgroundTaskConnector](interfaces/IBackgroundTaskConnector.md)
7
+ - [IScheduledTaskInfo](interfaces/IScheduledTaskInfo.md)
8
+ - [IScheduledTaskTime](interfaces/IScheduledTaskTime.md)
9
+ - [ITaskSchedulerComponent](interfaces/ITaskSchedulerComponent.md)
7
10
 
8
11
  ## Type Aliases
9
12
 
@@ -1,12 +1,16 @@
1
1
  # Interface: IBackgroundTask\<T, U\>
2
2
 
3
- Interface describing a background task connector.
3
+ Interface describing a background task.
4
4
 
5
5
  ## Type Parameters
6
6
 
7
- **T** = `any`
7
+ ### T
8
8
 
9
- **U** = `any`
9
+ `T` = `any`
10
+
11
+ ### U
12
+
13
+ `U` = `any`
10
14
 
11
15
  ## Properties
12
16
 
@@ -10,15 +10,19 @@ Interface describing a background task connector.
10
10
 
11
11
  ### registerHandler()
12
12
 
13
- > **registerHandler**\<`T`, `U`\>(`taskType`, `module`, `method`, `stateChangeCallback`?): `Promise`\<`void`\>
13
+ > **registerHandler**\<`T`, `U`\>(`taskType`, `module`, `method`, `stateChangeCallback?`): `Promise`\<`void`\>
14
14
 
15
15
  Register a handler for a task.
16
16
 
17
17
  #### Type Parameters
18
18
 
19
- **T**
19
+ ##### T
20
20
 
21
- • **U**
21
+ `T`
22
+
23
+ ##### U
24
+
25
+ `U`
22
26
 
23
27
  #### Parameters
24
28
 
@@ -78,13 +82,15 @@ Nothing.
78
82
 
79
83
  ### create()
80
84
 
81
- > **create**\<`T`\>(`type`, `payload`?, `options`?): `Promise`\<`string`\>
85
+ > **create**\<`T`\>(`type`, `payload?`, `options?`): `Promise`\<`string`\>
82
86
 
83
87
  Create a new task.
84
88
 
85
89
  #### Type Parameters
86
90
 
87
- **T**
91
+ ##### T
92
+
93
+ `T`
88
94
 
89
95
  #### Parameters
90
96
 
@@ -104,19 +110,19 @@ The payload for the task.
104
110
 
105
111
  Additional options for the task.
106
112
 
107
- ###### retryCount
113
+ ###### retryCount?
108
114
 
109
115
  `number`
110
116
 
111
117
  The number of times to retry the task if it fails, leave undefined to retry forever.
112
118
 
113
- ###### retryInterval
119
+ ###### retryInterval?
114
120
 
115
121
  `number`
116
122
 
117
123
  The interval in milliseconds to wait between retries, defaults to 5000, leave undefined for default scheduling.
118
124
 
119
- ###### retainFor
125
+ ###### retainFor?
120
126
 
121
127
  `number`
122
128
 
@@ -138,9 +144,13 @@ Get the task details.
138
144
 
139
145
  #### Type Parameters
140
146
 
141
- **T**
147
+ ##### T
148
+
149
+ `T`
150
+
151
+ ##### U
142
152
 
143
- • **U**
153
+ `U`
144
154
 
145
155
  #### Parameters
146
156
 
@@ -226,7 +236,7 @@ Nothing.
226
236
 
227
237
  ### query()
228
238
 
229
- > **query**(`taskType`?, `taskStatus`?, `sortProperty`?, `sortDirection`?, `cursor`?, `pageSize`?): `Promise`\<\{ `entities`: [`IBackgroundTask`](IBackgroundTask.md)[]; `cursor`: `string`; \}\>
239
+ > **query**(`taskType?`, `taskStatus?`, `sortProperty?`, `sortDirection?`, `cursor?`, `pageSize?`): `Promise`\<\{ `entities`: [`IBackgroundTask`](IBackgroundTask.md)\<`any`, `any`\>[]; `cursor?`: `string`; \}\>
230
240
 
231
241
  Get a list of tasks.
232
242
 
@@ -248,7 +258,7 @@ The status of the task to get.
248
258
 
249
259
  The property to sort by, defaults to dateCreated.
250
260
 
251
- `"status"` | `"dateCreated"` | `"dateModified"` | `"dateCompleted"`
261
+ `"dateCreated"` | `"dateModified"` | `"dateCompleted"` | `"status"`
252
262
 
253
263
  ##### sortDirection?
254
264
 
@@ -270,6 +280,6 @@ The maximum number of entities in a page.
270
280
 
271
281
  #### Returns
272
282
 
273
- `Promise`\<\{ `entities`: [`IBackgroundTask`](IBackgroundTask.md)[]; `cursor`: `string`; \}\>
283
+ `Promise`\<\{ `entities`: [`IBackgroundTask`](IBackgroundTask.md)\<`any`, `any`\>[]; `cursor?`: `string`; \}\>
274
284
 
275
285
  The list of tasks.
@@ -0,0 +1,15 @@
1
+ # Interface: IScheduledTaskInfo
2
+
3
+ Interface describing a scheduled task information.
4
+
5
+ ## Properties
6
+
7
+ ### tasks
8
+
9
+ > **tasks**: `object`
10
+
11
+ The information for the tasks.
12
+
13
+ #### Index Signature
14
+
15
+ \[`id`: `string`\]: [`IScheduledTaskTime`](IScheduledTaskTime.md)[]
@@ -0,0 +1,35 @@
1
+ # Interface: IScheduledTaskTime
2
+
3
+ Interface describing a scheduled task time.
4
+
5
+ ## Properties
6
+
7
+ ### nextTriggerTime?
8
+
9
+ > `optional` **nextTriggerTime**: `number`
10
+
11
+ The date/time to start the task, if not provided defaults to first interval from now.
12
+
13
+ ***
14
+
15
+ ### intervalDays?
16
+
17
+ > `optional` **intervalDays**: `number`
18
+
19
+ The interval in days to repeat the task, if no intervals are set the task will not repeat.
20
+
21
+ ***
22
+
23
+ ### intervalHours?
24
+
25
+ > `optional` **intervalHours**: `number`
26
+
27
+ The interval in hours to repeat the task, if no intervals are set the task will not repeat.
28
+
29
+ ***
30
+
31
+ ### intervalMinutes?
32
+
33
+ > `optional` **intervalMinutes**: `number`
34
+
35
+ The interval in minutes to repeat the task, if no intervals are set the task will not repeat.
@@ -0,0 +1,77 @@
1
+ # Interface: ITaskSchedulerComponent
2
+
3
+ Interface describing a task scheduler.
4
+
5
+ ## Extends
6
+
7
+ - `IComponent`
8
+
9
+ ## Methods
10
+
11
+ ### addTask()
12
+
13
+ > **addTask**(`taskId`, `times`, `taskCallback`): `Promise`\<`void`\>
14
+
15
+ Add a task to the scheduler.
16
+
17
+ #### Parameters
18
+
19
+ ##### taskId
20
+
21
+ `string`
22
+
23
+ The id of the task to add.
24
+
25
+ ##### times
26
+
27
+ [`IScheduledTaskTime`](IScheduledTaskTime.md)[]
28
+
29
+ The times at which the task should be scheduled.
30
+
31
+ ##### taskCallback
32
+
33
+ () => `Promise`\<`void`\>
34
+
35
+ The callback to execute when the task is scheduled.
36
+
37
+ #### Returns
38
+
39
+ `Promise`\<`void`\>
40
+
41
+ Nothing.
42
+
43
+ ***
44
+
45
+ ### removeTask()
46
+
47
+ > **removeTask**(`taskId`): `Promise`\<`void`\>
48
+
49
+ Remove a task from the scheduler.
50
+
51
+ #### Parameters
52
+
53
+ ##### taskId
54
+
55
+ `string`
56
+
57
+ The id of the task to remove.
58
+
59
+ #### Returns
60
+
61
+ `Promise`\<`void`\>
62
+
63
+ Nothing.
64
+
65
+ ***
66
+
67
+ ### tasksInfo()
68
+
69
+ > **tasksInfo**(): `Promise`\<[`IScheduledTaskInfo`](IScheduledTaskInfo.md)\>
70
+
71
+ Get the information about the tasks.
72
+
73
+ #### Returns
74
+
75
+ `Promise`\<[`IScheduledTaskInfo`](IScheduledTaskInfo.md)\>
76
+
77
+ The tasks information.
@@ -1,5 +1,5 @@
1
1
  # Type Alias: TaskStatus
2
2
 
3
- > **TaskStatus**: *typeof* [`TaskStatus`](../variables/TaskStatus.md)\[keyof *typeof* [`TaskStatus`](../variables/TaskStatus.md)\]
3
+ > **TaskStatus** = *typeof* [`TaskStatus`](../variables/TaskStatus.md)\[keyof *typeof* [`TaskStatus`](../variables/TaskStatus.md)\]
4
4
 
5
5
  Task statuses.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/background-task-models",
3
- "version": "0.0.1-next.9",
3
+ "version": "0.0.1",
4
4
  "description": "Models which define the structure of the background task contracts and connectors",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,18 +14,18 @@
14
14
  "node": ">=20.0.0"
15
15
  },
16
16
  "dependencies": {
17
- "@twin.org/core": "next",
18
- "@twin.org/entity": "next",
19
- "@twin.org/nameof": "next"
17
+ "@twin.org/core": "^0.0.1",
18
+ "@twin.org/entity": "^0.0.1",
19
+ "@twin.org/nameof": "^0.0.1"
20
20
  },
21
21
  "main": "./dist/cjs/index.cjs",
22
22
  "module": "./dist/esm/index.mjs",
23
23
  "types": "./dist/types/index.d.ts",
24
24
  "exports": {
25
25
  ".": {
26
+ "types": "./dist/types/index.d.ts",
26
27
  "require": "./dist/cjs/index.cjs",
27
- "import": "./dist/esm/index.mjs",
28
- "types": "./dist/types/index.d.ts"
28
+ "import": "./dist/esm/index.mjs"
29
29
  },
30
30
  "./locales/*.json": "./locales/*.json"
31
31
  },