From 7d0cfd7e0add12ca28d6fc8c139f9573afc4c3c1 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 30 Nov 2023 12:58:22 +0000 Subject: [PATCH] chore: update branch name --- .github/workflows/js-test-and-release.yml | 195 +++++++++++++++++++- .github/workflows/semantic-pull-request.yml | 12 ++ .github/workflows/stale.yml | 13 ++ README.md | 78 +++----- package.json | 8 +- src/index.ts | 56 +++++- 6 files changed, 301 insertions(+), 61 deletions(-) create mode 100644 .github/workflows/semantic-pull-request.yml create mode 100644 .github/workflows/stale.yml diff --git a/.github/workflows/js-test-and-release.yml b/.github/workflows/js-test-and-release.yml index 2c7a14bb..2e3db88e 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,189 @@ concurrency: cancel-in-progress: true jobs: - js-test-and-release: - uses: pl-strflt/uci/.github/workflows/js-test-and-release.yml@v0.0 - 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: + 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.ref == 'refs/heads/main' + 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/.github/workflows/stale.yml b/.github/workflows/stale.yml new file mode 100644 index 00000000..16d65d72 --- /dev/null +++ b/.github/workflows/stale.yml @@ -0,0 +1,13 @@ +name: Close and mark stale issue + +on: + schedule: + - cron: '0 0 * * *' + +permissions: + issues: write + pull-requests: write + +jobs: + stale: + uses: pl-strflt/.github/.github/workflows/reusable-stale-issue.yml@v0.3 diff --git a/README.md b/README.md index f6d867ea..ca5b33b9 100644 --- a/README.md +++ b/README.md @@ -1,40 +1,10 @@ -# @multiformats/multiaddr - [![multiformats.io](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://multiformats.io) [![codecov](https://img.shields.io/codecov/c/github/multiformats/js-multiaddr.svg?style=flat-square)](https://codecov.io/gh/multiformats/js-multiaddr) -[![CI](https://img.shields.io/github/actions/workflow/status/multiformats/js-multiaddr/js-test-and-release.yml?branch=master\&style=flat-square)](https://github.com/multiformats/js-multiaddr/actions/workflows/js-test-and-release.yml?query=branch%3Amaster) +[![CI](https://img.shields.io/github/actions/workflow/status/multiformats/js-multiaddr/js-test-and-release.yml?branch=main\&style=flat-square)](https://github.com/multiformats/js-multiaddr/actions/workflows/js-test-and-release.yml?query=branch%3Amain) > multiaddr implementation (binary + string representation of network addresses) -## Table of contents - -- [Install](#install) - - [Browser ` -``` - -## Background - -### What is multiaddr? +# About A standard way to represent addresses that @@ -44,7 +14,7 @@ A standard way to represent addresses that - have a nice string representation - encapsulate well -## Usage +## Example ```js import { multiaddr } from '@multiformats/multiaddr' @@ -61,22 +31,18 @@ addr.toString() // '/ip4/127.0.0.1/udp/1234' addr.protos() -/* -[ - {code: 4, name: 'ip4', size: 32}, - {code: 273, name: 'udp', size: 16} -] -*/ +// [ +// {code: 4, name: 'ip4', size: 32}, +// {code: 273, name: 'udp', size: 16} +// ] // gives you an object that is friendly with what Node.js core modules expect for addresses addr.nodeAddress() -/* -{ - family: 4, - port: 1234, - address: "127.0.0.1" -} -*/ +// { +// family: 4, +// port: 1234, +// address: "127.0.0.1" +// } addr.encapsulate('/sctp/5678') // Multiaddr(/ip4/127.0.0.1/udp/1234/sctp/5678) @@ -102,17 +68,31 @@ The available resolvers are: A resolver receives a `Multiaddr` as a parameter and returns a `Promise>`. -## API Docs +# Install + +```console +$ npm i @multiformats/multiaddr +``` + +## Browser ` +``` + +# API Docs - -## License +# License Licensed under either of - Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) - MIT ([LICENSE-MIT](LICENSE-MIT) / ) -## Contribution +# Contribution Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. diff --git a/package.json b/package.json index e594cfc6..00bde891 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,10 @@ "bugs": { "url": "https://github.com/multiformats/js-multiaddr/issues" }, + "publishConfig": { + "access": "public", + "provenance": true + }, "keywords": [ "binary", "multiaddr", @@ -63,7 +67,7 @@ }, "release": { "branches": [ - "master" + "main" ], "plugins": [ [ @@ -171,7 +175,7 @@ "uint8arrays": "^4.0.2" }, "devDependencies": { - "@types/sinon": "^10.0.14", + "@types/sinon": "^17.0.2", "aegir": "^41.0.11", "sinon": "^17.0.0" }, diff --git a/src/index.ts b/src/index.ts index d0adeec0..b1381a08 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,15 +1,67 @@ /** * @packageDocumentation * - * An implementation of a Multiaddr in JavaScript + * A standard way to represent addresses that + * + * - support any standard network protocol + * - are self-describing + * - have a binary packed format + * - have a nice string representation + * - encapsulate well * * @example * * ```js * import { multiaddr } from '@multiformats/multiaddr' + * const addr = multiaddr("/ip4/127.0.0.1/udp/1234") + * // Multiaddr(/ip4/127.0.0.1/udp/1234) + * + * const addr = multiaddr("/ip4/127.0.0.1/udp/1234") + * // Multiaddr(/ip4/127.0.0.1/udp/1234) + * + * addr.bytes + * // + * + * addr.toString() + * // '/ip4/127.0.0.1/udp/1234' + * + * addr.protos() + * // [ + * // {code: 4, name: 'ip4', size: 32}, + * // {code: 273, name: 'udp', size: 16} + * // ] + * + * // gives you an object that is friendly with what Node.js core modules expect for addresses + * addr.nodeAddress() + * // { + * // family: 4, + * // port: 1234, + * // address: "127.0.0.1" + * // } + * + * addr.encapsulate('/sctp/5678') + * // Multiaddr(/ip4/127.0.0.1/udp/1234/sctp/5678) + * ``` * - * const ma = multiaddr('/ip4/127.0.0.1/tcp/1234') + * ## Resolvers + * + * `multiaddr` allows multiaddrs to be resolved when appropriate resolvers are provided. This module already has resolvers available, but you can also create your own. Resolvers should always be set in the same module that is calling `multiaddr.resolve()` to avoid conflicts if multiple versions of `multiaddr` are in your dependency tree. + * + * To provide multiaddr resolvers you can do: + * + * ```js + * import { resolvers } from '@multiformats/multiaddr' + * + * resolvers.set('dnsaddr', resolvers.dnsaddrResolver) * ``` + * + * The available resolvers are: + * + * | Name | type | Description | + * | ----------------- | --------- | ----------------------------------- | + * | `dnsaddrResolver` | `dnsaddr` | dnsaddr resolution with TXT Records | + * + * A resolver receives a `Multiaddr` as a parameter and returns a `Promise>`. */ import { Multiaddr as MultiaddrClass, symbol } from './multiaddr.js'