@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
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2020 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
|
+
/** Single EDSM codex. */
|
|
10
|
+
export interface Codex {
|
|
11
|
+
systemId: number;
|
|
12
|
+
systemId64: Id64;
|
|
13
|
+
systemName: string;
|
|
14
|
+
region: string;
|
|
15
|
+
type: string | null;
|
|
16
|
+
name: string | number;
|
|
17
|
+
reportedOn: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** List of EDSM codices. */
|
|
21
|
+
export type Codices = Codex[];
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Parses codices from the given JSON stream.
|
|
25
|
+
*
|
|
26
|
+
* @param stream - The JSON input stream.
|
|
27
|
+
* @returns Stream of codices.
|
|
28
|
+
*/
|
|
29
|
+
export function parseCodexJSON(stream: AsyncIterable<Uint8Array>): AsyncIterable<Codex> {
|
|
30
|
+
return parseJSONArray(stream);
|
|
31
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2020 Klaus Reimer <k@ailis.de>
|
|
3
|
+
* See LICENSE.md for licensing information.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export interface Coordinates {
|
|
7
|
+
x: number;
|
|
8
|
+
y: number;
|
|
9
|
+
z: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** A 64 bit ID. Can be a `number` if ID does not need more then 53 bit. Must be `bigint` if ID needs more than 53 bit. */
|
|
13
|
+
export type Id64 = number | bigint;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Converts the given date to a UTC date string as expected by the EDSM REST API.
|
|
17
|
+
*
|
|
18
|
+
* @param date - The date to convert.
|
|
19
|
+
* @returns The date as an EDSM-compatible UTC date string.
|
|
20
|
+
*/
|
|
21
|
+
export function toUTCString(date: Date): string {
|
|
22
|
+
const year = date.getUTCFullYear().toString().padStart(4, "0");
|
|
23
|
+
const month = (date.getUTCMonth() + 1).toString().padStart(2, "0");
|
|
24
|
+
const day = date.getUTCDate().toString().padStart(2, "0");
|
|
25
|
+
const hour = date.getUTCHours().toString().padStart(2, "0");
|
|
26
|
+
const minute = date.getUTCMinutes().toString().padStart(2, "0");
|
|
27
|
+
const second = date.getUTCSeconds().toString().padStart(2, "0");
|
|
28
|
+
return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
|
|
29
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2020 Klaus Reimer <k@ailis.de>
|
|
3
|
+
* See LICENSE.md for licensing information.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export {
|
|
7
|
+
type CommanderCreditsResponse, type CommanderInventoryResponse, type CommanderRanksResponse, type CreditsPeriod, getCommanderCredits, getCommanderInventory,
|
|
8
|
+
getCommanderRanks, type InventoryType
|
|
9
|
+
} from "./api/commander.ts";
|
|
10
|
+
export { APIException, ServerException, type SystemIdRequestOptions } from "./api/common.ts";
|
|
11
|
+
export { type EDSMEvent, type EventResponse, getDiscardEvents, sendEvents } from "./api/journal.ts";
|
|
12
|
+
export {
|
|
13
|
+
type CommanderPositionOptions, type CommanderPositionResponse, type FlightLog, type FlightLogFilter, type FlightLogsResponse, getCommanderPosition,
|
|
14
|
+
getFlightLogs, getSystemComment, getSystemComments, setSystemComment, type SystemCommentResponse, type SystemCommentsOptions,
|
|
15
|
+
type SystemCommentsResponse
|
|
16
|
+
} from "./api/logs.ts";
|
|
17
|
+
export { type EliteServerStatusResponse, type EliteServerStatusType, getEliteServerStatus } from "./api/status.ts";
|
|
18
|
+
export {
|
|
19
|
+
type BodyScanValue, getStationMarket, getStationOutfitting, getStationShipyard, getSystemBodies, getSystemDeaths, getSystemEstimatedValue,
|
|
20
|
+
getSystemFactions, getSystemStations, getSystemTraffic, type ShortSystemFaction, type StationMarketResponse, type StationOutfittingResponse,
|
|
21
|
+
type StationShipyardResponse, type SystemBodiesResponse, type SystemDeathsResponse, type SystemEstimatedValueResponse, type SystemFaction,
|
|
22
|
+
type SystemFactionsOptions, type SystemFactionsResponse, type SystemStationsResponse, type SystemTrafficResponse
|
|
23
|
+
} from "./api/system.ts";
|
|
24
|
+
export {
|
|
25
|
+
type CubeSystemsRequestOptions, getCubeSystems, getSphereSystems, getSystem, getSystems, type SphereSystemsRequestOptions, type SystemRequestFlags,
|
|
26
|
+
type SystemRequestOptions, type SystemResponse, type SystemsRequestOptions
|
|
27
|
+
} from "./api/systems.ts";
|
|
28
|
+
export {
|
|
29
|
+
type Asteroids, type AtmosphereComposition, type Bodies, type Body, isPlanet, isStar, type Materials, parseBodiesJSON, type Planet, type SolidComposition,
|
|
30
|
+
type Star, type SystemBody, type SystemPlanet, type SystemStar
|
|
31
|
+
} from "./bodies.ts";
|
|
32
|
+
export { type Codex, type Codices, parseCodexJSON } from "./codex.ts";
|
|
33
|
+
export { type Coordinates, type Id64, toUTCString } from "./common.ts";
|
|
34
|
+
export { parsePowerPlayJSON, type PowerPlay, type PowerPlays } from "./powerplay.ts";
|
|
35
|
+
export {
|
|
36
|
+
type Commodity, type Outfitting, parseStationsJSON, type Ship, type Station, type StationBody, type StationControllingFaction, type Stations,
|
|
37
|
+
type StationUpdateTime, type SystemStation
|
|
38
|
+
} from "./stations.ts";
|
|
39
|
+
export {
|
|
40
|
+
type ControllingFaction, type EstimatedCoordinates, type Faction, parseSystemsJSON, type State, type System, type Systems, type TrendState
|
|
41
|
+
} from "./systems.ts";
|
|
42
|
+
export { IllegalStateException, NotFoundException } from "./util.ts";
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2020 Klaus Reimer <k@ailis.de>
|
|
3
|
+
* See LICENSE.md for licensing information.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { Coordinates, Id64 } from "./common.ts";
|
|
7
|
+
import { parseJSONArray } from "./util.ts";
|
|
8
|
+
|
|
9
|
+
/** Single EDSM power play information. */
|
|
10
|
+
export interface PowerPlay {
|
|
11
|
+
power: string;
|
|
12
|
+
powerState: string;
|
|
13
|
+
id: number;
|
|
14
|
+
id64: Id64;
|
|
15
|
+
name: string;
|
|
16
|
+
coords: Coordinates;
|
|
17
|
+
allegiance: string | null;
|
|
18
|
+
government: string | null;
|
|
19
|
+
state: string | null;
|
|
20
|
+
date: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** List of EDSM power play information. */
|
|
24
|
+
export type PowerPlays = PowerPlay[];
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Parses power play information from the given JSON stream.
|
|
28
|
+
*
|
|
29
|
+
* @param stream - The JSON input stream.
|
|
30
|
+
* @returns Stream of power play information.
|
|
31
|
+
*/
|
|
32
|
+
export function parsePowerPlayJSON(stream: AsyncIterable<Uint8Array>): AsyncIterable<PowerPlay> {
|
|
33
|
+
return parseJSONArray(stream);
|
|
34
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2020 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
|
+
export interface StationControllingFaction {
|
|
10
|
+
id: number | null;
|
|
11
|
+
name: string | null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface StationBody {
|
|
15
|
+
id: number;
|
|
16
|
+
name: string;
|
|
17
|
+
latitude?: number;
|
|
18
|
+
longitude?: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface StationUpdateTime {
|
|
22
|
+
information: string;
|
|
23
|
+
market: string | null;
|
|
24
|
+
shipyard: string | null;
|
|
25
|
+
outfitting: string | null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface Outfitting {
|
|
29
|
+
id: string | null;
|
|
30
|
+
name: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface Commodity {
|
|
34
|
+
id: string | null;
|
|
35
|
+
name: string;
|
|
36
|
+
buyPrice: number;
|
|
37
|
+
stock: number;
|
|
38
|
+
sellPrice: number;
|
|
39
|
+
demand: number;
|
|
40
|
+
stockBracket: number;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface Ship {
|
|
44
|
+
id: number;
|
|
45
|
+
name: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface Station {
|
|
49
|
+
id: number;
|
|
50
|
+
marketId: number | null;
|
|
51
|
+
type: string | null;
|
|
52
|
+
name: string;
|
|
53
|
+
body?: StationBody;
|
|
54
|
+
distanceToArrival: number | null;
|
|
55
|
+
allegiance: string | null;
|
|
56
|
+
government: string | null;
|
|
57
|
+
economy: string | null;
|
|
58
|
+
secondEconomy: string | null;
|
|
59
|
+
haveMarket: boolean;
|
|
60
|
+
haveShipyard: boolean;
|
|
61
|
+
haveOutfitting: boolean;
|
|
62
|
+
otherServices: string[];
|
|
63
|
+
controllingFaction?: StationControllingFaction;
|
|
64
|
+
updateTime: StationUpdateTime;
|
|
65
|
+
systemId?: number;
|
|
66
|
+
systemId64?: Id64 | null;
|
|
67
|
+
systemName?: string;
|
|
68
|
+
commodities: Commodity[] | null;
|
|
69
|
+
ships: Ship[] | null;
|
|
70
|
+
outfitting: Outfitting[] | null;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Station data in system objects with less details. */
|
|
74
|
+
export type SystemStation = Omit<Station, "systemId" | "systemId64" | "systemName" | "outfitting" | "ships" | "commodities">;
|
|
75
|
+
|
|
76
|
+
/** List of EDSM stations. */
|
|
77
|
+
export type Stations = Station[];
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Parses stations from the given JSON stream.
|
|
81
|
+
*
|
|
82
|
+
* @param stream - The JSON input stream.
|
|
83
|
+
* @returns Stream of stations.
|
|
84
|
+
*/
|
|
85
|
+
export function parseStationsJSON(stream: AsyncIterable<Uint8Array>): AsyncIterable<Station> {
|
|
86
|
+
return parseJSONArray(stream);
|
|
87
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
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 { Coordinates, Id64 } from "./common.ts";
|
|
8
|
+
import type { SystemStation } from "./stations.ts";
|
|
9
|
+
import { parseJSONArray } from "./util.ts";
|
|
10
|
+
|
|
11
|
+
export interface EstimatedCoordinates extends Coordinates {
|
|
12
|
+
precision: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface ControllingFaction {
|
|
16
|
+
id: number;
|
|
17
|
+
name: string | null;
|
|
18
|
+
allegiance?: string;
|
|
19
|
+
government?: string;
|
|
20
|
+
isPlayer: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface State {
|
|
24
|
+
state: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface TrendState extends State {
|
|
28
|
+
trend: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface Faction {
|
|
32
|
+
id: number;
|
|
33
|
+
name: string;
|
|
34
|
+
allegiance?: string | null;
|
|
35
|
+
government?: string | null;
|
|
36
|
+
influence: number;
|
|
37
|
+
state: string | null;
|
|
38
|
+
activeStates: State[];
|
|
39
|
+
recoveringStates: TrendState[];
|
|
40
|
+
pendingStates: TrendState[];
|
|
41
|
+
happiness: string;
|
|
42
|
+
isPlayer: boolean;
|
|
43
|
+
lastUpdate: number;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** A single EDSM system. */
|
|
47
|
+
export interface System {
|
|
48
|
+
name: string;
|
|
49
|
+
id: number;
|
|
50
|
+
id64: Id64 | null;
|
|
51
|
+
date: string;
|
|
52
|
+
coords?: Coordinates;
|
|
53
|
+
estimatedCoordinates?: EstimatedCoordinates;
|
|
54
|
+
allegiance?: string | null;
|
|
55
|
+
government?: string | null;
|
|
56
|
+
state?: string | null;
|
|
57
|
+
economy?: string | null;
|
|
58
|
+
security?: string;
|
|
59
|
+
population?: number | null;
|
|
60
|
+
controllingFaction?: ControllingFaction;
|
|
61
|
+
factions?: Faction[];
|
|
62
|
+
stations?: SystemStation[];
|
|
63
|
+
bodies?: SystemBody[];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** List of EDSM systems. */
|
|
67
|
+
export type Systems = System[];
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Parses systems from the given JSON stream.
|
|
71
|
+
*
|
|
72
|
+
* @param stream - The JSON input stream.
|
|
73
|
+
* @returns Stream of systems.
|
|
74
|
+
*/
|
|
75
|
+
export function parseSystemsJSON(stream: AsyncIterable<Uint8Array>): AsyncIterable<System> {
|
|
76
|
+
return parseJSONArray(stream);
|
|
77
|
+
}
|
package/src/main/util.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2020 Klaus Reimer <k@ailis.de>
|
|
3
|
+
* See LICENSE.md for licensing information.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Base class for all exceptions. Automatically corrects its prototype and name.
|
|
8
|
+
*/
|
|
9
|
+
export abstract class EDSMException extends Error {
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new exception.
|
|
12
|
+
*
|
|
13
|
+
* @param message - The exception message.
|
|
14
|
+
* @param options - Optional error options.
|
|
15
|
+
*/
|
|
16
|
+
public constructor(message: string, options?: ErrorOptions) {
|
|
17
|
+
super(message, options);
|
|
18
|
+
this.name = this.constructor.name;
|
|
19
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Thrown when state is illegal. */
|
|
24
|
+
export class IllegalStateException extends EDSMException {}
|
|
25
|
+
|
|
26
|
+
/** Thrown when some resource was not found. */
|
|
27
|
+
export class NotFoundException extends EDSMException {}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Helper function to iterate over the lines of a data stream.
|
|
31
|
+
*
|
|
32
|
+
* @param stream - The input stream.
|
|
33
|
+
* @yields The created iterable for iterating over the lines of the stream.
|
|
34
|
+
*/
|
|
35
|
+
async function *parseLines(stream: AsyncIterable<Uint8Array>): AsyncIterable<string> {
|
|
36
|
+
let line = "";
|
|
37
|
+
const decoder = new TextDecoder();
|
|
38
|
+
for await (const chunk of stream) {
|
|
39
|
+
const data = decoder.decode(chunk);
|
|
40
|
+
const parts = data.split("\n");
|
|
41
|
+
const numParts = parts.length;
|
|
42
|
+
for (let i = 0; i < numParts; i++) {
|
|
43
|
+
line += parts[i];
|
|
44
|
+
if (i < numParts - 1) {
|
|
45
|
+
yield line;
|
|
46
|
+
line = "";
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (line !== "") {
|
|
51
|
+
yield line;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Helper function to iterate over the array entries of the given stream. The stream must be a JSON file with an array
|
|
57
|
+
* bracket in the first and last line and all other lines must contain a single dataset each. So it's actually a JSONL
|
|
58
|
+
* file but wrapped in an array and with comma character suffixes.
|
|
59
|
+
*
|
|
60
|
+
* @param stream - The JSON input as an async iterable.
|
|
61
|
+
* @yields The created iterable for iterating over the array entries of the JSON stream.
|
|
62
|
+
*/
|
|
63
|
+
export async function *parseJSONArray<T>(stream: AsyncIterable<Uint8Array>): AsyncIterable<T> {
|
|
64
|
+
let inData = false;
|
|
65
|
+
for await (let line of parseLines(stream)) {
|
|
66
|
+
if (!inData) {
|
|
67
|
+
if (line === "[") {
|
|
68
|
+
inData = true;
|
|
69
|
+
} else {
|
|
70
|
+
throw new IllegalStateException(`Expected array start but got: ${line}`);
|
|
71
|
+
}
|
|
72
|
+
} else {
|
|
73
|
+
if (line === "]") {
|
|
74
|
+
inData = false;
|
|
75
|
+
} else {
|
|
76
|
+
if (line.endsWith(",")) {
|
|
77
|
+
line = line.substring(0, line.length - 1);
|
|
78
|
+
}
|
|
79
|
+
yield JSON.parse(line, jsonReviver);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* JSON reviver function which converts numbers of ID properties (property names ending with 'ID' or 'Address') to bigint if needed.
|
|
87
|
+
*
|
|
88
|
+
* @param key - The JSON property key.
|
|
89
|
+
* @param value - The parsed JSON property value.
|
|
90
|
+
* @param context - The reviver context containing the raw JSON source string.
|
|
91
|
+
* @returns The already parsed JSON property value if suitable or the raw source converted into a bigint.
|
|
92
|
+
*/
|
|
93
|
+
export function jsonReviver(key: string, value: unknown, context?: { source: string }): unknown {
|
|
94
|
+
if (context != null && typeof value === "number" && (value > Number.MAX_SAFE_INTEGER || value < Number.MIN_SAFE_INTEGER)) {
|
|
95
|
+
const source = context.source;
|
|
96
|
+
if (key === "id64" || key === "systemId64") {
|
|
97
|
+
return BigInt(source);
|
|
98
|
+
} else if (String(value) !== source && /^[-+]?\d+$/.test(source)) {
|
|
99
|
+
throw new IllegalStateException(`Value of property '${key}' looks like a bigint (${source}) but was parsed as an imprecise number (${value})`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return value;
|
|
103
|
+
}
|