diff --git a/.github/workflows/js-test-and-release.yml b/.github/workflows/js-test-and-release.yml
index 1f234e7f..7300edd6 100644
--- a/.github/workflows/js-test-and-release.yml
+++ b/.github/workflows/js-test-and-release.yml
@@ -3,7 +3,7 @@ name: test & maybe release
on:
push:
branches:
- - master
+ - main
pull_request:
workflow_dispatch:
@@ -16,10 +16,214 @@ concurrency:
cancel-in-progress: true
jobs:
- js-test-and-release:
- uses: pl-strflt/uci/.github/workflows/js-test-and-release.yml@main
- secrets:
- DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}
- DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
- NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- UCI_GITHUB_TOKEN: ${{ secrets.UCI_GITHUB_TOKEN }}
+ check:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v3
+ - uses: actions/setup-node@v3
+ with:
+ node-version: lts/*
+ - uses: ipfs/aegir/actions/cache-node-modules@master
+ - run: npm run --if-present lint
+ - run: npm run --if-present dep-check
+ - run: npm run --if-present doc-check
+
+ test-node:
+ needs: check
+ runs-on: ${{ matrix.os }}
+ strategy:
+ matrix:
+ os: [windows-latest, ubuntu-latest, macos-latest]
+ node: [lts/*]
+ fail-fast: true
+ steps:
+ - uses: actions/checkout@v3
+ - uses: actions/setup-node@v3
+ with:
+ node-version: ${{ matrix.node }}
+ - uses: ipfs/aegir/actions/cache-node-modules@master
+ - run: npm run --if-present test:node
+ - uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4
+ with:
+ flags: node
+ files: .coverage/*,packages/*/.coverage/*
+
+ test-chrome:
+ needs: check
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v3
+ - uses: actions/setup-node@v3
+ with:
+ node-version: lts/*
+ - uses: ipfs/aegir/actions/cache-node-modules@master
+ - run: npm run --if-present test:chrome
+ - uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4
+ with:
+ flags: chrome
+ files: .coverage/*,packages/*/.coverage/*
+
+ test-chrome-webworker:
+ needs: check
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v3
+ - uses: actions/setup-node@v3
+ with:
+ node-version: lts/*
+ - uses: ipfs/aegir/actions/cache-node-modules@master
+ - run: npm run --if-present test:chrome-webworker
+ - uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4
+ with:
+ flags: chrome-webworker
+ files: .coverage/*,packages/*/.coverage/*
+
+ test-firefox:
+ needs: check
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v3
+ - uses: actions/setup-node@v3
+ with:
+ node-version: lts/*
+ - uses: ipfs/aegir/actions/cache-node-modules@master
+ - run: npm run --if-present test:firefox
+ - uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4
+ with:
+ flags: firefox
+ files: .coverage/*,packages/*/.coverage/*
+
+ test-firefox-webworker:
+ needs: check
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v3
+ - uses: actions/setup-node@v3
+ with:
+ node-version: lts/*
+ - uses: ipfs/aegir/actions/cache-node-modules@master
+ - run: npm run --if-present test:firefox-webworker
+ - uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4
+ with:
+ flags: firefox-webworker
+ files: .coverage/*,packages/*/.coverage/*
+
+ test-webkit:
+ needs: check
+ runs-on: ${{ matrix.os }}
+ strategy:
+ matrix:
+ os: [ubuntu-latest, macos-latest]
+ node: [lts/*]
+ fail-fast: true
+ steps:
+ - uses: actions/checkout@v3
+ - uses: actions/setup-node@v3
+ with:
+ node-version: lts/*
+ - uses: ipfs/aegir/actions/cache-node-modules@master
+ - run: npm run --if-present test:webkit
+ - uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4
+ with:
+ flags: webkit
+ files: .coverage/*,packages/*/.coverage/*
+
+ test-webkit-webworker:
+ needs: check
+ runs-on: ${{ matrix.os }}
+ strategy:
+ matrix:
+ os: [ubuntu-latest, macos-latest]
+ node: [lts/*]
+ fail-fast: true
+ steps:
+ - uses: actions/checkout@v3
+ - uses: actions/setup-node@v3
+ with:
+ node-version: lts/*
+ - uses: ipfs/aegir/actions/cache-node-modules@master
+ - run: npm run --if-present test:webkit-webworker
+ - uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4
+ with:
+ flags: webkit-webworker
+ files: .coverage/*,packages/*/.coverage/*
+
+ test-electron-main:
+ needs: check
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v3
+ - uses: actions/setup-node@v3
+ with:
+ node-version: lts/*
+ - uses: ipfs/aegir/actions/cache-node-modules@master
+ - run: npx xvfb-maybe npm run --if-present test:electron-main
+ - uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4
+ with:
+ flags: electron-main
+ files: .coverage/*,packages/*/.coverage/*
+
+ test-electron-renderer:
+ needs: check
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v3
+ - uses: actions/setup-node@v3
+ with:
+ node-version: lts/*
+ - uses: ipfs/aegir/actions/cache-node-modules@master
+ - run: npx xvfb-maybe npm run --if-present test:electron-renderer
+ - uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4
+ with:
+ flags: electron-renderer
+ files: .coverage/*,packages/*/.coverage/*
+
+ release-check:
+ needs: [test-node, test-chrome, test-chrome-webworker, test-firefox, test-firefox-webworker, test-webkit, test-webkit-webworker, test-electron-main, test-electron-renderer]
+ runs-on: ubuntu-latest
+ if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
+ outputs:
+ release: ${{ steps.branch.outputs.release }}
+ steps:
+ - id: branch
+ name: Check if the branch is a release branch
+ env:
+ BRANCHES: ${{ inputs.branches }}
+ REF: ${{ github.ref }}
+ uses: actions/github-script@v6
+ with:
+ script: |
+ const branches = JSON.parse(process.env.BRANCHES);
+ const ref = process.env.REF.replace(/^refs\/heads\//, '');
+ const release = branches.some(b => {
+ const regexPattern = b.replace(/\*/g, '.*');
+ const regex = new RegExp(`^${regexPattern}$`);
+ return regex.test(ref);
+ });
+ console.log(`This is a release branch: ${release}`);
+ core.setOutput('release', release);
+
+ release:
+ needs: [release-check]
+ runs-on: ubuntu-latest
+ if: needs.release-check.outputs.release == 'true'
+ permissions:
+ id-token: write
+ contents: write
+ pull-requests: write
+ steps:
+ - uses: actions/checkout@v3
+ with:
+ fetch-depth: 0
+ - uses: actions/setup-node@v3
+ with:
+ node-version: lts/*
+ - uses: ipfs/aegir/actions/cache-node-modules@master
+ - uses: ipfs/aegir/actions/docker-login@master
+ with:
+ docker-token: ${{ secrets.DOCKER_TOKEN }}
+ docker-username: ${{ secrets.DOCKER_USERNAME }}
+ - run: npm run --if-present release
+ env:
+ GITHUB_TOKEN: ${{ secrets.UCI_GITHUB_TOKEN || github.token }}
+ NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
diff --git a/.github/workflows/semantic-pull-request.yml b/.github/workflows/semantic-pull-request.yml
new file mode 100644
index 00000000..bd00f090
--- /dev/null
+++ b/.github/workflows/semantic-pull-request.yml
@@ -0,0 +1,12 @@
+name: Semantic PR
+
+on:
+ pull_request_target:
+ types:
+ - opened
+ - edited
+ - synchronize
+
+jobs:
+ main:
+ uses: pl-strflt/.github/.github/workflows/reusable-semantic-pull-request.yml@v0.3
diff --git a/README.md b/README.md
index f0eaf182..7edf816d 100644
--- a/README.md
+++ b/README.md
@@ -1,33 +1,17 @@
-# ipfs-bitswap
-
[![ipfs.tech](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](https://ipfs.tech)
[![Discuss](https://img.shields.io/discourse/https/discuss.ipfs.tech/posts.svg?style=flat-square)](https://discuss.ipfs.tech)
[![codecov](https://img.shields.io/codecov/c/github/ipfs/js-ipfs-bitswap.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs-bitswap)
-[![CI](https://img.shields.io/github/actions/workflow/status/ipfs/js-ipfs-bitswap/js-test-and-release.yml?branch=master\&style=flat-square)](https://github.com/ipfs/js-ipfs-bitswap/actions/workflows/js-test-and-release.yml?query=branch%3Amaster)
+[![CI](https://img.shields.io/github/actions/workflow/status/ipfs/js-ipfs-bitswap/js-test-and-release.yml?branch=main\&style=flat-square)](https://github.com/ipfs/js-ipfs-bitswap/actions/workflows/js-test-and-release.yml?query=branch%3Amain)
> JavaScript implementation of the Bitswap data exchange protocol used by IPFS
-## Table of contents
-
-- [Install](#install)
- - [Browser `
```
-## Stats
-
-```js
-const bitswapNode = // ...
-
-const stats = bitswapNode.stats
-```
-
-Stats contains a snapshot accessor, a moving average acessor and a peer accessor.
-
-Besides that, it emits "update" events every time it is updated.
-
-```js
-stats.on('update', (stats) => {
- console.log('latest stats snapshot: %j', stats)
-})
-```
-
-### Peer accessor:
-
-You can get the stats for a specific peer by doing:
-
-```js
-const peerStats = stats.forPeer(peerId)
-```
-
-The returned object behaves like the root stats accessor (has a snapshot, a moving average accessors and is an event emitter).
-
-### Global snapshot accessor:
-
-```js
-const snapshot = stats.snapshot
-console.log('stats: %j', snapshot)
-```
-
-the snapshot will contain the following keys, with the values being [bignumber.js](https://github.com/MikeMcl/bignumber.js#readme) instances:
-
-```js
-// stats: {
-// "dataReceived":"96",
-// "blocksReceived":"2",
-// "dataReceived":"96",
-// "dupBlksReceived":"0",
-// "dupDataReceived":"0",
-// "blocksSent":"0",
-// "dataSent":"0",
-// "providesBufferLength":"0",
-// "wantListLength":"0",
-// "peerCount":"1"
-// }
-```
-
-### Moving average accessor:
-
-```js
-const movingAverages = stats.movingAverages
-```
-
-This object contains these properties:
-
-- 'blocksReceived',
-- 'dataReceived',
-- 'dupBlksReceived',
-- 'dupDataReceived',
-- 'blocksSent',
-- 'dataSent',
-- 'providesBufferLength',
-- 'wantListLength',
-- 'peerCount'
-
-```js
-const dataReceivedMovingAverages = movingAverages.dataReceived
-```
-
-Each one of these will contain one key per interval (miliseconds), being the default intervals defined:
-
-- 60000 (1 minute)
-- 300000 (5 minutes)
-- 900000 (15 minutes)
-
-You can then select one of them
-
-```js
-const oneMinuteDataReceivedMovingAverages = dataReceivedMovingAverages[60000]
-```
-
-This object will be a [movingAverage](https://github.com/pgte/moving-average#readme) instance.
-
-## Performance tests
-
-You can run performance tests like this:
-
-```
-$ npm run benchmarks
-```
-
-### Profiling
-
-You can run each of the individual performance tests with a profiler like 0x.
-
-To do that, you need to install 0x:
-
-```bash
-$ npm install 0x --global
-```
-
-And then run the test:
-
-```bash
-$ 0x test/benchmarks/get-many
-```
-
-This will output a flame graph and print the location for it.
-Use the browser Chrome to open and inspect the generated graph.
-
-![Flame graph](https://ipfs.io/ipfs/QmVbyLgYfkLewNtzTAFwAEMmP2hTJgs8sSqsRTBNBjyQ1y)
-
-## API Docs
+# API Docs
-
-## License
+# License
Licensed under either of
- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / )
- MIT ([LICENSE-MIT](LICENSE-MIT) / )
-## Contribute
+# Contribute
Contributions welcome! Please check out [the issues](https://github.com/ipfs/js-ipfs-bitswap/issues).
diff --git a/package.json b/package.json
index 01dc2839..4db0371f 100644
--- a/package.json
+++ b/package.json
@@ -48,7 +48,7 @@
},
"release": {
"branches": [
- "master"
+ "main"
],
"plugins": [
[
diff --git a/src/index.ts b/src/index.ts
index 1c80233b..df7e5fa2 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1,3 +1,9 @@
+/**
+ * @packageDocumentation
+ *
+ * This module implements the [Bitswap protocol](https://docs.ipfs.tech/concepts/bitswap/) in TypeScript.
+ */
+
import { DefaultBitswap } from './bitswap.js'
import type { Message } from './message/message'
import type { BitswapNetworkNotifyProgressEvents, BitswapNetworkWantProgressEvents } from './network.js'