@evefrontier/dapp-kit 0.1.8 → 0.2.0-alpha.1
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/README.md +28 -25
- package/dist/config/dapp-kit.d.ts +4 -0
- package/dist/config/dapp-kit.d.ts.map +1 -0
- package/dist/config/dapp-kit.js +14 -0
- package/dist/config/index.d.ts +2 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +1 -0
- package/dist/graphql/client.d.ts +277 -0
- package/dist/graphql/client.d.ts.map +1 -0
- package/dist/graphql/client.js +346 -0
- package/dist/graphql/index.d.ts +4 -0
- package/dist/graphql/index.d.ts.map +1 -0
- package/dist/graphql/index.js +16 -0
- package/dist/graphql/queries.d.ts +103 -0
- package/dist/graphql/queries.d.ts.map +1 -0
- package/{graphql/queries.ts → dist/graphql/queries.js} +113 -223
- package/dist/graphql/types.d.ts +396 -0
- package/dist/graphql/types.d.ts.map +1 -0
- package/dist/graphql/types.js +4 -0
- package/dist/hooks/index.d.ts +10 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +8 -0
- package/dist/hooks/useCharacterDirectory.d.ts +16 -0
- package/dist/hooks/useCharacterDirectory.d.ts.map +1 -0
- package/dist/hooks/useCharacterDirectory.js +23 -0
- package/dist/hooks/useCharacterSearch.d.ts +24 -0
- package/dist/hooks/useCharacterSearch.d.ts.map +1 -0
- package/dist/hooks/useCharacterSearch.js +24 -0
- package/dist/hooks/useConnection.d.ts +51 -0
- package/dist/hooks/useConnection.d.ts.map +1 -0
- package/{hooks/useConnection.ts → dist/hooks/useConnection.js} +8 -10
- package/dist/hooks/useEntityRole.d.ts +26 -0
- package/dist/hooks/useEntityRole.d.ts.map +1 -0
- package/dist/hooks/useEntityRole.js +91 -0
- package/dist/hooks/useNotification.d.ts +72 -0
- package/dist/hooks/useNotification.d.ts.map +1 -0
- package/{hooks/useNotification.ts → dist/hooks/useNotification.js} +8 -12
- package/dist/hooks/useSmartObject.d.ts +44 -0
- package/dist/hooks/useSmartObject.d.ts.map +1 -0
- package/dist/hooks/useSmartObject.js +50 -0
- package/dist/hooks/useSponsoredTransaction.d.ts +147 -0
- package/dist/hooks/useSponsoredTransaction.d.ts.map +1 -0
- package/dist/hooks/useSponsoredTransaction.js +240 -0
- package/dist/hooks/useTypeNames.d.ts +11 -0
- package/dist/hooks/useTypeNames.d.ts.map +1 -0
- package/dist/hooks/useTypeNames.js +24 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/providers/EveFrontierProvider.d.ts +23 -0
- package/dist/providers/EveFrontierProvider.d.ts.map +1 -0
- package/dist/providers/EveFrontierProvider.js +23 -0
- package/dist/providers/NotificationProvider.d.ts +14 -0
- package/dist/providers/NotificationProvider.d.ts.map +1 -0
- package/dist/providers/NotificationProvider.js +66 -0
- package/dist/providers/SmartObjectProvider.d.ts +31 -0
- package/dist/providers/SmartObjectProvider.d.ts.map +1 -0
- package/dist/providers/SmartObjectProvider.js +80 -0
- package/dist/providers/VaultProvider.d.ts +10 -0
- package/dist/providers/VaultProvider.d.ts.map +1 -0
- package/dist/providers/VaultProvider.js +79 -0
- package/dist/providers/index.d.ts +5 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +4 -0
- package/dist/providers/smartObject/useEntityData.d.ts +29 -0
- package/dist/providers/smartObject/useEntityData.d.ts.map +1 -0
- package/dist/providers/smartObject/useEntityData.js +135 -0
- package/dist/providers/smartObject/useEntitySubscription.d.ts +14 -0
- package/dist/providers/smartObject/useEntitySubscription.d.ts.map +1 -0
- package/dist/providers/smartObject/useEntitySubscription.js +58 -0
- package/dist/providers/smartObject/useObjectSelection.d.ts +11 -0
- package/dist/providers/smartObject/useObjectSelection.d.ts.map +1 -0
- package/dist/providers/smartObject/useObjectSelection.js +27 -0
- package/dist/providers/smartObject/usePollingBackstop.d.ts +18 -0
- package/dist/providers/smartObject/usePollingBackstop.d.ts.map +1 -0
- package/dist/providers/smartObject/usePollingBackstop.js +38 -0
- package/dist/types/character.d.ts +21 -0
- package/dist/types/character.d.ts.map +1 -0
- package/dist/types/character.js +1 -0
- package/dist/types/contexts.d.ts +61 -0
- package/dist/types/contexts.d.ts.map +1 -0
- package/dist/types/contexts.js +6 -0
- package/dist/types/entity.d.ts +245 -0
- package/dist/types/entity.d.ts.map +1 -0
- package/dist/types/entity.js +6 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +5 -0
- package/dist/types/sponsoredTransaction.d.ts +26 -0
- package/dist/types/sponsoredTransaction.d.ts.map +1 -0
- package/dist/types/sponsoredTransaction.js +10 -0
- package/dist/types/types.d.ts +110 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/types.js +41 -0
- package/dist/types/worldApiReturnTypes.d.ts +68 -0
- package/dist/types/worldApiReturnTypes.d.ts.map +1 -0
- package/dist/types/worldApiReturnTypes.js +1 -0
- package/{utils/burnRate.ts → dist/utils/burnRate.d.ts} +4 -29
- package/dist/utils/burnRate.d.ts.map +1 -0
- package/dist/utils/burnRate.js +25 -0
- package/dist/utils/characters.d.ts +26 -0
- package/dist/utils/characters.d.ts.map +1 -0
- package/dist/utils/characters.js +84 -0
- package/dist/utils/constants.d.ts +153 -0
- package/dist/utils/constants.d.ts.map +1 -0
- package/dist/utils/constants.js +190 -0
- package/dist/utils/datahub.d.ts +40 -0
- package/dist/utils/datahub.d.ts.map +1 -0
- package/{utils/datahub.ts → dist/utils/datahub.js} +32 -25
- package/dist/utils/entity.d.ts +58 -0
- package/dist/utils/entity.d.ts.map +1 -0
- package/dist/utils/entity.js +386 -0
- package/dist/utils/errors.d.ts +18 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +128 -0
- package/dist/utils/events/entityEvents.d.ts +44 -0
- package/dist/utils/events/entityEvents.d.ts.map +1 -0
- package/dist/utils/events/entityEvents.js +95 -0
- package/dist/utils/events/entitySubscription.d.ts +30 -0
- package/dist/utils/events/entitySubscription.d.ts.map +1 -0
- package/dist/utils/events/entitySubscription.js +84 -0
- package/dist/utils/events/graphqlEventStream.d.ts +90 -0
- package/dist/utils/events/graphqlEventStream.d.ts.map +1 -0
- package/dist/utils/events/graphqlEventStream.js +198 -0
- package/dist/utils/events/refetchScheduler.d.ts +30 -0
- package/dist/utils/events/refetchScheduler.d.ts.map +1 -0
- package/dist/utils/events/refetchScheduler.js +57 -0
- package/dist/utils/events/sseClient.d.ts +42 -0
- package/dist/utils/events/sseClient.d.ts.map +1 -0
- package/dist/utils/events/sseClient.js +97 -0
- package/dist/utils/fuel.d.ts +231 -0
- package/dist/utils/fuel.d.ts.map +1 -0
- package/dist/utils/fuel.js +652 -0
- package/dist/utils/grid.d.ts +115 -0
- package/dist/utils/grid.d.ts.map +1 -0
- package/dist/utils/grid.js +115 -0
- package/dist/utils/index.d.ts +15 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +22 -0
- package/dist/utils/inventory.d.ts +3 -0
- package/dist/utils/inventory.d.ts.map +1 -0
- package/dist/utils/inventory.js +12 -0
- package/dist/utils/logger.d.ts +25 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +228 -0
- package/dist/utils/mapping.d.ts +30 -0
- package/dist/utils/mapping.d.ts.map +1 -0
- package/dist/utils/mapping.js +73 -0
- package/dist/utils/mvr/worldTypes.d.ts +35 -0
- package/dist/utils/mvr/worldTypes.d.ts.map +1 -0
- package/dist/utils/mvr/worldTypes.js +54 -0
- package/dist/utils/role.d.ts +116 -0
- package/dist/utils/role.d.ts.map +1 -0
- package/dist/utils/role.js +120 -0
- package/dist/utils/smartObject.d.ts +24 -0
- package/dist/utils/smartObject.d.ts.map +1 -0
- package/dist/utils/smartObject.js +24 -0
- package/dist/utils/utils.d.ts +133 -0
- package/dist/utils/utils.d.ts.map +1 -0
- package/dist/utils/utils.js +213 -0
- package/dist/wallet/features.d.ts +28 -0
- package/dist/wallet/features.d.ts.map +1 -0
- package/dist/wallet/features.js +22 -0
- package/dist/wallet/index.d.ts +9 -0
- package/dist/wallet/index.d.ts.map +1 -0
- package/dist/wallet/index.js +9 -0
- package/dist/wallet/utils.d.ts +71 -0
- package/dist/wallet/utils.d.ts.map +1 -0
- package/dist/wallet/utils.js +79 -0
- package/package.json +69 -35
- package/config/dapp-kit.ts +0 -20
- package/config/index.ts +0 -1
- package/graphql/client.ts +0 -578
- package/graphql/index.ts +0 -39
- package/graphql/types.ts +0 -468
- package/hooks/index.ts +0 -15
- package/hooks/useSmartObject.ts +0 -66
- package/hooks/useSponsoredTransaction.ts +0 -442
- package/index.ts +0 -88
- package/providers/EveFrontierProvider.tsx +0 -41
- package/providers/NotificationProvider.tsx +0 -108
- package/providers/SmartObjectProvider.tsx +0 -296
- package/providers/VaultProvider.tsx +0 -108
- package/providers/index.ts +0 -10
- package/types/contexts.ts +0 -67
- package/types/global.d.ts +0 -7
- package/types/index.ts +0 -4
- package/types/sponsoredTransaction.ts +0 -70
- package/types/types.ts +0 -198
- package/types/worldApiReturnTypes.ts +0 -144
- package/utils/__tests__/burnRate.test.ts +0 -121
- package/utils/__tests__/character.test.ts +0 -112
- package/utils/__tests__/characterOwnedObjects.test.ts +0 -225
- package/utils/__tests__/config.test.ts +0 -424
- package/utils/__tests__/datahub.test.ts +0 -58
- package/utils/__tests__/logger.test.ts +0 -145
- package/utils/__tests__/mapping.test.ts +0 -439
- package/utils/__tests__/utils.test.ts +0 -299
- package/utils/character.ts +0 -46
- package/utils/characterOwnedObjects.ts +0 -53
- package/utils/config.ts +0 -151
- package/utils/constants.ts +0 -254
- package/utils/errors.ts +0 -171
- package/utils/index.ts +0 -47
- package/utils/logger.ts +0 -300
- package/utils/mapping.ts +0 -118
- package/utils/transforms.ts +0 -263
- package/utils/utils.ts +0 -270
- package/wallet/features.ts +0 -136
- package/wallet/index.ts +0 -26
- package/wallet/utils.ts +0 -117
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type { EntityDrawKind, EntityPowerGrid } from '../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Display state of a power grid and its modules, worked out from the parsed
|
|
4
|
+
* grid. The chain stores draws and desired state but no reasons, so the
|
|
5
|
+
* reason a switched-on module gets no power is inferred here.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Why something switched on has no power. `notEnoughPower` is the Firm
|
|
9
|
+
* all-or-nothing rule: the Firm modules switched on need more than the
|
|
10
|
+
* generators make, so none of them draw.
|
|
11
|
+
*
|
|
12
|
+
* @category Utilities - Power
|
|
13
|
+
*/
|
|
14
|
+
export type NoPowerReason = 'mainOff' | 'generatorOff' | 'outOfFuel' | 'notEnoughPower';
|
|
15
|
+
/**
|
|
16
|
+
* - `online`: drawing all it asks for (or it asks for 0 and the grid is live)
|
|
17
|
+
* - `reduced`: an Elastic module drawing less than it asks for
|
|
18
|
+
* - `off`: switched off
|
|
19
|
+
* - `mainOff`: switched on, but the main breaker is off
|
|
20
|
+
* - `blocked`: switched on, main breaker on, but no power granted; see `reason`
|
|
21
|
+
*
|
|
22
|
+
* @category Utilities - Power
|
|
23
|
+
*/
|
|
24
|
+
export type ModuleStatus = 'online' | 'reduced' | 'off' | 'mainOff' | 'blocked';
|
|
25
|
+
/** @category Utilities - Power */
|
|
26
|
+
export interface ModuleState {
|
|
27
|
+
componentId: string;
|
|
28
|
+
status: ModuleStatus;
|
|
29
|
+
/** Set for `mainOff` and `blocked` */
|
|
30
|
+
reason: NoPowerReason | null;
|
|
31
|
+
drawKind: EntityDrawKind;
|
|
32
|
+
/** Fixed point at 10^4 */
|
|
33
|
+
powerReq: bigint;
|
|
34
|
+
/** Live draw, fixed point at 10^4; 0 once the fuel has run out */
|
|
35
|
+
draw: bigint;
|
|
36
|
+
}
|
|
37
|
+
/** @category Utilities - Power */
|
|
38
|
+
export type GeneratorStatus = 'running' | 'off' | 'mainOff' | 'stopped';
|
|
39
|
+
/** @category Utilities - Power */
|
|
40
|
+
export interface GeneratorState {
|
|
41
|
+
componentId: string;
|
|
42
|
+
/** `stopped`: switched on, but out of fuel */
|
|
43
|
+
status: GeneratorStatus;
|
|
44
|
+
/** Fixed point at 10^4 */
|
|
45
|
+
maxOutputMw: bigint;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* - `online`: main breaker on, a generator running, fuel left
|
|
49
|
+
* - `off`: main breaker off
|
|
50
|
+
* - `noPower`: main breaker on, but no generator running or no fuel; see `reason`
|
|
51
|
+
*
|
|
52
|
+
* @category Utilities - Power
|
|
53
|
+
*/
|
|
54
|
+
export type GridStatus = 'online' | 'off' | 'noPower';
|
|
55
|
+
/**
|
|
56
|
+
* Power and fuel values are fixed point at 10^4 whatever the grid's model
|
|
57
|
+
* (see `normalizeMw` and `normalizeFuel`); `fuelUnit` says what a whole unit
|
|
58
|
+
* of fuel is.
|
|
59
|
+
*
|
|
60
|
+
* @category Utilities - Power
|
|
61
|
+
*/
|
|
62
|
+
export interface GridSummary {
|
|
63
|
+
status: GridStatus;
|
|
64
|
+
reason: NoPowerReason | null;
|
|
65
|
+
/** Output of the generators that are on (`capacity_mw`) */
|
|
66
|
+
outputMw: bigint;
|
|
67
|
+
/** MW drawn now; 0 once the fuel has run out */
|
|
68
|
+
drawMw: bigint;
|
|
69
|
+
/** Usable capacity left; 0 unless the grid is online */
|
|
70
|
+
headroomMw: bigint;
|
|
71
|
+
/** Modules `online` or `reduced` */
|
|
72
|
+
modulesOnline: number;
|
|
73
|
+
modulesTotal: number;
|
|
74
|
+
fuelSettled: bigint;
|
|
75
|
+
fuelNow: bigint;
|
|
76
|
+
fuelCapacity: bigint;
|
|
77
|
+
/** Fuel now as a fraction of capacity, 0 to 1; 0 when there is no capacity */
|
|
78
|
+
fuelFraction: number;
|
|
79
|
+
/** At the current draw; 0 when nothing draws */
|
|
80
|
+
fuelBurnPerHour: bigint;
|
|
81
|
+
/** Null when nothing burns */
|
|
82
|
+
msUntilEmpty: number | null;
|
|
83
|
+
/** What a whole unit of fuel is: abstract `units`, or `kg` on a `pools` grid */
|
|
84
|
+
fuelUnit: 'units' | 'kg';
|
|
85
|
+
/**
|
|
86
|
+
* `pools` grids only: the usable impulse every burning generator shares,
|
|
87
|
+
* fixed point; null when nothing burns or generators burn at different
|
|
88
|
+
* impulses, and always null on a `fuelFactor` grid
|
|
89
|
+
*/
|
|
90
|
+
burnImpulse: bigint | null;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* The state of every module on the grid, in connect order.
|
|
94
|
+
*
|
|
95
|
+
* @category Utilities - Power
|
|
96
|
+
* @param grid - Parsed power grid
|
|
97
|
+
* @param nowMs - Current time in ms since the epoch, to project fuel burn
|
|
98
|
+
*/
|
|
99
|
+
export declare function moduleStates(grid: EntityPowerGrid, nowMs: number): ModuleState[];
|
|
100
|
+
/**
|
|
101
|
+
* The state of every generator on the grid. A generator is `stopped` when the
|
|
102
|
+
* grid's fuel has run out, or on a `pools` grid when its own fuel type's pool
|
|
103
|
+
* has.
|
|
104
|
+
*
|
|
105
|
+
* @category Utilities - Power
|
|
106
|
+
*/
|
|
107
|
+
export declare function generatorStates(grid: EntityPowerGrid, nowMs: number): GeneratorState[];
|
|
108
|
+
/**
|
|
109
|
+
* The grid at a glance: whether it is running and why not, output, draw,
|
|
110
|
+
* headroom, how many modules are online, and fuel now and time left.
|
|
111
|
+
*
|
|
112
|
+
* @category Utilities - Power
|
|
113
|
+
*/
|
|
114
|
+
export declare function gridSummary(grid: EntityPowerGrid, nowMs: number): GridSummary;
|
|
115
|
+
//# sourceMappingURL=grid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grid.d.ts","sourceRoot":"","sources":["../../utils/grid.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAa/D;;;;GAIG;AAEH;;;;;;GAMG;AACH,MAAM,MAAM,aAAa,GACrB,SAAS,GACT,cAAc,GACd,WAAW,GACX,gBAAgB,CAAA;AAEpB;;;;;;;;GAQG;AACH,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,SAAS,GAAG,KAAK,GAAG,SAAS,GAAG,SAAS,CAAA;AAE/E,kCAAkC;AAClC,MAAM,WAAW,WAAW;IAC1B,WAAW,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,YAAY,CAAA;IACpB,sCAAsC;IACtC,MAAM,EAAE,aAAa,GAAG,IAAI,CAAA;IAC5B,QAAQ,EAAE,cAAc,CAAA;IACxB,0BAA0B;IAC1B,QAAQ,EAAE,MAAM,CAAA;IAChB,kEAAkE;IAClE,IAAI,EAAE,MAAM,CAAA;CACb;AAED,kCAAkC;AAClC,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,KAAK,GAAG,SAAS,GAAG,SAAS,CAAA;AAEvE,kCAAkC;AAClC,MAAM,WAAW,cAAc;IAC7B,WAAW,EAAE,MAAM,CAAA;IACnB,8CAA8C;IAC9C,MAAM,EAAE,eAAe,CAAA;IACvB,0BAA0B;IAC1B,WAAW,EAAE,MAAM,CAAA;CACpB;AAED;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,KAAK,GAAG,SAAS,CAAA;AAErD;;;;;;GAMG;AACH,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,UAAU,CAAA;IAClB,MAAM,EAAE,aAAa,GAAG,IAAI,CAAA;IAC5B,2DAA2D;IAC3D,QAAQ,EAAE,MAAM,CAAA;IAChB,gDAAgD;IAChD,MAAM,EAAE,MAAM,CAAA;IACd,wDAAwD;IACxD,UAAU,EAAE,MAAM,CAAA;IAClB,oCAAoC;IACpC,aAAa,EAAE,MAAM,CAAA;IACrB,YAAY,EAAE,MAAM,CAAA;IACpB,WAAW,EAAE,MAAM,CAAA;IACnB,OAAO,EAAE,MAAM,CAAA;IACf,YAAY,EAAE,MAAM,CAAA;IACpB,8EAA8E;IAC9E,YAAY,EAAE,MAAM,CAAA;IACpB,gDAAgD;IAChD,eAAe,EAAE,MAAM,CAAA;IACvB,8BAA8B;IAC9B,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,gFAAgF;IAChF,QAAQ,EAAE,OAAO,GAAG,IAAI,CAAA;IACxB;;;;OAIG;IACH,WAAW,EAAE,MAAM,GAAG,IAAI,CAAA;CAC3B;AAcD;;;;;;GAMG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,eAAe,EACrB,KAAK,EAAE,MAAM,GACZ,WAAW,EAAE,CA6Bf;AAaD;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,eAAe,EACrB,KAAK,EAAE,MAAM,GACZ,cAAc,EAAE,CAalB;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,GAAG,WAAW,CAqC7E"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { burnBreakdown, fuelBurnPerHour, fuelUnit, msUntilEmpty, normalizeFuel, normalizeMw, projectGrid, sharedBurnImpulse, } from './fuel.js';
|
|
2
|
+
function gridState(live) {
|
|
3
|
+
if (!live.on)
|
|
4
|
+
return { status: 'off', reason: 'mainOff' };
|
|
5
|
+
if (live.fuelNow === 0n)
|
|
6
|
+
return { status: 'noPower', reason: 'outOfFuel' };
|
|
7
|
+
if (live.capacityMw === 0n) {
|
|
8
|
+
return { status: 'noPower', reason: 'generatorOff' };
|
|
9
|
+
}
|
|
10
|
+
return { status: 'online', reason: null };
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The state of every module on the grid, in connect order.
|
|
14
|
+
*
|
|
15
|
+
* @category Utilities - Power
|
|
16
|
+
* @param grid - Parsed power grid
|
|
17
|
+
* @param nowMs - Current time in ms since the epoch, to project fuel burn
|
|
18
|
+
*/
|
|
19
|
+
export function moduleStates(grid, nowMs) {
|
|
20
|
+
const projection = projectGrid(grid, nowMs);
|
|
21
|
+
const live = gridState(projection);
|
|
22
|
+
return Object.entries(grid.modules).map(([componentId, module]) => {
|
|
23
|
+
const powerReq = normalizeMw(grid, module.powerReq);
|
|
24
|
+
// `module_draw` reads 0 once nothing can feed it
|
|
25
|
+
const draw = normalizeMw(grid, projection.draws[componentId] ?? 0n);
|
|
26
|
+
const state = (status, reason = null) => ({
|
|
27
|
+
componentId,
|
|
28
|
+
status,
|
|
29
|
+
reason,
|
|
30
|
+
drawKind: module.drawKind,
|
|
31
|
+
powerReq,
|
|
32
|
+
draw,
|
|
33
|
+
});
|
|
34
|
+
if (!module.desiredOnline)
|
|
35
|
+
return state('off');
|
|
36
|
+
if (!projection.on)
|
|
37
|
+
return state('mainOff', 'mainOff');
|
|
38
|
+
if (live.status !== 'online')
|
|
39
|
+
return state('blocked', live.reason);
|
|
40
|
+
if (powerReq === 0n || draw >= powerReq)
|
|
41
|
+
return state('online');
|
|
42
|
+
// Only Elastic modules take less than they ask for; Firm ones get all or nothing
|
|
43
|
+
if (draw > 0n) {
|
|
44
|
+
return state(module.drawKind === 'Elastic' ? 'reduced' : 'online');
|
|
45
|
+
}
|
|
46
|
+
return state('blocked', 'notEnoughPower');
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
function generatorStatus(online, gridOn, fed) {
|
|
50
|
+
if (!online)
|
|
51
|
+
return 'off';
|
|
52
|
+
if (!gridOn)
|
|
53
|
+
return 'mainOff';
|
|
54
|
+
if (!fed)
|
|
55
|
+
return 'stopped';
|
|
56
|
+
return 'running';
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The state of every generator on the grid. A generator is `stopped` when the
|
|
60
|
+
* grid's fuel has run out, or on a `pools` grid when its own fuel type's pool
|
|
61
|
+
* has.
|
|
62
|
+
*
|
|
63
|
+
* @category Utilities - Power
|
|
64
|
+
*/
|
|
65
|
+
export function generatorStates(grid, nowMs) {
|
|
66
|
+
const live = projectGrid(grid, nowMs);
|
|
67
|
+
return Object.entries(grid.generators).map(([componentId, generator]) => ({
|
|
68
|
+
componentId,
|
|
69
|
+
status: generatorStatus(generator.online, live.on, grid.model === 'pools'
|
|
70
|
+
? (live.outputs[componentId] ?? 0n) > 0n
|
|
71
|
+
: live.fuelNow > 0n),
|
|
72
|
+
maxOutputMw: normalizeMw(grid, generator.maxOutputMw),
|
|
73
|
+
}));
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* The grid at a glance: whether it is running and why not, output, draw,
|
|
77
|
+
* headroom, how many modules are online, and fuel now and time left.
|
|
78
|
+
*
|
|
79
|
+
* @category Utilities - Power
|
|
80
|
+
*/
|
|
81
|
+
export function gridSummary(grid, nowMs) {
|
|
82
|
+
const projection = projectGrid(grid, nowMs);
|
|
83
|
+
const live = gridState(projection);
|
|
84
|
+
const outputMw = normalizeMw(grid, projection.capacityMw);
|
|
85
|
+
const drawMw = projection.fuelNow === 0n
|
|
86
|
+
? 0n
|
|
87
|
+
: normalizeMw(grid, Object.values(projection.draws).reduce((sum, d) => sum + d, 0n));
|
|
88
|
+
const modules = moduleStates(grid, nowMs);
|
|
89
|
+
const capacity = BigInt(grid.fuelCapacity);
|
|
90
|
+
return {
|
|
91
|
+
status: live.status,
|
|
92
|
+
reason: live.reason,
|
|
93
|
+
outputMw,
|
|
94
|
+
drawMw,
|
|
95
|
+
headroomMw: live.status === 'online' && outputMw > drawMw ? outputMw - drawMw : 0n,
|
|
96
|
+
modulesOnline: modules.filter((m) => m.status === 'online' || m.status === 'reduced').length,
|
|
97
|
+
modulesTotal: modules.length,
|
|
98
|
+
fuelSettled: normalizeFuel(grid, grid.fuelQuantity),
|
|
99
|
+
fuelNow: normalizeFuel(grid, projection.fuelNow),
|
|
100
|
+
fuelCapacity: normalizeFuel(grid, capacity),
|
|
101
|
+
fuelFraction: capacity > 0n ? Number(projection.fuelNow) / Number(capacity) : 0,
|
|
102
|
+
fuelBurnPerHour: projection.fuelNow === 0n
|
|
103
|
+
? 0n
|
|
104
|
+
: normalizeFuel(grid, fuelBurnPerHour(grid, nowMs)),
|
|
105
|
+
msUntilEmpty: msUntilEmpty(grid, nowMs),
|
|
106
|
+
fuelUnit: fuelUnit(grid),
|
|
107
|
+
burnImpulse: impulseOf(grid, projection.fuelNow, nowMs),
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
function impulseOf(grid, fuelNow, nowMs) {
|
|
111
|
+
if (fuelNow === 0n)
|
|
112
|
+
return null;
|
|
113
|
+
const impulse = sharedBurnImpulse(burnBreakdown(grid, nowMs));
|
|
114
|
+
return impulse === null ? null : normalizeFuel(grid, impulse);
|
|
115
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { WORLD_TYPE_KEYS, type WorldTypeKey, } from '@evefrontier/wallet-core/tenant';
|
|
2
|
+
export { type AdjustedBurnRate, getAdjustedBurnRate } from './burnRate.js';
|
|
3
|
+
export { fetchCharacterDirectory, searchCharacters } from './characters.js';
|
|
4
|
+
export * from './constants.js';
|
|
5
|
+
export { getDatahubGameInfo, typeNamesFrom } from './datahub.js';
|
|
6
|
+
export { fetchEntity, fetchEntityOwner, isEntity, parseEntity, type RawEntity, } from './entity.js';
|
|
7
|
+
export type { ErrorType } from './errors.js';
|
|
8
|
+
export { ERROR_MESSAGES, ERRORS, parseErrorFromMessage } from './errors.js';
|
|
9
|
+
export { type BurnBreakdown, burnBreakdown, FUEL_SCALE, fromFixed, fuelBurn, fuelBurnPerHour, fuelFactor, fuelScale, fuelUnit, type GeneratorBurnInput, type GridProjection, generatorBurn, generatorOutput, msUntilEmpty, normalizeFuel, normalizeMw, POOLS_FUEL_SCALE, poolGeneratorBurn, powerScale, projectedFuel, projectGrid, sharedBurnImpulse, usedMw, volatilityShare, } from './fuel.js';
|
|
10
|
+
export { type GeneratorState, type GeneratorStatus, type GridStatus, type GridSummary, generatorStates, gridSummary, type ModuleState, type ModuleStatus, moduleStates, type NoPowerReason, } from './grid.js';
|
|
11
|
+
export * from './logger.js';
|
|
12
|
+
export { getObjectId, getRegistryAddress, parseStatus, } from './mapping.js';
|
|
13
|
+
export { canManage, type DirectoryNeedInput, type EntityRole, type EntityRoleInput, findCharacterByWallet, getEntityRole, isController, isFullAddress, type NewControllerResult, needsCharacterDirectory, resolveNewController, sameAddress, } from './role.js';
|
|
14
|
+
export * from './utils.js';
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,KAAK,YAAY,GAClB,MAAM,iCAAiC,CAAA;AACxC,OAAO,EAAE,KAAK,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAEvE,OAAO,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAExE,cAAc,aAAa,CAAA;AAE3B,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAE7D,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,QAAQ,EACR,WAAW,EACX,KAAK,SAAS,GACf,MAAM,UAAU,CAAA;AACjB,YAAY,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAEzC,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAA;AAExE,OAAO,EACL,KAAK,aAAa,EAClB,aAAa,EACb,UAAU,EACV,SAAS,EACT,QAAQ,EACR,eAAe,EACf,UAAU,EACV,SAAS,EACT,QAAQ,EACR,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,aAAa,EACb,eAAe,EACf,YAAY,EACZ,aAAa,EACb,WAAW,EACX,gBAAgB,EAChB,iBAAiB,EACjB,UAAU,EACV,aAAa,EACb,WAAW,EACX,iBAAiB,EACjB,MAAM,EACN,eAAe,GAChB,MAAM,QAAQ,CAAA;AACf,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,eAAe,EACf,WAAW,EACX,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,YAAY,EACZ,KAAK,aAAa,GACnB,MAAM,QAAQ,CAAA;AAEf,cAAc,UAAU,CAAA;AACxB,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,WAAW,GACZ,MAAM,WAAW,CAAA;AAElB,OAAO,EACL,SAAS,EACT,KAAK,kBAAkB,EACvB,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,qBAAqB,EACrB,aAAa,EACb,YAAY,EACZ,aAAa,EACb,KAAK,mBAAmB,EACxB,uBAAuB,EACvB,oBAAoB,EACpB,WAAW,GACZ,MAAM,QAAQ,CAAA;AAEf,cAAc,SAAS,CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export { WORLD_TYPE_KEYS, } from '@evefrontier/wallet-core/tenant';
|
|
2
|
+
export { getAdjustedBurnRate } from './burnRate.js';
|
|
3
|
+
// Characters: the directory from world events, and search over it
|
|
4
|
+
export { fetchCharacterDirectory, searchCharacters } from './characters.js';
|
|
5
|
+
// Constants
|
|
6
|
+
export * from './constants.js';
|
|
7
|
+
// Datahub utilities
|
|
8
|
+
export { getDatahubGameInfo, typeNamesFrom } from './datahub.js';
|
|
9
|
+
// World entity utilities
|
|
10
|
+
export { fetchEntity, fetchEntityOwner, isEntity, parseEntity, } from './entity.js';
|
|
11
|
+
// Error handling
|
|
12
|
+
export { ERROR_MESSAGES, ERRORS, parseErrorFromMessage } from './errors.js';
|
|
13
|
+
// Power grid: fuel burn (port of power::fuel_math) and display state
|
|
14
|
+
export { burnBreakdown, FUEL_SCALE, fromFixed, fuelBurn, fuelBurnPerHour, fuelFactor, fuelScale, fuelUnit, generatorBurn, generatorOutput, msUntilEmpty, normalizeFuel, normalizeMw, POOLS_FUEL_SCALE, poolGeneratorBurn, powerScale, projectedFuel, projectGrid, sharedBurnImpulse, usedMw, volatilityShare, } from './fuel.js';
|
|
15
|
+
export { generatorStates, gridSummary, moduleStates, } from './grid.js';
|
|
16
|
+
// Logging
|
|
17
|
+
export * from './logger.js';
|
|
18
|
+
export { getObjectId, getRegistryAddress, parseStatus, } from './mapping.js';
|
|
19
|
+
// Roles on an entity: shell, controller, visitor
|
|
20
|
+
export { canManage, findCharacterByWallet, getEntityRole, isController, isFullAddress, needsCharacterDirectory, resolveNewController, sameAddress, } from './role.js';
|
|
21
|
+
// General utilities
|
|
22
|
+
export * from './utils.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inventory.d.ts","sourceRoot":"","sources":["../../utils/inventory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAO7C,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,aAAa,EAAE,GAAG,SAAS,GACjC,aAAa,EAAE,CAOjB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
function toFiniteNumber(value, fallback = 0) {
|
|
2
|
+
const numberValue = Number(value);
|
|
3
|
+
return Number.isFinite(numberValue) ? numberValue : fallback;
|
|
4
|
+
}
|
|
5
|
+
export function sortInventoryItemsByQuantity(items) {
|
|
6
|
+
return [...(items ?? [])].sort((a, b) => {
|
|
7
|
+
const quantityDifference = toFiniteNumber(b.quantity) - toFiniteNumber(a.quantity);
|
|
8
|
+
if (quantityDifference !== 0)
|
|
9
|
+
return quantityDifference;
|
|
10
|
+
return toFiniteNumber(a.type_id) - toFiniteNumber(b.type_id);
|
|
11
|
+
});
|
|
12
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { CreateLoggerOptions, Logger, LogLevel } from '../types/index.js';
|
|
2
|
+
/** Inputs for {@link resolveLogLevelFromEnv} (mirrors Vite `import.meta.env`). */
|
|
3
|
+
export type ResolveLogLevelFromEnvOptions = {
|
|
4
|
+
/** `import.meta.env.VITE_LOG_LEVEL` — when set to a valid level, overrides mode. */
|
|
5
|
+
viteLogLevel?: string | undefined;
|
|
6
|
+
/** `import.meta.env.MODE` — `production` → `error`, `test` → `warn`, else `debug`. */
|
|
7
|
+
viteMode?: string | undefined;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Resolves log level from `VITE_LOG_LEVEL` (if a valid level) and Vite `MODE`.
|
|
11
|
+
* Exported for unit tests; {@link createLogger} uses the snapshot at module load.
|
|
12
|
+
*/
|
|
13
|
+
export declare function resolveLogLevelFromEnv(options: ResolveLogLevelFromEnvOptions): LogLevel;
|
|
14
|
+
/**
|
|
15
|
+
* Create a logger scoped to the current module. If no scope is provided, the
|
|
16
|
+
* logger automatically derives the filename (plus parent folder) from the call
|
|
17
|
+
* site so logs stay consistent without manual strings.
|
|
18
|
+
*/
|
|
19
|
+
export declare const createLogger: ({ scope, level, }?: CreateLoggerOptions) => Logger;
|
|
20
|
+
/**
|
|
21
|
+
* Default logger instance scoped to the application root. Prefer using
|
|
22
|
+
* module-level loggers (via `createLogger()`) for better call-site context.
|
|
23
|
+
*/
|
|
24
|
+
export declare const logger: Logger;
|
|
25
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../utils/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EAGnB,MAAM,EAEN,QAAQ,EAET,MAAM,UAAU,CAAA;AAqBjB,kFAAkF;AAClF,MAAM,MAAM,6BAA6B,GAAG;IAC1C,oFAAoF;IACpF,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACjC,sFAAsF;IACtF,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAC9B,CAAA;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,6BAA6B,GACrC,QAAQ,CAgBV;AA2MD;;;;GAIG;AACH,eAAO,MAAM,YAAY,uBAGtB,mBAAmB,KAAQ,MAmC7B,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,MAAM,QAAiB,CAAA"}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
const LOG_LEVELS = ['silent', 'error', 'warn', 'info', 'debug'];
|
|
2
|
+
const LOGGER_SOURCE_HINTS = ['logger.ts', 'logger.js', 'logger.mjs'];
|
|
3
|
+
const isLogLevel = (value) => {
|
|
4
|
+
if (!value) {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
return LOG_LEVELS.includes(value.toLowerCase());
|
|
8
|
+
};
|
|
9
|
+
const getProcessObject = () => {
|
|
10
|
+
try {
|
|
11
|
+
return globalThis.process;
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Resolves log level from `VITE_LOG_LEVEL` (if a valid level) and Vite `MODE`.
|
|
19
|
+
* Exported for unit tests; {@link createLogger} uses the snapshot at module load.
|
|
20
|
+
*/
|
|
21
|
+
export function resolveLogLevelFromEnv(options) {
|
|
22
|
+
const { viteLogLevel, viteMode } = options;
|
|
23
|
+
if (isLogLevel(viteLogLevel)) {
|
|
24
|
+
return viteLogLevel.toLowerCase();
|
|
25
|
+
}
|
|
26
|
+
if (viteMode === 'production') {
|
|
27
|
+
return 'error';
|
|
28
|
+
}
|
|
29
|
+
if (viteMode === 'test') {
|
|
30
|
+
return 'warn';
|
|
31
|
+
}
|
|
32
|
+
return 'debug';
|
|
33
|
+
}
|
|
34
|
+
const resolveEnvLogLevel = () => {
|
|
35
|
+
return resolveLogLevelFromEnv({
|
|
36
|
+
viteLogLevel: import.meta.env.VITE_LOG_LEVEL,
|
|
37
|
+
viteMode: import.meta.env.MODE,
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
const normalizeSeparators = (path) => {
|
|
41
|
+
return path.replace(/\\/g, '/');
|
|
42
|
+
};
|
|
43
|
+
const stripOrigin = (path) => {
|
|
44
|
+
if (typeof window !== 'undefined' && window.location?.origin) {
|
|
45
|
+
return path.replace(window.location.origin, '');
|
|
46
|
+
}
|
|
47
|
+
return path;
|
|
48
|
+
};
|
|
49
|
+
const stripWorkspaceRoot = (path) => {
|
|
50
|
+
try {
|
|
51
|
+
const globalProcess = getProcessObject();
|
|
52
|
+
if (globalProcess && typeof globalProcess.cwd === 'function') {
|
|
53
|
+
const cwd = normalizeSeparators(globalProcess.cwd());
|
|
54
|
+
if (path.startsWith(cwd)) {
|
|
55
|
+
return path.slice(cwd.length);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
// Ignore if process is unavailable
|
|
61
|
+
}
|
|
62
|
+
return path;
|
|
63
|
+
};
|
|
64
|
+
const sanitizeFilePath = (path) => {
|
|
65
|
+
if (!path) {
|
|
66
|
+
return '';
|
|
67
|
+
}
|
|
68
|
+
let cleaned = normalizeSeparators(path);
|
|
69
|
+
cleaned = cleaned.replace(/^webpack-internal:\/\/\/|^vite:\/\/|^file:\/\//, '');
|
|
70
|
+
cleaned = stripOrigin(cleaned);
|
|
71
|
+
cleaned = stripWorkspaceRoot(cleaned);
|
|
72
|
+
cleaned = cleaned.split(/[?#]/)[0] ?? '';
|
|
73
|
+
return cleaned;
|
|
74
|
+
};
|
|
75
|
+
const parseStackLine = (line) => {
|
|
76
|
+
const match = line.match(/(?:\()?(.*?):(\d+):(\d+)\)?$/);
|
|
77
|
+
if (!match) {
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
const [, rawPath, lineNumber, columnNumber] = match;
|
|
81
|
+
if (!rawPath || !lineNumber || !columnNumber) {
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
filePath: rawPath,
|
|
86
|
+
lineNumber: Number(lineNumber),
|
|
87
|
+
columnNumber: Number(columnNumber),
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
const captureStack = () => {
|
|
91
|
+
try {
|
|
92
|
+
return new Error().stack;
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
const getCallerFrameFromStack = (stack) => {
|
|
99
|
+
if (!stack) {
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
const lines = stack.split('\n').slice(1);
|
|
103
|
+
for (const rawLine of lines) {
|
|
104
|
+
const line = rawLine.trim();
|
|
105
|
+
if (!line ||
|
|
106
|
+
LOGGER_SOURCE_HINTS.some((hint) => line.includes(hint)) ||
|
|
107
|
+
line.includes('node:internal')) {
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
const frame = parseStackLine(line);
|
|
111
|
+
if (frame) {
|
|
112
|
+
return frame;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return undefined;
|
|
116
|
+
};
|
|
117
|
+
const deriveScopeFromPath = (filePath) => {
|
|
118
|
+
if (!filePath) {
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
const cleaned = sanitizeFilePath(filePath);
|
|
122
|
+
const segments = cleaned.split('/').filter(Boolean);
|
|
123
|
+
if (segments.length === 0) {
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
const fileName = segments.pop();
|
|
127
|
+
if (!fileName) {
|
|
128
|
+
return undefined;
|
|
129
|
+
}
|
|
130
|
+
const parent = segments.pop();
|
|
131
|
+
const baseName = fileName.replace(/\.[^.]+$/, '');
|
|
132
|
+
return parent ? `${parent}/${baseName}` : baseName;
|
|
133
|
+
};
|
|
134
|
+
const getLocationLabel = (frame) => {
|
|
135
|
+
if (!frame?.filePath) {
|
|
136
|
+
return undefined;
|
|
137
|
+
}
|
|
138
|
+
const cleaned = sanitizeFilePath(frame.filePath);
|
|
139
|
+
const parts = cleaned.split('/').filter(Boolean);
|
|
140
|
+
const shortPath = parts.length > 2 ? parts.slice(-2).join('/') : parts.join('/') || cleaned;
|
|
141
|
+
if (!shortPath) {
|
|
142
|
+
return undefined;
|
|
143
|
+
}
|
|
144
|
+
if (frame.lineNumber) {
|
|
145
|
+
return `${shortPath}:${frame.lineNumber}`;
|
|
146
|
+
}
|
|
147
|
+
return shortPath;
|
|
148
|
+
};
|
|
149
|
+
const resolveLoggerScope = (providedScope) => {
|
|
150
|
+
if (providedScope) {
|
|
151
|
+
return providedScope;
|
|
152
|
+
}
|
|
153
|
+
const frame = getCallerFrameFromStack(captureStack());
|
|
154
|
+
return deriveScopeFromPath(frame?.filePath);
|
|
155
|
+
};
|
|
156
|
+
const ENV_LOG_LEVEL = resolveEnvLogLevel();
|
|
157
|
+
const shouldLog = (requestedLevel, activeLevel) => {
|
|
158
|
+
return LOG_LEVELS.indexOf(requestedLevel) <= LOG_LEVELS.indexOf(activeLevel);
|
|
159
|
+
};
|
|
160
|
+
/**
|
|
161
|
+
* Builds the "[scope] (file:line)" prefix for a log call. The scope is left
|
|
162
|
+
* out when it matches what the call site's path already shows.
|
|
163
|
+
*/
|
|
164
|
+
const buildLogPrefix = (frame, resolvedScope) => {
|
|
165
|
+
const locationScopeCandidate = deriveScopeFromPath(frame?.filePath);
|
|
166
|
+
const showScope = resolvedScope &&
|
|
167
|
+
(!locationScopeCandidate || locationScopeCandidate !== resolvedScope);
|
|
168
|
+
const locationLabel = getLocationLabel(frame);
|
|
169
|
+
const prefixParts = [];
|
|
170
|
+
if (showScope) {
|
|
171
|
+
prefixParts.push(`[${resolvedScope}]`);
|
|
172
|
+
}
|
|
173
|
+
if (locationLabel) {
|
|
174
|
+
prefixParts.push(`(${locationLabel})`);
|
|
175
|
+
}
|
|
176
|
+
return prefixParts.join(' ');
|
|
177
|
+
};
|
|
178
|
+
const prependLogPrefix = (prefix, args) => {
|
|
179
|
+
if (!prefix) {
|
|
180
|
+
return args;
|
|
181
|
+
}
|
|
182
|
+
if (args.length === 0) {
|
|
183
|
+
return [prefix];
|
|
184
|
+
}
|
|
185
|
+
// Merge prefix into the first argument when it's a string so the first
|
|
186
|
+
// arg remains the console format string (e.g. "%s …" still works).
|
|
187
|
+
if (typeof args[0] === 'string') {
|
|
188
|
+
return [`${prefix} ${args[0]}`, ...args.slice(1)];
|
|
189
|
+
}
|
|
190
|
+
return [prefix, ...args];
|
|
191
|
+
};
|
|
192
|
+
/**
|
|
193
|
+
* Create a logger scoped to the current module. If no scope is provided, the
|
|
194
|
+
* logger automatically derives the filename (plus parent folder) from the call
|
|
195
|
+
* site so logs stay consistent without manual strings.
|
|
196
|
+
*/
|
|
197
|
+
export const createLogger = ({ scope, level = ENV_LOG_LEVEL, } = {}) => {
|
|
198
|
+
const resolvedScope = resolveLoggerScope(scope);
|
|
199
|
+
const log = (consoleMethod, logLevel) => (...args) => {
|
|
200
|
+
if (!shouldLog(logLevel, level)) {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
const method = (console?.[consoleMethod] ?? console.log);
|
|
204
|
+
if (!method) {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
const frame = getCallerFrameFromStack(captureStack());
|
|
208
|
+
const prefix = buildLogPrefix(frame, resolvedScope);
|
|
209
|
+
method.apply(console, prependLogPrefix(prefix, args));
|
|
210
|
+
};
|
|
211
|
+
return {
|
|
212
|
+
debug: log('debug', 'debug'),
|
|
213
|
+
info: log('info', 'info'),
|
|
214
|
+
warn: log('warn', 'warn'),
|
|
215
|
+
error: log('error', 'error'),
|
|
216
|
+
child: (childScope) => {
|
|
217
|
+
const nestedScope = resolvedScope && resolvedScope.length > 0
|
|
218
|
+
? `${resolvedScope}:${childScope}`
|
|
219
|
+
: childScope;
|
|
220
|
+
return createLogger({ scope: nestedScope, level });
|
|
221
|
+
},
|
|
222
|
+
};
|
|
223
|
+
};
|
|
224
|
+
/**
|
|
225
|
+
* Default logger instance scoped to the application root. Prefer using
|
|
226
|
+
* module-level loggers (via `createLogger()`) for better call-site context.
|
|
227
|
+
*/
|
|
228
|
+
export const logger = createLogger();
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { State } from '../types/index.js';
|
|
2
|
+
import { type TenantId } from './constants.js';
|
|
3
|
+
/**
|
|
4
|
+
* Convert raw status variant string to State enum
|
|
5
|
+
*
|
|
6
|
+
* @category Utilities - Mapping
|
|
7
|
+
*/
|
|
8
|
+
export declare function parseStatus(statusVariant: string | undefined): State;
|
|
9
|
+
/**
|
|
10
|
+
* Fetches the core ObjectRegistry singleton address from the chain.
|
|
11
|
+
* Each world tier has its own core package and registry; the tier comes from
|
|
12
|
+
* VITE_EVE_WORLD_TIER or the tenant (see {@link getWorldTier}).
|
|
13
|
+
* Caches the result per registry type to avoid repeated queries.
|
|
14
|
+
*
|
|
15
|
+
* @param tenant - Tenant whose tier to use when VITE_EVE_WORLD_TIER is unset
|
|
16
|
+
* @category Utilities - Mapping
|
|
17
|
+
*/
|
|
18
|
+
export declare function getRegistryAddress(tenant?: string): Promise<string>;
|
|
19
|
+
/**
|
|
20
|
+
* Derives an entity's object ID from its in-game ID and tenant, mirroring core
|
|
21
|
+
* `object_registry::derive_id` (a derived object over `EntityKey { id, tenant }`).
|
|
22
|
+
*
|
|
23
|
+
* @param itemId - The in-game item ID
|
|
24
|
+
* @param tenant - The tenant identifier (e.g. "utopia", "stillness")
|
|
25
|
+
* @returns The derived Sui object ID
|
|
26
|
+
*
|
|
27
|
+
* @category Utilities - Mapping
|
|
28
|
+
*/
|
|
29
|
+
export declare function getObjectId(itemId: string, tenant: string | TenantId): Promise<string>;
|
|
30
|
+
//# sourceMappingURL=mapping.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapping.d.ts","sourceRoot":"","sources":["../../utils/mapping.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAChC,OAAO,EAAuC,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAA;AAEhF;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,aAAa,EAAE,MAAM,GAAG,SAAS,GAAG,KAAK,CAiBpE;AAKD;;;;;;;;GAQG;AACH,wBAAsB,kBAAkB,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAezE;AAED;;;;;;;;;GASG;AACH,wBAAsB,WAAW,CAC/B,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,GAAG,QAAQ,GACxB,OAAO,CAAC,MAAM,CAAC,CAgBjB"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { bcs } from '@mysten/sui/bcs';
|
|
2
|
+
import { deriveObjectID } from '@mysten/sui/utils';
|
|
3
|
+
import { getSingletonObjectByType } from '../graphql/client.js';
|
|
4
|
+
import { State } from '../types/index.js';
|
|
5
|
+
import { getObjectRegistryType, getWorldType } from './constants.js';
|
|
6
|
+
/**
|
|
7
|
+
* Convert raw status variant string to State enum
|
|
8
|
+
*
|
|
9
|
+
* @category Utilities - Mapping
|
|
10
|
+
*/
|
|
11
|
+
export function parseStatus(statusVariant) {
|
|
12
|
+
if (!statusVariant)
|
|
13
|
+
return State.NULL;
|
|
14
|
+
switch (statusVariant.toUpperCase()) {
|
|
15
|
+
case 'ONLINE':
|
|
16
|
+
return State.ONLINE;
|
|
17
|
+
case 'OFFLINE':
|
|
18
|
+
return State.ANCHORED;
|
|
19
|
+
case 'ANCHORED':
|
|
20
|
+
return State.ANCHORED;
|
|
21
|
+
case 'UNANCHORED':
|
|
22
|
+
return State.UNANCHORED;
|
|
23
|
+
case 'DESTROYED':
|
|
24
|
+
return State.DESTROYED;
|
|
25
|
+
default:
|
|
26
|
+
return State.NULL;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
// Cache for the ObjectRegistry address, keyed by its type tag
|
|
30
|
+
const objectRegistryAddressCache = {};
|
|
31
|
+
/**
|
|
32
|
+
* Fetches the core ObjectRegistry singleton address from the chain.
|
|
33
|
+
* Each world tier has its own core package and registry; the tier comes from
|
|
34
|
+
* VITE_EVE_WORLD_TIER or the tenant (see {@link getWorldTier}).
|
|
35
|
+
* Caches the result per registry type to avoid repeated queries.
|
|
36
|
+
*
|
|
37
|
+
* @param tenant - Tenant whose tier to use when VITE_EVE_WORLD_TIER is unset
|
|
38
|
+
* @category Utilities - Mapping
|
|
39
|
+
*/
|
|
40
|
+
export async function getRegistryAddress(tenant) {
|
|
41
|
+
const registryType = getObjectRegistryType(tenant);
|
|
42
|
+
if (objectRegistryAddressCache[registryType]) {
|
|
43
|
+
return objectRegistryAddressCache[registryType];
|
|
44
|
+
}
|
|
45
|
+
const result = await getSingletonObjectByType(registryType);
|
|
46
|
+
const address = result.data?.objects?.nodes?.[0]?.address;
|
|
47
|
+
if (!address) {
|
|
48
|
+
throw new Error(`ObjectRegistry not found for type: ${registryType}`);
|
|
49
|
+
}
|
|
50
|
+
objectRegistryAddressCache[registryType] = address;
|
|
51
|
+
return address;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Derives an entity's object ID from its in-game ID and tenant, mirroring core
|
|
55
|
+
* `object_registry::derive_id` (a derived object over `EntityKey { id, tenant }`).
|
|
56
|
+
*
|
|
57
|
+
* @param itemId - The in-game item ID
|
|
58
|
+
* @param tenant - The tenant identifier (e.g. "utopia", "stillness")
|
|
59
|
+
* @returns The derived Sui object ID
|
|
60
|
+
*
|
|
61
|
+
* @category Utilities - Mapping
|
|
62
|
+
*/
|
|
63
|
+
export async function getObjectId(itemId, tenant) {
|
|
64
|
+
const registryAddress = await getRegistryAddress(tenant);
|
|
65
|
+
const key = bcs
|
|
66
|
+
.struct('EntityKey', {
|
|
67
|
+
id: bcs.u64(),
|
|
68
|
+
tenant: bcs.string(),
|
|
69
|
+
})
|
|
70
|
+
.serialize({ id: BigInt(itemId), tenant })
|
|
71
|
+
.toBytes();
|
|
72
|
+
return deriveObjectID(registryAddress, getWorldType('core::entity_key::EntityKey', tenant), key);
|
|
73
|
+
}
|