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.
- package/dist/geoserver-rest-client.js +38 -39
- package/dist/package.json +7 -7
- package/dist/src/about.js +35 -86
- package/dist/src/datastore.js +524 -950
- package/dist/src/imagemosaic.js +103 -211
- package/dist/src/layer.js +718 -1287
- package/dist/src/layergroup.js +128 -226
- package/dist/src/namespace.js +110 -222
- package/dist/src/reset-reload.js +41 -96
- package/dist/src/security.js +279 -567
- package/dist/src/settings.js +127 -255
- package/dist/src/style.js +228 -448
- package/dist/src/util/geoserver.js +17 -44
- package/dist/src/workspace.js +116 -229
- package/package.json +7 -7
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
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
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
)
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
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
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
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
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
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
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
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
|
-
|
|
484
|
-
|
|
485
|
-
}
|
|
486
|
-
}
|
|
262
|
+
}
|
|
263
|
+
return response.json();
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
exports.default = StyleClient;
|