Update TypeScript types from OpenSpace build

The JavaScript API supports TypeScript types that are generated from JSON schemas. The npm package openspace-api-js ships with pre-generated types targeting a specific OpenSpace version. These types need to be updated regularly, for example, when a Topic’s schema changes, a new Topic is added, or the Lua API is updated.

This guide walks through generating the corresponding TypeScript types in openspace-api-js from an OpenSpace build, and trying them out in a consuming repository (for example, the WebGui).

1. Generate the updated JSON schemas

If a Topic’s schema has changed, it needs to be regenerated. Run OpenSpace’s DocsWriter. This writes all JSON schemas into <OpenSpace>/support/types.

Note

Skip this step unless you’ve changed a Topic’s schema.

2. Generate the TypeScript types

There are two kinds of types that can be generated for the API:

  • Topic types, based on the JSON schemas generated in step 1.

  • Lua API types, based on the Lua functions available in the OpenSpace build.

See the openspace-api-js guide’s Generating types from your OpenSpace build section for detailed information about the required prerequisites and exact commands for the generation of both Topic and Lua API types. The generated types are written into the openspace-api-js repository.

3. Test local changes in a consuming repository

  1. In the openspace-api-js repository, run npm pack. This creates a tarball, e.g. openspace-api-js-x.x.x.tgz.

  2. In the consuming repository, run npm install <path-to-openspace-api-js-x.x.x.tgz> to install it as a local dependency pointing at your build.

4. Publish the updated package

See the detailed steps on how to publish the updated openspace-api-js package.