@mmstack/primitives 19.3.9 → 19.3.10

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 { 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,33 @@ 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(value: unknown): value is Opaque<object>;
10
37
  /**
11
38
  * An object marked via {@link opaque} — the store treats it as an indivisible leaf
12
39
  * (like a `Date`), returning it whole instead of deep-proxying its keys.
@@ -15,7 +42,7 @@ export type Opaque<T> = T & {
15
42
  readonly [OPAQUE]: true;
16
43
  };
17
44
  /** @internal Strips the opaque brand from the value a leaf signal carries. */
18
- type Unwrap<T> = T extends {
45
+ export type UnwrapOpqaue<T> = T extends {
19
46
  readonly [OPAQUE]: true;
20
47
  } ? Omit<T, typeof OPAQUE> : T;
21
48
  type BaseType = string | number | boolean | symbol | undefined | null | Function | Date | RegExp | {
@@ -102,11 +129,11 @@ type MutableSignalStoreObject<T> = Simplify<Readonly<{
102
129
  <L extends AnyRecord>(props: L): MutableSignalStore<Simplify<Omit<NonNullable<T>, keyof L> & L>>;
103
130
  };
104
131
  }>;
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>> & {
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>);
133
+ export type WritableSignalStore<T> = WritableSignal<UnwrapOpqaue<T>> & {
107
134
  readonly asReadonlyStore: () => SignalStore<T>;
108
135
  } & (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>> & {
136
+ export type MutableSignalStore<T> = MutableSignal<UnwrapOpqaue<T>> & {
110
137
  readonly asReadonlyStore: () => SignalStore<T>;
111
138
  } & (IsAny<T> extends true ? MutableSignalStoreObject<T> : NonNullable<T> extends BaseType ? unknown : NonNullable<T> extends Array<any> ? MutableArrayStore<NonNullable<T>> : MutableSignalStoreObject<T>);
112
139
  export declare function toStore<T extends AnyRecord>(source: MutableSignal<T>, injector?: Injector, vivify?: Vivify): MutableSignalStore<T>;
@@ -148,16 +175,4 @@ export declare function mutableStore<T extends AnyRecord>(value: T, opt?: Create
148
175
  */
149
176
  vivify?: Vivify;
150
177
  }): 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
178
  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.10",
4
4
  "keywords": [
5
5
  "angular",
6
6
  "signals",