@mmstack/primitives 19.3.10 → 19.3.11

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/index.d.ts CHANGED
@@ -7,7 +7,7 @@ export * from './lib/mutable';
7
7
  export * from './lib/pipeable/public_api';
8
8
  export * from './lib/pooled';
9
9
  export * from './lib/sensors';
10
- export { isOpaque, isStore, mutableStore, opaque, store, toStore, type MutableSignalStore, type Opaque, type SignalStore, type WritableSignalStore, } from './lib/store';
10
+ export { isLeaf, isOpaque, isStore, mutableStore, opaque, store, toStore, type MutableSignalStore, type Opaque, type SignalStore, type WritableSignalStore, } from './lib/store';
11
11
  export * from './lib/stored';
12
12
  export { tabSync } from './lib/tabSync';
13
13
  export * from './lib/throttled';
package/lib/store.d.ts CHANGED
@@ -33,7 +33,32 @@ export declare function opaque<T extends object>(value: T): Opaque<T>;
33
33
  * // value: Opaque<object> — `store` would treat it as an indivisible leaf
34
34
  * }
35
35
  */
36
- export declare function isOpaque(value: unknown): value is Opaque<object>;
36
+ export declare function isOpaque<T = object>(value: unknown): value is Opaque<T>;
37
+ /**
38
+ * @internal Runtime brand carrying a store node's lazily-built leaf probe. Exported (like
39
+ * {@link OPAQUE}) only so the `{ readonly [LEAF]: () => boolean }` brand on the store types is
40
+ * nameable in the emitted declarations — not part of the supported surface; use {@link isLeaf}.
41
+ */
42
+ export declare const LEAF: unique symbol;
43
+ /**
44
+ * Reports whether a store node is currently a **leaf** — a terminal value the store does not
45
+ * descend into (a primitive, `Date`, `RegExp`, {@link opaque} object, class instance, or a
46
+ * `null`/`undefined` hole when vivification is off) rather than a record/array substore.
47
+ *
48
+ * Leaf-ness reflects the node's **live** value: the probe is reactive and memoized, so calling
49
+ * `isLeaf` inside a `computed`/`effect` re-evaluates when the node's shape changes.
50
+ *
51
+ * @internal Exposed for advanced/niche interop only — not part of the supported public surface
52
+ * and may change without a major version bump.
53
+ *
54
+ * @example
55
+ * const s = store({ name: 'Ada', address: { city: 'London' } });
56
+ * isLeaf(s.name); // true
57
+ * isLeaf(s.address); // false — a substore
58
+ */
59
+ export declare function isLeaf<T = unknown>(value: unknown): value is Signal<T> & {
60
+ readonly [LEAF]: () => boolean;
61
+ };
37
62
  /**
38
63
  * An object marked via {@link opaque} — the store treats it as an indivisible leaf
39
64
  * (like a `Date`), returning it whole instead of deep-proxying its keys.
@@ -45,7 +70,7 @@ export type Opaque<T> = T & {
45
70
  export type UnwrapOpqaue<T> = T extends {
46
71
  readonly [OPAQUE]: true;
47
72
  } ? Omit<T, typeof OPAQUE> : T;
48
- type BaseType = string | number | boolean | symbol | undefined | null | Function | Date | RegExp | {
73
+ type BaseType = string | number | boolean | symbol | bigint | undefined | null | Function | Date | RegExp | {
49
74
  readonly [OPAQUE]: true;
50
75
  };
51
76
  type Key = string | number;
@@ -129,16 +154,22 @@ type MutableSignalStoreObject<T> = Simplify<Readonly<{
129
154
  <L extends AnyRecord>(props: L): MutableSignalStore<Simplify<Omit<NonNullable<T>, keyof L> & L>>;
130
155
  };
131
156
  }>;
132
- export type SignalStore<T> = Signal<UnwrapOpqaue<T>> & (IsAny<T> extends true ? SignalStoreObject<T> : NonNullable<T> extends BaseType ? unknown : NonNullable<T> extends Array<any> ? SignalArrayStore<NonNullable<T>> : SignalStoreObject<T>);
157
+ export type SignalStore<T> = Signal<UnwrapOpqaue<T>> & (IsAny<T> extends true ? SignalStoreObject<T> : NonNullable<T> extends BaseType ? {
158
+ readonly [LEAF]: () => boolean;
159
+ } : NonNullable<T> extends Array<any> ? SignalArrayStore<NonNullable<T>> : SignalStoreObject<T>);
133
160
  export type WritableSignalStore<T> = WritableSignal<UnwrapOpqaue<T>> & {
134
161
  readonly asReadonlyStore: () => SignalStore<T>;
135
- } & (IsAny<T> extends true ? WritableSignalStoreObject<T> : NonNullable<T> extends BaseType ? unknown : NonNullable<T> extends Array<any> ? WritableArrayStore<NonNullable<T>> : WritableSignalStoreObject<T>);
162
+ } & (IsAny<T> extends true ? WritableSignalStoreObject<T> : NonNullable<T> extends BaseType ? {
163
+ readonly [LEAF]: () => boolean;
164
+ } : NonNullable<T> extends Array<any> ? WritableArrayStore<NonNullable<T>> : WritableSignalStoreObject<T>);
136
165
  export type MutableSignalStore<T> = MutableSignal<UnwrapOpqaue<T>> & {
137
166
  readonly asReadonlyStore: () => SignalStore<T>;
138
- } & (IsAny<T> extends true ? MutableSignalStoreObject<T> : NonNullable<T> extends BaseType ? unknown : NonNullable<T> extends Array<any> ? MutableArrayStore<NonNullable<T>> : MutableSignalStoreObject<T>);
139
- export declare function toStore<T extends AnyRecord>(source: MutableSignal<T>, injector?: Injector, vivify?: Vivify): MutableSignalStore<T>;
140
- export declare function toStore<T extends AnyRecord>(source: WritableSignal<T>, injector?: Injector, vivify?: Vivify): WritableSignalStore<T>;
141
- export declare function toStore<T extends AnyRecord>(source: Signal<T>, injector?: Injector, vivify?: Vivify): SignalStore<T>;
167
+ } & (IsAny<T> extends true ? MutableSignalStoreObject<T> : NonNullable<T> extends BaseType ? {
168
+ readonly [LEAF]: () => boolean;
169
+ } : NonNullable<T> extends Array<any> ? MutableArrayStore<NonNullable<T>> : MutableSignalStoreObject<T>);
170
+ export declare function toStore<T extends AnyRecord>(source: MutableSignal<T>, injector?: Injector, vivify?: Vivify, noUnionLeaves?: boolean): MutableSignalStore<T>;
171
+ export declare function toStore<T extends AnyRecord>(source: WritableSignal<T>, injector?: Injector, vivify?: Vivify, noUnionLeaves?: boolean): WritableSignalStore<T>;
172
+ export declare function toStore<T extends AnyRecord>(source: Signal<T>, injector?: Injector, vivify?: Vivify, noUnionLeaves?: boolean): SignalStore<T>;
142
173
  /**
143
174
  * Creates a WritableSignalStore from a value.
144
175
  * @see {@link toStore}
@@ -156,6 +187,14 @@ export declare function store<T extends AnyRecord>(value: T, opt?: CreateSignalO
156
187
  * explicit `'object'`/`'array'`, or a `() => container` factory. See {@link Vivify}.
157
188
  */
