diff --git a/.github/dependabot.yml b/.github/dependabot.yml index de46e32..290ad02 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -4,5 +4,5 @@ updates: directory: "/" schedule: interval: daily - time: "11:00" + time: "10:00" open-pull-requests-limit: 10 diff --git a/.github/workflows/js-test-and-release.yml b/.github/workflows/js-test-and-release.yml new file mode 100644 index 0000000..8630dc5 --- /dev/null +++ b/.github/workflows/js-test-and-release.yml @@ -0,0 +1,152 @@ +name: test & maybe release +on: + push: + branches: + - master # with #262 - ${{{ github.default_branch }}} + pull_request: + branches: + - master # with #262 - ${{{ github.default_branch }}} + +jobs: + + check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + 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: [16] + fail-fast: true + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node }} + - uses: ipfs/aegir/actions/cache-node-modules@master + - run: npm run --if-present test:node + - uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0 + with: + directory: ./.nyc_output + flags: node + + test-chrome: + needs: check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + node-version: lts/* + - uses: ipfs/aegir/actions/cache-node-modules@master + - run: npm run --if-present test:chrome + - uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0 + with: + directory: ./.nyc_output + flags: chrome + + test-chrome-webworker: + needs: check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + node-version: lts/* + - uses: ipfs/aegir/actions/cache-node-modules@master + - run: npm run --if-present test:chrome-webworker + - uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0 + with: + directory: ./.nyc_output + flags: chrome-webworker + + test-firefox: + needs: check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + node-version: lts/* + - uses: ipfs/aegir/actions/cache-node-modules@master + - run: npm run --if-present test:firefox + - uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0 + with: + directory: ./.nyc_output + flags: firefox + + test-firefox-webworker: + needs: check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + node-version: lts/* + - uses: ipfs/aegir/actions/cache-node-modules@master + - run: npm run --if-present test:firefox-webworker + - uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0 + with: + directory: ./.nyc_output + flags: firefox-webworker + + test-electron-main: + needs: check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + 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@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0 + with: + directory: ./.nyc_output + flags: electron-main + + test-electron-renderer: + needs: check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + 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@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0 + with: + directory: ./.nyc_output + flags: electron-renderer + + release: + needs: [test-node, test-chrome, test-chrome-webworker, test-firefox, test-firefox-webworker, test-electron-main, test-electron-renderer] + runs-on: ubuntu-latest + if: github.event_name == 'push' && github.ref == 'refs/heads/master' # with #262 - 'refs/heads/${{{ github.default_branch }}}' + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - uses: actions/setup-node@v2 + 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.GITHUB_TOKEN }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index 05587f3..0000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,52 +0,0 @@ -name: ci -on: - push: - branches: - - master - pull_request: - branches: - - master - -jobs: - check: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - run: npm install - - run: npx aegir lint - - uses: gozala/typescript-error-reporter-action@v1.0.8 - - run: npx aegir build --no-bundle - - run: npx aegir dep-check - test-node: - needs: check - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [windows-latest, ubuntu-latest, macos-latest] - node: [14, 16] - fail-fast: true - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node }} - - run: npm install - - run: npm run pretest - - run: npx nyc --reporter=lcov aegir test -t node -- --bail - - uses: codecov/codecov-action@v1 - test-electron-main: - needs: check - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - run: npm install - - run: npm run pretest - - run: npx xvfb-maybe aegir test -t electron-main --bail -f dist/cjs/node-test/*js - test-electron-renderer: - needs: check - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - run: npm install - - run: npm run pretest - - run: npx xvfb-maybe aegir test -t electron-renderer --bail -f dist/cjs/browser-test/*js diff --git a/LICENSE b/LICENSE index 15ede75..20ce483 100644 --- a/LICENSE +++ b/LICENSE @@ -1,21 +1,4 @@ -MIT License +This project is dual licensed under MIT and Apache-2.0. -Copyright (c) 2017 IPFS - -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. \ No newline at end of file +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 0000000..14478a3 --- /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 0000000..72dc60d --- /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 index 15719c5..4c50240 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/) [![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs) [![standard-readme compliant](https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme) -[![Build Status](https://flat.badgen.net/travis/ipfs/js-datastore-fs)](https://travis-ci.com/ipfs/js-datastore-fs) +[![Build Status](https://github.com/ipfs/js-datastore-fs/actions/workflows/js-test-and-release.yml/badge.svg?branch=master)](https://github.com/ipfs/js-datastore-fs/actions/workflows/js-test-and-release.yml) [![Codecov](https://codecov.io/gh/ipfs/js-datastore-fs/branch/master/graph/badge.svg)](https://codecov.io/gh/ipfs/js-datastore-fs) [![Dependency Status](https://david-dm.org/ipfs/js-datastore-fs.svg?style=flat-square)](https://david-dm.org/ipfs/js-datastore-fs) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard) @@ -13,10 +13,6 @@ > Datastore implementation with file system backend. -## Lead Maintainer - -[Alex Potsides](https://github.com/achingbrain) - ## Table of Contents - [Install](#install) diff --git a/package.json b/package.json index a588bf5..f9d85b7 100644 --- a/package.json +++ b/package.json @@ -2,50 +2,155 @@ "name": "datastore-fs", "version": "6.0.1", "description": "Datastore implementation with file system backend", - "leadMaintainer": "Alex Potsides ", + "author": "Friedel Ziegelmayer", + "license": "Apache-2.0 OR MIT", + "homepage": "https://github.com/ipfs/js-datastore-fs#readme", + "repository": { + "type": "git", + "url": "git+https://github.com/ipfs/js-datastore-fs.git" + }, + "bugs": { + "url": "https://github.com/ipfs/js-datastore-fs/issues" + }, + "keywords": [ + "datastore", + "fs", + "interface", + "ipfs", + "key-value" + ], + "engines": { + "node": ">=16.0.0", + "npm": ">=7.0.0" + }, "main": "src/index.js", - "types": "types/src/index.d.ts", "type": "module", + "types": "types/src/index.d.ts", + "typesVersions": { + "*": { + "*": [ + "types/*", + "types/src/*" + ], + "types/*": [ + "types/*", + "types/src/*" + ] + } + }, "files": [ "*", "!**/*.tsbuildinfo" ], - "browser": { - "fs": false, - "path": false, - "util": false + "exports": { + ".": { + "import": "./src/index.js" + } + }, + "eslintConfig": { + "extends": "ipfs", + "parserOptions": { + "sourceType": "module" + } + }, + "release": { + "branches": [ + "master" + ], + "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": "chore", + "release": "patch" + }, + { + "type": "docs", + "release": "patch" + }, + { + "type": "test", + "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": "Trivial Changes" + }, + { + "type": "test", + "section": "Tests" + } + ] + } + } + ], + "@semantic-release/changelog", + [ + "@semantic-release/npm", + { + "pkgRoot": "dist" + } + ], + "@semantic-release/github", + "@semantic-release/git" + ] }, "scripts": { "clean": "rimraf dist types", "prepare": "aegir build --no-bundle && cp -R types dist", "lint": "aegir ts -p check && aegir lint", - "build": "aegir build --no-bundle", - "release": "aegir release --target node", - "release-minor": "aegir release --type minor --target node", - "release-major": "aegir release --type major --target node", - "pretest": "aegir build --esm-tests", + "build": "aegir build --esm-tests", + "release": "semantic-release", "test": "aegir test", + "test:node": "aegir test -t node", "dep-check": "aegir dep-check -i rimraf" }, - "repository": { - "type": "git", - "url": "git+https://github.com/ipfs/js-datastore-fs.git" - }, - "keywords": [ - "interface", - "key-value", - "ipfs", - "datastore", - "fs" - ], - "author": "Friedel Ziegelmayer", - "license": "MIT", - "bugs": { - "url": "https://github.com/ipfs/js-datastore-fs/issues" - }, - "homepage": "https://github.com/ipfs/js-datastore-fs#readme", "dependencies": { - "datastore-core": "^6.0.5", + "datastore-core": "^7.0.0", "fast-write-atomic": "^0.2.0", "interface-datastore": "^6.0.2", "it-glob": "^1.0.1", @@ -56,35 +161,17 @@ "devDependencies": { "@types/mkdirp": "^1.0.2", "@types/rimraf": "^3.0.2", - "aegir": "^35.0.3", + "aegir": "^36.1.3", "async-iterator-all": "^1.0.0", "detect-node": "^2.0.4", "interface-datastore-tests": "^2.0.3", - "ipfs-utils": "^8.1.3", + "ipfs-utils": "^9.0.4", "memdown": "^6.0.0", "rimraf": "^3.0.2" }, - "eslintConfig": { - "extends": "ipfs", - "parserOptions": { - "sourceType": "module" - } - }, - "contributors": [ - "achingbrain ", - "David Dias ", - "Friedel Ziegelmayer ", - "Jacob Heun ", - "Hugo Dias ", - "Pedro Teixeira ", - "Hector Sanjuan ", - "ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ ", - "Richard Schneider ", - "Vasco Santos ", - "Zane Starr ", - "Stephen Whitmore ", - "Matteo Collina ", - "Dmitriy Ryajov ", - "Bryan Stenson " - ] + "browser": { + "fs": false, + "path": false, + "util": false + } } diff --git a/src/index.js b/src/index.js index 2c43354..6d7c7df 100644 --- a/src/index.js +++ b/src/index.js @@ -92,7 +92,7 @@ export class FsDatastore extends BaseDatastore { throw Errors.dbOpenFailedError(new Error(`Datastore directory: ${this.path} already exists`)) } return Promise.resolve() - } catch (err) { + } catch (/** @type {any} */ err) { if (err.code === 'ERR_NOT_FOUND' && this.opts.createIfMissing) { mkdirp.sync(this.path, { fs: fs }) return Promise.resolve() @@ -177,7 +177,7 @@ export class FsDatastore extends BaseDatastore { try { await mkdirp(parts.dir, { fs: fs }) await writeFile(parts.file, val) - } catch (err) { + } catch (/** @type {any} */ err) { throw Errors.dbWriteFailedError(err) } } @@ -216,7 +216,7 @@ export class FsDatastore extends BaseDatastore { let data try { data = await fs.promises.readFile(file) - } catch (err) { + } catch (/** @type {any} */ err) { throw Errors.notFoundError(err) } return data @@ -233,7 +233,7 @@ export class FsDatastore extends BaseDatastore { let data try { data = await fs.promises.readFile(parts.file) - } catch (err) { + } catch (/** @type {any} */ err) { throw Errors.notFoundError(err) } return data @@ -282,7 +282,7 @@ export class FsDatastore extends BaseDatastore { try { await fs.promises.access(parts.file) - } catch (err) { + } catch (/** @type {any} */ err) { return false } return true @@ -298,7 +298,7 @@ export class FsDatastore extends BaseDatastore { const parts = this._encode(key) try { await fs.promises.unlink(parts.file) - } catch (err) { + } catch (/** @type {any} */ err) { if (err.code === 'ENOENT') { return } @@ -334,7 +334,7 @@ export class FsDatastore extends BaseDatastore { } yield pair - } catch (err) { + } catch (/** @type {any} */ err) { // if keys are removed from the datastore while the query is // running, we may encounter missing files. if (err.code !== 'ENOENT') { diff --git a/test/index.spec.js b/test/index.spec.js index cd0e7fa..d880022 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -106,7 +106,7 @@ describe('FsDatastore', () => { try { await fs.get(key) throw new Error('Should have errored') - } catch (err) { + } catch (/** @type {any} */ err) { expect(err.code).to.equal('ERR_NOT_FOUND') } })