@clipboard-health/json-api 0.16.0 → 0.17.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 +7 -6
- package/package.json +1 -1
- package/src/lib/query/toClientSearchParams.d.ts +4 -2
- package/src/lib/query/toClientSearchParams.js +4 -2
- package/src/lib/query/toClientSearchParams.js.map +1 -1
- package/src/lib/query/toServerJsonApiQuery.d.ts +4 -2
- package/src/lib/query/toServerJsonApiQuery.js +4 -2
- package/src/lib/query/toServerJsonApiQuery.js.map +1 -1
package/README.md
CHANGED
|
@@ -21,9 +21,9 @@ npm install @clipboard-health/json-api
|
|
|
21
21
|
|
|
22
22
|
From the client, call `toClientSearchParams` to convert from `ClientJsonApiQuery` to `URLSearchParams`:
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
<embedex source="packages/json-api/examples/toClientSearchParams.ts">
|
|
25
|
+
|
|
25
26
|
```ts
|
|
26
|
-
// packages/json-api/examples/toClientSearchParams.ts
|
|
27
27
|
import { deepEqual } from "node:assert/strict";
|
|
28
28
|
|
|
29
29
|
import { toClientSearchParams } from "@clipboard-health/json-api";
|
|
@@ -51,14 +51,14 @@ deepEqual(
|
|
|
51
51
|
`fields[user]=age,dateOfBirth&filter[age]=2&filter[dateOfBirth][gt]=${date1}&filter[dateOfBirth][lt]=${date2}&filter[isActive]=true&include=article&page[size]=10&sort=-age`,
|
|
52
52
|
).toString(),
|
|
53
53
|
);
|
|
54
|
-
|
|
55
54
|
```
|
|
56
55
|
|
|
56
|
+
</embedex>
|
|
57
57
|
From the server, call `toServerJsonApiQuery` to convert from `URLSearchParams` to `ServerJsonApiQuery`:
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
<embedex source="packages/json-api/examples/toServerJsonApiQuery.ts">
|
|
60
|
+
|
|
60
61
|
```ts
|
|
61
|
-
// packages/json-api/examples/toServerJsonApiQuery.ts
|
|
62
62
|
import { deepEqual } from "node:assert/strict";
|
|
63
63
|
|
|
64
64
|
import { type ServerJsonApiQuery, toServerJsonApiQuery } from "@clipboard-health/json-api";
|
|
@@ -84,9 +84,10 @@ deepEqual(query, {
|
|
|
84
84
|
},
|
|
85
85
|
sort: ["-age"],
|
|
86
86
|
});
|
|
87
|
-
|
|
88
87
|
```
|
|
89
88
|
|
|
89
|
+
</embedex>
|
|
90
|
+
|
|
90
91
|
## Local development commands
|
|
91
92
|
|
|
92
93
|
See [`package.json`](./package.json) `scripts` for a list of commands.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clipboard-health/json-api",
|
|
3
3
|
"description": "TypeScript-friendly utilities for adhering to the JSON:API specification.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.17.1",
|
|
5
5
|
"bugs": "https://github.com/ClipboardHealth/core-utils/issues",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"tslib": "2.8.0"
|
|
@@ -3,8 +3,9 @@ import { type ClientJsonApiQuery } from "../types";
|
|
|
3
3
|
* Call this function from clients to convert from {@link ClientJsonApiQuery} to {@link URLSearchParams}.
|
|
4
4
|
*
|
|
5
5
|
* @example
|
|
6
|
+
* <embedex source="packages/json-api/examples/toClientSearchParams.ts">
|
|
7
|
+
*
|
|
6
8
|
* ```ts
|
|
7
|
-
* // packages/json-api/examples/toClientSearchParams.ts
|
|
8
9
|
* import { deepEqual } from "node:assert/strict";
|
|
9
10
|
*
|
|
10
11
|
* import { toClientSearchParams } from "@clipboard-health/json-api";
|
|
@@ -32,7 +33,8 @@ import { type ClientJsonApiQuery } from "../types";
|
|
|
32
33
|
* `fields[user]=age,dateOfBirth&filter[age]=2&filter[dateOfBirth][gt]=${date1}&filter[dateOfBirth][lt]=${date2}&filter[isActive]=true&include=article&page[size]=10&sort=-age`,
|
|
33
34
|
* ).toString(),
|
|
34
35
|
* );
|
|
35
|
-
*
|
|
36
36
|
* ```
|
|
37
|
+
*
|
|
38
|
+
* </embedex>
|
|
37
39
|
*/
|
|
38
40
|
export declare function toClientSearchParams(query: ClientJsonApiQuery): URLSearchParams;
|
|
@@ -11,8 +11,9 @@ function join(values) {
|
|
|
11
11
|
* Call this function from clients to convert from {@link ClientJsonApiQuery} to {@link URLSearchParams}.
|
|
12
12
|
*
|
|
13
13
|
* @example
|
|
14
|
+
* <embedex source="packages/json-api/examples/toClientSearchParams.ts">
|
|
15
|
+
*
|
|
14
16
|
* ```ts
|
|
15
|
-
* // packages/json-api/examples/toClientSearchParams.ts
|
|
16
17
|
* import { deepEqual } from "node:assert/strict";
|
|
17
18
|
*
|
|
18
19
|
* import { toClientSearchParams } from "@clipboard-health/json-api";
|
|
@@ -40,8 +41,9 @@ function join(values) {
|
|
|
40
41
|
* `fields[user]=age,dateOfBirth&filter[age]=2&filter[dateOfBirth][gt]=${date1}&filter[dateOfBirth][lt]=${date2}&filter[isActive]=true&include=article&page[size]=10&sort=-age`,
|
|
41
42
|
* ).toString(),
|
|
42
43
|
* );
|
|
43
|
-
*
|
|
44
44
|
* ```
|
|
45
|
+
*
|
|
46
|
+
* </embedex>
|
|
45
47
|
*/
|
|
46
48
|
function toClientSearchParams(query) {
|
|
47
49
|
const searchParams = new URLSearchParams();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toClientSearchParams.js","sourceRoot":"","sources":["../../../../../../packages/json-api/src/lib/query/toClientSearchParams.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"toClientSearchParams.js","sourceRoot":"","sources":["../../../../../../packages/json-api/src/lib/query/toClientSearchParams.ts"],"names":[],"mappings":";;AAgDA,oDAoCC;AAlFD,SAAS,iBAAiB,CAAC,KAAyC;IAClE,OAAO,KAAK,YAAY,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACrE,CAAC;AAED,SAAS,IAAI,CAAC,MAAgB;IAC5B,OAAO,MAAM,CAAC,IAAI,CA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AI,KAAK,CAAC,IAAI,EAAE,CAAC;QACf,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;YAClD,YAAY,CAAC,MAAM,CAAC,QAAQ,GAAG,GAAG,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QACrD,CAAC,CAAC,CAAC;IACL,CAAC;IAED,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC;QACf,YAAY,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;IAChD,CAAC;IAED,OAAO,YAAY,CAAC;AACtB,CAAC"}
|
|
@@ -3,8 +3,9 @@ import { type ServerJsonApiQuery } from "../types";
|
|
|
3
3
|
* Call this function from servers to convert from {@link URLSearchParams} to {@link ServerJsonApiQuery}.
|
|
4
4
|
*
|
|
5
5
|
* @example
|
|
6
|
+
* <embedex source="packages/json-api/examples/toServerJsonApiQuery.ts">
|
|
7
|
+
*
|
|
6
8
|
* ```ts
|
|
7
|
-
* // packages/json-api/examples/toServerJsonApiQuery.ts
|
|
8
9
|
* import { deepEqual } from "node:assert/strict";
|
|
9
10
|
*
|
|
10
11
|
* import { type ServerJsonApiQuery, toServerJsonApiQuery } from "@clipboard-health/json-api";
|
|
@@ -30,7 +31,8 @@ import { type ServerJsonApiQuery } from "../types";
|
|
|
30
31
|
* },
|
|
31
32
|
* sort: ["-age"],
|
|
32
33
|
* });
|
|
33
|
-
*
|
|
34
34
|
* ```
|
|
35
|
+
*
|
|
36
|
+
* </embedex>
|
|
35
37
|
*/
|
|
36
38
|
export declare function toServerJsonApiQuery(searchParams: URLSearchParams): ServerJsonApiQuery;
|
|
@@ -13,8 +13,9 @@ const REGEX = {
|
|
|
13
13
|
* Call this function from servers to convert from {@link URLSearchParams} to {@link ServerJsonApiQuery}.
|
|
14
14
|
*
|
|
15
15
|
* @example
|
|
16
|
+
* <embedex source="packages/json-api/examples/toServerJsonApiQuery.ts">
|
|
17
|
+
*
|
|
16
18
|
* ```ts
|
|
17
|
-
* // packages/json-api/examples/toServerJsonApiQuery.ts
|
|
18
19
|
* import { deepEqual } from "node:assert/strict";
|
|
19
20
|
*
|
|
20
21
|
* import { type ServerJsonApiQuery, toServerJsonApiQuery } from "@clipboard-health/json-api";
|
|
@@ -40,8 +41,9 @@ const REGEX = {
|
|
|
40
41
|
* },
|
|
41
42
|
* sort: ["-age"],
|
|
42
43
|
* });
|
|
43
|
-
*
|
|
44
44
|
* ```
|
|
45
|
+
*
|
|
46
|
+
* </embedex>
|
|
45
47
|
*/
|
|
46
48
|
function toServerJsonApiQuery(searchParams) {
|
|
47
49
|
return [...searchParams].reduce((accumulator, [key, value]) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toServerJsonApiQuery.js","sourceRoot":"","sources":["../../../../../../packages/json-api/src/lib/query/toServerJsonApiQuery.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"toServerJsonApiQuery.js","sourceRoot":"","sources":["../../../../../../packages/json-api/src/lib/query/toServerJsonApiQuery.ts"],"names":[],"mappings":";;AA+CA,oDAiDC;AA9FD,MAAM,KAAK,GAAG;IACZ,MAAM,EAAE,mBAAmB;IAC3B,MAAM,EAAE,uBAAuB;IAC/B,UAAU,EAAE,2BAA2B;IACvC,OAAO,EAAE,YAAY;IACrB,IAAI,EAAE,iBAAiB;IACvB,IAAI,EAAE,SAAS;CACP,CAAC;AAEX;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,SAAgB,oBAAoB,CAAC,YAA6B;IAChE,OAAO,CAAC,GAAG,YAAY,CAAC,CAAC,MAAM,CAAqB,CAAC,WAAW,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;QAChF,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,IAAI,CA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