import type { LunaticData, LunaticOptions, LunaticSource } from '../../type'; import type { RefObject } from 'react'; import { IterationLevel } from './models'; export type EventArgs = { change: { /** Name of the changed variable. */ name: string; /** New value for the variable. */ value: unknown; /** Iteration changed (for array). */ iteration?: IterationLevel; /** What triggered this change. */ cause?: 'resizing' | 'cleaning'; /** Force a vector when an iteration is set and the value was a scalar **/ ignoreIterationOnScalar?: boolean; /** Extra sent when setting the variable. */ [extra: string]: unknown; }; }; export type LunaticVariablesStoreEvent = { detail: EventArgs[T]; }; /** * Represent a point in time (more precise than Date) */ declare class Timekey { private time; getTime(): number; touch(): void; } export declare function getChangedKey(variableName: string, iteration?: IterationLevel): string; export declare class LunaticVariablesStore { private readonly dictionary; private readonly eventTarget; private readonly queue; autoCommit: boolean; updatedAt: Timekey; constructor(); static makeFromSource(source: LunaticSource, data: LunaticData, options?: { changeHandler?: RefObject; disableCleaning?: boolean; autoCommit?: boolean; }): LunaticVariablesStore; /** * Create a new store from an object (useful for testing) */ static makeFromObject(values?: Record): LunaticVariablesStore; /** * Retrieve variable value */ get(name: string, iteration?: IterationLevel): T | null; /** * Transactional setter that will change data only when `commit()` is called */ enqueueSet(name: string, value: unknown, args?: Pick, forcedChangedKey?: string): void; unqueueSet(name: string, args?: Pick): void; /** * Commit all changes in the queue */ commit(): void; /** * Set variable value */ set(name: string, value: unknown, args?: Pick): LunaticVariable; /** * Register calculated variable */ setCalculated(name: string, expression: string, { dependencies, iterationDepth, shapeFrom, dimension, }?: { dependencies?: string[]; iterationDepth?: number; shapeFrom?: string | string[]; dimension?: number; }): LunaticVariable; /** * Register global variable */ setGlobal(name: string, { dependencies, globalDependencies, shapeFrom, }: { dependencies?: string[]; globalDependencies?: Map; shapeFrom?: string | string[]; }): LunaticVariable; /** * Run a VTL expression */ run(expression: string, args?: { iteration?: IterationLevel; deps?: string[]; }): unknown; /** * Bind event listeners */ on(eventName: T, cb: (e: CustomEvent) => void): void; /** * Detach a listener */ off(eventName: T, cb: (e: CustomEvent) => void): void; /** Retrieve the number of interpret() run (used in testing only). */ get interpretCount(): number; debug(): void; } export declare class LunaticVariable { /** Last time the value was updated (changed). */ updatedAt: Map; /** Last time the store was updated (changed). */ private readonly storeUpdatedAt; /** Last time "calculation" was run (for calculated variable). */ private readonly calculatedAt; /** Internal value for the variable. */ private value; /** List of direct dependencies, ex: ['FULLNAME', 'FIRSTNAME', 'LASTNAME']. */ private dependencies?; /** Expression for calculated variable. */ readonly expression?: string; /** Dictionary holding all the available variables. */ private readonly dictionary?; /** Specific iteration depth to get value from dependencies (used for yAxis for instance). */ private readonly iterationDepth?; /** For calculated variable, shape is copied from another variable. */ private readonly shapeFrom?; /** Whether this is a global variable with custom computation rules. */ private readonly isGlobal?; /** Name of variables needed for global variables computation rules. */ private readonly globalDependencies?; /** Keep a record of variable name (optional, used for debug). */ readonly name?: string; /** Count the number of calculation. */ calculatedCount: number; /** Dimension **/ dimension?: number; constructor(args: { expression?: string; dependencies?: string[]; dictionary?: Map; iterationDepth?: number; shapeFrom?: string | string[]; name?: string; dimension?: number; storeUpdatedAt: Timekey; isGlobal?: boolean; globalDependencies?: Map; }); getValue(iteration?: IterationLevel): unknown; /** * Set the value and returns true if the variable is touched */ setValue(value: unknown, opts: { iteration?: IterationLevel; ignoreIterationOnScalar?: boolean; }): boolean; private updateTimestamps; private setValueForArray; private getSavedValue; private getDependencies; private getDependenciesValues; /** * Check if the variable should be updated (comparing calculatedAt to dependency updated time) */ private isOutdated; getUpdatedAt(iteration?: IterationLevel): number; getCalculatedAt(iteration?: IterationLevel): number; } export {};