pulse-js-framework 1.4.3 → 1.4.5

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.
@@ -0,0 +1,170 @@
1
+ /**
2
+ * Pulse Framework - Store Type Definitions
3
+ * @module pulse-js-framework/runtime/store
4
+ */
5
+
6
+ import { Pulse } from './pulse';
7
+
8
+ /** Store options */
9
+ export interface StoreOptions {
10
+ persist?: boolean;
11
+ storageKey?: string;
12
+ }
13
+
14
+ /** Base store type - maps state keys to Pulse values */
15
+ export type StoreState<T extends Record<string, unknown>> = {
16
+ [K in keyof T]: Pulse<T[K]>;
17
+ };
18
+
19
+ /** Store methods */
20
+ export interface StoreMethods<T extends Record<string, unknown>> {
21
+ /** Get current state snapshot */
22
+ $getState(): T;
23
+
24
+ /** Set multiple values at once (batched) */
25
+ $setState(updates: Partial<T>): void;
26
+
27
+ /** Reset to initial state */
28
+ $reset(): void;
29
+
30
+ /** Subscribe to all changes, returns unsubscribe */
31
+ $subscribe(callback: (state: T) => void): () => void;
32
+
33
+ /** Access raw Pulse instances */
34
+ $pulses: StoreState<T>;
35
+ }
36
+
37
+ /** Complete store type */
38
+ export type Store<T extends Record<string, unknown>> = StoreState<T> & StoreMethods<T>;
39
+
40
+ /**
41
+ * Create global store
42
+ */
43
+ export declare function createStore<T extends Record<string, unknown>>(
44
+ initialState: T,
45
+ options?: StoreOptions
46
+ ): Store<T>;
47
+
48
+ /** Action function signature */
49
+ export type ActionFn<T extends Record<string, unknown>, Args extends unknown[] = unknown[], R = void> =
50
+ (store: Store<T>, ...args: Args) => R;
51
+
52
+ /** Actions definition object */
53
+ export type ActionsDef<T extends Record<string, unknown>> = {
54
+ [name: string]: ActionFn<T, unknown[], unknown>;
55
+ };
56
+
57
+ /** Bound actions (without store parameter) */
58
+ export type BoundActions<T extends Record<string, unknown>, A extends ActionsDef<T>> = {
59
+ [K in keyof A]: A[K] extends ActionFn<T, infer Args, infer R>
60
+ ? (...args: Args) => R
61
+ : never;
62
+ };
63
+
64
+ /**
65
+ * Create action functions bound to store
66
+ */
67
+ export declare function createActions<
68
+ T extends Record<string, unknown>,
69
+ A extends ActionsDef<T>
70
+ >(store: Store<T>, actions: A): BoundActions<T, A>;
71
+
72
+ /** Getter function signature */
73
+ export type GetterFn<T extends Record<string, unknown>, R = unknown> = (store: Store<T>) => R;
74
+
75
+ /** Getters definition object */
76
+ export type GettersDef<T extends Record<string, unknown>> = {
77
+ [name: string]: GetterFn<T, unknown>;
78
+ };
79
+
80
+ /** Computed getters (as Pulse values) */
81
+ export type ComputedGetters<T extends Record<string, unknown>, G extends GettersDef<T>> = {
82
+ [K in keyof G]: G[K] extends GetterFn<T, infer R> ? Pulse<R> : never;
83
+ };
84
+
85
+ /**
86
+ * Create computed values for store
87
+ */
88
+ export declare function createGetters<
89
+ T extends Record<string, unknown>,
90
+ G extends GettersDef<T>
91
+ >(store: Store<T>, getters: G): ComputedGetters<T, G>;
92
+
93
+ /** Combined stores type */
94
+ export type CombinedStores<S extends Record<string, Store<Record<string, unknown>>>> = {
95
+ [K in keyof S]: S[K];
96
+ };
97
+
98
+ /**
99
+ * Combine multiple stores under namespaces
100
+ */
101
+ export declare function combineStores<S extends Record<string, Store<Record<string, unknown>>>>(
102
+ stores: S
103
+ ): CombinedStores<S>;
104
+
105
+ /** Module definition */
106
+ export interface ModuleDef<T extends Record<string, unknown>> {
107
+ state: T;
108
+ actions?: ActionsDef<T>;
109
+ getters?: GettersDef<T>;
110
+ }
111
+
112
+ /** Modules configuration */
113
+ export type ModulesDef = {
114
+ [namespace: string]: ModuleDef<Record<string, unknown>>;
115
+ };
116
+
117
+ /** Module store type */
118
+ export type ModuleStore<M extends ModuleDef<Record<string, unknown>>> =
119
+ Store<M['state']> &
120
+ (M['actions'] extends ActionsDef<M['state']> ? BoundActions<M['state'], M['actions']> : {}) &
121
+ (M['getters'] extends GettersDef<M['state']> ? ComputedGetters<M['state'], M['getters']> : {});
122
+
123
+ /** Root module store type */
124
+ export type RootModuleStore<D extends ModulesDef> = {
125
+ [K in keyof D]: ModuleStore<D[K]>;
126
+ } & {
127
+ $getState(): { [K in keyof D]: D[K]['state'] };
128
+ $reset(): void;
129
+ };
130
+
131
+ /**
132
+ * Create module-based store (Vuex-like)
133
+ */
134
+ export declare function createModuleStore<D extends ModulesDef>(
135
+ modules: D
136
+ ): RootModuleStore<D>;
137
+
138
+ /** Plugin function */
139
+ export type StorePlugin<T extends Record<string, unknown>> = (store: Store<T>) => Store<T>;
140
+
141
+ /**
142
+ * Apply plugin to store
143
+ */
144
+ export declare function usePlugin<T extends Record<string, unknown>>(
145
+ store: Store<T>,
146
+ plugin: StorePlugin<T>
147
+ ): Store<T>;
148
+
149
+ /** Store with history plugin */
150
+ export interface HistoryStore<T extends Record<string, unknown>> extends Store<T> {
151
+ $undo(): void;
152
+ $redo(): void;
153
+ $canUndo(): boolean;
154
+ $canRedo(): boolean;
155
+ }
156
+
157
+ /**
158
+ * Logger plugin - logs state changes to console
159
+ */
160
+ export declare function loggerPlugin<T extends Record<string, unknown>>(
161
+ store: Store<T>
162
+ ): Store<T>;
163
+
164
+ /**
165
+ * History plugin - enables undo/redo
166
+ */
167
+ export declare function historyPlugin<T extends Record<string, unknown>>(
168
+ store: Store<T>,
169
+ maxHistory?: number
170
+ ): HistoryStore<T>;