@unisian/start 0.8.1 → 0.8.2
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/dist/client.mjs +19 -8
- package/package.json +5 -5
package/dist/client.mjs
CHANGED
|
@@ -81,7 +81,24 @@ const cachedQuery = (client, options) => {
|
|
|
81
81
|
staleTime: "static"
|
|
82
82
|
}).then(Option.some);
|
|
83
83
|
};
|
|
84
|
-
const
|
|
84
|
+
const isFetching = (cached) => cached.state.fetchStatus !== "idle";
|
|
85
|
+
const isUnobserved = (cached) => cached.getObserversCount() === 0;
|
|
86
|
+
const refreshOnceFetched = (client, fetchedBeforeWrite) => {
|
|
87
|
+
const refresh = () => {
|
|
88
|
+
if (isFetching(fetchedBeforeWrite)) return;
|
|
89
|
+
if (isUnobserved(fetchedBeforeWrite)) client.getQueryCache().remove(fetchedBeforeWrite);
|
|
90
|
+
else client.invalidateQueries({
|
|
91
|
+
exact: true,
|
|
92
|
+
queryKey: fetchedBeforeWrite.queryKey
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
fetchedBeforeWrite.promise?.then(refresh, refresh);
|
|
96
|
+
};
|
|
97
|
+
const refreshAfterWrite = (client, name) => {
|
|
98
|
+
for (const cached of client.getQueryCache().findAll({ queryKey: [name] })) if (isFetching(cached)) refreshOnceFetched(client, cached);
|
|
99
|
+
else if (isUnobserved(cached)) client.getQueryCache().remove(cached);
|
|
100
|
+
return client.invalidateQueries({ queryKey: [name] });
|
|
101
|
+
};
|
|
85
102
|
const command = (contract, serverFn, options) => {
|
|
86
103
|
const { encodeInput, decodeOutput, call } = callerFor(contract, serverFn);
|
|
87
104
|
return mutationOptions({
|
|
@@ -89,13 +106,7 @@ const command = (contract, serverFn, options) => {
|
|
|
89
106
|
try {
|
|
90
107
|
return decodeOutput(await call(encodeInput(input), options));
|
|
91
108
|
} finally {
|
|
92
|
-
await Promise.all(options.invalidates.map(({ name }) =>
|
|
93
|
-
client.removeQueries({
|
|
94
|
-
predicate: unobservedAndIdle,
|
|
95
|
-
queryKey: [name]
|
|
96
|
-
});
|
|
97
|
-
return client.invalidateQueries({ queryKey: [name] });
|
|
98
|
-
}));
|
|
109
|
+
await Promise.all(options.invalidates.map(({ name }) => refreshAfterWrite(client, name)));
|
|
99
110
|
}
|
|
100
111
|
},
|
|
101
112
|
mutationKey: keyFor([contract.name], options)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unisian/start",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"effect": "4.0.6",
|
|
33
33
|
"react": "19.3.0",
|
|
34
34
|
"vite": "npm:@voidzero-dev/vite-plus-core@1.1.0",
|
|
35
|
-
"@unisian/capability": "0.8.
|
|
36
|
-
"@unisian/effect-observability": "0.8.
|
|
35
|
+
"@unisian/capability": "0.8.2",
|
|
36
|
+
"@unisian/effect-observability": "0.8.2"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"@tanstack/react-query": "^5.104.1",
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"@tanstack/react-start": "^1.168.60",
|
|
43
43
|
"effect": "^4.0.2",
|
|
44
44
|
"react": "^19.3.0",
|
|
45
|
-
"@unisian/
|
|
46
|
-
"@unisian/
|
|
45
|
+
"@unisian/capability": "0.8.2",
|
|
46
|
+
"@unisian/effect-observability": "0.8.2"
|
|
47
47
|
},
|
|
48
48
|
"scripts": {}
|
|
49
49
|
}
|