websocket-ts 1.1.1 → 2.1.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.
Files changed (72) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +157 -93
  3. package/package.json +27 -14
  4. package/src/backoff/backoff.ts +21 -13
  5. package/src/backoff/constantbackoff.ts +29 -11
  6. package/src/backoff/exponentialbackoff.ts +68 -28
  7. package/src/backoff/linearbackoff.ts +77 -26
  8. package/src/index.ts +23 -9
  9. package/src/queue/array_queue.ts +41 -0
  10. package/src/queue/queue.ts +46 -0
  11. package/src/queue/ring_queue.ts +69 -0
  12. package/src/websocket.ts +463 -138
  13. package/src/websocket_buffer.ts +18 -0
  14. package/src/websocket_builder.ts +274 -0
  15. package/src/websocket_event.ts +88 -0
  16. package/src/websocket_options.ts +23 -0
  17. package/src/websocket_retry_options.ts +22 -0
  18. package/{tsconfig.json → tsconfig.cjs.json} +8 -8
  19. package/tsconfig.esm.json +71 -0
  20. package/jest.config.js +0 -9
  21. package/lib/backoff/backoff.d.ts +0 -18
  22. package/lib/backoff/backoff.d.ts.map +0 -1
  23. package/lib/backoff/backoff.js +0 -3
  24. package/lib/backoff/backoff.js.map +0 -1
  25. package/lib/backoff/constantbackoff.d.ts +0 -11
  26. package/lib/backoff/constantbackoff.d.ts.map +0 -1
  27. package/lib/backoff/constantbackoff.js +0 -20
  28. package/lib/backoff/constantbackoff.js.map +0 -1
  29. package/lib/backoff/exponentialbackoff.d.ts +0 -22
  30. package/lib/backoff/exponentialbackoff.d.ts.map +0 -1
  31. package/lib/backoff/exponentialbackoff.js +0 -35
  32. package/lib/backoff/exponentialbackoff.js.map +0 -1
  33. package/lib/backoff/linearbackoff.d.ts +0 -19
  34. package/lib/backoff/linearbackoff.d.ts.map +0 -1
  35. package/lib/backoff/linearbackoff.js +0 -34
  36. package/lib/backoff/linearbackoff.js.map +0 -1
  37. package/lib/buffer/buffer.d.ts +0 -41
  38. package/lib/buffer/buffer.d.ts.map +0 -1
  39. package/lib/buffer/buffer.js +0 -3
  40. package/lib/buffer/buffer.js.map +0 -1
  41. package/lib/buffer/lrubuffer.d.ts +0 -24
  42. package/lib/buffer/lrubuffer.d.ts.map +0 -1
  43. package/lib/buffer/lrubuffer.js +0 -76
  44. package/lib/buffer/lrubuffer.js.map +0 -1
  45. package/lib/buffer/timebuffer.d.ts +0 -25
  46. package/lib/buffer/timebuffer.d.ts.map +0 -1
  47. package/lib/buffer/timebuffer.js +0 -92
  48. package/lib/buffer/timebuffer.js.map +0 -1
  49. package/lib/index.d.ts +0 -10
  50. package/lib/index.d.ts.map +0 -1
  51. package/lib/index.js +0 -22
  52. package/lib/index.js.map +0 -1
  53. package/lib/websocket.d.ts +0 -47
  54. package/lib/websocket.d.ts.map +0 -1
  55. package/lib/websocket.js +0 -120
  56. package/lib/websocket.js.map +0 -1
  57. package/lib/websocketBuilder.d.ts +0 -32
  58. package/lib/websocketBuilder.d.ts.map +0 -1
  59. package/lib/websocketBuilder.js +0 -68
  60. package/lib/websocketBuilder.js.map +0 -1
  61. package/src/buffer/buffer.ts +0 -45
  62. package/src/buffer/lrubuffer.ts +0 -80
  63. package/src/buffer/timebuffer.ts +0 -105
  64. package/src/websocketBuilder.ts +0 -98
  65. package/test/backoff/constantbackoff.test.ts +0 -21
  66. package/test/backoff/exponentialbackoff.test.ts +0 -13
  67. package/test/backoff/linearbackoff.test.ts +0 -32
  68. package/test/buffer/common.ts +0 -10
  69. package/test/buffer/lrubuffer.test.ts +0 -128
  70. package/test/buffer/timebuffer.test.ts +0 -115
  71. package/test/websocket.test.ts +0 -341
  72. package/test/websocketBuilder.test.ts +0 -36
