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