@ethersphere/bee-js 1.2.1 → 3.0.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 (181) hide show
  1. package/CHANGELOG.md +135 -2
  2. package/README.md +3 -1
  3. package/dist/index.browser.min.js +1 -1
  4. package/dist/index.browser.min.js.LICENSE.txt +51 -0
  5. package/dist/index.browser.min.js.map +1 -1
  6. package/dist/index.min.js +1 -1
  7. package/dist/index.min.js.LICENSE.txt +42 -0
  8. package/dist/index.min.js.map +1 -1
  9. package/dist/src/bee-debug.d.ts +75 -38
  10. package/dist/src/bee.d.ts +88 -82
  11. package/dist/src/chunk/soc.d.ts +6 -6
  12. package/dist/src/feed/index.d.ts +7 -7
  13. package/dist/src/feed/json.d.ts +2 -2
  14. package/dist/src/modules/bytes.d.ts +8 -11
  15. package/dist/src/modules/bzz.d.ts +9 -14
  16. package/dist/src/modules/chunk.d.ts +7 -11
  17. package/dist/src/modules/debug/balance.d.ts +9 -9
  18. package/dist/src/modules/debug/chequebook.d.ts +17 -18
  19. package/dist/src/modules/debug/chunk.d.ts +5 -5
  20. package/dist/src/modules/debug/connectivity.d.ts +7 -7
  21. package/dist/src/modules/debug/settlements.d.ts +5 -5
  22. package/dist/src/modules/debug/stamps.d.ts +7 -5
  23. package/dist/src/modules/debug/states.d.ts +5 -5
  24. package/dist/src/modules/debug/status.d.ts +5 -4
  25. package/dist/src/modules/debug/tag.d.ts +3 -3
  26. package/dist/src/modules/debug/transactions.d.ts +9 -9
  27. package/dist/src/modules/feed.d.ts +5 -5
  28. package/dist/src/modules/pinning.d.ts +9 -9
  29. package/dist/src/modules/pss.d.ts +4 -3
  30. package/dist/src/modules/soc.d.ts +3 -3
  31. package/dist/src/modules/status.d.ts +3 -2
  32. package/dist/src/modules/stewardship.d.ts +4 -4
  33. package/dist/src/modules/tag.d.ts +6 -6
  34. package/dist/src/types/debug.d.ts +4 -2
  35. package/dist/src/types/index.d.ts +71 -19
  36. package/dist/src/utils/bytes.d.ts +1 -1
  37. package/dist/src/utils/data.browser.d.ts +3 -1
  38. package/dist/src/utils/data.d.ts +7 -4
  39. package/dist/src/utils/expose.d.ts +6 -9
  40. package/dist/src/utils/headers.d.ts +3 -3
  41. package/dist/src/utils/http.d.ts +25 -0
  42. package/dist/src/utils/merge.d.ts +8 -0
  43. package/dist/src/utils/pss.d.ts +9 -0
  44. package/dist/src/utils/stream.d.ts +37 -0
  45. package/dist/src/utils/type.d.ts +19 -9
  46. package/package.json +15 -8
  47. package/.babelrc.js +0 -33
  48. package/.depcheckrc.json +0 -27
  49. package/.editorconfig +0 -6
  50. package/.eslintignore +0 -1
  51. package/.eslintrc.js +0 -108
  52. package/.gitattributes +0 -1
  53. package/.github/config.yaml +0 -23
  54. package/.github/workflows/check.yaml +0 -57
  55. package/.github/workflows/publish_npmjs.yaml +0 -20
  56. package/.github/workflows/release_github.yaml +0 -20
  57. package/.github/workflows/tests.yaml +0 -128
  58. package/.huskyrc +0 -5
  59. package/.prettierrc +0 -13
  60. package/.vscode/launch.json +0 -49
  61. package/.vscode/settings.json +0 -39
  62. package/CODEOWNERS +0 -1
  63. package/CODE_OF_CONDUCT.md +0 -76
  64. package/commitlint.config.js +0 -3
  65. package/dist/src/modules/stamps.d.ts +0 -4
  66. package/dist/src/utils/hooks.d.ts +0 -31
  67. package/dist/src/utils/safe-axios.d.ts +0 -8
  68. package/jest-puppeteer.config.js +0 -5
  69. package/jest.config.ts +0 -170
  70. package/src/bee-debug.ts +0 -440
  71. package/src/bee.ts +0 -941
  72. package/src/chunk/bmt.ts +0 -55
  73. package/src/chunk/cac.ts +0 -79
  74. package/src/chunk/serialize.ts +0 -16
  75. package/src/chunk/signer.ts +0 -141
  76. package/src/chunk/soc.ts +0 -190
  77. package/src/chunk/span.ts +0 -33
  78. package/src/feed/index.ts +0 -221
  79. package/src/feed/json.ts +0 -32
  80. package/src/feed/topic.ts +0 -23
  81. package/src/feed/type.ts +0 -12
  82. package/src/index.ts +0 -24
  83. package/src/modules/bytes.ts +0 -75
  84. package/src/modules/bzz.ts +0 -184
  85. package/src/modules/chunk.ts +0 -75
  86. package/src/modules/debug/balance.ts +0 -63
  87. package/src/modules/debug/chequebook.ts +0 -174
  88. package/src/modules/debug/chunk.ts +0 -39
  89. package/src/modules/debug/connectivity.ts +0 -61
  90. package/src/modules/debug/settlements.ts +0 -33
  91. package/src/modules/debug/stamps.ts +0 -69
  92. package/src/modules/debug/states.ts +0 -35
  93. package/src/modules/debug/status.ts +0 -34
  94. package/src/modules/debug/tag.ts +0 -19
  95. package/src/modules/debug/transactions.ts +0 -79
  96. package/src/modules/feed.ts +0 -92
  97. package/src/modules/pinning.ts +0 -74
  98. package/src/modules/pss.ts +0 -48
  99. package/src/modules/soc.ts +0 -41
  100. package/src/modules/stamps.ts +0 -59
  101. package/src/modules/status.ts +0 -13
  102. package/src/modules/stewardship.ts +0 -21
  103. package/src/modules/tag.ts +0 -83
  104. package/src/types/axios/index.d.ts +0 -18
  105. package/src/types/debug.ts +0 -204
  106. package/src/types/index.ts +0 -497
  107. package/src/types/tar-js.d.ts +0 -1
  108. package/src/types/webpack-bundle-analyzer/index.d.ts +0 -13
  109. package/src/utils/bytes.ts +0 -144
  110. package/src/utils/collection.ts +0 -151
  111. package/src/utils/data.browser.ts +0 -24
  112. package/src/utils/data.ts +0 -35
  113. package/src/utils/error.ts +0 -23
  114. package/src/utils/eth.ts +0 -229
  115. package/src/utils/expose.ts +0 -10
  116. package/src/utils/file.ts +0 -40
  117. package/src/utils/hash.ts +0 -16
  118. package/src/utils/headers.ts +0 -63
  119. package/src/utils/hex.ts +0 -186
  120. package/src/utils/hooks.ts +0 -89
  121. package/src/utils/safe-axios.ts +0 -98
  122. package/src/utils/tar.ts +0 -30
  123. package/src/utils/type.ts +0 -302
  124. package/src/utils/uint64.ts +0 -31
  125. package/src/utils/url.ts +0 -52
  126. package/test/bee.sh +0 -187
  127. package/test/data/1.txt +0 -1
  128. package/test/data/2.txt +0 -0
  129. package/test/data/empty +0 -0
  130. package/test/data/sub/3.txt +0 -1
  131. package/test/data/sub//303/251 +0 -0
  132. package/test/data/sub//360/237/230/216 +0 -0
  133. package/test/integration/bee-class.browser.spec.ts +0 -215
  134. package/test/integration/bee-class.spec.ts +0 -595
  135. package/test/integration/bee-debug-class.spec.ts +0 -85
  136. package/test/integration/chunk/bmt.spec.ts +0 -33
  137. package/test/integration/chunk/cac.spec.ts +0 -27
  138. package/test/integration/chunk/soc.spec.ts +0 -38
  139. package/test/integration/feed/index.spec.ts +0 -84
  140. package/test/integration/modules/bytes.spec.ts +0 -23
  141. package/test/integration/modules/bzz.spec.ts +0 -270
  142. package/test/integration/modules/chunk.spec.ts +0 -29
  143. package/test/integration/modules/debug/balance.spec.ts +0 -70
  144. package/test/integration/modules/debug/chequebook.spec.ts +0 -64
  145. package/test/integration/modules/debug/connectivity.spec.ts +0 -69
  146. package/test/integration/modules/debug/settlements.spec.ts +0 -34
  147. package/test/integration/modules/debug/states.spec.ts +0 -34
  148. package/test/integration/modules/debug/status.spec.ts +0 -65
  149. package/test/integration/modules/debug/tag.spec.ts +0 -27
  150. package/test/integration/modules/feed.spec.ts +0 -61
  151. package/test/integration/modules/pinning.spec.ts +0 -155
  152. package/test/integration/modules/pss.spec.ts +0 -92
  153. package/test/integration/modules/status.spec.ts +0 -10
  154. package/test/integration/modules/stewardship.spec.ts +0 -32
  155. package/test/integration/modules/tag.spec.ts +0 -51
  156. package/test/test-type-sequencer.js +0 -36
  157. package/test/testpage/testpage.html +0 -20
  158. package/test/unit/assertions.ts +0 -376
  159. package/test/unit/bee-class.spec.ts +0 -685
  160. package/test/unit/bee-debug-class.spec.ts +0 -365
  161. package/test/unit/chunk/bmt.spec.ts +0 -16
  162. package/test/unit/chunk/cac.spec.ts +0 -29
  163. package/test/unit/chunk/serialize.spec.ts +0 -24
  164. package/test/unit/chunk/signer.spec.ts +0 -140
  165. package/test/unit/chunk/soc.spec.ts +0 -25
  166. package/test/unit/chunk/span.spec.ts +0 -38
  167. package/test/unit/feed/json.spec.ts +0 -73
  168. package/test/unit/nock.ts +0 -134
  169. package/test/unit/utils/bytes.spec.ts +0 -32
  170. package/test/unit/utils/collection.spec.ts +0 -22
  171. package/test/unit/utils/eth.spec.ts +0 -224
  172. package/test/unit/utils/hex.spec.ts +0 -115
  173. package/test/unit/utils/hooks.spec.ts +0 -179
  174. package/test/unit/utils/safe-axios.spec.ts +0 -20
  175. package/test/unit/utils/type.spec.ts +0 -32
  176. package/test/unit/utils/uint64.spec.ts +0 -102
  177. package/test/utils.ts +0 -292
  178. package/tsconfig.json +0 -18
  179. package/tsconfig.test.json +0 -11
  180. package/typedoc.json +0 -7
  181. package/webpack.config.ts +0 -141
