1
0
Fork 0

[node] begin the great typescript rewrite

This commit is contained in:
Julien Dessaux 2024-03-21 17:08:37 +01:00
parent 3b61a9694d
commit d668eac4a6
Signed by: adyxax
GPG key ID: F92E51B86E07177E
31 changed files with 879 additions and 666 deletions

8
nodejs/model/agent.ts Normal file
View file

@ -0,0 +1,8 @@
export type Agent = {
accountId: string;
credits: number;
headquarters: string;
shipCount: number;
startingFaction: string;
symbol: string;
};

32
nodejs/model/api.ts Normal file
View file

@ -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<T> = {
reject: (reason?: any) => void;
request: Request;
resolve: (value: Response<T> | PromiseLike<Response<T>>) => void;
};
export type Response<T> = {
data: T;
error?: APIError;
meta?: Meta;
}

17
nodejs/model/cargo.ts Normal file
View file

@ -0,0 +1,17 @@
export type Inventory = {
description: string;
name: string;
symbol: string;
units: number;
};
export type Cargo = {
"capacity": number;
"units": number;
"inventory": Array<Inventory>;
};
// Custom type, not from space traders api
export type CargoManifest = {
[key: string]: number;
};

22
nodejs/model/contract.ts Normal file
View file

@ -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;
};

56
nodejs/model/ship.ts Normal file
View file

@ -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;
};