Socket
Book a DemoInstallSign in
Socket

a2c

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

a2c

Lightweight Aria2 JSON-RPC client with full type definition.

latest
Source
npmnpm
Version
0.2.0
Version published
Maintainers
1
Created
Source

A2C

npm minified size downloads

Lightweight Aria2 JSON-RPC client with full type definition.

Features

  • Decoupling. A2C is responsible for only the Aria2-specific part, using async-call-rpc to implement the JSON-RPC client.
  • Lightweight. Most of the content of A2C is type definitions, they are generally not bundled.
  • Just Fetch. A2C uses the runtime environment fetch, not node-fetch, isomorphic-fetch or other...

Install

A2C requires async-call-rpc, so you should install them both.

pnpm add a2c async-call-rpc # pnpm
# yarn add a2c async-call-rpc # yarn
# npm i a2c async-call-rpc # npm

Usage

import { createClient } from 'a2c'
// import { notify, batch } from 'async-call-rpc'

const aria2 = createClient({
  url: 'http://localhost:6800/jsonrpc', // defaultValue
  secret: '123e4567-e89b-12d3-a456-426614174000', // --rpc-secret, optional
})

await aria2.getVersion().then(console.log) // { enabledFeatures: [], version: '1.36.0' }

// const notify = notify(createClient())
// const [batch, emit, drop] = batch(createClient())

If you use user/passwd instead of secret:

import { createClient } from 'a2c'

const aria2 = createClient({
  url: 'http://localhost:6800/jsonrpc', // defaultValue
  user: 'username', // --rpc-user
  secret: 'password', // --rpc-passwd
})

Advanced

createClient is a wrapper around AsyncCall. So of course you can use it directly if you want:

import { A2Channel, type Aria2 } from 'a2c'
import { AsyncCall } from 'async-call-rpc'

const aria2 = AsyncCall<Aria2>(
  {},
  {
    channel: new A2Channel({
      url: 'http://localhost:6800/jsonrpc', // defaultValue
      secret: '', // --rpc-secret, optional
    }),
  }
)

A2Channel uses the fetch in the runtime environment.

But for some custom use cases, you can also implement your own EventBasedChannel and reuse the A2C type definition:

import type { Aria2 } from 'a2c'
import { type EventBasedChannel, AsyncCall } from 'async-call-rpc'

class MyChannel implements EventBasedChannel {
  on(listener: (data: unknown) => void) {
    ...
  }
  send(data: unknown): void {
    ...
  }
}

const aria2 = AsyncCall<Aria2>(
  {},
  { channel: new MyChannel() }
)

Keywords

aria2

FAQs

Package last updated on 24 Oct 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts