🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

pinia-plugin-data

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pinia-plugin-data - npm Package Compare versions

Package version was removed
This package version has been unpublished, mostly likely due to security reasons
Comparing version
0.0.9
to
0.0.10
+1
-9
lib/index.d.ts

@@ -7,11 +7,3 @@ import { PiniaPluginContext, StateTree } from 'pinia';

serializer?: Serializer;
/**
* Hook called before state is hydrated from storage.
* @default undefined
*/
beforeRestore?: (context: PiniaPluginContext) => void;
/**
* Hook called after state is hydrated from storage.
* @default undefined
*/
afterRestore?: (context: PiniaPluginContext) => void;

@@ -26,3 +18,3 @@ onExpire?(store: StateTree): boolean;

* @param store Store data has resumed durable
* @return true | undefaine The default is to reject, you to return a clear state. false Represents data retention
* @return true | undefined The default is to reject, you to return a clear state. false Represents data retention
*/

@@ -29,0 +21,0 @@ onExpire(store: StateTree): boolean;

+1
-1

@@ -1,1 +0,1 @@

import"pinia";import{shallowRef as e}from"vue";class t{key;storage;serializer;constructor(e,t,s){this.key=e,this.storage=t,this.serializer=s}beforeRestore(){}afterRestore(){}onExpire(e){return!1}}const s=e(window.localStorage);class r{getItem(e){return s.value.getItem(e)}setItem(e,t){s.value.setItem(e,t)}removeItem(e){s.value.removeItem(e)}}class i{deserialize(e){return JSON.parse(e)}serialize(e){return JSON.stringify(e)}}class o{state;slave;values=[];constructor(e){this.slave=e,this.state="onWaiting"}dispatch(e){e.dispatch().then((()=>Promise.resolve(e.onExpire()))).then(a({reset:e.reset}))}trigger(e){if(e.center)e.dispatch().then((()=>Promise.resolve(e.onExpire()))).then((t=>{t||void 0===t?(this.state="onReject",e.reset(),this.values.forEach((({reset:e})=>{e()}))):(this.state="onResolve",this.values.forEach(this.dispatch)),this.values.length=0}));else if("onResolve"===this.state)this.dispatch(e);else if("onWaiting"===this.state)this.values.push({dispatch:e.dispatch,reset:e.reset,onExpire:e.onExpire});else{if("onReject"!==this.state)throw new Error(`未知的${this.state}状态`);e.reset()}}}const n=new Map;function a(e){return t=>{(t||void 0===t)&&e.reset()}}const c=()=>{};function l(e,t){try{const s=e.serializer,r=e.key,i=e.storage,c=s.serialize(r),l=i.getItem(c);if(null===l)return;const h=s.deserialize(l),p=async()=>(await Promise.resolve(e.beforeRestore(t)),await Promise.resolve(t.store.$patch(h)),await Promise.resolve(e.afterRestore(t))),u=()=>{const e=t.options.state?.();e&&t.store.$patch(e),i.removeItem(c)};"slave"in e?function(e){const t=n.get(e);if(t)return t;{const t=new o(e);return n.set(e,t),t}}(e.slave).trigger({dispatch:p,center:e.center,reset:u,onExpire:()=>e.onExpire(t.store)}):p().then((()=>{Promise.resolve(e.onExpire(t.store)).then(a({reset:u}))}))}catch(e){throw e}}function h(e,s){const o=function(e,s){if("boolean"==typeof s)return new t(e.store.$id,new r,new i);{const t=s;return{key:t.key??e.store.$id,afterRestore:t.afterRestore??c,beforeRestore:t.beforeRestore??c,serializer:t.serializer??new i,storage:t.storage??new r,slave:t.slave??void 0,center:t.center??!1,onExpire:t.onExpire??(()=>!1)}}}(e,s);l(o,e),e.store.$subscribe(((e,t)=>{const s=o.serializer,r=o.key;o.storage.setItem(s.serialize(r),s.serialize(t))}),{deep:!0,detached:!0})}function p(e){e.options.persistence&&h(e,e.options.persistence)}export{p as default};
import"pinia";import{shallowRef as e}from"vue";class t{key;storage;serializer;constructor(e,t,s){this.key=e,this.storage=t,this.serializer=s}beforeRestore(){}afterRestore(){}onExpire(e){return!1}}const s=e(window.localStorage);class r{getItem(e){return s.value.getItem(e)}setItem(e,t){s.value.setItem(e,t)}removeItem(e){s.value.removeItem(e)}}class i{deserialize(e){return JSON.parse(e)}serialize(e){return JSON.stringify(e)}}class o{state;slave;values=[];constructor(e){this.slave=e,this.state="onWaiting"}dispatch(e){e.dispatch().then((()=>e.onExpire())).then(a({reset:e.reset}))}trigger(e){if(e.center)e.dispatch().then((()=>e.onExpire())).then((t=>{t||void 0===t?(this.state="onReject",e.reset(),this.values.forEach((({reset:e})=>{e()}))):(this.state="onResolve",this.values.forEach(this.dispatch)),this.values.length=0}));else if("onResolve"===this.state)this.dispatch(e);else if("onWaiting"===this.state)this.values.push({dispatch:e.dispatch,reset:e.reset,onExpire:e.onExpire});else{if("onReject"!==this.state)throw new Error(`未知的${this.state}状态`);e.reset()}}}const n=new Map;function a(e){return t=>{(t||void 0===t)&&e.reset}}const c=()=>{};function l(e,t){try{const s=e.serializer,r=e.key,i=e.storage,c=s.serialize(r),l=i.getItem(c);if(null===l)return;const h=s.deserialize(l),p=async()=>{await e.beforeRestore(t),await t.store.$patch(h),await e.afterRestore(t)},u=()=>{const e=t.options.state?.();e&&t.store.$patch(e),i.removeItem(c)};"slave"in e?function(e){const t=n.get(e);if(t)return t;{const t=new o(e);return n.set(e,t),t}}(e.slave).trigger({dispatch:p,center:e.center,reset:u,onExpire:()=>e.onExpire(t.store)}):p().then((()=>{Promise.resolve(e.onExpire(t.store)).then(a({reset:u}))}))}catch(e){throw e}}function h(e,s){const o=function(e,s){if("boolean"==typeof s)return new t(e.store.$id,new r,new i);{const t=s;return{key:t.key??e.store.$id,afterRestore:t.afterRestore??c,beforeRestore:t.beforeRestore??c,serializer:t.serializer??new i,storage:t.storage??new r,slave:t.slave??void 0,center:t.center??!1,onExpire:t.onExpire??(()=>!1)}}}(e,s);l(o,e),e.store.$subscribe(((e,t)=>{!function(e,t,s,r){t.setItem(s.serialize(r),s.serialize(e))}(t,o.storage,o.serializer,o.key)}),{deep:!0,detached:!0})}function p(e){e.options.persistence&&h(e,e.options.persistence)}export{p as default};

