Skip to content

feat: create js-pinning-service-http-client #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
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
33 changes: 33 additions & 0 deletions .aegir.cjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,43 @@
// import { MockServer } from './test/MockServer'

// let mockServer = new MockServer()
require('ts-node').register({
project: 'tsconfig.json',
})

const { MockServerController } = require('./test/MockServerController')


/** @type {import('aegir').PartialOptions} */
module.exports = {
docs: {
publish: true,
entryPoint: './'
},
tsRepo: true,
build: {
config: {
platform: 'node'
},
bundlesizeMax: '44KB'
},
test: {
cov: false,
async before () {
return {
env: {
MOCK_PINNING_SERVER_SECRET: 'ci',
},
controller: new MockServerController(),
}
},
/**
*
* @param {GlobalOptions & TestOptions} _
* @param {MockServerController} controller
*/
async after (_, {controller}) {
await controller.shutdown()
}
}
}
2 changes: 1 addition & 1 deletion .envrc → .envrc-copy
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use asdf

export PATH=$(npm bin):${PATH}
export MOCK_PINNING_SERVER_PORT=3000
export MOCK_PINNING_SERVER_SECRET=secret
export DEBUG=0
53 changes: 41 additions & 12 deletions .github/workflows/js-test-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,32 @@ jobs:
- uses: actions/setup-node@v2
with:
node-version: lts/*
- uses: ipfs/aegir/actions/cache-node-modules@master
- run: npm run --if-present lint
- run: npm run --if-present dep-check
- name: Install dependencies
run: npm install
- name: Generate client files
run: npm run gen
- name: lint
run: npm run --if-present lint
- name: dependency check
run: npm run --if-present dep-check

test-node:
needs: check
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
node: [16]
node: ['lts/*']
fail-fast: true
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}
- uses: ipfs/aegir/actions/cache-node-modules@master
- name: Install dependencies
run: npm install
- name: Generate client files
run: npm run gen
- run: npm run --if-present test:node
- uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0
with:
Expand All @@ -48,7 +56,10 @@ jobs:
- uses: actions/setup-node@v2
with:
node-version: lts/*
- uses: ipfs/aegir/actions/cache-node-modules@master
- name: Install dependencies
run: npm install
- name: Generate client files
run: npm run gen
- run: npm run --if-present test:chrome
- uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0
with:
Expand All @@ -63,7 +74,10 @@ jobs:
- uses: actions/setup-node@v2
with:
node-version: lts/*
- uses: ipfs/aegir/actions/cache-node-modules@master
- name: Install dependencies
run: npm install
- name: Generate client files
run: npm run gen
- run: npm run --if-present test:chrome-webworker
- uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0
with:
Expand All @@ -78,7 +92,10 @@ jobs:
- uses: actions/setup-node@v2
with:
node-version: lts/*
- uses: ipfs/aegir/actions/cache-node-modules@master
- name: Install dependencies
run: npm install
- name: Generate client files
run: npm run gen
- run: npm run --if-present test:firefox
- uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0
with:
Expand All @@ -93,7 +110,10 @@ jobs:
- uses: actions/setup-node@v2
with:
node-version: lts/*
- uses: ipfs/aegir/actions/cache-node-modules@master
- name: Install dependencies
run: npm install
- name: Generate client files
run: npm run gen
- run: npm run --if-present test:firefox-webworker
- uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0
with:
Expand All @@ -108,7 +128,10 @@ jobs:
- uses: actions/setup-node@v2
with:
node-version: lts/*
- uses: ipfs/aegir/actions/cache-node-modules@master
- name: Install dependencies
run: npm install
- name: Generate client files
run: npm run gen
- run: npx xvfb-maybe npm run --if-present test:electron-main
- uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0
with:
Expand All @@ -123,7 +146,10 @@ jobs:
- uses: actions/setup-node@v2
with:
node-version: lts/*
- uses: ipfs/aegir/actions/cache-node-modules@master
- name: Install dependencies
run: npm install
- name: Generate client files
run: npm run gen
- run: npx xvfb-maybe npm run --if-present test:electron-renderer
- uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0
with:
Expand All @@ -141,7 +167,10 @@ jobs:
- uses: actions/setup-node@v2
with:
node-version: lts/*
- uses: ipfs/aegir/actions/cache-node-modules@master
- name: Install dependencies
run: npm install
- name: Generate client files
run: npm run gen
- uses: ipfs/aegir/actions/docker-login@master
with:
docker-token: ${{ secrets.DOCKER_TOKEN }}
Expand Down
60 changes: 0 additions & 60 deletions .github/workflows/test-and-release.yml

This file was deleted.

9 changes: 8 additions & 1 deletion .github/workflows/typecheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,16 @@ jobs:
uses: actions/[email protected]
with:
node-version: ${{ matrix.node-version }}
- name: Use Java for openapi generator
uses: actions/setup-java@v2 # https://github.com/actions/setup-java#basic
with:
distribution: 'temurin'
java-version: '17'
- name: Install dependencies
run: npm install
- name: Generate client from openapi spec
run: npm run gen
- name: Typecheck
uses: gozala/[email protected]
with:
project: test/tsconfig.json
project: tsconfig.json
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ yarn.lock
test/ts-use/tsconfig.tsbuildinfo
test/tsconfig.tsbuildinfo
package-lock.json
*.bak
.swc
.envrc
.nyc_output
generated/fetch/package.json
generated/fetch/tsconfig.json
4 changes: 4 additions & 0 deletions .mocharc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
require: ['./fixtures.js'],
extensions: ['ts', 'tsx'],
}
30 changes: 30 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
## @ipfs-shipyard/[email protected]

This generator creates TypeScript/JavaScript client that utilizes fetch-api.

### Building

To build and compile the typescript sources to javascript use:
```
npm install
npm run build
```

### Publishing

First build the package then run ```npm publish```

### Consuming

navigate to the folder of your consuming project and run one of the following commands.

_published:_

```
npm install @ipfs-shipyard/[email protected] --save
```

_unPublished (not recommended):_

```
npm install PATH_TO_GENERATED_PACKAGE --save
40 changes: 23 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
## @ipfs-shipyard/[email protected]

This generator creates TypeScript/JavaScript client that utilizes fetch-api.
This client was generated using [openapi-generator](https://github.com/OpenAPITools/openapi-generator) from the [ipfs pinning services API spec](https://raw.githubusercontent.com/ipfs/pinning-services-api-spec/main/ipfs-pinning-service.yaml).

### Building
You can see the commands used to generate the client in the `gen:fetch` npm script.

To build and compile the typescript sources to javascript use:
```
npm install
npm run build
```
### Usage

### Publishing
This client only has a programmatic API at the moment (no CLI). You use it like so:

First build the package then run ```npm publish```
```ts

### Consuming
import { Configuration, PinsApi, Status } from '@ipfs-shipyard/pinning-service-client'
import type { PinsGetRequest, PinResults } from '@ipfs-shipyard/pinning-service-client'

navigate to the folder of your consuming project and run one of the following commands.
const config = new Configuration({
basePath, // the URI for your pinning provider, e.g. `http://localhost:3000`
accessToken, // the secret token/key given to you by your pinning provider
// fetchApi: fetch, // You can pass your own fetchApi implementation, but we use fetch-ponyfill by default.
})

_published:_
const client = new PinsApi(config)

```
npm install @ipfs-shipyard/[email protected] --save
```
(async () => {
// Get 10 failed Pins
const pinsGetOptions: PinsGetRequest = {
limit: 10,
status: new Set([Status.Failed]) // requires a set, and not an array
}
const {count, results}: PinResults = await client.pinsGet(pinsGetOptions)

console.log(count, results)

_unPublished (not recommended):_
})()

```
npm install PATH_TO_GENERATED_PACKAGE --save
9 changes: 9 additions & 0 deletions fixtures.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

// @ts-check
// export async function mochaGlobalSetup () {

// }

// export async function mochaGlobalTeardown () {

// }
4 changes: 4 additions & 0 deletions generated/fetch/.gitignore

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

1 change: 1 addition & 0 deletions generated/fetch/.npmignore

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

23 changes: 23 additions & 0 deletions generated/fetch/.openapi-generator-ignore

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

Loading