@@ -0,0 +1,274 @@
1
+ import { Backoff } from "./backoff/backoff";
2
+ import {
3
+ WebsocketEvent,
4
+ WebsocketEventListener,
5
+ WebsocketEventListenerOptions,
6
+ } from "./websocket_event";
7
+ import { Websocket } from "./websocket";
8
+ import { WebsocketBuffer } from "./websocket_buffer";
9
+ import { WebsocketOptions } from "./websocket_options";
10
+
11
+ /**
12
+ * Builder for websockets.
13
+ */
14
+ export class WebsocketBuilder {
15
+ private readonly _url: string;
16
+
17
+ private _protocols?: string | string[];
18
+ private _options?: WebsocketOptions;
19
+
20
+ /**
21
+ * Creates a new WebsocketBuilder.
22
+ *
23
+ * @param url the url to connect to
24
+ */
25
+ constructor(url: string) {
26
+ this._url = url;
27
+ }
28
+
29
+ /**
30
+ * Getter for the url.
31
+ *
32
+ * @returns the url
33
+ */
34
+ get url(): string {
35
+ return this._url;
36
+ }
37
+
38
+ /**
39
+ * Adds protocols to the websocket. Subsequent calls to this method will override the previously set protocols.
40
+ *
41
+ * @param protocols the protocols to add
42
+ */
43
+ public withProtocols(
44
+ protocols: string | string[] | undefined,
45
+ ): WebsocketBuilder {
46
+ this._protocols = protocols;
47
+ return this;
48
+ }
49
+
50
+ /**
51
+ * Getter for the protocols.
52
+ *
53
+ * @returns the protocols, undefined if no protocols have been set
54
+ */
55
+ get protocols(): string | string[] | undefined {
56
+ return this._protocols;
57
+ }
58
+
59
+ /**
60
+ * Sets the maximum number of retries before giving up. No limit if undefined.
61
+ *
62
+ * @param maxRetries the maximum number of retries before giving up
63
+ */
64
+ public withMaxRetries(maxRetries: number | undefined): WebsocketBuilder {
65
+ this._options = {
66
+ ...this._options,
67
+ retry: { ...this._options?.retry, maxRetries },
68
+ };
69
+ return this;
70
+ }
71
+
72
+ /**
73
+ * Getter for the maximum number of retries before giving up.
74
+ *
75
+ * @returns the maximum number of retries before giving up, undefined if no maximum has been set
76
+ */
77
+ get maxRetries(): number | undefined {
78
+ return this._options?.retry?.maxRetries;
79
+ }
80
+
81
+ /**
82
+ * Sets wether to reconnect immediately after a connection has been lost, ignoring the backoff strategy for the first retry.
83
+ *
84
+ * @param instantReconnect wether to reconnect immediately after a connection has been lost
85
+ */
86
+ public withInstantReconnect(
87
+ instantReconnect: boolean | undefined,
88
+ ): WebsocketBuilder {
89
+ this._options = {
90
+ ...this._options,
91
+ retry: { ...this._options?.retry, instantReconnect },
92
+ };
93
+ return this;
94
+ }
95
+
96
+ /**
97
+ * Getter for wether to reconnect immediately after a connection has been lost, ignoring the backoff strategy for the first retry.
98
+ *
99
+ * @returns wether to reconnect immediately after a connection has been lost, undefined if no value has been set
100
+ */
101
+ get instantReconnect(): boolean | undefined {
102
+ return this._options?.retry?.instantReconnect;
103
+ }
104
+
105
+ /**
106
+ * Adds a backoff to the websocket. Subsequent calls to this method will override the previously set backoff.
107
+ *
108
+ * @param backoff the backoff to add
109
+ */
110
+ public withBackoff(backoff: Backoff | undefined): WebsocketBuilder {
111
+ this._options = {
112
+ ...this._options,
113
+ retry: { ...this._options?.retry, backoff },
114
+ };
115
+ return this;
116
+ }
117
+
118
+ /**
119
+ * Getter for the backoff.
120
+ *
121
+ * @returns the backoff, undefined if no backoff has been set
122
+ */
123
+ get backoff(): Backoff | undefined {
124
+ return this._options?.retry?.backoff;
125
+ }
126
+
127
+ /**
128
+ * Adds a buffer to the websocket. Subsequent calls to this method will override the previously set buffer.
129
+ *
130
+ * @param buffer the buffer to add
131
+ */
132
+ public withBuffer(buffer: WebsocketBuffer | undefined): WebsocketBuilder {
133
+ this._options = { ...this._options, buffer };
134
+ return this;
135
+ }
136
+
137
+ /**
138
+ * Getter for the buffer.
139
+ *
140
+ * @returns the buffer, undefined if no buffer has been set
141
+ */
142
+ get buffer(): WebsocketBuffer | undefined {
143
+ return this._options?.buffer;
144
+ }
145
+
146
+ /**
147
+ * Adds an 'open' event listener to the websocket. Subsequent calls to this method will add additional listeners that will be
148
+ * called in the order they were added.
149
+ *
150
+ * @param listener the listener to add
151
+ * @param options the listener options
152
+ */
153
+ public onOpen(
154
+ listener: WebsocketEventListener<WebsocketEvent.open>,
155
+ options?: WebsocketEventListenerOptions,
156
+ ): WebsocketBuilder {
157
+ this.addListener(WebsocketEvent.open, listener, options);
158
+ return this;
159
+ }
160
+
161
+ /**
162
+ * Adds an 'close' event listener to the websocket. Subsequent calls to this method will add additional listeners that will be
163
+ * called in the order they were added.
164
+ *
165
+ * @param listener the listener to add
166
+ * @param options the listener options
167
+ */
168
+ public onClose(
169
+ listener: WebsocketEventListener<WebsocketEvent.close>,
170
+ options?: WebsocketEventListenerOptions,
171
+ ): WebsocketBuilder {
172
+ this.addListener(WebsocketEvent.close, listener, options);
173
+ return this;
174
+ }
175
+
176
+ /**
177
+ * Adds an 'error' event listener to the websocket. Subsequent calls to this method will add additional listeners that will be
178
+ * called in the order they were added.
179
+ *
180
+ * @param listener the listener to add
181
+ * @param options the listener options
182
+ */
183
+ public onError(
184
+ listener: WebsocketEventListener<WebsocketEvent.error>,
185
+ options?: WebsocketEventListenerOptions,
186
+ ): WebsocketBuilder {
187
+ this.addListener(WebsocketEvent.error, listener, options);
188
+ return this;
189
+ }
190
+
191
+ /**
192
+ * Adds an 'message' event listener to the websocket. Subsequent calls to this method will add additional listeners that will be
193
+ * called in the order they were added.
194
+ *
195
+ * @param listener the listener to add
196
+ * @param options the listener options
197
+ */
198
+ public onMessage(
199
+ listener: WebsocketEventListener<WebsocketEvent.message>,
200
+ options?: WebsocketEventListenerOptions,
201
+ ): WebsocketBuilder {
202
+ this.addListener(WebsocketEvent.message, listener, options);
203
+ return this;
204
+ }
205
+
206
+ /**
207
+ * Adds an 'retry' event listener to the websocket. Subsequent calls to this method will add additional listeners that will be
208
+ * called in the order they were added.
209
+ *
210
+ * @param listener the listener to add
211
+ * @param options the listener options
212
+ */
213
+ public onRetry(
214
+ listener: WebsocketEventListener<WebsocketEvent.retry>,
215
+ options?: WebsocketEventListenerOptions,
216
+ ): WebsocketBuilder {
217
+ this.addListener(WebsocketEvent.retry, listener, options);
218
+ return this;
219
+ }
220
+
221
+ /**
222
+ * Adds an 'reconnect' event listener to the websocket. Subsequent calls to this method will add additional listeners that will be
223
+ * called in the order they were added.
224
+ *
225
+ * @param listener the listener to add
226
+ * @param options the listener options
227
+ */
228
+ public onReconnect(
229
+ listener: WebsocketEventListener<WebsocketEvent.reconnect>,
230
+ options?: WebsocketEventListenerOptions,
231
+ ): WebsocketBuilder {
232
+ this.addListener(WebsocketEvent.reconnect, listener, options);
233
+ return this;
234
+ }
235
+
236
+ /**
237
+ * Builds the websocket.
238
+ *
239
+ * @return a new websocket, with the set options
240
+ */
241
+ public build(): Websocket {
242
+ return new Websocket(this._url, this._protocols, this._options); // instantiate the websocket with the set options
243
+ }
244
+
245
+ /**
246
+ * Adds an event listener to the options.
247
+ *
248
+ * @param event the event to add the listener to
249
+ * @param listener the listener to add
250
+ * @param options the listener options
251
+ */
252
+ private addListener<K extends WebsocketEvent>(
253
+ event: WebsocketEvent,
254
+ listener: WebsocketEventListener<K>,
255
+ options?: WebsocketEventListenerOptions,
256
+ ): WebsocketBuilder {
257
+ this._options = {
258
+ ...this._options,
259
+ listeners: {
260
+ open: this._options?.listeners?.open ?? [],
261
+ close: this._options?.listeners?.close ?? [],
262
+ error: this._options?.listeners?.error ?? [],
263
+ message: this._options?.listeners?.message ?? [],
264
+ retry: this._options?.listeners?.retry ?? [],
265
+ reconnect: this._options?.listeners?.reconnect ?? [],
266
+ [event]: [
267
+ ...(this._options?.listeners?.[event] ?? []),
268
+ { listener, options },
269
+ ],
270
+ },
271
+ };
272
+ return this;
273
+ }
274
+ }
@@ -0,0 +1,88 @@
1
+ import { Websocket } from "./websocket";
2
+
3
+ /**
4
+ * Events that can be fired by the websocket.
5
+ */
6
+ export enum WebsocketEvent {
7
+ /** Fired when the connection is opened. */
8
+ open = "open",
9
+
10
+ /** Fired when the connection is closed. */
11
+ close = "close",
12
+
13
+ /** Fired when the connection has been closed because of an error, such as when some data couldn't be sent. */
14
+ error = "error",
15
+
16
+ /** Fired when a message is received. */
17
+ message = "message",
18
+
19
+ /** Fired when the websocket tries to reconnect after a connection loss. */
20
+ retry = "retry",
21
+
22
+ /** Fired when the websocket successfully reconnects after a connection loss. */
23
+ reconnect = "reconnect",
24
+ }
25
+
26
+ /***
27
+ * Details/properties of a retry-event.
28
+ */
29
+ export type RetryEventDetail = {
30
+ /** Number of retries that have been made since the connection was lost. */
31
+ readonly retries: number;
32
+
33
+ /** Time (ms) waited since the last connection-retry. */
34
+ readonly backoff: number;
35
+
36
+ /** Timestamp of when the connection was lost or undefined if the connection has never been established. */
37
+ readonly lastConnection: Date | undefined;
38
+ };
39
+
40
+ /**
41
+ * Properties of a reconnect-event.
42
+ */
43
+ export type ReconnectEventDetail = Omit<RetryEventDetail, "backoff">;
44
+
45
+ /**
46
+ * Maps websocket events to their corresponding event.
47
+ */
48
+ export type WebsocketEventMap = {
49
+ [WebsocketEvent.open]: Event;
50
+ [WebsocketEvent.close]: CloseEvent;
51
+ [WebsocketEvent.error]: Event;
52
+ [WebsocketEvent.message]: MessageEvent;
53
+ [WebsocketEvent.retry]: CustomEvent<RetryEventDetail>;
54
+ [WebsocketEvent.reconnect]: CustomEvent<ReconnectEventDetail>;
55
+ };
56
+
57
+ /**
58
+ * Listener for websocket events.
59
+ * */
60
+ export type WebsocketEventListener<K extends WebsocketEvent> = (
61
+ instance: Websocket,
62
+ ev: WebsocketEventMap[K],
63
+ ) => unknown;
64
+
65
+ export type WebsocketEventListenerParams<K extends WebsocketEvent> = Parameters<
66
+ WebsocketEventListener<K>
67
+ >;
68
+
69
+ /**
70
+ * Options for websocket events.
71
+ */
72
+ export type WebsocketEventListenerOptions = EventListenerOptions &
73
+ AddEventListenerOptions;
74
+
75
+ /**
76
+ * Listener for websocket events with options.
77
+ */
78
+ export type WebsocketEventListenerWithOptions<K extends WebsocketEvent> = {
79
+ readonly listener: WebsocketEventListener<K>;
80
+ readonly options?: WebsocketEventListenerOptions;
81
+ };
82
+
83
+ /**
84
+ * Maps websocket events to their corresponding event-listeners.
85
+ */
86
+ export type WebsocketEventListeners = {
87
+ [K in WebsocketEvent]: WebsocketEventListenerWithOptions<K>[];
88
+ };
@@ -0,0 +1,23 @@
1
+ import { WebsocketBuffer } from "./websocket_buffer";
2
+ import { WebsocketConnectionRetryOptions } from "./websocket_retry_options";
3
+ import { WebsocketEventListeners } from "./websocket_event";
4
+
5
+ /**
6
+ * Options that can be passed to the Websocket constructor.
7
+ */
8
+ export interface WebsocketOptions {
9
+ /**
10
+ * The Buffer to use.
11
+ */
12
+ readonly buffer?: WebsocketBuffer;
13
+
14
+ /**
15
+ * The options for the connection-retry-strategy.
16
+ */
17
+ readonly retry?: WebsocketConnectionRetryOptions;
18
+
19
+ /**
20
+ * The initial listeners to add to the websocket.
21
+ */
22
+ readonly listeners?: WebsocketEventListeners;
23
+ }
@@ -0,0 +1,22 @@
1
+ import { Backoff } from "./backoff/backoff";
2
+
3
+ /**
4
+ * Options for the websockets retry-strategy.
5
+ */
6
+ export interface WebsocketConnectionRetryOptions {
7
+ /**
8
+ * The maximum number of retries before giving up. No limit if undefined.
9
+ */
10
+ readonly maxRetries?: number;
11
+
12
+ /**
13
+ * Wether to reconnect immediately after a connection has been lost,
14
+ * ignoring the backoff strategy for the first retry.
15
+ */
16
+ readonly instantReconnect?: boolean;
17
+
18
+ /**
19
+ * The backoff strategy to use. This is used to determine the delay between connection-retries.
20
+ */
21
+ readonly backoff?: Backoff;
22
+ }
@@ -10,11 +10,11 @@
10
10
  // "allowJs": true, /* Allow javascript files to be compiled. */
