Skip to content

Commit 2cc9824

Browse files
committed
remove not-stringifyable params from query (e.g. null)
1 parent 0c7029f commit 2cc9824

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

src/engine/query.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ export type AbstractQueryValueElement =
99
| Date
1010
| bigint
1111

12-
export type AbstractQuery = Record<
13-
string,
14-
AbstractQueryValueElement | AbstractQueryValueElement[]
15-
>
12+
export type AbstractQuery = Record<string, unknown>
1613

1714
/**
1815
* Parses the query.
@@ -59,7 +56,7 @@ export type AbstractQueryOptions = {
5956
/**
6057
* How the abstract query is converted to an actual query.
6158
*
62-
* @default Each value that is not undefined is converted to a string by calling `.toString()`.
59+
* @default Each value that is not undefined is converted to a string by calling `.toString()` or removed if not stringifyable.
6360
*/
6461
convertToQuery: (abstractQuery: Partial<AbstractQuery>) => Query
6562
}
@@ -69,10 +66,19 @@ const DEFAULT_ABSTRACT_QUERY_OPTIONS: AbstractQueryOptions = {
6966
const query: Query = {}
7067
for (const [key, value] of Object.entries(abstractQuery)) {
7168
if (Array.isArray(value)) {
72-
query[key] = value.map((v) => v.toString())
69+
query[key] = value.map((v: unknown) =>
70+
typeof v?.toString === 'function'
71+
? // eslint-disable-next-line @typescript-eslint/no-base-to-string
72+
v.toString()
73+
: '',
74+
)
7375
} else {
7476
if (value !== undefined) {
75-
query[key] = value.toString()
77+
query[key] =
78+
typeof value?.toString === 'function'
79+
? // eslint-disable-next-line @typescript-eslint/no-base-to-string
80+
value.toString()
81+
: ''
7682
}
7783
}
7884
}

0 commit comments

Comments
 (0)