@spoosh/plugin-prefetch 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 CHANGED
@@ -64,10 +64,41 @@ await prefetch(
64
64
 
65
65
  The second argument to `prefetch()` accepts any plugin options (staleTime, retries, dedupe, etc.) plus:
66
66
 
67
- | Option | Type | Description |
68
- | ---------------- | ---------- | ------------------------- |
69
- | `tags` | `string[]` | Custom cache tags |
70
- | `additionalTags` | `string[]` | Additional tags to append |
67
+ | Option | Type | Description |
68
+ | ------ | --------------------------------------- | -------------------------------------------------- |
69
+ | `tags` | `'all' \| 'self' \| 'none' \| string[]` | Tag mode or custom tags (replaces `additionalTags`) |
70
+
71
+ **Examples:**
72
+
73
+ ```typescript
74
+ // Mode only - 'all' generates full hierarchy
75
+ await prefetch((api) => api("users/:id/posts").GET({ params: { id: '123' } }), {
76
+ tags: 'all' // ['users', 'users/123', 'users/123/posts']
77
+ });
78
+
79
+ // Mode only - 'self' generates only exact path
80
+ await prefetch((api) => api("users/:id/posts").GET({ params: { id: '123' } }), {
81
+ tags: 'self' // ['users/123/posts']
82
+ });
83
+
84
+ // Mode only - 'none' generates no tags
85
+ await prefetch((api) => api("posts").GET(), { tags: 'none' }); // []
86
+
87
+ // Custom tags only - replaces auto-generated tags
88
+ await prefetch((api) => api("posts").GET(), {
89
+ tags: ['custom', 'dashboard'] // ['custom', 'dashboard']
90
+ });
91
+
92
+ // Mode + custom tags - 'all' mode combined with custom tags
93
+ await prefetch((api) => api("users/:id/posts").GET({ params: { id: '123' } }), {
94
+ tags: ['all', 'dashboard'] // ['users', 'users/123', 'users/123/posts', 'dashboard']
95
+ });
96
+
97
+ // Mode + custom tags - 'self' mode combined with custom tags
98
+ await prefetch((api) => api("users/:id/posts").GET({ params: { id: '123' } }), {
99
+ tags: ['self', 'dashboard'] // ['users/123/posts', 'dashboard']
100
+ });
101
+ ```
71
102
 
72
103
  ## Features
73
104
 
package/dist/index.js CHANGED
@@ -57,7 +57,7 @@ function prefetchPlugin(config = {}) {
57
57
  instanceApi(context) {
58
58
  const { api, stateManager, eventEmitter, pluginExecutor } = context;
59
59
  const prefetch = async (selector, options = {}) => {
60
- const { tags, additionalTags } = options;
60
+ const { tags } = options;
61
61
  let callPath = "";
62
62
  let callMethod = "";
63
63
  let callOptions = void 0;
@@ -79,10 +79,7 @@ function prefetchPlugin(config = {}) {
79
79
  }
80
80
  const pathSegments = callPath.split("/").filter(Boolean);
81
81
  const resolvedPath = (0, import_core.resolvePath)(pathSegments, void 0);
82
- const resolvedTags = (0, import_core.resolveTags)(
83
- { tags, additionalTags },
84
- resolvedPath
85
- );
82
+ const resolvedTags = (0, import_core.resolveTags)({ tags }, resolvedPath);
86
83
  const queryKey = stateManager.createQueryKey({
87
84
  path: pathSegments,
88
85
  method: callMethod,
package/dist/index.mjs CHANGED
@@ -36,7 +36,7 @@ function prefetchPlugin(config = {}) {
36
36
  instanceApi(context) {
37
37
  const { api, stateManager, eventEmitter, pluginExecutor } = context;
38
38
  const prefetch = async (selector, options = {}) => {
39
- const { tags, additionalTags } = options;
39
+ const { tags } = options;
40
40
  let callPath = "";
41
41
  let callMethod = "";
42
42
  let callOptions = void 0;
@@ -58,10 +58,7 @@ function prefetchPlugin(config = {}) {
58
58
  }
59
59
  const pathSegments = callPath.split("/").filter(Boolean);
60
60
  const resolvedPath = resolvePath(pathSegments, void 0);
61
- const resolvedTags = resolveTags(
62
- { tags, additionalTags },
63
- resolvedPath
64
- );
61
+ const resolvedTags = resolveTags({ tags }, resolvedPath);
65
62
  const queryKey = stateManager.createQueryKey({
66
63
  path: pathSegments,
67
64
  method: callMethod,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spoosh/plugin-prefetch",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Prefetch plugin for Spoosh - preload data before it's needed",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -33,11 +33,11 @@
33
33
  }
34
34
  },
35
35
  "peerDependencies": {
36
- "@spoosh/core": ">=0.6.0"
36
+ "@spoosh/core": ">=0.7.0"
37
37
  },
38
38
  "devDependencies": {
39
- "@spoosh/core": "0.6.0",
40
- "@spoosh/test-utils": "0.1.5"
39
+ "@spoosh/test-utils": "0.1.5",
40
+ "@spoosh/core": "0.7.0"
41
41
  },
42
42
  "scripts": {
43
43
  "dev": "tsup --watch",