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

@repliql/conduit

v0.1.0

Published

SharedWorker, with dedicated Worker powers

Readme

@repliql/conduit

SharedWorker, with dedicated Worker powers

@repliql/conduit enables architecture where tabs share a SharedWorker and spin up dedicated Workers, with SharedWorker accessing dedicated workers through election. It is useful to give a SharedWorker capabilities of dedicated Workers, with automatic leader election.

Main application is to access OPFS from dedicated Worker transparently from SharedWorker.

Install

npm install @repliql/conduit comlink
# or
bun add @repliql/conduit comlink

comlink is a peer dependency.

How It Works

Comlink is used for inter-process communication. Leader election and tab close detection is done with Web Locks.

To access the dedicated worker capabilities, the shared worker communicates through the elected tab. Only one tab/dedicated worker is elected leader at any given time.

Example

types.d.ts - Define types of shared interfaces

export interface Computations {
  square: (v: number) => number
  abs: (v: number) => number
}

export interface Service {
  increment: (v: number) => void
  getSquare: () => number
  getAbs: () => number
}

worker.ts - The dedicated worker

import { conduit } from '@repliql/conduit/dedicated'
import * as Comlink from 'comlink'

import type { Computations } from './types.d.ts'

const computations: Computations = {
  square(value: number) {
    return value * value
  },
  abs(value: number) {
    return Math.abs(value)
  },
}

conduit({
  onElectedLeader(port) {
    Comlink.expose(computations, port)
  },
})

shared-worker.ts - The shared worker

import { conduit } from '@repliql/conduit/shared'
import * as Comlink from 'comlink'

import type { Computations, Service } from './types.d.ts'

const { wrapDedicatedWorker, onConnectTab, events } = conduit()

events
  .on('leaderElected', ({ leaderId }) => {
    console.log('New leader elected:', leaderId)
  })
  .on('leaderResigned', ({ leaderId }) => {
    console.log('Leader resigned:', leaderId)
  })

const computations = wrapDedicatedWorker<Computations>()

let i = 0

const service: Service = {
  increment(offset: number) {
    i += offset
  },
  async getSquare() {
    return await computations.square(i)
  },
  async getAbs() {
    return await computations.abs(i)
  },
}

// Use instead of `self.onconnect = ...`
onConnectTab(port => {
  Comlink.expose(service, port)
})

tab.ts - The web app

import { conduit } from '@repliql/conduit/tab'
import * as Comlink from 'comlink'

import type { Service } from './types.d.ts'

const { sharedWorker } = conduit({
  loadWorker: () => new Worker('worker.ts'),
  loadSharedWorker: () => new SharedWorker('shared-worker.ts'),
})

const service = Comlink.wrap<Service>(sharedWorker.port)

Promise.resolve().then(async () => {
  await service.increment(6)
  console.log(await service.getSquare()) // prints "36"
  await service.increment(-10)
  console.log(await service.getAbs()) // prints "4"
})