diff --git a/src/config.ts b/src/config.ts index 8ef64e24..d05037f8 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,7 +1,7 @@ -import type { ControllerType } from './index.js' +import type { NodeType } from './index.js' export interface ConfigInit { - type?: ControllerType + type?: NodeType } export default (init: ConfigInit): any => { diff --git a/src/endpoint/routes.ts b/src/endpoint/routes.ts index 92213ed4..38d80e1f 100644 --- a/src/endpoint/routes.ts +++ b/src/endpoint/routes.ts @@ -2,7 +2,7 @@ import boom from '@hapi/boom' import { logger } from '@libp2p/logger' import Joi from 'joi' import { nanoid } from 'nanoid' -import type { Controller, Factory } from '../index.js' +import type { Node, Factory } from '../index.js' import type { Server } from '@hapi/hapi' const debug = logger('ipfsd-ctl:routes') @@ -26,7 +26,7 @@ const badRequest = (err: Error & { stdout?: string }): void => { throw boom.badRequest(msg) } -const nodes: Record = {} +const nodes: Record = {} export default (server: Server, createFactory: () => Factory | Promise): void => { /** diff --git a/src/factory.ts b/src/factory.ts index bf5a548a..8800342b 100644 --- a/src/factory.ts +++ b/src/factory.ts @@ -2,7 +2,7 @@ import mergeOptions from 'merge-options' import { isNode, isElectronMain } from 'wherearewe' import KuboClient from './kubo/client.js' import KuboDaemon from './kubo/daemon.js' -import type { Controller, ControllerOptions, ControllerOptionsOverrides, ControllerType, Factory, KuboController, KuboOptions, SpawnOptions } from './index.js' +import type { Node, NodeOptions, NodeOptionsOverrides, NodeType, Factory, KuboNode, KuboOptions, SpawnOptions } from './index.js' const merge = mergeOptions.bind({ ignoreUndefined: true }) @@ -17,9 +17,9 @@ const defaults = { forceKillTimeout: 5000 } -export interface FactoryInit extends ControllerOptions { +export interface FactoryInit extends NodeOptions { /** - * Endpoint URL to manage remote Controllers. (Defaults: 'http://127.0.0.1:43134') + * Endpoint URL to manage remote Nodes. (Defaults: 'http://127.0.0.1:43134') */ endpoint?: string } @@ -28,13 +28,13 @@ export interface FactoryInit extends ControllerOptions { * Factory class to spawn ipfsd controllers */ class DefaultFactory implements Factory { - public options: ControllerOptions - public controllers: Controller[] - public readonly overrides: ControllerOptionsOverrides + public options: NodeOptions + public controllers: Node[] + public readonly overrides: NodeOptionsOverrides private readonly endpoint: string - constructor (options: FactoryInit = {}, overrides: ControllerOptionsOverrides = {}) { + constructor (options: FactoryInit = {}, overrides: NodeOptionsOverrides = {}) { this.endpoint = options.endpoint ?? process.env.IPFSD_CTL_SERVER ?? 'http://localhost:43134' this.options = merge(defaults, options) this.overrides = merge({ @@ -45,11 +45,11 @@ class DefaultFactory implements Factory { } /** - * Spawn an IPFSd Controller + * Spawn an IPFSd Node */ - async spawn (options?: KuboOptions & SpawnOptions): Promise - async spawn (options?: ControllerOptions & SpawnOptions): Promise { - const type: ControllerType = options?.type ?? this.options.type ?? 'kubo' + async spawn (options?: KuboOptions & SpawnOptions): Promise + async spawn (options?: NodeOptions & SpawnOptions): Promise { + const type: NodeType = options?.type ?? this.options.type ?? 'kubo' const opts = merge({}, this.options, this.overrides[type], options) let ctl: any diff --git a/src/index.ts b/src/index.ts index d016814e..770dab11 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,11 +1,11 @@ import Server from './endpoint/server.js' import DefaultFactory from './factory.js' -import type { KuboController, KuboOptions } from './kubo/index.js' +import type { KuboNode, KuboOptions } from './kubo/index.js' export * from './kubo/index.js' -export type ControllerType = 'kubo' +export type NodeType = 'kubo' -export interface Controller = Record, InitArgs = unknown, StartArgs = unknown, StopArgs = unknown, CleanupArgs = unknown> { +export interface Node = Record, InitArgs = unknown, StartArgs = unknown, StopArgs = unknown, CleanupArgs = unknown> { api: API options: Options @@ -66,11 +66,11 @@ export interface CircuitRelayOptions { hop: CircuitRelayHopOptions } -export interface ControllerOptions { +export interface NodeOptions { /** * The type of controller */ - type?: ControllerType + type?: NodeType /** * Flag to activate custom config for tests @@ -112,7 +112,7 @@ export interface ControllerOptions { +export interface Factory { /** * Create a node */ - spawn(options?: KuboOptions & SpawnOptions): Promise - spawn(options?: ControllerOptions & SpawnOptions): Promise + spawn(options?: KuboOptions & SpawnOptions): Promise + spawn(options?: NodeOptions & SpawnOptions): Promise /** * Shut down all previously created nodes that are still running @@ -138,33 +138,33 @@ export interface Factory { /** * The previously created nodes that are still running */ - controllers: Controller[] + controllers: Node[] /** * The default options that will be applied to all nodes */ - options: ControllerOptions + options: NodeOptions /** * Config overrides that will be applied to specific node types */ - overrides: ControllerOptionsOverrides + overrides: NodeOptionsOverrides } /** * Creates a factory */ -export function createFactory (options: KuboOptions, overrides?: ControllerOptionsOverrides): Factory -export function createFactory (options?: ControllerOptions, overrides?: ControllerOptionsOverrides): Factory -export function createFactory (options?: ControllerOptions, overrides?: ControllerOptionsOverrides): Factory { +export function createFactory (options: KuboOptions, overrides?: NodeOptionsOverrides): Factory +export function createFactory (options?: NodeOptions, overrides?: NodeOptionsOverrides): Factory +export function createFactory (options?: NodeOptions, overrides?: NodeOptionsOverrides): Factory { return new DefaultFactory(options, overrides) } /** * Creates a node */ -export async function createController (options: KuboOptions & SpawnOptions): Promise -export async function createController (options?: any): Promise { +export async function createNode (options: KuboOptions & SpawnOptions): Promise +export async function createNode (options?: any): Promise { const f = new DefaultFactory() return f.spawn(options) } @@ -172,7 +172,7 @@ export async function createController (options?: any): Promise { /** * Create a Endpoint Server */ -export const createServer = (options?: number | { port: number }, factoryOptions: ControllerOptions = {}, factoryOverrides: ControllerOptionsOverrides = {}): Server => { +export const createServer = (options?: number | { port: number }, factoryOptions: NodeOptions = {}, factoryOverrides: NodeOptionsOverrides = {}): Server => { let port: number | undefined if (typeof options === 'number') { diff --git a/src/kubo/client.ts b/src/kubo/client.ts index f111390f..548d6586 100644 --- a/src/kubo/client.ts +++ b/src/kubo/client.ts @@ -1,4 +1,4 @@ -import type { KuboController, KuboInfo, KuboInitOptions, KuboOptions, KuboStartOptions } from './index.js' +import type { KuboNode, KuboInfo, KuboInitOptions, KuboOptions, KuboStartOptions } from './index.js' import type { PeerInfo } from '@libp2p/interface' import type { KuboRPCClient } from 'kubo-rpc-client' @@ -10,9 +10,9 @@ export interface KuboClientInit extends KuboOptions { } /** - * Controller for remote nodes + * Node for remote nodes */ -export default class KuboClient implements KuboController { +export default class KuboClient implements KuboNode { public options: KuboOptions & Required> public peerInfo?: PeerInfo public id: string diff --git a/src/kubo/daemon.ts b/src/kubo/daemon.ts index 9e1b4fcb..f275f61b 100644 --- a/src/kubo/daemon.ts +++ b/src/kubo/daemon.ts @@ -5,7 +5,7 @@ import mergeOptions from 'merge-options' import pDefer from 'p-defer' import waitFor from 'p-wait-for' import { checkForRunningApi, tmpDir, buildStartArgs, repoExists, buildInitArgs } from './utils.js' -import type { KuboController, KuboInfo, KuboInitOptions, KuboOptions, KuboStartOptions } from './index.js' +import type { KuboNode, KuboInfo, KuboInitOptions, KuboOptions, KuboStartOptions } from './index.js' import type { Logger } from '@libp2p/interface' import type { KuboRPCClient } from 'kubo-rpc-client' @@ -19,9 +19,9 @@ function translateError (err: Error & { stdout: string, stderr: string }): Error } /** - * Controller for daemon nodes + * Node for daemon nodes */ -export default class KuboDaemon implements KuboController { +export default class KuboDaemon implements KuboNode { public options: KuboOptions & Required> private readonly disposable: boolean diff --git a/src/kubo/index.ts b/src/kubo/index.ts index 2630ee64..4930ff10 100644 --- a/src/kubo/index.ts +++ b/src/kubo/index.ts @@ -1,4 +1,4 @@ -import type { Controller, ControllerOptions } from '../index.js' +import type { Node, NodeOptions } from '../index.js' import type { KuboRPCClient } from 'kubo-rpc-client' export interface KuboInit { @@ -38,7 +38,7 @@ export interface KuboStartOptions { args?: string[] } -export interface KuboOptions extends ControllerOptions { +export interface KuboOptions extends NodeOptions { type: 'kubo' /** @@ -67,6 +67,6 @@ export interface KuboInfo { repo: string } -export interface KuboController extends Controller { +export interface KuboNode extends Node { } diff --git a/test/controller.spec.ts b/test/controller.spec.ts index 9c678275..87b70c52 100644 --- a/test/controller.spec.ts +++ b/test/controller.spec.ts @@ -9,7 +9,7 @@ import merge from 'merge-options' import { isBrowser, isWebWorker, isNode, isElectronMain } from 'wherearewe' import { createFactory } from '../src/index.js' import { repoExists } from '../src/kubo/utils.js' -import type { Factory, KuboOptions, SpawnOptions, KuboController } from '../src/index.js' +import type { Factory, KuboOptions, SpawnOptions, KuboNode } from '../src/index.js' const types: Array = [{ type: 'kubo' @@ -18,10 +18,10 @@ const types: Array = [{ remote: true }] -describe('Controller API', function () { +describe('Node API', function () { this.timeout(60000) - let factory: Factory + let factory: Factory before(async () => { factory = createFactory({ diff --git a/test/create.spec.ts b/test/create.spec.ts index 2e779ad2..b4c39862 100644 --- a/test/create.spec.ts +++ b/test/create.spec.ts @@ -6,20 +6,20 @@ import { expect } from 'aegir/chai' import * as kubo from 'kubo' import { create as createKuboRPCClient } from 'kubo-rpc-client' import { isNode, isElectronMain } from 'wherearewe' -import { createFactory, createController, createServer, type KuboOptions, type SpawnOptions, type KuboController, type Factory } from '../src/index.js' +import { createFactory, createNode, createServer, type KuboOptions, type SpawnOptions, type KuboNode, type Factory } from '../src/index.js' import KuboClient from '../src/kubo/client.js' import KuboDaemon from '../src/kubo/daemon.js' import type Server from '../src/endpoint/server.js' -describe('`createController` should return the correct class', () => { - let node: KuboController +describe('`createNode` should return the correct class', () => { + let node: KuboNode afterEach(async () => { await node?.stop() }) it('for type `kubo` ', async () => { - node = await createController({ + node = await createNode({ type: 'kubo', test: true, disposable: false, @@ -35,7 +35,7 @@ describe('`createController` should return the correct class', () => { }) it('for remote', async () => { - node = await createController({ + node = await createNode({ type: 'kubo', test: true, remote: true, @@ -60,8 +60,8 @@ const types: Array = [{ bin: isNode ? kubo.path() : undefined }] -describe('`createController({test: true})` should return daemon with test profile', () => { - let node: KuboController +describe('`createNode({test: true})` should return daemon with test profile', () => { + let node: KuboNode afterEach(async () => { await node?.stop() @@ -69,15 +69,15 @@ describe('`createController({test: true})` should return daemon with test profil for (const opts of types) { it(`type: ${opts.type} remote: ${Boolean(opts.remote)}`, async () => { - node = await createController(opts) + node = await createNode(opts) expect(await node.api.config.get('Bootstrap')).to.be.empty() await node.stop() }) } }) -describe('`createController({test: true})` should return daemon with correct config', () => { - let node: KuboController +describe('`createNode({test: true})` should return daemon with correct config', () => { + let node: KuboNode afterEach(async () => { await node?.stop() @@ -85,7 +85,7 @@ describe('`createController({test: true})` should return daemon with correct con for (const opts of types) { it(`type: ${opts.type} remote: ${Boolean(opts.remote)}`, async () => { - node = await createController(opts) + node = await createNode(opts) const swarm = await node.api.config.get('Addresses.Swarm') expect(swarm).to.include('/ip4/127.0.0.1/tcp/0') diff --git a/test/kubo/utils.node.ts b/test/kubo/utils.node.ts index 6ad317af..5e509296 100644 --- a/test/kubo/utils.node.ts +++ b/test/kubo/utils.node.ts @@ -6,7 +6,7 @@ import path from 'path' import { expect } from 'aegir/chai' import * as kubo from 'kubo' import { create as createKuboRPCClient } from 'kubo-rpc-client' -import { createFactory, createController } from '../../src/index.js' +import { createFactory, createNode } from '../../src/index.js' import { tmpDir, checkForRunningApi, repoExists, removeRepo, buildStartArgs, buildInitArgs } from '../../src/kubo/utils.js' describe('utils', function () { @@ -24,7 +24,7 @@ describe('utils', function () { }) it('should return path to api with running node', async () => { - const node = await createController({ + const node = await createNode({ test: true, type: 'kubo', rpc: createKuboRPCClient, @@ -68,7 +68,7 @@ describe('utils', function () { describe('repoExists', () => { it('should resolve true when repo exists', async () => { - const node = await createController({ + const node = await createNode({ type: 'kubo', test: true, rpc: createKuboRPCClient,