* 更新存储
(name: string, updates: Partial<StorageList>)
| 228 | * 更新存储 |
| 229 | */ |
| 230 | update(name: string, updates: Partial<StorageList>): StorageList | undefined { |
| 231 | const index = this.cache.findIndex(s => s.name === name) |
| 232 | if (index === -1) { |
| 233 | return undefined |
| 234 | } |
| 235 | |
| 236 | const existing = this.cache[index] |
| 237 | |
| 238 | // 使用类型断言来合并更新,绕过 exactOptionalPropertyTypes 限制 |
| 239 | this.cache[index] = { ...existing, ...updates } as StorageList |
| 240 | |
| 241 | const updated = this.cache[index] |
| 242 | |
| 243 | if (this.config.enableEventEmitter) { |
| 244 | this.emit(STORAGE_EVENTS.UPDATED, { |
| 245 | type: 'updated', |
| 246 | storage: updated, |
| 247 | timestamp: new Date(), |
| 248 | }) |
| 249 | } |
| 250 | |
| 251 | return updated |
| 252 | } |
| 253 | |
| 254 | /** |
| 255 | * 设置存储列表 (批量替换) |