@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.
- package/LICENSE.md +22 -0
- package/README.md +168 -0
- package/lib/body.schema.json +587 -0
- package/lib/codex.schema.json +55 -0
- package/lib/commander-credits-response.schema.json +52 -0
- package/lib/commander-inventory-response.schema.json +91 -0
- package/lib/commander-position-response.schema.json +101 -0
- package/lib/commander-ranks-response.schema.json +138 -0
- package/lib/elite-server-status-response.schema.json +38 -0
- package/lib/flight-logs-response.schema.json +68 -0
- package/lib/main/api/commander.d.ts +96 -0
- package/lib/main/api/commander.js +38 -0
- package/lib/main/api/commander.js.map +1 -0
- package/lib/main/api/common.d.ts +28 -0
- package/lib/main/api/common.js +54 -0
- package/lib/main/api/common.js.map +1 -0
- package/lib/main/api/journal.d.ts +51 -0
- package/lib/main/api/journal.js +35 -0
- package/lib/main/api/journal.js.map +1 -0
- package/lib/main/api/logs.d.ts +130 -0
- package/lib/main/api/logs.js +60 -0
- package/lib/main/api/logs.js.map +1 -0
- package/lib/main/api/status.d.ts +13 -0
- package/lib/main/api/status.js +14 -0
- package/lib/main/api/status.js.map +1 -0
- package/lib/main/api/system.d.ts +279 -0
- package/lib/main/api/system.js +125 -0
- package/lib/main/api/system.js.map +1 -0
- package/lib/main/api/systems.d.ts +148 -0
- package/lib/main/api/systems.js +51 -0
- package/lib/main/api/systems.js.map +1 -0
- package/lib/main/bodies.d.ts +116 -0
- package/lib/main/bodies.js +33 -0
- package/lib/main/bodies.js.map +1 -0
- package/lib/main/codex.d.ts +20 -0
- package/lib/main/codex.js +15 -0
- package/lib/main/codex.js.map +1 -0
- package/lib/main/common.d.ts +14 -0
- package/lib/main/common.js +20 -0
- package/lib/main/common.js.map +1 -0
- package/lib/main/index.d.ts +14 -0
- package/lib/main/index.js +19 -0
- package/lib/main/index.js.map +1 -0
- package/lib/main/powerplay.d.ts +23 -0
- package/lib/main/powerplay.js +15 -0
- package/lib/main/powerplay.js.map +1 -0
- package/lib/main/stations.d.ts +69 -0
- package/lib/main/stations.js +15 -0
- package/lib/main/stations.js.map +1 -0
- package/lib/main/systems.d.ts +61 -0
- package/lib/main/systems.js +15 -0
- package/lib/main/systems.js.map +1 -0
- package/lib/main/util.d.ts +38 -0
- package/lib/main/util.js +104 -0
- package/lib/main/util.js.map +1 -0
- package/lib/powerplay.schema.json +90 -0
- package/lib/station-market-response.schema.json +95 -0
- package/lib/station-outfitting-response.schema.json +75 -0
- package/lib/station-shipyard-response.schema.json +72 -0
- package/lib/station.schema.json +315 -0
- package/lib/system-bodies-response.schema.json +609 -0
- package/lib/system-deaths-response.schema.json +58 -0
- package/lib/system-estimated-value-response.schema.json +76 -0
- package/lib/system-factions-response.schema.json +313 -0
- package/lib/system-response.schema.json +137 -0
- package/lib/system-stations-response.schema.json +222 -0
- package/lib/system-traffic-response.schema.json +85 -0
- package/lib/system.schema.json +1016 -0
- package/package.json +82 -0
- package/src/main/api/commander.ts +116 -0
- package/src/main/api/common.ts +77 -0
- package/src/main/api/journal.ts +76 -0
- package/src/main/api/logs.ts +166 -0
- package/src/main/api/status.ts +24 -0
- package/src/main/api/system.ts +361 -0
- package/src/main/api/systems.ts +199 -0
- package/src/main/bodies.ts +153 -0
- package/src/main/codex.ts +31 -0
- package/src/main/common.ts +29 -0
- package/src/main/index.ts +42 -0
- package/src/main/powerplay.ts +34 -0
- package/src/main/stations.ts +87 -0
- package/src/main/systems.ts +77 -0
- package/src/main/util.ts +103 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT LICENSE
|
|
2
|
+
===========
|
|
3
|
+
|
|
4
|
+
Copyright (C) 2020 Klaus Reimer, k@ailis.de
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to
|
|
8
|
+
deal in the Software without restriction, including without limitation the
|
|
9
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
10
|
+
sell copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in
|
|
14
|
+
all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
22
|
+
IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
EDSM
|
|
2
|
+
====
|
|
3
|
+
|
|
4
|
+
[GitHub] | [NPM] | [API Doc]
|
|
5
|
+
|
|
6
|
+
This library provides typescript types, JSON schemas and utility functions for the Elite Dangerous Star Map ([EDSM]) API. It is primarily intended for Node.js and Electron applications to read EDSM data files and work with the EDSM REST API but it also works in a web browser.
|
|
7
|
+
|
|
8
|
+
Communication with the REST API is done with the standard [fetch] command which works out-of-the-box in a browser, modern Node.js or in Electron.
|
|
9
|
+
|
|
10
|
+
Usage
|
|
11
|
+
-----
|
|
12
|
+
|
|
13
|
+
First install the library as a dependency in your project:
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
npm install @kayahr/edsm
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Then download the data dumps from EDSM and use this library to read them. This is not needed if you just want to access EDSM's REST API.
|
|
20
|
+
|
|
21
|
+
Working with the JSON dumps
|
|
22
|
+
---------------------------
|
|
23
|
+
|
|
24
|
+
The nightly dumps of EDSM are always stored as gzipped JSON files where each dataset is stored in a single line. So when ignoring the array characters in the first and last line and ignoring the comma at the end this is just like a JSONL file. This library handles these files like this so the content of these large files can easily be streamed.
|
|
25
|
+
|
|
26
|
+
The utility functions provided by this library to read the data files expect an standard readable stream as input. Here is an example which parses all station objects from the `stations.json.gz` file and outputs them to console:
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import { createReadStream} from "node:fs";
|
|
30
|
+
import { createGunzip } from "node:zlib";
|
|
31
|
+
import { parseStationsJSON } from "@kayahr/edsm";
|
|
32
|
+
|
|
33
|
+
const stream = createReadStream("stations.json.gz").pipe(createGunzip());
|
|
34
|
+
|
|
35
|
+
for await (const station of parseStationsJSON(stream)) {
|
|
36
|
+
console.log(station);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
There are also `parseSystemsJSON`, `parsePowerPlayJSON`, `parseCodexJSON` and `parseBodiesJSON` functions for the other data files.
|
|
42
|
+
|
|
43
|
+
EDSM REST API
|
|
44
|
+
-------------
|
|
45
|
+
|
|
46
|
+
Asynchronous functions are provided for all EDSM API calls. Received HTTP and EDSM errors are automatically converted to exceptions (Promise rejects).
|
|
47
|
+
|
|
48
|
+
Here is an example listing the available ships in the shipyard of Jameson Memorial:
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
import { getStationShipyard } from "@kayahr/edsm";
|
|
52
|
+
|
|
53
|
+
const shipyard = await getStationShipyard("Shinrarta Dezhra", "Jameson Memorial");
|
|
54
|
+
for (const ship of shipyard.ships) {
|
|
55
|
+
console.log(ship.id, ship.name);
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Here is a list of all available API functions linked to their API documentation:
|
|
60
|
+
|
|
61
|
+
* [getEliteServerStatus]
|
|
62
|
+
* [getCommanderRanks]
|
|
63
|
+
* [getCommanderCredits]
|
|
64
|
+
* [getCommanderInventory]
|
|
65
|
+
* [getCommanderPosition]
|
|
66
|
+
* [getFlightLogs]
|
|
67
|
+
* [setSystemComment]
|
|
68
|
+
* [getSystemComment]
|
|
69
|
+
* [getSystemComments]
|
|
70
|
+
* [getSystemBodies]
|
|
71
|
+
* [getSystemEstimatedValue]
|
|
72
|
+
* [getSystemStations]
|
|
73
|
+
* [getSystemFactions]
|
|
74
|
+
* [getSystemTraffic]
|
|
75
|
+
* [getSystemDeaths]
|
|
76
|
+
* [getStationMarket]
|
|
77
|
+
* [getStationShipyard]
|
|
78
|
+
* [getStationOutfitting]
|
|
79
|
+
* [getSystem]
|
|
80
|
+
* [getSystems]
|
|
81
|
+
* [getSphereSystems]
|
|
82
|
+
* [getCubeSystems]
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
Other utility functions
|
|
86
|
+
-----------------------
|
|
87
|
+
|
|
88
|
+
### isPlanet(body)
|
|
89
|
+
|
|
90
|
+
Type-guard function which returns true when body is a planet, false when not.
|
|
91
|
+
|
|
92
|
+
### isStar(body)
|
|
93
|
+
|
|
94
|
+
Type-guard function which returns true when body is a star, false when not.
|
|
95
|
+
|
|
96
|
+
### toUTCString(date)
|
|
97
|
+
|
|
98
|
+
Converts a JavaScript Date object to a UTC date string in the format required by various EDSM API functions. Converting in the other direction can simply be done with `date = new Date(utcDateString)`.
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
64 bit number handling
|
|
102
|
+
----------------------
|
|
103
|
+
|
|
104
|
+
Some EDSM JSON properties (`id64`, `systemId64`) are 64 bit integers. But the JavaScript `number` type can only handle integers up to 53 bit. So when a number exceeds this range then it is interpreted as a large floating point number which looses precision, which is very bad for IDs. To fix this problem this library uses a special JSON reviver when parsing the journal logs to convert numbers, which are too large for JavaScript, into the `BigInt` type. So the value type of an ID-like property like `id64` for example can either be `number` or `BigInt`, depending on how many bits the number actually needs. The typescript typings use an `ID` type for these properties to express that.
|
|
105
|
+
|
|
106
|
+
`BigInt` values cannot be serialized. So when you need to serialize the parsed JSON again, then it is recommended to use the [json-with-bigint] library, which automatically handles this and writes the correct 64 bit numbers into the JSON output.
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
JSON Schemas
|
|
110
|
+
------------
|
|
111
|
+
|
|
112
|
+
### Dumps
|
|
113
|
+
|
|
114
|
+
* [body.schema.json](https://kayahr.github.io/edsm/schemas/body.schema.json)
|
|
115
|
+
* [codex.schema.json](https://kayahr.github.io/edsm/schemas/codex.schema.json)
|
|
116
|
+
* [powerplay.schema.json](https://kayahr.github.io/edsm/schemas/powerplay.schema.json)
|
|
117
|
+
* [station.schema.json](https://kayahr.github.io/edsm/schemas/station.schema.json)
|
|
118
|
+
* [system.schema.json](https://kayahr.github.io/edsm/schemas/system.schema.json)
|
|
119
|
+
|
|
120
|
+
### API
|
|
121
|
+
|
|
122
|
+
* [commander-credits-response.schema.json](https://kayahr.github.io/edsm/schemas/commander-credits-response.schema.json)
|
|
123
|
+
* [commander-inventory-response.schema.json](https://kayahr.github.io/edsm/schemas/commander-inventory-response.schema.json)
|
|
124
|
+
* [commander-position-response.schema.json](https://kayahr.github.io/edsm/schemas/commander-position-response.schema.json)
|
|
125
|
+
* [commander-ranks-response.schema.json](https://kayahr.github.io/edsm/schemas/commander-ranks-response.schema.json)
|
|
126
|
+
* [elite-server-status-response.schema.json](https://kayahr.github.io/edsm/schemas/elite-server-status-response.schema.json)
|
|
127
|
+
* [flight-logs-response.schema.json](https://kayahr.github.io/edsm/schemas/flight-logs-response.schema.json)
|
|
128
|
+
* [station-market-response.schema.json](https://kayahr.github.io/edsm/schemas/station-market-response.schema.json)
|
|
129
|
+
* [station-outfitting-response.schema.json](https://kayahr.github.io/edsm/schemas/station-outfitting-response.schema.json)
|
|
130
|
+
* [station-shipyard-response.schema.json](https://kayahr.github.io/edsm/schemas/station-shipyard-response.schema.json)
|
|
131
|
+
* [system-bodies-response.schema.json](https://kayahr.github.io/edsm/schemas/system-bodies-response.schema.json)
|
|
132
|
+
* [system-deaths-response.schema.json](https://kayahr.github.io/edsm/schemas/system-deaths-response.schema.json)
|
|
133
|
+
* [system-estimated-value-response.schema.json](https://kayahr.github.io/edsm/schemas/system-estimated-value-response.schema.json)
|
|
134
|
+
* [system-factions-response.schema.json](https://kayahr.github.io/edsm/schemas/system-factions-response.schema.json)
|
|
135
|
+
* [system-response.schema.json](https://kayahr.github.io/edsm/schemas/system-response.schema.json)
|
|
136
|
+
* [system-stations-response.schema.json](https://kayahr.github.io/edsm/schemas/system-stations-response.schema.json)
|
|
137
|
+
* [system-traffic-response.schema.json](https://kayahr.github.io/edsm/schemas/system-traffic-response.schema.json)
|
|
138
|
+
|
|
139
|
+
[API Doc]: https://kayahr.github.io/edsm/
|
|
140
|
+
[GitHub]: https://github.com/kayahr/edsm
|
|
141
|
+
[NPM]: https://www.npmjs.com/package/@kayahr/edsm
|
|
142
|
+
[EDSM]: https://www.edsm.net/
|
|
143
|
+
[fetch]: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API
|
|
144
|
+
[json-with-bigint]: https://www.npmjs.com/package/json-with-bigint
|
|
145
|
+
[getEliteServerStatus]: https://kayahr.github.io/edsm/functions/getEliteServerStatus.html
|
|
146
|
+
[getCommanderRanks]: https://kayahr.github.io/edsm/functions/getCommanderRanks.html
|
|
147
|
+
[getCommanderCredits]: https://kayahr.github.io/edsm/functions/getCommanderCredits.html
|
|
148
|
+
[getCommanderInventory]: https://kayahr.github.io/edsm/functions/getCommanderInventory.html
|
|
149
|
+
[getCommanderPosition]: https://kayahr.github.io/edsm/functions/getCommanderPosition.html
|
|
150
|
+
[getFlightLogs]: https://kayahr.github.io/edsm/functions/getFlightLogs.html
|
|
151
|
+
[setSystemComment]: https://kayahr.github.io/edsm/functions/setSystemComment.html
|
|
152
|
+
[getSystemComment]: https://kayahr.github.io/edsm/functions/getSystemComment.html
|
|
153
|
+
[getSystemComments]: https://kayahr.github.io/edsm/functions/getSystemComments.html
|
|
154
|
+
[getSystemBodies]: https://kayahr.github.io/edsm/functions/getSystemBodies.html
|
|
155
|
+
[getSystemEstimatedValue]: https://kayahr.github.io/edsm/functions/getSystemEstimatedValue.html
|
|
156
|
+
[getSystemStations]: https://kayahr.github.io/edsm/functions/getSystemStations.html
|
|
157
|
+
[getStationMarket]: https://kayahr.github.io/edsm/functions/getStationMarket.html
|
|
158
|
+
[getStationShipyard]: https://kayahr.github.io/edsm/functions/getStationShipyard.html
|
|
159
|
+
[getStationOutfitting]: https://kayahr.github.io/edsm/functions/getStationOutfitting.html
|
|
160
|
+
[getSystemFactions]: https://kayahr.github.io/edsm/functions/getSystemFactions.html
|
|
161
|
+
[getSystemTraffic]: https://kayahr.github.io/edsm/functions/getSystemTraffic.html
|
|
162
|
+
[getSystemDeaths]: https://kayahr.github.io/edsm/functions/getSystemDeaths.html
|
|
163
|
+
[getSystem]: https://kayahr.github.io/edsm/functions/getSystem.html
|
|
164
|
+
[getSystems]: https://kayahr.github.io/edsm/functions/getSystems.html
|
|
165
|
+
[getSphereSystems]: https://kayahr.github.io/edsm/functions/getSphereSystems.html
|
|
166
|
+
[getCubeSystems]: https://kayahr.github.io/edsm/functions/getCubeSystems.html
|
|
167
|
+
[getDiscardEvents]: https://kayahr.github.io/edsm/functions/getDiscardEvents.html
|
|
168
|
+
[sendEvents]: https://kayahr.github.io/edsm/functions/sendEvents.html
|