geoserver-node-client 0.0.7 → 1.2.0

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