Skip to content

Commit

Permalink
Move createFlagOverridesFromMap to common-js to reduce redundancy
Browse files Browse the repository at this point in the history
  • Loading branch information
adams85 committed Jan 15, 2024
1 parent fe881bb commit 9c48b21
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
25 changes: 19 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import type { IAutoPollOptions, ILazyLoadingOptions, IManualPollOptions, Options
import { PollingMode } from "./ConfigCatClientOptions";
import type { IConfigCatLogger } from "./ConfigCatLogger";
import { ConfigCatConsoleLogger, LogLevel } from "./ConfigCatLogger";
import { FlagOverrides, MapOverrideDataSource, OverrideBehaviour } from "./FlagOverrides";
import { setupPolyfills } from "./Polyfills";
import type { SettingValue } from "./ProjectConfig";

setupPolyfills();

Expand Down Expand Up @@ -37,6 +39,19 @@ export function createConsoleLogger(logLevel: LogLevel): IConfigCatLogger {
return new ConfigCatConsoleLogger(logLevel);
}

/**
* Creates an instance of `FlagOverrides` that uses a map data source.
* @param map The map that contains the overrides.
* @param behaviour The override behaviour.
* Specifies whether the local values should override the remote values
* or local values should only be used when a remote value doesn't exist
* or the local values should be used only.
* @param watchChanges If set to `true`, the input map will be tracked for changes.
*/
export function createFlagOverridesFromMap(map: { [name: string]: NonNullable<SettingValue> }, behaviour: OverrideBehaviour, watchChanges?: boolean): FlagOverrides {
return new FlagOverrides(new MapOverrideDataSource(map, watchChanges), behaviour);

Check warning on line 52 in src/index.ts

View check run for this annotation

Codecov / codecov/patch

src/index.ts#L52

Added line #L52 was not covered by tests
}

/* Public types for platform-specific SDKs */

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

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

export { ExternalConfigCache } from "./ConfigCatCache";
export { InMemoryConfigCache, ExternalConfigCache } from "./ConfigCatCache";

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

export type { IOverrideDataSource } from "./FlagOverrides";

export { FlagOverrides, MapOverrideDataSource } from "./FlagOverrides";

/* Public types for end users */

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

export { User } from "./User";

export { OverrideBehaviour } from "./FlagOverrides";
export type { FlagOverrides };

export { OverrideBehaviour };

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

Expand Down
3 changes: 2 additions & 1 deletion test/ConfigV2EvaluationTests.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { assert } from "chai";
import "mocha";
import { FlagOverrides, IManualPollOptions, MapOverrideDataSource, OverrideBehaviour, SettingValue, User, UserAttributeValue } from "../src";
import { IManualPollOptions, OverrideBehaviour, SettingValue, User, UserAttributeValue } from "../src";
import { LogLevel, LoggerWrapper } from "../src/ConfigCatLogger";
import { FlagOverrides, MapOverrideDataSource } from "../src/FlagOverrides";
import { RolloutEvaluator, evaluate, isAllowedValue } from "../src/RolloutEvaluator";
import { errorToString } from "../src/Utils";
import { CdnConfigLocation, LocalFileConfigLocation } from "./helpers/ConfigLocation";
Expand Down

0 comments on commit 9c48b21

Please sign in to comment.