@kayahr/edsm 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/LICENSE.md +22 -0
  2. package/README.md +168 -0
  3. package/lib/body.schema.json +587 -0
  4. package/lib/codex.schema.json +55 -0
  5. package/lib/commander-credits-response.schema.json +52 -0
  6. package/lib/commander-inventory-response.schema.json +91 -0
  7. package/lib/commander-position-response.schema.json +101 -0
  8. package/lib/commander-ranks-response.schema.json +138 -0
  9. package/lib/elite-server-status-response.schema.json +38 -0
  10. package/lib/flight-logs-response.schema.json +68 -0
  11. package/lib/main/api/commander.d.ts +96 -0
  12. package/lib/main/api/commander.js +38 -0
  13. package/lib/main/api/commander.js.map +1 -0
  14. package/lib/main/api/common.d.ts +28 -0
  15. package/lib/main/api/common.js +54 -0
  16. package/lib/main/api/common.js.map +1 -0
  17. package/lib/main/api/journal.d.ts +51 -0
  18. package/lib/main/api/journal.js +35 -0
  19. package/lib/main/api/journal.js.map +1 -0
  20. package/lib/main/api/logs.d.ts +130 -0
  21. package/lib/main/api/logs.js +60 -0
  22. package/lib/main/api/logs.js.map +1 -0
  23. package/lib/main/api/status.d.ts +13 -0
  24. package/lib/main/api/status.js +14 -0
  25. package/lib/main/api/status.js.map +1 -0
  26. package/lib/main/api/system.d.ts +279 -0
  27. package/lib/main/api/system.js +125 -0
  28. package/lib/main/api/system.js.map +1 -0
  29. package/lib/main/api/systems.d.ts +148 -0
  30. package/lib/main/api/systems.js +51 -0
  31. package/lib/main/api/systems.js.map +1 -0
  32. package/lib/main/bodies.d.ts +116 -0
  33. package/lib/main/bodies.js +33 -0
  34. package/lib/main/bodies.js.map +1 -0
  35. package/lib/main/codex.d.ts +20 -0
  36. package/lib/main/codex.js +15 -0
  37. package/lib/main/codex.js.map +1 -0
  38. package/lib/main/common.d.ts +14 -0
  39. package/lib/main/common.js +20 -0
  40. package/lib/main/common.js.map +1 -0
  41. package/lib/main/index.d.ts +14 -0
  42. package/lib/main/index.js +19 -0
  43. package/lib/main/index.js.map +1 -0
  44. package/lib/main/powerplay.d.ts +23 -0
  45. package/lib/main/powerplay.js +15 -0
  46. package/lib/main/powerplay.js.map +1 -0
  47. package/lib/main/stations.d.ts +69 -0
  48. package/lib/main/stations.js +15 -0
  49. package/lib/main/stations.js.map +1 -0
  50. package/lib/main/systems.d.ts +61 -0
  51. package/lib/main/systems.js +15 -0
  52. package/lib/main/systems.js.map +1 -0
  53. package/lib/main/util.d.ts +38 -0
  54. package/lib/main/util.js +104 -0
  55. package/lib/main/util.js.map +1 -0
  56. package/lib/powerplay.schema.json +90 -0
  57. package/lib/station-market-response.schema.json +95 -0
  58. package/lib/station-outfitting-response.schema.json +75 -0
  59. package/lib/station-shipyard-response.schema.json +72 -0
  60. package/lib/station.schema.json +315 -0
  61. package/lib/system-bodies-response.schema.json +609 -0
  62. package/lib/system-deaths-response.schema.json +58 -0
  63. package/lib/system-estimated-value-response.schema.json +76 -0
  64. package/lib/system-factions-response.schema.json +313 -0
  65. package/lib/system-response.schema.json +137 -0
  66. package/lib/system-stations-response.schema.json +222 -0
  67. package/lib/system-traffic-response.schema.json +85 -0
  68. package/lib/system.schema.json +1016 -0
  69. package/package.json +82 -0
  70. package/src/main/api/commander.ts +116 -0
  71. package/src/main/api/common.ts +77 -0
  72. package/src/main/api/journal.ts +76 -0
  73. package/src/main/api/logs.ts +166 -0
  74. package/src/main/api/status.ts +24 -0
  75. package/src/main/api/system.ts +361 -0
  76. package/src/main/api/systems.ts +199 -0
  77. package/src/main/bodies.ts +153 -0
  78. package/src/main/codex.ts +31 -0
  79. package/src/main/common.ts +29 -0
  80. package/src/main/index.ts +42 -0
  81. package/src/main/powerplay.ts +34 -0
  82. package/src/main/stations.ts +87 -0
  83. package/src/main/systems.ts +77 -0
  84. package/src/main/util.ts +103 -0
