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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@dreamstack-us/lucid-trpc

v0.0.3

Published

tRPC connector for Lucid.js - bidirectional sync with tRPC backends

Readme

@dreamstack-us/lucid-trpc

tRPC connector for Lucid.js - bidirectional sync with tRPC backends.

Installation

npm install @dreamstack-us/lucid-trpc @dreamstack-us/lucid-core @trpc/client

Usage

Basic Setup

import { createTrpcConnector, TrpcSyncManager } from '@dreamstack-us/lucid-trpc';
import { LocalForageStore } from '@dreamstack-us/lucid-web';
import { LucidProvider } from '@dreamstack-us/lucid-react';
import { trpcClient } from './trpc';
import { lucidSchema } from './schema';
import { useAuthStore } from './stores';

// Create store
const store = new LocalForageStore({ name: 'myapp' });

// Create connector
const connector = createTrpcConnector({
  client: trpcClient,
  schema: lucidSchema,
  store,
  routerMap: {
    posts: 'posts',
    tags: 'tags',
  },
  getAccessToken: () => useAuthStore.getState().getAccessToken(),
});

// Create sync manager
const syncManager = new TrpcSyncManager({
  connector,
  schema: lucidSchema,
  store,
  syncInterval: 30000, // 30 seconds
});

// Start sync on app mount
syncManager.start();

// In React
function App() {
  return (
    <LucidProvider schema={lucidSchema} store={store} connector={connector}>
      <MyApp />
    </LucidProvider>
  );
}

Connector Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | client | TrpcClientLike | required | tRPC client instance | | schema | LucidSchema | required | Lucid schema | | store | LucidStore | required | Local store instance | | routerMap | Record<string, string> | required | Map Lucid tables to tRPC routers | | procedureMap | ProcedureMap | { insert: 'create', update: 'update', delete: 'delete' } | Procedure names | | fetchProcedure | string | 'list' | Query procedure for downloads | | transformUpload | function | - | Transform data before upload | | transformDownload | function | - | Transform data after download | | getAccessToken | function | - | Auth token getter | | debug | boolean | false | Enable logging |

tRPC Router Requirements

Your tRPC routers should implement these procedures:

// Example posts router
export const postsRouter = router({
  // For downloads (fetchProcedure)
  list: publicProcedure
    .input(z.object({
      updatedAfter: z.string().optional(),
      limit: z.number().optional(),
    }).optional())
    .query(async ({ input }) => {
      // Return array of posts
    }),

  // For uploads (procedureMap)
  create: protectedProcedure
    .input(postSchema)
    .mutation(async ({ input }) => {
      // Insert new post
    }),

  update: protectedProcedure
    .input(z.object({ id: z.string(), ...partialPostSchema }))
    .mutation(async ({ input }) => {
      // Update existing post
    }),

  delete: protectedProcedure
    .input(z.object({ id: z.string() }))
    .mutation(async ({ input }) => {
      // Delete post
    }),
});

Sync Manager

The TrpcSyncManager handles periodic background sync:

const syncManager = new TrpcSyncManager({
  connector,
  schema: lucidSchema,
  store,
  syncInterval: 30000, // 30 seconds
  tables: ['posts', 'tags'], // Optional: specific tables
  debug: true,
});

// Start syncing
await syncManager.start();

// Force sync a table
await syncManager.forceSync('posts');

// Force sync all
await syncManager.forceSyncAll();

// Get sync status
const status = await syncManager.getSyncStatus();
// { posts: { lastSyncedAt: 1699999999999, isSynced: true }, ... }

// Stop syncing
syncManager.stop();

Data Transformation

Transform data between Lucid and tRPC formats:

const connector = createTrpcConnector({
  // ...
  transformUpload: (table, operation, data) => {
    // Convert camelCase to snake_case for server
    return {
      ...data,
      created_at: data.createdAt,
      updated_at: data.updatedAt,
    };
  },
  transformDownload: (table, data) => {
    // Convert snake_case to camelCase from server
    return {
      ...data,
      createdAt: data.created_at,
      updatedAt: data.updated_at,
    };
  },
});

How It Works

Upload Flow (Local -> Server)

  1. Mutations are queued locally via LucidStore.queueCrud()
  2. QueueProcessor calls connector.uploadData() with batches
  3. Connector maps table to tRPC router via routerMap
  4. Calls appropriate mutation (create, update, delete)
  5. On success, removes entries from queue

Download Flow (Server -> Local)

  1. TrpcSyncManager.syncTable() is called periodically
  2. Calls connector.fetchData() with since timestamp
  3. Connector calls tRPC query (default: list)
  4. Results are written to local store via store.upsertBatch()
  5. Sync timestamp is updated via store.setLastSyncedAt()

License

MIT