@spoosh/plugin-qs 0.2.4 → 0.3.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 +12 -1
- package/dist/index.mjs +12 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ npm install @spoosh/plugin-qs
|
|
|
16
16
|
import { Spoosh } from "@spoosh/core";
|
|
17
17
|
import { qsPlugin } from "@spoosh/plugin-qs";
|
|
18
18
|
|
|
19
|
-
const
|
|
19
|
+
const spoosh = new Spoosh<ApiSchema, Error>("/api").use([
|
|
20
20
|
qsPlugin({ arrayFormat: "brackets" }),
|
|
21
21
|
]);
|
|
22
22
|
|
package/dist/index.d.mts
CHANGED
|
@@ -29,7 +29,7 @@ type QsWriteResult = object;
|
|
|
29
29
|
* ```ts
|
|
30
30
|
* import { Spoosh } from "@spoosh/core";
|
|
31
31
|
*
|
|
32
|
-
* const
|
|
32
|
+
* const spoosh = new Spoosh<ApiSchema, Error>("/api")
|
|
33
33
|
* .use([
|
|
34
34
|
* // ... other plugins
|
|
35
35
|
* qsPlugin({ arrayFormat: "brackets" }),
|
package/dist/index.d.ts
CHANGED
|
@@ -29,7 +29,7 @@ type QsWriteResult = object;
|
|
|
29
29
|
* ```ts
|
|
30
30
|
* import { Spoosh } from "@spoosh/core";
|
|
31
31
|
*
|
|
32
|
-
* const
|
|
32
|
+
* const spoosh = new Spoosh<ApiSchema, Error>("/api")
|
|
33
33
|
* .use([
|
|
34
34
|
* // ... other plugins
|
|
35
35
|
* qsPlugin({ arrayFormat: "brackets" }),
|
package/dist/index.js
CHANGED
|
@@ -36,6 +36,7 @@ module.exports = __toCommonJS(src_exports);
|
|
|
36
36
|
|
|
37
37
|
// src/plugin.ts
|
|
38
38
|
var import_qs = __toESM(require("qs"));
|
|
39
|
+
var PLUGIN_NAME = "spoosh:qs";
|
|
39
40
|
var DEFAULT_OPTIONS = {
|
|
40
41
|
arrayFormat: "brackets",
|
|
41
42
|
allowDots: false,
|
|
@@ -43,11 +44,13 @@ var DEFAULT_OPTIONS = {
|
|
|
43
44
|
};
|
|
44
45
|
function qsPlugin(config = {}) {
|
|
45
46
|
return {
|
|
46
|
-
name:
|
|
47
|
+
name: PLUGIN_NAME,
|
|
47
48
|
operations: ["read", "write", "infiniteRead"],
|
|
48
49
|
middleware: async (context, next) => {
|
|
50
|
+
const t = context.tracer?.(PLUGIN_NAME);
|
|
49
51
|
const query = context.request.query;
|
|
50
52
|
if (!query || Object.keys(query).length === 0) {
|
|
53
|
+
t?.skip("No query params", { color: "muted" });
|
|
51
54
|
return next();
|
|
52
55
|
}
|
|
53
56
|
const pluginOptions = context.pluginOptions?.qs;
|
|
@@ -58,6 +61,14 @@ function qsPlugin(config = {}) {
|
|
|
58
61
|
encode: false
|
|
59
62
|
});
|
|
60
63
|
const flatQuery = import_qs.default.parse(stringified, { depth: 0 });
|
|
64
|
+
t?.log("Serialized query", {
|
|
65
|
+
color: "info",
|
|
66
|
+
diff: {
|
|
67
|
+
before: query,
|
|
68
|
+
after: flatQuery,
|
|
69
|
+
label: "Serialize query params"
|
|
70
|
+
}
|
|
71
|
+
});
|
|
61
72
|
context.request = {
|
|
62
73
|
...context.request,
|
|
63
74
|
query: flatQuery
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// src/plugin.ts
|
|
2
2
|
import qs from "qs";
|
|
3
|
+
var PLUGIN_NAME = "spoosh:qs";
|
|
3
4
|
var DEFAULT_OPTIONS = {
|
|
4
5
|
arrayFormat: "brackets",
|
|
5
6
|
allowDots: false,
|
|
@@ -7,11 +8,13 @@ var DEFAULT_OPTIONS = {
|
|
|
7
8
|
};
|
|
8
9
|
function qsPlugin(config = {}) {
|
|
9
10
|
return {
|
|
10
|
-
name:
|
|
11
|
+
name: PLUGIN_NAME,
|
|
11
12
|
operations: ["read", "write", "infiniteRead"],
|
|
12
13
|
middleware: async (context, next) => {
|
|
14
|
+
const t = context.tracer?.(PLUGIN_NAME);
|
|
13
15
|
const query = context.request.query;
|
|
14
16
|
if (!query || Object.keys(query).length === 0) {
|
|
17
|
+
t?.skip("No query params", { color: "muted" });
|
|
15
18
|
return next();
|
|
16
19
|
}
|
|
17
20
|
const pluginOptions = context.pluginOptions?.qs;
|
|
@@ -22,6 +25,14 @@ function qsPlugin(config = {}) {
|
|
|
22
25
|
encode: false
|
|
23
26
|
});
|
|
24
27
|
const flatQuery = qs.parse(stringified, { depth: 0 });
|
|
28
|
+
t?.log("Serialized query", {
|
|
29
|
+
color: "info",
|
|
30
|
+
diff: {
|
|
31
|
+
before: query,
|
|
32
|
+
after: flatQuery,
|
|
33
|
+
label: "Serialize query params"
|
|
34
|
+
}
|
|
35
|
+
});
|
|
25
36
|
context.request = {
|
|
26
37
|
...context.request,
|
|
27
38
|
query: flatQuery
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spoosh/plugin-qs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Query string serialization plugin for Spoosh with nested object support",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -37,12 +37,12 @@
|
|
|
37
37
|
"qs": "^6.13.0"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
|
-
"@spoosh/core": ">=0.
|
|
40
|
+
"@spoosh/core": ">=0.13.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/qs": "^6.9.17",
|
|
44
|
-
"@spoosh/core": "0.
|
|
45
|
-
"@spoosh/test-utils": "0.
|
|
44
|
+
"@spoosh/core": "0.13.0",
|
|
45
|
+
"@spoosh/test-utils": "0.2.0"
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
|
48
48
|
"dev": "tsup --watch",
|