@ethersphere/bee-js 5.1.1 → 5.1.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.
- package/README.md +14 -6
- package/dist/223.index.browser.min.js +3 -0
- package/dist/223.index.browser.min.js.LICENSE.txt +1 -0
- package/dist/223.index.browser.min.js.map +1 -0
- package/dist/cjs/bee-debug.js +208 -312
- package/dist/cjs/bee.js +258 -353
- package/dist/cjs/chunk/signer.js +11 -22
- package/dist/cjs/chunk/soc.js +33 -50
- package/dist/cjs/chunk/span.js +1 -1
- package/dist/cjs/feed/index.js +50 -65
- package/dist/cjs/feed/json.js +8 -21
- package/dist/cjs/feed/retrievable.js +14 -27
- package/dist/cjs/modules/bytes.js +25 -37
- package/dist/cjs/modules/bzz.js +63 -68
- package/dist/cjs/modules/chunk.js +17 -27
- package/dist/cjs/modules/debug/balance.js +24 -41
- package/dist/cjs/modules/debug/chequebook.js +71 -96
- package/dist/cjs/modules/debug/chunk.js +13 -26
- package/dist/cjs/modules/debug/connectivity.js +32 -53
- package/dist/cjs/modules/debug/settlements.js +12 -25
- package/dist/cjs/modules/debug/stake.js +20 -33
- package/dist/cjs/modules/debug/stamps.js +45 -66
- package/dist/cjs/modules/debug/states.js +27 -40
- package/dist/cjs/modules/debug/status.js +53 -80
- package/dist/cjs/modules/debug/tag.js +6 -17
- package/dist/cjs/modules/debug/transactions.js +23 -40
- package/dist/cjs/modules/feed.js +17 -27
- package/dist/cjs/modules/pinning.js +24 -41
- package/dist/cjs/modules/pss.js +9 -20
- package/dist/cjs/modules/soc.js +12 -20
- package/dist/cjs/modules/status.js +4 -15
- package/dist/cjs/modules/stewardship.js +10 -23
- package/dist/cjs/modules/tag.js +28 -47
- package/dist/cjs/utils/collection.browser.js +4 -17
- package/dist/cjs/utils/collection.js +11 -22
- package/dist/cjs/utils/collection.node.js +42 -86
- package/dist/cjs/utils/data.browser.js +46 -59
- package/dist/cjs/utils/data.js +22 -35
- package/dist/cjs/utils/eth.js +31 -43
- package/dist/cjs/utils/file.js +9 -20
- package/dist/cjs/utils/headers.js +4 -4
- package/dist/cjs/utils/http.js +78 -93
- package/dist/cjs/utils/merge.js +1 -1
- package/dist/cjs/utils/sleep.js +2 -13
- package/dist/cjs/utils/type.js +14 -12
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.LICENSE.txt +1 -3
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/bee-debug.js +209 -450
- package/dist/mjs/bee.js +256 -491
- package/dist/mjs/chunk/bmt.js +4 -10
- package/dist/mjs/chunk/cac.js +0 -3
- package/dist/mjs/chunk/signer.js +12 -63
- package/dist/mjs/chunk/soc.js +33 -85
- package/dist/mjs/chunk/span.js +3 -6
- package/dist/mjs/feed/identifier.js +0 -6
- package/dist/mjs/feed/index.js +53 -97
- package/dist/mjs/feed/json.js +10 -49
- package/dist/mjs/feed/retrievable.js +13 -64
- package/dist/mjs/feed/topic.js +0 -2
- package/dist/mjs/index.js +1 -2
- package/dist/mjs/modules/bytes.js +25 -65
- package/dist/mjs/modules/bzz.js +64 -108
- package/dist/mjs/modules/chunk.js +17 -54
- package/dist/mjs/modules/debug/balance.js +24 -68
- package/dist/mjs/modules/debug/chequebook.js +75 -138
- package/dist/mjs/modules/debug/chunk.js +13 -51
- package/dist/mjs/modules/debug/connectivity.js +32 -76
- package/dist/mjs/modules/debug/settlements.js +12 -50
- package/dist/mjs/modules/debug/stake.js +20 -61
- package/dist/mjs/modules/debug/stamps.js +47 -94
- package/dist/mjs/modules/debug/states.js +25 -66
- package/dist/mjs/modules/debug/status.js +66 -125
- package/dist/mjs/modules/debug/tag.js +6 -41
- package/dist/mjs/modules/debug/transactions.js +25 -69
- package/dist/mjs/modules/feed.js +17 -57
- package/dist/mjs/modules/pinning.js +24 -68
- package/dist/mjs/modules/pss.js +11 -47
- package/dist/mjs/modules/soc.js +14 -48
- package/dist/mjs/modules/status.js +4 -39
- package/dist/mjs/modules/stewardship.js +10 -47
- package/dist/mjs/modules/tag.js +31 -78
- package/dist/mjs/types/debug.js +0 -1
- package/dist/mjs/types/index.js +0 -4
- package/dist/mjs/utils/bytes.js +6 -14
- package/dist/mjs/utils/collection.browser.js +4 -42
- package/dist/mjs/utils/collection.js +11 -57
- package/dist/mjs/utils/collection.node.js +42 -150
- package/dist/mjs/utils/data.browser.js +49 -94
- package/dist/mjs/utils/data.js +19 -62
- package/dist/mjs/utils/error.js +0 -5
- package/dist/mjs/utils/eth.js +37 -95
- package/dist/mjs/utils/file.js +11 -50
- package/dist/mjs/utils/hash.js +0 -1
- package/dist/mjs/utils/headers.js +6 -14
- package/dist/mjs/utils/hex.js +6 -25
- package/dist/mjs/utils/http.js +80 -138
- package/dist/mjs/utils/merge.js +3 -7
- package/dist/mjs/utils/pss.js +0 -2
- package/dist/mjs/utils/reference.js +2 -5
- package/dist/mjs/utils/sleep.js +2 -37
- package/dist/mjs/utils/stream.js +0 -23
- package/dist/mjs/utils/tar.js +2 -5
- package/dist/mjs/utils/type.js +18 -82
- package/dist/mjs/utils/uint64.js +0 -1
- package/dist/mjs/utils/url.js +2 -10
- package/dist/types/bee-debug.d.ts +2 -2
- package/dist/types/bee.d.ts +2 -26
- package/dist/types/chunk/cac.d.ts +1 -1
- package/dist/types/chunk/soc.d.ts +8 -7
- package/dist/types/feed/index.d.ts +9 -8
- package/dist/types/feed/type.d.ts +1 -1
- package/dist/types/modules/bytes.d.ts +6 -5
- package/dist/types/modules/bzz.d.ts +9 -8
- package/dist/types/modules/chunk.d.ts +5 -4
- package/dist/types/modules/debug/balance.d.ts +10 -9
- package/dist/types/modules/debug/chequebook.d.ts +18 -17
- package/dist/types/modules/debug/chunk.d.ts +6 -5
- package/dist/types/modules/debug/connectivity.d.ts +8 -7
- package/dist/types/modules/debug/settlements.d.ts +6 -5
- package/dist/types/modules/debug/stake.d.ts +5 -4
- package/dist/types/modules/debug/stamps.d.ts +8 -7
- package/dist/types/modules/debug/states.d.ts +8 -7
- package/dist/types/modules/debug/status.d.ts +15 -15
- package/dist/types/modules/debug/tag.d.ts +4 -3
- package/dist/types/modules/debug/transactions.d.ts +6 -5
- package/dist/types/modules/feed.d.ts +4 -3
- package/dist/types/modules/pinning.d.ts +8 -7
- package/dist/types/modules/pss.d.ts +4 -3
- package/dist/types/modules/soc.d.ts +3 -2
- package/dist/types/modules/status.d.ts +3 -3
- package/dist/types/modules/stewardship.d.ts +4 -3
- package/dist/types/modules/tag.d.ts +7 -6
- package/dist/types/types/debug.d.ts +1 -1
- package/dist/types/types/index.d.ts +30 -34
- package/dist/types/utils/eth.d.ts +3 -3
- package/dist/types/utils/hex.d.ts +2 -2
- package/dist/types/utils/http.d.ts +6 -6
- package/package.json +34 -39
- package/dist/cjs/types/ky-options.js +0 -8
- package/dist/cjs/types/ky-universal/common.js +0 -8
- package/dist/cjs/types/ky-universal/hooks.js +0 -8
- package/dist/cjs/types/ky-universal/retry.js +0 -8
- package/dist/mjs/types/ky-options.js +0 -7
- package/dist/mjs/types/ky-universal/common.js +0 -7
- package/dist/mjs/types/ky-universal/hooks.js +0 -7
- package/dist/mjs/types/ky-universal/retry.js +0 -7
- package/dist/types/types/ky-options.d.ts +0 -221
- package/dist/types/types/ky-universal/common.d.ts +0 -13
- package/dist/types/types/ky-universal/hooks.d.ts +0 -92
- package/dist/types/types/ky-universal/retry.d.ts +0 -38
package/dist/mjs/modules/tag.js
CHANGED
|
@@ -1,35 +1,3 @@
|
|
|
1
|
-
var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) {
|
|
3
|
-
return value instanceof P ? value : new P(function (resolve) {
|
|
4
|
-
resolve(value);
|
|
5
|
-
});
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
9
|
-
function fulfilled(value) {
|
|
10
|
-
try {
|
|
11
|
-
step(generator.next(value));
|
|
12
|
-
} catch (e) {
|
|
13
|
-
reject(e);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function rejected(value) {
|
|
18
|
-
try {
|
|
19
|
-
step(generator["throw"](value));
|
|
20
|
-
} catch (e) {
|
|
21
|
-
reject(e);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function step(result) {
|
|
26
|
-
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
|
-
|
|
33
1
|
import { http } from "../utils/http.js";
|
|
34
2
|
const endpoint = 'tags';
|
|
35
3
|
/**
|
|
@@ -37,16 +5,13 @@ const endpoint = 'tags';
|
|
|
37
5
|
*
|
|
38
6
|
* @param url Bee tag URL
|
|
39
7
|
*/
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
path: endpoint,
|
|
46
|
-
responseType: 'json'
|
|
47
|
-
});
|
|
48
|
-
return response.data;
|
|
8
|
+
export async function createTag(kyOptions) {
|
|
9
|
+
const response = await http(kyOptions, {
|
|
10
|
+
method: 'post',
|
|
11
|
+
path: endpoint,
|
|
12
|
+
responseType: 'json'
|
|
49
13
|
});
|
|
14
|
+
return response.parsedData;
|
|
50
15
|
}
|
|
51
16
|
/**
|
|
52
17
|
* Retrieve tag information from Bee node
|
|
@@ -54,15 +19,12 @@ export function createTag(ky) {
|
|
|
54
19
|
* @param url Bee tag URL
|
|
55
20
|
* @param uid UID of tag to be retrieved
|
|
56
21
|
*/
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
path: `${endpoint}/${uid}`,
|
|
62
|
-
responseType: 'json'
|
|
63
|
-
});
|
|
64
|
-
return response.data;
|
|
22
|
+
export async function retrieveTag(kyOptions, uid) {
|
|
23
|
+
const response = await http(kyOptions, {
|
|
24
|
+
path: `${endpoint}/${uid}`,
|
|
25
|
+
responseType: 'json'
|
|
65
26
|
});
|
|
27
|
+
return response.parsedData;
|
|
66
28
|
}
|
|
67
29
|
/**
|
|
68
30
|
* Get limited listing of all tags.
|
|
@@ -71,32 +33,26 @@ export function retrieveTag(ky, uid) {
|
|
|
71
33
|
* @param offset
|
|
72
34
|
* @param limit
|
|
73
35
|
*/
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
},
|
|
83
|
-
responseType: 'json'
|
|
84
|
-
});
|
|
85
|
-
return response.data.tags;
|
|
36
|
+
export async function getAllTags(kyOptions, offset, limit) {
|
|
37
|
+
const response = await http(kyOptions, {
|
|
38
|
+
path: `${endpoint}`,
|
|
39
|
+
searchParams: {
|
|
40
|
+
offset,
|
|
41
|
+
limit
|
|
42
|
+
},
|
|
43
|
+
responseType: 'json'
|
|
86
44
|
});
|
|
45
|
+
return response.parsedData.tags;
|
|
87
46
|
}
|
|
88
47
|
/**
|
|
89
48
|
* Removes tag from the Bee node.
|
|
90
49
|
* @param url
|
|
91
50
|
* @param uid
|
|
92
51
|
*/
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
method: 'delete',
|
|
98
|
-
path: `${endpoint}/${uid}`
|
|
99
|
-
});
|
|
52
|
+
export async function deleteTag(kyOptions, uid) {
|
|
53
|
+
await http(kyOptions, {
|
|
54
|
+
method: 'delete',
|
|
55
|
+
path: `${endpoint}/${uid}`
|
|
100
56
|
});
|
|
101
57
|
}
|
|
102
58
|
/**
|
|
@@ -105,15 +61,12 @@ export function deleteTag(ky, uid) {
|
|
|
105
61
|
* @param uid
|
|
106
62
|
* @param reference
|
|
107
63
|
*/
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
reference
|
|
116
|
-
}
|
|
117
|
-
});
|
|
64
|
+
export async function updateTag(kyOptions, uid, reference) {
|
|
65
|
+
await http(kyOptions, {
|
|
66
|
+
method: 'patch',
|
|
67
|
+
path: `${endpoint}/${uid}`,
|
|
68
|
+
json: {
|
|
69
|
+
reference
|
|
70
|
+
}
|
|
118
71
|
});
|
|
119
72
|
}
|
package/dist/mjs/types/debug.js
CHANGED
package/dist/mjs/types/index.js
CHANGED
|
@@ -14,12 +14,10 @@ export const ENCRYPTED_REFERENCE_BYTES_LENGTH = 64;
|
|
|
14
14
|
/**
|
|
15
15
|
* Minimal depth that can be used for creation of postage batch
|
|
16
16
|
*/
|
|
17
|
-
|
|
18
17
|
export const STAMPS_DEPTH_MIN = 17;
|
|
19
18
|
/**
|
|
20
19
|
* Maximal depth that can be used for creation of postage batch
|
|
21
20
|
*/
|
|
22
|
-
|
|
23
21
|
export const STAMPS_DEPTH_MAX = 255;
|
|
24
22
|
export const TAGS_LIMIT_MIN = 1;
|
|
25
23
|
export const TAGS_LIMIT_MAX = 1000;
|
|
@@ -27,12 +25,10 @@ export const FEED_INDEX_HEX_LENGTH = 16;
|
|
|
27
25
|
/*********************************************************
|
|
28
26
|
* Writers and Readers interfaces
|
|
29
27
|
*/
|
|
30
|
-
|
|
31
28
|
export const TOPIC_BYTES_LENGTH = 32;
|
|
32
29
|
export const TOPIC_HEX_LENGTH = 64;
|
|
33
30
|
/*********************************************************
|
|
34
31
|
* Ethereum compatible signing interfaces and definitions
|
|
35
32
|
*/
|
|
36
|
-
|
|
37
33
|
export const SIGNATURE_HEX_LENGTH = 130;
|
|
38
34
|
export const SIGNATURE_BYTES_LENGTH = 65;
|
package/dist/mjs/utils/bytes.js
CHANGED
|
@@ -5,7 +5,6 @@ import { bytesToHex } from "./hex.js";
|
|
|
5
5
|
* @param b The byte array
|
|
6
6
|
* @param length The length of the byte array
|
|
7
7
|
*/
|
|
8
|
-
|
|
9
8
|
export function isBytes(b, length) {
|
|
10
9
|
return b instanceof Uint8Array && b.length === length;
|
|
11
10
|
}
|
|
@@ -15,12 +14,10 @@ export function isBytes(b, length) {
|
|
|
15
14
|
* @param offset
|
|
16
15
|
* @param length
|
|
17
16
|
*/
|
|
18
|
-
|
|
19
17
|
export function hasBytesAtOffset(data, offset, length) {
|
|
20
18
|
if (!(data instanceof Uint8Array)) {
|
|
21
19
|
throw new TypeError('Data has to an Uint8Array!');
|
|
22
20
|
}
|
|
23
|
-
|
|
24
21
|
const offsetBytes = data.slice(offset, offset + length);
|
|
25
22
|
return isBytes(offsetBytes, length);
|
|
26
23
|
}
|
|
@@ -30,7 +27,6 @@ export function hasBytesAtOffset(data, offset, length) {
|
|
|
30
27
|
* @param b The byte array
|
|
31
28
|
* @param length The specified length
|
|
32
29
|
*/
|
|
33
|
-
|
|
34
30
|
export function assertBytes(b, length) {
|
|
35
31
|
if (!isBytes(b, length)) {
|
|
36
32
|
throw new TypeError(`Parameter is not valid Bytes of length: ${length} !== ${b.length}`);
|
|
@@ -43,7 +39,6 @@ export function assertBytes(b, length) {
|
|
|
43
39
|
* @param min Minimum size of the array
|
|
44
40
|
* @param max Maximum size of the array
|
|
45
41
|
*/
|
|
46
|
-
|
|
47
42
|
export function isFlexBytes(b, min, max) {
|
|
48
43
|
return b instanceof Uint8Array && b.length >= min && b.length <= max;
|
|
49
44
|
}
|
|
@@ -54,7 +49,6 @@ export function isFlexBytes(b, min, max) {
|
|
|
54
49
|
* @param min Minimum size of the array
|
|
55
50
|
* @param max Maximum size of the array
|
|
56
51
|
*/
|
|
57
|
-
|
|
58
52
|
export function assertFlexBytes(b, min, max) {
|
|
59
53
|
if (!isFlexBytes(b, min, max)) {
|
|
60
54
|
throw new TypeError(`Parameter is not valid FlexBytes of min: ${min}, max: ${max}, length: ${b.length}`);
|
|
@@ -67,10 +61,9 @@ export function assertFlexBytes(b, min, max) {
|
|
|
67
61
|
* @param offset The offset to start from
|
|
68
62
|
* @param length The length of data to be returned
|
|
69
63
|
*/
|
|
70
|
-
|
|
71
64
|
export function bytesAtOffset(data, offset, length) {
|
|
72
|
-
const offsetBytes = data.slice(offset, offset + length);
|
|
73
|
-
|
|
65
|
+
const offsetBytes = data.slice(offset, offset + length);
|
|
66
|
+
// We are returning strongly typed Bytes so we have to verify that length is really what we claim
|
|
74
67
|
assertBytes(offsetBytes, length);
|
|
75
68
|
return offsetBytes;
|
|
76
69
|
}
|
|
@@ -82,9 +75,10 @@ export function bytesAtOffset(data, offset, length) {
|
|
|
82
75
|
* @param _min The minimum size of the data
|
|
83
76
|
* @param _max The maximum size of the data
|
|
84
77
|
*/
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
_min,
|
|
78
|
+
export function flexBytesAtOffset(data, offset,
|
|
79
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
80
|
+
_min,
|
|
81
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
88
82
|
_max) {
|
|
89
83
|
return data.slice(offset);
|
|
90
84
|
}
|
|
@@ -94,7 +88,6 @@ _max) {
|
|
|
94
88
|
* @param a Byte array to compare
|
|
95
89
|
* @param b Byte array to compare
|
|
96
90
|
*/
|
|
97
|
-
|
|
98
91
|
export function bytesEqual(a, b) {
|
|
99
92
|
return a.length === b.length && a.every((value, index) => value === b[index]);
|
|
100
93
|
}
|
|
@@ -103,7 +96,6 @@ export function bytesEqual(a, b) {
|
|
|
103
96
|
*
|
|
104
97
|
* @param length The length of data to be returned
|
|
105
98
|
*/
|
|
106
|
-
|
|
107
99
|
export function makeBytes(length) {
|
|
108
100
|
return new Uint8Array(length);
|
|
109
101
|
}
|
|
@@ -1,46 +1,11 @@
|
|
|
1
|
-
var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) {
|
|
3
|
-
return value instanceof P ? value : new P(function (resolve) {
|
|
4
|
-
resolve(value);
|
|
5
|
-
});
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
9
|
-
function fulfilled(value) {
|
|
10
|
-
try {
|
|
11
|
-
step(generator.next(value));
|
|
12
|
-
} catch (e) {
|
|
13
|
-
reject(e);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function rejected(value) {
|
|
18
|
-
try {
|
|
19
|
-
step(generator["throw"](value));
|
|
20
|
-
} catch (e) {
|
|
21
|
-
reject(e);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function step(result) {
|
|
26
|
-
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
1
|
/**
|
|
33
2
|
* Creates array in the format of Collection with data loaded from directory on filesystem.
|
|
34
3
|
* The function loads all the data into memory!
|
|
35
4
|
*
|
|
36
5
|
* @param dir path to the directory
|
|
37
6
|
*/
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
export function makeCollectionFromFS(dir) {
|
|
41
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
-
throw new Error('Creating Collection from File System is not supported in browsers!');
|
|
43
|
-
});
|
|
7
|
+
export async function makeCollectionFromFS(dir) {
|
|
8
|
+
throw new Error('Creating Collection from File System is not supported in browsers!');
|
|
44
9
|
}
|
|
45
10
|
/**
|
|
46
11
|
* Calculate folder size recursively
|
|
@@ -48,9 +13,6 @@ export function makeCollectionFromFS(dir) {
|
|
|
48
13
|
* @param dir the path to the folder to check
|
|
49
14
|
* @returns size in bytes
|
|
50
15
|
*/
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
-
throw new Error('Creating Collection from File System is not supported in browsers!');
|
|
55
|
-
});
|
|
16
|
+
export async function getFolderSize(dir) {
|
|
17
|
+
throw new Error('Creating Collection from File System is not supported in browsers!');
|
|
56
18
|
}
|
|
@@ -1,35 +1,3 @@
|
|
|
1
|
-
var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) {
|
|
3
|
-
return value instanceof P ? value : new P(function (resolve) {
|
|
4
|
-
resolve(value);
|
|
5
|
-
});
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
9
|
-
function fulfilled(value) {
|
|
10
|
-
try {
|
|
11
|
-
step(generator.next(value));
|
|
12
|
-
} catch (e) {
|
|
13
|
-
reject(e);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function rejected(value) {
|
|
18
|
-
try {
|
|
19
|
-
step(generator["throw"](value));
|
|
20
|
-
} catch (e) {
|
|
21
|
-
reject(e);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function step(result) {
|
|
26
|
-
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
|
-
|
|
33
1
|
import { BeeArgumentError } from "./error.js";
|
|
34
2
|
import { fileArrayBuffer } from "./file.js";
|
|
35
3
|
import { isUint8Array } from "./type.js";
|
|
@@ -37,7 +5,6 @@ export function isCollection(data) {
|
|
|
37
5
|
if (!Array.isArray(data)) {
|
|
38
6
|
return false;
|
|
39
7
|
}
|
|
40
|
-
|
|
41
8
|
return data.every(entry => typeof entry === 'object' && entry.data && entry.path && isUint8Array(entry.data));
|
|
42
9
|
}
|
|
43
10
|
export function assertCollection(data) {
|
|
@@ -45,36 +12,27 @@ export function assertCollection(data) {
|
|
|
45
12
|
throw new BeeArgumentError('invalid collection', data);
|
|
46
13
|
}
|
|
47
14
|
}
|
|
48
|
-
|
|
49
15
|
function makeFilePath(file) {
|
|
50
16
|
if (file.webkitRelativePath && file.webkitRelativePath !== '') {
|
|
51
17
|
return file.webkitRelativePath.replace(/.*?\//i, '');
|
|
52
18
|
}
|
|
53
|
-
|
|
54
19
|
if (file.name) {
|
|
55
20
|
return file.name;
|
|
56
21
|
}
|
|
57
|
-
|
|
58
22
|
throw new TypeError('file is not valid File object');
|
|
59
23
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
collection.push({
|
|
70
|
-
path: makeFilePath(file),
|
|
71
|
-
data: new Uint8Array(yield fileArrayBuffer(file))
|
|
72
|
-
});
|
|
73
|
-
}
|
|
24
|
+
export async function makeCollectionFromFileList(fileList) {
|
|
25
|
+
const collection = [];
|
|
26
|
+
for (let i = 0; i < fileList.length; i++) {
|
|
27
|
+
const file = fileList[i];
|
|
28
|
+
if (file) {
|
|
29
|
+
collection.push({
|
|
30
|
+
path: makeFilePath(file),
|
|
31
|
+
data: new Uint8Array(await fileArrayBuffer(file))
|
|
32
|
+
});
|
|
74
33
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
});
|
|
34
|
+
}
|
|
35
|
+
return collection;
|
|
78
36
|
}
|
|
79
37
|
/**
|
|
80
38
|
* Calculate cumulative size of files
|
|
@@ -82,17 +40,13 @@ export function makeCollectionFromFileList(fileList) {
|
|
|
82
40
|
* @param fileList list of files to check
|
|
83
41
|
* @returns size in bytes
|
|
84
42
|
*/
|
|
85
|
-
|
|
86
43
|
export function getCollectionSize(fileList) {
|
|
87
44
|
let sum = 0;
|
|
88
|
-
|
|
89
45
|
for (let i = 0; i < fileList.length; i++) {
|
|
90
46
|
const file = fileList[i];
|
|
91
|
-
|
|
92
47
|
if (file) {
|
|
93
48
|
sum += file.size;
|
|
94
49
|
}
|
|
95
50
|
}
|
|
96
|
-
|
|
97
51
|
return sum;
|
|
98
52
|
}
|
|
@@ -1,61 +1,3 @@
|
|
|
1
|
-
var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) {
|
|
3
|
-
return value instanceof P ? value : new P(function (resolve) {
|
|
4
|
-
resolve(value);
|
|
5
|
-
});
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
9
|
-
function fulfilled(value) {
|
|
10
|
-
try {
|
|
11
|
-
step(generator.next(value));
|
|
12
|
-
} catch (e) {
|
|
13
|
-
reject(e);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function rejected(value) {
|
|
18
|
-
try {
|
|
19
|
-
step(generator["throw"](value));
|
|
20
|
-
} catch (e) {
|
|
21
|
-
reject(e);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function step(result) {
|
|
26
|
-
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
var __asyncValues = this && this.__asyncValues || function (o) {
|
|
34
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
35
|
-
var m = o[Symbol.asyncIterator],
|
|
36
|
-
i;
|
|
37
|
-
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () {
|
|
38
|
-
return this;
|
|
39
|
-
}, i);
|
|
40
|
-
|
|
41
|
-
function verb(n) {
|
|
42
|
-
i[n] = o[n] && function (v) {
|
|
43
|
-
return new Promise(function (resolve, reject) {
|
|
44
|
-
v = o[n](v), settle(resolve, reject, v.done, v.value);
|
|
45
|
-
});
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function settle(resolve, reject, d, v) {
|
|
50
|
-
Promise.resolve(v).then(function (v) {
|
|
51
|
-
resolve({
|
|
52
|
-
value: v,
|
|
53
|
-
done: d
|
|
54
|
-
});
|
|
55
|
-
}, reject);
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
|
|
59
1
|
import fs from 'fs';
|
|
60
2
|
import path from 'path';
|
|
61
3
|
/**
|
|
@@ -64,59 +6,33 @@ import path from 'path';
|
|
|
64
6
|
*
|
|
65
7
|
* @param dir path to the directory
|
|
66
8
|
*/
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
throw new TypeError('dir must not be empty string!');
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return buildCollectionRelative(dir, '');
|
|
79
|
-
});
|
|
9
|
+
export async function makeCollectionFromFS(dir) {
|
|
10
|
+
if (typeof dir !== 'string') {
|
|
11
|
+
throw new TypeError('dir has to be string!');
|
|
12
|
+
}
|
|
13
|
+
if (dir === '') {
|
|
14
|
+
throw new TypeError('dir must not be empty string!');
|
|
15
|
+
}
|
|
16
|
+
return buildCollectionRelative(dir, '');
|
|
80
17
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
const
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
if (entry.isFile()) {
|
|
98
|
-
collection.push({
|
|
99
|
-
path: entryPath,
|
|
100
|
-
data: new Uint8Array(yield fs.promises.readFile(fullPath))
|
|
101
|
-
});
|
|
102
|
-
} else if (entry.isDirectory()) {
|
|
103
|
-
collection = [...(yield buildCollectionRelative(dir, entryPath)), ...collection];
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
} catch (e_1_1) {
|
|
107
|
-
e_1 = {
|
|
108
|
-
error: e_1_1
|
|
109
|
-
};
|
|
110
|
-
} finally {
|
|
111
|
-
try {
|
|
112
|
-
if (entries_1_1 && !entries_1_1.done && (_a = entries_1.return)) yield _a.call(entries_1);
|
|
113
|
-
} finally {
|
|
114
|
-
if (e_1) throw e_1.error;
|
|
115
|
-
}
|
|
18
|
+
async function buildCollectionRelative(dir, relativePath) {
|
|
19
|
+
// Handles case when the dir is not existing or it is a file ==> throws an error
|
|
20
|
+
const dirname = path.join(dir, relativePath);
|
|
21
|
+
const entries = await fs.promises.opendir(dirname);
|
|
22
|
+
let collection = [];
|
|
23
|
+
for await (const entry of entries) {
|
|
24
|
+
const fullPath = path.join(dir, relativePath, entry.name);
|
|
25
|
+
const entryPath = path.join(relativePath, entry.name);
|
|
26
|
+
if (entry.isFile()) {
|
|
27
|
+
collection.push({
|
|
28
|
+
path: entryPath,
|
|
29
|
+
data: new Uint8Array(await fs.promises.readFile(fullPath))
|
|
30
|
+
});
|
|
31
|
+
} else if (entry.isDirectory()) {
|
|
32
|
+
collection = [...(await buildCollectionRelative(dir, entryPath)), ...collection];
|
|
116
33
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
});
|
|
34
|
+
}
|
|
35
|
+
return collection;
|
|
120
36
|
}
|
|
121
37
|
/**
|
|
122
38
|
* Calculate folder size recursively
|
|
@@ -124,46 +40,22 @@ function buildCollectionRelative(dir, relativePath) {
|
|
|
124
40
|
* @param dir the path to the folder to check
|
|
125
41
|
* @returns size in bytes
|
|
126
42
|
*/
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
if (
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
let size = 0;
|
|
143
|
-
|
|
144
|
-
try {
|
|
145
|
-
for (var entries_2 = __asyncValues(entries), entries_2_1; entries_2_1 = yield entries_2.next(), !entries_2_1.done;) {
|
|
146
|
-
const entry = entries_2_1.value;
|
|
147
|
-
|
|
148
|
-
if (entry.isFile()) {
|
|
149
|
-
const stats = yield fs.promises.stat(path.join(dir, entry.name));
|
|
150
|
-
size += stats.size;
|
|
151
|
-
} else if (entry.isDirectory()) {
|
|
152
|
-
size += yield getFolderSize(path.join(dir, entry.name));
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
} catch (e_2_1) {
|
|
156
|
-
e_2 = {
|
|
157
|
-
error: e_2_1
|
|
158
|
-
};
|
|
159
|
-
} finally {
|
|
160
|
-
try {
|
|
161
|
-
if (entries_2_1 && !entries_2_1.done && (_a = entries_2.return)) yield _a.call(entries_2);
|
|
162
|
-
} finally {
|
|
163
|
-
if (e_2) throw e_2.error;
|
|
164
|
-
}
|
|
43
|
+
export async function getFolderSize(dir) {
|
|
44
|
+
if (typeof dir !== 'string') {
|
|
45
|
+
throw new TypeError('dir has to be string!');
|
|
46
|
+
}
|
|
47
|
+
if (dir === '') {
|
|
48
|
+
throw new TypeError('dir must not be empty string!');
|
|
49
|
+
}
|
|
50
|
+
const entries = await fs.promises.opendir(dir);
|
|
51
|
+
let size = 0;
|
|
52
|
+
for await (const entry of entries) {
|
|
53
|
+
if (entry.isFile()) {
|
|
54
|
+
const stats = await fs.promises.stat(path.join(dir, entry.name));
|
|
55
|
+
size += stats.size;
|
|
56
|
+
} else if (entry.isDirectory()) {
|
|
57
|
+
size += await getFolderSize(path.join(dir, entry.name));
|
|
165
58
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
});
|
|
59
|
+
}
|
|
60
|
+
return size;
|
|
169
61
|
}
|