@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,13 +1,4 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.isRetrievable = exports.reupload = void 0;
13
4
  const http_1 = require("../utils/http");
@@ -19,23 +10,19 @@ const stewardshipEndpoint = 'stewardship';
19
10
  * @param options
20
11
  * @throws BeeResponseError if not locally pinned or invalid data
21
12
  */
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
- });
13
+ async function reupload(kyOptions, reference) {
14
+ await (0, http_1.http)(kyOptions, {
15
+ method: 'put',
16
+ path: `${stewardshipEndpoint}/${reference}`,
28
17
  });
29
18
  }
30
19
  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;
20
+ async function isRetrievable(kyOptions, reference) {
21
+ const response = await (0, http_1.http)(kyOptions, {
22
+ method: 'get',
23
+ responseType: 'json',
24
+ path: `${stewardshipEndpoint}/${reference}`,
39
25
  });
26
+ return response.parsedData.isRetrievable;
40
27
  }
41
28
  exports.isRetrievable = isRetrievable;
@@ -1,13 +1,4 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.updateTag = exports.deleteTag = exports.getAllTags = exports.retrieveTag = exports.createTag = void 0;
13
4
  const http_1 = require("../utils/http");
@@ -17,15 +8,13 @@ const endpoint = 'tags';
17
8
  *
18
9
  * @param url Bee tag URL
19
10
  */
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;
11
+ async function createTag(kyOptions) {
12
+ const response = await (0, http_1.http)(kyOptions, {
13
+ method: 'post',
14
+ path: endpoint,
15
+ responseType: 'json',
28
16
  });
17
+ return response.parsedData;
29
18
  }
30
19
  exports.createTag = createTag;
31
20
  /**
@@ -34,14 +23,12 @@ exports.createTag = createTag;
34
23
  * @param url Bee tag URL
35
24
  * @param uid UID of tag to be retrieved
36
25
  */
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;
26
+ async function retrieveTag(kyOptions, uid) {
27
+ const response = await (0, http_1.http)(kyOptions, {
28
+ path: `${endpoint}/${uid}`,
29
+ responseType: 'json',
44
30
  });
31
+ return response.parsedData;
45
32
  }
46
33
  exports.retrieveTag = retrieveTag;
47
34
  /**
@@ -51,15 +38,13 @@ exports.retrieveTag = retrieveTag;
51
38
  * @param offset
52
39
  * @param limit
53
40
  */
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;
41
+ async function getAllTags(kyOptions, offset, limit) {
42
+ const response = await (0, http_1.http)(kyOptions, {
43
+ path: `${endpoint}`,
44
+ searchParams: { offset, limit },
45
+ responseType: 'json',
62
46
  });
47
+ return response.parsedData.tags;
63
48
  }
64
49
  exports.getAllTags = getAllTags;
65
50
  /**
@@ -67,12 +52,10 @@ exports.getAllTags = getAllTags;
67
52
  * @param url
68
53
  * @param uid
69
54
  */
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
- });
55
+ async function deleteTag(kyOptions, uid) {
56
+ await (0, http_1.http)(kyOptions, {
57
+ method: 'delete',
58
+ path: `${endpoint}/${uid}`,
76
59
  });
77
60
  }
78
61
  exports.deleteTag = deleteTag;
@@ -82,15 +65,13 @@ exports.deleteTag = deleteTag;
82
65
  * @param uid
83
66
  * @param reference
84
67
  */
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
- });
68
+ async function updateTag(kyOptions, uid, reference) {
69
+ await (0, http_1.http)(kyOptions, {
70
+ method: 'patch',
71
+ path: `${endpoint}/${uid}`,
72
+ json: {
73
+ reference,
74
+ },
94
75
  });
95
76
  }
96
77
  exports.updateTag = updateTag;
