@spoosh/plugin-debounce 0.3.0 → 0.4.1

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.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { SpooshPlugin } from '@spoosh/core';
1
+ import * as _spoosh_core from '@spoosh/core';
2
2
 
3
3
  type PrevQueryField<TQuery> = [TQuery] extends [never] ? object : {
4
4
  prevQuery?: TQuery;
@@ -17,7 +17,6 @@ interface DebounceReadOptions {
17
17
  */
18
18
  debounce?: RequestAwareDebounceFn;
19
19
  }
20
- type DebounceInfiniteReadOptions = DebounceReadOptions;
21
20
  type DebounceWriteOptions = object;
22
21
  type DebounceReadResult = object;
23
22
  type DebounceWriteResult = object;
@@ -56,12 +55,11 @@ declare module "@spoosh/core" {
56
55
  * });
57
56
  * ```
58
57
  */
59
- declare function debouncePlugin(): SpooshPlugin<{
58
+ declare function debouncePlugin(): _spoosh_core.SpooshPlugin<{
60
59
  readOptions: DebounceReadOptions;
61
60
  writeOptions: DebounceWriteOptions;
62
- infiniteReadOptions: DebounceInfiniteReadOptions;
63
61
  readResult: DebounceReadResult;
64
62
  writeResult: DebounceWriteResult;
65
63
  }>;
66
64
 
67
- export { type DebounceContext, type DebounceFn, type DebounceInfiniteReadOptions, type DebounceReadOptions, type DebounceReadResult, type DebounceValue, type DebounceWriteOptions, type DebounceWriteResult, type RequestAwareDebounceFn, debouncePlugin };
65
+ export { type DebounceContext, type DebounceFn, type DebounceReadOptions, type DebounceReadResult, type DebounceValue, type DebounceWriteOptions, type DebounceWriteResult, type RequestAwareDebounceFn, debouncePlugin };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { SpooshPlugin } from '@spoosh/core';
1
+ import * as _spoosh_core from '@spoosh/core';
2
2
 
3
3
  type PrevQueryField<TQuery> = [TQuery] extends [never] ? object : {
4
4
  prevQuery?: TQuery;
@@ -17,7 +17,6 @@ interface DebounceReadOptions {
17
17
  */
18
18
  debounce?: RequestAwareDebounceFn;
19
19
  }
20
- type DebounceInfiniteReadOptions = DebounceReadOptions;
21
20
  type DebounceWriteOptions = object;
22
21
  type DebounceReadResult = object;
23
22
  type DebounceWriteResult = object;
@@ -56,12 +55,11 @@ declare module "@spoosh/core" {
56
55
  * });
57
56
  * ```
58
57
  */
