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

google-script-dts-generator

v1.3.2

Published

Generate TypeScript declaration (.d.ts) files for google.script(Client-side API).

Downloads

50

Readme

google-script-dts-generator NPM version

Generate TypeScript declaration (.d.ts) file for google.script.run(Client-side API).

About

google-script-dts-generator generates a client-side TypeScript declaration (.d.ts) for the Apps Script function from a server-side TypeScript source that matchs the following conditions:

  • function assignment expressions to global object.
  • named export functions (when using namedExportsFiles option)

Example

See example.

server.ts:

global.echo = (message: string) => {
  return message;
};

generate:

$ google-script-dts-generator --sourcesDir server/ --outputDir client/

generated google-script.d.ts:

declare namespace google {
    /**
     * Methods available to Google Apps Script
     */
    namespace script {
        interface IRun {
            echo(message: string): void;
            /**
             * Sets a callback function to run if the server-side function throws an exception. Without a failure handler, failures are logged to the JavaScript console. To override this, call withFailureHandler(null) or supply a failure handler that does nothing.
             * @param callback a client-side callback function to run if the server-side function throws an exception; the Error object is passed to the function as the first argument, and the user object (if any) is passed as a second argument
             */
            withFailureHandler(callback: (error: Error, object?: any)=>void): IRun;
            /**
             * Sets a callback function to run if the server-side function returns successfully.
             * @param callback a client-side callback function to run if the server-side function returns successfully; the server's return value is passed to the function as the first argument, and the user object (if any) is passed as a second argument
             */
            withSuccessHandler(callback: (value: any, object?: any)=>void): IRun;
            /**
             * Sets an object to pass as a second parameter to the success and failure handlers.
             * @param {Object} object an object to pass as a second parameter to the success and failure handlers; because user objects are not sent to the server, they are not subject to the restrictions on parameters and return values for server calls. User objects cannot, however, be objects constructed with the new operator
             */
            withUserObject(object: object): IRun;
        }
        
        const run: IRun;

        // omitted below
}

Installation

$ npm install google-script-dts-generator --save-dev

or

$ yarn add google-script-dts-generator

Usage

CLI

$ google-script-dts-generator --sourcesDir server --outputDir client

Options

--sourcesDir <sources>

Path to TypeScript sources directory.

$ google-script-dts-generator --outputDir ./example/client --sourcesDir ./example/server

--outputDir <outputDir>

Path to a generated d.ts file output directory.

$ google-script-dts-generator --outputDir ./example/client --sourcesDir ./example/server

--namedExportsFiles <glob>

A glob path pattern to generates a client-side TypeScript declaration (.d.ts) from named exports.
Note: Glob patterns should always use / as a path separator, even on Windows systems

$ google-script-dts-generator --outputDir ./example/client --sourcesDir ./example/server --namedExportsFiles './example/server/**/*.ts'

--endpointsOnly

When use @types/google.script.client-side, User needs define specify functions as PublicEndpoints. google-script-dts-generator support generate only PublicEndpoint interfaces.

yarn google-script-dts-generator -s ./src/server/ -o ./src/client/ --namedExportsFiles "./src/server/**/*.ts" --endpointsOnly

Output:

declare namespace google {
  namespace script {
    interface PublicEndpoints {
        doGet(): void;
        myFunction(param1: string, param2: boolean): void;
    }
  }
}

--nonVoidReturnType

generate return type of server-side function as return type of client-side function. This option assumed that using in combination with gas-client.

Note: Use [email protected] or later

yarn google-script-dts-generator -s ./src/server/ -o ./src/client/ --namedExportsFiles "./src/server/**/*.ts" --endpointsOnly --nonVoidReturnType

Output:

declare namespace google {
    /**
     * Methods available to Google Apps Script
     */
    namespace script {
        interface PublicEndpoints {
            helloWorld(): string;
            echo(message: string): string;
        }
    }
}

client.ts

import { GASClient } from 'gas-client';

const { serverFunctions } = new GASClient<google.script.PublicEndpoints>();
serverFunctions.echo("hello gas")
    .then((s) => console.log(s))
    .catch(e => console.error(e));