Skip to content

Commit

Permalink
chore: Rename nuqs/parsers to nuqs/server
Browse files Browse the repository at this point in the history
BREAKING CHANGE: export path has been renamed. Contents are identical.

Since the `/parsers` export contained the server cache,
this name makes better sense and helps outline the client/server
nature of features in nuqs.
  • Loading branch information
franky47 committed Jan 17, 2024
1 parent abcbfdc commit ad3aa48
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 30 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -614,7 +614,7 @@ export function Server() {

// client.tsx
// prettier-ignore
'use client'
;'use client'

import { useQueryStates } from 'nuqs'
import { coordinatesParsers } from './searchParams'
Expand Down Expand Up @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion errors/NUQS-500.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
createSearchParamsCache,
parseAsInteger,
parseAsString
} from 'nuqs/parsers'
} from 'nuqs/server'

const cache = createSearchParamsCache({
q: parseAsString,
Expand Down
14 changes: 7 additions & 7 deletions packages/docs/content/docs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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 }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { parseAsInteger } from 'nuqs/parsers'
import { parseAsInteger } from 'nuqs/server'

export const counterParser = parseAsInteger.withDefault(0)
Original file line number Diff line number Diff line change
@@ -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('')
2 changes: 1 addition & 1 deletion packages/e2e/src/app/app/cache/searchParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
parseAsBoolean,
parseAsInteger,
parseAsString
} from 'nuqs/parsers'
} from 'nuqs/server'

export const parsers = {
str: parseAsString,
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e/src/app/app/rewrites/destination/page.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createSearchParamsCache, parseAsString } from 'nuqs/parsers'
import { createSearchParamsCache, parseAsString } from 'nuqs/server'

export const searchParams = {
injected: parseAsString.withDefault('null'),
Expand Down
Original file line number Diff line number Diff line change
@@ -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
10 changes: 5 additions & 5 deletions packages/nuqs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -87,8 +87,8 @@
]
},
{
"name": "Parsers",
"path": "dist/parsers.js",
"name": "Server",
"path": "dist/server.js",
"limit": "2 kB",
"ignore": [
"react"
Expand Down
4 changes: 2 additions & 2 deletions packages/nuqs/parsers.d.ts → packages/nuqs/server.d.ts
Original file line number Diff line number Diff line change
@@ -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'
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/nuqs/src/tests/cache.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
parseAsBoolean,
parseAsInteger,
parseAsString
} from '../../dist/parsers'
} from '../../dist/server'

{
const cache = createSearchParamsCache({
Expand Down

0 comments on commit ad3aa48

Please sign in to comment.