158
189
  vivify?: Vivify;
190
+ /**
191
+ * Performance opt-in: promise that no node ever switches between leaf and substore (i.e. no
192
+ * unions mixing a primitive with an object/array). With this on, each node's leaf-ness is
193
+ * resolved once on the first {@link isLeaf} probe and cached as a constant, skipping the
194
+ * reactive `computed`. If a node's shape does change anyway, {@link isLeaf} keeps its first
195
+ * answer. Off by default.
196
+ */
197
+ noUnionLeaves?: boolean;
159
198
  }): WritableSignalStore<T>;
160
199
  /**
161
200
  * Creates a MutableSignalStore from a value.
@@ -174,5 +213,13 @@ export declare function mutableStore<T extends AnyRecord>(value: T, opt?: Create
174
213
  * explicit `'object'`/`'array'`, or a `() => container` factory. See {@link Vivify}.
175
214
  */
176
215
  vivify?: Vivify;
216
+ /**
217
+ * Performance opt-in: promise that no node ever switches between leaf and substore (i.e. no
218
+ * unions mixing a primitive with an object/array). With this on, each node's leaf-ness is
219
+ * resolved once on the first {@link isLeaf} probe and cached as a constant, skipping the
220
+ * reactive `computed`. If a node's shape does change anyway, {@link isLeaf} keeps its first
221
+ * answer. Off by default.
222
+ */
223
+ noUnionLeaves?: boolean;
177
224
  }): MutableSignalStore<T>;
178
225
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mmstack/primitives",
3
- "version": "19.3.10",
3
+ "version": "19.3.11",
4
4
  "keywords": [
5
5
  "angular",
6
6
  "signals",