Skip to content

Commit e781f2f

Browse files
authored
feat: create docs & client ready for npm release
1 parent b59202f commit e781f2f

9 files changed

+90
-41
lines changed

.aegir.cjs

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// import { MockServer } from './test/MockServer'
2-
3-
// let mockServer = new MockServer()
41
require('ts-node').register({
52
project: 'tsconfig.json',
63
})

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
node_modules
22
typings
33
dist
4+
dist.generated
45
build
56
coverage
67
node_modules
@@ -15,3 +16,5 @@ package-lock.json
1516
.nyc_output
1617
generated/fetch/package.json
1718
generated/fetch/tsconfig.json
19+
tsconfig-types.aegir.tsbuildinfo
20+
docs

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ This client only has a programmatic API at the moment (no CLI). You use it like
1414

1515
```ts
1616

17-
import { Configuration, PinsApi, Status } from '@ipfs-shipyard/pinning-service-client'
17+
import { Configuration, RemotePinningServiceClient, Status } from '@ipfs-shipyard/pinning-service-client'
1818
import type { PinsGetRequest, PinResults } from '@ipfs-shipyard/pinning-service-client'
1919

2020
const config = new Configuration({
21-
basePath, // the URI for your pinning provider, e.g. `http://localhost:3000`
21+
endpointUrl, // the URI for your pinning provider, e.g. `http://localhost:3000`
2222
accessToken, // the secret token/key given to you by your pinning provider
2323
// fetchApi: fetch, // You can pass your own fetchApi implementation, but we use fetch-ponyfill by default.
2424
})
2525

26-
const client = new PinsApi(config)
26+
const client = new RemotePinningServiceClient(config)
2727

2828
(async () => {
2929
// Get 10 failed Pins

package.json

+17-14
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"node": ">=16.0.0",
2424
"npm": ">=7.0.0"
2525
},
26-
"main": "src/index.js",
26+
"main": "src/index.ts",
2727
"types": "dist/src/index.d.ts",
2828
"typesVersions": {
2929
"*": {
@@ -41,7 +41,8 @@
4141
},
4242
"files": [
4343
"src",
44-
"dist"
44+
"dist",
45+
"dist.generated"
4546
],
4647
"eslintConfig": {
4748
"extends": "ipfs",
@@ -131,7 +132,7 @@
131132
]
132133
},
133134
"scripts": {
134-
"clean": "npx rimraf dist generated node_modules",
135+
"clean": "npx rimraf dist generated node_modules .swc",
135136
"ci:test": "run-s test:*",
136137
"dep-check": "aegir dep-check src/**/*.ts test/**/*.ts generated/**/*.ts",
137138
"fix": "run-s fix:*",
@@ -142,10 +143,10 @@
142143
"lint-TODO:project": "check-aegir-project # currently broken due to corrupting the repoUrl",
143144
"release": "aegir release",
144145
"postinstall": "run-s gen",
145-
"build": "aegir build",
146-
"build2": "tsc-silent -p tsconfig.generated.json --suppress 6133@generated 6192@generated --stats",
146+
"build": "run-s build:* && cp-cli dist.generated dist/dist.generated",
147+
"build-todo:docs": "aegir docs -p false",
148+
"build:deps": "run-s gen",
147149
"build:main": "aegir build",
148-
"build:docs": "aegir ts docs",
149150
"build:types": "aegir ts -p types",
150151
"test": "run-s test:*",
151152
"test:browser": "aegir test --target browser",
@@ -160,39 +161,41 @@
160161
"gen:ts": "openapi-generator-cli generate --generator-key ts"
161162
},
162163
"dependencies": {
163-
"fetch-ponyfill": "^7.1.0",
164-
"yargs": "^17.3.1"
164+
"fetch-ponyfill": "^7.1.0"
165165
},
166166
"devDependencies": {
167167
"@openapitools/openapi-generator-cli": "^2.4.26",
168-
"@swc/core": "^1.2.144",
168+
"@swc/cli": "^0.1.55",
169+
"@swc/core": "^1.2.157",
169170
"@swc/helpers": "^0.3.3",
170171
"@types/cors": "^2.8.12",
171172
"@types/express": "^4.17.13",
172173
"@types/mocha": "^9.1.0",
173174
"@types/node": "^17.0.21",
174175
"@types/portscanner": "^2.1.1",
175-
"aegir": "^36.1.3",
176+
"aegir": "^36.2.2",
176177
"check-aegir-project": "^1.0.3",
177178
"cors": "^2.8.5",
179+
"cp-cli": "^2.0.0",
178180
"dotenvrc": "^1.0.1",
179181
"express": "^4.17.3",
180182
"express-promise-router": "^4.1.1",
181183
"mock-ipfs-pinning-service": "^0.4.0",
182184
"npm-run-all": "^4.1.5",
183-
"openapi-typescript": "^5.1.1",
184185
"portscanner": "^2.2.0",
185186
"regenerator-runtime": "^0.13.9",
186-
"ts-node": "^10.5.0",
187+
"ts-node": "^10.7.0",
187188
"tsc-silent": "^1.2.1",
188189
"winston": "^3.6.0"
189190
},
190191
"exports": {
191192
".": {
192-
"import": "./generated/api.ts"
193+
"import": "./dist/src/index.js",
194+
"require": "./dist/src/index.js"
193195
},
194196
"./api/apis": {
195-
"import": "./generated/api/apis.ts"
197+
"import": "./dist/dist.generated/apis",
198+
"require": "./dist/dist.generated/apis"
196199
}
197200
}
198201
}

