@ethersphere/bee-js 5.0.0 → 6.0.0-pre.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.
Files changed (192) hide show
  1. package/README.md +9 -1
  2. package/dist/index.browser.js +33 -0
  3. package/dist/index.browser.js.map +7 -0
  4. package/dist/src/bee-debug.js +624 -0
  5. package/dist/{mjs → src}/bee.js +243 -340
  6. package/dist/{mjs → src}/chunk/bmt.js +0 -0
  7. package/dist/{mjs → src}/chunk/cac.js +0 -0
  8. package/dist/{mjs → src}/chunk/serialize.js +0 -0
  9. package/dist/{mjs → src}/chunk/signer.js +13 -47
  10. package/dist/{mjs → src}/chunk/soc.js +31 -71
  11. package/dist/{mjs → src}/chunk/span.js +1 -1
  12. package/dist/{mjs → src}/feed/identifier.js +0 -0
  13. package/dist/src/feed/index.js +92 -0
  14. package/dist/src/feed/json.js +27 -0
  15. package/dist/src/feed/retrievable.js +67 -0
  16. package/dist/{mjs → src}/feed/topic.js +0 -0
  17. package/dist/{mjs → src}/feed/type.js +0 -0
  18. package/dist/{mjs → src}/index.js +1 -2
  19. package/dist/src/modules/bytes.js +59 -0
  20. package/dist/src/modules/bzz.js +122 -0
  21. package/dist/src/modules/chunk.js +45 -0
  22. package/dist/src/modules/debug/balance.js +57 -0
  23. package/dist/src/modules/debug/chequebook.js +150 -0
  24. package/dist/src/modules/debug/chunk.js +35 -0
  25. package/dist/src/modules/debug/connectivity.js +45 -0
  26. package/dist/src/modules/debug/settlements.js +29 -0
  27. package/dist/src/modules/debug/stamps.js +64 -0
  28. package/dist/src/modules/debug/states.js +46 -0
  29. package/dist/src/modules/debug/status.js +134 -0
  30. package/dist/src/modules/debug/tag.js +16 -0
  31. package/dist/src/modules/debug/transactions.js +69 -0
  32. package/dist/src/modules/feed.js +67 -0
  33. package/dist/src/modules/pinning.js +60 -0
  34. package/dist/src/modules/pss.js +40 -0
  35. package/dist/src/modules/soc.js +31 -0
  36. package/dist/src/modules/status.js +12 -0
  37. package/dist/src/modules/stewardship.js +24 -0
  38. package/dist/src/modules/tag.js +77 -0
  39. package/dist/{mjs → src}/types/debug.js +0 -0
  40. package/dist/{mjs → src}/types/index.js +0 -0
  41. package/dist/{mjs → src}/utils/bytes.js +3 -2
  42. package/dist/src/utils/collection-browser.js +19 -0
  43. package/dist/src/utils/collection-node.js +74 -0
  44. package/dist/src/utils/collection.js +64 -0
  45. package/dist/src/utils/data.browser.js +72 -0
  46. package/dist/src/utils/data.js +42 -0
  47. package/dist/{mjs → src}/utils/error.js +0 -0
  48. package/dist/{mjs → src}/utils/eth.js +32 -68
  49. package/dist/{mjs → src}/utils/expose.js +1 -1
  50. package/dist/src/utils/file.js +36 -0
  51. package/dist/{mjs → src}/utils/hash.js +0 -0
  52. package/dist/{mjs → src}/utils/headers.js +4 -4
  53. package/dist/{mjs → src}/utils/hex.js +0 -0
  54. package/dist/src/utils/http.js +162 -0
  55. package/dist/{mjs → src}/utils/merge.js +2 -2
  56. package/dist/{mjs → src}/utils/pss.js +0 -0
  57. package/dist/{mjs → src}/utils/reference.js +0 -0
  58. package/dist/src/utils/sleep.js +8 -0
  59. package/dist/{mjs → src}/utils/stamps.js +0 -0
  60. package/dist/{mjs → src}/utils/stream.js +3 -3
  61. package/dist/{mjs → src}/utils/tar.js +0 -0
  62. package/dist/{mjs → src}/utils/type.js +12 -13
  63. package/dist/{mjs → src}/utils/uint64.js +0 -0
  64. package/dist/{mjs → src}/utils/url.js +0 -0
  65. package/dist/types/chunk/bmt.d.ts +1 -1
  66. package/dist/types/chunk/soc.d.ts +1 -1
  67. package/dist/types/chunk/span.d.ts +1 -1
  68. package/dist/types/feed/index.d.ts +1 -1
  69. package/dist/types/index.d.ts +0 -13
  70. package/dist/types/modules/bzz.d.ts +1 -1
  71. package/dist/types/types/index.d.ts +8 -8
  72. package/dist/types/utils/{collection.browser.d.ts → collection-browser.d.ts} +0 -0
  73. package/dist/types/utils/{collection.node.d.ts → collection-node.d.ts} +0 -0
  74. package/dist/types/utils/error.d.ts +1 -1
  75. package/dist/types/utils/eth.d.ts +3 -3
  76. package/dist/types/utils/expose.d.ts +7 -4
  77. package/dist/types/utils/hash.d.ts +1 -1
  78. package/dist/types/utils/hex.d.ts +2 -2
  79. package/dist/types/utils/http.d.ts +3 -3
  80. package/dist/types/utils/stream.d.ts +1 -1
  81. package/dist/types/utils/uint64.d.ts +1 -1
  82. package/package.json +44 -59
  83. package/dist/cjs/bee-debug.js +0 -642
  84. package/dist/cjs/bee.js +0 -983
  85. package/dist/cjs/chunk/bmt.js +0 -55
  86. package/dist/cjs/chunk/cac.js +0 -56
  87. package/dist/cjs/chunk/serialize.js +0 -19
  88. package/dist/cjs/chunk/signer.js +0 -137
  89. package/dist/cjs/chunk/soc.js +0 -176
  90. package/dist/cjs/chunk/span.js +0 -29
  91. package/dist/cjs/feed/identifier.js +0 -35
  92. package/dist/cjs/feed/index.js +0 -132
  93. package/dist/cjs/feed/json.js +0 -41
  94. package/dist/cjs/feed/retrievable.js +0 -72
  95. package/dist/cjs/feed/topic.js +0 -25
  96. package/dist/cjs/feed/type.js +0 -15
  97. package/dist/cjs/index.js +0 -39
  98. package/dist/cjs/modules/bytes.js +0 -74
  99. package/dist/cjs/modules/bzz.js +0 -131
  100. package/dist/cjs/modules/chunk.js +0 -58
  101. package/dist/cjs/modules/debug/balance.js +0 -77
  102. package/dist/cjs/modules/debug/chequebook.js +0 -167
  103. package/dist/cjs/modules/debug/chunk.js +0 -51
  104. package/dist/cjs/modules/debug/connectivity.js +0 -75
  105. package/dist/cjs/modules/debug/settlements.js +0 -45
  106. package/dist/cjs/modules/debug/stamps.js +0 -89
  107. package/dist/cjs/modules/debug/states.js +0 -64
  108. package/dist/cjs/modules/debug/status.js +0 -153
  109. package/dist/cjs/modules/debug/tag.js +0 -30
  110. package/dist/cjs/modules/debug/transactions.js +0 -81
  111. package/dist/cjs/modules/feed.js +0 -76
  112. package/dist/cjs/modules/pinning.js +0 -80
  113. package/dist/cjs/modules/pss.js +0 -55
  114. package/dist/cjs/modules/soc.js +0 -40
  115. package/dist/cjs/modules/status.js +0 -26
  116. package/dist/cjs/modules/stewardship.js +0 -41
  117. package/dist/cjs/modules/tag.js +0 -96
  118. package/dist/cjs/package.json +0 -8
  119. package/dist/cjs/types/debug.js +0 -10
  120. package/dist/cjs/types/index.js +0 -51
  121. package/dist/cjs/types/ky-options.js +0 -8
  122. package/dist/cjs/types/ky-universal/common.js +0 -8
  123. package/dist/cjs/types/ky-universal/hooks.js +0 -8
  124. package/dist/cjs/types/ky-universal/retry.js +0 -8
  125. package/dist/cjs/utils/bytes.js +0 -121
  126. package/dist/cjs/utils/collection.browser.js +0 -36
  127. package/dist/cjs/utils/collection.js +0 -70
  128. package/dist/cjs/utils/collection.node.js +0 -115
  129. package/dist/cjs/utils/data.browser.js +0 -74
  130. package/dist/cjs/utils/data.js +0 -58
  131. package/dist/cjs/utils/error.js +0 -50
  132. package/dist/cjs/utils/eth.js +0 -211
  133. package/dist/cjs/utils/expose.js +0 -44
  134. package/dist/cjs/utils/file.js +0 -49
  135. package/dist/cjs/utils/hash.js +0 -21
  136. package/dist/cjs/utils/headers.js +0 -59
  137. package/dist/cjs/utils/hex.js +0 -150
  138. package/dist/cjs/utils/http.js +0 -172
  139. package/dist/cjs/utils/merge.js +0 -34
  140. package/dist/cjs/utils/pss.js +0 -18
  141. package/dist/cjs/utils/reference.js +0 -36
  142. package/dist/cjs/utils/sleep.js +0 -23
  143. package/dist/cjs/utils/stamps.js +0 -17
  144. package/dist/cjs/utils/stream.js +0 -146
  145. package/dist/cjs/utils/tar.js +0 -25
  146. package/dist/cjs/utils/type.js +0 -426
  147. package/dist/cjs/utils/uint64.js +0 -29
  148. package/dist/cjs/utils/url.js +0 -56
  149. package/dist/index.browser.min.js +0 -3
  150. package/dist/index.browser.min.js.LICENSE.txt +0 -60
  151. package/dist/index.browser.min.js.map +0 -1
  152. package/dist/mjs/bee-debug.js +0 -744
  153. package/dist/mjs/feed/index.js +0 -134
  154. package/dist/mjs/feed/json.js +0 -63
  155. package/dist/mjs/feed/retrievable.js +0 -105
  156. package/dist/mjs/modules/bytes.js +0 -96
  157. package/dist/mjs/modules/bzz.js +0 -160
  158. package/dist/mjs/modules/chunk.js +0 -80
  159. package/dist/mjs/modules/debug/balance.js +0 -97
  160. package/dist/mjs/modules/debug/chequebook.js +0 -198
  161. package/dist/mjs/modules/debug/chunk.js +0 -71
  162. package/dist/mjs/modules/debug/connectivity.js +0 -89
  163. package/dist/mjs/modules/debug/settlements.js +0 -65
  164. package/dist/mjs/modules/debug/stamps.js +0 -108
  165. package/dist/mjs/modules/debug/states.js +0 -84
  166. package/dist/mjs/modules/debug/status.js +0 -182
  167. package/dist/mjs/modules/debug/tag.js +0 -50
  168. package/dist/mjs/modules/debug/transactions.js +0 -103
  169. package/dist/mjs/modules/feed.js +0 -101
  170. package/dist/mjs/modules/pinning.js +0 -100
  171. package/dist/mjs/modules/pss.js +0 -74
  172. package/dist/mjs/modules/soc.js +0 -64
  173. package/dist/mjs/modules/status.js +0 -46
  174. package/dist/mjs/modules/stewardship.js +0 -60
  175. package/dist/mjs/modules/tag.js +0 -119
  176. package/dist/mjs/package.json +0 -8
  177. package/dist/mjs/types/ky-options.js +0 -7
  178. package/dist/mjs/types/ky-universal/common.js +0 -7
  179. package/dist/mjs/types/ky-universal/hooks.js +0 -7
  180. package/dist/mjs/types/ky-universal/retry.js +0 -7
  181. package/dist/mjs/utils/collection.browser.js +0 -56
  182. package/dist/mjs/utils/collection.js +0 -98
  183. package/dist/mjs/utils/collection.node.js +0 -169
  184. package/dist/mjs/utils/data.browser.js +0 -108
  185. package/dist/mjs/utils/data.js +0 -78
  186. package/dist/mjs/utils/file.js +0 -70
  187. package/dist/mjs/utils/http.js +0 -208
  188. package/dist/mjs/utils/sleep.js +0 -43
  189. package/dist/types/types/ky-options.d.ts +0 -221
  190. package/dist/types/types/ky-universal/common.d.ts +0 -13
  191. package/dist/types/types/ky-universal/hooks.d.ts +0 -92
  192. package/dist/types/types/ky-universal/retry.d.ts +0 -38
