@spoosh/plugin-polling 0.1.4 → 0.2.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
@@ -19,13 +19,13 @@ import { pollingPlugin } from "@spoosh/plugin-polling";
19
19
  const client = new Spoosh<ApiSchema, Error>("/api").use([pollingPlugin()]);
20
20
 
21
21
  // Static polling interval (5 seconds)
22
- useRead((api) => api.posts.$get(), { pollingInterval: 5000 });
22
+ useRead((api) => api("posts").GET(), { pollingInterval: 5000 });
23
23
 
24
24
  // Disable polling (Default behavior)
25
- useRead((api) => api.posts.$get(), { pollingInterval: false });
25
+ useRead((api) => api("posts").GET(), { pollingInterval: false });
26
26
 
27
27
  // Dynamic polling interval based on data/error
28
- useRead((api) => api.booking(123).$get(), {
28
+ useRead((api) => api("booking/:id").GET({ params: { id: 123 } }), {
29
29
  pollingInterval: (data, error) => {
30
30
  if (error) return 10000; // Slower polling on error
31
31
  if (data?.status === "pending") return 1000; // Fast polling for pending
@@ -47,7 +47,7 @@ useRead((api) => api.booking(123).$get(), {
47
47
  The polling interval can be a function that receives the current data and error, allowing you to adjust the polling rate based on the response:
48
48
 
49
49
  ```typescript
50
- useRead((api) => api.jobs(":id").$get({ id: jobId }), {
50
+ useRead((api) => api("jobs/:id").GET({ params: { id: jobId } }), {
51
51
  pollingInterval: (data) => {
52
52
  // Stop polling when job is complete
53
53
  if (data?.status === "completed") return false;
package/dist/index.d.mts CHANGED
@@ -36,12 +36,12 @@ declare module "@spoosh/core" {
36
36
  * ]);
37
37
  *
38
38
  * // Poll every 5 seconds
39
- * useRead((api) => api.posts.$get(), {
39
+ * useRead((api) => api("posts").GET(), {
40
40
  * pollingInterval: 5000,
41
41
  * });
42
42
  *
43
43
  * // Dynamic interval based on data
44
- * useRead((api) => api.posts.$get(), {
44
+ * useRead((api) => api("posts").GET(), {
45
45
  * pollingInterval: (data, error) => error ? 10000 : 5000,
46
46
  * });
47
47
  * ```
package/dist/index.d.ts CHANGED
@@ -36,12 +36,12 @@ declare module "@spoosh/core" {
36
36
  * ]);
37
37
  *
38
38
  * // Poll every 5 seconds
39
- * useRead((api) => api.posts.$get(), {
39
+ * useRead((api) => api("posts").GET(), {
40
40
  * pollingInterval: 5000,
41
41
  * });
42
42
  *
43
43
  * // Dynamic interval based on data
44
- * useRead((api) => api.posts.$get(), {
44
+ * useRead((api) => api("posts").GET(), {
45
45
  * pollingInterval: (data, error) => error ? 10000 : 5000,
46
46
  * });
47
47
  * ```
package/dist/index.js CHANGED
@@ -57,7 +57,7 @@ function pollingPlugin() {
57
57
  return {
58
58
  name: "spoosh:polling",
59
59
  operations: ["read", "infiniteRead"],
60
- onResponse(context) {
60
+ afterResponse(context) {
61
61
  scheduleNextPoll(context);
62
62
  },
63
63
  lifecycle: {
package/dist/index.mjs CHANGED
@@ -31,7 +31,7 @@ function pollingPlugin() {
31
31
  return {
32
32
  name: "spoosh:polling",
33
33
  operations: ["read", "infiniteRead"],
34
- onResponse(context) {
34
+ afterResponse(context) {
35
35
  scheduleNextPoll(context);
36
36
  },
37
37
  lifecycle: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spoosh/plugin-polling",
3
- "version": "0.1.4",
3
+ "version": "0.2.0",
4
4
  "description": "Automatic polling/refetching plugin for Spoosh",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -34,10 +34,10 @@
34
34
  }
35
35
  },
36
36
  "peerDependencies": {
37
- "@spoosh/core": ">=0.4.0"
37
+ "@spoosh/core": ">=0.8.0"
38
38
  },
39
39
  "devDependencies": {
40
- "@spoosh/core": "0.4.2",
40
+ "@spoosh/core": "0.8.0",
41
41
  "@spoosh/test-utils": "0.1.5"
42
42
  },
43
43
  "scripts": {