@ethersphere/bee-js 6.9.1 → 7.0.1
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.
- package/README.md +107 -65
- package/dist/cjs/bee.js +533 -6
- package/dist/cjs/chunk/cac.js +3 -3
- package/dist/cjs/chunk/soc.js +5 -5
- package/dist/cjs/chunk/span.js +2 -6
- package/dist/cjs/feed/identifier.js +2 -2
- package/dist/cjs/feed/index.js +5 -6
- package/dist/cjs/feed/retrievable.js +2 -2
- package/dist/cjs/index.js +1 -3
- package/dist/cjs/modules/bytes.js +3 -3
- package/dist/cjs/modules/bzz.js +9 -20
- package/dist/cjs/modules/chunk.js +2 -2
- package/dist/cjs/modules/debug/balance.js +4 -4
- package/dist/cjs/modules/debug/chequebook.js +8 -8
- package/dist/cjs/modules/debug/chunk.js +2 -19
- package/dist/cjs/modules/debug/settlements.js +2 -2
- package/dist/cjs/modules/debug/stake.js +3 -3
- package/dist/cjs/modules/debug/states.js +4 -19
- package/dist/cjs/modules/debug/status.js +15 -32
- package/dist/cjs/modules/debug/tag.js +1 -1
- package/dist/cjs/modules/debug/transactions.js +4 -4
- package/dist/cjs/modules/feed.js +6 -7
- package/dist/cjs/modules/pinning.js +4 -4
- package/dist/cjs/modules/pss.js +1 -1
- package/dist/cjs/modules/soc.js +1 -1
- package/dist/cjs/modules/status.js +1 -1
- package/dist/cjs/modules/stewardship.js +1 -1
- package/dist/cjs/package.json +4 -0
- package/dist/cjs/types/index.js +5 -1
- package/dist/cjs/utils/collection.js +7 -22
- package/dist/cjs/utils/collection.node.js +2 -1
- package/dist/cjs/utils/data.browser.js +1 -49
- package/dist/cjs/utils/error.js +2 -6
- package/dist/cjs/utils/eth.js +1 -1
- package/dist/cjs/utils/expose.js +1 -8
- package/dist/cjs/utils/file.js +2 -2
- package/dist/cjs/utils/http.js +6 -25
- package/dist/cjs/utils/tar-uploader.browser.js +26 -0
- package/dist/cjs/utils/tar-uploader.js +27 -0
- package/dist/cjs/utils/tar-writer.browser.js +17 -0
- package/dist/cjs/utils/tar-writer.js +21 -0
- package/dist/cjs/utils/tar.browser.js +65 -0
- package/dist/cjs/utils/tar.js +47 -21
- package/dist/cjs/utils/type.js +7 -3
- package/dist/cjs/utils/url.js +1 -6
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.LICENSE.txt +0 -42
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/bee.js +533 -9
- package/dist/mjs/chunk/cac.js +4 -4
- package/dist/mjs/chunk/soc.js +6 -6
- package/dist/mjs/chunk/span.js +2 -6
- package/dist/mjs/feed/identifier.js +2 -2
- package/dist/mjs/feed/index.js +5 -9
- package/dist/mjs/feed/retrievable.js +2 -2
- package/dist/mjs/index.js +1 -2
- package/dist/mjs/modules/bytes.js +3 -3
- package/dist/mjs/modules/bzz.js +8 -20
- package/dist/mjs/modules/chunk.js +2 -2
- package/dist/mjs/modules/debug/balance.js +4 -4
- package/dist/mjs/modules/debug/chequebook.js +8 -8
- package/dist/mjs/modules/debug/chunk.js +1 -17
- package/dist/mjs/modules/debug/settlements.js +2 -2
- package/dist/mjs/modules/debug/stake.js +3 -3
- package/dist/mjs/modules/debug/states.js +4 -19
- package/dist/mjs/modules/debug/status.js +15 -34
- package/dist/mjs/modules/debug/tag.js +1 -1
- package/dist/mjs/modules/debug/transactions.js +4 -4
- package/dist/mjs/modules/feed.js +6 -7
- package/dist/mjs/modules/pinning.js +4 -4
- package/dist/mjs/modules/pss.js +1 -1
- package/dist/mjs/modules/soc.js +1 -1
- package/dist/mjs/modules/status.js +1 -1
- package/dist/mjs/modules/stewardship.js +1 -1
- package/dist/mjs/package.json +6 -2
- package/dist/mjs/types/index.js +4 -0
- package/dist/mjs/utils/collection.js +7 -22
- package/dist/mjs/utils/collection.node.js +2 -1
- package/dist/mjs/utils/data.browser.js +0 -57
- package/dist/mjs/utils/error.js +2 -6
- package/dist/mjs/utils/eth.js +1 -1
- package/dist/mjs/utils/expose.js +0 -1
- package/dist/mjs/utils/http.js +5 -2
- package/dist/mjs/utils/tar-uploader.browser.js +22 -0
- package/dist/mjs/utils/tar-uploader.js +23 -0
- package/dist/mjs/utils/tar-writer.browser.js +12 -0
- package/dist/mjs/utils/tar-writer.js +16 -0
- package/dist/mjs/utils/tar.browser.js +61 -0
- package/dist/mjs/utils/tar.js +45 -16
- package/dist/mjs/utils/type.js +4 -1
- package/dist/mjs/utils/url.js +1 -6
- package/dist/types/bee.d.ts +305 -4
- package/dist/types/chunk/soc.d.ts +2 -2
- package/dist/types/feed/identifier.d.ts +1 -1
- package/dist/types/index.d.ts +1 -3
- package/dist/types/modules/bytes.d.ts +3 -3
- package/dist/types/modules/bzz.d.ts +14 -6
- package/dist/types/modules/chunk.d.ts +2 -2
- package/dist/types/modules/debug/balance.d.ts +4 -4
- package/dist/types/modules/debug/chequebook.d.ts +8 -8
- package/dist/types/modules/debug/chunk.d.ts +1 -10
- package/dist/types/modules/debug/settlements.d.ts +2 -2
- package/dist/types/modules/debug/stake.d.ts +3 -3
- package/dist/types/modules/debug/states.d.ts +3 -3
- package/dist/types/modules/debug/status.d.ts +10 -20
- package/dist/types/modules/debug/tag.d.ts +1 -1
- package/dist/types/modules/debug/transactions.d.ts +4 -4
- package/dist/types/modules/feed.d.ts +6 -9
- package/dist/types/modules/pinning.d.ts +4 -4
- package/dist/types/modules/pss.d.ts +1 -1
- package/dist/types/modules/soc.d.ts +1 -1
- package/dist/types/modules/status.d.ts +1 -1
- package/dist/types/modules/stewardship.d.ts +1 -1
- package/dist/types/types/debug.d.ts +0 -3
- package/dist/types/types/index.d.ts +9 -17
- package/dist/types/utils/collection.browser.d.ts +1 -1
- package/dist/types/utils/collection.d.ts +3 -3
- package/dist/types/utils/collection.node.d.ts +1 -1
- package/dist/types/utils/data.browser.d.ts +0 -7
- package/dist/types/utils/data.d.ts +1 -2
- package/dist/types/utils/error.d.ts +2 -7
- package/dist/types/utils/eth.d.ts +1 -1
- package/dist/types/utils/expose.d.ts +0 -1
- package/dist/types/utils/tar-uploader.browser.d.ts +4 -0
- package/dist/types/utils/tar-uploader.d.ts +4 -0
- package/dist/types/utils/tar-writer.browser.d.ts +3 -0
- package/dist/types/utils/tar-writer.d.ts +3 -0
- package/dist/types/utils/tar.browser.d.ts +9 -0
- package/dist/types/utils/tar.d.ts +10 -2
- package/dist/types/utils/type.d.ts +4 -1
- package/package.json +4 -19
- package/dist/cjs/bee-debug.js +0 -590
- package/dist/cjs/chunk/serialize.js +0 -19
- package/dist/cjs/utils/stream.js +0 -146
- package/dist/cjs/utils/uint64.js +0 -29
- package/dist/mjs/bee-debug.js +0 -560
- package/dist/mjs/chunk/serialize.js +0 -15
- package/dist/mjs/utils/stream.js +0 -129
- package/dist/mjs/utils/uint64.js +0 -22
- package/dist/types/bee-debug.d.ts +0 -323
- package/dist/types/chunk/serialize.d.ts +0 -6
- package/dist/types/utils/stream.d.ts +0 -40
- package/dist/types/utils/uint64.d.ts +0 -4
package/README.md
CHANGED
|
@@ -1,66 +1,47 @@
|
|
|
1
|
-
# Bee-
|
|
1
|
+
# Bee-JS
|
|
2
2
|
|
|
3
|
-
[](https://github.com/ethersphere/bee-js/actions/workflows/tests.yaml)
|
|
4
|
-
[](https://app.fossa.com/projects/git%2Bgithub.com%2Fethersphere%2Fbee-js?ref=badge_shield)
|
|
5
3
|
[](https://swarm.ethereum.org/)
|
|
4
|
+
[](https://app.fossa.com/projects/git%2Bgithub.com%2Fethersphere%2Fbee-js?ref=badge_shield)
|
|
6
5
|
[](https://github.com/RichardLitt/standard-readme)
|
|
7
6
|
[](https://github.com/feross/standard)
|
|
8
|
-

|
|
7
|
+

|
|
10
8
|

|
|
11
9
|
|
|
12
|
-
>
|
|
10
|
+
> JavaScript SDK for connecting to a Bee node in the Swarm decentralised storage.
|
|
13
11
|
|
|
14
|
-
|
|
12
|
+
> Supports Node.js 18+, Vite and Webpack.
|
|
15
13
|
|
|
16
|
-
|
|
14
|
+
> Write your code in CJS, MJS or TypeScript.
|
|
17
15
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
- [Install](#install)
|
|
21
|
-
- [npm](#npm)
|
|
22
|
-
- [Use in Node.js](#use-in-nodejs)
|
|
23
|
-
- [Use in a browser with browserify, webpack or any other bundler](#use-in-a-browser-with-browserify-webpack-or-any-other-bundler)
|
|
24
|
-
- [Use in a browser Using a script tag](#use-in-a-browser-using-a-script-tag)
|
|
25
|
-
- [Usage](#usage)
|
|
26
|
-
- [API](#api)
|
|
27
|
-
- [Contribute](#contribute)
|
|
28
|
-
- [Setup](#setup)
|
|
29
|
-
- [Test](#test)
|
|
30
|
-
- [License](#license)
|
|
16
|
+
> Intended to be used with Bee version 2.1.0.
|
|
31
17
|
|
|
32
18
|
## Install
|
|
33
19
|
|
|
34
|
-
### npm
|
|
35
|
-
|
|
36
20
|
```sh
|
|
37
|
-
|
|
21
|
+
npm install @ethersphere/bee-js
|
|
38
22
|
```
|
|
39
23
|
|
|
40
|
-
|
|
24
|
+
or
|
|
41
25
|
|
|
42
26
|
```sh
|
|
43
|
-
|
|
27
|
+
yarn add @ethersphere/bee-js
|
|
44
28
|
```
|
|
45
29
|
|
|
46
|
-
|
|
47
|
-
work as it does not correctly handle execution of `prepare` script.
|
|
30
|
+
## Import
|
|
48
31
|
|
|
49
|
-
###
|
|
50
|
-
|
|
51
|
-
**We require Node.js's version of at least 12.x**
|
|
32
|
+
### CJS
|
|
52
33
|
|
|
53
34
|
```js
|
|
54
|
-
|
|
35
|
+
const { Bee } = require('@ethersphere/bee-js')
|
|
55
36
|
```
|
|
56
37
|
|
|
57
|
-
###
|
|
38
|
+
### MJS and TypeScript
|
|
58
39
|
|
|
59
|
-
```
|
|
60
|
-
|
|
40
|
+
```ts
|
|
41
|
+
import { Bee } from '@ethersphere/bee-js'
|
|
61
42
|
```
|
|
62
43
|
|
|
63
|
-
###
|
|
44
|
+
### Script tag
|
|
64
45
|
|
|
65
46
|
Loading this module through a script tag will make the `BeeJs` object available in the global namespace.
|
|
66
47
|
|
|
@@ -70,33 +51,101 @@ Loading this module through a script tag will make the `BeeJs` object available
|
|
|
70
51
|
|
|
71
52
|
## Usage
|
|
72
53
|
|
|
54
|
+
### Create or select an existing postage batch
|
|
55
|
+
|
|
56
|
+
Swarm incentivizes nodes in the network to store content, therefor all uploads require a paid
|
|
57
|
+
[postage batch](https://docs.ethswarm.org/docs/learn/technology/contracts/postage-stamp).
|
|
58
|
+
|
|
59
|
+
```js
|
|
60
|
+
import { Bee } from '@ethersphere/bee-js'
|
|
61
|
+
|
|
62
|
+
async function getOrCreatePostageBatch() {
|
|
63
|
+
const bee = new Bee('http://localhost:1633')
|
|
64
|
+
let batchId
|
|
65
|
+
|
|
66
|
+
const batches = await bee.getAllPostageBatch()
|
|
67
|
+
const usable = batches.find(x => x.usable)
|
|
68
|
+
|
|
69
|
+
if (usable) {
|
|
70
|
+
batchId = usable.batchID
|
|
71
|
+
} else {
|
|
72
|
+
batchId = await bee.createPostageBatch('500000000', 20)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
> The following examples all assume an existing batchId.
|
|
78
|
+
|
|
79
|
+
### Upload simple data (Browser + Node.js)
|
|
80
|
+
|
|
73
81
|
```js
|
|
74
|
-
import { Bee
|
|
82
|
+
import { Bee } from '@ethersphere/bee-js'
|
|
75
83
|
|
|
76
84
|
const bee = new Bee('http://localhost:1633')
|
|
77
|
-
const beeDebug = new BeeDebug('http://localhost:1635')
|
|
78
85
|
|
|
79
|
-
|
|
80
|
-
const batchId = await bee.createPostageBatch('2000', 20)
|
|
81
|
-
const uploadResult = await bee.uploadData(batchId, "Bee is awesome!")
|
|
86
|
+
const uploadResult = await bee.uploadData(batchId, 'Bee is awesome!')
|
|
82
87
|
const data = await bee.downloadData(uploadResult.reference)
|
|
83
88
|
|
|
84
89
|
console.log(data.text()) // prints 'Bee is awesome!'
|
|
85
90
|
```
|
|
86
91
|
|
|
92
|
+
### Upload data from a file input (React)
|
|
93
|
+
|
|
94
|
+
```js
|
|
95
|
+
import { Bee } from '@ethersphere/bee-js'
|
|
96
|
+
|
|
97
|
+
const bee = new Bee('http://localhost:1633')
|
|
98
|
+
const result = await bee.uploadFile(batchId, file)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Upload multiple files or a directory (React)
|
|
102
|
+
|
|
103
|
+
```js
|
|
104
|
+
import { Bee } from '@ethersphere/bee-js'
|
|
105
|
+
|
|
106
|
+
const bee = new Bee('http://localhost:1633')
|
|
107
|
+
const result = await bee.uploadFiles(batchId, fileList)
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Upload arbitrary large file (Node.js)
|
|
111
|
+
|
|
112
|
+
```js
|
|
113
|
+
import { Bee } from '@ethersphere/bee-js'
|
|
114
|
+
import { createReadStream } from 'fs'
|
|
115
|
+
|
|
116
|
+
const bee = new Bee('http://localhost:1633')
|
|
117
|
+
const readable = createReadStream('./path/to/large.bin')
|
|
118
|
+
const uploadResult = await bee.uploadFile(batchId, readable)
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Upload arbitrary large directories (Node.js)
|
|
122
|
+
|
|
123
|
+
```js
|
|
124
|
+
import { Bee } from '@ethersphere/bee-js'
|
|
125
|
+
import { createReadStream } from 'fs'
|
|
126
|
+
|
|
127
|
+
const bee = new Bee('http://localhost:1633')
|
|
128
|
+
const uploadResult = await bee.uploadFilesFromDirectory(batchId, './path/to/gallery/')
|
|
129
|
+
```
|
|
130
|
+
|
|
87
131
|
[**Check out our examples repo for some more ideas on how to use `bee-js`**](https://github.com/ethersphere/examples-js)
|
|
88
132
|
|
|
89
133
|
## Documentation
|
|
90
134
|
|
|
91
|
-
You can find the full documentation [here](https://bee-js.ethswarm.org/docs). The API reference documentation can be
|
|
135
|
+
You can find the full documentation [here](https://bee-js.ethswarm.org/docs). The API reference documentation can be
|
|
136
|
+
found [here](https://bee-js.ethswarm.org/docs/api).
|
|
92
137
|
|
|
93
138
|
## Contribute
|
|
94
139
|
|
|
140
|
+
Stay up to date by joining the [official Discord](https://discord.gg/GU22h2utj6) and by keeping an eye on the
|
|
141
|
+
[releases tab](https://github.com/ethersphere/bee-js/releases).
|
|
142
|
+
|
|
95
143
|
There are some ways you can make this module better:
|
|
96
144
|
|
|
97
145
|
- Consult our [open issues](https://github.com/ethersphere/bee-js/issues) and take on one of them
|
|
98
146
|
- Help our tests reach 100% coverage!
|
|
99
|
-
- Join us in our [Discord chat](https://discord.gg/wdghaQsGq5) in the #develop-on-swarm channel if you have questions or
|
|
147
|
+
- Join us in our [Discord chat](https://discord.gg/wdghaQsGq5) in the #develop-on-swarm channel if you have questions or
|
|
148
|
+
want to give feedback
|
|
100
149
|
|
|
101
150
|
### Setup
|
|
102
151
|
|
|
@@ -106,35 +155,32 @@ Install project dependencies with
|
|
|
106
155
|
npm i
|
|
107
156
|
```
|
|
108
157
|
|
|
109
|
-
### Node 18
|
|
110
|
-
|
|
111
|
-
Node 18 came with its own fetch's native implementation called Undici. If you want to run bee-js tests under Node 18, then disable
|
|
112
|
-
the native's fetch implementation otherwise unit tests will fail as they capture HTTP calls with library called `nock` that does
|
|
113
|
-
not support native fetch yet.
|
|
114
|
-
|
|
115
|
-
```
|
|
116
|
-
export NODE_OPTIONS='--no-experimental-fetch'
|
|
117
|
-
```
|
|
118
|
-
|
|
119
158
|
### Test
|
|
120
159
|
|
|
121
160
|
The tests run in both context: node and dom with Jest.
|
|
122
161
|
|
|
123
|
-
To run the integration tests, you need to spin up local Bee cluster using our
|
|
124
|
-
In order to do that you have to have locally Docker
|
|
125
|
-
|
|
162
|
+
To run the integration tests, you need to spin up local Bee cluster using our
|
|
163
|
+
[`fdp-play`](https://github.com/fairDataSociety/fdp-play/) project. In order to do that you have to have locally Docker
|
|
164
|
+
running on your machine, but afterwards you can just simply run `npm run bee`, which spins up the cluster and display
|
|
165
|
+
Queen's logs. If you want to exit hit `CTRL+C`.
|
|
126
166
|
|
|
127
|
-
If you want to skip creation of postage stamps every run of integration tests you can create stamps for both nodes and
|
|
167
|
+
If you want to skip creation of postage stamps every run of integration tests you can create stamps for both nodes and
|
|
168
|
+
set them under env. variables `BEE_POSTAGE` and `BEE_PEER_POSTAGE`.
|
|
128
169
|
|
|
129
|
-
By default, for integration tests two bee nodes are expected to run on localhost on addresses `http://localhost:1633`
|
|
130
|
-
|
|
170
|
+
By default, for integration tests two bee nodes are expected to run on localhost on addresses `http://localhost:1633`
|
|
171
|
+
and `http://localhost:11633`. These are the default values for the `fdp-play` script. If you want to use custom setup,
|
|
172
|
+
you can change the behavior of tests to different addresses using environment variables `BEE_API_URL` and
|
|
173
|
+
`BEE_PEER_API_URL`.
|
|
131
174
|
|
|
132
175
|
There are also browser tests by Puppeteer, which also provide integrity testing.
|
|
176
|
+
|
|
133
177
|
```sh
|
|
134
178
|
npm run test:browser
|
|
135
179
|
```
|
|
136
|
-
|
|
137
|
-
|
|
180
|
+
|
|
181
|
+
The test HTML file which Puppeteer uses is the [test/testpage/testpage.html](test/testpage/testpage.html). To open and
|
|
182
|
+
manually test BeeJS with developer console, it is necessary to build the library first with `npm run compile:browser`
|
|
183
|
+
(running the browser tests `npm run test:browser` also builds the library).
|
|
138
184
|
|
|
139
185
|
### Compile code
|
|
140
186
|
|
|
@@ -146,12 +192,8 @@ or for Browsers
|
|
|
146
192
|
|
|
147
193
|
`npm run compile:browser`
|
|
148
194
|
|
|
149
|
-
## Maintainers
|
|
150
|
-
|
|
151
|
-
|
|
152
195
|
## License
|
|
153
196
|
|
|
154
197
|
[BSD-3-Clause](./LICENSE)
|
|
155
198
|
|
|
156
|
-
|
|
157
199
|
[](https://app.fossa.com/projects/git%2Bgithub.com%2Fethersphere%2Fbee-js?ref=badge_large)
|