@@ -1,46 +0,0 @@
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
- import { http } from "../utils/http.js";
34
- /**
35
- * Ping the base bee URL. If connection was not successful throw error
36
- *
37
- * @param ky Ky instance for given Bee class instance
38
- */
39
-
40
- export function checkConnection(ky) {
41
- return __awaiter(this, void 0, void 0, function* () {
42
- yield http(ky, {
43
- path: ''
44
- });
45
- });
46
- }
@@ -1,60 +0,0 @@
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
- import { http } from "../utils/http.js";
34
- const stewardshipEndpoint = 'stewardship';
35
- /**
36
- * Reupload locally pinned data
37
- * @param ky Ky instance
38
- * @param reference
39
- * @param options
40
- * @throws BeeResponseError if not locally pinned or invalid data
41
- */
42
-
43
- export function reupload(ky, reference) {
44
- return __awaiter(this, void 0, void 0, function* () {
45
- yield http(ky, {
46
- method: 'put',
47
- path: `${stewardshipEndpoint}/${reference}`
48
- });
49
- });
50
- }
51
- export function isRetrievable(ky, reference) {
52
- return __awaiter(this, void 0, void 0, function* () {
53
- const response = yield http(ky, {
54
- method: 'get',
55
- responseType: 'json',
56
- path: `${stewardshipEndpoint}/${reference}`
57
- });
58
- return response.data.isRetrievable;
59
- });
60
- }
@@ -1,119 +0,0 @@
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
- import { http } from "../utils/http.js";
34
- const endpoint = 'tags';
35
- /**
36
- * Create new tag on the Bee node
37
- *
38
- * @param url Bee tag URL
39
- */
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;
49
- });
50
- }
51
- /**
52
- * Retrieve tag information from Bee node
53
- *
54
- * @param url Bee tag URL
55
- * @param uid UID of tag to be retrieved
56
- */
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;
65
- });
66
- }
67
- /**
68
- * Get limited listing of all tags.
69
- *
70
- * @param url
71
- * @param offset
72
- * @param limit
73
- */
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;
86
- });
87
- }
88
- /**
89
- * Removes tag from the Bee node.
90
- * @param url
91
- * @param uid
92
- */
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
- });
100
- });
101
- }
102
- /**
103
- * Updates tag
104
- * @param url
105
- * @param uid
106
- * @param reference
107
- */
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
- });
118
- });
119
- }
@@ -1,8 +0,0 @@
1
- {
2
- "type": "module",
3
- "browser": {
4
- "stream": false,
5
- "./utils/data.js": "./utils/data.browser.js",
6
- "./utils/collection.node.js": "./utils/collection.browser.js"
7
- }
8
- }
@@ -1,7 +0,0 @@
1
- /**
2
- * Types extracted from Ky as a backport for older Ky non-ESM version
3
- *
4
- * @author https://github.com/sindresorhus
5
- * @licence MIT https://github.com/sindresorhus/ky/blob/main/license
6
- */
7
- export {};
@@ -1,7 +0,0 @@
1
- /**
2
- * Types extracted from Ky as a backport for older Ky non-ESM version
3
- *
4
- * @author https://github.com/sindresorhus
5
- * @licence MIT https://github.com/sindresorhus/ky/blob/main/license
6
- */
7
- export {};
@@ -1,7 +0,0 @@
1
- /**
2
- * Types extracted from Ky as a backport for older Ky non-ESM version
3
- *
4
- * @author https://github.com/sindresorhus
5
- * @licence MIT https://github.com/sindresorhus/ky/blob/main/license
6
- */
7
- export {};
@@ -1,7 +0,0 @@
1
- /**
2
- * Types extracted from Ky as a backport for older Ky non-ESM version
3
- *
4
- * @author https://github.com/sindresorhus
5
- * @licence MIT https://github.com/sindresorhus/ky/blob/main/license
6
- */
7
- export {};
@@ -1,56 +0,0 @@
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
- * Creates array in the format of Collection with data loaded from directory on filesystem.
34
- * The function loads all the data into memory!
35
- *
36
- * @param dir path to the directory
37
- */
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
- });
44
- }
45
- /**
46
- * Calculate folder size recursively
47
- *
48
- * @param dir the path to the folder to check
49
- * @returns size in bytes
50
- */
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
- });
56
- }
@@ -1,98 +0,0 @@
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
- import { BeeArgumentError } from "./error.js";
34
- import { fileArrayBuffer } from "./file.js";
35
- import { isUint8Array } from "./type.js";
36
- export function isCollection(data) {
37
- if (!Array.isArray(data)) {
38
- return false;
39
- }
40
-
41
- return data.every(entry => typeof entry === 'object' && entry.data && entry.path && isUint8Array(entry.data));
42
- }
43
- export function assertCollection(data) {
44
- if (!isCollection(data)) {
45
- throw new BeeArgumentError('invalid collection', data);
46
- }
47
- }
48
-
49
- function makeFilePath(file) {
50
- if (file.webkitRelativePath && file.webkitRelativePath !== '') {
51
- return file.webkitRelativePath.replace(/.*?\//i, '');
52
- }
53
-
54
- if (file.name) {
55
- return file.name;
56
- }
57
-
58
- throw new TypeError('file is not valid File object');
59
- }
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
- }
74
- }
75
-
76
- return collection;
77
- });
78
- }
79
- /**
80
- * Calculate cumulative size of files
81
- *
82
- * @param fileList list of files to check
83
- * @returns size in bytes
84
- */
85
-
86
- export function getCollectionSize(fileList) {
87
- let sum = 0;
88
-
89
- for (let i = 0; i < fileList.length; i++) {
90
- const file = fileList[i];
91
-
92
- if (file) {
93
- sum += file.size;
94
- }
95
- }
96
-
97
- return sum;
98
- }
@@ -1,169 +0,0 @@
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
- import fs from 'fs';
60
- import path from 'path';
61
- /**
62
- * Creates array in the format of Collection with data loaded from directory on filesystem.
63
- * The function loads all the data into memory!
64
- *
65
- * @param dir path to the directory
66
- */
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
- });
80
- }
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
- }
116
- }
117
-
118
- return collection;
119
- });
120
- }
121
- /**
122
- * Calculate folder size recursively
123
- *
124
- * @param dir the path to the folder to check
125
- * @returns size in bytes
126
- */
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
- }
165
- }
166
-
167
- return size;
168
- });
169
- }
@@ -1,108 +0,0 @@
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
- import { isNodeReadable, isReadableStream } from "./stream.js";
34
- /**
35
- * Validates input and converts to Uint8Array
36
- *
37
- * @param data any string, ArrayBuffer or Uint8Array
38
- */
39
-
40
- export function prepareData(data) {
41
- return __awaiter(this, void 0, void 0, function* () {
42
- if (typeof data === 'string') return new Blob([data], {
43
- type: 'text/plain'
44
- });
45
-
46
- if (data instanceof Uint8Array || data instanceof ArrayBuffer) {
47
- return new Blob([data], {
48
- type: 'application/octet-stream'
49
- });
50
- }
51
-
52
- if (data instanceof Blob) {
53
- return data;
54
- } // Currently it is not possible to stream requests from browsers
55
- // there are already first experiments on this field (Chromium)
56
- // but till it is fully implemented across browsers-land we have to
57
- // buffer the data before sending the requests.
58
-
59
-
60
- if (isNodeReadable(data)) {
61
- return new Promise(resolve => {
62
- const buffers = [];
63
- data.on('data', d => {
64
- buffers.push(d);
65
- });
66
- data.on('end', () => {
67
- resolve(new Blob(buffers, {
68
- type: 'application/octet-stream'
69
- }));
70
- });
71
- });
72
- }
73
-
74
- if (isReadableStream(data)) {
75
- return new Promise(resolve => __awaiter(this, void 0, void 0, function* () {
76
- const reader = data.getReader();
77
- const buffers = [];
78
- let done, value;
79
-
80
- do {
81
- ;
82
- ({
83
- done,
84
- value
85
- } = yield reader.read());
86
-
87
- if (!done) {
88
- buffers.push(value);
89
- }
90
- } while (!done);
91
-
92
- resolve(new Blob(buffers, {
93
- type: 'application/octet-stream'
94
- }));
95
- }));
96
- }
97
-
98
- throw new TypeError('unknown data type');
99
- });
100
- }
101
- export function prepareWebsocketData(data) {
102
- return __awaiter(this, void 0, void 0, function* () {
103
- if (typeof data === 'string') return new TextEncoder().encode(data);
104
- if (data instanceof ArrayBuffer) return new Uint8Array(data);
105
- if (data instanceof Blob) return new Uint8Array(yield new Response(data).arrayBuffer());
106
- throw new TypeError('unknown websocket data type');
107
- });
108
- }