@sladg/apex-state 3.9.1 → 3.11.2

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
@@ -1,5 +1,4 @@
1
1
  import { ReactNode } from 'react';
2
- import * as react_jsx_runtime from 'react/jsx-runtime';
3
2
 
4
3
  /**
5
4
  * Hash key type for Record-based paths
@@ -906,6 +905,30 @@ interface ConcernRegistration {
906
905
  dispose: () => void;
907
906
  }
908
907
 
908
+ /**
909
+ * Pipeline Observer — Unified debug logging + Redux DevTools integration.
910
+ *
911
+ * Single interface that dispatches to:
912
+ * - Console logging (controlled by logPipeline / logListeners / logConcerns flags)
913
+ * - Redux DevTools (controlled by devtools flag) with nested tree-shaped state
914
+ *
915
+ * Call sites use one `observer.xyz()` call; the observer fans out internally.
916
+ * Zero runtime cost when all flags are false (returns no-op object).
917
+ */
918
+
919
+ interface PipelineObserver {
920
+ pipelineStart: (label: string, input: unknown[]) => void;
921
+ phase1: (stateChanges: unknown[]) => void;
922
+ syncExpand: (changes: unknown[]) => void;
923
+ flipExpand: (changes: unknown[]) => void;
924
+ listenerDispatch: (subscriberId: number, fnName: string, scope: string, input: unknown[], output: unknown) => void;
925
+ validatorResult: (outputPath: string, input: unknown, result: unknown) => void;
926
+ phase2: (stateChanges: unknown[]) => void;
927
+ pipelineEnd: () => void;
928
+ concernEval: (path: string, name: string, value: unknown, result: unknown) => void;
929
+ destroy: () => void;
930
+ }
931
+
909
932
  /**
910
933
  * Debug Timing Utilities
911
934
  *
@@ -947,6 +970,7 @@ interface DispatchEntry {
947
970
  dispatch_id: number;
948
971
  subscriber_id: number;
949
972
  scope_path: string;
973
+ topic_path: string;
950
974
  /** Indexes into ProcessResult.changes array. */
951
975
  input_change_ids: number[];
952
976
  }
@@ -1158,6 +1182,14 @@ interface DebugConfig {
1158
1182
  timingThreshold?: number;
1159
1183
  /** Enable tracking of processChanges calls and applied changes for testing/debugging */
1160
1184
  track?: boolean;
1185
+ /** Log pipeline phases, state changes, sync/flip expansions */
1186
+ logPipeline?: boolean;
1187
+ /** Log listener dispatch inputs and outputs */
1188
+ logListeners?: boolean;
1189
+ /** Log concern evaluations and validator runs */
1190
+ logConcerns?: boolean;
1191
+ /** Connect to Redux DevTools Extension for state inspection */
1192
+ devtools?: boolean;
1161
1193
  }
1162
1194
  /**
1163
1195
  * A single recorded processChanges invocation
@@ -1295,6 +1327,7 @@ interface InternalState<DATA extends object = object, META extends GenericMeta =
1295
1327
  registrations: Registrations;
1296
1328
  processing: ProcessingState<DATA, META>;
1297
1329
  timing: Timing;
1330
+ observer: PipelineObserver;
1298
1331
  config: DeepRequired<StoreConfig>;
1299
1332
  /** Per-store WASM pipeline instance (null when using legacy implementation). */
1300
1333
  pipeline: WasmPipeline | null;
@@ -1636,20 +1669,17 @@ interface SideEffects<DATA extends object, META extends GenericMeta = GenericMet
1636
1669
  listeners?: ListenerRegistration<DATA, META>[];
1637
1670
  }
1638
1671
 
