zova-module-a-model 5.0.22 → 5.0.23
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zova-module-a-model",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.23",
|
|
4
4
|
"title": "a-model",
|
|
5
5
|
"zovaModule": {
|
|
6
6
|
"capabilities": {
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"@tanstack/vue-query": "^5.45.0",
|
|
56
56
|
"localforage": "^1.10.0"
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "624a81d8b0a58c276dd081ab612e7dcf37bd7f71"
|
|
59
59
|
}
|
|
@@ -18,7 +18,9 @@ export class BeanModelPersister<TScopeModule = unknown> extends BeanModelLast<TS
|
|
|
18
18
|
try {
|
|
19
19
|
const storedData = storage.getItem(storageKey);
|
|
20
20
|
if (!storedData) return undefined;
|
|
21
|
-
const persistedQuery = options.deserialize
|
|
21
|
+
const persistedQuery = options.deserialize
|
|
22
|
+
? options.deserialize(storedData as string, options.deserializeDefault!)
|
|
23
|
+
: options.deserializeDefault!(storedData as string);
|
|
22
24
|
|
|
23
25
|
if (persistedQuery.state.dataUpdatedAt) {
|
|
24
26
|
const queryAge = Date.now() - persistedQuery.state.dataUpdatedAt;
|
|
@@ -54,12 +56,15 @@ export class BeanModelPersister<TScopeModule = unknown> extends BeanModelLast<TS
|
|
|
54
56
|
const storage = this._getPersisterStorage(options, query);
|
|
55
57
|
if (!storage) return;
|
|
56
58
|
const storageKey = this._getPersisterStorageKey(options, query);
|
|
57
|
-
const
|
|
59
|
+
const params = {
|
|
58
60
|
state: query.state,
|
|
59
61
|
queryKey: query.queryKey,
|
|
60
62
|
queryHash: query.queryHash,
|
|
61
63
|
buster: options.buster,
|
|
62
|
-
}
|
|
64
|
+
};
|
|
65
|
+
const data = options.serialize
|
|
66
|
+
? options.serialize(params, options.serializeDefault!)
|
|
67
|
+
: options.serializeDefault!(params);
|
|
63
68
|
if (options.sync === true) {
|
|
64
69
|
storage.setItem(storageKey, data);
|
|
65
70
|
} else {
|
|
@@ -110,8 +115,8 @@ export class BeanModelPersister<TScopeModule = unknown> extends BeanModelLast<TS
|
|
|
110
115
|
options.maxAge = options.maxAge ?? this.scopeSelf.config.persister.maxAge[options.storage];
|
|
111
116
|
options.prefix = options.prefix ?? this._getPersisterPrefix();
|
|
112
117
|
options.buster = options.buster ?? this._getPersisterBuster();
|
|
113
|
-
options.
|
|
114
|
-
options.
|
|
118
|
+
options.serializeDefault = options.serializeDefault ?? JSON.stringify;
|
|
119
|
+
options.deserializeDefault = options.deserializeDefault ?? JSON.parse;
|
|
115
120
|
return options;
|
|
116
121
|
}
|
|
117
122
|
|
|
@@ -77,10 +77,10 @@ export class BeanModelUseQuery<TScopeModule = unknown> extends BeanModelQuery<TS
|
|
|
77
77
|
{
|
|
78
78
|
meta: {
|
|
79
79
|
persister: {
|
|
80
|
-
|
|
80
|
+
serializeDefault: (obj?: Query) => {
|
|
81
81
|
return this.$serializeLocal(obj);
|
|
82
82
|
},
|
|
83
|
-
|
|
83
|
+
deserializeDefault: (value?: string) => {
|
|
84
84
|
return this.$deserializeLocal(value);
|
|
85
85
|
},
|
|
86
86
|
},
|
|
@@ -139,10 +139,10 @@ export class BeanModelUseQuery<TScopeModule = unknown> extends BeanModelQuery<TS
|
|
|
139
139
|
{
|
|
140
140
|
meta: {
|
|
141
141
|
persister: {
|
|
142
|
-
|
|
142
|
+
serializeDefault: (obj?: Query) => {
|
|
143
143
|
return this.$serializeCookie(obj);
|
|
144
144
|
},
|
|
145
|
-
|
|
145
|
+
deserializeDefault: (value?: string) => {
|
|
146
146
|
const cookieType = options.meta.persister.cookieType;
|
|
147
147
|
return this.$deserializeCookie(this._cookieCoerce(value, cookieType));
|
|
148
148
|
},
|
package/src/types.ts
CHANGED
|
@@ -62,12 +62,14 @@ export interface QueryMetaPersister {
|
|
|
62
62
|
* How to serialize the data to storage.
|
|
63
63
|
* @default `JSON.stringify`
|
|
64
64
|
*/
|
|
65
|
-
serialize?: (persistedQuery: any) => any;
|
|
65
|
+
serialize?: (persistedQuery: any, serializeDefault: (persistedQuery: any) => any) => any;
|
|
66
|
+
serializeDefault?: (persistedQuery: any) => any;
|
|
66
67
|
/**
|
|
67
68
|
* How to deserialize the data from storage.
|
|
68
69
|
* @default `JSON.parse`
|
|
69
70
|
*/
|
|
70
|
-
deserialize?: (cachedString: any) => any;
|
|
71
|
+
deserialize?: (cachedString: any, deserializeDefault: (cachedString: any) => any) => any;
|
|
72
|
+
deserializeDefault?: (cachedString: any) => any;
|
|
71
73
|
prefix?: string;
|
|
72
74
|
buster?: string;
|
|
73
75
|
cookieType?: QueryMetaPersisterCookieType;
|