@ethersphere/bee-js 3.2.0 → 3.3.2-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 (193) hide show
  1. package/dist/cjs/bee-debug.js +615 -0
  2. package/dist/cjs/bee.js +922 -0
  3. package/dist/cjs/chunk/bmt.js +55 -0
  4. package/dist/cjs/chunk/cac.js +56 -0
  5. package/dist/cjs/chunk/serialize.js +19 -0
  6. package/dist/cjs/chunk/signer.js +137 -0
  7. package/dist/cjs/chunk/soc.js +172 -0
  8. package/dist/cjs/chunk/span.js +29 -0
  9. package/dist/cjs/feed/index.js +184 -0
  10. package/dist/cjs/feed/json.js +41 -0
  11. package/dist/cjs/feed/topic.js +25 -0
  12. package/dist/cjs/feed/type.js +15 -0
  13. package/dist/cjs/index.js +35 -0
  14. package/dist/cjs/modules/bytes.js +74 -0
  15. package/dist/cjs/modules/bzz.js +131 -0
  16. package/dist/cjs/modules/chunk.js +58 -0
  17. package/dist/cjs/modules/debug/balance.js +77 -0
  18. package/dist/cjs/modules/debug/chequebook.js +167 -0
  19. package/dist/cjs/modules/debug/chunk.js +51 -0
  20. package/dist/cjs/modules/debug/connectivity.js +75 -0
  21. package/dist/cjs/modules/debug/settlements.js +45 -0
  22. package/dist/cjs/modules/debug/stamps.js +89 -0
  23. package/dist/cjs/modules/debug/states.js +47 -0
  24. package/dist/cjs/modules/debug/status.js +153 -0
  25. package/dist/cjs/modules/debug/tag.js +30 -0
  26. package/dist/cjs/modules/debug/transactions.js +81 -0
  27. package/dist/cjs/modules/feed.js +76 -0
  28. package/dist/cjs/modules/pinning.js +84 -0
  29. package/dist/cjs/modules/pss.js +55 -0
  30. package/dist/cjs/modules/soc.js +40 -0
  31. package/dist/cjs/modules/status.js +26 -0
  32. package/dist/cjs/modules/stewardship.js +41 -0
  33. package/dist/cjs/modules/tag.js +96 -0
  34. package/dist/cjs/package.json +8 -0
  35. package/dist/cjs/types/debug.js +9 -0
  36. package/dist/cjs/types/index.js +46 -0
  37. package/dist/cjs/types/ky-options.js +8 -0
  38. package/dist/cjs/types/ky-universal/common.js +8 -0
  39. package/dist/cjs/types/ky-universal/hooks.js +8 -0
  40. package/dist/cjs/types/ky-universal/retry.js +8 -0
  41. package/dist/cjs/utils/bytes.js +107 -0
  42. package/dist/cjs/utils/collection.browser.js +36 -0
  43. package/dist/cjs/utils/collection.js +70 -0
  44. package/dist/cjs/utils/collection.node.js +115 -0
  45. package/dist/cjs/utils/data.browser.js +78 -0
  46. package/dist/cjs/utils/data.js +60 -0
  47. package/dist/cjs/utils/error.js +50 -0
  48. package/dist/cjs/utils/eth.js +211 -0
  49. package/dist/cjs/utils/expose.js +44 -0
  50. package/dist/cjs/utils/file.js +49 -0
  51. package/dist/cjs/utils/hash.js +21 -0
  52. package/dist/cjs/utils/headers.js +59 -0
  53. package/dist/cjs/utils/hex.js +150 -0
  54. package/dist/cjs/utils/http.js +166 -0
  55. package/dist/cjs/utils/merge.js +34 -0
  56. package/dist/cjs/utils/pss.js +18 -0
  57. package/dist/cjs/utils/stamps.js +17 -0
  58. package/dist/cjs/utils/stream.js +146 -0
  59. package/dist/cjs/utils/tar.js +25 -0
  60. package/dist/cjs/utils/type.js +327 -0
  61. package/dist/cjs/utils/uint64.js +29 -0
  62. package/dist/cjs/utils/url.js +56 -0
  63. package/dist/index.browser.min.js +1 -1
  64. package/dist/index.browser.min.js.LICENSE.txt +12 -11
  65. package/dist/index.browser.min.js.map +1 -1
  66. package/dist/mjs/bee-debug.js +609 -0
  67. package/dist/mjs/bee.js +944 -0
  68. package/dist/mjs/chunk/bmt.js +56 -0
  69. package/dist/mjs/chunk/cac.js +52 -0
  70. package/dist/mjs/chunk/serialize.js +15 -0
  71. package/dist/mjs/chunk/signer.js +131 -0
  72. package/dist/mjs/chunk/soc.js +139 -0
  73. package/dist/mjs/chunk/span.js +28 -0
  74. package/dist/mjs/feed/index.js +145 -0
  75. package/dist/mjs/feed/json.js +27 -0
  76. package/dist/mjs/feed/topic.js +21 -0
  77. package/dist/mjs/feed/type.js +10 -0
  78. package/dist/mjs/index.js +7 -0
  79. package/dist/mjs/modules/bytes.js +59 -0
  80. package/dist/mjs/modules/bzz.js +122 -0
  81. package/dist/mjs/modules/chunk.js +45 -0
  82. package/dist/mjs/modules/debug/balance.js +57 -0
  83. package/dist/mjs/modules/debug/chequebook.js +150 -0
  84. package/dist/mjs/modules/debug/chunk.js +35 -0
  85. package/dist/mjs/modules/debug/connectivity.js +45 -0
  86. package/dist/mjs/modules/debug/settlements.js +29 -0
  87. package/dist/mjs/modules/debug/stamps.js +64 -0
  88. package/dist/mjs/modules/debug/states.js +31 -0
  89. package/dist/mjs/modules/debug/status.js +134 -0
  90. package/dist/mjs/modules/debug/tag.js +16 -0
  91. package/dist/mjs/modules/debug/transactions.js +63 -0
  92. package/dist/mjs/modules/feed.js +67 -0
  93. package/dist/mjs/modules/pinning.js +66 -0
  94. package/dist/mjs/modules/pss.js +40 -0
  95. package/dist/mjs/modules/soc.js +31 -0
  96. package/dist/mjs/modules/status.js +12 -0
  97. package/dist/mjs/modules/stewardship.js +24 -0
  98. package/dist/mjs/modules/tag.js +77 -0
  99. package/dist/mjs/package.json +8 -0
  100. package/dist/mjs/types/debug.js +7 -0
  101. package/dist/mjs/types/index.js +37 -0
  102. package/dist/mjs/types/ky-options.js +7 -0
  103. package/dist/mjs/types/ky-universal/common.js +7 -0
  104. package/dist/mjs/types/ky-universal/hooks.js +7 -0
  105. package/dist/mjs/types/ky-universal/retry.js +7 -0
  106. package/dist/mjs/utils/bytes.js +101 -0
  107. package/dist/mjs/utils/collection.browser.js +19 -0
  108. package/dist/mjs/utils/collection.js +64 -0
  109. package/dist/mjs/utils/collection.node.js +74 -0
  110. package/dist/mjs/utils/data.browser.js +73 -0
  111. package/dist/mjs/utils/data.js +43 -0
  112. package/dist/mjs/utils/error.js +56 -0
  113. package/dist/mjs/utils/eth.js +199 -0
  114. package/dist/mjs/utils/expose.js +9 -0
  115. package/dist/mjs/utils/file.js +36 -0
  116. package/dist/mjs/utils/hash.js +17 -0
  117. package/dist/mjs/utils/headers.js +58 -0
  118. package/dist/mjs/utils/hex.js +154 -0
  119. package/dist/mjs/utils/http.js +155 -0
  120. package/dist/mjs/utils/merge.js +36 -0
  121. package/dist/mjs/utils/pss.js +16 -0
  122. package/dist/mjs/utils/stamps.js +17 -0
  123. package/dist/mjs/utils/stream.js +156 -0
  124. package/dist/mjs/utils/tar.js +21 -0
  125. package/dist/mjs/utils/type.js +336 -0
  126. package/dist/mjs/utils/uint64.js +23 -0
  127. package/dist/mjs/utils/url.js +57 -0
  128. package/dist/{src → types}/bee-debug.d.ts +47 -1
  129. package/dist/{src → types}/bee.d.ts +0 -0
  130. package/dist/{src → types}/chunk/bmt.d.ts +0 -0
  131. package/dist/{src → types}/chunk/cac.d.ts +0 -0
  132. package/dist/{src → types}/chunk/serialize.d.ts +0 -0
  133. package/dist/{src → types}/chunk/signer.d.ts +0 -0
  134. package/dist/{src → types}/chunk/soc.d.ts +0 -0
  135. package/dist/{src → types}/chunk/span.d.ts +0 -0
  136. package/dist/{src → types}/feed/index.d.ts +0 -0
  137. package/dist/{src → types}/feed/json.d.ts +0 -0
  138. package/dist/{src → types}/feed/topic.d.ts +0 -0
  139. package/dist/{src → types}/feed/type.d.ts +0 -0
  140. package/dist/{src → types}/index.d.ts +0 -0
  141. package/dist/{src → types}/modules/bytes.d.ts +0 -0
  142. package/dist/{src → types}/modules/bzz.d.ts +0 -0
  143. package/dist/{src → types}/modules/chunk.d.ts +0 -0
  144. package/dist/{src → types}/modules/debug/balance.d.ts +0 -0
  145. package/dist/{src → types}/modules/debug/chequebook.d.ts +0 -0
  146. package/dist/{src → types}/modules/debug/chunk.d.ts +0 -0
  147. package/dist/{src → types}/modules/debug/connectivity.d.ts +0 -0
  148. package/dist/{src → types}/modules/debug/settlements.d.ts +0 -0
  149. package/dist/{src → types}/modules/debug/stamps.d.ts +0 -0
  150. package/dist/{src → types}/modules/debug/states.d.ts +0 -0
  151. package/dist/types/modules/debug/status.d.ts +72 -0
  152. package/dist/{src → types}/modules/debug/tag.d.ts +0 -0
  153. package/dist/{src → types}/modules/debug/transactions.d.ts +0 -0
  154. package/dist/{src → types}/modules/feed.d.ts +0 -0
  155. package/dist/{src → types}/modules/pinning.d.ts +0 -0
  156. package/dist/{src → types}/modules/pss.d.ts +0 -0
  157. package/dist/{src → types}/modules/soc.d.ts +0 -0
  158. package/dist/{src → types}/modules/status.d.ts +0 -0
  159. package/dist/{src → types}/modules/stewardship.d.ts +0 -0
  160. package/dist/{src → types}/modules/tag.d.ts +0 -0
  161. package/dist/{src → types}/types/debug.d.ts +8 -0
  162. package/dist/{src → types}/types/index.d.ts +3 -2
  163. package/dist/types/types/ky-options.d.ts +221 -0
  164. package/dist/types/types/ky-universal/common.d.ts +13 -0
  165. package/dist/types/types/ky-universal/hooks.d.ts +92 -0
  166. package/dist/types/types/ky-universal/retry.d.ts +38 -0
  167. package/dist/{src → types}/utils/bytes.d.ts +0 -0
  168. package/dist/types/utils/collection.browser.d.ts +15 -0
  169. package/dist/{src → types}/utils/collection.d.ts +0 -14
  170. package/dist/types/utils/collection.node.d.ts +15 -0
  171. package/dist/{src → types}/utils/data.browser.d.ts +0 -0
  172. package/dist/{src → types}/utils/data.d.ts +0 -0
  173. package/dist/{src → types}/utils/error.d.ts +0 -0
  174. package/dist/{src → types}/utils/eth.d.ts +0 -0
  175. package/dist/{src → types}/utils/expose.d.ts +2 -1
  176. package/dist/{src → types}/utils/file.d.ts +0 -0
  177. package/dist/{src → types}/utils/hash.d.ts +0 -0
  178. package/dist/{src → types}/utils/headers.d.ts +0 -0
  179. package/dist/{src → types}/utils/hex.d.ts +0 -0
  180. package/dist/{src → types}/utils/http.d.ts +0 -0
  181. package/dist/{src → types}/utils/merge.d.ts +0 -0
  182. package/dist/{src → types}/utils/pss.d.ts +0 -0
  183. package/dist/{src → types}/utils/stamps.d.ts +0 -0
  184. package/dist/{src → types}/utils/stream.d.ts +11 -8
  185. package/dist/{src → types}/utils/tar.d.ts +0 -0
  186. package/dist/{src → types}/utils/type.d.ts +0 -0
  187. package/dist/{src → types}/utils/uint64.d.ts +0 -0
  188. package/dist/{src → types}/utils/url.d.ts +0 -0
  189. package/package.json +55 -36
  190. package/dist/index.min.js +0 -3
  191. package/dist/index.min.js.LICENSE.txt +0 -50
  192. package/dist/index.min.js.map +0 -1
  193. package/dist/src/modules/debug/status.d.ts +0 -24
