@openfeed/sdk-js 1.8.0 → 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 +16 -0
- package/DOCUMENTATION.md +2 -0
- package/README.md +10 -3
- package/dist/generated/version.d.ts +1 -1
- package/dist/index.js +124 -50
- package/dist/node.js +13700 -17447
- package/dist/src/connection/client.d.ts +7 -0
- package/dist/src/connection/connection.d.ts +7 -1
- package/dist/src/connection/errors.d.ts +8 -0
- package/dist/src/connection/interfaces.d.ts +12 -1
- package/dist/src/index.d.ts +1 -0
- 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,11 +13,17 @@ 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 */
|
|
20
24
|
private handleMessage;
|
|
25
|
+
/** Settles the lookup a response belongs to. One that isn't a lookup's, such as a request made through `send`, is only passed on. */
|
|
26
|
+
private settleInstrumentRequest;
|
|
21
27
|
private disconnect;
|
|
22
28
|
private onError;
|
|
23
29
|
private onClose;
|
|
@@ -1,9 +1,17 @@
|
|
|
1
|
+
import { Result } from '../../generated/openfeed_api.js';
|
|
1
2
|
export declare class DuplicateLoginError extends Error {
|
|
2
3
|
get name(): string;
|
|
3
4
|
}
|
|
4
5
|
export declare class InvalidCredentialsError extends Error {
|
|
5
6
|
get name(): string;
|
|
6
7
|
}
|
|
8
|
+
/** An instrument lookup the server refused, or found nothing for. Code should decide on `result`. */
|
|
9
|
+
export declare class InstrumentLookupError extends Error {
|
|
10
|
+
readonly result: Result;
|
|
11
|
+
readonly serverMessage: string;
|
|
12
|
+
constructor(result: Result, serverMessage: string);
|
|
13
|
+
get name(): string;
|
|
14
|
+
}
|
|
7
15
|
export declare class ConnectionDisposedError extends Error {
|
|
8
16
|
get name(): string;
|
|
9
17
|
}
|
|
@@ -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;
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from './connection/client.js';
|
|
2
2
|
export * from './connection/interfaces.js';
|
|
3
3
|
export * from './connection/listeners.js';
|
|
4
|
+
export { InstrumentLookupError } from './connection/errors.js';
|
|
4
5
|
export * from '../generated/index.js';
|
|
5
6
|
export { encodeMessage, decodeMessages, encodeResponseMessage, decodeRequestMessage } from './utilities/communication.js';
|
|
@@ -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",
|