diff --git a/package-lock.json b/package-lock.json index 81b9503a..4eadfce0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,7 +24,7 @@ "husky": "9.1.7", "jest": "29.7.0", "jest-environment-jsdom": "29.7.0", - "pinia": "2.2.2", + "pinia": "2.3.0", "prettier": "3.4.2", "rimraf": "6.0.1", "size-limit": "11.1.6", @@ -35,7 +35,7 @@ "vue": "3.5.13" }, "peerDependencies": { - "pinia": "^2.2.2" + "pinia": "^2.3.0" } }, "node_modules/@ampproject/remapping": { @@ -8768,9 +8768,9 @@ } }, "node_modules/pinia": { - "version": "2.2.2", - "resolved": "https://registry.npmjs.org/pinia/-/pinia-2.2.2.tgz", - "integrity": "sha512-ja2XqFWZC36mupU4z1ZzxeTApV7DOw44cV4dhQ9sGwun+N89v/XP7+j7q6TanS1u1tdbK4r+1BUx7heMaIdagA==", + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/pinia/-/pinia-2.3.0.tgz", + "integrity": "sha512-ohZj3jla0LL0OH5PlLTDMzqKiVw2XARmC1XYLdLWIPBMdhDW/123ZWr4zVAhtJm+aoSkFa13pYXskAvAscIkhQ==", "dev": true, "license": "MIT", "dependencies": { @@ -8781,46 +8781,15 @@ "url": "https://github.com/sponsors/posva" }, "peerDependencies": { - "@vue/composition-api": "^1.4.0", "typescript": ">=4.4.4", - "vue": "^2.6.14 || ^3.3.0" + "vue": "^2.7.0 || ^3.5.11" }, "peerDependenciesMeta": { - "@vue/composition-api": { - "optional": true - }, "typescript": { "optional": true } } }, - "node_modules/pinia/node_modules/vue-demi": { - "version": "0.14.10", - "resolved": "https://registry.npmjs.org/vue-demi/-/vue-demi-0.14.10.tgz", - "integrity": "sha512-nMZBOwuzabUO0nLgIcc6rycZEebF6eeUfaiQx9+WSk8e29IbLvPU9feI6tqW4kTo3hvoYAJkMh8n8D0fuISphg==", - "dev": true, - "hasInstallScript": true, - "license": "MIT", - "bin": { - "vue-demi-fix": "bin/vue-demi-fix.js", - "vue-demi-switch": "bin/vue-demi-switch.js" - }, - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/sponsors/antfu" - }, - "peerDependencies": { - "@vue/composition-api": "^1.0.0-rc.1", - "vue": "^3.0.0-0 || ^2.6.0" - }, - "peerDependenciesMeta": { - "@vue/composition-api": { - "optional": true - } - } - }, "node_modules/pirates": { "version": "4.0.6", "resolved": "https://registry.npmjs.org/pirates/-/pirates-4.0.6.tgz", @@ -10241,6 +10210,33 @@ "integrity": "sha512-3NaicyZ7N4B6cft4bfb7dOnPbE9CjLcx+6wZWAg5zwszfO4qXRh+U52dN5r5ZZfc6iMaxKCEcoH9CmxxoFZHLg==", "dev": true }, + "node_modules/vue-demi": { + "version": "0.14.10", + "resolved": "https://registry.npmjs.org/vue-demi/-/vue-demi-0.14.10.tgz", + "integrity": "sha512-nMZBOwuzabUO0nLgIcc6rycZEebF6eeUfaiQx9+WSk8e29IbLvPU9feI6tqW4kTo3hvoYAJkMh8n8D0fuISphg==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "bin": { + "vue-demi-fix": "bin/vue-demi-fix.js", + "vue-demi-switch": "bin/vue-demi-switch.js" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/antfu" + }, + "peerDependencies": { + "@vue/composition-api": "^1.0.0-rc.1", + "vue": "^3.0.0-0 || ^2.6.0" + }, + "peerDependenciesMeta": { + "@vue/composition-api": { + "optional": true + } + } + }, "node_modules/w3c-xmlserializer": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/w3c-xmlserializer/-/w3c-xmlserializer-4.0.0.tgz", diff --git a/package.json b/package.json index d8efb953..d37141cf 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "shvl": "^3.0.0" }, "peerDependencies": { - "pinia": "^2.2.2" + "pinia": "^2.3.0" }, "devDependencies": { "@babel/core": "7.26.0", @@ -63,7 +63,7 @@ "husky": "9.1.7", "jest": "29.7.0", "jest-environment-jsdom": "29.7.0", - "pinia": "2.2.2", + "pinia": "2.3.0", "prettier": "3.4.2", "rimraf": "6.0.1", "size-limit": "11.1.6", diff --git a/src/plugin.ts b/src/plugin.ts index 4c6f70b3..5d846c16 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -194,13 +194,13 @@ export function createPersistedStatePlugin( }, {} as any) } if (Array.isArray(options.excludePaths)) { - state = deserialize(serialize(state)) + state = deserialize(serialize(state as any)) options.excludePaths.forEach(function (path) { return shvl.set(state, path, void 0, void 0) }, {}) } - const value = serialize(state) + const value = serialize(state as any) const result = storage.setItem(key, value) if (result instanceof Promise) { ++pendingCount diff --git a/src/type.ts b/src/type.ts index b81fb78d..f80df943 100644 --- a/src/type.ts +++ b/src/type.ts @@ -1,4 +1,5 @@ import { StateTree, SubscriptionCallback } from 'pinia' +import { UnwrapRef } from 'vue' export interface IStorage { getItem: (key: string) => any | Promise @@ -47,7 +48,7 @@ export interface CommonOptions { * * @default (state, savedState) => savedState */ - merge?: (state: S, savedState: S) => S + merge?: (state: UnwrapRef, savedState: UnwrapRef) => UnwrapRef /** * When rehydrating, overwrite initial state (patch otherwise). @@ -61,7 +62,7 @@ export interface CommonOptions { * * @default JSON.stringify */ - serialize?: (state: S) => any + serialize?: (state: UnwrapRef) => any /** * This method will be called right after `storage.getItem`. @@ -123,7 +124,7 @@ export type StoreOptions = CommonOptions & { * * @default {value => value} */ - beforeHydrate?: (oldState: S) => void + beforeHydrate?: (oldState: UnwrapRef) => void } declare module 'pinia' {