@spoosh/plugin-invalidation 0.2.0 → 0.3.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/README.md +10 -10
- package/dist/index.js +2 -1
- package/dist/index.mjs +2 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -16,13 +16,13 @@ Tags are automatically generated from the API path hierarchy:
|
|
|
16
16
|
|
|
17
17
|
```typescript
|
|
18
18
|
// Query tags are generated from the path:
|
|
19
|
-
useRead((api) => api.
|
|
19
|
+
useRead((api) => api("users").GET());
|
|
20
20
|
// → tags: ["users"]
|
|
21
21
|
|
|
22
|
-
useRead((api) => api.
|
|
22
|
+
useRead((api) => api("users/:id").GET({ params: { id: 123 } }));
|
|
23
23
|
// → tags: ["users", "users/123"]
|
|
24
24
|
|
|
25
|
-
useRead((api) => api
|
|
25
|
+
useRead((api) => api("users/:id/posts").GET({ params: { id: 123 } }));
|
|
26
26
|
// → tags: ["users", "users/123", "users/123/posts"]
|
|
27
27
|
```
|
|
28
28
|
|
|
@@ -30,8 +30,8 @@ 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
|
|
34
|
-
await trigger({ body: { title: "New Post" } });
|
|
33
|
+
const { trigger } = useWrite((api) => api("users/:id/posts").POST);
|
|
34
|
+
await trigger({ params: { id: 123 }, body: { title: "New Post" } });
|
|
35
35
|
|
|
36
36
|
// ✓ Invalidates: "users", "users/123", "users/123/posts"
|
|
37
37
|
// All queries matching these tags will refetch automatically
|
|
@@ -45,7 +45,7 @@ import { invalidationPlugin } from "@spoosh/plugin-invalidation";
|
|
|
45
45
|
|
|
46
46
|
const client = new Spoosh<ApiSchema, Error>("/api").use([invalidationPlugin()]);
|
|
47
47
|
|
|
48
|
-
const { trigger } = useWrite((api) => api
|
|
48
|
+
const { trigger } = useWrite((api) => api("posts").POST);
|
|
49
49
|
await trigger({ body: { title: "New Post" } });
|
|
50
50
|
```
|
|
51
51
|
|
|
@@ -81,7 +81,7 @@ await trigger({
|
|
|
81
81
|
await trigger({
|
|
82
82
|
body: { title: "New Post" },
|
|
83
83
|
autoInvalidate: "none",
|
|
84
|
-
invalidate: (api) => [api.
|
|
84
|
+
invalidate: (api) => [api("posts").GET, api("stats").GET, "dashboard-data"],
|
|
85
85
|
});
|
|
86
86
|
|
|
87
87
|
// Add specific tags (works alongside autoInvalidate)
|
|
@@ -127,7 +127,7 @@ const { useRead, invalidate } = createReactSpoosh(client);
|
|
|
127
127
|
invalidate(["users", "posts"]);
|
|
128
128
|
|
|
129
129
|
// Invalidate with callback (type-safe API selector)
|
|
130
|
-
invalidate((api) => [api.
|
|
130
|
+
invalidate((api) => [api("users").GET, api("posts").GET, "custom-tag"]);
|
|
131
131
|
|
|
132
132
|
// Useful for external events like WebSocket messages
|
|
133
133
|
socket.on("data-changed", (tags) => {
|
|
@@ -135,6 +135,6 @@ socket.on("data-changed", (tags) => {
|
|
|
135
135
|
});
|
|
136
136
|
```
|
|
137
137
|
|
|
138
|
-
| Method
|
|
139
|
-
|
|
|
138
|
+
| Method | Description |
|
|
139
|
+
| ------------ | ------------------------------------------------------------------ |
|
|
140
140
|
| `invalidate` | Manually invalidate cache entries by tags or API selector callback |
|
package/dist/index.js
CHANGED
|
@@ -39,7 +39,8 @@ function resolveTagsFromOption(invalidate) {
|
|
|
39
39
|
tags.push(target);
|
|
40
40
|
} else {
|
|
41
41
|
const path = (0, import_core.extractPathFromSelector)(target);
|
|
42
|
-
const
|
|
42
|
+
const pathSegments = path.split("/").filter(Boolean);
|
|
43
|
+
const derivedTags = (0, import_core.generateTags)(pathSegments);
|
|
43
44
|
const exactTag = derivedTags[derivedTags.length - 1];
|
|
44
45
|
if (exactTag) {
|
|
45
46
|
tags.push(exactTag);
|
package/dist/index.mjs
CHANGED
|
@@ -17,7 +17,8 @@ function resolveTagsFromOption(invalidate) {
|
|
|
17
17
|
tags.push(target);
|
|
18
18
|
} else {
|
|
19
19
|
const path = extractPathFromSelector(target);
|
|
20
|
-
const
|
|
20
|
+
const pathSegments = path.split("/").filter(Boolean);
|
|
21
|
+
const derivedTags = generateTags(pathSegments);
|
|
21
22
|
const exactTag = derivedTags[derivedTags.length - 1];
|
|
22
23
|
if (exactTag) {
|
|
23
24
|
tags.push(exactTag);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spoosh/plugin-invalidation",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Cache invalidation plugin for Spoosh - auto-invalidates after mutations",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -33,11 +33,11 @@
|
|
|
33
33
|
}
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@spoosh/core": ">=0.
|
|
36
|
+
"@spoosh/core": ">=0.6.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@spoosh/
|
|
40
|
-
"@spoosh/
|
|
39
|
+
"@spoosh/test-utils": "0.1.5",
|
|
40
|
+
"@spoosh/core": "0.6.0"
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|
|
43
43
|
"dev": "tsup --watch",
|