import type { PrerequisiteFlagComparator, SegmentComparator, UserComparator } from "./ConfigJson.js"; import { SettingType } from "./ConfigJson.js"; import * as ConfigJson from "./ConfigJson.js"; import type { ObjectMap } from "./Utils.js"; export { ConfigJson }; export declare class ProjectConfig { readonly configJson: string | undefined; readonly config: Config | undefined; readonly timestamp: number; readonly httpETag: string | undefined; static readonly serializationFormatVersion = "v2"; static readonly empty: ProjectConfig; static contentEquals(projectConfig1: ProjectConfig, projectConfig2: ProjectConfig): boolean; constructor(configJson: string | undefined, config: Config | undefined, timestamp: number, httpETag: string | undefined); with(timestamp: number): ProjectConfig; get isEmpty(): boolean; isExpired(expirationMs: number): boolean; static generateTimestamp(): number; static serialize(config: ProjectConfig): string; static deserialize(value: string): ProjectConfig; } export declare function getTimestampAsDate(projectConfig: ProjectConfig | null): Date | undefined; export type UnknownSettingType = -1; /** @remarks May or may not be a null-prototype object. */ export type SettingMap = Readonly | ObjectMap>; export type SettingValue = boolean | string | number | null | undefined; export type VariationIdValue = string | null | undefined; type AdjustedConfigJsonConfig = PartialWithNull; "s": AdjustedConfigJsonSegment[]; "f": { [key: string]: AdjustedConfigJsonSetting; }; }>>; /** Describes a ConfigCat config's data model used for feature flag evaluation. */ export declare abstract class Config implements Immutable { private readonly _guard; readonly p?: Immutable> | null; readonly s?: ReadonlyArray | null; readonly f?: Readonly> | null; } type AdjustedConfigJsonSegment = OptionalWithNull, "r">; /** Describes a segment. */ export declare abstract class Segment implements Immutable { readonly n: string; readonly r?: ReadonlyArray | null; } type FlattenedConfigJsonSettingValue = PartialWithNull>>; /** Contains a value of one of the possible types. */ export declare abstract class SettingValueModel implements Immutable { readonly b?: boolean | null; readonly s?: string | null; readonly i?: number | null; readonly d?: number | null; } type AdjustedConfigJsonServedValue = OptionalWithNull; }>, "i">; /** Contains a setting value along with related data. */ export declare abstract class SettingValueContainer = SettingValueModel> implements Immutable { readonly v: TValue; /** @remarks May be missing in the case of flag overrides. */ readonly i?: string | null; } type AdjustedConfigJsonSetting = OptionalWithNull; }>, "i" | "a" | "r" | "p">; /** Describes a feature flag or setting. */ export declare abstract class Setting extends SettingValueContainer> implements Immutable { /** @remarks Can also be `-1` when the setting comes from a simple flag override. */ readonly t: SettingType | UnknownSettingType; readonly a?: string | null; readonly r?: ReadonlyArray | null; readonly p?: ReadonlyArray | null; /** @remarks Can be a plain `boolean`, `string` or `number` value in the case of a a simple flag override. */ readonly v: SettingValueModel | NonNullable; private ["_configJsonSalt"]; private ["_configSegments"]; } type AdjustedConfigJsonTargetingRule = OptionalWithNull>, { "c": FlattenedConfigJsonCondition[]; "s": AdjustedConfigJsonServedValue; "p": AdjustedConfigJsonPercentageOption[]; }>, "c" | "s" | "p">; /** Describes a targeting rule. */ export declare abstract class TargetingRule implements Immutable { readonly c?: ReadonlyArray | null; readonly s?: SettingValueContainer | null; readonly p?: ReadonlyArray | null; } type AdjustedConfigJsonPercentageOption = OptionalWithNull, "i">; /** Describes a percentage option. */ export declare abstract class PercentageOption extends SettingValueContainer implements Immutable { readonly p: number; } type FlattenedConfigJsonCondition = PartialWithNull>, { "u": AdjustedConfigJsonUserCondition; "p": AdjustedConfigJsonPrerequisiteFlagCondition; }>>; /** Contains one of the possible conditions. */ export declare abstract class ConditionContainer implements Immutable { readonly u?: UserCondition | null; readonly p?: PrerequisiteFlagCondition | null; readonly s?: SegmentCondition | null; } export type Condition = UserCondition | PrerequisiteFlagCondition | SegmentCondition; type AdjustedConfigJsonUserCondition = OptionalWithNull>, "s" | "d" | "l">; /** Describes a condition that is based on a User Object attribute. */ export declare abstract class UserCondition implements Immutable { readonly a: string; readonly c: UserComparator; readonly s?: string | null; readonly d?: number | null; readonly l?: ReadonlyArray | null; } type AdjustedConfigJsonPrerequisiteFlagCondition = ChangePropType; /** Describes a condition that is based on a prerequisite flag. */ export declare abstract class PrerequisiteFlagCondition implements Immutable { readonly f: string; readonly c: PrerequisiteFlagComparator; readonly v: SettingValueModel; } /** Describes a condition that is based on a segment. */ export declare abstract class SegmentCondition implements Immutable { readonly s: number; readonly c: SegmentComparator; } /** * Deserializes the specified config JSON to a `Config` model that can be used for feature flag evaluation. * * @remarks Does superficial model validation only, meaning that the method makes sure that the specified config JSON * matches the type definition of the `Config` model, but doesn't check for semantic issues. E.g. doesn't validate * whether referenced segments and feature flags actually exist. (Such issues are checked during feature flag evaluation.) */ export declare function deserializeConfig(configJson: string): Config; /** * Prepares the specified preparsed config JSON so it can be used for feature flag evaluation. Makes direct * modifications to the specified object and returns the same reference cast as type `Config`. * * @remarks Does superficial model validation only, meaning that the method makes sure that the specified config JSON * matches the type definition of the `Config` model, but doesn't check for semantic issues. E.g. doesn't validate * whether referenced segments and feature flags actually exist. (Such issues are checked during feature flag evaluation.) */ export declare function prepareConfig(config: Partial): Config; /** * Creates a setting that can be used for feature flag evaluation from the specified value. */ export declare function createSettingFromValue(value: NonNullable): Setting; export declare function nameOfSettingType(value: SettingType): string; export declare function getSettingType(setting: Setting): SettingType | UnknownSettingType; export declare function inferSettingType(value: unknown): SettingType | undefined; export declare function isCompatibleValue(value: SettingValue, settingType: SettingType): boolean; export declare function isAllowedValue(value: unknown): value is NonNullable; export declare function hasPercentageOptions(targetingRule: TargetingRule): boolean; export declare function hasPercentageOptions(targetingRule: TargetingRule, ignoreIfInvalid: true): boolean | undefined; export declare function getConditionType(container: ConditionContainer): keyof ConditionContainer; export declare function unwrapValue(settingValue: SettingValueModel | NonNullable, settingType: SettingType | UnknownSettingType | null, ignoreIfInvalid?: false): NonNullable; export declare function unwrapValue(settingValue: SettingValueModel | NonNullable, settingType: SettingType | UnknownSettingType | null, ignoreIfInvalid: true): NonNullable | undefined; export declare function throwInvalidConfigModelError(message: string): never; export declare class InvalidConfigModelError extends Error { readonly message: string; readonly name: string; constructor(message: string); } /** Recursively makes object `T` immutable by making arrays and object properties read-only. */ type Immutable = { readonly [K in keyof T]: NonNullable extends ReadonlyArray ? ReadonlyArray> | (T[K] & (null | undefined)) : NonNullable extends object ? Immutable : T[K]; }; /** Makes all properties optional in object `T` while also allowing `null`. */ type PartialWithNull = { [P in keyof T]?: T[P] | null; }; /** Makes properties specified by `K` optional in object `T` while also allowing `null`. */ type OptionalWithNull = Pick, K> & Omit; /** Changes the type of properties specified by `TPropMap` in object `T`. */ type ChangePropType = { [K in keyof T]: K extends keyof TPropMap ? TPropMap[K] : T[K]; }; /** Removes properties of type `never` from object `T`. */ type OmitNeverProps = Pick; /** Converts union type `U` to an intersection type. */ type UnionToIntersection = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;