import type { SavedGroupsPayload, WidenPrimitives } from "./growthbook";
type OrCondition = {
$or: ConditionInterface[];
};
type NorCondition = {
$nor: ConditionInterface[];
};
type AndCondition = {
$and: ConditionInterface[];
};
type NotCondition = {
$not: ConditionInterface;
};
/** Names one saved group. Unknown keys are ignored. */
export type SavedGroupReference = {
id: string;
/** Optional. Checks this attribute instead of the entry's own. */
attributeKey?: AttributePath;
};
/**
* A reference to one saved group. Top level like `$and`, not scoped to an
* attribute. The plural authoring operator `$savedGroups` never reaches an
* SDK, so it has no type here.
*/
export type SavedGroupCondition = {
$savedGroup: SavedGroupReference;
};
export type Operator = "$in" | "$ini" | "$inGroup" | "$nin" | "$nini" | "$notInGroup" | "$gt" | "$gte" | "$lt" | "$lte" | "$regex" | "$regexi" | "$ne" | "$eq" | "$size" | "$elemMatch" | "$all" | "$alli" | "$not" | "$type" | "$exists" | "$vgt" | "$vgte" | "$vlt" | "$vlte" | "$vne" | "$veq";
export type VarType = "string" | "number" | "boolean" | "array" | "object" | "null" | "undefined";
export type ConditionTypeMismatch = {
path: string;
/** `$eq` for implicit equality */
operator: string;
/** Condition value */
expected: unknown;
/** Attribute value, `null` when missing */
actual: unknown;
};
export type TypeMismatchCallback = (mismatch: ConditionTypeMismatch) => void;
export type EvalConditionOptions = {
/** Required for saved group operators to match anyone */
savedGroups?: SavedGroupsPayload;
onTypeMismatch?: TypeMismatchCallback;
};
export type OperatorConditionValue = {
$in?: (string | number)[];
$ini?: (string | number)[];
$inGroup?: string;
$nin?: (string | number)[];
$nini?: (string | number)[];
$notInGroup?: string;
$gt?: number | string;
$gte?: number | string;
$lt?: number | string;
$lte?: number | string;
$regex?: string;
$regexi?: string;
$ne?: number | string;
$eq?: number | string;
$exists?: boolean;
$all?: ConditionValue[];
$alli?: ConditionValue[];
$size?: number | ConditionValue;
$type?: VarType;
$elemMatch?: ConditionInterface | OperatorConditionValue;
$not?: ConditionValue;
};
export type ConditionValue = OperatorConditionValue | string | number | boolean | Array | Record | null;
export type OperatorCondition = {
[key: string]: ConditionValue;
};
type UntypedCondition = OrCondition | NorCondition | AndCondition | NotCondition | SavedGroupCondition | OperatorCondition;
export type ConditionInterface = A extends unknown ? string extends keyof A ? UntypedCondition : {
$or?: ConditionInterface[];
$nor?: ConditionInterface[];
$and?: ConditionInterface[];
$not?: ConditionInterface;
$savedGroup?: SavedGroupReference;
} & {
[P in AttributePath]?: AttributeConditionValue>;
} : never;
type ObjectOf = V extends readonly unknown[] ? never : V extends object ? V : never;
type ElementOf = V extends readonly (infer E)[] ? E : never;
type Scalar = string | number | boolean;
type OperatorsFor = [T] extends [never] ? unknown : Operators;
/** Attribute names, and dot paths into object attributes (`company.plan`) */
export type AttributePath = A extends unknown ? string extends keyof A ? string : {
[K in keyof A & string]: K | (Depth["length"] extends 3 ? never : `${K}.${AttributePath, [...Depth, 0]>}`);
}[keyof A & string] : never;
type AttributeValue = A extends unknown ? P extends keyof A ? A[P] : P extends `${infer K}.${infer Rest}` ? K extends keyof A ? AttributeValue, Rest> : unknown : unknown : never;
/** What an attribute of type V can be compared to: a value to equal, or operators */
export type AttributeConditionValue = unknown extends V ? ConditionValue : V | null | AttributeOperators;
/** The operators that work on an attribute of type V */
export type AttributeOperators = {
$exists?: boolean;
$type?: VarType;
$not?: AttributeConditionValue;
$eq?: Extract | null;
$ne?: Extract | null;
} & OperatorsFor, Scalar>, {
$in?: (Extract, Scalar> | null)[];
$nin?: (Extract, Scalar> | null)[];
$inGroup?: string;
$notInGroup?: string;
}> & OperatorsFor, string>, {
$ini?: (Extract, string> | null)[];
$nini?: (Extract, string> | null)[];
}> & OperatorsFor, {
[K in "$gt" | "$gte" | "$lt" | "$lte" | "$veq" | "$vne" | "$vgt" | "$vgte" | "$vlt" | "$vlte"]?: WidenPrimitives>;
}> & OperatorsFor, {
$regex?: string;
$regexi?: string;
}> & OperatorsFor, {
$size?: AttributeConditionValue;
$elemMatch?: AttributeOperators> | ConditionInterface>>;
$all?: AttributeConditionValue>[];
$alli?: AttributeConditionValue>[];
}>;
export type ParentConditionInterface = {
id: string;
condition: ConditionInterface;
gate?: boolean;
};
export type TestedObj = Record;
export {};
//# sourceMappingURL=mongrule.d.ts.map