Skip to content

Commit d99ff9c

Browse files
authored
fix: export common shared for external usage (#756)
1 parent 7645fb9 commit d99ff9c

File tree

93 files changed

+1312
-777
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+1312
-777
lines changed

biome.json

Lines changed: 76 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,78 @@
11
{
2-
"$schema": "https://biomejs.dev/schemas/2.3.10/schema.json",
3-
"vcs": { "enabled": false, "clientKind": "git", "useIgnoreFile": false },
4-
"files": {
5-
"ignoreUnknown": true,
6-
"includes": ["test/**/*.ts", "lib/**/*.ts"]
7-
},
8-
"formatter": {
9-
"enabled": true,
10-
"formatWithErrors": false,
11-
"indentStyle": "space",
12-
"indentWidth": 2,
13-
"lineEnding": "lf",
14-
"lineWidth": 80,
15-
"attributePosition": "auto",
16-
"bracketSameLine": false,
17-
"bracketSpacing": true,
18-
"expand": "auto",
19-
"useEditorconfig": true
20-
},
21-
"linter": {
22-
"enabled": true,
23-
"rules": {
24-
"recommended": true,
25-
"complexity": { "useArrowFunction": "off" },
26-
"style": { "noNonNullAssertion": "off", "useImportType": "on" },
27-
"suspicious": { "noExplicitAny": "warn" }
28-
},
29-
"includes": ["**", "!.github/**", "!docs/**", "!data/**"],
30-
"domains": { "test": "recommended" }
31-
},
32-
"javascript": {
33-
"formatter": {
34-
"jsxQuoteStyle": "double",
35-
"quoteProperties": "asNeeded",
36-
"trailingCommas": "all",
37-
"semicolons": "asNeeded",
38-
"arrowParentheses": "always",
39-
"bracketSameLine": false,
40-
"quoteStyle": "single",
41-
"attributePosition": "auto",
42-
"bracketSpacing": true
43-
}
44-
},
45-
"html": {
46-
"formatter": {
47-
"indentScriptAndStyle": false,
48-
"selfCloseVoidElements": "always"
49-
}
50-
},
51-
"assist": {
52-
"enabled": true,
53-
"actions": { "source": { "organizeImports": "on" } }
54-
}
2+
"$schema": "https://biomejs.dev/schemas/2.3.10/schema.json",
3+
"vcs": { "enabled": false, "clientKind": "git", "useIgnoreFile": false },
4+
"files": {
5+
"ignoreUnknown": true,
6+
"includes": ["test/**/*.ts", "lib/**/*.ts"]
7+
},
8+
"formatter": {
9+
"enabled": true,
10+
"formatWithErrors": false,
11+
"indentStyle": "space",
12+
"indentWidth": 2,
13+
"lineEnding": "lf",
14+
"lineWidth": 80,
15+
"attributePosition": "auto",
16+
"bracketSameLine": false,
17+
"bracketSpacing": true,
18+
"expand": "auto",
19+
"useEditorconfig": true
20+
},
21+
"linter": {
22+
"enabled": true,
23+
"rules": {
24+
"recommended": true,
25+
"complexity": { "useArrowFunction": "off" },
26+
"style": { "noNonNullAssertion": "off", "useImportType": "on" },
27+
"suspicious": { "noExplicitAny": "warn" }
28+
},
29+
"includes": ["**", "!.github/**", "!docs/**", "!data/**"],
30+
"domains": { "test": "recommended" }
31+
},
32+
"javascript": {
33+
"formatter": {
34+
"jsxQuoteStyle": "double",
35+
"quoteProperties": "asNeeded",
36+
"trailingCommas": "es5",
37+
"semicolons": "always",
38+
"arrowParentheses": "always",
39+
"bracketSameLine": false,
40+
"quoteStyle": "single",
41+
"attributePosition": "auto",
42+
"bracketSpacing": true
43+
}
44+
},
45+
"html": {
46+
"formatter": {
47+
"indentScriptAndStyle": false,
48+
"selfCloseVoidElements": "always"
49+
}
50+
},
51+
"assist": {
52+
"enabled": true,
53+
"actions": {
54+
"source": {
55+
"organizeImports": {
56+
"level": "on",
57+
"options": {
58+
"identifierOrder": "natural",
59+
"groups": [
60+
":URL:",
61+
":BLANK_LINE:",
62+
[":NODE:", ":BUN:"],
63+
":BLANK_LINE:",
64+
["!@*/**", ":PACKAGE_WITH_PROTOCOL:", ":PACKAGE:"],
65+
":BLANK_LINE:",
66+
["@wfcd/", "@wfcd/**"],
67+
":BLANK_LINE:",
68+
["@/models", "@/models/**", "@/supporting", "@/supporting/**"],
69+
["@/data/**"],
70+
":BLANK_LINE:",
71+
":RELATIVE:"
72+
]
73+
}
74+
}
75+
}
76+
}
77+
}
5578
}

lib/WorldState.ts

Lines changed: 112 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,63 @@ import { createHash } from 'node:crypto';
22

33
import wsData from 'warframe-worldstate-data';
44
import { parseDate } from 'warframe-worldstate-data/utilities';
5-
import Alert, { type RawAlert } from './models/Alert';
6-
import Archimedea, { type RawArchimedea } from './models/Archidemea';
7-
import Calendar, { type RawCalender } from './models/Calendar';
8-
import CambionCycle from './models/CambionCycle';
9-
import CetusCycle from './models/CetusCycle';
10-
import ConclaveChallenge, { type RawChallenge } from './models/ConclaveChallenge';
11-
import ConstructionProgress from './models/ConstructionProgress';
12-
import DailyDeal, { type RawDailyDeal } from './models/DailyDeal';
13-
import DarkSector, { type RawDarkSector } from './models/DarkSector';
14-
import DuviriCycle from './models/DuviriCycle';
15-
import EarthCycle from './models/EarthCycle';
16-
import Fissure, { type RawFissure } from './models/Fissure';
17-
import FlashSale, { type RawFlashSale } from './models/FlashSale';
18-
import GlobalUpgrade, { type RawGlobalUpgrade } from './models/GlobalUpgrade';
19-
import Invasion, { type RawInvasion } from './models/Invasion';
20-
import type Kinepage from './models/Kinepage';
21-
import Kuva from './models/Kuva';
22-
import News, { type RawNews } from './models/News';
23-
import Nightwave, { type RawNightwave } from './models/Nightwave';
24-
import PersistentEnemy, { type RawPersistentEnemy } from './models/PersistentEnemy';
25-
import type SentientOutpost from './models/SentientOutpost';
26-
import Simaris, { type LibraryInfo } from './models/Simaris';
27-
import Sortie, { type RawSortie } from './models/Sortie';
28-
import SteelPathOffering from './models/SteelPathOffering';
29-
import SyndicateMission, { type RawSyndicateMission } from './models/SyndicateMission';
30-
import VallisCycle from './models/VallisCycle';
31-
import VoidTrader, { type RawVoidTrader } from './models/VoidTrader';
32-
import WeeklyChallenge, { type RawWeeklyChallenge } from './models/WeeklyChallenge';
33-
import WorldEvent, { type RawWorldEvent } from './models/WorldEvent';
34-
import type WorldstateObject from './models/WorldstateObject';
35-
import type { BaseContentObject } from './models/WorldstateObject';
36-
import ZarimanCycle from './models/ZarimanCycle';
37-
import type Dependency from './supporting/Dependency';
38-
import DuviriChoice, { type RawChoice } from './supporting/DuviriChoice';
39-
import type ExternalMission from './supporting/ExternalMission';
40-
import { Tmp } from './Tmp';
5+
6+
import {
7+
Alert,
8+
Archimedea,
9+
type BaseContentObject,
10+
Calendar,
11+
CambionCycle,
12+
CetusCycle,
13+
ConclaveChallenge,
14+
ConstructionProgress,
15+
DailyDeal,
16+
DarkSector,
17+
DuviriCycle,
18+
EarthCycle,
19+
Fissure,
20+
FlashSale,
21+
GlobalUpgrade,
22+
Invasion,
23+
type Kinepage,
24+
Kuva,
25+
type LibraryInfo,
26+
News,
27+
Nightwave,
28+
PersistentEnemy,
29+
type RawAlert,
30+
type RawArchimedea,
31+
type RawCalender,
32+
type RawChallenge,
33+
type RawDailyDeal,
34+
type RawDarkSector,
35+
type RawFissure,
36+
type RawFlashSale,
37+
type RawGlobalUpgrade,
38+
type RawInvasion,
39+
type RawNews,
40+
type RawNightwave,
41+
type RawPersistentEnemy,
42+
type RawSortie,
43+
type RawSyndicateMission,
44+
type RawVoidTrader,
45+
type RawWeeklyChallenge,
46+
type RawWorldEvent,
47+
type SentientOutpost,
48+
Simaris,
49+
Sortie,
50+
SteelPathOfferings,
51+
SyndicateMission,
52+
Tmp,
53+
VallisCycle,
54+
VoidTrader,
55+
WeeklyChallenge,
56+
WorldEvent,
57+
type WorldStateObject,
58+
ZarimanCycle,
59+
} from '@/models';
60+
import type { Dependency, ExternalMission } from '@/supporting';
61+
import { DuviriChoice, type RawChoice } from '@/supporting';
4162

4263
const { sortie } = wsData;
4364

@@ -62,7 +83,8 @@ const defaultDeps: Dependency = {
6283
* @param uniqueField field to treat as unique
6384
* @returns array of parsed objects
6485
*/
65-
export function parseArray<T, D extends BaseContentObject>( // Not all instances of T extend WorldstateObject
86+
export function parseArray<T, D extends BaseContentObject>(
87+
// Not all instances of T extend WorldStateObject
6688
ParserClass: new (data: D, deps: Dependency) => T,
6789
dataArray: Array<D>,
6890
deps: Dependency,
@@ -94,7 +116,10 @@ export function parseArray<T, D extends BaseContentObject>( // Not all instances
94116
* @param uniqueField field to treat as unique
95117
* @returns array of parsed objects
96118
*/
97-
export async function parseAsyncArray<T extends WorldstateObject, D extends BaseContentObject>(
119+
export async function parseAsyncArray<
120+
T extends WorldStateObject,
121+
D extends BaseContentObject,
122+
>(
98123
ParserClass: { build: (data: D, deps: Dependency) => Promise<T> },
99124
dataArray: Array<D>,
100125
deps: Dependency,
@@ -308,7 +333,7 @@ export class WorldState {
308333
/**
309334
* Steel path offering rotation
310335
*/
311-
steelPath: SteelPathOffering;
336+
steelPath: SteelPathOfferings;
312337

313338
/**
314339
* The current prime resurgence
@@ -353,16 +378,28 @@ export class WorldState {
353378
/**
354379
* Generates the worldstate json as a string into usable objects
355380
*/
356-
static async build(json: string, deps: Dependency = defaultDeps): Promise<WorldState> {
381+
static async build(
382+
json: string,
383+
deps: Dependency = defaultDeps
384+
): Promise<WorldState> {
357385
if (typeof json !== 'string') {
358-
throw new TypeError(`json needs to be a string, provided ${typeof json} : ${JSON.stringify(json)}`);
386+
throw new TypeError(
387+
`json needs to be a string, provided ${typeof json} : ${JSON.stringify(json)}`
388+
);
359389
}
360390

361391
const data = JSON.parse(json);
362392
const ws = new WorldState(data, deps);
363393

364-
ws.events = await parseAsyncArray(WorldEvent, data.Goals, deps);
365-
ws.syndicateMissions = await parseAsyncArray(SyndicateMission, data.SyndicateMissions, deps, 'syndicate');
394+
ws.events = await parseAsyncArray<WorldEvent, RawWorldEvent>(
395+
WorldEvent,
396+
data.Goals,
397+
deps
398+
);
399+
ws.syndicateMissions = await parseAsyncArray<
400+
SyndicateMission,
401+
RawSyndicateMission
402+
>(SyndicateMission, data.SyndicateMissions, deps, 'syndicate');
366403

367404
return ws;
368405
}
@@ -384,7 +421,9 @@ export class WorldState {
384421
this.news = parseArray(
385422
News,
386423
safeArray<RawNews>(data.Events).filter(
387-
(e) => typeof e.Messages.find((msg) => msg.LanguageCode === deps.locale) !== 'undefined'
424+
(e) =>
425+
typeof e.Messages.find((msg) => msg.LanguageCode === deps.locale) !==
426+
'undefined'
388427
),
389428
deps
390429
);
@@ -397,7 +436,9 @@ export class WorldState {
397436

398437
this.syndicateMissions = [];
399438

400-
this.fissures = parseArray(Fissure, data.ActiveMissions, deps).concat(parseArray(Fissure, data.VoidStorms, deps));
439+
this.fissures = parseArray(Fissure, data.ActiveMissions, deps).concat(
440+
parseArray(Fissure, data.VoidStorms, deps)
441+
);
401442

402443
this.globalUpgrades = parseArray(GlobalUpgrade, data.GlobalUpgrades, deps);
403444

@@ -417,17 +458,27 @@ export class WorldState {
417458

418459
this.simaris = new Simaris(safeObj(data.LibraryInfo), deps);
419460

420-
this.conclaveChallenges = parseArray(ConclaveChallenge, data.PVPChallengeInstances, deps);
461+
this.conclaveChallenges = parseArray(
462+
ConclaveChallenge,
463+
data.PVPChallengeInstances,
464+
deps
465+
);
421466

422-
this.persistentEnemies = parseArray(PersistentEnemy, data.PersistentEnemies, deps);
467+
this.persistentEnemies = parseArray(
468+
PersistentEnemy,
469+
data.PersistentEnemies,
470+
deps
471+
);
423472

424473
this.earthCycle = new EarthCycle();
425474

426475
// bounties are 2.5 hours regardless of faction, so this can be reused
427-
const cetusSynd = safeArray<RawSyndicateMission>(data.SyndicateMissions).filter(
428-
(syndicate) => syndicate.Tag === 'CetusSyndicate'
476+
const cetusSynd = safeArray<RawSyndicateMission>(
477+
data.SyndicateMissions
478+
).filter((syndicate) => syndicate.Tag === 'CetusSyndicate');
479+
const bountyEnd = parseDate(
480+
cetusSynd.length > 0 ? cetusSynd[0].Expiry : { $date: { $numberLong: 0 } }
429481
);
430-
const bountyEnd = parseDate(cetusSynd.length > 0 ? cetusSynd[0].Expiry : { $date: { $numberLong: 0 } });
431482

432483
this.cetusCycle = new CetusCycle(bountyEnd);
433484

@@ -437,7 +488,9 @@ export class WorldState {
437488

438489
// this.midrathCycle = new MidrathCycle();
439490

440-
this.weeklyChallenges = data.WeeklyChallenges ? new WeeklyChallenge(data.WeeklyChallenges) : undefined;
491+
this.weeklyChallenges = data.WeeklyChallenges
492+
? new WeeklyChallenge(data.WeeklyChallenges)
493+
: undefined;
441494

442495
this.constructionProgress = new ConstructionProgress(data.ProjectPct);
443496

@@ -467,9 +520,12 @@ export class WorldState {
467520
};
468521
}
469522

470-
this.steelPath = new SteelPathOffering(deps);
523+
this.steelPath = new SteelPathOfferings(deps);
471524

472-
[this.vaultTrader] = parseArray(VoidTrader, data.PrimeVaultTraders, { ...deps, character: 'Varzia' });
525+
[this.vaultTrader] = parseArray(VoidTrader, data.PrimeVaultTraders, {
526+
...deps,
527+
character: 'Varzia',
528+
});
473529

474530
[this.archonHunt] = parseArray(Sortie, data.LiteSorties, deps);
475531

@@ -479,7 +535,7 @@ export class WorldState {
479535
[this.calendar] = parseArray(Calendar, data.KnownCalendarSeasons, deps);
480536

481537
this.archimedeas = parseArray(Archimedea, data.Conquests, deps);
482-
538+
483539
({
484540
kinepage: this.kinepage,
485541
sentientOutposts: this.sentientOutposts,
@@ -489,4 +545,5 @@ export class WorldState {
489545
}
490546
}
491547

492-
export default async (json: string, deps: Dependency) => WorldState.build(json, deps);
548+
export default async (json: string, deps: Dependency) =>
549+
WorldState.build(json, deps);

0 commit comments

Comments
 (0)