spec-3nweb-server 1.5.2 → 1.6.2

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.
@@ -37,7 +37,7 @@ const get_current_obj_1 = require("./routes/owner/get-current-obj");
37
37
  const get_archived_obj_ver_1 = require("./routes/owner/get-archived-obj-ver");
38
38
  const delete_obj_1 = require("./routes/owner/delete-obj");
39
39
  const archive_obj_version_1 = require("./routes/owner/archive-obj-version");
40
- const list_obj_archive_1 = require("./routes/owner/list-obj-archive");
40
+ const get_obj_status_1 = require("./routes/owner/get-obj-status");
41
41
  const api = require("../lib-common/service-api/3nstorage/owner");
42
42
  function makeApp(domain, sessions, users, midAuthorizer) {
43
43
  const app = new app_1.AppWithWSs();
@@ -88,14 +88,16 @@ function setHttpPart(app, domain, sessions, users, midAuthorizer) {
88
88
  app.http.route('/' + api.archivedObjVersion.EXPRESS_URL_END)
89
89
  .get((0, get_archived_obj_ver_1.getArchivedObjVersion)(false, users.getArchivedObjVersion));
90
90
  // Archive root's current version
91
- app.http.route('/' + api.archiveRoot.URL_END)
92
- .get((0, list_obj_archive_1.listObjArchive)(true, users.listObjArchive))
91
+ app.http.route('/' + api.archiveRoot.EXPRESS_URL_END)
93
92
  .post((0, body_parsers_1.emptyBody)(), (0, archive_obj_version_1.archiveCurrentObjVersion)(true, users.archiveObjVersion))
94
93
  .delete((0, delete_obj_1.deleteArchivedObjVer)(true, users.deleteArchivedObjVersion));
95
94
  // Archive non-root object's current version
96
95
  app.http.route('/' + api.archiveObj.EXPRESS_URL_END)
97
- .get((0, list_obj_archive_1.listObjArchive)(false, users.listObjArchive))
98
96
  .post((0, body_parsers_1.emptyBody)(), (0, archive_obj_version_1.archiveCurrentObjVersion)(false, users.archiveObjVersion))
99
97
  .delete((0, delete_obj_1.deleteArchivedObjVer)(false, users.deleteArchivedObjVersion));
98
+ // Getting root object status
99
+ app.http.get('/' + api.rootStatus.EXPRESS_URL_END, (0, get_obj_status_1.getObjStatus)(true, users.getObjStatus));
100
+ // Getting object status
101
+ app.http.get('/' + api.objStatus.EXPRESS_URL_END, (0, get_obj_status_1.getObjStatus)(false, users.getObjStatus));
100
102
  }
101
103
  Object.freeze(exports);
@@ -2,7 +2,7 @@
2
2
  import { Readable } from 'stream';
3
3
  import { PutObjFirstQueryOpts, PutObjSecondQueryOpts } from '../../lib-common/service-api/3nstorage/owner';
4
4
  import { UserFiles, ObjReader } from '../../lib-server/resources/user-files';
5
- import { DiffInfo, events } from '../../lib-common/service-api/3nstorage/owner';
5
+ import { DiffInfo, events, ObjStatus } from '../../lib-common/service-api/3nstorage/owner';
6
6
  export { DiffInfo } from '../../lib-common/service-api/3nstorage/owner';
7
7
  export { ObjPipe, ObjReader } from '../../lib-server/resources/user-files';
8
8
  export declare type StorageEventsSink = (userId: string, channel: events.EventNameType, event: events.AllTypes) => void;
@@ -111,7 +111,7 @@ export declare class Store extends UserFiles {
111
111
  */
112
112
  private rmObjFiles;
113
113
  archiveCurrentObjVersion(objId: string, version: number): Promise<void>;
114
- listObjArchive(objId: string): Promise<number[]>;
114
+ getObjStatus(objId: string): Promise<ObjStatus>;
115
115
  static getSpaceQuota(store: Store): Promise<number>;
116
116
  static getKeyDerivParams(store: Store): Promise<any>;
117
117
  static setKeyDerivParams(store: Store, params: any, setDefault: boolean): Promise<boolean>;
@@ -153,10 +153,12 @@ class Store extends user_files_1.UserFiles {
153
153
  await spaceTracker.change(this, byteLen);
154
154
  }
155
155
  const params = {
156
- isNewObj: opts.create,
157
156
  version: opts.ver,
158
157
  baseVersion: (diff ? diff.baseVersion : undefined)
159
158
  };
159
+ if (opts.ver === 1) {
160
+ params.isNewObj = true;
161
+ }
160
162
  const trans = await this.transactions.startNew(objId, params);
161
163
  let file;
162
164
  try {
@@ -413,10 +415,12 @@ class Store extends user_files_1.UserFiles {
413
415
  await this.statuses.set(objId, status);
414
416
  this.storageEventsSink(this.userId, owner_1.events.objVersionArchived.EVENT_NAME, { objId, archivedVer: version });
415
417
  }
416
- async listObjArchive(objId) {
418
+ async getObjStatus(objId) {
417
419
  const status = await this.statuses.get(objId);
418
- const arch = status.archivedVersions;
419
- return (Array.isArray(arch) ? arch : []);
420
+ return {
421
+ current: status.currentVersion,
422
+ archived: status.archivedVersions
423
+ };
420
424
  }
421
425
  static getSpaceQuota(store) {
422
426
  return store.getSpaceQuota();
@@ -651,7 +655,7 @@ class ObjTransactions {
651
655
  if (status.state !== 'current') {
652
656
  throw exports.SC.OBJ_UNKNOWN;
653
657
  }
654
- else if (trans.version <= status.currentVersion) {
658
+ else if (trans.version !== (status.currentVersion + 1)) {
655
659
  throw makeMismatchedObjVerException(status.currentVersion);
656
660
  }
657
661
  }
@@ -726,7 +730,7 @@ class ObjTransactions {
726
730
  Object.freeze(ObjStatuses.prototype);
727
731
  Object.freeze(ObjStatuses);
728
732
  function toFName(version) {
729
- return `${version}.`;
733
+ return `${version}.v`;
730
734
  }
731
735
  function noop() { }
732
736
  Object.freeze(exports);
@@ -6,7 +6,7 @@
6
6
  */
7
7
  import { Readable as ReadableStream } from 'stream';
8
8
  import { ObjReader, StorageEventsSink } from './store';
9
- import { PutObjFirstQueryOpts, PutObjSecondQueryOpts, DiffInfo } from '../../lib-common/service-api/3nstorage/owner';
9
+ import { PutObjFirstQueryOpts, PutObjSecondQueryOpts, DiffInfo, ObjStatus } from '../../lib-common/service-api/3nstorage/owner';
10
10
  export { SC, ObjReader, MismatchedObjVerException } from './store';
11
11
  export declare type UserExists = (userId: string) => Promise<boolean>;
12
12
  export declare type GetCurrentObj = (userId: string, objId: string | null, header: boolean, segsOffset: number, segsLimit: number | undefined) => Promise<{
@@ -17,7 +17,7 @@ export declare type SaveNewObjVersion = (userId: string, objId: string | null, f
17
17
  export declare type GetArchivedObjVersion = (userId: string, objId: string | null, version: number, header: boolean, segsOffset: number, segsLimit: number | undefined) => Promise<ObjReader>;
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
- export declare type ListObjArchive = (userId: string, objId: string) => Promise<number[]>;
20
+ export declare type GetObjStatus = (userId: string, objId: string) => Promise<ObjStatus>;
21
21
  export declare type DeleteCurrentObjVersion = (userId: string, objId: string, version?: number) => Promise<void>;
22
22
  export declare type DeleteArchivedObjVersion = (userId: string, objId: string | null, version: number) => Promise<void>;
23
23
  declare type GetParam<T> = (userId: string) => Promise<T>;
@@ -39,7 +39,7 @@ export interface Factory {
39
39
  saveNewObjVersion: SaveNewObjVersion;
40
40
  saveNewRootVersion: SaveNewObjVersion;
41
41
  getCurrentRootObj: GetCurrentObj;
42
- listObjArchive: ListObjArchive;
42
+ getObjStatus: GetObjStatus;
43
43
  archiveObjVersion: ArchiveObjCurrentVersion;
44
44
  getArchivedRootVersion: GetArchivedObjVersion;
45
45
  getArchivedObjVersion: GetArchivedObjVersion;
@@ -130,9 +130,9 @@ function makeFactory(rootFolder, writeBufferSize, readBufferSize) {
130
130
  const store = await getStore(userId);
131
131
  await store.archiveCurrentObjVersion(objId, version);
132
132
  },
133
- listObjArchive: async (userId, objId) => {
133
+ getObjStatus: async (userId, objId) => {
134
134
  const store = await getStore(userId);
135
- return store.listObjArchive(objId);
135
+ return store.getObjStatus(objId);
136
136
  },
137
137
  deleteArchivedObjVersion: async (userId, objId, version) => {
138
138
  const store = await getStore(userId);
@@ -0,0 +1,3 @@
1
+ import { RequestHandler } from 'express';
2
+ import { GetObjStatus } from '../../resources/users';
3
+ export declare function getObjStatus(root: boolean, getObjStatusFunc: GetObjStatus): RequestHandler;
@@ -16,26 +16,26 @@
16
16
  this program. If not, see <http://www.gnu.org/licenses/>.
17
17
  */
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
- exports.listObjArchive = void 0;
19
+ exports.getObjStatus = void 0;
20
20
  const users_1 = require("../../resources/users");
21
21
  const owner_1 = require("../../../lib-common/service-api/3nstorage/owner");
22
- function listObjArchive(root, listObjArchiveFunc) {
23
- if ('function' !== typeof listObjArchiveFunc) {
24
- throw new TypeError("Given argument 'listObjArchiveFunc' must be function, but is not.");
22
+ function getObjStatus(root, getObjStatusFunc) {
23
+ if ('function' !== typeof getObjStatusFunc) {
24
+ throw new TypeError("Given argument 'getObjStatusFunc' must be function, but is not.");
25
25
  }
26
26
  return async (req, res, next) => {
27
27
  const userId = req.session.params.userId;
28
28
  const objId = (root ? null : req.params.objId);
29
29
  try {
30
- const lst = await listObjArchiveFunc(userId, objId);
31
- res.status(owner_1.archiveObj.SC.okGet).json(lst);
30
+ const lst = await getObjStatusFunc(userId, objId);
31
+ res.status(owner_1.objStatus.SC.ok).json(lst);
32
32
  }
33
33
  catch (err) {
34
34
  if ("string" !== typeof err) {
35
35
  next(err);
36
36
  }
37
37
  else if (err === users_1.SC.OBJ_UNKNOWN) {
38
- res.status(owner_1.archiveObj.SC.unknownObj).send(root ?
38
+ res.status(owner_1.objStatus.SC.unknownObj).send(root ?
39
39
  `Root object is set.` : `Object ${objId} is unknown.`);
40
40
  }
41
41
  else if (err === users_1.SC.USER_UNKNOWN) {
@@ -48,6 +48,6 @@ function listObjArchive(root, listObjArchiveFunc) {
48
48
  }
49
49
  };
50
50
  }
51
- exports.listObjArchive = listObjArchive;
51
+ exports.getObjStatus = getObjStatus;
52
52
  ;
53
53
  Object.freeze(exports);
@@ -53,7 +53,7 @@ function saveCurrentObj(root, saveObjFunc, chunkLimit) {
53
53
  const { fstReq, sndReq } = opts;
54
54
  let diff;
55
55
  if (fstReq) {
56
- if (fstReq.create && objId) {
56
+ if (!root && objId) {
57
57
  if (!buffer_utils_1.base64urlSafe.allCharsFromAlphabet(objId)) {
58
58
  return replyToMalformed(req, "Bad object id", res);
59
59
  }
@@ -171,7 +171,6 @@ function extractQueryOptions(req) {
171
171
  // this is the first request
172
172
  // query fields are string or undefined, yet, type info helps the show
173
173
  const query = req.query;
174
- const create = (query.create === 'true');
175
174
  const ver = parseInt(query.ver);
176
175
  if (isNaN(ver) || (ver < 1)) {
177
176
  return;
@@ -187,7 +186,7 @@ function extractQueryOptions(req) {
187
186
  return;
188
187
  }
189
188
  const last = (query.last === 'true');
190
- return { fstReq: { diff, header, last, ver, create } };
189
+ return { fstReq: { diff, header, last, ver } };
191
190
  }
192
191
  }
193
192
  function getContentLenOrSendError(req, res, maxChunkSize) {
@@ -66,10 +66,6 @@ export interface GetObjQueryOpts {
66
66
  ver?: number;
67
67
  }
68
68
  export interface PutObjFirstQueryOpts {
69
- /**
70
- * This is a flag to indicate that new object should be created.
71
- */
72
- create?: boolean;
73
69
  /**
74
70
  * This parameter is object's new version.
75
71
  */
@@ -109,6 +105,7 @@ export interface PutObjSecondQueryOpts {
109
105
  export declare namespace currentObj {
110
106
  const EXPRESS_URL_END = "obj/:objId/current";
111
107
  function getReqUrlEnd(objId: string, opts?: GetObjQueryOpts): string;
108
+ function delReqUrlEnd(objId: string, ver?: number): string;
112
109
  function firstPutReqUrlEnd(objId: string, opts: PutObjFirstQueryOpts): string;
113
110
  function secondPutReqUrlEnd(objId: string, opts: PutObjSecondQueryOpts): string;
114
111
  interface ReplyToPut {
@@ -214,13 +211,33 @@ export declare namespace cancelRootTransaction {
214
211
  missing: number;
215
212
  };
216
213
  }
214
+ export interface ObjStatus {
215
+ current?: number;
216
+ archived?: number[];
217
+ }
218
+ export declare namespace objStatus {
219
+ const EXPRESS_URL_END = "obj/:objId/status";
220
+ function getReqUrlEnd(objId: string): string;
221
+ type Reply = ObjStatus;
222
+ const SC: {
223
+ ok: number;
224
+ unknownObj: number;
225
+ };
226
+ }
227
+ export declare namespace rootStatus {
228
+ const EXPRESS_URL_END = "root/status";
229
+ function getReqUrlEnd(): string;
230
+ type Reply = ObjStatus;
231
+ const SC: {
232
+ ok: number;
233
+ unknownObj: number;
234
+ };
235
+ }
217
236
  export declare namespace archiveObj {
218
237
  const EXPRESS_URL_END = "obj/:objId/archive";
219
- function getReqUrlEnd(objId: string): string;
220
238
  function postAndDelReqUrlEnd(objId: string, version: number): string;
221
239
  type VersionsList = number[];
222
240
  const SC: {
223
- okGet: number;
224
241
  okPost: number;
225
242
  okDelete: number;
226
243
  unknownObj: number;
@@ -228,12 +245,10 @@ export declare namespace archiveObj {
228
245
  };
229
246
  }
230
247
  export declare namespace archiveRoot {
231
- const URL_END = "root/archive";
232
- function getReqUrlEnd(): string;
248
+ const EXPRESS_URL_END = "root/archive";
233
249
  function postAndDelReqUrlEnd(version: number): string;
234
250
  type VersionsList = archiveObj.VersionsList;
235
251
  const SC: {
236
- okGet: number;
237
252
  okPost: number;
238
253
  okDelete: number;
239
254
  unknownObj: number;
@@ -16,7 +16,7 @@
16
16
  this program. If not, see <http://www.gnu.org/licenses/>.
17
17
  */
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
- exports.events = exports.wsEventChannel = exports.archiveRoot = exports.archiveObj = exports.cancelRootTransaction = exports.cancelTransaction = exports.addDiffSectionTo = exports.sanitizedDiff = exports.archivedRootVersion = exports.archivedObjVersion = exports.currentRootObj = exports.currentObj = exports.keyDerivParams = exports.PARAM_SC = exports.sessionParams = exports.closeSession = exports.midLogin = exports.BIN_TYPE = exports.HTTP_HEADER = exports.ERR_SC = void 0;
19
+ exports.events = exports.wsEventChannel = exports.archiveRoot = exports.archiveObj = exports.rootStatus = exports.objStatus = exports.cancelRootTransaction = exports.cancelTransaction = exports.addDiffSectionTo = exports.sanitizedDiff = exports.archivedRootVersion = exports.archivedObjVersion = exports.currentRootObj = exports.currentObj = exports.keyDerivParams = exports.PARAM_SC = exports.sessionParams = exports.closeSession = exports.midLogin = exports.BIN_TYPE = exports.HTTP_HEADER = exports.ERR_SC = void 0;
20
20
  /**
21
21
  * This defines interfaces for 3nstorage owner's requests.
22
22
  */
@@ -79,6 +79,10 @@ var currentObj;
79
79
  return `obj/${objId}/current${opts ? `?${(0, querystring_1.stringify)(opts)}` : ''}`;
80
80
  }
81
81
  currentObj.getReqUrlEnd = getReqUrlEnd;
82
+ function delReqUrlEnd(objId, ver) {
83
+ return `obj/${objId}/current${ver ? `?${(0, querystring_1.stringify)({ ver })}` : ''}`;
84
+ }
85
+ currentObj.delReqUrlEnd = delReqUrlEnd;
82
86
  function firstPutReqUrlEnd(objId, opts) {
83
87
  return `obj/${objId}/current?${(0, querystring_1.stringify)(opts)}`;
84
88
  }
@@ -220,19 +224,37 @@ var cancelRootTransaction;
220
224
  cancelRootTransaction.SC = cancelTransaction.SC;
221
225
  })(cancelRootTransaction = exports.cancelRootTransaction || (exports.cancelRootTransaction = {}));
222
226
  Object.freeze(cancelRootTransaction);
227
+ var objStatus;
228
+ (function (objStatus) {
229
+ objStatus.EXPRESS_URL_END = 'obj/:objId/status';
230
+ function getReqUrlEnd(objId) {
231
+ return `obj/${objId}/status`;
232
+ }
233
+ objStatus.getReqUrlEnd = getReqUrlEnd;
234
+ objStatus.SC = {
235
+ ok: 200,
236
+ unknownObj: 474,
237
+ };
238
+ })(objStatus = exports.objStatus || (exports.objStatus = {}));
239
+ Object.freeze(objStatus);
240
+ var rootStatus;
241
+ (function (rootStatus) {
242
+ rootStatus.EXPRESS_URL_END = 'root/status';
243
+ function getReqUrlEnd() {
244
+ return 'root/status';
245
+ }
246
+ rootStatus.getReqUrlEnd = getReqUrlEnd;
247
+ rootStatus.SC = objStatus.SC;
248
+ })(rootStatus = exports.rootStatus || (exports.rootStatus = {}));
249
+ Object.freeze(rootStatus);
223
250
  var archiveObj;
224
251
  (function (archiveObj) {
225
252
  archiveObj.EXPRESS_URL_END = 'obj/:objId/archive';
226
- function getReqUrlEnd(objId) {
227
- return `obj/${objId}/archive`;
228
- }
229
- archiveObj.getReqUrlEnd = getReqUrlEnd;
230
253
  function postAndDelReqUrlEnd(objId, version) {
231
254
  return `obj/${objId}/archive?ver=${version}`;
232
255
  }
233
256
  archiveObj.postAndDelReqUrlEnd = postAndDelReqUrlEnd;
234
257
  archiveObj.SC = {
235
- okGet: 200,
236
258
  okPost: 200,
237
259
  okDelete: 200,
238
260
  unknownObj: 474,
@@ -242,11 +264,7 @@ var archiveObj;
242
264
  Object.freeze(archiveObj);
243
265
  var archiveRoot;
244
266
  (function (archiveRoot) {
245
- archiveRoot.URL_END = 'root/archive';
246
- function getReqUrlEnd() {
247
- return `root/archive`;
248
- }
249
- archiveRoot.getReqUrlEnd = getReqUrlEnd;
267
+ archiveRoot.EXPRESS_URL_END = 'root/archive';
250
268
  function postAndDelReqUrlEnd(version) {
251
269
  return `root/archive?ver=${version}`;
252
270
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spec-3nweb-server",
3
- "version": "1.5.2",
3
+ "version": "1.6.2",
4
4
  "description": "3NWeb spec server.",
5
5
  "main": "build/lib.js",
6
6
  "types": "build/lib.d.ts",
@@ -1,3 +0,0 @@
1
- import { RequestHandler } from 'express';
2
- import { ListObjArchive } from '../../resources/users';
3
- export declare function listObjArchive(root: boolean, listObjArchiveFunc: ListObjArchive): RequestHandler;