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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@toolsplus/forge-trpc-link

v1.0.0

Published

Custom tRPC link to enable tRPC for Atlassian Forge apps

Downloads

51

Readme

@toolsplus/forge-trpc-link

Custom tRPC link to enable tRPC for Atlassian Forge apps.

Installation

npm install @toolsplus/forge-trpc-link
npm install superjson

Note that this package has a peer dependency on @forge/bridge. If you have not installed @forge/bridge you may install before installing this package.

Usage

You can import and add the customUiBridgeLink to the links array as follows:

// trpc-client.ts
import { createTRPCClient } from '@trpc/client';
import { customUiBridgeLink } from '@toolsplus/forge-trpc-link';
import type { HelloRouter } from '../my-trpc-server';
import superjson from 'superjson';

export const trpcClient = createTRPCClient<HelloRouter>({
  links: [
    customUiBridgeLink({
      resolverFunctionKey: 'rpc',
      transformer: superjson,
    }),
  ],
});

Usage with @trpc/react-query (optional)

react-query is a popular library for managing server state in React applications. You can use @trpc/react-query to integrate tRPC with react-query. You will need react-query 5 and React 18 to use this.

Instantiate the tRPC client with the customUiBridgeLink as shown below:

// trpc-client.ts
import { createTRPCReact } from '@trpc/react-query';
import { customUiBridgeLink } from '@toolsplus/forge-trpc-link';
import type { HelloRouter } from '../my-trpc-server';
import superjson  from 'superjson';

export const trpcReact = createTRPCReact<HelloRouter>();
export const trpcReactClient = trpcReact.createClient({
  links: [
    customUiBridgeLink({
      resolverFunctionKey: 'rpc',
      transformer: superjson,
    }),
  ],
})

Wrap your application with the TRPCProvider as shown below:

import { trpcReact, trpcReactClient } from "./trpc-client";

const queryClient = new QueryClient();

export default function App() {
  return (
    <trpcReact.Provider client={trpcReactClient} queryClient={queryClient}>
      <QueryClientProvider client={queryClient}>
        ... 
      </QueryClientProvider>
    </trpcReact.Provider>
  )
}

Then consume the typed queries and mutations in your components as shown below:

const query = trpcReact.greeting.useQuery({ name: 'result from trpc provided query!' });
// or even use suspense
const suspenseQuery = trpcReact.greeting.useSuspenseQuery();

customUiBridgeLink options

The customUiBridgeLink function takes an options object that has the CustomUiBridgeLinkOptions shape.

interface CustomUiBridgeLinkOptions {
  /**
   * Key of the Forge resolver function that handles tRPC 
   * requests from this link.
   * 
   * @defaultValue 'rpc'
   */
  resolverFunctionKey?: string;
  /**
   * The transformer to use for serializing and deserializing 
   * tRPC requests and responses. You usually want to use superjson.
   *
   */
  transformer: {
    serialize: (object: any) => any;
    deserialize: (object: any) => any;
  };
}