@@ -1,13 +1,4 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.getFolderSize = exports.makeCollectionFromFS = void 0;
13
4
  /**
@@ -16,10 +7,8 @@ exports.getFolderSize = exports.makeCollectionFromFS = void 0;
16
7
  *
17
8
  * @param dir path to the directory
18
9
  */
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
- });
10
+ async function makeCollectionFromFS(dir) {
11
+ throw new Error('Creating Collection from File System is not supported in browsers!');
23
12
  }
24
13
  exports.makeCollectionFromFS = makeCollectionFromFS;
25
14
  /**
@@ -28,9 +17,7 @@ exports.makeCollectionFromFS = makeCollectionFromFS;
28
17
  * @param dir the path to the folder to check
29
18
  * @returns size in bytes
30
19
  */
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
- });
20
+ async function getFolderSize(dir) {
21
+ throw new Error('Creating Collection from File System is not supported in browsers!');
35
22
  }
36
23
  exports.getFolderSize = getFolderSize;
@@ -1,13 +1,4 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.getCollectionSize = exports.makeCollectionFromFileList = exports.assertCollection = exports.isCollection = void 0;
13
4
  const error_1 = require("./error");
@@ -35,20 +26,18 @@ function makeFilePath(file) {
35
26
  }
36
27
  throw new TypeError('file is not valid File object');
37
28
  }
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
- }
29
+ async function makeCollectionFromFileList(fileList) {
30
+ const collection = [];
31
+ for (let i = 0; i < fileList.length; i++) {
32
+ const file = fileList[i];
33
+ if (file) {
34
+ collection.push({
35
+ path: makeFilePath(file),
36
+ data: new Uint8Array(await (0, file_1.fileArrayBuffer)(file)),
37
+ });
49
38
  }
50
- return collection;
51
- });
39
+ }
40
+ return collection;
52
41
  }
53
42
  exports.makeCollectionFromFileList = makeCollectionFromFileList;
54
43
  /**
@@ -1,20 +1,4 @@
1
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
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
19
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
20
4
  };
@@ -28,50 +12,35 @@ const path_1 = __importDefault(require("path"));
28
12
  *
29
13
  * @param dir path to the directory
30
14
  */
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
- });
15
+ async function makeCollectionFromFS(dir) {
16
+ if (typeof dir !== 'string') {
17
+ throw new TypeError('dir has to be string!');
18
+ }
19
+ if (dir === '') {
20
+ throw new TypeError('dir must not be empty string!');
21
+ }
22
+ return buildCollectionRelative(dir, '');
41
23
  }
42
24
  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
- }
25
+ async function buildCollectionRelative(dir, relativePath) {
26
+ // Handles case when the dir is not existing or it is a file ==> throws an error
27
+ const dirname = path_1.default.join(dir, relativePath);
28
+ const entries = await fs_1.default.promises.opendir(dirname);
29
+ let collection = [];
30
+ for await (const entry of entries) {
31
+ const fullPath = path_1.default.join(dir, relativePath, entry.name);
32
+ const entryPath = path_1.default.join(relativePath, entry.name);
33
+ if (entry.isFile()) {
34
+ collection.push({
35
+ path: entryPath,
36
+ data: new Uint8Array(await fs_1.default.promises.readFile(fullPath)),
37
+ });
65
38
  }
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; }
39
+ else if (entry.isDirectory()) {
40
+ collection = [...(await buildCollectionRelative(dir, entryPath)), ...collection];
72
41
  }
73
- return collection;
74
- });
42
+ }
43
+ return collection;
75
44
  }
