'use client'; import { HistoryOptions, LimitUrlUpdates, Nullable, Options, SearchParams, UrlKeys } from "./defs-BxjUD_70.js"; import { StandardSchemaV1 } from "@standard-schema/spec"; //#region src/lib/queues/rate-limiting.d.ts declare function throttle(timeMs: number): LimitUrlUpdates; declare function debounce(timeMs: number): LimitUrlUpdates; declare const defaultRateLimit: LimitUrlUpdates; //#endregion //#region src/parsers.d.ts type Require = Pick, Keys> & Omit; type Parser = { /** * Convert a query string value into a state value. * * If the string value does not represent a valid state value, * the parser should return `null`. Throwing an error is also supported. */ parse: (value: string) => T | null; /** * Render the state value into a query string value. */ serialize?: (value: T) => string; /** * Check if two state values are equal. * * This is used when using the `clearOnDefault` value, to compare the default * value with the set value. * * It makes sense to provide this function when the state value is an object * or an array, as the default referential equality check will not work. */ eq?: (a: T, b: T) => boolean; }; type ParserBuilder = Required> & Options & { /** * Set history type, shallow routing and scroll restoration options * at the hook declaration level. * * Note that you can override those options in individual calls to the * state updater function. */ withOptions(this: This, options: Options): This; /** * Specifying a default value makes the hook state non-nullable when the * query is missing from the URL: the default value is returned instead * of `null`. * * Setting the state to the default value¹ will clear the query string key * from the URL, unless `clearOnDefault` is set to `false`. * * Setting the state to `null` will always clear the query string key * from the URL, and return the default value. * * ¹: Equality is checked with the parser's `eq` function, or referential * equality if not provided. * * @param defaultValue */ withDefault(this: ParserBuilder, defaultValue: NonNullable): Omit, "parseServerSide"> & { readonly defaultValue: NonNullable; /** * Use the parser in Server Components * * `parse` is intended to be used only by the hook, but you can use this * method to hydrate query values on server-side rendered pages. * See the `server-side-parsing` demo for an example. * * Note that when multiple queries are presented to the parser * (eg: `/?a=1&a=2`), only the **first** will be parsed, to mimic the * behaviour of URLSearchParams: * https://url.spec.whatwg.org/#dom-urlsearchparams-get * * @param value as coming from page props * * @deprecated prefer using loaders instead, as they enforce a strong * bond between the data type and the search param key. */ parseServerSide(value: string | string[] | undefined): NonNullable; }; /** * Use the parser in Server Components * * `parse` is intended to be used only by the hook, but you can use this * method to hydrate query values on server-side rendered pages. * See the `server-side-parsing` demo for an example. * * Note that when multiple queries are presented to the parser * (eg: `/?a=1&a=2`), only the **first** will be parsed, to mimic the * behaviour of URLSearchParams: * https://url.spec.whatwg.org/#dom-urlsearchparams-get * * @param value as coming from page props * * @deprecated prefer using loaders instead, as they enforce a strong * bond between the data type and the search param key. */ parseServerSide(value: string | string[] | undefined): T | null; }; /** * Wrap a set of parse/serialize functions into a builder pattern parser * you can pass to one of the hooks, making its default value type safe. */ declare function createParser(parser: Require, "parse" | "serialize">): ParserBuilder; declare const parseAsString: ParserBuilder; declare const parseAsInteger: ParserBuilder; declare const parseAsIndex: ParserBuilder; declare const parseAsHex: ParserBuilder; declare const parseAsFloat: ParserBuilder; declare const parseAsBoolean: ParserBuilder; /** * Querystring encoded as the number of milliseconds since epoch, * and returned as a Date object. */ declare const parseAsTimestamp: ParserBuilder; /** * Querystring encoded as an ISO-8601 string (UTC), * and returned as a Date object. */ declare const parseAsIsoDateTime: ParserBuilder; /** * Querystring encoded as an ISO-8601 string (UTC) * without the time zone offset, and returned as * a Date object. * * The Date is parsed without the time zone offset, * making it at 00:00:00 UTC. */ declare const parseAsIsoDate: ParserBuilder; /** * String-based enums provide better type-safety for known sets of values. * You will need to pass the parseAsStringEnum function a list of your enum values * in order to validate the query string. Anything else will return `null`, * or your default value if specified. * * Example: * ```ts * enum Direction { * up = 'UP', * down = 'DOWN', * left = 'LEFT', * right = 'RIGHT' * } * * const [direction, setDirection] = useQueryState( * 'direction', * parseAsStringEnum(Object.values(Direction)) // pass a list of allowed values * .withDefault(Direction.up) * ) * ``` * * Note: the query string value will be the value of the enum, not its name * (example above: `direction=UP`). * * @param validValues The values you want to accept */ declare function parseAsStringEnum(validValues: Enum[]): ParserBuilder; /** * String-based literals provide better type-safety for known sets of values. * You will need to pass the parseAsStringLiteral function a list of your string values * in order to validate the query string. Anything else will return `null`, * or your default value if specified. * * Example: * ```ts * const colors = ["red", "green", "blue"] as const * * const [color, setColor] = useQueryState( * 'color', * parseAsStringLiteral(colors) // pass a readonly list of allowed values * .withDefault("red") * ) * ``` * * @param validValues The values you want to accept */ declare function parseAsStringLiteral(validValues: readonly Literal[]): ParserBuilder; /** * Number-based literals provide better type-safety for known sets of values. * You will need to pass the parseAsNumberLiteral function a list of your number values * in order to validate the query string. Anything else will return `null`, * or your default value if specified. * * Example: * ```ts * const diceSides = [1, 2, 3, 4, 5, 6] as const * * const [side, setSide] = useQueryState( * 'side', * parseAsNumberLiteral(diceSides) // pass a readonly list of allowed values * .withDefault(4) * ) * ``` * * @param validValues The values you want to accept */ declare function parseAsNumberLiteral(validValues: readonly Literal[]): ParserBuilder; /** * Encode any object shape into the querystring value as JSON. * Note: you may want to use `useQueryStates` for finer control over * multiple related query keys. * * @param runtimeParser Runtime parser (eg: Zod schema or Standard Schema) to validate after JSON.parse */ declare function parseAsJson(validator: ((value: unknown) => T | null) | StandardSchemaV1): ParserBuilder; /** * A comma-separated list of items. * Items are URI-encoded for safety, so they may not look nice in the URL. * * @param itemParser Parser for each individual item in the array * @param separator The character to use to separate items (default ',') */ declare function parseAsArrayOf(itemParser: Parser, separator?: string): ParserBuilder; type inferSingleParserType = Parser extends ParserBuilder & { defaultValue: infer Value; } ? Value : Parser extends ParserBuilder ? Value | null : never; type inferParserRecordType>> = { [Key in keyof Map]: inferSingleParserType } & {}; /** * Type helper to extract the underlying returned data type of a parser * or of an object describing multiple parsers and their associated keys. * * Usage: * * ```ts * import { type inferParserType } from 'nuqs' // or 'nuqs/server' * * const intNullable = parseAsInteger * const intNonNull = parseAsInteger.withDefault(0) * * inferParserType // number | null * inferParserType // number * * const parsers = { * a: parseAsInteger, * b: parseAsBoolean.withDefault(false) * } * * inferParserType * // { a: number | null, b: boolean } * ``` */ type inferParserType = Input extends ParserBuilder ? inferSingleParserType : Input extends Record> ? inferParserRecordType : never; type ParserWithOptionalDefault = ParserBuilder & { defaultValue?: T; }; type ParserMap = Record>; //#endregion //#region src/loader.d.ts type LoaderInput = URL | Request | URLSearchParams | Record | string; /** * @deprecated Use `CreateLoaderOptions` instead. */ type LoaderOptions = { urlKeys?: UrlKeys; }; type CreateLoaderOptions

