@angular-cool/repository 21.0.4 → 21.0.5
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
|
@@ -52,10 +52,10 @@ export class MyComponent {
|
|
|
52
52
|
|
|
53
53
|
protected myItem: Resource<ItemDTO | undefined> = this._myService.items.get(this.idParam);
|
|
54
54
|
|
|
55
|
-
protected updateItem() {
|
|
55
|
+
protected async updateItem() {
|
|
56
56
|
// Update item on the server here
|
|
57
57
|
|
|
58
|
-
this._myService.items.reload(this.idParam()); // This reloads the item from the server and updates the signal for all subscribers
|
|
58
|
+
await this._myService.items.reload(this.idParam()); // This reloads the item from the server and updates the signal for all subscribers
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
```
|
|
@@ -63,7 +63,23 @@ export class MyComponent {
|
|
|
63
63
|
### Manually update value if needed
|
|
64
64
|
|
|
65
65
|
```typescript
|
|
66
|
-
this._myService.items.setValue(this.idParam(), myValue); // Updates the signal for all subscribers
|
|
66
|
+
await this._myService.items.setValue(this.idParam(), myValue); // Updates the signal for all subscribers
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Manually get value if needed
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
const value = await this._myService.items.getValue(this.idParam());
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Manually update value if needed
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
await this._myService.items.updateValue(this.idParam(), val => {
|
|
79
|
+
// modify val
|
|
80
|
+
|
|
81
|
+
return val;
|
|
82
|
+
});
|
|
67
83
|
```
|
|
68
84
|
|
|
69
85
|
## License
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { rxResource } from '@angular/core/rxjs-interop';
|
|
2
|
-
import { ReplaySubject } from 'rxjs';
|
|
2
|
+
import { ReplaySubject, firstValueFrom } from 'rxjs';
|
|
3
3
|
|
|
4
4
|
class ResourceCache {
|
|
5
5
|
get isInvalid() {
|
|
@@ -25,6 +25,10 @@ class ResourceCache {
|
|
|
25
25
|
this._validUntil = Date.now() + this.maxAge;
|
|
26
26
|
this._subject.next(value);
|
|
27
27
|
}
|
|
28
|
+
async getValueAsync() {
|
|
29
|
+
await this.keepDataFreshAsync();
|
|
30
|
+
return firstValueFrom(this._subject);
|
|
31
|
+
}
|
|
28
32
|
invalidate() {
|
|
29
33
|
this._validUntil = null;
|
|
30
34
|
}
|
|
@@ -80,10 +84,26 @@ class ResourceRepository {
|
|
|
80
84
|
await cache.keepDataFreshAsync();
|
|
81
85
|
}
|
|
82
86
|
/**
|
|
83
|
-
*
|
|
87
|
+
* Retrieves a value from the cache associated with the specified key.
|
|
88
|
+
*
|
|
89
|
+
* @param {TParams} key - The key used to identify the cache entry.
|
|
90
|
+
* @return {Promise<TItem | undefined>} A promise that resolves with the retrieved value
|
|
91
|
+
* or undefined if the value does not exist.
|
|
92
|
+
* @throws {Error} If no cache is found for the given key.
|
|
93
|
+
*/
|
|
94
|
+
async getValue(key) {
|
|
95
|
+
const cacheKey = this._createCacheKey(key);
|
|
96
|
+
const cache = this._cacheStore.get(cacheKey);
|
|
97
|
+
if (!cache) {
|
|
98
|
+
throw new Error(`No cache found for the given key: ${key}`);
|
|
99
|
+
}
|
|
100
|
+
return await cache.getValueAsync();
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Sets a value in the cache associated with the given key and update all value subscribers
|
|
84
104
|
*
|
|
85
105
|
* @param {TParams} key - The unique key used to identify the cache.
|
|
86
|
-
* @param {TItem} value - The value to be stored in the cache
|
|
106
|
+
* @param {TItem} value - The value to be stored in the cache
|
|
87
107
|
* @return {Promise<void>} A promise that resolves when the value is successfully set.
|
|
88
108
|
*/
|
|
89
109
|
async setValue(key, value) {
|
|
@@ -94,6 +114,17 @@ class ResourceRepository {
|
|
|
94
114
|
}
|
|
95
115
|
await cache.setValueAsync(value);
|
|
96
116
|
}
|
|
117
|
+
/**
|
|
118
|
+
* Updates the value associated with the given key by applying an update function and update all value subscribers
|
|
119
|
+
*
|
|
120
|
+
* @param {TParams} key - The key whose value needs to be updated.
|
|
121
|
+
* @param {function(value: TItem | undefined): Promise<TItem>} updateFn - An asynchronous function that takes the current value (or undefined if not present) and returns the updated value.
|
|
122
|
+
* @return {Promise<void>} A promise that resolves when the update operation is complete.
|
|
123
|
+
*/
|
|
124
|
+
async updateValue(key, updateFn) {
|
|
125
|
+
const value = await this.getValue(key);
|
|
126
|
+
await this.setValue(key, await updateFn(value));
|
|
127
|
+
}
|
|
97
128
|
_createCacheKey(params) {
|
|
98
129
|
return (this.options.cacheKeyGenerator ?? JSON.stringify)(params);
|
|
99
130
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"angular-cool-repository.mjs","sources":["../../../projects/repository/src/lib/resource-cache.ts","../../../projects/repository/src/lib/resource-repository.ts","../../../projects/repository/src/angular-cool-repository.ts"],"sourcesContent":["import { ReplaySubject } from 'rxjs';\n\nexport class ResourceCache<TItem> {\n private _subject = new ReplaySubject<TItem | undefined>();\n private _validUntil: number | null = null;\n\n public get isInvalid(): boolean {\n return this._validUntil === null || Date.now() > this._validUntil;\n }\n\n constructor(\n private loader: () => Promise<TItem | undefined>,\n private maxAge: number,\n ) {\n }\n\n public getObservable() {\n return this._subject.asObservable();\n }\n\n public async keepDataFreshAsync() {\n if (!this.isInvalid) {\n return;\n }\n\n const data = await this.loader();\n\n await this.setValueAsync(data);\n }\n\n public async setValueAsync(value: TItem | undefined) {\n this._validUntil = Date.now() + this.maxAge;\n this._subject.next(value);\n }\n\n public invalidate() {\n this._validUntil = null;\n }\n}\n","import { Signal } from '@angular/core';\nimport { rxResource } from '@angular/core/rxjs-interop';\nimport { ResourceCache } from './resource-cache';\n\nconst DEFAULT_MAX_AGE = 5 * 60 * 1000;\n\ntype CacheKey = string;\n\nexport type ReloadableSignal<T> = Signal<T> & { reload: () => Promise<void> };\n\nclass ResourceRepository<TParams, TItem> {\n private _cacheStore = new Map<CacheKey, ResourceCache<TItem>>();\n\n constructor(private options: ResourceRepositoryOptions<TParams, TItem>) {\n }\n\n /**\n * Retrieves a resource cache\n *\n * @param {Signal<TParams>} key - A signal function used to resolve the parameters for retrieving or initializing the resource.\n * @return {ReloadableSignal<TItem | undefined>} A read-only signal containing the item associated with the provided key, already cached.\n */\n public get(key: Signal<TParams>): ReloadableSignal<TItem | undefined> {\n const resource = rxResource<TItem | undefined, TParams>({\n params: () => key(),\n stream: ({ params }) => {\n const cacheKey = this._createCacheKey(params);\n\n let cache = this._cacheStore.get(cacheKey);\n\n if (!cache) {\n cache = new ResourceCache(\n ((p) => () => this.options.loader(p))(params),\n this.options.maxAge ?? DEFAULT_MAX_AGE,\n );\n\n this._cacheStore.set(cacheKey, cache);\n }\n\n // Do not wait for it to load\n cache.keepDataFreshAsync();\n\n return cache.getObservable();\n }\n });\n\n const resultSignal = resource.asReadonly().value as ReloadableSignal<TItem | undefined>;\n\n resultSignal.reload = async () => {\n await this.reload(key());\n };\n\n return resultSignal;\n }\n\n /**\n * Reloads the cache associated with the given key, ensuring it is updated with fresh data.\n *\n * @param {TParams} key - The key used to identify the specific cache entry to reload.\n * @return {Promise<void>} A promise that resolves when the cache has been refreshed.\n * @throws {Error} If no cache is found for the provided key or if data loading fails.\n */\n public async reload(key: TParams): Promise<void> {\n const cacheKey = this._createCacheKey(key);\n\n const cache = this._cacheStore.get(cacheKey);\n\n if (!cache) {\n throw new Error(`No cache found for the given key: ${key}`);\n }\n\n cache.invalidate();\n\n await cache.keepDataFreshAsync();\n }\n\n /**\n * Sets a value in the cache associated with the given key.\n *\n * @param {TParams} key - The unique key used to identify the cache.\n * @param {TItem} value - The value to be stored in the cache.\n * @return {Promise<void>} A promise that resolves when the value is successfully set.\n */\n public async setValue(key: TParams, value: TItem): Promise<void> {\n const cacheKey = this._createCacheKey(key);\n\n let cache = this._cacheStore.get(cacheKey);\n\n if (!cache) {\n throw new Error(`No cache found for the given key: ${key}`);\n }\n\n await cache.setValueAsync(value);\n }\n\n private _createCacheKey(params: TParams): CacheKey {\n return (this.options.cacheKeyGenerator ?? JSON.stringify)(params) as CacheKey;\n }\n}\n\n/**\n * Configuration options for a ResourceRepository.\n * This interface provides options for customizing the behavior\n * of resource loading and caching mechanisms.\n *\n * @template TParams The type of the parameters used to load a resource.\n * @template TItem The type of the items being loaded or cached.\n *\n * @property loader A function responsible for loading a resource. It receives\n * parameters of type `TParams` and returns a Promise resolving to an item of type `TItem`.\n *\n * @property [maxAge] Optional. Specifies the maximum duration (in milliseconds)\n * for which a cached resource remains valid. Default: 5 minutes\n *\n * @property [cacheKeyGenerator] Optional. A function used to generate a unique\n * cache key based on the input parameters of type `TParams`. Default: JSON.stringify()\n */\nexport interface ResourceRepositoryOptions<TParams, TItem> {\n loader: (params: TParams) => Promise<TItem>;\n\n maxAge?: number;\n\n cacheKeyGenerator?: (params: TParams) => string;\n}\n\n/**\n * Creates a new instance of a ResourceRepository with the specified options.\n *\n * @param {ResourceRepositoryOptions<TParams, TItem>} options - The configuration options for the resource repository.\n * @return {ResourceRepository<TParams, TItem>} A new instance of ResourceRepository configured with the given options.\n */\nexport function resourceRepository<TParams, TItem>(options: ResourceRepositoryOptions<TParams, TItem>): ResourceRepository<TParams, TItem> {\n return new ResourceRepository<TParams, TItem>(options);\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;MAEa,aAAa,CAAA;AAIxB,IAAA,IAAW,SAAS,GAAA;AAClB,QAAA,OAAO,IAAI,CAAC,WAAW,KAAK,IAAI,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,WAAW;IACnE;IAEA,WAAA,CACU,MAAwC,EACxC,MAAc,EAAA;QADd,IAAA,CAAA,MAAM,GAAN,MAAM;QACN,IAAA,CAAA,MAAM,GAAN,MAAM;AATR,QAAA,IAAA,CAAA,QAAQ,GAAG,IAAI,aAAa,EAAqB;QACjD,IAAA,CAAA,WAAW,GAAkB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AC,KAAK,CAAC;IAClC;AAEQ,IAAA,eAAe,CAAC,MAAe,EAAA;AACrC,QAAA,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,iBAAiB,IAAI,IAAI,CAAC,SAAS,EAAE,MAAM,CAAa;IAC/E;AACD;AA2BD;;;;;AAKG;AACG,SAAU,kBAAkB,CAAiB,OAAkD,EAAA;AACnG,IAAA,OAAO,IAAI,kBAAkB,CAAiB,OAAO,CAAC;AACxD;;ACrIA;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"angular-cool-repository.mjs","sources":["../../../projects/repository/src/lib/resource-cache.ts","../../../projects/repository/src/lib/resource-repository.ts","../../../projects/repository/src/angular-cool-repository.ts"],"sourcesContent":["import { firstValueFrom, ReplaySubject } from 'rxjs';\n\nexport class ResourceCache<TItem> {\n private _subject = new ReplaySubject<TItem | undefined>();\n private _validUntil: number | null = null;\n\n public get isInvalid(): boolean {\n return this._validUntil === null || Date.now() > this._validUntil;\n }\n\n constructor(\n private loader: () => Promise<TItem | undefined>,\n private maxAge: number,\n ) {\n }\n\n public getObservable() {\n return this._subject.asObservable();\n }\n\n public async keepDataFreshAsync() {\n if (!this.isInvalid) {\n return;\n }\n\n const data = await this.loader();\n\n await this.setValueAsync(data);\n }\n\n public async setValueAsync(value: TItem | undefined) {\n this._validUntil = Date.now() + this.maxAge;\n this._subject.next(value);\n }\n\n public async getValueAsync(): Promise<TItem | undefined> {\n await this.keepDataFreshAsync();\n\n return firstValueFrom(this._subject);\n }\n\n public invalidate() {\n this._validUntil = null;\n }\n}\n","import { Signal } from '@angular/core';\nimport { rxResource } from '@angular/core/rxjs-interop';\nimport { ResourceCache } from './resource-cache';\n\nconst DEFAULT_MAX_AGE = 5 * 60 * 1000;\n\ntype CacheKey = string;\n\nexport type ReloadableSignal<T> = Signal<T> & { reload: () => Promise<void> };\n\nclass ResourceRepository<TParams, TItem> {\n private _cacheStore = new Map<CacheKey, ResourceCache<TItem>>();\n\n constructor(private options: ResourceRepositoryOptions<TParams, TItem>) {\n }\n\n /**\n * Retrieves a resource cache\n *\n * @param {Signal<TParams>} key - A signal function used to resolve the parameters for retrieving or initializing the resource.\n * @return {ReloadableSignal<TItem | undefined>} A read-only signal containing the item associated with the provided key, already cached.\n */\n public get(key: Signal<TParams>): ReloadableSignal<TItem | undefined> {\n const resource = rxResource<TItem | undefined, TParams>({\n params: () => key(),\n stream: ({ params }) => {\n const cacheKey = this._createCacheKey(params);\n\n let cache = this._cacheStore.get(cacheKey);\n\n if (!cache) {\n cache = new ResourceCache(\n ((p) => () => this.options.loader(p))(params),\n this.options.maxAge ?? DEFAULT_MAX_AGE,\n );\n\n this._cacheStore.set(cacheKey, cache);\n }\n\n // Do not wait for it to load\n cache.keepDataFreshAsync();\n\n return cache.getObservable();\n }\n });\n\n const resultSignal = resource.asReadonly().value as ReloadableSignal<TItem | undefined>;\n\n resultSignal.reload = async () => {\n await this.reload(key());\n };\n\n return resultSignal;\n }\n\n /**\n * Reloads the cache associated with the given key, ensuring it is updated with fresh data.\n *\n * @param {TParams} key - The key used to identify the specific cache entry to reload.\n * @return {Promise<void>} A promise that resolves when the cache has been refreshed.\n * @throws {Error} If no cache is found for the provided key or if data loading fails.\n */\n public async reload(key: TParams): Promise<void> {\n const cacheKey = this._createCacheKey(key);\n\n const cache = this._cacheStore.get(cacheKey);\n\n if (!cache) {\n throw new Error(`No cache found for the given key: ${key}`);\n }\n\n cache.invalidate();\n\n await cache.keepDataFreshAsync();\n }\n\n /**\n * Retrieves a value from the cache associated with the specified key.\n *\n * @param {TParams} key - The key used to identify the cache entry.\n * @return {Promise<TItem | undefined>} A promise that resolves with the retrieved value\n * or undefined if the value does not exist.\n * @throws {Error} If no cache is found for the given key.\n */\n public async getValue(key: TParams): Promise<TItem | undefined> {\n const cacheKey = this._createCacheKey(key);\n\n const cache = this._cacheStore.get(cacheKey);\n\n if (!cache) {\n throw new Error(`No cache found for the given key: ${key}`);\n }\n\n return await cache.getValueAsync();\n }\n\n /**\n * Sets a value in the cache associated with the given key and update all value subscribers\n *\n * @param {TParams} key - The unique key used to identify the cache.\n * @param {TItem} value - The value to be stored in the cache\n * @return {Promise<void>} A promise that resolves when the value is successfully set.\n */\n public async setValue(key: TParams, value: TItem): Promise<void> {\n const cacheKey = this._createCacheKey(key);\n\n let cache = this._cacheStore.get(cacheKey);\n\n if (!cache) {\n throw new Error(`No cache found for the given key: ${key}`);\n }\n\n await cache.setValueAsync(value);\n }\n\n /**\n * Updates the value associated with the given key by applying an update function and update all value subscribers\n *\n * @param {TParams} key - The key whose value needs to be updated.\n * @param {function(value: TItem | undefined): Promise<TItem>} updateFn - An asynchronous function that takes the current value (or undefined if not present) and returns the updated value.\n * @return {Promise<void>} A promise that resolves when the update operation is complete.\n */\n public async updateValue(key: TParams, updateFn: (value: TItem | undefined) => Promise<TItem>): Promise<void> {\n const value = await this.getValue(key);\n\n await this.setValue(key, await updateFn(value));\n }\n\n private _createCacheKey(params: TParams): CacheKey {\n return (this.options.cacheKeyGenerator ?? JSON.stringify)(params) as CacheKey;\n }\n}\n\n/**\n * Configuration options for a ResourceRepository.\n * This interface provides options for customizing the behavior\n * of resource loading and caching mechanisms.\n *\n * @template TParams The type of the parameters used to load a resource.\n * @template TItem The type of the items being loaded or cached.\n *\n * @property loader A function responsible for loading a resource. It receives\n * parameters of type `TParams` and returns a Promise resolving to an item of type `TItem`.\n *\n * @property [maxAge] Optional. Specifies the maximum duration (in milliseconds)\n * for which a cached resource remains valid. Default: 5 minutes\n *\n * @property [cacheKeyGenerator] Optional. A function used to generate a unique\n * cache key based on the input parameters of type `TParams`. Default: JSON.stringify()\n */\nexport interface ResourceRepositoryOptions<TParams, TItem> {\n loader: (params: TParams) => Promise<TItem>;\n\n maxAge?: number;\n\n cacheKeyGenerator?: (params: TParams) => string;\n}\n\n/**\n * Creates a new instance of a ResourceRepository with the specified options.\n *\n * @param {ResourceRepositoryOptions<TParams, TItem>} options - The configuration options for the resource repository.\n * @return {ResourceRepository<TParams, TItem>} A new instance of ResourceRepository configured with the given options.\n */\nexport function resourceRepository<TParams, TItem>(options: ResourceRepositoryOptions<TParams, TItem>): ResourceRepository<TParams, TItem> {\n return new ResourceRepository<TParams, TItem>(options);\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;MAEa,aAAa,CAAA;AAIxB,IAAA,IAAW,SAAS,GAAA;AAClB,QAAA,OAAO,IAAI,CAAC,WAAW,KAAK,IAAI,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,WAAW;IACnE;IAEA,WAAA,CACU,MAAwC,EACxC,MAAc,EAAA;QADd,IAAA,CAAA,MAAM,GAAN,MAAM;QACN,IAAA,CAAA,MAAM,GAAN,MAAM;AATR,QAAA,IAAA,CAAA,QAAQ,GAAG,IAAI,aAAa,EAAqB;QACjD,IAAA,CAAA,WAAW,GAAkB,IAAI;IAUzC;IAEO,aAAa,GAAA;AAClB,QAAA,OAAO,IAAI,CAAC,QAAQ,CAAC,YAAY,EAAE;IACrC;AAEO,IAAA,MAAM,kBAAkB,GAAA;AAC7B,QAAA,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;YACnB;QACF;AAEA,QAAA,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,EAAE;AAEhC,QAAA,MAAM,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC;IAChC;IAEO,MAAM,aAAa,CAAC,KAAwB,EAAA;QACjD,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,MAAM;AAC3C,QAAA,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC;IAC3B;AAEO,IAAA,MAAM,aAAa,GAAA;AACxB,QAAA,MAAM,IAAI,CAAC,kBAAkB,EAAE;AAE/B,QAAA,OAAO,cAAc,CAAC,IAAI,CAAC,QAAQ,CAAC;IACtC;IAEO,UAAU,GAAA;AACf,QAAA,IAAI,CAAC,WAAW,GA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AC,QAAQ,CAAC,GAAG,EAAE,MAAM,QAAQ,CAAC,KAAK,CAAC,CAAC;IACjD;AAEQ,IAAA,eAAe,CAAC,MAAe,EAAA;AACrC,QAAA,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,iBAAiB,IAAI,IAAI,CAAC,SAAS,EAAE,MAAM,CAAa;IAC/E;AACD;AA2BD;;;;;AAKG;AACG,SAAU,kBAAkB,CAAiB,OAAkD,EAAA;AACnG,IAAA,OAAO,IAAI,kBAAkB,CAAiB,OAAO,CAAC;AACxD;;ACtKA;;AAEG;;;;"}
|
package/package.json
CHANGED
|
@@ -23,13 +23,30 @@ declare class ResourceRepository<TParams, TItem> {
|
|
|
23
23
|
*/
|
|
24
24
|
reload(key: TParams): Promise<void>;
|
|
25
25
|
/**
|
|
26
|
-
*
|
|
26
|
+
* Retrieves a value from the cache associated with the specified key.
|
|
27
|
+
*
|
|
28
|
+
* @param {TParams} key - The key used to identify the cache entry.
|
|
29
|
+
* @return {Promise<TItem | undefined>} A promise that resolves with the retrieved value
|
|
30
|
+
* or undefined if the value does not exist.
|
|
31
|
+
* @throws {Error} If no cache is found for the given key.
|
|
32
|
+
*/
|
|
33
|
+
getValue(key: TParams): Promise<TItem | undefined>;
|
|
34
|
+
/**
|
|
35
|
+
* Sets a value in the cache associated with the given key and update all value subscribers
|
|
27
36
|
*
|
|
28
37
|
* @param {TParams} key - The unique key used to identify the cache.
|
|
29
|
-
* @param {TItem} value - The value to be stored in the cache
|
|
38
|
+
* @param {TItem} value - The value to be stored in the cache
|
|
30
39
|
* @return {Promise<void>} A promise that resolves when the value is successfully set.
|
|
31
40
|
*/
|
|
32
41
|
setValue(key: TParams, value: TItem): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Updates the value associated with the given key by applying an update function and update all value subscribers
|
|
44
|
+
*
|
|
45
|
+
* @param {TParams} key - The key whose value needs to be updated.
|
|
46
|
+
* @param {function(value: TItem | undefined): Promise<TItem>} updateFn - An asynchronous function that takes the current value (or undefined if not present) and returns the updated value.
|
|
47
|
+
* @return {Promise<void>} A promise that resolves when the update operation is complete.
|
|
48
|
+
*/
|
|
49
|
+
updateValue(key: TParams, updateFn: (value: TItem | undefined) => Promise<TItem>): Promise<void>;
|
|
33
50
|
private _createCacheKey;
|
|
34
51
|
}
|
|
35
52
|
/**
|