Skip to content

Commit 7de6a97

Browse files
lukasvicealexlanz
andauthored
remove not-stringifyable params from query (e.g. null) (#26)
* 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 0c7029f commit 7de6a97

5 files changed

Lines changed: 41 additions & 21 deletions

File tree

.github/workflows/main.yml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,27 @@ concurrency:
77
cancel-in-progress: true
88

99
jobs:
10+
checks:
11+
runs-on: ubuntu-22.04
12+
timeout-minutes: 10
13+
strategy:
14+
matrix:
15+
node_version: [16, 18, 20]
16+
steps:
17+
- uses: actions/checkout@v4
18+
- uses: aboutbits/github-actions-node/setup-and-install@v2
19+
with:
20+
node-version: ${{ matrix.node_version }}
21+
- name: Lint
22+
run: npm run lint
23+
shell: bash
24+
- name: Typecheck
25+
run: npm run typecheck
26+
shell: bash
27+
1028
test:
1129
runs-on: ubuntu-22.04
12-
timeout-minutes: 15
30+
timeout-minutes: 10
1331
strategy:
1432
matrix:
1533
node_version: [16, 18, 20]
@@ -18,4 +36,6 @@ jobs:
1836
- uses: aboutbits/github-actions-node/setup-and-install@v2
1937
with:
2038
node-version: ${{ matrix.node_version }}
21-
- run: npm run checks
39+
- name: Test
40+
run: npm run test
41+
shell: bash

.github/workflows/release.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ jobs:
2121
owner: context.repo.owner,
2222
repo: context.repo.repo,
2323
tag_name: '${{ github.ref }}',
24-
name: 'Release ${{ github.ref_name }}'
24+
name: 'Release ${{ github.ref_name }}',
25+
prerelease: '${{ github.ref_name }}'.includes('-')
2526
})
2627
- uses: aboutbits/github-actions-node/setup-and-install@v2
2728
with:

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@aboutbits/react-pagination",
3-
"version": "3.1.2",
3+
"version": "3.1.3-beta.1",
44
"description": "Pagination hooks for React",
55
"author": "About Bits",
66
"license": "MIT",
@@ -81,7 +81,7 @@
8181
"vitest": "^1.4.0"
8282
},
8383
"peerDependencies": {
84-
"next": "^12.0.0 || ^13.0.0 || ^14.0.0",
84+
"next": "^12.0.0 || ^13.0.0 || ^14.0.0 || ^15.0.0",
8585
"react": "^16.0.0 || ^17.0.0 || ^18.0.0",
8686
"react-router-dom": "^6.0.0",
8787
"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)