geoserver-node-client 1.3.0 → 1.4.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.
- package/README.md +5 -2
- package/dist/geoserver-rest-client.js +4 -25
- package/dist/package.json +15 -16
- package/dist/src/about.js +42 -70
- package/dist/src/datastore.js +450 -633
- package/dist/src/imagemosaic.js +112 -164
- package/dist/src/layer.js +591 -797
- package/dist/src/layergroup.js +275 -0
- package/dist/src/namespace.js +126 -186
- package/dist/src/reset-reload.js +49 -78
- package/dist/src/security.js +117 -169
- package/dist/src/settings.js +137 -198
- package/dist/src/style.js +260 -376
- package/dist/src/util/geoserver.js +12 -36
- package/dist/src/workspace.js +133 -190
- package/geoserver-rest-client.js +3 -0
- package/package.json +15 -16
- package/src/layergroup.js +176 -0
- package/src/workspace.js +4 -3
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports["default"] = void 0;
|
|
8
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
11
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
12
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
|
+
var _nodeFetch = _interopRequireDefault(require("node-fetch"));
|
|
14
|
+
var _geoserver = require("./util/geoserver.js");
|
|
15
|
+
var _about = _interopRequireDefault(require("./about.js"));
|
|
16
|
+
var _layer = _interopRequireDefault(require("./layer.js"));
|
|
17
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
18
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
19
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
20
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
21
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
22
|
+
/**
|
|
23
|
+
* Client for GeoServer layergroups
|
|
24
|
+
*
|
|
25
|
+
* @module LayerGroupClient
|
|
26
|
+
*/
|
|
27
|
+
var LayerGroupClient = /*#__PURE__*/function () {
|
|
28
|
+
/**
|
|
29
|
+
* Creates a GeoServer REST LayerGroupClient 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 LayerGroupClient(url, auth) {
|
|
35
|
+
(0, _classCallCheck2["default"])(this, LayerGroupClient);
|
|
36
|
+
this.url = url;
|
|
37
|
+
this.auth = auth;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @typedef {object} bounds
|
|
42
|
+
* @property {number} minx The minimum x coordinates. Default: -180
|
|
43
|
+
* @property {number} miny The minimum y coordinates. Default: -90
|
|
44
|
+
* @property {number} maxx The maximum x coordinates. Default: 180
|
|
45
|
+
* @property {number} maxy The maximum y coordinates. Default: 90
|
|
46
|
+
* @property {String} crs The crs of the bounds. Default: 'EPSG:4326'
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Create a GeoServer layergroup by the given workspace, layerGroupName, layers and options
|
|
51
|
+
* @param {String} workspace The name of the workspace
|
|
52
|
+
* @param {String} layerGroupName The name of the layer group
|
|
53
|
+
* @param {Array.<String>} layers List of layers to be added to the group. Must be in same workspace as layergroup
|
|
54
|
+
* @param {String} options.mode The mode of the layergroup. Default to SINGLE
|
|
55
|
+
* @param {String} options.layerGroupTitle The title of the layergroup.
|
|
56
|
+
* @param {bounds} options.bounds The bounds of the layer group.
|
|
57
|
+
*
|
|
58
|
+
* @throws Error if request fails
|
|
59
|
+
*
|
|
60
|
+
* @returns {string} A string with layer group location or undefined if not found
|
|
61
|
+
*/
|
|
62
|
+
(0, _createClass2["default"])(LayerGroupClient, [{
|
|
63
|
+
key: "create",
|
|
64
|
+
value: function () {
|
|
65
|
+
var _create = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(workspace, layerGroupName, layers, layerGroupOptions) {
|
|
66
|
+
var options, publishedLayers, styles, _iterator, _step, l, body, response, grc, geoServerResponse, location;
|
|
67
|
+
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
68
|
+
while (1) switch (_context.prev = _context.next) {
|
|
69
|
+
case 0:
|
|
70
|
+
options = _objectSpread({
|
|
71
|
+
mode: 'SINGLE',
|
|
72
|
+
layerGroupTitle: '',
|
|
73
|
+
abstractTxt: '',
|
|
74
|
+
bounds: {
|
|
75
|
+
minx: -180,
|
|
76
|
+
maxx: -90,
|
|
77
|
+
miny: 180,
|
|
78
|
+
maxy: 90,
|
|
79
|
+
crs: 'EPSG:4326'
|
|
80
|
+
}
|
|
81
|
+
}, layerGroupOptions);
|
|
82
|
+
publishedLayers = [];
|
|
83
|
+
styles = [];
|
|
84
|
+
_iterator = _createForOfIteratorHelper(layers);
|
|
85
|
+
try {
|
|
86
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
87
|
+
l = _step.value;
|
|
88
|
+
publishedLayers.push({
|
|
89
|
+
'@type': 'layer',
|
|
90
|
+
name: "".concat(workspace, ":").concat(l),
|
|
91
|
+
href: "".concat(this.url, "/workspaces/").concat(workspace, "/layers/").concat(l, ".json")
|
|
92
|
+
});
|
|
93
|
+
// use default style by define empty string
|
|
94
|
+
styles.push('');
|
|
95
|
+
}
|
|
96
|
+
} catch (err) {
|
|
97
|
+
_iterator.e(err);
|
|
98
|
+
} finally {
|
|
99
|
+
_iterator.f();
|
|
100
|
+
}
|
|
101
|
+
body = {
|
|
102
|
+
layerGroup: _objectSpread({
|
|
103
|
+
name: layerGroupName,
|
|
104
|
+
workspace: {
|
|
105
|
+
name: workspace
|
|
106
|
+
},
|
|
107
|
+
publishables: {
|
|
108
|
+
published: publishedLayers
|
|
109
|
+
},
|
|
110
|
+
styles: {
|
|
111
|
+
style: styles
|
|
112
|
+
}
|
|
113
|
+
}, options)
|
|
114
|
+
};
|
|
115
|
+
_context.next = 8;
|
|
116
|
+
return (0, _nodeFetch["default"])("".concat(this.url, "/workspaces/").concat(workspace, "/layergroups"), {
|
|
117
|
+
credentials: 'include',
|
|
118
|
+
method: 'POST',
|
|
119
|
+
headers: {
|
|
120
|
+
Authorization: this.auth,
|
|
121
|
+
'Content-Type': 'application/json'
|
|
122
|
+
},
|
|
123
|
+
body: JSON.stringify(body)
|
|
124
|
+
});
|
|
125
|
+
case 8:
|
|
126
|
+
response = _context.sent;
|
|
127
|
+
if (response.ok) {
|
|
128
|
+
_context.next = 21;
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
grc = new _about["default"](this.url, this.auth);
|
|
132
|
+
_context.next = 13;
|
|
133
|
+
return grc.exists();
|
|
134
|
+
case 13:
|
|
135
|
+
if (!_context.sent) {
|
|
136
|
+
_context.next = 17;
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
return _context.abrupt("return");
|
|
140
|
+
case 17:
|
|
141
|
+
_context.next = 19;
|
|
142
|
+
return (0, _geoserver.getGeoServerResponseText)(response);
|
|
143
|
+
case 19:
|
|
144
|
+
geoServerResponse = _context.sent;
|
|
145
|
+
throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
|
|
146
|
+
case 21:
|
|
147
|
+
// get resource location from response header
|
|
148
|
+
location = response.headers.get('location'); // return resource location
|
|
149
|
+
return _context.abrupt("return", location);
|
|
150
|
+
case 23:
|
|
151
|
+
case "end":
|
|
152
|
+
return _context.stop();
|
|
153
|
+
}
|
|
154
|
+
}, _callee, this);
|
|
155
|
+
}));
|
|
156
|
+
function create(_x, _x2, _x3, _x4) {
|
|
157
|
+
return _create.apply(this, arguments);
|
|
158
|
+
}
|
|
159
|
+
return create;
|
|
160
|
+
}()
|
|
161
|
+
/**
|
|
162
|
+
* Returns a GeoServer layergroup by the given workspace and layergroup name,
|
|
163
|
+
* e.g. "myWs:myLayergroup".
|
|
164
|
+
*
|
|
165
|
+
* @param {String} workspace The name of the workspace
|
|
166
|
+
* @param {String} layerGroupName The name of the layer group to query
|
|
167
|
+
*
|
|
168
|
+
* @throws Error if request fails
|
|
169
|
+
*
|
|
170
|
+
* @returns {Object} An object with layer group information or undefined if it cannot be found
|
|
171
|
+
*/
|
|
172
|
+
}, {
|
|
173
|
+
key: "get",
|
|
174
|
+
value: function () {
|
|
175
|
+
var _get = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(workspace, layerGroupName) {
|
|
176
|
+
var response, grc, geoServerResponse;
|
|
177
|
+
return _regenerator["default"].wrap(function _callee2$(_context2) {
|
|
178
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
179
|
+
case 0:
|
|
180
|
+
_context2.next = 2;
|
|
181
|
+
return (0, _nodeFetch["default"])("".concat(this.url, "/workspaces/").concat(workspace, "/layergroups/").concat(layerGroupName, ".json"), {
|
|
182
|
+
credentials: 'include',
|
|
183
|
+
method: 'GET',
|
|
184
|
+
headers: {
|
|
185
|
+
Authorization: this.auth
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
case 2:
|
|
189
|
+
response = _context2.sent;
|
|
190
|
+
if (response.ok) {
|
|
191
|
+
_context2.next = 15;
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
grc = new _about["default"](this.url, this.auth);
|
|
195
|
+
_context2.next = 7;
|
|
196
|
+
return grc.exists();
|
|
197
|
+
case 7:
|
|
198
|
+
if (!_context2.sent) {
|
|
199
|
+
_context2.next = 11;
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
return _context2.abrupt("return");
|
|
203
|
+
case 11:
|
|
204
|
+
_context2.next = 13;
|
|
205
|
+
return (0, _geoserver.getGeoServerResponseText)(response);
|
|
206
|
+
case 13:
|
|
207
|
+
geoServerResponse = _context2.sent;
|
|
208
|
+
throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
|
|
209
|
+
case 15:
|
|
210
|
+
return _context2.abrupt("return", response.json());
|
|
211
|
+
case 16:
|
|
212
|
+
case "end":
|
|
213
|
+
return _context2.stop();
|
|
214
|
+
}
|
|
215
|
+
}, _callee2, this);
|
|
216
|
+
}));
|
|
217
|
+
function get(_x5, _x6) {
|
|
218
|
+
return _get.apply(this, arguments);
|
|
219
|
+
}
|
|
220
|
+
return get;
|
|
221
|
+
}()
|
|
222
|
+
/**
|
|
223
|
+
* Updates an existing GeoServer layergroup
|
|
224
|
+
*
|
|
225
|
+
* @param {String} workspace The name of the workspace
|
|
226
|
+
* @param {String} layerName The name of the layergroup to update
|
|
227
|
+
* @param {Object} layerGroupDefinition The updated definiton of the layergroup
|
|
228
|
+
*
|
|
229
|
+
* @throws Error if request fails
|
|
230
|
+
*/
|
|
231
|
+
}, {
|
|
232
|
+
key: "update",
|
|
233
|
+
value: function () {
|
|
234
|
+
var _update = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(workspace, layerGroupName, layerGroupDefinition) {
|
|
235
|
+
var url, response, geoServerResponse;
|
|
236
|
+
return _regenerator["default"].wrap(function _callee3$(_context3) {
|
|
237
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
238
|
+
case 0:
|
|
239
|
+
url = "".concat(this.url, "/workspaces/").concat(workspace, "/layergroups/").concat(layerGroupName, ".json");
|
|
240
|
+
_context3.next = 3;
|
|
241
|
+
return (0, _nodeFetch["default"])(url, {
|
|
242
|
+
credentials: 'include',
|
|
243
|
+
method: 'PUT',
|
|
244
|
+
headers: {
|
|
245
|
+
Authorization: this.auth,
|
|
246
|
+
'Content-Type': 'application/json'
|
|
247
|
+
},
|
|
248
|
+
body: JSON.stringify(layerGroupDefinition)
|
|
249
|
+
});
|
|
250
|
+
case 3:
|
|
251
|
+
response = _context3.sent;
|
|
252
|
+
if (response.ok) {
|
|
253
|
+
_context3.next = 9;
|
|
254
|
+
break;
|
|
255
|
+
}
|
|
256
|
+
_context3.next = 7;
|
|
257
|
+
return (0, _geoserver.getGeoServerResponseText)(response);
|
|
258
|
+
case 7:
|
|
259
|
+
geoServerResponse = _context3.sent;
|
|
260
|
+
throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
|
|
261
|
+
case 9:
|
|
262
|
+
case "end":
|
|
263
|
+
return _context3.stop();
|
|
264
|
+
}
|
|
265
|
+
}, _callee3, this);
|
|
266
|
+
}));
|
|
267
|
+
function update(_x7, _x8, _x9) {
|
|
268
|
+
return _update.apply(this, arguments);
|
|
269
|
+
}
|
|
270
|
+
return update;
|
|
271
|
+
}()
|
|
272
|
+
}]);
|
|
273
|
+
return LayerGroupClient;
|
|
274
|
+
}();
|
|
275
|
+
exports["default"] = LayerGroupClient;
|