core-3nweb-client-lib 0.48.0 → 0.48.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.
@@ -122,7 +122,7 @@ Object.freeze(MsgOnDisk);
122
122
  async function readJSON(msgFolderPath, fname, msgId) {
123
123
  const path = (0, path_1.join)(msgFolderPath, fname);
124
124
  try {
125
- return JSON.parse(await fs.readFile(path, { flag: 'r', encoding: 'utf8' }));
125
+ return JSON.parse(await fs.readFile(path, { encoding: 'utf8' }));
126
126
  }
127
127
  catch (err) {
128
128
  throw (0, error_1.errWithCause)(err, `Can't read file ${fname} of message ${msgId}`);
@@ -49,6 +49,7 @@ class PublishedIntroKey {
49
49
  return pk;
50
50
  }
51
51
  startExpiryCheckProcess(calledInInit = false) {
52
+ var _a, _b;
52
53
  if (!calledInInit && !this.periodicExpiryCheck) {
53
54
  return;
54
55
  }
@@ -61,7 +62,8 @@ class PublishedIntroKey {
61
62
  }
62
63
  }
63
64
  if (calledInInit) {
64
- this.periodicExpiryCheck = setTimeout(() => this.startExpiryCheckProcess(), UPDATE_BEFORE_EXPIRY * 1000 / 20).unref();
65
+ this.periodicExpiryCheck = setTimeout(() => this.startExpiryCheckProcess(), UPDATE_BEFORE_EXPIRY * 1000 / 20);
66
+ (_b = (_a = this.periodicExpiryCheck).unref) === null || _b === void 0 ? void 0 : _b.call(_a);
65
67
  }
66
68
  }
67
69
  async close() {
@@ -1,10 +1,6 @@
1
- import type { Abortable } from 'events';
2
- import type { BufferEncodingOption, promises as fsFns, Mode, ObjectEncodingOptions, OpenMode, RmDirOptions, StatOptions, Stats } from 'fs';
3
- import { FlagAndOpenMode } from 'fs/promises';
4
- import type Stream = require('stream');
1
+ import type { BufferEncodingOption, Mode, ObjectEncodingOptions, OpenMode, RmDirOptions, StatOptions, Stats } from 'fs';
5
2
  export type { Stats } from 'fs';
6
3
  export type { FileException } from '../lib-common/exceptions/file';
7
- export type FileHandle = fsFns.FileHandle;
8
4
  /**
9
5
  * This should be injected at globalThis.platform.device_fs
10
6
  */
@@ -32,28 +28,24 @@ export interface PlatformDeviceFS {
32
28
  */
33
29
  copyFile(src: string, dst: string, overwrite?: boolean, dstMode?: string): Promise<void>;
34
30
  }
35
- declare function readFile(path: string, options?: ({
36
- encoding?: null | undefined;
37
- flag?: OpenMode | undefined;
38
- } & Abortable) | null): Promise<Buffer>;
39
- declare function readFile(path: string, options: ({
31
+ declare function readFile(path: string, options?: {
32
+ encoding?: null;
33
+ } | null): Promise<Buffer>;
34
+ declare function readFile(path: string, options: {
40
35
  encoding: BufferEncoding;
41
- flag?: OpenMode | undefined;
42
- } & Abortable) | BufferEncoding): Promise<string>;
43
- declare function readFile(path: string, options?: (ObjectEncodingOptions & Abortable & {
44
- flag?: OpenMode | undefined;
45
- }) | BufferEncoding | null): Promise<string | Buffer>;
46
- declare function writeFile(file: string, data: string | NodeJS.ArrayBufferView | Iterable<string | NodeJS.ArrayBufferView> | AsyncIterable<string | NodeJS.ArrayBufferView> | Stream, options?: (ObjectEncodingOptions & {
47
- mode?: Mode | undefined;
48
- flag?: OpenMode | undefined;
49
- flush?: boolean | undefined;
50
- } & Abortable) | BufferEncoding | null): Promise<void>;
51
- declare function appendFile(path: string, data: string | Uint8Array, options?: (ObjectEncodingOptions & FlagAndOpenMode & {
36
+ } | BufferEncoding): Promise<string>;
37
+ declare function readFile(path: string, options?: ObjectEncodingOptions | BufferEncoding | null): Promise<string | Buffer>;
38
+ declare function writeFile(file: string, data: string | Uint8Array, options?: (ObjectEncodingOptions & {
39
+ mode?: Mode;
40
+ flag?: OpenMode;
41
+ flush?: boolean;
42
+ }) | BufferEncoding | null): Promise<void>;
43
+ declare function appendFile(path: string, data: string | Uint8Array, options?: (ObjectEncodingOptions & {
52
44
  flush?: boolean | undefined;
53
45
  }) | BufferEncoding | null): Promise<void>;
54
46
  declare function mkdir(path: string, options?: {
55
47
  recursive?: boolean;
56
- }): Promise<string | undefined>;
48
+ }): Promise<unknown>;
57
49
  declare function open(path: string, flags?: string | number, mode?: Mode): Promise<FileHandle>;
58
50
  declare function symlink(target: string, path: string, type?: string | null): Promise<void>;
59
51
  declare function readlink(path: string, options?: ObjectEncodingOptions | BufferEncoding | null): Promise<string>;
@@ -66,3 +58,16 @@ declare function rmdir(path: string, options?: RmDirOptions): Promise<void>;
66
58
  declare function unlink(path: string): Promise<void>;
67
59
  declare function rename(oldPath: string, newPath: string): Promise<void>;
68
60
  declare function truncate(path: string, len?: number): Promise<void>;
61
+ export interface FileHandle {
62
+ readonly fd: number;
63
+ stat(): Promise<Stats>;
64
+ close(): Promise<void>;
65
+ read(buffer: Uint8Array, offset?: number, length?: number, position?: number): Promise<{
66
+ bytesRead: number;
67
+ }>;
68
+ write(buffer: Uint8Array, offset?: number, length?: number, position?: number): Promise<{
69
+ bytesWritten: number;
70
+ }>;
71
+ sync(): Promise<void>;
72
+ truncate(len?: number): Promise<void>;
73
+ }
@@ -229,10 +229,11 @@ class RotationsProc {
229
229
  return (0, path_1.join)(this.generationsFolder, `${backetIndex}`);
230
230
  }
231
231
  setNextCacheRotation(secs) {
232
- setTimeout(async () => {
232
+ var _a, _b;
233
+ (_b = (_a = setTimeout(async () => {
233
234
  await this.rotate();
234
235
  this.setNextCacheRotation(this.generations[0].period);
235
- }, secs * 1000).unref();
236
+ }, secs * 1000)).unref) === null || _b === void 0 ? void 0 : _b.call(_a);
236
237
  }
237
238
  async rotate() {
238
239
  const now = Math.floor(Date.now() / 1000);
@@ -5,31 +5,27 @@ export type { FileHandle, FileException, Stats } from '../injected-globals/platf
5
5
  * fs functions follow node's type, and are injected via global object to allow injection in
6
6
  * non-node environments, like Android or browser.
7
7
  */
8
- export declare const appendFile: (path: string, data: string | Uint8Array, options?: (import("fs").ObjectEncodingOptions & import("fs/promises").FlagAndOpenMode & {
8
+ export declare const appendFile: (path: string, data: string | Uint8Array, options?: (import("fs").ObjectEncodingOptions & {
9
9
  flush?: boolean | undefined;
10
10
  }) | BufferEncoding | null) => Promise<void>, lstat: (path: string, opts?: import("fs").StatOptions) => Promise<import("fs").Stats>, mkdir: (path: string, options?: {
11
11
  recursive?: boolean;
12
- }) => Promise<string | undefined>, open: (path: string, flags?: string | number, mode?: import("fs").Mode) => Promise<FileHandle>, readFile: {
13
- (path: string, options?: ({
14
- encoding?: null | undefined;
15
- flag?: import("fs").OpenMode | undefined;
16
- } & import("events").Abortable) | null): Promise<Buffer>;
17
- (path: string, options: ({
12
+ }) => Promise<unknown>, open: (path: string, flags?: string | number, mode?: import("fs").Mode) => Promise<FileHandle>, readFile: {
13
+ (path: string, options?: {
14
+ encoding?: null;
15
+ } | null): Promise<Buffer>;
16
+ (path: string, options: {
18
17
  encoding: BufferEncoding;
19
- flag?: import("fs").OpenMode | undefined;
20
- } & import("events").Abortable) | BufferEncoding): Promise<string>;
21
- (path: string, options?: (import("fs").ObjectEncodingOptions & import("events").Abortable & {
22
- flag?: import("fs").OpenMode | undefined;
23
- }) | BufferEncoding | null): Promise<string | Buffer>;
18
+ } | BufferEncoding): Promise<string>;
19
+ (path: string, options?: import("fs").ObjectEncodingOptions | BufferEncoding | null): Promise<string | Buffer>;
24
20
  }, readdir: (path: string) => Promise<string[]>, readlink: {
25
21
  (path: string, options?: import("fs").ObjectEncodingOptions | BufferEncoding | null): Promise<string>;
26
22
  (path: string, options: import("fs").BufferEncodingOption): Promise<Buffer>;
27
23
  (path: string, options?: import("fs").ObjectEncodingOptions | string | null): Promise<string | Buffer>;
28
- }, rename: (oldPath: string, newPath: string) => Promise<void>, rmdir: (path: string, options?: import("fs").RmDirOptions) => Promise<void>, stat: (path: string, opts?: import("fs").StatOptions) => Promise<import("fs").Stats>, symlink: (target: string, path: string, type?: string | null) => Promise<void>, truncate: (path: string, len?: number) => Promise<void>, unlink: (path: string) => Promise<void>, writeFile: (file: string, data: string | NodeJS.ArrayBufferView | Iterable<string | NodeJS.ArrayBufferView> | AsyncIterable<string | NodeJS.ArrayBufferView> | import("stream"), options?: (import("fs").ObjectEncodingOptions & {
29
- mode?: import("fs").Mode | undefined;
30
- flag?: import("fs").OpenMode | undefined;
31
- flush?: boolean | undefined;
32
- } & import("events").Abortable) | BufferEncoding | null) => Promise<void>, copyFile: (src: string, dst: string, overwrite?: boolean, dstMode?: string) => Promise<void>;
24
+ }, rename: (oldPath: string, newPath: string) => Promise<void>, rmdir: (path: string, options?: import("fs").RmDirOptions) => Promise<void>, stat: (path: string, opts?: import("fs").StatOptions) => Promise<import("fs").Stats>, symlink: (target: string, path: string, type?: string | null) => Promise<void>, truncate: (path: string, len?: number) => Promise<void>, unlink: (path: string) => Promise<void>, writeFile: (file: string, data: string | Uint8Array, options?: (import("fs").ObjectEncodingOptions & {
25
+ mode?: import("fs").Mode;
26
+ flag?: import("fs").OpenMode;
27
+ flush?: boolean;
28
+ }) | BufferEncoding | null) => Promise<void>, copyFile: (src: string, dst: string, overwrite?: boolean, dstMode?: string) => Promise<void>;
33
29
  /**
34
30
  * @param fh is an open file handle
35
31
  * @param pos is a position in the file, from which reading should start
@@ -84,12 +80,6 @@ export declare function getFolderContentSize(folderPath: string): Promise<number
84
80
  * @returns a promise, resolvable when all bytes were written to it.
85
81
  */
86
82
  export declare function write(fh: FileHandle, pos: number, buf: Buffer): Promise<void>;
87
- /**
88
- * @param fh is an open file handle in append mode.
89
- * @param buf is a buffer, from which all bytes should be written into the file.
90
- * @returns a promise, resolvable when all bytes were written to it.
91
- */
92
- export declare function append(fh: FileHandle, buf: Buffer): Promise<void>;
93
83
  /**
94
84
  * @param filePath
95
85
  * @param pos is a position in the file, from which writting should start
@@ -26,7 +26,6 @@ exports.existsFolder = existsFolder;
26
26
  exports.getFileSize = getFileSize;
27
27
  exports.getFolderContentSize = getFolderContentSize;
28
28
  exports.write = write;
29
- exports.append = append;
30
29
  exports.streamToExistingFile = streamToExistingFile;
31
30
  exports.read = read;
32
31
  exports.rmDirWithContent = rmDirWithContent;
@@ -191,18 +190,6 @@ async function write(fh, pos, buf) {
191
190
  }
192
191
  await fh.sync();
193
192
  }
194
- /**
195
- * @param fh is an open file handle in append mode.
196
- * @param buf is a buffer, from which all bytes should be written into the file.
197
- * @returns a promise, resolvable when all bytes were written to it.
198
- */
199
- async function append(fh, buf) {
200
- let bytesWritten = 0;
201
- while (bytesWritten < buf.length) {
202
- const { bytesWritten: bNum } = await fh.write(buf, bytesWritten, buf.length - bytesWritten);
203
- bytesWritten += bNum;
204
- }
205
- }
206
193
  /**
207
194
  * @param filePath is a path to an existing file
208
195
  * @param pos is a position in the file, from which writing should start
@@ -86,6 +86,7 @@ class ObjVersionFile {
86
86
  await fs.writeFromBuf(fh, ofs, layoutBytes);
87
87
  await recordLayoutOffsetInV1(fh, ofs);
88
88
  await fh.truncate(ofs + layoutBytes.length);
89
+ await fh.sync();
89
90
  }
90
91
  withRWFile(action) {
91
92
  return this.writeProc.startOrChain(async () => {
@@ -188,7 +189,7 @@ class ObjVersionFile {
188
189
  }
189
190
  await this.withROFile(async (fd) => {
190
191
  const src = (0, fs_1.createReadStream)('', {
191
- fd,
192
+ fd: fd,
192
193
  autoClose: false,
193
194
  start: chunkInfo.fileOfs,
194
195
  end: chunkInfo.fileOfs + chunkInfo.len - 1
@@ -221,7 +222,7 @@ class ObjVersionFile {
221
222
  if ((chunk.type === 'new-on-disk')
222
223
  || (chunk.type === 'base-on-disk')) {
223
224
  const src = (0, fs_1.createReadStream)('', {
224
- fd,
225
+ fd: fd,
225
226
  autoClose: false,
226
227
  start: chunk.fileOfs,
227
228
  end: chunk.fileOfs + chunk.len - 1
@@ -19,7 +19,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
19
19
  exports.sleep = sleep;
20
20
  function sleep(millis) {
21
21
  return new Promise((resolve) => {
22
- setTimeout(resolve, millis).unref();
22
+ var _a, _b;
23
+ (_b = (_a = setTimeout(resolve, millis)).unref) === null || _b === void 0 ? void 0 : _b.call(_a);
23
24
  });
24
25
  }
25
26
  Object.freeze(exports);
@@ -19,10 +19,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
19
19
  exports.TimeWindowCache = void 0;
20
20
  class TimeWindowCache {
21
21
  constructor(periodMillis) {
22
+ var _a, _b;
22
23
  this.filling = new Map();
23
24
  this.waiting = new Map();
24
- this.interval = setInterval(() => this.dropAndRotate(), periodMillis)
25
- .unref();
25
+ this.interval = setInterval(() => this.dropAndRotate(), periodMillis);
26
+ (_b = (_a = this.interval).unref) === null || _b === void 0 ? void 0 : _b.call(_a);
26
27
  Object.seal(this);
27
28
  }
28
29
  dropAndRotate() {
@@ -64,11 +64,12 @@ Object.freeze(WeakCache.prototype);
64
64
  Object.freeze(WeakCache);
65
65
  class WeakCacheWithMinLifeTime {
66
66
  constructor(millis) {
67
+ var _a, _b;
67
68
  this.wCache = new WeakCache();
68
69
  this.filling = new Map();
69
70
  this.waiting = new Map();
70
71
  this.interval = setInterval(() => { this.dropAndRotate(); }, millis);
71
- this.interval.unref();
72
+ (_b = (_a = this.interval).unref) === null || _b === void 0 ? void 0 : _b.call(_a);
72
73
  Object.seal(this);
73
74
  }
74
75
  dropAndRotate() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "core-3nweb-client-lib",
3
- "version": "0.48.0",
3
+ "version": "0.48.2",
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",