@@ -0,0 +1,361 @@
1
+ /*
2
+ * Copyright (C) 2020 Klaus Reimer <k@ailis.de>
3
+ * See LICENSE.md for licensing information.
4
+ */
5
+
6
+ import type { SystemBody } from "../bodies.ts";
7
+ import type { Id64 } from "../common.ts";
8
+ import type { Commodity, Outfitting, Ship, SystemStation } from "../stations.ts";
9
+ import { NotFoundException } from "../util.ts";
10
+ import { type SystemIdRequestOptions, request } from "./common.ts";
11
+
12
+ export interface BodyScanValue {
13
+ bodyId: number;
14
+ bodyName: string;
15
+ distance: number;
16
+ valueMax: number;
17
+ }
18
+
19
+ /**
20
+ * Response structure of the EDSM system bodies request.
21
+ */
22
+ export interface SystemBodiesResponse {
23
+ id: number;
24
+ id64: Id64;
25
+ name: string;
26
+ url: string;
27
+ bodies: SystemBody[];
28
+ bodyCount: number;
29
+ }
30
+
31
+ /**
32
+ * Response structure of the EDSM system estimated value request.
33
+ */
34
+ export interface SystemEstimatedValueResponse {
35
+ id: number;
36
+ id64: Id64;
37
+ name: string;
38
+ url: string;
39
+ estimatedValue: number;
40
+ estimatedValueMapped: number;
41
+ valuableBodies: BodyScanValue[];
42
+ }
43
+
44
+ /**
45
+ * Response structure of the EDSM system stations request.
46
+ */
47
+ export interface SystemStationsResponse {
48
+ id: number;
49
+ id64: Id64;
50
+ name: string;
51
+ url: string;
52
+ stations: SystemStation[];
53
+ }
54
+
55
+ /**
56
+ * Response structure of the EDSM system stations market request.
57
+ */
58
+ export interface StationMarketResponse {
59
+ id: number;
60
+ id64: Id64;
61
+ name: string;
62
+ marketId: number;
63
+ sId: number;
64
+ sName: string;
65
+ url: string;
66
+ commodities: Commodity[];
67
+ }
68
+
69
+ /**
70
+ * Response structure of the EDSM system stations shipyard request.
71
+ */
72
+ export interface StationShipyardResponse {
73
+ id: number;
74
+ id64: Id64;
75
+ name: string;
76
+ marketId: number;
77
+ sId: number;
78
+ sName: string;
79
+ url: string;
80
+ ships: Ship[];
81
+ }
82
+
83
+ /**
84
+ * Response structure of the EDSM system stations outfitting request.
85
+ */
86
+ export interface StationOutfittingResponse {
87
+ id: number;
88
+ id64: Id64;
89
+ name: string;
90
+ marketId: number;
91
+ sId: number;
92
+ sName: string;
93
+ url: string;
94
+ outfitting: Outfitting[];
95
+ }
96
+
97
+ /**
98
+ * Returns the system bodies of the given star system.
99
+ *
100
+ * @param systemName - The system name.
101
+ * @param ids - Optional system IDs if you seek for a duplicate system and want to force a specific ID.
102
+ * @returns The bodies found on EDSM.
103
+ * @throws NotFoundException - When system was not found.
104
+ */
105
+ export async function getSystemBodies(systemName: string, ids?: { systemId?: number, systemId64?: Id64 }): Promise<SystemBodiesResponse> {
106
+ const response = await request<SystemBodiesResponse>("api-system-v1/bodies", { systemName, ...ids });
107
+ if (response == null) {
108
+ throw new NotFoundException(`System not found: ${systemName}`);
109
+ }
110
+ return response;
111
+ }
112
+
113
+ /**
114
+ * Returns the estimated scan values of a system.
115
+ *
116
+ * @param systemName - The system name.
117
+ * @param ids - Optional parameters.
118
+ * @returns The scan values.
119
+ * @throws NotFoundException - When system was not found.
120
+ */
121
+ export async function getSystemEstimatedValue(systemName: string, ids?: SystemIdRequestOptions): Promise<SystemEstimatedValueResponse> {
122
+ const response = await request<SystemEstimatedValueResponse>("api-system-v1/estimated-value", { systemName, ...ids });
123
+ if (response == null) {
124
+ throw new NotFoundException(`System not found: ${systemName}`);
125
+ }
126
+ return response;
127
+ }
128
+
129
+ /**
130
+ * Returns information about stations in a system.
131
+ *
132
+ * @param systemName - The system name.
133
+ * @param ids - Optional parameters.
134
+ * @returns The information about stations in a system.
135
+ * @throws NotFoundException - When system was not found.
136
+ */
137
+ export async function getSystemStations(systemName: string, ids?: SystemIdRequestOptions): Promise<SystemStationsResponse> {
138
+ const response = await request<SystemStationsResponse>("api-system-v1/stations", { systemName, ...ids });
139
+ if (response == null) {
140
+ throw new NotFoundException(`System not found: ${systemName}`);
141
+ }
142
+ return response;
143
+ }
144
+
145
+ async function getStationDetails<T>(detail: string, marketIdOrSystemName: number | string, stationName?: string, params?: SystemIdRequestOptions): Promise<T> {
146
+ const url = `api-system-v1/stations/${detail}`;
147
+ let data: T | null;
148
+ if (stationName == null) {
149
+ const marketId = marketIdOrSystemName;
150
+ data = await request<T>(url, { marketId });
151
+ if (data == null) {
152
+ throw new NotFoundException(`Market not found: ${marketId}`);
153
+ }
154
+ } else {
155
+ const systemName = marketIdOrSystemName;
156
+ data = await request<T>(url, { systemName, stationName, ...params });
157
+ if (data == null) {
158
+ throw new NotFoundException(`Station '${stationName}' in '${systemName}' not found`);
159
+ }
160
+ }
161
+ return data;
162
+ }
163
+
164
+ /**
165
+ * Returns information about market in a station.
166
+ *
167
+ * @param marketId - The market ID.
168
+ * @returns The information about market in given station.
169
+ * @throws NotFoundException - When market was not found.
170
+ */
171
+ export async function getStationMarket(marketId: number): Promise<StationMarketResponse>;
172
+
173
+ /**
174
+ * Returns information about market in a station.
175
+ *
176
+ * @param systemName - The system name.
177
+ * @param stationName - The station name.
178
+ * @param params - Optional parameters.
179
+ * @returns The information about market in given station.
180
+ * @throws NotFoundException - When market was not found.
181
+ */
182
+ export async function getStationMarket(systemName: string, stationName: string, params?: SystemIdRequestOptions): Promise<StationMarketResponse>;
183
+
184
+ export async function getStationMarket(marketIdOrSystemName: number | string, stationName?: string, params?: SystemIdRequestOptions):
185
+ Promise<StationMarketResponse> {
186
+ return getStationDetails<StationMarketResponse>("market", marketIdOrSystemName, stationName, params);
187
+ }
188
+
189
+ /**
190
+ * Returns information about shipyard in a station.
191
+ *
192
+ * @param marketId - The market ID.
193
+ * @returns The information about shipyard in given station.
194
+ * @throws NotFoundException - When shipyard was not found.
195
+ */
196
+ export async function getStationShipyard(marketId: number): Promise<StationShipyardResponse>;
197
+
198
+ /**
199
+ * Returns information about shipyard in a station.
200
+ *
201
+ * @param systemName - The system name.
202
+ * @param stationName - The station name.
203
+ * @param params - Optional parameters.
204
+ * @returns The information about shipyard in given station.
205
+ * @throws NotFoundException - When shipyard was not found.
206
+ */
207
+ export async function getStationShipyard(systemName: string, stationName: string, params?: SystemIdRequestOptions): Promise<StationShipyardResponse>;
208
+
209
+ export async function getStationShipyard(marketIdOrSystemName: number | string, stationName?: string, params?: SystemIdRequestOptions):
210
+ Promise<StationShipyardResponse> {
211
+ return getStationDetails<StationShipyardResponse>("shipyard", marketIdOrSystemName, stationName, params);
212
+ }
213
+
214
+ /**
215
+ * Returns information about outfitting in a station.
216
+ *
217
+ * @param marketId - The market ID.
218
+ * @returns The information about outfitting in given station.
219
+ * @throws NotFoundException - When station was not found.
220
+ */
221
+ export async function getStationOutfitting(marketId: number): Promise<StationOutfittingResponse>;
222
+
223
+ /**
224
+ * Returns information about outfitting in a station.
225
+ *
226
+ * @param systemName - The system name.
227
+ * @param stationName - The station name.
228
+ * @param params - Optional parameters.
229
+ * @returns The information about outfitting in given station.
230
+ * @throws NotFoundException - When station was not found.
231
+ */
232
+ export async function getStationOutfitting(systemName: string, stationName: string, params?: SystemIdRequestOptions): Promise<StationOutfittingResponse>;
233
+
234
+ export async function getStationOutfitting(marketIdOrSystemName: number | string, stationName?: string, params?: SystemIdRequestOptions):
235
+ Promise<StationOutfittingResponse> {
236
+ return getStationDetails<StationOutfittingResponse>("outfitting", marketIdOrSystemName, stationName, params);
237
+ }
238
+
239
+ export interface SystemFactionsOptions extends SystemIdRequestOptions {
240
+ /** Set to 1 to get the factions history under the requested system. */
241
+ showHistory?: number;
242
+ }
243
+
244
+ export interface ShortSystemFaction {
245
+ id: number;
246
+ name: string;
247
+ allegiance: string;
248
+ government: string;
249
+ }
250
+
251
+ export interface SystemFaction extends ShortSystemFaction {
252
+ influence: number;
253
+ influenceHistory?: Record<string, number> | [];
254
+ state: string;
255
+ stateHistory?: Record<string, string> | [];
256
+ activeStates: Array<{ state: string }>;
257
+ activeStatesHistory?: Record<string, Array<{ state: string }>> | [];
258
+ recoveringStates: Array<{ state: string, trend?: number }>;
259
+ recoveringStatesHistory?: Record<string, Array<{ state: string, trend?: number }>> | [];
260
+ pendingStates: Array<{ state: string, trend?: number }>;
261
+ pendingStatesHistory?: Record<string, Array<{ state: string, trend?: number }>> | [];
262
+ happiness: string;
263
+ happinessHistory?: Record<string, string> | [];
264
+ isPlayer: boolean;
265
+ lastUpdate: number;
266
+ }
267
+
268
+ /**
269
+ * Response structure of the EDSM system factions request.
270
+ */
271
+ export interface SystemFactionsResponse {
272
+ id: number;
273
+ id64: Id64;
274
+ name: string;
275
+ url: string;
276
+ controllingFaction?: ShortSystemFaction;
277
+ factions: SystemFaction[];
278
+ }
279
+
280
+ /**
281
+ * Returns information about factions in a system.
282
+ *
283
+ * @param systemName - The system name.
284
+ * @param options - Optional parameters.
285
+ * @returns The information about stations in a system.
286
+ * @throws NotFoundException - When system was not found.
287
+ */
288
+ export async function getSystemFactions(systemName: string, options?: SystemFactionsOptions): Promise<SystemFactionsResponse> {
289
+ const response = await request<SystemFactionsResponse>("api-system-v1/factions", { systemName, ...options });
290
+ if (response == null) {
291
+ throw new NotFoundException(`System not found: ${systemName}`);
292
+ }
293
+ return response;
294
+ }
295
+
296
+ /**
297
+ * Response structure of the EDSM system traffic request.
298
+ */
299
+ export interface SystemTrafficResponse {
300
+ id: number;
301
+ id64: Id64;
302
+ name: string;
303
+ url: string;
304
+ discovery: {
305
+ commander: string;
306
+ date: string;
307
+ };
308
+ traffic: {
309
+ total: number;
310
+ week: number;
311
+ day: number;
312
+ };
313
+ breakdown: Record<string, number>;
314
+ }
315
+
316
+ /**
317
+ * Returns information about traffic in a system.
318
+ *
319
+ * @param systemName - The system name.
320
+ * @param ids - Optional parameters.
321
+ * @returns The information about traffic in a system.
322
+ * @throws NotFoundException - When system was not found.
323
+ */
324
+ export async function getSystemTraffic(systemName: string, ids?: SystemIdRequestOptions): Promise<SystemTrafficResponse> {
325
+ const response = await request<SystemTrafficResponse>("api-system-v1/traffic", { systemName, ...ids });
326
+ if (response == null) {
327
+ throw new NotFoundException(`System not found: ${systemName}`);
328
+ }
329
+ return response;
330
+ }
331
+
332
+ /**
333
+ * Response structure of the EDSM system deaths request.
334
+ */
335
+ export interface SystemDeathsResponse {
336
+ id: number;
337
+ id64: Id64;
338
+ name: string;
339
+ url: string;
340
+ deaths: {
341
+ total: number;
342
+ week: number;
343
+ day: number;
344
+ };
345
+ }
346
+
347
+ /**
348
+ * Returns information about deaths in a system.
349
+ *
350
+ * @param systemName - The system name.
351
+ * @param ids - Optional parameters.
352
+ * @returns The information about deaths in a system.
353
+ * @throws NotFoundException - When system was not found.
354
+ */
355
+ export async function getSystemDeaths(systemName: string, ids?: SystemIdRequestOptions): Promise<SystemDeathsResponse> {
356
+ const response = await request<SystemDeathsResponse>("api-system-v1/deaths", { systemName, ...ids });
357
+ if (response == null) {
358
+ throw new NotFoundException(`System not found: ${systemName}`);
359
+ }
360
+ return response;
361
+ }
@@ -0,0 +1,199 @@
1
+ /*
2
+ * Copyright (C) 2025 Klaus Reimer <k@ailis.de>
3
+ * See LICENSE.md for licensing information.
4
+ */
5
+
6
+ import type { Coordinates, Id64 } from "../common.ts";
7
+ import { NotFoundException } from "../util.ts";
8
+ import { type SystemIdRequestOptions, request } from "./common.ts";
9
+
10
+ /**
11
+ * Response of a {@link getSystem} request.
12
+ */
13
+ export interface SystemResponse {
14
+ /** The name of the system. */
15
+ name: string;
16
+
17
+ /** The EDSM ID of the system. Only present when {@link SystemRequestOptions#showId} option is set to 1. */
18
+ id?: number;
19
+
20
+ /** The Frontier ID of the system. Only present when {@link SystemRequestOptions#showId} option is set to 1. */
21
+ id64?: Id64;
22
+
23
+ /**
24
+ * The systems ID having the exact same name in the game. Only present when there are duplicated and
25
+ * {@link SystemRequestOptions#showId} option is set to 1.
26
+ */
27
+ duplicates?: number[];
28
+
29
+ /** The coordinates of the system. Only present when {@link SystemRequestOptions#showCoordinates} option is set to 1. */
30
+ coords?: {
31
+ x: number;
32
+ y: number;
33
+ z: number;
34
+ };
35
+
36
+ /**
37
+ * True when exact coords are known. False when position is trilaterated. Only present when {@link SystemRequestOptions#showCoordinates}
38
+ * option is set to 1
39
+ */
40
+ coordsLocked?: boolean;
41
+
42
+ /** System information. Only present when {@link SystemRequestOptions#showInformation} option is set to 1. */
43
+ information?: {
44
+ allegiance?: string;
45
+ government?: string;
46
+ faction?: string;
47
+ factionState?: string;
48
+ population?: number;
49
+ security?: string;
50
+ economy?: string;
51
+ secondEconomy?: string;
52
+ reserve?: string;
53
+ };
54
+
55
+ /** Permit information. Only present when {@link SystemRequestOptions#showPermit} option is set to 1. */
56
+ requirePermit?: boolean;
57
+
58
+ /** Permit name if any. Only present when {@link SystemRequestOptions#showPermit} option is set to 1. */
59
+ permitName?: string;
60
+
61
+ /** Information about the primary star if any. Only present when {@link SystemRequestOptions#showPrimaryStar} option is set to 1. */
62
+ primaryStar?: {
63
+ type: string;
64
+ name: string;
65
+ isScoopable: boolean;
66
+ };
67
+
68
+ /** The time when the system was hidden. Only present when system is hidden and {@link SystemRequestOptions#includeHidden} is set to 1 */
69
+ hidden_at?: string;
70
+
71
+ /**
72
+ * The system ID this system was merged to. Only present when system was merged and, {@link SystemRequestOptions#includeHidden} is set to 1
73
+ * and {@link SystemRequestOptions#showId} is also set to 1.
74
+ */
75
+ mergedTo?: number;
76
+ }
77
+
78
+ /**
79
+ * Flags for enabling data in {@link SystemResponse}.
80
+ */
81
+ export interface SystemRequestFlags {
82
+ /** Set to 1 to get our internal ID for this system. */
83
+ showId?: number;
84
+
85
+ /** Set to 1 to get the system coordinates. If coordinates are unknown, the coords key will not be returned. */
86
+ showCoordinates?: number;
87
+
88
+ /** Set to 1 to get the system permit if there is one. If the permit is named, also return permitName. */
89
+ showPermit?: number;
90
+
91
+ /** Set to 1 to get the system information like allegiance, government... If no information are stored, an empty object will be returned. */
92
+ showInformation?: number;
93
+
94
+ /** Set to 1 to get the system primary star if known. If no primary star is stored, null will be returned. */
95
+ showPrimaryStar?: number;
96
+
97
+ /** Set to 1 to get system even if hidden in the database. Hidden system are generally typo errors, renamed system in the game... */
98
+ includeHidden?: number;
99
+ }
100
+
101
+ /**
102
+ * Options for {@link getSystem} request.
103
+ */
104
+ export interface SystemRequestOptions extends SystemIdRequestOptions, SystemRequestFlags {}
105
+
106
+ /**
107
+ * Returns information about the given system.
108
+ *
109
+ * @param systemName - The system name.
110
+ * @returns The system information.
111
+ * @throws NotFoundException - When system was not found.
112
+ */
113
+ export async function getSystem(systemName: string, options?: SystemRequestOptions): Promise<SystemResponse> {
114
+ const system = await request<SystemResponse>("api-v1/system", { systemName, ...options });
115
+ if (system == null) {
116
+ throw new NotFoundException(`System not found: ${systemName}`);
117
+ }
118
+ return system;
119
+ }
120
+
121
+ /**
122
+ * Options for {@link getSystems} request.
123
+ */
124
+ export interface SystemsRequestOptions extends SystemRequestFlags {
125
+ /** The systems name to retrieve, can be a start of a name or an array of specific names. */
126
+ systemName?: string | string[];
127
+
128
+ /**
129
+ * If you only want to receive systems updated after a specific date & time, use this parameter.
130
+ * Parameter is inclusive. All dates must be UTC.
131
+ * Format: YYYY-MM-DD HH:MM:SS.
132
+ */
133
+ startDateTime?: string;
134
+
135
+ /**
136
+ * If you only want to receive systems updated before a specific date & time, use this parameter.
137
+ * Parameter is inclusive. All dates must be UTC.
138
+ * Format: YYYY-MM-DD HH:MM:SS.
139
+ */
140
+ endDateTime?: string;
141
+
142
+ /** Set to 1 to get only systems with known coordinates. */
143
+ onlyKnownCoordinates?: number;
144
+
145
+ /** Set to 1 to get only systems without coordinates. */
146
+ onlyUnknownCoordinates?: number;
147
+ }
148
+
149
+ /**
150
+ * Returns information about multiple systems.
151
+ *
152
+ * @param options - The request options.
153
+ * @returns List of system information. Empty if none.
154
+ */
155
+ export async function getSystems(options?: SystemsRequestOptions): Promise<SystemResponse[]> {
156
+ const system = await request<SystemResponse[]>("api-v1/systems", { ...options });
157
+ return system ?? [];
158
+ }
159
+
160
+ /**
161
+ * Options for {@link getSphereSystems} request.
162
+ */
163
+ export interface SphereSystemsRequestOptions extends SystemRequestFlags, SystemIdRequestOptions {
164
+ /** Desired radius in LY. Defaults to 50, maximum is 100. */
165
+ radius?: number;
166
+
167
+ /** The minimum radius in LY. Must be between 0 and {@link radius}. Defaults to 0. */
168
+ minRadius?: number;
169
+ }
170
+
171
+ /**
172
+ * Returns information about multiple systems in a given sphere.
173
+ *
174
+ * @param options - The request options.
175
+ * @returns List of system information in given sphere. Empty if none.
176
+ */
177
+ export async function getSphereSystems(systemNameOrCoords: string | Coordinates, options?: SphereSystemsRequestOptions): Promise<SystemResponse[]> {
178
+ const center = typeof systemNameOrCoords === "string" ? { systemName: systemNameOrCoords } : systemNameOrCoords;
179
+ return (await request("api-v1/sphere-systems", { ...center, ...options }))!;
180
+ }
181
+
182
+ /**
183
+ * Options for {@link getCubeSystems} request.
184
+ */
185
+ export interface CubeSystemsRequestOptions extends SystemRequestFlags, SystemIdRequestOptions {
186
+ /** Desired cube size in LY. Defaults to 100, maximum is 200. */
187
+ size?: number;
188
+ }
189
+
190
+ /**
191
+ * Returns information about multiple systems in a given cube.
192
+ *
193
+ * @param options - The request options.
194
+ * @returns List of system information in given cube. Empty if none.
195
+ */
196
+ export async function getCubeSystems(systemNameOrCoords: string | Coordinates, options?: CubeSystemsRequestOptions): Promise<SystemResponse[]> {
197
+ const center = typeof systemNameOrCoords === "string" ? { systemName: systemNameOrCoords } : systemNameOrCoords;
198
+ return (await request("api-v1/cube-systems", { ...center, ...options }))!;
199
+ }
@@ -0,0 +1,153 @@
1
+ /*
2
+ * Copyright (C) 2018 Klaus Reimer <k@ailis.de>
3
+ * See LICENSE.md for licensing information.
4
+ */
5
+
6
+ import type { Id64 } from "./common.ts";
7
+ import { parseJSONArray } from "./util.ts";
8
+
9
+ /**
10
+ * EDSM data about asteroid ring/belt.
11
+ */
12
+ export interface Asteroids {
13
+ name: string;
14
+ type: string;
15
+ mass: number;
16
+ innerRadius: number;
17
+ outerRadius: number;
18
+ }
19
+
20
+ /**
21
+ * EDSM data about raw materials on a planet.
22
+ */
23
+ export type Materials = Record<string, number>;
24
+ /**
25
+ * EDSM data about solid composition of a planet.
26
+ */
27
+ export type SolidComposition = Record<string, number>;
28
+
29
+ /**
30
+ * EDSM data about atmosphere composition of a planet.
31
+ */
32
+ export type AtmosphereComposition = Record<string, number>;
33
+
34
+ /**
35
+ * EDSM base body data shared by planets and stars.
36
+ */
37
+ export interface BaseBody {
38
+ id: number;
39
+ id64: Id64 | null;
40
+ bodyId: number | null;
41
+ systemId: number;
42
+ systemId64: Id64;
43
+ systemName: string;
44
+ name: string;
45
+ discovery?: {
46
+ commander: string;
47
+ date: string;
48
+ };
49
+ subType: string;
50
+ parents: null | Array<
51
+ { Star: number } | { Planet: number } | { Null: number }
52
+ >;
53
+ distanceToArrival: number;
54
+ surfaceTemperature: number;
55
+ orbitalPeriod: number | null;
56
+ semiMajorAxis: number | null;
57
+ orbitalEccentricity: number | null;
58
+ orbitalInclination: number | null;
59
+ argOfPeriapsis: number | null;
60
+ rotationalPeriod: number | null;
61
+ rotationalPeriodTidallyLocked: boolean;
62
+ axialTilt: number | null;
63
+ rings?: Asteroids[];
64
+ reserveLevel?: string | null;
65
+ belts?: Asteroids[];
66
+ updateTime: string;
67
+ }
68
+
69
+ /**
70
+ * EDSM star data.
71
+ */
72
+ export interface Star extends BaseBody {
73
+ type: "Star";
74
+ isMainStar?: boolean;
75
+ isScoopable?: boolean;
76
+ age: number;
77
+ spectralClass: string | null;
78
+ luminosity: string | null;
79
+ absoluteMagnitude: number;
80
+ solarMasses: number;
81
+ solarRadius: number;
82
+ surfaceTemperature: number;
83
+ }
84
+
85
+ /**
86
+ * EDSM planet data.
87
+ */
88
+ export interface Planet extends BaseBody {
89
+ type: "Planet";
90
+ isLandable: boolean;
91
+ gravity: number;
92
+ earthMasses: number;
93
+ radius: number;
94
+ surfacePressure: number | null;
95
+ volcanismType: string | null;
96
+ atmosphereType: string | null;
97
+ atmosphereComposition: AtmosphereComposition | null;
98
+ solidComposition: SolidComposition | null;
99
+ terraformingState: string | null;
100
+ materials?: Materials;
101
+ }
102
+
103
+ /**
104
+ * Union type for EDSM star and planet data.
105
+ */
106
+ export type Body = Planet | Star;
107
+
108
+ export type SystemStar = Omit<Star, "systemId" | "systemId64" | "systemName">;
109
+ export type SystemPlanet = Omit<Planet, "systemId" | "systemId64" | "systemName">;
110
+
111
+ /**
112
+ * Body within a system (without system information because its already in the parent object)
113
+ */
114
+ export type SystemBody = SystemStar | SystemPlanet;
115
+
116
+ export function isPlanet(body: Body): body is Planet;
117
+ export function isPlanet(body: SystemBody): body is SystemPlanet;
118
+
119
+ /**
120
+ * Checks if given body is a planet.
121
+ *
122
+ * @param body - The body to check.
123
+ * @returns True if body is a planet.
124
+ */
125
+ export function isPlanet(body: Body | SystemBody): boolean {
126
+ return body.type === "Planet";
127
+ }
128
+
129
+ export function isStar(body: Body): body is Star;
130
+ export function isStar(body: SystemBody): body is SystemStar;
131
+
132
+ /**
133
+ * Checks if given body is a planet.
134
+ *
135
+ * @param body - The body to check.
136
+ * @returns True if body is a star.
137
+ */
138
+ export function isStar(body: Body | SystemBody): boolean {
139
+ return body.type === "Star";
140
+ }
141
+
142
+ /** List of EDSM bodies. */
143
+ export type Bodies = Body[];
144
+
145
+ /**
146
+ * Parses bodies from the given JSON stream.
147
+ *
148
+ * @param stream - The JSON input stream.
149
+ * @returns Stream of bodies.
150
+ */
151
+ export function parseBodiesJSON(stream: AsyncIterable<Uint8Array>): AsyncIterable<Body> {
152
+ return parseJSONArray(stream);
153
+ }