@@ -0,0 +1,221 @@
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
+ import type { LiteralUnion, Required } from './ky-universal/common';
8
+ import type { Hooks } from './ky-universal/hooks';
9
+ import type { RetryOptions } from './ky-universal/retry';
10
+ export declare type SearchParamsInit = string | string[][] | Record<string, string> | URLSearchParams | undefined;
11
+ export declare type SearchParamsOption = SearchParamsInit | Record<string, string | number | boolean> | Array<Array<string | number | boolean>>;
12
+ export declare type HTTPMethod = 'get' | 'post' | 'put' | 'patch' | 'head' | 'delete';
13
+ export declare type Input = string | URL | Request;
14
+ export interface DownloadProgress {
15
+ percent: number;
16
+ transferredBytes: number;
17
+ /**
18
+ Note: If it's not possible to retrieve the body size, it will be `0`.
19
+ */
20
+ totalBytes: number;
21
+ }
22
+ export declare type KyHeadersInit = HeadersInit | Record<string, string | undefined>;
23
+ /**
24
+ Options are the same as `window.fetch`, with some exceptions.
25
+ */
26
+ export interface Options extends Omit<RequestInit, 'headers'> {
27
+ /**
28
+ HTTP method used to make the request.
29
+
30
+ Internally, the standard methods (`GET`, `POST`, `PUT`, `PATCH`, `HEAD` and `DELETE`) are uppercased in order to avoid server errors due to case sensitivity.
31
+ */
32
+ method?: LiteralUnion<HTTPMethod, string>;
33
+ /**
34
+ HTTP headers used to make the request.
35
+
36
+ You can pass a `Headers` instance or a plain object.
37
+
38
+ You can remove a header with `.extend()` by passing the header with an `undefined` value.
39
+
40
+ @example
41
+ ```
42
+ import ky from 'ky';
43
+
44
+ const url = 'https://sindresorhus.com';
45
+
46
+ const original = ky.create({
47
+ headers: {
48
+ rainbow: 'rainbow',
49
+ unicorn: 'unicorn'
50
+ }
51
+ });
52
+
53
+ const extended = original.extend({
54
+ headers: {
55
+ rainbow: undefined
56
+ }
57
+ });
58
+
59
+ const response = await extended(url).json();
60
+
61
+ console.log('rainbow' in response);
62
+ //=> false
63
+
64
+ console.log('unicorn' in response);
65
+ //=> true
66
+ ```
67
+ */
68
+ headers?: KyHeadersInit;
69
+ /**
70
+ Shortcut for sending JSON. Use this instead of the `body` option.
71
+
72
+ Accepts any plain object or value, which will be `JSON.stringify()`'d and sent in the body with the correct header set.
73
+ */
74
+ json?: unknown;
75
+ /**
76
+ User-defined JSON-parsing function.
77
+
78
+ Use-cases:
79
+ 1. Parse JSON via the [`bourne` package](https://github.com/hapijs/bourne) to protect from prototype pollution.
80
+ 2. Parse JSON with [`reviver` option of `JSON.parse()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse).
81
+
82
+ @default JSON.parse()
83
+
84
+ @example
85
+ ```
86
+ import ky from 'ky';
87
+ import bourne from '@hapijs/bourne';
88
+
89
+ const json = await ky('https://example.com', {
90
+ parseJson: text => bourne(text)
91
+ }).json();
92
+ ```
93
+ */
94
+ parseJson?: (text: string) => unknown;
95
+ /**
96
+ Search parameters to include in the request URL. Setting this will override all existing search parameters in the input URL.
97
+
98
+ Accepts any value supported by [`URLSearchParams()`](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams/URLSearchParams).
99
+ */
100
+ searchParams?: SearchParamsOption;
101
+ /**
102
+ A prefix to prepend to the `input` URL when making the request. It can be any valid URL, either relative or absolute. A trailing slash `/` is optional and will be added automatically, if needed, when it is joined with `input`. Only takes effect when `input` is a string. The `input` argument cannot start with a slash `/` when using this option.
103
+
104
+ Useful when used with `ky.extend()` to create niche-specific Ky-instances.
105
+
106
+ Notes:
107
+ - After `prefixUrl` and `input` are joined, the result is resolved against the [base URL](https://developer.mozilla.org/en-US/docs/Web/API/Node/baseURI) of the page (if any).
108
+ - Leading slashes in `input` are disallowed when using this option to enforce consistency and avoid confusion about how the `input` URL is handled, given that `input` will not follow the normal URL resolution rules when `prefixUrl` is being used, which changes the meaning of a leading slash.
109
+
110
+ @example
111
+ ```
112
+ import ky from 'ky';
113
+
114
+ // On https://example.com
115
+
116
+ const response = await ky('unicorn', {prefixUrl: '/api'});
117
+ //=> 'https://example.com/api/unicorn'
118
+
119
+ const response = await ky('unicorn', {prefixUrl: 'https://cats.com'});
120
+ //=> 'https://cats.com/unicorn'
121
+ ```
122
+ */
123
+ prefixUrl?: URL | string;
124
+ /**
125
+ An object representing `limit`, `methods`, `statusCodes` and `maxRetryAfter` fields for maximum retry count, allowed methods, allowed status codes and maximum [`Retry-After`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After) time.
126
+
127
+ If `retry` is a number, it will be used as `limit` and other defaults will remain in place.
128
+
129
+ If `maxRetryAfter` is set to `undefined`, it will use `options.timeout`. If [`Retry-After`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After) header is greater than `maxRetryAfter`, it will cancel the request.
130
+
131
+ Delays between retries is calculated with the function `0.3 * (2 ** (retry - 1)) * 1000`, where `retry` is the attempt number (starts from 1).
132
+
133
+ @example
134
+ ```
135
+ import ky from 'ky';
136
+
137
+ const json = await ky('https://example.com', {
138
+ retry: {
139
+ limit: 10,
140
+ methods: ['get'],
141
+ statusCodes: [413]
142
+ }
143
+ }).json();
144
+ ```
145
+ */
146
+ retry?: RetryOptions | number;
147
+ /**
148
+ Timeout in milliseconds for getting a response. Can not be greater than 2147483647.
149
+ If set to `false`, there will be no timeout.
150
+
151
+ @default 10000
152
+ */
153
+ timeout?: number | false;
154
+ /**
155
+ Hooks allow modifications during the request lifecycle. Hook functions may be async and are run serially.
156
+ */
157
+ hooks?: Hooks;
158
+ /**
159
+ Throw an `HTTPError` when, after following redirects, the response has a non-2xx status code. To also throw for redirects instead of following them, set the [`redirect`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters) option to `'manual'`.
160
+
161
+ Setting this to `false` may be useful if you are checking for resource availability and are expecting error responses.
162
+
163
+ @default true
164
+ */
165
+ throwHttpErrors?: boolean;
166
+ /**
167
+ Download progress event handler.
168
+
169
+ @param chunk - Note: It's empty for the first call.
170
+
171
+ @example
172
+ ```
173
+ import ky from 'ky';
174
+
175
+ const response = await ky('https://example.com', {
176
+ onDownloadProgress: (progress, chunk) => {
177
+ // Example output:
178
+ // `0% - 0 of 1271 bytes`
179
+ // `100% - 1271 of 1271 bytes`
180
+ console.log(`${progress.percent * 100}% - ${progress.transferredBytes} of ${progress.totalBytes} bytes`);
181
+ }
182
+ });
183
+ ```
184
+ */
185
+ onDownloadProgress?: (progress: DownloadProgress, chunk: Uint8Array) => void;
186
+ /**
187
+ User-defined `fetch` function.
188
+ Has to be fully compatible with the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) standard.
189
+
190
+ Use-cases:
191
+ 1. Use custom `fetch` implementations like [`isomorphic-unfetch`](https://www.npmjs.com/package/isomorphic-unfetch).
192
+ 2. Use the `fetch` wrapper function provided by some frameworks that use server-side rendering (SSR).
193
+
194
+ @default fetch
195
+
196
+ @example
197
+ ```
198
+ import ky from 'ky';
199
+ import fetch from 'isomorphic-unfetch';
200
+
201
+ const json = await ky('https://example.com', {fetch}).json();
202
+ ```
203
+ */
204
+ fetch?: (input: RequestInfo, init?: RequestInit) => Promise<Response>;
205
+ }
206
+ export declare type InternalOptions = Required<Omit<Options, 'hooks' | 'retry'>, 'credentials' | 'fetch' | 'prefixUrl' | 'timeout'> & {
207
+ hooks: Required<Hooks>;
208
+ retry: Required<RetryOptions>;
209
+ prefixUrl: string;
210
+ };
211
+ /**
212
+ Normalized options passed to the `fetch` call and the `beforeRequest` hooks.
213
+ */
214
+ export interface NormalizedOptions extends RequestInit {
215
+ method: RequestInit['method'];
216
+ credentials: RequestInit['credentials'];
217
+ retry: RetryOptions;
218
+ prefixUrl: string;
219
+ onDownloadProgress: Options['onDownloadProgress'];
220
+ }
221
+ export { RetryOptions };
@@ -0,0 +1,13 @@
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 declare type Primitive = null | undefined | string | number | boolean | symbol | bigint;
8
+ export declare type Required<T, K extends keyof T = keyof T> = T & {
9
+ [P in K]-?: T[P];
10
+ };
11
+ export declare type LiteralUnion<LiteralType extends BaseType, BaseType extends Primitive> = LiteralType | (BaseType & {
12
+ _?: never;
13
+ });
@@ -0,0 +1,92 @@
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
+ import type { NormalizedOptions } from '../ky-options';
8
+ export declare const stop: unique symbol;
9
+ export declare type BeforeRequestHook = (request: Request, options: NormalizedOptions) => Request | Response | void | Promise<Request | Response | void>;
10
+ export declare type BeforeRetryState = {
11
+ request: Request;
12
+ response: Response;
13
+ options: NormalizedOptions;
14
+ error: Error;
15
+ retryCount: number;
16
+ };
17
+ export declare type BeforeRetryHook = (options: BeforeRetryState) => typeof stop | void | Promise<typeof stop | void>;
18
+ export declare type AfterResponseHook = (request: Request, options: NormalizedOptions, response: Response) => Response | void | Promise<Response | void>;
19
+ export interface Hooks {
20
+ /**
21
+ This hook enables you to modify the request right before it is sent. Ky will make no further changes to the request after this. The hook function receives normalized input and options as arguments. You could, forf example, modiy `options.headers` here.
22
+
23
+ A [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) can be returned from this hook to completely avoid making a HTTP request. This can be used to mock a request, check an internal cache, etc. An **important** consideration when returning a `Response` from this hook is that all the following hooks will be skipped, so **ensure you only return a `Response` from the last hook**.
24
+
25
+ @default []
26
+ */
27
+ beforeRequest?: BeforeRequestHook[];
28
+ /**
29
+ This hook enables you to modify the request right before retry. Ky will make no further changes to the request after this. The hook function receives an object with the normalized request and options, an error instance, and the retry count. You could, for example, modify `request.headers` here.
30
+
31
+ If the request received a response, the error will be of type `HTTPError` and the `Response` object will be available at `error.response`. Be aware that some types of errors, such as network errors, inherently mean that a response was not received. In that case, the error will not be an instance of `HTTPError`.
32
+
33
+ You can prevent Ky from retrying the request by throwing an error. Ky will not handle it in any way and the error will be propagated to the request initiator. The rest of the `beforeRetry` hooks will not be called in this case. Alternatively, you can return the [`ky.stop`](#ky.stop) symbol to do the same thing but without propagating an error (this has some limitations, see `ky.stop` docs for details).
34
+
35
+ @example
36
+ ```
37
+ import ky from 'ky';
38
+
39
+ const response = await ky('https://example.com', {
40
+ hooks: {
41
+ beforeRetry: [
42
+ async ({request, options, error, retryCount}) => {
43
+ const token = await ky('https://example.com/refresh-token');
44
+ options.headers.set('Authorization', `token ${token}`);
45
+ }
46
+ ]
47
+ }
48
+ });
49
+ ```
50
+
51
+ @default []
52
+ */
53
+ beforeRetry?: BeforeRetryHook[];
54
+ /**
55
+ This hook enables you to read and optionally modify the response. The hook function receives normalized input, options, and a clone of the response as arguments. The return value of the hook function will be used by Ky as the response object if it's an instance of [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response).
56
+
57
+ @default []
58
+
59
+ @example
60
+ ```
61
+ import ky from 'ky';
62
+
63
+ const response = await ky('https://example.com', {
64
+ hooks: {
65
+ afterResponse: [
66
+ (_input, _options, response) => {
67
+ // You could do something with the response, for example, logging.
68
+ log(response);
69
+
70
+ // Or return a `Response` instance to overwrite the response.
71
+ return new Response('A different response', {status: 200});
72
+ },
73
+
74
+ // Or retry with a fresh token on a 403 error
75
+ async (input, options, response) => {
76
+ if (response.status === 403) {
77
+ // Get a fresh token
78
+ const token = await ky('https://example.com/token').text();
79
+
80
+ // Retry with the token
81
+ options.headers.set('Authorization', `token ${token}`);
82
+
83
+ return ky(input, options);
84
+ }
85
+ }
86
+ ]
87
+ }
88
+ });
89
+ ```
90
+ */
91
+ afterResponse?: AfterResponseHook[];
92
+ }
@@ -0,0 +1,38 @@
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 interface RetryOptions {
8
+ /**
9
+ The number of times to retry failed requests.
10
+
11
+ @default 2
12
+ */
13
+ limit?: number;
14
+ /**
15
+ The HTTP methods allowed to retry.
16
+
17
+ @default ['get', 'put', 'head', 'delete', 'options', 'trace']
18
+ */
19
+ methods?: string[];
20
+ /**
21
+ The HTTP status codes allowed to retry.
22
+
23
+ @default [408, 413, 429, 500, 502, 503, 504]
24
+ */
25
+ statusCodes?: number[];
26
+ /**
27
+ The HTTP status codes allowed to retry with a `Retry-After` header.
28
+
29
+ @default [413, 429, 503]
30
+ */
31
+ afterStatusCodes?: number[];
32
+ /**
33
+ If the `Retry-After` header is greater than `maxRetryAfter`, the request will be canceled.
34
+
35
+ @default Infinity
36
+ */
37
+ maxRetryAfter?: number;
38
+ }
File without changes
@@ -0,0 +1,15 @@
1
+ import { Collection } from '../types';
2
+ /**
3
+ * Creates array in the format of Collection with data loaded from directory on filesystem.
4
+ * The function loads all the data into memory!
5
+ *
6
+ * @param dir path to the directory
7
+ */
8
+ export declare function makeCollectionFromFS(dir: string): Promise<Collection<Uint8Array>>;
9
+ /**
10
+ * Calculate folder size recursively
11
+ *
12
+ * @param dir the path to the folder to check
13
+ * @returns size in bytes
14
+ */
15
+ export declare function getFolderSize(dir: string): Promise<number>;
@@ -1,13 +1,6 @@
1
1
  import { Collection } from '../types';
