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

@gasstack/rpc

v0.1.3

Published

Google Apps Script rpc client/server interaction support

Downloads

145

Readme

@gasstack/rpc

The package is meant to simplify the interaction between a contained webpage and the server side of a Google Apps Script application, beeing it a webapp or an addon.

Description

The package is inspierd by tRPC and provides a way to describe scoped endpoints as functions map on the server side, that can be invoked by a typed client proxy on the client side. Moreover, a mocking facility is provided in order to allow local testing of the clien application before the actual deploy to Google Apps Script.

Usage

On the server side create a scoped endpoint:

const serverApi = {
  sum(a: number, b: number): number {
    return a + b;
  },
  print(s: string): void {},
  wait(range: [number, number]): void {},
} satisfies ServerRunMethods;

const endpoint = createEndpoint(serverApi);

export serverApiType = typeof serverApi;

Then create a function in the global scope to work as a scoping functio. A scoping function is a function whose first parameter is the name of another function which it scopes. Inside it just call the .invoke method of the created endpoint:

function testMyApi(fnName: string, ...params: any[]): any {
  return endpoint.invoke(fnName, ...params);
}

On the client side, import the exported server api type and create a typed client proxy:

const client = createScopedClient<serverApiType>("testMyApi");

It is even possible to create a global scoped client proxy, if the type given describes a set of global functions:

const globalClient = createClient<serverApiType>();

It is then possible to jsut use the proxies with async/await typed interfaces:

await client.sum(1, 2);

In order to test your client app locally it is possible to setup a mock of your RPC interface:

setupMocks(
  {
    async sum(a: number, b: number): Promise<number> {
      return a + b;
    },
    async print(s: string): Promise<void> {},
    async wait(range: [number, number]): Promise<void> {},
  },
  {
    testMyApi: {
      async sum(a: number, b: number): Promise<number> {
        return a + b;
      },
      async print(s: string): Promise<void> {},
      async wait(range: [number, number]): Promise<void> {},
    },
  }
);

After that you can even use the native Google Apps Script proxy:

window.google.script.run
  .withSuccessHandler((value) => console.log(value))
  .sum(1, 2);

Example

Have a look to the e2e test.

API

API Reference