geoserver-node-client 0.0.6 → 0.0.7
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 +3 -0
- package/package.json +3 -2
- package/src/style.js +60 -1
- package/test/test.js +11 -0
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "geoserver-node-client",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
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
9
|
"docs": "./node_modules/.bin/jsdoc geoserver-rest-client.js src/*.js DOCS_HOME.md",
|
|
10
|
-
"lint": "eslint
|
|
10
|
+
"lint": "eslint '**/*.js' --ignore-pattern node_modules/ --ignore-pattern out/",
|
|
11
|
+
"lint-fix": "eslint --fix '**/*.js' --ignore-pattern node_modules/ --ignore-pattern out/",
|
|
11
12
|
"pretest": "npm run lint",
|
|
12
13
|
"test": "mocha --timeout 10000",
|
|
13
14
|
"release": "release-it"
|
package/src/style.js
CHANGED
|
@@ -128,7 +128,7 @@ export default class StyleClient {
|
|
|
128
128
|
/**
|
|
129
129
|
* Publishes a new SLD style.
|
|
130
130
|
*
|
|
131
|
-
* @param {String} workspace The workspace to publish style in
|
|
131
|
+
* @param {String} workspace The workspace to publish the style in
|
|
132
132
|
* @param {String} name Name of the style
|
|
133
133
|
* @param {String} sldBody SLD style (as XML text)
|
|
134
134
|
*
|
|
@@ -158,6 +158,65 @@ export default class StyleClient {
|
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
160
|
|
|
161
|
+
/**
|
|
162
|
+
* Deletes a style.
|
|
163
|
+
*
|
|
164
|
+
* @param {String} workspace The name of the workspace, can be undefined if style is not assigned to a workspace
|
|
165
|
+
* @param {String} name The name of the style to delete
|
|
166
|
+
* @param {Boolean} [recurse=false] If references to the specified style in existing layers should be deleted
|
|
167
|
+
* @param {Boolean} [purge=false] Whether the underlying file containing the style should be deleted on disk
|
|
168
|
+
*
|
|
169
|
+
* @returns {Boolean} If the style could be deleted
|
|
170
|
+
*/
|
|
171
|
+
async delete (workspace, name, recurse, purge) {
|
|
172
|
+
let paramPurge = false;
|
|
173
|
+
let paramRecurse = false;
|
|
174
|
+
|
|
175
|
+
if (purge === true) {
|
|
176
|
+
paramPurge = true;
|
|
177
|
+
}
|
|
178
|
+
if (recurse === true) {
|
|
179
|
+
paramRecurse = true;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
try {
|
|
183
|
+
const auth = Buffer.from(this.user + ':' + this.password).toString('base64');
|
|
184
|
+
let endpoint;
|
|
185
|
+
|
|
186
|
+
if (workspace) {
|
|
187
|
+
// delete style inside workspace
|
|
188
|
+
endpoint = this.url + 'workspaces/' + workspace + '/styles/' + name +
|
|
189
|
+
'?' + 'purge=' + paramPurge + '&' + 'recurse=' + paramRecurse;
|
|
190
|
+
} else {
|
|
191
|
+
// delete style without workspace
|
|
192
|
+
endpoint = this.url + 'styles/' + name +
|
|
193
|
+
'?' + 'purge=' + paramPurge + '&' + 'recurse=' + paramRecurse;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const response = await fetch(endpoint, {
|
|
197
|
+
credentials: 'include',
|
|
198
|
+
method: 'DELETE',
|
|
199
|
+
headers: {
|
|
200
|
+
Authorization: 'Basic ' + auth
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
if (response.ok) {
|
|
205
|
+
return true;
|
|
206
|
+
} else if (response.status === 403) {
|
|
207
|
+
console.warn('Deletion failed. There might be dependant objects to ' +
|
|
208
|
+
'this style. Delete them first or call this with "recurse=false"');
|
|
209
|
+
console.warn(await response.text());
|
|
210
|
+
return false;
|
|
211
|
+
} else {
|
|
212
|
+
console.warn(await response.text());
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
} catch (error) {
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
161
220
|
/**
|
|
162
221
|
* Assigns a style to a layer.
|
|
163
222
|
*
|
package/test/test.js
CHANGED
|
@@ -452,6 +452,17 @@ describe('style', () => {
|
|
|
452
452
|
expect(result.length).to.equal(1);
|
|
453
453
|
})
|
|
454
454
|
|
|
455
|
+
it('can delete a style', async () => {
|
|
456
|
+
let recurse = false;
|
|
457
|
+
const purge = false;
|
|
458
|
+
const withOutRecurse = await grc.styles.delete(workSpace, styleName, recurse, purge)
|
|
459
|
+
expect(withOutRecurse).to.be.false;
|
|
460
|
+
|
|
461
|
+
recurse = true;
|
|
462
|
+
const withRecurse = await grc.styles.delete(workSpace, styleName, recurse, purge)
|
|
463
|
+
expect(withRecurse).to.be.true;
|
|
464
|
+
});
|
|
465
|
+
|
|
455
466
|
after('delete Workspace', async () => {
|
|
456
467
|
const recursive = true;
|
|
457
468
|
await grc.workspaces.delete(createdWorkSpace, recursive);
|