@mmstack/primitives 22.0.1 → 22.0.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mmstack/primitives",
3
- "version": "22.0.1",
3
+ "version": "22.0.3",
4
4
  "keywords": [
5
5
  "angular",
6
6
  "signals",
@@ -2002,6 +2002,58 @@ declare function signalFromEvent<TEvent extends Event, U>(target: ResolvableTarg
2002
2002
  * by {@link opaque} and the type-level brand carried by {@link Opaque}.
2003
2003
  */
2004
2004
  declare const OPAQUE: unique symbol;
2005
+ /**
2006
+ * Marks a plain object as opaque so {@link store} treats it as an indivisible leaf
2007
+ * (returned whole, never deep-proxied) — the same way it treats a `Date` or `RegExp`.
2008
+ * The marker is a non-enumerable symbol, so it never appears in spreads or iteration.
2009
+ * Idempotent. Call before freezing (`defineProperty` fails on a frozen object).
2010
+ *
2011
+ * @example
2012
+ * const s = store({ config: opaque({ theme: 'dark', nested: { a: 1 } }) });
2013
+ * s.config(); // the whole object, not a child store
2014
+ * s.config.set(opaque({ theme: 'light', nested: { a: 2 } }));
2015
+ */
2016
+ declare function opaque<T extends object>(value: T): Opaque<T>;
2017
+ /**
2018
+ * Type guard companion to {@link opaque}: returns `true` when `value` carries the
2019
+ * {@link OPAQUE} brand, narrowing it to {@link Opaque}. This is the same check the
2020
+ * store uses to route opaque values to its leaf branch (alongside `Date`/`RegExp`).
2021
+ *
2022
+ * @internal Exposed for advanced/niche interop only — not part of the supported public
2023
+ * surface and may change without a major version bump. Reach for {@link opaque} for
2024
+ * normal usage.
2025
+ *
2026
+ * @example
2027
+ * if (isOpaque(value)) {
2028
+ * // value: Opaque<object> — `store` would treat it as an indivisible leaf
2029
+ * }
2030
+ */
2031
+ declare function isOpaque<T = object>(value: unknown): value is Opaque<T>;
2032
+ /**
2033
+ * @internal Runtime brand carrying a store node's lazily-built leaf probe. Exported (like
2034
+ * {@link OPAQUE}) only so the `{ readonly [LEAF]: () => boolean }` brand on the store types is
2035
+ * nameable in the emitted declarations — not part of the supported surface; use {@link isLeaf}.
2036
+ */
2037
+ declare const LEAF: unique symbol;
2038
+ /**
2039
+ * Reports whether a store node is currently a **leaf** — a terminal value the store does not
2040
+ * descend into (a primitive, `Date`, `RegExp`, {@link opaque} object, class instance, or a
2041
+ * `null`/`undefined` hole when vivification is off) rather than a record/array substore.
2042
+ *
2043
+ * Leaf-ness reflects the node's **live** value: the probe is reactive and memoized, so calling
2044
+ * `isLeaf` inside a `computed`/`effect` re-evaluates when the node's shape changes.
2045
+ *
2046
+ * @internal Exposed for advanced/niche interop only — not part of the supported public surface
2047
+ * and may change without a major version bump.
2048
+ *
2049
+ * @example
2050
+ * const s = store({ name: 'Ada', address: { city: 'London' } });
2051
+ * isLeaf(s.name); // true
2052
+ * isLeaf(s.address); // false — a substore
2053
+ */
2054
+ declare function isLeaf<T = unknown>(value: unknown): value is Signal<T> & {
2055
+ readonly [LEAF]: () => boolean;
2056
+ };
2005
2057
  /**
2006
2058
  * An object marked via {@link opaque} — the store treats it as an indivisible leaf
2007
2059
  * (like a `Date`), returning it whole instead of deep-proxying its keys.
@@ -2010,10 +2062,10 @@ type Opaque<T> = T & {
2010
2062
  readonly [OPAQUE]: true;
2011
2063
  };
2012
2064
  /** @internal Strips the opaque brand from the value a leaf signal carries. */
2013
- type Unwrap<T> = T extends {
2065
+ type UnwrapOpqaue<T> = T extends {
2014
2066
  readonly [OPAQUE]: true;
2015
2067
  } ? Omit<T, typeof OPAQUE> : T;
2016
- type BaseType = string | number | boolean | symbol | undefined | null | Function | Date | RegExp | {
2068
+ type BaseType = string | number | boolean | symbol | bigint | undefined | null | Function | Date | RegExp | {
2017
2069
  readonly [OPAQUE]: true;
2018
2070
  };
2019
2071
  type Key = string | number;
@@ -2082,16 +2134,22 @@ type MutableSignalStoreObject<T> = Simplify<Readonly<{
2082
2134
  <L extends AnyRecord>(props: L): MutableSignalStore<Simplify<Omit<NonNullable<T>, keyof L> & L>>;
2083
2135
  };
2084
2136
  }>;
2085
- type SignalStore<T> = Signal<Unwrap<T>> & (IsAny<T> extends true ? SignalStoreObject<T> : NonNullable<T> extends BaseType ? unknown : NonNullable<T> extends Array<any> ? SignalArrayStore<NonNullable<T>> : SignalStoreObject<T>);
2086
- type WritableSignalStore<T> = WritableSignal<Unwrap<T>> & {
2137
+ type SignalStore<T> = Signal<UnwrapOpqaue<T>> & (IsAny<T> extends true ? SignalStoreObject<T> : NonNullable<T> extends BaseType ? {
2138
+ readonly [LEAF]: () => boolean;
2139
+ } : NonNullable<T> extends Array<any> ? SignalArrayStore<NonNullable<T>> : SignalStoreObject<T>);
2140
+ type WritableSignalStore<T> = WritableSignal<UnwrapOpqaue<T>> & {
2087
2141
  readonly asReadonlyStore: () => SignalStore<T>;
2088
- } & (IsAny<T> extends true ? WritableSignalStoreObject<T> : NonNullable<T> extends BaseType ? unknown : NonNullable<T> extends Array<any> ? WritableArrayStore<NonNullable<T>> : WritableSignalStoreObject<T>);
2089
- type MutableSignalStore<T> = MutableSignal<Unwrap<T>> & {
2142
+ } & (IsAny<T> extends true ? WritableSignalStoreObject<T> : NonNullable<T> extends BaseType ? {
2143
+ readonly [LEAF]: () => boolean;
2144
+ } : NonNullable<T> extends Array<any> ? WritableArrayStore<NonNullable<T>> : WritableSignalStoreObject<T>);
2145
+ type MutableSignalStore<T> = MutableSignal<UnwrapOpqaue<T>> & {
2090
2146
  readonly asReadonlyStore: () => SignalStore<T>;
2091
- } & (IsAny<T> extends true ? MutableSignalStoreObject<T> : NonNullable<T> extends BaseType ? unknown : NonNullable<T> extends Array<any> ? MutableArrayStore<NonNullable<T>> : MutableSignalStoreObject<T>);
2092
- declare function toStore<T extends AnyRecord>(source: MutableSignal<T>, injector?: Injector, vivify?: Vivify): MutableSignalStore<T>;
2093
- declare function toStore<T extends AnyRecord>(source: WritableSignal<T>, injector?: Injector, vivify?: Vivify): WritableSignalStore<T>;
2094
- declare function toStore<T extends AnyRecord>(source: Signal<T>, injector?: Injector, vivify?: Vivify): SignalStore<T>;
2147
+ } & (IsAny<T> extends true ? MutableSignalStoreObject<T> : NonNullable<T> extends BaseType ? {
2148
+ readonly [LEAF]: () => boolean;
2149
+ } : NonNullable<T> extends Array<any> ? MutableArrayStore<NonNullable<T>> : MutableSignalStoreObject<T>);
2150
+ declare function toStore<T extends AnyRecord>(source: MutableSignal<T>, injector?: Injector, vivify?: Vivify, noUnionLeaves?: boolean): MutableSignalStore<T>;
2151
+ declare function toStore<T extends AnyRecord>(source: WritableSignal<T>, injector?: Injector, vivify?: Vivify, noUnionLeaves?: boolean): WritableSignalStore<T>;
2152
+ declare function toStore<T extends AnyRecord>(source: Signal<T>, injector?: Injector, vivify?: Vivify, noUnionLeaves?: boolean): SignalStore<T>;
2095
2153
  /**
2096
2154
  * Creates a WritableSignalStore from a value.
2097
2155
  * @see {@link toStore}
@@ -2109,6 +2167,14 @@ declare function store<T extends AnyRecord>(value: T, opt?: CreateSignalOptions<
2109
2167
  * explicit `'object'`/`'array'`, or a `() => container` factory. See {@link Vivify}.
2110
2168
  */
2111
2169
  vivify?: Vivify;
2170
+ /**
2171
+ * Performance opt-in: promise that no node ever switches between leaf and substore (i.e. no
2172
+ * unions mixing a primitive with an object/array). With this on, each node's leaf-ness is
2173
+ * resolved once on the first {@link isLeaf} probe and cached as a constant, skipping the
2174
+ * reactive `computed`. If a node's shape does change anyway, {@link isLeaf} keeps its first
2175
+ * answer. Off by default.
2176
+ */
2177
+ noUnionLeaves?: boolean;
2112
2178
  }): WritableSignalStore<T>;
2113
2179
  /**
2114
2180
  * Creates a MutableSignalStore from a value.
@@ -2127,19 +2193,15 @@ declare function mutableStore<T extends AnyRecord>(value: T, opt?: CreateSignalO
2127
2193
  * explicit `'object'`/`'array'`, or a `() => container` factory. See {@link Vivify}.
2128
2194
  */
2129
2195
  vivify?: Vivify;
2196
+ /**
2197
+ * Performance opt-in: promise that no node ever switches between leaf and substore (i.e. no
2198
+ * unions mixing a primitive with an object/array). With this on, each node's leaf-ness is
2199
+ * resolved once on the first {@link isLeaf} probe and cached as a constant, skipping the
2200
+ * reactive `computed`. If a node's shape does change anyway, {@link isLeaf} keeps its first
2201
+ * answer. Off by default.
2202
+ */
2203
+ noUnionLeaves?: boolean;
2130
2204
  }): MutableSignalStore<T>;
