@spoosh/plugin-prefetch 0.3.2 → 0.3.3

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/index.js CHANGED
@@ -81,7 +81,7 @@ function prefetchPlugin(config = {}) {
81
81
  const resolvedPath = (0, import_core.resolvePath)(pathSegments, void 0);
82
82
  const resolvedTags = (0, import_core.resolveTags)({ tags }, resolvedPath);
83
83
  const queryKey = stateManager.createQueryKey({
84
- path: pathSegments,
84
+ path: callPath,
85
85
  method: callMethod,
86
86
  options: callOptions
87
87
  });
@@ -89,21 +89,19 @@ function prefetchPlugin(config = {}) {
89
89
  const abortController = new AbortController();
90
90
  const pluginContext = pluginExecutor.createContext({
91
91
  operationType: "read",
92
- path: pathSegments,
92
+ path: pathSegments.join("/"),
93
93
  method: callMethod,
94
94
  queryKey,
95
95
  tags: resolvedTags,
96
96
  requestTimestamp: Date.now(),
97
- requestOptions: callOptions ?? {},
98
- state: initialState,
97
+ request: { headers: {}, ...callOptions ?? {} },
99
98
  metadata: /* @__PURE__ */ new Map(),
100
99
  pluginOptions: options,
101
- abort: () => abortController.abort(),
102
100
  stateManager,
103
101
  eventEmitter
104
102
  });
105
103
  const coreFetch = async () => {
106
- pluginContext.requestOptions.signal = abortController.signal;
104
+ pluginContext.request.signal = abortController.signal;
107
105
  const updateState = (updater) => {
108
106
  const cached = stateManager.getCache(queryKey);
109
107
  if (cached) {
@@ -122,10 +120,9 @@ function prefetchPlugin(config = {}) {
122
120
  const method = pathMethods[callMethod];
123
121
  const mergedOptions = {
124
122
  ...callOptions,
125
- ...pluginContext.requestOptions
123
+ ...pluginContext.request
126
124
  };
127
125
  const response = await method(mergedOptions);
128
- pluginContext.response = response;
129
126
  if (response.data !== void 0 && !response.error) {
130
127
  updateState({
131
128
  data: response.data,
@@ -148,7 +145,6 @@ function prefetchPlugin(config = {}) {
148
145
  error: err,
149
146
  data: void 0
150
147
  };
151
- pluginContext.response = errorResponse;
152
148
  return errorResponse;
153
149
  }
154
150
  };
package/dist/index.mjs CHANGED
@@ -60,7 +60,7 @@ function prefetchPlugin(config = {}) {
60
60
  const resolvedPath = resolvePath(pathSegments, void 0);
61
61
  const resolvedTags = resolveTags({ tags }, resolvedPath);
62
62
  const queryKey = stateManager.createQueryKey({
63
- path: pathSegments,
63
+ path: callPath,
64
64
  method: callMethod,
65
65
  options: callOptions
66
66
  });
@@ -68,21 +68,19 @@ function prefetchPlugin(config = {}) {
68
68
  const abortController = new AbortController();
69
69
  const pluginContext = pluginExecutor.createContext({
70
70
  operationType: "read",
71
- path: pathSegments,
71
+ path: pathSegments.join("/"),
72
72
  method: callMethod,
73
73
  queryKey,
74
74
  tags: resolvedTags,
75
75
  requestTimestamp: Date.now(),
76
- requestOptions: callOptions ?? {},
77
- state: initialState,
76
+ request: { headers: {}, ...callOptions ?? {} },
78
77
  metadata: /* @__PURE__ */ new Map(),
79
78
  pluginOptions: options,
80
- abort: () => abortController.abort(),
81
79
  stateManager,
82
80
  eventEmitter
83
81
  });
84
82
  const coreFetch = async () => {
85
- pluginContext.requestOptions.signal = abortController.signal;
83
+ pluginContext.request.signal = abortController.signal;
86
84
  const updateState = (updater) => {
87
85
  const cached = stateManager.getCache(queryKey);
88
86
  if (cached) {
@@ -101,10 +99,9 @@ function prefetchPlugin(config = {}) {
101
99
  const method = pathMethods[callMethod];
102
100
  const mergedOptions = {
103
101
  ...callOptions,
104
- ...pluginContext.requestOptions
102
+ ...pluginContext.request
105
103
  };
106
104
  const response = await method(mergedOptions);
107
- pluginContext.response = response;
108
105
  if (response.data !== void 0 && !response.error) {
109
106
  updateState({
110
107
  data: response.data,
@@ -127,7 +124,6 @@ function prefetchPlugin(config = {}) {
127
124
  error: err,
128
125
  data: void 0
129
126
  };
130
- pluginContext.response = errorResponse;
131
127
  return errorResponse;
132
128
  }
133
129
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spoosh/plugin-prefetch",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
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.9.0"
36
+ "@spoosh/core": ">=0.11.0"
37
37
  },
38
38
  "devDependencies": {
39
- "@spoosh/core": "0.10.0",
40
- "@spoosh/test-utils": "0.1.5"
39
+ "@spoosh/core": "0.11.0",
40
+ "@spoosh/test-utils": "0.1.6"
41
41
  },
42
42
  "scripts": {
43
43
  "dev": "tsup --watch",