@@ -1,17 +1,23 @@
1
- import type { AxiosRequestConfig } from 'axios';
2
- import { Identifier, SingleOwnerChunk } from '../chunk/soc';
3
- import { ChunkReference, FeedUploadOptions } from '../feed';
4
- import { FeedType } from '../feed/type';
5
- import { FeedUpdateOptions, FetchFeedUpdateResponse } from '../modules/feed';
6
- import { Bytes } from '../utils/bytes';
7
- import { BeeError } from '../utils/error';
8
- import { EthAddress, HexEthAddress } from '../utils/eth';
9
- import { HexString } from '../utils/hex';
1
+ /// <reference types="node" />
2
+ import type { Identifier, SingleOwnerChunk } from '../chunk/soc';
3
+ import type { ChunkReference, FeedUploadOptions } from '../feed';
4
+ import type { FeedType } from '../feed/type';
5
+ import type { FeedUpdateOptions, FetchFeedUpdateResponse } from '../modules/feed';
6
+ import type { Bytes } from '../utils/bytes';
7
+ import type { BeeError } from '../utils/error';
8
+ import type { EthAddress, HexEthAddress } from '../utils/eth';
9
+ import type { HexString } from '../utils/hex';
10
+ import type ky from 'ky-universal';
11
+ import type { Readable as NativeReadable } from 'stream';
12
+ import type { Readable as CompatibilityReadable } from 'readable-stream';
13
+ import type { ReadableStream as ReadableStreamPonyfill } from 'web-streams-polyfill/ponyfill';
10
14
  export * from './debug';
