This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: refactor common types (#3449)
Addresses #3442 (comment) by refactoring some of the common types used by root APIs as per #3413 Co-authored-by: achingbrain <alex@achingbrain.net>
- Loading branch information
1 parent
18d6359
commit 34e1492
Showing
53 changed files
with
650 additions
and
377 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } |
8 changes: 6 additions & 2 deletions
8
packages/ipfs-core/src/interface/bitswap.ts → packages/ipfs-core-types/src/bitswap.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.