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

Commit

Permalink
feat: type check & generate defs from jsdoc (#3281)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
3 people authored Oct 21, 2020
1 parent 4b8021d commit bbcaf34
Show file tree
Hide file tree
Showing 273 changed files with 5,267 additions and 2,282 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/bundlesize.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Checks bundlesize, does not run on master
on:
pull_request:
branches:
- '*'

name: Bundlesize
jobs:
check:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x]
project:
- packages/ipfs-core-utils
- packages/ipfs-core
- packages/ipfs-http-client
- packages/ipfs
- packages/ipfs-message-port-protocol
- packages/ipfs-message-port-client
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Restore dependencies
id: cache-modules
uses: actions/checkout@v2
with:
path: node_modules
key: ${{ matrix.node-version }}-${{ runner.OS }}-build-${{ hashFiles('package.json') }}
- name: Install dependencies
run: npm install
- name: Bundlesize ${{ matrix.project }}
uses: ipfs/aegir/actions/[email protected]
with:
project: ${{ matrix.project }}
github_token: ${{ secrets.GITHUB_TOKEN }}
18 changes: 0 additions & 18 deletions .github/workflows/main.yml

This file was deleted.

42 changes: 42 additions & 0 deletions .github/workflows/typecheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
on:
pull_request:
branches:
- '*'

name: Typecheck
jobs:
check:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x]
project:
- packages/ipfs-core-utils
- packages/ipfs-core
- packages/ipfs-http-client
- packages/ipfs
- packages/ipfs-cli
- packages/ipfs-http-server
- packages/ipfs-http-gateway
- packages/ipfs-message-port-protocol
- packages/ipfs-message-port-server
- packages/ipfs-message-port-client
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Restore dependencies
id: cache-modules
uses: actions/checkout@v2
with:
path: node_modules
key: ${{ matrix.node-version }}-${{ runner.OS }}-build-${{ hashFiles('package.json') }}
- name: Install dependencies
run: npm install
- name: Typecheck ${{ matrix.project }}
uses: gozala/[email protected]
with:
project: ${{ matrix.project }}

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

- stage: release-rc
# only run on changes to master
Expand Down
2 changes: 1 addition & 1 deletion docs/core-api/BITSWAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ A great source of [examples][] can be found in the tests for this API.

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

### Options

Expand Down
4 changes: 2 additions & 2 deletions docs/core-api/BLOCK.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

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

### Options

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

| Name | Type | Description |
| ---- | ---- | ----------- |
| block | A `Buffer` or [Block][] instance | The block or data to store |
| block | A `Uint8Array` or [Block][] instance | The block or data to store |

### Options

Expand Down
6 changes: 3 additions & 3 deletions docs/core-api/BOOTSTRAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ An optional object which may have the following keys:

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

example of the returned object:

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

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

example of the returned object:

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

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

```JavaScript
{
Expand Down
8 changes: 4 additions & 4 deletions docs/core-api/DHT.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ A great source of [examples][] can be found in the tests for this API.

| Name | Type | Description |
| ---- | ---- | ----------- |
| key | `Buffer` or `string` | The key associated with the value to find |
| key | `Uint8Array` or `string` | The key associated with the value to find |

### Options

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

| Type | Description |
| -------- | -------- |
| `Promise<Buffer>` | The value that was stored under that key |
| `Promise<Uint8Array>` | The value that was stored under that key |

### Example

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

| Name | Type | Description |
| ---- | ---- | ----------- |
| key | Buffer | The key to put the value as |
| value | Buffer | Value to put |
| key | Uint8Array | The key to put the value as |
| value | Uint8Array | Value to put |

### Options

Expand Down
12 changes: 6 additions & 6 deletions docs/core-api/FILES.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ An optional object which may have the following keys:

| Name | Type | Default | Description |
| ---- | ---- | ------- | ----------- |
| chunker | `String` | `'size-262144'` | chunking algorithm used to build ipfs DAGs |
| cidVersion | `Number` | `0` | the CID version to use when storing the data |
| chunker | `string` | `'size-262144'` | chunking algorithm used to build ipfs DAGs |
| cidVersion | `number` | `0` | the CID version to use when storing the data |
| 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 |
| hashAlg | `String` | `'sha2-256'` | multihash hashing algorithm to use |
| onlyHash | `boolean` | `false` | If true, will not add blocks to the blockstore |
Expand Down Expand Up @@ -415,7 +415,7 @@ An optional object which may have the following keys:

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

#### Example

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

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

#### Example

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

#### Options

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

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

> Move files from one location to another#### Parameters
> Move files from one location to another
#### Parameters

Expand Down
10 changes: 5 additions & 5 deletions docs/core-api/OBJECT.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ A great source of [examples][] can be found in the tests for this API.

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

### Options

An optional object which may have the following keys:

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

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

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

### Example

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

### Options

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

### Options

Expand Down
4 changes: 2 additions & 2 deletions docs/core-api/PUBSUB.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
| Name | Type | Description |
| ---- | ---- | ----------- |
| topic | `String` | The topic name |
| 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>}` |
| 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>}` |

### Options

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

### Returns

Expand Down
2 changes: 1 addition & 1 deletion examples/browser-add-readable-stream/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const createFiles = (directory) => {
return [{
path: `${directory}/file1.txt`,

// content could be a stream, a url, a Buffer, a File etc
// content could be a stream, a url, a Uint8Array, a File etc
content: 'one'
}, {
path: `${directory}/file2.txt`,
Expand Down
3 changes: 2 additions & 1 deletion examples/browser-ipns-publish/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const pRetry = require("p-retry");
const last = require("it-last");
const cryptoKeys = require("human-crypto-keys"); // { getKeyPairFromSeed }
const uint8ArrayToString = require('uint8arrays/to-string')
const uint8ArrayFromString = require('uint8arrays/from-string')

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

Expand Down Expand Up @@ -142,7 +143,7 @@ async function main() {
try {
// quick and dirty key gen, don't do this in real life
const key = await IPFS.multihashing.digest(
Buffer.from(keyName + Math.random().toString(36).substring(2)),
uint8ArrayFromString(keyName + Math.random().toString(36).substring(2)),
"sha2-256"
);
const keyPair = await cryptoKeys.getKeyPairFromSeed(key, "rsa");
Expand Down
4 changes: 2 additions & 2 deletions examples/traverse-ipld-graphs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Output:
```js
{ link:
{ '/':
<Buffer 12 20 8a> } }
<Uint8Array 12 20 8a> } }
```

Now:
Expand All @@ -108,7 +108,7 @@ Output:
codec: 'dag-pb',
version: 0,
multihash:
<Buffer 12 20 8a> } }
<Uint8Array 12 20 8a> } }
```

See https://github.com/ipld/ipld/issues/44 for more information on why this
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"test:interface:message-port-client": "lerna run test:interface:message-port-client",
"coverage": "lerna run coverage",
"build": "lerna run build",
"build:types": "lerna run build:types",
"clean": "lerna run clean",
"lint": "lerna run lint",
"dep-check": "lerna run dep-check",
Expand Down
2 changes: 1 addition & 1 deletion packages/interface-ipfs-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"uint8arrays": "^1.1.0"
},
"devDependencies": {
"aegir": "^27.0.0",
"aegir": "^28.0.0",
"ipfsd-ctl": "^7.0.2"
},
"contributors": [
Expand Down
Loading

0 comments on commit bbcaf34

Please sign in to comment.