15
+ export declare type Ky = typeof ky;
11
16
  export interface Dictionary<T> {
12
17
  [Key: string]: T;
13
18
  }
14
19
  export declare const ADDRESS_HEX_LENGTH = 64;
20
+ export declare const PSS_TARGET_HEX_LENGTH_MAX = 6;
15
21
  export declare const PUBKEY_HEX_LENGTH = 66;
16
22
  export declare const BATCH_ID_HEX_LENGTH = 64;
17
23
  export declare const REFERENCE_HEX_LENGTH = 64;
@@ -39,6 +45,11 @@ export declare const TAGS_LIMIT_MAX = 1000;
39
45
  export declare type Reference = HexString<typeof REFERENCE_HEX_LENGTH> | HexString<typeof ENCRYPTED_REFERENCE_HEX_LENGTH>;
40
46
  export declare type PublicKey = HexString<typeof PUBKEY_HEX_LENGTH>;
41
47
  export declare type Address = HexString<typeof ADDRESS_HEX_LENGTH>;
48
+ /**
49
+ * Type representing Readable stream that abstracts away implementation especially the difference between
50
+ * browser and NodeJS versions as both are supported.
51
+ */
52
+ export declare type Readable = NativeReadable | CompatibilityReadable | ReadableStream | ReadableStreamPonyfill;
42
53
  /**
43
54
  * BatchId is result of keccak256 hash so 64 hex string without prefix.
44
55
  */
@@ -48,13 +59,56 @@ export declare type BatchId = HexString<typeof BATCH_ID_HEX_LENGTH>;
48
59
  * It represents PSS Address Prefix that is used to define address neighborhood that will receive the PSS message.
49
60
  */
50
61
  export declare type AddressPrefix = HexString;
