@openeo/js-client 2.5.0 → 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/service.js CHANGED
@@ -1,221 +1,222 @@
1
- const BaseEntity = require('./baseentity');
2
- const Logs = require('./logs');
3
-
4
- /**
5
- * A Secondary Web Service.
6
- *
7
- * @augments BaseEntity
8
- */
9
- class Service extends BaseEntity {
10
-
11
- /**
12
- * Creates an object representing a secondary web service 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} serviceId - The service ID.
16
- */
17
- constructor(connection, serviceId) {
18
- super(connection, ["id", "title", "description", "process", "url", "type", "enabled", "configuration", "attributes", "created", "plan", "costs", "budget"]);
19
- /**
20
- * The identifier of the service.
21
- * @public
22
- * @readonly
23
- * @type {string}
24
- */
25
- this.id = serviceId;
26
- /**
27
- * @public
28
- * @readonly
29
- * @type {?string}
30
- */
31
- this.title = undefined;
32
- /**
33
- * @public
34
- * @readonly
35
- * @type {?string}
36
- */
37
- this.description = undefined;
38
- /**
39
- * The process chain to be executed.
40
- * @public
41
- * @readonly
42
- * @type {?Process}
43
- */
44
- this.process = undefined;
45
- /**
46
- * URL at which the secondary web service is accessible
47
- * @public
48
- * @readonly
49
- * @type {?string}
50
- */
51
- this.url = undefined;
52
- /**
53
- * Web service type (protocol / standard) that is exposed.
54
- * @public
55
- * @readonly
56
- * @type {?string}
57
- */
58
- this.type = undefined;
59
- /**
60
- * @public
61
- * @readonly
62
- * @type {?boolean}
63
- */
64
- this.enabled = undefined;
65
- /**
66
- * Map of configuration settings, i.e. the setting names supported by the secondary web service combined with actual values.
67
- * @public
68
- * @readonly
69
- * @type {?object.<string, *>}
70
- */
71
- this.configuration = undefined;
72
- /**
73
- * Additional attributes of the secondary web service, e.g. available layers for a WMS based on the bands in the underlying GeoTiff.
74
- * @public
75
- * @readonly
76
- * @type {?object.<string, *>}
77
- */
78
- this.attributes = undefined;
79
- /**
80
- * Date and time of creation, formatted as a RFC 3339 date-time.
81
- * @public
82
- * @readonly
83
- * @type {?string}
84
- */
85
- this.created = undefined;
86
- /**
87
- * The billing plan to process and charge the service with.
88
- * @public
89
- * @readonly
90
- * @type {?string}
91
- */
92
- this.plan = undefined;
93
- /**
94
- * An amount of money or credits in the currency specified by the back-end.
95
- * @public
96
- * @readonly
97
- * @type {?number}
98
- */
99
- this.costs = undefined;
100
- /**
101
- * Maximum amount of costs the request is allowed to produce in the currency specified by the back-end.
102
- * @public
103
- * @readonly
104
- * @type {?number}
105
- */
106
- this.budget = undefined;
107
- }
108
-
109
- /**
110
- * Updates the data stored in this object by requesting the secondary web service metadata from the back-end.
111
- *
112
- * @async
113
- * @returns {Promise<Service>} The updates service object (this).
114
- * @throws {Error}
115
- */
116
- async describeService() {
117
- let response = await this.connection._get('/services/' + this.id);
118
- return this.setAll(response.data);
119
- }
120
-
121
- /**
122
- * Modifies the secondary web service at the back-end and afterwards updates this object, too.
123
- *
124
- * @async
125
- * @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.
126
- * @param {Process} parameters.process - A new process.
127
- * @param {string} parameters.title - A new title.
128
- * @param {string} parameters.description - A new description.
129
- * @param {boolean} parameters.enabled - Enables (`true`) or disables (`false`) the service.
130
- * @param {object.<string, *>} parameters.configuration - A new set of configuration parameters to set for the service.
131
- * @param {string} parameters.plan - A new plan.
132
- * @param {number} parameters.budget - A new budget.
133
- * @returns {Promise<Service>} The updated service object (this).
134
- * @throws {Error}
135
- */
136
- async updateService(parameters) {
137
- await this.connection._patch('/services/' + this.id, this._convertToRequest(parameters));
138
- if (this._supports('describeService')) {
139
- return await this.describeService();
140
- }
141
- else {
142
- return this.setAll(parameters);
143
- }
144
- }
145
-
146
- /**
147
- * Deletes the secondary web service from the back-end.
148
- *
149
- * @async
150
- * @throws {Error}
151
- */
152
- async deleteService() {
153
- await this.connection._delete('/services/' + this.id);
154
- }
155
-
156
- /**
157
- * Get logs for the secondary web service from the back-end.
158
- *
159
- * @returns {Logs}
160
- */
161
- debugService() {
162
- return new Logs(this.connection, '/services/' + this.id + '/logs');
163
- }
164
-
165
- /**
166
- * Checks for new log entries every x seconds.
167
- *
168
- * On every status change (enabled/disabled) observed or on new log entries
169
- * (if supported by the back-end and not disabled via `requestLogs`), the
170
- * callback is executed. It may also be executed once at the beginning.
171
- * The callback receives the updated service (this object) and the logs (array) passed.
172
- *
173
- * Returns a function that can be called to stop monitoring the service manually.
174
- * The monitoring must be stopped manually, otherwise it runs forever.
175
- *
176
- * This is only supported if describeService is supported by the back-end.
177
- *
178
- * @param {Function} callback
179
- * @param {number} [interval=60] - Interval between update requests, in seconds as integer.
180
- * @param {boolean} [requestLogs=true] - Enables/Disables requesting logs
181
- * @returns {Function}
182
- * @throws {Error}
183
- */
184
- monitorService(callback, interval = 60, requestLogs = true) {
185
- if (typeof callback !== 'function' || interval < 1) {
186
- return;
187
- }
188
- let capabilities = this.connection.capabilities();
189
- if (!capabilities.hasFeature('describeService')) {
190
- throw new Error('Monitoring Services not supported by the back-end.');
191
- }
192
-
193
- let wasEnabled = this.enabled;
194
- let intervalId = null;
195
- let logIterator = null;
196
- if (capabilities.hasFeature('debugService') && requestLogs) {
197
- logIterator = this.debugService();
198
- }
199
- let monitorFn = async () => {
200
- if (this.getDataAge() > 1) {
201
- await this.describeService();
202
- }
203
- let logs = logIterator ? await logIterator.nextLogs() : [];
204
- if (wasEnabled !== this.enabled || logs.length > 0) {
205
- callback(this, logs);
206
- }
207
- wasEnabled = this.enabled;
208
- };
209
- setTimeout(monitorFn, 0);
210
- intervalId = setInterval(monitorFn, interval * 1000);
211
- let stopFn = () => {
212
- if (intervalId) {
213
- clearInterval(intervalId);
214
- intervalId = null;
215
- }
216
- };
217
- return stopFn;
218
- }
219
- }
220
-
221
- module.exports = Service;
1
+ const BaseEntity = require('./baseentity');
2
+ const Logs = require('./logs');
3
+
4
+ /**
5
+ * A Secondary Web Service.
6
+ *
7
+ * @augments BaseEntity
8
+ */
9
+ class Service extends BaseEntity {
10
+
11
+ /**
12
+ * Creates an object representing a secondary web service 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} serviceId - The service ID.
16
+ */
17
+ constructor(connection, serviceId) {
18
+ super(connection, ["id", "title", "description", "process", "url", "type", "enabled", "configuration", "attributes", "created", "plan", "costs", "budget", "usage", ["log_level", "logLevel"], "links"]);
19
+ /**
20
+ * The identifier of the service.
21
+ * @public
22
+ * @readonly
23
+ * @type {string}
24
+ */
25
+ this.id = serviceId;
26
+ /**
27
+ * @public
28
+ * @readonly
29
+ * @type {?string}
30
+ */
31
+ this.title = undefined;
32
+ /**
33
+ * @public
34
+ * @readonly
35
+ * @type {?string}
36
+ */
37
+ this.description = undefined;
38
+ /**
39
+ * The process chain to be executed.
40
+ * @public
41
+ * @readonly
42
+ * @type {?Process}
43
+ */
44
+ this.process = undefined;
45
+ /**
46
+ * URL at which the secondary web service is accessible
47
+ * @public
48
+ * @readonly
49
+ * @type {?string}
50
+ */
51
+ this.url = undefined;
52
+ /**
53
+ * Web service type (protocol / standard) that is exposed.
54
+ * @public
55
+ * @readonly
56
+ * @type {?string}
57
+ */
58
+ this.type = undefined;
59
+ /**
60
+ * @public
61
+ * @readonly
62
+ * @type {?boolean}
63
+ */
64
+ this.enabled = undefined;
65
+ /**
66
+ * Map of configuration settings, i.e. the setting names supported by the secondary web service combined with actual values.
67
+ * @public
68
+ * @readonly
69
+ * @type {?object.<string, *>}
70
+ */
71
+ this.configuration = undefined;
72
+ /**
73
+ * Additional attributes of the secondary web service, e.g. available layers for a WMS based on the bands in the underlying GeoTiff.
74
+ * @public
75
+ * @readonly
76
+ * @type {?object.<string, *>}
77
+ */
78
+ this.attributes = undefined;
79
+ /**
80
+ * Date and time of creation, formatted as a RFC 3339 date-time.
81
+ * @public
82
+ * @readonly
83
+ * @type {?string}
84
+ */
85
+ this.created = undefined;
86
+ /**
87
+ * The billing plan to process and charge the service with.
88
+ * @public
89
+ * @readonly
90
+ * @type {?string}
91
+ */
92
+ this.plan = undefined;
93
+ /**
94
+ * An amount of money or credits in the currency specified by the back-end.
95
+ * @public
96
+ * @readonly
97
+ * @type {?number}
98
+ */
99
+ this.costs = undefined;
100
+ /**
101
+ * Maximum amount of costs the request is allowed to produce in the currency specified by the back-end.
102
+ * @public
103
+ * @readonly
104
+ * @type {?number}
105
+ */
106
+ this.budget = undefined;
107
+ }
108
+
109
+ /**
110
+ * Updates the data stored in this object by requesting the secondary web service metadata from the back-end.
111
+ *
112
+ * @async
113
+ * @returns {Promise<Service>} The updates service object (this).
114
+ * @throws {Error}
115
+ */
116
+ async describeService() {
117
+ let response = await this.connection._get('/services/' + this.id);
118
+ return this.setAll(response.data);
119
+ }
120
+
121
+ /**
122
+ * Modifies the secondary web service at the back-end and afterwards updates this object, too.
123
+ *
124
+ * @async
125
+ * @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.
126
+ * @param {Process} parameters.process - A new process.
127
+ * @param {string} parameters.title - A new title.
128
+ * @param {string} parameters.description - A new description.
129
+ * @param {boolean} parameters.enabled - Enables (`true`) or disables (`false`) the service.
130
+ * @param {object.<string, *>} parameters.configuration - A new set of configuration parameters to set for the service.
131
+ * @param {string} parameters.plan - A new plan.
132
+ * @param {number} parameters.budget - A new budget.
133
+ * @returns {Promise<Service>} The updated service object (this).
134
+ * @throws {Error}
135
+ */
136
+ async updateService(parameters) {
137
+ await this.connection._patch('/services/' + this.id, this._convertToRequest(parameters));
138
+ if (this._supports('describeService')) {
139
+ return await this.describeService();
140
+ }
141
+ else {
142
+ return this.setAll(parameters);
143
+ }
144
+ }
145
+
146
+ /**
147
+ * Deletes the secondary web service from the back-end.
148
+ *
149
+ * @async
150
+ * @throws {Error}
151
+ */
152
+ async deleteService() {
153
+ await this.connection._delete('/services/' + this.id);
154
+ }
155
+
156
+ /**
157
+ * Get logs for the secondary web service from the back-end.
158
+ *
159
+ * @param {?string} [level=null] - Minimum level of logs to return.
160
+ * @returns {Logs}
161
+ */
162
+ debugService(level = null) {
163
+ return new Logs(this.connection, '/services/' + this.id + '/logs', level);
164
+ }
165
+
166
+ /**
167
+ * Checks for new log entries every x seconds.
168
+ *
169
+ * On every status change (enabled/disabled) observed or on new log entries
170
+ * (if supported by the back-end and not disabled via `requestLogs`), the
171
+ * callback is executed. It may also be executed once at the beginning.
172
+ * The callback receives the updated service (this object) and the logs (array) passed.
173
+ *
174
+ * Returns a function that can be called to stop monitoring the service manually.
175
+ * The monitoring must be stopped manually, otherwise it runs forever.
176
+ *
177
+ * This is only supported if describeService is supported by the back-end.
178
+ *
179
+ * @param {Function} callback
180
+ * @param {number} [interval=60] - Interval between update requests, in seconds as integer.
181
+ * @param {boolean} [requestLogs=true] - Enables/Disables requesting logs
182
+ * @returns {Function}
183
+ * @throws {Error}
184
+ */
185
+ monitorService(callback, interval = 60, requestLogs = true) {
186
+ if (typeof callback !== 'function' || interval < 1) {
187
+ return;
188
+ }
189
+ let capabilities = this.connection.capabilities();
190
+ if (!capabilities.hasFeature('describeService')) {
191
+ throw new Error('Monitoring Services not supported by the back-end.');
192
+ }
193
+
194
+ let wasEnabled = this.enabled;
195
+ let intervalId = null;
196
+ let logIterator = null;
197
+ if (capabilities.hasFeature('debugService') && requestLogs) {
198
+ logIterator = this.debugService();
199
+ }
200
+ let monitorFn = async () => {
201
+ if (this.getDataAge() > 1) {
202
+ await this.describeService();
203
+ }
204
+ let logs = logIterator ? await logIterator.nextLogs() : [];
205
+ if (wasEnabled !== this.enabled || logs.length > 0) {
206
+ callback(this, logs);
207
+ }
208
+ wasEnabled = this.enabled;
209
+ };
210
+ setTimeout(monitorFn, 0);
211
+ intervalId = setInterval(monitorFn, interval * 1000);
212
+ let stopFn = () => {
213
+ if (intervalId) {
214
+ clearInterval(intervalId);
215
+ intervalId = null;
216
+ }
217
+ };
218
+ return stopFn;
219
+ }
220
+ }
221
+
222
+ module.exports = Service;