@enonic-types/lib-task 0.1.1 → 7.11.0-B3
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 +4 -4
- package/package.json +35 -32
- package/task.d.ts +183 -181
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm i --save-dev @enonic/lib-task
|
|
8
|
+
npm i --save-dev @enonic-types/lib-task
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
## Use
|
|
@@ -26,8 +26,8 @@ Add the corresponding types to your `tsconfig.json` file that is used for applic
|
|
|
26
26
|
|
|
27
27
|
### Require and custom imports
|
|
28
28
|
|
|
29
|
-
To make `require` work out of box, you must install and add the `@enonic-types/global` types. Aside from providing definitions for XP
|
|
30
|
-
objects, e.g. `log`, `app`, `__`, etc, requiring library by the default path will return typed object.
|
|
29
|
+
To make `require` work out of the box, you must install and add the `@enonic-types/global` types. Aside from providing definitions for XP
|
|
30
|
+
global objects, e.g. `log`, `app`, `__`, etc, requiring a library by the default path will return typed object.
|
|
31
31
|
|
|
32
32
|
`tsconfig.json`
|
|
33
33
|
|
|
@@ -49,7 +49,7 @@ const {submit, executeFunction, submitNamed, submitTask, list, get, sleep, progr
|
|
|
49
49
|
```
|
|
50
50
|
|
|
51
51
|
More detailed explanation on how it works and how to type custom import function can be
|
|
52
|
-
found [here](https://
|
|
52
|
+
found [here](https://developer.enonic.com/docs/xp/stable/api).
|
|
53
53
|
|
|
54
54
|
### ES6-style import
|
|
55
55
|
|
package/package.json
CHANGED
|
@@ -1,32 +1,35 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@enonic-types/lib-task",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Type definitions for lib-task.",
|
|
5
|
-
"types": "task.d.ts",
|
|
6
|
-
"files": [
|
|
7
|
-
"task.d.ts"
|
|
8
|
-
],
|
|
9
|
-
"repository": {
|
|
10
|
-
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/enonic/xp.git#master"
|
|
12
|
-
},
|
|
13
|
-
"keywords": [
|
|
14
|
-
"enonic",
|
|
15
|
-
"enonic-xp",
|
|
16
|
-
"lib-task",
|
|
17
|
-
"task",
|
|
18
|
-
"types",
|
|
19
|
-
"typescript"
|
|
20
|
-
],
|
|
21
|
-
"contributors": [
|
|
22
|
-
"Mikita Taukachou <edloidas@gmail.com> (https://edloidas.github.io/)"
|
|
23
|
-
],
|
|
24
|
-
"license": "Apache-2.0",
|
|
25
|
-
"bugs": {
|
|
26
|
-
"url": "https://github.com/enonic/xp/issues"
|
|
27
|
-
},
|
|
28
|
-
"homepage": "https://github.com/enonic/xp/tree/master#readme",
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
}
|
|
32
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@enonic-types/lib-task",
|
|
3
|
+
"version": "7.11.0-B3",
|
|
4
|
+
"description": "Type definitions for lib-task.",
|
|
5
|
+
"types": "task.d.ts",
|
|
6
|
+
"files": [
|
|
7
|
+
"task.d.ts"
|
|
8
|
+
],
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/enonic/xp.git#master"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"enonic",
|
|
15
|
+
"enonic-xp",
|
|
16
|
+
"lib-task",
|
|
17
|
+
"task",
|
|
18
|
+
"types",
|
|
19
|
+
"typescript"
|
|
20
|
+
],
|
|
21
|
+
"contributors": [
|
|
22
|
+
"Mikita Taukachou <edloidas@gmail.com> (https://edloidas.github.io/)"
|
|
23
|
+
],
|
|
24
|
+
"license": "Apache-2.0",
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/enonic/xp/issues"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://github.com/enonic/xp/tree/master#readme",
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@enonic-types/core": "7.11.0-B3"
|
|
31
|
+
},
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
}
|
|
35
|
+
}
|
package/task.d.ts
CHANGED
|
@@ -1,181 +1,183 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Functions for execution of asynchronous tasks.
|
|
3
|
-
*
|
|
4
|
-
* @example
|
|
5
|
-
* var taskLib = require('/lib/xp/task');
|
|
6
|
-
*
|
|
7
|
-
* @module task
|
|
8
|
-
*/
|
|
9
|
-
declare global {
|
|
10
|
-
interface XpLibraries {
|
|
11
|
-
'/lib/xp/task': typeof import('./task');
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
* @
|
|
27
|
-
* @
|
|
28
|
-
* @property {string}
|
|
29
|
-
* @property {string}
|
|
30
|
-
* @property {string}
|
|
31
|
-
* @property {string}
|
|
32
|
-
* @property {string}
|
|
33
|
-
* @property {
|
|
34
|
-
* @property {
|
|
35
|
-
* @property {
|
|
36
|
-
* @property {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
*
|
|
42
|
-
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* @
|
|
48
|
-
*
|
|
49
|
-
* @param {
|
|
50
|
-
*
|
|
51
|
-
* @
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* @
|
|
62
|
-
*
|
|
63
|
-
* @param {
|
|
64
|
-
*
|
|
65
|
-
* @
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
* @
|
|
82
|
-
*
|
|
83
|
-
* @param {object}
|
|
84
|
-
*
|
|
85
|
-
* @
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
* @
|
|
100
|
-
*
|
|
101
|
-
* @param {object}
|
|
102
|
-
*
|
|
103
|
-
* @
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
export
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
* @
|
|
132
|
-
*
|
|
133
|
-
* @param {object} [params
|
|
134
|
-
* @
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
* @
|
|
143
|
-
*
|
|
144
|
-
* @
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
* @
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
* @
|
|
167
|
-
*
|
|
168
|
-
* @param {
|
|
169
|
-
* @param {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
* @
|
|
178
|
-
*
|
|
179
|
-
* @
|
|
180
|
-
|
|
181
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Functions for execution of asynchronous tasks.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* var taskLib = require('/lib/xp/task');
|
|
6
|
+
*
|
|
7
|
+
* @module task
|
|
8
|
+
*/
|
|
9
|
+
declare global {
|
|
10
|
+
interface XpLibraries {
|
|
11
|
+
'/lib/xp/task': typeof import('./task');
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
import type { UserKey } from '@enonic-types/core';
|
|
15
|
+
export type { UserKey } from '@enonic-types/core';
|
|
16
|
+
export declare type CallbackFn = () => void;
|
|
17
|
+
export interface SubmitParams {
|
|
18
|
+
description: string;
|
|
19
|
+
task: CallbackFn;
|
|
20
|
+
}
|
|
21
|
+
export interface ExecuteFunctionParams {
|
|
22
|
+
description: string;
|
|
23
|
+
func: CallbackFn;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* @typedef TaskInfo
|
|
27
|
+
* @type Object
|
|
28
|
+
* @property {string} id Task ID.
|
|
29
|
+
* @property {string} name Task name.
|
|
30
|
+
* @property {string} description Task description.
|
|
31
|
+
* @property {string} state Task state. Possible values: 'WAITING' | 'RUNNING' | 'FINISHED' | 'FAILED'
|
|
32
|
+
* @property {string} application Application containing the callback function to run.
|
|
33
|
+
* @property {string} user Key of the user that submitted the task.
|
|
34
|
+
* @property {string} startTime Time when the task was submitted (in ISO-8601 format).
|
|
35
|
+
* @property {object} progress Progress information provided by the running task.
|
|
36
|
+
* @property {number} progress.current Latest progress current numeric value.
|
|
37
|
+
* @property {number} progress.total Latest progress target numeric value.
|
|
38
|
+
* @property {string} progress.info Latest progress textual information.
|
|
39
|
+
*/
|
|
40
|
+
/**
|
|
41
|
+
* @deprecated Please use {@link executeFunction}.
|
|
42
|
+
|
|
43
|
+
* Submits a task to be executed in the background and returns an id representing the task.
|
|
44
|
+
*
|
|
45
|
+
* This function returns immediately. The callback function will be executed asynchronously.
|
|
46
|
+
*
|
|
47
|
+
* @example-ref examples/task/submit.js
|
|
48
|
+
*
|
|
49
|
+
* @param {object} params JSON with the parameters.
|
|
50
|
+
* @param {string} params.description Text describing the task to be executed.
|
|
51
|
+
* @param {function} params.task Callback function to be executed asynchronously.
|
|
52
|
+
*
|
|
53
|
+
* @returns {string} Id of the task that will be executed.
|
|
54
|
+
*/
|
|
55
|
+
export declare function submit(params: SubmitParams): string;
|
|
56
|
+
/**
|
|
57
|
+
* Runs a task function in the background and returns an id representing the task.
|
|
58
|
+
*
|
|
59
|
+
* This function returns immediately. The callback function will be executed asynchronously.
|
|
60
|
+
*
|
|
61
|
+
* @example-ref examples/task/executeFunction.js
|
|
62
|
+
*
|
|
63
|
+
* @param {object} params JSON with the parameters.
|
|
64
|
+
* @param {string} params.description Text describing the task to be executed.
|
|
65
|
+
* @param {function} params.func Callback function to be executed asynchronously.
|
|
66
|
+
*
|
|
67
|
+
* @returns {string} Id of the task that will be executed.
|
|
68
|
+
*/
|
|
69
|
+
export declare function executeFunction(params: ExecuteFunctionParams): string;
|
|
70
|
+
export interface SubmitNamedTaskParams<Config extends object = Record<string, unknown>> {
|
|
71
|
+
name: string;
|
|
72
|
+
config?: Config;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* @deprecated Please use {@link submitTask}.
|
|
76
|
+
*
|
|
77
|
+
* Submits a named task to be executed in the background and returns an id representing the task.
|
|
78
|
+
*
|
|
79
|
+
* This function returns immediately. The callback function will be executed asynchronously.
|
|
80
|
+
*
|
|
81
|
+
* @example-ref examples/task/submitNamed.js
|
|
82
|
+
*
|
|
83
|
+
* @param {object} params JSON with the parameters.
|
|
84
|
+
* @param {string} params.name Name of the task to execute.
|
|
85
|
+
* @param {object} [params.config] Configuration parameters to pass to the task to be executed.
|
|
86
|
+
* The object must be valid according to the schema defined in the form of the task descriptor XML.
|
|
87
|
+
* @returns {string} Id of the task that will be executed.
|
|
88
|
+
*/
|
|
89
|
+
export declare function submitNamed<Config extends object = Record<string, unknown>>(params: SubmitNamedTaskParams<Config>): string;
|
|
90
|
+
export interface SubmitTaskParams<Config extends object = Record<string, unknown>> {
|
|
91
|
+
descriptor: string;
|
|
92
|
+
config?: Config;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Submits a task to be executed in the background and returns an id representing the task.
|
|
96
|
+
*
|
|
97
|
+
* This function returns immediately. The callback function will be executed asynchronously.
|
|
98
|
+
*
|
|
99
|
+
* @example-ref examples/task/submitTask.js
|
|
100
|
+
*
|
|
101
|
+
* @param {object} params JSON with the parameters.
|
|
102
|
+
* @param {string} params.descriptor Descriptor of the task to execute.
|
|
103
|
+
* @param {object} [params.config] Configuration parameters to pass to the task to be executed.
|
|
104
|
+
* The object must be valid according to the schema defined in the form of the task descriptor XML.
|
|
105
|
+
* @returns {string} Id of the task that will be executed.
|
|
106
|
+
*/
|
|
107
|
+
export declare function submitTask<Config extends object = Record<string, unknown>>(params: SubmitTaskParams<Config>): string;
|
|
108
|
+
export declare type TaskStateType = 'WAITING' | 'RUNNING' | 'FINISHED' | 'FAILED';
|
|
109
|
+
export interface ListTasksParams {
|
|
110
|
+
name?: string | null;
|
|
111
|
+
state?: TaskStateType | null;
|
|
112
|
+
}
|
|
113
|
+
export interface TaskProgress {
|
|
114
|
+
info: string;
|
|
115
|
+
current: number;
|
|
116
|
+
total: number;
|
|
117
|
+
}
|
|
118
|
+
export interface TaskInfo {
|
|
119
|
+
description: string;
|
|
120
|
+
id: string;
|
|
121
|
+
name: string;
|
|
122
|
+
state: TaskStateType;
|
|
123
|
+
application: string;
|
|
124
|
+
user: UserKey;
|
|
125
|
+
startTime: string;
|
|
126
|
+
progress: TaskProgress;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Returns the list of active tasks with their current state and progress details.
|
|
130
|
+
*
|
|
131
|
+
* @example-ref examples/task/list.js
|
|
132
|
+
*
|
|
133
|
+
* @param {object} [params] JSON with optional parameters.
|
|
134
|
+
* @param {string} [params.name] Filter by name.
|
|
135
|
+
* @param {object} [params.state] Filter by task state ('WAITING' | 'RUNNING' | 'FINISHED' | 'FAILED').
|
|
136
|
+
* @returns {TaskInfo[]} List with task information for every task.
|
|
137
|
+
*/
|
|
138
|
+
export declare function list(params: ListTasksParams): TaskInfo[];
|
|
139
|
+
/**
|
|
140
|
+
* Returns the current state and progress details for the specified task.
|
|
141
|
+
*
|
|
142
|
+
* @example-ref examples/task/get.js
|
|
143
|
+
*
|
|
144
|
+
* @param {string} taskId Id of the task.
|
|
145
|
+
*
|
|
146
|
+
* @returns {TaskInfo} Detail information for the task. Or null if the task could not be found.
|
|
147
|
+
*/
|
|
148
|
+
export declare function get(taskId: string): TaskInfo | null;
|
|
149
|
+
/**
|
|
150
|
+
* Causes the current execution thread to sleep (temporarily cease execution) for the specified number of milliseconds.
|
|
151
|
+
*
|
|
152
|
+
* @example-ref examples/task/sleep.js
|
|
153
|
+
*
|
|
154
|
+
* @param {number} timeMillis The length of time to sleep in milliseconds.
|
|
155
|
+
*/
|
|
156
|
+
export declare function sleep(timeMillis: number): void;
|
|
157
|
+
export interface TaskProgressParams {
|
|
158
|
+
current?: number | null;
|
|
159
|
+
total?: number | null;
|
|
160
|
+
info?: string | null;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Reports progress information from an executing task.
|
|
164
|
+
* This function may only be called within the context of a task function, otherwise it will fail and throw an exception.
|
|
165
|
+
*
|
|
166
|
+
* @example-ref examples/task/progress.js
|
|
167
|
+
*
|
|
168
|
+
* @param {object} params JSON with progress details.
|
|
169
|
+
* @param {number} [params.current] Integer value representing the number of items that have been processed in the task.
|
|
170
|
+
* @param {number} [params.total] Integer value representing the total number of items to process in the task.
|
|
171
|
+
* @param {string} [params.info] Text describing the current progress for the task.
|
|
172
|
+
*/
|
|
173
|
+
export declare function progress(params: TaskProgressParams): void;
|
|
174
|
+
/**
|
|
175
|
+
* Checks if any task with the given name or id is currently running.
|
|
176
|
+
*
|
|
177
|
+
* @example-ref examples/task/isRunning.js
|
|
178
|
+
*
|
|
179
|
+
* @param {string} task Name or id of the task.
|
|
180
|
+
*
|
|
181
|
+
* @returns {boolean} True if there is a task with the specified name or id, and state 'RUNNING'; False otherwise.
|
|
182
|
+
*/
|
|
183
|
+
export declare function isRunning(task: string): boolean;
|