@clipboard-health/json-api 0.2.9 → 0.4.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 +30 -19
- package/package.json +1 -1
- package/src/index.d.ts +2 -2
- package/src/index.js +2 -2
- package/src/index.js.map +1 -1
- package/src/lib/query/toClientSearchParams.d.ts +9 -0
- package/src/lib/{toSearchParams.js → query/toClientSearchParams.js} +9 -15
- package/src/lib/query/toClientSearchParams.js.map +1 -0
- package/src/lib/query/toServerJsonApiQuery.d.ts +9 -0
- package/src/lib/{toJsonApiQuery.js → query/toServerJsonApiQuery.js} +10 -7
- package/src/lib/query/toServerJsonApiQuery.js.map +1 -0
- package/src/lib/types.d.ts +21 -23
- package/src/lib/toJsonApiQuery.d.ts +0 -7
- package/src/lib/toJsonApiQuery.js.map +0 -1
- package/src/lib/toSearchParams.d.ts +0 -7
- package/src/lib/toSearchParams.js.map +0 -1
package/README.md
CHANGED
|
@@ -6,6 +6,7 @@ Utilities for adhering to the [JSON:API](https://jsonapi.org/) specification.
|
|
|
6
6
|
|
|
7
7
|
- [Install](#install)
|
|
8
8
|
- [Usage](#usage)
|
|
9
|
+
- [Query helpers](#query-helpers)
|
|
9
10
|
- [Local development commands](#local-development-commands)
|
|
10
11
|
|
|
11
12
|
## Install
|
|
@@ -18,58 +19,68 @@ npm install @clipboard-health/json-api
|
|
|
18
19
|
|
|
19
20
|
### Query helpers
|
|
20
21
|
|
|
21
|
-
From the client, call `
|
|
22
|
+
From the client, call `toClientSearchParams` to convert from `ClientJsonApiQuery` to `URLSearchParams`:
|
|
22
23
|
|
|
23
24
|
<!-- prettier-ignore -->
|
|
24
25
|
```ts
|
|
25
|
-
// ./examples/
|
|
26
|
+
// ./examples/toClientSearchParams.ts
|
|
26
27
|
|
|
27
28
|
import { deepEqual } from "node:assert/strict";
|
|
28
29
|
|
|
29
|
-
import {
|
|
30
|
+
import { toClientSearchParams } from "@clipboard-health/json-api";
|
|
30
31
|
|
|
31
32
|
import { type ClientJsonApiQuery } from "../src/lib/types";
|
|
32
33
|
|
|
33
|
-
const
|
|
34
|
+
const [date1, date2] = ["2024-01-01", "2024-01-02"];
|
|
34
35
|
const query: ClientJsonApiQuery = {
|
|
35
|
-
fields: {
|
|
36
|
-
filter: {
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
fields: { user: ["age", "name"] },
|
|
37
|
+
filter: {
|
|
38
|
+
age: { eq: ["2"] },
|
|
39
|
+
dateOfBirth: { gt: [date1], lt: [date2] },
|
|
40
|
+
isActive: { eq: ["true"] },
|
|
41
|
+
},
|
|
42
|
+
include: ["article"],
|
|
43
|
+
page: {
|
|
44
|
+
size: "10",
|
|
45
|
+
},
|
|
39
46
|
sort: ["-age"],
|
|
40
47
|
};
|
|
41
48
|
|
|
42
49
|
deepEqual(
|
|
43
|
-
|
|
50
|
+
toClientSearchParams(query).toString(),
|
|
44
51
|
new URLSearchParams(
|
|
45
|
-
|
|
52
|
+
`fields[user]=age,name&filter[age]=2&filter[dateOfBirth][gt]=${date1}&filter[dateOfBirth][lt]=${date2}&filter[isActive]=true&include=article&page[size]=10&sort=-age`,
|
|
46
53
|
).toString(),
|
|
47
54
|
);
|
|
48
55
|
|
|
49
56
|
```
|
|
50
57
|
|
|
51
|
-
From the server, call `
|
|
58
|
+
From the server, call `toServerJsonApiQuery` to convert from `URLSearchParams` to `ServerJsonApiQuery`:
|
|
52
59
|
|
|
53
60
|
<!-- prettier-ignore -->
|
|
54
61
|
```ts
|
|
55
|
-
// ./examples/
|
|
62
|
+
// ./examples/toServerJsonApiQuery.ts
|
|
56
63
|
|
|
57
64
|
import { deepEqual } from "node:assert/strict";
|
|
58
65
|
|
|
59
|
-
import { type ServerJsonApiQuery,
|
|
66
|
+
import { type ServerJsonApiQuery, toServerJsonApiQuery } from "@clipboard-health/json-api";
|
|
60
67
|
|
|
61
|
-
const
|
|
68
|
+
const [date1, date2] = ["2024-01-01", "2024-01-02"];
|
|
62
69
|
// The URLSearchParams constructor also supports URL-encoded strings
|
|
63
70
|
const searchParams = new URLSearchParams(
|
|
64
|
-
`fields[
|
|
71
|
+
`fields[user]=age,name&filter[age]=2&filter[dateOfBirth][gt]=${date1}&filter[dateOfBirth][lt]=${date2}&filter[isActive]=true&include=article&page[size]=10&sort=-age`,
|
|
65
72
|
);
|
|
66
73
|
|
|
67
|
-
const query: ServerJsonApiQuery =
|
|
74
|
+
const query: ServerJsonApiQuery = toServerJsonApiQuery(searchParams);
|
|
68
75
|
|
|
69
76
|
deepEqual(query, {
|
|
70
|
-
fields: {
|
|
71
|
-
filter: {
|
|
72
|
-
|
|
77
|
+
fields: { user: ["age", "name"] },
|
|
78
|
+
filter: {
|
|
79
|
+
age: { eq: ["2"] },
|
|
80
|
+
dateOfBirth: { gt: [date1], lt: [date2] },
|
|
81
|
+
isActive: { eq: ["true"] },
|
|
82
|
+
},
|
|
83
|
+
include: ["article"],
|
|
73
84
|
page: {
|
|
74
85
|
size: "10",
|
|
75
86
|
},
|
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from "./lib/
|
|
2
|
-
export * from "./lib/
|
|
1
|
+
export * from "./lib/query/toClientSearchParams";
|
|
2
|
+
export * from "./lib/query/toServerJsonApiQuery";
|
|
3
3
|
export * from "./lib/types";
|
package/src/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./lib/
|
|
5
|
-
tslib_1.__exportStar(require("./lib/
|
|
4
|
+
tslib_1.__exportStar(require("./lib/query/toClientSearchParams"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./lib/query/toServerJsonApiQuery"), exports);
|
|
6
6
|
tslib_1.__exportStar(require("./lib/types"), exports);
|
|
7
7
|
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/json-api/src/index.ts"],"names":[],"mappings":";;;AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/json-api/src/index.ts"],"names":[],"mappings":";;;AAAA,2EAAiD;AACjD,2EAAiD;AACjD,sDAA4B"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type ClientJsonApiQuery } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* Call this function from clients to convert from {@link ClientJsonApiQuery} to {@link URLSearchParams}.
|
|
4
|
+
*
|
|
5
|
+
* @includeExample ./packages/json-api/examples/toClientSearchParams.ts
|
|
6
|
+
*
|
|
7
|
+
* @see [Usage example](../../../examples/toClientSearchParams.ts)
|
|
8
|
+
*/
|
|
9
|
+
export declare function toClientSearchParams(query: ClientJsonApiQuery): URLSearchParams;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.toClientSearchParams = toClientSearchParams;
|
|
4
4
|
function filterValueString(value) {
|
|
5
5
|
return value instanceof Date ? value.toISOString() : String(value);
|
|
6
6
|
}
|
|
@@ -10,9 +10,11 @@ function join(values) {
|
|
|
10
10
|
/**
|
|
11
11
|
* Call this function from clients to convert from {@link ClientJsonApiQuery} to {@link URLSearchParams}.
|
|
12
12
|
*
|
|
13
|
-
* @
|
|
13
|
+
* @includeExample ./packages/json-api/examples/toClientSearchParams.ts
|
|
14
|
+
*
|
|
15
|
+
* @see [Usage example](../../../examples/toClientSearchParams.ts)
|
|
14
16
|
*/
|
|
15
|
-
function
|
|
17
|
+
function toClientSearchParams(query) {
|
|
16
18
|
const searchParams = new URLSearchParams();
|
|
17
19
|
if (query.fields) {
|
|
18
20
|
Object.entries(query.fields).forEach(([type, fields]) => {
|
|
@@ -22,17 +24,9 @@ function toSearchParams(query) {
|
|
|
22
24
|
if (query.filter) {
|
|
23
25
|
Object.entries(query.filter).forEach(([field, values]) => {
|
|
24
26
|
const filterField = `filter[${field}]`;
|
|
25
|
-
|
|
26
|
-
searchParams.append(filterField
|
|
27
|
-
}
|
|
28
|
-
else if (typeof values === "boolean") {
|
|
29
|
-
searchParams.append(filterField, String(values));
|
|
30
|
-
}
|
|
31
|
-
else if (typeof values === "object") {
|
|
32
|
-
Object.entries(values).forEach(([fieldType, value]) => {
|
|
33
|
-
searchParams.append(`${filterField}[${fieldType}]`, filterValueString(value));
|
|
34
|
-
});
|
|
35
|
-
}
|
|
27
|
+
Object.entries(values).forEach(([fieldType, value]) => {
|
|
28
|
+
searchParams.append(fieldType === "eq" ? filterField : `${filterField}[${fieldType}]`, join(value.map((value) => filterValueString(value))));
|
|
29
|
+
});
|
|
36
30
|
});
|
|
37
31
|
}
|
|
38
32
|
if (query.include) {
|
|
@@ -48,4 +42,4 @@ function toSearchParams(query) {
|
|
|
48
42
|
}
|
|
49
43
|
return searchParams;
|
|
50
44
|
}
|
|
51
|
-
//# sourceMappingURL=
|
|
45
|
+
//# sourceMappingURL=toClientSearchParams.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toClientSearchParams.js","sourceRoot":"","sources":["../../../../../../packages/json-api/src/lib/query/toClientSearchParams.ts"],"names":[],"mappings":";;AAiBA,oDAoCC;AAnDD,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,CAAC,GAAG,CAAC,CAAC;AAC1B,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,oBAAoB,CAAC,KAAyB;IAC5D,MAAM,YAAY,GAAG,IAAI,eAAe,E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Y,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"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type ServerJsonApiQuery } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* Call this function from servers to convert from {@link URLSearchParams} to {@link ServerJsonApiQuery}.
|
|
4
|
+
*
|
|
5
|
+
* @includeExample packages/json-api/examples/toServerJsonApiQuery.ts
|
|
6
|
+
*
|
|
7
|
+
* @see [Usage example](../../../examples/toServerJsonApiQuery.ts)
|
|
8
|
+
*/
|
|
9
|
+
export declare function toServerJsonApiQuery(searchParams: URLSearchParams): ServerJsonApiQuery;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.toServerJsonApiQuery = toServerJsonApiQuery;
|
|
4
4
|
const REGEX = {
|
|
5
5
|
fields: /^fields\[(.*?)]$/i,
|
|
6
6
|
filter: /^filter\[([^\]]*?)]$/i,
|
|
@@ -12,9 +12,11 @@ const REGEX = {
|
|
|
12
12
|
/**
|
|
13
13
|
* Call this function from servers to convert from {@link URLSearchParams} to {@link ServerJsonApiQuery}.
|
|
14
14
|
*
|
|
15
|
-
* @
|
|
15
|
+
* @includeExample packages/json-api/examples/toServerJsonApiQuery.ts
|
|
16
|
+
*
|
|
17
|
+
* @see [Usage example](../../../examples/toServerJsonApiQuery.ts)
|
|
16
18
|
*/
|
|
17
|
-
function
|
|
19
|
+
function toServerJsonApiQuery(searchParams) {
|
|
18
20
|
return [...searchParams].reduce((accumulator, [key, value]) => {
|
|
19
21
|
const match = Object.entries(REGEX).find(([, regex]) => regex.test(key));
|
|
20
22
|
if (!match) {
|
|
@@ -38,9 +40,10 @@ function toJsonApiQuery(searchParams) {
|
|
|
38
40
|
...accumulator,
|
|
39
41
|
filter: {
|
|
40
42
|
...accumulator.filter,
|
|
41
|
-
[field]:
|
|
42
|
-
|
|
43
|
-
: value.split(","),
|
|
43
|
+
[field]: {
|
|
44
|
+
...accumulator.filter?.[field],
|
|
45
|
+
[fieldType ?? "eq"]: value.split(","),
|
|
46
|
+
},
|
|
44
47
|
},
|
|
45
48
|
};
|
|
46
49
|
}
|
|
@@ -58,4 +61,4 @@ function toJsonApiQuery(searchParams) {
|
|
|
58
61
|
return accumulator;
|
|
59
62
|
}, {});
|
|
60
63
|
}
|
|
61
|
-
//# sourceMappingURL=
|
|
64
|
+
//# sourceMappingURL=toServerJsonApiQuery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toServerJsonApiQuery.js","sourceRoot":"","sources":["../../../../../../packages/json-api/src/lib/query/toServerJsonApiQuery.ts"],"names":[],"mappings":";;AAkBA,oDAiDC;AAjED,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;;;;;;GAMG;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,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC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I,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACnC,OAAO;gBACL,GAAG,WAAW;gBACd,IAAI,EAAE,EAAE,GAAG,WAAW,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE;aAClD,CAAC;QACJ,CAAC;QAED,0BAA0B;QAC1B,OAAO,WAAW,CAAC;IACrB,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC"}
|
package/src/lib/types.d.ts
CHANGED
|
@@ -1,58 +1,57 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Filter types to build complex filter queries.
|
|
3
|
-
* -
|
|
4
|
-
* -
|
|
5
|
-
* -
|
|
6
|
-
* -
|
|
7
|
-
* -
|
|
3
|
+
* - eq: Equal to; the default when no filter type is provided, do not explicitly include it.
|
|
4
|
+
* - ne: Not equal to.
|
|
5
|
+
* - gt: Greater than.
|
|
6
|
+
* - gte: Greater than or equal to.
|
|
7
|
+
* - lt: Less than.
|
|
8
|
+
* - lte: Less than or equal to.
|
|
8
9
|
*/
|
|
9
|
-
type FilterType = "
|
|
10
|
+
type FilterType = "eq" | "ne" | "gt" | "gte" | "lt" | "lte";
|
|
10
11
|
type PageKey = "cursor" | "limit" | "number" | "offset" | "size";
|
|
11
|
-
|
|
12
|
+
export { type URLSearchParams } from "node:url";
|
|
13
|
+
export interface JsonApiQueryTypes {
|
|
12
14
|
filterValue: unknown;
|
|
13
|
-
filterTypeValue: unknown;
|
|
14
15
|
pageValue: unknown;
|
|
15
16
|
}
|
|
16
17
|
export interface ClientTypes {
|
|
17
|
-
filterValue: Array<Date | number | string
|
|
18
|
-
filterTypeValue: Date | number | string;
|
|
18
|
+
filterValue: Array<Date | number | string | boolean>;
|
|
19
19
|
pageValue: number | string;
|
|
20
20
|
}
|
|
21
|
-
interface ServerTypes {
|
|
21
|
+
export interface ServerTypes {
|
|
22
22
|
filterValue: string[];
|
|
23
|
-
filterTypeValue: string;
|
|
24
23
|
pageValue: string;
|
|
25
24
|
}
|
|
26
25
|
/**
|
|
27
26
|
* A JSON:API URL query string.
|
|
28
27
|
*/
|
|
29
|
-
interface JsonApiQuery<T extends JsonApiQueryTypes> {
|
|
28
|
+
export interface JsonApiQuery<T extends JsonApiQueryTypes> {
|
|
30
29
|
/**
|
|
31
30
|
* Fields to include in the response.
|
|
32
31
|
*
|
|
33
|
-
* @see {@link https://jsonapi.org/format/#fetching-sparse-fieldsets
|
|
32
|
+
* @see {@link https://jsonapi.org/format/#fetching-sparse-fieldsets JSON:API sparse fieldsets}
|
|
34
33
|
*/
|
|
35
34
|
fields?: Record<string, string[]>;
|
|
36
35
|
/**
|
|
37
36
|
* Filters to apply to the query.
|
|
38
37
|
*
|
|
39
|
-
* @see {@link https://jsonapi.org/recommendations/#filtering
|
|
40
|
-
* @see {@link https://discuss.jsonapi.org/t/share-propose-a-filtering-strategy/257
|
|
38
|
+
* @see {@link https://jsonapi.org/recommendations/#filtering JSON:API filtering}
|
|
39
|
+
* @see {@link https://discuss.jsonapi.org/t/share-propose-a-filtering-strategy/257 JSON:API filtering strategy}
|
|
41
40
|
*/
|
|
42
|
-
filter?: Record<string,
|
|
43
|
-
[K in FilterType]?: T["
|
|
41
|
+
filter?: Record<string, {
|
|
42
|
+
[K in FilterType]?: T["filterValue"];
|
|
44
43
|
}>;
|
|
45
44
|
/**
|
|
46
45
|
* Relationships to include in the response.
|
|
47
46
|
*
|
|
48
|
-
* @see {@link https://jsonapi.org/format/#fetching-includes
|
|
47
|
+
* @see {@link https://jsonapi.org/format/#fetching-includes JSON:API fetching includes}
|
|
49
48
|
*/
|
|
50
49
|
include?: string[];
|
|
51
50
|
/**
|
|
52
51
|
* Pagination data.
|
|
53
52
|
*
|
|
54
|
-
* @see {@link https://jsonapi.org/format/#fetching-pagination
|
|
55
|
-
* @see {@link https://jsonapi.org/examples/#pagination
|
|
53
|
+
* @see {@link https://jsonapi.org/format/#fetching-pagination JSON:API pagination}
|
|
54
|
+
* @see {@link https://jsonapi.org/examples/#pagination JSON:API pagination examples}
|
|
56
55
|
*/
|
|
57
56
|
page?: {
|
|
58
57
|
[K in PageKey]?: T["pageValue"];
|
|
@@ -60,10 +59,9 @@ interface JsonApiQuery<T extends JsonApiQueryTypes> {
|
|
|
60
59
|
/**
|
|
61
60
|
* Sorting data. Include the "-" prefix for descending order.
|
|
62
61
|
*
|
|
63
|
-
* @see {@link https://jsonapi.org/format/#fetching-sorting
|
|
62
|
+
* @see {@link https://jsonapi.org/format/#fetching-sorting JSON:API sorting}
|
|
64
63
|
*/
|
|
65
64
|
sort?: string[];
|
|
66
65
|
}
|
|
67
66
|
export type ClientJsonApiQuery = JsonApiQuery<ClientTypes>;
|
|
68
67
|
export type ServerJsonApiQuery = JsonApiQuery<ServerTypes>;
|
|
69
|
-
export {};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { type ServerJsonApiQuery } from "./types";
|
|
2
|
-
/**
|
|
3
|
-
* Call this function from servers to convert from {@link URLSearchParams} to {@link ServerJsonApiQuery}.
|
|
4
|
-
*
|
|
5
|
-
* @see [Example](https://github.com/ClipboardHealth/core-utils/blob/main/packages/json-api/examples/toJsonApiQuery.ts)
|
|
6
|
-
*/
|
|
7
|
-
export declare function toJsonApiQuery(searchParams: URLSearchParams): ServerJsonApiQuery;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"toJsonApiQuery.js","sourceRoot":"","sources":["../../../../../packages/json-api/src/lib/toJsonApiQuery.ts"],"names":[],"mappings":";;AAgBA,wCAgDC;AA9DD,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;;;;GAIG;AACH,SAAgB,cAAc,CAAC,YAA6B;IAC1D,OAAO,CAAC,GAAG,YAAY,C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G,CAAC;qBACrB;iBACF,CAAC;YACJ,CAAC;QACH,CAAC;QAED,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;YAC1C,OAAO,EAAE,GAAG,WAAW,EAAE,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;QACtD,CAAC;QAED,IAAI,IAAI,KAAK,MAAM,IAAI,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACnC,OAAO;gBACL,GAAG,WAAW;gBACd,IAAI,EAAE,EAAE,GAAG,WAAW,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE;aAClD,CAAC;QACJ,CAAC;QAED,0BAA0B;QAC1B,OAAO,WAAW,CAAC;IACrB,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { type ClientJsonApiQuery } from "./types";
|
|
2
|
-
/**
|
|
3
|
-
* Call this function from clients to convert from {@link ClientJsonApiQuery} to {@link URLSearchParams}.
|
|
4
|
-
*
|
|
5
|
-
* @see [Example](https://github.com/ClipboardHealth/core-utils/blob/main/packages/json-api/examples/toSearchParams.ts)
|
|
6
|
-
*/
|
|
7
|
-
export declare function toSearchParams(query: ClientJsonApiQuery): URLSearchParams;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"toSearchParams.js","sourceRoot":"","sources":["../../../../../packages/json-api/src/lib/toSearchParams.ts"],"names":[],"mappings":";;AAeA,wCAuCC;AApDD,SAAS,iBAAiB,CAAC,KAAqC;IAC9D,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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