npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@memofs/json-rpc

v1.3.0-beta.2

Published

Dependency-free JSON-RPC 2.0 protocol primitives shared by MemoFS transports.

Downloads

689

Readme

@memofs/json-rpc

Dependency-free JSON-RPC 2.0 protocol primitives shared by MemoFS transports.

Why a separate package?

Two MemoFS packages speak JSON-RPC over the wire. Before this package, both shipped near-identical copies of the same ~200 lines of spec types and helpers, and one was coupled to the other's error classes. That violates the workspace DRY/SSOT rule and the package-boundaries rule (no transport in core, no distribution→distribution import). Extracting the spec layer into a neutral, dependency-free package fixes both:

  • One set of types and helpers, consumed everywhere.
  • A neutral error type (JsonRpcProtocolError) — consumers that own their own error hierarchy catch it and re-throw in their own type.

What's inside

  • TypesJsonRpcRequest, JsonRpcResponse, JsonRpcSuccessResponse, JsonRpcErrorResponse, JsonRpcId.
  • ConstantsJSON_RPC_ERRORS (the five spec codes: parseError, invalidRequest, methodNotFound, invalidParams, internalError).
  • Parsing & validationparseJsonRpcPayload, validateJsonRpcRequest (throw JsonRpcProtocolError with the correct spec code on any violation).
  • Response helperssuccess(id, result), failure(id, code, message, data?).
  • UtilitiesisNotification, isPlainObject.

Install

npm install @memofs/json-rpc

Requires Node.js >= 22.

Usage

import {
	failure,
	JSON_RPC_ERRORS,
	JsonRpcProtocolError,
	parseJsonRpcPayload,
	success,
	validateJsonRpcRequest,
} from "@memofs/json-rpc";

// 1. Parse the incoming wire payload (throws JsonRpcProtocolError on bad JSON).
const payload = parseJsonRpcPayload(await request.text());

// 2. Validate the request shape (throws with the right spec code).
const request = validateJsonRpcRequest(payload);

// 3. Dispatch + respond.
return success(request.id, await handle(request.method, request.params));

// On an unknown method:
return failure(
	request.id,
	JSON_RPC_ERRORS.methodNotFound,
	`Method "${request.method}" is not available.`,
);

Mapping the neutral error to your own type

A package with its own error hierarchy re-throws in its own type — the protocol layer never imports a consumer's classes:

import { JsonRpcProtocolError, JSON_RPC_ERRORS } from "@memofs/json-rpc";

try {
	validateJsonRpcRequest(payload);
} catch (err) {
	if (err instanceof JsonRpcProtocolError) {
		throw new YourValidationError(err.message, {
			code: err.jsonRpcCode, // the spec code, already mapped
		});
	}
	throw err;
}

Contributing

See our central Contributing Guide and development scripts for details on formatting, linting, and testing within the monorepo.

License

MIT