pinia-plugin-persist-state 0.0.0-alpha.1 → 0.0.0-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/README.md CHANGED
@@ -33,7 +33,7 @@ import { createPersistStatePlugin } from 'persist-pinia-state'
33
33
  const app = createApp(App)
34
34
  const pinia = createPinia()
35
35
 
36
- // Pass `dbName` (e.g. 'localStorage' or a DB name for IndexedDB)
36
+ // Pass `dbName` (e.g. 'localStorage', 'sessionStorage' or a DB name for IndexedDB)
37
37
  // and an optional `cryptKey` to enable encryption support
38
38
  pinia.use(createPlugin([
39
39
  createPersistStatePlugin('localStorage', 'my-secret-key')
@@ -49,8 +49,21 @@ app.use(pinia)
49
49
  When defining a store you can pass `storeOptions` (type: `PersistedStoreOptions`) as part of the `defineStore` options. Example in `src/stores/test.ts`:
50
50
 
51
51
  ```ts
52
+ // -- using defineAStore
53
+
54
+ export const useTestStore = defineAStore('testStore', () => {
55
+ const myString = ref('Hello World')
56
+ const myStringEncrypted = ref('Sensitive Data')
57
+
58
+ return { myString, myStringEncrypted }
59
+ }, {
60
+ persistedPropertiesToEncrypt: ['myStringEncrypted'],
61
+ watchMutation: true
62
+ })
63
+
64
+ // -- or using defineStore
65
+
52
66
  const storeOptions = {
53
- persist: true,
54
67
  persistedPropertiesToEncrypt: ['myStringEncrypted'],
55
68
  watchMutation: true
56
69
  }
@@ -63,7 +76,7 @@ export const useTestStore = defineStore('testStore', () => {
63
76
  }, { storeOptions })
64
77
  ```
65
78
 
66
- If `persist` is `true` the plugin will attempt to persist the store state using the configured persister (localStorage/sessionStorage/IndexedDB).
79
+ If `persist` or `watchMutation` are `true` the plugin will attempt to persist the store state using the configured persister: localStorage, sessionStorage or IndexedDB.
67
80
 
68
81
  ---
69
82
 
@@ -71,9 +84,8 @@ If `persist` is `true` the plugin will attempt to persist the store state using
71
84
 
72
85
  Fields available when setting `storeOptions`:
73
86
 
74
- - `dbName?: string` — (Optional) Name of the database/storage to use. Use `'localStorage'` or `'sessionStorage'` for window storage, or any other name to use IndexedDB.
75
- - `excludedKeys?: string[]` — Keys that should NOT be persisted.
76
- - `isEncrypted?: boolean` — Internal flag used to reflect whether the persisted state is currently encrypted.
87
+ - `dbName?: string` — (Optional) Name of the database/storage to use to persist the store state (use only if different from the one defined in the plugin). Use `'localStorage'` or `'sessionStorage'` for window storage, or any other name to use IndexedDB.
88
+ - `excludedKeys?: string[]` — List of state properties that should NOT be persisted.
77
89
  - `persist?: boolean` — Enable or disable persistence for the store (default: `false`).
78
90
  - `persistedPropertiesToEncrypt?: string[]` — List of property names to be encrypted when persisted.
79
91
  - `watchMutation?: boolean` — When `true`, plugin watches store mutations and automatically persists changes.
@@ -104,6 +116,7 @@ The plugin uses the Web Crypto API (PBKDF2 + AES-GCM) to encrypt properties list
104
116
  ## 💡 Notes
105
117
 
106
118
  - The plugin augments Pinia store definitions using the `pinia-plugin-subscription` helper. It adds `storeOptions` to Pinia's `DefineStoreOptionsBase` type through declaration merging.
119
+ - The $reset method is available for stores augmented by the plugin (also setup store 😁).
107
120
  - When using IndexedDB, the persister stores objects with a `storeName` key path.
108
121
 
109
122
  ---