1639
- declare const createGenericStore: <DATA extends object, META extends GenericMeta = GenericMeta, CONCERNS extends readonly ConcernType<string, any, any>[] = typeof defaultConcerns>(config?: StoreConfig) => {
1640
- syncPairs: <T extends [Exclude<DeepKey<DATA, 20>, `${string}??`>, Exclude<DeepKey<DATA, 20>, `${string}??`>][]>(pairs: CheckSyncPairs<DATA, T, 20>) => ValidatedSyncPairs<DATA>;
1641
- flipPairs: <T extends [Exclude<DeepKey<DATA, 20>, `${string}??`>, Exclude<DeepKey<DATA, 20>, `${string}??`>][]>(pairs: CheckSyncPairs<DATA, T, 20>) => ValidatedFlipPairs<DATA>;
1642
- aggregationPairs: <T extends ([Exclude<DeepKey<DATA, 20>, `${string}??`>, Exclude<DeepKey<DATA, 20>, `${string}??`>] | [Exclude<DeepKey<DATA, 20>, `${string}??`>, Exclude<DeepKey<DATA, 20>, `${string}??`>, BoolLogic<DATA, 20>])[]>(pairs: CheckAggregationPairs<DATA, T, 20>) => ValidatedAggregationPairs<DATA>;
1643
- computationPairs: <T extends ([ComputationOp, DeepKeyFiltered<DATA, number, 20>, DeepKeyFiltered<DATA, number, 20>] | [ComputationOp, DeepKeyFiltered<DATA, number, 20>, DeepKeyFiltered<DATA, number, 20>, BoolLogic<DATA, 20>])[]>(pairs: CheckComputationPairs<DATA, T, 20>) => ValidatedComputationPairs<DATA>;
1644
- listeners: <T extends readonly {
1645
- path: Exclude<DeepKey<DATA, 20>, `${string}??`> | null;
1646
- scope?: Exclude<DeepKey<DATA, 20>, `${string}??`> | null | undefined;
1647
- fn: (...args: any[]) => any;
1648
- }[]>(items: CheckListeners<DATA, META, T, 20>) => ValidatedListeners<DATA, META>;
1649
- Provider: {
1650
- (props: ProviderProps<DATA>): react_jsx_runtime.JSX.Element;
1651
- displayName: string;
1652
- };
1672
+ /**
1673
+ * Explicit return type of createGenericStore.
1674
+ *
1675
+ * Defined as an interface so TypeScript references type aliases by name
1676
+ * (e.g. `SideEffects<DATA, META>`) instead of expanding them inline.
1677
+ * Without this, large DATA types (2800+ DeepKey paths) cause
1678
+ * "inferred type exceeds the maximum length" (TS error) because the
1679
+ * compiler tries to inline-expand every O(N²) pair type.
1680
+ */
1681
+ interface GenericStoreApi<DATA extends object, META extends GenericMeta = GenericMeta, CONCERNS extends readonly ConcernType<string, any, any>[] = typeof defaultConcerns> {
1682
+ Provider: (props: ProviderProps<DATA>) => React.JSX.Element;
1653
1683
  useFieldStore: <P extends DeepKey<DATA>>(path: P) => {
1654
1684
  value: DeepValue<DATA, P>;
1655
1685
  setValue: (newValue: DeepValue<DATA, P>, meta?: META) => void;
@@ -1664,11 +1694,13 @@ declare const createGenericStore: <DATA extends object, META extends GenericMeta
1664
1694
  useConcerns: <CUSTOM extends readonly ConcernType<string, any, any>[] = readonly []>(id: string, registration: ConcernRegistrationMap<DATA, readonly [...CONCERNS, ...CUSTOM]>, customConcerns?: CUSTOM) => void;
1665
1695
  withConcerns: <SELECTION extends Partial<Record<Extract<CONCERNS[number], {
1666
1696
  name: string;
1667
- }>["name"], boolean>>>(selection: SELECTION) => {
1697
+ }>['name'], boolean>>>(selection: SELECTION) => {
1668
1698
  useFieldStore: <P extends DeepKey<DATA>>(path: P) => {
1669
- value: DATA extends readonly any[] ? DATA[number] : P extends `${infer First}.${infer Rest}` ? First extends keyof DATA ? DeepValue<NonNullable<DATA[First]>, Rest> : string extends keyof DATA ? First extends "[*]" ? DeepValue<DATA[keyof DATA & string], Rest> : unknown : unknown : P extends "[*]" ? string extends keyof DATA ? DATA[keyof DATA & string] : unknown : P extends keyof DATA ? DATA[P] : unknown;
1670
- setValue: (newValue: DATA extends readonly any[] ? DATA[number] : P extends `${infer First}.${infer Rest}` ? First extends keyof DATA ? DeepValue<NonNullable<DATA[First]>, Rest> : string extends keyof DATA ? First extends "[*]" ? DeepValue<DATA[keyof DATA & string], Rest> : unknown : unknown : P extends "[*]" ? string extends keyof DATA ? DATA[keyof DATA & string] : unknown : P extends keyof DATA ? DATA[P] : unknown, meta?: META) => void;
1671
- } & { [K in keyof SELECTION as SELECTION[K] extends true ? K : never]?: K extends keyof EvaluatedConcerns<CONCERNS> ? EvaluatedConcerns<CONCERNS>[K] : never; };
1699
+ value: DeepValue<DATA, P>;
1700
+ setValue: (newValue: DeepValue<DATA, P>, meta?: META) => void;
1701
+ } & {
1702
+ [K in keyof SELECTION as SELECTION[K] extends true ? K : never]?: K extends keyof EvaluatedConcerns<CONCERNS> ? EvaluatedConcerns<CONCERNS>[K] : never;
1703
+ };
1672
1704
  };
1673
1705
  withMeta: (presetMeta: Partial<META>) => {
1674
1706
  useFieldStore: <P extends DeepKey<DATA>>(path: P) => {
@@ -1676,9 +1708,26 @@ declare const createGenericStore: <DATA extends object, META extends GenericMeta
1676
1708
  setValue: (newValue: DeepValue<DATA, P>, meta?: META) => void;
1677
1709
  };
1678
1710
  };
1679
- };
1680
- /** Return type of createGenericStore used by testing mock for 1:1 type safety */
1681
- type GenericStoreApi<DATA extends object, META extends GenericMeta = GenericMeta, CONCERNS extends readonly ConcernType<string, any, any>[] = typeof defaultConcerns> = ReturnType<typeof createGenericStore<DATA, META, CONCERNS>>;
1711
+ syncPairs: <T extends [ResolvableDeepKey<DATA>, ResolvableDeepKey<DATA>][]>(pairs: CheckSyncPairs<DATA, T>) => ValidatedSyncPairs<DATA>;
1712
+ flipPairs: <T extends [ResolvableDeepKey<DATA>, ResolvableDeepKey<DATA>][]>(pairs: CheckSyncPairs<DATA, T>) => ValidatedFlipPairs<DATA>;
1713
+ aggregationPairs: <T extends ([ResolvableDeepKey<DATA>, ResolvableDeepKey<DATA>] | [ResolvableDeepKey<DATA>, ResolvableDeepKey<DATA>, BoolLogic<DATA>])[]>(pairs: CheckAggregationPairs<DATA, T>) => ValidatedAggregationPairs<DATA>;
1714
+ computationPairs: <T extends ([
1715
+ ComputationOp,
1716
+ DeepKeyFiltered<DATA, number>,
1717
+ DeepKeyFiltered<DATA, number>
1718
+ ] | [
1719
+ ComputationOp,
1720
+ DeepKeyFiltered<DATA, number>,
1721
+ DeepKeyFiltered<DATA, number>,
1722
+ BoolLogic<DATA>
1723
+ ])[]>(pairs: CheckComputationPairs<DATA, T>) => ValidatedComputationPairs<DATA>;
1724
+ listeners: <T extends readonly {
1725
+ path: ResolvableDeepKey<DATA> | null;
1726
+ scope?: ResolvableDeepKey<DATA> | null | undefined;
1727
+ fn: (...args: any[]) => any;
1728
+ }[]>(items: CheckListeners<DATA, META, T>) => ValidatedListeners<DATA, META>;
1729
+ }
1730
+ declare const createGenericStore: <DATA extends object, META extends GenericMeta = GenericMeta, CONCERNS extends readonly ConcernType<string, any, any>[] = typeof defaultConcerns>(config?: StoreConfig) => GenericStoreApi<DATA, META, CONCERNS>;
1682
1731
 
