Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit bbcaf34

Browse files
GozalaXmaderachingbrain
authored
feat: type check & generate defs from jsdoc (#3281)
1. Add missing type info (via jsdoc) and fix existing one so that `tsc --noEmit` can succeed without an error. 2. Fix all the issues that `tsc` pointed out once it got enabled. 3. Add a npm script that generates typedefs & typedef maps in `dist` directory & corresponding settings in `package.json` so that when package installed from npm no config will be required to get all the typings. Co-authored-by: Xmader <[email protected]> Co-authored-by: Alex Potsides <[email protected]> Co-authored-by: achingbrain <[email protected]>
1 parent 4b8021d commit bbcaf34

File tree

273 files changed

+5267
-2282
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

273 files changed

+5267
-2282
lines changed

.github/workflows/bundlesize.yml

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Checks bundlesize, does not run on master
2+
on:
3+
pull_request:
4+
branches:
5+
- '*'
6+
7+
name: Bundlesize
8+
jobs:
9+
check:
10+
runs-on: ubuntu-latest
11+
strategy:
12+
matrix:
13+
node-version: [12.x]
14+
project:
15+
- packages/ipfs-core-utils
16+
- packages/ipfs-core
17+
- packages/ipfs-http-client
18+
- packages/ipfs
19+
- packages/ipfs-message-port-protocol
20+
- packages/ipfs-message-port-client
21+
steps:
22+
- uses: actions/checkout@v2
23+
- name: Use Node.js ${{ matrix.node-version }}
24+
uses: actions/setup-node@v1
25+
with:
26+
node-version: ${{ matrix.node-version }}
27+
- name: Restore dependencies
28+
id: cache-modules
29+
uses: actions/checkout@v2
30+
with:
31+
path: node_modules
32+
key: ${{ matrix.node-version }}-${{ runner.OS }}-build-${{ hashFiles('package.json') }}
33+
- name: Install dependencies
34+
run: npm install
35+
- name: Bundlesize ${{ matrix.project }}
36+
uses: ipfs/aegir/actions/[email protected]
37+
with:
38+
project: ${{ matrix.project }}
39+
github_token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/main.yml

-18
This file was deleted.

.github/workflows/typecheck.yml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
on:
2+
pull_request:
3+
branches:
4+
- '*'
5+
6+
name: Typecheck
7+
jobs:
8+
check:
9+
runs-on: ubuntu-latest
10+
strategy:
11+
matrix:
12+
node-version: [12.x]
13+
project:
14+
- packages/ipfs-core-utils
15+
- packages/ipfs-core
16+
- packages/ipfs-http-client
17+
- packages/ipfs
18+
- packages/ipfs-cli
19+
- packages/ipfs-http-server
20+
- packages/ipfs-http-gateway
21+
- packages/ipfs-message-port-protocol
22+
- packages/ipfs-message-port-server
23+
- packages/ipfs-message-port-client
24+
steps:
25+
- uses: actions/checkout@v2
26+
- name: Use Node.js ${{ matrix.node-version }}
27+
uses: actions/setup-node@v1
28+
with:
29+
node-version: ${{ matrix.node-version }}
30+
- name: Restore dependencies
31+
id: cache-modules
32+
uses: actions/checkout@v2
33+
with:
34+
path: node_modules
35+
key: ${{ matrix.node-version }}-${{ runner.OS }}-build-${{ hashFiles('package.json') }}
36+
- name: Install dependencies
37+
run: npm install
38+
- name: Typecheck ${{ matrix.project }}
39+
uses: gozala/[email protected]
40+
with:
41+
project: ${{ matrix.project }}
42+

.travis.yml

+7-6
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,13 @@ jobs:
229229
- stage: test
230230
name: examples
231231
script:
232-
- npx json -I -f ./lerna.json -e "this.packages.push('examples/*')"
233-
- npx json -I -f ./lerna.json -e "this.command.bootstrap.nohoist = ['ipfs-css', 'tachyons']"
234-
- npm run reset
235-
- npm install
236-
- npm run build -- --scope={ipfs,ipfs-http-client,ipfs-message-port-*}
237-
- npm run test -- --scope=example* --concurrency=1
232+
# Travis lets scripts continue even if previous steps fail: https://github.com/travis-ci/travis-ci/issues/1066
233+
- npm run build -- --scope={ipfs-core,ipfs,ipfs-http-client,ipfs-message-port-*} &&
234+
rm -rf node_modules packages/*/node_modules &&
235+
npx json -I -f ./lerna.json -e "this.packages.push('examples/*')" &&
236+
npx json -I -f ./lerna.json -e "this.command.bootstrap.nohoist = ['ipfs-css', 'tachyons']" &&
237+
npm install &&
238+
npm run test -- --scope=example* --concurrency=1
238239

239240
- stage: release-rc
240241
# only run on changes to master

docs/core-api/BITSWAP.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ A great source of [examples][] can be found in the tests for this API.
6262

6363
| Name | Type | Default | Description |
6464
| ---- | ---- | ------- | ----------- |
65-
| peerId | [PeerId][], [CID][], `String` or `Buffer` | A peer ID to return the wantlist for |
65+
| peerId | [PeerId][], [CID][], `String` or `Uint8Array` | A peer ID to return the wantlist for |
6666

6767
### Options
6868

docs/core-api/BLOCK.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
| Name | Type | Description |
3131
| ---- | ---- | ----------- |
32-
| cid | [CID][], `String` or `Buffer` | A CID that corresponds to the desired block |
32+
| cid | [CID][], `String` or `Uint8Array` | A CID that corresponds to the desired block |
3333

3434
### Options
3535

@@ -63,7 +63,7 @@ A great source of [examples][] can be found in the tests for this API.
6363

6464
| Name | Type | Description |
6565
| ---- | ---- | ----------- |
66-
| block | A `Buffer` or [Block][] instance | The block or data to store |
66+
| block | A `Uint8Array` or [Block][] instance | The block or data to store |
6767

6868
### Options
6969

docs/core-api/BOOTSTRAP.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ An optional object which may have the following keys:
5555

5656
| Type | Description |
5757
| -------- | -------- |
58-
| `Promise<Object>` | An object that contains an array with all the added addresses |
58+
| `Promise<{ Peers: Array<MultiAddr> }>` | An object that contains an array with all the added addresses |
5959

6060
example of the returned object:
6161

@@ -141,7 +141,7 @@ An optional object which may have the following keys:
141141

142142
| Type | Description |
143143
| -------- | -------- |
144-
| `Promise<Object>` | An object that contains an array with all the bootstrap addresses |
144+
| `Promise<{ Peers: Array<MultiAddr> }>` | An object that contains an array with all the bootstrap addresses |
145145

146146
example of the returned object:
147147

@@ -225,7 +225,7 @@ An optional object which may have the following keys:
225225

226226
| Type | Description |
227227
| -------- | -------- |
228-
| `Promise<Object>` | An object that contains an array with all the removed addresses |
228+
| `Promise<{ Peers: Array<MultiAddr> }>` | An object that contains an array with all the removed addresses |
229229

230230
```JavaScript
231231
{

docs/core-api/DHT.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ A great source of [examples][] can be found in the tests for this API.
126126

127127
| Name | Type | Description |
128128
| ---- | ---- | ----------- |
129-
| key | `Buffer` or `string` | The key associated with the value to find |
129+
| key | `Uint8Array` or `string` | The key associated with the value to find |
130130

131131
### Options
132132

@@ -141,7 +141,7 @@ An optional object which may have the following keys:
141141

142142
| Type | Description |
143143
| -------- | -------- |
144-
| `Promise<Buffer>` | The value that was stored under that key |
144+
| `Promise<Uint8Array>` | The value that was stored under that key |
145145

146146
### Example
147147

@@ -228,8 +228,8 @@ A great source of [examples][] can be found in the tests for this API.
228228

229229
| Name | Type | Description |
230230
| ---- | ---- | ----------- |
231-
| key | Buffer | The key to put the value as |
232-
| value | Buffer | Value to put |
231+
| key | Uint8Array | The key to put the value as |
232+
| value | Uint8Array | Value to put |
233233

234234
### Options
235235

docs/core-api/FILES.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,8 @@ An optional object which may have the following keys:
242242

243243
| Name | Type | Default | Description |
244244
| ---- | ---- | ------- | ----------- |
245-
| chunker | `String` | `'size-262144'` | chunking algorithm used to build ipfs DAGs |
246-
| cidVersion | `Number` | `0` | the CID version to use when storing the data |
245+
| chunker | `string` | `'size-262144'` | chunking algorithm used to build ipfs DAGs |
246+
| cidVersion | `number` | `0` | the CID version to use when storing the data |
247247
| enableShardingExperiment | `boolean` | `false` | allows to create directories with an unlimited number of entries currently size of unixfs directories is limited by the maximum block size. Note that this is an experimental feature |
248248
| hashAlg | `String` | `'sha2-256'` | multihash hashing algorithm to use |
249249
| onlyHash | `boolean` | `false` | If true, will not add blocks to the blockstore |
@@ -415,7 +415,7 @@ An optional object which may have the following keys:
415415

416416
| Type | Description |
417417
| -------- | -------- |
418-
| `AsyncIterable<Buffer>` | An async iterable that yields [`Buffer`][b] objects with the contents of `path` |
418+
| `AsyncIterable<Uint8Array>` | An async iterable that yields `Uint8Array` objects with the contents of `path` |
419419

420420
#### Example
421421

@@ -842,7 +842,7 @@ An optional object which may have the following keys:
842842

843843
| Type | Description |
844844
| -------- | -------- |
845-
| `AsyncIterable<Buffer>` | An async iterable that yields [`Buffer`][b] objects with the contents of `path` |
845+
| `AsyncIterable<Uint8Array>` | An async iterable that yields `Uint8Array` objects with the contents of `path` |
846846

847847
#### Example
848848

@@ -866,7 +866,7 @@ console.log(uint8ArrayConcat(chunks).toString())
866866
| Name | Type | Description |
867867
| ---- | ---- | ----------- |
868868
| path | `String` | The [MFS path] where you will write to |
869-
| content | `String`, `Buffer`, `AsyncIterable<Buffer>` or [`Blob`][blob] | The content to write to the path |
869+
| content | `String`, `Uint8Array`, `AsyncIterable<Uint8Array>` or [`Blob`][blob] | The content to write to the path |
870870

871871
#### Options
872872

@@ -902,7 +902,7 @@ await ipfs.files.write('/hello-world', new TextEncoder().encode('Hello, world!')
902902

903903
### `ipfs.files.mv(...from, to, [options])`
904904

905-
> Move files from one location to another#### Parameters
905+
> Move files from one location to another
906906
907907
#### Parameters
908908

docs/core-api/OBJECT.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,15 @@ A great source of [examples][] can be found in the tests for this API.
100100

101101
| Name | Type | Description |
102102
| ---- | ---- | ----------- |
103-
| obj | `Object{ Data: <data>, Links: [] }`, `Buffer` or [DAGNode][] | The MerkleDAG Node to be stored |
103+
| obj | `Object{ Data: <data>, Links: [] }`, `Uint8Array` or [DAGNode][] | The MerkleDAG Node to be stored |
104104

105105
### Options
106106

107107
An optional object which may have the following keys:
108108

109109
| Name | Type | Default | Description |
110110
| ---- | ---- | ------- | ----------- |
111-
| enc | `String` | `undefined` | The encoding of the Buffer (json, yml, etc), if passed a Buffer |
111+
| enc | `String` | `undefined` | The encoding of the Uint8Array (json, yml, etc), if passed a Uint8Array |
112112
| timeout | `Number` | `undefined` | A timeout in ms |
113113
| signal | [AbortSignal][] | `undefined` | Can be used to cancel any long running requests started as a result of this call |
114114

@@ -195,7 +195,7 @@ An optional object which may have the following keys:
195195

196196
| Type | Description |
197197
| -------- | -------- |
198-
| `Promise<Buffer>` | An Promise that resolves to Buffer objects with the data that the MerkleDAG node contained |
198+
| `Promise<Uint8Array>` | An Promise that resolves to Uint8Array objects with the data that the MerkleDAG node contained |
199199

200200
### Example
201201

@@ -431,7 +431,7 @@ A great source of [examples][] can be found in the tests for this API.
431431
| Name | Type | Description |
432432
| ---- | ---- | ----------- |
433433
| cid | [CID][] | Add data to the [DAGNode][] that corresponds to this CID |
434-
| data | `Buffer` | The data to append to the `.Data` field of the node |
434+
| data | `Uint8Array` | The data to append to the `.Data` field of the node |
435435

436436
### Options
437437

@@ -465,7 +465,7 @@ A great source of [examples][] can be found in the tests for this API.
465465
| Name | Type | Description |
466466
| ---- | ---- | ----------- |
467467
| cid | [CID][] | Replace data of the [DAGNode][] that corresponds to this CID |
468-
| data | `Buffer` | The data to overwrite with |
468+
| data | `Uint8Array` | The data to overwrite with |
469469

470470
### Options
471471

docs/core-api/PUBSUB.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
| Name | Type | Description |
3333
| ---- | ---- | ----------- |
3434
| topic | `String` | The topic name |
35-
| handler | `Function<(msg) => {}>` | Event handler which will be called with a message object everytime one is received. The `msg` has the format `{from: String, seqno: Buffer, data: Buffer, topicIDs: Array<String>}` |
35+
| handler | `Function<(msg) => {}>` | Event handler which will be called with a message object everytime one is received. The `msg` has the format `{from: String, seqno: Uint8Array, data: Uint8Array, topicIDs: Array<String>}` |
3636

3737
### Options
3838

@@ -125,7 +125,7 @@ If **only** the `topic` param is provided, unsubscribe will remove **all** handl
125125
> Publish a data message to a pubsub topic.
126126
127127
- `topic: String`
128-
- `data: Buffer|String` - The message to send
128+
- `data: Uint8Array|String` - The message to send
129129

130130
### Returns
131131

examples/browser-add-readable-stream/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const createFiles = (directory) => {
2727
return [{
2828
path: `${directory}/file1.txt`,
2929

30-
// content could be a stream, a url, a Buffer, a File etc
30+
// content could be a stream, a url, a Uint8Array, a File etc
3131
content: 'one'
3232
}, {
3333
path: `${directory}/file2.txt`,

examples/browser-ipns-publish/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const pRetry = require("p-retry");
77
const last = require("it-last");
88
const cryptoKeys = require("human-crypto-keys"); // { getKeyPairFromSeed }
99
const uint8ArrayToString = require('uint8arrays/to-string')
10+
const uint8ArrayFromString = require('uint8arrays/from-string')
1011

1112
const { sleep, Logger, onEnterPress, catchAndLog } = require("./util");
1213

@@ -142,7 +143,7 @@ async function main() {
142143
try {
143144
// quick and dirty key gen, don't do this in real life
144145
const key = await IPFS.multihashing.digest(
145-
Buffer.from(keyName + Math.random().toString(36).substring(2)),
146+
uint8ArrayFromString(keyName + Math.random().toString(36).substring(2)),
146147
"sha2-256"
147148
);
148149
const keyPair = await cryptoKeys.getKeyPairFromSeed(key, "rsa");

examples/traverse-ipld-graphs/CHANGELOG.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ Output:
8787
```js
8888
{ link:
8989
{ '/':
90-
<Buffer 12 20 8a> } }
90+
<Uint8Array 12 20 8a> } }
9191
```
9292

9393
Now:
@@ -108,7 +108,7 @@ Output:
108108
codec: 'dag-pb',
109109
version: 0,
110110
multihash:
111-
<Buffer 12 20 8a> } }
111+
<Uint8Array 12 20 8a> } }
112112
```
113113

114114
See https://github.com/ipld/ipld/issues/44 for more information on why this

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"test:interface:message-port-client": "lerna run test:interface:message-port-client",
2323
"coverage": "lerna run coverage",
2424
"build": "lerna run build",
25+
"build:types": "lerna run build:types",
2526
"clean": "lerna run clean",
2627
"lint": "lerna run lint",
2728
"dep-check": "lerna run dep-check",

packages/interface-ipfs-core/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"uint8arrays": "^1.1.0"
6767
},
6868
"devDependencies": {
69-
"aegir": "^27.0.0",
69+
"aegir": "^28.0.0",
7070
"ipfsd-ctl": "^7.0.2"
7171
},
7272
"contributors": [

0 commit comments

Comments
 (0)