Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ const api = openspaceApi('localhost', 4682);

The package ships with pre-generated types targeting a specific OpenSpace version. If your build differs, you can regenerate them locally. There are two separate generators, one for topic types and one for the Lua library. Both write directly into `src/types/generated/`.

### Topic types (`generate-topic-types`)
### Generate topic types (`generate-topic-types`)

Reads JSON schema files from OpenSpace's `support/types/` directory and compiles them to TypeScript using `json-schema-to-typescript`.
Reads JSON schema files from OpenSpace's `support/types/` directory and compiles them to TypeScript using the npm library `json-schema-to-typescript`.

**Prerequisites:**

Expand All @@ -102,8 +102,7 @@ npm run generate-topic-types -- "<path-to-openspace>/support/types"

This writes the generated files into `src/types/generated/` and rebuilds the `AllTopics` union type used throughout the API.


### Lua library types (`generate-lua-library`)
### Generate Lua library types (`generate-lua-library`)

Connects to a running OpenSpace instance, fetches the full Lua API documentation via the `documentation` topic, and generates `src/types/generated/openspacelualibrary.ts`.

Expand All @@ -124,6 +123,10 @@ Connects to a running OpenSpace instance, fetches the full Lua API documentation
npm run generate-lua-library
```

This installs the Python dependencies (via `pip install -r script/requirements.txt`) and runs `script/generatetypescriptfile.py`, writing the result to `src/types/generated/openspacelualibrary.ts`.
This installs the Python dependencies (via `pip install -r script/requirements.txt`) and runs the script `script/generatetypescriptfile.py`, writing the result to `src/types/generated/openspacelualibrary.ts`.

> **Note:** The generated file is specific to the OpenSpace version that was running when the script executed. Type hints may be inaccurate if your runtime version differs from the version used to generate them.

## Adding a new OpenSpace Topic

Adding a new Topic involves engine-side registration as well as regenerating, testing, and publishing the types above as a `-dev` prerelease before promoting them to a stable release. See [Creating a new OpenSpace Topic](https://docs.openspaceproject.com/latest/contribute/development/api/creating-a-new-topic.html) in the documentation for the full workflow.
5 changes: 3 additions & 2 deletions script/generatetopictypes.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ const Style = {
const BannerComment =
'/**\n' +
' * This file was automatically generated by json-schema-to-typescript.\n' +
' * DO NOT MODIFY IT BY HAND. Instead, modify the source JSON Schema file,\n' +
' * and run json-schema-to-typescript to regenerate this file.\n */';
' * DO NOT MODIFY IT BY HAND. Instead, modify the source JSON Schema file, and run\n' +
' * `generate-topic-types` to regenerate this file. See the openspace-api-js repository:\n' +
' * https://github.com/OpenSpace/openspace-api-js#generating-types-from-your-openspace-build\n */';

/**
* Extracts all type names defined in the $defs of a JSON schema file.
Expand Down
2 changes: 2 additions & 0 deletions script/generatetypescriptfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ def writeCustomTypes(file):
file.write("type path = string;\n")
file.write("type table = object;\n")
file.write("type action = object;\n")
file.write("type trail = object;\n")
file.write("type position = object;\n")
file.write("type custompropertytype = any;\n")
file.write("type integer = number;\n")
file.write("type vec2 = [number, number];\n")
Expand Down
6 changes: 4 additions & 2 deletions src/types/generated/actionkeybindtopic.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/**
* This file was automatically generated by json-schema-to-typescript.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSON Schema file,
* and run json-schema-to-typescript to regenerate this file.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSON Schema file, and run
* `generate-topic-types` to regenerate this file. See the openspace-api-js repository:
* https://github.com/OpenSpace/openspace-api-js#generating-types-from-your-openspace-build
*/

export interface ActionKeybindTopic {
Expand Down Expand Up @@ -34,6 +35,7 @@ export interface Action {
documentation: string;
guiPath: string;
identifier: string;
isHidden?: boolean;
isLocal: boolean;
name: string;
}
Expand Down
30 changes: 30 additions & 0 deletions src/types/generated/assettreetopic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* This file was automatically generated by json-schema-to-typescript.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSON Schema file, and run
* `generate-topic-types` to regenerate this file. See the openspace-api-js repository:
* https://github.com/OpenSpace/openspace-api-js#generating-types-from-your-openspace-build
*/

export interface AssetTreeTopic {
data: PathList | StateSnapshot | AssetState;
topicId: 'assetTree';
topicPayload: {
event: 'start_subscription' | 'stop_subscription' | 'scan_assets';
};
}
export interface PathList {
category: 'shipped' | 'user' | 'other' | 'rootAssets';
paths: string[];
type: 'pathList';
}
export interface StateSnapshot {
states: {
[k: string]: 'Loaded' | 'Loading' | 'Unloaded' | 'Error';
};
type: 'stateSnapshot';
}
export interface AssetState {
path: string;
state: 'Loaded' | 'Loading' | 'Unloaded' | 'Error';
type: 'state';
}
5 changes: 3 additions & 2 deletions src/types/generated/authorizationtopic.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/**
* This file was automatically generated by json-schema-to-typescript.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSON Schema file,
* and run json-schema-to-typescript to regenerate this file.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSON Schema file, and run
* `generate-topic-types` to regenerate this file. See the openspace-api-js repository:
* https://github.com/OpenSpace/openspace-api-js#generating-types-from-your-openspace-build
*/

export interface AuthorizationTopic {
Expand Down
5 changes: 3 additions & 2 deletions src/types/generated/camerapathtopic.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/**
* This file was automatically generated by json-schema-to-typescript.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSON Schema file,
* and run json-schema-to-typescript to regenerate this file.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSON Schema file, and run
* `generate-topic-types` to regenerate this file. See the openspace-api-js repository:
* https://github.com/OpenSpace/openspace-api-js#generating-types-from-your-openspace-build
*/

export interface CameraPathTopic {
Expand Down
5 changes: 3 additions & 2 deletions src/types/generated/cameratopic.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/**
* This file was automatically generated by json-schema-to-typescript.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSON Schema file,
* and run json-schema-to-typescript to regenerate this file.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSON Schema file, and run
* `generate-topic-types` to regenerate this file. See the openspace-api-js repository:
* https://github.com/OpenSpace/openspace-api-js#generating-types-from-your-openspace-build
*/

export interface CameraTopic {
Expand Down
5 changes: 3 additions & 2 deletions src/types/generated/documentationtopic.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/**
* This file was automatically generated by json-schema-to-typescript.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSON Schema file,
* and run json-schema-to-typescript to regenerate this file.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSON Schema file, and run
* `generate-topic-types` to regenerate this file. See the openspace-api-js repository:
* https://github.com/OpenSpace/openspace-api-js#generating-types-from-your-openspace-build
*/

export interface DocumentationTopic {
Expand Down
5 changes: 3 additions & 2 deletions src/types/generated/downloadeventtopic.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/**
* This file was automatically generated by json-schema-to-typescript.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSON Schema file,
* and run json-schema-to-typescript to regenerate this file.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSON Schema file, and run
* `generate-topic-types` to regenerate this file. See the openspace-api-js repository:
* https://github.com/OpenSpace/openspace-api-js#generating-types-from-your-openspace-build
*/

export interface DownloadEventTopic {
Expand Down
5 changes: 3 additions & 2 deletions src/types/generated/enginemodetopic.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/**
* This file was automatically generated by json-schema-to-typescript.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSON Schema file,
* and run json-schema-to-typescript to regenerate this file.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSON Schema file, and run
* `generate-topic-types` to regenerate this file. See the openspace-api-js repository:
* https://github.com/OpenSpace/openspace-api-js#generating-types-from-your-openspace-build
*/

export interface EngineModeTopic {
Expand Down
5 changes: 3 additions & 2 deletions src/types/generated/errorlogtopic.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/**
* This file was automatically generated by json-schema-to-typescript.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSON Schema file,
* and run json-schema-to-typescript to regenerate this file.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSON Schema file, and run
* `generate-topic-types` to regenerate this file. See the openspace-api-js repository:
* https://github.com/OpenSpace/openspace-api-js#generating-types-from-your-openspace-build
*/

export interface ErrorLogTopic {
Expand Down
13 changes: 7 additions & 6 deletions src/types/generated/eventtopic.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/**
* This file was automatically generated by json-schema-to-typescript.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSON Schema file,
* and run json-schema-to-typescript to regenerate this file.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSON Schema file, and run
* `generate-topic-types` to regenerate this file. See the openspace-api-js repository:
* https://github.com/OpenSpace/openspace-api-js#generating-types-from-your-openspace-build
*/

export type EventData =
Expand All @@ -20,7 +21,7 @@ export type EventData =
| MissionAddedEventData
| MissionEventReachedEventData
| MissionRemovedEventData
| ParallelConnectionEventData
| AstrocastConnectionEventData
| PlanetEclipsedEventData
| PointSpacecraftEventData
| ProfileLoadingFinishedEventData
Expand Down Expand Up @@ -48,7 +49,7 @@ export type EventType =
| 'MissionAdded'
| 'MissionEventReached'
| 'MissionRemoved'
| 'ParallelConnection'
| 'AstrocastConnection'
| 'PlanetEclipsed'
| 'PointSpacecraft'
| 'ProfileLoadingFinished'
Expand Down Expand Up @@ -136,9 +137,9 @@ export interface MissionRemovedEventData {
Identifier: string;
event: 'MissionRemoved';
}
export interface ParallelConnectionEventData {
export interface AstrocastConnectionEventData {
State: 'Established' | 'Lost' | 'HostshipGained' | 'HostshipLost';
event: 'ParallelConnection';
event: 'AstrocastConnection';
}
export interface PlanetEclipsedEventData {
Eclipsee: string;
Expand Down
5 changes: 3 additions & 2 deletions src/types/generated/flightcontrollertopic.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/**
* This file was automatically generated by json-schema-to-typescript.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSON Schema file,
* and run json-schema-to-typescript to regenerate this file.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSON Schema file, and run
* `generate-topic-types` to regenerate this file. See the openspace-api-js repository:
* https://github.com/OpenSpace/openspace-api-js#generating-types-from-your-openspace-build
*/

export type FlightControllerCommand =
Expand Down
5 changes: 3 additions & 2 deletions src/types/generated/getpropertytopic.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/**
* This file was automatically generated by json-schema-to-typescript.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSON Schema file,
* and run json-schema-to-typescript to regenerate this file.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSON Schema file, and run
* `generate-topic-types` to regenerate this file. See the openspace-api-js repository:
* https://github.com/OpenSpace/openspace-api-js#generating-types-from-your-openspace-build
*/

import type { BoolProperty, DMat2Property, DMat3Property, DMat4Property, DVec2Property, DVec3Property, DVec4Property, DoubleListProperty, DoubleProperty, FloatProperty, IVec2Property, IVec3Property, IVec4Property, IntListProperty, IntProperty, LongProperty, Mat2Property, Mat3Property, Mat4Property, OptionProperty, PropertyOwner, SelectionProperty, ShortProperty, StringListProperty, StringProperty, TriggerProperty, UIntProperty, ULongProperty, UShortProperty, UVec2Property, UVec3Property, UVec4Property, Vec2Property, Vec3Property, Vec4Property } from './properties';
Expand Down
3 changes: 3 additions & 0 deletions src/types/generated/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
export * from './properties';
export * from './openspacelualibrary';
export * from './actionkeybindtopic';
export * from './assettreetopic';
export * from './authorizationtopic';
export * from './camerapathtopic';
export * from './cameratopic';
Expand All @@ -26,6 +27,7 @@ export * from './triggerpropertytopic';
export * from './versiontopic';

import { ActionKeybindTopic } from './actionkeybindtopic';
import { AssetTreeTopic } from './assettreetopic';
import { AuthorizationTopic } from './authorizationtopic';
import { CameraPathTopic } from './camerapathtopic';
import { CameraTopic } from './cameratopic';
Expand All @@ -50,6 +52,7 @@ import { VersionTopic } from './versiontopic';

export type AllTopics =
| ActionKeybindTopic
| AssetTreeTopic
| AuthorizationTopic
| CameraPathTopic
| CameraTopic
Expand Down
5 changes: 3 additions & 2 deletions src/types/generated/luascripttopic.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/**
* This file was automatically generated by json-schema-to-typescript.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSON Schema file,
* and run json-schema-to-typescript to regenerate this file.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSON Schema file, and run
* `generate-topic-types` to regenerate this file. See the openspace-api-js repository:
* https://github.com/OpenSpace/openspace-api-js#generating-types-from-your-openspace-build
*/

export interface LuaScriptTopic {
Expand Down
5 changes: 3 additions & 2 deletions src/types/generated/missiontopic.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/**
* This file was automatically generated by json-schema-to-typescript.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSON Schema file,
* and run json-schema-to-typescript to regenerate this file.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSON Schema file, and run
* `generate-topic-types` to regenerate this file. See the openspace-api-js repository:
* https://github.com/OpenSpace/openspace-api-js#generating-types-from-your-openspace-build
*/

export interface MissionTopic {
Expand Down
Loading