2131
- /**
2132
- * Marks a plain object as opaque so {@link store} treats it as an indivisible leaf
2133
- * (returned whole, never deep-proxied) — the same way it treats a `Date` or `RegExp`.
2134
- * The marker is a non-enumerable symbol, so it never appears in spreads or iteration.
2135
- * Idempotent. Call before freezing (`defineProperty` fails on a frozen object).
2136
- *
2137
- * @example
2138
- * const s = store({ config: opaque({ theme: 'dark', nested: { a: 1 } }) });
2139
- * s.config(); // the whole object, not a child store
2140
- * s.config.set(opaque({ theme: 'light', nested: { a: 2 } }));
2141
- */
2142
- declare function opaque<T extends object>(value: T): Opaque<T>;
2143
2205
 
2144
2206
  /**
2145
2207
  * Interface for storage mechanisms compatible with the `stored` signal.
@@ -2568,5 +2630,5 @@ type CreateHistoryOptions<T> = Omit<CreateSignalOptions<T[]>, 'equal'> & {
2568
2630
  */
2569
2631
  declare function withHistory<T>(sourceOrValue: WritableSignal<T> | T, opt?: CreateHistoryOptions<T>): SignalWithHistory<T>;
2570
2632
 
2571
- export { batteryStatus, chunked, clipboard, combineWith, debounce, debounced, derived, distinct, elementSize, elementVisibility, filter, filterWith, focusWithin, geolocation, idle, indexArray, isDerivation, isMutable, isStore, keyArray, map, mapArray, mapObject, mediaQuery, mousePosition, mutable, mutableStore, nestedEffect, networkStatus, opaque, orientation, pageVisibility, pairwise, pipeable, piped, pooled, pooledArray, pooledMap, pooledSet, prefersDarkMode, prefersReducedMotion, scan, scrollPosition, select, sensor, sensors, signalFromEvent, startWith, store, stored, tabSync, tap, throttle, throttled, toFakeDerivation, toFakeSignalDerivation, toStore, toWritable, until, windowSize, withHistory };
2633
+ export { batteryStatus, chunked, clipboard, combineWith, debounce, debounced, derived, distinct, elementSize, elementVisibility, filter, filterWith, focusWithin, geolocation, idle, indexArray, isDerivation, isLeaf, isMutable, isOpaque, isStore, keyArray, map, mapArray, mapObject, mediaQuery, mousePosition, mutable, mutableStore, nestedEffect, networkStatus, opaque, orientation, pageVisibility, pairwise, pipeable, piped, pooled, pooledArray, pooledMap, pooledSet, prefersDarkMode, prefersReducedMotion, scan, scrollPosition, select, sensor, sensors, signalFromEvent, startWith, store, stored, tabSync, tap, throttle, throttled, toFakeDerivation, toFakeSignalDerivation, toStore, toWritable, until, windowSize, withHistory };
2572
2634
  export type { BatteryStatus, ClipboardSignal, Computation, CreateChunkedOptions, CreateDebouncedOptions, CreateHistoryOptions, CreatePooledOptions, CreateProvidedPooledOptions, CreateStoredOptions, CreateThrottledOptions, DebouncedSignal, DerivedSignal, ElementSize, ElementSizeOptions, ElementSizeSignal, ElementVisibilityOptions, ElementVisibilitySignal, GeolocationOptions, GeolocationSignal, IdleOptions, IdleSignal, MousePositionOptions, MousePositionSignal, MutableSignal, MutableSignalStore, NetworkStatusSignal, Opaque, PipeableSignal, ScreenOrientation, ScrollPosition, ScrollPositionOptions, ScrollPositionSignal, SignalFromEventOptions, SignalStore, SignalWithHistory, StoredSignal, ThrottledSignal, UntilOptions, Vivify, WindowSize, WindowSizeOptions, WindowSizeSignal, WithVivify, WritableSignalStore };