@mmstack/primitives 19.3.9 → 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 { 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
@@ -7,6 +7,58 @@ import { type Vivify } from './util';
7
7
  * by {@link opaque} and the type-level brand carried by {@link Opaque}.
8
8
  */
9
9
  export declare const OPAQUE: unique symbol;
10
+ /**
11
+ * Marks a plain object as opaque so {@link store} treats it as an indivisible leaf
12
+ * (returned whole, never deep-proxied) — the same way it treats a `Date` or `RegExp`.
13
+ * The marker is a non-enumerable symbol, so it never appears in spreads or iteration.
14
+ * Idempotent. Call before freezing (`defineProperty` fails on a frozen object).
15
+ *
16
+ * @example
17
+ * const s = store({ config: opaque({ theme: 'dark', nested: { a: 1 } }) });
18
+ * s.config(); // the whole object, not a child store
19
+ * s.config.set(opaque({ theme: 'light', nested: { a: 2 } }));
20
+ */
21
+ export declare function opaque<T extends object>(value: T): Opaque<T>;
22
+ /**
23
+ * Type guard companion to {@link opaque}: returns `true` when `value` carries the
24
+ * {@link OPAQUE} brand, narrowing it to {@link Opaque}. This is the same check the
25
+ * store uses to route opaque values to its leaf branch (alongside `Date`/`RegExp`).
26
+ *
27
+ * @internal Exposed for advanced/niche interop only — not part of the supported public
28
+ * surface and may change without a major version bump. Reach for {@link opaque} for
29
+ * normal usage.
30
+ *
31
+ * @example
32
+ * if (isOpaque(value)) {
33
+ * // value: Opaque<object> — `store` would treat it as an indivisible leaf
34
+ * }
35
+ */
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
+ };
10
62
  /**
11
63
  * An object marked via {@link opaque} — the store treats it as an indivisible leaf
12
64
  * (like a `Date`), returning it whole instead of deep-proxying its keys.
@@ -15,10 +67,10 @@ export type Opaque<T> = T & {
15
67
  readonly [OPAQUE]: true;
16
68
  };
17
69
  /** @internal Strips the opaque brand from the value a leaf signal carries. */
18
- type Unwrap<T> = T extends {
70
+ export type UnwrapOpqaue<T> = T extends {
19
71
  readonly [OPAQUE]: true;
20
72
  } ? Omit<T, typeof OPAQUE> : T;
21
- type BaseType = string | number | boolean | symbol | undefined | null | Function | Date | RegExp | {
73
+ type BaseType = string | number | boolean | symbol | bigint | undefined | null | Function | Date | RegExp | {
22
74
  readonly [OPAQUE]: true;
23
75
  };
24
76
  type Key = string | number;
@@ -102,16 +154,22 @@ type MutableSignalStoreObject<T> = Simplify<Readonly<{
102
154
  <L extends AnyRecord>(props: L): MutableSignalStore<Simplify<Omit<NonNullable<T>, keyof L> & L>>;
103
155
  };
104
156
  }>;
105
- export 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>);
106
- export type WritableSignalStore<T> = WritableSignal<Unwrap<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>);
160
+ export type WritableSignalStore<T> = WritableSignal<UnwrapOpqaue<T>> & {
107
161
  readonly asReadonlyStore: () => SignalStore<T>;
108
- } & (IsAny<T> extends true ? WritableSignalStoreObject<T> : NonNullable<T> extends BaseType ? unknown : NonNullable<T> extends Array<any> ? WritableArrayStore<NonNullable<T>> : WritableSignalStoreObject<T>);
109
- export type MutableSignalStore<T> = MutableSignal<Unwrap<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>);
165
+ export type MutableSignalStore<T> = MutableSignal<UnwrapOpqaue<T>> & {
110
166
  readonly asReadonlyStore: () => SignalStore<T>;
111
- } & (IsAny<T> extends true ? MutableSignalStoreObject<T> : NonNullable<T> extends BaseType ? unknown : NonNullable<T> extends Array<any> ? MutableArrayStore<NonNullable<T>> : MutableSignalStoreObject<T>);
112
- export declare function toStore<T extends AnyRecord>(source: MutableSignal<T>, injector?: Injector, vivify?: Vivify): MutableSignalStore<T>;
113
- export declare function toStore<T extends AnyRecord>(source: WritableSignal<T>, injector?: Injector, vivify?: Vivify): WritableSignalStore<T>;
114
- 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>;
115
173
  /**
116
174
  * Creates a WritableSignalStore from a value.
117
175
  * @see {@link toStore}
@@ -129,6 +187,14 @@ export declare function store<T extends AnyRecord>(value: T, opt?: CreateSignalO
129
187
  * explicit `'object'`/`'array'`, or a `() => container` factory. See {@link Vivify}.
130
188
  */
131
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;
132
198
  }): WritableSignalStore<T>;
133
199
  /**
134
200
  * Creates a MutableSignalStore from a value.
@@ -147,17 +213,13 @@ export declare function mutableStore<T extends AnyRecord>(value: T, opt?: Create
147
213
  * explicit `'object'`/`'array'`, or a `() => container` factory. See {@link Vivify}.
148
214
  */
149
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;
150
224
  }): MutableSignalStore<T>;
151
- /**
152
- * Marks a plain object as opaque so {@link store} treats it as an indivisible leaf
153
- * (returned whole, never deep-proxied) — the same way it treats a `Date` or `RegExp`.
154
- * The marker is a non-enumerable symbol, so it never appears in spreads or iteration.
155
- * Idempotent. Call before freezing (`defineProperty` fails on a frozen object).
156
- *
157
- * @example
158
- * const s = store({ config: opaque({ theme: 'dark', nested: { a: 1 } }) });
159
- * s.config(); // the whole object, not a child store
160
- * s.config.set(opaque({ theme: 'light', nested: { a: 2 } }));
161
- */
162
- export declare function opaque<T extends object>(value: T): Opaque<T>;
163
225
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mmstack/primitives",
3
- "version": "19.3.9",
3
+ "version": "19.3.11",
4
4
  "keywords": [
5
5
  "angular",
6
6
  "signals",