jotai-state-tree 1.1.1 → 1.1.2

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/dist/index.d.mts CHANGED
@@ -1,318 +1,7 @@
1
- import * as jotai_vanilla_internals from 'jotai/vanilla/internals';
2
- import { WritableAtom, createStore } from 'jotai';
3
-
4
- /**
5
- * Core types for jotai-state-tree
6
- * These types mirror the MobX-State-Tree API
7
- */
8
- type SnapshotIn<T> = T extends IModelType<infer P, any, any, any> ? {
9
- [K in keyof P]?: SnapshotInOfProperty<P[K]>;
10
- } : T extends IArrayType<infer I> ? SnapshotIn<I>[] : T extends IMapType<infer V> ? Record<string, SnapshotIn<V>> : T extends IReferenceType<any> ? string | number : T extends IType<infer C, any, any> ? C : T;
11
- type SnapshotInOfProperty<T> = T extends IType<infer C, any, any> ? C : never;
12
- type SnapshotOut<T> = T extends IModelType<infer P, any, any, any> ? {
13
- [K in keyof P]: SnapshotOutOfProperty<P[K]>;
14
- } : T extends IArrayType<infer I> ? SnapshotOut<I>[] : T extends IMapType<infer V> ? Record<string, SnapshotOut<V>> : T extends IReferenceType<any> ? string | number : T extends IType<any, infer S, any> ? S : T;
15
- type SnapshotOutOfProperty<T> = T extends IType<any, infer S, any> ? S : never;
16
- type Instance<T> = T extends IType<any, any, infer O> ? O : never;
17
- interface IType<C, S, T> {
18
- /** Name of this type */
19
- readonly name: string;
20
- /** The identifier attribute if this type has one */
21
- readonly identifierAttribute?: string;
22
- /** Create an instance of this type */
23
- create(snapshot?: C, env?: unknown): T;
24
- /** Check if a value is an instance of this type */
25
- is(value: unknown): value is T;
26
- /** Validate a value against this type */
27
- validate(value: unknown, context: IValidationContext[]): IValidationResult;
28
- /** Type discriminator */
29
- readonly _kind: string;
30
- readonly _C: C;
31
- readonly _S: S;
32
- readonly _T: T;
33
- }
34
- interface IValidationContext {
35
- path: string;
36
- type: IType<unknown, unknown, unknown>;
37
- parent: unknown;
38
- }
39
- interface IValidationResult {
40
- valid: boolean;
41
- errors: IValidationError[];
42
- }
43
- interface IValidationError {
44
- context: IValidationContext[];
45
- value: unknown;
46
- message: string;
47
- }
48
- interface ISimpleType<T> extends IType<T, T, T> {
49
- readonly _kind: "simple";
50
- }
51
- type ModelProperties = Record<string, IType<unknown, unknown, unknown>>;
52
- type ModelCreationType<P extends ModelProperties> = {
53
- [K in keyof P]?: P[K] extends IType<infer C, unknown, unknown> ? C : never;
54
- };
55
- type ModelSnapshotType<P extends ModelProperties> = {
56
- [K in keyof P]: P[K] extends IType<unknown, infer S, unknown> ? S : never;
57
- };
58
- type ModelInstanceType<P extends ModelProperties> = {
59
- [K in keyof P]: P[K] extends IType<unknown, unknown, infer T> ? T : never;
60
- };
61
- /** Represents a node in the state tree */
62
- interface IStateTreeNode<S = unknown> {
63
- readonly $id: string;
64
- readonly $type: IType<unknown, unknown, unknown>;
65
- readonly $parent: IStateTreeNode | null;
66
- readonly $path: string;
67
- readonly $env: unknown;
68
- readonly $isAlive: boolean;
69
- }
70
- type ModelInstance<P extends ModelProperties, V extends object, A extends object, Vol extends object> = ModelInstanceType<P> & {
71
- /** Access to the tree node metadata */
72
- readonly $treenode: IStateTreeNode;
73
- };
74
- type ModelViews<Self, V> = (self: Self) => V;
75
- type ModelActions<Self, A> = (self: Self) => A;
76
- type ModelVolatile<Self, Vol> = (self: Self) => Vol;
77
- interface IModelType<P extends ModelProperties, V extends object, A extends object, Vol extends object> extends IType<ModelCreationType<P>, ModelSnapshotType<P>, ModelInstance<P, V, A, Vol> & V & A & Vol> {
78
- readonly _kind: "model";
79
- readonly properties: P;
80
- /** Create a new model type with a different name */
81
- named(name: string): IModelType<P, V, A, Vol>;
82
- /** Add properties to the model */
83
- props<P2 extends ModelProperties>(properties: P2): IModelType<P & P2, V, A, Vol>;
84
- /** Add computed views to the model */
85
- views<V2 extends object>(fn: ModelViews<ModelInstance<P, V, A, Vol> & V & A & Vol, V2>): IModelType<P, V & V2, A, Vol>;
86
- /** Add actions to the model */
87
- actions<A2 extends object>(fn: ModelActions<ModelInstance<P, V, A, Vol> & V & A & Vol, A2>): IModelType<P, V, A & A2, Vol>;
88
- /** Add volatile (non-serialized) state */
89
- volatile<Vol2 extends object>(fn: ModelVolatile<ModelInstance<P, V, A, Vol> & V & A & Vol, Vol2>): IModelType<P, V, A, Vol & Vol2>;
90
- /** Transform snapshot before creating instance */
91
- preProcessSnapshot<NewC>(fn: (snapshot: NewC) => ModelCreationType<P>): IModelType<P, V, A, Vol>;
92
- /** Transform snapshot after getting it */
93
- postProcessSnapshot<NewS>(fn: (snapshot: ModelSnapshotType<P>) => NewS): IModelType<P, V, A, Vol>;
94
- /** Extend the model with views, actions, and state in one call */
95
- extend<V2 extends object = object, A2 extends object = object, Vol2 extends object = object>(fn: (self: ModelInstance<P, V, A, Vol> & V & A & Vol) => {
96
- views?: V2;
97
- actions?: A2;
98
- state?: Vol2;
99
- }): IModelType<P, V & V2, A & A2, Vol & Vol2>;
100
- /** Add afterCreate lifecycle hook */
101
- afterCreate(fn: (self: ModelInstance<P, V, A, Vol> & V & A & Vol) => void): IModelType<P, V, A, Vol>;
102
- /** Add afterAttach lifecycle hook (called when node is attached to tree) */
103
- afterAttach(fn: (self: ModelInstance<P, V, A, Vol> & V & A & Vol) => void): IModelType<P, V, A, Vol>;
104
- /** Add beforeDetach lifecycle hook (called before node is detached from tree) */
105
- beforeDetach(fn: (self: ModelInstance<P, V, A, Vol> & V & A & Vol) => void): IModelType<P, V, A, Vol>;
106
- /** Add beforeDestroy lifecycle hook (called before node is destroyed) */
107
- beforeDestroy(fn: (self: ModelInstance<P, V, A, Vol> & V & A & Vol) => void): IModelType<P, V, A, Vol>;
108
- /**
109
- * Apply a mixin to this model.
110
- * The mixin's requirements must be satisfied by this model's properties.
111
- *
112
- * @example
113
- * const Timestamped = types.mixin({
114
- * requires: { createdAt: types.number },
115
- * views: (self) => ({ get formattedDate() { ... } }),
116
- * });
117
- *
118
- * const MyModel = types
119
- * .model({ name: types.string, createdAt: types.number })
120
- * .apply(Timestamped);
121
- */
122
- apply<RequiredProps extends ModelProperties, MV extends object, MA extends object, MVol extends object>(mixin: IMixin<RequiredProps, MV, MA, MVol>): P extends RequiredProps ? IModelType<P, V & MV, A & MA, Vol & MVol> : never;
123
- }
124
- /**
125
- * MST Array interface that allows both instance types and snapshot/creation types
126
- * for mutation methods like push(), unshift(), splice(), etc.
127
- *
128
- * @template T - The instance type of array items
129
- * @template C - The creation/snapshot type of array items (defaults to T)
130
- */
131
- interface IMSTArray<T, C = T> extends Omit<Array<T>, "push" | "unshift" | "splice" | "fill"> {
132
- /** Array length */
133
- readonly length: number;
134
- /** Push items (accepts both instances and snapshots) */
135
- push(...items: (T | C)[]): number;
136
- /** Unshift items (accepts both instances and snapshots) */
137
- unshift(...items: (T | C)[]): number;
138
- /** Splice items (accepts both instances and snapshots for new items) */
139
- splice(start: number, deleteCount?: number, ...items: (T | C)[]): T[];
140
- /** Fill with value */
141
- fill(value: T | C, start?: number, end?: number): this;
142
- /** Replace all items */
143
- replace(items: (T | C)[]): void;
144
- /** Remove all items */
145
- clear(): void;
146
- /** Remove a specific item */
147
- remove(item: T): boolean;
148
- /** Splice with array argument */
149
- spliceWithArray(index: number, deleteCount?: number, newItems?: (T | C)[]): T[];
150
- /** Convert to JSON */
151
- toJSON(): T[];
152
- /** Index access */
153
- [index: number]: T;
154
- /** Iterator */
155
- [Symbol.iterator](): IterableIterator<T>;
156
- }
157
- interface IArrayType<T extends IType<unknown, unknown, unknown>> extends IType<Array<T extends IType<infer C, unknown, unknown> ? C : never>, Array<T extends IType<unknown, infer S, unknown> ? S : never>, IMSTArray<T extends IType<unknown, unknown, infer I> ? I : never, T extends IType<infer C, unknown, unknown> ? C : never>> {
158
- readonly _kind: "array";
159
- readonly _subType: T;
160
- }
161
- interface IMSTMap<V> extends Map<string, V> {
162
- /** Put a value, returning it */
163
- put(value: V): V;
164
- /** Merge values into the map */
165
- merge(values: Record<string, V> | Map<string, V>): this;
166
- /** Replace all values */
167
- replace(values: Record<string, V> | Map<string, V>): this;
168
- /** Convert to JSON */
169
- toJSON(): Record<string, V>;
170
- }
171
- interface IMapType<T extends IType<unknown, unknown, unknown>> extends IType<Record<string, T extends IType<infer C, unknown, unknown> ? C : never>, Record<string, T extends IType<unknown, infer S, unknown> ? S : never>, IMSTMap<T extends IType<unknown, unknown, infer I> ? I : never>> {
172
- readonly _kind: "map";
173
- readonly _subType: T;
174
- }
175
- interface IOptionalType<T extends IType<unknown, unknown, unknown>, Default> extends IType<(T extends IType<infer C, unknown, unknown> ? C : never) | undefined, T extends IType<unknown, infer S, unknown> ? S : never, T extends IType<unknown, unknown, infer I> ? I : never> {
176
- readonly _kind: "optional";
177
- readonly _subType: T;
178
- readonly _defaultValue: Default | (() => Default);
179
- }
180
- interface IMaybeType<T extends IType<unknown, unknown, unknown>> extends IType<(T extends IType<infer C, unknown, unknown> ? C : never) | undefined, (T extends IType<unknown, infer S, unknown> ? S : never) | undefined, (T extends IType<unknown, unknown, infer I> ? I : never) | undefined> {
181
- readonly _kind: "maybe";
182
- readonly _subType: T;
183
- }
184
- interface IMaybeNullType<T extends IType<unknown, unknown, unknown>> extends IType<(T extends IType<infer C, unknown, unknown> ? C : never) | null, (T extends IType<unknown, infer S, unknown> ? S : never) | null, (T extends IType<unknown, unknown, infer I> ? I : never) | null> {
185
- readonly _kind: "maybeNull";
186
- readonly _subType: T;
187
- }
188
- interface IReferenceType<T extends IAnyModelType> extends IType<string | number, string | number, Instance<T>> {
189
- readonly _kind: "reference";
190
- readonly _targetType: T;
191
- }
192
- interface ReferenceOptions<T extends IAnyModelType> {
193
- get?(identifier: string | number, parent: unknown): Instance<T> | undefined;
194
- set?(value: Instance<T>, parent: unknown): string | number;
195
- onInvalidated?: (event: {
196
- parent: unknown;
197
- invalidId: string | number;
198
- replaceRef: (newRef: Instance<T> | null) => void;
199
- removeRef: () => void;
200
- cause: "destroy" | "invalidSnapshotReference" | "detach";
201
- }) => void;
202
- }
203
- interface ISafeReferenceType<T extends IAnyModelType> extends IType<string | number | undefined, string | number | undefined, Instance<T> | undefined> {
204
- readonly _kind: "safeReference";
205
- readonly _targetType: T;
206
- }
207
- type UnionOptions = {
208
- dispatcher?: (snapshot: unknown) => IType<unknown, unknown, unknown>;
209
- eager?: boolean;
210
- };
211
- interface IUnionType<Types extends IType<unknown, unknown, unknown>[]> extends IType<Types[number] extends IType<infer C, unknown, unknown> ? C : never, Types[number] extends IType<unknown, infer S, unknown> ? S : never, Types[number] extends IType<unknown, unknown, infer T> ? T : never> {
212
- readonly _kind: "union";
213
- readonly _types: Types;
214
- }
215
- interface ILiteralType<T extends string | number | boolean> extends IType<T, T, T> {
216
- readonly _kind: "literal";
217
- readonly _value: T;
218
- }
219
- interface IEnumerationType<E extends string> extends IType<E, E, E> {
220
- readonly _kind: "enumeration";
221
- readonly _options: readonly E[];
222
- }
223
- interface IFrozenType<T> extends IType<T, T, T> {
224
- readonly _kind: "frozen";
225
- }
226
- interface ILateType<T extends IType<unknown, unknown, unknown>> extends IType<T extends IType<infer C, unknown, unknown> ? C : never, T extends IType<unknown, infer S, unknown> ? S : never, T extends IType<unknown, unknown, infer I> ? I : never> {
227
- readonly _kind: "late";
228
- readonly _definition: () => T;
229
- }
230
- interface IRefinementType<T extends IType<unknown, unknown, unknown>> extends IType<T extends IType<infer C, unknown, unknown> ? C : never, T extends IType<unknown, infer S, unknown> ? S : never, T extends IType<unknown, unknown, infer I> ? I : never> {
231
- readonly _kind: "refinement";
232
- readonly _subType: T;
233
- readonly _predicate: (value: unknown) => boolean;
234
- }
235
- interface CustomTypeOptions$1<C, S, T> {
236
- name: string;
237
- fromSnapshot(snapshot: S): T;
238
- toSnapshot(value: T): S;
239
- isTargetType(value: unknown): boolean;
240
- getValidationMessage(value: unknown): string;
241
- }
242
- interface IIdentifierType extends IType<string, string, string> {
243
- readonly _kind: "identifier";
244
- readonly identifierAttribute: string;
245
- }
246
- interface IIdentifierNumberType extends IType<number, number, number> {
247
- readonly _kind: "identifierNumber";
248
- readonly identifierAttribute: string;
249
- }
250
- interface IJsonPatch {
251
- op: "replace" | "add" | "remove";
252
- path: string;
253
- value?: unknown;
254
- }
255
- interface IReversibleJsonPatch extends IJsonPatch {
256
- oldValue?: unknown;
257
- }
258
- type IAnyType = IType<unknown, unknown, unknown>;
259
- type IAnyModelType = IModelType<ModelProperties, object, object, object>;
260
- type IAnyComplexType = IAnyModelType | IArrayType<IAnyType> | IMapType<IAnyType>;
261
- /**
262
- * Extract the full "self" type from a model type.
263
- * This includes properties, views, actions, and volatile state.
264
- *
265
- * @example
266
- * const User = types.model({ name: types.string }).views(self => ({ ... }));
267
- * type UserSelf = ModelSelf<typeof User>; // includes name + all views
268
- */
269
- type ModelSelf<M> = M extends IModelType<infer P, infer V, infer A, infer Vol> ? ModelInstance<P, V, A, Vol> & V & A & Vol : never;
270
- /**
271
- * Configuration for creating a mixin.
272
- * @template RequiredProps - Properties the mixin requires from the base model
273
- * @template V - Views the mixin provides
274
- * @template A - Actions the mixin provides
275
- * @template Vol - Volatile state the mixin provides
276
- */
277
- interface MixinConfig<RequiredProps extends ModelProperties, V extends object = object, A extends object = object, Vol extends object = object> {
278
- /** Properties the mixin requires from any model it's applied to */
279
- requires?: RequiredProps;
280
- /** Views to add to the model */
281
- views?: (self: ModelInstanceType<RequiredProps>) => V;
282
- /** Actions to add to the model */
283
- actions?: (self: ModelInstanceType<RequiredProps> & V) => A;
284
- /** Volatile state to add to the model */
285
- volatile?: (self: ModelInstanceType<RequiredProps> & V & A) => Vol;
286
- }
287
- /**
288
- * A mixin that can be applied to models to add views, actions, and volatile state.
289
- * Mixins declare what properties they require and what they provide.
290
- *
291
- * @template RequiredProps - Properties the mixin requires
292
- * @template V - Views the mixin provides
293
- * @template A - Actions the mixin provides
294
- * @template Vol - Volatile state the mixin provides
295
- */
296
- interface IMixin<RequiredProps extends ModelProperties, V extends object = object, A extends object = object, Vol extends object = object> {
297
- readonly _kind: "mixin";
298
- /** Properties the mixin requires from the base model */
299
- readonly requires: RequiredProps;
300
- /** Function to create views */
301
- readonly views?: (self: ModelInstanceType<RequiredProps>) => V;
302
- /** Function to create actions */
303
- readonly actions?: (self: ModelInstanceType<RequiredProps> & V) => A;
304
- /** Function to create volatile state */
305
- readonly volatile?: (self: ModelInstanceType<RequiredProps> & V & A) => Vol;
306
- /** Phantom types for inference */
307
- readonly _V: V;
308
- readonly _A: A;
309
- readonly _Vol: Vol;
310
- }
311
- /** Any mixin type */
312
- type IAnyMixin = IMixin<ModelProperties, object, object, object>;
313
- interface IDisposer {
314
- (): void;
315
- }
1
+ import { I as ISimpleType, a as IType, b as IIdentifierType, c as IIdentifierNumberType, d as ILiteralType, e as IEnumerationType, f as IFrozenType, M as ModelProperties, g as IModelType, h as MixinConfig, i as IMixin, j as IAnyType, k as IArrayType, l as IMapType, m as IOptionalType, n as IMaybeType, o as IMaybeNullType, p as IUnionType, U as UnionOptions, q as ILateType, r as IAnyModelType, R as ReferenceOptions, s as IReferenceType, t as ISafeReferenceType, u as IRefinementType, v as IDisposer, S as SnapshotIn, w as Instance, x as IReversibleJsonPatch } from './tree-CDmXgtM5.mjs';
2
+ export { L as CustomTypeOptions, D as IAnyComplexType, E as IAnyMixin, G as IJsonPatch, z as IMSTArray, A as IMSTMap, y as IStateTreeNode, H as IValidationContext, K as IValidationError, J as IValidationResult, B as ModelInstance, F as ModelSelf, C as SnapshotOut, T as applyPatch, O as applySnapshot, aw as cleanupStaleEntries, ax as clearAllRegistries, aa as clone, aq as cloneDeep, a8 as destroy, a9 as detach, am as findAll, an as findFirst, as as freeze, a2 as getEnv, ag as getGlobalStore, a4 as getIdentifier, af as getMembers, ar as getOrCreatePath, Y as getParent, $ as getParentOfType, a0 as getPath, a1 as getPathParts, av as getRegistryStats, aj as getRelativePath, X as getRoot, N as getSnapshot, ap as getTreeStats, a3 as getType, _ as hasParent, al as haveSameRoot, a5 as isAlive, ak as isAncestor, at as isFrozen, a6 as isRoot, a7 as isStateTreeNode, ao as isValidReference, W as onAction, ay as onLifecycleChange, Q as onPatch, P as onSnapshot, V as recordPatches, ai as resetGlobalStore, ae as resolveIdentifier, ac as resolvePath, ah as setGlobalStore, Z as tryGetParent, ad as tryResolve, au as unfreeze, ab as walk } from './tree-CDmXgtM5.mjs';
3
+ import 'jotai/vanilla/internals';
4
+ import 'jotai';
316
5
 
