spec-3nweb-server 1.4.1 → 1.5.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/build/3nstorage/owner.js +14 -14
- package/build/3nstorage/resources/store.d.ts +2 -9
- package/build/3nstorage/resources/store.js +51 -49
- package/build/3nstorage/resources/users.d.ts +4 -2
- package/build/3nstorage/resources/users.js +6 -2
- package/build/3nstorage/routes/owner/archive-obj-version.js +33 -29
- package/build/3nstorage/routes/owner/delete-obj.d.ts +3 -2
- package/build/3nstorage/routes/owner/delete-obj.js +41 -6
- package/build/3nstorage/routes/owner/get-archived-obj-ver.js +8 -4
- package/build/3nstorage/routes/owner/list-obj-archive.js +25 -29
- package/build/lib-common/async-fs-node.d.ts +2 -0
- package/build/lib-common/objs-on-disk/utils.d.ts +1 -0
- package/build/lib-common/service-api/3nstorage/owner.d.ts +19 -14
- package/build/lib-common/service-api/3nstorage/owner.js +22 -18
- package/build/lib-server/web-sockets/app.d.ts +1 -0
- package/package.json +6 -6
package/build/3nstorage/owner.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Copyright (C) 2015 - 2017 3NSoft Inc.
|
|
3
|
+
Copyright (C) 2015 - 2017, 2022 3NSoft Inc.
|
|
4
4
|
|
|
5
5
|
This program is free software: you can redistribute it and/or modify it under
|
|
6
6
|
the terms of the GNU General Public License as published by the Free Software
|
|
@@ -73,30 +73,30 @@ function setHttpPart(app, domain, sessions, users, midAuthorizer) {
|
|
|
73
73
|
// Transaction canceling
|
|
74
74
|
app.http.post('/' + api.cancelTransaction.EXPRESS_URL_END, (0, body_parsers_1.emptyBody)(), (0, cancel_trans_1.cancelTransaction)(false, users.cancelTransaction));
|
|
75
75
|
app.http.post('/' + api.cancelRootTransaction.EXPRESS_URL_END, (0, body_parsers_1.emptyBody)(), (0, cancel_trans_1.cancelTransaction)(true, users.cancelTransaction));
|
|
76
|
-
// Getting current root object
|
|
76
|
+
// Getting and updating current root object
|
|
77
77
|
app.http.route('/' + api.currentRootObj.EXPRESS_URL_END)
|
|
78
78
|
.get((0, get_current_obj_1.getCurrentObj)(true, users.getCurrentRootObj))
|
|
79
79
|
.put((0, put_current_obj_1.saveCurrentObj)(true, users.saveNewRootVersion, MAX_CHUNK_SIZE));
|
|
80
|
-
// Getting current non-root objects
|
|
80
|
+
// Getting, updating and removing current non-root objects
|
|
81
81
|
app.http.route('/' + api.currentObj.EXPRESS_URL_END)
|
|
82
82
|
.get((0, get_current_obj_1.getCurrentObj)(false, users.getCurrentObj))
|
|
83
|
-
.delete((0, delete_obj_1.
|
|
83
|
+
.delete((0, delete_obj_1.deleteCurrentObjVer)(users.deleteCurrentObjVersion))
|
|
84
84
|
.put((0, put_current_obj_1.saveCurrentObj)(false, users.saveNewObjVersion, MAX_CHUNK_SIZE));
|
|
85
|
+
// Getting root archived versions
|
|
86
|
+
app.http.route('/' + api.archivedRootVersion.EXPRESS_URL_END)
|
|
87
|
+
.get((0, get_archived_obj_ver_1.getArchivedObjVersion)(true, users.getArchivedRootVersion));
|
|
88
|
+
// Getting non-root object archived versions
|
|
89
|
+
app.http.route('/' + api.archivedObjVersion.EXPRESS_URL_END)
|
|
90
|
+
.get((0, get_archived_obj_ver_1.getArchivedObjVersion)(false, users.getArchivedObjVersion));
|
|
85
91
|
// Archive root's current version
|
|
86
92
|
app.http.route('/' + api.archiveRoot.URL_END)
|
|
87
93
|
.get((0, list_obj_archive_1.listObjArchive)(true, users.listObjArchive))
|
|
88
|
-
.
|
|
94
|
+
.post((0, body_parsers_1.emptyBody)(), (0, archive_obj_version_1.archiveCurrentObjVersion)(true, users.archiveObjVersion))
|
|
95
|
+
.delete((0, delete_obj_1.deleteArchivedObjVer)(true, users.deleteArchivedObjVersion));
|
|
89
96
|
// Archive non-root object's current version
|
|
90
97
|
app.http.route('/' + api.archiveObj.EXPRESS_URL_END)
|
|
91
98
|
.get((0, list_obj_archive_1.listObjArchive)(false, users.listObjArchive))
|
|
92
|
-
.
|
|
93
|
-
|
|
94
|
-
app.http.route('/' + api.archivedRootVersion.EXPRESS_URL_END)
|
|
95
|
-
.get((0, get_archived_obj_ver_1.getArchivedObjVersion)(true, users.getArchivedRootVersion))
|
|
96
|
-
.delete((0, delete_obj_1.deleteObj)(true, false, users.deleteObj));
|
|
97
|
-
// Removing archived and current versions of non-root object
|
|
98
|
-
app.http.route('/' + api.archivedObjVersion.EXPRESS_URL_END)
|
|
99
|
-
.get((0, get_archived_obj_ver_1.getArchivedObjVersion)(true, users.getArchivedObjVersion))
|
|
100
|
-
.delete((0, delete_obj_1.deleteObj)(false, false, users.deleteObj));
|
|
99
|
+
.post((0, body_parsers_1.emptyBody)(), (0, archive_obj_version_1.archiveCurrentObjVersion)(false, users.archiveObjVersion))
|
|
100
|
+
.delete((0, delete_obj_1.deleteArchivedObjVer)(false, users.deleteArchivedObjVersion));
|
|
101
101
|
}
|
|
102
102
|
Object.freeze(exports);
|
|
@@ -102,15 +102,8 @@ export declare class Store extends UserFiles {
|
|
|
102
102
|
getArchivedObjVersion(objId: string | null, version: number, header: boolean, segsOffset: number, segsLimit: number | undefined): Promise<ObjReader>;
|
|
103
103
|
private makeObjReader;
|
|
104
104
|
private getObjFile;
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
* root object.
|
|
108
|
-
* @param archVersion is an optional parameter, identifying archived version
|
|
109
|
-
* to delete. Default null value indicates that an object should be removed.
|
|
110
|
-
* If an object has any archived versions (even if current), these will not
|
|
111
|
-
* be removed, and such object state will be labeled as archived.
|
|
112
|
-
*/
|
|
113
|
-
deleteObj(objId: string, archVersion?: number | null): Promise<void>;
|
|
105
|
+
deleteCurrentObjVer(objId: string, version?: number | null): Promise<void>;
|
|
106
|
+
deleteArchivedObjVer(objId: string | null, version: number): Promise<void>;
|
|
114
107
|
/**
|
|
115
108
|
* @param objId is a string object id for non-root objects, and null for
|
|
116
109
|
* root object.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Copyright (C) 2015 - 2017, 2019 - 2020 3NSoft Inc.
|
|
3
|
+
Copyright (C) 2015 - 2017, 2019 - 2020, 2022 3NSoft Inc.
|
|
4
4
|
|
|
5
5
|
This program is free software: you can redistribute it and/or modify it under
|
|
6
6
|
the terms of the GNU General Public License as published by the Free Software
|
|
@@ -315,62 +315,63 @@ class Store extends user_files_1.UserFiles {
|
|
|
315
315
|
Object.freeze(reader);
|
|
316
316
|
return reader;
|
|
317
317
|
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
* to delete. Default null value indicates that an object should be removed.
|
|
323
|
-
* If an object has any archived versions (even if current), these will not
|
|
324
|
-
* be removed, and such object state will be labeled as archived.
|
|
325
|
-
*/
|
|
326
|
-
async deleteObj(objId, archVersion = null) {
|
|
318
|
+
async deleteCurrentObjVer(objId, version = null) {
|
|
319
|
+
if (!objId) {
|
|
320
|
+
throw new Error('Root object is not removable.');
|
|
321
|
+
}
|
|
327
322
|
const status = await this.statuses.get(objId);
|
|
328
|
-
|
|
323
|
+
if (status.state !== 'current') {
|
|
324
|
+
throw exports.SC.OBJ_UNKNOWN;
|
|
325
|
+
}
|
|
326
|
+
if (version && (version !== status.currentVersion)) {
|
|
327
|
+
throw exports.SC.OBJ_VER_UNKNOWN;
|
|
328
|
+
}
|
|
329
329
|
// XXX need to put removal transaction, closing it in a finally clause
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
if (status.state !== 'current') {
|
|
335
|
-
throw exports.SC.OBJ_UNKNOWN;
|
|
336
|
-
}
|
|
337
|
-
if (!Array.isArray(arch) || (arch.length === 0)) {
|
|
338
|
-
await this.statuses.deleteWithObj(objId);
|
|
339
|
-
}
|
|
340
|
-
else {
|
|
341
|
-
const currVer = status.currentVersion;
|
|
342
|
-
delete status.currentVersion;
|
|
343
|
-
status.state = 'archived';
|
|
344
|
-
await this.statuses.set(objId, status);
|
|
345
|
-
if (typeof currVer !== 'number') {
|
|
346
|
-
throw new Error(`Illegal state of object status file for ${objId}: state is current, while current version is missing.`);
|
|
347
|
-
}
|
|
348
|
-
if (arch.indexOf(currVer) < 0) {
|
|
349
|
-
await this.rmObjFiles(objId, currVer);
|
|
350
|
-
}
|
|
351
|
-
}
|
|
330
|
+
const arch = status.archivedVersions;
|
|
331
|
+
if (!Array.isArray(arch) || (arch.length === 0)) {
|
|
332
|
+
// remove everything related to this object
|
|
333
|
+
await this.statuses.deleteWithObj(objId);
|
|
352
334
|
}
|
|
353
335
|
else {
|
|
354
|
-
if
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
if (indInArch < 0) {
|
|
359
|
-
throw exports.SC.OBJ_UNKNOWN;
|
|
360
|
-
}
|
|
361
|
-
arch.splice(indInArch, 1);
|
|
362
|
-
if (arch.length === 0) {
|
|
363
|
-
delete status.archivedVersions;
|
|
364
|
-
}
|
|
336
|
+
// set status and remove version if it isn't archived
|
|
337
|
+
version = status.currentVersion;
|
|
338
|
+
delete status.currentVersion;
|
|
339
|
+
status.state = 'archived';
|
|
365
340
|
await this.statuses.set(objId, status);
|
|
366
|
-
if (
|
|
367
|
-
await this.rmObjFiles(objId,
|
|
341
|
+
if (arch.indexOf(version) < 0) {
|
|
342
|
+
await this.rmObjFiles(objId, version);
|
|
368
343
|
}
|
|
369
344
|
}
|
|
370
345
|
this.storageEventsSink(this.userId, owner_1.objRemoved.EVENT_NAME, {
|
|
371
346
|
objId,
|
|
372
347
|
});
|
|
373
348
|
}
|
|
349
|
+
async deleteArchivedObjVer(objId, version) {
|
|
350
|
+
const status = await this.statuses.get(objId);
|
|
351
|
+
const arch = status.archivedVersions;
|
|
352
|
+
// XXX need to put removal transaction, closing it in a finally clause
|
|
353
|
+
if (!Array.isArray(arch)) {
|
|
354
|
+
throw exports.SC.OBJ_VER_UNKNOWN;
|
|
355
|
+
}
|
|
356
|
+
const indInArch = arch.indexOf(version);
|
|
357
|
+
if (indInArch < 0) {
|
|
358
|
+
throw exports.SC.OBJ_VER_UNKNOWN;
|
|
359
|
+
}
|
|
360
|
+
arch.splice(indInArch, 1);
|
|
361
|
+
if (arch.length === 0) {
|
|
362
|
+
delete status.archivedVersions;
|
|
363
|
+
}
|
|
364
|
+
await this.statuses.set(objId, status);
|
|
365
|
+
if (!status.archivedVersions && !status.currentVersion) {
|
|
366
|
+
await this.rmObjFiles(objId, version);
|
|
367
|
+
}
|
|
368
|
+
else if (status.currentVersion !== version) {
|
|
369
|
+
await this.statuses.deleteWithObj(objId);
|
|
370
|
+
}
|
|
371
|
+
// this.storageEventsSink(this.userId, objRemoved.EVENT_NAME, {
|
|
372
|
+
// objId,
|
|
373
|
+
// });
|
|
374
|
+
}
|
|
374
375
|
/**
|
|
375
376
|
* @param objId is a string object id for non-root objects, and null for
|
|
376
377
|
* root object.
|
|
@@ -391,7 +392,7 @@ class Store extends user_files_1.UserFiles {
|
|
|
391
392
|
const verPart = toFName(version);
|
|
392
393
|
objFiles = objFiles.filter(fName => fName.startsWith(verPart));
|
|
393
394
|
if (objFiles.length === 0) {
|
|
394
|
-
throw exports.SC.
|
|
395
|
+
throw exports.SC.OBJ_VER_UNKNOWN;
|
|
395
396
|
}
|
|
396
397
|
for (const fName of objFiles) {
|
|
397
398
|
await fs.unlink((0, path_1.join)(objFolder, fName)).catch(() => { });
|
|
@@ -404,12 +405,13 @@ class Store extends user_files_1.UserFiles {
|
|
|
404
405
|
// file/folder.
|
|
405
406
|
async archiveCurrentObjVersion(objId, version) {
|
|
406
407
|
// XXX need to put archiving transaction, closing it in a finally clause
|
|
408
|
+
// - make in memory transactions for archival and removal, or chaining(?)
|
|
407
409
|
const status = await this.statuses.get(objId);
|
|
408
410
|
if (status.state !== 'current') {
|
|
409
411
|
throw exports.SC.OBJ_UNKNOWN;
|
|
410
412
|
}
|
|
411
|
-
if (
|
|
412
|
-
throw
|
|
413
|
+
if (status.currentVersion !== version) {
|
|
414
|
+
throw exports.SC.OBJ_VER_UNKNOWN;
|
|
413
415
|
}
|
|
414
416
|
const arch = status.archivedVersions;
|
|
415
417
|
if (Array.isArray(arch)) {
|
|
@@ -18,7 +18,8 @@ export declare type GetArchivedObjVersion = (userId: string, objId: string | nul
|
|
|
18
18
|
export declare type CancelTransaction = (userId: string, objId: string, transactionId?: string) => Promise<void>;
|
|
19
19
|
export declare type ArchiveObjCurrentVersion = (userId: string, objId: string, version: number) => Promise<void>;
|
|
20
20
|
export declare type ListObjArchive = (userId: string, objId: string) => Promise<number[]>;
|
|
21
|
-
export declare type
|
|
21
|
+
export declare type DeleteCurrentObjVersion = (userId: string, objId: string, version?: number) => Promise<void>;
|
|
22
|
+
export declare type DeleteArchivedObjVersion = (userId: string, objId: string | null, version: number) => Promise<void>;
|
|
22
23
|
declare type GetParam<T> = (userId: string) => Promise<T>;
|
|
23
24
|
declare type SetParam<T> = (userId: string, param: T) => Promise<boolean>;
|
|
24
25
|
export declare type GetSpaceQuota = GetParam<number>;
|
|
@@ -42,7 +43,8 @@ export interface Factory {
|
|
|
42
43
|
archiveObjVersion: ArchiveObjCurrentVersion;
|
|
43
44
|
getArchivedRootVersion: GetArchivedObjVersion;
|
|
44
45
|
getArchivedObjVersion: GetArchivedObjVersion;
|
|
45
|
-
|
|
46
|
+
deleteCurrentObjVersion: DeleteCurrentObjVersion;
|
|
47
|
+
deleteArchivedObjVersion: DeleteArchivedObjVersion;
|
|
46
48
|
setStorageEventsSink(sink: EventsSink): void;
|
|
47
49
|
}
|
|
48
50
|
export declare function makeFactory(rootFolder: string, writeBufferSize?: string | number, readBufferSize?: string | number): Factory;
|
|
@@ -122,9 +122,9 @@ function makeFactory(rootFolder, writeBufferSize, readBufferSize) {
|
|
|
122
122
|
saveNewRootVersion: makeObjSaver(true),
|
|
123
123
|
saveNewObjVersion: makeObjSaver(false),
|
|
124
124
|
cancelTransaction: makeTransactionCanceller(),
|
|
125
|
-
|
|
125
|
+
deleteCurrentObjVersion: async (userId, objId, version) => {
|
|
126
126
|
const store = await getStore(userId);
|
|
127
|
-
await store.
|
|
127
|
+
await store.deleteCurrentObjVer(objId, version);
|
|
128
128
|
},
|
|
129
129
|
archiveObjVersion: async (userId, objId, version) => {
|
|
130
130
|
const store = await getStore(userId);
|
|
@@ -134,6 +134,10 @@ function makeFactory(rootFolder, writeBufferSize, readBufferSize) {
|
|
|
134
134
|
const store = await getStore(userId);
|
|
135
135
|
return store.listObjArchive(objId);
|
|
136
136
|
},
|
|
137
|
+
deleteArchivedObjVersion: async (userId, objId, version) => {
|
|
138
|
+
const store = await getStore(userId);
|
|
139
|
+
await store.deleteArchivedObjVer(objId, version);
|
|
140
|
+
},
|
|
137
141
|
setStorageEventsSink(sink) {
|
|
138
142
|
if (storageEventsSink) {
|
|
139
143
|
throw new Error(`Storage events sink is already set`);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Copyright (C)
|
|
3
|
+
Copyright (C) 2022 3NSoft Inc.
|
|
4
4
|
|
|
5
5
|
This program is free software: you can redistribute it and/or modify it under
|
|
6
6
|
the terms of the GNU General Public License as published by the Free Software
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
*/
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
19
|
exports.archiveCurrentObjVersion = void 0;
|
|
20
|
+
const users_1 = require("../../resources/users");
|
|
20
21
|
const owner_1 = require("../../../lib-common/service-api/3nstorage/owner");
|
|
21
22
|
const SC = owner_1.archiveObj.SC;
|
|
22
23
|
function archiveCurrentObjVersion(root, archiveObjVerFunc) {
|
|
@@ -24,34 +25,37 @@ function archiveCurrentObjVersion(root, archiveObjVerFunc) {
|
|
|
24
25
|
throw new TypeError("Given argument 'archiveObjVerFunc' must be function, but is not.");
|
|
25
26
|
}
|
|
26
27
|
return async (req, res, next) => {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
28
|
+
const userId = req.session.params.userId;
|
|
29
|
+
const objId = (root ? null : req.params.objId);
|
|
30
|
+
const version = parseInt(req.query.ver);
|
|
31
|
+
if (isNaN(version) || (version < 1)) {
|
|
32
|
+
res.status(owner_1.ERR_SC.malformed).send("Bad query parameters");
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
await archiveObjVerFunc(userId, objId, version);
|
|
37
|
+
res.status(SC.okPost).end();
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
if ("string" !== typeof err) {
|
|
41
|
+
next(err);
|
|
42
|
+
}
|
|
43
|
+
else if (err === users_1.SC.OBJ_VER_UNKNOWN) {
|
|
44
|
+
res.status(SC.unknownObjVer).send(`Object ${objId} version ${version} is not current.`);
|
|
45
|
+
}
|
|
46
|
+
else if (err === users_1.SC.OBJ_UNKNOWN) {
|
|
47
|
+
res.status(SC.unknownObj).send(root ?
|
|
48
|
+
`Root object is not set.` :
|
|
49
|
+
`Object ${objId} is unknown.`);
|
|
50
|
+
}
|
|
51
|
+
else if (err === users_1.SC.USER_UNKNOWN) {
|
|
52
|
+
res.status(owner_1.ERR_SC.server).send("Recipient disappeared from the system.");
|
|
53
|
+
req.session.close();
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
next(new Error("Unhandled storage error code: " + err));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
55
59
|
};
|
|
56
60
|
}
|
|
57
61
|
exports.archiveCurrentObjVersion = archiveCurrentObjVersion;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { RequestHandler } from 'express';
|
|
2
|
-
import {
|
|
3
|
-
export declare function
|
|
2
|
+
import { DeleteArchivedObjVersion, DeleteCurrentObjVersion } from '../../resources/users';
|
|
3
|
+
export declare function deleteCurrentObjVer(deleteObjFunc: DeleteCurrentObjVersion): RequestHandler;
|
|
4
|
+
export declare function deleteArchivedObjVer(root: boolean, deleteObjFunc: DeleteArchivedObjVersion): RequestHandler;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Copyright (C) 2016, 2020 3NSoft Inc.
|
|
3
|
+
Copyright (C) 2016, 2020, 2022 3NSoft Inc.
|
|
4
4
|
|
|
5
5
|
This program is free software: you can redistribute it and/or modify it under
|
|
6
6
|
the terms of the GNU General Public License as published by the Free Software
|
|
@@ -16,19 +16,45 @@
|
|
|
16
16
|
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
17
|
*/
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.
|
|
19
|
+
exports.deleteArchivedObjVer = exports.deleteCurrentObjVer = void 0;
|
|
20
20
|
const users_1 = require("../../resources/users");
|
|
21
21
|
const owner_1 = require("../../../lib-common/service-api/3nstorage/owner");
|
|
22
|
+
const assert_1 = require("../../../tests/libs-for-tests/assert");
|
|
22
23
|
function deleteObj(root, delCurrent, deleteObjFunc) {
|
|
23
24
|
if ('function' !== typeof deleteObjFunc) {
|
|
24
25
|
throw new TypeError("Given argument 'deleteObjFunc' must be function, but is not.");
|
|
25
26
|
}
|
|
27
|
+
if (delCurrent) {
|
|
28
|
+
(0, assert_1.assert)(!root);
|
|
29
|
+
}
|
|
26
30
|
return async (req, res, next) => {
|
|
27
31
|
const userId = req.session.params.userId;
|
|
28
32
|
const objId = (root ? null : req.params.objId);
|
|
29
|
-
const
|
|
33
|
+
const ver = parseInt(req.query.ver);
|
|
34
|
+
let version;
|
|
35
|
+
if (isNaN(ver)) {
|
|
36
|
+
if (delCurrent) {
|
|
37
|
+
version = undefined;
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
res.status(owner_1.ERR_SC.malformed).send("Bad query parameters");
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
if (ver < 1) {
|
|
46
|
+
res.status(owner_1.ERR_SC.malformed).send("Bad query parameters");
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
version = ver;
|
|
50
|
+
}
|
|
30
51
|
try {
|
|
31
|
-
|
|
52
|
+
if (delCurrent) {
|
|
53
|
+
await deleteObjFunc(userId, objId, version);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
await deleteObjFunc(userId, objId, version);
|
|
57
|
+
}
|
|
32
58
|
res.status(owner_1.currentObj.SC.okDelete).end();
|
|
33
59
|
}
|
|
34
60
|
catch (err) {
|
|
@@ -41,6 +67,9 @@ function deleteObj(root, delCurrent, deleteObjFunc) {
|
|
|
41
67
|
else if (err === users_1.SC.OBJ_UNKNOWN) {
|
|
42
68
|
res.status(owner_1.currentObj.SC.unknownObj).send(`Object ${objId} is unknown.`);
|
|
43
69
|
}
|
|
70
|
+
else if (err === users_1.SC.OBJ_VER_UNKNOWN) {
|
|
71
|
+
res.status(owner_1.currentObj.SC.unknownObjVer).send(`Object version ${version} is unknown.`);
|
|
72
|
+
}
|
|
44
73
|
else if (err === users_1.SC.USER_UNKNOWN) {
|
|
45
74
|
res.status(owner_1.ERR_SC.server).send("Recipient disappeared from the system.");
|
|
46
75
|
req.session.close();
|
|
@@ -51,6 +80,12 @@ function deleteObj(root, delCurrent, deleteObjFunc) {
|
|
|
51
80
|
}
|
|
52
81
|
};
|
|
53
82
|
}
|
|
54
|
-
|
|
55
|
-
;
|
|
83
|
+
function deleteCurrentObjVer(deleteObjFunc) {
|
|
84
|
+
return deleteObj(false, true, deleteObjFunc);
|
|
85
|
+
}
|
|
86
|
+
exports.deleteCurrentObjVer = deleteCurrentObjVer;
|
|
87
|
+
function deleteArchivedObjVer(root, deleteObjFunc) {
|
|
88
|
+
return deleteObj(root, false, deleteObjFunc);
|
|
89
|
+
}
|
|
90
|
+
exports.deleteArchivedObjVer = deleteArchivedObjVer;
|
|
56
91
|
Object.freeze(exports);
|
|
@@ -85,10 +85,14 @@ function getArchivedObjVersion(root, getArchivedObjFunc) {
|
|
|
85
85
|
if ("string" !== typeof err) {
|
|
86
86
|
next(err);
|
|
87
87
|
}
|
|
88
|
-
else if (
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
88
|
+
else if (err === users_1.SC.OBJ_UNKNOWN) {
|
|
89
|
+
res.status(owner_1.archivedObjVersion.SC.unknownObj).send(objId ?
|
|
90
|
+
`Object ${objId}is unknown.` : `Root object is not set`);
|
|
91
|
+
}
|
|
92
|
+
else if (err === users_1.SC.OBJ_VER_UNKNOWN) {
|
|
93
|
+
res.status(owner_1.archivedObjVersion.SC.unknownObjVer).send(objId ?
|
|
94
|
+
`Object ${objId}, version ${opts.ver} is unknown.` :
|
|
95
|
+
`Root object version ${opts.ver} is not known.`);
|
|
92
96
|
}
|
|
93
97
|
else if (err === users_1.SC.USER_UNKNOWN) {
|
|
94
98
|
res.status(owner_1.ERR_SC.server).send(`Recipient disappeared from the system.`);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Copyright (C)
|
|
3
|
+
Copyright (C) 2022 3NSoft Inc.
|
|
4
4
|
|
|
5
5
|
This program is free software: you can redistribute it and/or modify it under
|
|
6
6
|
the terms of the GNU General Public License as published by the Free Software
|
|
@@ -17,39 +17,35 @@
|
|
|
17
17
|
*/
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
19
|
exports.listObjArchive = void 0;
|
|
20
|
+
const users_1 = require("../../resources/users");
|
|
21
|
+
const owner_1 = require("../../../lib-common/service-api/3nstorage/owner");
|
|
20
22
|
function listObjArchive(root, listObjArchiveFunc) {
|
|
21
23
|
if ('function' !== typeof listObjArchiveFunc) {
|
|
22
24
|
throw new TypeError("Given argument 'listObjArchiveFunc' must be function, but is not.");
|
|
23
25
|
}
|
|
24
26
|
return async (req, res, next) => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
// "Recipient disappeared from the system.");
|
|
48
|
-
// req.session.close();
|
|
49
|
-
// } else {
|
|
50
|
-
// next(new Error("Unhandled storage error code: "+err));
|
|
51
|
-
// }
|
|
52
|
-
// }
|
|
27
|
+
const userId = req.session.params.userId;
|
|
28
|
+
const objId = (root ? null : req.params.objId);
|
|
29
|
+
try {
|
|
30
|
+
const lst = await listObjArchiveFunc(userId, objId);
|
|
31
|
+
res.status(owner_1.archiveObj.SC.okGet).json(lst);
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
if ("string" !== typeof err) {
|
|
35
|
+
next(err);
|
|
36
|
+
}
|
|
37
|
+
else if (err === users_1.SC.OBJ_UNKNOWN) {
|
|
38
|
+
res.status(owner_1.archiveObj.SC.unknownObj).send(root ?
|
|
39
|
+
`Root object is set.` : `Object ${objId} is unknown.`);
|
|
40
|
+
}
|
|
41
|
+
else if (err === users_1.SC.USER_UNKNOWN) {
|
|
42
|
+
res.status(owner_1.ERR_SC.server).send("Recipient disappeared from the system.");
|
|
43
|
+
req.session.close();
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
next(new Error("Unhandled storage error code: " + err));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
53
49
|
};
|
|
54
50
|
}
|
|
55
51
|
exports.listObjArchive = listObjArchive;
|
|
@@ -157,24 +157,20 @@ export declare namespace currentRootObj {
|
|
|
157
157
|
}
|
|
158
158
|
export declare namespace archivedObjVersion {
|
|
159
159
|
const EXPRESS_URL_END = "/obj/:objId/archived";
|
|
160
|
-
function getReqUrlEnd(objId: string,
|
|
160
|
+
function getReqUrlEnd(objId: string, opts: GetObjQueryOpts): string;
|
|
161
161
|
const SC: {
|
|
162
162
|
okGet: number;
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
concurrentTransaction: number;
|
|
166
|
-
incompatibleObjState: number;
|
|
163
|
+
unknownObj: number;
|
|
164
|
+
unknownObjVer: number;
|
|
167
165
|
};
|
|
168
166
|
}
|
|
169
167
|
export declare namespace archivedRootVersion {
|
|
170
168
|
const EXPRESS_URL_END = "root/archived";
|
|
171
|
-
function getReqUrlEnd(
|
|
169
|
+
function getReqUrlEnd(opts: GetObjQueryOpts): string;
|
|
172
170
|
const SC: {
|
|
173
171
|
okGet: number;
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
concurrentTransaction: number;
|
|
177
|
-
incompatibleObjState: number;
|
|
172
|
+
unknownObj: number;
|
|
173
|
+
unknownObjVer: number;
|
|
178
174
|
};
|
|
179
175
|
}
|
|
180
176
|
export interface DiffInfo {
|
|
@@ -221,18 +217,27 @@ export declare namespace cancelRootTransaction {
|
|
|
221
217
|
export declare namespace archiveObj {
|
|
222
218
|
const EXPRESS_URL_END = "obj/:objId/archive";
|
|
223
219
|
function getReqUrlEnd(objId: string): string;
|
|
220
|
+
function postAndDelReqUrlEnd(objId: string, version: number): string;
|
|
221
|
+
type VersionsList = number[];
|
|
224
222
|
const SC: {
|
|
225
223
|
okGet: number;
|
|
226
|
-
|
|
227
|
-
|
|
224
|
+
okPost: number;
|
|
225
|
+
okDelete: number;
|
|
226
|
+
unknownObj: number;
|
|
227
|
+
unknownObjVer: number;
|
|
228
228
|
};
|
|
229
229
|
}
|
|
230
230
|
export declare namespace archiveRoot {
|
|
231
231
|
const URL_END = "root/archive";
|
|
232
|
+
function getReqUrlEnd(): string;
|
|
233
|
+
function postAndDelReqUrlEnd(version: number): string;
|
|
234
|
+
type VersionsList = archiveObj.VersionsList;
|
|
232
235
|
const SC: {
|
|
233
236
|
okGet: number;
|
|
234
|
-
|
|
235
|
-
|
|
237
|
+
okPost: number;
|
|
238
|
+
okDelete: number;
|
|
239
|
+
unknownObj: number;
|
|
240
|
+
unknownObjVer: number;
|
|
236
241
|
};
|
|
237
242
|
}
|
|
238
243
|
export interface ErrorReply {
|
|
@@ -123,32 +123,22 @@ Object.freeze(currentRootObj);
|
|
|
123
123
|
var archivedObjVersion;
|
|
124
124
|
(function (archivedObjVersion) {
|
|
125
125
|
archivedObjVersion.EXPRESS_URL_END = '/obj/:objId/archived';
|
|
126
|
-
function getReqUrlEnd(objId,
|
|
127
|
-
|
|
128
|
-
opts.ver = version;
|
|
129
|
-
}
|
|
130
|
-
const query = (opts ? `?${(0, querystring_1.stringify)(opts)}` : '');
|
|
131
|
-
return `/obj/${objId}/archived${query}`;
|
|
126
|
+
function getReqUrlEnd(objId, opts) {
|
|
127
|
+
return `/obj/${objId}/archived?${(0, querystring_1.stringify)(opts)}`;
|
|
132
128
|
}
|
|
133
129
|
archivedObjVersion.getReqUrlEnd = getReqUrlEnd;
|
|
134
130
|
archivedObjVersion.SC = {
|
|
135
131
|
okGet: 200,
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
concurrentTransaction: 483,
|
|
139
|
-
incompatibleObjState: 484
|
|
132
|
+
unknownObj: 474,
|
|
133
|
+
unknownObjVer: 494
|
|
140
134
|
};
|
|
141
135
|
})(archivedObjVersion = exports.archivedObjVersion || (exports.archivedObjVersion = {}));
|
|
142
136
|
Object.freeze(archivedObjVersion);
|
|
143
137
|
var archivedRootVersion;
|
|
144
138
|
(function (archivedRootVersion) {
|
|
145
139
|
archivedRootVersion.EXPRESS_URL_END = 'root/archived';
|
|
146
|
-
function getReqUrlEnd(
|
|
147
|
-
|
|
148
|
-
opts.ver = version;
|
|
149
|
-
}
|
|
150
|
-
const query = (opts ? `?${(0, querystring_1.stringify)(opts)}` : '');
|
|
151
|
-
return `root/archived${query}`;
|
|
140
|
+
function getReqUrlEnd(opts) {
|
|
141
|
+
return `root/archived?${(0, querystring_1.stringify)(opts)}`;
|
|
152
142
|
}
|
|
153
143
|
archivedRootVersion.getReqUrlEnd = getReqUrlEnd;
|
|
154
144
|
archivedRootVersion.SC = archivedObjVersion.SC;
|
|
@@ -237,16 +227,30 @@ var archiveObj;
|
|
|
237
227
|
return `obj/${objId}/archive`;
|
|
238
228
|
}
|
|
239
229
|
archiveObj.getReqUrlEnd = getReqUrlEnd;
|
|
230
|
+
function postAndDelReqUrlEnd(objId, version) {
|
|
231
|
+
return `obj/${objId}/archive?ver=${version}`;
|
|
232
|
+
}
|
|
233
|
+
archiveObj.postAndDelReqUrlEnd = postAndDelReqUrlEnd;
|
|
240
234
|
archiveObj.SC = {
|
|
241
235
|
okGet: 200,
|
|
242
|
-
|
|
243
|
-
|
|
236
|
+
okPost: 200,
|
|
237
|
+
okDelete: 200,
|
|
238
|
+
unknownObj: 474,
|
|
239
|
+
unknownObjVer: 494
|
|
244
240
|
};
|
|
245
241
|
})(archiveObj = exports.archiveObj || (exports.archiveObj = {}));
|
|
246
242
|
Object.freeze(archiveObj);
|
|
247
243
|
var archiveRoot;
|
|
248
244
|
(function (archiveRoot) {
|
|
249
245
|
archiveRoot.URL_END = 'root/archive';
|
|
246
|
+
function getReqUrlEnd() {
|
|
247
|
+
return `root/archive`;
|
|
248
|
+
}
|
|
249
|
+
archiveRoot.getReqUrlEnd = getReqUrlEnd;
|
|
250
|
+
function postAndDelReqUrlEnd(version) {
|
|
251
|
+
return `root/archive?ver=${version}`;
|
|
252
|
+
}
|
|
253
|
+
archiveRoot.postAndDelReqUrlEnd = postAndDelReqUrlEnd;
|
|
250
254
|
archiveRoot.SC = archiveObj.SC;
|
|
251
255
|
})(archiveRoot = exports.archiveRoot || (exports.archiveRoot = {}));
|
|
252
256
|
Object.freeze(archiveRoot);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "spec-3nweb-server",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "3NWeb spec server.",
|
|
5
5
|
"main": "build/lib.js",
|
|
6
6
|
"types": "build/lib.d.ts",
|
|
@@ -36,13 +36,13 @@
|
|
|
36
36
|
"xsp-files": "^2.0.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@types/express": "",
|
|
40
|
-
"@types/jasmine": "",
|
|
41
|
-
"@types/node": "",
|
|
39
|
+
"@types/express": "4.17.13",
|
|
40
|
+
"@types/jasmine": "^3.9.1",
|
|
41
|
+
"@types/node": "^16.11.7",
|
|
42
42
|
"@types/ws": "^4.0.0",
|
|
43
|
-
"jasmine": "^
|
|
43
|
+
"jasmine": "^3.9.0",
|
|
44
44
|
"rxjs": "^5.3.0",
|
|
45
|
-
"typescript": "^4.
|
|
45
|
+
"typescript": "^4.7.4",
|
|
46
46
|
"xhr2": "^0.1.3"
|
|
47
47
|
},
|
|
48
48
|
"readmeFilename": "README.md"
|