Skip to content

Commit 678e42f

Browse files
committed
style: [sdk-1577] fixing lint issues
1 parent 66c80c7 commit 678e42f

File tree

7 files changed

+88
-78
lines changed

7 files changed

+88
-78
lines changed

packages/shared/common/src/internal/fdv2/FDv2ChangeSetBuilder.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PutObject, DeleteObject, Event } from './proto';
1+
import { DeleteObject, Event, PutObject } from './proto';
22

33
// eventually this will be the same as the IntentCode type, but for now we'll use a simpler type
44
type supportedIntentCodes = 'xfer-full';
@@ -13,15 +13,15 @@ type supportedIntentCodes = 'xfer-full';
1313
* compatibility guarantees or semantic versioning. It is not suitable for production usage.
1414
*/
1515
export default class FDv2ChangeSetBuilder {
16-
private intent?: supportedIntentCodes;
17-
private events: Event[] = [];
16+
private _intent?: supportedIntentCodes;
17+
private _events: Event[] = [];
1818

1919
/**
2020
* Begins a new change set with a given intent.
2121
*/
2222
start(intent: supportedIntentCodes): this {
23-
this.intent = intent;
24-
this.events = [];
23+
this._intent = intent;
24+
this._events = [];
2525

2626
return this;
2727
}
@@ -33,7 +33,7 @@ export default class FDv2ChangeSetBuilder {
3333
* resetting some values in the future.
3434
*/
3535
finish(): Array<Event> {
36-
if (this.intent === undefined) {
36+
if (this._intent === undefined) {
3737
throw new Error('changeset: cannot complete without a server-intent');
3838
}
3939

@@ -45,16 +45,17 @@ export default class FDv2ChangeSetBuilder {
4545
{
4646
event: 'server-intent',
4747
data: {
48-
payloads: [{
48+
payloads: [
49+
{
4950
id: 'dummy-id',
5051
target: 1,
51-
intentCode: this.intent,
52+
intentCode: this._intent!,
5253
reason: 'payload-missing',
5354
},
54-
]
55-
}
55+
],
56+
},
5657
},
57-
...this.events,
58+
...this._events,
5859
{
5960
event: 'payload-transferred',
6061
data: {
@@ -63,7 +64,7 @@ export default class FDv2ChangeSetBuilder {
6364
state: '',
6465
version: 1,
6566
id: 'dummy-id',
66-
}
67+
},
6768
},
6869
];
6970

@@ -74,23 +75,23 @@ export default class FDv2ChangeSetBuilder {
7475
* Adds a new object to the changeset.
7576
*/
7677
putObject(obj: PutObject): this {
77-
this.events.push({
78+
this._events.push({
7879
event: 'put-object',
7980
data: obj,
8081
});
8182

82-
return this
83+
return this;
8384
}
8485

8586
/**
8687
* Adds a deletion to the changeset.
8788
*/
8889
deleteObject(obj: DeleteObject): this {
89-
this.events.push({
90+
this._events.push({
9091
event: 'delete-object',
91-
data: obj
92+
data: obj,
9293
});
9394

94-
return this
95+
return this;
9596
}
9697
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import FDv2ChangeSetBuilder from './FDv2ChangeSetBuilder';
12
import {
23
FDv2EventsCollection,
34
Payload,
@@ -6,7 +7,6 @@ import {
67
Update,
78
} from './payloadProcessor';
89
import { PayloadStreamReader } from './payloadStreamReader';
9-
import FDv2ChangeSetBuilder from './FDv2ChangeSetBuilder';
1010

1111
export {
1212
FDv2EventsCollection,

packages/shared/common/src/internal/fdv2/payloadProcessor.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ export class PayloadProcessor {
224224
// server intent hasn't been received yet.
225225
!this._tempId ||
226226
// selector can be an empty string if we are using a file data initilizer
227-
(data.state === null || data.state === undefined) ||
227+
data.state === null ||
228+
data.state === undefined ||
228229
!data.version
229230
) {
230231
this._resetAll(); // a reset is best defensive action since payload transferred terminates a payload

packages/shared/common/src/internal/fdv2/proto.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
1-
export type EventType = 'server-intent' | 'put-object' | 'delete-object' | 'payload-transferred' | 'goodbye' | 'error'| 'heart-beat';
1+
export type EventType =
2+
| 'server-intent'
3+
| 'put-object'
4+
| 'delete-object'
5+
| 'payload-transferred'
6+
| 'goodbye'
7+
| 'error'
8+
| 'heart-beat';
29
export type IntentCode = 'xfer-full' | 'xfer-changes' | 'none';
310
export type ObjectKind = 'flag' | 'segment';
411

512
export interface Event {
613
event: EventType;
7-
data: ServerIntentData | PutObject | DeleteObject | PayloadTransferred | GoodbyeObject | ErrorObject;
14+
data:
15+
| ServerIntentData
16+
| PutObject
17+
| DeleteObject
18+
| PayloadTransferred
19+
| GoodbyeObject
20+
| ErrorObject;
821
}
922

1023
export interface ServerIntentData {

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ import BigSegmentStoreStatusProvider from './BigSegmentStatusProviderImpl';
4343
import { createPluginEnvironmentMetadata } from './createPluginEnvironmentMetadata';
4444
import { createPayloadListener } from './data_sources/createPayloadListenerFDv2';
4545
import { createStreamListeners } from './data_sources/createStreamListeners';
46-
import FileDataInitializerFDv2 from './data_sources/fileDataInitilizerFDv2';
4746
import DataSourceUpdates from './data_sources/DataSourceUpdates';
47+
import FileDataInitializerFDv2 from './data_sources/fileDataInitilizerFDv2';
4848
import OneShotInitializerFDv2 from './data_sources/OneShotInitializerFDv2';
4949
import PollingProcessor from './data_sources/PollingProcessor';
5050
import PollingProcessorFDv2 from './data_sources/PollingProcessorFDv2';
@@ -335,13 +335,7 @@ function constructFDv2(
335335
),
336336
);
337337
} else if (dataSystem.dataSource?.initializerOptions?.type === 'file') {
338-
initializers.push(
339-
() =>
340-
new FileDataInitializerFDv2(
341-
config,
342-
platform,
343-
),
344-
);
338+
initializers.push(() => new FileDataInitializerFDv2(config, platform));
345339
}
346340

347341
const synchronizers: subsystem.LDDataSourceFactory[] = [];

packages/shared/sdk-server/src/api/options/LDDataSystemOptions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,15 @@ export interface FileDataInitializerOptions {
8484
type: 'file';
8585
paths: Array<string>;
8686
yamlParser?: (data: string) => any;
87-
};
87+
}
8888

8989
/**
9090
* Initializer option to initilize the SDK from doing a one time full payload transfer.
9191
* This will be the default initializer used by the standard data source type.
9292
*/
9393
export interface PollingDataInitializerOptions {
9494
type: 'polling';
95-
};
95+
}
9696

9797
/**
9898
* This standard data source is the recommended datasource for most customers. It will use

packages/shared/sdk-server/src/data_sources/fileDataInitilizerFDv2.ts

Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import {
88
subsystem as subsystemCommon,
99
} from '@launchdarkly/js-sdk-common';
1010

11+
import { FileDataInitializerOptions } from '../api';
1112
import { Flag } from '../evaluation/data/Flag';
1213
import { Segment } from '../evaluation/data/Segment';
13-
import { processFlag, processSegment } from '../store/serialization';
1414
import Configuration from '../options/Configuration';
15-
import { FileDataInitializerOptions } from '../api';
15+
import { processFlag, processSegment } from '../store/serialization';
1616
import FileLoader from './FileLoader';
1717

1818
/**
@@ -26,11 +26,8 @@ export default class FileDataInitializerFDv2 implements subsystemCommon.DataSour
2626
private _fileLoader?: FileLoader;
2727

2828
// TODO: do a options check here
29-
constructor(
30-
config: Configuration,
31-
platform: Platform
32-
) {
33-
const options = config.dataSystem?.dataSource?.initializerOptions as FileDataInitializerOptions
29+
constructor(config: Configuration, platform: Platform) {
30+
const options = config.dataSystem?.dataSource?.initializerOptions as FileDataInitializerOptions;
3431
this._validateInputs(options, platform);
3532

3633
this._paths = options.paths;
@@ -56,7 +53,8 @@ export default class FileDataInitializerFDv2 implements subsystemCommon.DataSour
5653
statusCallback(subsystemCommon.DataSourceState.Initializing);
5754
const initMetadata = internal.initMetadataFromHeaders(undefined);
5855

59-
const payloadProcessor = new internal.PayloadProcessor({
56+
const payloadProcessor = new internal.PayloadProcessor(
57+
{
6058
flag: (flag: Flag) => {
6159
processFlag(flag);
6260
return flag;
@@ -102,56 +100,59 @@ export default class FileDataInitializerFDv2 implements subsystemCommon.DataSour
102100
);
103101
}
104102
},
105-
)
103+
);
106104

107-
this._fileLoader.loadAndWatch()
105+
this._fileLoader.loadAndWatch();
108106
}
109107

110-
_processFileData(results: { path: string; data: string }[]) {
111-
const combined: any = results.reduce((acc, curr) => {
112-
let parsed: any;
113-
if (curr.path.endsWith('.yml') || curr.path.endsWith('.yaml')) {
114-
if (this._yamlParser) {
115-
parsed = this._yamlParser(curr.data);
108+
private _processFileData(results: { path: string; data: string }[]) {
109+
const combined: any = results.reduce(
110+
(acc, curr) => {
111+
let parsed: any;
112+
if (curr.path.endsWith('.yml') || curr.path.endsWith('.yaml')) {
113+
if (this._yamlParser) {
114+
parsed = this._yamlParser(curr.data);
115+
} else {
116+
throw new Error(`Attempted to parse yaml file (${curr.path}) without parser.`);
117+
}
116118
} else {
117-
throw new Error(`Attempted to parse yaml file (${curr.path}) without parser.`);
118-
}
119-
} else {
120-
parsed = JSON.parse(curr.data);
121-
}
122-
return {
123-
segments: {
124-
...acc.segments,
125-
...parsed.segments,
126-
},
127-
flags: {
128-
...acc.flags,
129-
...parsed.flags,
119+
parsed = JSON.parse(curr.data);
130120
}
131-
}
132-
}, {
133-
segments: {},
134-
flags: {},
135-
});
121+
return {
122+
segments: {
123+
...acc.segments,
124+
...parsed.segments,
125+
},
126+
flags: {
127+
...acc.flags,
128+
...parsed.flags,
129+
},
130+
};
131+
},
132+
{
133+
segments: {},
134+
flags: {},
135+
},
136+
);
136137

137-
const changeSetBuilder = new internal.FDv2ChangeSetBuilder()
138-
changeSetBuilder.start('xfer-full')
138+
const changeSetBuilder = new internal.FDv2ChangeSetBuilder();
139+
changeSetBuilder.start('xfer-full');
139140

140-
Object.keys(combined).forEach((kind : string) => {
141+
Object.keys(combined).forEach((kind: string) => {
141142
Object.entries<any>(combined[kind]).forEach(([k, v]) => {
142-
changeSetBuilder.putObject({
143-
// strong assumption here that we only have segments and flags.
144-
kind: kind === 'segments' ? 'segment' : 'flag',
145-
key: k,
146-
version: v.version || 1,
147-
object: v
148-
})
149-
})
143+
changeSetBuilder.putObject({
144+
// strong assumption here that we only have segments and flags.
145+
kind: kind === 'segments' ? 'segment' : 'flag',
146+
key: k,
147+
version: v.version || 1,
148+
object: v,
149+
});
150150
});
151+
});
151152

152153
return {
153-
events: changeSetBuilder.finish()
154-
}
154+
events: changeSetBuilder.finish(),
155+
};
155156
}
156157

157158
stop() {

0 commit comments

Comments
 (0)