Skip to content

Commit 1f8ba76

Browse files
feat: add types (#275)
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]>
1 parent a9ea5aa commit 1f8ba76

38 files changed

+750
-327
lines changed

.aegir.js

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,32 @@
11
'use strict'
2+
const path = require('path')
23

3-
module.exports = {
4-
webpack: {
5-
node: {
6-
// this is needed until level stops using node buffers in browser code
7-
Buffer: true,
4+
/** @type {import('aegir').Options["build"]["config"]} */
5+
const esbuild = {
6+
inject: [path.join(__dirname, 'scripts/node-globals.js')],
7+
plugins: [
8+
{
9+
name: 'node built ins',
10+
setup (build) {
11+
build.onResolve({ filter: /^stream$/ }, () => {
12+
return { path: require.resolve('readable-stream') }
13+
})
14+
}
15+
}
16+
]
17+
}
818

9-
// needed by binary-parse-stream
10-
stream: true
19+
/** @type {import('aegir').PartialOptions} */
20+
module.exports = {
21+
test: {
22+
browser: {
23+
config: {
24+
buildConfig: esbuild
25+
}
1126
}
27+
},
28+
build: {
29+
bundlesizeMax: '130kB',
30+
config: esbuild
1231
}
1332
}

.github/workflows/main.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: ci
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
7+
branches:
8+
- master
9+
10+
jobs:
11+
check:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v2
15+
- run: npm install
16+
- run: npx aegir lint
17+
- run: npx aegir ts -p check
18+
# or
19+
# - uses: gozala/[email protected]
20+
- run: npx aegir build
21+
- run: npx aegir dep-check
22+
- uses: ipfs/aegir/actions/bundle-size@master
23+
with:
24+
github_token: ${{ secrets.GITHUB_TOKEN }}
25+
test-node:
26+
needs: check
27+
runs-on: ${{ matrix.os }}
28+
strategy:
29+
matrix:
30+
os: [windows-latest, ubuntu-latest, macos-latest]
31+
node: [14, 15]
32+
fail-fast: true
33+
steps:
34+
- uses: actions/checkout@v2
35+
- uses: actions/setup-node@v1
36+
with:
37+
node-version: ${{ matrix.node }}
38+
- run: npm install
39+
- run: npx aegir test -t node --bail --cov
40+
- uses: codecov/codecov-action@v1
41+
test-chrome:
42+
needs: check
43+
runs-on: ubuntu-latest
44+
steps:
45+
- uses: actions/checkout@v2
46+
- uses: microsoft/playwright-github-action@v1
47+
- run: npm install
48+
- run: npx aegir test -t browser -t webworker --bail # add --cov later when its fixed
49+
- uses: codecov/codecov-action@v1
50+
test-firefox:
51+
needs: check
52+
runs-on: ubuntu-latest
53+
steps:
54+
- uses: actions/checkout@v2
55+
- uses: microsoft/playwright-github-action@v1
56+
- run: npm install
57+
- run: npx aegir test -t browser -t webworker --bail -- --browser firefox
58+
test-webkit:
59+
needs: check
60+
runs-on: ubuntu-latest
61+
steps:
62+
- uses: actions/checkout@v2
63+
- uses: microsoft/playwright-github-action@v1
64+
- run: npm install
65+
- run: npx aegir test -t browser -t webworker --bail --timeout 10000 -- --browser webkit
66+
# test-electron-main:
67+
# needs: check
68+
# runs-on: ubuntu-latest
69+
# steps:
70+
# - uses: actions/checkout@v2
71+
# - run: npm install
72+
# - run: npx xvfb-maybe aegir test -t electron-main --bail
73+
# test-electron-renderer:
74+
# needs: check
75+
# runs-on: ubuntu-latest
76+
# steps:
77+
# - uses: actions/checkout@v2
78+
# - run: npm install
79+
# - run: npx xvfb-maybe aegir test -t electron-renderer --bail

.travis.yml

Lines changed: 0 additions & 46 deletions
This file was deleted.

README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs-repo)](https://travis-ci.com/ipfs/js-ipfs-repo)
88
[![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)
99
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
10-
![](https://img.shields.io/badge/npm-%3E%3D6.0.0-orange.svg?style=flat-square)
11-
![](https://img.shields.io/badge/Node.js-%3E%3D10.0.0-orange.svg?style=flat-square)
1210

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

138136
```html
139137
<script src="https://unpkg.com/ipfs-repo/dist/index.min.js"></script>
140-
<!-- OR -->
141-
<script src="https://unpkg.com/ipfs-repo/dist/index.js"></script>
142138
```
143139

144140
## Usage

example.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

package.json

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"description": "IPFS Repo implementation",
55
"leadMaintainer": "Alex Potsides <[email protected]>",
66
"main": "src/index.js",
7+
"types": "dist/src/index.d.ts",
78
"files": [
89
"src",
910
"dist"
@@ -15,16 +16,17 @@
1516
"./src/default-options.js": "./src/default-options-browser.js"
1617
},
1718
"scripts": {
19+
"prepare": "aegir build --no-bundle",
1820
"test": "aegir test",
1921
"test:node": "aegir test -t node",
2022
"test:browser": "aegir test -t browser",
2123
"test:webworker": "aegir test -t webworker",
2224
"build": "aegir build",
2325
"lint": "aegir lint",
24-
"release": "aegir release --docs",
25-
"release-minor": "aegir release --type minor --docs",
26-
"release-major": "aegir release --type major --docs",
27-
"coverage": "nyc -s npm run test:node && nyc report --reporter=html",
26+
"release": "aegir release",
27+
"release-minor": "aegir release --type minor",
28+
"release-major": "aegir release --type major",
29+
"coverage": "aegir test -t node --cov && nyc report --reporter=html",
2830
"dep-check": "aegir dep-check",
2931
"docs": "aegir docs"
3032
},
@@ -39,43 +41,62 @@
3941
],
4042
"homepage": "https://github.com/ipfs/js-ipfs-repo",
4143
"engines": {
42-
"node": ">=10.0.0",
43-
"npm": ">=3.0.0"
44+
"node": ">=14.0.0",
45+
"npm": ">=6.0.0"
4446
},
4547
"devDependencies": {
46-
"aegir": "^30.0.1",
48+
"@types/bytes": "^3.1.0",
49+
"@types/debug": "^4.1.5",
50+
"@types/memdown": "^3.0.0",
51+
"@types/ncp": "^2.0.4",
52+
"@types/proper-lockfile": "^4.1.1",
53+
"@types/rimraf": "^3.0.0",
54+
"aegir": "^31.0.1",
55+
"assert": "^2.0.0",
56+
"events": "^3.3.0",
4757
"it-all": "^1.0.2",
4858
"it-drain": "^1.0.1",
4959
"it-first": "^1.0.2",
5060
"just-range": "^2.1.0",
5161
"memdown": "^5.1.0",
52-
"multihashing-async": "^2.0.0",
62+
"multihashing-async": "^2.1.0",
5363
"ncp": "^2.0.0",
64+
"process": "^0.11.10",
65+
"readable-stream": "^3.6.0",
5466
"rimraf": "^3.0.0",
55-
"sinon": "^9.0.2"
67+
"sinon": "^9.0.2",
68+
"url": "^0.11.0",
69+
"util": "^0.12.3"
5670
},
5771
"dependencies": {
5872
"bignumber.js": "^9.0.0",
5973
"bytes": "^3.1.0",
60-
"cids": "^1.0.0",
74+
"cids": "^1.1.6",
6175
"datastore-core": "^3.0.0",
6276
"datastore-fs": "^3.0.0",
6377
"datastore-level": "^4.0.0",
6478
"debug": "^4.1.0",
65-
"err-code": "^2.0.0",
79+
"err-code": "^3.0.1",
6680
"interface-datastore": "^3.0.3",
67-
"ipfs-repo-migrations": "^6.0.0",
81+
"ipfs-repo-migrations": "^7.0.1",
6882
"ipfs-utils": "^6.0.0",
6983
"ipld-block": "^0.11.0",
7084
"it-map": "^1.0.2",
7185
"it-pushable": "^1.4.0",
7286
"just-safe-get": "^2.0.0",
7387
"just-safe-set": "^2.1.0",
74-
"multibase": "^3.0.0",
88+
"merge-options": "^3.0.4",
89+
"multibase": "^4.0.1",
7590
"p-queue": "^6.0.0",
7691
"proper-lockfile": "^4.0.0",
7792
"sort-keys": "^4.0.0",
78-
"uint8arrays": "^2.0.5"
93+
"uint8arrays": "^2.1.3"
94+
},
95+
"eslintConfig": {
96+
"extends": "ipfs",
97+
"ignorePatterns": [
98+
"!.aegir.js"
99+
]
79100
},
80101
"license": "MIT",
81102
"contributors": [

scripts/node-globals.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// @ts-nocheck
2+
export const { Buffer } = require('buffer')
3+
export const process = require('process/browser')

src/api-addr.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ const uint8ArrayFromString = require('uint8arrays/from-string')
55

66
const apiFile = new Key('api')
77

8+
/**
9+
*
10+
* @param {import("interface-datastore").Datastore} store
11+
*/
812
module.exports = (store) => {
913
return {
1014
/**
@@ -18,19 +22,17 @@ module.exports = (store) => {
1822
},
1923
/**
2024
* Set the current configuration for this repo.
25+
* TODO: fix find the proper type or remove this API
2126
*
22-
* @param {Object} value - the api address to be written
23-
* @returns {Promise<?>}
27+
* @param {string} value - the api address to be written
2428
*/
25-
async set (value) { // eslint-disable-line require-await
29+
set (value) {
2630
return store.put(apiFile, uint8ArrayFromString(value.toString()))
2731
},
2832
/**
2933
* Deletes api file
30-
*
31-
* @returns {Promise<void>}
3234
*/
33-
async delete () { // eslint-disable-line require-await
35+
delete () {
3436
return store.delete(apiFile)
3537
}
3638
}

src/backends.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
11
'use strict'
22

3-
exports.create = function createBackend (name, path, options) {
3+
/**
4+
* @typedef {import("interface-datastore").Datastore} Datastore
5+
* @typedef {import("./types").Backends} Backends
6+
* @typedef {Required<import("./types").Options>} Options
7+
*/
8+
9+
/**
10+
*
11+
* @param {Backends} name
12+
* @param {string} path
13+
* @param {Options} options
14+
* @returns {Datastore}
15+
*/
16+
function createBackend (name, path, options) {
417
const Ctor = options.storageBackends[name]
518
const backendOptions = Object.assign({}, options.storageBackendOptions[name] || {})
19+
// @ts-ignore we don't have a signature for the constructor
620
return new Ctor(path, backendOptions)
721
}
22+
23+
module.exports = {
24+
create: createBackend
25+
}

0 commit comments

Comments
 (0)