Skip to content

Commit

Permalink
Merge pull request #14 from InterplanetaryDevs/dev
Browse files Browse the repository at this point in the history
Redesign & Persistent configuration
  • Loading branch information
undyingwraith authored Nov 9, 2023
2 parents 365c443 + afcb718 commit 26e404e
Show file tree
Hide file tree
Showing 90 changed files with 32,862 additions and 30,661 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ jobs:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Install yarn
run: npm install -g corepack
Expand All @@ -30,7 +29,12 @@ jobs:
run: yarn install

- name: Generate build artifact
run: CI=false yarn run build
run: CI=true yarn run build

- name: Run tests
run: yarn test
run: yarn test --ci --coverage

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
8 changes: 4 additions & 4 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -57,7 +57,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
Expand All @@ -71,4 +71,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
uses: github/codeql-action/analyze@v2
9 changes: 9 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# IPFS Toolbox

![GitHub Workflow Status (branch)](https://img.shields.io/github/workflow/status/InterplanetaryDevs/ipfs-toolbox/Build%20&%20test/master)
![GitHub Workflow Status (branch)](https://img.shields.io/github/actions/workflow/status/InterplanetaryDevs/ipfs-toolbox/build-and-test.yml?branch=master)
[![codecov](https://codecov.io/gh/InterplanetaryDevs/ipfs-toolbox/graph/badge.svg?token=47AD6TOODA)](https://codecov.io/gh/InterplanetaryDevs/ipfs-toolbox)
![GitHub](https://img.shields.io/github/license/InterplanetaryDevs/ipfs-toolbox)
![GitHub forks](https://img.shields.io/github/forks/InterplanetaryDevs/ipfs-toolbox?style=social)
![GitHub Repo stars](https://img.shields.io/github/stars/InterplanetaryDevs/ipfs-toolbox?style=social)
Expand Down
8 changes: 8 additions & 0 deletions ipfs-cluster-api/src/api/IIpfsAllocationsApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {AllocationsOptions} from '../options';
import {AllocationResult} from '../results';

export interface IIpfsAllocationsApi {
list(options: AllocationsOptions): Promise<AllocationResult>;

get(cid: string): void;
}
30 changes: 30 additions & 0 deletions ipfs-cluster-api/src/api/IIpfsClusterApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {PeerInfo, VersionResult} from '../results';
import {AddOptions} from '../options';
import {IIpfsPeersApi} from './IIpfsPeersApi';
import {IIpfsPinsApi} from './IIpfsPinsApi';
import {IIpfsAllocationsApi} from './IIpfsAllocationsApi';

export interface IIpfsClusterApi {
readonly peers: IIpfsPeersApi;
readonly pins: IIpfsPinsApi;
readonly allocations: IIpfsAllocationsApi;

/**
* Cluster peer information
* @return {Promise<PeerInfo>}
*/
id(): Promise<PeerInfo>;

/**
* Cluster version
*/
version(): Promise<VersionResult>;

/**
* Add content to the cluster.
* @param data
* @param {AddOptions} options
* @return {Promise<void>}
*/
add(data: any, options: AddOptions): Promise<void>;
}
14 changes: 14 additions & 0 deletions ipfs-cluster-api/src/api/IIpfsPeersApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {PeerListResult, RemovePeerResult} from './IpfsPeersApi';

export interface IIpfsPeersApi {
/**
* Cluster peers.
*/
list(): Promise<PeerListResult>;

/**
* Remove a peer.
* @param {string} peerId
*/
remove(peerId: string): Promise<RemovePeerResult>;
}
18 changes: 18 additions & 0 deletions ipfs-cluster-api/src/api/IIpfsPinsApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {PinOptions, PinStatusOptions} from '../options';

export interface IIpfsPinsApi {
/**
* Local status of all tracked CIDs.
*/
list(): void;

status(cid: string, options?: PinStatusOptions): any;

add(cid: string, options: PinOptions): any;

remove(cid: string): Promise<any>;

recover(cid?: string): void;

update(from: string, to: string, options: PinOptions): Promise<void>;
}
3 changes: 2 additions & 1 deletion ipfs-cluster-api/src/api/IpfsAllocationsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import {AxiosInstance} from 'axios';
import {AllocationsOptions} from '../options';
import {AllocationResult} from '../results';
import {mapOptions} from '../utils';
import {IIpfsAllocationsApi} from './IIpfsAllocationsApi';

export class IpfsAllocationsApi {
export class IpfsAllocationsApi implements IIpfsAllocationsApi {
constructor(private readonly api: AxiosInstance) {
}

Expand Down
18 changes: 9 additions & 9 deletions ipfs-cluster-api/src/api/IpfsClusterApi.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import axios, {AxiosInstance} from 'axios';
import {AddOptions} from '../options';
import {PeerInfo} from '../results';
import {VersionResult} from '../results';
import {PeerInfo, VersionResult} from '../results';
import {IpfsAllocationsApi} from './IpfsAllocationsApi';
import {IpfsPeersApi} from './IpfsPeersApi';
import {IpfsPinsApi} from './IpfsPinsApi';
import {IIpfsClusterApi} from './IIpfsClusterApi';

export class IpfsClusterApi {
export class IpfsClusterApi implements IIpfsClusterApi {
/**
* Create a new Cluster interface.
* @param {string} apiUrl API Url of the cluster
Expand All @@ -19,15 +19,15 @@ export class IpfsClusterApi {
* Cluster peer information
* @return {Promise<PeerInfo>}
*/
public id(): Promise<PeerInfo> {
id(): Promise<PeerInfo> {
return this.api.get('/id')
.then(r => r.data);
}

/**
* Cluster version
*/
public version(): Promise<VersionResult> {
version(): Promise<VersionResult> {
return this.api.get('/version')
.then(r => r.data);
}
Expand All @@ -36,15 +36,15 @@ export class IpfsClusterApi {
* Peers API
* @return {IpfsPeersApi}
*/
public get peers(): IpfsPeersApi {
get peers(): IpfsPeersApi {
return new IpfsPeersApi(this.api);
}

/**
* Pins API
* @return {IpfsPinsApi}
*/
public get pins(): IpfsPinsApi {
get pins(): IpfsPinsApi {
return new IpfsPinsApi(this.api);
}

Expand All @@ -54,11 +54,11 @@ export class IpfsClusterApi {
* @param {AddOptions} options
* @return {Promise<void>}
*/
public add(data: any, options: AddOptions): Promise<void> {
add(data: any, options: AddOptions): Promise<void> {
return Promise.reject();
}

public get allocations(): IpfsAllocationsApi {
get allocations(): IpfsAllocationsApi {
return new IpfsAllocationsApi(this.api);
}

Expand Down
7 changes: 4 additions & 3 deletions ipfs-cluster-api/src/api/IpfsPeersApi.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import {AxiosInstance} from 'axios';
import {PeerInfo} from '../results';
import {IIpfsPeersApi} from './IIpfsPeersApi';

export type PeerListResult = PeerInfo[]

export type RemovePeerResult = unknown

export class IpfsPeersApi {
export class IpfsPeersApi implements IIpfsPeersApi {
constructor(private readonly api: AxiosInstance) {
}

/**
* Cluster peers.
*/
public list(): Promise<PeerListResult> {
list(): Promise<PeerListResult> {
return this.api.get('/peers')
.then(r => r.data);
}
Expand All @@ -21,7 +22,7 @@ export class IpfsPeersApi {
* Remove a peer.
* @param {string} peerId
*/
public remove(peerId: string): Promise<RemovePeerResult> {
remove(peerId: string): Promise<RemovePeerResult> {
return this.api.delete(`/peers/${peerId}`)
.then(r => r.data);
}
Expand Down
18 changes: 9 additions & 9 deletions ipfs-cluster-api/src/api/IpfsPinsApi.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
import {AxiosInstance} from 'axios';
import {PinOptions} from '../options';
import {PinStatusOptions} from '../options';
import {PinOptions, PinStatusOptions} from '../options';
import {mapOptions} from '../utils';
import {IIpfsPinsApi} from './IIpfsPinsApi';

export class IpfsPinsApi {
export class IpfsPinsApi implements IIpfsPinsApi {
constructor(private readonly api: AxiosInstance) {
}

/**
* Local status of all tracked CIDs.
*/
public list() {
list() {

}

public status(cid: string, options?: PinStatusOptions) {
status(cid: string, options?: PinStatusOptions) {
return this.api.get(`/pins/${cid}?${mapOptions(options)}`).then(r => r.data);
}

public add(cid: string, options: PinOptions) {
add(cid: string, options: PinOptions) {
return this.api.post(`/pins/ipfs/${cid}?${mapOptions(options)}`);
}

public remove(cid: string): Promise<any> {
remove(cid: string): Promise<any> {
return this.api.delete(`/pins/${cid}`).then(r => r.data);
}

public recover(cid?: string) {
recover(cid?: string) {

}

public update(from: string, to: string, options: PinOptions) {
update(from: string, to: string, options: PinOptions) {
return this.api.post(`/pins/ipfs/${to}?mode=recursive&pin-update=${from}&${mapOptions(options)}`).then(r => {
});
}
Expand Down
4 changes: 4 additions & 0 deletions ipfs-cluster-api/src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
export type {IpfsPeersApi} from './IpfsPeersApi';
export type {IIpfsPeersApi} from './IIpfsPeersApi';
export {IpfsClusterApi} from './IpfsClusterApi';
export type {IIpfsClusterApi} from './IIpfsClusterApi';
export type {IpfsAllocationsApi} from './IpfsAllocationsApi';
export type {IIpfsAllocationsApi} from './IIpfsAllocationsApi';
export type {IpfsPinsApi} from './IpfsPinsApi';
export type {IIpfsPinsApi} from './IIpfsPinsApi';
8 changes: 8 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'jsdom',
coveragePathIgnorePatterns: [
"<rootDir>/testing/"
],
};
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@
"testing"
],
"scripts": {
"watch": "yarn workspaces foreach -A run watch",
"build": "yarn workspaces foreach -A run build",
"test": "yarn workspace tests run test"
"watch": "yarn workspaces foreach -Api run watch",
"build": "yarn workspaces foreach -At run build",
"test": "jest",
"test-coverage": "jest --ci --coverage"
},
"devDependencies": {
"jest": "^29.7.0",
"ts-jest": "^29.1.1"
}
}
4 changes: 0 additions & 4 deletions testing/context/MockIpfsClusterContext.tsx

This file was deleted.

10 changes: 0 additions & 10 deletions testing/context/MockIpfsContext.tsx

This file was deleted.

Loading

0 comments on commit 26e404e

Please sign in to comment.