geoserver-node-client 1.6.1 → 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.
@@ -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 _fs = _interopRequireDefault(require("fs"));
14
10
  var _geoserver = require("./util/geoserver.js");
@@ -18,15 +14,14 @@ var _about = _interopRequireDefault(require("./about.js"));
18
14
  *
19
15
  * @module DatastoreClient
20
16
  */
21
- var DatastoreClient = exports["default"] = /*#__PURE__*/function () {
17
+ class DatastoreClient {
22
18
  /**
23
19
  * Creates a GeoServer REST DatastoreClient instance.
24
20
  *
25
21
  * @param {String} url The URL of the GeoServer REST API endpoint
26
22
  * @param {String} auth The Basic Authentication string
27
23
  */
28
- function DatastoreClient(url, auth) {
29
- (0, _classCallCheck2["default"])(this, DatastoreClient);
24
+ constructor(url, auth) {
30
25
  this.url = url;
31
26
  this.auth = auth;
32
27
  }
@@ -38,955 +33,534 @@ var DatastoreClient = exports["default"] = /*#__PURE__*/function () {
38
33
  *
39
34
  * @returns {Object} An object containing store details
40
35
  */
41
- return (0, _createClass2["default"])(DatastoreClient, [{
42
- key: "getDataStores",
43
- value: (function () {
44
- var _getDataStores = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee(workspace) {
45
- return _regenerator["default"].wrap(function (_context) {
46
- while (1) switch (_context.prev = _context.next) {
47
- case 0:
48
- return _context.abrupt("return", this.getStores(workspace, 'datastores'));
49
- case 1:
50
- case "end":
51
- return _context.stop();
52
- }
53
- }, _callee, this);
54
- }));
55
- function getDataStores(_x) {
56
- return _getDataStores.apply(this, arguments);
57
- }
58
- return getDataStores;
59
- }()
60
- /**
61
- * Get all CoverageStores in a workspace.
62
- *
63
- * @param {String} workspace The workspace to get CoverageStores for
64
- *
65
- * @returns {Object} An object containing store details
66
- */
67
- )
68
- }, {
69
- key: "getCoverageStores",
70
- value: (function () {
71
- var _getCoverageStores = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee2(workspace) {
72
- return _regenerator["default"].wrap(function (_context2) {
73
- while (1) switch (_context2.prev = _context2.next) {
74
- case 0:
75
- return _context2.abrupt("return", this.getStores(workspace, 'coveragestores'));
76
- case 1:
77
- case "end":
78
- return _context2.stop();
79
- }
80
- }, _callee2, this);
81
- }));
82
- function getCoverageStores(_x2) {
83
- return _getCoverageStores.apply(this, arguments);
84
- }
85
- return getCoverageStores;
86
- }()
87
- /**
88
- * Get all WmsStores in a workspace.
89
- *
90
- * @param {String} workspace The workspace to get WmsStores for
91
- *
92
- * @returns {Object} An object containing store details
93
- */
94
- )
95
- }, {
96
- key: "getWmsStores",
97
- value: (function () {
98
- var _getWmsStores = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee3(workspace) {
99
- return _regenerator["default"].wrap(function (_context3) {
100
- while (1) switch (_context3.prev = _context3.next) {
101
- case 0:
102
- return _context3.abrupt("return", this.getStores(workspace, 'wmsstores'));
103
- case 1:
104
- case "end":
105
- return _context3.stop();
106
- }
107
- }, _callee3, this);
108
- }));
109
- function getWmsStores(_x3) {
110
- return _getWmsStores.apply(this, arguments);
111
- }
112
- return getWmsStores;
113
- }()
114
- /**
115
- * Get all WmtsStores in a workspace.
116
- *
117
- * @param {String} workspace The workspace to get WmtsStores for
118
- *
119
- * @returns {Object} An object containing store details
120
- */
121
- )
122
- }, {
123
- key: "getWmtsStores",
124
- value: (function () {
125
- var _getWmtsStores = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee4(workspace) {
126
- return _regenerator["default"].wrap(function (_context4) {
127
- while (1) switch (_context4.prev = _context4.next) {
128
- case 0:
129
- return _context4.abrupt("return", this.getStores(workspace, 'wmtsstores'));
130
- case 1:
131
- case "end":
132
- return _context4.stop();
133
- }
134
- }, _callee4, this);
135
- }));
136
- function getWmtsStores(_x4) {
137
- return _getWmtsStores.apply(this, arguments);
138
- }
139
- return getWmtsStores;
140
- }()
141
- /**
142
- * Get information about various store types in a workspace.
143
- *
144
- * @param {String} workspace The workspace name
145
- * @param {String} storeType The type of store
146
- *
147
- * @throws Error if request fails
148
- *
149
- * @returns {Object} An object containing store details or undefined if it cannot be found
150
- * @private
151
- */
152
- )
153
- }, {
154
- key: "getStores",
155
- value: (function () {
156
- var _getStores = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee5(workspace, storeType) {
157
- var response, geoServerResponse;
158
- return _regenerator["default"].wrap(function (_context5) {
159
- while (1) switch (_context5.prev = _context5.next) {
160
- case 0:
161
- _context5.next = 1;
162
- return (0, _nodeFetch["default"])(this.url + 'workspaces/' + workspace + '/' + storeType + '.json', {
163
- credentials: 'include',
164
- method: 'GET',
165
- headers: {
166
- Authorization: this.auth
167
- }
168
- });
169
- case 1:
170
- response = _context5.sent;
171
- if (response.ok) {
172
- _context5.next = 3;
173
- break;
174
- }
175
- _context5.next = 2;
176
- return (0, _geoserver.getGeoServerResponseText)(response);
177
- case 2:
178
- geoServerResponse = _context5.sent;
179
- throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
180
- case 3:
181
- return _context5.abrupt("return", response.json());
182
- case 4:
183
- case "end":
184
- return _context5.stop();
185
- }
186
- }, _callee5, this);
187
- }));
188
- function getStores(_x5, _x6) {
189
- return _getStores.apply(this, arguments);
190
- }
191
- return getStores;
192
- }()
193
- /**
194
- * Get specific DataStore by name in a workspace.
195
- *
196
- * @param {String} workspace The workspace to search DataStore in
197
- * @param {String} dataStore DataStore name
198
- *
199
- * @returns {Object} An object containing store details or undefined if it cannot be found
200
- */
201
- )
202
- }, {
203
- key: "getDataStore",
204
- value: (function () {
205
- var _getDataStore = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee6(workspace, dataStore) {
206
- return _regenerator["default"].wrap(function (_context6) {
207
- while (1) switch (_context6.prev = _context6.next) {
208
- case 0:
209
- return _context6.abrupt("return", this.getStore(workspace, dataStore, 'datastores'));
210
- case 1:
211
- case "end":
212
- return _context6.stop();
213
- }
214
- }, _callee6, this);
215
- }));
216
- function getDataStore(_x7, _x8) {
217
- return _getDataStore.apply(this, arguments);
218
- }
219
- return getDataStore;
220
- }()
221
- /**
222
- * Get specific CoverageStore by name in a workspace.
223
- *
224
- * @param {String} workspace The workspace to search CoverageStore in
225
- * @param {String} covStore CoverageStore name
226
- *
227
- * @returns {Object} An object containing store details or undefined if it cannot be found
228
- */
229
- )
230
- }, {
231
- key: "getCoverageStore",
232
- value: (function () {
233
- var _getCoverageStore = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee7(workspace, covStore) {
234
- return _regenerator["default"].wrap(function (_context7) {
235
- while (1) switch (_context7.prev = _context7.next) {
236
- case 0:
237
- return _context7.abrupt("return", this.getStore(workspace, covStore, 'coveragestores'));
238
- case 1:
239
- case "end":
240
- return _context7.stop();
241
- }
242
- }, _callee7, this);
243
- }));
244
- function getCoverageStore(_x9, _x0) {
245
- return _getCoverageStore.apply(this, arguments);
246
- }
247
- return getCoverageStore;
248
- }()
249
- /**
250
- * Get specific WmsStore by name in a workspace.
251
- *
252
- * @param {String} workspace The workspace to search WmsStore in
253
- * @param {String} wmsStore WmsStore name
254
- *
255
- * @returns {Object} An object containing store details or undefined if it cannot be found
256
- *
257
- */
258
- )
259
- }, {
260
- key: "getWmsStore",
261
- value: (function () {
262
- var _getWmsStore = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee8(workspace, wmsStore) {
263
- return _regenerator["default"].wrap(function (_context8) {
264
- while (1) switch (_context8.prev = _context8.next) {
265
- case 0:
266
- return _context8.abrupt("return", this.getStore(workspace, wmsStore, 'wmsstores'));
267
- case 1:
268
- case "end":
269
- return _context8.stop();
270
- }
271
- }, _callee8, this);
272
- }));
273
- function getWmsStore(_x1, _x10) {
274
- return _getWmsStore.apply(this, arguments);
275
- }
276
- return getWmsStore;
277
- }()
278
- /**
279
- * Get specific WmtsStore by name in a workspace.
280
- *
281
- * @param {String} workspace The workspace to search WmtsStore in
282
- * @param {String} wmtsStore WmtsStore name
283
- *
284
- * @returns {Object} An object containing store details or undefined if it cannot be found
285
- */
286
- )
287
- }, {
288
- key: "getWmtsStore",
289
- value: (function () {
290
- var _getWmtsStore = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee9(workspace, wmtsStore) {
291
- return _regenerator["default"].wrap(function (_context9) {
292
- while (1) switch (_context9.prev = _context9.next) {
293
- case 0:
294
- return _context9.abrupt("return", this.getStore(workspace, wmtsStore, 'wmtsstores'));
295
- case 1:
296
- case "end":
297
- return _context9.stop();
298
- }
299
- }, _callee9, this);
300
- }));
301
- function getWmtsStore(_x11, _x12) {
302
- return _getWmtsStore.apply(this, arguments);
303
- }
304
- return getWmtsStore;
305
- }()
306
- /**
307
- * Get GeoServer store by type
308
- *
309
- * @param {String} workspace The name of the workspace
310
- * @param {String} storeName The name of the store
311
- * @param {String} storeType The type of the store
312
- *
313
- * @throws Error if request fails
314
- *
315
- * @returns {Object} An object containing store details or undefined if it cannot be found
316
- * @private
317
- */
318
- )
319
- }, {
320
- key: "getStore",
321
- value: (function () {
322
- var _getStore = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee0(workspace, storeName, storeType) {
323
- var url, response, grc, geoServerResponse;
324
- return _regenerator["default"].wrap(function (_context0) {
325
- while (1) switch (_context0.prev = _context0.next) {
326
- case 0:
327
- url = this.url + 'workspaces/' + workspace + '/' + storeType + '/' + storeName + '.json';
328
- _context0.next = 1;
329
- return (0, _nodeFetch["default"])(url, {
330
- credentials: 'include',
331
- method: 'GET',
332
- headers: {
333
- Authorization: this.auth
334
- }
335
- });
336
- case 1:
337
- response = _context0.sent;
338
- if (response.ok) {
339
- _context0.next = 5;
340
- break;
341
- }
342
- grc = new _about["default"](this.url, this.auth);
343
- _context0.next = 2;
344
- return grc.exists();
345
- case 2:
346
- if (!_context0.sent) {
347
- _context0.next = 3;
348
- break;
349
- }
350
- return _context0.abrupt("return");
351
- case 3:
352
- _context0.next = 4;
353
- return (0, _geoserver.getGeoServerResponseText)(response);
354
- case 4:
355
- geoServerResponse = _context0.sent;
356
- throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
357
- case 5:
358
- return _context0.abrupt("return", response.json());
359
- case 6:
360
- case "end":
361
- return _context0.stop();
362
- }
363
- }, _callee0, this);
364
- }));
365
- function getStore(_x13, _x14, _x15) {
366
- return _getStore.apply(this, arguments);
36
+ async getDataStores(workspace) {
37
+ return this.getStores(workspace, 'datastores');
38
+ }
39
+
40
+ /**
41
+ * Get all CoverageStores in a workspace.
42
+ *
43
+ * @param {String} workspace The workspace to get CoverageStores for
44
+ *
45
+ * @returns {Object} An object containing store details
46
+ */
47
+ async getCoverageStores(workspace) {
48
+ return this.getStores(workspace, 'coveragestores');
49
+ }
50
+
51
+ /**
52
+ * Get all WmsStores in a workspace.
53
+ *
54
+ * @param {String} workspace The workspace to get WmsStores for
55
+ *
56
+ * @returns {Object} An object containing store details
57
+ */
58
+ async getWmsStores(workspace) {
59
+ return this.getStores(workspace, 'wmsstores');
60
+ }
61
+
62
+ /**
63
+ * Get all WmtsStores in a workspace.
64
+ *
65
+ * @param {String} workspace The workspace to get WmtsStores for
66
+ *
67
+ * @returns {Object} An object containing store details
68
+ */
69
+ async getWmtsStores(workspace) {
70
+ return this.getStores(workspace, 'wmtsstores');
71
+ }
72
+
73
+ /**
74
+ * Get information about various store types in a workspace.
75
+ *
76
+ * @param {String} workspace The workspace name
77
+ * @param {String} storeType The type of store
78
+ *
79
+ * @throws Error if request fails
80
+ *
81
+ * @returns {Object} An object containing store details or undefined if it cannot be found
82
+ * @private
83
+ */
84
+ async getStores(workspace, storeType) {
85
+ const response = await (0, _nodeFetch.default)(this.url + 'workspaces/' + workspace + '/' + storeType + '.json', {
86
+ credentials: 'include',
87
+ method: 'GET',
88
+ headers: {
89
+ Authorization: this.auth
367
90
  }
368
- return getStore;
369
- }()
370
- /**
371
- * Creates a GeoTIFF store from a file by path and publishes it as layer.
372
- * The GeoTIFF file has to be placed on the server, where your GeoServer
373
- * is running.
374
- *
375
- * @param {String} workspace The workspace to create GeoTIFF store in
376
- * @param {String} coverageStore The name of the new GeoTIFF store
377
- * @param {String} layerName The published name of the new layer
378
- * @param {String} layerTitle The published title of the new layer
379
- * @param {String} filePath The path to the GeoTIFF file on the server
380
- *
381
- * @throws Error if request fails
382
- *
383
- * @returns {String} The successful response text
384
- */
385
- )
386
- }, {
387
- key: "createGeotiffFromFile",
388
- value: (function () {
389
- var _createGeotiffFromFile = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee1(workspace, coverageStore, layerName, layerTitle, filePath) {
390
- var stats, fileSizeInBytes, readStream;
391
- return _regenerator["default"].wrap(function (_context1) {
392
- while (1) switch (_context1.prev = _context1.next) {
393
- case 0:
394
- stats = _fs["default"].statSync(filePath);
395
- fileSizeInBytes = stats.size;
396
- readStream = _fs["default"].createReadStream(filePath);
397
- return _context1.abrupt("return", this.createGeotiffFromStream(workspace, coverageStore, layerName, layerTitle, readStream, fileSizeInBytes));
398
- case 1:
399
- case "end":
400
- return _context1.stop();
401
- }
402
- }, _callee1, this);
403
- }));
404
- function createGeotiffFromFile(_x16, _x17, _x18, _x19, _x20) {
405
- return _createGeotiffFromFile.apply(this, arguments);
91
+ });
92
+ if (!response.ok) {
93
+ const geoServerResponse = await (0, _geoserver.getGeoServerResponseText)(response);
94
+ throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
95
+ }
96
+ return response.json();
97
+ }
98
+
99
+ /**
100
+ * Get specific DataStore by name in a workspace.
101
+ *
102
+ * @param {String} workspace The workspace to search DataStore in
103
+ * @param {String} dataStore DataStore name
104
+ *
105
+ * @returns {Object} An object containing store details or undefined if it cannot be found
106
+ */
107
+ async getDataStore(workspace, dataStore) {
108
+ return this.getStore(workspace, dataStore, 'datastores');
109
+ }
110
+
111
+ /**
112
+ * Get specific CoverageStore by name in a workspace.
113
+ *
114
+ * @param {String} workspace The workspace to search CoverageStore in
115
+ * @param {String} covStore CoverageStore name
116
+ *
117
+ * @returns {Object} An object containing store details or undefined if it cannot be found
118
+ */
119
+ async getCoverageStore(workspace, covStore) {
120
+ return this.getStore(workspace, covStore, 'coveragestores');
121
+ }
122
+
123
+ /**
124
+ * Get specific WmsStore by name in a workspace.
125
+ *
126
+ * @param {String} workspace The workspace to search WmsStore in
127
+ * @param {String} wmsStore WmsStore name
128
+ *
129
+ * @returns {Object} An object containing store details or undefined if it cannot be found
130
+ *
131
+ */
132
+ async getWmsStore(workspace, wmsStore) {
133
+ return this.getStore(workspace, wmsStore, 'wmsstores');
134
+ }
135
+
136
+ /**
137
+ * Get specific WmtsStore by name in a workspace.
138
+ *
139
+ * @param {String} workspace The workspace to search WmtsStore in
140
+ * @param {String} wmtsStore WmtsStore name
141
+ *
142
+ * @returns {Object} An object containing store details or undefined if it cannot be found
143
+ */
144
+ async getWmtsStore(workspace, wmtsStore) {
145
+ return this.getStore(workspace, wmtsStore, 'wmtsstores');
146
+ }
147
+
148
+ /**
149
+ * Get GeoServer store by type
150
+ *
151
+ * @param {String} workspace The name of the workspace
152
+ * @param {String} storeName The name of the store
153
+ * @param {String} storeType The type of the store
154
+ *
155
+ * @throws Error if request fails
156
+ *
157
+ * @returns {Object} An object containing store details or undefined if it cannot be found
158
+ * @private
159
+ */
160
+ async getStore(workspace, storeName, storeType) {
161
+ const url = this.url + 'workspaces/' + workspace + '/' + storeType + '/' + storeName + '.json';
162
+ const response = await (0, _nodeFetch.default)(url, {
163
+ credentials: 'include',
164
+ method: 'GET',
165
+ headers: {
166
+ Authorization: this.auth
406
167
  }
407
- return createGeotiffFromFile;
408
- }()
409
- /**
410
- * Creates a GeoTIFF store from a file by stream and publishes it as layer.
411
- * The GeoTIFF file is placed on the server, where your GeoServer
412
- * is running.
413
- *
414
- * @param {String} workspace The workspace to create GeoTIFF store in
415
- * @param {String} coverageStore The name of the new GeoTIFF store
416
- * @param {String} layerName The published name of the new layer
417
- * @param {String} layerTitle The published title of the new layer
418
- * @param {Stream} readStream The stream of the GeoTIFF file
419
- * @param {Number} fileSizeInBytes The number of bytes of the stream
420
- *
421
- * @throws Error if request fails
422
- *
423
- * @returns {String} The successful response text
424
- */
425
- )
426
- }, {
427
- key: "createGeotiffFromStream",
428
- value: (function () {
429
- var _createGeotiffFromStream = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee10(workspace, coverageStore, layerName, layerTitle, readStream, fileSizeInBytes) {
430
- var lyrTitle, url, response, geoServerResponse;
431
- return _regenerator["default"].wrap(function (_context10) {
432
- while (1) switch (_context10.prev = _context10.next) {
433
- case 0:
434
- lyrTitle = layerTitle || layerName;
435
- url = this.url + 'workspaces/' + workspace + '/coveragestores/' + coverageStore + '/file.geotiff';
436
- url += '?filename=' + lyrTitle + '&coverageName=' + layerName;
437
- _context10.next = 1;
438
- return (0, _nodeFetch["default"])(url, {
439
- credentials: 'include',
440
- method: 'PUT',
441
- headers: {
442
- Authorization: this.auth,
443
- 'Content-Type': 'image/tiff',
444
- 'Content-length': fileSizeInBytes
445
- },
446
- body: readStream
447
- });
448
- case 1:
449
- response = _context10.sent;
450
- if (response.ok) {
451
- _context10.next = 3;
452
- break;
453
- }
454
- _context10.next = 2;
455
- return (0, _geoserver.getGeoServerResponseText)(response);
456
- case 2:
457
- geoServerResponse = _context10.sent;
458
- throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
459
- case 3:
460
- return _context10.abrupt("return", response.text());
461
- case 4:
462
- case "end":
463
- return _context10.stop();
464
- }
465
- }, _callee10, this);
466
- }));
467
- function createGeotiffFromStream(_x21, _x22, _x23, _x24, _x25, _x26) {
468
- return _createGeotiffFromStream.apply(this, arguments);
168
+ });
169
+ if (!response.ok) {
170
+ const grc = new _about.default(this.url, this.auth);
171
+ if (await grc.exists()) {
172
+ // GeoServer exists, but requested item does not exist, we return empty
173
+ return;
174
+ } else {
175
+ // There was a general problem with GeoServer
176
+ const geoServerResponse = await (0, _geoserver.getGeoServerResponseText)(response);
177
+ throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
469
178
  }
470
- return createGeotiffFromStream;
471
- }()
472
- /**
473
- * Creates a PostGIS based data store.
474
- *
475
- * @param {String} workspace The WS to create the data store in
476
- * @param {String} namespaceUri The namespace URI of the workspace
477
- * @param {String} dataStore The data store name to be created
478
- * @param {String} pgHost The PostGIS DB host
479
- * @param {Number} pgPort The PostGIS DB port
480
- * @param {String} pgUser The PostGIS DB user
481
- * @param {String} pgPassword The PostGIS DB password
482
- * @param {String} pgSchema The PostGIS DB schema
483
- * @param {String} pgDb The PostGIS DB name
484
- * @param {Boolean} [exposePk] expose primary key, defaults to false
485
- *
486
- * @throws Error if request fails
487
- */
488
- )
489
- }, {
490
- key: "createPostgisStore",
491
- value: (function () {
492
- var _createPostgisStore = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee11(workspace, namespaceUri, dataStore, pgHost, pgPort, pgUser, pgPassword, pgSchema, pgDb, exposePk) {
493
- var body, url, response, geoServerResponse;
494
- return _regenerator["default"].wrap(function (_context11) {
495
- while (1) switch (_context11.prev = _context11.next) {
496
- case 0:
497
- body = {
498
- dataStore: {
499
- name: dataStore,
500
- type: 'PostGIS',
501
- enabled: true,
502
- workspace: {
503
- name: workspace
504
- },
505
- connectionParameters: {
506
- entry: [{
507
- '@key': 'dbtype',
508
- $: 'postgis'
509
- }, {
510
- '@key': 'schema',
511
- $: pgSchema
512
- }, {
513
- '@key': 'database',
514
- $: pgDb
515
- }, {
516
- '@key': 'host',
517
- $: pgHost
518
- }, {
519
- '@key': 'port',
520
- $: pgPort
521
- }, {
522
- '@key': 'passwd',
523
- $: pgPassword
524
- }, {
525
- '@key': 'namespace',
526
- $: namespaceUri
527
- }, {
528
- '@key': 'user',
529
- $: pgUser
530
- }, {
531
- '@key': 'Expose primary keys',
532
- $: exposePk || false
533
- }]
534
- }
535
- }
536
- };
537
- url = this.url + 'workspaces/' + workspace + '/datastores';
538
- _context11.next = 1;
539
- return (0, _nodeFetch["default"])(url, {
540
- credentials: 'include',
541
- method: 'POST',
542
- headers: {
543
- Authorization: this.auth,
544
- 'Content-Type': 'application/json'
545
- },
546
- body: JSON.stringify(body)
547
- });
548
- case 1:
549
- response = _context11.sent;
550
- if (response.ok) {
551
- _context11.next = 3;
552
- break;
553
- }
554
- _context11.next = 2;
555
- return (0, _geoserver.getGeoServerResponseText)(response);
556
- case 2:
557
- geoServerResponse = _context11.sent;
558
- throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
559
- case 3:
560
- case "end":
561
- return _context11.stop();
562
- }
563
- }, _callee11, this);
564
- }));
565
- function createPostgisStore(_x27, _x28, _x29, _x30, _x31, _x32, _x33, _x34, _x35, _x36) {
566
- return _createPostgisStore.apply(this, arguments);
179
+ }
180
+ return response.json();
181
+ }
182
+
183
+ /**
184
+ * Creates a GeoTIFF store from a file by path and publishes it as layer.
185
+ * The GeoTIFF file has to be placed on the server, where your GeoServer
186
+ * is running.
187
+ *
188
+ * @param {String} workspace The workspace to create GeoTIFF store in
189
+ * @param {String} coverageStore The name of the new GeoTIFF store
190
+ * @param {String} layerName The published name of the new layer
191
+ * @param {String} layerTitle The published title of the new layer
192
+ * @param {String} filePath The path to the GeoTIFF file on the server
193
+ *
194
+ * @throws Error if request fails
195
+ *
196
+ * @returns {String} The successful response text
197
+ */
198
+ async createGeotiffFromFile(workspace, coverageStore, layerName, layerTitle, filePath) {
199
+ const stats = _fs.default.statSync(filePath);
200
+ const fileSizeInBytes = stats.size;
201
+ const readStream = _fs.default.createReadStream(filePath);
202
+ return this.createGeotiffFromStream(workspace, coverageStore, layerName, layerTitle, readStream, fileSizeInBytes);
203
+ }
204
+
205
+ /**
206
+ * Creates a GeoTIFF store from a file by stream and publishes it as layer.
207
+ * The GeoTIFF file is placed on the server, where your GeoServer
208
+ * is running.
209
+ *
210
+ * @param {String} workspace The workspace to create GeoTIFF store in
211
+ * @param {String} coverageStore The name of the new GeoTIFF store
212
+ * @param {String} layerName The published name of the new layer
213
+ * @param {String} layerTitle The published title of the new layer
214
+ * @param {Stream} readStream The stream of the GeoTIFF file
215
+ * @param {Number} fileSizeInBytes The number of bytes of the stream
216
+ *
217
+ * @throws Error if request fails
218
+ *
219
+ * @returns {String} The successful response text
220
+ */
221
+ async createGeotiffFromStream(workspace, coverageStore, layerName, layerTitle, readStream, fileSizeInBytes) {
222
+ const lyrTitle = layerTitle || layerName;
223
+ let url = this.url + 'workspaces/' + workspace + '/coveragestores/' + coverageStore + '/file.geotiff';
224
+ url += '?filename=' + lyrTitle + '&coverageName=' + layerName;
225
+ const response = await (0, _nodeFetch.default)(url, {
226
+ credentials: 'include',
227
+ method: 'PUT',
228
+ headers: {
229
+ Authorization: this.auth,
230
+ 'Content-Type': 'image/tiff',
231
+ 'Content-length': fileSizeInBytes
232
+ },
233
+ body: readStream
234
+ });
235
+ if (!response.ok) {
236
+ const geoServerResponse = await (0, _geoserver.getGeoServerResponseText)(response);
237
+ throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
238
+ }
239
+ // TODO: enforce JSON response or parse XML
240
+ return response.text();
241
+ }
242
+
243
+ /**
244
+ * Creates a PostGIS based data store.
245
+ *
246
+ * @param {String} workspace The WS to create the data store in
247
+ * @param {String} namespaceUri The namespace URI of the workspace
248
+ * @param {String} dataStore The data store name to be created
249
+ * @param {String} pgHost The PostGIS DB host
250
+ * @param {Number} pgPort The PostGIS DB port
251
+ * @param {String} pgUser The PostGIS DB user
252
+ * @param {String} pgPassword The PostGIS DB password
253
+ * @param {String} pgSchema The PostGIS DB schema
254
+ * @param {String} pgDb The PostGIS DB name
255
+ * @param {Boolean} [exposePk] expose primary key, defaults to false
256
+ *
257
+ * @throws Error if request fails
258
+ */
259
+ async createPostgisStore(workspace, namespaceUri, dataStore, pgHost, pgPort, pgUser, pgPassword, pgSchema, pgDb, exposePk) {
260
+ const body = {
261
+ dataStore: {
262
+ name: dataStore,
263
+ type: 'PostGIS',
264
+ enabled: true,
265
+ workspace: {
266
+ name: workspace
267
+ },
268
+ connectionParameters: {
269
+ entry: [{
270
+ '@key': 'dbtype',
271
+ $: 'postgis'
272
+ }, {
273
+ '@key': 'schema',
274
+ $: pgSchema
275
+ }, {
276
+ '@key': 'database',
277
+ $: pgDb
278
+ }, {
279
+ '@key': 'host',
280
+ $: pgHost
281
+ }, {
282
+ '@key': 'port',
283
+ $: pgPort
284
+ }, {
285
+ '@key': 'passwd',
286
+ $: pgPassword
287
+ }, {
288
+ '@key': 'namespace',
289
+ $: namespaceUri
290
+ }, {
291
+ '@key': 'user',
292
+ $: pgUser
293
+ }, {
294
+ '@key': 'Expose primary keys',
295
+ $: exposePk || false
296
+ }]
297
+ }
567
298
  }
568
- return createPostgisStore;
569
- }()
570
- /**
571
- * Creates an ImageMosaic store from a zip archive with the 3 necessary files
572
- * - datastore.properties
573
- * - indexer.properties
574
- * - timeregex.properties
575
- *
576
- * The zip archive has to be given as absolute path, so before it has to be
577
- * placed on the server, where your GeoServer is running.
578
- *
579
- * @param {String} workspace The WS to create the data store in
580
- * @param {String} dataStore The data store name
581
- * @param {String} zipArchivePath Absolute path to zip archive with the 3 properties files
582
- *
583
- * @throws Error if request fails
584
- *
585
- * @returns {String} The response text
586
- */
587
- )
588
- }, {
589
- key: "createImageMosaicStore",
590
- value: (function () {
591
- var _createImageMosaicStore = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee12(workspace, coverageStore, zipArchivePath) {
592
- var readStream, url, response, geoServerResponse;
593
- return _regenerator["default"].wrap(function (_context12) {
594
- while (1) switch (_context12.prev = _context12.next) {
595
- case 0:
596
- readStream = _fs["default"].createReadStream(zipArchivePath);
597
- url = this.url + 'workspaces/' + workspace + '/coveragestores/' + coverageStore + '/file.imagemosaic';
598
- _context12.next = 1;
599
- return (0, _nodeFetch["default"])(url, {
600
- credentials: 'include',
601
- method: 'PUT',
602
- headers: {
603
- Authorization: this.auth,
604
- 'Content-Type': 'application/zip'
605
- },
606
- body: readStream
607
- });
608
- case 1:
609
- response = _context12.sent;
610
- if (response.ok) {
611
- _context12.next = 3;
612
- break;
613
- }
614
- _context12.next = 2;
615
- return (0, _geoserver.getGeoServerResponseText)(response);
616
- case 2:
617
- geoServerResponse = _context12.sent;
618
- throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
619
- case 3:
620
- return _context12.abrupt("return", response.text());
621
- case 4:
622
- case "end":
623
- return _context12.stop();
624
- }
625
- }, _callee12, this);
626
- }));
627
- function createImageMosaicStore(_x37, _x38, _x39) {
628
- return _createImageMosaicStore.apply(this, arguments);
299
+ };
300
+ const url = this.url + 'workspaces/' + workspace + '/datastores';
301
+ const response = await (0, _nodeFetch.default)(url, {
302
+ credentials: 'include',
303
+ method: 'POST',
304
+ headers: {
305
+ Authorization: this.auth,
306
+ 'Content-Type': 'application/json'
307
+ },
308
+ body: JSON.stringify(body)
309
+ });
310
+
311
+ // TODO: not tested yet
312
+ if (!response.ok) {
313
+ const geoServerResponse = await (0, _geoserver.getGeoServerResponseText)(response);
314
+ throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
315
+ }
316
+ }
317
+
318
+ /**
319
+ * Creates an ImageMosaic store from a zip archive with the 3 necessary files
320
+ * - datastore.properties
321
+ * - indexer.properties
322
+ * - timeregex.properties
323
+ *
324
+ * The zip archive has to be given as absolute path, so before it has to be
325
+ * placed on the server, where your GeoServer is running.
326
+ *
327
+ * @param {String} workspace The WS to create the data store in
328
+ * @param {String} dataStore The data store name
329
+ * @param {String} zipArchivePath Absolute path to zip archive with the 3 properties files
330
+ *
331
+ * @throws Error if request fails
332
+ *
333
+ * @returns {String} The response text
334
+ */
335
+ async createImageMosaicStore(workspace, coverageStore, zipArchivePath) {
336
+ const readStream = _fs.default.createReadStream(zipArchivePath);
337
+ const url = this.url + 'workspaces/' + workspace + '/coveragestores/' + coverageStore + '/file.imagemosaic';
338
+ const response = await (0, _nodeFetch.default)(url, {
339
+ credentials: 'include',
340
+ method: 'PUT',
341
+ headers: {
342
+ Authorization: this.auth,
343
+ 'Content-Type': 'application/zip'
344
+ },
345
+ body: readStream
346
+ });
347
+ if (!response.ok) {
348
+ const geoServerResponse = await (0, _geoserver.getGeoServerResponseText)(response);
349
+ throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
350
+ }
351
+ return response.text();
352
+ }
353
+
354
+ /**
355
+ * Creates a WMS based data store.
356
+ *
357
+ * @param {String} workspace The WS to create the data store in
358
+ * @param {String} dataStore The data store name
359
+ * @param {String} wmsCapabilitiesUrl Base WMS capabilities URL
360
+ *
361
+ * @throws Error if request fails
362
+ */
363
+ async createWmsStore(workspace, dataStore, wmsCapabilitiesUrl) {
364
+ const body = {
365
+ wmsStore: {
366
+ name: dataStore,
367
+ type: 'WMS',
368
+ capabilitiesURL: wmsCapabilitiesUrl
629
369
  }
630
- return createImageMosaicStore;
631
- }()
632
- /**
633
- * Creates a WMS based data store.
634
- *
635
- * @param {String} workspace The WS to create the data store in
636
- * @param {String} dataStore The data store name
637
- * @param {String} wmsCapabilitiesUrl Base WMS capabilities URL
638
- *
639
- * @throws Error if request fails
640
- */
641
- )
642
- }, {
643
- key: "createWmsStore",
644
- value: (function () {
645
- var _createWmsStore = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee13(workspace, dataStore, wmsCapabilitiesUrl) {
646
- var body, url, response, geoServerResponse;
647
- return _regenerator["default"].wrap(function (_context13) {
648
- while (1) switch (_context13.prev = _context13.next) {
649
- case 0:
650
- body = {
651
- wmsStore: {
652
- name: dataStore,
653
- type: 'WMS',
654
- capabilitiesURL: wmsCapabilitiesUrl
655
- }
656
- };
657
- url = this.url + 'workspaces/' + workspace + '/wmsstores';
658
- _context13.next = 1;
659
- return (0, _nodeFetch["default"])(url, {
660
- credentials: 'include',
661
- method: 'POST',
662
- headers: {
663
- Authorization: this.auth,
664
- 'Content-Type': 'application/json'
665
- },
666
- body: JSON.stringify(body)
667
- });
668
- case 1:
669
- response = _context13.sent;
670
- if (response.ok) {
671
- _context13.next = 3;
672
- break;
673
- }
674
- _context13.next = 2;
675
- return (0, _geoserver.getGeoServerResponseText)(response);
676
- case 2:
677
- geoServerResponse = _context13.sent;
678
- throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
679
- case 3:
680
- case "end":
681
- return _context13.stop();
682
- }
683
- }, _callee13, this);
684
- }));
685
- function createWmsStore(_x40, _x41, _x42) {
686
- return _createWmsStore.apply(this, arguments);
370
+ };
371
+ const url = this.url + 'workspaces/' + workspace + '/wmsstores';
372
+ const response = await (0, _nodeFetch.default)(url, {
373
+ credentials: 'include',
374
+ method: 'POST',
375
+ headers: {
376
+ Authorization: this.auth,
377
+ 'Content-Type': 'application/json'
378
+ },
379
+ body: JSON.stringify(body)
380
+ });
381
+ if (!response.ok) {
382
+ const geoServerResponse = await (0, _geoserver.getGeoServerResponseText)(response);
383
+ throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
384
+ }
385
+ }
386
+
387
+ /**
388
+ * Creates a WMTS based data store.
389
+ *
390
+ * @param {String} workspace The WS to create the data store in
391
+ * @param {String} dataStore The data store name
392
+ * @param {String} wmtsCapabilitiesUrl Base WMTS capabilities URL
393
+ *
394
+ * @throws Error if request fails
395
+ */
396
+ async createWmtsStore(workspace, dataStore, wmtsCapabilitiesUrl) {
397
+ const body = {
398
+ wmtsStore: {
399
+ name: dataStore,
400
+ type: 'WMTS',
401
+ capabilitiesURL: wmtsCapabilitiesUrl
687
402
  }
688
- return createWmsStore;
689
- }()
690
- /**
691
- * Creates a WMTS based data store.
692
- *
693
- * @param {String} workspace The WS to create the data store in
694
- * @param {String} dataStore The data store name
695
- * @param {String} wmtsCapabilitiesUrl Base WMTS capabilities URL
696
- *
697
- * @throws Error if request fails
698
- */
699
- )
700
- }, {
701
- key: "createWmtsStore",
702
- value: (function () {
703
- var _createWmtsStore = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee14(workspace, dataStore, wmtsCapabilitiesUrl) {
704
- var body, url, response, geoServerResponse;
705
- return _regenerator["default"].wrap(function (_context14) {
706
- while (1) switch (_context14.prev = _context14.next) {
707
- case 0:
708
- body = {
709
- wmtsStore: {
710
- name: dataStore,
711
- type: 'WMTS',
712
- capabilitiesURL: wmtsCapabilitiesUrl
713
- }
714
- };
715
- url = this.url + 'workspaces/' + workspace + '/wmtsstores';
716
- _context14.next = 1;
717
- return (0, _nodeFetch["default"])(url, {
718
- credentials: 'include',
719
- method: 'POST',
720
- headers: {
721
- Authorization: this.auth,
722
- 'Content-Type': 'application/json'
723
- },
724
- body: JSON.stringify(body)
725
- });
726
- case 1:
727
- response = _context14.sent;
728
- if (response.ok) {
729
- _context14.next = 3;
730
- break;
731
- }
732
- _context14.next = 2;
733
- return (0, _geoserver.getGeoServerResponseText)(response);
734
- case 2:
735
- geoServerResponse = _context14.sent;
736
- throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
737
- case 3:
738
- case "end":
739
- return _context14.stop();
740
- }
741
- }, _callee14, this);
742
- }));
743
- function createWmtsStore(_x43, _x44, _x45) {
744
- return _createWmtsStore.apply(this, arguments);
403
+ };
404
+ const url = this.url + 'workspaces/' + workspace + '/wmtsstores';
405
+ const response = await (0, _nodeFetch.default)(url, {
406
+ credentials: 'include',
407
+ method: 'POST',
408
+ headers: {
409
+ Authorization: this.auth,
410
+ 'Content-Type': 'application/json'
411
+ },
412
+ body: JSON.stringify(body)
413
+ });
414
+ if (!response.ok) {
415
+ const geoServerResponse = await (0, _geoserver.getGeoServerResponseText)(response);
416
+ throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
417
+ }
418
+ }
419
+
420
+ /**
421
+ * Creates a WFS based data store.
422
+ *
423
+ * @param {String} workspace The WS to create the data store in
424
+ * @param {String} dataStore The data store name
425
+ * @param {String} wfsCapabilitiesUrl WFS capabilities URL
426
+ * @param {String} namespaceUrl URL of the GeoServer namespace
427
+ * @param {Boolean} [useHttpConnectionPooling=true] use HTTP connection pooling for WFS connection
428
+ *
429
+ * @throws Error if request fails
430
+ */
431
+ async createWfsStore(workspace, dataStore, wfsCapabilitiesUrl, namespaceUrl, useHttpConnectionPooling) {
432
+ const body = {
433
+ dataStore: {
434
+ name: dataStore,
435
+ type: 'Web Feature Server (NG)',
436
+ connectionParameters: {
437
+ entry: [{
438
+ '@key': 'WFSDataStoreFactory:GET_CAPABILITIES_URL',
439
+ $: wfsCapabilitiesUrl
440
+ }, {
441
+ '@key': 'namespace',
442
+ $: namespaceUrl
443
+ }, {
444
+ '@key': 'WFSDataStoreFactory:USE_HTTP_CONNECTION_POOLING',
445
+ $: useHttpConnectionPooling !== false ? 'true' : 'false'
446
+ }]
447
+ }
745
448
  }
746
- return createWmtsStore;
747
- }()
748
- /**
749
- * Creates a WFS based data store.
750
- *
751
- * @param {String} workspace The WS to create the data store in
752
- * @param {String} dataStore The data store name
753
- * @param {String} wfsCapabilitiesUrl WFS capabilities URL
754
- * @param {String} namespaceUrl URL of the GeoServer namespace
755
- * @param {Boolean} [useHttpConnectionPooling=true] use HTTP connection pooling for WFS connection
756
- *
757
- * @throws Error if request fails
758
- */
759
- )
760
- }, {
761
- key: "createWfsStore",
762
- value: (function () {
763
- var _createWfsStore = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee15(workspace, dataStore, wfsCapabilitiesUrl, namespaceUrl, useHttpConnectionPooling) {
764
- var body, url, response, geoServerResponse;
765
- return _regenerator["default"].wrap(function (_context15) {
766
- while (1) switch (_context15.prev = _context15.next) {
767
- case 0:
768
- body = {
769
- dataStore: {
770
- name: dataStore,
771
- type: 'Web Feature Server (NG)',
772
- connectionParameters: {
773
- entry: [{
774
- '@key': 'WFSDataStoreFactory:GET_CAPABILITIES_URL',
775
- $: wfsCapabilitiesUrl
776
- }, {
777
- '@key': 'namespace',
778
- $: namespaceUrl
779
- }, {
780
- '@key': 'WFSDataStoreFactory:USE_HTTP_CONNECTION_POOLING',
781
- $: useHttpConnectionPooling !== false ? 'true' : 'false'
782
- }]
783
- }
784
- }
785
- };
786
- url = this.url + 'workspaces/' + workspace + '/datastores';
787
- _context15.next = 1;
788
- return (0, _nodeFetch["default"])(url, {
789
- credentials: 'include',
790
- method: 'POST',
791
- headers: {
792
- Authorization: this.auth,
793
- 'Content-Type': 'application/json'
794
- },
795
- body: JSON.stringify(body)
796
- });
797
- case 1:
798
- response = _context15.sent;
799
- if (response.ok) {
800
- _context15.next = 3;
801
- break;
802
- }
803
- _context15.next = 2;
804
- return (0, _geoserver.getGeoServerResponseText)(response);
805
- case 2:
806
- geoServerResponse = _context15.sent;
807
- throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
808
- case 3:
809
- case "end":
810
- return _context15.stop();
811
- }
812
- }, _callee15, this);
813
- }));
814
- function createWfsStore(_x46, _x47, _x48, _x49, _x50) {
815
- return _createWfsStore.apply(this, arguments);
449
+ };
450
+ const url = this.url + 'workspaces/' + workspace + '/datastores';
451
+ const response = await (0, _nodeFetch.default)(url, {
452
+ credentials: 'include',
453
+ method: 'POST',
454
+ headers: {
455
+ Authorization: this.auth,
456
+ 'Content-Type': 'application/json'
457
+ },
458
+ body: JSON.stringify(body)
459
+ });
460
+ if (!response.ok) {
461
+ const geoServerResponse = await (0, _geoserver.getGeoServerResponseText)(response);
462
+ throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
463
+ }
464
+ }
465
+
466
+ /**
467
+ * Deletes a data store.
468
+ *
469
+ * @param {String} workspace The workspace where the data store is in
470
+ * @param {String} coverageStore Name of data store to delete
471
+ * @param {String} recurse Flag to enable recursive deletion
472
+ *
473
+ * @throws Error if request fails
474
+ */
475
+ async deleteDataStore(workspace, dataStore, recurse) {
476
+ let url = this.url + 'workspaces/' + workspace + '/datastores/' + dataStore;
477
+ url += '?recurse=' + recurse;
478
+ const response = await (0, _nodeFetch.default)(url, {
479
+ credentials: 'include',
480
+ method: 'DELETE',
481
+ headers: {
482
+ Authorization: this.auth
816
483
  }
817
- return createWfsStore;
818
- }()
819
- /**
820
- * Deletes a data store.
821
- *
822
- * @param {String} workspace The workspace where the data store is in
823
- * @param {String} coverageStore Name of data store to delete
824
- * @param {String} recurse Flag to enable recursive deletion
825
- *
826
- * @throws Error if request fails
827
- */
828
- )
829
- }, {
830
- key: "deleteDataStore",
831
- value: (function () {
832
- var _deleteDataStore = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee16(workspace, dataStore, recurse) {
833
- var url, response, geoServerResponse;
834
- return _regenerator["default"].wrap(function (_context16) {
835
- while (1) switch (_context16.prev = _context16.next) {
836
- case 0:
837
- url = this.url + 'workspaces/' + workspace + '/datastores/' + dataStore;
838
- url += '?recurse=' + recurse;
839
- _context16.next = 1;
840
- return (0, _nodeFetch["default"])(url, {
841
- credentials: 'include',
842
- method: 'DELETE',
843
- headers: {
844
- Authorization: this.auth
845
- }
846
- });
847
- case 1:
848
- response = _context16.sent;
849
- if (response.ok) {
850
- _context16.next = 3;
851
- break;
852
- }
853
- _context16.next = 2;
854
- return (0, _geoserver.getGeoServerResponseText)(response);
855
- case 2:
856
- geoServerResponse = _context16.sent;
857
- throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
858
- case 3:
859
- case "end":
860
- return _context16.stop();
861
- }
862
- }, _callee16, this);
863
- }));
864
- function deleteDataStore(_x51, _x52, _x53) {
865
- return _deleteDataStore.apply(this, arguments);
484
+ });
485
+ if (!response.ok) {
486
+ // TODO: could not find status codes in the docs or via testing
487
+ // https://docs.geoserver.org/latest/en/api/#1.0.0/datastores.yaml
488
+ const geoServerResponse = await (0, _geoserver.getGeoServerResponseText)(response);
489
+ throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
490
+ }
491
+ }
492
+
493
+ /**
494
+ * Deletes a CoverageStore.
495
+ *
496
+ * @param {String} workspace The workspace where the CoverageStore is in
497
+ * @param {String} coverageStore Name of CoverageStore to delete
498
+ * @param {String} recurse Flag to enable recursive deletion
499
+ *
500
+ * @throws Error if request fails
501
+ */
502
+ async deleteCoverageStore(workspace, coverageStore, recurse) {
503
+ let url = this.url + 'workspaces/' + workspace + '/coveragestores/' + coverageStore;
504
+ url += '?recurse=' + recurse;
505
+ const response = await (0, _nodeFetch.default)(url, {
506
+ credentials: 'include',
507
+ method: 'DELETE',
508
+ headers: {
509
+ Authorization: this.auth
866
510
  }
867
- return deleteDataStore;
868
- }()
869
- /**
870
- * Deletes a CoverageStore.
871
- *
872
- * @param {String} workspace The workspace where the CoverageStore is in
873
- * @param {String} coverageStore Name of CoverageStore to delete
874
- * @param {String} recurse Flag to enable recursive deletion
875
- *
876
- * @throws Error if request fails
877
- */
878
- )
879
- }, {
880
- key: "deleteCoverageStore",
881
- value: (function () {
882
- var _deleteCoverageStore = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee17(workspace, coverageStore, recurse) {
883
- var url, response, geoServerResponse, _t;
884
- return _regenerator["default"].wrap(function (_context17) {
885
- while (1) switch (_context17.prev = _context17.next) {
886
- case 0:
887
- url = this.url + 'workspaces/' + workspace + '/coveragestores/' + coverageStore;
888
- url += '?recurse=' + recurse;
889
- _context17.next = 1;
890
- return (0, _nodeFetch["default"])(url, {
891
- credentials: 'include',
892
- method: 'DELETE',
893
- headers: {
894
- Authorization: this.auth
895
- }
896
- });
897
- case 1:
898
- response = _context17.sent;
899
- if (response.ok) {
900
- _context17.next = 5;
901
- break;
902
- }
903
- _context17.next = 2;
904
- return (0, _geoserver.getGeoServerResponseText)(response);
905
- case 2:
906
- geoServerResponse = _context17.sent;
907
- _t = response.status;
908
- _context17.next = _t === 401 ? 3 : 4;
909
- break;
910
- case 3:
911
- throw new _geoserver.GeoServerResponseError('Deletion failed. There might be dependant objects to ' + 'this store. Delete them first or call this with "recurse=false"', geoServerResponse);
912
- case 4:
913
- throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
914
- case 5:
915
- case "end":
916
- return _context17.stop();
917
- }
918
- }, _callee17, this);
919
- }));
920
- function deleteCoverageStore(_x54, _x55, _x56) {
921
- return _deleteCoverageStore.apply(this, arguments);
511
+ });
512
+
513
+ // TODO: could not test it
514
+ if (!response.ok) {
515
+ const geoServerResponse = await (0, _geoserver.getGeoServerResponseText)(response);
516
+ switch (response.status) {
517
+ case 401:
518
+ throw new _geoserver.GeoServerResponseError('Deletion failed. There might be dependant objects to ' + 'this store. Delete them first or call this with "recurse=false"', geoServerResponse);
519
+ default:
520
+ throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
922
521
  }
923
- return deleteCoverageStore;
924
- }()
925
- /**
926
- * Creates a GeoPackage store from a file placed in the geoserver_data dir.
927
- *
928
- * @param {String} workspace The WS to create the data store in
929
- * @param {String} dataStore The data store name
930
- * @param {String} gpkgPath Relative path to GeoPackage file within geoserver_data dir
931
- *
932
- * @throws Error if request fails
933
- */
934
- )
935
- }, {
936
- key: "createGpkgStore",
937
- value: (function () {
938
- var _createGpkgStore = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee18(workspace, dataStore, gpkgPath) {
939
- var body, url, response, geoServerResponse;
940
- return _regenerator["default"].wrap(function (_context18) {
941
- while (1) switch (_context18.prev = _context18.next) {
942
- case 0:
943
- body = {
944
- dataStore: {
945
- name: dataStore,
946
- type: 'GeoPackage',
947
- connectionParameters: {
948
- entry: [{
949
- '@key': 'database',
950
- $: "file:".concat(gpkgPath)
951
- }, {
952
- '@key': 'dbtype',
953
- $: 'geopkg'
954
- }]
955
- }
956
- }
957
- };
958
- url = this.url + 'workspaces/' + workspace + '/datastores';
959
- _context18.next = 1;
960
- return (0, _nodeFetch["default"])(url, {
961
- credentials: 'include',
962
- method: 'POST',
963
- headers: {
964
- Authorization: this.auth,
965
- 'Content-Type': 'application/json'
966
- },
967
- body: JSON.stringify(body)
968
- });
969
- case 1:
970
- response = _context18.sent;
971
- if (response.ok) {
972
- _context18.next = 3;
973
- break;
974
- }
975
- _context18.next = 2;
976
- return (0, _geoserver.getGeoServerResponseText)(response);
977
- case 2:
978
- geoServerResponse = _context18.sent;
979
- throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
980
- case 3:
981
- case "end":
982
- return _context18.stop();
983
- }
984
- }, _callee18, this);
985
- }));
986
- function createGpkgStore(_x57, _x58, _x59) {
987
- return _createGpkgStore.apply(this, arguments);
522
+ }
523
+ }
524
+
525
+ /**
526
+ * Creates a GeoPackage store from a file placed in the geoserver_data dir.
527
+ *
528
+ * @param {String} workspace The WS to create the data store in
529
+ * @param {String} dataStore The data store name
530
+ * @param {String} gpkgPath Relative path to GeoPackage file within geoserver_data dir
531
+ *
532
+ * @throws Error if request fails
533
+ */
534
+ async createGpkgStore(workspace, dataStore, gpkgPath) {
535
+ const body = {
536
+ dataStore: {
537
+ name: dataStore,
538
+ type: 'GeoPackage',
539
+ connectionParameters: {
540
+ entry: [{
541
+ '@key': 'database',
542
+ $: `file:${gpkgPath}`
543
+ }, {
544
+ '@key': 'dbtype',
545
+ $: 'geopkg'
546
+ }]
547
+ }
988
548
  }
989
- return createGpkgStore;
990
- }())
991
- }]);
992
- }();
549
+ };
550
+ const url = this.url + 'workspaces/' + workspace + '/datastores';
551
+ const response = await (0, _nodeFetch.default)(url, {
552
+ credentials: 'include',
553
+ method: 'POST',
554
+ headers: {
555
+ Authorization: this.auth,
556
+ 'Content-Type': 'application/json'
557
+ },
558
+ body: JSON.stringify(body)
559
+ });
560
+ if (!response.ok) {
561
+ const geoServerResponse = await (0, _geoserver.getGeoServerResponseText)(response);
562
+ throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
563
+ }
564
+ }
565
+ }
566
+ exports.default = DatastoreClient;