@@ -17,6 +17,8 @@ export class EncryptStorage implements EncryptStorageInterface {
17
17
18
18
readonly #prefix: string ;
19
19
20
+ #multiple = false ;
21
+
20
22
readonly #stateManagementUse: boolean ;
21
23
22
24
readonly #doNotEncryptValues: boolean ;
@@ -81,7 +83,7 @@ export class EncryptStorage implements EncryptStorageInterface {
81
83
82
84
this . storage ?. setItem ( storageKey , encryptedValue ) ;
83
85
84
- if ( this . #notifyHandler) {
86
+ if ( this . #notifyHandler && ! this . #multiple ) {
85
87
this . #notifyHandler( {
86
88
type : 'set' ,
87
89
key,
@@ -94,9 +96,24 @@ export class EncryptStorage implements EncryptStorageInterface {
94
96
param : [ string , any ] [ ] ,
95
97
doNotEncrypt ?: boolean ,
96
98
) : void {
99
+ this . #multiple = true ;
97
100
param . forEach ( ( [ key , value ] ) => {
98
101
this . setItem ( key , value , doNotEncrypt ) ;
99
102
} ) ;
103
+
104
+ if ( this . #notifyHandler) {
105
+ const keys = param . map ( ( [ key ] ) => key ) ;
106
+ const values = param . map ( ( [ _ , value ] ) =>
107
+ typeof value === 'object' ? JSON . stringify ( value ) : String ( value ) ,
108
+ ) ;
109
+ this . #notifyHandler( {
110
+ type : 'setMultiple' ,
111
+ key : keys ,
112
+ value : values ,
113
+ } ) ;
114
+
115
+ this . #multiple = false ;
116
+ }
100
117
}
101
118
102
119
public getItem < T = any > ( key : string , doNotDecrypt = false ) : T | undefined {
@@ -109,7 +126,7 @@ export class EncryptStorage implements EncryptStorageInterface {
109
126
? item
110
127
: this . #encryptation. decrypt ( item ) ;
111
128
112
- if ( this . #stateManagementUse) {
129
+ if ( this . #stateManagementUse && ! this . #multiple ) {
113
130
if ( this . #notifyHandler) {
114
131
this . #notifyHandler( {
115
132
type : 'get' ,
@@ -159,12 +176,23 @@ export class EncryptStorage implements EncryptStorageInterface {
159
176
keys : string [ ] ,
160
177
doNotDecrypt ?: boolean ,
161
178
) : Record < string , any > {
179
+ this . #multiple = true ;
162
180
const result = keys . reduce ( ( accumulator : Record < string , any > , key ) => {
163
181
accumulator [ key ] = this . getItem ( key , doNotDecrypt ) ;
164
182
165
183
return accumulator ;
166
184
} , { } ) ;
167
185
186
+ if ( this . #notifyHandler) {
187
+ this . #notifyHandler( {
188
+ type : 'getMultiple' ,
189
+ key : keys ,
190
+ value : result ,
191
+ } ) ;
192
+
193
+ this . #multiple = false ;
194
+ }
195
+
168
196
return result ;
169
197
}
170
198
0 commit comments