chore(): tidier types for pending subs, bump axios to latest
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES6",
|
||||
"module": "commonjs"
|
||||
"target": "ES6",
|
||||
"module": "commonjs"
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"**/node_modules/*",
|
||||
"coverage",
|
||||
"doc"
|
||||
"node_modules",
|
||||
"**/node_modules/*",
|
||||
"coverage",
|
||||
"doc",
|
||||
"examples/ignored/*"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
15
package-lock.json
generated
15
package-lock.json
generated
@@ -9,7 +9,7 @@
|
||||
"version": "3.10.29",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"axios": "^1.6.6",
|
||||
"axios": "^1.7.9",
|
||||
"isomorphic-ws": "^4.0.1",
|
||||
"ws": "^7.4.0"
|
||||
},
|
||||
@@ -2294,9 +2294,10 @@
|
||||
"integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k="
|
||||
},
|
||||
"node_modules/axios": {
|
||||
"version": "1.7.7",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-1.7.7.tgz",
|
||||
"integrity": "sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==",
|
||||
"version": "1.7.9",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-1.7.9.tgz",
|
||||
"integrity": "sha512-LhLcE7Hbiryz8oMDdDptSrWowmB4Bl6RCt6sIJKpRB4XtVf0iEgewX3au/pJqm+Py1kCASkb/FFKjxQaLtxJvw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"follow-redirects": "^1.15.6",
|
||||
"form-data": "^4.0.0",
|
||||
@@ -8784,9 +8785,9 @@
|
||||
"integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k="
|
||||
},
|
||||
"axios": {
|
||||
"version": "1.7.7",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-1.7.7.tgz",
|
||||
"integrity": "sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==",
|
||||
"version": "1.7.9",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-1.7.9.tgz",
|
||||
"integrity": "sha512-LhLcE7Hbiryz8oMDdDptSrWowmB4Bl6RCt6sIJKpRB4XtVf0iEgewX3au/pJqm+Py1kCASkb/FFKjxQaLtxJvw==",
|
||||
"requires": {
|
||||
"follow-redirects": "^1.15.6",
|
||||
"form-data": "^4.0.0",
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
"Stefan Aebischer <os@pixtron.ch> (https://pixtron.ch)"
|
||||
],
|
||||
"dependencies": {
|
||||
"axios": "^1.6.6",
|
||||
"axios": "^1.7.9",
|
||||
"isomorphic-ws": "^4.0.1",
|
||||
"ws": "^7.4.0"
|
||||
},
|
||||
|
||||
@@ -132,13 +132,14 @@ export abstract class BaseWebsocketClient<
|
||||
|
||||
private timeOffsetMs: number = 0;
|
||||
|
||||
private pendingTopicSubscriptionRequests: {
|
||||
[key in TWSKey]?: {
|
||||
[requestKey: string]:
|
||||
| undefined
|
||||
| WsKeyPendingTopicSubscriptions<TWSRequestEvent>;
|
||||
};
|
||||
} = {};
|
||||
/**
|
||||
* A nested wsKey->request key store.
|
||||
* pendingTopicSubscriptionRequests[wsKey][requestKey] = WsKeyPendingTopicSubscriptions<TWSRequestEvent>
|
||||
*/
|
||||
private pendingTopicSubscriptionRequests: Record<
|
||||
string,
|
||||
Record<string, undefined | WsKeyPendingTopicSubscriptions<TWSRequestEvent>>
|
||||
> = {};
|
||||
|
||||
constructor(
|
||||
options?: WSClientConfigurableOptions,
|
||||
@@ -281,9 +282,9 @@ export abstract class BaseWebsocketClient<
|
||||
const requestKey = requestData.requestKey;
|
||||
|
||||
// Should not be possible to see a requestKey collision in the current design, since the req ID increments automatically with every request, so this should never be true, but just in case a future mistake happens...
|
||||
const existingWsKeyPendingRequests =
|
||||
this.getWsKeyPendingSubscriptionStore(wsKey);
|
||||
if (existingWsKeyPendingRequests[requestKey]) {
|
||||
|
||||
const pendingSubReqs = this.getWsKeyPendingSubscriptionStore(wsKey);
|
||||
if (pendingSubReqs[requestKey]) {
|
||||
throw new Error(
|
||||
'Implementation error: attempted to upsert pending topics with duplicate request ID!',
|
||||
);
|
||||
@@ -294,8 +295,8 @@ export abstract class BaseWebsocketClient<
|
||||
resolver: TopicsPendingSubscriptionsResolver<TWSRequestEvent>,
|
||||
rejector: TopicsPendingSubscriptionsRejector<TWSRequestEvent>,
|
||||
) => {
|
||||
const store = this.getWsKeyPendingSubscriptionStore(wsKey);
|
||||
store[requestKey] = {
|
||||
const pendingSubReqs = this.getWsKeyPendingSubscriptionStore(wsKey);
|
||||
pendingSubReqs[requestKey] = {
|
||||
requestData: requestData.requestEvent,
|
||||
resolver,
|
||||
rejector,
|
||||
@@ -305,8 +306,8 @@ export abstract class BaseWebsocketClient<
|
||||
}
|
||||
|
||||
protected removeTopicPendingSubscription(wsKey: TWSKey, requestKey: string) {
|
||||
const store = this.getWsKeyPendingSubscriptionStore(wsKey);
|
||||
delete store[requestKey];
|
||||
const pendingSubReqs = this.getWsKeyPendingSubscriptionStore(wsKey);
|
||||
delete pendingSubReqs[requestKey];
|
||||
}
|
||||
|
||||
private clearTopicsPendingSubscriptions(
|
||||
@@ -315,9 +316,10 @@ export abstract class BaseWebsocketClient<
|
||||
rejectReason: string,
|
||||
) {
|
||||
if (rejectAll) {
|
||||
const wsKeyPendingRequests = this.getWsKeyPendingSubscriptionStore(wsKey);
|
||||
for (const requestKey in wsKeyPendingRequests) {
|
||||
const request = wsKeyPendingRequests[requestKey];
|
||||
const pendingSubReqs = this.getWsKeyPendingSubscriptionStore(wsKey);
|
||||
|
||||
for (const requestKey in pendingSubReqs) {
|
||||
const request = pendingSubReqs[requestKey];
|
||||
request?.rejector(request.requestData, rejectReason);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user