= LoaderOptions

; type LoaderFunctionOptions = { /** * Whether to use strict parsing. If true, the loader will throw an error if * any of the parsers fail to parse their respective values. If false, the * loader will return null or their default value for any failed parsers. */ strict?: boolean; }; type LoaderFunction = { /** * Load & parse search params from (almost) any input. * * While loaders are typically used in the context of a React Router / Remix * loader function, it can also be used in Next.js API routes or * getServerSideProps functions, or even with the app router `searchParams` * page prop (sync or async), if you don't need the cache behaviours. */ (input: LoaderInput, options?: LoaderFunctionOptions): inferParserType; /** * Load & parse search params from (almost) any input. * * While loaders are typically used in the context of a React Router / Remix * loader function, it can also be used in Next.js API routes or * getServerSideProps functions, or even with the app router `searchParams` * page prop (sync or async), if you don't need the cache behaviours. * * Note: this async overload makes it easier to use against the `searchParams` * page prop in Next.js 15 app router: * * ```tsx * export default async function Page({ searchParams }) { * const parsedSearchParamsPromise = loadSearchParams(searchParams) * return ( * // Pre-render & stream the shell immediately * * * // Stream the Promise down * * * * ) * } * ``` */ (input: Promise, options?: LoaderFunctionOptions): Promise>; }; declare function createLoader(parsers: Parsers, { urlKeys }?: CreateLoaderOptions): LoaderFunction; //#endregion //#region src/serializer.d.ts type Base = string | URLSearchParams | URL; type CreateSerializerOptions = Pick & { urlKeys?: UrlKeys; }; type SerializeFunction = { /** * Generate a query string for the given values. */ (values: Partial>>): Return; /** * Append/amend the query string of the given base with the given values. * * Existing search param values will kept, unless: * - the value is null, in which case the search param will be deleted * - another value is given for an existing key, in which case the * search param will be updated */ (base: BaseType, values: Partial>> | null): Return; }; declare function createSerializer(parsers: Parsers, { clearOnDefault, urlKeys }?: CreateSerializerOptions): SerializeFunction; //#endregion //#region src/standard-schema.d.ts type CreateStandardSchemaV1Options = CreateLoaderOptions & { /** * Marks the output type as Partial, and removes any keys * from the output that are not present in the input. * * This is useful for TanStack Router, to avoid reflecting default values * (or null) in the URL, and to make search params optional in Links, * as default values are handled by nuqs. * * @default false */ partialOutput?: PartialOutput; }; type MaybePartial = Condition extends true ? Partial : Type; declare function createStandardSchemaV1(parsers: Parsers, { urlKeys, partialOutput }?: CreateStandardSchemaV1Options): StandardSchemaV1>>; //#endregion //#region src/useQueryState.d.ts interface UseQueryStateOptions extends Parser, Options {} type UseQueryStateReturn = [Default extends undefined ? Parsed | null : Parsed, (value: null | Parsed | ((old: Default extends Parsed ? Parsed : Parsed | null) => Parsed | null), options?: Options) => Promise]; /** * React state hook synchronized with a URL query string in Next.js * * This variant is used when providing a default value. This will make * the returned state non-nullable when the query is not present in the URL. * (the default value will be returned instead). * * _Note: the URL will **not** be updated with the default value if the query * is missing._ * * Setting the value to `null` will clear the query in the URL, and return * the default value as state. * * Example usage: * ```ts * const [count, setCount] = useQueryState( * 'count', * parseAsInteger.defaultValue(0) * ) * * const increment = () => setCount(oldCount => oldCount + 1) * const decrement = () => setCount(oldCount => oldCount - 1) * // Clears the query key from the URL and `count` equals 0 * const clearCountQuery = () => setCount(null) * ``` * @param key The URL query string key to bind to * @param options - Parser (defines the state data type), default value and optional history mode. */ declare function useQueryState(key: string, options: UseQueryStateOptions & { defaultValue: T; }): UseQueryStateReturn>, typeof options.defaultValue>; /** * React state hook synchronized with a URL query string in Next.js * * If the query is missing in the URL, the state will be `null`. * * Example usage: * ```ts * // Blog posts filtering by tag * const [tag, selectTag] = useQueryState('tag') * const filteredPosts = posts.filter(post => tag ? post.tag === tag : true) * const clearTag = () => selectTag(null) * ``` * @param key The URL query string key to bind to * @param options - Parser (defines the state data type), and optional history mode. */ declare function useQueryState(key: string, options: UseQueryStateOptions): UseQueryStateReturn>, undefined>; /** * Default type string, limited options & default value */ declare function useQueryState(key: string, options: Options & { defaultValue: string; } & { [K in keyof Parser]?: never }): UseQueryStateReturn; /** * React state hook synchronized with a URL query string in Next.js * * If the query is missing in the URL, the state will be `null`. * * Note: by default the state type is a `string`. To use different types, * check out the `parseAsXYZ` helpers: * ```ts * const [date, setDate] = useQueryState( * 'date', * parseAsIsoDateTime.withDefault(new Date('2021-01-01')) * ) * * const setToNow = () => setDate(new Date()) * const addOneHour = () => { * setDate(oldDate => new Date(oldDate.valueOf() + 3600_000)) * } * ``` * @param key The URL query string key to bind to * @param options - Parser (defines the state data type), and optional history mode. */ declare function useQueryState(key: string, options: Pick, keyof Options>): UseQueryStateReturn; /** * React state hook synchronized with a URL query string in Next.js * * If the query is missing in the URL, the state will be `null`. * * Note: by default the state type is a `string`. To use different types, * check out the `parseAsXYZ` helpers: * ```ts * const [date, setDate] = useQueryState( * 'date', * parseAsIsoDateTime.withDefault(new Date('2021-01-01')) * ) * * const setToNow = () => setDate(new Date()) * const addOneHour = () => { * setDate(oldDate => new Date(oldDate.valueOf() + 3600_000)) * } * ``` * @param key The URL query string key to bind to */ declare function useQueryState(key: string): UseQueryStateReturn; //#endregion //#region src/useQueryStates.d.ts type KeyMapValue = Parser & Options & { defaultValue?: Type; }; type UseQueryStatesKeysMap = { [Key in keyof Map]: KeyMapValue } & {}; type UseQueryStatesOptions = Options & { urlKeys: UrlKeys; }; type Values = { [K in keyof T]: T[K]["defaultValue"] extends NonNullable> ? NonNullable> : ReturnType | null }; type UpdaterFn = (old: Values) => Partial>> | null; type SetValues = (values: Partial>> | UpdaterFn | null, options?: Options) => Promise; type UseQueryStatesReturn = [Values, SetValues]; /** * Synchronise multiple query string arguments to React state in Next.js * * @param keys - An object describing the keys to synchronise and how to * serialise and parse them. * Use `parseAs(String|Integer|Float|...)` for quick shorthands. * @param options - Optional history mode, shallow routing and scroll restoration options. */ declare function useQueryStates(keyMap: KeyMap, options?: Partial>): UseQueryStatesReturn; //#endregion export { type CreateSerializerOptions, type HistoryOptions, type LoaderFunction, type LoaderInput, type LoaderOptions, type Nullable, type Options, Parser, ParserBuilder, ParserMap, ParserWithOptionalDefault, type SearchParams, SetValues, type UrlKeys, UseQueryStateOptions, UseQueryStateReturn, UseQueryStatesKeysMap, UseQueryStatesOptions, UseQueryStatesReturn, Values, createLoader, createParser, createSerializer, createStandardSchemaV1, debounce, defaultRateLimit, inferParserType, parseAsArrayOf, parseAsBoolean, parseAsFloat, parseAsHex, parseAsIndex, parseAsInteger, parseAsIsoDate, parseAsIsoDateTime, parseAsJson, parseAsNumberLiteral, parseAsString, parseAsStringEnum, parseAsStringLiteral, parseAsTimestamp, throttle, useQueryState, useQueryStates }; //# sourceMappingURL=index.d.ts.map