@@ -228,6 +228,25 @@ function prepareRegisterParams(
|
228 | 228 | }; |
229 | 229 | } |
230 | 230 | |
| 231 | +function prepareUpdateValueJson<T>( |
| 232 | +key: string, |
| 233 | +updateValue: (current: T | undefined) => T | undefined, |
| 234 | +defaultTtlMs?: number, |
| 235 | +opts?: { ttlMs?: number }, |
| 236 | +): (current: unknown) => { valueJson: string; ttlMs?: number } | undefined { |
| 237 | +return (current) => { |
| 238 | +const next = updateValue(current as T | undefined); |
| 239 | +if (next === undefined) { |
| 240 | +return undefined; |
| 241 | +} |
| 242 | +const prepared = prepareRegisterParams(key, next, defaultTtlMs, opts); |
| 243 | +return { |
| 244 | +valueJson: prepared.valueJson, |
| 245 | + ...(prepared.ttlMs != null ? { ttlMs: prepared.ttlMs } : {}), |
| 246 | +}; |
| 247 | +}; |
| 248 | +} |
| 249 | + |
231 | 250 | function assertConsistentOptions( |
232 | 251 | pluginId: string, |
233 | 252 | namespace: string, |
@@ -294,17 +313,7 @@ function createKeyedStoreForPluginId<T>(
|
294 | 313 | namespace, |
295 | 314 | key: normalizedKey, |
296 | 315 | maxEntries, |
297 | | -updateValueJson: (current) => { |
298 | | -const next = updateValue(current as T | undefined); |
299 | | -if (next === undefined) { |
300 | | -return undefined; |
301 | | -} |
302 | | -const params = prepareRegisterParams(normalizedKey, next, defaultTtlMs, opts); |
303 | | -return { |
304 | | -valueJson: params.valueJson, |
305 | | - ...(params.ttlMs != null ? { ttlMs: params.ttlMs } : {}), |
306 | | -}; |
307 | | -}, |
| 316 | +updateValueJson: prepareUpdateValueJson(normalizedKey, updateValue, defaultTtlMs, opts), |
308 | 317 | ...(env ? { env } : {}), |
309 | 318 | }); |
310 | 319 | }, |
@@ -390,17 +399,7 @@ function createSyncKeyedStoreForPluginId<T>(
|
390 | 399 | namespace, |
391 | 400 | key: normalizedKey, |
392 | 401 | maxEntries, |
393 | | -updateValueJson: (current) => { |
394 | | -const next = updateValue(current as T | undefined); |
395 | | -if (next === undefined) { |
396 | | -return undefined; |
397 | | -} |
398 | | -const params = prepareRegisterParams(normalizedKey, next, defaultTtlMs, opts); |
399 | | -return { |
400 | | -valueJson: params.valueJson, |
401 | | - ...(params.ttlMs != null ? { ttlMs: params.ttlMs } : {}), |
402 | | -}; |
403 | | -}, |
| 402 | +updateValueJson: prepareUpdateValueJson(normalizedKey, updateValue, defaultTtlMs, opts), |
404 | 403 | ...(env ? { env } : {}), |
405 | 404 | }); |
406 | 405 | }, |
|