From ed4c319a67c18a3dd65e18f18aa12e82080b3fdc Mon Sep 17 00:00:00 2001 From: achingbrain Date: Tue, 2 May 2023 18:42:23 +0100 Subject: [PATCH] feat: initial commit --- .github/dependabot.yml | 11 ++ .github/workflows/automerge.yml | 8 + .github/workflows/js-test-and-release.yml | 181 ++++++++++++++++++ .github/workflows/stale.yml | 26 +++ .gitignore | 9 + LICENSE | 4 + LICENSE-APACHE | 5 + LICENSE-MIT | 19 ++ README.md | 49 +++++ package.json | 48 +++++ packages/dag-cbor/CHANGELOG.md | 0 packages/dag-cbor/LICENSE | 4 + packages/dag-cbor/LICENSE-APACHE | 5 + packages/dag-cbor/LICENSE-MIT | 19 ++ packages/dag-cbor/README.md | 59 ++++++ packages/dag-cbor/package.json | 156 +++++++++++++++ packages/dag-cbor/src/index.ts | 120 ++++++++++++ packages/dag-cbor/test/add.spec.ts | 36 ++++ packages/dag-cbor/test/get.spec.ts | 42 ++++ packages/dag-cbor/tsconfig.json | 10 + packages/interop/.aegir.js | 45 +++++ packages/interop/LICENSE | 4 + packages/interop/LICENSE-APACHE | 5 + packages/interop/LICENSE-MIT | 19 ++ packages/interop/README.md | 59 ++++++ packages/interop/package.json | 82 ++++++++ packages/interop/src/index.ts | 1 + packages/interop/test/dag-json.spec.ts | 64 +++++++ .../test/fixtures/create-helia.browser.ts | 41 ++++ .../interop/test/fixtures/create-helia.ts | 38 ++++ packages/interop/test/fixtures/create-kubo.ts | 28 +++ packages/interop/tsconfig.json | 15 ++ 32 files changed, 1212 insertions(+) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/automerge.yml create mode 100644 .github/workflows/js-test-and-release.yml create mode 100644 .github/workflows/stale.yml create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 LICENSE-APACHE create mode 100644 LICENSE-MIT create mode 100644 README.md create mode 100644 package.json create mode 100644 packages/dag-cbor/CHANGELOG.md create mode 100644 packages/dag-cbor/LICENSE create mode 100644 packages/dag-cbor/LICENSE-APACHE create mode 100644 packages/dag-cbor/LICENSE-MIT create mode 100644 packages/dag-cbor/README.md create mode 100644 packages/dag-cbor/package.json create mode 100644 packages/dag-cbor/src/index.ts create mode 100644 packages/dag-cbor/test/add.spec.ts create mode 100644 packages/dag-cbor/test/get.spec.ts create mode 100644 packages/dag-cbor/tsconfig.json create mode 100644 packages/interop/.aegir.js create mode 100644 packages/interop/LICENSE create mode 100644 packages/interop/LICENSE-APACHE create mode 100644 packages/interop/LICENSE-MIT create mode 100644 packages/interop/README.md create mode 100644 packages/interop/package.json create mode 100644 packages/interop/src/index.ts create mode 100644 packages/interop/test/dag-json.spec.ts create mode 100644 packages/interop/test/fixtures/create-helia.browser.ts create mode 100644 packages/interop/test/fixtures/create-helia.ts create mode 100644 packages/interop/test/fixtures/create-kubo.ts create mode 100644 packages/interop/tsconfig.json diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..0bc3b42d --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,11 @@ +version: 2 +updates: +- package-ecosystem: npm + directory: "/" + schedule: + interval: daily + time: "10:00" + open-pull-requests-limit: 10 + commit-message: + prefix: "deps" + prefix-development: "deps(dev)" diff --git a/.github/workflows/automerge.yml b/.github/workflows/automerge.yml new file mode 100644 index 00000000..d57c2a02 --- /dev/null +++ b/.github/workflows/automerge.yml @@ -0,0 +1,8 @@ +name: Automerge +on: [ pull_request ] + +jobs: + automerge: + uses: protocol/.github/.github/workflows/automerge.yml@master + with: + job: 'automerge' diff --git a/.github/workflows/js-test-and-release.yml b/.github/workflows/js-test-and-release.yml new file mode 100644 index 00000000..51686414 --- /dev/null +++ b/.github/workflows/js-test-and-release.yml @@ -0,0 +1,181 @@ +name: test & maybe release +on: + push: + branches: + - main + pull_request: + +jobs: + + 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 + + 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@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1 + with: + flags: node + + 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@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1 + with: + flags: chrome + + 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@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1 + with: + flags: chrome-webworker + + 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@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1 + with: + flags: firefox + + 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@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1 + with: + flags: firefox-webworker + + 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@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1 + with: + flags: webkit + + 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@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1 + with: + flags: webkit-webworker + + 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@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1 + with: + flags: electron-main + + 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@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1 + with: + flags: electron-renderer + + 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' + 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/stale.yml b/.github/workflows/stale.yml new file mode 100644 index 00000000..6f6d895d --- /dev/null +++ b/.github/workflows/stale.yml @@ -0,0 +1,26 @@ +name: Close and mark stale issue + +on: + schedule: + - cron: '0 0 * * *' + +jobs: + stale: + + runs-on: ubuntu-latest + permissions: + issues: write + pull-requests: write + + steps: + - uses: actions/stale@v3 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + stale-issue-message: 'Oops, seems like we needed more information for this issue, please comment with more details or this issue will be closed in 7 days.' + close-issue-message: 'This issue was closed because it is missing author input.' + stale-issue-label: 'kind/stale' + any-of-labels: 'need/author-input' + exempt-issue-labels: 'need/triage,need/community-input,need/maintainer-input,need/maintainers-input,need/analysis,status/blocked,status/in-progress,status/ready,status/deferred,status/inactive' + days-before-issue-stale: 6 + days-before-issue-close: 7 + enable-statistics: true diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..7ad9e674 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +node_modules +build +dist +.docs +.coverage +node_modules +package-lock.json +yarn.lock +.vscode diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..20ce483c --- /dev/null +++ b/LICENSE @@ -0,0 +1,4 @@ +This project is dual licensed under MIT and Apache-2.0. + +MIT: https://www.opensource.org/licenses/mit +Apache-2.0: https://www.apache.org/licenses/license-2.0 diff --git a/LICENSE-APACHE b/LICENSE-APACHE new file mode 100644 index 00000000..14478a3b --- /dev/null +++ b/LICENSE-APACHE @@ -0,0 +1,5 @@ +Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. diff --git a/LICENSE-MIT b/LICENSE-MIT new file mode 100644 index 00000000..72dc60d8 --- /dev/null +++ b/LICENSE-MIT @@ -0,0 +1,19 @@ +The MIT License (MIT) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 00000000..f99f7491 --- /dev/null +++ b/README.md @@ -0,0 +1,49 @@ +

