All Projects → Maxim-Mazurok → google-api-typings-generator

Maxim-Mazurok / google-api-typings-generator

Licence: MIT license
Updated and fixed version of TypeScript typings for Google APIs generator

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to google-api-typings-generator

mxgraph-road-to-DefinitelyTyped
Community effort followup to provide mxgraph TypeScript type definitions / typings via DefinitelyTyped
Stars: ✭ 23 (-45.24%)
Mutual labels:  typescript-definitions, type-definitions
google-it-telegram-bot
🤖 @Google_itBot 🔎 Search and share LINKS/IMAGES/VIDEOS in inline mode
Stars: ✭ 40 (-4.76%)
Mutual labels:  google-api
svelte-typeahead
Accessible, fuzzy search typeahead component
Stars: ✭ 141 (+235.71%)
Mutual labels:  typescript-definitions
svelte-intersection-observer
Detect if an element is in the viewport using the Intersection Observer API
Stars: ✭ 151 (+259.52%)
Mutual labels:  typescript-definitions
dts-jest
A preprocessor for Jest to snapshot test TypeScript declaration (.d.ts) files
Stars: ✭ 102 (+142.86%)
Mutual labels:  typescript-definitions
Definitelytyped
The repository for high quality TypeScript type definitions.
Stars: ✭ 37,066 (+88152.38%)
Mutual labels:  typescript-definitions
Bing-Maps-V8-TypeScript-Definitions
This project contains the TypeScript definitions for the Bing Maps V8 Web Control.
Stars: ✭ 36 (-14.29%)
Mutual labels:  typescript-definitions
TradeByte
💸 TradeByte - Stocks Trading Simulation WebApp
Stars: ✭ 30 (-28.57%)
Mutual labels:  google-api
handprint
Apply different text recognition services to images of handwritten documents.
Stars: ✭ 127 (+202.38%)
Mutual labels:  google-api
ember-typings
Typescript type definitions for ember.js
Stars: ✭ 13 (-69.05%)
Mutual labels:  typescript-definitions
types
TypeScript Type Definitions same as DefinitelyTyped.
Stars: ✭ 31 (-26.19%)
Mutual labels:  typescript-definitions
carbon-components-svelte
Svelte implementation of the Carbon Design System
Stars: ✭ 1,615 (+3745.24%)
Mutual labels:  typescript-definitions
HighlightTranslator
Highlight Translator can help you to translate the words quickly and accurately. By only highlighting, copying, or screenshoting the content you want to translate anywhere on your computer (ex. PDF, PPT, WORD etc.), the translated results will then be automatically displayed before you.
Stars: ✭ 54 (+28.57%)
Mutual labels:  google-api
TypeScript-Library-Checklist
Your pre-launch checklist.
Stars: ✭ 19 (-54.76%)
Mutual labels:  typescript-definitions
google-oauth2-web-client
Login with Google using OAuth2 for client-side web app
Stars: ✭ 32 (-23.81%)
Mutual labels:  google-api
Type Fest
A collection of essential TypeScript types
Stars: ✭ 6,623 (+15669.05%)
Mutual labels:  typescript-definitions
sveld
Generate TypeScript definitions for your Svelte components
Stars: ✭ 281 (+569.05%)
Mutual labels:  typescript-definitions
google maps
🗺 An unofficial Google Maps Platform client library for the Rust programming language.
Stars: ✭ 40 (-4.76%)
Mutual labels:  google-api
grasp
Essential NLP & ML, short & fast pure Python code
Stars: ✭ 58 (+38.1%)
Mutual labels:  google-api
FusedBulb
Location fetch library.
Stars: ✭ 22 (-47.62%)
Mutual labels:  google-api

google-api-typings-generator

GitHub Code Style: Google Dependabot Status Donate

Auto Publish to NPM Auto Generate Types CI Test

Generate TypeScript type definitions for all Google APIs, using Google API discovery service.

Meant to be used with Google APIs JavaScript Browser Client, aka gapi. Not to be mistaken with NodeJS Server Client which is already in TS; details

Fork Log:

Usage

Generating types

  1. Use the supported Node version via Node Version Manager:

    nvm install
  2. Install dependencies:

    npm install
  3. Generate type definitions for:

    • all discovered Google APIs:

      npm start

      Some APIs are disabled or not fully developed yet, so some expected errors might be output.

    • one service by name:

      npm start "--" --service sheets

      where sheets is the name of the Google Sheets service.

      The full list of APIs can be found here or here.

    • one service by URL:

      npm start "--" --url "https://sheets.googleapis.com/$discovery/rest?version=v4"

      Note that we have to use - full-width dollar sign instead of the regular $, it will be replaced by the script, this is to avoid complications with escaping of $discovery.

