burnrate 0.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 +21 -0
- package/README.md +507 -0
- package/dist/cli/format.d.ts +13 -0
- package/dist/cli/format.js +319 -0
- package/dist/cli/index.d.ts +7 -0
- package/dist/cli/index.js +1121 -0
- package/dist/cli/setup.d.ts +8 -0
- package/dist/cli/setup.js +143 -0
- package/dist/core/async-engine.d.ts +411 -0
- package/dist/core/async-engine.js +2274 -0
- package/dist/core/async-worldgen.d.ts +19 -0
- package/dist/core/async-worldgen.js +221 -0
- package/dist/core/engine.d.ts +154 -0
- package/dist/core/engine.js +1104 -0
- package/dist/core/pathfinding.d.ts +38 -0
- package/dist/core/pathfinding.js +146 -0
- package/dist/core/types.d.ts +489 -0
- package/dist/core/types.js +359 -0
- package/dist/core/worldgen.d.ts +22 -0
- package/dist/core/worldgen.js +292 -0
- package/dist/db/database.d.ts +83 -0
- package/dist/db/database.js +829 -0
- package/dist/db/turso-database.d.ts +177 -0
- package/dist/db/turso-database.js +1586 -0
- package/dist/mcp/server.d.ts +7 -0
- package/dist/mcp/server.js +1877 -0
- package/dist/server/api.d.ts +8 -0
- package/dist/server/api.js +1234 -0
- package/dist/server/async-tick-server.d.ts +5 -0
- package/dist/server/async-tick-server.js +63 -0
- package/dist/server/errors.d.ts +78 -0
- package/dist/server/errors.js +156 -0
- package/dist/server/rate-limit.d.ts +22 -0
- package/dist/server/rate-limit.js +134 -0
- package/dist/server/tick-server.d.ts +9 -0
- package/dist/server/tick-server.js +114 -0
- package/dist/server/validation.d.ts +194 -0
- package/dist/server/validation.js +114 -0
- package/package.json +65 -0
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BURNRATE Database Layer (Turso/LibSQL)
|
|
3
|
+
* Multiplayer-ready persistence using Turso distributed SQLite
|
|
4
|
+
*/
|
|
5
|
+
import { InStatement } from '@libsql/client';
|
|
6
|
+
import { Zone, Route, Player, Faction, Shipment, Unit, MarketOrder, Contract, IntelReport, GameEvent, Inventory, FactionRank, IntelReportWithFreshness, SeasonScore, Doctrine, Webhook, ConditionalOrder, TimeWeightedOrder, AuditLogEntry } from '../core/types.js';
|
|
7
|
+
export declare class TursoDatabase {
|
|
8
|
+
private client;
|
|
9
|
+
constructor(url?: string, authToken?: string);
|
|
10
|
+
initialize(): Promise<void>;
|
|
11
|
+
/**
|
|
12
|
+
* Execute multiple statements in a single transaction.
|
|
13
|
+
* All statements succeed or all fail.
|
|
14
|
+
*/
|
|
15
|
+
transaction<T>(fn: (tx: TransactionContext) => Promise<T>): Promise<T>;
|
|
16
|
+
/**
|
|
17
|
+
* Execute a batch of independent statements efficiently.
|
|
18
|
+
* Not a transaction - some may succeed while others fail.
|
|
19
|
+
*/
|
|
20
|
+
batch(statements: InStatement[]): Promise<void>;
|
|
21
|
+
private initSchema;
|
|
22
|
+
getCurrentTick(): Promise<number>;
|
|
23
|
+
incrementTick(): Promise<number>;
|
|
24
|
+
getSeasonInfo(): Promise<{
|
|
25
|
+
seasonNumber: number;
|
|
26
|
+
seasonWeek: number;
|
|
27
|
+
}>;
|
|
28
|
+
createZone(zone: Omit<Zone, 'id'>): Promise<Zone>;
|
|
29
|
+
getZone(id: string): Promise<Zone | null>;
|
|
30
|
+
getAllZones(): Promise<Zone[]>;
|
|
31
|
+
updateZone(id: string, updates: Partial<Zone>): Promise<void>;
|
|
32
|
+
private rowToZone;
|
|
33
|
+
createRoute(route: Omit<Route, 'id'>): Promise<Route>;
|
|
34
|
+
getRoute(id: string): Promise<Route | null>;
|
|
35
|
+
getRoutesBetween(fromZoneId: string, toZoneId: string): Promise<Route[]>;
|
|
36
|
+
getRoutesFromZone(zoneId: string): Promise<Route[]>;
|
|
37
|
+
getAllRoutes(): Promise<Route[]>;
|
|
38
|
+
private rowToRoute;
|
|
39
|
+
createPlayer(name: string, startingZoneId: string): Promise<Player & {
|
|
40
|
+
apiKey: string;
|
|
41
|
+
}>;
|
|
42
|
+
getPlayer(id: string): Promise<Player | null>;
|
|
43
|
+
getPlayerByApiKey(apiKey: string): Promise<Player | null>;
|
|
44
|
+
getPlayerByName(name: string): Promise<Player | null>;
|
|
45
|
+
getAllPlayers(): Promise<Player[]>;
|
|
46
|
+
updatePlayer(id: string, updates: Partial<Player>): Promise<void>;
|
|
47
|
+
private rowToPlayer;
|
|
48
|
+
createFaction(name: string, tag: string, founderId: string): Promise<Faction>;
|
|
49
|
+
getFaction(id: string): Promise<Faction | null>;
|
|
50
|
+
getAllFactions(): Promise<Faction[]>;
|
|
51
|
+
private rowToFaction;
|
|
52
|
+
addFactionMember(factionId: string, playerId: string, rank?: FactionRank): Promise<void>;
|
|
53
|
+
removeFactionMember(factionId: string, playerId: string): Promise<void>;
|
|
54
|
+
createShipment(shipment: Omit<Shipment, 'id'>): Promise<Shipment>;
|
|
55
|
+
getShipment(id: string): Promise<Shipment | null>;
|
|
56
|
+
getActiveShipments(): Promise<Shipment[]>;
|
|
57
|
+
getPlayerShipments(playerId: string): Promise<Shipment[]>;
|
|
58
|
+
updateShipment(id: string, updates: Partial<Shipment>): Promise<void>;
|
|
59
|
+
private rowToShipment;
|
|
60
|
+
createUnit(unit: Omit<Unit, 'id'>): Promise<Unit>;
|
|
61
|
+
getUnit(id: string): Promise<Unit | null>;
|
|
62
|
+
getPlayerUnits(playerId: string): Promise<Unit[]>;
|
|
63
|
+
getUnitsForSaleAtZone(zoneId: string): Promise<Unit[]>;
|
|
64
|
+
updateUnit(id: string, updates: Partial<Unit>): Promise<void>;
|
|
65
|
+
deleteUnit(id: string): Promise<void>;
|
|
66
|
+
private rowToUnit;
|
|
67
|
+
createOrder(order: Omit<MarketOrder, 'id'>): Promise<MarketOrder>;
|
|
68
|
+
getOrdersForZone(zoneId: string, resource?: string): Promise<MarketOrder[]>;
|
|
69
|
+
updateOrder(id: string, quantity: number): Promise<void>;
|
|
70
|
+
private rowToOrder;
|
|
71
|
+
createContract(contract: Omit<Contract, 'id'>): Promise<Contract>;
|
|
72
|
+
getOpenContracts(): Promise<Contract[]>;
|
|
73
|
+
updateContract(id: string, updates: {
|
|
74
|
+
status?: string;
|
|
75
|
+
acceptedBy?: string;
|
|
76
|
+
}): Promise<void>;
|
|
77
|
+
private rowToContract;
|
|
78
|
+
createIntel(intel: Omit<IntelReport, 'id'>): Promise<IntelReport>;
|
|
79
|
+
getFactionIntel(factionId: string, limit?: number): Promise<IntelReport[]>;
|
|
80
|
+
private rowToIntel;
|
|
81
|
+
recordEvent(event: Omit<GameEvent, 'id'>): Promise<GameEvent>;
|
|
82
|
+
getEvents(options?: {
|
|
83
|
+
limit?: number;
|
|
84
|
+
type?: string;
|
|
85
|
+
actorId?: string;
|
|
86
|
+
}): Promise<GameEvent[]>;
|
|
87
|
+
getPlayerIntel(playerId: string, limit?: number): Promise<IntelReport[]>;
|
|
88
|
+
/**
|
|
89
|
+
* Get player intel with freshness calculation and data decay applied.
|
|
90
|
+
* This is the recommended method for retrieving intel for display.
|
|
91
|
+
*/
|
|
92
|
+
getPlayerIntelWithFreshness(playerId: string, limit?: number): Promise<IntelReportWithFreshness[]>;
|
|
93
|
+
/**
|
|
94
|
+
* Get faction intel with freshness calculation and data decay applied.
|
|
95
|
+
*/
|
|
96
|
+
getFactionIntelWithFreshness(factionId: string, limit?: number): Promise<IntelReportWithFreshness[]>;
|
|
97
|
+
/**
|
|
98
|
+
* Get the most recent intel on a specific target (zone or route).
|
|
99
|
+
* Returns intel with freshness applied.
|
|
100
|
+
*/
|
|
101
|
+
getTargetIntel(playerId: string, factionId: string | null, targetType: 'zone' | 'route', targetId: string): Promise<IntelReportWithFreshness | null>;
|
|
102
|
+
/**
|
|
103
|
+
* Delete expired intel older than a threshold to keep database clean.
|
|
104
|
+
* Called periodically during tick processing.
|
|
105
|
+
*/
|
|
106
|
+
cleanupExpiredIntel(maxAgeTicks?: number): Promise<number>;
|
|
107
|
+
/**
|
|
108
|
+
* Apply freshness calculation to raw intel data
|
|
109
|
+
*/
|
|
110
|
+
private applyFreshnessToIntel;
|
|
111
|
+
getContract(id: string): Promise<Contract | null>;
|
|
112
|
+
getContractsAtZone(zoneId: string): Promise<Contract[]>;
|
|
113
|
+
getPlayerContracts(playerId: string): Promise<Contract[]>;
|
|
114
|
+
getFactionMemberRank(factionId: string, playerId: string): Promise<FactionRank | null>;
|
|
115
|
+
updateFactionMemberRank(factionId: string, playerId: string, rank: FactionRank): Promise<void>;
|
|
116
|
+
updateFaction(id: string, updates: Partial<{
|
|
117
|
+
founderId: string;
|
|
118
|
+
treasury: Inventory;
|
|
119
|
+
officerWithdrawLimit: number;
|
|
120
|
+
doctrineHash: string | null;
|
|
121
|
+
upgrades: Faction['upgrades'];
|
|
122
|
+
relations: Record<string, 'allied' | 'neutral' | 'war'>;
|
|
123
|
+
}>): Promise<void>;
|
|
124
|
+
getOrCreateSeasonScore(seasonNumber: number, entityId: string, entityType: 'player' | 'faction', entityName: string): Promise<SeasonScore>;
|
|
125
|
+
incrementSeasonScore(seasonNumber: number, entityId: string, entityType: 'player' | 'faction', entityName: string, field: 'supplyDelivered' | 'shipmentsCompleted' | 'contractsCompleted' | 'reputationGained' | 'combatVictories', amount: number): Promise<void>;
|
|
126
|
+
updateSeasonZoneScores(seasonNumber: number): Promise<void>;
|
|
127
|
+
getSeasonLeaderboard(seasonNumber: number, entityType?: 'player' | 'faction', limit?: number): Promise<SeasonScore[]>;
|
|
128
|
+
getEntitySeasonScore(seasonNumber: number, entityId: string): Promise<SeasonScore | null>;
|
|
129
|
+
advanceSeason(): Promise<{
|
|
130
|
+
newSeason: number;
|
|
131
|
+
newWeek: number;
|
|
132
|
+
}>;
|
|
133
|
+
advanceWeek(): Promise<{
|
|
134
|
+
seasonNumber: number;
|
|
135
|
+
newWeek: number;
|
|
136
|
+
}>;
|
|
137
|
+
/**
|
|
138
|
+
* Reset the game world for a new season.
|
|
139
|
+
* Archives scores, resets zones/inventories, preserves accounts/licenses/factions.
|
|
140
|
+
*/
|
|
141
|
+
createDoctrine(factionId: string, title: string, content: string, createdBy: string): Promise<Doctrine>;
|
|
142
|
+
getFactionDoctrines(factionId: string): Promise<Doctrine[]>;
|
|
143
|
+
getDoctrine(id: string): Promise<Doctrine | null>;
|
|
144
|
+
updateDoctrine(id: string, content: string): Promise<void>;
|
|
145
|
+
deleteDoctrine(id: string): Promise<void>;
|
|
146
|
+
createWebhook(playerId: string, url: string, events: string[]): Promise<Webhook>;
|
|
147
|
+
getPlayerWebhooks(playerId: string): Promise<Webhook[]>;
|
|
148
|
+
deleteWebhook(id: string, playerId: string): Promise<boolean>;
|
|
149
|
+
getWebhooksForEvent(eventType: string): Promise<Webhook[]>;
|
|
150
|
+
updateWebhookStatus(id: string, lastTriggered: number, failCount: number): Promise<void>;
|
|
151
|
+
createConditionalOrder(order: Omit<ConditionalOrder, 'id'>): Promise<ConditionalOrder>;
|
|
152
|
+
getActiveConditionalOrders(): Promise<ConditionalOrder[]>;
|
|
153
|
+
updateConditionalOrderStatus(id: string, status: string): Promise<void>;
|
|
154
|
+
createTimeWeightedOrder(order: Omit<TimeWeightedOrder, 'id'>): Promise<TimeWeightedOrder>;
|
|
155
|
+
getActiveTimeWeightedOrders(): Promise<TimeWeightedOrder[]>;
|
|
156
|
+
updateTimeWeightedOrder(id: string, remainingQuantity: number): Promise<void>;
|
|
157
|
+
createAuditLog(factionId: string, playerId: string, action: string, details: Record<string, unknown>): Promise<void>;
|
|
158
|
+
getFactionAuditLogs(factionId: string, limit?: number): Promise<AuditLogEntry[]>;
|
|
159
|
+
seasonReset(newSeasonNumber: number): Promise<void>;
|
|
160
|
+
private rowToSeasonScore;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Collects statements to be executed in a transaction.
|
|
164
|
+
* Call add() to queue statements, they execute when transaction() completes.
|
|
165
|
+
*/
|
|
166
|
+
export declare class TransactionContext {
|
|
167
|
+
private statements;
|
|
168
|
+
constructor(statements: InStatement[]);
|
|
169
|
+
/**
|
|
170
|
+
* Add a statement to the transaction
|
|
171
|
+
*/
|
|
172
|
+
add(sql: string, args?: any[]): void;
|
|
173
|
+
/**
|
|
174
|
+
* Generate a UUID for use in the transaction
|
|
175
|
+
*/
|
|
176
|
+
uuid(): string;
|
|
177
|
+
}
|