@spoosh/plugin-qs 0.2.1 → 0.2.3
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 +5 -5
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -3
- package/dist/index.mjs +3 -3
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Query string serialization plugin for Spoosh with nested object support.
|
|
4
4
|
|
|
5
|
-
**[Documentation](https://spoosh.dev/docs/plugins/qs)** · **Requirements:** TypeScript >= 5.0 · **Peer Dependencies:** `@spoosh/core`
|
|
5
|
+
**[Documentation](https://spoosh.dev/docs/react/plugins/qs)** · **Requirements:** TypeScript >= 5.0 · **Peer Dependencies:** `@spoosh/core`
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
@@ -25,7 +25,7 @@ const query = {
|
|
|
25
25
|
filters: { status: "active", tags: ["a", "b"] },
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
-
useRead((api) => api.
|
|
28
|
+
useRead((api) => api("items").GET({ query }));
|
|
29
29
|
// Result: pagination[limit]=10&pagination[offset]=0&filters[status]=active&filters[tags][]=a,b
|
|
30
30
|
```
|
|
31
31
|
|
|
@@ -54,13 +54,13 @@ Override plugin defaults for specific requests:
|
|
|
54
54
|
|
|
55
55
|
```typescript
|
|
56
56
|
// Use comma-separated arrays for this request
|
|
57
|
-
useRead((api) => api.
|
|
57
|
+
useRead((api) => api("items").GET({ query }), { qs: { arrayFormat: "comma" } });
|
|
58
58
|
|
|
59
59
|
// Use dot notation for nested objects
|
|
60
|
-
useRead((api) => api.
|
|
60
|
+
useRead((api) => api("search").GET({ query }), { qs: { allowDots: true } });
|
|
61
61
|
|
|
62
62
|
// Include null values for this request
|
|
63
|
-
useRead((api) => api.
|
|
63
|
+
useRead((api) => api("data").GET({ query }), { qs: { skipNulls: false } });
|
|
64
64
|
```
|
|
65
65
|
|
|
66
66
|
## Array Formats
|
package/dist/index.d.mts
CHANGED
|
@@ -23,7 +23,7 @@ type QsWriteResult = object;
|
|
|
23
23
|
*
|
|
24
24
|
* @param config - Plugin configuration
|
|
25
25
|
*
|
|
26
|
-
* @see {@link https://spoosh.dev/docs/plugins/qs | QS Plugin Documentation}
|
|
26
|
+
* @see {@link https://spoosh.dev/docs/react/plugins/qs | QS Plugin Documentation}
|
|
27
27
|
*
|
|
28
28
|
* @example
|
|
29
29
|
* ```ts
|
package/dist/index.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ type QsWriteResult = object;
|
|
|
23
23
|
*
|
|
24
24
|
* @param config - Plugin configuration
|
|
25
25
|
*
|
|
26
|
-
* @see {@link https://spoosh.dev/docs/plugins/qs | QS Plugin Documentation}
|
|
26
|
+
* @see {@link https://spoosh.dev/docs/react/plugins/qs | QS Plugin Documentation}
|
|
27
27
|
*
|
|
28
28
|
* @example
|
|
29
29
|
* ```ts
|
package/dist/index.js
CHANGED
|
@@ -46,7 +46,7 @@ function qsPlugin(config = {}) {
|
|
|
46
46
|
name: "spoosh:qs",
|
|
47
47
|
operations: ["read", "write", "infiniteRead"],
|
|
48
48
|
middleware: async (context, next) => {
|
|
49
|
-
const query = context.
|
|
49
|
+
const query = context.request.query;
|
|
50
50
|
if (!query || Object.keys(query).length === 0) {
|
|
51
51
|
return next();
|
|
52
52
|
}
|
|
@@ -58,8 +58,8 @@ function qsPlugin(config = {}) {
|
|
|
58
58
|
encode: false
|
|
59
59
|
});
|
|
60
60
|
const flatQuery = import_qs.default.parse(stringified, { depth: 0 });
|
|
61
|
-
context.
|
|
62
|
-
...context.
|
|
61
|
+
context.request = {
|
|
62
|
+
...context.request,
|
|
63
63
|
query: flatQuery
|
|
64
64
|
};
|
|
65
65
|
return next();
|
package/dist/index.mjs
CHANGED
|
@@ -10,7 +10,7 @@ function qsPlugin(config = {}) {
|
|
|
10
10
|
name: "spoosh:qs",
|
|
11
11
|
operations: ["read", "write", "infiniteRead"],
|
|
12
12
|
middleware: async (context, next) => {
|
|
13
|
-
const query = context.
|
|
13
|
+
const query = context.request.query;
|
|
14
14
|
if (!query || Object.keys(query).length === 0) {
|
|
15
15
|
return next();
|
|
16
16
|
}
|
|
@@ -22,8 +22,8 @@ function qsPlugin(config = {}) {
|
|
|
22
22
|
encode: false
|
|
23
23
|
});
|
|
24
24
|
const flatQuery = qs.parse(stringified, { depth: 0 });
|
|
25
|
-
context.
|
|
26
|
-
...context.
|
|
25
|
+
context.request = {
|
|
26
|
+
...context.request,
|
|
27
27
|
query: flatQuery
|
|
28
28
|
};
|
|
29
29
|
return next();
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spoosh/plugin-qs",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Query string serialization plugin for Spoosh with nested object 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-qs"
|
|
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/qs",
|
|
15
15
|
"publishConfig": {
|
|
16
16
|
"access": "public"
|
|
17
17
|
},
|
|
@@ -37,12 +37,12 @@
|
|
|
37
37
|
"qs": "^6.13.0"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
|
-
"@spoosh/core": ">=0.
|
|
40
|
+
"@spoosh/core": ">=0.11.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/qs": "^6.9.17",
|
|
44
|
-
"@spoosh/core": "0.
|
|
45
|
-
"@spoosh/test-utils": "0.1.
|
|
44
|
+
"@spoosh/core": "0.11.0",
|
|
45
|
+
"@spoosh/test-utils": "0.1.6"
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
|
48
48
|
"dev": "tsup --watch",
|