@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.
Files changed (151) hide show
  1. package/README.md +14 -6
  2. package/dist/223.index.browser.min.js +3 -0
  3. package/dist/223.index.browser.min.js.LICENSE.txt +1 -0
  4. package/dist/223.index.browser.min.js.map +1 -0
  5. package/dist/cjs/bee-debug.js +208 -312
  6. package/dist/cjs/bee.js +258 -353
  7. package/dist/cjs/chunk/signer.js +11 -22
  8. package/dist/cjs/chunk/soc.js +33 -50
  9. package/dist/cjs/chunk/span.js +1 -1
  10. package/dist/cjs/feed/index.js +50 -65
  11. package/dist/cjs/feed/json.js +8 -21
  12. package/dist/cjs/feed/retrievable.js +14 -27
  13. package/dist/cjs/modules/bytes.js +25 -37
  14. package/dist/cjs/modules/bzz.js +63 -68
  15. package/dist/cjs/modules/chunk.js +17 -27
  16. package/dist/cjs/modules/debug/balance.js +24 -41
  17. package/dist/cjs/modules/debug/chequebook.js +71 -96
  18. package/dist/cjs/modules/debug/chunk.js +13 -26
  19. package/dist/cjs/modules/debug/connectivity.js +32 -53
  20. package/dist/cjs/modules/debug/settlements.js +12 -25
  21. package/dist/cjs/modules/debug/stake.js +20 -33
  22. package/dist/cjs/modules/debug/stamps.js +45 -66
  23. package/dist/cjs/modules/debug/states.js +27 -40
  24. package/dist/cjs/modules/debug/status.js +53 -80
  25. package/dist/cjs/modules/debug/tag.js +6 -17
  26. package/dist/cjs/modules/debug/transactions.js +23 -40
  27. package/dist/cjs/modules/feed.js +17 -27
  28. package/dist/cjs/modules/pinning.js +24 -41
  29. package/dist/cjs/modules/pss.js +9 -20
  30. package/dist/cjs/modules/soc.js +12 -20
  31. package/dist/cjs/modules/status.js +4 -15
  32. package/dist/cjs/modules/stewardship.js +10 -23
  33. package/dist/cjs/modules/tag.js +28 -47
  34. package/dist/cjs/utils/collection.browser.js +4 -17
  35. package/dist/cjs/utils/collection.js +11 -22
  36. package/dist/cjs/utils/collection.node.js +42 -86
  37. package/dist/cjs/utils/data.browser.js +46 -59
  38. package/dist/cjs/utils/data.js +22 -35
  39. package/dist/cjs/utils/eth.js +31 -43
  40. package/dist/cjs/utils/file.js +9 -20
  41. package/dist/cjs/utils/headers.js +4 -4
  42. package/dist/cjs/utils/http.js +78 -93
  43. package/dist/cjs/utils/merge.js +1 -1
  44. package/dist/cjs/utils/sleep.js +2 -13
  45. package/dist/cjs/utils/type.js +14 -12
  46. package/dist/index.browser.min.js +1 -1
  47. package/dist/index.browser.min.js.LICENSE.txt +1 -3
  48. package/dist/index.browser.min.js.map +1 -1
  49. package/dist/mjs/bee-debug.js +209 -450
  50. package/dist/mjs/bee.js +256 -491
  51. package/dist/mjs/chunk/bmt.js +4 -10
  52. package/dist/mjs/chunk/cac.js +0 -3
  53. package/dist/mjs/chunk/signer.js +12 -63
  54. package/dist/mjs/chunk/soc.js +33 -85
  55. package/dist/mjs/chunk/span.js +3 -6
  56. package/dist/mjs/feed/identifier.js +0 -6
  57. package/dist/mjs/feed/index.js +53 -97
  58. package/dist/mjs/feed/json.js +10 -49
  59. package/dist/mjs/feed/retrievable.js +13 -64
  60. package/dist/mjs/feed/topic.js +0 -2
  61. package/dist/mjs/index.js +1 -2
  62. package/dist/mjs/modules/bytes.js +25 -65
  63. package/dist/mjs/modules/bzz.js +64 -108
  64. package/dist/mjs/modules/chunk.js +17 -54
  65. package/dist/mjs/modules/debug/balance.js +24 -68
  66. package/dist/mjs/modules/debug/chequebook.js +75 -138
  67. package/dist/mjs/modules/debug/chunk.js +13 -51
  68. package/dist/mjs/modules/debug/connectivity.js +32 -76
  69. package/dist/mjs/modules/debug/settlements.js +12 -50
  70. package/dist/mjs/modules/debug/stake.js +20 -61
  71. package/dist/mjs/modules/debug/stamps.js +47 -94
  72. package/dist/mjs/modules/debug/states.js +25 -66
  73. package/dist/mjs/modules/debug/status.js +66 -125
  74. package/dist/mjs/modules/debug/tag.js +6 -41
  75. package/dist/mjs/modules/debug/transactions.js +25 -69
  76. package/dist/mjs/modules/feed.js +17 -57
  77. package/dist/mjs/modules/pinning.js +24 -68
  78. package/dist/mjs/modules/pss.js +11 -47
  79. package/dist/mjs/modules/soc.js +14 -48
  80. package/dist/mjs/modules/status.js +4 -39
  81. package/dist/mjs/modules/stewardship.js +10 -47
  82. package/dist/mjs/modules/tag.js +31 -78
  83. package/dist/mjs/types/debug.js +0 -1
  84. package/dist/mjs/types/index.js +0 -4
  85. package/dist/mjs/utils/bytes.js +6 -14
  86. package/dist/mjs/utils/collection.browser.js +4 -42
  87. package/dist/mjs/utils/collection.js +11 -57
  88. package/dist/mjs/utils/collection.node.js +42 -150
  89. package/dist/mjs/utils/data.browser.js +49 -94
  90. package/dist/mjs/utils/data.js +19 -62
  91. package/dist/mjs/utils/error.js +0 -5
  92. package/dist/mjs/utils/eth.js +37 -95
  93. package/dist/mjs/utils/file.js +11 -50
  94. package/dist/mjs/utils/hash.js +0 -1
  95. package/dist/mjs/utils/headers.js +6 -14
  96. package/dist/mjs/utils/hex.js +6 -25
  97. package/dist/mjs/utils/http.js +80 -138
  98. package/dist/mjs/utils/merge.js +3 -7
  99. package/dist/mjs/utils/pss.js +0 -2
  100. package/dist/mjs/utils/reference.js +2 -5
  101. package/dist/mjs/utils/sleep.js +2 -37
  102. package/dist/mjs/utils/stream.js +0 -23
  103. package/dist/mjs/utils/tar.js +2 -5
  104. package/dist/mjs/utils/type.js +18 -82
  105. package/dist/mjs/utils/uint64.js +0 -1
  106. package/dist/mjs/utils/url.js +2 -10
  107. package/dist/types/bee-debug.d.ts +2 -2
  108. package/dist/types/bee.d.ts +2 -26
  109. package/dist/types/chunk/cac.d.ts +1 -1
  110. package/dist/types/chunk/soc.d.ts +8 -7
  111. package/dist/types/feed/index.d.ts +9 -8
  112. package/dist/types/feed/type.d.ts +1 -1
  113. package/dist/types/modules/bytes.d.ts +6 -5
  114. package/dist/types/modules/bzz.d.ts +9 -8
  115. package/dist/types/modules/chunk.d.ts +5 -4
  116. package/dist/types/modules/debug/balance.d.ts +10 -9
  117. package/dist/types/modules/debug/chequebook.d.ts +18 -17
  118. package/dist/types/modules/debug/chunk.d.ts +6 -5
  119. package/dist/types/modules/debug/connectivity.d.ts +8 -7
  120. package/dist/types/modules/debug/settlements.d.ts +6 -5
  121. package/dist/types/modules/debug/stake.d.ts +5 -4
  122. package/dist/types/modules/debug/stamps.d.ts +8 -7
  123. package/dist/types/modules/debug/states.d.ts +8 -7
  124. package/dist/types/modules/debug/status.d.ts +15 -15
  125. package/dist/types/modules/debug/tag.d.ts +4 -3
  126. package/dist/types/modules/debug/transactions.d.ts +6 -5
  127. package/dist/types/modules/feed.d.ts +4 -3
  128. package/dist/types/modules/pinning.d.ts +8 -7
  129. package/dist/types/modules/pss.d.ts +4 -3
  130. package/dist/types/modules/soc.d.ts +3 -2
  131. package/dist/types/modules/status.d.ts +3 -3
  132. package/dist/types/modules/stewardship.d.ts +4 -3
  133. package/dist/types/modules/tag.d.ts +7 -6
  134. package/dist/types/types/debug.d.ts +1 -1
  135. package/dist/types/types/index.d.ts +30 -34
  136. package/dist/types/utils/eth.d.ts +3 -3
  137. package/dist/types/utils/hex.d.ts +2 -2
  138. package/dist/types/utils/http.d.ts +6 -6
  139. package/package.json +34 -39
  140. package/dist/cjs/types/ky-options.js +0 -8
  141. package/dist/cjs/types/ky-universal/common.js +0 -8
  142. package/dist/cjs/types/ky-universal/hooks.js +0 -8
  143. package/dist/cjs/types/ky-universal/retry.js +0 -8
  144. package/dist/mjs/types/ky-options.js +0 -7
  145. package/dist/mjs/types/ky-universal/common.js +0 -7
  146. package/dist/mjs/types/ky-universal/hooks.js +0 -7
  147. package/dist/mjs/types/ky-universal/retry.js +0 -7
  148. package/dist/types/types/ky-options.d.ts +0 -221
  149. package/dist/types/types/ky-universal/common.d.ts +0 -13
  150. package/dist/types/types/ky-universal/hooks.d.ts +0 -92
  151. package/dist/types/types/ky-universal/retry.d.ts +0 -38