59
- declare function debouncePlugin(): SpooshPlugin<{
58
+ declare function debouncePlugin(): _spoosh_core.SpooshPlugin<{
60
59
  readOptions: DebounceReadOptions;
61
60
  writeOptions: DebounceWriteOptions;
62
- infiniteReadOptions: DebounceInfiniteReadOptions;
63
61
  readResult: DebounceReadResult;
64
62
  writeResult: DebounceWriteResult;
65
63
  }>;
66
64
 
67
- export { type DebounceContext, type DebounceFn, type DebounceInfiniteReadOptions, type DebounceReadOptions, type DebounceReadResult, type DebounceValue, type DebounceWriteOptions, type DebounceWriteResult, type RequestAwareDebounceFn, debouncePlugin };
65
+ export { type DebounceContext, type DebounceFn, type DebounceReadOptions, type DebounceReadResult, type DebounceValue, type DebounceWriteOptions, type DebounceWriteResult, type RequestAwareDebounceFn, debouncePlugin };
package/dist/index.js CHANGED
@@ -25,6 +25,7 @@ __export(src_exports, {
25
25
  module.exports = __toCommonJS(src_exports);
26
26
 
27
27
  // src/plugin.ts
28
+ var import_core = require("@spoosh/core");
28
29
  var PLUGIN_NAME = "spoosh:debounce";
29
30
  function resolveDebounceMs(debounce, context) {
30
31
  if (debounce === void 0) return 0;
@@ -36,9 +37,9 @@ function debouncePlugin() {
36
37
  const latestQueryKeys = /* @__PURE__ */ new Map();
37
38
  const prevRequests = /* @__PURE__ */ new Map();
38
39
  const eventTracers = /* @__PURE__ */ new Map();
39
- return {
40
+ return (0, import_core.createSpooshPlugin)({
40
41
  name: PLUGIN_NAME,
41
- operations: ["read", "infiniteRead"],
42
+ operations: ["read"],
42
43
  lifecycle: {
43
44
  onUnmount: (context) => {
44
45
  const { path, method } = context;
@@ -55,8 +56,7 @@ function debouncePlugin() {
55
56
  middleware: async (context, next) => {
56
57
  const t = context.tracer?.(PLUGIN_NAME);
57
58
  const et = context.eventTracer?.(PLUGIN_NAME);
58
- const pluginOptions = context.pluginOptions;
59
- const debounceOption = pluginOptions?.debounce;
59
+ const debounceOption = context.pluginOptions?.debounce;
60
60
  if (debounceOption === void 0 || context.forceRefetch) {
61
61
  t?.skip("No debounce configured");
62
62
  return next();
@@ -134,5 +134,5 @@ function debouncePlugin() {
134
134
  t?.return("Debounced, no cached data", { color: "info" });
135
135
  return { data: void 0, status: 0 };
136
136
  }
137
- };
137
+ });
138
138
  }
package/dist/index.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  // src/plugin.ts
2
+ import { createSpooshPlugin } from "@spoosh/core";
2
3
  var PLUGIN_NAME = "spoosh:debounce";
3
4
  function resolveDebounceMs(debounce, context) {
4
5
  if (debounce === void 0) return 0;
@@ -10,9 +11,9 @@ function debouncePlugin() {
10
11
  const latestQueryKeys = /* @__PURE__ */ new Map();
11
12
  const prevRequests = /* @__PURE__ */ new Map();
12
13
  const eventTracers = /* @__PURE__ */ new Map();
13
- return {
14
+ return createSpooshPlugin({
14
15
  name: PLUGIN_NAME,
15
- operations: ["read", "infiniteRead"],
16
+ operations: ["read"],
16
17
  lifecycle: {
17
18
  onUnmount: (context) => {
18
19
  const { path, method } = context;
@@ -29,8 +30,7 @@ function debouncePlugin() {
29
30
  middleware: async (context, next) => {
30
31
  const t = context.tracer?.(PLUGIN_NAME);
31
32
  const et = context.eventTracer?.(PLUGIN_NAME);
32
- const pluginOptions = context.pluginOptions;
33
- const debounceOption = pluginOptions?.debounce;
33
+ const debounceOption = context.pluginOptions?.debounce;
34
34
  if (debounceOption === void 0 || context.forceRefetch) {
35
35
  t?.skip("No debounce configured");
36
36
  return next();
@@ -108,7 +108,7 @@ function debouncePlugin() {
108
108
  t?.return("Debounced, no cached data", { color: "info" });
109
109
  return { data: void 0, status: 0 };
110
110
  }
111
- };
111
+ });
112
112
  }
113
113
  export {
114
114
  debouncePlugin
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spoosh/plugin-debounce",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
4
4
  "description": "Request debouncing plugin for Spoosh - waits for inactivity before fetching",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -33,11 +33,11 @@
33
33
  }
34
34
  },
35
35
  "peerDependencies": {
36
- "@spoosh/core": ">=0.13.0"
36
+ "@spoosh/core": ">=0.15.0"
37
37
  },
38
38
  "devDependencies": {
39
- "@spoosh/core": "0.13.0",
40
- "@spoosh/test-utils": "0.2.0"
39
+ "@spoosh/test-utils": "0.3.0",
40
+ "@spoosh/core": "0.15.1"
41
41
  },
42
42
  "scripts": {
43
43
  "dev": "tsup --watch",