From d668eac4a63a9aa98c3efff395faa23cfcea1c1b Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Thu, 21 Mar 2024 17:08:37 +0100 Subject: [node] begin the great typescript rewrite --- nodejs/model/agent.ts | 8 +++++++ nodejs/model/api.ts | 32 +++++++++++++++++++++++++++ nodejs/model/cargo.ts | 17 +++++++++++++++ nodejs/model/contract.ts | 22 +++++++++++++++++++ nodejs/model/ship.ts | 56 ++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 135 insertions(+) create mode 100644 nodejs/model/agent.ts create mode 100644 nodejs/model/api.ts create mode 100644 nodejs/model/cargo.ts create mode 100644 nodejs/model/contract.ts create mode 100644 nodejs/model/ship.ts (limited to 'nodejs/model') diff --git a/nodejs/model/agent.ts b/nodejs/model/agent.ts new file mode 100644 index 0000000..dce6424 --- /dev/null +++ b/nodejs/model/agent.ts @@ -0,0 +1,8 @@ +export type Agent = { + accountId: string; + credits: number; + headquarters: string; + shipCount: number; + startingFaction: string; + symbol: string; +}; diff --git a/nodejs/model/api.ts b/nodejs/model/api.ts new file mode 100644 index 0000000..5092157 --- /dev/null +++ b/nodejs/model/api.ts @@ -0,0 +1,32 @@ +export type APIError = { + apiError: 'APIError'; + error: string; + code: number; + data: any; // TODO +}; + +export type Meta = { + limit: number; + page: number; + total: number; +} + +export type Request = { + endpoint: string; // the path part of the url to call + method?: string; // HTTP method for `fetch` call, defaults to 'GET' + page?: number; // run a paginated request starting from this page until all the following pages are fetched + payload?: { [key:string]: any}; // optional json object that will be sent along the request + priority?: number; // optional priority value, defaults to 10. lower than 10 means the message will be sent faster +}; + +export type RequestPromise = { + reject: (reason?: any) => void; + request: Request; + resolve: (value: Response | PromiseLike>) => void; +}; + +export type Response = { + data: T; + error?: APIError; + meta?: Meta; +} diff --git a/nodejs/model/cargo.ts b/nodejs/model/cargo.ts new file mode 100644 index 0000000..869fa49 --- /dev/null +++ b/nodejs/model/cargo.ts @@ -0,0 +1,17 @@ +export type Inventory = { + description: string; + name: string; + symbol: string; + units: number; +}; + +export type Cargo = { + "capacity": number; + "units": number; + "inventory": Array; +}; + +// Custom type, not from space traders api +export type CargoManifest = { + [key: string]: number; +}; diff --git a/nodejs/model/contract.ts b/nodejs/model/contract.ts new file mode 100644 index 0000000..eb7add4 --- /dev/null +++ b/nodejs/model/contract.ts @@ -0,0 +1,22 @@ +export type Contract = { + id: string; + factionSymbol: string; + type: string; + terms: { + deadline: Date; + payment: { + onAccepted: number; + onFulfilled: number; + }, + deliver: Array<{ + tradeSymbol: string; + destinationSymbol: string; + unitsRequired: number; + unitsFulfilled: number; + }>; + }; + accepted: boolean; + fulfilled: boolean; + expiration: Date; + deadlineToAccept: Date; +}; diff --git a/nodejs/model/ship.ts b/nodejs/model/ship.ts new file mode 100644 index 0000000..9aaf601 --- /dev/null +++ b/nodejs/model/ship.ts @@ -0,0 +1,56 @@ +import { Cargo } from './cargo.ts'; + +export type Cooldown = { + shipSymbol: string; + totalSeconds: number; + remainingSeconds: number; +}; + +export type Consummed = { + amount: number; + timestamp: Date; +}; + +export type Fuel = { + capacity: number; + consummed: Consummed; + current: number; +}; + +export type Nav = { + flightMode: string; + route: Route; + status: string; + systemSymbol: string; + waypointSymbol: string; +}; + +export type Route = { + arrival: Date; + departureTime: Date; + destination: RouteEndpoint; + origin: RouteEndpoint; +}; + +export type RouteEndpoint = { + type: string; + symbol: string; + systemSymbol: string; + x: number; + y: number; +}; + +export type Ship = { + cargo: Cargo; + cooldown: Cooldown; + // crew + // engine + // frame + fuel: Fuel; + // modules + // mounts + nav: Nav; + // reactor + // registration + symbol: string; +}; -- cgit v1.2.3