@spoosh/plugin-prefetch 0.3.5 → 0.5.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
@@ -14,18 +14,18 @@ npm install @spoosh/plugin-prefetch
14
14
 
15
15
  ```typescript
16
16
  import { Spoosh } from "@spoosh/core";
17
- import { createReactSpoosh } from "@spoosh/react";
17
+ import { create } from "@spoosh/react";
18
18
  import { prefetchPlugin } from "@spoosh/plugin-prefetch";
19
19
  import { cachePlugin } from "@spoosh/plugin-cache";
20
20
  import { retryPlugin } from "@spoosh/plugin-retry";
21
21
 
22
- // Setup - prefetch is returned from createReactSpoosh
22
+ // Setup - prefetch is returned from create
23
23
  const spoosh = new Spoosh<ApiSchema, Error>("/api").use([
24
24
  prefetchPlugin(),
25
25
  cachePlugin(),
26
26
  retryPlugin(),
27
27
  ]);
28
- const { useRead, useWrite, prefetch } = createReactSpoosh(spoosh);
28
+ const { useRead, useWrite, prefetch } = create(spoosh);
29
29
 
30
30
  // Basic prefetch
31
31
  await prefetch((api) => api("posts").GET());
package/dist/index.d.mts CHANGED
@@ -41,7 +41,7 @@ declare module "@spoosh/core" {
41
41
  * ```ts
42
42
  * import { Spoosh } from "@spoosh/core";
43
43
  *
44
- * const client = new Spoosh<ApiSchema, Error>("/api")
44
+ * const spoosh = new Spoosh<ApiSchema, Error>("/api")
45
45
  * .use([
46
46
  * // ... other plugins
47
47
  * prefetchPlugin(),
@@ -49,7 +49,7 @@ declare module "@spoosh/core" {
49
49
  * retryPlugin(),
50
50
  * ]);
51
51
  *
52
- * const { prefetch } = createReactSpoosh(client);
52
+ * const { prefetch } = create(client);
53
53
  *
54
54
  * // Basic prefetch
55
55
  * await prefetch((api) => api("posts").GET());
package/dist/index.d.ts CHANGED
@@ -41,7 +41,7 @@ declare module "@spoosh/core" {
41
41
  * ```ts
42
42
  * import { Spoosh } from "@spoosh/core";
43
43
  *
44
- * const client = new Spoosh<ApiSchema, Error>("/api")
44
+ * const spoosh = new Spoosh<ApiSchema, Error>("/api")
45
45
  * .use([
46
46
  * // ... other plugins
47
47
  * prefetchPlugin(),
@@ -49,7 +49,7 @@ declare module "@spoosh/core" {
49
49
  * retryPlugin(),
50
50
  * ]);
51
51
  *
52
- * const { prefetch } = createReactSpoosh(client);
52
+ * const { prefetch } = create(client);
53
53
  *
54
54
  * // Basic prefetch
55
55
  * await prefetch((api) => api("posts").GET());
package/dist/index.js CHANGED
@@ -49,10 +49,11 @@ function storePromiseInCache(promise, options) {
49
49
  }
50
50
 
51
51
  // src/plugin.ts
52
+ var PLUGIN_NAME = "spoosh:prefetch";
52
53
  function prefetchPlugin(config = {}) {
53
54
  const { timeout } = config;
54
55
  return {
55
- name: "spoosh:prefetch",
56
+ name: PLUGIN_NAME,
56
57
  operations: [],
57
58
  instanceApi(context) {
58
59
  const { api, stateManager, eventEmitter, pluginExecutor } = context;
@@ -149,9 +150,11 @@ function prefetchPlugin(config = {}) {
149
150
  }
150
151
  };
151
152
  const existingPromise = stateManager.getPendingPromise(queryKey);
153
+ const et = pluginContext.eventTracer?.(PLUGIN_NAME);
152
154
  if (existingPromise) {
153
155
  return existingPromise;
154
156
  }
157
+ et?.emit("Prefetching", { queryKey, color: "info" });
155
158
  const fetchPromise = pluginExecutor.executeMiddleware(
156
159
  "read",
157
160
  pluginContext,
package/dist/index.mjs CHANGED
@@ -28,10 +28,11 @@ function storePromiseInCache(promise, options) {
28
28
  }
29
29
 
30
30
  // src/plugin.ts
31
+ var PLUGIN_NAME = "spoosh:prefetch";
31
32
  function prefetchPlugin(config = {}) {
32
33
  const { timeout } = config;
33
34
  return {
34
- name: "spoosh:prefetch",
35
+ name: PLUGIN_NAME,
35
36
  operations: [],
36
37
  instanceApi(context) {
37
38
  const { api, stateManager, eventEmitter, pluginExecutor } = context;
@@ -128,9 +129,11 @@ function prefetchPlugin(config = {}) {
128
129
  }
129
130
  };
130
131
  const existingPromise = stateManager.getPendingPromise(queryKey);
132
+ const et = pluginContext.eventTracer?.(PLUGIN_NAME);
131
133
  if (existingPromise) {
132
134
  return existingPromise;
133
135
  }
136
+ et?.emit("Prefetching", { queryKey, color: "info" });
134
137
  const fetchPromise = pluginExecutor.executeMiddleware(
135
138
  "read",
136
139
  pluginContext,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spoosh/plugin-prefetch",
3
- "version": "0.3.5",
3
+ "version": "0.5.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.12.0"
36
+ "@spoosh/core": ">=0.15.0"
37
37
  },
38
38
  "devDependencies": {
39
- "@spoosh/core": "0.12.0",
40
- "@spoosh/test-utils": "0.1.8"
39
+ "@spoosh/core": "0.15.0",
40
+ "@spoosh/test-utils": "0.3.0"
41
41
  },
42
42
  "scripts": {
43
43
  "dev": "tsup --watch",