(input: {
current: AsyncStorage
legacyStore?: AsyncStorage
stores: AsyncStorage[]
keys: string[]
key: string
defaults: unknown
migrate?: (value: unknown) => unknown
})
| 296 | } |
| 297 | |
| 298 | async function migrateLegacyAsync(input: { |
| 299 | current: AsyncStorage |
| 300 | legacyStore?: AsyncStorage |
| 301 | stores: AsyncStorage[] |
| 302 | keys: string[] |
| 303 | key: string |
| 304 | defaults: unknown |
| 305 | migrate?: (value: unknown) => unknown |
| 306 | }) { |
| 307 | for (const store of input.stores) { |
| 308 | const raw = await store.getItem(input.key) |
| 309 | if (raw === null) continue |
| 310 | |
| 311 | const next = normalize(input.defaults, raw, input.migrate) |
| 312 | if (next === undefined) { |
| 313 | await removeAsync(store, input.key) |
| 314 | continue |
| 315 | } |
| 316 | await input.current.setItem(input.key, next) |
| 317 | await store.removeItem(input.key) |
| 318 | return next |
| 319 | } |
| 320 | |
| 321 | if (!input.legacyStore) return null |
| 322 | |
| 323 | for (const key of input.keys) { |
| 324 | const raw = await input.legacyStore.getItem(key) |
| 325 | if (raw === null) continue |
| 326 | |
| 327 | const next = normalize(input.defaults, raw, input.migrate) |
| 328 | if (next === undefined) { |
| 329 | await removeAsync(input.legacyStore, key) |
| 330 | continue |
| 331 | } |
| 332 | await input.current.setItem(input.key, next) |
| 333 | await input.legacyStore.removeItem(key) |
| 334 | return next |
| 335 | } |
| 336 | |
| 337 | return null |
| 338 | } |
| 339 | |
| 340 | function workspaceStorage(dir: string) { |
| 341 | const head = (dir.slice(0, 12) || "workspace").replace(/[^a-zA-Z0-9._-]/g, "-") |
no test coverage detected