From caea6223d1777daacbacdab561c9e98ac787775d Mon Sep 17 00:00:00 2001 From: devgioele Date: Thu, 31 Aug 2023 14:23:41 +0200 Subject: [PATCH 1/2] use dynamic import instead of require --- src/routers/__test__/nextRouter.test.ts | 3 +-- tsconfig.json | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/routers/__test__/nextRouter.test.ts b/src/routers/__test__/nextRouter.test.ts index 4f9a5b6..d97a0d6 100644 --- a/src/routers/__test__/nextRouter.test.ts +++ b/src/routers/__test__/nextRouter.test.ts @@ -5,8 +5,7 @@ import { expectTypeOf, vi } from 'vitest' import { useQuery, useQueryAndPagination } from '../../zod/routers/nextRouter' import { usePagination } from '../nextRouter' -// eslint-disable-next-line @typescript-eslint/no-unsafe-return -vi.mock('next/router', () => require('next-router-mock')) +vi.mock('next/router', async () => await import('next-router-mock')) describe('NextRouter', () => { beforeEach(() => { diff --git a/tsconfig.json b/tsconfig.json index 341f0e5..bcc56e8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,7 @@ { "extends": "@aboutbits/ts-config/react", "compilerOptions": { + "module": "es2020", "moduleResolution": "node", "skipLibCheck": true }, From 39c3a9fe35798869693903f78939d3c0adac12aa Mon Sep 17 00:00:00 2001 From: devgioele Date: Mon, 4 Sep 2023 08:43:28 +0200 Subject: [PATCH 2/2] add null as a valid query value --- src/engine/query.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/engine/query.ts b/src/engine/query.ts index e8eafcc..2a90498 100644 --- a/src/engine/query.ts +++ b/src/engine/query.ts @@ -8,6 +8,7 @@ export type AbstractQueryValueElement = | boolean | Date | bigint + | null export type AbstractQuery = Record< string, @@ -54,7 +55,7 @@ export type AbstractQueryOptions = { /** * How the abstract query is converted to an actual query. * - * @default Each value that is not undefined is converted to a string by calling `.toString()`. + * @default Each value that is not undefined and is converted to a string. `null` is converted to an empty string, while other values are converted calling `String(value)`. */ convertToQuery: (abstractQuery: Partial) => Query } @@ -64,7 +65,7 @@ const DEFAULT_ABSTRACT_QUERY_OPTIONS: AbstractQueryOptions = { const query: Query = {} for (const [key, value] of Object.entries(abstractQuery)) { if (value !== undefined) { - query[key] = value.toString() + query[key] = value === null ? '' : String(value) } } return query