core-3nweb-client-lib 0.48.1 → 0.48.3

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.
@@ -22,7 +22,6 @@ const id_to_email_map_1 = require("./id-to-email-map");
22
22
  const common_1 = require("./common");
23
23
  const async_cryptor_wrap_1 = require("../../lib-common/async-cryptor-wrap");
24
24
  const xsp_files_1 = require("xsp-files");
25
- const random = require("../../lib-common-on-node/random-node");
26
25
  const buffer_utils_1 = require("../../lib-common/buffer-utils");
27
26
  const canonical_address_1 = require("../../lib-common/canonical-address");
28
27
  const common_2 = require("../asmail/delivery/common");
@@ -119,7 +118,7 @@ class Keyrings {
119
118
  }
120
119
  const { msgMasterKey, currentPair, msgCount } = await ck.getSendingPair(introPKeyFromServer);
121
120
  // prepare message encryptor
122
- const nextNonce = await random.bytes(xsp_files_1.NONCE_LENGTH);
121
+ const nextNonce = await this.random(xsp_files_1.NONCE_LENGTH);
123
122
  const encryptor = (0, async_cryptor_wrap_1.makeEncryptor)(this.cryptor, this.workLabel, msgMasterKey, nextNonce);
124
123
  msgMasterKey.fill(0);
125
124
  return { encryptor, currentPair, msgCount };
@@ -19,7 +19,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
19
19
  exports.LocalStorage = void 0;
20
20
  const common_1 = require("../../../lib-client/xsp-fs/common");
21
21
  const exceptions_1 = require("../../../lib-client/xsp-fs/exceptions");
22
- const random_node_1 = require("../../../lib-common-on-node/random-node");
23
22
  const ecma_nacl_1 = require("ecma-nacl");
24
23
  const buffer_utils_1 = require("../../../lib-common/buffer-utils");
25
24
  const obj_files_1 = require("./obj-files");
@@ -75,7 +74,7 @@ class LocalStorage {
75
74
  return obj.localStatus();
76
75
  }
