Skip to content

Commit daf423b

Browse files
lukasvicealexlanz
andauthored
remove not-stringifyable params from query (e.g. null) + add next 15 support (#31)
* remove not-stringifyable params from query (e.g. null) * add next 15 support * remove obsolete AbstractQueryValueElement --------- Co-authored-by: Alex Lanz <alex.lanz@aboutbits.it>
1 parent 6e75db9 commit daf423b

2 files changed

Lines changed: 14 additions & 15 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
"vitest": "^1.4.0"
8383
},
8484
"peerDependencies": {
85-
"next": "^12.0.0 || ^13.0.0 || ^14.0.0",
85+
"next": "^12.0.0 || ^13.0.0 || ^14.0.0 || ^15.0.0",
8686
"react": "^16.0.0 || ^17.0.0 || ^18.0.0",
8787
"react-router-dom": "^6.0.0",
8888
"zod": "^3.0.0"

src/engine/query.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,7 @@ import { useCallback, useMemo } from 'react'
22

33
export type Query = Record<string, string | string[]>
44

5-
export type AbstractQueryValueElement =
6-
| string
7-
| number
8-
| boolean
9-
| Date
10-
| bigint
11-
12-
export type AbstractQuery = Record<
13-
string,
14-
AbstractQueryValueElement | AbstractQueryValueElement[]
15-
>
5+
export type AbstractQuery = Record<string, unknown>
166

177
/**
188
* Parses the query.
@@ -59,7 +49,7 @@ export type AbstractQueryOptions = {
5949
/**
6050
* How the abstract query is converted to an actual query.
6151
*
62-
* @default Each value that is not undefined is converted to a string by calling `.toString()`.
52+
* @default Each value that is not undefined is converted to a string by calling `.toString()` or removed if not stringifyable.
6353
*/
6454
convertToQuery: (abstractQuery: Partial<AbstractQuery>) => Query
6555
}
@@ -69,10 +59,19 @@ const DEFAULT_ABSTRACT_QUERY_OPTIONS: AbstractQueryOptions = {
6959
const query: Query = {}
7060
for (const [key, value] of Object.entries(abstractQuery)) {
7161
if (Array.isArray(value)) {
72-
query[key] = value.map((v) => v.toString())
62+
query[key] = value.map((v: unknown) =>
63+
typeof v?.toString === 'function'
64+
? // eslint-disable-next-line @typescript-eslint/no-base-to-string
65+
v.toString()
66+
: '',
67+
)
7368
} else {
7469
if (value !== undefined) {
75-
query[key] = value.toString()
70+
query[key] =
71+
typeof value?.toString === 'function'
72+
? // eslint-disable-next-line @typescript-eslint/no-base-to-string
73+
value.toString()
74+
: ''
7675
}
7776
}
7877
}

0 commit comments

Comments
 (0)