76
45
  /**
77
46
  * Calculate folder size recursively
@@ -79,37 +48,24 @@ function buildCollectionRelative(dir, relativePath) {
79
48
  * @param dir the path to the folder to check
80
49
  * @returns size in bytes
81
50
  */
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
- }
51
+ async function getFolderSize(dir) {
52
+ if (typeof dir !== 'string') {
53
+ throw new TypeError('dir has to be string!');
54
+ }
55
+ if (dir === '') {
56
+ throw new TypeError('dir must not be empty string!');
57
+ }
58
+ const entries = await fs_1.default.promises.opendir(dir);
59
+ let size = 0;
60
+ for await (const entry of entries) {
61
+ if (entry.isFile()) {
62
+ const stats = await fs_1.default.promises.stat(path_1.default.join(dir, entry.name));
63
+ size += stats.size;
104
64
  }
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; }
65
+ else if (entry.isDirectory()) {
66
+ size += await getFolderSize(path_1.default.join(dir, entry.name));
111
67
  }
112
- return size;
113
- });
68
+ }
69
+ return size;
114
70
  }
115
71
  exports.getFolderSize = getFolderSize;
@@ -1,13 +1,4 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.prepareWebsocketData = exports.prepareData = void 0;
13
4
  const stream_1 = require("./stream");
@@ -16,59 +7,55 @@ const stream_1 = require("./stream");
16
7
  *
17
8
  * @param data any string, ArrayBuffer or Uint8Array
18
9
  */
19
- function prepareData(data) {
20
- return __awaiter(this, void 0, void 0, function* () {
21
- if (typeof data === 'string')
22
- return new Blob([data], { type: 'text/plain' });
23
- if (data instanceof Uint8Array || data instanceof ArrayBuffer) {
24
- return new Blob([data], { type: 'application/octet-stream' });
25
- }
26
- if (data instanceof Blob) {
27
- return data;
28
- }
29
- // Currently it is not possible to stream requests from browsers
30
- // there are already first experiments on this field (Chromium)
31
- // but till it is fully implemented across browsers-land we have to
32
- // buffer the data before sending the requests.
33
- if ((0, stream_1.isNodeReadable)(data)) {
34
- return new Promise(resolve => {
35
- const buffers = [];
36
- data.on('data', d => {
37
- buffers.push(d);
38
- });
39
- data.on('end', () => {
40
- resolve(new Blob(buffers, { type: 'application/octet-stream' }));
41
- });
10
+ async function prepareData(data) {
11
+ if (typeof data === 'string')
12
+ return new Blob([data], { type: 'text/plain' });
13
+ if (data instanceof Uint8Array || data instanceof ArrayBuffer) {
14
+ return new Blob([data], { type: 'application/octet-stream' });
15
+ }
16
+ if (data instanceof Blob) {
17
+ return data;
18
+ }
19
+ // Currently it is not possible to stream requests from browsers
20
+ // there are already first experiments on this field (Chromium)
21
+ // but till it is fully implemented across browsers-land we have to
22
+ // buffer the data before sending the requests.
23
+ if ((0, stream_1.isNodeReadable)(data)) {
24
+ return new Promise(resolve => {
25
+ const buffers = [];
26
+ data.on('data', d => {
27
+ buffers.push(d);
42
28
  });
43
- }
44
- if ((0, stream_1.isReadableStream)(data)) {
45
- return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
46
- const reader = data.getReader();
47
- const buffers = [];
48
- let done, value;
49
- do {
50
- ;
51
- ({ done, value } = yield reader.read());
52
- if (!done) {
53
- buffers.push(value);
54
- }
55
- } while (!done);
29
+ data.on('end', () => {
56
30
  resolve(new Blob(buffers, { type: 'application/octet-stream' }));
57
- }));
58
- }
59
- throw new TypeError('unknown data type');
60
- });
31
+ });
32
+ });
33
+ }
34
+ if ((0, stream_1.isReadableStream)(data)) {
35
+ return new Promise(async (resolve) => {
36
+ const reader = data.getReader();
37
+ const buffers = [];
38
+ let done, value;
39
+ do {
40
+ ;
41
+ ({ done, value } = await reader.read());
42
+ if (!done) {
43
+ buffers.push(value);
44
+ }
45
+ } while (!done);
46
+ resolve(new Blob(buffers, { type: 'application/octet-stream' }));
47
+ });
48
+ }
49
+ throw new TypeError('unknown data type');
61
50
  }
