legispro-cli 1.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/LICENSE +21 -0
- package/README.md +696 -0
- package/bin/dev +17 -0
- package/bin/dev.cmd +3 -0
- package/bin/run +5 -0
- package/bin/run.cmd +3 -0
- package/dist/commands/backup/create.d.ts +7 -0
- package/dist/commands/backup/create.js +26 -0
- package/dist/commands/backup/list.d.ts +7 -0
- package/dist/commands/backup/list.js +38 -0
- package/dist/commands/collection/add.d.ts +12 -0
- package/dist/commands/collection/add.js +108 -0
- package/dist/commands/collection/create.d.ts +14 -0
- package/dist/commands/collection/create.js +132 -0
- package/dist/commands/collection/delete.d.ts +10 -0
- package/dist/commands/collection/delete.js +53 -0
- package/dist/commands/collection/download.d.ts +11 -0
- package/dist/commands/collection/download.js +87 -0
- package/dist/commands/collection/get.d.ts +10 -0
- package/dist/commands/collection/get.js +54 -0
- package/dist/commands/collection/list.d.ts +7 -0
- package/dist/commands/collection/list.js +25 -0
- package/dist/commands/collection/perms.d.ts +12 -0
- package/dist/commands/collection/perms.js +82 -0
- package/dist/commands/collection/update.d.ts +16 -0
- package/dist/commands/collection/update.js +174 -0
- package/dist/commands/collection/upload.d.ts +12 -0
- package/dist/commands/collection/upload.js +127 -0
- package/dist/commands/config/get.d.ts +1 -0
- package/dist/commands/config/get.js +19 -0
- package/dist/commands/config/set.d.ts +1 -0
- package/dist/commands/config/set.js +125 -0
- package/dist/commands/db/init.d.ts +7 -0
- package/dist/commands/db/init.js +90 -0
- package/dist/commands/db/memory.d.ts +7 -0
- package/dist/commands/db/memory.js +27 -0
- package/dist/commands/db/uptime.d.ts +7 -0
- package/dist/commands/db/uptime.js +17 -0
- package/dist/commands/db/version.d.ts +7 -0
- package/dist/commands/db/version.js +17 -0
- package/dist/commands/document/copy.d.ts +7 -0
- package/dist/commands/document/copy.js +35 -0
- package/dist/commands/document/list.d.ts +7 -0
- package/dist/commands/document/list.js +34 -0
- package/dist/commands/group/create.d.ts +14 -0
- package/dist/commands/group/create.js +132 -0
- package/dist/commands/group/delete.d.ts +10 -0
- package/dist/commands/group/delete.js +50 -0
- package/dist/commands/group/get.d.ts +10 -0
- package/dist/commands/group/get.js +51 -0
- package/dist/commands/group/list.d.ts +7 -0
- package/dist/commands/group/list.js +20 -0
- package/dist/commands/group/update.d.ts +14 -0
- package/dist/commands/group/update.js +132 -0
- package/dist/commands/locks/add.d.ts +7 -0
- package/dist/commands/locks/add.js +80 -0
- package/dist/commands/locks/clear.d.ts +7 -0
- package/dist/commands/locks/clear.js +23 -0
- package/dist/commands/locks/list.d.ts +7 -0
- package/dist/commands/locks/list.js +86 -0
- package/dist/commands/services/health.d.ts +8 -0
- package/dist/commands/services/health.js +66 -0
- package/dist/commands/user/create.d.ts +26 -0
- package/dist/commands/user/create.js +374 -0
- package/dist/commands/user/delete.d.ts +10 -0
- package/dist/commands/user/delete.js +58 -0
- package/dist/commands/user/get.d.ts +10 -0
- package/dist/commands/user/get.js +53 -0
- package/dist/commands/user/list.d.ts +7 -0
- package/dist/commands/user/list.js +24 -0
- package/dist/commands/user/login.d.ts +13 -0
- package/dist/commands/user/login.js +93 -0
- package/dist/commands/user/update.d.ts +25 -0
- package/dist/commands/user/update.js +267 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +5 -0
- package/dist/lib/fusiondb-client.d.ts +52 -0
- package/dist/lib/fusiondb-client.js +655 -0
- package/dist/lib/rclone-client.d.ts +11 -0
- package/dist/lib/rclone-client.js +41 -0
- package/dist/lib/types.d.ts +79 -0
- package/dist/lib/types.js +2 -0
- package/dist/lib/utils.d.ts +4 -0
- package/dist/lib/utils.js +7 -0
- package/dist/lib/xml-templates.d.ts +6 -0
- package/dist/lib/xml-templates.js +66 -0
- package/oclif.manifest.json +1063 -0
- package/package.json +98 -0
|
@@ -0,0 +1,655 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FusiondbClient = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const axios_1 = tslib_1.__importDefault(require("axios"));
|
|
6
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
7
|
+
const xpath = require('xpath'), dom = require('xmldom').DOMParser;
|
|
8
|
+
class FusiondbClient {
|
|
9
|
+
constructor() {
|
|
10
|
+
}
|
|
11
|
+
static get instance() {
|
|
12
|
+
return this._instance;
|
|
13
|
+
}
|
|
14
|
+
setConfig(cmd) {
|
|
15
|
+
const configFile = path_1.default.join(cmd.config.configDir, 'config.json');
|
|
16
|
+
const env = require(configFile);
|
|
17
|
+
this._baseUrl = env.protocol + "://" + env.hostname + ":" + env.port;
|
|
18
|
+
this._auth = Buffer.from(`${env.user}:${env.password}`).toString('base64');
|
|
19
|
+
this._headers = {
|
|
20
|
+
"Authorization": "Basic " + this._auth,
|
|
21
|
+
"content-type": "application/json",
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
// =========================================================================
|
|
25
|
+
// ========================== HTTP METHODS =================================
|
|
26
|
+
// =========================================================================
|
|
27
|
+
get(url) {
|
|
28
|
+
return (0, axios_1.default)({
|
|
29
|
+
method: 'GET',
|
|
30
|
+
url: this._baseUrl + "/exist/restxq/fusiondb" + url,
|
|
31
|
+
headers: this._headers
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
put(url, data) {
|
|
35
|
+
return (0, axios_1.default)({
|
|
36
|
+
method: 'PUT',
|
|
37
|
+
url: this._baseUrl + "/exist/restxq/fusiondb" + url,
|
|
38
|
+
headers: this._headers,
|
|
39
|
+
data: JSON.stringify(data)
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
putXml(url, data) {
|
|
43
|
+
return (0, axios_1.default)({
|
|
44
|
+
method: 'PUT',
|
|
45
|
+
url: this._baseUrl + "/exist/restxq/fusiondb/document?uri=" + url,
|
|
46
|
+
headers: {
|
|
47
|
+
"Authorization": "Basic " + this._auth,
|
|
48
|
+
"content-type": "text/xml"
|
|
49
|
+
},
|
|
50
|
+
data: data
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
delete(url) {
|
|
54
|
+
return (0, axios_1.default)({
|
|
55
|
+
method: 'DELETE',
|
|
56
|
+
url: this._baseUrl + "/exist/restxq/fusiondb" + url,
|
|
57
|
+
headers: this._headers
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
post(url, data) {
|
|
61
|
+
return (0, axios_1.default)({
|
|
62
|
+
method: 'POST',
|
|
63
|
+
url: this._baseUrl + "/exist/restxq/fusiondb" + url,
|
|
64
|
+
headers: this._headers,
|
|
65
|
+
data: JSON.stringify(data)
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
raw_post(url, headers, data) {
|
|
69
|
+
return (0, axios_1.default)({
|
|
70
|
+
method: 'POST',
|
|
71
|
+
url: this._baseUrl + url,
|
|
72
|
+
headers: headers,
|
|
73
|
+
data: data
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
getMeta(meta, key) {
|
|
77
|
+
let alias = {};
|
|
78
|
+
alias = {
|
|
79
|
+
"firstName": "http://axschema.org/namePerson/first",
|
|
80
|
+
"lastName": "http://axschema.org/namePerson/last",
|
|
81
|
+
"fullName": "http://axschema.org/namePerson",
|
|
82
|
+
"alias": "http://axschema.org/namePerson/friendly",
|
|
83
|
+
"timezone": "http://axschema.org/pref/timezone",
|
|
84
|
+
"country": "http://axschema.org/contact/country/home",
|
|
85
|
+
"language": "http://axschema.org/pref/language",
|
|
86
|
+
"description": "http://exist-db.org/security/description",
|
|
87
|
+
"email": "http://axschema.org/contact/email",
|
|
88
|
+
};
|
|
89
|
+
let match = meta.filter(function (m) {
|
|
90
|
+
return m.key === alias[key];
|
|
91
|
+
});
|
|
92
|
+
return match[0] ? match[0].value : null;
|
|
93
|
+
}
|
|
94
|
+
setMeta(flags) {
|
|
95
|
+
let meta = [];
|
|
96
|
+
if (flags.alias) {
|
|
97
|
+
meta.push({
|
|
98
|
+
key: "http://axschema.org/namePerson/friendly",
|
|
99
|
+
value: flags.alias
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
if (flags.timezone) {
|
|
103
|
+
meta.push({
|
|
104
|
+
key: "http://axschema.org/pref/timezone",
|
|
105
|
+
value: flags.timezone
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
if (flags.firstName) {
|
|
109
|
+
meta.push({
|
|
110
|
+
key: "http://axschema.org/namePerson/first",
|
|
111
|
+
value: flags.firstName
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
if (flags.lastName) {
|
|
115
|
+
meta.push({
|
|
116
|
+
key: "http://axschema.org/namePerson/last",
|
|
117
|
+
value: flags.lastName
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
if (flags.fullName) {
|
|
121
|
+
meta.push({
|
|
122
|
+
key: "http://axschema.org/namePerson",
|
|
123
|
+
value: flags.fullName
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
if (flags.email) {
|
|
127
|
+
meta.push({
|
|
128
|
+
key: "http://axschema.org/contact/email",
|
|
129
|
+
value: flags.email
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
if (flags.description) {
|
|
133
|
+
meta.push({
|
|
134
|
+
key: "http://exist-db.org/security/description",
|
|
135
|
+
value: flags.description
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
if (flags.language) {
|
|
139
|
+
meta.push({
|
|
140
|
+
key: "http://axschema.org/pref/language",
|
|
141
|
+
value: flags.language
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
if (flags.country) {
|
|
145
|
+
meta.push({
|
|
146
|
+
key: "http://axschema.org/contact/country/home",
|
|
147
|
+
value: flags.country
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
return meta;
|
|
151
|
+
}
|
|
152
|
+
// =========================================================================
|
|
153
|
+
// ============================== USERS ====================================
|
|
154
|
+
// =========================================================================
|
|
155
|
+
async getUsers() {
|
|
156
|
+
const result = await this.get("/user");
|
|
157
|
+
// console.log(result);
|
|
158
|
+
return result.data;
|
|
159
|
+
}
|
|
160
|
+
async getUser(username) {
|
|
161
|
+
try {
|
|
162
|
+
this._userName = username;
|
|
163
|
+
const response = await this.get("/user/" + this._userName);
|
|
164
|
+
return response;
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
if (error.response.status !== 200) {
|
|
168
|
+
return error.response;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
async createUser(user) {
|
|
173
|
+
try {
|
|
174
|
+
const response = await this.put("/user/" + user.userName, user);
|
|
175
|
+
let status = response.status;
|
|
176
|
+
// console.log(response);
|
|
177
|
+
if (status == 204)
|
|
178
|
+
return `${user.userName} created`;
|
|
179
|
+
}
|
|
180
|
+
catch (error) {
|
|
181
|
+
return error.response.statusText;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
async deleteUser(userName) {
|
|
185
|
+
this._userName = userName;
|
|
186
|
+
try {
|
|
187
|
+
const response = await this.delete("/user/" + this._userName);
|
|
188
|
+
return response;
|
|
189
|
+
}
|
|
190
|
+
catch (error) {
|
|
191
|
+
return error.response;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
// =========================================================================
|
|
195
|
+
// ============================== GROUPS ===================================
|
|
196
|
+
// =========================================================================
|
|
197
|
+
async getGroups() {
|
|
198
|
+
try {
|
|
199
|
+
const response = await this.get("/group");
|
|
200
|
+
return response.data;
|
|
201
|
+
}
|
|
202
|
+
catch (error) {
|
|
203
|
+
// console.log(error);
|
|
204
|
+
if (error.response.status !== 200) {
|
|
205
|
+
return error.response.statusText;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
async getGroup(groupName) {
|
|
210
|
+
this._groupName = groupName;
|
|
211
|
+
try {
|
|
212
|
+
const response = await this.get("/group/" + this._groupName);
|
|
213
|
+
return response;
|
|
214
|
+
}
|
|
215
|
+
catch (error) {
|
|
216
|
+
// console.log(error);
|
|
217
|
+
if (error.response.status !== 200) {
|
|
218
|
+
return error.response;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
async createGroup(group) {
|
|
223
|
+
try {
|
|
224
|
+
const response = await this.put("/group/" + group.groupName, group);
|
|
225
|
+
return response;
|
|
226
|
+
}
|
|
227
|
+
catch (error) {
|
|
228
|
+
return error.response;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
async deleteGroup(groupName) {
|
|
232
|
+
this._groupName = groupName;
|
|
233
|
+
try {
|
|
234
|
+
const response = await this.delete("/group/" + this._groupName);
|
|
235
|
+
// console.log(response);
|
|
236
|
+
return response;
|
|
237
|
+
}
|
|
238
|
+
catch (error) {
|
|
239
|
+
return error.response;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
// =========================================================================
|
|
243
|
+
// ============================== COLLECTIONS ==============================
|
|
244
|
+
// =========================================================================
|
|
245
|
+
async getCollection(uri) {
|
|
246
|
+
try {
|
|
247
|
+
const response = await this.get("/explorer?uri=" + uri);
|
|
248
|
+
// console.log(response);
|
|
249
|
+
return response.data;
|
|
250
|
+
}
|
|
251
|
+
catch (error) {
|
|
252
|
+
// console.log(error);
|
|
253
|
+
if (error.response.status !== 200) {
|
|
254
|
+
return error.response.statusText;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
async getCollectionObject(uri) {
|
|
259
|
+
try {
|
|
260
|
+
const response = await this.get("/explorer?uri=" + uri);
|
|
261
|
+
let coll = response.data;
|
|
262
|
+
let collection = {
|
|
263
|
+
uri: coll.uri,
|
|
264
|
+
owner: coll.owner,
|
|
265
|
+
group: coll.group,
|
|
266
|
+
mode: coll.mode
|
|
267
|
+
};
|
|
268
|
+
return collection;
|
|
269
|
+
}
|
|
270
|
+
catch (error) {
|
|
271
|
+
if (error.response.status !== 200) {
|
|
272
|
+
return error.response.statusText;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
async getCollectionProject(uri) {
|
|
277
|
+
try {
|
|
278
|
+
const response = await this.get("/document?uri=" + uri + '/.project.xml');
|
|
279
|
+
// console.log(response);
|
|
280
|
+
let doc = new dom().parseFromString(response.data);
|
|
281
|
+
let select = xpath.useNamespaces({ "doc": "http://www.xcential.com/schemas/docs" });
|
|
282
|
+
let name = select("//doc:name/text()", doc)[0].nodeValue;
|
|
283
|
+
let title = select("//doc:title/text()", doc)[0].nodeValue;
|
|
284
|
+
let baseURI = select("//doc:baseURI/text()", doc)[0].nodeValue;
|
|
285
|
+
let defaultExt = select("//doc:defaultExt/text()", doc)[0].nodeValue;
|
|
286
|
+
let type = select("//doc:type/text()", doc)[0].nodeValue;
|
|
287
|
+
let project = {
|
|
288
|
+
name: name,
|
|
289
|
+
title: title,
|
|
290
|
+
baseURI: baseURI,
|
|
291
|
+
defaultExt: defaultExt,
|
|
292
|
+
type: type
|
|
293
|
+
};
|
|
294
|
+
return project;
|
|
295
|
+
}
|
|
296
|
+
catch (error) {
|
|
297
|
+
// console.log(error);
|
|
298
|
+
if (error.response.status !== 200) {
|
|
299
|
+
return null;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
async existsCollection(uri) {
|
|
304
|
+
try {
|
|
305
|
+
const response = await this.get("/explorer?uri=" + uri);
|
|
306
|
+
if (response.status !== 200) {
|
|
307
|
+
return false;
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
return true;
|
|
311
|
+
}
|
|
312
|
+
return response.data;
|
|
313
|
+
}
|
|
314
|
+
catch (error) {
|
|
315
|
+
return false;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
async createCollection(collection) {
|
|
319
|
+
try {
|
|
320
|
+
const response = await this.put("/collection?uri=" + collection.uri, collection);
|
|
321
|
+
return response;
|
|
322
|
+
// let status = response.status;
|
|
323
|
+
// // console.log(response);
|
|
324
|
+
// if (status == 201)
|
|
325
|
+
// return `${collection.uri} created`;
|
|
326
|
+
}
|
|
327
|
+
catch (error) {
|
|
328
|
+
return error.response.statusText;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
async modifyCollection(collection) {
|
|
332
|
+
try {
|
|
333
|
+
const response = await this.post("/collection?uri=" + collection.uri, collection);
|
|
334
|
+
return response;
|
|
335
|
+
// let status = response.status;
|
|
336
|
+
// // console.log(response);
|
|
337
|
+
// if (status == 201)
|
|
338
|
+
// return `${collection.uri} created`;
|
|
339
|
+
}
|
|
340
|
+
catch (error) {
|
|
341
|
+
return error.response.statusText;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
async deleteCollection(uri) {
|
|
345
|
+
try {
|
|
346
|
+
const response = await this.delete("/collection?uri=" + uri);
|
|
347
|
+
//console.log(response);
|
|
348
|
+
return response;
|
|
349
|
+
}
|
|
350
|
+
catch (error) {
|
|
351
|
+
// console.log(error);
|
|
352
|
+
if (error.response.status !== 204) {
|
|
353
|
+
return error.response.statusText;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
// =========================================================================
|
|
358
|
+
// ============================== DOCUMENTS ================================
|
|
359
|
+
// =========================================================================
|
|
360
|
+
async createDocument(uri, data) {
|
|
361
|
+
try {
|
|
362
|
+
const response = await this.putXml(uri, data);
|
|
363
|
+
return response;
|
|
364
|
+
}
|
|
365
|
+
catch (error) {
|
|
366
|
+
return error.response;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
async updateDocumentProperties(document) {
|
|
370
|
+
try {
|
|
371
|
+
const response = await this.post("/document?uri=" + document.uri, document);
|
|
372
|
+
// let status = response.status;
|
|
373
|
+
// console.log(response);
|
|
374
|
+
return response;
|
|
375
|
+
// if (status == 201)
|
|
376
|
+
// return `${collection.uri} created`;
|
|
377
|
+
}
|
|
378
|
+
catch (error) {
|
|
379
|
+
// console.log(error);
|
|
380
|
+
return error.response;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
// =========================================================================
|
|
384
|
+
// ============================== QUERIES ==================================
|
|
385
|
+
// =========================================================================
|
|
386
|
+
async updateUserCollectionPerms(owner) {
|
|
387
|
+
try {
|
|
388
|
+
let user_mode = 'rwxrwsr-T';
|
|
389
|
+
let scratchpad_mode = 'rw-r--r--';
|
|
390
|
+
let chmod_query = {
|
|
391
|
+
"query": "import module namespace dbutil='http://exist-db.org/xquery/dbutil' " +
|
|
392
|
+
"at 'xmldb:exist:///db/apps/fundocs/modules/dbutil.xqm'; " +
|
|
393
|
+
"dbutil:scan(xs:anyURI('/db/repository/" + owner + "'), " +
|
|
394
|
+
"function($c, $r) { if ($r and xmldb:get-mime-type($r) = 'application/xml') " +
|
|
395
|
+
"then sm:chmod($r, '" + user_mode + "') else () })",
|
|
396
|
+
"defaultSerialization": {}
|
|
397
|
+
};
|
|
398
|
+
const chmod_response = await this.post("/query", chmod_query);
|
|
399
|
+
let chown_query = {
|
|
400
|
+
"query": "import module namespace dbutil='http://exist-db.org/xquery/dbutil' " +
|
|
401
|
+
"at 'xmldb:exist:///db/apps/fundocs/modules/dbutil.xqm'; " +
|
|
402
|
+
"dbutil:scan(xs:anyURI('/db/repository/" + owner + "'), " +
|
|
403
|
+
"function($c, $r) { if ($r and xmldb:get-mime-type($r) = 'application/xml') " +
|
|
404
|
+
"then sm:chown($r, '" + owner + "') else () })",
|
|
405
|
+
"defaultSerialization": {}
|
|
406
|
+
};
|
|
407
|
+
const chown_response = await this.post("/query", chown_query);
|
|
408
|
+
// special case for scratchpad.xml
|
|
409
|
+
// let chmod_scratchpad_query =
|
|
410
|
+
// {
|
|
411
|
+
// "query": "sm:chmod(xs:anyURI('/db/repository/"+owner+"/akn-"+env.gov_group+"-data-scratchpad.xml'), '" +
|
|
412
|
+
// scratchpad_mode +"')",
|
|
413
|
+
// "defaultSerialization": {}
|
|
414
|
+
// }
|
|
415
|
+
// const chmod_scratchpad_response = await this.post("/query", chmod_scratchpad_query);
|
|
416
|
+
return chmod_response;
|
|
417
|
+
}
|
|
418
|
+
catch (error) {
|
|
419
|
+
return error.response;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
async updateLibraryCollectionPerms(owner) {
|
|
423
|
+
try {
|
|
424
|
+
let mode = 'rwxr-sr-T';
|
|
425
|
+
let chmod_query = {
|
|
426
|
+
"query": "import module namespace dbutil='http://exist-db.org/xquery/dbutil' " +
|
|
427
|
+
"at 'xmldb:exist:///db/apps/fundocs/modules/dbutil.xqm'; " +
|
|
428
|
+
"dbutil:scan(xs:anyURI('/db/repository/" + owner + "'), " +
|
|
429
|
+
"function($c, $r) { if ($r and xmldb:get-mime-type($r) = 'application/xml') " +
|
|
430
|
+
"then sm:chmod($r, '" + mode + "') else () })",
|
|
431
|
+
"defaultSerialization": {}
|
|
432
|
+
};
|
|
433
|
+
const chmod_response = await this.post("/query", chmod_query);
|
|
434
|
+
let chown_query = {
|
|
435
|
+
"query": "import module namespace dbutil='http://exist-db.org/xquery/dbutil' " +
|
|
436
|
+
"at 'xmldb:exist:///db/apps/fundocs/modules/dbutil.xqm'; " +
|
|
437
|
+
"dbutil:scan(xs:anyURI('/db/repository/" + owner + "'), " +
|
|
438
|
+
"function($c, $r) { if ($r and xmldb:get-mime-type($r) = 'application/xml') " +
|
|
439
|
+
"then sm:chown($r, '" + owner + "') else () })",
|
|
440
|
+
"defaultSerialization": {}
|
|
441
|
+
};
|
|
442
|
+
const chown_response = await this.post("/query", chown_query);
|
|
443
|
+
return chmod_response;
|
|
444
|
+
}
|
|
445
|
+
catch (error) {
|
|
446
|
+
return error.response;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
async updateSharedCollectionPerms(owner) {
|
|
450
|
+
try {
|
|
451
|
+
let mode = 'rwxrwsr-T';
|
|
452
|
+
let chmod_query = {
|
|
453
|
+
"query": "import module namespace dbutil='http://exist-db.org/xquery/dbutil' " +
|
|
454
|
+
"at 'xmldb:exist:///db/apps/fundocs/modules/dbutil.xqm'; " +
|
|
455
|
+
"dbutil:scan(xs:anyURI('/db/repository/" + owner + "'), " +
|
|
456
|
+
"function($c, $r) { if ($r and xmldb:get-mime-type($r) = 'application/xml') " +
|
|
457
|
+
"then sm:chmod($r, '" + mode + "') else () })",
|
|
458
|
+
"defaultSerialization": {}
|
|
459
|
+
};
|
|
460
|
+
const chmod_response = await this.post("/query", chmod_query);
|
|
461
|
+
let chown_query = {
|
|
462
|
+
"query": "import module namespace dbutil='http://exist-db.org/xquery/dbutil' " +
|
|
463
|
+
"at 'xmldb:exist:///db/apps/fundocs/modules/dbutil.xqm'; " +
|
|
464
|
+
"dbutil:scan(xs:anyURI('/db/repository/" + owner + "'), " +
|
|
465
|
+
"function($c, $r) { if ($r and xmldb:get-mime-type($r) = 'application/xml') " +
|
|
466
|
+
"then sm:chown($r, '" + owner + "') else () })",
|
|
467
|
+
"defaultSerialization": {}
|
|
468
|
+
};
|
|
469
|
+
const chown_response = await this.post("/query", chown_query);
|
|
470
|
+
return chmod_response;
|
|
471
|
+
}
|
|
472
|
+
catch (error) {
|
|
473
|
+
return error.response;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
async backupDatabase() {
|
|
477
|
+
try {
|
|
478
|
+
let backup_query = {
|
|
479
|
+
"query": "let $params :=\n" +
|
|
480
|
+
" <parameters>\n" +
|
|
481
|
+
" <param name=\"output\" value=\"backups\"/>\n" +
|
|
482
|
+
" <param name=\"backup\" value=\"yes\"/>\n" +
|
|
483
|
+
" <param name=\"zip\" value=\"no\"/>\n" +
|
|
484
|
+
" <param name=\"incremental\" value=\"no\"/>\n" +
|
|
485
|
+
" </parameters>\n" +
|
|
486
|
+
" return\n" +
|
|
487
|
+
" system:trigger-system-task(\"org.exist.storage.ConsistencyCheckTask\", $params)"
|
|
488
|
+
};
|
|
489
|
+
const backup_response = await this.post("/query", backup_query);
|
|
490
|
+
return backup_response;
|
|
491
|
+
}
|
|
492
|
+
catch (error) {
|
|
493
|
+
return error.response;
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
async listBackups() {
|
|
497
|
+
try {
|
|
498
|
+
let list_backups_query = {
|
|
499
|
+
"query": "backups:list(\"backups\")"
|
|
500
|
+
};
|
|
501
|
+
const backup_response = await this.post("/query", list_backups_query);
|
|
502
|
+
return backup_response;
|
|
503
|
+
}
|
|
504
|
+
catch (error) {
|
|
505
|
+
return error.response;
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
async clearExpiredLocks() {
|
|
509
|
+
try {
|
|
510
|
+
let headers = {
|
|
511
|
+
"Authorization": "Basic " + this._auth,
|
|
512
|
+
"content-type": "application/xml",
|
|
513
|
+
};
|
|
514
|
+
let query_xml = '<query xmlns="http://exist.sourceforge.net/NS/exist" cache="no" start="1" max="1000">\n' +
|
|
515
|
+
' <text><![CDATA[\n' +
|
|
516
|
+
' declare default element namespace "http://www.xcential.com/schemas/locks/1.0";\n' +
|
|
517
|
+
' declare namespace d="DAV:";\n' +
|
|
518
|
+
' declare namespace xs="http://www.w3.org/2001/XMLSchema";\n' +
|
|
519
|
+
' for $expiredLocks in //context[@lockExpires and current-dateTime() > xs:dateTime(@lockExpires)]/d:activelock\n' +
|
|
520
|
+
' let $result := update delete $expiredLocks\n' +
|
|
521
|
+
' return "success"\n' +
|
|
522
|
+
' ]]></text>\n' +
|
|
523
|
+
'</query>';
|
|
524
|
+
const clear_locks_response = await this.raw_post("/exist/rest/db/etc/Locks.xml", headers, query_xml);
|
|
525
|
+
return clear_locks_response;
|
|
526
|
+
}
|
|
527
|
+
catch (error) {
|
|
528
|
+
return error.response;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
async listExpiredLocks() {
|
|
532
|
+
try {
|
|
533
|
+
let headers = {
|
|
534
|
+
"Authorization": "Basic " + this._auth,
|
|
535
|
+
"content-type": "application/xml",
|
|
536
|
+
};
|
|
537
|
+
let query_xml = '<query xmlns="http://exist.sourceforge.net/NS/exist" cache="no" start="1" max="1000">\n' +
|
|
538
|
+
' <text><![CDATA[\n' +
|
|
539
|
+
' declare default element namespace "http://www.xcential.com/schemas/locks/1.0";\n' +
|
|
540
|
+
' declare namespace d="DAV:";\n' +
|
|
541
|
+
' declare namespace xs="http://www.w3.org/2001/XMLSchema";\n' +
|
|
542
|
+
' for $expiredLocks in //context[@lockExpires and current-dateTime() > xs:dateTime(@lockExpires)]\n' +
|
|
543
|
+
' let $result := $expiredLocks\n' +
|
|
544
|
+
' return $result\n' +
|
|
545
|
+
' ]]></text>\n' +
|
|
546
|
+
'</query>';
|
|
547
|
+
const list_locks_response = await this.raw_post("/exist/rest/db/etc/Locks.xml", headers, query_xml);
|
|
548
|
+
return list_locks_response;
|
|
549
|
+
}
|
|
550
|
+
catch (error) {
|
|
551
|
+
return error.response;
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
async listActiveLocks() {
|
|
555
|
+
try {
|
|
556
|
+
let headers = {
|
|
557
|
+
"Authorization": "Basic " + this._auth,
|
|
558
|
+
"content-type": "application/xml",
|
|
559
|
+
};
|
|
560
|
+
let query_xml = '<query xmlns="http://exist.sourceforge.net/NS/exist" cache="no" start="1" max="1000">\n' +
|
|
561
|
+
' <text><![CDATA[\n' +
|
|
562
|
+
' declare default element namespace "http://www.xcential.com/schemas/locks/1.0";\n' +
|
|
563
|
+
' declare namespace d="DAV:";\n' +
|
|
564
|
+
' declare namespace xs="http://www.w3.org/2001/XMLSchema";\n' +
|
|
565
|
+
' for $expiredLocks in //context[@lockExpires and current-dateTime() < xs:dateTime(@lockExpires)]\n' +
|
|
566
|
+
' let $result := $expiredLocks\n' +
|
|
567
|
+
' return $result\n' +
|
|
568
|
+
' ]]></text>\n' +
|
|
569
|
+
'</query>';
|
|
570
|
+
const list_locks_response = await this.raw_post("/exist/rest/db/etc/Locks.xml", headers, query_xml);
|
|
571
|
+
return list_locks_response;
|
|
572
|
+
}
|
|
573
|
+
catch (error) {
|
|
574
|
+
return error.response;
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
async listAllLocks() {
|
|
578
|
+
try {
|
|
579
|
+
let headers = {
|
|
580
|
+
"Authorization": "Basic " + this._auth,
|
|
581
|
+
"content-type": "application/xml",
|
|
582
|
+
};
|
|
583
|
+
let query_xml = '<query xmlns="http://exist.sourceforge.net/NS/exist" cache="no" start="1" max="1000">\n' +
|
|
584
|
+
' <text><![CDATA[\n' +
|
|
585
|
+
' declare default element namespace "http://www.xcential.com/schemas/locks/1.0";\n' +
|
|
586
|
+
' declare namespace d="DAV:";\n' +
|
|
587
|
+
' declare namespace xs="http://www.w3.org/2001/XMLSchema";\n' +
|
|
588
|
+
' for $allLocks in //context[d:activelock]\n' +
|
|
589
|
+
' let $result := $allLocks\n' +
|
|
590
|
+
' return $result\n' +
|
|
591
|
+
' ]]></text>\n' +
|
|
592
|
+
'</query>';
|
|
593
|
+
const list_locks_response = await this.raw_post("/exist/rest/db/etc/Locks.xml", headers, query_xml);
|
|
594
|
+
return list_locks_response;
|
|
595
|
+
}
|
|
596
|
+
catch (error) {
|
|
597
|
+
return error.response;
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
async memoryFree() {
|
|
601
|
+
try {
|
|
602
|
+
let query = {
|
|
603
|
+
"query": "system:get-memory-free()",
|
|
604
|
+
"defaultSerialization": {}
|
|
605
|
+
};
|
|
606
|
+
const response = await this.post("/query", query);
|
|
607
|
+
return response;
|
|
608
|
+
}
|
|
609
|
+
catch (error) {
|
|
610
|
+
return error.response;
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
async memoryTotal() {
|
|
614
|
+
try {
|
|
615
|
+
let query = {
|
|
616
|
+
"query": "system:get-memory-total()",
|
|
617
|
+
"defaultSerialization": {}
|
|
618
|
+
};
|
|
619
|
+
const response = await this.post("/query", query);
|
|
620
|
+
return response;
|
|
621
|
+
}
|
|
622
|
+
catch (error) {
|
|
623
|
+
return error.response;
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
async memoryMax() {
|
|
627
|
+
try {
|
|
628
|
+
let query = {
|
|
629
|
+
"query": "system:get-memory-max()",
|
|
630
|
+
"defaultSerialization": {}
|
|
631
|
+
};
|
|
632
|
+
const response = await this.post("/query", query);
|
|
633
|
+
return response;
|
|
634
|
+
}
|
|
635
|
+
catch (error) {
|
|
636
|
+
return error.response;
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
async uptime() {
|
|
640
|
+
try {
|
|
641
|
+
let query = {
|
|
642
|
+
"query": "system:get-uptime()",
|
|
643
|
+
"defaultSerialization": {}
|
|
644
|
+
};
|
|
645
|
+
const response = await this.post("/query", query);
|
|
646
|
+
return response;
|
|
647
|
+
}
|
|
648
|
+
catch (error) {
|
|
649
|
+
return error.response;
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
exports.FusiondbClient = FusiondbClient;
|
|
654
|
+
// singleton
|
|
655
|
+
FusiondbClient._instance = new FusiondbClient();
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Command } from "@oclif/core";
|
|
2
|
+
export declare class RcloneClient {
|
|
3
|
+
private _webdavUrl;
|
|
4
|
+
private _webdavUser;
|
|
5
|
+
private _webdavPassword;
|
|
6
|
+
private static _instance;
|
|
7
|
+
private constructor();
|
|
8
|
+
static get instance(): RcloneClient;
|
|
9
|
+
setConfig(cmd: Command): void;
|
|
10
|
+
list(url: string): string;
|
|
11
|
+
}
|