1683
1732
  /**
1684
1733
  * Minimal field interface that useBufferedField accepts
@@ -2214,28 +2263,30 @@ declare const is: {
2214
2263
  * Applies an array of changes to an object, returning a new object.
2215
2264
  */
2216
2265
 
2266
+ /** A change tuple: [path, value] or [path, value, anyMeta]. Meta is ignored. */
2267
+ type AnyChange<DATA> = {
2268
+ [K in DeepKey<DATA>]: [K, DeepValue<DATA, K>] | [K, DeepValue<DATA, K>, ...unknown[]];
2269
+ }[DeepKey<DATA>];
2217
2270
  /**
2218
2271
  * Applies changes to an object, returning a new object with changes applied.
2219
- * Does not mutate the original object.
2272
+ * Does not mutate the original object. Meta fields on change tuples are ignored.
2220
2273
  *
2221
2274
  * @param obj - Source object
2222
- * @param changes - Array of [path, value, meta] tuples
2275
+ * @param changes - Array of [path, value] or [path, value, meta] tuples
2223
2276
  * @returns New object with changes applied
2224
2277
  *
2225
2278
  * @example
2226
2279
  * ```typescript
2227
2280
  * const state = { user: { name: 'Alice', age: 30 } }
2228
- * const changes: ArrayOfChanges<typeof state> = [
2229
- * ['user.name', 'Bob', {}],
2230
- * ['user.age', 31, {}],
2231
- * ]
2232
- *
2233
- * const newState = applyChangesToObject(state, changes)
2281
+ * const newState = applyChangesToObject(state, [
2282
+ * ['user.name', 'Bob'],
2283
+ * ['user.age', 31],
2284
+ * ])
2234
2285
  * // newState: { user: { name: 'Bob', age: 31 } }
2235
2286
  * // state is unchanged
2236
2287
  * ```
2237
2288
  */