+ + Helia logo + +

+ +# @helia/dag-cbor + +[![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/helia-dag-cbor.svg?style=flat-square)](https://codecov.io/gh/ipfs/helia-dag-cbor) +[![CI](https://img.shields.io/github/actions/workflow/status/ipfs/helia-dag-cbor/js-test-and-release.yml?branch=main\&style=flat-square)](https://github.com/ipfs/helia-dag-cbor/actions/workflows/js-test-and-release.yml?query=branch%3Amain) + +> Add/get IPLD blocks containing json with your Helia node + +## Table of contents + +- [Structure](#structure) +- [API Docs](#api-docs) +- [License](#license) +- [Contribute](#contribute) + +## Structure + +- [`/packages/dag-cbor`](./packages/dag-cbor) Add/get IPLD blocks containing dag-cbor with your Helia node +- [`/packages/interop`](./packages/interop) Interop tests for @helia/dag-cbor + +## API Docs + +- + +## License + +Licensed under either of + +- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) +- MIT ([LICENSE-MIT](LICENSE-MIT) / ) + +## Contribute + +Contributions welcome! Please check out [the issues](https://github.com/ipfs/helia-dag-cbor/issues). + +Also see our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. + +Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md). + +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. + +[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md) diff --git a/package.json b/package.json new file mode 100644 index 00000000..06a10056 --- /dev/null +++ b/package.json @@ -0,0 +1,48 @@ +{ + "name": "@helia/dag-cbor", + "version": "0.0.0", + "description": "Add/get IPLD blocks containing json with your Helia node", + "license": "Apache-2.0 OR MIT", + "homepage": "https://github.com/ipfs/helia-dag-cbor#readme", + "repository": { + "type": "git", + "url": "git+https://github.com/ipfs/helia-dag-cbor.git" + }, + "bugs": { + "url": "https://github.com/ipfs/helia-dag-cbor/issues" + }, + "keywords": [ + "ipfs" + ], + "engines": { + "node": ">=16.0.0", + "npm": ">=7.0.0" + }, + "private": true, + "scripts": { + "reset": "aegir run clean && aegir clean **/node_modules **/package-lock.json", + "test": "aegir run test", + "test:node": "aegir run test:node", + "test:chrome": "aegir run test:chrome", + "test:chrome-webworker": "aegir run test:chrome-webworker", + "test:firefox": "aegir run test:firefox", + "test:firefox-webworker": "aegir run test:firefox-webworker", + "test:electron-main": "aegir run test:electron-main", + "test:electron-renderer": "aegir run test:electron-renderer", + "clean": "aegir run clean", + "generate": "aegir run generate", + "build": "aegir run build", + "lint": "aegir run lint", + "docs": "NODE_OPTIONS=--max_old_space_size=4096 aegir docs", + "docs:no-publish": "npm run docs -- --publish false", + "dep-check": "aegir run dep-check", + "release": "npm run docs:no-publish && aegir run release && npm run docs" + }, + "devDependencies": { + "aegir": "^39.0.3" + }, + "type": "module", + "workspaces": [ + "packages/*" + ] +} diff --git a/packages/dag-cbor/CHANGELOG.md b/packages/dag-cbor/CHANGELOG.md new file mode 100644 index 00000000..e69de29b diff --git a/packages/dag-cbor/LICENSE b/packages/dag-cbor/LICENSE new file mode 100644 index 00000000..20ce483c --- /dev/null +++ b/packages/dag-cbor/LICENSE @@ -0,0 +1,4 @@ +This project is dual licensed under MIT and Apache-2.0. + +MIT: https://www.opensource.org/licenses/mit +Apache-2.0: https://www.apache.org/licenses/license-2.0 diff --git a/packages/dag-cbor/LICENSE-APACHE b/packages/dag-cbor/LICENSE-APACHE new file mode 100644 index 00000000..14478a3b --- /dev/null +++ b/packages/dag-cbor/LICENSE-APACHE @@ -0,0 +1,5 @@ +Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. diff --git a/packages/dag-cbor/LICENSE-MIT b/packages/dag-cbor/LICENSE-MIT new file mode 100644 index 00000000..72dc60d8 --- /dev/null +++ b/packages/dag-cbor/LICENSE-MIT @@ -0,0 +1,19 @@ +The MIT License (MIT) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/packages/dag-cbor/README.md b/packages/dag-cbor/README.md new file mode 100644 index 00000000..6350b669 --- /dev/null +++ b/packages/dag-cbor/README.md @@ -0,0 +1,59 @@ +