2
2
  export declare function isCollection(data: unknown): data is Collection<Uint8Array>;
3
3
  export declare function assertCollection(data: unknown): asserts data is Collection<Uint8Array>;
4
- /**
5
- * Creates array in the format of Collection with data loaded from directory on filesystem.
6
- * The function loads all the data into memory!
7
- *
8
- * @param dir path to the directory
9
- */
10
- export declare function makeCollectionFromFS(dir: string): Promise<Collection<Uint8Array>>;
11
4
  export declare function makeCollectionFromFileList(fileList: FileList | File[]): Promise<Collection<Uint8Array>>;
12
5
  /**
13
6
  * Calculate cumulative size of files
@@ -16,10 +9,3 @@ export declare function makeCollectionFromFileList(fileList: FileList | File[]):
16
9
  * @returns size in bytes
17
10
  */
18
11
  export declare function getCollectionSize(fileList: FileList | File[]): number;
19
- /**
20
- * Calculate folder size recursively
21
- *
22
- * @param dir the path to the folder to check
23
- * @returns size in bytes
24
- */
25
- export declare function getFolderSize(dir: string): Promise<number>;
@@ -0,0 +1,15 @@
1
+ import { Collection } from '../types';
2
+ /**
3
+ * Creates array in the format of Collection with data loaded from directory on filesystem.
4
+ * The function loads all the data into memory!
5
+ *
6
+ * @param dir path to the directory
7
+ */
8
+ export declare function makeCollectionFromFS(dir: string): Promise<Collection<Uint8Array>>;
9
+ /**
10
+ * Calculate folder size recursively
11
+ *
12
+ * @param dir the path to the folder to check
13
+ * @returns size in bytes
14
+ */
15
+ export declare function getFolderSize(dir: string): Promise<number>;
File without changes
File without changes
File without changes
File without changes
@@ -1,4 +1,5 @@
1
- export { getCollectionSize, getFolderSize } from './collection';
1
+ export { getCollectionSize } from './collection';
2
+ export { getFolderSize } from './collection.node';
2
3
  export { Bytes, FlexBytes, isBytes, assertBytes, isFlexBytes, assertFlexBytes, bytesAtOffset, flexBytesAtOffset, bytesEqual, } from './bytes';
