Skip to content

@xtandard/lib/tanstack/server

Framework-free query-state parsers, serializer, loader and Standard Schema bridge. Zero dependencies.

import { … } from "@xtandard/lib/tanstack/server";
Name Summary
combineRateLimits When several updates coincide in the same tick, the strongest limit wins: the longest delay, and debounce dominates throttle (it waits for settling). The store uses this to merge batched updates; adapter authors can reuse it.
combineResolvedOptions Combine resolved options from multiple updates batched in the same tick. The “loudest” update wins: push over replace, full navigation over shallow, scroll over no-scroll, and the strongest rate limit. The clearOn* flags stay on only if both have them on, and b’s startTransition wins when both set one.
createLoader Server-side parser. Accepts a URL string, query string, URL, URLSearchParams, Request, a record, or a promise of any of those, and returns the parsed values. In strict mode, present-but-invalid values throw.
createMultiParser Build a custom multi-value parser for repeated keys (?id=1&id=2): parse receives every value of the key (params.getAll) and serialize returns one string per repeated key. Return null from parse to reject. eq defaults to ===. Only called when the key is present; an absent key resolves to the default (or null).
createParser Build a custom single-value parser from a parse/serialize pair. parse returns null for a value it rejects (the key then resolves to the default). serialize defaults to String(value) and eq (used by clearOnDefault) to ===; pass eq for object values like Date. Chain .withDefault() / .withOptions() like any built-in parser.
createSerializer Build a query string or URL from a parser map. Preserves unrelated params on the base, removes keys set to null, and honors clearOnDefault/urlKeys.
createStandardSchemaV1 Build a Standard Schema from a parser map for use in a route’s validateSearch. The same parser definitions a component uses with useQueryStates can validate/type the route — without the component importing the route object.
debounce Debounce: wait until timeMs of quiet has elapsed before committing. Use it as the limitUrlUpdates option, e.g. for a search box that should only write the URL once the user stops typing.
hasInvalidKey Whether a key is PRESENT in the URL but its raw value fails to parse — stale or tampered junk that clearOnInvalid strips. An absent key is NOT invalid (it just resolves to the default), so this returns false for it.
keepSubDelims Serialize search params but leave the RFC-3986 sub-delims ( ) , : ! ' raw instead of percent-encoding them. They round-trip through URLSearchParams unchanged (none is &/=/+), so this is purely cosmetic — it keeps Rison-encoded (and other structured) tokens human-readable in the address bar ((type:and,…) instead of %28type%3Aand%2C…). Pass as a query-state adapter’s serializeSearch. &, = and + stay encoded.
parseAsArrayOf Array packed into a single key, comma-separated by default (?ids=1,2,3). Each item goes through itemParser; items that fail to parse are dropped ("1,x,3" → [1, 3], "x" → []), and an empty value is []. It never returns null, so clearOnInvalid never strips the key (same as nuqs). A separator inside an item is percent-encoded so it round-trips.
parseAsCodec Store a structured value as an opaque token in the URL via a codec. Decode failures fall back to null (the parser contract), so a tampered/stale token resolves to the default instead of throwing.
parseAsJson JSON-encoded value. A runtime validator is required (Standard Schema or a function that returns the value or throws); malformed JSON or a failed validation yields null. Validation must be sync. Equality compares JSON.stringify output.
parseAsNativeArrayOf Native URL arrays via repeated keys: ?tag=a&tag=b. A multi-value parser that already has .withDefault([]) applied. Items that fail itemParser are dropped; when none parse, the key is invalid (null, so it reads as the default and clearOnInvalid strips it), except a single empty value (?tag=), which is an explicit []. Same rules as nuqs.
parseAsNumberLiteral One of a fixed list of numbers, typed as their union. Anything else parses to null. Read with Number.parseFloat, like nuqs, so trailing junk is ignored ("25px" → 25 when 25 is in the list).
parseAsStandardSchema Validate the raw query string through a Standard Schema (Zod, Valibot, ArkType, …) and return its output; invalid input → null. Best for scalar params (z.string().email(), z.coerce.number(), z.enum([...])); for structured values prefer parseAsJson(schema). Validation must be sync.
parseAsStringEnum A value of a string enum (or any Record<string, string>), matched by the enum’s values, not its keys. Anything else parses to null.
parseAsStringLiteral One of a fixed list of strings, typed as their union. Anything else parses to null.
resolveOptions Resolve options across precedence layers (highest first): call-level > parser .withOptions() > hook options > adapter defaults > library defaults. Each option is picked separately from the first layer that sets it. This is what the hooks run on every setter call; adapter authors can reuse it.
throttle Throttle: commit the first update quickly, then at most once per timeMs. Pass Infinity to keep state in sync while never committing to the URL. Use it as the limitUrlUpdates option.
validateWithStandardSchema Run a Standard Schema synchronously, returning its output or throwing. Async validators are unsupported (matches nuqs parseAsJson).
withTransport Wrap a parser with a string transport layer — the encoder/decoder stage. encode runs after the parser’s serialize, decode before its parse. Useful for base64url / signing on top of any existing parser. The inner parser’s eq, default and .withOptions() carry over, so wrapping a .withDefault() parser keeps it non-nullable. A decode that throws yields null.
Name Summary
MultiParser Server / framework-free entrypoint. No React, safe to import in loaders, server functions, and validateSearch.
MultiParserWithDefault Server / framework-free entrypoint. No React, safe to import in loaders, server functions, and validateSearch.
Parser Server / framework-free entrypoint. No React, safe to import in loaders, server functions, and validateSearch.
ParserWithDefault Server / framework-free entrypoint. No React, safe to import in loaders, server functions, and validateSearch.
StandardSchemaV1 Vendored Standard Schema v1 interface (https://standardschema.dev), so we don’t take a dependency just for the ~30-line contract. Compatible with Zod/Valibot/ArkType validators and with TanStack Router validateSearch.
Name Summary
AnyMultiParser Server / framework-free entrypoint. No React, safe to import in loaders, server functions, and validateSearch.
AnyParser Server / framework-free entrypoint. No React, safe to import in loaders, server functions, and validateSearch.
AnySingleParser Server / framework-free entrypoint. No React, safe to import in loaders, server functions, and validateSearch.
CreateLoaderOptions
CreateSerializerOptions
CreateStandardSchemaOptions
Eq Equality check a parser uses to compare values (e.g. against its default for clearOnDefault).
HistoryMode
inferParserMapType Server / framework-free entrypoint. No React, safe to import in loaders, server functions, and validateSearch.
inferParserType Map a parser type to the value its hook returns.
JsonValidator Runtime validator for parseAsJson: a Standard Schema or a function that returns the value or throws.
LoaderInput
LoadOptions
ParserMap Server / framework-free entrypoint. No React, safe to import in loaders, server functions, and validateSearch.
QueryStateOptions
RateLimit Rate limiting for URL commits.
ResolvedOptions
SchemaInput Input type of the schema createStandardSchemaV1 builds: the parser map’s values, all optional when partial is set.
SerializerBase Base URL or query a serializer merges into: a string, URL or URLSearchParams.
SerializerValues
StartTransitionFn Structural type for React’s startTransition so the core stays React-free. Matches React.TransitionStartFunction.
Transport String encoder/decoder pair for withTransport (e.g. base64url or signing).
ValueCodec A value codec: structured data ⇄ opaque token. Structurally matches xtandard’s CursorCodec<T> (from createCursorCodec), so a single codec — with its own serializer/parser/encoder/decoder overrides — can back URL state, pagination, and drizzle-cursor at once.
Name Summary
defaultRateLimit nuqs-compatible default: throttle at 50ms. It is the limitUrlUpdates used when no layer sets one.
LIBRARY_DEFAULTS The bottom option layer, used when no call, parser, hook or adapter sets a value. Matches nuqs. Read-only reference: changing it at runtime is not a supported way to configure the library (use the adapter’s defaultOptions).
parseAsBoolean "true" ⇄ true, "false" ⇄ false. Case-insensitive on read ("TRUE" → true), like nuqs.
parseAsFloat Floating-point number (Number.parseFloat); a non-numeric value parses to null.
parseAsHex Integer stored as hexadecimal (no 0x prefix), e.g. for colors. Serializes rounded.
parseAsIndex Page index: the URL is 1-indexed, state is 0-indexed (?page=1 ⇄ 0). Fits TanStack Table’s pageIndex while keeping human-friendly URLs.
parseAsInteger Base-10 integer (Number.parseInt). A value with no leading digits parses to null; trailing junk is ignored ("42abc" → 42), the same lenient read as nuqs. Serializes rounded.
parseAsIsoDate Date stored as an ISO date without a time component (YYYY-MM-DD). "2026-12-25" parses to UTC midnight; serializing and equality use the UTC calendar day, so two Dates on the same UTC day are equal.
parseAsIsoDateTime Date stored as a full ISO-8601 timestamp (toISOString(), UTC). Anything new Date(value) can’t read parses to null. Equality is by time value.
parseAsString Identity parser: the raw query value as a string. Any present value parses, so add .withDefault("") to get a non-null string.
parseAsTimestamp Date stored as Unix epoch milliseconds.