core-3nweb-client-lib 0.44.6 → 0.44.8

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.
Files changed (43) hide show
  1. package/build/api-defs/files.d.ts +1 -0
  2. package/build/api-defs/web3n.d.ts +2 -1
  3. package/build/core/asmail/inbox/inbox-events.d.ts +0 -1
  4. package/build/core/asmail/inbox/inbox-events.js +3 -5
  5. package/build/core/asmail/inbox/index.js +1 -1
  6. package/build/core/asmail/inbox/msg-downloader.d.ts +1 -2
  7. package/build/core/asmail/inbox/msg-downloader.js +3 -4
  8. package/build/core/storage/synced/obj-files.js +1 -1
  9. package/build/core/storage/synced/obj-status.d.ts +2 -0
  10. package/build/core/storage/synced/obj-status.js +9 -5
  11. package/build/core/storage/synced/remote-events.d.ts +0 -1
  12. package/build/core/storage/synced/remote-events.js +5 -7
  13. package/build/core/storage/synced/storage.js +2 -2
  14. package/build/core/storage/synced/upsyncer.d.ts +1 -2
  15. package/build/core/storage/synced/upsyncer.js +49 -25
  16. package/build/lib-client/3nstorage/storage-owner.js +1 -1
  17. package/build/lib-client/asmail/recipient.js +8 -4
  18. package/build/lib-client/cryptor/cryptor-wasm.js +1 -1
  19. package/build/lib-client/cryptor/cryptor.wasm +0 -0
  20. package/build/lib-client/cryptor/worker-js.js +4 -2
  21. package/build/lib-client/local-files/dev-file-sink.js +30 -28
  22. package/build/lib-client/local-files/dev-file-src.js +7 -6
  23. package/build/lib-client/local-files/device-fs.js +23 -23
  24. package/build/lib-client/objs-on-disk/obj-folders.js +6 -3
  25. package/build/lib-client/request-utils.d.ts +2 -1
  26. package/build/lib-client/request-utils.js +8 -19
  27. package/build/lib-client/user-with-mid-session.d.ts +2 -0
  28. package/build/lib-client/user-with-mid-session.js +33 -22
  29. package/build/lib-client/xsp-fs/attrs.js +4 -2
  30. package/build/lib-client/xsp-fs/exceptions.js +5 -2
  31. package/build/lib-client/xsp-fs/folder-node-serialization.js +4 -2
  32. package/build/lib-client/xsp-fs/node-in-fs.js +2 -5
  33. package/build/lib-common/async-fs-node.d.ts +30 -46
  34. package/build/lib-common/async-fs-node.js +71 -309
  35. package/build/lib-common/awaitable-state.js +3 -1
  36. package/build/lib-common/exceptions/file.d.ts +1 -1
  37. package/build/lib-common/exceptions/file.js +11 -6
  38. package/build/lib-common/exceptions/runtime.d.ts +7 -1
  39. package/build/lib-common/exceptions/runtime.js +16 -2
  40. package/build/lib-common/objs-on-disk/obj-version-file.d.ts +1 -1
  41. package/build/lib-common/objs-on-disk/obj-version-file.js +35 -33
  42. package/build/lib-index.d.ts +1 -1
  43. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- Copyright (C) 2021 3NSoft Inc.
3
+ Copyright (C) 2021, 2026 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,7 +17,8 @@
17
17
  */
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
19
  exports.makeRuntimeException = makeRuntimeException;