77
76
  async generateNewObjId() {
78
- const nonce = await (0, random_node_1.bytes)(ecma_nacl_1.secret_box.NONCE_LENGTH);
77
+ const nonce = await this.random(ecma_nacl_1.secret_box.NONCE_LENGTH);
79
78
  const id = buffer_utils_1.base64urlSafe.pack(nonce);
80
79
  if (this.nodes.reserveId(id)) {
81
80
  return id;
@@ -21,7 +21,6 @@ const common_1 = require("../../../lib-client/xsp-fs/common");
21
21
  const exceptions_1 = require("../../../lib-client/xsp-fs/exceptions");
22
22
  const storage_owner_1 = require("../../../lib-client/3nstorage/storage-owner");
23
23
  const obj_files_1 = require("./obj-files");
24
- const random_node_1 = require("../../../lib-common-on-node/random-node");
25
24
  const buffer_utils_1 = require("../../../lib-common/buffer-utils");
26
25
  const xsp_files_1 = require("xsp-files");
27
26
  const remote_events_1 = require("./remote-events");
@@ -160,7 +159,7 @@ class SyncedStore {
160
159
  return this.remoteStorage.getKeyDerivParams();
161
160
  }
162
161
  async generateNewObjId() {
163
- const nonce = await (0, random_node_1.bytes)(xsp_files_1.NONCE_LENGTH);
162
+ const nonce = await this.random(xsp_files_1.NONCE_LENGTH);
164
163
  const id = buffer_utils_1.base64urlSafe.pack(nonce);
165
164
  if (this.nodes.reserveId(id)) {
166
165
  return id;
@@ -1,7 +1,6 @@
1
- import type { BufferEncodingOption, promises as fsFns, Mode, ObjectEncodingOptions, OpenMode, RmDirOptions, StatOptions, Stats } from 'fs';
1
+ import type { BufferEncodingOption, Mode, ObjectEncodingOptions, RmDirOptions, Stats } from 'fs';
2
2
  export type { Stats } from 'fs';
3
3
  export type { FileException } from '../lib-common/exceptions/file';
4
- export type FileHandle = fsFns.FileHandle;
5
4
  /**
6
5
  * This should be injected at globalThis.platform.device_fs
7
6
  */
@@ -38,7 +37,7 @@ declare function readFile(path: string, options: {
38
37
  declare function readFile(path: string, options?: ObjectEncodingOptions | BufferEncoding | null): Promise<string | Buffer>;
39
38
  declare function writeFile(file: string, data: string | Uint8Array, options?: (ObjectEncodingOptions & {
40
39
  mode?: Mode;
41
- flag?: OpenMode;
40
+ flag?: string;
42
41
  flush?: boolean;
43
42
  }) | BufferEncoding | null): Promise<void>;
44
43
  declare function appendFile(path: string, data: string | Uint8Array, options?: (ObjectEncodingOptions & {
@@ -47,15 +46,28 @@ declare function appendFile(path: string, data: string | Uint8Array, options?: (
47
46
  declare function mkdir(path: string, options?: {
48
47
  recursive?: boolean;
49
48
  }): Promise<unknown>;
50
- declare function open(path: string, flags?: string | number, mode?: Mode): Promise<FileHandle>;
49
+ declare function open(path: string, flags?: string, mode?: Mode): Promise<FileHandle>;
51
50
  declare function symlink(target: string, path: string, type?: string | null): Promise<void>;
52
51
  declare function readlink(path: string, options?: ObjectEncodingOptions | BufferEncoding | null): Promise<string>;
53
52
  declare function readlink(path: string, options: BufferEncodingOption): Promise<Buffer>;
54
53
  declare function readlink(path: string, options?: ObjectEncodingOptions | string | null): Promise<string | Buffer>;
55
- declare function lstat(path: string, opts?: StatOptions): Promise<Stats>;
56
- declare function stat(path: string, opts?: StatOptions): Promise<Stats>;
54
+ declare function lstat(path: string): Promise<Stats>;
55
+ declare function stat(path: string): Promise<Stats>;
57
56
  declare function readdir(path: string): Promise<string[]>;
58
57
  declare function rmdir(path: string, options?: RmDirOptions): Promise<void>;
59
58
  declare function unlink(path: string): Promise<void>;
60
59
  declare function rename(oldPath: string, newPath: string): Promise<void>;
61
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
+ }
@@ -7,9 +7,9 @@ export type { FileHandle, FileException, Stats } from '../injected-globals/platf
7
7
  */
8
8
  export declare const appendFile: (path: string, data: string | Uint8Array, options?: (import("fs").ObjectEncodingOptions & {
9
9
  flush?: boolean | undefined;
10
- }) | BufferEncoding | null) => Promise<void>, lstat: (path: string, opts?: import("fs").StatOptions) => Promise<import("fs").Stats>, mkdir: (path: string, options?: {
10
+ }) | BufferEncoding | null) => Promise<void>, lstat: (path: string) => Promise<import("fs").Stats>, mkdir: (path: string, options?: {
11
11
  recursive?: boolean;
12
- }) => Promise<unknown>, open: (path: string, flags?: string | number, mode?: import("fs").Mode) => Promise<FileHandle>, readFile: {
12
+ }) => Promise<unknown>, open: (path: string, flags?: string, mode?: import("fs").Mode) => Promise<FileHandle>, readFile: {
13
13
  (path: string, options?: {
14
14
  encoding?: null;
15
15
  } | null): Promise<Buffer>;
@@ -21,9 +21,9 @@ export declare const appendFile: (path: string, data: string | Uint8Array, optio
21
21
  (path: string, options?: import("fs").ObjectEncodingOptions | BufferEncoding | null): Promise<string>;
22
22
  (path: string, options: import("fs").BufferEncodingOption): Promise<Buffer>;
23
23
  (path: string, options?: import("fs").ObjectEncodingOptions | string | null): Promise<string | Buffer>;
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 & {
24
+ }, rename: (oldPath: string, newPath: string) => Promise<void>, rmdir: (path: string, options?: import("fs").RmDirOptions) => Promise<void>, stat: (path: string) => 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
25
  mode?: import("fs").Mode;
26
- flag?: import("fs").OpenMode;
26
+ flag?: string;
27
27
  flush?: boolean;
28
28
  }) | BufferEncoding | null) => Promise<void>, copyFile: (src: string, dst: string, overwrite?: boolean, dstMode?: string) => Promise<void>;
29
29
  /**
@@ -80,12 +80,6 @@ export declare function getFolderContentSize(folderPath: string): Promise<number
80
80
  * @returns a promise, resolvable when all bytes were written to it.
81
81
  */
82
82
  export declare function write(fh: FileHandle, pos: number, buf: Buffer): Promise<void>;
83
- /**
84
- * @param fh is an open file handle in append mode.
85
- * @param buf is a buffer, from which all bytes should be written into the file.
86
- * @returns a promise, resolvable when all bytes were written to it.
87
- */
88
- export declare function append(fh: FileHandle, buf: Buffer): Promise<void>;
89
83
  /**
90
84
  * @param filePath
91
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "core-3nweb-client-lib",
3
- "version": "0.48.1",
3
+ "version": "0.48.3",
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",