317
6
  /**
318
7
  * Primitive types implementation
@@ -648,193 +337,6 @@ declare function dynamicReference<T extends IAnyType = IAnyType>(modelName: stri
648
337
  */
649
338
  declare function safeDynamicReference<T extends IAnyType = IAnyType>(modelName: string, options?: DynamicReferenceOptions<T>): IType<string | number | undefined, string | number | undefined, (T extends IType<unknown, unknown, infer I> ? I : unknown) | undefined>;
650
339
 
651
- /** Get the global store */
652
- declare function getGlobalStore(): jotai_vanilla_internals.INTERNAL_Store;
653
- /** Set a custom global store (useful for testing) */
654
- declare function setGlobalStore(store: ReturnType<typeof createStore>): void;
655
- /** Reset the global store (useful for testing) */
656
- declare function resetGlobalStore(): void;
657
- /** Subscribe to lifecycle changes of a node */
658
- declare function onLifecycleChange(node: StateTreeNode, listener: (isAlive: boolean) => void): IDisposer;
659
- declare class StateTreeNode implements IStateTreeNode {
660
- readonly $id: string;
661
- readonly $type: IAnyType;
662
- $parent: StateTreeNode | null;
663
- $path: string;
664
- $env: unknown;
665
- $isAlive: boolean;
666
- /** Child nodes - uses Map but children are explicitly destroyed */
667
- private children;
668
- /** Atom storing the raw value/snapshot */
669
- valueAtom: WritableAtom<unknown, [unknown], void>;
670
- /** Snapshot listeners */
671
- private snapshotListeners;
672
- /** Patch listeners */
673
- private patchListeners;
674
- /** Volatile state (non-serialized) */
675
- volatileState: Record<string, unknown>;
676
- /** Pre/post process snapshot functions */
677
- preProcessor?: (snapshot: unknown) => unknown;
678
- postProcessor?: (snapshot: unknown) => unknown;
679
- /** Identifier value if this node has one */
680
- identifierValue?: string | number;
681
- /** Type name for identifier registry */
682
- identifierTypeName?: string;
683
- constructor(type: IAnyType, initialValue: unknown, env?: unknown, parent?: StateTreeNode, pathSegment?: string);
684
- /** Set the instance reference */
685
- setInstance(instance: unknown): void;
686
- /** Get the instance */
687
- getInstance(): unknown;
688
- /** Get current value from atom */
689
- getValue(): unknown;
690
- /** Set value on atom */
691
- setValue(value: unknown): void;
692
- /** Add a child node */
693
- addChild(key: string, child: StateTreeNode): void;
694
- /** Recursively update the path of a node and all its children */
695
- private updatePathRecursively;
696
- /** Remove a child node */
697
- removeChild(key: string): void;
698
- /** Get a child node */
699
- getChild(key: string): StateTreeNode | undefined;
700
- /** Get all children */
701
- getChildren(): Map<string, StateTreeNode>;
702
- /** Register identifier */
703
- registerIdentifier(typeName: string, identifier: string | number): void;
704
- /** Unregister identifier */
705
- unregisterIdentifier(): void;
706
- /** Subscribe to snapshot changes */
707
- onSnapshot(listener: (snapshot: unknown) => void): IDisposer;
708
- /** Subscribe to patches */
709
- onPatch(listener: (patch: IJsonPatch, reversePatch: IReversibleJsonPatch) => void): IDisposer;
710
- /** Notify patch listeners */
711
- private notifyPatch;
712
- /** Notify snapshot listeners */
713
- private notifySnapshotChange;
714
- /** Notify about a property change (for use by model proxy) */
715
- notifyPropertyChange(propName: string, newValue: unknown, oldValue: unknown): void;
716
- /** Notify about a volatile state change (triggers snapshot listeners without patches) */
717
- notifyVolatileChange(): void;
718
- /** Get root node */
719
- getRoot(): StateTreeNode;
720
- /** Destroy this node and all children */
721
- destroy(): void;
722
- /** Detach from parent */
723
- detach(): void;
724
- }
725
- /** Look up a node by identifier */
726
- declare function resolveIdentifier(typeName: string, identifier: string | number): StateTreeNode | undefined;
727
- /** Get statistics about the registries - useful for debugging memory issues */
728
- declare function getRegistryStats(): {
729
- nodeRegistrySize: number;
730
- identifierRegistrySize: number;
731
- identifierTypeCount: number;
732
- liveNodeCount: number;
733
- staleNodeCount: number;
734
- };
735
- /** Clean up stale entries from registries - call periodically if needed */
736
- declare function cleanupStaleEntries(): number;
737
- /** Clear all registries - useful for testing */
738
- declare function clearAllRegistries(): void;
739
- /** Get the root of the tree */
740
- declare function getRoot<T>(target: T): T;
741
- /** Get the parent of a node */
742
- declare function getParent<T = unknown>(target: unknown, depth?: number): T;
743
- /** Try to get the parent, returns undefined if at root */
744
- declare function tryGetParent<T = unknown>(target: unknown, depth?: number): T | undefined;
745
- /** Check if a node has a parent */
746
- declare function hasParent(target: unknown, depth?: number): boolean;
747
- /** Get parent of specific type */
748
- declare function getParentOfType<T extends IAnyModelType>(target: unknown, type: T): T extends IType<unknown, unknown, infer I> ? I : never;
749
- /** Get the path of a node */
750
- declare function getPath(target: unknown): string;
751
- /** Get path parts as array */
752
- declare function getPathParts(target: unknown): string[];
753
- /** Get the environment */
754
- declare function getEnv<E = unknown>(target: unknown): E;
755
- /** Check if node is alive */
756
- declare function isAlive(target: unknown): boolean;
757
- /** Check if node is root */
758
- declare function isRoot(target: unknown): boolean;
759
- /** Get the type of a node */
760
- declare function getType(target: unknown): IAnyType;
761
- /** Check if value is a state tree node */
762
- declare function isStateTreeNode(value: unknown): boolean;
763
- /** Get identifier of a node */
764
- declare function getIdentifier(target: unknown): string | number | null;
765
- /** Destroy a node */
766
- declare function destroy(target: unknown): void;
767
- /** Detach a node from its parent */
768
- declare function detach<T>(target: T): T;
769
- /** Clone a node */
770
- declare function clone<T>(target: T, keepEnvironment?: boolean): T;
771
- /** Get snapshot from an instance */
772
- declare function getSnapshot<S>(target: unknown): S;
773
- /** Apply snapshot to an instance */
774
- declare function applySnapshot<S>(target: unknown, snapshot: S): void;
775
- /** Subscribe to snapshots */
776
- declare function onSnapshot<S>(target: unknown, listener: (snapshot: S) => void): IDisposer;
777
- /** Subscribe to patches */
778
- declare function onPatch(target: unknown, listener: (patch: IJsonPatch, reversePatch: IReversibleJsonPatch) => void): IDisposer;
779
- /** Apply a single patch */
780
- declare function applyPatch(target: unknown, patch: IJsonPatch | IJsonPatch[]): void;
781
- /** Record patches during a function execution */
782
- declare function recordPatches(target: unknown): {
783
- patches: IJsonPatch[];
784
- inversePatches: IReversibleJsonPatch[];
785
- stop: () => void;
786
- resume: () => void;
787
- replay: (target: unknown) => void;
788
- undo: (target: unknown) => void;
789
- };
790
- interface ActionCall {
791
- name: string;
792
- path: string;
793
- args: unknown[];
794
- }
795
- /** Subscribe to action calls */
796
- declare function onAction(target: unknown, listener: (call: ActionCall) => void): IDisposer;
797
- /** Walk the tree */
798
- declare function walk(target: unknown, visitor: (node: unknown) => void): void;
799
- /** Get all members (properties) of a node */
800
- declare function getMembers(target: unknown): {
801
- name: string;
802
- type: "view" | "action" | "property" | "volatile";
803
- value: unknown;
804
- }[];
805
- /** Resolve a path to a node */
806
- declare function resolvePath(target: unknown, path: string): unknown;
807
- /** Try to resolve a path */
808
- declare function tryResolve(target: unknown, path: string): unknown | undefined;
809
- /** Get the relative path from one node to another */
810
- declare function getRelativePath(from: unknown, to: unknown): string;
811
- /** Check if a node is an ancestor of another */
812
- declare function isAncestor(ancestor: unknown, descendant: unknown): boolean;
813
- /** Check if two nodes share a common root */
814
- declare function haveSameRoot(a: unknown, b: unknown): boolean;
815
- /** Get all nodes of a specific type in the tree */
816
- declare function findAll<T>(target: unknown, predicate: (node: unknown) => node is T): T[];
817
- /** Get the first node matching a predicate */
818
- declare function findFirst<T>(target: unknown, predicate: (node: unknown) => node is T): T | undefined;
819
- /** Check if a value is a valid reference target */
820
- declare function isValidReference(target: unknown, identifier: string | number): boolean;
821
- /** Get statistics about the tree */
822
- declare function getTreeStats(target: unknown): {
823
- nodeCount: number;
824
- depth: number;
825
- types: Record<string, number>;
826
- };
827
- /** Create a deep observable copy of a tree */
828
- declare function cloneDeep<T>(target: T): T;
829
- /** Get or create a node by path */
830
- declare function getOrCreatePath(target: unknown, path: string, creator: () => unknown): unknown;
831
- /** Freeze a node, making it read-only */
832
- declare function freeze(target: unknown): void;
833
- /** Check if a node is frozen */
834
- declare function isFrozen(target: unknown): boolean;
835
- /** Unfreeze a node */
836
- declare function unfreeze(target: unknown): void;
837
-
838
340
  /**
839
341
  * Lifecycle hooks and middleware system
840
342
  * Implements afterCreate, beforeDestroy, afterAttach, beforeDetach, etc.
@@ -1209,4 +711,4 @@ declare function typecheck<T>(type: {
1209
711
  is(v: unknown): v is T;
1210
712
  }, value: unknown): void;
1211
713
 
1212
- export { type CustomTypeOptions$1 as CustomTypeOptions, DatePrimitive as Date, type DynamicReferenceOptions, type IActionRecorder, type IActionRecording, type IAnyComplexType, type IAnyMixin, type IAnyModelType, type IAnyType, type IArrayType, type IDisposer, type IEnumerationType, type IFrozenType, type IHistoryEntry, type IIdentifierNumberType, type IIdentifierType, type IJsonPatch, type ILateType, type ILiteralType, type IMSTArray, type IMSTMap, type IMapType, type IMaybeNullType, type IMaybeType, type IMiddlewareEvent, type IMiddlewareHandler, type IMixin, type IModelType, type IOptionalType, type IReferenceType, type IRefinementType, type IReversibleJsonPatch, type ISafeReferenceType, type ISerializedActionCall, type ISimpleType, type IStateTreeNode, type ITimeTravelManager, type IType, type IUndoManager, type IUndoManagerOptions, type IUnionType, type IValidationContext, type IValidationError, type IValidationResult, type Instance, type MixinConfig, type ModelInstance, type ModelProperties, type ModelSelf, type ReferenceOptions, type SnapshotIn, type SnapshotOut, type UnionOptions, addMiddleware, applyAction, applyPatch, applySnapshot, array, boolean, cast, castToReferenceSnapshot, castToSnapshot, cleanupStaleEntries, clearAllRegistries, clearModelRegistry, clone, cloneDeep, cloneFrozen, compose, createActionRecorder, createTimeTravelManager, createUndoManager, createWithDefaults, custom, types as default, destroy, detach, dynamicReference, enumeration, escapeJsonPath, findAll, findFirst, finite, float, flow, freeze, frozen, getDebugInfo, getEnv, getGlobalStore, getIdentifier, getIdentifierAttribute, getMembers, getModelMetadata, getOrCreate, getOrCreatePath, getParent, getParentOfType, getPath, getPathParts, getRegisteredModelNames, getRegistryStats, getRelativePath, getRoot, getSnapshot, getTreeStats, getType, getTypeName, getValidationError, hasIdentifier, hasParent, haveSameRoot, identifier, identifierNumber, integer, isAlive, isAncestor, isArrayType, isFrozen, isFrozenType, isIdentifierType, isInstanceOf, isLateType, isLiteralType, isMapType, isModelRegistered, isModelType, isOptionalType, isPrimitiveType, isProtected, isReferenceType, isRoot, isStateTreeNode, isType, isUnionType, isValidReference, isValidSnapshot, joinJsonPath, late, lateModel, literal, map, maybe, maybeNull, mixin, model, nullType, nullable, number, onAction, onLifecycleChange, onModelRegistered, onPatch, onSnapshot, optional, printTree, protect, recordActions, recordPatches, reference, refinement, registerModel, resetGlobalStore, resolveIdentifier, resolveModel, resolveModelAsync, resolvePath, safeCreate, safeDynamicReference, safeReference, setGlobalStore, snapshotProcessor, splitJsonPath, string, tryGetParent, tryResolve, tryResolveModel, typecheck, types, undefinedType, unescapeJsonPath, unfreeze, union, unprotect, unregisterModel, walk };
714
+ export { DatePrimitive as Date, type DynamicReferenceOptions, type IActionRecorder, type IActionRecording, IAnyModelType, IAnyType, IArrayType, IDisposer, IEnumerationType, IFrozenType, type IHistoryEntry, IIdentifierNumberType, IIdentifierType, ILateType, ILiteralType, IMapType, IMaybeNullType, IMaybeType, type IMiddlewareEvent, type IMiddlewareHandler, IMixin, IModelType, IOptionalType, IReferenceType, IRefinementType, IReversibleJsonPatch, ISafeReferenceType, type ISerializedActionCall, ISimpleType, type ITimeTravelManager, IType, type IUndoManager, type IUndoManagerOptions, IUnionType, Instance, MixinConfig, ModelProperties, ReferenceOptions, SnapshotIn, UnionOptions, addMiddleware, applyAction, array, boolean, cast, castToReferenceSnapshot, castToSnapshot, clearModelRegistry, cloneFrozen, compose, createActionRecorder, createTimeTravelManager, createUndoManager, createWithDefaults, custom, types as default, dynamicReference, enumeration, escapeJsonPath, finite, float, flow, frozen, getDebugInfo, getIdentifierAttribute, getModelMetadata, getOrCreate, getRegisteredModelNames, getTypeName, getValidationError, hasIdentifier, identifier, identifierNumber, integer, isArrayType, isFrozenType, isIdentifierType, isInstanceOf, isLateType, isLiteralType, isMapType, isModelRegistered, isModelType, isOptionalType, isPrimitiveType, isProtected, isReferenceType, isType, isUnionType, isValidSnapshot, joinJsonPath, late, lateModel, literal, map, maybe, maybeNull, mixin, model, nullType, nullable, number, onModelRegistered, optional, printTree, protect, recordActions, reference, refinement, registerModel, resolveModel, resolveModelAsync, safeCreate, safeDynamicReference, safeReference, snapshotProcessor, splitJsonPath, string, tryResolveModel, typecheck, types, undefinedType, unescapeJsonPath, union, unprotect, unregisterModel };