diff --git a/README.md b/README.md index 301578ac..f0c008cb 100644 --- a/README.md +++ b/README.md @@ -171,13 +171,13 @@ export default () => { > section for a more user-friendly way to achieve type-safety. If you wish to parse the searchParams in server components, you'll need to -import the parsers from `nuqs/parsers`, which doesn't include +import the parsers from `nuqs/server`, which doesn't include the `"use client"` directive. You can then use the `parseServerSide` method: ```tsx -import { parseAsInteger } from 'nuqs/parsers' +import { parseAsInteger } from 'nuqs/server' type PageProps = { searchParams: { @@ -394,7 +394,7 @@ You can get this pattern for your custom parsers too, and compose them with others: ```ts -import { createParser, parseAsHex } from 'nuqs/parsers' +import { createParser, parseAsHex } from 'nuqs' // Wrapping your parser/serializer in `createParser` // gives it access to the builder pattern & server-side @@ -529,8 +529,8 @@ import { createSearchParamsCache, parseAsInteger, parseAsString -} from 'nuqs/parsers' -// Note: import from '…/parsers' to avoid the "use client" directive +} from 'nuqs/server' +// Note: import from '…/server' to avoid the "use client" directive export const searchParamsCache = createSearchParamsCache({ // List your search param keys and associated parsers here: @@ -572,7 +572,7 @@ parser declaration with `useQueryStates` for type-safety in client components: ```tsx // searchParams.ts -import { parseAsFloat, createSearchParamsCache } from 'nuqs/parsers' +import { parseAsFloat, createSearchParamsCache } from 'nuqs/server' export const coordinatesParsers = { lat: parseAsFloat.withDefault(45.18), @@ -614,7 +614,7 @@ export function Server() { // client.tsx // prettier-ignore -'use client' +;'use client' import { useQueryStates } from 'nuqs' import { coordinatesParsers } from './searchParams' @@ -692,7 +692,7 @@ use `useQueryState` to read it: // page.tsx import type { Metadata, ResolvingMetadata } from 'next' import { useQueryState } from 'nuqs' -import { parseAsString } from 'nuqs/parsers' +import { parseAsString } from 'nuqs/server' type Props = { searchParams: { [key: string]: string | string[] | undefined } diff --git a/errors/NUQS-500.md b/errors/NUQS-500.md index 9e7f1021..4cfd9f24 100644 --- a/errors/NUQS-500.md +++ b/errors/NUQS-500.md @@ -26,7 +26,7 @@ import { createSearchParamsCache, parseAsInteger, parseAsString -} from 'nuqs/parsers' +} from 'nuqs/server' const cache = createSearchParamsCache({ q: parseAsString, diff --git a/packages/docs/content/docs/index.mdx b/packages/docs/content/docs/index.mdx index 5ec35e48..27cb8b39 100644 --- a/packages/docs/content/docs/index.mdx +++ b/packages/docs/content/docs/index.mdx @@ -162,13 +162,13 @@ export default () => { > section for a more user-friendly way to achieve type-safety. If you wish to parse the searchParams in server components, you'll need to -import the parsers from `nuqs/parsers`, which doesn't include +import the parsers from `nuqs/server`, which doesn't include the `"use client"` directive. You can then use the `parseServerSide` method: ```tsx -import { parseAsInteger } from 'nuqs/parsers' +import { parseAsInteger } from 'nuqs/server' type PageProps = { searchParams: { @@ -388,7 +388,7 @@ You can get this pattern for your custom parsers too, and compose them with others: ```ts -import { createParser, parseAsHex } from 'nuqs/parsers' +import { createParser, parseAsHex } from 'nuqs' // Wrapping your parser/serializer in `createParser` // gives it access to the builder pattern & server-side @@ -523,8 +523,8 @@ import { createSearchParamsCache, parseAsInteger, parseAsString -} from 'nuqs/parsers' -// Note: import from '…/parsers' to avoid the "use client" directive +} from 'nuqs/server' +// Note: import from '…/server' to avoid the "use client" directive export const searchParamsCache = createSearchParamsCache({ // List your search param keys and associated parsers here: @@ -569,7 +569,7 @@ parser declaration with `useQueryStates` for type-safety in client components: import { parseAsFloat, createSearchParamsCache -} from 'nuqs/parsers' +} from 'nuqs/server' export const coordinatesParsers = { lat: parseAsFloat.withDefault(45.18), @@ -689,7 +689,7 @@ use `useQueryState` to read it: // page.tsx import type { Metadata, ResolvingMetadata } from 'next' import { useQueryState } from 'nuqs' -import { parseAsString } from 'nuqs/parsers' +import { parseAsString } from 'nuqs/server' type Props = { searchParams: { [key: string]: string | string[] | undefined } diff --git a/packages/docs/src/app/(pages)/playground/server-side-parsing/parser.ts b/packages/docs/src/app/(pages)/playground/server-side-parsing/parser.ts index bede7766..fc9f7110 100644 --- a/packages/docs/src/app/(pages)/playground/server-side-parsing/parser.ts +++ b/packages/docs/src/app/(pages)/playground/server-side-parsing/parser.ts @@ -1,3 +1,3 @@ -import { parseAsInteger } from 'nuqs/parsers' +import { parseAsInteger } from 'nuqs/server' export const counterParser = parseAsInteger.withDefault(0) diff --git a/packages/docs/src/app/(pages)/playground/throttling/parsers.ts b/packages/docs/src/app/(pages)/playground/throttling/parsers.ts index 4798335c..b5f4e25d 100644 --- a/packages/docs/src/app/(pages)/playground/throttling/parsers.ts +++ b/packages/docs/src/app/(pages)/playground/throttling/parsers.ts @@ -1,4 +1,4 @@ -import { parseAsInteger, parseAsString } from 'nuqs/parsers' +import { parseAsInteger, parseAsString } from 'nuqs/server' export const delayParser = parseAsInteger.withDefault(0) export const queryParser = parseAsString.withDefault('') diff --git a/packages/e2e/src/app/app/cache/searchParams.ts b/packages/e2e/src/app/app/cache/searchParams.ts index d8351742..d8b7b5ad 100644 --- a/packages/e2e/src/app/app/cache/searchParams.ts +++ b/packages/e2e/src/app/app/cache/searchParams.ts @@ -3,7 +3,7 @@ import { parseAsBoolean, parseAsInteger, parseAsString -} from 'nuqs/parsers' +} from 'nuqs/server' export const parsers = { str: parseAsString, diff --git a/packages/e2e/src/app/app/rewrites/destination/page.tsx b/packages/e2e/src/app/app/rewrites/destination/page.tsx index bc29c5e2..5237eaf6 100644 --- a/packages/e2e/src/app/app/rewrites/destination/page.tsx +++ b/packages/e2e/src/app/app/rewrites/destination/page.tsx @@ -1,4 +1,4 @@ -import type { SearchParams } from 'nuqs/parsers' +import type { SearchParams } from 'nuqs/server' import { Suspense } from 'react' import { RewriteDestinationClient } from './client' import { cache } from './searchParams' diff --git a/packages/e2e/src/app/app/rewrites/destination/searchParams.ts b/packages/e2e/src/app/app/rewrites/destination/searchParams.ts index 3c822e45..c1b536be 100644 --- a/packages/e2e/src/app/app/rewrites/destination/searchParams.ts +++ b/packages/e2e/src/app/app/rewrites/destination/searchParams.ts @@ -1,4 +1,4 @@ -import { createSearchParamsCache, parseAsString } from 'nuqs/parsers' +import { createSearchParamsCache, parseAsString } from 'nuqs/server' export const searchParams = { injected: parseAsString.withDefault('null'), diff --git a/packages/e2e/src/app/app/routing-tour/_components/parsers.ts b/packages/e2e/src/app/app/routing-tour/_components/parsers.ts index c2ce900a..9b06599d 100644 --- a/packages/e2e/src/app/app/routing-tour/_components/parsers.ts +++ b/packages/e2e/src/app/app/routing-tour/_components/parsers.ts @@ -1,4 +1,4 @@ -import { parseAsInteger, parseAsString } from 'nuqs/parsers' +import { parseAsInteger, parseAsString } from 'nuqs/server' export const counterParser = parseAsInteger.withDefault(0) export const fromParser = parseAsString diff --git a/packages/nuqs/package.json b/packages/nuqs/package.json index 718de6a8..dc4e4146 100644 --- a/packages/nuqs/package.json +++ b/packages/nuqs/package.json @@ -39,9 +39,9 @@ "types": "./dist/index.d.ts", "import": "./dist/index.js" }, - "./parsers": { - "types": "./dist/parsers.d.ts", - "import": "./dist/parsers.js" + "./server": { + "types": "./dist/server.d.ts", + "import": "./dist/server.js" } }, "scripts": { @@ -87,8 +87,8 @@ ] }, { - "name": "Parsers", - "path": "dist/parsers.js", + "name": "Server", + "path": "dist/server.js", "limit": "2 kB", "ignore": [ "react" diff --git a/packages/nuqs/parsers.d.ts b/packages/nuqs/server.d.ts similarity index 72% rename from packages/nuqs/parsers.d.ts rename to packages/nuqs/server.d.ts index 6e0e1b44..11f42731 100644 --- a/packages/nuqs/parsers.d.ts +++ b/packages/nuqs/server.d.ts @@ -1,7 +1,7 @@ // This file is needed for projects that have `moduleResolution` set to `node` -// in their tsconfig.json to be able to `import {} from 'nuqs/parsers'`. +// in their tsconfig.json to be able to `import {} from 'nuqs/server'`. // Other module resolutions strategies will look for the `exports` in `package.json`, // but with `node`, TypeScript will look for a .d.ts file with that name at the // root of the package. -export * from './dist/parsers' +export * from './dist/server' diff --git a/packages/nuqs/src/index.parsers.ts b/packages/nuqs/src/index.server.ts similarity index 100% rename from packages/nuqs/src/index.parsers.ts rename to packages/nuqs/src/index.server.ts diff --git a/packages/nuqs/src/tests/cache.test-d.ts b/packages/nuqs/src/tests/cache.test-d.ts index 2812f8bf..49c3459f 100644 --- a/packages/nuqs/src/tests/cache.test-d.ts +++ b/packages/nuqs/src/tests/cache.test-d.ts @@ -4,7 +4,7 @@ import { parseAsBoolean, parseAsInteger, parseAsString -} from '../../dist/parsers' +} from '../../dist/server' { const cache = createSearchParamsCache({