]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
refactor: export internal types
authorEduardo San Martin Morote <posva13@gmail.com>
Fri, 24 Dec 2021 14:17:42 +0000 (15:17 +0100)
committerEduardo San Martin Morote <posva13@gmail.com>
Fri, 24 Dec 2021 14:17:42 +0000 (15:17 +0100)
packages/pinia/src/index.ts
packages/pinia/src/store.ts
packages/pinia/src/types.ts

index 99fbd400e91b162090d7df37e934fdce579ee10e..58b1f4a7f39625e1ab6b49c9653aa788f6cf139a 100644 (file)
@@ -27,6 +27,7 @@ export type {
   _StoreWithState,
   StoreProperties,
   StoreOnActionListener,
+  _StoreOnActionListenerContext,
   StoreOnActionListenerContext,
   SubscriptionCallback,
   SubscriptionCallbackMutation,
@@ -40,6 +41,14 @@ export type {
   DefineStoreOptions,
   DefineSetupStoreOptions,
   DefineStoreOptionsInPlugin,
+  _ExtractActionsFromSetupStore,
+  _ExtractGettersFromSetupStore,
+  _ExtractStateFromSetupStore,
+  _DeepPartial,
+  _ExtractActionsFromSetupStore_Keys,
+  _ExtractGettersFromSetupStore_Keys,
+  _ExtractStateFromSetupStore_Keys,
+  _UnwrapAll,
 } from './types'
 export { MutationType } from './types'
 
index 33415b3dbc2414c1890e2a89648779619279de17..5a23b475375a59b48df2bea46f110ecbb5ba3e88 100644 (file)
@@ -26,7 +26,7 @@ import {
 import {
   StateTree,
   SubscriptionCallback,
-  DeepPartial,
+  _DeepPartial,
   isPlainObject,
   Store,
   _Method,
@@ -55,7 +55,7 @@ type _ArrayType<AT> = AT extends Array<infer T> ? T : never
 
 function mergeReactiveObjects<T extends StateTree>(
   target: T,
-  patchToApply: DeepPartial<T>
+  patchToApply: _DeepPartial<T>
 ): T {
   // no need to go through symbols because they cannot be serialized anyway
   for (const key in patchToApply) {
@@ -250,10 +250,10 @@ function createSetupStore<
   const hotState = ref({} as S)
 
   function $patch(stateMutation: (state: UnwrapRef<S>) => void): void
-  function $patch(partialState: DeepPartial<UnwrapRef<S>>): void
+  function $patch(partialState: _DeepPartial<UnwrapRef<S>>): void
   function $patch(
     partialStateOrMutator:
-      | DeepPartial<UnwrapRef<S>>
+      | _DeepPartial<UnwrapRef<S>>
       | ((state: UnwrapRef<S>) => void)
   ): void {
     let subscriptionMutation: SubscriptionCallbackMutation<S>
index ab21cd3a889fc2a8857a53c04571a158c63fccd3..5b2d3dad7f0f0be7ae258cbc9908823a4e5d33db 100644 (file)
@@ -32,7 +32,7 @@ export function isPlainObject(
  *
  * @internal
  */
-export type DeepPartial<T> = { [K in keyof T]?: DeepPartial<T[K]> }
+export type _DeepPartial<T> = { [K in keyof T]?: _DeepPartial<T[K]> }
 // type DeepReadonly<T> = { readonly [P in keyof T]: DeepReadonly<T[P]> }
 
 // TODO: can we change these to numbers?
@@ -112,7 +112,7 @@ export interface SubscriptionCallbackMutationPatchObject<S>
   /**
    * Object passed to `store.$patch()`.
    */
-  payload: DeepPartial<S>
+  payload: _DeepPartial<S>
 }
 
 /**
@@ -142,8 +142,6 @@ export type SubscriptionCallbackMutation<S> =
   | SubscriptionCallbackMutationPatchObject<S>
   | SubscriptionCallbackMutationPatchFunction
 
-export type UnwrapPromise<T> = T extends Promise<infer V> ? V : T
-
 /**
  * Callback of a subscription
  */
@@ -164,8 +162,13 @@ export type SubscriptionCallback<S> = (
 /**
  * Actual type for {@link StoreOnActionListenerContext}. Exists for refactoring
  * purposes. For internal use only.
+ * @internal
  */
-interface _StoreOnActionListenerContext<Store, ActionName extends string, A> {
+export interface _StoreOnActionListenerContext<
+  Store,
+  ActionName extends string,
+  A
+> {
   /**
    * Name of the action
    */
@@ -191,12 +194,12 @@ interface _StoreOnActionListenerContext<Store, ActionName extends string, A> {
   after: (
     callback: A extends Record<ActionName, _Method>
       ? (
-          resolvedReturn: UnwrapPromise<ReturnType<A[ActionName]>>
+          resolvedReturn: Awaited<ReturnType<A[ActionName]>>
           // allow the after callback to override the return value
         ) =>
           | void
           | ReturnType<A[ActionName]>
-          | UnwrapPromise<ReturnType<A[ActionName]>>
+          | Awaited<ReturnType<A[ActionName]>>
       : () => void
   ) => void
 
@@ -328,7 +331,7 @@ export interface _StoreWithState<
    *
    * @param partialState - patch to apply to the state
    */
-  $patch(partialState: DeepPartial<UnwrapRef<S>>): void
+  $patch(partialState: _DeepPartial<UnwrapRef<S>>): void
 
   /**
    * Group multiple changes into one function. Useful when mutating objects like
@@ -544,30 +547,34 @@ export type _GettersTree<S extends StateTree> = Record<
 export type _ActionsTree = Record<string, _Method>
 
 /**
+ * Type that enables refactoring through IDE.
  * @internal
  */
-type _ExtractStateFromSetupStore_Keys<SS> = keyof {
+export type _ExtractStateFromSetupStore_Keys<SS> = keyof {
   [K in keyof SS as SS[K] extends _Method | ComputedRef ? never : K]: any
 }
 
 /**
+ * Type that enables refactoring through IDE.
  * @internal
  */
-type _ExtractActionsFromSetupStore_Keys<SS> = keyof {
+export type _ExtractActionsFromSetupStore_Keys<SS> = keyof {
   [K in keyof SS as SS[K] extends _Method ? K : never]: any
 }
 
 /**
+ * Type that enables refactoring through IDE.
  * @internal
  */
-type _ExtractGettersFromSetupStore_Keys<SS> = keyof {
+export type _ExtractGettersFromSetupStore_Keys<SS> = keyof {
   [K in keyof SS as SS[K] extends ComputedRef ? K : never]: any
 }
 
 /**
+ * Type that enables refactoring through IDE.
  * @internal
  */
-type _UnwrapAll<SS> = { [K in keyof SS]: UnwrapRef<SS[K]> }
+export type _UnwrapAll<SS> = { [K in keyof SS]: UnwrapRef<SS[K]> }
 
 /**
  * @internal