3
4
  export { HexString, PrefixedHexString, makeHexString, hexToBytes, bytesToHex, intToHex, isHexString, assertHexString, assertPrefixedHexString, } from './hex';
4
5
  export { EthAddress, makeEthAddress, makeHexEthAddress, isHexEthAddress, ethToSwarmAddress, toLittleEndian, fromLittleEndian, makeEthereumWalletSigner, } from './eth';
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -1,7 +1,6 @@
1
1
  /// <reference types="node" />
2
- import type { Readable as NodeReadableType } from 'stream';
3
- import { ReadableStream } from 'web-streams-polyfill/ponyfill';
4
- import { ReadableOptions as NodeReadableOptions } from 'readable-stream';
2
+ import { Readable as NodeReadableNative, ReadableOptions as NodeReadableOptions } from 'stream';
3
+ import { ReadableStream } from 'web-streams-polyfill';
5
4
  import { Readable } from '../types';
6
5
  /**
7
6
  * Validates if passed object is either browser's ReadableStream
@@ -9,9 +8,9 @@ import { Readable } from '../types';
9
8
  *
10
9
  * @param entry
11
10
  */
12
- export declare function isReadable(entry: unknown): entry is NodeReadableType;
11
+ export declare function isReadable(entry: unknown): entry is Readable;
13
12
  export declare function isReadableStream(entry: unknown): entry is ReadableStream;
