Skip to content

Commit

Permalink
feat: add types (#275)
Browse files Browse the repository at this point in the history
Changes:

   fix: fix possible undefined datastores
   - split datastore instantiation from opening
   -  add it-pushable types
   - add just-range types
   - add proper-lockfile types
   - fix lock.close we werent waiting for the promise
   - adds types
   - removes fake async
   - fixes tests for async errors that now are sync
   - adds local types for merge-options

Co-authored-by: achingbrain <[email protected]>
  • Loading branch information
hugomrdias and achingbrain authored Mar 5, 2021
1 parent a9ea5aa commit 1f8ba76
Show file tree
Hide file tree
Showing 38 changed files with 750 additions and 327 deletions.
33 changes: 26 additions & 7 deletions .aegir.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
'use strict'
const path = require('path')

module.exports = {
webpack: {
node: {
// this is needed until level stops using node buffers in browser code
Buffer: true,
/** @type {import('aegir').Options["build"]["config"]} */
const esbuild = {
inject: [path.join(__dirname, 'scripts/node-globals.js')],
plugins: [
{
name: 'node built ins',
setup (build) {
build.onResolve({ filter: /^stream$/ }, () => {
return { path: require.resolve('readable-stream') }
})
}
}
]
}

// needed by binary-parse-stream
stream: true
/** @type {import('aegir').PartialOptions} */
module.exports = {
test: {
browser: {
config: {
buildConfig: esbuild
}
}
},
build: {
bundlesizeMax: '130kB',
config: esbuild
}
}
79 changes: 79 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
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
- run: npx aegir ts -p check
# or
# - uses: gozala/[email protected]
- run: npx aegir build
- run: npx aegir dep-check
- uses: ipfs/aegir/actions/bundle-size@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
test-node:
needs: check
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
node: [14, 15]
fail-fast: true
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- run: npm install
- run: npx aegir test -t node --bail --cov
- uses: codecov/codecov-action@v1
test-chrome:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: microsoft/playwright-github-action@v1
- run: npm install
- run: npx aegir test -t browser -t webworker --bail # add --cov later when its fixed
- uses: codecov/codecov-action@v1
test-firefox:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: microsoft/playwright-github-action@v1
- run: npm install
- run: npx aegir test -t browser -t webworker --bail -- --browser firefox
test-webkit:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: microsoft/playwright-github-action@v1
- run: npm install
- run: npx aegir test -t browser -t webworker --bail --timeout 10000 -- --browser webkit
# test-electron-main:
# needs: check
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v2
# - run: npm install
# - run: npx xvfb-maybe aegir test -t electron-main --bail
# test-electron-renderer:
# needs: check
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v2
# - run: npm install
# - run: npx xvfb-maybe aegir test -t electron-renderer --bail
46 changes: 0 additions & 46 deletions .travis.yml

This file was deleted.

4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs-repo)](https://travis-ci.com/ipfs/js-ipfs-repo)
[![codecov](https://codecov.io/gh/ipfs/js-ipfs-repo/branch/master/graph/badge.svg)](https://codecov.io/gh/ipfs/js-ipfs-repo) [![Dependency Status](https://david-dm.org/ipfs/js-ipfs-repo.svg?style=flat-square)](https://david-dm.org/ipfs/js-ipfs-repo)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
![](https://img.shields.io/badge/npm-%3E%3D6.0.0-orange.svg?style=flat-square)
![](https://img.shields.io/badge/Node.js-%3E%3D10.0.0-orange.svg?style=flat-square)

> Implementation of the IPFS repo spec (https://github.com/ipfs/specs/blob/master/REPO.md) in JavaScript
Expand Down Expand Up @@ -137,8 +135,6 @@ Loading this module through a script tag will make the `IpfsRepo` obj available

```html
<script src="https://unpkg.com/ipfs-repo/dist/index.min.js"></script>
<!-- OR -->
<script src="https://unpkg.com/ipfs-repo/dist/index.js"></script>
```

## Usage
Expand Down
11 changes: 0 additions & 11 deletions example.js

This file was deleted.

49 changes: 35 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "IPFS Repo implementation",
"leadMaintainer": "Alex Potsides <[email protected]>",
"main": "src/index.js",
"types": "dist/src/index.d.ts",
"files": [
"src",
"dist"
Expand All @@ -15,16 +16,17 @@
"./src/default-options.js": "./src/default-options-browser.js"
},
"scripts": {
"prepare": "aegir build --no-bundle",
"test": "aegir test",
"test:node": "aegir test -t node",
"test:browser": "aegir test -t browser",
"test:webworker": "aegir test -t webworker",
"build": "aegir build",
"lint": "aegir lint",
"release": "aegir release --docs",
"release-minor": "aegir release --type minor --docs",
"release-major": "aegir release --type major --docs",
"coverage": "nyc -s npm run test:node && nyc report --reporter=html",
"release": "aegir release",
"release-minor": "aegir release --type minor",
"release-major": "aegir release --type major",
"coverage": "aegir test -t node --cov && nyc report --reporter=html",
"dep-check": "aegir dep-check",
"docs": "aegir docs"
},
Expand All @@ -39,43 +41,62 @@
],
"homepage": "https://github.com/ipfs/js-ipfs-repo",
"engines": {
"node": ">=10.0.0",
"npm": ">=3.0.0"
"node": ">=14.0.0",
"npm": ">=6.0.0"
},
"devDependencies": {
"aegir": "^30.0.1",
"@types/bytes": "^3.1.0",
"@types/debug": "^4.1.5",
"@types/memdown": "^3.0.0",
"@types/ncp": "^2.0.4",
"@types/proper-lockfile": "^4.1.1",
"@types/rimraf": "^3.0.0",
"aegir": "^31.0.1",
"assert": "^2.0.0",
"events": "^3.3.0",
"it-all": "^1.0.2",
"it-drain": "^1.0.1",
"it-first": "^1.0.2",
"just-range": "^2.1.0",
"memdown": "^5.1.0",
"multihashing-async": "^2.0.0",
"multihashing-async": "^2.1.0",
"ncp": "^2.0.0",
"process": "^0.11.10",
"readable-stream": "^3.6.0",
"rimraf": "^3.0.0",
"sinon": "^9.0.2"
"sinon": "^9.0.2",
"url": "^0.11.0",
"util": "^0.12.3"
},
"dependencies": {
"bignumber.js": "^9.0.0",
"bytes": "^3.1.0",
"cids": "^1.0.0",
"cids": "^1.1.6",
"datastore-core": "^3.0.0",
"datastore-fs": "^3.0.0",
"datastore-level": "^4.0.0",
"debug": "^4.1.0",
"err-code": "^2.0.0",
"err-code": "^3.0.1",
"interface-datastore": "^3.0.3",
"ipfs-repo-migrations": "^6.0.0",
"ipfs-repo-migrations": "^7.0.1",
"ipfs-utils": "^6.0.0",
"ipld-block": "^0.11.0",
"it-map": "^1.0.2",
"it-pushable": "^1.4.0",
"just-safe-get": "^2.0.0",
"just-safe-set": "^2.1.0",
"multibase": "^3.0.0",
"merge-options": "^3.0.4",
"multibase": "^4.0.1",
"p-queue": "^6.0.0",
"proper-lockfile": "^4.0.0",
"sort-keys": "^4.0.0",
"uint8arrays": "^2.0.5"
"uint8arrays": "^2.1.3"
},
"eslintConfig": {
"extends": "ipfs",
"ignorePatterns": [
"!.aegir.js"
]
},
"license": "MIT",
"contributors": [
Expand Down
3 changes: 3 additions & 0 deletions scripts/node-globals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// @ts-nocheck
export const { Buffer } = require('buffer')
export const process = require('process/browser')
14 changes: 8 additions & 6 deletions src/api-addr.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ const uint8ArrayFromString = require('uint8arrays/from-string')

const apiFile = new Key('api')

/**
*
* @param {import("interface-datastore").Datastore} store
*/
module.exports = (store) => {
return {
/**
Expand All @@ -18,19 +22,17 @@ module.exports = (store) => {
},
/**
* Set the current configuration for this repo.
* TODO: fix find the proper type or remove this API
*
* @param {Object} value - the api address to be written
* @returns {Promise<?>}
* @param {string} value - the api address to be written
*/
async set (value) { // eslint-disable-line require-await
set (value) {
return store.put(apiFile, uint8ArrayFromString(value.toString()))
},
/**
* Deletes api file
*
* @returns {Promise<void>}
*/
async delete () { // eslint-disable-line require-await
delete () {
return store.delete(apiFile)
}
}
Expand Down
20 changes: 19 additions & 1 deletion src/backends.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
'use strict'

exports.create = function createBackend (name, path, options) {
/**
* @typedef {import("interface-datastore").Datastore} Datastore
* @typedef {import("./types").Backends} Backends
* @typedef {Required<import("./types").Options>} Options
*/

/**
*
* @param {Backends} name
* @param {string} path
* @param {Options} options
* @returns {Datastore}
*/
function createBackend (name, path, options) {
const Ctor = options.storageBackends[name]
const backendOptions = Object.assign({}, options.storageBackendOptions[name] || {})
// @ts-ignore we don't have a signature for the constructor
return new Ctor(path, backendOptions)
}

module.exports = {
create: createBackend
}
Loading

0 comments on commit 1f8ba76

Please sign in to comment.