@openfeed/sdk-js 1.8.1 → 1.8.2
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/CHANGELOG.md +9 -0
- package/DOCUMENTATION.md +2 -0
- package/README.md +10 -3
- package/dist/generated/version.d.ts +1 -1
- package/dist/index.js +89 -35
- package/dist/node.js +13698 -17467
- package/dist/src/connection/client.d.ts +7 -0
- package/dist/src/connection/connection.d.ts +5 -1
- package/dist/src/connection/interfaces.d.ts +12 -1
- package/dist/src/utilities/constants.d.ts +1 -1
- package/dist/src/utilities/reconnect_backoff.d.ts +11 -0
- package/package.json +10 -11
|
@@ -16,12 +16,19 @@ export declare class OpenFeedClient implements IOpenFeedClient {
|
|
|
16
16
|
private whenConnectedSource;
|
|
17
17
|
private loopResetSource;
|
|
18
18
|
private subscribeResetSource;
|
|
19
|
+
private readonly reconnectBackoff;
|
|
19
20
|
private readonly subscriptions;
|
|
20
21
|
constructor(url: string, username: string, password: string, listeners: OpenFeedListeners, logger?: IOpenFeedLogger | undefined, clientId?: string | undefined);
|
|
21
22
|
private onOpen;
|
|
22
23
|
private onMessage;
|
|
23
24
|
private onError;
|
|
24
25
|
private onClose;
|
|
26
|
+
/**
|
|
27
|
+
* Waits for the login, as long as the socket isn't silent. Once logged in, the connection watches for silence; until
|
|
28
|
+
* then this does, so a socket that connects and then goes quiet (a half-open connection, or a server that never
|
|
29
|
+
* answers the login) is dropped and tried again, instead of waiting for a close that may never come.
|
|
30
|
+
*/
|
|
31
|
+
private whenLoggedInOrSilent;
|
|
25
32
|
private runConnectLoop;
|
|
26
33
|
private cleanUp;
|
|
27
34
|
private runSubscribeLoop;
|
|
@@ -13,7 +13,11 @@ export declare class OpenFeedConnection implements IOpenFeedConnection {
|
|
|
13
13
|
private readonly logger?;
|
|
14
14
|
private readonly whenDisconnectedSource;
|
|
15
15
|
constructor(connectionToken: string, socket: WebSocket, listeners: OpenFeedListeners, logger?: IOpenFeedLogger | undefined);
|
|
16
|
-
private
|
|
16
|
+
private lastMessageAt;
|
|
17
|
+
/**
|
|
18
|
+
* Drops the connection once it has been silent for `CONNECTION_TIMEOUT`. Messages only note when they came, and the
|
|
19
|
+
* timer, when it fires early, waits out the rest, so there's no timer to reset on every message.
|
|
20
|
+
*/
|
|
17
21
|
private runConnectionWatchLoop;
|
|
18
22
|
private onMessage;
|
|
19
23
|
/** Returns false when the connection was closed, and the rest of the messages should be dropped */
|
|
@@ -12,7 +12,18 @@ type Id<T> = {} & {
|
|
|
12
12
|
type OmitRecursively<T, K extends PropertyKey> = {
|
|
13
13
|
[P in keyof T]: OmitDistributive<T[P], K>;
|
|
14
14
|
};
|
|
15
|
-
|
|
15
|
+
type SendableRequests = OmitRecursively<Required<Omit<OpenfeedGatewayRequest, "loginRequest" | "logoutRequest">>, "correlationId" | "token">;
|
|
16
|
+
/**
|
|
17
|
+
* What `send` takes: exactly one of the gateway request's kinds, other than login and logout, without the correlation id
|
|
18
|
+
* and token it fills in. `{}`, or two kinds at once, doesn't type-check.
|
|
19
|
+
*/
|
|
20
|
+
export type OpenfeedRequest = {
|
|
21
|
+
[K in keyof SendableRequests]: {
|
|
22
|
+
[P in K]: SendableRequests[P];
|
|
23
|
+
} & {
|
|
24
|
+
[P in Exclude<keyof SendableRequests, K>]?: never;
|
|
25
|
+
};
|
|
26
|
+
}[keyof SendableRequests];
|
|
16
27
|
export interface IOpenFeedConnection {
|
|
17
28
|
subscribe: (service: Service, subscriptionType: SubscriptionType, snapshotIntervalSeconds: number, symbols: string[] | null, marketIds: Long[] | null, exchanges: string[] | null, channels: number[] | null) => Long;
|
|
18
29
|
unsubscribe: (subscriptionId: Long) => void;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Exponential backoff with jitter for reconnects, as in `sdk-net`: each attempt doubles the delay, up to the maximum, and
|
|
3
|
+
* waits a random time in its upper half, so clients dropped together don't all come back at once.
|
|
4
|
+
*/
|
|
5
|
+
export declare class ReconnectBackoff {
|
|
6
|
+
private delay;
|
|
7
|
+
/** The next wait: 5-10s, then 10-20s, 20-40s, and 30-60s from then on, until reset. */
|
|
8
|
+
nextDelay: () => number;
|
|
9
|
+
/** Called once logged in, so the next disconnect starts again from the shortest wait. */
|
|
10
|
+
reset: () => void;
|
|
11
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfeed/sdk-js",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.2",
|
|
4
4
|
"description": "JavaScript SDK for Barchart OpenFeed",
|
|
5
5
|
"main": "dist/node.js",
|
|
6
6
|
"browser": "dist/index.js",
|
|
@@ -22,16 +22,16 @@
|
|
|
22
22
|
"author": "Dejan Maksimovic <maximovic.d@gmail.com>",
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"scripts": {
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"generate:proto": "cd
|
|
25
|
+
"hooks:install": "husky",
|
|
26
|
+
"fetch:proto": "tsx ./scripts/fetch-proto.ts",
|
|
27
|
+
"generate:proto": "cd .proto && protoc --plugin=../node_modules/.bin/protoc-gen-ts_proto --ts_proto_opt=outputJsonMethods=false --ts_proto_opt=outputPartialMethods=false --ts_proto_opt=exportCommonSymbols=false --ts_proto_opt=esModuleInterop=true --ts_proto_opt=forceLong=long --ts_proto_opt=useExactTypes=false --ts_proto_out=../generated *.proto",
|
|
28
28
|
"generate:version": "genversion --es6 -s -d ./generated/version.ts",
|
|
29
29
|
"generate:process": "tsx ./scripts/process.ts",
|
|
30
|
-
"generate": "yarn
|
|
31
|
-
"build:node": "
|
|
32
|
-
"build:ts": "yarn generate:version && vite build",
|
|
33
|
-
"run:browser": "yarn generate:version && vite dev",
|
|
34
|
-
"run:node": "yarn generate:version && tsx ./src/test.ts",
|
|
30
|
+
"generate": "yarn fetch:proto && yarn generate:proto && yarn generate:process",
|
|
31
|
+
"build:node": "vite build --mode node",
|
|
32
|
+
"build:ts": "yarn hooks:install && yarn generate:version && vite build",
|
|
33
|
+
"run:browser": "yarn hooks:install && yarn generate:version && vite dev",
|
|
34
|
+
"run:node": "yarn hooks:install && yarn generate:version && tsx ./src/test.ts",
|
|
35
35
|
"test": "vitest run",
|
|
36
36
|
"lint": "eslint .",
|
|
37
37
|
"format": "prettier --write .",
|
|
@@ -52,7 +52,6 @@
|
|
|
52
52
|
"google-protobuf": "^4.0.3",
|
|
53
53
|
"husky": "^9.1.7",
|
|
54
54
|
"prettier": "^3.9.10",
|
|
55
|
-
"proto": "git+ssh://git@github.com/openfeed-org/proto.git#master",
|
|
56
55
|
"publint": "^0.3.25",
|
|
57
56
|
"ts-proto": "^2.18.3",
|
|
58
57
|
"tsx": "^4.23.15",
|
|
@@ -63,7 +62,7 @@
|
|
|
63
62
|
"vite-plugin-dts": "^5.1.2",
|
|
64
63
|
"vitest": "^5.1.0"
|
|
65
64
|
},
|
|
66
|
-
"packageManager": "yarn@
|
|
65
|
+
"packageManager": "yarn@4.18.1",
|
|
67
66
|
"dependencies": {
|
|
68
67
|
"@bufbuild/protobuf": "^2.14.1",
|
|
69
68
|
"isomorphic-ws": "^5.0.0",
|