14
- export declare function isNodeReadable(entry: unknown): entry is NodeReadableType;
13
+ export declare function isNodeReadable(entry: unknown): entry is NodeReadableNative;
15
14
  /**
16
15
  * Function that converts Node's Readable into WHATWG ReadableStream
17
16
  *
@@ -22,16 +21,20 @@ export declare function isNodeReadable(entry: unknown): entry is NodeReadableTyp
22
21
  * @licence Apache License 2.0 https://github.com/gwicke/node-web-streams/blob/master/LICENSE
23
22
  * @param nodeStream
24
23
  */
25
- export declare function readableNodeToWeb(nodeStream: NodeReadableType): ReadableStream<Uint8Array>;
24
+ export declare function readableNodeToWeb(nodeStream: NodeReadableNative): ReadableStream<Uint8Array>;
26
25
  /**
27
26
  * Function that converts WHATWG ReadableStream into Node's Readable
28
27
  *
29
28
  * Taken over from https://github.com/gwicke/node-web-streams/blob/master/lib/conversions.js
30
- * Because it uses forked web-streams-polyfill that are outdated.
29
+ * Because it uses forked web-streams-polyfill that is outdated.
30
+ *
31
+ * **Warning!**
32
+ * If you want to use this function in browser you have to polyfill `stream` package with your bundler.
31
33
  *
32
34
  * @author https://github.com/gwicke
33
35
  * @licence Apache License 2.0 https://github.com/gwicke/node-web-streams/blob/master/LICENSE
34
36
  * @param webStream
37
+ * @param options
35
38
  */
36
- export declare function readableWebToNode(webStream: ReadableStream, options?: NodeReadableOptions): NodeReadableType;
39
+ export declare function readableWebToNode(webStream: ReadableStream<unknown>, options?: NodeReadableOptions): NodeReadableNative;
37
40
  export declare function normalizeToReadableStream(stream: Readable): ReadableStream;
File without changes
File without changes
File without changes
File without changes