src/index.ts

+54-8
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,58 @@
11
import fetchPonyfill from 'fetch-ponyfill'
2-
import { Configuration as GeneratedConfiguration } from '../generated/fetch/dist/src'
3-
import type { ConfigurationParameters } from '../generated/fetch/dist/src'
42

5-
export * from '../generated/fetch/dist/src/apis'
6-
export * from '../generated/fetch/dist/src/models'
3+
import { Configuration as GeneratedConfiguration } from '../dist.generated'
4+
import type { ConfigurationParameters as GeneratedConfigurationParameters } from '../dist.generated'
5+
import { PinsApi as RemotePinningServiceClient } from '../dist.generated/apis'
76

8-
export class Configuration extends GeneratedConfiguration {
7+
interface ConfigurationParameters extends Omit<GeneratedConfigurationParameters, 'basePath'>{
8+
endpointUrl?: string
9+
}
10+
class Configuration extends GeneratedConfiguration {
911
constructor (options: ConfigurationParameters) {
12+
const finalOptions: GeneratedConfigurationParameters = { ...options }
13+
1014
/**
1115
* Prevent the need for everyone to have to override the fetch API...
1216
*/
1317
if (options.fetchApi == null) {
14-
options.fetchApi = fetchPonyfill().fetch
18+
finalOptions.fetchApi = fetchPonyfill().fetch
19+
}
20+
21+
// @see https://github.com/ipfs-shipyard/js-pinning-service-http-client/issues/3
22+
if (options.endpointUrl != null) {
23+
finalOptions.basePath = options.endpointUrl
1524
}
16-
super(options)
25+
26+
super(finalOptions)
1727
}
1828
}
1929

30+
/**
31+
* Overwritten and renamed exports
32+
*/
33+
export type {
34+
PinsApiInterface as RemotePinningServiceClientInterface
35+
} from '../dist.generated/apis'
36+
37+
export {
38+
Configuration,
39+
RemotePinningServiceClient
40+
}
2041
export type { ConfigurationParameters }
42+
43+
/**
44+
* Unmodified exports
45+
*/
46+
export type {
47+
PinsGetRequest,
48+
PinsPostRequest,
49+
PinsRequestidDeleteRequest,
50+
PinsRequestidGetRequest,
51+
PinsRequestidPostRequest
52+
} from '../dist.generated/apis'
53+
54+
export * from '../dist.generated/models'
55+
2156
export {
2257
BASE_PATH,
2358
BaseAPI,
@@ -32,4 +67,15 @@ export {
3267
exists,
3368
mapValues,
3469
querystring
35-
} from '../generated/fetch/dist/src/runtime'
70+
} from '../dist.generated/runtime'
71+
72+
export type {
73+
FetchParams,
74+
RequestOpts,
75+
Consume,
76+
RequestContext,
77+
ResponseContext,
78+
Middleware,
79+
ApiResponse,
80+
ResponseTransformer
81+
} from '../dist.generated/runtime'

test/MockServerController.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class MockServerController {
2828
*/
2929
res.send({
3030
success: true,
31-
basePath: mockServer.basePath,
31+
endpointUrl: mockServer.basePath,
3232
accessToken: process.env.MOCK_PINNING_SERVER_SECRET
3333
})
3434
} catch (error) {

test/client.spec.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
/* eslint-env browser, node, mocha */
22

33
import { expect } from 'aegir/utils/chai'
4-
import { Configuration, PinsApi, Status } from '../src'
4+
import { Configuration, RemotePinningServiceClient, Status } from '../src'
55
import type { Pin } from '../src'
66
import fetchPonyfill from 'fetch-ponyfill'
77

88
const { fetch } = fetchPonyfill()
99

1010
let Config = new Configuration({
11-
basePath: 'http://127.0.0.1:3000',
11+
endpointUrl: 'http://127.0.0.1:3000',
1212
// fetchApi: fetch,
1313
accessToken: process.env.MOCK_PINNING_SERVER_SECRET
1414
})
1515
describe('Client', () => {
1616
it('Can be instantiated', () => {
17-
expect(() => new PinsApi(Config)).not.to.throw()
17+
expect(() => new RemotePinningServiceClient(Config)).not.to.throw()
1818
})
1919

2020
describe('Operations', () => {
2121
// let mockServer: MockServer
2222
// let Config: Configuration
2323
beforeEach(async () => {
2424
const response = await fetch('http://localhost:3000/start')
25-
const { basePath, accessToken } = await response.json()
25+
const { endpointUrl, accessToken } = await response.json()
2626
Config = new Configuration({
27-
basePath,
27+
endpointUrl,
2828
accessToken
2929
// fetchApi: fetch
3030
})
@@ -42,13 +42,13 @@ describe('Client', () => {
4242
})
4343

4444
it('GET: Can get failed Pins', async () => {
45-
const Client = new PinsApi(Config)
45+
const Client = new RemotePinningServiceClient(Config)
4646
const response = await Client.pinsGet({ limit: 1, status: new Set([Status.Failed]) })
4747
expect(response).to.deep.eq({ count: 0, results: new Set() })
4848
})
4949

5050
it('GET: Can add a Pin successfully', async () => {
51-
const Client = new PinsApi(Config)
51+
const Client = new RemotePinningServiceClient(Config)
5252
const pin: Pin = {
5353
cid: 'abc123',
5454
name: 'pinned-test1'
@@ -59,7 +59,7 @@ describe('Client', () => {
5959
})
6060

6161
it('POST: Can handle a failed pinning', async () => {
62-
const Client = new PinsApi(Config)
62+
const Client = new RemotePinningServiceClient(Config)
6363
const pin: Pin = {
6464
cid: 'abc123',
6565
name: 'failed-test2'

tsconfig.generated.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"compilerOptions": {
33
"sourceRoot": "generated/fetch/src",
4-
"outDir": "generated/fetch/dist",
4+
"outDir": "dist.generated",
55
"emitDeclarationOnly": false,
66
"module": "ES2020",
77
"target": "ES2020",
@@ -15,7 +15,7 @@
1515
"noUnusedLocals": false,
1616
"noUnusedParameters": false,
1717
"isolatedModules": false,
18-
"rootDir": "generated/fetch",
18+
"rootDir": "generated/fetch/src",
1919
"sourceMap": true,
2020
"moduleResolution":"Node"
2121

tsconfig.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"typeRoots": [
88
"./types",
99
"./node_modules/@types",
10-
"./generated/fetch/dist"
10+
"dist/dist.generated"
1111
],
1212
"noEmitOnError": true,
1313
"esModuleInterop": true,
@@ -20,7 +20,7 @@
2020
"test/**/*.ts",
2121
"types/**/*.d.ts",
2222
"MockServer.ts",
23-
"./generated/fetch/dist"
23+
"dist/dist.generated"
2424
],
2525
"exclude": [
2626
"generated"

0 commit comments

Comments
 (0)