@spoosh/plugin-transform 0.4.2 → 0.5.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/README.md +1 -1
- package/dist/index.d.mts +2 -3
- package/dist/index.d.ts +2 -3
- package/dist/index.js +7 -6
- package/dist/index.mjs +7 -6
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Transform response data with full type inference.
|
|
4
4
|
|
|
5
|
-
**[Documentation](https://spoosh.dev/docs/plugins/transform)** · **Requirements:** TypeScript >= 5.0 · **Peer Dependencies:** `@spoosh/core`
|
|
5
|
+
**[Documentation](https://spoosh.dev/docs/react/plugins/transform)** · **Requirements:** TypeScript >= 5.0 · **Peer Dependencies:** `@spoosh/core`
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
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
|
|
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.
|
|
@@ -48,7 +48,7 @@ declare module "@spoosh/core" {
|
|
|
48
48
|
*
|
|
49
49
|
* All transforms are per-request for full type inference.
|
|
50
50
|
*
|
|
51
|
-
* @see {@link https://spoosh.dev/docs/plugins/transform | Transform Plugin Documentation}
|
|
51
|
+
* @see {@link https://spoosh.dev/docs/react/plugins/transform | Transform Plugin Documentation}
|
|
52
52
|
*
|
|
53
53
|
* @example
|
|
54
54
|
* ```ts
|
|
@@ -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
|
|
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.
|
|
@@ -48,7 +48,7 @@ declare module "@spoosh/core" {
|
|
|
48
48
|
*
|
|
49
49
|
* All transforms are per-request for full type inference.
|
|
50
50
|
*
|
|
51
|
-
* @see {@link https://spoosh.dev/docs/plugins/transform | Transform Plugin Documentation}
|
|
51
|
+
* @see {@link https://spoosh.dev/docs/react/plugins/transform | Transform Plugin Documentation}
|
|
52
52
|
*
|
|
53
53
|
* @example
|
|
54
54
|
* ```ts
|
|
@@ -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
|
-
|
|
32
|
+
afterResponse: async (context, response) => {
|
|
33
33
|
const pluginOptions = context.pluginOptions;
|
|
34
34
|
const responseTransformer = pluginOptions?.transform;
|
|
35
|
-
if (responseTransformer
|
|
36
|
-
|
|
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
|
-
|
|
6
|
+
afterResponse: async (context, response) => {
|
|
7
7
|
const pluginOptions = context.pluginOptions;
|
|
8
8
|
const responseTransformer = pluginOptions?.transform;
|
|
9
|
-
if (responseTransformer
|
|
10
|
-
|
|
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,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spoosh/plugin-transform",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "Data transformation plugin for Spoosh with sync/async support",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "git+https://github.com/
|
|
8
|
+
"url": "git+https://github.com/spooshdev/spoosh.git",
|
|
9
9
|
"directory": "packages/plugin-transform"
|
|
10
10
|
},
|
|
11
11
|
"bugs": {
|
|
12
|
-
"url": "https://github.com/
|
|
12
|
+
"url": "https://github.com/spooshdev/spoosh/issues"
|
|
13
13
|
},
|
|
14
|
-
"homepage": "https://spoosh.dev/react/
|
|
14
|
+
"homepage": "https://spoosh.dev/docs/react/plugins/transform",
|
|
15
15
|
"publishConfig": {
|
|
16
16
|
"access": "public"
|
|
17
17
|
},
|
|
@@ -33,10 +33,10 @@
|
|
|
33
33
|
}
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@spoosh/core": ">=0.
|
|
36
|
+
"@spoosh/core": ">=0.8.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@spoosh/core": "0.
|
|
39
|
+
"@spoosh/core": "0.10.0",
|
|
40
40
|
"@spoosh/test-utils": "0.1.5"
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|