11
11
  // "checkJs": true, /* Report errors in .js files. */
12
12
  // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
13
- "declaration": true, /* Generates corresponding '.d.ts' file. */
14
- "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
15
- "sourceMap": true, /* Generates corresponding '.map' file. */
13
+ "declaration": true, /* Generates corresponding '.d.ts' file. */
14
+ "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
15
+ "sourceMap": true, /* Generates corresponding '.map' file. */
16
16
  // "outFile": "./", /* Concatenate and emit output to single file. */
17
- "outDir": "lib", /* Redirect output structure to the directory. */
17
+ "outDir": "./dist/cjs", /* Redirect output structure to the directory. */
18
18
  // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
19
19
  // "composite": true, /* Enable project compilation */
20
20
  // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
@@ -26,7 +26,7 @@
26
26
 
27
27
  /* Strict Type-Checking Options */
28
28
  "strict": true, /* Enable all strict type-checking options. */
29
- // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
29
+ "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
30
30
  // "strictNullChecks": true, /* Enable strict null checks. */
31
31
  // "strictFunctionTypes": true, /* Enable strict checking of function types. */
32
32
  // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
@@ -63,9 +63,9 @@
63
63
  // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
64
64
 
65
65
  /* Advanced Options */
66
- "skipLibCheck": true, /* Skip type checking of declaration files. */
66
+ // "skipLibCheck": true, /* Skip type checking of declaration files. */
67
67
  "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
