Unofficial TypeScript type definitions for the Holepunch ecosystem
Welcome! This package provides TypeScript type definitions for key modules in the Holepunch ecosystem, making it easier for TypeScript developers to build on top of these amazing peer-to-peer tools.
npm install holepunch-types
# or
yarn add holepunch-types
# or
bun add holepunch-typesOnce installed, the type definitions will be automatically available when you import the corresponding modules:
import Autobase from "autobase";
import Hyperswarm from "hyperswarm";
import BlindPairing from "blind-pairing";
import ReadyResource from "ready-resource";
import Corestore from "corestore";
import Hyperbee from "hyperbee";
import Hyperblobs from "hyperblobs";
import Hyperdrive from "hyperdrive";
import * as b4a from "b4a";
import { encode, decode } from "z32";
// TypeScript will now provide full type support for these modulesGet started quickly with TypeScript support in your Pear project:
pear init --yes --type terminalmv index.js index.tsbun installbun add github:Drache93/holepunch-types#v0.1.9Create or update your tsconfig.json to include the type definitions:
{
"compilerOptions": {
"typeRoots": ["./node_modules/@types", "./node_modules/holepunch-types"]
}
}Install some of the supported libraries and start building:
bun add hyperswarm hyperbee// index.ts
import Hyperswarm from "hyperswarm";
import Hyperbee from "hyperbee";
import * as b4a from "b4a";
// Full TypeScript support with autocomplete!
const swarm = new Hyperswarm({
keyPair: crypto.keyPair(), // Properly typed
maxPeers: 10,
});
const bee = new Hyperbee(core, {
keyEncoding: "utf-8",
valueEncoding: "utf-8",
});
swarm.on("connection", (connection, peerInfo) => {
// Both connection and peerInfo are fully typed
console.log("Connected to peer:", b4a.toString(peerInfo.publicKey, "hex"));
});
await swarm.join(b4a.from("chat-room", "utf-8"));Build your TypeScript project:
bun build index.ts --outdir . --packages=externalThen run it like a normal(TM) Pear app!:
pear run -d .Update your package.json dev script for easy development:
{
"scripts": {
"dev": "bun build index.ts --outdir . --packages=external && pear run -d ."
}
}Then simply run:
bun run devautobase⚡ - Append-only log with automatic linearizationblind-pairing🕶️ - Secure peer discovery and pairingcorestore📦 - Hypercore factory and storage managementhyperswarm🌐 - Distributed peer discovery and networkingready-resource🔧 - Resource lifecycle management
hyperbee🐝 - Sorted key-value store built on Hypercorehyperblobs💾 - Binary large object storagehyperdrive🚗 - P2P file system and versioning
z32🔢 - Base32 encoding/decodingb4a🧩 - Buffer utilities for Node.js and browsers
Note: This is not a conclusive list or fully tested. More modules may be added as the ecosystem grows and as usage expands.
The type definitions include:
- Full API coverage for all public methods and properties
- Proper inheritance and interface implementations
- Event emitter support with typed events
- Async iterator support where applicable
- Comprehensive options interfaces for all method parameters
- Stream support for read/write operations
- Batch operations with proper typing
- Versioning and snapshot support
- Zero configuration - Types are automatically available
- Complete IntelliSense - Full autocomplete and type checking
- Event handling - Properly typed event listeners and emitters
- Async operations - Full support for promises and async/await
- Stream operations - Typed read/write streams
- Batch processing - Efficient batch operations with type safety
Special thanks to the folks at Holepunch for their groundbreaking work on these projects! This package is community-maintained and not officially affiliated with Holepunch or the upstream projects.
Contributions, suggestions, and corrections are very welcome! Please open an issue or pull request if you spot a problem or want to add more types.
MIT — see LICENSE