@sladg/apex-state 4.6.0 → 4.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -986,6 +986,10 @@ type ClearPathInput = {
986
986
  triggers: Array<string>;
987
987
  targets: Array<string>;
988
988
  };
989
+ type MathExprRegistration = {
990
+ target: string;
991
+ expr_json: string;
992
+ };
989
993
  type SideEffectsRegistration = {
990
994
  registration_id: string;
991
995
  sync_pairs: Array<[string, string]>;
@@ -995,6 +999,7 @@ type SideEffectsRegistration = {
995
999
  clear_paths: Array<ClearPathInput>;
996
1000
  computation_pairs: Array<unknown>;
997
1001
  listeners: Array<ListenerRegistration$1>;
1002
+ math_exprs: Array<MathExprRegistration>;
998
1003
  anchor_path: string | null;
999
1004
  };
1000
1005
  type ListenerRegistration$1 = {
@@ -1711,6 +1716,21 @@ interface SideEffects<DATA extends object, META extends GenericMeta = GenericMet
1711
1716
  * Accepts direct `ListenerRegistration<T>[]` or pre-validated result from `listeners()`.
1712
1717
  */
1713
1718
  listeners?: ListenerRegistration<DATA, META>[];
1719
+ /**
1720
+ * Math expressions - arbitrary numeric computations
1721
+ * Format: { target: path, expr: MathExpr JSON }
1722
+ * Evaluates reactively when source paths change.
1723
+ *
1724
+ * @example
1725
+ * ```typescript
1726
+ * math: [
1727
+ * { target: 'total', expr: { MUL: ['price', 'quantity'] } },
1728
+ * { target: 'discounted', expr: { SUB: [{ MUL: ['price', 'qty'] }, 'discount'] } },
1729
+ * { target: 'average', expr: { AVG: ['score1', 'score2', 'score3'] } },
1730
+ * ]
1731
+ * ```
1732
+ */
1733
+ math?: MathRegistration<DATA, Depth>[];
1714
1734
  /**
1715
1735
  * Anchor path - guard for all resources in this registration.
1716
1736
  * When the anchor path is structurally absent from shadow state, all listeners,
@@ -1719,6 +1739,59 @@ interface SideEffects<DATA extends object, META extends GenericMeta = GenericMet
1719
1739
  */
1720
1740
  anchorPath?: DeepKey<DATA, Depth>;
1721
1741
  }
1742
+ /**
1743
+ * Numeric computation DSL — type-safe expression tree.
1744
+ *
1745
+ * Leaf nodes:
1746
+ * - `number`: inline literal (`42`, `1.21`)
1747
+ * - `string`: path reference (constrained to numeric paths in DATA)
1748
+ *
1749
+ * Operators:
1750
+ * - Arithmetic: `{ ADD: [...] }`, `{ MUL: [...] }` (n-ary), `{ SUB: [a, b] }`, `{ DIV: [a, b] }`, `{ MOD: [a, b] }` (binary)
1751
+ * - Reductions: `{ SUM: [...] }`, `{ AVG: [...] }`, `{ MIN: [...] }`, `{ MAX: [...] }`, `{ COUNT: [...] }` (n-ary)
1752
+ * - Utilities: `{ ABS: expr }`, `{ NEGATE: expr }`, `{ ROUND: [expr, precision?] }`
1753
+ * - Explicit ref: `{ REF: path }` (equivalent to bare string)
1754
+ *
1755
+ * @example
1756
+ * ```typescript
1757
+ * type State = { price: number; quantity: number; discount: number; total: number }
1758
+ * const expr: MathExpr<State> = { SUB: [{ MUL: ['price', 'quantity'] }, 'discount'] }
1759
+ * ```
1760
+ */
1761
+ type MathExpr<DATA extends object, Depth extends number = DefaultDepth> = number | DeepKeyFiltered<DATA, number, Depth> | {
1762
+ REF: DeepKeyFiltered<DATA, number, Depth>;
1763
+ } | {
1764
+ ADD: MathExpr<DATA, Depth>[];
1765
+ } | {
1766
+ SUB: [MathExpr<DATA, Depth>, MathExpr<DATA, Depth>];
1767
+ } | {
1768
+ MUL: MathExpr<DATA, Depth>[];
1769
+ } | {
1770
+ DIV: [MathExpr<DATA, Depth>, MathExpr<DATA, Depth>];
1771
+ } | {
1772
+ MOD: [MathExpr<DATA, Depth>, MathExpr<DATA, Depth>];
1773
+ } | {
1774
+ ABS: MathExpr<DATA, Depth>;
1775
+ } | {
1776
+ NEGATE: MathExpr<DATA, Depth>;
1777
+ } | {
1778
+ ROUND: [MathExpr<DATA, Depth>, number?];
1779
+ } | {
1780
+ SUM: MathExpr<DATA, Depth>[];
1781
+ } | {
1782
+ AVG: MathExpr<DATA, Depth>[];
1783
+ } | {
1784
+ MIN: MathExpr<DATA, Depth>[];
1785
+ } | {
1786
+ MAX: MathExpr<DATA, Depth>[];
1787
+ } | {
1788
+ COUNT: MathExpr<DATA, Depth>[];
1789
+ };
1790
+ /** Math expression registration — type-safe target + expression tree. */
1791
+ interface MathRegistration<DATA extends object, Depth extends number = DefaultDepth> {
1792
+ target: DeepKeyFiltered<DATA, number, Depth>;
1793
+ expr: MathExpr<DATA, Depth>;
1794
+ }
1722
1795
 
1723
1796
  /**
1724
1797
  * Explicit return type of createGenericStore.