@spoosh/plugin-transform 0.5.3 → 0.6.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 +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +11 -1
- package/dist/index.mjs +11 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ Response transforms produce a separate `transformedData` field in `meta` while p
|
|
|
20
20
|
import { Spoosh } from "@spoosh/core";
|
|
21
21
|
import { transformPlugin } from "@spoosh/plugin-transform";
|
|
22
22
|
|
|
23
|
-
const
|
|
23
|
+
const spoosh = new Spoosh<ApiSchema, Error>("/api").use([transformPlugin()]);
|
|
24
24
|
|
|
25
25
|
const { data, meta } = useRead((api) => api("posts").GET(), {
|
|
26
26
|
transform: (posts) => ({
|
package/dist/index.d.mts
CHANGED
|
@@ -54,7 +54,7 @@ declare module "@spoosh/core" {
|
|
|
54
54
|
* ```ts
|
|
55
55
|
* import { Spoosh } from "@spoosh/core";
|
|
56
56
|
*
|
|
57
|
-
* const
|
|
57
|
+
* const spoosh = new Spoosh<ApiSchema, Error>("/api")
|
|
58
58
|
* .use([
|
|
59
59
|
* // ... other plugins
|
|
60
60
|
* transformPlugin(),
|
package/dist/index.d.ts
CHANGED
|
@@ -54,7 +54,7 @@ declare module "@spoosh/core" {
|
|
|
54
54
|
* ```ts
|
|
55
55
|
* import { Spoosh } from "@spoosh/core";
|
|
56
56
|
*
|
|
57
|
-
* const
|
|
57
|
+
* const spoosh = new Spoosh<ApiSchema, Error>("/api")
|
|
58
58
|
* .use([
|
|
59
59
|
* // ... other plugins
|
|
60
60
|
* transformPlugin(),
|
package/dist/index.js
CHANGED
|
@@ -25,17 +25,27 @@ __export(src_exports, {
|
|
|
25
25
|
module.exports = __toCommonJS(src_exports);
|
|
26
26
|
|
|
27
27
|
// src/plugin.ts
|
|
28
|
+
var PLUGIN_NAME = "spoosh:transform";
|
|
28
29
|
function transformPlugin() {
|
|
29
30
|
return {
|
|
30
|
-
name:
|
|
31
|
+
name: PLUGIN_NAME,
|
|
31
32
|
operations: ["read", "write"],
|
|
32
33
|
afterResponse: async (context, response) => {
|
|
34
|
+
const t = context.tracer?.(PLUGIN_NAME);
|
|
33
35
|
const pluginOptions = context.pluginOptions;
|
|
34
36
|
const responseTransformer = pluginOptions?.transform;
|
|
35
37
|
if (!responseTransformer || response.data === void 0) {
|
|
36
38
|
return;
|
|
37
39
|
}
|
|
38
40
|
const transformedData = await responseTransformer(response.data);
|
|
41
|
+
t?.log("Transformed", {
|
|
42
|
+
color: "success",
|
|
43
|
+
diff: {
|
|
44
|
+
before: response.data,
|
|
45
|
+
after: transformedData,
|
|
46
|
+
label: "Transform applied to response data"
|
|
47
|
+
}
|
|
48
|
+
});
|
|
39
49
|
context.stateManager.setMeta(context.queryKey, {
|
|
40
50
|
transformedData
|
|
41
51
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -1,15 +1,25 @@
|
|
|
1
1
|
// src/plugin.ts
|
|
2
|
+
var PLUGIN_NAME = "spoosh:transform";
|
|
2
3
|
function transformPlugin() {
|
|
3
4
|
return {
|
|
4
|
-
name:
|
|
5
|
+
name: PLUGIN_NAME,
|
|
5
6
|
operations: ["read", "write"],
|
|
6
7
|
afterResponse: async (context, response) => {
|
|
8
|
+
const t = context.tracer?.(PLUGIN_NAME);
|
|
7
9
|
const pluginOptions = context.pluginOptions;
|
|
8
10
|
const responseTransformer = pluginOptions?.transform;
|
|
9
11
|
if (!responseTransformer || response.data === void 0) {
|
|
10
12
|
return;
|
|
11
13
|
}
|
|
12
14
|
const transformedData = await responseTransformer(response.data);
|
|
15
|
+
t?.log("Transformed", {
|
|
16
|
+
color: "success",
|
|
17
|
+
diff: {
|
|
18
|
+
before: response.data,
|
|
19
|
+
after: transformedData,
|
|
20
|
+
label: "Transform applied to response data"
|
|
21
|
+
}
|
|
22
|
+
});
|
|
13
23
|
context.stateManager.setMeta(context.queryKey, {
|
|
14
24
|
transformedData
|
|
15
25
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spoosh/plugin-transform",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Data transformation plugin for Spoosh with sync/async support",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -33,11 +33,11 @@
|
|
|
33
33
|
}
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@spoosh/core": ">=0.
|
|
36
|
+
"@spoosh/core": ">=0.13.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@spoosh/core": "0.
|
|
40
|
-
"@spoosh/test-utils": "0.
|
|
39
|
+
"@spoosh/core": "0.13.0",
|
|
40
|
+
"@spoosh/test-utils": "0.2.0"
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|
|
43
43
|
"dev": "tsup --watch",
|