Skip to content
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

feat!: remove js-ipfs support #823

Merged
merged 9 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ updates:
schedule:
interval: daily
time: "10:00"
open-pull-requests-limit: 10
open-pull-requests-limit: 20
commit-message:
prefix: "deps"
prefix-development: "deps(dev)"
3 changes: 1 addition & 2 deletions .github/workflows/js-test-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ concurrency:

jobs:
js-test-and-release:
uses: ipdxco/unified-github-workflows/.github/workflows/js-test-and-release.yml@v1.0
uses: ipdxco/unified-github-workflows/.github/workflows/js-test-and-release.yml@v0.0
secrets:
DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
UCI_GITHUB_TOKEN: ${{ secrets.UCI_GITHUB_TOKEN }}
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
12 changes: 12 additions & 0 deletions .github/workflows/semantic-pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Semantic PR

on:
pull_request_target:
types:
- opened
- edited
- synchronize

jobs:
main:
uses: pl-strflt/.github/.github/workflows/[email protected]
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
node_modules
build
dist
.docs
.coverage
node_modules
achingbrain marked this conversation as resolved.
Show resolved Hide resolved
package-lock.json
yarn.lock
.vscode
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"typescript.tsdk": "node_modules/typescript/lib"
}
20 changes: 12 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
"bugs": {
"url": "https://github.com/ipfs/js-ipfsd-ctl/issues"
},
"publishConfig": {
"access": "public",
"provenance": true
},
"keywords": [
"daemon",
"ipfs",
"node"
],
"engines": {
"node": ">=16.0.0",
"npm": ">=7.0.0"
},
"type": "module",
"types": "./dist/src/index.d.ts",
"files": [
Expand All @@ -37,6 +37,7 @@
"eslintConfig": {
"extends": "ipfs",
"parserOptions": {
"project": true,
"sourceType": "module"
}
},
Expand Down Expand Up @@ -144,6 +145,7 @@
"@libp2p/logger": "^2.0.0",
"@multiformats/multiaddr": "^11.0.0",
"execa": "^6.1.0",
"ipfs-core-types": "^0.14.0",
"ipfs-utils": "^9.0.1",
"joi": "^17.2.1",
"merge-options": "^3.0.1",
Expand All @@ -153,21 +155,23 @@
"wherearewe": "^2.0.1"
},
"devDependencies": {
"aegir": "^37.0.15",
"aegir": "^42.2.5",
"go-ipfs": "^0.17.0",
"ipfs": "^0.66.0",
"ipfs-client": "^0.10.0",
"ipfs-core-types": "^0.14.0",
"ipfs-http-client": "^60.0.0",
"kubo-rpc-client": "^3.0.0",
"util": "^0.12.4"
"kubo-rpc-client": "^3.0.0"
},
"browser": {
"./dist/src/endpoint/server.js": "./dist/src/endpoint/server.browser.js",
"./dist/src/utils.js": "./dist/src/utils.browser.js",
"./dist/src/ipfsd-daemon.js": "./dist/src/ipfsd-client.js",
"go-ipfs": false
},
"engines": {
"node": ">=16.0.0",
"npm": ">=7.0.0"
},
"jsdelivr": "dist/index.min.js",
"unpkg": "dist/index.min.js"
}
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export interface ConfigInit {
type?: ControllerType
}

