/** * Shared verb: collapse a provider's targeting model into Quonfig's ordered, * first-match-wins rule list. * * Part of the `quonfig-target/` verb library (plan §3.1, D1). The hard part of * every converter is topology translation into Quonfig's specific shape — no * "flag off" toggle, no individual-target primitive, no within-rule OR. These * verbs do the LaunchDarkly collapse; a second provider with a different * topology composes them differently. */ import type { ConversionReport } from './report.js'; import { type QuonfigOperator } from './operators.js'; import { type QuonfigValue, type QuonfigValueType } from './values.js'; export interface QuonfigCriterion { operator: QuonfigOperator | 'ALWAYS_TRUE'; propertyName?: string; valueToMatch?: QuonfigValue; } export interface QuonfigWeightedValues { type: 'weighted_values'; value: { hashByPropertyName: string; weightedValues: Array<{ value: QuonfigValue; weight: number; }>; }; } export type QuonfigRuleValue = QuonfigValue | QuonfigWeightedValues; export interface QuonfigRule { criteria: QuonfigCriterion[]; value: QuonfigRuleValue; } interface SourceClause { attribute: string; contextKind?: string; negate?: boolean; op: string; values: unknown[]; } interface SourceRollout { bucketBy?: string; contextKind?: string; kind?: string; seed?: number; variations: Array<{ variation: number; weight: number; }>; } interface SourceRule { _id?: string; clauses: SourceClause[]; rollout?: SourceRollout; variation?: number; } interface SourceTarget { contextKind?: string; values: string[]; variation: number; } interface SourceVariationOrRollout { rollout?: SourceRollout; variation?: number; } interface SourceFlagEnvironment { contextTargets?: SourceTarget[]; fallthrough?: SourceVariationOrRollout; offVariation?: number; on: boolean; prerequisites?: Array<{ key: string; variation: number; }>; rules?: SourceRule[]; targets?: SourceTarget[]; } export interface RulesetContext { report: ConversionReport; /** Source flag/segment key — used for precise report entries. */ sourceKey: string; /** The flag's resolved Quonfig value type. */ valueType: QuonfigValueType; /** Raw variation values, indexed as the provider indexes them. */ variationValues: unknown[]; } /** * LaunchDarkly attribute → Quonfig property name. The context kind becomes a * namespace prefix (plan §5.1: `organization` + `plan` → `organization.plan`), * defaulting to `user`. A nested JSON-pointer attribute (`/address/city`) * becomes a dotted path (`address.city`). */ export declare function normalizeAttribute(contextKind: string | undefined, attribute: string): string; /** * Map one provider clause to a Quonfig criterion, or `null` when the clause's * operator has no v1 mapping (D3 — negated comparisons, applicationVersion…). * A null result means the whole containing rule must be dropped: keeping a * partial AND would silently broaden targeting. */ export declare function clauseToCriterion(clause: SourceClause, ctx: RulesetContext): QuonfigCriterion | null; /** * Build a Quonfig rule from a provider rule's clauses (AND semantics) plus its * served value. Returns `null` when any clause cannot be mapped — the rule is * dropped wholesale and reported, rather than silently broadened. */ export declare function buildRule(clauses: SourceClause[], value: QuonfigRuleValue, ctx: RulesetContext): QuonfigRule | null; /** * Convert a provider rollout to a Quonfig `weighted_values`. The experiment * framing (`kind: "experiment"` + `seed`) is dropped + reported (plan §5.4), * and every rollout is recorded as re-bucketing (LD and Quonfig hash * differently, so post-migration bucket assignments differ). */ export declare function rolloutToWeightedValues(rollout: SourceRollout, ctx: RulesetContext): QuonfigWeightedValues; /** Resolve a `variation`-or-`rollout` pointer (rule served value / fallthrough). */ export declare function servedValue(voR: SourceVariationOrRollout, ctx: RulesetContext): QuonfigRuleValue; /** * Collapse a single LaunchDarkly per-environment flag state into an ordered, * first-match-wins Quonfig rule list. * * - `on: false` → one ALWAYS_TRUE rule serving the `offVariation` value. * - `on: true` → individual/context targets become leading PROP_IS_ONE_OF * rules; `rules[]` translate in order; `fallthrough` becomes a trailing * ALWAYS_TRUE rule. Prerequisites are dropped + reported (no Quonfig * cross-flag dependency operator in v1). */ export declare function collapseEnvironment(env: SourceFlagEnvironment, ctx: RulesetContext): QuonfigRule[]; export {};