pinia-react 1.5.0-beta.3 → 1.5.0-beta.4
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.ts +365 -353
- package/dist/index.js +367 -2232
- package/dist/index.js.map +1 -0
- package/package.json +7 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
//#region src/types.d.ts
|
|
1
|
+
import { UnwrapRef, Ref, DebuggerEvent, WatchOptions, ComputedRef, WritableComputedRef, EffectScope } from '@maoism/runtime-core';
|
|
4
2
|
|
|
5
3
|
/**
|
|
6
4
|
* Generic state of a Store
|
|
@@ -11,50 +9,52 @@ type StateTree = Record<PropertyKey, any>;
|
|
|
11
9
|
*
|
|
12
10
|
* For internal use **only**
|
|
13
11
|
*/
|
|
14
|
-
type _DeepPartial<T> = {
|
|
12
|
+
type _DeepPartial<T> = {
|
|
13
|
+
[K in keyof T]?: _DeepPartial<T[K]>;
|
|
14
|
+
};
|
|
15
15
|
/**
|
|
16
16
|
* Possible types for SubscriptionCallback
|
|
17
17
|
*/
|
|
18
18
|
declare enum MutationType {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Direct mutation of the state:
|
|
21
|
+
*
|
|
22
|
+
* - `store.name = 'new name'`
|
|
23
|
+
* - `store.$state.name = 'new name'`
|
|
24
|
+
* - `store.list.push('new item')`
|
|
25
|
+
*/
|
|
26
|
+
direct = "direct",
|
|
27
|
+
/**
|
|
28
|
+
* Mutated the state with `$patch` and an object
|
|
29
|
+
*
|
|
30
|
+
* - `store.$patch({ name: 'newName' })`
|
|
31
|
+
*/
|
|
32
|
+
patchObject = "patch object",
|
|
33
|
+
/**
|
|
34
|
+
* Mutated the state with `$patch` and a function
|
|
35
|
+
*
|
|
36
|
+
* - `store.$patch(state => state.name = 'newName')`
|
|
37
|
+
*/
|
|
38
|
+
patchFunction = "patch function"
|
|
39
39
|
}
|
|
40
40
|
/**
|
|
41
41
|
* Base type for the context passed to a subscription callback. Internal type.
|
|
42
42
|
*/
|
|
43
43
|
interface _SubscriptionCallbackMutationBase {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
44
|
+
/**
|
|
45
|
+
* Type of the mutation.
|
|
46
|
+
*/
|
|
47
|
+
type: MutationType;
|
|
48
|
+
/**
|
|
49
|
+
* `id` of the store doing the mutation.
|
|
50
|
+
*/
|
|
51
|
+
storeId: string;
|
|
52
|
+
/**
|
|
53
|
+
* 🔴 DEV ONLY, DO NOT use for production code. Different mutation calls. Comes from
|
|
54
|
+
* https://vuejs.org/guide/extras/reactivity-in-depth.html#reactivity-debugging and allows to track mutations in
|
|
55
|
+
* devtools and plugins **during development only**.
|
|
56
|
+
*/
|
|
57
|
+
events?: DebuggerEvent[] | DebuggerEvent;
|
|
58
58
|
}
|
|
59
59
|
/**
|
|
60
60
|
* Context passed to a subscription callback when directly mutating the state of
|
|
@@ -62,28 +62,28 @@ interface _SubscriptionCallbackMutationBase {
|
|
|
62
62
|
* newValue`.
|
|
63
63
|
*/
|
|
64
64
|
interface SubscriptionCallbackMutationDirect extends _SubscriptionCallbackMutationBase {
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
type: MutationType.direct;
|
|
66
|
+
events: DebuggerEvent;
|
|
67
67
|
}
|
|
68
68
|
/**
|
|
69
69
|
* Context passed to a subscription callback when `store.$patch()` is called
|
|
70
70
|
* with an object.
|
|
71
71
|
*/
|
|
72
72
|
interface SubscriptionCallbackMutationPatchObject<S> extends _SubscriptionCallbackMutationBase {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
73
|
+
type: MutationType.patchObject;
|
|
74
|
+
events: DebuggerEvent[];
|
|
75
|
+
/**
|
|
76
|
+
* Object passed to `store.$patch()`.
|
|
77
|
+
*/
|
|
78
|
+
payload: _DeepPartial<UnwrapRef<S>>;
|
|
79
79
|
}
|
|
80
80
|
/**
|
|
81
81
|
* Context passed to a subscription callback when `store.$patch()` is called
|
|
82
82
|
* with a function.
|
|
83
83
|
*/
|
|
84
84
|
interface SubscriptionCallbackMutationPatchFunction extends _SubscriptionCallbackMutationBase {
|
|
85
|
-
|
|
86
|
-
|
|
85
|
+
type: MutationType.patchFunction;
|
|
86
|
+
events: DebuggerEvent[];
|
|
87
87
|
}
|
|
88
88
|
/**
|
|
89
89
|
* Context object passed to a subscription callback.
|
|
@@ -97,7 +97,7 @@ type SubscriptionCallback<S> = (
|
|
|
97
97
|
* Object with information relative to the store mutation that triggered the
|
|
98
98
|
* subscription.
|
|
99
99
|
*/
|
|
100
|
-
mutation: SubscriptionCallbackMutation<S>,
|
|
100
|
+
mutation: SubscriptionCallbackMutation<S>,
|
|
101
101
|
/**
|
|
102
102
|
* State of the store when the subscription is triggered. Same as
|
|
103
103
|
* `store.$state`.
|
|
@@ -109,34 +109,36 @@ state: UnwrapRef<S>) => void;
|
|
|
109
109
|
* For internal use **only**
|
|
110
110
|
*/
|
|
111
111
|
interface _StoreOnActionListenerContext<Store, ActionName extends string, A> {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
112
|
+
/**
|
|
113
|
+
* Name of the action
|
|
114
|
+
*/
|
|
115
|
+
name: ActionName;
|
|
116
|
+
/**
|
|
117
|
+
* Store that is invoking the action
|
|
118
|
+
*/
|
|
119
|
+
store: Store;
|
|
120
|
+
/**
|
|
121
|
+
* Parameters passed to the action
|
|
122
|
+
*/
|
|
123
|
+
args: A extends Record<ActionName, _Method> ? Parameters<A[ActionName]> : unknown[];
|
|
124
|
+
/**
|
|
125
|
+
* Sets up a hook once the action is finished. It receives the return value
|
|
126
|
+
* of the action, if it's a Promise, it will be unwrapped.
|
|
127
|
+
*/
|
|
128
|
+
after: (callback: A extends Record<ActionName, _Method> ? (resolvedReturn: Awaited<ReturnType<A[ActionName]>>) => void : () => void) => void;
|
|
129
|
+
/**
|
|
130
|
+
* Sets up a hook if the action fails. Return `false` to catch the error and
|
|
131
|
+
* stop it from propagating.
|
|
132
|
+
*/
|
|
133
|
+
onError: (callback: (error: unknown) => void) => void;
|
|
134
134
|
}
|
|
135
135
|
/**
|
|
136
136
|
* Context object passed to callbacks of `store.$onAction(context => {})`
|
|
137
137
|
* TODO: should have only the Id, the Store and Actions to generate the proper object
|
|
138
138
|
*/
|
|
139
|
-
type StoreOnActionListenerContext<Id extends string, S extends StateTree, G, A> = _ActionsTree extends A ? _StoreOnActionListenerContext<StoreGeneric, string, _ActionsTree> : {
|
|
139
|
+
type StoreOnActionListenerContext<Id extends string, S extends StateTree, G, A> = _ActionsTree extends A ? _StoreOnActionListenerContext<StoreGeneric, string, _ActionsTree> : {
|
|
140
|
+
[Name in keyof A]: Name extends string ? _StoreOnActionListenerContext<Store<Id, S, G, A>, Name, A> : never;
|
|
141
|
+
}[keyof A];
|
|
140
142
|
/**
|
|
141
143
|
* Argument of `store.$onAction()`
|
|
142
144
|
*/
|
|
@@ -145,144 +147,144 @@ type StoreOnActionListener<Id extends string, S extends StateTree, G, A> = (cont
|
|
|
145
147
|
* Properties of a store.
|
|
146
148
|
*/
|
|
147
149
|
interface StoreProperties<Id extends string> {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
150
|
+
/**
|
|
151
|
+
* Unique identifier of the store
|
|
152
|
+
*/
|
|
153
|
+
$id: Id;
|
|
154
|
+
/**
|
|
155
|
+
* Private property defining the pinia the store is attached to.
|
|
156
|
+
*
|
|
157
|
+
* @internal
|
|
158
|
+
*/
|
|
159
|
+
_p: Pinia;
|
|
160
|
+
/**
|
|
161
|
+
* Used by devtools plugin to retrieve getters. Removed in production.
|
|
162
|
+
*
|
|
163
|
+
* @internal
|
|
164
|
+
*/
|
|
165
|
+
_getters?: string[];
|
|
166
|
+
/**
|
|
167
|
+
* Used (and added) by devtools plugin to detect Setup vs Options API usage.
|
|
168
|
+
*
|
|
169
|
+
* @internal
|
|
170
|
+
*/
|
|
171
|
+
_isOptionsAPI?: boolean;
|
|
172
|
+
/**
|
|
173
|
+
* Used by devtools plugin to retrieve properties added with plugins. Removed
|
|
174
|
+
* in production. Can be used by the user to add property keys of the store
|
|
175
|
+
* that should be displayed in devtools.
|
|
176
|
+
*/
|
|
177
|
+
_customProperties: Set<string>;
|
|
178
|
+
/**
|
|
179
|
+
* Handles a HMR replacement of this store. Dev Only.
|
|
180
|
+
*
|
|
181
|
+
* @internal
|
|
182
|
+
*/
|
|
183
|
+
_hotUpdate(useStore: StoreGeneric): void;
|
|
184
|
+
/**
|
|
185
|
+
* Allows pausing some of the watching mechanisms while the store is being
|
|
186
|
+
* patched with a newer version.
|
|
187
|
+
*
|
|
188
|
+
* @internal
|
|
189
|
+
*/
|
|
190
|
+
_hotUpdating: boolean;
|
|
191
|
+
/**
|
|
192
|
+
* Payload of the hmr update. Dev only.
|
|
193
|
+
*
|
|
194
|
+
* @internal
|
|
195
|
+
*/
|
|
196
|
+
_hmrPayload: {
|
|
197
|
+
state: string[];
|
|
198
|
+
hotState: Ref<StateTree>;
|
|
199
|
+
actions: _ActionsTree;
|
|
200
|
+
getters: _ActionsTree;
|
|
201
|
+
};
|
|
200
202
|
}
|
|
201
203
|
/**
|
|
202
204
|
* Base store with state and functions. Should not be used directly.
|
|
203
205
|
*/
|
|
204
206
|
interface _StoreWithState<Id extends string, S extends StateTree, G, A> extends StoreProperties<Id> {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
207
|
+
/**
|
|
208
|
+
* State of the Store. Setting it will internally call `$patch()` to update the state.
|
|
209
|
+
*/
|
|
210
|
+
$state: UnwrapRef<S> & PiniaCustomStateProperties<S>;
|
|
211
|
+
/**
|
|
212
|
+
* Applies a state patch to current state. Allows passing nested values
|
|
213
|
+
*
|
|
214
|
+
* @param partialState - patch to apply to the state
|
|
215
|
+
*/
|
|
216
|
+
$patch(partialState: _DeepPartial<UnwrapRef<S>>): void;
|
|
217
|
+
/**
|
|
218
|
+
* Group multiple changes into one function. Useful when mutating objects like
|
|
219
|
+
* Sets or arrays and applying an object patch isn't practical, e.g. appending
|
|
220
|
+
* to an array. The function passed to `$patch()` **must be synchronous**.
|
|
221
|
+
*
|
|
222
|
+
* @param stateMutator - function that mutates `state`, cannot be asynchronous
|
|
223
|
+
*/
|
|
224
|
+
$patch<F extends (state: UnwrapRef<S>) => any>(stateMutator: ReturnType<F> extends Promise<any> ? never : F): void;
|
|
225
|
+
/**
|
|
226
|
+
* Resets the store to its initial state by building a new state object.
|
|
227
|
+
*/
|
|
228
|
+
$reset(): void;
|
|
229
|
+
/**
|
|
230
|
+
* Setups a callback to be called whenever the state changes. It also returns a function to remove the callback. Note
|
|
231
|
+
* that when calling `store.$subscribe()` inside of a component, it will be automatically cleaned up when the
|
|
232
|
+
* component gets unmounted unless `detached` is set to true.
|
|
233
|
+
*
|
|
234
|
+
* @param callback - callback passed to the watcher
|
|
235
|
+
* @param options - `watch` options + `detached` to detach the subscription from the context (usually a component)
|
|
236
|
+
* this is called from. Note that the `flush` option does not affect calls to `store.$patch()`.
|
|
237
|
+
* @returns function that removes the watcher
|
|
238
|
+
*/
|
|
239
|
+
$subscribe(callback: SubscriptionCallback<S>, options?: {
|
|
240
|
+
detached?: boolean;
|
|
241
|
+
} & WatchOptions): () => void;
|
|
242
|
+
/**
|
|
243
|
+
* Setups a callback to be called every time an action is about to get
|
|
244
|
+
* invoked. The callback receives an object with all the relevant information
|
|
245
|
+
* of the invoked action:
|
|
246
|
+
* - `store`: the store it is invoked on
|
|
247
|
+
* - `name`: The name of the action
|
|
248
|
+
* - `args`: The parameters passed to the action
|
|
249
|
+
*
|
|
250
|
+
* On top of these, it receives two functions that allow setting up a callback
|
|
251
|
+
* once the action finishes or when it fails.
|
|
252
|
+
*
|
|
253
|
+
* It also returns a function to remove the callback. Note than when calling
|
|
254
|
+
* `store.$onAction()` inside of a component, it will be automatically cleaned
|
|
255
|
+
* up when the component gets unmounted unless `detached` is set to true.
|
|
256
|
+
*
|
|
257
|
+
* @example
|
|
258
|
+
*
|
|
259
|
+
*```js
|
|
260
|
+
*store.$onAction(({ after, onError }) => {
|
|
261
|
+
* // Here you could share variables between all of the hooks as well as
|
|
262
|
+
* // setting up watchers and clean them up
|
|
263
|
+
* after((resolvedValue) => {
|
|
264
|
+
* // can be used to cleanup side effects
|
|
265
|
+
* . // `resolvedValue` is the value returned by the action, if it's a
|
|
266
|
+
* . // Promise, it will be the resolved value instead of the Promise
|
|
267
|
+
* })
|
|
268
|
+
* onError((error) => {
|
|
269
|
+
* // can be used to pass up errors
|
|
270
|
+
* })
|
|
271
|
+
*})
|
|
272
|
+
*```
|
|
273
|
+
*
|
|
274
|
+
* @param callback - callback called before every action
|
|
275
|
+
* @param detached - detach the subscription from the context this is called from
|
|
276
|
+
* @returns function that removes the watcher
|
|
277
|
+
*/
|
|
278
|
+
$onAction(callback: StoreOnActionListener<Id, S, G, A>, detached?: boolean): () => void;
|
|
279
|
+
/**
|
|
280
|
+
* Stops the associated effect scope of the store and remove it from the store
|
|
281
|
+
* registry. Plugins can override this method to cleanup any added effects.
|
|
282
|
+
* e.g. devtools plugin stops displaying disposed stores from devtools.
|
|
283
|
+
* Note this doesn't delete the state of the store, you have to do it manually with
|
|
284
|
+
* `delete pinia.state.value[store.$id]` if you want to. If you don't and the
|
|
285
|
+
* store is used again, it will reuse the previous state.
|
|
286
|
+
*/
|
|
287
|
+
$dispose(): void;
|
|
286
288
|
}
|
|
287
289
|
/**
|
|
288
290
|
* Generic type for a function that can infer arguments and return type
|
|
@@ -294,7 +296,9 @@ type _Method = (...args: any[]) => any;
|
|
|
294
296
|
* Store augmented for actions. For internal usage only.
|
|
295
297
|
* For internal use **only**
|
|
296
298
|
*/
|
|
297
|
-
type _StoreWithActions<A> = {
|
|
299
|
+
type _StoreWithActions<A> = {
|
|
300
|
+
[k in keyof A]: A[k] extends (...args: infer P) => infer R ? (...args: P) => R : never;
|
|
301
|
+
};
|
|
298
302
|
/**
|
|
299
303
|
* Store augmented with getters. For internal usage only.
|
|
300
304
|
* For internal use **only**
|
|
@@ -303,11 +307,15 @@ type _StoreWithGetters<G> = _StoreWithGetters_Readonly<G> & _StoreWithGetters_Wr
|
|
|
303
307
|
/**
|
|
304
308
|
* Store augmented with readonly getters. For internal usage **only**.
|
|
305
309
|
*/
|
|
306
|
-
type _StoreWithGetters_Readonly<G> = {
|
|
310
|
+
type _StoreWithGetters_Readonly<G> = {
|
|
311
|
+
readonly [K in keyof G as G[K] extends (...args: any[]) => any ? K : ComputedRef extends G[K] ? K : never]: G[K] extends (...args: any[]) => infer R ? R : UnwrapRef<G[K]>;
|
|
312
|
+
};
|
|
307
313
|
/**
|
|
308
314
|
* Store augmented with writable getters. For internal usage **only**.
|
|
309
315
|
*/
|
|
310
|
-
type _StoreWithGetters_Writable<G> = {
|
|
316
|
+
type _StoreWithGetters_Writable<G> = {
|
|
317
|
+
[K in keyof G as G[K] extends WritableComputedRef<any> ? K : never]: G[K] extends Readonly<WritableComputedRef<infer R>> ? R : never;
|
|
318
|
+
};
|
|
311
319
|
/**
|
|
312
320
|
* Store type to build a store.
|
|
313
321
|
*/
|
|
@@ -322,36 +330,38 @@ type StoreGeneric = Store<string, StateTree, _GettersTree<StateTree>, _ActionsTr
|
|
|
322
330
|
* Return type of `defineStore()`. Function that allows instantiating a store.
|
|
323
331
|
*/
|
|
324
332
|
interface StoreDefinition<Id extends string = string, S extends StateTree = StateTree, G = _GettersTree<S>, A = _ActionsTree> {
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
333
|
+
/**
|
|
334
|
+
* Returns a store, creates it if necessary.
|
|
335
|
+
*
|
|
336
|
+
* @param pinia - Pinia instance to retrieve the store
|
|
337
|
+
* @param hot - dev only hot module replacement
|
|
338
|
+
*/
|
|
339
|
+
(pinia?: Pinia | null | undefined, hot?: StoreGeneric): Store<Id, S, G, A>;
|
|
340
|
+
/**
|
|
341
|
+
* Id of the store. Used by map helpers.
|
|
342
|
+
*/
|
|
343
|
+
$id: Id;
|
|
344
|
+
/**
|
|
345
|
+
* Return to store for use within non-functional components
|
|
346
|
+
*/
|
|
347
|
+
$getStore: () => Store<Id, S, G, A>;
|
|
348
|
+
/**
|
|
349
|
+
* Dev only pinia for HMR.
|
|
350
|
+
*
|
|
351
|
+
* @internal
|
|
352
|
+
*/
|
|
353
|
+
_pinia?: Pinia;
|
|
346
354
|
}
|
|
347
355
|
/**
|
|
348
356
|
* Interface to be extended by the user when they add properties through plugins.
|
|
349
357
|
*/
|
|
350
|
-
interface PiniaCustomProperties<Id extends string = string, S extends StateTree = StateTree, G = _GettersTree<S>, A = _ActionsTree> {
|
|
358
|
+
interface PiniaCustomProperties<Id extends string = string, S extends StateTree = StateTree, G = _GettersTree<S>, A = _ActionsTree> {
|
|
359
|
+
}
|
|
351
360
|
/**
|
|
352
361
|
* Properties that are added to every `store.$state` by `pinia.use()`.
|
|
353
362
|
*/
|
|
354
|
-
interface PiniaCustomStateProperties<S extends StateTree = StateTree> {
|
|
363
|
+
interface PiniaCustomStateProperties<S extends StateTree = StateTree> {
|
|
364
|
+
}
|
|
355
365
|
/**
|
|
356
366
|
* Type of an object of Getters that infers the argument. For internal usage only.
|
|
357
367
|
* For internal use **only**
|
|
@@ -366,22 +376,30 @@ type _ActionsTree = Record<string, _Method>;
|
|
|
366
376
|
* Type that enables refactoring through IDE.
|
|
367
377
|
* For internal use **only**
|
|
368
378
|
*/
|
|
369
|
-
type _ExtractStateFromSetupStore_Keys<SS> = keyof {
|
|
379
|
+
type _ExtractStateFromSetupStore_Keys<SS> = keyof {
|
|
380
|
+
[K in keyof SS as SS[K] extends _Method | ComputedRef ? never : K]: any;
|
|
381
|
+
};
|
|
370
382
|
/**
|
|
371
383
|
* Type that enables refactoring through IDE.
|
|
372
384
|
* For internal use **only**
|
|
373
385
|
*/
|
|
374
|
-
type _ExtractActionsFromSetupStore_Keys<SS> = keyof {
|
|
386
|
+
type _ExtractActionsFromSetupStore_Keys<SS> = keyof {
|
|
387
|
+
[K in keyof SS as SS[K] extends _Method ? K : never]: any;
|
|
388
|
+
};
|
|
375
389
|
/**
|
|
376
390
|
* Type that enables refactoring through IDE.
|
|
377
391
|
* For internal use **only**
|
|
378
392
|
*/
|
|
379
|
-
type _ExtractGettersFromSetupStore_Keys<SS> = keyof {
|
|
393
|
+
type _ExtractGettersFromSetupStore_Keys<SS> = keyof {
|
|
394
|
+
[K in keyof SS as SS[K] extends ComputedRef ? K : never]: any;
|
|
395
|
+
};
|
|
380
396
|
/**
|
|
381
397
|
* Type that enables refactoring through IDE.
|
|
382
398
|
* For internal use **only**
|
|
383
399
|
*/
|
|
384
|
-
type _UnwrapAll<SS> = {
|
|
400
|
+
type _UnwrapAll<SS> = {
|
|
401
|
+
[K in keyof SS]: UnwrapRef<SS[K]>;
|
|
402
|
+
};
|
|
385
403
|
/**
|
|
386
404
|
* For internal use **only**
|
|
387
405
|
*/
|
|
@@ -405,77 +423,73 @@ type DefineStoreOptionsBase<S extends StateTree, Store> = {};
|
|
|
405
423
|
* augment stores with the plugin API. @see {@link DefineStoreOptionsBase}.
|
|
406
424
|
*/
|
|
407
425
|
interface DefineStoreOptions<Id extends string, S extends StateTree, G extends _GettersTree<S>, A> extends DefineStoreOptionsBase<S, Store<Id, S, G, A>> {
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
426
|
+
/**
|
|
427
|
+
* Unique string key to identify the store across the application.
|
|
428
|
+
*/
|
|
429
|
+
id: Id;
|
|
430
|
+
/**
|
|
431
|
+
* Function to create a fresh state. **Must be an arrow function** to ensure
|
|
432
|
+
* correct typings!
|
|
433
|
+
*/
|
|
434
|
+
state?: () => S;
|
|
435
|
+
/**
|
|
436
|
+
* Optional object of getters.
|
|
437
|
+
*/
|
|
438
|
+
getters?: G & ThisType<UnwrapRef<S> & _StoreWithGetters<G> & PiniaCustomProperties> & _GettersTree<S>;
|
|
439
|
+
/**
|
|
440
|
+
* Optional object of actions.
|
|
441
|
+
*/
|
|
442
|
+
actions?: A & ThisType<A & UnwrapRef<S> & _StoreWithState<Id, S, G, A> & _StoreWithGetters<G> & PiniaCustomProperties>;
|
|
443
|
+
/**
|
|
444
|
+
* Allows hydrating the store during SSR when complex state (like client side only refs) are used in the store
|
|
445
|
+
* definition and copying the value from `pinia.state` isn't enough.
|
|
446
|
+
*
|
|
447
|
+
* @example
|
|
448
|
+
* If in your `state`, you use any `customRef`s, any `computed`s, or any `ref`s that have a different value on
|
|
449
|
+
* Server and Client, you need to manually hydrate them. e.g., a custom ref that is stored in the local
|
|
450
|
+
* storage:
|
|
451
|
+
*
|
|
452
|
+
* ```ts
|
|
453
|
+
* const useStore = defineStore('main', {
|
|
454
|
+
* state: () => ({
|
|
455
|
+
* n: useLocalStorage('key', 0)
|
|
456
|
+
* }),
|
|
457
|
+
* hydrate(storeState, initialState) {
|
|
458
|
+
* // @ts-expect-error: https://github.com/microsoft/TypeScript/issues/43826
|
|
459
|
+
* storeState.n = useLocalStorage('key', 0)
|
|
460
|
+
* }
|
|
461
|
+
* })
|
|
462
|
+
* ```
|
|
463
|
+
*
|
|
464
|
+
* @param storeState - the current state in the store
|
|
465
|
+
* @param initialState - initialState
|
|
466
|
+
*/
|
|
467
|
+
hydrate?(storeState: UnwrapRef<S>, initialState: UnwrapRef<S>): void;
|
|
450
468
|
}
|
|
451
469
|
/**
|
|
452
470
|
* Options parameter of `defineStore()` for setup stores. Can be extended to
|
|
453
471
|
* augment stores with the plugin API. @see {@link DefineStoreOptionsBase}.
|
|
454
472
|
*/
|
|
455
473
|
interface DefineSetupStoreOptions<Id extends string, S extends StateTree, G, A> extends DefineStoreOptionsBase<S, Store<Id, S, G, A>> {
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
474
|
+
/**
|
|
475
|
+
* Extracted actions. Added by useStore(). SHOULD NOT be added by the user when
|
|
476
|
+
* creating the store. Can be used in plugins to get the list of actions in a
|
|
477
|
+
* store defined with a setup function. Note this is always defined
|
|
478
|
+
*/
|
|
479
|
+
actions?: A;
|
|
462
480
|
}
|
|
463
481
|
/**
|
|
464
482
|
* Available `options` when creating a pinia plugin.
|
|
465
483
|
*/
|
|
466
484
|
interface DefineStoreOptionsInPlugin<Id extends string, S extends StateTree, G extends _GettersTree<S>, A> extends Omit<DefineStoreOptions<Id, S, G, A>, 'id' | 'actions'> {
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
485
|
+
/**
|
|
486
|
+
* Extracted object of actions. Added by useStore() when the store is built
|
|
487
|
+
* using the setup API, otherwise uses the one passed to `defineStore()`.
|
|
488
|
+
* Defaults to an empty object if no actions are defined.
|
|
489
|
+
*/
|
|
490
|
+
actions: A;
|
|
473
491
|
}
|
|
474
|
-
|
|
475
|
-
* Utility type. For internal use **only**
|
|
476
|
-
*/
|
|
477
|
-
//#endregion
|
|
478
|
-
//#region src/rootStore.d.ts
|
|
492
|
+
|
|
479
493
|
/**
|
|
480
494
|
* Get the currently active pinia if there is any.
|
|
481
495
|
*/
|
|
@@ -484,76 +498,74 @@ declare const getActivePinia: () => Pinia | undefined;
|
|
|
484
498
|
* Every application must own its own pinia to be able to create stores
|
|
485
499
|
*/
|
|
486
500
|
interface Pinia {
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
501
|
+
/**
|
|
502
|
+
* root state
|
|
503
|
+
*/
|
|
504
|
+
state: Ref<Record<string, StateTree>>;
|
|
505
|
+
/**
|
|
506
|
+
* Adds a store plugin to extend every store
|
|
507
|
+
*
|
|
508
|
+
* @param plugin - store plugin to add
|
|
509
|
+
*/
|
|
510
|
+
use(plugin: PiniaPlugin): Pinia;
|
|
511
|
+
/**
|
|
512
|
+
* Installed store plugins
|
|
513
|
+
*
|
|
514
|
+
* @internal
|
|
515
|
+
*/
|
|
516
|
+
_p: PiniaPlugin[];
|
|
517
|
+
/**
|
|
518
|
+
* Effect scope the pinia is attached to
|
|
519
|
+
*
|
|
520
|
+
* @internal
|
|
521
|
+
*/
|
|
522
|
+
_e: EffectScope;
|
|
523
|
+
/**
|
|
524
|
+
* Registry of stores used by this pinia.
|
|
525
|
+
*
|
|
526
|
+
* @internal
|
|
527
|
+
*/
|
|
528
|
+
_s: Map<string, StoreGeneric>;
|
|
529
|
+
/**
|
|
530
|
+
* Added by `createTestingPinia()` to bypass `useStore(pinia)`.
|
|
531
|
+
*
|
|
532
|
+
* @internal
|
|
533
|
+
*/
|
|
534
|
+
_testing?: boolean;
|
|
521
535
|
}
|
|
522
536
|
declare function setActivePinia(_pinia: Pinia): void;
|
|
523
537
|
type PiniaPluginContext<Id extends string = string, S extends StateTree = StateTree, G extends _GettersTree<S> = _GettersTree<S>, A = _ActionsTree> = {
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
538
|
+
/**
|
|
539
|
+
* pinia instance.
|
|
540
|
+
*/
|
|
541
|
+
pinia: Pinia;
|
|
542
|
+
/**
|
|
543
|
+
* Current store being extended.
|
|
544
|
+
*/
|
|
545
|
+
store: Store<Id, S, G, A>;
|
|
546
|
+
/**
|
|
547
|
+
* Initial options defining the store when calling `defineStore()`.
|
|
548
|
+
*/
|
|
549
|
+
options: DefineStoreOptionsInPlugin<Id, S, G, A>;
|
|
536
550
|
};
|
|
537
551
|
/**
|
|
538
552
|
* Plugin to extend every store.
|
|
539
553
|
*/
|
|
540
554
|
interface PiniaPlugin {
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
555
|
+
/**
|
|
556
|
+
* Plugin to extend every store. Returns an object to extend the store or
|
|
557
|
+
* nothing.
|
|
558
|
+
*
|
|
559
|
+
* @param context - Context
|
|
560
|
+
*/
|
|
561
|
+
(context: PiniaPluginContext): Partial<PiniaCustomProperties & PiniaCustomStateProperties> | void;
|
|
548
562
|
}
|
|
549
|
-
|
|
550
|
-
//#region src/createPinia.d.ts
|
|
563
|
+
|
|
551
564
|
/**
|
|
552
565
|
* Creates a Pinia instance to be used by the application
|
|
553
566
|
*/
|
|
554
567
|
declare function createPinia(): Pinia;
|
|
555
|
-
|
|
556
|
-
//#region src/store.d.ts
|
|
568
|
+
|
|
557
569
|
/**
|
|
558
570
|
* Creates a `useStore` function that retrieves the store instance
|
|
559
571
|
*
|
|
@@ -561,5 +573,5 @@ declare function createPinia(): Pinia;
|
|
|
561
573
|
* @param options - options to define the store
|
|
562
574
|
*/
|
|
563
575
|
declare function defineStore<Id extends string, S extends StateTree = {}, G extends _GettersTree<S> = {}, A = {}>(id: Id, options: Omit<DefineStoreOptions<Id, S, G, A>, 'id'>): StoreDefinition<Id, S, G, A>;
|
|
564
|
-
|
|
565
|
-
export { type DefineSetupStoreOptions, type DefineStoreOptions, type DefineStoreOptionsBase, type DefineStoreOptionsInPlugin, MutationType, type Pinia, type PiniaCustomProperties, type PiniaCustomStateProperties, type PiniaPlugin, type PiniaPluginContext, type StateTree, type Store, type StoreDefinition, type StoreGeneric, type StoreOnActionListener, type StoreOnActionListenerContext, type StoreProperties, type SubscriptionCallback, type SubscriptionCallbackMutation, type SubscriptionCallbackMutationDirect, type SubscriptionCallbackMutationPatchFunction, type SubscriptionCallbackMutationPatchObject, type _ActionsTree, type _DeepPartial, type _ExtractActionsFromSetupStore, type _ExtractActionsFromSetupStore_Keys, type _ExtractGettersFromSetupStore, type _ExtractGettersFromSetupStore_Keys, type _ExtractStateFromSetupStore, type _ExtractStateFromSetupStore_Keys, type _GettersTree, type _Method, type _StoreOnActionListenerContext, type _StoreWithActions, type _StoreWithGetters, type _StoreWithState, type _SubscriptionCallbackMutationBase, type _UnwrapAll, createPinia, defineStore, getActivePinia, setActivePinia };
|
|
576
|
+
|
|
577
|
+
export { type DefineSetupStoreOptions, type DefineStoreOptions, type DefineStoreOptionsBase, type DefineStoreOptionsInPlugin, MutationType, type Pinia, type PiniaCustomProperties, type PiniaCustomStateProperties, type PiniaPlugin, type PiniaPluginContext, type StateTree, type Store, type StoreDefinition, type StoreGeneric, type StoreOnActionListener, type StoreOnActionListenerContext, type StoreProperties, type SubscriptionCallback, type SubscriptionCallbackMutation, type SubscriptionCallbackMutationDirect, type SubscriptionCallbackMutationPatchFunction, type SubscriptionCallbackMutationPatchObject, type _ActionsTree, type _DeepPartial, type _ExtractActionsFromSetupStore, type _ExtractActionsFromSetupStore_Keys, type _ExtractGettersFromSetupStore, type _ExtractGettersFromSetupStore_Keys, type _ExtractStateFromSetupStore, type _ExtractStateFromSetupStore_Keys, type _GettersTree, type _Method, type _StoreOnActionListenerContext, type _StoreWithActions, type _StoreWithGetters, type _StoreWithState, type _SubscriptionCallbackMutationBase, type _UnwrapAll, createPinia, defineStore, getActivePinia, setActivePinia };
|