@mmstack/primitives 19.3.8 → 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/fesm2022/mmstack-primitives.mjs +46 -10
- package/fesm2022/mmstack-primitives.mjs.map +1 -1
- package/index.d.ts +1 -1
- package/lib/store.d.ts +50 -4
- package/package.json +1 -1
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 {
|
|
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
|
@@ -1,7 +1,53 @@
|
|
|
1
1
|
import { Injector, type CreateSignalOptions, type Signal, type WritableSignal } from '@angular/core';
|
|
2
2
|
import { type MutableSignal } from './mutable';
|
|
3
3
|
import { type Vivify } from './util';
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Runtime marker + compile-time brand for an opaque value. A `const`-declared `Symbol`
|
|
6
|
+
* has a `unique symbol` type, so the same symbol serves as both the property key written
|
|
7
|
+
* by {@link opaque} and the type-level brand carried by {@link Opaque}.
|
|
8
|
+
*/
|
|
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>;
|
|
37
|
+
/**
|
|
38
|
+
* An object marked via {@link opaque} — the store treats it as an indivisible leaf
|
|
39
|
+
* (like a `Date`), returning it whole instead of deep-proxying its keys.
|
|
40
|
+
*/
|
|
41
|
+
export type Opaque<T> = T & {
|
|
42
|
+
readonly [OPAQUE]: true;
|
|
43
|
+
};
|
|
44
|
+
/** @internal Strips the opaque brand from the value a leaf signal carries. */
|
|
45
|
+
export type UnwrapOpqaue<T> = T extends {
|
|
46
|
+
readonly [OPAQUE]: true;
|
|
47
|
+
} ? Omit<T, typeof OPAQUE> : T;
|
|
48
|
+
type BaseType = string | number | boolean | symbol | undefined | null | Function | Date | RegExp | {
|
|
49
|
+
readonly [OPAQUE]: true;
|
|
50
|
+
};
|
|
5
51
|
type Key = string | number;
|
|
6
52
|
type AnyRecord = Record<Key, any>;
|
|
7
53
|
/**
|
|
@@ -83,11 +129,11 @@ type MutableSignalStoreObject<T> = Simplify<Readonly<{
|
|
|
83
129
|
<L extends AnyRecord>(props: L): MutableSignalStore<Simplify<Omit<NonNullable<T>, keyof L> & L>>;
|
|
84
130
|
};
|
|
85
131
|
}>;
|
|
86
|
-
export type SignalStore<T> = Signal<T
|
|
87
|
-
export type WritableSignalStore<T> = WritableSignal<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>> & {
|
|
88
134
|
readonly asReadonlyStore: () => SignalStore<T>;
|
|
89
135
|
} & (IsAny<T> extends true ? WritableSignalStoreObject<T> : NonNullable<T> extends BaseType ? unknown : NonNullable<T> extends Array<any> ? WritableArrayStore<NonNullable<T>> : WritableSignalStoreObject<T>);
|
|
90
|
-
export type MutableSignalStore<T> = MutableSignal<T
|
|
136
|
+
export type MutableSignalStore<T> = MutableSignal<UnwrapOpqaue<T>> & {
|
|
91
137
|
readonly asReadonlyStore: () => SignalStore<T>;
|
|
92
138
|
} & (IsAny<T> extends true ? MutableSignalStoreObject<T> : NonNullable<T> extends BaseType ? unknown : NonNullable<T> extends Array<any> ? MutableArrayStore<NonNullable<T>> : MutableSignalStoreObject<T>);
|
|
93
139
|
export declare function toStore<T extends AnyRecord>(source: MutableSignal<T>, injector?: Injector, vivify?: Vivify): MutableSignalStore<T>;
|