51
- export interface BeeOptions {
62
+ export interface RequestOptions {
63
+ /**
64
+ * Timeout of requests in milliseconds
65
+ */
66
+ timeout?: number;
67
+ /**
68
+ * Configure backoff mechanism for requests retries.
69
+ * Specifies how many retries will be performed before failing a request.
70
+ * Retries are performed for GET, PUT, HEAD, DELETE, OPTIONS and TRACE requests.
71
+ * Default is 2.
72
+ */
73
+ retry?: number;
74
+ /**
75
+ * User defined Fetch compatible function
76
+ */
77
+ fetch?: Fetch;
78
+ }
79
+ export interface BeeOptions extends RequestOptions {
52
80
  /**
53
81
  * Signer object or private key of the Signer in form of either hex string or Uint8Array that will be default signer for the instance.
54
82
  */
55
83
  signer?: Signer | Uint8Array | string;
84
+ /**
85
+ * Object that contains default headers that will be present
86
+ * in all outgoing bee-js requests for instance of Bee class.
87
+ */
88
+ defaultHeaders?: Record<string, string>;
89
+ /**
90
+ * Function that registers listener callback for all outgoing HTTP requests that Bee instance makes.
91
+ */
92
+ onRequest?: HookCallback<BeeRequest>;
93
+ /**
94
+ * Function that registers listener callback for all incoming HTTP responses that Bee instance made.
95
+ */
96
+ onResponse?: HookCallback<BeeResponse>;
97
+ }
98
+ /**
99
+ * Result of upload calls.
100
+ */
101
+ export interface UploadResult {
102
+ /**
103
+ * Reference of the uploaded data
104
+ */
105
+ reference: Reference;
106
+ /**
107
+ * Automatically created tag's UID.
108
+ */
109
+ tagUid: number;
56
110
  }
57
- export interface UploadOptions {
111
+ export interface UploadOptions extends RequestOptions {
58
112
  /**
59
113
  * Will pin the data locally in the Bee node as well.
60
114
  *
@@ -84,8 +138,6 @@ export interface UploadOptions {
84
138
  * @link Tag
85
139
  */
86
140
  tag?: number;
87
- /** Alter default options of axios HTTP client */
88
- axiosOptions?: AxiosRequestConfig;
89
141
  }
90
142
  export interface FileUploadOptions extends UploadOptions {
91
143
  /**
@@ -150,7 +202,7 @@ export interface Tag {
150
202
  */
151
203
  startedAt: string;
152
204
  }
153
- export interface AllTagsOptions {
205
+ export interface AllTagsOptions extends RequestOptions {
154
206
  limit?: number;
155
207
  offset?: number;
156
208
  }
@@ -215,17 +267,16 @@ export interface BeeGenericResponse {
215
267
  export interface ReferenceResponse {
216
268
  reference: Reference;
217
269
  }
218
- export declare type HttpMethod = 'get' | 'GET' | 'delete' | 'DELETE' | 'post' | 'POST' | 'patch' | 'PATCH';
270
+ export declare type HttpMethod = 'GET' | 'DELETE' | 'POST' | 'PATCH' | 'PUT';
271
+ export declare type HookCallback<V> = (value: V) => void | Promise<void>;
219
272
  export interface BeeRequest {
220
273
  url: string;
221
274
  method: HttpMethod;
222
275
  headers?: Record<string, string>;
223
276
  params?: Record<string, unknown>;
224
- data?: unknown;
225
277
  }
226
278
  export interface BeeResponse {
227
279
  headers: Record<string, string>;
228
- data: unknown;
229
280
  status: number;
230
281
  statusText?: string;
231
282
  request: BeeRequest;
@@ -251,7 +302,7 @@ export interface FeedReader {
251
302
  */
252
303
  download(options?: FeedUpdateOptions): Promise<FetchFeedUpdateResponse>;
253
304
  }
254
- export interface JsonFeedOptions {
305
+ export interface JsonFeedOptions extends RequestOptions {
255
306
  /**
256
307
  * Valid only for `get` action, where either this `address` or `signer` has
257
308
  * to be specified.
@@ -350,7 +401,7 @@ export interface TransactionInfo {
350
401
  /**
351
402
  * Options for creation of postage batch
352
403
  */
353
- export interface PostageBatchOptions {
404
+ export interface PostageBatchOptions extends RequestOptions {
354
405
  /**
355
406
  * Sets label for the postage batch
356
407
  */
@@ -419,3 +470,4 @@ interface JsonMap {
419
470
  [key: string]: AnyJson;
420
471
  }
421
472
  declare type JsonArray = Array<AnyJson>;
473
+ declare type Fetch = (input: RequestInfo, init?: RequestInit) => Promise<Response>;
@@ -22,7 +22,7 @@ export interface FlexBytes<Min extends number, Max extends number> extends Uint8
22
22
  readonly __max__: Max;
23
23
  }
24
24
  /**
25
- * Type guard for Bytes<T> type
25
+ * Type guard for `Bytes<T>` type
26
26
  *
27
27
  * @param b The byte array
28
28
  * @param length The length of the byte array
@@ -1,7 +1,9 @@
1
+ import { Readable } from '../types';
2
+ import Blob from 'cross-blob';
1
3
  /**
2
4
  * Validates input and converts to Uint8Array
3
5
  *
4
6
  * @param data any string, ArrayBuffer or Uint8Array
5
7
  */
6
- export declare function prepareData(data: string | ArrayBuffer | Uint8Array): Uint8Array | never;
8
+ export declare function prepareData(data: string | Blob | ArrayBuffer | Uint8Array | Readable): Promise<Blob | ReadableStream<Uint8Array> | never>;
7
9
  export declare function prepareWebsocketData(data: string | ArrayBuffer | Blob): Promise<Uint8Array> | never;
@@ -1,10 +1,13 @@
1
- /// <reference types="node" />
2
- import { Readable } from 'stream';
3
1
  import type { Data } from 'ws';
2
+ import Blob from 'cross-blob';
3
+ import { Readable } from '../types';
4
4
  /**
5
- * Validates input and converts to Uint8Array or Readable
5
+ * Prepare data for valid input for node-fetch.
6
+ *
7
+ * node-fetch is not using WHATWG ReadableStream but NodeJS Readable so we need to convert in case of ReadableStream,
8
+ * but the typings are set to use ReadableStream so hence why type conversion here.
6
9
  *
7
10
  * @param data any string, ArrayBuffer, Uint8Array or Readable
8
11
  */
9
- export declare function prepareData(data: string | ArrayBuffer | Uint8Array | Readable): Uint8Array | Readable | never;
12
+ export declare function prepareData(data: string | ArrayBuffer | Uint8Array | Readable): Promise<Blob | ReadableStream<Uint8Array> | never>;
10
13
  export declare function prepareWebsocketData(data: Data | Blob): Promise<Uint8Array> | never;
@@ -1,10 +1,7 @@
1
- export * as Collections from './collection';
2
- export * as Bytes from './bytes';
3
- export * as Data from './data';
4
- export * as File from './file';
5
- export * as Hex from './hex';
6
- export * as Tar from './tar';
7
- export * as Eth from './eth';
8
- export * as Hooks from './hooks';
9
- export { setDefaultHeaders } from './safe-axios';
1
+ export { getCollectionSize, getFolderSize } from './collection';
2
+ export { Bytes, FlexBytes, isBytes, assertBytes, isFlexBytes, assertFlexBytes, bytesAtOffset, flexBytesAtOffset, bytesEqual, } from './bytes';
3
+ export { HexString, PrefixedHexString, makeHexString, hexToBytes, bytesToHex, intToHex, isHexString, assertHexString, assertPrefixedHexString, } from './hex';
4
+ export { EthAddress, makeEthAddress, makeHexEthAddress, isHexEthAddress, ethToSwarmAddress, toLittleEndian, fromLittleEndian, makeEthereumWalletSigner, } from './eth';
5
+ export { readableWebToNode, readableNodeToWeb, isReadableStream, isNodeReadable, normalizeToReadableStream, isReadable, } from './stream';
10
6
  export { keccak256Hash } from './hash';
7
+ export { makeMaxTarget } from './pss';
@@ -1,3 +1,3 @@
1
- import { BatchId, Dictionary, FileHeaders, UploadHeaders, UploadOptions } from '../types';
2
- export declare function readFileHeaders(headers: Dictionary<string>): FileHeaders;
3
- export declare function extractUploadHeaders(postageBatchId: BatchId, options?: UploadOptions): UploadHeaders;
1
+ import { BatchId, FileHeaders, UploadOptions } from '../types';
2
+ export declare function readFileHeaders(headers: Headers): FileHeaders;
3
+ export declare function extractUploadHeaders(postageBatchId: BatchId, options?: UploadOptions): Record<string, string>;
@@ -0,0 +1,25 @@
1
+ import type { BeeRequest, BeeResponse, HookCallback, Ky } from '../types';
2
+ import { Options as KyOptions } from 'ky-universal';
3
+ interface HttpOptions extends Omit<KyOptions, 'searchParams'> {
4
+ path: string;
5
+ responseType?: 'json' | 'arraybuffer' | 'stream';
6
+ /**
7
+ * Overridden parameter that allows undefined as a value.
8
+ */
9
+ searchParams?: Record<string, string | number | boolean | undefined>;
10
+ }
11
+ interface KyResponse<T> extends Response {
12
+ data: T;
13
+ }
14
+ export declare function wrapRequestClosure(cb: HookCallback<BeeRequest>): (request: Request) => Promise<void>;
15
+ export declare function wrapResponseClosure(cb: HookCallback<BeeResponse>): (request: Request, options: unknown, response: Response) => Promise<void>;
16
+ /**
17
+ * Filters out entries that has undefined value from headers object.
18
+ * Modifies the original object!
19
+ *
20
+ * @param obj
21
+ */
22
+ export declare function filterHeaders(obj?: object): Record<string, string> | undefined;
23
+ export declare function http<T>(ky: Ky, config: HttpOptions): Promise<KyResponse<T>>;
24
+ export declare function makeDefaultKy(kyConfig: KyOptions): Ky;
25
+ export {};
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Function that deep merges objects
3
+ *
4
+ * @copyright https://github.com/sindresorhus/ky/blob/b3c9e88fa49d50150dbb6e6b771b4af56cb40c98/source/utils/merge.ts
5
+ * @licence MIT
6
+ * @param sources
7
+ */
8
+ export declare function deepMerge<T>(...sources: Array<Partial<T> | undefined>): T;
@@ -0,0 +1,9 @@
1
+ import { AddressPrefix } from '../types';
2
+ /**
3
+ * Utility function that for given strings/reference takes the most specific
4
+ * target that Bee node will except.
5
+ *
6
+ * @param target is a non-prefixed hex string Bee address
7
+ * @see [Bee docs - PSS](https://docs.ethswarm.org/docs/dapps-on-swarm/pss)
8
+ */
9
+ export declare function makeMaxTarget(target: string): AddressPrefix;
@@ -0,0 +1,37 @@
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';
5
+ import { Readable } from '../types';
6
+ /**
7
+ * Validates if passed object is either browser's ReadableStream
8
+ * or Node's Readable.
9
+ *
10
+ * @param entry
11
+ */
12
+ export declare function isReadable(entry: unknown): entry is NodeReadableType;
13
+ export declare function isReadableStream(entry: unknown): entry is ReadableStream;
14
+ export declare function isNodeReadable(entry: unknown): entry is NodeReadableType;
15
+ /**
16
+ * Function that converts Node's Readable into WHATWG ReadableStream
17
+ *
18
+ * Taken over from https://github.com/gwicke/node-web-streams/blob/master/lib/conversions.js
19
+ * Because it uses forked web-streams-polyfill that are outdated.
20
+ *
21
+ * @author https://github.com/gwicke
22
+ * @licence Apache License 2.0 https://github.com/gwicke/node-web-streams/blob/master/LICENSE
23
+ * @param nodeStream
24
+ */
25
+ export declare function readableNodeToWeb(nodeStream: NodeReadableType): ReadableStream<Uint8Array>;
26
+ /**
27
+ * Function that converts WHATWG ReadableStream into Node's Readable
28
+ *
29
+ * 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.
31
+ *
32
+ * @author https://github.com/gwicke
33
+ * @licence Apache License 2.0 https://github.com/gwicke/node-web-streams/blob/master/LICENSE
34
+ * @param webStream
35
+ */
36
+ export declare function readableWebToNode(webStream: ReadableStream, options?: NodeReadableOptions): NodeReadableType;
37
+ export declare function normalizeToReadableStream(stream: Readable): ReadableStream;
@@ -1,17 +1,25 @@
1
- /// <reference types="node" />
2
- import { Readable } from 'stream';
3
- import { Address, AddressPrefix, BatchId, CollectionUploadOptions, FileUploadOptions, NumberString, PssMessageHandler, PublicKey, Reference, Tag, UploadOptions, AllTagsOptions, TransactionHash } from '../types';
4
- export declare function isReadable(entry: unknown): entry is Readable;
1
+ import { Address, AddressPrefix, AllTagsOptions, BatchId, CollectionUploadOptions, FileUploadOptions, NumberString, PssMessageHandler, PublicKey, Readable, Reference, Tag, UploadOptions, TransactionHash, RequestOptions, PostageBatchOptions, CashoutOptions } from '../types';
5
2
  export declare function isUint8Array(obj: unknown): obj is Uint8Array;
6
3
  export declare function isInteger(value: unknown): value is number | NumberString;
7
4
  export declare function isObject(value: unknown): value is Record<string, unknown>;
8
- export declare function isStrictlyObject(value: unknown): value is Record<string, unknown>;
9
- export declare function assertBoolean(value: unknown): asserts value is boolean;
10
- export declare function assertInteger(value: unknown): asserts value is number | NumberString;
5
+ /**
6
+ * Generally it is discouraged to use `object` type, but in this case I think
7
+ * it is best to do so as it is possible to easily convert from `object`to other
8
+ * types, which will be usually the case after asserting that the object is
9
+ * strictly object. With for example Record<string, unknown> you have to first
10
+ * cast it to `unknown` which I think bit defeat the purpose.
11
+ *
12
+ * @param value
13
+ */
14
+ export declare function isStrictlyObject(value: unknown): value is object;
15
+ export declare function assertStrictlyObject(value: unknown, name?: string): asserts value is object;
16
+ export declare function assertBoolean(value: unknown, name?: string): asserts value is boolean;
17
+ export declare function assertInteger(value: unknown, name?: string): asserts value is number | NumberString;
11
18
  export declare function assertNonNegativeInteger(value: unknown, name?: string): asserts value is number | NumberString;
12
19
  export declare function assertReference(value: unknown): asserts value is Reference;
13
20
  export declare function assertAddress(value: unknown): asserts value is Address;
14
21
  export declare function assertBatchId(value: unknown): asserts value is BatchId;
22
+ export declare function assertRequestOptions(value: unknown, name?: string): asserts value is RequestOptions;
15
23
  export declare function assertUploadOptions(value: unknown, name?: string): asserts value is UploadOptions;
16
24
  export declare function assertFileUploadOptions(value: unknown): asserts value is FileUploadOptions;
17
25
  export declare function assertCollectionUploadOptions(value: unknown): asserts value is CollectionUploadOptions;
@@ -20,6 +28,8 @@ export declare function assertTag(value: unknown): asserts value is Tag;
20
28
  export declare function assertAddressPrefix(value: unknown): asserts value is AddressPrefix;
21
29
  export declare function assertPssMessageHandler(value: unknown): asserts value is PssMessageHandler;
22
30
  export declare function assertPublicKey(value: unknown): asserts value is PublicKey;
31
+ export declare function assertPostageBatchOptions(value: unknown): asserts value is PostageBatchOptions;
32
+ export declare function assertCashoutOptions(value: unknown): asserts value is CashoutOptions;
23
33
  /**
24
34
  * Check whether the given parameter is valid data to upload
25
35
  * @param value
@@ -36,10 +46,10 @@ export declare function assertFileData(value: unknown): asserts value is string
36
46
  * Checks whether optional options for AllTags query are valid
37
47
  * @param options
38
48
  */
39
- export declare function assertAllTagsOptions(options: unknown): asserts options is AllTagsOptions;
49
+ export declare function assertAllTagsOptions(entry: unknown): asserts entry is AllTagsOptions;
40
50
  /**
41
51
  * Utility functions that return Tag UID
42
52
  * @param tagUid
43
53
  */
44
- export declare function makeTagUid(tagUid: number | Tag): number;
54
+ export declare function makeTagUid(tagUid: number | Tag | string | null | undefined): number;
45
55
  export declare function assertTransactionHash(transactionHash: unknown): asserts transactionHash is TransactionHash;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ethersphere/bee-js",
3
- "version": "1.2.1",
3
+ "version": "3.0.0",
4
4
  "description": "Javascript client for Bee",
5
5
  "keywords": [
6
6
  "bee",
@@ -27,9 +27,12 @@
27
27
  "./dist/index.min.js": "./dist/index.browser.min.js",
28
28
  "data": "data.browser"
29
29
  },
30
+ "files": [
31
+ "dist"
32
+ ],
30
33
  "types": "dist/src/index.d.ts",
31
34
  "scripts": {
32
- "prepare": "rimraf dist && npm run compile:types && npm run compile:browser --env mode=production && npm run compile:node --env mode=production",
35
+ "prepublishOnly": "rimraf dist && npm run compile:types && npm run compile:browser --env mode=production && npm run compile:node --env mode=production",
33
36
  "compile:node": "webpack --progress --env target=node",
34
37
  "compile:types": "tsc --emitDeclarationOnly --declaration",
35
38
  "compile:browser": "webpack --progress --env target=web",
@@ -38,7 +41,7 @@
38
41
  "test": "npm run compile:browser && jest --verbose --selectProjects=node:unit node:integration dom:integration --config=jest.config.ts",
39
42
  "test:integration:browser": "npm run compile:browser && jest --verbose --selectProjects=dom:integration --config=jest.config.ts",
40
43
  "test:integration:node": "jest --verbose --selectProjects=node:integration --config=jest.config.ts",
41
- "test:integration": "npm run compile:browser && jest --verbose --selectProjects=node:integration dom:integration --config=jest.config.ts ",
44
+ "test:integration": "npm run compile:browser && jest --verbose --selectProjects=node:integration dom:integration --config=jest.config.ts",
42
45
  "test:unit": "jest --verbose --selectProjects=node:unit --config=jest.config.ts ",
43
46
  "test:node": "jest --verbose --selectProjects=node:unit node:integration --config=jest.config.ts",
44
47
  "test:browser": "npm run test:integration:browser",
@@ -48,11 +51,18 @@
48
51
  "depcheck": "depcheck ."
49
52
  },
50
53
  "dependencies": {
51
- "axios": "^0.21.1",
54
+ "@types/readable-stream": "^2.3.11",
55
+ "bufferutil": "^4.0.3",
56
+ "cross-blob": "^2.0.1",
52
57
  "elliptic": "^6.5.4",
53
58
  "isomorphic-ws": "^4.0.1",
54
59
  "js-sha3": "^0.8.0",
60
+ "ky": "^0.25.1",
61
+ "ky-universal": "^0.8.2",
62
+ "readable-stream": "^3.6.0",
55
63
  "tar-js": "^0.3.0",
64
+ "utf-8-validate": "^5.0.5",
65
+ "web-streams-polyfill": "^3.1.0",
56
66
  "ws": "^7.5.0"
57
67
  },
58
68
  "devDependencies": {
@@ -75,14 +85,12 @@
75
85
  "@types/jest-environment-puppeteer": "^4.4.1",
76
86
  "@types/node": "^15.12.4",
77
87
  "@types/puppeteer": "^5.4.3",
78
- "@types/tar-stream": "^2.2.0",
79
88
  "@types/terser-webpack-plugin": "^5.0.3",
80
89
  "@types/ws": "^7.4.5",
81
90
  "@typescript-eslint/eslint-plugin": "^4.28.0",
82
91
  "@typescript-eslint/parser": "^4.28.0",
83
92
  "babel-jest": "^27.0.5",
84
93
  "babel-loader": "^8.2.2",
85
- "bufferutil": "^4.0.3",
86
94
  "debug": "^4.3.1",
87
95
  "depcheck": "^1.4.0",
88
96
  "eslint": "^7.29.0",
@@ -103,7 +111,6 @@
103
111
  "typedoc": "^0.21.0",
104
112
  "typedoc-plugin-markdown": "^3.10.0",
105
113
  "typescript": "^4.3.4",
106
- "utf-8-validate": "^5.0.5",
107
114
  "webpack": "^5.40.0",
108
115
  "webpack-bundle-analyzer": "^4.4.1",
109
116
  "webpack-cli": "^4.7.2"
@@ -111,6 +118,6 @@
111
118
  "engines": {
112
119
  "node": ">=12.0.0",
113
120
  "npm": ">=6.0.0",
114
- "bee": "1.1.0-80cdea19"
121
+ "bee": "1.4.0-8fa696a8"
115
122
  }
116
123
  }
package/.babelrc.js DELETED
@@ -1,33 +0,0 @@
1
- 'use strict'
2
-
3
- module.exports = function (api) {
4
- const targets = '>1% or node >=10 and not ie 11 and not dead'
5
- api.cache(true)
6
- api.cacheDirectory = true
7
-
8
- return {
9
- presets: [
10
- '@babel/preset-typescript',
11
- [
12
- '@babel/preset-env',
13
- {
14
- corejs: 3,
15
- useBuiltIns: 'entry',
16
- modules: 'commonjs',
17
- bugfixes: true,
18
- targets
19
- }
20
- ]
21
- ],
22
- plugins: [
23
- '@babel/plugin-proposal-class-properties',
24
- [
25
- '@babel/plugin-transform-runtime',
26
- {
27
- helpers: false,
28
- regenerator: true
29
- }
30
- ]
31
- ]
32
- }
33
- }
package/.depcheckrc.json DELETED
@@ -1,27 +0,0 @@
1
- {
2
- "ignores": [
3
- "@babel/core",
4
- "@babel/plugin-proposal-class-properties",
5
- "@babel/plugin-transform-runtime",
6
- "@babel/preset-env",
7
- "@babel/preset-typescript",
8
- "@commitlint/cli",
9
- "@commitlint/config-conventional",
10
- "@types/content-disposition",
11
- "@types/debug",
12
- "@types/expect-puppeteer",
13
- "@types/jest",
14
- "@types/jest-environment-puppeteer",
15
- "@types/puppeteer",
16
- "@types/tar-stream",
17
- "babel-jest",
18
- "babel-loader",
19
- "debug",
20
- "husky",
21
- "jest-puppeteer",
22
- "puppeteer",
23
- "ts-node",
24
- "typedoc-plugin-markdown",
25
- "webpack-cli"
26
- ]
27
- }
package/.editorconfig DELETED
@@ -1,6 +0,0 @@
1
- [*]
2
- indent_style = space
3
- indent_size = 2
4
- trim_trailing_whitespace = true
5
- insert_final_newline = true
6
- end_of_line = lf
package/.eslintignore DELETED
@@ -1 +0,0 @@
1
- dist/**
package/.eslintrc.js DELETED
@@ -1,108 +0,0 @@
1
- module.exports = {
2
- extends: ['plugin:@typescript-eslint/recommended', 'prettier', 'plugin:prettier/recommended'],
3
- parserOptions: {
4
- sourceType: 'module',
5
- ecmaVersion: 2018,
6
- project: './tsconfig.test.json'
7
- },
8
- env: {
9
- jest: true,
10
- },
11
- globals: {
12
- browser: true,
13
- page: true,
14
- },
15
- plugins: ['jest', 'unused-imports'],
16
- rules: {
17
- 'array-bracket-newline': ['error', 'consistent'],
18
- strict: ['error', 'safe'],
19
- 'block-scoped-var': 'error',
20
- complexity: 'warn',
21
- 'default-case': 'error',
22
- 'dot-notation': 'warn',
23
- eqeqeq: 'error',
24
- 'guard-for-in': 'warn',
25
- 'linebreak-style': ['warn', 'unix'],
26
- 'no-alert': 'error',
27
- 'no-case-declarations': 'error',
28
- 'no-console': 'error',
29
- 'no-constant-condition': 'error',
30
- 'no-continue': 'warn',
31
- 'no-div-regex': 'error',
32
- 'no-empty': 'warn',
33
- 'no-empty-pattern': 'error',
34
- 'no-implicit-coercion': 'error',
35
- 'prefer-arrow-callback': 'warn',
36
- 'no-labels': 'error',
37
- 'no-loop-func': 'error',
38
- 'no-nested-ternary': 'warn',
39
- 'no-script-url': 'error',
40
- 'no-warning-comments': 'warn',
41
- 'quote-props': ['error', 'as-needed'],
42
- 'require-yield': 'error',
43
- 'max-nested-callbacks': ['error', 4],
44
- 'max-depth': ['error', 4],
45
- 'space-before-function-paren': [
46
- 'error',
47
- {
48
- anonymous: 'never',
49
- named: 'never',
50
- asyncArrow: 'always',
51
- },
52
- ],
53
- 'padding-line-between-statements': [
54
- 'error',
55
- { blankLine: 'always', prev: '*', next: 'if' },
56
- { blankLine: 'always', prev: '*', next: 'function' },
57
- { blankLine: 'always', prev: '*', next: 'return' },
58
- ],
59
- 'no-useless-constructor': 'off',
60
- 'no-dupe-class-members': 'off',
61
- 'no-unused-expressions': 'off',
62
- curly: ['error', 'multi-line'],
63
- 'object-curly-spacing': ['error', 'always'],
64
- 'comma-dangle': ['error', 'always-multiline'],
65
- '@typescript-eslint/no-useless-constructor': 'error',
66
- '@typescript-eslint/no-unused-expressions': 'error',
67
- '@typescript-eslint/member-delimiter-style': [
68
- 'error',
69
- {
70
- multiline: {
71
- delimiter: 'none',
72
- requireLast: true,
73
- },
74
- singleline: {
75
- delimiter: 'semi',
76
- requireLast: false,
77
- },
78
- },
79
- ],
80
- '@typescript-eslint/ban-ts-comment': [
81
- 'error',
82
- {
83
- 'ts-expect-error': 'allow-with-description',
84
- 'ts-ignore': 'allow-with-description',
85
- 'ts-nocheck': 'allow-with-description',
86
- 'ts-check': 'allow-with-description',
87
- minimumDescriptionLength: 6,
88
- },
89
- ],
90
- "require-await": "off",
91
- "@typescript-eslint/promise-function-async": "error",
92
- "@typescript-eslint/require-await": "off",
93
- "@typescript-eslint/no-unused-vars": "off",
94
- "unused-imports/no-unused-imports": "error",
95
- "unused-imports/no-unused-vars": [
96
- "warn",
97
- { "vars": "all", "varsIgnorePattern": "^_", "args": "after-used", "argsIgnorePattern": "^_" }
98
- ]
99
- },
100
- overrides: [
101
- {
102
- files: ['*.spec.ts'],
103
- rules: {
104
- 'max-nested-callbacks': ['error', 10], // allow describe/it nesting
105
- },
106
- },
107
- ],
108
- }
package/.gitattributes DELETED
@@ -1 +0,0 @@
1
- * text=auto
@@ -1,23 +0,0 @@
1
- labels:
2
- issue: type:issue
3
- pull-request: type:pull-request
4
- release:
5
- trigger:
6
- labels:
7
- - 'autorelease: pending'
8
- checklist: |
9
- ## 🚀 Release checklist
10
-
11
- ### Before release
12
-
13
- - [ ] Ensure the release works with the intended `bee` version
14
- - [ ] Verify all the example code works with the release code
15
- - [ ] Verify all user documentation is up to date
16
- - [ ] Have two approval for this PR
17
- - [ ] Write small summary for the release and verify changelog
18
- - [ ] Verify that changes to release PR comment is synchronized to `CHANGELOG` with manual commit
19
-
20
- ### After release
21
-
22
- - [ ] Update API docs
23
- - [ ] Update example's `bee-js` version