core-3nweb-client-lib 0.44.7 → 0.44.9

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 (42) 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/common/obj-info-file.d.ts +0 -1
  9. package/build/core/storage/common/obj-info-file.js +0 -10
  10. package/build/core/storage/synced/obj-status.d.ts +1 -0
  11. package/build/core/storage/synced/obj-status.js +8 -12
  12. package/build/core/storage/synced/remote-events.d.ts +0 -1
  13. package/build/core/storage/synced/remote-events.js +5 -7
  14. package/build/core/storage/synced/storage.js +2 -2
  15. package/build/core/storage/synced/upsyncer.d.ts +1 -2
  16. package/build/core/storage/synced/upsyncer.js +49 -25
  17. package/build/lib-client/3nstorage/storage-owner.js +1 -1
  18. package/build/lib-client/asmail/recipient.js +8 -4
  19. package/build/lib-client/cryptor/worker-js.js +4 -2
  20. package/build/lib-client/local-files/dev-file-sink.js +30 -28
  21. package/build/lib-client/local-files/dev-file-src.js +7 -6
  22. package/build/lib-client/local-files/device-fs.js +23 -23
  23. package/build/lib-client/objs-on-disk/obj-folders.js +6 -3
  24. package/build/lib-client/request-utils.d.ts +2 -1
  25. package/build/lib-client/request-utils.js +8 -19
  26. package/build/lib-client/user-with-mid-session.d.ts +2 -0
  27. package/build/lib-client/user-with-mid-session.js +33 -22
  28. package/build/lib-client/xsp-fs/attrs.js +4 -2
  29. package/build/lib-client/xsp-fs/exceptions.js +5 -4
  30. package/build/lib-client/xsp-fs/folder-node-serialization.js +4 -2
  31. package/build/lib-client/xsp-fs/node-in-fs.js +2 -5
  32. package/build/lib-common/async-fs-node.d.ts +30 -46
  33. package/build/lib-common/async-fs-node.js +71 -309
  34. package/build/lib-common/awaitable-state.js +3 -1
  35. package/build/lib-common/exceptions/file.d.ts +1 -1
  36. package/build/lib-common/exceptions/file.js +11 -6
  37. package/build/lib-common/exceptions/runtime.d.ts +7 -1
  38. package/build/lib-common/exceptions/runtime.js +16 -2
  39. package/build/lib-common/objs-on-disk/obj-version-file.d.ts +1 -1
  40. package/build/lib-common/objs-on-disk/obj-version-file.js +35 -33
  41. package/build/lib-index.d.ts +1 -1
  42. package/package.json +1 -1
@@ -13,7 +13,8 @@
13
13
  See the GNU General Public License for more details.
14
14
 
15
15
  You should have received a copy of the GNU General Public License along with
16
- this program. If not, see <http://www.gnu.org/licenses/>. */
16
+ this program. If not, see <http://www.gnu.org/licenses/>.
17
+ */
17
18
  Object.defineProperty(exports, "__esModule", { value: true });
18
19
  exports.DevFileByteSource = void 0;
19
20
  const fs = require("../../lib-common/async-fs-node");
