pinia-react 1.5.2-beta.1 β 1.5.2-beta.2
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 +2 -1
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
package/dist/index.d.ts
CHANGED
|
@@ -417,7 +417,8 @@ type _ExtractGettersFromSetupStore<SS> = SS extends undefined | void ? {} : Pick
|
|
|
417
417
|
* stores. Extend this interface if you want to add custom options to both kinds
|
|
418
418
|
* of stores.
|
|
419
419
|
*/
|
|
420
|
-
|
|
420
|
+
declare interface DefineStoreOptionsBase<S extends StateTree, Store> {
|
|
421
|
+
}
|
|
421
422
|
/**
|
|
422
423
|
* Options parameter of `defineStore()` for option stores. Can be extended to
|
|
423
424
|
* augment stores with the plugin API. @see {@link DefineStoreOptionsBase}.
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/createPinia.ts","../src/rootStore.ts","../src/store.ts","../src/subscription.ts","../src/types.ts","../src/utils.ts"],"sourcesContent":["import { effectScope, markRaw, type Ref, ref } from '@maoism/runtime-core'\nimport { type Pinia, setActivePinia } from './rootStore'\nimport type { StateTree, StoreGeneric } from './types'\n\n/**\n * Creates a Pinia instance to be used by the application\n */\nexport function createPinia(): Pinia {\n const scope = effectScope(true)\n\n const state = scope.run<Ref<Record<string, StateTree>>>(() => ref<Record<string, StateTree>>({}))!\n\n const _p: Pinia['_p'] = []\n\n const pinia: Pinia = markRaw({\n use(plugin) {\n _p.push(plugin)\n return this\n },\n _p,\n _e: scope,\n _s: new Map<string, StoreGeneric>(),\n state\n })\n\n setActivePinia(pinia)\n\n return pinia\n}\n","import type { EffectScope, Ref } from '@maoism/runtime-core'\nimport type {\n _ActionsTree,\n _GettersTree,\n DefineStoreOptionsInPlugin,\n PiniaCustomProperties,\n PiniaCustomStateProperties,\n StateTree,\n Store,\n StoreGeneric\n} from './types'\n\n/**\n * Get the currently active pinia if there is any.\n */\nexport const getActivePinia = () => activePinia\n\n/**\n * Every application must own its own pinia to be able to create stores\n */\nexport interface Pinia {\n /**\n * root state\n */\n state: Ref<Record<string, StateTree>>\n\n /**\n * Adds a store plugin to extend every store\n *\n * @param plugin - store plugin to add\n */\n use(plugin: PiniaPlugin): Pinia\n\n /**\n * Installed store plugins\n *\n * @internal\n */\n _p: PiniaPlugin[]\n\n /**\n * Effect scope the pinia is attached to\n *\n * @internal\n */\n _e: EffectScope\n\n /**\n * Registry of stores used by this pinia.\n *\n * @internal\n */\n _s: Map<string, StoreGeneric>\n\n /**\n * Added by `createTestingPinia()` to bypass `useStore(pinia)`.\n *\n * @internal\n */\n _testing?: boolean\n}\n\nexport let activePinia: Pinia | undefined\n\nexport function setActivePinia(_pinia: Pinia) {\n activePinia = _pinia\n}\n\nexport type PiniaPluginContext<\n Id extends string = string,\n S extends StateTree = StateTree,\n G extends _GettersTree<S> = _GettersTree<S>,\n A /* extends _ActionsTree */ = _ActionsTree\n> = {\n /**\n * pinia instance.\n */\n pinia: Pinia\n /**\n * Current store being extended.\n */\n store: Store<Id, S, G, A>\n\n /**\n * Initial options defining the store when calling `defineStore()`.\n */\n options: DefineStoreOptionsInPlugin<Id, S, G, A>\n}\n\n/**\n * Plugin to extend every store.\n */\nexport interface PiniaPlugin {\n /**\n * Plugin to extend every store. Returns an object to extend the store or\n * nothing.\n *\n * @param context - Context\n */\n (context: PiniaPluginContext): Partial<PiniaCustomProperties & PiniaCustomStateProperties> | void\n}\n","import {\n activeEffect,\n type ComputedRef,\n computed,\n type DebuggerEvent,\n type EffectScope,\n effectScope,\n markRaw,\n nextTick,\n ReactiveEffect,\n reactive,\n toRaw,\n toRefs,\n type UnwrapRef,\n type WatchOptions,\n watch\n} from '@maoism/runtime-core'\nimport { useCallback, useEffect, useId, useRef, useSyncExternalStore } from 'react'\nimport { activePinia, type Pinia, setActivePinia } from './rootStore'\nimport { addSubscription, triggerSubscriptions } from './subscription'\nimport {\n type _ActionsTree,\n type _DeepPartial,\n type _GettersTree,\n type _Method,\n type _StoreWithState,\n type DefineSetupStoreOptions,\n type DefineStoreOptions,\n type DefineStoreOptionsInPlugin,\n type Fn,\n MutationType,\n type StateTree,\n type Store,\n type StoreDefinition,\n type StoreOnActionListener,\n type SubscriptionCallback,\n type SubscriptionCallbackMutation\n} from './types'\nimport { mergeReactiveObjects, noop } from './utils'\n\ntype _SetType<AT> = AT extends Set<infer T> ? T : never\n/**\n * Marks a function as an action for `$onAction`\n * @internal\n */\nconst ACTION_MARKER = Symbol()\n/**\n * Action name symbol. Allows to add a name to an action after defining it\n * @internal\n */\nconst ACTION_NAME = Symbol()\n/**\n * Function type extended with action markers\n * @internal\n */\ninterface MarkedAction<Fn extends _Method = _Method> {\n (...args: Parameters<Fn>): ReturnType<Fn>\n [ACTION_MARKER]: boolean\n [ACTION_NAME]: string\n}\n\nconst { assign } = Object\n\nfunction createOptionsStore<Id extends string, S extends StateTree, G extends _GettersTree<S>, A extends _ActionsTree>(\n id: Id,\n options: DefineStoreOptions<Id, S, G, A>,\n pinia: Pinia\n): Store<Id, S, G, A> {\n const { state, actions, getters } = options\n\n const initialState: StateTree | undefined = pinia.state.value[id]\n\n let store: Store<Id, S, G, A>\n\n function setup() {\n if (!initialState) {\n pinia.state.value[id] = state ? state() : {}\n }\n\n const localState = toRefs(pinia.state.value[id])\n\n return assign(\n localState,\n actions,\n Object.keys(getters || {}).reduce(\n (computedGetters, name) => {\n if (name in localState) {\n console.warn(\n `[π]: A getter cannot have the same name as another state property. Rename one of them. Found with \"${name}\" in store \"${id}\".`\n )\n }\n\n computedGetters[name] = markRaw(\n computed(() => {\n setActivePinia(pinia)\n // it was created just before\n const store = pinia._s.get(id)!\n // @ts-expect-error\n return getters![name].call(store, store)\n })\n )\n return computedGetters\n },\n {} as Record<string, ComputedRef>\n )\n )\n }\n\n store = createSetupStore(id, setup, options, pinia)\n\n return store as any\n}\n\nfunction createSetupStore<\n Id extends string,\n SS extends Record<any, unknown>,\n S extends StateTree,\n G extends Record<string, _Method>,\n A extends _ActionsTree\n>(\n $id: Id,\n setup: (helpers: SetupStoreHelpers) => SS,\n options: DefineSetupStoreOptions<Id, S, G, A> | DefineStoreOptions<Id, S, G, A> = {},\n pinia: Pinia\n): Store<Id, S, G, A> {\n let scope!: EffectScope\n\n const optionsForPlugin: DefineStoreOptionsInPlugin<Id, S, G, A> = assign({ actions: {} as A }, options)\n\n const $subscribeOptions: WatchOptions = { deep: true }\n\n // internal state\n let isListening: boolean // set to true at the end\n let isSyncListening: boolean // set to true at the end\n const subscriptions: Set<SubscriptionCallback<S>> = new Set()\n const actionSubscriptions: Set<StoreOnActionListener<Id, S, G, A>> = new Set()\n const debuggerEvents: DebuggerEvent[] | DebuggerEvent = []\n // const initialState = pinia.state.value[$id] as UnwrapRef<S> | undefined\n\n let activeListener: symbol | undefined\n function $patch(stateMutation: (state: UnwrapRef<S>) => void): void\n function $patch(partialState: _DeepPartial<UnwrapRef<S>>): void\n function $patch(partialStateOrMutator: _DeepPartial<UnwrapRef<S>> | ((state: UnwrapRef<S>) => void)): void {\n let subscriptionMutation: SubscriptionCallbackMutation<S>\n isListening = isSyncListening = false\n // reset the debugger events since patches are sync\n /* istanbul ignore else */\n // if (__DEV__) {\n // debuggerEvents = []\n // }\n if (typeof partialStateOrMutator === 'function') {\n partialStateOrMutator(pinia.state.value[$id] as UnwrapRef<S>)\n subscriptionMutation = {\n type: MutationType.patchFunction,\n storeId: $id,\n events: debuggerEvents as DebuggerEvent[]\n }\n } else {\n mergeReactiveObjects(pinia.state.value[$id], partialStateOrMutator)\n subscriptionMutation = {\n type: MutationType.patchObject,\n payload: partialStateOrMutator,\n storeId: $id,\n events: debuggerEvents as DebuggerEvent[]\n }\n }\n activeListener = Symbol()\n const myListenerId = activeListener\n nextTick().then(() => {\n if (activeListener === myListenerId) {\n isListening = true\n }\n })\n isSyncListening = true\n // because we paused the watcher, we need to manually call the subscriptions\n triggerSubscriptions(subscriptions, subscriptionMutation, pinia.state.value[$id] as UnwrapRef<S>)\n }\n\n const $reset = function $reset(this: _StoreWithState<Id, S, G, A>) {\n const { state } = options as DefineStoreOptions<Id, S, G, A>\n const newState: _DeepPartial<UnwrapRef<S>> = state ? state() : {}\n // we use a patch to group all changes into one single subscription\n this.$patch(($state) => {\n // @ts-expect-error: FIXME: shouldn't error?\n assign($state, newState)\n })\n }\n\n /**\n * Helper that wraps function so it can be tracked with $onAction\n * @param fn - action to wrap\n * @param name - name of the action\n */\n const action = <Fn extends _Method>(fn: Fn, name: string = ''): Fn => {\n if (ACTION_MARKER in fn) {\n // we ensure the name is set from the returned function\n ;(fn as unknown as MarkedAction<Fn>)[ACTION_NAME] = name\n return fn\n }\n\n const wrappedAction = function (this: any) {\n setActivePinia(pinia)\n const args = Array.from(arguments)\n\n const afterCallbackSet: Set<(resolvedReturn: any) => any> = new Set()\n const onErrorCallbackSet: Set<(error: unknown) => unknown> = new Set()\n function after(callback: _SetType<typeof afterCallbackSet>) {\n afterCallbackSet.add(callback)\n }\n function onError(callback: _SetType<typeof onErrorCallbackSet>) {\n onErrorCallbackSet.add(callback)\n }\n\n // @ts-expect-error\n triggerSubscriptions(actionSubscriptions, {\n args,\n name: wrappedAction[ACTION_NAME],\n store,\n after,\n onError\n })\n\n let ret: unknown\n try {\n ret = fn.apply(this && this.$id === $id ? this : store, args)\n // handle sync errors\n } catch (error) {\n triggerSubscriptions(onErrorCallbackSet, error)\n throw error\n }\n\n if (ret instanceof Promise) {\n return ret\n .then((value) => {\n triggerSubscriptions(afterCallbackSet, value)\n return value\n })\n .catch((error) => {\n triggerSubscriptions(onErrorCallbackSet, error)\n return Promise.reject(error)\n })\n }\n\n // trigger after callbacks\n triggerSubscriptions(afterCallbackSet, ret)\n return ret\n } as MarkedAction<Fn>\n\n wrappedAction[ACTION_MARKER] = true\n wrappedAction[ACTION_NAME] = name // will be set later\n\n // @ts-expect-error: we are intentionally limiting the returned type to just Fn\n // because all the added properties are internals that are exposed through `$onAction()` only\n return wrappedAction\n }\n\n const partialStore = {\n _p: pinia,\n // _s: scope,\n $id,\n $onAction: addSubscription.bind(null, activeComponentCleanUp, actionSubscriptions),\n $patch,\n $reset,\n $subscribe(callback, options = {}) {\n const removeSubscription = addSubscription([[]], subscriptions, callback, options.detached, () => stopWatcher())\n const stopWatcher = scope.run(() =>\n watch(\n () => pinia.state.value[$id] as UnwrapRef<S>,\n (state) => {\n if (options.flush === 'sync' ? isSyncListening : isListening) {\n callback(\n {\n storeId: $id,\n type: MutationType.direct,\n events: debuggerEvents as unknown as DebuggerEvent\n },\n state\n )\n }\n },\n assign({}, $subscribeOptions, options)\n )\n )!\n\n return removeSubscription\n }\n // $dispose\n } as _StoreWithState<Id, S, G, A>\n\n const store: Store<Id, S, G, A> = reactive(partialStore) as unknown as Store<Id, S, G, A>\n\n // store the partial store now so the setup of stores can instantiate each other before they are finished without\n // creating infinite loops.\n pinia._s.set($id, store as Store)\n\n scope = effectScope()\n const setupStore = scope.run(() => setup({ action }))\n\n // overwrite existing actions to support $onAction\n for (const key in setupStore) {\n const prop = setupStore[key]\n\n if (typeof prop === 'function') {\n const actionValue = action(prop as _Method, key)\n // this a hot module replacement store because the hotUpdate method needs\n // @ts-expect-error\n setupStore[key] = actionValue\n\n // list actions so they can be used in plugins\n // @ts-expect-error\n optionsForPlugin.actions[key] = prop\n }\n }\n\n assign(store, setupStore)\n // allows retrieving reactive objects with `storeToRefs()`. Must be called after assigning to the reactive object.\n // Make `storeToRefs()` work with `reactive()` #799\n assign(toRaw(store), setupStore)\n\n // use this instead of a computed with setter to be able to create it anywhere\n // without linking the computed lifespan to wherever the store is first\n // created.\n Object.defineProperty(store, '$state', {\n get: () => pinia.state.value[$id],\n set: (state) => {\n $patch(($state) => {\n // @ts-expect-error: FIXME: shouldn't error?\n assign($state, state)\n })\n }\n })\n\n // apply all plugins\n pinia._p.forEach((extender) => {\n assign(\n store,\n scope.run(() =>\n extender({\n store: store as Store,\n pinia,\n options: optionsForPlugin\n })\n )!\n )\n })\n\n isListening = true\n isSyncListening = true\n return store\n}\n\nexport interface SetupStoreHelpers {\n /**\n * Helper that wraps function so it can be tracked with $onAction when the\n * action is called **within the store**. This helper is rarely needed in\n * applications. It's intended for advanced use cases like Pinia Colada.\n *\n * @param fn - action to wrap\n * @param name - name of the action. Will be picked up by the store at creation\n */\n action: <Fn extends _Method>(fn: Fn, name?: string) => Fn\n}\n\nconst activeComponentCleanUp: [Fn[]] = [[]]\n\n/**\n * Creates a `useStore` function that retrieves the store instance\n *\n * @param id - id of the store (must be unique)\n * @param options - options to define the store\n */\nexport function defineStore<\n Id extends string,\n S extends StateTree = {},\n G extends _GettersTree<S> = {},\n // cannot extends ActionsTree because we loose the typings\n A /* extends ActionsTree */ = {}\n>(id: Id, options: Omit<DefineStoreOptions<Id, S, G, A>, 'id'>): StoreDefinition<Id, S, G, A> {\n const effectMap = new WeakMap<[string], ReactiveEffect>()\n const subscribeMap = new WeakMap<[string], Fn>()\n const cleanUpMap = new WeakMap<[string], Fn[]>()\n\n function useStore(pinia?: Pinia | null): Store<Id, S, G, A> {\n if (pinia) setActivePinia(pinia)\n if (!activePinia) {\n throw new Error(\n `[π]: \"getActivePinia()\" was called but there was no active Pinia. Are you trying to use a store before calling \"createPinia()\"?\\n`\n )\n }\n pinia = activePinia!\n\n const lastEffect = activeEffect.value\n activeEffect.value = undefined\n\n if (!pinia._s.has(id)) createOptionsStore(id, options as any, pinia)\n activeEffect.value = lastEffect\n\n const store = pinia._s.get(id)!\n const _id = useRef<[string]>([useId()])\n const storeSnapshotRef = useRef({ ...store })\n const isCollectDep = useRef(false)\n\n if (!cleanUpMap.get(_id.current)) {\n cleanUpMap.set(_id.current, [])\n }\n\n activeComponentCleanUp[0] = cleanUpMap.get(_id.current)!\n\n useEffect(() => {\n activeComponentCleanUp[0] = cleanUpMap.get(_id.current)!\n return () => {\n cleanUpMap.get(_id.current)!.forEach((fn) => {\n fn()\n })\n }\n }, [])\n\n const subscribe = useCallback((onStoreChange: () => void) => {\n subscribeMap.set(_id.current, onStoreChange)\n\n return () => {\n // θΏιε°±θ¦θ°η¨ζΈ
ι€ε―δ½η¨ηζζε½ζ°γ\n const effect = effectMap.get(_id.current)\n if (effect) effect.stop()\n subscribeMap.delete(_id.current)\n effectMap.delete(_id.current)\n }\n }, [])\n\n useSyncExternalStore(\n subscribe,\n () => storeSnapshotRef.current,\n () => storeSnapshotRef.current\n )\n\n let effect = effectMap.get(_id.current)\n if (!effect) {\n const fn = () => {\n const onStoreChange = subscribeMap.get(_id.current)\n if (!isCollectDep.current) {\n storeSnapshotRef.current = { ...store }\n onStoreChange?.()\n }\n }\n\n effect = new ReactiveEffect(fn, noop, () => {\n if (effect?.dirty) effect.run()\n })\n activeEffect.value = effect\n isCollectDep.current = true\n effect.run()\n effectMap.set(_id.current, effect)\n isCollectDep.current = false\n }\n\n return store as Store<Id, S, G, A>\n }\n\n useStore.$id = id\n useStore.$getStore = (pinia?: Pinia | null) => {\n if (pinia) setActivePinia(pinia)\n pinia = activePinia!\n if (!pinia._s.has(id)) createOptionsStore(id, options as any, pinia)\n const store = pinia._s.get(id)!\n return store as Store<Id, S, G, A>\n }\n return useStore\n}\n","import type { _Method, Fn } from './types'\n\nexport const noop = () => {}\n\nexport function addSubscription<T extends _Method>(\n activeComponentCleanUp: [Fn[]],\n subscriptions: Set<T>,\n callback: T,\n detached?: boolean,\n onCleanup: () => void = noop\n) {\n subscriptions.add(callback)\n\n const removeSubscription = () => {\n subscriptions.delete(callback)\n onCleanup()\n }\n\n if (!detached) {\n activeComponentCleanUp[0].push(removeSubscription)\n }\n\n return removeSubscription\n}\n\nexport function triggerSubscriptions<T extends _Method>(subscriptions: Set<T>, ...args: Parameters<T>) {\n subscriptions.forEach((callback) => {\n callback(...args)\n })\n}\n","import type {\n ComputedRef,\n DebuggerEvent,\n Ref,\n UnwrapRef,\n WatchOptions,\n WritableComputedRef\n} from '@maoism/runtime-core'\nimport type { Pinia } from './rootStore'\n\n/**\n * Generic state of a Store\n */\nexport type StateTree = Record<PropertyKey, any>\n\nexport function isPlainObject<S extends StateTree>(value: S | unknown): value is S\nexport function isPlainObject(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n o: any\n): o is StateTree {\n return (\n o &&\n typeof o === 'object' &&\n Object.prototype.toString.call(o) === '[object Object]' &&\n typeof o.toJSON !== 'function'\n )\n}\n\n/**\n * Recursive `Partial<T>`. Used by {@link Store['$patch']}.\n *\n * For internal use **only**\n */\nexport type _DeepPartial<T> = { [K in keyof T]?: _DeepPartial<T[K]> }\n// type DeepReadonly<T> = { readonly [P in keyof T]: DeepReadonly<T[P]> }\n\n// TODO: can we change these to numbers?\n/**\n * Possible types for SubscriptionCallback\n */\nexport enum MutationType {\n /**\n * Direct mutation of the state:\n *\n * - `store.name = 'new name'`\n * - `store.$state.name = 'new name'`\n * - `store.list.push('new item')`\n */\n direct = 'direct',\n\n /**\n * Mutated the state with `$patch` and an object\n *\n * - `store.$patch({ name: 'newName' })`\n */\n patchObject = 'patch object',\n\n /**\n * Mutated the state with `$patch` and a function\n *\n * - `store.$patch(state => state.name = 'newName')`\n */\n patchFunction = 'patch function'\n\n // maybe reset? for $state = {} and $reset\n}\n\n/**\n * Base type for the context passed to a subscription callback. Internal type.\n */\nexport interface _SubscriptionCallbackMutationBase {\n /**\n * Type of the mutation.\n */\n type: MutationType\n\n /**\n * `id` of the store doing the mutation.\n */\n storeId: string\n\n /**\n * π΄ DEV ONLY, DO NOT use for production code. Different mutation calls. Comes from\n * https://vuejs.org/guide/extras/reactivity-in-depth.html#reactivity-debugging and allows to track mutations in\n * devtools and plugins **during development only**.\n */\n events?: DebuggerEvent[] | DebuggerEvent\n}\n\n/**\n * Context passed to a subscription callback when directly mutating the state of\n * a store with `store.someState = newValue` or `store.$state.someState =\n * newValue`.\n */\nexport interface SubscriptionCallbackMutationDirect extends _SubscriptionCallbackMutationBase {\n type: MutationType.direct\n\n events: DebuggerEvent\n}\n\n/**\n * Context passed to a subscription callback when `store.$patch()` is called\n * with an object.\n */\nexport interface SubscriptionCallbackMutationPatchObject<S> extends _SubscriptionCallbackMutationBase {\n type: MutationType.patchObject\n\n events: DebuggerEvent[]\n\n /**\n * Object passed to `store.$patch()`.\n */\n payload: _DeepPartial<UnwrapRef<S>>\n}\n\n/**\n * Context passed to a subscription callback when `store.$patch()` is called\n * with a function.\n */\nexport interface SubscriptionCallbackMutationPatchFunction extends _SubscriptionCallbackMutationBase {\n type: MutationType.patchFunction\n\n events: DebuggerEvent[]\n\n /**\n * Object passed to `store.$patch()`.\n */\n // payload: DeepPartial<UnwrapRef<S>>\n}\n\n/**\n * Context object passed to a subscription callback.\n */\nexport type SubscriptionCallbackMutation<S> =\n | SubscriptionCallbackMutationDirect\n | SubscriptionCallbackMutationPatchObject<S>\n | SubscriptionCallbackMutationPatchFunction\n\n/**\n * Callback of a subscription\n */\nexport type SubscriptionCallback<S> = (\n /**\n * Object with information relative to the store mutation that triggered the\n * subscription.\n */\n mutation: SubscriptionCallbackMutation<S>,\n\n /**\n * State of the store when the subscription is triggered. Same as\n * `store.$state`.\n */\n state: UnwrapRef<S>\n) => void\n\n/**\n * Actual type for {@link StoreOnActionListenerContext}. Exists for refactoring\n * purposes. For internal use only.\n * For internal use **only**\n */\nexport interface _StoreOnActionListenerContext<Store, ActionName extends string, A> {\n /**\n * Name of the action\n */\n name: ActionName\n\n /**\n * Store that is invoking the action\n */\n store: Store\n\n /**\n * Parameters passed to the action\n */\n args: A extends Record<ActionName, _Method> ? Parameters<A[ActionName]> : unknown[]\n\n /**\n * Sets up a hook once the action is finished. It receives the return value\n * of the action, if it's a Promise, it will be unwrapped.\n */\n after: (\n callback: A extends Record<ActionName, _Method>\n ? (resolvedReturn: Awaited<ReturnType<A[ActionName]>>) => void\n : () => void\n ) => void\n\n /**\n * Sets up a hook if the action fails. Return `false` to catch the error and\n * stop it from propagating.\n */\n onError: (callback: (error: unknown) => void) => void\n}\n\n/**\n * Context object passed to callbacks of `store.$onAction(context => {})`\n * TODO: should have only the Id, the Store and Actions to generate the proper object\n */\nexport type StoreOnActionListenerContext<\n Id extends string,\n S extends StateTree,\n G /* extends GettersTree<S> */,\n A /* extends ActionsTree */\n> = _ActionsTree extends A\n ? _StoreOnActionListenerContext<StoreGeneric, string, _ActionsTree>\n : {\n [Name in keyof A]: Name extends string ? _StoreOnActionListenerContext<Store<Id, S, G, A>, Name, A> : never\n }[keyof A]\n\n/**\n * Argument of `store.$onAction()`\n */\nexport type StoreOnActionListener<\n Id extends string,\n S extends StateTree,\n G /* extends GettersTree<S> */,\n A /* extends ActionsTree */\n> = (\n context: StoreOnActionListenerContext<\n Id,\n S,\n G,\n // {} creates a type of never due to how StoreOnActionListenerContext is defined\n {} extends A ? _ActionsTree : A\n >\n) => void\n\n/**\n * Properties of a store.\n */\nexport interface StoreProperties<Id extends string> {\n /**\n * Unique identifier of the store\n */\n $id: Id\n\n /**\n * Private property defining the pinia the store is attached to.\n *\n * @internal\n */\n _p: Pinia\n\n /**\n * Used by devtools plugin to retrieve getters. Removed in production.\n *\n * @internal\n */\n _getters?: string[]\n\n /**\n * Used (and added) by devtools plugin to detect Setup vs Options API usage.\n *\n * @internal\n */\n _isOptionsAPI?: boolean\n\n /**\n * Used by devtools plugin to retrieve properties added with plugins. Removed\n * in production. Can be used by the user to add property keys of the store\n * that should be displayed in devtools.\n */\n _customProperties: Set<string>\n\n /**\n * Handles a HMR replacement of this store. Dev Only.\n *\n * @internal\n */\n _hotUpdate(useStore: StoreGeneric): void\n\n /**\n * Allows pausing some of the watching mechanisms while the store is being\n * patched with a newer version.\n *\n * @internal\n */\n _hotUpdating: boolean\n\n /**\n * Payload of the hmr update. Dev only.\n *\n * @internal\n */\n _hmrPayload: {\n state: string[]\n hotState: Ref<StateTree>\n actions: _ActionsTree\n getters: _ActionsTree\n }\n}\n\n/**\n * Base store with state and functions. Should not be used directly.\n */\nexport interface _StoreWithState<\n Id extends string,\n S extends StateTree,\n G /* extends GettersTree<StateTree> */,\n A /* extends ActionsTree */\n> extends StoreProperties<Id> {\n /**\n * State of the Store. Setting it will internally call `$patch()` to update the state.\n */\n $state: UnwrapRef<S> & PiniaCustomStateProperties<S>\n\n /**\n * Applies a state patch to current state. Allows passing nested values\n *\n * @param partialState - patch to apply to the state\n */\n $patch(partialState: _DeepPartial<UnwrapRef<S>>): void\n\n /**\n * Group multiple changes into one function. Useful when mutating objects like\n * Sets or arrays and applying an object patch isn't practical, e.g. appending\n * to an array. The function passed to `$patch()` **must be synchronous**.\n *\n * @param stateMutator - function that mutates `state`, cannot be asynchronous\n */\n $patch<F extends (state: UnwrapRef<S>) => any>(\n // this prevents the user from using `async` which isn't allowed\n stateMutator: ReturnType<F> extends Promise<any> ? never : F\n ): void\n\n /**\n * Resets the store to its initial state by building a new state object.\n */\n $reset(): void\n\n /**\n * Setups a callback to be called whenever the state changes. It also returns a function to remove the callback. Note\n * that when calling `store.$subscribe()` inside of a component, it will be automatically cleaned up when the\n * component gets unmounted unless `detached` is set to true.\n *\n * @param callback - callback passed to the watcher\n * @param options - `watch` options + `detached` to detach the subscription from the context (usually a component)\n * this is called from. Note that the `flush` option does not affect calls to `store.$patch()`.\n * @returns function that removes the watcher\n */\n $subscribe(callback: SubscriptionCallback<S>, options?: { detached?: boolean } & WatchOptions): () => void\n\n /**\n * Setups a callback to be called every time an action is about to get\n * invoked. The callback receives an object with all the relevant information\n * of the invoked action:\n * - `store`: the store it is invoked on\n * - `name`: The name of the action\n * - `args`: The parameters passed to the action\n *\n * On top of these, it receives two functions that allow setting up a callback\n * once the action finishes or when it fails.\n *\n * It also returns a function to remove the callback. Note than when calling\n * `store.$onAction()` inside of a component, it will be automatically cleaned\n * up when the component gets unmounted unless `detached` is set to true.\n *\n * @example\n *\n *```js\n *store.$onAction(({ after, onError }) => {\n * // Here you could share variables between all of the hooks as well as\n * // setting up watchers and clean them up\n * after((resolvedValue) => {\n * // can be used to cleanup side effects\n * . // `resolvedValue` is the value returned by the action, if it's a\n * . // Promise, it will be the resolved value instead of the Promise\n * })\n * onError((error) => {\n * // can be used to pass up errors\n * })\n *})\n *```\n *\n * @param callback - callback called before every action\n * @param detached - detach the subscription from the context this is called from\n * @returns function that removes the watcher\n */\n $onAction(callback: StoreOnActionListener<Id, S, G, A>, detached?: boolean): () => void\n\n /**\n * Stops the associated effect scope of the store and remove it from the store\n * registry. Plugins can override this method to cleanup any added effects.\n * e.g. devtools plugin stops displaying disposed stores from devtools.\n * Note this doesn't delete the state of the store, you have to do it manually with\n * `delete pinia.state.value[store.$id]` if you want to. If you don't and the\n * store is used again, it will reuse the previous state.\n */\n $dispose(): void\n}\n\n/**\n * Generic type for a function that can infer arguments and return type\n *\n * For internal use **only**\n */\nexport type _Method = (...args: any[]) => any\n\n// export type StoreAction<P extends any[], R> = (...args: P) => R\n// export interface StoreAction<P, R> {\n// (...args: P[]): R\n// }\n\n// in this type we forget about this because otherwise the type is recursive\n/**\n * Store augmented for actions. For internal usage only.\n * For internal use **only**\n */\nexport type _StoreWithActions<A> = {\n [k in keyof A]: A[k] extends (...args: infer P) => infer R ? (...args: P) => R : never\n}\n\n/**\n * Store augmented with getters. For internal usage only.\n * For internal use **only**\n */\nexport type _StoreWithGetters<G> = _StoreWithGetters_Readonly<G> & _StoreWithGetters_Writable<G>\n\n/**\n * Store augmented with readonly getters. For internal usage **only**.\n */\nexport type _StoreWithGetters_Readonly<G> = {\n readonly [K in keyof G as G[K] extends (...args: any[]) => any\n ? K\n : ComputedRef extends G[K]\n ? K\n : never]: G[K] extends (...args: any[]) => infer R ? R : UnwrapRef<G[K]>\n}\n\n/**\n * Store augmented with writable getters. For internal usage **only**.\n */\nexport type _StoreWithGetters_Writable<G> = {\n [K in keyof G as G[K] extends WritableComputedRef<any>\n ? K\n : // NOTE: there is still no way to have a different type for a setter and a getter in TS with dynamic keys\n // https://github.com/microsoft/TypeScript/issues/43826\n never]: G[K] extends Readonly<WritableComputedRef<infer R>> ? R : never\n}\n\n/**\n * Store type to build a store.\n */\nexport type Store<\n Id extends string = string,\n S extends StateTree = {},\n G /* extends GettersTree<S>*/ = {},\n // has the actions without the context (this) for typings\n A /* extends ActionsTree */ = {}\n> = _StoreWithState<Id, S, G, A> &\n UnwrapRef<S> &\n _StoreWithGetters<G> &\n // StoreWithActions<A> &\n (_ActionsTree extends A ? {} : A) &\n PiniaCustomProperties<Id, S, G, A> &\n PiniaCustomStateProperties<S>\n\n/**\n * Generic and type-unsafe version of Store. Doesn't fail on access with\n * strings, making it much easier to write generic functions that do not care\n * about the kind of store that is passed.\n */\nexport type StoreGeneric = Store<string, StateTree, _GettersTree<StateTree>, _ActionsTree>\n\n/**\n * Return type of `defineStore()`. Function that allows instantiating a store.\n */\nexport interface StoreDefinition<\n Id extends string = string,\n S extends StateTree = StateTree,\n G /* extends GettersTree<S>*/ = _GettersTree<S>,\n A /* extends ActionsTree */ = _ActionsTree\n> {\n /**\n * Returns a store, creates it if necessary.\n *\n * @param pinia - Pinia instance to retrieve the store\n * @param hot - dev only hot module replacement\n */\n (pinia?: Pinia | null | undefined, hot?: StoreGeneric): Store<Id, S, G, A>\n\n /**\n * Id of the store. Used by map helpers.\n */\n $id: Id\n /**\n * Return to store for use within non-functional components\n */\n $getStore: () => Store<Id, S, G, A>\n /**\n * Dev only pinia for HMR.\n *\n * @internal\n */\n _pinia?: Pinia\n}\n\n/**\n * Interface to be extended by the user when they add properties through plugins.\n */\nexport interface PiniaCustomProperties<\n Id extends string = string,\n S extends StateTree = StateTree,\n G /* extends GettersTree<S> */ = _GettersTree<S>,\n A /* extends ActionsTree */ = _ActionsTree\n> {}\n\n/**\n * Properties that are added to every `store.$state` by `pinia.use()`.\n */\nexport interface PiniaCustomStateProperties<S extends StateTree = StateTree> {}\n\n/**\n * Type of an object of Getters that infers the argument. For internal usage only.\n * For internal use **only**\n */\nexport type _GettersTree<S extends StateTree> = Record<\n string,\n ((state: UnwrapRef<S> & UnwrapRef<PiniaCustomStateProperties<S>>) => any) | (() => any)\n>\n\n/**\n * Type of an object of Actions. For internal usage only.\n * For internal use **only**\n */\nexport type _ActionsTree = Record<string, _Method>\n\n/**\n * Type that enables refactoring through IDE.\n * For internal use **only**\n */\nexport type _ExtractStateFromSetupStore_Keys<SS> = keyof {\n [K in keyof SS as SS[K] extends _Method | ComputedRef ? never : K]: any\n}\n\n/**\n * Type that enables refactoring through IDE.\n * For internal use **only**\n */\nexport type _ExtractActionsFromSetupStore_Keys<SS> = keyof {\n [K in keyof SS as SS[K] extends _Method ? K : never]: any\n}\n\n/**\n * Type that enables refactoring through IDE.\n * For internal use **only**\n */\nexport type _ExtractGettersFromSetupStore_Keys<SS> = keyof {\n [K in keyof SS as SS[K] extends ComputedRef ? K : never]: any\n}\n\n/**\n * Type that enables refactoring through IDE.\n * For internal use **only**\n */\nexport type _UnwrapAll<SS> = { [K in keyof SS]: UnwrapRef<SS[K]> }\n\n/**\n * For internal use **only**\n */\nexport type _ExtractStateFromSetupStore<SS> = SS extends undefined | void\n ? {}\n : Pick<SS, _ExtractStateFromSetupStore_Keys<SS>>\n\n/**\n * For internal use **only**\n */\nexport type _ExtractActionsFromSetupStore<SS> = SS extends undefined | void\n ? {}\n : Pick<SS, _ExtractActionsFromSetupStore_Keys<SS>>\n\n/**\n * For internal use **only**\n */\nexport type _ExtractGettersFromSetupStore<SS> = SS extends undefined | void\n ? {}\n : Pick<SS, _ExtractGettersFromSetupStore_Keys<SS>>\n\n/**\n * Options passed to `defineStore()` that are common between option and setup\n * stores. Extend this interface if you want to add custom options to both kinds\n * of stores.\n */\nexport type DefineStoreOptionsBase<S extends StateTree, Store> = {}\n\n/**\n * Options parameter of `defineStore()` for option stores. Can be extended to\n * augment stores with the plugin API. @see {@link DefineStoreOptionsBase}.\n */\nexport interface DefineStoreOptions<\n Id extends string,\n S extends StateTree,\n G extends _GettersTree<S>,\n A /* extends Record<string, StoreAction> */\n> extends DefineStoreOptionsBase<S, Store<Id, S, G, A>> {\n /**\n * Unique string key to identify the store across the application.\n */\n id: Id\n\n /**\n * Function to create a fresh state. **Must be an arrow function** to ensure\n * correct typings!\n */\n state?: () => S\n\n /**\n * Optional object of getters.\n */\n getters?: G & ThisType<UnwrapRef<S> & _StoreWithGetters<G> & PiniaCustomProperties> & _GettersTree<S>\n\n /**\n * Optional object of actions.\n */\n actions?: A & ThisType<A & UnwrapRef<S> & _StoreWithState<Id, S, G, A> & _StoreWithGetters<G> & PiniaCustomProperties>\n\n /**\n * Allows hydrating the store during SSR when complex state (like client side only refs) are used in the store\n * definition and copying the value from `pinia.state` isn't enough.\n *\n * @example\n * If in your `state`, you use any `customRef`s, any `computed`s, or any `ref`s that have a different value on\n * Server and Client, you need to manually hydrate them. e.g., a custom ref that is stored in the local\n * storage:\n *\n * ```ts\n * const useStore = defineStore('main', {\n * state: () => ({\n * n: useLocalStorage('key', 0)\n * }),\n * hydrate(storeState, initialState) {\n * // @ts-expect-error: https://github.com/microsoft/TypeScript/issues/43826\n * storeState.n = useLocalStorage('key', 0)\n * }\n * })\n * ```\n *\n * @param storeState - the current state in the store\n * @param initialState - initialState\n */\n hydrate?(storeState: UnwrapRef<S>, initialState: UnwrapRef<S>): void\n}\n\n/**\n * Options parameter of `defineStore()` for setup stores. Can be extended to\n * augment stores with the plugin API. @see {@link DefineStoreOptionsBase}.\n */\nexport interface DefineSetupStoreOptions<\n Id extends string,\n // NOTE: Passing SS seems to make TS crash\n S extends StateTree,\n G,\n A /* extends ActionsTree */\n> extends DefineStoreOptionsBase<S, Store<Id, S, G, A>> {\n /**\n * Extracted actions. Added by useStore(). SHOULD NOT be added by the user when\n * creating the store. Can be used in plugins to get the list of actions in a\n * store defined with a setup function. Note this is always defined\n */\n actions?: A\n}\n\n/**\n * Available `options` when creating a pinia plugin.\n */\nexport interface DefineStoreOptionsInPlugin<Id extends string, S extends StateTree, G extends _GettersTree<S>, A>\n extends Omit<DefineStoreOptions<Id, S, G, A>, 'id' | 'actions'> {\n /**\n * Extracted object of actions. Added by useStore() when the store is built\n * using the setup API, otherwise uses the one passed to `defineStore()`.\n * Defaults to an empty object if no actions are defined.\n */\n actions: A\n}\n\n/**\n * Utility type. For internal use **only**\n */\nexport type _Empty = {}\n\n/**\n * Merges type objects for better readability in the code.\n * Utility type. For internal use **only**\n */\nexport type _Simplify<T> = _Empty extends T ? _Empty : { [key in keyof T]: T[key] } & {}\n\nexport type Fn = () => void\n","import { isReactive, isRef } from '@maoism/runtime-core'\nimport type { _DeepPartial, StateTree } from './types'\n\nexport function noop() {\n return {}\n}\n\nexport function isPlainObject<S extends StateTree>(value: S | unknown): value is S\nexport function isPlainObject(o: any): o is StateTree {\n return (\n o &&\n typeof o === 'object' &&\n Object.prototype.toString.call(o) === '[object Object]' &&\n typeof o.toJSON !== 'function'\n )\n}\n\nexport function mergeReactiveObjects<T extends Record<any, unknown> | Map<unknown, unknown> | Set<unknown>>(\n target: T,\n patchToApply: _DeepPartial<T>\n): T {\n // Handle Map instances\n if (target instanceof Map && patchToApply instanceof Map) {\n patchToApply.forEach((value, key) => target.set(key, value))\n }\n // Handle Set instances\n if (target instanceof Set && patchToApply instanceof Set) {\n patchToApply.forEach(target.add, target)\n }\n\n // no need to go through symbols because they cannot be serialized anyway\n for (const key in patchToApply) {\n // eslint-disable-next-line no-prototype-builtins\n if (!Object.hasOwn(patchToApply, key)) continue\n const subPatch = patchToApply[key]\n const targetValue = target[key]\n if (\n isPlainObject(targetValue) &&\n isPlainObject(subPatch) &&\n // biome-ignore lint/suspicious/noPrototypeBuiltins: <>\n target.hasOwnProperty(key) &&\n !isRef(subPatch) &&\n !isReactive(subPatch)\n ) {\n target[key] = mergeReactiveObjects(targetValue, subPatch)\n } else {\n // @ts-expect-error: subPatch is a valid value\n target[key] = subPatch\n }\n }\n\n return target\n}\n"],"mappings":";AAAA,SAAS,aAAa,SAAmB,WAAW;;;ACe7C,IAAM,iBAAiB,MAAM;AA+C7B,IAAI;AAEJ,SAAS,eAAe,QAAe;AAC5C,gBAAc;AAChB;;;AD3DO,SAAS,cAAqB;AACnC,QAAM,QAAQ,YAAY,IAAI;AA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O;AACT;","names":["effectScope","markRaw","activeComponentCleanUp","MutationType","noop","markRaw","store","$reset","options","effectScope","effect","noop"]}
|
|
1
|
+
{"version":3,"sources":["../src/createPinia.ts","../src/rootStore.ts","../src/store.ts","../src/subscription.ts","../src/types.ts","../src/utils.ts"],"sourcesContent":["import { effectScope, markRaw, type Ref, ref } from '@maoism/runtime-core'\nimport { type Pinia, setActivePinia } from './rootStore'\nimport type { StateTree, StoreGeneric } from './types'\n\n/**\n * Creates a Pinia instance to be used by the application\n */\nexport function createPinia(): Pinia {\n const scope = effectScope(true)\n\n const state = scope.run<Ref<Record<string, StateTree>>>(() => ref<Record<string, StateTree>>({}))!\n\n const _p: Pinia['_p'] = []\n\n const pinia: Pinia = markRaw({\n use(plugin) {\n _p.push(plugin)\n return this\n },\n _p,\n _e: scope,\n _s: new Map<string, StoreGeneric>(),\n state\n })\n\n setActivePinia(pinia)\n\n return pinia\n}\n","import type { EffectScope, Ref } from '@maoism/runtime-core'\nimport type {\n _ActionsTree,\n _GettersTree,\n DefineStoreOptionsInPlugin,\n PiniaCustomProperties,\n PiniaCustomStateProperties,\n StateTree,\n Store,\n StoreGeneric\n} from './types'\n\n/**\n * Get the currently active pinia if there is any.\n */\nexport const getActivePinia = () => activePinia\n\n/**\n * Every application must own its own pinia to be able to create stores\n */\nexport interface Pinia {\n /**\n * root state\n */\n state: Ref<Record<string, StateTree>>\n\n /**\n * Adds a store plugin to extend every store\n *\n * @param plugin - store plugin to add\n */\n use(plugin: PiniaPlugin): Pinia\n\n /**\n * Installed store plugins\n *\n * @internal\n */\n _p: PiniaPlugin[]\n\n /**\n * Effect scope the pinia is attached to\n *\n * @internal\n */\n _e: EffectScope\n\n /**\n * Registry of stores used by this pinia.\n *\n * @internal\n */\n _s: Map<string, StoreGeneric>\n\n /**\n * Added by `createTestingPinia()` to bypass `useStore(pinia)`.\n *\n * @internal\n */\n _testing?: boolean\n}\n\nexport let activePinia: Pinia | undefined\n\nexport function setActivePinia(_pinia: Pinia) {\n activePinia = _pinia\n}\n\nexport type PiniaPluginContext<\n Id extends string = string,\n S extends StateTree = StateTree,\n G extends _GettersTree<S> = _GettersTree<S>,\n A /* extends _ActionsTree */ = _ActionsTree\n> = {\n /**\n * pinia instance.\n */\n pinia: Pinia\n /**\n * Current store being extended.\n */\n store: Store<Id, S, G, A>\n\n /**\n * Initial options defining the store when calling `defineStore()`.\n */\n options: DefineStoreOptionsInPlugin<Id, S, G, A>\n}\n\n/**\n * Plugin to extend every store.\n */\nexport interface PiniaPlugin {\n /**\n * Plugin to extend every store. Returns an object to extend the store or\n * nothing.\n *\n * @param context - Context\n */\n (context: PiniaPluginContext): Partial<PiniaCustomProperties & PiniaCustomStateProperties> | void\n}\n","import {\n activeEffect,\n type ComputedRef,\n computed,\n type DebuggerEvent,\n type EffectScope,\n effectScope,\n markRaw,\n nextTick,\n ReactiveEffect,\n reactive,\n toRaw,\n toRefs,\n type UnwrapRef,\n type WatchOptions,\n watch\n} from '@maoism/runtime-core'\nimport { useCallback, useEffect, useId, useRef, useSyncExternalStore } from 'react'\nimport { activePinia, type Pinia, setActivePinia } from './rootStore'\nimport { addSubscription, triggerSubscriptions } from './subscription'\nimport {\n type _ActionsTree,\n type _DeepPartial,\n type _GettersTree,\n type _Method,\n type _StoreWithState,\n type DefineSetupStoreOptions,\n type DefineStoreOptions,\n type DefineStoreOptionsInPlugin,\n type Fn,\n MutationType,\n type StateTree,\n type Store,\n type StoreDefinition,\n type StoreOnActionListener,\n type SubscriptionCallback,\n type SubscriptionCallbackMutation\n} from './types'\nimport { mergeReactiveObjects, noop } from './utils'\n\ntype _SetType<AT> = AT extends Set<infer T> ? T : never\n/**\n * Marks a function as an action for `$onAction`\n * @internal\n */\nconst ACTION_MARKER = Symbol()\n/**\n * Action name symbol. Allows to add a name to an action after defining it\n * @internal\n */\nconst ACTION_NAME = Symbol()\n/**\n * Function type extended with action markers\n * @internal\n */\ninterface MarkedAction<Fn extends _Method = _Method> {\n (...args: Parameters<Fn>): ReturnType<Fn>\n [ACTION_MARKER]: boolean\n [ACTION_NAME]: string\n}\n\nconst { assign } = Object\n\nfunction createOptionsStore<Id extends string, S extends StateTree, G extends _GettersTree<S>, A extends _ActionsTree>(\n id: Id,\n options: DefineStoreOptions<Id, S, G, A>,\n pinia: Pinia\n): Store<Id, S, G, A> {\n const { state, actions, getters } = options\n\n const initialState: StateTree | undefined = pinia.state.value[id]\n\n let store: Store<Id, S, G, A>\n\n function setup() {\n if (!initialState) {\n pinia.state.value[id] = state ? state() : {}\n }\n\n const localState = toRefs(pinia.state.value[id])\n\n return assign(\n localState,\n actions,\n Object.keys(getters || {}).reduce(\n (computedGetters, name) => {\n if (name in localState) {\n console.warn(\n `[π]: A getter cannot have the same name as another state property. Rename one of them. Found with \"${name}\" in store \"${id}\".`\n )\n }\n\n computedGetters[name] = markRaw(\n computed(() => {\n setActivePinia(pinia)\n // it was created just before\n const store = pinia._s.get(id)!\n // @ts-expect-error\n return getters![name].call(store, store)\n })\n )\n return computedGetters\n },\n {} as Record<string, ComputedRef>\n )\n )\n }\n\n store = createSetupStore(id, setup, options, pinia)\n\n return store as any\n}\n\nfunction createSetupStore<\n Id extends string,\n SS extends Record<any, unknown>,\n S extends StateTree,\n G extends Record<string, _Method>,\n A extends _ActionsTree\n>(\n $id: Id,\n setup: (helpers: SetupStoreHelpers) => SS,\n options: DefineSetupStoreOptions<Id, S, G, A> | DefineStoreOptions<Id, S, G, A> = {},\n pinia: Pinia\n): Store<Id, S, G, A> {\n let scope!: EffectScope\n\n const optionsForPlugin: DefineStoreOptionsInPlugin<Id, S, G, A> = assign({ actions: {} as A }, options)\n\n const $subscribeOptions: WatchOptions = { deep: true }\n\n // internal state\n let isListening: boolean // set to true at the end\n let isSyncListening: boolean // set to true at the end\n const subscriptions: Set<SubscriptionCallback<S>> = new Set()\n const actionSubscriptions: Set<StoreOnActionListener<Id, S, G, A>> = new Set()\n const debuggerEvents: DebuggerEvent[] | DebuggerEvent = []\n // const initialState = pinia.state.value[$id] as UnwrapRef<S> | undefined\n\n let activeListener: symbol | undefined\n function $patch(stateMutation: (state: UnwrapRef<S>) => void): void\n function $patch(partialState: _DeepPartial<UnwrapRef<S>>): void\n function $patch(partialStateOrMutator: _DeepPartial<UnwrapRef<S>> | ((state: UnwrapRef<S>) => void)): void {\n let subscriptionMutation: SubscriptionCallbackMutation<S>\n isListening = isSyncListening = false\n // reset the debugger events since patches are sync\n /* istanbul ignore else */\n // if (__DEV__) {\n // debuggerEvents = []\n // }\n if (typeof partialStateOrMutator === 'function') {\n partialStateOrMutator(pinia.state.value[$id] as UnwrapRef<S>)\n subscriptionMutation = {\n type: MutationType.patchFunction,\n storeId: $id,\n events: debuggerEvents as DebuggerEvent[]\n }\n } else {\n mergeReactiveObjects(pinia.state.value[$id], partialStateOrMutator)\n subscriptionMutation = {\n type: MutationType.patchObject,\n payload: partialStateOrMutator,\n storeId: $id,\n events: debuggerEvents as DebuggerEvent[]\n }\n }\n activeListener = Symbol()\n const myListenerId = activeListener\n nextTick().then(() => {\n if (activeListener === myListenerId) {\n isListening = true\n }\n })\n isSyncListening = true\n // because we paused the watcher, we need to manually call the subscriptions\n triggerSubscriptions(subscriptions, subscriptionMutation, pinia.state.value[$id] as UnwrapRef<S>)\n }\n\n const $reset = function $reset(this: _StoreWithState<Id, S, G, A>) {\n const { state } = options as DefineStoreOptions<Id, S, G, A>\n const newState: _DeepPartial<UnwrapRef<S>> = state ? state() : {}\n // we use a patch to group all changes into one single subscription\n this.$patch(($state) => {\n // @ts-expect-error: FIXME: shouldn't error?\n assign($state, newState)\n })\n }\n\n /**\n * Helper that wraps function so it can be tracked with $onAction\n * @param fn - action to wrap\n * @param name - name of the action\n */\n const action = <Fn extends _Method>(fn: Fn, name: string = ''): Fn => {\n if (ACTION_MARKER in fn) {\n // we ensure the name is set from the returned function\n ;(fn as unknown as MarkedAction<Fn>)[ACTION_NAME] = name\n return fn\n }\n\n const wrappedAction = function (this: any) {\n setActivePinia(pinia)\n const args = Array.from(arguments)\n\n const afterCallbackSet: Set<(resolvedReturn: any) => any> = new Set()\n const onErrorCallbackSet: Set<(error: unknown) => unknown> = new Set()\n function after(callback: _SetType<typeof afterCallbackSet>) {\n afterCallbackSet.add(callback)\n }\n function onError(callback: _SetType<typeof onErrorCallbackSet>) {\n onErrorCallbackSet.add(callback)\n }\n\n // @ts-expect-error\n triggerSubscriptions(actionSubscriptions, {\n args,\n name: wrappedAction[ACTION_NAME],\n store,\n after,\n onError\n })\n\n let ret: unknown\n try {\n ret = fn.apply(this && this.$id === $id ? this : store, args)\n // handle sync errors\n } catch (error) {\n triggerSubscriptions(onErrorCallbackSet, error)\n throw error\n }\n\n if (ret instanceof Promise) {\n return ret\n .then((value) => {\n triggerSubscriptions(afterCallbackSet, value)\n return value\n })\n .catch((error) => {\n triggerSubscriptions(onErrorCallbackSet, error)\n return Promise.reject(error)\n })\n }\n\n // trigger after callbacks\n triggerSubscriptions(afterCallbackSet, ret)\n return ret\n } as MarkedAction<Fn>\n\n wrappedAction[ACTION_MARKER] = true\n wrappedAction[ACTION_NAME] = name // will be set later\n\n // @ts-expect-error: we are intentionally limiting the returned type to just Fn\n // because all the added properties are internals that are exposed through `$onAction()` only\n return wrappedAction\n }\n\n const partialStore = {\n _p: pinia,\n // _s: scope,\n $id,\n $onAction: addSubscription.bind(null, activeComponentCleanUp, actionSubscriptions),\n $patch,\n $reset,\n $subscribe(callback, options = {}) {\n const removeSubscription = addSubscription([[]], subscriptions, callback, options.detached, () => stopWatcher())\n const stopWatcher = scope.run(() =>\n watch(\n () => pinia.state.value[$id] as UnwrapRef<S>,\n (state) => {\n if (options.flush === 'sync' ? isSyncListening : isListening) {\n callback(\n {\n storeId: $id,\n type: MutationType.direct,\n events: debuggerEvents as unknown as DebuggerEvent\n },\n state\n )\n }\n },\n assign({}, $subscribeOptions, options)\n )\n )!\n\n return removeSubscription\n }\n // $dispose\n } as _StoreWithState<Id, S, G, A>\n\n const store: Store<Id, S, G, A> = reactive(partialStore) as unknown as Store<Id, S, G, A>\n\n // store the partial store now so the setup of stores can instantiate each other before they are finished without\n // creating infinite loops.\n pinia._s.set($id, store as Store)\n\n scope = effectScope()\n const setupStore = scope.run(() => setup({ action }))\n\n // overwrite existing actions to support $onAction\n for (const key in setupStore) {\n const prop = setupStore[key]\n\n if (typeof prop === 'function') {\n const actionValue = action(prop as _Method, key)\n // this a hot module replacement store because the hotUpdate method needs\n // @ts-expect-error\n setupStore[key] = actionValue\n\n // list actions so they can be used in plugins\n // @ts-expect-error\n optionsForPlugin.actions[key] = prop\n }\n }\n\n assign(store, setupStore)\n // allows retrieving reactive objects with `storeToRefs()`. Must be called after assigning to the reactive object.\n // Make `storeToRefs()` work with `reactive()` #799\n assign(toRaw(store), setupStore)\n\n // use this instead of a computed with setter to be able to create it anywhere\n // without linking the computed lifespan to wherever the store is first\n // created.\n Object.defineProperty(store, '$state', {\n get: () => pinia.state.value[$id],\n set: (state) => {\n $patch(($state) => {\n // @ts-expect-error: FIXME: shouldn't error?\n assign($state, state)\n })\n }\n })\n\n // apply all plugins\n pinia._p.forEach((extender) => {\n assign(\n store,\n scope.run(() =>\n extender({\n store: store as Store,\n pinia,\n options: optionsForPlugin\n })\n )!\n )\n })\n\n isListening = true\n isSyncListening = true\n return store\n}\n\nexport interface SetupStoreHelpers {\n /**\n * Helper that wraps function so it can be tracked with $onAction when the\n * action is called **within the store**. This helper is rarely needed in\n * applications. It's intended for advanced use cases like Pinia Colada.\n *\n * @param fn - action to wrap\n * @param name - name of the action. Will be picked up by the store at creation\n */\n action: <Fn extends _Method>(fn: Fn, name?: string) => Fn\n}\n\nconst activeComponentCleanUp: [Fn[]] = [[]]\n\n/**\n * Creates a `useStore` function that retrieves the store instance\n *\n * @param id - id of the store (must be unique)\n * @param options - options to define the store\n */\nexport function defineStore<\n Id extends string,\n S extends StateTree = {},\n G extends _GettersTree<S> = {},\n // cannot extends ActionsTree because we loose the typings\n A /* extends ActionsTree */ = {}\n>(id: Id, options: Omit<DefineStoreOptions<Id, S, G, A>, 'id'>): StoreDefinition<Id, S, G, A> {\n const effectMap = new WeakMap<[string], ReactiveEffect>()\n const subscribeMap = new WeakMap<[string], Fn>()\n const cleanUpMap = new WeakMap<[string], Fn[]>()\n\n function useStore(pinia?: Pinia | null): Store<Id, S, G, A> {\n if (pinia) setActivePinia(pinia)\n if (!activePinia) {\n throw new Error(\n `[π]: \"getActivePinia()\" was called but there was no active Pinia. Are you trying to use a store before calling \"createPinia()\"?\\n`\n )\n }\n pinia = activePinia!\n\n const lastEffect = activeEffect.value\n activeEffect.value = undefined\n\n if (!pinia._s.has(id)) createOptionsStore(id, options as any, pinia)\n activeEffect.value = lastEffect\n\n const store = pinia._s.get(id)!\n const _id = useRef<[string]>([useId()])\n const storeSnapshotRef = useRef({ ...store })\n const isCollectDep = useRef(false)\n\n if (!cleanUpMap.get(_id.current)) {\n cleanUpMap.set(_id.current, [])\n }\n\n activeComponentCleanUp[0] = cleanUpMap.get(_id.current)!\n\n useEffect(() => {\n activeComponentCleanUp[0] = cleanUpMap.get(_id.current)!\n return () => {\n cleanUpMap.get(_id.current)!.forEach((fn) => {\n fn()\n })\n }\n }, [])\n\n const subscribe = useCallback((onStoreChange: () => void) => {\n subscribeMap.set(_id.current, onStoreChange)\n\n return () => {\n // θΏιε°±θ¦θ°η¨ζΈ
ι€ε―δ½η¨ηζζε½ζ°γ\n const effect = effectMap.get(_id.current)\n if (effect) effect.stop()\n subscribeMap.delete(_id.current)\n effectMap.delete(_id.current)\n }\n }, [])\n\n useSyncExternalStore(\n subscribe,\n () => storeSnapshotRef.current,\n () => storeSnapshotRef.current\n )\n\n let effect = effectMap.get(_id.current)\n if (!effect) {\n const fn = () => {\n const onStoreChange = subscribeMap.get(_id.current)\n if (!isCollectDep.current) {\n storeSnapshotRef.current = { ...store }\n onStoreChange?.()\n }\n }\n\n effect = new ReactiveEffect(fn, noop, () => {\n if (effect?.dirty) effect.run()\n })\n activeEffect.value = effect\n isCollectDep.current = true\n effect.run()\n effectMap.set(_id.current, effect)\n isCollectDep.current = false\n }\n\n return store as Store<Id, S, G, A>\n }\n\n useStore.$id = id\n useStore.$getStore = (pinia?: Pinia | null) => {\n if (pinia) setActivePinia(pinia)\n pinia = activePinia!\n if (!pinia._s.has(id)) createOptionsStore(id, options as any, pinia)\n const store = pinia._s.get(id)!\n return store as Store<Id, S, G, A>\n }\n return useStore\n}\n","import type { _Method, Fn } from './types'\n\nexport const noop = () => {}\n\nexport function addSubscription<T extends _Method>(\n activeComponentCleanUp: [Fn[]],\n subscriptions: Set<T>,\n callback: T,\n detached?: boolean,\n onCleanup: () => void = noop\n) {\n subscriptions.add(callback)\n\n const removeSubscription = () => {\n subscriptions.delete(callback)\n onCleanup()\n }\n\n if (!detached) {\n activeComponentCleanUp[0].push(removeSubscription)\n }\n\n return removeSubscription\n}\n\nexport function triggerSubscriptions<T extends _Method>(subscriptions: Set<T>, ...args: Parameters<T>) {\n subscriptions.forEach((callback) => {\n callback(...args)\n })\n}\n","import type {\n ComputedRef,\n DebuggerEvent,\n Ref,\n UnwrapRef,\n WatchOptions,\n WritableComputedRef\n} from '@maoism/runtime-core'\nimport type { Pinia } from './rootStore'\n\n/**\n * Generic state of a Store\n */\nexport type StateTree = Record<PropertyKey, any>\n\nexport function isPlainObject<S extends StateTree>(value: S | unknown): value is S\nexport function isPlainObject(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n o: any\n): o is StateTree {\n return (\n o &&\n typeof o === 'object' &&\n Object.prototype.toString.call(o) === '[object Object]' &&\n typeof o.toJSON !== 'function'\n )\n}\n\n/**\n * Recursive `Partial<T>`. Used by {@link Store['$patch']}.\n *\n * For internal use **only**\n */\nexport type _DeepPartial<T> = { [K in keyof T]?: _DeepPartial<T[K]> }\n// type DeepReadonly<T> = { readonly [P in keyof T]: DeepReadonly<T[P]> }\n\n// TODO: can we change these to numbers?\n/**\n * Possible types for SubscriptionCallback\n */\nexport enum MutationType {\n /**\n * Direct mutation of the state:\n *\n * - `store.name = 'new name'`\n * - `store.$state.name = 'new name'`\n * - `store.list.push('new item')`\n */\n direct = 'direct',\n\n /**\n * Mutated the state with `$patch` and an object\n *\n * - `store.$patch({ name: 'newName' })`\n */\n patchObject = 'patch object',\n\n /**\n * Mutated the state with `$patch` and a function\n *\n * - `store.$patch(state => state.name = 'newName')`\n */\n patchFunction = 'patch function'\n\n // maybe reset? for $state = {} and $reset\n}\n\n/**\n * Base type for the context passed to a subscription callback. Internal type.\n */\nexport interface _SubscriptionCallbackMutationBase {\n /**\n * Type of the mutation.\n */\n type: MutationType\n\n /**\n * `id` of the store doing the mutation.\n */\n storeId: string\n\n /**\n * π΄ DEV ONLY, DO NOT use for production code. Different mutation calls. Comes from\n * https://vuejs.org/guide/extras/reactivity-in-depth.html#reactivity-debugging and allows to track mutations in\n * devtools and plugins **during development only**.\n */\n events?: DebuggerEvent[] | DebuggerEvent\n}\n\n/**\n * Context passed to a subscription callback when directly mutating the state of\n * a store with `store.someState = newValue` or `store.$state.someState =\n * newValue`.\n */\nexport interface SubscriptionCallbackMutationDirect extends _SubscriptionCallbackMutationBase {\n type: MutationType.direct\n\n events: DebuggerEvent\n}\n\n/**\n * Context passed to a subscription callback when `store.$patch()` is called\n * with an object.\n */\nexport interface SubscriptionCallbackMutationPatchObject<S> extends _SubscriptionCallbackMutationBase {\n type: MutationType.patchObject\n\n events: DebuggerEvent[]\n\n /**\n * Object passed to `store.$patch()`.\n */\n payload: _DeepPartial<UnwrapRef<S>>\n}\n\n/**\n * Context passed to a subscription callback when `store.$patch()` is called\n * with a function.\n */\nexport interface SubscriptionCallbackMutationPatchFunction extends _SubscriptionCallbackMutationBase {\n type: MutationType.patchFunction\n\n events: DebuggerEvent[]\n\n /**\n * Object passed to `store.$patch()`.\n */\n // payload: DeepPartial<UnwrapRef<S>>\n}\n\n/**\n * Context object passed to a subscription callback.\n */\nexport type SubscriptionCallbackMutation<S> =\n | SubscriptionCallbackMutationDirect\n | SubscriptionCallbackMutationPatchObject<S>\n | SubscriptionCallbackMutationPatchFunction\n\n/**\n * Callback of a subscription\n */\nexport type SubscriptionCallback<S> = (\n /**\n * Object with information relative to the store mutation that triggered the\n * subscription.\n */\n mutation: SubscriptionCallbackMutation<S>,\n\n /**\n * State of the store when the subscription is triggered. Same as\n * `store.$state`.\n */\n state: UnwrapRef<S>\n) => void\n\n/**\n * Actual type for {@link StoreOnActionListenerContext}. Exists for refactoring\n * purposes. For internal use only.\n * For internal use **only**\n */\nexport interface _StoreOnActionListenerContext<Store, ActionName extends string, A> {\n /**\n * Name of the action\n */\n name: ActionName\n\n /**\n * Store that is invoking the action\n */\n store: Store\n\n /**\n * Parameters passed to the action\n */\n args: A extends Record<ActionName, _Method> ? Parameters<A[ActionName]> : unknown[]\n\n /**\n * Sets up a hook once the action is finished. It receives the return value\n * of the action, if it's a Promise, it will be unwrapped.\n */\n after: (\n callback: A extends Record<ActionName, _Method>\n ? (resolvedReturn: Awaited<ReturnType<A[ActionName]>>) => void\n : () => void\n ) => void\n\n /**\n * Sets up a hook if the action fails. Return `false` to catch the error and\n * stop it from propagating.\n */\n onError: (callback: (error: unknown) => void) => void\n}\n\n/**\n * Context object passed to callbacks of `store.$onAction(context => {})`\n * TODO: should have only the Id, the Store and Actions to generate the proper object\n */\nexport type StoreOnActionListenerContext<\n Id extends string,\n S extends StateTree,\n G /* extends GettersTree<S> */,\n A /* extends ActionsTree */\n> = _ActionsTree extends A\n ? _StoreOnActionListenerContext<StoreGeneric, string, _ActionsTree>\n : {\n [Name in keyof A]: Name extends string ? _StoreOnActionListenerContext<Store<Id, S, G, A>, Name, A> : never\n }[keyof A]\n\n/**\n * Argument of `store.$onAction()`\n */\nexport type StoreOnActionListener<\n Id extends string,\n S extends StateTree,\n G /* extends GettersTree<S> */,\n A /* extends ActionsTree */\n> = (\n context: StoreOnActionListenerContext<\n Id,\n S,\n G,\n // {} creates a type of never due to how StoreOnActionListenerContext is defined\n {} extends A ? _ActionsTree : A\n >\n) => void\n\n/**\n * Properties of a store.\n */\nexport interface StoreProperties<Id extends string> {\n /**\n * Unique identifier of the store\n */\n $id: Id\n\n /**\n * Private property defining the pinia the store is attached to.\n *\n * @internal\n */\n _p: Pinia\n\n /**\n * Used by devtools plugin to retrieve getters. Removed in production.\n *\n * @internal\n */\n _getters?: string[]\n\n /**\n * Used (and added) by devtools plugin to detect Setup vs Options API usage.\n *\n * @internal\n */\n _isOptionsAPI?: boolean\n\n /**\n * Used by devtools plugin to retrieve properties added with plugins. Removed\n * in production. Can be used by the user to add property keys of the store\n * that should be displayed in devtools.\n */\n _customProperties: Set<string>\n\n /**\n * Handles a HMR replacement of this store. Dev Only.\n *\n * @internal\n */\n _hotUpdate(useStore: StoreGeneric): void\n\n /**\n * Allows pausing some of the watching mechanisms while the store is being\n * patched with a newer version.\n *\n * @internal\n */\n _hotUpdating: boolean\n\n /**\n * Payload of the hmr update. Dev only.\n *\n * @internal\n */\n _hmrPayload: {\n state: string[]\n hotState: Ref<StateTree>\n actions: _ActionsTree\n getters: _ActionsTree\n }\n}\n\n/**\n * Base store with state and functions. Should not be used directly.\n */\nexport interface _StoreWithState<\n Id extends string,\n S extends StateTree,\n G /* extends GettersTree<StateTree> */,\n A /* extends ActionsTree */\n> extends StoreProperties<Id> {\n /**\n * State of the Store. Setting it will internally call `$patch()` to update the state.\n */\n $state: UnwrapRef<S> & PiniaCustomStateProperties<S>\n\n /**\n * Applies a state patch to current state. Allows passing nested values\n *\n * @param partialState - patch to apply to the state\n */\n $patch(partialState: _DeepPartial<UnwrapRef<S>>): void\n\n /**\n * Group multiple changes into one function. Useful when mutating objects like\n * Sets or arrays and applying an object patch isn't practical, e.g. appending\n * to an array. The function passed to `$patch()` **must be synchronous**.\n *\n * @param stateMutator - function that mutates `state`, cannot be asynchronous\n */\n $patch<F extends (state: UnwrapRef<S>) => any>(\n // this prevents the user from using `async` which isn't allowed\n stateMutator: ReturnType<F> extends Promise<any> ? never : F\n ): void\n\n /**\n * Resets the store to its initial state by building a new state object.\n */\n $reset(): void\n\n /**\n * Setups a callback to be called whenever the state changes. It also returns a function to remove the callback. Note\n * that when calling `store.$subscribe()` inside of a component, it will be automatically cleaned up when the\n * component gets unmounted unless `detached` is set to true.\n *\n * @param callback - callback passed to the watcher\n * @param options - `watch` options + `detached` to detach the subscription from the context (usually a component)\n * this is called from. Note that the `flush` option does not affect calls to `store.$patch()`.\n * @returns function that removes the watcher\n */\n $subscribe(callback: SubscriptionCallback<S>, options?: { detached?: boolean } & WatchOptions): () => void\n\n /**\n * Setups a callback to be called every time an action is about to get\n * invoked. The callback receives an object with all the relevant information\n * of the invoked action:\n * - `store`: the store it is invoked on\n * - `name`: The name of the action\n * - `args`: The parameters passed to the action\n *\n * On top of these, it receives two functions that allow setting up a callback\n * once the action finishes or when it fails.\n *\n * It also returns a function to remove the callback. Note than when calling\n * `store.$onAction()` inside of a component, it will be automatically cleaned\n * up when the component gets unmounted unless `detached` is set to true.\n *\n * @example\n *\n *```js\n *store.$onAction(({ after, onError }) => {\n * // Here you could share variables between all of the hooks as well as\n * // setting up watchers and clean them up\n * after((resolvedValue) => {\n * // can be used to cleanup side effects\n * . // `resolvedValue` is the value returned by the action, if it's a\n * . // Promise, it will be the resolved value instead of the Promise\n * })\n * onError((error) => {\n * // can be used to pass up errors\n * })\n *})\n *```\n *\n * @param callback - callback called before every action\n * @param detached - detach the subscription from the context this is called from\n * @returns function that removes the watcher\n */\n $onAction(callback: StoreOnActionListener<Id, S, G, A>, detached?: boolean): () => void\n\n /**\n * Stops the associated effect scope of the store and remove it from the store\n * registry. Plugins can override this method to cleanup any added effects.\n * e.g. devtools plugin stops displaying disposed stores from devtools.\n * Note this doesn't delete the state of the store, you have to do it manually with\n * `delete pinia.state.value[store.$id]` if you want to. If you don't and the\n * store is used again, it will reuse the previous state.\n */\n $dispose(): void\n}\n\n/**\n * Generic type for a function that can infer arguments and return type\n *\n * For internal use **only**\n */\nexport type _Method = (...args: any[]) => any\n\n// export type StoreAction<P extends any[], R> = (...args: P) => R\n// export interface StoreAction<P, R> {\n// (...args: P[]): R\n// }\n\n// in this type we forget about this because otherwise the type is recursive\n/**\n * Store augmented for actions. For internal usage only.\n * For internal use **only**\n */\nexport type _StoreWithActions<A> = {\n [k in keyof A]: A[k] extends (...args: infer P) => infer R ? (...args: P) => R : never\n}\n\n/**\n * Store augmented with getters. For internal usage only.\n * For internal use **only**\n */\nexport type _StoreWithGetters<G> = _StoreWithGetters_Readonly<G> & _StoreWithGetters_Writable<G>\n\n/**\n * Store augmented with readonly getters. For internal usage **only**.\n */\nexport type _StoreWithGetters_Readonly<G> = {\n readonly [K in keyof G as G[K] extends (...args: any[]) => any\n ? K\n : ComputedRef extends G[K]\n ? K\n : never]: G[K] extends (...args: any[]) => infer R ? R : UnwrapRef<G[K]>\n}\n\n/**\n * Store augmented with writable getters. For internal usage **only**.\n */\nexport type _StoreWithGetters_Writable<G> = {\n [K in keyof G as G[K] extends WritableComputedRef<any>\n ? K\n : // NOTE: there is still no way to have a different type for a setter and a getter in TS with dynamic keys\n // https://github.com/microsoft/TypeScript/issues/43826\n never]: G[K] extends Readonly<WritableComputedRef<infer R>> ? R : never\n}\n\n/**\n * Store type to build a store.\n */\nexport type Store<\n Id extends string = string,\n S extends StateTree = {},\n G /* extends GettersTree<S>*/ = {},\n // has the actions without the context (this) for typings\n A /* extends ActionsTree */ = {}\n> = _StoreWithState<Id, S, G, A> &\n UnwrapRef<S> &\n _StoreWithGetters<G> &\n // StoreWithActions<A> &\n (_ActionsTree extends A ? {} : A) &\n PiniaCustomProperties<Id, S, G, A> &\n PiniaCustomStateProperties<S>\n\n/**\n * Generic and type-unsafe version of Store. Doesn't fail on access with\n * strings, making it much easier to write generic functions that do not care\n * about the kind of store that is passed.\n */\nexport type StoreGeneric = Store<string, StateTree, _GettersTree<StateTree>, _ActionsTree>\n\n/**\n * Return type of `defineStore()`. Function that allows instantiating a store.\n */\nexport interface StoreDefinition<\n Id extends string = string,\n S extends StateTree = StateTree,\n G /* extends GettersTree<S>*/ = _GettersTree<S>,\n A /* extends ActionsTree */ = _ActionsTree\n> {\n /**\n * Returns a store, creates it if necessary.\n *\n * @param pinia - Pinia instance to retrieve the store\n * @param hot - dev only hot module replacement\n */\n (pinia?: Pinia | null | undefined, hot?: StoreGeneric): Store<Id, S, G, A>\n\n /**\n * Id of the store. Used by map helpers.\n */\n $id: Id\n /**\n * Return to store for use within non-functional components\n */\n $getStore: () => Store<Id, S, G, A>\n /**\n * Dev only pinia for HMR.\n *\n * @internal\n */\n _pinia?: Pinia\n}\n\n/**\n * Interface to be extended by the user when they add properties through plugins.\n */\nexport interface PiniaCustomProperties<\n Id extends string = string,\n S extends StateTree = StateTree,\n G /* extends GettersTree<S> */ = _GettersTree<S>,\n A /* extends ActionsTree */ = _ActionsTree\n> {}\n\n/**\n * Properties that are added to every `store.$state` by `pinia.use()`.\n */\nexport interface PiniaCustomStateProperties<S extends StateTree = StateTree> {}\n\n/**\n * Type of an object of Getters that infers the argument. For internal usage only.\n * For internal use **only**\n */\nexport type _GettersTree<S extends StateTree> = Record<\n string,\n ((state: UnwrapRef<S> & UnwrapRef<PiniaCustomStateProperties<S>>) => any) | (() => any)\n>\n\n/**\n * Type of an object of Actions. For internal usage only.\n * For internal use **only**\n */\nexport type _ActionsTree = Record<string, _Method>\n\n/**\n * Type that enables refactoring through IDE.\n * For internal use **only**\n */\nexport type _ExtractStateFromSetupStore_Keys<SS> = keyof {\n [K in keyof SS as SS[K] extends _Method | ComputedRef ? never : K]: any\n}\n\n/**\n * Type that enables refactoring through IDE.\n * For internal use **only**\n */\nexport type _ExtractActionsFromSetupStore_Keys<SS> = keyof {\n [K in keyof SS as SS[K] extends _Method ? K : never]: any\n}\n\n/**\n * Type that enables refactoring through IDE.\n * For internal use **only**\n */\nexport type _ExtractGettersFromSetupStore_Keys<SS> = keyof {\n [K in keyof SS as SS[K] extends ComputedRef ? K : never]: any\n}\n\n/**\n * Type that enables refactoring through IDE.\n * For internal use **only**\n */\nexport type _UnwrapAll<SS> = { [K in keyof SS]: UnwrapRef<SS[K]> }\n\n/**\n * For internal use **only**\n */\nexport type _ExtractStateFromSetupStore<SS> = SS extends undefined | void\n ? {}\n : Pick<SS, _ExtractStateFromSetupStore_Keys<SS>>\n\n/**\n * For internal use **only**\n */\nexport type _ExtractActionsFromSetupStore<SS> = SS extends undefined | void\n ? {}\n : Pick<SS, _ExtractActionsFromSetupStore_Keys<SS>>\n\n/**\n * For internal use **only**\n */\nexport type _ExtractGettersFromSetupStore<SS> = SS extends undefined | void\n ? {}\n : Pick<SS, _ExtractGettersFromSetupStore_Keys<SS>>\n\n/**\n * Options passed to `defineStore()` that are common between option and setup\n * stores. Extend this interface if you want to add custom options to both kinds\n * of stores.\n */\nexport declare interface DefineStoreOptionsBase<S extends StateTree, Store> {}\n\n/**\n * Options parameter of `defineStore()` for option stores. Can be extended to\n * augment stores with the plugin API. @see {@link DefineStoreOptionsBase}.\n */\nexport interface DefineStoreOptions<\n Id extends string,\n S extends StateTree,\n G extends _GettersTree<S>,\n A /* extends Record<string, StoreAction> */\n> extends DefineStoreOptionsBase<S, Store<Id, S, G, A>> {\n /**\n * Unique string key to identify the store across the application.\n */\n id: Id\n\n /**\n * Function to create a fresh state. **Must be an arrow function** to ensure\n * correct typings!\n */\n state?: () => S\n\n /**\n * Optional object of getters.\n */\n getters?: G & ThisType<UnwrapRef<S> & _StoreWithGetters<G> & PiniaCustomProperties> & _GettersTree<S>\n\n /**\n * Optional object of actions.\n */\n actions?: A & ThisType<A & UnwrapRef<S> & _StoreWithState<Id, S, G, A> & _StoreWithGetters<G> & PiniaCustomProperties>\n\n /**\n * Allows hydrating the store during SSR when complex state (like client side only refs) are used in the store\n * definition and copying the value from `pinia.state` isn't enough.\n *\n * @example\n * If in your `state`, you use any `customRef`s, any `computed`s, or any `ref`s that have a different value on\n * Server and Client, you need to manually hydrate them. e.g., a custom ref that is stored in the local\n * storage:\n *\n * ```ts\n * const useStore = defineStore('main', {\n * state: () => ({\n * n: useLocalStorage('key', 0)\n * }),\n * hydrate(storeState, initialState) {\n * // @ts-expect-error: https://github.com/microsoft/TypeScript/issues/43826\n * storeState.n = useLocalStorage('key', 0)\n * }\n * })\n * ```\n *\n * @param storeState - the current state in the store\n * @param initialState - initialState\n */\n hydrate?(storeState: UnwrapRef<S>, initialState: UnwrapRef<S>): void\n}\n\n/**\n * Options parameter of `defineStore()` for setup stores. Can be extended to\n * augment stores with the plugin API. @see {@link DefineStoreOptionsBase}.\n */\nexport interface DefineSetupStoreOptions<\n Id extends string,\n // NOTE: Passing SS seems to make TS crash\n S extends StateTree,\n G,\n A /* extends ActionsTree */\n> extends DefineStoreOptionsBase<S, Store<Id, S, G, A>> {\n /**\n * Extracted actions. Added by useStore(). SHOULD NOT be added by the user when\n * creating the store. Can be used in plugins to get the list of actions in a\n * store defined with a setup function. Note this is always defined\n */\n actions?: A\n}\n\n/**\n * Available `options` when creating a pinia plugin.\n */\nexport interface DefineStoreOptionsInPlugin<Id extends string, S extends StateTree, G extends _GettersTree<S>, A>\n extends Omit<DefineStoreOptions<Id, S, G, A>, 'id' | 'actions'> {\n /**\n * Extracted object of actions. Added by useStore() when the store is built\n * using the setup API, otherwise uses the one passed to `defineStore()`.\n * Defaults to an empty object if no actions are defined.\n */\n actions: A\n}\n\n/**\n * Utility type. For internal use **only**\n */\nexport type _Empty = {}\n\n/**\n * Merges type objects for better readability in the code.\n * Utility type. For internal use **only**\n */\nexport type _Simplify<T> = _Empty extends T ? _Empty : { [key in keyof T]: T[key] } & {}\n\nexport type Fn = () => void\n","import { isReactive, isRef } from '@maoism/runtime-core'\nimport type { _DeepPartial, StateTree } from './types'\n\nexport function noop() {\n return {}\n}\n\nexport function isPlainObject<S extends StateTree>(value: S | unknown): value is S\nexport function isPlainObject(o: any): o is StateTree {\n return (\n o &&\n typeof o === 'object' &&\n Object.prototype.toString.call(o) === '[object Object]' &&\n typeof o.toJSON !== 'function'\n )\n}\n\nexport function mergeReactiveObjects<T extends Record<any, unknown> | Map<unknown, unknown> | Set<unknown>>(\n target: T,\n patchToApply: _DeepPartial<T>\n): T {\n // Handle Map instances\n if (target instanceof Map && patchToApply instanceof Map) {\n patchToApply.forEach((value, key) => target.set(key, value))\n }\n // Handle Set instances\n if (target instanceof Set && patchToApply instanceof Set) {\n patchToApply.forEach(target.add, target)\n }\n\n // no need to go through symbols because they cannot be serialized anyway\n for (const key in patchToApply) {\n // eslint-disable-next-line no-prototype-builtins\n if (!Object.hasOwn(patchToApply, key)) continue\n const subPatch = patchToApply[key]\n const targetValue = target[key]\n if (\n isPlainObject(targetValue) &&\n isPlainObject(subPatch) &&\n // biome-ignore lint/suspicious/noPrototypeBuiltins: <>\n target.hasOwnProperty(key) &&\n !isRef(subPatch) &&\n !isReactive(subPatch)\n ) {\n target[key] = mergeReactiveObjects(targetValue, subPatch)\n } else {\n // @ts-expect-error: subPatch is a valid value\n target[key] = subPatch\n }\n }\n\n return target\n}\n"],"mappings":";AAAA,SAAS,aAAa,SAAmB,WAAW;;;ACe7C,IAAM,iBAAiB,MAAM;AA+C7B,IAAI;AAEJ,SAAS,eAAe,QAAe;AAC5C,gBAAc;AAChB;;;AD3DO,SAAS,cAAqB;AACnC,QAAM,QAAQ,YAAY,IAAI;AAE9B,QAAM,QAAQ,MAAM,IAAoC,MAAM,IAA+B,CAAC,CAAC,CAAC;AAEhG,QAAM,KAAkB,CAAC;AAEzB,QAAM,QAAe,QAAQ;AAAA,IAC3B,IAAI,QAAQ;AACV,SAAG,KAAK,MAAM;AACd,aAAO;AAAA,IACT;AAAA,IACA;AAAA,IACA,IAAI;AAAA,IACJ,IAAI,oBAAI,IAA0B;AAAA,IAClC;AAAA,EACF,CAAC;AAED,iBAAe,KAAK;AAEpB,SAAO;AACT;;;AE5BA;AAAA,EACE;AAAA,EAEA;AAAA,EAGA,eAAAA;AAAA,EACA,WAAAC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAGA;AAAA,OACK;AACP,SAAS,aAAa,WAAW,OAAO,Q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AAAA,IACzB;AAEA,QAAI,SAAS,UAAU,IAAI,IAAI,OAAO;AACtC,QAAI,CAAC,QAAQ;AACX,YAAM,KAAK,MAAM;AACf,cAAM,gBAAgB,aAAa,IAAI,IAAI,OAAO;AAClD,YAAI,CAAC,aAAa,SAAS;AACzB,2BAAiB,UAAU,EAAE,GAAG,MAAM;AACtC,0BAAgB;AAAA,QAClB;AAAA,MACF;AAEA,eAAS,IAAI,eAAe,IAAIC,OAAM,MAAM;AAC1C,YAAI,QAAQ,MAAO,QAAO,IAAI;AAAA,MAChC,CAAC;AACD,mBAAa,QAAQ;AACrB,mBAAa,UAAU;AACvB,aAAO,IAAI;AACX,gBAAU,IAAI,IAAI,SAAS,MAAM;AACjC,mBAAa,UAAU;AAAA,IACzB;AAEA,WAAO;AAAA,EACT;AAEA,WAAS,MAAM;AACf,WAAS,YAAY,CAAC,UAAyB;AAC7C,QAAI,MAAO,gBAAe,KAAK;AAC/B,YAAQ;AACR,QAAI,CAAC,MAAM,GAAG,IAAI,EAAE,EAAG,oBAAmB,IAAI,SAAgB,KAAK;AACnE,UAAM,QAAQ,MAAM,GAAG,IAAI,EAAE;AAC7B,WAAO;AAAA,EACT;AACA,SAAO;AACT;","names":["effectScope","markRaw","activeComponentCleanUp","MutationType","noop","markRaw","store","$reset","options","effectScope","effect","noop"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pinia-react",
|
|
3
|
-
"version": "1.5.2-beta.
|
|
3
|
+
"version": "1.5.2-beta.2",
|
|
4
4
|
"description": "Intuitive, type safe and flexible Store for React",
|
|
5
5
|
"packageManager": "pnpm@10.14.0",
|
|
6
6
|
"type": "module",
|
|
@@ -32,11 +32,12 @@
|
|
|
32
32
|
"access": "public"
|
|
33
33
|
},
|
|
34
34
|
"scripts": {
|
|
35
|
+
"dev": "tsup --watch",
|
|
35
36
|
"build": "tsup",
|
|
36
37
|
"playground-react": "vite playground/react",
|
|
37
38
|
"playground-nextjs": "pnpm next dev ./playground/nextjs",
|
|
38
39
|
"test": "vitest",
|
|
39
|
-
"
|
|
40
|
+
"release": "release-it",
|
|
40
41
|
"test-dts": "tsc -p ./test-dts/tsconfig.json"
|
|
41
42
|
},
|
|
42
43
|
"keywords": [
|