68
68
  },
69
- "include": ["src"],
70
- "exclude": ["node_modules", "lib"]
69
+ "include": ["src", "tests"],
70
+ "exclude": ["node_modules", "dist"]
71
71
  }
@@ -0,0 +1,71 @@
1
+ {
2
+ "compilerOptions": {
3
+ /* Visit https://aka.ms/tsconfig.json to read more about this file */
4
+
5
+ /* Basic Options */
6
+ // "incremental": true, /* Enable incremental compilation */
7
+ "target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
8
+ "module": "es6", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
9
+ // "lib": [], /* Specify library files to be included in the compilation. */
10
+ // "allowJs": true, /* Allow javascript files to be compiled. */
11
+ // "checkJs": true, /* Report errors in .js files. */
12
+ // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
13
+ "declaration": true, /* Generates corresponding '.d.ts' file. */
14
+ "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
15
+ "sourceMap": true, /* Generates corresponding '.map' file. */
16
+ // "outFile": "./", /* Concatenate and emit output to single file. */
17
+ "outDir": "./dist/esm", /* Redirect output structure to the directory. */
18
+ // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
19
+ // "composite": true, /* Enable project compilation */
20
+ // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
21
+ // "removeComments": true, /* Do not emit comments to output. */
22
+ // "noEmit": true, /* Do not emit outputs. */
23
+ // "importHelpers": true, /* Import emit helpers from 'tslib'. */
24
+ // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
25
+ // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
26
+
27
+ /* Strict Type-Checking Options */
28
+ "strict": true, /* Enable all strict type-checking options. */
29
+ "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
30
+ // "strictNullChecks": true, /* Enable strict null checks. */
31
+ // "strictFunctionTypes": true, /* Enable strict checking of function types. */
32
+ // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
33
+ // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
34
+ // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
35
+ // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
36
+
37
+ /* Additional Checks */
38
+ // "noUnusedLocals": true, /* Report errors on unused locals. */
39
+ // "noUnusedParameters": true, /* Report errors on unused parameters. */
40
+ // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
41
+ // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
42
+
43
+ /* Module Resolution Options */
44
+ "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
45
+ // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
46
+ // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
47
+ // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
48
+ // "typeRoots": [], /* List of folders to include type definitions from. */
49
+ // "types": [], /* Type declaration files to be included in compilation. */
50
+ // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
51
+ "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
52
+ // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
53
+ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
54
+
55
+ /* Source Map Options */
56
+ // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
57
+ // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
58
+ // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
59
+ // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
60
+
61
+ /* Experimental Options */
62
+ // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
63
+ // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
64
+
65
+ /* Advanced Options */
66
+ // "skipLibCheck": true, /* Skip type checking of declaration files. */
67
+ "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
68
+ },
69
+ "include": ["src", "tests"],
70
+ "exclude": ["node_modules", "dist"]
71
+ }
package/jest.config.js DELETED
@@ -1,9 +0,0 @@
1
- module.exports = {
2
- transform: {
3
- "^.+\\.tsx?$": "ts-jest",
4
- },
5
- testRegex: "(/tests/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
6
- moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
7
- collectCoverage: true,
8
- testEnvironment: "jsdom"
9
- };
@@ -1,18 +0,0 @@
1
- /**
2
- * Backoff provides a series of numbers. This series follows
3
- * a concrete pattern, e.g. be constant, linearly increasing,
4
- * exponentially increasing etc.
5
- */
6
- export interface Backoff {
7
- /**
8
- * Provides the callee with the next number in the
9
- * series.
10
- * @return the next number
11
- */
12
- next(): number;
13
- /**
14
- * Resets the series to its starting-value.
15
- */
16
- reset(): void;
17
- }
18
- //# sourceMappingURL=backoff.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"backoff.d.ts","sourceRoot":"","sources":["../../src/backoff/backoff.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,WAAW,OAAO;IACpB;;;;OAIG;IACH,IAAI,IAAI,MAAM,CAAA;IAEd;;OAEG;IACH,KAAK,IAAI,IAAI,CAAA;CAChB"}
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=backoff.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"backoff.js","sourceRoot":"","sources":["../../src/backoff/backoff.ts"],"names":[],"mappings":""}
@@ -1,11 +0,0 @@
1
- import { Backoff } from "./backoff";
2
- /**
3
- * ConstantBackoff always returns the same value.
4
- */
5
- export declare class ConstantBackoff implements Backoff {
6
- private readonly backoff;
7
- constructor(backoff: number);
8
- next(): number;
9
- reset: () => void;
10
- }
11
- //# sourceMappingURL=constantbackoff.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constantbackoff.d.ts","sourceRoot":"","sources":["../../src/backoff/constantbackoff.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAElC;;GAEG;AACH,qBAAa,eAAgB,YAAW,OAAO;IAC3C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAErB,OAAO,EAAE,MAAM;IAI3B,IAAI,IAAI,MAAM;IAId,KAAK,aAEJ;CACJ"}
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ConstantBackoff = void 0;
4
- /**
5
- * ConstantBackoff always returns the same value.
6
- */
7
- var ConstantBackoff = /** @class */ (function () {
8
- function ConstantBackoff(backoff) {
9
- this.reset = function () {
10
- // no-op
11
- };
12
- this.backoff = backoff;
13
- }
14
- ConstantBackoff.prototype.next = function () {
15
- return this.backoff;
16
- };
17
- return ConstantBackoff;
18
- }());
19
- exports.ConstantBackoff = ConstantBackoff;
20
- //# sourceMappingURL=constantbackoff.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constantbackoff.js","sourceRoot":"","sources":["../../src/backoff/constantbackoff.ts"],"names":[],"mappings":";;;AAEA;;GAEG;AACH;IAGI,yBAAY,OAAe;QAQ3B,UAAK,GAAG;YACJ,QAAQ;QACZ,CAAC,CAAA;QATG,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IAC3B,CAAC;IAED,8BAAI,GAAJ;QACI,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;IAKL,sBAAC;AAAD,CAAC,AAdD,IAcC;AAdY,0CAAe"}
@@ -1,22 +0,0 @@
1
- import { Backoff } from "./backoff";
2
- /**
3
- * ExponentialBackoff doubles the backoff with every step until a maximum
4
- * is reached. This is modelled after the binary exponential-backoff algo-
5
- * rithm used in computer-networking.
6
- *
7
- * The calculation-specification is:
8
- * backoff = k * 2^s with s in [1, expMax].
9
- *
10
- * Example: for initial=100, expMax=7 the ExponentialBackoff will pro-
11
- * duce the backoff-series [100, 200, 400, 800, 1600, 3200, 6400].
12
- */
13
- export declare class ExponentialBackoff implements Backoff {
14
- private readonly initial;
15
- private readonly expMax;
16
- private expCurrent;
17
- private current;
18
- constructor(initial: number, expMax: number);
19
- next(): number;
20
- reset(): void;
21
- }
22
- //# sourceMappingURL=exponentialbackoff.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"exponentialbackoff.d.ts","sourceRoot":"","sources":["../../src/backoff/exponentialbackoff.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAElC;;;;;;;;;;GAUG;AACH,qBAAa,kBAAmB,YAAW,OAAO;IAC9C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,OAAO,CAAS;gBAEZ,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAO3C,IAAI,IAAI,MAAM;IAOd,KAAK;CAIR"}
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ExponentialBackoff = void 0;
4
- /**
5
- * ExponentialBackoff doubles the backoff with every step until a maximum
6
- * is reached. This is modelled after the binary exponential-backoff algo-
7
- * rithm used in computer-networking.
8
- *
9
- * The calculation-specification is:
10
- * backoff = k * 2^s with s in [1, expMax].
11
- *
12
- * Example: for initial=100, expMax=7 the ExponentialBackoff will pro-
13
- * duce the backoff-series [100, 200, 400, 800, 1600, 3200, 6400].
14
- */
15
- var ExponentialBackoff = /** @class */ (function () {
16
- function ExponentialBackoff(initial, expMax) {
17
- this.initial = initial;
18
- this.expMax = expMax;
19
- this.expCurrent = 1;
20
- this.current = this.initial;
21
- }
22
- ExponentialBackoff.prototype.next = function () {
23
- var backoff = this.current;
24
- if (this.expMax > this.expCurrent++)
25
- this.current = this.current * 2;
26
- return backoff;
27
- };
28
- ExponentialBackoff.prototype.reset = function () {
29
- this.expCurrent = 1;
30
- this.current = this.initial;
31
- };
32
- return ExponentialBackoff;
33
- }());
34
- exports.ExponentialBackoff = ExponentialBackoff;
35
- //# sourceMappingURL=exponentialbackoff.js.map