Skip to content

Commit 9c48b21

Browse files
committed
Move createFlagOverridesFromMap to common-js to reduce redundancy
1 parent fe881bb commit 9c48b21

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

src/index.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import type { IAutoPollOptions, ILazyLoadingOptions, IManualPollOptions, Options
44
import { PollingMode } from "./ConfigCatClientOptions";
55
import type { IConfigCatLogger } from "./ConfigCatLogger";
66
import { ConfigCatConsoleLogger, LogLevel } from "./ConfigCatLogger";
7+
import { FlagOverrides, MapOverrideDataSource, OverrideBehaviour } from "./FlagOverrides";
78
import { setupPolyfills } from "./Polyfills";
9+
import type { SettingValue } from "./ProjectConfig";
810

911
setupPolyfills();
1012

@@ -37,6 +39,19 @@ export function createConsoleLogger(logLevel: LogLevel): IConfigCatLogger {
3739
return new ConfigCatConsoleLogger(logLevel);
3840
}
3941

42+
/**
43+
* Creates an instance of `FlagOverrides` that uses a map data source.
44+
* @param map The map that contains the overrides.
45+
* @param behaviour The override behaviour.
46+
* Specifies whether the local values should override the remote values
47+
* or local values should only be used when a remote value doesn't exist
48+
* or the local values should be used only.
49+
* @param watchChanges If set to `true`, the input map will be tracked for changes.
50+
*/
51+
export function createFlagOverridesFromMap(map: { [name: string]: NonNullable<SettingValue> }, behaviour: OverrideBehaviour, watchChanges?: boolean): FlagOverrides {
52+
return new FlagOverrides(new MapOverrideDataSource(map, watchChanges), behaviour);
53+
}
54+
4055
/* Public types for platform-specific SDKs */
4156

4257
// List types here which are required to implement the platform-specific SDKs but shouldn't be exposed to end users.
@@ -51,14 +66,10 @@ export type { OptionsBase } from "./ConfigCatClientOptions";
5166

5267
export type { IConfigCache } from "./ConfigCatCache";
5368

54-
export { ExternalConfigCache } from "./ConfigCatCache";
69+
export { InMemoryConfigCache, ExternalConfigCache } from "./ConfigCatCache";
5570

5671
export type { IEventProvider, IEventEmitter } from "./EventEmitter";
5772

58-
export type { IOverrideDataSource } from "./FlagOverrides";
59-
60-
export { FlagOverrides, MapOverrideDataSource } from "./FlagOverrides";
61-
6273
/* Public types for end users */
6374

6475
// List types here which are part of the public API of platform-specific SDKs, thus, should be exposed to end users.
@@ -101,7 +112,9 @@ export type { UserAttributeValue } from "./User";
101112

102113
export { User } from "./User";
103114

104-
export { OverrideBehaviour } from "./FlagOverrides";
115+
export type { FlagOverrides };
116+
117+
export { OverrideBehaviour };
105118

106119
export { ClientCacheState, RefreshResult } from "./ConfigServiceBase";
107120

test/ConfigV2EvaluationTests.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { assert } from "chai";
22
import "mocha";
3-
import { FlagOverrides, IManualPollOptions, MapOverrideDataSource, OverrideBehaviour, SettingValue, User, UserAttributeValue } from "../src";
3+
import { IManualPollOptions, OverrideBehaviour, SettingValue, User, UserAttributeValue } from "../src";
44
import { LogLevel, LoggerWrapper } from "../src/ConfigCatLogger";
5+
import { FlagOverrides, MapOverrideDataSource } from "../src/FlagOverrides";
56
import { RolloutEvaluator, evaluate, isAllowedValue } from "../src/RolloutEvaluator";
67
import { errorToString } from "../src/Utils";
78
import { CdnConfigLocation, LocalFileConfigLocation } from "./helpers/ConfigLocation";

0 commit comments

Comments
 (0)