Skip to content

Commit 1608aa8

Browse files
committed
chore: moving internal StreamingProcessor class from js-sdk-common to js-server-sdk-common
1 parent 8351aca commit 1608aa8

File tree

9 files changed

+49
-37
lines changed

9 files changed

+49
-37
lines changed

packages/shared/common/src/datasource/errors.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,5 @@ export class LDStreamingError extends Error {
3535
this.recoverable = recoverable;
3636
}
3737
}
38+
39+
export type StreamingErrorHandler = (err: LDStreamingError) => void;
Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
import { DataSourceErrorKind } from './DataSourceErrorKinds';
2-
import { LDFileDataSourceError, LDPollingError, LDStreamingError } from './errors';
2+
import {
3+
LDFileDataSourceError,
4+
LDPollingError,
5+
LDStreamingError,
6+
StreamingErrorHandler,
7+
} from './errors';
38

4-
export { DataSourceErrorKind, LDFileDataSourceError, LDPollingError, LDStreamingError };
9+
export {
10+
DataSourceErrorKind,
11+
LDFileDataSourceError,
12+
LDPollingError,
13+
LDStreamingError,
14+
StreamingErrorHandler,
15+
};

packages/shared/common/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
LDFileDataSourceError,
77
LDPollingError,
88
LDStreamingError,
9+
StreamingErrorHandler,
910
} from './datasource';
1011

1112
export * from './api';
@@ -24,5 +25,6 @@ export {
2425
DataSourceErrorKind,
2526
LDPollingError,
2627
LDStreamingError,
28+
StreamingErrorHandler,
2729
LDFileDataSourceError,
2830
};

packages/shared/common/src/internal/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@ export * from './context';
22
export * from './diagnostics';
33
export * from './evaluation';
44
export * from './events';
5-
export * from './stream';

packages/shared/common/src/internal/stream/index.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

packages/shared/common/src/internal/stream/types.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

packages/shared/common/__tests__/internal/stream/StreamingProcessor.test.ts renamed to packages/shared/sdk-server/__tests__/data_sources/StreamingProcessor.test.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
import { EventName, Info, LDLogger, ProcessStreamResponse } from '../../../src/api';
2-
import { LDStreamProcessor } from '../../../src/api/subsystem';
3-
import { DataSourceErrorKind } from '../../../src/datasource/DataSourceErrorKinds';
4-
import { LDStreamingError } from '../../../src/datasource/errors';
5-
import { DiagnosticsManager } from '../../../src/internal/diagnostics';
6-
import StreamingProcessor from '../../../src/internal/stream/StreamingProcessor';
7-
import { defaultHeaders } from '../../../src/utils';
8-
import { createBasicPlatform } from '../../createBasicPlatform';
1+
import {
2+
DataSourceErrorKind,
3+
defaultHeaders,
4+
EventName,
5+
Info,
6+
internal,
7+
LDLogger,
8+
LDStreamingError,
9+
ProcessStreamResponse,
10+
subsystem,
11+
} from '@launchdarkly/js-sdk-common';
12+
13+
import StreamingProcessor from '../../src/data_sources/StreamingProcessor';
14+
import { createBasicPlatform } from '../createBasicPlatform';
915

1016
let logger: LDLogger;
1117

