geoserver-node-client 0.0.6 → 1.1.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,297 @@
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
+ /**
23
+ * Client for GeoServer image mosaics
24
+ *
25
+ * @module ImageMosaicClient
26
+ */
27
+ var ImageMosaicClient = /*#__PURE__*/function () {
28
+ /**
29
+ * Creates a GeoServer REST ImageMosaicClient instance.
30
+ *
31
+ * @param {String} url The URL of the GeoServer REST API endpoint
32
+ * @param {String} auth The Basic Authentication string
33
+ */
34
+ function ImageMosaicClient(url, auth) {
35
+ (0, _classCallCheck2["default"])(this, ImageMosaicClient);
36
+ this.url = url;
37
+ this.auth = auth;
38
+ }
39
+ /**
40
+ * Returns all granules of an image mosaic.
41
+ *
42
+ * @param {String} workspace Workspace of image mosaic
43
+ * @param {String} coverageStore CoverageStore of image mosaic
44
+ * @param {*} coverage Name of image mosaic
45
+ *
46
+ * @throws Error if request fails
47
+ *
48
+ * @returns {Object} An object with the granules
49
+ */
50
+
51
+
52
+ (0, _createClass2["default"])(ImageMosaicClient, [{
53
+ key: "getGranules",
54
+ value: function () {
55
+ var _getGranules = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(workspace, coverageStore, coverage) {
56
+ var url, response, geoServerResponse;
57
+ return _regenerator["default"].wrap(function _callee$(_context) {
58
+ while (1) {
59
+ switch (_context.prev = _context.next) {
60
+ case 0:
61
+ url = this.url + 'workspaces/' + workspace + '/coveragestores/' + coverageStore + '/coverages/' + coverage + '/index/granules.json';
62
+ _context.next = 3;
63
+ return (0, _nodeFetch["default"])(url, {
64
+ credentials: 'include',
65
+ method: 'GET',
66
+ headers: {
67
+ Authorization: this.auth,
68
+ 'Content-type': 'text/plain'
69
+ }
70
+ });
71
+
72
+ case 3:
73
+ response = _context.sent;
74
+
75
+ if (response.ok) {
76
+ _context.next = 9;
77
+ break;
78
+ }
79
+
80
+ _context.next = 7;
81
+ return (0, _geoserver.getGeoServerResponseText)(response);
82
+
83
+ case 7:
84
+ geoServerResponse = _context.sent;
85
+ throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
86
+
87
+ case 9:
88
+ return _context.abrupt("return", response.json());
89
+
90
+ case 10:
91
+ case "end":
92
+ return _context.stop();
93
+ }
94
+ }
95
+ }, _callee, this);
96
+ }));
97
+
98
+ function getGranules(_x, _x2, _x3) {
99
+ return _getGranules.apply(this, arguments);
100
+ }
101
+
102
+ return getGranules;
103
+ }()
104
+ /**
105
+ * Harvests all granules in the given folder for an image mosaic.
106
+ *
107
+ * @param {String} workspace Workspace of image mosaic
108
+ * @param {String} coverageStore CoverageStore of image mosaic
109
+ * @param {String} filePath Server path of folder to harvest
110
+ *
111
+ * @throws Error if request fails
112
+ *
113
+ * @returns {Object} An object with the granules
114
+ */
115
+
116
+ }, {
117
+ key: "harvestGranules",
118
+ value: function () {
119
+ var _harvestGranules = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(workspace, coverageStore, filePath) {
120
+ var url, response, geoServerResponse;
121
+ return _regenerator["default"].wrap(function _callee2$(_context2) {
122
+ while (1) {
123
+ switch (_context2.prev = _context2.next) {
124
+ case 0:
125
+ url = this.url + 'workspaces/' + workspace + '/coveragestores/' + coverageStore + '/external.imagemosaic';
126
+ _context2.next = 3;
127
+ return (0, _nodeFetch["default"])(url, {
128
+ credentials: 'include',
129
+ method: 'POST',
130
+ headers: {
131
+ Authorization: this.auth,
132
+ 'Content-Type': 'text/plain'
133
+ },
134
+ body: filePath
135
+ });
136
+
137
+ case 3:
138
+ response = _context2.sent;
139
+
140
+ if (response.ok) {
141
+ _context2.next = 9;
142
+ break;
143
+ }
144
+
145
+ _context2.next = 7;
146
+ return (0, _geoserver.getGeoServerResponseText)(response);
147
+
148
+ case 7:
149
+ geoServerResponse = _context2.sent;
150
+ throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
151
+
152
+ case 9:
153
+ return _context2.abrupt("return", response.json());
154
+
155
+ case 10:
156
+ case "end":
157
+ return _context2.stop();
158
+ }
159
+ }
160
+ }, _callee2, this);
161
+ }));
162
+
163
+ function harvestGranules(_x4, _x5, _x6) {
164
+ return _harvestGranules.apply(this, arguments);
165
+ }
166
+
167
+ return harvestGranules;
168
+ }()
169
+ /**
170
+ * Adds a granule (defined by a server file) to an image mosaic.
171
+ *
172
+ * @param {String} workspace Workspace of image mosaic
173
+ * @param {String} coverageStore CoverageStore of image mosaic
174
+ * @param {String} filePath Server file path of new granule
175
+ *
176
+ * @throws Error if request fails
177
+ */
178
+
179
+ }, {
180
+ key: "addGranuleByServerFile",
181
+ value: function () {
182
+ var _addGranuleByServerFile = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(workspace, coverageStore, filePath) {
183
+ var url, response, geoServerResponse;
184
+ return _regenerator["default"].wrap(function _callee3$(_context3) {
185
+ while (1) {
186
+ switch (_context3.prev = _context3.next) {
187
+ case 0:
188
+ url = this.url + 'workspaces/' + workspace + '/coveragestores/' + coverageStore + '/external.imagemosaic';
189
+ _context3.next = 3;
190
+ return (0, _nodeFetch["default"])(url, {
191
+ credentials: 'include',
192
+ method: 'POST',
193
+ headers: {
194
+ Authorization: this.auth,
195
+ 'Content-type': 'text/plain'
196
+ },
197
+ body: filePath
198
+ });
199
+
200
+ case 3:
201
+ response = _context3.sent;
202
+
203
+ if (response.ok) {
204
+ _context3.next = 9;
205
+ break;
206
+ }
207
+
208
+ _context3.next = 7;
209
+ return (0, _geoserver.getGeoServerResponseText)(response);
210
+
211
+ case 7:
212
+ geoServerResponse = _context3.sent;
213
+ throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
214
+
215
+ case 9:
216
+ case "end":
217
+ return _context3.stop();
218
+ }
219
+ }
220
+ }, _callee3, this);
221
+ }));
222
+
223
+ function addGranuleByServerFile(_x7, _x8, _x9) {
224
+ return _addGranuleByServerFile.apply(this, arguments);
225
+ }
226
+
227
+ return addGranuleByServerFile;
228
+ }()
229
+ /**
230
+ * Deletes a single granule of an image mosaic.
231
+ *
232
+ * @param {String} workspace Workspace of image mosaic
233
+ * @param {String} coverageStore CoverageStore of image mosaic
234
+ * @param {String} coverage Name of image mosaic
235
+ * @param {String} covFileLocation Location of coverage file
236
+ *
237
+ * @throws Error if request fails
238
+ */
239
+
240
+ }, {
241
+ key: "deleteSingleGranule",
242
+ value: function () {
243
+ var _deleteSingleGranule = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4(workspace, coverageStore, coverage, covFileLocation) {
244
+ var url, response, geoServerResponse;
245
+ return _regenerator["default"].wrap(function _callee4$(_context4) {
246
+ while (1) {
247
+ switch (_context4.prev = _context4.next) {
248
+ case 0:
249
+ url = this.url + 'workspaces/' + workspace + '/coveragestores/' + coverageStore + '/coverages/' + coverage + '/index/granules.xml';
250
+ url += '?filter=location=\'' + covFileLocation + '\'';
251
+ _context4.next = 4;
252
+ return (0, _nodeFetch["default"])(url, {
253
+ credentials: 'include',
254
+ method: 'DELETE',
255
+ headers: {
256
+ Authorization: this.auth,
257
+ 'Content-type': 'text/plain'
258
+ }
259
+ });
260
+
261
+ case 4:
262
+ response = _context4.sent;
263
+
264
+ if (response.ok) {
265
+ _context4.next = 10;
266
+ break;
267
+ }
268
+
269
+ _context4.next = 8;
270
+ return (0, _geoserver.getGeoServerResponseText)(response);
271
+
272
+ case 8:
273
+ geoServerResponse = _context4.sent;
274
+ throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
275
+
276
+ case 10:
277
+ return _context4.abrupt("return", true);
278
+
279
+ case 11:
280
+ case "end":
281
+ return _context4.stop();
282
+ }
283
+ }
284
+ }, _callee4, this);
285
+ }));
286
+
287
+ function deleteSingleGranule(_x10, _x11, _x12, _x13) {
288
+ return _deleteSingleGranule.apply(this, arguments);
289
+ }
290
+
291
+ return deleteSingleGranule;
292
+ }()
293
+ }]);
294
+ return ImageMosaicClient;
295
+ }();
296
+
297
+ exports["default"] = ImageMosaicClient;