geoserver-node-client 1.0.0 → 1.2.1
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 +19 -13
- package/dist/geoserver-rest-client.js +5 -0
- package/dist/package.json +3 -2
- package/dist/src/datastore.js +113 -46
- package/dist/src/imagemosaic.js +1 -1
- package/dist/src/layer.js +343 -120
- package/dist/src/reset-reload.js +160 -0
- package/geoserver-rest-client.js +3 -0
- package/package.json +3 -2
- package/src/datastore.js +35 -0
- package/src/imagemosaic.js +1 -1
- package/src/layer.js +97 -0
- package/src/reset-reload.js +70 -0
|
@@ -0,0 +1,160 @@
|
|
|
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 "Reset/Reload" to clear internal caches and reload
|
|
24
|
+
* configuration from disk endpoint.
|
|
25
|
+
*
|
|
26
|
+
* @module ResetReloadClient
|
|
27
|
+
*/
|
|
28
|
+
var ResetReloadClient = /*#__PURE__*/function () {
|
|
29
|
+
/**
|
|
30
|
+
* Creates a GeoServer REST ResetReloadClient instance.
|
|
31
|
+
*
|
|
32
|
+
* @param {String} url The URL of the GeoServer REST API endpoint
|
|
33
|
+
* @param {String} auth The Basic Authentication string
|
|
34
|
+
*/
|
|
35
|
+
function ResetReloadClient(url, auth) {
|
|
36
|
+
(0, _classCallCheck2["default"])(this, ResetReloadClient);
|
|
37
|
+
this.url = url;
|
|
38
|
+
this.auth = auth;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Resets all store, raster, and schema caches. This operation is used to
|
|
42
|
+
* force GeoServer to drop all caches and store connections and reconnect to
|
|
43
|
+
* each of them the next time they are needed by a request.
|
|
44
|
+
* This is useful in case the stores themselves cache some information about
|
|
45
|
+
* the data structures they manage that may have changed in the meantime.
|
|
46
|
+
*
|
|
47
|
+
* @throws Error if request fails
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
(0, _createClass2["default"])(ResetReloadClient, [{
|
|
52
|
+
key: "reset",
|
|
53
|
+
value: function () {
|
|
54
|
+
var _reset = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
|
|
55
|
+
var url, response, geoServerResponse;
|
|
56
|
+
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
57
|
+
while (1) {
|
|
58
|
+
switch (_context.prev = _context.next) {
|
|
59
|
+
case 0:
|
|
60
|
+
url = this.url + 'reset';
|
|
61
|
+
_context.next = 3;
|
|
62
|
+
return (0, _nodeFetch["default"])(url, {
|
|
63
|
+
credentials: 'include',
|
|
64
|
+
method: 'POST',
|
|
65
|
+
headers: {
|
|
66
|
+
Authorization: this.auth
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
case 3:
|
|
71
|
+
response = _context.sent;
|
|
72
|
+
|
|
73
|
+
if (response.ok) {
|
|
74
|
+
_context.next = 9;
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
_context.next = 7;
|
|
79
|
+
return (0, _geoserver.getGeoServerResponseText)(response);
|
|
80
|
+
|
|
81
|
+
case 7:
|
|
82
|
+
geoServerResponse = _context.sent;
|
|
83
|
+
throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
|
|
84
|
+
|
|
85
|
+
case 9:
|
|
86
|
+
case "end":
|
|
87
|
+
return _context.stop();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}, _callee, this);
|
|
91
|
+
}));
|
|
92
|
+
|
|
93
|
+
function reset() {
|
|
94
|
+
return _reset.apply(this, arguments);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return reset;
|
|
98
|
+
}()
|
|
99
|
+
/**
|
|
100
|
+
* Reloads the GeoServer catalog and configuration from disk. This operation
|
|
101
|
+
* is used in cases where an external tool has modified the on-disk
|
|
102
|
+
* configuration. This operation will also force GeoServer to drop any
|
|
103
|
+
* internal caches and reconnect to all data stores.
|
|
104
|
+
*
|
|
105
|
+
* @throws Error if request fails
|
|
106
|
+
*/
|
|
107
|
+
|
|
108
|
+
}, {
|
|
109
|
+
key: "reload",
|
|
110
|
+
value: function () {
|
|
111
|
+
var _reload = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
|
|
112
|
+
var url, response, geoServerResponse;
|
|
113
|
+
return _regenerator["default"].wrap(function _callee2$(_context2) {
|
|
114
|
+
while (1) {
|
|
115
|
+
switch (_context2.prev = _context2.next) {
|
|
116
|
+
case 0:
|
|
117
|
+
url = this.url + 'reload';
|
|
118
|
+
_context2.next = 3;
|
|
119
|
+
return (0, _nodeFetch["default"])(url, {
|
|
120
|
+
credentials: 'include',
|
|
121
|
+
method: 'POST',
|
|
122
|
+
headers: {
|
|
123
|
+
Authorization: this.auth
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
case 3:
|
|
128
|
+
response = _context2.sent;
|
|
129
|
+
|
|
130
|
+
if (response.ok) {
|
|
131
|
+
_context2.next = 9;
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
_context2.next = 7;
|
|
136
|
+
return (0, _geoserver.getGeoServerResponseText)(response);
|
|
137
|
+
|
|
138
|
+
case 7:
|
|
139
|
+
geoServerResponse = _context2.sent;
|
|
140
|
+
throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
|
|
141
|
+
|
|
142
|
+
case 9:
|
|
143
|
+
case "end":
|
|
144
|
+
return _context2.stop();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}, _callee2, this);
|
|
148
|
+
}));
|
|
149
|
+
|
|
150
|
+
function reload() {
|
|
151
|
+
return _reload.apply(this, arguments);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return reload;
|
|
155
|
+
}()
|
|
156
|
+
}]);
|
|
157
|
+
return ResetReloadClient;
|
|
158
|
+
}();
|
|
159
|
+
|
|
160
|
+
exports["default"] = ResetReloadClient;
|
package/geoserver-rest-client.js
CHANGED
|
@@ -7,6 +7,7 @@ import SecurityClient from './src/security.js';
|
|
|
7
7
|
import SettingsClient from './src/settings.js';
|
|
8
8
|
import NamespaceClient from './src/namespace.js';
|
|
9
9
|
import AboutClient from './src/about.js';
|
|
10
|
+
import ResetReloadClient from './src/reset-reload.js';
|
|
10
11
|
|
|
11
12
|
export { GeoServerResponseError } from './src/util/geoserver.js'
|
|
12
13
|
|
|
@@ -47,5 +48,7 @@ export class GeoServerRestClient {
|
|
|
47
48
|
this.settings = new SettingsClient(this.url, this.auth);
|
|
48
49
|
/** @member {AboutClient} about GeoServer REST client instance for about endpoint */
|
|
49
50
|
this.about = new AboutClient(this.url, this.auth);
|
|
51
|
+
/** @member {ResetReloadClient} about GeoServer REST client instance for reset/reload endpoints */
|
|
52
|
+
this.resetReload = new ResetReloadClient(this.url, this.auth);
|
|
50
53
|
}
|
|
51
54
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "geoserver-node-client",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Node.js client for GeoServer REST API",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "geoserver-rest-client.js",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"demo": "node demo/index.js",
|
|
9
|
-
"docs": "./node_modules/.bin/jsdoc geoserver-rest-client.js src/*.js DOCS_HOME.md",
|
|
9
|
+
"docs": "./node_modules/.bin/jsdoc geoserver-rest-client.js src/*.js DOCS_HOME.md && cp img/*.png out/",
|
|
10
10
|
"lint": "eslint src/**/*.js test/**/*.js scripts/**/*.js geoserver-rest-client.js",
|
|
11
11
|
"lint-fix": "eslint --fix src/**/*.js test/**/*.js scripts/**/*.js geoserver-rest-client.js",
|
|
12
12
|
"pretest": "npm run lint",
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
"author": "C. Mayer, meggsimum (info_at*meggsimum?dot?de)",
|
|
35
35
|
"license": "BSD-2-Clause",
|
|
36
36
|
"dependencies": {
|
|
37
|
+
"@babel/runtime": "^7.18.3",
|
|
37
38
|
"node-fetch": "^2.6.5"
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|
package/src/datastore.js
CHANGED
|
@@ -378,6 +378,41 @@ export default class DatastoreClient {
|
|
|
378
378
|
}
|
|
379
379
|
}
|
|
380
380
|
|
|
381
|
+
/**
|
|
382
|
+
* Creates a WMTS based data store.
|
|
383
|
+
*
|
|
384
|
+
* @param {String} workspace The WS to create the data store in
|
|
385
|
+
* @param {String} dataStore The data store name
|
|
386
|
+
* @param {String} wmtsCapabilitiesUrl Base WMTS capabilities URL
|
|
387
|
+
*
|
|
388
|
+
* @throws Error if request fails
|
|
389
|
+
*/
|
|
390
|
+
async createWmtsStore (workspace, dataStore, wmtsCapabilitiesUrl) {
|
|
391
|
+
const body = {
|
|
392
|
+
wmtsStore: {
|
|
393
|
+
name: dataStore,
|
|
394
|
+
type: 'WMTS',
|
|
395
|
+
capabilitiesURL: wmtsCapabilitiesUrl
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
const url = this.url + 'workspaces/' + workspace + '/wmtsstores';
|
|
400
|
+
const response = await fetch(url, {
|
|
401
|
+
credentials: 'include',
|
|
402
|
+
method: 'POST',
|
|
403
|
+
headers: {
|
|
404
|
+
Authorization: this.auth,
|
|
405
|
+
'Content-Type': 'application/json'
|
|
406
|
+
},
|
|
407
|
+
body: JSON.stringify(body)
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
if (!response.ok) {
|
|
411
|
+
const geoServerResponse = await getGeoServerResponseText(response);
|
|
412
|
+
throw new GeoServerResponseError(null, geoServerResponse);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
|
|
381
416
|
/**
|
|
382
417
|
* Creates a WFS based data store.
|
|
383
418
|
*
|
package/src/imagemosaic.js
CHANGED
|
@@ -23,7 +23,7 @@ export default class ImageMosaicClient {
|
|
|
23
23
|
*
|
|
24
24
|
* @param {String} workspace Workspace of image mosaic
|
|
25
25
|
* @param {String} coverageStore CoverageStore of image mosaic
|
|
26
|
-
* @param {
|
|
26
|
+
* @param {String} coverage Name of image mosaic
|
|
27
27
|
*
|
|
28
28
|
* @throws Error if request fails
|
|
29
29
|
*
|
package/src/layer.js
CHANGED
|
@@ -133,6 +133,103 @@ export default class LayerClient {
|
|
|
133
133
|
return response.json();
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
+
/**
|
|
137
|
+
* Get all layers of a workspace.
|
|
138
|
+
*
|
|
139
|
+
* @param {String} workspace The workspace
|
|
140
|
+
*
|
|
141
|
+
* @throws Error if request fails
|
|
142
|
+
*
|
|
143
|
+
* @return {Object} An object with the information about the layers
|
|
144
|
+
*/
|
|
145
|
+
async getLayers (workspace) {
|
|
146
|
+
const response = await fetch(this.url + 'workspaces/' + workspace + '/layers.json', {
|
|
147
|
+
credentials: 'include',
|
|
148
|
+
method: 'GET',
|
|
149
|
+
headers: {
|
|
150
|
+
Authorization: this.auth,
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
if (!response.ok) {
|
|
155
|
+
const geoServerResponse = await getGeoServerResponseText(response);
|
|
156
|
+
throw new GeoServerResponseError(null, geoServerResponse);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return await response.json();
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Returns information about a cascaded WMS layer.
|
|
164
|
+
*
|
|
165
|
+
* @param {String} workspace The workspace
|
|
166
|
+
* @param {String} datastore The datastore
|
|
167
|
+
* @param {String} layerName The WMS layer name
|
|
168
|
+
*
|
|
169
|
+
* @throws Error if request fails
|
|
170
|
+
*
|
|
171
|
+
* @returns {Object} An object with layer information or undefined if it cannot be found
|
|
172
|
+
*/
|
|
173
|
+
async getWmsLayer (workspace, datastore, layerName) {
|
|
174
|
+
const response = await fetch(this.url + 'workspaces/' + workspace + '/wmsstores/' + datastore + '/wmslayers/' + layerName + '.json', {
|
|
175
|
+
credentials: 'include',
|
|
176
|
+
method: 'GET',
|
|
177
|
+
headers: {
|
|
178
|
+
Authorization: this.auth,
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
if (!response.ok) {
|
|
183
|
+
const grc = new AboutClient(this.url, this.auth);
|
|
184
|
+
if (await grc.exists()) {
|
|
185
|
+
// GeoServer exists, but requested item does not exist, we return empty
|
|
186
|
+
return;
|
|
187
|
+
} else {
|
|
188
|
+
// There was a general problem with GeoServer
|
|
189
|
+
const geoServerResponse = await getGeoServerResponseText(response);
|
|
190
|
+
throw new GeoServerResponseError(null, geoServerResponse);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return await response.json();
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// TODO: automated test needed
|
|
198
|
+
/**
|
|
199
|
+
* Returns information about a cascaded WMTS layer.
|
|
200
|
+
*
|
|
201
|
+
* @param {String} workspace The workspace
|
|
202
|
+
* @param {String} datastore The datastore
|
|
203
|
+
* @param {String} layerName The WMTS layer name
|
|
204
|
+
*
|
|
205
|
+
* @throws Error if request fails
|
|
206
|
+
*
|
|
207
|
+
* @returns {Object} An object with layer information or undefined if it cannot be found
|
|
208
|
+
*/
|
|
209
|
+
async getWmtsLayer (workspace, datastore, layerName) {
|
|
210
|
+
const response = await fetch(this.url + 'workspaces/' + workspace + '/wmtsstores/' + datastore + '/layers/' + layerName + '.json', {
|
|
211
|
+
credentials: 'include',
|
|
212
|
+
method: 'GET',
|
|
213
|
+
headers: {
|
|
214
|
+
Authorization: this.auth,
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
if (!response.ok) {
|
|
219
|
+
const grc = new AboutClient(this.url, this.auth);
|
|
220
|
+
if (await grc.exists()) {
|
|
221
|
+
// GeoServer exists, but requested item does not exist, we return empty
|
|
222
|
+
return;
|
|
223
|
+
} else {
|
|
224
|
+
// There was a general problem with GeoServer
|
|
225
|
+
const geoServerResponse = await getGeoServerResponseText(response);
|
|
226
|
+
throw new GeoServerResponseError(null, geoServerResponse);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return await response.json();
|
|
231
|
+
}
|
|
232
|
+
|
|
136
233
|
/**
|
|
137
234
|
* Publishes a FeatureType in the default data store of the workspace.
|
|
138
235
|
*
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import fetch from 'node-fetch';
|
|
2
|
+
import { GeoServerResponseError, getGeoServerResponseText } from './util/geoserver.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Client for GeoServer "Reset/Reload" to clear internal caches and reload
|
|
6
|
+
* configuration from disk endpoint.
|
|
7
|
+
*
|
|
8
|
+
* @module ResetReloadClient
|
|
9
|
+
*/
|
|
10
|
+
export default class ResetReloadClient {
|
|
11
|
+
/**
|
|
12
|
+
* Creates a GeoServer REST ResetReloadClient instance.
|
|
13
|
+
*
|
|
14
|
+
* @param {String} url The URL of the GeoServer REST API endpoint
|
|
15
|
+
* @param {String} auth The Basic Authentication string
|
|
16
|
+
*/
|
|
17
|
+
constructor (url, auth) {
|
|
18
|
+
this.url = url;
|
|
19
|
+
this.auth = auth;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Resets all store, raster, and schema caches. This operation is used to
|
|
24
|
+
* force GeoServer to drop all caches and store connections and reconnect to
|
|
25
|
+
* each of them the next time they are needed by a request.
|
|
26
|
+
* This is useful in case the stores themselves cache some information about
|
|
27
|
+
* the data structures they manage that may have changed in the meantime.
|
|
28
|
+
*
|
|
29
|
+
* @throws Error if request fails
|
|
30
|
+
*/
|
|
31
|
+
async reset () {
|
|
32
|
+
const url = this.url + 'reset';
|
|
33
|
+
const response = await fetch(url, {
|
|
34
|
+
credentials: 'include',
|
|
35
|
+
method: 'POST',
|
|
36
|
+
headers: {
|
|
37
|
+
Authorization: this.auth
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
if (!response.ok) {
|
|
42
|
+
const geoServerResponse = await getGeoServerResponseText(response);
|
|
43
|
+
throw new GeoServerResponseError(null, geoServerResponse);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Reloads the GeoServer catalog and configuration from disk. This operation
|
|
49
|
+
* is used in cases where an external tool has modified the on-disk
|
|
50
|
+
* configuration. This operation will also force GeoServer to drop any
|
|
51
|
+
* internal caches and reconnect to all data stores.
|
|
52
|
+
*
|
|
53
|
+
* @throws Error if request fails
|
|
54
|
+
*/
|
|
55
|
+
async reload () {
|
|
56
|
+
const url = this.url + 'reload';
|
|
57
|
+
const response = await fetch(url, {
|
|
58
|
+
credentials: 'include',
|
|
59
|
+
method: 'POST',
|
|
60
|
+
headers: {
|
|
61
|
+
Authorization: this.auth
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
if (!response.ok) {
|
|
66
|
+
const geoServerResponse = await getGeoServerResponseText(response);
|
|
67
|
+
throw new GeoServerResponseError(null, geoServerResponse);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|