2238
- declare const applyChangesToObject: <T extends object>(obj: T, changes: ArrayOfChanges<T>) => T;
2289
+ declare const applyChangesToObject: <T extends object>(obj: T, changes: AnyChange<T>[]) => T;
2239
2290
 
2240
2291
  /**
2241
2292
  * Deep clone utility — single swap point for the cloning implementation.
@@ -2255,4 +2306,4 @@ declare const applyChangesToObject: <T extends object>(obj: T, changes: ArrayOfC
2255
2306
  */
2256
2307
  declare const deepClone: <T>(value: T) => T;
2257
2308
 
2258
- export { type Aggregation, type AggregationPair, type ArrayOfChanges, type BaseConcernProps, type BoolLogic, type BufferedField, type CheckAggregationPairs, type CheckComputationPairs, type CheckPairValueMatch, type CheckSyncPairs, type ClearPathRule, type ComputationOp, type ComputationPair, type ConcernRegistration, type ConcernRegistrationMap, type ConcernType, type DebugConfig, type DebugTrack, type DebugTrackEntry, type DeepKey, type DeepKeyFiltered, type DeepPartial, type DeepRequired, type DeepValue, type EvaluatedConcerns, type ExtractEvaluateReturn, type FieldInput$2 as FieldInput, type FlipPair, type GenericMeta, type GenericStoreApi, type HASH_KEY, type KeyboardSelectConfig, type ListenerRegistration, type OnStateListener, type PathsWithSameValueAs, type ProviderProps, type SelectOption, type SideEffects, type StoreConfig, type StoreInstance, type SyncPair, type ThrottleConfig, type ThrottleFieldInput, type TransformConfig, type ValidationError, type ValidationSchema, type ValidationStateConcern, type ValidationStateInput, type ValidationStateResult, _, aggregationPairs, applyChangesToObject, computationPairs, createGenericStore, deepClone, defaultConcerns, dot, evaluateBoolLogic, extractPlaceholders, findConcern, flipPairs, hashKey, interpolateTemplate, is, listeners, index as prebuilts, registerFlipPair, registerListenerLegacy, registerSideEffects, registerSyncPairsBatch, syncPairs, useBufferedField, useKeyboardSelect, useThrottledField, useTransformedField };
2309
+ export { type Aggregation, type AggregationPair, type ArrayOfChanges, type BaseConcernProps, type BoolLogic, type BufferedField, type CheckAggregationPairs, type CheckComputationPairs, type CheckPairValueMatch, type CheckSyncPairs, type ClearPathRule, type ComputationOp, type ComputationPair, type ConcernRegistration, type ConcernRegistrationMap, type ConcernType, type DebugConfig, type DebugTrack, type DebugTrackEntry, type DeepKey, type DeepKeyFiltered, type DeepPartial, type DeepRequired, type DeepValue, type EvaluatedConcerns, type ExtractEvaluateReturn, type FieldInput$2 as FieldInput, type FlipPair, type GenericMeta, type GenericStoreApi, type HASH_KEY, type KeyboardSelectConfig, type ListenerRegistration, type OnStateListener, type PathsWithSameValueAs, type PipelineObserver, type ProviderProps, STORE_DATA, type SelectOption, type SideEffects, type StoreConfig, type StoreInstance, type SyncPair, type ThrottleConfig, type ThrottleFieldInput, type TransformConfig, VALIDATED, type ValidatedAggregationPairs, type ValidatedComputationPairs, type ValidatedFlipPairs, type ValidatedListeners, type ValidatedSyncPairs, type ValidationError, type ValidationSchema, type ValidationStateConcern, type ValidationStateInput, type ValidationStateResult, _, aggregationPairs, applyChangesToObject, computationPairs, createGenericStore, deepClone, defaultConcerns, dot, evaluateBoolLogic, extractPlaceholders, findConcern, flipPairs, hashKey, interpolateTemplate, is, listeners, index as prebuilts, registerFlipPair, registerListenerLegacy, registerSideEffects, registerSyncPairsBatch, syncPairs, useBufferedField, useKeyboardSelect, useThrottledField, useTransformedField };