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