@spoosh/plugin-transform 0.4.2 → 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/dist/index.d.mts CHANGED
@@ -22,7 +22,7 @@ type TransformReadResult = object;
22
22
  type TransformWriteResult = {
23
23
  transformedData?: unknown;
24
24
  };
25
- type TransformOptions = TransformReadOptions | TransformWriteOptions | TransformInfiniteReadOptions;
25
+ type TransformOptions = TransformReadOptions | TransformWriteOptions;
26
26
  /**
27
27
  * Extracts the return type of a response transformer from hook options.
28
28
  * Returns `never` if no response transformer is provided.
@@ -78,7 +78,6 @@ declare module "@spoosh/core" {
78
78
  declare function transformPlugin(): SpooshPlugin<{
79
79
  readOptions: TransformReadOptions;
80
80
  writeOptions: TransformWriteOptions;
81
- infiniteReadOptions: TransformInfiniteReadOptions;
82
81
  readResult: TransformReadResult;
83
82
  writeResult: TransformWriteResult;
84
83
  }>;
package/dist/index.d.ts CHANGED
@@ -22,7 +22,7 @@ type TransformReadResult = object;
22
22
  type TransformWriteResult = {
23
23
  transformedData?: unknown;
24
24
  };
25
- type TransformOptions = TransformReadOptions | TransformWriteOptions | TransformInfiniteReadOptions;
25
+ type TransformOptions = TransformReadOptions | TransformWriteOptions;
26
26
  /**
27
27
  * Extracts the return type of a response transformer from hook options.
28
28
  * Returns `never` if no response transformer is provided.
@@ -78,7 +78,6 @@ declare module "@spoosh/core" {
78
78
  declare function transformPlugin(): SpooshPlugin<{
79
79
  readOptions: TransformReadOptions;
80
80
  writeOptions: TransformWriteOptions;
81
- infiniteReadOptions: TransformInfiniteReadOptions;
82
81
  readResult: TransformReadResult;
83
82
  writeResult: TransformWriteResult;
84
83
  }>;
package/dist/index.js CHANGED
@@ -29,15 +29,16 @@ function transformPlugin() {
29
29
  return {
30
30
  name: "spoosh:transform",
31
31
  operations: ["read", "write"],
32
- onResponse: async (context, response) => {
32
+ afterResponse: async (context, response) => {
33
33
  const pluginOptions = context.pluginOptions;
34
34
  const responseTransformer = pluginOptions?.transform;
35
- if (responseTransformer && response.data !== void 0) {
36
- const transformedData = await responseTransformer(response.data);
37
- context.stateManager.setMeta(context.queryKey, {
38
- transformedData
39
- });
35
+ if (!responseTransformer || response.data === void 0) {
36
+ return;
40
37
  }
38
+ const transformedData = await responseTransformer(response.data);
39
+ context.stateManager.setMeta(context.queryKey, {
40
+ transformedData
41
+ });
41
42
  }
42
43
  };
43
44
  }
package/dist/index.mjs CHANGED
@@ -3,15 +3,16 @@ function transformPlugin() {
3
3
  return {
4
4
  name: "spoosh:transform",
5
5
  operations: ["read", "write"],
6
- onResponse: async (context, response) => {
6
+ afterResponse: async (context, response) => {
7
7
  const pluginOptions = context.pluginOptions;
8
8
  const responseTransformer = pluginOptions?.transform;
9
- if (responseTransformer && response.data !== void 0) {
10
- const transformedData = await responseTransformer(response.data);
11
- context.stateManager.setMeta(context.queryKey, {
12
- transformedData
13
- });
9
+ if (!responseTransformer || response.data === void 0) {
10
+ return;
14
11
  }
12
+ const transformedData = await responseTransformer(response.data);
13
+ context.stateManager.setMeta(context.queryKey, {
14
+ transformedData
15
+ });
15
16
  }
16
17
  };
17
18
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spoosh/plugin-transform",
3
- "version": "0.4.2",
3
+ "version": "0.5.0",
4
4
  "description": "Data transformation plugin for Spoosh with sync/async support",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -33,10 +33,10 @@
33
33
  }
34
34
  },
35
35
  "peerDependencies": {
36
- "@spoosh/core": ">=0.6.0"
36
+ "@spoosh/core": ">=0.8.0"
37
37
  },
38
38
  "devDependencies": {
39
- "@spoosh/core": "0.7.0",
39
+ "@spoosh/core": "0.8.0",
40
40
  "@spoosh/test-utils": "0.1.5"
41
41
  },
42
42
  "scripts": {