20
- function makeRuntimeException(type, params, flags) {
20
+ exports.getStackHere = getStackHere;
21
+ function makeRuntimeException(type, params, flags, addStack = false) {
21
22
  const exc = {
22
23
  runtimeException: true,
23
24
  type,
@@ -32,6 +33,19 @@ function makeRuntimeException(type, params, flags) {
32
33
  exc[field] = val;
33
34
  }
34
35
  }
36
+ if (addStack) {
37
+ exc.stack = getStackHere(1);
38
+ }
35
39
  return exc;
36
40
  }
41
+ /**
42
+ *
43
+ * @param numOfTopLayersToRemove
44
+ * @returns
45
+ */
46
+ function getStackHere(numOfTopLayersToRemove = 0) {
47
+ var _a;
48
+ const err = new Error('stack');
49
+ return (_a = err.stack) === null || _a === void 0 ? void 0 : _a.split('\n').slice(2 + numOfTopLayersToRemove).join('\n');
50
+ }
37
51
  Object.freeze(exports);
@@ -13,7 +13,7 @@ export declare class ObjVersionFile {
13
13
  removeFile(): Promise<void>;
14
14
  saveLayout(): Promise<void>;
15
15
  /**
16
- * @param fd already openned file descriptor
16
+ * @param fh already opened file handle
17
17
  * @param ofs is an optional offset at which layout is written, when we need
18
18
  * value different from current one in layout.
19
19
  */
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- Copyright (C) 2019 - 2020, 2022 3NSoft Inc.
3
+ Copyright (C) 2019 - 2020, 2022, 2026 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
@@ -28,6 +28,7 @@ const fs_1 = require("fs");
28
28
  const file_layout_1 = require("./file-layout");
29
29
  const big_endian_1 = require("../big-endian");
30
30
  const assert_1 = require("../assert");
31
+ const runtime_1 = require("../exceptions/runtime");
31
32
  class ObjVersionFile {
32
33
  constructor(path, layout) {
33
34
  this.path = path;
@@ -56,12 +57,12 @@ class ObjVersionFile {
56
57
  if (newHeader) {
57
58
  (0, assert_1.assert)(newHeader.length === ((_a = this.layout.headerLocation()) === null || _a === void 0 ? void 0 : _a.len));
58
59
  const headerOfs = this.layout.headerLocation().fileOfs;
59
- const fd = await fs.open(this.path, 'r+');
60
+ const fh = await fs.open(this.path, 'r+');
60
61
  try {
61
- await fs.write(fd, headerOfs, (0, buffer_utils_1.toBuffer)(newHeader));
62
+ await fs.write(fh, headerOfs, (0, buffer_utils_1.toBuffer)(newHeader));
62
63
  }
63
64
  finally {
64
- await fs.close(fd).catch(noop);
65
+ await fh.close().catch(noop);
65
66
  }
66
67
  }
67
68
  });
@@ -73,30 +74,30 @@ class ObjVersionFile {
73
74
  return this.withRWFile(fd => this.recordLayout(fd));
74
75
  }
75
76
  /**
76
- * @param fd already openned file descriptor
77
+ * @param fh already opened file handle
77
78
  * @param ofs is an optional offset at which layout is written, when we need
78
79
  * value different from current one in layout.
79
80
  */
80
- async recordLayout(fd, ofs) {
81
+ async recordLayout(fh, ofs) {
81
82
  const layoutBytes = this.layout.toBytes();
82
83
  if (!ofs) {
83
84
  ofs = this.layout.getLayoutOfs();
84
85
  }
85
- await fs.writeFromBuf(fd, ofs, layoutBytes);
86
- await recordLayoutOffsetInV1(fd, ofs);
87
- await fs.ftruncate(fd, ofs + layoutBytes.length);
86
+ await fs.writeFromBuf(fh, ofs, layoutBytes);
87
+ await recordLayoutOffsetInV1(fh, ofs);
88
+ await fh.truncate(ofs + layoutBytes.length);
88
89
  }
89
90
  withRWFile(action) {
90
91
  return this.writeProc.startOrChain(async () => {
91
- const fd = await fs.open(this.path, 'r+')
92
+ const fh = await fs.open(this.path, 'r+')
92
93
  .catch(exc => {
93
94
  throw (0, error_1.errWithCause)(exc, `Can't open for writing obj-version file ${this.path}`);
94
95
  });
95
96
  try {
96
- return await action(fd);
97
+ return await action(fh);
97
98
  }
98
99
  finally {
99
- await fs.close(fd).catch(noop);
100
+ await fh.close().catch(noop);
100
101
  }
101
102
  });
102
103
  }
@@ -136,16 +137,16 @@ class ObjVersionFile {
136
137
  }
137
138
  async withROFile(action) {
138
139
  const path = this.path;
139
- let fd;
140
+ let fh;
140
141
  try {
141
- fd = await fs.open(path, 'r');
142
+ fh = await fs.open(path, 'r');
142
143
  }
143
144
  catch (exc) {
144
145
  // in some use cases version file can be moved, and for this reason
145
146
  // we make second attempt if path is newer
146
147
  if (exc.notFound && (path !== this.path)) {
147
148
  try {
148
- fd = await fs.open(this.path, 'r');
149
+ fh = await fs.open(this.path, 'r');
149
150
  }
150
151
  catch (exc) {
151
152
  throw (0, error_1.errWithCause)(exc, `Can't open for reading obj version file ${this.path}`);
@@ -156,10 +157,10 @@ class ObjVersionFile {
156
157
  }
157
158
  }
158
159
  try {
159
- return await action(fd);
160
+ return await action(fh);
160
161
  }
161
162
  finally {
162
- await fs.close(fd).catch(err => { });
163
+ await fh.close().catch(noop);
163
164
  }
164
165
  }
165
166
  getHeaderLen() {
@@ -251,13 +252,13 @@ class ObjVersionFile {
251
252
  return this.layout.isFileComplete();
252
253
  }
253
254
  async absorbImmediateBaseVersion(baseVer, path) {
254
- (0, assert_1.assert)(baseVer === this.layout.getBaseVersion());
255
+ (0, assert_1.assert)(Number.isInteger(baseVer) && (baseVer === this.layout.getBaseVersion()));
255
256
  const baseLayout = await readLayoutFrom(path);
256
257
  const absorptionParams = this.layout.calcBaseAbsorptionParams(baseLayout);
257
258
  const src = await fs.open(path, 'r');
258
- await this.withRWFile(async (fd) => {
259
+ await this.withRWFile(async (fh) => {
259
260
  if (absorptionParams.copyOps.length > 0) {
260
- await this.recordLayout(fd, absorptionParams.newBytesEnd);
261
+ await this.recordLayout(fh, absorptionParams.newBytesEnd);
261
262
  let buf = Buffer.allocUnsafe(absorptionParams.copyOps[0].len);
262
263
  for (const op of absorptionParams.copyOps) {
263
264
  if (buf.length < op.len) {
@@ -266,14 +267,14 @@ class ObjVersionFile {
266
267
  const chunk = ((op.len < buf.length) ?
267
268
  buf.slice(0, op.len) : buf);
268
269
  await fs.readToBuf(src, op.ofsInSrcFile, chunk);
269
- await fs.writeFromBuf(fd, op.ofsInDstFile, chunk);
270
+ await fs.writeFromBuf(fh, op.ofsInDstFile, chunk);
270
271
  }
271
272
  }
272
273
  this.layout.applyAbsorptionParams(absorptionParams);
273
- await this.recordLayout(fd);
274
+ await this.recordLayout(fh);
274
275
  })
275
- .then(() => fs.close(src).catch(noop), async (exc) => {
276
- await fs.close(src).catch(noop);
276
+ .then(() => src.close().catch(noop), async (exc) => {
277
+ await src.close().catch(noop);
277
278
  throw exc;
278
279
  });
279
280
  }
@@ -303,16 +304,17 @@ function parsingException(msg, cause) {
303
304
  runtimeException: true,
304
305
  type: 'obj-file-parsing',
305
306
  cause, msg,
306
- path: ''
307
+ path: '',
308
+ stack: (0, runtime_1.getStackHere)(1)
307
309
  };
308
310
  }
309
311
  /**
310
312
  * This parses obj version file's informational parts.
311
- * @param fd is an open file descriptor, of a file to parse
313
+ * @param fh is an open file handle, of a file to parse
312
314
  */
313
- async function parseObjVersionBytesLayout(fd) {
315
+ async function parseObjVersionBytesLayout(fh) {
314
316
  const fstBytes = Buffer.allocUnsafe(12);
315
- await fs.readToBuf(fd, 0, fstBytes).catch((exc) => {
317
+ await fs.readToBuf(fh, 0, fstBytes).catch((exc) => {
316
318
  if (exc.endOfFile) {
317
319
  throw parsingException('File is too short to contain object');
318
320
  }
@@ -327,12 +329,12 @@ async function parseObjVersionBytesLayout(fd) {
327
329
  if (layoutOfs > Number.MAX_SAFE_INTEGER) {
328
330
  throw parsingException(`This implementation can't handle files with length over 2^53`);
329
331
  }
330
- const fileSize = (await fs.fstat(fd)).size;
332
+ const fileSize = (await fh.stat()).size;
331
333
  if (layoutOfs >= fileSize) {
332
334
  throw parsingException(`Layout offset is greater than file size`);
333
335
  }
334
336
  const layoutBytes = Buffer.allocUnsafe(fileSize - layoutOfs);
335
- await fs.readToBuf(fd, layoutOfs, layoutBytes);
337
+ await fs.readToBuf(fh, layoutOfs, layoutBytes);
336
338
  return file_layout_1.ObjVersionBytesLayout.fromV1Bytes(layoutOfs, layoutBytes);
337
339
  }
338
340
  else {
@@ -354,9 +356,9 @@ async function recordLayoutOffsetInV1(fd, ofs) {
354
356
  });
355
357
  }
356
358
  async function readLayoutFrom(path) {
357
- const fd = await fs.open(path, 'r');
359
+ const fh = await fs.open(path, 'r');
358
360
  try {
359
- const layout = await parseObjVersionBytesLayout(fd)
361
+ const layout = await parseObjVersionBytesLayout(fh)
360
362
  .catch((err) => {
361
363
  if (err.type === 'obj-file-parsing') {
362
364
  err.path = path;
@@ -366,7 +368,7 @@ async function readLayoutFrom(path) {
366
368
  return layout;
367
369
  }
368
370
  finally {
369
- await fs.close(fd).catch(noop);
371
+ await fh.close().catch(noop);
370
372
  }
371
373
  }
372
374
  Object.freeze(exports);
@@ -6,7 +6,7 @@ export { Storages, FactoryOfFSs, reverseDomain } from './core/storage';
6
6
  export { SignIn, GenerateKey, CompleteInitWithoutCache } from './core/startup/sign-in';
7
7
  export { ASMail } from './core/asmail';
8
8
  export { makeServiceLocator, ServiceLocatorMaker } from "./lib-client/service-locator";
9
- export { makeNetClient } from "./lib-client/request-utils";
9
+ export { makeNetClient, NetClient } from "./lib-client/request-utils";
10
10
  export { appDirs } from './core/app-files';
11
11
  export { sysFolders } from "./core/storage/system-folders";
12
12
  export { DeviceFS } from './lib-client/local-files/device-fs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "core-3nweb-client-lib",
3
- "version": "0.44.6",
3
+ "version": "0.44.8",
4
4
  "description": "3NWeb client core library, embeddable into different environments",
5
5
  "main": "build/lib-index.js",
6
6
  "types": "build/lib-index.d.ts",