fractostate 4.8.4 → 4.8.6
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/cjs/index.js +21 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/src/proxy.js.map +1 -1
- package/dist/cjs/src/store.js +41 -0
- package/dist/cjs/src/store.js.map +1 -1
- package/dist/esm/index.js +21 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/src/proxy.js.map +1 -1
- package/dist/esm/src/store.js +41 -0
- package/dist/esm/src/store.js.map +1 -1
- package/dist/index.d.ts +17 -4
- package/dist/plugins.d.ts +1 -1
- package/dist/types-DgcrW93l.d.ts +288 -0
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
|
-
import { F as FlowDefinition, D as DerivedFlowDefinition, C as ContextGetterOps, a as FlowOptions, A as ActionOpsObject, b as FlowOperations, U as UseFlowOptions } from './types-
|
|
2
|
-
export { c as ArrayOps, B as BaseOps, d as BooleanOps, e as BoundActions, f as FlowAction, g as FlowEffect, h as FlowOpsObject, i as FlowPlugin, N as NumberOps, O as ObjectOps, S as StringOps, T as TypeAwareOps } from './types-
|
|
1
|
+
import { F as FlowDefinition, D as DerivedFlowDefinition, C as ContextGetterOps, a as FlowOptions, A as ActionOpsObject, b as FlowOperations, U as UseFlowOptions } from './types-DgcrW93l.js';
|
|
2
|
+
export { c as ArrayOps, B as BaseOps, d as BooleanOps, e as BoundActions, f as FlowAction, g as FlowEffect, h as FlowOpsObject, i as FlowPlugin, N as NumberOps, O as ObjectOps, S as StringOps, T as TypeAwareOps } from './types-DgcrW93l.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Manually initializes a flow to ensure its effects run immediately.
|
|
6
6
|
* This is useful for flows that need to start working before any component subscribes to them.
|
|
7
7
|
*/
|
|
8
8
|
declare function initFlow<T, A, C>(flow: FlowDefinition<T, A, C>): void;
|
|
9
|
+
/**
|
|
10
|
+
* Executes a list of predefined flows immediately and optimally.
|
|
11
|
+
* Guaranteed to run exactly once per application initialization.
|
|
12
|
+
* Ideal for authentication checks, data pre-fetching, or setting up
|
|
13
|
+
* global state at the root of your application (e.g., in main.tsx).
|
|
14
|
+
*/
|
|
15
|
+
declare function runFlows(flows: FlowDefinition<any, any, any>[]): void;
|
|
9
16
|
/**
|
|
10
17
|
* Clears the entire store, all timers, and runs cleanup for all active flow effects.
|
|
11
18
|
*/
|
|
@@ -20,8 +27,14 @@ declare function defineFlow<T, A extends Record<string, any>, C = A extends {
|
|
|
20
27
|
} ? R : undefined>(key: string, initial: T, options: FlowOptions<NoInfer<T>, any> & {
|
|
21
28
|
actions: {
|
|
22
29
|
__ctx__?: (c: ContextGetterOps<T, Record<string, any>>) => C;
|
|
30
|
+
/**
|
|
31
|
+
* Automatic initialization action.
|
|
32
|
+
* Executed once when the flow is first initialized (e.g., page refresh or first use).
|
|
33
|
+
* Useful for fetching initial data or setting up state before components consume it.
|
|
34
|
+
*/
|
|
35
|
+
__init__?: () => (ops: ActionOpsObject<T, Record<string, any>, C>) => any;
|
|
23
36
|
} & {
|
|
24
|
-
[K in keyof A as K extends "__ctx__" ? never : K]: (...args: any[]) => (ops: ActionOpsObject<T, Record<string, any>, C>) => any;
|
|
37
|
+
[K in keyof A as K extends "__ctx__" | "__init__" ? never : K]: (...args: any[]) => (ops: ActionOpsObject<T, Record<string, any>, C>) => any;
|
|
25
38
|
} & A;
|
|
26
39
|
}): FlowDefinition<T, A, C>;
|
|
27
40
|
declare function defineFlow<T>(key: string, initial: T, options?: FlowOptions<NoInfer<T>, {}>): FlowDefinition<T, {}>;
|
|
@@ -38,4 +51,4 @@ declare function useFlow<K extends string, T = any>(key: K, initial?: T, options
|
|
|
38
51
|
declare function useFlow<T, A, C>(def: FlowDefinition<T, A, C>, options?: UseFlowOptions<T>): [T, FlowOperations<T, A>];
|
|
39
52
|
declare function useFlow<T, R>(def: DerivedFlowDefinition<T, R>): [R, {}];
|
|
40
53
|
|
|
41
|
-
export { ActionOpsObject, ContextGetterOps, DerivedFlowDefinition, FlowDefinition, FlowOperations, FlowOptions, UseFlowOptions, clearAll, defineDerived, defineFlow, getFlow, initFlow, useFlow };
|
|
54
|
+
export { ActionOpsObject, ContextGetterOps, DerivedFlowDefinition, FlowDefinition, FlowOperations, FlowOptions, UseFlowOptions, clearAll, defineDerived, defineFlow, getFlow, initFlow, runFlows, useFlow };
|
package/dist/plugins.d.ts
CHANGED
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core types for FractoState
|
|
3
|
+
*/
|
|
4
|
+
type TypeAwareOps<T, A = any> = [T] extends [null | undefined] ? BaseOps<T, A> : [T] extends [any[]] ? ArrayOps<T[number], A> : [T] extends [number] ? NumberOps<A> : [T] extends [string] ? StringOps<A> : [T] extends [boolean] ? BooleanOps<A> : [NonNullable<T>] extends [object] ? ObjectOps<T, A> : BaseOps<T, A>;
|
|
5
|
+
type FlowOpsObject<T, A = any> = {
|
|
6
|
+
readonly self: TypeAwareOps<T, A>;
|
|
7
|
+
readonly state: T;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Enhanced operations for actions that include the context
|
|
11
|
+
*/
|
|
12
|
+
type ActionOpsObject<T, A = any, C = undefined> = FlowOpsObject<T, A> & {
|
|
13
|
+
readonly ctx: C;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Action structure: (...args) => (ops) => Result
|
|
17
|
+
*/
|
|
18
|
+
type FlowAction<T, A = any, C = undefined> = (...args: any[]) => (ops: ActionOpsObject<T, A, C>) => any;
|
|
19
|
+
/**
|
|
20
|
+
* Transform actions for the component toolbox.
|
|
21
|
+
* Excludes internal __ctx__ property.
|
|
22
|
+
*/
|
|
23
|
+
type BoundActions<A> = {
|
|
24
|
+
[K in keyof A as K extends "__ctx__" | "__init__" ? never : K]: A[K] extends (...args: infer P) => (...inner: any[]) => infer R ? (...args: P) => R : never;
|
|
25
|
+
};
|
|
26
|
+
interface FlowPlugin<T = any, A = any> {
|
|
27
|
+
name: string;
|
|
28
|
+
onInit?: (ctx: {
|
|
29
|
+
key: string;
|
|
30
|
+
initial: T;
|
|
31
|
+
store: any;
|
|
32
|
+
}) => void;
|
|
33
|
+
onUpdate?: (ctx: {
|
|
34
|
+
key: string;
|
|
35
|
+
prev: T;
|
|
36
|
+
next: T;
|
|
37
|
+
store: any;
|
|
38
|
+
}) => void;
|
|
39
|
+
onHydrate?: (ctx: {
|
|
40
|
+
key: string;
|
|
41
|
+
initial: T;
|
|
42
|
+
store: any;
|
|
43
|
+
}) => T | Promise<T> | undefined;
|
|
44
|
+
/** Return methods that will be exposed under ops.self._[pluginName] */
|
|
45
|
+
getOps?: (ctx: {
|
|
46
|
+
key: string;
|
|
47
|
+
store: any;
|
|
48
|
+
}) => Record<string, Function>;
|
|
49
|
+
/** @internal Phantom type for action inference */
|
|
50
|
+
__plugin_actions__?: A;
|
|
51
|
+
}
|
|
52
|
+
interface FlowEffect<T, A = any> {
|
|
53
|
+
/** Function to run on init and when deps change. Can return a cleanup function. */
|
|
54
|
+
run: (ops: FlowOpsObject<T, A>) => void | (() => void) | Promise<void>;
|
|
55
|
+
/** Optional dependencies selector. If omitted, runs only on init */
|
|
56
|
+
deps?: (state: T) => any[];
|
|
57
|
+
}
|
|
58
|
+
interface FlowOptions<T = any, A = any> {
|
|
59
|
+
timeTravel?: boolean;
|
|
60
|
+
maxHistory?: number;
|
|
61
|
+
debounce?: number;
|
|
62
|
+
middleware?: Array<(state: T) => T>;
|
|
63
|
+
plugins?: FlowPlugin<T, A>[];
|
|
64
|
+
effects?: FlowEffect<T, A>[];
|
|
65
|
+
force?: boolean;
|
|
66
|
+
skipEquality?: boolean;
|
|
67
|
+
isUndoRedo?: boolean;
|
|
68
|
+
bypassClone?: boolean;
|
|
69
|
+
/** The name of the component or module performing the update */
|
|
70
|
+
actor?: string;
|
|
71
|
+
/** Raw actions dictionary for internal binding */
|
|
72
|
+
actions?: A;
|
|
73
|
+
}
|
|
74
|
+
interface ContextGetterOps<T, A> {
|
|
75
|
+
state: T;
|
|
76
|
+
initialState: T;
|
|
77
|
+
actions: BoundActions<A>;
|
|
78
|
+
ops: FlowOpsObject<T, A>;
|
|
79
|
+
}
|
|
80
|
+
interface UseFlowOptions<T> extends FlowOptions<T> {
|
|
81
|
+
name?: string;
|
|
82
|
+
}
|
|
83
|
+
interface FlowDefinition<T, A = {}, C = undefined> {
|
|
84
|
+
key: string;
|
|
85
|
+
initial: T;
|
|
86
|
+
options?: FlowOptions<T, A> & {
|
|
87
|
+
actions?: A;
|
|
88
|
+
};
|
|
89
|
+
/** @internal Phantom type for context inference */
|
|
90
|
+
__ctx__?: C;
|
|
91
|
+
}
|
|
92
|
+
interface DerivedFlowDefinition<T, R> {
|
|
93
|
+
key: string;
|
|
94
|
+
source: FlowDefinition<T, any>;
|
|
95
|
+
selector: (state: T) => R;
|
|
96
|
+
}
|
|
97
|
+
interface FlowOperations<T, A = {}> {
|
|
98
|
+
/** The operation object for recursive state manipulation via proxies */
|
|
99
|
+
ops: FlowOpsObject<T, A>;
|
|
100
|
+
/** The actions defined in defineFlow, bound to this specific state instance */
|
|
101
|
+
actions: BoundActions<A>;
|
|
102
|
+
/** Reverts to the previous state in history (if timeTravel is enabled) */
|
|
103
|
+
_undo: () => void;
|
|
104
|
+
/** Reapplies a previously undone state (if timeTravel is enabled) */
|
|
105
|
+
_redo: () => void;
|
|
106
|
+
/** Returns the full history stack for this flow */
|
|
107
|
+
history: T[];
|
|
108
|
+
/** Boolean indicating if an undo operation is currently possible */
|
|
109
|
+
_canUndo: boolean;
|
|
110
|
+
/** Boolean indicating if a redo operation is currently possible */
|
|
111
|
+
_canRedo: boolean;
|
|
112
|
+
/** Forcefully updates the state and records history even if values are identical. Useful for triggering effects or manual snapshots. */
|
|
113
|
+
_set: (val: T | ((prev: T) => T)) => void;
|
|
114
|
+
/** Optimized update: only commits the change if the new value differs from the current one. Saves history space and render cycles. */
|
|
115
|
+
_patch: (val: T | ((prev: T) => T)) => void;
|
|
116
|
+
/** Resets the state back to its initial defined configuration */
|
|
117
|
+
_reset: () => void;
|
|
118
|
+
/** Returns the current flow configuration options */
|
|
119
|
+
cf: FlowOptions<T>;
|
|
120
|
+
/** Boolean indicating if the flow is currently loading data from a hydration plugin (e.g., localStorage) */
|
|
121
|
+
isHydrating: boolean;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Common operations available on every state node.
|
|
125
|
+
* Prefixed with underscores to avoid collisions with your nested data properties.
|
|
126
|
+
*/
|
|
127
|
+
type BaseOps<T, A = any> = {
|
|
128
|
+
/** Forcefully replace the value at this path, ignoring equality checks. Records history. */
|
|
129
|
+
_set: (value: T) => void;
|
|
130
|
+
/** Smart update: only commits the change if the value is different. */
|
|
131
|
+
_patch: (value: T) => void;
|
|
132
|
+
/** Unwraps the proxy and returns the raw value at this specific tree path. */
|
|
133
|
+
_val: T;
|
|
134
|
+
/** Access all actions defined in this flow */
|
|
135
|
+
__actions__: BoundActions<A>;
|
|
136
|
+
/** Persistence control (provided by persist plugin) */
|
|
137
|
+
_persist?: {
|
|
138
|
+
clear: () => void;
|
|
139
|
+
update: () => void;
|
|
140
|
+
refresh: () => Promise<void>;
|
|
141
|
+
getData: () => Promise<T | undefined>;
|
|
142
|
+
};
|
|
143
|
+
/** Reverts to the previous state in history (if timeTravel is enabled) - Global Effect */
|
|
144
|
+
_undo: () => void;
|
|
145
|
+
/** Reapplies a previously undone state (if timeTravel is enabled) - Global Effect */
|
|
146
|
+
_redo: () => void;
|
|
147
|
+
/** Boolean indicating if an undo operation is currently possible */
|
|
148
|
+
_canUndo: boolean;
|
|
149
|
+
/** Boolean indicating if a redo operation is currently possible */
|
|
150
|
+
_canRedo: boolean;
|
|
151
|
+
/** Returns the full history stack for this flow */
|
|
152
|
+
_history: T[];
|
|
153
|
+
};
|
|
154
|
+
/** Operations specific to numeric values */
|
|
155
|
+
type NumberOps<A = any> = BaseOps<number, A> & {
|
|
156
|
+
/** Increment by n (default 1) */
|
|
157
|
+
_increment: (n?: number) => void;
|
|
158
|
+
/** Decrement by n (default 1) */
|
|
159
|
+
_decrement: (n?: number) => void;
|
|
160
|
+
/** Add n to the value */
|
|
161
|
+
_add: (n: number) => void;
|
|
162
|
+
/** Subtract n from the value */
|
|
163
|
+
_subtract: (n: number) => void;
|
|
164
|
+
/** Multiply the value by n */
|
|
165
|
+
_multiply: (n: number) => void;
|
|
166
|
+
/** Divide the value by n */
|
|
167
|
+
_divide: (n: number) => void;
|
|
168
|
+
/** Raise to the power of n */
|
|
169
|
+
_pow: (n: number) => void;
|
|
170
|
+
/** Calculate square root */
|
|
171
|
+
_sqrt: () => void;
|
|
172
|
+
/** Set to absolute value */
|
|
173
|
+
_abs: () => void;
|
|
174
|
+
/** Round to the nearest integer */
|
|
175
|
+
_round: () => void;
|
|
176
|
+
/** Round down to the nearest integer */
|
|
177
|
+
_floor: () => void;
|
|
178
|
+
/** Round up to the nearest integer */
|
|
179
|
+
_ceil: () => void;
|
|
180
|
+
/** Modulo operation */
|
|
181
|
+
_mod: (n: number) => void;
|
|
182
|
+
/** Clamp value between min and max */
|
|
183
|
+
_clamp: (min: number, max: number) => void;
|
|
184
|
+
/** Negate the value */
|
|
185
|
+
_negate: () => void;
|
|
186
|
+
/** Format to fixed precision (updates value to parsed float) */
|
|
187
|
+
_toPrecision: (precision: number) => void;
|
|
188
|
+
};
|
|
189
|
+
/** Operations specific to string values */
|
|
190
|
+
type StringOps<A = any> = BaseOps<string, A> & {
|
|
191
|
+
/** Append a string at the end */
|
|
192
|
+
_append: (s: string) => void;
|
|
193
|
+
/** Prepend a string at the beginning */
|
|
194
|
+
_prepend: (s: string) => void;
|
|
195
|
+
/** Convert value to uppercase */
|
|
196
|
+
_uppercase: () => void;
|
|
197
|
+
/** Convert value to lowercase */
|
|
198
|
+
_lowercase: () => void;
|
|
199
|
+
/** Trim whitespace from both ends */
|
|
200
|
+
_trim: () => void;
|
|
201
|
+
/** Replace first occurrence matching pattern */
|
|
202
|
+
_replace: (pattern: string | RegExp, replacement: string) => void;
|
|
203
|
+
/** Replace all occurrences matching pattern */
|
|
204
|
+
_replaceAll: (pattern: string | RegExp, replacement: string) => void;
|
|
205
|
+
/** Extract substring */
|
|
206
|
+
_substring: (start: number, end?: number) => void;
|
|
207
|
+
/** Extract section of string */
|
|
208
|
+
_slice: (start: number, end?: number) => void;
|
|
209
|
+
/** Capitalize first letter */
|
|
210
|
+
_capitalize: () => void;
|
|
211
|
+
/** Truncate string to length with suffix */
|
|
212
|
+
_truncate: (length: number, suffix?: string) => void;
|
|
213
|
+
/** Pad end of string */
|
|
214
|
+
_padEnd: (length: number, fill?: string) => void;
|
|
215
|
+
/** Pad start of string */
|
|
216
|
+
_padStart: (length: number, fill?: string) => void;
|
|
217
|
+
/** Repeat string count times */
|
|
218
|
+
_repeat: (count: number) => void;
|
|
219
|
+
};
|
|
220
|
+
/** Operations specific to array values */
|
|
221
|
+
type ArrayOps<T, A = any> = BaseOps<T[], A> & {
|
|
222
|
+
/** Add an item to the end of the array */
|
|
223
|
+
_push: (v: T) => void;
|
|
224
|
+
/** Remove and return the last item */
|
|
225
|
+
_pop: () => void;
|
|
226
|
+
/** Remove and return the first item */
|
|
227
|
+
_shift: () => void;
|
|
228
|
+
/** Add an item to the beginning of the array */
|
|
229
|
+
_unshift: (v: T) => void;
|
|
230
|
+
/** Keep only items matching the condition */
|
|
231
|
+
_filter: (fn: (v: T, i: number) => boolean) => void;
|
|
232
|
+
/** Transform every item in the array */
|
|
233
|
+
_map: (fn: (v: T, i: number) => T) => void;
|
|
234
|
+
/** Remove item at a specific index */
|
|
235
|
+
_removeAt: (i: number) => void;
|
|
236
|
+
/** Insert an item at a specific index */
|
|
237
|
+
_insertAt: (i: number, v: T) => void;
|
|
238
|
+
/** Splice the array (items removed/replaced) */
|
|
239
|
+
_splice: (start: number, deleteCount: number, ...items: T[]) => void;
|
|
240
|
+
/** Reverse the array */
|
|
241
|
+
_reverse: () => void;
|
|
242
|
+
/** Sort the array */
|
|
243
|
+
_sort: (compareFn?: (a: T, b: T) => number) => void;
|
|
244
|
+
/** Fill the array with a static value */
|
|
245
|
+
_fill: (value: T, start?: number, end?: number) => void;
|
|
246
|
+
/** Concatenate with another array */
|
|
247
|
+
_concat: (other: T[]) => void;
|
|
248
|
+
/** Remove duplicates */
|
|
249
|
+
_uniq: () => void;
|
|
250
|
+
/** Randomly shuffle the array */
|
|
251
|
+
_shuffle: () => void;
|
|
252
|
+
/** Access item at index (supports negative index) */
|
|
253
|
+
_at: (i: number) => TypeAwareOps<T, A>;
|
|
254
|
+
/** Access the first item */
|
|
255
|
+
_first: () => TypeAwareOps<T, A>;
|
|
256
|
+
/** Access the last item */
|
|
257
|
+
_last: () => TypeAwareOps<T, A>;
|
|
258
|
+
/** Find item by predicate and return its proxy */
|
|
259
|
+
_findBy: (predicate: (item: T, index: number) => boolean) => TypeAwareOps<T, A> | undefined;
|
|
260
|
+
};
|
|
261
|
+
/** Operations specific to object values */
|
|
262
|
+
type ObjectOps<T, A = any> = BaseOps<T, A> & {
|
|
263
|
+
/** Shallow merge the provided object into the current state */
|
|
264
|
+
_merge: (p: Partial<NonNullable<T>>) => void;
|
|
265
|
+
/** Remove a specific key from the object */
|
|
266
|
+
_delete: (k: keyof NonNullable<T>) => void;
|
|
267
|
+
/** Pick only specific keys (removes others) */
|
|
268
|
+
_pick: (keys: (keyof NonNullable<T>)[]) => void;
|
|
269
|
+
/** Omit specific keys */
|
|
270
|
+
_omit: (keys: (keyof NonNullable<T>)[]) => void;
|
|
271
|
+
/** Set default values for undefined keys */
|
|
272
|
+
_defaults: (defaults: Partial<NonNullable<T>>) => void;
|
|
273
|
+
/** Clear all keys (empty object) */
|
|
274
|
+
_clear: () => void;
|
|
275
|
+
/** Deep clone (re-assigns self) */
|
|
276
|
+
_clone: () => void;
|
|
277
|
+
/** Assign properties from source (alias to merge) */
|
|
278
|
+
_assign: (source: Partial<NonNullable<T>>) => void;
|
|
279
|
+
/** Map over values and update */
|
|
280
|
+
_mapValues: (fn: (value: any, key: keyof T) => any) => void;
|
|
281
|
+
} & {
|
|
282
|
+
[K in keyof NonNullable<T>]-?: TypeAwareOps<NonNullable<T>[K], A>;
|
|
283
|
+
};
|
|
284
|
+
type BooleanOps<A = any> = BaseOps<boolean, A> & {
|
|
285
|
+
_toggle: () => void;
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
export type { ActionOpsObject as A, BaseOps as B, ContextGetterOps as C, DerivedFlowDefinition as D, FlowDefinition as F, NumberOps as N, ObjectOps as O, StringOps as S, TypeAwareOps as T, UseFlowOptions as U, FlowOptions as a, FlowOperations as b, ArrayOps as c, BooleanOps as d, BoundActions as e, FlowAction as f, FlowEffect as g, FlowOpsObject as h, FlowPlugin as i };
|
package/package.json
CHANGED
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"types": "./dist/devtools.d.ts"
|
|
47
47
|
},
|
|
48
48
|
"./package.json": "./package.json",
|
|
49
|
-
"./plugins": {
|
|
49
|
+
"./plugins": {
|
|
50
50
|
"default": "./dist/cjs/plugins.js",
|
|
51
51
|
"import": "./dist/esm/plugins.js",
|
|
52
52
|
"require": "./dist/cjs/plugins.js",
|
|
@@ -112,5 +112,5 @@
|
|
|
112
112
|
},
|
|
113
113
|
"type": "module",
|
|
114
114
|
"types": "dist/index.d.ts",
|
|
115
|
-
"version": "4.8.
|
|
115
|
+
"version": "4.8.6"
|
|
116
116
|
}
|