core-3nweb-client-lib 0.20.9 → 0.23.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.
Files changed (67) hide show
  1. package/build/api-defs/common-caps.d.ts +6 -10
  2. package/build/api-defs/files.d.ts +8 -7
  3. package/build/core/asmail/inbox/attachments/fs.d.ts +2 -2
  4. package/build/core/asmail/inbox/attachments/fs.js +3 -2
  5. package/build/core/asmail/msg/common.d.ts +2 -2
  6. package/build/core/asmail/msg/common.js +3 -2
  7. package/build/core/asmail/msg/opener.d.ts +2 -2
  8. package/build/core/asmail/msg/opener.js +3 -2
  9. package/build/core/asmail/msg/packer.d.ts +2 -2
  10. package/build/core/asmail/msg/packer.js +7 -6
  11. package/build/core/index.d.ts +2 -2
  12. package/build/core/index.js +24 -28
  13. package/build/core/storage/index.js +2 -2
  14. package/build/core/storage/local/obj-files.js +8 -5
  15. package/build/core/storage/local/obj-status.js +4 -3
  16. package/build/core/storage/synced/obj-status.js +4 -3
  17. package/build/ipc-via-protobuf/bytes.js +1 -1
  18. package/build/ipc-via-protobuf/file.d.ts +4 -0
  19. package/build/ipc-via-protobuf/file.js +17 -15
  20. package/build/ipc-via-protobuf/fs.js +1 -1
  21. package/build/lib-client/3nstorage/xsp-fs/attrs.d.ts +28 -0
  22. package/build/lib-client/3nstorage/xsp-fs/attrs.js +337 -0
  23. package/build/lib-client/3nstorage/xsp-fs/common.d.ts +1 -1
  24. package/build/lib-client/3nstorage/xsp-fs/common.js +3 -2
  25. package/build/lib-client/3nstorage/xsp-fs/file-node.d.ts +31 -18
  26. package/build/lib-client/3nstorage/xsp-fs/file-node.js +130 -118
  27. package/build/lib-client/3nstorage/xsp-fs/file.d.ts +0 -1
  28. package/build/lib-client/3nstorage/xsp-fs/file.js +14 -49
  29. package/build/lib-client/3nstorage/xsp-fs/folder-node-serialization.d.ts +1 -1
  30. package/build/lib-client/3nstorage/xsp-fs/folder-node-serialization.js +95 -91
  31. package/build/lib-client/3nstorage/xsp-fs/folder-node.d.ts +19 -24
  32. package/build/lib-client/3nstorage/xsp-fs/folder-node.js +133 -190
  33. package/build/lib-client/3nstorage/xsp-fs/fs.d.ts +3 -4
  34. package/build/lib-client/3nstorage/xsp-fs/fs.js +18 -21
  35. package/build/lib-client/3nstorage/xsp-fs/link-node.d.ts +13 -8
  36. package/build/lib-client/3nstorage/xsp-fs/link-node.js +46 -38
  37. package/build/lib-client/3nstorage/xsp-fs/node-in-fs.d.ts +17 -35
  38. package/build/lib-client/3nstorage/xsp-fs/node-in-fs.js +34 -127
  39. package/build/lib-client/3nstorage/xsp-fs/node-persistence.d.ts +57 -0
  40. package/build/lib-client/3nstorage/xsp-fs/node-persistence.js +182 -0
  41. package/build/lib-client/3nstorage/xsp-fs/xsp-payload-v1.d.ts +3 -0
  42. package/build/lib-client/3nstorage/xsp-fs/xsp-payload-v1.js +87 -0
  43. package/build/lib-client/3nstorage/xsp-fs/xsp-payload-v2.d.ts +6 -0
  44. package/build/lib-client/3nstorage/xsp-fs/xsp-payload-v2.js +1022 -0
  45. package/build/lib-client/cryptor/cryptor-wasm.js +1 -1
  46. package/build/lib-client/cryptor/cryptor.wasm +0 -0
  47. package/build/lib-client/local-files/device-fs.js +7 -3
  48. package/build/lib-client/objs-on-disk/file-writing-proc.js +3 -2
  49. package/build/lib-client/objs-on-disk/obj-on-disk.js +8 -7
  50. package/build/lib-common/big-endian.d.ts +0 -24
  51. package/build/lib-common/big-endian.js +16 -78
  52. package/build/lib-common/exceptions/file.js +6 -2
  53. package/build/lib-common/obj-streaming/sink-utils.d.ts +0 -4
  54. package/build/lib-common/obj-streaming/sink-utils.js +4 -70
  55. package/build/lib-common/objs-on-disk/file-layout.js +2 -1
  56. package/build/lib-common/objs-on-disk/obj-file.js +2 -2
  57. package/build/lib-common/objs-on-disk/utils.js +2 -1
  58. package/build/lib-common/objs-on-disk/v1-obj-file-format.js +2 -1
  59. package/package.json +2 -2
  60. package/build/lib-client/files/file-attrs.d.ts +0 -76
  61. package/build/lib-client/files/file-attrs.js +0 -549
  62. package/build/lib-client/files/file-layout.d.ts +0 -56
  63. package/build/lib-client/files/file-layout.js +0 -456
  64. package/build/lib-client/files/file-sink.d.ts +0 -33
  65. package/build/lib-client/files/file-sink.js +0 -173
  66. package/build/lib-client/files/file-source.d.ts +0 -19
  67. package/build/lib-client/files/file-source.js +0 -115