+ + Helia logo + +

+ +# @helia/dag-cbor + +[![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/helia-dag-cbor.svg?style=flat-square)](https://codecov.io/gh/ipfs/helia-dag-cbor) +[![CI](https://img.shields.io/github/actions/workflow/status/ipfs/helia-dag-cbor/js-test-and-release.yml?branch=main\&style=flat-square)](https://github.com/ipfs/helia-dag-cbor/actions/workflows/js-test-and-release.yml?query=branch%3Amain) + +> Add/get IPLD blocks containing dag-cbor with your Helia node + +## Table of contents + +- [Install](#install) + - [Browser ` +``` + +## API Docs + +- + +## License + +Licensed under either of + +- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) +- MIT ([LICENSE-MIT](LICENSE-MIT) / ) + +## Contribute + +Contributions welcome! Please check out [the issues](https://github.com/ipfs/helia-dag-cbor/issues). + +Also see our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. + +Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md). + +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. + +[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md) diff --git a/packages/dag-cbor/package.json b/packages/dag-cbor/package.json new file mode 100644 index 00000000..6d417ebd --- /dev/null +++ b/packages/dag-cbor/package.json @@ -0,0 +1,156 @@ +{ + "name": "@helia/dag-cbor", + "version": "0.0.0", + "description": "Add/get IPLD blocks containing dag-cbor with your Helia node", + "license": "Apache-2.0 OR MIT", + "homepage": "https://github.com/ipfs/helia-dag-cbor/tree/master/packages/dag-cbor#readme", + "repository": { + "type": "git", + "url": "git+https://github.com/ipfs/helia-dag-cbor.git" + }, + "bugs": { + "url": "https://github.com/ipfs/helia-dag-cbor/issues" + }, + "keywords": [ + "IPFS" + ], + "engines": { + "node": ">=16.0.0", + "npm": ">=7.0.0" + }, + "type": "module", + "types": "./dist/src/index.d.ts", + "files": [ + "src", + "dist", + "!dist/test", + "!**/*.tsbuildinfo" + ], + "exports": { + ".": { + "types": "./dist/src/index.d.ts", + "import": "./dist/src/index.js" + } + }, + "eslintConfig": { + "extends": "ipfs", + "parserOptions": { + "sourceType": "module" + } + }, + "release": { + "branches": [ + "main" + ], + "plugins": [ + [ + "@semantic-release/commit-analyzer", + { + "preset": "conventionalcommits", + "releaseRules": [ + { + "breaking": true, + "release": "major" + }, + { + "revert": true, + "release": "patch" + }, + { + "type": "feat", + "release": "minor" + }, + { + "type": "fix", + "release": "patch" + }, + { + "type": "docs", + "release": "patch" + }, + { + "type": "test", + "release": "patch" + }, + { + "type": "deps", + "release": "patch" + }, + { + "scope": "no-release", + "release": false + } + ] + } + ], + [ + "@semantic-release/release-notes-generator", + { + "preset": "conventionalcommits", + "presetConfig": { + "types": [ + { + "type": "feat", + "section": "Features" + }, + { + "type": "fix", + "section": "Bug Fixes" + }, + { + "type": "chore", + "section": "Trivial Changes" + }, + { + "type": "docs", + "section": "Documentation" + }, + { + "type": "deps", + "section": "Dependencies" + }, + { + "type": "test", + "section": "Tests" + } + ] + } + } + ], + "@semantic-release/changelog", + "@semantic-release/npm", + "@semantic-release/github", + "@semantic-release/git" + ] + }, + "scripts": { + "clean": "aegir clean", + "lint": "aegir lint", + "dep-check": "aegir dep-check", + "build": "aegir build", + "docs": "aegir docs", + "test": "aegir test", + "test:chrome": "aegir test -t browser --cov", + "test:chrome-webworker": "aegir test -t webworker", + "test:firefox": "aegir test -t browser -- --browser firefox", + "test:firefox-webworker": "aegir test -t webworker -- --browser firefox", + "test:node": "aegir test -t node --cov", + "test:electron-main": "aegir test -t electron-main", + "release": "aegir release" + }, + "dependencies": { + "@helia/interface": "^1.0.0", + "@ipld/dag-cbor": "^9.0.0", + "@libp2p/interfaces": "^3.3.1", + "interface-blockstore": "^5.0.0", + "multiformats": "^11.0.1", + "progress-events": "^1.0.0" + }, + "devDependencies": { + "aegir": "^39.0.3", + "blockstore-core": "^4.0.1" + }, + "typedoc": { + "entryPoint": "./src/index.ts" + } +} diff --git a/packages/dag-cbor/src/index.ts b/packages/dag-cbor/src/index.ts new file mode 100644 index 00000000..18f148f9 --- /dev/null +++ b/packages/dag-cbor/src/index.ts @@ -0,0 +1,120 @@ +/** + * @packageDocumentation + * + * `@helia/dag-cbor` makes working with DAG-JSON {@link https://github.com/ipfs/helia Helia} simple & straightforward. + * + * See the {@link Strings Strings interface} for all available operations. + * + * @example + * + * ```typescript + * import { createHelia } from 'helia' + * import { dagCbor } from '@helia/dag-cbor' + * import { CID } from 'multiformats/cid' + * + * const d = dagCbor(helia) + * const cid = await d.put({ + * hello: 'world' + * }) + * const obj = await d.get(cid) + * + * console.info(obj) + * // { hello: 'world' } + * ``` + */ + +import * as codec from '@ipld/dag-cbor' +import { CID } from 'multiformats/cid' +import { sha256 } from 'multiformats/hashes/sha2' +import type { Blocks, GetBlockProgressEvents, PutBlockProgressEvents } from '@helia/interface/blocks' +import type { AbortOptions } from '@libp2p/interfaces' +import type { BlockCodec } from 'multiformats/codecs/interface' +import type { MultihashHasher } from 'multiformats/hashes/interface' +import type { ProgressOptions } from 'progress-events' + +export interface DAGCBORComponents { + blockstore: Blocks +} + +export interface AddOptions extends AbortOptions, ProgressOptions { + hasher: MultihashHasher +} + +export interface GetOptions extends AbortOptions, ProgressOptions { + codec: BlockCodec +} + +/** + * The JSON interface provides a simple and intuitive way to add/get objects + * with your Helia node and is a great place to start learning about IPFS. + */ +export interface DAGCBOR { + /** + * Add an object to your Helia node and get a CID that refers to the block the + * object has been stored as. + * + * @example + * + * ```typescript + * import { json } from '@helia/dag-cbor' + * + * const j = json(helia) + * const cid = await str.add({ hello: 'world' }) + * + * console.info(cid) + * // CID(bafyreidykglsfhoixmivffc5uwhcgshx4j465xwqntbmu43nb2dzqwfvae) + * ``` + */ + add: (str: unknown, options?: Partial) => Promise + + /** + * Get an object from your Helia node, either previously added to it or to + * another node on the network. + * + * @example + * + * ```typescript + * import { json } from '@helia/dag-cbor' + * import { CID } from 'multiformats/cid' + * + * const j = json(helia) + * const cid = CID.parse('bafyreidykglsfhoixmivffc5uwhcgshx4j465xwqntbmu43nb2dzqwfvae') + * const obj = await j.get(cid) + * + * console.info(obj) + * // { hello: 'world' } + * ``` + */ + get: (cid: CID, options?: Partial) => Promise +} + +class DefaultDAGCBOR implements DAGCBOR { + private readonly components: DAGCBORComponents + + constructor (components: DAGCBORComponents) { + this.components = components + } + + async add (obj: any, options: Partial = {}): Promise { + const buf = codec.encode(obj) + const hash = await (options.hasher ?? sha256).digest(buf) + const cid = CID.createV1(codec.code, hash) + + await this.components.blockstore.put(cid, buf, options) + + return cid + } + + async get (cid: CID, options: Partial = {}): Promise { + const buf = await this.components.blockstore.get(cid, options) + + return codec.decode(buf) + } +} + +/** + * Create a {@link DAGCBOR} instance for use with {@link https://github.com/ipfs/helia Helia} + */ +export function dagCbor (helia: { blockstore: Blocks }): DAGCBOR { + return new DefaultDAGCBOR(helia) +} diff --git a/packages/dag-cbor/test/add.spec.ts b/packages/dag-cbor/test/add.spec.ts new file mode 100644 index 00000000..eb1e52c7 --- /dev/null +++ b/packages/dag-cbor/test/add.spec.ts @@ -0,0 +1,36 @@ +/* eslint-env mocha */ + +import { expect } from 'aegir/chai' +import { MemoryBlockstore } from 'blockstore-core' +import { identity } from 'multiformats/hashes/identity' +import { dagCbor, type DAGCBOR } from '../src/index.js' +import type { Blockstore } from 'interface-blockstore' + +describe('put', () => { + let blockstore: Blockstore + let d: DAGCBOR + + beforeEach(async () => { + blockstore = new MemoryBlockstore() + + d = dagCbor({ blockstore }) + }) + + it('adds an object', async () => { + const cid = await d.add({ + hello: 'world' + }) + + expect(`${cid}`).to.equal('bafyreidykglsfhoixmivffc5uwhcgshx4j465xwqntbmu43nb2dzqwfvae') + }) + + it('adds an object with a non-default hashing algorithm', async () => { + const cid = await d.add({ + hello: 'world' + }, { + hasher: identity + }) + + expect(`${cid}`).to.equal('bafyqadnbmvugk3dmn5sxo33snrsa') + }) +}) diff --git a/packages/dag-cbor/test/get.spec.ts b/packages/dag-cbor/test/get.spec.ts new file mode 100644 index 00000000..e893125d --- /dev/null +++ b/packages/dag-cbor/test/get.spec.ts @@ -0,0 +1,42 @@ +/* eslint-env mocha */ + +import { expect } from 'aegir/chai' +import { MemoryBlockstore } from 'blockstore-core' +import { identity } from 'multiformats/hashes/identity' +import { dagCbor, type DAGCBOR } from '../src/index.js' +import type { Blockstore } from 'interface-blockstore' +import type { CID } from 'multiformats/cid' + +describe('get', () => { + let blockstore: Blockstore + let d: DAGCBOR + let cid: CID + + beforeEach(async () => { + blockstore = new MemoryBlockstore() + + d = dagCbor({ blockstore }) + cid = await d.add({ + hello: 'world' + }) + }) + + it('gets an object', async () => { + const result = await d.get(cid) + + expect(result).to.deep.equal({ + hello: 'world' + }) + }) + + it('gets an object with a non-default hashing algorithm', async () => { + const input = { + hello: 'world' + } + const cid = await d.add(input, { + hasher: identity + }) + + await expect(d.get(cid)).to.eventually.deep.equal(input) + }) +}) diff --git a/packages/dag-cbor/tsconfig.json b/packages/dag-cbor/tsconfig.json new file mode 100644 index 00000000..13a35996 --- /dev/null +++ b/packages/dag-cbor/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "aegir/src/config/tsconfig.aegir.json", + "compilerOptions": { + "outDir": "dist" + }, + "include": [ + "src", + "test" + ] +} diff --git a/packages/interop/.aegir.js b/packages/interop/.aegir.js new file mode 100644 index 00000000..498799ac --- /dev/null +++ b/packages/interop/.aegir.js @@ -0,0 +1,45 @@ +import getPort from 'aegir/get-port' +import { createServer } from 'ipfsd-ctl' +import * as kuboRpcClient from 'kubo-rpc-client' + +/** @type {import('aegir').PartialOptions} */ +export default { + test: { + before: async (options) => { + if (options.runner !== 'node') { + const ipfsdPort = await getPort() + const ipfsdServer = await createServer({ + host: '127.0.0.1', + port: ipfsdPort + }, { + ipfsBin: (await import('go-ipfs')).default.path(), + kuboRpcModule: kuboRpcClient, + ipfsOptions: { + config: { + Addresses: { + Swarm: [ + "/ip4/0.0.0.0/tcp/4001", + "/ip4/0.0.0.0/tcp/4002/ws" + ] + } + } + } + }).start() + + return { + env: { + IPFSD_SERVER: `http://127.0.0.1:${ipfsdPort}` + }, + ipfsdServer + } + } + + return {} + }, + after: async (options, beforeResult) => { + if (options.runner !== 'node') { + await beforeResult.ipfsdServer.stop() + } + } + } +} diff --git a/packages/interop/LICENSE b/packages/interop/LICENSE new file mode 100644 index 00000000..20ce483c --- /dev/null +++ b/packages/interop/LICENSE @@ -0,0 +1,4 @@ +This project is dual licensed under MIT and Apache-2.0. + +MIT: https://www.opensource.org/licenses/mit +Apache-2.0: https://www.apache.org/licenses/license-2.0 diff --git a/packages/interop/LICENSE-APACHE b/packages/interop/LICENSE-APACHE new file mode 100644 index 00000000..14478a3b --- /dev/null +++ b/packages/interop/LICENSE-APACHE @@ -0,0 +1,5 @@ +Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. diff --git a/packages/interop/LICENSE-MIT b/packages/interop/LICENSE-MIT new file mode 100644 index 00000000..72dc60d8 --- /dev/null +++ b/packages/interop/LICENSE-MIT @@ -0,0 +1,19 @@ +The MIT License (MIT) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/packages/interop/README.md b/packages/interop/README.md new file mode 100644 index 00000000..b7fddf73 --- /dev/null +++ b/packages/interop/README.md @@ -0,0 +1,59 @@ +

