@asaidimu/utils-persistence 5.0.1 → 6.0.0
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.mts +36 -26
- package/index.d.ts +36 -26
- package/index.js +1 -1
- package/index.mjs +1 -1
- package/package.json +1 -1
package/index.d.mts
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* configuration object for initializing a persistence store.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* -
|
|
6
|
-
* -
|
|
4
|
+
* this configuration allows you to:
|
|
5
|
+
* - define the **schema/application version** of the data being persisted.
|
|
6
|
+
* - distinguish between multiple **applications** that may run on the same host
|
|
7
7
|
* (so they don’t overwrite each other’s storage).
|
|
8
|
-
* -
|
|
8
|
+
* - optionally provide an **upgrade handler** to migrate persisted data when
|
|
9
9
|
* the version changes.
|
|
10
10
|
*
|
|
11
|
-
* @template T
|
|
11
|
+
* @template T the type of data being persisted.
|
|
12
12
|
*/
|
|
13
13
|
interface StoreConfig<T> {
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
15
|
+
* the semantic version string (e.g., "1.0.0") of the data schema or application.
|
|
16
16
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
17
|
+
* this is used for version control and data migrations.
|
|
18
|
+
* when the persisted state’s version does not match the current version,
|
|
19
19
|
* the `onUpgrade` function will be invoked (if provided).
|
|
20
20
|
*/
|
|
21
21
|
version: string;
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
23
|
+
* a unique application identifier (e.g., "chat-app" or "my-dashboard").
|
|
24
24
|
*
|
|
25
|
-
*
|
|
26
|
-
* that might share the same persistence backend (e.g.,
|
|
25
|
+
* this prevents collisions between different apps or modules
|
|
26
|
+
* that might share the same persistence backend (e.g., localstorage).
|
|
27
27
|
*
|
|
28
|
-
*
|
|
28
|
+
* example: if two apps both persist under the key "user", the `app`
|
|
29
29
|
* value ensures they can be distinguished.
|
|
30
30
|
*/
|
|
31
31
|
app: string;
|
|
32
32
|
/**
|
|
33
|
-
*
|
|
33
|
+
* optional handler for upgrading persisted state across versions.
|
|
34
34
|
*
|
|
35
|
-
*
|
|
35
|
+
* this function will be called when the persisted state’s `version`
|
|
36
36
|
* does not match the `version` specified in this config.
|
|
37
37
|
*
|
|
38
|
-
* @param state
|
|
39
|
-
* - `data`:
|
|
40
|
-
* - `version`:
|
|
41
|
-
* - `app`:
|
|
38
|
+
* @param state the existing state object, including:
|
|
39
|
+
* - `data`: the current persisted data (or null if none exists).
|
|
40
|
+
* - `version`: the version string stored with the data.
|
|
41
|
+
* - `app`: the application identifier stored with the data.
|
|
42
42
|
*
|
|
43
|
-
* @returns
|
|
44
|
-
* - `state`:
|
|
45
|
-
* - `version`:
|
|
43
|
+
* @returns a new state object with:
|
|
44
|
+
* - `state`: the migrated data (or null if clearing/resetting).
|
|
45
|
+
* - `version`: the new version string (must match `config.version`).
|
|
46
46
|
*
|
|
47
|
-
*
|
|
47
|
+
* example:
|
|
48
48
|
* ```ts
|
|
49
|
-
*
|
|
49
|
+
* onupgrade: async ({ data, version, app }) => {
|
|
50
50
|
* if (version === "1.0.0") {
|
|
51
|
-
* //
|
|
52
|
-
* return { state: { ...data,
|
|
51
|
+
* // migrate from 1.0.0 to 2.0.0
|
|
52
|
+
* return { state: { ...data, newfield: "default" }, version: "2.0.0" };
|
|
53
53
|
* }
|
|
54
54
|
* return { state: data, version: "2.0.0" };
|
|
55
55
|
* }
|
|
@@ -63,6 +63,16 @@ interface StoreConfig<T> {
|
|
|
63
63
|
state: T | null;
|
|
64
64
|
version: string;
|
|
65
65
|
}>;
|
|
66
|
+
/**
|
|
67
|
+
* enables or disables developer mode for the persistence store.
|
|
68
|
+
*
|
|
69
|
+
* when set to `true`, the store may provide additional logging,
|
|
70
|
+
* verbose error reporting, or bypass certain production constraints
|
|
71
|
+
* (such as strict cache validation) to aid in debugging.
|
|
72
|
+
*
|
|
73
|
+
* @default false
|
|
74
|
+
*/
|
|
75
|
+
dev?: boolean;
|
|
66
76
|
}
|
|
67
77
|
interface SimplePersistence<T> {
|
|
68
78
|
/**
|
package/index.d.ts
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* configuration object for initializing a persistence store.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* -
|
|
6
|
-
* -
|
|
4
|
+
* this configuration allows you to:
|
|
5
|
+
* - define the **schema/application version** of the data being persisted.
|
|
6
|
+
* - distinguish between multiple **applications** that may run on the same host
|
|
7
7
|
* (so they don’t overwrite each other’s storage).
|
|
8
|
-
* -
|
|
8
|
+
* - optionally provide an **upgrade handler** to migrate persisted data when
|
|
9
9
|
* the version changes.
|
|
10
10
|
*
|
|
11
|
-
* @template T
|
|
11
|
+
* @template T the type of data being persisted.
|
|
12
12
|
*/
|
|
13
13
|
interface StoreConfig<T> {
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
15
|
+
* the semantic version string (e.g., "1.0.0") of the data schema or application.
|
|
16
16
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
17
|
+
* this is used for version control and data migrations.
|
|
18
|
+
* when the persisted state’s version does not match the current version,
|
|
19
19
|
* the `onUpgrade` function will be invoked (if provided).
|
|
20
20
|
*/
|
|
21
21
|
version: string;
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
23
|
+
* a unique application identifier (e.g., "chat-app" or "my-dashboard").
|
|
24
24
|
*
|
|
25
|
-
*
|
|
26
|
-
* that might share the same persistence backend (e.g.,
|
|
25
|
+
* this prevents collisions between different apps or modules
|
|
26
|
+
* that might share the same persistence backend (e.g., localstorage).
|
|
27
27
|
*
|
|
28
|
-
*
|
|
28
|
+
* example: if two apps both persist under the key "user", the `app`
|
|
29
29
|
* value ensures they can be distinguished.
|
|
30
30
|
*/
|
|
31
31
|
app: string;
|
|
32
32
|
/**
|
|
33
|
-
*
|
|
33
|
+
* optional handler for upgrading persisted state across versions.
|
|
34
34
|
*
|
|
35
|
-
*
|
|
35
|
+
* this function will be called when the persisted state’s `version`
|
|
36
36
|
* does not match the `version` specified in this config.
|
|
37
37
|
*
|
|
38
|
-
* @param state
|
|
39
|
-
* - `data`:
|
|
40
|
-
* - `version`:
|
|
41
|
-
* - `app`:
|
|
38
|
+
* @param state the existing state object, including:
|
|
39
|
+
* - `data`: the current persisted data (or null if none exists).
|
|
40
|
+
* - `version`: the version string stored with the data.
|
|
41
|
+
* - `app`: the application identifier stored with the data.
|
|
42
42
|
*
|
|
43
|
-
* @returns
|
|
44
|
-
* - `state`:
|
|
45
|
-
* - `version`:
|
|
43
|
+
* @returns a new state object with:
|
|
44
|
+
* - `state`: the migrated data (or null if clearing/resetting).
|
|
45
|
+
* - `version`: the new version string (must match `config.version`).
|
|
46
46
|
*
|
|
47
|
-
*
|
|
47
|
+
* example:
|
|
48
48
|
* ```ts
|
|
49
|
-
*
|
|
49
|
+
* onupgrade: async ({ data, version, app }) => {
|
|
50
50
|
* if (version === "1.0.0") {
|
|
51
|
-
* //
|
|
52
|
-
* return { state: { ...data,
|
|
51
|
+
* // migrate from 1.0.0 to 2.0.0
|
|
52
|
+
* return { state: { ...data, newfield: "default" }, version: "2.0.0" };
|
|
53
53
|
* }
|
|
54
54
|
* return { state: data, version: "2.0.0" };
|
|
55
55
|
* }
|
|
@@ -63,6 +63,16 @@ interface StoreConfig<T> {
|
|
|
63
63
|
state: T | null;
|
|
64
64
|
version: string;
|
|
65
65
|
}>;
|
|
66
|
+
/**
|
|
67
|
+
* enables or disables developer mode for the persistence store.
|
|
68
|
+
*
|
|
69
|
+
* when set to `true`, the store may provide additional logging,
|
|
70
|
+
* verbose error reporting, or bypass certain production constraints
|
|
71
|
+
* (such as strict cache validation) to aid in debugging.
|
|
72
|
+
*
|
|
73
|
+
* @default false
|
|
74
|
+
*/
|
|
75
|
+
dev?: boolean;
|
|
66
76
|
}
|
|
67
77
|
interface SimplePersistence<T> {
|
|
68
78
|
/**
|