Catalog npm
Back to packageRELEASE DETAILS

0.0.1

npm

123peterkim-minirpc

Server:

Published26 Oct 2024
Direct dependencies8
Transitive dependenciesNot calculated

README

Current package documentation

Basic Usage

Server:

import { createServer } from 'minirpc'

const server = createServer()

const router = server.router({
	greet(name: string) {
		return `Hello ${name}`
	},
})

export type Router = typeof router

await server.serve({ port: 3000 })

Client:

import createClient from 'minirpc'
import type { Router } from './server'

const api = createClient<Router>({
	url: 'ws://localhost:3000',
})

console.log(await api.greet('World')) // Hello World

Subscriptions

Server:

import { createChannel } from 'minirpc'

const channel = createChannel((name: string) => {
	return `Welcome ${name} to this channel`
})

setInterval(() => {
	channel.push(`This channel has ${channel.size} subscribers`)
}, 1000)

router({
	getEvents: channel.pull,
})

Client:

api.getEvents('John Doe').subscribe((event) => {
	// Welcome John Doe to this channel
	// This channel has 1 subscribers
	console.log(event)
})

Context

import { createContext, RPCClientError } from 'minirpc'

const userIdContext = createContext<string>()

router({
	logIn(username: string, password: string) {
		const userId = userIdContext()
		if (username === 'Admin' && password === '123456') {
			userId.set('admin')
		} else {
			throw new RPCClientError('Wrong credentials')
		}
	},
	getAdminData() {
		const userId = userIdContext()
		if (userId.get() === 'admin') {
			return 'secret'
		} else {
			throw new RPCClientError('Expected Admin')
		}
	},
})

Connection Options

Server:

server.serve({
	onUpgrade(ctx) {
		if (ctx.request.url === '/forbidden') {
			ctx.error(401)
			return
		}
		const ws = ctx.upgrade()
		console.log('connection open')
		ws.on('close', (code, reason) => {
			console.log('connection closed')
		})
	},
})

Client:

const api = createClient<Router>({
	url: 'ws://localhost:3000',
	backoff: {
		jitter: false,
		maxDelay: Infinity,
		numOfAttempts: 10,
		retry: () => true,
		startingDelay: 100,
		timeMultiple: 2,
	},
	onConnection((connection) => {
		console.log('connection opened')
		await connection.closed // wait for connection to close
		console.log('connection closed')
	})
})

Pruning Stale Connections

Server:

const server = createServer({
	pingTimeout: 60_000,
	pongTimeout: 1_000,
})

Client:

const api = createClient({
	pingInterval: 30_000,
	pongTimeout: 1_000,
})

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 8

Native requirements
8 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
devalue
Environment
{
  "local_name": "devalue",
  "alias": false,
  "peer_metadata": null
}
^5.0.0runtime
ws
Environment
{
  "local_name": "ws",
  "alias": false,
  "peer_metadata": null
}
^8.18.0runtime
@types/node
Environment
{
  "local_name": "@types/node",
  "alias": false,
  "peer_metadata": null
}
^22.5.4development
@types/ws
Environment
{
  "local_name": "@types/ws",
  "alias": false,
  "peer_metadata": null
}
^8.5.12development
eslint
Environment
{
  "local_name": "eslint",
  "alias": false,
  "peer_metadata": null
}
^9.10.0development
tsx
Environment
{
  "local_name": "tsx",
  "alias": false,
  "peer_metadata": null
}
^4.19.0development
typescript
Environment
{
  "local_name": "typescript",
  "alias": false,
  "peer_metadata": null
}
^5.5.4development
typescript-eslint
Environment
{
  "local_name": "typescript-eslint",
  "alias": false,
  "peer_metadata": null
}
^8.4.0development

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "integrity": "sha512-odPAVWHfkQ+M9z+P71raMpw67NX2PHfnd9DkOF1n31KC+hq56f+1vMWa1uoVooIreRFeS2jsNYt4q5wJqSGdwg==",
  "shasum": "31b163c6044015ec6b68ca396e37a0ca2d3e2200",
  "tarball": "https://registry.npmjs.org/123peterkim-minirpc/-/123peterkim-minirpc-0.0.1.tgz",
  "fileCount": 5,
  "unpackedSize": 35892,
  "signatures": [
    {
      "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
      "sig": "MEUCIH7L/+ZkGeogsqyBwGGG/LvUccKd8De0cIUqhd3q/kH2AiEAya+r2ytPXvXeXSc7lzth/QQgg78dGoDdvAAdbbT6Iv4="
    }
  ]
}

Repository

ACCESSIBLE
123peterkim/minirpc

Shared repository data · GitHub

License detected in repository
Not collected
Last push
7 Mar 2024
Archived
No
Contributor identities
— · partial collection

Public sponsor counts have not been collected. These signals belong to the repository owner.

Downloads & popularity

0count
Gauge · observed snapshots24 Oct 2026
10.50
2026-10-24: 0 · observed 2026-10-24T11:54:14.9074778Z
24 Oct24 Oct

github · 1 observations shown. Missing days are unknown.

View observed values
Date / source periodValueObserved at
2026-10-2402026-10-24T11:54:14.9074778Z

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 18:10 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:bd941f894395e49b52a98c8c574b3bf02d912d7287d65a2afabccc8edc5d1330

Other collected versions

View all collected versions →