+ + Helia logo + +

+ +# @helia/dag-cbor-interop + +[![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/helia-dag-cbor.svg?style=flat-square)](https://codecov.io/gh/ipfs/helia-dag-cbor) +[![CI](https://img.shields.io/github/actions/workflow/status/ipfs/helia-dag-cbor/js-test-and-release.yml?branch=main\&style=flat-square)](https://github.com/ipfs/helia-dag-cbor/actions/workflows/js-test-and-release.yml?query=branch%3Amain) + +> Interop tests for @helia/dag-cbor + +## Table of contents + +- [Install](#install) + - [Browser ` +``` + +## API Docs + +- + +## License + +Licensed under either of + +- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) +- MIT ([LICENSE-MIT](LICENSE-MIT) / ) + +## Contribute + +Contributions welcome! Please check out [the issues](https://github.com/ipfs/helia-dag-cbor/issues). + +Also see our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. + +Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md). + +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. + +[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md) diff --git a/packages/interop/package.json b/packages/interop/package.json new file mode 100644 index 00000000..f9f31332 --- /dev/null +++ b/packages/interop/package.json @@ -0,0 +1,82 @@ +{ + "name": "@helia/dag-cbor-interop", + "version": "0.0.0", + "description": "Interop tests for @helia/dag-cbor", + "license": "Apache-2.0 OR MIT", + "homepage": "https://github.com/ipfs/helia-dag-cbor/tree/master/packages/interop#readme", + "repository": { + "type": "git", + "url": "git+https://github.com/ipfs/helia-dag-cbor.git" + }, + "bugs": { + "url": "https://github.com/ipfs/helia-dag-cbor/issues" + }, + "keywords": [ + "IPFS" + ], + "engines": { + "node": ">=16.0.0", + "npm": ">=7.0.0" + }, + "type": "module", + "types": "./dist/src/index.d.ts", + "files": [ + "src", + "dist", + "!dist/test", + "!**/*.tsbuildinfo" + ], + "exports": { + ".": { + "types": "./dist/src/index.d.ts", + "import": "./dist/src/index.js" + } + }, + "eslintConfig": { + "extends": "ipfs", + "parserOptions": { + "sourceType": "module" + } + }, + "scripts": { + "clean": "aegir clean", + "lint": "aegir lint", + "dep-check": "aegir dep-check", + "build": "aegir build", + "test": "aegir test", + "test:chrome": "aegir test -t browser --cov", + "test:chrome-webworker": "aegir test -t webworker", + "test:firefox": "aegir test -t browser -- --browser firefox", + "test:firefox-webworker": "aegir test -t webworker -- --browser firefox", + "test:node": "aegir test -t node --cov", + "test:electron-main": "aegir test -t electron-main" + }, + "devDependencies": { + "@chainsafe/libp2p-noise": "^11.0.0", + "@chainsafe/libp2p-yamux": "^4.0.1", + "@helia/dag-cbor": "~0.0.0", + "@helia/interface": "^1.0.0", + "@ipld/dag-cbor": "^9.0.0", + "@libp2p/tcp": "^7.0.1", + "@libp2p/websockets": "^6.0.1", + "aegir": "^39.0.3", + "blockstore-core": "^4.0.1", + "datastore-core": "^9.0.3", + "go-ipfs": "^0.19.0", + "helia": "^1.0.0", + "ipfs-core-types": "^0.14.0", + "ipfsd-ctl": "^13.0.0", + "kubo-rpc-client": "^3.0.0", + "libp2p": "^0.44.0", + "merge-options": "^3.0.4", + "wherearewe": "^2.0.1" + }, + "browser": { + "./dist/test/fixtures/create-helia.js": "./dist/test/fixtures/create-helia.browser.js", + "go-ipfs": false + }, + "private": true, + "typedoc": { + "entryPoint": "./src/index.ts" + } +} diff --git a/packages/interop/src/index.ts b/packages/interop/src/index.ts new file mode 100644 index 00000000..336ce12b --- /dev/null +++ b/packages/interop/src/index.ts @@ -0,0 +1 @@ +export {} diff --git a/packages/interop/test/dag-json.spec.ts b/packages/interop/test/dag-json.spec.ts new file mode 100644 index 00000000..dd4ef3e1 --- /dev/null +++ b/packages/interop/test/dag-json.spec.ts @@ -0,0 +1,64 @@ +/* eslint-env mocha */ + +import { dagCbor, type DAGCBOR, type AddOptions } from '@helia/dag-cbor' +import * as codec from '@ipld/dag-cbor' +import { expect } from 'aegir/chai' +import { createHeliaNode } from './fixtures/create-helia.js' +import { createKuboNode } from './fixtures/create-kubo.js' +import type { Helia } from '@helia/interface' +import type { PutOptions as KuboAddOptions } from 'ipfs-core-types/src/block/index.js' +import type { Controller } from 'ipfsd-ctl' + +describe('dag-json interop', () => { + let helia: Helia + let d: DAGCBOR + let kubo: Controller + + async function expectSameCid (data: () => any, heliaOpts: Partial = {}, kuboOpts: KuboAddOptions = {}): Promise { + const heliaCid = await d.add(data(), heliaOpts) + const kuboCid = await kubo.api.dag.put(data(), kuboOpts) + + expect(heliaCid.toString()).to.equal(kuboCid.toString()) + } + + beforeEach(async () => { + helia = await createHeliaNode() + d = dagCbor(helia) + kubo = await createKuboNode() + + await helia.libp2p.dial((await (kubo.api.id())).addresses) + }) + + afterEach(async () => { + if (helia != null) { + await helia.stop() + } + + if (kubo != null) { + await kubo.stop() + } + }) + + it('should create the same CID for a string', async () => { + const candidate = (): any => ({ hello: 'world' }) + + await expectSameCid(candidate) + }) + + it('should add to helia and fetch from kubo', async () => { + const input = { hello: 'world' } + const cid = await d.add(input) + const block = await kubo.api.block.get(cid) + const output = codec.decode(block) + + expect(output).to.deep.equal(input) + }) + + it('should add to kubo and fetch from helia', async () => { + const input = { hello: 'world' } + const cid = await kubo.api.block.put(codec.encode(input)) + const output = await d.get(cid) + + expect(output).to.deep.equal(input) + }) +}) diff --git a/packages/interop/test/fixtures/create-helia.browser.ts b/packages/interop/test/fixtures/create-helia.browser.ts new file mode 100644 index 00000000..6baa5299 --- /dev/null +++ b/packages/interop/test/fixtures/create-helia.browser.ts @@ -0,0 +1,41 @@ +import { noise } from '@chainsafe/libp2p-noise' +import { yamux } from '@chainsafe/libp2p-yamux' +import { webSockets } from '@libp2p/websockets' +import { all } from '@libp2p/websockets/filters' +import { MemoryBlockstore } from 'blockstore-core' +import { MemoryDatastore } from 'datastore-core' +import { createHelia } from 'helia' +import { createLibp2p } from 'libp2p' +import type { Helia } from '@helia/interface' + +export async function createHeliaNode (): Promise { + const blockstore = new MemoryBlockstore() + const datastore = new MemoryDatastore() + + // dial-only in the browser until webrtc browser-to-browser arrives + const libp2p = await createLibp2p({ + transports: [ + webSockets({ + filter: all + }) + ], + connectionEncryption: [ + noise() + ], + streamMuxers: [ + yamux() + ], + datastore, + nat: { + enabled: false + } + }) + + const helia = await createHelia({ + libp2p, + blockstore, + datastore + }) + + return helia +} diff --git a/packages/interop/test/fixtures/create-helia.ts b/packages/interop/test/fixtures/create-helia.ts new file mode 100644 index 00000000..c92d309b --- /dev/null +++ b/packages/interop/test/fixtures/create-helia.ts @@ -0,0 +1,38 @@ +import { noise } from '@chainsafe/libp2p-noise' +import { yamux } from '@chainsafe/libp2p-yamux' +import { tcp } from '@libp2p/tcp' +import { MemoryBlockstore } from 'blockstore-core' +import { MemoryDatastore } from 'datastore-core' +import { createHelia } from 'helia' +import { createLibp2p, type Libp2pOptions } from 'libp2p' +import type { Helia } from '@helia/interface' + +export async function createHeliaNode (config: Libp2pOptions = {}): Promise { + const blockstore = new MemoryBlockstore() + const datastore = new MemoryDatastore() + + const libp2p = await createLibp2p({ + transports: [ + tcp() + ], + connectionEncryption: [ + noise() + ], + streamMuxers: [ + yamux() + ], + datastore, + nat: { + enabled: false + }, + ...config + }) + + const helia = await createHelia({ + libp2p, + blockstore, + datastore + }) + + return helia +} diff --git a/packages/interop/test/fixtures/create-kubo.ts b/packages/interop/test/fixtures/create-kubo.ts new file mode 100644 index 00000000..52ed76e1 --- /dev/null +++ b/packages/interop/test/fixtures/create-kubo.ts @@ -0,0 +1,28 @@ + +// @ts-expect-error no types +import * as goIpfs from 'go-ipfs' +import { type Controller, type ControllerOptions, createController } from 'ipfsd-ctl' +import * as kuboRpcClient from 'kubo-rpc-client' +import mergeOptions from 'merge-options' +import { isElectronMain, isNode } from 'wherearewe' + +export async function createKuboNode (options: ControllerOptions<'go'> = {}): Promise { + const opts = mergeOptions({ + kuboRpcModule: kuboRpcClient, + ipfsBin: isNode || isElectronMain ? goIpfs.path() : undefined, + test: true, + endpoint: process.env.IPFSD_SERVER, + ipfsOptions: { + config: { + Addresses: { + Swarm: [ + '/ip4/0.0.0.0/tcp/4001', + '/ip4/0.0.0.0/tcp/4002/ws' + ] + } + } + } + }, options) + + return createController(opts) +} diff --git a/packages/interop/tsconfig.json b/packages/interop/tsconfig.json new file mode 100644 index 00000000..a1ee8237 --- /dev/null +++ b/packages/interop/tsconfig.json @@ -0,0 +1,15 @@ +{ + "extends": "aegir/src/config/tsconfig.aegir.json", + "compilerOptions": { + "outDir": "dist" + }, + "include": [ + "src", + "test" + ], + "references": [ + { + "path": "../dag-cbor" + } + ] +}