Skip to content

Commit 79c8398

Browse files
authored
feat: remove redundant language selectors from User Documentation (#98)
* docs: add information to README about bee-js submodule requirement * fix: remove redundant language selectors from User Documentation In most cases the Typescript / Javascript codeblock language selectors shared the same exact code snippets. For these cases, the redundant language selector control and duplicate code snippets have been removed.
1 parent 97df626 commit 79c8398

File tree

5 files changed

+19
-229
lines changed

5 files changed

+19
-229
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,22 @@ Documentation for the [Swarm Bee-js javascript library](https://github.com/ether
66

77
You must use **node 14** or above. We recommend [nvm](https://github.com/nvm-sh/nvm).
88

9+
### Prerequisites
10+
11+
This project requires the bee-js repository to be cloned as a git submodule.
12+
13+
You can fetch it by cloning the entire repository with the following command:
14+
15+
```
16+
$ git clone --recurse-submodules https://github.com/ethersphere/bee-js.git
17+
```
18+
19+
Or optionally fetch the submodule after cloning with the following command:
20+
21+
```
22+
$ git submodule update --init
23+
```
24+
925
### Installation
1026

1127
```

docs/user-documentation/getting-started.md

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -43,34 +43,12 @@ yarn add @ethersphere/bee-js --save
4343
After that you need to import the Bee class and create a bee instance connecting to your Bee node (here we assume it runs on localhost on default port).
4444
Be aware, if you will pass invalid URL the constructor will throw an exception!
4545

46-
47-
<Tabs
48-
groupId="lang_preferrence"
49-
defaultValue="ts"
50-
values={[
51-
{label: 'TypeScript', value: 'ts'},
52-
{label: 'JavaScript', value: 'js'},
53-
]}>
54-
<TabItem value="ts">
55-
56-
```ts
57-
import { Bee } from "@ethersphere/bee-js"
58-
59-
const bee = new Bee('http://localhost:1633')
60-
```
61-
62-
</TabItem>
63-
<TabItem value="js">
64-
6546
```js
6647
import { Bee } from "@ethersphere/bee-js"
6748

6849
const bee = new Bee('http://localhost:1633')
6950
```
7051

71-
</TabItem>
72-
</Tabs>
73-
7452
That’s it! now you can use the `bee` object.
7553

7654
:::info Run your own Bee node

docs/user-documentation/pss.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ subscription.cancel()
174174

175175
```js
176176
const handler = {
177-
onMessage: (message: Data) => {console.log(message.text())},
178-
onError: (error: BeeError) => {console.log(error)}
177+
onMessage: (message) => {console.log(message.text())},
178+
onError: (error) => {console.log(error)}
179179
}
180180

181181
// Subscribe

docs/user-documentation/track-upload.md

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -45,57 +45,14 @@ If you are using a node that is in Gateway mode then this operation is not allow
4545

4646
Creating a tag is easy. Just use the `createTag` function.
4747

48-
<Tabs
49-
groupId="lang_preferrence"
50-
defaultValue="ts"
51-
values={[
52-
{label: 'TypeScript', value: 'ts'},
53-
{label: 'JavaScript', value: 'js'},
54-
]}>
55-
<TabItem value="ts">
56-
57-
```ts
58-
const tag = await bee.createTag()
59-
```
60-
61-
</TabItem>
62-
<TabItem value="js">
63-
6448
```js
6549
const tag = await bee.createTag()
6650
```
6751

68-
</TabItem>
69-
</Tabs>
70-
7152
## Upload with tag
7253

7354
You can then use the tag when uploading data, by providing it in the options arguments for each of these methods.
7455

75-
<Tabs
76-
groupId="lang_preferrence"
77-
defaultValue="ts"
78-
values={[
79-
{label: 'TypeScript', value: 'ts'},
80-
{label: 'JavaScript', value: 'js'},
81-
]}>
82-
<TabItem value="ts">
83-
84-
```ts
85-
const postageBatchId = getOrCreatePostageBatch()
86-
87-
await bee.uploadData(postageBatchId, "Bee is awesome!", { tag })
88-
// OR
89-
await bee.uploadFile(postageBatchId, file, "foo.txt", { tag })
90-
// OR
91-
await bee.uploadFiles(postageBatchId, files, { tag })
92-
// OR
93-
await bee.uploadFilesFromDirectory(postageBatchId, "./", { tag })
94-
```
95-
96-
</TabItem>
97-
<TabItem value="js">
98-
9956
```js
10057
const postageBatchId = getOrCreatePostageBatch()
10158

@@ -108,9 +65,6 @@ await bee.uploadFiles(postageBatchId, files, { tag })
10865
await bee.uploadFilesFromDirectory(postageBatchId, "./", { tag })
10966
```
11067

111-
</TabItem>
112-
</Tabs>
113-
11468
## Retrieve tag
11569

11670
:::warning Forbidden on Gateways
@@ -119,30 +73,8 @@ If you are using a node that is in Gateway mode then this operation is not allow
11973

12074
Each time you want to check the upload status, you can use the `retrieveTag` function.
12175

122-
123-
<Tabs
124-
groupId="lang_preferrence"
125-
defaultValue="ts"
126-
values={[
127-
{label: 'TypeScript', value: 'ts'},
128-
{label: 'JavaScript', value: 'js'},
129-
]}>
130-
<TabItem value="ts">
131-
132-
```ts
133-
const updatedTag = await bee.retrieveTag(tag)
134-
// OR
135-
const updatedTag = await bee.retrieveTag(tag.uid)
136-
```
137-
138-
</TabItem>
139-
<TabItem value="js">
140-
14176
```js
14277
const updatedTag = await bee.retrieveTag(tag)
14378
// OR
14479
const updatedTag = await bee.retrieveTag(tag.uid)
14580
```
146-
147-
</TabItem>
148-
</Tabs>

docs/user-documentation/upload-download.md

Lines changed: 1 addition & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -30,31 +30,6 @@ When you download data the return type is [`Data`](../api/interfaces/data.md) in
3030
- `hex()` that converts the bytes into **non-prefixed** hex string
3131
- `json()` that converts the bytes into JSON object
3232

33-
<Tabs
34-
groupId="lang_preferrence"
35-
defaultValue="ts"
36-
values={[
37-
{label: 'TypeScript', value: 'ts'},
38-
{label: 'JavaScript', value: 'js'},
39-
]}>
40-
<TabItem value="ts">
41-
42-
```ts
43-
const postageBatchId = await bee.createPostageBatch("100", 17)
44-
const result = await bee.uploadData(postageBatchId, "Bee is awesome!")
45-
46-
// prints Swarm hash of the file with which it can be retrieved
47-
// here it is fd79d5e0ebd8407e422f53ce1d7c4c41ebf403be55143900f8d1490560294780
48-
console.log(result.reference)
49-
50-
const retrievedData = await bee.downloadData(result.reference)
51-
52-
console.log(retrievedData.text()) // prints 'Bee is awesome!'
53-
```
54-
55-
</TabItem>
56-
<TabItem value="js">
57-
5833
```js
5934
const postageBatchId = await bee.createPostageBatch("100", 17)
6035
const result = await bee.uploadData(postageBatchId, "Bee is awesome!")
@@ -68,9 +43,6 @@ const retrievedData = await bee.downloadData(result.reference)
6843
console.log(retrievedData.text()) // prints 'Bee is awesome!'
6944
```
7045

71-
</TabItem>
72-
</Tabs>
73-
7446
:::info Tip
7547
Swarm reference or hash is a 64 characters long hex string which is the address of the uploaded data, file or directory.
7648
:::
@@ -79,28 +51,6 @@ Swarm reference or hash is a 64 characters long hex string which is the address
7951

8052
You can also upload files and include a filename. When you download the file, `bee-js` will return additional information like `contentType` or `name` of the file.
8153

82-
<Tabs
83-
groupId="lang_preferrence"
84-
defaultValue="ts"
85-
values={[
86-
{label: 'TypeScript', value: 'ts'},
87-
{label: 'JavaScript', value: 'js'},
88-
]}>
89-
<TabItem value="ts">
90-
91-
```ts
92-
const postageBatchId = await bee.createPostageBatch("100", 17)
93-
const result = await bee.uploadFile(postageBatchId, "Bee is awesome!", "textfile.txt")
94-
const retrievedFile = await bee.downloadFile(result.reference)
95-
96-
console.log(retrievedFile.name) // prints 'textfile.txt'
97-
console.log(retrievedFile.contentType) // prints 'application/octet-stream'
98-
console.log(retrievedFile.data.text()) // prints 'Bee is awesome!'
99-
```
100-
101-
</TabItem>
102-
<TabItem value="js">
103-
10454
```js
10555
const postageBatchId = await bee.createPostageBatch("100", 17)
10656
const result = await bee.uploadFile(postageBatchId, "Bee is awesome!", "textfile.txt")
@@ -111,35 +61,8 @@ console.log(retrievedFile.contentType) // prints 'application/octet-stream'
11161
console.log(retrievedFile.data.text()) // prints 'Bee is awesome!'
11262
```
11363

114-
</TabItem>
115-
</Tabs>
116-
11764
In browsers, you can upload directly `File` type. The filename is taken from the file object itself, but can be overwritten through the second argument of the `uploadFile` function (see the [API docs](../api/classes/bee.md#uploadfile))
11865

119-
<Tabs
120-
groupId="lang_preferrence"
121-
defaultValue="ts"
122-
values={[
123-
{label: 'TypeScript', value: 'ts'},
124-
{label: 'JavaScript', value: 'js'},
125-
]}>
126-
<TabItem value="ts">
127-
128-
```ts
129-
const file = new File(["foo"], "foo.txt", { type: "text/plain" })
130-
131-
const postageBatchId = await bee.createPostageBatch("100", 17)
132-
const result = await bee.uploadFile(postageBatchId, file)
133-
const retrievedFile = await bee.downloadFile(result.reference)
134-
135-
console.log(retrievedFile.name) // prints 'foo.txt'
136-
console.log(retrievedFile.contentType) // prints 'text/plain'
137-
console.log(retrievedFile.data.text()) // prints 'foo'
138-
```
139-
140-
</TabItem>
141-
<TabItem value="js">
142-
14366
```js
14467
const file = new File(["foo"], "foo.txt", { type: "text/plain" })
14568

@@ -152,39 +75,10 @@ console.log(retrievedFile.contentType) // prints 'text/plain'
15275
console.log(retrievedFile.data.text()) // prints 'foo'
15376
```
15477

155-
</TabItem>
156-
</Tabs>
157-
15878
### Files and Directories
15979

16080
The last supported mode is upload of files and directories. In browsers, you can easily upload an array of `File` comming from your form directly as well as [`FileList`](https://developer.mozilla.org/en-US/docs/Web/API/FileList). If the files uploaded through `uploadFiles` have a relative path, they are added relative to this filepath. Otherwise, the whole structure is flattened into single directory.
16181

162-
<Tabs
163-
groupId="lang_preferrence"
164-
defaultValue="ts"
165-
values={[
166-
{label: 'TypeScript', value: 'ts'},
167-
{label: 'JavaScript', value: 'js'},
168-
]}>
169-
<TabItem value="ts">
170-
171-
```ts
172-
const foo = new File(["foo"], "foo.txt", { type: "text/plain" })
173-
const bar = new File(["bar"], "bar.txt", { type: "text/plain" })
174-
175-
const postageBatchId = await bee.createPostageBatch("100", 17)
176-
const result = await bee.uploadFiles(postageBatchId, [ foo, bar ]) // upload
177-
178-
const rFoo = await bee.downloadFile(result.reference, './foo.txt') // download foo
179-
const rBar = await bee.downloadFile(result.reference, './bar.txt') // download bar
180-
181-
console.log(rFoo.data.text()) // prints 'foo'
182-
console.log(rBar.data.text()) // prints 'bar'
183-
```
184-
185-
</TabItem>
186-
<TabItem value="js">
187-
18882
```js
18983
const foo = new File(["foo"], "foo.txt", { type: "text/plain" })
19084
const bar = new File(["bar"], "bar.txt", { type: "text/plain" })
@@ -199,9 +93,6 @@ console.log(rFoo.data.text()) // prints 'foo'
19993
console.log(rBar.data.text()) // prints 'bar'
20094
```
20195

202-
</TabItem>
203-
</Tabs>
204-
20596
In nodejs, you may utilise the `uploadFilesFromDirectory` function, which takes directory path as input and upload all files in that directory. Lets assum we have following data structure:
20697

20798
```sh
@@ -211,34 +102,10 @@ In nodejs, you may utilise the `uploadFilesFromDirectory` function, which takes
211102
| +-- bar.txt
212103
```
213104

214-
<Tabs
215-
groupId="lang_preferrence"
216-
defaultValue="ts"
217-
values={[
218-
{label: 'TypeScript', value: 'ts'},
219-
{label: 'JavaScript', value: 'js'},
220-
]}>
221-
<TabItem value="ts">
222-
223-
```ts
224-
const postageBatchId = await bee.createPostageBatch("100", 17)
225-
226-
const result = await bee.uploadFilesFromDirectory(postageBatchId, './') // upload recursively current folder
227-
228-
const rFoo = await bee.downloadFile(result.reference, './foo.txt') // download foo
229-
const rBar = await bee.downloadFile(result.reference, './dir/bar.txt') // download bar
230-
231-
console.log(rFoo.data.text()) // prints 'foo'
232-
console.log(rBar.data.text()) // prints 'bar'
233-
```
234-
235-
</TabItem>
236-
<TabItem value="js">
237-
238105
```js
239106
const postageBatchId = await bee.createPostageBatch("100", 17)
240107

241-
const hash = await bee.uploadFilesFromDirectory(postageBatchId, './') // upload recursively current folder
108+
const result = await bee.uploadFilesFromDirectory(postageBatchId, './') // upload recursively current folder
242109

243110
const rFoo = await bee.downloadFile(result.reference, './foo.txt') // download foo
244111
const rBar = await bee.downloadFile(result.reference, './dir/bar.txt') // download bar
@@ -247,9 +114,6 @@ console.log(rFoo.data.text()) // prints 'foo'
247114
console.log(rBar.data.text()) // prints 'bar'
248115
```
249116

250-
</TabItem>
251-
</Tabs>
252-
253117
## Retrieve file from node or gateway
254118

255119
You can always retrieve your files and data directly from the bee node through browser as well. For example, if you want to retrieve the "Bee is awesome!" text uploaded to Swarm in section [upload data](#data), you can directly access it with: [http://localhost:1633/files/fd79d5...294780](http://localhost:1633/files/fd79d5e0ebd8407e422f53ce1d7c4c41ebf403be55143900f8d1490560294780)

0 commit comments

Comments
 (0)