core-3nweb-client-lib 0.21.0 → 0.24.0
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.
- package/build/api-defs/common-caps.d.ts +6 -9
- package/build/api-defs/files.d.ts +8 -7
- package/build/core/asmail/inbox/attachments/fs.d.ts +2 -2
- package/build/core/asmail/inbox/attachments/fs.js +3 -2
- package/build/core/asmail/msg/common.d.ts +2 -2
- package/build/core/asmail/msg/common.js +3 -2
- package/build/core/asmail/msg/opener.d.ts +2 -2
- package/build/core/asmail/msg/opener.js +3 -2
- package/build/core/asmail/msg/packer.d.ts +2 -2
- package/build/core/asmail/msg/packer.js +7 -6
- package/build/core/index.d.ts +1 -1
- package/build/core/index.js +1 -1
- package/build/core/storage/index.js +2 -2
- package/build/core/storage/local/obj-files.js +8 -5
- package/build/core/storage/local/obj-status.js +4 -3
- package/build/core/storage/synced/obj-status.js +4 -3
- package/build/ipc-via-protobuf/bytes.d.ts +4 -4
- package/build/ipc-via-protobuf/bytes.js +1 -1
- package/build/ipc-via-protobuf/connector-clients-side.d.ts +2 -2
- package/build/ipc-via-protobuf/connector-services-side.d.ts +3 -3
- package/build/ipc-via-protobuf/connector-services-side.js +0 -1
- package/build/ipc-via-protobuf/connector.d.ts +6 -7
- package/build/ipc-via-protobuf/connector.js +1 -16
- package/build/ipc-via-protobuf/file.d.ts +7 -3
- package/build/ipc-via-protobuf/file.js +17 -15
- package/build/ipc-via-protobuf/fs.d.ts +2 -2
- package/build/ipc-via-protobuf/fs.js +1 -1
- package/build/ipc-via-protobuf/protobuf-msg.d.ts +3 -4
- package/build/lib-client/3nstorage/xsp-fs/attrs.d.ts +28 -0
- package/build/lib-client/3nstorage/xsp-fs/attrs.js +337 -0
- package/build/lib-client/3nstorage/xsp-fs/common.d.ts +1 -1
- package/build/lib-client/3nstorage/xsp-fs/common.js +3 -2
- package/build/lib-client/3nstorage/xsp-fs/file-node.d.ts +31 -18
- package/build/lib-client/3nstorage/xsp-fs/file-node.js +130 -118
- package/build/lib-client/3nstorage/xsp-fs/file.d.ts +0 -1
- package/build/lib-client/3nstorage/xsp-fs/file.js +14 -49
- package/build/lib-client/3nstorage/xsp-fs/folder-node-serialization.d.ts +1 -1
- package/build/lib-client/3nstorage/xsp-fs/folder-node-serialization.js +95 -91
- package/build/lib-client/3nstorage/xsp-fs/folder-node.d.ts +19 -24
- package/build/lib-client/3nstorage/xsp-fs/folder-node.js +133 -190
- package/build/lib-client/3nstorage/xsp-fs/fs.d.ts +3 -4
- package/build/lib-client/3nstorage/xsp-fs/fs.js +18 -21
- package/build/lib-client/3nstorage/xsp-fs/link-node.d.ts +13 -8
- package/build/lib-client/3nstorage/xsp-fs/link-node.js +46 -38
- package/build/lib-client/3nstorage/xsp-fs/node-in-fs.d.ts +17 -35
- package/build/lib-client/3nstorage/xsp-fs/node-in-fs.js +34 -127
- package/build/lib-client/3nstorage/xsp-fs/node-persistence.d.ts +57 -0
- package/build/lib-client/3nstorage/xsp-fs/node-persistence.js +182 -0
- package/build/lib-client/3nstorage/xsp-fs/xsp-payload-v1.d.ts +3 -0
- package/build/lib-client/3nstorage/xsp-fs/xsp-payload-v1.js +87 -0
- package/build/lib-client/3nstorage/xsp-fs/xsp-payload-v2.d.ts +6 -0
- package/build/lib-client/3nstorage/xsp-fs/xsp-payload-v2.js +1022 -0
- package/build/lib-client/cryptor/cryptor-wasm.js +1 -1
- package/build/lib-client/cryptor/cryptor.wasm +0 -0
- package/build/lib-client/local-files/device-fs.js +7 -3
- package/build/lib-client/objs-on-disk/file-writing-proc.js +3 -2
- package/build/lib-client/objs-on-disk/obj-on-disk.js +8 -7
- package/build/lib-common/big-endian.d.ts +0 -24
- package/build/lib-common/big-endian.js +16 -78
- package/build/lib-common/exceptions/file.js +6 -2
- package/build/lib-common/obj-streaming/sink-utils.d.ts +0 -4
- package/build/lib-common/obj-streaming/sink-utils.js +4 -70
- package/build/lib-common/objs-on-disk/file-layout.js +2 -1
- package/build/lib-common/objs-on-disk/obj-file.js +2 -2
- package/build/lib-common/objs-on-disk/utils.js +2 -1
- package/build/lib-common/objs-on-disk/v1-obj-file-format.js +2 -1
- package/package.json +2 -2
- package/build/lib-client/files/file-attrs.d.ts +0 -76
- package/build/lib-client/files/file-attrs.js +0 -549
- package/build/lib-client/files/file-layout.d.ts +0 -56
- package/build/lib-client/files/file-layout.js +0 -456
- package/build/lib-client/files/file-sink.d.ts +0 -33
- package/build/lib-client/files/file-sink.js +0 -173
- package/build/lib-client/files/file-source.d.ts +0 -19
- package/build/lib-client/files/file-source.js +0 -115
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Copyright (C) 2017 3NSoft Inc.
|
|
3
|
+
Copyright (C) 2017, 2022 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
|
|
@@ -13,113 +13,117 @@
|
|
|
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
|
-
exports.
|
|
19
|
-
/**
|
|
20
|
-
* Everything in this module is assumed to be inside of a file system
|
|
21
|
-
* reliance set.
|
|
22
|
-
*/
|
|
19
|
+
exports.serializeFolderInfo = exports.parseFolderInfo = void 0;
|
|
23
20
|
const buffer_utils_1 = require("../../../lib-common/buffer-utils");
|
|
24
21
|
const xsp_files_1 = require("xsp-files");
|
|
25
|
-
const
|
|
22
|
+
const big_endian_1 = require("../../../lib-common/big-endian");
|
|
23
|
+
const assert_1 = require("../../../lib-common/assert");
|
|
26
24
|
const ver1Serialization = new Uint8Array([1]);
|
|
27
|
-
function
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
.map(serializeNodeInfoV1)
|
|
31
|
-
.forEach(nodeBytes => bytes.push(...nodeBytes));
|
|
32
|
-
return bytes;
|
|
33
|
-
}
|
|
34
|
-
function serializeNodeInfoV1(nodeInfo) {
|
|
35
|
-
const bytes = [nodeInfo.key];
|
|
36
|
-
const json = {
|
|
37
|
-
t: (nodeInfo.isFolder ? 1 : (nodeInfo.isFile ? 2 : 3)),
|
|
38
|
-
n: nodeInfo.name,
|
|
39
|
-
o: nodeInfo.objId
|
|
40
|
-
};
|
|
41
|
-
const jsonBytes = buffer_utils_1.utf8.pack(JSON.stringify(json));
|
|
42
|
-
bytes.push(numberToBytes(jsonBytes.length));
|
|
43
|
-
bytes.push(jsonBytes);
|
|
44
|
-
return bytes;
|
|
45
|
-
}
|
|
46
|
-
function load_bigendian(arr) {
|
|
47
|
-
return (arr[3] | arr[2] << 8) | (arr[1] << 16) | (arr[0] << 24);
|
|
48
|
-
}
|
|
49
|
-
function store_bigendian(arr, x) {
|
|
50
|
-
if (x > 0xffffffff) {
|
|
51
|
-
throw new Error(`Number ${x} is bigger than expected unsigned 32 bit integer`);
|
|
25
|
+
function parseFolderInfo(bytes) {
|
|
26
|
+
if (!bytes) {
|
|
27
|
+
throw parsingException(`Can't parse folder from no bytes`);
|
|
52
28
|
}
|
|
53
|
-
arr[3] = x;
|
|
54
|
-
arr[2] = x >>> 8;
|
|
55
|
-
arr[1] = x >>> 16;
|
|
56
|
-
arr[0] = x >>> 24;
|
|
57
|
-
}
|
|
58
|
-
function numberToBytes(x) {
|
|
59
|
-
const arr = new Uint8Array(4);
|
|
60
|
-
store_bigendian(arr, x);
|
|
61
|
-
return arr;
|
|
62
|
-
}
|
|
63
|
-
function serializeFolderInfo(folderInfo) {
|
|
64
|
-
return serializeFolderInfoV1(folderInfo);
|
|
65
|
-
}
|
|
66
|
-
exports.serializeFolderInfo = serializeFolderInfo;
|
|
67
|
-
function deserializeFolderInfo(bytes) {
|
|
68
29
|
if (bytes[0] === ver1Serialization[0]) {
|
|
69
|
-
return
|
|
30
|
+
return formatV1.parse(bytes.subarray(1));
|
|
70
31
|
}
|
|
71
32
|
else {
|
|
72
|
-
throw
|
|
33
|
+
throw parsingException(`Cannot recognize folder's serialization version`);
|
|
73
34
|
}
|
|
74
35
|
}
|
|
75
|
-
exports.
|
|
76
|
-
function
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
36
|
+
exports.parseFolderInfo = parseFolderInfo;
|
|
37
|
+
function serializeFolderInfo(folderInfo) {
|
|
38
|
+
return formatV1.pack(folderInfo);
|
|
39
|
+
}
|
|
40
|
+
exports.serializeFolderInfo = serializeFolderInfo;
|
|
41
|
+
function parsingException(msg, cause) {
|
|
42
|
+
return {
|
|
43
|
+
runtimeException: true,
|
|
44
|
+
type: 'folder-parsing',
|
|
45
|
+
message: msg,
|
|
46
|
+
cause
|
|
80
47
|
};
|
|
81
|
-
while (slice.length > 0) {
|
|
82
|
-
const { node, bytesRead } = deserializeNodeInfoV1(slice);
|
|
83
|
-
slice = slice.subarray(bytesRead);
|
|
84
|
-
folderInfo.nodes[node.name] = node;
|
|
85
|
-
}
|
|
86
|
-
bytes.fill(0);
|
|
87
|
-
return folderInfo;
|
|
88
48
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
49
|
+
var formatV1;
|
|
50
|
+
(function (formatV1) {
|
|
51
|
+
function pack(folderInfo) {
|
|
52
|
+
const bytes = [ver1Serialization];
|
|
53
|
+
for (const nodeInfo of Object.values(folderInfo.nodes)) {
|
|
54
|
+
bytes.push(...packNode(nodeInfo));
|
|
55
|
+
}
|
|
56
|
+
return bytes;
|
|
57
|
+
}
|
|
58
|
+
formatV1.pack = pack;
|
|
59
|
+
function packNode(nodeInfo) {
|
|
60
|
+
const bytes = [nodeInfo.key];
|
|
61
|
+
const json = {
|
|
62
|
+
t: (nodeInfo.isFolder ? 1 : (nodeInfo.isFile ? 2 : 3)),
|
|
63
|
+
n: nodeInfo.name,
|
|
64
|
+
o: nodeInfo.objId
|
|
65
|
+
};
|
|
66
|
+
const jsonBytes = buffer_utils_1.utf8.pack(JSON.stringify(json));
|
|
67
|
+
assert_1.assert(jsonBytes.length < 0xffffffff);
|
|
68
|
+
bytes.push(numberToBytes(jsonBytes.length));
|
|
69
|
+
bytes.push(jsonBytes);
|
|
70
|
+
return bytes;
|
|
92
71
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
objId: json.o
|
|
72
|
+
function numberToBytes(x) {
|
|
73
|
+
const arr = Buffer.allocUnsafe(4);
|
|
74
|
+
big_endian_1.packUintTo4Bytes(x, arr, 0);
|
|
75
|
+
return arr;
|
|
76
|
+
}
|
|
77
|
+
function parse(bytes) {
|
|
78
|
+
let slice = bytes;
|
|
79
|
+
const folderInfo = {
|
|
80
|
+
nodes: {}
|
|
103
81
|
};
|
|
104
|
-
|
|
105
|
-
node
|
|
82
|
+
while (slice.length > 0) {
|
|
83
|
+
const { node, bytesRead } = deserializeNodeInfoV1(slice);
|
|
84
|
+
slice = slice.subarray(bytesRead);
|
|
85
|
+
folderInfo.nodes[node.name] = node;
|
|
106
86
|
}
|
|
107
|
-
|
|
108
|
-
|
|
87
|
+
bytes.fill(0);
|
|
88
|
+
return folderInfo;
|
|
89
|
+
}
|
|
90
|
+
formatV1.parse = parse;
|
|
91
|
+
function deserializeNodeInfoV1(bytes) {
|
|
92
|
+
if (bytes.length < (xsp_files_1.KEY_LENGTH + 4)) {
|
|
93
|
+
throw parsingException(`Cannot deserialize node key from bytes`);
|
|
109
94
|
}
|
|
110
|
-
|
|
111
|
-
|
|
95
|
+
const key = buffer_utils_1.makeUint8ArrayCopy(bytes.subarray(0, xsp_files_1.KEY_LENGTH));
|
|
96
|
+
bytes = bytes.subarray(xsp_files_1.KEY_LENGTH);
|
|
97
|
+
const jsonBytesLen = big_endian_1.uintFrom4Bytes(bytes);
|
|
98
|
+
bytes = bytes.subarray(4);
|
|
99
|
+
try {
|
|
100
|
+
const json = JSON.parse(buffer_utils_1.utf8.open(bytes.subarray(0, jsonBytesLen)));
|
|
101
|
+
const node = {
|
|
102
|
+
name: json.n,
|
|
103
|
+
key,
|
|
104
|
+
objId: json.o
|
|
105
|
+
};
|
|
106
|
+
if (json.t === 1) {
|
|
107
|
+
node.isFolder = true;
|
|
108
|
+
}
|
|
109
|
+
else if (json.t === 2) {
|
|
110
|
+
node.isFile = true;
|
|
111
|
+
}
|
|
112
|
+
else if (json.t === 3) {
|
|
113
|
+
node.isLink = true;
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
throw parsingException('unidentified node type');
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
node,
|
|
120
|
+
bytesRead: xsp_files_1.KEY_LENGTH + 4 + jsonBytesLen
|
|
121
|
+
};
|
|
112
122
|
}
|
|
113
|
-
|
|
114
|
-
throw
|
|
123
|
+
catch (err) {
|
|
124
|
+
throw parsingException(`Cannot deserialize node info from bytes.`, err);
|
|
115
125
|
}
|
|
116
|
-
return {
|
|
117
|
-
node,
|
|
118
|
-
bytesRead: xsp_files_1.KEY_LENGTH + 4 + jsonBytesLen
|
|
119
|
-
};
|
|
120
126
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
}
|
|
124
|
-
}
|
|
127
|
+
})(formatV1 || (formatV1 = {}));
|
|
128
|
+
Object.freeze(formatV1);
|
|
125
129
|
Object.freeze(exports);
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { Storage, Node, NodeType } from './common';
|
|
2
|
-
import { NodeInFS
|
|
2
|
+
import { NodeInFS } from './node-in-fs';
|
|
3
3
|
import { FileNode } from './file-node';
|
|
4
4
|
import { LinkNode } from './link-node';
|
|
5
5
|
import { LinkParameters } from '../../files';
|
|
6
6
|
import { AsyncSBoxCryptor, Subscribe, ObjSource } from 'xsp-files';
|
|
7
|
-
import {
|
|
7
|
+
import { CommonAttrs, XAttrs } from './attrs';
|
|
8
|
+
import { NodePersistance } from './node-persistence';
|
|
8
9
|
declare type ListingEntry = web3n.files.ListingEntry;
|
|
10
|
+
declare type XAttrsChanges = web3n.files.XAttrsChanges;
|
|
9
11
|
export interface NodeInfo {
|
|
10
12
|
/**
|
|
11
13
|
* This is a usual file name.
|
|
@@ -40,15 +42,17 @@ export interface FolderInfo {
|
|
|
40
42
|
[name: string]: NodeInfo;
|
|
41
43
|
};
|
|
42
44
|
}
|
|
43
|
-
export interface
|
|
44
|
-
|
|
45
|
+
export interface FolderInJSON extends FolderInfo {
|
|
46
|
+
ctime: number;
|
|
47
|
+
xattrs?: any;
|
|
45
48
|
}
|
|
46
|
-
declare class
|
|
49
|
+
declare class FolderPersistance extends NodePersistance {
|
|
47
50
|
constructor(zNonce: Uint8Array, key: Uint8Array, cryptor: AsyncSBoxCryptor);
|
|
48
|
-
|
|
49
|
-
|
|
51
|
+
write(folderInfo: FolderInfo, version: number, attrs: CommonAttrs, xattrs: XAttrs | undefined): Promise<Subscribe>;
|
|
52
|
+
read(src: ObjSource): Promise<{
|
|
50
53
|
folderInfo: FolderInfo;
|
|
51
|
-
attrs
|
|
54
|
+
attrs: CommonAttrs;
|
|
55
|
+
xattrs?: XAttrs;
|
|
52
56
|
}>;
|
|
53
57
|
}
|
|
54
58
|
export interface FolderLinkParams {
|
|
@@ -56,17 +60,14 @@ export interface FolderLinkParams {
|
|
|
56
60
|
objId: string;
|
|
57
61
|
fKey: string;
|
|
58
62
|
}
|
|
59
|
-
export declare class FolderNode extends NodeInFS<
|
|
63
|
+
export declare class FolderNode extends NodeInFS<FolderPersistance> {
|
|
60
64
|
private currentState;
|
|
61
|
-
private transitionState;
|
|
62
|
-
private transitionVersion;
|
|
63
|
-
private transitionSaved;
|
|
64
65
|
private constructor();
|
|
65
66
|
static newRoot(storage: Storage, key: Uint8Array): Promise<FolderNode>;
|
|
66
67
|
static rootFromObjBytes(storage: Storage, name: string | undefined, objId: string | null, src: ObjSource, key: Uint8Array): Promise<FolderNode>;
|
|
67
68
|
private static readNodeFromObjBytes;
|
|
68
69
|
static rootFromLinkParams(storage: Storage, params: FolderLinkParams): Promise<FolderNode>;
|
|
69
|
-
static rootFromJSON(storage: Storage, name: string | undefined, folderJson:
|
|
70
|
+
static rootFromJSON(storage: Storage, name: string | undefined, folderJson: FolderInJSON): FolderNode;
|
|
70
71
|
list(): {
|
|
71
72
|
lst: ListingEntry[];
|
|
72
73
|
version: number;
|
|
@@ -88,21 +89,15 @@ export declare class FolderNode extends NodeInFS<FolderCrypto, FolderAttrs> {
|
|
|
88
89
|
private fixMissingChildAndThrow;
|
|
89
90
|
/**
|
|
90
91
|
* This method prepares a transition state, runs given action, and completes
|
|
91
|
-
* transition to a new version.
|
|
92
|
-
* action returns (promise is unwrapped).
|
|
92
|
+
* transition to a new version.
|
|
93
93
|
* Note that if there is already an ongoing change, this transition will
|
|
94
94
|
* wait. Such behaviour is generally needed for folder as different processes
|
|
95
95
|
* may be sharing same elements in a file tree. In contrast, file
|
|
96
96
|
* operations should more often follow a throw instead wait approach.
|
|
97
|
-
* @param
|
|
98
|
-
* while false value indicates that saving will be done within a given action
|
|
99
|
-
* @param action is a function that is run when transition is started
|
|
97
|
+
* @param change is a function that is run when transition is started
|
|
100
98
|
*/
|
|
101
99
|
private doTransition;
|
|
102
|
-
private
|
|
103
|
-
private clearTransitionState;
|
|
104
|
-
private saveTransitionState;
|
|
105
|
-
private addToTransitionState;
|
|
100
|
+
private performTransition;
|
|
106
101
|
/**
|
|
107
102
|
* This function only creates folder node, but it doesn't insert it anywhere.
|
|
108
103
|
* @param name
|
|
@@ -121,10 +116,10 @@ export declare class FolderNode extends NodeInFS<FolderCrypto, FolderAttrs> {
|
|
|
121
116
|
*/
|
|
122
117
|
private makeAndSaveNewChildLinkNode;
|
|
123
118
|
private create;
|
|
124
|
-
createFolder(name: string, exclusive: boolean): Promise<FolderNode>;
|
|
119
|
+
createFolder(name: string, exclusive: boolean, changes: XAttrsChanges | undefined): Promise<FolderNode>;
|
|
125
120
|
createFile(name: string, exclusive: boolean): Promise<FileNode>;
|
|
126
121
|
createLink(name: string, params: LinkParameters<any>): Promise<void>;
|
|
127
|
-
removeChild(f: NodeInFS<
|
|
122
|
+
removeChild(f: NodeInFS<any>): Promise<void>;
|
|
128
123
|
private changeChildName;
|
|
129
124
|
moveChildTo(childName: string, dst: FolderNode, nameInDst: string): Promise<void>;
|
|
130
125
|
private moveChildOut;
|