@@ -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
- 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;
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
- 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;
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
- 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;
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
- 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
- });
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
- 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
- });
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
  }
@@ -1,5 +1,4 @@
1
1
  export var BeeModes;
2
-
3
2
  (function (BeeModes) {
4
3
  BeeModes["FULL"] = "full";
5
4
  BeeModes["LIGHT"] = "light";
@@ -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;
@@ -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); // We are returning strongly typed Bytes so we have to verify that length is really what we claim
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
- export function flexBytesAtOffset(data, offset, // eslint-disable-next-line @typescript-eslint/no-unused-vars
87
- _min, // eslint-disable-next-line @typescript-eslint/no-unused-vars
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
- 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
- });
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
- export function makeCollectionFromFileList(fileList) {
62
- return __awaiter(this, void 0, void 0, function* () {
63
- const collection = [];
64
-
65
- for (let i = 0; i < fileList.length; i++) {
66
- const file = fileList[i];
67
-
68
- if (file) {
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
- return collection;
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
- 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
- }
73
-
74
- if (dir === '') {
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
- function buildCollectionRelative(dir, relativePath) {
83
- var e_1, _a;
84
-
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 = [];
90
-
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
- }
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
- return collection;
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
- export function getFolderSize(dir) {
130
- var e_2, _a;
131
-
132
- return __awaiter(this, void 0, void 0, function* () {
133
- if (typeof dir !== 'string') {
134
- throw new TypeError('dir has to be string!');
135
- }
136
-
137
- if (dir === '') {
138
- throw new TypeError('dir must not be empty string!');
139
- }
140
-
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
- }
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
- return size;
168
- });
59
+ }
60
+ return size;
169
61
  }