Skip to content

Commit 9d3169b

Browse files
committed
linting
Signed-off-by: marcozabel <[email protected]>
1 parent 976136d commit 9d3169b

File tree

8 files changed

+59
-40
lines changed

8 files changed

+59
-40
lines changed

libs/providers/flagd/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
"current-version": "echo $npm_package_version"
88
},
99
"peerDependencies": {
10-
"@grpc/grpc-js": "~1.8.0 || ~1.9.0 || ~1.10.0 || ~1.11.0 || ~1.12.0 || ~1.13.0",
11-
"@openfeature/server-sdk": "^1.17.0"
10+
"@grpc/grpc-js": "~1.8.0 || ~1.9.0 || ~1.10.0 || ~1.11.0 || ~1.12.0 || ~1.13.0 || ~1.14.0",
11+
"@openfeature/server-sdk": "^1.17.0",
12+
"@openfeature/web-sdk": "^1.6.0",
13+
"@openfeature/core": "^1.9.0"
1214
},
1315
"dependencies": {
1416
"lru-cache": "^11.0.0",
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import {Hook} from "@openfeature/web-sdk";
2-
import { EvaluationContext } from "@openfeature/server-sdk";
3-
import { BeforeHookContext, HookHints } from "@openfeature/core";
1+
import type { Hook } from '@openfeature/web-sdk';
2+
import type { EvaluationContext } from '@openfeature/server-sdk';
3+
import type { BeforeHookContext, HookHints } from '@openfeature/core';
44

5-
export class SyncMetadataHook implements Hook<any> {
5+
export class SyncMetadataHook implements Hook {
66
enrichedContext: () => EvaluationContext;
77

88
constructor(enrichedContext: () => EvaluationContext) {
9-
this.enrichedContext = enrichedContext
9+
this.enrichedContext = enrichedContext;
1010
}
1111

12-
public before(hookContext: BeforeHookContext, hookHints?: HookHints): EvaluationContext {
12+
public before(): EvaluationContext {
1313
return this.enrichedContext.apply(this);
1414
}
1515
}

libs/providers/flagd/src/lib/configuration.spec.ts

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Config, FlagdProviderOptions } from './configuration';
22
import { getConfig } from './configuration';
33
import { DEFAULT_MAX_CACHE_SIZE } from './constants';
4-
import { EvaluationContext } from "@openfeature/server-sdk";
4+
import type { EvaluationContext } from '@openfeature/server-sdk';
55

66
describe('Configuration', () => {
77
const OLD_ENV = process.env;
@@ -48,33 +48,39 @@ describe('Configuration', () => {
4848
process.env['FLAGD_OFFLINE_FLAG_SOURCE_PATH'] = offlineFlagSourcePath;
4949
process.env['FLAGD_DEFAULT_AUTHORITY'] = defaultAuthority;
5050

51-
expect(getConfig()).toEqual(expect.objectContaining({
52-
host,
53-
port,
54-
tls,
55-
socketPath,
56-
maxCacheSize,
57-
cache,
58-
resolverType,
59-
selector,
60-
offlineFlagSourcePath,
61-
defaultAuthority,
62-
deadlineMs: 500,
63-
}));
51+
expect(getConfig()).toEqual(
52+
expect.objectContaining({
53+
host,
54+
port,
55+
tls,
56+
socketPath,
57+
maxCacheSize,
58+
cache,
59+
resolverType,
60+
selector,
61+
offlineFlagSourcePath,
62+
defaultAuthority,
63+
deadlineMs: 500,
64+
}),
65+
);
6466
});
6567

6668
it('should override context enricher', () => {
67-
const contextEnricher = (syncContext: {[key: string]: string} | null) => { return { ...syncContext, extraKey: "extraValue" } as EvaluationContext };
69+
const contextEnricher = (syncContext: { [key: string]: string } | null) => {
70+
return { ...syncContext, extraKey: 'extraValue' } as EvaluationContext;
71+
};
6872

69-
expect(getConfig({ contextEnricher }).contextEnricher({})).toEqual({extraKey: "extraValue"});
73+
expect(getConfig({ contextEnricher }).contextEnricher({})).toEqual({ extraKey: 'extraValue' });
7074
});
7175

7276
it('should return identity function', () => {
7377
expect(getConfig().contextEnricher({})).toStrictEqual({});
7478
});
7579

7680
it('should use incoming options over defaults and environment variable', () => {
77-
const contextEnricher = (syncContext: {[key: string]: string} | null) => { return { ...syncContext, extraKey: "extraValue" } as EvaluationContext };
81+
const contextEnricher = (syncContext: { [key: string]: string } | null) => {
82+
return { ...syncContext, extraKey: 'extraValue' } as EvaluationContext;
83+
};
7884
const options: FlagdProviderOptions = {
7985
host: 'test',
8086
port: 3000,
@@ -85,7 +91,7 @@ describe('Configuration', () => {
8591
selector: '',
8692
defaultAuthority: '',
8793
deadlineMs: 500,
88-
contextEnricher: contextEnricher
94+
contextEnricher: contextEnricher,
8995
};
9096

9197
process.env['FLAGD_HOST'] = 'override';

libs/providers/flagd/src/lib/configuration.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { DEFAULT_MAX_CACHE_SIZE } from './constants';
2-
import { EvaluationContext } from "@openfeature/core";
2+
import type { EvaluationContext } from '@openfeature/core';
33

44
export type CacheOption = 'lru' | 'disabled';
55
export type ResolverType = 'rpc' | 'in-process';
@@ -85,7 +85,6 @@ export interface Config {
8585
}
8686

8787
interface FlagdConfig extends Config {
88-
8988
/**
9089
* Function providing an EvaluationContext to mix into every evaluation.
9190
* The syncContext from the SyncFlagsResponse
@@ -95,8 +94,7 @@ interface FlagdConfig extends Config {
9594
* This function runs every time the provider (re)connects, and its result is cached and used in every evaluation.
9695
* By default, the entire sync response (converted to a Structure) is used.
9796
*/
98-
contextEnricher: (syncContext: {[key: string]: string} | null) => EvaluationContext
99-
97+
contextEnricher: (syncContext: { [key: string]: string } | null) => EvaluationContext;
10098
}
10199

102100
export type FlagdProviderOptions = Partial<FlagdConfig>;
@@ -108,7 +106,7 @@ const DEFAULT_CONFIG: Omit<FlagdConfig, 'port' | 'resolverType'> = {
108106
selector: '',
109107
cache: 'lru',
110108
maxCacheSize: DEFAULT_MAX_CACHE_SIZE,
111-
contextEnricher: (syncContext: {[key: string]: string} | null) => syncContext as EvaluationContext
109+
contextEnricher: (syncContext: { [key: string]: string } | null) => syncContext as EvaluationContext,
112110
};
113111

114112
const DEFAULT_RPC_CONFIG: FlagdConfig = { ...DEFAULT_CONFIG, resolverType: 'rpc', port: 8013 };

libs/providers/flagd/src/lib/flagd-provider.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { getConfig } from './configuration';
55
import { GRPCService } from './service/grpc/grpc-service';
66
import type { Service } from './service/service';
77
import { InProcessService } from './service/in-process/in-process-service';
8-
import { Hook } from "@openfeature/web-sdk";
9-
import { SyncMetadataHook } from "./SyncMetadataHook";
8+
import type { Hook } from '@openfeature/web-sdk';
9+
import { SyncMetadataHook } from './SyncMetadataHook';
1010

1111
export class FlagdProvider implements Provider {
1212
metadata = {
@@ -35,7 +35,7 @@ export class FlagdProvider implements Provider {
3535
const config = getConfig(options);
3636

3737
if (service === undefined) {
38-
if (config.resolverType === "in-process") {
38+
if (config.resolverType === 'in-process') {
3939
this._service = new InProcessService(config, this.setSyncContext, undefined, logger);
4040

4141
if (config?.offlineFlagSourcePath === undefined) {
@@ -49,11 +49,11 @@ export class FlagdProvider implements Provider {
4949
}
5050
}
5151

52-
setSyncContext(context: {[key: string]: string}) {
52+
setSyncContext(context: { [key: string]: string }) {
5353
this.syncContext = context;
5454
}
5555

56-
getSyncContext(): {[key: string]: string} | null {
56+
getSyncContext(): { [key: string]: string } | null {
5757
return this.syncContext;
5858
}
5959

libs/providers/flagd/src/lib/service/in-process/grpc/grpc-fetch.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ describe('grpc fetch', () => {
8484

8585
it('should handle SyncContext from SyncFlagsResponse', (done) => {
8686
const initFlagConfig = '{"flags":{}}';
87-
const syncContext = {"test": "example"};
87+
const syncContext = { test: 'example' };
8888

8989
const fetch = new GrpcFetch(cfg, setSyncContext, serviceMock);
9090
fetch

libs/providers/flagd/src/lib/service/in-process/grpc/grpc-fetch.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ export class GrpcFetch implements DataFetch {
3030
*/
3131
private _isConnected = false;
3232

33-
constructor(config: Config, setSyncContext: (syncContext: {[key: string]: string }) => void, syncServiceClient?: FlagSyncServiceClient, logger?: Logger) {
33+
constructor(
34+
config: Config,
35+
setSyncContext: (syncContext: { [key: string]: string }) => void,
36+
syncServiceClient?: FlagSyncServiceClient,
37+
logger?: Logger,
38+
) {
3439
const { host, port, tls, socketPath, selector, defaultAuthority } = config;
3540
let clientOptions: ClientOptions | undefined;
3641
if (defaultAuthority) {

libs/providers/flagd/src/lib/service/in-process/in-process-service.spec.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ describe('In-process-service', () => {
3131
it('should include scope as flag metadata', async () => {
3232
// given
3333
const selector = 'devFlags';
34-
const service = new InProcessService({ deadlineMs: 500, host: '', port: 0, tls: false, selector }, jest.fn(), dataFetcher);
34+
const service = new InProcessService(
35+
{ deadlineMs: 500, host: '', port: 0, tls: false, selector },
36+
jest.fn(),
37+
dataFetcher,
38+
);
3539

3640
// when
3741
await service.connect(jest.fn, jest.fn, jest.fn);
@@ -44,7 +48,11 @@ describe('In-process-service', () => {
4448
it('should not override existing scope in flag metadata', async () => {
4549
// given
4650
const selector = 'devFlags';
47-
const service = new InProcessService({ deadlineMs: 500, host: '', port: 0, tls: false, selector }, jest.fn(), dataFetcher);
51+
const service = new InProcessService(
52+
{ deadlineMs: 500, host: '', port: 0, tls: false, selector },
53+
jest.fn(),
54+
dataFetcher,
55+
);
4856

4957
// when
5058
await service.connect(jest.fn, jest.fn, jest.fn);

0 commit comments

Comments
 (0)