Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

chore: refactor common types #3449

Merged
merged 22 commits into from
Dec 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
02402c7
trigger ci
Gozala Dec 11, 2020
0da1850
chore: change cid dep to use git pull
Gozala Dec 11, 2020
58134d5
Revert "chore: change cid dep to use git pull"
Gozala Dec 11, 2020
01a75cd
fix: regression introduced by new cid & multicodec
Gozala Dec 11, 2020
83dcdac
Merge remote-tracking branch 'upstream/master' into chore/verify-cid-fix
Gozala Dec 15, 2020
446da30
Revert "chore: fixed cid and multicodec versions (#3445)"
Gozala Dec 15, 2020
2d3268f
chore: fix remaning type missmatches
Gozala Dec 15, 2020
a51a6e5
fix: regressions in examples
Gozala Dec 15, 2020
58d5d0c
chore: revert bundle size
Gozala Dec 15, 2020
f032cbd
chore: fix failing test
achingbrain Dec 15, 2020
8b185ae
chore: update require
achingbrain Dec 15, 2020
f5a37a6
chore: update deps
achingbrain Dec 15, 2020
b568e26
chore: use daemon class instead of cli which does not have it any more
achingbrain Dec 15, 2020
acb7378
Merge remote-tracking branch 'origin/master' into chore/verify-cid-fix
achingbrain Dec 15, 2020
a699b9d
chore: align versions and remove ts-ignore
achingbrain Dec 15, 2020
c2ec920
chore: factor out types into ipfs-interface
Gozala Dec 16, 2020
7dd1e72
chore: revert ts-expect-error
Gozala Dec 16, 2020
0cd45dc
chore: consolidate all the types in one place
Gozala Dec 16, 2020
371529e
chore: merge master
Gozala Dec 16, 2020
777f18e
chore: rename ipfs-interface to ipfs-core-types
Gozala Dec 16, 2020
ec4b5c8
chore: disable dep-check
Gozala Dec 17, 2020
f370ddd
chore: ignore ipfs-core-types in dep checks
Gozala Dec 17, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/types-use-ipfs-from-ts/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default async function main() {

console.log('Added file:', file.path, file.cid.toString())
try {
// @ts-expect-error CID has no toUpperCase method
file.cid.toUpperCase()
} catch (error) {

Expand Down
1 change: 1 addition & 0 deletions examples/types-use-ipfs-from-typed-js/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ async function main () {

console.log('Added file:', file.path, file.cid.toString())
try {
// @ts-expect-error CID has no toUpperCase method
file.cid.toUpperCase()
} catch(error) {

Expand Down
5 changes: 5 additions & 0 deletions packages/ipfs-core-types/COPYRIGHT
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
This project is transitioning from an MIT-only license to a dual MIT/Apache-2.0 license.
Unless otherwise noted, all code contributed prior to 2019-11-21 and not contributed by
a user listed in [this signoff issue](https://github.com/ipfs/js-ipfs/issues/2624) is
licensed under MIT-only. All new contributions (and past contributions since 2019-11-21)
are licensed under a dual MIT/Apache-2.0 license.
5 changes: 5 additions & 0 deletions packages/ipfs-core-types/LICENSE-APACHE
Original file line number Diff line number Diff line change
@@ -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.
19 changes: 19 additions & 0 deletions packages/ipfs-core-types/LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -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.
82 changes: 82 additions & 0 deletions packages/ipfs-core-types/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# ipfs-core-types <!-- omit in toc -->

[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io)
[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)
[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)
[![standard-readme compliant](https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)
[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?style=flat-square&path=packages/interface-ipfs-core)](https://david-dm.org/ipfs/js-ipfs?path=packages/interface-ipfs-core)

> IPFS interface definitions used by implementations for API compatibility.

## Lead Maintainer <!-- omit in toc -->

[Alex Potsides](http://github.com/achingbrain)

## Table of Contents <!-- omit in toc -->

- [Background](#background)
- [Install](#install)
- [Usage](#usage)
- [Validation](#validation)
- [Contribute](#contribute)
- [Want to hack on IPFS?](#want-to-hack-on-ipfs)
- [License](#license)

## Background

The primary goal of this module is to define and ensure that IPFS core implementations and their respective HTTP client libraries implement the same interface, so that developers can quickly change between a local and a remote node without having to change their applications.

It offers set of typescript interface definitions that implementations can claim compatibility with and use typescript to validate those claims.

## Install

In JavaScript land:

```console
$ npm install ipfs-core-types
```

## Usage

Install `ipfs-core-types` as one of the dependencies of your project and use it to ensure your implementations API compatibility:

### In [JSDoc syntax](https://www.typescriptlang.org/docs/handbook/type-checking-javascript-files.html)

```js
/**
* @implements {import('ipfs-core-types').RootAPI}
*/
class Root {
// your implementation goes here
}
```

### In Typescript

```ts
import { RootAPI } from 'ipfs-core-types'
class Root implements RootAPI {
// your implementation goes here
}
```

## Validation

In order to validate API compatibility you can run [typescript](https://www.typescriptlang.org/) over your implementation which will point out all the API compatibilities if there are some.


## Contribute

Feel free to join in. All welcome. Open an [issue](https://github.com/ipfs/js-ipfs/issues)!

This repository falls under the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).

### Want to hack on IPFS?

[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)

## License

[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)

[![](https://github.com/ipfs/js-ipfs/raw/master/ipfs-core-types/img/badge.png)](https://github.com/ipfs/js-ipfs/tree/master/ipfs-core-types)
43 changes: 43 additions & 0 deletions packages/ipfs-core-types/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "ipfs-core-types",
"version": "0.1.0",
"description": "IPFS interface definitions used by implementations for API compatibility.",
"leadMaintainer": "Alex Potsides <alex@achingbrain.net>",
"types": "src/index.ts",
"homepage": "https://github.com/ipfs/js-ipfs/tree/master/packages/interface-ipfs-core#readme",
"bugs": "https://github.com/ipfs/js-ipfs/issues",
"scripts": {
"lint": "aegir lint",
"test": "aegir ts -p check"
},
"types": "src/index.ts",
"files": [
"src"
],
"eslintConfig": {
"extends": "ipfs"
},
"repository": {
"type": "git",
"url": "git+https://github.com/ipfs/js-ipfs.git"
},
"keywords": [
"IPFS",
"types",
"interface",
"API"
],
"license": "(Apache-2.0 OR MIT)",
"dependencies": {
"cids": "^1.0.0",
"multiaddr": "^8.0.0",
"peer-id": "^0.14.1"
},
"devDependencies": {
"aegir": "^29.2.2",
"typescript": "4.0.x"
},
"contributors": [
"Irakli Gozalishvili <dev@gozala.io>"
]
}
39 changes: 39 additions & 0 deletions packages/ipfs-core-types/src/basic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Represents a value that you can await on, which is either value or a promise
* of one.
*/
export type Await<T> =
| T
| Promise<T>

/**
* Represents an iterable that can be used in `for await` loops, that is either
* iterable or an async iterable.
*/
export type AwaitIterable<T> =
| Iterable<T>
| AsyncIterable<T>

/**
* Common options across all cancellable requests.
*/
export interface AbortOptions {
/**
* Can be provided to a function that starts a long running task, which will
* be aborted when signal is triggered.
*/
signal?: AbortSignal
/**
* Can be provided to a function that starts a long running task, which will
* be aborted after provided timeout (in ms).
*/
timeout?: number
}

export type ToJSON =
| null
| string
| number
| boolean
| ToJSON[]
| { toJSON?: () => ToJSON } & { [key: string]: ToJSON }
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { PeerId, CID, Block, Await, BigInteger, AbortOptions } from './basic'
import { MovingAverage } from './moving-avarage'
import BigInteger from 'bignumber.js'
import PeerId from 'peer-id'
import CID from 'cids'
import { Block } from './block-service'
import { AbortOptions, Await } from './basic'
import { MovingAverage } from './bitswap/moving-avarage'
import { StoreReader, StoreExporter, StoreImporter } from './store'

export interface Bitswap extends
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Block, CID, Await, AbortOptions } from './basic'
import CID from 'cids'
import { Await, AbortOptions } from './basic'
import { StoreReader, StoreImporter, StoreExporter, StoreEraser } from './store'
import { Bitswap } from './bitswap'

Expand All @@ -18,3 +19,8 @@ export interface BlockService extends
*/
put(block: Block, options?:AbortOptions): Await<Block>
}

export interface Block {
cid: CID
data: Uint8Array
}
Loading