@@ -38,9 +39,9 @@ class DevFileByteSource {
38
39
  if (this.offset >= this.size) {
39
40
  return;
40
41
  }
41
- let fd = undefined;
42
+ let fh = undefined;
42
43
  try {
43
- fd = await fs.open(this.path, 'r');
44
+ fh = await fs.open(this.path, 'r');
44
45
  let buf;
45
46
  if (typeof len === 'number') {
46
47
  len = Math.min(this.size - this.offset, len);
@@ -49,7 +50,7 @@ class DevFileByteSource {
49
50
  else {
50
51
  buf = Buffer.allocUnsafe(this.size - this.offset);
51
52
  }
52
- await fs.readToBuf(fd, this.offset, buf);
53
+ await fs.readToBuf(fh, this.offset, buf);
53
54
  this.offset += buf.length;
54
55
  return buf;
55
56
  }
@@ -57,8 +58,8 @@ class DevFileByteSource {
57
58
  throw (0, file_1.maskPathInExc)(this.pathPrefixMaskLen, e);
58
59
  }
59
60
  finally {
60
- if (fd !== undefined) {
61
- await fs.close(fd);
61
+ if (fh !== undefined) {
62
+ await fh.close();
62
63
  }
63
64
  }
64
65
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- Copyright (C) 2015 - 2018, 2020, 2022 3NSoft Inc.
3
+ Copyright (C) 2015 - 2018, 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
@@ -335,15 +335,15 @@ class DeviceFS {
335
335
  }
336
336
  async readBytes(path, start, end) {
337
337
  if ((typeof start === 'number') && (start < 0)) {
338
- throw new Error(`Parameter start has bad value: ${start}`);
338
+ throw new RangeError(`Parameter start has bad value: ${start}`);
339
339
  }
340
340
  if ((typeof end === 'number') && (end < 0)) {
341
- throw new Error(`Parameter end has bad value: ${end}`);
341
+ throw new RangeError(`Parameter end has bad value: ${end}`);
342
342
  }
343
- let fd = undefined;
343
+ let fh = undefined;
344
344
  try {
345
- fd = await fs.open(this.fullPath(path), 'r');
346
- const size = (await fs.fstat(fd)).size;
345
+ fh = await fs.open(this.fullPath(path), 'r');
346
+ const size = (await fh.stat()).size;
347
347
  if (size === 0) {
348
348
  return;
349
349
  }
@@ -358,22 +358,22 @@ class DeviceFS {
358
358
  return;
359
359
  }
360
360
  const bytes = Buffer.allocUnsafe(end - start);
361
- await fs.readToBuf(fd, start, bytes);
361
+ await fs.readToBuf(fh, start, bytes);
362
362
  return bytes;
363
363
  }
364
364
  catch (e) {
365
365
  throw (0, file_1.maskPathInExc)(this.root.length, e);
366
366
  }
367
367
  finally {
368
- if (fd !== undefined) {
369
- await fs.close(fd);
368
+ if (fh !== undefined) {
369
+ await fh.close();
370
370
  }
371
371
  }
372
372
  }
373
373
  async getByteSink(path, flags = WRITE_NONEXCL_FLAGS) {
374
374
  const pathSections = splitPathIntoParts(path);
375
375
  const pathStr = this.fullPath(path);
376
- let fd = undefined;
376
+ let fh = undefined;
377
377
  try {
378
378
  if (flags.create) {
379
379
  if (pathSections.length > 1) {
@@ -381,10 +381,10 @@ class DeviceFS {
381
381
  await this.makeFolder(enclosingFolder);
382
382
  }
383
383
  if (flags.exclusive) {
384
- fd = await fs.open(pathStr, 'wx');
384
+ fh = await fs.open(pathStr, 'wx');
385
385
  }
386
386
  else {
387
- fd = await fs.open(pathStr, flags.truncate ? 'w' : 'r+')
387
+ fh = await fs.open(pathStr, flags.truncate ? 'w' : 'r+')
388
388
  .catch((exc) => {
389
389
  if (exc.notFound) {
390
390
  return fs.open(pathStr, 'w');
@@ -396,17 +396,17 @@ class DeviceFS {
396
396
  }
397
397
  }
398
398
  else {
399
- fd = await fs.open(pathStr, flags.truncate ? 'w' : 'r+');
399
+ fh = await fs.open(pathStr, flags.truncate ? 'w' : 'r+');
400
400
  }
401
- const stats = await fs.fstat(fd);
401
+ const stats = await fh.stat();
402
402
  return dev_file_sink_1.DevFileByteSink.make(pathStr, this.root.length, stats);
403
403
  }
404
404
  catch (e) {
405
405
  throw (0, file_1.maskPathInExc)(this.root.length, e);
406
406
  }
407
407
  finally {
408
- if (fd !== undefined) {
409
- await fs.close(fd);
408
+ if (fh !== undefined) {
409
+ await fh.close();
410
410
  }
411
411
  }
412
412
  }
@@ -427,27 +427,27 @@ class DeviceFS {
427
427
  async writeBytes(path, bytes, flags = WRITE_NONEXCL_FLAGS) {
428
428
  const pathSections = splitPathIntoParts(path);
429
429
  const pathStr = this.fullPath(path);
430
- let fd = undefined;
430
+ let fh = undefined;
431
431
  try {
432
432
  if (flags.create) {
433
433
  if (pathSections.length > 1) {
434
434
  const enclosingFolder = pathSections.slice(0, pathSections.length - 1).join('/');
435
435
  await this.makeFolder(enclosingFolder);
436
436
  }
437
- fd = await fs.open(pathStr, (flags.exclusive ? 'wx' : 'w'));
437
+ fh = await fs.open(pathStr, (flags.exclusive ? 'wx' : 'w'));
438
438
  }
439
439
  else {
440
- fd = await fs.open(pathStr, 'r+');
441
- await fs.ftruncate(fd, 0);
440
+ fh = await fs.open(pathStr, 'r+');
441
+ await fh.truncate(0);
442
442
  }
443
- await fs.writeFromBuf(fd, 0, (0, buffer_utils_1.toBuffer)(bytes));
443
+ await fs.writeFromBuf(fh, 0, (0, buffer_utils_1.toBuffer)(bytes));
444
444
  }
445
445
  catch (e) {
446
446
  throw (0, file_1.maskPathInExc)(this.root.length, e);
447
447
  }
448
448
  finally {
449
- if (fd !== undefined) {
450
- await fs.close(fd);
449
+ if (fh !== undefined) {
450
+ await fh.close();
451
451
  }
452
452
  }
453
453
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- Copyright (C) 2016 - 2020, 2022 3NSoft Inc.
3
+ Copyright (C) 2016 - 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
@@ -25,12 +25,14 @@ const xsp_files_1 = require("xsp-files");
25
25
  const assert_1 = require("../../lib-common/assert");
26
26
  const error_1 = require("../../lib-common/exceptions/error");
27
27
  const path_1 = require("path");
28
+ const runtime_1 = require("../../lib-common/exceptions/runtime");
28
29
  function makeNotFoundExc(msg) {
29
30
  return {
30
31
  runtimeException: true,
31
32
  type: 'cache',
32
33
  cause: msg,
33
- notFound: true
34
+ notFound: true,
35
+ stack: (0, runtime_1.getStackHere)(1)
34
36
  };
35
37
  }
36
38
  function makeAlreadyExistExc(msg) {
@@ -38,7 +40,8 @@ function makeAlreadyExistExc(msg) {
38
40
  runtimeException: true,
39
41
  type: 'cache',
40
42
  cause: msg,
41
- alreadyExist: true
43
+ alreadyExist: true,
44
+ stack: (0, runtime_1.getStackHere)(1)
42
45
  };
43
46
  }
44
47
  function alreadyExistsOrReThrow(exc) {
@@ -51,5 +51,6 @@ export interface NetClient {
51
51
  * @param opts
52
52
  */
53
53
  doBodylessRequest<T>(opts: RequestOpts): Promise<Reply<T>>;
54
+ reset(): void;
54
55
  }
55
- export declare function makeNetClient(request?: RequestFn<unknown>): NetClient;
56
+ export declare function makeNetClient(request?: RequestFn<unknown>, reset?: () => void): NetClient;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- Copyright (C) 2015 - 2018, 2020, 2025 3NSoft Inc.
3
+ Copyright (C) 2015 - 2018, 2020, 2025 - 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
@@ -23,7 +23,6 @@ exports.makeNetClient = makeNetClient;
23
23
  const http_1 = require("../lib-common/exceptions/http");
24
24
  const bytes_fifo_buffer_1 = require("../lib-common/byte-streaming/bytes-fifo-buffer");
25
25
  const https = require("https");
26
- const url_1 = require("url");
27
26
  const rxjs_1 = require("rxjs");
28
27
  const buffer_utils_1 = require("../lib-common/buffer-utils");
29
28
  const deferred_1 = require("../lib-common/processes/deferred");
@@ -54,13 +53,13 @@ function formHttpsReqOpts(opts, contentType, reqBody) {
54
53
  if (reqBody && (opts.method !== 'POST') && (opts.method !== 'PUT')) {
55
54
  throw new Error(`Cannot have body in ${opts.method} request.`);
56
55
  }
57
- const url = (0, url_1.parse)(opts.url);
56
+ const url = new URL(opts.url);
58
57
  const netReqOpts = {
59
58
  protocol: url.protocol,
60
59
  method: opts.method,
61
60
  hostname: url.hostname,
62
61
  port: url.port,
63
- path: url.path,
62
+ path: url.pathname + url.search,
64
63
  headers: {}
65
64
  };
66
65
  if (reqBody) {
@@ -147,8 +146,7 @@ function formReply(res, resBody, reqOpts) {
147
146
  status,
148
147
  data,
149
148
  headers: (reqOpts.responseHeaders ?
150
- makeHeaders(filterHeaders(res.headers, reqOpts.responseHeaders)) :
151
- undefined)
149
+ makeHeaders(filterHeaders(res.headers, reqOpts.responseHeaders)) : undefined)
152
150
  };
153
151
  return rep;
154
152
  }
@@ -171,14 +169,6 @@ function makeHeaders(headers) {
171
169
  }
172
170
  };
173
171
  }
174
- // /**
175
- // * @param rep
176
- // * @param errMsg
177
- // * @return http exception based on given reply, with an optional message
178
- // */
179
- // export function makeException(rep: Reply<any>, message?: string): HTTPException {
180
- // return makeHTTPException(rep.url, rep.method, rep.status, { message });
181
- // }
182
172
  function extractIntHeader(rep, headerName) {
183
173
  const intHeader = parseInt(rep.headers.get(headerName));
184
174
  if (isNaN(intHeader)) {
@@ -195,7 +185,7 @@ function makeNodeRequest() {
195
185
  return processRequest(nodeRequest, httpsOpts, opts, reqBody);
196
186
  };
197
187
  }
198
- function makeNetClient(request = makeNodeRequest()) {
188
+ function makeNetClient(request = makeNodeRequest(), reset = () => { }) {
199
189
  const client = {
200
190
  doBinaryRequest(opts, bytes) {
201
191
  let reqBody;
@@ -215,11 +205,10 @@ function makeNetClient(request = makeNodeRequest()) {
215
205
  return request(opts);
216
206
  },
217
207
  doJsonRequest(opts, json) {
218
- const reqBody = ((json === undefined) ?
219
- new Uint8Array(0) :
220
- buffer_utils_1.utf8.pack(JSON.stringify(json)));
208
+ const reqBody = ((json === undefined) ? new Uint8Array(0) : buffer_utils_1.utf8.pack(JSON.stringify(json)));
221
209
  return request(opts, 'application/json', reqBody);
222
- }
210
+ },
211
+ reset
223
212
  };
224
213
  return Object.freeze(client);
225
214
  }
@@ -5,6 +5,7 @@
5
5
  import { Reply, RequestOpts, NetClient } from '../lib-client/request-utils';
6
6
  import * as WebSocket from 'ws';
7
7
  import { MailerIdSigner } from '../lib-common/mailerid-sigs/user';
8
+ import { AwaitableState } from '../lib-common/awaitable-state';
8
9
  export type IGetMailerIdSigner = () => Promise<MailerIdSigner>;
9
10
  export interface ServiceAccessParams {
10
11
  login: string;
@@ -22,6 +23,7 @@ export declare abstract class ServiceUser {
22
23
  private loginUrlPart;
23
24
  private logoutUrlEnd;
24
25
  private get loginUrl();
26
+ readonly connectedState: AwaitableState;
25
27
  private redirectedFrom;
26
28
  private canBeRedirected;
27
29
  private sessionId;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- Copyright (C) 2015, 2017, 2020, 2022, 2025 3NSoft Inc.
3
+ Copyright (C) 2015, 2017, 2020, 2022, 2025 - 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
@@ -19,16 +19,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
19
19
  exports.ServiceUser = void 0;
20
20
  const api = require("../lib-common/service-api/mailer-id/login");
21
21
  const ws_utils_1 = require("./ws-utils");
22
- const url_1 = require("url");
23
22
  const login_1 = require("./mailer-id/login");
24
23
  const assert_1 = require("../lib-common/assert");
25
24
  const http_1 = require("../lib-common/exceptions/http");
25
+ const awaitable_state_1 = require("../lib-common/awaitable-state");
26
26
  class ServiceUser {
27
27
  get serviceURI() {
28
28
  return this.uri;
29
29
  }
30
30
  set serviceURI(uriString) {
31
- const u = (0, url_1.parse)(uriString);
31
+ const u = new URL(uriString);
32
32
  if (u.protocol !== 'https:') {
33
33
  throw new Error("Url protocol must be https.");
34
34
  }
@@ -49,12 +49,12 @@ class ServiceUser {
49
49
  this.getInitServiceURI = getInitServiceURI;
50
50
  this.net = net;
51
51
  this.uri = undefined;
52
+ this.connectedState = new awaitable_state_1.AwaitableState();
52
53
  this.redirectedFrom = undefined;
53
54
  this.sessionId = undefined;
54
55
  this.loginProc = undefined;
55
56
  this.loginUrlPart = accessParams.login;
56
- if ((this.loginUrlPart.length > 0)
57
- && (this.loginUrlPart[this.loginUrlPart.length - 1] !== '/')) {
57
+ if ((this.loginUrlPart.length > 0) && !this.loginUrlPart.endsWith('/')) {
58
58
  this.loginUrlPart += '/';
59
59
  }
60
60
  this.logoutUrlEnd = accessParams.logout;
@@ -162,31 +162,42 @@ class ServiceUser {
162
162
  }
163
163
  }
164
164
  async callEnsuringLogin(func) {
165
- if (this.loginProc || !this.sessionId) {
166
- await this.login();
167
- return func();
168
- }
169
- else {
170
- // first attepmt
171
- const initSessionId = this.sessionId;
172
- const rep = await func();
173
- if (rep.status !== api.ERR_SC.needAuth) {
174
- return rep;
165
+ try {
166
+ let reply;
167
+ if (this.loginProc || !this.sessionId) {
168
+ await this.login();
169
+ reply = await func();
170
+ }
171
+ else {
172
+ // first attepmt
173
+ const initSessionId = this.sessionId;
174
+ const rep = await func();
175
+ if (rep.status !== api.ERR_SC.needAuth) {
176
+ return rep;
177
+ }
178
+ // if auth is needed, do login and a second attempt
179
+ if (this.sessionId === initSessionId) {
180
+ this.sessionId = undefined;
181
+ }
182
+ await this.login();
183
+ reply = await func();
175
184
  }
176
- // if auth is needed, do login and a second attempt
177
- if (this.sessionId === initSessionId) {
178
- this.sessionId = undefined;
185
+ this.connectedState.setState();
186
+ return reply;
187
+ }
188
+ catch (exc) {
189
+ if (exc.type === 'connect') {
190
+ this.net.reset();
191
+ this.connectedState.clearState();
179
192
  }
180
- await this.login();
181
- return func();
193
+ throw exc;
182
194
  }
183
195
  }
184
196
  prepCallOpts(opts, isWS) {
185
197
  opts.sessionId = this.sessionId;
186
198
  if (opts.appPath) {
187
199
  opts.url = (isWS ?
188
- `wss${this.serviceURI.substring(5)}${opts.appPath}` :
189
- `${this.serviceURI}${opts.appPath}`);
200
+ `wss${this.serviceURI.substring(5)}${opts.appPath}` : `${this.serviceURI}${opts.appPath}`);
190
201
  }
191
202
  else if (!opts.url) {
192
203
  throw new Error(`Missing both appPath and ready url in request options.`);
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- Copyright (C) 2020, 2022 3NSoft Inc.
3
+ Copyright (C) 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
@@ -20,6 +20,7 @@ exports.XAttrs = exports.CommonAttrs = void 0;
20
20
  const assert_1 = require("../../lib-common/assert");
21
21
  const buffer_utils_1 = require("../../lib-common/buffer-utils");
22
22
  const big_endian_1 = require("../../lib-common/big-endian");
23
+ const runtime_1 = require("../../lib-common/exceptions/runtime");
23
24
  class CommonAttrs {
24
25
  constructor(ctime, mtime) {
25
26
  this.ctime = ctime;
@@ -309,7 +310,8 @@ function parsingException(msg, cause) {
309
310
  return {
310
311
  runtimeException: true,
311
312
  type: 'attrs-parsing',
312
- cause, msg
313
+ cause, msg,
314
+ stack: (0, runtime_1.getStackHere)(1)
313
315
  };
314
316
  }
315
317
  Object.freeze(exports);
@@ -25,16 +25,16 @@ exports.makeUnknownTransactionExc = makeUnknownTransactionExc;
25
25
  exports.makeVersionMismatchExc = makeVersionMismatchExc;
26
26
  exports.makeStorageIsClosedExc = makeStorageIsClosedExc;
27
27
  exports.makeFSSyncException = makeFSSyncException;
28
+ const runtime_1 = require("../../lib-common/exceptions/runtime");
28
29
  function makeStorageException(fields) {
29
30
  const exc = {
30
31
  runtimeException: true,
31
- type: 'storage'
32
+ type: 'storage',
33
+ stack: (0, runtime_1.getStackHere)(1)
32
34
  };
33
35
  for (const [key, value] of Object.entries(fields)) {
34
36
  exc[key] = value;
35
37
  }
36
- const err = new Error(`runtime exception stack`);
37
- exc['stack'] = err.stack;
38
38
  return exc;
39
39
  }
40
40
  function makeObjNotFoundExc(objId, remoteStorage) {
@@ -74,7 +74,8 @@ function makeFSSyncException(path, fields) {
74
74
  const exc = {
75
75
  runtimeException: true,
76
76
  type: 'fs-sync',
77
- path
77
+ path,
78
+ stack: (0, runtime_1.getStackHere)(1)
78
79
  };
79
80
  for (const [key, value] of Object.entries(fields)) {
80
81
  exc[key] = value;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- Copyright (C) 2017, 2022 3NSoft Inc.
3
+ Copyright (C) 2017, 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
@@ -22,6 +22,7 @@ const buffer_utils_1 = require("../../lib-common/buffer-utils");
22
22
  const xsp_files_1 = require("xsp-files");
23
23
  const big_endian_1 = require("../../lib-common/big-endian");
24
24
  const assert_1 = require("../../lib-common/assert");
25
+ const runtime_1 = require("../../lib-common/exceptions/runtime");
25
26
  const ver1Serialization = new Uint8Array([1]);
26
27
  function parseFolderInfo(bytes) {
27
28
  if (!bytes) {
@@ -42,7 +43,8 @@ function parsingException(msg, cause) {
42
43
  runtimeException: true,
43
44
  type: 'folder-parsing',
44
45
  message: msg,
45
- cause
46
+ cause,
47
+ stack: (0, runtime_1.getStackHere)(1)
46
48
  };
47
49
  }
48
50
  var formatV1;
@@ -268,14 +268,11 @@ class NodeInFS {
268
268
  this.writeProc = new synced_1.SingleProc();
269
269
  }
270
270
  if (!awaitPrevChange && this.writeProc.isProcessing()) {
271
- throw (0, runtime_1.makeRuntimeException)('file', { path: this.name, fsEtityType: this.type }, { concurrentUpdate: true });
271
+ throw (0, runtime_1.makeRuntimeException)('file', { path: this.name, fsEtityType: this.type }, { concurrentUpdate: true }, true);
272
272
  }
273
273
  const res = await this.writeProc.startOrChain(async () => {
274
274
  if (this.isMarkedRemoved) {
275
- throw (0, runtime_1.makeRuntimeException)('file', {
276
- path: this.name, fsEtityType: this.type,
277
- message: `NodeInFS is marked removed`
278
- }, { notFound: true });
275
+ throw (0, runtime_1.makeRuntimeException)('file', { path: this.name, fsEtityType: this.type, message: `NodeInFS is marked removed` }, { notFound: true });
279
276
  }
280
277
  try {
281
278
  const res = await change();
@@ -1,40 +1,24 @@
1
1
  import * as fs from 'fs';
2
2
  import { Readable, Writable } from 'stream';
3
- export { Stats } from 'fs';
4
- export { FileException } from './exceptions/file';
5
- export declare function readFile(filename: string, options: {
6
- encoding: BufferEncoding;
7
- flag?: string;
8
- }): Promise<string>;
9
- export declare function readFile(filename: string, options?: {
10
- flag?: string;
11
- }): Promise<Buffer>;
12
- export declare function writeFile(path: string, data: any, options?: {
13
- encoding?: BufferEncoding;
14
- mode?: string;
15
- flag?: string;
16
- }): Promise<void>;
17
- export declare function appendFile(path: string, data: any, options?: {
18
- encoding?: BufferEncoding;
19
- mode?: string;
20
- flag?: string;
21
- }): Promise<void>;
22
- export declare function mkdir(path: string, options?: number | string | fs.MakeDirectoryOptions | null): Promise<void>;
23
- export declare function open(path: string, flags: string): Promise<number>;
24
- export declare function close(fd: number): Promise<void>;
25
- export declare function symlink(target: string, path: string, type?: 'dir' | 'file' | 'junction'): Promise<void>;
26
- export declare function readlink(path: string): Promise<string>;
27
- export declare function lstat(path: string): Promise<fs.Stats>;
28
- export declare function stat(path: string): Promise<fs.Stats>;
29
- export declare function fstat(fd: number): Promise<fs.Stats>;
30
- export declare function readdir(path: string): Promise<string[]>;
31
- export declare function rmdir(path: string): Promise<void>;
32
- export declare function unlink(path: string): Promise<void>;
33
- export declare function rename(oldPath: string, newPath: string): Promise<void>;
34
- export declare function truncate(path: string, size: number): Promise<void>;
35
- export declare function ftruncate(fd: number, size: number): Promise<void>;
36
- /**
37
- * @param fd is an open file descriptor
3
+ export type { Stats } from 'fs';
4
+ export type { FileException } from './exceptions/file';
5
+ export type FileHandle = fs.promises.FileHandle;
6
+ export declare const readFile: typeof fs.promises.readFile;
7
+ export declare const writeFile: typeof fs.promises.writeFile;
8
+ export declare const appendFile: typeof fs.promises.appendFile;
9
+ export declare const mkdir: typeof fs.promises.mkdir;
10
+ export declare const open: typeof fs.promises.open;
11
+ export declare const symlink: typeof fs.promises.symlink;
12
+ export declare const readlink: typeof fs.promises.readlink;
13
+ export declare const lstat: typeof fs.promises.lstat;
14
+ export declare const stat: typeof fs.promises.stat;
15
+ export declare const readdir: typeof fs.promises.readdir;
16
+ export declare const rmdir: typeof fs.promises.rmdir;
17
+ export declare const unlink: typeof fs.promises.unlink;
18
+ export declare const rename: typeof fs.promises.rename;
19
+ export declare const truncate: typeof fs.promises.truncate;
20
+ /**
21
+ * @param fh is an open file handle
38
22
  * @param pos is a position in the file, from which reading should start
39
23
  * @param buf is a buffer, into which bytes should be read from start to
40
24
  * the end, i.e. number of bytes that must be read is equal to the buffer's
@@ -44,14 +28,14 @@ export declare function ftruncate(fd: number, size: number): Promise<void>;
44
28
  * The promise fails, if an end of file is encountered before entire buffer is
45
29
  * filled up with bytes.
46
30
  */
47
- export declare function readToBuf(fd: number, pos: number, buf: Buffer): Promise<void>;
31
+ export declare function readToBuf(fh: FileHandle, pos: number, buf: Buffer): Promise<void>;
48
32
  /**
49
- * @param fd is an open file descriptor
33
+ * @param fh is an open file handle
50
34
  * @param pos is a position in the file, from which writing should start
51
35
  * @param buf is a buffer, from which all bytes should be written into the file.
52
36
  * @returns a promise, resolvable when all bytes were written to the file.
53
37
  */
54
- export declare function writeFromBuf(fd: number, pos: number, buf: Buffer): Promise<void>;
38
+ export declare function writeFromBuf(fh: FileHandle, pos: number, buf: Buffer): Promise<void>;
55
39
  /**
56
40
  * This will create a new file of a given size, and will fail, if a file
57
41
  * with a given path already exists.
@@ -59,10 +43,10 @@ export declare function writeFromBuf(fd: number, pos: number, buf: Buffer): Prom
59
43
  * @param fileSize
60
44
  * @param keepFileOpen
61
45
  * @returns a promise, resolvable, when a new empty file has been created.
62
- * When keep open flag was passed, live numeric file descriptor is returned,
46
+ * When keep open flag was passed, live file handle is returned,
63
47
  * else return value is undefined and should be ignored.
64
48
  */
65
- export declare function createEmptyFile(filePath: string, fileSize: number, keepFileOpen?: boolean): Promise<number | undefined>;
49
+ export declare function createEmptyFile(filePath: string, fileSize: number, keepFileOpen?: boolean): Promise<FileHandle | undefined>;
66
50
  /**
67
51
  * @param path
68
52
  * @return a promise, resolvable to true, if given path represents directory,
@@ -91,18 +75,18 @@ export declare function getFileSize(filePath: string): Promise<number>;
91
75
  */
92
76
  export declare function getFolderContentSize(folderPath: string): Promise<number>;
93
77
  /**
94
- * @param fd is an open file descriptor
78
+ * @param fh is an open file handle
95
79
  * @param pos is a position in the file, from which writing should start
96
80
  * @param buf is a buffer, from which all bytes should be written into the file.
97
81
  * @returns a promise, resolvable when all bytes were written to it.
98
82
  */
99
- export declare function write(fd: number, pos: number, buf: Buffer): Promise<void>;
83
+ export declare function write(fh: FileHandle, pos: number, buf: Buffer): Promise<void>;
100
84
  /**
101
- * @param fd is an open file descriptor in append mode.
85
+ * @param fh is an open file handle in append mode.
102
86
  * @param buf is a buffer, from which all bytes should be written into the file.
103
87
  * @returns a promise, resolvable when all bytes were written to it.
104
88
  */
105
- export declare function append(fd: number, buf: Buffer): Promise<void>;
89
+ export declare function append(fh: FileHandle, buf: Buffer): Promise<void>;
106
90
  /**
107
91
  * @param filePath
108
92
  * @param pos is a position in the file, from which writting should start
@@ -115,7 +99,7 @@ export declare function append(fd: number, buf: Buffer): Promise<void>;
115
99
  */
116
100
  export declare function streamToExistingFile(filePath: string, pos: number, len: number, src: Readable, bufSize: number): Promise<void>;
117
101
  /**
118
- * @param fd is an open file descriptor
102
+ * @param fh is an open file handle
119
103
  * @param pos is a position in the file, from which reading should start
120
104
  * @param buf is a buffer, into which bytes should be read from start to
121
105
  * the end, i.e. number of bytes that must be read is equal to the buffer's
@@ -125,7 +109,7 @@ export declare function streamToExistingFile(filePath: string, pos: number, len:
125
109
  * The promise fails, if an end of file is encountered before entire buffer is
126
110
  * filled up with bytes.
127
111
  */
128
- export declare function read(fd: number, pos: number, buf: Buffer): Promise<void>;
112
+ export declare function read(fh: FileHandle, pos: number, buf: Buffer): Promise<void>;
129
113
  /**
130
114
  * @param folder is a path to a folder, which should be recursively removed,
131
115
  * together with all files.