@ethersphere/bee-js 3.3.2-pre.1 → 3.3.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.
- package/dist/mjs/bee-debug.js +294 -189
- package/dist/mjs/bee.js +316 -237
- package/dist/mjs/chunk/signer.js +46 -12
- package/dist/mjs/chunk/soc.js +71 -31
- package/dist/mjs/chunk/span.js +1 -1
- package/dist/mjs/feed/index.js +86 -42
- package/dist/mjs/feed/json.js +46 -10
- package/dist/mjs/index.js +2 -1
- package/dist/mjs/modules/bytes.js +61 -24
- package/dist/mjs/modules/bzz.js +96 -58
- package/dist/mjs/modules/chunk.js +51 -16
- package/dist/mjs/modules/debug/balance.js +60 -20
- package/dist/mjs/modules/debug/chequebook.js +115 -67
- package/dist/mjs/modules/debug/chunk.js +47 -11
- package/dist/mjs/modules/debug/connectivity.js +76 -32
- package/dist/mjs/modules/debug/settlements.js +46 -10
- package/dist/mjs/modules/debug/stamps.js +91 -47
- package/dist/mjs/modules/debug/states.js +48 -12
- package/dist/mjs/modules/debug/status.js +97 -49
- package/dist/mjs/modules/debug/tag.js +39 -5
- package/dist/mjs/modules/debug/transactions.js +65 -25
- package/dist/mjs/modules/feed.js +50 -16
- package/dist/mjs/modules/pinning.js +67 -27
- package/dist/mjs/modules/pss.js +44 -10
- package/dist/mjs/modules/soc.js +47 -14
- package/dist/mjs/modules/status.js +37 -3
- package/dist/mjs/modules/stewardship.js +46 -10
- package/dist/mjs/modules/tag.js +73 -31
- package/dist/mjs/utils/collection.browser.js +41 -4
- package/dist/mjs/utils/collection.js +45 -11
- package/dist/mjs/utils/collection.node.js +137 -42
- package/dist/mjs/utils/data.browser.js +88 -52
- package/dist/mjs/utils/data.js +57 -21
- package/dist/mjs/utils/error.js +0 -9
- package/dist/mjs/utils/eth.js +68 -32
- package/dist/mjs/utils/file.js +42 -8
- package/dist/mjs/utils/headers.js +4 -4
- package/dist/mjs/utils/http.js +110 -64
- package/dist/mjs/utils/merge.js +2 -2
- package/dist/mjs/utils/stream.js +0 -4
- package/dist/mjs/utils/type.js +6 -6
- package/package.json +2 -2
package/dist/mjs/modules/soc.js
CHANGED
|
@@ -1,3 +1,35 @@
|
|
|
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
|
import { extractUploadHeaders } from "../utils/headers.js";
|
|
2
34
|
import { http } from "../utils/http.js";
|
|
3
35
|
const socEndpoint = 'soc';
|
|
@@ -13,19 +45,20 @@ const socEndpoint = 'soc';
|
|
|
13
45
|
* @param options Additional options like tag, encryption, pinning
|
|
14
46
|
*/
|
|
15
47
|
|
|
16
|
-
export
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
48
|
+
export function upload(ky, owner, identifier, signature, data, postageBatchId, options) {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
const response = yield http(ky, {
|
|
51
|
+
method: 'post',
|
|
52
|
+
path: `${socEndpoint}/${owner}/${identifier}`,
|
|
53
|
+
body: data,
|
|
54
|
+
headers: Object.assign({
|
|
55
|
+
'content-type': 'application/octet-stream'
|
|
56
|
+
}, extractUploadHeaders(postageBatchId, options)),
|
|
57
|
+
responseType: 'json',
|
|
58
|
+
searchParams: {
|
|
59
|
+
sig: signature
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
return response.data.reference;
|
|
29
63
|
});
|
|
30
|
-
return response.data.reference;
|
|
31
64
|
}
|
|
@@ -1,3 +1,35 @@
|
|
|
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
|
import { http } from "../utils/http.js";
|
|
2
34
|
/**
|
|
3
35
|
* Ping the base bee URL. If connection was not successful throw error
|
|
@@ -5,8 +37,10 @@ import { http } from "../utils/http.js";
|
|
|
5
37
|
* @param ky Ky instance for given Bee class instance
|
|
6
38
|
*/
|
|
7
39
|
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
|
|
40
|
+
export function checkConnection(ky) {
|
|
41
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
yield http(ky, {
|
|
43
|
+
path: ''
|
|
44
|
+
});
|
|
11
45
|
});
|
|
12
46
|
}
|
|
@@ -1,3 +1,35 @@
|
|
|
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
|
import { http } from "../utils/http.js";
|
|
2
34
|
const stewardshipEndpoint = 'stewardship';
|
|
3
35
|
/**
|
|
@@ -8,17 +40,21 @@ const stewardshipEndpoint = 'stewardship';
|
|
|
8
40
|
* @throws BeeResponseError if not locally pinned or invalid data
|
|
9
41
|
*/
|
|
10
42
|
|
|
11
|
-
export
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
43
|
+
export function reupload(ky, reference) {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
yield http(ky, {
|
|
46
|
+
method: 'put',
|
|
47
|
+
path: `${stewardshipEndpoint}/${reference}`
|
|
48
|
+
});
|
|
15
49
|
});
|
|
16
50
|
}
|
|
17
|
-
export
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
51
|
+
export function isRetrievable(ky, reference) {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
const response = yield http(ky, {
|
|
54
|
+
method: 'get',
|
|
55
|
+
responseType: 'json',
|
|
56
|
+
path: `${stewardshipEndpoint}/${reference}`
|
|
57
|
+
});
|
|
58
|
+
return response.data.isRetrievable;
|
|
22
59
|
});
|
|
23
|
-
return response.data.isRetrievable;
|
|
24
60
|
}
|
package/dist/mjs/modules/tag.js
CHANGED
|
@@ -1,3 +1,35 @@
|
|
|
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
|
import { http } from "../utils/http.js";
|
|
2
34
|
const endpoint = 'tags';
|
|
3
35
|
/**
|
|
@@ -6,13 +38,15 @@ const endpoint = 'tags';
|
|
|
6
38
|
* @param url Bee tag URL
|
|
7
39
|
*/
|
|
8
40
|
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
41
|
+
export function createTag(ky) {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
const response = yield http(ky, {
|
|
44
|
+
method: 'post',
|
|
45
|
+
path: endpoint,
|
|
46
|
+
responseType: 'json'
|
|
47
|
+
});
|
|
48
|
+
return response.data;
|
|
14
49
|
});
|
|
15
|
-
return response.data;
|
|
16
50
|
}
|
|
17
51
|
/**
|
|
18
52
|
* Retrieve tag information from Bee node
|
|
@@ -21,12 +55,14 @@ export async function createTag(ky) {
|
|
|
21
55
|
* @param uid UID of tag to be retrieved
|
|
22
56
|
*/
|
|
23
57
|
|
|
24
|
-
export
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
58
|
+
export function retrieveTag(ky, uid) {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
const response = yield http(ky, {
|
|
61
|
+
path: `${endpoint}/${uid}`,
|
|
62
|
+
responseType: 'json'
|
|
63
|
+
});
|
|
64
|
+
return response.data;
|
|
28
65
|
});
|
|
29
|
-
return response.data;
|
|
30
66
|
}
|
|
31
67
|
/**
|
|
32
68
|
* Get limited listing of all tags.
|
|
@@ -36,16 +72,18 @@ export async function retrieveTag(ky, uid) {
|
|
|
36
72
|
* @param limit
|
|
37
73
|
*/
|
|
38
74
|
|
|
39
|
-
export
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
75
|
+
export function getAllTags(ky, offset, limit) {
|
|
76
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
const response = yield http(ky, {
|
|
78
|
+
path: `${endpoint}`,
|
|
79
|
+
searchParams: {
|
|
80
|
+
offset,
|
|
81
|
+
limit
|
|
82
|
+
},
|
|
83
|
+
responseType: 'json'
|
|
84
|
+
});
|
|
85
|
+
return response.data.tags;
|
|
47
86
|
});
|
|
48
|
-
return response.data.tags;
|
|
49
87
|
}
|
|
50
88
|
/**
|
|
51
89
|
* Removes tag from the Bee node.
|
|
@@ -53,10 +91,12 @@ export async function getAllTags(ky, offset, limit) {
|
|
|
53
91
|
* @param uid
|
|
54
92
|
*/
|
|
55
93
|
|
|
56
|
-
export
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
94
|
+
export function deleteTag(ky, uid) {
|
|
95
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
+
yield http(ky, {
|
|
97
|
+
method: 'delete',
|
|
98
|
+
path: `${endpoint}/${uid}`
|
|
99
|
+
});
|
|
60
100
|
});
|
|
61
101
|
}
|
|
62
102
|
/**
|
|
@@ -66,12 +106,14 @@ export async function deleteTag(ky, uid) {
|
|
|
66
106
|
* @param reference
|
|
67
107
|
*/
|
|
68
108
|
|
|
69
|
-
export
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
109
|
+
export function updateTag(ky, uid, reference) {
|
|
110
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
111
|
+
yield http(ky, {
|
|
112
|
+
method: 'patch',
|
|
113
|
+
path: `${endpoint}/${uid}`,
|
|
114
|
+
json: {
|
|
115
|
+
reference
|
|
116
|
+
}
|
|
117
|
+
});
|
|
76
118
|
});
|
|
77
119
|
}
|
|
@@ -1,11 +1,46 @@
|
|
|
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
|
+
};
|
|
1
32
|
/**
|
|
2
33
|
* Creates array in the format of Collection with data loaded from directory on filesystem.
|
|
3
34
|
* The function loads all the data into memory!
|
|
4
35
|
*
|
|
5
36
|
* @param dir path to the directory
|
|
6
37
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
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
|
+
});
|
|
9
44
|
}
|
|
10
45
|
/**
|
|
11
46
|
* Calculate folder size recursively
|
|
@@ -14,6 +49,8 @@ export async function makeCollectionFromFS(dir) {
|
|
|
14
49
|
* @returns size in bytes
|
|
15
50
|
*/
|
|
16
51
|
|
|
17
|
-
export
|
|
18
|
-
|
|
52
|
+
export function getFolderSize(dir) {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
throw new Error('Creating Collection from File System is not supported in browsers!');
|
|
55
|
+
});
|
|
19
56
|
}
|
|
@@ -1,3 +1,35 @@
|
|
|
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
|
import { BeeArgumentError } from "./error.js";
|
|
2
34
|
import { fileArrayBuffer } from "./file.js";
|
|
3
35
|
import { isUint8Array } from "./type.js";
|
|
@@ -26,21 +58,23 @@ function makeFilePath(file) {
|
|
|
26
58
|
throw new TypeError('file is not valid File object');
|
|
27
59
|
}
|
|
28
60
|
|
|
29
|
-
export
|
|
30
|
-
|
|
61
|
+
export function makeCollectionFromFileList(fileList) {
|
|
62
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
const collection = [];
|
|
31
64
|
|
|
32
|
-
|
|
33
|
-
|
|
65
|
+
for (let i = 0; i < fileList.length; i++) {
|
|
66
|
+
const file = fileList[i];
|
|
34
67
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
68
|
+
if (file) {
|
|
69
|
+
collection.push({
|
|
70
|
+
path: makeFilePath(file),
|
|
71
|
+
data: new Uint8Array(yield fileArrayBuffer(file))
|
|
72
|
+
});
|
|
73
|
+
}
|
|
40
74
|
}
|
|
41
|
-
}
|
|
42
75
|
|
|
43
|
-
|
|
76
|
+
return collection;
|
|
77
|
+
});
|
|
44
78
|
}
|
|
45
79
|
/**
|
|
46
80
|
* Calculate cumulative size of files
|
|
@@ -1,3 +1,61 @@
|
|
|
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
|
+
|
|
1
59
|
import fs from 'fs';
|
|
2
60
|
import path from 'path';
|
|
3
61
|
/**
|
|
@@ -7,39 +65,58 @@ import path from 'path';
|
|
|
7
65
|
* @param dir path to the directory
|
|
8
66
|
*/
|
|
9
67
|
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
68
|
+
export function makeCollectionFromFS(dir) {
|
|
69
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
+
if (typeof dir !== 'string') {
|
|
71
|
+
throw new TypeError('dir has to be string!');
|
|
72
|
+
}
|
|
14
73
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
74
|
+
if (dir === '') {
|
|
75
|
+
throw new TypeError('dir must not be empty string!');
|
|
76
|
+
}
|
|
18
77
|
|
|
19
|
-
|
|
78
|
+
return buildCollectionRelative(dir, '');
|
|
79
|
+
});
|
|
20
80
|
}
|
|
21
81
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const dirname = path.join(dir, relativePath);
|
|
25
|
-
const entries = await fs.promises.opendir(dirname);
|
|
26
|
-
let collection = [];
|
|
82
|
+
function buildCollectionRelative(dir, relativePath) {
|
|
83
|
+
var e_1, _a;
|
|
27
84
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const
|
|
85
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
// Handles case when the dir is not existing or it is a file ==> throws an error
|
|
87
|
+
const dirname = path.join(dir, relativePath);
|
|
88
|
+
const entries = yield fs.promises.opendir(dirname);
|
|
89
|
+
let collection = [];
|
|
31
90
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
91
|
+
try {
|
|
92
|
+
for (var entries_1 = __asyncValues(entries), entries_1_1; entries_1_1 = yield entries_1.next(), !entries_1_1.done;) {
|
|
93
|
+
const entry = entries_1_1.value;
|
|
94
|
+
const fullPath = path.join(dir, relativePath, entry.name);
|
|
95
|
+
const entryPath = path.join(relativePath, entry.name);
|
|
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
|
+
}
|
|
39
116
|
}
|
|
40
|
-
}
|
|
41
117
|
|
|
42
|
-
|
|
118
|
+
return collection;
|
|
119
|
+
});
|
|
43
120
|
}
|
|
44
121
|
/**
|
|
45
122
|
* Calculate folder size recursively
|
|
@@ -49,26 +126,44 @@ async function buildCollectionRelative(dir, relativePath) {
|
|
|
49
126
|
*/
|
|
50
127
|
|
|
51
128
|
|
|
52
|
-
export
|
|
53
|
-
|
|
54
|
-
throw new TypeError('dir has to be string!');
|
|
55
|
-
}
|
|
129
|
+
export function getFolderSize(dir) {
|
|
130
|
+
var e_2, _a;
|
|
56
131
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
132
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
133
|
+
if (typeof dir !== 'string') {
|
|
134
|
+
throw new TypeError('dir has to be string!');
|
|
135
|
+
}
|
|
60
136
|
|
|
61
|
-
|
|
62
|
-
|
|
137
|
+
if (dir === '') {
|
|
138
|
+
throw new TypeError('dir must not be empty string!');
|
|
139
|
+
}
|
|
63
140
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
141
|
+
const entries = yield fs.promises.opendir(dir);
|
|
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
|
+
}
|
|
70
165
|
}
|
|
71
|
-
}
|
|
72
166
|
|
|
73
|
-
|
|
167
|
+
return size;
|
|
168
|
+
});
|
|
74
169
|
}
|