62
51
  exports.prepareData = prepareData;
63
- function prepareWebsocketData(data) {
64
- return __awaiter(this, void 0, void 0, function* () {
65
- if (typeof data === 'string')
66
- return new TextEncoder().encode(data);
67
- if (data instanceof ArrayBuffer)
68
- return new Uint8Array(data);
69
- if (data instanceof Blob)
70
- return new Uint8Array(yield new Response(data).arrayBuffer());
71
- throw new TypeError('unknown websocket data type');
72
- });
52
+ async function prepareWebsocketData(data) {
53
+ if (typeof data === 'string')
54
+ return new TextEncoder().encode(data);
55
+ if (data instanceof ArrayBuffer)
56
+ return new Uint8Array(data);
57
+ if (data instanceof Blob)
58
+ return new Uint8Array(await new Response(data).arrayBuffer());
59
+ throw new TypeError('unknown websocket data type');
73
60
  }
74
61
  exports.prepareWebsocketData = prepareWebsocketData;
@@ -1,13 +1,4 @@
1
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
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -23,36 +14,32 @@ const stream_1 = require("./stream");
23
14
  *
24
15
  * @param data any string, ArrayBuffer, Uint8Array or Readable
25
16
  */
26
- function prepareData(data) {
27
- return __awaiter(this, void 0, void 0, function* () {
28
- if (typeof data === 'string')
29
- return new fetch_blob_1.default([data], { type: 'text/plain' });
30
- if (data instanceof Uint8Array || data instanceof ArrayBuffer) {
31
- return new fetch_blob_1.default([data], { type: 'application/octet-stream' });
32
- }
33
- if (data instanceof fetch_blob_1.default || (0, stream_1.isNodeReadable)(data))
34
- return data;
35
- if ((0, stream_1.isReadableStream)(data)) {
36
- return (0, stream_1.readableWebToNode)(data);
37
- }
38
- throw new TypeError('unknown data type');
39
- });
17
+ async function prepareData(data) {
18
+ if (typeof data === 'string')
19
+ return new fetch_blob_1.default([data], { type: 'text/plain' });
20
+ if (data instanceof Uint8Array || data instanceof ArrayBuffer) {
21
+ return new fetch_blob_1.default([data], { type: 'application/octet-stream' });
22
+ }
23
+ if (data instanceof fetch_blob_1.default || (0, stream_1.isNodeReadable)(data))
24
+ return data;
25
+ if ((0, stream_1.isReadableStream)(data)) {
26
+ return (0, stream_1.readableWebToNode)(data);
27
+ }
28
+ throw new TypeError('unknown data type');
40
29
  }
41
30
  exports.prepareData = prepareData;
42
31
  function isBufferArray(buffer) {
43
32
  return Array.isArray(buffer) && buffer.length > 0 && buffer.every(data => data instanceof Buffer);
44
33
  }
45
- function prepareWebsocketData(data) {
46
- return __awaiter(this, void 0, void 0, function* () {
47
- if (typeof data === 'string')
48
- return new TextEncoder().encode(data);
49
- if (data instanceof Buffer)
50
- return new Uint8Array(data);
51
- if (data instanceof ArrayBuffer)
52
- return new Uint8Array(data);
53
- if (isBufferArray(data))
54
- return new Uint8Array(Buffer.concat(data));
55
- throw new TypeError('unknown websocket data type');
56
- });
34
+ async function prepareWebsocketData(data) {
35
+ if (typeof data === 'string')
36
+ return new TextEncoder().encode(data);
37
+ if (data instanceof Buffer)
38
+ return new Uint8Array(data);
39
+ if (data instanceof ArrayBuffer)
40
+ return new Uint8Array(data);
41
+ if (isBufferArray(data))
42
+ return new Uint8Array(Buffer.concat(data));
43
+ throw new TypeError('unknown websocket data type');
57
44
  }
58
45
  exports.prepareWebsocketData = prepareWebsocketData;