pinia-react 1.5.0-beta.2 → 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 CHANGED
@@ -1,6 +1,4 @@
1
- import { ComputedRef, DebuggerEvent, EffectScope, Ref, UnwrapRef, WatchOptions, WritableComputedRef } from "@maoism/runtime-core";
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> = { [K in keyof T]?: _DeepPartial<T[K]> };
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
- * 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",
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
- * 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;
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
- type: MutationType.direct;
66
- events: DebuggerEvent;
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
- type: MutationType.patchObject;
74
- events: DebuggerEvent[];
75
- /**
76
- * Object passed to `store.$patch()`.
77
- */
78
- payload: _DeepPartial<UnwrapRef<S>>;
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
- type: MutationType.patchFunction;
86
- events: DebuggerEvent[];
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
- * 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;
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> : { [Name in keyof A]: Name extends string ? _StoreOnActionListenerContext<Store<Id, S, G, A>, Name, A> : never }[keyof A];
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
- * Unique identifier of the store
150
- */
151
- $id: Id;
152
- /**
153
- * Private property defining the pinia the store is attached to.
154
- *
155
- * @internal
156
- */
157
- _p: Pinia;
158
- /**
159
- * Used by devtools plugin to retrieve getters. Removed in production.
160
- *
161
- * @internal
162
- */
163
- _getters?: string[];
164
- /**
165
- * Used (and added) by devtools plugin to detect Setup vs Options API usage.
166
- *
167
- * @internal
168
- */
169
- _isOptionsAPI?: boolean;
170
- /**
171
- * Used by devtools plugin to retrieve properties added with plugins. Removed
172
- * in production. Can be used by the user to add property keys of the store
173
- * that should be displayed in devtools.
174
- */
175
- _customProperties: Set<string>;
176
- /**
177
- * Handles a HMR replacement of this store. Dev Only.
178
- *
179
- * @internal
180
- */
181
- _hotUpdate(useStore: StoreGeneric): void;
182
- /**
183
- * Allows pausing some of the watching mechanisms while the store is being
184
- * patched with a newer version.
185
- *
186
- * @internal
187
- */
188
- _hotUpdating: boolean;
189
- /**
190
- * Payload of the hmr update. Dev only.
191
- *
192
- * @internal
193
- */
194
- _hmrPayload: {
195
- state: string[];
196
- hotState: Ref<StateTree>;
197
- actions: _ActionsTree;
198
- getters: _ActionsTree;
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
- * State of the Store. Setting it will internally call `$patch()` to update the state.
207
- */
208
- $state: UnwrapRef<S> & PiniaCustomStateProperties<S>;
209
- /**
210
- * Applies a state patch to current state. Allows passing nested values
211
- *
212
- * @param partialState - patch to apply to the state
213
- */
214
- $patch(partialState: _DeepPartial<UnwrapRef<S>>): void;
215
- /**
216
- * Group multiple changes into one function. Useful when mutating objects like
217
- * Sets or arrays and applying an object patch isn't practical, e.g. appending
218
- * to an array. The function passed to `$patch()` **must be synchronous**.
219
- *
220
- * @param stateMutator - function that mutates `state`, cannot be asynchronous
221
- */
222
- $patch<F extends (state: UnwrapRef<S>) => any>(stateMutator: ReturnType<F> extends Promise<any> ? never : F): void;
223
- /**
224
- * Resets the store to its initial state by building a new state object.
225
- */
226
- $reset(): void;
227
- /**
228
- * Setups a callback to be called whenever the state changes. It also returns a function to remove the callback. Note
229
- * that when calling `store.$subscribe()` inside of a component, it will be automatically cleaned up when the
230
- * component gets unmounted unless `detached` is set to true.
231
- *
232
- * @param callback - callback passed to the watcher
233
- * @param options - `watch` options + `detached` to detach the subscription from the context (usually a component)
234
- * this is called from. Note that the `flush` option does not affect calls to `store.$patch()`.
235
- * @returns function that removes the watcher
236
- */
237
- $subscribe(callback: SubscriptionCallback<S>, options?: {
238
- detached?: boolean;
239
- } & WatchOptions): () => void;
240
- /**
241
- * Setups a callback to be called every time an action is about to get
242
- * invoked. The callback receives an object with all the relevant information
243
- * of the invoked action:
244
- * - `store`: the store it is invoked on
245
- * - `name`: The name of the action
246
- * - `args`: The parameters passed to the action
247
- *
248
- * On top of these, it receives two functions that allow setting up a callback
249
- * once the action finishes or when it fails.
250
- *
251
- * It also returns a function to remove the callback. Note than when calling
252
- * `store.$onAction()` inside of a component, it will be automatically cleaned
253
- * up when the component gets unmounted unless `detached` is set to true.
254
- *
255
- * @example
256
- *
257
- *```js
258
- *store.$onAction(({ after, onError }) => {
259
- * // Here you could share variables between all of the hooks as well as
260
- * // setting up watchers and clean them up
261
- * after((resolvedValue) => {
262
- * // can be used to cleanup side effects
263
- * . // `resolvedValue` is the value returned by the action, if it's a
264
- * . // Promise, it will be the resolved value instead of the Promise
265
- * })
266
- * onError((error) => {
267
- * // can be used to pass up errors
268
- * })
269
- *})
270
- *```
271
- *
272
- * @param callback - callback called before every action
273
- * @param detached - detach the subscription from the context this is called from
274
- * @returns function that removes the watcher
275
- */
276
- $onAction(callback: StoreOnActionListener<Id, S, G, A>, detached?: boolean): () => void;
277
- /**
278
- * Stops the associated effect scope of the store and remove it from the store
279
- * registry. Plugins can override this method to cleanup any added effects.
280
- * e.g. devtools plugin stops displaying disposed stores from devtools.
281
- * Note this doesn't delete the state of the store, you have to do it manually with
282
- * `delete pinia.state.value[store.$id]` if you want to. If you don't and the
283
- * store is used again, it will reuse the previous state.
284
- */
285
- $dispose(): void;
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> = { [k in keyof A]: A[k] extends ((...args: infer P) => infer R) ? (...args: P) => R : never };
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> = { 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]> };
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> = { [K in keyof G as G[K] extends WritableComputedRef<any> ? K : never]: G[K] extends Readonly<WritableComputedRef<infer R>> ? R : never };
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
- * Returns a store, creates it if necessary.
327
- *
328
- * @param pinia - Pinia instance to retrieve the store
329
- * @param hot - dev only hot module replacement
330
- */
331
- (pinia?: Pinia | null | undefined, hot?: StoreGeneric): Store<Id, S, G, A>;
332
- /**
333
- * Id of the store. Used by map helpers.
334
- */
335
- $id: Id;
336
- /**
337
- * Return to store for use within non-functional components
338
- */
339
- $getStore: () => Store<Id, S, G, A>;
340
- /**
341
- * Dev only pinia for HMR.
342
- *
343
- * @internal
344
- */
345
- _pinia?: Pinia;
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 { [K in keyof SS as SS[K] extends _Method | ComputedRef ? never : K]: any };
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 { [K in keyof SS as SS[K] extends _Method ? K : never]: any };
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 { [K in keyof SS as SS[K] extends ComputedRef ? K : never]: any };
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> = { [K in keyof SS]: UnwrapRef<SS[K]> };
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
- * Unique string key to identify the store across the application.
410
- */
411
- id: Id;
412
- /**
413
- * Function to create a fresh state. **Must be an arrow function** to ensure
414
- * correct typings!
415
- */
416
- state?: () => S;
417
- /**
418
- * Optional object of getters.
419
- */
420
- getters?: G & ThisType<UnwrapRef<S> & _StoreWithGetters<G> & PiniaCustomProperties> & _GettersTree<S>;
421
- /**
422
- * Optional object of actions.
423
- */
424
- actions?: A & ThisType<A & UnwrapRef<S> & _StoreWithState<Id, S, G, A> & _StoreWithGetters<G> & PiniaCustomProperties>;
425
- /**
426
- * Allows hydrating the store during SSR when complex state (like client side only refs) are used in the store
427
- * definition and copying the value from `pinia.state` isn't enough.
428
- *
429
- * @example
430
- * If in your `state`, you use any `customRef`s, any `computed`s, or any `ref`s that have a different value on
431
- * Server and Client, you need to manually hydrate them. e.g., a custom ref that is stored in the local
432
- * storage:
433
- *
434
- * ```ts
435
- * const useStore = defineStore('main', {
436
- * state: () => ({
437
- * n: useLocalStorage('key', 0)
438
- * }),
439
- * hydrate(storeState, initialState) {
440
- * // @ts-expect-error: https://github.com/microsoft/TypeScript/issues/43826
441
- * storeState.n = useLocalStorage('key', 0)
442
- * }
443
- * })
444
- * ```
445
- *
446
- * @param storeState - the current state in the store
447
- * @param initialState - initialState
448
- */
449
- hydrate?(storeState: UnwrapRef<S>, initialState: UnwrapRef<S>): void;
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
- * Extracted actions. Added by useStore(). SHOULD NOT be added by the user when
458
- * creating the store. Can be used in plugins to get the list of actions in a
459
- * store defined with a setup function. Note this is always defined
460
- */
461
- actions?: A;
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
- * Extracted object of actions. Added by useStore() when the store is built
469
- * using the setup API, otherwise uses the one passed to `defineStore()`.
470
- * Defaults to an empty object if no actions are defined.
471
- */
472
- actions: A;
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
- * root state
489
- */
490
- state: Ref<Record<string, StateTree>>;
491
- /**
492
- * Adds a store plugin to extend every store
493
- *
494
- * @param plugin - store plugin to add
495
- */
496
- use(plugin: PiniaPlugin): Pinia;
497
- /**
498
- * Installed store plugins
499
- *
500
- * @internal
501
- */
502
- _p: PiniaPlugin[];
503
- /**
504
- * Effect scope the pinia is attached to
505
- *
506
- * @internal
507
- */
508
- _e: EffectScope;
509
- /**
510
- * Registry of stores used by this pinia.
511
- *
512
- * @internal
513
- */
514
- _s: Map<string, StoreGeneric>;
515
- /**
516
- * Added by `createTestingPinia()` to bypass `useStore(pinia)`.
517
- *
518
- * @internal
519
- */
520
- _testing?: boolean;
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
- * pinia instance.
526
- */
527
- pinia: Pinia;
528
- /**
529
- * Current store being extended.
530
- */
531
- store: Store<Id, S, G, A>;
532
- /**
533
- * Initial options defining the store when calling `defineStore()`.
534
- */
535
- options: DefineStoreOptionsInPlugin<Id, S, G, A>;
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
- * Plugin to extend every store. Returns an object to extend the store or
543
- * nothing.
544
- *
545
- * @param context - Context
546
- */
547
- (context: PiniaPluginContext): Partial<PiniaCustomProperties & PiniaCustomStateProperties> | void;
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
- //#endregion
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
- //#endregion
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
- //#endregion
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 };