Skip to content

Commit 633dcb4

Browse files
committed
Update syncContext type to EvaluationContext
Signed-off-by: marcozabel <[email protected]>
1 parent 88985a5 commit 633dcb4

File tree

5 files changed

+14
-14
lines changed

5 files changed

+14
-14
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ describe('Configuration', () => {
6666
});
6767

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

7373
expect(getConfig({ contextEnricher }).contextEnricher({})).toEqual({ extraKey: 'extraValue' });
@@ -78,8 +78,8 @@ describe('Configuration', () => {
7878
});
7979

8080
it('should use incoming options over defaults and environment variable', () => {
81-
const contextEnricher = (syncContext: { [key: string]: string } | null) => {
82-
return { ...syncContext, extraKey: 'extraValue' } as EvaluationContext;
81+
const contextEnricher = (syncContext: EvaluationContext | null): EvaluationContext => {
82+
return { ...syncContext, extraKey: 'extraValue' };
8383
};
8484
const options: FlagdProviderOptions = {
8585
host: 'test',

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ interface FlagdConfig extends Config {
9494
* This function runs every time the provider (re)connects, and its result is cached and used in every evaluation.
9595
* By default, the entire sync response (as a JSON Object) is used.
9696
*/
97-
contextEnricher: (syncContext: { [key: string]: string } | null) => EvaluationContext;
97+
contextEnricher: (syncContext: EvaluationContext | null) => EvaluationContext;
9898
}
9999

100100
export type FlagdProviderOptions = Partial<FlagdConfig>;
@@ -106,7 +106,7 @@ const DEFAULT_CONFIG: Omit<FlagdConfig, 'port' | 'resolverType'> = {
106106
selector: '',
107107
cache: 'lru',
108108
maxCacheSize: DEFAULT_MAX_CACHE_SIZE,
109-
contextEnricher: (syncContext: { [key: string]: string } | null) => syncContext ?? {},
109+
contextEnricher: (syncContext: EvaluationContext | null) => syncContext ?? {},
110110
};
111111

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

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class FlagdProvider implements Provider {
1616
readonly hooks?: Hook[];
1717
readonly runsOn = 'server';
1818
readonly events = new OpenFeatureEventEmitter();
19-
private syncContext: { [key: string]: string } | null = null;
19+
private syncContext: EvaluationContext | null = null;
2020

2121
private readonly _service: Service;
2222

@@ -49,11 +49,11 @@ export class FlagdProvider implements Provider {
4949
}
5050
}
5151

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

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

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { ClientReadableStream, ServiceError, ClientOptions } from '@grpc/grpc-js';
22
import { credentials } from '@grpc/grpc-js';
3-
import type { Logger } from '@openfeature/server-sdk';
3+
import type { EvaluationContext, Logger } from '@openfeature/server-sdk';
44
import { GeneralError } from '@openfeature/server-sdk';
55
import type { SyncFlagsRequest, SyncFlagsResponse } from '../../../../proto/ts/flagd/sync/v1/sync';
66
import { FlagSyncServiceClient } from '../../../../proto/ts/flagd/sync/v1/sync';
@@ -15,7 +15,7 @@ export class GrpcFetch implements DataFetch {
1515
private readonly _syncClient: FlagSyncServiceClient;
1616
private readonly _request: SyncFlagsRequest;
1717
private _syncStream: ClientReadableStream<SyncFlagsResponse> | undefined;
18-
private readonly _setSyncContext: (syncContext: { [key: string]: string }) => void;
18+
private readonly _setSyncContext: (syncContext: EvaluationContext) => void;
1919
private _logger: Logger | undefined;
2020
/**
2121
* Initialized will be set to true once the initial connection is successful
@@ -32,7 +32,7 @@ export class GrpcFetch implements DataFetch {
3232

3333
constructor(
3434
config: Config,
35-
setSyncContext: (syncContext: { [key: string]: string }) => void,
35+
setSyncContext: (syncContext: EvaluationContext) => void,
3636
syncServiceClient?: FlagSyncServiceClient,
3737
logger?: Logger,
3838
) {
@@ -92,7 +92,7 @@ export class GrpcFetch implements DataFetch {
9292

9393
try {
9494
if (data.syncContext) {
95-
this._setSyncContext(data.syncContext as { [key: string]: string });
95+
this._setSyncContext(data.syncContext);
9696
}
9797
const changes = dataCallback(data.flagConfiguration);
9898
if (this._initialized && changes.length > 0) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class InProcessService implements Service {
1919

2020
constructor(
2121
private readonly config: Config,
22-
setSyncContext: (syncContext: { [key: string]: string }) => void,
22+
setSyncContext: (syncContext: EvaluationContext) => void,
2323
dataFetcher?: DataFetch,
2424
logger?: Logger,
2525
) {

0 commit comments

Comments
 (0)