@ethersphere/bee-js 3.2.0 → 3.3.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/dist/cjs/bee-debug.js +615 -0
- package/dist/cjs/bee.js +922 -0
- package/dist/cjs/chunk/bmt.js +50 -0
- package/dist/cjs/chunk/cac.js +56 -0
- package/dist/cjs/chunk/serialize.js +19 -0
- package/dist/cjs/chunk/signer.js +132 -0
- package/dist/cjs/chunk/soc.js +172 -0
- package/dist/cjs/chunk/span.js +29 -0
- package/dist/cjs/feed/index.js +184 -0
- package/dist/cjs/feed/json.js +41 -0
- package/dist/cjs/feed/topic.js +25 -0
- package/dist/cjs/feed/type.js +15 -0
- package/dist/cjs/index.js +35 -0
- package/dist/cjs/modules/bytes.js +74 -0
- package/dist/cjs/modules/bzz.js +131 -0
- package/dist/cjs/modules/chunk.js +58 -0
- package/dist/cjs/modules/debug/balance.js +77 -0
- package/dist/cjs/modules/debug/chequebook.js +167 -0
- package/dist/cjs/modules/debug/chunk.js +51 -0
- package/dist/cjs/modules/debug/connectivity.js +75 -0
- package/dist/cjs/modules/debug/settlements.js +45 -0
- package/dist/cjs/modules/debug/stamps.js +89 -0
- package/dist/cjs/modules/debug/states.js +47 -0
- package/dist/cjs/modules/debug/status.js +153 -0
- package/dist/cjs/modules/debug/tag.js +30 -0
- package/dist/cjs/modules/debug/transactions.js +81 -0
- package/dist/cjs/modules/feed.js +76 -0
- package/dist/cjs/modules/pinning.js +84 -0
- package/dist/cjs/modules/pss.js +55 -0
- package/dist/cjs/modules/soc.js +40 -0
- package/dist/cjs/modules/status.js +26 -0
- package/dist/cjs/modules/stewardship.js +41 -0
- package/dist/cjs/modules/tag.js +96 -0
- package/dist/cjs/package.json +7 -0
- package/dist/cjs/types/debug.js +9 -0
- package/dist/cjs/types/index.js +46 -0
- package/dist/cjs/utils/bytes.js +107 -0
- package/dist/cjs/utils/collection.browser.js +36 -0
- package/dist/cjs/utils/collection.js +70 -0
- package/dist/cjs/utils/collection.node.js +115 -0
- package/dist/cjs/utils/data.browser.js +78 -0
- package/dist/cjs/utils/data.js +60 -0
- package/dist/cjs/utils/error.js +50 -0
- package/dist/cjs/utils/eth.js +206 -0
- package/dist/cjs/utils/expose.js +44 -0
- package/dist/cjs/utils/file.js +49 -0
- package/dist/cjs/utils/hash.js +16 -0
- package/dist/cjs/utils/headers.js +59 -0
- package/dist/cjs/utils/hex.js +150 -0
- package/dist/cjs/utils/http.js +166 -0
- package/dist/cjs/utils/merge.js +34 -0
- package/dist/cjs/utils/pss.js +18 -0
- package/dist/cjs/utils/stamps.js +17 -0
- package/dist/cjs/utils/stream.js +137 -0
- package/dist/cjs/utils/tar.js +25 -0
- package/dist/cjs/utils/type.js +327 -0
- package/dist/cjs/utils/uint64.js +29 -0
- package/dist/cjs/utils/url.js +56 -0
- package/dist/index.js +28326 -0
- package/dist/index.js.map +1 -0
- package/dist/mjs/bee-debug.js +509 -0
- package/dist/mjs/bee.js +845 -0
- package/dist/mjs/chunk/bmt.js +46 -0
- package/dist/mjs/chunk/cac.js +50 -0
- package/dist/mjs/chunk/serialize.js +15 -0
- package/dist/mjs/chunk/signer.js +112 -0
- package/dist/mjs/chunk/soc.js +127 -0
- package/dist/mjs/chunk/span.js +25 -0
- package/dist/mjs/feed/index.js +136 -0
- package/dist/mjs/feed/json.js +23 -0
- package/dist/mjs/feed/topic.js +20 -0
- package/dist/mjs/feed/type.js +10 -0
- package/dist/mjs/index.js +7 -0
- package/dist/mjs/modules/bytes.js +56 -0
- package/dist/mjs/modules/bzz.js +119 -0
- package/dist/mjs/modules/chunk.js +43 -0
- package/dist/mjs/modules/debug/balance.js +53 -0
- package/dist/mjs/modules/debug/chequebook.js +131 -0
- package/dist/mjs/modules/debug/chunk.js +33 -0
- package/dist/mjs/modules/debug/connectivity.js +45 -0
- package/dist/mjs/modules/debug/settlements.js +27 -0
- package/dist/mjs/modules/debug/stamps.js +59 -0
- package/dist/mjs/modules/debug/states.js +29 -0
- package/dist/mjs/modules/debug/status.js +114 -0
- package/dist/mjs/modules/debug/tag.js +15 -0
- package/dist/mjs/modules/debug/transactions.js +57 -0
- package/dist/mjs/modules/feed.js +61 -0
- package/dist/mjs/modules/pinning.js +60 -0
- package/dist/mjs/modules/pss.js +36 -0
- package/dist/mjs/modules/soc.js +28 -0
- package/dist/mjs/modules/status.js +11 -0
- package/dist/mjs/modules/stewardship.js +23 -0
- package/dist/mjs/modules/tag.js +69 -0
- package/dist/mjs/package.json +7 -0
- package/dist/mjs/types/debug.js +6 -0
- package/dist/mjs/types/index.js +33 -0
- package/dist/mjs/utils/bytes.js +95 -0
- package/dist/mjs/utils/collection.browser.js +18 -0
- package/dist/mjs/utils/collection.js +52 -0
- package/dist/mjs/utils/collection.node.js +63 -0
- package/dist/mjs/utils/data.browser.js +57 -0
- package/dist/mjs/utils/data.js +39 -0
- package/dist/mjs/utils/error.js +48 -0
- package/dist/mjs/utils/eth.js +184 -0
- package/dist/mjs/utils/expose.js +9 -0
- package/dist/mjs/utils/file.js +33 -0
- package/dist/mjs/utils/hash.js +12 -0
- package/dist/mjs/utils/headers.js +54 -0
- package/dist/mjs/utils/hex.js +139 -0
- package/dist/mjs/utils/http.js +136 -0
- package/dist/mjs/utils/merge.js +30 -0
- package/dist/mjs/utils/pss.js +14 -0
- package/dist/mjs/utils/stamps.js +13 -0
- package/dist/mjs/utils/stream.js +131 -0
- package/dist/mjs/utils/tar.js +18 -0
- package/dist/mjs/utils/type.js +296 -0
- package/dist/mjs/utils/uint64.js +23 -0
- package/dist/mjs/utils/url.js +50 -0
- package/dist/{src → types}/bee-debug.d.ts +47 -1
- package/dist/{src → types}/bee.d.ts +0 -0
- package/dist/{src → types}/chunk/bmt.d.ts +0 -0
- package/dist/{src → types}/chunk/cac.d.ts +0 -0
- package/dist/{src → types}/chunk/serialize.d.ts +0 -0
- package/dist/{src → types}/chunk/signer.d.ts +0 -0
- package/dist/{src → types}/chunk/soc.d.ts +0 -0
- package/dist/{src → types}/chunk/span.d.ts +0 -0
- package/dist/{src → types}/feed/index.d.ts +0 -0
- package/dist/{src → types}/feed/json.d.ts +0 -0
- package/dist/{src → types}/feed/topic.d.ts +0 -0
- package/dist/{src → types}/feed/type.d.ts +0 -0
- package/dist/{src → types}/index.d.ts +0 -0
- package/dist/{src → types}/modules/bytes.d.ts +0 -0
- package/dist/{src → types}/modules/bzz.d.ts +0 -0
- package/dist/{src → types}/modules/chunk.d.ts +0 -0
- package/dist/{src → types}/modules/debug/balance.d.ts +0 -0
- package/dist/{src → types}/modules/debug/chequebook.d.ts +0 -0
- package/dist/{src → types}/modules/debug/chunk.d.ts +0 -0
- package/dist/{src → types}/modules/debug/connectivity.d.ts +0 -0
- package/dist/{src → types}/modules/debug/settlements.d.ts +0 -0
- package/dist/{src → types}/modules/debug/stamps.d.ts +0 -0
- package/dist/{src → types}/modules/debug/states.d.ts +0 -0
- package/dist/types/modules/debug/status.d.ts +72 -0
- package/dist/{src → types}/modules/debug/tag.d.ts +0 -0
- package/dist/{src → types}/modules/debug/transactions.d.ts +0 -0
- package/dist/{src → types}/modules/feed.d.ts +0 -0
- package/dist/{src → types}/modules/pinning.d.ts +0 -0
- package/dist/{src → types}/modules/pss.d.ts +0 -0
- package/dist/{src → types}/modules/soc.d.ts +0 -0
- package/dist/{src → types}/modules/status.d.ts +0 -0
- package/dist/{src → types}/modules/stewardship.d.ts +0 -0
- package/dist/{src → types}/modules/tag.d.ts +0 -0
- package/dist/{src → types}/types/debug.d.ts +8 -0
- package/dist/{src → types}/types/index.d.ts +1 -0
- package/dist/{src → types}/utils/bytes.d.ts +0 -0
- package/dist/types/utils/collection.browser.d.ts +15 -0
- package/dist/{src → types}/utils/collection.d.ts +0 -14
- package/dist/types/utils/collection.node.d.ts +15 -0
- package/dist/{src → types}/utils/data.browser.d.ts +0 -0
- package/dist/{src → types}/utils/data.d.ts +0 -0
- package/dist/{src → types}/utils/error.d.ts +0 -0
- package/dist/{src → types}/utils/eth.d.ts +0 -0
- package/dist/{src → types}/utils/expose.d.ts +2 -1
- package/dist/{src → types}/utils/file.d.ts +0 -0
- package/dist/{src → types}/utils/hash.d.ts +0 -0
- package/dist/{src → types}/utils/headers.d.ts +0 -0
- package/dist/{src → types}/utils/hex.d.ts +0 -0
- package/dist/{src → types}/utils/http.d.ts +0 -0
- package/dist/{src → types}/utils/merge.d.ts +0 -0
- package/dist/{src → types}/utils/pss.d.ts +0 -0
- package/dist/{src → types}/utils/stamps.d.ts +0 -0
- package/dist/{src → types}/utils/stream.d.ts +0 -0
- package/dist/{src → types}/utils/tar.d.ts +0 -0
- package/dist/{src → types}/utils/type.d.ts +0 -0
- package/dist/{src → types}/utils/uint64.d.ts +0 -0
- package/dist/{src → types}/utils/url.d.ts +0 -0
- package/package.json +39 -23
- package/dist/index.browser.min.js +0 -3
- package/dist/index.browser.min.js.LICENSE.txt +0 -59
- package/dist/index.browser.min.js.map +0 -1
- package/dist/index.min.js +0 -3
- package/dist/index.min.js.LICENSE.txt +0 -50
- package/dist/index.min.js.map +0 -1
- package/dist/src/modules/debug/status.d.ts +0 -24
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.subscribe = exports.send = void 0;
|
|
16
|
+
const isomorphic_ws_1 = __importDefault(require("isomorphic-ws"));
|
|
17
|
+
const data_1 = require("../utils/data");
|
|
18
|
+
const http_1 = require("../utils/http");
|
|
19
|
+
const headers_1 = require("../utils/headers");
|
|
20
|
+
const endpoint = 'pss';
|
|
21
|
+
/**
|
|
22
|
+
* Send to recipient or target with Postal Service for Swarm
|
|
23
|
+
*
|
|
24
|
+
* @param ky Ky instance for given Bee class instance
|
|
25
|
+
* @param topic Topic name
|
|
26
|
+
* @param target Target message address prefix
|
|
27
|
+
* @param data
|
|
28
|
+
* @param postageBatchId Postage BatchId that will be assigned to sent message
|
|
29
|
+
* @param recipient Recipient public key
|
|
30
|
+
*
|
|
31
|
+
*/
|
|
32
|
+
function send(ky, topic, target, data, postageBatchId, recipient) {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
yield (0, http_1.http)(ky, {
|
|
35
|
+
method: 'post',
|
|
36
|
+
path: `${endpoint}/send/${topic}/${target}`,
|
|
37
|
+
body: yield (0, data_1.prepareData)(data),
|
|
38
|
+
responseType: 'json',
|
|
39
|
+
searchParams: { recipient },
|
|
40
|
+
headers: (0, headers_1.extractUploadHeaders)(postageBatchId),
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
exports.send = send;
|
|
45
|
+
/**
|
|
46
|
+
* Subscribe for messages on the given topic
|
|
47
|
+
*
|
|
48
|
+
* @param url Bee node URL
|
|
49
|
+
* @param topic Topic name
|
|
50
|
+
*/
|
|
51
|
+
function subscribe(url, topic) {
|
|
52
|
+
const wsUrl = url.replace(/^http/i, 'ws');
|
|
53
|
+
return new isomorphic_ws_1.default(`${wsUrl}/${endpoint}/subscribe/${topic}`);
|
|
54
|
+
}
|
|
55
|
+
exports.subscribe = subscribe;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.upload = void 0;
|
|
13
|
+
const headers_1 = require("../utils/headers");
|
|
14
|
+
const http_1 = require("../utils/http");
|
|
15
|
+
const socEndpoint = 'soc';
|
|
16
|
+
/**
|
|
17
|
+
* Upload single owner chunk (SOC) to a Bee node
|
|
18
|
+
*
|
|
19
|
+
* @param ky Ky instance
|
|
20
|
+
* @param owner Owner's ethereum address in hex
|
|
21
|
+
* @param identifier Arbitrary identifier in hex
|
|
22
|
+
* @param signature Signature in hex
|
|
23
|
+
* @param data Content addressed chunk data to be uploaded
|
|
24
|
+
* @param postageBatchId Postage BatchId that will be assigned to uploaded data
|
|
25
|
+
* @param options Additional options like tag, encryption, pinning
|
|
26
|
+
*/
|
|
27
|
+
function upload(ky, owner, identifier, signature, data, postageBatchId, options) {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
const response = yield (0, http_1.http)(ky, {
|
|
30
|
+
method: 'post',
|
|
31
|
+
path: `${socEndpoint}/${owner}/${identifier}`,
|
|
32
|
+
body: data,
|
|
33
|
+
headers: Object.assign({ 'content-type': 'application/octet-stream' }, (0, headers_1.extractUploadHeaders)(postageBatchId, options)),
|
|
34
|
+
responseType: 'json',
|
|
35
|
+
searchParams: { sig: signature },
|
|
36
|
+
});
|
|
37
|
+
return response.data.reference;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
exports.upload = upload;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.checkConnection = void 0;
|
|
13
|
+
const http_1 = require("../utils/http");
|
|
14
|
+
/**
|
|
15
|
+
* Ping the base bee URL. If connection was not successful throw error
|
|
16
|
+
*
|
|
17
|
+
* @param ky Ky instance for given Bee class instance
|
|
18
|
+
*/
|
|
19
|
+
function checkConnection(ky) {
|
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
yield (0, http_1.http)(ky, {
|
|
22
|
+
path: '',
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
exports.checkConnection = checkConnection;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.isRetrievable = exports.reupload = void 0;
|
|
13
|
+
const http_1 = require("../utils/http");
|
|
14
|
+
const stewardshipEndpoint = 'stewardship';
|
|
15
|
+
/**
|
|
16
|
+
* Reupload locally pinned data
|
|
17
|
+
* @param ky Ky instance
|
|
18
|
+
* @param reference
|
|
19
|
+
* @param options
|
|
20
|
+
* @throws BeeResponseError if not locally pinned or invalid data
|
|
21
|
+
*/
|
|
22
|
+
function reupload(ky, reference) {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
yield (0, http_1.http)(ky, {
|
|
25
|
+
method: 'put',
|
|
26
|
+
path: `${stewardshipEndpoint}/${reference}`,
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
exports.reupload = reupload;
|
|
31
|
+
function isRetrievable(ky, reference) {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
const response = yield (0, http_1.http)(ky, {
|
|
34
|
+
method: 'get',
|
|
35
|
+
responseType: 'json',
|
|
36
|
+
path: `${stewardshipEndpoint}/${reference}`,
|
|
37
|
+
});
|
|
38
|
+
return response.data.isRetrievable;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
exports.isRetrievable = isRetrievable;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.updateTag = exports.deleteTag = exports.getAllTags = exports.retrieveTag = exports.createTag = void 0;
|
|
13
|
+
const http_1 = require("../utils/http");
|
|
14
|
+
const endpoint = 'tags';
|
|
15
|
+
/**
|
|
16
|
+
* Create new tag on the Bee node
|
|
17
|
+
*
|
|
18
|
+
* @param url Bee tag URL
|
|
19
|
+
*/
|
|
20
|
+
function createTag(ky) {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
const response = yield (0, http_1.http)(ky, {
|
|
23
|
+
method: 'post',
|
|
24
|
+
path: endpoint,
|
|
25
|
+
responseType: 'json',
|
|
26
|
+
});
|
|
27
|
+
return response.data;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
exports.createTag = createTag;
|
|
31
|
+
/**
|
|
32
|
+
* Retrieve tag information from Bee node
|
|
33
|
+
*
|
|
34
|
+
* @param url Bee tag URL
|
|
35
|
+
* @param uid UID of tag to be retrieved
|
|
36
|
+
*/
|
|
37
|
+
function retrieveTag(ky, uid) {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
const response = yield (0, http_1.http)(ky, {
|
|
40
|
+
path: `${endpoint}/${uid}`,
|
|
41
|
+
responseType: 'json',
|
|
42
|
+
});
|
|
43
|
+
return response.data;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
exports.retrieveTag = retrieveTag;
|
|
47
|
+
/**
|
|
48
|
+
* Get limited listing of all tags.
|
|
49
|
+
*
|
|
50
|
+
* @param url
|
|
51
|
+
* @param offset
|
|
52
|
+
* @param limit
|
|
53
|
+
*/
|
|
54
|
+
function getAllTags(ky, offset, limit) {
|
|
55
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
const response = yield (0, http_1.http)(ky, {
|
|
57
|
+
path: `${endpoint}`,
|
|
58
|
+
searchParams: { offset, limit },
|
|
59
|
+
responseType: 'json',
|
|
60
|
+
});
|
|
61
|
+
return response.data.tags;
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
exports.getAllTags = getAllTags;
|
|
65
|
+
/**
|
|
66
|
+
* Removes tag from the Bee node.
|
|
67
|
+
* @param url
|
|
68
|
+
* @param uid
|
|
69
|
+
*/
|
|
70
|
+
function deleteTag(ky, uid) {
|
|
71
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
yield (0, http_1.http)(ky, {
|
|
73
|
+
method: 'delete',
|
|
74
|
+
path: `${endpoint}/${uid}`,
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
exports.deleteTag = deleteTag;
|
|
79
|
+
/**
|
|
80
|
+
* Updates tag
|
|
81
|
+
* @param url
|
|
82
|
+
* @param uid
|
|
83
|
+
* @param reference
|
|
84
|
+
*/
|
|
85
|
+
function updateTag(ky, uid, reference) {
|
|
86
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
+
yield (0, http_1.http)(ky, {
|
|
88
|
+
method: 'patch',
|
|
89
|
+
path: `${endpoint}/${uid}`,
|
|
90
|
+
json: {
|
|
91
|
+
reference,
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
exports.updateTag = updateTag;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BeeModes = void 0;
|
|
4
|
+
var BeeModes;
|
|
5
|
+
(function (BeeModes) {
|
|
6
|
+
BeeModes["FULL"] = "full";
|
|
7
|
+
BeeModes["LIGHT"] = "light";
|
|
8
|
+
BeeModes["DEV"] = "dev";
|
|
9
|
+
})(BeeModes = exports.BeeModes || (exports.BeeModes = {}));
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.SIGNATURE_BYTES_LENGTH = exports.SIGNATURE_HEX_LENGTH = exports.TOPIC_HEX_LENGTH = exports.TOPIC_BYTES_LENGTH = exports.TAGS_LIMIT_MAX = exports.TAGS_LIMIT_MIN = exports.STAMPS_DEPTH_MAX = exports.STAMPS_DEPTH_MIN = exports.ENCRYPTED_REFERENCE_BYTES_LENGTH = exports.REFERENCE_BYTES_LENGTH = exports.ENCRYPTED_REFERENCE_HEX_LENGTH = exports.REFERENCE_HEX_LENGTH = exports.BATCH_ID_HEX_LENGTH = exports.PUBKEY_HEX_LENGTH = exports.PSS_TARGET_HEX_LENGTH_MAX = exports.ADDRESS_HEX_LENGTH = exports.CHUNK_SIZE = exports.BRANCHES = exports.SECTION_SIZE = exports.SPAN_SIZE = void 0;
|
|
14
|
+
__exportStar(require("./debug"), exports);
|
|
15
|
+
exports.SPAN_SIZE = 8;
|
|
16
|
+
exports.SECTION_SIZE = 32;
|
|
17
|
+
exports.BRANCHES = 128;
|
|
18
|
+
exports.CHUNK_SIZE = exports.SECTION_SIZE * exports.BRANCHES;
|
|
19
|
+
exports.ADDRESS_HEX_LENGTH = 64;
|
|
20
|
+
exports.PSS_TARGET_HEX_LENGTH_MAX = 6;
|
|
21
|
+
exports.PUBKEY_HEX_LENGTH = 66;
|
|
22
|
+
exports.BATCH_ID_HEX_LENGTH = 64;
|
|
23
|
+
exports.REFERENCE_HEX_LENGTH = 64;
|
|
24
|
+
exports.ENCRYPTED_REFERENCE_HEX_LENGTH = 128;
|
|
25
|
+
exports.REFERENCE_BYTES_LENGTH = 32;
|
|
26
|
+
exports.ENCRYPTED_REFERENCE_BYTES_LENGTH = 64;
|
|
27
|
+
/**
|
|
28
|
+
* Minimal depth that can be used for creation of postage batch
|
|
29
|
+
*/
|
|
30
|
+
exports.STAMPS_DEPTH_MIN = 17;
|
|
31
|
+
/**
|
|
32
|
+
* Maximal depth that can be used for creation of postage batch
|
|
33
|
+
*/
|
|
34
|
+
exports.STAMPS_DEPTH_MAX = 255;
|
|
35
|
+
exports.TAGS_LIMIT_MIN = 1;
|
|
36
|
+
exports.TAGS_LIMIT_MAX = 1000;
|
|
37
|
+
/*********************************************************
|
|
38
|
+
* Writers and Readers interfaces
|
|
39
|
+
*/
|
|
40
|
+
exports.TOPIC_BYTES_LENGTH = 32;
|
|
41
|
+
exports.TOPIC_HEX_LENGTH = 64;
|
|
42
|
+
/*********************************************************
|
|
43
|
+
* Ethereum compatible signing interfaces and definitions
|
|
44
|
+
*/
|
|
45
|
+
exports.SIGNATURE_HEX_LENGTH = 130;
|
|
46
|
+
exports.SIGNATURE_BYTES_LENGTH = 65;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.wrapBytesWithHelpers = exports.makeBytes = exports.bytesEqual = exports.flexBytesAtOffset = exports.bytesAtOffset = exports.assertFlexBytes = exports.isFlexBytes = exports.assertBytes = exports.isBytes = void 0;
|
|
4
|
+
const hex_1 = require("./hex");
|
|
5
|
+
/**
|
|
6
|
+
* Type guard for `Bytes<T>` type
|
|
7
|
+
*
|
|
8
|
+
* @param b The byte array
|
|
9
|
+
* @param length The length of the byte array
|
|
10
|
+
*/
|
|
11
|
+
function isBytes(b, length) {
|
|
12
|
+
return b instanceof Uint8Array && b.length === length;
|
|
13
|
+
}
|
|
14
|
+
exports.isBytes = isBytes;
|
|
15
|
+
/**
|
|
16
|
+
* Verifies if a byte array has a certain length
|
|
17
|
+
*
|
|
18
|
+
* @param b The byte array
|
|
19
|
+
* @param length The specified length
|
|
20
|
+
*/
|
|
21
|
+
function assertBytes(b, length) {
|
|
22
|
+
if (!isBytes(b, length)) {
|
|
23
|
+
throw new TypeError(`Parameter is not valid Bytes of length: ${length} !== ${b.length}`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.assertBytes = assertBytes;
|
|
27
|
+
/**
|
|
28
|
+
* Type guard for FlexBytes<Min,Max> type
|
|
29
|
+
*
|
|
30
|
+
* @param b The byte array
|
|
31
|
+
* @param min Minimum size of the array
|
|
32
|
+
* @param max Maximum size of the array
|
|
33
|
+
*/
|
|
34
|
+
function isFlexBytes(b, min, max) {
|
|
35
|
+
return b instanceof Uint8Array && b.length >= min && b.length <= max;
|
|
36
|
+
}
|
|
37
|
+
exports.isFlexBytes = isFlexBytes;
|
|
38
|
+
/**
|
|
39
|
+
* Verifies if a byte array has a certain length between min and max
|
|
40
|
+
*
|
|
41
|
+
* @param b The byte array
|
|
42
|
+
* @param min Minimum size of the array
|
|
43
|
+
* @param max Maximum size of the array
|
|
44
|
+
*/
|
|
45
|
+
function assertFlexBytes(b, min, max) {
|
|
46
|
+
if (!isFlexBytes(b, min, max)) {
|
|
47
|
+
throw new TypeError(`Parameter is not valid FlexBytes of min: ${min}, max: ${max}, length: ${b.length}`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.assertFlexBytes = assertFlexBytes;
|
|
51
|
+
/**
|
|
52
|
+
* Return `length` bytes starting from `offset`
|
|
53
|
+
*
|
|
54
|
+
* @param data The original data
|
|
55
|
+
* @param offset The offset to start from
|
|
56
|
+
* @param length The length of data to be returned
|
|
57
|
+
*/
|
|
58
|
+
function bytesAtOffset(data, offset, length) {
|
|
59
|
+
const offsetBytes = data.slice(offset, offset + length);
|
|
60
|
+
// We are returning strongly typed Bytes so we have to verify that length is really what we claim
|
|
61
|
+
assertBytes(offsetBytes, length);
|
|
62
|
+
return offsetBytes;
|
|
63
|
+
}
|
|
64
|
+
exports.bytesAtOffset = bytesAtOffset;
|
|
65
|
+
/**
|
|
66
|
+
* Return flex bytes starting from `offset`
|
|
67
|
+
*
|
|
68
|
+
* @param data The original data
|
|
69
|
+
* @param offset The offset to start from
|
|
70
|
+
* @param _min The minimum size of the data
|
|
71
|
+
* @param _max The maximum size of the data
|
|
72
|
+
*/
|
|
73
|
+
function flexBytesAtOffset(data, offset,
|
|
74
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
75
|
+
_min,
|
|
76
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
77
|
+
_max) {
|
|
78
|
+
return data.slice(offset);
|
|
79
|
+
}
|
|
80
|
+
exports.flexBytesAtOffset = flexBytesAtOffset;
|
|
81
|
+
/**
|
|
82
|
+
* Returns true if two byte arrays are equal
|
|
83
|
+
*
|
|
84
|
+
* @param a Byte array to compare
|
|
85
|
+
* @param b Byte array to compare
|
|
86
|
+
*/
|
|
87
|
+
function bytesEqual(a, b) {
|
|
88
|
+
return a.length === b.length && a.every((value, index) => value === b[index]);
|
|
89
|
+
}
|
|
90
|
+
exports.bytesEqual = bytesEqual;
|
|
91
|
+
/**
|
|
92
|
+
* Returns a new byte array filled with zeroes with the specified length
|
|
93
|
+
*
|
|
94
|
+
* @param length The length of data to be returned
|
|
95
|
+
*/
|
|
96
|
+
function makeBytes(length) {
|
|
97
|
+
return new Uint8Array(length);
|
|
98
|
+
}
|
|
99
|
+
exports.makeBytes = makeBytes;
|
|
100
|
+
function wrapBytesWithHelpers(data) {
|
|
101
|
+
return Object.assign(data, {
|
|
102
|
+
text: () => new TextDecoder('utf-8').decode(data),
|
|
103
|
+
json: () => JSON.parse(new TextDecoder('utf-8').decode(data)),
|
|
104
|
+
hex: () => (0, hex_1.bytesToHex)(data),
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
exports.wrapBytesWithHelpers = wrapBytesWithHelpers;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getFolderSize = exports.makeCollectionFromFS = void 0;
|
|
13
|
+
/**
|
|
14
|
+
* Creates array in the format of Collection with data loaded from directory on filesystem.
|
|
15
|
+
* The function loads all the data into memory!
|
|
16
|
+
*
|
|
17
|
+
* @param dir path to the directory
|
|
18
|
+
*/
|
|
19
|
+
function makeCollectionFromFS(dir) {
|
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
throw new Error('Creating Collection from File System is not supported in browsers!');
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
exports.makeCollectionFromFS = makeCollectionFromFS;
|
|
25
|
+
/**
|
|
26
|
+
* Calculate folder size recursively
|
|
27
|
+
*
|
|
28
|
+
* @param dir the path to the folder to check
|
|
29
|
+
* @returns size in bytes
|
|
30
|
+
*/
|
|
31
|
+
function getFolderSize(dir) {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
throw new Error('Creating Collection from File System is not supported in browsers!');
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
exports.getFolderSize = getFolderSize;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getCollectionSize = exports.makeCollectionFromFileList = exports.assertCollection = exports.isCollection = void 0;
|
|
13
|
+
const error_1 = require("./error");
|
|
14
|
+
const file_1 = require("./file");
|
|
15
|
+
const type_1 = require("./type");
|
|
16
|
+
function isCollection(data) {
|
|
17
|
+
if (!Array.isArray(data)) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
return data.every(entry => typeof entry === 'object' && entry.data && entry.path && (0, type_1.isUint8Array)(entry.data));
|
|
21
|
+
}
|
|
22
|
+
exports.isCollection = isCollection;
|
|
23
|
+
function assertCollection(data) {
|
|
24
|
+
if (!isCollection(data)) {
|
|
25
|
+
throw new error_1.BeeArgumentError('invalid collection', data);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.assertCollection = assertCollection;
|
|
29
|
+
function makeFilePath(file) {
|
|
30
|
+
if (file.webkitRelativePath && file.webkitRelativePath !== '') {
|
|
31
|
+
return file.webkitRelativePath.replace(/.*?\//i, '');
|
|
32
|
+
}
|
|
33
|
+
if (file.name) {
|
|
34
|
+
return file.name;
|
|
35
|
+
}
|
|
36
|
+
throw new TypeError('file is not valid File object');
|
|
37
|
+
}
|
|
38
|
+
function makeCollectionFromFileList(fileList) {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
const collection = [];
|
|
41
|
+
for (let i = 0; i < fileList.length; i++) {
|
|
42
|
+
const file = fileList[i];
|
|
43
|
+
if (file) {
|
|
44
|
+
collection.push({
|
|
45
|
+
path: makeFilePath(file),
|
|
46
|
+
data: new Uint8Array(yield (0, file_1.fileArrayBuffer)(file)),
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return collection;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
exports.makeCollectionFromFileList = makeCollectionFromFileList;
|
|
54
|
+
/**
|
|
55
|
+
* Calculate cumulative size of files
|
|
56
|
+
*
|
|
57
|
+
* @param fileList list of files to check
|
|
58
|
+
* @returns size in bytes
|
|
59
|
+
*/
|
|
60
|
+
function getCollectionSize(fileList) {
|
|
61
|
+
let sum = 0;
|
|
62
|
+
for (let i = 0; i < fileList.length; i++) {
|
|
63
|
+
const file = fileList[i];
|
|
64
|
+
if (file) {
|
|
65
|
+
sum += file.size;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return sum;
|
|
69
|
+
}
|
|
70
|
+
exports.getCollectionSize = getCollectionSize;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
12
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
13
|
+
var m = o[Symbol.asyncIterator], i;
|
|
14
|
+
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 () { return this; }, i);
|
|
15
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
16
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
17
|
+
};
|
|
18
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
19
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.getFolderSize = exports.makeCollectionFromFS = void 0;
|
|
23
|
+
const fs_1 = __importDefault(require("fs"));
|
|
24
|
+
const path_1 = __importDefault(require("path"));
|
|
25
|
+
/**
|
|
26
|
+
* Creates array in the format of Collection with data loaded from directory on filesystem.
|
|
27
|
+
* The function loads all the data into memory!
|
|
28
|
+
*
|
|
29
|
+
* @param dir path to the directory
|
|
30
|
+
*/
|
|
31
|
+
function makeCollectionFromFS(dir) {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
if (typeof dir !== 'string') {
|
|
34
|
+
throw new TypeError('dir has to be string!');
|
|
35
|
+
}
|
|
36
|
+
if (dir === '') {
|
|
37
|
+
throw new TypeError('dir must not be empty string!');
|
|
38
|
+
}
|
|
39
|
+
return buildCollectionRelative(dir, '');
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
exports.makeCollectionFromFS = makeCollectionFromFS;
|
|
43
|
+
function buildCollectionRelative(dir, relativePath) {
|
|
44
|
+
var e_1, _a;
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
// Handles case when the dir is not existing or it is a file ==> throws an error
|
|
47
|
+
const dirname = path_1.default.join(dir, relativePath);
|
|
48
|
+
const entries = yield fs_1.default.promises.opendir(dirname);
|
|
49
|
+
let collection = [];
|
|
50
|
+
try {
|
|
51
|
+
for (var entries_1 = __asyncValues(entries), entries_1_1; entries_1_1 = yield entries_1.next(), !entries_1_1.done;) {
|
|
52
|
+
const entry = entries_1_1.value;
|
|
53
|
+
const fullPath = path_1.default.join(dir, relativePath, entry.name);
|
|
54
|
+
const entryPath = path_1.default.join(relativePath, entry.name);
|
|
55
|
+
if (entry.isFile()) {
|
|
56
|
+
collection.push({
|
|
57
|
+
path: entryPath,
|
|
58
|
+
data: new Uint8Array(yield fs_1.default.promises.readFile(fullPath)),
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
else if (entry.isDirectory()) {
|
|
62
|
+
collection = [...(yield buildCollectionRelative(dir, entryPath)), ...collection];
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
67
|
+
finally {
|
|
68
|
+
try {
|
|
69
|
+
if (entries_1_1 && !entries_1_1.done && (_a = entries_1.return)) yield _a.call(entries_1);
|
|
70
|
+
}
|
|
71
|
+
finally { if (e_1) throw e_1.error; }
|
|
72
|
+
}
|
|
73
|
+
return collection;
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Calculate folder size recursively
|
|
78
|
+
*
|
|
79
|
+
* @param dir the path to the folder to check
|
|
80
|
+
* @returns size in bytes
|
|
81
|
+
*/
|
|
82
|
+
function getFolderSize(dir) {
|
|
83
|
+
var e_2, _a;
|
|
84
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
if (typeof dir !== 'string') {
|
|
86
|
+
throw new TypeError('dir has to be string!');
|
|
87
|
+
}
|
|
88
|
+
if (dir === '') {
|
|
89
|
+
throw new TypeError('dir must not be empty string!');
|
|
90
|
+
}
|
|
91
|
+
const entries = yield fs_1.default.promises.opendir(dir);
|
|
92
|
+
let size = 0;
|
|
93
|
+
try {
|
|
94
|
+
for (var entries_2 = __asyncValues(entries), entries_2_1; entries_2_1 = yield entries_2.next(), !entries_2_1.done;) {
|
|
95
|
+
const entry = entries_2_1.value;
|
|
96
|
+
if (entry.isFile()) {
|
|
97
|
+
const stats = yield fs_1.default.promises.stat(path_1.default.join(dir, entry.name));
|
|
98
|
+
size += stats.size;
|
|
99
|
+
}
|
|
100
|
+
else if (entry.isDirectory()) {
|
|
101
|
+
size += yield getFolderSize(path_1.default.join(dir, entry.name));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
106
|
+
finally {
|
|
107
|
+
try {
|
|
108
|
+
if (entries_2_1 && !entries_2_1.done && (_a = entries_2.return)) yield _a.call(entries_2);
|
|
109
|
+
}
|
|
110
|
+
finally { if (e_2) throw e_2.error; }
|
|
111
|
+
}
|
|
112
|
+
return size;
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
exports.getFolderSize = getFolderSize;
|