Compiling project

npm run compile
node dist/cli.js --out ./types

Running tests

Tests are run automatically in practice via GitHub Actions continuous integration.

Syncing gapi client namespace in DT with available APIs

Here's how to sync (add new and remove obsolete) Google APIs to/from @types/gapi.client.* namespace in DefinitelyTyped:

  1. Make sure that this project, DefinitelyTyped/DefinitelyTyped, and microsoft/DefinitelyTyped-tools are all in the home directory on Linux: ~
  2. npm run apis-sync-helper will update config in this repo and allowed list in DT-tools
  3. npm run start-dt will update DT
  4. Open PR to DT-tools, but only include additions, not deletions, otherwise, all DT PRs are gonna start failing
  5. Wait for it to get merged
  6. Open PR to DT (include all changes)
  7. Wait for it to get merged
  8. Open PR to DT-tools, now only include deletions that were omitted previously, making sure that all deleted types are absent in the DT repo
  9. Once it's merged - all done, rinse and repeat in a few months or so.

Ideally, this should be automated in #401

Lint

The generated type definitions are linted via dtslint, mimicking DefinitelyTyped's process.

A single project can be linted via:

npm run dtslint types/<project-directory>

All projects can be linted in parallel via:

GAPI_MAX_PARALLEL=3 npm run lint

Unit (WIP)

Unit tests for this generator project are written with Jest. They can be run via:

npm run test

Fixing formatting

This project leverages Google's TypeScript Style (gts) to standardize formatting.

To invoke the automatic code fixer, run:

npm run fix

Publishing to DefinitelyTypes @types

Do not publish types to DT directly

We've switched to publishing "real" types to npm as @maxim_mazurok/gapi.client.* and then referencing them in @types/gapi.client.* so that we can release updates automatically and quickly, without using too many human resources of DT.

See Syncing gapi client namespace in DT with available APIs section for instructions.

Details

Auto Updates

Every hour, type definitions are generated, linted, tested, and published to NPM.

Resource VS Body

First approach (Resource):

gapi.client.sheets.spreadsheets.batchUpdate({
  spreadsheetId: 'someId',
  resource: {
    // Request Body goes here, as part of `request`
  },
});

second approach (Body):

gapi.client.sheets.spreadsheets.batchUpdate(
  {
    spreadsheetId: 'someId',
  },
  {
    // Request Body goes here, as a second argument
  }
);

Both approaches are valid (tested for Google Sheets API), but the first one seems to be the default for JS Client Library.

More info here: google/google-api-javascript-client#432 (comment), and here: declanvong@bec4f89#r35992626

NOTE: Some APIs have methods that accept resource parameter that is not the request body. In that case, we only generate the second approach (details)

Empty interfaces

This fork keeps interfaces even if they are empty to make typings more accurate.

More info here: Maxim-Mazurok/google-api-typings-generator#4

Arrays / repeated values

This fork understands "repeated": true

More info here: Maxim-Mazurok/google-api-typings-generator#1 and here: declanvong@bec4f89#r35992626

JavaScript VS NodeJS Clients

There are two ways to use Google APIs: on the client-side (in the browser) and on the server-side.

The client-side library, called gapi is kinda closed-source. We can see compiled (unreadable minified) JS code of the client-side library. When you use any Google JS API, you use gapi. It loads library definitions from Google API Discovery Service and generates all API calls on the fly.

So, there's no TS version of gapi because it's closed-source and other client libraries do not exist, because they are being generated on the fly by gapi.

If you want to use TypeScript with gapi - you have to use type definitions generated by this project. While we do generate typings for Google APIs, we can't generate gapi typings from discovery, so we rely on @types/gapi and you also should.

The server-side libraries are open-sourced and are available here. Since they are written in TS, you don't need any additional type definitions to use them.

Troubleshooting

npm install - 404 Not Found

The error looks like this (see #483):

$ npm install @types/gapi.client.YOUR_API@v2 --save-dev
npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/@types%2fgapi.client.YOUR_API - Not found
npm ERR! 404
npm ERR! 404  '@types/gapi.client.YOUR_API@v2' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)

It's most likely caused by your API package not being published to NPM yet.

To fix this - open an issue and I'll update the list of supported APIs.

Later on, when #401 is closed - this process will be automated.

Also, you can use these types from the types branch

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].