geoserver-node-client 1.6.0 → 1.6.2

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/dist/src/layer.js CHANGED
@@ -1,14 +1,10 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports["default"] = void 0;
8
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
10
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
7
+ exports.default = void 0;
12
8
  var _nodeFetch = _interopRequireDefault(require("node-fetch"));
13
9
  var _geoserver = require("./util/geoserver.js");
14
10
  var _about = _interopRequireDefault(require("./about.js"));
@@ -17,15 +13,14 @@ var _about = _interopRequireDefault(require("./about.js"));
17
13
  *
18
14
  * @module LayerClient
19
15
  */
20
- var LayerClient = exports["default"] = /*#__PURE__*/function () {
16
+ class LayerClient {
21
17
  /**
22
18
  * Creates a GeoServer REST LayerClient instance.
23
19
  *
24
20
  * @param {String} url The URL of the GeoServer REST API endpoint
25
21
  * @param {String} auth The Basic Authentication string
26
22
  */
27
- function LayerClient(url, auth) {
28
- (0, _classCallCheck2["default"])(this, LayerClient);
23
+ constructor(url, auth) {
29
24
  this.url = url;
30
25
  this.auth = auth;
31
26
  }
@@ -41,1301 +36,737 @@ var LayerClient = exports["default"] = /*#__PURE__*/function () {
41
36
  *
42
37
  * @returns {Object} An object with layer information or undefined if it cannot be found
43
38
  */
44
- return (0, _createClass2["default"])(LayerClient, [{
45
- key: "get",
46
- value: (function () {
47
- var _get = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee(workspace, layerName) {
48
- var qualifiedName, response, grc, geoServerResponse;
49
- return _regenerator["default"].wrap(function (_context) {
50
- while (1) switch (_context.prev = _context.next) {
51
- case 0:
52
- if (workspace) {
53
- qualifiedName = "".concat(workspace, ":").concat(layerName);
54
- } else {
55
- qualifiedName = layerName;
56
- }
57
- _context.next = 1;
58
- return (0, _nodeFetch["default"])(this.url + 'layers/' + qualifiedName + '.json', {
59
- credentials: 'include',
60
- method: 'GET',
61
- headers: {
62
- Authorization: this.auth
63
- }
64
- });
65
- case 1:
66
- response = _context.sent;
67
- if (response.ok) {
68
- _context.next = 5;
69
- break;
70
- }
71
- grc = new _about["default"](this.url, this.auth);
72
- _context.next = 2;
73
- return grc.exists();
74
- case 2:
75
- if (!_context.sent) {
76
- _context.next = 3;
77
- break;
78
- }
79
- return _context.abrupt("return");
80
- case 3:
81
- _context.next = 4;
82
- return (0, _geoserver.getGeoServerResponseText)(response);
83
- case 4:
84
- geoServerResponse = _context.sent;
85
- throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
86
- case 5:
87
- return _context.abrupt("return", response.json());
88
- case 6:
89
- case "end":
90
- return _context.stop();
91
- }
92
- }, _callee, this);
93
- }));
94
- function get(_x, _x2) {
95
- return _get.apply(this, arguments);
39
+ async get(workspace, layerName) {
40
+ let qualifiedName;
41
+ if (workspace) {
42
+ qualifiedName = `${workspace}:${layerName}`;
43
+ } else {
44
+ qualifiedName = layerName;
45
+ }
46
+ const response = await (0, _nodeFetch.default)(this.url + 'layers/' + qualifiedName + '.json', {
47
+ credentials: 'include',
48
+ method: 'GET',
49
+ headers: {
50
+ Authorization: this.auth
96
51
  }
97
- return get;
98
- }()
99
- /**
100
- * Sets the attribution text and link of a layer.
101
- *
102
- * @param {String} workspace The name of the workspace, can be undefined
103
- * @param {String} layerName The name of the layer to query
104
- * @param {String} [attributionText] The attribution text
105
- * @param {String} [attributionLink] The attribution link
106
- *
107
- * @throws Error if request fails
108
- */
109
- )
110
- }, {
111
- key: "modifyAttribution",
112
- value: (function () {
113
- var _modifyAttribution = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee2(workspace, layerName, attributionText, attributionLink) {
114
- var qualifiedName, jsonBody, url, response, geoServerResponse;
115
- return _regenerator["default"].wrap(function (_context2) {
116
- while (1) switch (_context2.prev = _context2.next) {
117
- case 0:
118
- if (workspace) {
119
- qualifiedName = "".concat(workspace, ":").concat(layerName);
120
- } else {
121
- qualifiedName = layerName;
122
- }
123
- // take existing layer properties as template
124
- _context2.next = 1;
125
- return this.get(workspace, layerName);
126
- case 1:
127
- jsonBody = _context2.sent;
128
- if (!(!jsonBody || !jsonBody.layer || !jsonBody.layer.attribution)) {
129
- _context2.next = 2;
130
- break;
131
- }
132
- throw new _geoserver.GeoServerResponseError("layer '".concat(workspace, ":").concat(layerName, "' misses the property 'attribution'"));
133
- case 2:
134
- // set attribution text and link
135
- if (attributionText) {
136
- jsonBody.layer.attribution.title = attributionText;
137
- }
138
- if (attributionLink) {
139
- jsonBody.layer.attribution.href = attributionLink;
140
- }
141
- url = this.url + 'layers/' + qualifiedName + '.json';
142
- _context2.next = 3;
143
- return (0, _nodeFetch["default"])(url, {
144
- credentials: 'include',
145
- method: 'PUT',
146
- headers: {
147
- Authorization: this.auth,
148
- 'Content-Type': 'application/json'
149
- },
150
- body: JSON.stringify(jsonBody)
151
- });
152
- case 3:
153
- response = _context2.sent;
154
- if (response.ok) {
155
- _context2.next = 5;
156
- break;
157
- }
158
- _context2.next = 4;
159
- return (0, _geoserver.getGeoServerResponseText)(response);
160
- case 4:
161
- geoServerResponse = _context2.sent;
162
- throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
163
- case 5:
164
- case "end":
165
- return _context2.stop();
166
- }
167
- }, _callee2, this);
168
- }));
169
- function modifyAttribution(_x3, _x4, _x5, _x6) {
170
- return _modifyAttribution.apply(this, arguments);
52
+ });
53
+ if (!response.ok) {
54
+ const grc = new _about.default(this.url, this.auth);
55
+ if (await grc.exists()) {
56
+ // GeoServer exists, but requested item does not exist, we return empty
57
+ return;
58
+ } else {
59
+ // There was a general problem with GeoServer
60
+ const geoServerResponse = await (0, _geoserver.getGeoServerResponseText)(response);
61
+ throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
171
62
  }
172
- return modifyAttribution;
173
- }()
174
- /**
175
- * Returns all layers in the GeoServer.
176
- *
177
- * @throws Error if request fails
178
- *
179
- * @returns {Object} An object with all layer information
180
- */
181
- )
182
- }, {
183
- key: "getAll",
184
- value: (function () {
185
- var _getAll = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee3() {
186
- var response, geoServerResponse;
187
- return _regenerator["default"].wrap(function (_context3) {
188
- while (1) switch (_context3.prev = _context3.next) {
189
- case 0:
190
- _context3.next = 1;
191
- return (0, _nodeFetch["default"])(this.url + 'layers.json', {
192
- credentials: 'include',
193
- method: 'GET',
194
- headers: {
195
- Authorization: this.auth
196
- }
197
- });
198
- case 1:
199
- response = _context3.sent;
200
- if (response.ok) {
201
- _context3.next = 3;
202
- break;
203
- }
204
- _context3.next = 2;
205
- return (0, _geoserver.getGeoServerResponseText)(response);
206
- case 2:
207
- geoServerResponse = _context3.sent;
208
- throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
209
- case 3:
210
- return _context3.abrupt("return", response.json());
211
- case 4:
212
- case "end":
213
- return _context3.stop();
214
- }
215
- }, _callee3, this);
216
- }));
217
- function getAll() {
218
- return _getAll.apply(this, arguments);
63
+ }
64
+ return response.json();
65
+ }
66
+
67
+ /**
68
+ * Sets the attribution text and link of a layer.
69
+ *
70
+ * @param {String} workspace The name of the workspace, can be undefined
71
+ * @param {String} layerName The name of the layer to query
72
+ * @param {String} [attributionText] The attribution text
73
+ * @param {String} [attributionLink] The attribution link
74
+ *
75
+ * @throws Error if request fails
76
+ */
77
+ async modifyAttribution(workspace, layerName, attributionText, attributionLink) {
78
+ let qualifiedName;
79
+ if (workspace) {
80
+ qualifiedName = `${workspace}:${layerName}`;
81
+ } else {
82
+ qualifiedName = layerName;
83
+ }
84
+ // take existing layer properties as template
85
+ const jsonBody = await this.get(workspace, layerName);
86
+ if (!jsonBody || !jsonBody.layer || !jsonBody.layer.attribution) {
87
+ throw new _geoserver.GeoServerResponseError(`layer '${workspace}:${layerName}' misses the property 'attribution'`);
88
+ }
89
+
90
+ // set attribution text and link
91
+ if (attributionText) {
92
+ jsonBody.layer.attribution.title = attributionText;
93
+ }
94
+ if (attributionLink) {
95
+ jsonBody.layer.attribution.href = attributionLink;
96
+ }
97
+ const url = this.url + 'layers/' + qualifiedName + '.json';
98
+ const response = await (0, _nodeFetch.default)(url, {
99
+ credentials: 'include',
100
+ method: 'PUT',
101
+ headers: {
102
+ Authorization: this.auth,
103
+ 'Content-Type': 'application/json'
104
+ },
105
+ body: JSON.stringify(jsonBody)
106
+ });
107
+ if (!response.ok) {
108
+ const geoServerResponse = await (0, _geoserver.getGeoServerResponseText)(response);
109
+ throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
110
+ }
111
+ }
112
+
113
+ /**
114
+ * Returns all layers in the GeoServer.
115
+ *
116
+ * @throws Error if request fails
117
+ *
118
+ * @returns {Object} An object with all layer information
119
+ */
120
+ async getAll() {
121
+ const response = await (0, _nodeFetch.default)(this.url + 'layers.json', {
122
+ credentials: 'include',
123
+ method: 'GET',
124
+ headers: {
125
+ Authorization: this.auth
219
126
  }
220
- return getAll;
221
- }()
222
- /**
223
- * Get all layers of a workspace.
224
- *
225
- * @param {String} workspace The workspace
226
- *
227
- * @throws Error if request fails
228
- *
229
- * @return {Object} An object with the information about the layers
230
- */
231
- )
232
- }, {
233
- key: "getLayers",
234
- value: (function () {
235
- var _getLayers = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee4(workspace) {
236
- var response, geoServerResponse;
237
- return _regenerator["default"].wrap(function (_context4) {
238
- while (1) switch (_context4.prev = _context4.next) {
239
- case 0:
240
- _context4.next = 1;
241
- return (0, _nodeFetch["default"])(this.url + 'workspaces/' + workspace + '/layers.json', {
242
- credentials: 'include',
243
- method: 'GET',
244
- headers: {
245
- Authorization: this.auth
246
- }
247
- });
248
- case 1:
249
- response = _context4.sent;
250
- if (response.ok) {
251
- _context4.next = 3;
252
- break;
253
- }
254
- _context4.next = 2;
255
- return (0, _geoserver.getGeoServerResponseText)(response);
256
- case 2:
257
- geoServerResponse = _context4.sent;
258
- throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
259
- case 3:
260
- _context4.next = 4;
261
- return response.json();
262
- case 4:
263
- return _context4.abrupt("return", _context4.sent);
264
- case 5:
265
- case "end":
266
- return _context4.stop();
267
- }
268
- }, _callee4, this);
269
- }));
270
- function getLayers(_x7) {
271
- return _getLayers.apply(this, arguments);
127
+ });
128
+ if (!response.ok) {
129
+ const geoServerResponse = await (0, _geoserver.getGeoServerResponseText)(response);
130
+ throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
131
+ }
132
+ return response.json();
133
+ }
134
+
135
+ /**
136
+ * Get all layers of a workspace.
137
+ *
138
+ * @param {String} workspace The workspace
139
+ *
140
+ * @throws Error if request fails
141
+ *
142
+ * @return {Object} An object with the information about the layers
143
+ */
144
+ async getLayers(workspace) {
145
+ const response = await (0, _nodeFetch.default)(this.url + 'workspaces/' + workspace + '/layers.json', {
146
+ credentials: 'include',
147
+ method: 'GET',
148
+ headers: {
149
+ Authorization: this.auth
272
150
  }
273
- return getLayers;
274
- }()
275
- /**
276
- * Returns information about a cascaded WMS layer.
277
- *
278
- * @param {String} workspace The workspace
279
- * @param {String} datastore The datastore
280
- * @param {String} layerName The WMS layer name
281
- *
282
- * @throws Error if request fails
283
- *
284
- * @returns {Object} An object with layer information or undefined if it cannot be found
285
- */
286
- )
287
- }, {
288
- key: "getWmsLayer",
289
- value: (function () {
290
- var _getWmsLayer = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee5(workspace, datastore, layerName) {
291
- var response, grc, geoServerResponse;
292
- return _regenerator["default"].wrap(function (_context5) {
293
- while (1) switch (_context5.prev = _context5.next) {
294
- case 0:
295
- _context5.next = 1;
296
- return (0, _nodeFetch["default"])(this.url + 'workspaces/' + workspace + '/wmsstores/' + datastore + '/wmslayers/' + layerName + '.json', {
297
- credentials: 'include',
298
- method: 'GET',
299
- headers: {
300
- Authorization: this.auth
301
- }
302
- });
303
- case 1:
304
- response = _context5.sent;
305
- if (response.ok) {
306
- _context5.next = 5;
307
- break;
308
- }
309
- grc = new _about["default"](this.url, this.auth);
310
- _context5.next = 2;
311
- return grc.exists();
312
- case 2:
313
- if (!_context5.sent) {
314
- _context5.next = 3;
315
- break;
316
- }
317
- return _context5.abrupt("return");
318
- case 3:
319
- _context5.next = 4;
320
- return (0, _geoserver.getGeoServerResponseText)(response);
321
- case 4:
322
- geoServerResponse = _context5.sent;
323
- throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
324
- case 5:
325
- _context5.next = 6;
326
- return response.json();
327
- case 6:
328
- return _context5.abrupt("return", _context5.sent);
329
- case 7:
330
- case "end":
331
- return _context5.stop();
332
- }
333
- }, _callee5, this);
334
- }));
335
- function getWmsLayer(_x8, _x9, _x0) {
336
- return _getWmsLayer.apply(this, arguments);
151
+ });
152
+ if (!response.ok) {
153
+ const geoServerResponse = await (0, _geoserver.getGeoServerResponseText)(response);
154
+ throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
155
+ }
156
+ return await response.json();
157
+ }
158
+
159
+ /**
160
+ * Returns information about a cascaded WMS layer.
161
+ *
162
+ * @param {String} workspace The workspace
163
+ * @param {String} datastore The datastore
164
+ * @param {String} layerName The WMS layer name
165
+ *
166
+ * @throws Error if request fails
167
+ *
168
+ * @returns {Object} An object with layer information or undefined if it cannot be found
169
+ */
170
+ async getWmsLayer(workspace, datastore, layerName) {
171
+ const response = await (0, _nodeFetch.default)(this.url + 'workspaces/' + workspace + '/wmsstores/' + datastore + '/wmslayers/' + layerName + '.json', {
172
+ credentials: 'include',
173
+ method: 'GET',
174
+ headers: {
175
+ Authorization: this.auth
176
+ }
177
+ });
178
+ if (!response.ok) {
179
+ const grc = new _about.default(this.url, this.auth);
180
+ if (await grc.exists()) {
181
+ // GeoServer exists, but requested item does not exist, we return empty
182
+ return;
183
+ } else {
184
+ // There was a general problem with GeoServer
185
+ const geoServerResponse = await (0, _geoserver.getGeoServerResponseText)(response);
186
+ throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
337
187
  }
338
- return getWmsLayer;
339
- }() // TODO: automated test needed
340
- /**
341
- * Returns information about a cascaded WMTS layer.
342
- *
343
- * @param {String} workspace The workspace
344
- * @param {String} datastore The datastore
345
- * @param {String} layerName The WMTS layer name
346
- *
347
- * @throws Error if request fails
348
- *
349
- * @returns {Object} An object with layer information or undefined if it cannot be found
350
- */
351
- )
352
- }, {
353
- key: "getWmtsLayer",
354
- value: function () {
355
- var _getWmtsLayer = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee6(workspace, datastore, layerName) {
356
- var response, grc, geoServerResponse;
357
- return _regenerator["default"].wrap(function (_context6) {
358
- while (1) switch (_context6.prev = _context6.next) {
359
- case 0:
360
- _context6.next = 1;
361
- return (0, _nodeFetch["default"])(this.url + 'workspaces/' + workspace + '/wmtsstores/' + datastore + '/layers/' + layerName + '.json', {
362
- credentials: 'include',
363
- method: 'GET',
364
- headers: {
365
- Authorization: this.auth
366
- }
367
- });
368
- case 1:
369
- response = _context6.sent;
370
- if (response.ok) {
371
- _context6.next = 5;
372
- break;
373
- }
374
- grc = new _about["default"](this.url, this.auth);
375
- _context6.next = 2;
376
- return grc.exists();
377
- case 2:
378
- if (!_context6.sent) {
379
- _context6.next = 3;
380
- break;
381
- }
382
- return _context6.abrupt("return");
383
- case 3:
384
- _context6.next = 4;
385
- return (0, _geoserver.getGeoServerResponseText)(response);
386
- case 4:
387
- geoServerResponse = _context6.sent;
388
- throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
389
- case 5:
390
- _context6.next = 6;
391
- return response.json();
392
- case 6:
393
- return _context6.abrupt("return", _context6.sent);
394
- case 7:
395
- case "end":
396
- return _context6.stop();
397
- }
398
- }, _callee6, this);
399
- }));
400
- function getWmtsLayer(_x1, _x10, _x11) {
401
- return _getWmtsLayer.apply(this, arguments);
188
+ }
189
+ return await response.json();
190
+ }
191
+
192
+ // TODO: automated test needed
193
+ /**
194
+ * Returns information about a cascaded WMTS layer.
195
+ *
196
+ * @param {String} workspace The workspace
197
+ * @param {String} datastore The datastore
198
+ * @param {String} layerName The WMTS layer name
199
+ *
200
+ * @throws Error if request fails
201
+ *
202
+ * @returns {Object} An object with layer information or undefined if it cannot be found
203
+ */
204
+ async getWmtsLayer(workspace, datastore, layerName) {
205
+ const response = await (0, _nodeFetch.default)(this.url + 'workspaces/' + workspace + '/wmtsstores/' + datastore + '/layers/' + layerName + '.json', {
206
+ credentials: 'include',
207
+ method: 'GET',
208
+ headers: {
209
+ Authorization: this.auth
210
+ }
211
+ });
212
+ if (!response.ok) {
213
+ const grc = new _about.default(this.url, this.auth);
214
+ if (await grc.exists()) {
215
+ // GeoServer exists, but requested item does not exist, we return empty
216
+ return;
217
+ } else {
218
+ // There was a general problem with GeoServer
219
+ const geoServerResponse = await (0, _geoserver.getGeoServerResponseText)(response);
220
+ throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
221
+ }
222
+ }
223
+ return await response.json();
224
+ }
225
+
226
+ /**
227
+ * Publishes a FeatureType in the default data store of the workspace.
228
+ *
229
+ * @param {String} workspace Workspace to publish FeatureType in
230
+ * @param {String} [nativeName] Native name of FeatureType
231
+ * @param {String} name Published name of FeatureType
232
+ * @param {String} [title] Published title of FeatureType
233
+ * @param {String} [srs="EPSG:4326"] The SRS of the FeatureType
234
+ * @param {String} enabled Flag to enable FeatureType by default
235
+ * @param {String} [abstract] The abstract of the layer
236
+ *
237
+ * @throws Error if request fails
238
+ */
239
+ async publishFeatureTypeDefaultDataStore(workspace, nativeName, name, title, srs, enabled, abstract) {
240
+ const body = {
241
+ featureType: {
242
+ name: name,
243
+ nativeName: nativeName || name,
244
+ title: title || name,
245
+ srs: srs || 'EPSG:4326',
246
+ enabled: enabled,
247
+ abstract: abstract || ''
248
+ }
249
+ };
250
+ const response = await (0, _nodeFetch.default)(this.url + 'workspaces/' + workspace + '/featuretypes', {
251
+ credentials: 'include',
252
+ method: 'POST',
253
+ headers: {
254
+ Authorization: this.auth,
255
+ 'Content-Type': 'application/json'
256
+ },
257
+ body: JSON.stringify(body)
258
+ });
259
+ if (!response.ok) {
260
+ const geoServerResponse = await (0, _geoserver.getGeoServerResponseText)(response);
261
+ throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
262
+ }
263
+ }
264
+
265
+ /**
266
+ * Publishes a FeatureType in the given data store of the workspace.
267
+ *
268
+ * @param {String} workspace Workspace to publish FeatureType in
269
+ * @param {String} dataStore The datastore where the FeatureType's data is in
270
+ * @param {String} [nativeName] Native name of FeatureType
271
+ * @param {String} name Published name of FeatureType
272
+ * @param {String} [title] Published title of FeatureType
273
+ * @param {String} [srs="EPSG:4326"] The SRS of the FeatureType
274
+ * @param {String} enabled Flag to enable FeatureType by default
275
+ * @param {String} [abstract] The abstract of the layer
276
+ * @param {String} [nativeBoundingBox] The native BoundingBox of the FeatureType (has to be set if no data is in store at creation time)
277
+ *
278
+ * @throws Error if request fails
279
+ */
280
+ async publishFeatureType(workspace, dataStore, nativeName, name, title, srs, enabled, abstract, nativeBoundingBox) {
281
+ // apply CRS info for native BBOX if not provided
282
+ if (nativeBoundingBox && !nativeBoundingBox.crs) {
283
+ nativeBoundingBox.crs = {
284
+ '@class': 'projected',
285
+ $: srs
286
+ };
287
+ }
288
+ const body = {
289
+ featureType: {
290
+ name: name || nativeName,
291
+ nativeName: nativeName,
292
+ title: title || name,
293
+ srs: srs || 'EPSG:4326',
294
+ enabled: enabled,
295
+ abstract: abstract || '',
296
+ nativeBoundingBox: nativeBoundingBox
297
+ }
298
+ };
299
+ const response = await (0, _nodeFetch.default)(this.url + 'workspaces/' + workspace + '/datastores/' + dataStore + '/featuretypes', {
300
+ credentials: 'include',
301
+ method: 'POST',
302
+ headers: {
303
+ Authorization: this.auth,
304
+ 'Content-Type': 'application/json'
305
+ },
306
+ body: JSON.stringify(body)
307
+ });
308
+ if (!response.ok) {
309
+ const geoServerResponse = await (0, _geoserver.getGeoServerResponseText)(response);
310
+ throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
311
+ }
312
+ }
313
+
314
+ /**
315
+ * Get detailed information about a FeatureType.
316
+ *
317
+ * @param {String} workspace The workspace of the FeatureType
318
+ * @param {String} datastore The datastore of the FeatureType
319
+ * @param {String} name The name of the FeatureType
320
+ *
321
+ * @throws Error if request fails
322
+ *
323
+ * @returns {Object} The object of the FeatureType
324
+ */
325
+ async getFeatureType(workspace, datastore, name) {
326
+ const url = this.url + 'workspaces/' + workspace + '/datastores/' + datastore + '/featuretypes/' + name + '.json';
327
+ const response = await (0, _nodeFetch.default)(url, {
328
+ credentials: 'include',
329
+ method: 'GET',
330
+ headers: {
331
+ Authorization: this.auth
332
+ }
333
+ });
334
+ if (!response.ok) {
335
+ const grc = new _about.default(this.url, this.auth);
336
+ if (await grc.exists()) {
337
+ // GeoServer exists, but requested item does not exist, we return empty
338
+ return;
339
+ } else {
340
+ // There was a general problem with GeoServer
341
+ const geoServerResponse = await (0, _geoserver.getGeoServerResponseText)(response);
342
+ throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
343
+ }
344
+ }
345
+ return response.json();
346
+ }
347
+
348
+ /**
349
+ * Get detailed information about a FeatureType.
350
+ *
351
+ * @param {String} workspace The workspace of the FeatureType
352
+ * @param {String} name The name of the FeatureType
353
+ *
354
+ * @throws GeoServerResponseError if request fails or layer does not exist or lacks the right properties.
355
+ *
356
+ * @returns {Object} The object of the FeatureType
357
+ */
358
+ async getFeatureTypeFromLayer(workspace, layer) {
359
+ const layerObj = await this.get(workspace, layer);
360
+ if (!layerObj || !layerObj.layer || !layerObj.layer.resource || !layerObj.layer.resource.href) {
361
+ throw new _geoserver.GeoServerResponseError(`Layer '${workspace}:${layer}' does not exist or lacks the layer.resource.href property.`);
362
+ }
363
+ const url = layerObj?.layer?.resource?.href;
364
+ const response = await (0, _nodeFetch.default)(url, {
365
+ credentials: 'include',
366
+ method: 'GET',
367
+ headers: {
368
+ Authorization: this.auth
402
369
  }
403
- return getWmtsLayer;
404
- }()
405
- /**
406
- * Publishes a FeatureType in the default data store of the workspace.
407
- *
408
- * @param {String} workspace Workspace to publish FeatureType in
409
- * @param {String} [nativeName] Native name of FeatureType
410
- * @param {String} name Published name of FeatureType
411
- * @param {String} [title] Published title of FeatureType
412
- * @param {String} [srs="EPSG:4326"] The SRS of the FeatureType
413
- * @param {String} enabled Flag to enable FeatureType by default
414
- * @param {String} [abstract] The abstract of the layer
415
- *
416
- * @throws Error if request fails
417
- */
418
- }, {
419
- key: "publishFeatureTypeDefaultDataStore",
420
- value: (function () {
421
- var _publishFeatureTypeDefaultDataStore = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee7(workspace, nativeName, name, title, srs, enabled, _abstract) {
422
- var body, response, geoServerResponse;
423
- return _regenerator["default"].wrap(function (_context7) {
424
- while (1) switch (_context7.prev = _context7.next) {
425
- case 0:
426
- body = {
427
- featureType: {
428
- name: name,
429
- nativeName: nativeName || name,
430
- title: title || name,
431
- srs: srs || 'EPSG:4326',
432
- enabled: enabled,
433
- "abstract": _abstract || ''
434
- }
435
- };
436
- _context7.next = 1;
437
- return (0, _nodeFetch["default"])(this.url + 'workspaces/' + workspace + '/featuretypes', {
438
- credentials: 'include',
439
- method: 'POST',
440
- headers: {
441
- Authorization: this.auth,
442
- 'Content-Type': 'application/json'
443
- },
444
- body: JSON.stringify(body)
445
- });
446
- case 1:
447
- response = _context7.sent;
448
- if (response.ok) {
449
- _context7.next = 3;
450
- break;
451
- }
452
- _context7.next = 2;
453
- return (0, _geoserver.getGeoServerResponseText)(response);
454
- case 2:
455
- geoServerResponse = _context7.sent;
456
- throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
457
- case 3:
458
- case "end":
459
- return _context7.stop();
460
- }
461
- }, _callee7, this);
462
- }));
463
- function publishFeatureTypeDefaultDataStore(_x12, _x13, _x14, _x15, _x16, _x17, _x18) {
464
- return _publishFeatureTypeDefaultDataStore.apply(this, arguments);
370
+ });
371
+ if (!response.ok) {
372
+ const geoServerResponse = await (0, _geoserver.getGeoServerResponseText)(response);
373
+ throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
374
+ }
375
+ return response.json();
376
+ }
377
+
378
+ /**
379
+ * Publishes a WMS layer.
380
+ *
381
+ * @param {String} workspace Workspace to publish WMS layer in
382
+ * @param {String} dataStore The datastore where the WMS is connected
383
+ * @param {String} nativeName Native name of WMS layer
384
+ * @param {String} [name] Published name of WMS layer
385
+ * @param {String} [title] Published title of WMS layer
386
+ * @param {String} [srs="EPSG:4326"] The SRS of the WMS layer
387
+ * @param {String} enabled Flag to enable WMS layer by default
388
+ * @param {String} [abstract] The abstract of the layer
389
+ *
390
+ * @throws Error if request fails
391
+ */
392
+ async publishWmsLayer(workspace, dataStore, nativeName, name, title, srs, enabled, abstract) {
393
+ const body = {
394
+ wmsLayer: {
395
+ name: name || nativeName,
396
+ nativeName: nativeName,
397
+ title: title || name || nativeName,
398
+ srs: srs || 'EPSG:4326',
399
+ enabled: enabled,
400
+ abstract: abstract || ''
465
401
  }
466
- return publishFeatureTypeDefaultDataStore;
467
- }()
468
- /**
469
- * Publishes a FeatureType in the given data store of the workspace.
470
- *
471
- * @param {String} workspace Workspace to publish FeatureType in
472
- * @param {String} dataStore The datastore where the FeatureType's data is in
473
- * @param {String} [nativeName] Native name of FeatureType
474
- * @param {String} name Published name of FeatureType
475
- * @param {String} [title] Published title of FeatureType
476
- * @param {String} [srs="EPSG:4326"] The SRS of the FeatureType
477
- * @param {String} enabled Flag to enable FeatureType by default
478
- * @param {String} [abstract] The abstract of the layer
479
- * @param {String} [nativeBoundingBox] The native BoundingBox of the FeatureType (has to be set if no data is in store at creation time)
480
- *
481
- * @throws Error if request fails
482
- */
483
- )
484
- }, {
485
- key: "publishFeatureType",
486
- value: (function () {
487
- var _publishFeatureType = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee8(workspace, dataStore, nativeName, name, title, srs, enabled, _abstract2, nativeBoundingBox) {
488
- var body, response, geoServerResponse;
489
- return _regenerator["default"].wrap(function (_context8) {
490
- while (1) switch (_context8.prev = _context8.next) {
491
- case 0:
492
- // apply CRS info for native BBOX if not provided
493
- if (nativeBoundingBox && !nativeBoundingBox.crs) {
494
- nativeBoundingBox.crs = {
495
- '@class': 'projected',
496
- $: srs
497
- };
498
- }
499
- body = {
500
- featureType: {
501
- name: name || nativeName,
502
- nativeName: nativeName,
503
- title: title || name,
504
- srs: srs || 'EPSG:4326',
505
- enabled: enabled,
506
- "abstract": _abstract2 || '',
507
- nativeBoundingBox: nativeBoundingBox
508
- }
509
- };
510
- _context8.next = 1;
511
- return (0, _nodeFetch["default"])(this.url + 'workspaces/' + workspace + '/datastores/' + dataStore + '/featuretypes', {
512
- credentials: 'include',
513
- method: 'POST',
514
- headers: {
515
- Authorization: this.auth,
516
- 'Content-Type': 'application/json'
517
- },
518
- body: JSON.stringify(body)
519
- });
520
- case 1:
521
- response = _context8.sent;
522
- if (response.ok) {
523
- _context8.next = 3;
524
- break;
525
- }
526
- _context8.next = 2;
527
- return (0, _geoserver.getGeoServerResponseText)(response);
528
- case 2:
529
- geoServerResponse = _context8.sent;
530
- throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
531
- case 3:
532
- case "end":
533
- return _context8.stop();
534
- }
535
- }, _callee8, this);
536
- }));
537
- function publishFeatureType(_x19, _x20, _x21, _x22, _x23, _x24, _x25, _x26, _x27) {
538
- return _publishFeatureType.apply(this, arguments);
402
+ };
403
+ const response = await (0, _nodeFetch.default)(this.url + 'workspaces/' + workspace + '/wmsstores/' + dataStore + '/wmslayers', {
404
+ credentials: 'include',
405
+ method: 'POST',
406
+ headers: {
407
+ Authorization: this.auth,
408
+ 'Content-Type': 'application/json'
409
+ },
410
+ body: JSON.stringify(body)
411
+ });
412
+ if (!response.ok) {
413
+ const geoServerResponse = await (0, _geoserver.getGeoServerResponseText)(response);
414
+ throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
415
+ }
416
+ }
417
+
418
+ /**
419
+ * Publishes a raster stored in a database.
420
+ *
421
+ * @param {String} workspace Workspace to publish layer in
422
+ * @param {String} coverageStore The coveragestore where the layer's data is in
423
+ * @param {String} nativeName Native name of raster
424
+ * @param {String} name Published name of layer
425
+ * @param {String} [title] Published title of layer
426
+ * @param {String} [srs="EPSG:4326"] The SRS of the layer
427
+ * @param {String} enabled Flag to enable layer by default
428
+ * @param {String} [abstract] The abstract of the layer
429
+ *
430
+ * @throws Error if request fails
431
+ */
432
+ async publishDbRaster(workspace, coverageStore, nativeName, name, title, srs, enabled, abstract) {
433
+ const body = {
434
+ coverage: {
435
+ name: name || nativeName,
436
+ nativeName: nativeName,
437
+ title: title || name,
438
+ srs: srs,
439
+ enabled: enabled,
440
+ abstract: abstract || ''
539
441
  }
540
- return publishFeatureType;
541
- }()
542
- /**
543
- * Get detailed information about a FeatureType.
544
- *
545
- * @param {String} workspace The workspace of the FeatureType
546
- * @param {String} datastore The datastore of the FeatureType
547
- * @param {String} name The name of the FeatureType
548
- *
549
- * @throws Error if request fails
550
- *
551
- * @returns {Object} The object of the FeatureType
552
- */
553
- )
554
- }, {
555
- key: "getFeatureType",
556
- value: (function () {
557
- var _getFeatureType = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee9(workspace, datastore, name) {
558
- var url, response, grc, geoServerResponse;
559
- return _regenerator["default"].wrap(function (_context9) {
560
- while (1) switch (_context9.prev = _context9.next) {
561
- case 0:
562
- url = this.url + 'workspaces/' + workspace + '/datastores/' + datastore + '/featuretypes/' + name + '.json';
563
- _context9.next = 1;
564
- return (0, _nodeFetch["default"])(url, {
565
- credentials: 'include',
566
- method: 'GET',
567
- headers: {
568
- Authorization: this.auth
569
- }
570
- });
571
- case 1:
572
- response = _context9.sent;
573
- if (response.ok) {
574
- _context9.next = 5;
575
- break;
576
- }
577
- grc = new _about["default"](this.url, this.auth);
578
- _context9.next = 2;
579
- return grc.exists();
580
- case 2:
581
- if (!_context9.sent) {
582
- _context9.next = 3;
583
- break;
584
- }
585
- return _context9.abrupt("return");
586
- case 3:
587
- _context9.next = 4;
588
- return (0, _geoserver.getGeoServerResponseText)(response);
589
- case 4:
590
- geoServerResponse = _context9.sent;
591
- throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
592
- case 5:
593
- return _context9.abrupt("return", response.json());
594
- case 6:
595
- case "end":
596
- return _context9.stop();
597
- }
598
- }, _callee9, this);
599
- }));
600
- function getFeatureType(_x28, _x29, _x30) {
601
- return _getFeatureType.apply(this, arguments);
442
+ };
443
+ const response = await (0, _nodeFetch.default)(this.url + 'workspaces/' + workspace + '/coveragestores/' + coverageStore + '/coverages', {
444
+ credentials: 'include',
445
+ method: 'POST',
446
+ headers: {
447
+ Authorization: this.auth,
448
+ 'Content-Type': 'application/json'
449
+ },
450
+ body: JSON.stringify(body)
451
+ });
452
+ if (!response.ok) {
453
+ const geoServerResponse = await (0, _geoserver.getGeoServerResponseText)(response);
454
+ throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
455
+ }
456
+ }
457
+
458
+ /**
459
+ * Deletes a FeatureType.
460
+ *
461
+ * @param {String} workspace Workspace where layer to delete is in
462
+ * @param {String} datastore The datastore where the layer to delete is in
463
+ * @param {String} name Layer to delete
464
+ * @param {Boolean} recurse Flag to enable recursive deletion
465
+ *
466
+ * @throws Error if request fails
467
+ */
468
+ async deleteFeatureType(workspace, datastore, name, recurse) {
469
+ const response = await (0, _nodeFetch.default)(this.url + 'workspaces/' + workspace + '/datastores/' + datastore + '/featuretypes/' + name + '?recurse=' + recurse, {
470
+ credentials: 'include',
471
+ method: 'DELETE',
472
+ headers: {
473
+ Authorization: this.auth
602
474
  }
603
- return getFeatureType;
604
- }()
605
- /**
606
- * Get detailed information about a FeatureType.
607
- *
608
- * @param {String} workspace The workspace of the FeatureType
609
- * @param {String} name The name of the FeatureType
610
- *
611
- * @throws GeoServerResponseError if request fails or layer does not exist or lacks the right properties.
612
- *
613
- * @returns {Object} The object of the FeatureType
614
- */
615
- )
616
- }, {
617
- key: "getFeatureTypeFromLayer",
618
- value: (function () {
619
- var _getFeatureTypeFromLayer = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee0(workspace, layer) {
620
- var _layerObj$layer;
621
- var layerObj, url, response, geoServerResponse;
622
- return _regenerator["default"].wrap(function (_context0) {
623
- while (1) switch (_context0.prev = _context0.next) {
624
- case 0:
625
- _context0.next = 1;
626
- return this.get(workspace, layer);
627
- case 1:
628
- layerObj = _context0.sent;
629
- if (!(!layerObj || !layerObj.layer || !layerObj.layer.resource || !layerObj.layer.resource.href)) {
630
- _context0.next = 2;
631
- break;
632
- }
633
- throw new _geoserver.GeoServerResponseError("Layer '".concat(workspace, ":").concat(layer, "' does not exist or lacks the layer.resource.href property."));
634
- case 2:
635
- url = layerObj === null || layerObj === void 0 || (_layerObj$layer = layerObj.layer) === null || _layerObj$layer === void 0 || (_layerObj$layer = _layerObj$layer.resource) === null || _layerObj$layer === void 0 ? void 0 : _layerObj$layer.href;
636
- _context0.next = 3;
637
- return (0, _nodeFetch["default"])(url, {
638
- credentials: 'include',
639
- method: 'GET',
640
- headers: {
641
- Authorization: this.auth
642
- }
643
- });
644
- case 3:
645
- response = _context0.sent;
646
- if (response.ok) {
647
- _context0.next = 5;
648
- break;
649
- }
650
- _context0.next = 4;
651
- return (0, _geoserver.getGeoServerResponseText)(response);
652
- case 4:
653
- geoServerResponse = _context0.sent;
654
- throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
655
- case 5:
656
- return _context0.abrupt("return", response.json());
657
- case 6:
658
- case "end":
659
- return _context0.stop();
660
- }
661
- }, _callee0, this);
662
- }));
663
- function getFeatureTypeFromLayer(_x31, _x32) {
664
- return _getFeatureTypeFromLayer.apply(this, arguments);
475
+ });
476
+ if (!response.ok) {
477
+ const geoServerResponse = await (0, _geoserver.getGeoServerResponseText)(response);
478
+ throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
479
+ }
480
+ }
481
+
482
+ /**
483
+ * Enables TIME dimension for the given coverage layer.
484
+ *
485
+ * @param {String} workspace Workspace where layer to enable time dimension for is in
486
+ * @param {String} datastore The datastore where the layer to enable time dimension for is in
487
+ * @param {String} name Layer to enable time dimension for
488
+ * @param {String} presentation Presentation type: 'LIST' or 'DISCRETE_INTERVAL' or 'CONTINUOUS_INTERVAL'
489
+ * @param {Number} resolution Resolution in milliseconds, e.g. 3600000 for 1 hour
490
+ * @param {String} defaultValue The default time value, e.g. 'MINIMUM' or 'MAXIMUM' or 'NEAREST' or 'FIXED'
491
+ * @param {Boolean} [nearestMatchEnabled] Enable nearest match
492
+ * @param {Boolean} [rawNearestMatchEnabled] Enable raw nearest match
493
+ * @param {String} [acceptableInterval] Acceptable interval for nearest match, e.g.'PT30M'
494
+ *
495
+ * @throws Error if request fails
496
+ */
497
+ async enableTimeCoverage(workspace, dataStore, name, presentation, resolution, defaultValue, nearestMatchEnabled, rawNearestMatchEnabled, acceptableInterval) {
498
+ const body = {
499
+ coverage: {
500
+ metadata: {
501
+ entry: [{
502
+ '@key': 'time',
503
+ dimensionInfo: {
504
+ enabled: true,
505
+ presentation: presentation || 'DISCRETE_INTERVAL',
506
+ resolution: resolution,
507
+ units: 'ISO8601',
508
+ defaultValue: {
509
+ strategy: defaultValue
510
+ },
511
+ nearestMatchEnabled: nearestMatchEnabled,
512
+ rawNearestMatchEnabled: rawNearestMatchEnabled,
513
+ acceptableInterval: acceptableInterval
514
+ }
515
+ }]
516
+ }
665
517
  }
666
- return getFeatureTypeFromLayer;
667
- }()
668
- /**
669
- * Publishes a WMS layer.
670
- *
671
- * @param {String} workspace Workspace to publish WMS layer in
672
- * @param {String} dataStore The datastore where the WMS is connected
673
- * @param {String} nativeName Native name of WMS layer
674
- * @param {String} [name] Published name of WMS layer
675
- * @param {String} [title] Published title of WMS layer
676
- * @param {String} [srs="EPSG:4326"] The SRS of the WMS layer
677
- * @param {String} enabled Flag to enable WMS layer by default
678
- * @param {String} [abstract] The abstract of the layer
679
- *
680
- * @throws Error if request fails
681
- */
682
- )
683
- }, {
684
- key: "publishWmsLayer",
685
- value: (function () {
686
- var _publishWmsLayer = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee1(workspace, dataStore, nativeName, name, title, srs, enabled, _abstract3) {
687
- var body, response, geoServerResponse;
688
- return _regenerator["default"].wrap(function (_context1) {
689
- while (1) switch (_context1.prev = _context1.next) {
690
- case 0:
691
- body = {
692
- wmsLayer: {
693
- name: name || nativeName,
694
- nativeName: nativeName,
695
- title: title || name || nativeName,
696
- srs: srs || 'EPSG:4326',
697
- enabled: enabled,
698
- "abstract": _abstract3 || ''
699
- }
700
- };
701
- _context1.next = 1;
702
- return (0, _nodeFetch["default"])(this.url + 'workspaces/' + workspace + '/wmsstores/' + dataStore + '/wmslayers', {
703
- credentials: 'include',
704
- method: 'POST',
705
- headers: {
706
- Authorization: this.auth,
707
- 'Content-Type': 'application/json'
708
- },
709
- body: JSON.stringify(body)
710
- });
711
- case 1:
712
- response = _context1.sent;
713
- if (response.ok) {
714
- _context1.next = 3;
715
- break;
716
- }
717
- _context1.next = 2;
718
- return (0, _geoserver.getGeoServerResponseText)(response);
719
- case 2:
720
- geoServerResponse = _context1.sent;
721
- throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
722
- case 3:
723
- case "end":
724
- return _context1.stop();
725
- }
726
- }, _callee1, this);
727
- }));
728
- function publishWmsLayer(_x33, _x34, _x35, _x36, _x37, _x38, _x39, _x40) {
729
- return _publishWmsLayer.apply(this, arguments);
518
+ };
519
+ const url = this.url + 'workspaces/' + workspace + '/coveragestores/' + dataStore + '/coverages/' + name + '.json';
520
+ const response = await (0, _nodeFetch.default)(url, {
521
+ credentials: 'include',
522
+ method: 'PUT',
523
+ headers: {
524
+ Authorization: this.auth,
525
+ 'Content-Type': 'application/json'
526
+ },
527
+ body: JSON.stringify(body)
528
+ });
529
+ if (!response.ok) {
530
+ const geoServerResponse = await (0, _geoserver.getGeoServerResponseText)(response);
531
+ throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
532
+ }
533
+ }
534
+
535
+ /**
536
+ * Enables TIME dimension for the given FeatureType layer.
537
+ *
538
+ * @param {String} workspace Workspace containing layer to enable time dimension for
539
+ * @param {String} datastore The datastore containing the FeatureType to enable time dimension for
540
+ * @param {String} name FeatureType to enable time dimension for
541
+ * @param {String} attribute Data column / attribute holding the time values
542
+ * @param {String} presentation Presentation type: 'LIST' or 'DISCRETE_INTERVAL' or 'CONTINUOUS_INTERVAL'
543
+ * @param {Number} resolution Resolution in milliseconds, e.g. 3600000 for 1 hour
544
+ * @param {String} defaultValue The default time value, e.g. 'MINIMUM' or 'MAXIMUM' or 'NEAREST' or 'FIXED'
545
+ * @param {Boolean} [nearestMatchEnabled] Enable nearest match
546
+ * @param {Boolean} [rawNearestMatchEnabled] Enable raw nearest match
547
+ *
548
+ * @throws Error if request fails
549
+ */
550
+ async enableTimeFeatureType(workspace, dataStore, name, attribute, presentation, resolution, defaultValue, nearestMatchEnabled, rawNearestMatchEnabled, acceptableInterval) {
551
+ const body = {
552
+ featureType: {
553
+ metadata: {
554
+ entry: [{
555
+ '@key': 'time',
556
+ dimensionInfo: {
557
+ attribute: attribute,
558
+ presentation: presentation,
559
+ resolution: resolution,
560
+ units: 'ISO8601',
561
+ defaultValue: {
562
+ strategy: defaultValue
563
+ },
564
+ nearestMatchEnabled: nearestMatchEnabled,
565
+ rawNearestMatchEnabled: rawNearestMatchEnabled,
566
+ acceptableInterval: acceptableInterval
567
+ }
568
+ }]
569
+ }
730
570
  }
731
- return publishWmsLayer;
732
- }()
733
- /**
734
- * Publishes a raster stored in a database.
735
- *
736
- * @param {String} workspace Workspace to publish layer in
737
- * @param {String} coverageStore The coveragestore where the layer's data is in
738
- * @param {String} nativeName Native name of raster
739
- * @param {String} name Published name of layer
740
- * @param {String} [title] Published title of layer
741
- * @param {String} [srs="EPSG:4326"] The SRS of the layer
742
- * @param {String} enabled Flag to enable layer by default
743
- * @param {String} [abstract] The abstract of the layer
744
- *
745
- * @throws Error if request fails
746
- */
747
- )
748
- }, {
749
- key: "publishDbRaster",
750
- value: (function () {
751
- var _publishDbRaster = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee10(workspace, coverageStore, nativeName, name, title, srs, enabled, _abstract4) {
752
- var body, response, geoServerResponse;
753
- return _regenerator["default"].wrap(function (_context10) {
754
- while (1) switch (_context10.prev = _context10.next) {
755
- case 0:
756
- body = {
757
- coverage: {
758
- name: name || nativeName,
759
- nativeName: nativeName,
760
- title: title || name,
761
- srs: srs,
762
- enabled: enabled,
763
- "abstract": _abstract4 || ''
764
- }
765
- };
766
- _context10.next = 1;
767
- return (0, _nodeFetch["default"])(this.url + 'workspaces/' + workspace + '/coveragestores/' + coverageStore + '/coverages', {
768
- credentials: 'include',
769
- method: 'POST',
770
- headers: {
771
- Authorization: this.auth,
772
- 'Content-Type': 'application/json'
773
- },
774
- body: JSON.stringify(body)
775
- });
776
- case 1:
777
- response = _context10.sent;
778
- if (response.ok) {
779
- _context10.next = 3;
780
- break;
781
- }
782
- _context10.next = 2;
783
- return (0, _geoserver.getGeoServerResponseText)(response);
784
- case 2:
785
- geoServerResponse = _context10.sent;
786
- throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
787
- case 3:
788
- case "end":
789
- return _context10.stop();
790
- }
791
- }, _callee10, this);
792
- }));
793
- function publishDbRaster(_x41, _x42, _x43, _x44, _x45, _x46, _x47, _x48) {
794
- return _publishDbRaster.apply(this, arguments);
571
+ };
572
+ const url = this.url + 'workspaces/' + workspace + '/datastores/' + dataStore + '/featuretypes/' + name + '.json';
573
+ const response = await (0, _nodeFetch.default)(url, {
574
+ credentials: 'include',
575
+ method: 'PUT',
576
+ headers: {
577
+ Authorization: this.auth,
578
+ 'Content-Type': 'application/json'
579
+ },
580
+ body: JSON.stringify(body)
581
+ });
582
+ if (!response.ok) {
583
+ const geoServerResponse = await (0, _geoserver.getGeoServerResponseText)(response);
584
+ throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
585
+ }
586
+ }
587
+
588
+ /**
589
+ * Returns a dedicated coverage object.
590
+ *
591
+ * @param {String} workspace Workspace containing the coverage
592
+ * @param {String} coverageStore The coveragestore containing the coverage
593
+ * @param {String} name Coverage to query
594
+ *
595
+ * @throws Error if request fails
596
+ *
597
+ * @returns {Object} An object with coverage information or undefined if it cannot be found
598
+ */
599
+ async getCoverage(workspace, coverageStore, name) {
600
+ const url = this.url + 'workspaces/' + workspace + '/coveragestores/' + coverageStore + '/coverages/' + name + '.json';
601
+ const response = await (0, _nodeFetch.default)(url, {
602
+ credentials: 'include',
603
+ method: 'GET',
604
+ headers: {
605
+ Authorization: this.auth
795
606
  }
796
- return publishDbRaster;
797
- }()
798
- /**
799
- * Deletes a FeatureType.
800
- *
801
- * @param {String} workspace Workspace where layer to delete is in
802
- * @param {String} datastore The datastore where the layer to delete is in
803
- * @param {String} name Layer to delete
804
- * @param {Boolean} recurse Flag to enable recursive deletion
805
- *
806
- * @throws Error if request fails
807
- */
808
- )
809
- }, {
810
- key: "deleteFeatureType",
811
- value: (function () {
812
- var _deleteFeatureType = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee11(workspace, datastore, name, recurse) {
813
- var response, geoServerResponse;
814
- return _regenerator["default"].wrap(function (_context11) {
815
- while (1) switch (_context11.prev = _context11.next) {
816
- case 0:
817
- _context11.next = 1;
818
- return (0, _nodeFetch["default"])(this.url + 'workspaces/' + workspace + '/datastores/' + datastore + '/featuretypes/' + name + '?recurse=' + recurse, {
819
- credentials: 'include',
820
- method: 'DELETE',
821
- headers: {
822
- Authorization: this.auth
823
- }
824
- });
825
- case 1:
826
- response = _context11.sent;
827
- if (response.ok) {
828
- _context11.next = 3;
829
- break;
830
- }
831
- _context11.next = 2;
832
- return (0, _geoserver.getGeoServerResponseText)(response);
833
- case 2:
834
- geoServerResponse = _context11.sent;
835
- throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
836
- case 3:
837
- case "end":
838
- return _context11.stop();
839
- }
840
- }, _callee11, this);
841
- }));
842
- function deleteFeatureType(_x49, _x50, _x51, _x52) {
843
- return _deleteFeatureType.apply(this, arguments);
607
+ });
608
+ if (!response.ok) {
609
+ const grc = new _about.default(this.url, this.auth);
610
+ if (await grc.exists()) {
611
+ // GeoServer exists, but requested item does not exist, we return empty
612
+ return;
613
+ } else {
614
+ // There was a general problem with GeoServer
615
+ const geoServerResponse = await (0, _geoserver.getGeoServerResponseText)(response);
616
+ throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
844
617
  }
845
- return deleteFeatureType;
846
- }()
847
- /**
848
- * Enables TIME dimension for the given coverage layer.
849
- *
850
- * @param {String} workspace Workspace where layer to enable time dimension for is in
851
- * @param {String} datastore The datastore where the layer to enable time dimension for is in
852
- * @param {String} name Layer to enable time dimension for
853
- * @param {String} presentation Presentation type: 'LIST' or 'DISCRETE_INTERVAL' or 'CONTINUOUS_INTERVAL'
854
- * @param {Number} resolution Resolution in milliseconds, e.g. 3600000 for 1 hour
855
- * @param {String} defaultValue The default time value, e.g. 'MINIMUM' or 'MAXIMUM' or 'NEAREST' or 'FIXED'
856
- * @param {Boolean} [nearestMatchEnabled] Enable nearest match
857
- * @param {Boolean} [rawNearestMatchEnabled] Enable raw nearest match
858
- * @param {String} [acceptableInterval] Acceptable interval for nearest match, e.g.'PT30M'
859
- *
860
- * @throws Error if request fails
861
- */
862
- )
863
- }, {
864
- key: "enableTimeCoverage",
865
- value: (function () {
866
- var _enableTimeCoverage = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee12(workspace, dataStore, name, presentation, resolution, defaultValue, nearestMatchEnabled, rawNearestMatchEnabled, acceptableInterval) {
867
- var body, url, response, geoServerResponse;
868
- return _regenerator["default"].wrap(function (_context12) {
869
- while (1) switch (_context12.prev = _context12.next) {
870
- case 0:
871
- body = {
872
- coverage: {
873
- metadata: {
874
- entry: [{
875
- '@key': 'time',
876
- dimensionInfo: {
877
- enabled: true,
878
- presentation: presentation || 'DISCRETE_INTERVAL',
879
- resolution: resolution,
880
- units: 'ISO8601',
881
- defaultValue: {
882
- strategy: defaultValue
883
- },
884
- nearestMatchEnabled: nearestMatchEnabled,
885
- rawNearestMatchEnabled: rawNearestMatchEnabled,
886
- acceptableInterval: acceptableInterval
887
- }
888
- }]
889
- }
890
- }
891
- };
892
- url = this.url + 'workspaces/' + workspace + '/coveragestores/' + dataStore + '/coverages/' + name + '.json';
893
- _context12.next = 1;
894
- return (0, _nodeFetch["default"])(url, {
895
- credentials: 'include',
896
- method: 'PUT',
897
- headers: {
898
- Authorization: this.auth,
899
- 'Content-Type': 'application/json'
900
- },
901
- body: JSON.stringify(body)
902
- });
903
- case 1:
904
- response = _context12.sent;
905
- if (response.ok) {
906
- _context12.next = 3;
907
- break;
908
- }
909
- _context12.next = 2;
910
- return (0, _geoserver.getGeoServerResponseText)(response);
911
- case 2:
912
- geoServerResponse = _context12.sent;
913
- throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
914
- case 3:
915
- case "end":
916
- return _context12.stop();
917
- }
918
- }, _callee12, this);
919
- }));
920
- function enableTimeCoverage(_x53, _x54, _x55, _x56, _x57, _x58, _x59, _x60, _x61) {
921
- return _enableTimeCoverage.apply(this, arguments);
618
+ }
619
+ return response.json();
620
+ }
621
+
622
+ /**
623
+ * Returns a dedicated coverage object.
624
+ *
625
+ * @param {String} workspace Workspace containing the coverage
626
+ * @param {String} name Coverage to query
627
+ *
628
+ * @throws Error if request fails
629
+ *
630
+ * @returns {Object} An object with coverage information or undefined if it cannot be found
631
+ */
632
+ async getCoverageFromLayer(workspace, name) {
633
+ const url = this.url + '/workspaces/' + workspace + '/coverages/' + name + '.json';
634
+ const response = await (0, _nodeFetch.default)(url, {
635
+ credentials: 'include',
636
+ method: 'GET',
637
+ headers: {
638
+ Authorization: this.auth
922
639
  }
923
- return enableTimeCoverage;
924
- }()
925
- /**
926
- * Enables TIME dimension for the given FeatureType layer.
927
- *
928
- * @param {String} workspace Workspace containing layer to enable time dimension for
929
- * @param {String} datastore The datastore containing the FeatureType to enable time dimension for
930
- * @param {String} name FeatureType to enable time dimension for
931
- * @param {String} attribute Data column / attribute holding the time values
932
- * @param {String} presentation Presentation type: 'LIST' or 'DISCRETE_INTERVAL' or 'CONTINUOUS_INTERVAL'
933
- * @param {Number} resolution Resolution in milliseconds, e.g. 3600000 for 1 hour
934
- * @param {String} defaultValue The default time value, e.g. 'MINIMUM' or 'MAXIMUM' or 'NEAREST' or 'FIXED'
935
- * @param {Boolean} [nearestMatchEnabled] Enable nearest match
936
- * @param {Boolean} [rawNearestMatchEnabled] Enable raw nearest match
937
- *
938
- * @throws Error if request fails
939
- */
940
- )
941
- }, {
942
- key: "enableTimeFeatureType",
943
- value: (function () {
944
- var _enableTimeFeatureType = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee13(workspace, dataStore, name, attribute, presentation, resolution, defaultValue, nearestMatchEnabled, rawNearestMatchEnabled, acceptableInterval) {
945
- var body, url, response, geoServerResponse;
946
- return _regenerator["default"].wrap(function (_context13) {
947
- while (1) switch (_context13.prev = _context13.next) {
948
- case 0:
949
- body = {
950
- featureType: {
951
- metadata: {
952
- entry: [{
953
- '@key': 'time',
954
- dimensionInfo: {
955
- attribute: attribute,
956
- presentation: presentation,
957
- resolution: resolution,
958
- units: 'ISO8601',
959
- defaultValue: {
960
- strategy: defaultValue
961
- },
962
- nearestMatchEnabled: nearestMatchEnabled,
963
- rawNearestMatchEnabled: rawNearestMatchEnabled,
964
- acceptableInterval: acceptableInterval
965
- }
966
- }]
967
- }
968
- }
969
- };
970
- url = this.url + 'workspaces/' + workspace + '/datastores/' + dataStore + '/featuretypes/' + name + '.json';
971
- _context13.next = 1;
972
- return (0, _nodeFetch["default"])(url, {
973
- credentials: 'include',
974
- method: 'PUT',
975
- headers: {
976
- Authorization: this.auth,
977
- 'Content-Type': 'application/json'
978
- },
979
- body: JSON.stringify(body)
980
- });
981
- case 1:
982
- response = _context13.sent;
983
- if (response.ok) {
984
- _context13.next = 3;
985
- break;
986
- }
987
- _context13.next = 2;
988
- return (0, _geoserver.getGeoServerResponseText)(response);
989
- case 2:
990
- geoServerResponse = _context13.sent;
991
- throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
992
- case 3:
993
- case "end":
994
- return _context13.stop();
995
- }
996
- }, _callee13, this);
997
- }));
998
- function enableTimeFeatureType(_x62, _x63, _x64, _x65, _x66, _x67, _x68, _x69, _x70, _x71) {
999
- return _enableTimeFeatureType.apply(this, arguments);
640
+ });
641
+ if (!response.ok) {
642
+ const grc = new _about.default(this.url, this.auth);
643
+ if (await grc.exists()) {
644
+ // GeoServer exists, but requested item does not exist, we return empty
645
+ return;
646
+ } else {
647
+ // There was a general problem with GeoServer
648
+ const geoServerResponse = await (0, _geoserver.getGeoServerResponseText)(response);
649
+ throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
1000
650
  }
1001
- return enableTimeFeatureType;
1002
- }()
1003
- /**
1004
- * Returns a dedicated coverage object.
1005
- *
1006
- * @param {String} workspace Workspace containing the coverage
1007
- * @param {String} coverageStore The coveragestore containing the coverage
1008
- * @param {String} name Coverage to query
1009
- *
1010
- * @throws Error if request fails
1011
- *
1012
- * @returns {Object} An object with coverage information or undefined if it cannot be found
1013
- */
1014
- )
1015
- }, {
1016
- key: "getCoverage",
1017
- value: (function () {
1018
- var _getCoverage = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee14(workspace, coverageStore, name) {
1019
- var url, response, grc, geoServerResponse;
1020
- return _regenerator["default"].wrap(function (_context14) {
1021
- while (1) switch (_context14.prev = _context14.next) {
1022
- case 0:
1023
- url = this.url + 'workspaces/' + workspace + '/coveragestores/' + coverageStore + '/coverages/' + name + '.json';
1024
- _context14.next = 1;
1025
- return (0, _nodeFetch["default"])(url, {
1026
- credentials: 'include',
1027
- method: 'GET',
1028
- headers: {
1029
- Authorization: this.auth
1030
- }
1031
- });
1032
- case 1:
1033
- response = _context14.sent;
1034
- if (response.ok) {
1035
- _context14.next = 5;
1036
- break;
1037
- }
1038
- grc = new _about["default"](this.url, this.auth);
1039
- _context14.next = 2;
1040
- return grc.exists();
1041
- case 2:
1042
- if (!_context14.sent) {
1043
- _context14.next = 3;
1044
- break;
1045
- }
1046
- return _context14.abrupt("return");
1047
- case 3:
1048
- _context14.next = 4;
1049
- return (0, _geoserver.getGeoServerResponseText)(response);
1050
- case 4:
1051
- geoServerResponse = _context14.sent;
1052
- throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
1053
- case 5:
1054
- return _context14.abrupt("return", response.json());
1055
- case 6:
1056
- case "end":
1057
- return _context14.stop();
1058
- }
1059
- }, _callee14, this);
1060
- }));
1061
- function getCoverage(_x72, _x73, _x74) {
1062
- return _getCoverage.apply(this, arguments);
651
+ }
652
+ return response.json();
653
+ }
654
+
655
+ /**
656
+ * Renames the existing bands of a coverage layer.
657
+ *
658
+ * Make sure to provide the same number of bands as existing in the layer.
659
+ *
660
+ * @param {String} workspace Workspace of layer
661
+ * @param {String} datastore The datastore of the layer
662
+ * @param {String} layername The layer name
663
+ * @param {String[]} bandNames An array of the new band names in correct order
664
+ *
665
+ * @throws Error if request fails
666
+ */
667
+ async renameCoverageBands(workspace, dataStore, layername, bandNames) {
668
+ const body = {
669
+ coverage: {
670
+ dimensions: {
671
+ coverageDimension: []
672
+ }
1063
673
  }
1064
- return getCoverage;
1065
- }()
1066
- /**
1067
- * Returns a dedicated coverage object.
1068
- *
1069
- * @param {String} workspace Workspace containing the coverage
1070
- * @param {String} name Coverage to query
1071
- *
1072
- * @throws Error if request fails
1073
- *
1074
- * @returns {Object} An object with coverage information or undefined if it cannot be found
1075
- */
1076
- )
1077
- }, {
1078
- key: "getCoverageFromLayer",
1079
- value: (function () {
1080
- var _getCoverageFromLayer = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee15(workspace, name) {
1081
- var url, response, grc, geoServerResponse;
1082
- return _regenerator["default"].wrap(function (_context15) {
1083
- while (1) switch (_context15.prev = _context15.next) {
1084
- case 0:
1085
- url = this.url + '/workspaces/' + workspace + '/coverages/' + name + '.json';
1086
- _context15.next = 1;
1087
- return (0, _nodeFetch["default"])(url, {
1088
- credentials: 'include',
1089
- method: 'GET',
1090
- headers: {
1091
- Authorization: this.auth
1092
- }
1093
- });
1094
- case 1:
1095
- response = _context15.sent;
1096
- if (response.ok) {
1097
- _context15.next = 5;
1098
- break;
1099
- }
1100
- grc = new _about["default"](this.url, this.auth);
1101
- _context15.next = 2;
1102
- return grc.exists();
1103
- case 2:
1104
- if (!_context15.sent) {
1105
- _context15.next = 3;
1106
- break;
1107
- }
1108
- return _context15.abrupt("return");
1109
- case 3:
1110
- _context15.next = 4;
1111
- return (0, _geoserver.getGeoServerResponseText)(response);
1112
- case 4:
1113
- geoServerResponse = _context15.sent;
1114
- throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
1115
- case 5:
1116
- return _context15.abrupt("return", response.json());
1117
- case 6:
1118
- case "end":
1119
- return _context15.stop();
1120
- }
1121
- }, _callee15, this);
1122
- }));
1123
- function getCoverageFromLayer(_x75, _x76) {
1124
- return _getCoverageFromLayer.apply(this, arguments);
674
+ };
675
+
676
+ // dynamically create the body
677
+ bandNames.forEach(bandName => {
678
+ body.coverage.dimensions.coverageDimension.push({
679
+ name: bandName
680
+ });
681
+ });
682
+ const url = this.url + 'workspaces/' + workspace + '/coveragestores/' + dataStore + '/coverages/' + layername + '.json';
683
+ const response = await (0, _nodeFetch.default)(url, {
684
+ credentials: 'include',
685
+ method: 'PUT',
686
+ headers: {
687
+ Authorization: this.auth,
688
+ 'Content-Type': 'application/json'
689
+ },
690
+ body: JSON.stringify(body)
691
+ });
692
+ if (!response.ok) {
693
+ const geoServerResponse = await (0, _geoserver.getGeoServerResponseText)(response);
694
+ throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
695
+ }
696
+ }
697
+
698
+ /**
699
+ * Returns the data store of a layer.
700
+ *
701
+ * @param {String} workspace The workspace of the layer
702
+ * @param {String} layer The name of the layer
703
+ *
704
+ * @throws GeoServerResponseError if request fails or layer does not exist or lacks a data store.
705
+ *
706
+ * @returns {Object} The data store object
707
+ */
708
+ async getDataStore(workspace, layer) {
709
+ const featureTypeObj = await this.getFeatureTypeFromLayer(workspace, layer);
710
+ if (!featureTypeObj || !featureTypeObj.featureType || !featureTypeObj.featureType.store || !featureTypeObj.featureType.store.name) {
711
+ throw new _geoserver.GeoServerResponseError(`Layer '${workspace}:${layer}' lacks a feature type or the feature type lacks a data store.`);
712
+ }
713
+ const url = featureTypeObj?.featureType?.store?.href;
714
+ const response = await (0, _nodeFetch.default)(url, {
715
+ credentials: 'include',
716
+ method: 'GET',
717
+ headers: {
718
+ Authorization: this.auth
1125
719
  }
1126
- return getCoverageFromLayer;
1127
- }()
1128
- /**
1129
- * Renames the existing bands of a coverage layer.
1130
- *
1131
- * Make sure to provide the same number of bands as existing in the layer.
1132
- *
1133
- * @param {String} workspace Workspace of layer
1134
- * @param {String} datastore The datastore of the layer
1135
- * @param {String} layername The layer name
1136
- * @param {String[]} bandNames An array of the new band names in correct order
1137
- *
1138
- * @throws Error if request fails
1139
- */
1140
- )
1141
- }, {
1142
- key: "renameCoverageBands",
1143
- value: (function () {
1144
- var _renameCoverageBands = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee16(workspace, dataStore, layername, bandNames) {
1145
- var body, url, response, geoServerResponse;
1146
- return _regenerator["default"].wrap(function (_context16) {
1147
- while (1) switch (_context16.prev = _context16.next) {
1148
- case 0:
1149
- body = {
1150
- coverage: {
1151
- dimensions: {
1152
- coverageDimension: []
1153
- }
1154
- }
1155
- }; // dynamically create the body
1156
- bandNames.forEach(function (bandName) {
1157
- body.coverage.dimensions.coverageDimension.push({
1158
- name: bandName
1159
- });
1160
- });
1161
- url = this.url + 'workspaces/' + workspace + '/coveragestores/' + dataStore + '/coverages/' + layername + '.json';
1162
- _context16.next = 1;
1163
- return (0, _nodeFetch["default"])(url, {
1164
- credentials: 'include',
1165
- method: 'PUT',
1166
- headers: {
1167
- Authorization: this.auth,
1168
- 'Content-Type': 'application/json'
1169
- },
1170
- body: JSON.stringify(body)
1171
- });
1172
- case 1:
1173
- response = _context16.sent;
1174
- if (response.ok) {
1175
- _context16.next = 3;
1176
- break;
1177
- }
1178
- _context16.next = 2;
1179
- return (0, _geoserver.getGeoServerResponseText)(response);
1180
- case 2:
1181
- geoServerResponse = _context16.sent;
1182
- throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
1183
- case 3:
1184
- case "end":
1185
- return _context16.stop();
1186
- }
1187
- }, _callee16, this);
1188
- }));
1189
- function renameCoverageBands(_x77, _x78, _x79, _x80) {
1190
- return _renameCoverageBands.apply(this, arguments);
720
+ });
721
+ if (!response.ok) {
722
+ const grc = new _about.default(this.url, this.auth);
723
+ if (await grc.exists()) {
724
+ // GeoServer exists, but requested item does not exist, we return empty
725
+ return;
726
+ } else {
727
+ // There was a general problem with GeoServer
728
+ const geoServerResponse = await (0, _geoserver.getGeoServerResponseText)(response);
729
+ throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
1191
730
  }
1192
- return renameCoverageBands;
1193
- }()
1194
- /**
1195
- * Returns the data store of a layer.
1196
- *
1197
- * @param {String} workspace The workspace of the layer
1198
- * @param {String} layer The name of the layer
1199
- *
1200
- * @throws GeoServerResponseError if request fails or layer does not exist or lacks a data store.
1201
- *
1202
- * @returns {Object} The data store object
1203
- */
1204
- )
1205
- }, {
1206
- key: "getDataStore",
1207
- value: (function () {
1208
- var _getDataStore = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee17(workspace, layer) {
1209
- var _featureTypeObj$featu;
1210
- var featureTypeObj, url, response, grc, geoServerResponse;
1211
- return _regenerator["default"].wrap(function (_context17) {
1212
- while (1) switch (_context17.prev = _context17.next) {
1213
- case 0:
1214
- _context17.next = 1;
1215
- return this.getFeatureTypeFromLayer(workspace, layer);
1216
- case 1:
1217
- featureTypeObj = _context17.sent;
1218
- if (!(!featureTypeObj || !featureTypeObj.featureType || !featureTypeObj.featureType.store || !featureTypeObj.featureType.store.name)) {
1219
- _context17.next = 2;
1220
- break;
1221
- }
1222
- throw new _geoserver.GeoServerResponseError("Layer '".concat(workspace, ":").concat(layer, "' lacks a feature type or the feature type lacks a data store."));
1223
- case 2:
1224
- url = featureTypeObj === null || featureTypeObj === void 0 || (_featureTypeObj$featu = featureTypeObj.featureType) === null || _featureTypeObj$featu === void 0 || (_featureTypeObj$featu = _featureTypeObj$featu.store) === null || _featureTypeObj$featu === void 0 ? void 0 : _featureTypeObj$featu.href;
1225
- _context17.next = 3;
1226
- return (0, _nodeFetch["default"])(url, {
1227
- credentials: 'include',
1228
- method: 'GET',
1229
- headers: {
1230
- Authorization: this.auth
1231
- }
1232
- });
1233
- case 3:
1234
- response = _context17.sent;
1235
- if (response.ok) {
1236
- _context17.next = 7;
1237
- break;
1238
- }
1239
- grc = new _about["default"](this.url, this.auth);
1240
- _context17.next = 4;
1241
- return grc.exists();
1242
- case 4:
1243
- if (!_context17.sent) {
1244
- _context17.next = 5;
1245
- break;
1246
- }
1247
- return _context17.abrupt("return");
1248
- case 5:
1249
- _context17.next = 6;
1250
- return (0, _geoserver.getGeoServerResponseText)(response);
1251
- case 6:
1252
- geoServerResponse = _context17.sent;
1253
- throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
1254
- case 7:
1255
- return _context17.abrupt("return", response.json());
1256
- case 8:
1257
- case "end":
1258
- return _context17.stop();
1259
- }
1260
- }, _callee17, this);
1261
- }));
1262
- function getDataStore(_x81, _x82) {
1263
- return _getDataStore.apply(this, arguments);
731
+ }
732
+ return response.json();
733
+ }
734
+
735
+ /**
736
+ * Returns the coverage store of a layer.
737
+ *
738
+ * @param {String} workspace The workspace of the layer
739
+ * @param {String} layer The name of the layer
740
+ *
741
+ * @throws GeoServerResponseError if request fails or layer does not exist or lacks a coverage store.
742
+ *
743
+ * @returns {Object} The coverage store object
744
+ */
745
+ async getCoverageStore(workspace, layer) {
746
+ const coverageObj = await this.getCoverageFromLayer(workspace, layer);
747
+ if (!coverageObj || !coverageObj.coverage || !coverageObj.coverage.store || !coverageObj.coverage.store.name) {
748
+ throw new _geoserver.GeoServerResponseError(`Layer '${workspace}:${layer}' lacks a coverage or the coverage lacks a coverage store.`);
749
+ }
750
+ const url = coverageObj?.coverage?.store?.href;
751
+ const response = await (0, _nodeFetch.default)(url, {
752
+ credentials: 'include',
753
+ method: 'GET',
754
+ headers: {
755
+ Authorization: this.auth
1264
756
  }
1265
- return getDataStore;
1266
- }()
1267
- /**
1268
- * Returns the coverage store of a layer.
1269
- *
1270
- * @param {String} workspace The workspace of the layer
1271
- * @param {String} layer The name of the layer
1272
- *
1273
- * @throws GeoServerResponseError if request fails or layer does not exist or lacks a coverage store.
1274
- *
1275
- * @returns {Object} The coverage store object
1276
- */
1277
- )
1278
- }, {
1279
- key: "getCoverageStore",
1280
- value: (function () {
1281
- var _getCoverageStore = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee18(workspace, layer) {
1282
- var _coverageObj$coverage;
1283
- var coverageObj, url, response, grc, geoServerResponse;
1284
- return _regenerator["default"].wrap(function (_context18) {
1285
- while (1) switch (_context18.prev = _context18.next) {
1286
- case 0:
1287
- _context18.next = 1;
1288
- return this.getCoverageFromLayer(workspace, layer);
1289
- case 1:
1290
- coverageObj = _context18.sent;
1291
- if (!(!coverageObj || !coverageObj.coverage || !coverageObj.coverage.store || !coverageObj.coverage.store.name)) {
1292
- _context18.next = 2;
1293
- break;
1294
- }
1295
- throw new _geoserver.GeoServerResponseError("Layer '".concat(workspace, ":").concat(layer, "' lacks a coverage or the coverage lacks a coverage store."));
1296
- case 2:
1297
- url = coverageObj === null || coverageObj === void 0 || (_coverageObj$coverage = coverageObj.coverage) === null || _coverageObj$coverage === void 0 || (_coverageObj$coverage = _coverageObj$coverage.store) === null || _coverageObj$coverage === void 0 ? void 0 : _coverageObj$coverage.href;
1298
- _context18.next = 3;
1299
- return (0, _nodeFetch["default"])(url, {
1300
- credentials: 'include',
1301
- method: 'GET',
1302
- headers: {
1303
- Authorization: this.auth
1304
- }
1305
- });
1306
- case 3:
1307
- response = _context18.sent;
1308
- if (response.ok) {
1309
- _context18.next = 7;
1310
- break;
1311
- }
1312
- grc = new _about["default"](this.url, this.auth);
1313
- _context18.next = 4;
1314
- return grc.exists();
1315
- case 4:
1316
- if (!_context18.sent) {
1317
- _context18.next = 5;
1318
- break;
1319
- }
1320
- return _context18.abrupt("return");
1321
- case 5:
1322
- _context18.next = 6;
1323
- return (0, _geoserver.getGeoServerResponseText)(response);
1324
- case 6:
1325
- geoServerResponse = _context18.sent;
1326
- throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
1327
- case 7:
1328
- return _context18.abrupt("return", response.json());
1329
- case 8:
1330
- case "end":
1331
- return _context18.stop();
1332
- }
1333
- }, _callee18, this);
1334
- }));
1335
- function getCoverageStore(_x83, _x84) {
1336
- return _getCoverageStore.apply(this, arguments);
757
+ });
758
+ if (!response.ok) {
759
+ const grc = new _about.default(this.url, this.auth);
760
+ if (await grc.exists()) {
761
+ // GeoServer exists, but requested item does not exist, we return empty
762
+ return;
763
+ } else {
764
+ // There was a general problem with GeoServer
765
+ const geoServerResponse = await (0, _geoserver.getGeoServerResponseText)(response);
766
+ throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
1337
767
  }
1338
- return getCoverageStore;
1339
- }())
1340
- }]);
1341
- }();
768
+ }
769
+ return response.json();
770
+ }
771
+ }
772
+ exports.default = LayerClient;