@@ -61,8 +67,8 @@ const createMockEventSource = (streamUri: string = '', options: any = {}) => ({
6167

6268
describe('given a stream processor with mock event source', () => {
6369
let info: Info;
64-
let streamingProcessor: LDStreamProcessor;
65-
let diagnosticsManager: DiagnosticsManager;
70+
let streamingProcessor: subsystem.LDStreamProcessor;
71+
let diagnosticsManager: internal.DiagnosticsManager;
6672
let listeners: Map<EventName, ProcessStreamResponse>;
6773
let mockEventSource: any;
6874
let mockListener: ProcessStreamResponse;
@@ -104,7 +110,7 @@ describe('given a stream processor with mock event source', () => {
104110
listeners.set('put', mockListener);
105111
listeners.set('patch', mockListener);
106112

107-
diagnosticsManager = new DiagnosticsManager(sdkKey, basicPlatform, {});
113+
diagnosticsManager = new internal.DiagnosticsManager(sdkKey, basicPlatform, {});
108114
streamingProcessor = new StreamingProcessor(
109115
{
110116
basicConfiguration: getBasicConfiguration(logger),

packages/shared/sdk-server/src/LDClientImpl.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import { createStreamListeners } from './data_sources/createStreamListeners';
3636
import DataSourceUpdates from './data_sources/DataSourceUpdates';
3737
import PollingProcessor from './data_sources/PollingProcessor';
3838
import Requestor from './data_sources/Requestor';
39+
import StreamingProcessor from './data_sources/StreamingProcessor';
3940
import createDiagnosticsInitConfig from './diagnostics/createDiagnosticsInitConfig';
4041
import { allAsync } from './evaluation/collection';
4142
import { Flag } from './evaluation/data/Flag';
@@ -220,7 +221,7 @@ export default class LDClientImpl implements LDClient {
220221
});
221222
const makeDefaultProcessor = () =>
222223
config.stream
223-
? new internal.StreamingProcessor(
224+
? new StreamingProcessor(
224225
clientContext,
225226
'/all',
226227
[],

packages/shared/common/src/internal/stream/StreamingProcessor.ts renamed to packages/shared/sdk-server/src/data_sources/StreamingProcessor.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
import {
2+
ClientContext,
3+
DataSourceErrorKind,
24
EventName,
35
EventSource,
6+
getStreamingUri,
7+
httpErrorMessage,
48
HttpErrorResponse,
9+
internal,
10+
LDHeaders,
511
LDLogger,
12+
LDStreamingError,
613
ProcessStreamResponse,
714
Requests,
8-
} from '../../api';
9-
import { LDStreamProcessor } from '../../api/subsystem';
10-
import { DataSourceErrorKind } from '../../datasource/DataSourceErrorKinds';
11-
import { LDStreamingError } from '../../datasource/errors';
12-
import { ClientContext } from '../../options';
13-
import { getStreamingUri } from '../../options/ServiceEndpoints';
14-
import { httpErrorMessage, LDHeaders, shouldRetry } from '../../utils';
15-
import { DiagnosticsManager } from '../diagnostics';
16-
import { StreamingErrorHandler } from './types';
15+
shouldRetry,
16+
StreamingErrorHandler,
17+
subsystem,
18+
} from '@launchdarkly/js-sdk-common';
1719

1820
const reportJsonError = (
1921
type: string,
@@ -28,8 +30,7 @@ const reportJsonError = (
2830
);
2931
};
3032

31-
// TODO: SDK-156 - Move to Server SDK specific location
32-
class StreamingProcessor implements LDStreamProcessor {
33+
export default class StreamingProcessor implements subsystem.LDStreamProcessor {
3334
private readonly _headers: { [key: string]: string | string[] };
3435
private readonly _streamUri: string;
3536
private readonly _logger?: LDLogger;
@@ -44,7 +45,7 @@ class StreamingProcessor implements LDStreamProcessor {
4445
parameters: { key: string; value: string }[],
4546
private readonly _listeners: Map<EventName, ProcessStreamResponse>,
4647
baseHeaders: LDHeaders,
47-
private readonly _diagnosticsManager?: DiagnosticsManager,
48+
private readonly _diagnosticsManager?: internal.DiagnosticsManager,
4849
private readonly _errorHandler?: StreamingErrorHandler,
4950
private readonly _streamInitialReconnectDelay = 1,
5051
) {
@@ -167,5 +168,3 @@ class StreamingProcessor implements LDStreamProcessor {
167168
this.stop();
168169
}
169170
}
170-
171-
export default StreamingProcessor;

0 commit comments

Comments
 (0)