@openeo/js-client 2.5.1 → 2.6.0

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/src/userfile.js CHANGED
@@ -1,128 +1,128 @@
1
- const Environment = require('./env');
2
- const BaseEntity = require('./baseentity');
3
-
4
- /**
5
- * A File on the user workspace.
6
- *
7
- * @augments BaseEntity
8
- */
9
- class UserFile extends BaseEntity {
10
-
11
- /**
12
- * Creates an object representing a file on the user workspace.
13
- *
14
- * @param {Connection} connection - A Connection object representing an established connection to an openEO back-end.
15
- * @param {string} path - The path to the file, relative to the user workspace and without user ID.
16
- */
17
- constructor(connection, path) {
18
- super(connection, ["path", "size", "modified"]);
19
- /**
20
- * Path to the file, relative to the user's directory.
21
- * @readonly
22
- * @public
23
- * @type {string}
24
- */
25
- this.path = path;
26
- /**
27
- * File size in bytes as integer.
28
- * @readonly
29
- * @public
30
- * @type {number}
31
- */
32
- this.size = undefined;
33
- /**
34
- * Date and time the file has lastly been modified, formatted as a RFC 3339 date-time.
35
- * @readonly
36
- * @public
37
- * @type {string}
38
- */
39
- this.modified = undefined;
40
- }
41
-
42
- /**
43
- * Downloads a file from the user workspace into memory.
44
- *
45
- * This method has different behaviour depending on the environment.
46
- * Returns a stream in a NodeJS environment or a Blob in a browser environment.
47
- *
48
- * @async
49
- * @returns {Promise<Stream.Readable|Blob>} - Return value depends on the target and environment, see method description for details.
50
- * @throws {Error}
51
- */
52
- async retrieveFile() {
53
- return await this.connection.download('/files/' + this.path, true);
54
- }
55
-
56
- /**
57
- * Downloads a file from the user workspace and saves it.
58
- *
59
- * This method has different behaviour depending on the environment.
60
- * In a NodeJS environment writes the downloaded file to the target location on the file system.
61
- * In a browser environment offers the file for downloading using the specified name (folders are not supported).
62
- *
63
- * @async
64
- * @param {string} target - The target, see method description for details.
65
- * @returns {Promise<Array.<string>|void>} - Return value depends on the target and environment, see method description for details.
66
- * @throws {Error}
67
- */
68
- async downloadFile(target) {
69
- let data = await this.connection.download('/files/' + this.path, true);
70
- // @ts-ignore
71
- return await Environment.saveToFile(data, target);
72
- }
73
-
74
- /**
75
- * A callback that is executed on upload progress updates.
76
- *
77
- * @callback uploadStatusCallback
78
- * @param {number} percentCompleted - The percent (0-100) completed.
79
- * @param {UserFile} file - The file object corresponding to the callback.
80
- */
81
-
82
- /**
83
- * Uploads a file to the user workspace.
84
- * If a file with the name exists, overwrites it.
85
- *
86
- * This method has different behaviour depending on the environment.
87
- * In a nodeJS environment the source must be a path to a file as string.
88
- * In a browser environment the source must be an object from a file upload form.
89
- *
90
- * @async
91
- * @param {*} source - The source, see method description for details.
92
- * @param {?uploadStatusCallback} statusCallback - Optionally, a callback that is executed on upload progress updates.
93
- * @param {?AbortController} [abortController=null] - An AbortController object that can be used to cancel the upload process.
94
- * @returns {Promise<UserFile>}
95
- * @throws {Error}
96
- */
97
- async uploadFile(source, statusCallback = null, abortController = null) {
98
- let options = {
99
- method: 'put',
100
- url: '/files/' + this.path,
101
- data: Environment.dataForUpload(source),
102
- headers: {
103
- 'Content-Type': 'application/octet-stream'
104
- }
105
- };
106
- if (typeof statusCallback === 'function') {
107
- options.onUploadProgress = (progressEvent) => {
108
- let percentCompleted = Math.round( (progressEvent.loaded * 100) / progressEvent.total );
109
- statusCallback(percentCompleted, this);
110
- };
111
- }
112
-
113
- let response = await this.connection._send(options, abortController);
114
- return this.setAll(response.data);
115
- }
116
-
117
- /**
118
- * Deletes the file from the user workspace.
119
- *
120
- * @async
121
- * @throws {Error}
122
- */
123
- async deleteFile() {
124
- await this.connection._delete('/files/' + this.path);
125
- }
126
- }
127
-
128
- module.exports = UserFile;
1
+ const Environment = require('./env');
2
+ const BaseEntity = require('./baseentity');
3
+
4
+ /**
5
+ * A File on the user workspace.
6
+ *
7
+ * @augments BaseEntity
8
+ */
9
+ class UserFile extends BaseEntity {
10
+
11
+ /**
12
+ * Creates an object representing a file on the user workspace.
13
+ *
14
+ * @param {Connection} connection - A Connection object representing an established connection to an openEO back-end.
15
+ * @param {string} path - The path to the file, relative to the user workspace and without user ID.
16
+ */
17
+ constructor(connection, path) {
18
+ super(connection, ["path", "size", "modified"]);
19
+ /**
20
+ * Path to the file, relative to the user's directory.
21
+ * @readonly
22
+ * @public
23
+ * @type {string}
24
+ */
25
+ this.path = path;
26
+ /**
27
+ * File size in bytes as integer.
28
+ * @readonly
29
+ * @public
30
+ * @type {number}
31
+ */
32
+ this.size = undefined;
33
+ /**
34
+ * Date and time the file has lastly been modified, formatted as a RFC 3339 date-time.
35
+ * @readonly
36
+ * @public
37
+ * @type {string}
38
+ */
39
+ this.modified = undefined;
40
+ }
41
+
42
+ /**
43
+ * Downloads a file from the user workspace into memory.
44
+ *
45
+ * This method has different behaviour depending on the environment.
46
+ * Returns a stream in a NodeJS environment or a Blob in a browser environment.
47
+ *
48
+ * @async
49
+ * @returns {Promise<Stream.Readable|Blob>} - Return value depends on the target and environment, see method description for details.
50
+ * @throws {Error}
51
+ */
52
+ async retrieveFile() {
53
+ return await this.connection.download('/files/' + this.path, true);
54
+ }
55
+
56
+ /**
57
+ * Downloads a file from the user workspace and saves it.
58
+ *
59
+ * This method has different behaviour depending on the environment.
60
+ * In a NodeJS environment writes the downloaded file to the target location on the file system.
61
+ * In a browser environment offers the file for downloading using the specified name (folders are not supported).
62
+ *
63
+ * @async
64
+ * @param {string} target - The target, see method description for details.
65
+ * @returns {Promise<Array.<string>|void>} - Return value depends on the target and environment, see method description for details.
66
+ * @throws {Error}
67
+ */
68
+ async downloadFile(target) {
69
+ let data = await this.connection.download('/files/' + this.path, true);
70
+ // @ts-ignore
71
+ return await Environment.saveToFile(data, target);
72
+ }
73
+
74
+ /**
75
+ * A callback that is executed on upload progress updates.
76
+ *
77
+ * @callback uploadStatusCallback
78
+ * @param {number} percentCompleted - The percent (0-100) completed.
79
+ * @param {UserFile} file - The file object corresponding to the callback.
80
+ */
81
+
82
+ /**
83
+ * Uploads a file to the user workspace.
84
+ * If a file with the name exists, overwrites it.
85
+ *
86
+ * This method has different behaviour depending on the environment.
87
+ * In a nodeJS environment the source must be a path to a file as string.
88
+ * In a browser environment the source must be an object from a file upload form.
89
+ *
90
+ * @async
91
+ * @param {*} source - The source, see method description for details.
92
+ * @param {?uploadStatusCallback} statusCallback - Optionally, a callback that is executed on upload progress updates.
93
+ * @param {?AbortController} [abortController=null] - An AbortController object that can be used to cancel the upload process.
94
+ * @returns {Promise<UserFile>}
95
+ * @throws {Error}
96
+ */
97
+ async uploadFile(source, statusCallback = null, abortController = null) {
98
+ let options = {
99
+ method: 'put',
100
+ url: '/files/' + this.path,
101
+ data: Environment.dataForUpload(source),
102
+ headers: {
103
+ 'Content-Type': 'application/octet-stream'
104
+ }
105
+ };
106
+ if (typeof statusCallback === 'function') {
107
+ options.onUploadProgress = (progressEvent) => {
108
+ let percentCompleted = Math.round( (progressEvent.loaded * 100) / progressEvent.total );
109
+ statusCallback(percentCompleted, this);
110
+ };
111
+ }
112
+
113
+ let response = await this.connection._send(options, abortController);
114
+ return this.setAll(response.data);
115
+ }
116
+
117
+ /**
118
+ * Deletes the file from the user workspace.
119
+ *
120
+ * @async
121
+ * @throws {Error}
122
+ */
123
+ async deleteFile() {
124
+ await this.connection._delete('/files/' + this.path);
125
+ }
126
+ }
127
+
128
+ module.exports = UserFile;
@@ -1,166 +1,166 @@
1
- const BaseEntity = require('./baseentity');
2
- const Utils = require('@openeo/js-commons/src/utils');
3
-
4
- /**
5
- * A Stored Process Graph.
6
- *
7
- * @augments BaseEntity
8
- */
9
- class UserProcess extends BaseEntity {
10
-
11
- /**
12
- * Creates an object representing a process graph stored at the back-end.
13
- *
14
- * @param {Connection} connection - A Connection object representing an established connection to an openEO back-end.
15
- * @param {string} id - ID of a stored process graph.
16
- */
17
- constructor(connection, id) {
18
- super(connection, [
19
- "id",
20
- "summary",
21
- "description",
22
- "categories",
23
- "parameters",
24
- "returns",
25
- "deprecated",
26
- "experimental",
27
- "exceptions",
28
- "examples",
29
- "links",
30
- ["process_graph", "processGraph"]
31
- ]);
32
- /**
33
- * The identifier of the process.
34
- * @public
35
- * @readonly
36
- * @type {string}
37
- */
38
- this.id = id;
39
- /**
40
- * @public
41
- * @readonly
42
- * @type {?string}
43
- */
44
- this.summary = undefined;
45
- /**
46
- * @public
47
- * @readonly
48
- * @type {?string}
49
- */
50
- this.description = undefined;
51
- /**
52
- * A list of categories.
53
- * @public
54
- * @readonly
55
- * @type {?Array.<string>}
56
- */
57
- this.categories = undefined;
58
- /**
59
- * A list of parameters.
60
- *
61
- * @public
62
- * @readonly
63
- * @type {?Array.<object.<string, *>>}
64
- */
65
- this.parameters = undefined;
66
- /**
67
- * Description of the data that is returned by this process.
68
- * @public
69
- * @readonly
70
- * @type {?object.<string, *>}
71
- */
72
- this.returns = undefined;
73
- /**
74
- * Specifies that the process or parameter is deprecated with the potential to be removed in any of the next versions.
75
- * @public
76
- * @readonly
77
- * @type {?boolean}
78
- */
79
- this.deprecated = undefined;
80
- /**
81
- * Declares the process or parameter to be experimental, which means that it is likely to change or may produce unpredictable behaviour.
82
- * @public
83
- * @readonly
84
- * @type {?boolean}
85
- */
86
- this.experimental = undefined;
87
- /**
88
- * Declares any exceptions (errors) that might occur during execution of this process.
89
- * @public
90
- * @readonly
91
- * @type {?object.<string, *>}
92
- */
93
- this.exceptions = undefined;
94
- /**
95
- * @public
96
- * @readonly
97
- * @type {?Array.<object.<string, *>>}
98
- */
99
- this.examples = undefined;
100
- /**
101
- * Links related to this process.
102
- * @public
103
- * @readonly
104
- * @type {?Array.<Link>}
105
- */
106
- this.links = undefined;
107
- /**
108
- * @public
109
- * @readonly
110
- * @type {?object.<string, *>}
111
- */
112
- this.processGraph = undefined;
113
- }
114
-
115
- /**
116
- * Updates the data stored in this object by requesting the process graph metadata from the back-end.
117
- *
118
- * @async
119
- * @returns {Promise<UserProcess>} The updated process graph object (this).
120
- * @throws {Error}
121
- */
122
- async describeUserProcess() {
123
- let response = await this.connection._get('/process_graphs/' + this.id);
124
- if (!Utils.isObject(response.data) || typeof response.data.id !== 'string') {
125
- throw new Error('Invalid response received for user process');
126
- }
127
- this.connection.processes.add(response.data, 'user');
128
- return this.setAll(response.data);
129
- }
130
-
131
- /**
132
- * Modifies the stored process graph at the back-end and afterwards updates this object, too.
133
- *
134
- * @async
135
- * @param {object} parameters - An object with properties to update, each of them is optional, but at least one of them must be specified. Additional properties can be set if the server supports them.
136
- * @param {Process} parameters.process - A new process.
137
- * @param {string} parameters.title - A new title.
138
- * @param {string} parameters.description - A new description.
139
- * @returns {Promise<UserProcess>} The updated process graph object (this).
140
- * @throws {Error}
141
- */
142
- async replaceUserProcess(parameters) {
143
- await this.connection._put('/process_graphs/' + this.id, this._convertToRequest(parameters));
144
- if (this._supports('describeUserProcess')) {
145
- return this.describeUserProcess();
146
- }
147
- else {
148
- let obj = this.setAll(parameters);
149
- this.connection.processes.add(obj.toJSON(), 'user');
150
- return obj;
151
- }
152
- }
153
-
154
- /**
155
- * Deletes the stored process graph from the back-end.
156
- *
157
- * @async
158
- * @throws {Error}
159
- */
160
- async deleteUserProcess() {
161
- await this.connection._delete('/process_graphs/' + this.id);
162
- this.connection.processes.remove(this.id, 'user');
163
- }
164
- }
165
-
166
- module.exports = UserProcess;
1
+ const BaseEntity = require('./baseentity');
2
+ const Utils = require('@openeo/js-commons/src/utils');
3
+
4
+ /**
5
+ * A Stored Process Graph.
6
+ *
7
+ * @augments BaseEntity
8
+ */
9
+ class UserProcess extends BaseEntity {
10
+
11
+ /**
12
+ * Creates an object representing a process graph stored at the back-end.
13
+ *
14
+ * @param {Connection} connection - A Connection object representing an established connection to an openEO back-end.
15
+ * @param {string} id - ID of a stored process graph.
16
+ */
17
+ constructor(connection, id) {
18
+ super(connection, [
19
+ "id",
20
+ "summary",
21
+ "description",
22
+ "categories",
23
+ "parameters",
24
+ "returns",
25
+ "deprecated",
26
+ "experimental",
27
+ "exceptions",
28
+ "examples",
29
+ "links",
30
+ ["process_graph", "processGraph"]
31
+ ]);
32
+ /**
33
+ * The identifier of the process.
34
+ * @public
35
+ * @readonly
36
+ * @type {string}
37
+ */
38
+ this.id = id;
39
+ /**
40
+ * @public
41
+ * @readonly
42
+ * @type {?string}
43
+ */
44
+ this.summary = undefined;
45
+ /**
46
+ * @public
47
+ * @readonly
48
+ * @type {?string}
49
+ */
50
+ this.description = undefined;
51
+ /**
52
+ * A list of categories.
53
+ * @public
54
+ * @readonly
55
+ * @type {?Array.<string>}
56
+ */
57
+ this.categories = undefined;
58
+ /**
59
+ * A list of parameters.
60
+ *
61
+ * @public
62
+ * @readonly
63
+ * @type {?Array.<object.<string, *>>}
64
+ */
65
+ this.parameters = undefined;
66
+ /**
67
+ * Description of the data that is returned by this process.
68
+ * @public
69
+ * @readonly
70
+ * @type {?object.<string, *>}
71
+ */
72
+ this.returns = undefined;
73
+ /**
74
+ * Specifies that the process or parameter is deprecated with the potential to be removed in any of the next versions.
75
+ * @public
76
+ * @readonly
77
+ * @type {?boolean}
78
+ */
79
+ this.deprecated = undefined;
80
+ /**
81
+ * Declares the process or parameter to be experimental, which means that it is likely to change or may produce unpredictable behaviour.
82
+ * @public
83
+ * @readonly
84
+ * @type {?boolean}
85
+ */
86
+ this.experimental = undefined;
87
+ /**
88
+ * Declares any exceptions (errors) that might occur during execution of this process.
89
+ * @public
90
+ * @readonly
91
+ * @type {?object.<string, *>}
92
+ */
93
+ this.exceptions = undefined;
94
+ /**
95
+ * @public
96
+ * @readonly
97
+ * @type {?Array.<object.<string, *>>}
98
+ */
99
+ this.examples = undefined;
100
+ /**
101
+ * Links related to this process.
102
+ * @public
103
+ * @readonly
104
+ * @type {?Array.<Link>}
105
+ */
106
+ this.links = undefined;
107
+ /**
108
+ * @public
109
+ * @readonly
110
+ * @type {?object.<string, *>}
111
+ */
112
+ this.processGraph = undefined;
113
+ }
114
+
115
+ /**
116
+ * Updates the data stored in this object by requesting the process graph metadata from the back-end.
117
+ *
118
+ * @async
119
+ * @returns {Promise<UserProcess>} The updated process graph object (this).
120
+ * @throws {Error}
121
+ */
122
+ async describeUserProcess() {
123
+ let response = await this.connection._get('/process_graphs/' + this.id);
124
+ if (!Utils.isObject(response.data) || typeof response.data.id !== 'string') {
125
+ throw new Error('Invalid response received for user process');
126
+ }
127
+ this.connection.processes.add(response.data, 'user');
128
+ return this.setAll(response.data);
129
+ }
130
+
131
+ /**
132
+ * Modifies the stored process graph at the back-end and afterwards updates this object, too.
133
+ *
134
+ * @async
135
+ * @param {object} parameters - An object with properties to update, each of them is optional, but at least one of them must be specified. Additional properties can be set if the server supports them.
136
+ * @param {Process} parameters.process - A new process.
137
+ * @param {string} parameters.title - A new title.
138
+ * @param {string} parameters.description - A new description.
139
+ * @returns {Promise<UserProcess>} The updated process graph object (this).
140
+ * @throws {Error}
141
+ */
142
+ async replaceUserProcess(parameters) {
143
+ await this.connection._put('/process_graphs/' + this.id, this._convertToRequest(parameters));
144
+ if (this._supports('describeUserProcess')) {
145
+ return this.describeUserProcess();
146
+ }
147
+ else {
148
+ let obj = this.setAll(parameters);
149
+ this.connection.processes.add(obj.toJSON(), 'user');
150
+ return obj;
151
+ }
152
+ }
153
+
154
+ /**
155
+ * Deletes the stored process graph from the back-end.
156
+ *
157
+ * @async
158
+ * @throws {Error}
159
+ */
160
+ async deleteUserProcess() {
161
+ await this.connection._delete('/process_graphs/' + this.id);
162
+ this.connection.processes.remove(this.id, 'user');
163
+ }
164
+ }
165
+
166
+ module.exports = UserProcess;