@spoosh/plugin-invalidation 0.6.0 → 0.7.1
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/README.md +3 -3
- package/dist/index.d.mts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +4 -2
- package/dist/index.mjs +4 -2
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -30,7 +30,7 @@ When a mutation succeeds, related queries are automatically invalidated:
|
|
|
30
30
|
|
|
31
31
|
```typescript
|
|
32
32
|
// Creating a post at users/123/posts invalidates:
|
|
33
|
-
const { trigger } = useWrite((api) => api("users/:id/posts").POST);
|
|
33
|
+
const { trigger } = useWrite((api) => api("users/:id/posts").POST());
|
|
34
34
|
await trigger({ params: { id: 123 }, body: { title: "New Post" } });
|
|
35
35
|
|
|
36
36
|
// ✓ Invalidates: "users", "users/123", "users/123/posts"
|
|
@@ -45,7 +45,7 @@ import { invalidationPlugin } from "@spoosh/plugin-invalidation";
|
|
|
45
45
|
|
|
46
46
|
const spoosh = new Spoosh<ApiSchema, Error>("/api").use([invalidationPlugin()]);
|
|
47
47
|
|
|
48
|
-
const { trigger } = useWrite((api) => api("posts").POST);
|
|
48
|
+
const { trigger } = useWrite((api) => api("posts").POST());
|
|
49
49
|
await trigger({ body: { title: "New Post" } });
|
|
50
50
|
```
|
|
51
51
|
|
|
@@ -205,7 +205,7 @@ socket.on("full-sync", () => {
|
|
|
205
205
|
For scenarios like logout or user switching, combine `invalidate: "*"` with `clearCache` from `@spoosh/plugin-cache`:
|
|
206
206
|
|
|
207
207
|
```typescript
|
|
208
|
-
const { trigger } = useWrite((api) => api("auth/logout").POST);
|
|
208
|
+
const { trigger } = useWrite((api) => api("auth/logout").POST());
|
|
209
209
|
|
|
210
210
|
// Clear cache + trigger all queries to refetch
|
|
211
211
|
await trigger({
|
package/dist/index.d.mts
CHANGED
|
@@ -23,7 +23,8 @@ interface InvalidationPluginConfig {
|
|
|
23
23
|
*/
|
|
24
24
|
defaultMode?: InvalidationMode;
|
|
25
25
|
}
|
|
26
|
-
|
|
26
|
+
type InvalidationWriteOptions = object;
|
|
27
|
+
interface InvalidationWriteTriggerOptions<TSchema = unknown> {
|
|
27
28
|
/** Unified invalidation configuration */
|
|
28
29
|
invalidate?: InvalidateOption<TSchema>;
|
|
29
30
|
}
|
|
@@ -103,10 +104,11 @@ declare module "@spoosh/core" {
|
|
|
103
104
|
declare function invalidationPlugin(config?: InvalidationPluginConfig): SpooshPlugin<{
|
|
104
105
|
readOptions: InvalidationReadOptions;
|
|
105
106
|
writeOptions: InvalidationWriteOptions;
|
|
107
|
+
writeTriggerOptions: InvalidationWriteTriggerOptions;
|
|
106
108
|
infiniteReadOptions: InvalidationInfiniteReadOptions;
|
|
107
109
|
readResult: InvalidationReadResult;
|
|
108
110
|
writeResult: InvalidationWriteResult;
|
|
109
111
|
instanceApi: InvalidationInstanceApi;
|
|
110
112
|
}>;
|
|
111
113
|
|
|
112
|
-
export { type InvalidateOption, type InvalidationInfiniteReadOptions, type InvalidationMode, type InvalidationPluginConfig, type InvalidationPluginExports, type InvalidationReadOptions, type InvalidationReadResult, type InvalidationWriteOptions, type InvalidationWriteResult, invalidationPlugin };
|
|
114
|
+
export { type InvalidateOption, type InvalidationInfiniteReadOptions, type InvalidationMode, type InvalidationPluginConfig, type InvalidationPluginExports, type InvalidationReadOptions, type InvalidationReadResult, type InvalidationWriteOptions, type InvalidationWriteResult, type InvalidationWriteTriggerOptions, invalidationPlugin };
|
package/dist/index.d.ts
CHANGED
|
@@ -23,7 +23,8 @@ interface InvalidationPluginConfig {
|
|
|
23
23
|
*/
|
|
24
24
|
defaultMode?: InvalidationMode;
|
|
25
25
|
}
|
|
26
|
-
|
|
26
|
+
type InvalidationWriteOptions = object;
|
|
27
|
+
interface InvalidationWriteTriggerOptions<TSchema = unknown> {
|
|
27
28
|
/** Unified invalidation configuration */
|
|
28
29
|
invalidate?: InvalidateOption<TSchema>;
|
|
29
30
|
}
|
|
@@ -103,10 +104,11 @@ declare module "@spoosh/core" {
|
|
|
103
104
|
declare function invalidationPlugin(config?: InvalidationPluginConfig): SpooshPlugin<{
|
|
104
105
|
readOptions: InvalidationReadOptions;
|
|
105
106
|
writeOptions: InvalidationWriteOptions;
|
|
107
|
+
writeTriggerOptions: InvalidationWriteTriggerOptions;
|
|
106
108
|
infiniteReadOptions: InvalidationInfiniteReadOptions;
|
|
107
109
|
readResult: InvalidationReadResult;
|
|
108
110
|
writeResult: InvalidationWriteResult;
|
|
109
111
|
instanceApi: InvalidationInstanceApi;
|
|
110
112
|
}>;
|
|
111
113
|
|
|
112
|
-
export { type InvalidateOption, type InvalidationInfiniteReadOptions, type InvalidationMode, type InvalidationPluginConfig, type InvalidationPluginExports, type InvalidationReadOptions, type InvalidationReadResult, type InvalidationWriteOptions, type InvalidationWriteResult, invalidationPlugin };
|
|
114
|
+
export { type InvalidateOption, type InvalidationInfiniteReadOptions, type InvalidationMode, type InvalidationPluginConfig, type InvalidationPluginExports, type InvalidationReadOptions, type InvalidationReadResult, type InvalidationWriteOptions, type InvalidationWriteResult, type InvalidationWriteTriggerOptions, invalidationPlugin };
|
package/dist/index.js
CHANGED
|
@@ -25,14 +25,16 @@ __export(src_exports, {
|
|
|
25
25
|
module.exports = __toCommonJS(src_exports);
|
|
26
26
|
|
|
27
27
|
// src/plugin.ts
|
|
28
|
+
var import_core = require("@spoosh/core");
|
|
28
29
|
var PLUGIN_NAME = "spoosh:invalidation";
|
|
29
30
|
var INVALIDATION_DEFAULT_KEY = "invalidation:defaultMode";
|
|
30
31
|
function resolveModeTags(context, mode) {
|
|
32
|
+
const params = context.request.params;
|
|
31
33
|
switch (mode) {
|
|
32
34
|
case "all":
|
|
33
|
-
return context.tags;
|
|
35
|
+
return context.tags.map((tag) => (0, import_core.resolvePathString)(tag, params));
|
|
34
36
|
case "self":
|
|
35
|
-
return [context.path];
|
|
37
|
+
return [(0, import_core.resolvePathString)(context.path, params)];
|
|
36
38
|
case "none":
|
|
37
39
|
return [];
|
|
38
40
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
// src/plugin.ts
|
|
2
|
+
import { resolvePathString } from "@spoosh/core";
|
|
2
3
|
var PLUGIN_NAME = "spoosh:invalidation";
|
|
3
4
|
var INVALIDATION_DEFAULT_KEY = "invalidation:defaultMode";
|
|
4
5
|
function resolveModeTags(context, mode) {
|
|
6
|
+
const params = context.request.params;
|
|
5
7
|
switch (mode) {
|
|
6
8
|
case "all":
|
|
7
|
-
return context.tags;
|
|
9
|
+
return context.tags.map((tag) => resolvePathString(tag, params));
|
|
8
10
|
case "self":
|
|
9
|
-
return [context.path];
|
|
11
|
+
return [resolvePathString(context.path, params)];
|
|
10
12
|
case "none":
|
|
11
13
|
return [];
|
|
12
14
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spoosh/plugin-invalidation",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "Cache invalidation plugin for Spoosh - auto-invalidates after mutations",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -33,10 +33,10 @@
|
|
|
33
33
|
}
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@spoosh/core": ">=0.13.
|
|
36
|
+
"@spoosh/core": ">=0.13.2"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@spoosh/core": "0.13.
|
|
39
|
+
"@spoosh/core": "0.13.2",
|
|
40
40
|
"@spoosh/test-utils": "0.2.0"
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|