@@ -7,11 +7,3 @@ import { Serializer, StorageLike } from "./index";

serializer?: Serializer;
/**
* Hook called before state is hydrated from storage.
* @default undefined
*/
beforeRestore?: (context: PiniaPluginContext) => void;
/**
* Hook called after state is hydrated from storage.
* @default undefined
*/
afterRestore?: (context: PiniaPluginContext) => void;

@@ -26,3 +18,3 @@ onExpire?(store: StateTree): boolean;

* @param store Store data has resumed durable
* @return true | undefaine The default is to reject, you to return a clear state. false Represents data retention
* @return true | undefined The default is to reject, you to return a clear state. false Represents data retention
*/

@@ -29,0 +21,0 @@ onExpire(store: StateTree): boolean;

{
"name": "pinia-plugin-data",
"version": "0.0.9",
"version": "0.0.10",
"main": "./lib/index.min.js",

@@ -12,16 +12,18 @@ "types": "./lib/index.d.ts",

"peerDependencies": {
"pinia": "^2.0.17",
"vue": "^3.2.37"
"pinia": "^2.0.17"
},
"peerDependenciesMeta": {
"pinia": {
"optional": true
}
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^13.3.0",
"vue": "^3.2.37",
"@rollup/plugin-typescript": "^8.3.3",
"@vue/tsconfig": "^0.1.3",
"rollup": "^2.77.0",
"rollup-plugin-dts": "^4.2.2",
"rollup-plugin-filesize": "^9.1.2",
"rollup-plugin-terser": "^7.0.2",
"tslib": "^2.4.0",
"typescript": "~4.7.4",
"vite": "^3.0.2",
"rollup-plugin-filesize": "^9.1.2"
"typescript": "~4.7.4"
},

@@ -28,0 +30,0 @@ "author": "mauguin <2508192786@qq.com>",

@@ -38,5 +38,8 @@ # pinia 数据持久化

beforeRestore?: (context: PiniaPluginContext) => void;
afterRestore?: (context: PiniaPluginContext) => void | boolean;
afterRestore?: (context: PiniaPluginContext) => void ;
// 将当前的store恢复托管 到 center的store上
slave?: string;
center?: boolean;
//在任何地方恢复数据后执行查询是否过期 过期会删除缓存支持异步返回
onExpire:(store:StateTree):boolean;
}

@@ -43,0 +46,0 @@