@mmstack/resource 20.2.8 → 20.2.9

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/index.d.ts CHANGED
@@ -1,6 +1,13 @@
1
1
  import { HttpResponse, HttpInterceptorFn, HttpContext, HttpResourceOptions, HttpResourceRequest, HttpResourceRef, HttpHeaders } from '@angular/common/http';
2
2
  import { Signal, Injector, Provider, WritableSignal, ValueEqualityFn } from '@angular/core';
3
3
 
4
+ type StoredEntry<T> = Omit<CacheEntry<T>, 'timeout'>;
5
+ type CacheDB<T> = {
6
+ getAll: () => Promise<StoredEntry<T>[]>;
7
+ store: (value: StoredEntry<T>) => Promise<void>;
8
+ remove: (key: string) => Promise<void>;
9
+ };
10
+
4
11
  /**
5
12
  * Options for configuring the Least Recently Used (LRU) cache cleanup strategy.
6
13
  * @internal
@@ -61,8 +68,10 @@ type CleanupType = LRUCleanupType | OldsetCleanupType;
61
68
  declare class Cache<T> {
62
69
  protected readonly ttl: number;
63
70
  protected readonly staleTime: number;
71
+ private readonly db;
64
72
  private readonly internal;
65
73
  private readonly cleanupOpt;
74
+ private readonly id;
66
75
  /**
67
76
  * Destroys the cache instance, cleaning up any resources used by the cache.
68
77
  * This method is called automatically when the cache instance is garbage collected.
@@ -84,7 +93,7 @@ declare class Cache<T> {
84
93
  id: string;
85
94
  serialize: (value: T) => string;
86
95
  deserialize: (value: string) => T | null;
87
- });
96
+ }, db?: Promise<CacheDB<T>>);
88
97
  /** @internal */
89
98
  private getInternal;
90
99
  /**
@@ -125,7 +134,7 @@ declare class Cache<T> {
125
134
  * @param staleTime - (Optional) The stale time for this entry, in milliseconds. Overrides the default `staleTime`.
126
135
  * @param ttl - (Optional) The TTL for this entry, in milliseconds. Overrides the default `ttl`.
127
136
  */
128
- store(key: string, value: T, staleTime?: number, ttl?: number): void;
137
+ store(key: string, value: T, staleTime?: number, ttl?: number, persist?: boolean): void;
129
138
  private storeInternal;
130
139
  /**
131
140
  * Invalidates (removes) a cache entry.
@@ -155,9 +164,22 @@ type CacheOptions = {
155
164
  */
156
165
  cleanup?: Partial<CleanupType>;
157
166
  /**
158
- * Whether to synchronize cache across tabs. If provided, the cache will use a BroadcastChannel to send updates between tabs.
167
+ * Whether to synchronize cache across tabs. If true, the cache will use a BroadcastChannel to send updates between tabs.
168
+ */
169
+ syncTabs?: boolean;
170
+ /**
171
+ * Globally disable persistence of cache entries.
172
+ * If set to `false`, cache entries will not be persisted to the database.
173
+ * `true` means, cache entries can be persisted, they must still be opted into on the resource level & allowed by server headers.
174
+ * @default true
159
175
  */
160
- syncTabsId?: string;
176
+ persist?: boolean;
177
+ /**
178
+ * Version of the caches database, increment this if the interfaces change, this will cause the old data to be deleted.
179
+ * Minimum value is 1, so first increment should be 2.
180
+ * @default 1
181
+ */
182
+ version?: number;
161
183
  };
162
184
  /**
163
185
  * Provides the instance of the QueryCache for queryResource. This should probably be called
@@ -428,6 +450,11 @@ type ResourceCacheOptions = true | {
428
450
  * @default false - By default the resource will respect `Cache-Control` headers.
429
451
  */
430
452
  ignoreCacheControl?: boolean;
453
+ /**
454
+ * Whether to persist the cache entry in the local DB instance.
455
+ * @default false - By default, the cache entry is not persisted.
456
+ */
457
+ persist?: boolean;
431
458
  };
432
459
  /**
433
460
  * Options for configuring a `queryResource`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mmstack/resource",
3
- "version": "20.2.8",
3
+ "version": "20.2.9",
4
4
  "keywords": [
5
5
  "angular",
6
6
  "signals",