@openfeed/sdk-js 1.1.5 → 1.1.6
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/.releases/CHANGELOG-1.1.6.md +10 -0
- package/CHANGELOG.md +2 -2
- package/dist/generated/version.d.ts +1 -1
- package/dist/index.js +45 -15
- package/dist/node.js +45 -15
- package/package.json +1 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
|
+
|
|
5
|
+
### [1.1.5](https://github.com/openfeed-org/sdk-js/compare/1.1.4...1.1.5) (2023-12-22)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* new approach for listening to alias changes ([69f2d7d](https://github.com/openfeed-org/sdk-js/commit/69f2d7d6e5b64d7abeb6c6cda052c6e7f512aef3))
|
package/CHANGELOG.md
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
-
### [1.1.
|
|
5
|
+
### [1.1.6](https://github.com/openfeed-org/sdk-js/compare/1.1.5...1.1.6) (2024-02-27)
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
### Bug Fixes
|
|
9
9
|
|
|
10
|
-
*
|
|
10
|
+
* enhance unsubscription flow to prevent duplicate race condition ([863a4fe](https://github.com/openfeed-org/sdk-js/commit/863a4fe5e2ff27613b70a9f1638df211fd796acc))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.1.
|
|
1
|
+
export declare const version = "1.1.6";
|
package/dist/index.js
CHANGED
|
@@ -8031,7 +8031,7 @@ class ResolutionSource {
|
|
|
8031
8031
|
return this.onError;
|
|
8032
8032
|
}
|
|
8033
8033
|
}
|
|
8034
|
-
const version = "1.1.
|
|
8034
|
+
const version = "1.1.6";
|
|
8035
8035
|
const send = (socket, message) => {
|
|
8036
8036
|
socket.send(OpenfeedGatewayRequestEncode.encode(toT(message)).finish());
|
|
8037
8037
|
};
|
|
@@ -8073,7 +8073,7 @@ class ConnectionDisposedError extends Error {
|
|
|
8073
8073
|
}
|
|
8074
8074
|
class OpenFeedConnection {
|
|
8075
8075
|
constructor(connectionToken, socket, listeners, logger) {
|
|
8076
|
-
__publicField(this, "
|
|
8076
|
+
__publicField(this, "subscriptionRequests", /* @__PURE__ */ new Map());
|
|
8077
8077
|
__publicField(this, "exchangeRequests", /* @__PURE__ */ new Map());
|
|
8078
8078
|
__publicField(this, "instrumentRequests", /* @__PURE__ */ new Map());
|
|
8079
8079
|
__publicField(this, "definitionsInFlight", /* @__PURE__ */ new Map());
|
|
@@ -8157,6 +8157,16 @@ class OpenFeedConnection {
|
|
|
8157
8157
|
request.resolve(message.exchangeResponse);
|
|
8158
8158
|
continue;
|
|
8159
8159
|
}
|
|
8160
|
+
if (message.subscriptionResponse) {
|
|
8161
|
+
const { correlationId, unsubscribe } = message.subscriptionResponse;
|
|
8162
|
+
if (!unsubscribe) {
|
|
8163
|
+
const request = this.subscriptionRequests.get(correlationId.toString());
|
|
8164
|
+
if (!request)
|
|
8165
|
+
throw new Error(`Subscription response ID ${correlationId} not found`);
|
|
8166
|
+
const [, sub] = request;
|
|
8167
|
+
sub.resolve();
|
|
8168
|
+
}
|
|
8169
|
+
}
|
|
8160
8170
|
this.listeners.onMessage(message);
|
|
8161
8171
|
}
|
|
8162
8172
|
} catch (error) {
|
|
@@ -8229,7 +8239,8 @@ class OpenFeedConnection {
|
|
|
8229
8239
|
requests: requests.map((r) => toT(r)),
|
|
8230
8240
|
unsubscribe: false
|
|
8231
8241
|
};
|
|
8232
|
-
|
|
8242
|
+
const source = new ResolutionSource();
|
|
8243
|
+
this.subscriptionRequests.set(correlationId.toString(), [subscriptionRequest, source]);
|
|
8233
8244
|
send(this.socket, { subscriptionRequest });
|
|
8234
8245
|
return correlationId;
|
|
8235
8246
|
});
|
|
@@ -8237,13 +8248,12 @@ class OpenFeedConnection {
|
|
|
8237
8248
|
if (this.whenDisconnectedSource.completed) {
|
|
8238
8249
|
throw new ConnectionDisposedError("This connection was closed");
|
|
8239
8250
|
}
|
|
8240
|
-
const subscription = this.
|
|
8251
|
+
const subscription = this.subscriptionRequests.get(subscriptionId.toString());
|
|
8241
8252
|
if (!subscription) {
|
|
8242
8253
|
throw new Error(`Subscription ID ${subscriptionId} does not exist.`);
|
|
8243
8254
|
}
|
|
8244
|
-
const
|
|
8245
|
-
|
|
8246
|
-
this.subscriptions.delete(subscriptionId.toString());
|
|
8255
|
+
const [originalRequest, sub] = subscription;
|
|
8256
|
+
this.fireUnsubscribeWhenReady(originalRequest, sub);
|
|
8247
8257
|
});
|
|
8248
8258
|
__publicField(this, "getExchanges", async () => {
|
|
8249
8259
|
var _a;
|
|
@@ -8342,6 +8352,18 @@ class OpenFeedConnection {
|
|
|
8342
8352
|
this.socket.close(1e3, error.message);
|
|
8343
8353
|
this.whenDisconnectedSource.reject(error);
|
|
8344
8354
|
}
|
|
8355
|
+
// We are keeping this fire and forget, because our problems
|
|
8356
|
+
// would be caused by disconnection, and reconnect will clean up the rest
|
|
8357
|
+
async fireUnsubscribeWhenReady(originalRequest, sub) {
|
|
8358
|
+
try {
|
|
8359
|
+
await sub.whenCompleted;
|
|
8360
|
+
const subscriptionRequest = { ...originalRequest, unsubscribe: true };
|
|
8361
|
+
send(this.socket, { subscriptionRequest });
|
|
8362
|
+
} catch (e) {
|
|
8363
|
+
} finally {
|
|
8364
|
+
this.subscriptionRequests.delete(originalRequest.correlationId.toString());
|
|
8365
|
+
}
|
|
8366
|
+
}
|
|
8345
8367
|
}
|
|
8346
8368
|
class OpenFeedClient {
|
|
8347
8369
|
constructor(url, username, password, listeners, logger, clientId) {
|
|
@@ -8607,14 +8629,22 @@ class OpenFeedListeners {
|
|
|
8607
8629
|
return res ?? [void 0, void 0];
|
|
8608
8630
|
};
|
|
8609
8631
|
if (message.subscriptionResponse) {
|
|
8610
|
-
|
|
8611
|
-
|
|
8612
|
-
|
|
8613
|
-
|
|
8614
|
-
|
|
8615
|
-
|
|
8616
|
-
|
|
8617
|
-
|
|
8632
|
+
const { marketId, symbol, unsubscribe } = message.subscriptionResponse;
|
|
8633
|
+
if (marketId !== Long.ZERO) {
|
|
8634
|
+
[def, symbols] = getInstrumentDefinition(marketId);
|
|
8635
|
+
if (!unsubscribe) {
|
|
8636
|
+
if (!symbols) {
|
|
8637
|
+
symbols = [symbol];
|
|
8638
|
+
} else if (!symbols.includes(symbol)) {
|
|
8639
|
+
symbols = [...symbols, symbol];
|
|
8640
|
+
}
|
|
8641
|
+
} else {
|
|
8642
|
+
if (symbols) {
|
|
8643
|
+
symbols = symbols.filter((s) => s !== symbol);
|
|
8644
|
+
}
|
|
8645
|
+
this.instrumentBySymbol.delete(symbol);
|
|
8646
|
+
}
|
|
8647
|
+
this.instrumentByMarketId.set(marketId.toString(), [def, symbols]);
|
|
8618
8648
|
}
|
|
8619
8649
|
} else if (message.instrumentDefinition) {
|
|
8620
8650
|
[def, symbols] = getInstrumentDefinition(message.instrumentDefinition.marketId);
|
package/dist/node.js
CHANGED
|
@@ -11655,7 +11655,7 @@ var ResolutionSource = class {
|
|
|
11655
11655
|
};
|
|
11656
11656
|
|
|
11657
11657
|
// generated/version.ts
|
|
11658
|
-
var version = "1.1.
|
|
11658
|
+
var version = "1.1.6";
|
|
11659
11659
|
|
|
11660
11660
|
// src/connection/connection.ts
|
|
11661
11661
|
var send = (socket, message) => {
|
|
@@ -11707,7 +11707,7 @@ var OpenFeedConnection = class {
|
|
|
11707
11707
|
this.socket.onclose = this.onClose;
|
|
11708
11708
|
this.runConnectionWatchLoop();
|
|
11709
11709
|
}
|
|
11710
|
-
|
|
11710
|
+
subscriptionRequests = /* @__PURE__ */ new Map();
|
|
11711
11711
|
exchangeRequests = /* @__PURE__ */ new Map();
|
|
11712
11712
|
instrumentRequests = /* @__PURE__ */ new Map();
|
|
11713
11713
|
definitionsInFlight = /* @__PURE__ */ new Map();
|
|
@@ -11791,6 +11791,16 @@ var OpenFeedConnection = class {
|
|
|
11791
11791
|
request.resolve(message.exchangeResponse);
|
|
11792
11792
|
continue;
|
|
11793
11793
|
}
|
|
11794
|
+
if (message.subscriptionResponse) {
|
|
11795
|
+
const { correlationId, unsubscribe } = message.subscriptionResponse;
|
|
11796
|
+
if (!unsubscribe) {
|
|
11797
|
+
const request = this.subscriptionRequests.get(correlationId.toString());
|
|
11798
|
+
if (!request)
|
|
11799
|
+
throw new Error(`Subscription response ID ${correlationId} not found`);
|
|
11800
|
+
const [, sub] = request;
|
|
11801
|
+
sub.resolve();
|
|
11802
|
+
}
|
|
11803
|
+
}
|
|
11794
11804
|
this.listeners.onMessage(message);
|
|
11795
11805
|
}
|
|
11796
11806
|
} catch (error) {
|
|
@@ -11881,7 +11891,8 @@ var OpenFeedConnection = class {
|
|
|
11881
11891
|
requests: requests.map((r) => toT(r)),
|
|
11882
11892
|
unsubscribe: false
|
|
11883
11893
|
};
|
|
11884
|
-
|
|
11894
|
+
const source = new ResolutionSource();
|
|
11895
|
+
this.subscriptionRequests.set(correlationId.toString(), [subscriptionRequest, source]);
|
|
11885
11896
|
send(this.socket, { subscriptionRequest });
|
|
11886
11897
|
return correlationId;
|
|
11887
11898
|
};
|
|
@@ -11889,14 +11900,25 @@ var OpenFeedConnection = class {
|
|
|
11889
11900
|
if (this.whenDisconnectedSource.completed) {
|
|
11890
11901
|
throw new ConnectionDisposedError("This connection was closed");
|
|
11891
11902
|
}
|
|
11892
|
-
const subscription = this.
|
|
11903
|
+
const subscription = this.subscriptionRequests.get(subscriptionId.toString());
|
|
11893
11904
|
if (!subscription) {
|
|
11894
11905
|
throw new Error(`Subscription ID ${subscriptionId} does not exist.`);
|
|
11895
11906
|
}
|
|
11896
|
-
const
|
|
11897
|
-
|
|
11898
|
-
this.subscriptions.delete(subscriptionId.toString());
|
|
11907
|
+
const [originalRequest, sub] = subscription;
|
|
11908
|
+
this.fireUnsubscribeWhenReady(originalRequest, sub);
|
|
11899
11909
|
};
|
|
11910
|
+
// We are keeping this fire and forget, because our problems
|
|
11911
|
+
// would be caused by disconnection, and reconnect will clean up the rest
|
|
11912
|
+
async fireUnsubscribeWhenReady(originalRequest, sub) {
|
|
11913
|
+
try {
|
|
11914
|
+
await sub.whenCompleted;
|
|
11915
|
+
const subscriptionRequest = { ...originalRequest, unsubscribe: true };
|
|
11916
|
+
send(this.socket, { subscriptionRequest });
|
|
11917
|
+
} catch (e) {
|
|
11918
|
+
} finally {
|
|
11919
|
+
this.subscriptionRequests.delete(originalRequest.correlationId.toString());
|
|
11920
|
+
}
|
|
11921
|
+
}
|
|
11900
11922
|
getExchanges = async () => {
|
|
11901
11923
|
var _a;
|
|
11902
11924
|
if (this.whenDisconnectedSource.completed) {
|
|
@@ -12236,14 +12258,22 @@ var OpenFeedListeners = class {
|
|
|
12236
12258
|
return res ?? [void 0, void 0];
|
|
12237
12259
|
};
|
|
12238
12260
|
if (message.subscriptionResponse) {
|
|
12239
|
-
|
|
12240
|
-
|
|
12241
|
-
|
|
12242
|
-
|
|
12243
|
-
|
|
12244
|
-
|
|
12245
|
-
|
|
12246
|
-
|
|
12261
|
+
const { marketId, symbol, unsubscribe } = message.subscriptionResponse;
|
|
12262
|
+
if (marketId !== long_default.ZERO) {
|
|
12263
|
+
[def, symbols] = getInstrumentDefinition(marketId);
|
|
12264
|
+
if (!unsubscribe) {
|
|
12265
|
+
if (!symbols) {
|
|
12266
|
+
symbols = [symbol];
|
|
12267
|
+
} else if (!symbols.includes(symbol)) {
|
|
12268
|
+
symbols = [...symbols, symbol];
|
|
12269
|
+
}
|
|
12270
|
+
} else {
|
|
12271
|
+
if (symbols) {
|
|
12272
|
+
symbols = symbols.filter((s) => s !== symbol);
|
|
12273
|
+
}
|
|
12274
|
+
this.instrumentBySymbol.delete(symbol);
|
|
12275
|
+
}
|
|
12276
|
+
this.instrumentByMarketId.set(marketId.toString(), [def, symbols]);
|
|
12247
12277
|
}
|
|
12248
12278
|
} else if (message.instrumentDefinition) {
|
|
12249
12279
|
[def, symbols] = getInstrumentDefinition(message.instrumentDefinition.marketId);
|