@@ -0,0 +1,182 @@
1
+ "use strict";
2
+ /*
3
+ Copyright (C) 2015 - 2020, 2022 3NSoft Inc.
4
+
5
+ This program is free software: you can redistribute it and/or modify it under
6
+ the terms of the GNU General Public License as published by the Free Software
7
+ Foundation, either version 3 of the License, or (at your option) any later
8
+ version.
9
+
10
+ This program is distributed in the hope that it will be useful, but
11
+ WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
+ See the GNU General Public License for more details.
14
+
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/>.
17
+ */
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.NodePersistance = void 0;
20
+ /**
21
+ * Everything in this module is assumed to be inside of a file system
22
+ * reliance set.
23
+ */
24
+ const xsp_files_1 = require("xsp-files");
25
+ const buffer_utils_1 = require("../../../lib-common/buffer-utils");
26
+ const processes_1 = require("../../../lib-common/processes");
27
+ const random = require("../../../lib-common/random-node");
28
+ const pv1 = require("./xsp-payload-v1");
29
+ const pv2 = require("./xsp-payload-v2");
30
+ const SEG_SIZE = 16; // in 256-byte blocks = 4K in bytes
31
+ const EMPTY_BYTE_ARR = new Uint8Array(0);
32
+ /**
33
+ * This does reading and writing, keeping keys. This and extending objects are
34
+ * used in file system nodes as thematic place with persistence functionality.
35
+ */
36
+ class NodePersistance {
37
+ constructor(zerothHeaderNonce, key, cryptor) {
38
+ this.zerothHeaderNonce = zerothHeaderNonce;
39
+ this.key = key;
40
+ this.cryptor = cryptor;
41
+ this.reencryptHeader = async (initHeader, newVersion) => {
42
+ if (!this.key) {
43
+ throw new Error("Cannot use wiped object.");
44
+ }
45
+ const headerContent = await this.cryptor.formatWN.open(initHeader, this.key);
46
+ const n = xsp_files_1.calculateNonce(this.zerothHeaderNonce, newVersion);
47
+ return this.cryptor.formatWN.pack(headerContent, n, this.key);
48
+ };
49
+ }
50
+ wipe() {
51
+ if (this.key) {
52
+ this.key.fill(0);
53
+ this.key = undefined;
54
+ this.zerothHeaderNonce.fill(0);
55
+ this.zerothHeaderNonce = undefined;
56
+ }
57
+ }
58
+ compareKey(keyB64) {
59
+ const k = buffer_utils_1.base64.open(keyB64);
60
+ return xsp_files_1.compareVectors(k, this.key);
61
+ }
62
+ fileKeyInBase64() {
63
+ if (!this.key) {
64
+ throw new Error("Cannot use wiped object.");
65
+ }
66
+ return buffer_utils_1.base64.pack(this.key);
67
+ }
68
+ segWriter(version) {
69
+ if (!this.key) {
70
+ throw new Error("Cannot use wiped object.");
71
+ }
72
+ return xsp_files_1.makeSegmentsWriter(this.key, this.zerothHeaderNonce, version, { type: 'new', segSize: SEG_SIZE, payloadFormat: 2 }, random.bytes, this.cryptor);
73
+ }
74
+ async segWriterWithBase(newVersion, base) {
75
+ if (!this.key) {
76
+ throw new Error("Cannot use wiped object.");
77
+ }
78
+ return xsp_files_1.makeSegmentsWriter(this.key, this.zerothHeaderNonce, newVersion, { type: 'update', base, payloadFormat: 2 }, random.bytes, this.cryptor);
79
+ }
80
+ async decryptedByteSrc(src) {
81
+ if (!this.key) {
82
+ throw new Error("Cannot use wiped object.");
83
+ }
84
+ const version = src.version;
85
+ const header = await src.readHeader();
86
+ const segReader = await xsp_files_1.makeSegmentsReader(this.key, this.zerothHeaderNonce, version, header, this.cryptor);
87
+ return {
88
+ version,
89
+ byteSrc: xsp_files_1.makeDecryptedByteSource(src.segSrc, segReader),
90
+ payloadFormat: segReader.payloadFormat
91
+ };
92
+ }
93
+ async readonlyPayload(src) {
94
+ const { payloadFormat, byteSrc } = await this.decryptedByteSrc(src);
95
+ if (payloadFormat === 2) {
96
+ const payload = await pv2.makeReadonlyPayload(byteSrc);
97
+ return payload;
98
+ }
99
+ else if (payloadFormat === 1) {
100
+ return await pv1.makeReadonlyPayload(byteSrc);
101
+ }
102
+ else {
103
+ throw new Error(`XSP segments payload format ${payloadFormat} is unknown`);
104
+ }
105
+ }
106
+ async readAll(src) {
107
+ const payload = await this.readonlyPayload(src);
108
+ return {
109
+ content: await payload.readAllContent(),
110
+ attrs: payload.getAttrs(),
111
+ xattrs: await payload.getXAttrs(),
112
+ };
113
+ }
114
+ async writablePayload(sink, attrs, base) {
115
+ if (base) {
116
+ const { byteSrc, version } = await this.decryptedByteSrc(base);
117
+ return await pv2.makeWritablePayloadFromBase(sink, version, byteSrc);
118
+ }
119
+ else {
120
+ return await pv2.makeWritablePayload(sink, attrs);
121
+ }
122
+ }
123
+ async writeWhole(content, newVersion, attrs, xattrs) {
124
+ const bytes = (Array.isArray(content) ? content : [content]);
125
+ const segWriter = await this.segWriter(newVersion);
126
+ const { sink, sub } = xsp_files_1.makeEncryptingByteSink(segWriter);
127
+ return (obs, backpressure) => {
128
+ // sub must be called before payload creation that uses sink
129
+ const unsub = sub(obs, backpressure);
130
+ this.writablePayload(sink, attrs)
131
+ .then(payload => payload.writeAllContent(bytes, xattrs), err => { var _a; return (_a = obs.error) === null || _a === void 0 ? void 0 : _a.call(obs, err); });
132
+ return unsub;
133
+ };
134
+ }
135
+ async writeXAttrs(xattrs, newVersion, base) {
136
+ const segWriter = await this.segWriterWithBase(newVersion, base);
137
+ const { sink, sub } = xsp_files_1.makeEncryptingByteSink(segWriter);
138
+ return (obs, backpressure) => {
139
+ // sub must be called before payload creation that uses sink
140
+ const unsub = sub(obs, backpressure);
141
+ this.writablePayload(sink, undefined, base)
142
+ .then(payload => payload.setXAttrs(xattrs), err => { var _a; return (_a = obs.error) === null || _a === void 0 ? void 0 : _a.call(obs, err); });
143
+ return unsub;
144
+ };
145
+ }
146
+ async writableSink(newVersion, attrs, xattrs, base) {
147
+ const segWriter = await (base ?
148
+ this.segWriterWithBase(newVersion, base) :
149
+ this.segWriter(newVersion));
150
+ const { sink, sub } = xsp_files_1.makeEncryptingByteSink(segWriter);
151
+ const defSink = processes_1.defer();
152
+ return {
153
+ sinkPromise: defSink.promise,
154
+ sub: (obs, backpressure) => {
155
+ var _a;
156
+ try {
157
+ // sub must be called before payload creation that uses sink
158
+ const unsub = sub(obs, backpressure);
159
+ this.writablePayload(sink, attrs, base)
160
+ .then(payload => payload.makeFileByteSink(xattrs))
161
+ .then(sink => defSink.resolve(sink), err => {
162
+ if (obs.error) {
163
+ obs.error(err);
164
+ }
165
+ defSink.reject(err);
166
+ });
167
+ return unsub;
168
+ }
169
+ catch (err) {
170
+ defSink.reject(err);
171
+ (_a = obs.error) === null || _a === void 0 ? void 0 : _a.call(obs, err);
172
+ throw err;
173
+ }
174
+ }
175
+ };
176
+ }
177
+ }
178
+ exports.NodePersistance = NodePersistance;
179
+ Object.freeze(NodePersistance.prototype);
180
+ Object.freeze(NodePersistance);
181
+ function noop() { }
182
+ Object.freeze(exports);
@@ -0,0 +1,3 @@
1
+ import { ByteSource } from "xsp-files";
2
+ import { ReadonlyPayload } from "./node-persistence";
3
+ export declare function makeReadonlyPayload(src: ByteSource): Promise<ReadonlyPayload>;
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ /*
3
+ Copyright (C) 2022 3NSoft Inc.
4
+
5
+ This program is free software: you can redistribute it and/or modify it under
6
+ the terms of the GNU General Public License as published by the Free Software
7
+ Foundation, either version 3 of the License, or (at your option) any later
8
+ version.
9
+
10
+ This program is distributed in the hope that it will be useful, but
11
+ WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
+ See the GNU General Public License for more details.
14
+
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/>.
17
+ */
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.makeReadonlyPayload = void 0;
20
+ const assert_1 = require("../../../lib-common/assert");
21
+ const file_1 = require("../../../lib-common/exceptions/file");
22
+ const processes_1 = require("../../../lib-common/processes");
23
+ const attrs_1 = require("./attrs");
24
+ async function makeReadonlyPayload(src) {
25
+ const payload = await ReadonlyPayloadV1.makeFor(src);
26
+ return payload;
27
+ }
28
+ exports.makeReadonlyPayload = makeReadonlyPayload;
29
+ class ReadonlyPayloadV1 {
30
+ constructor(src, size, isEndless = false) {
31
+ this.src = src;
32
+ this.size = size;
33
+ this.isEndless = isEndless;
34
+ this.syncProc = new processes_1.SingleProc();
35
+ this.xattrs = undefined;
36
+ this.isEndless = (this.size === undefined);
37
+ Object.seal(this);
38
+ }
39
+ static async makeFor(src) {
40
+ let { size, isEndless } = await src.getSize();
41
+ return new ReadonlyPayloadV1(src, size, isEndless);
42
+ }
43
+ getAttrs() {
44
+ return {
45
+ ctime: 0, mtime: 0, size: this.size, isEndless: this.isEndless
46
+ };
47
+ }
48
+ async getXAttrs() {
49
+ if (!this.xattrs) {
50
+ this.xattrs = attrs_1.XAttrs.makeEmpty();
51
+ }
52
+ return this.xattrs;
53
+ }
54
+ readAllContent() {
55
+ if (this.isEndless) {
56
+ throw makeEndlessException();
57
+ }
58
+ return this.readSomeContentBytes(0, this.size);
59
+ }
60
+ async readSomeContentBytes(start, end) {
61
+ if (this.isEndless) {
62
+ throw makeEndlessException();
63
+ }
64
+ assert_1.assert(Number.isInteger(start) && (start >= 0) && (start <= this.size));
65
+ assert_1.assert(Number.isInteger(end) && (end >= start) && (end <= this.size));
66
+ if (end === start) {
67
+ return;
68
+ }
69
+ return await this.syncProc.startOrChain(async () => {
70
+ await this.src.seek(start);
71
+ return await this.src.read(end - start);
72
+ });
73
+ }
74
+ makeFileByteSource() {
75
+ const { getPosition, seek, read } = this.src;
76
+ return {
77
+ seek, getPosition, read,
78
+ getSize: async () => this.size,
79
+ };
80
+ }
81
+ }
82
+ Object.freeze(ReadonlyPayloadV1.prototype);
83
+ Object.freeze(ReadonlyPayloadV1);
84
+ function makeEndlessException() {
85
+ return file_1.makeFileException(file_1.Code.isEndless, '');
86
+ }
87
+ Object.freeze(exports);
@@ -0,0 +1,6 @@
1
+ import { ByteSink, ByteSource } from "xsp-files";
2
+ import { CommonAttrs } from "./attrs";
3
+ import { ReadonlyPayload, WritablePayload } from "./node-persistence";
4
+ export declare function makeReadonlyPayload(src: ByteSource): Promise<ReadonlyPayload>;
5
+ export declare function makeWritablePayload(sink: ByteSink, attrs?: CommonAttrs): Promise<WritablePayload>;
6
+ export declare function makeWritablePayloadFromBase(sink: ByteSink, base: number, baseSrc: ByteSource): Promise<WritablePayload>;