export default (init: ConfigInit) => {
export default (init: ConfigInit): any => {
const { type } = init
let swarm: string[]

Expand Down
12 changes: 6 additions & 6 deletions src/endpoint/routes.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { nanoid } from 'nanoid'
import Joi from 'joi'
import boom from '@hapi/boom'
import { logger } from '@libp2p/logger'
import Joi from 'joi'
import { nanoid } from 'nanoid'
import { tmpDir } from '../utils.js'
import type { Server } from '@hapi/hapi'
import type { Factory } from '../index.js'
import type { Server } from '@hapi/hapi'

const debug = logger('ipfsd-ctl:routes')

Expand All @@ -16,7 +16,7 @@ const routeOptions = {
}
}

const badRequest = (err: Error & { stdout?: string }) => {
const badRequest = (err: Error & { stdout?: string }): void => {
let msg
if (err.stdout != null) {
msg = err.stdout + ' - ' + err.message
Expand All @@ -36,7 +36,7 @@ export default (server: Server, createFactory: () => Factory | Promise<Factory>)
handler: async (request) => {
const type = request.query.type ?? 'go'
try {
return { tmpDir: await tmpDir(type) }
return { tmpDir: tmpDir(type) }
} catch (err: any) {
badRequest(err)
}
Expand Down Expand Up @@ -69,7 +69,7 @@ export default (server: Server, createFactory: () => Factory | Promise<Factory>)
// @ts-expect-error opts is a json object
nodes[id] = await ipfsd.spawn(opts)
return {
id: id,
id,
apiAddr: nodes[id].apiAddr?.toString(),
gatewayAddr: nodes[id].gatewayAddr?.toString(),
grpcAddr: nodes[id].grpcAddr?.toString(),
Expand Down
8 changes: 2 additions & 6 deletions src/endpoint/server.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,17 @@ class Server {

/**
* Start the server
*
* @returns {Promise<Server>}
*/
async start () {
async start (): Promise<Server> {
console.warn('Server not implemented in the browser')

return this
}

/**
* Stop the server
*
* @returns {Promise<void>}
*/
async stop () {
async stop (): Promise<void> {
console.warn('Server not implemented in the browser')
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/endpoint/server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Hapi from '@hapi/hapi'
import type { CreateFactory } from '../index.js'
import routes from './routes.js'
import type { CreateFactory } from '../index.js'

export interface ServerInit {
port?: number
Expand Down Expand Up @@ -31,7 +31,7 @@ class Server {
async start (port = this.port): Promise<Server> {
this.port = port
this.server = new Hapi.Server({
port: port,
port,
host: this.host,
routes: {
cors: true
Expand Down
14 changes: 7 additions & 7 deletions src/factory.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import http from 'ipfs-utils/src/http.js'
import mergeOptions from 'merge-options'
import { tmpDir } from './utils.js'
import { isNode, isElectronMain } from 'wherearewe'
import http from 'ipfs-utils/src/http.js'
import ControllerDaemon from './ipfsd-daemon.js'
import testsConfig from './config.js'
import ControllerRemote from './ipfsd-client.js'
import ControllerDaemon from './ipfsd-daemon.js'
import ControllerProc from './ipfsd-in-proc.js'
import testsConfig from './config.js'
import { tmpDir } from './utils.js'
import type { Controller, ControllerOptions, ControllerOptionsOverrides, Factory } from './index.js'

const merge = mergeOptions.bind({ ignoreUndefined: true })
Expand Down Expand Up @@ -71,10 +71,10 @@ class DefaultFactory implements Factory {
return out.tmpDir
}

return await Promise.resolve(tmpDir(opts.type))
return Promise.resolve(tmpDir(opts.type))
}

async _spawnRemote (options: ControllerOptionsWithEndpoint) {
async _spawnRemote (options: ControllerOptionsWithEndpoint): Promise<ControllerRemote> {
const opts = {
json: {
...options,
Expand Down Expand Up @@ -153,7 +153,7 @@ class DefaultFactory implements Factory {
* Stop all controllers
*/
async clean (): Promise<void> {
await Promise.all(this.controllers.map(async n => await n.stop()))
await Promise.all(this.controllers.map(async n => n.stop()))
this.controllers = []
}
}
Expand Down
28 changes: 14 additions & 14 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import DefaultFactory from './factory.js'
import Server from './endpoint/server.js'
import type { IPFS } from 'ipfs-core-types'
import type { Multiaddr } from '@multiformats/multiaddr'
import DefaultFactory from './factory.js'
import type { PeerId } from '@libp2p/interface-peer-id'
import type { Multiaddr } from '@multiformats/multiaddr'
import type { ExecaChildProcess } from 'execa'
import type { IPFS } from 'ipfs-core-types'

export interface PeerData {
id: PeerId
Expand All @@ -16,34 +16,34 @@ export interface Controller<Type extends ControllerType = 'go'> {
/**
* Initialize a repo
*/
init: (options?: InitOptions) => Promise<Controller<Type>>
init(options?: InitOptions): Promise<Controller<Type>>

/**
* Start the daemon
*/
start: () => Promise<Controller<Type>>
start(): Promise<Controller<Type>>

/**
* Stop the daemon
*/
stop: () => Promise<Controller<Type>>
stop(): Promise<Controller<Type>>

/**
* Delete the repo that was being used.
* If the node was marked as `disposable` this will be called
* automatically when the process is exited.
*/
cleanup: () => Promise<Controller<Type>>
cleanup(): Promise<Controller<Type>>

/**
* Get the pid of the `ipfs daemon` process
*/
pid: () => Promise<number>
pid(): Promise<number>

/**
* Get the version of ipfs
*/
version: () => Promise<string>
version(): Promise<string>
path: string
started: boolean
initialized: boolean
Expand Down Expand Up @@ -226,9 +226,9 @@ export interface ControllerOptionsOverrides {
}

export interface Factory<Type extends ControllerType = ControllerType> {
tmpDir: (options?: ControllerOptions) => Promise<string>
spawn: (options?: ControllerOptions) => Promise<Controller<Type>>
clean: () => Promise<void>
tmpDir(options?: ControllerOptions): Promise<string>
spawn(options?: ControllerOptions): Promise<Controller<Type>>
clean(): Promise<void>
controllers: Array<Controller<Type>>
opts: ControllerOptions<Type>
}
Expand All @@ -251,7 +251,7 @@ export const createFactory = (options?: ControllerOptions, overrides?: Controlle
*/
export const createController = async (options?: ControllerOptions): Promise<Controller> => {
const f = new DefaultFactory()
return await f.spawn(options)
return f.spawn(options)
}

export interface IPFSAPI extends IPFS {
Expand All @@ -270,7 +270,7 @@ export interface IPFSAPI extends IPFS {
* @param {ControllerOptions} [factoryOptions]
* @param {ControllerOptionsOverrides} [factoryOverrides]
*/
export const createServer = (options?: number | { port: number }, factoryOptions: ControllerOptions = {}, factoryOverrides: ControllerOptionsOverrides = {}) => {
export const createServer = (options?: number | { port: number }, factoryOptions: ControllerOptions = {}, factoryOverrides: ControllerOptionsOverrides = {}): Server => {
let port: number | undefined

if (typeof options === 'number') {
Expand Down
6 changes: 3 additions & 3 deletions src/ipfsd-client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Multiaddr, multiaddr } from '@multiformats/multiaddr'
import { logger } from '@libp2p/logger'
import { type Multiaddr, multiaddr } from '@multiformats/multiaddr'
import http from 'ipfs-utils/src/http.js'
import mergeOptions from 'merge-options'
import { logger } from '@libp2p/logger'
import type { Controller, ControllerOptions, InitOptions, IPFSAPI, PeerData, RemoteState } from './index.js'

const merge = mergeOptions.bind({ ignoreUndefined: true })
Expand Down Expand Up @@ -52,7 +52,7 @@ class Client implements Controller {
this._peerId = null
}

get peer () {
get peer (): PeerData {
if (this._peerId == null) {
throw new Error('Not started')
}
Expand Down
Loading
Loading