diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index f06235c..0000000 --- a/.eslintignore +++ /dev/null @@ -1,2 +0,0 @@ -node_modules -dist diff --git a/.eslintrc.json b/.eslintrc.json index d5bbb3a..44b3322 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,66 +1,7 @@ { - "parser": "@typescript-eslint/parser", - "env": { - "browser": true, - "node": true - }, - "plugins": ["@typescript-eslint", "react", "react-hooks"], - "extends": [ - "eslint:recommended", - "plugin:@typescript-eslint/recommended", - "plugin:react/recommended", - "plugin:react/jsx-runtime", - "plugin:import/recommended", - "plugin:import/typescript", - "plugin:prettier/recommended" - ], + "extends": "@aboutbits/eslint-config/ts-react", "parserOptions": { - "sourceType": "module", - "ecmaVersion": 2018 - }, - "settings": { - "react": { - "version": "detect" - }, - "import/resolver": { - "node": { - "paths": ["./"] - } - } + "project": true }, - "rules": { - "react-hooks/rules-of-hooks": "error", - "react-hooks/exhaustive-deps": "error", - "@typescript-eslint/no-unused-vars": [ - "error", - { - "ignoreRestSiblings": true, - "varsIgnorePattern": "^[iI]gnored", - "argsIgnorePattern": "^_", - "caughtErrorsIgnorePattern": "^ignore" - } - ], - "@typescript-eslint/member-delimiter-style": "off", - "@typescript-eslint/explicit-function-return-type": "off", - "@next/next/no-img-element": "off", - "import/order": [ - "error", - { - "groups": [ - "builtin", - "external", - "unknown", - "parent", - "sibling", - "index" - ] - } - ], - "no-console": [ - "error", - { - "allow": ["warn", "error", "assert"] - } - ] - } + "ignorePatterns": ["node_modules", "dist"] } diff --git a/.gitignore b/.gitignore index 1d33405..5d73263 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,6 @@ # ESLint .eslintcache + +# TypeScript +*.tsbuildinfo diff --git a/.prettierrc b/.prettierrc deleted file mode 100644 index fd496a8..0000000 --- a/.prettierrc +++ /dev/null @@ -1,4 +0,0 @@ -{ - "singleQuote": true, - "semi": false -} diff --git a/package.json b/package.json index 2173824..a9ee1b5 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "@aboutbits/react-pagination", "version": "2.0.1", "description": "Pagination hooks for React", + "type": "module", "exports": { ".": { "types": "./dist/types/engine/index.d.ts", @@ -48,7 +49,7 @@ "build:esm": "tsc -p tsconfig.esm.json", "build:cjs": "tsc -p tsconfig.cjs.json", "build:types": "tsc -p tsconfig.types.json", - "lint": "eslint --ext js,ts,tsx --cache .", + "lint": "eslint --cache .", "lint:fix": "npm run lint -- --fix", "test": "vitest run --passWithNoTests", "test:watch": "vitest watch --passWithNoTests", @@ -85,23 +86,24 @@ "access": "public" }, "devDependencies": { + "@aboutbits/eslint-config": "^2.0.12", + "@aboutbits/prettier-config": "^1.5.0", + "@aboutbits/ts-config": "^1.1.2", "@testing-library/jest-dom": "^5.16.5", "@testing-library/react": "^13.4.0", "@types/react": "^18.0.0", "@types/react-dom": "^18.0.0", "@types/react-router-dom": "^5.3.3", - "@typescript-eslint/eslint-plugin": "^5.30.0", - "@typescript-eslint/parser": "^5.30.0", - "eslint": "^8.18.0", - "eslint-config-prettier": "^8.5.0", - "eslint-plugin-import": "^2.26.0", - "eslint-plugin-prettier": "^4.1.0", - "eslint-plugin-react": "^7.32.2", + "@typescript-eslint/eslint-plugin": "^6.1.0", + "eslint": "^8.45.0", + "eslint-plugin-import": "^2.27.5", + "eslint-plugin-prettier": "^5.0.0", + "eslint-plugin-react": "^7.33.0", "eslint-plugin-react-hooks": "^4.6.0", "jsdom": "^22.1.0", "next": "^13.1.3", "next-router-mock": "^0.7.4", - "prettier": "^2.7.1", + "prettier": "^3.0.0", "react": "^18.0.0", "react-dom": "^18.0.0", "react-router-dom": "^6.7.0", @@ -126,5 +128,6 @@ "zod": { "optional": true } - } + }, + "prettier": "@aboutbits/prettier-config" } diff --git a/src/engine/pagination.ts b/src/engine/pagination.ts index 61a3ee0..c462789 100644 --- a/src/engine/pagination.ts +++ b/src/engine/pagination.ts @@ -51,7 +51,7 @@ export const useAbstractQueryAndPagination = ( parseQuery: ParseQuery, router: Router, defaultPagination?: PaginationQuery, - options?: Partial + options?: Partial, ) => { const mergedDefaultPagination = { ...DEFAULT_PAGINATION, @@ -66,7 +66,7 @@ export const useAbstractQueryAndPagination = ( mergedDefaultQueryAndPagination, parseQuery, router, - options + options, ) const { @@ -77,7 +77,7 @@ export const useAbstractQueryAndPagination = ( mergedDefaultPagination, parsePagination, router, - options + options, ) return { @@ -102,10 +102,16 @@ export const useAbstractQueryAndPagination = ( }, page: pagination.page, size: pagination.size, - setPage: (page: PaginationQuery['page']) => setPagination({ page }), - setSize: (size: PaginationQuery['size']) => setPagination({ size }), + setPage: (page: PaginationQuery['page']) => { + setPagination({ page }) + }, + setSize: (size: PaginationQuery['size']) => { + setPagination({ size }) + }, setPagination, resetPagination, - resetQueryAndPagination: () => setQuery(mergedDefaultQueryAndPagination), + resetQueryAndPagination: () => { + setQuery(mergedDefaultQueryAndPagination) + }, } } diff --git a/src/engine/query.ts b/src/engine/query.ts index 3c5cba6..e5f73f4 100644 --- a/src/engine/query.ts +++ b/src/engine/query.ts @@ -35,16 +35,17 @@ export type Router = { } export const useQuery = (defaultQuery: T, router: Router) => { - const resetQuery = useCallback( - () => router.setQuery(defaultQuery, defaultQuery), - [router, defaultQuery] - ) + const resetQuery = useCallback(() => { + router.setQuery(defaultQuery, defaultQuery) + }, [router, defaultQuery]) const query = router.getQuery(defaultQuery) return { query, - setQuery: (query: Partial) => router.setQuery(query, defaultQuery), + setQuery: (query: Partial) => { + router.setQuery(query, defaultQuery) + }, resetQuery, } } @@ -74,21 +75,21 @@ export const useAbstractQuery = ( defaultQuery: T, parseQuery: ParseQuery, router: Router, - options?: Partial + options?: Partial, ) => { const mergedOptions = useMemo( () => ({ ...DEFAULT_ABSTRACT_QUERY_OPTIONS, ...options }), - [options] + [options], ) const convertedDefaultQuery = useMemo( () => mergedOptions.convertToQuery(defaultQuery), - [mergedOptions, defaultQuery] + [mergedOptions, defaultQuery], ) const { query, setQuery, resetQuery } = useQuery( convertedDefaultQuery, - router + router, ) const parsedQuery: T = useMemo(() => { @@ -105,8 +106,10 @@ export const useAbstractQuery = ( }, [defaultQuery, parseQuery, query]) const setAbstractQuery = useCallback( - (query: Partial) => setQuery(mergedOptions.convertToQuery(query)), - [setQuery, mergedOptions] + (query: Partial) => { + setQuery(mergedOptions.convertToQuery(query)) + }, + [setQuery, mergedOptions], ) return { diff --git a/src/routers/__test__/inMemory.test.ts b/src/routers/__test__/inMemory.test.ts index a8ea949..eae893e 100644 --- a/src/routers/__test__/inMemory.test.ts +++ b/src/routers/__test__/inMemory.test.ts @@ -10,7 +10,7 @@ describe('InMemory', () => { }) const useInMemoryQueryWithSearch = ( - defaultQuery: NonNullableRecord> + defaultQuery: NonNullableRecord>, ) => useQuery(defaultQuery, searchSchema) test('should set default page and size', () => { @@ -38,14 +38,14 @@ describe('InMemory', () => { const search = 'Max' const { result } = renderHook(() => - useInMemoryQueryWithSearch({ search: '' }) + useInMemoryQueryWithSearch({ search: '' }), ) act(() => { result.current.setQuery({ search }) }) - expect(result.current.query?.search).toBe(search) + expect(result.current.query.search).toBe(search) }) test('changing pagination should not reset the remaining query', () => { @@ -53,7 +53,7 @@ describe('InMemory', () => { const page = 2 const { result } = renderHook(() => - useQueryAndPagination({ search: '' }, searchSchema) + useQueryAndPagination({ search: '' }, searchSchema), ) act(() => { @@ -90,7 +90,7 @@ describe('InMemory', () => { const page = 2 const { result } = renderHook(() => - useQueryAndPagination({ search: defaultSearch }, searchSchema) + useQueryAndPagination({ search: defaultSearch }, searchSchema), ) act(() => { @@ -125,7 +125,7 @@ describe('InMemory', () => { const page = 2 const { result } = renderHook(() => - useQueryAndPagination({ search: defaultSearch }, searchSchema) + useQueryAndPagination({ search: defaultSearch }, searchSchema), ) act(() => { @@ -159,7 +159,7 @@ describe('InMemory', () => { }) const { result } = renderHook(() => - useQuery({ search: '', department: '' }, schema) + useQuery({ search: '', department: '' }, schema), ) act(() => { @@ -178,7 +178,7 @@ describe('InMemory', () => { const search = '' const { result } = renderHook(() => - useQuery({ search: 'Default search' }, searchSchema) + useQuery({ search: 'Default search' }, searchSchema), ) act(() => { diff --git a/src/routers/__test__/nextRouter.test.ts b/src/routers/__test__/nextRouter.test.ts index dadc446..46f95ae 100644 --- a/src/routers/__test__/nextRouter.test.ts +++ b/src/routers/__test__/nextRouter.test.ts @@ -6,6 +6,7 @@ import { NonNullableRecord } from '../../utils' 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')) describe('NextRouter', () => { @@ -18,7 +19,7 @@ describe('NextRouter', () => { }) const useNextRouterQueryWithSearch = ( - defaultQuery: NonNullableRecord> + defaultQuery: NonNullableRecord>, ) => useQuery(defaultQuery, searchSchema) test('should set default page and size', () => { @@ -47,14 +48,14 @@ describe('NextRouter', () => { const search = 'Max' const { result } = renderHook(() => - useNextRouterQueryWithSearch({ search: '' }) + useNextRouterQueryWithSearch({ search: '' }), ) act(() => { result.current.setQuery({ search }) }) - expect(result.current.query?.search).toBe(search) + expect(result.current.query.search).toBe(search) expect(router.query.search).toBe(search) }) @@ -63,7 +64,7 @@ describe('NextRouter', () => { const page = 2 const { result } = renderHook(() => - useQueryAndPagination({ search: '' }, searchSchema) + useQueryAndPagination({ search: '' }, searchSchema), ) act(() => { @@ -103,7 +104,7 @@ describe('NextRouter', () => { const page = 2 const { result } = renderHook(() => - useQueryAndPagination({ search: defaultSearch }, searchSchema) + useQueryAndPagination({ search: defaultSearch }, searchSchema), ) act(() => { @@ -145,7 +146,7 @@ describe('NextRouter', () => { const page = 2 const { result } = renderHook(() => - useQueryAndPagination({ search: defaultSearch }, searchSchema) + useQueryAndPagination({ search: defaultSearch }, searchSchema), ) act(() => { @@ -202,8 +203,8 @@ describe('NextRouter', () => { netWorth: defaultNetWorth, darkMode: defaultDarkMode, }, - schema - ) + schema, + ), ) act(() => { @@ -241,7 +242,7 @@ describe('NextRouter', () => { router.query = { search: 'Max' } const { result } = renderHook(() => - useQuery({ search: defaultSearch }, searchSchema) + useQuery({ search: defaultSearch }, searchSchema), ) act(() => { @@ -256,7 +257,7 @@ describe('NextRouter', () => { const search = '' const { result } = renderHook(() => - useQuery({ search: 'Default search' }, searchSchema) + useQuery({ search: 'Default search' }, searchSchema), ) act(() => { diff --git a/src/routers/__test__/reactRouter.test.tsx b/src/routers/__test__/reactRouter.test.tsx index f02a2ea..803ff28 100644 --- a/src/routers/__test__/reactRouter.test.tsx +++ b/src/routers/__test__/reactRouter.test.tsx @@ -6,7 +6,7 @@ import { useQuery, useQueryAndPagination } from '../../zod/routers/reactRouter' import { usePagination } from '../reactRouter' const renderHookWithContext = ( - render: (initialProps: Props) => Result + render: (initialProps: Props) => Result, ) => renderHook(render, { wrapper: ({ children }) => { @@ -24,14 +24,14 @@ describe('ReactRouter', () => { }) const useReactRouterQueryWithSearch = ( - defaultQuery: NonNullableRecord> + defaultQuery: NonNullableRecord>, ) => useQuery(defaultQuery, searchSchema) test('should set default page and size', () => { const page = 0 const size = 15 const { result } = renderHookWithContext(() => - usePagination({ page, size }) + usePagination({ page, size }), ) expect(result.current.page).toBe(page) @@ -55,14 +55,14 @@ describe('ReactRouter', () => { const search = 'Max' const { result } = renderHookWithContext(() => - useReactRouterQueryWithSearch({ search: '' }) + useReactRouterQueryWithSearch({ search: '' }), ) act(() => { result.current.setQuery({ search }) }) - expect(result.current.query?.search).toBe(search) + expect(result.current.query.search).toBe(search) expect(window.location.search).toBe(`?search=${search}`) }) @@ -71,7 +71,7 @@ describe('ReactRouter', () => { const page = 2 const { result } = renderHookWithContext(() => - useQueryAndPagination({ search: '' }, searchSchema) + useQueryAndPagination({ search: '' }, searchSchema), ) act(() => { @@ -97,7 +97,7 @@ describe('ReactRouter', () => { const page = 1 const size = 10 const { result } = renderHookWithContext(() => - usePagination({ page, size }) + usePagination({ page, size }), ) expect(result.current.page).toBe(page) @@ -111,7 +111,7 @@ describe('ReactRouter', () => { const page = 2 const { result } = renderHookWithContext(() => - useQueryAndPagination({ search: defaultSearch }, searchSchema) + useQueryAndPagination({ search: defaultSearch }, searchSchema), ) act(() => { @@ -149,7 +149,7 @@ describe('ReactRouter', () => { const page = 2 const { result } = renderHookWithContext(() => - useQueryAndPagination({ search: defaultSearch }, searchSchema) + useQueryAndPagination({ search: defaultSearch }, searchSchema), ) act(() => { @@ -186,7 +186,7 @@ describe('ReactRouter', () => { }) const { result } = renderHookWithContext(() => - useQuery({ search: '', department: '' }, schema) + useQuery({ search: '', department: '' }, schema), ) act(() => { @@ -207,7 +207,7 @@ describe('ReactRouter', () => { window.history.pushState({}, '', `/?greeting=${greeting}`) const { result } = renderHookWithContext(() => - useQuery({ search: '' }, searchSchema) + useQuery({ search: '' }, searchSchema), ) act(() => { @@ -216,7 +216,7 @@ describe('ReactRouter', () => { expect(result.current.query.search).toBe(search) expect(window.location.search).toBe( - `?greeting=${greeting}&search=${search}` + `?greeting=${greeting}&search=${search}`, ) }) @@ -226,7 +226,7 @@ describe('ReactRouter', () => { window.history.pushState({}, '', `/?search=Max`) const { result } = renderHookWithContext(() => - useQuery({ search: defaultSearch }, searchSchema) + useQuery({ search: defaultSearch }, searchSchema), ) act(() => { @@ -241,7 +241,7 @@ describe('ReactRouter', () => { const search = '' const { result } = renderHookWithContext(() => - useQuery({ search: 'Default search' }, searchSchema) + useQuery({ search: 'Default search' }, searchSchema), ) act(() => { diff --git a/src/routers/inMemory.ts b/src/routers/inMemory.ts index f18de91..c8e8f54 100644 --- a/src/routers/inMemory.ts +++ b/src/routers/inMemory.ts @@ -32,7 +32,7 @@ const useInMemoryRouter = (): Router => { export const useQuery = ( defaultQuery: T, parseQuery: ParseQuery, - options?: Partial + options?: Partial, ) => { const router = useInMemoryRouter() return useAbstractQuery(defaultQuery, parseQuery, router, options) @@ -42,7 +42,7 @@ export const useQueryAndPagination = ( defaultQuery: T, parseQuery: ParseQuery, defaultPagination?: PaginationQuery, - options?: Partial + options?: Partial, ) => { const router = useInMemoryRouter() return useAbstractQueryAndPagination( @@ -50,13 +50,13 @@ export const useQueryAndPagination = ( parseQuery, router, defaultPagination, - options + options, ) } export const usePagination = ( defaultPagination?: PaginationQuery, - options?: Partial + options?: Partial, ) => { const { page, size, setPage, setSize, setPagination, resetPagination } = useQueryAndPagination({}, () => ({}), defaultPagination, options) diff --git a/src/routers/nextRouter.ts b/src/routers/nextRouter.ts index 5ce2ff7..85b3dcd 100644 --- a/src/routers/nextRouter.ts +++ b/src/routers/nextRouter.ts @@ -19,13 +19,13 @@ const DEFAULT_NEXT_ROUTER_OPTIONS: RouterWithHistoryOptions = { } const useNextRouter = ( - options: undefined | Partial + options: undefined | Partial, ): Router => { const nextRouter = useRouter() const mergedOptions = useMemo( () => ({ ...DEFAULT_NEXT_ROUTER_OPTIONS, ...options }), - [options] + [options], ) return { @@ -40,15 +40,19 @@ const useNextRouter = ( }, setQuery: (query, defaultQuery) => { const newQuery = { ...nextRouter.query, ...query } - for (const [key, value] of Object.entries(query)) { - if (value === defaultQuery[key]) { - delete newQuery[key] - } - } + const newQueryWithoutDefaults = Object.fromEntries( + Object.entries(newQuery).filter( + ([key, value]) => value !== defaultQuery[key], + ), + ) if (mergedOptions.setQueryMethod === 'push') { - nextRouter.push({ query: newQuery }, undefined, { shallow: true }) + void nextRouter.push({ query: newQueryWithoutDefaults }, undefined, { + shallow: true, + }) } else { - nextRouter.replace({ query: newQuery }, undefined, { shallow: true }) + void nextRouter.replace({ query: newQueryWithoutDefaults }, undefined, { + shallow: true, + }) } }, } @@ -57,7 +61,7 @@ const useNextRouter = ( export const useQuery = ( defaultQuery: T, parseQuery: ParseQuery, - options?: Partial + options?: Partial, ) => { const router = useNextRouter(options) return useAbstractQuery(defaultQuery, parseQuery, router, options) @@ -67,7 +71,7 @@ export const useQueryAndPagination = ( defaultQuery: T, parseQuery: ParseQuery, defaultPagination?: PaginationQuery, - options?: Partial + options?: Partial, ) => { const router = useNextRouter(options) return useAbstractQueryAndPagination( @@ -75,13 +79,13 @@ export const useQueryAndPagination = ( parseQuery, router, defaultPagination, - options + options, ) } export const usePagination = ( defaultPagination?: PaginationQuery, - options?: Partial + options?: Partial, ) => { const { page, size, setPage, setSize, setPagination, resetPagination } = useQueryAndPagination({}, () => ({}), defaultPagination, options) diff --git a/src/routers/reactRouter.ts b/src/routers/reactRouter.ts index fee5529..5aaeb0f 100644 --- a/src/routers/reactRouter.ts +++ b/src/routers/reactRouter.ts @@ -17,14 +17,14 @@ const DEFAULT_REACT_ROUTER_OPTIONS: RouterWithHistoryOptions = { } const useReactRouter = ( - options: undefined | Partial + options: undefined | Partial, ): Router => { const navigate = useNavigate() const { pathname, search } = useLocation() const mergedOptions = useMemo( () => ({ ...DEFAULT_REACT_ROUTER_OPTIONS, ...options }), - [options] + [options], ) return { @@ -61,7 +61,7 @@ const useReactRouter = ( } navigate( { pathname, search: urlSearchParams.toString() }, - { replace: mergedOptions.setQueryMethod === 'replace' } + { replace: mergedOptions.setQueryMethod === 'replace' }, ) }, } @@ -70,7 +70,7 @@ const useReactRouter = ( export const useQuery = ( defaultQuery: T, parseQuery: ParseQuery, - options?: Partial + options?: Partial, ) => { const router = useReactRouter(options) return useAbstractQuery(defaultQuery, parseQuery, router, options) @@ -80,7 +80,7 @@ export const useQueryAndPagination = ( defaultQuery: T, parseQuery: ParseQuery, defaultPagination?: PaginationQuery, - options?: Partial + options?: Partial, ) => { const router = useReactRouter(options) return useAbstractQueryAndPagination( @@ -88,13 +88,13 @@ export const useQueryAndPagination = ( parseQuery, router, defaultPagination, - options + options, ) } export const usePagination = ( defaultPagination?: PaginationQuery, - options?: Partial + options?: Partial, ) => { const { page, size, setPage, setSize, setPagination, resetPagination } = useQueryAndPagination({}, () => ({}), defaultPagination, options) diff --git a/src/utils.ts b/src/utils.ts index c49ff18..e2002ec 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,13 +1,13 @@ import { Query } from './engine/query' export type NonNullableRecord< - T extends Record + T extends Record, > = { [Key in keyof T]-?: NonNullable } export const queryValueToIntOrUndefined = ( - value: Query[keyof Query] | undefined + value: Query[keyof Query] | undefined, ): number | undefined => { if (value === undefined || Array.isArray(value)) { return undefined diff --git a/src/zod/routers/inMemory.ts b/src/zod/routers/inMemory.ts index 7eef00b..d0c9427 100644 --- a/src/zod/routers/inMemory.ts +++ b/src/zod/routers/inMemory.ts @@ -15,27 +15,27 @@ export const useQuery = < TQuery extends NonNullableRecord, TSchemaOutput extends Partial, TSchemaDef extends ZodTypeDef = ZodTypeDef, - TSchemaInput = TSchemaOutput + TSchemaInput = TSchemaOutput, >( defaultQuery: TQuery, schemaQuery: ZodType, - options?: Partial + options?: Partial, ) => useQueryVanilla(defaultQuery, zodParser(schemaQuery), options) export const useQueryAndPagination = < TQuery extends NonNullableRecord, TSchemaOutput extends Partial, TSchemaDef extends ZodTypeDef = ZodTypeDef, - TSchemaInput = TSchemaOutput + TSchemaInput = TSchemaOutput, >( defaultQuery: TQuery, schemaQuery: ZodType, defaultPagination?: PaginationQuery, - options?: Partial + options?: Partial, ) => useQueryAndPaginationVanilla( defaultQuery, zodParser(schemaQuery), defaultPagination, - options + options, ) diff --git a/src/zod/routers/nextRouter.ts b/src/zod/routers/nextRouter.ts index 7878d40..a0374ab 100644 --- a/src/zod/routers/nextRouter.ts +++ b/src/zod/routers/nextRouter.ts @@ -16,27 +16,27 @@ export const useQuery = < TQuery extends NonNullableRecord, TSchemaOutput extends Partial, TSchemaDef extends ZodTypeDef = ZodTypeDef, - TSchemaInput = TSchemaOutput + TSchemaInput = TSchemaOutput, >( defaultQuery: TQuery, schemaQuery: ZodType, - options?: Partial + options?: Partial, ) => useQueryVanilla(defaultQuery, zodParser(schemaQuery), options) export const useQueryAndPagination = < TQuery extends NonNullableRecord, TSchemaOutput extends Partial, TSchemaDef extends ZodTypeDef = ZodTypeDef, - TSchemaInput = TSchemaOutput + TSchemaInput = TSchemaOutput, >( defaultQuery: TQuery, schemaQuery: ZodType, defaultPagination?: PaginationQuery, - options?: Partial + options?: Partial, ) => useQueryAndPaginationVanilla( defaultQuery, zodParser(schemaQuery), defaultPagination, - options + options, ) diff --git a/src/zod/routers/reactRouter.ts b/src/zod/routers/reactRouter.ts index 4ffe8fe..d0350b3 100644 --- a/src/zod/routers/reactRouter.ts +++ b/src/zod/routers/reactRouter.ts @@ -16,27 +16,27 @@ export const useQuery = < TQuery extends NonNullableRecord, TSchemaOutput extends Partial, TSchemaDef extends ZodTypeDef = ZodTypeDef, - TSchemaInput = TSchemaOutput + TSchemaInput = TSchemaOutput, >( defaultQuery: TQuery, schemaQuery: ZodType, - options?: Partial + options?: Partial, ) => useQueryVanilla(defaultQuery, zodParser(schemaQuery), options) export const useQueryAndPagination = < TQuery extends NonNullableRecord, TSchemaOutput extends Partial, TSchemaDef extends ZodTypeDef = ZodTypeDef, - TSchemaInput = TSchemaOutput + TSchemaInput = TSchemaOutput, >( defaultQuery: TQuery, schemaQuery: ZodType, defaultPagination?: PaginationQuery, - options?: Partial + options?: Partial, ) => useQueryAndPaginationVanilla( defaultQuery, zodParser(schemaQuery), defaultPagination, - options + options, ) diff --git a/src/zod/util.ts b/src/zod/util.ts index 625ef83..ae2eff2 100644 --- a/src/zod/util.ts +++ b/src/zod/util.ts @@ -3,7 +3,7 @@ import { AbstractQuery, ParseQuery } from '../engine/query' export const zodParser = , Def extends ZodTypeDef, Input>( - schema: ZodType + schema: ZodType, ): ParseQuery => (q) => schema.parse(q) diff --git a/tsconfig.cjs.json b/tsconfig.cjs.json index 678c53c..46ef3ae 100644 --- a/tsconfig.cjs.json +++ b/tsconfig.cjs.json @@ -2,18 +2,13 @@ "extends": "./tsconfig.json", "compilerOptions": { "module": "commonjs", + "moduleResolution": "node", "outDir": "./dist/cjs", "declaration": false, "declarationMap": false, "sourceMap": false, "removeComments": true }, - "exclude": [ - "src/vitest.ts", - "**/__test__/*", - "**/__tests__/*" - ], - "include": [ - "src" - ] + "exclude": ["src/vitest.ts", "**/__test__/*", "**/__tests__/*"], + "include": ["src"] } diff --git a/tsconfig.esm.json b/tsconfig.esm.json index 999299b..1afe2c2 100644 --- a/tsconfig.esm.json +++ b/tsconfig.esm.json @@ -6,14 +6,9 @@ "declaration": false, "declarationMap": false, "sourceMap": false, - "removeComments": true + "removeComments": true, + "incremental": false }, - "exclude": [ - "src/vitest.ts", - "**/__test__/*", - "**/__tests__/*" - ], - "include": [ - "src" - ] + "exclude": ["src/vitest.ts", "**/__test__/*", "**/__tests__/*"], + "include": ["src"] } diff --git a/tsconfig.json b/tsconfig.json index 11c6705..982e3e8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,26 +1,8 @@ { + "extends": "@aboutbits/ts-config/react", "compilerOptions": { - "target": "es2020", - "moduleResolution": "node", - "esModuleInterop": true, - "resolveJsonModule": true, - "strict": true, - "noImplicitReturns": true, - "noImplicitOverride": true, - "noFallthroughCasesInSwitch": true, - "noUncheckedIndexedAccess": true, - "forceConsistentCasingInFileNames": true, - "allowUnreachableCode": false, - "downlevelIteration": true, - "isolatedModules": true, - "jsx": "react-jsx", - "importHelpers": true, - "outDir": "./dist", - "declaration": true, - "sourceMap": true, "skipLibCheck": true }, - "include": [ - "src" - ] + "exclude": ["node_modules", "dist"], + "include": ["**/*.ts", "**/*.tsx", "**/*.js"] }