@spacemolt/lib 15.0.0 → 15.0.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/dist/account.d.ts +1 -1
- package/dist/index.js +29 -4
- package/package.json +1 -1
package/dist/account.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ import type { AuthCredentials } from './auth/credentials.js';
|
|
|
15
15
|
import type { LoggedInPayload as LoggedInPayloadSchema, SubscribeMarketResponse, SubscribeObservationResponse } from './generated/openapi/types.gen.js';
|
|
16
16
|
import type { NotificationPayloads, TypedNotificationType } from './generated/notifications.gen.js';
|
|
17
17
|
import type { FleetPush, OkPush } from './push-frames.js';
|
|
18
|
-
import {
|
|
18
|
+
import { ConnectionClosedError } from './errors.js';
|
|
19
19
|
import { type MarketBook } from './state/market.js';
|
|
20
20
|
import { type ObservationView } from './state/observation.js';
|
|
21
21
|
import type { GameState, MutationAck, MutationResult, QueryResult, RawFrame, StateSection, WelcomeFrame } from './protocol.js';
|
package/dist/index.js
CHANGED
|
@@ -4308,9 +4308,16 @@ class Account {
|
|
|
4308
4308
|
});
|
|
4309
4309
|
}
|
|
4310
4310
|
makeSocket() {
|
|
4311
|
-
|
|
4312
|
-
|
|
4313
|
-
|
|
4311
|
+
const socket = new Socket({ url: this.url, webSocketFactory: this.webSocketFactory });
|
|
4312
|
+
socket.onFrame = (frame) => {
|
|
4313
|
+
if (this.socket === socket)
|
|
4314
|
+
this.routeFrame(frame);
|
|
4315
|
+
};
|
|
4316
|
+
socket.onClose = (err) => {
|
|
4317
|
+
if (this.socket === socket)
|
|
4318
|
+
this.handleClose(err);
|
|
4319
|
+
};
|
|
4320
|
+
this.socket = socket;
|
|
4314
4321
|
}
|
|
4315
4322
|
get state() {
|
|
4316
4323
|
return this.cache.snapshot();
|
|
@@ -4451,8 +4458,11 @@ class Account {
|
|
|
4451
4458
|
}
|
|
4452
4459
|
}
|
|
4453
4460
|
async refresh() {
|
|
4461
|
+
const revision = this.stateRevision;
|
|
4454
4462
|
const result = await this.commands.spacemolt.get_status();
|
|
4455
4463
|
const snapshot = requireStructuredContent(result, "spacemolt/get_status");
|
|
4464
|
+
if (revision !== this.stateRevision)
|
|
4465
|
+
return this.cache.snapshot();
|
|
4456
4466
|
const changed = this.cache.seed(snapshot);
|
|
4457
4467
|
if (changed.length)
|
|
4458
4468
|
this.stateRevision++;
|
|
@@ -4983,10 +4993,19 @@ class Account {
|
|
|
4983
4993
|
async reconnectOnce() {
|
|
4984
4994
|
if (!this.credentialsProvider)
|
|
4985
4995
|
throw new Error("reconnectOnce requires credentials");
|
|
4996
|
+
const stopIfClosed = () => {
|
|
4997
|
+
if (!this.userClosing)
|
|
4998
|
+
return;
|
|
4999
|
+
this.socket.close();
|
|
5000
|
+
throw new ConnectionClosedError("account was closed");
|
|
5001
|
+
};
|
|
5002
|
+
stopIfClosed();
|
|
4986
5003
|
this.socket.close();
|
|
4987
5004
|
this.makeSocket();
|
|
4988
5005
|
await this.open();
|
|
5006
|
+
stopIfClosed();
|
|
4989
5007
|
await this.authenticate(await this.credentialsProvider());
|
|
5008
|
+
stopIfClosed();
|
|
4990
5009
|
await this.resubscribe();
|
|
4991
5010
|
}
|
|
4992
5011
|
async resubscribe() {
|
|
@@ -5484,7 +5503,13 @@ class SpacemoltClient {
|
|
|
5484
5503
|
return;
|
|
5485
5504
|
}
|
|
5486
5505
|
this.reconnectingIds.add(id);
|
|
5487
|
-
|
|
5506
|
+
const wanted = () => this.connected.get(id) === account;
|
|
5507
|
+
this.enqueueRateLimited(() => this.withConnectRetry(async () => wanted() ? account.reconnectOnce() : undefined)).then(() => {
|
|
5508
|
+
if (wanted())
|
|
5509
|
+
this.notifyAccountReconnected(account);
|
|
5510
|
+
}).catch((reconnectErr) => {
|
|
5511
|
+
if (!wanted())
|
|
5512
|
+
return;
|
|
5488
5513
|
console.warn(`[spacemolt] failed to reconnect "${id}": ${reconnectErr}`);
|
|
5489
5514
|
this.connected.delete(id);
|
|
5490
5515
|
this.notifyAccountDisconnected(id, err);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spacemolt/lib",
|
|
3
|
-
"version": "15.0.
|
|
3
|
+
"version": "15.0.1",
|
|
4
4
|
"description": "The definitive TypeScript library for SpaceMolt. WebSocket-v2-first, multi-account, with local state caches. Internals are regenerated from the server's OpenAPI spec.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./dist/index.js",
|