npaw-plugin-nwf
Version:
NPAW's Plugin
50 lines (49 loc) • 2.19 kB
TypeScript
import BalancerOptions from './Options';
/**
* @class
* @description Processes custom options from backend /decision API response and applies them to BalancerOptions.
* Handles null vs undefined values according to business requirements:
* - null: explicitly set the option to null/default value
* - undefined: leave the existing option unchanged
* @exports CustomOptionsProcessor
*/
export default class CustomOptionsProcessor {
/**
* Apply custom options from backend to balancer options.
* @param {BalancerOptions} balancerOptions The balancer options to update
* @param {object} customDataOptions The options object from customData.options in API response
*/
/**
* Registry of dotted (nested) customData keys mirroring the Android
* `CustomOptionsProcessor`. Each entry declares the expected scalar type so
* an invalid value falls back through the same null/empty/invalid semantics
* as the flat options below. New nested groups (latencyTrialTrigger.*,
* peakSampler.*, firstChunkProbe.*) extend this map in subsequent PRs.
*/
private static NESTED_OPTION_KEYS;
static applyCustomOptionsToBalancerOptions(balancerOptions: BalancerOptions, customDataOptions?: {
[key: string]: any;
}): void;
/**
* Routes a dotted customData key (e.g. `cdnTimeout.connectTimeoutMilliseconds`)
* to the matching nested sub-object on BalancerOptions. Walks the path,
* creating intermediate objects as needed, then applies the same null /
* empty / invalid-type semantics as the flat helpers.
*/
private static processNestedKey;
private static setNestedBoolean;
private static setNestedNumber;
private static setNestedString;
private static processBoolean;
private static processString;
private static processNumber;
private static processStringArray;
private static processObject;
/**
* Process lists with special __add__ feature from Android implementation
* @param customDataList List from backend
* @param existingList Current list in options
* @returns Processed list
*/
private static processListWithAddFeature;
}