geoserver-node-client 1.6.0 → 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.
package/dist/src/style.js CHANGED
@@ -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 _workspace = _interopRequireDefault(require("./workspace.js"));
14
10
  var _geoserver = require("./util/geoserver.js");
@@ -18,15 +14,14 @@ var _about = _interopRequireDefault(require("./about.js"));
18
14
  *
19
15
  * @module StyleClient
20
16
  */
21
- var StyleClient = exports["default"] = /*#__PURE__*/function () {
17
+ class StyleClient {
22
18
  /**
23
19
  * Creates a GeoServer REST StyleClient instance.
24
20
  *
25
21
  * @param {String} url The URL of the GeoServer REST API endpoint
26
22
  * @param {String} auth The Basic Authentication string
27
23
  */
28
- function StyleClient(url, auth) {
29
- (0, _classCallCheck2["default"])(this, StyleClient);
24
+ constructor(url, auth) {
30
25
  this.url = url;
31
26
  this.auth = auth;
32
27
  }
@@ -38,449 +33,234 @@ var StyleClient = exports["default"] = /*#__PURE__*/function () {
38
33
  *
39
34
  * @returns {Object} An object with the default styles
40
35
  */
41
- return (0, _createClass2["default"])(StyleClient, [{
42
- key: "getDefaults",
43
- value: (function () {
44
- var _getDefaults = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee() {
45
- var response, geoServerResponse;
46
- return _regenerator["default"].wrap(function (_context) {
47
- while (1) switch (_context.prev = _context.next) {
48
- case 0:
49
- _context.next = 1;
50
- return (0, _nodeFetch["default"])(this.url + 'styles.json', {
51
- credentials: 'include',
52
- method: 'GET',
53
- headers: {
54
- Authorization: this.auth
55
- }
56
- });
57
- case 1:
58
- response = _context.sent;
59
- if (response.ok) {
60
- _context.next = 3;
61
- break;
62
- }
63
- _context.next = 2;
64
- return (0, _geoserver.getGeoServerResponseText)(response);
65
- case 2:
66
- geoServerResponse = _context.sent;
67
- throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
68
- case 3:
69
- return _context.abrupt("return", response.json());
70
- case 4:
71
- case "end":
72
- return _context.stop();
73
- }
74
- }, _callee, this);
75
- }));
76
- function getDefaults() {
77
- return _getDefaults.apply(this, arguments);
36
+ async getDefaults() {
37
+ const response = await (0, _nodeFetch.default)(this.url + 'styles.json', {
38
+ credentials: 'include',
39
+ method: 'GET',
40
+ headers: {
41
+ Authorization: this.auth
78
42
  }
79
- return getDefaults;
80
- }()
81
- /**
82
- * Returns all styles in a workspace.
83
- *
84
- * @param {String} workspace Workspace name to get styles for
85
- *
86
- * @throws Error if request fails
87
- *
88
- * @returns {Object} An object with all styles
89
- */
90
- )
91
- }, {
92
- key: "getInWorkspace",
93
- value: (function () {
94
- var _getInWorkspace = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee2(workspace) {
95
- var response, geoServerResponse;
96
- return _regenerator["default"].wrap(function (_context2) {
97
- while (1) switch (_context2.prev = _context2.next) {
98
- case 0:
99
- _context2.next = 1;
100
- return (0, _nodeFetch["default"])(this.url + 'workspaces/' + workspace + '/styles.json', {
101
- credentials: 'include',
102
- method: 'GET',
103
- headers: {
104
- Authorization: this.auth
105
- }
106
- });
107
- case 1:
108
- response = _context2.sent;
109
- if (response.ok) {
110
- _context2.next = 3;
111
- break;
112
- }
113
- _context2.next = 2;
114
- return (0, _geoserver.getGeoServerResponseText)(response);
115
- case 2:
116
- geoServerResponse = _context2.sent;
117
- throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
118
- case 3:
119
- return _context2.abrupt("return", response.json());
120
- case 4:
121
- case "end":
122
- return _context2.stop();
123
- }
124
- }, _callee2, this);
125
- }));
126
- function getInWorkspace(_x) {
127
- return _getInWorkspace.apply(this, arguments);
128
- }
129
- return getInWorkspace;
130
- }()
131
- /**
132
- * Returns all styles defined in workspaces.
133
- *
134
- * @throws Error if request fails
135
- *
136
- * @returns {Object[]} An array with all style objects
137
- */
138
- )
139
- }, {
140
- key: "getAllWorkspaceStyles",
141
- value: (function () {
142
- var _getAllWorkspaceStyles = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee3() {
143
- var allStyles, ws, allWs, i, _ws, wsStyles;
144
- return _regenerator["default"].wrap(function (_context3) {
145
- while (1) switch (_context3.prev = _context3.next) {
146
- case 0:
147
- allStyles = [];
148
- ws = new _workspace["default"](this.url, this.auth);
149
- _context3.next = 1;
150
- return ws.getAll();
151
- case 1:
152
- allWs = _context3.sent;
153
- if (!(!allWs || !allWs.workspaces || !allWs.workspaces.workspace || !Array.isArray(allWs.workspaces.workspace))) {
154
- _context3.next = 2;
155
- break;
156
- }
157
- throw new _geoserver.GeoServerResponseError('Response of available workspaces is malformed');
158
- case 2:
159
- i = 0;
160
- case 3:
161
- if (!(i < allWs.workspaces.workspace.length)) {
162
- _context3.next = 6;
163
- break;
164
- }
165
- _ws = allWs.workspaces.workspace[i];
166
- _context3.next = 4;
167
- return this.getInWorkspace(_ws.name);
168
- case 4:
169
- wsStyles = _context3.sent;
170
- if (wsStyles.styles.style) {
171
- wsStyles.styles.style.forEach(function (wsStyle) {
172
- allStyles.push(wsStyle);
173
- });
174
- }
175
- case 5:
176
- i++;
177
- _context3.next = 3;
178
- break;
179
- case 6:
180
- return _context3.abrupt("return", allStyles);
181
- case 7:
182
- case "end":
183
- return _context3.stop();
184
- }
185
- }, _callee3, this);
186
- }));
187
- function getAllWorkspaceStyles() {
188
- return _getAllWorkspaceStyles.apply(this, arguments);
43
+ });
44
+ if (!response.ok) {
45
+ const geoServerResponse = await (0, _geoserver.getGeoServerResponseText)(response);
46
+ throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
47
+ }
48
+ return response.json();
49
+ }
50
+
51
+ /**
52
+ * Returns all styles in a workspace.
53
+ *
54
+ * @param {String} workspace Workspace name to get styles for
55
+ *
56
+ * @throws Error if request fails
57
+ *
58
+ * @returns {Object} An object with all styles
59
+ */
60
+ async getInWorkspace(workspace) {
61
+ const response = await (0, _nodeFetch.default)(this.url + 'workspaces/' + workspace + '/styles.json', {
62
+ credentials: 'include',
63
+ method: 'GET',
64
+ headers: {
65
+ Authorization: this.auth
189
66
  }
190
- return getAllWorkspaceStyles;
191
- }()
192
- /**
193
- * Returns all styles as combined object (default ones and those in
194
- * workspaces).
195
- *
196
- * @returns {Object[]} An array with all style objects
197
- */
198
- )
199
- }, {
200
- key: "getAll",
201
- value: (function () {
202
- var _getAll = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee4() {
203
- var defaultStyles, wsStyles, allStyles;
204
- return _regenerator["default"].wrap(function (_context4) {
205
- while (1) switch (_context4.prev = _context4.next) {
206
- case 0:
207
- _context4.next = 1;
208
- return this.getDefaults();
209
- case 1:
210
- defaultStyles = _context4.sent;
211
- _context4.next = 2;
212
- return this.getAllWorkspaceStyles();
213
- case 2:
214
- wsStyles = _context4.sent;
215
- if (!(!defaultStyles || !defaultStyles.styles || !defaultStyles.styles.style || !Array.isArray(defaultStyles.styles.style))) {
216
- _context4.next = 3;
217
- break;
218
- }
219
- throw new _geoserver.GeoServerResponseError('Response of default styles malformed');
220
- case 3:
221
- allStyles = defaultStyles.styles.style.concat(wsStyles);
222
- return _context4.abrupt("return", allStyles);
223
- case 4:
224
- case "end":
225
- return _context4.stop();
226
- }
227
- }, _callee4, this);
228
- }));
229
- function getAll() {
230
- return _getAll.apply(this, arguments);
67
+ });
68
+ if (!response.ok) {
69
+ const geoServerResponse = await (0, _geoserver.getGeoServerResponseText)(response);
70
+ throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
71
+ }
72
+ return response.json();
73
+ }
74
+
75
+ /**
76
+ * Returns all styles defined in workspaces.
77
+ *
78
+ * @throws Error if request fails
79
+ *
80
+ * @returns {Object[]} An array with all style objects
81
+ */
82
+ async getAllWorkspaceStyles() {
83
+ const allStyles = [];
84
+ const ws = new _workspace.default(this.url, this.auth);
85
+ const allWs = await ws.getAll();
86
+ if (!allWs || !allWs.workspaces || !allWs.workspaces.workspace || !Array.isArray(allWs.workspaces.workspace)) {
87
+ throw new _geoserver.GeoServerResponseError('Response of available workspaces is malformed');
88
+ }
89
+
90
+ // go over all workspaces and query the styles for
91
+ for (let i = 0; i < allWs.workspaces.workspace.length; i++) {
92
+ const ws = allWs.workspaces.workspace[i];
93
+ const wsStyles = await this.getInWorkspace(ws.name);
94
+ if (wsStyles.styles.style) {
95
+ wsStyles.styles.style.forEach(wsStyle => {
96
+ allStyles.push(wsStyle);
97
+ });
231
98
  }
232
- return getAll;
233
- }()
234
- /**
235
- * Publishes a new SLD style.
236
- *
237
- * @param {String} workspace The workspace to publish the style in
238
- * @param {String} name Name of the style
239
- * @param {String} sldBody SLD style (as XML text)
240
- *
241
- * @throws Error if request fails
242
- */
243
- )
244
- }, {
245
- key: "publish",
246
- value: (function () {
247
- var _publish = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee5(workspace, name, sldBody) {
248
- var response, geoServerResponse;
249
- return _regenerator["default"].wrap(function (_context5) {
250
- while (1) switch (_context5.prev = _context5.next) {
251
- case 0:
252
- _context5.next = 1;
253
- return (0, _nodeFetch["default"])(this.url + 'workspaces/' + workspace + '/styles?name=' + name, {
254
- credentials: 'include',
255
- method: 'POST',
256
- headers: {
257
- Authorization: this.auth,
258
- 'Content-Type': 'application/vnd.ogc.sld+xml'
259
- },
260
- body: sldBody
261
- });
262
- case 1:
263
- response = _context5.sent;
264
- if (response.ok) {
265
- _context5.next = 3;
266
- break;
267
- }
268
- _context5.next = 2;
269
- return (0, _geoserver.getGeoServerResponseText)(response);
270
- case 2:
271
- geoServerResponse = _context5.sent;
272
- throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
273
- case 3:
274
- case "end":
275
- return _context5.stop();
276
- }
277
- }, _callee5, this);
278
- }));
279
- function publish(_x2, _x3, _x4) {
280
- return _publish.apply(this, arguments);
99
+ }
100
+ return allStyles;
101
+ }
102
+
103
+ /**
104
+ * Returns all styles as combined object (default ones and those in
105
+ * workspaces).
106
+ *
107
+ * @returns {Object[]} An array with all style objects
108
+ */
109
+ async getAll() {
110
+ const defaultStyles = await this.getDefaults();
111
+ const wsStyles = await this.getAllWorkspaceStyles();
112
+ if (!defaultStyles || !defaultStyles.styles || !defaultStyles.styles.style || !Array.isArray(defaultStyles.styles.style)) {
113
+ throw new _geoserver.GeoServerResponseError('Response of default styles malformed');
114
+ }
115
+ const allStyles = defaultStyles.styles.style.concat(wsStyles);
116
+ return allStyles;
117
+ }
118
+
119
+ /**
120
+ * Publishes a new SLD style.
121
+ *
122
+ * @param {String} workspace The workspace to publish the style in
123
+ * @param {String} name Name of the style
124
+ * @param {String} sldBody SLD style (as XML text)
125
+ *
126
+ * @throws Error if request fails
127
+ */
128
+ async publish(workspace, name, sldBody) {
129
+ const response = await (0, _nodeFetch.default)(this.url + 'workspaces/' + workspace + '/styles?name=' + name, {
130
+ credentials: 'include',
131
+ method: 'POST',
132
+ headers: {
133
+ Authorization: this.auth,
134
+ 'Content-Type': 'application/vnd.ogc.sld+xml'
135
+ },
136
+ body: sldBody
137
+ });
138
+ if (!response.ok) {
139
+ const geoServerResponse = await (0, _geoserver.getGeoServerResponseText)(response);
140
+ throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
141
+ }
142
+ }
143
+
144
+ /**
145
+ * Deletes a style.
146
+ *
147
+ * @param {String} workspace The name of the workspace, can be undefined if style is not assigned to a workspace
148
+ * @param {String} name The name of the style to delete
149
+ * @param {Boolean} [recurse=false] If references to the specified style in existing layers should be deleted
150
+ * @param {Boolean} [purge=false] Whether the underlying file containing the style should be deleted on disk
151
+ */
152
+ async delete(workspace, name, recurse, purge) {
153
+ let paramPurge = false;
154
+ let paramRecurse = false;
155
+ if (purge === true) {
156
+ paramPurge = true;
157
+ }
158
+ if (recurse === true) {
159
+ paramRecurse = true;
160
+ }
161
+ let endpoint;
162
+ if (workspace) {
163
+ // delete style inside workspace
164
+ endpoint = this.url + 'workspaces/' + workspace + '/styles/' + name + '?' + 'purge=' + paramPurge + '&' + 'recurse=' + paramRecurse;
165
+ } else {
166
+ // delete style without workspace
167
+ endpoint = this.url + 'styles/' + name + '?' + 'purge=' + paramPurge + '&' + 'recurse=' + paramRecurse;
168
+ }
169
+ const response = await (0, _nodeFetch.default)(endpoint, {
170
+ credentials: 'include',
171
+ method: 'DELETE',
172
+ headers: {
173
+ Authorization: this.auth
281
174
  }
282
- return publish;
283
- }()
284
- /**
285
- * Deletes a style.
286
- *
287
- * @param {String} workspace The name of the workspace, can be undefined if style is not assigned to a workspace
288
- * @param {String} name The name of the style to delete
289
- * @param {Boolean} [recurse=false] If references to the specified style in existing layers should be deleted
290
- * @param {Boolean} [purge=false] Whether the underlying file containing the style should be deleted on disk
291
- */
292
- )
293
- }, {
294
- key: "delete",
295
- value: (function () {
296
- var _delete2 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee6(workspace, name, recurse, purge) {
297
- var paramPurge, paramRecurse, endpoint, response, geoServerResponse, _t;
298
- return _regenerator["default"].wrap(function (_context6) {
299
- while (1) switch (_context6.prev = _context6.next) {
300
- case 0:
301
- paramPurge = false;
302
- paramRecurse = false;
303
- if (purge === true) {
304
- paramPurge = true;
305
- }
306
- if (recurse === true) {
307
- paramRecurse = true;
308
- }
309
- if (workspace) {
310
- // delete style inside workspace
311
- endpoint = this.url + 'workspaces/' + workspace + '/styles/' + name + '?' + 'purge=' + paramPurge + '&' + 'recurse=' + paramRecurse;
312
- } else {
313
- // delete style without workspace
314
- endpoint = this.url + 'styles/' + name + '?' + 'purge=' + paramPurge + '&' + 'recurse=' + paramRecurse;
315
- }
316
- _context6.next = 1;
317
- return (0, _nodeFetch["default"])(endpoint, {
318
- credentials: 'include',
319
- method: 'DELETE',
320
- headers: {
321
- Authorization: this.auth
322
- }
323
- });
324
- case 1:
325
- response = _context6.sent;
326
- if (response.ok) {
327
- _context6.next = 5;
328
- break;
329
- }
330
- _context6.next = 2;
331
- return (0, _geoserver.getGeoServerResponseText)(response);
332
- case 2:
333
- geoServerResponse = _context6.sent;
334
- _t = response.status;
335
- _context6.next = _t === 403 ? 3 : 4;
336
- break;
337
- case 3:
338
- throw new _geoserver.GeoServerResponseError('Deletion failed. There might be dependant layers to this style. Delete them first or call this with "recurse=false"', geoServerResponse);
339
- case 4:
340
- throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
341
- case 5:
342
- case "end":
343
- return _context6.stop();
344
- }
345
- }, _callee6, this);
346
- }));
347
- function _delete(_x5, _x6, _x7, _x8) {
348
- return _delete2.apply(this, arguments);
175
+ });
176
+ if (!response.ok) {
177
+ const geoServerResponse = await (0, _geoserver.getGeoServerResponseText)(response);
178
+ switch (response.status) {
179
+ case 403:
180
+ throw new _geoserver.GeoServerResponseError('Deletion failed. There might be dependant layers to this style. Delete them first or call this with "recurse=false"', geoServerResponse);
181
+ default:
182
+ throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
349
183
  }
350
- return _delete;
351
- }()
352
- /**
353
- * Assigns a style to a layer.
354
- *
355
- * @param {String} workspaceOfLayer The name of the layer's workspace, can be undefined
356
- * @param {String} layerName The name of the layer to query
357
- * @param {String} workspaceOfStyle The workspace of the style, can be undefined
358
- * @param {String} styleName The name of the style
359
- * @param {Boolean} [isDefaultStyle=true] If the style should be the default style of the layer
360
- *
361
- * @throws Error if request fails
362
- */
363
- )
364
- }, {
365
- key: "assignStyleToLayer",
366
- value: (function () {
367
- var _assignStyleToLayer = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee7(workspaceOfLayer, layerName, workspaceOfStyle, styleName, isDefaultStyle) {
368
- var qualifiedName, styleBody, url, response, geoServerResponse;
369
- return _regenerator["default"].wrap(function (_context7) {
370
- while (1) switch (_context7.prev = _context7.next) {
371
- case 0:
372
- if (workspaceOfLayer) {
373
- qualifiedName = "".concat(workspaceOfLayer, ":").concat(layerName);
374
- } else {
375
- qualifiedName = layerName;
376
- }
377
- _context7.next = 1;
378
- return this.getStyleInformation(workspaceOfStyle, styleName);
379
- case 1:
380
- styleBody = _context7.sent;
381
- // we set the style as defaultStyle, unless user explicitly provides 'false'
382
- if (isDefaultStyle !== false) {
383
- url = this.url + 'layers/' + qualifiedName + '/styles?default=true';
384
- } else {
385
- url = this.url + 'layers/' + qualifiedName + '/styles';
386
- }
387
- _context7.next = 2;
388
- return (0, _nodeFetch["default"])(url, {
389
- credentials: 'include',
390
- method: 'POST',
391
- headers: {
392
- Authorization: this.auth,
393
- 'Content-Type': 'application/json'
394
- },
395
- body: JSON.stringify(styleBody)
396
- });
397
- case 2:
398
- response = _context7.sent;
399
- if (response.ok) {
400
- _context7.next = 4;
401
- break;
402
- }
403
- _context7.next = 3;
404
- return (0, _geoserver.getGeoServerResponseText)(response);
405
- case 3:
406
- geoServerResponse = _context7.sent;
407
- throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
408
- case 4:
409
- case "end":
410
- return _context7.stop();
411
- }
412
- }, _callee7, this);
413
- }));
414
- function assignStyleToLayer(_x9, _x0, _x1, _x10, _x11) {
415
- return _assignStyleToLayer.apply(this, arguments);
184
+ }
185
+ }
186
+
187
+ /**
188
+ * Assigns a style to a layer.
189
+ *
190
+ * @param {String} workspaceOfLayer The name of the layer's workspace, can be undefined
191
+ * @param {String} layerName The name of the layer to query
192
+ * @param {String} workspaceOfStyle The workspace of the style, can be undefined
193
+ * @param {String} styleName The name of the style
194
+ * @param {Boolean} [isDefaultStyle=true] If the style should be the default style of the layer
195
+ *
196
+ * @throws Error if request fails
197
+ */
198
+ async assignStyleToLayer(workspaceOfLayer, layerName, workspaceOfStyle, styleName, isDefaultStyle) {
199
+ let qualifiedName;
200
+ if (workspaceOfLayer) {
201
+ qualifiedName = `${workspaceOfLayer}:${layerName}`;
202
+ } else {
203
+ qualifiedName = layerName;
204
+ }
205
+ const styleBody = await this.getStyleInformation(workspaceOfStyle, styleName);
206
+ let url;
207
+ // we set the style as defaultStyle, unless user explicitly provides 'false'
208
+ if (isDefaultStyle !== false) {
209
+ url = this.url + 'layers/' + qualifiedName + '/styles?default=true';
210
+ } else {
211
+ url = this.url + 'layers/' + qualifiedName + '/styles';
212
+ }
213
+ const response = await (0, _nodeFetch.default)(url, {
214
+ credentials: 'include',
215
+ method: 'POST',
216
+ headers: {
217
+ Authorization: this.auth,
218
+ 'Content-Type': 'application/json'
219
+ },
220
+ body: JSON.stringify(styleBody)
221
+ });
222
+ if (!response.ok) {
223
+ const geoServerResponse = await (0, _geoserver.getGeoServerResponseText)(response);
224
+ throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
225
+ }
226
+ }
227
+
228
+ /**
229
+ * Get information about a style.
230
+ *
231
+ * @param {String} workspace The name of the workspace, can be undefined
232
+ * @param {String} styleName The name of the style
233
+ *
234
+ * @throws Error if request fails
235
+ *
236
+ * @returns {Object} An object about the style or undefined if it cannot be found
237
+ */
238
+ async getStyleInformation(workspace, styleName) {
239
+ let url;
240
+ if (workspace) {
241
+ url = this.url + 'workspaces/' + workspace + '/styles/' + styleName + '.json';
242
+ } else {
243
+ url = this.url + 'styles/' + styleName + '.json';
244
+ }
245
+ const response = await (0, _nodeFetch.default)(url, {
246
+ credentials: 'include',
247
+ method: 'GET',
248
+ headers: {
249
+ Authorization: this.auth
416
250
  }
417
- return assignStyleToLayer;
418
- }()
419
- /**
420
- * Get information about a style.
421
- *
422
- * @param {String} workspace The name of the workspace, can be undefined
423
- * @param {String} styleName The name of the style
424
- *
425
- * @throws Error if request fails
426
- *
427
- * @returns {Object} An object about the style or undefined if it cannot be found
428
- */
429
- )
430
- }, {
431
- key: "getStyleInformation",
432
- value: (function () {
433
- var _getStyleInformation = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee8(workspace, styleName) {
434
- var url, response, grc, geoServerResponse;
435
- return _regenerator["default"].wrap(function (_context8) {
436
- while (1) switch (_context8.prev = _context8.next) {
437
- case 0:
438
- if (workspace) {
439
- url = this.url + 'workspaces/' + workspace + '/styles/' + styleName + '.json';
440
- } else {
441
- url = this.url + 'styles/' + styleName + '.json';
442
- }
443
- _context8.next = 1;
444
- return (0, _nodeFetch["default"])(url, {
445
- credentials: 'include',
446
- method: 'GET',
447
- headers: {
448
- Authorization: this.auth
449
- }
450
- });
451
- case 1:
452
- response = _context8.sent;
453
- if (response.ok) {
454
- _context8.next = 5;
455
- break;
456
- }
457
- grc = new _about["default"](this.url, this.auth);
458
- _context8.next = 2;
459
- return grc.exists();
460
- case 2:
461
- if (!_context8.sent) {
462
- _context8.next = 3;
463
- break;
464
- }
465
- return _context8.abrupt("return");
466
- case 3:
467
- _context8.next = 4;
468
- return (0, _geoserver.getGeoServerResponseText)(response);
469
- case 4:
470
- geoServerResponse = _context8.sent;
471
- throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
472
- case 5:
473
- return _context8.abrupt("return", response.json());
474
- case 6:
475
- case "end":
476
- return _context8.stop();
477
- }
478
- }, _callee8, this);
479
- }));
480
- function getStyleInformation(_x12, _x13) {
481
- return _getStyleInformation.apply(this, arguments);
251
+ });
252
+ if (!response.ok) {
253
+ const grc = new _about.default(this.url, this.auth);
254
+ if (await grc.exists()) {
255
+ // GeoServer exists, but requested item does not exist, we return empty
256
+ return;
257
+ } else {
258
+ // There was a general problem with GeoServer
259
+ const geoServerResponse = await (0, _geoserver.getGeoServerResponseText)(response);
260
+ throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
482
261
  }
483
- return getStyleInformation;
484
- }())
485
- }]);
486
- }();
262
+ }
263
+ return response.json();
264
+ }
265
+ }
266
+ exports.default = StyleClient;