@asaidimu/utils-cache 2.1.1 → 2.1.3

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.
Files changed (3) hide show
  1. package/index.d.mts +48 -1
  2. package/index.d.ts +48 -1
  3. package/package.json +2 -2
package/index.d.mts CHANGED
@@ -1,4 +1,51 @@
1
- import { S as SimplePersistence } from '../types-ZDD-bdCz.js';
1
+ interface SimplePersistence<T> {
2
+ /**
3
+ * Persists data to storage.
4
+ *
5
+ * @param id The **unique identifier of the *consumer instance*** making the change. This is NOT the ID of the data (`T`) itself.
6
+ * Think of it as the ID of the specific browser tab, component, or module that's currently interacting with the persistence layer.
7
+ * It should typically be a **UUID** generated once at the consumer instance's instantiation.
8
+ * This `id` is crucial for the `subscribe` method, helping to differentiate updates originating from the current instance versus other instances/tabs, thereby preventing self-triggered notification loops.
9
+ * @param state The state (of type T) to persist. This state is generally considered the **global or shared state** that all instances interact with.
10
+ * @returns `true` if the operation was successful, `false` if an error occurred. For asynchronous implementations (like `IndexedDBPersistence`), this returns a `Promise<boolean>`.
11
+ */
12
+ set(id: string, state: T): boolean | Promise<boolean>;
13
+ /**
14
+ * Retrieves the global persisted data from storage.
15
+ *
16
+ * @returns The retrieved state of type `T`, or `null` if no data is found or if an error occurs during retrieval/parsing.
17
+ * For asynchronous implementations, this returns a `Promise<T | null>`.
18
+ */
19
+ get(): (T | null) | (Promise<T | null>);
20
+ /**
21
+ * Subscribes to changes in the global persisted data that originate from *other* instances of your application (e.g., other tabs or independent components using the same persistence layer).
22
+ *
23
+ * @param id The **unique identifier of the *consumer instance* subscribing**. This allows the persistence implementation to filter out notifications that were initiated by the subscribing instance itself.
24
+ * @param callback The function to call when the global persisted data changes from *another* source. The new state (`T`) is passed as an argument to this callback.
25
+ * @returns A function that, when called, will unsubscribe the provided callback from future updates. Call this when your component or instance is no longer active to prevent memory leaks.
26
+ */
27
+ subscribe(id: string, callback: (state: T) => void): () => void;
28
+ /**
29
+ * Clears (removes) the entire global persisted data from storage.
30
+ *
31
+ * @returns `true` if the operation was successful, `false` if an error occurred. For asynchronous implementations, this returns a `Promise<boolean>`.
32
+ */
33
+ clear(): boolean | Promise<boolean>;
34
+ /**
35
+ * Returns metadata about the persistence layer.
36
+ *
37
+ * This is useful for distinguishing between multiple apps running on the same host
38
+ * (e.g., several apps served at `localhost:3000` that share the same storage key).
39
+ *
40
+ * @returns An object containing:
41
+ * - `version`: The semantic version string of the persistence schema or application.
42
+ * - `id`: A unique identifier for the application using this persistence instance.
43
+ */
44
+ stats(): {
45
+ version: string;
46
+ id: string;
47
+ };
48
+ }
2
49
 
3
50
  interface CacheOptions {
4
51
  staleTime?: number;
package/index.d.ts CHANGED
@@ -1,4 +1,51 @@
1
- import { S as SimplePersistence } from '../types-ZDD-bdCz.js';
1
+ interface SimplePersistence<T> {
2
+ /**
3
+ * Persists data to storage.
4
+ *
5
+ * @param id The **unique identifier of the *consumer instance*** making the change. This is NOT the ID of the data (`T`) itself.
6
+ * Think of it as the ID of the specific browser tab, component, or module that's currently interacting with the persistence layer.
7
+ * It should typically be a **UUID** generated once at the consumer instance's instantiation.
8
+ * This `id` is crucial for the `subscribe` method, helping to differentiate updates originating from the current instance versus other instances/tabs, thereby preventing self-triggered notification loops.
9
+ * @param state The state (of type T) to persist. This state is generally considered the **global or shared state** that all instances interact with.
10
+ * @returns `true` if the operation was successful, `false` if an error occurred. For asynchronous implementations (like `IndexedDBPersistence`), this returns a `Promise<boolean>`.
11
+ */
12
+ set(id: string, state: T): boolean | Promise<boolean>;
13
+ /**
14
+ * Retrieves the global persisted data from storage.
15
+ *
16
+ * @returns The retrieved state of type `T`, or `null` if no data is found or if an error occurs during retrieval/parsing.
17
+ * For asynchronous implementations, this returns a `Promise<T | null>`.
18
+ */
19
+ get(): (T | null) | (Promise<T | null>);
20
+ /**
21
+ * Subscribes to changes in the global persisted data that originate from *other* instances of your application (e.g., other tabs or independent components using the same persistence layer).
22
+ *
23
+ * @param id The **unique identifier of the *consumer instance* subscribing**. This allows the persistence implementation to filter out notifications that were initiated by the subscribing instance itself.
24
+ * @param callback The function to call when the global persisted data changes from *another* source. The new state (`T`) is passed as an argument to this callback.
25
+ * @returns A function that, when called, will unsubscribe the provided callback from future updates. Call this when your component or instance is no longer active to prevent memory leaks.
26
+ */
27
+ subscribe(id: string, callback: (state: T) => void): () => void;
28
+ /**
29
+ * Clears (removes) the entire global persisted data from storage.
30
+ *
31
+ * @returns `true` if the operation was successful, `false` if an error occurred. For asynchronous implementations, this returns a `Promise<boolean>`.
32
+ */
33
+ clear(): boolean | Promise<boolean>;
34
+ /**
35
+ * Returns metadata about the persistence layer.
36
+ *
37
+ * This is useful for distinguishing between multiple apps running on the same host
38
+ * (e.g., several apps served at `localhost:3000` that share the same storage key).
39
+ *
40
+ * @returns An object containing:
41
+ * - `version`: The semantic version string of the persistence schema or application.
42
+ * - `id`: A unique identifier for the application using this persistence instance.
43
+ */
44
+ stats(): {
45
+ version: string;
46
+ id: string;
47
+ };
48
+ }
2
49
 
3
50
  interface CacheOptions {
4
51
  staleTime?: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@asaidimu/utils-cache",
3
- "version": "2.1.1",
3
+ "version": "2.1.3",
4
4
  "description": "Resource and cache management utilities for @asaidimu applications.",
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",
@@ -30,7 +30,7 @@
30
30
  "access": "public"
31
31
  },
32
32
  "dependencies": {
33
- "@asaidimu/utils-persistence": "2.1.0",
33
+ "@asaidimu/utils-persistence": "2.2.1",
34
34
  "uuid": "^11.1.0",
35
35
  "@asaidimu/events": "^1.1.1"
36
36
  },